svelora 3.0.4 → 3.0.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 (36) hide show
  1. package/dist/Button/Button.svelte +65 -33
  2. package/dist/Fonts/fonts.js +3 -1
  3. package/dist/Link/Link.context-harness.svelte +8 -0
  4. package/dist/Link/Link.context-harness.svelte.d.ts +7 -0
  5. package/dist/Link/Link.svelte +57 -30
  6. package/dist/Link/index.d.ts +2 -0
  7. package/dist/Link/index.js +1 -0
  8. package/dist/Link/location-context.d.ts +4 -0
  9. package/dist/Link/location-context.js +1 -0
  10. package/dist/SelectMenu/SelectMenu.svelte +46 -14
  11. package/dist/Stepper/Stepper.svelte +12 -9
  12. package/dist/docs/navigation.js +54 -0
  13. package/dist/hooks/index.d.ts +14 -0
  14. package/dist/hooks/index.js +9 -0
  15. package/dist/hooks/useDebouncedState.svelte.d.ts +30 -0
  16. package/dist/hooks/useDebouncedState.svelte.js +45 -0
  17. package/dist/hooks/useEventListener.svelte.d.ts +30 -0
  18. package/dist/hooks/useEventListener.svelte.js +16 -0
  19. package/dist/hooks/useFocusTrap.svelte.d.ts +42 -0
  20. package/dist/hooks/useFocusTrap.svelte.js +87 -0
  21. package/dist/hooks/useIntersectionObserver.svelte.d.ts +30 -0
  22. package/dist/hooks/useIntersectionObserver.svelte.js +46 -0
  23. package/dist/hooks/useLocalStorage.svelte.d.ts +39 -0
  24. package/dist/hooks/useLocalStorage.svelte.js +73 -0
  25. package/dist/hooks/useResizeObserver.svelte.d.ts +50 -0
  26. package/dist/hooks/useResizeObserver.svelte.js +71 -0
  27. package/dist/hooks/useScrollLock.svelte.d.ts +28 -0
  28. package/dist/hooks/useScrollLock.svelte.js +79 -0
  29. package/dist/hooks/useThrottle.svelte.d.ts +37 -0
  30. package/dist/hooks/useThrottle.svelte.js +72 -0
  31. package/dist/hooks/useTimers.svelte.d.ts +62 -0
  32. package/dist/hooks/useTimers.svelte.js +90 -0
  33. package/dist/hooks/utils.d.ts +1 -0
  34. package/dist/hooks/utils.js +3 -0
  35. package/dist/mcp/svelora-docs.data.json +23 -5
  36. package/package.json +3 -3
