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,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 { };