@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.
Files changed (56) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +159 -0
  3. package/lib/DOMRectReadOnly.d.ts +30 -0
  4. package/lib/DOMRectReadOnly.js +23 -0
  5. package/lib/ResizeObservation.d.ts +10 -0
  6. package/lib/ResizeObservation.js +31 -0
  7. package/lib/ResizeObserver.d.ts +10 -0
  8. package/lib/ResizeObserver.js +39 -0
  9. package/lib/ResizeObserverBoxOptions.d.ts +6 -0
  10. package/lib/ResizeObserverBoxOptions.js +7 -0
  11. package/lib/ResizeObserverCallback.d.ts +4 -0
  12. package/lib/ResizeObserverCallback.js +1 -0
  13. package/lib/ResizeObserverController.d.ts +10 -0
  14. package/lib/ResizeObserverController.js +49 -0
  15. package/lib/ResizeObserverDetail.d.ts +12 -0
  16. package/lib/ResizeObserverDetail.js +11 -0
  17. package/lib/ResizeObserverEntry.d.ts +11 -0
  18. package/lib/ResizeObserverEntry.js +14 -0
  19. package/lib/ResizeObserverOptions.d.ts +5 -0
  20. package/lib/ResizeObserverOptions.js +1 -0
  21. package/lib/ResizeObserverSize.d.ts +6 -0
  22. package/lib/ResizeObserverSize.js +10 -0
  23. package/lib/algorithms/broadcastActiveObservations.d.ts +2 -0
  24. package/lib/algorithms/broadcastActiveObservations.js +33 -0
  25. package/lib/algorithms/calculateBoxSize.d.ts +12 -0
  26. package/lib/algorithms/calculateBoxSize.js +79 -0
  27. package/lib/algorithms/calculateDepthForNode.d.ts +2 -0
  28. package/lib/algorithms/calculateDepthForNode.js +14 -0
  29. package/lib/algorithms/deliverResizeLoopError.d.ts +2 -0
  30. package/lib/algorithms/deliverResizeLoopError.js +16 -0
  31. package/lib/algorithms/gatherActiveObservationsAtDepth.d.ts +2 -0
  32. package/lib/algorithms/gatherActiveObservationsAtDepth.js +19 -0
  33. package/lib/algorithms/hasActiveObservations.d.ts +2 -0
  34. package/lib/algorithms/hasActiveObservations.js +5 -0
  35. package/lib/algorithms/hasSkippedObservations.d.ts +2 -0
  36. package/lib/algorithms/hasSkippedObservations.js +5 -0
  37. package/lib/exports/resize-observer.d.ts +3 -0
  38. package/lib/exports/resize-observer.js +3 -0
  39. package/lib/exports/resize-observer.umd.js +512 -0
  40. package/lib/utils/element.d.ts +5 -0
  41. package/lib/utils/element.js +35 -0
  42. package/lib/utils/freeze.d.ts +1 -0
  43. package/lib/utils/freeze.js +1 -0
  44. package/lib/utils/global.d.ts +10 -0
  45. package/lib/utils/global.js +1 -0
  46. package/lib/utils/process.d.ts +2 -0
  47. package/lib/utils/process.js +18 -0
  48. package/lib/utils/queueMicroTask.d.ts +2 -0
  49. package/lib/utils/queueMicroTask.js +15 -0
  50. package/lib/utils/queueResizeObserver.d.ts +2 -0
  51. package/lib/utils/queueResizeObserver.js +7 -0
  52. package/lib/utils/resizeObservers.d.ts +3 -0
  53. package/lib/utils/resizeObservers.js +2 -0
  54. package/lib/utils/scheduler.d.ts +14 -0
  55. package/lib/utils/scheduler.js +100 -0
  56. package/package.json +88 -0
