elements-kit 0.0.14 → 0.0.16
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 +138 -31
- package/dist/attributes-Dtn68R1u.d.mts +94 -0
- package/dist/attributes.d.mts +1 -93
- package/dist/custom-elements.d.mts +74 -0
- package/dist/custom-elements.mjs +100 -0
- package/dist/define-CjbTZ3VG.d.mts +23 -0
- package/dist/{element-C_4VbkvQ.mjs → element-CGVy_8TW.mjs} +12 -18
- package/dist/for.d.mts +45 -0
- package/dist/for.mjs +136 -0
- package/dist/{index-DUshSQ_6.d.mts → index-DydGTqZU.d.mts} +60 -10
- package/dist/index.d.mts +1 -36
- package/dist/index.mjs +1 -144
- package/dist/infer-BfzRJoCn.d.mts +203 -0
- package/dist/integrations/react.d.mts +1 -1
- package/dist/integrations/react.mjs +1 -1
- package/dist/jsx-runtime/index.d.mts +18 -25
- package/dist/jsx-runtime/index.mjs +2 -2
- package/dist/signals/index.d.mts +2 -2
- package/dist/signals/index.mjs +2 -2
- package/dist/{signals-BHmWX6ox.mjs → signals-J8dK_rA4.mjs} +57 -17
- package/dist/slot-C7GQZe-r.d.mts +104 -0
- package/dist/{slot-Cydy7-0L.mjs → slot-Kb61AcgW.mjs} +21 -2
- package/dist/slot.d.mts +2 -84
- package/dist/slot.mjs +2 -2
- package/dist/{test.BmQO5GaM-ANkhHvbr.mjs → test.BmQO5GaM-DfGStnii.mjs} +1 -1
- package/dist/utilities/_observe.d.mts +11 -0
- package/dist/utilities/_observe.mjs +15 -0
- package/dist/utilities/active-element.d.mts +1 -1
- package/dist/utilities/active-element.mjs +6 -2
- package/dist/utilities/active-element.test.mjs +1 -1
- package/dist/utilities/async.d.mts +1 -1
- package/dist/utilities/async.mjs +1 -1
- package/dist/utilities/async.test.mjs +2 -2
- package/dist/utilities/debounced.d.mts +1 -1
- package/dist/utilities/debounced.mjs +1 -1
- package/dist/utilities/debounced.test.mjs +2 -2
- package/dist/utilities/element-rect.d.mts +1 -1
- package/dist/utilities/element-rect.mjs +1 -1
- package/dist/utilities/element-rect.test.mjs +2 -2
- package/dist/utilities/element-scroll.d.mts +1 -1
- package/dist/utilities/element-scroll.mjs +7 -34
- package/dist/utilities/element-scroll.test.mjs +2 -2
- package/dist/utilities/environment.d.mts +5 -0
- package/dist/utilities/environment.mjs +5 -0
- package/dist/utilities/event-driven.d.mts +1 -1
- package/dist/utilities/event-driven.mjs +2 -2
- package/dist/utilities/event-listener.d.mts +1 -1
- package/dist/utilities/event-listener.mjs +1 -1
- package/dist/utilities/event-listener.test.mjs +2 -2
- package/dist/utilities/focus-within.d.mts +1 -1
- package/dist/utilities/focus-within.mjs +1 -1
- package/dist/utilities/focus-within.test.mjs +2 -2
- package/dist/utilities/hover.d.mts +1 -1
- package/dist/utilities/hover.mjs +1 -1
- package/dist/utilities/hover.test.mjs +2 -2
- package/dist/utilities/intersection-observer.mjs +4 -6
- package/dist/utilities/intersection-observer.test.mjs +2 -2
- package/dist/utilities/interval.d.mts +1 -1
- package/dist/utilities/interval.mjs +1 -1
- package/dist/utilities/interval.test.mjs +18 -2
- package/dist/utilities/location.d.mts +2 -14
- package/dist/utilities/location.mjs +12 -3
- package/dist/utilities/location.test.mjs +5 -5
- package/dist/utilities/long-press.mjs +1 -1
- package/dist/utilities/long-press.test.mjs +2 -2
- package/dist/utilities/media-devices.d.mts +1 -1
- package/dist/utilities/media-devices.mjs +1 -1
- package/dist/utilities/media-devices.test.mjs +2 -2
- package/dist/utilities/media-player.d.mts +1 -1
- package/dist/utilities/media-player.test.mjs +2 -2
- package/dist/utilities/media-query.d.mts +2 -3
- package/dist/utilities/media-query.mjs +3 -3
- package/dist/utilities/mutation-observer.mjs +4 -7
- package/dist/utilities/mutation-observer.test.mjs +2 -2
- package/dist/utilities/network.d.mts +2 -2
- package/dist/utilities/network.mjs +5 -3
- package/dist/utilities/network.test.mjs +1 -1
- package/dist/utilities/on-click-outside.test.mjs +2 -2
- package/dist/utilities/orientation.d.mts +1 -1
- package/dist/utilities/orientation.mjs +9 -1
- package/dist/utilities/previous.d.mts +1 -1
- package/dist/utilities/previous.mjs +1 -1
- package/dist/utilities/previous.test.mjs +2 -2
- package/dist/utilities/promise.d.mts +1 -1
- package/dist/utilities/promise.mjs +1 -1
- package/dist/utilities/promise.test.mjs +2 -2
- package/dist/utilities/resize-observer.mjs +4 -6
- package/dist/utilities/retry.mjs +1 -1
- package/dist/utilities/retry.test.mjs +2 -2
- package/dist/utilities/routing.d.mts +1 -1
- package/dist/utilities/routing.mjs +1 -1
- package/dist/utilities/routing.test.mjs +1 -1
- package/dist/utilities/search-params.d.mts +1 -1
- package/dist/utilities/search-params.test.mjs +2 -2
- package/dist/utilities/ssr.test.d.mts +1 -0
- package/dist/utilities/ssr.test.mjs +64 -0
- package/dist/utilities/storage.d.mts +1 -1
- package/dist/utilities/storage.test.mjs +2 -2
- package/dist/utilities/throttled.d.mts +1 -1
- package/dist/utilities/throttled.mjs +1 -1
- package/dist/utilities/throttled.test.mjs +2 -2
- package/dist/utilities/timeout.d.mts +1 -1
- package/dist/utilities/timeout.mjs +1 -1
- package/dist/utilities/timeout.test.mjs +57 -2
- package/dist/utilities/window-focus.d.mts +2 -2
- package/dist/utilities/window-focus.mjs +5 -3
- package/dist/utilities/window-size.d.mts +1 -1
- package/dist/utilities/window-size.mjs +10 -5
- package/dist/utilities/window-size.test.mjs +1 -1
- package/package.json +11 -1
- package/dist/lib-JA05lzCN.d.mts +0 -4
- /package/dist/{polyfill-DR5XVnh_.d.mts → polyfill-BVNd6ogU.d.mts} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { f as effectScope } from "../signals-J8dK_rA4.mjs";
|
|
2
|
+
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
3
3
|
import { createMediaPlayer } from "./media-player.mjs";
|
|
4
4
|
//#region src/utilities/media-player.test.ts
|
|
5
5
|
afterEach(() => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { t as Computed } from "../index-
|
|
1
|
+
import { t as Computed } from "../index-DydGTqZU.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/utilities/media-query.d.ts
|
|
4
|
-
declare const isBrowser: boolean;
|
|
5
4
|
/**
|
|
6
5
|
* Creates a signal that tracks a CSS media query.
|
|
7
6
|
*
|
|
@@ -11,4 +10,4 @@ declare const isBrowser: boolean;
|
|
|
11
10
|
*/
|
|
12
11
|
declare function createMediaQuery(query: string, defaultState?: boolean): Computed<boolean>;
|
|
13
12
|
//#endregion
|
|
14
|
-
export { createMediaQuery
|
|
13
|
+
export { createMediaQuery };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v as signal } from "../signals-J8dK_rA4.mjs";
|
|
2
2
|
import { fromEvent, sync } from "./event-driven.mjs";
|
|
3
|
+
import { isBrowser } from "./environment.mjs";
|
|
3
4
|
//#region src/utilities/media-query.ts
|
|
4
|
-
const isBrowser = typeof window !== "undefined";
|
|
5
5
|
/**
|
|
6
6
|
* Creates a signal that tracks a CSS media query.
|
|
7
7
|
*
|
|
@@ -16,4 +16,4 @@ function createMediaQuery(query, defaultState) {
|
|
|
16
16
|
return state;
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
|
-
export { createMediaQuery
|
|
19
|
+
export { createMediaQuery };
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { observe } from "./_observe.mjs";
|
|
2
2
|
//#region src/utilities/mutation-observer.ts
|
|
3
3
|
/**
|
|
4
4
|
* Watches `target` for DOM mutations and calls `callback` with each batch of
|
|
5
5
|
* `MutationRecord`s.
|
|
6
6
|
*/
|
|
7
7
|
function createMutationObserver(target, options, callback) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const cleanup = () => observer.disconnect();
|
|
12
|
-
onCleanup(cleanup);
|
|
13
|
-
return { [Symbol.dispose]: cleanup };
|
|
8
|
+
return observe(new MutationObserver((records) => callback(records)), (o) => {
|
|
9
|
+
if (target) o.observe(target, options);
|
|
10
|
+
});
|
|
14
11
|
}
|
|
15
12
|
//#endregion
|
|
16
13
|
export { createMutationObserver };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { f as effectScope } from "../signals-J8dK_rA4.mjs";
|
|
2
|
+
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
3
3
|
import { createMutationObserver } from "./mutation-observer.mjs";
|
|
4
4
|
//#region src/utilities/mutation-observer.test.ts
|
|
5
5
|
afterEach(() => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as Computed } from "../index-
|
|
1
|
+
import { t as Computed } from "../index-DydGTqZU.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/utilities/network.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Singleton `Computed<boolean>` — `true` when `navigator.onLine` is true.
|
|
6
|
-
* Reacts to `online` / `offline` window events.
|
|
6
|
+
* Reacts to `online` / `offline` window events. Outside a browser, always `true`.
|
|
7
7
|
*/
|
|
8
8
|
declare const online: Computed<boolean>;
|
|
9
9
|
//#endregion
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v as signal } from "../signals-J8dK_rA4.mjs";
|
|
2
2
|
import { on } from "./event-listener.mjs";
|
|
3
|
+
import { isBrowser } from "./environment.mjs";
|
|
3
4
|
//#region src/utilities/network.ts
|
|
4
5
|
function createOnline() {
|
|
5
|
-
|
|
6
|
+
if (!isBrowser) return signal(true);
|
|
7
|
+
const value = signal(navigator.onLine);
|
|
6
8
|
const update = () => value(navigator.onLine);
|
|
7
9
|
on(window, "online", update);
|
|
8
10
|
on(window, "offline", update);
|
|
@@ -10,7 +12,7 @@ function createOnline() {
|
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* Singleton `Computed<boolean>` — `true` when `navigator.onLine` is true.
|
|
13
|
-
* Reacts to `online` / `offline` window events.
|
|
15
|
+
* Reacts to `online` / `offline` window events. Outside a browser, always `true`.
|
|
14
16
|
*/
|
|
15
17
|
const online = createOnline();
|
|
16
18
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
2
2
|
import { online } from "./network.mjs";
|
|
3
3
|
//#region src/utilities/network.test.ts
|
|
4
4
|
afterEach(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { f as effectScope } from "../signals-J8dK_rA4.mjs";
|
|
2
|
+
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
3
3
|
import { onClickOutside } from "./on-click-outside.mjs";
|
|
4
4
|
//#region src/utilities/on-click-outside.test.ts
|
|
5
5
|
afterEach(() => {
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
import { u as computed } from "../signals-J8dK_rA4.mjs";
|
|
1
2
|
import { fromEvent, sync } from "./event-driven.mjs";
|
|
3
|
+
import { isBrowser } from "./environment.mjs";
|
|
2
4
|
//#region src/utilities/orientation.ts
|
|
3
5
|
/**
|
|
4
|
-
* Returns reactive signals for the screen orientation.
|
|
6
|
+
* Returns reactive signals for the screen orientation. Outside a browser,
|
|
7
|
+
* returns `{ angle: 0, type: "portrait-primary" }` and a no-op disposer.
|
|
5
8
|
*/
|
|
6
9
|
function createOrientation() {
|
|
10
|
+
if (!isBrowser) return {
|
|
11
|
+
angle: computed(() => 0),
|
|
12
|
+
type: computed(() => "portrait-primary"),
|
|
13
|
+
[Symbol.dispose]() {}
|
|
14
|
+
};
|
|
7
15
|
const subscribe = fromEvent(screen.orientation, "change");
|
|
8
16
|
const [angle, stopAngle] = sync(subscribe, () => screen.orientation?.angle ?? 0);
|
|
9
17
|
const [type, stopType] = sync(subscribe, () => screen.orientation?.type ?? "portrait-primary");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { o as describe, s as it, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { f as effectScope, v as signal } from "../signals-J8dK_rA4.mjs";
|
|
2
|
+
import { o as describe, s as it, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
3
3
|
import { createPrevious } from "./previous.mjs";
|
|
4
4
|
//#region src/utilities/previous.test.ts
|
|
5
5
|
describe("createPrevious", () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as batch, u as computed, v as signal } from "../signals-J8dK_rA4.mjs";
|
|
2
2
|
//#region src/utilities/promise.ts
|
|
3
3
|
/**
|
|
4
4
|
* A `Promise` subclass that exposes its state as reactive signals.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { o as describe, s as it, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { d as effect } from "../signals-J8dK_rA4.mjs";
|
|
2
|
+
import { o as describe, s as it, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
3
3
|
import { ReactivePromise, promise } from "./promise.mjs";
|
|
4
4
|
//#region src/utilities/promise.test.ts
|
|
5
5
|
describe("ReactivePromise", () => {
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { observe } from "./_observe.mjs";
|
|
2
2
|
//#region src/utilities/resize-observer.ts
|
|
3
3
|
/**
|
|
4
4
|
* Raw `ResizeObserver` wrapper with automatic cleanup.
|
|
5
5
|
* Use `createElementRect` for the common case.
|
|
6
6
|
*/
|
|
7
7
|
function createResizeObserver(target, callback) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
onCleanup(cleanup);
|
|
12
|
-
return { [Symbol.dispose]: cleanup };
|
|
8
|
+
return observe(new ResizeObserver(callback), (o) => {
|
|
9
|
+
if (target) o.observe(target);
|
|
10
|
+
});
|
|
13
11
|
}
|
|
14
12
|
//#endregion
|
|
15
13
|
export { createResizeObserver };
|
package/dist/utilities/retry.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as vi, o as describe, s as it, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { _ as onCleanup } from "../signals-J8dK_rA4.mjs";
|
|
2
|
+
import { n as vi, o as describe, s as it, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
3
3
|
import { retry } from "./retry.mjs";
|
|
4
4
|
//#region src/utilities/retry.test.ts
|
|
5
5
|
describe("retry", () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as beforeAll, n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { i as beforeAll, n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
2
2
|
import { isLocalNavigationEvent, match, matches, navigate, patchHistory } from "./routing.mjs";
|
|
3
3
|
//#region src/utilities/routing.test.ts
|
|
4
4
|
beforeAll(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { f as effectScope } from "../signals-J8dK_rA4.mjs";
|
|
2
|
+
import { o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
3
3
|
import { createSearchParam } from "./search-params.mjs";
|
|
4
4
|
//#region src/utilities/search-params.test.ts
|
|
5
5
|
afterEach(() => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { c as test, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
2
|
+
//#region src/utilities/ssr.test.ts
|
|
3
|
+
// @vitest-environment node
|
|
4
|
+
test.each([
|
|
5
|
+
"./active-element.ts",
|
|
6
|
+
"./async.ts",
|
|
7
|
+
"./debounced.ts",
|
|
8
|
+
"./element-rect.ts",
|
|
9
|
+
"./element-scroll.ts",
|
|
10
|
+
"./environment.ts",
|
|
11
|
+
"./event-driven.ts",
|
|
12
|
+
"./event-listener.ts",
|
|
13
|
+
"./focus-within.ts",
|
|
14
|
+
"./hover.ts",
|
|
15
|
+
"./intersection-observer.ts",
|
|
16
|
+
"./interval.ts",
|
|
17
|
+
"./location.ts",
|
|
18
|
+
"./long-press.ts",
|
|
19
|
+
"./media-devices.ts",
|
|
20
|
+
"./media-player.ts",
|
|
21
|
+
"./media-query.ts",
|
|
22
|
+
"./mutation-observer.ts",
|
|
23
|
+
"./network.ts",
|
|
24
|
+
"./on-click-outside.ts",
|
|
25
|
+
"./orientation.ts",
|
|
26
|
+
"./previous.ts",
|
|
27
|
+
"./promise.ts",
|
|
28
|
+
"./resize-observer.ts",
|
|
29
|
+
"./retry.ts",
|
|
30
|
+
"./routing.ts",
|
|
31
|
+
"./search-params.ts",
|
|
32
|
+
"./storage.ts",
|
|
33
|
+
"./throttled.ts",
|
|
34
|
+
"./timeout.ts",
|
|
35
|
+
"./window-focus.ts",
|
|
36
|
+
"./window-size.ts"
|
|
37
|
+
])("imports %s in Node without crashing", async (path) => {
|
|
38
|
+
await globalExpect(import(path)).resolves.toBeDefined();
|
|
39
|
+
});
|
|
40
|
+
test("singletons return neutral values in Node", async () => {
|
|
41
|
+
const { windowSize } = await import("./window-size.mjs");
|
|
42
|
+
globalExpect(windowSize.width()).toBe(0);
|
|
43
|
+
globalExpect(windowSize.height()).toBe(0);
|
|
44
|
+
const { online } = await import("./network.mjs");
|
|
45
|
+
globalExpect(online()).toBe(true);
|
|
46
|
+
const { windowFocused } = await import("./window-focus.mjs");
|
|
47
|
+
globalExpect(windowFocused()).toBe(true);
|
|
48
|
+
const { activeElement } = await import("./active-element.mjs");
|
|
49
|
+
globalExpect(activeElement()).toBe(null);
|
|
50
|
+
const { orientation } = await import("./orientation.mjs");
|
|
51
|
+
globalExpect(orientation.angle()).toBe(0);
|
|
52
|
+
globalExpect(orientation.type()).toBe("portrait-primary");
|
|
53
|
+
const { currentLocation } = await import("./location.mjs");
|
|
54
|
+
globalExpect(currentLocation.href()).toBe("");
|
|
55
|
+
globalExpect(currentLocation.pathname()).toBe("");
|
|
56
|
+
globalExpect(currentLocation.search()).toBe("");
|
|
57
|
+
globalExpect(currentLocation.hash()).toBe("");
|
|
58
|
+
});
|
|
59
|
+
test("isBrowser is false in Node", async () => {
|
|
60
|
+
const { isBrowser } = await import("./environment.mjs");
|
|
61
|
+
globalExpect(isBrowser).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
//#endregion
|
|
64
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { f as effectScope } from "../signals-J8dK_rA4.mjs";
|
|
2
|
+
import { o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
3
3
|
import { createLocalStorage, createSessionStorage } from "./storage.mjs";
|
|
4
4
|
//#region src/utilities/storage.test.ts
|
|
5
5
|
describe("createLocalStorage", () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as beforeEach, n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { f as effectScope, v as signal } from "../signals-J8dK_rA4.mjs";
|
|
2
|
+
import { a as beforeEach, n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
3
3
|
import { createThrottled } from "./throttled.mjs";
|
|
4
4
|
//#region src/utilities/throttled.test.ts
|
|
5
5
|
beforeEach(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { f as effectScope } from "../signals-J8dK_rA4.mjs";
|
|
2
|
+
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
3
3
|
import { createTimeout } from "./timeout.mjs";
|
|
4
4
|
//#region src/utilities/timeout.test.ts
|
|
5
5
|
afterEach(() => {
|
|
@@ -59,6 +59,61 @@ describe("createTimeout", () => {
|
|
|
59
59
|
vi.advanceTimersByTime(300);
|
|
60
60
|
globalExpect(cb).toHaveBeenCalledOnce();
|
|
61
61
|
});
|
|
62
|
+
it("immediate=false does not start automatically", () => {
|
|
63
|
+
vi.useFakeTimers();
|
|
64
|
+
const cb = vi.fn();
|
|
65
|
+
let t;
|
|
66
|
+
effectScope(() => {
|
|
67
|
+
t = createTimeout(cb, 200, false);
|
|
68
|
+
});
|
|
69
|
+
globalExpect(t.pending()).toBe(false);
|
|
70
|
+
vi.advanceTimersByTime(300);
|
|
71
|
+
globalExpect(cb).not.toHaveBeenCalled();
|
|
72
|
+
});
|
|
73
|
+
it("start() fires after delay when called manually", () => {
|
|
74
|
+
vi.useFakeTimers();
|
|
75
|
+
const cb = vi.fn();
|
|
76
|
+
let t;
|
|
77
|
+
effectScope(() => {
|
|
78
|
+
t = createTimeout(cb, 200, false);
|
|
79
|
+
});
|
|
80
|
+
t.start();
|
|
81
|
+
globalExpect(t.pending()).toBe(true);
|
|
82
|
+
vi.advanceTimersByTime(200);
|
|
83
|
+
globalExpect(cb).toHaveBeenCalledOnce();
|
|
84
|
+
globalExpect(t.pending()).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
it("Symbol.dispose cancels the timeout", () => {
|
|
87
|
+
vi.useFakeTimers();
|
|
88
|
+
const cb = vi.fn();
|
|
89
|
+
let t;
|
|
90
|
+
effectScope(() => {
|
|
91
|
+
t = createTimeout(cb, 500);
|
|
92
|
+
});
|
|
93
|
+
t[Symbol.dispose]();
|
|
94
|
+
vi.advanceTimersByTime(1e3);
|
|
95
|
+
globalExpect(cb).not.toHaveBeenCalled();
|
|
96
|
+
});
|
|
97
|
+
it("stops when scope is disposed", () => {
|
|
98
|
+
vi.useFakeTimers();
|
|
99
|
+
const cb = vi.fn();
|
|
100
|
+
effectScope(() => {
|
|
101
|
+
createTimeout(cb, 200);
|
|
102
|
+
})();
|
|
103
|
+
vi.advanceTimersByTime(500);
|
|
104
|
+
globalExpect(cb).not.toHaveBeenCalled();
|
|
105
|
+
});
|
|
106
|
+
it("dynamic delay function is called at start", () => {
|
|
107
|
+
vi.useFakeTimers();
|
|
108
|
+
const cb = vi.fn();
|
|
109
|
+
const getDelay = vi.fn().mockReturnValue(300);
|
|
110
|
+
effectScope(() => {
|
|
111
|
+
createTimeout(cb, getDelay);
|
|
112
|
+
});
|
|
113
|
+
vi.advanceTimersByTime(300);
|
|
114
|
+
globalExpect(cb).toHaveBeenCalledOnce();
|
|
115
|
+
globalExpect(getDelay).toHaveBeenCalledOnce();
|
|
116
|
+
});
|
|
62
117
|
});
|
|
63
118
|
//#endregion
|
|
64
119
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as Computed } from "../index-
|
|
1
|
+
import { t as Computed } from "../index-DydGTqZU.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/utilities/window-focus.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Singleton `Computed<boolean>` — `true` while the browser window has focus.
|
|
6
|
-
* Reacts to `focus` / `blur` window events.
|
|
6
|
+
* Reacts to `focus` / `blur` window events. Outside a browser, always `true`.
|
|
7
7
|
*/
|
|
8
8
|
declare const windowFocused: Computed<boolean>;
|
|
9
9
|
//#endregion
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v as signal } from "../signals-J8dK_rA4.mjs";
|
|
2
2
|
import { on } from "./event-listener.mjs";
|
|
3
|
+
import { isBrowser } from "./environment.mjs";
|
|
3
4
|
//#region src/utilities/window-focus.ts
|
|
4
5
|
function createWindowFocused() {
|
|
5
|
-
|
|
6
|
+
if (!isBrowser) return signal(true);
|
|
7
|
+
const value = signal(document.hasFocus());
|
|
6
8
|
on(window, "focus", () => value(true));
|
|
7
9
|
on(window, "blur", () => value(false));
|
|
8
10
|
return value;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* Singleton `Computed<boolean>` — `true` while the browser window has focus.
|
|
12
|
-
* Reacts to `focus` / `blur` window events.
|
|
14
|
+
* Reacts to `focus` / `blur` window events. Outside a browser, always `true`.
|
|
13
15
|
*/
|
|
14
16
|
const windowFocused = createWindowFocused();
|
|
15
17
|
//#endregion
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { u as computed } from "../signals-J8dK_rA4.mjs";
|
|
2
2
|
import { fromEvent, sync } from "./event-driven.mjs";
|
|
3
|
+
import { isBrowser } from "./environment.mjs";
|
|
3
4
|
//#region src/utilities/window-size.ts
|
|
4
5
|
/**
|
|
5
6
|
* Returns reactive `width` and `height` signals tracking the browser window
|
|
6
|
-
* inner dimensions.
|
|
7
|
+
* inner dimensions. Outside a browser, returns zeros and a no-op disposer.
|
|
7
8
|
*/
|
|
8
9
|
function createWindowSize() {
|
|
9
|
-
|
|
10
|
+
if (!isBrowser) return {
|
|
11
|
+
width: computed(() => 0),
|
|
12
|
+
height: computed(() => 0),
|
|
13
|
+
[Symbol.dispose]() {}
|
|
14
|
+
};
|
|
10
15
|
const [size, stop] = sync(fromEvent(window, "resize"), () => ({
|
|
11
|
-
w:
|
|
12
|
-
h:
|
|
16
|
+
w: window.innerWidth,
|
|
17
|
+
h: window.innerHeight
|
|
13
18
|
}));
|
|
14
19
|
return {
|
|
15
20
|
width: computed(() => size().w),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as describe, s as it, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { o as describe, s as it, t as globalExpect } from "../test.BmQO5GaM-DfGStnii.mjs";
|
|
2
2
|
import { windowSize } from "./window-size.mjs";
|
|
3
3
|
//#region src/utilities/window-size.test.ts
|
|
4
4
|
describe("windowSize (singleton)", () => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elements-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.16",
|
|
5
5
|
"description": "A lightweight reactive UI library that transforms native HTMLElements into reactive components with signals. Ideal for framework-agnostic applications and web components.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"webcomponents",
|
|
@@ -38,11 +38,21 @@
|
|
|
38
38
|
"import": "./dist/slot.mjs",
|
|
39
39
|
"types": "./dist/slot.d.ts"
|
|
40
40
|
},
|
|
41
|
+
"./for": {
|
|
42
|
+
"source": "./src/for.ts",
|
|
43
|
+
"import": "./dist/for.mjs",
|
|
44
|
+
"types": "./dist/for.d.ts"
|
|
45
|
+
},
|
|
41
46
|
"./attributes": {
|
|
42
47
|
"source": "./src/attributes.ts",
|
|
43
48
|
"import": "./dist/attributes.mjs",
|
|
44
49
|
"types": "./dist/attributes.d.ts"
|
|
45
50
|
},
|
|
51
|
+
"./custom-elements": {
|
|
52
|
+
"source": "./src/custom-elements.ts",
|
|
53
|
+
"import": "./dist/custom-elements.mjs",
|
|
54
|
+
"types": "./dist/custom-elements.d.ts"
|
|
55
|
+
},
|
|
46
56
|
"./jsx-runtime": {
|
|
47
57
|
"source": "./src/jsx-runtime/index.ts",
|
|
48
58
|
"import": "./dist/jsx-runtime/index.mjs",
|
package/dist/lib-JA05lzCN.d.mts
DELETED
|
File without changes
|