@@ -0,0 +1,62 @@
1
+ type MaybeGetter<T> = T | (() => T);
2
+ export interface UseIntervalOptions {
3
+ /**
4
+ * Whether the interval is paused. Accepts a value or a reactive getter.
5
+ * @default false
6
+ */
7
+ paused?: boolean | (() => boolean);
8
+ }
9
+ interface UseIntervalReturn {
10
+ /** Pause ticking. */
11
+ pause(): void;
12
+ /** Resume ticking. */
13
+ resume(): void;
14
+ /** Whether the interval is currently ticking. */
15
+ readonly active: boolean;
16
+ }
17
+ interface UseTimeoutReturn {
18
+ /** Cancel the pending timeout, then schedule a fresh one. */
19
+ restart(): void;
20
+ /** Cancel the pending timeout. */
21
+ cancel(): void;
22
+ }
23
+ /**
24
+ * Run a callback on an interval with proper runes teardown.
25
+ *
26
+ * The delay may be a value or a getter; changing it restarts the interval with
27
+ * the new period. A `null`/`undefined` or non-positive delay disables it, as
28
+ * does `pause()` or the `paused` option. SSR-safe: no timer runs on the server.
29
+ *
30
+ * @example
31
+ * ```svelte
32
+ * <script>
33
+ * import { useInterval } from 'svelora'
34
+ *
35
+ * let count = $state(0)
36
+ * const timer = useInterval(() => count++, 1000)
37
+ * </script>
38
+ *
39
+ * <button onclick={timer.pause}>Pause</button>
40
+ * ```
41
+ */
42
+ export declare function useInterval(callback: () => void, delay: MaybeGetter<number | null | undefined>, options?: UseIntervalOptions): UseIntervalReturn;
43
+ /**
44
+ * Schedule a callback to run once after a delay, with proper runes teardown.
45
+ *
46
+ * Starts on mount. The delay may be a value or a getter; changing it restarts
47
+ * the timer. A `null`/`undefined` or negative delay schedules nothing. SSR-safe:
48
+ * no timer runs on the server.
49
+ *
50
+ * @example
51
+ * ```svelte
52
+ * <script>
53
+ * import { useTimeout } from 'svelora'
54
+ *
55
+ * const timer = useTimeout(() => (visible = false), 3000)
56
+ * </script>
57
+ *
58
+ * <button onclick={timer.restart}>Reset</button>
59
+ * ```
60
+ */
61
+ export declare function useTimeout(callback: () => void, delay: MaybeGetter<number | null | undefined>): UseTimeoutReturn;
62
+ export {};
@@ -0,0 +1,90 @@
1
+ import { toGetter } from './utils.js';
2
+ /**
3
+ * Run a callback on an interval with proper runes teardown.
4
+ *
5
+ * The delay may be a value or a getter; changing it restarts the interval with
6
+ * the new period. A `null`/`undefined` or non-positive delay disables it, as
7
+ * does `pause()` or the `paused` option. SSR-safe: no timer runs on the server.
8
+ *
9
+ * @example
10
+ * ```svelte
11
+ * <script>
12
+ * import { useInterval } from 'svelora'
13
+ *
14
+ * let count = $state(0)
15
+ * const timer = useInterval(() => count++, 1000)
16
+ * </script>
17
+ *
18
+ * <button onclick={timer.pause}>Pause</button>
19
+ * ```
20
+ */
21
+ export function useInterval(callback, delay, options = {}) {
22
+ const resolveDelay = toGetter(delay);
23
+ const resolvePaused = toGetter(options.paused ?? false);
24
+ let manuallyPaused = $state(false);
25
+ const active = $derived.by(() => {
26
+ if (manuallyPaused || resolvePaused())
27
+ return false;
28
+ const ms = resolveDelay();
29
+ return typeof ms === 'number' && ms > 0;
30
+ });
31
+ $effect(() => {
32
+ if (!active)
33
+ return;
34
+ const ms = resolveDelay();
35
+ if (typeof ms !== 'number' || ms <= 0)
36
+ return;
37
+ const id = setInterval(callback, ms);
38
+ return () => clearInterval(id);
39
+ });
40
+ return {
41
+ pause() {
42
+ manuallyPaused = true;
43
+ },
44
+ resume() {
45
+ manuallyPaused = false;
46
+ },
47
+ get active() {
48
+ return active;
49
+ }
50
+ };
51
+ }
52
+ /**
53
+ * Schedule a callback to run once after a delay, with proper runes teardown.
54
+ *
55
+ * Starts on mount. The delay may be a value or a getter; changing it restarts
56
+ * the timer. A `null`/`undefined` or negative delay schedules nothing. SSR-safe:
57
+ * no timer runs on the server.
58
+ *
59
+ * @example
60
+ * ```svelte
61
+ * <script>
62
+ * import { useTimeout } from 'svelora'
63
+ *
64
+ * const timer = useTimeout(() => (visible = false), 3000)
65
+ * </script>
66
+ *
67
+ * <button onclick={timer.restart}>Reset</button>
68
+ * ```
69
+ */
70
+ export function useTimeout(callback, delay) {
71
+ const resolveDelay = toGetter(delay);
72
+ let timeoutId;
73
+ let restartToken = $state(0);
74
+ $effect(() => {
75
+ void restartToken;
76
+ const ms = resolveDelay();
77
+ if (typeof ms !== 'number' || ms < 0)
78
+ return;
79
+ timeoutId = setTimeout(callback, ms);
80
+ return () => clearTimeout(timeoutId);
81
+ });
82
+ return {
83
+ restart() {
84
+ restartToken++;
85
+ },
86
+ cancel() {
87
+ clearTimeout(timeoutId);
88
+ }
89
+ };
90
+ }
@@ -0,0 +1 @@
1
+ export declare function toGetter<T>(value: T | (() => T)): () => T;
@@ -0,0 +1,3 @@
1
+ export function toGetter(value) {
2
+ return typeof value === 'function' ? value : () => value;
3
+ }