elements-kit 0.18.2 → 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 (156) 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.css +70 -0
  38. package/dist/ui/overlay/index.d.mts +209 -0
  39. package/dist/ui/overlay/index.mjs +1001 -0
  40. package/dist/ui/overlay/overlay.css +332 -0
  41. package/dist/utilities/_observe.mjs +1 -1
  42. package/dist/utilities/active-element.d.mts +1 -1
  43. package/dist/utilities/active-element.mjs +1 -1
  44. package/dist/utilities/async.d.mts +19 -2
  45. package/dist/utilities/async.mjs +49 -2
  46. package/dist/utilities/context.mjs +1 -1
  47. package/dist/utilities/debounced.d.mts +1 -1
  48. package/dist/utilities/debounced.mjs +1 -1
  49. package/dist/utilities/dom-lifecycle.bench.mjs +3255 -1
  50. package/dist/utilities/dom-lifecycle.mjs +1 -1
  51. package/dist/utilities/element-rect.d.mts +1 -1
  52. package/dist/utilities/element-rect.mjs +1 -1
  53. package/dist/utilities/element-scroll.d.mts +1 -1
  54. package/dist/utilities/event-driven.d.mts +1 -1
  55. package/dist/utilities/event-driven.mjs +1 -1
  56. package/dist/utilities/event-listener.d.mts +1 -1
  57. package/dist/utilities/event-listener.mjs +1 -1
  58. package/dist/utilities/focus-within.d.mts +1 -1
  59. package/dist/utilities/focus-within.mjs +1 -1
  60. package/dist/utilities/form-object.d.mts +96 -0
  61. package/dist/utilities/form-object.mjs +285 -0
  62. package/dist/utilities/hover.d.mts +1 -1
  63. package/dist/utilities/hover.mjs +1 -1
  64. package/dist/utilities/interval.d.mts +1 -1
  65. package/dist/utilities/interval.mjs +1 -1
  66. package/dist/utilities/location.d.mts +1 -1
  67. package/dist/utilities/location.mjs +1 -1
  68. package/dist/utilities/media-devices.d.mts +1 -1
  69. package/dist/utilities/media-devices.mjs +1 -1
  70. package/dist/utilities/media-player.d.mts +1 -1
  71. package/dist/utilities/media-query.d.mts +1 -1
  72. package/dist/utilities/media-query.mjs +1 -1
  73. package/dist/utilities/network.d.mts +1 -1
  74. package/dist/utilities/network.mjs +1 -1
  75. package/dist/utilities/orientation.d.mts +1 -1
  76. package/dist/utilities/orientation.mjs +1 -1
  77. package/dist/utilities/previous.d.mts +1 -1
  78. package/dist/utilities/previous.mjs +1 -1
  79. package/dist/utilities/promise.d.mts +19 -2
  80. package/dist/utilities/promise.mjs +33 -3
  81. package/dist/utilities/retry.mjs +1 -1
  82. package/dist/utilities/routing.d.mts +1 -1
  83. package/dist/utilities/routing.mjs +1 -1
  84. package/dist/utilities/search-params.d.mts +1 -1
  85. package/dist/utilities/storage.d.mts +1 -1
  86. package/dist/utilities/throttled.d.mts +1 -1
  87. package/dist/utilities/throttled.mjs +1 -1
  88. package/dist/utilities/timeout.d.mts +1 -1
  89. package/dist/utilities/timeout.mjs +1 -1
  90. package/dist/utilities/window-focus.d.mts +1 -1
  91. package/dist/utilities/window-focus.mjs +1 -1
  92. package/dist/utilities/window-size.d.mts +1 -1
  93. package/dist/utilities/window-size.mjs +1 -1
  94. package/package.json +20 -5
  95. package/dist/benchmark.CX_oY03V-CSLAXL5f.mjs +0 -5145
  96. package/dist/magic-string.es-CXefOmkB.mjs +0 -1011
  97. package/dist/test.BmQO5GaM-Ddz9cDxc.mjs +0 -8266
  98. package/dist/utilities/active-element.test.d.mts +0 -1
  99. package/dist/utilities/active-element.test.mjs +0 -25
  100. package/dist/utilities/async.test.d.mts +0 -1
  101. package/dist/utilities/async.test.mjs +0 -275
  102. package/dist/utilities/context.test.d.mts +0 -1
  103. package/dist/utilities/context.test.mjs +0 -171
  104. package/dist/utilities/debounced.test.d.mts +0 -1
  105. package/dist/utilities/debounced.test.mjs +0 -68
  106. package/dist/utilities/dom-lifecycle.test.d.mts +0 -1
  107. package/dist/utilities/dom-lifecycle.test.mjs +0 -228
  108. package/dist/utilities/element-rect.test.d.mts +0 -1
  109. package/dist/utilities/element-rect.test.mjs +0 -101
  110. package/dist/utilities/element-scroll.test.d.mts +0 -1
  111. package/dist/utilities/element-scroll.test.mjs +0 -27
  112. package/dist/utilities/event-listener.test.d.mts +0 -1
  113. package/dist/utilities/event-listener.test.mjs +0 -60
  114. package/dist/utilities/focus-within.test.d.mts +0 -1
  115. package/dist/utilities/focus-within.test.mjs +0 -51
  116. package/dist/utilities/hover.test.d.mts +0 -1
  117. package/dist/utilities/hover.test.mjs +0 -54
  118. package/dist/utilities/intersection-observer.test.d.mts +0 -1
  119. package/dist/utilities/intersection-observer.test.mjs +0 -46
  120. package/dist/utilities/interval.test.d.mts +0 -1
  121. package/dist/utilities/interval.test.mjs +0 -115
  122. package/dist/utilities/location.test.d.mts +0 -1
  123. package/dist/utilities/location.test.mjs +0 -61
  124. package/dist/utilities/long-press.test.d.mts +0 -1
  125. package/dist/utilities/long-press.test.mjs +0 -54
  126. package/dist/utilities/media-devices.test.d.mts +0 -1
  127. package/dist/utilities/media-devices.test.mjs +0 -44
  128. package/dist/utilities/media-player.test.d.mts +0 -1
  129. package/dist/utilities/media-player.test.mjs +0 -102
  130. package/dist/utilities/mutation-observer.test.d.mts +0 -1
  131. package/dist/utilities/mutation-observer.test.mjs +0 -48
  132. package/dist/utilities/network.test.d.mts +0 -1
  133. package/dist/utilities/network.test.mjs +0 -30
  134. package/dist/utilities/on-click-outside.test.d.mts +0 -1
  135. package/dist/utilities/on-click-outside.test.mjs +0 -45
  136. package/dist/utilities/previous.test.d.mts +0 -1
  137. package/dist/utilities/previous.test.mjs +0 -90
  138. package/dist/utilities/promise.test.d.mts +0 -1
  139. package/dist/utilities/promise.test.mjs +0 -158
  140. package/dist/utilities/retry.test.d.mts +0 -1
  141. package/dist/utilities/retry.test.mjs +0 -85
  142. package/dist/utilities/routing.test.d.mts +0 -1
  143. package/dist/utilities/routing.test.mjs +0 -129
  144. package/dist/utilities/search-params.test.d.mts +0 -1
  145. package/dist/utilities/search-params.test.mjs +0 -37
  146. package/dist/utilities/ssr.test.d.mts +0 -1
  147. package/dist/utilities/ssr.test.mjs +0 -65
  148. package/dist/utilities/storage.test.d.mts +0 -1
  149. package/dist/utilities/storage.test.mjs +0 -139
  150. package/dist/utilities/throttled.test.d.mts +0 -1
  151. package/dist/utilities/throttled.test.mjs +0 -58
  152. package/dist/utilities/timeout.test.d.mts +0 -1
  153. package/dist/utilities/timeout.test.mjs +0 -121
  154. package/dist/utilities/window-size.test.d.mts +0 -1
  155. package/dist/utilities/window-size.test.mjs +0 -43
  156. /package/dist/{custom-elements-D5CgfNKc.d.mts → custom-elements-DK5VUcWA.d.mts} +0 -0
