@reactuses/core 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs ADDED
@@ -0,0 +1,2215 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var lodash = require('lodash');
7
+
8
+ function usePrevious(state) {
9
+ const ref = react.useRef();
10
+ react.useEffect(() => {
11
+ ref.current = state;
12
+ });
13
+ return ref.current;
14
+ }
15
+
16
+ var __async$1 = (__this, __arguments, generator) => {
17
+ return new Promise((resolve, reject) => {
18
+ var fulfilled = (value) => {
19
+ try {
20
+ step(generator.next(value));
21
+ } catch (e) {
22
+ reject(e);
23
+ }
24
+ };
25
+ var rejected = (value) => {
26
+ try {
27
+ step(generator.throw(value));
28
+ } catch (e) {
29
+ reject(e);
30
+ }
31
+ };
32
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
33
+ step((generator = generator.apply(__this, __arguments)).next());
34
+ });
35
+ };
36
+ function useMarkdown(filepath) {
37
+ const [content, setContent] = react.useState("");
38
+ react.useEffect(() => {
39
+ const getContent = () => __async$1(this, null, function* () {
40
+ const data = yield (yield fetch(filepath)).text();
41
+ setContent(data);
42
+ });
43
+ getContent();
44
+ }, [filepath]);
45
+ return content;
46
+ }
47
+
48
+ function useLatest(value) {
49
+ const ref = react.useRef(value);
50
+ react.useEffect(() => {
51
+ ref.current = value;
52
+ }, [value]);
53
+ return ref;
54
+ }
55
+
56
+ function useFirstMountState() {
57
+ const isFirst = react.useRef(true);
58
+ if (isFirst.current) {
59
+ isFirst.current = false;
60
+ return true;
61
+ }
62
+ return isFirst.current;
63
+ }
64
+
65
+ const createUpdateEffect = (hook) => (effect, deps) => {
66
+ const isFirstMount = useFirstMountState();
67
+ hook(() => {
68
+ if (!isFirstMount) {
69
+ return effect();
70
+ }
71
+ }, deps);
72
+ };
73
+
74
+ var useUpdateEffect = createUpdateEffect(react.useEffect);
75
+
76
+ var useUpdateLayoutEffect = createUpdateEffect(react.useLayoutEffect);
77
+
78
+ var _a;
79
+ const isFunction = (val) => typeof val === "function";
80
+ const isDev = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
81
+ const isBrowser = typeof window !== "undefined";
82
+ const isNavigator = typeof navigator !== "undefined";
83
+ const noop = () => {
84
+ };
85
+ const isIOS = isBrowser && ((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
86
+
87
+ function guessSerializerType(rawInit) {
88
+ return rawInit == null ? "any" : rawInit instanceof Set ? "set" : rawInit instanceof Map ? "map" : rawInit instanceof Date ? "date" : typeof rawInit === "boolean" ? "boolean" : typeof rawInit === "string" ? "string" : typeof rawInit === "object" ? "object" : Array.isArray(rawInit) ? "object" : !Number.isNaN(rawInit) ? "number" : "any";
89
+ }
90
+
91
+ const useIsomorphicLayoutEffect = isBrowser ? react.useLayoutEffect : react.useEffect;
92
+
93
+ function useEvent(fn) {
94
+ if (isDev) {
95
+ if (!isFunction(fn)) {
96
+ console.error(
97
+ `useEvent expected parameter is a function, got ${typeof fn}`
98
+ );
99
+ }
100
+ }
101
+ const handlerRef = react.useRef(fn);
102
+ useIsomorphicLayoutEffect(() => {
103
+ handlerRef.current = fn;
104
+ }, [fn]);
105
+ return react.useCallback((...args) => {
106
+ const fn2 = handlerRef.current;
107
+ return fn2(...args);
108
+ }, []);
109
+ }
110
+
111
+ const StorageSerializers = {
112
+ boolean: {
113
+ read: (v) => v === "true",
114
+ write: (v) => String(v)
115
+ },
116
+ object: {
117
+ read: (v) => JSON.parse(v),
118
+ write: (v) => JSON.stringify(v)
119
+ },
120
+ number: {
121
+ read: (v) => Number.parseFloat(v),
122
+ write: (v) => String(v)
123
+ },
124
+ any: {
125
+ read: (v) => v,
126
+ write: (v) => String(v)
127
+ },
128
+ string: {
129
+ read: (v) => v,
130
+ write: (v) => String(v)
131
+ },
132
+ map: {
133
+ read: (v) => new Map(JSON.parse(v)),
134
+ write: (v) => JSON.stringify(Array.from(v.entries()))
135
+ },
136
+ set: {
137
+ read: (v) => new Set(JSON.parse(v)),
138
+ write: (v) => JSON.stringify(Array.from(v))
139
+ },
140
+ date: {
141
+ read: (v) => new Date(v),
142
+ write: (v) => v.toISOString()
143
+ }
144
+ };
145
+ function useStorage(key, defaults, getStorage, options = {}) {
146
+ var _a;
147
+ let storage;
148
+ const {
149
+ onError = (e) => {
150
+ console.error(e);
151
+ }
152
+ } = options;
153
+ const data = defaults;
154
+ try {
155
+ storage = getStorage();
156
+ } catch (err) {
157
+ console.error(err);
158
+ }
159
+ const type = guessSerializerType(defaults);
160
+ const serializer = (_a = options.serializer) != null ? _a : StorageSerializers[type];
161
+ const getStoredValue = () => {
162
+ try {
163
+ const raw = storage == null ? void 0 : storage.getItem(key);
164
+ if (raw) {
165
+ return serializer.read(raw);
166
+ } else {
167
+ storage == null ? void 0 : storage.setItem(key, serializer.write(data));
168
+ return data;
169
+ }
170
+ } catch (e) {
171
+ onError(e);
172
+ }
173
+ };
174
+ const [state, setState] = react.useState(() => getStoredValue());
175
+ useUpdateEffect(() => {
176
+ setState(getStoredValue());
177
+ }, [key]);
178
+ const updateState = useEvent(
179
+ (valOrFunc) => {
180
+ const currentState = isFunction(valOrFunc) ? valOrFunc(state) : valOrFunc;
181
+ setState(currentState);
182
+ if (currentState === null) {
183
+ storage == null ? void 0 : storage.removeItem(key);
184
+ } else {
185
+ try {
186
+ storage == null ? void 0 : storage.setItem(key, serializer.write(currentState));
187
+ } catch (e) {
188
+ onError(e);
189
+ }
190
+ }
191
+ }
192
+ );
193
+ return [state, updateState];
194
+ }
195
+
196
+ function useLocalStorage(key, defaults, options = {}) {
197
+ return useStorage(
198
+ key,
199
+ defaults,
200
+ () => isBrowser ? localStorage : void 0,
201
+ options
202
+ );
203
+ }
204
+
205
+ function useSessionStorage(key, defaults, options = {}) {
206
+ return useStorage(
207
+ key,
208
+ defaults,
209
+ () => isBrowser ? sessionStorage : void 0,
210
+ options
211
+ );
212
+ }
213
+
214
+ const toggleReducer = (state, nextValue) => typeof nextValue === "boolean" ? nextValue : !state;
215
+ function useToggle(initialValue) {
216
+ return react.useReducer(toggleReducer, initialValue);
217
+ }
218
+
219
+ function useInterval(callback, delay, options) {
220
+ const immediate = options == null ? void 0 : options.immediate;
221
+ const savedCallback = useLatest(callback);
222
+ react.useEffect(() => {
223
+ if (immediate) {
224
+ savedCallback.current();
225
+ }
226
+ if (delay !== null) {
227
+ const interval = setInterval(() => savedCallback.current(), delay || 0);
228
+ return () => clearInterval(interval);
229
+ }
230
+ return void 0;
231
+ }, [delay, immediate]);
232
+ }
233
+
234
+ const getInitialState = (query, defaultState) => {
235
+ if (isBrowser) {
236
+ return window.matchMedia(query).matches;
237
+ }
238
+ if (defaultState !== void 0) {
239
+ return defaultState;
240
+ }
241
+ if (process.env.NODE_ENV !== "production") {
242
+ console.warn(
243
+ "`useMedia` When server side rendering, defaultState should be defined to prevent a hydration mismatches."
244
+ );
245
+ }
246
+ return false;
247
+ };
248
+ function useMediaQuery(query, defaultState) {
249
+ const [state, setState] = react.useState(getInitialState(query, defaultState));
250
+ react.useEffect(() => {
251
+ let mounted = true;
252
+ const mql = window.matchMedia(query);
253
+ const onChange = () => {
254
+ if (!mounted) {
255
+ return;
256
+ }
257
+ setState(!!mql.matches);
258
+ };
259
+ if ("addEventListener" in mql) {
260
+ mql.addEventListener("change", onChange);
261
+ } else {
262
+ mql.addListener(onChange);
263
+ }
264
+ setState(mql.matches);
265
+ return () => {
266
+ mounted = false;
267
+ if ("removeEventListener" in mql) {
268
+ mql.removeEventListener("change", onChange);
269
+ } else {
270
+ mql.removeListener(onChange);
271
+ }
272
+ };
273
+ }, [query]);
274
+ return state;
275
+ }
276
+
277
+ function usePreferredDark(defaultState) {
278
+ return useMediaQuery("(prefers-color-scheme: dark)", defaultState);
279
+ }
280
+
281
+ function useDarkMode(options = {}) {
282
+ const {
283
+ selector = "html",
284
+ attribute = "class",
285
+ initialValue,
286
+ storageKey = "reactuses-color-scheme",
287
+ storage = () => isBrowser ? localStorage : void 0
288
+ } = options;
289
+ const prefersDarkMode = usePreferredDark();
290
+ const value = initialValue ? initialValue : prefersDarkMode ? "dark" : "light";
291
+ const [dark, setDark] = useStorage(storageKey, value, storage);
292
+ react.useEffect(() => {
293
+ const element = window == null ? void 0 : window.document.querySelector(selector);
294
+ if (!element) {
295
+ return;
296
+ }
297
+ if (attribute === "class") {
298
+ dark && element.classList.add(dark);
299
+ } else {
300
+ dark && element.setAttribute(attribute, dark);
301
+ }
302
+ return () => {
303
+ dark && (element == null ? void 0 : element.classList.remove(dark));
304
+ };
305
+ }, [attribute, dark, selector]);
306
+ return [dark, setDark];
307
+ }
308
+
309
+ function useMount(fn) {
310
+ if (isDev) {
311
+ if (!isFunction(fn)) {
312
+ console.error(
313
+ `useMount: parameter \`fn\` expected to be a function, but got "${typeof fn}".`
314
+ );
315
+ }
316
+ }
317
+ react.useEffect(() => {
318
+ fn == null ? void 0 : fn();
319
+ }, []);
320
+ }
321
+
322
+ function useUnmount(fn) {
323
+ if (isDev) {
324
+ if (!isFunction(fn)) {
325
+ console.error(
326
+ `useUnmount expected parameter is a function, got ${typeof fn}`
327
+ );
328
+ }
329
+ }
330
+ const fnRef = useLatest(fn);
331
+ react.useEffect(
332
+ () => () => {
333
+ fnRef.current();
334
+ },
335
+ [fnRef]
336
+ );
337
+ }
338
+
339
+ function useThrottleFn(fn, wait, options) {
340
+ if (isDev) {
341
+ if (!isFunction(fn)) {
342
+ console.error(
343
+ `useThrottleFn expected parameter is a function, got ${typeof fn}`
344
+ );
345
+ }
346
+ }
347
+ const fnRef = useLatest(fn);
348
+ const throttled = react.useMemo(
349
+ () => lodash.throttle(
350
+ (...args) => {
351
+ return fnRef.current(...args);
352
+ },
353
+ wait,
354
+ options
355
+ ),
356
+ []
357
+ );
358
+ useUnmount(() => {
359
+ throttled.cancel();
360
+ });
361
+ return {
362
+ run: throttled,
363
+ cancel: throttled.cancel,
364
+ flush: throttled.flush
365
+ };
366
+ }
367
+
368
+ function useThrottle(value, wait, options) {
369
+ const [throttled, setThrottled] = react.useState(value);
370
+ const { run } = useThrottleFn(
371
+ () => {
372
+ setThrottled(value);
373
+ },
374
+ wait,
375
+ options
376
+ );
377
+ react.useEffect(() => {
378
+ run();
379
+ }, [run, value]);
380
+ return throttled;
381
+ }
382
+
383
+ function useDebounceFn(fn, wait, options) {
384
+ if (isDev) {
385
+ if (!isFunction(fn)) {
386
+ console.error(
387
+ `useDebounceFn expected parameter is a function, got ${typeof fn}`
388
+ );
389
+ }
390
+ }
391
+ const fnRef = useLatest(fn);
392
+ const debounced = react.useMemo(
393
+ () => lodash.debounce(
394
+ (...args) => {
395
+ return fnRef.current(...args);
396
+ },
397
+ wait,
398
+ options
399
+ ),
400
+ []
401
+ );
402
+ useUnmount(() => {
403
+ debounced.cancel();
404
+ });
405
+ return {
406
+ run: debounced,
407
+ cancel: debounced.cancel,
408
+ flush: debounced.flush
409
+ };
410
+ }
411
+
412
+ function useDebounce(value, wait, options) {
413
+ const [debounced, setDebounced] = react.useState(value);
414
+ const { run } = useDebounceFn(
415
+ () => {
416
+ setDebounced(value);
417
+ },
418
+ wait,
419
+ options
420
+ );
421
+ react.useEffect(() => {
422
+ run();
423
+ }, [run, value]);
424
+ return debounced;
425
+ }
426
+
427
+ function useRafState(initialState) {
428
+ const frame = react.useRef(0);
429
+ const [state, setState] = react.useState(initialState);
430
+ const setRafState = react.useCallback((value) => {
431
+ cancelAnimationFrame(frame.current);
432
+ frame.current = requestAnimationFrame(() => {
433
+ setState(value);
434
+ });
435
+ }, []);
436
+ useUnmount(() => {
437
+ cancelAnimationFrame(frame.current);
438
+ });
439
+ return [state, setRafState];
440
+ }
441
+
442
+ const updateReducer = (num) => (num + 1) % 1e6;
443
+ function useUpdate() {
444
+ const [, update] = react.useReducer(updateReducer, 0);
445
+ return update;
446
+ }
447
+
448
+ function useTimeoutFn(cb, interval, options = {}) {
449
+ const { immediate = true } = options;
450
+ const [pending, setPending] = react.useState(false);
451
+ const savedCallback = useLatest(cb);
452
+ const timer = react.useRef();
453
+ const stop = useEvent(() => {
454
+ setPending(false);
455
+ if (timer.current) {
456
+ clearTimeout(timer.current);
457
+ }
458
+ });
459
+ const start = useEvent((...args) => {
460
+ if (timer) {
461
+ clearTimeout(timer.current);
462
+ }
463
+ timer.current = setTimeout(() => {
464
+ setPending(false);
465
+ savedCallback.current(...args);
466
+ }, interval);
467
+ setPending(true);
468
+ });
469
+ react.useEffect(() => {
470
+ if (immediate) {
471
+ start();
472
+ }
473
+ return stop;
474
+ }, [stop, immediate, interval, start]);
475
+ return [pending, start, stop];
476
+ }
477
+
478
+ function useTimeout(ms = 0, options = {}) {
479
+ const update = useUpdate();
480
+ return useTimeoutFn(update, ms, options);
481
+ }
482
+
483
+ function useMountedState() {
484
+ const mountedRef = react.useRef(false);
485
+ const get = react.useCallback(() => mountedRef.current, []);
486
+ react.useEffect(() => {
487
+ mountedRef.current = true;
488
+ return () => {
489
+ mountedRef.current = false;
490
+ };
491
+ }, []);
492
+ return get;
493
+ }
494
+
495
+ function on(obj, ...args) {
496
+ if (obj && obj.addEventListener) {
497
+ obj.addEventListener(
498
+ ...args
499
+ );
500
+ }
501
+ }
502
+ function off(obj, ...args) {
503
+ if (obj && obj.removeEventListener) {
504
+ obj.removeEventListener(
505
+ ...args
506
+ );
507
+ }
508
+ }
509
+
510
+ function getTargetElement(target, defaultElement) {
511
+ if (!isBrowser) {
512
+ return void 0;
513
+ }
514
+ if (!target) {
515
+ return defaultElement;
516
+ }
517
+ let targetElement;
518
+ if (isFunction(target)) {
519
+ targetElement = target();
520
+ } else if ("current" in target) {
521
+ targetElement = target.current;
522
+ } else {
523
+ targetElement = target;
524
+ }
525
+ return targetElement;
526
+ }
527
+
528
+ const isPrimitive$1 = (val) => val !== Object(val);
529
+ function useCustomCompareEffect(effect, deps, depsEqual) {
530
+ if (process.env.NODE_ENV !== "production") {
531
+ if (!(deps instanceof Array) || !deps.length) {
532
+ console.warn(
533
+ "`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
534
+ );
535
+ }
536
+ if (deps.every(isPrimitive$1)) {
537
+ console.warn(
538
+ "`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
539
+ );
540
+ }
541
+ if (typeof depsEqual !== "function") {
542
+ console.warn(
543
+ "`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list"
544
+ );
545
+ }
546
+ }
547
+ const ref = react.useRef(void 0);
548
+ if (!ref.current || !depsEqual(deps, ref.current)) {
549
+ ref.current = deps;
550
+ }
551
+ react.useEffect(effect, ref.current);
552
+ }
553
+
554
+ const isPrimitive = (val) => val !== Object(val);
555
+ function useDeepCompareEffect(effect, deps) {
556
+ if (process.env.NODE_ENV !== "production") {
557
+ if (!(deps instanceof Array) || !deps.length) {
558
+ console.warn(
559
+ "`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
560
+ );
561
+ }
562
+ if (deps.every(isPrimitive)) {
563
+ console.warn(
564
+ "`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
565
+ );
566
+ }
567
+ }
568
+ useCustomCompareEffect(effect, deps, lodash.isEqual);
569
+ }
570
+
571
+ function useEventListener(eventName, handler, element, options) {
572
+ const savedHandler = useLatest(handler);
573
+ useDeepCompareEffect(() => {
574
+ const targetElement = getTargetElement(element, window);
575
+ if (!(targetElement && targetElement.addEventListener)) {
576
+ return;
577
+ }
578
+ const eventListener = (event) => savedHandler.current(event);
579
+ on(targetElement, eventName, eventListener, options);
580
+ return () => {
581
+ off(targetElement, eventName, eventListener);
582
+ };
583
+ }, [eventName, element, options, savedHandler]);
584
+ }
585
+
586
+ function useCounter(initialValue = 0, max = null, min = null) {
587
+ const initFunc = () => {
588
+ let init = typeof initialValue === "function" ? initialValue() : initialValue;
589
+ typeof init !== "number" && console.error(
590
+ "initialValue has to be a number, got " + typeof initialValue
591
+ );
592
+ if (typeof min === "number") {
593
+ init = Math.max(init, min);
594
+ } else if (min !== null) {
595
+ console.error("min has to be a number, got " + typeof min);
596
+ }
597
+ if (typeof max === "number") {
598
+ init = Math.min(init, max);
599
+ } else if (max !== null) {
600
+ console.error("max has to be a number, got " + typeof max);
601
+ }
602
+ return init;
603
+ };
604
+ const [value, setValue] = react.useState(initFunc);
605
+ const set = useEvent(
606
+ (newState) => {
607
+ setValue((v) => {
608
+ let nextValue = typeof newState === "function" ? newState(v) : newState;
609
+ if (typeof min === "number") {
610
+ nextValue = Math.max(nextValue, min);
611
+ }
612
+ if (typeof max === "number") {
613
+ nextValue = Math.min(nextValue, max);
614
+ }
615
+ return nextValue;
616
+ });
617
+ }
618
+ );
619
+ const inc = (delta = 1) => {
620
+ set((value2) => value2 + delta);
621
+ };
622
+ const dec = (delta = 1) => {
623
+ set((value2) => value2 - delta);
624
+ };
625
+ const reset = () => {
626
+ set(initFunc);
627
+ };
628
+ return [value, set, inc, dec, reset];
629
+ }
630
+
631
+ function useRafFn(callback, initiallyActive = true) {
632
+ const raf = react.useRef(null);
633
+ const rafActivity = react.useRef(false);
634
+ const rafCallback = useLatest(callback);
635
+ const step = react.useCallback(
636
+ (time) => {
637
+ if (rafActivity.current) {
638
+ rafCallback.current(time);
639
+ raf.current = requestAnimationFrame(step);
640
+ }
641
+ },
642
+ [rafCallback]
643
+ );
644
+ const result = react.useMemo(
645
+ () => [
646
+ () => {
647
+ if (rafActivity.current) {
648
+ rafActivity.current = false;
649
+ raf.current && cancelAnimationFrame(raf.current);
650
+ }
651
+ },
652
+ () => {
653
+ if (!rafActivity.current) {
654
+ rafActivity.current = true;
655
+ raf.current = requestAnimationFrame(step);
656
+ }
657
+ },
658
+ () => rafActivity.current
659
+ ],
660
+ [step]
661
+ );
662
+ react.useEffect(() => {
663
+ if (initiallyActive) {
664
+ result[1]();
665
+ }
666
+ return result[0];
667
+ }, [initiallyActive, result]);
668
+ return result;
669
+ }
670
+
671
+ function useEventEmitter() {
672
+ const listeners = react.useRef([]);
673
+ const _event = react.useRef((listener) => {
674
+ listeners.current.push(listener);
675
+ const disposable = {
676
+ dispose: () => {
677
+ if (!_disposed.current) {
678
+ for (let i = 0; i < listeners.current.length; i++) {
679
+ if (listeners.current[i] === listener) {
680
+ listeners.current.splice(i, 1);
681
+ return;
682
+ }
683
+ }
684
+ }
685
+ }
686
+ };
687
+ return disposable;
688
+ });
689
+ const _disposed = react.useRef(false);
690
+ const fire = (arg1, arg2) => {
691
+ const queue = [];
692
+ for (let i = 0; i < listeners.current.length; i++) {
693
+ queue.push(listeners.current[i]);
694
+ }
695
+ for (let i = 0; i < queue.length; i++) {
696
+ queue[i].call(void 0, arg1, arg2);
697
+ }
698
+ };
699
+ const dispose = () => {
700
+ if (listeners.current.length !== 0) {
701
+ listeners.current.length = 0;
702
+ }
703
+ _disposed.current = true;
704
+ };
705
+ return [_event.current, fire, dispose];
706
+ }
707
+
708
+ function useFavicon(href, baseUrl = "", rel = "icon") {
709
+ react.useEffect(() => {
710
+ const url = `${baseUrl}${href}`;
711
+ const element = document.head.querySelectorAll(
712
+ `link[rel*="${rel}"]`
713
+ );
714
+ element.forEach((el) => el.href = url);
715
+ if (element.length === 0) {
716
+ const link = document.createElement("link");
717
+ link.rel = rel;
718
+ link.href = url;
719
+ document.getElementsByTagName("head")[0].appendChild(link);
720
+ }
721
+ }, [baseUrl, href, rel]);
722
+ }
723
+
724
+ function useMutationObserver(callback, target, options = {}) {
725
+ const callbackRef = useLatest(callback);
726
+ const observerRef = react.useRef();
727
+ const stop = react.useCallback(() => {
728
+ if (observerRef.current) {
729
+ observerRef.current.disconnect();
730
+ }
731
+ }, []);
732
+ useDeepCompareEffect(() => {
733
+ const element = getTargetElement(target);
734
+ if (!element) {
735
+ return;
736
+ }
737
+ observerRef.current = new MutationObserver(callbackRef.current);
738
+ observerRef.current.observe(element, options);
739
+ return stop;
740
+ }, [options]);
741
+ return stop;
742
+ }
743
+
744
+ function useTitle(title) {
745
+ react.useEffect(() => {
746
+ document.title = title;
747
+ }, [title]);
748
+ }
749
+
750
+ function useScriptTag(src, onLoaded = noop, options = {}) {
751
+ const {
752
+ immediate = true,
753
+ manual = false,
754
+ type = "text/javascript",
755
+ async = true,
756
+ crossOrigin,
757
+ referrerPolicy,
758
+ noModule,
759
+ defer,
760
+ attrs = {}
761
+ } = options;
762
+ const scriptTag = react.useRef(null);
763
+ const _promise = react.useRef(null);
764
+ const [status, setStatus] = react.useState(src ? "loading" : "idle");
765
+ const loadScript = (waitForScriptLoad) => new Promise((resolve, reject) => {
766
+ const resolveWithElement = (el2) => {
767
+ scriptTag.current = el2;
768
+ resolve(el2);
769
+ return el2;
770
+ };
771
+ if (!document) {
772
+ resolve(false);
773
+ return;
774
+ }
775
+ if (!src) {
776
+ setStatus("idle");
777
+ resolve(false);
778
+ return;
779
+ }
780
+ let shouldAppend = false;
781
+ let el = document.querySelector(
782
+ `script[src="${src}"]`
783
+ );
784
+ if (!el) {
785
+ el = document.createElement("script");
786
+ el.type = type;
787
+ el.async = async;
788
+ el.src = src;
789
+ if (defer) {
790
+ el.defer = defer;
791
+ }
792
+ if (crossOrigin) {
793
+ el.crossOrigin = crossOrigin;
794
+ }
795
+ if (noModule) {
796
+ el.noModule = noModule;
797
+ }
798
+ if (referrerPolicy) {
799
+ el.referrerPolicy = referrerPolicy;
800
+ }
801
+ Object.entries(attrs).forEach(
802
+ ([name, value]) => el == null ? void 0 : el.setAttribute(name, value)
803
+ );
804
+ shouldAppend = true;
805
+ } else if (el.hasAttribute("data-loaded")) {
806
+ setStatus(el.getAttribute("data-status"));
807
+ resolveWithElement(el);
808
+ }
809
+ el.addEventListener("error", (event) => {
810
+ setStatus(event.type === "load" ? "ready" : "error");
811
+ return reject(event);
812
+ });
813
+ el.addEventListener("abort", (event) => {
814
+ setStatus(event.type === "load" ? "ready" : "error");
815
+ return reject(event);
816
+ });
817
+ el.addEventListener("load", (event) => {
818
+ setStatus(event.type === "load" ? "ready" : "error");
819
+ el.setAttribute("data-loaded", "true");
820
+ onLoaded(el);
821
+ resolveWithElement(el);
822
+ });
823
+ if (shouldAppend) {
824
+ el = document.head.appendChild(el);
825
+ }
826
+ if (!waitForScriptLoad) {
827
+ resolveWithElement(el);
828
+ }
829
+ });
830
+ const load = (waitForScriptLoad = true) => {
831
+ if (!_promise.current) {
832
+ _promise.current = loadScript(waitForScriptLoad);
833
+ }
834
+ return _promise.current;
835
+ };
836
+ const unload = () => {
837
+ if (!document) {
838
+ return;
839
+ }
840
+ _promise.current = null;
841
+ if (scriptTag.current) {
842
+ scriptTag.current = null;
843
+ }
844
+ const el = document.querySelector(
845
+ `script[src="${src}"]`
846
+ );
847
+ if (el) {
848
+ document.head.removeChild(el);
849
+ }
850
+ };
851
+ useMount(() => {
852
+ if (immediate && !manual) {
853
+ load();
854
+ }
855
+ });
856
+ useUnmount(() => {
857
+ if (!manual) {
858
+ unload();
859
+ }
860
+ });
861
+ return [scriptTag.current, status, load, unload];
862
+ }
863
+
864
+ function usePermission(permissionDesc) {
865
+ const [state, setState] = react.useState("");
866
+ react.useEffect(() => {
867
+ const desc = typeof permissionDesc === "string" ? { name: permissionDesc } : permissionDesc;
868
+ let mounted = true;
869
+ let permissionStatus = null;
870
+ const onChange = () => {
871
+ if (!mounted) {
872
+ return;
873
+ }
874
+ setState(() => {
875
+ var _a;
876
+ return (_a = permissionStatus == null ? void 0 : permissionStatus.state) != null ? _a : "";
877
+ });
878
+ };
879
+ navigator.permissions.query(desc).then((status) => {
880
+ permissionStatus = status;
881
+ on(permissionStatus, "change", onChange);
882
+ onChange();
883
+ }).catch(noop);
884
+ return () => {
885
+ permissionStatus && off(permissionStatus, "change", onChange);
886
+ mounted = false;
887
+ permissionStatus = null;
888
+ };
889
+ }, [permissionDesc]);
890
+ return state;
891
+ }
892
+
893
+ const isTouchEvent = (ev) => {
894
+ return "touches" in ev;
895
+ };
896
+ const preventDefault$1 = (ev) => {
897
+ if (!isTouchEvent(ev)) {
898
+ return;
899
+ }
900
+ if (ev.touches.length < 2 && ev.preventDefault) {
901
+ ev.preventDefault();
902
+ }
903
+ };
904
+ function useLongPress(callback, { isPreventDefault = true, delay = 300 } = {}) {
905
+ const timeout = react.useRef();
906
+ const target = react.useRef();
907
+ const start = react.useCallback(
908
+ (event) => {
909
+ if (isPreventDefault && event.target) {
910
+ on(event.target, "touchend", preventDefault$1, { passive: false });
911
+ target.current = event.target;
912
+ }
913
+ timeout.current = setTimeout(() => callback(event), delay);
914
+ },
915
+ [callback, delay, isPreventDefault]
916
+ );
917
+ const clear = react.useCallback(() => {
918
+ timeout.current && clearTimeout(timeout.current);
919
+ if (isPreventDefault && target.current) {
920
+ off(target.current, "touchend", preventDefault$1);
921
+ }
922
+ }, [isPreventDefault]);
923
+ return {
924
+ onMouseDown: (e) => start(e),
925
+ onTouchStart: (e) => start(e),
926
+ onMouseUp: clear,
927
+ onMouseLeave: clear,
928
+ onTouchEnd: clear
929
+ };
930
+ }
931
+
932
+ function useObjectUrl(object) {
933
+ const [url, setUrl] = react.useState();
934
+ react.useEffect(() => {
935
+ if (object) {
936
+ setUrl(URL.createObjectURL(object));
937
+ }
938
+ return () => {
939
+ if (url) {
940
+ URL.revokeObjectURL(url);
941
+ }
942
+ };
943
+ }, [object]);
944
+ return url;
945
+ }
946
+
947
+ const defaultEvents$1 = [
948
+ "mousemove",
949
+ "mousedown",
950
+ "resize",
951
+ "keydown",
952
+ "touchstart",
953
+ "wheel"
954
+ ];
955
+ const oneMinute = 6e4;
956
+ function useIdle(ms = oneMinute, initialState = false, events = defaultEvents$1) {
957
+ const [state, setState] = react.useState(initialState);
958
+ react.useEffect(() => {
959
+ let mounted = true;
960
+ let timeout;
961
+ let localState = state;
962
+ const set = (newState) => {
963
+ if (mounted) {
964
+ localState = newState;
965
+ setState(newState);
966
+ }
967
+ };
968
+ const onEvent = lodash.throttle(() => {
969
+ if (localState) {
970
+ set(false);
971
+ }
972
+ clearTimeout(timeout);
973
+ timeout = setTimeout(() => set(true), ms);
974
+ }, 50);
975
+ const onVisibility = () => {
976
+ if (!document.hidden) {
977
+ onEvent();
978
+ }
979
+ };
980
+ for (let i = 0; i < events.length; i++) {
981
+ on(window, events[i], onEvent);
982
+ }
983
+ on(document, "visibilitychange", onVisibility);
984
+ timeout = setTimeout(() => set(true), ms);
985
+ return () => {
986
+ mounted = false;
987
+ for (let i = 0; i < events.length; i++) {
988
+ off(window, events[i], onEvent);
989
+ }
990
+ off(document, "visibilitychange", onVisibility);
991
+ };
992
+ }, [ms, events]);
993
+ return state;
994
+ }
995
+
996
+ function useMediaDevices() {
997
+ const [state, setState] = react.useState({ devices: [] });
998
+ react.useEffect(() => {
999
+ let mounted = true;
1000
+ const onChange = () => {
1001
+ navigator.mediaDevices.enumerateDevices().then((devices) => {
1002
+ if (mounted) {
1003
+ setState({
1004
+ devices: devices.map(({ deviceId, groupId, kind, label }) => ({
1005
+ deviceId,
1006
+ groupId,
1007
+ kind,
1008
+ label
1009
+ }))
1010
+ });
1011
+ }
1012
+ }).catch(noop);
1013
+ };
1014
+ on(navigator.mediaDevices, "devicechange", onChange);
1015
+ onChange();
1016
+ return () => {
1017
+ mounted = false;
1018
+ off(navigator.mediaDevices, "devicechange", onChange);
1019
+ };
1020
+ }, []);
1021
+ return state;
1022
+ }
1023
+ const useMediaDevicesMock = () => ({});
1024
+ var useMediaDevices$1 = isNavigator && !!navigator.mediaDevices ? useMediaDevices : useMediaDevicesMock;
1025
+
1026
+ function useTextDirection(options = {}) {
1027
+ const { selector = "html", initialValue = "ltr" } = options;
1028
+ const getValue = () => {
1029
+ var _a, _b;
1030
+ if (isBrowser) {
1031
+ return (_b = (_a = document == null ? void 0 : document.querySelector(selector)) == null ? void 0 : _a.getAttribute("dir")) != null ? _b : initialValue;
1032
+ } else {
1033
+ return initialValue;
1034
+ }
1035
+ };
1036
+ const [value, setValue] = react.useState(getValue());
1037
+ const set = (value2) => {
1038
+ var _a, _b;
1039
+ if (!isBrowser) {
1040
+ return;
1041
+ }
1042
+ if (value2 !== null) {
1043
+ (_a = document.querySelector(selector)) == null ? void 0 : _a.setAttribute("dir", value2);
1044
+ } else {
1045
+ (_b = document.querySelector(selector)) == null ? void 0 : _b.removeAttribute("dir");
1046
+ }
1047
+ setValue(value2);
1048
+ };
1049
+ return [value, set];
1050
+ }
1051
+
1052
+ const initState = {
1053
+ screenX: NaN,
1054
+ screenY: NaN,
1055
+ clientX: NaN,
1056
+ clientY: NaN,
1057
+ pageX: NaN,
1058
+ pageY: NaN,
1059
+ elementX: NaN,
1060
+ elementY: NaN,
1061
+ elementH: NaN,
1062
+ elementW: NaN,
1063
+ elementPosX: NaN,
1064
+ elementPosY: NaN
1065
+ };
1066
+ function useMouse(target) {
1067
+ const [state, setState] = useRafState(initState);
1068
+ useEventListener(
1069
+ "mousemove",
1070
+ (event) => {
1071
+ const { screenX, screenY, clientX, clientY, pageX, pageY } = event;
1072
+ const newState = {
1073
+ screenX,
1074
+ screenY,
1075
+ clientX,
1076
+ clientY,
1077
+ pageX,
1078
+ pageY,
1079
+ elementX: NaN,
1080
+ elementY: NaN,
1081
+ elementH: NaN,
1082
+ elementW: NaN,
1083
+ elementPosX: NaN,
1084
+ elementPosY: NaN
1085
+ };
1086
+ const targetElement = getTargetElement(target);
1087
+ if (targetElement) {
1088
+ const { left, top, width, height } = targetElement.getBoundingClientRect();
1089
+ newState.elementPosX = left + window.pageXOffset;
1090
+ newState.elementPosY = top + window.pageYOffset;
1091
+ newState.elementX = pageX - newState.elementPosX;
1092
+ newState.elementY = pageY - newState.elementPosY;
1093
+ newState.elementW = width;
1094
+ newState.elementH = height;
1095
+ }
1096
+ setState(newState);
1097
+ },
1098
+ () => document
1099
+ );
1100
+ return state;
1101
+ }
1102
+
1103
+ function useFps(options) {
1104
+ var _a;
1105
+ const [fps, setFps] = react.useState(0);
1106
+ const every = (_a = options == null ? void 0 : options.every) != null ? _a : 10;
1107
+ const last = react.useRef(performance.now());
1108
+ const ticks = react.useRef(0);
1109
+ useRafFn(() => {
1110
+ ticks.current += 1;
1111
+ if (ticks.current >= every) {
1112
+ const now = performance.now();
1113
+ const diff = now - last.current;
1114
+ setFps(Math.round(1e3 / (diff / ticks.current)));
1115
+ last.current = now;
1116
+ ticks.current = 0;
1117
+ }
1118
+ });
1119
+ return fps;
1120
+ }
1121
+ const useFpsMock = (options) => 0;
1122
+ var useFps$1 = typeof performance === "undefined" ? useFpsMock : useFps;
1123
+
1124
+ const initCoord = {
1125
+ accuracy: 0,
1126
+ latitude: Infinity,
1127
+ longitude: Infinity,
1128
+ altitude: null,
1129
+ altitudeAccuracy: null,
1130
+ heading: null,
1131
+ speed: null
1132
+ };
1133
+ function useGeolocation(options = {}) {
1134
+ const {
1135
+ enableHighAccuracy = true,
1136
+ maximumAge = 3e4,
1137
+ timeout = 27e3
1138
+ } = options;
1139
+ const [coordinates, setCoordinates] = react.useState(initCoord);
1140
+ const [locatedAt, setLocatedAt] = react.useState(null);
1141
+ const [error, setError] = react.useState(null);
1142
+ const updatePosition = react.useCallback((position) => {
1143
+ setCoordinates(position.coords);
1144
+ setLocatedAt(position.timestamp);
1145
+ setError(null);
1146
+ }, []);
1147
+ const updateError = react.useCallback((err) => {
1148
+ setCoordinates(initCoord);
1149
+ setLocatedAt(null);
1150
+ setError(err);
1151
+ }, []);
1152
+ react.useEffect(() => {
1153
+ navigator.geolocation.getCurrentPosition(updatePosition, updateError);
1154
+ const watchId = navigator.geolocation.watchPosition(
1155
+ updatePosition,
1156
+ updateError,
1157
+ {
1158
+ enableHighAccuracy,
1159
+ maximumAge,
1160
+ timeout
1161
+ }
1162
+ );
1163
+ return () => {
1164
+ if (watchId) {
1165
+ navigator.geolocation.clearWatch(watchId);
1166
+ }
1167
+ };
1168
+ }, [enableHighAccuracy, maximumAge, timeout, updateError, updatePosition]);
1169
+ return {
1170
+ coordinates,
1171
+ locatedAt,
1172
+ error
1173
+ };
1174
+ }
1175
+
1176
+ var screenfull$1 = {exports: {}};
1177
+
1178
+ /*!
1179
+ * screenfull
1180
+ * v5.2.0 - 2021-11-03
1181
+ * (c) Sindre Sorhus; MIT License
1182
+ */
1183
+
1184
+ (function (module) {
1185
+ (function () {
1186
+
1187
+ var document = typeof window !== 'undefined' && typeof window.document !== 'undefined' ? window.document : {};
1188
+ var isCommonjs = module.exports;
1189
+
1190
+ var fn = (function () {
1191
+ var val;
1192
+
1193
+ var fnMap = [
1194
+ [
1195
+ 'requestFullscreen',
1196
+ 'exitFullscreen',
1197
+ 'fullscreenElement',
1198
+ 'fullscreenEnabled',
1199
+ 'fullscreenchange',
1200
+ 'fullscreenerror'
1201
+ ],
1202
+ // New WebKit
1203
+ [
1204
+ 'webkitRequestFullscreen',
1205
+ 'webkitExitFullscreen',
1206
+ 'webkitFullscreenElement',
1207
+ 'webkitFullscreenEnabled',
1208
+ 'webkitfullscreenchange',
1209
+ 'webkitfullscreenerror'
1210
+
1211
+ ],
1212
+ // Old WebKit
1213
+ [
1214
+ 'webkitRequestFullScreen',
1215
+ 'webkitCancelFullScreen',
1216
+ 'webkitCurrentFullScreenElement',
1217
+ 'webkitCancelFullScreen',
1218
+ 'webkitfullscreenchange',
1219
+ 'webkitfullscreenerror'
1220
+
1221
+ ],
1222
+ [
1223
+ 'mozRequestFullScreen',
1224
+ 'mozCancelFullScreen',
1225
+ 'mozFullScreenElement',
1226
+ 'mozFullScreenEnabled',
1227
+ 'mozfullscreenchange',
1228
+ 'mozfullscreenerror'
1229
+ ],
1230
+ [
1231
+ 'msRequestFullscreen',
1232
+ 'msExitFullscreen',
1233
+ 'msFullscreenElement',
1234
+ 'msFullscreenEnabled',
1235
+ 'MSFullscreenChange',
1236
+ 'MSFullscreenError'
1237
+ ]
1238
+ ];
1239
+
1240
+ var i = 0;
1241
+ var l = fnMap.length;
1242
+ var ret = {};
1243
+
1244
+ for (; i < l; i++) {
1245
+ val = fnMap[i];
1246
+ if (val && val[1] in document) {
1247
+ for (i = 0; i < val.length; i++) {
1248
+ ret[fnMap[0][i]] = val[i];
1249
+ }
1250
+ return ret;
1251
+ }
1252
+ }
1253
+
1254
+ return false;
1255
+ })();
1256
+
1257
+ var eventNameMap = {
1258
+ change: fn.fullscreenchange,
1259
+ error: fn.fullscreenerror
1260
+ };
1261
+
1262
+ var screenfull = {
1263
+ request: function (element, options) {
1264
+ return new Promise(function (resolve, reject) {
1265
+ var onFullScreenEntered = function () {
1266
+ this.off('change', onFullScreenEntered);
1267
+ resolve();
1268
+ }.bind(this);
1269
+
1270
+ this.on('change', onFullScreenEntered);
1271
+
1272
+ element = element || document.documentElement;
1273
+
1274
+ var returnPromise = element[fn.requestFullscreen](options);
1275
+
1276
+ if (returnPromise instanceof Promise) {
1277
+ returnPromise.then(onFullScreenEntered).catch(reject);
1278
+ }
1279
+ }.bind(this));
1280
+ },
1281
+ exit: function () {
1282
+ return new Promise(function (resolve, reject) {
1283
+ if (!this.isFullscreen) {
1284
+ resolve();
1285
+ return;
1286
+ }
1287
+
1288
+ var onFullScreenExit = function () {
1289
+ this.off('change', onFullScreenExit);
1290
+ resolve();
1291
+ }.bind(this);
1292
+
1293
+ this.on('change', onFullScreenExit);
1294
+
1295
+ var returnPromise = document[fn.exitFullscreen]();
1296
+
1297
+ if (returnPromise instanceof Promise) {
1298
+ returnPromise.then(onFullScreenExit).catch(reject);
1299
+ }
1300
+ }.bind(this));
1301
+ },
1302
+ toggle: function (element, options) {
1303
+ return this.isFullscreen ? this.exit() : this.request(element, options);
1304
+ },
1305
+ onchange: function (callback) {
1306
+ this.on('change', callback);
1307
+ },
1308
+ onerror: function (callback) {
1309
+ this.on('error', callback);
1310
+ },
1311
+ on: function (event, callback) {
1312
+ var eventName = eventNameMap[event];
1313
+ if (eventName) {
1314
+ document.addEventListener(eventName, callback, false);
1315
+ }
1316
+ },
1317
+ off: function (event, callback) {
1318
+ var eventName = eventNameMap[event];
1319
+ if (eventName) {
1320
+ document.removeEventListener(eventName, callback, false);
1321
+ }
1322
+ },
1323
+ raw: fn
1324
+ };
1325
+
1326
+ if (!fn) {
1327
+ if (isCommonjs) {
1328
+ module.exports = {isEnabled: false};
1329
+ } else {
1330
+ window.screenfull = {isEnabled: false};
1331
+ }
1332
+
1333
+ return;
1334
+ }
1335
+
1336
+ Object.defineProperties(screenfull, {
1337
+ isFullscreen: {
1338
+ get: function () {
1339
+ return Boolean(document[fn.fullscreenElement]);
1340
+ }
1341
+ },
1342
+ element: {
1343
+ enumerable: true,
1344
+ get: function () {
1345
+ return document[fn.fullscreenElement];
1346
+ }
1347
+ },
1348
+ isEnabled: {
1349
+ enumerable: true,
1350
+ get: function () {
1351
+ // Coerce to boolean in case of old WebKit
1352
+ return Boolean(document[fn.fullscreenEnabled]);
1353
+ }
1354
+ }
1355
+ });
1356
+
1357
+ if (isCommonjs) {
1358
+ module.exports = screenfull;
1359
+ } else {
1360
+ window.screenfull = screenfull;
1361
+ }
1362
+ })();
1363
+ } (screenfull$1));
1364
+
1365
+ var screenfull = screenfull$1.exports;
1366
+
1367
+ function useFullscreen(target, options) {
1368
+ const { onExit, onEnter } = options || {};
1369
+ const onExitRef = useLatest(onExit);
1370
+ const onEnterRef = useLatest(onEnter);
1371
+ const [state, setState] = react.useState(false);
1372
+ const onChange = () => {
1373
+ var _a, _b;
1374
+ if (screenfull.isEnabled) {
1375
+ const { isFullscreen } = screenfull;
1376
+ if (isFullscreen) {
1377
+ (_a = onEnterRef.current) == null ? void 0 : _a.call(onEnterRef);
1378
+ } else {
1379
+ screenfull.off("change", onChange);
1380
+ (_b = onExitRef.current) == null ? void 0 : _b.call(onExitRef);
1381
+ }
1382
+ setState(isFullscreen);
1383
+ }
1384
+ };
1385
+ const enterFullscreen = () => {
1386
+ const el = getTargetElement(target);
1387
+ if (!el) {
1388
+ return;
1389
+ }
1390
+ if (screenfull.isEnabled) {
1391
+ try {
1392
+ screenfull.request(el);
1393
+ screenfull.on("change", onChange);
1394
+ } catch (error) {
1395
+ console.error(error);
1396
+ }
1397
+ }
1398
+ };
1399
+ const exitFullscreen = () => {
1400
+ if (screenfull.isEnabled) {
1401
+ screenfull.exit();
1402
+ }
1403
+ };
1404
+ const toggleFullscreen = () => {
1405
+ if (state) {
1406
+ exitFullscreen();
1407
+ } else {
1408
+ enterFullscreen();
1409
+ }
1410
+ };
1411
+ useUnmount(() => {
1412
+ if (screenfull.isEnabled) {
1413
+ screenfull.off("change", onChange);
1414
+ }
1415
+ });
1416
+ return [
1417
+ state,
1418
+ {
1419
+ enterFullscreen: useEvent(enterFullscreen),
1420
+ exitFullscreen: useEvent(exitFullscreen),
1421
+ toggleFullscreen: useEvent(toggleFullscreen),
1422
+ isEnabled: screenfull.isEnabled
1423
+ }
1424
+ ];
1425
+ }
1426
+
1427
+ const nav = isNavigator ? navigator : void 0;
1428
+ const conn = nav && (nav.connection || nav.mozConnection || nav.webkitConnection);
1429
+ function getConnectionState(previousState) {
1430
+ const online = nav == null ? void 0 : nav.onLine;
1431
+ const previousOnline = previousState == null ? void 0 : previousState.online;
1432
+ return {
1433
+ online,
1434
+ previous: previousOnline,
1435
+ since: online !== previousOnline ? new Date() : previousState == null ? void 0 : previousState.since,
1436
+ downlink: conn == null ? void 0 : conn.downlink,
1437
+ downlinkMax: conn == null ? void 0 : conn.downlinkMax,
1438
+ effectiveType: conn == null ? void 0 : conn.effectiveType,
1439
+ rtt: conn == null ? void 0 : conn.rtt,
1440
+ saveData: conn == null ? void 0 : conn.saveData,
1441
+ type: conn == null ? void 0 : conn.type
1442
+ };
1443
+ }
1444
+ function useNetwork() {
1445
+ const [state, setState] = react.useState(getConnectionState);
1446
+ react.useEffect(() => {
1447
+ const handleStateChange = () => {
1448
+ setState(getConnectionState);
1449
+ };
1450
+ on(window, "online", handleStateChange, { passive: true });
1451
+ on(window, "offline", handleStateChange, { passive: true });
1452
+ if (conn) {
1453
+ on(conn, "change", handleStateChange, { passive: true });
1454
+ }
1455
+ return () => {
1456
+ off(window, "online", handleStateChange);
1457
+ off(window, "offline", handleStateChange);
1458
+ if (conn) {
1459
+ off(conn, "change", handleStateChange);
1460
+ }
1461
+ };
1462
+ }, []);
1463
+ return state;
1464
+ }
1465
+
1466
+ function useOnline() {
1467
+ const { online } = useNetwork();
1468
+ return online;
1469
+ }
1470
+
1471
+ const defaultState = {
1472
+ angle: 0,
1473
+ type: "landscape-primary"
1474
+ };
1475
+ function useOrientation(initialState = defaultState) {
1476
+ const [state, setState] = react.useState(initialState);
1477
+ react.useEffect(() => {
1478
+ const screen = window.screen;
1479
+ let mounted = true;
1480
+ const onChange = () => {
1481
+ if (mounted) {
1482
+ const { orientation } = screen;
1483
+ if (orientation) {
1484
+ const { angle, type } = orientation;
1485
+ setState({ angle, type });
1486
+ } else if (window.orientation !== void 0) {
1487
+ setState({
1488
+ angle: typeof window.orientation === "number" ? window.orientation : 0,
1489
+ type: ""
1490
+ });
1491
+ }
1492
+ }
1493
+ };
1494
+ on(window, "orientationchange", onChange);
1495
+ onChange();
1496
+ return () => {
1497
+ mounted = false;
1498
+ off(window, "orientationchange", onChange);
1499
+ };
1500
+ }, []);
1501
+ const lockOrientation = (type) => {
1502
+ if (isBrowser) {
1503
+ return;
1504
+ }
1505
+ if (!(window && "screen" in window && "orientation" in window.screen)) {
1506
+ return Promise.reject(new Error("Not supported"));
1507
+ }
1508
+ return window.screen.orientation.lock(type);
1509
+ };
1510
+ const unlockOrientation = () => {
1511
+ if (isBrowser) {
1512
+ return;
1513
+ }
1514
+ if (!(window && "screen" in window && "orientation" in window.screen)) {
1515
+ return;
1516
+ }
1517
+ return window.screen.orientation.unlock();
1518
+ };
1519
+ return [state, lockOrientation, unlockOrientation];
1520
+ }
1521
+
1522
+ function useIntersectionObserver(target, callback, options = {}) {
1523
+ const savedCallback = useLatest(callback);
1524
+ const observerRef = react.useRef();
1525
+ const stop = react.useCallback(() => {
1526
+ if (observerRef.current) {
1527
+ observerRef.current.disconnect();
1528
+ }
1529
+ }, []);
1530
+ useDeepCompareEffect(() => {
1531
+ const element = getTargetElement(target);
1532
+ if (!element) {
1533
+ return;
1534
+ }
1535
+ observerRef.current = new IntersectionObserver(
1536
+ savedCallback.current,
1537
+ options
1538
+ );
1539
+ observerRef.current.observe(element);
1540
+ return stop;
1541
+ }, [options]);
1542
+ return stop;
1543
+ }
1544
+
1545
+ function usePageLeave() {
1546
+ const [isLeft, setIsLeft] = react.useState(false);
1547
+ const handler = (event) => {
1548
+ if (!window)
1549
+ return;
1550
+ event = event || window.event;
1551
+ const from = event.relatedTarget || event.toElement;
1552
+ setIsLeft(!from);
1553
+ };
1554
+ useEventListener("mouseout", handler, window, { passive: true });
1555
+ useEventListener("mouseleave", handler, document, { passive: true });
1556
+ useEventListener("mouseenter", handler, document, { passive: true });
1557
+ return isLeft;
1558
+ }
1559
+
1560
+ function useDocumentVisibility() {
1561
+ const [visible, setVisible] = react.useState(() => {
1562
+ if (!document) {
1563
+ return "visible";
1564
+ } else {
1565
+ return document.visibilityState;
1566
+ }
1567
+ });
1568
+ useEventListener(
1569
+ "visibilitychange",
1570
+ () => {
1571
+ setVisible(document.visibilityState);
1572
+ },
1573
+ document
1574
+ );
1575
+ return visible;
1576
+ }
1577
+
1578
+ function useResizeObserver(target, callback, options = {}) {
1579
+ const savedCallback = useLatest(callback);
1580
+ const observerRef = react.useRef();
1581
+ const stop = react.useCallback(() => {
1582
+ if (observerRef.current) {
1583
+ observerRef.current.disconnect();
1584
+ }
1585
+ }, []);
1586
+ useDeepCompareEffect(() => {
1587
+ const element = getTargetElement(target);
1588
+ if (!element) {
1589
+ return;
1590
+ }
1591
+ observerRef.current = new ResizeObserver(savedCallback.current);
1592
+ observerRef.current.observe(element, options);
1593
+ return stop;
1594
+ }, [options]);
1595
+ return stop;
1596
+ }
1597
+
1598
+ function useDropZone(target, onDrop) {
1599
+ const [over, setOver] = react.useState(false);
1600
+ const counter = react.useRef(0);
1601
+ const element = getTargetElement(target);
1602
+ useEventListener(
1603
+ "dragenter",
1604
+ (event) => {
1605
+ event.preventDefault();
1606
+ counter.current += 1;
1607
+ setOver(true);
1608
+ },
1609
+ element
1610
+ );
1611
+ useEventListener(
1612
+ "dragover",
1613
+ (event) => {
1614
+ event.preventDefault();
1615
+ },
1616
+ element
1617
+ );
1618
+ useEventListener(
1619
+ "dragleave",
1620
+ (event) => {
1621
+ event.preventDefault();
1622
+ counter.current -= 1;
1623
+ if (counter.current === 0) {
1624
+ setOver(false);
1625
+ }
1626
+ },
1627
+ element
1628
+ );
1629
+ useEventListener(
1630
+ "drop",
1631
+ (event) => {
1632
+ var _a, _b;
1633
+ event.preventDefault();
1634
+ counter.current = 0;
1635
+ setOver(false);
1636
+ const files = Array.from((_b = (_a = event.dataTransfer) == null ? void 0 : _a.files) != null ? _b : []);
1637
+ onDrop == null ? void 0 : onDrop(files.length === 0 ? null : files);
1638
+ },
1639
+ element
1640
+ );
1641
+ return over;
1642
+ }
1643
+
1644
+ var __defProp$1 = Object.defineProperty;
1645
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
1646
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
1647
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
1648
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1649
+ var __spreadValues$1 = (a, b) => {
1650
+ for (var prop in b || (b = {}))
1651
+ if (__hasOwnProp$1.call(b, prop))
1652
+ __defNormalProp$1(a, prop, b[prop]);
1653
+ if (__getOwnPropSymbols$1)
1654
+ for (var prop of __getOwnPropSymbols$1(b)) {
1655
+ if (__propIsEnum$1.call(b, prop))
1656
+ __defNormalProp$1(a, prop, b[prop]);
1657
+ }
1658
+ return a;
1659
+ };
1660
+ const DEFAULT_OPTIONS = {
1661
+ multiple: true,
1662
+ accept: "*"
1663
+ };
1664
+ function useFileDialog(options = {}) {
1665
+ const [files, setFiles] = react.useState(null);
1666
+ const inputRef = react.useRef();
1667
+ const initFn = react.useCallback(() => {
1668
+ if (!document) {
1669
+ return void 0;
1670
+ }
1671
+ const input = document.createElement("input");
1672
+ input.type = "file";
1673
+ input.onchange = (event) => {
1674
+ const result = event.target;
1675
+ setFiles(result.files);
1676
+ };
1677
+ return input;
1678
+ }, []);
1679
+ inputRef.current = initFn();
1680
+ const open = (localOptions) => {
1681
+ if (!inputRef.current) {
1682
+ return;
1683
+ }
1684
+ const _options = __spreadValues$1(__spreadValues$1(__spreadValues$1({}, DEFAULT_OPTIONS), options), localOptions);
1685
+ inputRef.current.multiple = _options.multiple;
1686
+ inputRef.current.accept = _options.accept;
1687
+ inputRef.current.capture = _options.capture;
1688
+ inputRef.current.click();
1689
+ };
1690
+ const reset = () => {
1691
+ setFiles(null);
1692
+ if (inputRef.current) {
1693
+ inputRef.current.value = "";
1694
+ }
1695
+ };
1696
+ return [files, open, reset];
1697
+ }
1698
+
1699
+ const ARRIVED_STATE_THRESHOLD_PIXELS = 1;
1700
+ function useScroll(target, options = {}) {
1701
+ const {
1702
+ throttle = 0,
1703
+ idle = 200,
1704
+ onStop = noop,
1705
+ onScroll = noop,
1706
+ offset = {
1707
+ left: 0,
1708
+ right: 0,
1709
+ top: 0,
1710
+ bottom: 0
1711
+ },
1712
+ eventListenerOptions = {
1713
+ capture: false,
1714
+ passive: true
1715
+ }
1716
+ } = options;
1717
+ const [x, setX] = react.useState(0);
1718
+ const [y, setY] = react.useState(0);
1719
+ const [isScrolling, setIsScrolling] = react.useState(false);
1720
+ const [arrivedState, setArrivedState] = react.useState({
1721
+ left: true,
1722
+ right: false,
1723
+ top: true,
1724
+ bottom: false
1725
+ });
1726
+ const [directions, setDirections] = react.useState({
1727
+ left: false,
1728
+ right: false,
1729
+ top: false,
1730
+ bottom: false
1731
+ });
1732
+ const { run: onScrollEnd } = useDebounceFn((e) => {
1733
+ setIsScrolling(false);
1734
+ setDirections({ left: false, right: false, top: false, bottom: false });
1735
+ onStop(e);
1736
+ }, throttle + idle);
1737
+ const onScrollHandler = useEvent((e) => {
1738
+ const eventTarget = e.target === document ? e.target.documentElement : e.target;
1739
+ const scrollLeft = eventTarget.scrollLeft;
1740
+ let scrollTop = eventTarget.scrollTop;
1741
+ if (e.target === document && !scrollTop)
1742
+ scrollTop = document.body.scrollTop;
1743
+ setX(scrollLeft);
1744
+ setY(scrollTop);
1745
+ setDirections({
1746
+ left: scrollLeft < x,
1747
+ right: scrollLeft > x,
1748
+ top: scrollTop < y,
1749
+ bottom: scrollTop > y
1750
+ });
1751
+ setArrivedState({
1752
+ left: scrollLeft <= 0 + (offset.left || 0),
1753
+ right: scrollLeft + eventTarget.clientWidth >= eventTarget.scrollWidth - (offset.right || 0) - ARRIVED_STATE_THRESHOLD_PIXELS,
1754
+ top: scrollTop <= 0 + (offset.top || 0),
1755
+ bottom: scrollTop + eventTarget.clientHeight >= eventTarget.scrollHeight - (offset.bottom || 0) - ARRIVED_STATE_THRESHOLD_PIXELS
1756
+ });
1757
+ setIsScrolling(true);
1758
+ onScrollEnd(e);
1759
+ onScroll(e);
1760
+ });
1761
+ const { run: throttleOnScroll } = useThrottleFn(onScrollHandler, throttle);
1762
+ useEventListener(
1763
+ "scroll",
1764
+ throttle ? throttleOnScroll : onScrollHandler,
1765
+ target,
1766
+ eventListenerOptions
1767
+ );
1768
+ return [x, y, isScrolling, arrivedState, directions];
1769
+ }
1770
+
1771
+ var __defProp = Object.defineProperty;
1772
+ var __defProps = Object.defineProperties;
1773
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
1774
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
1775
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
1776
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
1777
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1778
+ var __spreadValues = (a, b) => {
1779
+ for (var prop in b || (b = {}))
1780
+ if (__hasOwnProp.call(b, prop))
1781
+ __defNormalProp(a, prop, b[prop]);
1782
+ if (__getOwnPropSymbols)
1783
+ for (var prop of __getOwnPropSymbols(b)) {
1784
+ if (__propIsEnum.call(b, prop))
1785
+ __defNormalProp(a, prop, b[prop]);
1786
+ }
1787
+ return a;
1788
+ };
1789
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1790
+ var __async = (__this, __arguments, generator) => {
1791
+ return new Promise((resolve, reject) => {
1792
+ var fulfilled = (value) => {
1793
+ try {
1794
+ step(generator.next(value));
1795
+ } catch (e) {
1796
+ reject(e);
1797
+ }
1798
+ };
1799
+ var rejected = (value) => {
1800
+ try {
1801
+ step(generator.throw(value));
1802
+ } catch (e) {
1803
+ reject(e);
1804
+ }
1805
+ };
1806
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
1807
+ step((generator = generator.apply(__this, __arguments)).next());
1808
+ });
1809
+ };
1810
+ function useInfiniteScroll(target, onLoadMore, options = {}) {
1811
+ var _a, _b;
1812
+ const savedLoadMore = useLatest(onLoadMore);
1813
+ const direction = (_a = options.direction) != null ? _a : "bottom";
1814
+ const state = useScroll(target, __spreadProps(__spreadValues({}, options), {
1815
+ offset: __spreadValues({
1816
+ [direction]: (_b = options.distance) != null ? _b : 0
1817
+ }, options.offset)
1818
+ }));
1819
+ const di = state[3][direction];
1820
+ useUpdateEffect(() => {
1821
+ const fn = () => __async(this, null, function* () {
1822
+ var _a2, _b2;
1823
+ const element = getTargetElement(target);
1824
+ const previous = {
1825
+ height: (_a2 = element == null ? void 0 : element.scrollHeight) != null ? _a2 : 0,
1826
+ width: (_b2 = element == null ? void 0 : element.scrollWidth) != null ? _b2 : 0
1827
+ };
1828
+ yield savedLoadMore.current(state);
1829
+ if (options.preserveScrollPosition && element) {
1830
+ element.scrollTo({
1831
+ top: element.scrollHeight - previous.height,
1832
+ left: element.scrollWidth - previous.width
1833
+ });
1834
+ }
1835
+ });
1836
+ fn();
1837
+ }, [di, options.preserveScrollPosition]);
1838
+ }
1839
+
1840
+ const defaultEvents = [
1841
+ "mousedown",
1842
+ "mouseup",
1843
+ "keydown",
1844
+ "keyup"
1845
+ ];
1846
+ function useKeyModifier(modifier, options = {}) {
1847
+ const { events = defaultEvents, initial = false } = options;
1848
+ const [state, setState] = react.useState(initial);
1849
+ useMount(() => {
1850
+ events.forEach((listenEvent) => {
1851
+ on(document, listenEvent, (evt) => {
1852
+ if (typeof evt.getModifierState === "function") {
1853
+ setState(evt.getModifierState(modifier));
1854
+ }
1855
+ });
1856
+ });
1857
+ return () => {
1858
+ events.forEach((listenerEvent) => {
1859
+ off(document, listenerEvent, (evt) => {
1860
+ if (typeof evt.getModifierState === "function") {
1861
+ setState(evt.getModifierState(modifier));
1862
+ }
1863
+ });
1864
+ });
1865
+ };
1866
+ });
1867
+ return state;
1868
+ }
1869
+
1870
+ function useMousePressed(target, options = {}) {
1871
+ const { touch = true, drag = true, initialValue = false } = options;
1872
+ const [pressed, setPressed] = react.useState(initialValue);
1873
+ const [sourceType, setSourceType] = react.useState(null);
1874
+ const onPressed = react.useCallback(
1875
+ (srcType) => () => {
1876
+ setPressed(true);
1877
+ setSourceType(srcType);
1878
+ },
1879
+ []
1880
+ );
1881
+ const onReleased = react.useCallback(() => {
1882
+ setPressed(false);
1883
+ setSourceType(null);
1884
+ }, []);
1885
+ useEventListener("mousedown", onPressed("mouse"), target, { passive: true });
1886
+ useEventListener("mouseleave", onReleased, window, { passive: true });
1887
+ useEventListener("mouseup", onReleased, window, { passive: true });
1888
+ useMount(() => {
1889
+ const element = getTargetElement(target);
1890
+ if (drag) {
1891
+ element == null ? void 0 : element.addEventListener("dragstart", onPressed("mouse"), {
1892
+ passive: true
1893
+ });
1894
+ element == null ? void 0 : element.addEventListener("drop", onReleased, {
1895
+ passive: true
1896
+ });
1897
+ element == null ? void 0 : element.addEventListener("dragend", onReleased, {
1898
+ passive: true
1899
+ });
1900
+ }
1901
+ if (touch) {
1902
+ element == null ? void 0 : element.addEventListener("touchstart", onPressed("touch"), {
1903
+ passive: true
1904
+ });
1905
+ element == null ? void 0 : element.addEventListener("touchend", onReleased, {
1906
+ passive: true
1907
+ });
1908
+ element == null ? void 0 : element.addEventListener("touchcancel", onReleased, {
1909
+ passive: true
1910
+ });
1911
+ }
1912
+ return () => {
1913
+ if (drag) {
1914
+ element == null ? void 0 : element.removeEventListener("dragstart", onPressed("mouse"));
1915
+ element == null ? void 0 : element.removeEventListener("drop", onReleased);
1916
+ element == null ? void 0 : element.removeEventListener("dragend", onReleased);
1917
+ }
1918
+ if (touch) {
1919
+ element == null ? void 0 : element.removeEventListener("touchstart", onPressed("touch"));
1920
+ element == null ? void 0 : element.removeEventListener("touchend", onReleased);
1921
+ element == null ? void 0 : element.removeEventListener("touchcancel", onReleased);
1922
+ }
1923
+ };
1924
+ });
1925
+ return [pressed, sourceType];
1926
+ }
1927
+
1928
+ function preventDefault(rawEvent) {
1929
+ const e = rawEvent || window.event;
1930
+ if (e.touches.length > 1) {
1931
+ return true;
1932
+ }
1933
+ if (e.preventDefault) {
1934
+ e.preventDefault();
1935
+ }
1936
+ return false;
1937
+ }
1938
+ function useScrollLock(target, initialState = false) {
1939
+ const [locked, setLocked] = react.useState(initialState);
1940
+ const initialOverflowRef = react.useRef("scroll");
1941
+ useMount(() => {
1942
+ const element = getTargetElement(target);
1943
+ if (element) {
1944
+ initialOverflowRef.current = element.style.overflow;
1945
+ if (locked) {
1946
+ element.style.overflow = "hidden";
1947
+ }
1948
+ }
1949
+ });
1950
+ const lock = useEvent(() => {
1951
+ const element = getTargetElement(target);
1952
+ if (!element || locked) {
1953
+ return;
1954
+ }
1955
+ if (isIOS) {
1956
+ element.addEventListener("touchmove", preventDefault, { passive: false });
1957
+ }
1958
+ element.style.overflow = "hidden";
1959
+ setLocked(true);
1960
+ });
1961
+ const unlock = useEvent(() => {
1962
+ const element = getTargetElement(target);
1963
+ if (!element || !locked) {
1964
+ return;
1965
+ }
1966
+ if (isIOS) {
1967
+ element.removeEventListener("touchmove", preventDefault);
1968
+ }
1969
+ element.style.overflow = initialOverflowRef.current;
1970
+ setLocked(false);
1971
+ });
1972
+ const set = useEvent((flag) => {
1973
+ if (flag) {
1974
+ lock();
1975
+ } else {
1976
+ unlock();
1977
+ }
1978
+ });
1979
+ return [locked, set];
1980
+ }
1981
+
1982
+ function useElementSize(target, options = {}) {
1983
+ const { box = "content-box" } = options;
1984
+ const [width, setWidth] = react.useState(0);
1985
+ const [height, setHeight] = react.useState(0);
1986
+ useResizeObserver(
1987
+ target,
1988
+ ([entry]) => {
1989
+ const boxSize = box === "border-box" ? entry.borderBoxSize : box === "content-box" ? entry.contentBoxSize : entry.devicePixelContentBoxSize;
1990
+ if (boxSize) {
1991
+ setWidth(boxSize.reduce((acc, { inlineSize }) => acc + inlineSize, 0));
1992
+ setHeight(boxSize.reduce((acc, { blockSize }) => acc + blockSize, 0));
1993
+ } else {
1994
+ setWidth(entry.contentRect.width);
1995
+ setHeight(entry.contentRect.height);
1996
+ }
1997
+ },
1998
+ options
1999
+ );
2000
+ return [width, height];
2001
+ }
2002
+
2003
+ function useVirtualList(list = [], options) {
2004
+ const containerRef = react.useRef(null);
2005
+ const [width, height] = useElementSize(containerRef);
2006
+ const [currentList, setCurrentList] = react.useState([]);
2007
+ const { itemHeight, overscan = 5, containerHeight = 300 } = options;
2008
+ const state = react.useRef({ start: 0, end: 10 });
2009
+ const getViewCapacity = react.useCallback(
2010
+ (containerHeight2) => {
2011
+ if (typeof itemHeight === "number") {
2012
+ return Math.ceil(containerHeight2 / itemHeight);
2013
+ }
2014
+ const { start = 0 } = state.current;
2015
+ let sum = 0;
2016
+ let capacity = 0;
2017
+ for (let i = start; i < list.length; i++) {
2018
+ const height2 = itemHeight(i);
2019
+ sum += height2;
2020
+ if (sum >= containerHeight2) {
2021
+ capacity = i;
2022
+ break;
2023
+ }
2024
+ }
2025
+ return capacity - start;
2026
+ },
2027
+ [itemHeight, list]
2028
+ );
2029
+ const getOffset = react.useCallback(
2030
+ (scrollTop) => {
2031
+ if (typeof itemHeight === "number")
2032
+ return Math.floor(scrollTop / itemHeight) + 1;
2033
+ let sum = 0;
2034
+ let offset = 0;
2035
+ for (let i = 0; i < list.length; i++) {
2036
+ const height2 = itemHeight(i);
2037
+ sum += height2;
2038
+ if (sum >= scrollTop) {
2039
+ offset = i;
2040
+ break;
2041
+ }
2042
+ }
2043
+ return offset + 1;
2044
+ },
2045
+ [itemHeight, list]
2046
+ );
2047
+ const calculateRange = useEvent(() => {
2048
+ const element = containerRef.current;
2049
+ if (element != null) {
2050
+ const offset = getOffset(element.scrollTop);
2051
+ const viewCapacity = getViewCapacity(element.clientHeight);
2052
+ const from = offset - overscan;
2053
+ const to = offset + viewCapacity + overscan;
2054
+ state.current = {
2055
+ start: from < 0 ? 0 : from,
2056
+ end: to > list.length ? list.length : to
2057
+ };
2058
+ setCurrentList(
2059
+ list.slice(state.current.start, state.current.end).map((ele, index) => ({
2060
+ data: ele,
2061
+ index: index + state.current.start
2062
+ }))
2063
+ );
2064
+ }
2065
+ });
2066
+ react.useEffect(() => {
2067
+ calculateRange();
2068
+ }, [width, height, list, calculateRange]);
2069
+ const totalHeight = react.useMemo(() => {
2070
+ if (typeof itemHeight === "number") {
2071
+ return list.length * itemHeight;
2072
+ }
2073
+ return list.reduce((sum, _, index) => sum + itemHeight(index), 0);
2074
+ }, [itemHeight, list]);
2075
+ const getDistanceTop = react.useCallback(
2076
+ (index) => {
2077
+ if (typeof itemHeight === "number") {
2078
+ const height3 = index * itemHeight;
2079
+ return height3;
2080
+ }
2081
+ const height2 = list.slice(0, index).reduce((sum, _, i) => sum + itemHeight(i), 0);
2082
+ return height2;
2083
+ },
2084
+ [itemHeight, list]
2085
+ );
2086
+ const scrollTo = useEvent((index) => {
2087
+ if (containerRef.current) {
2088
+ containerRef.current.scrollTop = getDistanceTop(index);
2089
+ calculateRange();
2090
+ }
2091
+ });
2092
+ const offsetTop = react.useMemo(
2093
+ () => getDistanceTop(state.current.start),
2094
+ [getDistanceTop]
2095
+ );
2096
+ const wrapperProps = react.useMemo(() => {
2097
+ return {
2098
+ style: {
2099
+ width: "100%",
2100
+ height: `${totalHeight - offsetTop}px`,
2101
+ marginTop: `${offsetTop}px`
2102
+ }
2103
+ };
2104
+ }, [offsetTop, totalHeight]);
2105
+ const containerStyle = react.useMemo(() => {
2106
+ return { overflowY: "auto", height: containerHeight };
2107
+ }, [containerHeight]);
2108
+ return {
2109
+ list: currentList,
2110
+ scrollTo,
2111
+ containerProps: {
2112
+ ref: containerRef,
2113
+ onScroll: () => {
2114
+ calculateRange();
2115
+ },
2116
+ style: containerStyle
2117
+ },
2118
+ wrapperProps
2119
+ };
2120
+ }
2121
+
2122
+ function usePreferredColorScheme(defaultState) {
2123
+ const isLight = useMediaQuery("(prefers-color-scheme: light)");
2124
+ const isDark = useMediaQuery("(prefers-color-scheme: dark)");
2125
+ if (!isBrowser && defaultState) {
2126
+ return defaultState;
2127
+ }
2128
+ return isDark ? "dark" : isLight ? "light" : "no-preference";
2129
+ }
2130
+
2131
+ function usePreferredContrast(defaultState) {
2132
+ const isMore = useMediaQuery("(prefers-contrast: more)");
2133
+ const isLess = useMediaQuery("(prefers-contrast: less)");
2134
+ const isCustom = useMediaQuery("(prefers-contrast: custom)");
2135
+ if (!isBrowser && defaultState) {
2136
+ return defaultState;
2137
+ }
2138
+ return isMore ? "more" : isLess ? "less" : isCustom ? "custom" : "no-preference";
2139
+ }
2140
+
2141
+ function useActiveElement() {
2142
+ const [active, setActive] = react.useState(null);
2143
+ const listener = react.useCallback(() => {
2144
+ setActive(window == null ? void 0 : window.document.activeElement);
2145
+ }, []);
2146
+ useEventListener("blur", listener, window, true);
2147
+ useEventListener("focus", listener, window, true);
2148
+ return active;
2149
+ }
2150
+
2151
+ exports.useActiveElement = useActiveElement;
2152
+ exports.useCounter = useCounter;
2153
+ exports.useCustomCompareEffect = useCustomCompareEffect;
2154
+ exports.useDarkMode = useDarkMode;
2155
+ exports.useDebounce = useDebounce;
2156
+ exports.useDebounceFn = useDebounceFn;
2157
+ exports.useDeepCompareEffect = useDeepCompareEffect;
2158
+ exports.useDocumentVisibility = useDocumentVisibility;
2159
+ exports.useDropZone = useDropZone;
2160
+ exports.useElementSize = useElementSize;
2161
+ exports.useEvent = useEvent;
2162
+ exports.useEventEmitter = useEventEmitter;
2163
+ exports.useEventListener = useEventListener;
2164
+ exports.useFavicon = useFavicon;
2165
+ exports.useFileDialog = useFileDialog;
2166
+ exports.useFirstMountState = useFirstMountState;
2167
+ exports.useFps = useFps$1;
2168
+ exports.useFullscreen = useFullscreen;
2169
+ exports.useGeolocation = useGeolocation;
2170
+ exports.useIdle = useIdle;
2171
+ exports.useInfiniteScroll = useInfiniteScroll;
2172
+ exports.useIntersectionObserver = useIntersectionObserver;
2173
+ exports.useInterval = useInterval;
2174
+ exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
2175
+ exports.useKeyModifier = useKeyModifier;
2176
+ exports.useLatest = useLatest;
2177
+ exports.useLocalStorage = useLocalStorage;
2178
+ exports.useLongPress = useLongPress;
2179
+ exports.useMarkdown = useMarkdown;
2180
+ exports.useMediaDevices = useMediaDevices$1;
2181
+ exports.useMediaQuery = useMediaQuery;
2182
+ exports.useMount = useMount;
2183
+ exports.useMountedState = useMountedState;
2184
+ exports.useMouse = useMouse;
2185
+ exports.useMousePressed = useMousePressed;
2186
+ exports.useMutationObserver = useMutationObserver;
2187
+ exports.useNetwork = useNetwork;
2188
+ exports.useObjectUrl = useObjectUrl;
2189
+ exports.useOnline = useOnline;
2190
+ exports.useOrientation = useOrientation;
2191
+ exports.usePageLeave = usePageLeave;
2192
+ exports.usePermission = usePermission;
2193
+ exports.usePreferredColorScheme = usePreferredColorScheme;
2194
+ exports.usePreferredContrast = usePreferredContrast;
2195
+ exports.usePreferredDark = usePreferredDark;
2196
+ exports.usePrevious = usePrevious;
2197
+ exports.useRafFn = useRafFn;
2198
+ exports.useRafState = useRafState;
2199
+ exports.useResizeObserver = useResizeObserver;
2200
+ exports.useScriptTag = useScriptTag;
2201
+ exports.useScroll = useScroll;
2202
+ exports.useScrollLock = useScrollLock;
2203
+ exports.useSessionStorage = useSessionStorage;
2204
+ exports.useTextDirection = useTextDirection;
2205
+ exports.useThrottle = useThrottle;
2206
+ exports.useThrottleFn = useThrottleFn;
2207
+ exports.useTimeout = useTimeout;
2208
+ exports.useTimeoutFn = useTimeoutFn;
2209
+ exports.useTitle = useTitle;
2210
+ exports.useToggle = useToggle;
2211
+ exports.useUnmount = useUnmount;
2212
+ exports.useUpdate = useUpdate;
2213
+ exports.useUpdateEffect = useUpdateEffect;
2214
+ exports.useUpdateLayoutEffect = useUpdateLayoutEffect;
2215
+ exports.useVirtualList = useVirtualList;