@fictjs/runtime 0.0.2
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 +17 -0
- package/dist/index.cjs +4224 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1572 -0
- package/dist/index.d.ts +1572 -0
- package/dist/index.dev.js +4240 -0
- package/dist/index.dev.js.map +1 -0
- package/dist/index.js +4133 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.cjs +44 -0
- package/dist/jsx-dev-runtime.cjs.map +1 -0
- package/dist/jsx-dev-runtime.js +14 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.cjs +44 -0
- package/dist/jsx-runtime.cjs.map +1 -0
- package/dist/jsx-runtime.js +14 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/slim.cjs +3384 -0
- package/dist/slim.cjs.map +1 -0
- package/dist/slim.d.cts +475 -0
- package/dist/slim.d.ts +475 -0
- package/dist/slim.js +3335 -0
- package/dist/slim.js.map +1 -0
- package/package.json +68 -0
- package/src/binding.ts +2127 -0
- package/src/constants.ts +456 -0
- package/src/cycle-guard.ts +134 -0
- package/src/devtools.ts +17 -0
- package/src/dom.ts +683 -0
- package/src/effect.ts +83 -0
- package/src/error-boundary.ts +118 -0
- package/src/hooks.ts +72 -0
- package/src/index.ts +184 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +2 -0
- package/src/jsx.ts +786 -0
- package/src/lifecycle.ts +273 -0
- package/src/list-helpers.ts +619 -0
- package/src/memo.ts +14 -0
- package/src/node-ops.ts +185 -0
- package/src/props.ts +212 -0
- package/src/reconcile.ts +151 -0
- package/src/ref.ts +25 -0
- package/src/scheduler.ts +12 -0
- package/src/signal.ts +1278 -0
- package/src/slim.ts +68 -0
- package/src/store.ts +210 -0
- package/src/suspense.ts +187 -0
- package/src/transition.ts +128 -0
- package/src/types.ts +172 -0
- package/src/versioned-signal.ts +58 -0
|
@@ -0,0 +1,4240 @@
|
|
|
1
|
+
// src/devtools.ts
|
|
2
|
+
function getGlobalHook() {
|
|
3
|
+
if (typeof globalThis === "undefined") return void 0;
|
|
4
|
+
return globalThis.__FICT_DEVTOOLS_HOOK__;
|
|
5
|
+
}
|
|
6
|
+
function getDevtoolsHook() {
|
|
7
|
+
return getGlobalHook();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/cycle-guard.ts
|
|
11
|
+
var defaultOptions = {
|
|
12
|
+
maxFlushCyclesPerMicrotask: 1e4,
|
|
13
|
+
maxEffectRunsPerFlush: 2e4,
|
|
14
|
+
windowSize: 5,
|
|
15
|
+
highUsageRatio: 0.8,
|
|
16
|
+
maxRootReentrantDepth: 10,
|
|
17
|
+
enableWindowWarning: true,
|
|
18
|
+
devMode: false
|
|
19
|
+
};
|
|
20
|
+
var options = {
|
|
21
|
+
...defaultOptions
|
|
22
|
+
};
|
|
23
|
+
var effectRunsThisFlush = 0;
|
|
24
|
+
var windowUsage = [];
|
|
25
|
+
var rootDepth = /* @__PURE__ */ new WeakMap();
|
|
26
|
+
var flushWarned = false;
|
|
27
|
+
var rootWarned = false;
|
|
28
|
+
var windowWarned = false;
|
|
29
|
+
function setCycleProtectionOptions(opts) {
|
|
30
|
+
options = { ...options, ...opts };
|
|
31
|
+
}
|
|
32
|
+
function beginFlushGuard() {
|
|
33
|
+
effectRunsThisFlush = 0;
|
|
34
|
+
flushWarned = false;
|
|
35
|
+
windowWarned = false;
|
|
36
|
+
}
|
|
37
|
+
function beforeEffectRunGuard() {
|
|
38
|
+
const next = ++effectRunsThisFlush;
|
|
39
|
+
if (next > options.maxFlushCyclesPerMicrotask || next > options.maxEffectRunsPerFlush) {
|
|
40
|
+
const message = `[fict] cycle protection triggered: flush-budget-exceeded`;
|
|
41
|
+
if (options.devMode) {
|
|
42
|
+
throw new Error(message);
|
|
43
|
+
}
|
|
44
|
+
if (!flushWarned) {
|
|
45
|
+
flushWarned = true;
|
|
46
|
+
console.warn(message, { effectRuns: next });
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
function endFlushGuard() {
|
|
53
|
+
recordWindowUsage(effectRunsThisFlush, options.maxFlushCyclesPerMicrotask);
|
|
54
|
+
effectRunsThisFlush = 0;
|
|
55
|
+
}
|
|
56
|
+
function enterRootGuard(root) {
|
|
57
|
+
const depth = (rootDepth.get(root) ?? 0) + 1;
|
|
58
|
+
if (depth > options.maxRootReentrantDepth) {
|
|
59
|
+
const message = `[fict] cycle protection triggered: root-reentry`;
|
|
60
|
+
if (options.devMode) {
|
|
61
|
+
throw new Error(message);
|
|
62
|
+
}
|
|
63
|
+
if (!rootWarned) {
|
|
64
|
+
rootWarned = true;
|
|
65
|
+
console.warn(message, { depth });
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
rootDepth.set(root, depth);
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
function exitRootGuard(root) {
|
|
73
|
+
const depth = rootDepth.get(root);
|
|
74
|
+
if (depth === void 0) return;
|
|
75
|
+
if (depth <= 1) {
|
|
76
|
+
rootDepth.delete(root);
|
|
77
|
+
} else {
|
|
78
|
+
rootDepth.set(root, depth - 1);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function recordWindowUsage(used, budget) {
|
|
82
|
+
if (!options.enableWindowWarning) return;
|
|
83
|
+
const entry = { used, budget };
|
|
84
|
+
windowUsage.push(entry);
|
|
85
|
+
if (windowUsage.length > options.windowSize) {
|
|
86
|
+
windowUsage.shift();
|
|
87
|
+
}
|
|
88
|
+
if (windowWarned) return;
|
|
89
|
+
if (windowUsage.length >= options.windowSize && windowUsage.every((item) => item.budget > 0 && item.used / item.budget >= options.highUsageRatio)) {
|
|
90
|
+
windowWarned = true;
|
|
91
|
+
reportCycle("high-usage-window", {
|
|
92
|
+
windowSize: options.windowSize,
|
|
93
|
+
ratio: options.highUsageRatio
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function reportCycle(reason, detail = void 0) {
|
|
98
|
+
const hook = getDevtoolsHook();
|
|
99
|
+
hook?.cycleDetected?.(detail ? { reason, detail } : { reason });
|
|
100
|
+
console.warn(`[fict] cycle protection triggered: ${reason}`, detail ?? "");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/lifecycle.ts
|
|
104
|
+
var currentRoot;
|
|
105
|
+
var currentEffectCleanups;
|
|
106
|
+
var globalErrorHandlers = /* @__PURE__ */ new WeakMap();
|
|
107
|
+
var globalSuspenseHandlers = /* @__PURE__ */ new WeakMap();
|
|
108
|
+
function createRootContext(parent = currentRoot) {
|
|
109
|
+
return { parent, cleanups: [], destroyCallbacks: [] };
|
|
110
|
+
}
|
|
111
|
+
function pushRoot(root) {
|
|
112
|
+
if (!enterRootGuard(root)) {
|
|
113
|
+
return currentRoot;
|
|
114
|
+
}
|
|
115
|
+
const prev = currentRoot;
|
|
116
|
+
currentRoot = root;
|
|
117
|
+
return prev;
|
|
118
|
+
}
|
|
119
|
+
function getCurrentRoot() {
|
|
120
|
+
return currentRoot;
|
|
121
|
+
}
|
|
122
|
+
function popRoot(prev) {
|
|
123
|
+
if (currentRoot) {
|
|
124
|
+
exitRootGuard(currentRoot);
|
|
125
|
+
}
|
|
126
|
+
currentRoot = prev;
|
|
127
|
+
}
|
|
128
|
+
function onMount(fn) {
|
|
129
|
+
if (currentRoot) {
|
|
130
|
+
;
|
|
131
|
+
(currentRoot.onMountCallbacks || (currentRoot.onMountCallbacks = [])).push(fn);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
runLifecycle(fn);
|
|
135
|
+
}
|
|
136
|
+
function onDestroy(fn) {
|
|
137
|
+
if (currentRoot) {
|
|
138
|
+
currentRoot.destroyCallbacks.push(() => runLifecycle(fn));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
runLifecycle(fn);
|
|
142
|
+
}
|
|
143
|
+
function onCleanup(fn) {
|
|
144
|
+
registerEffectCleanup(fn);
|
|
145
|
+
}
|
|
146
|
+
function flushOnMount(root) {
|
|
147
|
+
const cbs = root.onMountCallbacks;
|
|
148
|
+
if (!cbs || cbs.length === 0) return;
|
|
149
|
+
for (let i = 0; i < cbs.length; i++) {
|
|
150
|
+
const cleanup = cbs[i]();
|
|
151
|
+
if (typeof cleanup === "function") {
|
|
152
|
+
root.cleanups.push(cleanup);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
cbs.length = 0;
|
|
156
|
+
}
|
|
157
|
+
function registerRootCleanup(fn) {
|
|
158
|
+
if (currentRoot) {
|
|
159
|
+
currentRoot.cleanups.push(fn);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function clearRoot(root) {
|
|
163
|
+
runCleanupList(root.cleanups);
|
|
164
|
+
if (root.onMountCallbacks) {
|
|
165
|
+
root.onMountCallbacks.length = 0;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function destroyRoot(root) {
|
|
169
|
+
clearRoot(root);
|
|
170
|
+
runCleanupList(root.destroyCallbacks);
|
|
171
|
+
if (root.errorHandlers) {
|
|
172
|
+
root.errorHandlers.length = 0;
|
|
173
|
+
}
|
|
174
|
+
if (globalErrorHandlers.has(root)) {
|
|
175
|
+
globalErrorHandlers.delete(root);
|
|
176
|
+
}
|
|
177
|
+
if (root.suspenseHandlers) {
|
|
178
|
+
root.suspenseHandlers.length = 0;
|
|
179
|
+
}
|
|
180
|
+
if (globalSuspenseHandlers.has(root)) {
|
|
181
|
+
globalSuspenseHandlers.delete(root);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function createRoot(fn) {
|
|
185
|
+
const root = createRootContext();
|
|
186
|
+
const prev = pushRoot(root);
|
|
187
|
+
let value;
|
|
188
|
+
try {
|
|
189
|
+
value = fn();
|
|
190
|
+
} finally {
|
|
191
|
+
popRoot(prev);
|
|
192
|
+
}
|
|
193
|
+
flushOnMount(root);
|
|
194
|
+
return {
|
|
195
|
+
dispose: () => destroyRoot(root),
|
|
196
|
+
value
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function withEffectCleanups(bucket, fn) {
|
|
200
|
+
const prev = currentEffectCleanups;
|
|
201
|
+
currentEffectCleanups = bucket;
|
|
202
|
+
try {
|
|
203
|
+
return fn();
|
|
204
|
+
} finally {
|
|
205
|
+
currentEffectCleanups = prev;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function registerEffectCleanup(fn) {
|
|
209
|
+
if (currentEffectCleanups) {
|
|
210
|
+
currentEffectCleanups.push(fn);
|
|
211
|
+
} else {
|
|
212
|
+
registerRootCleanup(fn);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function runCleanupList(list) {
|
|
216
|
+
let error;
|
|
217
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
218
|
+
try {
|
|
219
|
+
const cleanup = list[i];
|
|
220
|
+
if (cleanup) cleanup();
|
|
221
|
+
} catch (err) {
|
|
222
|
+
if (error === void 0) {
|
|
223
|
+
error = err;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
list.length = 0;
|
|
228
|
+
if (error !== void 0) {
|
|
229
|
+
if (!handleError(error, { source: "cleanup" })) {
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function runLifecycle(fn) {
|
|
235
|
+
const cleanup = fn();
|
|
236
|
+
if (typeof cleanup === "function") {
|
|
237
|
+
cleanup();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function registerErrorHandler(fn) {
|
|
241
|
+
if (!currentRoot) {
|
|
242
|
+
throw new Error("registerErrorHandler must be called within a root");
|
|
243
|
+
}
|
|
244
|
+
if (!currentRoot.errorHandlers) {
|
|
245
|
+
currentRoot.errorHandlers = [];
|
|
246
|
+
}
|
|
247
|
+
currentRoot.errorHandlers.push(fn);
|
|
248
|
+
const existing = globalErrorHandlers.get(currentRoot);
|
|
249
|
+
if (existing) {
|
|
250
|
+
existing.push(fn);
|
|
251
|
+
} else {
|
|
252
|
+
globalErrorHandlers.set(currentRoot, [fn]);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function registerSuspenseHandler(fn) {
|
|
256
|
+
if (!currentRoot) {
|
|
257
|
+
throw new Error("registerSuspenseHandler must be called within a root");
|
|
258
|
+
}
|
|
259
|
+
if (!currentRoot.suspenseHandlers) {
|
|
260
|
+
currentRoot.suspenseHandlers = [];
|
|
261
|
+
}
|
|
262
|
+
currentRoot.suspenseHandlers.push(fn);
|
|
263
|
+
const existing = globalSuspenseHandlers.get(currentRoot);
|
|
264
|
+
if (existing) {
|
|
265
|
+
existing.push(fn);
|
|
266
|
+
} else {
|
|
267
|
+
globalSuspenseHandlers.set(currentRoot, [fn]);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function handleError(err, info, startRoot) {
|
|
271
|
+
let root = startRoot ?? currentRoot;
|
|
272
|
+
let error = err;
|
|
273
|
+
while (root) {
|
|
274
|
+
const handlers = root.errorHandlers;
|
|
275
|
+
if (handlers && handlers.length) {
|
|
276
|
+
for (let i = handlers.length - 1; i >= 0; i--) {
|
|
277
|
+
const handler = handlers[i];
|
|
278
|
+
try {
|
|
279
|
+
const handled = handler(error, info);
|
|
280
|
+
if (handled !== false) {
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
} catch (nextErr) {
|
|
284
|
+
error = nextErr;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
root = root.parent;
|
|
289
|
+
}
|
|
290
|
+
const globalForRoot = startRoot ? globalErrorHandlers.get(startRoot) : currentRoot ? globalErrorHandlers.get(currentRoot) : void 0;
|
|
291
|
+
if (globalForRoot && globalForRoot.length) {
|
|
292
|
+
for (let i = globalForRoot.length - 1; i >= 0; i--) {
|
|
293
|
+
const handler = globalForRoot[i];
|
|
294
|
+
try {
|
|
295
|
+
const handled = handler(error, info);
|
|
296
|
+
if (handled !== false) {
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
} catch (nextErr) {
|
|
300
|
+
error = nextErr;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
306
|
+
function handleSuspend(token, startRoot) {
|
|
307
|
+
let root = startRoot ?? currentRoot;
|
|
308
|
+
while (root) {
|
|
309
|
+
const handlers = root.suspenseHandlers;
|
|
310
|
+
if (handlers && handlers.length) {
|
|
311
|
+
for (let i = handlers.length - 1; i >= 0; i--) {
|
|
312
|
+
const handler = handlers[i];
|
|
313
|
+
const handled = handler(token);
|
|
314
|
+
if (handled !== false) return true;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
root = root.parent;
|
|
318
|
+
}
|
|
319
|
+
const globalForRoot = startRoot && globalSuspenseHandlers.get(startRoot) ? globalSuspenseHandlers.get(startRoot) : currentRoot ? globalSuspenseHandlers.get(currentRoot) : void 0;
|
|
320
|
+
if (globalForRoot && globalForRoot.length) {
|
|
321
|
+
for (let i = globalForRoot.length - 1; i >= 0; i--) {
|
|
322
|
+
const handler = globalForRoot[i];
|
|
323
|
+
const handled = handler(token);
|
|
324
|
+
if (handled !== false) return true;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// src/signal.ts
|
|
331
|
+
var Mutable = 1;
|
|
332
|
+
var Watching = 2;
|
|
333
|
+
var Running = 4;
|
|
334
|
+
var Recursed = 8;
|
|
335
|
+
var Dirty = 16;
|
|
336
|
+
var Pending = 32;
|
|
337
|
+
var MutableDirty = 17;
|
|
338
|
+
var MutablePending = 33;
|
|
339
|
+
var MutableRunning = 5;
|
|
340
|
+
var WatchingRunning = 6;
|
|
341
|
+
var cycle = 0;
|
|
342
|
+
var batchDepth = 0;
|
|
343
|
+
var activeSub;
|
|
344
|
+
var flushScheduled = false;
|
|
345
|
+
var highPriorityQueue = [];
|
|
346
|
+
var lowPriorityQueue = [];
|
|
347
|
+
var isInTransition = false;
|
|
348
|
+
var enqueueMicrotask = typeof queueMicrotask === "function" ? queueMicrotask : (fn) => {
|
|
349
|
+
Promise.resolve().then(fn);
|
|
350
|
+
};
|
|
351
|
+
function link(dep, sub, version) {
|
|
352
|
+
const prevDep = sub.depsTail;
|
|
353
|
+
if (prevDep !== void 0 && prevDep.dep === dep) return;
|
|
354
|
+
const nextDep = prevDep !== void 0 ? prevDep.nextDep : sub.deps;
|
|
355
|
+
if (nextDep !== void 0 && nextDep.dep === dep) {
|
|
356
|
+
nextDep.version = version;
|
|
357
|
+
sub.depsTail = nextDep;
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const prevSub = dep.subsTail;
|
|
361
|
+
if (prevSub !== void 0 && prevSub.version === version && prevSub.sub === sub) return;
|
|
362
|
+
const newLink = { version, dep, sub, prevDep, nextDep, prevSub, nextSub: void 0 };
|
|
363
|
+
sub.depsTail = newLink;
|
|
364
|
+
dep.subsTail = newLink;
|
|
365
|
+
if (nextDep !== void 0) nextDep.prevDep = newLink;
|
|
366
|
+
if (prevDep !== void 0) prevDep.nextDep = newLink;
|
|
367
|
+
else sub.deps = newLink;
|
|
368
|
+
if (prevSub !== void 0) prevSub.nextSub = newLink;
|
|
369
|
+
else dep.subs = newLink;
|
|
370
|
+
}
|
|
371
|
+
function unlink(lnk, sub = lnk.sub) {
|
|
372
|
+
const dep = lnk.dep;
|
|
373
|
+
const prevDep = lnk.prevDep;
|
|
374
|
+
const nextDep = lnk.nextDep;
|
|
375
|
+
const nextSub = lnk.nextSub;
|
|
376
|
+
const prevSub = lnk.prevSub;
|
|
377
|
+
if (nextDep !== void 0) nextDep.prevDep = prevDep;
|
|
378
|
+
else sub.depsTail = prevDep;
|
|
379
|
+
if (prevDep !== void 0) prevDep.nextDep = nextDep;
|
|
380
|
+
else sub.deps = nextDep;
|
|
381
|
+
if (nextSub !== void 0) nextSub.prevSub = prevSub;
|
|
382
|
+
else dep.subsTail = prevSub;
|
|
383
|
+
if (prevSub !== void 0) prevSub.nextSub = nextSub;
|
|
384
|
+
else if ((dep.subs = nextSub) === void 0) unwatched(dep);
|
|
385
|
+
return nextDep;
|
|
386
|
+
}
|
|
387
|
+
function unwatched(dep) {
|
|
388
|
+
if (!(dep.flags & Mutable)) {
|
|
389
|
+
disposeNode(dep);
|
|
390
|
+
} else if ("getter" in dep && dep.getter !== void 0) {
|
|
391
|
+
dep.depsTail = void 0;
|
|
392
|
+
dep.flags = MutableDirty;
|
|
393
|
+
purgeDeps(dep);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function propagate(firstLink) {
|
|
397
|
+
let link2 = firstLink;
|
|
398
|
+
let next = link2.nextSub;
|
|
399
|
+
let stack;
|
|
400
|
+
top: for (; ; ) {
|
|
401
|
+
const sub = link2.sub;
|
|
402
|
+
let flags = sub.flags;
|
|
403
|
+
if (!(flags & 60)) {
|
|
404
|
+
sub.flags = flags | Pending;
|
|
405
|
+
} else if (!(flags & 12)) {
|
|
406
|
+
flags = 0;
|
|
407
|
+
} else if (!(flags & Running)) {
|
|
408
|
+
sub.flags = flags & ~Recursed | Pending;
|
|
409
|
+
} else if (!(flags & 48)) {
|
|
410
|
+
let vlink = sub.depsTail;
|
|
411
|
+
let valid = false;
|
|
412
|
+
while (vlink !== void 0) {
|
|
413
|
+
if (vlink === link2) {
|
|
414
|
+
valid = true;
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
vlink = vlink.prevDep;
|
|
418
|
+
}
|
|
419
|
+
if (valid) {
|
|
420
|
+
sub.flags = flags | 40;
|
|
421
|
+
flags &= Mutable;
|
|
422
|
+
} else {
|
|
423
|
+
flags = 0;
|
|
424
|
+
}
|
|
425
|
+
} else {
|
|
426
|
+
flags = 0;
|
|
427
|
+
}
|
|
428
|
+
if (flags & Watching) notify(sub);
|
|
429
|
+
if (flags & Mutable) {
|
|
430
|
+
const subSubs = sub.subs;
|
|
431
|
+
if (subSubs !== void 0) {
|
|
432
|
+
const nextSub = subSubs.nextSub;
|
|
433
|
+
if (nextSub !== void 0) {
|
|
434
|
+
stack = { value: next, prev: stack };
|
|
435
|
+
next = nextSub;
|
|
436
|
+
}
|
|
437
|
+
link2 = subSubs;
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (next !== void 0) {
|
|
442
|
+
link2 = next;
|
|
443
|
+
next = link2.nextSub;
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
while (stack !== void 0) {
|
|
447
|
+
link2 = stack.value;
|
|
448
|
+
stack = stack.prev;
|
|
449
|
+
if (link2 !== void 0) {
|
|
450
|
+
next = link2.nextSub;
|
|
451
|
+
continue top;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function checkDirty(firstLink, sub) {
|
|
458
|
+
let link2 = firstLink;
|
|
459
|
+
let stack;
|
|
460
|
+
let checkDepth = 0;
|
|
461
|
+
let dirty = false;
|
|
462
|
+
top: for (; ; ) {
|
|
463
|
+
const dep = link2.dep;
|
|
464
|
+
const depFlags = dep.flags;
|
|
465
|
+
if (sub.flags & Dirty) {
|
|
466
|
+
dirty = true;
|
|
467
|
+
} else if ((depFlags & MutableDirty) === MutableDirty) {
|
|
468
|
+
if (update(dep)) {
|
|
469
|
+
const subs = dep.subs;
|
|
470
|
+
if (subs !== void 0 && subs.nextSub !== void 0) shallowPropagate(subs);
|
|
471
|
+
dirty = true;
|
|
472
|
+
}
|
|
473
|
+
} else if ((depFlags & MutablePending) === MutablePending) {
|
|
474
|
+
if (link2.nextSub !== void 0 || link2.prevSub !== void 0) {
|
|
475
|
+
stack = { value: link2, prev: stack };
|
|
476
|
+
}
|
|
477
|
+
link2 = dep.deps;
|
|
478
|
+
sub = dep;
|
|
479
|
+
++checkDepth;
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
if (!dirty) {
|
|
483
|
+
const nextDep = link2.nextDep;
|
|
484
|
+
if (nextDep !== void 0) {
|
|
485
|
+
link2 = nextDep;
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
while (checkDepth-- > 0) {
|
|
490
|
+
const firstSub = sub.subs;
|
|
491
|
+
const hasMultipleSubs = firstSub.nextSub !== void 0;
|
|
492
|
+
if (hasMultipleSubs) {
|
|
493
|
+
link2 = stack.value;
|
|
494
|
+
stack = stack.prev;
|
|
495
|
+
} else {
|
|
496
|
+
link2 = firstSub;
|
|
497
|
+
}
|
|
498
|
+
if (dirty) {
|
|
499
|
+
if (update(sub)) {
|
|
500
|
+
if (hasMultipleSubs) shallowPropagate(firstSub);
|
|
501
|
+
sub = link2.sub;
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
dirty = false;
|
|
505
|
+
} else {
|
|
506
|
+
sub.flags &= ~Pending;
|
|
507
|
+
}
|
|
508
|
+
sub = link2.sub;
|
|
509
|
+
const nextDep = link2.nextDep;
|
|
510
|
+
if (nextDep !== void 0) {
|
|
511
|
+
link2 = nextDep;
|
|
512
|
+
continue top;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return dirty;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function shallowPropagate(firstLink) {
|
|
519
|
+
let link2 = firstLink;
|
|
520
|
+
do {
|
|
521
|
+
const sub = link2.sub;
|
|
522
|
+
const flags = sub.flags;
|
|
523
|
+
if ((flags & 48) === Pending) {
|
|
524
|
+
sub.flags = flags | Dirty;
|
|
525
|
+
if ((flags & 6) === Watching) notify(sub);
|
|
526
|
+
}
|
|
527
|
+
link2 = link2.nextSub;
|
|
528
|
+
} while (link2 !== void 0);
|
|
529
|
+
}
|
|
530
|
+
function update(node) {
|
|
531
|
+
return "getter" in node && node.getter !== void 0 ? updateComputed(node) : updateSignal(node);
|
|
532
|
+
}
|
|
533
|
+
function notify(effect2) {
|
|
534
|
+
effect2.flags &= ~Watching;
|
|
535
|
+
const effects = [];
|
|
536
|
+
for (; ; ) {
|
|
537
|
+
effects.push(effect2);
|
|
538
|
+
const nextLink = effect2.subs;
|
|
539
|
+
if (nextLink === void 0) break;
|
|
540
|
+
effect2 = nextLink.sub;
|
|
541
|
+
if (effect2 === void 0 || !(effect2.flags & Watching)) break;
|
|
542
|
+
effect2.flags &= ~Watching;
|
|
543
|
+
}
|
|
544
|
+
const targetQueue = isInTransition ? lowPriorityQueue : highPriorityQueue;
|
|
545
|
+
for (let i = effects.length - 1; i >= 0; i--) {
|
|
546
|
+
targetQueue.push(effects[i]);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
function purgeDeps(sub) {
|
|
550
|
+
const depsTail = sub.depsTail;
|
|
551
|
+
let dep = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
|
|
552
|
+
while (dep !== void 0) dep = unlink(dep, sub);
|
|
553
|
+
}
|
|
554
|
+
function disposeNode(node) {
|
|
555
|
+
node.depsTail = void 0;
|
|
556
|
+
node.flags = 0;
|
|
557
|
+
purgeDeps(node);
|
|
558
|
+
const sub = node.subs;
|
|
559
|
+
if (sub !== void 0) unlink(sub, node);
|
|
560
|
+
}
|
|
561
|
+
function updateSignal(s) {
|
|
562
|
+
s.flags = Mutable;
|
|
563
|
+
const current = s.currentValue;
|
|
564
|
+
const pending = s.pendingValue;
|
|
565
|
+
if (current !== pending) {
|
|
566
|
+
s.currentValue = pending;
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
function updateComputed(c) {
|
|
572
|
+
++cycle;
|
|
573
|
+
const oldValue = c.value;
|
|
574
|
+
c.depsTail = void 0;
|
|
575
|
+
c.flags = MutableRunning;
|
|
576
|
+
const prevSub = activeSub;
|
|
577
|
+
activeSub = c;
|
|
578
|
+
try {
|
|
579
|
+
const newValue = c.getter(oldValue);
|
|
580
|
+
activeSub = prevSub;
|
|
581
|
+
c.flags &= ~Running;
|
|
582
|
+
purgeDeps(c);
|
|
583
|
+
if (oldValue !== newValue) {
|
|
584
|
+
c.value = newValue;
|
|
585
|
+
return true;
|
|
586
|
+
}
|
|
587
|
+
return false;
|
|
588
|
+
} catch (e) {
|
|
589
|
+
activeSub = prevSub;
|
|
590
|
+
c.flags &= ~Running;
|
|
591
|
+
throw e;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
function runEffect(e) {
|
|
595
|
+
const flags = e.flags;
|
|
596
|
+
if (flags & Dirty || flags & Pending && e.deps && checkDirty(e.deps, e)) {
|
|
597
|
+
++cycle;
|
|
598
|
+
effectRunDevtools(e);
|
|
599
|
+
e.depsTail = void 0;
|
|
600
|
+
e.flags = WatchingRunning;
|
|
601
|
+
const prevSub = activeSub;
|
|
602
|
+
activeSub = e;
|
|
603
|
+
try {
|
|
604
|
+
e.fn();
|
|
605
|
+
activeSub = prevSub;
|
|
606
|
+
e.flags = Watching;
|
|
607
|
+
purgeDeps(e);
|
|
608
|
+
} catch (err) {
|
|
609
|
+
activeSub = prevSub;
|
|
610
|
+
e.flags = Watching;
|
|
611
|
+
throw err;
|
|
612
|
+
}
|
|
613
|
+
} else {
|
|
614
|
+
e.flags = Watching;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
function scheduleFlush() {
|
|
618
|
+
const hasWork = highPriorityQueue.length > 0 || lowPriorityQueue.length > 0;
|
|
619
|
+
if (flushScheduled || !hasWork) return;
|
|
620
|
+
if (batchDepth > 0) return;
|
|
621
|
+
flushScheduled = true;
|
|
622
|
+
enqueueMicrotask(() => {
|
|
623
|
+
flush();
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
function flush() {
|
|
627
|
+
beginFlushGuard();
|
|
628
|
+
if (batchDepth > 0) {
|
|
629
|
+
scheduleFlush();
|
|
630
|
+
endFlushGuard();
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
const hasWork = highPriorityQueue.length > 0 || lowPriorityQueue.length > 0;
|
|
634
|
+
if (!hasWork) {
|
|
635
|
+
flushScheduled = false;
|
|
636
|
+
endFlushGuard();
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
flushScheduled = false;
|
|
640
|
+
let highIndex = 0;
|
|
641
|
+
while (highIndex < highPriorityQueue.length) {
|
|
642
|
+
const e = highPriorityQueue[highIndex];
|
|
643
|
+
if (!beforeEffectRunGuard()) {
|
|
644
|
+
if (highIndex > 0) {
|
|
645
|
+
highPriorityQueue.copyWithin(0, highIndex);
|
|
646
|
+
highPriorityQueue.length -= highIndex;
|
|
647
|
+
}
|
|
648
|
+
endFlushGuard();
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
highIndex++;
|
|
652
|
+
runEffect(e);
|
|
653
|
+
}
|
|
654
|
+
highPriorityQueue.length = 0;
|
|
655
|
+
let lowIndex = 0;
|
|
656
|
+
while (lowIndex < lowPriorityQueue.length) {
|
|
657
|
+
if (highPriorityQueue.length > 0) {
|
|
658
|
+
if (lowIndex > 0) {
|
|
659
|
+
lowPriorityQueue.copyWithin(0, lowIndex);
|
|
660
|
+
lowPriorityQueue.length -= lowIndex;
|
|
661
|
+
}
|
|
662
|
+
scheduleFlush();
|
|
663
|
+
endFlushGuard();
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
const e = lowPriorityQueue[lowIndex];
|
|
667
|
+
if (!beforeEffectRunGuard()) {
|
|
668
|
+
if (lowIndex > 0) {
|
|
669
|
+
lowPriorityQueue.copyWithin(0, lowIndex);
|
|
670
|
+
lowPriorityQueue.length -= lowIndex;
|
|
671
|
+
}
|
|
672
|
+
endFlushGuard();
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
lowIndex++;
|
|
676
|
+
runEffect(e);
|
|
677
|
+
}
|
|
678
|
+
lowPriorityQueue.length = 0;
|
|
679
|
+
endFlushGuard();
|
|
680
|
+
}
|
|
681
|
+
function signal(initialValue) {
|
|
682
|
+
const s = {
|
|
683
|
+
currentValue: initialValue,
|
|
684
|
+
pendingValue: initialValue,
|
|
685
|
+
subs: void 0,
|
|
686
|
+
subsTail: void 0,
|
|
687
|
+
flags: Mutable,
|
|
688
|
+
__id: void 0
|
|
689
|
+
};
|
|
690
|
+
registerSignalDevtools(initialValue, s);
|
|
691
|
+
return signalOper.bind(s);
|
|
692
|
+
}
|
|
693
|
+
function signalOper(value) {
|
|
694
|
+
if (arguments.length > 0) {
|
|
695
|
+
if (this.pendingValue !== value) {
|
|
696
|
+
this.pendingValue = value;
|
|
697
|
+
this.flags = MutableDirty;
|
|
698
|
+
updateSignalDevtools(this, value);
|
|
699
|
+
const subs = this.subs;
|
|
700
|
+
if (subs !== void 0) {
|
|
701
|
+
propagate(subs);
|
|
702
|
+
if (!batchDepth) scheduleFlush();
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
const flags = this.flags;
|
|
708
|
+
if (flags & Dirty) {
|
|
709
|
+
if (updateSignal(this)) {
|
|
710
|
+
const subs = this.subs;
|
|
711
|
+
if (subs !== void 0) shallowPropagate(subs);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
let sub = activeSub;
|
|
715
|
+
while (sub !== void 0) {
|
|
716
|
+
if (sub.flags & 3) {
|
|
717
|
+
link(this, sub, cycle);
|
|
718
|
+
break;
|
|
719
|
+
}
|
|
720
|
+
const subSubs = sub.subs;
|
|
721
|
+
sub = subSubs !== void 0 ? subSubs.sub : void 0;
|
|
722
|
+
}
|
|
723
|
+
return this.currentValue;
|
|
724
|
+
}
|
|
725
|
+
function computed(getter) {
|
|
726
|
+
const c = {
|
|
727
|
+
value: void 0,
|
|
728
|
+
subs: void 0,
|
|
729
|
+
subsTail: void 0,
|
|
730
|
+
deps: void 0,
|
|
731
|
+
depsTail: void 0,
|
|
732
|
+
flags: 0,
|
|
733
|
+
getter
|
|
734
|
+
};
|
|
735
|
+
const bound = computedOper.bind(c);
|
|
736
|
+
return bound;
|
|
737
|
+
}
|
|
738
|
+
function computedOper() {
|
|
739
|
+
const flags = this.flags;
|
|
740
|
+
if (flags & Dirty) {
|
|
741
|
+
if (updateComputed(this)) {
|
|
742
|
+
const subs = this.subs;
|
|
743
|
+
if (subs !== void 0) shallowPropagate(subs);
|
|
744
|
+
}
|
|
745
|
+
} else if (flags & Pending) {
|
|
746
|
+
if (this.deps && checkDirty(this.deps, this)) {
|
|
747
|
+
if (updateComputed(this)) {
|
|
748
|
+
const subs = this.subs;
|
|
749
|
+
if (subs !== void 0) shallowPropagate(subs);
|
|
750
|
+
}
|
|
751
|
+
} else {
|
|
752
|
+
this.flags = flags & ~Pending;
|
|
753
|
+
}
|
|
754
|
+
} else if (!flags) {
|
|
755
|
+
this.flags = MutableRunning;
|
|
756
|
+
const prevSub = setActiveSub(this);
|
|
757
|
+
try {
|
|
758
|
+
this.value = this.getter(void 0);
|
|
759
|
+
} finally {
|
|
760
|
+
setActiveSub(prevSub);
|
|
761
|
+
this.flags &= ~Running;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
if (activeSub !== void 0) link(this, activeSub, cycle);
|
|
765
|
+
return this.value;
|
|
766
|
+
}
|
|
767
|
+
function effect(fn) {
|
|
768
|
+
const e = {
|
|
769
|
+
fn,
|
|
770
|
+
subs: void 0,
|
|
771
|
+
subsTail: void 0,
|
|
772
|
+
deps: void 0,
|
|
773
|
+
depsTail: void 0,
|
|
774
|
+
flags: WatchingRunning,
|
|
775
|
+
__id: void 0
|
|
776
|
+
};
|
|
777
|
+
registerEffectDevtools(e);
|
|
778
|
+
const prevSub = activeSub;
|
|
779
|
+
if (prevSub !== void 0) link(e, prevSub, 0);
|
|
780
|
+
activeSub = e;
|
|
781
|
+
try {
|
|
782
|
+
effectRunDevtools(e);
|
|
783
|
+
fn();
|
|
784
|
+
} finally {
|
|
785
|
+
activeSub = prevSub;
|
|
786
|
+
e.flags &= ~Running;
|
|
787
|
+
}
|
|
788
|
+
return effectOper.bind(e);
|
|
789
|
+
}
|
|
790
|
+
function effectOper() {
|
|
791
|
+
disposeNode(this);
|
|
792
|
+
}
|
|
793
|
+
function batch(fn) {
|
|
794
|
+
++batchDepth;
|
|
795
|
+
try {
|
|
796
|
+
return fn();
|
|
797
|
+
} finally {
|
|
798
|
+
if (--batchDepth === 0) flush();
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
function setActiveSub(sub) {
|
|
802
|
+
const prev = activeSub;
|
|
803
|
+
activeSub = sub;
|
|
804
|
+
return prev;
|
|
805
|
+
}
|
|
806
|
+
function untrack(fn) {
|
|
807
|
+
const prev = activeSub;
|
|
808
|
+
activeSub = void 0;
|
|
809
|
+
try {
|
|
810
|
+
return fn();
|
|
811
|
+
} finally {
|
|
812
|
+
activeSub = prev;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
function setTransitionContext(value) {
|
|
816
|
+
const prev = isInTransition;
|
|
817
|
+
isInTransition = value;
|
|
818
|
+
return prev;
|
|
819
|
+
}
|
|
820
|
+
var $state = signal;
|
|
821
|
+
var devtoolsSignalId = 0;
|
|
822
|
+
var devtoolsEffectId = 0;
|
|
823
|
+
function registerSignalDevtools(value, node) {
|
|
824
|
+
const hook = getDevtoolsHook();
|
|
825
|
+
if (!hook) return void 0;
|
|
826
|
+
const id = ++devtoolsSignalId;
|
|
827
|
+
hook.registerSignal(id, value);
|
|
828
|
+
node.__id = id;
|
|
829
|
+
return id;
|
|
830
|
+
}
|
|
831
|
+
function updateSignalDevtools(node, value) {
|
|
832
|
+
const hook = getDevtoolsHook();
|
|
833
|
+
if (!hook) return;
|
|
834
|
+
const id = node.__id;
|
|
835
|
+
if (id) hook.updateSignal(id, value);
|
|
836
|
+
}
|
|
837
|
+
function registerEffectDevtools(node) {
|
|
838
|
+
const hook = getDevtoolsHook();
|
|
839
|
+
if (!hook) return void 0;
|
|
840
|
+
const id = ++devtoolsEffectId;
|
|
841
|
+
hook.registerEffect(id);
|
|
842
|
+
node.__id = id;
|
|
843
|
+
return id;
|
|
844
|
+
}
|
|
845
|
+
function effectRunDevtools(node) {
|
|
846
|
+
const hook = getDevtoolsHook();
|
|
847
|
+
if (!hook) return;
|
|
848
|
+
const id = node.__id;
|
|
849
|
+
if (id) hook.effectRun(id);
|
|
850
|
+
}
|
|
851
|
+
function createSelector(source, equalityFn = (a, b) => a === b) {
|
|
852
|
+
let current = source();
|
|
853
|
+
const observers = /* @__PURE__ */ new Map();
|
|
854
|
+
effect(() => {
|
|
855
|
+
const next = source();
|
|
856
|
+
if (equalityFn(current, next)) return;
|
|
857
|
+
const prevSig = observers.get(current);
|
|
858
|
+
if (prevSig) prevSig(false);
|
|
859
|
+
const nextSig = observers.get(next);
|
|
860
|
+
if (nextSig) nextSig(true);
|
|
861
|
+
current = next;
|
|
862
|
+
});
|
|
863
|
+
return (key) => {
|
|
864
|
+
let sig = observers.get(key);
|
|
865
|
+
if (!sig) {
|
|
866
|
+
sig = signal(equalityFn(key, current));
|
|
867
|
+
observers.set(key, sig);
|
|
868
|
+
registerRootCleanup(() => observers.delete(key));
|
|
869
|
+
}
|
|
870
|
+
return sig();
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// src/store.ts
|
|
875
|
+
var PROXY = Symbol("fict:store-proxy");
|
|
876
|
+
var TARGET = Symbol("fict:store-target");
|
|
877
|
+
function createStore(initialValue) {
|
|
878
|
+
const unwrapped = unwrap(initialValue);
|
|
879
|
+
const wrapped = wrap(unwrapped);
|
|
880
|
+
function setStore(fn) {
|
|
881
|
+
batch(() => {
|
|
882
|
+
const result = fn(wrapped);
|
|
883
|
+
if (result !== void 0) {
|
|
884
|
+
reconcile(wrapped, result);
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
return [wrapped, setStore];
|
|
889
|
+
}
|
|
890
|
+
var proxyCache = /* @__PURE__ */ new WeakMap();
|
|
891
|
+
var signalCache = /* @__PURE__ */ new WeakMap();
|
|
892
|
+
function wrap(value) {
|
|
893
|
+
if (value === null || typeof value !== "object") return value;
|
|
894
|
+
if (value[PROXY]) return value;
|
|
895
|
+
if (proxyCache.has(value)) return proxyCache.get(value);
|
|
896
|
+
const handler = {
|
|
897
|
+
get(target, prop, receiver) {
|
|
898
|
+
if (prop === PROXY) return true;
|
|
899
|
+
if (prop === TARGET) return target;
|
|
900
|
+
const value2 = Reflect.get(target, prop, receiver);
|
|
901
|
+
track(target, prop);
|
|
902
|
+
return wrap(value2);
|
|
903
|
+
},
|
|
904
|
+
set(target, prop, value2, receiver) {
|
|
905
|
+
if (prop === PROXY || prop === TARGET) return false;
|
|
906
|
+
const oldValue = Reflect.get(target, prop, receiver);
|
|
907
|
+
if (oldValue === value2) return true;
|
|
908
|
+
const result = Reflect.set(target, prop, value2, receiver);
|
|
909
|
+
if (result) {
|
|
910
|
+
trigger(target, prop);
|
|
911
|
+
}
|
|
912
|
+
return result;
|
|
913
|
+
},
|
|
914
|
+
deleteProperty(target, prop) {
|
|
915
|
+
const result = Reflect.deleteProperty(target, prop);
|
|
916
|
+
if (result) {
|
|
917
|
+
trigger(target, prop);
|
|
918
|
+
}
|
|
919
|
+
return result;
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
const proxy = new Proxy(value, handler);
|
|
923
|
+
proxyCache.set(value, proxy);
|
|
924
|
+
return proxy;
|
|
925
|
+
}
|
|
926
|
+
function unwrap(value) {
|
|
927
|
+
if (value && typeof value === "object" && value[PROXY]) {
|
|
928
|
+
return value[TARGET];
|
|
929
|
+
}
|
|
930
|
+
return value;
|
|
931
|
+
}
|
|
932
|
+
function track(target, prop) {
|
|
933
|
+
let signals = signalCache.get(target);
|
|
934
|
+
if (!signals) {
|
|
935
|
+
signals = /* @__PURE__ */ new Map();
|
|
936
|
+
signalCache.set(target, signals);
|
|
937
|
+
}
|
|
938
|
+
let s = signals.get(prop);
|
|
939
|
+
if (!s) {
|
|
940
|
+
s = signal(getLastValue(target, prop));
|
|
941
|
+
signals.set(prop, s);
|
|
942
|
+
}
|
|
943
|
+
s();
|
|
944
|
+
}
|
|
945
|
+
function trigger(target, prop) {
|
|
946
|
+
const signals = signalCache.get(target);
|
|
947
|
+
if (signals) {
|
|
948
|
+
const s = signals.get(prop);
|
|
949
|
+
if (s) {
|
|
950
|
+
s(getLastValue(target, prop));
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
function getLastValue(target, prop) {
|
|
955
|
+
return target[prop];
|
|
956
|
+
}
|
|
957
|
+
function reconcile(target, value) {
|
|
958
|
+
if (target === value) return;
|
|
959
|
+
if (value === null || typeof value !== "object") return;
|
|
960
|
+
const realTarget = unwrap(target);
|
|
961
|
+
const realValue = unwrap(value);
|
|
962
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(realTarget), ...Object.keys(realValue)]);
|
|
963
|
+
for (const key of keys) {
|
|
964
|
+
if (realValue[key] === void 0 && realTarget[key] !== void 0) {
|
|
965
|
+
delete target[key];
|
|
966
|
+
} else if (realTarget[key] !== realValue[key]) {
|
|
967
|
+
target[key] = realValue[key];
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
// src/memo.ts
|
|
973
|
+
function createMemo(fn) {
|
|
974
|
+
return computed(fn);
|
|
975
|
+
}
|
|
976
|
+
var $memo = createMemo;
|
|
977
|
+
|
|
978
|
+
// src/effect.ts
|
|
979
|
+
function createEffect(fn) {
|
|
980
|
+
let cleanups = [];
|
|
981
|
+
const rootForError = getCurrentRoot();
|
|
982
|
+
const run = () => {
|
|
983
|
+
runCleanupList(cleanups);
|
|
984
|
+
const bucket = [];
|
|
985
|
+
withEffectCleanups(bucket, () => {
|
|
986
|
+
try {
|
|
987
|
+
const maybeCleanup = fn();
|
|
988
|
+
if (typeof maybeCleanup === "function") {
|
|
989
|
+
bucket.push(maybeCleanup);
|
|
990
|
+
}
|
|
991
|
+
} catch (err) {
|
|
992
|
+
if (handleError(err, { source: "effect" }, rootForError)) {
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
throw err;
|
|
996
|
+
}
|
|
997
|
+
});
|
|
998
|
+
cleanups = bucket;
|
|
999
|
+
};
|
|
1000
|
+
const disposeEffect = effect(run);
|
|
1001
|
+
const teardown = () => {
|
|
1002
|
+
runCleanupList(cleanups);
|
|
1003
|
+
disposeEffect();
|
|
1004
|
+
};
|
|
1005
|
+
registerRootCleanup(teardown);
|
|
1006
|
+
return teardown;
|
|
1007
|
+
}
|
|
1008
|
+
var $effect = createEffect;
|
|
1009
|
+
function createRenderEffect(fn) {
|
|
1010
|
+
let cleanup;
|
|
1011
|
+
const rootForError = getCurrentRoot();
|
|
1012
|
+
const run = () => {
|
|
1013
|
+
if (cleanup) {
|
|
1014
|
+
cleanup();
|
|
1015
|
+
cleanup = void 0;
|
|
1016
|
+
}
|
|
1017
|
+
try {
|
|
1018
|
+
const maybeCleanup = fn();
|
|
1019
|
+
if (typeof maybeCleanup === "function") {
|
|
1020
|
+
cleanup = maybeCleanup;
|
|
1021
|
+
}
|
|
1022
|
+
} catch (err) {
|
|
1023
|
+
if (handleError(err, { source: "effect" }, rootForError)) {
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
throw err;
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
const disposeEffect = effect(run);
|
|
1030
|
+
const teardown = () => {
|
|
1031
|
+
if (cleanup) {
|
|
1032
|
+
cleanup();
|
|
1033
|
+
cleanup = void 0;
|
|
1034
|
+
}
|
|
1035
|
+
disposeEffect();
|
|
1036
|
+
};
|
|
1037
|
+
registerRootCleanup(teardown);
|
|
1038
|
+
return teardown;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
// src/hooks.ts
|
|
1042
|
+
var ctxStack = [];
|
|
1043
|
+
function __fictUseContext() {
|
|
1044
|
+
if (ctxStack.length === 0) {
|
|
1045
|
+
const ctx2 = { slots: [], cursor: 0 };
|
|
1046
|
+
ctxStack.push(ctx2);
|
|
1047
|
+
return ctx2;
|
|
1048
|
+
}
|
|
1049
|
+
const ctx = ctxStack[ctxStack.length - 1];
|
|
1050
|
+
ctx.cursor = 0;
|
|
1051
|
+
return ctx;
|
|
1052
|
+
}
|
|
1053
|
+
function __fictPushContext() {
|
|
1054
|
+
const ctx = { slots: [], cursor: 0 };
|
|
1055
|
+
ctxStack.push(ctx);
|
|
1056
|
+
return ctx;
|
|
1057
|
+
}
|
|
1058
|
+
function __fictPopContext() {
|
|
1059
|
+
ctxStack.pop();
|
|
1060
|
+
}
|
|
1061
|
+
function __fictResetContext() {
|
|
1062
|
+
ctxStack.length = 0;
|
|
1063
|
+
}
|
|
1064
|
+
function __fictUseSignal(ctx, initial, slot) {
|
|
1065
|
+
const index = slot ?? ctx.cursor++;
|
|
1066
|
+
if (!ctx.slots[index]) {
|
|
1067
|
+
ctx.slots[index] = signal(initial);
|
|
1068
|
+
}
|
|
1069
|
+
return ctx.slots[index];
|
|
1070
|
+
}
|
|
1071
|
+
function __fictUseMemo(ctx, fn, slot) {
|
|
1072
|
+
const index = slot ?? ctx.cursor++;
|
|
1073
|
+
if (!ctx.slots[index]) {
|
|
1074
|
+
ctx.slots[index] = createMemo(fn);
|
|
1075
|
+
}
|
|
1076
|
+
return ctx.slots[index];
|
|
1077
|
+
}
|
|
1078
|
+
function __fictUseEffect(ctx, fn, slot) {
|
|
1079
|
+
const index = slot ?? ctx.cursor++;
|
|
1080
|
+
if (!ctx.slots[index]) {
|
|
1081
|
+
ctx.slots[index] = createEffect(fn);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
function __fictRender(ctx, fn) {
|
|
1085
|
+
ctxStack.push(ctx);
|
|
1086
|
+
ctx.cursor = 0;
|
|
1087
|
+
try {
|
|
1088
|
+
return fn();
|
|
1089
|
+
} finally {
|
|
1090
|
+
ctxStack.pop();
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
// src/versioned-signal.ts
|
|
1095
|
+
function createVersionedSignal(initialValue, options2) {
|
|
1096
|
+
const equals = options2?.equals ?? Object.is;
|
|
1097
|
+
const value = signal(initialValue);
|
|
1098
|
+
const version = signal(0);
|
|
1099
|
+
const bumpVersion = () => {
|
|
1100
|
+
const next = version() + 1;
|
|
1101
|
+
version(next);
|
|
1102
|
+
};
|
|
1103
|
+
return {
|
|
1104
|
+
read: () => {
|
|
1105
|
+
version();
|
|
1106
|
+
return value();
|
|
1107
|
+
},
|
|
1108
|
+
write: (next) => {
|
|
1109
|
+
const prev = value();
|
|
1110
|
+
if (!equals(prev, next)) {
|
|
1111
|
+
value(next);
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
bumpVersion();
|
|
1115
|
+
},
|
|
1116
|
+
force: () => {
|
|
1117
|
+
bumpVersion();
|
|
1118
|
+
},
|
|
1119
|
+
peekVersion: () => version(),
|
|
1120
|
+
peekValue: () => value()
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// src/props.ts
|
|
1125
|
+
var propGetters = /* @__PURE__ */ new WeakSet();
|
|
1126
|
+
var rawToProxy = /* @__PURE__ */ new WeakMap();
|
|
1127
|
+
var proxyToRaw = /* @__PURE__ */ new WeakMap();
|
|
1128
|
+
function __fictProp(getter) {
|
|
1129
|
+
if (typeof getter === "function" && getter.length === 0) {
|
|
1130
|
+
propGetters.add(getter);
|
|
1131
|
+
}
|
|
1132
|
+
return getter;
|
|
1133
|
+
}
|
|
1134
|
+
function isPropGetter(value) {
|
|
1135
|
+
return typeof value === "function" && propGetters.has(value);
|
|
1136
|
+
}
|
|
1137
|
+
function createPropsProxy(props) {
|
|
1138
|
+
if (!props || typeof props !== "object") {
|
|
1139
|
+
return props;
|
|
1140
|
+
}
|
|
1141
|
+
if (proxyToRaw.has(props)) {
|
|
1142
|
+
return props;
|
|
1143
|
+
}
|
|
1144
|
+
const cached = rawToProxy.get(props);
|
|
1145
|
+
if (cached) {
|
|
1146
|
+
return cached;
|
|
1147
|
+
}
|
|
1148
|
+
const proxy = new Proxy(props, {
|
|
1149
|
+
get(target, prop, receiver) {
|
|
1150
|
+
const value = Reflect.get(target, prop, receiver);
|
|
1151
|
+
if (isPropGetter(value)) {
|
|
1152
|
+
return value();
|
|
1153
|
+
}
|
|
1154
|
+
return value;
|
|
1155
|
+
},
|
|
1156
|
+
set(target, prop, value, receiver) {
|
|
1157
|
+
return Reflect.set(target, prop, value, receiver);
|
|
1158
|
+
},
|
|
1159
|
+
has(target, prop) {
|
|
1160
|
+
return prop in target;
|
|
1161
|
+
},
|
|
1162
|
+
ownKeys(target) {
|
|
1163
|
+
return Reflect.ownKeys(target);
|
|
1164
|
+
},
|
|
1165
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
1166
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
rawToProxy.set(props, proxy);
|
|
1170
|
+
proxyToRaw.set(proxy, props);
|
|
1171
|
+
return proxy;
|
|
1172
|
+
}
|
|
1173
|
+
function unwrapProps(props) {
|
|
1174
|
+
if (!props || typeof props !== "object") {
|
|
1175
|
+
return props;
|
|
1176
|
+
}
|
|
1177
|
+
return proxyToRaw.get(props) ?? props;
|
|
1178
|
+
}
|
|
1179
|
+
function __fictPropsRest(props, exclude) {
|
|
1180
|
+
const raw = unwrapProps(props);
|
|
1181
|
+
const out = {};
|
|
1182
|
+
const excludeSet = new Set(exclude);
|
|
1183
|
+
for (const key of Reflect.ownKeys(raw)) {
|
|
1184
|
+
if (excludeSet.has(key)) continue;
|
|
1185
|
+
out[key] = raw[key];
|
|
1186
|
+
}
|
|
1187
|
+
return createPropsProxy(out);
|
|
1188
|
+
}
|
|
1189
|
+
function mergeProps(...sources) {
|
|
1190
|
+
const validSources = sources.filter(
|
|
1191
|
+
(s) => s != null && (typeof s === "object" || typeof s === "function")
|
|
1192
|
+
);
|
|
1193
|
+
if (validSources.length === 0) {
|
|
1194
|
+
return {};
|
|
1195
|
+
}
|
|
1196
|
+
if (validSources.length === 1 && typeof validSources[0] === "object") {
|
|
1197
|
+
return validSources[0];
|
|
1198
|
+
}
|
|
1199
|
+
const resolveSource = (src) => {
|
|
1200
|
+
const value = typeof src === "function" ? src() : src;
|
|
1201
|
+
if (!value || typeof value !== "object") return void 0;
|
|
1202
|
+
return unwrapProps(value);
|
|
1203
|
+
};
|
|
1204
|
+
return new Proxy({}, {
|
|
1205
|
+
get(_, prop) {
|
|
1206
|
+
if (typeof prop === "symbol") {
|
|
1207
|
+
return void 0;
|
|
1208
|
+
}
|
|
1209
|
+
for (let i = validSources.length - 1; i >= 0; i--) {
|
|
1210
|
+
const src = validSources[i];
|
|
1211
|
+
const raw = resolveSource(src);
|
|
1212
|
+
if (!raw || !(prop in raw)) continue;
|
|
1213
|
+
const value = raw[prop];
|
|
1214
|
+
if (typeof src === "function" && !isPropGetter(value)) {
|
|
1215
|
+
return __fictProp(() => {
|
|
1216
|
+
const latest = resolveSource(src);
|
|
1217
|
+
if (!latest || !(prop in latest)) return void 0;
|
|
1218
|
+
return latest[prop];
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
return value;
|
|
1222
|
+
}
|
|
1223
|
+
return void 0;
|
|
1224
|
+
},
|
|
1225
|
+
has(_, prop) {
|
|
1226
|
+
for (const src of validSources) {
|
|
1227
|
+
const raw = resolveSource(src);
|
|
1228
|
+
if (raw && prop in raw) {
|
|
1229
|
+
return true;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
return false;
|
|
1233
|
+
},
|
|
1234
|
+
ownKeys() {
|
|
1235
|
+
const keys = /* @__PURE__ */ new Set();
|
|
1236
|
+
for (const src of validSources) {
|
|
1237
|
+
const raw = resolveSource(src);
|
|
1238
|
+
if (raw) {
|
|
1239
|
+
for (const key of Reflect.ownKeys(raw)) {
|
|
1240
|
+
keys.add(key);
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
return Array.from(keys);
|
|
1245
|
+
},
|
|
1246
|
+
getOwnPropertyDescriptor(_, prop) {
|
|
1247
|
+
for (let i = validSources.length - 1; i >= 0; i--) {
|
|
1248
|
+
const raw = resolveSource(validSources[i]);
|
|
1249
|
+
if (raw && prop in raw) {
|
|
1250
|
+
return {
|
|
1251
|
+
enumerable: true,
|
|
1252
|
+
configurable: true,
|
|
1253
|
+
get: () => {
|
|
1254
|
+
const value = raw[prop];
|
|
1255
|
+
return value;
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
return void 0;
|
|
1261
|
+
}
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
function useProp(getter) {
|
|
1265
|
+
return __fictProp(createMemo(getter));
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
// src/ref.ts
|
|
1269
|
+
function createRef() {
|
|
1270
|
+
return { current: null };
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
// src/transition.ts
|
|
1274
|
+
function startTransition(fn) {
|
|
1275
|
+
const prev = setTransitionContext(true);
|
|
1276
|
+
try {
|
|
1277
|
+
fn();
|
|
1278
|
+
} finally {
|
|
1279
|
+
setTransitionContext(prev);
|
|
1280
|
+
scheduleFlush();
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
function useTransition() {
|
|
1284
|
+
const pending = signal(false);
|
|
1285
|
+
const start = (fn) => {
|
|
1286
|
+
pending(true);
|
|
1287
|
+
startTransition(() => {
|
|
1288
|
+
try {
|
|
1289
|
+
fn();
|
|
1290
|
+
} finally {
|
|
1291
|
+
pending(false);
|
|
1292
|
+
}
|
|
1293
|
+
});
|
|
1294
|
+
};
|
|
1295
|
+
return [() => pending(), start];
|
|
1296
|
+
}
|
|
1297
|
+
function useDeferredValue(getValue) {
|
|
1298
|
+
const deferredValue = signal(getValue());
|
|
1299
|
+
createEffect(() => {
|
|
1300
|
+
const newValue = getValue();
|
|
1301
|
+
const currentDeferred = untrack(() => deferredValue());
|
|
1302
|
+
if (currentDeferred !== newValue) {
|
|
1303
|
+
startTransition(() => {
|
|
1304
|
+
deferredValue(newValue);
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
});
|
|
1308
|
+
return () => deferredValue();
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
// src/scheduler.ts
|
|
1312
|
+
function batch2(fn) {
|
|
1313
|
+
return batch(fn);
|
|
1314
|
+
}
|
|
1315
|
+
function untrack2(fn) {
|
|
1316
|
+
return untrack(fn);
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
// src/jsx.ts
|
|
1320
|
+
var Fragment = Symbol("Fragment");
|
|
1321
|
+
|
|
1322
|
+
// src/constants.ts
|
|
1323
|
+
var booleans = [
|
|
1324
|
+
"allowfullscreen",
|
|
1325
|
+
"async",
|
|
1326
|
+
"alpha",
|
|
1327
|
+
// HTMLInputElement
|
|
1328
|
+
"autofocus",
|
|
1329
|
+
// HTMLElement prop
|
|
1330
|
+
"autoplay",
|
|
1331
|
+
"checked",
|
|
1332
|
+
"controls",
|
|
1333
|
+
"default",
|
|
1334
|
+
"disabled",
|
|
1335
|
+
"formnovalidate",
|
|
1336
|
+
"hidden",
|
|
1337
|
+
// HTMLElement prop
|
|
1338
|
+
"indeterminate",
|
|
1339
|
+
"inert",
|
|
1340
|
+
// HTMLElement prop
|
|
1341
|
+
"ismap",
|
|
1342
|
+
"loop",
|
|
1343
|
+
"multiple",
|
|
1344
|
+
"muted",
|
|
1345
|
+
"nomodule",
|
|
1346
|
+
"novalidate",
|
|
1347
|
+
"open",
|
|
1348
|
+
"playsinline",
|
|
1349
|
+
"readonly",
|
|
1350
|
+
"required",
|
|
1351
|
+
"reversed",
|
|
1352
|
+
"seamless",
|
|
1353
|
+
// HTMLIframeElement - non-standard
|
|
1354
|
+
"selected",
|
|
1355
|
+
// Experimental attributes
|
|
1356
|
+
"adauctionheaders",
|
|
1357
|
+
"browsingtopics",
|
|
1358
|
+
"credentialless",
|
|
1359
|
+
"defaultchecked",
|
|
1360
|
+
"defaultmuted",
|
|
1361
|
+
"defaultselected",
|
|
1362
|
+
"defer",
|
|
1363
|
+
"disablepictureinpicture",
|
|
1364
|
+
"disableremoteplayback",
|
|
1365
|
+
"preservespitch",
|
|
1366
|
+
"shadowrootclonable",
|
|
1367
|
+
"shadowrootcustomelementregistry",
|
|
1368
|
+
"shadowrootdelegatesfocus",
|
|
1369
|
+
"shadowrootserializable",
|
|
1370
|
+
"sharedstoragewritable"
|
|
1371
|
+
];
|
|
1372
|
+
var BooleanAttributes = new Set(booleans);
|
|
1373
|
+
var Properties = /* @__PURE__ */ new Set([
|
|
1374
|
+
// Core properties
|
|
1375
|
+
"className",
|
|
1376
|
+
"value",
|
|
1377
|
+
// CamelCase booleans
|
|
1378
|
+
"readOnly",
|
|
1379
|
+
"noValidate",
|
|
1380
|
+
"formNoValidate",
|
|
1381
|
+
"isMap",
|
|
1382
|
+
"noModule",
|
|
1383
|
+
"playsInline",
|
|
1384
|
+
// Experimental (camelCase)
|
|
1385
|
+
"adAuctionHeaders",
|
|
1386
|
+
"allowFullscreen",
|
|
1387
|
+
"browsingTopics",
|
|
1388
|
+
"defaultChecked",
|
|
1389
|
+
"defaultMuted",
|
|
1390
|
+
"defaultSelected",
|
|
1391
|
+
"disablePictureInPicture",
|
|
1392
|
+
"disableRemotePlayback",
|
|
1393
|
+
"preservesPitch",
|
|
1394
|
+
"shadowRootClonable",
|
|
1395
|
+
"shadowRootCustomElementRegistry",
|
|
1396
|
+
"shadowRootDelegatesFocus",
|
|
1397
|
+
"shadowRootSerializable",
|
|
1398
|
+
"sharedStorageWritable",
|
|
1399
|
+
// All lowercase booleans
|
|
1400
|
+
...booleans
|
|
1401
|
+
]);
|
|
1402
|
+
var ChildProperties = /* @__PURE__ */ new Set([
|
|
1403
|
+
"innerHTML",
|
|
1404
|
+
"textContent",
|
|
1405
|
+
"innerText",
|
|
1406
|
+
"children"
|
|
1407
|
+
]);
|
|
1408
|
+
var Aliases = {
|
|
1409
|
+
className: "class",
|
|
1410
|
+
htmlFor: "for"
|
|
1411
|
+
};
|
|
1412
|
+
var PropAliases = {
|
|
1413
|
+
// Direct mapping
|
|
1414
|
+
class: "className",
|
|
1415
|
+
// Element-specific mappings
|
|
1416
|
+
novalidate: {
|
|
1417
|
+
$: "noValidate",
|
|
1418
|
+
FORM: 1
|
|
1419
|
+
},
|
|
1420
|
+
formnovalidate: {
|
|
1421
|
+
$: "formNoValidate",
|
|
1422
|
+
BUTTON: 1,
|
|
1423
|
+
INPUT: 1
|
|
1424
|
+
},
|
|
1425
|
+
ismap: {
|
|
1426
|
+
$: "isMap",
|
|
1427
|
+
IMG: 1
|
|
1428
|
+
},
|
|
1429
|
+
nomodule: {
|
|
1430
|
+
$: "noModule",
|
|
1431
|
+
SCRIPT: 1
|
|
1432
|
+
},
|
|
1433
|
+
playsinline: {
|
|
1434
|
+
$: "playsInline",
|
|
1435
|
+
VIDEO: 1
|
|
1436
|
+
},
|
|
1437
|
+
readonly: {
|
|
1438
|
+
$: "readOnly",
|
|
1439
|
+
INPUT: 1,
|
|
1440
|
+
TEXTAREA: 1
|
|
1441
|
+
},
|
|
1442
|
+
// Experimental element-specific
|
|
1443
|
+
adauctionheaders: {
|
|
1444
|
+
$: "adAuctionHeaders",
|
|
1445
|
+
IFRAME: 1
|
|
1446
|
+
},
|
|
1447
|
+
allowfullscreen: {
|
|
1448
|
+
$: "allowFullscreen",
|
|
1449
|
+
IFRAME: 1
|
|
1450
|
+
},
|
|
1451
|
+
browsingtopics: {
|
|
1452
|
+
$: "browsingTopics",
|
|
1453
|
+
IMG: 1
|
|
1454
|
+
},
|
|
1455
|
+
defaultchecked: {
|
|
1456
|
+
$: "defaultChecked",
|
|
1457
|
+
INPUT: 1
|
|
1458
|
+
},
|
|
1459
|
+
defaultmuted: {
|
|
1460
|
+
$: "defaultMuted",
|
|
1461
|
+
AUDIO: 1,
|
|
1462
|
+
VIDEO: 1
|
|
1463
|
+
},
|
|
1464
|
+
defaultselected: {
|
|
1465
|
+
$: "defaultSelected",
|
|
1466
|
+
OPTION: 1
|
|
1467
|
+
},
|
|
1468
|
+
disablepictureinpicture: {
|
|
1469
|
+
$: "disablePictureInPicture",
|
|
1470
|
+
VIDEO: 1
|
|
1471
|
+
},
|
|
1472
|
+
disableremoteplayback: {
|
|
1473
|
+
$: "disableRemotePlayback",
|
|
1474
|
+
AUDIO: 1,
|
|
1475
|
+
VIDEO: 1
|
|
1476
|
+
},
|
|
1477
|
+
preservespitch: {
|
|
1478
|
+
$: "preservesPitch",
|
|
1479
|
+
AUDIO: 1,
|
|
1480
|
+
VIDEO: 1
|
|
1481
|
+
},
|
|
1482
|
+
shadowrootclonable: {
|
|
1483
|
+
$: "shadowRootClonable",
|
|
1484
|
+
TEMPLATE: 1
|
|
1485
|
+
},
|
|
1486
|
+
shadowrootdelegatesfocus: {
|
|
1487
|
+
$: "shadowRootDelegatesFocus",
|
|
1488
|
+
TEMPLATE: 1
|
|
1489
|
+
},
|
|
1490
|
+
shadowrootserializable: {
|
|
1491
|
+
$: "shadowRootSerializable",
|
|
1492
|
+
TEMPLATE: 1
|
|
1493
|
+
},
|
|
1494
|
+
sharedstoragewritable: {
|
|
1495
|
+
$: "sharedStorageWritable",
|
|
1496
|
+
IFRAME: 1,
|
|
1497
|
+
IMG: 1
|
|
1498
|
+
}
|
|
1499
|
+
};
|
|
1500
|
+
function getPropAlias(prop, tagName) {
|
|
1501
|
+
const a = PropAliases[prop];
|
|
1502
|
+
if (typeof a === "object") {
|
|
1503
|
+
return a[tagName] ? a["$"] : void 0;
|
|
1504
|
+
}
|
|
1505
|
+
return a;
|
|
1506
|
+
}
|
|
1507
|
+
var $$EVENTS = "_$FICT_DELEGATE";
|
|
1508
|
+
var DelegatedEvents = /* @__PURE__ */ new Set([
|
|
1509
|
+
"beforeinput",
|
|
1510
|
+
"click",
|
|
1511
|
+
"dblclick",
|
|
1512
|
+
"contextmenu",
|
|
1513
|
+
"focusin",
|
|
1514
|
+
"focusout",
|
|
1515
|
+
"input",
|
|
1516
|
+
"keydown",
|
|
1517
|
+
"keyup",
|
|
1518
|
+
"mousedown",
|
|
1519
|
+
"mousemove",
|
|
1520
|
+
"mouseout",
|
|
1521
|
+
"mouseover",
|
|
1522
|
+
"mouseup",
|
|
1523
|
+
"pointerdown",
|
|
1524
|
+
"pointermove",
|
|
1525
|
+
"pointerout",
|
|
1526
|
+
"pointerover",
|
|
1527
|
+
"pointerup",
|
|
1528
|
+
"touchend",
|
|
1529
|
+
"touchmove",
|
|
1530
|
+
"touchstart"
|
|
1531
|
+
]);
|
|
1532
|
+
var SVGElements = /* @__PURE__ */ new Set([
|
|
1533
|
+
"altGlyph",
|
|
1534
|
+
"altGlyphDef",
|
|
1535
|
+
"altGlyphItem",
|
|
1536
|
+
"animate",
|
|
1537
|
+
"animateColor",
|
|
1538
|
+
"animateMotion",
|
|
1539
|
+
"animateTransform",
|
|
1540
|
+
"circle",
|
|
1541
|
+
"clipPath",
|
|
1542
|
+
"color-profile",
|
|
1543
|
+
"cursor",
|
|
1544
|
+
"defs",
|
|
1545
|
+
"desc",
|
|
1546
|
+
"ellipse",
|
|
1547
|
+
"feBlend",
|
|
1548
|
+
"feColorMatrix",
|
|
1549
|
+
"feComponentTransfer",
|
|
1550
|
+
"feComposite",
|
|
1551
|
+
"feConvolveMatrix",
|
|
1552
|
+
"feDiffuseLighting",
|
|
1553
|
+
"feDisplacementMap",
|
|
1554
|
+
"feDistantLight",
|
|
1555
|
+
"feDropShadow",
|
|
1556
|
+
"feFlood",
|
|
1557
|
+
"feFuncA",
|
|
1558
|
+
"feFuncB",
|
|
1559
|
+
"feFuncG",
|
|
1560
|
+
"feFuncR",
|
|
1561
|
+
"feGaussianBlur",
|
|
1562
|
+
"feImage",
|
|
1563
|
+
"feMerge",
|
|
1564
|
+
"feMergeNode",
|
|
1565
|
+
"feMorphology",
|
|
1566
|
+
"feOffset",
|
|
1567
|
+
"fePointLight",
|
|
1568
|
+
"feSpecularLighting",
|
|
1569
|
+
"feSpotLight",
|
|
1570
|
+
"feTile",
|
|
1571
|
+
"feTurbulence",
|
|
1572
|
+
"filter",
|
|
1573
|
+
"font",
|
|
1574
|
+
"font-face",
|
|
1575
|
+
"font-face-format",
|
|
1576
|
+
"font-face-name",
|
|
1577
|
+
"font-face-src",
|
|
1578
|
+
"font-face-uri",
|
|
1579
|
+
"foreignObject",
|
|
1580
|
+
"g",
|
|
1581
|
+
"glyph",
|
|
1582
|
+
"glyphRef",
|
|
1583
|
+
"hkern",
|
|
1584
|
+
"image",
|
|
1585
|
+
"line",
|
|
1586
|
+
"linearGradient",
|
|
1587
|
+
"marker",
|
|
1588
|
+
"mask",
|
|
1589
|
+
"metadata",
|
|
1590
|
+
"missing-glyph",
|
|
1591
|
+
"mpath",
|
|
1592
|
+
"path",
|
|
1593
|
+
"pattern",
|
|
1594
|
+
"polygon",
|
|
1595
|
+
"polyline",
|
|
1596
|
+
"radialGradient",
|
|
1597
|
+
"rect",
|
|
1598
|
+
"set",
|
|
1599
|
+
"stop",
|
|
1600
|
+
"svg",
|
|
1601
|
+
"switch",
|
|
1602
|
+
"symbol",
|
|
1603
|
+
"text",
|
|
1604
|
+
"textPath",
|
|
1605
|
+
"tref",
|
|
1606
|
+
"tspan",
|
|
1607
|
+
"use",
|
|
1608
|
+
"view",
|
|
1609
|
+
"vkern"
|
|
1610
|
+
]);
|
|
1611
|
+
var SVGNamespace = {
|
|
1612
|
+
xlink: "http://www.w3.org/1999/xlink",
|
|
1613
|
+
xml: "http://www.w3.org/XML/1998/namespace"
|
|
1614
|
+
};
|
|
1615
|
+
var UnitlessStyles = /* @__PURE__ */ new Set([
|
|
1616
|
+
"animationIterationCount",
|
|
1617
|
+
"animation-iteration-count",
|
|
1618
|
+
"borderImageOutset",
|
|
1619
|
+
"border-image-outset",
|
|
1620
|
+
"borderImageSlice",
|
|
1621
|
+
"border-image-slice",
|
|
1622
|
+
"borderImageWidth",
|
|
1623
|
+
"border-image-width",
|
|
1624
|
+
"boxFlex",
|
|
1625
|
+
"box-flex",
|
|
1626
|
+
"boxFlexGroup",
|
|
1627
|
+
"box-flex-group",
|
|
1628
|
+
"boxOrdinalGroup",
|
|
1629
|
+
"box-ordinal-group",
|
|
1630
|
+
"columnCount",
|
|
1631
|
+
"column-count",
|
|
1632
|
+
"columns",
|
|
1633
|
+
"flex",
|
|
1634
|
+
"flexGrow",
|
|
1635
|
+
"flex-grow",
|
|
1636
|
+
"flexPositive",
|
|
1637
|
+
"flex-positive",
|
|
1638
|
+
"flexShrink",
|
|
1639
|
+
"flex-shrink",
|
|
1640
|
+
"flexNegative",
|
|
1641
|
+
"flex-negative",
|
|
1642
|
+
"flexOrder",
|
|
1643
|
+
"flex-order",
|
|
1644
|
+
"gridRow",
|
|
1645
|
+
"grid-row",
|
|
1646
|
+
"gridRowEnd",
|
|
1647
|
+
"grid-row-end",
|
|
1648
|
+
"gridRowSpan",
|
|
1649
|
+
"grid-row-span",
|
|
1650
|
+
"gridRowStart",
|
|
1651
|
+
"grid-row-start",
|
|
1652
|
+
"gridColumn",
|
|
1653
|
+
"grid-column",
|
|
1654
|
+
"gridColumnEnd",
|
|
1655
|
+
"grid-column-end",
|
|
1656
|
+
"gridColumnSpan",
|
|
1657
|
+
"grid-column-span",
|
|
1658
|
+
"gridColumnStart",
|
|
1659
|
+
"grid-column-start",
|
|
1660
|
+
"fontWeight",
|
|
1661
|
+
"font-weight",
|
|
1662
|
+
"lineClamp",
|
|
1663
|
+
"line-clamp",
|
|
1664
|
+
"lineHeight",
|
|
1665
|
+
"line-height",
|
|
1666
|
+
"opacity",
|
|
1667
|
+
"order",
|
|
1668
|
+
"orphans",
|
|
1669
|
+
"tabSize",
|
|
1670
|
+
"tab-size",
|
|
1671
|
+
"widows",
|
|
1672
|
+
"zIndex",
|
|
1673
|
+
"z-index",
|
|
1674
|
+
"zoom",
|
|
1675
|
+
"fillOpacity",
|
|
1676
|
+
"fill-opacity",
|
|
1677
|
+
"floodOpacity",
|
|
1678
|
+
"flood-opacity",
|
|
1679
|
+
"stopOpacity",
|
|
1680
|
+
"stop-opacity",
|
|
1681
|
+
"strokeDasharray",
|
|
1682
|
+
"stroke-dasharray",
|
|
1683
|
+
"strokeDashoffset",
|
|
1684
|
+
"stroke-dashoffset",
|
|
1685
|
+
"strokeMiterlimit",
|
|
1686
|
+
"stroke-miterlimit",
|
|
1687
|
+
"strokeOpacity",
|
|
1688
|
+
"stroke-opacity",
|
|
1689
|
+
"strokeWidth",
|
|
1690
|
+
"stroke-width"
|
|
1691
|
+
]);
|
|
1692
|
+
|
|
1693
|
+
// src/node-ops.ts
|
|
1694
|
+
function toNodeArray(node) {
|
|
1695
|
+
try {
|
|
1696
|
+
if (Array.isArray(node)) {
|
|
1697
|
+
let allNodes = true;
|
|
1698
|
+
for (const item of node) {
|
|
1699
|
+
let isItemNode = false;
|
|
1700
|
+
try {
|
|
1701
|
+
isItemNode = item instanceof Node;
|
|
1702
|
+
} catch {
|
|
1703
|
+
isItemNode = false;
|
|
1704
|
+
}
|
|
1705
|
+
if (!isItemNode) {
|
|
1706
|
+
allNodes = false;
|
|
1707
|
+
break;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
if (allNodes) {
|
|
1711
|
+
return node;
|
|
1712
|
+
}
|
|
1713
|
+
const result = [];
|
|
1714
|
+
for (const item of node) {
|
|
1715
|
+
result.push(...toNodeArray(item));
|
|
1716
|
+
}
|
|
1717
|
+
return result;
|
|
1718
|
+
}
|
|
1719
|
+
if (node === null || node === void 0 || node === false) {
|
|
1720
|
+
return [];
|
|
1721
|
+
}
|
|
1722
|
+
} catch {
|
|
1723
|
+
return [];
|
|
1724
|
+
}
|
|
1725
|
+
let isNode = false;
|
|
1726
|
+
try {
|
|
1727
|
+
isNode = node instanceof Node;
|
|
1728
|
+
} catch {
|
|
1729
|
+
isNode = false;
|
|
1730
|
+
}
|
|
1731
|
+
if (isNode) {
|
|
1732
|
+
try {
|
|
1733
|
+
if (node instanceof DocumentFragment) {
|
|
1734
|
+
return Array.from(node.childNodes);
|
|
1735
|
+
}
|
|
1736
|
+
} catch {
|
|
1737
|
+
}
|
|
1738
|
+
return [node];
|
|
1739
|
+
}
|
|
1740
|
+
try {
|
|
1741
|
+
if (typeof node === "object" && node !== null && "marker" in node) {
|
|
1742
|
+
return toNodeArray(node.marker);
|
|
1743
|
+
}
|
|
1744
|
+
} catch {
|
|
1745
|
+
}
|
|
1746
|
+
try {
|
|
1747
|
+
return [document.createTextNode(String(node))];
|
|
1748
|
+
} catch {
|
|
1749
|
+
return [document.createTextNode("")];
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
function insertNodesBefore(parent, nodes, anchor) {
|
|
1753
|
+
if (nodes.length === 0) return;
|
|
1754
|
+
if (nodes.length === 1) {
|
|
1755
|
+
const node = nodes[0];
|
|
1756
|
+
if (node === void 0 || node === null) return;
|
|
1757
|
+
if (node.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
|
|
1758
|
+
parent.ownerDocument.adoptNode(node);
|
|
1759
|
+
}
|
|
1760
|
+
try {
|
|
1761
|
+
parent.insertBefore(node, anchor);
|
|
1762
|
+
} catch (e) {
|
|
1763
|
+
if (parent.ownerDocument) {
|
|
1764
|
+
try {
|
|
1765
|
+
const clone = parent.ownerDocument.importNode(node, true);
|
|
1766
|
+
parent.insertBefore(clone, anchor);
|
|
1767
|
+
return;
|
|
1768
|
+
} catch {
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
throw e;
|
|
1772
|
+
}
|
|
1773
|
+
return;
|
|
1774
|
+
}
|
|
1775
|
+
const doc = parent.ownerDocument;
|
|
1776
|
+
if (doc) {
|
|
1777
|
+
const frag = doc.createDocumentFragment();
|
|
1778
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
1779
|
+
const node = nodes[i];
|
|
1780
|
+
if (node === void 0 || node === null) continue;
|
|
1781
|
+
if (node.nodeType === 11) {
|
|
1782
|
+
const childrenArr = Array.from(node.childNodes);
|
|
1783
|
+
for (let j = 0; j < childrenArr.length; j++) {
|
|
1784
|
+
frag.appendChild(childrenArr[j]);
|
|
1785
|
+
}
|
|
1786
|
+
} else {
|
|
1787
|
+
if (node.ownerDocument !== doc) {
|
|
1788
|
+
doc.adoptNode(node);
|
|
1789
|
+
}
|
|
1790
|
+
frag.appendChild(node);
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
parent.insertBefore(frag, anchor);
|
|
1794
|
+
return;
|
|
1795
|
+
}
|
|
1796
|
+
const insertSingle = (nodeToInsert, anchorNode) => {
|
|
1797
|
+
if (nodeToInsert.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
|
|
1798
|
+
parent.ownerDocument.adoptNode(nodeToInsert);
|
|
1799
|
+
}
|
|
1800
|
+
try {
|
|
1801
|
+
parent.insertBefore(nodeToInsert, anchorNode);
|
|
1802
|
+
return nodeToInsert;
|
|
1803
|
+
} catch (e) {
|
|
1804
|
+
if (parent.ownerDocument) {
|
|
1805
|
+
try {
|
|
1806
|
+
const clone = parent.ownerDocument.importNode(nodeToInsert, true);
|
|
1807
|
+
parent.insertBefore(clone, anchorNode);
|
|
1808
|
+
return clone;
|
|
1809
|
+
} catch {
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
throw e;
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1815
|
+
for (let i = nodes.length - 1; i >= 0; i--) {
|
|
1816
|
+
const node = nodes[i];
|
|
1817
|
+
if (node === void 0 || node === null) continue;
|
|
1818
|
+
const isFrag = node.nodeType === 11;
|
|
1819
|
+
if (isFrag) {
|
|
1820
|
+
const childrenArr = Array.from(node.childNodes);
|
|
1821
|
+
for (let j = childrenArr.length - 1; j >= 0; j--) {
|
|
1822
|
+
const child = childrenArr[j];
|
|
1823
|
+
anchor = insertSingle(child, anchor);
|
|
1824
|
+
}
|
|
1825
|
+
} else {
|
|
1826
|
+
anchor = insertSingle(node, anchor);
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
function removeNodes(nodes) {
|
|
1831
|
+
for (const node of nodes) {
|
|
1832
|
+
node.parentNode?.removeChild(node);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
// src/binding.ts
|
|
1837
|
+
function isReactive(value) {
|
|
1838
|
+
return typeof value === "function" && value.length === 0;
|
|
1839
|
+
}
|
|
1840
|
+
function unwrap2(value) {
|
|
1841
|
+
return isReactive(value) ? value() : value;
|
|
1842
|
+
}
|
|
1843
|
+
var PRIMITIVE_PROXY = Symbol("fict:primitive-proxy");
|
|
1844
|
+
var PRIMITIVE_PROXY_RAW_VALUE = Symbol("fict:primitive-proxy:raw-value");
|
|
1845
|
+
function unwrapPrimitive(value) {
|
|
1846
|
+
if (value && typeof value === "object" && PRIMITIVE_PROXY in value) {
|
|
1847
|
+
const getRawValue = value[PRIMITIVE_PROXY_RAW_VALUE];
|
|
1848
|
+
if (typeof getRawValue === "function") {
|
|
1849
|
+
return getRawValue();
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
return value;
|
|
1853
|
+
}
|
|
1854
|
+
function createValueProxy(read) {
|
|
1855
|
+
const getPrimitivePrototype = (value) => {
|
|
1856
|
+
switch (typeof value) {
|
|
1857
|
+
case "string":
|
|
1858
|
+
return String.prototype;
|
|
1859
|
+
case "number":
|
|
1860
|
+
return Number.prototype;
|
|
1861
|
+
case "boolean":
|
|
1862
|
+
return Boolean.prototype;
|
|
1863
|
+
case "bigint":
|
|
1864
|
+
return BigInt.prototype;
|
|
1865
|
+
case "symbol":
|
|
1866
|
+
return Symbol.prototype;
|
|
1867
|
+
default:
|
|
1868
|
+
return void 0;
|
|
1869
|
+
}
|
|
1870
|
+
};
|
|
1871
|
+
const target = {};
|
|
1872
|
+
const handler = {
|
|
1873
|
+
get(_target, prop, receiver) {
|
|
1874
|
+
if (prop === PRIMITIVE_PROXY) {
|
|
1875
|
+
return true;
|
|
1876
|
+
}
|
|
1877
|
+
if (prop === PRIMITIVE_PROXY_RAW_VALUE) {
|
|
1878
|
+
return () => read();
|
|
1879
|
+
}
|
|
1880
|
+
if (prop === Symbol.toPrimitive) {
|
|
1881
|
+
return (hint) => {
|
|
1882
|
+
const value2 = read();
|
|
1883
|
+
if (value2 != null && (typeof value2 === "object" || typeof value2 === "function")) {
|
|
1884
|
+
const toPrimitive = value2[Symbol.toPrimitive];
|
|
1885
|
+
if (typeof toPrimitive === "function") {
|
|
1886
|
+
return toPrimitive.call(value2, hint);
|
|
1887
|
+
}
|
|
1888
|
+
if (hint === "string") return value2.toString?.() ?? "[object Object]";
|
|
1889
|
+
if (hint === "number") return value2.valueOf?.() ?? value2;
|
|
1890
|
+
return value2.valueOf?.() ?? value2;
|
|
1891
|
+
}
|
|
1892
|
+
return value2;
|
|
1893
|
+
};
|
|
1894
|
+
}
|
|
1895
|
+
if (prop === "valueOf") {
|
|
1896
|
+
return () => {
|
|
1897
|
+
const value2 = read();
|
|
1898
|
+
if (value2 != null && (typeof value2 === "object" || typeof value2 === "function")) {
|
|
1899
|
+
return typeof value2.valueOf === "function" ? value2.valueOf() : value2;
|
|
1900
|
+
}
|
|
1901
|
+
return value2;
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
if (prop === "toString") {
|
|
1905
|
+
return () => String(read());
|
|
1906
|
+
}
|
|
1907
|
+
const value = read();
|
|
1908
|
+
if (value != null && (typeof value === "object" || typeof value === "function")) {
|
|
1909
|
+
return Reflect.get(value, prop, receiver === _target ? value : receiver);
|
|
1910
|
+
}
|
|
1911
|
+
const proto = getPrimitivePrototype(value);
|
|
1912
|
+
if (proto && prop in proto) {
|
|
1913
|
+
const descriptor = Reflect.get(proto, prop, value);
|
|
1914
|
+
return typeof descriptor === "function" ? descriptor.bind(value) : descriptor;
|
|
1915
|
+
}
|
|
1916
|
+
return void 0;
|
|
1917
|
+
},
|
|
1918
|
+
set(_target, prop, newValue, receiver) {
|
|
1919
|
+
const value = read();
|
|
1920
|
+
if (value != null && (typeof value === "object" || typeof value === "function")) {
|
|
1921
|
+
return Reflect.set(value, prop, newValue, receiver === _target ? value : receiver);
|
|
1922
|
+
}
|
|
1923
|
+
return false;
|
|
1924
|
+
},
|
|
1925
|
+
has(_target, prop) {
|
|
1926
|
+
if (prop === PRIMITIVE_PROXY || prop === PRIMITIVE_PROXY_RAW_VALUE) {
|
|
1927
|
+
return true;
|
|
1928
|
+
}
|
|
1929
|
+
const value = read();
|
|
1930
|
+
if (value != null && (typeof value === "object" || typeof value === "function")) {
|
|
1931
|
+
return prop in value;
|
|
1932
|
+
}
|
|
1933
|
+
const proto = getPrimitivePrototype(value);
|
|
1934
|
+
return proto ? prop in proto : false;
|
|
1935
|
+
},
|
|
1936
|
+
ownKeys() {
|
|
1937
|
+
const value = read();
|
|
1938
|
+
if (value != null && (typeof value === "object" || typeof value === "function")) {
|
|
1939
|
+
return Reflect.ownKeys(value);
|
|
1940
|
+
}
|
|
1941
|
+
const proto = getPrimitivePrototype(value);
|
|
1942
|
+
return proto ? Reflect.ownKeys(proto) : [];
|
|
1943
|
+
},
|
|
1944
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
1945
|
+
const value = read();
|
|
1946
|
+
if (value != null && (typeof value === "object" || typeof value === "function")) {
|
|
1947
|
+
return Object.getOwnPropertyDescriptor(value, prop);
|
|
1948
|
+
}
|
|
1949
|
+
const proto = getPrimitivePrototype(value);
|
|
1950
|
+
return proto ? Object.getOwnPropertyDescriptor(proto, prop) || void 0 : void 0;
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
return new Proxy(target, handler);
|
|
1954
|
+
}
|
|
1955
|
+
function createTextBinding(value) {
|
|
1956
|
+
const text = document.createTextNode("");
|
|
1957
|
+
if (isReactive(value)) {
|
|
1958
|
+
createRenderEffect(() => {
|
|
1959
|
+
const v = value();
|
|
1960
|
+
const fmt = formatTextValue(v);
|
|
1961
|
+
if (text.data !== fmt) {
|
|
1962
|
+
text.data = fmt;
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
} else {
|
|
1966
|
+
text.data = formatTextValue(value);
|
|
1967
|
+
}
|
|
1968
|
+
return text;
|
|
1969
|
+
}
|
|
1970
|
+
function bindText(textNode, getValue) {
|
|
1971
|
+
return createRenderEffect(() => {
|
|
1972
|
+
const value = formatTextValue(getValue());
|
|
1973
|
+
if (textNode.data !== value) {
|
|
1974
|
+
textNode.data = value;
|
|
1975
|
+
}
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
function formatTextValue(value) {
|
|
1979
|
+
if (value == null || value === false) {
|
|
1980
|
+
return "";
|
|
1981
|
+
}
|
|
1982
|
+
return String(value);
|
|
1983
|
+
}
|
|
1984
|
+
function createAttributeBinding(el, key, value, setter) {
|
|
1985
|
+
if (isReactive(value)) {
|
|
1986
|
+
createRenderEffect(() => {
|
|
1987
|
+
setter(el, key, value());
|
|
1988
|
+
});
|
|
1989
|
+
} else {
|
|
1990
|
+
setter(el, key, value);
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
function bindAttribute(el, key, getValue) {
|
|
1994
|
+
let prevValue = void 0;
|
|
1995
|
+
return createRenderEffect(() => {
|
|
1996
|
+
const value = getValue();
|
|
1997
|
+
if (value === prevValue) return;
|
|
1998
|
+
prevValue = value;
|
|
1999
|
+
if (value === void 0 || value === null || value === false) {
|
|
2000
|
+
el.removeAttribute(key);
|
|
2001
|
+
} else if (value === true) {
|
|
2002
|
+
el.setAttribute(key, "");
|
|
2003
|
+
} else {
|
|
2004
|
+
el.setAttribute(key, String(value));
|
|
2005
|
+
}
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
function bindProperty(el, key, getValue) {
|
|
2009
|
+
const PROPERTY_BINDING_KEYS = /* @__PURE__ */ new Set([
|
|
2010
|
+
"value",
|
|
2011
|
+
"checked",
|
|
2012
|
+
"selected",
|
|
2013
|
+
"disabled",
|
|
2014
|
+
"readOnly",
|
|
2015
|
+
"multiple",
|
|
2016
|
+
"muted"
|
|
2017
|
+
]);
|
|
2018
|
+
let prevValue = void 0;
|
|
2019
|
+
return createRenderEffect(() => {
|
|
2020
|
+
const next = getValue();
|
|
2021
|
+
if (next === prevValue) return;
|
|
2022
|
+
prevValue = next;
|
|
2023
|
+
if (PROPERTY_BINDING_KEYS.has(key) && (next === void 0 || next === null)) {
|
|
2024
|
+
const fallback = key === "checked" || key === "selected" ? false : "";
|
|
2025
|
+
el[key] = fallback;
|
|
2026
|
+
return;
|
|
2027
|
+
}
|
|
2028
|
+
;
|
|
2029
|
+
el[key] = next;
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
function createStyleBinding(el, value) {
|
|
2033
|
+
if (isReactive(value)) {
|
|
2034
|
+
let prev;
|
|
2035
|
+
createRenderEffect(() => {
|
|
2036
|
+
const next = value();
|
|
2037
|
+
applyStyle(el, next, prev);
|
|
2038
|
+
prev = next;
|
|
2039
|
+
});
|
|
2040
|
+
} else {
|
|
2041
|
+
applyStyle(el, value, void 0);
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
function bindStyle(el, getValue) {
|
|
2045
|
+
let prev;
|
|
2046
|
+
return createRenderEffect(() => {
|
|
2047
|
+
const next = getValue();
|
|
2048
|
+
applyStyle(el, next, prev);
|
|
2049
|
+
prev = next;
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
function applyStyle(el, value, prev) {
|
|
2053
|
+
if (typeof value === "string") {
|
|
2054
|
+
el.style.cssText = value;
|
|
2055
|
+
} else if (value && typeof value === "object") {
|
|
2056
|
+
const styles = value;
|
|
2057
|
+
if (typeof prev === "string") {
|
|
2058
|
+
el.style.cssText = "";
|
|
2059
|
+
}
|
|
2060
|
+
if (prev && typeof prev === "object") {
|
|
2061
|
+
const prevStyles = prev;
|
|
2062
|
+
for (const key of Object.keys(prevStyles)) {
|
|
2063
|
+
if (!(key in styles)) {
|
|
2064
|
+
const cssProperty = key.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
2065
|
+
el.style.removeProperty(cssProperty);
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
for (const [prop, v] of Object.entries(styles)) {
|
|
2070
|
+
if (v != null) {
|
|
2071
|
+
const cssProperty = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
2072
|
+
const unitless = isUnitlessStyleProperty(prop) || isUnitlessStyleProperty(cssProperty);
|
|
2073
|
+
const valueStr = typeof v === "number" && !unitless ? `${v}px` : String(v);
|
|
2074
|
+
el.style.setProperty(cssProperty, valueStr);
|
|
2075
|
+
} else {
|
|
2076
|
+
const cssProperty = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
2077
|
+
el.style.removeProperty(cssProperty);
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
} else {
|
|
2081
|
+
if (prev && typeof prev === "object") {
|
|
2082
|
+
const prevStyles = prev;
|
|
2083
|
+
for (const key of Object.keys(prevStyles)) {
|
|
2084
|
+
const cssProperty = key.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
2085
|
+
el.style.removeProperty(cssProperty);
|
|
2086
|
+
}
|
|
2087
|
+
} else if (typeof prev === "string") {
|
|
2088
|
+
el.style.cssText = "";
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
function isUnitlessStyleProperty(prop) {
|
|
2093
|
+
return UnitlessStyles.has(prop);
|
|
2094
|
+
}
|
|
2095
|
+
function createClassBinding(el, value) {
|
|
2096
|
+
if (isReactive(value)) {
|
|
2097
|
+
let prev = {};
|
|
2098
|
+
createRenderEffect(() => {
|
|
2099
|
+
const next = value();
|
|
2100
|
+
prev = applyClass(el, next, prev);
|
|
2101
|
+
});
|
|
2102
|
+
} else {
|
|
2103
|
+
applyClass(el, value, {});
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
function bindClass(el, getValue) {
|
|
2107
|
+
let prev = {};
|
|
2108
|
+
return createRenderEffect(() => {
|
|
2109
|
+
const next = getValue();
|
|
2110
|
+
prev = applyClass(el, next, prev);
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
function toggleClassKey(node, key, value) {
|
|
2114
|
+
const classNames = key.trim().split(/\s+/);
|
|
2115
|
+
for (let i = 0, len = classNames.length; i < len; i++) {
|
|
2116
|
+
node.classList.toggle(classNames[i], value);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
function applyClass(el, value, prev) {
|
|
2120
|
+
const prevState = prev && typeof prev === "object" ? prev : {};
|
|
2121
|
+
if (typeof value === "string") {
|
|
2122
|
+
el.className = value;
|
|
2123
|
+
return {};
|
|
2124
|
+
}
|
|
2125
|
+
if (value && typeof value === "object") {
|
|
2126
|
+
const classes = value;
|
|
2127
|
+
const classKeys = Object.keys(classes);
|
|
2128
|
+
const prevKeys = Object.keys(prevState);
|
|
2129
|
+
for (let i = 0, len = prevKeys.length; i < len; i++) {
|
|
2130
|
+
const key = prevKeys[i];
|
|
2131
|
+
if (!key || key === "undefined" || classes[key]) continue;
|
|
2132
|
+
toggleClassKey(el, key, false);
|
|
2133
|
+
delete prevState[key];
|
|
2134
|
+
}
|
|
2135
|
+
for (let i = 0, len = classKeys.length; i < len; i++) {
|
|
2136
|
+
const key = classKeys[i];
|
|
2137
|
+
const classValue = !!classes[key];
|
|
2138
|
+
if (!key || key === "undefined" || prevState[key] === classValue || !classValue) continue;
|
|
2139
|
+
toggleClassKey(el, key, true);
|
|
2140
|
+
prevState[key] = classValue;
|
|
2141
|
+
}
|
|
2142
|
+
return prevState;
|
|
2143
|
+
}
|
|
2144
|
+
if (!value) {
|
|
2145
|
+
for (const key of Object.keys(prevState)) {
|
|
2146
|
+
if (key && key !== "undefined") {
|
|
2147
|
+
toggleClassKey(el, key, false);
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
return {};
|
|
2151
|
+
}
|
|
2152
|
+
return prevState;
|
|
2153
|
+
}
|
|
2154
|
+
function classList(node, value, prev = {}) {
|
|
2155
|
+
return applyClass(node, value, prev);
|
|
2156
|
+
}
|
|
2157
|
+
function insert(parent, getValue, markerOrCreateElement, createElementFn) {
|
|
2158
|
+
let marker;
|
|
2159
|
+
let ownsMarker = false;
|
|
2160
|
+
let createFn = createElementFn;
|
|
2161
|
+
if (markerOrCreateElement instanceof Node) {
|
|
2162
|
+
marker = markerOrCreateElement;
|
|
2163
|
+
createFn = createElementFn;
|
|
2164
|
+
} else {
|
|
2165
|
+
marker = document.createComment("fict:insert");
|
|
2166
|
+
parent.appendChild(marker);
|
|
2167
|
+
createFn = markerOrCreateElement;
|
|
2168
|
+
ownsMarker = true;
|
|
2169
|
+
}
|
|
2170
|
+
let currentNodes = [];
|
|
2171
|
+
let currentText = null;
|
|
2172
|
+
let currentRoot2 = null;
|
|
2173
|
+
const clearCurrentNodes = () => {
|
|
2174
|
+
if (currentNodes.length > 0) {
|
|
2175
|
+
removeNodes(currentNodes);
|
|
2176
|
+
currentNodes = [];
|
|
2177
|
+
}
|
|
2178
|
+
};
|
|
2179
|
+
const setTextNode = (textValue, shouldInsert, parentNode) => {
|
|
2180
|
+
if (!currentText) {
|
|
2181
|
+
currentText = document.createTextNode(textValue);
|
|
2182
|
+
} else if (currentText.data !== textValue) {
|
|
2183
|
+
currentText.data = textValue;
|
|
2184
|
+
}
|
|
2185
|
+
if (!shouldInsert) {
|
|
2186
|
+
clearCurrentNodes();
|
|
2187
|
+
return;
|
|
2188
|
+
}
|
|
2189
|
+
if (currentNodes.length === 1 && currentNodes[0] === currentText) {
|
|
2190
|
+
return;
|
|
2191
|
+
}
|
|
2192
|
+
clearCurrentNodes();
|
|
2193
|
+
insertNodesBefore(parentNode, [currentText], marker);
|
|
2194
|
+
currentNodes = [currentText];
|
|
2195
|
+
};
|
|
2196
|
+
const dispose = createRenderEffect(() => {
|
|
2197
|
+
const value = getValue();
|
|
2198
|
+
const parentNode = marker.parentNode;
|
|
2199
|
+
const isPrimitive = value == null || value === false || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
2200
|
+
if (isPrimitive) {
|
|
2201
|
+
if (currentRoot2) {
|
|
2202
|
+
destroyRoot(currentRoot2);
|
|
2203
|
+
currentRoot2 = null;
|
|
2204
|
+
}
|
|
2205
|
+
if (!parentNode) {
|
|
2206
|
+
clearCurrentNodes();
|
|
2207
|
+
return;
|
|
2208
|
+
}
|
|
2209
|
+
const textValue = value == null || value === false ? "" : String(value);
|
|
2210
|
+
const shouldInsert = value != null && value !== false;
|
|
2211
|
+
setTextNode(textValue, shouldInsert, parentNode);
|
|
2212
|
+
return;
|
|
2213
|
+
}
|
|
2214
|
+
if (currentRoot2) {
|
|
2215
|
+
destroyRoot(currentRoot2);
|
|
2216
|
+
currentRoot2 = null;
|
|
2217
|
+
}
|
|
2218
|
+
clearCurrentNodes();
|
|
2219
|
+
const root = createRootContext();
|
|
2220
|
+
const prev = pushRoot(root);
|
|
2221
|
+
let nodes = [];
|
|
2222
|
+
try {
|
|
2223
|
+
let newNode;
|
|
2224
|
+
if (value instanceof Node) {
|
|
2225
|
+
newNode = value;
|
|
2226
|
+
} else if (Array.isArray(value)) {
|
|
2227
|
+
if (value.every((v) => v instanceof Node)) {
|
|
2228
|
+
newNode = value;
|
|
2229
|
+
} else {
|
|
2230
|
+
newNode = createFn ? createFn(value) : document.createTextNode(String(value));
|
|
2231
|
+
}
|
|
2232
|
+
} else {
|
|
2233
|
+
newNode = createFn ? createFn(value) : document.createTextNode(String(value));
|
|
2234
|
+
}
|
|
2235
|
+
nodes = toNodeArray(newNode);
|
|
2236
|
+
if (parentNode) {
|
|
2237
|
+
insertNodesBefore(parentNode, nodes, marker);
|
|
2238
|
+
}
|
|
2239
|
+
} finally {
|
|
2240
|
+
popRoot(prev);
|
|
2241
|
+
flushOnMount(root);
|
|
2242
|
+
}
|
|
2243
|
+
currentRoot2 = root;
|
|
2244
|
+
currentNodes = nodes;
|
|
2245
|
+
});
|
|
2246
|
+
return () => {
|
|
2247
|
+
dispose();
|
|
2248
|
+
if (currentRoot2) {
|
|
2249
|
+
destroyRoot(currentRoot2);
|
|
2250
|
+
currentRoot2 = null;
|
|
2251
|
+
}
|
|
2252
|
+
clearCurrentNodes();
|
|
2253
|
+
if (ownsMarker) {
|
|
2254
|
+
marker.parentNode?.removeChild(marker);
|
|
2255
|
+
}
|
|
2256
|
+
};
|
|
2257
|
+
}
|
|
2258
|
+
function createChildBinding(parent, getValue, createElementFn) {
|
|
2259
|
+
const marker = document.createComment("fict:child");
|
|
2260
|
+
parent.appendChild(marker);
|
|
2261
|
+
const dispose = createRenderEffect(() => {
|
|
2262
|
+
const root = createRootContext();
|
|
2263
|
+
const prev = pushRoot(root);
|
|
2264
|
+
let nodes = [];
|
|
2265
|
+
let handledError = false;
|
|
2266
|
+
try {
|
|
2267
|
+
const value = getValue();
|
|
2268
|
+
if (value == null || value === false) {
|
|
2269
|
+
return;
|
|
2270
|
+
}
|
|
2271
|
+
const output = createElementFn(value);
|
|
2272
|
+
nodes = toNodeArray(output);
|
|
2273
|
+
const parentNode = marker.parentNode;
|
|
2274
|
+
if (parentNode) {
|
|
2275
|
+
insertNodesBefore(parentNode, nodes, marker);
|
|
2276
|
+
}
|
|
2277
|
+
return () => {
|
|
2278
|
+
destroyRoot(root);
|
|
2279
|
+
removeNodes(nodes);
|
|
2280
|
+
};
|
|
2281
|
+
} catch (err) {
|
|
2282
|
+
if (handleSuspend(err, root)) {
|
|
2283
|
+
handledError = true;
|
|
2284
|
+
destroyRoot(root);
|
|
2285
|
+
return;
|
|
2286
|
+
}
|
|
2287
|
+
if (handleError(err, { source: "renderChild" }, root)) {
|
|
2288
|
+
handledError = true;
|
|
2289
|
+
destroyRoot(root);
|
|
2290
|
+
return;
|
|
2291
|
+
}
|
|
2292
|
+
throw err;
|
|
2293
|
+
} finally {
|
|
2294
|
+
popRoot(prev);
|
|
2295
|
+
if (!handledError) {
|
|
2296
|
+
flushOnMount(root);
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
});
|
|
2300
|
+
return {
|
|
2301
|
+
marker,
|
|
2302
|
+
dispose: () => {
|
|
2303
|
+
dispose();
|
|
2304
|
+
marker.parentNode?.removeChild(marker);
|
|
2305
|
+
}
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
function delegateEvents(eventNames, doc = window.document) {
|
|
2309
|
+
const e = doc[$$EVENTS] || (doc[$$EVENTS] = /* @__PURE__ */ new Set());
|
|
2310
|
+
for (let i = 0, l = eventNames.length; i < l; i++) {
|
|
2311
|
+
const name = eventNames[i];
|
|
2312
|
+
if (!e.has(name)) {
|
|
2313
|
+
e.add(name);
|
|
2314
|
+
doc.addEventListener(name, globalEventHandler);
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
function clearDelegatedEvents(doc = window.document) {
|
|
2319
|
+
const e = doc[$$EVENTS];
|
|
2320
|
+
if (e) {
|
|
2321
|
+
for (const name of e.keys()) {
|
|
2322
|
+
doc.removeEventListener(name, globalEventHandler);
|
|
2323
|
+
}
|
|
2324
|
+
delete doc[$$EVENTS];
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
function globalEventHandler(e) {
|
|
2328
|
+
let node = e.target;
|
|
2329
|
+
const key = `$$${e.type}`;
|
|
2330
|
+
const dataKey = `${key}Data`;
|
|
2331
|
+
const oriTarget = e.target;
|
|
2332
|
+
const oriCurrentTarget = e.currentTarget;
|
|
2333
|
+
const retarget = (value) => Object.defineProperty(e, "target", {
|
|
2334
|
+
configurable: true,
|
|
2335
|
+
value
|
|
2336
|
+
});
|
|
2337
|
+
const handleNode = () => {
|
|
2338
|
+
if (!node) return false;
|
|
2339
|
+
const handler = node[key];
|
|
2340
|
+
if (handler && !node.disabled) {
|
|
2341
|
+
const resolveData = (value) => {
|
|
2342
|
+
if (typeof value === "function") {
|
|
2343
|
+
try {
|
|
2344
|
+
const fn = value;
|
|
2345
|
+
return fn.length > 0 ? fn(e) : fn();
|
|
2346
|
+
} catch {
|
|
2347
|
+
return value();
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
return value;
|
|
2351
|
+
};
|
|
2352
|
+
const rawData = node[dataKey];
|
|
2353
|
+
const hasData = rawData !== void 0;
|
|
2354
|
+
const resolvedNodeData = hasData ? resolveData(rawData) : void 0;
|
|
2355
|
+
if (typeof handler === "function") {
|
|
2356
|
+
if (hasData) {
|
|
2357
|
+
;
|
|
2358
|
+
handler.call(node, resolvedNodeData, e);
|
|
2359
|
+
} else {
|
|
2360
|
+
;
|
|
2361
|
+
handler.call(node, e);
|
|
2362
|
+
}
|
|
2363
|
+
} else if (Array.isArray(handler)) {
|
|
2364
|
+
const tupleData = resolveData(handler[1]);
|
|
2365
|
+
handler[0].call(node, tupleData, e);
|
|
2366
|
+
}
|
|
2367
|
+
if (e.cancelBubble) return false;
|
|
2368
|
+
}
|
|
2369
|
+
const shadowHost = node.host;
|
|
2370
|
+
if (shadowHost && typeof shadowHost !== "string" && !shadowHost._$host && node.contains(e.target)) {
|
|
2371
|
+
retarget(shadowHost);
|
|
2372
|
+
}
|
|
2373
|
+
return true;
|
|
2374
|
+
};
|
|
2375
|
+
const walkUpTree = () => {
|
|
2376
|
+
while (handleNode() && node) {
|
|
2377
|
+
node = node._$host || node.parentNode || node.host;
|
|
2378
|
+
}
|
|
2379
|
+
};
|
|
2380
|
+
Object.defineProperty(e, "currentTarget", {
|
|
2381
|
+
configurable: true,
|
|
2382
|
+
get() {
|
|
2383
|
+
return node || document;
|
|
2384
|
+
}
|
|
2385
|
+
});
|
|
2386
|
+
if (e.composedPath) {
|
|
2387
|
+
const path = e.composedPath();
|
|
2388
|
+
retarget(path[0]);
|
|
2389
|
+
for (let i = 0; i < path.length - 2; i++) {
|
|
2390
|
+
node = path[i];
|
|
2391
|
+
if (!handleNode()) break;
|
|
2392
|
+
if (node._$host) {
|
|
2393
|
+
node = node._$host;
|
|
2394
|
+
walkUpTree();
|
|
2395
|
+
break;
|
|
2396
|
+
}
|
|
2397
|
+
if (node.parentNode === oriCurrentTarget) {
|
|
2398
|
+
break;
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
} else {
|
|
2402
|
+
walkUpTree();
|
|
2403
|
+
}
|
|
2404
|
+
retarget(oriTarget);
|
|
2405
|
+
}
|
|
2406
|
+
function addEventListener(node, name, handler, delegate) {
|
|
2407
|
+
if (handler == null) return;
|
|
2408
|
+
if (delegate) {
|
|
2409
|
+
if (Array.isArray(handler)) {
|
|
2410
|
+
;
|
|
2411
|
+
node[`$$${name}`] = handler[0];
|
|
2412
|
+
node[`$$${name}Data`] = handler[1];
|
|
2413
|
+
} else {
|
|
2414
|
+
;
|
|
2415
|
+
node[`$$${name}`] = handler;
|
|
2416
|
+
}
|
|
2417
|
+
} else if (Array.isArray(handler)) {
|
|
2418
|
+
const handlerFn = handler[0];
|
|
2419
|
+
node.addEventListener(name, (e) => handlerFn.call(node, handler[1], e));
|
|
2420
|
+
} else {
|
|
2421
|
+
node.addEventListener(name, handler);
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
function bindEvent(el, eventName, handler, options2) {
|
|
2425
|
+
if (handler == null) return () => {
|
|
2426
|
+
};
|
|
2427
|
+
const rootRef = getCurrentRoot();
|
|
2428
|
+
if (DelegatedEvents.has(eventName) && !options2) {
|
|
2429
|
+
const key = `$$${eventName}`;
|
|
2430
|
+
delegateEvents([eventName]);
|
|
2431
|
+
const createWrapped = (resolve) => {
|
|
2432
|
+
const wrapped2 = function(...args) {
|
|
2433
|
+
try {
|
|
2434
|
+
const fn = resolve();
|
|
2435
|
+
if (typeof fn === "function") {
|
|
2436
|
+
return fn.apply(this, args);
|
|
2437
|
+
} else if (fn && typeof fn.handleEvent === "function") {
|
|
2438
|
+
return fn.handleEvent.apply(fn, args);
|
|
2439
|
+
}
|
|
2440
|
+
} catch (err) {
|
|
2441
|
+
handleError(err, { source: "event", eventName }, rootRef);
|
|
2442
|
+
}
|
|
2443
|
+
};
|
|
2444
|
+
return wrapped2;
|
|
2445
|
+
};
|
|
2446
|
+
const resolveHandler = isReactive(handler) ? handler : () => handler;
|
|
2447
|
+
el[key] = createWrapped(resolveHandler);
|
|
2448
|
+
return () => {
|
|
2449
|
+
el[key] = void 0;
|
|
2450
|
+
};
|
|
2451
|
+
}
|
|
2452
|
+
const getHandler = isReactive(handler) ? handler : () => handler;
|
|
2453
|
+
const wrapped = (event) => {
|
|
2454
|
+
try {
|
|
2455
|
+
const resolved = getHandler();
|
|
2456
|
+
if (typeof resolved === "function") {
|
|
2457
|
+
;
|
|
2458
|
+
resolved(event);
|
|
2459
|
+
} else if (resolved && typeof resolved.handleEvent === "function") {
|
|
2460
|
+
;
|
|
2461
|
+
resolved.handleEvent(event);
|
|
2462
|
+
}
|
|
2463
|
+
} catch (err) {
|
|
2464
|
+
if (handleError(err, { source: "event", eventName }, rootRef)) {
|
|
2465
|
+
return;
|
|
2466
|
+
}
|
|
2467
|
+
throw err;
|
|
2468
|
+
}
|
|
2469
|
+
};
|
|
2470
|
+
el.addEventListener(eventName, wrapped, options2);
|
|
2471
|
+
const cleanup = () => el.removeEventListener(eventName, wrapped, options2);
|
|
2472
|
+
registerRootCleanup(cleanup);
|
|
2473
|
+
return cleanup;
|
|
2474
|
+
}
|
|
2475
|
+
function bindRef(el, ref) {
|
|
2476
|
+
if (ref == null) return () => {
|
|
2477
|
+
};
|
|
2478
|
+
const getRef = isReactive(ref) ? ref : () => ref;
|
|
2479
|
+
const applyRef2 = (refValue) => {
|
|
2480
|
+
if (refValue == null) return;
|
|
2481
|
+
if (typeof refValue === "function") {
|
|
2482
|
+
;
|
|
2483
|
+
refValue(el);
|
|
2484
|
+
} else if (typeof refValue === "object" && "current" in refValue) {
|
|
2485
|
+
;
|
|
2486
|
+
refValue.current = el;
|
|
2487
|
+
}
|
|
2488
|
+
};
|
|
2489
|
+
const initialRef = getRef();
|
|
2490
|
+
applyRef2(initialRef);
|
|
2491
|
+
if (isReactive(ref)) {
|
|
2492
|
+
const cleanup2 = createRenderEffect(() => {
|
|
2493
|
+
const currentRef = getRef();
|
|
2494
|
+
applyRef2(currentRef);
|
|
2495
|
+
});
|
|
2496
|
+
registerRootCleanup(cleanup2);
|
|
2497
|
+
const nullifyCleanup = () => {
|
|
2498
|
+
const currentRef = getRef();
|
|
2499
|
+
if (currentRef && typeof currentRef === "object" && "current" in currentRef) {
|
|
2500
|
+
;
|
|
2501
|
+
currentRef.current = null;
|
|
2502
|
+
}
|
|
2503
|
+
};
|
|
2504
|
+
registerRootCleanup(nullifyCleanup);
|
|
2505
|
+
return () => {
|
|
2506
|
+
cleanup2();
|
|
2507
|
+
nullifyCleanup();
|
|
2508
|
+
};
|
|
2509
|
+
}
|
|
2510
|
+
const cleanup = () => {
|
|
2511
|
+
const refValue = getRef();
|
|
2512
|
+
if (refValue && typeof refValue === "object" && "current" in refValue) {
|
|
2513
|
+
;
|
|
2514
|
+
refValue.current = null;
|
|
2515
|
+
}
|
|
2516
|
+
};
|
|
2517
|
+
registerRootCleanup(cleanup);
|
|
2518
|
+
return cleanup;
|
|
2519
|
+
}
|
|
2520
|
+
function spread(node, props = {}, isSVG = false, skipChildren = false) {
|
|
2521
|
+
const prevProps = {};
|
|
2522
|
+
if (!skipChildren && "children" in props) {
|
|
2523
|
+
createRenderEffect(() => {
|
|
2524
|
+
prevProps.children = props.children;
|
|
2525
|
+
});
|
|
2526
|
+
}
|
|
2527
|
+
createRenderEffect(() => {
|
|
2528
|
+
if (typeof props.ref === "function") {
|
|
2529
|
+
;
|
|
2530
|
+
props.ref(node);
|
|
2531
|
+
}
|
|
2532
|
+
});
|
|
2533
|
+
createRenderEffect(() => {
|
|
2534
|
+
assign(node, props, isSVG, true, prevProps, true);
|
|
2535
|
+
});
|
|
2536
|
+
return prevProps;
|
|
2537
|
+
}
|
|
2538
|
+
function assign(node, props, isSVG = false, skipChildren = false, prevProps = {}, skipRef = false) {
|
|
2539
|
+
props = props || {};
|
|
2540
|
+
for (const prop in prevProps) {
|
|
2541
|
+
if (!(prop in props)) {
|
|
2542
|
+
if (prop === "children") continue;
|
|
2543
|
+
prevProps[prop] = assignProp(node, prop, null, prevProps[prop], isSVG, skipRef, props);
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
for (const prop in props) {
|
|
2547
|
+
if (prop === "children") {
|
|
2548
|
+
if (!skipChildren) {
|
|
2549
|
+
prevProps.children = props.children;
|
|
2550
|
+
}
|
|
2551
|
+
continue;
|
|
2552
|
+
}
|
|
2553
|
+
const value = props[prop];
|
|
2554
|
+
prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG, skipRef, props);
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
function assignProp(node, prop, value, prev, isSVG, skipRef, props) {
|
|
2558
|
+
if (prop === "style") {
|
|
2559
|
+
applyStyle(node, value, prev);
|
|
2560
|
+
return value;
|
|
2561
|
+
}
|
|
2562
|
+
if (prop === "classList") {
|
|
2563
|
+
return applyClass(node, value, prev);
|
|
2564
|
+
}
|
|
2565
|
+
if (value === prev) return prev;
|
|
2566
|
+
if (prop === "ref") {
|
|
2567
|
+
if (!skipRef && typeof value === "function") {
|
|
2568
|
+
;
|
|
2569
|
+
value(node);
|
|
2570
|
+
}
|
|
2571
|
+
return value;
|
|
2572
|
+
}
|
|
2573
|
+
if (prop.slice(0, 3) === "on:") {
|
|
2574
|
+
const eventName = prop.slice(3);
|
|
2575
|
+
if (prev) node.removeEventListener(eventName, prev);
|
|
2576
|
+
if (value) node.addEventListener(eventName, value);
|
|
2577
|
+
return value;
|
|
2578
|
+
}
|
|
2579
|
+
if (prop.slice(0, 10) === "oncapture:") {
|
|
2580
|
+
const eventName = prop.slice(10);
|
|
2581
|
+
if (prev) node.removeEventListener(eventName, prev, true);
|
|
2582
|
+
if (value) node.addEventListener(eventName, value, true);
|
|
2583
|
+
return value;
|
|
2584
|
+
}
|
|
2585
|
+
if (prop.slice(0, 2) === "on") {
|
|
2586
|
+
const eventName = prop.slice(2).toLowerCase();
|
|
2587
|
+
const shouldDelegate = DelegatedEvents.has(eventName);
|
|
2588
|
+
if (!shouldDelegate && prev) {
|
|
2589
|
+
const handler = Array.isArray(prev) ? prev[0] : prev;
|
|
2590
|
+
node.removeEventListener(eventName, handler);
|
|
2591
|
+
}
|
|
2592
|
+
if (shouldDelegate || value) {
|
|
2593
|
+
addEventListener(node, eventName, value, shouldDelegate);
|
|
2594
|
+
if (shouldDelegate) delegateEvents([eventName]);
|
|
2595
|
+
}
|
|
2596
|
+
return value;
|
|
2597
|
+
}
|
|
2598
|
+
if (prop.slice(0, 5) === "attr:") {
|
|
2599
|
+
if (value == null) node.removeAttribute(prop.slice(5));
|
|
2600
|
+
else node.setAttribute(prop.slice(5), String(value));
|
|
2601
|
+
return value;
|
|
2602
|
+
}
|
|
2603
|
+
if (prop.slice(0, 5) === "bool:") {
|
|
2604
|
+
if (value) node.setAttribute(prop.slice(5), "");
|
|
2605
|
+
else node.removeAttribute(prop.slice(5));
|
|
2606
|
+
return value;
|
|
2607
|
+
}
|
|
2608
|
+
if (prop.slice(0, 5) === "prop:") {
|
|
2609
|
+
;
|
|
2610
|
+
node[prop.slice(5)] = value;
|
|
2611
|
+
return value;
|
|
2612
|
+
}
|
|
2613
|
+
if (prop === "class" || prop === "className") {
|
|
2614
|
+
if (value == null) node.removeAttribute("class");
|
|
2615
|
+
else node.className = String(value);
|
|
2616
|
+
return value;
|
|
2617
|
+
}
|
|
2618
|
+
const isCE = node.nodeName.includes("-") || "is" in props;
|
|
2619
|
+
if (!isSVG) {
|
|
2620
|
+
const propAlias = getPropAlias(prop, node.tagName);
|
|
2621
|
+
const isProperty = Properties.has(prop);
|
|
2622
|
+
const isChildProp = ChildProperties.has(prop);
|
|
2623
|
+
if (propAlias || isProperty || isChildProp || isCE) {
|
|
2624
|
+
const propName = propAlias || prop;
|
|
2625
|
+
if (isCE && !isProperty && !isChildProp) {
|
|
2626
|
+
;
|
|
2627
|
+
node[toPropertyName(propName)] = value;
|
|
2628
|
+
} else {
|
|
2629
|
+
;
|
|
2630
|
+
node[propName] = value;
|
|
2631
|
+
}
|
|
2632
|
+
return value;
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
if (isSVG && prop.indexOf(":") > -1) {
|
|
2636
|
+
const [prefix, name] = prop.split(":");
|
|
2637
|
+
const ns = SVGNamespace[prefix];
|
|
2638
|
+
if (ns) {
|
|
2639
|
+
if (value == null) node.removeAttributeNS(ns, name);
|
|
2640
|
+
else node.setAttributeNS(ns, name, String(value));
|
|
2641
|
+
return value;
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
const attrName = Aliases[prop] || prop;
|
|
2645
|
+
if (value == null) node.removeAttribute(attrName);
|
|
2646
|
+
else node.setAttribute(attrName, String(value));
|
|
2647
|
+
return value;
|
|
2648
|
+
}
|
|
2649
|
+
function toPropertyName(name) {
|
|
2650
|
+
return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
|
|
2651
|
+
}
|
|
2652
|
+
function createConditional(condition, renderTrue, createElementFn, renderFalse) {
|
|
2653
|
+
const startMarker = document.createComment("fict:cond:start");
|
|
2654
|
+
const endMarker = document.createComment("fict:cond:end");
|
|
2655
|
+
const fragment = document.createDocumentFragment();
|
|
2656
|
+
fragment.append(startMarker, endMarker);
|
|
2657
|
+
let currentNodes = [];
|
|
2658
|
+
let currentRoot2 = null;
|
|
2659
|
+
let lastCondition = void 0;
|
|
2660
|
+
let pendingRender = false;
|
|
2661
|
+
const conditionMemo = computed(condition);
|
|
2662
|
+
const runConditional = () => {
|
|
2663
|
+
const cond = conditionMemo();
|
|
2664
|
+
const parent = startMarker.parentNode;
|
|
2665
|
+
if (!parent) {
|
|
2666
|
+
pendingRender = true;
|
|
2667
|
+
return;
|
|
2668
|
+
}
|
|
2669
|
+
pendingRender = false;
|
|
2670
|
+
if (lastCondition === cond && currentNodes.length > 0) {
|
|
2671
|
+
return;
|
|
2672
|
+
}
|
|
2673
|
+
if (lastCondition === cond && lastCondition === false && renderFalse === void 0) {
|
|
2674
|
+
return;
|
|
2675
|
+
}
|
|
2676
|
+
lastCondition = cond;
|
|
2677
|
+
if (currentRoot2) {
|
|
2678
|
+
destroyRoot(currentRoot2);
|
|
2679
|
+
currentRoot2 = null;
|
|
2680
|
+
}
|
|
2681
|
+
removeNodes(currentNodes);
|
|
2682
|
+
currentNodes = [];
|
|
2683
|
+
const render2 = cond ? renderTrue : renderFalse;
|
|
2684
|
+
if (!render2) {
|
|
2685
|
+
return;
|
|
2686
|
+
}
|
|
2687
|
+
const root = createRootContext();
|
|
2688
|
+
const prev = pushRoot(root);
|
|
2689
|
+
let handledError = false;
|
|
2690
|
+
try {
|
|
2691
|
+
const output = untrack(render2);
|
|
2692
|
+
if (output == null || output === false) {
|
|
2693
|
+
return;
|
|
2694
|
+
}
|
|
2695
|
+
const el = createElementFn(output);
|
|
2696
|
+
const nodes = toNodeArray(el);
|
|
2697
|
+
insertNodesBefore(parent, nodes, endMarker);
|
|
2698
|
+
currentNodes = nodes;
|
|
2699
|
+
} catch (err) {
|
|
2700
|
+
if (handleSuspend(err, root)) {
|
|
2701
|
+
handledError = true;
|
|
2702
|
+
destroyRoot(root);
|
|
2703
|
+
return;
|
|
2704
|
+
}
|
|
2705
|
+
if (handleError(err, { source: "renderChild" }, root)) {
|
|
2706
|
+
handledError = true;
|
|
2707
|
+
destroyRoot(root);
|
|
2708
|
+
return;
|
|
2709
|
+
}
|
|
2710
|
+
throw err;
|
|
2711
|
+
} finally {
|
|
2712
|
+
popRoot(prev);
|
|
2713
|
+
if (!handledError) {
|
|
2714
|
+
flushOnMount(root);
|
|
2715
|
+
currentRoot2 = root;
|
|
2716
|
+
} else {
|
|
2717
|
+
currentRoot2 = null;
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
};
|
|
2721
|
+
const dispose = createRenderEffect(runConditional);
|
|
2722
|
+
return {
|
|
2723
|
+
marker: fragment,
|
|
2724
|
+
flush: () => {
|
|
2725
|
+
if (pendingRender) {
|
|
2726
|
+
runConditional();
|
|
2727
|
+
}
|
|
2728
|
+
},
|
|
2729
|
+
dispose: () => {
|
|
2730
|
+
dispose();
|
|
2731
|
+
if (currentRoot2) {
|
|
2732
|
+
destroyRoot(currentRoot2);
|
|
2733
|
+
}
|
|
2734
|
+
removeNodes(currentNodes);
|
|
2735
|
+
currentNodes = [];
|
|
2736
|
+
startMarker.parentNode?.removeChild(startMarker);
|
|
2737
|
+
endMarker.parentNode?.removeChild(endMarker);
|
|
2738
|
+
}
|
|
2739
|
+
};
|
|
2740
|
+
}
|
|
2741
|
+
function createList(items, renderItem, createElementFn, getKey) {
|
|
2742
|
+
const startMarker = document.createComment("fict:list:start");
|
|
2743
|
+
const endMarker = document.createComment("fict:list:end");
|
|
2744
|
+
const fragment = document.createDocumentFragment();
|
|
2745
|
+
fragment.append(startMarker, endMarker);
|
|
2746
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
2747
|
+
let pendingItems = null;
|
|
2748
|
+
const runListUpdate = () => {
|
|
2749
|
+
const arr = items();
|
|
2750
|
+
const parent = startMarker.parentNode;
|
|
2751
|
+
if (!parent) {
|
|
2752
|
+
pendingItems = arr;
|
|
2753
|
+
return;
|
|
2754
|
+
}
|
|
2755
|
+
pendingItems = null;
|
|
2756
|
+
const newNodeMap = /* @__PURE__ */ new Map();
|
|
2757
|
+
const blocks = [];
|
|
2758
|
+
for (let i = 0; i < arr.length; i++) {
|
|
2759
|
+
const item = arr[i];
|
|
2760
|
+
const key = getKey ? getKey(item, i) : i;
|
|
2761
|
+
const existing = nodeMap.get(key);
|
|
2762
|
+
let block;
|
|
2763
|
+
if (existing) {
|
|
2764
|
+
const previousValue = existing.value();
|
|
2765
|
+
if (!getKey && previousValue !== item) {
|
|
2766
|
+
destroyRoot(existing.root);
|
|
2767
|
+
removeBlockNodes(existing);
|
|
2768
|
+
block = mountBlock(item, i, renderItem, parent, endMarker, createElementFn);
|
|
2769
|
+
} else {
|
|
2770
|
+
const previousIndex = existing.index();
|
|
2771
|
+
existing.value(item);
|
|
2772
|
+
existing.index(i);
|
|
2773
|
+
if (previousValue === item) {
|
|
2774
|
+
bumpBlockVersion(existing);
|
|
2775
|
+
}
|
|
2776
|
+
const needsRerender = getKey ? true : previousValue !== item || previousIndex !== i;
|
|
2777
|
+
block = needsRerender ? rerenderBlock(existing, createElementFn) : existing;
|
|
2778
|
+
}
|
|
2779
|
+
} else {
|
|
2780
|
+
block = mountBlock(item, i, renderItem, parent, endMarker, createElementFn);
|
|
2781
|
+
}
|
|
2782
|
+
newNodeMap.set(key, block);
|
|
2783
|
+
blocks.push(block);
|
|
2784
|
+
}
|
|
2785
|
+
for (const [key, managed] of nodeMap) {
|
|
2786
|
+
if (!newNodeMap.has(key)) {
|
|
2787
|
+
destroyRoot(managed.root);
|
|
2788
|
+
removeBlockNodes(managed);
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
let anchor = endMarker;
|
|
2792
|
+
for (let i = blocks.length - 1; i >= 0; i--) {
|
|
2793
|
+
const block = blocks[i];
|
|
2794
|
+
insertNodesBefore(parent, block.nodes, anchor);
|
|
2795
|
+
if (block.nodes.length > 0) {
|
|
2796
|
+
anchor = block.nodes[0];
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
nodeMap.clear();
|
|
2800
|
+
for (const [k, v] of newNodeMap) {
|
|
2801
|
+
nodeMap.set(k, v);
|
|
2802
|
+
}
|
|
2803
|
+
};
|
|
2804
|
+
const dispose = createRenderEffect(runListUpdate);
|
|
2805
|
+
return {
|
|
2806
|
+
marker: fragment,
|
|
2807
|
+
flush: () => {
|
|
2808
|
+
if (pendingItems !== null) {
|
|
2809
|
+
runListUpdate();
|
|
2810
|
+
}
|
|
2811
|
+
},
|
|
2812
|
+
dispose: () => {
|
|
2813
|
+
dispose();
|
|
2814
|
+
for (const [, managed] of nodeMap) {
|
|
2815
|
+
destroyRoot(managed.root);
|
|
2816
|
+
removeBlockNodes(managed);
|
|
2817
|
+
}
|
|
2818
|
+
nodeMap.clear();
|
|
2819
|
+
startMarker.parentNode?.removeChild(startMarker);
|
|
2820
|
+
endMarker.parentNode?.removeChild(endMarker);
|
|
2821
|
+
}
|
|
2822
|
+
};
|
|
2823
|
+
}
|
|
2824
|
+
function createShow(el, condition, displayValue) {
|
|
2825
|
+
const originalDisplay = displayValue ?? el.style.display;
|
|
2826
|
+
createRenderEffect(() => {
|
|
2827
|
+
el.style.display = condition() ? originalDisplay : "none";
|
|
2828
|
+
});
|
|
2829
|
+
}
|
|
2830
|
+
function createPortal(container, render2, createElementFn) {
|
|
2831
|
+
const parentRoot = getCurrentRoot();
|
|
2832
|
+
const marker = document.createComment("fict:portal");
|
|
2833
|
+
container.appendChild(marker);
|
|
2834
|
+
let currentNodes = [];
|
|
2835
|
+
let currentRoot2 = null;
|
|
2836
|
+
const dispose = createRenderEffect(() => {
|
|
2837
|
+
if (currentRoot2) {
|
|
2838
|
+
destroyRoot(currentRoot2);
|
|
2839
|
+
currentRoot2 = null;
|
|
2840
|
+
}
|
|
2841
|
+
if (currentNodes.length > 0) {
|
|
2842
|
+
removeNodes(currentNodes);
|
|
2843
|
+
currentNodes = [];
|
|
2844
|
+
}
|
|
2845
|
+
const root = createRootContext();
|
|
2846
|
+
const prev = pushRoot(root);
|
|
2847
|
+
let handledError = false;
|
|
2848
|
+
try {
|
|
2849
|
+
const output = render2();
|
|
2850
|
+
if (output != null && output !== false) {
|
|
2851
|
+
const el = createElementFn(output);
|
|
2852
|
+
const nodes = toNodeArray(el);
|
|
2853
|
+
if (marker.parentNode) {
|
|
2854
|
+
insertNodesBefore(marker.parentNode, nodes, marker);
|
|
2855
|
+
}
|
|
2856
|
+
currentNodes = nodes;
|
|
2857
|
+
}
|
|
2858
|
+
} catch (err) {
|
|
2859
|
+
if (handleSuspend(err, root)) {
|
|
2860
|
+
handledError = true;
|
|
2861
|
+
destroyRoot(root);
|
|
2862
|
+
currentNodes = [];
|
|
2863
|
+
return;
|
|
2864
|
+
}
|
|
2865
|
+
if (handleError(err, { source: "renderChild" }, root)) {
|
|
2866
|
+
handledError = true;
|
|
2867
|
+
destroyRoot(root);
|
|
2868
|
+
currentNodes = [];
|
|
2869
|
+
return;
|
|
2870
|
+
}
|
|
2871
|
+
throw err;
|
|
2872
|
+
} finally {
|
|
2873
|
+
popRoot(prev);
|
|
2874
|
+
if (!handledError) {
|
|
2875
|
+
flushOnMount(root);
|
|
2876
|
+
currentRoot2 = root;
|
|
2877
|
+
} else {
|
|
2878
|
+
currentRoot2 = null;
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
});
|
|
2882
|
+
const portalDispose = () => {
|
|
2883
|
+
dispose();
|
|
2884
|
+
if (currentRoot2) {
|
|
2885
|
+
destroyRoot(currentRoot2);
|
|
2886
|
+
}
|
|
2887
|
+
if (currentNodes.length > 0) {
|
|
2888
|
+
removeNodes(currentNodes);
|
|
2889
|
+
}
|
|
2890
|
+
marker.parentNode?.removeChild(marker);
|
|
2891
|
+
};
|
|
2892
|
+
if (parentRoot) {
|
|
2893
|
+
parentRoot.destroyCallbacks.push(portalDispose);
|
|
2894
|
+
}
|
|
2895
|
+
return {
|
|
2896
|
+
marker,
|
|
2897
|
+
dispose: portalDispose
|
|
2898
|
+
};
|
|
2899
|
+
}
|
|
2900
|
+
function mountBlock(initialValue, initialIndex, renderItem, parent, anchor, createElementFn) {
|
|
2901
|
+
const start = document.createComment("fict:block:start");
|
|
2902
|
+
const end = document.createComment("fict:block:end");
|
|
2903
|
+
const valueSig = signal(initialValue);
|
|
2904
|
+
const indexSig = signal(initialIndex);
|
|
2905
|
+
const versionSig = signal(0);
|
|
2906
|
+
const valueProxy = createValueProxy(() => {
|
|
2907
|
+
versionSig();
|
|
2908
|
+
return valueSig();
|
|
2909
|
+
});
|
|
2910
|
+
const renderCurrent = () => renderItem(valueProxy, indexSig());
|
|
2911
|
+
const root = createRootContext();
|
|
2912
|
+
const prev = pushRoot(root);
|
|
2913
|
+
const nodes = [start];
|
|
2914
|
+
let handledError = false;
|
|
2915
|
+
try {
|
|
2916
|
+
const output = renderCurrent();
|
|
2917
|
+
if (output != null && output !== false) {
|
|
2918
|
+
const el = createElementFn(output);
|
|
2919
|
+
const rendered = toNodeArray(el);
|
|
2920
|
+
nodes.push(...rendered);
|
|
2921
|
+
}
|
|
2922
|
+
nodes.push(end);
|
|
2923
|
+
insertNodesBefore(parent, nodes, anchor);
|
|
2924
|
+
} catch (err) {
|
|
2925
|
+
if (handleSuspend(err, root)) {
|
|
2926
|
+
handledError = true;
|
|
2927
|
+
nodes.push(end);
|
|
2928
|
+
insertNodesBefore(parent, nodes, anchor);
|
|
2929
|
+
} else if (handleError(err, { source: "renderChild" }, root)) {
|
|
2930
|
+
handledError = true;
|
|
2931
|
+
nodes.push(end);
|
|
2932
|
+
insertNodesBefore(parent, nodes, anchor);
|
|
2933
|
+
} else {
|
|
2934
|
+
throw err;
|
|
2935
|
+
}
|
|
2936
|
+
} finally {
|
|
2937
|
+
popRoot(prev);
|
|
2938
|
+
if (!handledError) {
|
|
2939
|
+
flushOnMount(root);
|
|
2940
|
+
} else {
|
|
2941
|
+
destroyRoot(root);
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
return {
|
|
2945
|
+
nodes,
|
|
2946
|
+
root,
|
|
2947
|
+
value: valueSig,
|
|
2948
|
+
index: indexSig,
|
|
2949
|
+
version: versionSig,
|
|
2950
|
+
start,
|
|
2951
|
+
end,
|
|
2952
|
+
valueProxy,
|
|
2953
|
+
renderCurrent
|
|
2954
|
+
};
|
|
2955
|
+
}
|
|
2956
|
+
function rerenderBlock(block, createElementFn) {
|
|
2957
|
+
const currentContent = block.nodes.slice(1, Math.max(1, block.nodes.length - 1));
|
|
2958
|
+
const currentNode = currentContent.length === 1 ? currentContent[0] : null;
|
|
2959
|
+
clearRoot(block.root);
|
|
2960
|
+
const prev = pushRoot(block.root);
|
|
2961
|
+
let nextOutput;
|
|
2962
|
+
let handledError = false;
|
|
2963
|
+
try {
|
|
2964
|
+
nextOutput = block.renderCurrent();
|
|
2965
|
+
} catch (err) {
|
|
2966
|
+
if (handleSuspend(err, block.root)) {
|
|
2967
|
+
handledError = true;
|
|
2968
|
+
popRoot(prev);
|
|
2969
|
+
destroyRoot(block.root);
|
|
2970
|
+
block.nodes = [block.start, block.end];
|
|
2971
|
+
return block;
|
|
2972
|
+
}
|
|
2973
|
+
if (handleError(err, { source: "renderChild" }, block.root)) {
|
|
2974
|
+
handledError = true;
|
|
2975
|
+
popRoot(prev);
|
|
2976
|
+
destroyRoot(block.root);
|
|
2977
|
+
block.nodes = [block.start, block.end];
|
|
2978
|
+
return block;
|
|
2979
|
+
}
|
|
2980
|
+
throw err;
|
|
2981
|
+
} finally {
|
|
2982
|
+
if (!handledError) {
|
|
2983
|
+
popRoot(prev);
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
if (isFragmentVNode(nextOutput) && currentContent.length > 0) {
|
|
2987
|
+
const patched = patchFragmentChildren(currentContent, nextOutput.props?.children);
|
|
2988
|
+
if (patched) {
|
|
2989
|
+
block.nodes = [block.start, ...currentContent, block.end];
|
|
2990
|
+
return block;
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
if (currentNode && patchNode(currentNode, nextOutput)) {
|
|
2994
|
+
block.nodes = [block.start, currentNode, block.end];
|
|
2995
|
+
return block;
|
|
2996
|
+
}
|
|
2997
|
+
clearContent(block);
|
|
2998
|
+
if (nextOutput != null && nextOutput !== false) {
|
|
2999
|
+
const newNodes = toNodeArray(
|
|
3000
|
+
nextOutput instanceof Node ? nextOutput : createElementFn(nextOutput)
|
|
3001
|
+
);
|
|
3002
|
+
insertNodesBefore(block.start.parentNode, newNodes, block.end);
|
|
3003
|
+
block.nodes = [block.start, ...newNodes, block.end];
|
|
3004
|
+
} else {
|
|
3005
|
+
block.nodes = [block.start, block.end];
|
|
3006
|
+
}
|
|
3007
|
+
return block;
|
|
3008
|
+
}
|
|
3009
|
+
function patchElement(el, output) {
|
|
3010
|
+
if (output === null || output === void 0 || output === false || typeof output === "string" || typeof output === "number") {
|
|
3011
|
+
el.textContent = output === null || output === void 0 || output === false ? "" : String(output);
|
|
3012
|
+
return true;
|
|
3013
|
+
}
|
|
3014
|
+
if (output instanceof Text) {
|
|
3015
|
+
el.textContent = output.data;
|
|
3016
|
+
return true;
|
|
3017
|
+
}
|
|
3018
|
+
if (output && typeof output === "object" && !(output instanceof Node)) {
|
|
3019
|
+
const vnode = output;
|
|
3020
|
+
if (typeof vnode.type === "string" && vnode.type.toLowerCase() === el.tagName.toLowerCase()) {
|
|
3021
|
+
const children = vnode.props?.children;
|
|
3022
|
+
const props = vnode.props ?? {};
|
|
3023
|
+
for (const [key, value] of Object.entries(props)) {
|
|
3024
|
+
if (key === "children" || key === "key") continue;
|
|
3025
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null || value === void 0) {
|
|
3026
|
+
if (key === "class" || key === "className") {
|
|
3027
|
+
el.setAttribute("class", value === false || value === null ? "" : String(value));
|
|
3028
|
+
} else if (key === "style" && typeof value === "string") {
|
|
3029
|
+
;
|
|
3030
|
+
el.style.cssText = value;
|
|
3031
|
+
} else if (value === false || value === null || value === void 0) {
|
|
3032
|
+
el.removeAttribute(key);
|
|
3033
|
+
} else if (value === true) {
|
|
3034
|
+
el.setAttribute(key, "");
|
|
3035
|
+
} else {
|
|
3036
|
+
el.setAttribute(key, String(value));
|
|
3037
|
+
}
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
if (typeof children === "string" || typeof children === "number" || children === null || children === void 0 || children === false) {
|
|
3041
|
+
el.textContent = children === null || children === void 0 || children === false ? "" : String(children);
|
|
3042
|
+
return true;
|
|
3043
|
+
}
|
|
3044
|
+
if (children && typeof children === "object" && !Array.isArray(children) && !(children instanceof Node)) {
|
|
3045
|
+
const childVNode = children;
|
|
3046
|
+
if (typeof childVNode.type === "string") {
|
|
3047
|
+
const childEl = el.querySelector(childVNode.type);
|
|
3048
|
+
if (childEl && patchElement(childEl, children)) {
|
|
3049
|
+
return true;
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
return false;
|
|
3054
|
+
}
|
|
3055
|
+
}
|
|
3056
|
+
if (output instanceof Node) {
|
|
3057
|
+
if (output.nodeType === Node.ELEMENT_NODE) {
|
|
3058
|
+
const nextEl = output;
|
|
3059
|
+
if (nextEl.tagName.toLowerCase() === el.tagName.toLowerCase()) {
|
|
3060
|
+
el.textContent = nextEl.textContent;
|
|
3061
|
+
return true;
|
|
3062
|
+
}
|
|
3063
|
+
} else if (output.nodeType === Node.TEXT_NODE) {
|
|
3064
|
+
el.textContent = output.data;
|
|
3065
|
+
return true;
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
return false;
|
|
3069
|
+
}
|
|
3070
|
+
function patchNode(currentNode, nextOutput) {
|
|
3071
|
+
if (!currentNode) return false;
|
|
3072
|
+
if (currentNode instanceof Text && (nextOutput === null || nextOutput === void 0 || nextOutput === false || typeof nextOutput === "string" || typeof nextOutput === "number" || nextOutput instanceof Text)) {
|
|
3073
|
+
const nextText = nextOutput instanceof Text ? nextOutput.data : nextOutput === null || nextOutput === void 0 || nextOutput === false ? "" : String(nextOutput);
|
|
3074
|
+
currentNode.data = nextText;
|
|
3075
|
+
return true;
|
|
3076
|
+
}
|
|
3077
|
+
if (currentNode instanceof Element && patchElement(currentNode, nextOutput)) {
|
|
3078
|
+
return true;
|
|
3079
|
+
}
|
|
3080
|
+
if (nextOutput instanceof Node && currentNode === nextOutput) {
|
|
3081
|
+
return true;
|
|
3082
|
+
}
|
|
3083
|
+
return false;
|
|
3084
|
+
}
|
|
3085
|
+
function isFragmentVNode(value) {
|
|
3086
|
+
return value != null && typeof value === "object" && !(value instanceof Node) && value.type === Fragment;
|
|
3087
|
+
}
|
|
3088
|
+
function normalizeChildren(children, result = []) {
|
|
3089
|
+
if (children === void 0) {
|
|
3090
|
+
return result;
|
|
3091
|
+
}
|
|
3092
|
+
if (Array.isArray(children)) {
|
|
3093
|
+
for (const child of children) {
|
|
3094
|
+
normalizeChildren(child, result);
|
|
3095
|
+
}
|
|
3096
|
+
return result;
|
|
3097
|
+
}
|
|
3098
|
+
if (children === null || children === false) {
|
|
3099
|
+
return result;
|
|
3100
|
+
}
|
|
3101
|
+
result.push(children);
|
|
3102
|
+
return result;
|
|
3103
|
+
}
|
|
3104
|
+
function patchFragmentChildren(nodes, children) {
|
|
3105
|
+
const normalized = normalizeChildren(children);
|
|
3106
|
+
if (normalized.length !== nodes.length) {
|
|
3107
|
+
return false;
|
|
3108
|
+
}
|
|
3109
|
+
for (let i = 0; i < normalized.length; i++) {
|
|
3110
|
+
if (!patchNode(nodes[i], normalized[i])) {
|
|
3111
|
+
return false;
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
return true;
|
|
3115
|
+
}
|
|
3116
|
+
function clearContent(block) {
|
|
3117
|
+
const nodes = block.nodes.slice(1, Math.max(1, block.nodes.length - 1));
|
|
3118
|
+
removeNodes(nodes);
|
|
3119
|
+
}
|
|
3120
|
+
function removeBlockNodes(block) {
|
|
3121
|
+
let cursor = block.start;
|
|
3122
|
+
const end = block.end;
|
|
3123
|
+
while (cursor) {
|
|
3124
|
+
const next = cursor.nextSibling;
|
|
3125
|
+
cursor.parentNode?.removeChild(cursor);
|
|
3126
|
+
if (cursor === end) break;
|
|
3127
|
+
cursor = next;
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
function bumpBlockVersion(block) {
|
|
3131
|
+
block.version(block.version() + 1);
|
|
3132
|
+
}
|
|
3133
|
+
|
|
3134
|
+
// src/dom.ts
|
|
3135
|
+
function render(view, container) {
|
|
3136
|
+
const root = createRootContext();
|
|
3137
|
+
const prev = pushRoot(root);
|
|
3138
|
+
let dom;
|
|
3139
|
+
try {
|
|
3140
|
+
const output = view();
|
|
3141
|
+
dom = createElement(output);
|
|
3142
|
+
} finally {
|
|
3143
|
+
popRoot(prev);
|
|
3144
|
+
}
|
|
3145
|
+
container.replaceChildren(dom);
|
|
3146
|
+
container.setAttribute("data-fict-fine-grained", "1");
|
|
3147
|
+
flushOnMount(root);
|
|
3148
|
+
const teardown = () => {
|
|
3149
|
+
destroyRoot(root);
|
|
3150
|
+
container.innerHTML = "";
|
|
3151
|
+
};
|
|
3152
|
+
return teardown;
|
|
3153
|
+
}
|
|
3154
|
+
function createElement(node) {
|
|
3155
|
+
if (node instanceof Node) {
|
|
3156
|
+
return node;
|
|
3157
|
+
}
|
|
3158
|
+
if (node === null || node === void 0 || node === false) {
|
|
3159
|
+
return document.createTextNode("");
|
|
3160
|
+
}
|
|
3161
|
+
if (typeof node === "object" && node !== null && !(node instanceof Node)) {
|
|
3162
|
+
if ("marker" in node) {
|
|
3163
|
+
return createElement(node.marker);
|
|
3164
|
+
}
|
|
3165
|
+
const nodeRecord = node;
|
|
3166
|
+
if (nodeRecord[PRIMITIVE_PROXY]) {
|
|
3167
|
+
const primitiveGetter = nodeRecord[Symbol.toPrimitive];
|
|
3168
|
+
const value = typeof primitiveGetter === "function" ? primitiveGetter.call(node, "default") : node;
|
|
3169
|
+
return document.createTextNode(value == null || value === false ? "" : String(value));
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
if (Array.isArray(node)) {
|
|
3173
|
+
const frag = document.createDocumentFragment();
|
|
3174
|
+
for (const child of node) {
|
|
3175
|
+
appendChildNode(frag, child);
|
|
3176
|
+
}
|
|
3177
|
+
return frag;
|
|
3178
|
+
}
|
|
3179
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
3180
|
+
return document.createTextNode(String(node));
|
|
3181
|
+
}
|
|
3182
|
+
if (typeof node === "boolean") {
|
|
3183
|
+
return document.createTextNode("");
|
|
3184
|
+
}
|
|
3185
|
+
const vnode = node;
|
|
3186
|
+
if (typeof vnode.type === "function") {
|
|
3187
|
+
const rawProps = unwrapProps(vnode.props ?? {});
|
|
3188
|
+
const baseProps = vnode.key === void 0 ? rawProps : new Proxy(rawProps, {
|
|
3189
|
+
get(target, prop, receiver) {
|
|
3190
|
+
if (prop === "key") return vnode.key;
|
|
3191
|
+
return Reflect.get(target, prop, receiver);
|
|
3192
|
+
},
|
|
3193
|
+
has(target, prop) {
|
|
3194
|
+
if (prop === "key") return true;
|
|
3195
|
+
return prop in target;
|
|
3196
|
+
},
|
|
3197
|
+
ownKeys(target) {
|
|
3198
|
+
const keys = new Set(Reflect.ownKeys(target));
|
|
3199
|
+
keys.add("key");
|
|
3200
|
+
return Array.from(keys);
|
|
3201
|
+
},
|
|
3202
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
3203
|
+
if (prop === "key") {
|
|
3204
|
+
return { enumerable: true, configurable: true, value: vnode.key };
|
|
3205
|
+
}
|
|
3206
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
3207
|
+
}
|
|
3208
|
+
});
|
|
3209
|
+
const props = createPropsProxy(baseProps);
|
|
3210
|
+
try {
|
|
3211
|
+
__fictPushContext();
|
|
3212
|
+
const rendered = vnode.type(props);
|
|
3213
|
+
__fictPopContext();
|
|
3214
|
+
return createElement(rendered);
|
|
3215
|
+
} catch (err) {
|
|
3216
|
+
__fictPopContext();
|
|
3217
|
+
if (handleSuspend(err)) {
|
|
3218
|
+
return document.createComment("fict:suspend");
|
|
3219
|
+
}
|
|
3220
|
+
handleError(err, { source: "render", componentName: vnode.type.name });
|
|
3221
|
+
throw err;
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
if (vnode.type === Fragment) {
|
|
3225
|
+
const frag = document.createDocumentFragment();
|
|
3226
|
+
const children = vnode.props?.children;
|
|
3227
|
+
appendChildren(frag, children);
|
|
3228
|
+
return frag;
|
|
3229
|
+
}
|
|
3230
|
+
const tagName = typeof vnode.type === "string" ? vnode.type : "div";
|
|
3231
|
+
const el = document.createElement(tagName);
|
|
3232
|
+
applyProps(el, vnode.props ?? {});
|
|
3233
|
+
return el;
|
|
3234
|
+
}
|
|
3235
|
+
function template(html, isImportNode, isSVG, isMathML) {
|
|
3236
|
+
let node = null;
|
|
3237
|
+
const create = () => {
|
|
3238
|
+
const t = isMathML ? document.createElementNS("http://www.w3.org/1998/Math/MathML", "template") : document.createElement("template");
|
|
3239
|
+
t.innerHTML = html;
|
|
3240
|
+
if (isSVG) {
|
|
3241
|
+
return t.content.firstChild.firstChild;
|
|
3242
|
+
}
|
|
3243
|
+
if (isMathML) {
|
|
3244
|
+
return t.firstChild;
|
|
3245
|
+
}
|
|
3246
|
+
return t.content.firstChild;
|
|
3247
|
+
};
|
|
3248
|
+
const fn = isImportNode ? () => untrack2(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true);
|
|
3249
|
+
fn.cloneNode = fn;
|
|
3250
|
+
return fn;
|
|
3251
|
+
}
|
|
3252
|
+
function isBindingHandle(node) {
|
|
3253
|
+
return node !== null && typeof node === "object" && "marker" in node && "dispose" in node && typeof node.dispose === "function";
|
|
3254
|
+
}
|
|
3255
|
+
function appendChildNode(parent, child) {
|
|
3256
|
+
if (child === null || child === void 0 || child === false) {
|
|
3257
|
+
return;
|
|
3258
|
+
}
|
|
3259
|
+
if (isBindingHandle(child)) {
|
|
3260
|
+
appendChildNode(parent, child.marker);
|
|
3261
|
+
child.flush?.();
|
|
3262
|
+
return;
|
|
3263
|
+
}
|
|
3264
|
+
if (typeof child === "function" && child.length === 0) {
|
|
3265
|
+
const childGetter = child;
|
|
3266
|
+
createChildBinding(parent, childGetter, createElement);
|
|
3267
|
+
return;
|
|
3268
|
+
}
|
|
3269
|
+
if (Array.isArray(child)) {
|
|
3270
|
+
for (const item of child) {
|
|
3271
|
+
appendChildNode(parent, item);
|
|
3272
|
+
}
|
|
3273
|
+
return;
|
|
3274
|
+
}
|
|
3275
|
+
let domNode;
|
|
3276
|
+
if (typeof child !== "object" || child === null) {
|
|
3277
|
+
domNode = document.createTextNode(String(child ?? ""));
|
|
3278
|
+
} else {
|
|
3279
|
+
domNode = createElement(child);
|
|
3280
|
+
}
|
|
3281
|
+
if (domNode.nodeType === 11) {
|
|
3282
|
+
const children = Array.from(domNode.childNodes);
|
|
3283
|
+
for (const node of children) {
|
|
3284
|
+
appendChildNode(parent, node);
|
|
3285
|
+
}
|
|
3286
|
+
return;
|
|
3287
|
+
}
|
|
3288
|
+
if (domNode.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
|
|
3289
|
+
parent.ownerDocument.adoptNode(domNode);
|
|
3290
|
+
}
|
|
3291
|
+
try {
|
|
3292
|
+
parent.appendChild(domNode);
|
|
3293
|
+
} catch (e) {
|
|
3294
|
+
if (parent.ownerDocument) {
|
|
3295
|
+
const clone = parent.ownerDocument.importNode(domNode, true);
|
|
3296
|
+
parent.appendChild(clone);
|
|
3297
|
+
return;
|
|
3298
|
+
}
|
|
3299
|
+
throw e;
|
|
3300
|
+
}
|
|
3301
|
+
}
|
|
3302
|
+
function appendChildren(parent, children) {
|
|
3303
|
+
if (children === void 0) return;
|
|
3304
|
+
if (Array.isArray(children)) {
|
|
3305
|
+
for (const child of children) {
|
|
3306
|
+
appendChildren(parent, child);
|
|
3307
|
+
}
|
|
3308
|
+
return;
|
|
3309
|
+
}
|
|
3310
|
+
appendChildNode(parent, children);
|
|
3311
|
+
}
|
|
3312
|
+
function applyRef(el, value) {
|
|
3313
|
+
if (typeof value === "function") {
|
|
3314
|
+
const refFn = value;
|
|
3315
|
+
refFn(el);
|
|
3316
|
+
if (getCurrentRoot()) {
|
|
3317
|
+
registerRootCleanup(() => {
|
|
3318
|
+
refFn(null);
|
|
3319
|
+
});
|
|
3320
|
+
}
|
|
3321
|
+
} else if (value && typeof value === "object" && "current" in value) {
|
|
3322
|
+
const refObj = value;
|
|
3323
|
+
refObj.current = el;
|
|
3324
|
+
if (getCurrentRoot()) {
|
|
3325
|
+
registerRootCleanup(() => {
|
|
3326
|
+
refObj.current = null;
|
|
3327
|
+
});
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
}
|
|
3331
|
+
function applyProps(el, props, isSVG = false) {
|
|
3332
|
+
props = unwrapProps(props);
|
|
3333
|
+
const tagName = el.tagName;
|
|
3334
|
+
const isCE = tagName.includes("-") || "is" in props;
|
|
3335
|
+
for (const [key, value] of Object.entries(props)) {
|
|
3336
|
+
if (key === "children") continue;
|
|
3337
|
+
if (key === "ref") {
|
|
3338
|
+
applyRef(el, value);
|
|
3339
|
+
continue;
|
|
3340
|
+
}
|
|
3341
|
+
if (isEventKey(key)) {
|
|
3342
|
+
bindEvent(
|
|
3343
|
+
el,
|
|
3344
|
+
eventNameFromProp(key),
|
|
3345
|
+
value
|
|
3346
|
+
);
|
|
3347
|
+
continue;
|
|
3348
|
+
}
|
|
3349
|
+
if (key.slice(0, 3) === "on:") {
|
|
3350
|
+
bindEvent(
|
|
3351
|
+
el,
|
|
3352
|
+
key.slice(3),
|
|
3353
|
+
value,
|
|
3354
|
+
false
|
|
3355
|
+
// Non-delegated
|
|
3356
|
+
);
|
|
3357
|
+
continue;
|
|
3358
|
+
}
|
|
3359
|
+
if (key.slice(0, 10) === "oncapture:") {
|
|
3360
|
+
bindEvent(
|
|
3361
|
+
el,
|
|
3362
|
+
key.slice(10),
|
|
3363
|
+
value,
|
|
3364
|
+
true
|
|
3365
|
+
// Capture
|
|
3366
|
+
);
|
|
3367
|
+
continue;
|
|
3368
|
+
}
|
|
3369
|
+
if (key === "class" || key === "className") {
|
|
3370
|
+
createClassBinding(el, value);
|
|
3371
|
+
continue;
|
|
3372
|
+
}
|
|
3373
|
+
if (key === "classList") {
|
|
3374
|
+
createClassBinding(el, value);
|
|
3375
|
+
continue;
|
|
3376
|
+
}
|
|
3377
|
+
if (key === "style") {
|
|
3378
|
+
createStyleBinding(
|
|
3379
|
+
el,
|
|
3380
|
+
value
|
|
3381
|
+
);
|
|
3382
|
+
continue;
|
|
3383
|
+
}
|
|
3384
|
+
if (key === "dangerouslySetInnerHTML" && value && typeof value === "object") {
|
|
3385
|
+
const htmlValue = value.__html;
|
|
3386
|
+
if (htmlValue !== void 0) {
|
|
3387
|
+
if (isReactive(htmlValue)) {
|
|
3388
|
+
createAttributeBinding(el, "innerHTML", htmlValue, setInnerHTML);
|
|
3389
|
+
} else {
|
|
3390
|
+
el.innerHTML = htmlValue;
|
|
3391
|
+
}
|
|
3392
|
+
}
|
|
3393
|
+
continue;
|
|
3394
|
+
}
|
|
3395
|
+
if (ChildProperties.has(key)) {
|
|
3396
|
+
createAttributeBinding(el, key, value, setProperty);
|
|
3397
|
+
continue;
|
|
3398
|
+
}
|
|
3399
|
+
if (key.slice(0, 5) === "attr:") {
|
|
3400
|
+
createAttributeBinding(el, key.slice(5), value, setAttribute);
|
|
3401
|
+
continue;
|
|
3402
|
+
}
|
|
3403
|
+
if (key.slice(0, 5) === "bool:") {
|
|
3404
|
+
createAttributeBinding(el, key.slice(5), value, setBoolAttribute);
|
|
3405
|
+
continue;
|
|
3406
|
+
}
|
|
3407
|
+
if (key.slice(0, 5) === "prop:") {
|
|
3408
|
+
createAttributeBinding(el, key.slice(5), value, setProperty);
|
|
3409
|
+
continue;
|
|
3410
|
+
}
|
|
3411
|
+
const propAlias = !isSVG ? getPropAlias(key, tagName) : void 0;
|
|
3412
|
+
if (propAlias || !isSVG && Properties.has(key) || isCE && !isSVG) {
|
|
3413
|
+
const propName = propAlias || key;
|
|
3414
|
+
if (isCE && !Properties.has(key)) {
|
|
3415
|
+
createAttributeBinding(
|
|
3416
|
+
el,
|
|
3417
|
+
toPropertyName2(propName),
|
|
3418
|
+
value,
|
|
3419
|
+
setProperty
|
|
3420
|
+
);
|
|
3421
|
+
} else {
|
|
3422
|
+
createAttributeBinding(el, propName, value, setProperty);
|
|
3423
|
+
}
|
|
3424
|
+
continue;
|
|
3425
|
+
}
|
|
3426
|
+
if (isSVG && key.indexOf(":") > -1) {
|
|
3427
|
+
const [prefix, name] = key.split(":");
|
|
3428
|
+
const ns = SVGNamespace[prefix];
|
|
3429
|
+
if (ns) {
|
|
3430
|
+
createAttributeBinding(
|
|
3431
|
+
el,
|
|
3432
|
+
key,
|
|
3433
|
+
value,
|
|
3434
|
+
(el2, _key, val) => setAttributeNS(el2, ns, name, val)
|
|
3435
|
+
);
|
|
3436
|
+
continue;
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
const attrName = Aliases[key] || key;
|
|
3440
|
+
createAttributeBinding(el, attrName, value, setAttribute);
|
|
3441
|
+
}
|
|
3442
|
+
const children = props.children;
|
|
3443
|
+
appendChildren(el, children);
|
|
3444
|
+
}
|
|
3445
|
+
function toPropertyName2(name) {
|
|
3446
|
+
return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
|
|
3447
|
+
}
|
|
3448
|
+
var setAttribute = (el, key, value) => {
|
|
3449
|
+
if (value === void 0 || value === null || value === false) {
|
|
3450
|
+
el.removeAttribute(key);
|
|
3451
|
+
return;
|
|
3452
|
+
}
|
|
3453
|
+
if (value === true) {
|
|
3454
|
+
el.setAttribute(key, "");
|
|
3455
|
+
return;
|
|
3456
|
+
}
|
|
3457
|
+
const valueType = typeof value;
|
|
3458
|
+
if (valueType === "string" || valueType === "number") {
|
|
3459
|
+
el.setAttribute(key, String(value));
|
|
3460
|
+
return;
|
|
3461
|
+
}
|
|
3462
|
+
if (key in el) {
|
|
3463
|
+
;
|
|
3464
|
+
el[key] = value;
|
|
3465
|
+
return;
|
|
3466
|
+
}
|
|
3467
|
+
el.setAttribute(key, String(value));
|
|
3468
|
+
};
|
|
3469
|
+
var setProperty = (el, key, value) => {
|
|
3470
|
+
if (value === void 0 || value === null) {
|
|
3471
|
+
const fallback = key === "checked" || key === "selected" ? false : "";
|
|
3472
|
+
el[key] = fallback;
|
|
3473
|
+
return;
|
|
3474
|
+
}
|
|
3475
|
+
if (key === "style" && typeof value === "object" && value !== null) {
|
|
3476
|
+
for (const k in value) {
|
|
3477
|
+
const v = value[k];
|
|
3478
|
+
if (v !== void 0) {
|
|
3479
|
+
;
|
|
3480
|
+
el.style[k] = String(v);
|
|
3481
|
+
}
|
|
3482
|
+
}
|
|
3483
|
+
return;
|
|
3484
|
+
}
|
|
3485
|
+
;
|
|
3486
|
+
el[key] = value;
|
|
3487
|
+
};
|
|
3488
|
+
var setInnerHTML = (el, _key, value) => {
|
|
3489
|
+
el.innerHTML = value == null ? "" : String(value);
|
|
3490
|
+
};
|
|
3491
|
+
var setBoolAttribute = (el, key, value) => {
|
|
3492
|
+
if (value) {
|
|
3493
|
+
el.setAttribute(key, "");
|
|
3494
|
+
} else {
|
|
3495
|
+
el.removeAttribute(key);
|
|
3496
|
+
}
|
|
3497
|
+
};
|
|
3498
|
+
function setAttributeNS(el, namespace, name, value) {
|
|
3499
|
+
if (value == null) {
|
|
3500
|
+
el.removeAttributeNS(namespace, name);
|
|
3501
|
+
} else {
|
|
3502
|
+
el.setAttributeNS(namespace, name, String(value));
|
|
3503
|
+
}
|
|
3504
|
+
}
|
|
3505
|
+
function isEventKey(key) {
|
|
3506
|
+
return key.startsWith("on") && key.length > 2 && key[2].toUpperCase() === key[2];
|
|
3507
|
+
}
|
|
3508
|
+
function eventNameFromProp(key) {
|
|
3509
|
+
return key.slice(2).toLowerCase();
|
|
3510
|
+
}
|
|
3511
|
+
|
|
3512
|
+
// src/error-boundary.ts
|
|
3513
|
+
function ErrorBoundary(props) {
|
|
3514
|
+
const fragment = document.createDocumentFragment();
|
|
3515
|
+
const marker = document.createComment("fict:error-boundary");
|
|
3516
|
+
fragment.appendChild(marker);
|
|
3517
|
+
const currentView = signal(props.children ?? null);
|
|
3518
|
+
let cleanup;
|
|
3519
|
+
let activeNodes = [];
|
|
3520
|
+
let renderingFallback = false;
|
|
3521
|
+
const toView = (err) => {
|
|
3522
|
+
if (err != null) {
|
|
3523
|
+
return typeof props.fallback === "function" ? props.fallback(err) : props.fallback;
|
|
3524
|
+
}
|
|
3525
|
+
return props.children ?? null;
|
|
3526
|
+
};
|
|
3527
|
+
const renderValue = (value) => {
|
|
3528
|
+
if (cleanup) {
|
|
3529
|
+
cleanup();
|
|
3530
|
+
cleanup = void 0;
|
|
3531
|
+
}
|
|
3532
|
+
if (activeNodes.length) {
|
|
3533
|
+
removeNodes(activeNodes);
|
|
3534
|
+
activeNodes = [];
|
|
3535
|
+
}
|
|
3536
|
+
if (value == null || value === false) {
|
|
3537
|
+
return;
|
|
3538
|
+
}
|
|
3539
|
+
const root = createRootContext();
|
|
3540
|
+
const prev = pushRoot(root);
|
|
3541
|
+
let nodes = [];
|
|
3542
|
+
try {
|
|
3543
|
+
const output = createElement(value);
|
|
3544
|
+
nodes = toNodeArray(output);
|
|
3545
|
+
const parentNode = marker.parentNode;
|
|
3546
|
+
if (parentNode) {
|
|
3547
|
+
insertNodesBefore(parentNode, nodes, marker);
|
|
3548
|
+
}
|
|
3549
|
+
} catch (err) {
|
|
3550
|
+
popRoot(prev);
|
|
3551
|
+
flushOnMount(root);
|
|
3552
|
+
destroyRoot(root);
|
|
3553
|
+
if (renderingFallback) {
|
|
3554
|
+
throw err;
|
|
3555
|
+
}
|
|
3556
|
+
renderingFallback = true;
|
|
3557
|
+
try {
|
|
3558
|
+
renderValue(toView(err));
|
|
3559
|
+
} finally {
|
|
3560
|
+
renderingFallback = false;
|
|
3561
|
+
}
|
|
3562
|
+
props.onError?.(err);
|
|
3563
|
+
return;
|
|
3564
|
+
}
|
|
3565
|
+
popRoot(prev);
|
|
3566
|
+
flushOnMount(root);
|
|
3567
|
+
cleanup = () => {
|
|
3568
|
+
destroyRoot(root);
|
|
3569
|
+
removeNodes(nodes);
|
|
3570
|
+
};
|
|
3571
|
+
activeNodes = nodes;
|
|
3572
|
+
};
|
|
3573
|
+
createEffect(() => {
|
|
3574
|
+
const value = currentView();
|
|
3575
|
+
renderValue(value);
|
|
3576
|
+
});
|
|
3577
|
+
registerErrorHandler((err) => {
|
|
3578
|
+
renderValue(toView(err));
|
|
3579
|
+
props.onError?.(err);
|
|
3580
|
+
return true;
|
|
3581
|
+
});
|
|
3582
|
+
if (props.resetKeys !== void 0) {
|
|
3583
|
+
const isGetter = typeof props.resetKeys === "function" && props.resetKeys.length === 0;
|
|
3584
|
+
const getter = isGetter ? props.resetKeys : void 0;
|
|
3585
|
+
let prev = isGetter ? getter() : props.resetKeys;
|
|
3586
|
+
createEffect(() => {
|
|
3587
|
+
const next = getter ? getter() : props.resetKeys;
|
|
3588
|
+
if (prev !== next) {
|
|
3589
|
+
prev = next;
|
|
3590
|
+
renderValue(toView(null));
|
|
3591
|
+
}
|
|
3592
|
+
});
|
|
3593
|
+
}
|
|
3594
|
+
return fragment;
|
|
3595
|
+
}
|
|
3596
|
+
|
|
3597
|
+
// src/suspense.ts
|
|
3598
|
+
function createSuspenseToken() {
|
|
3599
|
+
let resolve;
|
|
3600
|
+
let reject;
|
|
3601
|
+
const promise = new Promise((res, rej) => {
|
|
3602
|
+
resolve = res;
|
|
3603
|
+
reject = rej;
|
|
3604
|
+
});
|
|
3605
|
+
return {
|
|
3606
|
+
token: {
|
|
3607
|
+
then: promise.then.bind(promise)
|
|
3608
|
+
},
|
|
3609
|
+
resolve,
|
|
3610
|
+
reject
|
|
3611
|
+
};
|
|
3612
|
+
}
|
|
3613
|
+
var isThenable = (value) => typeof value === "object" && value !== null && typeof value.then === "function";
|
|
3614
|
+
function Suspense(props) {
|
|
3615
|
+
const currentView = signal(props.children ?? null);
|
|
3616
|
+
const pending = signal(0);
|
|
3617
|
+
let resolvedOnce = false;
|
|
3618
|
+
let epoch = 0;
|
|
3619
|
+
const hostRoot = getCurrentRoot();
|
|
3620
|
+
const toFallback = (err) => typeof props.fallback === "function" ? props.fallback(err) : props.fallback;
|
|
3621
|
+
const switchView = (view) => {
|
|
3622
|
+
currentView(view);
|
|
3623
|
+
renderView(view);
|
|
3624
|
+
};
|
|
3625
|
+
const renderView = (view) => {
|
|
3626
|
+
if (cleanup) {
|
|
3627
|
+
cleanup();
|
|
3628
|
+
cleanup = void 0;
|
|
3629
|
+
}
|
|
3630
|
+
if (activeNodes.length) {
|
|
3631
|
+
removeNodes(activeNodes);
|
|
3632
|
+
activeNodes = [];
|
|
3633
|
+
}
|
|
3634
|
+
if (view == null || view === false) {
|
|
3635
|
+
return;
|
|
3636
|
+
}
|
|
3637
|
+
const root = createRootContext(hostRoot);
|
|
3638
|
+
const prev = pushRoot(root);
|
|
3639
|
+
let nodes = [];
|
|
3640
|
+
try {
|
|
3641
|
+
const output = createElement(view);
|
|
3642
|
+
nodes = toNodeArray(output);
|
|
3643
|
+
const suspendedAttempt = nodes.length > 0 && nodes.every((node) => node instanceof Comment && node.data === "fict:suspend");
|
|
3644
|
+
if (suspendedAttempt) {
|
|
3645
|
+
popRoot(prev);
|
|
3646
|
+
destroyRoot(root);
|
|
3647
|
+
return;
|
|
3648
|
+
}
|
|
3649
|
+
const parentNode = marker.parentNode;
|
|
3650
|
+
if (parentNode) {
|
|
3651
|
+
insertNodesBefore(parentNode, nodes, marker);
|
|
3652
|
+
}
|
|
3653
|
+
} catch (err) {
|
|
3654
|
+
popRoot(prev);
|
|
3655
|
+
flushOnMount(root);
|
|
3656
|
+
destroyRoot(root);
|
|
3657
|
+
handleError(err, { source: "render" });
|
|
3658
|
+
return;
|
|
3659
|
+
}
|
|
3660
|
+
popRoot(prev);
|
|
3661
|
+
flushOnMount(root);
|
|
3662
|
+
cleanup = () => {
|
|
3663
|
+
destroyRoot(root);
|
|
3664
|
+
removeNodes(nodes);
|
|
3665
|
+
};
|
|
3666
|
+
activeNodes = nodes;
|
|
3667
|
+
};
|
|
3668
|
+
const fragment = document.createDocumentFragment();
|
|
3669
|
+
const marker = document.createComment("fict:suspense");
|
|
3670
|
+
fragment.appendChild(marker);
|
|
3671
|
+
let cleanup;
|
|
3672
|
+
let activeNodes = [];
|
|
3673
|
+
const onResolveMaybe = () => {
|
|
3674
|
+
if (!resolvedOnce) {
|
|
3675
|
+
resolvedOnce = true;
|
|
3676
|
+
props.onResolve?.();
|
|
3677
|
+
}
|
|
3678
|
+
};
|
|
3679
|
+
registerSuspenseHandler((token) => {
|
|
3680
|
+
const tokenEpoch = epoch;
|
|
3681
|
+
pending(pending() + 1);
|
|
3682
|
+
switchView(toFallback());
|
|
3683
|
+
const thenable = token.then ? token : isThenable(token) ? token : null;
|
|
3684
|
+
if (thenable) {
|
|
3685
|
+
thenable.then(
|
|
3686
|
+
() => {
|
|
3687
|
+
if (epoch !== tokenEpoch) return;
|
|
3688
|
+
pending(Math.max(0, pending() - 1));
|
|
3689
|
+
if (pending() === 0) {
|
|
3690
|
+
switchView(props.children ?? null);
|
|
3691
|
+
onResolveMaybe();
|
|
3692
|
+
}
|
|
3693
|
+
},
|
|
3694
|
+
(err) => {
|
|
3695
|
+
if (epoch !== tokenEpoch) return;
|
|
3696
|
+
pending(Math.max(0, pending() - 1));
|
|
3697
|
+
props.onReject?.(err);
|
|
3698
|
+
handleError(err, { source: "render" }, hostRoot);
|
|
3699
|
+
}
|
|
3700
|
+
);
|
|
3701
|
+
return true;
|
|
3702
|
+
}
|
|
3703
|
+
return false;
|
|
3704
|
+
});
|
|
3705
|
+
createEffect(() => {
|
|
3706
|
+
renderView(currentView());
|
|
3707
|
+
});
|
|
3708
|
+
if (props.resetKeys !== void 0) {
|
|
3709
|
+
const isGetter = typeof props.resetKeys === "function" && props.resetKeys.length === 0;
|
|
3710
|
+
const getter = isGetter ? props.resetKeys : void 0;
|
|
3711
|
+
let prev = isGetter ? getter() : props.resetKeys;
|
|
3712
|
+
createEffect(() => {
|
|
3713
|
+
const next = getter ? getter() : props.resetKeys;
|
|
3714
|
+
if (prev !== next) {
|
|
3715
|
+
prev = next;
|
|
3716
|
+
epoch++;
|
|
3717
|
+
pending(0);
|
|
3718
|
+
switchView(props.children ?? null);
|
|
3719
|
+
}
|
|
3720
|
+
});
|
|
3721
|
+
}
|
|
3722
|
+
return fragment;
|
|
3723
|
+
}
|
|
3724
|
+
|
|
3725
|
+
// src/reconcile.ts
|
|
3726
|
+
function reconcileArrays(parentNode, a, b) {
|
|
3727
|
+
const bLength = b.length;
|
|
3728
|
+
let aEnd = a.length;
|
|
3729
|
+
let bEnd = bLength;
|
|
3730
|
+
let aStart = 0;
|
|
3731
|
+
let bStart = 0;
|
|
3732
|
+
const after = aEnd > 0 ? a[aEnd - 1].nextSibling : null;
|
|
3733
|
+
let map = null;
|
|
3734
|
+
while (aStart < aEnd || bStart < bEnd) {
|
|
3735
|
+
if (a[aStart] === b[bStart]) {
|
|
3736
|
+
aStart++;
|
|
3737
|
+
bStart++;
|
|
3738
|
+
continue;
|
|
3739
|
+
}
|
|
3740
|
+
while (a[aEnd - 1] === b[bEnd - 1]) {
|
|
3741
|
+
aEnd--;
|
|
3742
|
+
bEnd--;
|
|
3743
|
+
}
|
|
3744
|
+
if (aEnd === aStart) {
|
|
3745
|
+
const node = bEnd < bLength ? bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart] ?? null : after;
|
|
3746
|
+
const count = bEnd - bStart;
|
|
3747
|
+
const doc = parentNode.ownerDocument;
|
|
3748
|
+
if (count > 1 && doc) {
|
|
3749
|
+
const frag = doc.createDocumentFragment();
|
|
3750
|
+
for (let i = bStart; i < bEnd; i++) {
|
|
3751
|
+
frag.appendChild(b[i]);
|
|
3752
|
+
}
|
|
3753
|
+
parentNode.insertBefore(frag, node);
|
|
3754
|
+
bStart = bEnd;
|
|
3755
|
+
} else {
|
|
3756
|
+
while (bStart < bEnd) {
|
|
3757
|
+
parentNode.insertBefore(b[bStart++], node);
|
|
3758
|
+
}
|
|
3759
|
+
}
|
|
3760
|
+
} else if (bEnd === bStart) {
|
|
3761
|
+
while (aStart < aEnd) {
|
|
3762
|
+
const nodeToRemove = a[aStart];
|
|
3763
|
+
if (!map || !map.has(nodeToRemove)) {
|
|
3764
|
+
nodeToRemove.parentNode?.removeChild(nodeToRemove);
|
|
3765
|
+
}
|
|
3766
|
+
aStart++;
|
|
3767
|
+
}
|
|
3768
|
+
} else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) {
|
|
3769
|
+
const node = a[--aEnd].nextSibling;
|
|
3770
|
+
parentNode.insertBefore(b[bStart++], a[aStart++].nextSibling);
|
|
3771
|
+
parentNode.insertBefore(b[--bEnd], node);
|
|
3772
|
+
a[aEnd] = b[bEnd];
|
|
3773
|
+
} else {
|
|
3774
|
+
if (!map) {
|
|
3775
|
+
map = /* @__PURE__ */ new Map();
|
|
3776
|
+
let i = bStart;
|
|
3777
|
+
while (i < bEnd) {
|
|
3778
|
+
map.set(b[i], i++);
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3781
|
+
const index = map.get(a[aStart]);
|
|
3782
|
+
if (index != null) {
|
|
3783
|
+
if (bStart < index && index < bEnd) {
|
|
3784
|
+
let i = aStart;
|
|
3785
|
+
let sequence = 1;
|
|
3786
|
+
let t;
|
|
3787
|
+
while (++i < aEnd && i < bEnd) {
|
|
3788
|
+
t = map.get(a[i]);
|
|
3789
|
+
if (t == null || t !== index + sequence) break;
|
|
3790
|
+
sequence++;
|
|
3791
|
+
}
|
|
3792
|
+
if (sequence > index - bStart) {
|
|
3793
|
+
const node = a[aStart];
|
|
3794
|
+
while (bStart < index) {
|
|
3795
|
+
parentNode.insertBefore(b[bStart++], node);
|
|
3796
|
+
}
|
|
3797
|
+
} else {
|
|
3798
|
+
parentNode.replaceChild(b[bStart++], a[aStart++]);
|
|
3799
|
+
}
|
|
3800
|
+
} else {
|
|
3801
|
+
aStart++;
|
|
3802
|
+
}
|
|
3803
|
+
} else {
|
|
3804
|
+
const nodeToRemove = a[aStart++];
|
|
3805
|
+
nodeToRemove.parentNode?.removeChild(nodeToRemove);
|
|
3806
|
+
}
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3810
|
+
|
|
3811
|
+
// src/list-helpers.ts
|
|
3812
|
+
function moveNodesBefore(parent, nodes, anchor) {
|
|
3813
|
+
for (let i = nodes.length - 1; i >= 0; i--) {
|
|
3814
|
+
const node = nodes[i];
|
|
3815
|
+
if (!node || !(node instanceof Node)) {
|
|
3816
|
+
throw new Error("Invalid node in moveNodesBefore");
|
|
3817
|
+
}
|
|
3818
|
+
if (node.nextSibling !== anchor) {
|
|
3819
|
+
if (node.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
|
|
3820
|
+
parent.ownerDocument.adoptNode(node);
|
|
3821
|
+
}
|
|
3822
|
+
try {
|
|
3823
|
+
parent.insertBefore(node, anchor);
|
|
3824
|
+
} catch (e) {
|
|
3825
|
+
if (parent.ownerDocument) {
|
|
3826
|
+
try {
|
|
3827
|
+
const clone = parent.ownerDocument.importNode(node, true);
|
|
3828
|
+
parent.insertBefore(clone, anchor);
|
|
3829
|
+
continue;
|
|
3830
|
+
} catch {
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3833
|
+
throw e;
|
|
3834
|
+
}
|
|
3835
|
+
}
|
|
3836
|
+
anchor = node;
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
function moveMarkerBlock(parent, block, anchor) {
|
|
3840
|
+
const nodes = collectBlockNodes(block);
|
|
3841
|
+
if (nodes.length === 0) return;
|
|
3842
|
+
moveNodesBefore(parent, nodes, anchor);
|
|
3843
|
+
}
|
|
3844
|
+
function destroyMarkerBlock(block) {
|
|
3845
|
+
if (block.root) {
|
|
3846
|
+
destroyRoot(block.root);
|
|
3847
|
+
}
|
|
3848
|
+
removeBlockRange(block);
|
|
3849
|
+
}
|
|
3850
|
+
function collectBlockNodes(block) {
|
|
3851
|
+
const nodes = [];
|
|
3852
|
+
let cursor = block.start;
|
|
3853
|
+
while (cursor) {
|
|
3854
|
+
nodes.push(cursor);
|
|
3855
|
+
if (cursor === block.end) {
|
|
3856
|
+
break;
|
|
3857
|
+
}
|
|
3858
|
+
cursor = cursor.nextSibling;
|
|
3859
|
+
}
|
|
3860
|
+
return nodes;
|
|
3861
|
+
}
|
|
3862
|
+
function removeBlockRange(block) {
|
|
3863
|
+
let cursor = block.start;
|
|
3864
|
+
while (cursor) {
|
|
3865
|
+
const next = cursor.nextSibling;
|
|
3866
|
+
cursor.parentNode?.removeChild(cursor);
|
|
3867
|
+
if (cursor === block.end) {
|
|
3868
|
+
break;
|
|
3869
|
+
}
|
|
3870
|
+
cursor = next;
|
|
3871
|
+
}
|
|
3872
|
+
}
|
|
3873
|
+
function createVersionedSignalAccessor(initialValue) {
|
|
3874
|
+
let current = initialValue;
|
|
3875
|
+
let version = 0;
|
|
3876
|
+
const track2 = signal(version);
|
|
3877
|
+
function accessor(value) {
|
|
3878
|
+
if (arguments.length === 0) {
|
|
3879
|
+
track2();
|
|
3880
|
+
return current;
|
|
3881
|
+
}
|
|
3882
|
+
current = value;
|
|
3883
|
+
version++;
|
|
3884
|
+
track2(version);
|
|
3885
|
+
}
|
|
3886
|
+
return accessor;
|
|
3887
|
+
}
|
|
3888
|
+
function createKeyedListContainer() {
|
|
3889
|
+
const startMarker = document.createComment("fict:list:start");
|
|
3890
|
+
const endMarker = document.createComment("fict:list:end");
|
|
3891
|
+
const dispose = () => {
|
|
3892
|
+
for (const block of container.blocks.values()) {
|
|
3893
|
+
destroyRoot(block.root);
|
|
3894
|
+
}
|
|
3895
|
+
container.blocks.clear();
|
|
3896
|
+
container.nextBlocks.clear();
|
|
3897
|
+
const range = document.createRange();
|
|
3898
|
+
range.setStartBefore(startMarker);
|
|
3899
|
+
range.setEndAfter(endMarker);
|
|
3900
|
+
range.deleteContents();
|
|
3901
|
+
container.currentNodes = [];
|
|
3902
|
+
container.nextNodes = [];
|
|
3903
|
+
container.nextBlocks.clear();
|
|
3904
|
+
container.orderedBlocks.length = 0;
|
|
3905
|
+
container.nextOrderedBlocks.length = 0;
|
|
3906
|
+
container.orderedIndexByKey.clear();
|
|
3907
|
+
};
|
|
3908
|
+
const container = {
|
|
3909
|
+
startMarker,
|
|
3910
|
+
endMarker,
|
|
3911
|
+
blocks: /* @__PURE__ */ new Map(),
|
|
3912
|
+
nextBlocks: /* @__PURE__ */ new Map(),
|
|
3913
|
+
currentNodes: [startMarker, endMarker],
|
|
3914
|
+
nextNodes: [],
|
|
3915
|
+
orderedBlocks: [],
|
|
3916
|
+
nextOrderedBlocks: [],
|
|
3917
|
+
orderedIndexByKey: /* @__PURE__ */ new Map(),
|
|
3918
|
+
dispose
|
|
3919
|
+
};
|
|
3920
|
+
return container;
|
|
3921
|
+
}
|
|
3922
|
+
function createKeyedBlock(key, item, index, render2, needsIndex = true) {
|
|
3923
|
+
const itemSig = createVersionedSignalAccessor(item);
|
|
3924
|
+
const indexSig = needsIndex ? signal(index) : ((next) => {
|
|
3925
|
+
if (arguments.length === 0) return index;
|
|
3926
|
+
index = next;
|
|
3927
|
+
return index;
|
|
3928
|
+
});
|
|
3929
|
+
const root = createRootContext();
|
|
3930
|
+
const prevRoot = pushRoot(root);
|
|
3931
|
+
const prevSub = setActiveSub(void 0);
|
|
3932
|
+
let nodes = [];
|
|
3933
|
+
try {
|
|
3934
|
+
const rendered = render2(itemSig, indexSig, key);
|
|
3935
|
+
if (rendered instanceof Node || Array.isArray(rendered) && rendered.every((n) => n instanceof Node)) {
|
|
3936
|
+
nodes = toNodeArray(rendered);
|
|
3937
|
+
} else {
|
|
3938
|
+
const element = createElement(rendered);
|
|
3939
|
+
nodes = toNodeArray(element);
|
|
3940
|
+
}
|
|
3941
|
+
} finally {
|
|
3942
|
+
setActiveSub(prevSub);
|
|
3943
|
+
popRoot(prevRoot);
|
|
3944
|
+
flushOnMount(root);
|
|
3945
|
+
}
|
|
3946
|
+
return {
|
|
3947
|
+
key,
|
|
3948
|
+
nodes,
|
|
3949
|
+
root,
|
|
3950
|
+
item: itemSig,
|
|
3951
|
+
index: indexSig,
|
|
3952
|
+
rawItem: item,
|
|
3953
|
+
rawIndex: index
|
|
3954
|
+
};
|
|
3955
|
+
}
|
|
3956
|
+
function getFirstNodeAfter(marker) {
|
|
3957
|
+
return marker.nextSibling;
|
|
3958
|
+
}
|
|
3959
|
+
function isNodeBetweenMarkers(node, startMarker, endMarker) {
|
|
3960
|
+
let current = startMarker.nextSibling;
|
|
3961
|
+
while (current && current !== endMarker) {
|
|
3962
|
+
if (current === node) return true;
|
|
3963
|
+
current = current.nextSibling;
|
|
3964
|
+
}
|
|
3965
|
+
return false;
|
|
3966
|
+
}
|
|
3967
|
+
function createKeyedList(getItems, keyFn, renderItem, needsIndex) {
|
|
3968
|
+
const resolvedNeedsIndex = arguments.length >= 4 ? !!needsIndex : renderItem.length > 1;
|
|
3969
|
+
return createFineGrainedKeyedList(getItems, keyFn, renderItem, resolvedNeedsIndex);
|
|
3970
|
+
}
|
|
3971
|
+
function createFineGrainedKeyedList(getItems, keyFn, renderItem, needsIndex) {
|
|
3972
|
+
const container = createKeyedListContainer();
|
|
3973
|
+
const fragment = document.createDocumentFragment();
|
|
3974
|
+
fragment.append(container.startMarker, container.endMarker);
|
|
3975
|
+
let pendingItems = null;
|
|
3976
|
+
let disposed = false;
|
|
3977
|
+
const performDiff = () => {
|
|
3978
|
+
if (disposed) return;
|
|
3979
|
+
batch2(() => {
|
|
3980
|
+
const newItems = pendingItems || getItems();
|
|
3981
|
+
pendingItems = null;
|
|
3982
|
+
const oldBlocks = container.blocks;
|
|
3983
|
+
const newBlocks = container.nextBlocks;
|
|
3984
|
+
const prevOrderedBlocks = container.orderedBlocks;
|
|
3985
|
+
const nextOrderedBlocks = container.nextOrderedBlocks;
|
|
3986
|
+
const orderedIndexByKey = container.orderedIndexByKey;
|
|
3987
|
+
newBlocks.clear();
|
|
3988
|
+
nextOrderedBlocks.length = 0;
|
|
3989
|
+
orderedIndexByKey.clear();
|
|
3990
|
+
const endParent = container.endMarker.parentNode;
|
|
3991
|
+
const startParent = container.startMarker.parentNode;
|
|
3992
|
+
const parent = endParent && startParent && endParent === startParent && endParent.isConnected ? endParent : null;
|
|
3993
|
+
if (!parent) {
|
|
3994
|
+
pendingItems = newItems;
|
|
3995
|
+
queueMicrotask(performDiff);
|
|
3996
|
+
return;
|
|
3997
|
+
}
|
|
3998
|
+
if (newItems.length === 0) {
|
|
3999
|
+
if (oldBlocks.size > 0) {
|
|
4000
|
+
for (const block of oldBlocks.values()) {
|
|
4001
|
+
destroyRoot(block.root);
|
|
4002
|
+
removeNodes(block.nodes);
|
|
4003
|
+
}
|
|
4004
|
+
}
|
|
4005
|
+
oldBlocks.clear();
|
|
4006
|
+
newBlocks.clear();
|
|
4007
|
+
prevOrderedBlocks.length = 0;
|
|
4008
|
+
nextOrderedBlocks.length = 0;
|
|
4009
|
+
orderedIndexByKey.clear();
|
|
4010
|
+
container.currentNodes.length = 0;
|
|
4011
|
+
container.currentNodes.push(container.startMarker, container.endMarker);
|
|
4012
|
+
container.nextNodes.length = 0;
|
|
4013
|
+
return;
|
|
4014
|
+
}
|
|
4015
|
+
const prevCount = prevOrderedBlocks.length;
|
|
4016
|
+
let appendCandidate = prevCount > 0 && newItems.length >= prevCount;
|
|
4017
|
+
const appendedBlocks = [];
|
|
4018
|
+
newItems.forEach((item, index) => {
|
|
4019
|
+
const key = keyFn(item, index);
|
|
4020
|
+
const existed = oldBlocks.has(key);
|
|
4021
|
+
let block = oldBlocks.get(key);
|
|
4022
|
+
if (block) {
|
|
4023
|
+
if (block.rawItem !== item) {
|
|
4024
|
+
block.rawItem = item;
|
|
4025
|
+
block.item(item);
|
|
4026
|
+
}
|
|
4027
|
+
if (needsIndex && block.rawIndex !== index) {
|
|
4028
|
+
block.rawIndex = index;
|
|
4029
|
+
block.index(index);
|
|
4030
|
+
}
|
|
4031
|
+
}
|
|
4032
|
+
const existingBlock = newBlocks.get(key);
|
|
4033
|
+
if (existingBlock && existingBlock !== block) {
|
|
4034
|
+
destroyRoot(existingBlock.root);
|
|
4035
|
+
removeNodes(existingBlock.nodes);
|
|
4036
|
+
}
|
|
4037
|
+
if (block) {
|
|
4038
|
+
newBlocks.set(key, block);
|
|
4039
|
+
oldBlocks.delete(key);
|
|
4040
|
+
} else {
|
|
4041
|
+
const existingBlock2 = newBlocks.get(key);
|
|
4042
|
+
if (existingBlock2) {
|
|
4043
|
+
destroyRoot(existingBlock2.root);
|
|
4044
|
+
removeNodes(existingBlock2.nodes);
|
|
4045
|
+
}
|
|
4046
|
+
block = createKeyedBlock(key, item, index, renderItem, needsIndex);
|
|
4047
|
+
}
|
|
4048
|
+
const resolvedBlock = block;
|
|
4049
|
+
newBlocks.set(key, resolvedBlock);
|
|
4050
|
+
const position = orderedIndexByKey.get(key);
|
|
4051
|
+
if (position !== void 0) {
|
|
4052
|
+
appendCandidate = false;
|
|
4053
|
+
}
|
|
4054
|
+
if (appendCandidate) {
|
|
4055
|
+
if (index < prevCount) {
|
|
4056
|
+
if (!prevOrderedBlocks[index] || prevOrderedBlocks[index].key !== key) {
|
|
4057
|
+
appendCandidate = false;
|
|
4058
|
+
}
|
|
4059
|
+
} else if (existed) {
|
|
4060
|
+
appendCandidate = false;
|
|
4061
|
+
}
|
|
4062
|
+
}
|
|
4063
|
+
if (position !== void 0) {
|
|
4064
|
+
const prior = nextOrderedBlocks[position];
|
|
4065
|
+
if (prior && prior !== resolvedBlock) {
|
|
4066
|
+
destroyRoot(prior.root);
|
|
4067
|
+
removeNodes(prior.nodes);
|
|
4068
|
+
}
|
|
4069
|
+
nextOrderedBlocks[position] = resolvedBlock;
|
|
4070
|
+
} else {
|
|
4071
|
+
orderedIndexByKey.set(key, nextOrderedBlocks.length);
|
|
4072
|
+
nextOrderedBlocks.push(resolvedBlock);
|
|
4073
|
+
}
|
|
4074
|
+
if (appendCandidate && index >= prevCount) {
|
|
4075
|
+
appendedBlocks.push(resolvedBlock);
|
|
4076
|
+
}
|
|
4077
|
+
});
|
|
4078
|
+
const canAppend = appendCandidate && prevCount > 0 && newItems.length > prevCount && oldBlocks.size === 0 && appendedBlocks.length > 0;
|
|
4079
|
+
if (canAppend) {
|
|
4080
|
+
const appendedNodes = [];
|
|
4081
|
+
for (const block of appendedBlocks) {
|
|
4082
|
+
for (let i = 0; i < block.nodes.length; i++) {
|
|
4083
|
+
appendedNodes.push(block.nodes[i]);
|
|
4084
|
+
}
|
|
4085
|
+
}
|
|
4086
|
+
if (appendedNodes.length > 0) {
|
|
4087
|
+
insertNodesBefore(parent, appendedNodes, container.endMarker);
|
|
4088
|
+
const currentNodes = container.currentNodes;
|
|
4089
|
+
currentNodes.pop();
|
|
4090
|
+
for (let i = 0; i < appendedNodes.length; i++) {
|
|
4091
|
+
currentNodes.push(appendedNodes[i]);
|
|
4092
|
+
}
|
|
4093
|
+
currentNodes.push(container.endMarker);
|
|
4094
|
+
}
|
|
4095
|
+
container.blocks = newBlocks;
|
|
4096
|
+
container.nextBlocks = oldBlocks;
|
|
4097
|
+
container.orderedBlocks = nextOrderedBlocks;
|
|
4098
|
+
container.nextOrderedBlocks = prevOrderedBlocks;
|
|
4099
|
+
return;
|
|
4100
|
+
}
|
|
4101
|
+
if (oldBlocks.size > 0) {
|
|
4102
|
+
for (const block of oldBlocks.values()) {
|
|
4103
|
+
destroyRoot(block.root);
|
|
4104
|
+
removeNodes(block.nodes);
|
|
4105
|
+
}
|
|
4106
|
+
oldBlocks.clear();
|
|
4107
|
+
}
|
|
4108
|
+
if (newBlocks.size > 0 || container.currentNodes.length > 0) {
|
|
4109
|
+
const prevNodes = container.currentNodes;
|
|
4110
|
+
const nextNodes = container.nextNodes;
|
|
4111
|
+
nextNodes.length = 0;
|
|
4112
|
+
nextNodes.push(container.startMarker);
|
|
4113
|
+
for (let i = 0; i < nextOrderedBlocks.length; i++) {
|
|
4114
|
+
const nodes = nextOrderedBlocks[i].nodes;
|
|
4115
|
+
for (let j = 0; j < nodes.length; j++) {
|
|
4116
|
+
nextNodes.push(nodes[j]);
|
|
4117
|
+
}
|
|
4118
|
+
}
|
|
4119
|
+
nextNodes.push(container.endMarker);
|
|
4120
|
+
reconcileArrays(parent, prevNodes, nextNodes);
|
|
4121
|
+
container.currentNodes = nextNodes;
|
|
4122
|
+
container.nextNodes = prevNodes;
|
|
4123
|
+
}
|
|
4124
|
+
container.blocks = newBlocks;
|
|
4125
|
+
container.nextBlocks = oldBlocks;
|
|
4126
|
+
container.orderedBlocks = nextOrderedBlocks;
|
|
4127
|
+
container.nextOrderedBlocks = prevOrderedBlocks;
|
|
4128
|
+
});
|
|
4129
|
+
};
|
|
4130
|
+
const effectDispose = createRenderEffect(performDiff);
|
|
4131
|
+
return {
|
|
4132
|
+
marker: fragment,
|
|
4133
|
+
startMarker: container.startMarker,
|
|
4134
|
+
endMarker: container.endMarker,
|
|
4135
|
+
// Flush pending items - call after markers are inserted into DOM
|
|
4136
|
+
flush: () => {
|
|
4137
|
+
if (pendingItems !== null) {
|
|
4138
|
+
performDiff();
|
|
4139
|
+
}
|
|
4140
|
+
},
|
|
4141
|
+
dispose: () => {
|
|
4142
|
+
disposed = true;
|
|
4143
|
+
effectDispose?.();
|
|
4144
|
+
container.dispose();
|
|
4145
|
+
}
|
|
4146
|
+
};
|
|
4147
|
+
}
|
|
4148
|
+
export {
|
|
4149
|
+
$effect,
|
|
4150
|
+
$memo,
|
|
4151
|
+
$state,
|
|
4152
|
+
Aliases,
|
|
4153
|
+
BooleanAttributes,
|
|
4154
|
+
ChildProperties,
|
|
4155
|
+
DelegatedEvents,
|
|
4156
|
+
ErrorBoundary,
|
|
4157
|
+
Fragment,
|
|
4158
|
+
Properties,
|
|
4159
|
+
SVGElements,
|
|
4160
|
+
SVGNamespace,
|
|
4161
|
+
Suspense,
|
|
4162
|
+
UnitlessStyles,
|
|
4163
|
+
__fictPopContext,
|
|
4164
|
+
__fictProp,
|
|
4165
|
+
__fictPropsRest,
|
|
4166
|
+
__fictPushContext,
|
|
4167
|
+
__fictRender,
|
|
4168
|
+
__fictResetContext,
|
|
4169
|
+
__fictUseContext,
|
|
4170
|
+
__fictUseEffect,
|
|
4171
|
+
__fictUseMemo,
|
|
4172
|
+
__fictUseSignal,
|
|
4173
|
+
addEventListener,
|
|
4174
|
+
assign,
|
|
4175
|
+
batch2 as batch,
|
|
4176
|
+
bindAttribute,
|
|
4177
|
+
bindClass,
|
|
4178
|
+
bindEvent,
|
|
4179
|
+
bindProperty,
|
|
4180
|
+
bindRef,
|
|
4181
|
+
bindStyle,
|
|
4182
|
+
bindText,
|
|
4183
|
+
classList,
|
|
4184
|
+
clearDelegatedEvents,
|
|
4185
|
+
createAttributeBinding,
|
|
4186
|
+
createChildBinding,
|
|
4187
|
+
createClassBinding,
|
|
4188
|
+
createConditional,
|
|
4189
|
+
createEffect,
|
|
4190
|
+
createElement,
|
|
4191
|
+
createKeyedBlock,
|
|
4192
|
+
createKeyedList,
|
|
4193
|
+
createKeyedListContainer,
|
|
4194
|
+
createList,
|
|
4195
|
+
createMemo,
|
|
4196
|
+
createPortal,
|
|
4197
|
+
createPropsProxy,
|
|
4198
|
+
createRef,
|
|
4199
|
+
createRenderEffect,
|
|
4200
|
+
createRoot,
|
|
4201
|
+
createSelector,
|
|
4202
|
+
createShow,
|
|
4203
|
+
signal as createSignal,
|
|
4204
|
+
createStore,
|
|
4205
|
+
createStyleBinding,
|
|
4206
|
+
createSuspenseToken,
|
|
4207
|
+
createTextBinding,
|
|
4208
|
+
createVersionedSignal,
|
|
4209
|
+
delegateEvents,
|
|
4210
|
+
destroyMarkerBlock,
|
|
4211
|
+
getDevtoolsHook,
|
|
4212
|
+
getFirstNodeAfter,
|
|
4213
|
+
getPropAlias,
|
|
4214
|
+
insert,
|
|
4215
|
+
insertNodesBefore,
|
|
4216
|
+
isNodeBetweenMarkers,
|
|
4217
|
+
isReactive,
|
|
4218
|
+
mergeProps,
|
|
4219
|
+
moveMarkerBlock,
|
|
4220
|
+
moveNodesBefore,
|
|
4221
|
+
onCleanup,
|
|
4222
|
+
onDestroy,
|
|
4223
|
+
onMount,
|
|
4224
|
+
__fictProp as prop,
|
|
4225
|
+
reconcileArrays,
|
|
4226
|
+
removeNodes,
|
|
4227
|
+
render,
|
|
4228
|
+
setCycleProtectionOptions,
|
|
4229
|
+
spread,
|
|
4230
|
+
startTransition,
|
|
4231
|
+
template,
|
|
4232
|
+
toNodeArray,
|
|
4233
|
+
untrack2 as untrack,
|
|
4234
|
+
unwrap2 as unwrap,
|
|
4235
|
+
unwrapPrimitive,
|
|
4236
|
+
useDeferredValue,
|
|
4237
|
+
useProp,
|
|
4238
|
+
useTransition
|
|
4239
|
+
};
|
|
4240
|
+
//# sourceMappingURL=index.dev.js.map
|