@@ -0,0 +1,512 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ResizeObserver = {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ var resizeObservers = [];
8
+
9
+ var hasActiveObservations = function () {
10
+ return resizeObservers.some(function (ro) { return ro.activeTargets.length > 0; });
11
+ };
12
+
13
+ var hasSkippedObservations = function () {
14
+ return resizeObservers.some(function (ro) { return ro.skippedTargets.length > 0; });
15
+ };
16
+
17
+ var msg = 'ResizeObserver loop completed with undelivered notifications.';
18
+ var deliverResizeLoopError = function () {
19
+ var event;
20
+ if (typeof ErrorEvent === 'function') {
21
+ event = new ErrorEvent('error', {
22
+ message: msg
23
+ });
24
+ }
25
+ else {
26
+ event = document.createEvent('Event');
27
+ event.initEvent('error', false, false);
28
+ event.message = msg;
29
+ }
30
+ window.dispatchEvent(event);
31
+ };
32
+
33
+ var ResizeObserverBoxOptions;
34
+ (function (ResizeObserverBoxOptions) {
35
+ ResizeObserverBoxOptions["BORDER_BOX"] = "border-box";
36
+ ResizeObserverBoxOptions["CONTENT_BOX"] = "content-box";
37
+ ResizeObserverBoxOptions["DEVICE_PIXEL_CONTENT_BOX"] = "device-pixel-content-box";
38
+ })(ResizeObserverBoxOptions || (ResizeObserverBoxOptions = {}));
39
+
40
+ var freeze = function (obj) { return Object.freeze(obj); };
41
+
42
+ var ResizeObserverSize = (function () {
43
+ function ResizeObserverSize(inlineSize, blockSize) {
44
+ this.inlineSize = inlineSize;
45
+ this.blockSize = blockSize;
46
+ freeze(this);
47
+ }
48
+ return ResizeObserverSize;
49
+ }());
50
+
51
+ var DOMRectReadOnly = (function () {
52
+ function DOMRectReadOnly(x, y, width, height) {
53
+ this.x = x;
54
+ this.y = y;
55
+ this.width = width;
56
+ this.height = height;
57
+ this.top = this.y;
58
+ this.left = this.x;
59
+ this.bottom = this.top + this.height;
60
+ this.right = this.left + this.width;
61
+ return freeze(this);
62
+ }
63
+ DOMRectReadOnly.prototype.toJSON = function () {
64
+ var _a = this, x = _a.x, y = _a.y, top = _a.top, right = _a.right, bottom = _a.bottom, left = _a.left, width = _a.width, height = _a.height;
65
+ return { x: x, y: y, top: top, right: right, bottom: bottom, left: left, width: width, height: height };
66
+ };
67
+ DOMRectReadOnly.fromRect = function (rectangle) {
68
+ return new DOMRectReadOnly(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
69
+ };
70
+ return DOMRectReadOnly;
71
+ }());
72
+
73
+ var isSVG = function (target) { return target instanceof SVGElement && 'getBBox' in target; };
74
+ var isHidden = function (target) {
75
+ if (isSVG(target)) {
76
+ var _a = target.getBBox(), width = _a.width, height = _a.height;
77
+ return !width && !height;
78
+ }
79
+ var _b = target, offsetWidth = _b.offsetWidth, offsetHeight = _b.offsetHeight;
80
+ return !(offsetWidth || offsetHeight || target.getClientRects().length);
81
+ };
82
+ var isElement = function (obj) {
83
+ var _a;
84
+ if (obj instanceof Element) {
85
+ return true;
86
+ }
87
+ var scope = (_a = obj === null || obj === void 0 ? void 0 : obj.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
88
+ return !!(scope && obj instanceof scope.Element);
89
+ };
90
+ var isReplacedElement = function (target) {
91
+ switch (target.tagName) {
92
+ case 'INPUT':
93
+ if (target.type !== 'image') {
94
+ break;
95
+ }
96
+ case 'VIDEO':
97
+ case 'AUDIO':
98
+ case 'EMBED':
99
+ case 'OBJECT':
100
+ case 'CANVAS':
101
+ case 'IFRAME':
102
+ case 'IMG':
103
+ return true;
104
+ }
105
+ return false;
106
+ };
107
+
108
+ var global = typeof window !== 'undefined' ? window : {};
109
+
110
+ var cache = new WeakMap();
111
+ var scrollRegexp = /auto|scroll/;
112
+ var verticalRegexp = /^tb|vertical/;
113
+ var IE = (/msie|trident/i).test(global.navigator && global.navigator.userAgent);
114
+ var parseDimension = function (pixel) { return parseFloat(pixel || '0'); };
115
+ var size = function (inlineSize, blockSize, switchSizes) {
116
+ if (inlineSize === void 0) { inlineSize = 0; }
117
+ if (blockSize === void 0) { blockSize = 0; }
118
+ if (switchSizes === void 0) { switchSizes = false; }
119
+ return new ResizeObserverSize((switchSizes ? blockSize : inlineSize) || 0, (switchSizes ? inlineSize : blockSize) || 0);
120
+ };
121
+ var zeroBoxes = freeze({
122
+ devicePixelContentBoxSize: size(),
123
+ borderBoxSize: size(),
124
+ contentBoxSize: size(),
125
+ contentRect: new DOMRectReadOnly(0, 0, 0, 0)
126
+ });
127
+ var calculateBoxSizes = function (target, forceRecalculation) {
128
+ if (forceRecalculation === void 0) { forceRecalculation = false; }
129
+ if (cache.has(target) && !forceRecalculation) {
130
+ return cache.get(target);
131
+ }
132
+ if (isHidden(target)) {
133
+ cache.set(target, zeroBoxes);
134
+ return zeroBoxes;
135
+ }
136
+ var cs = getComputedStyle(target);
137
+ var svg = isSVG(target) && target.ownerSVGElement && target.getBBox();
138
+ var removePadding = !IE && cs.boxSizing === 'border-box';
139
+ var switchSizes = verticalRegexp.test(cs.writingMode || '');
140
+ var canScrollVertically = !svg && scrollRegexp.test(cs.overflowY || '');
141
+ var canScrollHorizontally = !svg && scrollRegexp.test(cs.overflowX || '');
142
+ var paddingTop = svg ? 0 : parseDimension(cs.paddingTop);
143
+ var paddingRight = svg ? 0 : parseDimension(cs.paddingRight);
144
+ var paddingBottom = svg ? 0 : parseDimension(cs.paddingBottom);
145
+ var paddingLeft = svg ? 0 : parseDimension(cs.paddingLeft);
146
+ var borderTop = svg ? 0 : parseDimension(cs.borderTopWidth);
147
+ var borderRight = svg ? 0 : parseDimension(cs.borderRightWidth);
148
+ var borderBottom = svg ? 0 : parseDimension(cs.borderBottomWidth);
149
+ var borderLeft = svg ? 0 : parseDimension(cs.borderLeftWidth);
150
+ var horizontalPadding = paddingLeft + paddingRight;
151
+ var verticalPadding = paddingTop + paddingBottom;
152
+ var horizontalBorderArea = borderLeft + borderRight;
153
+ var verticalBorderArea = borderTop + borderBottom;
154
+ var horizontalScrollbarThickness = !canScrollHorizontally ? 0 : target.offsetHeight - verticalBorderArea - target.clientHeight;
155
+ var verticalScrollbarThickness = !canScrollVertically ? 0 : target.offsetWidth - horizontalBorderArea - target.clientWidth;
156
+ var widthReduction = removePadding ? horizontalPadding + horizontalBorderArea : 0;
157
+ var heightReduction = removePadding ? verticalPadding + verticalBorderArea : 0;
158
+ var contentWidth = svg ? svg.width : parseDimension(cs.width) - widthReduction - verticalScrollbarThickness;
159
+ var contentHeight = svg ? svg.height : parseDimension(cs.height) - heightReduction - horizontalScrollbarThickness;
160
+ var borderBoxWidth = contentWidth + horizontalPadding + verticalScrollbarThickness + horizontalBorderArea;
161
+ var borderBoxHeight = contentHeight + verticalPadding + horizontalScrollbarThickness + verticalBorderArea;
162
+ var boxes = freeze({
163
+ devicePixelContentBoxSize: size(Math.round(contentWidth * devicePixelRatio), Math.round(contentHeight * devicePixelRatio), switchSizes),
164
+ borderBoxSize: size(borderBoxWidth, borderBoxHeight, switchSizes),
165
+ contentBoxSize: size(contentWidth, contentHeight, switchSizes),
166
+ contentRect: new DOMRectReadOnly(paddingLeft, paddingTop, contentWidth, contentHeight)
167
+ });
168
+ cache.set(target, boxes);
169
+ return boxes;
170
+ };
171
+ var calculateBoxSize = function (target, observedBox, forceRecalculation) {
172
+ var _a = calculateBoxSizes(target, forceRecalculation), borderBoxSize = _a.borderBoxSize, contentBoxSize = _a.contentBoxSize, devicePixelContentBoxSize = _a.devicePixelContentBoxSize;
173
+ switch (observedBox) {
174
+ case ResizeObserverBoxOptions.DEVICE_PIXEL_CONTENT_BOX:
175
+ return devicePixelContentBoxSize;
176
+ case ResizeObserverBoxOptions.BORDER_BOX:
177
+ return borderBoxSize;
178
+ default:
179
+ return contentBoxSize;
180
+ }
181
+ };
182
+
183
+ var ResizeObserverEntry = (function () {
184
+ function ResizeObserverEntry(target) {
185
+ var boxes = calculateBoxSizes(target);
186
+ this.target = target;
187
+ this.contentRect = boxes.contentRect;
188
+ this.borderBoxSize = freeze([boxes.borderBoxSize]);
189
+ this.contentBoxSize = freeze([boxes.contentBoxSize]);
190
+ this.devicePixelContentBoxSize = freeze([boxes.devicePixelContentBoxSize]);
191
+ }
192
+ return ResizeObserverEntry;
193
+ }());
194
+
195
+ var calculateDepthForNode = function (node) {
196
+ if (isHidden(node)) {
197
+ return Infinity;
198
+ }
199
+ var depth = 0;
200
+ var parent = node.parentNode;
201
+ while (parent) {
202
+ depth += 1;
203
+ parent = parent.parentNode;
204
+ }
205
+ return depth;
206
+ };
207
+
208
+ var broadcastActiveObservations = function () {
209
+ var shallowestDepth = Infinity;
210
+ var callbacks = [];
211
+ resizeObservers.forEach(function processObserver(ro) {
212
+ if (ro.activeTargets.length === 0) {
213
+ return;
214
+ }
215
+ var entries = [];
216
+ ro.activeTargets.forEach(function processTarget(ot) {
217
+ var entry = new ResizeObserverEntry(ot.target);
218
+ var targetDepth = calculateDepthForNode(ot.target);
219
+ entries.push(entry);
220
+ ot.lastReportedSize = calculateBoxSize(ot.target, ot.observedBox);
221
+ if (targetDepth < shallowestDepth) {
222
+ shallowestDepth = targetDepth;
223
+ }
224
+ });
225
+ callbacks.push(function resizeObserverCallback() {
226
+ ro.callback.call(ro.observer, entries, ro.observer);
227
+ });
228
+ ro.activeTargets.splice(0, ro.activeTargets.length);
229
+ });
230
+ for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) {
231
+ var callback = callbacks_1[_i];
232
+ callback();
233
+ }
234
+ return shallowestDepth;
235
+ };
236
+
237
+ var gatherActiveObservationsAtDepth = function (depth) {
238
+ resizeObservers.forEach(function processObserver(ro) {
239
+ ro.activeTargets.splice(0, ro.activeTargets.length);
240
+ ro.skippedTargets.splice(0, ro.skippedTargets.length);
241
+ ro.observationTargets.forEach(function processTarget(ot) {
242
+ if (ot.isActive()) {
243
+ if (calculateDepthForNode(ot.target) > depth) {
244
+ ro.activeTargets.push(ot);
245
+ }
246
+ else {
247
+ ro.skippedTargets.push(ot);
248
+ }
249
+ }
250
+ });
251
+ });
252
+ };
253
+
254
+ var processAlgorithm = function () {
255
+ var depth = 0;
256
+ gatherActiveObservationsAtDepth(depth);
257
+ while (hasActiveObservations()) {
258
+ depth = broadcastActiveObservations();
259
+ gatherActiveObservationsAtDepth(depth);
260
+ }
261
+ if (hasSkippedObservations()) {
262
+ deliverResizeLoopError();
263
+ }
264
+ return depth > 0;
265
+ };
266
+
267
+ var trigger;
268
+ var callbacks = [];
269
+ var notify = function () { return callbacks.splice(0).forEach(function (cb) { return cb(); }); };
270
+ var queueMicroTask = function (callback) {
271
+ if (!trigger) {
272
+ var toggle_1 = 0;
273
+ var el_1 = document.createTextNode('');
274
+ var config = { characterData: true };
275
+ new MutationObserver(function () { return notify(); }).observe(el_1, config);
276
+ trigger = function () { el_1.textContent = "".concat(toggle_1 ? toggle_1-- : toggle_1++); };
277
+ }
278
+ callbacks.push(callback);
279
+ trigger();
280
+ };
281
+
282
+ var queueResizeObserver = function (cb) {
283
+ queueMicroTask(function ResizeObserver() {
284
+ requestAnimationFrame(cb);
285
+ });
286
+ };
287
+
288
+ var watching = 0;
289
+ var isWatching = function () { return !!watching; };
290
+ var CATCH_PERIOD = 250;
291
+ var observerConfig = { attributes: true, characterData: true, childList: true, subtree: true };
292
+ var events = [
293
+ 'resize',
294
+ 'load',
295
+ 'transitionend',
296
+ 'animationend',
297
+ 'animationstart',
298
+ 'animationiteration',
299
+ 'keyup',
300
+ 'keydown',
301
+ 'mouseup',
302
+ 'mousedown',
303
+ 'mouseover',
304
+ 'mouseout',
305
+ 'blur',
306
+ 'focus'
307
+ ];
308
+ var time = function (timeout) {
309
+ if (timeout === void 0) { timeout = 0; }
310
+ return Date.now() + timeout;
311
+ };
312
+ var scheduled = false;
313
+ var Scheduler = (function () {
314
+ function Scheduler() {
315
+ var _this = this;
316
+ this.stopped = true;
317
+ this.listener = function () { return _this.schedule(); };
318
+ }
319
+ Scheduler.prototype.run = function (timeout) {
320
+ var _this = this;
321
+ if (timeout === void 0) { timeout = CATCH_PERIOD; }
322
+ if (scheduled) {
323
+ return;
324
+ }
325
+ scheduled = true;
326
+ var until = time(timeout);
327
+ queueResizeObserver(function () {
328
+ var elementsHaveResized = false;
329
+ try {
330
+ elementsHaveResized = processAlgorithm();
331
+ }
332
+ finally {
333
+ scheduled = false;
334
+ timeout = until - time();
335
+ if (!isWatching()) {
336
+ return;
337
+ }
338
+ if (elementsHaveResized) {
339
+ _this.run(1000);
340
+ }
341
+ else if (timeout > 0) {
342
+ _this.run(timeout);
343
+ }
344
+ else {
345
+ _this.start();
346
+ }
347
+ }
348
+ });
349
+ };
350
+ Scheduler.prototype.schedule = function () {
351
+ this.stop();
352
+ this.run();
353
+ };
354
+ Scheduler.prototype.observe = function () {
355
+ var _this = this;
356
+ var cb = function () { return _this.observer && _this.observer.observe(document.body, observerConfig); };
357
+ document.body ? cb() : global.addEventListener('DOMContentLoaded', cb);
358
+ };
359
+ Scheduler.prototype.start = function () {
360
+ var _this = this;
361
+ if (this.stopped) {
362
+ this.stopped = false;
363
+ this.observer = new MutationObserver(this.listener);
364
+ this.observe();
365
+ events.forEach(function (name) { return global.addEventListener(name, _this.listener, true); });
366
+ }
367
+ };
368
+ Scheduler.prototype.stop = function () {
369
+ var _this = this;
370
+ if (!this.stopped) {
371
+ this.observer && this.observer.disconnect();
372
+ events.forEach(function (name) { return global.removeEventListener(name, _this.listener, true); });
373
+ this.stopped = true;
374
+ }
375
+ };
376
+ return Scheduler;
377
+ }());
378
+ var scheduler = new Scheduler();
379
+ var updateCount = function (n) {
380
+ !watching && n > 0 && scheduler.start();
381
+ watching += n;
382
+ !watching && scheduler.stop();
383
+ };
384
+
385
+ var skipNotifyOnElement = function (target) {
386
+ return !isSVG(target)
387
+ && !isReplacedElement(target)
388
+ && getComputedStyle(target).display === 'inline';
389
+ };
390
+ var ResizeObservation = (function () {
391
+ function ResizeObservation(target, observedBox) {
392
+ this.target = target;
393
+ this.observedBox = observedBox || ResizeObserverBoxOptions.CONTENT_BOX;
394
+ this.lastReportedSize = {
395
+ inlineSize: -1,
396
+ blockSize: -1
397
+ };
398
+ }
399
+ ResizeObservation.prototype.isActive = function () {
400
+ var size = calculateBoxSize(this.target, this.observedBox, true);
401
+ if (skipNotifyOnElement(this.target)) {
402
+ this.lastReportedSize = size;
403
+ }
404
+ if (this.lastReportedSize.inlineSize !== size.inlineSize
405
+ || this.lastReportedSize.blockSize !== size.blockSize) {
406
+ return true;
407
+ }
408
+ return false;
409
+ };
410
+ return ResizeObservation;
411
+ }());
412
+
413
+ var ResizeObserverDetail = (function () {
414
+ function ResizeObserverDetail(resizeObserver, callback) {
415
+ this.activeTargets = [];
416
+ this.skippedTargets = [];
417
+ this.observationTargets = [];
418
+ this.observer = resizeObserver;
419
+ this.callback = callback;
420
+ }
421
+ return ResizeObserverDetail;
422
+ }());
423
+
424
+ var observerMap = new WeakMap();
425
+ var getObservationIndex = function (observationTargets, target) {
426
+ for (var i = 0; i < observationTargets.length; i += 1) {
427
+ if (observationTargets[i].target === target) {
428
+ return i;
429
+ }
430
+ }
431
+ return -1;
432
+ };
433
+ var ResizeObserverController = (function () {
434
+ function ResizeObserverController() {
435
+ }
436
+ ResizeObserverController.connect = function (resizeObserver, callback) {
437
+ var detail = new ResizeObserverDetail(resizeObserver, callback);
438
+ observerMap.set(resizeObserver, detail);
439
+ };
440
+ ResizeObserverController.observe = function (resizeObserver, target, options) {
441
+ var detail = observerMap.get(resizeObserver);
442
+ var firstObservation = detail.observationTargets.length === 0;
443
+ if (getObservationIndex(detail.observationTargets, target) < 0) {
444
+ firstObservation && resizeObservers.push(detail);
445
+ detail.observationTargets.push(new ResizeObservation(target, options && options.box));
446
+ updateCount(1);
447
+ scheduler.schedule();
448
+ }
449
+ };
450
+ ResizeObserverController.unobserve = function (resizeObserver, target) {
451
+ var detail = observerMap.get(resizeObserver);
452
+ var index = getObservationIndex(detail.observationTargets, target);
453
+ var lastObservation = detail.observationTargets.length === 1;
454
+ if (index >= 0) {
455
+ lastObservation && resizeObservers.splice(resizeObservers.indexOf(detail), 1);
456
+ detail.observationTargets.splice(index, 1);
457
+ updateCount(-1);
458
+ }
459
+ };
460
+ ResizeObserverController.disconnect = function (resizeObserver) {
461
+ var _this = this;
462
+ var detail = observerMap.get(resizeObserver);
463
+ detail.observationTargets.slice().forEach(function (ot) { return _this.unobserve(resizeObserver, ot.target); });
464
+ detail.activeTargets.splice(0, detail.activeTargets.length);
465
+ };
466
+ return ResizeObserverController;
467
+ }());
468
+
469
+ var ResizeObserver = (function () {
470
+ function ResizeObserver(callback) {
471
+ if (arguments.length === 0) {
472
+ throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");
473
+ }
474
+ if (typeof callback !== 'function') {
475
+ throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");
476
+ }
477
+ ResizeObserverController.connect(this, callback);
478
+ }
479
+ ResizeObserver.prototype.observe = function (target, options) {
480
+ if (arguments.length === 0) {
481
+ throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");
482
+ }
483
+ if (!isElement(target)) {
484
+ throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");
485
+ }
486
+ ResizeObserverController.observe(this, target, options);
487
+ };
488
+ ResizeObserver.prototype.unobserve = function (target) {
489
+ if (arguments.length === 0) {
490
+ throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");
491
+ }
492
+ if (!isElement(target)) {
493
+ throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");
494
+ }
495
+ ResizeObserverController.unobserve(this, target);
496
+ };
497
+ ResizeObserver.prototype.disconnect = function () {
498
+ ResizeObserverController.disconnect(this);
499
+ };
500
+ ResizeObserver.toString = function () {
501
+ return 'function ResizeObserver () { [polyfill code] }';
502
+ };
503
+ return ResizeObserver;
504
+ }());
505
+
506
+ exports.ResizeObserver = ResizeObserver;
507
+ exports.ResizeObserverEntry = ResizeObserverEntry;
508
+ exports.ResizeObserverSize = ResizeObserverSize;
509
+
510
+ Object.defineProperty(exports, '__esModule', { value: true });
511
+
512
+ }));
@@ -0,0 +1,5 @@
1
+ declare const isSVG: (target: Element) => boolean;
2
+ declare const isHidden: (target: Element) => boolean;
3
+ declare const isElement: (obj: unknown) => boolean;
4
+ declare const isReplacedElement: (target: Element) => boolean;
5
+ export { isSVG, isHidden, isElement, isReplacedElement };
@@ -0,0 +1,35 @@
1
+ var isSVG = function (target) { return target instanceof SVGElement && 'getBBox' in target; };
2
+ var isHidden = function (target) {
3
+ if (isSVG(target)) {
4
+ var _a = target.getBBox(), width = _a.width, height = _a.height;
5
+ return !width && !height;
6
+ }
7
+ var _b = target, offsetWidth = _b.offsetWidth, offsetHeight = _b.offsetHeight;
8
+ return !(offsetWidth || offsetHeight || target.getClientRects().length);
9
+ };
10
+ var isElement = function (obj) {
11
+ var _a;
12
+ if (obj instanceof Element) {
13
+ return true;
14
+ }
15
+ var scope = (_a = obj === null || obj === void 0 ? void 0 : obj.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
16
+ return !!(scope && obj instanceof scope.Element);
17
+ };
18
+ var isReplacedElement = function (target) {
19
+ switch (target.tagName) {
20
+ case 'INPUT':
21
+ if (target.type !== 'image') {
22
+ break;
23
+ }
24
+ case 'VIDEO':
25
+ case 'AUDIO':
26
+ case 'EMBED':
27
+ case 'OBJECT':
28
+ case 'CANVAS':
29
+ case 'IFRAME':
30
+ case 'IMG':
31
+ return true;
32
+ }
33
+ return false;
34
+ };
35
+ export { isSVG, isHidden, isElement, isReplacedElement };
@@ -0,0 +1 @@
1
+ export declare const freeze: <T>(obj: T) => Readonly<T>;
@@ -0,0 +1 @@
1
+ export var freeze = function (obj) { return Object.freeze(obj); };
@@ -0,0 +1,10 @@
1
+ import { ResizeObserver } from '../ResizeObserver';
2
+ import { ResizeObserverEntry } from '../ResizeObserverEntry';
3
+ import { ResizeObserverSize } from '../ResizeObserverSize';
4
+ declare type IsomorphicWindow = Window & {
5
+ ResizeObserver?: typeof ResizeObserver;
6
+ ResizeObserverEntry?: typeof ResizeObserverEntry;
7
+ ResizeObserverSize?: typeof ResizeObserverSize;
8
+ };
9
+ export declare const global: IsomorphicWindow;
10
+ export {};
@@ -0,0 +1 @@
1
+ export var global = typeof window !== 'undefined' ? window : {};
@@ -0,0 +1,2 @@
1
+ declare const processAlgorithm: () => boolean;
2
+ export { processAlgorithm as process };
@@ -0,0 +1,18 @@
1
+ import { hasActiveObservations } from '../algorithms/hasActiveObservations';
2
+ import { hasSkippedObservations } from '../algorithms/hasSkippedObservations';
3
+ import { deliverResizeLoopError } from '../algorithms/deliverResizeLoopError';
4
+ import { broadcastActiveObservations } from '../algorithms/broadcastActiveObservations';
5
+ import { gatherActiveObservationsAtDepth } from '../algorithms/gatherActiveObservationsAtDepth';
6
+ var processAlgorithm = function () {
7
+ var depth = 0;
8
+ gatherActiveObservationsAtDepth(depth);
9
+ while (hasActiveObservations()) {
10
+ depth = broadcastActiveObservations();
11
+ gatherActiveObservationsAtDepth(depth);
12
+ }
13
+ if (hasSkippedObservations()) {
14
+ deliverResizeLoopError();
15
+ }
16
+ return depth > 0;
17
+ };
18
+ export { processAlgorithm as process };
@@ -0,0 +1,2 @@
1
+ declare const queueMicroTask: (callback: () => void) => void;
2
+ export { queueMicroTask };
@@ -0,0 +1,15 @@
1
+ var trigger;
2
+ var callbacks = [];
3
+ var notify = function () { return callbacks.splice(0).forEach(function (cb) { return cb(); }); };
4
+ var queueMicroTask = function (callback) {
5
+ if (!trigger) {
6
+ var toggle_1 = 0;
7
+ var el_1 = document.createTextNode('');
8
+ var config = { characterData: true };
9
+ new MutationObserver(function () { return notify(); }).observe(el_1, config);
10
+ trigger = function () { el_1.textContent = "".concat(toggle_1 ? toggle_1-- : toggle_1++); };
11
+ }
12
+ callbacks.push(callback);
13
+ trigger();
14
+ };
15
+ export { queueMicroTask };
@@ -0,0 +1,2 @@
1
+ declare const queueResizeObserver: (cb: () => void) => void;
2
+ export { queueResizeObserver };
@@ -0,0 +1,7 @@
1
+ import { queueMicroTask } from './queueMicroTask';
2
+ var queueResizeObserver = function (cb) {
3
+ queueMicroTask(function ResizeObserver() {
4
+ requestAnimationFrame(cb);
5
+ });
6
+ };
7
+ export { queueResizeObserver };
@@ -0,0 +1,3 @@
1
+ import { ResizeObserverDetail } from '../ResizeObserverDetail';
2
+ declare const resizeObservers: ResizeObserverDetail[];
3
+ export { resizeObservers };
@@ -0,0 +1,2 @@
1
+ var resizeObservers = [];
2
+ export { resizeObservers };
@@ -0,0 +1,14 @@
1
+ declare class Scheduler {
2
+ private observer;
3
+ private listener;
4
+ stopped: boolean;
5
+ constructor();
6
+ private run;
7
+ schedule(): void;
8
+ private observe;
9
+ start(): void;
10
+ stop(): void;
11
+ }
12
+ declare const scheduler: Scheduler;
13
+ declare const updateCount: (n: number) => void;
14
+ export { scheduler, updateCount };