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,61 +0,0 @@
1
- import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
2
- import { t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
3
- import { currentLocation } from "./location.mjs";
4
- //#region src/utilities/location.test.ts
5
- afterEach(() => {
6
- location.hash = "";
7
- history.replaceState(null, "", "/");
8
- });
9
- describe("currentLocation (singleton)", () => {
10
- it("reads current hash", () => {
11
- globalExpect(currentLocation.hash()).toBe(location.hash);
12
- });
13
- it("reads current href", () => {
14
- globalExpect(typeof currentLocation.href()).toBe("string");
15
- });
16
- it("reads current pathname", () => {
17
- globalExpect(typeof currentLocation.pathname()).toBe("string");
18
- });
19
- it("reads current search", () => {
20
- globalExpect(typeof currentLocation.search()).toBe("string");
21
- });
22
- it("updates hash on hashchange", () => {
23
- location.hash = "#foo";
24
- window.dispatchEvent(new HashChangeEvent("hashchange"));
25
- globalExpect(currentLocation.hash()).toBe("#foo");
26
- });
27
- it("updates href on popstate", () => {
28
- history.replaceState(null, "", "/foo");
29
- window.dispatchEvent(new PopStateEvent("popstate"));
30
- globalExpect(currentLocation.href()).toMatch(/\/foo$/);
31
- });
32
- it("updates pathname on popstate", () => {
33
- history.replaceState(null, "", "/new-page");
34
- window.dispatchEvent(new PopStateEvent("popstate"));
35
- globalExpect(currentLocation.pathname()).toBe("/new-page");
36
- });
37
- it("updates href on hashchange", () => {
38
- history.replaceState(null, "", "/bar#baz");
39
- window.dispatchEvent(new HashChangeEvent("hashchange"));
40
- globalExpect(currentLocation.href()).toMatch(/#baz$/);
41
- });
42
- });
43
- describe("currentLocation (singleton)", () => {
44
- it("returns independent location signals", () => {
45
- const loc = currentLocation;
46
- globalExpect(typeof loc.hash()).toBe("string");
47
- globalExpect(typeof loc.href()).toBe("string");
48
- globalExpect(typeof loc.pathname()).toBe("string");
49
- globalExpect(typeof loc.search()).toBe("string");
50
- });
51
- it("all four properties update from a single event", () => {
52
- const loc = currentLocation;
53
- history.replaceState(null, "", "/factory-test?q=1#section");
54
- window.dispatchEvent(new PopStateEvent("popstate"));
55
- globalExpect(loc.pathname()).toBe("/factory-test");
56
- globalExpect(loc.search()).toBe("?q=1");
57
- globalExpect(loc.hash()).toBe("#section");
58
- });
59
- });
60
- //#endregion
61
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,54 +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 { createLongPress } from "./long-press.mjs";
6
- //#region src/utilities/long-press.test.ts
7
- afterEach(() => {
8
- document.body.innerHTML = "";
9
- vi.useRealTimers();
10
- });
11
- describe("createLongPress", () => {
12
- it("does not fire handler on short press", () => {
13
- vi.useFakeTimers();
14
- const el = document.createElement("button");
15
- document.body.appendChild(el);
16
- const handler = vi.fn();
17
- effectScope(() => {
18
- createLongPress(el, handler, { delay: 500 });
19
- });
20
- el.dispatchEvent(new PointerEvent("pointerdown"));
21
- vi.advanceTimersByTime(200);
22
- el.dispatchEvent(new PointerEvent("pointerup"));
23
- vi.advanceTimersByTime(500);
24
- globalExpect(handler).not.toHaveBeenCalled();
25
- });
26
- it("fires handler after delay", () => {
27
- vi.useFakeTimers();
28
- const el = document.createElement("button");
29
- document.body.appendChild(el);
30
- const handler = vi.fn();
31
- effectScope(() => {
32
- createLongPress(el, handler, { delay: 500 });
33
- });
34
- el.dispatchEvent(new PointerEvent("pointerdown"));
35
- vi.advanceTimersByTime(600);
36
- globalExpect(handler).toHaveBeenCalledOnce();
37
- });
38
- it("cancels when pointer moves", () => {
39
- vi.useFakeTimers();
40
- const el = document.createElement("button");
41
- document.body.appendChild(el);
42
- const handler = vi.fn();
43
- effectScope(() => {
44
- createLongPress(el, handler, { delay: 500 });
45
- });
46
- el.dispatchEvent(new PointerEvent("pointerdown"));
47
- vi.advanceTimersByTime(200);
48
- el.dispatchEvent(new PointerEvent("pointermove"));
49
- vi.advanceTimersByTime(500);
50
- globalExpect(handler).not.toHaveBeenCalled();
51
- });
52
- });
53
- //#endregion
54
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,44 +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 { createMediaDevices } from "./media-devices.mjs";
6
- //#region src/utilities/media-devices.test.ts
7
- afterEach(() => {
8
- document.body.innerHTML = "";
9
- vi.unstubAllGlobals();
10
- });
11
- describe("createMediaDevices", () => {
12
- it("returns a list of devices", async () => {
13
- const mockDevices = [{
14
- deviceId: "1",
15
- kind: "audioinput",
16
- label: "Mic"
17
- }];
18
- vi.stubGlobal("navigator", { mediaDevices: {
19
- enumerateDevices: vi.fn().mockResolvedValue(mockDevices),
20
- addEventListener: vi.fn(),
21
- removeEventListener: vi.fn()
22
- } });
23
- let d;
24
- effectScope(() => {
25
- d = createMediaDevices();
26
- });
27
- await new Promise((res) => setTimeout(res, 0));
28
- globalExpect(d()).toEqual(mockDevices);
29
- });
30
- it("removes devicechange listener on scope disposal", () => {
31
- const removeListener = vi.fn();
32
- vi.stubGlobal("navigator", { mediaDevices: {
33
- enumerateDevices: vi.fn().mockResolvedValue([]),
34
- addEventListener: vi.fn(),
35
- removeEventListener: removeListener
36
- } });
37
- effectScope(() => {
38
- createMediaDevices();
39
- })();
40
- globalExpect(removeListener).toHaveBeenCalledWith("devicechange", globalExpect.any(Function));
41
- });
42
- });
43
- //#endregion
44
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,102 +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 { createMediaPlayer } from "./media-player.mjs";
6
- //#region src/utilities/media-player.test.ts
7
- afterEach(() => {
8
- document.body.innerHTML = "";
9
- vi.restoreAllMocks();
10
- });
11
- describe("createMediaPlayer", () => {
12
- describe("with <audio>", () => {
13
- it("accepts an HTMLAudioElement", () => {
14
- const el = new Audio();
15
- let a;
16
- effectScope(() => {
17
- a = createMediaPlayer(el);
18
- });
19
- globalExpect(a.element).toBe(el);
20
- });
21
- it("starts as paused", () => {
22
- let a;
23
- effectScope(() => {
24
- a = createMediaPlayer(new Audio());
25
- });
26
- globalExpect(a.playing()).toBe(false);
27
- });
28
- it("muted(true) sets muted to true", () => {
29
- let a;
30
- effectScope(() => {
31
- a = createMediaPlayer(new Audio());
32
- });
33
- a.muted(true);
34
- globalExpect(a.element.muted).toBe(true);
35
- });
36
- it("volume() clamps to [0, 1]", () => {
37
- let a;
38
- effectScope(() => {
39
- a = createMediaPlayer(new Audio());
40
- });
41
- a.volume(2);
42
- globalExpect(a.element.volume).toBe(1);
43
- a.volume(-1);
44
- globalExpect(a.element.volume).toBe(0);
45
- });
46
- it("removes event listeners when scope is disposed", () => {
47
- const removeSpy = vi.fn();
48
- const el = new Audio();
49
- let dispose;
50
- let a;
51
- dispose = effectScope(() => {
52
- a = createMediaPlayer(el);
53
- });
54
- vi.spyOn(a.element, "removeEventListener").mockImplementation(removeSpy);
55
- dispose();
56
- globalExpect(removeSpy).toHaveBeenCalled();
57
- });
58
- });
59
- describe("with <video>", () => {
60
- it("accepts an HTMLVideoElement", () => {
61
- const el = document.createElement("video");
62
- document.body.appendChild(el);
63
- let v;
64
- effectScope(() => {
65
- v = createMediaPlayer(el);
66
- });
67
- globalExpect(v.element).toBe(el);
68
- });
69
- it("starts as paused", () => {
70
- const el = document.createElement("video");
71
- document.body.appendChild(el);
72
- let v;
73
- effectScope(() => {
74
- v = createMediaPlayer(el);
75
- });
76
- globalExpect(v.playing()).toBe(false);
77
- });
78
- it("time(v) updates currentTime", () => {
79
- const el = document.createElement("video");
80
- document.body.appendChild(el);
81
- let v;
82
- effectScope(() => {
83
- v = createMediaPlayer(el);
84
- });
85
- v.time(30);
86
- globalExpect(el.currentTime).toBe(30);
87
- });
88
- it("removes event listeners when scope is disposed", () => {
89
- const el = document.createElement("video");
90
- document.body.appendChild(el);
91
- let dispose;
92
- dispose = effectScope(() => {
93
- createMediaPlayer(el);
94
- });
95
- const removeSpy = vi.spyOn(el, "removeEventListener");
96
- dispose();
97
- globalExpect(removeSpy).toHaveBeenCalled();
98
- });
99
- });
100
- });
101
- //#endregion
102
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,48 +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 { createMutationObserver } from "./mutation-observer.mjs";
6
- //#region src/utilities/mutation-observer.test.ts
7
- afterEach(() => {
8
- document.body.innerHTML = "";
9
- vi.unstubAllGlobals();
10
- });
11
- describe("createMutationObserver", () => {
12
- it("observes mutations on a target element", () => {
13
- const target = document.createElement("div");
14
- document.body.appendChild(target);
15
- let observeCount = 0;
16
- vi.stubGlobal("MutationObserver", function MockMO(cb) {
17
- return {
18
- observe: () => {
19
- observeCount++;
20
- },
21
- disconnect: vi.fn()
22
- };
23
- });
24
- effectScope(() => {
25
- createMutationObserver(target, { childList: true }, vi.fn());
26
- });
27
- globalExpect(observeCount).toBe(1);
28
- });
29
- it("disconnects on Symbol.dispose", () => {
30
- const target = document.createElement("div");
31
- document.body.appendChild(target);
32
- const disconnect = vi.fn();
33
- vi.stubGlobal("MutationObserver", function MockMO() {
34
- return {
35
- observe: vi.fn(),
36
- disconnect
37
- };
38
- });
39
- let mo;
40
- effectScope(() => {
41
- mo = createMutationObserver(target, { childList: true }, vi.fn());
42
- });
43
- mo[Symbol.dispose]();
44
- globalExpect(disconnect).toHaveBeenCalledOnce();
45
- });
46
- });
47
- //#endregion
48
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,30 +0,0 @@
1
- import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
2
- import { n as vi, t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
3
- import { online } from "./network.mjs";
4
- //#region src/utilities/network.test.ts
5
- afterEach(() => {
6
- vi.restoreAllMocks();
7
- });
8
- describe("online", () => {
9
- it("reflects navigator.onLine", () => {
10
- globalExpect(online()).toBe(navigator.onLine);
11
- });
12
- it("becomes false on offline event", () => {
13
- Object.defineProperty(navigator, "onLine", {
14
- configurable: true,
15
- get: () => false
16
- });
17
- window.dispatchEvent(new Event("offline"));
18
- globalExpect(online()).toBe(false);
19
- });
20
- it("becomes true on online event", () => {
21
- Object.defineProperty(navigator, "onLine", {
22
- configurable: true,
23
- get: () => true
24
- });
25
- window.dispatchEvent(new Event("online"));
26
- globalExpect(online()).toBe(true);
27
- });
28
- });
29
- //#endregion
30
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,45 +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 { onClickOutside } from "./on-click-outside.mjs";
6
- //#region src/utilities/on-click-outside.test.ts
7
- afterEach(() => {
8
- document.body.innerHTML = "";
9
- });
10
- describe("createOnClickOutside", () => {
11
- it("fires handler when clicking outside the target", () => {
12
- const inside = document.createElement("div");
13
- const outside = document.createElement("span");
14
- document.body.append(inside, outside);
15
- const handler = vi.fn();
16
- effectScope(() => {
17
- onClickOutside(inside, handler);
18
- });
19
- outside.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true }));
20
- globalExpect(handler).toHaveBeenCalledOnce();
21
- });
22
- it("does not fire handler when clicking inside the target", () => {
23
- const el = document.createElement("div");
24
- document.body.appendChild(el);
25
- const handler = vi.fn();
26
- effectScope(() => {
27
- onClickOutside(el, handler);
28
- });
29
- el.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true }));
30
- globalExpect(handler).not.toHaveBeenCalled();
31
- });
32
- it("does not fire after scope disposal", () => {
33
- const inside = document.createElement("div");
34
- const outside = document.createElement("span");
35
- document.body.append(inside, outside);
36
- const handler = vi.fn();
37
- effectScope(() => {
38
- onClickOutside(inside, handler);
39
- })();
40
- outside.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true }));
41
- globalExpect(handler).not.toHaveBeenCalled();
42
- });
43
- });
44
- //#endregion
45
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,90 +0,0 @@
1
- import { c as effectScope, m as signal } 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 { t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
5
- import { createPrevious } from "./previous.mjs";
6
- //#region src/utilities/previous.test.ts
7
- describe("createPrevious", () => {
8
- it("starts as undefined", () => {
9
- const s = signal(1);
10
- let p;
11
- effectScope(() => {
12
- p = createPrevious(s);
13
- });
14
- globalExpect(p()).toBeUndefined();
15
- });
16
- it("returns the previous value after a change", () => {
17
- const s = signal(1);
18
- let p;
19
- effectScope(() => {
20
- p = createPrevious(s);
21
- });
22
- s(2);
23
- globalExpect(p()).toBe(1);
24
- });
25
- it("tracks each successive previous value", () => {
26
- const s = signal("a");
27
- let p;
28
- effectScope(() => {
29
- p = createPrevious(s);
30
- });
31
- s("b");
32
- globalExpect(p()).toBe("a");
33
- s("c");
34
- globalExpect(p()).toBe("b");
35
- });
36
- it("does not update after scope disposal", () => {
37
- const s = signal(10);
38
- let p;
39
- const stop = effectScope(() => {
40
- p = createPrevious(s);
41
- });
42
- s(20);
43
- stop();
44
- s(30);
45
- globalExpect(p()).toBe(10);
46
- });
47
- });
48
- describe("createPrevious with isEqual (distinct mode)", () => {
49
- it("starts as undefined", () => {
50
- const s = signal(0);
51
- let prev;
52
- effectScope(() => {
53
- prev = createPrevious(s, Object.is);
54
- });
55
- globalExpect(prev()).toBeUndefined();
56
- });
57
- it("updates previous when value changes", () => {
58
- const s = signal(0);
59
- let prev;
60
- effectScope(() => {
61
- prev = createPrevious(s, Object.is);
62
- });
63
- s(1);
64
- globalExpect(prev()).toBe(0);
65
- });
66
- it("does not update previous when value is the same", () => {
67
- const s = signal(0);
68
- let prev;
69
- effectScope(() => {
70
- prev = createPrevious(s, Object.is);
71
- });
72
- s(1);
73
- globalExpect(prev()).toBe(0);
74
- s(1);
75
- globalExpect(prev()).toBe(0);
76
- });
77
- it("uses a custom equality function", () => {
78
- const s = signal({ id: 1 });
79
- let prev;
80
- effectScope(() => {
81
- prev = createPrevious(s, (a, b) => a.id === b.id);
82
- });
83
- s({ id: 1 });
84
- globalExpect(prev()).toBeUndefined();
85
- s({ id: 2 });
86
- globalExpect(prev()?.id).toBe(1);
87
- });
88
- });
89
- //#endregion
90
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,158 +0,0 @@
1
- import { s as effect } 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 { t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
5
- import { ReactivePromise, promise } from "./promise.mjs";
6
- //#region src/utilities/promise.test.ts
7
- describe("ReactivePromise", () => {
8
- it("starts in pending state", () => {
9
- const rp = new ReactivePromise(() => {});
10
- globalExpect(rp.state).toBe("pending");
11
- globalExpect(rp.value).toBeUndefined();
12
- globalExpect(rp.reason).toBeUndefined();
13
- globalExpect(rp.result).toBeUndefined();
14
- });
15
- it("transitions to fulfilled", async () => {
16
- const rp = new ReactivePromise((resolve) => resolve(42));
17
- await rp;
18
- globalExpect(rp.state).toBe("fulfilled");
19
- globalExpect(rp.value).toBe(42);
20
- globalExpect(rp.reason).toBeUndefined();
21
- globalExpect(rp.result).toBe(42);
22
- });
23
- it("transitions to rejected", async () => {
24
- const err = /* @__PURE__ */ new Error("fail");
25
- const rp = new ReactivePromise((_, reject) => reject(err));
26
- await rp.catch(() => {});
27
- globalExpect(rp.state).toBe("rejected");
28
- globalExpect(rp.reason).toBe(err);
29
- globalExpect(rp.value).toBeUndefined();
30
- globalExpect(rp.result).toBe(err);
31
- });
32
- it("unwraps a PromiseLike value", async () => {
33
- const rp = new ReactivePromise((resolve) => resolve(Promise.resolve(99)));
34
- await rp;
35
- globalExpect(rp.value).toBe(99);
36
- });
37
- it("state and value update atomically — no inconsistent intermediate state", async () => {
38
- const rp = new ReactivePromise((resolve) => resolve(7));
39
- const snapshots = [];
40
- const stop = effect(() => {
41
- snapshots.push({
42
- state: rp.state,
43
- value: rp.value
44
- });
45
- });
46
- await rp;
47
- stop();
48
- globalExpect(snapshots.find((s) => s.state === "fulfilled" && s.value === void 0)).toBeUndefined();
49
- globalExpect(snapshots.at(-1)).toEqual({
50
- state: "fulfilled",
51
- value: 7
52
- });
53
- });
54
- it("state and reason update atomically on rejection", async () => {
55
- const err = /* @__PURE__ */ new Error("oops");
56
- const rp = new ReactivePromise((_, reject) => reject(err));
57
- const snapshots = [];
58
- const stop = effect(() => {
59
- snapshots.push({
60
- state: rp.state,
61
- reason: rp.reason
62
- });
63
- });
64
- await rp.catch(() => {});
65
- stop();
66
- globalExpect(snapshots.find((s) => s.state === "rejected" && s.reason === void 0)).toBeUndefined();
67
- globalExpect(snapshots.at(-1)).toEqual({
68
- state: "rejected",
69
- reason: err
70
- });
71
- });
72
- it("ReactivePromise.from() wraps an existing Promise", async () => {
73
- const rp = ReactivePromise.from(Promise.resolve("hello"));
74
- await rp;
75
- globalExpect(rp.state).toBe("fulfilled");
76
- globalExpect(rp.value).toBe("hello");
77
- });
78
- });
79
- describe("promise()", () => {
80
- it("is instanceof ReactivePromise", () => {
81
- globalExpect(promise(() => {}) instanceof ReactivePromise).toBe(true);
82
- });
83
- it("returns undefined while pending", () => {
84
- const cp = promise(() => {});
85
- globalExpect(cp()).toBeUndefined();
86
- globalExpect(cp.state).toBe("pending");
87
- });
88
- it("returns the resolved value when fulfilled", async () => {
89
- const cp = promise((resolve) => resolve(42));
90
- await cp;
91
- globalExpect(cp()).toBe(42);
92
- });
93
- it("returns the rejection reason when rejected", async () => {
94
- const err = /* @__PURE__ */ new Error("fail");
95
- const cp = promise((_, reject) => reject(err));
96
- await cp.catch(() => {});
97
- globalExpect(cp()).toBe(err);
98
- });
99
- it("wraps an existing Promise", async () => {
100
- const cp = promise(Promise.resolve("hi"));
101
- await cp;
102
- globalExpect(cp()).toBe("hi");
103
- });
104
- it("passes through a ReactivePromise", async () => {
105
- const cp = promise(new ReactivePromise((resolve) => resolve(5)));
106
- await cp;
107
- globalExpect(cp()).toBe(5);
108
- });
109
- it("is awaitable — resolves to the fulfilled value", async () => {
110
- globalExpect(await promise((resolve) => resolve(100))).toBe(100);
111
- });
112
- it("is awaitable — rejects on failure", async () => {
113
- const err = /* @__PURE__ */ new Error("bad");
114
- const cp = promise((_, reject) => reject(err));
115
- let caught;
116
- await cp.catch((e) => {
117
- caught = e;
118
- });
119
- globalExpect(caught).toBe(err);
120
- });
121
- it("delegates .then()", async () => {
122
- globalExpect(await promise((resolve) => resolve(3)).then((v) => v * 2)).toBe(6);
123
- });
124
- it("delegates .catch()", async () => {
125
- const err = /* @__PURE__ */ new Error("caught");
126
- globalExpect(await promise((_, reject) => reject(err)).catch((e) => e)).toBe(err);
127
- });
128
- it("cp.catch handler runs on rejection", async () => {
129
- const err = /* @__PURE__ */ new Error("caught");
130
- const cp = promise((_, reject) => reject(err));
131
- const caught = [];
132
- await cp.catch((e) => caught.push(e));
133
- globalExpect(caught).toEqual([err]);
134
- });
135
- it("is reactive — effect reruns on fulfillment", async () => {
136
- const cp = promise((resolve) => resolve(1));
137
- const values = [];
138
- const stop = effect(() => {
139
- values.push(cp.value);
140
- });
141
- await cp;
142
- stop();
143
- globalExpect(values).toEqual([void 0, 1]);
144
- });
145
- it("is reactive — effect reruns on rejection", async () => {
146
- const err = /* @__PURE__ */ new Error("x");
147
- const cp = promise((_, reject) => reject(err));
148
- const results = [];
149
- const stop = effect(() => {
150
- results.push(cp());
151
- });
152
- await cp.catch(() => {});
153
- stop();
154
- globalExpect(results).toEqual([void 0, err]);
155
- });
156
- });
157
- //#endregion
158
- export {};
@@ -1 +0,0 @@
1
- export { };