@pyreon/hooks 0.11.4 → 0.11.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +5 -5
  2. package/lib/index.d.ts +6 -6
  3. package/lib/index.js +4 -6
  4. package/package.json +24 -24
  5. package/src/__tests__/useBreakpoint.test.ts +48 -48
  6. package/src/__tests__/useClickOutside.test.ts +31 -31
  7. package/src/__tests__/useColorScheme.test.ts +22 -22
  8. package/src/__tests__/useControllableState.test.ts +18 -18
  9. package/src/__tests__/useDebouncedCallback.test.ts +19 -19
  10. package/src/__tests__/useDebouncedValue.test.ts +28 -28
  11. package/src/__tests__/useElementSize.test.ts +21 -21
  12. package/src/__tests__/useFocus.test.ts +12 -12
  13. package/src/__tests__/useFocusTrap.test.ts +36 -36
  14. package/src/__tests__/useHover.test.ts +13 -13
  15. package/src/__tests__/useIntersection.test.ts +20 -20
  16. package/src/__tests__/useInterval.test.ts +7 -7
  17. package/src/__tests__/useIsomorphicLayoutEffect.test.ts +5 -5
  18. package/src/__tests__/useKeyboard.test.ts +38 -38
  19. package/src/__tests__/useLatest.test.ts +11 -11
  20. package/src/__tests__/useMediaQuery.test.ts +29 -29
  21. package/src/__tests__/useMergedRef.test.ts +10 -10
  22. package/src/__tests__/usePrevious.test.ts +20 -20
  23. package/src/__tests__/useReducedMotion.test.ts +15 -15
  24. package/src/__tests__/useRootSize.test.ts +9 -9
  25. package/src/__tests__/useScrollLock.test.ts +33 -33
  26. package/src/__tests__/useSpacing.test.ts +11 -11
  27. package/src/__tests__/useThemeValue.test.ts +5 -5
  28. package/src/__tests__/useThrottledCallback.test.ts +16 -16
  29. package/src/__tests__/useTimeout.test.ts +8 -8
  30. package/src/__tests__/useToggle.test.ts +14 -14
  31. package/src/__tests__/useUpdateEffect.test.ts +8 -8
  32. package/src/__tests__/useWindowResize.test.ts +34 -34
  33. package/src/index.ts +56 -56
  34. package/src/useBreakpoint.ts +6 -6
  35. package/src/useClickOutside.ts +5 -5
  36. package/src/useClipboard.ts +2 -2
  37. package/src/useColorScheme.ts +5 -5
  38. package/src/useControllableState.ts +2 -2
  39. package/src/useDebouncedCallback.ts +1 -1
  40. package/src/useDebouncedValue.ts +2 -2
  41. package/src/useDialog.ts +4 -4
  42. package/src/useElementSize.ts +2 -2
  43. package/src/useEventListener.ts +2 -2
  44. package/src/useFocus.ts +1 -1
  45. package/src/useFocusTrap.ts +4 -4
  46. package/src/useHover.ts +1 -1
  47. package/src/useInfiniteScroll.ts +10 -10
  48. package/src/useIntersection.ts +2 -2
  49. package/src/useInterval.ts +3 -4
  50. package/src/useIsomorphicLayoutEffect.ts +2 -2
  51. package/src/useKeyboard.ts +3 -3
  52. package/src/useMediaQuery.ts +4 -4
  53. package/src/useMergedRef.ts +1 -1
  54. package/src/useOnline.ts +6 -6
  55. package/src/usePrevious.ts +1 -1
  56. package/src/useReducedMotion.ts +2 -2
  57. package/src/useRootSize.ts +1 -1
  58. package/src/useScrollLock.ts +3 -3
  59. package/src/useSpacing.ts +1 -1
  60. package/src/useThemeValue.ts +2 -2
  61. package/src/useThrottledCallback.ts +2 -2
  62. package/src/useTimeAgo.ts +15 -15
  63. package/src/useTimeout.ts +3 -4
  64. package/src/useToggle.ts +1 -1
  65. package/src/useUpdateEffect.ts +2 -2
  66. package/src/useWindowResize.ts +6 -6
package/src/useDialog.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { onCleanup, signal } from "@pyreon/reactivity"
1
+ import { onCleanup, signal } from '@pyreon/reactivity'
2
2
 