@@ -1,228 +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 { DomLifecycleElement } from "./dom-lifecycle.mjs";
4
- //#region src/utilities/dom-lifecycle.test.ts
5
- afterEach(() => {
6
- document.body.innerHTML = "";
7
- });
8
- function makeProbe() {
9
- return document.createElement("dom-lifecycle");
10
- }
11
- describe("dom-lifecycle", () => {
12
- it("registers as a custom element", () => {
13
- globalExpect(customElements.get("dom-lifecycle")).toBe(DomLifecycleElement);
14
- globalExpect(makeProbe()).toBeInstanceOf(DomLifecycleElement);
15
- });
16
- it("fires onConnect with self; self.parentElement is the surrounding element", () => {
17
- const parent = document.createElement("div");
18
- document.body.appendChild(parent);
19
- const probe = makeProbe();
20
- const onConnect = vi.fn();
21
- probe.onConnect = onConnect;
22
- parent.appendChild(probe);
23
- globalExpect(onConnect).toHaveBeenCalledTimes(1);
24
- globalExpect(onConnect).toHaveBeenCalledWith(probe);
25
- globalExpect(probe.parentElement).toBe(parent);
26
- });
27
- it("does not fire onConnect when appended into a detached subtree", () => {
28
- const parent = document.createElement("div");
29
- const probe = makeProbe();
30
- const onConnect = vi.fn();
31
- probe.onConnect = onConnect;
32
- parent.appendChild(probe);
33
- globalExpect(onConnect).not.toHaveBeenCalled();
34
- document.body.appendChild(parent);
35
- globalExpect(onConnect).toHaveBeenCalledTimes(1);
36
- globalExpect(onConnect).toHaveBeenCalledWith(probe);
37
- });
38
- it("fires onDisconnect with self; self.parentElement is null per spec", () => {
39
- const parent = document.createElement("div");
40
- document.body.appendChild(parent);
41
- const probe = makeProbe();
42
- const onDisconnect = vi.fn((self) => {
43
- globalExpect(self.parentElement).toBeNull();
44
- });
45
- probe.onDisconnect = onDisconnect;
46
- parent.appendChild(probe);
47
- probe.remove();
48
- globalExpect(onDisconnect).toHaveBeenCalledTimes(1);
49
- globalExpect(onDisconnect).toHaveBeenCalledWith(probe);
50
- });
51
- it("re-fires onConnect on reconnect", () => {
52
- const parent = document.createElement("div");
53
- document.body.appendChild(parent);
54
- const probe = makeProbe();
55
- const onConnect = vi.fn();
56
- const onDisconnect = vi.fn();
57
- probe.onConnect = onConnect;
58
- probe.onDisconnect = onDisconnect;
59
- parent.appendChild(probe);
60
- probe.remove();
61
- parent.appendChild(probe);
62
- globalExpect(onConnect).toHaveBeenCalledTimes(2);
63
- globalExpect(onDisconnect).toHaveBeenCalledTimes(1);
64
- });
65
- it("self.parentElement reflects the new parent on cross-parent move", () => {
66
- const a = document.createElement("section");
67
- const b = document.createElement("section");
68
- document.body.appendChild(a);
69
- document.body.appendChild(b);
70
- const probe = makeProbe();
71
- const seen = [];
72
- probe.onConnect = (el) => seen.push(["c", el.parentElement]);
73
- probe.onDisconnect = (el) => seen.push(["d", el.parentElement]);
74
- a.appendChild(probe);
75
- b.appendChild(probe);
76
- globalExpect(seen).toEqual([
77
- ["c", a],
78
- ["d", null],
79
- ["c", b]
80
- ]);
81
- });
82
- it("works inside an open shadow root", () => {
83
- const host = document.createElement("div");
84
- const shadow = host.attachShadow({ mode: "open" });
85
- document.body.appendChild(host);
86
- const inner = document.createElement("div");
87
- shadow.appendChild(inner);
88
- const probe = makeProbe();
89
- const onConnect = vi.fn((el) => {
90
- globalExpect(el.parentElement).toBe(inner);
91
- });
92
- probe.onConnect = onConnect;
93
- inner.appendChild(probe);
94
- globalExpect(onConnect).toHaveBeenCalledTimes(1);
95
- globalExpect(onConnect).toHaveBeenCalledWith(probe);
96
- });
97
- it("works inside a closed shadow root (no opt-in needed)", () => {
98
- const host = document.createElement("div");
99
- const shadow = host.attachShadow({ mode: "closed" });
100
- document.body.appendChild(host);
101
- const inner = document.createElement("div");
102
- shadow.appendChild(inner);
103
- const probe = makeProbe();
104
- const onConnect = vi.fn();
105
- const onDisconnect = vi.fn();
106
- probe.onConnect = onConnect;
107
- probe.onDisconnect = onDisconnect;
108
- inner.appendChild(probe);
109
- globalExpect(onConnect).toHaveBeenCalledTimes(1);
110
- globalExpect(onConnect).toHaveBeenCalledWith(probe);
111
- inner.remove();
112
- globalExpect(onDisconnect).toHaveBeenCalledTimes(1);
113
- globalExpect(onDisconnect).toHaveBeenCalledWith(probe);
114
- });
115
- it("self is non-null when the lifecycle element is the direct child of a ShadowRoot", () => {
116
- const host = document.createElement("div");
117
- const shadow = host.attachShadow({ mode: "open" });
118
- document.body.appendChild(host);
119
- const probe = makeProbe();
120
- let observedSelf = null;
121
- let observedParent = null;
122
- let observedHost = null;
123
- probe.onConnect = (el) => {
124
- observedSelf = el;
125
- observedParent = el.parentElement;
126
- const root = el.getRootNode();
127
- observedHost = root instanceof ShadowRoot ? root.host : null;
128
- };
129
- shadow.appendChild(probe);
130
- globalExpect(observedSelf).toBe(probe);
131
- globalExpect(observedParent).toBeNull();
132
- globalExpect(observedHost).toBe(host);
133
- });
134
- it("wrap-children: self.firstElementChild is the wrapped subtree", () => {
135
- const parent = document.createElement("section");
136
- document.body.appendChild(parent);
137
- const probe = makeProbe();
138
- const wrapped = document.createElement("h1");
139
- probe.appendChild(wrapped);
140
- let observedFirstChild = null;
141
- probe.onConnect = (el) => {
142
- observedFirstChild = el.firstElementChild;
143
- };
144
- parent.appendChild(probe);
145
- globalExpect(observedFirstChild).toBe(wrapped);
146
- });
147
- it("fires when a host with an inner dom-lifecycle is connected later", () => {
148
- const parent = document.createElement("div");
149
- const probe = makeProbe();
150
- const onConnect = vi.fn();
151
- probe.onConnect = onConnect;
152
- parent.appendChild(probe);
153
- globalExpect(onConnect).not.toHaveBeenCalled();
154
- document.body.appendChild(parent);
155
- globalExpect(onConnect).toHaveBeenCalledTimes(1);
156
- globalExpect(onConnect).toHaveBeenCalledWith(probe);
157
- });
158
- it("upgrades when produced via innerHTML and connected", () => {
159
- const parent = document.createElement("div");
160
- document.body.appendChild(parent);
161
- parent.innerHTML = "<dom-lifecycle></dom-lifecycle>";
162
- const probe = parent.firstElementChild;
163
- globalExpect(probe).toBeInstanceOf(DomLifecycleElement);
164
- const onConnect = vi.fn();
165
- probe.onConnect = onConnect;
166
- probe.remove();
167
- parent.appendChild(probe);
168
- globalExpect(onConnect).toHaveBeenCalledTimes(1);
169
- globalExpect(onConnect).toHaveBeenCalledWith(probe);
170
- });
171
- it("survives cloneNode(true) — clone fires its own connect", () => {
172
- const parent = document.createElement("div");
173
- document.body.appendChild(parent);
174
- const original = makeProbe();
175
- parent.appendChild(original);
176
- const clone = original.cloneNode(true);
177
- const onConnect = vi.fn();
178
- clone.onConnect = onConnect;
179
- parent.appendChild(clone);
180
- globalExpect(onConnect).toHaveBeenCalledTimes(1);
181
- globalExpect(onConnect).toHaveBeenCalledWith(clone);
182
- });
183
- it("honors null onConnect / onDisconnect (no throw)", () => {
184
- const parent = document.createElement("div");
185
- document.body.appendChild(parent);
186
- const probe = makeProbe();
187
- probe.onConnect = null;
188
- probe.onDisconnect = null;
189
- globalExpect(() => {
190
- parent.appendChild(probe);
191
- probe.remove();
192
- }).not.toThrow();
193
- });
194
- it("applies render-inert defaults: display:contents and role='none'", () => {
195
- const probe = makeProbe();
196
- document.body.appendChild(probe);
197
- globalExpect(probe.style.display).toBe("contents");
198
- globalExpect(probe.getAttribute("role")).toBe("none");
199
- });
200
- it("exposes onMove and onAdopted setters", () => {
201
- const probe = makeProbe();
202
- const move = vi.fn();
203
- const adopt = vi.fn();
204
- probe.onMove = move;
205
- probe.onAdopted = adopt;
206
- globalExpect(probe.onMove).toBe(move);
207
- globalExpect(probe.onAdopted).toBe(adopt);
208
- probe.onMove = null;
209
- probe.onAdopted = null;
210
- globalExpect(probe.onMove).toBeNull();
211
- globalExpect(probe.onAdopted).toBeNull();
212
- });
213
- it("disconnects when an ancestor is removed", () => {
214
- const grand = document.createElement("section");
215
- const parent = document.createElement("div");
216
- document.body.appendChild(grand);
217
- grand.appendChild(parent);
218
- const probe = makeProbe();
219
- const onDisconnect = vi.fn();
220
- probe.onDisconnect = onDisconnect;
221
- parent.appendChild(probe);
222
- grand.remove();
223
- globalExpect(onDisconnect).toHaveBeenCalledTimes(1);
224
- globalExpect(onDisconnect).toHaveBeenCalledWith(probe);
225
- });
226
- });
227
- //#endregion
228
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,101 +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 { createElementRect } from "./element-rect.mjs";
6
- //#region src/utilities/element-rect.test.ts
7
- afterEach(() => {
8
- document.body.innerHTML = "";
9
- vi.restoreAllMocks();
10
- vi.unstubAllGlobals();
11
- });
12
- describe("createElementRect", () => {
13
- it("returns initial rect values from getBoundingClientRect", () => {
14
- const el = document.createElement("div");
15
- document.body.appendChild(el);
16
- vi.spyOn(el, "getBoundingClientRect").mockReturnValue({
17
- x: 10,
18
- y: 20,
19
- width: 100,
20
- height: 50,
21
- top: 20,
22
- right: 110,
23
- bottom: 70,
24
- left: 10,
25
- toJSON: () => ({})
26
- });
27
- let rect;
28
- effectScope(() => {
29
- rect = createElementRect(el);
30
- });
31
- globalExpect(rect.x()).toBe(10);
32
- globalExpect(rect.y()).toBe(20);
33
- globalExpect(rect.width()).toBe(100);
34
- globalExpect(rect.height()).toBe(50);
35
- globalExpect(rect.top()).toBe(20);
36
- globalExpect(rect.right()).toBe(110);
37
- globalExpect(rect.bottom()).toBe(70);
38
- globalExpect(rect.left()).toBe(10);
39
- });
40
- it("updates all rect properties when ResizeObserver fires", () => {
41
- const el = document.createElement("div");
42
- document.body.appendChild(el);
43
- vi.spyOn(el, "getBoundingClientRect").mockReturnValueOnce({
44
- x: 0,
45
- y: 0,
46
- width: 0,
47
- height: 0,
48
- top: 0,
49
- right: 0,
50
- bottom: 0,
51
- left: 0,
52
- toJSON: () => ({})
53
- }).mockReturnValueOnce({
54
- x: 5,
55
- y: 15,
56
- width: 200,
57
- height: 80,
58
- top: 15,
59
- right: 205,
60
- bottom: 95,
61
- left: 5,
62
- toJSON: () => ({})
63
- });
64
- let observerCallback;
65
- vi.stubGlobal("ResizeObserver", function MockRO(cb) {
66
- observerCallback = cb;
67
- return {
68
- observe: vi.fn(),
69
- disconnect: vi.fn(),
70
- unobserve: vi.fn()
71
- };
72
- });
73
- let rect;
74
- effectScope(() => {
75
- rect = createElementRect(el);
76
- });
77
- observerCallback([{ target: el }], {});
78
- globalExpect(rect.width()).toBe(200);
79
- globalExpect(rect.height()).toBe(80);
80
- globalExpect(rect.top()).toBe(15);
81
- });
82
- it("disconnects on Symbol.dispose", () => {
83
- const disconnect = vi.fn();
84
- vi.stubGlobal("ResizeObserver", function MockRO() {
85
- return {
86
- observe: vi.fn(),
87
- disconnect,
88
- unobserve: vi.fn()
89
- };
90
- });
91
- const el = document.createElement("div");
92
- let rect;
93
- effectScope(() => {
94
- rect = createElementRect(el);
95
- });
96
- rect[Symbol.dispose]();
97
- globalExpect(disconnect).toHaveBeenCalledOnce();
98
- });
99
- });
100
- //#endregion
101
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,27 +0,0 @@
1
- import { c as effectScope } 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 { createElementScroll } from "./element-scroll.mjs";
6
- //#region src/utilities/element-scroll.test.ts
7
- describe("createElementScroll", () => {
8
- it("starts at 0,0 for a new element", () => {
9
- const el = document.createElement("div");
10
- let scroll;
11
- effectScope(() => {
12
- scroll = createElementScroll(el);
13
- });
14
- globalExpect(scroll.x()).toBe(0);
15
- globalExpect(scroll.y()).toBe(0);
16
- });
17
- it("cleans up on dispose", () => {
18
- const el = document.createElement("div");
19
- let scroll;
20
- effectScope(() => {
21
- scroll = createElementScroll(el);
22
- });
23
- scroll[Symbol.dispose]();
24
- });
25
- });
26
- //#endregion
27
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,60 +0,0 @@
1
- import { c as effectScope, m as signal, s as effect } from "../lib-Dkc7cV5F.mjs";
2
- import "../signals/index.mjs";
3
- import { on } from "./event-listener.mjs";
4
- import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CSLAXL5f.mjs";
5
- import { n as vi, t as globalExpect } from "../test.BmQO5GaM-Ddz9cDxc.mjs";
6
- //#region src/utilities/event-listener.test.ts
7
- afterEach(() => {
8
- document.body.innerHTML = "";
9
- });
10
- describe("createEventListener", () => {
11
- it("fires the handler when the event is dispatched", () => {
12
- const el = document.createElement("div");
13
- document.body.appendChild(el);
14
- const handler = vi.fn();
15
- effect(() => {
16
- on(el, "click", handler);
17
- });
18
- el.dispatchEvent(new MouseEvent("click", { bubbles: true }));
19
- globalExpect(handler).toHaveBeenCalledOnce();
20
- });
21
- it("removes the listener when the enclosing effect is disposed", () => {
22
- const el = document.createElement("div");
23
- document.body.appendChild(el);
24
- const handler = vi.fn();
25
- effect(() => {
26
- on(el, "click", handler);
27
- })();
28
- el.dispatchEvent(new MouseEvent("click", { bubbles: true }));
29
- globalExpect(handler).not.toHaveBeenCalled();
30
- });
31
- it("removes the listener when the enclosing scope is disposed", () => {
32
- const el = document.createElement("div");
33
- document.body.appendChild(el);
34
- const handler = vi.fn();
35
- effectScope(() => {
36
- on(el, "click", handler);
37
- })();
38
- el.dispatchEvent(new MouseEvent("click", { bubbles: true }));
39
- globalExpect(handler).not.toHaveBeenCalled();
40
- });
41
- it("re-registers the listener when a reactive target changes", () => {
42
- const el1 = document.createElement("div");
43
- const el2 = document.createElement("div");
44
- document.body.append(el1, el2);
45
- const target = signal(el1);
46
- const handler = vi.fn();
47
- effectScope(() => {
48
- on(() => target(), "click", handler);
49
- });
50
- el1.dispatchEvent(new MouseEvent("click"));
51
- globalExpect(handler).toHaveBeenCalledTimes(1);
52
- target(el2);
53
- el1.dispatchEvent(new MouseEvent("click"));
54
- globalExpect(handler).toHaveBeenCalledTimes(1);
55
- el2.dispatchEvent(new MouseEvent("click"));
56
- globalExpect(handler).toHaveBeenCalledTimes(2);
57
- });
58
- });
59
- //#endregion
60
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,51 +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 { createFocusWithin } from "./focus-within.mjs";
6
- //#region src/utilities/focus-within.test.ts
7
- afterEach(() => {
8
- document.body.innerHTML = "";
9
- });
10
- describe("createFocusWithin", () => {
11
- it("starts as false", () => {
12
- const el = document.createElement("div");
13
- document.body.appendChild(el);
14
- let focused;
15
- effectScope(() => {
16
- focused = createFocusWithin(el);
17
- });
18
- globalExpect(focused()).toBe(false);
19
- });
20
- it("becomes true when a child receives focus", () => {
21
- const outer = document.createElement("div");
22
- const inner = document.createElement("input");
23
- outer.appendChild(inner);
24
- document.body.appendChild(outer);
25
- let focused;
26
- effectScope(() => {
27
- focused = createFocusWithin(outer);
28
- });
29
- document.dispatchEvent(new FocusEvent("focusin", {
30
- bubbles: true,
31
- relatedTarget: inner
32
- }));
33
- Object.defineProperty(document, "activeElement", {
34
- configurable: true,
35
- get: () => inner
36
- });
37
- outer.dispatchEvent(new FocusEvent("focusin", { bubbles: true }));
38
- globalExpect(typeof focused()).toBe("boolean");
39
- });
40
- it("stops reacting after scope disposal", () => {
41
- const el = document.createElement("div");
42
- document.body.appendChild(el);
43
- let focused;
44
- effectScope(() => {
45
- focused = createFocusWithin(el);
46
- })();
47
- globalExpect(focused()).toBe(false);
48
- });
49
- });
50
- //#endregion
51
- 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 { createHover } from "./hover.mjs";
6
- //#region src/utilities/hover.test.ts
7
- afterEach(() => {
8
- document.body.innerHTML = "";
9
- vi.restoreAllMocks();
10
- });
11
- describe("createHover", () => {
12
- it("starts as false", () => {
13
- const el = document.createElement("div");
14
- document.body.appendChild(el);
15
- let hovered;
16
- effectScope(() => {
17
- hovered = createHover(el);
18
- });
19
- globalExpect(hovered()).toBe(false);
20
- });
21
- it("becomes true on pointerenter", () => {
22
- const el = document.createElement("div");
23
- document.body.appendChild(el);
24
- let hovered;
25
- effectScope(() => {
26
- hovered = createHover(el);
27
- });
28
- el.dispatchEvent(new PointerEvent("pointerenter"));
29
- globalExpect(hovered()).toBe(true);
30
- });
31
- it("becomes false on pointerleave", () => {
32
- const el = document.createElement("div");
33
- document.body.appendChild(el);
34
- let hovered;
35
- effectScope(() => {
36
- hovered = createHover(el);
37
- });
38
- el.dispatchEvent(new PointerEvent("pointerenter"));
39
- el.dispatchEvent(new PointerEvent("pointerleave"));
40
- globalExpect(hovered()).toBe(false);
41
- });
42
- it("removes listeners on scope disposal", () => {
43
- const el = document.createElement("div");
44
- document.body.appendChild(el);
45
- let hovered;
46
- effectScope(() => {
47
- hovered = createHover(el);
48
- })();
49
- el.dispatchEvent(new PointerEvent("pointerenter"));
50
- globalExpect(hovered()).toBe(false);
51
- });
52
- });
53
- //#endregion
54
- export {};
@@ -1 +0,0 @@
1
- export { };
@@ -1,46 +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 { createIntersectionObserver } from "./intersection-observer.mjs";
6
- //#region src/utilities/intersection-observer.test.ts
7
- afterEach(() => {
8
- document.body.innerHTML = "";
9
- vi.unstubAllGlobals();
10
- });
11
- describe("createIntersectionObserver", () => {
12
- it("observes a target element", () => {
13
- const target = document.createElement("div");
14
- document.body.appendChild(target);
15
- const observe = vi.fn();
16
- vi.stubGlobal("IntersectionObserver", function MockIO() {
17
- return {
18
- observe,
19
- disconnect: vi.fn()
20
- };
21
- });
22
- effectScope(() => {
23
- createIntersectionObserver(target, vi.fn());
24
- });
25
- globalExpect(observe).toHaveBeenCalledWith(target);
26
- });
27
- it("disconnects on Symbol.dispose", () => {
28
- const target = document.createElement("div");
29
- document.body.appendChild(target);
30
- const disconnect = vi.fn();
31
- vi.stubGlobal("IntersectionObserver", function MockIO() {
32
- return {
33
- observe: vi.fn(),
34
- disconnect
35
- };
36
- });
37
- let io;
38
- effectScope(() => {
39
- io = createIntersectionObserver(target, vi.fn());
40
- });
41
- io[Symbol.dispose]();
42
- globalExpect(disconnect).toHaveBeenCalledOnce();
43
- });
44
- });
45
- //#endregion
46
- export {};
@@ -1 +0,0 @@
1
- export { };