@jobber/hooks 2.17.4 → 2.18.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 (148) hide show
  1. package/dist/index.cjs +49 -0
  2. package/dist/index.mjs +23 -0
  3. package/dist/isObjectLike-cjs.js +228 -0
  4. package/dist/isObjectLike-es.js +219 -0
  5. package/dist/useBool/index.cjs +8 -0
  6. package/dist/useBool/index.mjs +2 -0
  7. package/dist/useBool-cjs.js +13 -0
  8. package/dist/useBool-es.js +11 -0
  9. package/dist/useBreakpoints/index.cjs +11 -0
  10. package/dist/useBreakpoints/index.mjs +3 -0
  11. package/dist/useBreakpoints/mockViewportWidth/{mockViewportWidth.js → index.cjs} +5 -4
  12. package/dist/useBreakpoints/mockViewportWidth/index.mjs +66 -0
  13. package/dist/useBreakpoints-cjs.js +48 -0
  14. package/dist/useBreakpoints-es.js +45 -0
  15. package/dist/useCallbackRef/index.cjs +8 -0
  16. package/dist/useCallbackRef/index.mjs +2 -0
  17. package/dist/useCallbackRef-cjs.js +17 -0
  18. package/dist/useCallbackRef-es.js +15 -0
  19. package/dist/useCollectionQuery/index.cjs +13 -0
  20. package/dist/useCollectionQuery/index.mjs +7 -0
  21. package/dist/useCollectionQuery/useCollectionQuery.d.ts +1 -1
  22. package/dist/useCollectionQuery-cjs.js +2842 -0
  23. package/dist/useCollectionQuery-es.js +2821 -0
  24. package/dist/useDebounce/index.cjs +9 -0
  25. package/dist/useDebounce/index.mjs +3 -0
  26. package/dist/useDebounce-cjs.js +92 -0
  27. package/dist/useDebounce-es.js +90 -0
  28. package/dist/useFocusTrap/index.cjs +8 -0
  29. package/dist/useFocusTrap/index.mjs +2 -0
  30. package/dist/{useFocusTrap/useFocusTrap.js → useFocusTrap-cjs.js} +8 -6
  31. package/dist/useFocusTrap-es.js +68 -0
  32. package/dist/useFormState/index.cjs +8 -0
  33. package/dist/useFormState/index.mjs +2 -0
  34. package/dist/useFormState-cjs.js +13 -0
  35. package/dist/useFormState-es.js +11 -0
  36. package/dist/useInView/index.cjs +8 -0
  37. package/dist/useInView/index.mjs +2 -0
  38. package/dist/{useInView/useInView.js → useInView-cjs.js} +10 -8
  39. package/dist/useInView-es.js +19 -0
  40. package/dist/useIsMounted/index.cjs +9 -0
  41. package/dist/useIsMounted/index.mjs +3 -0
  42. package/dist/{useIsMounted/useIsMounted.js → useIsMounted-cjs.js} +9 -7
  43. package/dist/useIsMounted-es.js +34 -0
  44. package/dist/useLiveAnnounce/index.cjs +8 -0
  45. package/dist/useLiveAnnounce/index.mjs +2 -0
  46. package/dist/{useLiveAnnounce/useLiveAnnounce.js → useLiveAnnounce-cjs.js} +8 -6
  47. package/dist/useLiveAnnounce-es.js +41 -0
  48. package/dist/useOnKeyDown/index.cjs +8 -0
  49. package/dist/useOnKeyDown/index.mjs +2 -0
  50. package/dist/{useOnKeyDown/useOnKeyDown.js → useOnKeyDown-cjs.js} +7 -5
  51. package/dist/useOnKeyDown-es.js +34 -0
  52. package/dist/useOnMount/index.cjs +9 -0
  53. package/dist/useOnMount/index.mjs +3 -0
  54. package/dist/{useOnMount/useOnMount.js → useOnMount-cjs.js} +9 -8
  55. package/dist/useOnMount-es.js +19 -0
  56. package/dist/useRefocusOnActivator/index.cjs +8 -0
  57. package/dist/useRefocusOnActivator/index.mjs +2 -0
  58. package/dist/{useRefocusOnActivator/useRefocusOnActivator.js → useRefocusOnActivator-cjs.js} +7 -5
  59. package/dist/useRefocusOnActivator-es.js +26 -0
  60. package/dist/useResizeObserver/index.cjs +10 -0
  61. package/dist/useResizeObserver/index.mjs +3 -0
  62. package/dist/useResizeObserver-cjs.js +1519 -0
  63. package/dist/useResizeObserver-es.js +1516 -0
  64. package/dist/useSafeLayoutEffect/index.cjs +8 -0
  65. package/dist/useSafeLayoutEffect/index.mjs +2 -0
  66. package/dist/useSafeLayoutEffect-cjs.js +9 -0
  67. package/dist/useSafeLayoutEffect-es.js +7 -0
  68. package/dist/useShowClear/{useShowClear.js → index.cjs} +4 -3
  69. package/dist/useShowClear/index.mjs +17 -0
  70. package/dist/useStepper/index.cjs +8 -0
  71. package/dist/useStepper/index.mjs +2 -0
  72. package/dist/{useStepper/useStepper.js → useStepper-cjs.js} +26 -14
  73. package/dist/useStepper-es.js +51 -0
  74. package/dist/useWindowDimensions/index.cjs +8 -0
  75. package/dist/useWindowDimensions/index.mjs +2 -0
  76. package/dist/{useWindowDimensions/useWindowDimensions.js → useWindowDimensions-cjs.js} +8 -6
  77. package/dist/useWindowDimensions-es.js +28 -0
  78. package/package.json +109 -7
  79. package/dist/index.js +0 -34
  80. package/dist/useBool/index.js +0 -5
  81. package/dist/useBool/useBool.js +0 -11
  82. package/dist/useBool/useBool.test.d.ts +0 -1
  83. package/dist/useBool/useBool.test.js +0 -28
  84. package/dist/useBreakpoints/index.js +0 -20
  85. package/dist/useBreakpoints/mockViewportWidth/index.js +0 -17
  86. package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.test.d.ts +0 -1
  87. package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.test.js +0 -17
  88. package/dist/useBreakpoints/useBreakpoints.js +0 -28
  89. package/dist/useBreakpoints/useBreakpoints.test.d.ts +0 -1
  90. package/dist/useBreakpoints/useBreakpoints.test.js +0 -142
  91. package/dist/useBreakpoints/useMediaQuery.js +0 -22
  92. package/dist/useCallbackRef/index.js +0 -5
  93. package/dist/useCallbackRef/useCallbackRef.js +0 -15
  94. package/dist/useCallbackRef/useCallbackRef.test.d.ts +0 -1
  95. package/dist/useCallbackRef/useCallbackRef.test.js +0 -29
  96. package/dist/useCollectionQuery/index.js +0 -5
  97. package/dist/useCollectionQuery/mdxUtils.js +0 -152
  98. package/dist/useCollectionQuery/test-utilities/index.d.ts +0 -3
  99. package/dist/useCollectionQuery/test-utilities/index.js +0 -19
  100. package/dist/useCollectionQuery/test-utilities/mocks.d.ts +0 -106
  101. package/dist/useCollectionQuery/test-utilities/mocks.js +0 -131
  102. package/dist/useCollectionQuery/test-utilities/queries.d.ts +0 -37
  103. package/dist/useCollectionQuery/test-utilities/queries.js +0 -59
  104. package/dist/useCollectionQuery/test-utilities/utils.d.ts +0 -1
  105. package/dist/useCollectionQuery/test-utilities/utils.js +0 -17
  106. package/dist/useCollectionQuery/uniqueEdges.js +0 -18
  107. package/dist/useCollectionQuery/uniqueNodes.js +0 -10
  108. package/dist/useCollectionQuery/useCollectionQuery.js +0 -194
  109. package/dist/useCollectionQuery/useCollectionQuery.test.d.ts +0 -1
  110. package/dist/useCollectionQuery/useCollectionQuery.test.js +0 -357
  111. package/dist/useDebounce/index.js +0 -5
  112. package/dist/useDebounce/useDebounce.js +0 -29
  113. package/dist/useDebounce/useDebounce.test.d.ts +0 -1
  114. package/dist/useDebounce/useDebounce.test.js +0 -190
  115. package/dist/useFocusTrap/index.js +0 -5
  116. package/dist/useFocusTrap/useFocusTrap.test.d.ts +0 -1
  117. package/dist/useFocusTrap/useFocusTrap.test.js +0 -61
  118. package/dist/useFormState/index.js +0 -5
  119. package/dist/useFormState/useFormState.js +0 -11
  120. package/dist/useInView/index.js +0 -17
  121. package/dist/useInView/useInView.test.d.ts +0 -1
  122. package/dist/useInView/useInView.test.js +0 -29
  123. package/dist/useIsMounted/index.js +0 -5
  124. package/dist/useIsMounted/useIsMounted.test.d.ts +0 -1
  125. package/dist/useIsMounted/useIsMounted.test.js +0 -15
  126. package/dist/useLiveAnnounce/index.js +0 -5
  127. package/dist/useLiveAnnounce/useLiveAnnounce.test.d.ts +0 -1
  128. package/dist/useLiveAnnounce/useLiveAnnounce.test.js +0 -60
  129. package/dist/useOnKeyDown/index.js +0 -5
  130. package/dist/useOnKeyDown/useOnKeyDown.test.d.ts +0 -1
  131. package/dist/useOnKeyDown/useOnKeyDown.test.js +0 -23
  132. package/dist/useOnMount/index.js +0 -5
  133. package/dist/useOnMount/useOnMount.test.d.ts +0 -1
  134. package/dist/useOnMount/useOnMount.test.js +0 -18
  135. package/dist/useRefocusOnActivator/index.js +0 -5
  136. package/dist/useResizeObserver/index.js +0 -17
  137. package/dist/useResizeObserver/useResizeObserver.js +0 -68
  138. package/dist/useSafeLayoutEffect/index.js +0 -5
  139. package/dist/useSafeLayoutEffect/useSafeLayoutEffect.js +0 -7
  140. package/dist/useShowClear/index.js +0 -5
  141. package/dist/useShowClear/useShowClear.test.d.ts +0 -1
  142. package/dist/useShowClear/useShowClear.test.js +0 -210
  143. package/dist/useStepper/index.js +0 -5
  144. package/dist/useStepper/useStepper.test.d.ts +0 -1
  145. package/dist/useStepper/useStepper.test.js +0 -79
  146. package/dist/useWindowDimensions/index.js +0 -5
  147. package/dist/useWindowDimensions/useWIndowDimensions.test.d.ts +0 -1
  148. package/dist/useWindowDimensions/useWIndowDimensions.test.js +0 -23
