what-core 0.8.4 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-AW3BAPIK.js +1685 -0
- package/dist/chunk-AW3BAPIK.js.map +7 -0
- package/dist/chunk-AZP2EOGX.js +188 -0
- package/dist/chunk-AZP2EOGX.js.map +7 -0
- package/dist/chunk-F2HUXI22.js +1675 -0
- package/dist/chunk-F2HUXI22.js.map +7 -0
- package/dist/chunk-KBM6CWG4.min.js +2 -0
- package/dist/chunk-KBM6CWG4.min.js.map +7 -0
- package/dist/chunk-KL7TNUIU.min.js +2 -0
- package/dist/chunk-KL7TNUIU.min.js.map +7 -0
- package/dist/chunk-L6XOF7P4.min.js +2 -0
- package/dist/chunk-L6XOF7P4.min.js.map +7 -0
- package/dist/chunk-M7UEET5O.js +1323 -0
- package/dist/chunk-M7UEET5O.js.map +7 -0
- package/dist/chunk-O3SKPRTY.min.js +2 -0
- package/dist/chunk-O3SKPRTY.min.js.map +7 -0
- package/dist/chunk-RN6QIBWL.min.js +2 -0
- package/dist/chunk-RN6QIBWL.min.js.map +7 -0
- package/dist/chunk-VMTTYB4L.min.js +2 -0
- package/dist/chunk-VMTTYB4L.min.js.map +7 -0
- package/dist/chunk-VP4WLF5A.js +1323 -0
- package/dist/chunk-VP4WLF5A.js.map +7 -0
- package/dist/chunk-YA3W4XKH.js +1323 -0
- package/dist/chunk-YA3W4XKH.js.map +7 -0
- package/dist/index.js +212 -2785
- package/dist/index.js.map +4 -4
- package/dist/index.min.js +6 -6
- package/dist/index.min.js.map +4 -4
- package/dist/jsx-dev-runtime.js +4 -53
- package/dist/jsx-dev-runtime.js.map +3 -3
- package/dist/jsx-dev-runtime.min.js +1 -1
- package/dist/jsx-dev-runtime.min.js.map +4 -4
- package/dist/jsx-runtime.js +4 -53
- package/dist/jsx-runtime.js.map +3 -3
- package/dist/jsx-runtime.min.js +1 -1
- package/dist/jsx-runtime.min.js.map +4 -4
- package/dist/render.js +22 -2044
- package/dist/render.js.map +4 -4
- package/dist/render.min.js +1 -1
- package/dist/render.min.js.map +4 -4
- package/dist/testing.js +13 -1079
- package/dist/testing.js.map +4 -4
- package/dist/testing.min.js +1 -1
- package/dist/testing.min.js.map +4 -4
- package/package.json +2 -2
- package/src/dom.js +54 -6
- package/src/h.js +15 -3
- package/src/head.js +72 -2
- package/src/hooks.js +65 -4
- package/src/hydration-data.js +34 -0
- package/src/index.js +9 -2
- package/src/reactive.js +78 -1
- package/src/render.js +450 -105
- package/src/server-context.js +48 -0
- package/src/store.js +6 -2
package/dist/index.js
CHANGED
|
@@ -1,2786 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
} finally {
|
|
74
|
-
if (__DEV__) insideComputed = prevInsideComputed;
|
|
75
|
-
}
|
|
76
|
-
}, true);
|
|
77
|
-
inner._level = 1;
|
|
78
|
-
inner._computed = true;
|
|
79
|
-
inner._computedSubs = subs;
|
|
80
|
-
subs._owner = inner;
|
|
81
|
-
inner._markDirty = () => {
|
|
82
|
-
dirty = true;
|
|
83
|
-
};
|
|
84
|
-
inner._isDirty = () => dirty;
|
|
85
|
-
function read() {
|
|
86
|
-
const ce = currentEffect;
|
|
87
|
-
if (ce !== null) {
|
|
88
|
-
if (ce !== lastTracked || ce._epoch !== lastTrackedEpoch) {
|
|
89
|
-
lastTracked = ce;
|
|
90
|
-
lastTrackedEpoch = ce._epoch;
|
|
91
|
-
subs.add(ce);
|
|
92
|
-
ce.deps.push(subs);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (dirty) _evaluateComputed(inner);
|
|
96
|
-
return value;
|
|
97
|
-
}
|
|
98
|
-
inner._onNotify = () => {
|
|
99
|
-
dirty = true;
|
|
100
|
-
lastTracked = null;
|
|
101
|
-
if (subs.size > 0) notify(subs);
|
|
102
|
-
};
|
|
103
|
-
read._signal = true;
|
|
104
|
-
read.peek = () => {
|
|
105
|
-
if (dirty) _evaluateComputed(inner);
|
|
106
|
-
return value;
|
|
107
|
-
};
|
|
108
|
-
return read;
|
|
109
|
-
}
|
|
110
|
-
function _evaluateComputed(computedEffect) {
|
|
111
|
-
if (iterativeEvalStack !== null) {
|
|
112
|
-
iterativeEvalStack.push(computedEffect);
|
|
113
|
-
throw NEEDS_UPSTREAM;
|
|
114
|
-
}
|
|
115
|
-
const stack = [computedEffect];
|
|
116
|
-
iterativeEvalStack = stack;
|
|
117
|
-
try {
|
|
118
|
-
while (stack.length > 0) {
|
|
119
|
-
const current = stack[stack.length - 1];
|
|
120
|
-
if (!current._isDirty || !current._isDirty()) {
|
|
121
|
-
stack.pop();
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
let pushedUpstream = false;
|
|
125
|
-
const deps = current.deps;
|
|
126
|
-
for (let i = 0; i < deps.length; i++) {
|
|
127
|
-
const depOwner = deps[i]._owner;
|
|
128
|
-
if (depOwner && depOwner._computed && depOwner._isDirty && depOwner._isDirty()) {
|
|
129
|
-
stack.push(depOwner);
|
|
130
|
-
pushedUpstream = true;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (pushedUpstream) {
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
const prevDepsLen = current.deps.length;
|
|
138
|
-
_runEffect(current);
|
|
139
|
-
if (current.deps.length !== prevDepsLen) {
|
|
140
|
-
_updateLevel(current);
|
|
141
|
-
}
|
|
142
|
-
stack.pop();
|
|
143
|
-
} catch (err) {
|
|
144
|
-
if (err === NEEDS_UPSTREAM) {
|
|
145
|
-
current._markDirty();
|
|
146
|
-
} else {
|
|
147
|
-
throw err;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
} finally {
|
|
152
|
-
iterativeEvalStack = null;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
function _updateLevel(e) {
|
|
156
|
-
let maxDepLevel = 0;
|
|
157
|
-
const deps = e.deps;
|
|
158
|
-
for (let i = 0; i < deps.length; i++) {
|
|
159
|
-
const owner = deps[i]._owner;
|
|
160
|
-
if (owner) {
|
|
161
|
-
const depLevel = owner._level;
|
|
162
|
-
if (depLevel > maxDepLevel) maxDepLevel = depLevel;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
e._level = maxDepLevel + 1;
|
|
166
|
-
}
|
|
167
|
-
function effect(fn, opts) {
|
|
168
|
-
const e = _createEffect(fn);
|
|
169
|
-
e._level = 1;
|
|
170
|
-
const prev = currentEffect;
|
|
171
|
-
currentEffect = e;
|
|
172
|
-
try {
|
|
173
|
-
const result = e.fn();
|
|
174
|
-
if (typeof result === "function") e._cleanup = result;
|
|
175
|
-
} finally {
|
|
176
|
-
currentEffect = prev;
|
|
177
|
-
}
|
|
178
|
-
_updateLevel(e);
|
|
179
|
-
if (opts?.stable) e._stable = true;
|
|
180
|
-
const dispose = () => _disposeEffect(e);
|
|
181
|
-
if (currentRoot) {
|
|
182
|
-
currentRoot.disposals.push(dispose);
|
|
183
|
-
}
|
|
184
|
-
return dispose;
|
|
185
|
-
}
|
|
186
|
-
function batch(fn) {
|
|
187
|
-
batchDepth++;
|
|
188
|
-
try {
|
|
189
|
-
fn();
|
|
190
|
-
} finally {
|
|
191
|
-
batchDepth--;
|
|
192
|
-
if (batchDepth === 0) flush();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
function _createEffect(fn, lazy2) {
|
|
196
|
-
const e = {
|
|
197
|
-
fn,
|
|
198
|
-
deps: [],
|
|
199
|
-
// array of subscriber sets (cheaper than Set for typical 1-3 deps)
|
|
200
|
-
lazy: lazy2 || false,
|
|
201
|
-
_onNotify: null,
|
|
202
|
-
disposed: false,
|
|
203
|
-
_pending: false,
|
|
204
|
-
_stable: false,
|
|
205
|
-
// stable effects skip cleanup/re-subscribe on re-run
|
|
206
|
-
_level: 0,
|
|
207
|
-
// topological depth: signals=0, computed/effects=max(deps)+1
|
|
208
|
-
_computed: false,
|
|
209
|
-
// true for computed inner effects
|
|
210
|
-
_computedSubs: null,
|
|
211
|
-
// reference to the computed's subscriber set
|
|
212
|
-
_isDirty: null,
|
|
213
|
-
// function to check if computed is dirty (set by computed())
|
|
214
|
-
_markDirty: null,
|
|
215
|
-
// function to mark computed dirty (set by computed())
|
|
216
|
-
_cleanup: null,
|
|
217
|
-
// cleanup function returned by effect fn (declared upfront for shape)
|
|
218
|
-
_epoch: 0
|
|
219
|
-
// incremented on cleanup — used by signal lastTracked cache
|
|
220
|
-
};
|
|
221
|
-
if (__DEV__ && __devtools) __devtools.onEffectCreate(e);
|
|
222
|
-
return e;
|
|
223
|
-
}
|
|
224
|
-
function _runEffect(e) {
|
|
225
|
-
if (e.disposed) return;
|
|
226
|
-
if (e._stable) {
|
|
227
|
-
if (e._cleanup) {
|
|
228
|
-
try {
|
|
229
|
-
e._cleanup();
|
|
230
|
-
} catch (err) {
|
|
231
|
-
if (__DEV__) console.warn("[what] Error in effect cleanup:", err);
|
|
232
|
-
}
|
|
233
|
-
e._cleanup = null;
|
|
234
|
-
}
|
|
235
|
-
const prev2 = currentEffect;
|
|
236
|
-
currentEffect = null;
|
|
237
|
-
try {
|
|
238
|
-
const result = e.fn();
|
|
239
|
-
if (typeof result === "function") e._cleanup = result;
|
|
240
|
-
} catch (err) {
|
|
241
|
-
if (__devtools?.onError) __devtools.onError(err, { type: "effect", effect: e });
|
|
242
|
-
if (__DEV__) console.warn("[what] Error in stable effect:", err);
|
|
243
|
-
} finally {
|
|
244
|
-
currentEffect = prev2;
|
|
245
|
-
}
|
|
246
|
-
if (__DEV__ && __devtools?.onEffectRun) __devtools.onEffectRun(e);
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
const singleDep = e.deps.length === 1 ? e.deps[0] : null;
|
|
250
|
-
cleanup(e);
|
|
251
|
-
if (e._cleanup) {
|
|
252
|
-
try {
|
|
253
|
-
e._cleanup();
|
|
254
|
-
} catch (err) {
|
|
255
|
-
if (__DEV__ && __devtools?.onError) __devtools.onError(err, { type: "effect-cleanup", effect: e });
|
|
256
|
-
if (__DEV__) console.warn("[what] Error in effect cleanup:", err);
|
|
257
|
-
}
|
|
258
|
-
e._cleanup = null;
|
|
259
|
-
}
|
|
260
|
-
const prev = currentEffect;
|
|
261
|
-
currentEffect = e;
|
|
262
|
-
try {
|
|
263
|
-
const result = e.fn();
|
|
264
|
-
if (typeof result === "function") {
|
|
265
|
-
e._cleanup = result;
|
|
266
|
-
}
|
|
267
|
-
} catch (err) {
|
|
268
|
-
if (err === NEEDS_UPSTREAM) throw err;
|
|
269
|
-
if (__DEV__ && __devtools?.onError) __devtools.onError(err, { type: "effect", effect: e });
|
|
270
|
-
throw err;
|
|
271
|
-
} finally {
|
|
272
|
-
currentEffect = prev;
|
|
273
|
-
}
|
|
274
|
-
if (singleDep !== null && e.deps.length === 1 && e.deps[0] === singleDep && !e._cleanup && !e._pending) {
|
|
275
|
-
e._stable = true;
|
|
276
|
-
}
|
|
277
|
-
if (__DEV__ && __devtools?.onEffectRun) __devtools.onEffectRun(e);
|
|
278
|
-
}
|
|
279
|
-
function _disposeEffect(e) {
|
|
280
|
-
e.disposed = true;
|
|
281
|
-
if (__DEV__ && __devtools) __devtools.onEffectDispose(e);
|
|
282
|
-
cleanup(e);
|
|
283
|
-
if (e._cleanup) {
|
|
284
|
-
try {
|
|
285
|
-
e._cleanup();
|
|
286
|
-
} catch (err) {
|
|
287
|
-
if (__DEV__) console.warn("[what] Error in effect cleanup on dispose:", err);
|
|
288
|
-
}
|
|
289
|
-
e._cleanup = null;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
function cleanup(e) {
|
|
293
|
-
const deps = e.deps;
|
|
294
|
-
for (let i = 0; i < deps.length; i++) deps[i].delete(e);
|
|
295
|
-
deps.length = 0;
|
|
296
|
-
e._epoch++;
|
|
297
|
-
}
|
|
298
|
-
var notifyDepth = 0;
|
|
299
|
-
var notifyQueue = null;
|
|
300
|
-
var notifyQueueLen = 0;
|
|
301
|
-
function _processSubscriber(e) {
|
|
302
|
-
if (e.disposed) return;
|
|
303
|
-
if (e._onNotify) {
|
|
304
|
-
e._onNotify();
|
|
305
|
-
} else if (!e._pending) {
|
|
306
|
-
if (batchDepth === 0 && e._stable) {
|
|
307
|
-
const prev = currentEffect;
|
|
308
|
-
currentEffect = null;
|
|
309
|
-
try {
|
|
310
|
-
const result = e.fn();
|
|
311
|
-
if (typeof result === "function") {
|
|
312
|
-
if (e._cleanup) try {
|
|
313
|
-
e._cleanup();
|
|
314
|
-
} catch (err) {
|
|
315
|
-
}
|
|
316
|
-
e._cleanup = result;
|
|
317
|
-
}
|
|
318
|
-
} catch (err) {
|
|
319
|
-
if (__DEV__ && __devtools?.onError) __devtools.onError(err, { type: "effect", effect: e });
|
|
320
|
-
if (__DEV__) console.warn("[what] Error in stable effect:", err);
|
|
321
|
-
} finally {
|
|
322
|
-
currentEffect = prev;
|
|
323
|
-
}
|
|
324
|
-
} else {
|
|
325
|
-
e._pending = true;
|
|
326
|
-
const level = e._level;
|
|
327
|
-
const len = pendingEffects.length;
|
|
328
|
-
if (len > 0 && pendingEffects[len - 1]._level > level) {
|
|
329
|
-
pendingNeedSort = true;
|
|
330
|
-
}
|
|
331
|
-
pendingEffects.push(e);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
function notify(subs) {
|
|
336
|
-
if (notifyDepth === 0) {
|
|
337
|
-
notifyDepth = 1;
|
|
338
|
-
try {
|
|
339
|
-
for (const e of subs) {
|
|
340
|
-
_processSubscriber(e);
|
|
341
|
-
}
|
|
342
|
-
if (notifyQueueLen > 0) {
|
|
343
|
-
let qi = 0;
|
|
344
|
-
while (qi < notifyQueueLen) {
|
|
345
|
-
const queuedSubs = notifyQueue[qi];
|
|
346
|
-
notifyQueue[qi] = null;
|
|
347
|
-
qi++;
|
|
348
|
-
for (const e of queuedSubs) {
|
|
349
|
-
_processSubscriber(e);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
notifyQueueLen = 0;
|
|
353
|
-
}
|
|
354
|
-
} finally {
|
|
355
|
-
notifyDepth = 0;
|
|
356
|
-
}
|
|
357
|
-
if (batchDepth === 0 && pendingEffects.length > 0) scheduleMicrotask();
|
|
358
|
-
} else {
|
|
359
|
-
if (notifyQueue === null) notifyQueue = [];
|
|
360
|
-
if (notifyQueueLen >= notifyQueue.length) {
|
|
361
|
-
notifyQueue.push(subs);
|
|
362
|
-
} else {
|
|
363
|
-
notifyQueue[notifyQueueLen] = subs;
|
|
364
|
-
}
|
|
365
|
-
notifyQueueLen++;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
var microtaskScheduled = false;
|
|
369
|
-
function scheduleMicrotask() {
|
|
370
|
-
if (!microtaskScheduled) {
|
|
371
|
-
microtaskScheduled = true;
|
|
372
|
-
queueMicrotask(() => {
|
|
373
|
-
microtaskScheduled = false;
|
|
374
|
-
flush();
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
var isFlushing = false;
|
|
379
|
-
function flush() {
|
|
380
|
-
if (isFlushing) return;
|
|
381
|
-
isFlushing = true;
|
|
382
|
-
try {
|
|
383
|
-
let iterations = 0;
|
|
384
|
-
while (pendingEffects.length > 0 && iterations < 25) {
|
|
385
|
-
const batch2 = pendingEffects;
|
|
386
|
-
pendingEffects = [];
|
|
387
|
-
if (batch2.length > 1 && pendingNeedSort) {
|
|
388
|
-
batch2.sort((a, b) => a._level - b._level);
|
|
389
|
-
}
|
|
390
|
-
pendingNeedSort = false;
|
|
391
|
-
for (let i = 0; i < batch2.length; i++) {
|
|
392
|
-
const e = batch2[i];
|
|
393
|
-
e._pending = false;
|
|
394
|
-
if (!e.disposed && !e._onNotify) {
|
|
395
|
-
const prevDepsLen = e.deps.length;
|
|
396
|
-
_runEffect(e);
|
|
397
|
-
if (!e._computed && e.deps.length !== prevDepsLen) {
|
|
398
|
-
_updateLevel(e);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
iterations++;
|
|
403
|
-
}
|
|
404
|
-
if (iterations >= 25) {
|
|
405
|
-
if (__DEV__) {
|
|
406
|
-
const remaining = pendingEffects.slice(0, 3);
|
|
407
|
-
const effectNames = remaining.map((e) => e.fn?.name || e.fn?.toString().slice(0, 60) || "(anonymous)");
|
|
408
|
-
console.warn(
|
|
409
|
-
`[what] Possible infinite effect loop detected (25 iterations). Likely cause: an effect writes to a signal it also reads, creating a cycle. Use untrack() to read signals without subscribing. Looping effects: ${effectNames.join(", ")}`
|
|
410
|
-
);
|
|
411
|
-
} else {
|
|
412
|
-
console.warn("[what] Possible infinite effect loop detected");
|
|
413
|
-
}
|
|
414
|
-
for (let i = 0; i < pendingEffects.length; i++) pendingEffects[i]._pending = false;
|
|
415
|
-
pendingEffects.length = 0;
|
|
416
|
-
}
|
|
417
|
-
} finally {
|
|
418
|
-
isFlushing = false;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
function memo(fn) {
|
|
422
|
-
let value;
|
|
423
|
-
const subs = /* @__PURE__ */ new Set();
|
|
424
|
-
const e = _createEffect(() => {
|
|
425
|
-
const next = fn();
|
|
426
|
-
if (!Object.is(value, next)) {
|
|
427
|
-
value = next;
|
|
428
|
-
for (const sub of subs) {
|
|
429
|
-
if (sub.disposed) continue;
|
|
430
|
-
if (sub._onNotify) {
|
|
431
|
-
sub._onNotify();
|
|
432
|
-
} else if (!sub._pending) {
|
|
433
|
-
sub._pending = true;
|
|
434
|
-
const level = sub._level;
|
|
435
|
-
const len = pendingEffects.length;
|
|
436
|
-
if (len > 0 && pendingEffects[len - 1]._level > level) {
|
|
437
|
-
pendingNeedSort = true;
|
|
438
|
-
}
|
|
439
|
-
pendingEffects.push(sub);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
e._level = 1;
|
|
445
|
-
_runEffect(e);
|
|
446
|
-
_updateLevel(e);
|
|
447
|
-
subs._owner = e;
|
|
448
|
-
if (currentRoot) {
|
|
449
|
-
currentRoot.disposals.push(() => _disposeEffect(e));
|
|
450
|
-
}
|
|
451
|
-
function read() {
|
|
452
|
-
if (currentEffect) {
|
|
453
|
-
subs.add(currentEffect);
|
|
454
|
-
currentEffect.deps.push(subs);
|
|
455
|
-
}
|
|
456
|
-
return value;
|
|
457
|
-
}
|
|
458
|
-
read._signal = true;
|
|
459
|
-
read.peek = () => value;
|
|
460
|
-
return read;
|
|
461
|
-
}
|
|
462
|
-
function flushSync() {
|
|
463
|
-
if (isFlushing) {
|
|
464
|
-
if (__DEV__) {
|
|
465
|
-
console.warn(
|
|
466
|
-
"[what] flushSync() called during an active flush (e.g., inside a component render or effect). This is a no-op to prevent infinite loops. Move flushSync() to an event handler or onMount callback."
|
|
467
|
-
);
|
|
468
|
-
}
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
if (currentEffect) {
|
|
472
|
-
if (__DEV__) {
|
|
473
|
-
console.warn(
|
|
474
|
-
"[what] flushSync() called during effect execution. This is a no-op to prevent infinite loops. Move flushSync() to an event handler or onMount callback."
|
|
475
|
-
);
|
|
476
|
-
}
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
microtaskScheduled = false;
|
|
480
|
-
flush();
|
|
481
|
-
}
|
|
482
|
-
function untrack(fn) {
|
|
483
|
-
const prev = currentEffect;
|
|
484
|
-
currentEffect = null;
|
|
485
|
-
try {
|
|
486
|
-
return fn();
|
|
487
|
-
} finally {
|
|
488
|
-
currentEffect = prev;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
function getOwner() {
|
|
492
|
-
return currentOwner;
|
|
493
|
-
}
|
|
494
|
-
function runWithOwner(owner, fn) {
|
|
495
|
-
const prev = currentOwner;
|
|
496
|
-
const prevRoot = currentRoot;
|
|
497
|
-
currentOwner = owner;
|
|
498
|
-
currentRoot = owner;
|
|
499
|
-
try {
|
|
500
|
-
return fn();
|
|
501
|
-
} finally {
|
|
502
|
-
currentOwner = prev;
|
|
503
|
-
currentRoot = prevRoot;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
function createRoot(fn) {
|
|
507
|
-
const prevRoot = currentRoot;
|
|
508
|
-
const prevOwner = currentOwner;
|
|
509
|
-
const root = {
|
|
510
|
-
disposals: [],
|
|
511
|
-
owner: currentOwner,
|
|
512
|
-
// parent owner for ownership tree
|
|
513
|
-
children: [],
|
|
514
|
-
// child roots (ownership tree)
|
|
515
|
-
_disposed: false
|
|
516
|
-
};
|
|
517
|
-
if (currentOwner) {
|
|
518
|
-
currentOwner.children.push(root);
|
|
519
|
-
}
|
|
520
|
-
currentRoot = root;
|
|
521
|
-
currentOwner = root;
|
|
522
|
-
try {
|
|
523
|
-
const dispose = () => {
|
|
524
|
-
if (root._disposed) return;
|
|
525
|
-
root._disposed = true;
|
|
526
|
-
for (let i = root.children.length - 1; i >= 0; i--) {
|
|
527
|
-
_disposeRoot(root.children[i]);
|
|
528
|
-
}
|
|
529
|
-
root.children.length = 0;
|
|
530
|
-
for (let i = root.disposals.length - 1; i >= 0; i--) {
|
|
531
|
-
root.disposals[i]();
|
|
532
|
-
}
|
|
533
|
-
root.disposals.length = 0;
|
|
534
|
-
if (root.owner) {
|
|
535
|
-
const idx = root.owner.children.indexOf(root);
|
|
536
|
-
if (idx >= 0) root.owner.children.splice(idx, 1);
|
|
537
|
-
}
|
|
538
|
-
};
|
|
539
|
-
return fn(dispose);
|
|
540
|
-
} finally {
|
|
541
|
-
currentRoot = prevRoot;
|
|
542
|
-
currentOwner = prevOwner;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
function _disposeRoot(root) {
|
|
546
|
-
if (root._disposed) return;
|
|
547
|
-
root._disposed = true;
|
|
548
|
-
for (let i = root.children.length - 1; i >= 0; i--) {
|
|
549
|
-
_disposeRoot(root.children[i]);
|
|
550
|
-
}
|
|
551
|
-
root.children.length = 0;
|
|
552
|
-
for (let i = root.disposals.length - 1; i >= 0; i--) {
|
|
553
|
-
root.disposals[i]();
|
|
554
|
-
}
|
|
555
|
-
root.disposals.length = 0;
|
|
556
|
-
}
|
|
557
|
-
function _createItemScope(fn) {
|
|
558
|
-
const prevRoot = currentRoot;
|
|
559
|
-
const prevOwner = currentOwner;
|
|
560
|
-
const scope = {
|
|
561
|
-
disposals: [],
|
|
562
|
-
owner: null,
|
|
563
|
-
// No parent registration
|
|
564
|
-
children: [],
|
|
565
|
-
// Kept for compat with effects that create sub-roots
|
|
566
|
-
_disposed: false
|
|
567
|
-
};
|
|
568
|
-
currentRoot = scope;
|
|
569
|
-
currentOwner = scope;
|
|
570
|
-
try {
|
|
571
|
-
const dispose = () => {
|
|
572
|
-
if (scope._disposed) return;
|
|
573
|
-
scope._disposed = true;
|
|
574
|
-
for (let i = scope.children.length - 1; i >= 0; i--) {
|
|
575
|
-
_disposeRoot(scope.children[i]);
|
|
576
|
-
}
|
|
577
|
-
scope.children.length = 0;
|
|
578
|
-
for (let i = scope.disposals.length - 1; i >= 0; i--) {
|
|
579
|
-
scope.disposals[i]();
|
|
580
|
-
}
|
|
581
|
-
scope.disposals.length = 0;
|
|
582
|
-
};
|
|
583
|
-
return fn(dispose);
|
|
584
|
-
} finally {
|
|
585
|
-
currentRoot = prevRoot;
|
|
586
|
-
currentOwner = prevOwner;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
function onCleanup(fn) {
|
|
590
|
-
if (currentRoot) {
|
|
591
|
-
currentRoot.disposals.push(fn);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
// packages/core/src/h.js
|
|
596
|
-
var EMPTY_OBJ = /* @__PURE__ */ Object.create(null);
|
|
597
|
-
var EMPTY_ARR = [];
|
|
598
|
-
function h(tag, props) {
|
|
599
|
-
props = props || EMPTY_OBJ;
|
|
600
|
-
const argLen = arguments.length;
|
|
601
|
-
let flat;
|
|
602
|
-
if (argLen <= 2) {
|
|
603
|
-
flat = EMPTY_ARR;
|
|
604
|
-
} else if (argLen === 3) {
|
|
605
|
-
flat = _flattenSingle(arguments[2]);
|
|
606
|
-
} else {
|
|
607
|
-
const out = [];
|
|
608
|
-
for (let i = 2; i < argLen; i++) {
|
|
609
|
-
_flattenInto(arguments[i], out);
|
|
610
|
-
}
|
|
611
|
-
flat = out;
|
|
612
|
-
}
|
|
613
|
-
const key = props.key ?? null;
|
|
614
|
-
if (props.key !== void 0) {
|
|
615
|
-
props = { ...props };
|
|
616
|
-
delete props.key;
|
|
617
|
-
}
|
|
618
|
-
return { tag, props, children: flat, key, _vnode: true };
|
|
619
|
-
}
|
|
620
|
-
function Fragment({ children }) {
|
|
621
|
-
return children;
|
|
622
|
-
}
|
|
623
|
-
function _flattenSingle(child) {
|
|
624
|
-
if (child == null || child === false || child === true) return EMPTY_ARR;
|
|
625
|
-
if (Array.isArray(child)) {
|
|
626
|
-
const out = [];
|
|
627
|
-
_flattenInto(child, out);
|
|
628
|
-
return out;
|
|
629
|
-
}
|
|
630
|
-
if (typeof child === "object" && child._vnode) return [child];
|
|
631
|
-
if (typeof child === "function") return [child];
|
|
632
|
-
return [String(child)];
|
|
633
|
-
}
|
|
634
|
-
function _flattenInto(child, out) {
|
|
635
|
-
if (child == null || child === false || child === true) return;
|
|
636
|
-
if (Array.isArray(child)) {
|
|
637
|
-
for (let i = 0; i < child.length; i++) {
|
|
638
|
-
_flattenInto(child[i], out);
|
|
639
|
-
}
|
|
640
|
-
} else if (typeof child === "object" && child._vnode) {
|
|
641
|
-
out.push(child);
|
|
642
|
-
} else if (typeof child === "function") {
|
|
643
|
-
out.push(child);
|
|
644
|
-
} else {
|
|
645
|
-
out.push(String(child));
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
function html(strings, ...values) {
|
|
649
|
-
const src = strings.reduce((acc, str, i) => acc + str + (i < values.length ? `\0${i}\0` : ""), "");
|
|
650
|
-
return parseTemplate(src, values);
|
|
651
|
-
}
|
|
652
|
-
function parseTemplate(src, values) {
|
|
653
|
-
src = src.trim();
|
|
654
|
-
const nodes = [];
|
|
655
|
-
let i = 0;
|
|
656
|
-
while (i < src.length) {
|
|
657
|
-
if (src[i] === "<") {
|
|
658
|
-
const result2 = parseElement(src, i, values);
|
|
659
|
-
if (result2) {
|
|
660
|
-
nodes.push(result2.node);
|
|
661
|
-
i = result2.end;
|
|
662
|
-
continue;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
const result = parseText(src, i, values);
|
|
666
|
-
if (result.text) nodes.push(result.text);
|
|
667
|
-
i = result.end;
|
|
668
|
-
}
|
|
669
|
-
return nodes.length === 1 ? nodes[0] : nodes;
|
|
670
|
-
}
|
|
671
|
-
function parseElement(src, start, values) {
|
|
672
|
-
const openMatch = src.slice(start).match(/^<([a-zA-Z][a-zA-Z0-9-]*|[A-Z]\w*)/);
|
|
673
|
-
if (!openMatch) return null;
|
|
674
|
-
const tag = openMatch[1];
|
|
675
|
-
let i = start + openMatch[0].length;
|
|
676
|
-
const props = {};
|
|
677
|
-
while (i < src.length) {
|
|
678
|
-
while (i < src.length && /\s/.test(src[i])) i++;
|
|
679
|
-
if (src.slice(i, i + 2) === "/>") {
|
|
680
|
-
return { node: h(tag, Object.keys(props).length ? props : null), end: i + 2 };
|
|
681
|
-
}
|
|
682
|
-
if (src[i] === ">") {
|
|
683
|
-
i++;
|
|
684
|
-
break;
|
|
685
|
-
}
|
|
686
|
-
if (src.slice(i, i + 3) === "...") {
|
|
687
|
-
const placeholder = src.slice(i + 3).match(/^\x00(\d+)\x00/);
|
|
688
|
-
if (placeholder) {
|
|
689
|
-
Object.assign(props, values[Number(placeholder[1])]);
|
|
690
|
-
i += 3 + placeholder[0].length;
|
|
691
|
-
continue;
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
const attrMatch = src.slice(i).match(/^([a-zA-Z_@:][a-zA-Z0-9_:.-]*)/);
|
|
695
|
-
if (!attrMatch) break;
|
|
696
|
-
const attrName = attrMatch[1];
|
|
697
|
-
i += attrMatch[0].length;
|
|
698
|
-
while (i < src.length && /\s/.test(src[i])) i++;
|
|
699
|
-
if (src[i] === "=") {
|
|
700
|
-
i++;
|
|
701
|
-
while (i < src.length && /\s/.test(src[i])) i++;
|
|
702
|
-
const ph = src.slice(i).match(/^\x00(\d+)\x00/);
|
|
703
|
-
if (ph) {
|
|
704
|
-
props[attrName] = values[Number(ph[1])];
|
|
705
|
-
i += ph[0].length;
|
|
706
|
-
} else if (src[i] === '"' || src[i] === "'") {
|
|
707
|
-
const q = src[i];
|
|
708
|
-
i++;
|
|
709
|
-
let val = "";
|
|
710
|
-
while (i < src.length && src[i] !== q) {
|
|
711
|
-
const tph = src.slice(i).match(/^\x00(\d+)\x00/);
|
|
712
|
-
if (tph) {
|
|
713
|
-
val += String(values[Number(tph[1])]);
|
|
714
|
-
i += tph[0].length;
|
|
715
|
-
} else {
|
|
716
|
-
val += src[i];
|
|
717
|
-
i++;
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
i++;
|
|
721
|
-
props[attrName] = val;
|
|
722
|
-
}
|
|
723
|
-
} else {
|
|
724
|
-
props[attrName] = true;
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
const children = [];
|
|
728
|
-
const closeTag = `</${tag}>`;
|
|
729
|
-
while (i < src.length) {
|
|
730
|
-
if (src.slice(i, i + closeTag.length) === closeTag) {
|
|
731
|
-
i += closeTag.length;
|
|
732
|
-
break;
|
|
733
|
-
}
|
|
734
|
-
if (src[i] === "<") {
|
|
735
|
-
const child = parseElement(src, i, values);
|
|
736
|
-
if (child) {
|
|
737
|
-
children.push(child.node);
|
|
738
|
-
i = child.end;
|
|
739
|
-
continue;
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
const text = parseText(src, i, values);
|
|
743
|
-
if (text.text != null) children.push(text.text);
|
|
744
|
-
i = text.end;
|
|
745
|
-
}
|
|
746
|
-
return {
|
|
747
|
-
node: h(tag, Object.keys(props).length ? props : null, ...children),
|
|
748
|
-
end: i
|
|
749
|
-
};
|
|
750
|
-
}
|
|
751
|
-
function parseText(src, start, values) {
|
|
752
|
-
let i = start;
|
|
753
|
-
let text = "";
|
|
754
|
-
while (i < src.length && src[i] !== "<") {
|
|
755
|
-
const ph = src.slice(i).match(/^\x00(\d+)\x00/);
|
|
756
|
-
if (ph) {
|
|
757
|
-
if (text.trim()) {
|
|
758
|
-
return { text: text.trim(), end: i };
|
|
759
|
-
}
|
|
760
|
-
return { text: values[Number(ph[1])], end: i + ph[0].length };
|
|
761
|
-
}
|
|
762
|
-
text += src[i];
|
|
763
|
-
i++;
|
|
764
|
-
}
|
|
765
|
-
return { text: text.trim() || null, end: i };
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
// packages/core/src/components.js
|
|
769
|
-
function memo2(Component, _areEqual) {
|
|
770
|
-
const MemoWrapper = function MemoWrapper2(props) {
|
|
771
|
-
return Component(props);
|
|
772
|
-
};
|
|
773
|
-
MemoWrapper.displayName = `Memo(${Component.name || "Anonymous"})`;
|
|
774
|
-
return MemoWrapper;
|
|
775
|
-
}
|
|
776
|
-
var _getCurrentComponent = null;
|
|
777
|
-
function _injectGetCurrentComponent(fn) {
|
|
778
|
-
_getCurrentComponent = fn;
|
|
779
|
-
}
|
|
780
|
-
function lazy(loader) {
|
|
781
|
-
let Component = null;
|
|
782
|
-
let loadPromise = null;
|
|
783
|
-
let loadError = null;
|
|
784
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
785
|
-
function LazyWrapper(props) {
|
|
786
|
-
if (loadError) throw loadError;
|
|
787
|
-
if (Component) return h(Component, props);
|
|
788
|
-
if (!loadPromise) {
|
|
789
|
-
loadPromise = loader().then((mod) => {
|
|
790
|
-
Component = mod.default || mod;
|
|
791
|
-
listeners.forEach((fn) => fn());
|
|
792
|
-
listeners.clear();
|
|
793
|
-
}).catch((err) => {
|
|
794
|
-
loadError = err;
|
|
795
|
-
});
|
|
796
|
-
}
|
|
797
|
-
throw loadPromise;
|
|
798
|
-
}
|
|
799
|
-
LazyWrapper.displayName = "Lazy";
|
|
800
|
-
LazyWrapper._lazy = true;
|
|
801
|
-
LazyWrapper._onLoad = (fn) => {
|
|
802
|
-
if (Component) fn();
|
|
803
|
-
else listeners.add(fn);
|
|
804
|
-
};
|
|
805
|
-
return LazyWrapper;
|
|
806
|
-
}
|
|
807
|
-
function Suspense({ fallback, children }) {
|
|
808
|
-
const loading = signal(false);
|
|
809
|
-
const pendingPromises = /* @__PURE__ */ new Set();
|
|
810
|
-
const boundary = {
|
|
811
|
-
_suspense: true,
|
|
812
|
-
onSuspend(promise) {
|
|
813
|
-
loading.set(true);
|
|
814
|
-
pendingPromises.add(promise);
|
|
815
|
-
promise.finally(() => {
|
|
816
|
-
pendingPromises.delete(promise);
|
|
817
|
-
if (pendingPromises.size === 0) {
|
|
818
|
-
loading.set(false);
|
|
819
|
-
}
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
};
|
|
823
|
-
return {
|
|
824
|
-
tag: "__suspense",
|
|
825
|
-
props: { boundary, fallback, loading },
|
|
826
|
-
children: Array.isArray(children) ? children : [children],
|
|
827
|
-
_vnode: true
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
function ErrorBoundary({ fallback, children, onError }) {
|
|
831
|
-
const errorState = signal(null);
|
|
832
|
-
const handleError = (error) => {
|
|
833
|
-
errorState.set(error);
|
|
834
|
-
if (onError) {
|
|
835
|
-
try {
|
|
836
|
-
onError(error);
|
|
837
|
-
} catch (e) {
|
|
838
|
-
console.error("Error in onError handler:", e);
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
const reset = () => errorState.set(null);
|
|
843
|
-
return {
|
|
844
|
-
tag: "__errorBoundary",
|
|
845
|
-
props: { errorState, handleError, fallback, reset },
|
|
846
|
-
children: Array.isArray(children) ? children : [children],
|
|
847
|
-
_vnode: true
|
|
848
|
-
};
|
|
849
|
-
}
|
|
850
|
-
function reportError(error, startCtx) {
|
|
851
|
-
let ctx = startCtx || _getCurrentComponent?.();
|
|
852
|
-
while (ctx) {
|
|
853
|
-
if (ctx._errorBoundary) {
|
|
854
|
-
ctx._errorBoundary(error);
|
|
855
|
-
return true;
|
|
856
|
-
}
|
|
857
|
-
ctx = ctx._parentCtx;
|
|
858
|
-
}
|
|
859
|
-
return false;
|
|
860
|
-
}
|
|
861
|
-
function Show({ when, fallback = null, children }) {
|
|
862
|
-
const condition = typeof when === "function" ? when() : when;
|
|
863
|
-
return condition ? children : fallback;
|
|
864
|
-
}
|
|
865
|
-
function For({ each: each2, fallback = null, children }) {
|
|
866
|
-
const list = typeof each2 === "function" ? each2() : each2;
|
|
867
|
-
if (!list || list.length === 0) return fallback;
|
|
868
|
-
const renderFn = Array.isArray(children) ? children[0] : children;
|
|
869
|
-
if (typeof renderFn !== "function") {
|
|
870
|
-
console.warn("[what] For: children must be a render function, e.g. <For each={items}>{(item) => ...}</For>");
|
|
871
|
-
return fallback;
|
|
872
|
-
}
|
|
873
|
-
return list.map((item, index) => {
|
|
874
|
-
const vnode = renderFn(item, index);
|
|
875
|
-
if (vnode && typeof vnode === "object" && vnode.key == null) {
|
|
876
|
-
if (item != null && typeof item === "object") {
|
|
877
|
-
if (item.id != null) vnode.key = item.id;
|
|
878
|
-
else if (item.key != null) vnode.key = item.key;
|
|
879
|
-
} else if (typeof item === "string" || typeof item === "number") {
|
|
880
|
-
vnode.key = item;
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
return vnode;
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
function Switch({ fallback = null, children }) {
|
|
887
|
-
const kids = Array.isArray(children) ? children : [children];
|
|
888
|
-
for (const child of kids) {
|
|
889
|
-
if (child && child.tag === Match) {
|
|
890
|
-
const condition = typeof child.props.when === "function" ? child.props.when() : child.props.when;
|
|
891
|
-
if (condition) {
|
|
892
|
-
return child.children;
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
return fallback;
|
|
897
|
-
}
|
|
898
|
-
function Match({ when, children }) {
|
|
899
|
-
return { tag: Match, props: { when }, children, _vnode: true };
|
|
900
|
-
}
|
|
901
|
-
function Island({ component: Component, mode, mediaQuery, ...props }) {
|
|
902
|
-
const placeholder = h("div", { "data-island": Component.name || "Island", "data-hydrate": mode });
|
|
903
|
-
const wrapper = signal(null);
|
|
904
|
-
const hydrated = signal(false);
|
|
905
|
-
function doHydrate() {
|
|
906
|
-
if (hydrated()) return;
|
|
907
|
-
hydrated.set(true);
|
|
908
|
-
wrapper.set(h(Component, props));
|
|
909
|
-
}
|
|
910
|
-
function scheduleHydration(el) {
|
|
911
|
-
switch (mode) {
|
|
912
|
-
case "load":
|
|
913
|
-
queueMicrotask(doHydrate);
|
|
914
|
-
break;
|
|
915
|
-
case "idle":
|
|
916
|
-
if (typeof requestIdleCallback !== "undefined") {
|
|
917
|
-
requestIdleCallback(doHydrate);
|
|
918
|
-
} else {
|
|
919
|
-
setTimeout(doHydrate, 200);
|
|
920
|
-
}
|
|
921
|
-
break;
|
|
922
|
-
case "visible": {
|
|
923
|
-
const observer = new IntersectionObserver((entries) => {
|
|
924
|
-
if (entries[0].isIntersecting) {
|
|
925
|
-
observer.disconnect();
|
|
926
|
-
doHydrate();
|
|
927
|
-
}
|
|
928
|
-
});
|
|
929
|
-
observer.observe(el);
|
|
930
|
-
break;
|
|
931
|
-
}
|
|
932
|
-
case "interaction": {
|
|
933
|
-
const hydrate2 = () => {
|
|
934
|
-
el.removeEventListener("click", hydrate2);
|
|
935
|
-
el.removeEventListener("focus", hydrate2);
|
|
936
|
-
el.removeEventListener("mouseenter", hydrate2);
|
|
937
|
-
doHydrate();
|
|
938
|
-
};
|
|
939
|
-
el.addEventListener("click", hydrate2, { once: true });
|
|
940
|
-
el.addEventListener("focus", hydrate2, { once: true });
|
|
941
|
-
el.addEventListener("mouseenter", hydrate2, { once: true });
|
|
942
|
-
break;
|
|
943
|
-
}
|
|
944
|
-
case "media": {
|
|
945
|
-
if (!mediaQuery) {
|
|
946
|
-
doHydrate();
|
|
947
|
-
break;
|
|
948
|
-
}
|
|
949
|
-
const mq = window.matchMedia(mediaQuery);
|
|
950
|
-
if (mq.matches) {
|
|
951
|
-
queueMicrotask(doHydrate);
|
|
952
|
-
} else {
|
|
953
|
-
const checkMedia = () => {
|
|
954
|
-
if (mq.matches) {
|
|
955
|
-
mq.removeEventListener("change", checkMedia);
|
|
956
|
-
doHydrate();
|
|
957
|
-
}
|
|
958
|
-
};
|
|
959
|
-
mq.addEventListener("change", checkMedia);
|
|
960
|
-
}
|
|
961
|
-
break;
|
|
962
|
-
}
|
|
963
|
-
default:
|
|
964
|
-
queueMicrotask(doHydrate);
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
const refCallback = (el) => {
|
|
968
|
-
if (el) scheduleHydration(el);
|
|
969
|
-
};
|
|
970
|
-
return h(
|
|
971
|
-
"div",
|
|
972
|
-
{ "data-island": Component.name || "Island", "data-hydrate": mode, ref: refCallback },
|
|
973
|
-
hydrated() ? wrapper() : null
|
|
974
|
-
);
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
// packages/core/src/helpers.js
|
|
978
|
-
var _eachWarned = false;
|
|
979
|
-
function each(list, fn, keyFn) {
|
|
980
|
-
if (!_eachWarned) {
|
|
981
|
-
_eachWarned = true;
|
|
982
|
-
console.warn("[what] each() is deprecated. Use the <For> component or Array.map() instead.");
|
|
983
|
-
}
|
|
984
|
-
if (!list || list.length === 0) return [];
|
|
985
|
-
return list.map((item, index) => {
|
|
986
|
-
const vnode = fn(item, index);
|
|
987
|
-
if (keyFn && vnode && typeof vnode === "object") {
|
|
988
|
-
vnode.key = keyFn(item, index);
|
|
989
|
-
}
|
|
990
|
-
return vnode;
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
function cls(...args) {
|
|
994
|
-
const classes = [];
|
|
995
|
-
for (const arg of args) {
|
|
996
|
-
if (!arg) continue;
|
|
997
|
-
if (typeof arg === "string") {
|
|
998
|
-
classes.push(arg);
|
|
999
|
-
} else if (typeof arg === "object") {
|
|
1000
|
-
for (const [key, val] of Object.entries(arg)) {
|
|
1001
|
-
if (val) classes.push(key);
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
return classes.join(" ");
|
|
1006
|
-
}
|
|
1007
|
-
function style(obj) {
|
|
1008
|
-
if (typeof obj === "string") return obj;
|
|
1009
|
-
return Object.entries(obj).filter(([, v]) => v != null && v !== "").map(([k, v]) => `${camelToKebab(k)}:${v}`).join(";");
|
|
1010
|
-
}
|
|
1011
|
-
function camelToKebab(str) {
|
|
1012
|
-
return str.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
1013
|
-
}
|
|
1014
|
-
function debounce(fn, ms) {
|
|
1015
|
-
let timer;
|
|
1016
|
-
return (...args) => {
|
|
1017
|
-
clearTimeout(timer);
|
|
1018
|
-
timer = setTimeout(() => fn(...args), ms);
|
|
1019
|
-
};
|
|
1020
|
-
}
|
|
1021
|
-
function throttle(fn, ms) {
|
|
1022
|
-
let last = 0;
|
|
1023
|
-
return (...args) => {
|
|
1024
|
-
const now = Date.now();
|
|
1025
|
-
if (now - last >= ms) {
|
|
1026
|
-
last = now;
|
|
1027
|
-
fn(...args);
|
|
1028
|
-
}
|
|
1029
|
-
};
|
|
1030
|
-
}
|
|
1031
|
-
var _getCurrentComponentRef = null;
|
|
1032
|
-
function _setComponentRef(fn) {
|
|
1033
|
-
_getCurrentComponentRef = fn;
|
|
1034
|
-
}
|
|
1035
|
-
function useMediaQuery(query) {
|
|
1036
|
-
if (typeof window === "undefined") return signal(false);
|
|
1037
|
-
const mq = window.matchMedia(query);
|
|
1038
|
-
const s = signal(mq.matches);
|
|
1039
|
-
const handler = (e) => s.set(e.matches);
|
|
1040
|
-
mq.addEventListener("change", handler);
|
|
1041
|
-
const ctx = _getCurrentComponentRef?.();
|
|
1042
|
-
if (ctx) {
|
|
1043
|
-
ctx._cleanupCallbacks = ctx._cleanupCallbacks || [];
|
|
1044
|
-
ctx._cleanupCallbacks.push(() => mq.removeEventListener("change", handler));
|
|
1045
|
-
}
|
|
1046
|
-
return s;
|
|
1047
|
-
}
|
|
1048
|
-
function useLocalStorage(key, initial) {
|
|
1049
|
-
let stored;
|
|
1050
|
-
try {
|
|
1051
|
-
const raw = localStorage.getItem(key);
|
|
1052
|
-
stored = raw !== null ? JSON.parse(raw) : initial;
|
|
1053
|
-
} catch {
|
|
1054
|
-
stored = initial;
|
|
1055
|
-
}
|
|
1056
|
-
const s = signal(stored);
|
|
1057
|
-
const dispose = effect(() => {
|
|
1058
|
-
try {
|
|
1059
|
-
localStorage.setItem(key, JSON.stringify(s()));
|
|
1060
|
-
} catch (e) {
|
|
1061
|
-
if (__DEV__) console.warn("[what] localStorage write failed (quota exceeded?):", e);
|
|
1062
|
-
}
|
|
1063
|
-
});
|
|
1064
|
-
let storageHandler = null;
|
|
1065
|
-
if (typeof window !== "undefined") {
|
|
1066
|
-
storageHandler = (e) => {
|
|
1067
|
-
if (e.key === key && e.newValue !== null) {
|
|
1068
|
-
try {
|
|
1069
|
-
s.set(JSON.parse(e.newValue));
|
|
1070
|
-
} catch (err) {
|
|
1071
|
-
if (__DEV__) console.warn("[what] localStorage parse failed:", err);
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
};
|
|
1075
|
-
window.addEventListener("storage", storageHandler);
|
|
1076
|
-
}
|
|
1077
|
-
const ctx = _getCurrentComponentRef?.();
|
|
1078
|
-
if (ctx) {
|
|
1079
|
-
ctx._cleanupCallbacks = ctx._cleanupCallbacks || [];
|
|
1080
|
-
ctx._cleanupCallbacks.push(() => {
|
|
1081
|
-
dispose();
|
|
1082
|
-
if (storageHandler) window.removeEventListener("storage", storageHandler);
|
|
1083
|
-
});
|
|
1084
|
-
}
|
|
1085
|
-
return s;
|
|
1086
|
-
}
|
|
1087
|
-
function Portal({ target, children }) {
|
|
1088
|
-
if (typeof document === "undefined") return null;
|
|
1089
|
-
const container = typeof target === "string" ? document.querySelector(target) : target;
|
|
1090
|
-
if (!container) return null;
|
|
1091
|
-
return { tag: "__portal", props: { container }, children: Array.isArray(children) ? children : [children], _vnode: true };
|
|
1092
|
-
}
|
|
1093
|
-
function useClickOutside(ref, handler) {
|
|
1094
|
-
if (typeof document === "undefined") return;
|
|
1095
|
-
const listener = (e) => {
|
|
1096
|
-
const el = ref.current || ref;
|
|
1097
|
-
if (!el || el.contains(e.target)) return;
|
|
1098
|
-
handler(e);
|
|
1099
|
-
};
|
|
1100
|
-
document.addEventListener("mousedown", listener);
|
|
1101
|
-
document.addEventListener("touchstart", listener);
|
|
1102
|
-
const ctx = _getCurrentComponentRef?.();
|
|
1103
|
-
if (ctx) {
|
|
1104
|
-
ctx._cleanupCallbacks = ctx._cleanupCallbacks || [];
|
|
1105
|
-
ctx._cleanupCallbacks.push(() => {
|
|
1106
|
-
document.removeEventListener("mousedown", listener);
|
|
1107
|
-
document.removeEventListener("touchstart", listener);
|
|
1108
|
-
});
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
function transition(name, active) {
|
|
1112
|
-
return {
|
|
1113
|
-
class: active ? `${name}-enter ${name}-enter-active` : `${name}-leave ${name}-leave-active`
|
|
1114
|
-
};
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
// packages/core/src/dom.js
|
|
1118
|
-
var SVG_ELEMENTS = /* @__PURE__ */ new Set([
|
|
1119
|
-
"svg",
|
|
1120
|
-
"path",
|
|
1121
|
-
"circle",
|
|
1122
|
-
"rect",
|
|
1123
|
-
"line",
|
|
1124
|
-
"polyline",
|
|
1125
|
-
"polygon",
|
|
1126
|
-
"ellipse",
|
|
1127
|
-
"g",
|
|
1128
|
-
"defs",
|
|
1129
|
-
"use",
|
|
1130
|
-
"symbol",
|
|
1131
|
-
"clipPath",
|
|
1132
|
-
"mask",
|
|
1133
|
-
"pattern",
|
|
1134
|
-
"image",
|
|
1135
|
-
"text",
|
|
1136
|
-
"tspan",
|
|
1137
|
-
"textPath",
|
|
1138
|
-
"foreignObject",
|
|
1139
|
-
"linearGradient",
|
|
1140
|
-
"radialGradient",
|
|
1141
|
-
"stop",
|
|
1142
|
-
"marker",
|
|
1143
|
-
"animate",
|
|
1144
|
-
"animateTransform",
|
|
1145
|
-
"animateMotion",
|
|
1146
|
-
"set",
|
|
1147
|
-
"filter",
|
|
1148
|
-
"feBlend",
|
|
1149
|
-
"feColorMatrix",
|
|
1150
|
-
"feComponentTransfer",
|
|
1151
|
-
"feComposite",
|
|
1152
|
-
"feConvolveMatrix",
|
|
1153
|
-
"feDiffuseLighting",
|
|
1154
|
-
"feDisplacementMap",
|
|
1155
|
-
"feFlood",
|
|
1156
|
-
"feGaussianBlur",
|
|
1157
|
-
"feImage",
|
|
1158
|
-
"feMerge",
|
|
1159
|
-
"feMergeNode",
|
|
1160
|
-
"feMorphology",
|
|
1161
|
-
"feOffset",
|
|
1162
|
-
"feSpecularLighting",
|
|
1163
|
-
"feTile",
|
|
1164
|
-
"feTurbulence"
|
|
1165
|
-
]);
|
|
1166
|
-
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
1167
|
-
var mountedComponents = /* @__PURE__ */ new Set();
|
|
1168
|
-
var _commentCtxMap = /* @__PURE__ */ new WeakMap();
|
|
1169
|
-
function isDomNode(value) {
|
|
1170
|
-
if (!value || typeof value !== "object") return false;
|
|
1171
|
-
if (typeof Node !== "undefined" && value instanceof Node) return true;
|
|
1172
|
-
return typeof value.nodeType === "number" && typeof value.nodeName === "string";
|
|
1173
|
-
}
|
|
1174
|
-
function isVNode(value) {
|
|
1175
|
-
return !!value && typeof value === "object" && (value._vnode === true || "tag" in value);
|
|
1176
|
-
}
|
|
1177
|
-
function disposeComponent(ctx) {
|
|
1178
|
-
if (ctx.disposed) return;
|
|
1179
|
-
ctx.disposed = true;
|
|
1180
|
-
if (ctx.cleanups) {
|
|
1181
|
-
for (const cleanup2 of ctx.cleanups) {
|
|
1182
|
-
try {
|
|
1183
|
-
cleanup2();
|
|
1184
|
-
} catch (e) {
|
|
1185
|
-
console.error("[what] cleanup error:", e);
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
if (ctx.effects) {
|
|
1190
|
-
for (const dispose of ctx.effects) {
|
|
1191
|
-
try {
|
|
1192
|
-
dispose();
|
|
1193
|
-
} catch (e) {
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
if (ctx.hooks) {
|
|
1198
|
-
for (const hook of ctx.hooks) {
|
|
1199
|
-
if (hook && typeof hook.cleanup === "function") {
|
|
1200
|
-
try {
|
|
1201
|
-
hook.cleanup();
|
|
1202
|
-
} catch (e) {
|
|
1203
|
-
console.error("[what] hook cleanup error:", e);
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
if (ctx._cleanupCallbacks) {
|
|
1209
|
-
for (const fn of ctx._cleanupCallbacks) {
|
|
1210
|
-
try {
|
|
1211
|
-
fn();
|
|
1212
|
-
} catch (e) {
|
|
1213
|
-
console.error("[what] onCleanup error:", e);
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
if (__DEV__ && __devtools?.onComponentUnmount) __devtools.onComponentUnmount(ctx);
|
|
1218
|
-
mountedComponents.delete(ctx);
|
|
1219
|
-
}
|
|
1220
|
-
function disposeTree(node) {
|
|
1221
|
-
if (!node) return;
|
|
1222
|
-
if (node._componentCtx) {
|
|
1223
|
-
disposeComponent(node._componentCtx);
|
|
1224
|
-
}
|
|
1225
|
-
if (node.nodeType === 8) {
|
|
1226
|
-
const commentCtx = _commentCtxMap.get(node);
|
|
1227
|
-
if (commentCtx) {
|
|
1228
|
-
disposeComponent(commentCtx);
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
if (node._dispose) {
|
|
1232
|
-
try {
|
|
1233
|
-
node._dispose();
|
|
1234
|
-
} catch (e) {
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
if (node._propEffects) {
|
|
1238
|
-
for (const key in node._propEffects) {
|
|
1239
|
-
try {
|
|
1240
|
-
node._propEffects[key]();
|
|
1241
|
-
} catch (e) {
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
const children = node.childNodes;
|
|
1246
|
-
if (children && children.length > 0) {
|
|
1247
|
-
for (let i = 0; i < children.length; i++) {
|
|
1248
|
-
disposeTree(children[i]);
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
function mount(vnode, container) {
|
|
1253
|
-
if (typeof container === "string") {
|
|
1254
|
-
container = document.querySelector(container);
|
|
1255
|
-
}
|
|
1256
|
-
disposeTree(container);
|
|
1257
|
-
container.textContent = "";
|
|
1258
|
-
const node = createDOM(vnode, container);
|
|
1259
|
-
if (node) container.appendChild(node);
|
|
1260
|
-
return () => {
|
|
1261
|
-
disposeTree(container);
|
|
1262
|
-
container.textContent = "";
|
|
1263
|
-
};
|
|
1264
|
-
}
|
|
1265
|
-
function createDOM(vnode, parent, isSvg) {
|
|
1266
|
-
if (vnode == null || vnode === false || vnode === true) {
|
|
1267
|
-
return document.createComment("");
|
|
1268
|
-
}
|
|
1269
|
-
if (typeof vnode === "string" || typeof vnode === "number") {
|
|
1270
|
-
return document.createTextNode(String(vnode));
|
|
1271
|
-
}
|
|
1272
|
-
if (isDomNode(vnode)) {
|
|
1273
|
-
return vnode;
|
|
1274
|
-
}
|
|
1275
|
-
if (typeof vnode === "function") {
|
|
1276
|
-
const startMarker = document.createComment("fn");
|
|
1277
|
-
const endMarker = document.createComment("/fn");
|
|
1278
|
-
let currentNodes = [];
|
|
1279
|
-
const frag = document.createDocumentFragment();
|
|
1280
|
-
frag.appendChild(startMarker);
|
|
1281
|
-
frag.appendChild(endMarker);
|
|
1282
|
-
const dispose = effect(() => {
|
|
1283
|
-
const val = vnode();
|
|
1284
|
-
const vnodes = val == null || val === false || val === true ? [] : Array.isArray(val) ? val : [val];
|
|
1285
|
-
const realParent = endMarker.parentNode;
|
|
1286
|
-
if (!realParent) return;
|
|
1287
|
-
for (const old of currentNodes) {
|
|
1288
|
-
disposeTree(old);
|
|
1289
|
-
if (old.parentNode === realParent) realParent.removeChild(old);
|
|
1290
|
-
}
|
|
1291
|
-
currentNodes = [];
|
|
1292
|
-
for (const v of vnodes) {
|
|
1293
|
-
const node = createDOM(v, realParent, parent?._isSvg);
|
|
1294
|
-
if (node) {
|
|
1295
|
-
if (node.nodeType === 11) {
|
|
1296
|
-
const children = Array.from(node.childNodes);
|
|
1297
|
-
realParent.insertBefore(node, endMarker);
|
|
1298
|
-
for (const child of children) currentNodes.push(child);
|
|
1299
|
-
} else {
|
|
1300
|
-
realParent.insertBefore(node, endMarker);
|
|
1301
|
-
currentNodes.push(node);
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
});
|
|
1306
|
-
startMarker._dispose = dispose;
|
|
1307
|
-
endMarker._dispose = dispose;
|
|
1308
|
-
return frag;
|
|
1309
|
-
}
|
|
1310
|
-
if (Array.isArray(vnode)) {
|
|
1311
|
-
const frag = document.createDocumentFragment();
|
|
1312
|
-
for (const child of vnode) {
|
|
1313
|
-
const node = createDOM(child, parent, isSvg);
|
|
1314
|
-
if (node) frag.appendChild(node);
|
|
1315
|
-
}
|
|
1316
|
-
return frag;
|
|
1317
|
-
}
|
|
1318
|
-
if (isVNode(vnode) && typeof vnode.tag === "function") {
|
|
1319
|
-
return createComponent(vnode, parent, isSvg);
|
|
1320
|
-
}
|
|
1321
|
-
if (isVNode(vnode)) {
|
|
1322
|
-
return createElementFromVNode(vnode, parent, isSvg);
|
|
1323
|
-
}
|
|
1324
|
-
return document.createTextNode(String(vnode));
|
|
1325
|
-
}
|
|
1326
|
-
var _propsProxyHandler = {
|
|
1327
|
-
get(target, key) {
|
|
1328
|
-
if (key === "_sig") return void 0;
|
|
1329
|
-
return target._sig()[key];
|
|
1330
|
-
},
|
|
1331
|
-
has(target, key) {
|
|
1332
|
-
if (key === "_sig") return false;
|
|
1333
|
-
return key in target._sig();
|
|
1334
|
-
},
|
|
1335
|
-
ownKeys(target) {
|
|
1336
|
-
return Reflect.ownKeys(target._sig());
|
|
1337
|
-
},
|
|
1338
|
-
getOwnPropertyDescriptor(target, key) {
|
|
1339
|
-
if (key === "_sig") return void 0;
|
|
1340
|
-
const current = target._sig();
|
|
1341
|
-
if (key in current) {
|
|
1342
|
-
return { value: current[key], writable: false, enumerable: true, configurable: true };
|
|
1343
|
-
}
|
|
1344
|
-
return void 0;
|
|
1345
|
-
}
|
|
1346
|
-
};
|
|
1347
|
-
var componentStack = [];
|
|
1348
|
-
function getCurrentComponent() {
|
|
1349
|
-
return componentStack[componentStack.length - 1];
|
|
1350
|
-
}
|
|
1351
|
-
_injectGetCurrentComponent(getCurrentComponent);
|
|
1352
|
-
_setComponentRef(getCurrentComponent);
|
|
1353
|
-
function getComponentStack() {
|
|
1354
|
-
return componentStack;
|
|
1355
|
-
}
|
|
1356
|
-
function createComponent(vnode, parent, isSvg) {
|
|
1357
|
-
let { tag: Component, props, children } = vnode;
|
|
1358
|
-
if (typeof Component === "function" && (Component.prototype?.isReactComponent || Component.prototype?.render)) {
|
|
1359
|
-
const ClassComp = Component;
|
|
1360
|
-
Component = function ClassComponentBridge(props2) {
|
|
1361
|
-
const instance = new ClassComp(props2);
|
|
1362
|
-
return instance.render();
|
|
1363
|
-
};
|
|
1364
|
-
Component.displayName = ClassComp.displayName || ClassComp.name || "ClassComponent";
|
|
1365
|
-
}
|
|
1366
|
-
if (Component === "__errorBoundary" || vnode.tag === "__errorBoundary") {
|
|
1367
|
-
return createErrorBoundary(vnode, parent);
|
|
1368
|
-
}
|
|
1369
|
-
if (Component === "__suspense" || vnode.tag === "__suspense") {
|
|
1370
|
-
return createSuspenseBoundary(vnode, parent);
|
|
1371
|
-
}
|
|
1372
|
-
if (Component === "__portal" || vnode.tag === "__portal") {
|
|
1373
|
-
return createPortalDOM(vnode, parent);
|
|
1374
|
-
}
|
|
1375
|
-
const parentCtx = componentStack[componentStack.length - 1] || null;
|
|
1376
|
-
let errorBoundary = null;
|
|
1377
|
-
if (parentCtx) {
|
|
1378
|
-
errorBoundary = parentCtx._errorBoundary || null;
|
|
1379
|
-
if (!errorBoundary) {
|
|
1380
|
-
let p = parentCtx._parentCtx;
|
|
1381
|
-
while (p) {
|
|
1382
|
-
if (p._errorBoundary) {
|
|
1383
|
-
errorBoundary = p._errorBoundary;
|
|
1384
|
-
break;
|
|
1385
|
-
}
|
|
1386
|
-
p = p._parentCtx;
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
|
-
const ctx = {
|
|
1391
|
-
hooks: [],
|
|
1392
|
-
hookIndex: 0,
|
|
1393
|
-
effects: [],
|
|
1394
|
-
cleanups: [],
|
|
1395
|
-
mounted: false,
|
|
1396
|
-
disposed: false,
|
|
1397
|
-
Component,
|
|
1398
|
-
_parentCtx: parentCtx,
|
|
1399
|
-
_errorBoundary: errorBoundary
|
|
1400
|
-
};
|
|
1401
|
-
const startComment = document.createComment("c:start");
|
|
1402
|
-
const endComment = document.createComment("c:end");
|
|
1403
|
-
_commentCtxMap.set(startComment, ctx);
|
|
1404
|
-
ctx._startComment = startComment;
|
|
1405
|
-
ctx._endComment = endComment;
|
|
1406
|
-
const container = document.createDocumentFragment();
|
|
1407
|
-
container._componentCtx = ctx;
|
|
1408
|
-
ctx._wrapper = startComment;
|
|
1409
|
-
mountedComponents.add(ctx);
|
|
1410
|
-
if (__DEV__ && __devtools?.onComponentMount) __devtools.onComponentMount(ctx);
|
|
1411
|
-
const propsChildren = children.length === 0 ? void 0 : children.length === 1 ? children[0] : children;
|
|
1412
|
-
let mergedProps;
|
|
1413
|
-
if (propsChildren !== void 0) {
|
|
1414
|
-
mergedProps = props ? Object.assign({}, props, { children: propsChildren }) : { children: propsChildren };
|
|
1415
|
-
} else {
|
|
1416
|
-
mergedProps = props ? Object.assign({}, props) : {};
|
|
1417
|
-
}
|
|
1418
|
-
const propsSignal = signal(mergedProps);
|
|
1419
|
-
ctx._propsSignal = propsSignal;
|
|
1420
|
-
const reactiveProps = new Proxy({ _sig: propsSignal }, _propsProxyHandler);
|
|
1421
|
-
componentStack.push(ctx);
|
|
1422
|
-
let result;
|
|
1423
|
-
try {
|
|
1424
|
-
result = Component(reactiveProps);
|
|
1425
|
-
} catch (error) {
|
|
1426
|
-
componentStack.pop();
|
|
1427
|
-
if (!reportError(error, ctx)) {
|
|
1428
|
-
console.error("[what] Uncaught error in component:", Component.name || "Anonymous", error);
|
|
1429
|
-
throw error;
|
|
1430
|
-
}
|
|
1431
|
-
container.appendChild(startComment);
|
|
1432
|
-
container.appendChild(endComment);
|
|
1433
|
-
return container;
|
|
1434
|
-
}
|
|
1435
|
-
componentStack.pop();
|
|
1436
|
-
ctx.mounted = true;
|
|
1437
|
-
if (ctx._mountCallbacks) {
|
|
1438
|
-
queueMicrotask(() => {
|
|
1439
|
-
if (ctx.disposed) return;
|
|
1440
|
-
for (const fn of ctx._mountCallbacks) {
|
|
1441
|
-
try {
|
|
1442
|
-
fn();
|
|
1443
|
-
} catch (e) {
|
|
1444
|
-
console.error("[what] onMount error:", e);
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
});
|
|
1448
|
-
}
|
|
1449
|
-
container.appendChild(startComment);
|
|
1450
|
-
const vnodes = Array.isArray(result) ? result : [result];
|
|
1451
|
-
for (const v of vnodes) {
|
|
1452
|
-
const node = createDOM(v, container, isSvg);
|
|
1453
|
-
if (node) container.appendChild(node);
|
|
1454
|
-
}
|
|
1455
|
-
container.appendChild(endComment);
|
|
1456
|
-
return container;
|
|
1457
|
-
}
|
|
1458
|
-
function createErrorBoundary(vnode, parent) {
|
|
1459
|
-
const { errorState, handleError, fallback, reset } = vnode.props;
|
|
1460
|
-
const children = vnode.children;
|
|
1461
|
-
const startComment = document.createComment("eb:start");
|
|
1462
|
-
const endComment = document.createComment("eb:end");
|
|
1463
|
-
const boundaryCtx = {
|
|
1464
|
-
hooks: [],
|
|
1465
|
-
hookIndex: 0,
|
|
1466
|
-
effects: [],
|
|
1467
|
-
cleanups: [],
|
|
1468
|
-
mounted: false,
|
|
1469
|
-
disposed: false,
|
|
1470
|
-
_parentCtx: componentStack[componentStack.length - 1] || null,
|
|
1471
|
-
_errorBoundary: handleError,
|
|
1472
|
-
_startComment: startComment,
|
|
1473
|
-
_endComment: endComment
|
|
1474
|
-
};
|
|
1475
|
-
_commentCtxMap.set(startComment, boundaryCtx);
|
|
1476
|
-
const container = document.createDocumentFragment();
|
|
1477
|
-
container._componentCtx = boundaryCtx;
|
|
1478
|
-
container.appendChild(startComment);
|
|
1479
|
-
container.appendChild(endComment);
|
|
1480
|
-
const dispose = effect(() => {
|
|
1481
|
-
const error = errorState();
|
|
1482
|
-
componentStack.push(boundaryCtx);
|
|
1483
|
-
if (startComment.parentNode) {
|
|
1484
|
-
while (startComment.nextSibling && startComment.nextSibling !== endComment) {
|
|
1485
|
-
const old = startComment.nextSibling;
|
|
1486
|
-
disposeTree(old);
|
|
1487
|
-
old.parentNode.removeChild(old);
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
let vnodes;
|
|
1491
|
-
if (error) {
|
|
1492
|
-
vnodes = typeof fallback === "function" ? [fallback({ error, reset })] : [fallback];
|
|
1493
|
-
} else {
|
|
1494
|
-
vnodes = children;
|
|
1495
|
-
}
|
|
1496
|
-
vnodes = Array.isArray(vnodes) ? vnodes : [vnodes];
|
|
1497
|
-
for (const v of vnodes) {
|
|
1498
|
-
const node = createDOM(v, parent);
|
|
1499
|
-
if (node) {
|
|
1500
|
-
if (endComment.parentNode) {
|
|
1501
|
-
endComment.parentNode.insertBefore(node, endComment);
|
|
1502
|
-
} else {
|
|
1503
|
-
container.insertBefore(node, endComment);
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
componentStack.pop();
|
|
1508
|
-
});
|
|
1509
|
-
boundaryCtx.effects.push(dispose);
|
|
1510
|
-
return container;
|
|
1511
|
-
}
|
|
1512
|
-
function createSuspenseBoundary(vnode, parent) {
|
|
1513
|
-
const { boundary, fallback, loading } = vnode.props;
|
|
1514
|
-
const children = vnode.children;
|
|
1515
|
-
const startComment = document.createComment("sb:start");
|
|
1516
|
-
const endComment = document.createComment("sb:end");
|
|
1517
|
-
const boundaryCtx = {
|
|
1518
|
-
hooks: [],
|
|
1519
|
-
hookIndex: 0,
|
|
1520
|
-
effects: [],
|
|
1521
|
-
cleanups: [],
|
|
1522
|
-
mounted: false,
|
|
1523
|
-
disposed: false,
|
|
1524
|
-
_parentCtx: componentStack[componentStack.length - 1] || null,
|
|
1525
|
-
_startComment: startComment,
|
|
1526
|
-
_endComment: endComment
|
|
1527
|
-
};
|
|
1528
|
-
_commentCtxMap.set(startComment, boundaryCtx);
|
|
1529
|
-
const container = document.createDocumentFragment();
|
|
1530
|
-
container._componentCtx = boundaryCtx;
|
|
1531
|
-
container.appendChild(startComment);
|
|
1532
|
-
container.appendChild(endComment);
|
|
1533
|
-
const dispose = effect(() => {
|
|
1534
|
-
const isLoading = loading();
|
|
1535
|
-
const vnodes = isLoading ? [fallback] : children;
|
|
1536
|
-
const normalized = Array.isArray(vnodes) ? vnodes : [vnodes];
|
|
1537
|
-
componentStack.push(boundaryCtx);
|
|
1538
|
-
if (startComment.parentNode) {
|
|
1539
|
-
while (startComment.nextSibling && startComment.nextSibling !== endComment) {
|
|
1540
|
-
const old = startComment.nextSibling;
|
|
1541
|
-
disposeTree(old);
|
|
1542
|
-
old.parentNode.removeChild(old);
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
for (const v of normalized) {
|
|
1546
|
-
const node = createDOM(v, parent);
|
|
1547
|
-
if (node) {
|
|
1548
|
-
if (endComment.parentNode) {
|
|
1549
|
-
endComment.parentNode.insertBefore(node, endComment);
|
|
1550
|
-
} else {
|
|
1551
|
-
container.insertBefore(node, endComment);
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
componentStack.pop();
|
|
1556
|
-
});
|
|
1557
|
-
boundaryCtx.effects.push(dispose);
|
|
1558
|
-
return container;
|
|
1559
|
-
}
|
|
1560
|
-
function createPortalDOM(vnode, parent) {
|
|
1561
|
-
const { container } = vnode.props;
|
|
1562
|
-
const children = vnode.children;
|
|
1563
|
-
if (!container) {
|
|
1564
|
-
console.warn("[what] Portal: target container not found");
|
|
1565
|
-
return document.createComment("portal:empty");
|
|
1566
|
-
}
|
|
1567
|
-
const portalCtx = {
|
|
1568
|
-
hooks: [],
|
|
1569
|
-
hookIndex: 0,
|
|
1570
|
-
effects: [],
|
|
1571
|
-
cleanups: [],
|
|
1572
|
-
mounted: false,
|
|
1573
|
-
disposed: false,
|
|
1574
|
-
_parentCtx: componentStack[componentStack.length - 1] || null
|
|
1575
|
-
};
|
|
1576
|
-
const placeholder = document.createComment("portal");
|
|
1577
|
-
placeholder._componentCtx = portalCtx;
|
|
1578
|
-
const portalNodes = [];
|
|
1579
|
-
for (const child of children) {
|
|
1580
|
-
const node = createDOM(child, container);
|
|
1581
|
-
if (node) {
|
|
1582
|
-
container.appendChild(node);
|
|
1583
|
-
portalNodes.push(node);
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
portalCtx._cleanupCallbacks = [() => {
|
|
1587
|
-
for (const node of portalNodes) {
|
|
1588
|
-
disposeTree(node);
|
|
1589
|
-
if (node.parentNode) node.parentNode.removeChild(node);
|
|
1590
|
-
}
|
|
1591
|
-
}];
|
|
1592
|
-
return placeholder;
|
|
1593
|
-
}
|
|
1594
|
-
function createElementFromVNode(vnode, parent, isSvg) {
|
|
1595
|
-
const { tag, props, children } = vnode;
|
|
1596
|
-
const svgContext = isSvg || SVG_ELEMENTS.has(tag);
|
|
1597
|
-
const el = svgContext ? document.createElementNS(SVG_NS, tag) : document.createElement(tag);
|
|
1598
|
-
if (props) {
|
|
1599
|
-
applyProps(el, props, {}, svgContext);
|
|
1600
|
-
}
|
|
1601
|
-
const isSvgChildren = svgContext && tag !== "foreignObject";
|
|
1602
|
-
for (let i = 0; i < children.length; i++) {
|
|
1603
|
-
const node = createDOM(children[i], el, isSvgChildren);
|
|
1604
|
-
if (node) el.appendChild(node);
|
|
1605
|
-
}
|
|
1606
|
-
el._vnode = vnode;
|
|
1607
|
-
return el;
|
|
1608
|
-
}
|
|
1609
|
-
function applyProps(el, newProps, oldProps, isSvg) {
|
|
1610
|
-
if (!newProps) return;
|
|
1611
|
-
for (const key in newProps) {
|
|
1612
|
-
if (key === "key" || key === "children") continue;
|
|
1613
|
-
if (key === "ref") {
|
|
1614
|
-
const ref = newProps.ref;
|
|
1615
|
-
if (typeof ref === "function") ref(el);
|
|
1616
|
-
else if (ref) ref.current = el;
|
|
1617
|
-
continue;
|
|
1618
|
-
}
|
|
1619
|
-
setProp(el, key, newProps[key], isSvg);
|
|
1620
|
-
}
|
|
1621
|
-
}
|
|
1622
|
-
function setProp(el, key, value, isSvg) {
|
|
1623
|
-
if (typeof value === "function" && !(key.startsWith("on") && key.length > 2) && key !== "ref") {
|
|
1624
|
-
if (!el._propEffects) el._propEffects = {};
|
|
1625
|
-
if (el._propEffects[key]) {
|
|
1626
|
-
try {
|
|
1627
|
-
el._propEffects[key]();
|
|
1628
|
-
} catch (e) {
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
el._propEffects[key] = effect(() => {
|
|
1632
|
-
const resolved = value();
|
|
1633
|
-
setProp(el, key, resolved, isSvg);
|
|
1634
|
-
});
|
|
1635
|
-
return;
|
|
1636
|
-
}
|
|
1637
|
-
if (key.startsWith("on") && key.length > 2) {
|
|
1638
|
-
let eventName = key.slice(2);
|
|
1639
|
-
let useCapture = false;
|
|
1640
|
-
if (eventName.endsWith("Capture")) {
|
|
1641
|
-
eventName = eventName.slice(0, -7);
|
|
1642
|
-
useCapture = true;
|
|
1643
|
-
}
|
|
1644
|
-
const event = eventName.toLowerCase();
|
|
1645
|
-
const storageKey = useCapture ? event + "_capture" : event;
|
|
1646
|
-
const old = el._events?.[storageKey];
|
|
1647
|
-
if (old && old._original === value) return;
|
|
1648
|
-
if (old) el.removeEventListener(event, old, useCapture);
|
|
1649
|
-
if (value == null) return;
|
|
1650
|
-
if (!el._events) el._events = {};
|
|
1651
|
-
const wrappedHandler = (e) => {
|
|
1652
|
-
if (!e.nativeEvent) e.nativeEvent = e;
|
|
1653
|
-
return untrack(() => wrappedHandler._handler(e));
|
|
1654
|
-
};
|
|
1655
|
-
wrappedHandler._handler = value;
|
|
1656
|
-
wrappedHandler._original = value;
|
|
1657
|
-
el._events[storageKey] = wrappedHandler;
|
|
1658
|
-
const eventOpts = value._eventOpts;
|
|
1659
|
-
el.addEventListener(event, wrappedHandler, eventOpts || useCapture || void 0);
|
|
1660
|
-
return;
|
|
1661
|
-
}
|
|
1662
|
-
if (key === "className" || key === "class") {
|
|
1663
|
-
if (isSvg) {
|
|
1664
|
-
el.setAttribute("class", value || "");
|
|
1665
|
-
} else {
|
|
1666
|
-
el.className = value || "";
|
|
1667
|
-
}
|
|
1668
|
-
return;
|
|
1669
|
-
}
|
|
1670
|
-
if (key === "style") {
|
|
1671
|
-
if (typeof value === "string") {
|
|
1672
|
-
el.style.cssText = value;
|
|
1673
|
-
el._prevStyle = null;
|
|
1674
|
-
} else if (typeof value === "object") {
|
|
1675
|
-
const oldStyle = el._prevStyle || {};
|
|
1676
|
-
for (const prop in oldStyle) {
|
|
1677
|
-
if (!(prop in value)) el.style[prop] = "";
|
|
1678
|
-
}
|
|
1679
|
-
for (const prop in value) {
|
|
1680
|
-
el.style[prop] = value[prop] ?? "";
|
|
1681
|
-
}
|
|
1682
|
-
el._prevStyle = { ...value };
|
|
1683
|
-
}
|
|
1684
|
-
return;
|
|
1685
|
-
}
|
|
1686
|
-
if (key === "dangerouslySetInnerHTML") {
|
|
1687
|
-
el.innerHTML = value?.__html ?? "";
|
|
1688
|
-
return;
|
|
1689
|
-
}
|
|
1690
|
-
if (key === "innerHTML") {
|
|
1691
|
-
if (value == null) return;
|
|
1692
|
-
if (value && typeof value === "object" && "__html" in value) {
|
|
1693
|
-
el.innerHTML = value.__html ?? "";
|
|
1694
|
-
} else {
|
|
1695
|
-
if (__DEV__) {
|
|
1696
|
-
console.warn(
|
|
1697
|
-
"[what] innerHTML received a raw string. This is a security risk (XSS). Use innerHTML={{ __html: trustedString }} or dangerouslySetInnerHTML={{ __html: trustedString }} instead."
|
|
1698
|
-
);
|
|
1699
|
-
}
|
|
1700
|
-
return;
|
|
1701
|
-
}
|
|
1702
|
-
return;
|
|
1703
|
-
}
|
|
1704
|
-
if (typeof value === "boolean") {
|
|
1705
|
-
if (value) el.setAttribute(key, "");
|
|
1706
|
-
else el.removeAttribute(key);
|
|
1707
|
-
return;
|
|
1708
|
-
}
|
|
1709
|
-
if (key.startsWith("data-") || key.startsWith("aria-")) {
|
|
1710
|
-
el.setAttribute(key, value);
|
|
1711
|
-
return;
|
|
1712
|
-
}
|
|
1713
|
-
if (isSvg) {
|
|
1714
|
-
if (value === false || value == null) {
|
|
1715
|
-
el.removeAttribute(key);
|
|
1716
|
-
} else {
|
|
1717
|
-
el.setAttribute(key, value === true ? "" : String(value));
|
|
1718
|
-
}
|
|
1719
|
-
return;
|
|
1720
|
-
}
|
|
1721
|
-
if (key in el) {
|
|
1722
|
-
el[key] = value;
|
|
1723
|
-
} else {
|
|
1724
|
-
el.setAttribute(key, value);
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
|
|
1728
|
-
// packages/core/src/render.js
|
|
1729
|
-
var _onTextInsert = null;
|
|
1730
|
-
function _setTextInsertHook(fn) {
|
|
1731
|
-
_onTextInsert = typeof fn === "function" ? fn : null;
|
|
1732
|
-
}
|
|
1733
|
-
function _$createComponent(Component, props, children) {
|
|
1734
|
-
if (children && children.length > 0) {
|
|
1735
|
-
const mergedChildren = children.length === 1 ? children[0] : children;
|
|
1736
|
-
if (props) {
|
|
1737
|
-
props.children = mergedChildren;
|
|
1738
|
-
} else {
|
|
1739
|
-
props = { children: mergedChildren };
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
return createDOM({ tag: Component, props: props || {}, children: children || [], key: null, _vnode: true });
|
|
1743
|
-
}
|
|
1744
|
-
var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "formAction"]);
|
|
1745
|
-
function isSafeUrl(url) {
|
|
1746
|
-
if (typeof url !== "string") return true;
|
|
1747
|
-
const normalized = url.trim().replace(/[\s\x00-\x1f]/g, "").toLowerCase();
|
|
1748
|
-
if (normalized.startsWith("javascript:")) return false;
|
|
1749
|
-
if (normalized.startsWith("data:")) return false;
|
|
1750
|
-
if (normalized.startsWith("vbscript:")) return false;
|
|
1751
|
-
return true;
|
|
1752
|
-
}
|
|
1753
|
-
var TABLE_WRAPPERS = {
|
|
1754
|
-
tr: { depth: 2, wrap: "<table><tbody>", unwrap: "</tbody></table>" },
|
|
1755
|
-
td: { depth: 3, wrap: "<table><tbody><tr>", unwrap: "</tr></tbody></table>" },
|
|
1756
|
-
th: { depth: 3, wrap: "<table><tbody><tr>", unwrap: "</tr></tbody></table>" },
|
|
1757
|
-
thead: { depth: 1, wrap: "<table>", unwrap: "</table>" },
|
|
1758
|
-
tbody: { depth: 1, wrap: "<table>", unwrap: "</table>" },
|
|
1759
|
-
tfoot: { depth: 1, wrap: "<table>", unwrap: "</table>" },
|
|
1760
|
-
colgroup: { depth: 1, wrap: "<table>", unwrap: "</table>" },
|
|
1761
|
-
col: { depth: 1, wrap: "<table>", unwrap: "</table>" },
|
|
1762
|
-
caption: { depth: 1, wrap: "<table>", unwrap: "</table>" }
|
|
1763
|
-
};
|
|
1764
|
-
var SVG_ELEMENTS2 = /* @__PURE__ */ new Set([
|
|
1765
|
-
"svg",
|
|
1766
|
-
"path",
|
|
1767
|
-
"circle",
|
|
1768
|
-
"rect",
|
|
1769
|
-
"line",
|
|
1770
|
-
"polyline",
|
|
1771
|
-
"polygon",
|
|
1772
|
-
"ellipse",
|
|
1773
|
-
"g",
|
|
1774
|
-
"defs",
|
|
1775
|
-
"use",
|
|
1776
|
-
"text",
|
|
1777
|
-
"tspan",
|
|
1778
|
-
"foreignObject",
|
|
1779
|
-
"clipPath",
|
|
1780
|
-
"mask",
|
|
1781
|
-
"pattern",
|
|
1782
|
-
"linearGradient",
|
|
1783
|
-
"radialGradient",
|
|
1784
|
-
"stop",
|
|
1785
|
-
"marker",
|
|
1786
|
-
"symbol",
|
|
1787
|
-
"image",
|
|
1788
|
-
"animate",
|
|
1789
|
-
"animateTransform",
|
|
1790
|
-
"animateMotion",
|
|
1791
|
-
"set",
|
|
1792
|
-
"filter",
|
|
1793
|
-
"feGaussianBlur",
|
|
1794
|
-
"feOffset",
|
|
1795
|
-
"feMerge",
|
|
1796
|
-
"feMergeNode",
|
|
1797
|
-
"feBlend",
|
|
1798
|
-
"feColorMatrix",
|
|
1799
|
-
"feComponentTransfer",
|
|
1800
|
-
"feComposite",
|
|
1801
|
-
"feConvolveMatrix",
|
|
1802
|
-
"feDiffuseLighting",
|
|
1803
|
-
"feDisplacementMap",
|
|
1804
|
-
"feFlood",
|
|
1805
|
-
"feImage",
|
|
1806
|
-
"feMorphology",
|
|
1807
|
-
"feSpecularLighting",
|
|
1808
|
-
"feTile",
|
|
1809
|
-
"feTurbulence",
|
|
1810
|
-
"feDistantLight",
|
|
1811
|
-
"fePointLight",
|
|
1812
|
-
"feSpotLight"
|
|
1813
|
-
]);
|
|
1814
|
-
function getLeadingTag(html2) {
|
|
1815
|
-
const m = html2.match(/^<([a-zA-Z][a-zA-Z0-9]*)/);
|
|
1816
|
-
return m ? m[1] : "";
|
|
1817
|
-
}
|
|
1818
|
-
function _$templateImpl(html2) {
|
|
1819
|
-
const trimmed = html2.trim();
|
|
1820
|
-
const tag = getLeadingTag(trimmed);
|
|
1821
|
-
if (SVG_ELEMENTS2.has(tag)) {
|
|
1822
|
-
return svgTemplate(trimmed);
|
|
1823
|
-
}
|
|
1824
|
-
const tableInfo = TABLE_WRAPPERS[tag];
|
|
1825
|
-
if (tableInfo) {
|
|
1826
|
-
const t2 = document.createElement("template");
|
|
1827
|
-
t2.innerHTML = tableInfo.wrap + trimmed + tableInfo.unwrap;
|
|
1828
|
-
let target = t2.content.firstChild;
|
|
1829
|
-
for (let i = 0; i < tableInfo.depth; i++) target = target.firstChild;
|
|
1830
|
-
return () => target.cloneNode(true);
|
|
1831
|
-
}
|
|
1832
|
-
const t = document.createElement("template");
|
|
1833
|
-
t.innerHTML = trimmed;
|
|
1834
|
-
return () => t.content.firstChild.cloneNode(true);
|
|
1835
|
-
}
|
|
1836
|
-
var _templateWarned = false;
|
|
1837
|
-
function template(html2) {
|
|
1838
|
-
if (__DEV__ && !_templateWarned) {
|
|
1839
|
-
_templateWarned = true;
|
|
1840
|
-
console.warn(
|
|
1841
|
-
"[what] template() is a compiler internal. Use JSX instead. Direct calls with user input can lead to XSS vulnerabilities."
|
|
1842
|
-
);
|
|
1843
|
-
}
|
|
1844
|
-
return _$templateImpl(html2);
|
|
1845
|
-
}
|
|
1846
|
-
function svgTemplate(html2) {
|
|
1847
|
-
const trimmed = html2.trim();
|
|
1848
|
-
const tag = getLeadingTag(trimmed);
|
|
1849
|
-
if (tag === "svg") {
|
|
1850
|
-
const t2 = document.createElement("template");
|
|
1851
|
-
t2.innerHTML = trimmed;
|
|
1852
|
-
return () => t2.content.firstChild.cloneNode(true);
|
|
1853
|
-
}
|
|
1854
|
-
const t = document.createElement("template");
|
|
1855
|
-
t.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg">${trimmed}</svg>`;
|
|
1856
|
-
return () => t.content.firstChild.firstChild.cloneNode(true);
|
|
1857
|
-
}
|
|
1858
|
-
function insert(parent, child, marker) {
|
|
1859
|
-
if (typeof child === "function") {
|
|
1860
|
-
const first = child();
|
|
1861
|
-
const t = typeof first;
|
|
1862
|
-
if (t === "string" || t === "number") {
|
|
1863
|
-
const textNode = document.createTextNode(String(first));
|
|
1864
|
-
const m = marker || null;
|
|
1865
|
-
if (m) parent.insertBefore(textNode, m);
|
|
1866
|
-
else parent.appendChild(textNode);
|
|
1867
|
-
if (_onTextInsert) _onTextInsert(parent, String(first));
|
|
1868
|
-
let current2 = textNode;
|
|
1869
|
-
let isTextFastPath = true;
|
|
1870
|
-
effect(() => {
|
|
1871
|
-
const val = child();
|
|
1872
|
-
const vt = typeof val;
|
|
1873
|
-
if (isTextFastPath && (vt === "string" || vt === "number")) {
|
|
1874
|
-
const str = String(val);
|
|
1875
|
-
if (textNode.data !== str) textNode.data = str;
|
|
1876
|
-
if (_onTextInsert) _onTextInsert(parent, str);
|
|
1877
|
-
} else {
|
|
1878
|
-
isTextFastPath = false;
|
|
1879
|
-
current2 = reconcileInsert(parent, val, current2, m);
|
|
1880
|
-
}
|
|
1881
|
-
});
|
|
1882
|
-
return textNode;
|
|
1883
|
-
}
|
|
1884
|
-
let current = first != null ? reconcileInsert(parent, first, null, marker || null) : null;
|
|
1885
|
-
effect(() => {
|
|
1886
|
-
current = reconcileInsert(parent, child(), current, marker || null);
|
|
1887
|
-
});
|
|
1888
|
-
return current;
|
|
1889
|
-
}
|
|
1890
|
-
if (typeof child === "string" || typeof child === "number") {
|
|
1891
|
-
const textNode = document.createTextNode(String(child));
|
|
1892
|
-
if (marker) parent.insertBefore(textNode, marker);
|
|
1893
|
-
else parent.appendChild(textNode);
|
|
1894
|
-
return textNode;
|
|
1895
|
-
}
|
|
1896
|
-
if (child != null && typeof child === "object" && child.nodeType > 0) {
|
|
1897
|
-
if (marker) parent.insertBefore(child, marker);
|
|
1898
|
-
else parent.appendChild(child);
|
|
1899
|
-
return child;
|
|
1900
|
-
}
|
|
1901
|
-
return reconcileInsert(parent, child, null, marker || null);
|
|
1902
|
-
}
|
|
1903
|
-
function isDomNode2(value) {
|
|
1904
|
-
if (!value || typeof value !== "object") return false;
|
|
1905
|
-
if (typeof Node !== "undefined" && value instanceof Node) return true;
|
|
1906
|
-
return typeof value.nodeType === "number" && typeof value.nodeName === "string";
|
|
1907
|
-
}
|
|
1908
|
-
function isVNode2(value) {
|
|
1909
|
-
return !!value && typeof value === "object" && (value._vnode === true || "tag" in value);
|
|
1910
|
-
}
|
|
1911
|
-
var _hasSVGElement = typeof SVGElement !== "undefined";
|
|
1912
|
-
function isSvgParent(parent) {
|
|
1913
|
-
return _hasSVGElement && parent instanceof SVGElement && parent.tagName !== "foreignObject";
|
|
1914
|
-
}
|
|
1915
|
-
function asNodeArray(value) {
|
|
1916
|
-
if (value == null) return [];
|
|
1917
|
-
return Array.isArray(value) ? value : [value];
|
|
1918
|
-
}
|
|
1919
|
-
function valuesToNodes(value, parent, out) {
|
|
1920
|
-
if (value == null || typeof value === "boolean") return out;
|
|
1921
|
-
if (Array.isArray(value)) {
|
|
1922
|
-
for (let i = 0; i < value.length; i++) {
|
|
1923
|
-
valuesToNodes(value[i], parent, out);
|
|
1924
|
-
}
|
|
1925
|
-
return out;
|
|
1926
|
-
}
|
|
1927
|
-
if (typeof value === "string" || typeof value === "number") {
|
|
1928
|
-
out.push(document.createTextNode(String(value)));
|
|
1929
|
-
return out;
|
|
1930
|
-
}
|
|
1931
|
-
if (isDomNode2(value)) {
|
|
1932
|
-
out.push(value);
|
|
1933
|
-
return out;
|
|
1934
|
-
}
|
|
1935
|
-
if (isVNode2(value)) {
|
|
1936
|
-
out.push(createDOM(value, parent, isSvgParent(parent)));
|
|
1937
|
-
return out;
|
|
1938
|
-
}
|
|
1939
|
-
out.push(document.createTextNode(String(value)));
|
|
1940
|
-
return out;
|
|
1941
|
-
}
|
|
1942
|
-
function sameNodeArray(a, b) {
|
|
1943
|
-
if (a.length !== b.length) return false;
|
|
1944
|
-
for (let i = 0; i < a.length; i++) {
|
|
1945
|
-
if (a[i] !== b[i]) return false;
|
|
1946
|
-
}
|
|
1947
|
-
return true;
|
|
1948
|
-
}
|
|
1949
|
-
function reconcileInsert(parent, value, current, marker) {
|
|
1950
|
-
if (!parent || typeof parent.insertBefore !== "function") {
|
|
1951
|
-
if (__DEV__) {
|
|
1952
|
-
console.warn("[what] reconcileInsert called with invalid parent:", parent);
|
|
1953
|
-
}
|
|
1954
|
-
return current;
|
|
1955
|
-
}
|
|
1956
|
-
const targetMarker = marker || null;
|
|
1957
|
-
if (value == null || typeof value === "boolean") {
|
|
1958
|
-
const oldNodes2 = asNodeArray(current);
|
|
1959
|
-
for (let i = 0; i < oldNodes2.length; i++) {
|
|
1960
|
-
const oldNode = oldNodes2[i];
|
|
1961
|
-
if (oldNode.parentNode === parent) {
|
|
1962
|
-
disposeTree(oldNode);
|
|
1963
|
-
parent.removeChild(oldNode);
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
return null;
|
|
1967
|
-
}
|
|
1968
|
-
if ((typeof value === "string" || typeof value === "number") && current && !Array.isArray(current) && current.nodeType === 3) {
|
|
1969
|
-
const text = String(value);
|
|
1970
|
-
if (current.data !== text) current.data = text;
|
|
1971
|
-
return current;
|
|
1972
|
-
}
|
|
1973
|
-
if (typeof value === "object" && value !== null && value.nodeType > 0 && !Array.isArray(value)) {
|
|
1974
|
-
if (value === current) return current;
|
|
1975
|
-
if (current && !Array.isArray(current) && current.nodeType > 0) {
|
|
1976
|
-
if (current.parentNode === parent) {
|
|
1977
|
-
disposeTree(current);
|
|
1978
|
-
parent.replaceChild(value, current);
|
|
1979
|
-
} else {
|
|
1980
|
-
if (targetMarker) parent.insertBefore(value, targetMarker);
|
|
1981
|
-
else parent.appendChild(value);
|
|
1982
|
-
}
|
|
1983
|
-
return value;
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
const newNodes = valuesToNodes(value, parent, []);
|
|
1987
|
-
const oldNodes = asNodeArray(current);
|
|
1988
|
-
if (sameNodeArray(oldNodes, newNodes)) {
|
|
1989
|
-
return current;
|
|
1990
|
-
}
|
|
1991
|
-
const newLen = newNodes.length;
|
|
1992
|
-
for (let i = 0; i < oldNodes.length; i++) {
|
|
1993
|
-
const oldNode = oldNodes[i];
|
|
1994
|
-
if (oldNode.parentNode !== parent) continue;
|
|
1995
|
-
let found = false;
|
|
1996
|
-
for (let j = 0; j < newLen; j++) {
|
|
1997
|
-
if (newNodes[j] === oldNode) {
|
|
1998
|
-
found = true;
|
|
1999
|
-
break;
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
if (!found) {
|
|
2003
|
-
disposeTree(oldNode);
|
|
2004
|
-
parent.removeChild(oldNode);
|
|
2005
|
-
}
|
|
2006
|
-
}
|
|
2007
|
-
let ref = targetMarker;
|
|
2008
|
-
for (let i = newNodes.length - 1; i >= 0; i--) {
|
|
2009
|
-
const node = newNodes[i];
|
|
2010
|
-
if (node.parentNode !== parent || node.nextSibling !== ref) {
|
|
2011
|
-
if (ref && ref.parentNode !== parent) ref = null;
|
|
2012
|
-
if (ref) parent.insertBefore(node, ref);
|
|
2013
|
-
else parent.appendChild(node);
|
|
2014
|
-
}
|
|
2015
|
-
ref = node;
|
|
2016
|
-
}
|
|
2017
|
-
if (newNodes.length === 0) return null;
|
|
2018
|
-
return newNodes.length === 1 ? newNodes[0] : newNodes;
|
|
2019
|
-
}
|
|
2020
|
-
function mapArray(source, mapFn, options) {
|
|
2021
|
-
const keyFn = options?.key;
|
|
2022
|
-
const raw = options?.raw || false;
|
|
2023
|
-
return (parent, marker) => {
|
|
2024
|
-
let items = [];
|
|
2025
|
-
let mappedNodes = [];
|
|
2026
|
-
let disposeFns = [];
|
|
2027
|
-
let keyedState = keyFn && !raw ? /* @__PURE__ */ new Map() : null;
|
|
2028
|
-
const endMarker = document.createComment("/list");
|
|
2029
|
-
parent.insertBefore(endMarker, marker || null);
|
|
2030
|
-
effect(() => {
|
|
2031
|
-
const newItems = source() || [];
|
|
2032
|
-
if (keyFn) {
|
|
2033
|
-
reconcileKeyed(parent, endMarker, items, newItems, mappedNodes, disposeFns, mapFn, keyFn, keyedState);
|
|
2034
|
-
} else {
|
|
2035
|
-
reconcileList(parent, endMarker, items, newItems, mappedNodes, disposeFns, mapFn);
|
|
2036
|
-
}
|
|
2037
|
-
items = newItems.length > 0 ? newItems.slice() : newItems;
|
|
2038
|
-
});
|
|
2039
|
-
return endMarker;
|
|
2040
|
-
};
|
|
2041
|
-
}
|
|
2042
|
-
function reconcileList(parent, endMarker, oldItems, newItems, mappedNodes, disposeFns, mapFn) {
|
|
2043
|
-
const newLen = newItems.length;
|
|
2044
|
-
const oldLen = oldItems.length;
|
|
2045
|
-
if (newLen === 0) {
|
|
2046
|
-
if (oldLen > 0) {
|
|
2047
|
-
for (let i = 0; i < oldLen; i++) {
|
|
2048
|
-
if (disposeFns[i]) disposeFns[i]();
|
|
2049
|
-
}
|
|
2050
|
-
for (let i = oldLen - 1; i >= 0; i--) {
|
|
2051
|
-
const node = mappedNodes[i];
|
|
2052
|
-
if (node) {
|
|
2053
|
-
if (node._componentCtx || node._dispose || node._propEffects) {
|
|
2054
|
-
disposeTree(node);
|
|
2055
|
-
}
|
|
2056
|
-
if (node.parentNode === parent) parent.removeChild(node);
|
|
2057
|
-
}
|
|
2058
|
-
}
|
|
2059
|
-
mappedNodes.length = 0;
|
|
2060
|
-
disposeFns.length = 0;
|
|
2061
|
-
}
|
|
2062
|
-
return;
|
|
2063
|
-
}
|
|
2064
|
-
if (oldLen === 0) {
|
|
2065
|
-
const frag = document.createDocumentFragment();
|
|
2066
|
-
for (let i = 0; i < newLen; i++) {
|
|
2067
|
-
const item = newItems[i];
|
|
2068
|
-
const node = _createItemScope((dispose) => {
|
|
2069
|
-
disposeFns[i] = dispose;
|
|
2070
|
-
return mapFn(item, i);
|
|
2071
|
-
});
|
|
2072
|
-
mappedNodes[i] = node;
|
|
2073
|
-
frag.appendChild(node);
|
|
2074
|
-
}
|
|
2075
|
-
parent.insertBefore(frag, endMarker);
|
|
2076
|
-
return;
|
|
2077
|
-
}
|
|
2078
|
-
let start = 0;
|
|
2079
|
-
const minLen = Math.min(oldLen, newLen);
|
|
2080
|
-
while (start < minLen && oldItems[start] === newItems[start]) start++;
|
|
2081
|
-
if (start === oldLen && start === newLen) return;
|
|
2082
|
-
let oldEnd = oldLen - 1;
|
|
2083
|
-
let newEnd = newLen - 1;
|
|
2084
|
-
while (oldEnd >= start && newEnd >= start && oldItems[oldEnd] === newItems[newEnd]) {
|
|
2085
|
-
oldEnd--;
|
|
2086
|
-
newEnd--;
|
|
2087
|
-
}
|
|
2088
|
-
const newMapped = new Array(newLen);
|
|
2089
|
-
const newDispose = new Array(newLen);
|
|
2090
|
-
for (let i = 0; i < start; i++) {
|
|
2091
|
-
newMapped[i] = mappedNodes[i];
|
|
2092
|
-
newDispose[i] = disposeFns[i];
|
|
2093
|
-
}
|
|
2094
|
-
for (let i = newEnd + 1; i < newLen; i++) {
|
|
2095
|
-
const oldI = oldEnd + 1 + (i - newEnd - 1);
|
|
2096
|
-
newMapped[i] = mappedNodes[oldI];
|
|
2097
|
-
newDispose[i] = disposeFns[oldI];
|
|
2098
|
-
}
|
|
2099
|
-
const midNewLen = newEnd - start + 1;
|
|
2100
|
-
const midOldLen = oldEnd - start + 1;
|
|
2101
|
-
if (midNewLen === 0) {
|
|
2102
|
-
for (let i = start; i <= oldEnd; i++) {
|
|
2103
|
-
disposeFns[i]?.();
|
|
2104
|
-
if (mappedNodes[i]?.parentNode) mappedNodes[i].parentNode.removeChild(mappedNodes[i]);
|
|
2105
|
-
}
|
|
2106
|
-
} else if (midOldLen === 0) {
|
|
2107
|
-
const marker = start < newLen && newMapped[newEnd + 1] ? newMapped[newEnd + 1] : endMarker;
|
|
2108
|
-
const frag = document.createDocumentFragment();
|
|
2109
|
-
for (let i = start; i <= newEnd; i++) {
|
|
2110
|
-
const item = newItems[i];
|
|
2111
|
-
const idx = i;
|
|
2112
|
-
newMapped[i] = _createItemScope((dispose) => {
|
|
2113
|
-
newDispose[idx] = dispose;
|
|
2114
|
-
return mapFn(item, idx);
|
|
2115
|
-
});
|
|
2116
|
-
frag.appendChild(newMapped[i]);
|
|
2117
|
-
}
|
|
2118
|
-
parent.insertBefore(frag, marker);
|
|
2119
|
-
} else {
|
|
2120
|
-
_reconcileMiddle(
|
|
2121
|
-
parent,
|
|
2122
|
-
endMarker,
|
|
2123
|
-
oldItems,
|
|
2124
|
-
newItems,
|
|
2125
|
-
mappedNodes,
|
|
2126
|
-
disposeFns,
|
|
2127
|
-
mapFn,
|
|
2128
|
-
start,
|
|
2129
|
-
oldEnd,
|
|
2130
|
-
newEnd,
|
|
2131
|
-
newMapped,
|
|
2132
|
-
newDispose
|
|
2133
|
-
);
|
|
2134
|
-
}
|
|
2135
|
-
mappedNodes.length = newLen;
|
|
2136
|
-
disposeFns.length = newLen;
|
|
2137
|
-
for (let i = 0; i < newLen; i++) {
|
|
2138
|
-
mappedNodes[i] = newMapped[i];
|
|
2139
|
-
disposeFns[i] = newDispose[i];
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
function _reconcileMiddle(parent, endMarker, oldItems, newItems, mappedNodes, disposeFns, mapFn, start, oldEnd, newEnd, newMapped, newDispose) {
|
|
2143
|
-
const oldIdxMap = /* @__PURE__ */ new Map();
|
|
2144
|
-
for (let i = start; i <= oldEnd; i++) {
|
|
2145
|
-
oldIdxMap.set(oldItems[i], i);
|
|
2146
|
-
}
|
|
2147
|
-
const midLen = newEnd - start + 1;
|
|
2148
|
-
const oldIndices = new Int32Array(midLen);
|
|
2149
|
-
oldIndices.fill(-1);
|
|
2150
|
-
for (let i = start; i <= newEnd; i++) {
|
|
2151
|
-
const oldIdx = oldIdxMap.get(newItems[i]);
|
|
2152
|
-
if (oldIdx !== void 0) {
|
|
2153
|
-
oldIdxMap.delete(newItems[i]);
|
|
2154
|
-
newMapped[i] = mappedNodes[oldIdx];
|
|
2155
|
-
newDispose[i] = disposeFns[oldIdx];
|
|
2156
|
-
oldIndices[i - start] = oldIdx;
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
for (const [, oldIdx] of oldIdxMap) {
|
|
2160
|
-
disposeFns[oldIdx]?.();
|
|
2161
|
-
if (mappedNodes[oldIdx]?.parentNode) mappedNodes[oldIdx].parentNode.removeChild(mappedNodes[oldIdx]);
|
|
2162
|
-
}
|
|
2163
|
-
const reusedCount = midLen - _countNeg1(oldIndices, midLen);
|
|
2164
|
-
const inLIS = new Uint8Array(midLen);
|
|
2165
|
-
if (reusedCount > 1) {
|
|
2166
|
-
const seq = new Int32Array(reusedCount);
|
|
2167
|
-
const seqToMid = new Int32Array(reusedCount);
|
|
2168
|
-
let k = 0;
|
|
2169
|
-
for (let i = 0; i < midLen; i++) {
|
|
2170
|
-
if (oldIndices[i] !== -1) {
|
|
2171
|
-
seq[k] = oldIndices[i];
|
|
2172
|
-
seqToMid[k] = i;
|
|
2173
|
-
k++;
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
const lisResult = _lis(seq, reusedCount);
|
|
2177
|
-
for (let i = 0; i < lisResult.length; i++) {
|
|
2178
|
-
inLIS[seqToMid[lisResult[i]]] = 1;
|
|
2179
|
-
}
|
|
2180
|
-
} else if (reusedCount === 1) {
|
|
2181
|
-
for (let i = 0; i < midLen; i++) {
|
|
2182
|
-
if (oldIndices[i] !== -1) {
|
|
2183
|
-
inLIS[i] = 1;
|
|
2184
|
-
break;
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2187
|
-
}
|
|
2188
|
-
for (let i = start; i <= newEnd; i++) {
|
|
2189
|
-
if (!newMapped[i]) {
|
|
2190
|
-
const item = newItems[i];
|
|
2191
|
-
const idx = i;
|
|
2192
|
-
newMapped[i] = _createItemScope((dispose) => {
|
|
2193
|
-
newDispose[idx] = dispose;
|
|
2194
|
-
return mapFn(item, idx);
|
|
2195
|
-
});
|
|
2196
|
-
}
|
|
2197
|
-
}
|
|
2198
|
-
let nextSibling = newEnd + 1 < newMapped.length && newMapped[newEnd + 1] ? newMapped[newEnd + 1] : endMarker;
|
|
2199
|
-
for (let i = newEnd; i >= start; i--) {
|
|
2200
|
-
const mi = i - start;
|
|
2201
|
-
if (oldIndices[mi] === -1 || !inLIS[mi]) {
|
|
2202
|
-
if (nextSibling && nextSibling.parentNode !== parent) nextSibling = endMarker;
|
|
2203
|
-
parent.insertBefore(newMapped[i], nextSibling);
|
|
2204
|
-
}
|
|
2205
|
-
nextSibling = newMapped[i];
|
|
2206
|
-
}
|
|
2207
|
-
}
|
|
2208
|
-
function _countNeg1(arr, len) {
|
|
2209
|
-
let c = 0;
|
|
2210
|
-
for (let i = 0; i < len; i++) if (arr[i] === -1) c++;
|
|
2211
|
-
return c;
|
|
2212
|
-
}
|
|
2213
|
-
function _lis(arr, len) {
|
|
2214
|
-
if (len === 0) return [];
|
|
2215
|
-
if (len === 1) return [0];
|
|
2216
|
-
const tails = new Int32Array(len);
|
|
2217
|
-
const predecessors = new Int32Array(len);
|
|
2218
|
-
let tailLen = 1;
|
|
2219
|
-
tails[0] = 0;
|
|
2220
|
-
predecessors[0] = -1;
|
|
2221
|
-
for (let i = 1; i < len; i++) {
|
|
2222
|
-
if (arr[i] > arr[tails[tailLen - 1]]) {
|
|
2223
|
-
predecessors[i] = tails[tailLen - 1];
|
|
2224
|
-
tails[tailLen++] = i;
|
|
2225
|
-
} else {
|
|
2226
|
-
let lo = 0, hi = tailLen - 1;
|
|
2227
|
-
while (lo < hi) {
|
|
2228
|
-
const mid = lo + hi >> 1;
|
|
2229
|
-
if (arr[tails[mid]] < arr[i]) lo = mid + 1;
|
|
2230
|
-
else hi = mid;
|
|
2231
|
-
}
|
|
2232
|
-
tails[lo] = i;
|
|
2233
|
-
predecessors[i] = lo > 0 ? tails[lo - 1] : -1;
|
|
2234
|
-
}
|
|
2235
|
-
}
|
|
2236
|
-
const result = new Array(tailLen);
|
|
2237
|
-
let k = tails[tailLen - 1];
|
|
2238
|
-
for (let i = tailLen - 1; i >= 0; i--) {
|
|
2239
|
-
result[i] = k;
|
|
2240
|
-
k = predecessors[k];
|
|
2241
|
-
}
|
|
2242
|
-
return result;
|
|
2243
|
-
}
|
|
2244
|
-
function reconcileKeyed(parent, endMarker, oldItems, newItems, mappedNodes, disposeFns, mapFn, keyFn, keyedState) {
|
|
2245
|
-
const newLen = newItems.length;
|
|
2246
|
-
const oldLen = oldItems.length;
|
|
2247
|
-
if (newLen === 0) {
|
|
2248
|
-
if (oldLen > 0) {
|
|
2249
|
-
for (let i = 0; i < oldLen; i++) {
|
|
2250
|
-
if (disposeFns[i]) disposeFns[i]();
|
|
2251
|
-
}
|
|
2252
|
-
for (let i = oldLen - 1; i >= 0; i--) {
|
|
2253
|
-
const node = mappedNodes[i];
|
|
2254
|
-
if (node) {
|
|
2255
|
-
if (node._componentCtx || node._dispose || node._propEffects) {
|
|
2256
|
-
disposeTree(node);
|
|
2257
|
-
}
|
|
2258
|
-
if (node.parentNode === parent) parent.removeChild(node);
|
|
2259
|
-
}
|
|
2260
|
-
}
|
|
2261
|
-
mappedNodes.length = 0;
|
|
2262
|
-
disposeFns.length = 0;
|
|
2263
|
-
if (keyedState) keyedState.clear();
|
|
2264
|
-
}
|
|
2265
|
-
return;
|
|
2266
|
-
}
|
|
2267
|
-
if (oldLen === 0) {
|
|
2268
|
-
const frag = document.createDocumentFragment();
|
|
2269
|
-
for (let i = 0; i < newLen; i++) {
|
|
2270
|
-
const item = newItems[i];
|
|
2271
|
-
const idx = i;
|
|
2272
|
-
let accessor;
|
|
2273
|
-
if (keyedState) {
|
|
2274
|
-
const key = keyFn(item);
|
|
2275
|
-
const itemSig = signal(item);
|
|
2276
|
-
accessor = itemSig;
|
|
2277
|
-
keyedState.set(key, { itemSig });
|
|
2278
|
-
} else {
|
|
2279
|
-
accessor = item;
|
|
2280
|
-
}
|
|
2281
|
-
const node = _createItemScope((dispose) => {
|
|
2282
|
-
disposeFns[idx] = dispose;
|
|
2283
|
-
return mapFn(accessor, idx);
|
|
2284
|
-
});
|
|
2285
|
-
mappedNodes[i] = node;
|
|
2286
|
-
frag.appendChild(node);
|
|
2287
|
-
}
|
|
2288
|
-
parent.insertBefore(frag, endMarker);
|
|
2289
|
-
return;
|
|
2290
|
-
}
|
|
2291
|
-
let start = 0;
|
|
2292
|
-
const minLen = Math.min(oldLen, newLen);
|
|
2293
|
-
while (start < minLen) {
|
|
2294
|
-
if (oldItems[start] === newItems[start]) {
|
|
2295
|
-
start++;
|
|
2296
|
-
continue;
|
|
2297
|
-
}
|
|
2298
|
-
const oldKey = keyFn(oldItems[start]);
|
|
2299
|
-
const newKey = keyFn(newItems[start]);
|
|
2300
|
-
if (oldKey !== newKey) break;
|
|
2301
|
-
if (keyedState) keyedState.get(oldKey).itemSig.set(newItems[start]);
|
|
2302
|
-
start++;
|
|
2303
|
-
}
|
|
2304
|
-
let oldEnd = oldLen - 1;
|
|
2305
|
-
let newEnd = newLen - 1;
|
|
2306
|
-
while (oldEnd >= start && newEnd >= start) {
|
|
2307
|
-
if (oldItems[oldEnd] === newItems[newEnd]) {
|
|
2308
|
-
oldEnd--;
|
|
2309
|
-
newEnd--;
|
|
2310
|
-
continue;
|
|
2311
|
-
}
|
|
2312
|
-
const oldKey = keyFn(oldItems[oldEnd]);
|
|
2313
|
-
const newKey = keyFn(newItems[newEnd]);
|
|
2314
|
-
if (oldKey !== newKey) break;
|
|
2315
|
-
if (keyedState) keyedState.get(oldKey).itemSig.set(newItems[newEnd]);
|
|
2316
|
-
oldEnd--;
|
|
2317
|
-
newEnd--;
|
|
2318
|
-
}
|
|
2319
|
-
if (start > oldEnd && start > newEnd) {
|
|
2320
|
-
return;
|
|
2321
|
-
}
|
|
2322
|
-
const newMapped = new Array(newLen);
|
|
2323
|
-
const newDispose = new Array(newLen);
|
|
2324
|
-
for (let i = 0; i < start; i++) {
|
|
2325
|
-
newMapped[i] = mappedNodes[i];
|
|
2326
|
-
newDispose[i] = disposeFns[i];
|
|
2327
|
-
}
|
|
2328
|
-
for (let i = newEnd + 1; i < newLen; i++) {
|
|
2329
|
-
const oldI = oldEnd + 1 + (i - newEnd - 1);
|
|
2330
|
-
newMapped[i] = mappedNodes[oldI];
|
|
2331
|
-
newDispose[i] = disposeFns[oldI];
|
|
2332
|
-
}
|
|
2333
|
-
const midNewLen = newEnd - start + 1;
|
|
2334
|
-
const midOldLen = oldEnd - start + 1;
|
|
2335
|
-
if (midOldLen === 0) {
|
|
2336
|
-
const marker = newEnd + 1 < newLen && newMapped[newEnd + 1] ? newMapped[newEnd + 1] : endMarker;
|
|
2337
|
-
const frag = document.createDocumentFragment();
|
|
2338
|
-
for (let i = start; i <= newEnd; i++) {
|
|
2339
|
-
const item = newItems[i];
|
|
2340
|
-
const idx = i;
|
|
2341
|
-
let accessor;
|
|
2342
|
-
if (keyedState) {
|
|
2343
|
-
const key = keyFn(item);
|
|
2344
|
-
const itemSig = signal(item);
|
|
2345
|
-
accessor = itemSig;
|
|
2346
|
-
keyedState.set(key, { itemSig });
|
|
2347
|
-
} else {
|
|
2348
|
-
accessor = item;
|
|
2349
|
-
}
|
|
2350
|
-
newMapped[i] = _createItemScope((dispose) => {
|
|
2351
|
-
newDispose[idx] = dispose;
|
|
2352
|
-
return mapFn(accessor, idx);
|
|
2353
|
-
});
|
|
2354
|
-
frag.appendChild(newMapped[i]);
|
|
2355
|
-
}
|
|
2356
|
-
parent.insertBefore(frag, marker);
|
|
2357
|
-
_copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen);
|
|
2358
|
-
return;
|
|
2359
|
-
}
|
|
2360
|
-
if (midNewLen === 0) {
|
|
2361
|
-
for (let i = start; i <= oldEnd; i++) {
|
|
2362
|
-
disposeFns[i]?.();
|
|
2363
|
-
if (mappedNodes[i]?.parentNode) parent.removeChild(mappedNodes[i]);
|
|
2364
|
-
if (keyedState) keyedState.delete(keyFn(oldItems[i]));
|
|
2365
|
-
}
|
|
2366
|
-
_copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen);
|
|
2367
|
-
return;
|
|
2368
|
-
}
|
|
2369
|
-
const oldKeyMap = /* @__PURE__ */ new Map();
|
|
2370
|
-
for (let i = start; i <= oldEnd; i++) {
|
|
2371
|
-
oldKeyMap.set(keyFn(oldItems[i]), i);
|
|
2372
|
-
}
|
|
2373
|
-
const oldIndices = new Int32Array(midNewLen);
|
|
2374
|
-
oldIndices.fill(-1);
|
|
2375
|
-
for (let i = start; i <= newEnd; i++) {
|
|
2376
|
-
const key = keyFn(newItems[i]);
|
|
2377
|
-
const oldIdx = oldKeyMap.get(key);
|
|
2378
|
-
if (oldIdx !== void 0) {
|
|
2379
|
-
oldKeyMap.delete(key);
|
|
2380
|
-
newMapped[i] = mappedNodes[oldIdx];
|
|
2381
|
-
newDispose[i] = disposeFns[oldIdx];
|
|
2382
|
-
oldIndices[i - start] = oldIdx;
|
|
2383
|
-
if (keyedState && newItems[i] !== oldItems[oldIdx]) {
|
|
2384
|
-
keyedState.get(key).itemSig.set(newItems[i]);
|
|
2385
|
-
}
|
|
2386
|
-
}
|
|
2387
|
-
}
|
|
2388
|
-
for (const [key, oldIdx] of oldKeyMap) {
|
|
2389
|
-
disposeFns[oldIdx]?.();
|
|
2390
|
-
if (mappedNodes[oldIdx]?.parentNode) parent.removeChild(mappedNodes[oldIdx]);
|
|
2391
|
-
if (keyedState) keyedState.delete(key);
|
|
2392
|
-
}
|
|
2393
|
-
for (let i = start; i <= newEnd; i++) {
|
|
2394
|
-
if (!newMapped[i]) {
|
|
2395
|
-
const item = newItems[i];
|
|
2396
|
-
const idx = i;
|
|
2397
|
-
let accessor;
|
|
2398
|
-
if (keyedState) {
|
|
2399
|
-
const key = keyFn(item);
|
|
2400
|
-
const itemSig = signal(item);
|
|
2401
|
-
accessor = itemSig;
|
|
2402
|
-
keyedState.set(key, { itemSig });
|
|
2403
|
-
} else {
|
|
2404
|
-
accessor = item;
|
|
2405
|
-
}
|
|
2406
|
-
newMapped[i] = _createItemScope((dispose) => {
|
|
2407
|
-
newDispose[idx] = dispose;
|
|
2408
|
-
return mapFn(accessor, idx);
|
|
2409
|
-
});
|
|
2410
|
-
}
|
|
2411
|
-
}
|
|
2412
|
-
let reusedCount = 0;
|
|
2413
|
-
let alreadySorted = true;
|
|
2414
|
-
let lastOldIdx = -1;
|
|
2415
|
-
for (let i = 0; i < midNewLen; i++) {
|
|
2416
|
-
if (oldIndices[i] !== -1) {
|
|
2417
|
-
reusedCount++;
|
|
2418
|
-
if (oldIndices[i] <= lastOldIdx) alreadySorted = false;
|
|
2419
|
-
lastOldIdx = oldIndices[i];
|
|
2420
|
-
}
|
|
2421
|
-
}
|
|
2422
|
-
const inLIS = new Uint8Array(midNewLen);
|
|
2423
|
-
if (alreadySorted) {
|
|
2424
|
-
for (let i = 0; i < midNewLen; i++) {
|
|
2425
|
-
if (oldIndices[i] !== -1) inLIS[i] = 1;
|
|
2426
|
-
}
|
|
2427
|
-
} else if (reusedCount > 1) {
|
|
2428
|
-
const seq = new Int32Array(reusedCount);
|
|
2429
|
-
const seqToMid = new Int32Array(reusedCount);
|
|
2430
|
-
let k = 0;
|
|
2431
|
-
for (let i = 0; i < midNewLen; i++) {
|
|
2432
|
-
if (oldIndices[i] !== -1) {
|
|
2433
|
-
seq[k] = oldIndices[i];
|
|
2434
|
-
seqToMid[k] = i;
|
|
2435
|
-
k++;
|
|
2436
|
-
}
|
|
2437
|
-
}
|
|
2438
|
-
const lisResult = _lis(seq, reusedCount);
|
|
2439
|
-
for (let i = 0; i < lisResult.length; i++) {
|
|
2440
|
-
inLIS[seqToMid[lisResult[i]]] = 1;
|
|
2441
|
-
}
|
|
2442
|
-
} else if (reusedCount === 1) {
|
|
2443
|
-
for (let i = 0; i < midNewLen; i++) {
|
|
2444
|
-
if (oldIndices[i] !== -1) {
|
|
2445
|
-
inLIS[i] = 1;
|
|
2446
|
-
break;
|
|
2447
|
-
}
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
let nextSibling = newEnd + 1 < newMapped.length && newMapped[newEnd + 1] ? newMapped[newEnd + 1] : endMarker;
|
|
2451
|
-
for (let i = newEnd; i >= start; i--) {
|
|
2452
|
-
const mi = i - start;
|
|
2453
|
-
if (oldIndices[mi] === -1 || !inLIS[mi]) {
|
|
2454
|
-
if (nextSibling && nextSibling.parentNode !== parent) nextSibling = endMarker;
|
|
2455
|
-
parent.insertBefore(newMapped[i], nextSibling);
|
|
2456
|
-
}
|
|
2457
|
-
nextSibling = newMapped[i];
|
|
2458
|
-
}
|
|
2459
|
-
_copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen);
|
|
2460
|
-
}
|
|
2461
|
-
function _copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen) {
|
|
2462
|
-
mappedNodes.length = newLen;
|
|
2463
|
-
disposeFns.length = newLen;
|
|
2464
|
-
for (let i = 0; i < newLen; i++) {
|
|
2465
|
-
mappedNodes[i] = newMapped[i];
|
|
2466
|
-
disposeFns[i] = newDispose[i];
|
|
2467
|
-
}
|
|
2468
|
-
}
|
|
2469
|
-
function spread(el, props) {
|
|
2470
|
-
for (const key in props) {
|
|
2471
|
-
const value = props[key];
|
|
2472
|
-
if (key.startsWith("on") && key.length > 2) {
|
|
2473
|
-
const event = key.slice(2).toLowerCase();
|
|
2474
|
-
el.addEventListener(event, value);
|
|
2475
|
-
continue;
|
|
2476
|
-
}
|
|
2477
|
-
if (typeof value === "function" && !key.startsWith("on")) {
|
|
2478
|
-
if (key === "class" || key === "className") {
|
|
2479
|
-
effect(() => {
|
|
2480
|
-
el.className = value() || "";
|
|
2481
|
-
});
|
|
2482
|
-
} else if (key === "style" && typeof value() === "object") {
|
|
2483
|
-
effect(() => {
|
|
2484
|
-
const styles = value();
|
|
2485
|
-
for (const prop in styles) {
|
|
2486
|
-
el.style[prop] = styles[prop] ?? "";
|
|
2487
|
-
}
|
|
2488
|
-
});
|
|
2489
|
-
} else {
|
|
2490
|
-
effect(() => {
|
|
2491
|
-
setProp2(el, key, value());
|
|
2492
|
-
});
|
|
2493
|
-
}
|
|
2494
|
-
} else {
|
|
2495
|
-
setProp2(el, key, value);
|
|
2496
|
-
}
|
|
2497
|
-
}
|
|
2498
|
-
}
|
|
2499
|
-
function setProp2(el, key, value) {
|
|
2500
|
-
if (key === "ref") {
|
|
2501
|
-
if (typeof value === "function") value(el);
|
|
2502
|
-
else if (value && typeof value === "object") value.current = el;
|
|
2503
|
-
return;
|
|
2504
|
-
}
|
|
2505
|
-
if (key === "key") return;
|
|
2506
|
-
if (URL_ATTRS.has(key) || URL_ATTRS.has(key.toLowerCase())) {
|
|
2507
|
-
if (!isSafeUrl(value)) {
|
|
2508
|
-
if (typeof console !== "undefined") {
|
|
2509
|
-
console.warn(`[what] Blocked unsafe URL in "${key}" attribute: ${value}`);
|
|
2510
|
-
}
|
|
2511
|
-
return;
|
|
2512
|
-
}
|
|
2513
|
-
}
|
|
2514
|
-
if (key === "class" || key === "className") {
|
|
2515
|
-
el.className = value || "";
|
|
2516
|
-
} else if (key === "dangerouslySetInnerHTML") {
|
|
2517
|
-
el.innerHTML = value?.__html ?? "";
|
|
2518
|
-
} else if (key === "innerHTML") {
|
|
2519
|
-
if (value && typeof value === "object" && "__html" in value) {
|
|
2520
|
-
el.innerHTML = value.__html ?? "";
|
|
2521
|
-
} else {
|
|
2522
|
-
if (typeof console !== "undefined" && value != null && value !== "") {
|
|
2523
|
-
console.warn(
|
|
2524
|
-
'[what] Plain string innerHTML is not allowed. Use { __html: "..." } or dangerouslySetInnerHTML={{ __html: "..." }} instead.'
|
|
2525
|
-
);
|
|
2526
|
-
}
|
|
2527
|
-
}
|
|
2528
|
-
} else if (key === "style") {
|
|
2529
|
-
if (typeof value === "string") {
|
|
2530
|
-
el.style.cssText = value;
|
|
2531
|
-
} else if (typeof value === "object") {
|
|
2532
|
-
for (const prop in value) {
|
|
2533
|
-
el.style[prop] = value[prop] ?? "";
|
|
2534
|
-
}
|
|
2535
|
-
}
|
|
2536
|
-
} else if (key.startsWith("data-") || key.startsWith("aria-")) {
|
|
2537
|
-
el.setAttribute(key, value);
|
|
2538
|
-
} else if (typeof value === "boolean") {
|
|
2539
|
-
if (value) el.setAttribute(key, "");
|
|
2540
|
-
else el.removeAttribute(key);
|
|
2541
|
-
} else if (key in el) {
|
|
2542
|
-
el[key] = value;
|
|
2543
|
-
} else {
|
|
2544
|
-
el.setAttribute(key, value);
|
|
2545
|
-
}
|
|
2546
|
-
}
|
|
2547
|
-
var delegatedEvents = /* @__PURE__ */ new Set();
|
|
2548
|
-
function delegateEvents(eventNames) {
|
|
2549
|
-
for (const name of eventNames) {
|
|
2550
|
-
if (delegatedEvents.has(name)) continue;
|
|
2551
|
-
delegatedEvents.add(name);
|
|
2552
|
-
document.addEventListener(name, (e) => {
|
|
2553
|
-
let node = e.target;
|
|
2554
|
-
const key = "$$" + name;
|
|
2555
|
-
while (node) {
|
|
2556
|
-
const handler = node[key];
|
|
2557
|
-
if (handler) {
|
|
2558
|
-
handler(e);
|
|
2559
|
-
if (e.cancelBubble) return;
|
|
2560
|
-
}
|
|
2561
|
-
node = node.parentNode;
|
|
2562
|
-
}
|
|
2563
|
-
});
|
|
2564
|
-
}
|
|
2565
|
-
}
|
|
2566
|
-
function on(el, event, handler) {
|
|
2567
|
-
el.addEventListener(event, handler);
|
|
2568
|
-
return () => el.removeEventListener(event, handler);
|
|
2569
|
-
}
|
|
2570
|
-
function classList(el, classes) {
|
|
2571
|
-
effect(() => {
|
|
2572
|
-
for (const name in classes) {
|
|
2573
|
-
const value = typeof classes[name] === "function" ? classes[name]() : classes[name];
|
|
2574
|
-
el.classList.toggle(name, !!value);
|
|
2575
|
-
}
|
|
2576
|
-
});
|
|
2577
|
-
}
|
|
2578
|
-
var _isHydrating = false;
|
|
2579
|
-
var _hydrationCursor = null;
|
|
2580
|
-
function isHydrating() {
|
|
2581
|
-
return _isHydrating;
|
|
2582
|
-
}
|
|
2583
|
-
function hydrate(vnode, container) {
|
|
2584
|
-
_isHydrating = true;
|
|
2585
|
-
_hydrationCursor = { parent: container, index: 0 };
|
|
1
|
+
import {
|
|
2
|
+
_$createComponent,
|
|
3
|
+
_$templateImpl,
|
|
4
|
+
_setTextInsertHook,
|
|
5
|
+
classList,
|
|
6
|
+
delegateEvents,
|
|
7
|
+
hydrate,
|
|
8
|
+
insert,
|
|
9
|
+
isHydrating,
|
|
10
|
+
mapArray,
|
|
11
|
+
on,
|
|
12
|
+
setProp,
|
|
13
|
+
spread,
|
|
14
|
+
svgTemplate,
|
|
15
|
+
template
|
|
16
|
+
} from "./chunk-M7UEET5O.js";
|
|
17
|
+
import {
|
|
18
|
+
ErrorBoundary,
|
|
19
|
+
For,
|
|
20
|
+
Island,
|
|
21
|
+
Match,
|
|
22
|
+
Portal,
|
|
23
|
+
Show,
|
|
24
|
+
Suspense,
|
|
25
|
+
Switch,
|
|
26
|
+
__DEV__,
|
|
27
|
+
__drainPreinstallBuffer,
|
|
28
|
+
__setDevToolsHooks,
|
|
29
|
+
batch,
|
|
30
|
+
cls,
|
|
31
|
+
computed,
|
|
32
|
+
createRoot,
|
|
33
|
+
debounce,
|
|
34
|
+
each,
|
|
35
|
+
effect,
|
|
36
|
+
flushSync,
|
|
37
|
+
getCurrentComponent,
|
|
38
|
+
getOwner,
|
|
39
|
+
lazy,
|
|
40
|
+
memo,
|
|
41
|
+
memo2,
|
|
42
|
+
mount,
|
|
43
|
+
onCleanup,
|
|
44
|
+
runWithOwner,
|
|
45
|
+
signal,
|
|
46
|
+
style,
|
|
47
|
+
throttle,
|
|
48
|
+
transition,
|
|
49
|
+
untrack,
|
|
50
|
+
useClickOutside,
|
|
51
|
+
useLocalStorage,
|
|
52
|
+
useMediaQuery
|
|
53
|
+
} from "./chunk-AW3BAPIK.js";
|
|
54
|
+
import {
|
|
55
|
+
Fragment,
|
|
56
|
+
h,
|
|
57
|
+
html
|
|
58
|
+
} from "./chunk-AZP2EOGX.js";
|
|
59
|
+
|
|
60
|
+
// packages/core/src/server-context.js
|
|
61
|
+
var _current = null;
|
|
62
|
+
function getServerContext() {
|
|
63
|
+
return _current;
|
|
64
|
+
}
|
|
65
|
+
function setServerContext(ctx) {
|
|
66
|
+
const prev = _current;
|
|
67
|
+
_current = ctx;
|
|
68
|
+
return prev;
|
|
69
|
+
}
|
|
70
|
+
function runWithServerContext(ctx, fn) {
|
|
71
|
+
const prev = _current;
|
|
72
|
+
_current = ctx;
|
|
2586
73
|
try {
|
|
2587
|
-
|
|
2588
|
-
return result;
|
|
74
|
+
return fn();
|
|
2589
75
|
} finally {
|
|
2590
|
-
|
|
2591
|
-
_hydrationCursor = null;
|
|
76
|
+
_current = prev;
|
|
2592
77
|
}
|
|
2593
78
|
}
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
return node;
|
|
79
|
+
|
|
80
|
+
// packages/core/src/hydration-data.js
|
|
81
|
+
var _cache;
|
|
82
|
+
function __readHydrationData() {
|
|
83
|
+
if (_cache !== void 0) return _cache;
|
|
84
|
+
if (typeof document === "undefined") return _cache = null;
|
|
85
|
+
const el = document.getElementById("__what_data");
|
|
86
|
+
if (!el) return _cache = null;
|
|
87
|
+
try {
|
|
88
|
+
_cache = JSON.parse(el.textContent);
|
|
89
|
+
} catch {
|
|
90
|
+
_cache = null;
|
|
2607
91
|
}
|
|
2608
|
-
return
|
|
92
|
+
return _cache;
|
|
2609
93
|
}
|
|
2610
|
-
function
|
|
2611
|
-
|
|
94
|
+
function __resetHydrationData() {
|
|
95
|
+
_cache = void 0;
|
|
2612
96
|
}
|
|
2613
|
-
function
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
if (existing && existing.nodeType === 3) {
|
|
2621
|
-
if (isDevMode() && existing.textContent !== text) {
|
|
2622
|
-
console.warn(
|
|
2623
|
-
`[what] Hydration mismatch: expected text "${text}", got "${existing.textContent}"`
|
|
2624
|
-
);
|
|
2625
|
-
existing.textContent = text;
|
|
2626
|
-
}
|
|
2627
|
-
return existing;
|
|
2628
|
-
}
|
|
2629
|
-
if (isDevMode()) {
|
|
2630
|
-
console.warn(
|
|
2631
|
-
`[what] Hydration mismatch: expected text node "${text}", got ${existing ? existing.nodeName : "nothing"}. Falling back to client render.`
|
|
2632
|
-
);
|
|
2633
|
-
}
|
|
2634
|
-
const textNode2 = document.createTextNode(text);
|
|
2635
|
-
if (existing) {
|
|
2636
|
-
parent.replaceChild(textNode2, existing);
|
|
2637
|
-
} else {
|
|
2638
|
-
parent.appendChild(textNode2);
|
|
2639
|
-
}
|
|
2640
|
-
return textNode2;
|
|
2641
|
-
}
|
|
2642
|
-
if (typeof vnode === "function") {
|
|
2643
|
-
const initialValue = vnode();
|
|
2644
|
-
let current = hydrateNode(initialValue, parent);
|
|
2645
|
-
effect(() => {
|
|
2646
|
-
const value = vnode();
|
|
2647
|
-
if (!_isHydrating) {
|
|
2648
|
-
current = reconcileInsert(parent, value, current, null);
|
|
2649
|
-
}
|
|
2650
|
-
});
|
|
2651
|
-
return current;
|
|
2652
|
-
}
|
|
2653
|
-
if (Array.isArray(vnode)) {
|
|
2654
|
-
const nodes = [];
|
|
2655
|
-
for (const child of vnode) {
|
|
2656
|
-
const node = hydrateNode(child, parent);
|
|
2657
|
-
if (node) nodes.push(node);
|
|
2658
|
-
}
|
|
2659
|
-
return nodes.length === 1 ? nodes[0] : nodes;
|
|
2660
|
-
}
|
|
2661
|
-
if (typeof vnode === "object" && vnode._vnode) {
|
|
2662
|
-
if (typeof vnode.tag === "function") {
|
|
2663
|
-
const componentStack2 = getComponentStack();
|
|
2664
|
-
const Component = vnode.tag;
|
|
2665
|
-
const props = vnode.props || {};
|
|
2666
|
-
const children = vnode.children || [];
|
|
2667
|
-
const ctx = {
|
|
2668
|
-
hooks: [],
|
|
2669
|
-
hookIndex: 0,
|
|
2670
|
-
effects: [],
|
|
2671
|
-
cleanups: [],
|
|
2672
|
-
mounted: false,
|
|
2673
|
-
disposed: false,
|
|
2674
|
-
Component,
|
|
2675
|
-
_parentCtx: componentStack2[componentStack2.length - 1] || null,
|
|
2676
|
-
_errorBoundary: null
|
|
2677
|
-
};
|
|
2678
|
-
componentStack2.push(ctx);
|
|
2679
|
-
let result;
|
|
2680
|
-
try {
|
|
2681
|
-
const propsChildren = children.length === 0 ? void 0 : children.length === 1 ? children[0] : children;
|
|
2682
|
-
result = Component({ ...props, children: propsChildren });
|
|
2683
|
-
} catch (error) {
|
|
2684
|
-
componentStack2.pop();
|
|
2685
|
-
console.error("[what] Error in component during hydration:", Component.name || "Anonymous", error);
|
|
2686
|
-
return null;
|
|
2687
|
-
}
|
|
2688
|
-
componentStack2.pop();
|
|
2689
|
-
ctx.mounted = true;
|
|
2690
|
-
if (ctx._mountCallbacks) {
|
|
2691
|
-
queueMicrotask(() => {
|
|
2692
|
-
if (ctx.disposed) return;
|
|
2693
|
-
for (const fn of ctx._mountCallbacks) {
|
|
2694
|
-
try {
|
|
2695
|
-
fn();
|
|
2696
|
-
} catch (e) {
|
|
2697
|
-
console.error("[what] onMount error:", e);
|
|
2698
|
-
}
|
|
2699
|
-
}
|
|
2700
|
-
});
|
|
2701
|
-
}
|
|
2702
|
-
return hydrateNode(result, parent);
|
|
2703
|
-
}
|
|
2704
|
-
const existing = claimNode(parent);
|
|
2705
|
-
const expectedTag = vnode.tag.toUpperCase();
|
|
2706
|
-
if (existing && existing.nodeType === 1 && existing.nodeName === expectedTag) {
|
|
2707
|
-
hydrateElementProps(existing, vnode.props || {});
|
|
2708
|
-
const savedCursor = _hydrationCursor;
|
|
2709
|
-
_hydrationCursor = { parent: existing, index: 0 };
|
|
2710
|
-
const rawInner = vnode.props?.dangerouslySetInnerHTML?.__html;
|
|
2711
|
-
if (rawInner == null) {
|
|
2712
|
-
for (const child of vnode.children) {
|
|
2713
|
-
hydrateNode(child, existing);
|
|
2714
|
-
}
|
|
2715
|
-
}
|
|
2716
|
-
_hydrationCursor = savedCursor;
|
|
2717
|
-
return existing;
|
|
2718
|
-
}
|
|
2719
|
-
if (isDevMode()) {
|
|
2720
|
-
console.warn(
|
|
2721
|
-
`[what] Hydration mismatch: expected <${vnode.tag}>, got ${existing ? existing.nodeName : "nothing"}. Falling back to client render.`
|
|
2722
|
-
);
|
|
2723
|
-
}
|
|
2724
|
-
const newEl = document.createElement(vnode.tag);
|
|
2725
|
-
for (const key in vnode.props || {}) {
|
|
2726
|
-
if (key === "children" || key === "key") continue;
|
|
2727
|
-
setProp2(newEl, key, vnode.props[key]);
|
|
2728
|
-
}
|
|
2729
|
-
for (const child of vnode.children) {
|
|
2730
|
-
reconcileInsert(newEl, child, null, null);
|
|
2731
|
-
}
|
|
2732
|
-
if (existing) {
|
|
2733
|
-
parent.replaceChild(newEl, existing);
|
|
2734
|
-
} else {
|
|
2735
|
-
parent.appendChild(newEl);
|
|
2736
|
-
}
|
|
2737
|
-
return newEl;
|
|
2738
|
-
}
|
|
2739
|
-
if (isDomNode2(vnode)) {
|
|
2740
|
-
return vnode;
|
|
2741
|
-
}
|
|
2742
|
-
const textNode = document.createTextNode(String(vnode));
|
|
2743
|
-
parent.appendChild(textNode);
|
|
2744
|
-
return textNode;
|
|
2745
|
-
}
|
|
2746
|
-
function hydrateElementProps(el, props) {
|
|
2747
|
-
for (const key in props) {
|
|
2748
|
-
if (key === "children" || key === "key" || key === "ref") continue;
|
|
2749
|
-
if (key === "dangerouslySetInnerHTML" || key === "innerHTML") continue;
|
|
2750
|
-
const value = props[key];
|
|
2751
|
-
if (key.startsWith("on") && key.length > 2) {
|
|
2752
|
-
const event = key.slice(2).toLowerCase();
|
|
2753
|
-
el.addEventListener(event, value);
|
|
2754
|
-
continue;
|
|
2755
|
-
}
|
|
2756
|
-
if (key.startsWith("$$")) {
|
|
2757
|
-
el[key] = value;
|
|
2758
|
-
continue;
|
|
2759
|
-
}
|
|
2760
|
-
if (typeof value === "function" && !key.startsWith("on")) {
|
|
2761
|
-
if (key === "class" || key === "className") {
|
|
2762
|
-
effect(() => {
|
|
2763
|
-
el.className = value() || "";
|
|
2764
|
-
});
|
|
2765
|
-
} else if (key === "style" && typeof value() === "object") {
|
|
2766
|
-
effect(() => {
|
|
2767
|
-
const styles = value();
|
|
2768
|
-
for (const prop in styles) {
|
|
2769
|
-
el.style[prop] = styles[prop] ?? "";
|
|
2770
|
-
}
|
|
2771
|
-
});
|
|
2772
|
-
} else {
|
|
2773
|
-
effect(() => {
|
|
2774
|
-
setProp2(el, key, value());
|
|
2775
|
-
});
|
|
2776
|
-
}
|
|
2777
|
-
continue;
|
|
2778
|
-
}
|
|
2779
|
-
if (key === "data-hk") continue;
|
|
2780
|
-
}
|
|
97
|
+
function getLoaderData() {
|
|
98
|
+
const data = __readHydrationData();
|
|
99
|
+
return data ? data.loaderData : void 0;
|
|
100
|
+
}
|
|
101
|
+
function getResource(key) {
|
|
102
|
+
const data = __readHydrationData();
|
|
103
|
+
return data && data.resources ? data.resources[key] : void 0;
|
|
2781
104
|
}
|
|
2782
105
|
|
|
2783
106
|
// packages/core/src/hooks.js
|
|
107
|
+
function useLoaderData() {
|
|
108
|
+
if (typeof document === "undefined") {
|
|
109
|
+
const ctx = getServerContext();
|
|
110
|
+
return ctx ? ctx.loaderData : void 0;
|
|
111
|
+
}
|
|
112
|
+
return getLoaderData();
|
|
113
|
+
}
|
|
2784
114
|
function getCtx(hookName) {
|
|
2785
115
|
const ctx = getCurrentComponent();
|
|
2786
116
|
if (!ctx) {
|
|
@@ -2978,8 +308,49 @@ function onCleanup2(fn) {
|
|
|
2978
308
|
ctx._cleanupCallbacks.push(fn);
|
|
2979
309
|
}
|
|
2980
310
|
function createResource(fetcher, options = {}) {
|
|
2981
|
-
|
|
2982
|
-
|
|
311
|
+
if (typeof document === "undefined") {
|
|
312
|
+
const ctx2 = getServerContext();
|
|
313
|
+
if (ctx2) {
|
|
314
|
+
const key = options.key != null ? options.key : `__r${ctx2.resourceCounter++}`;
|
|
315
|
+
const cached = ctx2.resources.get(key);
|
|
316
|
+
if (cached && cached.status === "ready") {
|
|
317
|
+
const accessor = () => cached.value;
|
|
318
|
+
return [accessor, { loading: () => false, error: () => null, refetch: () => {
|
|
319
|
+
}, mutate: () => {
|
|
320
|
+
} }];
|
|
321
|
+
}
|
|
322
|
+
if (cached && cached.status === "error") {
|
|
323
|
+
const accessor = () => void 0;
|
|
324
|
+
return [accessor, { loading: () => false, error: () => cached.error, refetch: () => {
|
|
325
|
+
}, mutate: () => {
|
|
326
|
+
} }];
|
|
327
|
+
}
|
|
328
|
+
if (!cached) {
|
|
329
|
+
const promise = Promise.resolve().then(() => fetcher(options.source ?? true, {})).then((v) => {
|
|
330
|
+
ctx2.resources.set(key, { status: "ready", value: v });
|
|
331
|
+
}).catch((e) => {
|
|
332
|
+
ctx2.resources.set(key, { status: "error", error: e });
|
|
333
|
+
});
|
|
334
|
+
ctx2.resources.set(key, { status: "pending", promise });
|
|
335
|
+
throw promise;
|
|
336
|
+
}
|
|
337
|
+
throw cached.promise;
|
|
338
|
+
}
|
|
339
|
+
if (options.initialValue != null) {
|
|
340
|
+
const accessor = () => options.initialValue;
|
|
341
|
+
return [accessor, { loading: () => false, error: () => null, refetch: () => {
|
|
342
|
+
}, mutate: () => {
|
|
343
|
+
} }];
|
|
344
|
+
}
|
|
345
|
+
throw Promise.resolve().then(() => fetcher(options.source ?? true, {}));
|
|
346
|
+
}
|
|
347
|
+
let seeded = options.initialValue;
|
|
348
|
+
if (seeded == null && options.key != null) {
|
|
349
|
+
const fromPayload = getResource(options.key);
|
|
350
|
+
if (fromPayload !== void 0) seeded = fromPayload;
|
|
351
|
+
}
|
|
352
|
+
const data = signal(seeded ?? null);
|
|
353
|
+
const loading = signal(seeded == null);
|
|
2983
354
|
const error = signal(null);
|
|
2984
355
|
let controller = null;
|
|
2985
356
|
const refetch = async (source) => {
|
|
@@ -3015,7 +386,7 @@ function createResource(fetcher, options = {}) {
|
|
|
3015
386
|
if (controller) controller.abort();
|
|
3016
387
|
});
|
|
3017
388
|
}
|
|
3018
|
-
if (
|
|
389
|
+
if (seeded == null) {
|
|
3019
390
|
refetch(options.source);
|
|
3020
391
|
}
|
|
3021
392
|
return [data, { loading, error, refetch, mutate: mutate2 }];
|
|
@@ -3065,6 +436,7 @@ function createStore(definition) {
|
|
|
3065
436
|
}
|
|
3066
437
|
for (const [key, fn] of Object.entries(actions)) {
|
|
3067
438
|
actions[key] = (...args) => {
|
|
439
|
+
let result;
|
|
3068
440
|
batch(() => {
|
|
3069
441
|
const proxy = new Proxy({}, {
|
|
3070
442
|
get(_, prop) {
|
|
@@ -3078,8 +450,9 @@ function createStore(definition) {
|
|
|
3078
450
|
return true;
|
|
3079
451
|
}
|
|
3080
452
|
});
|
|
3081
|
-
fn.apply(proxy, args);
|
|
453
|
+
result = fn.apply(proxy, args);
|
|
3082
454
|
});
|
|
455
|
+
return result;
|
|
3083
456
|
};
|
|
3084
457
|
}
|
|
3085
458
|
return function useStore() {
|
|
@@ -3112,7 +485,11 @@ var headState = {
|
|
|
3112
485
|
links: /* @__PURE__ */ new Map()
|
|
3113
486
|
};
|
|
3114
487
|
function Head({ title, meta, link, children }) {
|
|
3115
|
-
if (typeof document === "undefined")
|
|
488
|
+
if (typeof document === "undefined") {
|
|
489
|
+
const ctx = getServerContext();
|
|
490
|
+
if (ctx && ctx.head) writeToSink(ctx.head, { title, meta, link });
|
|
491
|
+
return children ?? null;
|
|
492
|
+
}
|
|
3116
493
|
if (title) {
|
|
3117
494
|
document.title = title;
|
|
3118
495
|
headState.title = title;
|
|
@@ -3131,6 +508,45 @@ function Head({ title, meta, link, children }) {
|
|
|
3131
508
|
}
|
|
3132
509
|
return children || null;
|
|
3133
510
|
}
|
|
511
|
+
function metaKey(attrs) {
|
|
512
|
+
return attrs.name || attrs.property || attrs.httpEquiv || JSON.stringify(attrs);
|
|
513
|
+
}
|
|
514
|
+
function writeToSink(sink, { title, meta, link }) {
|
|
515
|
+
if (title != null) sink.title = title;
|
|
516
|
+
if (meta) {
|
|
517
|
+
for (const attrs of Array.isArray(meta) ? meta : [meta]) {
|
|
518
|
+
sink.metas.set(metaKey(attrs), attrs);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (link) {
|
|
522
|
+
for (const attrs of Array.isArray(link) ? link : [link]) {
|
|
523
|
+
sink.links.set(attrs.rel + (attrs.href || ""), attrs);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
function beginHeadCollection() {
|
|
528
|
+
return { title: null, metas: /* @__PURE__ */ new Map(), links: /* @__PURE__ */ new Map() };
|
|
529
|
+
}
|
|
530
|
+
function endHeadCollection(sink) {
|
|
531
|
+
if (!sink) return "";
|
|
532
|
+
let out = "";
|
|
533
|
+
if (sink.title != null) out += `<title>${escapeHtml(String(sink.title))}</title>`;
|
|
534
|
+
for (const attrs of sink.metas.values()) out += renderHeadTag("meta", attrs);
|
|
535
|
+
for (const attrs of sink.links.values()) out += renderHeadTag("link", attrs);
|
|
536
|
+
return out;
|
|
537
|
+
}
|
|
538
|
+
function renderHeadTag(tag, attrs) {
|
|
539
|
+
let s = `<${tag}`;
|
|
540
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
541
|
+
if (v == null || v === false) continue;
|
|
542
|
+
const name = k === "httpEquiv" ? "http-equiv" : k;
|
|
543
|
+
s += ` ${name}="${escapeHtml(String(v))}"`;
|
|
544
|
+
}
|
|
545
|
+
return s + ">";
|
|
546
|
+
}
|
|
547
|
+
function escapeHtml(str) {
|
|
548
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
549
|
+
}
|
|
3134
550
|
function setHeadTag(tag, key, attrs) {
|
|
3135
551
|
const existing = document.head.querySelector(`[data-what-head="${key}"]`);
|
|
3136
552
|
if (existing) {
|
|
@@ -5907,18 +3323,18 @@ function levenshtein(a, b) {
|
|
|
5907
3323
|
|
|
5908
3324
|
// packages/core/src/agent-context.js
|
|
5909
3325
|
var VERSION = "0.6.0";
|
|
5910
|
-
var
|
|
3326
|
+
var mountedComponents = [];
|
|
5911
3327
|
function registerComponent(component) {
|
|
5912
3328
|
if (!__DEV__) return;
|
|
5913
|
-
|
|
3329
|
+
mountedComponents.push(component);
|
|
5914
3330
|
}
|
|
5915
3331
|
function unregisterComponent(component) {
|
|
5916
3332
|
if (!__DEV__) return;
|
|
5917
|
-
const idx =
|
|
5918
|
-
if (idx >= 0)
|
|
3333
|
+
const idx = mountedComponents.indexOf(component);
|
|
3334
|
+
if (idx >= 0) mountedComponents.splice(idx, 1);
|
|
5919
3335
|
}
|
|
5920
3336
|
function getMountedComponents() {
|
|
5921
|
-
return
|
|
3337
|
+
return mountedComponents.slice();
|
|
5922
3338
|
}
|
|
5923
3339
|
var activeSignals = [];
|
|
5924
3340
|
function registerSignal(sig) {
|
|
@@ -5952,7 +3368,7 @@ function getHealth() {
|
|
|
5952
3368
|
memoryPressure,
|
|
5953
3369
|
recentErrorCount: recentErrors.length,
|
|
5954
3370
|
totalSignals,
|
|
5955
|
-
totalComponents:
|
|
3371
|
+
totalComponents: mountedComponents.length
|
|
5956
3372
|
};
|
|
5957
3373
|
}
|
|
5958
3374
|
function installAgentContext() {
|
|
@@ -6021,7 +3437,10 @@ export {
|
|
|
6021
3437
|
WhatError,
|
|
6022
3438
|
_$createComponent,
|
|
6023
3439
|
_$templateImpl as _$template,
|
|
3440
|
+
__drainPreinstallBuffer,
|
|
6024
3441
|
__getCacheSnapshot,
|
|
3442
|
+
__readHydrationData,
|
|
3443
|
+
__resetHydrationData,
|
|
6025
3444
|
__setDevToolsHooks,
|
|
6026
3445
|
_setTextInsertHook,
|
|
6027
3446
|
template as _template,
|
|
@@ -6029,6 +3448,7 @@ export {
|
|
|
6029
3448
|
announceAssertive,
|
|
6030
3449
|
atom,
|
|
6031
3450
|
batch,
|
|
3451
|
+
beginHeadCollection,
|
|
6032
3452
|
checkComponentName,
|
|
6033
3453
|
classList,
|
|
6034
3454
|
classifyError,
|
|
@@ -6052,15 +3472,19 @@ export {
|
|
|
6052
3472
|
each,
|
|
6053
3473
|
easings,
|
|
6054
3474
|
effect,
|
|
3475
|
+
endHeadCollection,
|
|
6055
3476
|
flushScheduler,
|
|
6056
3477
|
flushSync,
|
|
6057
3478
|
getActiveSignals,
|
|
6058
3479
|
getCollectedErrors,
|
|
6059
3480
|
getGuardrailConfig,
|
|
6060
3481
|
getHealth,
|
|
3482
|
+
getLoaderData,
|
|
6061
3483
|
getMountedComponents,
|
|
6062
3484
|
getOwner,
|
|
6063
3485
|
getQueryData,
|
|
3486
|
+
getResource,
|
|
3487
|
+
getServerContext,
|
|
6064
3488
|
h,
|
|
6065
3489
|
html,
|
|
6066
3490
|
hydrate,
|
|
@@ -6090,10 +3514,12 @@ export {
|
|
|
6090
3514
|
registerSignal,
|
|
6091
3515
|
rules,
|
|
6092
3516
|
runWithOwner,
|
|
3517
|
+
runWithServerContext,
|
|
6093
3518
|
scheduleRead,
|
|
6094
3519
|
scheduleWrite,
|
|
6095
|
-
|
|
3520
|
+
setProp,
|
|
6096
3521
|
setQueryData,
|
|
3522
|
+
setServerContext,
|
|
6097
3523
|
signal,
|
|
6098
3524
|
memo as signalMemo,
|
|
6099
3525
|
simpleResolver,
|
|
@@ -6131,6 +3557,7 @@ export {
|
|
|
6131
3557
|
useIds,
|
|
6132
3558
|
useInfiniteQuery,
|
|
6133
3559
|
useLabelledBy,
|
|
3560
|
+
useLoaderData,
|
|
6134
3561
|
useLocalStorage,
|
|
6135
3562
|
useMediaQuery,
|
|
6136
3563
|
useMemo,
|