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