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