what-core 0.14.0 → 0.15.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/LICENSE +21 -0
- package/README.md +64 -38
- package/a11y.d.ts +128 -0
- package/data.d.ts +294 -0
- package/dist/a11y.js +510 -0
- package/dist/a11y.min.js +413 -0
- package/dist/actions.js +158 -0
- package/dist/actions.min.js +112 -0
- package/dist/animation.js +481 -0
- package/dist/animation.min.js +295 -0
- package/dist/async.js +180 -0
- package/dist/async.min.js +134 -0
- package/dist/components.js +577 -0
- package/dist/components.min.js +413 -0
- package/dist/data.js +1212 -0
- package/dist/data.min.js +918 -0
- package/dist/diagnostics.js +187 -0
- package/dist/diagnostics.min.js +134 -0
- package/dist/dom.js +796 -0
- package/dist/dom.min.js +603 -0
- package/dist/entries/a11y.js +43 -0
- package/dist/entries/a11y.min.js +43 -0
- package/dist/entries/data.js +29 -0
- package/dist/entries/data.min.js +29 -0
- package/dist/entries/dom.js +45 -0
- package/dist/entries/dom.min.js +45 -0
- package/dist/entries/form.js +31 -0
- package/dist/entries/form.min.js +31 -0
- package/dist/entries/internal.js +123 -0
- package/dist/entries/internal.min.js +123 -0
- package/dist/entries/motion.js +23 -0
- package/dist/entries/motion.min.js +23 -0
- package/dist/entries/ui.js +25 -0
- package/dist/entries/ui.min.js +25 -0
- package/dist/env.js +5 -0
- package/dist/env.min.js +5 -0
- package/dist/errors.js +1518 -0
- package/dist/errors.min.js +548 -0
- package/dist/form.js +936 -0
- package/dist/form.min.js +703 -0
- package/dist/guardrails.js +84 -0
- package/dist/guardrails.min.js +55 -0
- package/dist/h.js +232 -0
- package/dist/h.min.js +171 -0
- package/dist/head.js +241 -0
- package/dist/head.min.js +207 -0
- package/dist/helpers.js +126 -0
- package/dist/helpers.min.js +98 -0
- package/dist/hooks.js +255 -0
- package/dist/hooks.min.js +153 -0
- package/dist/hot.js +215 -0
- package/dist/hot.min.js +24 -0
- package/dist/hydration-data.js +495 -0
- package/dist/hydration-data.min.js +371 -0
- package/dist/import-changes.js +273 -0
- package/dist/import-changes.min.js +272 -0
- package/dist/index.js +95 -0
- package/dist/index.min.js +95 -227
- package/dist/jsx-dev-runtime.js +10 -0
- package/dist/jsx-dev-runtime.min.js +10 -1
- package/dist/jsx-runtime.js +27 -0
- package/dist/jsx-runtime.min.js +15 -1
- package/dist/live.js +54 -0
- package/dist/live.min.js +49 -0
- package/dist/markup-rules.js +250 -0
- package/dist/markup-rules.min.js +213 -0
- package/dist/reactive.js +3334 -0
- package/dist/reactive.min.js +2033 -0
- package/dist/render.js +4746 -0
- package/dist/render.min.js +2797 -1
- package/dist/scheduler.js +225 -0
- package/dist/scheduler.min.js +162 -0
- package/dist/selector.js +11 -0
- package/dist/selector.min.js +10 -0
- package/dist/server-context.js +148 -0
- package/dist/server-context.min.js +121 -0
- package/dist/skeleton.js +342 -0
- package/dist/skeleton.min.js +310 -0
- package/dist/store.js +72 -0
- package/dist/store.min.js +50 -0
- package/dist/testing.js +720 -0
- package/dist/testing.min.js +458 -1
- package/dist/vnode-adoption.js +19 -0
- package/dist/vnode-adoption.min.js +19 -0
- package/dist/vnode-renderer.js +61 -0
- package/dist/vnode-renderer.min.js +47 -0
- package/dom.d.ts +44 -0
- package/form.d.ts +218 -0
- package/hot.d.ts +35 -0
- package/index.d.ts +421 -736
- package/internal.d.ts +284 -0
- package/jsx-runtime.d.ts +160 -137
- package/markup-rules.d.ts +83 -0
- package/motion.d.ts +156 -0
- package/package.json +117 -3
- package/render.d.ts +278 -29
- package/src/a11y.js +64 -59
- package/src/actions.js +226 -0
- package/src/animation.js +105 -57
- package/src/async.js +259 -0
- package/src/components.js +495 -144
- package/src/data.js +1410 -1159
- package/src/diagnostics.js +263 -0
- package/src/dom.js +1159 -872
- package/src/entries/a11y.js +24 -0
- package/src/entries/data.js +17 -0
- package/src/entries/dom.js +29 -0
- package/src/entries/form.js +16 -0
- package/src/entries/internal.js +63 -0
- package/src/entries/motion.js +13 -0
- package/src/entries/ui.js +13 -0
- package/src/env-development.js +12 -0
- package/src/env.js +33 -0
- package/src/errors.js +1144 -168
- package/src/form.js +723 -225
- package/src/guardrails.js +38 -126
- package/src/h.js +227 -152
- package/src/head.js +189 -19
- package/src/helpers.js +47 -75
- package/src/hooks.js +233 -248
- package/src/hot.js +316 -0
- package/src/hydration-data.js +859 -16
- package/src/import-changes.js +156 -0
- package/src/index.js +38 -188
- package/src/jsx-dev-runtime.js +7 -14
- package/src/jsx-runtime.js +25 -9
- package/src/live.js +80 -0
- package/src/markup-rules.js +387 -0
- package/src/reactive.js +4400 -862
- package/src/render.js +6502 -2570
- package/src/scheduler.js +56 -21
- package/src/selector.js +31 -0
- package/src/server-context.js +252 -22
- package/src/skeleton.js +22 -12
- package/src/store.js +17 -31
- package/src/testing.js +389 -63
- package/src/vnode-adoption.js +48 -0
- package/src/vnode-renderer.js +114 -0
- package/testing.d.ts +81 -1
- package/ui.d.ts +20 -0
- package/dist/chunk-6YOUZ6T4.min.js +0 -1
- package/dist/chunk-FN6HXME3.min.js +0 -11
- package/dist/chunk-VKZY7JPN.min.js +0 -1
- package/src/agent-context.js +0 -127
- package/src/warnings.js +0 -193
package/dist/testing.min.js
CHANGED
|
@@ -1 +1,458 @@
|
|
|
1
|
-
|
|
1
|
+
// src/testing.js
|
|
2
|
+
import { signal as g, effect as N, flushSync as $, createRoot as B, __devtools as I, __setDevToolsHooks as A, __depsOf as P, __subsOf as V, __ownerPath as F } from "./reactive.min.js";
|
|
3
|
+
import { mount as C } from "./dom.min.js";
|
|
4
|
+
import { h as O } from "./h.min.js";
|
|
5
|
+
import { capture as W } from "./diagnostics.min.js";
|
|
6
|
+
import { settled as L } from "./async.min.js";
|
|
7
|
+
var l = null, h = /* @__PURE__ */ new Set();
|
|
8
|
+
function R(e) {
|
|
9
|
+
let t = q(), n;
|
|
10
|
+
try {
|
|
11
|
+
n = e();
|
|
12
|
+
} catch (c) {
|
|
13
|
+
throw t(), c;
|
|
14
|
+
}
|
|
15
|
+
let o = () => {
|
|
16
|
+
if (h.has(o)) {
|
|
17
|
+
h.delete(o);
|
|
18
|
+
try {
|
|
19
|
+
n();
|
|
20
|
+
} finally {
|
|
21
|
+
t();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return h.add(o), o;
|
|
26
|
+
}
|
|
27
|
+
function j() {
|
|
28
|
+
return typeof document < "u" && (l = document.createElement("div"), l.id = "test-root", document.body.appendChild(l)), l;
|
|
29
|
+
}
|
|
30
|
+
function U() {
|
|
31
|
+
for (let e of [...h])
|
|
32
|
+
try {
|
|
33
|
+
e();
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
l && (l.innerHTML = "", l.parentNode && l.parentNode.removeChild(l), l = null);
|
|
37
|
+
}
|
|
38
|
+
function ne(e, t = {}) {
|
|
39
|
+
let { container: n } = t, o = n || j();
|
|
40
|
+
if (!o)
|
|
41
|
+
throw new Error("No DOM container available. Are you running in Node.js without jsdom?");
|
|
42
|
+
let c = R(() => C(e, o));
|
|
43
|
+
return {
|
|
44
|
+
container: o,
|
|
45
|
+
unmount: c,
|
|
46
|
+
// Query helpers
|
|
47
|
+
getByText: (r) => p(o, r),
|
|
48
|
+
getByTestId: (r) => o.querySelector(`[data-testid="${r}"]`),
|
|
49
|
+
getByRole: (r) => o.querySelector(`[role="${r}"]`),
|
|
50
|
+
getAllByText: (r) => H(o, r),
|
|
51
|
+
queryByText: (r) => p(o, r),
|
|
52
|
+
queryByTestId: (r) => o.querySelector(`[data-testid="${r}"]`),
|
|
53
|
+
// Debug
|
|
54
|
+
debug: () => console.log(o.innerHTML),
|
|
55
|
+
// Async utilities
|
|
56
|
+
findByText: (r, s) => D(() => p(o, r), { timeout: s }),
|
|
57
|
+
findByTestId: (r, s) => D(() => o.querySelector(`[data-testid="${r}"]`), { timeout: s })
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function oe(e, t) {
|
|
61
|
+
let n = j();
|
|
62
|
+
if (!n)
|
|
63
|
+
throw new Error("No DOM container available. Are you running in Node.js without jsdom?");
|
|
64
|
+
let o = {}, c = null, r;
|
|
65
|
+
return B((s) => {
|
|
66
|
+
c = s;
|
|
67
|
+
let i = O(e, t || {});
|
|
68
|
+
r = R(() => C(i, n));
|
|
69
|
+
}), {
|
|
70
|
+
container: n,
|
|
71
|
+
// Proxy to access component signals by name
|
|
72
|
+
signals: new Proxy(o, {
|
|
73
|
+
get(s, i) {
|
|
74
|
+
if (i in s) return s[i];
|
|
75
|
+
},
|
|
76
|
+
set(s, i, a) {
|
|
77
|
+
return s[i] = a, !0;
|
|
78
|
+
}
|
|
79
|
+
}),
|
|
80
|
+
// Synchronous flush: run all pending effects immediately
|
|
81
|
+
update() {
|
|
82
|
+
$();
|
|
83
|
+
},
|
|
84
|
+
unmount() {
|
|
85
|
+
r && r(), c && c(), U();
|
|
86
|
+
},
|
|
87
|
+
// Query helpers
|
|
88
|
+
getByText: (s) => p(n, s),
|
|
89
|
+
getByTestId: (s) => n.querySelector(`[data-testid="${s}"]`),
|
|
90
|
+
queryByText: (s) => p(n, s),
|
|
91
|
+
debug: () => console.log(n.innerHTML)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function re() {
|
|
95
|
+
$();
|
|
96
|
+
}
|
|
97
|
+
var b = {
|
|
98
|
+
onSignalUpdate: /* @__PURE__ */ new Set(),
|
|
99
|
+
onEffectRun: /* @__PURE__ */ new Set(),
|
|
100
|
+
onEffectCreate: /* @__PURE__ */ new Set(),
|
|
101
|
+
onEffectDispose: /* @__PURE__ */ new Set()
|
|
102
|
+
}, v = null, T = null;
|
|
103
|
+
function m(e, t) {
|
|
104
|
+
return () => {
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
var w = /* @__PURE__ */ new Set(), _ = 0, k = () => {
|
|
108
|
+
};
|
|
109
|
+
function z(e) {
|
|
110
|
+
w.add(e);
|
|
111
|
+
}
|
|
112
|
+
function K(e) {
|
|
113
|
+
w.delete(e);
|
|
114
|
+
}
|
|
115
|
+
function q() {
|
|
116
|
+
return () => {
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function X(e) {
|
|
120
|
+
let t = F(e).filter((n) => n[0] === "<");
|
|
121
|
+
return t.length ? t : null;
|
|
122
|
+
}
|
|
123
|
+
var S = "(unnamed)";
|
|
124
|
+
function se(e) {
|
|
125
|
+
throw new Error(
|
|
126
|
+
'[what] trackSignals() requires a development build. Signal debug names and the dependency graph API are stripped in production, so there is nothing to report. Run your tests with NODE_ENV !== "production".'
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
function J(e) {
|
|
130
|
+
return (e.fn?.inner ?? e.fn)?.name || "(anonymous)";
|
|
131
|
+
}
|
|
132
|
+
function ce(e) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
'[what] captureDiagnostics() requires a development build: production builds report no diagnostics, so an empty result would look like a pass. Run your tests with NODE_ENV !== "production".'
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
function E(e) {
|
|
138
|
+
return e.map((t) => {
|
|
139
|
+
let n = [` ${t.code}${t.count > 1 ? ` \xD7${t.count}` : ""} ${t.message}`];
|
|
140
|
+
return t.owner?.length && n.push(` in ${t.owner.join(" \u203A ")}`), t.loc && n.push(` at ${t.loc}`), n.push(` fix: ${t.fix}`), n.join(`
|
|
141
|
+
`);
|
|
142
|
+
}).join(`
|
|
143
|
+
`);
|
|
144
|
+
}
|
|
145
|
+
function ie(e, { allow: t = [] } = {}) {
|
|
146
|
+
let n = e.events.filter((o) => !t.includes(o.code));
|
|
147
|
+
if (n.length)
|
|
148
|
+
throw new Error(`Expected no diagnostics, got ${n.length}:
|
|
149
|
+
${E(n)}`);
|
|
150
|
+
}
|
|
151
|
+
var x = ["exact", "min", "max"];
|
|
152
|
+
function M(e, t, n) {
|
|
153
|
+
if (t === null || typeof t != "object")
|
|
154
|
+
throw new TypeError(`[what] ${e}() takes an options object: { ${n.join(", ")} }.`);
|
|
155
|
+
for (let u of Object.keys(t))
|
|
156
|
+
if (!n.includes(u))
|
|
157
|
+
throw new TypeError(`[what] ${e}(): unknown option "${u}". The options are ${n.join(", ")}.`);
|
|
158
|
+
for (let u of x) {
|
|
159
|
+
let d = t[u];
|
|
160
|
+
if (d !== void 0 && !(Number.isInteger(d) && d >= 0))
|
|
161
|
+
throw new TypeError(`[what] ${e}(): ${u} must be a whole number of 0 or more, got ${String(d)}.`);
|
|
162
|
+
}
|
|
163
|
+
let { exact: o, min: c, max: r } = t;
|
|
164
|
+
if (o !== void 0 && (c !== void 0 || r !== void 0))
|
|
165
|
+
throw new TypeError(`[what] ${e}(): exact cannot be combined with min or max.`);
|
|
166
|
+
if (c !== void 0 && r !== void 0 && c > r)
|
|
167
|
+
throw new TypeError(`[what] ${e}(): min (${c}) is greater than max (${r}).`);
|
|
168
|
+
let s = o ?? c ?? (r === void 0 ? 1 : 0), i = o ?? r ?? 1 / 0, a = `between ${s} and ${i} times`;
|
|
169
|
+
return s === i ? a = `exactly ${s} time(s)` : i === 1 / 0 ? a = `at least ${s} time(s)` : s === 0 && (a = `at most ${i} time(s)`), { lo: s, hi: i, text: a };
|
|
170
|
+
}
|
|
171
|
+
function y(e, t, n) {
|
|
172
|
+
if (n !== void 0 && (typeof n != "string" || n === ""))
|
|
173
|
+
throw new TypeError(`[what] ${e}(): ${t} must be a non-empty string, got ${String(n)}.`);
|
|
174
|
+
return n;
|
|
175
|
+
}
|
|
176
|
+
function ue(e, t) {
|
|
177
|
+
let n = M("expectDiagnostic", t, ["code", ...x]), o = y("expectDiagnostic", "code", t.code);
|
|
178
|
+
if (o === void 0) throw new TypeError("[what] expectDiagnostic(): code, the ERR_* code to expect, is required.");
|
|
179
|
+
if (e.events.some((r) => r.code !== o))
|
|
180
|
+
throw new Error(`Expected exactly ${o}, got:
|
|
181
|
+
${E(e.events)}`);
|
|
182
|
+
let c = e.events.reduce((r, s) => r + s.count, 0);
|
|
183
|
+
if (c < n.lo || c > n.hi) {
|
|
184
|
+
let r = c ? `${c}:
|
|
185
|
+
${E(e.events)}` : "none.";
|
|
186
|
+
throw new Error(`Expected ${o} ${n.text}, got ${r}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function G(e) {
|
|
190
|
+
let t = /* @__PURE__ */ new Map();
|
|
191
|
+
for (let o of e) {
|
|
192
|
+
if (o.runs === 0) continue;
|
|
193
|
+
let c = o.owner === null ? " \xB7 outside any component" : ` in ${o.owner.join(" \u203A ")}`, r = `${o.name}${o.kind === "computed" ? " (computed)" : ""}`, s = `${r}
|
|
194
|
+
${c}`, i = t.get(s);
|
|
195
|
+
i ? i.runs += o.runs : t.set(s, { label: r, where: c, runs: o.runs });
|
|
196
|
+
}
|
|
197
|
+
return t.size === 0 ? "No effect ran during the capture." : `All runs:
|
|
198
|
+
${[...t.values()].sort((o, c) => c.runs - o.runs).map((o) => ` ${o.label}: ${o.runs}${o.where}`).join(`
|
|
199
|
+
`)}`;
|
|
200
|
+
}
|
|
201
|
+
function ae(e, t = {}) {
|
|
202
|
+
let n = M("expectRuns", t, ["effect", "component", ...x]), o = y("expectRuns", "effect", t.effect), c = y("expectRuns", "component", t.component), r = c === void 0 ? null : `<${c}>`, s = o === void 0 && r === null, i = 0;
|
|
203
|
+
for (let f of e.effects)
|
|
204
|
+
o !== void 0 && f.name !== o || r !== null && !f.owner?.includes(r) || (s = !0, i += f.runs);
|
|
205
|
+
let a = o === void 0 ? r === null ? "all effects together" : `effects in ${r}` : `effect "${o}"${r === null ? "" : ` in ${r}`}`, u = o === void 0 ? "they" : "it", d = G(e.effects);
|
|
206
|
+
if (!s) {
|
|
207
|
+
let f = `${o === void 0 ? "" : ` named "${o}"`}${r === null ? "" : ` created in ${r}`}`;
|
|
208
|
+
throw new Error(
|
|
209
|
+
`Expected ${a} to run ${n.text}, but no effect${f} ran or was known to exist during the capture. An effect that did not run is known only when it was created inside a render()/renderTest() tree or the capture.
|
|
210
|
+
${d}`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
if (!(i >= n.lo && i <= n.hi))
|
|
214
|
+
throw new Error(`Expected ${a} to run ${n.text}, ${u} ran ${i}.
|
|
215
|
+
${d}`);
|
|
216
|
+
}
|
|
217
|
+
function de(e, t) {
|
|
218
|
+
let n = [t], o = 0, c = g(t, e), r = c.set;
|
|
219
|
+
c.set = function(a) {
|
|
220
|
+
let u = typeof a == "function" ? a(c.peek()) : a;
|
|
221
|
+
return Object.is(c.peek(), u) || (o++, n.push(u)), r(u);
|
|
222
|
+
};
|
|
223
|
+
let s = c, i = function(...a) {
|
|
224
|
+
if (a.length === 0)
|
|
225
|
+
return s();
|
|
226
|
+
let u = typeof a[0] == "function" ? a[0](s.peek()) : a[0];
|
|
227
|
+
return Object.is(s.peek(), u) || (o++, n.push(u)), s(u);
|
|
228
|
+
};
|
|
229
|
+
return i._signal = !0, i.peek = c.peek, i.set = c.set, i.subscribe = c.subscribe, c._debugName && (i._debugName = c._debugName), Object.defineProperty(i, "history", {
|
|
230
|
+
get() {
|
|
231
|
+
return n;
|
|
232
|
+
}
|
|
233
|
+
}), Object.defineProperty(i, "setCount", {
|
|
234
|
+
get() {
|
|
235
|
+
return o;
|
|
236
|
+
}
|
|
237
|
+
}), i.reset = function(a) {
|
|
238
|
+
let u = a !== void 0 ? a : t;
|
|
239
|
+
n.length = 0, n.push(u), o = 0, s(u);
|
|
240
|
+
}, i;
|
|
241
|
+
}
|
|
242
|
+
function p(e, t) {
|
|
243
|
+
let n = t instanceof RegExp ? t : null, o = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, null);
|
|
244
|
+
for (; o.nextNode(); ) {
|
|
245
|
+
let c = o.currentNode, r = c.textContent || "";
|
|
246
|
+
if (n ? n.test(r) : r.includes(t))
|
|
247
|
+
return c.parentElement;
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
function H(e, t) {
|
|
252
|
+
let n = [], o = t instanceof RegExp ? t : null, c = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, null);
|
|
253
|
+
for (; c.nextNode(); ) {
|
|
254
|
+
let r = c.currentNode, s = r.textContent || "";
|
|
255
|
+
(o ? o.test(s) : s.includes(t)) && n.push(r.parentElement);
|
|
256
|
+
}
|
|
257
|
+
return n;
|
|
258
|
+
}
|
|
259
|
+
var fe = {
|
|
260
|
+
click(e) {
|
|
261
|
+
let t = new MouseEvent("click", {
|
|
262
|
+
bubbles: !0,
|
|
263
|
+
cancelable: !0,
|
|
264
|
+
view: typeof window < "u" ? window : void 0
|
|
265
|
+
});
|
|
266
|
+
return e.dispatchEvent(t), t;
|
|
267
|
+
},
|
|
268
|
+
change(e, t) {
|
|
269
|
+
e.value = t;
|
|
270
|
+
let n = new Event("input", { bubbles: !0 });
|
|
271
|
+
e.dispatchEvent(n);
|
|
272
|
+
let o = new Event("change", { bubbles: !0 });
|
|
273
|
+
return e.dispatchEvent(o), o;
|
|
274
|
+
},
|
|
275
|
+
input(e, t) {
|
|
276
|
+
e.value = t;
|
|
277
|
+
let n = new Event("input", { bubbles: !0 });
|
|
278
|
+
return e.dispatchEvent(n), n;
|
|
279
|
+
},
|
|
280
|
+
submit(e) {
|
|
281
|
+
let t = new Event("submit", { bubbles: !0, cancelable: !0 });
|
|
282
|
+
return e.dispatchEvent(t), t;
|
|
283
|
+
},
|
|
284
|
+
focus(e) {
|
|
285
|
+
e.focus();
|
|
286
|
+
let t = new FocusEvent("focus", { bubbles: !0 });
|
|
287
|
+
return e.dispatchEvent(t), t;
|
|
288
|
+
},
|
|
289
|
+
blur(e) {
|
|
290
|
+
e.blur();
|
|
291
|
+
let t = new FocusEvent("blur", { bubbles: !0 });
|
|
292
|
+
return e.dispatchEvent(t), t;
|
|
293
|
+
},
|
|
294
|
+
keyDown(e, t, n = {}) {
|
|
295
|
+
let o = new KeyboardEvent("keydown", {
|
|
296
|
+
bubbles: !0,
|
|
297
|
+
cancelable: !0,
|
|
298
|
+
key: t,
|
|
299
|
+
...n
|
|
300
|
+
});
|
|
301
|
+
return e.dispatchEvent(o), o;
|
|
302
|
+
},
|
|
303
|
+
keyUp(e, t, n = {}) {
|
|
304
|
+
let o = new KeyboardEvent("keyup", {
|
|
305
|
+
bubbles: !0,
|
|
306
|
+
cancelable: !0,
|
|
307
|
+
key: t,
|
|
308
|
+
...n
|
|
309
|
+
});
|
|
310
|
+
return e.dispatchEvent(o), o;
|
|
311
|
+
},
|
|
312
|
+
mouseEnter(e) {
|
|
313
|
+
let t = new MouseEvent("mouseenter", { bubbles: !0 });
|
|
314
|
+
return e.dispatchEvent(t), t;
|
|
315
|
+
},
|
|
316
|
+
mouseLeave(e) {
|
|
317
|
+
let t = new MouseEvent("mouseleave", { bubbles: !0 });
|
|
318
|
+
return e.dispatchEvent(t), t;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
async function D(e, t = {}) {
|
|
322
|
+
let { timeout: n = 1e3, interval: o = 50 } = t, c = Date.now();
|
|
323
|
+
for (; Date.now() - c < n; ) {
|
|
324
|
+
try {
|
|
325
|
+
let r = e();
|
|
326
|
+
if (r) return r;
|
|
327
|
+
} catch {
|
|
328
|
+
}
|
|
329
|
+
await new Promise((r) => setTimeout(r, o));
|
|
330
|
+
}
|
|
331
|
+
throw new Error(`waitFor timed out after ${n}ms`);
|
|
332
|
+
}
|
|
333
|
+
async function le(e, t = {}) {
|
|
334
|
+
let { timeout: n = 1e3, interval: o = 50 } = t, c = Date.now(), r = e();
|
|
335
|
+
if (!r)
|
|
336
|
+
throw new Error("Element not found");
|
|
337
|
+
for (; Date.now() - c < n; ) {
|
|
338
|
+
if (r = e(), !r) return;
|
|
339
|
+
await new Promise((s) => setTimeout(s, o));
|
|
340
|
+
}
|
|
341
|
+
throw new Error(`Element still present after ${n}ms`);
|
|
342
|
+
}
|
|
343
|
+
async function pe(e) {
|
|
344
|
+
let t = await e();
|
|
345
|
+
return $(), await /** @type {Promise<void>} */
|
|
346
|
+
new Promise((n) => queueMicrotask(() => n())), await /** @type {Promise<void>} */
|
|
347
|
+
new Promise((n) => setTimeout(() => n(), 0)), await L(), t;
|
|
348
|
+
}
|
|
349
|
+
function we(e) {
|
|
350
|
+
let t = g(e), n = [e];
|
|
351
|
+
return N(() => {
|
|
352
|
+
n.push(t());
|
|
353
|
+
}), {
|
|
354
|
+
signal: t,
|
|
355
|
+
get value() {
|
|
356
|
+
return t();
|
|
357
|
+
},
|
|
358
|
+
set value(o) {
|
|
359
|
+
t.set(o);
|
|
360
|
+
},
|
|
361
|
+
history: n,
|
|
362
|
+
reset() {
|
|
363
|
+
n.length = 0, n.push(t());
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
function he(e = "MockComponent") {
|
|
368
|
+
let t = [];
|
|
369
|
+
function n(o) {
|
|
370
|
+
return t.push({ props: o, timestamp: Date.now() }), O(
|
|
371
|
+
"div",
|
|
372
|
+
{ "data-testid": `mock-${e}` },
|
|
373
|
+
JSON.stringify(o, null, 2)
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
return n.displayName = e, n.calls = t, n.lastCall = () => t[t.length - 1], n.reset = () => {
|
|
377
|
+
t.length = 0;
|
|
378
|
+
}, n;
|
|
379
|
+
}
|
|
380
|
+
var me = {
|
|
381
|
+
toBeInTheDocument(e) {
|
|
382
|
+
if (!e || !e.isConnected)
|
|
383
|
+
throw new Error("Expected element to be in the document");
|
|
384
|
+
},
|
|
385
|
+
toHaveTextContent(e, t) {
|
|
386
|
+
if (!e)
|
|
387
|
+
throw new Error("Element not found");
|
|
388
|
+
let n = e.textContent;
|
|
389
|
+
if (!(t instanceof RegExp ? t.test(n) : n.includes(t)))
|
|
390
|
+
throw new Error(`Expected "${n}" to contain "${t}"`);
|
|
391
|
+
},
|
|
392
|
+
toHaveAttribute(e, t, n) {
|
|
393
|
+
if (!e)
|
|
394
|
+
throw new Error("Element not found");
|
|
395
|
+
let o = e.getAttribute(t);
|
|
396
|
+
if (n !== void 0 && o !== n)
|
|
397
|
+
throw new Error(`Expected attribute "${t}" to be "${n}", got "${o}"`);
|
|
398
|
+
if (n === void 0 && o === null)
|
|
399
|
+
throw new Error(`Expected element to have attribute "${t}"`);
|
|
400
|
+
},
|
|
401
|
+
toHaveClass(e, t) {
|
|
402
|
+
if (!e)
|
|
403
|
+
throw new Error("Element not found");
|
|
404
|
+
if (!e.classList.contains(t))
|
|
405
|
+
throw new Error(`Expected element to have class "${t}"`);
|
|
406
|
+
},
|
|
407
|
+
toBeVisible(e) {
|
|
408
|
+
if (!e)
|
|
409
|
+
throw new Error("Element not found");
|
|
410
|
+
if (window.getComputedStyle(e).visibility === "hidden") throw new Error("Expected element to be visible");
|
|
411
|
+
for (let t = e; t && t.nodeType === 1; t = t.parentElement) {
|
|
412
|
+
let n = window.getComputedStyle(t);
|
|
413
|
+
if (n.display === "none" || n.opacity === "0") throw new Error("Expected element to be visible");
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
toBeDisabled(e) {
|
|
417
|
+
if (!e)
|
|
418
|
+
throw new Error("Element not found");
|
|
419
|
+
if (!e.disabled && !e.matches(":disabled"))
|
|
420
|
+
throw new Error("Expected element to be disabled");
|
|
421
|
+
},
|
|
422
|
+
toHaveValue(e, t) {
|
|
423
|
+
if (!e)
|
|
424
|
+
throw new Error("Element not found");
|
|
425
|
+
if (e.value !== t)
|
|
426
|
+
throw new Error(`Expected value to be "${t}", got "${e.value}"`);
|
|
427
|
+
}
|
|
428
|
+
}, be = {
|
|
429
|
+
getByText: (e) => p(document.body, e),
|
|
430
|
+
getByTestId: (e) => document.querySelector(`[data-testid="${e}"]`),
|
|
431
|
+
getByRole: (e) => document.querySelector(`[role="${e}"]`),
|
|
432
|
+
getAllByText: (e) => H(document.body, e),
|
|
433
|
+
queryByText: (e) => p(document.body, e),
|
|
434
|
+
queryByTestId: (e) => document.querySelector(`[data-testid="${e}"]`),
|
|
435
|
+
debug: () => console.log(document.body.innerHTML)
|
|
436
|
+
};
|
|
437
|
+
export {
|
|
438
|
+
pe as act,
|
|
439
|
+
ce as captureDiagnostics,
|
|
440
|
+
U as cleanup,
|
|
441
|
+
we as createTestSignal,
|
|
442
|
+
me as expect,
|
|
443
|
+
ue as expectDiagnostic,
|
|
444
|
+
ie as expectNoDiagnostics,
|
|
445
|
+
ae as expectRuns,
|
|
446
|
+
fe as fireEvent,
|
|
447
|
+
re as flushEffects,
|
|
448
|
+
he as mockComponent,
|
|
449
|
+
de as mockSignal,
|
|
450
|
+
ne as render,
|
|
451
|
+
oe as renderTest,
|
|
452
|
+
be as screen,
|
|
453
|
+
L as settled,
|
|
454
|
+
j as setupDOM,
|
|
455
|
+
se as trackSignals,
|
|
456
|
+
D as waitFor,
|
|
457
|
+
le as waitForElementToBeRemoved
|
|
458
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/vnode-adoption.js
|
|
2
|
+
import { _carryFields } from "./render.js";
|
|
3
|
+
import { vnodeRenderer } from "./vnode-renderer.js";
|
|
4
|
+
import { _adoptVNodeKinds, _adoptVNodeRows } from "./render.js";
|
|
5
|
+
import { _installVNodeRuntime } from "./vnode-renderer.js";
|
|
6
|
+
var carries = false;
|
|
7
|
+
function installFieldCarry() {
|
|
8
|
+
carries = true;
|
|
9
|
+
}
|
|
10
|
+
function fieldCarry(server, built) {
|
|
11
|
+
if (carries || vnodeRenderer !== null) _carryFields(server, built);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
_adoptVNodeKinds as adoptVNodeKinds,
|
|
15
|
+
_adoptVNodeRows as adoptVNodeRows,
|
|
16
|
+
fieldCarry,
|
|
17
|
+
installFieldCarry,
|
|
18
|
+
_installVNodeRuntime as installVNodeRuntime
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/vnode-adoption.js
|
|
2
|
+
import { _carryFields as t } from "./render.min.js";
|
|
3
|
+
import { vnodeRenderer as d } from "./vnode-renderer.min.js";
|
|
4
|
+
import { _adoptVNodeKinds as f, _adoptVNodeRows as m } from "./render.min.js";
|
|
5
|
+
import { _installVNodeRuntime as N } from "./vnode-renderer.min.js";
|
|
6
|
+
var o = !1;
|
|
7
|
+
function n() {
|
|
8
|
+
o = !0;
|
|
9
|
+
}
|
|
10
|
+
function l(e, r) {
|
|
11
|
+
(o || d !== null) && t(e, r);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
f as adoptVNodeKinds,
|
|
15
|
+
m as adoptVNodeRows,
|
|
16
|
+
l as fieldCarry,
|
|
17
|
+
n as installFieldCarry,
|
|
18
|
+
N as installVNodeRuntime
|
|
19
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/vnode-renderer.js
|
|
2
|
+
var BRANDS = /* @__PURE__ */ Symbol.for("what-core.vnode.v1");
|
|
3
|
+
var registered = false;
|
|
4
|
+
var VNode = class _VNode {
|
|
5
|
+
#brand;
|
|
6
|
+
constructor(tag, props, children, key) {
|
|
7
|
+
this.tag = tag;
|
|
8
|
+
this.props = props;
|
|
9
|
+
this.children = children;
|
|
10
|
+
this.key = key;
|
|
11
|
+
if (!registered) {
|
|
12
|
+
registered = true;
|
|
13
|
+
const global = globalThis;
|
|
14
|
+
(global[BRANDS] ??= /* @__PURE__ */ new Set()).add(_VNode.own);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
static own(value) {
|
|
18
|
+
return #brand in value;
|
|
19
|
+
}
|
|
20
|
+
static is(value) {
|
|
21
|
+
if (typeof value !== "object" || value === null) return false;
|
|
22
|
+
if (#brand in value) return true;
|
|
23
|
+
const brands = (
|
|
24
|
+
/** @type {any} */
|
|
25
|
+
globalThis[BRANDS]
|
|
26
|
+
);
|
|
27
|
+
if (brands !== void 0 && brands.size > (registered ? 1 : 0)) {
|
|
28
|
+
for (const own of brands) if (own !== _VNode.own && own(value)) return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
function isVNode(value) {
|
|
34
|
+
return VNode.is(value);
|
|
35
|
+
}
|
|
36
|
+
var vnodeRenderer = null;
|
|
37
|
+
var SVG_TAG = /^(?:svg|animate(?:motion|transform)?|circle|clippath|defs|desc|ellipse|fe[a-z]+|filter|foreignobject|g|image|line|lineargradient|marker|mask|metadata|mpath|path|pattern|poly(?:gon|line)|radialgradient|rect|set|stop|switch|symbol|text|textpath|tspan|use|view)$/i;
|
|
38
|
+
var vnodeRows = null;
|
|
39
|
+
var vnodeProp = null;
|
|
40
|
+
var vnodeRefuses = null;
|
|
41
|
+
function _installVNodeRuntime(render, keyedRows, setProp, refuses) {
|
|
42
|
+
vnodeRenderer = render;
|
|
43
|
+
VNode.prototype._$r = render;
|
|
44
|
+
vnodeRows = keyedRows;
|
|
45
|
+
vnodeProp = setProp;
|
|
46
|
+
vnodeRefuses = refuses;
|
|
47
|
+
}
|
|
48
|
+
function _installForeignRows(wrap) {
|
|
49
|
+
vnodeRows = wrap(vnodeRows);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
SVG_TAG,
|
|
53
|
+
VNode,
|
|
54
|
+
_installForeignRows,
|
|
55
|
+
_installVNodeRuntime,
|
|
56
|
+
isVNode,
|
|
57
|
+
vnodeProp,
|
|
58
|
+
vnodeRefuses,
|
|
59
|
+
vnodeRenderer,
|
|
60
|
+
vnodeRows
|
|
61
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/vnode-renderer.js
|
|
2
|
+
var l = /* @__PURE__ */ Symbol.for("what-core.vnode.v1"), i = !1, r = class e {
|
|
3
|
+
#t;
|
|
4
|
+
constructor(t, n, o, a) {
|
|
5
|
+
if (this.tag = t, this.props = n, this.children = o, this.key = a, !i) {
|
|
6
|
+
i = !0;
|
|
7
|
+
let p = globalThis;
|
|
8
|
+
(p[l] ??= /* @__PURE__ */ new Set()).add(e.own);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
static own(t) {
|
|
12
|
+
return #t in t;
|
|
13
|
+
}
|
|
14
|
+
static is(t) {
|
|
15
|
+
if (typeof t != "object" || t === null) return !1;
|
|
16
|
+
if (#t in t) return !0;
|
|
17
|
+
let n = (
|
|
18
|
+
/** @type {any} */
|
|
19
|
+
globalThis[l]
|
|
20
|
+
);
|
|
21
|
+
if (n !== void 0 && n.size > (i ? 1 : 0)) {
|
|
22
|
+
for (let o of n) if (o !== e.own && o(t)) return !0;
|
|
23
|
+
}
|
|
24
|
+
return !1;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function u(e) {
|
|
28
|
+
return r.is(e);
|
|
29
|
+
}
|
|
30
|
+
var c = null, g = /^(?:svg|animate(?:motion|transform)?|circle|clippath|defs|desc|ellipse|fe[a-z]+|filter|foreignobject|g|image|line|lineargradient|marker|mask|metadata|mpath|path|pattern|poly(?:gon|line)|radialgradient|rect|set|stop|switch|symbol|text|textpath|tspan|use|view)$/i, s = null, f = null, d = null;
|
|
31
|
+
function h(e, t, n, o) {
|
|
32
|
+
c = e, r.prototype._$r = e, s = t, f = n, d = o;
|
|
33
|
+
}
|
|
34
|
+
function m(e) {
|
|
35
|
+
s = e(s);
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
g as SVG_TAG,
|
|
39
|
+
r as VNode,
|
|
40
|
+
m as _installForeignRows,
|
|
41
|
+
h as _installVNodeRuntime,
|
|
42
|
+
u as isVNode,
|
|
43
|
+
f as vnodeProp,
|
|
44
|
+
d as vnodeRefuses,
|
|
45
|
+
c as vnodeRenderer,
|
|
46
|
+
s as vnodeRows
|
|
47
|
+
};
|
package/dom.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// what-core/dom (what-framework/dom): the DOM read/write scheduler and DOM utilities.
|
|
2
|
+
import type { Signal } from './index.js';
|
|
3
|
+
|
|
4
|
+
// --- Scheduler ---
|
|
5
|
+
// Batch reads before writes so a frame never thrashes layout.
|
|
6
|
+
|
|
7
|
+
export function scheduleRead(fn: () => void): () => void;
|
|
8
|
+
export function scheduleWrite(fn: () => void): () => void;
|
|
9
|
+
export function flushScheduler(): void;
|
|
10
|
+
export function measure<T>(fn: () => T): Promise<T>;
|
|
11
|
+
export function mutate(fn: () => void): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* `readFn` runs in a frame's read phase and `writeFn(data)` in its write
|
|
14
|
+
* phase, and both again in the next frame when a signal `readFn` read
|
|
15
|
+
* changes. Returns a dispose function; disposed with its owner too.
|
|
16
|
+
*/
|
|
17
|
+
export function useScheduledEffect<T>(readFn: () => T, writeFn?: (data: T) => void): () => void;
|
|
18
|
+
export function nextFrame(): Promise<void> & { cancel: () => void };
|
|
19
|
+
export function raf(key: string, fn: () => void): void;
|
|
20
|
+
export function onResize(element: Element, callback: (rect: DOMRectReadOnly) => void): () => void;
|
|
21
|
+
export function onIntersect(
|
|
22
|
+
element: Element,
|
|
23
|
+
callback: (entry: IntersectionObserverEntry) => void,
|
|
24
|
+
options?: IntersectionObserverInit,
|
|
25
|
+
): () => void;
|
|
26
|
+
export function smoothScrollTo(
|
|
27
|
+
element: Element,
|
|
28
|
+
options?: { duration?: number; easing?: (t: number) => number },
|
|
29
|
+
): Promise<void>;
|
|
30
|
+
|
|
31
|
+
// --- Utilities ---
|
|
32
|
+
|
|
33
|
+
export type ClassValue = string | false | null | undefined | Record<string, unknown> | ClassValue[];
|
|
34
|
+
export function cls(...args: ClassValue[]): string;
|
|
35
|
+
export function style(obj: string | Record<string, string | number | null | undefined>): string;
|
|
36
|
+
/** Calls `fn` once, with the last call's arguments, `ms` after the calls stop. */
|
|
37
|
+
export function debounce<T extends (...args: any[]) => any>(fn: T, ms: number): (...args: Parameters<T>) => void;
|
|
38
|
+
/** Calls `fn` at once, then at most once per `ms`; a call inside the window is dropped. */
|
|
39
|
+
export function throttle<T extends (...args: any[]) => any>(fn: T, ms: number): (...args: Parameters<T>) => void;
|
|
40
|
+
export function useMediaQuery(query: string): Signal<boolean>;
|
|
41
|
+
export function useLocalStorage<T>(key: string, initial: T): Signal<T>;
|
|
42
|
+
export function useClickOutside(ref: { current?: Element | null } | Element, handler: (e: Event) => void): void;
|
|
43
|
+
/** Remove the head tags <Head> manages. */
|
|
44
|
+
export function clearHead(): void;
|