@@ -0,0 +1,1519 @@
1
+ 'use strict';
2
+
3
+ var require$$1 = require('react');
4
+ var isObjectLike$1 = require('./isObjectLike-cjs.js');
5
+
6
+ /**
7
+ * A collection of shims that provide minimal functionality of the ES6 collections.
8
+ *
9
+ * These implementations are not meant to be used outside of the ResizeObserver
10
+ * modules as they cover only a limited range of use cases.
11
+ */
12
+ /* eslint-disable require-jsdoc, valid-jsdoc */
13
+ var MapShim = (function () {
14
+ if (typeof Map !== 'undefined') {
15
+ return Map;
16
+ }
17
+ /**
18
+ * Returns index in provided array that matches the specified key.
19
+ *
20
+ * @param {Array<Array>} arr
21
+ * @param {*} key
22
+ * @returns {number}
23
+ */
24
+ function getIndex(arr, key) {
25
+ var result = -1;
26
+ arr.some(function (entry, index) {
27
+ if (entry[0] === key) {
28
+ result = index;
29
+ return true;
30
+ }
31
+ return false;
32
+ });
33
+ return result;
34
+ }
35
+ return /** @class */ (function () {
36
+ function class_1() {
37
+ this.__entries__ = [];
38
+ }
39
+ Object.defineProperty(class_1.prototype, "size", {
40
+ /**
41
+ * @returns {boolean}
42
+ */
43
+ get: function () {
44
+ return this.__entries__.length;
45
+ },
46
+ enumerable: true,
47
+ configurable: true
48
+ });
49
+ /**
50
+ * @param {*} key
51
+ * @returns {*}
52
+ */
53
+ class_1.prototype.get = function (key) {
54
+ var index = getIndex(this.__entries__, key);
55
+ var entry = this.__entries__[index];
56
+ return entry && entry[1];
57
+ };
58
+ /**
59
+ * @param {*} key
60
+ * @param {*} value
61
+ * @returns {void}
62
+ */
63
+ class_1.prototype.set = function (key, value) {
64
+ var index = getIndex(this.__entries__, key);
65
+ if (~index) {
66
+ this.__entries__[index][1] = value;
67
+ }
68
+ else {
69
+ this.__entries__.push([key, value]);
70
+ }
71
+ };
72
+ /**
73
+ * @param {*} key
74
+ * @returns {void}
75
+ */
76
+ class_1.prototype.delete = function (key) {
77
+ var entries = this.__entries__;
78
+ var index = getIndex(entries, key);
79
+ if (~index) {
80
+ entries.splice(index, 1);
81
+ }
82
+ };
83
+ /**
84
+ * @param {*} key
85
+ * @returns {void}
86
+ */
87
+ class_1.prototype.has = function (key) {
88
+ return !!~getIndex(this.__entries__, key);
89
+ };
90
+ /**
91
+ * @returns {void}
92
+ */
93
+ class_1.prototype.clear = function () {
94
+ this.__entries__.splice(0);
95
+ };
96
+ /**
97
+ * @param {Function} callback
98
+ * @param {*} [ctx=null]
99
+ * @returns {void}
100
+ */
101
+ class_1.prototype.forEach = function (callback, ctx) {
102
+ if (ctx === void 0) { ctx = null; }
103
+ for (var _i = 0, _a = this.__entries__; _i < _a.length; _i++) {
104
+ var entry = _a[_i];
105
+ callback.call(ctx, entry[1], entry[0]);
106
+ }
107
+ };
108
+ return class_1;
109
+ }());
110
+ })();
111
+
112
+ /**
113
+ * Detects whether window and document objects are available in current environment.
114
+ */
115
+ var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && window.document === document;
116
+
117
+ // Returns global object of a current environment.
118
+ var global$1 = (function () {
119
+ if (typeof global !== 'undefined' && global.Math === Math) {
120
+ return global;
121
+ }
122
+ if (typeof self !== 'undefined' && self.Math === Math) {
123
+ return self;
124
+ }
125
+ if (typeof window !== 'undefined' && window.Math === Math) {
126
+ return window;
127
+ }
128
+ // eslint-disable-next-line no-new-func
129
+ return Function('return this')();
130
+ })();
131
+
132
+ /**
133
+ * A shim for the requestAnimationFrame which falls back to the setTimeout if
134
+ * first one is not supported.
135
+ *
136
+ * @returns {number} Requests' identifier.
137
+ */
138
+ var requestAnimationFrame$1 = (function () {
139
+ if (typeof requestAnimationFrame === 'function') {
140
+ // It's required to use a bounded function because IE sometimes throws
141
+ // an "Invalid calling object" error if rAF is invoked without the global
142
+ // object on the left hand side.
143
+ return requestAnimationFrame.bind(global$1);
144
+ }
145
+ return function (callback) { return setTimeout(function () { return callback(Date.now()); }, 1000 / 60); };
146
+ })();
147
+
148
+ // Defines minimum timeout before adding a trailing call.
149
+ var trailingTimeout = 2;
150
+ /**
151
+ * Creates a wrapper function which ensures that provided callback will be
152
+ * invoked only once during the specified delay period.
153
+ *
154
+ * @param {Function} callback - Function to be invoked after the delay period.
155
+ * @param {number} delay - Delay after which to invoke callback.
156
+ * @returns {Function}
157
+ */
158
+ function throttle$2 (callback, delay) {
159
+ var leadingCall = false, trailingCall = false, lastCallTime = 0;
160
+ /**
161
+ * Invokes the original callback function and schedules new invocation if
162
+ * the "proxy" was called during current request.
163
+ *
164
+ * @returns {void}
165
+ */
166
+ function resolvePending() {
167
+ if (leadingCall) {
168
+ leadingCall = false;
169
+ callback();
170
+ }
171
+ if (trailingCall) {
172
+ proxy();
173
+ }
174
+ }
175
+ /**
176
+ * Callback invoked after the specified delay. It will further postpone
177
+ * invocation of the original function delegating it to the
178
+ * requestAnimationFrame.
179
+ *
180
+ * @returns {void}
181
+ */
182
+ function timeoutCallback() {
183
+ requestAnimationFrame$1(resolvePending);
184
+ }
185
+ /**
186
+ * Schedules invocation of the original function.
187
+ *
188
+ * @returns {void}
189
+ */
190
+ function proxy() {
191
+ var timeStamp = Date.now();
192
+ if (leadingCall) {
193
+ // Reject immediately following calls.
194
+ if (timeStamp - lastCallTime < trailingTimeout) {
195
+ return;
196
+ }
197
+ // Schedule new call to be in invoked when the pending one is resolved.
198
+ // This is important for "transitions" which never actually start
199
+ // immediately so there is a chance that we might miss one if change
200
+ // happens amids the pending invocation.
201
+ trailingCall = true;
202
+ }
203
+ else {
204
+ leadingCall = true;
205
+ trailingCall = false;
206
+ setTimeout(timeoutCallback, delay);
207
+ }
208
+ lastCallTime = timeStamp;
209
+ }
210
+ return proxy;
211
+ }
212
+
213
+ // Minimum delay before invoking the update of observers.
214
+ var REFRESH_DELAY = 20;
215
+ // A list of substrings of CSS properties used to find transition events that
216
+ // might affect dimensions of observed elements.
217
+ var transitionKeys = ['top', 'right', 'bottom', 'left', 'width', 'height', 'size', 'weight'];
218
+ // Check if MutationObserver is available.
219
+ var mutationObserverSupported = typeof MutationObserver !== 'undefined';
220
+ /**
221
+ * Singleton controller class which handles updates of ResizeObserver instances.
222
+ */
223
+ var ResizeObserverController = /** @class */ (function () {
224
+ /**
225
+ * Creates a new instance of ResizeObserverController.
226
+ *
227
+ * @private
228
+ */
229
+ function ResizeObserverController() {
230
+ /**
231
+ * Indicates whether DOM listeners have been added.
232
+ *
233
+ * @private {boolean}
234
+ */
235
+ this.connected_ = false;
236
+ /**
237
+ * Tells that controller has subscribed for Mutation Events.
238
+ *
239
+ * @private {boolean}
240
+ */
241
+ this.mutationEventsAdded_ = false;
242
+ /**
243
+ * Keeps reference to the instance of MutationObserver.
244
+ *
245
+ * @private {MutationObserver}
246
+ */
247
+ this.mutationsObserver_ = null;
248
+ /**
249
+ * A list of connected observers.
250
+ *
251
+ * @private {Array<ResizeObserverSPI>}
252
+ */
253
+ this.observers_ = [];
254
+ this.onTransitionEnd_ = this.onTransitionEnd_.bind(this);
255
+ this.refresh = throttle$2(this.refresh.bind(this), REFRESH_DELAY);
256
+ }
257
+ /**
258
+ * Adds observer to observers list.
259
+ *
260
+ * @param {ResizeObserverSPI} observer - Observer to be added.
261
+ * @returns {void}
262
+ */
263
+ ResizeObserverController.prototype.addObserver = function (observer) {
264
+ if (!~this.observers_.indexOf(observer)) {
265
+ this.observers_.push(observer);
266
+ }
267
+ // Add listeners if they haven't been added yet.
268
+ if (!this.connected_) {
269
+ this.connect_();
270
+ }
271
+ };
272
+ /**
273
+ * Removes observer from observers list.
274
+ *
275
+ * @param {ResizeObserverSPI} observer - Observer to be removed.
276
+ * @returns {void}
277
+ */
278
+ ResizeObserverController.prototype.removeObserver = function (observer) {
279
+ var observers = this.observers_;
280
+ var index = observers.indexOf(observer);
281
+ // Remove observer if it's present in registry.
282
+ if (~index) {
283
+ observers.splice(index, 1);
284
+ }
285
+ // Remove listeners if controller has no connected observers.
286
+ if (!observers.length && this.connected_) {
287
+ this.disconnect_();
288
+ }
289
+ };
290
+ /**
291
+ * Invokes the update of observers. It will continue running updates insofar
292
+ * it detects changes.
293
+ *
294
+ * @returns {void}
295
+ */
296
+ ResizeObserverController.prototype.refresh = function () {
297
+ var changesDetected = this.updateObservers_();
298
+ // Continue running updates if changes have been detected as there might
299
+ // be future ones caused by CSS transitions.
300
+ if (changesDetected) {
301
+ this.refresh();
302
+ }
303
+ };
304
+ /**
305
+ * Updates every observer from observers list and notifies them of queued
306
+ * entries.
307
+ *
308
+ * @private
309
+ * @returns {boolean} Returns "true" if any observer has detected changes in
310
+ * dimensions of it's elements.
311
+ */
312
+ ResizeObserverController.prototype.updateObservers_ = function () {
313
+ // Collect observers that have active observations.
314
+ var activeObservers = this.observers_.filter(function (observer) {
315
+ return observer.gatherActive(), observer.hasActive();
316
+ });
317
+ // Deliver notifications in a separate cycle in order to avoid any
318
+ // collisions between observers, e.g. when multiple instances of
319
+ // ResizeObserver are tracking the same element and the callback of one
320
+ // of them changes content dimensions of the observed target. Sometimes
321
+ // this may result in notifications being blocked for the rest of observers.
322
+ activeObservers.forEach(function (observer) { return observer.broadcastActive(); });
323
+ return activeObservers.length > 0;
324
+ };
325
+ /**
326
+ * Initializes DOM listeners.
327
+ *
328
+ * @private
329
+ * @returns {void}
330
+ */
331
+ ResizeObserverController.prototype.connect_ = function () {
332
+ // Do nothing if running in a non-browser environment or if listeners
333
+ // have been already added.
334
+ if (!isBrowser || this.connected_) {
335
+ return;
336
+ }
337
+ // Subscription to the "Transitionend" event is used as a workaround for
338
+ // delayed transitions. This way it's possible to capture at least the
339
+ // final state of an element.
340
+ document.addEventListener('transitionend', this.onTransitionEnd_);
341
+ window.addEventListener('resize', this.refresh);
342
+ if (mutationObserverSupported) {
343
+ this.mutationsObserver_ = new MutationObserver(this.refresh);
344
+ this.mutationsObserver_.observe(document, {
345
+ attributes: true,
346
+ childList: true,
347
+ characterData: true,
348
+ subtree: true
349
+ });
350
+ }
351
+ else {
352
+ document.addEventListener('DOMSubtreeModified', this.refresh);
353
+ this.mutationEventsAdded_ = true;
354
+ }
355
+ this.connected_ = true;
356
+ };
357
+ /**
358
+ * Removes DOM listeners.
359
+ *
360
+ * @private
361
+ * @returns {void}
362
+ */
363
+ ResizeObserverController.prototype.disconnect_ = function () {
364
+ // Do nothing if running in a non-browser environment or if listeners
365
+ // have been already removed.
366
+ if (!isBrowser || !this.connected_) {
367
+ return;
368
+ }
369
+ document.removeEventListener('transitionend', this.onTransitionEnd_);
370
+ window.removeEventListener('resize', this.refresh);
371
+ if (this.mutationsObserver_) {
372
+ this.mutationsObserver_.disconnect();
373
+ }
374
+ if (this.mutationEventsAdded_) {
375
+ document.removeEventListener('DOMSubtreeModified', this.refresh);
376
+ }
377
+ this.mutationsObserver_ = null;
378
+ this.mutationEventsAdded_ = false;
379
+ this.connected_ = false;
380
+ };
381
+ /**
382
+ * "Transitionend" event handler.
383
+ *
384
+ * @private
385
+ * @param {TransitionEvent} event
386
+ * @returns {void}
387
+ */
388
+ ResizeObserverController.prototype.onTransitionEnd_ = function (_a) {
389
+ var _b = _a.propertyName, propertyName = _b === void 0 ? '' : _b;
390
+ // Detect whether transition may affect dimensions of an element.
391
+ var isReflowProperty = transitionKeys.some(function (key) {
392
+ return !!~propertyName.indexOf(key);
393
+ });
394
+ if (isReflowProperty) {
395
+ this.refresh();
396
+ }
397
+ };
398
+ /**
399
+ * Returns instance of the ResizeObserverController.
400
+ *
401
+ * @returns {ResizeObserverController}
402
+ */
403
+ ResizeObserverController.getInstance = function () {
404
+ if (!this.instance_) {
405
+ this.instance_ = new ResizeObserverController();
406
+ }
407
+ return this.instance_;
408
+ };
409
+ /**
410
+ * Holds reference to the controller's instance.
411
+ *
412
+ * @private {ResizeObserverController}
413
+ */
414
+ ResizeObserverController.instance_ = null;
415
+ return ResizeObserverController;
416
+ }());
417
+
418
+ /**
419
+ * Defines non-writable/enumerable properties of the provided target object.
420
+ *
421
+ * @param {Object} target - Object for which to define properties.
422
+ * @param {Object} props - Properties to be defined.
423
+ * @returns {Object} Target object.
424
+ */
425
+ var defineConfigurable = (function (target, props) {
426
+ for (var _i = 0, _a = Object.keys(props); _i < _a.length; _i++) {
427
+ var key = _a[_i];
428
+ Object.defineProperty(target, key, {
429
+ value: props[key],
430
+ enumerable: false,
431
+ writable: false,
432
+ configurable: true
433
+ });
434
+ }
435
+ return target;
436
+ });
437
+
438
+ /**
439
+ * Returns the global object associated with provided element.
440
+ *
441
+ * @param {Object} target
442
+ * @returns {Object}
443
+ */
444
+ var getWindowOf = (function (target) {
445
+ // Assume that the element is an instance of Node, which means that it
446
+ // has the "ownerDocument" property from which we can retrieve a
447
+ // corresponding global object.
448
+ var ownerGlobal = target && target.ownerDocument && target.ownerDocument.defaultView;
449
+ // Return the local global object if it's not possible extract one from
450
+ // provided element.
451
+ return ownerGlobal || global$1;
452
+ });
453
+
454
+ // Placeholder of an empty content rectangle.
455
+ var emptyRect = createRectInit(0, 0, 0, 0);
456
+ /**
457
+ * Converts provided string to a number.
458
+ *
459
+ * @param {number|string} value
460
+ * @returns {number}
461
+ */
462
+ function toFloat(value) {
463
+ return parseFloat(value) || 0;
464
+ }
465
+ /**
466
+ * Extracts borders size from provided styles.
467
+ *
468
+ * @param {CSSStyleDeclaration} styles
469
+ * @param {...string} positions - Borders positions (top, right, ...)
470
+ * @returns {number}
471
+ */
472
+ function getBordersSize(styles) {
473
+ var positions = [];
474
+ for (var _i = 1; _i < arguments.length; _i++) {
475
+ positions[_i - 1] = arguments[_i];
476
+ }
477
+ return positions.reduce(function (size, position) {
478
+ var value = styles['border-' + position + '-width'];
479
+ return size + toFloat(value);
480
+ }, 0);
481
+ }
482
+ /**
483
+ * Extracts paddings sizes from provided styles.
484
+ *
485
+ * @param {CSSStyleDeclaration} styles
486
+ * @returns {Object} Paddings box.
487
+ */
488
+ function getPaddings(styles) {
489
+ var positions = ['top', 'right', 'bottom', 'left'];
490
+ var paddings = {};
491
+ for (var _i = 0, positions_1 = positions; _i < positions_1.length; _i++) {
492
+ var position = positions_1[_i];
493
+ var value = styles['padding-' + position];
494
+ paddings[position] = toFloat(value);
495
+ }
496
+ return paddings;
497
+ }
498
+ /**
499
+ * Calculates content rectangle of provided SVG element.
500
+ *
501
+ * @param {SVGGraphicsElement} target - Element content rectangle of which needs
502
+ * to be calculated.
503
+ * @returns {DOMRectInit}
504
+ */
505
+ function getSVGContentRect(target) {
506
+ var bbox = target.getBBox();
507
+ return createRectInit(0, 0, bbox.width, bbox.height);
508
+ }
509
+ /**
510
+ * Calculates content rectangle of provided HTMLElement.
511
+ *
512
+ * @param {HTMLElement} target - Element for which to calculate the content rectangle.
513
+ * @returns {DOMRectInit}
514
+ */
515
+ function getHTMLElementContentRect(target) {
516
+ // Client width & height properties can't be
517
+ // used exclusively as they provide rounded values.
518
+ var clientWidth = target.clientWidth, clientHeight = target.clientHeight;
519
+ // By this condition we can catch all non-replaced inline, hidden and
520
+ // detached elements. Though elements with width & height properties less
521
+ // than 0.5 will be discarded as well.
522
+ //
523
+ // Without it we would need to implement separate methods for each of
524
+ // those cases and it's not possible to perform a precise and performance
525
+ // effective test for hidden elements. E.g. even jQuery's ':visible' filter
526
+ // gives wrong results for elements with width & height less than 0.5.
527
+ if (!clientWidth && !clientHeight) {
528
+ return emptyRect;
529
+ }
530
+ var styles = getWindowOf(target).getComputedStyle(target);
531
+ var paddings = getPaddings(styles);
532
+ var horizPad = paddings.left + paddings.right;
533
+ var vertPad = paddings.top + paddings.bottom;
534
+ // Computed styles of width & height are being used because they are the
535
+ // only dimensions available to JS that contain non-rounded values. It could
536
+ // be possible to utilize the getBoundingClientRect if only it's data wasn't
537
+ // affected by CSS transformations let alone paddings, borders and scroll bars.
538
+ var width = toFloat(styles.width), height = toFloat(styles.height);
539
+ // Width & height include paddings and borders when the 'border-box' box
540
+ // model is applied (except for IE).
541
+ if (styles.boxSizing === 'border-box') {
542
+ // Following conditions are required to handle Internet Explorer which
543
+ // doesn't include paddings and borders to computed CSS dimensions.
544
+ //
545
+ // We can say that if CSS dimensions + paddings are equal to the "client"
546
+ // properties then it's either IE, and thus we don't need to subtract
547
+ // anything, or an element merely doesn't have paddings/borders styles.
548
+ if (Math.round(width + horizPad) !== clientWidth) {
549
+ width -= getBordersSize(styles, 'left', 'right') + horizPad;
550
+ }
551
+ if (Math.round(height + vertPad) !== clientHeight) {
552
+ height -= getBordersSize(styles, 'top', 'bottom') + vertPad;
553
+ }
554
+ }
555
+ // Following steps can't be applied to the document's root element as its
556
+ // client[Width/Height] properties represent viewport area of the window.
557
+ // Besides, it's as well not necessary as the <html> itself neither has
558
+ // rendered scroll bars nor it can be clipped.
559
+ if (!isDocumentElement(target)) {
560
+ // In some browsers (only in Firefox, actually) CSS width & height
561
+ // include scroll bars size which can be removed at this step as scroll
562
+ // bars are the only difference between rounded dimensions + paddings
563
+ // and "client" properties, though that is not always true in Chrome.
564
+ var vertScrollbar = Math.round(width + horizPad) - clientWidth;
565
+ var horizScrollbar = Math.round(height + vertPad) - clientHeight;
566
+ // Chrome has a rather weird rounding of "client" properties.
567
+ // E.g. for an element with content width of 314.2px it sometimes gives
568
+ // the client width of 315px and for the width of 314.7px it may give
569
+ // 314px. And it doesn't happen all the time. So just ignore this delta
570
+ // as a non-relevant.
571
+ if (Math.abs(vertScrollbar) !== 1) {
572
+ width -= vertScrollbar;
573
+ }
574
+ if (Math.abs(horizScrollbar) !== 1) {
575
+ height -= horizScrollbar;
576
+ }
577
+ }
578
+ return createRectInit(paddings.left, paddings.top, width, height);
579
+ }
580
+ /**
581
+ * Checks whether provided element is an instance of the SVGGraphicsElement.
582
+ *
583
+ * @param {Element} target - Element to be checked.
584
+ * @returns {boolean}
585
+ */
586
+ var isSVGGraphicsElement = (function () {
587
+ // Some browsers, namely IE and Edge, don't have the SVGGraphicsElement
588
+ // interface.
589
+ if (typeof SVGGraphicsElement !== 'undefined') {
590
+ return function (target) { return target instanceof getWindowOf(target).SVGGraphicsElement; };
591
+ }
592
+ // If it's so, then check that element is at least an instance of the
593
+ // SVGElement and that it has the "getBBox" method.
594
+ // eslint-disable-next-line no-extra-parens
595
+ return function (target) { return (target instanceof getWindowOf(target).SVGElement &&
596
+ typeof target.getBBox === 'function'); };
597
+ })();
598
+ /**
599
+ * Checks whether provided element is a document element (<html>).
600
+ *
601
+ * @param {Element} target - Element to be checked.
602
+ * @returns {boolean}
603
+ */
604
+ function isDocumentElement(target) {
605
+ return target === getWindowOf(target).document.documentElement;
606
+ }
607
+ /**
608
+ * Calculates an appropriate content rectangle for provided html or svg element.
609
+ *
610
+ * @param {Element} target - Element content rectangle of which needs to be calculated.
611
+ * @returns {DOMRectInit}
612
+ */
613
+ function getContentRect(target) {
614
+ if (!isBrowser) {
615
+ return emptyRect;
616
+ }
617
+ if (isSVGGraphicsElement(target)) {
618
+ return getSVGContentRect(target);
619
+ }
620
+ return getHTMLElementContentRect(target);
621
+ }
622
+ /**
623
+ * Creates rectangle with an interface of the DOMRectReadOnly.
624
+ * Spec: https://drafts.fxtf.org/geometry/#domrectreadonly
625
+ *
626
+ * @param {DOMRectInit} rectInit - Object with rectangle's x/y coordinates and dimensions.
627
+ * @returns {DOMRectReadOnly}
628
+ */
629
+ function createReadOnlyRect(_a) {
630
+ var x = _a.x, y = _a.y, width = _a.width, height = _a.height;
631
+ // If DOMRectReadOnly is available use it as a prototype for the rectangle.
632
+ var Constr = typeof DOMRectReadOnly !== 'undefined' ? DOMRectReadOnly : Object;
633
+ var rect = Object.create(Constr.prototype);
634
+ // Rectangle's properties are not writable and non-enumerable.
635
+ defineConfigurable(rect, {
636
+ x: x, y: y, width: width, height: height,
637
+ top: y,
638
+ right: x + width,
639
+ bottom: height + y,
640
+ left: x
641
+ });
642
+ return rect;
643
+ }
644
+ /**
645
+ * Creates DOMRectInit object based on the provided dimensions and the x/y coordinates.
646
+ * Spec: https://drafts.fxtf.org/geometry/#dictdef-domrectinit
647
+ *
648
+ * @param {number} x - X coordinate.
649
+ * @param {number} y - Y coordinate.
650
+ * @param {number} width - Rectangle's width.
651
+ * @param {number} height - Rectangle's height.
652
+ * @returns {DOMRectInit}
653
+ */
654
+ function createRectInit(x, y, width, height) {
655
+ return { x: x, y: y, width: width, height: height };
656
+ }
657
+
658
+ /**
659
+ * Class that is responsible for computations of the content rectangle of
660
+ * provided DOM element and for keeping track of it's changes.
661
+ */
662
+ var ResizeObservation = /** @class */ (function () {
663
+ /**
664
+ * Creates an instance of ResizeObservation.
665
+ *
666
+ * @param {Element} target - Element to be observed.
667
+ */
668
+ function ResizeObservation(target) {
669
+ /**
670
+ * Broadcasted width of content rectangle.
671
+ *
672
+ * @type {number}
673
+ */
674
+ this.broadcastWidth = 0;
675
+ /**
676
+ * Broadcasted height of content rectangle.
677
+ *
678
+ * @type {number}
679
+ */
680
+ this.broadcastHeight = 0;
681
+ /**
682
+ * Reference to the last observed content rectangle.
683
+ *
684
+ * @private {DOMRectInit}
685
+ */
686
+ this.contentRect_ = createRectInit(0, 0, 0, 0);
687
+ this.target = target;
688
+ }
689
+ /**
690
+ * Updates content rectangle and tells whether it's width or height properties
691
+ * have changed since the last broadcast.
692
+ *
693
+ * @returns {boolean}
694
+ */
695
+ ResizeObservation.prototype.isActive = function () {
696
+ var rect = getContentRect(this.target);
697
+ this.contentRect_ = rect;
698
+ return (rect.width !== this.broadcastWidth ||
699
+ rect.height !== this.broadcastHeight);
700
+ };
701
+ /**
702
+ * Updates 'broadcastWidth' and 'broadcastHeight' properties with a data
703
+ * from the corresponding properties of the last observed content rectangle.
704
+ *
705
+ * @returns {DOMRectInit} Last observed content rectangle.
706
+ */
707
+ ResizeObservation.prototype.broadcastRect = function () {
708
+ var rect = this.contentRect_;
709
+ this.broadcastWidth = rect.width;
710
+ this.broadcastHeight = rect.height;
711
+ return rect;
712
+ };
713
+ return ResizeObservation;
714
+ }());
715
+
716
+ var ResizeObserverEntry = /** @class */ (function () {
717
+ /**
718
+ * Creates an instance of ResizeObserverEntry.
719
+ *
720
+ * @param {Element} target - Element that is being observed.
721
+ * @param {DOMRectInit} rectInit - Data of the element's content rectangle.
722
+ */
723
+ function ResizeObserverEntry(target, rectInit) {
724
+ var contentRect = createReadOnlyRect(rectInit);
725
+ // According to the specification following properties are not writable
726
+ // and are also not enumerable in the native implementation.
727
+ //
728
+ // Property accessors are not being used as they'd require to define a
729
+ // private WeakMap storage which may cause memory leaks in browsers that
730
+ // don't support this type of collections.
731
+ defineConfigurable(this, { target: target, contentRect: contentRect });
732
+ }
733
+ return ResizeObserverEntry;
734
+ }());
735
+
736
+ var ResizeObserverSPI = /** @class */ (function () {
737
+ /**
738
+ * Creates a new instance of ResizeObserver.
739
+ *
740
+ * @param {ResizeObserverCallback} callback - Callback function that is invoked
741
+ * when one of the observed elements changes it's content dimensions.
742
+ * @param {ResizeObserverController} controller - Controller instance which
743
+ * is responsible for the updates of observer.
744
+ * @param {ResizeObserver} callbackCtx - Reference to the public
745
+ * ResizeObserver instance which will be passed to callback function.
746
+ */
747
+ function ResizeObserverSPI(callback, controller, callbackCtx) {
748
+ /**
749
+ * Collection of resize observations that have detected changes in dimensions
750
+ * of elements.
751
+ *
752
+ * @private {Array<ResizeObservation>}
753
+ */
754
+ this.activeObservations_ = [];
755
+ /**
756
+ * Registry of the ResizeObservation instances.
757
+ *
758
+ * @private {Map<Element, ResizeObservation>}
759
+ */
760
+ this.observations_ = new MapShim();
761
+ if (typeof callback !== 'function') {
762
+ throw new TypeError('The callback provided as parameter 1 is not a function.');
763
+ }
764
+ this.callback_ = callback;
765
+ this.controller_ = controller;
766
+ this.callbackCtx_ = callbackCtx;
767
+ }
768
+ /**
769
+ * Starts observing provided element.
770
+ *
771
+ * @param {Element} target - Element to be observed.
772
+ * @returns {void}
773
+ */
774
+ ResizeObserverSPI.prototype.observe = function (target) {
775
+ if (!arguments.length) {
776
+ throw new TypeError('1 argument required, but only 0 present.');
777
+ }
778
+ // Do nothing if current environment doesn't have the Element interface.
779
+ if (typeof Element === 'undefined' || !(Element instanceof Object)) {
780
+ return;
781
+ }
782
+ if (!(target instanceof getWindowOf(target).Element)) {
783
+ throw new TypeError('parameter 1 is not of type "Element".');
784
+ }
785
+ var observations = this.observations_;
786
+ // Do nothing if element is already being observed.
787
+ if (observations.has(target)) {
788
+ return;
789
+ }
790
+ observations.set(target, new ResizeObservation(target));
791
+ this.controller_.addObserver(this);
792
+ // Force the update of observations.
793
+ this.controller_.refresh();
794
+ };
795
+ /**
796
+ * Stops observing provided element.
797
+ *
798
+ * @param {Element} target - Element to stop observing.
799
+ * @returns {void}
800
+ */
801
+ ResizeObserverSPI.prototype.unobserve = function (target) {
802
+ if (!arguments.length) {
803
+ throw new TypeError('1 argument required, but only 0 present.');
804
+ }
805
+ // Do nothing if current environment doesn't have the Element interface.
806
+ if (typeof Element === 'undefined' || !(Element instanceof Object)) {
807
+ return;
808
+ }
809
+ if (!(target instanceof getWindowOf(target).Element)) {
810
+ throw new TypeError('parameter 1 is not of type "Element".');
811
+ }
812
+ var observations = this.observations_;
813
+ // Do nothing if element is not being observed.
814
+ if (!observations.has(target)) {
815
+ return;
816
+ }
817
+ observations.delete(target);
818
+ if (!observations.size) {
819
+ this.controller_.removeObserver(this);
820
+ }
821
+ };
822
+ /**
823
+ * Stops observing all elements.
824
+ *
825
+ * @returns {void}
826
+ */
827
+ ResizeObserverSPI.prototype.disconnect = function () {
828
+ this.clearActive();
829
+ this.observations_.clear();
830
+ this.controller_.removeObserver(this);
831
+ };
832
+ /**
833
+ * Collects observation instances the associated element of which has changed
834
+ * it's content rectangle.
835
+ *
836
+ * @returns {void}
837
+ */
838
+ ResizeObserverSPI.prototype.gatherActive = function () {
839
+ var _this = this;
840
+ this.clearActive();
841
+ this.observations_.forEach(function (observation) {
842
+ if (observation.isActive()) {
843
+ _this.activeObservations_.push(observation);
844
+ }
845
+ });
846
+ };
847
+ /**
848
+ * Invokes initial callback function with a list of ResizeObserverEntry
849
+ * instances collected from active resize observations.
850
+ *
851
+ * @returns {void}
852
+ */
853
+ ResizeObserverSPI.prototype.broadcastActive = function () {
854
+ // Do nothing if observer doesn't have active observations.
855
+ if (!this.hasActive()) {
856
+ return;
857
+ }
858
+ var ctx = this.callbackCtx_;
859
+ // Create ResizeObserverEntry instance for every active observation.
860
+ var entries = this.activeObservations_.map(function (observation) {
861
+ return new ResizeObserverEntry(observation.target, observation.broadcastRect());
862
+ });
863
+ this.callback_.call(ctx, entries, ctx);
864
+ this.clearActive();
865
+ };
866
+ /**
867
+ * Clears the collection of active observations.
868
+ *
869
+ * @returns {void}
870
+ */
871
+ ResizeObserverSPI.prototype.clearActive = function () {
872
+ this.activeObservations_.splice(0);
873
+ };
874
+ /**
875
+ * Tells whether observer has active observations.
876
+ *
877
+ * @returns {boolean}
878
+ */
879
+ ResizeObserverSPI.prototype.hasActive = function () {
880
+ return this.activeObservations_.length > 0;
881
+ };
882
+ return ResizeObserverSPI;
883
+ }());
884
+
885
+ // Registry of internal observers. If WeakMap is not available use current shim
886
+ // for the Map collection as it has all required methods and because WeakMap
887
+ // can't be fully polyfilled anyway.
888
+ var observers = typeof WeakMap !== 'undefined' ? new WeakMap() : new MapShim();
889
+ /**
890
+ * ResizeObserver API. Encapsulates the ResizeObserver SPI implementation
891
+ * exposing only those methods and properties that are defined in the spec.
892
+ */
893
+ var ResizeObserver$1 = /** @class */ (function () {
894
+ /**
895
+ * Creates a new instance of ResizeObserver.
896
+ *
897
+ * @param {ResizeObserverCallback} callback - Callback that is invoked when
898
+ * dimensions of the observed elements change.
899
+ */
900
+ function ResizeObserver(callback) {
901
+ if (!(this instanceof ResizeObserver)) {
902
+ throw new TypeError('Cannot call a class as a function.');
903
+ }
904
+ if (!arguments.length) {
905
+ throw new TypeError('1 argument required, but only 0 present.');
906
+ }
907
+ var controller = ResizeObserverController.getInstance();
908
+ var observer = new ResizeObserverSPI(callback, controller, this);
909
+ observers.set(this, observer);
910
+ }
911
+ return ResizeObserver;
912
+ }());
913
+ // Expose public methods of ResizeObserver.
914
+ [
915
+ 'observe',
916
+ 'unobserve',
917
+ 'disconnect'
918
+ ].forEach(function (method) {
919
+ ResizeObserver$1.prototype[method] = function () {
920
+ var _a;
921
+ return (_a = observers.get(this))[method].apply(_a, arguments);
922
+ };
923
+ });
924
+
925
+ var index = (function () {
926
+ // Export existing implementation if available.
927
+ if (typeof global$1.ResizeObserver !== 'undefined') {
928
+ return global$1.ResizeObserver;
929
+ }
930
+ return ResizeObserver$1;
931
+ })();
932
+
933
+ var ResizeObserver_es = /*#__PURE__*/Object.freeze({
934
+ __proto__: null,
935
+ default: index
936
+ });
937
+
938
+ var require$$0 = /*@__PURE__*/isObjectLike$1.getAugmentedNamespace(ResizeObserver_es);
939
+
940
+ function _interopDefault$1 (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
941
+
942
+ var ResizeObserver = _interopDefault$1(require$$0);
943
+ var react = require$$1;
944
+
945
+ function useResizeObserver$1(opts) {
946
+ if (opts === void 0) {
947
+ opts = {};
948
+ }
949
+
950
+ // `defaultRef` Has to be non-conditionally declared here whether or not it'll
951
+ // be used as that's how hooks work.
952
+ // @see https://reactjs.org/docs/hooks-rules.html#explanation
953
+ var defaultRef = react.useRef(null); // Saving the callback as a ref. With this, I don't need to put onResize in the
954
+ // effect dep array, and just passing in an anonymous function without memoising
955
+ // will not reinstantiate the hook's ResizeObserver
956
+
957
+ var onResize = opts.onResize;
958
+ var onResizeRef = react.useRef(undefined);
959
+ onResizeRef.current = onResize; // Using a single instance throughought the hook's lifetime
960
+
961
+ var resizeObserverRef = react.useRef();
962
+ var ref = opts.ref || defaultRef;
963
+
964
+ var _useState = react.useState({
965
+ width: undefined,
966
+ height: undefined
967
+ }),
968
+ size = _useState[0],
969
+ setSize = _useState[1]; // Using a ref to track the previous width / height to avoid unnecessary renders
970
+
971
+
972
+ var previous = react.useRef({
973
+ width: undefined,
974
+ height: undefined
975
+ });
976
+ react.useEffect(function () {
977
+ if (resizeObserverRef.current) {
978
+ return;
979
+ }
980
+
981
+ resizeObserverRef.current = new ResizeObserver(function (entries) {
982
+ if (!Array.isArray(entries)) {
983
+ return;
984
+ } // Since we only observe the one element, we don't need to loop over the
985
+ // array
986
+
987
+
988
+ if (!entries.length) {
989
+ return;
990
+ }
991
+
992
+ var entry = entries[0]; // `Math.round` is in line with how CSS resolves sub-pixel values
993
+
994
+ var newWidth = Math.round(entry.contentRect.width);
995
+ var newHeight = Math.round(entry.contentRect.height);
996
+
997
+ if (previous.current.width !== newWidth || previous.current.height !== newHeight) {
998
+ var newSize = {
999
+ width: newWidth,
1000
+ height: newHeight
1001
+ };
1002
+
1003
+ if (onResizeRef.current) {
1004
+ onResizeRef.current(newSize);
1005
+ } else {
1006
+ previous.current.width = newWidth;
1007
+ previous.current.height = newHeight;
1008
+ setSize(newSize);
1009
+ }
1010
+ }
1011
+ });
1012
+ }, []);
1013
+ react.useEffect(function () {
1014
+ if (typeof ref !== "object" || ref === null || !(ref.current instanceof Element)) {
1015
+ return;
1016
+ }
1017
+
1018
+ var element = ref.current;
1019
+ resizeObserverRef.current.observe(element);
1020
+ return function () {
1021
+ return resizeObserverRef.current.unobserve(element);
1022
+ };
1023
+ }, [ref]);
1024
+ return react.useMemo(function () {
1025
+ return {
1026
+ ref: ref,
1027
+ width: size.width,
1028
+ height: size.height
1029
+ };
1030
+ }, [ref, size ? size.width : null, size ? size.height : null]);
1031
+ }
1032
+
1033
+ var polyfilled = useResizeObserver$1;
1034
+
1035
+ var useResizeObserverPackage = /*@__PURE__*/isObjectLike$1.getDefaultExportFromCjs(polyfilled);
1036
+
1037
+ var root = isObjectLike$1._root;
1038
+
1039
+ /**
1040
+ * Gets the timestamp of the number of milliseconds that have elapsed since
1041
+ * the Unix epoch (1 January 1970 00:00:00 UTC).
1042
+ *
1043
+ * @static
1044
+ * @memberOf _
1045
+ * @since 2.4.0
1046
+ * @category Date
1047
+ * @returns {number} Returns the timestamp.
1048
+ * @example
1049
+ *
1050
+ * _.defer(function(stamp) {
1051
+ * console.log(_.now() - stamp);
1052
+ * }, _.now());
1053
+ * // => Logs the number of milliseconds it took for the deferred invocation.
1054
+ */
1055
+ var now$1 = function() {
1056
+ return root.Date.now();
1057
+ };
1058
+
1059
+ var now_1 = now$1;
1060
+
1061
+ /** Used to match a single whitespace character. */
1062
+
1063
+ var reWhitespace = /\s/;
1064
+
1065
+ /**
1066
+ * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
1067
+ * character of `string`.
1068
+ *
1069
+ * @private
1070
+ * @param {string} string The string to inspect.
1071
+ * @returns {number} Returns the index of the last non-whitespace character.
1072
+ */
1073
+ function trimmedEndIndex$1(string) {
1074
+ var index = string.length;
1075
+
1076
+ while (index-- && reWhitespace.test(string.charAt(index))) {}
1077
+ return index;
1078
+ }
1079
+
1080
+ var _trimmedEndIndex = trimmedEndIndex$1;
1081
+
1082
+ var trimmedEndIndex = _trimmedEndIndex;
1083
+
1084
+ /** Used to match leading whitespace. */
1085
+ var reTrimStart = /^\s+/;
1086
+
1087
+ /**
1088
+ * The base implementation of `_.trim`.
1089
+ *
1090
+ * @private
1091
+ * @param {string} string The string to trim.
1092
+ * @returns {string} Returns the trimmed string.
1093
+ */
1094
+ function baseTrim$1(string) {
1095
+ return string
1096
+ ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
1097
+ : string;
1098
+ }
1099
+
1100
+ var _baseTrim = baseTrim$1;
1101
+
1102
+ var baseGetTag = isObjectLike$1._baseGetTag,
1103
+ isObjectLike = isObjectLike$1.isObjectLike_1;
1104
+
1105
+ /** `Object#toString` result references. */
1106
+ var symbolTag = '[object Symbol]';
1107
+
1108
+ /**
1109
+ * Checks if `value` is classified as a `Symbol` primitive or object.
1110
+ *
1111
+ * @static
1112
+ * @memberOf _
1113
+ * @since 4.0.0
1114
+ * @category Lang
1115
+ * @param {*} value The value to check.
1116
+ * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
1117
+ * @example
1118
+ *
1119
+ * _.isSymbol(Symbol.iterator);
1120
+ * // => true
1121
+ *
1122
+ * _.isSymbol('abc');
1123
+ * // => false
1124
+ */
1125
+ function isSymbol$1(value) {
1126
+ return typeof value == 'symbol' ||
1127
+ (isObjectLike(value) && baseGetTag(value) == symbolTag);
1128
+ }
1129
+
1130
+ var isSymbol_1 = isSymbol$1;
1131
+
1132
+ var baseTrim = _baseTrim,
1133
+ isObject$2 = isObjectLike$1.isObject_1,
1134
+ isSymbol = isSymbol_1;
1135
+
1136
+ /** Used as references for various `Number` constants. */
1137
+ var NAN = 0 / 0;
1138
+
1139
+ /** Used to detect bad signed hexadecimal string values. */
1140
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
1141
+
1142
+ /** Used to detect binary string values. */
1143
+ var reIsBinary = /^0b[01]+$/i;
1144
+
1145
+ /** Used to detect octal string values. */
1146
+ var reIsOctal = /^0o[0-7]+$/i;
1147
+
1148
+ /** Built-in method references without a dependency on `root`. */
1149
+ var freeParseInt = parseInt;
1150
+
1151
+ /**
1152
+ * Converts `value` to a number.
1153
+ *
1154
+ * @static
1155
+ * @memberOf _
1156
+ * @since 4.0.0
1157
+ * @category Lang
1158
+ * @param {*} value The value to process.
1159
+ * @returns {number} Returns the number.
1160
+ * @example
1161
+ *
1162
+ * _.toNumber(3.2);
1163
+ * // => 3.2
1164
+ *
1165
+ * _.toNumber(Number.MIN_VALUE);
1166
+ * // => 5e-324
1167
+ *
1168
+ * _.toNumber(Infinity);
1169
+ * // => Infinity
1170
+ *
1171
+ * _.toNumber('3.2');
1172
+ * // => 3.2
1173
+ */
1174
+ function toNumber$1(value) {
1175
+ if (typeof value == 'number') {
1176
+ return value;
1177
+ }
1178
+ if (isSymbol(value)) {
1179
+ return NAN;
1180
+ }
1181
+ if (isObject$2(value)) {
1182
+ var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
1183
+ value = isObject$2(other) ? (other + '') : other;
1184
+ }
1185
+ if (typeof value != 'string') {
1186
+ return value === 0 ? value : +value;
1187
+ }
1188
+ value = baseTrim(value);
1189
+ var isBinary = reIsBinary.test(value);
1190
+ return (isBinary || reIsOctal.test(value))
1191
+ ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
1192
+ : (reIsBadHex.test(value) ? NAN : +value);
1193
+ }
1194
+
1195
+ var toNumber_1 = toNumber$1;
1196
+
1197
+ var isObject$1 = isObjectLike$1.isObject_1,
1198
+ now = now_1,
1199
+ toNumber = toNumber_1;
1200
+
1201
+ /** Error message constants. */
1202
+ var FUNC_ERROR_TEXT$1 = 'Expected a function';
1203
+
1204
+ /* Built-in method references for those with the same name as other `lodash` methods. */
1205
+ var nativeMax = Math.max,
1206
+ nativeMin = Math.min;
1207
+
1208
+ /**
1209
+ * Creates a debounced function that delays invoking `func` until after `wait`
1210
+ * milliseconds have elapsed since the last time the debounced function was
1211
+ * invoked. The debounced function comes with a `cancel` method to cancel
1212
+ * delayed `func` invocations and a `flush` method to immediately invoke them.
1213
+ * Provide `options` to indicate whether `func` should be invoked on the
1214
+ * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
1215
+ * with the last arguments provided to the debounced function. Subsequent
1216
+ * calls to the debounced function return the result of the last `func`
1217
+ * invocation.
1218
+ *
1219
+ * **Note:** If `leading` and `trailing` options are `true`, `func` is
1220
+ * invoked on the trailing edge of the timeout only if the debounced function
1221
+ * is invoked more than once during the `wait` timeout.
1222
+ *
1223
+ * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
1224
+ * until to the next tick, similar to `setTimeout` with a timeout of `0`.
1225
+ *
1226
+ * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
1227
+ * for details over the differences between `_.debounce` and `_.throttle`.
1228
+ *
1229
+ * @static
1230
+ * @memberOf _
1231
+ * @since 0.1.0
1232
+ * @category Function
1233
+ * @param {Function} func The function to debounce.
1234
+ * @param {number} [wait=0] The number of milliseconds to delay.
1235
+ * @param {Object} [options={}] The options object.
1236
+ * @param {boolean} [options.leading=false]
1237
+ * Specify invoking on the leading edge of the timeout.
1238
+ * @param {number} [options.maxWait]
1239
+ * The maximum time `func` is allowed to be delayed before it's invoked.
1240
+ * @param {boolean} [options.trailing=true]
1241
+ * Specify invoking on the trailing edge of the timeout.
1242
+ * @returns {Function} Returns the new debounced function.
1243
+ * @example
1244
+ *
1245
+ * // Avoid costly calculations while the window size is in flux.
1246
+ * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
1247
+ *
1248
+ * // Invoke `sendMail` when clicked, debouncing subsequent calls.
1249
+ * jQuery(element).on('click', _.debounce(sendMail, 300, {
1250
+ * 'leading': true,
1251
+ * 'trailing': false
1252
+ * }));
1253
+ *
1254
+ * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
1255
+ * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
1256
+ * var source = new EventSource('/stream');
1257
+ * jQuery(source).on('message', debounced);
1258
+ *
1259
+ * // Cancel the trailing debounced invocation.
1260
+ * jQuery(window).on('popstate', debounced.cancel);
1261
+ */
1262
+ function debounce$1(func, wait, options) {
1263
+ var lastArgs,
1264
+ lastThis,
1265
+ maxWait,
1266
+ result,
1267
+ timerId,
1268
+ lastCallTime,
1269
+ lastInvokeTime = 0,
1270
+ leading = false,
1271
+ maxing = false,
1272
+ trailing = true;
1273
+
1274
+ if (typeof func != 'function') {
1275
+ throw new TypeError(FUNC_ERROR_TEXT$1);
1276
+ }
1277
+ wait = toNumber(wait) || 0;
1278
+ if (isObject$1(options)) {
1279
+ leading = !!options.leading;
1280
+ maxing = 'maxWait' in options;
1281
+ maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
1282
+ trailing = 'trailing' in options ? !!options.trailing : trailing;
1283
+ }
1284
+
1285
+ function invokeFunc(time) {
1286
+ var args = lastArgs,
1287
+ thisArg = lastThis;
1288
+
1289
+ lastArgs = lastThis = undefined;
1290
+ lastInvokeTime = time;
1291
+ result = func.apply(thisArg, args);
1292
+ return result;
1293
+ }
1294
+
1295
+ function leadingEdge(time) {
1296
+ // Reset any `maxWait` timer.
1297
+ lastInvokeTime = time;
1298
+ // Start the timer for the trailing edge.
1299
+ timerId = setTimeout(timerExpired, wait);
1300
+ // Invoke the leading edge.
1301
+ return leading ? invokeFunc(time) : result;
1302
+ }
1303
+
1304
+ function remainingWait(time) {
1305
+ var timeSinceLastCall = time - lastCallTime,
1306
+ timeSinceLastInvoke = time - lastInvokeTime,
1307
+ timeWaiting = wait - timeSinceLastCall;
1308
+
1309
+ return maxing
1310
+ ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
1311
+ : timeWaiting;
1312
+ }
1313
+
1314
+ function shouldInvoke(time) {
1315
+ var timeSinceLastCall = time - lastCallTime,
1316
+ timeSinceLastInvoke = time - lastInvokeTime;
1317
+
1318
+ // Either this is the first call, activity has stopped and we're at the
1319
+ // trailing edge, the system time has gone backwards and we're treating
1320
+ // it as the trailing edge, or we've hit the `maxWait` limit.
1321
+ return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
1322
+ (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
1323
+ }
1324
+
1325
+ function timerExpired() {
1326
+ var time = now();
1327
+ if (shouldInvoke(time)) {
1328
+ return trailingEdge(time);
1329
+ }
1330
+ // Restart the timer.
1331
+ timerId = setTimeout(timerExpired, remainingWait(time));
1332
+ }
1333
+
1334
+ function trailingEdge(time) {
1335
+ timerId = undefined;
1336
+
1337
+ // Only invoke if we have `lastArgs` which means `func` has been
1338
+ // debounced at least once.
1339
+ if (trailing && lastArgs) {
1340
+ return invokeFunc(time);
1341
+ }
1342
+ lastArgs = lastThis = undefined;
1343
+ return result;
1344
+ }
1345
+
1346
+ function cancel() {
1347
+ if (timerId !== undefined) {
1348
+ clearTimeout(timerId);
1349
+ }
1350
+ lastInvokeTime = 0;
1351
+ lastArgs = lastCallTime = lastThis = timerId = undefined;
1352
+ }
1353
+
1354
+ function flush() {
1355
+ return timerId === undefined ? result : trailingEdge(now());
1356
+ }
1357
+
1358
+ function debounced() {
1359
+ var time = now(),
1360
+ isInvoking = shouldInvoke(time);
1361
+
1362
+ lastArgs = arguments;
1363
+ lastThis = this;
1364
+ lastCallTime = time;
1365
+
1366
+ if (isInvoking) {
1367
+ if (timerId === undefined) {
1368
+ return leadingEdge(lastCallTime);
1369
+ }
1370
+ if (maxing) {
1371
+ // Handle invocations in a tight loop.
1372
+ clearTimeout(timerId);
1373
+ timerId = setTimeout(timerExpired, wait);
1374
+ return invokeFunc(lastCallTime);
1375
+ }
1376
+ }
1377
+ if (timerId === undefined) {
1378
+ timerId = setTimeout(timerExpired, wait);
1379
+ }
1380
+ return result;
1381
+ }
1382
+ debounced.cancel = cancel;
1383
+ debounced.flush = flush;
1384
+ return debounced;
1385
+ }
1386
+
1387
+ var debounce_1 = debounce$1;
1388
+
1389
+ var debounce = debounce_1,
1390
+ isObject = isObjectLike$1.isObject_1;
1391
+
1392
+ /** Error message constants. */
1393
+ var FUNC_ERROR_TEXT = 'Expected a function';
1394
+
1395
+ /**
1396
+ * Creates a throttled function that only invokes `func` at most once per
1397
+ * every `wait` milliseconds. The throttled function comes with a `cancel`
1398
+ * method to cancel delayed `func` invocations and a `flush` method to
1399
+ * immediately invoke them. Provide `options` to indicate whether `func`
1400
+ * should be invoked on the leading and/or trailing edge of the `wait`
1401
+ * timeout. The `func` is invoked with the last arguments provided to the
1402
+ * throttled function. Subsequent calls to the throttled function return the
1403
+ * result of the last `func` invocation.
1404
+ *
1405
+ * **Note:** If `leading` and `trailing` options are `true`, `func` is
1406
+ * invoked on the trailing edge of the timeout only if the throttled function
1407
+ * is invoked more than once during the `wait` timeout.
1408
+ *
1409
+ * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
1410
+ * until to the next tick, similar to `setTimeout` with a timeout of `0`.
1411
+ *
1412
+ * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
1413
+ * for details over the differences between `_.throttle` and `_.debounce`.
1414
+ *
1415
+ * @static
1416
+ * @memberOf _
1417
+ * @since 0.1.0
1418
+ * @category Function
1419
+ * @param {Function} func The function to throttle.
1420
+ * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
1421
+ * @param {Object} [options={}] The options object.
1422
+ * @param {boolean} [options.leading=true]
1423
+ * Specify invoking on the leading edge of the timeout.
1424
+ * @param {boolean} [options.trailing=true]
1425
+ * Specify invoking on the trailing edge of the timeout.
1426
+ * @returns {Function} Returns the new throttled function.
1427
+ * @example
1428
+ *
1429
+ * // Avoid excessively updating the position while scrolling.
1430
+ * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
1431
+ *
1432
+ * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
1433
+ * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
1434
+ * jQuery(element).on('click', throttled);
1435
+ *
1436
+ * // Cancel the trailing throttled invocation.
1437
+ * jQuery(window).on('popstate', throttled.cancel);
1438
+ */
1439
+ function throttle(func, wait, options) {
1440
+ var leading = true,
1441
+ trailing = true;
1442
+
1443
+ if (typeof func != 'function') {
1444
+ throw new TypeError(FUNC_ERROR_TEXT);
1445
+ }
1446
+ if (isObject(options)) {
1447
+ leading = 'leading' in options ? !!options.leading : leading;
1448
+ trailing = 'trailing' in options ? !!options.trailing : trailing;
1449
+ }
1450
+ return debounce(func, wait, {
1451
+ 'leading': leading,
1452
+ 'maxWait': wait,
1453
+ 'trailing': trailing
1454
+ });
1455
+ }
1456
+
1457
+ var throttle_1 = throttle;
1458
+
1459
+ var throttle$1 = /*@__PURE__*/isObjectLike$1.getDefaultExportFromCjs(throttle_1);
1460
+
1461
+ const Breakpoints = {
1462
+ base: 640,
1463
+ small: 500,
1464
+ smaller: 265,
1465
+ large: 750,
1466
+ larger: 1024,
1467
+ };
1468
+ const wait = 100;
1469
+ function useResizeObserver({ widths = Breakpoints, heights = Breakpoints, } = {}) {
1470
+ const [exactSize, setSize] = require$$1.useState({
1471
+ width: undefined,
1472
+ height: undefined,
1473
+ });
1474
+ const onResize = require$$1.useMemo(() => {
1475
+ return throttle$1(({ width, height }) => {
1476
+ if (!width || width <= 1) {
1477
+ // Ignore invalid values. ResizeObserver is unexpectedly looping between 1 and the actual
1478
+ // width of the element. This is only happening in playwright chromium.
1479
+ // Soon we need to replace this unmaintained package with a more reliable one.
1480
+ return;
1481
+ }
1482
+ setSize({ width, height });
1483
+ }, wait);
1484
+ }, []);
1485
+ const { ref } = useResizeObserverPackage({
1486
+ onResize,
1487
+ });
1488
+ const exactWidth = exactSize.width;
1489
+ const exactHeight = exactSize.height;
1490
+ const sizes = {
1491
+ width: getSize(widths, exactSize.width),
1492
+ height: getSize(heights, exactSize.height),
1493
+ exactWidth,
1494
+ exactHeight,
1495
+ };
1496
+ return [ref, sizes];
1497
+ }
1498
+ /**
1499
+ * To get the proper size we want to make sure that our value is greater
1500
+ * then the comparable, but less then the next largest number in our
1501
+ * object.
1502
+ */
1503
+ function getSize(sizes, comparable) {
1504
+ if (!comparable || !sizes) {
1505
+ return undefined;
1506
+ }
1507
+ /**
1508
+ * Sort the values of our object so that we know they are in proper
1509
+ * order to be compared by
1510
+ */
1511
+ const sortedSizes = Object.values(sizes)
1512
+ .sort((a, b) => a - b)
1513
+ .reverse();
1514
+ return (sortedSizes.find(value => value <= comparable) ||
1515
+ sortedSizes[sortedSizes.length - 1]);
1516
+ }
1517
+
1518
+ exports.Breakpoints = Breakpoints;
1519
+ exports.useResizeObserver = useResizeObserver;