@revivejs/resize-observer 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +159 -0
- package/lib/DOMRectReadOnly.d.ts +30 -0
- package/lib/DOMRectReadOnly.js +23 -0
- package/lib/ResizeObservation.d.ts +10 -0
- package/lib/ResizeObservation.js +31 -0
- package/lib/ResizeObserver.d.ts +10 -0
- package/lib/ResizeObserver.js +39 -0
- package/lib/ResizeObserverBoxOptions.d.ts +6 -0
- package/lib/ResizeObserverBoxOptions.js +7 -0
- package/lib/ResizeObserverCallback.d.ts +4 -0
- package/lib/ResizeObserverCallback.js +1 -0
- package/lib/ResizeObserverController.d.ts +10 -0
- package/lib/ResizeObserverController.js +49 -0
- package/lib/ResizeObserverDetail.d.ts +12 -0
- package/lib/ResizeObserverDetail.js +11 -0
- package/lib/ResizeObserverEntry.d.ts +11 -0
- package/lib/ResizeObserverEntry.js +14 -0
- package/lib/ResizeObserverOptions.d.ts +5 -0
- package/lib/ResizeObserverOptions.js +1 -0
- package/lib/ResizeObserverSize.d.ts +6 -0
- package/lib/ResizeObserverSize.js +10 -0
- package/lib/algorithms/broadcastActiveObservations.d.ts +2 -0
- package/lib/algorithms/broadcastActiveObservations.js +33 -0
- package/lib/algorithms/calculateBoxSize.d.ts +12 -0
- package/lib/algorithms/calculateBoxSize.js +79 -0
- package/lib/algorithms/calculateDepthForNode.d.ts +2 -0
- package/lib/algorithms/calculateDepthForNode.js +14 -0
- package/lib/algorithms/deliverResizeLoopError.d.ts +2 -0
- package/lib/algorithms/deliverResizeLoopError.js +16 -0
- package/lib/algorithms/gatherActiveObservationsAtDepth.d.ts +2 -0
- package/lib/algorithms/gatherActiveObservationsAtDepth.js +19 -0
- package/lib/algorithms/hasActiveObservations.d.ts +2 -0
- package/lib/algorithms/hasActiveObservations.js +5 -0
- package/lib/algorithms/hasSkippedObservations.d.ts +2 -0
- package/lib/algorithms/hasSkippedObservations.js +5 -0
- package/lib/exports/resize-observer.d.ts +3 -0
- package/lib/exports/resize-observer.js +3 -0
- package/lib/exports/resize-observer.umd.js +512 -0
- package/lib/utils/element.d.ts +5 -0
- package/lib/utils/element.js +35 -0
- package/lib/utils/freeze.d.ts +1 -0
- package/lib/utils/freeze.js +1 -0
- package/lib/utils/global.d.ts +10 -0
- package/lib/utils/global.js +1 -0
- package/lib/utils/process.d.ts +2 -0
- package/lib/utils/process.js +18 -0
- package/lib/utils/queueMicroTask.d.ts +2 -0
- package/lib/utils/queueMicroTask.js +15 -0
- package/lib/utils/queueResizeObserver.d.ts +2 -0
- package/lib/utils/queueResizeObserver.js +7 -0
- package/lib/utils/resizeObservers.d.ts +3 -0
- package/lib/utils/resizeObservers.js +2 -0
- package/lib/utils/scheduler.d.ts +14 -0
- package/lib/utils/scheduler.js +100 -0
- package/package.json +88 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { freeze } from './utils/freeze';
|
|
2
|
+
var ResizeObserverSize = (function () {
|
|
3
|
+
function ResizeObserverSize(inlineSize, blockSize) {
|
|
4
|
+
this.inlineSize = inlineSize;
|
|
5
|
+
this.blockSize = blockSize;
|
|
6
|
+
freeze(this);
|
|
7
|
+
}
|
|
8
|
+
return ResizeObserverSize;
|
|
9
|
+
}());
|
|
10
|
+
export { ResizeObserverSize };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { resizeObservers } from '../utils/resizeObservers';
|
|
2
|
+
import { ResizeObserverEntry } from '../ResizeObserverEntry';
|
|
3
|
+
import { calculateDepthForNode } from './calculateDepthForNode';
|
|
4
|
+
import { calculateBoxSize } from './calculateBoxSize';
|
|
5
|
+
var broadcastActiveObservations = function () {
|
|
6
|
+
var shallowestDepth = Infinity;
|
|
7
|
+
var callbacks = [];
|
|
8
|
+
resizeObservers.forEach(function processObserver(ro) {
|
|
9
|
+
if (ro.activeTargets.length === 0) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
var entries = [];
|
|
13
|
+
ro.activeTargets.forEach(function processTarget(ot) {
|
|
14
|
+
var entry = new ResizeObserverEntry(ot.target);
|
|
15
|
+
var targetDepth = calculateDepthForNode(ot.target);
|
|
16
|
+
entries.push(entry);
|
|
17
|
+
ot.lastReportedSize = calculateBoxSize(ot.target, ot.observedBox);
|
|
18
|
+
if (targetDepth < shallowestDepth) {
|
|
19
|
+
shallowestDepth = targetDepth;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
callbacks.push(function resizeObserverCallback() {
|
|
23
|
+
ro.callback.call(ro.observer, entries, ro.observer);
|
|
24
|
+
});
|
|
25
|
+
ro.activeTargets.splice(0, ro.activeTargets.length);
|
|
26
|
+
});
|
|
27
|
+
for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) {
|
|
28
|
+
var callback = callbacks_1[_i];
|
|
29
|
+
callback();
|
|
30
|
+
}
|
|
31
|
+
return shallowestDepth;
|
|
32
|
+
};
|
|
33
|
+
export { broadcastActiveObservations };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ResizeObserverBoxOptions } from '../ResizeObserverBoxOptions';
|
|
2
|
+
import { ResizeObserverSize } from '../ResizeObserverSize';
|
|
3
|
+
import { DOMRectReadOnly } from '../DOMRectReadOnly';
|
|
4
|
+
interface ResizeObserverSizeCollection {
|
|
5
|
+
devicePixelContentBoxSize: ResizeObserverSize;
|
|
6
|
+
borderBoxSize: ResizeObserverSize;
|
|
7
|
+
contentBoxSize: ResizeObserverSize;
|
|
8
|
+
contentRect: DOMRectReadOnly;
|
|
9
|
+
}
|
|
10
|
+
declare const calculateBoxSizes: (target: Element, forceRecalculation?: boolean) => ResizeObserverSizeCollection;
|
|
11
|
+
declare const calculateBoxSize: (target: Element, observedBox: ResizeObserverBoxOptions, forceRecalculation?: boolean) => ResizeObserverSize;
|
|
12
|
+
export { calculateBoxSize, calculateBoxSizes };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ResizeObserverBoxOptions } from '../ResizeObserverBoxOptions';
|
|
2
|
+
import { ResizeObserverSize } from '../ResizeObserverSize';
|
|
3
|
+
import { DOMRectReadOnly } from '../DOMRectReadOnly';
|
|
4
|
+
import { isSVG, isHidden } from '../utils/element';
|
|
5
|
+
import { freeze } from '../utils/freeze';
|
|
6
|
+
import { global } from '../utils/global';
|
|
7
|
+
var cache = new WeakMap();
|
|
8
|
+
var scrollRegexp = /auto|scroll/;
|
|
9
|
+
var verticalRegexp = /^tb|vertical/;
|
|
10
|
+
var IE = (/msie|trident/i).test(global.navigator && global.navigator.userAgent);
|
|
11
|
+
var parseDimension = function (pixel) { return parseFloat(pixel || '0'); };
|
|
12
|
+
var size = function (inlineSize, blockSize, switchSizes) {
|
|
13
|
+
if (inlineSize === void 0) { inlineSize = 0; }
|
|
14
|
+
if (blockSize === void 0) { blockSize = 0; }
|
|
15
|
+
if (switchSizes === void 0) { switchSizes = false; }
|
|
16
|
+
return new ResizeObserverSize((switchSizes ? blockSize : inlineSize) || 0, (switchSizes ? inlineSize : blockSize) || 0);
|
|
17
|
+
};
|
|
18
|
+
var zeroBoxes = freeze({
|
|
19
|
+
devicePixelContentBoxSize: size(),
|
|
20
|
+
borderBoxSize: size(),
|
|
21
|
+
contentBoxSize: size(),
|
|
22
|
+
contentRect: new DOMRectReadOnly(0, 0, 0, 0)
|
|
23
|
+
});
|
|
24
|
+
var calculateBoxSizes = function (target, forceRecalculation) {
|
|
25
|
+
if (forceRecalculation === void 0) { forceRecalculation = false; }
|
|
26
|
+
if (cache.has(target) && !forceRecalculation) {
|
|
27
|
+
return cache.get(target);
|
|
28
|
+
}
|
|
29
|
+
if (isHidden(target)) {
|
|
30
|
+
cache.set(target, zeroBoxes);
|
|
31
|
+
return zeroBoxes;
|
|
32
|
+
}
|
|
33
|
+
var cs = getComputedStyle(target);
|
|
34
|
+
var svg = isSVG(target) && target.ownerSVGElement && target.getBBox();
|
|
35
|
+
var removePadding = !IE && cs.boxSizing === 'border-box';
|
|
36
|
+
var switchSizes = verticalRegexp.test(cs.writingMode || '');
|
|
37
|
+
var canScrollVertically = !svg && scrollRegexp.test(cs.overflowY || '');
|
|
38
|
+
var canScrollHorizontally = !svg && scrollRegexp.test(cs.overflowX || '');
|
|
39
|
+
var paddingTop = svg ? 0 : parseDimension(cs.paddingTop);
|
|
40
|
+
var paddingRight = svg ? 0 : parseDimension(cs.paddingRight);
|
|
41
|
+
var paddingBottom = svg ? 0 : parseDimension(cs.paddingBottom);
|
|
42
|
+
var paddingLeft = svg ? 0 : parseDimension(cs.paddingLeft);
|
|
43
|
+
var borderTop = svg ? 0 : parseDimension(cs.borderTopWidth);
|
|
44
|
+
var borderRight = svg ? 0 : parseDimension(cs.borderRightWidth);
|
|
45
|
+
var borderBottom = svg ? 0 : parseDimension(cs.borderBottomWidth);
|
|
46
|
+
var borderLeft = svg ? 0 : parseDimension(cs.borderLeftWidth);
|
|
47
|
+
var horizontalPadding = paddingLeft + paddingRight;
|
|
48
|
+
var verticalPadding = paddingTop + paddingBottom;
|
|
49
|
+
var horizontalBorderArea = borderLeft + borderRight;
|
|
50
|
+
var verticalBorderArea = borderTop + borderBottom;
|
|
51
|
+
var horizontalScrollbarThickness = !canScrollHorizontally ? 0 : target.offsetHeight - verticalBorderArea - target.clientHeight;
|
|
52
|
+
var verticalScrollbarThickness = !canScrollVertically ? 0 : target.offsetWidth - horizontalBorderArea - target.clientWidth;
|
|
53
|
+
var widthReduction = removePadding ? horizontalPadding + horizontalBorderArea : 0;
|
|
54
|
+
var heightReduction = removePadding ? verticalPadding + verticalBorderArea : 0;
|
|
55
|
+
var contentWidth = svg ? svg.width : parseDimension(cs.width) - widthReduction - verticalScrollbarThickness;
|
|
56
|
+
var contentHeight = svg ? svg.height : parseDimension(cs.height) - heightReduction - horizontalScrollbarThickness;
|
|
57
|
+
var borderBoxWidth = contentWidth + horizontalPadding + verticalScrollbarThickness + horizontalBorderArea;
|
|
58
|
+
var borderBoxHeight = contentHeight + verticalPadding + horizontalScrollbarThickness + verticalBorderArea;
|
|
59
|
+
var boxes = freeze({
|
|
60
|
+
devicePixelContentBoxSize: size(Math.round(contentWidth * devicePixelRatio), Math.round(contentHeight * devicePixelRatio), switchSizes),
|
|
61
|
+
borderBoxSize: size(borderBoxWidth, borderBoxHeight, switchSizes),
|
|
62
|
+
contentBoxSize: size(contentWidth, contentHeight, switchSizes),
|
|
63
|
+
contentRect: new DOMRectReadOnly(paddingLeft, paddingTop, contentWidth, contentHeight)
|
|
64
|
+
});
|
|
65
|
+
cache.set(target, boxes);
|
|
66
|
+
return boxes;
|
|
67
|
+
};
|
|
68
|
+
var calculateBoxSize = function (target, observedBox, forceRecalculation) {
|
|
69
|
+
var _a = calculateBoxSizes(target, forceRecalculation), borderBoxSize = _a.borderBoxSize, contentBoxSize = _a.contentBoxSize, devicePixelContentBoxSize = _a.devicePixelContentBoxSize;
|
|
70
|
+
switch (observedBox) {
|
|
71
|
+
case ResizeObserverBoxOptions.DEVICE_PIXEL_CONTENT_BOX:
|
|
72
|
+
return devicePixelContentBoxSize;
|
|
73
|
+
case ResizeObserverBoxOptions.BORDER_BOX:
|
|
74
|
+
return borderBoxSize;
|
|
75
|
+
default:
|
|
76
|
+
return contentBoxSize;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
export { calculateBoxSize, calculateBoxSizes };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isHidden } from '../utils/element';
|
|
2
|
+
var calculateDepthForNode = function (node) {
|
|
3
|
+
if (isHidden(node)) {
|
|
4
|
+
return Infinity;
|
|
5
|
+
}
|
|
6
|
+
var depth = 0;
|
|
7
|
+
var parent = node.parentNode;
|
|
8
|
+
while (parent) {
|
|
9
|
+
depth += 1;
|
|
10
|
+
parent = parent.parentNode;
|
|
11
|
+
}
|
|
12
|
+
return depth;
|
|
13
|
+
};
|
|
14
|
+
export { calculateDepthForNode };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var msg = 'ResizeObserver loop completed with undelivered notifications.';
|
|
2
|
+
var deliverResizeLoopError = function () {
|
|
3
|
+
var event;
|
|
4
|
+
if (typeof ErrorEvent === 'function') {
|
|
5
|
+
event = new ErrorEvent('error', {
|
|
6
|
+
message: msg
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
event = document.createEvent('Event');
|
|
11
|
+
event.initEvent('error', false, false);
|
|
12
|
+
event.message = msg;
|
|
13
|
+
}
|
|
14
|
+
window.dispatchEvent(event);
|
|
15
|
+
};
|
|
16
|
+
export { deliverResizeLoopError };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { resizeObservers } from '../utils/resizeObservers';
|
|
2
|
+
import { calculateDepthForNode } from './calculateDepthForNode';
|
|
3
|
+
var gatherActiveObservationsAtDepth = function (depth) {
|
|
4
|
+
resizeObservers.forEach(function processObserver(ro) {
|
|
5
|
+
ro.activeTargets.splice(0, ro.activeTargets.length);
|
|
6
|
+
ro.skippedTargets.splice(0, ro.skippedTargets.length);
|
|
7
|
+
ro.observationTargets.forEach(function processTarget(ot) {
|
|
8
|
+
if (ot.isActive()) {
|
|
9
|
+
if (calculateDepthForNode(ot.target) > depth) {
|
|
10
|
+
ro.activeTargets.push(ot);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
ro.skippedTargets.push(ot);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export { gatherActiveObservationsAtDepth };
|