marko 6.1.2 → 6.1.4
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/common/accessor.d.ts +5 -0
- package/dist/common/accessor.debug.d.ts +5 -0
- package/dist/common/compat-meta.d.ts +0 -1
- package/dist/common/opt.d.ts +3 -1
- package/dist/common/types.d.ts +1 -1
- package/dist/debug/dom.js +315 -122
- package/dist/debug/dom.mjs +306 -123
- package/dist/debug/html.js +922 -712
- package/dist/debug/html.mjs +920 -713
- package/dist/dom/compat.d.ts +3 -2
- package/dist/dom/control-flow.d.ts +2 -1
- package/dist/dom/load.d.ts +23 -0
- package/dist/dom/queue.d.ts +4 -2
- package/dist/dom/resume.d.ts +10 -8
- package/dist/dom/signals.d.ts +4 -3
- package/dist/dom.d.ts +3 -2
- package/dist/dom.js +195 -66
- package/dist/dom.mjs +195 -66
- package/dist/html/assets.d.ts +47 -0
- package/dist/html/compat.d.ts +3 -2
- package/dist/html/inlined-runtimes.d.ts +1 -1
- package/dist/html/inlined-runtimes.debug.d.ts +1 -1
- package/dist/html/serializer.d.ts +14 -9
- package/dist/html/writer.d.ts +34 -15
- package/dist/html.d.ts +1 -0
- package/dist/html.js +502 -345
- package/dist/html.mjs +502 -345
- package/dist/translator/index.d.ts +1 -0
- package/dist/translator/index.js +342 -76
- package/dist/translator/interop/index.d.ts +1 -0
- package/dist/translator/util/marko-config.d.ts +2 -0
- package/dist/translator/util/references.d.ts +1 -5
- package/dist/translator/util/runtime.d.ts +1 -0
- package/dist/translator/util/tag-name-type.d.ts +2 -0
- package/dist/translator/util/walks.d.ts +1 -1
- package/dist/translator/visitors/import-declaration.d.ts +10 -1
- package/dist/translator/visitors/tag/custom-tag.d.ts +7 -0
- package/package.json +2 -2
package/dist/debug/html.js
CHANGED
|
@@ -61,51 +61,8 @@ function joinWithAnd(a) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
//#endregion
|
|
64
|
-
//#region src/common/
|
|
65
|
-
const
|
|
66
|
-
function stringifyClassObject(name, value) {
|
|
67
|
-
return value ? name : "";
|
|
68
|
-
}
|
|
69
|
-
function stringifyStyleObject(name, value) {
|
|
70
|
-
return value || value === 0 ? name + ":" + value : "";
|
|
71
|
-
}
|
|
72
|
-
const toDelimitedString = function toDelimitedString(val, delimiter, stringify) {
|
|
73
|
-
let str = "";
|
|
74
|
-
let sep = "";
|
|
75
|
-
let part;
|
|
76
|
-
if (val) if (typeof val !== "object") str += val;
|
|
77
|
-
else if (Array.isArray(val)) for (const v of val) {
|
|
78
|
-
part = toDelimitedString(v, delimiter, stringify);
|
|
79
|
-
if (part) {
|
|
80
|
-
str += sep + part;
|
|
81
|
-
sep = delimiter;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
else for (const name in val) {
|
|
85
|
-
part = stringify(name, val[name]);
|
|
86
|
-
if (part) {
|
|
87
|
-
str += sep + part;
|
|
88
|
-
sep = delimiter;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return str;
|
|
92
|
-
};
|
|
93
|
-
function isEventHandler(name) {
|
|
94
|
-
return /^on[A-Z-]/.test(name);
|
|
95
|
-
}
|
|
96
|
-
function getEventHandlerName(name) {
|
|
97
|
-
return name[2] === "-" ? name.slice(3) : name.slice(2).toLowerCase();
|
|
98
|
-
}
|
|
99
|
-
function isVoid(value) {
|
|
100
|
-
return value == null || value === false;
|
|
101
|
-
}
|
|
102
|
-
function normalizeDynamicRenderer(value) {
|
|
103
|
-
if (value) {
|
|
104
|
-
if (typeof value === "string") return value;
|
|
105
|
-
const normalized = value.content || value.default || value;
|
|
106
|
-
if ("id" in normalized) return normalized;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
64
|
+
//#region src/common/meta.ts
|
|
65
|
+
const DYNAMIC_TAG_SCRIPT_REGISTER_ID = "_dynamicTagScript";
|
|
109
66
|
//#endregion
|
|
110
67
|
//#region src/html/content.ts
|
|
111
68
|
function _unescaped(val) {
|
|
@@ -133,145 +90,10 @@ function _escape_comment(val) {
|
|
|
133
90
|
return val ? escapeCommentStr(val + "") : val === 0 ? "0" : "";
|
|
134
91
|
}
|
|
135
92
|
//#endregion
|
|
136
|
-
//#region src/common/for.ts
|
|
137
|
-
function forIn(obj, cb) {
|
|
138
|
-
for (const key in obj) cb(key, obj[key]);
|
|
139
|
-
}
|
|
140
|
-
function forOf(list, cb) {
|
|
141
|
-
if (list) {
|
|
142
|
-
let i = 0;
|
|
143
|
-
for (const item of list) cb(item, i++);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function forTo(to, from, step, cb) {
|
|
147
|
-
const start = from || 0;
|
|
148
|
-
const delta = step || 1;
|
|
149
|
-
for (let steps = (to - start) / delta, i = 0; i <= steps; i++) cb(start + i * delta);
|
|
150
|
-
}
|
|
151
|
-
function forUntil(until, from, step, cb) {
|
|
152
|
-
const start = from || 0;
|
|
153
|
-
const delta = step || 1;
|
|
154
|
-
for (let steps = (until - start) / delta, i = 0; i < steps; i++) cb(start + i * delta);
|
|
155
|
-
}
|
|
156
|
-
//#endregion
|
|
157
|
-
//#region src/common/opt.ts
|
|
158
|
-
function push(opt, item) {
|
|
159
|
-
return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
|
|
160
|
-
}
|
|
161
|
-
//#endregion
|
|
162
|
-
//#region src/html/for.ts
|
|
163
|
-
function forOfBy(by, item, index) {
|
|
164
|
-
if (by) {
|
|
165
|
-
if (typeof by === "string") return item[by];
|
|
166
|
-
return by(item, index);
|
|
167
|
-
}
|
|
168
|
-
return index;
|
|
169
|
-
}
|
|
170
|
-
function forInBy(by, name, value) {
|
|
171
|
-
if (by) return by(name, value);
|
|
172
|
-
return name;
|
|
173
|
-
}
|
|
174
|
-
function forStepBy(by, index) {
|
|
175
|
-
if (by) return by(index);
|
|
176
|
-
return index;
|
|
177
|
-
}
|
|
178
|
-
//#endregion
|
|
179
|
-
//#region src/html/inlined-runtimes.debug.ts
|
|
180
|
-
const WALKER_RUNTIME_CODE = `((runtimeId) => (self[runtimeId] || (self[runtimeId] = (
|
|
181
|
-
renderId,
|
|
182
|
-
prefix = runtimeId + renderId,
|
|
183
|
-
prefixLen = prefix.length,
|
|
184
|
-
lookup = {},
|
|
185
|
-
visits = [],
|
|
186
|
-
doc = document,
|
|
187
|
-
walker = doc.createTreeWalker(
|
|
188
|
-
doc,
|
|
189
|
-
129 /* NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_ELEMENT */,
|
|
190
|
-
),
|
|
191
|
-
) =>
|
|
192
|
-
doc = (self[runtimeId][renderId] = {
|
|
193
|
-
i: prefix,
|
|
194
|
-
d: doc,
|
|
195
|
-
l: lookup,
|
|
196
|
-
v: visits,
|
|
197
|
-
x() {},
|
|
198
|
-
w(node, op, id) {
|
|
199
|
-
while ((node = walker.nextNode())) {
|
|
200
|
-
doc.x(
|
|
201
|
-
(op =
|
|
202
|
-
(op = node.data) &&
|
|
203
|
-
!op.indexOf(prefix) &&
|
|
204
|
-
((lookup[(id = op.slice(prefixLen + 1))] = node), op[prefixLen])),
|
|
205
|
-
id,
|
|
206
|
-
node,
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
if (op > "#") {
|
|
210
|
-
visits.push(node);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
})
|
|
215
|
-
), self[runtimeId]))`;
|
|
216
|
-
const REORDER_RUNTIME_CODE = `((runtime) => {
|
|
217
|
-
if (runtime.j) return;
|
|
218
|
-
let onNextSibling,
|
|
219
|
-
placeholder,
|
|
220
|
-
nextSibling,
|
|
221
|
-
placeholders = runtime.p = {},
|
|
222
|
-
replace = (id, container) => runtime.l[id].replaceWith(...container.childNodes);
|
|
223
|
-
runtime.d.head.append(
|
|
224
|
-
runtime.d.querySelector("style[" + runtime.i + "]") || ""
|
|
225
|
-
);
|
|
226
|
-
runtime.j = {};
|
|
227
|
-
runtime.x = (op, id, node, placeholderRoot, placeholderCb) => {
|
|
228
|
-
if (node == nextSibling) {
|
|
229
|
-
onNextSibling();
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (op == "#") {
|
|
233
|
-
(placeholders[id] = placeholder).i++;
|
|
234
|
-
} else if (op == "!") {
|
|
235
|
-
if (runtime.l[id] && placeholders[id]) {
|
|
236
|
-
nextSibling = node.nextSibling;
|
|
237
|
-
onNextSibling = () => placeholders[id].c();
|
|
238
|
-
}
|
|
239
|
-
} else if (node.tagName == "T" && (id = node.getAttribute(runtime.i))) {
|
|
240
|
-
nextSibling = node.nextSibling;
|
|
241
|
-
onNextSibling = () => {
|
|
242
|
-
node.remove();
|
|
243
|
-
placeholderRoot || replace(id, node);
|
|
244
|
-
placeholder.c();
|
|
245
|
-
};
|
|
246
|
-
placeholder =
|
|
247
|
-
placeholders[id] ||
|
|
248
|
-
(placeholderRoot = placeholders[id] =
|
|
249
|
-
{
|
|
250
|
-
i: runtime.l[id] ? 1 : 2,
|
|
251
|
-
c(start = runtime.l["^" + id]) {
|
|
252
|
-
if (--placeholderRoot.i) return 1;
|
|
253
|
-
for (
|
|
254
|
-
;
|
|
255
|
-
(nextSibling =
|
|
256
|
-
runtime.l[id].previousSibling || start).remove(),
|
|
257
|
-
start != nextSibling;
|
|
258
|
-
|
|
259
|
-
);
|
|
260
|
-
replace(id, node);
|
|
261
|
-
},
|
|
262
|
-
});
|
|
263
|
-
// repurpose "op" for callbacks ...carefully
|
|
264
|
-
if ((op = runtime.j[id])) {
|
|
265
|
-
placeholderCb = placeholder.c;
|
|
266
|
-
placeholder.c = () => placeholderCb() || op(runtime.r);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
})`;
|
|
271
|
-
//#endregion
|
|
272
93
|
//#region src/html/serializer.ts
|
|
94
|
+
const K_SCOPE_ID = Symbol("Scope ID");
|
|
273
95
|
const kTouchedIterator = Symbol.for("marko.touchedIterator");
|
|
274
|
-
const { hasOwnProperty } = {};
|
|
96
|
+
const { hasOwnProperty: hasOwnProperty$1 } = {};
|
|
275
97
|
const Generator = (function* () {})().constructor;
|
|
276
98
|
const AsyncGenerator = (async function* () {})().constructor;
|
|
277
99
|
patchIteratorNext(Generator.prototype);
|
|
@@ -517,15 +339,14 @@ const KNOWN_OBJECTS = new Map([
|
|
|
517
339
|
var State$1 = class {
|
|
518
340
|
ids = 0;
|
|
519
341
|
flush = 0;
|
|
520
|
-
registerInstanceId = 0;
|
|
521
|
-
flushed = false;
|
|
522
342
|
wroteUndefined = false;
|
|
523
343
|
buf = [];
|
|
524
344
|
strs = /* @__PURE__ */ new Map();
|
|
525
345
|
refs = /* @__PURE__ */ new WeakMap();
|
|
526
346
|
assigned = /* @__PURE__ */ new Set();
|
|
527
|
-
registered = [];
|
|
528
347
|
boundary = void 0;
|
|
348
|
+
channel = void 0;
|
|
349
|
+
channelDeps = null;
|
|
529
350
|
mutated = [];
|
|
530
351
|
};
|
|
531
352
|
var Reference = class {
|
|
@@ -534,19 +355,15 @@ var Reference = class {
|
|
|
534
355
|
flush;
|
|
535
356
|
pos;
|
|
536
357
|
id;
|
|
537
|
-
registered = null;
|
|
538
358
|
assigns = null;
|
|
359
|
+
scopeId = void 0;
|
|
360
|
+
channel = void 0;
|
|
539
361
|
constructor(parent, accessor, flush, pos = null, id = null) {
|
|
540
362
|
this.parent = parent;
|
|
541
363
|
this.accessor = accessor;
|
|
542
364
|
this.flush = flush;
|
|
543
365
|
this.pos = pos;
|
|
544
366
|
this.id = id;
|
|
545
|
-
this.parent = parent;
|
|
546
|
-
this.accessor = accessor;
|
|
547
|
-
this.flush = flush;
|
|
548
|
-
this.pos = pos;
|
|
549
|
-
this.id = id;
|
|
550
367
|
}
|
|
551
368
|
};
|
|
552
369
|
const DEBUG = /* @__PURE__ */ new WeakMap();
|
|
@@ -559,57 +376,43 @@ function setDebugInfo(obj, file, loc, vars) {
|
|
|
559
376
|
}
|
|
560
377
|
var Serializer = class {
|
|
561
378
|
#state = new State$1();
|
|
562
|
-
|
|
563
|
-
return this.#state.
|
|
379
|
+
pending(channel) {
|
|
380
|
+
return hasMatchingMutations(this.#state.mutated, channel?.readyId);
|
|
564
381
|
}
|
|
565
|
-
|
|
382
|
+
pendingReadyChannel() {
|
|
383
|
+
for (const mutation of this.#state.mutated) if (mutation.channel?.readyId) return mutation.channel;
|
|
384
|
+
}
|
|
385
|
+
stringifyScopes(flushes, globals, boundary, channel) {
|
|
566
386
|
try {
|
|
567
|
-
this.#state.flushed = false;
|
|
568
387
|
this.#state.boundary = boundary;
|
|
569
|
-
|
|
388
|
+
this.#state.channel = channel;
|
|
389
|
+
return writeScopesRoot(this.#state, flushes, globals);
|
|
570
390
|
} finally {
|
|
571
391
|
this.#state.flush++;
|
|
572
392
|
this.#state.buf = [];
|
|
573
393
|
}
|
|
574
394
|
}
|
|
575
|
-
|
|
576
|
-
return
|
|
395
|
+
written(val) {
|
|
396
|
+
return this.#state.refs.has(val);
|
|
577
397
|
}
|
|
578
|
-
|
|
579
|
-
const
|
|
580
|
-
this.#state.
|
|
581
|
-
return
|
|
398
|
+
takeChannelDeps() {
|
|
399
|
+
const deps = this.#state.channelDeps;
|
|
400
|
+
this.#state.channelDeps = null;
|
|
401
|
+
return deps;
|
|
582
402
|
}
|
|
583
|
-
writeCall(value, object, property,
|
|
584
|
-
|
|
585
|
-
state.mutated.push({
|
|
586
|
-
type: 0,
|
|
403
|
+
writeCall(value, object, property, channel) {
|
|
404
|
+
this.#state.mutated.push({
|
|
587
405
|
value,
|
|
588
406
|
object,
|
|
589
407
|
property,
|
|
590
|
-
|
|
591
|
-
});
|
|
592
|
-
state.flushed = true;
|
|
593
|
-
}
|
|
594
|
-
writeAssign(value, object, property) {
|
|
595
|
-
const state = this.#state;
|
|
596
|
-
state.mutated.push({
|
|
597
|
-
type: 1,
|
|
598
|
-
value,
|
|
599
|
-
object,
|
|
600
|
-
property
|
|
408
|
+
channel
|
|
601
409
|
});
|
|
602
|
-
state.flushed = true;
|
|
603
|
-
}
|
|
604
|
-
register(id, val, scope) {
|
|
605
|
-
return register(id, val, scope, scope ? ++this.#state.registerInstanceId : 0);
|
|
606
410
|
}
|
|
607
411
|
};
|
|
608
|
-
function register(id, val, scope
|
|
412
|
+
function register(id, val, scope) {
|
|
609
413
|
REGISTRY.set(val, {
|
|
610
414
|
id,
|
|
611
415
|
scope,
|
|
612
|
-
instanceId: instanceId ?? 0,
|
|
613
416
|
access: "_._" + toAccess(toObjectKey(id))
|
|
614
417
|
});
|
|
615
418
|
return val;
|
|
@@ -621,65 +424,70 @@ function getRegistered(val) {
|
|
|
621
424
|
scope: registered.scope
|
|
622
425
|
};
|
|
623
426
|
}
|
|
624
|
-
function
|
|
427
|
+
function writeScopesRoot(state, flushes, globals) {
|
|
625
428
|
const { buf } = state;
|
|
626
|
-
|
|
627
|
-
let
|
|
628
|
-
if (
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
429
|
+
let nextSlotId = -1;
|
|
430
|
+
let fillIndex = -1;
|
|
431
|
+
if (globals) {
|
|
432
|
+
fillIndex = buf.push("[0,") - 1;
|
|
433
|
+
writeProp(state, globals, null, "");
|
|
434
|
+
nextSlotId = 1;
|
|
435
|
+
}
|
|
436
|
+
for (const flush of flushes) {
|
|
437
|
+
const scopeId = flush[0];
|
|
438
|
+
const scope = flush[1];
|
|
439
|
+
const ref = state.refs.get(scope) || newScopeReference(state, scope, scopeId);
|
|
440
|
+
const openIndex = buf.push("") - 1;
|
|
441
|
+
if (writeObjectProps(state, flush[2], ref)) {
|
|
442
|
+
buf[openIndex] = nextSlotId === -1 ? "[" + scopeId + ",{" : (scopeId > nextSlotId ? "," + (scopeId - nextSlotId) : "") + ",{";
|
|
443
|
+
if (fillIndex === -1) fillIndex = openIndex;
|
|
444
|
+
nextSlotId = scopeId + 1;
|
|
445
|
+
buf.push("}");
|
|
446
|
+
} else buf.pop();
|
|
447
|
+
}
|
|
448
|
+
if (nextSlotId !== -1) buf.push("]");
|
|
449
|
+
let extras = "";
|
|
450
|
+
if (state.assigned.size || hasChannelMutations(state)) {
|
|
451
|
+
extras = ",0)";
|
|
452
|
+
if (fillIndex !== -1) {
|
|
453
|
+
buf[fillIndex] = "_(" + buf[fillIndex];
|
|
454
|
+
buf.push(")");
|
|
638
455
|
}
|
|
639
|
-
|
|
640
|
-
buf.push(")");
|
|
641
|
-
} else {
|
|
642
|
-
if (hadBuf) {
|
|
643
|
-
buf.pop();
|
|
644
|
-
writeAssigned(state);
|
|
645
|
-
}
|
|
646
|
-
result = "{";
|
|
647
|
-
buf.push("}");
|
|
456
|
+
writeAssigned(state);
|
|
648
457
|
}
|
|
458
|
+
let result = extras && "(";
|
|
649
459
|
for (const chunk of buf) result += chunk;
|
|
460
|
+
result += extras;
|
|
461
|
+
if (!result) return "";
|
|
650
462
|
if (state.wroteUndefined) {
|
|
651
463
|
state.wroteUndefined = false;
|
|
652
464
|
return "(_,$)=>" + result;
|
|
653
465
|
} else return "_=>" + result;
|
|
654
466
|
}
|
|
655
467
|
function writeAssigned(state) {
|
|
468
|
+
let sep = state.buf.length ? "," : "";
|
|
656
469
|
if (state.assigned.size) {
|
|
657
470
|
let buf = "";
|
|
658
471
|
for (const ref of state.assigned) {
|
|
659
|
-
buf +=
|
|
472
|
+
buf += sep + assignsToString(ref.assigns, ref.id);
|
|
660
473
|
ref.assigns = null;
|
|
474
|
+
sep = ",";
|
|
661
475
|
}
|
|
662
476
|
state.buf.push(buf);
|
|
663
477
|
state.assigned = /* @__PURE__ */ new Set();
|
|
664
478
|
}
|
|
665
|
-
if (state
|
|
666
|
-
|
|
667
|
-
for (const ref of state.registered.sort(compareRegisteredReferences)) {
|
|
668
|
-
const scopeRef = state.refs.get(ref.registered.scope);
|
|
669
|
-
buf += "," + assignsToString(ref.assigns, ref.registered.access + "(" + (scopeRef ? ensureId(state, scopeRef) : ref.assigns[0]) + ")");
|
|
670
|
-
ref.assigns = null;
|
|
671
|
-
ref.registered = null;
|
|
672
|
-
}
|
|
673
|
-
state.buf.push(buf);
|
|
674
|
-
state.registered = [];
|
|
675
|
-
}
|
|
676
|
-
if (state.mutated.length) {
|
|
479
|
+
if (hasChannelMutations(state)) {
|
|
480
|
+
const remaining = [];
|
|
677
481
|
for (const mutation of state.mutated) {
|
|
482
|
+
if (!mutationMatchesReadyId(mutation, state.channel?.readyId)) {
|
|
483
|
+
remaining.push(mutation);
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
678
486
|
const hasSeen = state.refs.get(mutation.object)?.id;
|
|
679
487
|
const objectStartIndex = state.buf.push(state.buf.length === 0 ? "" : ",");
|
|
680
488
|
if (writeProp(state, mutation.object, null, "")) {
|
|
681
489
|
const objectRef = state.refs.get(mutation.object);
|
|
682
|
-
if (objectRef) {
|
|
490
|
+
if (objectRef && objectRef.scopeId === void 0) {
|
|
683
491
|
if (!objectRef.id) {
|
|
684
492
|
objectRef.id = nextRefAccess(state);
|
|
685
493
|
state.buf[objectStartIndex] = "(" + objectRef.id + "=" + state.buf[objectStartIndex];
|
|
@@ -690,21 +498,30 @@ function writeAssigned(state) {
|
|
|
690
498
|
}
|
|
691
499
|
}
|
|
692
500
|
} else state.buf.push("void 0");
|
|
693
|
-
const
|
|
694
|
-
|
|
695
|
-
if (writeProp(state, mutation.value, null, "")) {
|
|
501
|
+
const valueStartIndex = state.buf.push(toAccess(toObjectKey(mutation.property)) + "(");
|
|
502
|
+
if (mutation.value === void 0) {} else if (writeProp(state, mutation.value, null, "")) {
|
|
696
503
|
const valueRef = state.refs.get(mutation.value);
|
|
697
|
-
if (valueRef && !valueRef.id) {
|
|
698
|
-
valueRef.id = nextRefAccess(state);
|
|
504
|
+
if (valueRef && !valueRef.id && valueRef.scopeId === void 0) {
|
|
505
|
+
valueRef.id = mutation.valueId || nextRefAccess(state);
|
|
699
506
|
state.buf[valueStartIndex] = valueRef.id + "=" + state.buf[valueStartIndex];
|
|
700
507
|
}
|
|
701
508
|
} else state.buf.push("void 0");
|
|
702
|
-
|
|
509
|
+
state.buf.push(")");
|
|
703
510
|
}
|
|
704
|
-
state.mutated =
|
|
705
|
-
if (state.assigned.size
|
|
511
|
+
state.mutated = remaining;
|
|
512
|
+
if (state.assigned.size) writeAssigned(state);
|
|
706
513
|
}
|
|
707
514
|
}
|
|
515
|
+
function hasChannelMutations(state) {
|
|
516
|
+
return hasMatchingMutations(state.mutated, state.channel?.readyId);
|
|
517
|
+
}
|
|
518
|
+
function hasMatchingMutations(mutated, readyId) {
|
|
519
|
+
for (const mutation of mutated) if (mutationMatchesReadyId(mutation, readyId)) return true;
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
function mutationMatchesReadyId(mutation, readyId) {
|
|
523
|
+
return mutation.channel?.readyId ? mutation.channel.readyId === readyId : !readyId;
|
|
524
|
+
}
|
|
708
525
|
function writeProp(state, val, parent, accessor) {
|
|
709
526
|
switch (typeof val) {
|
|
710
527
|
case "string": return writeString(state, val, parent, accessor);
|
|
@@ -720,16 +537,26 @@ function writeProp(state, val, parent, accessor) {
|
|
|
720
537
|
}
|
|
721
538
|
}
|
|
722
539
|
function writeReferenceOr(state, write, val, parent, accessor) {
|
|
540
|
+
const scopeId = val[K_SCOPE_ID];
|
|
541
|
+
if (scopeId !== void 0) {
|
|
542
|
+
trackScope(state, val, scopeId);
|
|
543
|
+
state.buf.push("_(" + scopeId + ")");
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
723
546
|
let ref = state.refs.get(val);
|
|
724
547
|
if (ref) {
|
|
548
|
+
if (!trackChannel(state, ref)) {
|
|
549
|
+
abortUnreachableChannel(state, val);
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
725
552
|
if (parent) {
|
|
726
553
|
if (ref.assigns) {
|
|
727
|
-
addAssignment(ref,
|
|
554
|
+
addAssignment(ref, accessId(state, parent) + toAccess(accessor));
|
|
728
555
|
return false;
|
|
729
556
|
} else if (isCircular(parent, ref)) {
|
|
730
557
|
ensureId(state, ref);
|
|
731
558
|
state.assigned.add(ref);
|
|
732
|
-
addAssignment(ref,
|
|
559
|
+
addAssignment(ref, accessId(state, parent) + toAccess(accessor));
|
|
733
560
|
return false;
|
|
734
561
|
}
|
|
735
562
|
}
|
|
@@ -739,39 +566,54 @@ function writeReferenceOr(state, write, val, parent, accessor) {
|
|
|
739
566
|
const registered = REGISTRY.get(val);
|
|
740
567
|
if (registered) return writeRegistered(state, val, parent, accessor, registered);
|
|
741
568
|
state.refs.set(val, ref = new Reference(parent, accessor, state.flush, state.buf.length));
|
|
569
|
+
ref.channel = state.channel;
|
|
742
570
|
ref.debug = DEBUG.get(val);
|
|
743
571
|
if (write(state, val, ref)) return true;
|
|
744
572
|
state.refs.delete(val);
|
|
745
573
|
return false;
|
|
746
574
|
}
|
|
575
|
+
function trackScope(state, val, scopeId) {
|
|
576
|
+
const ref = state.refs.get(val);
|
|
577
|
+
if (ref) trackChannel(state, ref);
|
|
578
|
+
else newScopeReference(state, val, scopeId);
|
|
579
|
+
}
|
|
580
|
+
function newScopeReference(state, val, scopeId) {
|
|
581
|
+
const ref = new Reference(null, null, state.flush);
|
|
582
|
+
ref.scopeId = scopeId;
|
|
583
|
+
ref.channel = state.channel;
|
|
584
|
+
state.refs.set(val, ref);
|
|
585
|
+
ref.debug = DEBUG.get(val);
|
|
586
|
+
return ref;
|
|
587
|
+
}
|
|
747
588
|
function writeRegistered(state, val, parent, accessor, registered) {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
const fnRef = new Reference(parent, accessor, state.flush, state.buf.length);
|
|
758
|
-
fnRef.registered = registered;
|
|
759
|
-
state.refs.set(val, fnRef);
|
|
760
|
-
state.registered.push(fnRef);
|
|
761
|
-
addAssignment(fnRef, ensureId(state, parent) + toAccess(accessor));
|
|
762
|
-
return false;
|
|
589
|
+
const { scope } = registered;
|
|
590
|
+
if (scope) {
|
|
591
|
+
const ref = new Reference(parent, accessor, state.flush, state.buf.length);
|
|
592
|
+
ref.channel = state.channel;
|
|
593
|
+
state.refs.set(val, ref);
|
|
594
|
+
ref.debug = DEBUG.get(val);
|
|
595
|
+
const scopeId = scope[K_SCOPE_ID];
|
|
596
|
+
trackScope(state, scope, scopeId);
|
|
597
|
+
state.buf.push("_(" + scopeId + "," + quote(registered.id, 0) + ")");
|
|
763
598
|
} else state.buf.push(registered.access);
|
|
764
599
|
return true;
|
|
765
600
|
}
|
|
601
|
+
const STRING_DEDUP_LENGTH = 12;
|
|
766
602
|
function writeString(state, val, parent, accessor) {
|
|
767
|
-
if (val.length >
|
|
603
|
+
if (val.length > STRING_DEDUP_LENGTH) {
|
|
768
604
|
const ref = state.strs.get(val);
|
|
769
|
-
if (ref)
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
605
|
+
if (ref) {
|
|
606
|
+
if (trackChannel(state, ref)) {
|
|
607
|
+
state.buf.push(ensureId(state, ref));
|
|
608
|
+
return true;
|
|
609
|
+
}
|
|
610
|
+
} else {
|
|
611
|
+
const ref = new Reference(parent, accessor, state.flush, state.buf.length);
|
|
612
|
+
ref.channel = state.channel;
|
|
613
|
+
state.strs.set(val, ref);
|
|
773
614
|
}
|
|
774
|
-
}
|
|
615
|
+
}
|
|
616
|
+
state.buf.push(quote(val, 0));
|
|
775
617
|
return true;
|
|
776
618
|
}
|
|
777
619
|
function writeNumber(state, val) {
|
|
@@ -893,7 +735,7 @@ function writeArray(state, val, ref) {
|
|
|
893
735
|
return true;
|
|
894
736
|
}
|
|
895
737
|
function writeDate(state, val) {
|
|
896
|
-
state.buf.push("new Date(
|
|
738
|
+
state.buf.push("new Date(" + +val + ")");
|
|
897
739
|
return true;
|
|
898
740
|
}
|
|
899
741
|
function writeRegExp(state, val) {
|
|
@@ -901,23 +743,30 @@ function writeRegExp(state, val) {
|
|
|
901
743
|
return true;
|
|
902
744
|
}
|
|
903
745
|
function writePromise(state, val, ref) {
|
|
904
|
-
const { boundary } = state;
|
|
746
|
+
const { boundary, channel } = state;
|
|
905
747
|
if (!boundary) return false;
|
|
906
748
|
const pId = nextRefAccess(state);
|
|
907
|
-
const
|
|
749
|
+
const handle = newAsyncHandle(state, ref, pId);
|
|
908
750
|
state.buf.push("(p=>p=new Promise((f,r)=>" + pId + "={f,r(e){p.catch(_=>0);r(e)}}))()");
|
|
909
|
-
val.then((v) => writeAsyncCall(state, boundary,
|
|
751
|
+
val.then((v) => writeAsyncCall(state, boundary, handle, "f", v, channel, pId), (v) => writeAsyncCall(state, boundary, handle, "r", v, channel, pId));
|
|
910
752
|
boundary.startAsync();
|
|
911
753
|
return true;
|
|
912
754
|
}
|
|
755
|
+
function newAsyncHandle(state, parent, id) {
|
|
756
|
+
const handle = {};
|
|
757
|
+
const handleRef = new Reference(parent, null, state.flush, null, id);
|
|
758
|
+
handleRef.channel = state.channel;
|
|
759
|
+
state.refs.set(handle, handleRef);
|
|
760
|
+
return handle;
|
|
761
|
+
}
|
|
913
762
|
function writeMap(state, val, ref) {
|
|
914
763
|
if (!val.size) {
|
|
915
764
|
state.buf.push("new Map");
|
|
916
765
|
return true;
|
|
917
766
|
}
|
|
918
|
-
const arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
|
|
919
767
|
const items = [];
|
|
920
768
|
let assigns;
|
|
769
|
+
let needsId;
|
|
921
770
|
let i = 0;
|
|
922
771
|
if (val.size < 25) {
|
|
923
772
|
for (let [itemKey, itemValue] of val) {
|
|
@@ -929,12 +778,10 @@ function writeMap(state, val, ref) {
|
|
|
929
778
|
itemValue = void 0;
|
|
930
779
|
(assigns ||= []).push("a[" + i + "][1]");
|
|
931
780
|
}
|
|
781
|
+
needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue);
|
|
932
782
|
i = items.push(itemValue === void 0 ? itemKey === void 0 ? [] : [itemKey] : [itemKey, itemValue]);
|
|
933
783
|
}
|
|
934
|
-
|
|
935
|
-
else state.buf.push("new Map(" + arrayRef.id + "=");
|
|
936
|
-
writeArray(state, items, arrayRef);
|
|
937
|
-
state.buf.push(")");
|
|
784
|
+
writeArrayArg(state, ref, items, assigns && "((m,a)=>(" + assignsToString(assigns, "m") + ",a.forEach(i=>m.set(i[0],i[1])),m))(new Map,", "new Map(", needsId);
|
|
938
785
|
} else {
|
|
939
786
|
for (let [itemKey, itemValue] of val) {
|
|
940
787
|
if (itemKey === val) {
|
|
@@ -945,12 +792,10 @@ function writeMap(state, val, ref) {
|
|
|
945
792
|
itemValue = 0;
|
|
946
793
|
(assigns ||= []).push("a[" + (i + 1) + "]");
|
|
947
794
|
}
|
|
795
|
+
needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue);
|
|
948
796
|
i = items.push(itemKey, itemValue);
|
|
949
797
|
}
|
|
950
|
-
|
|
951
|
-
else state.buf.push("(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1]),new Map))(" + arrayRef.id + "=");
|
|
952
|
-
writeArray(state, items, arrayRef);
|
|
953
|
-
state.buf.push(")");
|
|
798
|
+
writeArrayArg(state, ref, items, assigns && "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1])," + assignsToString(assigns, "new Map") + "))(", "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1]),new Map))(", needsId);
|
|
954
799
|
}
|
|
955
800
|
return true;
|
|
956
801
|
}
|
|
@@ -961,20 +806,38 @@ function writeSet(state, val, ref) {
|
|
|
961
806
|
}
|
|
962
807
|
const items = [];
|
|
963
808
|
let assigns;
|
|
809
|
+
let needsId;
|
|
964
810
|
let i = 0;
|
|
965
811
|
for (let item of val) {
|
|
966
812
|
if (item === val) {
|
|
967
813
|
item = 0;
|
|
968
814
|
(assigns ||= []).push("i[" + i + "]");
|
|
969
|
-
}
|
|
815
|
+
} else needsId ||= isDedupedMember(item);
|
|
970
816
|
i = items.push(item);
|
|
971
817
|
}
|
|
972
|
-
|
|
973
|
-
state.buf.push((assigns ? "((s,i)=>(" + assignsToString(assigns, "s") + ",i.forEach(i=>s.add(i)),s))(new Set," : "new Set(") + arrayRef.id + "=");
|
|
974
|
-
writeArray(state, items, arrayRef);
|
|
975
|
-
state.buf.push(")");
|
|
818
|
+
writeArrayArg(state, ref, items, assigns && "((s,i)=>(" + assignsToString(assigns, "s") + ",i.forEach(i=>s.add(i)),s))(new Set,", "new Set(", needsId);
|
|
976
819
|
return true;
|
|
977
820
|
}
|
|
821
|
+
function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
|
|
822
|
+
if (assignsPrefix || needsId) {
|
|
823
|
+
const arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
|
|
824
|
+
state.buf.push((assignsPrefix || plainPrefix) + arrayRef.id + "=");
|
|
825
|
+
writeArray(state, items, arrayRef);
|
|
826
|
+
} else {
|
|
827
|
+
state.buf.push(plainPrefix);
|
|
828
|
+
writeArray(state, items, new Reference(ref, null, state.flush, state.buf.length));
|
|
829
|
+
}
|
|
830
|
+
state.buf.push(")");
|
|
831
|
+
}
|
|
832
|
+
function isDedupedMember(val) {
|
|
833
|
+
switch (typeof val) {
|
|
834
|
+
case "object": return val !== null && val[K_SCOPE_ID] === void 0;
|
|
835
|
+
case "function":
|
|
836
|
+
case "symbol": return true;
|
|
837
|
+
case "string": return val.length > STRING_DEDUP_LENGTH;
|
|
838
|
+
default: return false;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
978
841
|
function writeArrayBuffer(state, val) {
|
|
979
842
|
let result;
|
|
980
843
|
if (val.byteLength) {
|
|
@@ -1121,21 +984,21 @@ function writeResponse(state, val, ref) {
|
|
|
1121
984
|
return true;
|
|
1122
985
|
}
|
|
1123
986
|
function writeReadableStream(state, val, ref) {
|
|
1124
|
-
const { boundary } = state;
|
|
987
|
+
const { boundary, channel } = state;
|
|
1125
988
|
if (!boundary || val.locked) return false;
|
|
1126
989
|
const reader = val.getReader();
|
|
1127
990
|
const iterId = nextRefAccess(state);
|
|
1128
|
-
const
|
|
991
|
+
const handle = newAsyncHandle(state, ref, iterId);
|
|
1129
992
|
const onFulfilled = ({ value, done }) => {
|
|
1130
|
-
if (done) writeAsyncCall(state, boundary,
|
|
993
|
+
if (done) writeAsyncCall(state, boundary, handle, "r", value, channel);
|
|
1131
994
|
else if (!boundary.signal.aborted) {
|
|
1132
995
|
reader.read().then(onFulfilled, onRejected);
|
|
1133
996
|
boundary.startAsync();
|
|
1134
|
-
writeAsyncCall(state, boundary,
|
|
997
|
+
writeAsyncCall(state, boundary, handle, "f", value, channel);
|
|
1135
998
|
}
|
|
1136
999
|
};
|
|
1137
1000
|
const onRejected = (reason) => {
|
|
1138
|
-
writeAsyncCall(state, boundary,
|
|
1001
|
+
writeAsyncCall(state, boundary, handle, "j", reason, channel);
|
|
1139
1002
|
};
|
|
1140
1003
|
state.buf.push("new ReadableStream({start(c){(async(_,f,v,l,i,p=a=>l=new Promise((r,j)=>{f=_.r=r;_.j=j}),a=((_.f=v=>{f(v);a.push(p())}),[p()]))=>{for(i of a)v=await i,i==l?c.close():c.enqueue(v)})(" + iterId + "={}).catch(e=>c.error(e))}})");
|
|
1141
1004
|
reader.read().then(onFulfilled, onRejected);
|
|
@@ -1173,20 +1036,20 @@ function writeAsyncGenerator(state, iter, ref) {
|
|
|
1173
1036
|
state.buf.push("(async function*(){}())");
|
|
1174
1037
|
return true;
|
|
1175
1038
|
}
|
|
1176
|
-
const { boundary } = state;
|
|
1039
|
+
const { boundary, channel } = state;
|
|
1177
1040
|
if (!boundary) return false;
|
|
1178
1041
|
const iterId = nextRefAccess(state);
|
|
1179
|
-
const
|
|
1042
|
+
const handle = newAsyncHandle(state, ref, iterId);
|
|
1180
1043
|
const onFulfilled = ({ value, done }) => {
|
|
1181
|
-
if (done) writeAsyncCall(state, boundary,
|
|
1044
|
+
if (done) writeAsyncCall(state, boundary, handle, "r", value, channel);
|
|
1182
1045
|
else if (!boundary.signal.aborted) {
|
|
1183
1046
|
iter.next().then(onFulfilled, onRejected);
|
|
1184
1047
|
boundary.startAsync();
|
|
1185
|
-
writeAsyncCall(state, boundary,
|
|
1048
|
+
writeAsyncCall(state, boundary, handle, "f", value, channel);
|
|
1186
1049
|
}
|
|
1187
1050
|
};
|
|
1188
1051
|
const onRejected = (reason) => {
|
|
1189
|
-
writeAsyncCall(state, boundary,
|
|
1052
|
+
writeAsyncCall(state, boundary, handle, "j", reason, channel);
|
|
1190
1053
|
};
|
|
1191
1054
|
state.buf.push("(async function*(_,f,v,l,i,p=a=>l=new Promise((r,j)=>{f=_.r=r;_.j=j}),a=((_.f=v=>{f(v);a.push(p())}),[p()])){for(i of a)v=await i,i!=l&&(yield v);return v})(" + iterId + "={})");
|
|
1192
1055
|
iter.next().then(onFulfilled, onRejected);
|
|
@@ -1200,45 +1063,36 @@ function writeNullObject(state, val, ref) {
|
|
|
1200
1063
|
}
|
|
1201
1064
|
function writeObjectProps(state, val, ref) {
|
|
1202
1065
|
let sep = "";
|
|
1203
|
-
for (const key in val) if (hasOwnProperty.call(val, key)) {
|
|
1066
|
+
for (const key in val) if (hasOwnProperty$1.call(val, key)) {
|
|
1204
1067
|
const escapedKey = toObjectKey(key);
|
|
1205
1068
|
state.buf.push(sep + escapedKey + ":");
|
|
1206
1069
|
if (writeProp(state, val[key], ref, escapedKey)) sep = ",";
|
|
1207
1070
|
else state.buf.pop();
|
|
1208
1071
|
}
|
|
1209
1072
|
if (hasSymbolIterator(val)) {
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
state.buf.push(sep + "*[(" + iterRef.id + "=");
|
|
1221
|
-
writeArray(state, iterArr, iterRef);
|
|
1222
|
-
state.buf.push(",Symbol.iterator)](){yield*" + iterRef.id + "}");
|
|
1223
|
-
break;
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1073
|
+
let yieldSelf = "";
|
|
1074
|
+
const iterArr = [];
|
|
1075
|
+
for (const item of val) if (item === val && !(yieldSelf || iterArr.length)) yieldSelf = "yield this;";
|
|
1076
|
+
else iterArr.push(item);
|
|
1077
|
+
if (iterArr.length) {
|
|
1078
|
+
const iterRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
|
|
1079
|
+
state.buf.push(sep + "*[(" + iterRef.id + "=");
|
|
1080
|
+
writeArray(state, iterArr, iterRef);
|
|
1081
|
+
state.buf.push(",Symbol.iterator)](){" + yieldSelf + "yield*" + iterRef.id + "}");
|
|
1082
|
+
} else state.buf.push(sep + "*[Symbol.iterator](){" + yieldSelf.slice(0, -1) + "}");
|
|
1226
1083
|
sep = ",";
|
|
1227
1084
|
}
|
|
1228
1085
|
return sep;
|
|
1229
1086
|
}
|
|
1230
|
-
function writeAsyncCall(state, boundary,
|
|
1087
|
+
function writeAsyncCall(state, boundary, handle, method, value, channel, valueId = null) {
|
|
1231
1088
|
if (boundary.signal.aborted) return;
|
|
1232
|
-
state.
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
state.buf.push(")");
|
|
1089
|
+
state.mutated.push({
|
|
1090
|
+
value,
|
|
1091
|
+
object: handle,
|
|
1092
|
+
property: method,
|
|
1093
|
+
channel,
|
|
1094
|
+
valueId
|
|
1095
|
+
});
|
|
1242
1096
|
boundary.endAsync();
|
|
1243
1097
|
}
|
|
1244
1098
|
function throwUnserializable(state, cause, ref = null, accessor = "") {
|
|
@@ -1270,6 +1124,26 @@ function throwUnserializable(state, cause, ref = null, accessor = "") {
|
|
|
1270
1124
|
state.boundary.abort(err);
|
|
1271
1125
|
}
|
|
1272
1126
|
}
|
|
1127
|
+
function trackChannel(state, ref) {
|
|
1128
|
+
const refReadyId = ref.channel?.readyId;
|
|
1129
|
+
if (!refReadyId || refReadyId === state.channel?.readyId) return true;
|
|
1130
|
+
let cur = state.channel?.parent;
|
|
1131
|
+
while (cur) {
|
|
1132
|
+
if (cur.readyId === refReadyId) {
|
|
1133
|
+
(state.channelDeps ||= /* @__PURE__ */ new Set()).add(refReadyId);
|
|
1134
|
+
return true;
|
|
1135
|
+
}
|
|
1136
|
+
cur = cur.parent;
|
|
1137
|
+
}
|
|
1138
|
+
return false;
|
|
1139
|
+
}
|
|
1140
|
+
function abortUnreachableChannel(state, val) {
|
|
1141
|
+
if (state.boundary?.abort) {
|
|
1142
|
+
const err = new TypeError("Unable to serialize a value shared between independently lazy loaded content. Values shared this way must also be serialized by content that is not lazily loaded, or by a common parent.", { cause: val });
|
|
1143
|
+
err.stack = void 0;
|
|
1144
|
+
state.boundary.abort(err);
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1273
1147
|
function isCircular(parent, ref) {
|
|
1274
1148
|
let cur = parent;
|
|
1275
1149
|
while (cur) {
|
|
@@ -1329,7 +1203,19 @@ function quote(str, startPos) {
|
|
|
1329
1203
|
return "\"" + (lastPos === startPos ? str : result + str.slice(lastPos)) + "\"";
|
|
1330
1204
|
}
|
|
1331
1205
|
function ensureId(state, ref) {
|
|
1332
|
-
|
|
1206
|
+
if (ref.scopeId !== void 0) {
|
|
1207
|
+
trackChannel(state, ref);
|
|
1208
|
+
return "_(" + ref.scopeId + ")";
|
|
1209
|
+
}
|
|
1210
|
+
if (ref.id) {
|
|
1211
|
+
trackChannel(state, ref);
|
|
1212
|
+
return ref.id;
|
|
1213
|
+
}
|
|
1214
|
+
return assignId(state, ref);
|
|
1215
|
+
}
|
|
1216
|
+
function accessId(state, ref) {
|
|
1217
|
+
const id = ensureId(state, ref);
|
|
1218
|
+
return id === ref.id || ref.scopeId !== void 0 ? id : "(" + id + ")";
|
|
1333
1219
|
}
|
|
1334
1220
|
function assignId(state, ref) {
|
|
1335
1221
|
const { pos } = ref;
|
|
@@ -1339,17 +1225,20 @@ function assignId(state, ref) {
|
|
|
1339
1225
|
else state.buf[pos - 1] += ref.id + "=";
|
|
1340
1226
|
return ref.id;
|
|
1341
1227
|
}
|
|
1228
|
+
ref.channel = state.channel;
|
|
1342
1229
|
let cur = ref;
|
|
1343
1230
|
let accessPrevValue = "";
|
|
1344
1231
|
do {
|
|
1345
1232
|
accessPrevValue = toAccess(cur.accessor) + accessPrevValue;
|
|
1346
1233
|
const parent = cur.parent;
|
|
1347
1234
|
if (parent.id) {
|
|
1348
|
-
|
|
1349
|
-
|
|
1235
|
+
if (trackChannel(state, parent) || !parent.parent) {
|
|
1236
|
+
accessPrevValue = parent.id + accessPrevValue;
|
|
1237
|
+
break;
|
|
1238
|
+
}
|
|
1350
1239
|
}
|
|
1351
|
-
if (parent.flush === state.flush) {
|
|
1352
|
-
accessPrevValue =
|
|
1240
|
+
if (parent.flush === state.flush || parent.scopeId !== void 0) {
|
|
1241
|
+
accessPrevValue = accessId(state, parent) + accessPrevValue;
|
|
1353
1242
|
break;
|
|
1354
1243
|
}
|
|
1355
1244
|
cur = parent;
|
|
@@ -1418,15 +1307,206 @@ function patchIteratorNext(proto) {
|
|
|
1418
1307
|
};
|
|
1419
1308
|
proto.next[kTouchedIterator] = true;
|
|
1420
1309
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1310
|
+
//#endregion
|
|
1311
|
+
//#region src/common/helpers.ts
|
|
1312
|
+
const htmlAttrNameReg = /^[^a-z_]|[^a-z0-9._:-]/i;
|
|
1313
|
+
function stringifyClassObject(name, value) {
|
|
1314
|
+
return value ? name : "";
|
|
1315
|
+
}
|
|
1316
|
+
function stringifyStyleObject(name, value) {
|
|
1317
|
+
return value || value === 0 ? name + ":" + value : "";
|
|
1318
|
+
}
|
|
1319
|
+
const toDelimitedString = function toDelimitedString(val, delimiter, stringify) {
|
|
1320
|
+
let str = "";
|
|
1321
|
+
let sep = "";
|
|
1322
|
+
let part;
|
|
1323
|
+
if (val) if (typeof val !== "object") str += val;
|
|
1324
|
+
else if (Array.isArray(val)) for (const v of val) {
|
|
1325
|
+
part = toDelimitedString(v, delimiter, stringify);
|
|
1326
|
+
if (part) {
|
|
1327
|
+
str += sep + part;
|
|
1328
|
+
sep = delimiter;
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
else for (const name in val) {
|
|
1332
|
+
part = stringify(name, val[name]);
|
|
1333
|
+
if (part) {
|
|
1334
|
+
str += sep + part;
|
|
1335
|
+
sep = delimiter;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
return str;
|
|
1339
|
+
};
|
|
1340
|
+
function isEventHandler(name) {
|
|
1341
|
+
return /^on[A-Z-]/.test(name);
|
|
1342
|
+
}
|
|
1343
|
+
function getEventHandlerName(name) {
|
|
1344
|
+
return name[2] === "-" ? name.slice(3) : name.slice(2).toLowerCase();
|
|
1345
|
+
}
|
|
1346
|
+
function isVoid(value) {
|
|
1347
|
+
return value == null || value === false;
|
|
1348
|
+
}
|
|
1349
|
+
function normalizeDynamicRenderer(value) {
|
|
1350
|
+
if (value) {
|
|
1351
|
+
if (typeof value === "string") return value;
|
|
1352
|
+
const normalized = value.content || value.default || value;
|
|
1353
|
+
if ("id" in normalized) return normalized;
|
|
1354
|
+
}
|
|
1423
1355
|
}
|
|
1424
1356
|
//#endregion
|
|
1357
|
+
//#region src/common/for.ts
|
|
1358
|
+
function forIn(obj, cb) {
|
|
1359
|
+
for (const key in obj) cb(key, obj[key]);
|
|
1360
|
+
}
|
|
1361
|
+
function forOf(list, cb) {
|
|
1362
|
+
if (list) {
|
|
1363
|
+
let i = 0;
|
|
1364
|
+
for (const item of list) cb(item, i++);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
function forTo(to, from, step, cb) {
|
|
1368
|
+
const start = from || 0;
|
|
1369
|
+
const delta = step || 1;
|
|
1370
|
+
for (let steps = (to - start) / delta, i = 0; i <= steps; i++) cb(start + i * delta);
|
|
1371
|
+
}
|
|
1372
|
+
function forUntil(until, from, step, cb) {
|
|
1373
|
+
const start = from || 0;
|
|
1374
|
+
const delta = step || 1;
|
|
1375
|
+
for (let steps = (until - start) / delta, i = 0; i < steps; i++) cb(start + i * delta);
|
|
1376
|
+
}
|
|
1377
|
+
//#endregion
|
|
1378
|
+
//#region src/common/opt.ts
|
|
1379
|
+
function forEach(opt, cb) {
|
|
1380
|
+
if (opt) if (Array.isArray(opt)) for (const item of opt) cb(item);
|
|
1381
|
+
else cb(opt);
|
|
1382
|
+
}
|
|
1383
|
+
function push(opt, item) {
|
|
1384
|
+
return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
|
|
1385
|
+
}
|
|
1386
|
+
function concat(opt, other) {
|
|
1387
|
+
if (!opt) return other;
|
|
1388
|
+
if (!other) return opt;
|
|
1389
|
+
if (Array.isArray(opt)) {
|
|
1390
|
+
if (Array.isArray(other)) for (const item of other) opt.push(item);
|
|
1391
|
+
else opt.push(other);
|
|
1392
|
+
return opt;
|
|
1393
|
+
}
|
|
1394
|
+
return Array.isArray(other) ? [opt, ...other] : [opt, other];
|
|
1395
|
+
}
|
|
1396
|
+
//#endregion
|
|
1397
|
+
//#region src/html/for.ts
|
|
1398
|
+
function forOfBy(by, item, index) {
|
|
1399
|
+
if (by) {
|
|
1400
|
+
if (typeof by === "string") return item[by];
|
|
1401
|
+
return by(item, index);
|
|
1402
|
+
}
|
|
1403
|
+
return index;
|
|
1404
|
+
}
|
|
1405
|
+
function forInBy(by, name, value) {
|
|
1406
|
+
if (by) return by(name, value);
|
|
1407
|
+
return name;
|
|
1408
|
+
}
|
|
1409
|
+
function forStepBy(by, index) {
|
|
1410
|
+
if (by) return by(index);
|
|
1411
|
+
return index;
|
|
1412
|
+
}
|
|
1413
|
+
//#endregion
|
|
1414
|
+
//#region src/html/inlined-runtimes.debug.ts
|
|
1415
|
+
const WALKER_RUNTIME_CODE = `((runtimeId) => (self[runtimeId] ||= (
|
|
1416
|
+
renderId,
|
|
1417
|
+
prefix = runtimeId + renderId,
|
|
1418
|
+
prefixLen = prefix.length,
|
|
1419
|
+
lookup = {},
|
|
1420
|
+
visits = [],
|
|
1421
|
+
doc = document,
|
|
1422
|
+
walker = doc.createTreeWalker(
|
|
1423
|
+
doc,
|
|
1424
|
+
129 /* NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_ELEMENT */,
|
|
1425
|
+
),
|
|
1426
|
+
) =>
|
|
1427
|
+
doc = (self[runtimeId][renderId] = {
|
|
1428
|
+
i: prefix,
|
|
1429
|
+
d: doc,
|
|
1430
|
+
l: lookup,
|
|
1431
|
+
v: visits,
|
|
1432
|
+
x() {},
|
|
1433
|
+
w(node, op, id) {
|
|
1434
|
+
while ((node = walker.nextNode())) {
|
|
1435
|
+
doc.x(
|
|
1436
|
+
(op =
|
|
1437
|
+
(op = node.data) &&
|
|
1438
|
+
!op.indexOf(prefix) &&
|
|
1439
|
+
((lookup[(id = op.slice(prefixLen + 1))] = node), op[prefixLen])),
|
|
1440
|
+
id,
|
|
1441
|
+
node,
|
|
1442
|
+
);
|
|
1443
|
+
|
|
1444
|
+
if (op > "#") {
|
|
1445
|
+
visits.push(node);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
},
|
|
1449
|
+
})
|
|
1450
|
+
, self[runtimeId]))`;
|
|
1451
|
+
const REORDER_RUNTIME_CODE = `((runtime) => {
|
|
1452
|
+
if (runtime.j) return;
|
|
1453
|
+
let onNextSibling,
|
|
1454
|
+
placeholder,
|
|
1455
|
+
nextSibling,
|
|
1456
|
+
placeholders = runtime.p = {},
|
|
1457
|
+
replace = (id, container) => runtime.l[id].replaceWith(...container.childNodes);
|
|
1458
|
+
runtime.d.head.append(
|
|
1459
|
+
runtime.d.querySelector("style[" + runtime.i + "]") || ""
|
|
1460
|
+
);
|
|
1461
|
+
runtime.j = {};
|
|
1462
|
+
runtime.x = (op, id, node, placeholderRoot, placeholderCb) => {
|
|
1463
|
+
if (node == nextSibling) {
|
|
1464
|
+
onNextSibling();
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
if (op == "#") {
|
|
1468
|
+
(placeholders[id] = placeholder).i++;
|
|
1469
|
+
} else if (op == "!") {
|
|
1470
|
+
if (runtime.l[id] && placeholders[id]) {
|
|
1471
|
+
nextSibling = node.nextSibling;
|
|
1472
|
+
onNextSibling = () => placeholders[id].c();
|
|
1473
|
+
}
|
|
1474
|
+
} else if (node.tagName == "T" && (id = node.getAttribute(runtime.i))) {
|
|
1475
|
+
nextSibling = node.nextSibling;
|
|
1476
|
+
onNextSibling = () => {
|
|
1477
|
+
node.remove();
|
|
1478
|
+
placeholderRoot || replace(id, node);
|
|
1479
|
+
placeholder.c();
|
|
1480
|
+
};
|
|
1481
|
+
placeholder =
|
|
1482
|
+
placeholders[id] ||
|
|
1483
|
+
(placeholderRoot = placeholders[id] =
|
|
1484
|
+
{
|
|
1485
|
+
i: runtime.l[id] ? 1 : 2,
|
|
1486
|
+
c(start = runtime.l["^" + id]) {
|
|
1487
|
+
if (--placeholderRoot.i) return 1;
|
|
1488
|
+
for (
|
|
1489
|
+
;
|
|
1490
|
+
(nextSibling =
|
|
1491
|
+
runtime.l[id].previousSibling || start).remove(),
|
|
1492
|
+
start != nextSibling;
|
|
1493
|
+
|
|
1494
|
+
);
|
|
1495
|
+
replace(id, node);
|
|
1496
|
+
},
|
|
1497
|
+
});
|
|
1498
|
+
// repurpose "op" for callbacks ...carefully
|
|
1499
|
+
if ((op = runtime.j[id])) {
|
|
1500
|
+
placeholderCb = placeholder.c;
|
|
1501
|
+
placeholder.c = () => placeholderCb() || op(runtime.r);
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
})`;
|
|
1506
|
+
//#endregion
|
|
1425
1507
|
//#region src/html/writer.ts
|
|
1426
1508
|
let $chunk;
|
|
1427
1509
|
const NOOP$2 = () => {};
|
|
1428
|
-
const K_SCOPE_ID = Symbol("Scope ID");
|
|
1429
|
-
const K_SCOPE_REFERENCED = Symbol("Scope Referenced");
|
|
1430
1510
|
function getChunk() {
|
|
1431
1511
|
return $chunk;
|
|
1432
1512
|
}
|
|
@@ -1445,8 +1525,28 @@ function _html(html) {
|
|
|
1445
1525
|
function writeScript(script) {
|
|
1446
1526
|
$chunk.writeScript(script);
|
|
1447
1527
|
}
|
|
1528
|
+
function writeWaitReady(readyId, renderer, input) {
|
|
1529
|
+
const chunk = $chunk;
|
|
1530
|
+
const { boundary } = chunk;
|
|
1531
|
+
const body = new Chunk(boundary, null, chunk.context, {
|
|
1532
|
+
readyId,
|
|
1533
|
+
parent: chunk.serializeState,
|
|
1534
|
+
resumes: "",
|
|
1535
|
+
writeScopes: {},
|
|
1536
|
+
flushScopes: false
|
|
1537
|
+
});
|
|
1538
|
+
const bodyEnd = body.render(renderer, input);
|
|
1539
|
+
if (body === bodyEnd) {
|
|
1540
|
+
chunk.writeHTML(body.html);
|
|
1541
|
+
body.deferOwnReady();
|
|
1542
|
+
chunk.deferredReady = push(chunk.deferredReady, body);
|
|
1543
|
+
} else {
|
|
1544
|
+
bodyEnd.next = $chunk = chunk.fork(boundary, chunk.next);
|
|
1545
|
+
chunk.next = body;
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1448
1548
|
function _script(scopeId, registryId) {
|
|
1449
|
-
if ($chunk.context?.[kIsAsync]) _resume_branch(scopeId);
|
|
1549
|
+
if ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync]) _resume_branch(scopeId);
|
|
1450
1550
|
$chunk.boundary.state.needsMainRuntime = true;
|
|
1451
1551
|
$chunk.writeEffect(scopeId, registryId);
|
|
1452
1552
|
}
|
|
@@ -1458,7 +1558,7 @@ function _attr_content(nodeAccessor, scopeId, content, serializeReason) {
|
|
|
1458
1558
|
else render();
|
|
1459
1559
|
if (_peek_scope_id() !== branchId) {
|
|
1460
1560
|
if (shouldResume) writeScope(scopeId, {
|
|
1461
|
-
["BranchScopes:" + nodeAccessor]:
|
|
1561
|
+
["BranchScopes:" + nodeAccessor]: writeScope(branchId, {}),
|
|
1462
1562
|
["ConditionalRenderer:" + nodeAccessor]: render?.["id"]
|
|
1463
1563
|
});
|
|
1464
1564
|
} else _scope_id();
|
|
@@ -1482,13 +1582,20 @@ function withContext(key, value, cb, cbValue) {
|
|
|
1482
1582
|
}
|
|
1483
1583
|
}
|
|
1484
1584
|
function _var(parentScopeId, scopeOffsetAccessor, childScopeId, registryId, nodeAccessor) {
|
|
1485
|
-
|
|
1486
|
-
const childScope =
|
|
1487
|
-
childScope["#TagVariable"] = _resume({}, registryId, parentScopeId);
|
|
1585
|
+
writeScopePassive(parentScopeId, { [scopeOffsetAccessor]: _scope_id() });
|
|
1586
|
+
const childScope = writeScopePassive(childScopeId, { ["#TagVariable"]: _resume({}, registryId, parentScopeId) });
|
|
1488
1587
|
if (nodeAccessor !== void 0) writeScope(parentScopeId, { ["BranchScopes:" + nodeAccessor]: childScope });
|
|
1489
1588
|
}
|
|
1589
|
+
function writeScopePassive(scopeId, partialScope) {
|
|
1590
|
+
const target = $chunk.serializeState;
|
|
1591
|
+
const scope = _scope_with_id(scopeId);
|
|
1592
|
+
const passive = target.passiveScopes ||= {};
|
|
1593
|
+
Object.assign(scope, partialScope);
|
|
1594
|
+
passive[scopeId] = Object.assign(passive[scopeId] || {}, partialScope);
|
|
1595
|
+
return scope;
|
|
1596
|
+
}
|
|
1490
1597
|
function _resume(val, id, scopeId) {
|
|
1491
|
-
return scopeId === void 0 ?
|
|
1598
|
+
return register(id, val, scopeId === void 0 ? void 0 : _scope_with_id(scopeId));
|
|
1492
1599
|
}
|
|
1493
1600
|
function _id() {
|
|
1494
1601
|
const state = $chunk.boundary.state;
|
|
@@ -1516,7 +1623,7 @@ function _serialize_if(condition, key) {
|
|
|
1516
1623
|
return condition && (condition === 1 || condition[key]) ? 1 : void 0;
|
|
1517
1624
|
}
|
|
1518
1625
|
function _serialize_guard(condition, key) {
|
|
1519
|
-
return
|
|
1626
|
+
return _serialize_if(condition, key) || 0;
|
|
1520
1627
|
}
|
|
1521
1628
|
function _el_resume(scopeId, accessor, shouldResume) {
|
|
1522
1629
|
if (shouldResume === 0) return "";
|
|
@@ -1551,127 +1658,58 @@ function withIsAsync(cb, value) {
|
|
|
1551
1658
|
return withContext(kIsAsync, true, cb, value);
|
|
1552
1659
|
}
|
|
1553
1660
|
function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
if (serializeBranch !== 0) {
|
|
1559
|
-
let loopScopes;
|
|
1560
|
-
var seenKeys = /* @__PURE__ */ new Set();
|
|
1561
|
-
forOf(list, (item, index) => {
|
|
1562
|
-
const branchId = _peek_scope_id();
|
|
1563
|
-
const itemKey = forOfBy(by, item, index);
|
|
1564
|
-
if (by) {
|
|
1565
|
-
if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
|
|
1566
|
-
seenKeys.add(itemKey);
|
|
1567
|
-
}
|
|
1568
|
-
if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
|
|
1569
|
-
else {
|
|
1570
|
-
$chunk.writeHTML(state.mark("[", flushBranchIds));
|
|
1571
|
-
flushBranchIds = branchId + "";
|
|
1572
|
-
}
|
|
1573
|
-
withBranchId(branchId, () => {
|
|
1574
|
-
cb(item, index);
|
|
1575
|
-
const branchScope = writeScope(branchId, {});
|
|
1576
|
-
if (resumeKeys && itemKey !== index) branchScope["#LoopKey"] = itemKey;
|
|
1577
|
-
if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
|
|
1578
|
-
});
|
|
1579
|
-
});
|
|
1580
|
-
if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
|
|
1581
|
-
} else forOf(list, cb);
|
|
1582
|
-
writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
|
|
1661
|
+
forBranches(by, (each) => each ? forOf(list, (item, index) => {
|
|
1662
|
+
const itemKey = forOfBy(by, item, index);
|
|
1663
|
+
each(itemKey, itemKey === index, () => cb(item, index));
|
|
1664
|
+
}) : forOf(list, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
|
|
1583
1665
|
}
|
|
1584
1666
|
function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
let flushBranchIds = "";
|
|
1589
|
-
if (serializeBranch !== 0) {
|
|
1590
|
-
let loopScopes;
|
|
1591
|
-
var seenKeys = /* @__PURE__ */ new Set();
|
|
1592
|
-
forIn(obj, (key, value) => {
|
|
1593
|
-
const branchId = _peek_scope_id();
|
|
1594
|
-
const itemKey = forInBy(by, key, value);
|
|
1595
|
-
if (by) {
|
|
1596
|
-
if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
|
|
1597
|
-
seenKeys.add(itemKey);
|
|
1598
|
-
}
|
|
1599
|
-
if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
|
|
1600
|
-
else {
|
|
1601
|
-
$chunk.writeHTML(state.mark("[", flushBranchIds));
|
|
1602
|
-
flushBranchIds = branchId + "";
|
|
1603
|
-
}
|
|
1604
|
-
withBranchId(branchId, () => {
|
|
1605
|
-
cb(key, value);
|
|
1606
|
-
const branchScope = writeScope(branchId, {});
|
|
1607
|
-
if (resumeKeys) branchScope["#LoopKey"] = itemKey;
|
|
1608
|
-
if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
|
|
1609
|
-
});
|
|
1610
|
-
});
|
|
1611
|
-
if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
|
|
1612
|
-
} else forIn(obj, cb);
|
|
1613
|
-
writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
|
|
1667
|
+
forBranches(by, (each) => each ? forIn(obj, (key, value) => {
|
|
1668
|
+
each(forInBy(by, key, value), false, () => cb(key, value));
|
|
1669
|
+
}) : forIn(obj, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
|
|
1614
1670
|
}
|
|
1615
1671
|
function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
if (serializeBranch !== 0) {
|
|
1621
|
-
let loopScopes;
|
|
1622
|
-
var seenKeys = /* @__PURE__ */ new Set();
|
|
1623
|
-
forTo(to, from, step, (i) => {
|
|
1624
|
-
const branchId = _peek_scope_id();
|
|
1625
|
-
const itemKey = forStepBy(by, i);
|
|
1626
|
-
if (by) {
|
|
1627
|
-
if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
|
|
1628
|
-
seenKeys.add(itemKey);
|
|
1629
|
-
}
|
|
1630
|
-
if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
|
|
1631
|
-
else {
|
|
1632
|
-
$chunk.writeHTML(state.mark("[", flushBranchIds));
|
|
1633
|
-
flushBranchIds = branchId + "";
|
|
1634
|
-
}
|
|
1635
|
-
withBranchId(branchId, () => {
|
|
1636
|
-
cb(i);
|
|
1637
|
-
const branchScope = writeScope(branchId, {});
|
|
1638
|
-
if (resumeKeys && itemKey !== i) branchScope["#LoopKey"] = itemKey;
|
|
1639
|
-
if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
|
|
1640
|
-
});
|
|
1641
|
-
});
|
|
1642
|
-
if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
|
|
1643
|
-
} else forTo(to, from, step, cb);
|
|
1644
|
-
writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
|
|
1672
|
+
forBranches(by, (each) => each ? forTo(to, from, step, (i) => {
|
|
1673
|
+
const itemKey = forStepBy(by, i);
|
|
1674
|
+
each(itemKey, itemKey === i, () => cb(i));
|
|
1675
|
+
}) : forTo(to, from, step, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
|
|
1645
1676
|
}
|
|
1646
1677
|
function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
|
|
1678
|
+
forBranches(by, (each) => each ? forUntil(to, from, step, (i) => {
|
|
1679
|
+
const itemKey = forStepBy(by, i);
|
|
1680
|
+
each(itemKey, itemKey === i, () => cb(i));
|
|
1681
|
+
}) : forUntil(to, from, step, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
|
|
1682
|
+
}
|
|
1683
|
+
function forBranches(by, iterate, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
|
|
1684
|
+
if (serializeBranch === 0) {
|
|
1685
|
+
iterate(0);
|
|
1686
|
+
writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, "");
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1647
1689
|
const { state } = $chunk.boundary;
|
|
1648
1690
|
const resumeKeys = serializeMarker !== 0;
|
|
1649
1691
|
const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
|
|
1650
1692
|
let flushBranchIds = "";
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
const branchScope = writeScope(branchId, {});
|
|
1669
|
-
if (resumeKeys && itemKey !== i) branchScope["#LoopKey"] = itemKey;
|
|
1670
|
-
if (!resumeMarker) loopScopes = push(loopScopes, referenceScope(branchScope));
|
|
1671
|
-
});
|
|
1693
|
+
let loopScopes;
|
|
1694
|
+
var seenKeys = /* @__PURE__ */ new Set();
|
|
1695
|
+
iterate((itemKey, sameAsIndex, render) => {
|
|
1696
|
+
const branchId = _peek_scope_id();
|
|
1697
|
+
if (by) {
|
|
1698
|
+
if (seenKeys.has(itemKey)) console.error(`A <for> tag's \`by\` attribute must return a unique value for each item, but a duplicate was found matching:`, itemKey);
|
|
1699
|
+
seenKeys.add(itemKey);
|
|
1700
|
+
}
|
|
1701
|
+
if (resumeMarker) if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
|
|
1702
|
+
else {
|
|
1703
|
+
$chunk.writeHTML(state.mark("[", flushBranchIds));
|
|
1704
|
+
flushBranchIds = branchId + "";
|
|
1705
|
+
}
|
|
1706
|
+
withBranchId(branchId, () => {
|
|
1707
|
+
render();
|
|
1708
|
+
const branchScope = writeScope(branchId, resumeKeys && !sameAsIndex ? { ["#LoopKey"]: itemKey } : {});
|
|
1709
|
+
if (!resumeMarker) loopScopes = push(loopScopes, branchScope);
|
|
1672
1710
|
});
|
|
1673
|
-
|
|
1674
|
-
|
|
1711
|
+
});
|
|
1712
|
+
if (loopScopes) writeScope(scopeId, { ["BranchScopes:" + accessor]: loopScopes });
|
|
1675
1713
|
writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
|
|
1676
1714
|
}
|
|
1677
1715
|
function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
|
|
@@ -1684,7 +1722,7 @@ function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeS
|
|
|
1684
1722
|
const shouldWriteBranch = resumeBranch && branchIndex !== void 0;
|
|
1685
1723
|
if (shouldWriteBranch && (branchIndex || !resumeMarker)) writeScope(scopeId, {
|
|
1686
1724
|
["ConditionalRenderer:" + accessor]: branchIndex || void 0,
|
|
1687
|
-
["BranchScopes:" + accessor]: resumeMarker ? void 0 :
|
|
1725
|
+
["BranchScopes:" + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
|
|
1688
1726
|
});
|
|
1689
1727
|
writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, shouldWriteBranch ? " " + branchId : "");
|
|
1690
1728
|
}
|
|
@@ -1697,46 +1735,34 @@ function writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, p
|
|
|
1697
1735
|
} else $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
|
|
1698
1736
|
else $chunk.writeHTML(endTag);
|
|
1699
1737
|
}
|
|
1700
|
-
function scopeHasReference(scope) {
|
|
1701
|
-
return !!scope[K_SCOPE_REFERENCED];
|
|
1702
|
-
}
|
|
1703
|
-
function referenceScope(scope) {
|
|
1704
|
-
scope[K_SCOPE_REFERENCED] = 1;
|
|
1705
|
-
return scope;
|
|
1706
|
-
}
|
|
1707
1738
|
let writeScope = (scopeId, partialScope) => {
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
const
|
|
1712
|
-
let scope = scopes.get(scopeId);
|
|
1739
|
+
const { state } = $chunk.boundary;
|
|
1740
|
+
const target = $chunk.serializeState;
|
|
1741
|
+
const scope = scopeWithId(state, scopeId);
|
|
1742
|
+
const pending = target.writeScopes[scopeId];
|
|
1713
1743
|
state.needsMainRuntime = true;
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
state.scopes.set(scopeId, scope);
|
|
1719
|
-
}
|
|
1720
|
-
if (state.writeScopes) state.writeScopes[scopeId] = scope;
|
|
1721
|
-
else state.writeScopes = { [scopeId]: scope };
|
|
1744
|
+
Object.assign(scope, partialScope);
|
|
1745
|
+
if (pending && pending !== partialScope) Object.assign(pending, partialScope);
|
|
1746
|
+
else target.writeScopes[scopeId] = partialScope;
|
|
1747
|
+
target.flushScopes = true;
|
|
1722
1748
|
return scope;
|
|
1723
|
-
}
|
|
1749
|
+
};
|
|
1724
1750
|
writeScope = ((writeScope) => (scopeId, partialScope, file, loc, vars) => {
|
|
1725
1751
|
const scope = writeScope(scopeId, partialScope);
|
|
1726
1752
|
if (file && loc !== void 0) setDebugInfo(scope, file, loc, vars);
|
|
1727
1753
|
return scope;
|
|
1728
1754
|
})(writeScope);
|
|
1729
1755
|
function _existing_scope(scopeId) {
|
|
1730
|
-
return writeScope(scopeId,
|
|
1756
|
+
return writeScope(scopeId, {});
|
|
1731
1757
|
}
|
|
1732
1758
|
function _scope_with_id(scopeId) {
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
}
|
|
1739
|
-
return
|
|
1759
|
+
return scopeWithId($chunk.boundary.state, scopeId);
|
|
1760
|
+
}
|
|
1761
|
+
function scopeWithId(state, scopeId) {
|
|
1762
|
+
const { scopes } = state;
|
|
1763
|
+
let scope = scopes.get(scopeId);
|
|
1764
|
+
if (!scope) scopes.set(scopeId, scope = { [K_SCOPE_ID]: scopeId });
|
|
1765
|
+
return scope;
|
|
1740
1766
|
}
|
|
1741
1767
|
function $global() {
|
|
1742
1768
|
return $chunk.boundary.state.$global;
|
|
@@ -1754,7 +1780,7 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
|
|
|
1754
1780
|
}
|
|
1755
1781
|
const chunk = $chunk;
|
|
1756
1782
|
const { boundary } = chunk;
|
|
1757
|
-
chunk.next = $chunk =
|
|
1783
|
+
chunk.next = $chunk = chunk.fork(boundary, chunk.next);
|
|
1758
1784
|
chunk.async = true;
|
|
1759
1785
|
if (chunk.context?.[kPendingContexts]) chunk.context = {
|
|
1760
1786
|
...chunk.context,
|
|
@@ -1799,22 +1825,24 @@ function _try(scopeId, accessor, content, input) {
|
|
|
1799
1825
|
function tryPlaceholder(content, placeholder, branchId) {
|
|
1800
1826
|
const chunk = $chunk;
|
|
1801
1827
|
const { boundary } = chunk;
|
|
1802
|
-
const body =
|
|
1828
|
+
const body = chunk.fork(boundary, null);
|
|
1803
1829
|
if (body === body.render(content)) {
|
|
1804
1830
|
chunk.append(body);
|
|
1805
1831
|
return;
|
|
1806
1832
|
}
|
|
1807
|
-
chunk.next = $chunk =
|
|
1808
|
-
chunk.
|
|
1809
|
-
|
|
1810
|
-
|
|
1833
|
+
chunk.next = $chunk = chunk.fork(boundary, chunk.next);
|
|
1834
|
+
chunk.placeholder = {
|
|
1835
|
+
body,
|
|
1836
|
+
render: placeholder,
|
|
1837
|
+
branchId
|
|
1838
|
+
};
|
|
1811
1839
|
}
|
|
1812
1840
|
function tryCatch(content, catchContent) {
|
|
1813
1841
|
const chunk = $chunk;
|
|
1814
1842
|
const { boundary } = chunk;
|
|
1815
1843
|
const { state } = boundary;
|
|
1816
1844
|
const catchBoundary = new Boundary(state);
|
|
1817
|
-
const body =
|
|
1845
|
+
const body = chunk.fork(catchBoundary, null);
|
|
1818
1846
|
const bodyEnd = body.render(content);
|
|
1819
1847
|
if (catchBoundary.signal.aborted) {
|
|
1820
1848
|
catchContent(catchBoundary.signal.reason);
|
|
@@ -1826,7 +1854,7 @@ function tryCatch(content, catchContent) {
|
|
|
1826
1854
|
}
|
|
1827
1855
|
const reorderId = state.nextReorderId();
|
|
1828
1856
|
const endMarker = state.mark("!", reorderId);
|
|
1829
|
-
const bodyNext = bodyEnd.next = $chunk =
|
|
1857
|
+
const bodyNext = bodyEnd.next = $chunk = body.fork(boundary, chunk.next);
|
|
1830
1858
|
chunk.next = body;
|
|
1831
1859
|
chunk.writeHTML(state.mark("!^", reorderId));
|
|
1832
1860
|
bodyEnd.writeHTML(endMarker);
|
|
@@ -1847,12 +1875,12 @@ function tryCatch(content, catchContent) {
|
|
|
1847
1875
|
cur.needsWalk = true;
|
|
1848
1876
|
cur.html = endMarker;
|
|
1849
1877
|
cur.scripts = cur.effects = cur.lastEffect = "";
|
|
1850
|
-
cur.
|
|
1878
|
+
cur.placeholder = cur.reorderId = cur.deferredReady = null;
|
|
1851
1879
|
}
|
|
1852
1880
|
cur = next;
|
|
1853
1881
|
} while (cur !== bodyNext);
|
|
1854
1882
|
}
|
|
1855
|
-
const catchChunk =
|
|
1883
|
+
const catchChunk = chunk.fork(boundary, null);
|
|
1856
1884
|
catchChunk.reorderId = reorderId;
|
|
1857
1885
|
catchChunk.render(catchContent, catchBoundary.signal.reason);
|
|
1858
1886
|
state.reorder(catchChunk);
|
|
@@ -1866,10 +1894,11 @@ var State = class {
|
|
|
1866
1894
|
tagId = 1;
|
|
1867
1895
|
scopeId = 1;
|
|
1868
1896
|
reorderId = 1;
|
|
1869
|
-
|
|
1897
|
+
readyGate = 1;
|
|
1870
1898
|
hasGlobals = false;
|
|
1871
1899
|
needsMainRuntime = false;
|
|
1872
1900
|
hasMainRuntime = false;
|
|
1901
|
+
hasReadyRuntime = false;
|
|
1873
1902
|
hasReorderRuntime = false;
|
|
1874
1903
|
hasWrittenResume = false;
|
|
1875
1904
|
walkOnNextFlush = false;
|
|
@@ -1879,11 +1908,11 @@ var State = class {
|
|
|
1879
1908
|
serializer = new Serializer();
|
|
1880
1909
|
writeReorders = null;
|
|
1881
1910
|
scopes = /* @__PURE__ */ new Map();
|
|
1882
|
-
|
|
1883
|
-
|
|
1911
|
+
flushScopes = false;
|
|
1912
|
+
writeScopes = {};
|
|
1913
|
+
readyIds = null;
|
|
1884
1914
|
serializeReason;
|
|
1885
1915
|
constructor($global) {
|
|
1886
|
-
this.$global = $global;
|
|
1887
1916
|
this.$global = $global;
|
|
1888
1917
|
if ($global.cspNonce) this.nonceAttr = " nonce" + attrAssignment($global.cspNonce);
|
|
1889
1918
|
}
|
|
@@ -1902,6 +1931,17 @@ var State = class {
|
|
|
1902
1931
|
this.writeReorders = [chunk];
|
|
1903
1932
|
}
|
|
1904
1933
|
}
|
|
1934
|
+
writeReady(id, resumes) {
|
|
1935
|
+
const readyKey = toObjectKey(id);
|
|
1936
|
+
if (this.readyIds?.has(id)) return this.readyAccess(readyKey) + ".push(" + resumes + ")";
|
|
1937
|
+
(this.readyIds ||= /* @__PURE__ */ new Set()).add(id);
|
|
1938
|
+
if (this.hasReadyRuntime) return this.readyAccess(readyKey) + "=[" + resumes + "]";
|
|
1939
|
+
this.hasReadyRuntime = true;
|
|
1940
|
+
return this.runtimePrefix + ".b={" + readyKey + ":[" + resumes + "]}";
|
|
1941
|
+
}
|
|
1942
|
+
readyAccess(readyKey) {
|
|
1943
|
+
return this.runtimePrefix + ".b" + toAccess(readyKey);
|
|
1944
|
+
}
|
|
1905
1945
|
nextReorderId() {
|
|
1906
1946
|
const c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789";
|
|
1907
1947
|
let n = this.reorderId++;
|
|
@@ -1920,7 +1960,6 @@ var Boundary = class extends AbortController {
|
|
|
1920
1960
|
constructor(state, parent) {
|
|
1921
1961
|
super();
|
|
1922
1962
|
this.state = state;
|
|
1923
|
-
this.state = state;
|
|
1924
1963
|
this.signal.addEventListener("abort", () => {
|
|
1925
1964
|
this.count = 0;
|
|
1926
1965
|
this.state = new State(this.state.$global);
|
|
@@ -1932,7 +1971,7 @@ var Boundary = class extends AbortController {
|
|
|
1932
1971
|
});
|
|
1933
1972
|
}
|
|
1934
1973
|
flush() {
|
|
1935
|
-
if (!this.signal.aborted) flushSerializer(this);
|
|
1974
|
+
if (!this.signal.aborted) flushSerializer(this, this.state);
|
|
1936
1975
|
return this.count ? 1 : this.signal.aborted ? 2 : 0;
|
|
1937
1976
|
}
|
|
1938
1977
|
startAsync() {
|
|
@@ -1946,10 +1985,11 @@ var Boundary = class extends AbortController {
|
|
|
1946
1985
|
}
|
|
1947
1986
|
}
|
|
1948
1987
|
};
|
|
1949
|
-
var Chunk = class {
|
|
1988
|
+
var Chunk = class Chunk {
|
|
1950
1989
|
boundary;
|
|
1951
1990
|
next;
|
|
1952
1991
|
context;
|
|
1992
|
+
serializeState;
|
|
1953
1993
|
html = "";
|
|
1954
1994
|
scripts = "";
|
|
1955
1995
|
effects = "";
|
|
@@ -1958,16 +1998,16 @@ var Chunk = class {
|
|
|
1958
1998
|
consumed = false;
|
|
1959
1999
|
needsWalk = false;
|
|
1960
2000
|
reorderId = null;
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
constructor(boundary, next, context) {
|
|
1965
|
-
this.boundary = boundary;
|
|
1966
|
-
this.next = next;
|
|
1967
|
-
this.context = context;
|
|
2001
|
+
deferredReady = null;
|
|
2002
|
+
placeholder = null;
|
|
2003
|
+
constructor(boundary, next, context, serializeState) {
|
|
1968
2004
|
this.boundary = boundary;
|
|
1969
2005
|
this.next = next;
|
|
1970
2006
|
this.context = context;
|
|
2007
|
+
this.serializeState = serializeState;
|
|
2008
|
+
}
|
|
2009
|
+
fork(boundary, next) {
|
|
2010
|
+
return new Chunk(boundary, next, this.context, this.serializeState);
|
|
1971
2011
|
}
|
|
1972
2012
|
writeHTML(html) {
|
|
1973
2013
|
this.html += html;
|
|
@@ -1987,16 +2027,31 @@ var Chunk = class {
|
|
|
1987
2027
|
this.effects = concatEffects(this.effects, chunk.effects);
|
|
1988
2028
|
this.scripts = concatScripts(this.scripts, chunk.scripts);
|
|
1989
2029
|
this.lastEffect = chunk.lastEffect || this.lastEffect;
|
|
2030
|
+
this.deferredReady = concat(this.deferredReady, chunk.takeDeferredReady());
|
|
2031
|
+
}
|
|
2032
|
+
takeDeferredReady() {
|
|
2033
|
+
const { deferredReady } = this;
|
|
2034
|
+
this.deferredReady = null;
|
|
2035
|
+
return deferredReady;
|
|
2036
|
+
}
|
|
2037
|
+
deferOwnReady() {
|
|
2038
|
+
if (this.serializeState.readyId && (this.effects || this.scripts || this.serializeState.flushScopes)) {
|
|
2039
|
+
const deferred = this.fork(this.boundary, null);
|
|
2040
|
+
deferred.effects = this.effects;
|
|
2041
|
+
deferred.scripts = this.scripts;
|
|
2042
|
+
this.effects = this.scripts = this.lastEffect = "";
|
|
2043
|
+
this.deferredReady = concat(deferred, this.deferredReady);
|
|
2044
|
+
}
|
|
1990
2045
|
}
|
|
1991
2046
|
flushPlaceholder() {
|
|
1992
|
-
|
|
1993
|
-
|
|
2047
|
+
const { placeholder } = this;
|
|
2048
|
+
if (placeholder) {
|
|
2049
|
+
const body = placeholder.body.consume();
|
|
1994
2050
|
if (body.async) {
|
|
1995
2051
|
const { state } = this.boundary;
|
|
1996
|
-
const reorderId = body.reorderId =
|
|
1997
|
-
this.placeholderBranchId = null;
|
|
2052
|
+
const reorderId = body.reorderId = placeholder.branchId ? placeholder.branchId + "" : state.nextReorderId();
|
|
1998
2053
|
this.writeHTML(state.mark("!^", reorderId));
|
|
1999
|
-
const after = this.render(
|
|
2054
|
+
const after = this.render(placeholder.render);
|
|
2000
2055
|
if (after !== this) this.boundary.abort(/* @__PURE__ */ new Error("An @placeholder cannot contain async content."));
|
|
2001
2056
|
after.writeHTML(state.mark("!", reorderId));
|
|
2002
2057
|
state.reorder(body);
|
|
@@ -2004,33 +2059,38 @@ var Chunk = class {
|
|
|
2004
2059
|
body.next = this.next;
|
|
2005
2060
|
this.next = body;
|
|
2006
2061
|
}
|
|
2007
|
-
this.
|
|
2062
|
+
this.placeholder = null;
|
|
2008
2063
|
}
|
|
2009
2064
|
}
|
|
2010
2065
|
consume() {
|
|
2011
2066
|
let cur = this;
|
|
2012
|
-
let
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2067
|
+
let html = "";
|
|
2068
|
+
let effects = "";
|
|
2069
|
+
let scripts = "";
|
|
2070
|
+
let lastEffect = "";
|
|
2071
|
+
let needsWalk = false;
|
|
2072
|
+
let deferredReady;
|
|
2073
|
+
while (cur.next && !cur.async) {
|
|
2074
|
+
cur.flushPlaceholder();
|
|
2075
|
+
needsWalk ||= cur.needsWalk;
|
|
2076
|
+
html += cur.html;
|
|
2077
|
+
if (cur.serializeState.readyId) deferredReady = push(deferredReady, cur);
|
|
2078
|
+
else {
|
|
2022
2079
|
effects = concatEffects(effects, cur.effects);
|
|
2023
2080
|
scripts = concatScripts(scripts, cur.scripts);
|
|
2024
2081
|
lastEffect = cur.lastEffect || lastEffect;
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
cur
|
|
2029
|
-
cur.html = html + cur.html;
|
|
2030
|
-
cur.effects = concatEffects(effects, cur.effects);
|
|
2031
|
-
cur.scripts = concatScripts(scripts, cur.scripts);
|
|
2032
|
-
cur.lastEffect = lastEffect;
|
|
2082
|
+
}
|
|
2083
|
+
deferredReady = concat(deferredReady, cur.takeDeferredReady());
|
|
2084
|
+
cur.consumed = true;
|
|
2085
|
+
cur = cur.next;
|
|
2033
2086
|
}
|
|
2087
|
+
cur.deferOwnReady();
|
|
2088
|
+
cur.deferredReady = concat(deferredReady, cur.deferredReady);
|
|
2089
|
+
cur.needsWalk ||= needsWalk;
|
|
2090
|
+
cur.html = html + cur.html;
|
|
2091
|
+
cur.effects = concatEffects(effects, cur.effects);
|
|
2092
|
+
cur.scripts = concatScripts(scripts, cur.scripts);
|
|
2093
|
+
cur.lastEffect ||= lastEffect;
|
|
2034
2094
|
return cur;
|
|
2035
2095
|
}
|
|
2036
2096
|
render(content, val) {
|
|
@@ -2046,28 +2106,57 @@ var Chunk = class {
|
|
|
2046
2106
|
$chunk = prev;
|
|
2047
2107
|
}
|
|
2048
2108
|
}
|
|
2109
|
+
flushReadyScripts(reservations) {
|
|
2110
|
+
const { boundary, serializeState } = this;
|
|
2111
|
+
const { readyId } = serializeState;
|
|
2112
|
+
let scripts = "";
|
|
2113
|
+
forEach(this.takeDeferredReady(), (chunk) => {
|
|
2114
|
+
scripts = concatScripts(scripts, chunk.flushReadyScripts(reservations));
|
|
2115
|
+
});
|
|
2116
|
+
if (readyId && !this.async) {
|
|
2117
|
+
const { state } = boundary;
|
|
2118
|
+
flushSerializer(boundary, serializeState);
|
|
2119
|
+
const deps = state.serializer.takeChannelDeps();
|
|
2120
|
+
const { effects } = this;
|
|
2121
|
+
const { resumes } = serializeState;
|
|
2122
|
+
const chunkScripts = this.scripts;
|
|
2123
|
+
serializeState.resumes = "";
|
|
2124
|
+
this.effects = this.scripts = "";
|
|
2125
|
+
this.lastEffect = "";
|
|
2126
|
+
if (resumes || effects) {
|
|
2127
|
+
state.needsMainRuntime = true;
|
|
2128
|
+
const batch = concatSequence(depsMarker(deps), concatSequence(resumes, effects && `"${effects}"`));
|
|
2129
|
+
if (reservations) {
|
|
2130
|
+
const gate = state.readyGate++;
|
|
2131
|
+
reservations.push(state.writeReady(readyId, gate + ""));
|
|
2132
|
+
scripts = concatScripts(scripts, "(b=>b.splice(b.indexOf(" + gate + "),1," + batch + "))(" + state.readyAccess(toObjectKey(readyId)) + ")");
|
|
2133
|
+
} else scripts = concatScripts(scripts, state.writeReady(readyId, batch));
|
|
2134
|
+
}
|
|
2135
|
+
scripts = concatScripts(scripts, chunkScripts);
|
|
2136
|
+
}
|
|
2137
|
+
return scripts;
|
|
2138
|
+
}
|
|
2049
2139
|
flushScript() {
|
|
2050
|
-
const { boundary
|
|
2140
|
+
const { boundary } = this;
|
|
2051
2141
|
const { state } = boundary;
|
|
2052
2142
|
const { $global, runtimePrefix, nonceAttr } = state;
|
|
2053
|
-
let { html, scripts } = this;
|
|
2054
2143
|
let needsWalk = state.walkOnNextFlush;
|
|
2055
2144
|
if (needsWalk) state.walkOnNextFlush = false;
|
|
2145
|
+
let readyResumeScripts = this.flushReadyScripts();
|
|
2146
|
+
for (let channel; channel = state.serializer.pendingReadyChannel();) {
|
|
2147
|
+
const resumes = state.serializer.stringifyScopes([], 0, boundary, channel);
|
|
2148
|
+
const deps = state.serializer.takeChannelDeps();
|
|
2149
|
+
state.needsMainRuntime = true;
|
|
2150
|
+
readyResumeScripts = concatScripts(readyResumeScripts, state.writeReady(channel.readyId, concatSequence(depsMarker(deps), resumes)));
|
|
2151
|
+
}
|
|
2152
|
+
if (readyResumeScripts) needsWalk = true;
|
|
2153
|
+
const { effects } = this;
|
|
2154
|
+
let { html, scripts } = this;
|
|
2056
2155
|
if (state.needsMainRuntime && !state.hasMainRuntime) {
|
|
2057
2156
|
state.hasMainRuntime = true;
|
|
2058
2157
|
scripts = concatScripts(scripts, WALKER_RUNTIME_CODE + "(\"" + $global.runtimeId + "\")(\"" + $global.renderId + "\")");
|
|
2059
2158
|
}
|
|
2060
|
-
|
|
2061
|
-
let first = true;
|
|
2062
|
-
for (const id in state.ensureReady) {
|
|
2063
|
-
if (state.ensureReady[id]) {
|
|
2064
|
-
state.ensureReady[id] = 0;
|
|
2065
|
-
if (first) scripts = concatScripts(scripts, "(" + runtimePrefix + ".b={})" + toAccess(toObjectKey(id)) + "=1");
|
|
2066
|
-
else scripts = concatScripts(scripts, runtimePrefix + ".b" + toAccess(toObjectKey(id)) + "=1");
|
|
2067
|
-
}
|
|
2068
|
-
first = false;
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2159
|
+
scripts = concatScripts(scripts, readyResumeScripts);
|
|
2071
2160
|
if (effects) {
|
|
2072
2161
|
needsWalk = true;
|
|
2073
2162
|
state.resumes = state.resumes ? state.resumes + ",\"" + effects + "\"" : "\"" + effects + "\"";
|
|
@@ -2086,6 +2175,7 @@ var Chunk = class {
|
|
|
2086
2175
|
}
|
|
2087
2176
|
for (const reorderedChunk of state.writeReorders) {
|
|
2088
2177
|
const { reorderId } = reorderedChunk;
|
|
2178
|
+
const readyReservations = [];
|
|
2089
2179
|
let reorderHTML = "";
|
|
2090
2180
|
let reorderEffects = "";
|
|
2091
2181
|
let reorderScripts = "";
|
|
@@ -2093,11 +2183,13 @@ var Chunk = class {
|
|
|
2093
2183
|
reorderedChunk.reorderId = null;
|
|
2094
2184
|
for (;;) {
|
|
2095
2185
|
cur.flushPlaceholder();
|
|
2186
|
+
cur.deferOwnReady();
|
|
2096
2187
|
const { next } = cur;
|
|
2188
|
+
const readyResumeScripts = cur.flushReadyScripts(readyReservations);
|
|
2097
2189
|
cur.consumed = true;
|
|
2098
2190
|
reorderHTML += cur.html;
|
|
2099
2191
|
reorderEffects = concatEffects(reorderEffects, cur.effects);
|
|
2100
|
-
reorderScripts = concatScripts(reorderScripts, cur.scripts);
|
|
2192
|
+
reorderScripts = concatScripts(reorderScripts, concatScripts(readyResumeScripts, cur.scripts));
|
|
2101
2193
|
if (cur.async) {
|
|
2102
2194
|
reorderHTML += state.mark("#", cur.reorderId = state.nextReorderId());
|
|
2103
2195
|
cur.html = cur.effects = cur.scripts = cur.lastEffect = "";
|
|
@@ -2113,6 +2205,7 @@ var Chunk = class {
|
|
|
2113
2205
|
}
|
|
2114
2206
|
reorderScripts = concatScripts(reorderScripts, "_.push(\"" + reorderEffects + "\")");
|
|
2115
2207
|
}
|
|
2208
|
+
for (const reservation of readyReservations) scripts = concatScripts(scripts, reservation);
|
|
2116
2209
|
scripts = concatScripts(scripts, reorderScripts && runtimePrefix + ".j" + toAccess(reorderId) + "=_=>{" + reorderScripts + "}");
|
|
2117
2210
|
html += "<t " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
|
|
2118
2211
|
}
|
|
@@ -2146,35 +2239,60 @@ var Chunk = class {
|
|
|
2146
2239
|
return html;
|
|
2147
2240
|
}
|
|
2148
2241
|
};
|
|
2149
|
-
function flushSerializer(boundary) {
|
|
2242
|
+
function flushSerializer(boundary, serializeState) {
|
|
2150
2243
|
const { state } = boundary;
|
|
2151
|
-
const {
|
|
2152
|
-
const
|
|
2153
|
-
if (
|
|
2154
|
-
|
|
2155
|
-
const
|
|
2156
|
-
|
|
2157
|
-
|
|
2244
|
+
const { serializer } = state;
|
|
2245
|
+
const pending = serializer.pending(serializeState);
|
|
2246
|
+
if (serializeState.flushScopes || pending) {
|
|
2247
|
+
const { writeScopes, passiveScopes } = serializeState;
|
|
2248
|
+
const isBlockingState = serializeState !== state;
|
|
2249
|
+
const flushes = [];
|
|
2250
|
+
let globals = 0;
|
|
2251
|
+
if (passiveScopes) for (const key in passiveScopes) {
|
|
2252
|
+
const props = writeScopes[key];
|
|
2253
|
+
if (props) {
|
|
2254
|
+
writeScopes[key] = Object.assign(passiveScopes[key], props);
|
|
2255
|
+
delete passiveScopes[key];
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
if (!isBlockingState && !state.hasGlobals) {
|
|
2158
2259
|
state.hasGlobals = true;
|
|
2159
|
-
|
|
2160
|
-
shouldSerialize = true;
|
|
2260
|
+
globals = getFilteredGlobals(state.$global);
|
|
2161
2261
|
}
|
|
2162
2262
|
for (const key in writeScopes) {
|
|
2163
|
-
const
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2263
|
+
const scopeId = +key;
|
|
2264
|
+
const props = writeScopes[scopeId];
|
|
2265
|
+
if (Object.getOwnPropertyNames(props).length) flushes.push([
|
|
2266
|
+
scopeId,
|
|
2267
|
+
state.scopes.get(scopeId),
|
|
2268
|
+
props
|
|
2269
|
+
]);
|
|
2270
|
+
}
|
|
2271
|
+
if (flushes.length || globals || pending) {
|
|
2272
|
+
if (isBlockingState && !state.hasGlobals) flushSerializerGlobals(boundary);
|
|
2273
|
+
serializeState.resumes = concatSequence(serializeState.resumes, serializer.stringifyScopes(flushes, globals, boundary, serializeState));
|
|
2172
2274
|
}
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
state.
|
|
2176
|
-
|
|
2275
|
+
serializeState.writeScopes = {};
|
|
2276
|
+
serializeState.flushScopes = false;
|
|
2277
|
+
if (pending) state.walkOnNextFlush = true;
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
function flushSerializerGlobals(boundary) {
|
|
2281
|
+
const { state } = boundary;
|
|
2282
|
+
const globals = getFilteredGlobals(state.$global);
|
|
2283
|
+
if (globals) {
|
|
2284
|
+
state.hasGlobals = true;
|
|
2285
|
+
state.needsMainRuntime = true;
|
|
2286
|
+
state.resumes = concatSequence(state.resumes, state.serializer.stringifyScopes([], globals, boundary));
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
function depsMarker(deps) {
|
|
2290
|
+
let marker = "";
|
|
2291
|
+
if (deps) {
|
|
2292
|
+
for (const dep of deps) marker += (marker ? "," : "[") + quote(dep, 0);
|
|
2293
|
+
marker += "]";
|
|
2177
2294
|
}
|
|
2295
|
+
return marker;
|
|
2178
2296
|
}
|
|
2179
2297
|
function _trailers(html) {
|
|
2180
2298
|
$chunk.boundary.state.trailerHTML += html;
|
|
@@ -2226,8 +2344,12 @@ function getFilteredGlobals($global) {
|
|
|
2226
2344
|
return filtered;
|
|
2227
2345
|
}
|
|
2228
2346
|
function _subscribe(subscribers, scope) {
|
|
2229
|
-
if (subscribers)
|
|
2230
|
-
|
|
2347
|
+
if (subscribers) {
|
|
2348
|
+
const { serializer } = $chunk.boundary.state;
|
|
2349
|
+
if (!$chunk.serializeState.readyId && !serializer.written(subscribers)) subscribers.add(scope);
|
|
2350
|
+
else serializer.writeCall(scope, subscribers, "add", $chunk.serializeState);
|
|
2351
|
+
}
|
|
2352
|
+
return scope;
|
|
2231
2353
|
}
|
|
2232
2354
|
//#endregion
|
|
2233
2355
|
//#region src/html/attrs.ts
|
|
@@ -2410,14 +2532,6 @@ function normalizeBoolAttrValue(value) {
|
|
|
2410
2532
|
if (value != null && value !== false) return true;
|
|
2411
2533
|
}
|
|
2412
2534
|
//#endregion
|
|
2413
|
-
//#region src/common/compat-meta.ts
|
|
2414
|
-
const RENDERER_REGISTER_ID = "$compat_renderer";
|
|
2415
|
-
const SET_SCOPE_REGISTER_ID = "$compat_setScope";
|
|
2416
|
-
const RENDER_BODY_ID = "$compat_renderBody";
|
|
2417
|
-
//#endregion
|
|
2418
|
-
//#region src/common/meta.ts
|
|
2419
|
-
const DYNAMIC_TAG_SCRIPT_REGISTER_ID = "_dynamicTagScript";
|
|
2420
|
-
//#endregion
|
|
2421
2535
|
//#region src/html/dynamic-tag.ts
|
|
2422
2536
|
const voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/;
|
|
2423
2537
|
let _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, serializeReason) => {
|
|
@@ -2449,7 +2563,7 @@ let _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, s
|
|
|
2449
2563
|
const childScope = getScopeById(branchId);
|
|
2450
2564
|
const needsScript = childScope && (childScope[`EventAttributes:#${renderer}/0`] || childScope[`ControlledHandler:#${renderer}/0`]);
|
|
2451
2565
|
if (needsScript) {
|
|
2452
|
-
|
|
2566
|
+
writeScope(branchId, { ["#Renderer"]: renderer });
|
|
2453
2567
|
_script(branchId, DYNAMIC_TAG_SCRIPT_REGISTER_ID);
|
|
2454
2568
|
}
|
|
2455
2569
|
if (shouldResume || needsScript) _html(state.mark("'", scopeId + " " + accessor + " " + branchId));
|
|
@@ -2491,115 +2605,6 @@ const patchDynamicTag = ((originalDynamicTag) => (patch) => {
|
|
|
2491
2605
|
};
|
|
2492
2606
|
})(_dynamic_tag);
|
|
2493
2607
|
//#endregion
|
|
2494
|
-
//#region src/html/compat.ts
|
|
2495
|
-
const K_TAGS_API_STATE = Symbol();
|
|
2496
|
-
const COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap();
|
|
2497
|
-
const compat = {
|
|
2498
|
-
$global,
|
|
2499
|
-
fork: _await,
|
|
2500
|
-
write: _html,
|
|
2501
|
-
writeScript,
|
|
2502
|
-
nextScopeId: _scope_id,
|
|
2503
|
-
peekNextScopeId: _peek_scope_id,
|
|
2504
|
-
isInResumedBranch,
|
|
2505
|
-
ensureState($global) {
|
|
2506
|
-
let state = $global[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
|
|
2507
|
-
if (!state) {
|
|
2508
|
-
$global.runtimeId ||= "M";
|
|
2509
|
-
$global.renderId ||= $global.componentIdPrefix || $global.widgetIdPrefix || "_";
|
|
2510
|
-
$global[K_TAGS_API_STATE] = state = new State($global);
|
|
2511
|
-
}
|
|
2512
|
-
return state;
|
|
2513
|
-
},
|
|
2514
|
-
isTagsAPI(fn) {
|
|
2515
|
-
return !!fn["id"];
|
|
2516
|
-
},
|
|
2517
|
-
onFlush(fn) {
|
|
2518
|
-
const { flushHTML } = Chunk.prototype;
|
|
2519
|
-
Chunk.prototype.flushHTML = function() {
|
|
2520
|
-
fn(this);
|
|
2521
|
-
return flushHTML.call(this);
|
|
2522
|
-
};
|
|
2523
|
-
},
|
|
2524
|
-
patchDynamicTag,
|
|
2525
|
-
writeSetScopeForComponent(branchId, m5c, m5i) {
|
|
2526
|
-
writeScope(branchId, {
|
|
2527
|
-
m5c,
|
|
2528
|
-
m5i
|
|
2529
|
-
});
|
|
2530
|
-
_script(branchId, SET_SCOPE_REGISTER_ID);
|
|
2531
|
-
},
|
|
2532
|
-
toJSON(state) {
|
|
2533
|
-
return function toJSON() {
|
|
2534
|
-
let compatRegistered = COMPAT_REGISTRY.get(this);
|
|
2535
|
-
if (!compatRegistered) {
|
|
2536
|
-
const registered = getRegistered(this);
|
|
2537
|
-
if (registered) {
|
|
2538
|
-
const scopeId = registered.scope ? getScopeId(registered.scope) : void 0;
|
|
2539
|
-
if (scopeId !== void 0) writeScopeToState(state, scopeId, {});
|
|
2540
|
-
COMPAT_REGISTRY.set(this, compatRegistered = [registered.id, scopeId]);
|
|
2541
|
-
}
|
|
2542
|
-
}
|
|
2543
|
-
return compatRegistered;
|
|
2544
|
-
};
|
|
2545
|
-
},
|
|
2546
|
-
flushScript($global) {
|
|
2547
|
-
const boundary = new Boundary(this.ensureState($global));
|
|
2548
|
-
if (boundary.flush() === 1) throw new Error("Cannot serialize promise across tags/class compat layer.");
|
|
2549
|
-
return new Chunk(boundary, null, null).flushScript().scripts;
|
|
2550
|
-
},
|
|
2551
|
-
render(renderer, willRerender, classAPIOut, component, input, completeChunks) {
|
|
2552
|
-
const boundary = new Boundary(this.ensureState(classAPIOut.global));
|
|
2553
|
-
let head = new Chunk(boundary, null, null);
|
|
2554
|
-
let normalizedInput = input;
|
|
2555
|
-
if ("renderBody" in input) {
|
|
2556
|
-
normalizedInput = {};
|
|
2557
|
-
for (const key in input) normalizedInput[key === "renderBody" ? "content" : key] = input[key];
|
|
2558
|
-
}
|
|
2559
|
-
head.render(() => {
|
|
2560
|
-
if (willRerender) {
|
|
2561
|
-
const scopeId = _peek_scope_id();
|
|
2562
|
-
writeScope(scopeId, { m5c: component.id });
|
|
2563
|
-
_script(scopeId, SET_SCOPE_REGISTER_ID);
|
|
2564
|
-
}
|
|
2565
|
-
_set_serialize_reason(willRerender ? 1 : 0);
|
|
2566
|
-
try {
|
|
2567
|
-
renderer(normalizedInput);
|
|
2568
|
-
} finally {
|
|
2569
|
-
_set_serialize_reason(void 0);
|
|
2570
|
-
}
|
|
2571
|
-
const asyncOut = classAPIOut.beginAsync({
|
|
2572
|
-
last: true,
|
|
2573
|
-
timeout: -1
|
|
2574
|
-
});
|
|
2575
|
-
classAPIOut.onLast((next) => {
|
|
2576
|
-
(boundary.onNext = () => {
|
|
2577
|
-
if (boundary.signal.aborted) {
|
|
2578
|
-
asyncOut.error(boundary.signal.reason);
|
|
2579
|
-
boundary.onNext = NOOP$1;
|
|
2580
|
-
} else if (!boundary.count) {
|
|
2581
|
-
boundary.onNext = NOOP$1;
|
|
2582
|
-
head = head.consume();
|
|
2583
|
-
asyncOut.write(head.html);
|
|
2584
|
-
asyncOut.script(head.scripts);
|
|
2585
|
-
asyncOut.end();
|
|
2586
|
-
head.html = head.scripts = "";
|
|
2587
|
-
completeChunks.push(head);
|
|
2588
|
-
next();
|
|
2589
|
-
}
|
|
2590
|
-
})();
|
|
2591
|
-
});
|
|
2592
|
-
});
|
|
2593
|
-
},
|
|
2594
|
-
registerRenderer(renderer, id) {
|
|
2595
|
-
return register(RENDERER_REGISTER_ID, renderer, register(id, () => {}));
|
|
2596
|
-
},
|
|
2597
|
-
registerRenderBody(fn) {
|
|
2598
|
-
register(RENDER_BODY_ID, fn);
|
|
2599
|
-
}
|
|
2600
|
-
};
|
|
2601
|
-
function NOOP$1() {}
|
|
2602
|
-
//#endregion
|
|
2603
2608
|
//#region src/html/template.ts
|
|
2604
2609
|
const _template = (templateId, renderer, page) => {
|
|
2605
2610
|
renderer.render = render;
|
|
@@ -2626,9 +2631,9 @@ function render(input = {}) {
|
|
|
2626
2631
|
renderId: getDefaultRenderId(this)
|
|
2627
2632
|
};
|
|
2628
2633
|
const state = new State($global);
|
|
2629
|
-
const head = new Chunk(new Boundary(state, $global.signal), null, null);
|
|
2630
|
-
if (this["embed"]) (
|
|
2631
|
-
head.render(this, input);
|
|
2634
|
+
const head = new Chunk(new Boundary(state, $global.signal), null, null, state);
|
|
2635
|
+
if (this["embed"]) head.render(() => writeWaitReady(this["id"], this, input));
|
|
2636
|
+
else head.render(this, input);
|
|
2632
2637
|
return new ServerRendered(head);
|
|
2633
2638
|
}
|
|
2634
2639
|
function getDefaultRenderId(template) {
|
|
@@ -2764,7 +2769,7 @@ var ServerRendered = class {
|
|
|
2764
2769
|
(boundary.onNext = () => {
|
|
2765
2770
|
switch (!boundary.count && boundary.flush()) {
|
|
2766
2771
|
case 2:
|
|
2767
|
-
boundary.onNext = NOOP;
|
|
2772
|
+
boundary.onNext = NOOP$1;
|
|
2768
2773
|
reject(boundary.signal.reason);
|
|
2769
2774
|
break;
|
|
2770
2775
|
case 0:
|
|
@@ -2787,7 +2792,7 @@ var ServerRendered = class {
|
|
|
2787
2792
|
const status = boundary.flush();
|
|
2788
2793
|
if (status === 2) {
|
|
2789
2794
|
if (!tick) offTick(onNext);
|
|
2790
|
-
boundary.onNext = NOOP;
|
|
2795
|
+
boundary.onNext = NOOP$1;
|
|
2791
2796
|
onAbort(boundary.signal.reason);
|
|
2792
2797
|
} else if (write || status === 0) {
|
|
2793
2798
|
const html = (head = head.consume()).flushHTML();
|
|
@@ -2816,6 +2821,208 @@ var ServerRendered = class {
|
|
|
2816
2821
|
return head.consume().flushHTML();
|
|
2817
2822
|
}
|
|
2818
2823
|
};
|
|
2824
|
+
function NOOP$1() {}
|
|
2825
|
+
//#endregion
|
|
2826
|
+
//#region src/html/assets.ts
|
|
2827
|
+
const kAssets = Symbol();
|
|
2828
|
+
const kBlockIndex = Symbol();
|
|
2829
|
+
const kDeferIndex = Symbol();
|
|
2830
|
+
const { hasOwnProperty } = {};
|
|
2831
|
+
let assetFlush;
|
|
2832
|
+
function withLoadAssets(renderer, assetId, triggers) {
|
|
2833
|
+
return Object.assign((input) => {
|
|
2834
|
+
const g = $global();
|
|
2835
|
+
addAsset(g, assetId, triggers);
|
|
2836
|
+
_html(flush(g, ""));
|
|
2837
|
+
return writeWaitReady(assetId, renderer, input);
|
|
2838
|
+
}, renderer);
|
|
2839
|
+
}
|
|
2840
|
+
function withPageAssets(template, runtime, assetId, runtimeId) {
|
|
2841
|
+
assetFlush = runtime;
|
|
2842
|
+
return Object.assign((input) => {
|
|
2843
|
+
const g = $global();
|
|
2844
|
+
if (runtimeId) {
|
|
2845
|
+
if (g.runtimeId !== "M" && g.runtimeId !== runtimeId) throw new Error(`$global.runtimeId ("${g.runtimeId}") conflicts with the runtimeId this entry was compiled with ("${runtimeId}").`);
|
|
2846
|
+
g.runtimeId = runtimeId;
|
|
2847
|
+
}
|
|
2848
|
+
addAsset(g, assetId);
|
|
2849
|
+
if (g.__flush__) {
|
|
2850
|
+
_html(flush(g, ""));
|
|
2851
|
+
return writeWaitReady(assetId, template, input);
|
|
2852
|
+
}
|
|
2853
|
+
g.__flush__ = flush;
|
|
2854
|
+
return template(input);
|
|
2855
|
+
}, template);
|
|
2856
|
+
}
|
|
2857
|
+
function _flush_head() {
|
|
2858
|
+
const g = $global();
|
|
2859
|
+
return g[kAssets] ? flush(g, "") : "";
|
|
2860
|
+
}
|
|
2861
|
+
function flush(g, html) {
|
|
2862
|
+
let result = "";
|
|
2863
|
+
const assets = g[kAssets];
|
|
2864
|
+
const { length } = assets;
|
|
2865
|
+
let bi = g[kBlockIndex];
|
|
2866
|
+
let di = g[kDeferIndex];
|
|
2867
|
+
for (; bi < length; bi++) result += assetFlush(g, "block", assets[bi].id);
|
|
2868
|
+
for (; di < length; di++) {
|
|
2869
|
+
const { id, triggers } = assets[di];
|
|
2870
|
+
const deferHTML = assetFlush(g, "defer", id);
|
|
2871
|
+
if (triggers) {
|
|
2872
|
+
if (deferHTML) writeTriggerScript(deferHTML, triggers);
|
|
2873
|
+
} else result += deferHTML;
|
|
2874
|
+
}
|
|
2875
|
+
g[kBlockIndex] = bi;
|
|
2876
|
+
g[kDeferIndex] = di;
|
|
2877
|
+
return result + html;
|
|
2878
|
+
}
|
|
2879
|
+
function addAsset(g, id, triggers) {
|
|
2880
|
+
const assets = g[kAssets];
|
|
2881
|
+
if (!assets) {
|
|
2882
|
+
g[kAssets] = [{
|
|
2883
|
+
id,
|
|
2884
|
+
triggers
|
|
2885
|
+
}];
|
|
2886
|
+
g[kBlockIndex] = g[kDeferIndex] = 0;
|
|
2887
|
+
} else if (!assets.find((a) => a.id === id)) assets.push({
|
|
2888
|
+
id,
|
|
2889
|
+
triggers
|
|
2890
|
+
});
|
|
2891
|
+
}
|
|
2892
|
+
function writeTriggerScript(html, triggers) {
|
|
2893
|
+
const htmlStr = _escape_script(JSON.stringify(html));
|
|
2894
|
+
const exprs = triggers.map((trigger) => {
|
|
2895
|
+
const options = trigger.options && toObjectExpression(trigger.options);
|
|
2896
|
+
switch (trigger.type) {
|
|
2897
|
+
case "visible": return `(e=>e&&new IntersectionObserver((e,i)=>e.some(e=>e.isIntersecting)&&i.disconnect()+l()${options ? `,${options}` : ""}).observe(e))(document.querySelector(${JSON.stringify(trigger.selector)})||l())`;
|
|
2898
|
+
case "idle": return `(self.requestIdleCallback||l)(l${options ? `,${options}` : ""})`;
|
|
2899
|
+
case "media": return `(m=>m.matches?l():m.addEventListener("change",l,{once:1}))(matchMedia(${JSON.stringify(trigger.selector)}))`;
|
|
2900
|
+
default: return `(e=>e?.addEventListener("${trigger.type.slice(3)}",l,{once:1}))(document.querySelector(${JSON.stringify(trigger.selector)})||l())`;
|
|
2901
|
+
}
|
|
2902
|
+
});
|
|
2903
|
+
writeScript(`((p,h,d,l=$=>d||p.insertAdjacentHTML("afterend",d=h))=>${exprs.length > 1 ? `{${exprs.join(";")}}` : exprs[0]})(document.currentScript,${htmlStr})`);
|
|
2904
|
+
}
|
|
2905
|
+
function toObjectExpression(options) {
|
|
2906
|
+
let result = "{";
|
|
2907
|
+
let sep = "";
|
|
2908
|
+
for (const key in options) if (hasOwnProperty.call(options, key)) {
|
|
2909
|
+
result += sep + toObjectKey(key) + ":" + JSON.stringify(options[key]);
|
|
2910
|
+
sep = ",";
|
|
2911
|
+
}
|
|
2912
|
+
return result + "}";
|
|
2913
|
+
}
|
|
2914
|
+
//#endregion
|
|
2915
|
+
//#region src/common/compat-meta.ts
|
|
2916
|
+
const SET_SCOPE_REGISTER_ID = "$compat_setScope";
|
|
2917
|
+
const RENDER_BODY_ID = "$compat_renderBody";
|
|
2918
|
+
//#endregion
|
|
2919
|
+
//#region src/html/compat.ts
|
|
2920
|
+
const K_TAGS_API_STATE = Symbol();
|
|
2921
|
+
const COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap();
|
|
2922
|
+
const compat = {
|
|
2923
|
+
$global,
|
|
2924
|
+
fork: _await,
|
|
2925
|
+
write: _html,
|
|
2926
|
+
writeScript,
|
|
2927
|
+
nextScopeId: _scope_id,
|
|
2928
|
+
peekNextScopeId: _peek_scope_id,
|
|
2929
|
+
isInResumedBranch,
|
|
2930
|
+
ensureState($global) {
|
|
2931
|
+
let state = $global[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
|
|
2932
|
+
if (!state) {
|
|
2933
|
+
$global.runtimeId ||= "M";
|
|
2934
|
+
$global.renderId ||= $global.componentIdPrefix || $global.widgetIdPrefix || "_";
|
|
2935
|
+
$global[K_TAGS_API_STATE] = state = new State($global);
|
|
2936
|
+
}
|
|
2937
|
+
return state;
|
|
2938
|
+
},
|
|
2939
|
+
isTagsAPI(fn) {
|
|
2940
|
+
return !!fn["id"];
|
|
2941
|
+
},
|
|
2942
|
+
onFlush(fn) {
|
|
2943
|
+
const { flushHTML } = Chunk.prototype;
|
|
2944
|
+
Chunk.prototype.flushHTML = function() {
|
|
2945
|
+
fn(this);
|
|
2946
|
+
return flushHTML.call(this);
|
|
2947
|
+
};
|
|
2948
|
+
},
|
|
2949
|
+
patchDynamicTag,
|
|
2950
|
+
writeSetScopeForComponent(branchId, m5c, m5i) {
|
|
2951
|
+
writeScope(branchId, {
|
|
2952
|
+
m5c,
|
|
2953
|
+
m5i
|
|
2954
|
+
});
|
|
2955
|
+
_script(branchId, SET_SCOPE_REGISTER_ID);
|
|
2956
|
+
},
|
|
2957
|
+
toJSON() {
|
|
2958
|
+
return function toJSON() {
|
|
2959
|
+
let compatRegistered = COMPAT_REGISTRY.get(this);
|
|
2960
|
+
if (!compatRegistered) {
|
|
2961
|
+
const registered = getRegistered(this);
|
|
2962
|
+
if (registered) {
|
|
2963
|
+
const scopeId = registered.scope ? getScopeId(registered.scope) : void 0;
|
|
2964
|
+
if (scopeId !== void 0) _script(scopeId, SET_SCOPE_REGISTER_ID);
|
|
2965
|
+
COMPAT_REGISTRY.set(this, compatRegistered = [registered.id, scopeId]);
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
return compatRegistered;
|
|
2969
|
+
};
|
|
2970
|
+
},
|
|
2971
|
+
flushScript($global) {
|
|
2972
|
+
const state = this.ensureState($global);
|
|
2973
|
+
const boundary = new Boundary(state);
|
|
2974
|
+
if (boundary.flush() === 1) throw new Error("Cannot serialize promise across tags/class compat layer.");
|
|
2975
|
+
return new Chunk(boundary, null, null, state).flushScript().scripts;
|
|
2976
|
+
},
|
|
2977
|
+
render(renderer, willRerender, classAPIOut, component, input, completeChunks) {
|
|
2978
|
+
const state = this.ensureState(classAPIOut.global);
|
|
2979
|
+
const boundary = new Boundary(state);
|
|
2980
|
+
let head = new Chunk(boundary, null, null, state);
|
|
2981
|
+
let normalizedInput = input;
|
|
2982
|
+
if ("renderBody" in input) {
|
|
2983
|
+
normalizedInput = {};
|
|
2984
|
+
for (const key in input) normalizedInput[key === "renderBody" ? "content" : key] = input[key];
|
|
2985
|
+
}
|
|
2986
|
+
head.render(() => {
|
|
2987
|
+
if (willRerender) {
|
|
2988
|
+
const scopeId = _peek_scope_id();
|
|
2989
|
+
writeScope(scopeId, { m5c: component.id });
|
|
2990
|
+
_script(scopeId, SET_SCOPE_REGISTER_ID);
|
|
2991
|
+
}
|
|
2992
|
+
_set_serialize_reason(willRerender ? 1 : 0);
|
|
2993
|
+
try {
|
|
2994
|
+
renderer(normalizedInput);
|
|
2995
|
+
} finally {
|
|
2996
|
+
_set_serialize_reason(void 0);
|
|
2997
|
+
}
|
|
2998
|
+
const asyncOut = classAPIOut.beginAsync({
|
|
2999
|
+
last: true,
|
|
3000
|
+
timeout: -1
|
|
3001
|
+
});
|
|
3002
|
+
classAPIOut.onLast((next) => {
|
|
3003
|
+
(boundary.onNext = () => {
|
|
3004
|
+
if (boundary.signal.aborted) {
|
|
3005
|
+
asyncOut.error(boundary.signal.reason);
|
|
3006
|
+
boundary.onNext = NOOP;
|
|
3007
|
+
} else if (!boundary.count) {
|
|
3008
|
+
boundary.onNext = NOOP;
|
|
3009
|
+
head = head.consume();
|
|
3010
|
+
asyncOut.write(head.html);
|
|
3011
|
+
asyncOut.script(head.scripts);
|
|
3012
|
+
asyncOut.end();
|
|
3013
|
+
head.html = head.scripts = "";
|
|
3014
|
+
completeChunks.push(head);
|
|
3015
|
+
next();
|
|
3016
|
+
}
|
|
3017
|
+
})();
|
|
3018
|
+
});
|
|
3019
|
+
});
|
|
3020
|
+
},
|
|
3021
|
+
register,
|
|
3022
|
+
registerRenderBody(fn) {
|
|
3023
|
+
register(RENDER_BODY_ID, fn);
|
|
3024
|
+
}
|
|
3025
|
+
};
|
|
2819
3026
|
function NOOP() {}
|
|
2820
3027
|
//#endregion
|
|
2821
3028
|
exports.$global = $global;
|
|
@@ -2854,6 +3061,7 @@ exports._escape_comment = _escape_comment;
|
|
|
2854
3061
|
exports._escape_script = _escape_script;
|
|
2855
3062
|
exports._escape_style = _escape_style;
|
|
2856
3063
|
exports._existing_scope = _existing_scope;
|
|
3064
|
+
exports._flush_head = _flush_head;
|
|
2857
3065
|
exports._for_in = _for_in;
|
|
2858
3066
|
exports._for_of = _for_of;
|
|
2859
3067
|
exports._for_to = _for_to;
|
|
@@ -2896,3 +3104,5 @@ exports.forOfBy = forOfBy;
|
|
|
2896
3104
|
exports.forStepBy = forStepBy;
|
|
2897
3105
|
exports.forTo = forTo;
|
|
2898
3106
|
exports.forUntil = forUntil;
|
|
3107
|
+
exports.withLoadAssets = withLoadAssets;
|
|
3108
|
+
exports.withPageAssets = withPageAssets;
|