elements-kit 0.0.12 → 0.0.14
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 +38 -0
- package/dist/{element-MXzFk4G2.mjs → element-C_4VbkvQ.mjs} +1 -1
- package/dist/{index-Cvdhuy6Y.d.mts → index-DUshSQ_6.d.mts} +11 -7
- package/dist/index.mjs +2 -2
- package/dist/integrations/react.d.mts +1 -1
- package/dist/integrations/react.mjs +1 -1
- package/dist/jsx-runtime/index.d.mts +1 -1
- 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-DcgXhkU2.mjs → signals-BHmWX6ox.mjs} +86 -76
- package/dist/slot.d.mts +2 -1
- package/dist/utilities/active-element.d.mts +1 -1
- package/dist/utilities/async.d.mts +37 -0
- package/dist/utilities/async.mjs +119 -0
- package/dist/utilities/async.test.d.mts +1 -0
- package/dist/utilities/async.test.mjs +273 -0
- package/dist/utilities/debounced.d.mts +1 -1
- package/dist/utilities/debounced.mjs +1 -1
- package/dist/utilities/debounced.test.mjs +1 -1
- package/dist/utilities/element-rect.d.mts +1 -1
- package/dist/utilities/element-rect.mjs +1 -1
- package/dist/utilities/element-rect.test.mjs +1 -1
- package/dist/utilities/element-scroll.d.mts +1 -1
- package/dist/utilities/element-scroll.mjs +1 -1
- package/dist/utilities/element-scroll.test.mjs +1 -1
- package/dist/utilities/event-driven.d.mts +1 -1
- package/dist/utilities/event-driven.mjs +10 -8
- package/dist/utilities/event-listener.d.mts +1 -1
- package/dist/utilities/event-listener.mjs +1 -1
- package/dist/utilities/event-listener.test.mjs +1 -1
- package/dist/utilities/focus-within.d.mts +1 -1
- package/dist/utilities/focus-within.mjs +1 -1
- package/dist/utilities/focus-within.test.mjs +1 -1
- package/dist/utilities/hover.d.mts +1 -1
- package/dist/utilities/hover.mjs +1 -1
- package/dist/utilities/hover.test.mjs +1 -1
- package/dist/utilities/intersection-observer.mjs +1 -1
- package/dist/utilities/intersection-observer.test.mjs +1 -1
- package/dist/utilities/interval.d.mts +7 -6
- package/dist/utilities/interval.mjs +17 -13
- package/dist/utilities/interval.test.mjs +31 -2
- package/dist/utilities/location.d.mts +1 -1
- package/dist/utilities/location.mjs +1 -1
- package/dist/utilities/long-press.test.mjs +1 -1
- package/dist/utilities/media-devices.d.mts +1 -1
- package/dist/utilities/media-devices.mjs +1 -1
- package/dist/utilities/media-devices.test.mjs +1 -1
- package/dist/utilities/media-player.d.mts +1 -1
- package/dist/utilities/media-player.test.mjs +1 -1
- package/dist/utilities/media-query.d.mts +1 -1
- package/dist/utilities/media-query.mjs +1 -1
- package/dist/utilities/mutation-observer.mjs +1 -1
- package/dist/utilities/mutation-observer.test.mjs +1 -1
- package/dist/utilities/network.d.mts +10 -0
- package/dist/utilities/network.mjs +17 -0
- package/dist/utilities/network.test.d.mts +1 -0
- package/dist/utilities/network.test.mjs +29 -0
- package/dist/utilities/on-click-outside.test.mjs +1 -1
- package/dist/utilities/orientation.d.mts +1 -1
- package/dist/utilities/previous.d.mts +1 -1
- package/dist/utilities/previous.mjs +1 -1
- package/dist/utilities/previous.test.mjs +1 -1
- package/dist/utilities/promise.d.mts +56 -0
- package/dist/utilities/promise.mjs +101 -0
- package/dist/utilities/promise.test.d.mts +1 -0
- package/dist/utilities/promise.test.mjs +156 -0
- package/dist/utilities/resize-observer.mjs +1 -1
- package/dist/utilities/retry.d.mts +10 -0
- package/dist/utilities/retry.mjs +32 -0
- package/dist/utilities/retry.test.d.mts +1 -0
- package/dist/utilities/retry.test.mjs +83 -0
- 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/search-params.test.mjs +1 -1
- package/dist/utilities/storage.d.mts +1 -1
- package/dist/utilities/storage.test.mjs +1 -1
- package/dist/utilities/throttled.d.mts +1 -1
- package/dist/utilities/throttled.mjs +1 -1
- package/dist/utilities/throttled.test.mjs +1 -1
- package/dist/utilities/timeout.d.mts +2 -2
- package/dist/utilities/timeout.mjs +7 -7
- package/dist/utilities/timeout.test.mjs +4 -4
- package/dist/utilities/window-focus.d.mts +10 -0
- package/dist/utilities/window-focus.mjs +16 -0
- package/dist/utilities/window-size.d.mts +1 -1
- package/dist/utilities/window-size.mjs +1 -1
- package/package.json +3 -13
- package/dist/builder/dom.d.mts +0 -212
- package/dist/builder/dom.mjs +0 -205
- package/dist/builder/index.d.mts +0 -88
- package/dist/builder/index.mjs +0 -114
- /package/dist/{lib-BYJ5jPTG.d.mts → lib-JA05lzCN.d.mts} +0 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { _ as signal, r as resolve, u as effect, y as untracked } from "../signals-BHmWX6ox.mjs";
|
|
2
|
+
import { promise } from "./promise.mjs";
|
|
3
|
+
//#region src/utilities/async.ts
|
|
4
|
+
var Async = class {
|
|
5
|
+
#fn = signal(async () => Promise.resolve(void 0));
|
|
6
|
+
#cleanup = () => {};
|
|
7
|
+
get fn() {
|
|
8
|
+
return this.#fn();
|
|
9
|
+
}
|
|
10
|
+
set fn(fn) {
|
|
11
|
+
this.#fn(resolve(fn));
|
|
12
|
+
}
|
|
13
|
+
#current = signal(promise(() => {}));
|
|
14
|
+
get raw() {
|
|
15
|
+
return this.#current();
|
|
16
|
+
}
|
|
17
|
+
get pending() {
|
|
18
|
+
return this.raw.state === "pending";
|
|
19
|
+
}
|
|
20
|
+
get state() {
|
|
21
|
+
return this.raw.state;
|
|
22
|
+
}
|
|
23
|
+
get value() {
|
|
24
|
+
return this.raw.value;
|
|
25
|
+
}
|
|
26
|
+
get reason() {
|
|
27
|
+
return this.raw.reason;
|
|
28
|
+
}
|
|
29
|
+
get result() {
|
|
30
|
+
return this.raw.result;
|
|
31
|
+
}
|
|
32
|
+
then(onfulfilled, onrejected) {
|
|
33
|
+
return this.raw.then(onfulfilled, onrejected);
|
|
34
|
+
}
|
|
35
|
+
catch(onrejected) {
|
|
36
|
+
return this.raw.catch(onrejected);
|
|
37
|
+
}
|
|
38
|
+
finally(onfinally) {
|
|
39
|
+
return this.raw.finally(onfinally);
|
|
40
|
+
}
|
|
41
|
+
constructor(fn) {
|
|
42
|
+
this.#fn(resolve(fn));
|
|
43
|
+
}
|
|
44
|
+
#execute(...args) {
|
|
45
|
+
const input = args[0];
|
|
46
|
+
const p = promise(this.fn(input));
|
|
47
|
+
this.#current(p);
|
|
48
|
+
return p;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Runs the async function once with the given input, stopping any currently active
|
|
52
|
+
* and register cleanup effects.
|
|
53
|
+
*/
|
|
54
|
+
run(...args) {
|
|
55
|
+
this.stop();
|
|
56
|
+
this.#cleanup = effect(() => {
|
|
57
|
+
untracked(() => this.#execute(...args));
|
|
58
|
+
});
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Stops the current async operation and run cleanup effects.
|
|
63
|
+
*/
|
|
64
|
+
stop() {
|
|
65
|
+
this.#cleanup();
|
|
66
|
+
this.#cleanup = () => {};
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
[Symbol.dispose]() {
|
|
70
|
+
this.stop();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Starts a new reactive async operation, stopping any currently active one.
|
|
74
|
+
*/
|
|
75
|
+
start(...args) {
|
|
76
|
+
this.stop();
|
|
77
|
+
this.#cleanup = effect(() => {
|
|
78
|
+
this.#execute(...args);
|
|
79
|
+
});
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const ASYNC_KEYS = new Set([
|
|
84
|
+
"then",
|
|
85
|
+
"catch",
|
|
86
|
+
"finally",
|
|
87
|
+
"state",
|
|
88
|
+
"value",
|
|
89
|
+
"reason",
|
|
90
|
+
"result",
|
|
91
|
+
"pending",
|
|
92
|
+
"start",
|
|
93
|
+
"stop",
|
|
94
|
+
"run",
|
|
95
|
+
"fn",
|
|
96
|
+
"raw",
|
|
97
|
+
Symbol.dispose
|
|
98
|
+
]);
|
|
99
|
+
function async(fn) {
|
|
100
|
+
const inst = new Async(fn);
|
|
101
|
+
const signal = () => inst.result;
|
|
102
|
+
return new Proxy(signal, {
|
|
103
|
+
apply(_target, _thisArg, args) {
|
|
104
|
+
return inst.result;
|
|
105
|
+
},
|
|
106
|
+
get(_target, prop, receiver) {
|
|
107
|
+
if (ASYNC_KEYS.has(prop)) {
|
|
108
|
+
const val = inst[prop];
|
|
109
|
+
return typeof val === "function" ? val.bind(inst) : val;
|
|
110
|
+
}
|
|
111
|
+
return Reflect.get(signal, prop, receiver);
|
|
112
|
+
},
|
|
113
|
+
getPrototypeOf() {
|
|
114
|
+
return Async.prototype;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
export { Async, async };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { _ as signal, g as onCleanup, u as effect } from "../signals-BHmWX6ox.mjs";
|
|
2
|
+
import { n as vi, o as describe, s as it, t as globalExpect } from "../test.BmQO5GaM-ANkhHvbr.mjs";
|
|
3
|
+
import { Async, async } from "./async.mjs";
|
|
4
|
+
import { createInterval } from "./interval.mjs";
|
|
5
|
+
//#region src/utilities/async.test.ts
|
|
6
|
+
function deferred() {
|
|
7
|
+
let resolve;
|
|
8
|
+
let reject;
|
|
9
|
+
return {
|
|
10
|
+
promise: new Promise((res, rej) => {
|
|
11
|
+
resolve = res;
|
|
12
|
+
reject = rej;
|
|
13
|
+
}),
|
|
14
|
+
resolve,
|
|
15
|
+
reject
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
describe("Async", () => {
|
|
19
|
+
it("is reactive as a computed signal (effect)", async () => {
|
|
20
|
+
const op = async((x) => Promise.resolve(x * 2));
|
|
21
|
+
const values = [];
|
|
22
|
+
const stop = effect(() => {
|
|
23
|
+
values.push(op());
|
|
24
|
+
});
|
|
25
|
+
op.run(2);
|
|
26
|
+
await op;
|
|
27
|
+
op.run(3);
|
|
28
|
+
await op;
|
|
29
|
+
stop();
|
|
30
|
+
globalExpect(values).toContain(void 0);
|
|
31
|
+
globalExpect(values).toContain(4);
|
|
32
|
+
globalExpect(values).toContain(6);
|
|
33
|
+
globalExpect(values.at(-1)).toBe(6);
|
|
34
|
+
});
|
|
35
|
+
it("is callable as a signal and returns the current result", async () => {
|
|
36
|
+
const op = async(() => Promise.resolve(123));
|
|
37
|
+
globalExpect(op()).toBeUndefined();
|
|
38
|
+
op.start();
|
|
39
|
+
await op;
|
|
40
|
+
globalExpect(op()).toBe(123);
|
|
41
|
+
const err = /* @__PURE__ */ new Error("fail");
|
|
42
|
+
const op2 = async(() => Promise.reject(err));
|
|
43
|
+
op2.start();
|
|
44
|
+
await op2.catch(() => {});
|
|
45
|
+
globalExpect(op2()).toBe(err);
|
|
46
|
+
});
|
|
47
|
+
it("starts in pending state with no value or reason", () => {
|
|
48
|
+
const op = async(() => Promise.resolve(1));
|
|
49
|
+
globalExpect(op.state).toBe("pending");
|
|
50
|
+
globalExpect(op.pending).toBe(true);
|
|
51
|
+
globalExpect(op.value).toBeUndefined();
|
|
52
|
+
globalExpect(op.reason).toBeUndefined();
|
|
53
|
+
globalExpect(op.result).toBeUndefined();
|
|
54
|
+
globalExpect(op.pending).toBe(op.state === "pending");
|
|
55
|
+
});
|
|
56
|
+
it("transitions to fulfilled after start()", async () => {
|
|
57
|
+
const op = async(() => Promise.resolve(42));
|
|
58
|
+
op.start();
|
|
59
|
+
await op;
|
|
60
|
+
globalExpect(op.state).toBe("fulfilled");
|
|
61
|
+
globalExpect(op.pending).toBe(false);
|
|
62
|
+
globalExpect(op.value).toBe(42);
|
|
63
|
+
globalExpect(op.reason).toBeUndefined();
|
|
64
|
+
globalExpect(op.result).toBe(42);
|
|
65
|
+
globalExpect(op.result).toBe(42);
|
|
66
|
+
});
|
|
67
|
+
it("transitions to rejected after start()", async () => {
|
|
68
|
+
const err = /* @__PURE__ */ new Error("fail");
|
|
69
|
+
const op = async(() => Promise.reject(err));
|
|
70
|
+
op.start();
|
|
71
|
+
await op.catch(() => {});
|
|
72
|
+
globalExpect(op.state).toBe("rejected");
|
|
73
|
+
globalExpect(op.pending).toBe(false);
|
|
74
|
+
globalExpect(op.reason).toBe(err);
|
|
75
|
+
globalExpect(op.value).toBeUndefined();
|
|
76
|
+
globalExpect(op.result).toBe(err);
|
|
77
|
+
globalExpect(op.reason).toBe(err);
|
|
78
|
+
});
|
|
79
|
+
it("await op.run(args) resolves to the fulfilled value", async () => {
|
|
80
|
+
const op = async((x) => Promise.resolve(x + 100));
|
|
81
|
+
globalExpect(await op.run(23)).toBe(123);
|
|
82
|
+
globalExpect(op.value).toBe(123);
|
|
83
|
+
globalExpect(op.state).toBe("fulfilled");
|
|
84
|
+
});
|
|
85
|
+
it("run() resolves to the fulfilled value", async () => {
|
|
86
|
+
globalExpect(await async((x) => Promise.resolve(x * 2)).run(5)).toBe(10);
|
|
87
|
+
});
|
|
88
|
+
it("await op resolves to the fulfilled value", async () => {
|
|
89
|
+
const op = async(() => Promise.resolve(7));
|
|
90
|
+
op.start();
|
|
91
|
+
globalExpect(await op).toBe(7);
|
|
92
|
+
});
|
|
93
|
+
it("await op.catch() resolves on rejection", async () => {
|
|
94
|
+
const err = /* @__PURE__ */ new Error("fail");
|
|
95
|
+
const op = async(() => Promise.reject(err));
|
|
96
|
+
op.start();
|
|
97
|
+
globalExpect(await op.catch((e) => e)).toBe(err);
|
|
98
|
+
});
|
|
99
|
+
it("delegates .then()", async () => {
|
|
100
|
+
const op = async(() => Promise.resolve(3));
|
|
101
|
+
op.start();
|
|
102
|
+
globalExpect(await op.then((v) => (v ?? 0) * 2)).toBe(6);
|
|
103
|
+
});
|
|
104
|
+
it("instanceof Async", () => {
|
|
105
|
+
globalExpect(async(() => Promise.resolve()) instanceof Async).toBe(true);
|
|
106
|
+
});
|
|
107
|
+
it("is reactive — effect reruns when state transitions to fulfilled", async () => {
|
|
108
|
+
const op = async(() => Promise.resolve(10));
|
|
109
|
+
const snapshots = [];
|
|
110
|
+
const stop = effect(() => {
|
|
111
|
+
snapshots.push(op.state);
|
|
112
|
+
});
|
|
113
|
+
op.start();
|
|
114
|
+
await op;
|
|
115
|
+
stop();
|
|
116
|
+
globalExpect(snapshots).toContain("pending");
|
|
117
|
+
globalExpect(snapshots.at(-1)).toBe("fulfilled");
|
|
118
|
+
});
|
|
119
|
+
it("is reactive — effect sees value after fulfillment", async () => {
|
|
120
|
+
const op = async(() => Promise.resolve(99));
|
|
121
|
+
const values = [];
|
|
122
|
+
const stop = effect(() => {
|
|
123
|
+
values.push(op.value);
|
|
124
|
+
});
|
|
125
|
+
op.start();
|
|
126
|
+
await op;
|
|
127
|
+
stop();
|
|
128
|
+
globalExpect(values).toEqual([
|
|
129
|
+
void 0,
|
|
130
|
+
void 0,
|
|
131
|
+
99
|
|
132
|
+
]);
|
|
133
|
+
});
|
|
134
|
+
it("is reactive — effect reruns on rejection", async () => {
|
|
135
|
+
const err = /* @__PURE__ */ new Error("x");
|
|
136
|
+
const op = async(() => Promise.reject(err));
|
|
137
|
+
const reasons = [];
|
|
138
|
+
const stop = effect(() => {
|
|
139
|
+
reasons.push(op.reason);
|
|
140
|
+
});
|
|
141
|
+
op.start();
|
|
142
|
+
await op.catch(() => {});
|
|
143
|
+
stop();
|
|
144
|
+
globalExpect(reasons).toEqual([
|
|
145
|
+
void 0,
|
|
146
|
+
void 0,
|
|
147
|
+
err
|
|
148
|
+
]);
|
|
149
|
+
});
|
|
150
|
+
it("start() re-runs when a signal read inside fn changes", async () => {
|
|
151
|
+
const id = signal(1);
|
|
152
|
+
const calls = [];
|
|
153
|
+
const op = async(() => {
|
|
154
|
+
const current = id();
|
|
155
|
+
calls.push(current);
|
|
156
|
+
return Promise.resolve(current);
|
|
157
|
+
});
|
|
158
|
+
op.start();
|
|
159
|
+
await op;
|
|
160
|
+
id(2);
|
|
161
|
+
await op;
|
|
162
|
+
op.stop();
|
|
163
|
+
globalExpect(calls).toEqual([1, 2]);
|
|
164
|
+
});
|
|
165
|
+
it("run() is not reactive — signal change does not re-run", async () => {
|
|
166
|
+
const id = signal(1);
|
|
167
|
+
const calls = [];
|
|
168
|
+
const op = async(() => {
|
|
169
|
+
const current = id();
|
|
170
|
+
calls.push(current);
|
|
171
|
+
return Promise.resolve(current);
|
|
172
|
+
});
|
|
173
|
+
op.run();
|
|
174
|
+
await op;
|
|
175
|
+
id(2);
|
|
176
|
+
await Promise.resolve();
|
|
177
|
+
op.stop();
|
|
178
|
+
globalExpect(calls).toEqual([1]);
|
|
179
|
+
});
|
|
180
|
+
it("start() resets to pending on re-run", async () => {
|
|
181
|
+
const d = deferred();
|
|
182
|
+
const id = signal(1);
|
|
183
|
+
const op = async(() => {
|
|
184
|
+
id();
|
|
185
|
+
return d.promise;
|
|
186
|
+
});
|
|
187
|
+
op.start();
|
|
188
|
+
globalExpect(op.pending).toBe(true);
|
|
189
|
+
id(2);
|
|
190
|
+
globalExpect(op.pending).toBe(true);
|
|
191
|
+
d.resolve(5);
|
|
192
|
+
op.stop();
|
|
193
|
+
});
|
|
194
|
+
it("stop() prevents further reactive reruns", async () => {
|
|
195
|
+
const id = signal(1);
|
|
196
|
+
const calls = [];
|
|
197
|
+
const op = async(() => {
|
|
198
|
+
calls.push(id());
|
|
199
|
+
return Promise.resolve(id());
|
|
200
|
+
});
|
|
201
|
+
op.start();
|
|
202
|
+
await op;
|
|
203
|
+
op.stop();
|
|
204
|
+
id(2);
|
|
205
|
+
await Promise.resolve();
|
|
206
|
+
globalExpect(calls).toEqual([1]);
|
|
207
|
+
});
|
|
208
|
+
it("onCleanup inside run() fires when stop() is called", () => {
|
|
209
|
+
const cleaned = [];
|
|
210
|
+
const op = async(() => {
|
|
211
|
+
onCleanup(() => cleaned.push(1));
|
|
212
|
+
return Promise.resolve();
|
|
213
|
+
});
|
|
214
|
+
op.run();
|
|
215
|
+
globalExpect(cleaned).toEqual([]);
|
|
216
|
+
op.stop();
|
|
217
|
+
globalExpect(cleaned).toEqual([1]);
|
|
218
|
+
});
|
|
219
|
+
it("onCleanup inside start() fires on each re-run", async () => {
|
|
220
|
+
const id = signal(1);
|
|
221
|
+
const cleaned = [];
|
|
222
|
+
const op = async(() => {
|
|
223
|
+
const current = id();
|
|
224
|
+
onCleanup(() => cleaned.push(current));
|
|
225
|
+
return Promise.resolve();
|
|
226
|
+
});
|
|
227
|
+
op.start();
|
|
228
|
+
await op;
|
|
229
|
+
id(2);
|
|
230
|
+
await op;
|
|
231
|
+
op.stop();
|
|
232
|
+
globalExpect(cleaned[0]).toBe(1);
|
|
233
|
+
});
|
|
234
|
+
it("re-runs when createInterval ticks", async () => {
|
|
235
|
+
vi.useFakeTimers();
|
|
236
|
+
const timer = createInterval(1e3);
|
|
237
|
+
const calls = [];
|
|
238
|
+
const op = async(() => {
|
|
239
|
+
timer.timestamp();
|
|
240
|
+
calls.push(calls.length);
|
|
241
|
+
return Promise.resolve(calls.length);
|
|
242
|
+
});
|
|
243
|
+
op.start();
|
|
244
|
+
await op;
|
|
245
|
+
globalExpect(calls.length).toBe(1);
|
|
246
|
+
vi.advanceTimersByTime(1e3);
|
|
247
|
+
await op;
|
|
248
|
+
globalExpect(calls.length).toBe(2);
|
|
249
|
+
op.stop();
|
|
250
|
+
timer.stop();
|
|
251
|
+
vi.useRealTimers();
|
|
252
|
+
});
|
|
253
|
+
it("state and value update atomically — no inconsistent intermediate state", async () => {
|
|
254
|
+
const op = async(() => Promise.resolve(7));
|
|
255
|
+
const snapshots = [];
|
|
256
|
+
const stop = effect(() => {
|
|
257
|
+
snapshots.push({
|
|
258
|
+
state: op.state,
|
|
259
|
+
value: op.value
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
op.start();
|
|
263
|
+
await op;
|
|
264
|
+
stop();
|
|
265
|
+
globalExpect(snapshots.find((s) => s.state === "fulfilled" && s.value === void 0)).toBeUndefined();
|
|
266
|
+
globalExpect(snapshots.at(-1)).toEqual({
|
|
267
|
+
state: "fulfilled",
|
|
268
|
+
value: 7
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
//#endregion
|
|
273
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as signal, d as effectScope } from "../signals-BHmWX6ox.mjs";
|
|
2
2
|
import { a as beforeEach, n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-ANkhHvbr.mjs";
|
|
3
3
|
import { createDebounced } from "./debounced.mjs";
|
|
4
4
|
//#region src/utilities/debounced.test.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as effectScope } from "../signals-BHmWX6ox.mjs";
|
|
2
2
|
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-ANkhHvbr.mjs";
|
|
3
3
|
import { createElementRect } from "./element-rect.mjs";
|
|
4
4
|
//#region src/utilities/element-rect.test.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as effectScope } from "../signals-BHmWX6ox.mjs";
|
|
2
2
|
import { o as describe, s as it, t as globalExpect } from "../test.BmQO5GaM-ANkhHvbr.mjs";
|
|
3
3
|
import { createElementScroll } from "./element-scroll.mjs";
|
|
4
4
|
//#region src/utilities/element-scroll.test.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as signal, g as onCleanup, l as computed, s as $signal, v as trigger } from "../signals-BHmWX6ox.mjs";
|
|
2
2
|
//#region src/utilities/event-driven.ts
|
|
3
3
|
/**
|
|
4
4
|
* Returns a `Subscribe` for one or more DOM events on a target.
|
|
@@ -24,15 +24,17 @@ function sync(subscribe, getter, setter) {
|
|
|
24
24
|
value();
|
|
25
25
|
const cleanup = subscribe(() => trigger(tick));
|
|
26
26
|
onCleanup(cleanup);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const factory = () => {
|
|
28
|
+
if (!setter) return value;
|
|
29
|
+
function proxy(v) {
|
|
30
|
+
if (arguments.length === 0 || !setter) return value();
|
|
30
31
|
setter(v);
|
|
31
32
|
return v;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(proxy, $signal, { value: true });
|
|
35
|
+
return proxy;
|
|
36
|
+
};
|
|
37
|
+
return [factory(), cleanup];
|
|
36
38
|
}
|
|
37
39
|
//#endregion
|
|
38
40
|
export { fromEvent, sync };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { g as onCleanup, u as effect } from "../signals-BHmWX6ox.mjs";
|
|
2
2
|
//#region src/utilities/event-listener.ts
|
|
3
3
|
function on(target, type, handler, options) {
|
|
4
4
|
const add = (t) => options !== void 0 ? t.addEventListener(type, handler, options) : t.addEventListener(type, handler);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as signal, d as effectScope, u as effect } from "../signals-BHmWX6ox.mjs";
|
|
2
2
|
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-ANkhHvbr.mjs";
|
|
3
3
|
import { on } from "./event-listener.mjs";
|
|
4
4
|
//#region src/utilities/event-listener.test.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as effectScope } from "../signals-BHmWX6ox.mjs";
|
|
2
2
|
import { o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-ANkhHvbr.mjs";
|
|
3
3
|
import { createFocusWithin } from "./focus-within.mjs";
|
|
4
4
|
//#region src/utilities/focus-within.test.ts
|
package/dist/utilities/hover.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as effectScope } from "../signals-BHmWX6ox.mjs";
|
|
2
2
|
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-ANkhHvbr.mjs";
|
|
3
3
|
import { createHover } from "./hover.mjs";
|
|
4
4
|
//#region src/utilities/hover.test.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as effectScope } from "../signals-BHmWX6ox.mjs";
|
|
2
2
|
import { n as vi, o as describe, r as afterEach, s as it, t as globalExpect } from "../test.BmQO5GaM-ANkhHvbr.mjs";
|
|
3
3
|
import { createIntersectionObserver } from "./intersection-observer.mjs";
|
|
4
4
|
//#region src/utilities/intersection-observer.test.ts
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { t as Computed } from "../index-
|
|
1
|
+
import { t as Computed } from "../index-DUshSQ_6.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/utilities/interval.d.ts
|
|
4
4
|
type IntervalResult = {
|
|
5
|
-
|
|
5
|
+
timestamp: Computed<number>;
|
|
6
|
+
pending: Computed<boolean>;
|
|
6
7
|
start(): void;
|
|
7
8
|
stop(): void;
|
|
8
9
|
reset(): void;
|
|
9
10
|
} & Disposable;
|
|
11
|
+
type Fn = () => void;
|
|
12
|
+
type Delay = number | (() => number);
|
|
10
13
|
/**
|
|
11
14
|
* Pausable `setInterval` wrapper. Starts running immediately on creation.
|
|
12
|
-
*
|
|
13
|
-
* @param callback - Called on each tick.
|
|
14
|
-
* @param delay - Interval delay in ms (or a reactive getter).
|
|
15
15
|
*/
|
|
16
|
-
declare function createInterval(
|
|
16
|
+
declare function createInterval(delay: Delay): IntervalResult;
|
|
17
|
+
declare function createInterval(callback: Fn, delay: Delay): IntervalResult;
|
|
17
18
|
//#endregion
|
|
18
19
|
export { createInterval };
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as signal, g as onCleanup } from "../signals-BHmWX6ox.mjs";
|
|
2
2
|
//#region src/utilities/interval.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @param callback - Called on each tick.
|
|
7
|
-
* @param delay - Interval delay in ms (or a reactive getter).
|
|
8
|
-
*/
|
|
9
|
-
function createInterval(callback, delay) {
|
|
10
|
-
const isRunning = signal(true);
|
|
3
|
+
function createInterval(arg1, arg2) {
|
|
4
|
+
const [callback, delay] = resolveArgs(arg1, arg2);
|
|
5
|
+
const pending = signal(true);
|
|
11
6
|
let id;
|
|
7
|
+
const timestamp = signal(Date.now());
|
|
12
8
|
const getDelay = typeof delay === "function" ? delay : () => delay;
|
|
13
9
|
const start = () => {
|
|
14
10
|
if (id !== void 0) return;
|
|
15
|
-
|
|
16
|
-
id = setInterval(() =>
|
|
11
|
+
pending(true);
|
|
12
|
+
id = setInterval(() => {
|
|
13
|
+
callback?.();
|
|
14
|
+
timestamp(Date.now());
|
|
15
|
+
}, getDelay());
|
|
17
16
|
};
|
|
18
17
|
const stop = () => {
|
|
19
18
|
clearInterval(id);
|
|
20
19
|
id = void 0;
|
|
21
|
-
|
|
20
|
+
pending(false);
|
|
22
21
|
};
|
|
23
22
|
const reset = () => {
|
|
24
23
|
stop();
|
|
@@ -28,12 +27,17 @@ function createInterval(callback, delay) {
|
|
|
28
27
|
const cleanup = () => stop();
|
|
29
28
|
onCleanup(cleanup);
|
|
30
29
|
return {
|
|
31
|
-
|
|
30
|
+
timestamp,
|
|
31
|
+
pending,
|
|
32
32
|
start,
|
|
33
33
|
stop,
|
|
34
34
|
reset,
|
|
35
35
|
[Symbol.dispose]: cleanup
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
+
function resolveArgs(arg1, arg2) {
|
|
39
|
+
if (arg2 === void 0) return [void 0, arg1];
|
|
40
|
+
return [arg1, arg2];
|
|
41
|
+
}
|
|
38
42
|
//#endregion
|
|
39
43
|
export { createInterval };
|