Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/capnfabs/paperesque.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@juggle/resize-observer/lib/algorithms/calculateBoxSize.js')
-rw-r--r--node_modules/@juggle/resize-observer/lib/algorithms/calculateBoxSize.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/node_modules/@juggle/resize-observer/lib/algorithms/calculateBoxSize.js b/node_modules/@juggle/resize-observer/lib/algorithms/calculateBoxSize.js
new file mode 100644
index 0000000..65d699c
--- /dev/null
+++ b/node_modules/@juggle/resize-observer/lib/algorithms/calculateBoxSize.js
@@ -0,0 +1,80 @@
+import { ResizeObserverBoxOptions } from '../ResizeObserverBoxOptions';
+import { DOMRectReadOnly } from '../DOMRectReadOnly';
+import { isSVG, isHidden } from '../utils/element';
+import { global } from '../utils/global';
+var cache = new WeakMap();
+var scrollRegexp = /auto|scroll/;
+var verticalRegexp = /^tb|vertical/;
+var IE = (/msie|trident/i).test(global.navigator && global.navigator.userAgent);
+var parseDimension = function (pixel) { return parseFloat(pixel || '0'); };
+var size = function (inlineSize, blockSize, switchSizes) {
+ if (inlineSize === void 0) { inlineSize = 0; }
+ if (blockSize === void 0) { blockSize = 0; }
+ if (switchSizes === void 0) { switchSizes = false; }
+ return Object.freeze({
+ inlineSize: (switchSizes ? blockSize : inlineSize) || 0,
+ blockSize: (switchSizes ? inlineSize : blockSize) || 0
+ });
+};
+var zeroBoxes = Object.freeze({
+ devicePixelContentBoxSize: size(),
+ borderBoxSize: size(),
+ contentBoxSize: size(),
+ contentRect: new DOMRectReadOnly(0, 0, 0, 0)
+});
+var calculateBoxSizes = function (target, forceRecalculation) {
+ if (forceRecalculation === void 0) { forceRecalculation = false; }
+ if (cache.has(target) && !forceRecalculation) {
+ return cache.get(target);
+ }
+ if (isHidden(target)) {
+ cache.set(target, zeroBoxes);
+ return zeroBoxes;
+ }
+ var cs = getComputedStyle(target);
+ var svg = isSVG(target) && target.ownerSVGElement && target.getBBox();
+ var removePadding = !IE && cs.boxSizing === 'border-box';
+ var switchSizes = verticalRegexp.test(cs.writingMode || '');
+ var canScrollVertically = !svg && scrollRegexp.test(cs.overflowY || '');
+ var canScrollHorizontally = !svg && scrollRegexp.test(cs.overflowX || '');
+ var paddingTop = svg ? 0 : parseDimension(cs.paddingTop);
+ var paddingRight = svg ? 0 : parseDimension(cs.paddingRight);
+ var paddingBottom = svg ? 0 : parseDimension(cs.paddingBottom);
+ var paddingLeft = svg ? 0 : parseDimension(cs.paddingLeft);
+ var borderTop = svg ? 0 : parseDimension(cs.borderTopWidth);
+ var borderRight = svg ? 0 : parseDimension(cs.borderRightWidth);
+ var borderBottom = svg ? 0 : parseDimension(cs.borderBottomWidth);
+ var borderLeft = svg ? 0 : parseDimension(cs.borderLeftWidth);
+ var horizontalPadding = paddingLeft + paddingRight;
+ var verticalPadding = paddingTop + paddingBottom;
+ var horizontalBorderArea = borderLeft + borderRight;
+ var verticalBorderArea = borderTop + borderBottom;
+ var horizontalScrollbarThickness = !canScrollHorizontally ? 0 : target.offsetHeight - verticalBorderArea - target.clientHeight;
+ var verticalScrollbarThickness = !canScrollVertically ? 0 : target.offsetWidth - horizontalBorderArea - target.clientWidth;
+ var widthReduction = removePadding ? horizontalPadding + horizontalBorderArea : 0;
+ var heightReduction = removePadding ? verticalPadding + verticalBorderArea : 0;
+ var contentWidth = svg ? svg.width : parseDimension(cs.width) - widthReduction - verticalScrollbarThickness;
+ var contentHeight = svg ? svg.height : parseDimension(cs.height) - heightReduction - horizontalScrollbarThickness;
+ var borderBoxWidth = contentWidth + horizontalPadding + verticalScrollbarThickness + horizontalBorderArea;
+ var borderBoxHeight = contentHeight + verticalPadding + horizontalScrollbarThickness + verticalBorderArea;
+ var boxes = Object.freeze({
+ devicePixelContentBoxSize: size(Math.round(contentWidth * devicePixelRatio), Math.round(contentHeight * devicePixelRatio), switchSizes),
+ borderBoxSize: size(borderBoxWidth, borderBoxHeight, switchSizes),
+ contentBoxSize: size(contentWidth, contentHeight, switchSizes),
+ contentRect: new DOMRectReadOnly(paddingLeft, paddingTop, contentWidth, contentHeight)
+ });
+ cache.set(target, boxes);
+ return boxes;
+};
+var calculateBoxSize = function (target, observedBox, forceRecalculation) {
+ var _a = calculateBoxSizes(target, forceRecalculation), borderBoxSize = _a.borderBoxSize, contentBoxSize = _a.contentBoxSize, devicePixelContentBoxSize = _a.devicePixelContentBoxSize;
+ switch (observedBox) {
+ case ResizeObserverBoxOptions.DEVICE_PIXEL_CONTENT_BOX:
+ return devicePixelContentBoxSize;
+ case ResizeObserverBoxOptions.BORDER_BOX:
+ return borderBoxSize;
+ default:
+ return contentBoxSize;
+ }
+};
+export { calculateBoxSize, calculateBoxSizes };