@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,100 @@
|
|
|
1
|
+
import { process } from './process';
|
|
2
|
+
import { global } from './global';
|
|
3
|
+
import { queueResizeObserver } from './queueResizeObserver';
|
|
4
|
+
var watching = 0;
|
|
5
|
+
var isWatching = function () { return !!watching; };
|
|
6
|
+
var CATCH_PERIOD = 250;
|
|
7
|
+
var observerConfig = { attributes: true, characterData: true, childList: true, subtree: true };
|
|
8
|
+
var events = [
|
|
9
|
+
'resize',
|
|
10
|
+
'load',
|
|
11
|
+
'transitionend',
|
|
12
|
+
'animationend',
|
|
13
|
+
'animationstart',
|
|
14
|
+
'animationiteration',
|
|
15
|
+
'keyup',
|
|
16
|
+
'keydown',
|
|
17
|
+
'mouseup',
|
|
18
|
+
'mousedown',
|
|
19
|
+
'mouseover',
|
|
20
|
+
'mouseout',
|
|
21
|
+
'blur',
|
|
22
|
+
'focus'
|
|
23
|
+
];
|
|
24
|
+
var time = function (timeout) {
|
|
25
|
+
if (timeout === void 0) { timeout = 0; }
|
|
26
|
+
return Date.now() + timeout;
|
|
27
|
+
};
|
|
28
|
+
var scheduled = false;
|
|
29
|
+
var Scheduler = (function () {
|
|
30
|
+
function Scheduler() {
|
|
31
|
+
var _this = this;
|
|
32
|
+
this.stopped = true;
|
|
33
|
+
this.listener = function () { return _this.schedule(); };
|
|
34
|
+
}
|
|
35
|
+
Scheduler.prototype.run = function (timeout) {
|
|
36
|
+
var _this = this;
|
|
37
|
+
if (timeout === void 0) { timeout = CATCH_PERIOD; }
|
|
38
|
+
if (scheduled) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
scheduled = true;
|
|
42
|
+
var until = time(timeout);
|
|
43
|
+
queueResizeObserver(function () {
|
|
44
|
+
var elementsHaveResized = false;
|
|
45
|
+
try {
|
|
46
|
+
elementsHaveResized = process();
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
scheduled = false;
|
|
50
|
+
timeout = until - time();
|
|
51
|
+
if (!isWatching()) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (elementsHaveResized) {
|
|
55
|
+
_this.run(1000);
|
|
56
|
+
}
|
|
57
|
+
else if (timeout > 0) {
|
|
58
|
+
_this.run(timeout);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
_this.start();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
Scheduler.prototype.schedule = function () {
|
|
67
|
+
this.stop();
|
|
68
|
+
this.run();
|
|
69
|
+
};
|
|
70
|
+
Scheduler.prototype.observe = function () {
|
|
71
|
+
var _this = this;
|
|
72
|
+
var cb = function () { return _this.observer && _this.observer.observe(document.body, observerConfig); };
|
|
73
|
+
document.body ? cb() : global.addEventListener('DOMContentLoaded', cb);
|
|
74
|
+
};
|
|
75
|
+
Scheduler.prototype.start = function () {
|
|
76
|
+
var _this = this;
|
|
77
|
+
if (this.stopped) {
|
|
78
|
+
this.stopped = false;
|
|
79
|
+
this.observer = new MutationObserver(this.listener);
|
|
80
|
+
this.observe();
|
|
81
|
+
events.forEach(function (name) { return global.addEventListener(name, _this.listener, true); });
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
Scheduler.prototype.stop = function () {
|
|
85
|
+
var _this = this;
|
|
86
|
+
if (!this.stopped) {
|
|
87
|
+
this.observer && this.observer.disconnect();
|
|
88
|
+
events.forEach(function (name) { return global.removeEventListener(name, _this.listener, true); });
|
|
89
|
+
this.stopped = true;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
return Scheduler;
|
|
93
|
+
}());
|
|
94
|
+
var scheduler = new Scheduler();
|
|
95
|
+
var updateCount = function (n) {
|
|
96
|
+
!watching && n > 0 && scheduler.start();
|
|
97
|
+
watching += n;
|
|
98
|
+
!watching && scheduler.stop();
|
|
99
|
+
};
|
|
100
|
+
export { scheduler, updateCount };
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@revivejs/resize-observer",
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "Polyfills the ResizeObserver API and supports box size options from the latest spec",
|
|
5
|
+
"main": "lib/exports/resize-observer.umd.js",
|
|
6
|
+
"module": "lib/exports/resize-observer.js",
|
|
7
|
+
"types": "lib/exports/resize-observer.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/exports/resize-observer.d.ts",
|
|
11
|
+
"import": "./lib/exports/resize-observer.js",
|
|
12
|
+
"require": "./lib/exports/resize-observer.umd.js",
|
|
13
|
+
"default": "./lib/exports/resize-observer.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"files": [
|
|
18
|
+
"lib/**/*.{js,ts}"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"clean": "rm -rf lib docs/index.html docs/page.js docs/page.css",
|
|
22
|
+
"build": "npm run clean && npm run build:lib && npm run build:docs",
|
|
23
|
+
"build:lib": "npm run build:esm && npm run build:umd",
|
|
24
|
+
"build:esm": "tsc",
|
|
25
|
+
"build:umd": "rollup -c",
|
|
26
|
+
"build:docs": "node scripts/build-docs.mjs",
|
|
27
|
+
"build:package": "npm run build",
|
|
28
|
+
"pack:check": "npm pack --dry-run",
|
|
29
|
+
"start": "npm run build:docs && serve docs -l 4173",
|
|
30
|
+
"ci": "npm test && npm run build && npm run pack:check",
|
|
31
|
+
"test": "npm run lint && jest --coverage",
|
|
32
|
+
"lint": "eslint '{src,test}/**/*.ts'",
|
|
33
|
+
"preversion": "npm run build",
|
|
34
|
+
"prepublishOnly": "npm run build"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/alexandroit/resize-observer.git"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"resize-observer",
|
|
42
|
+
"polyfill",
|
|
43
|
+
"ponyfill",
|
|
44
|
+
"browser",
|
|
45
|
+
"dom",
|
|
46
|
+
"resize",
|
|
47
|
+
"observer",
|
|
48
|
+
"typescript",
|
|
49
|
+
"javascript",
|
|
50
|
+
"element",
|
|
51
|
+
"element-resize",
|
|
52
|
+
"responsive",
|
|
53
|
+
"web-components",
|
|
54
|
+
"ui",
|
|
55
|
+
"angular",
|
|
56
|
+
"react",
|
|
57
|
+
"vue",
|
|
58
|
+
"maintained",
|
|
59
|
+
"revived"
|
|
60
|
+
],
|
|
61
|
+
"author": "Alexandro Paixao Marques",
|
|
62
|
+
"contributors": [
|
|
63
|
+
"Juggle (original project)"
|
|
64
|
+
],
|
|
65
|
+
"license": "Apache-2.0",
|
|
66
|
+
"bugs": {
|
|
67
|
+
"url": "https://github.com/alexandroit/resize-observer/issues"
|
|
68
|
+
},
|
|
69
|
+
"homepage": "https://alexandroit.github.io/resize-observer/",
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=18"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@types/jest": "^28.1.7",
|
|
75
|
+
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
76
|
+
"@typescript-eslint/parser": "^5.33.1",
|
|
77
|
+
"esbuild": "^0.25.11",
|
|
78
|
+
"eslint": "^8.22.0",
|
|
79
|
+
"jest": "^28.1.3",
|
|
80
|
+
"jest-environment-jsdom": "^28.1.3",
|
|
81
|
+
"jest-junit": "^14.0.0",
|
|
82
|
+
"jsdom": "^20.0.0",
|
|
83
|
+
"rollup": "^2.78.0",
|
|
84
|
+
"serve": "^14.2.5",
|
|
85
|
+
"ts-jest": "^28.0.8",
|
|
86
|
+
"typescript": "^4.7.4"
|
|
87
|
+
}
|
|
88
|
+
}
|