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,115 +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 { async } from "./async.mjs";
|
|
6
|
-
import { createInterval } from "./interval.mjs";
|
|
7
|
-
//#region src/utilities/interval.test.ts
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
document.body.innerHTML = "";
|
|
10
|
-
vi.useRealTimers();
|
|
11
|
-
});
|
|
12
|
-
describe("createInterval", () => {
|
|
13
|
-
it("calls callback on each tick", () => {
|
|
14
|
-
vi.useFakeTimers();
|
|
15
|
-
const cb = vi.fn();
|
|
16
|
-
effectScope(() => {
|
|
17
|
-
createInterval(cb, 100);
|
|
18
|
-
});
|
|
19
|
-
vi.advanceTimersByTime(350);
|
|
20
|
-
globalExpect(cb).toHaveBeenCalledTimes(3);
|
|
21
|
-
});
|
|
22
|
-
it("stop() pauses the interval", () => {
|
|
23
|
-
vi.useFakeTimers();
|
|
24
|
-
const cb = vi.fn();
|
|
25
|
-
let iv;
|
|
26
|
-
effectScope(() => {
|
|
27
|
-
iv = createInterval(cb, 100);
|
|
28
|
-
});
|
|
29
|
-
iv.stop();
|
|
30
|
-
vi.advanceTimersByTime(500);
|
|
31
|
-
globalExpect(cb).toHaveBeenCalledTimes(0);
|
|
32
|
-
globalExpect(iv.pending()).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
it("start() resumes after stop", () => {
|
|
35
|
-
vi.useFakeTimers();
|
|
36
|
-
const cb = vi.fn();
|
|
37
|
-
let iv;
|
|
38
|
-
effectScope(() => {
|
|
39
|
-
iv = createInterval(cb, 100);
|
|
40
|
-
});
|
|
41
|
-
iv.stop();
|
|
42
|
-
iv.start();
|
|
43
|
-
vi.advanceTimersByTime(250);
|
|
44
|
-
globalExpect(cb).toHaveBeenCalledTimes(2);
|
|
45
|
-
});
|
|
46
|
-
it("reset() restarts the interval", () => {
|
|
47
|
-
vi.useFakeTimers();
|
|
48
|
-
const cb = vi.fn();
|
|
49
|
-
let iv;
|
|
50
|
-
effectScope(() => {
|
|
51
|
-
iv = createInterval(cb, 100);
|
|
52
|
-
});
|
|
53
|
-
vi.advanceTimersByTime(50);
|
|
54
|
-
iv.reset();
|
|
55
|
-
vi.advanceTimersByTime(100);
|
|
56
|
-
globalExpect(cb).toHaveBeenCalledTimes(1);
|
|
57
|
-
});
|
|
58
|
-
it("Symbol.dispose cleans up", () => {
|
|
59
|
-
vi.useFakeTimers();
|
|
60
|
-
const cb = vi.fn();
|
|
61
|
-
let iv;
|
|
62
|
-
effectScope(() => {
|
|
63
|
-
iv = createInterval(cb, 100);
|
|
64
|
-
});
|
|
65
|
-
iv[Symbol.dispose]();
|
|
66
|
-
vi.advanceTimersByTime(500);
|
|
67
|
-
globalExpect(cb).toHaveBeenCalledTimes(0);
|
|
68
|
-
});
|
|
69
|
-
it("no-callback form updates timestamp on each tick", () => {
|
|
70
|
-
vi.useFakeTimers();
|
|
71
|
-
let iv;
|
|
72
|
-
effectScope(() => {
|
|
73
|
-
iv = createInterval(100);
|
|
74
|
-
});
|
|
75
|
-
const before = iv.timestamp();
|
|
76
|
-
vi.advanceTimersByTime(100);
|
|
77
|
-
globalExpect(iv.timestamp()).toBeGreaterThan(before);
|
|
78
|
-
});
|
|
79
|
-
it("dynamic delay form is called each tick", () => {
|
|
80
|
-
vi.useFakeTimers();
|
|
81
|
-
const cb = vi.fn();
|
|
82
|
-
const getDelay = vi.fn().mockReturnValue(100);
|
|
83
|
-
effectScope(() => {
|
|
84
|
-
createInterval(cb, getDelay);
|
|
85
|
-
});
|
|
86
|
-
vi.advanceTimersByTime(300);
|
|
87
|
-
globalExpect(cb).toHaveBeenCalledTimes(3);
|
|
88
|
-
});
|
|
89
|
-
it("stops when scope is disposed", () => {
|
|
90
|
-
vi.useFakeTimers();
|
|
91
|
-
const cb = vi.fn();
|
|
92
|
-
effectScope(() => {
|
|
93
|
-
createInterval(cb, 100);
|
|
94
|
-
})();
|
|
95
|
-
vi.advanceTimersByTime(500);
|
|
96
|
-
globalExpect(cb).toHaveBeenCalledTimes(0);
|
|
97
|
-
});
|
|
98
|
-
it("composes with async() — reruns on each tick", async () => {
|
|
99
|
-
vi.useFakeTimers();
|
|
100
|
-
const asyncOp = async;
|
|
101
|
-
let runCount = 0;
|
|
102
|
-
const timer = createInterval(100);
|
|
103
|
-
const op = asyncOp(() => {
|
|
104
|
-
timer.timestamp();
|
|
105
|
-
runCount++;
|
|
106
|
-
return Promise.resolve(runCount);
|
|
107
|
-
}).start();
|
|
108
|
-
await vi.advanceTimersByTimeAsync(350);
|
|
109
|
-
globalExpect(runCount).toBeGreaterThan(1);
|
|
110
|
-
timer[Symbol.dispose]();
|
|
111
|
-
op.stop();
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
//#endregion
|
|
115
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -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 { };
|