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.
- package/README.md +14 -0
- package/dist/await.d.mts +53 -0
- package/dist/await.mjs +70 -0
- package/dist/custom-elements.d.mts +1 -1
- package/dist/{element-xQwq4ulc.mjs → element-D3om9yA6.mjs} +71 -4
- package/dist/for.d.mts +20 -26
- package/dist/for.mjs +29 -4
- package/dist/fragment-ROPRBJQd.mjs +61 -0
- package/dist/hydrate/index.d.mts +41 -0
- package/dist/hydrate/index.mjs +2 -0
- package/dist/hydrate-6Qx4n4Su.mjs +380 -0
- package/dist/integrations/astro-client.d.mts +17 -0
- package/dist/integrations/astro-client.mjs +23 -0
- package/dist/integrations/astro-server.d.mts +15 -0
- package/dist/integrations/astro-server.mjs +39 -0
- package/dist/integrations/astro-slots.d.mts +12 -0
- package/dist/integrations/astro-slots.mjs +30 -0
- package/dist/integrations/astro.d.mts +46 -0
- package/dist/integrations/astro.mjs +64 -0
- package/dist/integrations/react.d.mts +1 -1
- package/dist/integrations/react.mjs +2 -2
- package/dist/jsx-runtime/index.d.mts +1 -1
- package/dist/jsx-runtime/index.mjs +2 -20
- package/dist/{lib-Dkc7cV5F.mjs → lib-DYypKhxk.mjs} +63 -5
- package/dist/render.mjs +1 -1
- package/dist/{scope-CnEvL9Nd.mjs → scope-zbEG299F.mjs} +1 -1
- package/dist/server/index.d.mts +43 -0
- package/dist/server/index.mjs +2 -0
- package/dist/server-iFSng50i.mjs +385 -0
- package/dist/signals/index.d.mts +2 -2
- package/dist/signals/index.mjs +5 -3
- package/dist/{slot-B8y0aEoz.d.mts → slot-BFWXeFRl.d.mts} +6 -0
- package/dist/{slot-Cne__au7.mjs → slot-Dvf30O0B.mjs} +12 -1
- package/dist/slot.d.mts +1 -1
- package/dist/slot.mjs +1 -1
- package/dist/{infer-B7T5hi_D.d.mts → types-ncUK9rki.d.mts} +140 -141
- package/dist/ui/overlay/index.css +70 -0
- package/dist/ui/overlay/index.d.mts +209 -0
- package/dist/ui/overlay/index.mjs +1001 -0
- package/dist/ui/overlay/overlay.css +332 -0
- package/dist/utilities/_observe.mjs +1 -1
- package/dist/utilities/active-element.d.mts +1 -1
- package/dist/utilities/active-element.mjs +1 -1
- package/dist/utilities/async.d.mts +19 -2
- package/dist/utilities/async.mjs +49 -2
- package/dist/utilities/context.mjs +1 -1
- package/dist/utilities/debounced.d.mts +1 -1
- package/dist/utilities/debounced.mjs +1 -1
- package/dist/utilities/dom-lifecycle.bench.mjs +3255 -1
- package/dist/utilities/dom-lifecycle.mjs +1 -1
- package/dist/utilities/element-rect.d.mts +1 -1
- package/dist/utilities/element-rect.mjs +1 -1
- package/dist/utilities/element-scroll.d.mts +1 -1
- package/dist/utilities/event-driven.d.mts +1 -1
- package/dist/utilities/event-driven.mjs +1 -1
- package/dist/utilities/event-listener.d.mts +1 -1
- package/dist/utilities/event-listener.mjs +1 -1
- package/dist/utilities/focus-within.d.mts +1 -1
- package/dist/utilities/focus-within.mjs +1 -1
- package/dist/utilities/form-object.d.mts +96 -0
- package/dist/utilities/form-object.mjs +285 -0
- package/dist/utilities/hover.d.mts +1 -1
- package/dist/utilities/hover.mjs +1 -1
- package/dist/utilities/interval.d.mts +1 -1
- package/dist/utilities/interval.mjs +1 -1
- package/dist/utilities/location.d.mts +1 -1
- package/dist/utilities/location.mjs +1 -1
- package/dist/utilities/media-devices.d.mts +1 -1
- package/dist/utilities/media-devices.mjs +1 -1
- package/dist/utilities/media-player.d.mts +1 -1
- package/dist/utilities/media-query.d.mts +1 -1
- package/dist/utilities/media-query.mjs +1 -1
- package/dist/utilities/network.d.mts +1 -1
- package/dist/utilities/network.mjs +1 -1
- package/dist/utilities/orientation.d.mts +1 -1
- package/dist/utilities/orientation.mjs +1 -1
- package/dist/utilities/previous.d.mts +1 -1
- package/dist/utilities/previous.mjs +1 -1
- package/dist/utilities/promise.d.mts +19 -2
- package/dist/utilities/promise.mjs +33 -3
- package/dist/utilities/retry.mjs +1 -1
- package/dist/utilities/routing.d.mts +1 -1
- package/dist/utilities/routing.mjs +1 -1
- package/dist/utilities/search-params.d.mts +1 -1
- package/dist/utilities/storage.d.mts +1 -1
- package/dist/utilities/throttled.d.mts +1 -1
- package/dist/utilities/throttled.mjs +1 -1
- package/dist/utilities/timeout.d.mts +1 -1
- package/dist/utilities/timeout.mjs +1 -1
- package/dist/utilities/window-focus.d.mts +1 -1
- package/dist/utilities/window-focus.mjs +1 -1
- package/dist/utilities/window-size.d.mts +1 -1
- package/dist/utilities/window-size.mjs +1 -1
- package/package.json +20 -5
- package/dist/benchmark.CX_oY03V-CSLAXL5f.mjs +0 -5145
- package/dist/magic-string.es-CXefOmkB.mjs +0 -1011
- package/dist/test.BmQO5GaM-Ddz9cDxc.mjs +0 -8266
- package/dist/utilities/active-element.test.d.mts +0 -1
- package/dist/utilities/active-element.test.mjs +0 -25
- package/dist/utilities/async.test.d.mts +0 -1
- package/dist/utilities/async.test.mjs +0 -275
- package/dist/utilities/context.test.d.mts +0 -1
- package/dist/utilities/context.test.mjs +0 -171
- package/dist/utilities/debounced.test.d.mts +0 -1
- package/dist/utilities/debounced.test.mjs +0 -68
- package/dist/utilities/dom-lifecycle.test.d.mts +0 -1
- package/dist/utilities/dom-lifecycle.test.mjs +0 -228
- package/dist/utilities/element-rect.test.d.mts +0 -1
- package/dist/utilities/element-rect.test.mjs +0 -101
- package/dist/utilities/element-scroll.test.d.mts +0 -1
- package/dist/utilities/element-scroll.test.mjs +0 -27
- package/dist/utilities/event-listener.test.d.mts +0 -1
- package/dist/utilities/event-listener.test.mjs +0 -60
- package/dist/utilities/focus-within.test.d.mts +0 -1
- package/dist/utilities/focus-within.test.mjs +0 -51
- package/dist/utilities/hover.test.d.mts +0 -1
- package/dist/utilities/hover.test.mjs +0 -54
- package/dist/utilities/intersection-observer.test.d.mts +0 -1
- package/dist/utilities/intersection-observer.test.mjs +0 -46
- package/dist/utilities/interval.test.d.mts +0 -1
- package/dist/utilities/interval.test.mjs +0 -115
- package/dist/utilities/location.test.d.mts +0 -1
- package/dist/utilities/location.test.mjs +0 -61
- package/dist/utilities/long-press.test.d.mts +0 -1
- package/dist/utilities/long-press.test.mjs +0 -54
- package/dist/utilities/media-devices.test.d.mts +0 -1
- package/dist/utilities/media-devices.test.mjs +0 -44
- package/dist/utilities/media-player.test.d.mts +0 -1
- package/dist/utilities/media-player.test.mjs +0 -102
- package/dist/utilities/mutation-observer.test.d.mts +0 -1
- package/dist/utilities/mutation-observer.test.mjs +0 -48
- package/dist/utilities/network.test.d.mts +0 -1
- package/dist/utilities/network.test.mjs +0 -30
- package/dist/utilities/on-click-outside.test.d.mts +0 -1
- package/dist/utilities/on-click-outside.test.mjs +0 -45
- package/dist/utilities/previous.test.d.mts +0 -1
- package/dist/utilities/previous.test.mjs +0 -90
- package/dist/utilities/promise.test.d.mts +0 -1
- package/dist/utilities/promise.test.mjs +0 -158
- package/dist/utilities/retry.test.d.mts +0 -1
- package/dist/utilities/retry.test.mjs +0 -85
- package/dist/utilities/routing.test.d.mts +0 -1
- package/dist/utilities/routing.test.mjs +0 -129
- package/dist/utilities/search-params.test.d.mts +0 -1
- package/dist/utilities/search-params.test.mjs +0 -37
- package/dist/utilities/ssr.test.d.mts +0 -1
- package/dist/utilities/ssr.test.mjs +0 -65
- package/dist/utilities/storage.test.d.mts +0 -1
- package/dist/utilities/storage.test.mjs +0 -139
- package/dist/utilities/throttled.test.d.mts +0 -1
- package/dist/utilities/throttled.test.mjs +0 -58
- package/dist/utilities/timeout.test.d.mts +0 -1
- package/dist/utilities/timeout.test.mjs +0 -121
- package/dist/utilities/window-size.test.d.mts +0 -1
- package/dist/utilities/window-size.test.mjs +0 -43
- /package/dist/{custom-elements-D5CgfNKc.d.mts → custom-elements-DK5VUcWA.d.mts} +0 -0
|
@@ -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 { };
|
|
@@ -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 {};
|