{"name":"css-box-model","version":"0.0.4","description":"Returns the css box model for a HTMLElement","main":"dist/css-box-model.cjs.js","module":"dist/css-box-model.esm.js","sideEffects":false,"scripts":{"test":"yarn jest","lint":"yarn prettier --debug-check src/** test/**","typecheck":"yarn flow","validate":"yarn lint && yarn flow","build:clean":"rimraf dist","build:flow":"echo \"// @flow\n\nexport * from '../src';\" > dist/css-box-model.cjs.js.flow","build:dist":"yarn rollup --config rollup.config.js","build":"yarn build:clean && yarn build:dist && yarn build:flow","prepublishOnly":"yarn build"},"author":{"name":"Alex Reardon","email":"alexreardon@gmail.com"},"license":"MIT","devDependencies":{"babel-cli":"^6.26.0","babel-core":"^6.26.0","babel-plugin-transform-es2015-modules-commonjs":"^6.26.0","babel-preset-env":"^1.6.1","babel-preset-flow":"^6.23.0","flow-bin":"^0.69.0","jest":"^22.4.3","prettier":"1.12.0","rimraf":"^2.6.2","rollup":"^0.58.1","rollup-plugin-babel":"^3.0.3"},"gitHead":"7fdaafce5967183b968cc169df36d2b17a947b05","_id":"css-box-model@0.0.4","_npmVersion":"5.8.0","_nodeVersion":"8.4.0","_npmUser":{"name":"alexreardon","email":"alexreardon@gmail.com"},"dist":{"integrity":"sha512-GhetTxumwnN1KWrel9xF0OyxDFjtzlEKBj1HUuI1G+o4pI0strwbK3zKnfSX/xe59Q+96pFdrZouVQ7uaHLPPw==","shasum":"ba24e8a90a68bf09a4d18cea4e9fb27fc47a3091","tarball":"http://registry-npm.ywwl.com/css-box-model/download/css-box-model-0.0.4.tgz","fileCount":17,"unpackedSize":178574,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa3TbvCRA9TVsSAnZWagAA9a0QAJYRd6uD80sVnIGJSYDm\n+2kL/dGMFddjA4rYyX+IpL1A3jcYBXSHXCbr5qFRXNxiiL7rZQNh9JHzLat1\nycK9BLb59hoBEHZ6Al64T7M2KWtVdw9riHrTY7CGfaFyHVymelQgLyoKqGmn\nG+ahFppqZbwrD5zlr67+VBgJtdc1823VQe4b/vAMg2j49Pqd+1VATH5+PObl\nbkg3C1vYOdEHvMkMEpZoP2uO8LngQd74Ud/u+AhQgi+zf6MwPhXvqbQ7AhqW\n2GVgPEPu93mOcdAvqz0MHMtq1/REI9x49AUjdgmKBfAEC2m70WV7RmH28/2K\nNN4Cys4ImPi12+h/VS6b51WQZhZ3ExRIO1a94YswvEkK+mV1sxAadhjhhfaZ\nELhlgCwuN5dP4JTEZMNnnn3AYj9Q2bkC4vkZvojUVwQ/Ar1ya6OfI5KIzjtF\nUSlnKpP+PP/ncFGtH4x/iHKIFvkzREeSajxYi9xCK8pcy0llJ0oVvkuaw1t7\n8Qrf0cOXvF7aDPT1n3o+EzOeicyPegTl2WkmiixuBgyp8PSQZ7L3gGEHgR0v\nYmedfUBEN/aPj4gDtJtO6r9CH2FOlRsvAldzjZYNuIK753m72jblHMgUJfxH\nXPdiL0/lYKFGqMyGYcF4RWX6nCrYNw4wJIQ8XUzoguAMHu46IRtuKnQrpoy8\ngqug\r\n=O/Pr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCID5ojjLWjNj258afuaDF3/FM7YaBucGh1L8Ybz2ByidVAiEAktpfy3fx2MkiNzzNKkDYSo4TY5d/rAUYBAtL0NZYnYI="}],"size":47133,"noattachment":false,"key":"/css-box-model/-/css-box-model-0.0.4.tgz"},"maintainers":[{"name":"alexreardon","email":"alexreardon@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/css-box-model_0.0.4_1524446959318_0.48898806250748006"},"_hasShrinkwrap":false,"readme":"# `css-box-model` 📦\n\nGet accurate and well named [CSS Box Model](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model) information about a [`Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element).\n\n[![Build Status](https://travis-ci.org/alexreardon/css-box-model.svg?branch=master)](https://travis-ci.org/alexreardon/css-box-model)\n[![npm](https://img.shields.io/npm/v/css-box-model.svg)](https://www.npmjs.com/package/css-box-model)\n[![dependencies](https://david-dm.org/alexreardon/css-box-model.svg)](https://david-dm.org/alexreardon/css-box-model)\n[![Downloads per month](https://img.shields.io/npm/dm/css-box-model.svg)](https://www.npmjs.com/package/css-box-model)\n[![min](https://img.shields.io/bundlephobia/min/css-box-model.svg)](https://www.npmjs.com/package/css-box-model)\n[![minzip](https://img.shields.io/bundlephobia/minzip/css-box-model.svg)](https://www.npmjs.com/package/css-box-model)\n\nAny time you are using [`Element.getBoundingClientRect()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect) you might want to consider using `css-box-model` instead to get more detailed box model information.\n\n## Usage\n\n```js\n// @flow\nimport { getBox } from 'css-box-model';\n\nconst el: HTMLElement = document.getElementById('foo');\nconst box: BoxModel = getBox(el);\n\n// profit\n```\n\n## Installation\n\n```bash\n## yarn\nyarn add css-box-model\n\n# npm\nnpm install css-box-model --save\n```\n\n## The [CSS Box Model](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model)\n\n![the box model](https://user-images.githubusercontent.com/2182637/46847224-f8a23e80-ce2e-11e8-80d6-0ca62a1871a7.png)\n\n| Box type    | Composition                         |\n| ----------- | ----------------------------------- |\n| Margin box  | margin + border + padding + content |\n| Border box  | border + padding + content          |\n| Padding box | padding + content                   |\n| Content box | content                             |\n\nThis our returned `BoxModel`:\n\n```js\nexport type BoxModel = {|\n  // content + padding + border + margin\n  marginBox: Rect,\n  // content + padding + border\n  borderBox: Rect,\n  // content + padding\n  paddingBox: Rect,\n  // content\n  contentBox: Rect,\n  // for your own consumption\n  border: Spacing,\n  padding: Spacing,\n  margin: Spacing,\n|};\n\n// Supporting types\n\n// This is an extension of DOMRect and ClientRect\nexport type Rect = {|\n  // ClientRect\n  top: number,\n  right: number,\n  bottom: number,\n  left: number,\n  width: number,\n  height: number,\n  // DOMRect\n  x: number,\n  y: number,\n  // Rect\n  center: Position,\n|};\n\nexport type Position = {|\n  x: number,\n  y: number,\n|};\n\nexport type Spacing = {\n  top: number,\n  right: number,\n  bottom: number,\n  left: number,\n};\n```\n\n## API\n\n### `getBox`\n\n> (el: HTMLElement) => BoxModel\n\nUse `getBox` to return the box model for an element\n\n### `withScroll`\n\n> `(original: BoxModel, scroll?: Position = getWindowScroll()) => BoxModel`\n\nThis is useful if you want to know the box model for an element relative to a page\n\n```js\nconst el: HTMLElement = document.getElementById('app');\nconst box: BoxModel = getBox(el);\nconst withScroll: BoxModel = withScroll(box);\n```\n\nYou are welcome to pass in your own `scroll`. By default we we use the window scroll:\n\n```js\nconst getWindowScroll = (): Position => ({\n  x: window.pageXOffset,\n  y: window.pageYOffset,\n});\n```\n\n### `calculateBox`\n\n> `(borderBox: AnyRectType, styles: CSSStyleDeclaration) => BoxModel`\n\nThis will do the box model calculations without needing to read from the DOM. This is useful if you have already got a `ClientRect` / `DOMRect` and a `CSSStyleDeclaration` as then we can skip computing these values.\n\n```js\nconst el: HTMLElement = document.getElementById('app');\nconst borderBox: ClientRect = el.getBoundingClientRect();\nconst styles: CSSStyleDeclaration = window.getComputedStyles(el);\n\nconst box: BoxModel = calculateBox(borderBox, styles);\n```\n\n**`AnyRectType`** allows for simple interoperability with any rect type\n\n```js\ntype AnyRectType = ClientRect | DOMRect | Rect | Spacing;\n```\n\n### `createBox`\n\n> `({ borderBox, margin, border, padding }: CreateBoxArgs) => BoxModel`\n\nAllows you to create a `BoxModel` by passing in a `Rect` like shape (`AnyRectType`) and optionally your own `margin`, `border` and or `padding`.\n\n```js\ntype CreateBoxArgs = {|\n  borderBox: AnyRectType,\n  margin?: Spacing,\n  border?: Spacing,\n  padding?: Spacing,\n|};\n```\n\n```js\nconst borderBox: Spacing = {\n  top: 10,\n  right: 100,\n  left: 20,\n  bottom: 80,\n};\nconst padding: Spacing = {\n  top: 10,\n  right: 20,\n  left: 20,\n  bottom: 10,\n};\n\nconst box: BoxModel = createBox({ borderBox, padding });\n```\n\n## Utility API\n\n> Functions to help you interact with the objects we provide\n\n### `getRect`\n\n> `(spacing: AnyRectType) => Rect`\n\nGiven any `Rect` like shape, return a `Rect`. Accepts any object that has `top`, `right`, `bottom` and `right` (eg `ClientRect`, `DOMRect`);\n\n```js\nconst spacing: Spacing = {\n  top: 0,\n  right: 100,\n  bottom: 50,\n  left: 50,\n};\n\nconst rect: Rect = getRect(spacing);\n\nconsole.log(rect);\n\n/*\n{\n  top: 0,\n  right: 100,\n  bottom: 50,\n  left: 50,\n  width: 100,\n  height: 50,\n  x: 0,\n  y: 0,\n  center: { x: 50, y: 50 },\n}\n*/\n```\n\n### `expand`\n\nUsed to expand a `Spacing`\n\n```js\n(target: Spacing, expandBy: Spacing) => Spacing;\n```\n\n```js\nconst original: Spacing = {\n  top: 10,\n  left: 11,\n  right: 21,\n  bottom: 22,\n};\n\nconst expandBy: Spacing = {\n  top: 1,\n  left: 2,\n  right: 3,\n  bottom: 4,\n};\n\nconst expanded: Spacing = expand(original, expandBy);\n\nconsole.log(expanded);\n\n/*\n{\n  // pulled back\n  top: 8,\n  left: 8\n  // pushed forward\n  bottom: 22,\n  right: 22,\n}\n*/\n```\n\n### `shrink`\n\nUsed to shrink a `Spacing`\n\n```js\n(target: Spacing, shrinkBy: Spacing) => Spacing;\n```\n\n```js\nconst original: Spacing = {\n  top: 10,\n  left: 10,\n  right: 20,\n  bottom: 20,\n};\n\nconst shrinkBy: Spacing = {\n  top: 2,\n  left: 2,\n  right: 2,\n  bottom: 2,\n};\n\nconst smaller: Spacing = shrink(original, shrinkBy);\n\nconsole.log(smaller);\n\n/*\n{\n  // pushed forward\n  top: 12,\n  left: 12\n  // pulled back\n  bottom: 18,\n  right: 18,\n}\n*/\n```\n","publish_time":1524446959410,"_cnpm_publish_time":1524446959410,"dist-tags":{"latest":"1.2.1"}}