You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
14 KiB

2 years ago
{"ast":null,"code":"import invariant from 'tiny-invariant';\n\nvar getRect = function getRect(_ref) {\n var top = _ref.top,\n right = _ref.right,\n bottom = _ref.bottom,\n left = _ref.left;\n var width = right - left;\n var height = bottom - top;\n var rect = {\n top: top,\n right: right,\n bottom: bottom,\n left: left,\n width: width,\n height: height,\n x: left,\n y: top,\n center: {\n x: (right + left) / 2,\n y: (bottom + top) / 2\n }\n };\n return rect;\n};\n\nvar expand = function expand(target, expandBy) {\n return {\n top: target.top - expandBy.top,\n left: target.left - expandBy.left,\n bottom: target.bottom + expandBy.bottom,\n right: target.right + expandBy.right\n };\n};\n\nvar shrink = function shrink(target, shrinkBy) {\n return {\n top: target.top + shrinkBy.top,\n left: target.left + shrinkBy.left,\n bottom: target.bottom - shrinkBy.bottom,\n right: target.right - shrinkBy.right\n };\n};\n\nvar shift = function shift(target, shiftBy) {\n return {\n top: target.top + shiftBy.y,\n left: target.left + shiftBy.x,\n bottom: target.bottom + shiftBy.y,\n right: target.right + shiftBy.x\n };\n};\n\nvar noSpacing = {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0\n};\n\nvar createBox = function createBox(_ref2) {\n var borderBox = _ref2.borderBox,\n _ref2$margin = _ref2.margin,\n margin = _ref2$margin === void 0 ? noSpacing : _ref2$margin,\n _ref2$border = _ref2.border,\n border = _ref2$border === void 0 ? noSpacing : _ref2$border,\n _ref2$padding = _ref2.padding,\n padding = _ref2$padding === void 0 ? noSpacing : _ref2$padding;\n var marginBox = getRect(expand(borderBox, margin));\n var paddingBox = getRect(shrink(borderBox, border));\n var contentBox = getRect(shrink(paddingBox, padding));\n return {\n marginBox: marginBox,\n borderBox: getRect(borderBox),\n paddingBox: paddingBox,\n contentBox: contentBox,\n margin: margin,\n border: border,\n padding: padding\n };\n};\n\nvar parse = function parse(raw) {\n var value = raw.slice(0, -2);\n var suffix = raw.slice(-2);\n\n if (suffix !== 'px') {\n return 0;\n }\n\n var result = Number(value);\n !!isNaN(result) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"Could not parse value [raw: \" + raw + \", without suffix: \" + value + \"]\") : invariant(false) : void 0;\n return result;\n};\n\nvar getWindowScroll = function getWindowScroll() {\n return {\n x: window.pageXOffset,\n y: window.pageYOffset\n };\n};\n\nvar offset = function offset(original, change) {\n var borderBox = original.borderBox,\n border = original.border,\n margin = original.margin,\n padding = original.padding;\n var shifted = shift(borderBox, change);\n return createBox({\n borderBox: shifted,\n border: border,\n margin: margin,\n padding: padding\n });\n};\n\nvar withScroll = function withScroll(original, scroll) {\n if (scroll === void 0) {\n scroll = getWindowScroll();\n }\n\n return offset(original, scroll);\n};\n\nvar calculateBox = function calculateBox(borderBox, styles) {\n var margin = {\n top: parse(styles.marginTop),\n right: parse(styles.marginRight),\n bottom: parse(styles.marginBottom),\n left: parse(styles.marginLeft)\n };\n var padding = {\n top: parse(styles.paddingTop),\n right: parse(styles.paddingRight),\n bottom: parse(styles.paddingBottom),\n left: parse(styles.paddingLeft)\n };\n var border = {\n top: parse(styles.borderTopWidth),\n right: parse(styles.borderRightWidth),\n bottom: parse(styles.borderBottomWidth),\n left: parse(styles.borderLeftWidth)\n };\n return createBox({\n borderBox: borderBox,\n margin: margin,\n padding: padding,\n border: border\n });\n};\n\nvar getBox = function getBox(el) {\n var borderBox = el.getBoundingClientRect();\n var styles = window.getComputedStyle(el);\n return calculateBox(borderBox, styles);\n};\n\nexport { calculateBox, createBox, expand, getBox, get