@ox0/hooks 0.2.1 → 0.2.2

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/dist/index.js CHANGED
@@ -1,8 +1,7 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
- import * as __WEBPACK_EXTERNAL_MODULE__react_aria_interactions_8422cce9__ from "@react-aria/interactions";
1
+ import { createContext, createElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
3
2
  function useBeforeUnloadWarning(enabled) {
4
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
5
- if (!enabled || "undefined" == typeof window) return;
3
+ useEffect(()=>{
4
+ if (!enabled || "u" < typeof window) return;
6
5
  const handle = (event)=>{
7
6
  event.preventDefault();
8
7
  event.returnValue = "";
@@ -16,7 +15,7 @@ function useBeforeUnloadWarning(enabled) {
16
15
  const MOBILE_MAX = 767;
17
16
  const TABLET_MAX = 1023;
18
17
  function getBreakpoint() {
19
- if ("undefined" == typeof window) return "desktop";
18
+ if ("u" < typeof window) return "desktop";
20
19
  if (window.matchMedia(`(max-width: ${MOBILE_MAX}px)`).matches) return "mobile";
21
20
  if (window.matchMedia(`(max-width: ${TABLET_MAX}px)`).matches) return "tablet";
22
21
  return "desktop";
@@ -32,9 +31,9 @@ function toState(breakpoint) {
32
31
  };
33
32
  }
34
33
  function useBreakpoint() {
35
- const [state, setState] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(()=>toState(getBreakpoint()));
36
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
37
- if ("undefined" == typeof window) return;
34
+ const [state, setState] = useState(()=>toState(getBreakpoint()));
35
+ useEffect(()=>{
36
+ if ("u" < typeof window) return;
38
37
  const mobileQuery = window.matchMedia(`(max-width: ${MOBILE_MAX}px)`);
39
38
  const tabletQuery = window.matchMedia(`(max-width: ${TABLET_MAX}px)`);
40
39
  const handleChange = ()=>{
@@ -54,12 +53,12 @@ function useBreakpoint() {
54
53
  return state;
55
54
  }
56
55
  function useContainerSize() {
57
- const ref = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
58
- const [size, setSize] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)({
56
+ const ref = useRef(null);
57
+ const [size, setSize] = useState({
59
58
  width: 0,
60
59
  height: 0
61
60
  });
62
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
61
+ useEffect(()=>{
63
62
  const el = ref.current;
64
63
  if (!el) return;
65
64
  const observer = new ResizeObserver((entries)=>{
@@ -84,10 +83,10 @@ function useContainerSize() {
84
83
  }
85
84
  function useControllableState(options) {
86
85
  const { defaultValue, onChange, value } = options;
87
- const [uncontrolledValue, setUncontrolledValue] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(defaultValue);
86
+ const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
88
87
  const isControlled = void 0 !== value;
89
88
  const currentValue = void 0 !== value ? value : uncontrolledValue;
90
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
89
+ useEffect(()=>{
91
90
  if (!isControlled) setUncontrolledValue(defaultValue);
92
91
  }, [
93
92
  defaultValue,
@@ -103,12 +102,12 @@ function useControllableState(options) {
103
102
  ];
104
103
  }
105
104
  function useCopyToClipboard(resetMs = 2000) {
106
- const [copied, setCopied] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
107
- const timerRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
108
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>()=>{
105
+ const [copied, setCopied] = useState(false);
106
+ const timerRef = useRef(null);
107
+ useEffect(()=>()=>{
109
108
  if (null !== timerRef.current) clearTimeout(timerRef.current);
110
109
  }, []);
111
- const copy = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(async (text)=>{
110
+ const copy = useCallback(async (text)=>{
112
111
  try {
113
112
  await navigator.clipboard.writeText(text);
114
113
  setCopied(true);
@@ -124,8 +123,8 @@ function useCopyToClipboard(resetMs = 2000) {
124
123
  };
125
124
  }
126
125
  function useDebouncedValue(value, delay = 200) {
127
- const [debouncedValue, setDebouncedValue] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(value);
128
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
126
+ const [debouncedValue, setDebouncedValue] = useState(value);
127
+ useEffect(()=>{
129
128
  const timeoutId = window.setTimeout(()=>{
130
129
  setDebouncedValue(value);
131
130
  }, delay);
@@ -139,21 +138,18 @@ function useDebouncedValue(value, delay = 200) {
139
138
  return debouncedValue;
140
139
  }
141
140
  function useDeferredPresence(isPresent, { delayMs, exitMs, minimumVisibleMs }) {
142
- const [state, setState] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)({
141
+ const [state, setState] = useState({
143
142
  phase: "hidden"
144
143
  });
145
- const timerRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(void 0);
146
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
144
+ const timerRef = useRef(void 0);
145
+ useEffect(()=>{
147
146
  clearTimeout(timerRef.current);
148
147
  if (isPresent) {
149
148
  if ("visible" === state.phase) return;
150
- if ("exiting" === state.phase) {
151
- setState({
152
- phase: "visible",
153
- shownAt: state.shownAt
154
- });
155
- return;
156
- }
149
+ if ("exiting" === state.phase) return void setState({
150
+ phase: "visible",
151
+ shownAt: state.shownAt
152
+ });
157
153
  timerRef.current = window.setTimeout(()=>{
158
154
  setState({
159
155
  phase: "visible",
@@ -183,14 +179,14 @@ function useDeferredPresence(isPresent, { delayMs, exitMs, minimumVisibleMs }) {
183
179
  return state.phase;
184
180
  }
185
181
  function useDisclosure(initialOpen = false) {
186
- const [isOpen, setIsOpen] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(initialOpen);
187
- const onClose = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
182
+ const [isOpen, setIsOpen] = useState(initialOpen);
183
+ const onClose = useCallback(()=>{
188
184
  setIsOpen(false);
189
185
  }, []);
190
- const onOpen = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
186
+ const onOpen = useCallback(()=>{
191
187
  setIsOpen(true);
192
188
  }, []);
193
- const onToggle = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
189
+ const onToggle = useCallback(()=>{
194
190
  setIsOpen((value)=>!value);
195
191
  }, []);
196
192
  return {
@@ -201,13 +197,13 @@ function useDisclosure(initialOpen = false) {
201
197
  };
202
198
  }
203
199
  function useEventListener(type, listener, target) {
204
- const listenerRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(listener);
205
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
200
+ const listenerRef = useRef(listener);
201
+ useEffect(()=>{
206
202
  listenerRef.current = listener;
207
203
  }, [
208
204
  listener
209
205
  ]);
210
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
206
+ useEffect(()=>{
211
207
  const el = void 0 === target ? window : target && "current" in target ? target.current : target;
212
208
  if (!el) return;
213
209
  const handler = (e)=>listenerRef.current(e);
@@ -219,9 +215,9 @@ function useEventListener(type, listener, target) {
219
215
  ]);
220
216
  }
221
217
  function useHover() {
222
- const ref = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
223
- const [hovered, setHovered] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
224
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
218
+ const ref = useRef(null);
219
+ const [hovered, setHovered] = useState(false);
220
+ useEffect(()=>{
225
221
  const el = ref.current;
226
222
  if (!el) return;
227
223
  const enter = ()=>setHovered(true);
@@ -239,13 +235,13 @@ function useHover() {
239
235
  ];
240
236
  }
241
237
  function useInterval(callback, delay) {
242
- const callbackRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(callback);
243
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
238
+ const callbackRef = useRef(callback);
239
+ useEffect(()=>{
244
240
  callbackRef.current = callback;
245
241
  }, [
246
242
  callback
247
243
  ]);
248
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
244
+ useEffect(()=>{
249
245
  if (null === delay) return;
250
246
  const id = window.setInterval(()=>callbackRef.current(), delay);
251
247
  return ()=>window.clearInterval(id);
@@ -254,13 +250,13 @@ function useInterval(callback, delay) {
254
250
  ]);
255
251
  }
256
252
  function useKeyDown(key, callback, { ctrl = false, meta = false, shift = false, alt = false, enabled = true } = {}) {
257
- const callbackRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(callback);
258
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
253
+ const callbackRef = useRef(callback);
254
+ useEffect(()=>{
259
255
  callbackRef.current = callback;
260
256
  }, [
261
257
  callback
262
258
  ]);
263
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
259
+ useEffect(()=>{
264
260
  if (!enabled) return;
265
261
  const handler = (e)=>{
266
262
  if (e.key !== key) return;
@@ -302,7 +298,7 @@ function tabNotify(key, value) {
302
298
  const crossTabSubscribers = new Map();
303
299
  let broadcastChannel = null;
304
300
  function getChannel() {
305
- if ("undefined" == typeof window || "undefined" == typeof BroadcastChannel) return null;
301
+ if ("u" < typeof window || "u" < typeof BroadcastChannel) return null;
306
302
  if (!broadcastChannel) {
307
303
  broadcastChannel = new BroadcastChannel("ox0:storage");
308
304
  broadcastChannel.addEventListener("message", (e)=>{
@@ -326,7 +322,7 @@ function crossTabSubscribe(key, fn) {
326
322
  };
327
323
  }
328
324
  function getTabId() {
329
- if ("undefined" == typeof sessionStorage) return instanceId;
325
+ if ("u" < typeof sessionStorage) return instanceId;
330
326
  const existing = sessionStorage.getItem("ox0:tab-id");
331
327
  if (existing) return existing;
332
328
  const next = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
@@ -334,7 +330,7 @@ function getTabId() {
334
330
  return next;
335
331
  }
336
332
  function getStorage(kind) {
337
- if ("undefined" == typeof window) return null;
333
+ if ("u" < typeof window) return null;
338
334
  return "persistent" === kind ? window.localStorage : window.sessionStorage;
339
335
  }
340
336
  function makeStorageKey(key, kind, shared, scope) {
@@ -354,7 +350,7 @@ function readSafe(raw, parser, defaultValue, version, migrate) {
354
350
  migrated: false
355
351
  };
356
352
  if (parsed.v !== version) return migrate ? {
357
- value: migrate(parsed.value, parsed.v),
353
+ value: parser.parse(migrate(parsed.value, parsed.v)),
358
354
  migrated: true
359
355
  } : {
360
356
  value: defaultValue,
@@ -382,49 +378,49 @@ function writeStorage(storage, key, value, version) {
382
378
  } catch {}
383
379
  return raw;
384
380
  }
385
- const StorageScopeContext = (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)(void 0);
381
+ const StorageScopeContext = createContext(void 0);
386
382
  function StorageProvider({ scope, children }) {
387
- return (0, __WEBPACK_EXTERNAL_MODULE_react__.createElement)(StorageScopeContext.Provider, {
383
+ return createElement(StorageScopeContext.Provider, {
388
384
  value: scope
389
385
  }, children);
390
386
  }
391
387
  function useStorageScope() {
392
- const scope = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(StorageScopeContext);
388
+ const scope = useContext(StorageScopeContext);
393
389
  if (void 0 === scope) throw new Error("useStoredState: no StorageProvider found. Wrap your app with <StorageProvider scope={userId ?? null}>.");
394
390
  return scope;
395
391
  }
396
392
  function useStoredState(kind, key, parser, { defaultValue, version = 1, migrate }, shared) {
397
393
  const scope = useStorageScope();
398
394
  const storage = getStorage(kind);
399
- const storageKey = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>makeStorageKey(key, kind, shared, scope), [
395
+ const storageKey = useMemo(()=>makeStorageKey(key, kind, shared, scope), [
400
396
  key,
401
397
  kind,
402
398
  shared,
403
399
  scope
404
400
  ]);
405
- const parserRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(parser);
406
- const defaultValueRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(defaultValue);
407
- const versionRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(version);
408
- const migrateRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(migrate);
409
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
401
+ const parserRef = useRef(parser);
402
+ const defaultValueRef = useRef(defaultValue);
403
+ const versionRef = useRef(version);
404
+ const migrateRef = useRef(migrate);
405
+ useEffect(()=>{
410
406
  parserRef.current = parser;
411
407
  defaultValueRef.current = defaultValue;
412
408
  versionRef.current = version;
413
409
  migrateRef.current = migrate;
414
410
  });
415
- const [value, setValueState] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(()=>{
411
+ const [value, setValueState] = useState(()=>{
416
412
  const raw = storage?.getItem(storageKey) ?? null;
417
413
  const result = readSafe(raw, parser, defaultValue, version, migrate);
418
414
  if (result.migrated) writeStorage(storage, storageKey, result.value, version);
419
415
  return result.value;
420
416
  });
421
- const valueRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(value);
422
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
417
+ const valueRef = useRef(value);
418
+ useEffect(()=>{
423
419
  valueRef.current = value;
424
420
  }, [
425
421
  value
426
422
  ]);
427
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
423
+ useEffect(()=>{
428
424
  const raw = storage?.getItem(storageKey) ?? null;
429
425
  const result = readSafe(raw, parserRef.current, defaultValueRef.current, versionRef.current, migrateRef.current);
430
426
  setValueState((prev)=>Object.is(prev, result.value) ? prev : result.value);
@@ -433,12 +429,12 @@ function useStoredState(kind, key, parser, { defaultValue, version = 1, migrate
433
429
  storage,
434
430
  storageKey
435
431
  ]);
436
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>tabSubscribe(storageKey, (next)=>{
432
+ useEffect(()=>tabSubscribe(storageKey, (next)=>{
437
433
  setValueState((prev)=>Object.is(prev, next) ? prev : next);
438
434
  }), [
439
435
  storageKey
440
436
  ]);
441
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
437
+ useEffect(()=>{
442
438
  if (!shared) return;
443
439
  return crossTabSubscribe(storageKey, (msg)=>{
444
440
  if (msg.storage !== kind || msg.sourceId === instanceId) return;
@@ -453,8 +449,8 @@ function useStoredState(kind, key, parser, { defaultValue, version = 1, migrate
453
449
  storage,
454
450
  storageKey
455
451
  ]);
456
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
457
- if (!shared || "persistent" !== kind || "undefined" == typeof window) return;
452
+ useEffect(()=>{
453
+ if (!shared || "persistent" !== kind || "u" < typeof window) return;
458
454
  const handler = (event)=>{
459
455
  if (event.key !== storageKey) return;
460
456
  const result = readSafe(event.newValue, parserRef.current, defaultValueRef.current, versionRef.current, migrateRef.current);
@@ -470,7 +466,7 @@ function useStoredState(kind, key, parser, { defaultValue, version = 1, migrate
470
466
  storage,
471
467
  storageKey
472
468
  ]);
473
- const setValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((next)=>{
469
+ const setValue = useCallback((next)=>{
474
470
  const resolved = "function" == typeof next ? next(valueRef.current) : next;
475
471
  if (Object.is(valueRef.current, resolved)) return;
476
472
  valueRef.current = resolved;
@@ -507,10 +503,10 @@ function useSessionSharedState(key, parser, options) {
507
503
  return useStoredState("session", key, parser, options, true);
508
504
  }
509
505
  function useLongPress({ delayMs = 500, moveThresholdPx = 8, disabled = false, onLongPress }) {
510
- const timerRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
511
- const pointerIdRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
512
- const startRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
513
- const triggeredRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(false);
506
+ const timerRef = useRef(null);
507
+ const pointerIdRef = useRef(null);
508
+ const startRef = useRef(null);
509
+ const triggeredRef = useRef(false);
514
510
  const clearTimer = ()=>{
515
511
  if (null == timerRef.current) return;
516
512
  window.clearTimeout(timerRef.current);
@@ -521,7 +517,7 @@ function useLongPress({ delayMs = 500, moveThresholdPx = 8, disabled = false, on
521
517
  pointerIdRef.current = null;
522
518
  startRef.current = null;
523
519
  };
524
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
520
+ useEffect(()=>{
525
521
  if (disabled) {
526
522
  triggeredRef.current = false;
527
523
  reset();
@@ -529,7 +525,7 @@ function useLongPress({ delayMs = 500, moveThresholdPx = 8, disabled = false, on
529
525
  }, [
530
526
  disabled
531
527
  ]);
532
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>()=>clearTimer(), []);
528
+ useEffect(()=>()=>clearTimer(), []);
533
529
  return {
534
530
  onPointerDown (event) {
535
531
  if (disabled || 0 !== event.button) return;
@@ -571,10 +567,10 @@ function useLongPress({ delayMs = 500, moveThresholdPx = 8, disabled = false, on
571
567
  };
572
568
  }
573
569
  function useMediaQuery(query) {
574
- const getMatches = ()=>"undefined" != typeof window && window.matchMedia(query).matches;
575
- const [matches, setMatches] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(getMatches);
576
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
577
- if ("undefined" == typeof window) return;
570
+ const getMatches = ()=>"u" > typeof window && window.matchMedia(query).matches;
571
+ const [matches, setMatches] = useState(getMatches);
572
+ useEffect(()=>{
573
+ if ("u" < typeof window) return;
578
574
  const mediaQuery = window.matchMedia(query);
579
575
  const update = ()=>{
580
576
  setMatches(mediaQuery.matches);
@@ -590,9 +586,9 @@ function useMediaQuery(query) {
590
586
  return matches;
591
587
  }
592
588
  function useNavigatorOnline() {
593
- const [isOnline, setIsOnline] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(()=>"undefined" == typeof navigator ? true : navigator.onLine);
594
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
595
- if ("undefined" == typeof window) return;
589
+ const [isOnline, setIsOnline] = useState(()=>"u" < typeof navigator ? true : navigator.onLine);
590
+ useEffect(()=>{
591
+ if ("u" < typeof window) return;
596
592
  const sync = ()=>setIsOnline(navigator.onLine);
597
593
  window.addEventListener("online", sync);
598
594
  window.addEventListener("offline", sync);
@@ -604,8 +600,8 @@ function useNavigatorOnline() {
604
600
  return isOnline;
605
601
  }
606
602
  function useNow({ update = 1000 } = {}) {
607
- const [now, setNow] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(()=>Date.now());
608
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
603
+ const [now, setNow] = useState(()=>Date.now());
604
+ useEffect(()=>{
609
605
  if (false === update) return;
610
606
  const id = window.setInterval(()=>setNow(Date.now()), update);
611
607
  return ()=>window.clearInterval(id);
@@ -615,7 +611,7 @@ function useNow({ update = 1000 } = {}) {
615
611
  return now;
616
612
  }
617
613
  function detectOS() {
618
- if ("undefined" == typeof navigator) return "windows";
614
+ if ("u" < typeof navigator) return "windows";
619
615
  const ua = navigator.userAgent.toLowerCase();
620
616
  const platform = (navigator.platform ?? "").toLowerCase();
621
617
  const combined = `${ua} ${platform}`;
@@ -626,7 +622,7 @@ function detectOS() {
626
622
  return "windows";
627
623
  }
628
624
  function useOS(override) {
629
- return (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>override ?? detectOS(), [
625
+ return useMemo(()=>override ?? detectOS(), [
630
626
  override
631
627
  ]);
632
628
  }
@@ -637,8 +633,8 @@ function usePrefersReducedMotion() {
637
633
  return useMediaQuery("(prefers-reduced-motion: reduce)");
638
634
  }
639
635
  function usePrevious(value) {
640
- const ref = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(void 0);
641
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
636
+ const ref = useRef(void 0);
637
+ useEffect(()=>{
642
638
  ref.current = value;
643
639
  }, [
644
640
  value
@@ -646,13 +642,13 @@ function usePrevious(value) {
646
642
  return ref.current;
647
643
  }
648
644
  function useTimeout(callback, delay) {
649
- const callbackRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(callback);
650
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
645
+ const callbackRef = useRef(callback);
646
+ useEffect(()=>{
651
647
  callbackRef.current = callback;
652
648
  }, [
653
649
  callback
654
650
  ]);
655
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
651
+ useEffect(()=>{
656
652
  if (null === delay) return;
657
653
  const id = window.setTimeout(()=>callbackRef.current(), delay);
658
654
  return ()=>window.clearTimeout(id);
@@ -662,7 +658,7 @@ function useTimeout(callback, delay) {
662
658
  }
663
659
  const KEYBOARD_OPEN_DELTA = 150;
664
660
  function getViewportState() {
665
- if ("undefined" == typeof window) return {
661
+ if ("u" < typeof window) return {
666
662
  visualViewportHeight: 0,
667
663
  keyboardOpen: false
668
664
  };
@@ -674,9 +670,9 @@ function getViewportState() {
674
670
  };
675
671
  }
676
672
  function useViewport() {
677
- const [state, setState] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(()=>getViewportState());
678
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
679
- if ("undefined" == typeof window) return;
673
+ const [state, setState] = useState(()=>getViewportState());
674
+ useEffect(()=>{
675
+ if ("u" < typeof window) return;
680
676
  const target = window.visualViewport ?? window;
681
677
  const handleChange = ()=>{
682
678
  setState((prev)=>{
@@ -695,7 +691,7 @@ function useViewport() {
695
691
  return state;
696
692
  }
697
693
  function getWindowSize() {
698
- if ("undefined" == typeof window) return {
694
+ if ("u" < typeof window) return {
699
695
  width: 0,
700
696
  height: 0
701
697
  };
@@ -705,9 +701,9 @@ function getWindowSize() {
705
701
  };
706
702
  }
707
703
  function useWindowSize() {
708
- const [size, setSize] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(getWindowSize);
709
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
710
- if ("undefined" == typeof window) return;
704
+ const [size, setSize] = useState(getWindowSize);
705
+ useEffect(()=>{
706
+ if ("u" < typeof window) return;
711
707
  const handleResize = ()=>{
712
708
  setSize((prev)=>{
713
709
  const next = getWindowSize();
@@ -720,6 +716,5 @@ function useWindowSize() {
720
716
  }, []);
721
717
  return size;
722
718
  }
723
- var __webpack_exports__isFocusVisible = __WEBPACK_EXTERNAL_MODULE__react_aria_interactions_8422cce9__.isFocusVisible;
724
- var __webpack_exports__usePress = __WEBPACK_EXTERNAL_MODULE__react_aria_interactions_8422cce9__.usePress;
725
- export { StorageProvider, useBeforeUnloadWarning, useBreakpoint, useContainerSize, useControllableState, useCopyToClipboard, useDebouncedValue, useDeferredPresence, useDisclosure, useEventListener, useHover, useInterval, useKeyDown, useLongPress, useMediaQuery, useNavigatorOnline, useNow, useOS, usePersistentSharedState, usePersistentState, usePointerCoarse, usePrefersReducedMotion, usePrevious, useSessionSharedState, useSessionState, useTimeout, useViewport, useWindowSize, __webpack_exports__isFocusVisible as isFocusVisible, __webpack_exports__usePress as usePress };
719
+ export { isFocusVisible, usePress } from "@react-aria/interactions";
720
+ export { StorageProvider, useBeforeUnloadWarning, useBreakpoint, useContainerSize, useControllableState, useCopyToClipboard, useDebouncedValue, useDeferredPresence, useDisclosure, useEventListener, useHover, useInterval, useKeyDown, useLongPress, useMediaQuery, useNavigatorOnline, useNow, useOS, usePersistentSharedState, usePersistentState, usePointerCoarse, usePrefersReducedMotion, usePrevious, useSessionSharedState, useSessionState, useTimeout, useViewport, useWindowSize };
@@ -1 +1 @@
1
- {"version":3,"file":"use-controllable-state.d.ts","sourceRoot":"","sources":["../src/use-controllable-state.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,2BAA2B,CAAC,MAAM;IACjD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EACzC,OAAO,EAAE,2BAA2B,CAAC,MAAM,CAAC,GAC3C,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC,CAoBvC"}
1
+ {"version":3,"file":"use-controllable-state.d.ts","sourceRoot":"","sources":["../src/use-controllable-state.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,2BAA2B,CAAC,MAAM;IACjD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EACzC,OAAO,EAAE,2BAA2B,CAAC,MAAM,CAAC,GAC3C,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC,CAqBvC"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-deferred-presence.d.ts","sourceRoot":"","sources":["../src/use-deferred-presence.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;AAIpE,MAAM,WAAW,uBAAuB;IACtC,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,wEAAwE;IACxE,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,OAAO,EAClB,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE,uBAAuB,GAC7D,qBAAqB,CA8BvB"}
1
+ {"version":3,"file":"use-deferred-presence.d.ts","sourceRoot":"","sources":["../src/use-deferred-presence.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;AAIpE,MAAM,WAAW,uBAAuB;IACtC,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,wEAAwE;IACxE,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,OAAO,EAClB,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE,uBAAuB,GAC7D,qBAAqB,CA+BvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-long-press.d.ts","sourceRoot":"","sources":["../src/use-long-press.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,IAAI,eAAe,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAG7F,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,6EAA6E;IAC7E,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,EAAE,MAAM,IAAI,CAAA;CACxB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAa,EACb,eAAmB,EACnB,QAAgB,EAChB,WAAW,GACZ,EAAE,mBAAmB;yBA4BG,iBAAiB,CAAC,WAAW,CAAC;yBAc9B,iBAAiB,CAAC,WAAW,CAAC;uBAMhC,iBAAiB,CAAC,WAAW,CAAC;2BAI1B,iBAAiB,CAAC,WAAW,CAAC;0BAI/B,eAAe,CAAC,WAAW,CAAC;EAQrD"}
1
+ {"version":3,"file":"use-long-press.d.ts","sourceRoot":"","sources":["../src/use-long-press.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,IAAI,eAAe,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAG7F,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,6EAA6E;IAC7E,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,EAAE,MAAM,IAAI,CAAA;CACxB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAa,EACb,eAAmB,EACnB,QAAgB,EAChB,WAAW,GACZ,EAAE,mBAAmB;IA8BlB,aAAa,QAAQ,iBAAiB,CAAC,WAAW,CAAC;IAcnD,aAAa,QAAQ,iBAAiB,CAAC,WAAW,CAAC;IAMnD,WAAW,QAAQ,iBAAiB,CAAC,WAAW,CAAC;IAIjD,eAAe,QAAQ,iBAAiB,CAAC,WAAW,CAAC;IAIrD,cAAc,QAAQ,eAAe,CAAC,WAAW,CAAC;EAQrD"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-previous.d.ts","sourceRoot":"","sources":["../src/use-previous.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAMtD"}
1
+ {"version":3,"file":"use-previous.d.ts","sourceRoot":"","sources":["../src/use-previous.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAOtD"}
@@ -1,5 +1,5 @@
1
1
  import type { ReactNode } from "react";
2
- /** Anything with a `.parse` method — Zod schemas satisfy this directly. */
2
+ /** Anything with a `.parse` method that throws on invalid input — `@ox0/schema` and Zod schemas fit. */
3
3
  export type Parser<T> = {
4
4
  parse: (value: unknown) => T;
5
5
  };
@@ -1 +1 @@
1
- {"version":3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AC,CAAC,CAAC,uCAxI1D,IAAI,EA0I1C;AAED,yCAAyC;AACzC,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,uCAhJO,IAAI,EAmJ1C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ox0/hooks",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/esturcke/ox0-platform.git",