elements-kit 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +14 -0
  2. package/dist/await.d.mts +53 -0
  3. package/dist/await.mjs +70 -0
  4. package/dist/custom-elements.d.mts +1 -1
  5. package/dist/{element-xQwq4ulc.mjs → element-D3om9yA6.mjs} +71 -4
  6. package/dist/for.d.mts +20 -26
  7. package/dist/for.mjs +29 -4
  8. package/dist/fragment-ROPRBJQd.mjs +61 -0
  9. package/dist/hydrate/index.d.mts +41 -0
  10. package/dist/hydrate/index.mjs +2 -0
  11. package/dist/hydrate-6Qx4n4Su.mjs +380 -0
  12. package/dist/integrations/astro-client.d.mts +17 -0
  13. package/dist/integrations/astro-client.mjs +23 -0
  14. package/dist/integrations/astro-server.d.mts +15 -0
  15. package/dist/integrations/astro-server.mjs +39 -0
  16. package/dist/integrations/astro-slots.d.mts +12 -0
  17. package/dist/integrations/astro-slots.mjs +30 -0
  18. package/dist/integrations/astro.d.mts +46 -0
  19. package/dist/integrations/astro.mjs +64 -0
  20. package/dist/integrations/react.d.mts +1 -1
  21. package/dist/integrations/react.mjs +2 -2
  22. package/dist/jsx-runtime/index.d.mts +1 -1
  23. package/dist/jsx-runtime/index.mjs +2 -20
  24. package/dist/{lib-Dkc7cV5F.mjs → lib-DYypKhxk.mjs} +63 -5
  25. package/dist/render.mjs +1 -1
  26. package/dist/{scope-CnEvL9Nd.mjs → scope-zbEG299F.mjs} +1 -1
  27. package/dist/server/index.d.mts +43 -0
  28. package/dist/server/index.mjs +2 -0
  29. package/dist/server-iFSng50i.mjs +385 -0
  30. package/dist/signals/index.d.mts +2 -2
  31. package/dist/signals/index.mjs +5 -3
  32. package/dist/{slot-B8y0aEoz.d.mts → slot-BFWXeFRl.d.mts} +6 -0
  33. package/dist/{slot-Cne__au7.mjs → slot-Dvf30O0B.mjs} +12 -1
  34. package/dist/slot.d.mts +1 -1
  35. package/dist/slot.mjs +1 -1
  36. package/dist/{infer-B7T5hi_D.d.mts → types-ncUK9rki.d.mts} +140 -141
  37. package/dist/ui/overlay/index.mjs +1 -1
  38. package/dist/utilities/_observe.mjs +1 -1
  39. package/dist/utilities/active-element.d.mts +1 -1
  40. package/dist/utilities/active-element.mjs +1 -1
  41. package/dist/utilities/async.d.mts +19 -2
  42. package/dist/utilities/async.mjs +49 -2
  43. package/dist/utilities/context.mjs +1 -1
  44. package/dist/utilities/debounced.d.mts +1 -1
  45. package/dist/utilities/debounced.mjs +1 -1
  46. package/dist/utilities/dom-lifecycle.bench.mjs +3255 -1
  47. package/dist/utilities/dom-lifecycle.mjs +1 -1
  48. package/dist/utilities/element-rect.d.mts +1 -1
  49. package/dist/utilities/element-rect.mjs +1 -1
  50. package/dist/utilities/element-scroll.d.mts +1 -1
  51. package/dist/utilities/event-driven.d.mts +1 -1
  52. package/dist/utilities/event-driven.mjs +1 -1
  53. package/dist/utilities/event-listener.d.mts +1 -1
  54. package/dist/utilities/event-listener.mjs +1 -1
  55. package/dist/utilities/focus-within.d.mts +1 -1
  56. package/dist/utilities/focus-within.mjs +1 -1
  57. package/dist/utilities/hover.d.mts +1 -1
  58. package/dist/utilities/hover.mjs +1 -1
  59. package/dist/utilities/interval.d.mts +1 -1
  60. package/dist/utilities/interval.mjs +1 -1
  61. package/dist/utilities/location.d.mts +1 -1
  62. package/dist/utilities/location.mjs +1 -1
  63. package/dist/utilities/media-devices.d.mts +1 -1
  64. package/dist/utilities/media-devices.mjs +1 -1
  65. package/dist/utilities/media-player.d.mts +1 -1
  66. package/dist/utilities/media-query.d.mts +1 -1
  67. package/dist/utilities/media-query.mjs +1 -1
  68. package/dist/utilities/network.d.mts +1 -1
  69. package/dist/utilities/network.mjs +1 -1
  70. package/dist/utilities/orientation.d.mts +1 -1
  71. package/dist/utilities/orientation.mjs +1 -1
  72. package/dist/utilities/previous.d.mts +1 -1
  73. package/dist/utilities/previous.mjs +1 -1
  74. package/dist/utilities/promise.d.mts +19 -2
  75. package/dist/utilities/promise.mjs +33 -3
  76. package/dist/utilities/retry.mjs +1 -1
  77. package/dist/utilities/routing.d.mts +1 -1
  78. package/dist/utilities/routing.mjs +1 -1
  79. package/dist/utilities/search-params.d.mts +1 -1
  80. package/dist/utilities/storage.d.mts +1 -1
  81. package/dist/utilities/throttled.d.mts +1 -1
  82. package/dist/utilities/throttled.mjs +1 -1
  83. package/dist/utilities/timeout.d.mts +1 -1
  84. package/dist/utilities/timeout.mjs +1 -1
  85. package/dist/utilities/window-focus.d.mts +1 -1
  86. package/dist/utilities/window-focus.mjs +1 -1
  87. package/dist/utilities/window-size.d.mts +1 -1
  88. package/dist/utilities/window-size.mjs +1 -1
  89. package/package.json +16 -1
  90. package/dist/benchmark.CX_oY03V-CSLAXL5f.mjs +0 -5145
  91. package/dist/magic-string.es-CXefOmkB.mjs +0 -1011
  92. package/dist/test.BmQO5GaM-Ddz9cDxc.mjs +0 -8266
  93. package/dist/utilities/active-element.test.d.mts +0 -1
  94. package/dist/utilities/active-element.test.mjs +0 -25
  95. package/dist/utilities/async.test.d.mts +0 -1
  96. package/dist/utilities/async.test.mjs +0 -275
  97. package/dist/utilities/context.test.d.mts +0 -1
  98. package/dist/utilities/context.test.mjs +0 -171
  99. package/dist/utilities/debounced.test.d.mts +0 -1
  100. package/dist/utilities/debounced.test.mjs +0 -68
  101. package/dist/utilities/dom-lifecycle.test.d.mts +0 -1
  102. package/dist/utilities/dom-lifecycle.test.mjs +0 -228
  103. package/dist/utilities/element-rect.test.d.mts +0 -1
  104. package/dist/utilities/element-rect.test.mjs +0 -101
  105. package/dist/utilities/element-scroll.test.d.mts +0 -1
  106. package/dist/utilities/element-scroll.test.mjs +0 -27
  107. package/dist/utilities/event-listener.test.d.mts +0 -1
  108. package/dist/utilities/event-listener.test.mjs +0 -60
  109. package/dist/utilities/focus-within.test.d.mts +0 -1
  110. package/dist/utilities/focus-within.test.mjs +0 -51
  111. package/dist/utilities/form-object.test.d.mts +0 -1
  112. package/dist/utilities/form-object.test.mjs +0 -408
  113. package/dist/utilities/hover.test.d.mts +0 -1
  114. package/dist/utilities/hover.test.mjs +0 -54
  115. package/dist/utilities/intersection-observer.test.d.mts +0 -1
  116. package/dist/utilities/intersection-observer.test.mjs +0 -46
  117. package/dist/utilities/interval.test.d.mts +0 -1
  118. package/dist/utilities/interval.test.mjs +0 -115
  119. package/dist/utilities/location.test.d.mts +0 -1
  120. package/dist/utilities/location.test.mjs +0 -61
  121. package/dist/utilities/long-press.test.d.mts +0 -1
  122. package/dist/utilities/long-press.test.mjs +0 -54
  123. package/dist/utilities/media-devices.test.d.mts +0 -1
  124. package/dist/utilities/media-devices.test.mjs +0 -44
  125. package/dist/utilities/media-player.test.d.mts +0 -1
  126. package/dist/utilities/media-player.test.mjs +0 -102
  127. package/dist/utilities/mutation-observer.test.d.mts +0 -1
  128. package/dist/utilities/mutation-observer.test.mjs +0 -48
  129. package/dist/utilities/network.test.d.mts +0 -1
  130. package/dist/utilities/network.test.mjs +0 -30
  131. package/dist/utilities/on-click-outside.test.d.mts +0 -1
  132. package/dist/utilities/on-click-outside.test.mjs +0 -45
  133. package/dist/utilities/previous.test.d.mts +0 -1
  134. package/dist/utilities/previous.test.mjs +0 -90
  135. package/dist/utilities/promise.test.d.mts +0 -1
  136. package/dist/utilities/promise.test.mjs +0 -158
  137. package/dist/utilities/retry.test.d.mts +0 -1
  138. package/dist/utilities/retry.test.mjs +0 -85
  139. package/dist/utilities/routing.test.d.mts +0 -1
  140. package/dist/utilities/routing.test.mjs +0 -129
  141. package/dist/utilities/search-params.test.d.mts +0 -1
  142. package/dist/utilities/search-params.test.mjs +0 -37
  143. package/dist/utilities/ssr.test.d.mts +0 -1
  144. package/dist/utilities/ssr.test.mjs +0 -65
  145. package/dist/utilities/storage.test.d.mts +0 -1
  146. package/dist/utilities/storage.test.mjs +0 -139
  147. package/dist/utilities/throttled.test.d.mts +0 -1
  148. package/dist/utilities/throttled.test.mjs +0 -58
  149. package/dist/utilities/timeout.test.d.mts +0 -1
  150. package/dist/utilities/timeout.test.mjs +0 -121
  151. package/dist/utilities/window-size.test.d.mts +0 -1
  152. package/dist/utilities/window-size.test.mjs +0 -43
  153. /package/dist/{custom-elements-D5CgfNKc.d.mts → custom-elements-DK5VUcWA.d.mts} +0 -0
