@shadow-js/core 0.1.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 +386 -0
- package/dist/chunk-6Y3CCWOY.js +887 -0
- package/dist/chunk-6Y3CCWOY.js.map +1 -0
- package/dist/chunk-B5FTYDUG.js +3 -0
- package/dist/chunk-B5FTYDUG.js.map +1 -0
- package/dist/index.cjs +2000 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +609 -0
- package/dist/index.d.ts +609 -0
- package/dist/index.js +1094 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-Bugil6CJ.d.cts +151 -0
- package/dist/jsx-Bugil6CJ.d.ts +151 -0
- package/dist/jsx-dev-runtime.cjs +742 -0
- package/dist/jsx-dev-runtime.cjs.map +1 -0
- package/dist/jsx-dev-runtime.d.cts +2 -0
- package/dist/jsx-dev-runtime.d.ts +2 -0
- package/dist/jsx-dev-runtime.js +4 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.cjs +742 -0
- package/dist/jsx-runtime.cjs.map +1 -0
- package/dist/jsx-runtime.d.cts +36 -0
- package/dist/jsx-runtime.d.ts +36 -0
- package/dist/jsx-runtime.js +4 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/package.json +66 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1094 @@
|
|
|
1
|
+
import { ERRORS, useEffect, getCurrentScope, warn, onCleanup, jsx, disposeBetween, untrack, disposeAllChildren, isComponentThunk, __currentEffect, __currentEffectDeps } from './chunk-6Y3CCWOY.js';
|
|
2
|
+
export { Fragment, Match, Switch, jsx, jsxDEV, jsxs, onCleanup, useEffect } from './chunk-6Y3CCWOY.js';
|
|
3
|
+
|
|
4
|
+
// src/reactivity/scheduler.ts
|
|
5
|
+
var pending = false;
|
|
6
|
+
var queue = /* @__PURE__ */ new Set();
|
|
7
|
+
function flush() {
|
|
8
|
+
pending = false;
|
|
9
|
+
const tasks = Array.from(queue);
|
|
10
|
+
queue.clear();
|
|
11
|
+
for (const fn of tasks) {
|
|
12
|
+
try {
|
|
13
|
+
fn();
|
|
14
|
+
} catch {
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function scheduleEffect(fn) {
|
|
19
|
+
queue.add(fn);
|
|
20
|
+
if (!pending) {
|
|
21
|
+
pending = true;
|
|
22
|
+
queueMicrotask(flush);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/reactivity/hooks/useStore.ts
|
|
27
|
+
function useStore(initialValue, opts) {
|
|
28
|
+
var _a;
|
|
29
|
+
let value = initialValue;
|
|
30
|
+
const hot = typeof import.meta !== "undefined" ? import.meta.hot : null;
|
|
31
|
+
if (opts?.hmrKey && hot?.data) {
|
|
32
|
+
const bucket = (_a = hot.data).__shadowStores || (_a.__shadowStores = /* @__PURE__ */ Object.create(null));
|
|
33
|
+
if (opts.hmrKey in bucket) {
|
|
34
|
+
value = bucket[opts.hmrKey];
|
|
35
|
+
}
|
|
36
|
+
hot.accept?.();
|
|
37
|
+
hot.dispose?.(() => {
|
|
38
|
+
bucket[opts.hmrKey] = value;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
42
|
+
const read = () => {
|
|
43
|
+
if (__currentEffect) {
|
|
44
|
+
subscribers.add(__currentEffect);
|
|
45
|
+
}
|
|
46
|
+
if (__currentEffectDeps) {
|
|
47
|
+
__currentEffectDeps.add(subscribers);
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
};
|
|
51
|
+
const write = (newValue) => {
|
|
52
|
+
value = typeof newValue === "function" ? newValue(value) : newValue;
|
|
53
|
+
if (value !== newValue) {
|
|
54
|
+
subscribers.forEach((effect) => scheduleEffect(effect));
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const store = (() => read());
|
|
58
|
+
Object.defineProperty(store, "value", {
|
|
59
|
+
get: read,
|
|
60
|
+
set: write
|
|
61
|
+
});
|
|
62
|
+
store.__isStore = true;
|
|
63
|
+
return [store, write];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/reactivity/hooks/useData.ts
|
|
67
|
+
function useData(source, fetcher, deps) {
|
|
68
|
+
if (fetcher !== void 0 && typeof fetcher !== "function") {
|
|
69
|
+
throw ERRORS.HOOK_INVALID_ARGUMENT("useData", "fetcher", "function");
|
|
70
|
+
}
|
|
71
|
+
if (deps !== void 0) {
|
|
72
|
+
if (!Array.isArray(deps) || deps.some((d) => typeof d !== "function")) {
|
|
73
|
+
throw ERRORS.HOOK_INVALID_DEPS("useData");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const getSource = typeof source === "function" ? source : () => source;
|
|
77
|
+
const [state, setState] = useStore({
|
|
78
|
+
data: void 0,
|
|
79
|
+
loading: !!fetcher,
|
|
80
|
+
error: null,
|
|
81
|
+
lastSource: getSource(),
|
|
82
|
+
initialized: false
|
|
83
|
+
});
|
|
84
|
+
let currentFetchId = 0;
|
|
85
|
+
async function runFetch() {
|
|
86
|
+
if (!fetcher) return;
|
|
87
|
+
const fetchId = ++currentFetchId;
|
|
88
|
+
const currentSource = getSource();
|
|
89
|
+
setState({
|
|
90
|
+
...state(),
|
|
91
|
+
loading: true,
|
|
92
|
+
error: null
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
const result = await fetcher(currentSource);
|
|
96
|
+
if (fetchId === currentFetchId) {
|
|
97
|
+
setState({
|
|
98
|
+
data: result,
|
|
99
|
+
loading: false,
|
|
100
|
+
error: null,
|
|
101
|
+
lastSource: currentSource,
|
|
102
|
+
initialized: true
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
} catch (err) {
|
|
106
|
+
if (fetchId === currentFetchId) {
|
|
107
|
+
setState({
|
|
108
|
+
...state(),
|
|
109
|
+
error: err,
|
|
110
|
+
loading: false,
|
|
111
|
+
lastSource: currentSource,
|
|
112
|
+
initialized: true
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
useEffect(
|
|
118
|
+
() => {
|
|
119
|
+
runFetch();
|
|
120
|
+
},
|
|
121
|
+
deps || [() => getSource()]
|
|
122
|
+
);
|
|
123
|
+
const data = (() => state().data);
|
|
124
|
+
data.loading = () => state().loading;
|
|
125
|
+
data.error = () => state().error;
|
|
126
|
+
data.mutate = (value) => {
|
|
127
|
+
const newValue = typeof value === "function" ? value(state().data) : value;
|
|
128
|
+
setState({
|
|
129
|
+
...state(),
|
|
130
|
+
data: newValue,
|
|
131
|
+
loading: false,
|
|
132
|
+
error: null,
|
|
133
|
+
initialized: true
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
data.refetch = async () => {
|
|
137
|
+
await runFetch();
|
|
138
|
+
};
|
|
139
|
+
return data;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/reactivity/hooks/useId.ts
|
|
143
|
+
var globalIdCounter = 0;
|
|
144
|
+
function generateNextId() {
|
|
145
|
+
globalIdCounter += 1;
|
|
146
|
+
return String(globalIdCounter);
|
|
147
|
+
}
|
|
148
|
+
function useId() {
|
|
149
|
+
const next = generateNextId();
|
|
150
|
+
return `sfid-${next}`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/reactivity/hooks/useMemo.ts
|
|
154
|
+
function useMemo(fn) {
|
|
155
|
+
if (typeof fn !== "function") {
|
|
156
|
+
throw ERRORS.HOOK_INVALID_ARGUMENT("useMemo", "fn", "function");
|
|
157
|
+
}
|
|
158
|
+
const [get, set] = useStore(fn());
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
set(fn());
|
|
161
|
+
});
|
|
162
|
+
return get;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/reactivity/hooks/useOptimistic.ts
|
|
166
|
+
function isStore(value) {
|
|
167
|
+
return typeof value === "function" && value.__isStore === true;
|
|
168
|
+
}
|
|
169
|
+
function useOptimistic(base, reducer) {
|
|
170
|
+
if (reducer !== void 0 && typeof reducer !== "function") {
|
|
171
|
+
throw ERRORS.HOOK_INVALID_REDUCER("useOptimistic");
|
|
172
|
+
}
|
|
173
|
+
const getBaseValue = () => isStore(base) ? base() : base;
|
|
174
|
+
const [optimistic, setOptimistic] = useStore(getBaseValue());
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
if (isStore(base)) {
|
|
177
|
+
setOptimistic(base());
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
const apply = (arg) => {
|
|
181
|
+
if (reducer) {
|
|
182
|
+
setOptimistic(reducer(optimistic(), arg));
|
|
183
|
+
} else {
|
|
184
|
+
setOptimistic(arg);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
return [optimistic, apply];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// src/reactivity/hooks/onMount.ts
|
|
191
|
+
function onMount(fn) {
|
|
192
|
+
if (typeof fn !== "function") {
|
|
193
|
+
throw ERRORS.HOOK_INVALID_ARGUMENT("onMount", "fn", "function");
|
|
194
|
+
}
|
|
195
|
+
if (!getCurrentScope()) {
|
|
196
|
+
throw ERRORS.HOOK_OUTSIDE_COMPONENT("onMount");
|
|
197
|
+
}
|
|
198
|
+
fn();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/runtime/For.ts
|
|
202
|
+
function For(props) {
|
|
203
|
+
const fragment = document.createDocumentFragment();
|
|
204
|
+
const start = document.createComment("for-s");
|
|
205
|
+
const end = document.createComment("for-e");
|
|
206
|
+
fragment.appendChild(start);
|
|
207
|
+
fragment.appendChild(end);
|
|
208
|
+
if (typeof props.children !== "function") {
|
|
209
|
+
throw ERRORS.FOR_CHILDREN_MUST_BE_FUNCTION();
|
|
210
|
+
}
|
|
211
|
+
const keyToBlock = /* @__PURE__ */ new Map();
|
|
212
|
+
const objectIdentityToKey = /* @__PURE__ */ new WeakMap();
|
|
213
|
+
let objectIdentityCounter = 0;
|
|
214
|
+
const getParent = () => start.parentNode;
|
|
215
|
+
const toNode2 = (value) => {
|
|
216
|
+
if (value === null || value === void 0 || typeof value === "boolean") {
|
|
217
|
+
return document.createComment("");
|
|
218
|
+
}
|
|
219
|
+
if (typeof value === "function") {
|
|
220
|
+
try {
|
|
221
|
+
if (isComponentThunk(value)) {
|
|
222
|
+
return value();
|
|
223
|
+
}
|
|
224
|
+
return toNode2(value());
|
|
225
|
+
} catch {
|
|
226
|
+
return document.createComment("error");
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (typeof value === "object" && value !== null && "nodeType" in value)
|
|
230
|
+
return value;
|
|
231
|
+
if (Array.isArray(value)) {
|
|
232
|
+
const df = document.createDocumentFragment();
|
|
233
|
+
value.forEach((v) => {
|
|
234
|
+
const n = toNode2(v);
|
|
235
|
+
if (n) df.appendChild(n);
|
|
236
|
+
});
|
|
237
|
+
return df;
|
|
238
|
+
}
|
|
239
|
+
return document.createTextNode(String(value));
|
|
240
|
+
};
|
|
241
|
+
const appendChild = (parent, child, before) => {
|
|
242
|
+
if (Array.isArray(child)) {
|
|
243
|
+
child.forEach((n) => appendChild(parent, n, before));
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (child === null || child === void 0 || typeof child === "boolean")
|
|
247
|
+
return;
|
|
248
|
+
if (typeof child === "function") {
|
|
249
|
+
try {
|
|
250
|
+
if (isComponentThunk(child)) {
|
|
251
|
+
parent.insertBefore(child(), before);
|
|
252
|
+
} else {
|
|
253
|
+
appendChild(parent, child(), before);
|
|
254
|
+
}
|
|
255
|
+
} catch {
|
|
256
|
+
parent.insertBefore(document.createComment("error"), before);
|
|
257
|
+
}
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (typeof child === "object" && child !== null && "nodeType" in child) {
|
|
261
|
+
parent.insertBefore(child, before);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
parent.insertBefore(document.createTextNode(String(child)), before);
|
|
265
|
+
};
|
|
266
|
+
const createBlockAt = (before, content) => {
|
|
267
|
+
const s = document.createComment("for-item-s");
|
|
268
|
+
const e = document.createComment("for-item-e");
|
|
269
|
+
const parent = getParent();
|
|
270
|
+
if (!parent) return { start: s, end: e };
|
|
271
|
+
parent.insertBefore(s, before);
|
|
272
|
+
appendChild(parent, content, before);
|
|
273
|
+
parent.insertBefore(e, before);
|
|
274
|
+
return { start: s, end: e };
|
|
275
|
+
};
|
|
276
|
+
const removeBlock = (block) => {
|
|
277
|
+
const parent = getParent();
|
|
278
|
+
if (!parent) return;
|
|
279
|
+
disposeBetween(block.start, block.end);
|
|
280
|
+
parent.removeChild(block.start);
|
|
281
|
+
parent.removeChild(block.end);
|
|
282
|
+
};
|
|
283
|
+
const moveBlockBefore = (block, before) => {
|
|
284
|
+
const parent = getParent();
|
|
285
|
+
if (!parent) return;
|
|
286
|
+
if (block.start === before) return;
|
|
287
|
+
const afterEnd = block.end.nextSibling;
|
|
288
|
+
let node = block.start;
|
|
289
|
+
while (node && node !== afterEnd) {
|
|
290
|
+
const next = node.nextSibling;
|
|
291
|
+
parent.insertBefore(node, before);
|
|
292
|
+
node = next;
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
const defaultKey = (item, index) => {
|
|
296
|
+
if (item && typeof item === "object") {
|
|
297
|
+
let k = objectIdentityToKey.get(item);
|
|
298
|
+
if (!k) {
|
|
299
|
+
k = `o:${++objectIdentityCounter}`;
|
|
300
|
+
objectIdentityToKey.set(item, k);
|
|
301
|
+
}
|
|
302
|
+
return k;
|
|
303
|
+
}
|
|
304
|
+
return `v:${String(item)}@${index}`;
|
|
305
|
+
};
|
|
306
|
+
const update = () => {
|
|
307
|
+
const parent = getParent();
|
|
308
|
+
if (!parent) return;
|
|
309
|
+
const source = typeof props.each === "function" ? props.each() : props.each;
|
|
310
|
+
if (!Array.isArray(source)) {
|
|
311
|
+
throw ERRORS.FOR_EACH_REQUIRES_ARRAY();
|
|
312
|
+
}
|
|
313
|
+
const expectedKeys = [];
|
|
314
|
+
for (let i = 0; i < source.length; i++) {
|
|
315
|
+
expectedKeys.push(defaultKey(source[i], i));
|
|
316
|
+
}
|
|
317
|
+
const expectedSet = new Set(expectedKeys);
|
|
318
|
+
for (const [k, block] of keyToBlock.entries()) {
|
|
319
|
+
if (!expectedSet.has(k)) {
|
|
320
|
+
removeBlock(block);
|
|
321
|
+
keyToBlock.delete(k);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const s = new Set(expectedKeys);
|
|
325
|
+
warn(
|
|
326
|
+
s.size === expectedKeys.length,
|
|
327
|
+
"<For> detected duplicate keys. This can cause incorrect reordering."
|
|
328
|
+
);
|
|
329
|
+
let cursor = start.nextSibling;
|
|
330
|
+
for (let i = 0; i < source.length; i++) {
|
|
331
|
+
const item = source[i];
|
|
332
|
+
const key = expectedKeys[i];
|
|
333
|
+
const existing = keyToBlock.get(key);
|
|
334
|
+
if (existing) {
|
|
335
|
+
if (existing.start !== cursor) moveBlockBefore(existing, cursor);
|
|
336
|
+
cursor = existing.end.nextSibling;
|
|
337
|
+
} else {
|
|
338
|
+
const content = props.children(item, i);
|
|
339
|
+
const block = createBlockAt(cursor, toNode2(content));
|
|
340
|
+
keyToBlock.set(key, block);
|
|
341
|
+
cursor = block.end.nextSibling;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
update();
|
|
346
|
+
useEffect(update);
|
|
347
|
+
return fragment;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// src/runtime/Show.ts
|
|
351
|
+
function Show(props) {
|
|
352
|
+
if (typeof props.when !== "boolean" && typeof props.when !== "function") {
|
|
353
|
+
throw ERRORS.SHOW_INVALID_WHEN();
|
|
354
|
+
}
|
|
355
|
+
warn(
|
|
356
|
+
props.children !== void 0 || props.fallback !== void 0,
|
|
357
|
+
"<Show> has no children or fallback; renders empty content."
|
|
358
|
+
);
|
|
359
|
+
const fragment = document.createDocumentFragment();
|
|
360
|
+
const start = document.createComment("show-s");
|
|
361
|
+
const end = document.createComment("show-e");
|
|
362
|
+
fragment.appendChild(start);
|
|
363
|
+
fragment.appendChild(end);
|
|
364
|
+
const getParent = () => start.parentNode;
|
|
365
|
+
const toNode2 = (value) => {
|
|
366
|
+
if (typeof value === "function") {
|
|
367
|
+
try {
|
|
368
|
+
if (isComponentThunk(value)) {
|
|
369
|
+
return value();
|
|
370
|
+
}
|
|
371
|
+
return toNode2(value());
|
|
372
|
+
} catch {
|
|
373
|
+
return document.createComment("error");
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (value === null || value === void 0 || typeof value === "boolean") {
|
|
377
|
+
return document.createComment("");
|
|
378
|
+
}
|
|
379
|
+
if (typeof value === "object" && value !== null && "nodeType" in value)
|
|
380
|
+
return value;
|
|
381
|
+
if (Array.isArray(value)) {
|
|
382
|
+
const df = document.createDocumentFragment();
|
|
383
|
+
value.forEach((v) => df.appendChild(toNode2(v)));
|
|
384
|
+
return df;
|
|
385
|
+
}
|
|
386
|
+
return document.createTextNode(String(value));
|
|
387
|
+
};
|
|
388
|
+
const detachBetween = () => {
|
|
389
|
+
const parent = getParent();
|
|
390
|
+
if (!parent) return [];
|
|
391
|
+
const nodes = [];
|
|
392
|
+
let cur = start.nextSibling;
|
|
393
|
+
while (cur && cur !== end) {
|
|
394
|
+
const next = cur.nextSibling;
|
|
395
|
+
nodes.push(cur);
|
|
396
|
+
parent.removeChild(cur);
|
|
397
|
+
cur = next;
|
|
398
|
+
}
|
|
399
|
+
return nodes;
|
|
400
|
+
};
|
|
401
|
+
const insertNodes = (nodes) => {
|
|
402
|
+
const parent = getParent();
|
|
403
|
+
if (!parent) return;
|
|
404
|
+
nodes.forEach((n) => parent.insertBefore(n, end));
|
|
405
|
+
};
|
|
406
|
+
const materialize = (content) => {
|
|
407
|
+
const n = toNode2(content);
|
|
408
|
+
if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
|
409
|
+
const arr = [];
|
|
410
|
+
let c = n.firstChild;
|
|
411
|
+
while (c) {
|
|
412
|
+
const next = c.nextSibling;
|
|
413
|
+
arr.push(c);
|
|
414
|
+
c = next;
|
|
415
|
+
}
|
|
416
|
+
return arr;
|
|
417
|
+
}
|
|
418
|
+
return [n];
|
|
419
|
+
};
|
|
420
|
+
let lastCond = null;
|
|
421
|
+
let cachedTrueContent = null;
|
|
422
|
+
let cachedFalseContent = null;
|
|
423
|
+
const computeCond = () => {
|
|
424
|
+
try {
|
|
425
|
+
return typeof props.when === "function" ? props.when() : props.when;
|
|
426
|
+
} catch {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
const shouldUnmount = props.unmount === void 0 ? false : !!props.unmount;
|
|
431
|
+
const update = () => {
|
|
432
|
+
const parent = getParent();
|
|
433
|
+
if (!parent) return;
|
|
434
|
+
const cond = computeCond();
|
|
435
|
+
const mat = (c) => untrack(() => materialize(c));
|
|
436
|
+
if (lastCond === null) {
|
|
437
|
+
lastCond = cond;
|
|
438
|
+
if (cond) {
|
|
439
|
+
insertNodes(mat(props.children));
|
|
440
|
+
} else if (props.fallback !== void 0) {
|
|
441
|
+
insertNodes(mat(props.fallback));
|
|
442
|
+
}
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (cond === lastCond) return;
|
|
446
|
+
if (shouldUnmount) {
|
|
447
|
+
disposeBetween(start, end);
|
|
448
|
+
if (cond) {
|
|
449
|
+
insertNodes(mat(props.children));
|
|
450
|
+
} else if (props.fallback !== void 0) {
|
|
451
|
+
insertNodes(mat(props.fallback));
|
|
452
|
+
}
|
|
453
|
+
} else {
|
|
454
|
+
disposeBetween(start, end);
|
|
455
|
+
const detachedNodes = detachBetween();
|
|
456
|
+
if (lastCond) {
|
|
457
|
+
cachedTrueContent = detachedNodes;
|
|
458
|
+
} else if (props.fallback !== void 0) {
|
|
459
|
+
cachedFalseContent = detachedNodes;
|
|
460
|
+
}
|
|
461
|
+
let toInsert = [];
|
|
462
|
+
if (cond) {
|
|
463
|
+
toInsert = mat(cachedTrueContent || props.children);
|
|
464
|
+
cachedTrueContent = null;
|
|
465
|
+
} else if (props.fallback !== void 0) {
|
|
466
|
+
toInsert = mat(cachedFalseContent || props.fallback);
|
|
467
|
+
cachedFalseContent = null;
|
|
468
|
+
}
|
|
469
|
+
if (toInsert.length) insertNodes(toInsert);
|
|
470
|
+
}
|
|
471
|
+
lastCond = cond;
|
|
472
|
+
};
|
|
473
|
+
update();
|
|
474
|
+
useEffect(update);
|
|
475
|
+
return fragment;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// src/runtime/Title.ts
|
|
479
|
+
function Title(props) {
|
|
480
|
+
const prevTitle = document.title;
|
|
481
|
+
let lastSet = null;
|
|
482
|
+
const toText = (v) => {
|
|
483
|
+
if (v == null || typeof v === "boolean") return "";
|
|
484
|
+
if (typeof v === "string" || typeof v === "number") return String(v);
|
|
485
|
+
if (typeof v === "function") {
|
|
486
|
+
if (isComponentThunk(v)) {
|
|
487
|
+
warn(
|
|
488
|
+
false,
|
|
489
|
+
"<Title> children should be text; component children are ignored."
|
|
490
|
+
);
|
|
491
|
+
return "";
|
|
492
|
+
}
|
|
493
|
+
try {
|
|
494
|
+
return toText(v());
|
|
495
|
+
} catch {
|
|
496
|
+
return "";
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (Array.isArray(v)) {
|
|
500
|
+
return v.map((x) => toText(x)).join("");
|
|
501
|
+
}
|
|
502
|
+
if (typeof v === "object" && v !== null && "nodeType" in v) {
|
|
503
|
+
try {
|
|
504
|
+
return v.textContent ?? "";
|
|
505
|
+
} catch {
|
|
506
|
+
return "";
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return String(v);
|
|
510
|
+
};
|
|
511
|
+
useEffect(() => {
|
|
512
|
+
const next = toText(props.children);
|
|
513
|
+
document.title = next;
|
|
514
|
+
lastSet = next;
|
|
515
|
+
});
|
|
516
|
+
onCleanup(() => {
|
|
517
|
+
if (lastSet !== null && document.title === lastSet) {
|
|
518
|
+
document.title = prevTitle;
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
return document.createDocumentFragment();
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// src/runtime/lazy.ts
|
|
525
|
+
function initInsertedTree(node) {
|
|
526
|
+
if (!node) return;
|
|
527
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
528
|
+
node?.__shadow_init?.();
|
|
529
|
+
}
|
|
530
|
+
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
|
531
|
+
let c = node.firstChild;
|
|
532
|
+
while (c) {
|
|
533
|
+
initInsertedTree(c);
|
|
534
|
+
c = c.nextSibling;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
var componentCache = /* @__PURE__ */ new WeakMap();
|
|
539
|
+
var promiseCache = /* @__PURE__ */ new WeakMap();
|
|
540
|
+
function lazy(importFn, options = {}) {
|
|
541
|
+
const { retries = 3, retryDelay = 1e3 } = options;
|
|
542
|
+
const load = async (attemptsLeft) => {
|
|
543
|
+
try {
|
|
544
|
+
const module = await importFn();
|
|
545
|
+
let Component;
|
|
546
|
+
if (module && typeof module === "object" && module !== null && "default" in module && module.default !== void 0) {
|
|
547
|
+
Component = module.default;
|
|
548
|
+
} else if (module && typeof module === "function") {
|
|
549
|
+
Component = module;
|
|
550
|
+
} else {
|
|
551
|
+
throw ERRORS.LAZY_INVALID_EXPORT();
|
|
552
|
+
}
|
|
553
|
+
componentCache.set(importFn, Component);
|
|
554
|
+
} catch (err) {
|
|
555
|
+
if (attemptsLeft > 0) {
|
|
556
|
+
await new Promise((r) => setTimeout(r, retryDelay));
|
|
557
|
+
return load(attemptsLeft - 1);
|
|
558
|
+
}
|
|
559
|
+
throw ERRORS.LAZY_FAILED_AFTER_ATTEMPTS(retries, err);
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
return function LazyWrapper(props) {
|
|
563
|
+
if (componentCache.has(importFn)) {
|
|
564
|
+
const C = componentCache.get(importFn);
|
|
565
|
+
return typeof C === "function" ? jsx(C, props ?? {}) : C;
|
|
566
|
+
}
|
|
567
|
+
const frag = document.createDocumentFragment();
|
|
568
|
+
const start = document.createComment("lazy-s");
|
|
569
|
+
const end = document.createComment("lazy-e");
|
|
570
|
+
frag.appendChild(start);
|
|
571
|
+
frag.appendChild(end);
|
|
572
|
+
let p = promiseCache.get(importFn);
|
|
573
|
+
if (!p) {
|
|
574
|
+
p = load(retries);
|
|
575
|
+
promiseCache.set(importFn, p);
|
|
576
|
+
}
|
|
577
|
+
const meta = {
|
|
578
|
+
pending: true,
|
|
579
|
+
promise: p,
|
|
580
|
+
onResolve: /* @__PURE__ */ new Set()
|
|
581
|
+
};
|
|
582
|
+
frag.__shadow_lazy = meta;
|
|
583
|
+
p.then(
|
|
584
|
+
() => {
|
|
585
|
+
meta.pending = false;
|
|
586
|
+
const C = componentCache.get(importFn);
|
|
587
|
+
const parent = start.parentNode;
|
|
588
|
+
if (!parent) {
|
|
589
|
+
meta.onResolve.forEach((fn) => {
|
|
590
|
+
try {
|
|
591
|
+
fn();
|
|
592
|
+
} catch {
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
disposeBetween(start, end);
|
|
598
|
+
let node = typeof C === "function" ? jsx(C, props ?? {}) : C;
|
|
599
|
+
if (typeof node === "function" && node.__isComponent) {
|
|
600
|
+
try {
|
|
601
|
+
node = node();
|
|
602
|
+
} catch {
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
untrack(() => {
|
|
606
|
+
if (node && typeof node === "object" && "nodeType" in node) {
|
|
607
|
+
parent.insertBefore(node, end);
|
|
608
|
+
initInsertedTree(node);
|
|
609
|
+
} else if (node !== null && node !== void 0) {
|
|
610
|
+
parent.insertBefore(document.createTextNode(String(node)), end);
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
meta.onResolve.forEach((fn) => {
|
|
614
|
+
try {
|
|
615
|
+
fn();
|
|
616
|
+
} catch {
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
meta.onResolve.clear();
|
|
620
|
+
},
|
|
621
|
+
() => {
|
|
622
|
+
}
|
|
623
|
+
);
|
|
624
|
+
return frag;
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// src/runtime/Portal.ts
|
|
629
|
+
function createReactiveSectionBetweenAnchors(anchorEnd, valueOrFunction) {
|
|
630
|
+
const anchorParent = anchorEnd.parentNode;
|
|
631
|
+
if (!anchorParent) return;
|
|
632
|
+
const startComment = document.createComment("p-r-s");
|
|
633
|
+
const endComment = document.createComment("p-r-e");
|
|
634
|
+
anchorParent.insertBefore(startComment, anchorEnd);
|
|
635
|
+
anchorParent.insertBefore(endComment, anchorEnd);
|
|
636
|
+
const insertBeforeEnd = (end, content) => {
|
|
637
|
+
const parentNode = startComment.parentNode;
|
|
638
|
+
if (!parentNode) return;
|
|
639
|
+
const insert = (v) => {
|
|
640
|
+
if (v === null || v === void 0 || typeof v === "boolean") return;
|
|
641
|
+
if (typeof v === "string" || typeof v === "number") {
|
|
642
|
+
parentNode.insertBefore(document.createTextNode(String(v)), end);
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
if (Array.isArray(v)) {
|
|
646
|
+
v.forEach((x) => insert(x));
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
if (typeof v === "object" && v !== null && "nodeType" in v) {
|
|
650
|
+
parentNode.insertBefore(v, end);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
parentNode.insertBefore(document.createTextNode(String(v)), end);
|
|
654
|
+
};
|
|
655
|
+
insert(content);
|
|
656
|
+
};
|
|
657
|
+
const update = () => {
|
|
658
|
+
const parentNode = startComment.parentNode;
|
|
659
|
+
if (!parentNode) return;
|
|
660
|
+
const newContent = untrack(
|
|
661
|
+
() => typeof valueOrFunction === "function" ? valueOrFunction() : valueOrFunction
|
|
662
|
+
);
|
|
663
|
+
disposeBetween(startComment, endComment);
|
|
664
|
+
untrack(() => insertBeforeEnd(endComment, newContent));
|
|
665
|
+
};
|
|
666
|
+
update();
|
|
667
|
+
useEffect(update);
|
|
668
|
+
}
|
|
669
|
+
function Portal(props) {
|
|
670
|
+
const { mount, children, ref } = props || {};
|
|
671
|
+
if (!mount) {
|
|
672
|
+
throw ERRORS.PORTAL_MOUNT_REQUIRED();
|
|
673
|
+
}
|
|
674
|
+
if (ref) {
|
|
675
|
+
if (typeof ref === "function") {
|
|
676
|
+
try {
|
|
677
|
+
ref(mount);
|
|
678
|
+
} catch {
|
|
679
|
+
}
|
|
680
|
+
} else if (ref && typeof ref === "object" && "current" in ref) {
|
|
681
|
+
try {
|
|
682
|
+
ref.current = mount;
|
|
683
|
+
} catch {
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
const startAnchor = document.createComment("p-s");
|
|
688
|
+
const endAnchor = document.createComment("p-e");
|
|
689
|
+
mount.appendChild(startAnchor);
|
|
690
|
+
mount.appendChild(endAnchor);
|
|
691
|
+
if (children !== void 0) {
|
|
692
|
+
createReactiveSectionBetweenAnchors(endAnchor, children);
|
|
693
|
+
}
|
|
694
|
+
onCleanup(() => {
|
|
695
|
+
const parent = startAnchor.parentNode;
|
|
696
|
+
if (!parent) return;
|
|
697
|
+
disposeBetween(startAnchor, endAnchor);
|
|
698
|
+
parent.removeChild(startAnchor);
|
|
699
|
+
parent.removeChild(endAnchor);
|
|
700
|
+
});
|
|
701
|
+
return document.createDocumentFragment();
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// src/runtime/Suspense.ts
|
|
705
|
+
function isThenable(value) {
|
|
706
|
+
return value !== null && typeof value === "object" && "then" in value && typeof value.then === "function";
|
|
707
|
+
}
|
|
708
|
+
function toNode(value) {
|
|
709
|
+
if (value === null || value === void 0) return null;
|
|
710
|
+
if (isComponentThunk(value)) {
|
|
711
|
+
try {
|
|
712
|
+
return value();
|
|
713
|
+
} catch {
|
|
714
|
+
return document.createComment("error");
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
if (typeof value === "object" && value !== null && "nodeType" in value)
|
|
718
|
+
return value;
|
|
719
|
+
if (Array.isArray(value)) {
|
|
720
|
+
const df = document.createDocumentFragment();
|
|
721
|
+
value.forEach((v) => {
|
|
722
|
+
const n = toNode(v);
|
|
723
|
+
if (n) df.appendChild(n);
|
|
724
|
+
});
|
|
725
|
+
return df;
|
|
726
|
+
}
|
|
727
|
+
if (typeof value === "function") {
|
|
728
|
+
try {
|
|
729
|
+
return toNode(value());
|
|
730
|
+
} catch {
|
|
731
|
+
return document.createComment("error");
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
735
|
+
return document.createTextNode(String(value));
|
|
736
|
+
}
|
|
737
|
+
return document.createTextNode(String(value));
|
|
738
|
+
}
|
|
739
|
+
function isSuspenseFragmentNode(node) {
|
|
740
|
+
if (!node || typeof node !== "object" || !node.nodeType || node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE)
|
|
741
|
+
return false;
|
|
742
|
+
const df = node;
|
|
743
|
+
for (let i = 0; i < df.childNodes.length; i++) {
|
|
744
|
+
const n = df.childNodes[i];
|
|
745
|
+
if (n.nodeType === Node.COMMENT_NODE && n.textContent === "suspense-s") {
|
|
746
|
+
return true;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return false;
|
|
750
|
+
}
|
|
751
|
+
function getLazyMeta(node) {
|
|
752
|
+
if (node && typeof node === "object" && node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && node.__shadow_lazy && typeof node.__shadow_lazy === "object") {
|
|
753
|
+
return node.__shadow_lazy;
|
|
754
|
+
}
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
function Suspense(props) {
|
|
758
|
+
const { fallback, children } = props || {};
|
|
759
|
+
const fragment = document.createDocumentFragment();
|
|
760
|
+
const startComment = document.createComment("suspense-s");
|
|
761
|
+
const endComment = document.createComment("suspense-e");
|
|
762
|
+
fragment.appendChild(startComment);
|
|
763
|
+
fragment.appendChild(endComment);
|
|
764
|
+
const childrenArray = () => children === void 0 ? [] : Array.isArray(children) ? children : [children];
|
|
765
|
+
const clearBetween = () => {
|
|
766
|
+
disposeBetween(startComment, endComment);
|
|
767
|
+
};
|
|
768
|
+
let slots = [];
|
|
769
|
+
let anchors = null;
|
|
770
|
+
let fallbackVisible = false;
|
|
771
|
+
let stageOneCompleted = false;
|
|
772
|
+
const showFallback = () => {
|
|
773
|
+
const parent = startComment.parentNode;
|
|
774
|
+
if (!parent) return;
|
|
775
|
+
clearBetween();
|
|
776
|
+
if (fallback !== void 0) {
|
|
777
|
+
const node = toNode(
|
|
778
|
+
typeof fallback === "function" ? fallback() : fallback
|
|
779
|
+
);
|
|
780
|
+
if (node) parent.insertBefore(node, endComment);
|
|
781
|
+
}
|
|
782
|
+
fallbackVisible = true;
|
|
783
|
+
};
|
|
784
|
+
const ensureAnchors = () => {
|
|
785
|
+
if (anchors) return;
|
|
786
|
+
const parent = startComment.parentNode;
|
|
787
|
+
if (!parent) return;
|
|
788
|
+
const arr = childrenArray();
|
|
789
|
+
anchors = arr.map((_, i) => ({
|
|
790
|
+
start: document.createComment(`suspense-slot-s:${i}`),
|
|
791
|
+
end: document.createComment(`suspense-slot-e:${i}`)
|
|
792
|
+
}));
|
|
793
|
+
anchors.forEach((a) => {
|
|
794
|
+
parent.insertBefore(a.start, endComment);
|
|
795
|
+
parent.insertBefore(a.end, endComment);
|
|
796
|
+
});
|
|
797
|
+
};
|
|
798
|
+
const setSlotContent = (index, node) => {
|
|
799
|
+
if (!anchors) return;
|
|
800
|
+
const parent = startComment.parentNode;
|
|
801
|
+
if (!parent) return;
|
|
802
|
+
const a = anchors[index];
|
|
803
|
+
if (!a) return;
|
|
804
|
+
disposeBetween(a.start, a.end);
|
|
805
|
+
if (node) parent.insertBefore(node, a.end);
|
|
806
|
+
};
|
|
807
|
+
const maybeReveal = () => {
|
|
808
|
+
if (stageOneCompleted) return;
|
|
809
|
+
for (let i = 0; i < slots.length; i++) {
|
|
810
|
+
if (!slots[i].isNested && !slots[i].resolved) return;
|
|
811
|
+
}
|
|
812
|
+
stageOneCompleted = true;
|
|
813
|
+
const parent = startComment.parentNode;
|
|
814
|
+
if (!parent) return;
|
|
815
|
+
if (fallbackVisible) {
|
|
816
|
+
clearBetween();
|
|
817
|
+
fallbackVisible = false;
|
|
818
|
+
}
|
|
819
|
+
ensureAnchors();
|
|
820
|
+
for (let i = 0; i < slots.length; i++) {
|
|
821
|
+
if (!slots[i].isNested) {
|
|
822
|
+
setSlotContent(i, slots[i].node);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
for (let i = 0; i < slots.length; i++) {
|
|
826
|
+
if (slots[i].isNested) {
|
|
827
|
+
setSlotContent(i, slots[i].node);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
const inspectChild = (index, value) => {
|
|
832
|
+
const finish = (resolvedValue) => {
|
|
833
|
+
const node = toNode(resolvedValue);
|
|
834
|
+
slots[index].resolved = true;
|
|
835
|
+
slots[index].node = node;
|
|
836
|
+
maybeReveal();
|
|
837
|
+
};
|
|
838
|
+
if (isThenable(value)) {
|
|
839
|
+
slots[index].promise = value;
|
|
840
|
+
value.then(
|
|
841
|
+
(v) => finish(v),
|
|
842
|
+
() => finish(null)
|
|
843
|
+
// treat rejection as resolved-null to avoid deadlock
|
|
844
|
+
);
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
const meta = getLazyMeta(value);
|
|
848
|
+
if (meta && meta.pending) {
|
|
849
|
+
slots[index].promise = meta.promise;
|
|
850
|
+
const onRes = () => finish(value);
|
|
851
|
+
meta.onResolve.add(onRes);
|
|
852
|
+
meta.promise.finally(() => {
|
|
853
|
+
meta.onResolve.delete(onRes);
|
|
854
|
+
});
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
finish(value);
|
|
858
|
+
};
|
|
859
|
+
const process = () => {
|
|
860
|
+
const arr = childrenArray();
|
|
861
|
+
slots = arr.map((child) => {
|
|
862
|
+
let value = child;
|
|
863
|
+
let isNested = false;
|
|
864
|
+
if (typeof child === "function") {
|
|
865
|
+
try {
|
|
866
|
+
value = child();
|
|
867
|
+
} catch (err) {
|
|
868
|
+
if (isThenable(err)) value = err;
|
|
869
|
+
else throw err;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
if (typeof value === "object" && value !== null && "nodeType" in value && isSuspenseFragmentNode(value)) {
|
|
873
|
+
isNested = true;
|
|
874
|
+
}
|
|
875
|
+
return {
|
|
876
|
+
isNested,
|
|
877
|
+
resolved: isNested ? true : false,
|
|
878
|
+
node: isNested ? value : null,
|
|
879
|
+
promise: null,
|
|
880
|
+
reactive: typeof child === "function" ? child : null
|
|
881
|
+
};
|
|
882
|
+
});
|
|
883
|
+
let hasPending = false;
|
|
884
|
+
arr.forEach((child, index) => {
|
|
885
|
+
let value = child;
|
|
886
|
+
if (typeof child === "function") {
|
|
887
|
+
try {
|
|
888
|
+
value = child();
|
|
889
|
+
} catch (err) {
|
|
890
|
+
if (isThenable(err)) value = err;
|
|
891
|
+
else throw err;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
const meta = getLazyMeta(value);
|
|
895
|
+
if (!slots[index].isNested && isThenable(value) || !slots[index].isNested && meta && meta.pending) {
|
|
896
|
+
hasPending = true;
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
if (hasPending) {
|
|
900
|
+
showFallback();
|
|
901
|
+
}
|
|
902
|
+
arr.forEach((child, index) => {
|
|
903
|
+
if (slots[index].isNested) return;
|
|
904
|
+
let value = child;
|
|
905
|
+
if (typeof child === "function") {
|
|
906
|
+
try {
|
|
907
|
+
value = child();
|
|
908
|
+
} catch (err) {
|
|
909
|
+
if (isThenable(err)) value = err;
|
|
910
|
+
else throw err;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
inspectChild(index, value);
|
|
914
|
+
});
|
|
915
|
+
maybeReveal();
|
|
916
|
+
slots.forEach((slot, index) => {
|
|
917
|
+
if (!slot.reactive) return;
|
|
918
|
+
useEffect(() => {
|
|
919
|
+
let v;
|
|
920
|
+
try {
|
|
921
|
+
v = slot.reactive();
|
|
922
|
+
} catch (err) {
|
|
923
|
+
if (isThenable(err)) {
|
|
924
|
+
err.then(() => {
|
|
925
|
+
try {
|
|
926
|
+
const next = slot.reactive();
|
|
927
|
+
if (isThenable(next)) {
|
|
928
|
+
next.then(
|
|
929
|
+
(r) => setSlotContent(
|
|
930
|
+
index,
|
|
931
|
+
untrack(() => toNode(r))
|
|
932
|
+
)
|
|
933
|
+
);
|
|
934
|
+
} else {
|
|
935
|
+
setSlotContent(
|
|
936
|
+
index,
|
|
937
|
+
untrack(() => toNode(next))
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
} catch {
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
return;
|
|
944
|
+
} else {
|
|
945
|
+
throw err;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
if (isThenable(v)) {
|
|
949
|
+
v.then(
|
|
950
|
+
(r) => setSlotContent(
|
|
951
|
+
index,
|
|
952
|
+
untrack(() => toNode(r))
|
|
953
|
+
)
|
|
954
|
+
);
|
|
955
|
+
} else {
|
|
956
|
+
setSlotContent(
|
|
957
|
+
index,
|
|
958
|
+
untrack(() => toNode(v))
|
|
959
|
+
);
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
});
|
|
963
|
+
};
|
|
964
|
+
const checkConnected = () => {
|
|
965
|
+
if (startComment.isConnected) process();
|
|
966
|
+
else setTimeout(checkConnected, 0);
|
|
967
|
+
};
|
|
968
|
+
checkConnected();
|
|
969
|
+
if (typeof children === "function") {
|
|
970
|
+
useEffect(() => {
|
|
971
|
+
if (startComment.isConnected) {
|
|
972
|
+
anchors = null;
|
|
973
|
+
fallbackVisible = false;
|
|
974
|
+
stageOneCompleted = false;
|
|
975
|
+
slots = [];
|
|
976
|
+
clearBetween();
|
|
977
|
+
process();
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
return fragment;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// src/runtime/ErrorBoundary.ts
|
|
985
|
+
function ErrorBoundary(props) {
|
|
986
|
+
const { fallback, children, onError } = props || {};
|
|
987
|
+
const fragment = document.createDocumentFragment();
|
|
988
|
+
const startComment = document.createComment("error-boundary-s");
|
|
989
|
+
const endComment = document.createComment("error-boundary-e");
|
|
990
|
+
fragment.appendChild(startComment);
|
|
991
|
+
fragment.appendChild(endComment);
|
|
992
|
+
let hasError = false;
|
|
993
|
+
let storedError = null;
|
|
994
|
+
const insertNode = (node) => {
|
|
995
|
+
const parent = startComment.parentNode;
|
|
996
|
+
if (!parent) return;
|
|
997
|
+
const insert = (v) => {
|
|
998
|
+
if (v === null || v === void 0 || typeof v === "boolean") return;
|
|
999
|
+
if (Array.isArray(v)) {
|
|
1000
|
+
v.forEach((x) => insert(x));
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
if (typeof v === "function") {
|
|
1004
|
+
try {
|
|
1005
|
+
if (isComponentThunk(v)) {
|
|
1006
|
+
parent.insertBefore(v(), endComment);
|
|
1007
|
+
} else {
|
|
1008
|
+
insert(v());
|
|
1009
|
+
}
|
|
1010
|
+
} catch {
|
|
1011
|
+
}
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if (typeof v === "string" || typeof v === "number") {
|
|
1015
|
+
parent.insertBefore(document.createTextNode(String(v)), endComment);
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
if (v && typeof v === "object" && "nodeType" in v) {
|
|
1019
|
+
parent.insertBefore(v, endComment);
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
parent.insertBefore(document.createTextNode(String(v)), endComment);
|
|
1023
|
+
};
|
|
1024
|
+
untrack(() => insert(node));
|
|
1025
|
+
};
|
|
1026
|
+
const render2 = () => {
|
|
1027
|
+
disposeBetween(startComment, endComment);
|
|
1028
|
+
if (hasError) {
|
|
1029
|
+
const node = typeof fallback === "function" ? fallback(storedError) : fallback;
|
|
1030
|
+
insertNode(node);
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
try {
|
|
1034
|
+
const content = typeof children === "function" ? children() : children;
|
|
1035
|
+
insertNode(content);
|
|
1036
|
+
} catch (error) {
|
|
1037
|
+
hasError = true;
|
|
1038
|
+
storedError = error;
|
|
1039
|
+
try {
|
|
1040
|
+
onError?.(error);
|
|
1041
|
+
} catch {
|
|
1042
|
+
}
|
|
1043
|
+
const node = typeof fallback === "function" ? fallback(error) : fallback;
|
|
1044
|
+
disposeBetween(startComment, endComment);
|
|
1045
|
+
insertNode(node);
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
render2();
|
|
1049
|
+
if (typeof children === "function") {
|
|
1050
|
+
useEffect(() => {
|
|
1051
|
+
if (!hasError) render2();
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
return fragment;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
// src/runtime/render.ts
|
|
1058
|
+
function render(component, container) {
|
|
1059
|
+
if (!container) {
|
|
1060
|
+
throw ERRORS.RENDER_CONTAINER_REQUIRED();
|
|
1061
|
+
}
|
|
1062
|
+
disposeAllChildren(container);
|
|
1063
|
+
container.innerHTML = "";
|
|
1064
|
+
let element;
|
|
1065
|
+
if (typeof component === "function") {
|
|
1066
|
+
element = jsx(component, {});
|
|
1067
|
+
if (typeof element === "function" && element.__isComponent) {
|
|
1068
|
+
element = element();
|
|
1069
|
+
}
|
|
1070
|
+
} else if (typeof component === "object" && component !== null && "nodeType" in component) {
|
|
1071
|
+
element = component;
|
|
1072
|
+
} else {
|
|
1073
|
+
throw ERRORS.RENDER_INVALID_COMPONENT();
|
|
1074
|
+
}
|
|
1075
|
+
if (typeof element === "object" && element !== null && "nodeType" in element) {
|
|
1076
|
+
container.appendChild(element);
|
|
1077
|
+
} else {
|
|
1078
|
+
throw ERRORS.RENDER_INVALID_RETURN();
|
|
1079
|
+
}
|
|
1080
|
+
return element;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
// src/runtime/createElement.ts
|
|
1084
|
+
function createElement(tag, props, ...children) {
|
|
1085
|
+
const finalProps = { ...props || {} };
|
|
1086
|
+
if (children.length > 0) {
|
|
1087
|
+
finalProps.children = children.length === 1 ? children[0] : children;
|
|
1088
|
+
}
|
|
1089
|
+
return jsx(tag, finalProps);
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
export { ErrorBoundary, For, Portal, Show, Suspense, Title, createElement, lazy, onMount, render, useData, useId, useMemo, useOptimistic, useStore };
|
|
1093
|
+
//# sourceMappingURL=index.js.map
|
|
1094
|
+
//# sourceMappingURL=index.js.map
|