3
3
  export interface UseDialogResult {
4
4
  /** Whether the dialog is currently open. */
@@ -60,7 +60,7 @@ export function useDialog(options?: { onClose?: () => void }): UseDialogResult {
60
60
  const ref = (el: HTMLDialogElement) => {
61
61
  // Clean up previous element if ref is called again
62
62
  if (dialogEl && closeHandler) {
63
- dialogEl.removeEventListener("close", closeHandler)
63
+ dialogEl.removeEventListener('close', closeHandler)
64
64
  }
65
65
 
66
66
  dialogEl = el
@@ -70,12 +70,12 @@ export function useDialog(options?: { onClose?: () => void }): UseDialogResult {
70
70
  options?.onClose?.()
71
71
  }
72
72
 
73
- el.addEventListener("close", closeHandler)
73
+ el.addEventListener('close', closeHandler)
74
74
  }
75
75
 
76
76
  onCleanup(() => {
77
77
  if (dialogEl && closeHandler) {
78
- dialogEl.removeEventListener("close", closeHandler)
78
+ dialogEl.removeEventListener('close', closeHandler)
79
79
  }
80
80
  })
81
81
 
@@ -1,5 +1,5 @@
1
- import { onMount, onUnmount } from "@pyreon/core"
2
- import { signal } from "@pyreon/reactivity"
1
+ import { onMount, onUnmount } from '@pyreon/core'
2
+ import { signal } from '@pyreon/reactivity'
3
3
 
4
4
  export interface Size {
5
5
  width: number
@@ -1,4 +1,4 @@
1
- import { onCleanup } from "@pyreon/reactivity"
1
+ import { onCleanup } from '@pyreon/reactivity'
2
2
 
3
3
  /**
4
4
  * Attach an event listener with automatic cleanup on unmount.
@@ -22,7 +22,7 @@ export function useEventListener<K extends keyof WindowEventMap>(
22
22
  options?: boolean | AddEventListenerOptions,
23
23
  target?: () => EventTarget | null | undefined,
24
24
  ): void {
25
- const isBrowser = typeof window !== "undefined"
25
+ const isBrowser = typeof window !== 'undefined'
26
26
  if (!isBrowser) return
27
27
 
28
28
  const el = target?.() ?? window
package/src/useFocus.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { signal } from "@pyreon/reactivity"
1
+ import { signal } from '@pyreon/reactivity'
2
2
 
3
3
  export interface UseFocusResult {
4
4
  focused: () => boolean
@@ -1,4 +1,4 @@
1
- import { onMount, onUnmount } from "@pyreon/core"
1
+ import { onMount, onUnmount } from '@pyreon/core'
2
2
 
3
3
  const FOCUSABLE =
4
4
  'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])'
@@ -8,7 +8,7 @@ const FOCUSABLE =
8
8
  */
9
9
  export function useFocusTrap(getEl: () => HTMLElement | null): void {
10
10
  const listener = (e: KeyboardEvent) => {
11
- if (e.key !== "Tab") return
11
+ if (e.key !== 'Tab') return
12
12
  const el = getEl()
13
13
  if (!el) return
14
14
 
@@ -32,11 +32,11 @@ export function useFocusTrap(getEl: () => HTMLElement | null): void {
32
32
  }
33
33
 
34
34
  onMount(() => {
35
- document.addEventListener("keydown", listener)
35
+ document.addEventListener('keydown', listener)
36
36
  return undefined
37
37
  })
38
38
 
39
39
  onUnmount(() => {
40
- document.removeEventListener("keydown", listener)
40
+ document.removeEventListener('keydown', listener)
41
41
  })
42
42
  }
package/src/useHover.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { signal } from "@pyreon/reactivity"
1
+ import { signal } from '@pyreon/reactivity'
2
2
 
3
3
  export interface UseHoverResult {
4
4
  /** Reactive boolean — true when element is hovered */
@@ -1,4 +1,4 @@
1
- import { onCleanup, signal } from "@pyreon/reactivity"
1
+ import { onCleanup, signal } from '@pyreon/reactivity'
2
2
 
3
3
  export interface UseInfiniteScrollOptions {
4
4
  /** Distance from bottom (px) to trigger load. Default: 100 */
@@ -8,7 +8,7 @@ export interface UseInfiniteScrollOptions {
8
8
  /** Whether there's more data to load. Default: true */
9
9
  hasMore?: () => boolean
10
10
  /** Scroll direction. Default: "down" */
11
- direction?: "up" | "down"
11
+ direction?: 'up' | 'down'
12
12
  }
13
13
 
14
14
  export interface UseInfiniteScrollResult {
@@ -48,7 +48,7 @@ export function useInfiniteScroll(
48
48
  options?: UseInfiniteScrollOptions,
49
49
  ): UseInfiniteScrollResult {
50
50
  const threshold = options?.threshold ?? 100
51
- const direction = options?.direction ?? "down"
51
+ const direction = options?.direction ?? 'down'
52
52
  const triggered = signal(false)
53
53
  let observer: IntersectionObserver | null = null
54
54
  let sentinel: HTMLDivElement | null = null
@@ -72,13 +72,13 @@ export function useInfiniteScroll(
72
72
  containerEl = el
73
73
 
74
74
  // Create an invisible sentinel element at the scroll boundary
75
- sentinel = document.createElement("div")
76
- sentinel.style.height = "1px"
77
- sentinel.style.width = "100%"
78
- sentinel.style.pointerEvents = "none"
79
- sentinel.setAttribute("aria-hidden", "true")
75
+ sentinel = document.createElement('div')
76
+ sentinel.style.height = '1px'
77
+ sentinel.style.width = '100%'
78
+ sentinel.style.pointerEvents = 'none'
79
+ sentinel.setAttribute('aria-hidden', 'true')
80
80
 
81
- if (direction === "down") {
81
+ if (direction === 'down') {
82
82
  el.appendChild(sentinel)
83
83
  } else {
84
84
  el.insertBefore(sentinel, el.firstChild)
@@ -87,7 +87,7 @@ export function useInfiniteScroll(
87
87
  observer = new IntersectionObserver(handleIntersect, {
88
88
  root: el,
89
89
  rootMargin:
90
- direction === "down" ? `0px 0px ${threshold}px 0px` : `${threshold}px 0px 0px 0px`,
90
+ direction === 'down' ? `0px 0px ${threshold}px 0px` : `${threshold}px 0px 0px 0px`,
91
91
  threshold: 0,
92
92
  })
93
93
  observer.observe(sentinel)
@@ -1,5 +1,5 @@
1
- import { onMount, onUnmount } from "@pyreon/core"
2
- import { signal } from "@pyreon/reactivity"
1
+ import { onMount, onUnmount } from '@pyreon/core'
2
+ import { signal } from '@pyreon/reactivity'
3
3
 
4
4
  /**
5
5
  * Observe element intersection reactively.
@@ -1,19 +1,18 @@
1
- import { onUnmount } from "@pyreon/core"
1
+ import { onUnmount } from '@pyreon/core'
2
2
 
3
3
  export type UseInterval = (callback: () => void, delay: number | null) => void
4
4
 
5
5
  /**
6
6
  * Declarative `setInterval` with auto-cleanup.
7
7
  * Pass `null` as `delay` to pause the interval.
8
- * Always calls the latest callback (no stale closures).
8
+ * In Pyreon, components run once — callback is captured at setup time.
9
9
  */
10
10
  export const useInterval: UseInterval = (callback, delay) => {
11
- const currentCallback = callback
12
11
  let intervalId: ReturnType<typeof setInterval> | null = null
13
12
 
14
13
  const start = () => {
15
14
  if (delay === null) return
16
- intervalId = setInterval(() => currentCallback(), delay)
15
+ intervalId = setInterval(() => callback(), delay)
17
16
  }
18
17
 
19
18
  const stop = () => {
@@ -1,4 +1,4 @@
1
- import { onMount } from "@pyreon/core"
1
+ import { onMount } from '@pyreon/core'
2
2
 
3
3
  /**
4
4
  * In Pyreon there is no SSR warning distinction between effect and
@@ -14,6 +14,6 @@ import { onMount } from "@pyreon/core"
14
14
  export type UseIsomorphicLayoutEffect = typeof onMount
15
15
 
16
16
  const useIsomorphicLayoutEffect: UseIsomorphicLayoutEffect =
17
- typeof window !== "undefined" ? onMount : onMount
17
+ typeof window !== 'undefined' ? onMount : onMount
18
18
 
19
19
  export default useIsomorphicLayoutEffect
@@ -1,4 +1,4 @@
1
- import { onMount, onUnmount } from "@pyreon/core"
1
+ import { onMount, onUnmount } from '@pyreon/core'
2
2
 
3
3
  /**
4
4
  * Listen for a specific key press.
@@ -6,9 +6,9 @@ import { onMount, onUnmount } from "@pyreon/core"
6
6
  export function useKeyboard(
7
7
  key: string,
8
8
  handler: (event: KeyboardEvent) => void,
9
- options?: { event?: "keydown" | "keyup"; target?: EventTarget },
9
+ options?: { event?: 'keydown' | 'keyup'; target?: EventTarget },
10
10
  ): void {
11
- const eventName = options?.event ?? "keydown"
11
+ const eventName = options?.event ?? 'keydown'
12
12
 
13
13
  const listener = (e: Event) => {
14
14
  const ke = e as KeyboardEvent
@@ -1,5 +1,5 @@
1
- import { onMount, onUnmount } from "@pyreon/core"
2
- import { signal } from "@pyreon/reactivity"
1
+ import { onMount, onUnmount } from '@pyreon/core'
2
+ import { signal } from '@pyreon/reactivity'
3
3
 
4
4
  /**
5
5
  * Subscribe to a CSS media query, returns a reactive boolean.
@@ -15,12 +15,12 @@ export function useMediaQuery(query: string): () => boolean {
15
15
  onMount(() => {
16
16
  mql = window.matchMedia(query)
17
17
  matches.set(mql.matches)
18
- mql.addEventListener("change", onChange)
18
+ mql.addEventListener('change', onChange)
19
19
  return undefined
20
20
  })
21
21
 
22
22
  onUnmount(() => {
23
- mql?.removeEventListener("change", onChange)
23
+ mql?.removeEventListener('change', onChange)
24
24
  })
25
25
 
26
26
  return matches
@@ -12,7 +12,7 @@ export const useMergedRef = <T>(...refs: (Ref<T> | undefined)[]): ((node: T | nu
12
12
  return (node: T | null) => {
13
13
  for (const ref of refs) {
14
14
  if (!ref) continue
15
- if (typeof ref === "function") {
15
+ if (typeof ref === 'function') {
16
16
  ref(node)
17
17
  } else {
18
18
  ;(ref as RefObject<unknown>).current = node
package/src/useOnline.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { onCleanup, signal } from "@pyreon/reactivity"
1
+ import { onCleanup, signal } from '@pyreon/reactivity'
2
2
 
3
3
  /**
4
4
  * Reactive online/offline status.
@@ -13,17 +13,17 @@ import { onCleanup, signal } from "@pyreon/reactivity"
13
13
  * ```
14
14
  */
15
15
  export function useOnline(): () => boolean {
16
- const isBrowser = typeof window !== "undefined"
16
+ const isBrowser = typeof window !== 'undefined'
17
17
  const online = signal(isBrowser ? navigator.onLine : true)
18
18
 
19
19
  if (isBrowser) {
20
20
  const setOnline = () => online.set(true)
21
21
  const setOffline = () => online.set(false)
22
- window.addEventListener("online", setOnline)
23
- window.addEventListener("offline", setOffline)
22
+ window.addEventListener('online', setOnline)
23
+ window.addEventListener('offline', setOffline)
24
24
  onCleanup(() => {
25
- window.removeEventListener("online", setOnline)
26
- window.removeEventListener("offline", setOffline)
25
+ window.removeEventListener('online', setOnline)
26
+ window.removeEventListener('offline', setOffline)
27
27
  })
28
28
  }
29
29
 
@@ -1,4 +1,4 @@
1
- import { effect, signal } from "@pyreon/reactivity"
1
+ import { effect, signal } from '@pyreon/reactivity'
2
2
 
3
3
  /**
4
4
  * Track the previous value of a reactive getter.
@@ -1,8 +1,8 @@
1
- import { useMediaQuery } from "./useMediaQuery"
1
+ import { useMediaQuery } from './useMediaQuery'
2
2
 
3
3
  /**
4
4
  * Returns true when the user prefers reduced motion.
5
5
  */
6
6
  export function useReducedMotion(): () => boolean {
7
- return useMediaQuery("(prefers-reduced-motion: reduce)")
7
+ return useMediaQuery('(prefers-reduced-motion: reduce)')
8
8
  }
@@ -1,4 +1,4 @@
1
- import { useTheme } from "@pyreon/styler"
1
+ import { useTheme } from '@pyreon/styler'
2
2
 
3
3
  type RootSizeResult = {
4
4
  rootSize: number
@@ -1,7 +1,7 @@
1
- import { onUnmount } from "@pyreon/core"
1
+ import { onUnmount } from '@pyreon/core'
2
2
 
3
3
  let lockCount = 0
4
- let savedOverflow = ""
4
+ let savedOverflow = ''
5
5
 
6
6
  /**
7
7
  * Lock page scroll. Uses reference counting for concurrent locks.
@@ -15,7 +15,7 @@ export function useScrollLock(): { lock: () => void; unlock: () => void } {
15
15
  isLocked = true
16
16
  if (lockCount === 0) {
17
17
  savedOverflow = document.body.style.overflow
18
- document.body.style.overflow = "hidden"
18
+ document.body.style.overflow = 'hidden'
19
19
  }
20
20
  lockCount++
21
21
  }
package/src/useSpacing.ts CHANGED
@@ -1,4 +1,4 @@
1
- import useRootSize from "./useRootSize"
1
+ import useRootSize from './useRootSize'
2
2
 
3
3
  export type UseSpacing = (base?: number | undefined) => (multiplier: number) => string
4
4
 
@@ -1,5 +1,5 @@
1
- import { useTheme } from "@pyreon/styler"
2
- import { get } from "@pyreon/ui-core"
1
+ import { useTheme } from '@pyreon/styler'
2
+ import { get } from '@pyreon/ui-core'
3
3
 
4
4
  export type UseThemeValue = <T = unknown>(path: string) => T | undefined
5
5
 
@@ -1,5 +1,5 @@
1
- import { onUnmount } from "@pyreon/core"
2
- import { throttle } from "@pyreon/ui-core"
1
+ import { onUnmount } from '@pyreon/core'
2
+ import { throttle } from '@pyreon/ui-core'
3
3
 
4
4
  type ThrottledFn<T extends (...args: any[]) => any> = {
5
5
  (...args: Parameters<T>): void
package/src/useTimeAgo.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { onCleanup, signal } from "@pyreon/reactivity"
1
+ import { onCleanup, signal } from '@pyreon/reactivity'
2
2
 
3
- type TimeUnit = "second" | "minute" | "hour" | "day" | "week" | "month" | "year"
3
+ type TimeUnit = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'
4
4
 
5
5
  interface TimeInterval {
6
6
  unit: TimeUnit
@@ -8,13 +8,13 @@ interface TimeInterval {
8
8
  }
9
9
 
10
10
  const INTERVALS: TimeInterval[] = [
11
- { unit: "year", seconds: 31536000 },
12
- { unit: "month", seconds: 2592000 },
13
- { unit: "week", seconds: 604800 },
14
- { unit: "day", seconds: 86400 },
15
- { unit: "hour", seconds: 3600 },
16
- { unit: "minute", seconds: 60 },
17
- { unit: "second", seconds: 1 },
11
+ { unit: 'year', seconds: 31536000 },
12
+ { unit: 'month', seconds: 2592000 },
13
+ { unit: 'week', seconds: 604800 },
14
+ { unit: 'day', seconds: 86400 },
15
+ { unit: 'hour', seconds: 3600 },
16
+ { unit: 'minute', seconds: 60 },
17
+ { unit: 'second', seconds: 1 },
18
18
  ]
19
19
 
20
20
  /**
@@ -40,7 +40,7 @@ export interface UseTimeAgoOptions {
40
40
  */
41
41
  const defaultFormatter = (() => {
42
42
  const rtf =
43
- typeof Intl !== "undefined" ? new Intl.RelativeTimeFormat("en", { numeric: "auto" }) : undefined
43
+ typeof Intl !== 'undefined' ? new Intl.RelativeTimeFormat('en', { numeric: 'auto' }) : undefined
44
44
 
45
45
  return (value: number, unit: TimeUnit, isPast: boolean): string => {
46
46
  if (rtf) return rtf.format(isPast ? -value : value, unit)
@@ -58,19 +58,19 @@ function computeTimeAgo(
58
58
  formatter: (value: number, unit: TimeUnit, isPast: boolean) => string,
59
59
  ): string {
60
60
  const now = Date.now()
61
- const target = typeof date === "number" ? date : date.getTime()
61
+ const target = typeof date === 'number' ? date : date.getTime()
62
62
  const diff = Math.abs(now - target)
63
63
  const diffSeconds = Math.floor(diff / 1000)
64
64
  const isPast = target < now
65
65
 
66
- if (diffSeconds < 5) return "just now"
66
+ if (diffSeconds < 5) return 'just now'
67
67
 
68
68
  for (const { unit, seconds } of INTERVALS) {
69
69
  const value = Math.floor(diffSeconds / seconds)
70
70
  if (value >= 1) return formatter(value, unit, isPast)
71
71
  }
72
72
 
73
- return "just now"
73
+ return 'just now'
74
74
  }
75
75
 
76
76
  /**
@@ -99,7 +99,7 @@ export function useTimeAgo(
99
99
  options?: UseTimeAgoOptions,
100
100
  ): () => string {
101
101
  const formatter = options?.formatter ?? defaultFormatter
102
- const resolveDate = typeof date === "function" ? date : () => date
102
+ const resolveDate = typeof date === 'function' ? date : () => date
103
103
 
104
104
  const result = signal(computeTimeAgo(resolveDate(), formatter))
105
105
 
@@ -116,7 +116,7 @@ export function useTimeAgo(
116
116
  result.set(computeTimeAgo(d, formatter))
117
117
 
118
118
  // Schedule next update with adaptive interval
119
- const target = typeof d === "number" ? d : d.getTime()
119
+ const target = typeof d === 'number' ? d : d.getTime()
120
120
  const diffSeconds = Math.floor(Math.abs(Date.now() - target) / 1000)
121
121
  const interval = options?.interval ?? getRefreshInterval(diffSeconds)
122
122
  timer = setTimeout(tick, interval)
package/src/useTimeout.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { onUnmount } from "@pyreon/core"
1
+ import { onUnmount } from '@pyreon/core'
2
2
 
3
3
  export type UseTimeout = (
4
4
  callback: () => void,
@@ -8,10 +8,9 @@ export type UseTimeout = (
8
8
  /**
9
9
  * Declarative `setTimeout` with auto-cleanup.
10
10
  * Pass `null` as `delay` to disable. Returns `reset` and `clear` controls.
11
- * Always calls the latest callback (no stale closures).
11
+ * In Pyreon, components run once — callback is captured at setup time.
12
12
  */
13
13
  export const useTimeout: UseTimeout = (callback, delay) => {
14
- const currentCallback = callback
15
14
  let timer: ReturnType<typeof setTimeout> | null = null
16
15
 
17
16
  const clear = () => {
@@ -26,7 +25,7 @@ export const useTimeout: UseTimeout = (callback, delay) => {
26
25
  if (delay !== null) {
27
26
  timer = setTimeout(() => {
28
27
  timer = null
29
- currentCallback()
28
+ callback()
30
29
  }, delay)
31
30
  }
32
31
  }
package/src/useToggle.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { signal } from "@pyreon/reactivity"
1
+ import { signal } from '@pyreon/reactivity'
2
2
 
3
3
  export interface UseToggleResult {
4
4
  value: () => boolean
@@ -1,5 +1,5 @@
1
- import { onUnmount } from "@pyreon/core"
2
- import { watch } from "@pyreon/reactivity"
1
+ import { onUnmount } from '@pyreon/core'
2
+ import { watch } from '@pyreon/reactivity'
3
3
 
4
4
  export type UseUpdateEffect = <T>(
5
5
  source: () => T,
@@ -1,5 +1,5 @@
1
- import { onMount, onUnmount } from "@pyreon/core"
2
- import { signal } from "@pyreon/reactivity"
1
+ import { onMount, onUnmount } from '@pyreon/core'
2
+ import { signal } from '@pyreon/reactivity'
3
3
 
4
4
  export interface WindowSize {
5
5
  width: number
@@ -11,8 +11,8 @@ export interface WindowSize {
11
11
  */
12
12
  export function useWindowResize(throttleMs = 200): () => WindowSize {
13
13
  const size = signal<WindowSize>({
14
- width: typeof window !== "undefined" ? window.innerWidth : 0,
15
- height: typeof window !== "undefined" ? window.innerHeight : 0,
14
+ width: typeof window !== 'undefined' ? window.innerWidth : 0,
15
+ height: typeof window !== 'undefined' ? window.innerHeight : 0,
16
16
  })
17
17
 
18
18
  let timer: ReturnType<typeof setTimeout> | undefined
@@ -26,12 +26,12 @@ export function useWindowResize(throttleMs = 200): () => WindowSize {
26
26
  }
27
27
 
28
28
  onMount(() => {
29
- window.addEventListener("resize", onResize)
29
+ window.addEventListener('resize', onResize)
30
30
  return undefined
31
31
  })
32
32
 
33
33
  onUnmount(() => {
34
- window.removeEventListener("resize", onResize)
34
+ window.removeEventListener('resize', onResize)
35
35
  if (timer !== undefined) clearTimeout(timer)
36
36
  })
37
37