@@ -1,85 +0,0 @@
1
- import { p as onCleanup } from "../lib-Dkc7cV5F.mjs";
2
- import "../signals/index.mjs";
3
- import { f as it, l as describe } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
4
- import { n as vi, t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
5
- import { retry } from "./retry.mjs";
6
- //#region src/utilities/retry.test.ts
7
- describe("retry", () => {
8
- it("resolves immediately on first success", async () => {
9
- globalExpect(await retry(() => Promise.resolve(42), 3)()).toBe(42);
10
- });
11
- it("retries after failure and resolves on later success", async () => {
12
- let calls = 0;
13
- globalExpect(await retry(() => {
14
- calls++;
15
- if (calls < 3) return Promise.reject(/* @__PURE__ */ new Error("fail"));
16
- return Promise.resolve(calls);
17
- }, 3)()).toBe(3);
18
- globalExpect(calls).toBe(3);
19
- });
20
- it("rejects after exhausting all attempts", async () => {
21
- const err = /* @__PURE__ */ new Error("always fails");
22
- await globalExpect(retry(() => Promise.reject(err), 3)()).rejects.toBe(err);
23
- });
24
- it("rejects with the last error", async () => {
25
- let i = 0;
26
- const errors = [
27
- /* @__PURE__ */ new Error("a"),
28
- /* @__PURE__ */ new Error("b"),
29
- /* @__PURE__ */ new Error("c")
30
- ];
31
- await globalExpect(retry(() => Promise.reject(errors[i++]), 3)()).rejects.toBe(errors[2]);
32
- });
33
- it("delays between failures but not after the last", async () => {
34
- const delayFn = vi.fn().mockReturnValue(0);
35
- await retry(() => Promise.reject(/* @__PURE__ */ new Error("x")), 3, delayFn)().catch(() => {});
36
- globalExpect(delayFn).toHaveBeenCalledTimes(2);
37
- });
38
- it("supports dynamic delay via function — passes attempt index", async () => {
39
- const delayFn = vi.fn().mockReturnValue(0);
40
- await retry(() => Promise.reject(/* @__PURE__ */ new Error("x")), 3, delayFn)().catch(() => {});
41
- globalExpect(delayFn).toHaveBeenNthCalledWith(1, 0);
42
- globalExpect(delayFn).toHaveBeenNthCalledWith(2, 1);
43
- });
44
- it("onCleanup inside fn fires before each retry", async () => {
45
- const cleaned = [];
46
- let attempt = 0;
47
- await retry(() => {
48
- const i = attempt++;
49
- onCleanup(() => cleaned.push(i));
50
- if (i < 2) return Promise.reject(/* @__PURE__ */ new Error("fail"));
51
- return Promise.resolve(i);
52
- }, 3)();
53
- globalExpect(cleaned).toContain(0);
54
- globalExpect(cleaned).toContain(1);
55
- });
56
- it("composes with async()", async () => {
57
- const asyncOp = (await import("./async.mjs")).async;
58
- let calls = 0;
59
- const op = asyncOp(() => retry(() => {
60
- calls++;
61
- if (calls < 2) return Promise.reject(/* @__PURE__ */ new Error("fail"));
62
- return Promise.resolve(calls);
63
- }, 3)());
64
- op.start();
65
- await op;
66
- globalExpect(op.value).toBe(2);
67
- op.stop();
68
- });
69
- it("AbortController cleanup fires between retries when composed with async()", async () => {
70
- const asyncOp = (await import("./async.mjs")).async;
71
- const aborted = [];
72
- let attempt = 0;
73
- const op = asyncOp(() => {
74
- const i = attempt++;
75
- onCleanup(() => aborted.push(i));
76
- if (i < 2) return Promise.reject(/* @__PURE__ */ new Error("fail"));
77
- return Promise.resolve(i);
78
- });
79
- op.start();
80
- await op.catch(() => {});
81
- op.stop();
82
- });
83
- });
84
- //#endregion
85
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,129 +0,0 @@
1
- import { f as it, l as describe, o as afterEach, s as beforeAll } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
2
- import { n as vi, t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
3
- import { isLocalNavigationEvent, match, matches, navigate, patchHistory } from "./routing.mjs";
4
- //#region src/utilities/routing.test.ts
5
- beforeAll(() => {
6
- patchHistory();
7
- });
8
- afterEach(() => {
9
- history.replaceState(null, "", "/");
10
- });
11
- describe("navigate", () => {
12
- it("pushes a new history entry", () => {
13
- navigate("/about");
14
- globalExpect(location.pathname).toBe("/about");
15
- });
16
- it("replaces the current entry when replace is true", () => {
17
- const before = history.length;
18
- navigate("/replaced", { replace: true });
19
- globalExpect(location.pathname).toBe("/replaced");
20
- globalExpect(history.length).toBe(before);
21
- });
22
- it("dispatches pushstate event so currentLocation updates", () => {
23
- const handler = vi.fn();
24
- window.addEventListener("pushstate", handler);
25
- navigate("/dispatched");
26
- window.removeEventListener("pushstate", handler);
27
- globalExpect(handler).toHaveBeenCalledOnce();
28
- });
29
- it("dispatches replacestate event on replace", () => {
30
- const handler = vi.fn();
31
- window.addEventListener("replacestate", handler);
32
- navigate("/dispatched", { replace: true });
33
- window.removeEventListener("replacestate", handler);
34
- globalExpect(handler).toHaveBeenCalledOnce();
35
- });
36
- });
37
- describe("isLocalNavigationEvent", () => {
38
- function makeClick(el, init = {}) {
39
- const e = new MouseEvent("click", {
40
- bubbles: true,
41
- cancelable: true,
42
- ...init
43
- });
44
- Object.defineProperty(e, "currentTarget", {
45
- value: el,
46
- configurable: true
47
- });
48
- return e;
49
- }
50
- it("returns true for a same-origin link", () => {
51
- const el = document.createElement("a");
52
- el.href = "/linked";
53
- globalExpect(isLocalNavigationEvent(makeClick(el))).toBe(true);
54
- });
55
- it("returns false for an external link", () => {
56
- const el = document.createElement("a");
57
- el.href = "https://example.com/page";
58
- globalExpect(isLocalNavigationEvent(makeClick(el))).toBe(false);
59
- });
60
- it("returns false when metaKey is held", () => {
61
- const el = document.createElement("a");
62
- el.href = "/about";
63
- globalExpect(isLocalNavigationEvent(makeClick(el, { metaKey: true }))).toBe(false);
64
- });
65
- it("returns false when ctrlKey is held", () => {
66
- const el = document.createElement("a");
67
- el.href = "/about";
68
- globalExpect(isLocalNavigationEvent(makeClick(el, { ctrlKey: true }))).toBe(false);
69
- });
70
- it("returns false for download links", () => {
71
- const el = document.createElement("a");
72
- el.href = "/file.pdf";
73
- el.setAttribute("download", "");
74
- globalExpect(isLocalNavigationEvent(makeClick(el))).toBe(false);
75
- });
76
- it("returns false for _blank links", () => {
77
- const el = document.createElement("a");
78
- el.href = "/page";
79
- el.setAttribute("target", "_blank");
80
- globalExpect(isLocalNavigationEvent(makeClick(el))).toBe(false);
81
- });
82
- it("returns false for non-primary button clicks", () => {
83
- const el = document.createElement("a");
84
- el.href = "/page";
85
- globalExpect(isLocalNavigationEvent(makeClick(el, { button: 1 }))).toBe(false);
86
- });
87
- });
88
- describe("matches", () => {
89
- it("returns true when current URL matches", () => {
90
- navigate("/users/42");
91
- globalExpect(matches({ pathname: "/users/:id" })()).toBe(true);
92
- });
93
- it("returns false when current URL does not match", () => {
94
- navigate("/other");
95
- globalExpect(matches({ pathname: "/users/:id" })()).toBe(false);
96
- });
97
- it("updates reactively on navigation", () => {
98
- const result = matches({ pathname: "/home" });
99
- navigate("/other");
100
- globalExpect(result()).toBe(false);
101
- navigate("/home");
102
- globalExpect(result()).toBe(true);
103
- });
104
- });
105
- describe("match", () => {
106
- it("returns null when current URL does not match", () => {
107
- navigate("/other");
108
- globalExpect(match({ pathname: "/users/:id" })()).toBeNull();
109
- });
110
- it("returns URLPatternResult with groups when matched", () => {
111
- navigate("/users/42");
112
- globalExpect(match({ pathname: "/users/:id" })()?.pathname.groups.id).toBe("42");
113
- });
114
- it("updates reactively on navigation", () => {
115
- const result = match({ pathname: "/posts/:slug" });
116
- navigate("/posts/hello");
117
- globalExpect(result()?.pathname.groups.slug).toBe("hello");
118
- navigate("/other");
119
- globalExpect(result()).toBeNull();
120
- });
121
- it("extracts multiple params", () => {
122
- navigate("/posts/2024/my-slug");
123
- const result = match({ pathname: "/posts/:year/:slug" });
124
- globalExpect(result()?.pathname.groups.year).toBe("2024");
125
- globalExpect(result()?.pathname.groups.slug).toBe("my-slug");
126
- });
127
- });
128
- //#endregion
129
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,37 +0,0 @@
1
- import { c as effectScope } from "../lib-Dkc7cV5F.mjs";
2
- import "../signals/index.mjs";
3
- import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
4
- import { t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
5
- import { createSearchParam } from "./search-params.mjs";
6
- //#region src/utilities/search-params.test.ts
7
- afterEach(() => {
8
- history.replaceState(null, "", location.pathname);
9
- });
10
- describe("createSearchParam", () => {
11
- it("returns null when param is absent", () => {
12
- let s;
13
- effectScope(() => {
14
- s = createSearchParam("q");
15
- });
16
- globalExpect(s()).toBeNull();
17
- });
18
- it("reads an existing param from the URL", () => {
19
- history.replaceState(null, "", "?q=hello");
20
- let s;
21
- effectScope(() => {
22
- s = createSearchParam("q");
23
- });
24
- globalExpect(s()).toBe("hello");
25
- });
26
- it("reacts to popstate events", () => {
27
- let s;
28
- effectScope(() => {
29
- s = createSearchParam("q");
30
- });
31
- history.replaceState(null, "", "?q=changed");
32
- window.dispatchEvent(new PopStateEvent("popstate"));
33
- globalExpect(s()).toBe("changed");
34
- });
35
- });
36
- //#endregion
37
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,65 +0,0 @@
1
- import { p as test } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
2
- import { t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
3
- //#region src/utilities/ssr.test.ts
4
- // @vitest-environment node
5
- test.each([
6
- "./active-element.ts",
7
- "./async.ts",
8
- "./debounced.ts",
9
- "./element-rect.ts",
10
- "./element-scroll.ts",
11
- "./environment.ts",
12
- "./event-driven.ts",
13
- "./event-listener.ts",
14
- "./focus-within.ts",
15
- "./hover.ts",
16
- "./intersection-observer.ts",
17
- "./interval.ts",
18
- "./location.ts",
19
- "./long-press.ts",
20
- "./media-devices.ts",
21
- "./media-player.ts",
22
- "./media-query.ts",
23
- "./mutation-observer.ts",
24
- "./network.ts",
25
- "./on-click-outside.ts",
26
- "./orientation.ts",
27
- "./previous.ts",
28
- "./promise.ts",
29
- "./resize-observer.ts",
30
- "./retry.ts",
31
- "./routing.ts",
32
- "./search-params.ts",
33
- "./storage.ts",
34
- "./throttled.ts",
35
- "./timeout.ts",
36
- "./window-focus.ts",
37
- "./window-size.ts"
38
- ])("imports %s in Node without crashing", async (path) => {
39
- await globalExpect(import(path)).resolves.toBeDefined();
40
- });
41
- test("singletons return neutral values in Node", async () => {
42
- const { windowSize } = await import("./window-size.mjs");
43
- globalExpect(windowSize.width()).toBe(0);
44
- globalExpect(windowSize.height()).toBe(0);
45
- const { online } = await import("./network.mjs");
46
- globalExpect(online()).toBe(true);
47
- const { windowFocused } = await import("./window-focus.mjs");
48
- globalExpect(windowFocused()).toBe(true);
49
- const { activeElement } = await import("./active-element.mjs");
50
- globalExpect(activeElement()).toBe(null);
51
- const { orientation } = await import("./orientation.mjs");
52
- globalExpect(orientation.angle()).toBe(0);
53
- globalExpect(orientation.type()).toBe("portrait-primary");
54
- const { currentLocation } = await import("./location.mjs");
55
- globalExpect(currentLocation.href()).toBe("");
56
- globalExpect(currentLocation.pathname()).toBe("");
57
- globalExpect(currentLocation.search()).toBe("");
58
- globalExpect(currentLocation.hash()).toBe("");
59
- });
60
- test("isBrowser is false in Node", async () => {
61
- const { isBrowser } = await import("./environment.mjs");
62
- globalExpect(isBrowser).toBe(false);
63
- });
64
- //#endregion
65
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,139 +0,0 @@
1
- import { c as effectScope } from "../lib-Dkc7cV5F.mjs";
2
- import "../signals/index.mjs";
3
- import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
4
- import { t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
5
- import { createLocalStorage, createSessionStorage } from "./storage.mjs";
6
- //#region src/utilities/storage.test.ts
7
- describe("createLocalStorage", () => {
8
- afterEach(() => {
9
- localStorage.clear();
10
- });
11
- it("uses initialValue when storage is empty", () => {
12
- let s;
13
- effectScope(() => {
14
- s = createLocalStorage("count", 0);
15
- });
16
- globalExpect(s()).toBe(0);
17
- });
18
- it("reads an existing value from localStorage", () => {
19
- localStorage.setItem("count", "42");
20
- let s;
21
- effectScope(() => {
22
- s = createLocalStorage("count", 0);
23
- });
24
- globalExpect(s()).toBe(42);
25
- });
26
- it("persists writes to localStorage", () => {
27
- let s;
28
- effectScope(() => {
29
- s = createLocalStorage("key", "a");
30
- });
31
- s("b");
32
- globalExpect(JSON.parse(localStorage.getItem("key"))).toBe("b");
33
- });
34
- it("persists complex values as JSON", () => {
35
- let s;
36
- effectScope(() => {
37
- s = createLocalStorage("obj", { x: 1 });
38
- });
39
- s({ x: 99 });
40
- globalExpect(JSON.parse(localStorage.getItem("obj"))).toEqual({ x: 99 });
41
- });
42
- it("falls back to initialValue on invalid JSON", () => {
43
- localStorage.setItem("broken", "{not json}");
44
- let s;
45
- effectScope(() => {
46
- s = createLocalStorage("broken", 7);
47
- });
48
- globalExpect(s()).toBe(7);
49
- });
50
- it("supports custom serialise / deserialise", () => {
51
- let s;
52
- effectScope(() => {
53
- s = createLocalStorage("date", /* @__PURE__ */ new Date("2024-01-01"), {
54
- serialise: (d) => d.toISOString(),
55
- deserialise: (raw) => new Date(raw)
56
- });
57
- });
58
- const d = /* @__PURE__ */ new Date("2025-06-15");
59
- s(d);
60
- globalExpect(localStorage.getItem("date")).toBe(d.toISOString());
61
- });
62
- it("reacts to storage events from other tabs", () => {
63
- let s;
64
- effectScope(() => {
65
- s = createLocalStorage("sync-key", "init");
66
- });
67
- localStorage.setItem("sync-key", JSON.stringify("from-other-tab"));
68
- window.dispatchEvent(new StorageEvent("storage", {
69
- key: "sync-key",
70
- newValue: JSON.stringify("from-other-tab"),
71
- storageArea: localStorage
72
- }));
73
- globalExpect(s()).toBe("from-other-tab");
74
- });
75
- it("ignores storage events for different keys", () => {
76
- let s;
77
- effectScope(() => {
78
- s = createLocalStorage("my-key", "init");
79
- });
80
- window.dispatchEvent(new StorageEvent("storage", {
81
- key: "other-key",
82
- newValue: JSON.stringify("nope"),
83
- storageArea: localStorage
84
- }));
85
- globalExpect(s()).toBe("init");
86
- });
87
- it("resets to initialValue when key is removed", () => {
88
- let s;
89
- effectScope(() => {
90
- s = createLocalStorage("rm-key", "default");
91
- });
92
- s("changed");
93
- localStorage.removeItem("rm-key");
94
- window.dispatchEvent(new StorageEvent("storage", {
95
- key: "rm-key",
96
- newValue: null,
97
- storageArea: localStorage
98
- }));
99
- globalExpect(s()).toBe("default");
100
- });
101
- });
102
- describe("createSessionStorage", () => {
103
- afterEach(() => {
104
- sessionStorage.clear();
105
- });
106
- it("uses initialValue when storage is empty", () => {
107
- let s;
108
- effectScope(() => {
109
- s = createSessionStorage("count", 0);
110
- });
111
- globalExpect(s()).toBe(0);
112
- });
113
- it("reads an existing value from sessionStorage", () => {
114
- sessionStorage.setItem("count", "42");
115
- let s;
116
- effectScope(() => {
117
- s = createSessionStorage("count", 0);
118
- });
119
- globalExpect(s()).toBe(42);
120
- });
121
- it("persists writes to sessionStorage", () => {
122
- let s;
123
- effectScope(() => {
124
- s = createSessionStorage("key", "a");
125
- });
126
- s("b");
127
- globalExpect(JSON.parse(sessionStorage.getItem("key"))).toBe("b");
128
- });
129
- it("falls back to initialValue on invalid JSON", () => {
130
- sessionStorage.setItem("broken", "{not json}");
131
- let s;
132
- effectScope(() => {
133
- s = createSessionStorage("broken", 7);
134
- });
135
- globalExpect(s()).toBe(7);
136
- });
137
- });
138
- //#endregion
139
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,58 +0,0 @@
1
- import { c as effectScope, m as signal } from "../lib-Dkc7cV5F.mjs";
2
- import "../signals/index.mjs";
3
- import { c as beforeEach, f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
4
- import { n as vi, t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
5
- import { createThrottled } from "./throttled.mjs";
6
- //#region src/utilities/throttled.test.ts
7
- beforeEach(() => {
8
- vi.useFakeTimers();
9
- });
10
- afterEach(() => {
11
- vi.useRealTimers();
12
- });
13
- describe("createThrottled", () => {
14
- it("returns the initial value synchronously", () => {
15
- const s = signal(7);
16
- let t;
17
- effectScope(() => {
18
- t = createThrottled(() => s(), 200);
19
- });
20
- globalExpect(t()).toBe(7);
21
- });
22
- it("passes through the first change immediately (leading edge)", () => {
23
- const s = signal(0);
24
- let t;
25
- effectScope(() => {
26
- t = createThrottled(() => s(), 200);
27
- });
28
- s(1);
29
- globalExpect(t()).toBe(1);
30
- });
31
- it("schedules a trailing update for rapid changes within the interval", () => {
32
- const s = signal(0);
33
- let t;
34
- effectScope(() => {
35
- t = createThrottled(() => s(), 200);
36
- });
37
- s(1);
38
- globalExpect(t()).toBe(1);
39
- s(2);
40
- globalExpect(t()).toBe(1);
41
- vi.advanceTimersByTime(200);
42
- globalExpect(t()).toBe(2);
43
- });
44
- it("stops updating after scope disposal", () => {
45
- const s = signal(0);
46
- let t;
47
- const stop = effectScope(() => {
48
- t = createThrottled(() => s(), 200);
49
- });
50
- s(1);
51
- stop();
52
- s(99);
53
- vi.advanceTimersByTime(400);
54
- globalExpect(t()).toBe(1);
55
- });
56
- });
57
- //#endregion
58
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,121 +0,0 @@
1
- import { c as effectScope } from "../lib-Dkc7cV5F.mjs";
2
- import "../signals/index.mjs";
3
- import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
4
- import { n as vi, t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
5
- import { createTimeout } from "./timeout.mjs";
6
- //#region src/utilities/timeout.test.ts
7
- afterEach(() => {
8
- document.body.innerHTML = "";
9
- vi.useRealTimers();
10
- });
11
- describe("createTimeout", () => {
12
- it("starts as running", () => {
13
- vi.useFakeTimers();
14
- let t;
15
- const cb = vi.fn();
16
- effectScope(() => {
17
- t = createTimeout(cb, 500);
18
- });
19
- globalExpect(t.pending()).toBe(true);
20
- });
21
- it("fires callback after delay", () => {
22
- vi.useFakeTimers();
23
- const cb = vi.fn();
24
- effectScope(() => {
25
- createTimeout(cb, 500);
26
- });
27
- vi.advanceTimersByTime(600);
28
- globalExpect(cb).toHaveBeenCalledOnce();
29
- });
30
- it("pending becomes false after firing", () => {
31
- vi.useFakeTimers();
32
- let t;
33
- effectScope(() => {
34
- t = createTimeout(vi.fn(), 200);
35
- });
36
- vi.advanceTimersByTime(300);
37
- globalExpect(t.pending()).toBe(false);
38
- });
39
- it("stop() cancels the timeout", () => {
40
- vi.useFakeTimers();
41
- const cb = vi.fn();
42
- let t;
43
- effectScope(() => {
44
- t = createTimeout(cb, 500);
45
- });
46
- t.stop();
47
- vi.advanceTimersByTime(1e3);
48
- globalExpect(cb).not.toHaveBeenCalled();
49
- });
50
- it("reset() restarts the timer", () => {
51
- vi.useFakeTimers();
52
- const cb = vi.fn();
53
- let t;
54
- effectScope(() => {
55
- t = createTimeout(cb, 500);
56
- });
57
- vi.advanceTimersByTime(300);
58
- t.reset();
59
- vi.advanceTimersByTime(300);
60
- globalExpect(cb).not.toHaveBeenCalled();
61
- vi.advanceTimersByTime(300);
62
- globalExpect(cb).toHaveBeenCalledOnce();
63
- });
64
- it("immediate=false does not start automatically", () => {
65
- vi.useFakeTimers();
66
- const cb = vi.fn();
67
- let t;
68
- effectScope(() => {
69
- t = createTimeout(cb, 200, false);
70
- });
71
- globalExpect(t.pending()).toBe(false);
72
- vi.advanceTimersByTime(300);
73
- globalExpect(cb).not.toHaveBeenCalled();
74
- });
75
- it("start() fires after delay when called manually", () => {
76
- vi.useFakeTimers();
77
- const cb = vi.fn();
78
- let t;
79
- effectScope(() => {
80
- t = createTimeout(cb, 200, false);
81
- });
82
- t.start();
83
- globalExpect(t.pending()).toBe(true);
84
- vi.advanceTimersByTime(200);
85
- globalExpect(cb).toHaveBeenCalledOnce();
86
- globalExpect(t.pending()).toBe(false);
87
- });
88
- it("Symbol.dispose cancels the timeout", () => {
89
- vi.useFakeTimers();
90
- const cb = vi.fn();
91
- let t;
92
- effectScope(() => {
93
- t = createTimeout(cb, 500);
94
- });
95
- t[Symbol.dispose]();
96
- vi.advanceTimersByTime(1e3);
97
- globalExpect(cb).not.toHaveBeenCalled();
98
- });
99
- it("stops when scope is disposed", () => {
100
- vi.useFakeTimers();
101
- const cb = vi.fn();
102
- effectScope(() => {
103
- createTimeout(cb, 200);
104
- })();
105
- vi.advanceTimersByTime(500);
106
- globalExpect(cb).not.toHaveBeenCalled();
107
- });
108
- it("dynamic delay function is called at start", () => {
109
- vi.useFakeTimers();
110
- const cb = vi.fn();
111
- const getDelay = vi.fn().mockReturnValue(300);
112
- effectScope(() => {
113
- createTimeout(cb, getDelay);
114
- });
115
- vi.advanceTimersByTime(300);
116
- globalExpect(cb).toHaveBeenCalledOnce();
117
- globalExpect(getDelay).toHaveBeenCalledOnce();
118
- });
119
- });
120
- //#endregion
121
- export {};
@@ -1 +0,0 @@
1
- export { };