marko 6.4.10 → 6.4.12
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 +0 -3
- package/dist/common/accessor.debug.d.ts +0 -3
- package/dist/common/attr-tag.d.ts +1 -0
- package/dist/common/errors.d.ts +2 -0
- package/dist/common/helpers.d.ts +3 -1
- package/dist/common/types.d.ts +4 -3
- package/dist/debug/dom/catch.feat.js +1 -1
- package/dist/debug/dom/catch.feat.mjs +1 -1
- package/dist/debug/dom/compat.feat.js +143 -0
- package/dist/debug/dom/compat.feat.mjs +141 -0
- package/dist/debug/dom/controllable-input.feat.js +1 -1
- package/dist/debug/dom/controllable-input.feat.mjs +1 -1
- package/dist/debug/dom/controllable-open.feat.js +1 -1
- package/dist/debug/dom/controllable-open.feat.mjs +1 -1
- package/dist/debug/dom/controllable-select.feat.js +1 -1
- package/dist/debug/dom/controllable-select.feat.mjs +1 -1
- package/dist/debug/dom/controllable-textarea.feat.js +1 -1
- package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
- package/dist/debug/dom/controllable.feat.js +1 -1
- package/dist/debug/dom/controllable.feat.mjs +1 -1
- package/dist/debug/dom/dynamic-tag-script.feat.js +1 -1
- package/dist/debug/dom/dynamic-tag-script.feat.mjs +1 -1
- package/dist/debug/dom/dynamic-tag-var.feat.js +1 -1
- package/dist/debug/dom/dynamic-tag-var.feat.mjs +1 -1
- package/dist/debug/dom/lazy.feat.js +1 -1
- package/dist/debug/dom/lazy.feat.mjs +1 -1
- package/dist/debug/dom/placeholder.feat.js +1 -1
- package/dist/debug/dom/placeholder.feat.mjs +1 -1
- package/dist/debug/{dom-DNB5yq3U.js → dom-CtXOr4Nm.js} +257 -230
- package/dist/debug/{dom-C1V5vpFs.mjs → dom-DaHYZpf2.mjs} +238 -229
- package/dist/debug/dom.js +8 -134
- package/dist/debug/dom.mjs +5 -126
- package/dist/debug/html/compat.feat.js +222 -0
- package/dist/debug/html/compat.feat.mjs +220 -0
- package/dist/debug/html-DMo6pc_h.mjs +3931 -0
- package/dist/debug/html-DfZjMkhx.js +4513 -0
- package/dist/debug/html.js +83 -4239
- package/dist/debug/html.mjs +1 -4152
- package/dist/dom/abort-signal.d.ts +1 -1
- package/dist/dom/catch.feat.js +3 -3
- package/dist/dom/catch.feat.mjs +1 -1
- package/dist/dom/{compat.d.ts → compat.feat.d.ts} +18 -9
- package/dist/dom/compat.feat.js +101 -0
- package/dist/dom/compat.feat.mjs +100 -0
- package/dist/dom/control-flow.d.ts +4 -5
- package/dist/dom/controllable-input.feat.js +2 -2
- package/dist/dom/controllable-input.feat.mjs +1 -1
- package/dist/dom/controllable-open.feat.js +2 -2
- package/dist/dom/controllable-open.feat.mjs +1 -1
- package/dist/dom/controllable-select.feat.js +2 -2
- package/dist/dom/controllable-select.feat.mjs +1 -1
- package/dist/dom/controllable-textarea.feat.js +2 -2
- package/dist/dom/controllable-textarea.feat.mjs +1 -1
- package/dist/dom/controllable.feat.js +2 -2
- package/dist/dom/controllable.feat.mjs +1 -1
- package/dist/dom/dom.d.ts +2 -1
- package/dist/dom/dynamic-tag-script.feat.js +2 -2
- package/dist/dom/dynamic-tag-script.feat.mjs +1 -1
- package/dist/dom/dynamic-tag-var.feat.js +1 -1
- package/dist/dom/dynamic-tag-var.feat.mjs +1 -1
- package/dist/dom/lazy.feat.js +1 -1
- package/dist/dom/lazy.feat.mjs +1 -1
- package/dist/dom/load.d.ts +3 -4
- package/dist/dom/placeholder.feat.js +3 -3
- package/dist/dom/placeholder.feat.mjs +1 -1
- package/dist/dom/queue.d.ts +1 -2
- package/dist/dom/resume.d.ts +3 -1
- package/dist/dom/signals.d.ts +5 -7
- package/dist/{dom-C2-Flitp.js → dom-BB-Te-3z.js} +222 -239
- package/dist/{dom-DsHYWMCR.mjs → dom-BO-0hzLZ.mjs} +124 -146
- package/dist/dom.d.ts +1 -2
- package/dist/dom.js +17 -95
- package/dist/dom.mjs +6 -79
- package/dist/html/assets.d.ts +3 -4
- package/dist/html/{compat.d.ts → compat.feat.d.ts} +5 -4
- package/dist/html/compat.feat.js +165 -0
- package/dist/html/compat.feat.mjs +164 -0
- package/dist/html/dynamic-tag.d.ts +1 -2
- package/dist/html/for.d.ts +0 -1
- package/dist/html/writer.d.ts +4 -3
- package/dist/html-DMDc0zKs.mjs +2404 -0
- package/dist/html-DrHsybFm.js +2880 -0
- package/dist/html.d.ts +1 -2
- package/dist/html.js +2 -2578
- package/dist/html.mjs +3 -2573
- package/dist/translator/index.d.ts +0 -1
- package/dist/translator/index.js +4889 -4733
- package/dist/translator/interop/out-global.d.ts +5 -0
- package/dist/translator/util/assert.d.ts +6 -0
- package/dist/translator/util/branch-tag.d.ts +1 -1
- package/dist/translator/util/entry-builder.d.ts +1 -1
- package/dist/translator/util/finalize-references.d.ts +2 -1
- package/dist/translator/util/for-selector.d.ts +1 -1
- package/dist/translator/util/known-tag.d.ts +10 -1
- package/dist/translator/util/optional.d.ts +0 -1
- package/dist/translator/util/reasons.d.ts +0 -1
- package/dist/translator/util/references.d.ts +12 -5
- package/dist/translator/util/runtime.d.ts +1 -0
- package/dist/translator/util/sections.d.ts +11 -2
- package/dist/translator/util/signals.d.ts +2 -1
- package/dist/translator/util/style-interpolation.d.ts +1 -1
- package/dist/translator/util/tag-facts.d.ts +2 -0
- package/dist/translator/util/tag-name-type.d.ts +1 -0
- package/dist/translator/util/translate-attrs.d.ts +1 -4
- package/dist/translator/util/visitors.d.ts +1 -1
- package/dist/translator/util/write-guard.d.ts +2 -0
- package/dist/translator/visitors/program/index.d.ts +2 -6
- package/dist/translator/visitors/referenced-identifier.d.ts +3 -1
- package/index.d.ts +2 -7
- package/package.json +4 -4
- package/dist/common/constants/keyed-scopes-prop.d.ts +0 -4
- package/dist/common/constants/keyed-scopes-prop.debug.d.ts +0 -4
|
@@ -0,0 +1,3931 @@
|
|
|
1
|
+
// src/common/attr-tag.ts
|
|
2
|
+
const empty = [];
|
|
3
|
+
const rest = Symbol("Attribute Tag");
|
|
4
|
+
function attrTag(attrs) {
|
|
5
|
+
attrs[Symbol.iterator] = attrTagIterator;
|
|
6
|
+
attrs[rest] = empty;
|
|
7
|
+
return attrs;
|
|
8
|
+
}
|
|
9
|
+
function attrTags(first, attrs) {
|
|
10
|
+
if (first) {
|
|
11
|
+
if (first[rest] === empty) first[rest] = [attrs];
|
|
12
|
+
else first[rest].push(attrs);
|
|
13
|
+
return first;
|
|
14
|
+
}
|
|
15
|
+
return attrTag(attrs);
|
|
16
|
+
}
|
|
17
|
+
function isAttrTag(value) {
|
|
18
|
+
return !!value?.[rest];
|
|
19
|
+
}
|
|
20
|
+
function* attrTagIterator() {
|
|
21
|
+
yield this;
|
|
22
|
+
yield* this[rest];
|
|
23
|
+
}
|
|
24
|
+
// src/common/constants/accessor-prefix.debug.ts
|
|
25
|
+
const BranchScopes = "BranchScopes:";
|
|
26
|
+
const ConditionalRenderer = "ConditionalRenderer:";
|
|
27
|
+
const ControlledHandler = "ControlledHandler:";
|
|
28
|
+
const ControlledType = "ControlledType:";
|
|
29
|
+
const ControlledValue = "ControlledValue:";
|
|
30
|
+
const EventAttributes = "EventAttributes:";
|
|
31
|
+
const CatchContent = "#CatchContent";
|
|
32
|
+
const ClosestBranchId = "#ClosestBranchId";
|
|
33
|
+
const LoopKey = "#LoopKey";
|
|
34
|
+
const PlaceholderBranch = "#PlaceholderBranch";
|
|
35
|
+
const PlaceholderContent = "#PlaceholderContent";
|
|
36
|
+
const Renderer = "#Renderer";
|
|
37
|
+
const TagVariable = "#TagVariable";
|
|
38
|
+
const Owner = "owner";
|
|
39
|
+
const Embed = "embed";
|
|
40
|
+
const Lazy = "lazy";
|
|
41
|
+
// src/common/helpers.ts
|
|
42
|
+
const invalidNativeAttrNameReg = /^[^a-z_]|[^a-z0-9._:-]/i;
|
|
43
|
+
const knownWrongAttrs = {
|
|
44
|
+
className: "class",
|
|
45
|
+
classList: "class",
|
|
46
|
+
htmlFor: "for",
|
|
47
|
+
acceptCharset: "accept-charset",
|
|
48
|
+
httpEquiv: "http-equiv",
|
|
49
|
+
defaultValue: "value",
|
|
50
|
+
defaultChecked: "checked",
|
|
51
|
+
dangerouslySetInnerHTML: "$!{html}",
|
|
52
|
+
key: "<for by>",
|
|
53
|
+
ref: "<tag/ref>",
|
|
54
|
+
"v-if": "<if>",
|
|
55
|
+
"v-else": "<else>",
|
|
56
|
+
"v-else-if": "<else if>",
|
|
57
|
+
"v-for": "<for>",
|
|
58
|
+
"v-show": "<if>",
|
|
59
|
+
"v-model": "value:=state",
|
|
60
|
+
"v-bind": "...attrs",
|
|
61
|
+
"v-html": "$!{html}",
|
|
62
|
+
"v-text": "${text}"
|
|
63
|
+
};
|
|
64
|
+
function getWrongAttrSuggestion(name) {
|
|
65
|
+
if (Object.hasOwn(knownWrongAttrs, name)) return knownWrongAttrs[name];
|
|
66
|
+
const colon = name.indexOf(":");
|
|
67
|
+
if (colon > 0) {
|
|
68
|
+
const rest = name.slice(colon + 1);
|
|
69
|
+
switch (name.slice(0, colon)) {
|
|
70
|
+
case "class": return `class={ ${rest}: condition }`;
|
|
71
|
+
case "style": return `style={ ${rest}: value }`;
|
|
72
|
+
case "on":
|
|
73
|
+
case "v-on": return `on${rest.charAt(0).toUpperCase()}${rest.slice(1)}`;
|
|
74
|
+
case "bind":
|
|
75
|
+
case "v-model": return `${rest}:=state`;
|
|
76
|
+
case "v-bind": return rest;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function stringifyClassEntry(name, value) {
|
|
81
|
+
return value ? name : "";
|
|
82
|
+
}
|
|
83
|
+
const warnedStyleKeys = /* @__PURE__ */ new Set();
|
|
84
|
+
function stringifyStyleEntry(name, value) {
|
|
85
|
+
if (/[A-Z]/.test(name) && !name.includes("-") && !warnedStyleKeys.has(name)) {
|
|
86
|
+
warnedStyleKeys.add(name);
|
|
87
|
+
console.warn(`\`${name}\` is not a CSS property name; \`style\` object keys are written verbatim, so it renders as invalid CSS. Use \`${name.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase()).replace(/^ms-/, "-ms-")}\`.`);
|
|
88
|
+
}
|
|
89
|
+
if (value !== value || typeof value === "bigint" && !value) console.warn(`The \`${name}\` style value \`${value !== value ? "NaN" : "0n"}\` drops the declaration; convert it to a string or number to render it.`);
|
|
90
|
+
return value || value === 0 ? escapeStyleAttr(name) + ":" + escapeStyleAttr(value + "") : "";
|
|
91
|
+
}
|
|
92
|
+
const unsafeStyleAttrReg = /[\\;]/g;
|
|
93
|
+
const replaceUnsafeStyleAttr = (c) => c === ";" ? "\\3B " : "\\\\";
|
|
94
|
+
function escapeStyleAttr(str) {
|
|
95
|
+
return unsafeStyleAttrReg.test(str) ? str.replace(unsafeStyleAttrReg, replaceUnsafeStyleAttr) : str;
|
|
96
|
+
}
|
|
97
|
+
function escapeStyleValue(str) {
|
|
98
|
+
let closers = "";
|
|
99
|
+
const result = str.replace(/[\\"'{};<>]|\/(?=\*)/g, (c) => c === "<" ? "\\3C " : c === ";" ? "\\3B " : c === "{" ? "\\7B " : "\\" + c);
|
|
100
|
+
for (const c of result) if (c === "(") closers = ")" + closers;
|
|
101
|
+
else if (c === "[") closers = "]" + closers;
|
|
102
|
+
else if (c === closers[0]) closers = closers.slice(1);
|
|
103
|
+
return result + closers;
|
|
104
|
+
}
|
|
105
|
+
function toDelimitedString(val, delimiter, stringify) {
|
|
106
|
+
let str = "";
|
|
107
|
+
let sep = "";
|
|
108
|
+
let part;
|
|
109
|
+
if (val) {
|
|
110
|
+
if (typeof val !== "object") str += val;
|
|
111
|
+
else if (Array.isArray(val)) for (const v of val) {
|
|
112
|
+
part = toDelimitedString(v, delimiter, stringify);
|
|
113
|
+
if (part) {
|
|
114
|
+
str += sep + part;
|
|
115
|
+
sep = delimiter;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else for (const name in val) {
|
|
119
|
+
part = stringify(name, val[name]);
|
|
120
|
+
if (part) {
|
|
121
|
+
str += sep + part;
|
|
122
|
+
sep = delimiter;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return str;
|
|
127
|
+
}
|
|
128
|
+
function isEventHandler(name) {
|
|
129
|
+
return /^on[A-Z-]/.test(name);
|
|
130
|
+
}
|
|
131
|
+
function getEventType(name) {
|
|
132
|
+
return name[2] === "-" ? name.slice(3) : name.slice(2).toLowerCase();
|
|
133
|
+
}
|
|
134
|
+
function hasKeys(obj) {
|
|
135
|
+
for (const _ in obj) return true;
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
function isNullishOrFalse(value) {
|
|
139
|
+
return value == null || value === false;
|
|
140
|
+
}
|
|
141
|
+
function isNotNullishOrFalse(value) {
|
|
142
|
+
return value != null && value !== false;
|
|
143
|
+
}
|
|
144
|
+
function isPromise(value) {
|
|
145
|
+
return value != null && typeof value.then === "function";
|
|
146
|
+
}
|
|
147
|
+
let classAPIRenderer;
|
|
148
|
+
function setClassAPIRenderer(render) {
|
|
149
|
+
classAPIRenderer = render;
|
|
150
|
+
}
|
|
151
|
+
function normalizeDynamicRenderer(value) {
|
|
152
|
+
if (value) {
|
|
153
|
+
if (typeof value === "string") return value;
|
|
154
|
+
const normalized = value.content || value.default || value;
|
|
155
|
+
if (typeof normalized !== "object" && typeof normalized !== "function") throw new Error(`A dynamic tag must be a string tag name (like \`"div"\`) or a Marko template/component, but received ${normalized === value ? `a ${typeof value}` : `an object whose \`content\` or \`default\` is a ${typeof normalized}`}.`);
|
|
156
|
+
if (classAPIRenderer) {
|
|
157
|
+
const renderer = classAPIRenderer(normalized);
|
|
158
|
+
if (renderer || false) return renderer;
|
|
159
|
+
} else if ("id" in normalized) return normalized;
|
|
160
|
+
if (value.content) throw new Error(`A dynamic tag must be a string tag name (like \`"div"\`) or a Marko template/component, but received an object whose \`content\` is not a template/component.`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// src/common/errors.ts
|
|
164
|
+
const lowercaseOnAttrReg = /^on[a-z]/;
|
|
165
|
+
function assertValidAttrValue(name, value) {
|
|
166
|
+
if (value && typeof value !== "string" && lowercaseOnAttrReg.test(name)) throw new Error(`The \`${name}\` attribute must be a string or a falsey value (\`null\`, \`undefined\`, \`false\`, \`0\`, …), but received type "${typeof value}". To attach an event listener, use the \`on${name[2].toUpperCase()}${name.slice(3)}\` event handler instead.`);
|
|
167
|
+
if (typeof value === "function") throw new Error(`The \`${name}\` attribute cannot be a function.${/Change$/.test(name) ? " A change handler is only used when its matching controllable attribute combination applies." : ""}`);
|
|
168
|
+
const unrenderable = describeUnrenderable(value);
|
|
169
|
+
if (unrenderable) throw new Error(`The \`${name}\` attribute cannot be ${unrenderable}.`);
|
|
170
|
+
}
|
|
171
|
+
function _assert_class_toggles(classes, toggles) {
|
|
172
|
+
{
|
|
173
|
+
const written = new Set(classes.split(" "));
|
|
174
|
+
for (const toggle of toggles) {
|
|
175
|
+
const names = new Set(toggle.split(" "));
|
|
176
|
+
for (const name of names) if (written.has(name)) throw new Error(`The toggled class \`${name}\` is also written by another part of the \`class\` value; a toggled class may appear only once.`);
|
|
177
|
+
for (const name of names) written.add(name);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function assertValidTextValue(value) {
|
|
182
|
+
const unrenderable = describeUnrenderable(value);
|
|
183
|
+
if (unrenderable) throw new Error(`Text content cannot be ${unrenderable}.`);
|
|
184
|
+
if (isSilentlyDropped(value)) console.warn(`Text content of \`${describeDropped(value)}\` renders as nothing; convert it to a string or number to render it.`);
|
|
185
|
+
}
|
|
186
|
+
function isSilentlyDropped(value) {
|
|
187
|
+
return value !== value || typeof value === "bigint" && !value;
|
|
188
|
+
}
|
|
189
|
+
function describeDropped(value) {
|
|
190
|
+
return value !== value ? "NaN" : "0n";
|
|
191
|
+
}
|
|
192
|
+
function describeUnrenderable(value) {
|
|
193
|
+
if (typeof value === "symbol") return "a symbol";
|
|
194
|
+
if (typeof value === "object" && value !== null) {
|
|
195
|
+
let stringified;
|
|
196
|
+
try {
|
|
197
|
+
stringified = `${value}`;
|
|
198
|
+
} catch {
|
|
199
|
+
stringified = "[object Object]";
|
|
200
|
+
}
|
|
201
|
+
if (/^\[object \w+\]$/.test(stringified)) return stringified === "[object Promise]" ? "a promise (use the `<await>` tag to render its resolved value)" : stringified === "[object Object]" ? "a plain object (it would render as `[object Object]`)" : `a value that renders as \`${stringified}\``;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function assertValidLoopKey(key, seenKeys) {
|
|
205
|
+
if (typeof key !== "string" && typeof key !== "number" || key !== key) throw new Error(`A \`<for>\` tag's \`by\` attribute must return a string or number for each item, but received ${key === null || key !== key ? key : `type "${typeof key}"`}.`);
|
|
206
|
+
if (seenKeys) {
|
|
207
|
+
if (seenKeys.has(key)) throw new Error(`A \`<for>\` tag's \`by\` attribute must return a unique value for each item, but \`${key}\` was used more than once.`);
|
|
208
|
+
seenKeys.add(key);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function assertValidList(value) {
|
|
212
|
+
if (value && typeof value[Symbol.iterator] !== "function") throw new Error(`A \`<for>\` tag's \`of\` attribute must be an iterable, such as an array, but received ${describeForValue(value)}.`);
|
|
213
|
+
}
|
|
214
|
+
function assertOptionalRangeNumber(name, value) {
|
|
215
|
+
if (value && (typeof value !== "number" || !isFinite(value))) throw new Error(`A \`<for>\` tag's \`${name}\` attribute must be a finite number, but received ${describeForValue(value)}.`);
|
|
216
|
+
}
|
|
217
|
+
function assertValidRangeBound(name, value) {
|
|
218
|
+
if (!isFinite(value)) throw new Error(`A \`<for>\` tag's \`${name}\` attribute must be a finite number, but received ${describeForValue(value)}.`);
|
|
219
|
+
}
|
|
220
|
+
function describeForValue(value) {
|
|
221
|
+
return typeof value === "number" || typeof value === "bigint" ? `\`${value}\`` : value === null ? "null" : `type "${typeof value}"`;
|
|
222
|
+
}
|
|
223
|
+
function assertValidAttrName(name) {
|
|
224
|
+
if (invalidNativeAttrNameReg.test(name)) throw new Error(`Invalid attribute name: ${JSON.stringify(name)}`);
|
|
225
|
+
const suggestion = getWrongAttrSuggestion(name);
|
|
226
|
+
if (suggestion) throw new Error(`\`${name}\` is not a valid attribute, did you mean \`${suggestion}\`?`);
|
|
227
|
+
}
|
|
228
|
+
function _el_read_error() {
|
|
229
|
+
throw new Error("Element references can only be read in scripts and event handlers.");
|
|
230
|
+
}
|
|
231
|
+
function _hoist_read_error() {
|
|
232
|
+
throw new Error("Hoisted values can only be read in scripts and event handlers.");
|
|
233
|
+
}
|
|
234
|
+
function _signal_read_error() {
|
|
235
|
+
throw new Error("Cannot use $signal in a server render.");
|
|
236
|
+
}
|
|
237
|
+
function _assert_hoist(value) {
|
|
238
|
+
if (value !== void 0 && typeof value !== "function") throw new Error(`Hoisted values must be functions, received type "${typeof value}".`);
|
|
239
|
+
}
|
|
240
|
+
function assertExclusiveAttrs(attrs, onError = throwErr, isSet = isTruthy) {
|
|
241
|
+
if (attrs) {
|
|
242
|
+
let exclusiveAttrs;
|
|
243
|
+
if (isSet(attrs.checkedChange)) (exclusiveAttrs ||= []).push("checkedChange");
|
|
244
|
+
if ("checkedValue" in attrs) {
|
|
245
|
+
(exclusiveAttrs ||= []).push("checkedValue");
|
|
246
|
+
if ("checked" in attrs) exclusiveAttrs.push("checked");
|
|
247
|
+
} else if (isSet(attrs.checkedValueChange)) {
|
|
248
|
+
(exclusiveAttrs ||= []).push("checkedValueChange");
|
|
249
|
+
if ("checked" in attrs) exclusiveAttrs.push("checked");
|
|
250
|
+
}
|
|
251
|
+
if (isSet(attrs.valueChange)) {
|
|
252
|
+
(exclusiveAttrs ||= []).push("valueChange");
|
|
253
|
+
if ("checked" in attrs && !exclusiveAttrs.includes("checked")) exclusiveAttrs.push("checked");
|
|
254
|
+
}
|
|
255
|
+
if (exclusiveAttrs && exclusiveAttrs.length > 1) onError(`The attributes ${joinWithAnd(exclusiveAttrs)} are mutually exclusive.`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function assertNoValueBindingOnCheckable(type, valueChange) {
|
|
259
|
+
if (valueChange && /^(?:button|checkbox|hidden|image|radio|reset|submit)$/i.test(type)) console.error(`\`valueChange\` cannot be used on a \`type="${type}"\` \`<input>\` — user interaction can never change its \`value\`.` + (/^[cr]/i.test(type) ? " Bind `checked` or `checkedValue` instead." : ""));
|
|
260
|
+
}
|
|
261
|
+
function assertHandlerIsFunction(name, value) {
|
|
262
|
+
if (value && typeof value !== "function") throw new Error(`The \`${name}\` handler must be a function or a falsey value (\`null\`, \`undefined\`, \`false\`, \`0\`, …), but received type "${typeof value}".`);
|
|
263
|
+
}
|
|
264
|
+
function assertNoNativeAttrTags(tagName, input) {
|
|
265
|
+
for (const name in input) if (name !== "content" && isAttrTag(input[name])) throw new Error(`A dynamic tag passed the native \`<${tagName}>\` tag an [attribute tag](https://markojs.com/docs/reference/language#attribute-tags) as \`${name}\`, but [native tags](https://markojs.com/docs/reference/native-tag) do not support attribute tags.`);
|
|
266
|
+
}
|
|
267
|
+
function assertValidContent(value, renderer) {
|
|
268
|
+
if (value && !renderer?.["id"]) throw new Error(`The \`content\` attribute on a [native tag](https://markojs.com/docs/reference/native-tag#content) must be body content, a \`<define>\` tag variable or attribute tag holding it, or a falsey value (\`null\`, \`undefined\`, \`false\`, \`0\`, …), but received type "${typeof value}".`);
|
|
269
|
+
}
|
|
270
|
+
function assertValidTagName(tagName) {
|
|
271
|
+
if (!/^[a-z][a-z0-9._-]*$/i.test(tagName)) throw new Error(`Invalid tag name: "${tagName}". Tag names must start with a letter and contain only letters, numbers, periods, hyphens, and underscores.`);
|
|
272
|
+
}
|
|
273
|
+
function isTruthy(value) {
|
|
274
|
+
return value;
|
|
275
|
+
}
|
|
276
|
+
function throwErr(msg) {
|
|
277
|
+
throw new Error(msg);
|
|
278
|
+
}
|
|
279
|
+
function joinWithAnd(a) {
|
|
280
|
+
switch (a.length) {
|
|
281
|
+
case 0: return "";
|
|
282
|
+
case 1: return a[0];
|
|
283
|
+
case 2: return `${a[0]} and ${a[1]}`;
|
|
284
|
+
default: return `${a.slice(0, -1).join(", ")}, and ${a[a.length - 1]}`;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
// src/common/meta.ts
|
|
288
|
+
const DYNAMIC_TAG_SCRIPT_REGISTER_ID = "_dynamicTagScript";
|
|
289
|
+
const DYNAMIC_TAG_VAR_REGISTER_ID = "_dynamicTagVar";
|
|
290
|
+
const PLACEHOLDER_DISMISS_REGISTER_ID = "_placeholderDismiss";
|
|
291
|
+
// src/common/opt.ts
|
|
292
|
+
function toArray(opt) {
|
|
293
|
+
return opt ? Array.isArray(opt) ? opt : [opt] : [];
|
|
294
|
+
}
|
|
295
|
+
function reduce(opt, cb, acc) {
|
|
296
|
+
if (opt) {
|
|
297
|
+
if (Array.isArray(opt)) for (const item of opt) acc = cb(acc, item);
|
|
298
|
+
else acc = cb(acc, opt);
|
|
299
|
+
}
|
|
300
|
+
return acc;
|
|
301
|
+
}
|
|
302
|
+
function push(opt, item) {
|
|
303
|
+
return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
|
|
304
|
+
}
|
|
305
|
+
function concat(opt, other) {
|
|
306
|
+
if (!opt) return other;
|
|
307
|
+
if (!other) return opt;
|
|
308
|
+
if (Array.isArray(opt)) {
|
|
309
|
+
if (Array.isArray(other)) for (const item of other) opt.push(item);
|
|
310
|
+
else opt.push(other);
|
|
311
|
+
return opt;
|
|
312
|
+
}
|
|
313
|
+
return Array.isArray(other) ? [opt, ...other] : [opt, other];
|
|
314
|
+
}
|
|
315
|
+
// src/html/serializer.ts
|
|
316
|
+
const K_SCOPE_ID = Symbol("Scope ID");
|
|
317
|
+
const kTouchedIterator = /* @__PURE__ */ Symbol.for("marko.touchedIterator");
|
|
318
|
+
const { hasOwnProperty } = {};
|
|
319
|
+
const objectProto = Object.prototype;
|
|
320
|
+
const arrayProto = Array.prototype;
|
|
321
|
+
const Generator = (/* @__PURE__ */ (function* () {})()).constructor;
|
|
322
|
+
const AsyncGenerator = (/* @__PURE__ */ (async function* () {})()).constructor;
|
|
323
|
+
patchIteratorNext(Generator.prototype);
|
|
324
|
+
patchIteratorNext(AsyncGenerator.prototype);
|
|
325
|
+
const REGISTRY = /* @__PURE__ */ new WeakMap();
|
|
326
|
+
const KNOWN_SYMBOLS = /* @__PURE__ */ (() => {
|
|
327
|
+
const KNOWN_SYMBOLS = /* @__PURE__ */ new Map();
|
|
328
|
+
for (const name of Object.getOwnPropertyNames(Symbol)) {
|
|
329
|
+
const symbol = Symbol[name];
|
|
330
|
+
if (typeof symbol === "symbol") KNOWN_SYMBOLS.set(symbol, "Symbol." + name);
|
|
331
|
+
}
|
|
332
|
+
return KNOWN_SYMBOLS;
|
|
333
|
+
})();
|
|
334
|
+
const KNOWN_FUNCTIONS = /* @__PURE__ */ (() => /* @__PURE__ */ new Map([
|
|
335
|
+
[AggregateError, "AggregateError"],
|
|
336
|
+
[Array, "Array"],
|
|
337
|
+
[Array.from, "Array.from"],
|
|
338
|
+
[Array.isArray, "Array.isArray"],
|
|
339
|
+
[Array.of, "Array.of"],
|
|
340
|
+
[ArrayBuffer, "ArrayBuffer"],
|
|
341
|
+
[ArrayBuffer.isView, "ArrayBuffer.isView"],
|
|
342
|
+
[Atomics.add, "Atomics.add"],
|
|
343
|
+
[Atomics.and, "Atomics.and"],
|
|
344
|
+
[Atomics.compareExchange, "Atomics.compareExchange"],
|
|
345
|
+
[Atomics.exchange, "Atomics.exchange"],
|
|
346
|
+
[Atomics.isLockFree, "Atomics.isLockFree"],
|
|
347
|
+
[Atomics.load, "Atomics.load"],
|
|
348
|
+
[Atomics.notify, "Atomics.notify"],
|
|
349
|
+
[Atomics.or, "Atomics.or"],
|
|
350
|
+
[Atomics.store, "Atomics.store"],
|
|
351
|
+
[Atomics.sub, "Atomics.sub"],
|
|
352
|
+
[Atomics.wait, "Atomics.wait"],
|
|
353
|
+
[BigInt, "BigInt"],
|
|
354
|
+
[BigInt.asIntN, "BigInt.asIntN"],
|
|
355
|
+
[BigInt.asUintN, "BigInt.asUintN"],
|
|
356
|
+
[BigInt64Array, "BigInt64Array"],
|
|
357
|
+
[BigInt64Array.from, "BigInt64Array.from"],
|
|
358
|
+
[BigInt64Array.of, "BigInt64Array.of"],
|
|
359
|
+
[BigUint64Array, "BigUint64Array"],
|
|
360
|
+
[BigUint64Array.from, "BigUint64Array.from"],
|
|
361
|
+
[BigUint64Array.of, "BigUint64Array.of"],
|
|
362
|
+
[Boolean, "Boolean"],
|
|
363
|
+
[console.assert, "console.assert"],
|
|
364
|
+
[console.clear, "console.clear"],
|
|
365
|
+
[console.count, "console.count"],
|
|
366
|
+
[console.countReset, "console.countReset"],
|
|
367
|
+
[console.debug, "console.debug"],
|
|
368
|
+
[console.dir, "console.dir"],
|
|
369
|
+
[console.dirxml, "console.dirxml"],
|
|
370
|
+
[console.error, "console.error"],
|
|
371
|
+
[console.group, "console.group"],
|
|
372
|
+
[console.groupCollapsed, "console.groupCollapsed"],
|
|
373
|
+
[console.groupEnd, "console.groupEnd"],
|
|
374
|
+
[console.info, "console.info"],
|
|
375
|
+
[console.log, "console.log"],
|
|
376
|
+
[console.table, "console.table"],
|
|
377
|
+
[console.time, "console.time"],
|
|
378
|
+
[console.timeEnd, "console.timeEnd"],
|
|
379
|
+
[console.timeLog, "console.timeLog"],
|
|
380
|
+
[console.timeStamp, "console.timeStamp"],
|
|
381
|
+
[console.trace, "console.trace"],
|
|
382
|
+
[console.warn, "console.warn"],
|
|
383
|
+
[DataView, "DataView"],
|
|
384
|
+
[Date, "Date"],
|
|
385
|
+
[Date.now, "Date.now"],
|
|
386
|
+
[Date.parse, "Date.parse"],
|
|
387
|
+
[Date.UTC, "Date.UTC"],
|
|
388
|
+
[decodeURI, "decodeURI"],
|
|
389
|
+
[decodeURIComponent, "decodeURIComponent"],
|
|
390
|
+
[encodeURI, "encodeURI"],
|
|
391
|
+
[encodeURIComponent, "encodeURIComponent"],
|
|
392
|
+
[Error, "Error"],
|
|
393
|
+
[EvalError, "EvalError"],
|
|
394
|
+
[Float32Array, "Float32Array"],
|
|
395
|
+
[Float32Array.from, "Float32Array.from"],
|
|
396
|
+
[Float32Array.of, "Float32Array.of"],
|
|
397
|
+
[Float64Array, "Float64Array"],
|
|
398
|
+
[Float64Array.from, "Float64Array.from"],
|
|
399
|
+
[Float64Array.of, "Float64Array.of"],
|
|
400
|
+
[Function, "Function"],
|
|
401
|
+
[globalThis.atob, "atob"],
|
|
402
|
+
[globalThis.btoa, "btoa"],
|
|
403
|
+
[globalThis.clearInterval, "clearInterval"],
|
|
404
|
+
[globalThis.clearTimeout, "clearTimeout"],
|
|
405
|
+
[globalThis.crypto?.getRandomValues, "crypto.getRandomValues"],
|
|
406
|
+
[globalThis.crypto?.randomUUID, "crypto.randomUUID"],
|
|
407
|
+
[globalThis.fetch, "fetch"],
|
|
408
|
+
[globalThis.performance?.now, "performance.now"],
|
|
409
|
+
[globalThis.queueMicrotask, "queueMicrotask"],
|
|
410
|
+
[globalThis.setInterval, "setInterval"],
|
|
411
|
+
[globalThis.setTimeout, "setTimeout"],
|
|
412
|
+
[globalThis.structuredClone, "structuredClone"],
|
|
413
|
+
[globalThis.URL, "URL"],
|
|
414
|
+
[globalThis.URLSearchParams, "URLSearchParams"],
|
|
415
|
+
[globalThis.WritableStream, "WritableStream"],
|
|
416
|
+
[Int16Array, "Int16Array"],
|
|
417
|
+
[Int16Array.from, "Int16Array.from"],
|
|
418
|
+
[Int16Array.of, "Int16Array.of"],
|
|
419
|
+
[Int32Array, "Int32Array"],
|
|
420
|
+
[Int32Array.from, "Int32Array.from"],
|
|
421
|
+
[Int32Array.of, "Int32Array.of"],
|
|
422
|
+
[Int8Array, "Int8Array"],
|
|
423
|
+
[Int8Array.from, "Int8Array.from"],
|
|
424
|
+
[Int8Array.of, "Int8Array.of"],
|
|
425
|
+
[Intl.Collator, "Intl.Collator"],
|
|
426
|
+
[Intl.DateTimeFormat, "Intl.DateTimeFormat"],
|
|
427
|
+
[Intl.DisplayNames, "Intl.DisplayNames"],
|
|
428
|
+
[Intl.getCanonicalLocales, "Intl.getCanonicalLocales"],
|
|
429
|
+
[Intl.ListFormat, "Intl.ListFormat"],
|
|
430
|
+
[Intl.Locale, "Intl.Locale"],
|
|
431
|
+
[Intl.NumberFormat, "Intl.NumberFormat"],
|
|
432
|
+
[Intl.PluralRules, "Intl.PluralRules"],
|
|
433
|
+
[Intl.RelativeTimeFormat, "Intl.RelativeTimeFormat"],
|
|
434
|
+
[Intl.Segmenter, "Intl.Segmenter"],
|
|
435
|
+
[Intl.supportedValuesOf, "Intl.supportedValuesOf"],
|
|
436
|
+
[isFinite, "isFinite"],
|
|
437
|
+
[isNaN, "isNaN"],
|
|
438
|
+
[JSON.parse, "JSON.parse"],
|
|
439
|
+
[JSON.stringify, "JSON.stringify"],
|
|
440
|
+
[Map, "Map"],
|
|
441
|
+
[Map.groupBy, "Map.groupBy"],
|
|
442
|
+
[Math.abs, "Math.abs"],
|
|
443
|
+
[Math.acos, "Math.acos"],
|
|
444
|
+
[Math.acosh, "Math.acosh"],
|
|
445
|
+
[Math.asin, "Math.asin"],
|
|
446
|
+
[Math.asinh, "Math.asinh"],
|
|
447
|
+
[Math.atan, "Math.atan"],
|
|
448
|
+
[Math.atan2, "Math.atan2"],
|
|
449
|
+
[Math.atanh, "Math.atanh"],
|
|
450
|
+
[Math.cbrt, "Math.cbrt"],
|
|
451
|
+
[Math.ceil, "Math.ceil"],
|
|
452
|
+
[Math.clz32, "Math.clz32"],
|
|
453
|
+
[Math.cos, "Math.cos"],
|
|
454
|
+
[Math.cosh, "Math.cosh"],
|
|
455
|
+
[Math.exp, "Math.exp"],
|
|
456
|
+
[Math.expm1, "Math.expm1"],
|
|
457
|
+
[Math.floor, "Math.floor"],
|
|
458
|
+
[Math.fround, "Math.fround"],
|
|
459
|
+
[Math.hypot, "Math.hypot"],
|
|
460
|
+
[Math.imul, "Math.imul"],
|
|
461
|
+
[Math.log, "Math.log"],
|
|
462
|
+
[Math.log10, "Math.log10"],
|
|
463
|
+
[Math.log1p, "Math.log1p"],
|
|
464
|
+
[Math.log2, "Math.log2"],
|
|
465
|
+
[Math.max, "Math.max"],
|
|
466
|
+
[Math.min, "Math.min"],
|
|
467
|
+
[Math.pow, "Math.pow"],
|
|
468
|
+
[Math.random, "Math.random"],
|
|
469
|
+
[Math.round, "Math.round"],
|
|
470
|
+
[Math.sign, "Math.sign"],
|
|
471
|
+
[Math.sin, "Math.sin"],
|
|
472
|
+
[Math.sinh, "Math.sinh"],
|
|
473
|
+
[Math.sqrt, "Math.sqrt"],
|
|
474
|
+
[Math.tan, "Math.tan"],
|
|
475
|
+
[Math.tanh, "Math.tanh"],
|
|
476
|
+
[Math.trunc, "Math.trunc"],
|
|
477
|
+
[Number, "Number"],
|
|
478
|
+
[Number.isFinite, "Number.isFinite"],
|
|
479
|
+
[Number.isInteger, "Number.isInteger"],
|
|
480
|
+
[Number.isNaN, "Number.isNaN"],
|
|
481
|
+
[Number.isSafeInteger, "Number.isSafeInteger"],
|
|
482
|
+
[Number.parseFloat, "Number.parseFloat"],
|
|
483
|
+
[Number.parseInt, "Number.parseInt"],
|
|
484
|
+
[Object, "Object"],
|
|
485
|
+
[Object.assign, "Object.assign"],
|
|
486
|
+
[Object.create, "Object.create"],
|
|
487
|
+
[Object.defineProperties, "Object.defineProperties"],
|
|
488
|
+
[Object.defineProperty, "Object.defineProperty"],
|
|
489
|
+
[Object.entries, "Object.entries"],
|
|
490
|
+
[Object.freeze, "Object.freeze"],
|
|
491
|
+
[Object.fromEntries, "Object.fromEntries"],
|
|
492
|
+
[Object.getOwnPropertyDescriptor, "Object.getOwnPropertyDescriptor"],
|
|
493
|
+
[Object.getOwnPropertyDescriptors, "Object.getOwnPropertyDescriptors"],
|
|
494
|
+
[Object.getOwnPropertyNames, "Object.getOwnPropertyNames"],
|
|
495
|
+
[Object.getOwnPropertySymbols, "Object.getOwnPropertySymbols"],
|
|
496
|
+
[Object.getPrototypeOf, "Object.getPrototypeOf"],
|
|
497
|
+
[Object.is, "Object.is"],
|
|
498
|
+
[Object.isExtensible, "Object.isExtensible"],
|
|
499
|
+
[Object.isFrozen, "Object.isFrozen"],
|
|
500
|
+
[Object.isSealed, "Object.isSealed"],
|
|
501
|
+
[Object.keys, "Object.keys"],
|
|
502
|
+
[Object.preventExtensions, "Object.preventExtensions"],
|
|
503
|
+
[Object.seal, "Object.seal"],
|
|
504
|
+
[Object.setPrototypeOf, "Object.setPrototypeOf"],
|
|
505
|
+
[Object.values, "Object.values"],
|
|
506
|
+
[parseFloat, "parseFloat"],
|
|
507
|
+
[parseInt, "parseInt"],
|
|
508
|
+
[Promise, "Promise"],
|
|
509
|
+
[Proxy, "Proxy"],
|
|
510
|
+
[RangeError, "RangeError"],
|
|
511
|
+
[ReferenceError, "ReferenceError"],
|
|
512
|
+
[Reflect.apply, "Reflect.apply"],
|
|
513
|
+
[Reflect.construct, "Reflect.construct"],
|
|
514
|
+
[Reflect.defineProperty, "Reflect.defineProperty"],
|
|
515
|
+
[Reflect.deleteProperty, "Reflect.deleteProperty"],
|
|
516
|
+
[Reflect.get, "Reflect.get"],
|
|
517
|
+
[Reflect.getOwnPropertyDescriptor, "Reflect.getOwnPropertyDescriptor"],
|
|
518
|
+
[Reflect.getPrototypeOf, "Reflect.getPrototypeOf"],
|
|
519
|
+
[Reflect.has, "Reflect.has"],
|
|
520
|
+
[Reflect.isExtensible, "Reflect.isExtensible"],
|
|
521
|
+
[Reflect.ownKeys, "Reflect.ownKeys"],
|
|
522
|
+
[Reflect.preventExtensions, "Reflect.preventExtensions"],
|
|
523
|
+
[Reflect.set, "Reflect.set"],
|
|
524
|
+
[Reflect.setPrototypeOf, "Reflect.setPrototypeOf"],
|
|
525
|
+
[RegExp, "RegExp"],
|
|
526
|
+
[Set, "Set"],
|
|
527
|
+
[String, "String"],
|
|
528
|
+
[String.fromCharCode, "String.fromCharCode"],
|
|
529
|
+
[String.fromCodePoint, "String.fromCodePoint"],
|
|
530
|
+
[String.raw, "String.raw"],
|
|
531
|
+
[Symbol, "Symbol"],
|
|
532
|
+
[Symbol.for, "Symbol.for"],
|
|
533
|
+
[SyntaxError, "SyntaxError"],
|
|
534
|
+
[TypeError, "TypeError"],
|
|
535
|
+
[Uint16Array, "Uint16Array"],
|
|
536
|
+
[Uint16Array.from, "Uint16Array.from"],
|
|
537
|
+
[Uint16Array.of, "Uint16Array.of"],
|
|
538
|
+
[Uint32Array, "Uint32Array"],
|
|
539
|
+
[Uint32Array.from, "Uint32Array.from"],
|
|
540
|
+
[Uint32Array.of, "Uint32Array.of"],
|
|
541
|
+
[Uint8Array, "Uint8Array"],
|
|
542
|
+
[Uint8Array.from, "Uint8Array.from"],
|
|
543
|
+
[Uint8Array.of, "Uint8Array.of"],
|
|
544
|
+
[Uint8ClampedArray, "Uint8ClampedArray"],
|
|
545
|
+
[Uint8ClampedArray.from, "Uint8ClampedArray.from"],
|
|
546
|
+
[Uint8ClampedArray.of, "Uint8ClampedArray.of"],
|
|
547
|
+
[URIError, "URIError"],
|
|
548
|
+
[WeakMap, "WeakMap"],
|
|
549
|
+
[WeakSet, "WeakSet"]
|
|
550
|
+
]))();
|
|
551
|
+
const KNOWN_OBJECTS = /* @__PURE__ */ (() => /* @__PURE__ */ new Map([
|
|
552
|
+
[Atomics, "Atomics"],
|
|
553
|
+
[console, "console"],
|
|
554
|
+
[globalThis, "globalThis"],
|
|
555
|
+
[globalThis.crypto, "crypto"],
|
|
556
|
+
[Intl, "Intl"],
|
|
557
|
+
[JSON, "JSON"],
|
|
558
|
+
[Math, "Math"],
|
|
559
|
+
[Reflect, "Reflect"]
|
|
560
|
+
]))();
|
|
561
|
+
var State$1 = class {
|
|
562
|
+
ids = 0;
|
|
563
|
+
flushId = 0;
|
|
564
|
+
wroteUndefined = false;
|
|
565
|
+
buf = [];
|
|
566
|
+
strs = /* @__PURE__ */ new Map();
|
|
567
|
+
refs = /* @__PURE__ */ new WeakMap();
|
|
568
|
+
deferredRefs = /* @__PURE__ */ new Set();
|
|
569
|
+
boundary;
|
|
570
|
+
channel = void 0;
|
|
571
|
+
channelDeps = null;
|
|
572
|
+
queuedCalls = [];
|
|
573
|
+
queuedReadyCalls = [];
|
|
574
|
+
scopeRef(scope, scopeId) {
|
|
575
|
+
return this.refs.get(scope) || newScopeReference(this, scope, scopeId);
|
|
576
|
+
}
|
|
577
|
+
writeScopeProps(props, ref) {
|
|
578
|
+
return writeObjectProps(this, props, ref);
|
|
579
|
+
}
|
|
580
|
+
scopesCursor(scopeId) {
|
|
581
|
+
return scopeId + ",";
|
|
582
|
+
}
|
|
583
|
+
writeTrailing(scopesIndex) {
|
|
584
|
+
const { buf } = this;
|
|
585
|
+
if (~scopesIndex) {
|
|
586
|
+
buf[scopesIndex] = "_([" + buf[scopesIndex];
|
|
587
|
+
buf.push("])");
|
|
588
|
+
}
|
|
589
|
+
writeDeferred(this);
|
|
590
|
+
return ",0)";
|
|
591
|
+
}
|
|
592
|
+
wrapPayload(result, extras) {
|
|
593
|
+
const arrow = this.wroteUndefined ? "(_,$)=>" : "_=>";
|
|
594
|
+
this.wroteUndefined = false;
|
|
595
|
+
return extras ? arrow + result : arrow + "[" + result + "]";
|
|
596
|
+
}
|
|
597
|
+
writeScopedRegistration(val, parent, accessor, registered) {
|
|
598
|
+
const ref = new Reference(parent, accessor, this.flushId, this.buf.length);
|
|
599
|
+
ref.channel = this.channel;
|
|
600
|
+
this.refs.set(val, ref);
|
|
601
|
+
ref.debug = DEBUG.get(val);
|
|
602
|
+
const scope = registered.scope;
|
|
603
|
+
const scopeId = scope[K_SCOPE_ID];
|
|
604
|
+
trackScope(this, scope, scopeId);
|
|
605
|
+
const locals = registered.locals?.(this.boundary.state.scope);
|
|
606
|
+
if (locals) {
|
|
607
|
+
this.buf.push(registered.access + "(_(" + scopeId + ")");
|
|
608
|
+
for (const local of locals) {
|
|
609
|
+
this.buf.push(",");
|
|
610
|
+
writePlainObject(this, local, newArgReference(this, ref, local));
|
|
611
|
+
}
|
|
612
|
+
} else this.buf.push("_(" + scopeId + "," + quoteRegistryId(registered.id));
|
|
613
|
+
this.buf.push(")");
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
var Reference = class {
|
|
617
|
+
assignments = null;
|
|
618
|
+
deferredMembers = null;
|
|
619
|
+
scopeId = void 0;
|
|
620
|
+
channel = void 0;
|
|
621
|
+
parent;
|
|
622
|
+
accessor;
|
|
623
|
+
flushId;
|
|
624
|
+
pos;
|
|
625
|
+
id;
|
|
626
|
+
path = null;
|
|
627
|
+
constructor(parent, accessor, flushId, pos = null, id = null) {
|
|
628
|
+
this.parent = parent;
|
|
629
|
+
this.accessor = accessor;
|
|
630
|
+
this.flushId = flushId;
|
|
631
|
+
this.pos = pos;
|
|
632
|
+
this.id = id;
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
const DEBUG = /* @__PURE__ */ new WeakMap();
|
|
636
|
+
function setDebugInfo(obj, file, loc, vars) {
|
|
637
|
+
DEBUG.set(obj, {
|
|
638
|
+
file,
|
|
639
|
+
loc,
|
|
640
|
+
vars,
|
|
641
|
+
slots: DEBUG.get(obj)?.slots
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
function setDebugSlotName(obj, accessor, name) {
|
|
645
|
+
const debug = DEBUG.get(obj);
|
|
646
|
+
if (debug) (debug.slots ??= {})[accessor] = name;
|
|
647
|
+
else DEBUG.set(obj, {
|
|
648
|
+
file: "",
|
|
649
|
+
loc: 0,
|
|
650
|
+
vars: void 0,
|
|
651
|
+
slots: { [accessor]: name }
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
function stringifyScopes(state, flushes, boundary, channel) {
|
|
655
|
+
try {
|
|
656
|
+
state.boundary = boundary;
|
|
657
|
+
state.channel = channel;
|
|
658
|
+
return writeScopesRoot(state, flushes);
|
|
659
|
+
} catch (err) {
|
|
660
|
+
abortRender(boundary, err);
|
|
661
|
+
return "";
|
|
662
|
+
} finally {
|
|
663
|
+
state.flushId++;
|
|
664
|
+
state.buf = [];
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
function pendingReadyChannel(state) {
|
|
668
|
+
const calls = state.queuedReadyCalls;
|
|
669
|
+
return calls.length ? calls[0].channel : void 0;
|
|
670
|
+
}
|
|
671
|
+
function takeChannelDeps(state) {
|
|
672
|
+
const deps = state.channelDeps;
|
|
673
|
+
state.channelDeps = null;
|
|
674
|
+
return deps;
|
|
675
|
+
}
|
|
676
|
+
function queueCall(state, value, object, method, channel) {
|
|
677
|
+
(channel?.readyId ? state.queuedReadyCalls : state.queuedCalls).push({
|
|
678
|
+
method,
|
|
679
|
+
value,
|
|
680
|
+
object,
|
|
681
|
+
channel,
|
|
682
|
+
valueId: null
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
function dropQueuedCall(state, value, object, method, channel) {
|
|
686
|
+
const queuedCalls = channel?.readyId ? state.queuedReadyCalls : state.queuedCalls;
|
|
687
|
+
for (let i = 0; i < queuedCalls.length; i++) {
|
|
688
|
+
const call = queuedCalls[i];
|
|
689
|
+
if (call.value === value && call.object === object && call.method === method) {
|
|
690
|
+
queuedCalls.splice(i, 1);
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
function register(id, val, scope, locals, access = "_._" + toAccess(toObjectKey(id))) {
|
|
697
|
+
REGISTRY.set(val, {
|
|
698
|
+
id,
|
|
699
|
+
scope,
|
|
700
|
+
locals,
|
|
701
|
+
access
|
|
702
|
+
});
|
|
703
|
+
return val;
|
|
704
|
+
}
|
|
705
|
+
function writeScopesRoot(state, flushes) {
|
|
706
|
+
const { buf } = state;
|
|
707
|
+
let nextSlotId = -1;
|
|
708
|
+
let scopesIndex = -1;
|
|
709
|
+
for (const flush of flushes) {
|
|
710
|
+
const scopeId = flush[0];
|
|
711
|
+
const scope = flush[1];
|
|
712
|
+
const ref = state.scopeRef(scope, scopeId);
|
|
713
|
+
const openIndex = buf.push("") - 1;
|
|
714
|
+
if (state.writeScopeProps(flush[2], ref)) {
|
|
715
|
+
buf[openIndex] = nextSlotId === -1 ? state.scopesCursor(scopeId) + "{" : (scopeId !== nextSlotId ? "," + (scopeId - nextSlotId) : "") + ",{";
|
|
716
|
+
if (scopesIndex === -1) scopesIndex = openIndex;
|
|
717
|
+
nextSlotId = scopeId + 1;
|
|
718
|
+
buf.push("}");
|
|
719
|
+
} else buf.pop();
|
|
720
|
+
}
|
|
721
|
+
let extras = "";
|
|
722
|
+
if (state.deferredRefs.size || hasMatchingCalls(state, state.channel?.readyId)) extras = state.writeTrailing(scopesIndex);
|
|
723
|
+
let result = extras && "(";
|
|
724
|
+
for (const chunk of buf) result += chunk;
|
|
725
|
+
result += extras;
|
|
726
|
+
if (!result) return "";
|
|
727
|
+
return state.wrapPayload(result, extras);
|
|
728
|
+
}
|
|
729
|
+
function writeDeferred(state) {
|
|
730
|
+
let sep = state.buf.length ? "," : "";
|
|
731
|
+
if (state.deferredRefs.size) {
|
|
732
|
+
const pending = state.deferredRefs;
|
|
733
|
+
state.deferredRefs = /* @__PURE__ */ new Set();
|
|
734
|
+
let buf = "";
|
|
735
|
+
let hasCalls = false;
|
|
736
|
+
for (const ref of pending) {
|
|
737
|
+
if (ref.assignments) {
|
|
738
|
+
buf += sep + assignmentsToString(ref.assignments, ref.id);
|
|
739
|
+
ref.assignments = null;
|
|
740
|
+
sep = ",";
|
|
741
|
+
}
|
|
742
|
+
hasCalls ||= ref.deferredMembers !== null;
|
|
743
|
+
}
|
|
744
|
+
if (buf) state.buf.push(buf);
|
|
745
|
+
if (hasCalls) for (const ref of pending) {
|
|
746
|
+
const members = ref.deferredMembers;
|
|
747
|
+
if (members) {
|
|
748
|
+
writeDeferredMembers(state, ref.id, members);
|
|
749
|
+
ref.deferredMembers = null;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
const readyId = state.channel?.readyId;
|
|
754
|
+
let calls = state.queuedCalls;
|
|
755
|
+
if (readyId) {
|
|
756
|
+
calls = [];
|
|
757
|
+
const remaining = [];
|
|
758
|
+
for (const call of state.queuedReadyCalls) (call.channel.readyId === readyId ? calls : remaining).push(call);
|
|
759
|
+
state.queuedReadyCalls = remaining;
|
|
760
|
+
} else if (calls.length) state.queuedCalls = [];
|
|
761
|
+
for (const call of calls) {
|
|
762
|
+
const objectStartIndex = state.buf.push(state.buf.length === 0 ? "" : ",");
|
|
763
|
+
if (writeProp(state, call.object, null, "")) {
|
|
764
|
+
const objectRef = state.refs.get(call.object);
|
|
765
|
+
if (!objectRef.id && !isAncestorChannelRef(state, objectRef)) {
|
|
766
|
+
objectRef.id = nextRefAccess(state);
|
|
767
|
+
state.buf[objectStartIndex] = "(" + objectRef.id + "=" + state.buf[objectStartIndex];
|
|
768
|
+
state.buf.push(")");
|
|
769
|
+
} else if (objectRef.id && state.buf[objectStartIndex] !== objectRef.id) {
|
|
770
|
+
state.buf[objectStartIndex] = "(" + state.buf[objectStartIndex];
|
|
771
|
+
state.buf.push(")");
|
|
772
|
+
}
|
|
773
|
+
} else state.buf.push("void 0");
|
|
774
|
+
state.buf.push("." + call.method + "(");
|
|
775
|
+
if (call.value !== void 0) writeCallArg(state, call.value, call.valueId);
|
|
776
|
+
state.buf.push(")");
|
|
777
|
+
}
|
|
778
|
+
if (state.deferredRefs.size) writeDeferred(state);
|
|
779
|
+
}
|
|
780
|
+
function writeDeferredMembers(state, id, { collection, first, rest }) {
|
|
781
|
+
if (collection instanceof Map) {
|
|
782
|
+
writeDeferredEntry(state, id, first);
|
|
783
|
+
for (const entry of rest) writeDeferredEntry(state, id, entry);
|
|
784
|
+
} else {
|
|
785
|
+
writeDeferredMember(state, id, first);
|
|
786
|
+
for (const member of rest) writeDeferredMember(state, id, member);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
function writeDeferredEntry(state, id, [key, value]) {
|
|
790
|
+
state.buf.push("," + id + ".set(");
|
|
791
|
+
if (key !== void 0 || value !== void 0) writeCallArg(state, key, null);
|
|
792
|
+
if (value !== void 0) {
|
|
793
|
+
state.buf.push(",");
|
|
794
|
+
writeCallArg(state, value, null);
|
|
795
|
+
}
|
|
796
|
+
state.buf.push(")");
|
|
797
|
+
}
|
|
798
|
+
function writeDeferredMember(state, id, member) {
|
|
799
|
+
state.buf.push("," + id + ".add(");
|
|
800
|
+
if (member !== void 0) writeCallArg(state, member, null);
|
|
801
|
+
state.buf.push(")");
|
|
802
|
+
}
|
|
803
|
+
function writeCallArg(state, val, valueId) {
|
|
804
|
+
const startIndex = state.buf.length;
|
|
805
|
+
if (val === void 0) {
|
|
806
|
+
state.wroteUndefined = true;
|
|
807
|
+
state.buf.push("$");
|
|
808
|
+
} else if (writeProp(state, val, null, "")) {
|
|
809
|
+
const ref = typeof val === "string" ? state.strs.get(val) : state.refs.get(val);
|
|
810
|
+
if (ref && !ref.id && ref.scopeId === void 0 && !isAncestorChannelRef(state, ref)) {
|
|
811
|
+
ref.id = valueId || nextRefAccess(state);
|
|
812
|
+
state.buf[startIndex] = ref.id + "=" + state.buf[startIndex];
|
|
813
|
+
}
|
|
814
|
+
} else state.buf.push("void 0");
|
|
815
|
+
}
|
|
816
|
+
function hasMatchingCalls(state, readyId) {
|
|
817
|
+
if (!readyId) return state.queuedCalls.length > 0;
|
|
818
|
+
for (const call of state.queuedReadyCalls) if (call.channel.readyId === readyId) return true;
|
|
819
|
+
return false;
|
|
820
|
+
}
|
|
821
|
+
function writeProp(state, val, parent, accessor) {
|
|
822
|
+
switch (typeof val) {
|
|
823
|
+
case "string": return writeString(state, val, parent, accessor);
|
|
824
|
+
case "number": return writeNumber(state, val);
|
|
825
|
+
case "boolean": return writeBoolean(state, val);
|
|
826
|
+
case "bigint": return writeBigInt(state, val);
|
|
827
|
+
case "symbol": return writeSymbol(state, val, parent, accessor);
|
|
828
|
+
case "function": return writeFunction(state, val, parent, accessor);
|
|
829
|
+
case "object": return writeObject(state, val, parent, accessor);
|
|
830
|
+
default:
|
|
831
|
+
throwUnserializable(state, val, parent, accessor);
|
|
832
|
+
return false;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
function writeReferenceOr(state, write, val, parent, accessor) {
|
|
836
|
+
let ref = state.refs.get(val);
|
|
837
|
+
if (ref) {
|
|
838
|
+
if (!trackChannel(state, ref)) {
|
|
839
|
+
abortUnreachableChannel(state, val);
|
|
840
|
+
return false;
|
|
841
|
+
}
|
|
842
|
+
if (parent && isCircular(parent, ref)) {
|
|
843
|
+
ensureRefAccess(state, ref);
|
|
844
|
+
state.deferredRefs.add(ref);
|
|
845
|
+
addAssignment(ref, accessId(state, parent) + toAccess(accessor));
|
|
846
|
+
return false;
|
|
847
|
+
}
|
|
848
|
+
writeRef(state, ref);
|
|
849
|
+
return true;
|
|
850
|
+
}
|
|
851
|
+
const registered = REGISTRY.get(val);
|
|
852
|
+
if (registered) return writeRegistered(state, val, parent, accessor, registered);
|
|
853
|
+
state.refs.set(val, ref = new Reference(parent, accessor, state.flushId, state.buf.length));
|
|
854
|
+
ref.channel = state.channel;
|
|
855
|
+
ref.debug = DEBUG.get(val);
|
|
856
|
+
if (write(state, val, ref)) return true;
|
|
857
|
+
state.refs.delete(val);
|
|
858
|
+
return false;
|
|
859
|
+
}
|
|
860
|
+
function trackScope(state, val, scopeId) {
|
|
861
|
+
const ref = state.refs.get(val);
|
|
862
|
+
if (ref) trackChannel(state, ref);
|
|
863
|
+
else newScopeReference(state, val, scopeId);
|
|
864
|
+
}
|
|
865
|
+
function newScopeReference(state, val, scopeId) {
|
|
866
|
+
const ref = new Reference(null, null, state.flushId);
|
|
867
|
+
ref.scopeId = scopeId;
|
|
868
|
+
ref.channel = state.channel;
|
|
869
|
+
state.refs.set(val, ref);
|
|
870
|
+
ref.debug = DEBUG.get(val);
|
|
871
|
+
return ref;
|
|
872
|
+
}
|
|
873
|
+
function quoteRegistryId(id) {
|
|
874
|
+
return quote(id, 0);
|
|
875
|
+
}
|
|
876
|
+
function writeRegistered(state, val, parent, accessor, registered) {
|
|
877
|
+
const { scope } = registered;
|
|
878
|
+
if (scope) state.writeScopedRegistration(val, parent, accessor, registered);
|
|
879
|
+
else state.buf.push(registered.access);
|
|
880
|
+
return true;
|
|
881
|
+
}
|
|
882
|
+
const STRING_DEDUP_LENGTH = 12;
|
|
883
|
+
function writeString(state, val, parent, accessor) {
|
|
884
|
+
if (val.length > STRING_DEDUP_LENGTH) {
|
|
885
|
+
const ref = state.strs.get(val);
|
|
886
|
+
if (ref) {
|
|
887
|
+
if (trackChannel(state, ref)) {
|
|
888
|
+
writeRef(state, ref);
|
|
889
|
+
return true;
|
|
890
|
+
}
|
|
891
|
+
} else {
|
|
892
|
+
const ref = new Reference(parent, accessor, state.flushId, state.buf.length);
|
|
893
|
+
ref.channel = state.channel;
|
|
894
|
+
state.strs.set(val, ref);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
state.buf.push(quote(val, 0));
|
|
898
|
+
return true;
|
|
899
|
+
}
|
|
900
|
+
function writeNumber(state, val) {
|
|
901
|
+
state.buf.push(val + "");
|
|
902
|
+
return true;
|
|
903
|
+
}
|
|
904
|
+
function writeBoolean(state, val) {
|
|
905
|
+
state.buf.push(val ? "!0" : "!1");
|
|
906
|
+
return true;
|
|
907
|
+
}
|
|
908
|
+
function writeBigInt(state, val) {
|
|
909
|
+
state.buf.push(val + "n");
|
|
910
|
+
return true;
|
|
911
|
+
}
|
|
912
|
+
function writeFunction(state, val, parent, accessor) {
|
|
913
|
+
const wellKnownFunction = KNOWN_FUNCTIONS.get(val);
|
|
914
|
+
if (wellKnownFunction) {
|
|
915
|
+
state.buf.push(wellKnownFunction);
|
|
916
|
+
return true;
|
|
917
|
+
}
|
|
918
|
+
return writeReferenceOr(state, writeNever, val, parent, accessor);
|
|
919
|
+
}
|
|
920
|
+
function writeSymbol(state, val, parent, accessor) {
|
|
921
|
+
const wellKnownSymbol = KNOWN_SYMBOLS.get(val);
|
|
922
|
+
if (wellKnownSymbol) {
|
|
923
|
+
state.buf.push(wellKnownSymbol);
|
|
924
|
+
return true;
|
|
925
|
+
}
|
|
926
|
+
const key = Symbol.keyFor(val);
|
|
927
|
+
if (key !== void 0) {
|
|
928
|
+
state.buf.push("Symbol.for(" + quote(key, 0) + ")");
|
|
929
|
+
return true;
|
|
930
|
+
}
|
|
931
|
+
return writeReferenceOr(state, writeUnknownSymbol, val, parent, accessor);
|
|
932
|
+
}
|
|
933
|
+
function writeUnknownSymbol(state) {
|
|
934
|
+
state.buf.push("Symbol()");
|
|
935
|
+
return true;
|
|
936
|
+
}
|
|
937
|
+
function writeNever(state, val, ref) {
|
|
938
|
+
throwUnserializable(state, val, ref);
|
|
939
|
+
return false;
|
|
940
|
+
}
|
|
941
|
+
function writeNull(state) {
|
|
942
|
+
state.buf.push("null");
|
|
943
|
+
return true;
|
|
944
|
+
}
|
|
945
|
+
function writeObject(state, val, parent, accessor) {
|
|
946
|
+
if (val === null) return writeNull(state);
|
|
947
|
+
const scopeId = val[K_SCOPE_ID];
|
|
948
|
+
if (scopeId !== void 0) {
|
|
949
|
+
trackScope(state, val, scopeId);
|
|
950
|
+
state.buf.push("_(" + scopeId + ")");
|
|
951
|
+
return true;
|
|
952
|
+
}
|
|
953
|
+
const wellKnownObject = KNOWN_OBJECTS.get(val);
|
|
954
|
+
if (wellKnownObject) {
|
|
955
|
+
state.buf.push(wellKnownObject);
|
|
956
|
+
return true;
|
|
957
|
+
}
|
|
958
|
+
return writeReferenceOr(state, writeUnknownObject, val, parent, accessor);
|
|
959
|
+
}
|
|
960
|
+
function writeUnknownObject(state, val, ref) {
|
|
961
|
+
const proto = Object.getPrototypeOf(val);
|
|
962
|
+
if (proto === objectProto) return writePlainObject(state, val, ref);
|
|
963
|
+
if (proto === arrayProto) return writeArray(state, val, ref);
|
|
964
|
+
const constructor = proto?.constructor;
|
|
965
|
+
switch (constructor) {
|
|
966
|
+
case void 0: return writeNullObject(state, val, ref);
|
|
967
|
+
case Object: return writePlainObject(state, val, ref);
|
|
968
|
+
case Array: return writeArray(state, val, ref);
|
|
969
|
+
case Date: return writeDate(state, val);
|
|
970
|
+
case RegExp: return writeRegExp(state, val);
|
|
971
|
+
case Promise: return writePromise(state, val, ref);
|
|
972
|
+
case Map: return writeMap(state, val, ref);
|
|
973
|
+
case Set: return writeSet(state, val, ref);
|
|
974
|
+
case Generator: return writeGenerator(state, val, ref);
|
|
975
|
+
case AsyncGenerator: return writeAsyncGenerator(state, val, ref);
|
|
976
|
+
case Error:
|
|
977
|
+
case EvalError:
|
|
978
|
+
case RangeError:
|
|
979
|
+
case ReferenceError:
|
|
980
|
+
case SyntaxError:
|
|
981
|
+
case TypeError:
|
|
982
|
+
case URIError: return writeError(state, val, constructor.name, ref);
|
|
983
|
+
case AggregateError: return writeAggregateError(state, val, ref);
|
|
984
|
+
case ArrayBuffer: return writeArrayBuffer(state, val);
|
|
985
|
+
case Int8Array:
|
|
986
|
+
case Uint8Array:
|
|
987
|
+
case Uint8ClampedArray:
|
|
988
|
+
case Int16Array:
|
|
989
|
+
case Uint16Array:
|
|
990
|
+
case Int32Array:
|
|
991
|
+
case Uint32Array:
|
|
992
|
+
case Float32Array:
|
|
993
|
+
case Float64Array:
|
|
994
|
+
case BigInt64Array:
|
|
995
|
+
case BigUint64Array: return writeTypedArray(state, val, constructor.name, ref);
|
|
996
|
+
case DataView: return writeDataView(state, val, ref);
|
|
997
|
+
case WeakSet: return writeWeakSet(state);
|
|
998
|
+
case WeakMap: return writeWeakMap(state);
|
|
999
|
+
case globalThis.URL: return writeURL(state, val);
|
|
1000
|
+
case globalThis.URLSearchParams: return writeURLSearchParams(state, val);
|
|
1001
|
+
case globalThis.Headers: return writeHeaders(state, val);
|
|
1002
|
+
case globalThis.FormData: return writeFormData(state, val, ref);
|
|
1003
|
+
case globalThis.ReadableStream: return writeReadableStream(state, val, ref);
|
|
1004
|
+
case globalThis.Request: return writeRequest(state, val, ref);
|
|
1005
|
+
case globalThis.Response: return writeResponse(state, val, ref);
|
|
1006
|
+
case globalThis.Intl?.NumberFormat: return writeIntl(state, val, "NumberFormat", ref);
|
|
1007
|
+
case globalThis.Intl?.DateTimeFormat: return writeIntl(state, val, "DateTimeFormat", ref);
|
|
1008
|
+
case globalThis.Intl?.Collator: return writeIntl(state, val, "Collator", ref);
|
|
1009
|
+
case globalThis.Intl?.PluralRules: return writeIntl(state, val, "PluralRules", ref);
|
|
1010
|
+
case globalThis.Intl?.RelativeTimeFormat: return writeIntl(state, val, "RelativeTimeFormat", ref);
|
|
1011
|
+
case globalThis.Intl?.ListFormat: return writeIntl(state, val, "ListFormat", ref);
|
|
1012
|
+
case globalThis.Intl?.DisplayNames: return writeIntl(state, val, "DisplayNames", ref);
|
|
1013
|
+
case globalThis.Intl?.Segmenter: return writeIntl(state, val, "Segmenter", ref);
|
|
1014
|
+
case globalThis.Intl?.DurationFormat: return writeIntl(state, val, "DurationFormat", ref);
|
|
1015
|
+
case globalThis.Intl?.Locale: return writeIntlLocale(state, val);
|
|
1016
|
+
case globalThis.Temporal?.Instant: return writeTemporal(state, val, "Instant");
|
|
1017
|
+
case globalThis.Temporal?.Duration: return writeTemporal(state, val, "Duration");
|
|
1018
|
+
case globalThis.Temporal?.PlainDate: return writeTemporal(state, val, "PlainDate");
|
|
1019
|
+
case globalThis.Temporal?.PlainDateTime: return writeTemporal(state, val, "PlainDateTime");
|
|
1020
|
+
case globalThis.Temporal?.PlainMonthDay: return writeTemporal(state, val, "PlainMonthDay");
|
|
1021
|
+
case globalThis.Temporal?.PlainTime: return writeTemporal(state, val, "PlainTime");
|
|
1022
|
+
case globalThis.Temporal?.PlainYearMonth: return writeTemporal(state, val, "PlainYearMonth");
|
|
1023
|
+
case globalThis.Temporal?.ZonedDateTime: return writeTemporal(state, val, "ZonedDateTime");
|
|
1024
|
+
}
|
|
1025
|
+
throwUnserializable(state, val, ref);
|
|
1026
|
+
return false;
|
|
1027
|
+
}
|
|
1028
|
+
function writePlainObject(state, val, ref) {
|
|
1029
|
+
state.buf.push("{");
|
|
1030
|
+
writeMaybeIterableProps(state, val, ref);
|
|
1031
|
+
state.buf.push("}");
|
|
1032
|
+
return true;
|
|
1033
|
+
}
|
|
1034
|
+
function writeArray(state, val, ref) {
|
|
1035
|
+
let sep = "[";
|
|
1036
|
+
for (let i = 0; i < val.length; i++) {
|
|
1037
|
+
const item = val[i];
|
|
1038
|
+
state.buf.push(sep);
|
|
1039
|
+
sep = ",";
|
|
1040
|
+
if (item === void 0) {
|
|
1041
|
+
state.wroteUndefined = true;
|
|
1042
|
+
state.buf.push("$");
|
|
1043
|
+
} else writeProp(state, item, ref, "" + i);
|
|
1044
|
+
}
|
|
1045
|
+
if (sep === "[") state.buf.push("[]");
|
|
1046
|
+
else state.buf.push("]");
|
|
1047
|
+
return true;
|
|
1048
|
+
}
|
|
1049
|
+
function writeDate(state, val) {
|
|
1050
|
+
state.buf.push("new Date(" + +val + ")");
|
|
1051
|
+
return true;
|
|
1052
|
+
}
|
|
1053
|
+
const unsafeRegExpSourceReg = /\\[\s\S]|[<\0\ud800-\udfff]/gu;
|
|
1054
|
+
const unsafeRegExpSourceDetect = /[<\0\ud800-\udfff]/u;
|
|
1055
|
+
const replaceUnsafeRegExpSourceChar = (match) => {
|
|
1056
|
+
const ch = match.length === 3 ? "" : match[match.length - 1];
|
|
1057
|
+
if (ch === "<") return "\\x3C";
|
|
1058
|
+
if (ch === "\0") return "\\x00";
|
|
1059
|
+
const code = ch.charCodeAt(0);
|
|
1060
|
+
return code >= 55296 && code <= 57343 ? "\\u" + code.toString(16).padStart(4, "0") : match;
|
|
1061
|
+
};
|
|
1062
|
+
function writeRegExp(state, val) {
|
|
1063
|
+
const { source } = val;
|
|
1064
|
+
if (source.includes("<")) state.buf.push(`RegExp(${quote(source, 0)}${val.flags ? ",\"" + val.flags + "\"" : ""})`);
|
|
1065
|
+
else state.buf.push("/" + (unsafeRegExpSourceDetect.test(source) ? source.replace(unsafeRegExpSourceReg, replaceUnsafeRegExpSourceChar) : source) + "/" + val.flags);
|
|
1066
|
+
return true;
|
|
1067
|
+
}
|
|
1068
|
+
function writePromise(state, val, ref) {
|
|
1069
|
+
const { boundary, channel } = state;
|
|
1070
|
+
const pId = nextRefAccess(state);
|
|
1071
|
+
const handle = newAsyncHandle(state, ref, pId);
|
|
1072
|
+
state.buf.push("(p=>p=new Promise((f,r)=>" + pId + "={f,r(e){p.catch(_=>0);r(e)}}))()");
|
|
1073
|
+
val.then((v) => queueAsyncCall(state, boundary, handle, "f", v, channel, pId), (v) => queueAsyncCall(state, boundary, handle, "r", v, channel, pId));
|
|
1074
|
+
boundary.startAsync();
|
|
1075
|
+
return true;
|
|
1076
|
+
}
|
|
1077
|
+
function newAsyncHandle(state, parent, id) {
|
|
1078
|
+
const handle = {};
|
|
1079
|
+
const handleRef = new Reference(parent, null, state.flushId, null, id);
|
|
1080
|
+
handleRef.channel = state.channel;
|
|
1081
|
+
state.refs.set(handle, handleRef);
|
|
1082
|
+
return handle;
|
|
1083
|
+
}
|
|
1084
|
+
function writeMap(state, val, ref) {
|
|
1085
|
+
if (!val.size) {
|
|
1086
|
+
state.buf.push("new Map");
|
|
1087
|
+
return true;
|
|
1088
|
+
}
|
|
1089
|
+
const items = [];
|
|
1090
|
+
let assignments;
|
|
1091
|
+
let needsId;
|
|
1092
|
+
let i = 0;
|
|
1093
|
+
const entries = val.entries();
|
|
1094
|
+
if (val.size < 25) {
|
|
1095
|
+
for (const entry of entries) {
|
|
1096
|
+
let [itemKey, itemValue] = entry;
|
|
1097
|
+
if (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) {
|
|
1098
|
+
deferMembers(state, ref, val, entry, entries);
|
|
1099
|
+
if (!i) {
|
|
1100
|
+
state.buf.push("new Map");
|
|
1101
|
+
return true;
|
|
1102
|
+
}
|
|
1103
|
+
break;
|
|
1104
|
+
}
|
|
1105
|
+
if (itemKey === val) {
|
|
1106
|
+
itemKey = void 0;
|
|
1107
|
+
(assignments ||= []).push("a[" + i + "][0]");
|
|
1108
|
+
}
|
|
1109
|
+
if (itemValue === val) {
|
|
1110
|
+
itemValue = void 0;
|
|
1111
|
+
(assignments ||= []).push("a[" + i + "][1]");
|
|
1112
|
+
}
|
|
1113
|
+
needsId ||= isReusableMember(itemKey) || isReusableMember(itemValue);
|
|
1114
|
+
i = items.push(itemValue === void 0 ? itemKey === void 0 ? [] : [itemKey] : [itemKey, itemValue]);
|
|
1115
|
+
}
|
|
1116
|
+
writeArrayArg(state, ref, items, assignments && "((m,a)=>(" + assignmentsToString(assignments, "m") + ",a.forEach(i=>m.set(i[0],i[1])),m))(new Map,", "new Map(", needsId);
|
|
1117
|
+
} else {
|
|
1118
|
+
for (const entry of entries) {
|
|
1119
|
+
let [itemKey, itemValue] = entry;
|
|
1120
|
+
if (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) {
|
|
1121
|
+
deferMembers(state, ref, val, entry, entries);
|
|
1122
|
+
if (!i) {
|
|
1123
|
+
state.buf.push("new Map");
|
|
1124
|
+
return true;
|
|
1125
|
+
}
|
|
1126
|
+
break;
|
|
1127
|
+
}
|
|
1128
|
+
if (itemKey === val) {
|
|
1129
|
+
itemKey = 0;
|
|
1130
|
+
(assignments ||= []).push("a[" + i + "]");
|
|
1131
|
+
}
|
|
1132
|
+
if (itemValue === val) {
|
|
1133
|
+
itemValue = 0;
|
|
1134
|
+
(assignments ||= []).push("a[" + (i + 1) + "]");
|
|
1135
|
+
}
|
|
1136
|
+
needsId ||= isReusableMember(itemKey) || isReusableMember(itemValue);
|
|
1137
|
+
i = items.push(itemKey, itemValue);
|
|
1138
|
+
}
|
|
1139
|
+
writeArrayArg(state, ref, items, assignments && "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1])," + assignmentsToString(assignments, "new Map") + "))(", "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1]),new Map))(", needsId);
|
|
1140
|
+
}
|
|
1141
|
+
return true;
|
|
1142
|
+
}
|
|
1143
|
+
function writeSet(state, val, ref) {
|
|
1144
|
+
if (!val.size) {
|
|
1145
|
+
state.buf.push("new Set");
|
|
1146
|
+
return true;
|
|
1147
|
+
}
|
|
1148
|
+
const items = [];
|
|
1149
|
+
let assignments;
|
|
1150
|
+
let needsId;
|
|
1151
|
+
let i = 0;
|
|
1152
|
+
const members = val.values();
|
|
1153
|
+
for (let item of members) {
|
|
1154
|
+
if (item !== val && isAncestorMember(state, ref, item)) {
|
|
1155
|
+
deferMembers(state, ref, val, item, members);
|
|
1156
|
+
if (!i) {
|
|
1157
|
+
state.buf.push("new Set");
|
|
1158
|
+
return true;
|
|
1159
|
+
}
|
|
1160
|
+
break;
|
|
1161
|
+
}
|
|
1162
|
+
if (item === val) {
|
|
1163
|
+
item = 0;
|
|
1164
|
+
(assignments ||= []).push("i[" + i + "]");
|
|
1165
|
+
} else needsId ||= isReusableMember(item);
|
|
1166
|
+
i = items.push(item);
|
|
1167
|
+
}
|
|
1168
|
+
writeArrayArg(state, ref, items, assignments && "((s,i)=>(" + assignmentsToString(assignments, "s") + ",i.forEach(i=>s.add(i)),s))(new Set,", "new Set(", needsId);
|
|
1169
|
+
return true;
|
|
1170
|
+
}
|
|
1171
|
+
function isAncestorMember(state, container, member) {
|
|
1172
|
+
if (member === null || typeof member !== "object" && typeof member !== "function") return false;
|
|
1173
|
+
const ref = state.refs.get(member);
|
|
1174
|
+
return ref !== void 0 && isCircular(container, ref);
|
|
1175
|
+
}
|
|
1176
|
+
function deferMembers(state, ref, collection, first, rest) {
|
|
1177
|
+
ensureRefAccess(state, ref);
|
|
1178
|
+
ref.deferredMembers = {
|
|
1179
|
+
collection,
|
|
1180
|
+
first,
|
|
1181
|
+
rest
|
|
1182
|
+
};
|
|
1183
|
+
state.deferredRefs.add(ref);
|
|
1184
|
+
}
|
|
1185
|
+
function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
|
|
1186
|
+
if (assignsPrefix || needsId) {
|
|
1187
|
+
const arrayRef = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
|
|
1188
|
+
state.buf.push((assignsPrefix || plainPrefix) + arrayRef.id + "=");
|
|
1189
|
+
writeArray(state, items, arrayRef);
|
|
1190
|
+
} else {
|
|
1191
|
+
state.buf.push(plainPrefix);
|
|
1192
|
+
writeArray(state, items, new Reference(ref, null, state.flushId, state.buf.length));
|
|
1193
|
+
}
|
|
1194
|
+
state.buf.push(")");
|
|
1195
|
+
}
|
|
1196
|
+
function newArgReference(state, parent, val) {
|
|
1197
|
+
for (const key in val) {
|
|
1198
|
+
const member = val[key];
|
|
1199
|
+
if (isReusableMember(member) && !(typeof member === "string" ? state.strs.has(member) : state.refs.has(member))) {
|
|
1200
|
+
const ref = new Reference(parent, null, state.flushId, null, nextRefAccess(state));
|
|
1201
|
+
state.buf.push(ref.id + "=");
|
|
1202
|
+
return ref;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
return new Reference(parent, null, state.flushId, state.buf.length);
|
|
1206
|
+
}
|
|
1207
|
+
function isReusableMember(val) {
|
|
1208
|
+
switch (typeof val) {
|
|
1209
|
+
case "object": return val !== null && val[K_SCOPE_ID] === void 0;
|
|
1210
|
+
case "function":
|
|
1211
|
+
case "symbol": return true;
|
|
1212
|
+
case "string": return val.length > STRING_DEDUP_LENGTH;
|
|
1213
|
+
default: return false;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
function canWriteBuffer(state, buffer, ref) {
|
|
1217
|
+
if (Object.getPrototypeOf(buffer)?.constructor === ArrayBuffer) return true;
|
|
1218
|
+
throwUnserializable(state, buffer, ref, "buffer");
|
|
1219
|
+
return false;
|
|
1220
|
+
}
|
|
1221
|
+
function writeDataView(state, val, ref) {
|
|
1222
|
+
const { buffer } = val;
|
|
1223
|
+
if (!canWriteBuffer(state, buffer, ref)) return false;
|
|
1224
|
+
const needsLength = val.byteOffset + val.byteLength < buffer.byteLength;
|
|
1225
|
+
state.buf.push("new DataView(");
|
|
1226
|
+
writeProp(state, buffer, ref, "buffer");
|
|
1227
|
+
state.buf.push((val.byteOffset || needsLength ? "," + val.byteOffset + (needsLength ? "," + val.byteLength : "") : "") + ")");
|
|
1228
|
+
return true;
|
|
1229
|
+
}
|
|
1230
|
+
function writeArrayBuffer(state, val) {
|
|
1231
|
+
let result;
|
|
1232
|
+
if (val.byteLength) {
|
|
1233
|
+
const view = new Int8Array(val);
|
|
1234
|
+
result = hasOnlyZeros(view) ? "new ArrayBuffer(" + val.byteLength + ")" : "new Int8Array(" + typedArrayToInitString(view) + ").buffer";
|
|
1235
|
+
} else result = "new ArrayBuffer";
|
|
1236
|
+
state.buf.push(result);
|
|
1237
|
+
return true;
|
|
1238
|
+
}
|
|
1239
|
+
function writeTypedArray(state, val, name, ref) {
|
|
1240
|
+
if (val.byteOffset || val.byteLength < val.buffer.byteLength || state.refs.has(val.buffer)) {
|
|
1241
|
+
if (!canWriteBuffer(state, val.buffer, ref)) return false;
|
|
1242
|
+
const needsLength = val.byteOffset + val.byteLength < val.buffer.byteLength;
|
|
1243
|
+
state.buf.push("new " + name + "(");
|
|
1244
|
+
writeProp(state, val.buffer, ref, "buffer");
|
|
1245
|
+
state.buf.push((val.byteOffset || needsLength ? "," + val.byteOffset + (needsLength ? "," + val.length : "") : "") + ")");
|
|
1246
|
+
} else {
|
|
1247
|
+
state.refs.set(val.buffer, new Reference(ref, "buffer", state.flushId, null));
|
|
1248
|
+
state.buf.push("new " + name + (val.length === 0 ? "" : "(" + (hasOnlyZeros(val) ? val.length : typedArrayToInitString(val)) + ")"));
|
|
1249
|
+
}
|
|
1250
|
+
return true;
|
|
1251
|
+
}
|
|
1252
|
+
function writeWeakSet(state) {
|
|
1253
|
+
state.buf.push("new WeakSet");
|
|
1254
|
+
return true;
|
|
1255
|
+
}
|
|
1256
|
+
function writeWeakMap(state) {
|
|
1257
|
+
state.buf.push("new WeakMap");
|
|
1258
|
+
return true;
|
|
1259
|
+
}
|
|
1260
|
+
function writeError(state, val, name, ref) {
|
|
1261
|
+
const result = "new " + name + "(" + quote(val.message + "", 0);
|
|
1262
|
+
if (val.cause !== void 0) {
|
|
1263
|
+
const pos = state.buf.push(result + ",{cause:") - 1;
|
|
1264
|
+
if (writeProp(state, val.cause, ref, "cause")) state.buf.push("})");
|
|
1265
|
+
else state.buf[pos] = state.buf[pos].slice(0, -8) + ")";
|
|
1266
|
+
} else state.buf.push(result + ")");
|
|
1267
|
+
return true;
|
|
1268
|
+
}
|
|
1269
|
+
function writeAggregateError(state, val, ref) {
|
|
1270
|
+
state.buf.push("new AggregateError(");
|
|
1271
|
+
const inlined = writeProp(state, val.errors, ref, "errors");
|
|
1272
|
+
if (!inlined) state.buf.push("[]");
|
|
1273
|
+
if (val.message) state.buf.push("," + quote(val.message + "", 0) + ")");
|
|
1274
|
+
else state.buf.push(")");
|
|
1275
|
+
if (inlined) {
|
|
1276
|
+
const errorsRef = state.refs.get(val.errors);
|
|
1277
|
+
if (errorsRef?.id) {
|
|
1278
|
+
state.deferredRefs.add(errorsRef);
|
|
1279
|
+
addAssignment(errorsRef, accessId(state, ref) + toAccess("errors"));
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
return true;
|
|
1283
|
+
}
|
|
1284
|
+
function writeURL(state, val) {
|
|
1285
|
+
state.buf.push("new URL(" + quote(val.toString(), 0) + ")");
|
|
1286
|
+
return true;
|
|
1287
|
+
}
|
|
1288
|
+
function writeURLSearchParams(state, val) {
|
|
1289
|
+
const str = val.toString();
|
|
1290
|
+
if (str) state.buf.push("new URLSearchParams(" + quote(str, 0) + ")");
|
|
1291
|
+
else state.buf.push("new URLSearchParams");
|
|
1292
|
+
return true;
|
|
1293
|
+
}
|
|
1294
|
+
function writeHeaders(state, val) {
|
|
1295
|
+
const headers = stringEntriesToHeadersInit(val);
|
|
1296
|
+
state.buf.push("new Headers" + (headers ? "(" + headers + ")" : ""));
|
|
1297
|
+
return true;
|
|
1298
|
+
}
|
|
1299
|
+
function writeFormData(state, val, ref) {
|
|
1300
|
+
let sep = "[";
|
|
1301
|
+
let valStr = "";
|
|
1302
|
+
for (const [key, value] of val) {
|
|
1303
|
+
if (typeof value !== "string") {
|
|
1304
|
+
throwUnserializable(state, value, ref, key);
|
|
1305
|
+
return false;
|
|
1306
|
+
}
|
|
1307
|
+
valStr += sep + quote(key, 0) + "," + quote(value, 0);
|
|
1308
|
+
sep = ",";
|
|
1309
|
+
}
|
|
1310
|
+
if (sep === "[") state.buf.push("new FormData");
|
|
1311
|
+
else state.buf.push(valStr + "].reduce((f,v,i,a)=>i%2&&f.append(a[i-1],v)||f,new FormData)");
|
|
1312
|
+
return true;
|
|
1313
|
+
}
|
|
1314
|
+
function writeRequest(state, val, ref) {
|
|
1315
|
+
let sep = "";
|
|
1316
|
+
let bodySerialized = false;
|
|
1317
|
+
const hasBody = val.body && !val.bodyUsed && val.duplex === "half";
|
|
1318
|
+
state.buf.push("new Request(" + quote(val.url, 0));
|
|
1319
|
+
if (hasBody) {
|
|
1320
|
+
state.buf.push(",{body:");
|
|
1321
|
+
if (writeProp(state, val.body, ref, "body")) {
|
|
1322
|
+
state.buf.push(",duplex:\"half\"");
|
|
1323
|
+
sep = ",";
|
|
1324
|
+
bodySerialized = true;
|
|
1325
|
+
} else state.buf.pop();
|
|
1326
|
+
}
|
|
1327
|
+
let options = "";
|
|
1328
|
+
if (val.cache !== "default") {
|
|
1329
|
+
options += sep + "cache:" + quote(val.cache, 0);
|
|
1330
|
+
sep = ",";
|
|
1331
|
+
}
|
|
1332
|
+
if (val.credentials !== "same-origin") {
|
|
1333
|
+
options += sep + "credentials:" + quote(val.credentials, 0);
|
|
1334
|
+
sep = ",";
|
|
1335
|
+
}
|
|
1336
|
+
const headers = headersOption(state, val.headers, ref);
|
|
1337
|
+
if (headers) {
|
|
1338
|
+
options += sep + "headers:" + headers;
|
|
1339
|
+
sep = ",";
|
|
1340
|
+
}
|
|
1341
|
+
if (val.integrity) {
|
|
1342
|
+
options += sep + "integrity:" + quote(val.integrity, 0);
|
|
1343
|
+
sep = ",";
|
|
1344
|
+
}
|
|
1345
|
+
if (val.keepalive) {
|
|
1346
|
+
options += sep + "keepalive:true";
|
|
1347
|
+
sep = ",";
|
|
1348
|
+
}
|
|
1349
|
+
if (val.method !== "GET") {
|
|
1350
|
+
options += sep + "method:" + quote(val.method, 0);
|
|
1351
|
+
sep = ",";
|
|
1352
|
+
}
|
|
1353
|
+
if (val.mode !== "cors") {
|
|
1354
|
+
options += sep + "mode:" + quote(val.mode, 0);
|
|
1355
|
+
sep = ",";
|
|
1356
|
+
}
|
|
1357
|
+
if (val.redirect !== "follow") {
|
|
1358
|
+
options += sep + "redirect:" + quote(val.redirect, 0);
|
|
1359
|
+
sep = ",";
|
|
1360
|
+
}
|
|
1361
|
+
if (val.referrer !== "about:client") {
|
|
1362
|
+
options += sep + "referrer:" + quote(val.referrer, 0);
|
|
1363
|
+
sep = ",";
|
|
1364
|
+
}
|
|
1365
|
+
if (val.referrerPolicy) options += sep + "referrerPolicy:" + quote(val.referrerPolicy, 0);
|
|
1366
|
+
state.buf.push(bodySerialized ? options + "})" : options ? ",{" + options + "})" : ")");
|
|
1367
|
+
return true;
|
|
1368
|
+
}
|
|
1369
|
+
function writeResponse(state, val, ref) {
|
|
1370
|
+
let sep = "";
|
|
1371
|
+
let options = "";
|
|
1372
|
+
if (val.status !== 200) {
|
|
1373
|
+
options += "status:" + val.status;
|
|
1374
|
+
sep = ",";
|
|
1375
|
+
}
|
|
1376
|
+
if (val.statusText) {
|
|
1377
|
+
options += sep + "statusText:" + quote(val.statusText, 0);
|
|
1378
|
+
sep = ",";
|
|
1379
|
+
}
|
|
1380
|
+
const headers = headersOption(state, val.headers, ref);
|
|
1381
|
+
if (headers) options += sep + "headers:" + headers;
|
|
1382
|
+
if (!val.body || val.bodyUsed) state.buf.push("new Response" + (options ? "(null,{" + options + "})" : ""));
|
|
1383
|
+
else {
|
|
1384
|
+
state.buf.push("new Response(");
|
|
1385
|
+
state.buf.push((writeProp(state, val.body, ref, "body") ? "" : "null") + (options ? ",{" + options + "})" : ")"));
|
|
1386
|
+
}
|
|
1387
|
+
return true;
|
|
1388
|
+
}
|
|
1389
|
+
function headersOption(state, headers, ref) {
|
|
1390
|
+
const seen = state.refs.get(headers);
|
|
1391
|
+
if (seen) return ensureRefAccess(state, seen);
|
|
1392
|
+
state.refs.set(headers, new Reference(ref, "headers", state.flushId, null));
|
|
1393
|
+
return stringEntriesToHeadersInit(headers);
|
|
1394
|
+
}
|
|
1395
|
+
function writeIntl(state, val, name, ref) {
|
|
1396
|
+
const { locale, ...options } = val.resolvedOptions();
|
|
1397
|
+
state.buf.push("new Intl." + name + "(" + quote(locale, 0) + ",");
|
|
1398
|
+
const optionsRef = newArgReference(state, ref, options);
|
|
1399
|
+
state.buf.push("{");
|
|
1400
|
+
writeObjectProps(state, options, optionsRef);
|
|
1401
|
+
state.buf.push("})");
|
|
1402
|
+
return true;
|
|
1403
|
+
}
|
|
1404
|
+
function writeIntlLocale(state, val) {
|
|
1405
|
+
state.buf.push("new Intl.Locale(" + quote(val.toString(), 0) + ")");
|
|
1406
|
+
return true;
|
|
1407
|
+
}
|
|
1408
|
+
function writeTemporal(state, val, name) {
|
|
1409
|
+
state.buf.push("Temporal." + name + ".from(" + quote(val.toString(), 0) + ")");
|
|
1410
|
+
return true;
|
|
1411
|
+
}
|
|
1412
|
+
function writeReadableStream(state, val, ref) {
|
|
1413
|
+
if (val.locked) {
|
|
1414
|
+
throwUnserializable(state, val, ref, "", "The ReadableStream is locked by a reader on the server; to also send it to the browser, `tee()` it (or `clone()` its `Request`/`Response`) before reading.");
|
|
1415
|
+
return false;
|
|
1416
|
+
}
|
|
1417
|
+
const { boundary, channel } = state;
|
|
1418
|
+
const reader = val.getReader();
|
|
1419
|
+
const iterId = nextRefAccess(state);
|
|
1420
|
+
const handle = newAsyncHandle(state, ref, iterId);
|
|
1421
|
+
const onFulfilled = ({ value, done }) => {
|
|
1422
|
+
if (done) queueAsyncCall(state, boundary, handle, "r", value, channel);
|
|
1423
|
+
else if (!boundary.aborted) {
|
|
1424
|
+
reader.read().then(onFulfilled, onRejected);
|
|
1425
|
+
boundary.startAsync();
|
|
1426
|
+
queueAsyncCall(state, boundary, handle, "f", value, channel);
|
|
1427
|
+
}
|
|
1428
|
+
};
|
|
1429
|
+
const onRejected = (reason) => {
|
|
1430
|
+
queueAsyncCall(state, boundary, handle, "j", reason, channel);
|
|
1431
|
+
};
|
|
1432
|
+
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))}})");
|
|
1433
|
+
reader.read().then(onFulfilled, onRejected);
|
|
1434
|
+
boundary.startAsync();
|
|
1435
|
+
return true;
|
|
1436
|
+
}
|
|
1437
|
+
function writeGenerator(state, iter, ref) {
|
|
1438
|
+
if (iter[kTouchedIterator]) {
|
|
1439
|
+
state.buf.push("(function*(){}())");
|
|
1440
|
+
return true;
|
|
1441
|
+
}
|
|
1442
|
+
const yields = [];
|
|
1443
|
+
let returnValue;
|
|
1444
|
+
let needsId;
|
|
1445
|
+
while (true) {
|
|
1446
|
+
const { value, done } = iter.next();
|
|
1447
|
+
if (done) {
|
|
1448
|
+
returnValue = value;
|
|
1449
|
+
break;
|
|
1450
|
+
}
|
|
1451
|
+
needsId ||= isReusableMember(value);
|
|
1452
|
+
yields.push(value);
|
|
1453
|
+
}
|
|
1454
|
+
if (returnValue === void 0 && !yields.length) {
|
|
1455
|
+
state.buf.push("(function*(){})()");
|
|
1456
|
+
return true;
|
|
1457
|
+
}
|
|
1458
|
+
const heldReturn = returnValue !== void 0 && isAncestorMember(state, ref, returnValue);
|
|
1459
|
+
state.buf.push(returnValue === void 0 ? "(function*(a){yield*a})(" : heldReturn ? "(function*(a,r){yield*a;return r.v})(" : "(function*(a,r){yield*a;return r})(");
|
|
1460
|
+
if (needsId) {
|
|
1461
|
+
const arrayRef = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
|
|
1462
|
+
state.buf.push(arrayRef.id + "=");
|
|
1463
|
+
writeArray(state, yields, arrayRef);
|
|
1464
|
+
} else writeArray(state, yields, new Reference(ref, null, state.flushId, state.buf.length));
|
|
1465
|
+
if (heldReturn) {
|
|
1466
|
+
const holder = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
|
|
1467
|
+
state.buf.push("," + holder.id + "={}");
|
|
1468
|
+
writeProp(state, returnValue, holder, "v");
|
|
1469
|
+
} else if (returnValue !== void 0) {
|
|
1470
|
+
state.buf.push(",");
|
|
1471
|
+
if (writeProp(state, returnValue, ref, "") && isReusableMember(returnValue)) {
|
|
1472
|
+
const retRef = typeof returnValue === "string" ? state.strs.get(returnValue) : state.refs.get(returnValue);
|
|
1473
|
+
if (retRef) ensureRefAccess(state, retRef);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
state.buf.push(")");
|
|
1477
|
+
return true;
|
|
1478
|
+
}
|
|
1479
|
+
function writeAsyncGenerator(state, iter, ref) {
|
|
1480
|
+
if (iter[kTouchedIterator]) {
|
|
1481
|
+
state.buf.push("(async function*(){}())");
|
|
1482
|
+
return true;
|
|
1483
|
+
}
|
|
1484
|
+
const { boundary, channel } = state;
|
|
1485
|
+
const iterId = nextRefAccess(state);
|
|
1486
|
+
const handle = newAsyncHandle(state, ref, iterId);
|
|
1487
|
+
const onFulfilled = ({ value, done }) => {
|
|
1488
|
+
if (done) queueAsyncCall(state, boundary, handle, "r", value, channel);
|
|
1489
|
+
else if (!boundary.aborted) {
|
|
1490
|
+
iter.next().then(onFulfilled, onRejected);
|
|
1491
|
+
boundary.startAsync();
|
|
1492
|
+
queueAsyncCall(state, boundary, handle, "f", value, channel);
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
const onRejected = (reason) => {
|
|
1496
|
+
queueAsyncCall(state, boundary, handle, "j", reason, channel);
|
|
1497
|
+
};
|
|
1498
|
+
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 + "={})");
|
|
1499
|
+
iter.next().then(onFulfilled, onRejected);
|
|
1500
|
+
boundary.startAsync();
|
|
1501
|
+
return true;
|
|
1502
|
+
}
|
|
1503
|
+
function writeNullObject(state, val, ref) {
|
|
1504
|
+
state.buf.push("{");
|
|
1505
|
+
state.buf.push(writeMaybeIterableProps(state, val, ref) + "__proto__:null}");
|
|
1506
|
+
return true;
|
|
1507
|
+
}
|
|
1508
|
+
function writeObjectProps(state, val, ref) {
|
|
1509
|
+
let sep = "";
|
|
1510
|
+
for (const key in val) if (hasOwnProperty.call(val, key)) {
|
|
1511
|
+
const escapedKey = toObjectKey(key);
|
|
1512
|
+
state.buf.push(sep + escapedKey + ":");
|
|
1513
|
+
if (writeProp(state, val[key], ref, escapedKey)) sep = ",";
|
|
1514
|
+
else state.buf.pop();
|
|
1515
|
+
}
|
|
1516
|
+
return sep;
|
|
1517
|
+
}
|
|
1518
|
+
function writeMaybeIterableProps(state, val, ref) {
|
|
1519
|
+
let sep = writeObjectProps(state, val, ref);
|
|
1520
|
+
if (hasSymbolIterator(val)) {
|
|
1521
|
+
let yieldSelf = "";
|
|
1522
|
+
const iterArr = [];
|
|
1523
|
+
for (const item of val) if (item === val && !(yieldSelf || iterArr.length)) yieldSelf = "yield this;";
|
|
1524
|
+
else iterArr.push(item);
|
|
1525
|
+
if (iterArr.length) {
|
|
1526
|
+
const iterRef = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
|
|
1527
|
+
state.buf.push(sep + "*[(" + iterRef.id + "=");
|
|
1528
|
+
writeArray(state, iterArr, iterRef);
|
|
1529
|
+
state.buf.push(",Symbol.iterator)](){" + yieldSelf + "yield*" + iterRef.id + "}");
|
|
1530
|
+
} else state.buf.push(sep + "*[Symbol.iterator](){" + yieldSelf.slice(0, -1) + "}");
|
|
1531
|
+
sep = ",";
|
|
1532
|
+
}
|
|
1533
|
+
return sep;
|
|
1534
|
+
}
|
|
1535
|
+
function queueAsyncCall(state, boundary, handle, method, value, channel, valueId = null) {
|
|
1536
|
+
if (boundary.aborted) return;
|
|
1537
|
+
(channel?.readyId ? state.queuedReadyCalls : state.queuedCalls).push({
|
|
1538
|
+
method,
|
|
1539
|
+
value,
|
|
1540
|
+
object: handle,
|
|
1541
|
+
channel,
|
|
1542
|
+
valueId
|
|
1543
|
+
});
|
|
1544
|
+
boundary.endAsync();
|
|
1545
|
+
}
|
|
1546
|
+
function throwUnserializable(state, cause, ref = null, accessor = "", hint = "Values referenced in the browser must be serializable.") {
|
|
1547
|
+
if (cause !== void 0) {
|
|
1548
|
+
let message = "Unable to serialize";
|
|
1549
|
+
let access = "";
|
|
1550
|
+
while (ref) {
|
|
1551
|
+
const { accessor } = ref;
|
|
1552
|
+
const debug = ref.parent?.debug;
|
|
1553
|
+
if (accessor && debug) {
|
|
1554
|
+
const rawAccessor = fromObjectKey(accessor);
|
|
1555
|
+
const varLoc = debug.vars?.[rawAccessor];
|
|
1556
|
+
const slotName = debug.slots?.[rawAccessor];
|
|
1557
|
+
let debugAccess = varLoc ? rawAccessor : void 0;
|
|
1558
|
+
let debugLoc = debug.loc;
|
|
1559
|
+
if (varLoc) {
|
|
1560
|
+
if (Array.isArray(varLoc)) {
|
|
1561
|
+
debugAccess = varLoc[0];
|
|
1562
|
+
if (varLoc[1]) debugLoc = varLoc[1];
|
|
1563
|
+
} else debugLoc = varLoc;
|
|
1564
|
+
}
|
|
1565
|
+
let display;
|
|
1566
|
+
if (debugAccess !== void 0) display = slotName && debugAccess.startsWith("...") ? `\`${slotName}\` from \`${debugAccess}\`` : JSON.stringify(debugAccess);
|
|
1567
|
+
else display = describeAccessor(rawAccessor, slotName) ?? JSON.stringify(rawAccessor);
|
|
1568
|
+
message += ` ${display} in ${debug.file}`;
|
|
1569
|
+
if (debugLoc) message += `:${debugLoc}`;
|
|
1570
|
+
break;
|
|
1571
|
+
}
|
|
1572
|
+
if (accessor) access = toAccess(accessor) + access;
|
|
1573
|
+
ref = ref.parent;
|
|
1574
|
+
}
|
|
1575
|
+
if (accessor) access = toAccess(accessor) + access;
|
|
1576
|
+
if (access[0] === ".") access = access.slice(1);
|
|
1577
|
+
if (access) message += ` (reading ${access})`;
|
|
1578
|
+
message += ". " + hint;
|
|
1579
|
+
const err = new TypeError(message, { cause });
|
|
1580
|
+
err.stack = void 0;
|
|
1581
|
+
abortRender(state.boundary, err);
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
const accessorPrefixDescriptions = {
|
|
1585
|
+
BranchScopes: "the branch scopes",
|
|
1586
|
+
ClosureScopes: "the closure scopes",
|
|
1587
|
+
ClosureSignalIndex: "the closure signal index",
|
|
1588
|
+
ConditionalRenderer: "the conditional renderer",
|
|
1589
|
+
ControlledObserver: "the controlled observer",
|
|
1590
|
+
ControlledHandler: "the change handler",
|
|
1591
|
+
ControlledType: "the controlled type",
|
|
1592
|
+
ControlledValue: "the controlled value",
|
|
1593
|
+
DynamicHTMLLastChild: "the dynamic html",
|
|
1594
|
+
DynamicHTMLValue: "the dynamic html value",
|
|
1595
|
+
EventAttributes: "the event handlers",
|
|
1596
|
+
IdFallback: "the generated id",
|
|
1597
|
+
KeyedScopes: "the keyed scopes",
|
|
1598
|
+
Lifecycle: "the lifecycle handlers",
|
|
1599
|
+
Promise: "the pending promise",
|
|
1600
|
+
TagVariableChange: "the tag variable change handler",
|
|
1601
|
+
TryBranch: "the try branch"
|
|
1602
|
+
};
|
|
1603
|
+
function describeAccessor(accessor, slotName) {
|
|
1604
|
+
const sep = accessor.indexOf(":");
|
|
1605
|
+
if (~sep) {
|
|
1606
|
+
const description = slotName === void 0 ? accessorPrefixDescriptions[accessor.slice(0, sep)] : `the \`${slotName}\` handler`;
|
|
1607
|
+
if (description) {
|
|
1608
|
+
const node = /^#([a-z-]+)\//i.exec(accessor.slice(sep + 1));
|
|
1609
|
+
return node ? `${description} of \`<${node[1]}>\`` : description;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
function fromObjectKey(key) {
|
|
1614
|
+
try {
|
|
1615
|
+
if (key[0] === "\"") return JSON.parse(key.replace(/\\x/g, "\\u00"));
|
|
1616
|
+
if (key[0] === "[") return JSON.parse(key.slice(1, -1));
|
|
1617
|
+
} catch {}
|
|
1618
|
+
return key;
|
|
1619
|
+
}
|
|
1620
|
+
function trackChannel(state, ref) {
|
|
1621
|
+
const refReadyId = ref.channel?.readyId;
|
|
1622
|
+
if (!refReadyId || refReadyId === state.channel?.readyId) return true;
|
|
1623
|
+
let cur = state.channel?.parent;
|
|
1624
|
+
while (cur) {
|
|
1625
|
+
if (cur.readyId === refReadyId) {
|
|
1626
|
+
(state.channelDeps ||= /* @__PURE__ */ new Set()).add(refReadyId);
|
|
1627
|
+
return true;
|
|
1628
|
+
}
|
|
1629
|
+
cur = cur.parent;
|
|
1630
|
+
}
|
|
1631
|
+
return false;
|
|
1632
|
+
}
|
|
1633
|
+
function isAncestorChannelRef(state, ref) {
|
|
1634
|
+
return ref.channel?.readyId !== state.channel?.readyId;
|
|
1635
|
+
}
|
|
1636
|
+
function abortUnreachableChannel(state, val) {
|
|
1637
|
+
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 });
|
|
1638
|
+
err.stack = void 0;
|
|
1639
|
+
abortRender(state.boundary, err);
|
|
1640
|
+
}
|
|
1641
|
+
function abortRender(boundary, err) {
|
|
1642
|
+
while (boundary.parent) boundary = boundary.parent;
|
|
1643
|
+
boundary.abort(err);
|
|
1644
|
+
}
|
|
1645
|
+
function isCircular(parent, ref) {
|
|
1646
|
+
let cur = parent;
|
|
1647
|
+
while (cur) {
|
|
1648
|
+
if (cur === ref) return true;
|
|
1649
|
+
cur = cur.parent;
|
|
1650
|
+
}
|
|
1651
|
+
return false;
|
|
1652
|
+
}
|
|
1653
|
+
function toObjectKey(name) {
|
|
1654
|
+
if (name === "") return "\"\"";
|
|
1655
|
+
if (name === "__proto__") return "[\"__proto__\"]";
|
|
1656
|
+
const len = name.length;
|
|
1657
|
+
const c0 = name.charCodeAt(0);
|
|
1658
|
+
if (c0 >= 48 && c0 <= 57) {
|
|
1659
|
+
if (c0 === 48) {
|
|
1660
|
+
if (len !== 1) return quote(name, 1);
|
|
1661
|
+
} else {
|
|
1662
|
+
for (let i = 1; i < len; i++) {
|
|
1663
|
+
const c = name.charCodeAt(i);
|
|
1664
|
+
if (c < 48 || c > 57) return quote(name, i);
|
|
1665
|
+
}
|
|
1666
|
+
if (len > 15 && "" + +name !== name) return quote(name, 0);
|
|
1667
|
+
}
|
|
1668
|
+
} else if (c0 >= 97 && c0 <= 122 || c0 >= 65 && c0 <= 90 || c0 === 95 || c0 === 36) for (let i = 1; i < len; i++) {
|
|
1669
|
+
const c = name.charCodeAt(i);
|
|
1670
|
+
if (!(c >= 97 && c <= 122 || c >= 65 && c <= 90 || c >= 48 && c <= 57 || c === 95 || c === 36)) return quote(name, i);
|
|
1671
|
+
}
|
|
1672
|
+
else return quote(name, 0);
|
|
1673
|
+
return name;
|
|
1674
|
+
}
|
|
1675
|
+
function toAccess(accessor) {
|
|
1676
|
+
const start = accessor[0];
|
|
1677
|
+
return start === "[" ? accessor : start === "\"" || start >= "0" && start <= "9" ? "[" + accessor + "]" : "." + accessor;
|
|
1678
|
+
}
|
|
1679
|
+
const unsafeQuoteReg = /["\\<\n\r\u2028\u2029\0\ud800-\udfff]/u;
|
|
1680
|
+
function quote(str, startPos) {
|
|
1681
|
+
if (!unsafeQuoteReg.test(str)) return "\"" + str + "\"";
|
|
1682
|
+
let result = "";
|
|
1683
|
+
let lastPos = 0;
|
|
1684
|
+
for (let i = startPos; i < str.length; i++) {
|
|
1685
|
+
let replacement;
|
|
1686
|
+
const code = str.charCodeAt(i);
|
|
1687
|
+
switch (code) {
|
|
1688
|
+
case 34:
|
|
1689
|
+
replacement = "\\\"";
|
|
1690
|
+
break;
|
|
1691
|
+
case 92:
|
|
1692
|
+
replacement = "\\\\";
|
|
1693
|
+
break;
|
|
1694
|
+
case 60:
|
|
1695
|
+
replacement = "\\x3C";
|
|
1696
|
+
break;
|
|
1697
|
+
case 10:
|
|
1698
|
+
replacement = "\\n";
|
|
1699
|
+
break;
|
|
1700
|
+
case 13:
|
|
1701
|
+
replacement = "\\r";
|
|
1702
|
+
break;
|
|
1703
|
+
case 8232:
|
|
1704
|
+
replacement = "\\u2028";
|
|
1705
|
+
break;
|
|
1706
|
+
case 8233:
|
|
1707
|
+
replacement = "\\u2029";
|
|
1708
|
+
break;
|
|
1709
|
+
case 0:
|
|
1710
|
+
replacement = "\\x00";
|
|
1711
|
+
break;
|
|
1712
|
+
default:
|
|
1713
|
+
if (code < 55296 || code > 57343) continue;
|
|
1714
|
+
if (code < 56320) {
|
|
1715
|
+
const next = str.charCodeAt(i + 1);
|
|
1716
|
+
if (next >= 56320 && next <= 57343) {
|
|
1717
|
+
i++;
|
|
1718
|
+
continue;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
replacement = "\\u" + code.toString(16);
|
|
1722
|
+
}
|
|
1723
|
+
result += str.slice(lastPos, i) + replacement;
|
|
1724
|
+
lastPos = i + 1;
|
|
1725
|
+
}
|
|
1726
|
+
return "\"" + (lastPos === startPos ? str : result + str.slice(lastPos)) + "\"";
|
|
1727
|
+
}
|
|
1728
|
+
function writeRef(state, ref) {
|
|
1729
|
+
if (ref.id === null && ref.scopeId === void 0 && ref.path === null && (ref.pos === null || ref.flushId !== state.flushId) && !isAncestorChannelRef(state, ref)) {
|
|
1730
|
+
ref.path = accessPath(state, ref);
|
|
1731
|
+
ref.pos = state.buf.length;
|
|
1732
|
+
ref.flushId = state.flushId;
|
|
1733
|
+
state.buf.push(ref.path);
|
|
1734
|
+
} else state.buf.push(ensureRefAccess(state, ref));
|
|
1735
|
+
}
|
|
1736
|
+
function ensureRefAccess(state, ref) {
|
|
1737
|
+
if (ref.scopeId !== void 0) {
|
|
1738
|
+
trackChannel(state, ref);
|
|
1739
|
+
return "_(" + ref.scopeId + ")";
|
|
1740
|
+
}
|
|
1741
|
+
if (ref.id) {
|
|
1742
|
+
trackChannel(state, ref);
|
|
1743
|
+
return ref.id;
|
|
1744
|
+
}
|
|
1745
|
+
return claimRefAccess(state, ref);
|
|
1746
|
+
}
|
|
1747
|
+
function accessId(state, ref) {
|
|
1748
|
+
const id = ensureRefAccess(state, ref);
|
|
1749
|
+
return id === ref.id || ref.scopeId !== void 0 ? id : "(" + id + ")";
|
|
1750
|
+
}
|
|
1751
|
+
function claimRefAccess(state, ref) {
|
|
1752
|
+
const { pos } = ref;
|
|
1753
|
+
if (pos !== null && ref.flushId === state.flushId) {
|
|
1754
|
+
ref.id = nextRefAccess(state);
|
|
1755
|
+
if (pos === 0) state.buf[0] = ref.id + "=" + state.buf[0];
|
|
1756
|
+
else state.buf[pos - 1] += ref.id + "=";
|
|
1757
|
+
return ref.id;
|
|
1758
|
+
}
|
|
1759
|
+
if (isAncestorChannelRef(state, ref)) return ref.path || accessPath(state, ref);
|
|
1760
|
+
ref.id = nextRefAccess(state);
|
|
1761
|
+
return ref.id + "=" + (ref.path || accessPath(state, ref));
|
|
1762
|
+
}
|
|
1763
|
+
function accessPath(state, ref) {
|
|
1764
|
+
let cur = ref;
|
|
1765
|
+
let accessPrevValue = "";
|
|
1766
|
+
do {
|
|
1767
|
+
if (cur.accessor === null) throw new Error("Unable to serialize a reused value: no access path reaches where it was first written, and it has no id.");
|
|
1768
|
+
accessPrevValue = toAccess(cur.accessor) + accessPrevValue;
|
|
1769
|
+
const parent = cur.parent;
|
|
1770
|
+
if (parent.id) {
|
|
1771
|
+
trackChannel(state, parent);
|
|
1772
|
+
return parent.id + accessPrevValue;
|
|
1773
|
+
}
|
|
1774
|
+
if (parent.flushId === state.flushId || parent.scopeId !== void 0) return accessId(state, parent) + accessPrevValue;
|
|
1775
|
+
cur = parent;
|
|
1776
|
+
} while (cur);
|
|
1777
|
+
return accessPrevValue;
|
|
1778
|
+
}
|
|
1779
|
+
function assignmentsToString(assignments, value) {
|
|
1780
|
+
if (assignments.length > 100) return "($=>(" + assignments.join("=$,") + "=$))(" + value + ")";
|
|
1781
|
+
return assignments.join("=") + "=" + value;
|
|
1782
|
+
}
|
|
1783
|
+
function addAssignment(ref, assign) {
|
|
1784
|
+
if (ref.assignments) ref.assignments.push(assign);
|
|
1785
|
+
else ref.assignments = [assign];
|
|
1786
|
+
}
|
|
1787
|
+
function nextRefAccess(state) {
|
|
1788
|
+
return "_." + nextId(state);
|
|
1789
|
+
}
|
|
1790
|
+
function nextId(state) {
|
|
1791
|
+
const c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789";
|
|
1792
|
+
let n = state.ids++;
|
|
1793
|
+
let r = c[n % 53];
|
|
1794
|
+
for (n = n / 53 | 0; n; n >>>= 6) r += c[n & 63];
|
|
1795
|
+
return r === "name" ? nextId(state) : r;
|
|
1796
|
+
}
|
|
1797
|
+
function hasSymbolIterator(value) {
|
|
1798
|
+
return Symbol.iterator in value;
|
|
1799
|
+
}
|
|
1800
|
+
function stringEntriesToHeadersInit(entries) {
|
|
1801
|
+
const list = [...entries];
|
|
1802
|
+
if (!list.length) return "";
|
|
1803
|
+
let duplicate = false;
|
|
1804
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1805
|
+
for (const [key] of list) {
|
|
1806
|
+
if (seen.has(key)) {
|
|
1807
|
+
duplicate = true;
|
|
1808
|
+
break;
|
|
1809
|
+
}
|
|
1810
|
+
seen.add(key);
|
|
1811
|
+
}
|
|
1812
|
+
let result = "";
|
|
1813
|
+
let sep = "";
|
|
1814
|
+
for (const [key, value] of list) {
|
|
1815
|
+
result += duplicate ? sep + "[" + quote(key, 0) + "," + quote(value, 0) + "]" : sep + toObjectKey(key) + ":" + quote(value, 0);
|
|
1816
|
+
sep = ",";
|
|
1817
|
+
}
|
|
1818
|
+
return duplicate ? "[" + result + "]" : "{" + result + "}";
|
|
1819
|
+
}
|
|
1820
|
+
function typedArrayToInitString(view) {
|
|
1821
|
+
const suffix = typeof view[0] === "bigint" ? "n" : "";
|
|
1822
|
+
let result = "[";
|
|
1823
|
+
let sep = "";
|
|
1824
|
+
for (let i = 0; i < view.length; i++) {
|
|
1825
|
+
result += sep + view[i] + suffix;
|
|
1826
|
+
sep = ",";
|
|
1827
|
+
}
|
|
1828
|
+
result += "]";
|
|
1829
|
+
return result;
|
|
1830
|
+
}
|
|
1831
|
+
function hasOnlyZeros(typedArray) {
|
|
1832
|
+
const zero = typeof typedArray[0] === "bigint" ? 0n : 0;
|
|
1833
|
+
for (let i = 0; i < typedArray.length; i++) if (typedArray[i] !== zero) return false;
|
|
1834
|
+
return true;
|
|
1835
|
+
}
|
|
1836
|
+
function patchIteratorNext(proto) {
|
|
1837
|
+
if (proto.next[kTouchedIterator]) return;
|
|
1838
|
+
const { next } = proto;
|
|
1839
|
+
proto.next = function(value) {
|
|
1840
|
+
this[kTouchedIterator] = 1;
|
|
1841
|
+
return next.call(this, value);
|
|
1842
|
+
};
|
|
1843
|
+
proto.next[kTouchedIterator] = true;
|
|
1844
|
+
}
|
|
1845
|
+
// src/html/attrs.ts
|
|
1846
|
+
function _attr_class(value) {
|
|
1847
|
+
return stringAttr("class", toDelimitedString(value, " ", stringifyClassEntry));
|
|
1848
|
+
}
|
|
1849
|
+
function _attr_style(value) {
|
|
1850
|
+
return stringAttr("style", toDelimitedString(value, ";", stringifyStyleEntry));
|
|
1851
|
+
}
|
|
1852
|
+
function _attr_option_value(value) {
|
|
1853
|
+
const valueAttr = _attr("value", value);
|
|
1854
|
+
const selectedValue = getContext(kSelectedValue);
|
|
1855
|
+
if (selectedValue !== void 0 && normalizedValueMatches(selectedValue, value)) {
|
|
1856
|
+
getContext(kSelectedValueMatched)?.add(normalizeStrAttrValue(value));
|
|
1857
|
+
return valueAttr + " selected";
|
|
1858
|
+
}
|
|
1859
|
+
return valueAttr;
|
|
1860
|
+
}
|
|
1861
|
+
const kSelectedValue = Symbol("selectedValue");
|
|
1862
|
+
const kSelectedValueMatched = Symbol("selectedValueMatched");
|
|
1863
|
+
function _attr_select_value(scopeId, nodeAccessor, value, valueChange, content, serializeType) {
|
|
1864
|
+
if (valueChange) writeControlledScope(3, scopeId, nodeAccessor, void 0, valueChange, serializeType);
|
|
1865
|
+
if (content) {
|
|
1866
|
+
const selectedValue = value ?? "";
|
|
1867
|
+
if (valueChange) {
|
|
1868
|
+
const matched = /* @__PURE__ */ new Set();
|
|
1869
|
+
withContext(kSelectedValue, selectedValue, () => withContext(kSelectedValueMatched, matched, content));
|
|
1870
|
+
if ((Array.isArray(value) ? value : [value]).some((v) => {
|
|
1871
|
+
const str = normalizeStrAttrValue(v);
|
|
1872
|
+
return str !== "" && !matched.has(str);
|
|
1873
|
+
})) console.error("A controlled `<select>`'s `value` has no matching `<option>`:", value);
|
|
1874
|
+
} else withContext(kSelectedValue, selectedValue, content);
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
function _attrs_select_value(scopeId, nodeAccessor, data, content) {
|
|
1878
|
+
if (data && ("value" in data || data.valueChange)) _attr_select_value(scopeId, nodeAccessor, data.value, data.valueChange, content, 1);
|
|
1879
|
+
else content();
|
|
1880
|
+
}
|
|
1881
|
+
function _attr_textarea_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
|
|
1882
|
+
if (valueChange) writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType);
|
|
1883
|
+
return _textarea_value(value);
|
|
1884
|
+
}
|
|
1885
|
+
function _attrs_textarea_value(scopeId, nodeAccessor, data) {
|
|
1886
|
+
return _attr_textarea_value(scopeId, nodeAccessor, data?.value, data?.valueChange, 1);
|
|
1887
|
+
}
|
|
1888
|
+
function _textarea_value(value) {
|
|
1889
|
+
const escaped = _escape(normalizeStrAttrValue(value));
|
|
1890
|
+
return escaped[0] === "\n" ? "\n" + escaped : escaped;
|
|
1891
|
+
}
|
|
1892
|
+
function _attr_input_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
|
|
1893
|
+
if (valueChange) writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType);
|
|
1894
|
+
return _attr("value", value);
|
|
1895
|
+
}
|
|
1896
|
+
function _attr_input_checked(scopeId, nodeAccessor, checked, checkedChange, serializeType) {
|
|
1897
|
+
if (checkedChange) writeControlledScope(0, scopeId, nodeAccessor, void 0, checkedChange, serializeType);
|
|
1898
|
+
return isNotNullishOrFalse(checked) ? " checked" : "";
|
|
1899
|
+
}
|
|
1900
|
+
function _attr_input_checkedValue(scopeId, nodeAccessor, checkedValue, checkedValueChange, value, serializeType) {
|
|
1901
|
+
const valueAttr = _attr("value", value);
|
|
1902
|
+
if (checkedValueChange) writeControlledScope(1, scopeId, nodeAccessor, getCheckedValueRef(checkedValue), checkedValueChange, serializeType);
|
|
1903
|
+
return normalizedValueMatches(checkedValue, value) ? valueAttr + " checked" : valueAttr;
|
|
1904
|
+
}
|
|
1905
|
+
const checkedValuesRefs = /* @__PURE__ */ new WeakMap();
|
|
1906
|
+
function getCheckedValueRef(checkedValue) {
|
|
1907
|
+
if (Array.isArray(checkedValue)) {
|
|
1908
|
+
let ref = checkedValuesRefs.get(checkedValue);
|
|
1909
|
+
if (!ref) {
|
|
1910
|
+
ref = [];
|
|
1911
|
+
checkedValuesRefs.set(checkedValue, ref);
|
|
1912
|
+
}
|
|
1913
|
+
return ref;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange, serializeType) {
|
|
1917
|
+
const normalizedOpen = isNotNullishOrFalse(open);
|
|
1918
|
+
if (openChange) writeControlledScope(4, scopeId, nodeAccessor, normalizedOpen || void 0, openChange, serializeType);
|
|
1919
|
+
return normalizedOpen ? " open" : "";
|
|
1920
|
+
}
|
|
1921
|
+
function _attr_nonce() {
|
|
1922
|
+
return getState().nonceAttr;
|
|
1923
|
+
}
|
|
1924
|
+
function _style_html(decls) {
|
|
1925
|
+
const id = _id();
|
|
1926
|
+
return `<style${_attr_nonce()} class=${id}>.${id}~*{${decls}}</style>`;
|
|
1927
|
+
}
|
|
1928
|
+
function _attr(name, value) {
|
|
1929
|
+
return isNullishOrFalse(value) ? "" : stringifyAttr(name, value);
|
|
1930
|
+
}
|
|
1931
|
+
function _attr_and(name, value, attr) {
|
|
1932
|
+
return value ? attr : _attr(name, value);
|
|
1933
|
+
}
|
|
1934
|
+
function _attr_or(name, value, attr) {
|
|
1935
|
+
return value ? _attr(name, value) : attr;
|
|
1936
|
+
}
|
|
1937
|
+
function _attr_nullish(name, value, attr) {
|
|
1938
|
+
return value == null ? attr : _attr(name, value);
|
|
1939
|
+
}
|
|
1940
|
+
function _attrs(data, nodeAccessor, scopeId, tagName) {
|
|
1941
|
+
let result = "";
|
|
1942
|
+
let skip = /[\s/>"'=]/;
|
|
1943
|
+
let events;
|
|
1944
|
+
switch (data && tagName) {
|
|
1945
|
+
case "input":
|
|
1946
|
+
assertExclusiveAttrs(data);
|
|
1947
|
+
if (data.checkedChange) {
|
|
1948
|
+
result += _attr_input_checked(scopeId, nodeAccessor, data.checked, data.checkedChange, 1);
|
|
1949
|
+
skip = /^checked(?:Value)?(?:Change)?$|[\s/>"'=]/;
|
|
1950
|
+
} else if ("checkedValue" in data || data.checkedValueChange) {
|
|
1951
|
+
result += _attr_input_checkedValue(scopeId, nodeAccessor, data.checkedValue, data.checkedValueChange, data.value, 1);
|
|
1952
|
+
skip = /^(?:value|checked(?:Value)?)(?:Change)?$|[\s/>"'=]/;
|
|
1953
|
+
} else if (data.valueChange) {
|
|
1954
|
+
assertNoValueBindingOnCheckable(data.type, data.valueChange);
|
|
1955
|
+
result += _attr_input_value(scopeId, nodeAccessor, data.value, data.valueChange, 1);
|
|
1956
|
+
skip = /^value(?:Change)?$|[\s/>"'=]/;
|
|
1957
|
+
}
|
|
1958
|
+
break;
|
|
1959
|
+
case "select":
|
|
1960
|
+
case "textarea":
|
|
1961
|
+
if ("value" in data || data.valueChange) skip = /^value(?:Change)?$|[\s/>"'=]/;
|
|
1962
|
+
break;
|
|
1963
|
+
case "option":
|
|
1964
|
+
if ("value" in data) {
|
|
1965
|
+
result += _attr_option_value(data.value);
|
|
1966
|
+
skip = /^value$|[\s/>"'=]/;
|
|
1967
|
+
}
|
|
1968
|
+
break;
|
|
1969
|
+
case "details":
|
|
1970
|
+
case "dialog": if (data.openChange) {
|
|
1971
|
+
result += _attr_details_or_dialog_open(scopeId, nodeAccessor, data.open, data.openChange, 1);
|
|
1972
|
+
skip = /^open(?:Change)?$|[\s/>"'=]/;
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
for (const name in data) {
|
|
1976
|
+
const value = data[name];
|
|
1977
|
+
switch (name) {
|
|
1978
|
+
case "class":
|
|
1979
|
+
result += _attr_class(value);
|
|
1980
|
+
break;
|
|
1981
|
+
case "style":
|
|
1982
|
+
result += _attr_style(value);
|
|
1983
|
+
break;
|
|
1984
|
+
default:
|
|
1985
|
+
if (name) assertValidAttrName(name);
|
|
1986
|
+
if (name && !(isNullishOrFalse(value) || name === "content" && tagName !== "meta" || skip.test(name))) {
|
|
1987
|
+
if (isEventHandler(name)) {
|
|
1988
|
+
if (!events) {
|
|
1989
|
+
events = {};
|
|
1990
|
+
writeScope(scopeId, { [EventAttributes + nodeAccessor]: events });
|
|
1991
|
+
}
|
|
1992
|
+
events[getEventType(name)] = value;
|
|
1993
|
+
} else result += stringifyAttr(name, value);
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
return result;
|
|
1998
|
+
}
|
|
1999
|
+
function _attrs_content(data, nodeAccessor, scopeId, tagName, markerGuard) {
|
|
2000
|
+
_html(`${_attrs(data, nodeAccessor, scopeId, tagName)}>`);
|
|
2001
|
+
_attr_content(nodeAccessor, scopeId, data?.content, markerGuard);
|
|
2002
|
+
}
|
|
2003
|
+
function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
|
|
2004
|
+
const partial = {};
|
|
2005
|
+
for (const name in data) {
|
|
2006
|
+
const key = isEventHandler(name) ? `on-${getEventType(name)}` : name;
|
|
2007
|
+
if (!skip[key]) partial[key] = data[name];
|
|
2008
|
+
}
|
|
2009
|
+
assertExclusiveAttrs({
|
|
2010
|
+
...data,
|
|
2011
|
+
...skip
|
|
2012
|
+
});
|
|
2013
|
+
return _attrs(partial, nodeAccessor, scopeId, tagName);
|
|
2014
|
+
}
|
|
2015
|
+
function _attrs_partial_content(data, skip, nodeAccessor, scopeId, tagName, markerGuard) {
|
|
2016
|
+
_html(`${_attrs_partial(data, skip, nodeAccessor, scopeId, tagName)}>`);
|
|
2017
|
+
_attr_content(nodeAccessor, scopeId, data?.content, markerGuard);
|
|
2018
|
+
}
|
|
2019
|
+
function writeControlledScope(type, scopeId, nodeAccessor, value, valueChange, serializeType) {
|
|
2020
|
+
var handlerName = [
|
|
2021
|
+
"checkedChange",
|
|
2022
|
+
"checkedValueChange",
|
|
2023
|
+
"valueChange",
|
|
2024
|
+
"valueChange",
|
|
2025
|
+
"openChange"
|
|
2026
|
+
][type];
|
|
2027
|
+
assertHandlerIsFunction(handlerName, valueChange);
|
|
2028
|
+
setDebugSlotName(writeScope(scopeId, serializeType ? {
|
|
2029
|
+
[ControlledType + nodeAccessor]: type,
|
|
2030
|
+
[ControlledValue + nodeAccessor]: value,
|
|
2031
|
+
[ControlledHandler + nodeAccessor]: valueChange
|
|
2032
|
+
} : {
|
|
2033
|
+
[ControlledValue + nodeAccessor]: value,
|
|
2034
|
+
[ControlledHandler + nodeAccessor]: valueChange
|
|
2035
|
+
}), ControlledHandler + nodeAccessor, handlerName);
|
|
2036
|
+
}
|
|
2037
|
+
function stringAttr(name, value) {
|
|
2038
|
+
return value && " " + name + attrAssignment(value);
|
|
2039
|
+
}
|
|
2040
|
+
function stringifyAttr(name, value) {
|
|
2041
|
+
assertValidAttrValue(name, value);
|
|
2042
|
+
switch (typeof value) {
|
|
2043
|
+
case "string": return " " + name + attrAssignment(value);
|
|
2044
|
+
case "boolean": return " " + name;
|
|
2045
|
+
case "number": return " " + name + "=" + value;
|
|
2046
|
+
}
|
|
2047
|
+
return " " + name + attrAssignment(value + "");
|
|
2048
|
+
}
|
|
2049
|
+
const singleQuoteAttrReplacements = /['\r]|&(?=[#a-zA-Z])/g;
|
|
2050
|
+
const doubleQuoteAttrReplacements = /["\r]|&(?=[#a-zA-Z])/g;
|
|
2051
|
+
const needsQuotedAttr = /["'>\s]|&[#a-zA-Z]|\/$/g;
|
|
2052
|
+
function attrAssignment(value) {
|
|
2053
|
+
return value ? needsQuotedAttr.test(value) ? value[needsQuotedAttr.lastIndex - 1] === (needsQuotedAttr.lastIndex = 0, "\"") ? "='" + escapeSingleQuotedAttrValue(value) + "'" : "=\"" + escapeDoubleQuotedAttrValue(value) + "\"" : "=" + value : "";
|
|
2054
|
+
}
|
|
2055
|
+
function escapeSingleQuotedAttrValue(value) {
|
|
2056
|
+
return singleQuoteAttrReplacements.test(value) ? value.replace(singleQuoteAttrReplacements, replaceUnsafeSingleQuoteAttrChar) : value;
|
|
2057
|
+
}
|
|
2058
|
+
function replaceUnsafeSingleQuoteAttrChar(match) {
|
|
2059
|
+
return match === "'" ? "'" : match === "\r" ? " " : "&";
|
|
2060
|
+
}
|
|
2061
|
+
function escapeDoubleQuotedAttrValue(value) {
|
|
2062
|
+
return doubleQuoteAttrReplacements.test(value) ? value.replace(doubleQuoteAttrReplacements, replaceUnsafeDoubleQuoteAttrChar) : value;
|
|
2063
|
+
}
|
|
2064
|
+
function replaceUnsafeDoubleQuoteAttrChar(match) {
|
|
2065
|
+
return match === "\"" ? """ : match === "\r" ? " " : "&";
|
|
2066
|
+
}
|
|
2067
|
+
function normalizedValueMatches(a, b) {
|
|
2068
|
+
const value = normalizeStrAttrValue(b);
|
|
2069
|
+
if (Array.isArray(a)) {
|
|
2070
|
+
for (const item of a) if (normalizeStrAttrValue(item) === value) return true;
|
|
2071
|
+
} else if (normalizeStrAttrValue(a) === value) return true;
|
|
2072
|
+
return false;
|
|
2073
|
+
}
|
|
2074
|
+
function normalizeStrAttrValue(value) {
|
|
2075
|
+
return isNotNullishOrFalse(value) && value !== true ? value + "" : "";
|
|
2076
|
+
}
|
|
2077
|
+
// src/html/inlined-runtimes.debug.ts
|
|
2078
|
+
const WALKER_RUNTIME_CODE = `((runtimeId) => (self[runtimeId] ||= (
|
|
2079
|
+
renderId,
|
|
2080
|
+
prefix = runtimeId + renderId,
|
|
2081
|
+
prefixLen = prefix.length,
|
|
2082
|
+
lookup = {},
|
|
2083
|
+
visits = [],
|
|
2084
|
+
doc = document,
|
|
2085
|
+
walker = doc.createTreeWalker(
|
|
2086
|
+
doc,
|
|
2087
|
+
129 /* NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_ELEMENT */,
|
|
2088
|
+
),
|
|
2089
|
+
) =>
|
|
2090
|
+
doc = (self[runtimeId][renderId] = {
|
|
2091
|
+
i: prefix,
|
|
2092
|
+
l: lookup,
|
|
2093
|
+
v: visits,
|
|
2094
|
+
x() {},
|
|
2095
|
+
w(node, op, id) {
|
|
2096
|
+
while ((node = walker.nextNode())) {
|
|
2097
|
+
// Only reorder markers ("#", "!") are ever looked up, so only they are
|
|
2098
|
+
// kept: the lookup lives as long as the page, and every node marker
|
|
2099
|
+
// would otherwise stay referenced in it after resume consumed it.
|
|
2100
|
+
doc.x(
|
|
2101
|
+
(op =
|
|
2102
|
+
(op = node.data) &&
|
|
2103
|
+
!op.indexOf(prefix) &&
|
|
2104
|
+
((id = op.slice(prefixLen + 1)),
|
|
2105
|
+
(op = op[prefixLen]) > "#" || (lookup[id] = node),
|
|
2106
|
+
op)),
|
|
2107
|
+
id,
|
|
2108
|
+
node,
|
|
2109
|
+
);
|
|
2110
|
+
|
|
2111
|
+
if (op > "#") {
|
|
2112
|
+
visits.push(node);
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
},
|
|
2116
|
+
})
|
|
2117
|
+
, self[runtimeId]))`;
|
|
2118
|
+
const REORDER_RUNTIME_CODE = `((runtime) => {
|
|
2119
|
+
if (runtime.j) return;
|
|
2120
|
+
let onNextSibling,
|
|
2121
|
+
placeholder,
|
|
2122
|
+
nextSibling,
|
|
2123
|
+
placeholders = runtime.p = {},
|
|
2124
|
+
replace = (id, container) => runtime.l[id].replaceWith(...container.childNodes);
|
|
2125
|
+
runtime.j = {};
|
|
2126
|
+
runtime.x = (op, id, node, placeholderRoot, placeholderCb) => {
|
|
2127
|
+
if (node == nextSibling) {
|
|
2128
|
+
onNextSibling();
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
if (op == "#") {
|
|
2132
|
+
(placeholders[id] = placeholder).i++;
|
|
2133
|
+
} else if (node.tagName == "T" && (id = node.getAttribute(runtime.i))) {
|
|
2134
|
+
nextSibling = node.nextSibling;
|
|
2135
|
+
onNextSibling = (_) => {
|
|
2136
|
+
node.remove();
|
|
2137
|
+
placeholderRoot || replace(id, node);
|
|
2138
|
+
placeholder.c();
|
|
2139
|
+
};
|
|
2140
|
+
placeholder =
|
|
2141
|
+
placeholders[id] ||
|
|
2142
|
+
(placeholderRoot = placeholders[id] =
|
|
2143
|
+
{
|
|
2144
|
+
// The writer streams a reorder only after its markers.
|
|
2145
|
+
i: 1,
|
|
2146
|
+
r: id,
|
|
2147
|
+
// Resume may still walk markers inside the dropped placeholder, so
|
|
2148
|
+
// park it in any detached parent (a bare <t> clone is the cheapest).
|
|
2149
|
+
c(start = runtime.l["^" + id], removed = node.cloneNode()) {
|
|
2150
|
+
if (--placeholderRoot.i) return 1;
|
|
2151
|
+
for (
|
|
2152
|
+
;
|
|
2153
|
+
removed.prepend(
|
|
2154
|
+
(nextSibling = runtime.l[id].previousSibling || start),
|
|
2155
|
+
),
|
|
2156
|
+
start != nextSibling;
|
|
2157
|
+
|
|
2158
|
+
);
|
|
2159
|
+
replace(id, node);
|
|
2160
|
+
},
|
|
2161
|
+
});
|
|
2162
|
+
// Opens the chunk's visits for resume to parent to the root's branch; the
|
|
2163
|
+
// walk that this chunk's own script triggers closes it.
|
|
2164
|
+
runtime.v.push({ data: runtime.i + "*" + placeholder.r });
|
|
2165
|
+
// repurpose "op" for callbacks ...carefully
|
|
2166
|
+
if ((op = runtime.j[id])) {
|
|
2167
|
+
placeholderCb = placeholder.c;
|
|
2168
|
+
placeholder.c = (_) => placeholderCb() || op(runtime.r);
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
};
|
|
2172
|
+
})`;
|
|
2173
|
+
// src/html/writer.ts
|
|
2174
|
+
let $chunk;
|
|
2175
|
+
function getChunk() {
|
|
2176
|
+
return $chunk;
|
|
2177
|
+
}
|
|
2178
|
+
function withChunk(chunk, cb) {
|
|
2179
|
+
const prev = $chunk;
|
|
2180
|
+
$chunk = chunk;
|
|
2181
|
+
try {
|
|
2182
|
+
return cb();
|
|
2183
|
+
} finally {
|
|
2184
|
+
$chunk = prev;
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
function getContext(key) {
|
|
2188
|
+
return $chunk.context?.[key];
|
|
2189
|
+
}
|
|
2190
|
+
function getState() {
|
|
2191
|
+
return $chunk.boundary.state;
|
|
2192
|
+
}
|
|
2193
|
+
function rendererKey(renderer) {
|
|
2194
|
+
return renderer?.["owner"] === void 0 ? renderer?.["id"] || renderer : renderer["id"] + " " + renderer[Owner];
|
|
2195
|
+
}
|
|
2196
|
+
function getScopeId(scope) {
|
|
2197
|
+
return scope[K_SCOPE_ID];
|
|
2198
|
+
}
|
|
2199
|
+
function getScopeById(scopeId) {
|
|
2200
|
+
return $chunk.boundary.state.scopes.get(scopeId);
|
|
2201
|
+
}
|
|
2202
|
+
function $global() {
|
|
2203
|
+
return $chunk.boundary.state.$global;
|
|
2204
|
+
}
|
|
2205
|
+
function _id() {
|
|
2206
|
+
const state = $chunk.boundary.state;
|
|
2207
|
+
const { $global } = state;
|
|
2208
|
+
return "s" + $global.runtimeId + $global.renderId + (state.tagId++).toString(36);
|
|
2209
|
+
}
|
|
2210
|
+
function _scope_id() {
|
|
2211
|
+
return $chunk.boundary.state.scopeId++;
|
|
2212
|
+
}
|
|
2213
|
+
function _peek_scope_id() {
|
|
2214
|
+
return $chunk.boundary.state.scopeId;
|
|
2215
|
+
}
|
|
2216
|
+
const kPendingContexts = Symbol("Pending Contexts");
|
|
2217
|
+
function withContext(key, value, cb, cbValue, cbValue2) {
|
|
2218
|
+
const ctx = $chunk.context ||= { [kPendingContexts]: 0 };
|
|
2219
|
+
const prev = ctx[key];
|
|
2220
|
+
ctx[kPendingContexts]++;
|
|
2221
|
+
ctx[key] = value;
|
|
2222
|
+
try {
|
|
2223
|
+
return cb(cbValue, cbValue2);
|
|
2224
|
+
} finally {
|
|
2225
|
+
ctx[kPendingContexts]--;
|
|
2226
|
+
ctx[key] = prev;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
function captureContext(chunk) {
|
|
2230
|
+
if (chunk.context?.[kPendingContexts]) chunk.context = {
|
|
2231
|
+
...chunk.context,
|
|
2232
|
+
[kPendingContexts]: 0
|
|
2233
|
+
};
|
|
2234
|
+
}
|
|
2235
|
+
const kBranchId = Symbol("Branch Id");
|
|
2236
|
+
const kAsyncContent = Symbol("Async Content");
|
|
2237
|
+
function isInResumedBranch() {
|
|
2238
|
+
return $chunk?.context?.[kBranchId] !== void 0;
|
|
2239
|
+
}
|
|
2240
|
+
function withBranchId(branchId, cb, cbValue, cbValue2) {
|
|
2241
|
+
return withContext(kBranchId, branchId, cb, cbValue, cbValue2);
|
|
2242
|
+
}
|
|
2243
|
+
function withAsyncContent(async, cb, value) {
|
|
2244
|
+
return withContext(kAsyncContent, async, cb, value);
|
|
2245
|
+
}
|
|
2246
|
+
function _html(html) {
|
|
2247
|
+
$chunk.writeHTML(html);
|
|
2248
|
+
}
|
|
2249
|
+
function writeScript(script) {
|
|
2250
|
+
$chunk.writeScript(script);
|
|
2251
|
+
}
|
|
2252
|
+
function catchableBoundary() {
|
|
2253
|
+
const { boundary } = $chunk;
|
|
2254
|
+
return boundary.withinCatch ? boundary : null;
|
|
2255
|
+
}
|
|
2256
|
+
function mayDrop(written) {
|
|
2257
|
+
const { boundary } = $chunk;
|
|
2258
|
+
for (let cur = written; cur && !isWithin(boundary, cur); cur = cur.parent) if (cur.aborted || cur.count) return true;
|
|
2259
|
+
return false;
|
|
2260
|
+
}
|
|
2261
|
+
function _script(scopeId, registryId, markerGuard) {
|
|
2262
|
+
if (markerGuard === 0 && ($chunk.channel.readyId || getAsyncContent($chunk))) _resume_branch(scopeId);
|
|
2263
|
+
$chunk.boundary.state.queueEffect(scopeId, registryId);
|
|
2264
|
+
}
|
|
2265
|
+
function _trailers(html) {
|
|
2266
|
+
$chunk.boundary.state.trailerHTML += html;
|
|
2267
|
+
}
|
|
2268
|
+
function _resume(val, id, scopeId, locals) {
|
|
2269
|
+
return register(id, val, scopeId === void 0 ? void 0 : _scope_with_id(scopeId), locals);
|
|
2270
|
+
}
|
|
2271
|
+
function _resume_locals(val, id, locals, ownerScopeId) {
|
|
2272
|
+
if (ownerScopeId !== void 0) locals["_"] = _scope_with_id(ownerScopeId);
|
|
2273
|
+
return register(id, val, writeScope(_scope_id(), locals));
|
|
2274
|
+
}
|
|
2275
|
+
function _el(scopeId, id) {
|
|
2276
|
+
return _resume(() => _el_read_error(), id, scopeId);
|
|
2277
|
+
}
|
|
2278
|
+
function _hoist(scopeId, id) {
|
|
2279
|
+
const getter = () => _hoist_read_error();
|
|
2280
|
+
getter[Symbol.iterator] = _hoist_read_error;
|
|
2281
|
+
return _resume(getter, id, scopeId);
|
|
2282
|
+
}
|
|
2283
|
+
function _el_mark(scopeId, accessor, markerGuard) {
|
|
2284
|
+
if (markerGuard === 0) return "";
|
|
2285
|
+
const { state } = $chunk.boundary;
|
|
2286
|
+
state.needsWalkerRuntime = true;
|
|
2287
|
+
return state.mark("$", scopeId + " " + accessor);
|
|
2288
|
+
}
|
|
2289
|
+
function _text_mark(scopeId, accessor, val, markerGuard) {
|
|
2290
|
+
return markText(scopeId, accessor, _escape(val), markerGuard);
|
|
2291
|
+
}
|
|
2292
|
+
function _html_mark(scopeId, accessor, val, markerGuard) {
|
|
2293
|
+
const html = _unescaped(val);
|
|
2294
|
+
if (markerGuard === 0 || !~html.indexOf("<")) return markText(scopeId, accessor, html, markerGuard);
|
|
2295
|
+
const { state } = $chunk.boundary;
|
|
2296
|
+
state.needsWalkerRuntime = true;
|
|
2297
|
+
return state.mark("&", "") + html + state.mark("'", scopeId + " " + accessor);
|
|
2298
|
+
}
|
|
2299
|
+
function markText(scopeId, accessor, text, markerGuard) {
|
|
2300
|
+
if (markerGuard === 0) return text;
|
|
2301
|
+
const { state } = $chunk.boundary;
|
|
2302
|
+
state.needsWalkerRuntime = true;
|
|
2303
|
+
return text ? (markerGuard === 2 ? "<!>" : "") + text + state.mark("$", scopeId + " " + accessor) : state.mark("%", scopeId + " " + accessor);
|
|
2304
|
+
}
|
|
2305
|
+
function _resume_branch(scopeId) {
|
|
2306
|
+
const branchId = getContext(kBranchId);
|
|
2307
|
+
if (branchId !== void 0 && branchId !== scopeId) writeScope(scopeId, { [ClosestBranchId]: branchId });
|
|
2308
|
+
}
|
|
2309
|
+
function _attr_content(nodeAccessor, scopeId, content, markerGuard) {
|
|
2310
|
+
const shouldResume = markerGuard !== 0;
|
|
2311
|
+
var value = content;
|
|
2312
|
+
content = content?.content || content;
|
|
2313
|
+
if (classAPIRenderer && content) content = classAPIRenderer(content);
|
|
2314
|
+
assertValidContent(value, content);
|
|
2315
|
+
const branchId = _peek_scope_id();
|
|
2316
|
+
if (content) try {
|
|
2317
|
+
_set_scope_reason(shouldResume ? ALL_GROUPS : 0);
|
|
2318
|
+
if (shouldResume) withBranchId(branchId, content);
|
|
2319
|
+
else content();
|
|
2320
|
+
} finally {
|
|
2321
|
+
_set_scope_reason(void 0);
|
|
2322
|
+
}
|
|
2323
|
+
if (_peek_scope_id() !== branchId) {
|
|
2324
|
+
if (shouldResume) writeScope(scopeId, {
|
|
2325
|
+
[BranchScopes + nodeAccessor]: writeScope(branchId, {}),
|
|
2326
|
+
[ConditionalRenderer + nodeAccessor]: rendererKey(content)
|
|
2327
|
+
});
|
|
2328
|
+
} else _scope_id();
|
|
2329
|
+
}
|
|
2330
|
+
function _var(parentScopeId, scopeOffsetAccessor, childScopeId, registryId, nodeAccessor) {
|
|
2331
|
+
writeScopePassive(parentScopeId, { [scopeOffsetAccessor]: _scope_id() });
|
|
2332
|
+
const childScope = writeScopePassive(childScopeId, { [TagVariable]: _resume({}, registryId, parentScopeId) });
|
|
2333
|
+
if (nodeAccessor !== void 0) writeScope(parentScopeId, { [BranchScopes + nodeAccessor]: childScope });
|
|
2334
|
+
}
|
|
2335
|
+
function writeScopePassive(scopeId, partialScope) {
|
|
2336
|
+
const target = $chunk.channel;
|
|
2337
|
+
const scope = _scope_with_id(scopeId);
|
|
2338
|
+
Object.assign(scope, partialScope);
|
|
2339
|
+
$chunk.boundary.state.queuePassiveScope(target, scopeId, partialScope);
|
|
2340
|
+
return scope;
|
|
2341
|
+
}
|
|
2342
|
+
let writeScope = (scopeId, partialScope) => {
|
|
2343
|
+
const { state } = $chunk.boundary;
|
|
2344
|
+
const target = $chunk.channel;
|
|
2345
|
+
const scope = scopeWithId(state, scopeId);
|
|
2346
|
+
state.needsWalkerRuntime = true;
|
|
2347
|
+
countResumeWrite($chunk);
|
|
2348
|
+
writeAsyncVisits($chunk);
|
|
2349
|
+
Object.assign(scope, partialScope);
|
|
2350
|
+
state.queueScope(target, scopeId, partialScope);
|
|
2351
|
+
return scope;
|
|
2352
|
+
};
|
|
2353
|
+
writeScope = ((writeScope) => (scopeId, partialScope, file, loc, vars) => {
|
|
2354
|
+
const scope = writeScope(scopeId, partialScope);
|
|
2355
|
+
if (file && loc !== void 0) setDebugInfo(scope, file, loc, vars);
|
|
2356
|
+
return scope;
|
|
2357
|
+
})(writeScope);
|
|
2358
|
+
function _existing_scope(scopeId) {
|
|
2359
|
+
return writeScope(scopeId, {});
|
|
2360
|
+
}
|
|
2361
|
+
function _scope_with_id(scopeId) {
|
|
2362
|
+
return scopeWithId($chunk.boundary.state, scopeId);
|
|
2363
|
+
}
|
|
2364
|
+
function scopeWithId(state, scopeId) {
|
|
2365
|
+
const { scopes } = state;
|
|
2366
|
+
let scope = scopes.get(scopeId);
|
|
2367
|
+
if (!scope) scopes.set(scopeId, scope = { [K_SCOPE_ID]: scopeId });
|
|
2368
|
+
return scope;
|
|
2369
|
+
}
|
|
2370
|
+
function _subscribe(subscribers, scope, resumeId, markerGuard) {
|
|
2371
|
+
if (subscribers) {
|
|
2372
|
+
const { boundary, channel } = $chunk;
|
|
2373
|
+
const { serializer } = boundary.state;
|
|
2374
|
+
if (!channel.readyId && !serializer.refs.has(subscribers)) subscribers.add(scope);
|
|
2375
|
+
else if (resumeId) _script(scope[K_SCOPE_ID], resumeId, markerGuard);
|
|
2376
|
+
else queueCall(serializer, scope, subscribers, "add", channel);
|
|
2377
|
+
if (boundary.withinCatch) (boundary.subscribed ||= []).push(subscribers, scope, channel);
|
|
2378
|
+
}
|
|
2379
|
+
return scope;
|
|
2380
|
+
}
|
|
2381
|
+
const ALL_GROUPS = 715827883;
|
|
2382
|
+
function getGroupReason(reason, group) {
|
|
2383
|
+
return reason === 715827883 ? 1 : typeof reason === "number" ? group < 15 ? reason >>> 1 + 2 * group & 3 : 0 : reason[group] ?? 0;
|
|
2384
|
+
}
|
|
2385
|
+
function _set_scope_reason(reason) {
|
|
2386
|
+
$chunk.boundary.state.scopeReason = reason;
|
|
2387
|
+
}
|
|
2388
|
+
function _scope_reason() {
|
|
2389
|
+
const reason = $chunk.boundary.state.scopeReason;
|
|
2390
|
+
$chunk.boundary.state.scopeReason = void 0;
|
|
2391
|
+
return reason;
|
|
2392
|
+
}
|
|
2393
|
+
function _write_if(reason, group) {
|
|
2394
|
+
return reason && getGroupReason(reason, group) ? 1 : void 0;
|
|
2395
|
+
}
|
|
2396
|
+
function _write_guard(reason, group) {
|
|
2397
|
+
return _write_if(reason, group) || 0;
|
|
2398
|
+
}
|
|
2399
|
+
function writeWaitReady(readyId, renderer, input) {
|
|
2400
|
+
const chunk = $chunk;
|
|
2401
|
+
const { boundary } = chunk;
|
|
2402
|
+
const body = new Chunk(boundary, null, chunk.context, {
|
|
2403
|
+
readyId,
|
|
2404
|
+
parent: chunk.channel,
|
|
2405
|
+
resumes: "",
|
|
2406
|
+
writeScopes: {},
|
|
2407
|
+
flushScopes: false
|
|
2408
|
+
});
|
|
2409
|
+
const bodyEnd = body.render(renderer, input);
|
|
2410
|
+
if (boundary.aborted) throw boundary.reason;
|
|
2411
|
+
if (body === bodyEnd) {
|
|
2412
|
+
chunk.writeHTML(body.html);
|
|
2413
|
+
body.deferOwnReady();
|
|
2414
|
+
chunk.deferredReady = push(chunk.deferredReady, body);
|
|
2415
|
+
} else {
|
|
2416
|
+
bodyEnd.next = chunk.forkRest(boundary);
|
|
2417
|
+
chunk.next = body;
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
function deferBranchStart(chunk) {
|
|
2421
|
+
const beforeBranch = chunk.html;
|
|
2422
|
+
chunk.html = "";
|
|
2423
|
+
return beforeBranch;
|
|
2424
|
+
}
|
|
2425
|
+
function applyBranchStart(chunk, beforeBranch, rendered) {
|
|
2426
|
+
chunk.html = beforeBranch + (rendered ? chunk.boundary.state.mark("[", "") : "") + chunk.html;
|
|
2427
|
+
}
|
|
2428
|
+
function unsubscribe(subscribed, serializer) {
|
|
2429
|
+
for (let i = 0; i < subscribed.length; i += 3) {
|
|
2430
|
+
const subscribers = subscribed[i];
|
|
2431
|
+
const scope = subscribed[i + 1];
|
|
2432
|
+
if (!serializer.refs.has(subscribers)) subscribers.delete(scope);
|
|
2433
|
+
else {
|
|
2434
|
+
const channel = subscribed[i + 2];
|
|
2435
|
+
if (!dropQueuedCall(serializer, scope, subscribers, "add", channel)) queueCall(serializer, scope, subscribers, "delete", channel);
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
function countResumeWrite(chunk) {
|
|
2440
|
+
for (let boundary = chunk.boundary; boundary; boundary = boundary.parent) boundary.resumeWrites++;
|
|
2441
|
+
}
|
|
2442
|
+
function writeAsyncVisits(chunk) {
|
|
2443
|
+
for (let async = getAsyncContent(chunk); async && !async.resumed; async = async.parent) {
|
|
2444
|
+
async.resumed = true;
|
|
2445
|
+
async.end?.writeHTML(async.visit);
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
function getAsyncContent(chunk) {
|
|
2449
|
+
return chunk.context?.[kAsyncContent];
|
|
2450
|
+
}
|
|
2451
|
+
var State = class {
|
|
2452
|
+
tagId = 1;
|
|
2453
|
+
scopeId = 1;
|
|
2454
|
+
reorderId = 1;
|
|
2455
|
+
readyGate = 1;
|
|
2456
|
+
hasWrittenGlobals = false;
|
|
2457
|
+
needsWalkerRuntime = false;
|
|
2458
|
+
hasWalkerRuntime = false;
|
|
2459
|
+
hasWrittenReady = false;
|
|
2460
|
+
hasReorderRuntime = false;
|
|
2461
|
+
hasWrittenResume = false;
|
|
2462
|
+
walkOnNextFlush = false;
|
|
2463
|
+
trailerHTML = "";
|
|
2464
|
+
resumes = "";
|
|
2465
|
+
nonceAttr = "";
|
|
2466
|
+
serializer = new State$1();
|
|
2467
|
+
writeReorders = null;
|
|
2468
|
+
scopes = /* @__PURE__ */ new Map();
|
|
2469
|
+
scope = (scopeId) => scopeWithId(this, scopeId);
|
|
2470
|
+
flushScopes = false;
|
|
2471
|
+
writeScopes = {};
|
|
2472
|
+
readyIds = null;
|
|
2473
|
+
readyPositions = null;
|
|
2474
|
+
scopeReason;
|
|
2475
|
+
$global;
|
|
2476
|
+
constructor($global) {
|
|
2477
|
+
this.$global = $global;
|
|
2478
|
+
if ($global.cspNonce) this.nonceAttr = " nonce" + attrAssignment($global.cspNonce);
|
|
2479
|
+
}
|
|
2480
|
+
joinFlush(html, scripts, pending) {
|
|
2481
|
+
const { $global, nonceAttr } = this;
|
|
2482
|
+
const { __flush__ } = $global;
|
|
2483
|
+
if (scripts) html += "<script" + nonceAttr + ">" + scripts + "<\/script>";
|
|
2484
|
+
if (__flush__) {
|
|
2485
|
+
$global.__flush__ = void 0;
|
|
2486
|
+
html = __flush__($global, html);
|
|
2487
|
+
}
|
|
2488
|
+
return pending ? html : html + this.trailerHTML;
|
|
2489
|
+
}
|
|
2490
|
+
walkScript() {
|
|
2491
|
+
return this.runtimePrefix + ".w()";
|
|
2492
|
+
}
|
|
2493
|
+
addResumes(channel, resumes) {
|
|
2494
|
+
channel.resumes = concatSequence(channel.resumes, resumes);
|
|
2495
|
+
}
|
|
2496
|
+
queueScope(target, scopeId, partialScope) {
|
|
2497
|
+
const pending = target.writeScopes[scopeId];
|
|
2498
|
+
if (pending && pending !== partialScope) Object.assign(pending, partialScope);
|
|
2499
|
+
else target.writeScopes[scopeId] = partialScope;
|
|
2500
|
+
target.flushScopes = true;
|
|
2501
|
+
}
|
|
2502
|
+
queuePassiveScope(target, scopeId, partialScope) {
|
|
2503
|
+
const passive = target.passiveScopes ||= {};
|
|
2504
|
+
passive[scopeId] = Object.assign(passive[scopeId] || {}, partialScope);
|
|
2505
|
+
}
|
|
2506
|
+
queueEffect(scopeId, registryId) {
|
|
2507
|
+
this.needsWalkerRuntime = true;
|
|
2508
|
+
$chunk.writeEffect(scopeId, registryId);
|
|
2509
|
+
}
|
|
2510
|
+
serializeFlush(boundary) {
|
|
2511
|
+
flushSerializer(boundary, this);
|
|
2512
|
+
}
|
|
2513
|
+
runtimeScript() {
|
|
2514
|
+
return WALKER_RUNTIME_CODE + "(\"" + this.$global.runtimeId + "\")(\"" + this.$global.renderId + "\")";
|
|
2515
|
+
}
|
|
2516
|
+
keepsTryMarks(chunk, resumeWrites) {
|
|
2517
|
+
return chunk !== $chunk || chunk.boundary.resumeWrites !== resumeWrites;
|
|
2518
|
+
}
|
|
2519
|
+
resumeScript(resumes) {
|
|
2520
|
+
if (this.hasWrittenResume) return this.runtimePrefix + ".r.push(" + resumes + ")";
|
|
2521
|
+
this.hasWrittenResume = true;
|
|
2522
|
+
return this.runtimePrefix + ".r=[" + resumes + "]";
|
|
2523
|
+
}
|
|
2524
|
+
get runtimePrefix() {
|
|
2525
|
+
const { $global } = this;
|
|
2526
|
+
return $global.runtimeId + "." + $global.renderId;
|
|
2527
|
+
}
|
|
2528
|
+
get commentPrefix() {
|
|
2529
|
+
const { $global } = this;
|
|
2530
|
+
return $global.runtimeId + $global.renderId;
|
|
2531
|
+
}
|
|
2532
|
+
reorder(chunk) {
|
|
2533
|
+
if (this.writeReorders) this.writeReorders.push(chunk);
|
|
2534
|
+
else {
|
|
2535
|
+
this.needsWalkerRuntime = true;
|
|
2536
|
+
this.writeReorders = [chunk];
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
readyScript(id, resumes) {
|
|
2540
|
+
const readyKey = toObjectKey(id);
|
|
2541
|
+
if (this.readyIds?.has(id)) return this.readyAccess(readyKey) + ".push(" + resumes + ")";
|
|
2542
|
+
(this.readyIds ||= /* @__PURE__ */ new Set()).add(id);
|
|
2543
|
+
if (this.hasWrittenReady) return this.readyAccess(readyKey) + "=[" + resumes + "]";
|
|
2544
|
+
this.hasWrittenReady = true;
|
|
2545
|
+
return this.runtimePrefix + ".b={" + readyKey + ":[" + resumes + "]}";
|
|
2546
|
+
}
|
|
2547
|
+
readyAccess(readyKey) {
|
|
2548
|
+
return this.runtimePrefix + ".b" + toAccess(readyKey);
|
|
2549
|
+
}
|
|
2550
|
+
nextReorderId() {
|
|
2551
|
+
const c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789";
|
|
2552
|
+
let n = this.reorderId++;
|
|
2553
|
+
let r = c[n % 54];
|
|
2554
|
+
for (n = n / 54 | 0; n; n >>>= 6) r += c[n & 63];
|
|
2555
|
+
return r;
|
|
2556
|
+
}
|
|
2557
|
+
mark(code, str) {
|
|
2558
|
+
return "<!--" + this.commentPrefix + code + str + "-->";
|
|
2559
|
+
}
|
|
2560
|
+
};
|
|
2561
|
+
function NOOP() {}
|
|
2562
|
+
var Boundary = class {
|
|
2563
|
+
onNext = NOOP;
|
|
2564
|
+
count = 0;
|
|
2565
|
+
resumeWrites = 0;
|
|
2566
|
+
state;
|
|
2567
|
+
parent;
|
|
2568
|
+
aborted = false;
|
|
2569
|
+
reason;
|
|
2570
|
+
subscribed;
|
|
2571
|
+
pendingReorders;
|
|
2572
|
+
children;
|
|
2573
|
+
withinCatch = false;
|
|
2574
|
+
constructor(state, signal, parent) {
|
|
2575
|
+
this.state = state;
|
|
2576
|
+
this.parent = parent;
|
|
2577
|
+
if (parent) {
|
|
2578
|
+
this.withinCatch = parent.withinCatch;
|
|
2579
|
+
if (parent.aborted) this.abort(parent.reason);
|
|
2580
|
+
else (parent.children ||= []).push(this);
|
|
2581
|
+
} else if (signal) {
|
|
2582
|
+
if (signal.aborted) this.abort(signal.reason);
|
|
2583
|
+
else signal.addEventListener("abort", this);
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
abort(reason) {
|
|
2587
|
+
if (this.aborted) return;
|
|
2588
|
+
const { state } = this;
|
|
2589
|
+
this.aborted = true;
|
|
2590
|
+
this.reason = reason;
|
|
2591
|
+
if (this.subscribed) unsubscribe(this.subscribed, state.serializer);
|
|
2592
|
+
if (this.pendingReorders) {
|
|
2593
|
+
for (const reorder of this.pendingReorders) state.reorder(reorder);
|
|
2594
|
+
this.pendingReorders = void 0;
|
|
2595
|
+
}
|
|
2596
|
+
this.count = 0;
|
|
2597
|
+
this.state = new State(state.$global);
|
|
2598
|
+
if (this.children) for (const child of this.children) child.abort(reason);
|
|
2599
|
+
this.onNext();
|
|
2600
|
+
}
|
|
2601
|
+
handleEvent(event) {
|
|
2602
|
+
this.abort(event.target.reason);
|
|
2603
|
+
}
|
|
2604
|
+
flush() {
|
|
2605
|
+
if (!this.aborted) this.state.serializeFlush(this);
|
|
2606
|
+
return this.count ? 1 : this.aborted ? 2 : 0;
|
|
2607
|
+
}
|
|
2608
|
+
startAsync() {
|
|
2609
|
+
if (!this.aborted) this.count++;
|
|
2610
|
+
}
|
|
2611
|
+
endAsync() {
|
|
2612
|
+
if (!this.aborted) {
|
|
2613
|
+
if (!this.count) throw new Error("A boundary ended more async work than it started.");
|
|
2614
|
+
this.count--;
|
|
2615
|
+
this.onNext();
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
};
|
|
2619
|
+
var Chunk = class Chunk {
|
|
2620
|
+
html = "";
|
|
2621
|
+
scripts = "";
|
|
2622
|
+
effects = "";
|
|
2623
|
+
lastEffect = "";
|
|
2624
|
+
async = false;
|
|
2625
|
+
consumed = false;
|
|
2626
|
+
reorderId = null;
|
|
2627
|
+
reorderBranch = 0;
|
|
2628
|
+
deferredReady = null;
|
|
2629
|
+
heldEffects = null;
|
|
2630
|
+
deferredReorder = null;
|
|
2631
|
+
catchRange = null;
|
|
2632
|
+
placeholder = null;
|
|
2633
|
+
boundary;
|
|
2634
|
+
next;
|
|
2635
|
+
context;
|
|
2636
|
+
channel;
|
|
2637
|
+
constructor(boundary, next, context, channel) {
|
|
2638
|
+
this.boundary = boundary;
|
|
2639
|
+
this.next = next;
|
|
2640
|
+
this.context = context;
|
|
2641
|
+
this.channel = channel;
|
|
2642
|
+
}
|
|
2643
|
+
fork(boundary, next) {
|
|
2644
|
+
return new Chunk(boundary, next, this.context, this.channel);
|
|
2645
|
+
}
|
|
2646
|
+
forkRest(boundary) {
|
|
2647
|
+
return $chunk = this.fork(boundary, this.next);
|
|
2648
|
+
}
|
|
2649
|
+
writeHTML(html) {
|
|
2650
|
+
this.html += html;
|
|
2651
|
+
}
|
|
2652
|
+
writeEffect(scopeId, registryId) {
|
|
2653
|
+
countResumeWrite(this);
|
|
2654
|
+
writeAsyncVisits(this);
|
|
2655
|
+
if (this.lastEffect === registryId) this.effects = concatEffects(this.effects, scopeId + "");
|
|
2656
|
+
else {
|
|
2657
|
+
this.lastEffect = registryId;
|
|
2658
|
+
this.effects = concatEffects(this.effects, registryId + " " + scopeId);
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
writeScript(script) {
|
|
2662
|
+
this.scripts = concatScripts(this.scripts, script);
|
|
2663
|
+
}
|
|
2664
|
+
append(chunk) {
|
|
2665
|
+
this.html += chunk.html;
|
|
2666
|
+
this.effects = concatEffects(this.effects, chunk.effects);
|
|
2667
|
+
this.scripts = concatScripts(this.scripts, chunk.scripts);
|
|
2668
|
+
this.lastEffect = chunk.lastEffect || this.lastEffect;
|
|
2669
|
+
this.deferredReady = concat(this.deferredReady, chunk.takeDeferredReady());
|
|
2670
|
+
}
|
|
2671
|
+
takeHeldEffects() {
|
|
2672
|
+
const { heldEffects } = this;
|
|
2673
|
+
this.heldEffects = null;
|
|
2674
|
+
return heldEffects;
|
|
2675
|
+
}
|
|
2676
|
+
takeDeferredReady() {
|
|
2677
|
+
const { deferredReady } = this;
|
|
2678
|
+
this.deferredReady = null;
|
|
2679
|
+
return deferredReady;
|
|
2680
|
+
}
|
|
2681
|
+
deferOwnReady() {
|
|
2682
|
+
if (this.channel.readyId && (this.effects || this.scripts || this.channel.flushScopes)) {
|
|
2683
|
+
const deferred = this.fork(this.boundary, null);
|
|
2684
|
+
deferred.effects = this.effects;
|
|
2685
|
+
deferred.scripts = this.scripts;
|
|
2686
|
+
this.effects = this.scripts = this.lastEffect = "";
|
|
2687
|
+
this.deferredReady = concat(deferred, this.deferredReady);
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
renderPlaceholders(boundary) {
|
|
2691
|
+
const { state } = boundary;
|
|
2692
|
+
restart: for (;;) {
|
|
2693
|
+
let reorders = null;
|
|
2694
|
+
for (let cur = this; cur.next && !cur.async; cur = cur.next) {
|
|
2695
|
+
if (cur.renderPlaceholder(state)) {
|
|
2696
|
+
if (boundary.aborted) return;
|
|
2697
|
+
continue restart;
|
|
2698
|
+
}
|
|
2699
|
+
if (cur.deferredReorder) (reorders ||= []).push(cur.deferredReorder);
|
|
2700
|
+
}
|
|
2701
|
+
if (state.writeReorders) {
|
|
2702
|
+
for (const reorder of state.writeReorders) if ((reorders = renderReorderPlaceholders(reorder, reorders)) === false) {
|
|
2703
|
+
if (boundary.aborted) return;
|
|
2704
|
+
continue restart;
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
for (let i = 0; reorders && i < reorders.length; i++) if ((reorders = renderReorderPlaceholders(reorders[i], reorders)) === false) {
|
|
2708
|
+
if (boundary.aborted) return;
|
|
2709
|
+
continue restart;
|
|
2710
|
+
}
|
|
2711
|
+
return;
|
|
2712
|
+
}
|
|
2713
|
+
}
|
|
2714
|
+
renderPlaceholder(state) {
|
|
2715
|
+
const { placeholder } = this;
|
|
2716
|
+
if (!placeholder) return false;
|
|
2717
|
+
this.placeholder = null;
|
|
2718
|
+
if (this.boundary.aborted) return false;
|
|
2719
|
+
const { body } = placeholder;
|
|
2720
|
+
let end = body;
|
|
2721
|
+
while (end.next && !end.async) end = end.next;
|
|
2722
|
+
if (!end.async) {
|
|
2723
|
+
end.next = this.next;
|
|
2724
|
+
this.next = body;
|
|
2725
|
+
return false;
|
|
2726
|
+
}
|
|
2727
|
+
const { branchId, scopeId, placeholderBranchId } = placeholder;
|
|
2728
|
+
const reorderId = body.reorderId = branchId + "";
|
|
2729
|
+
this.writeHTML(state.mark("!^", reorderId));
|
|
2730
|
+
const { effects } = this;
|
|
2731
|
+
const beforeBranch = deferBranchStart(this);
|
|
2732
|
+
if (this.render(withBranchId, placeholderBranchId, placeholder.render) !== this) this.boundary.abort(/* @__PURE__ */ new Error("An @placeholder cannot contain async content."));
|
|
2733
|
+
if (this.boundary.aborted) return true;
|
|
2734
|
+
const stateful = this.effects !== effects;
|
|
2735
|
+
applyBranchStart(this, beforeBranch, stateful);
|
|
2736
|
+
if (stateful) {
|
|
2737
|
+
this.render(writeScope, branchId, { [PlaceholderBranch]: scopeWithId(state, placeholderBranchId) });
|
|
2738
|
+
this.writeHTML(state.mark("]", scopeId + " " + (PlaceholderBranch + branchId) + " " + placeholderBranchId));
|
|
2739
|
+
dismissChunk(end, body).writeEffect(branchId, PLACEHOLDER_DISMISS_REGISTER_ID);
|
|
2740
|
+
}
|
|
2741
|
+
this.writeHTML(state.mark("!", reorderId));
|
|
2742
|
+
this.deferredReorder = body;
|
|
2743
|
+
return false;
|
|
2744
|
+
}
|
|
2745
|
+
markCatchRange() {
|
|
2746
|
+
const { catchRange } = this;
|
|
2747
|
+
if (catchRange) {
|
|
2748
|
+
const { state } = this.boundary;
|
|
2749
|
+
this.catchRange = null;
|
|
2750
|
+
this.writeHTML(state.mark("!^", catchRange.id));
|
|
2751
|
+
catchRange.end.writeHTML(state.mark("!", catchRange.id));
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
queueDeferredReorder() {
|
|
2755
|
+
const { deferredReorder } = this;
|
|
2756
|
+
if (deferredReorder) {
|
|
2757
|
+
this.deferredReorder = null;
|
|
2758
|
+
deferredReorder.boundary.state.reorder(deferredReorder);
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
consume(boundary) {
|
|
2762
|
+
this.renderPlaceholders(boundary);
|
|
2763
|
+
let cur = this;
|
|
2764
|
+
let html = "";
|
|
2765
|
+
let effects = "";
|
|
2766
|
+
let scripts = "";
|
|
2767
|
+
let effectsEnd;
|
|
2768
|
+
let heldEffects = this.heldEffects;
|
|
2769
|
+
let deferredReady;
|
|
2770
|
+
this.heldEffects = null;
|
|
2771
|
+
if (this.channel.readyId && this.effects) followHeldEffects(this);
|
|
2772
|
+
while (cur.next && !cur.async) {
|
|
2773
|
+
cur.markCatchRange();
|
|
2774
|
+
cur.queueDeferredReorder();
|
|
2775
|
+
html += cur.html;
|
|
2776
|
+
if (cur.channel.readyId) deferredReady = push(deferredReady, cur);
|
|
2777
|
+
else {
|
|
2778
|
+
if (cur.effects) {
|
|
2779
|
+
if (effectsEnd && effectsEnd.boundary !== cur.boundary) {
|
|
2780
|
+
heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects);
|
|
2781
|
+
effects = "";
|
|
2782
|
+
}
|
|
2783
|
+
effectsEnd = cur;
|
|
2784
|
+
effects = concatEffects(effects, cur.effects);
|
|
2785
|
+
}
|
|
2786
|
+
scripts = concatScripts(scripts, cur.scripts);
|
|
2787
|
+
}
|
|
2788
|
+
deferredReady = concat(deferredReady, cur.takeDeferredReady());
|
|
2789
|
+
cur.consumed = true;
|
|
2790
|
+
cur = cur.next;
|
|
2791
|
+
}
|
|
2792
|
+
cur.deferOwnReady();
|
|
2793
|
+
if (effects) {
|
|
2794
|
+
if (cur.channel.readyId) heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects);
|
|
2795
|
+
else if (effectsEnd.boundary !== cur.boundary) {
|
|
2796
|
+
heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects);
|
|
2797
|
+
if (isWithin(cur.boundary, effectsEnd.boundary)) cur.lastEffect ||= effectsEnd.lastEffect;
|
|
2798
|
+
} else {
|
|
2799
|
+
cur.effects = concatEffects(effects, cur.effects);
|
|
2800
|
+
cur.lastEffect ||= effectsEnd.lastEffect;
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
cur.heldEffects = heldEffects;
|
|
2804
|
+
cur.deferredReady = concat(deferredReady, cur.deferredReady);
|
|
2805
|
+
cur.html = html + cur.html;
|
|
2806
|
+
cur.scripts = concatScripts(scripts, cur.scripts);
|
|
2807
|
+
return cur;
|
|
2808
|
+
}
|
|
2809
|
+
render(content, val, val2) {
|
|
2810
|
+
const prev = $chunk;
|
|
2811
|
+
$chunk = this;
|
|
2812
|
+
try {
|
|
2813
|
+
content(val, val2);
|
|
2814
|
+
return $chunk;
|
|
2815
|
+
} catch (err) {
|
|
2816
|
+
this.boundary.abort(err);
|
|
2817
|
+
return this;
|
|
2818
|
+
} finally {
|
|
2819
|
+
$chunk = prev;
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
flushReadyScripts(boundary, reservations, holdEffects) {
|
|
2823
|
+
const { channel } = this;
|
|
2824
|
+
const { readyId } = channel;
|
|
2825
|
+
let scripts = "";
|
|
2826
|
+
const held = this.takeDeferredReady();
|
|
2827
|
+
if (held) for (const chunk of toArray(held)) {
|
|
2828
|
+
if (chunk.boundary.aborted) continue;
|
|
2829
|
+
scripts = concatScripts(scripts, chunk.flushReadyScripts(boundary, reservations, holdEffects));
|
|
2830
|
+
if (chunk.effects || chunk.deferredReady) this.deferredReady = push(this.deferredReady, chunk);
|
|
2831
|
+
}
|
|
2832
|
+
if (readyId && !this.async) {
|
|
2833
|
+
const { state } = boundary;
|
|
2834
|
+
const effects = holdEffects ? "" : this.effects;
|
|
2835
|
+
if (effects) flushSerializerGlobals(boundary);
|
|
2836
|
+
flushSerializer(boundary, channel);
|
|
2837
|
+
const deps = takeChannelDeps(state.serializer);
|
|
2838
|
+
const { resumes } = channel;
|
|
2839
|
+
const chunkScripts = this.scripts;
|
|
2840
|
+
channel.resumes = this.scripts = "";
|
|
2841
|
+
if (effects) this.effects = this.lastEffect = "";
|
|
2842
|
+
if (resumes || effects) {
|
|
2843
|
+
state.needsWalkerRuntime = true;
|
|
2844
|
+
const batch = concatSequence(readyBatch(state, channel, deps, resumes), effects && `"${effects}"`);
|
|
2845
|
+
if (reservations) {
|
|
2846
|
+
const gate = state.readyGate++;
|
|
2847
|
+
reservations.push(state.readyScript(readyId, gate + ""));
|
|
2848
|
+
scripts = concatScripts(scripts, "(b=>b.splice(b.indexOf(" + gate + "),1," + batch + "))(" + state.readyAccess(toObjectKey(readyId)) + ")");
|
|
2849
|
+
} else scripts = concatScripts(scripts, state.readyScript(readyId, batch));
|
|
2850
|
+
}
|
|
2851
|
+
scripts = concatScripts(scripts, chunkScripts);
|
|
2852
|
+
}
|
|
2853
|
+
return scripts;
|
|
2854
|
+
}
|
|
2855
|
+
flush(boundary) {
|
|
2856
|
+
const { state } = boundary;
|
|
2857
|
+
const { runtimePrefix } = state;
|
|
2858
|
+
let needsWalk = state.walkOnNextFlush;
|
|
2859
|
+
if (needsWalk) state.walkOnNextFlush = false;
|
|
2860
|
+
flushSerializer(boundary, state);
|
|
2861
|
+
let readyResumeScripts = this.flushReadyScripts(boundary, void 0, this.async);
|
|
2862
|
+
for (let channel; !boundary.aborted && (channel = pendingReadyChannel(state.serializer));) {
|
|
2863
|
+
const resumes = stringifyScopes(state.serializer, [], boundary, channel);
|
|
2864
|
+
const deps = takeChannelDeps(state.serializer);
|
|
2865
|
+
state.needsWalkerRuntime = true;
|
|
2866
|
+
readyResumeScripts = concatScripts(readyResumeScripts, state.readyScript(channel.readyId, readyBatch(state, channel, deps, resumes)));
|
|
2867
|
+
}
|
|
2868
|
+
if (readyResumeScripts) needsWalk = true;
|
|
2869
|
+
const effects = this.async ? "" : joinHeldEffects(this.takeHeldEffects(), this.effects);
|
|
2870
|
+
let { html, scripts } = this;
|
|
2871
|
+
if (html && state.hasReorderRuntime) html = state.mark("*", "") + html;
|
|
2872
|
+
if (state.needsWalkerRuntime && !state.hasWalkerRuntime) {
|
|
2873
|
+
state.hasWalkerRuntime = true;
|
|
2874
|
+
scripts = concatScripts(scripts, state.runtimeScript());
|
|
2875
|
+
}
|
|
2876
|
+
scripts = concatScripts(scripts, readyResumeScripts);
|
|
2877
|
+
if (effects) {
|
|
2878
|
+
needsWalk = true;
|
|
2879
|
+
flushSerializerGlobals(boundary);
|
|
2880
|
+
state.resumes = concatSequence(state.resumes, "\"" + effects + "\"");
|
|
2881
|
+
}
|
|
2882
|
+
let reordered = "";
|
|
2883
|
+
let needsResumeArray = false;
|
|
2884
|
+
if (state.writeReorders) {
|
|
2885
|
+
for (const reorderedChunk of state.writeReorders) {
|
|
2886
|
+
needsWalk = true;
|
|
2887
|
+
if (!state.hasReorderRuntime) {
|
|
2888
|
+
state.hasReorderRuntime = true;
|
|
2889
|
+
scripts = concatScripts(scripts, REORDER_RUNTIME_CODE + "(" + runtimePrefix + ")");
|
|
2890
|
+
}
|
|
2891
|
+
const { reorderId, reorderBranch } = reorderedChunk;
|
|
2892
|
+
const rootBranch = reorderBranch || +reorderId;
|
|
2893
|
+
const readyReservations = [];
|
|
2894
|
+
let reorderHTML = "";
|
|
2895
|
+
let reorderEffects = "";
|
|
2896
|
+
let effectsBoundary = reorderedChunk.boundary;
|
|
2897
|
+
let reorderScripts = "";
|
|
2898
|
+
let cur = reorderedChunk.boundary.aborted ? null : reorderedChunk;
|
|
2899
|
+
reorderedChunk.reorderId = null;
|
|
2900
|
+
while (cur) {
|
|
2901
|
+
cur.markCatchRange();
|
|
2902
|
+
cur.queueDeferredReorder();
|
|
2903
|
+
cur.deferOwnReady();
|
|
2904
|
+
const { next } = cur;
|
|
2905
|
+
const readyResumeScripts = cur.flushReadyScripts(boundary, readyReservations, this.async);
|
|
2906
|
+
this.deferredReady = concat(this.deferredReady, cur.takeDeferredReady());
|
|
2907
|
+
cur.consumed = true;
|
|
2908
|
+
reorderHTML += cur.html;
|
|
2909
|
+
if (this.async && cur.effects && cur.boundary !== effectsBoundary) {
|
|
2910
|
+
if (reorderEffects) {
|
|
2911
|
+
holdReorderEffects(this, effectsBoundary, reorderEffects);
|
|
2912
|
+
reorderEffects = "";
|
|
2913
|
+
}
|
|
2914
|
+
effectsBoundary = cur.boundary;
|
|
2915
|
+
}
|
|
2916
|
+
reorderEffects = concatEffects(reorderEffects, cur.effects);
|
|
2917
|
+
reorderScripts = concatScripts(reorderScripts, concatScripts(readyResumeScripts, cur.scripts));
|
|
2918
|
+
if (cur.async) {
|
|
2919
|
+
reorderHTML += state.mark("#", cur.reorderId = state.nextReorderId());
|
|
2920
|
+
const holeBranch = cur.context?.[kBranchId];
|
|
2921
|
+
cur.reorderBranch = holeBranch > rootBranch ? holeBranch : reorderBranch;
|
|
2922
|
+
(cur.boundary.pendingReorders ||= /* @__PURE__ */ new Set()).add(cur);
|
|
2923
|
+
cur.html = cur.effects = cur.scripts = cur.lastEffect = "";
|
|
2924
|
+
cur.next = null;
|
|
2925
|
+
}
|
|
2926
|
+
cur = next;
|
|
2927
|
+
}
|
|
2928
|
+
if (reorderEffects) {
|
|
2929
|
+
if (this.async) holdReorderEffects(this, effectsBoundary, reorderEffects);
|
|
2930
|
+
else {
|
|
2931
|
+
needsResumeArray = true;
|
|
2932
|
+
reorderScripts = concatScripts(reorderScripts, "_.push(\"" + reorderEffects + "\")");
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
for (const reservation of readyReservations) reordered = concatScripts(reordered, reservation);
|
|
2936
|
+
reordered = concatScripts(reordered, reorderScripts && runtimePrefix + ".j" + toAccess(reorderId) + "=_=>{" + reorderScripts + "}");
|
|
2937
|
+
html += "<t hidden " + state.commentPrefix + "=" + reorderId + ">" + (reorderBranch ? state.mark("*", reorderBranch + "") : "") + reorderHTML + "</t>";
|
|
2938
|
+
}
|
|
2939
|
+
state.writeReorders = null;
|
|
2940
|
+
}
|
|
2941
|
+
if (state.resumes || needsResumeArray && !state.hasWrittenResume) scripts = concatScripts(scripts, state.resumeScript(state.resumes));
|
|
2942
|
+
scripts = concatScripts(scripts, reordered);
|
|
2943
|
+
if (needsWalk) scripts = concatScripts(scripts, state.walkScript());
|
|
2944
|
+
this.html = html;
|
|
2945
|
+
this.scripts = scripts;
|
|
2946
|
+
if (!this.async) this.effects = this.lastEffect = "";
|
|
2947
|
+
state.resumes = "";
|
|
2948
|
+
return this;
|
|
2949
|
+
}
|
|
2950
|
+
flushHTML(boundary) {
|
|
2951
|
+
const { state } = boundary;
|
|
2952
|
+
this.flush(boundary);
|
|
2953
|
+
const { html, scripts } = this;
|
|
2954
|
+
this.html = this.scripts = "";
|
|
2955
|
+
return state.joinFlush(html, scripts, boundary.count);
|
|
2956
|
+
}
|
|
2957
|
+
};
|
|
2958
|
+
function renderReorderPlaceholders(reorder, reorders) {
|
|
2959
|
+
if (!reorder.boundary.aborted) for (let cur = reorder; cur; cur = cur.next) {
|
|
2960
|
+
if (cur.renderPlaceholder(reorder.boundary.state)) return false;
|
|
2961
|
+
if (cur.deferredReorder) (reorders ||= []).push(cur.deferredReorder);
|
|
2962
|
+
}
|
|
2963
|
+
return reorders;
|
|
2964
|
+
}
|
|
2965
|
+
function dismissChunk(end, body) {
|
|
2966
|
+
if (end.boundary !== body.boundary) while (end.next) end = end.next;
|
|
2967
|
+
return end;
|
|
2968
|
+
}
|
|
2969
|
+
function followHeldEffects(chunk) {
|
|
2970
|
+
const held = reduce(chunk.deferredReady, lastHeldOf, chunk);
|
|
2971
|
+
if (held !== chunk) {
|
|
2972
|
+
held.effects = concatEffects(held.effects, chunk.effects);
|
|
2973
|
+
chunk.effects = "";
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
2976
|
+
function lastHeldOf(held, cur) {
|
|
2977
|
+
return cur.channel === held.channel && cur.boundary === held.boundary ? cur : held;
|
|
2978
|
+
}
|
|
2979
|
+
function holdEffectsOn(heldEffects, chunk, effects) {
|
|
2980
|
+
chunk.effects = effects;
|
|
2981
|
+
return push(heldEffects, chunk);
|
|
2982
|
+
}
|
|
2983
|
+
function isWithin(boundary, outer) {
|
|
2984
|
+
while (boundary && boundary !== outer) boundary = boundary.parent;
|
|
2985
|
+
return !!boundary;
|
|
2986
|
+
}
|
|
2987
|
+
function holdReorderEffects(head, boundary, effects) {
|
|
2988
|
+
if (!head.channel.readyId) {
|
|
2989
|
+
if (head.effects) head.heldEffects = holdEffectsOn(head.heldEffects, head.fork(head.boundary, null), head.effects);
|
|
2990
|
+
head.effects = head.lastEffect = "";
|
|
2991
|
+
}
|
|
2992
|
+
head.heldEffects = holdEffectsOn(head.heldEffects, head.fork(boundary, null), effects);
|
|
2993
|
+
}
|
|
2994
|
+
function joinHeldEffects(heldEffects, effects) {
|
|
2995
|
+
return concatEffects(reduce(heldEffects, joinUncaught, ""), effects);
|
|
2996
|
+
}
|
|
2997
|
+
function joinUncaught(joined, held) {
|
|
2998
|
+
return held.boundary.aborted ? joined : concatEffects(joined, held.effects);
|
|
2999
|
+
}
|
|
3000
|
+
function flushSerializer(boundary, channel) {
|
|
3001
|
+
const { state } = boundary;
|
|
3002
|
+
const { serializer } = state;
|
|
3003
|
+
const pending = hasMatchingCalls(serializer, channel.readyId);
|
|
3004
|
+
if (channel.flushScopes || pending) {
|
|
3005
|
+
const { writeScopes, passiveScopes } = channel;
|
|
3006
|
+
const flushes = [];
|
|
3007
|
+
if (passiveScopes) for (const key in passiveScopes) {
|
|
3008
|
+
const props = writeScopes[key];
|
|
3009
|
+
if (props) {
|
|
3010
|
+
writeScopes[key] = Object.assign(passiveScopes[key], props);
|
|
3011
|
+
delete passiveScopes[key];
|
|
3012
|
+
}
|
|
3013
|
+
}
|
|
3014
|
+
if (!channel.readyId && !state.hasWrittenGlobals) {
|
|
3015
|
+
state.hasWrittenGlobals = true;
|
|
3016
|
+
const globals = getFilteredGlobals(state.$global);
|
|
3017
|
+
if (globals) flushes.push([
|
|
3018
|
+
0,
|
|
3019
|
+
globals,
|
|
3020
|
+
globals
|
|
3021
|
+
]);
|
|
3022
|
+
}
|
|
3023
|
+
for (const key in writeScopes) {
|
|
3024
|
+
const scopeId = +key;
|
|
3025
|
+
const props = writeScopes[scopeId];
|
|
3026
|
+
if (hasKeys(props)) flushes.push([
|
|
3027
|
+
scopeId,
|
|
3028
|
+
state.scopes.get(scopeId),
|
|
3029
|
+
props
|
|
3030
|
+
]);
|
|
3031
|
+
}
|
|
3032
|
+
if (flushes.length || pending) {
|
|
3033
|
+
if (channel.readyId) flushSerializerGlobals(boundary);
|
|
3034
|
+
state.addResumes(channel, stringifyScopes(serializer, flushes, boundary, channel));
|
|
3035
|
+
}
|
|
3036
|
+
channel.writeScopes = {};
|
|
3037
|
+
channel.flushScopes = false;
|
|
3038
|
+
if (pending) state.walkOnNextFlush = true;
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
function flushSerializerGlobals(boundary) {
|
|
3042
|
+
const { state } = boundary;
|
|
3043
|
+
if (state.hasWrittenGlobals) return;
|
|
3044
|
+
state.hasWrittenGlobals = true;
|
|
3045
|
+
const globals = getFilteredGlobals(state.$global);
|
|
3046
|
+
if (globals) {
|
|
3047
|
+
state.needsWalkerRuntime = true;
|
|
3048
|
+
state.resumes = concatSequence(state.resumes, stringifyScopes(state.serializer, [[
|
|
3049
|
+
0,
|
|
3050
|
+
globals,
|
|
3051
|
+
globals
|
|
3052
|
+
]], boundary));
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
function readyBatch(state, channel, deps, resumes) {
|
|
3056
|
+
const readyId = channel.readyId;
|
|
3057
|
+
const positions = state.readyPositions ||= {};
|
|
3058
|
+
const own = positions[readyId] ||= { [readyId]: 0 };
|
|
3059
|
+
let wait = "";
|
|
3060
|
+
for (let cur = channel.parent; cur.readyId; cur = cur.parent) {
|
|
3061
|
+
const id = cur.readyId;
|
|
3062
|
+
const position = deps?.has(id) ? positions[id][id] : 0;
|
|
3063
|
+
if (!(own[id] >= position)) {
|
|
3064
|
+
own[id] = position;
|
|
3065
|
+
wait += (wait ? "," : "{") + toObjectKey(id) + ":" + position;
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
if (resumes) own[readyId]++;
|
|
3069
|
+
return concatSequence(wait && wait + "}", resumes);
|
|
3070
|
+
}
|
|
3071
|
+
function getFilteredGlobals($global) {
|
|
3072
|
+
const serializedGlobals = $global.serializedGlobals;
|
|
3073
|
+
if (!serializedGlobals) return 0;
|
|
3074
|
+
let filtered = 0;
|
|
3075
|
+
if (Array.isArray(serializedGlobals)) for (const key of serializedGlobals) {
|
|
3076
|
+
const value = $global[key];
|
|
3077
|
+
if (value !== void 0) (filtered ||= {})[key] = value;
|
|
3078
|
+
}
|
|
3079
|
+
else for (const key in serializedGlobals) if (serializedGlobals[key]) {
|
|
3080
|
+
const value = $global[key];
|
|
3081
|
+
if (value !== void 0) (filtered ||= {})[key] = value;
|
|
3082
|
+
}
|
|
3083
|
+
return filtered;
|
|
3084
|
+
}
|
|
3085
|
+
function concatEffects(a, b) {
|
|
3086
|
+
return a ? b ? a + " " + b : a : b;
|
|
3087
|
+
}
|
|
3088
|
+
function concatSequence(a, b) {
|
|
3089
|
+
return a ? b ? a + "," + b : a : b;
|
|
3090
|
+
}
|
|
3091
|
+
function concatScripts(a, b) {
|
|
3092
|
+
return a ? b ? a + ";" + b : a : b;
|
|
3093
|
+
}
|
|
3094
|
+
const tick = globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask || ((cb) => Promise.resolve().then(cb));
|
|
3095
|
+
let tickQueue;
|
|
3096
|
+
function queueTick(cb) {
|
|
3097
|
+
if (tickQueue) tickQueue.add(cb);
|
|
3098
|
+
else {
|
|
3099
|
+
tickQueue = /* @__PURE__ */ new Set([cb]);
|
|
3100
|
+
tick(flushTickQueue);
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
function offTick(cb) {
|
|
3104
|
+
tickQueue?.delete(cb);
|
|
3105
|
+
}
|
|
3106
|
+
function flushTickQueue() {
|
|
3107
|
+
const queue = tickQueue;
|
|
3108
|
+
tickQueue = void 0;
|
|
3109
|
+
for (const cb of queue) try {
|
|
3110
|
+
cb(true);
|
|
3111
|
+
} catch (err) {
|
|
3112
|
+
tick(() => {
|
|
3113
|
+
throw err;
|
|
3114
|
+
});
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
// src/html/content.ts
|
|
3118
|
+
function _to_text(val) {
|
|
3119
|
+
assertValidTextValue(val);
|
|
3120
|
+
return val || val === 0 ? val + "" : "";
|
|
3121
|
+
}
|
|
3122
|
+
function _unescaped(val) {
|
|
3123
|
+
assertValidTextValue(val);
|
|
3124
|
+
return val ? val + "" : val === 0 ? "0" : "";
|
|
3125
|
+
}
|
|
3126
|
+
const unsafeXMLReg = /[<&\r]/g;
|
|
3127
|
+
const replaceUnsafeXML = (c) => c === "&" ? "&" : c === "<" ? "<" : " ";
|
|
3128
|
+
const escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str;
|
|
3129
|
+
function _escape(val) {
|
|
3130
|
+
assertValidTextValue(val);
|
|
3131
|
+
return val || val === 0 ? typeof val === "number" ? val + "" : escapeXMLStr(val + "") : "";
|
|
3132
|
+
}
|
|
3133
|
+
const unsafeScriptReg = /<(\/?script|!--)/gi;
|
|
3134
|
+
const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\u003C$1") : str;
|
|
3135
|
+
function _escape_script(val) {
|
|
3136
|
+
assertValidTextValue(val);
|
|
3137
|
+
return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
|
|
3138
|
+
}
|
|
3139
|
+
const unsafeScriptTemplateLiteralReg = /[`\\\r]|\$\{|<(?=\/?script|!--)/gi;
|
|
3140
|
+
const replaceUnsafeScriptTemplateLiteral = (c) => c === "<" ? "\\x3C" : c === "\r" ? "\\r" : "\\" + c;
|
|
3141
|
+
const quoteScriptTemplateLiteral = (str) => "`" + (unsafeScriptTemplateLiteralReg.test(str) ? str.replace(unsafeScriptTemplateLiteralReg, replaceUnsafeScriptTemplateLiteral) : str) + "`";
|
|
3142
|
+
const unsafeStyleReg = /<(\/style)/gi;
|
|
3143
|
+
const escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C$1") : str;
|
|
3144
|
+
function _escape_style(val) {
|
|
3145
|
+
assertValidTextValue(val);
|
|
3146
|
+
return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
|
|
3147
|
+
}
|
|
3148
|
+
function _escape_style_value(val) {
|
|
3149
|
+
assertValidTextValue(val);
|
|
3150
|
+
return val || val === 0 ? escapeStyleValue(val + "") : "";
|
|
3151
|
+
}
|
|
3152
|
+
const unsafeCommentReg = />/g;
|
|
3153
|
+
function escapeCommentStr(str) {
|
|
3154
|
+
if (unsafeCommentReg.test(str)) str = str.replace(unsafeCommentReg, ">");
|
|
3155
|
+
return str.startsWith(getState().commentPrefix) ? "&#" + str.charCodeAt(0) + ";" + str.slice(1) : str;
|
|
3156
|
+
}
|
|
3157
|
+
function _escape_comment(val) {
|
|
3158
|
+
assertValidTextValue(val);
|
|
3159
|
+
return val ? escapeCommentStr(val + "") : val === 0 ? "0" : "";
|
|
3160
|
+
}
|
|
3161
|
+
// src/html/dynamic-tag.ts
|
|
3162
|
+
const voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/;
|
|
3163
|
+
function _dynamic_tag(scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, markerGuard, tagVar) {
|
|
3164
|
+
const shouldResume = markerGuard !== 0;
|
|
3165
|
+
const renderer = normalizeDynamicRenderer(tag);
|
|
3166
|
+
const state = getState();
|
|
3167
|
+
const branchId = _peek_scope_id();
|
|
3168
|
+
let rendered;
|
|
3169
|
+
let result;
|
|
3170
|
+
if (typeof renderer === "string") {
|
|
3171
|
+
assertValidTagName(renderer);
|
|
3172
|
+
const nodeAccessor = `#${renderer.toLowerCase()}/0`;
|
|
3173
|
+
const input = (inputIsArgs ? inputOrArgs[0] : inputOrArgs) || {};
|
|
3174
|
+
assertNoNativeAttrTags(renderer, input);
|
|
3175
|
+
rendered = true;
|
|
3176
|
+
_scope_id();
|
|
3177
|
+
_html(`<${renderer}${_attrs(input, nodeAccessor, branchId, renderer)}>`);
|
|
3178
|
+
if (!voidElementsReg.test(renderer)) {
|
|
3179
|
+
const renderContent = content || input.content;
|
|
3180
|
+
if (renderer === "textarea") {
|
|
3181
|
+
if (renderContent) throw new Error("A dynamic tag rendering a `<textarea>` cannot have `content` and must use the `value` attribute instead.");
|
|
3182
|
+
_html(_attrs_textarea_value(branchId, nodeAccessor, input));
|
|
3183
|
+
} else if (renderer === "select" && ("value" in input || "valueChange" in input)) _attr_select_value(branchId, nodeAccessor, input.value, input.valueChange, renderContent ? () => _attr_content(nodeAccessor, branchId, renderContent, markerGuard) : void 0, 1);
|
|
3184
|
+
else if (renderContent) _attr_content(nodeAccessor, branchId, renderContent, markerGuard);
|
|
3185
|
+
_html(`</${renderer}>`);
|
|
3186
|
+
} else if (content) throw new Error(`Body content is not supported for the \`<${renderer}>\` tag.`);
|
|
3187
|
+
const childScope = getScopeById(branchId);
|
|
3188
|
+
const needsScript = childScope && (childScope["EventAttributes:" + nodeAccessor] || childScope["ControlledHandler:" + nodeAccessor]);
|
|
3189
|
+
if (needsScript) {
|
|
3190
|
+
writeScope(branchId, { [Renderer]: renderer });
|
|
3191
|
+
_script(branchId, DYNAMIC_TAG_SCRIPT_REGISTER_ID);
|
|
3192
|
+
}
|
|
3193
|
+
if (shouldResume || needsScript) _html(state.mark("(", scopeId + " " + accessor + " " + branchId));
|
|
3194
|
+
result = _el(scopeId, DYNAMIC_TAG_VAR_REGISTER_ID + accessor);
|
|
3195
|
+
} else {
|
|
3196
|
+
if (tagVar && renderer?.["lazy"]) throw new Error(`A dynamic tag with a [tag variable](https://markojs.com/docs/reference/language#tag-variables) rendered \`${renderer["id"]}\`, which is lazily loaded, so it does not support one. Import it without \`load\`, or remove the variable.`);
|
|
3197
|
+
const chunk = $chunk;
|
|
3198
|
+
const beforeBranch = shouldResume ? deferBranchStart(chunk) : void 0;
|
|
3199
|
+
const render = () => {
|
|
3200
|
+
if (renderer) try {
|
|
3201
|
+
_set_scope_reason(shouldResume ? ALL_GROUPS : 0);
|
|
3202
|
+
return inputIsArgs ? renderer(...inputOrArgs) : renderer(content ? {
|
|
3203
|
+
...inputOrArgs,
|
|
3204
|
+
content
|
|
3205
|
+
} : inputOrArgs);
|
|
3206
|
+
} finally {
|
|
3207
|
+
_set_scope_reason(void 0);
|
|
3208
|
+
}
|
|
3209
|
+
else if (content) content();
|
|
3210
|
+
};
|
|
3211
|
+
result = shouldResume ? withBranchId(branchId, render) : render();
|
|
3212
|
+
rendered = _peek_scope_id() !== branchId;
|
|
3213
|
+
if (beforeBranch !== void 0) {
|
|
3214
|
+
applyBranchStart(chunk, beforeBranch, rendered);
|
|
3215
|
+
_html(state.mark("]", scopeId + " " + accessor + (rendered ? " " + branchId : "")));
|
|
3216
|
+
if (renderer) _existing_scope(branchId);
|
|
3217
|
+
}
|
|
3218
|
+
}
|
|
3219
|
+
if (rendered) {
|
|
3220
|
+
if (shouldResume) writeScope(scopeId, { [ConditionalRenderer + accessor]: rendererKey(renderer) });
|
|
3221
|
+
} else _scope_id();
|
|
3222
|
+
return result;
|
|
3223
|
+
}
|
|
3224
|
+
function _content(id, fn, scopeId) {
|
|
3225
|
+
fn["id"] = id;
|
|
3226
|
+
fn[Owner] = scopeId;
|
|
3227
|
+
return fn;
|
|
3228
|
+
}
|
|
3229
|
+
function _content_resume(id, fn, scopeId, locals) {
|
|
3230
|
+
return _resume(_content(id, fn, scopeId), id, scopeId, locals);
|
|
3231
|
+
}
|
|
3232
|
+
// src/html/template.ts
|
|
3233
|
+
const CONSUMED_RESULT_MESSAGE = "Cannot read from a consumed render result";
|
|
3234
|
+
const _template = (templateId, renderer, page) => {
|
|
3235
|
+
renderer.render = render;
|
|
3236
|
+
renderer[Embed] = !page;
|
|
3237
|
+
renderer._ = renderer;
|
|
3238
|
+
renderer.mount = () => {
|
|
3239
|
+
throw new Error(`mount() is not implemented for the HTML compilation of a Marko template`);
|
|
3240
|
+
};
|
|
3241
|
+
return _content_resume(templateId, renderer);
|
|
3242
|
+
};
|
|
3243
|
+
function render(input = {}) {
|
|
3244
|
+
return startRender(this, input, State);
|
|
3245
|
+
}
|
|
3246
|
+
function startRender(template, input, StateClass) {
|
|
3247
|
+
let { $global } = input;
|
|
3248
|
+
if ($global) {
|
|
3249
|
+
({$global, ...input} = input);
|
|
3250
|
+
$global = {
|
|
3251
|
+
runtimeId: "M",
|
|
3252
|
+
renderId: getDefaultRenderId(template),
|
|
3253
|
+
...$global
|
|
3254
|
+
};
|
|
3255
|
+
if (!String($global.runtimeId).match(/^[_a-z][_a-z0-9]*$/i)) throw new Error(`Invalid runtimeId: "${$global.runtimeId}". The runtimeId must start with a letter or underscore and only contain letters, numbers, and underscores.`);
|
|
3256
|
+
if (!String($global.renderId).match(/^[_a-z][_a-z0-9]*$/i)) throw new Error(`Invalid renderId: "${$global.renderId}". The renderId must start with a letter or underscore and only contain letters, numbers, and underscores.`);
|
|
3257
|
+
} else $global = {
|
|
3258
|
+
runtimeId: "M",
|
|
3259
|
+
renderId: getDefaultRenderId(template)
|
|
3260
|
+
};
|
|
3261
|
+
const state = new StateClass($global);
|
|
3262
|
+
const head = new Chunk(new Boundary(state, $global.signal), null, null, state);
|
|
3263
|
+
if (template["embed"]) head.render(() => writeWaitReady(template["id"], template, input));
|
|
3264
|
+
else head.render(template, input);
|
|
3265
|
+
return new ServerRendered(head);
|
|
3266
|
+
}
|
|
3267
|
+
function getDefaultRenderId(template) {
|
|
3268
|
+
if (template["embed"]) {
|
|
3269
|
+
const ENCODE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
|
|
3270
|
+
let n = Math.random() * 4294967296 >>> 0;
|
|
3271
|
+
let r = ENCODE_CHARS[n % 52];
|
|
3272
|
+
for (n = n / 52 | 0; n; n = n / 63 | 0) r += ENCODE_CHARS[n % 63];
|
|
3273
|
+
return r;
|
|
3274
|
+
}
|
|
3275
|
+
return "_";
|
|
3276
|
+
}
|
|
3277
|
+
var ServerRendered = class {
|
|
3278
|
+
#head;
|
|
3279
|
+
#cachedPromise = null;
|
|
3280
|
+
constructor(head) {
|
|
3281
|
+
this.#head = head;
|
|
3282
|
+
}
|
|
3283
|
+
[Symbol.asyncIterator]() {
|
|
3284
|
+
let resolve;
|
|
3285
|
+
let reject;
|
|
3286
|
+
let value = "";
|
|
3287
|
+
let done = false;
|
|
3288
|
+
let aborted = false;
|
|
3289
|
+
let reason;
|
|
3290
|
+
const boundary = this.#read((html) => {
|
|
3291
|
+
value += html;
|
|
3292
|
+
if (resolve) {
|
|
3293
|
+
const settle = resolve;
|
|
3294
|
+
resolve = reject = void 0;
|
|
3295
|
+
settle({
|
|
3296
|
+
value,
|
|
3297
|
+
done
|
|
3298
|
+
});
|
|
3299
|
+
value = "";
|
|
3300
|
+
}
|
|
3301
|
+
}, (err) => {
|
|
3302
|
+
aborted = true;
|
|
3303
|
+
reason = err;
|
|
3304
|
+
if (reject) {
|
|
3305
|
+
const settle = reject;
|
|
3306
|
+
resolve = reject = void 0;
|
|
3307
|
+
settle(err);
|
|
3308
|
+
}
|
|
3309
|
+
}, () => {
|
|
3310
|
+
done = true;
|
|
3311
|
+
if (resolve) {
|
|
3312
|
+
const settle = resolve;
|
|
3313
|
+
resolve = reject = void 0;
|
|
3314
|
+
settle({
|
|
3315
|
+
value,
|
|
3316
|
+
done: !value
|
|
3317
|
+
});
|
|
3318
|
+
value = "";
|
|
3319
|
+
}
|
|
3320
|
+
});
|
|
3321
|
+
return {
|
|
3322
|
+
next() {
|
|
3323
|
+
if (aborted) return Promise.reject(reason);
|
|
3324
|
+
else if (value) {
|
|
3325
|
+
const result = {
|
|
3326
|
+
value,
|
|
3327
|
+
done: false
|
|
3328
|
+
};
|
|
3329
|
+
value = "";
|
|
3330
|
+
return Promise.resolve(result);
|
|
3331
|
+
} else if (done) return Promise.resolve({
|
|
3332
|
+
value: "",
|
|
3333
|
+
done
|
|
3334
|
+
});
|
|
3335
|
+
else return new Promise(exec);
|
|
3336
|
+
},
|
|
3337
|
+
throw(error) {
|
|
3338
|
+
if (!(done || aborted)) boundary?.abort(error);
|
|
3339
|
+
return Promise.resolve({
|
|
3340
|
+
value: "",
|
|
3341
|
+
done: true
|
|
3342
|
+
});
|
|
3343
|
+
},
|
|
3344
|
+
return(value) {
|
|
3345
|
+
if (!(done || aborted)) boundary?.abort(/* @__PURE__ */ new Error("Iterator returned before consumed."));
|
|
3346
|
+
return Promise.resolve({
|
|
3347
|
+
value,
|
|
3348
|
+
done: true
|
|
3349
|
+
});
|
|
3350
|
+
}
|
|
3351
|
+
};
|
|
3352
|
+
function exec(_resolve, _reject) {
|
|
3353
|
+
resolve = _resolve;
|
|
3354
|
+
reject = _reject;
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3357
|
+
pipe(stream) {
|
|
3358
|
+
this.#read((html) => {
|
|
3359
|
+
stream.write(html);
|
|
3360
|
+
stream.flush?.();
|
|
3361
|
+
}, (err) => {
|
|
3362
|
+
const socket = "socket" in stream && stream.socket;
|
|
3363
|
+
if (socket && typeof socket.destroySoon === "function") socket.destroySoon();
|
|
3364
|
+
else if (stream.destroy) stream.destroy();
|
|
3365
|
+
else stream.end();
|
|
3366
|
+
if (!stream.emit?.("error", err)) throw err;
|
|
3367
|
+
}, () => {
|
|
3368
|
+
stream.end();
|
|
3369
|
+
});
|
|
3370
|
+
}
|
|
3371
|
+
toReadable() {
|
|
3372
|
+
let cancelled = false;
|
|
3373
|
+
let started = false;
|
|
3374
|
+
let boundary;
|
|
3375
|
+
const encoder = new TextEncoder();
|
|
3376
|
+
return new ReadableStream({
|
|
3377
|
+
pull: (ctrl) => {
|
|
3378
|
+
if (started) return;
|
|
3379
|
+
started = true;
|
|
3380
|
+
boundary = this.#read((html) => {
|
|
3381
|
+
ctrl.enqueue(encoder.encode(html));
|
|
3382
|
+
}, (err) => {
|
|
3383
|
+
boundary = void 0;
|
|
3384
|
+
if (!cancelled) ctrl.error(err);
|
|
3385
|
+
}, () => {
|
|
3386
|
+
boundary = void 0;
|
|
3387
|
+
ctrl.close();
|
|
3388
|
+
});
|
|
3389
|
+
},
|
|
3390
|
+
cancel: (reason) => {
|
|
3391
|
+
cancelled = true;
|
|
3392
|
+
boundary?.abort(reason);
|
|
3393
|
+
}
|
|
3394
|
+
}, { highWaterMark: 0 });
|
|
3395
|
+
}
|
|
3396
|
+
then(onfulfilled, onrejected) {
|
|
3397
|
+
return this.#promise().then(onfulfilled, onrejected);
|
|
3398
|
+
}
|
|
3399
|
+
catch(onrejected) {
|
|
3400
|
+
return this.#promise().catch(onrejected);
|
|
3401
|
+
}
|
|
3402
|
+
finally(onfinally) {
|
|
3403
|
+
return this.#promise().finally(onfinally);
|
|
3404
|
+
}
|
|
3405
|
+
#promise() {
|
|
3406
|
+
return this.#cachedPromise ||= new Promise((resolve, reject) => {
|
|
3407
|
+
let head = this.#head;
|
|
3408
|
+
this.#head = null;
|
|
3409
|
+
if (!head) return reject(/* @__PURE__ */ new Error(CONSUMED_RESULT_MESSAGE));
|
|
3410
|
+
const { boundary } = head;
|
|
3411
|
+
let html = "";
|
|
3412
|
+
(boundary.onNext = () => {
|
|
3413
|
+
switch (!boundary.count && boundary.flush()) {
|
|
3414
|
+
case 2:
|
|
3415
|
+
settle(boundary);
|
|
3416
|
+
reject(boundary.reason);
|
|
3417
|
+
break;
|
|
3418
|
+
case 0:
|
|
3419
|
+
head = head.consume(boundary);
|
|
3420
|
+
if (boundary.aborted) break;
|
|
3421
|
+
html += head.flushHTML(boundary);
|
|
3422
|
+
if (!(boundary.count || boundary.aborted)) {
|
|
3423
|
+
settle(boundary);
|
|
3424
|
+
resolve(html);
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
})();
|
|
3428
|
+
});
|
|
3429
|
+
}
|
|
3430
|
+
#read(onWrite, onAbort, onClose) {
|
|
3431
|
+
let tick = true;
|
|
3432
|
+
let flushing = false;
|
|
3433
|
+
let again = false;
|
|
3434
|
+
let head = this.#head;
|
|
3435
|
+
this.#head = null;
|
|
3436
|
+
if (!head) {
|
|
3437
|
+
onAbort(/* @__PURE__ */ new Error(CONSUMED_RESULT_MESSAGE));
|
|
3438
|
+
return;
|
|
3439
|
+
}
|
|
3440
|
+
const { boundary } = head;
|
|
3441
|
+
const onNext = boundary.onNext = (write) => {
|
|
3442
|
+
if (flushing) {
|
|
3443
|
+
again = true;
|
|
3444
|
+
return;
|
|
3445
|
+
}
|
|
3446
|
+
flushing = true;
|
|
3447
|
+
do {
|
|
3448
|
+
again = false;
|
|
3449
|
+
const status = boundary.flush();
|
|
3450
|
+
if (status === 2) {
|
|
3451
|
+
if (!tick) offTick(onNext);
|
|
3452
|
+
settle(boundary);
|
|
3453
|
+
onAbort(boundary.reason);
|
|
3454
|
+
return;
|
|
3455
|
+
}
|
|
3456
|
+
if (write || status === 0) {
|
|
3457
|
+
head = head.consume(boundary);
|
|
3458
|
+
if (boundary.aborted) continue;
|
|
3459
|
+
const html = head.flushHTML(boundary);
|
|
3460
|
+
if (boundary.aborted) continue;
|
|
3461
|
+
if (html) onWrite(html);
|
|
3462
|
+
if (!boundary.count) {
|
|
3463
|
+
if (!tick) offTick(onNext);
|
|
3464
|
+
settle(boundary);
|
|
3465
|
+
onClose();
|
|
3466
|
+
return;
|
|
3467
|
+
}
|
|
3468
|
+
if (write) tick = true;
|
|
3469
|
+
} else if (tick) {
|
|
3470
|
+
tick = false;
|
|
3471
|
+
queueTick(onNext);
|
|
3472
|
+
}
|
|
3473
|
+
} while (again);
|
|
3474
|
+
flushing = false;
|
|
3475
|
+
};
|
|
3476
|
+
onNext();
|
|
3477
|
+
return boundary;
|
|
3478
|
+
}
|
|
3479
|
+
toString() {
|
|
3480
|
+
const head = this.#head;
|
|
3481
|
+
this.#head = null;
|
|
3482
|
+
if (!head) throw /* @__PURE__ */ new Error(CONSUMED_RESULT_MESSAGE);
|
|
3483
|
+
const { boundary } = head;
|
|
3484
|
+
const html = boundary.flush() === 0 ? head.consume(boundary).flushHTML(boundary) : "";
|
|
3485
|
+
if (boundary.count) boundary.abort(/* @__PURE__ */ new Error("Cannot consume asynchronous render with 'toString'"));
|
|
3486
|
+
settle(boundary);
|
|
3487
|
+
if (boundary.aborted) throw boundary.reason;
|
|
3488
|
+
return html;
|
|
3489
|
+
}
|
|
3490
|
+
};
|
|
3491
|
+
function settle(boundary) {
|
|
3492
|
+
boundary.onNext = NOOP;
|
|
3493
|
+
boundary.state.$global.signal?.removeEventListener("abort", boundary);
|
|
3494
|
+
}
|
|
3495
|
+
// src/html/assets.ts
|
|
3496
|
+
const kAssets = Symbol();
|
|
3497
|
+
const kHead = Symbol();
|
|
3498
|
+
function withLoadAssets(template, id, flush, assetId, triggers) {
|
|
3499
|
+
const renderer = (input) => {
|
|
3500
|
+
writeLoadAsset(assetId, flush, triggers);
|
|
3501
|
+
return writeWaitReady(assetId, template(), input);
|
|
3502
|
+
};
|
|
3503
|
+
renderer[Lazy] = 1;
|
|
3504
|
+
_template(id, renderer);
|
|
3505
|
+
return renderer;
|
|
3506
|
+
}
|
|
3507
|
+
function writeLoadAsset(assetId, flush, triggers) {
|
|
3508
|
+
const g = $global();
|
|
3509
|
+
writeAsset(g, addAsset(g, assetId, flush, triggers));
|
|
3510
|
+
}
|
|
3511
|
+
function withPageAssets(template, flush, assetId, runtimeId) {
|
|
3512
|
+
return Object.assign((input) => {
|
|
3513
|
+
const g = $global();
|
|
3514
|
+
if (runtimeId) {
|
|
3515
|
+
if (!g[kAssets]) {
|
|
3516
|
+
if (g.runtimeId !== "M" && g.runtimeId !== runtimeId) throw new Error(`$global.runtimeId ("${g.runtimeId}") conflicts with the runtimeId this entry was compiled with ("${runtimeId}").`);
|
|
3517
|
+
g.runtimeId = runtimeId;
|
|
3518
|
+
} else if (g.runtimeId !== runtimeId) console.error(`A page entry compiled with runtimeId "${runtimeId}" is nested in a render using runtimeId "${g.runtimeId}", so its content cannot resume.`);
|
|
3519
|
+
}
|
|
3520
|
+
const asset = addAsset(g, assetId, flush);
|
|
3521
|
+
if (g.__flush__) {
|
|
3522
|
+
writeAsset(g, asset);
|
|
3523
|
+
return writeWaitReady(assetId, template, input);
|
|
3524
|
+
}
|
|
3525
|
+
g.__flush__ = flushPage;
|
|
3526
|
+
return template(input);
|
|
3527
|
+
}, template);
|
|
3528
|
+
}
|
|
3529
|
+
function _flush_head() {
|
|
3530
|
+
const g = $global();
|
|
3531
|
+
if (!g[kAssets]) return "";
|
|
3532
|
+
g[kHead] = true;
|
|
3533
|
+
return takeAssets(g, catchableBoundary());
|
|
3534
|
+
}
|
|
3535
|
+
function flushPage(g, html) {
|
|
3536
|
+
return takeAssets(g, null) + html;
|
|
3537
|
+
}
|
|
3538
|
+
function takeAssets(g, at) {
|
|
3539
|
+
let block = "";
|
|
3540
|
+
let defer = "";
|
|
3541
|
+
for (const asset of g[kAssets]) if (asset.htmlAt === void 0) {
|
|
3542
|
+
asset.htmlAt = at;
|
|
3543
|
+
block += blockHTML(g, asset);
|
|
3544
|
+
if (!asset.triggers) defer += deferHTML(g, asset);
|
|
3545
|
+
}
|
|
3546
|
+
return block + defer;
|
|
3547
|
+
}
|
|
3548
|
+
function writeAsset(g, asset) {
|
|
3549
|
+
if (needsWrite(asset.htmlAt)) {
|
|
3550
|
+
asset.htmlAt = void 0;
|
|
3551
|
+
if (g[kHead] || g.__flush__ !== flushPage) {
|
|
3552
|
+
const block = blockHTML(g, asset);
|
|
3553
|
+
_html(block + (asset.triggers ? "" : deferHTML(g, asset)));
|
|
3554
|
+
if (block && isInResumedBranch()) writeScript(`document.head.insertAdjacentHTML("beforeend",${quoteScriptTemplateLiteral(block)})`);
|
|
3555
|
+
asset.htmlAt = catchableBoundary();
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
if (asset.triggers && needsWrite(asset.scriptAt)) {
|
|
3559
|
+
const defer = deferHTML(g, asset);
|
|
3560
|
+
if (defer) writeScript(asset.script ||= triggerScript(asset.id, defer, asset.triggers));
|
|
3561
|
+
asset.scriptAt = catchableBoundary();
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
function needsWrite(at) {
|
|
3565
|
+
return at === void 0 || at !== null && mayDrop(at);
|
|
3566
|
+
}
|
|
3567
|
+
function blockHTML(g, asset) {
|
|
3568
|
+
return asset.block ??= asset.flush(g, "block", asset.id);
|
|
3569
|
+
}
|
|
3570
|
+
function deferHTML(g, asset) {
|
|
3571
|
+
return asset.defer ??= asset.flush(g, "defer", asset.id);
|
|
3572
|
+
}
|
|
3573
|
+
function addAsset(g, id, flush, triggers) {
|
|
3574
|
+
const assets = g[kAssets] ||= [];
|
|
3575
|
+
let asset = assets.find((a) => a.id === id);
|
|
3576
|
+
if (!asset) assets.push(asset = {
|
|
3577
|
+
id,
|
|
3578
|
+
flush,
|
|
3579
|
+
triggers,
|
|
3580
|
+
block: void 0,
|
|
3581
|
+
defer: void 0,
|
|
3582
|
+
script: void 0,
|
|
3583
|
+
htmlAt: void 0,
|
|
3584
|
+
scriptAt: void 0
|
|
3585
|
+
});
|
|
3586
|
+
else if (JSON.stringify(asset.triggers) !== JSON.stringify(triggers)) console.error(`The lazy asset "${id}" is imported with different \`load\` triggers; an asset must use one consistent trigger.`);
|
|
3587
|
+
return asset;
|
|
3588
|
+
}
|
|
3589
|
+
function triggerScript(id, html, triggers) {
|
|
3590
|
+
const htmlStr = quoteScriptTemplateLiteral(html);
|
|
3591
|
+
const insert = `(d=new Range().createContextualFragment(h),d.querySelectorAll("script").forEach(s=>s.onerror=()=>console.error(${quoteScriptTemplateLiteral(`The lazy module for "${id}" failed to load; its server-rendered content cannot become interactive.`)})),document.head.append(d))`;
|
|
3592
|
+
const exprs = triggers.map(triggerExpression);
|
|
3593
|
+
return `((h,d,l=$=>{d||${insert}})=>${exprs.length > 1 ? `{${exprs.join(";")}}` : exprs[0]})(${htmlStr})`;
|
|
3594
|
+
}
|
|
3595
|
+
function triggerExpression(trigger) {
|
|
3596
|
+
const options = trigger.options && toObjectExpression(trigger.options);
|
|
3597
|
+
switch (trigger.type) {
|
|
3598
|
+
case "visible": return `(e=>e&&new IntersectionObserver((e,i)=>e.some(e=>e.isIntersecting)&&i.disconnect()+l()${options ? `,${options}` : ""}).observe(e))(${querySelectorOrLoad(trigger.selector)})`;
|
|
3599
|
+
case "idle": return `(self.requestIdleCallback||l)(l${options ? `,${options}` : ""})`;
|
|
3600
|
+
case "media": return `(m=>m.matches?l():m.addEventListener("change",l,{once:1}))(matchMedia(${JSON.stringify(trigger.selector)}))`;
|
|
3601
|
+
default: return `(e=>e?.addEventListener("${trigger.type.slice(3)}",l,{once:1}))(${querySelectorOrLoad(trigger.selector)})`;
|
|
3602
|
+
}
|
|
3603
|
+
}
|
|
3604
|
+
function querySelectorOrLoad(selector) {
|
|
3605
|
+
return `document.querySelector(${JSON.stringify(selector)})||${`(console.warn(${JSON.stringify(`A lazy load trigger could not find an element matching "${selector}". The module was loaded immediately.`)}),l())`}`;
|
|
3606
|
+
}
|
|
3607
|
+
function toObjectExpression(options) {
|
|
3608
|
+
let result = "{";
|
|
3609
|
+
let sep = "";
|
|
3610
|
+
for (const key in options) if (Object.hasOwn(options, key)) {
|
|
3611
|
+
result += sep + toObjectKey(key) + ":" + JSON.stringify(options[key]);
|
|
3612
|
+
sep = ",";
|
|
3613
|
+
}
|
|
3614
|
+
return result + "}";
|
|
3615
|
+
}
|
|
3616
|
+
// src/common/for.ts
|
|
3617
|
+
function forIn(obj, cb) {
|
|
3618
|
+
for (const key in obj) cb(key, obj[key]);
|
|
3619
|
+
}
|
|
3620
|
+
function forOf(list, cb) {
|
|
3621
|
+
assertValidList(list);
|
|
3622
|
+
if (list) {
|
|
3623
|
+
let i = 0;
|
|
3624
|
+
for (const item of list) cb(item, i++);
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
function forTo(to, from, step, cb) {
|
|
3628
|
+
assertValidRangeBound("to", to);
|
|
3629
|
+
assertOptionalRangeNumber("from", from);
|
|
3630
|
+
assertOptionalRangeNumber("step", step);
|
|
3631
|
+
const start = from || 0;
|
|
3632
|
+
const delta = step || 1;
|
|
3633
|
+
for (let steps = (to - start) / delta, i = 0; i <= steps; i++) cb(start + i * delta);
|
|
3634
|
+
}
|
|
3635
|
+
function forUntil(until, from, step, cb) {
|
|
3636
|
+
assertValidRangeBound("until", until);
|
|
3637
|
+
assertOptionalRangeNumber("from", from);
|
|
3638
|
+
assertOptionalRangeNumber("step", step);
|
|
3639
|
+
const start = from || 0;
|
|
3640
|
+
const delta = step || 1;
|
|
3641
|
+
for (let steps = (until - start) / delta, i = 0; i < steps; i++) cb(start + i * delta);
|
|
3642
|
+
}
|
|
3643
|
+
// src/html/for.ts
|
|
3644
|
+
function forOfBy(by, item, index) {
|
|
3645
|
+
return by ? typeof by === "string" ? item[by] : by(item, index) : index;
|
|
3646
|
+
}
|
|
3647
|
+
function forInBy(by, name, value) {
|
|
3648
|
+
return by ? by(name, value) : name;
|
|
3649
|
+
}
|
|
3650
|
+
function forStepBy(by, index) {
|
|
3651
|
+
return by ? by(index) : index;
|
|
3652
|
+
}
|
|
3653
|
+
// src/html/control-flow.ts
|
|
3654
|
+
function _show_start(display, markerGuard, branchExprGuard, parentEndTag) {
|
|
3655
|
+
if (display) {
|
|
3656
|
+
if (resumesMarker(markerGuard, branchExprGuard, parentEndTag)) $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
|
|
3657
|
+
} else $chunk.writeHTML("<t hidden>");
|
|
3658
|
+
}
|
|
3659
|
+
function _show_end(scopeId, accessor, display, markerGuard, branchExprGuard, parentEndTag, singleNode) {
|
|
3660
|
+
const branchId = _scope_id();
|
|
3661
|
+
const wrap = !display;
|
|
3662
|
+
if (wrap) $chunk.writeHTML("</t>");
|
|
3663
|
+
writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
|
|
3664
|
+
}
|
|
3665
|
+
function _for_of(list, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
|
|
3666
|
+
forBranches(by, cb, iterateForOf(list, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
|
|
3667
|
+
}
|
|
3668
|
+
function iterateForOf(list, cb, by) {
|
|
3669
|
+
return (each) => each ? forOf(list, (item, index) => {
|
|
3670
|
+
const itemKey = forOfBy(by, item, index);
|
|
3671
|
+
each(itemKey, itemKey === index, item, index);
|
|
3672
|
+
}) : forOf(list, cb);
|
|
3673
|
+
}
|
|
3674
|
+
function _for_in(obj, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
|
|
3675
|
+
forBranches(by, cb, iterateForIn(obj, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
|
|
3676
|
+
}
|
|
3677
|
+
function iterateForIn(obj, cb, by) {
|
|
3678
|
+
return (each) => each ? forIn(obj, (key, value) => {
|
|
3679
|
+
each(forInBy(by, key, value), false, key, value);
|
|
3680
|
+
}) : forIn(obj, cb);
|
|
3681
|
+
}
|
|
3682
|
+
function _for_to(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
|
|
3683
|
+
forBranches(by, cb, iterateForTo(to, from, step, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
|
|
3684
|
+
}
|
|
3685
|
+
function iterateForTo(to, from, step, cb, by) {
|
|
3686
|
+
return (each) => {
|
|
3687
|
+
let index = 0;
|
|
3688
|
+
return each ? forTo(to, from, step, (value) => {
|
|
3689
|
+
const itemKey = forStepBy(by, value);
|
|
3690
|
+
each(itemKey, itemKey === index++, value);
|
|
3691
|
+
}) : forTo(to, from, step, cb);
|
|
3692
|
+
};
|
|
3693
|
+
}
|
|
3694
|
+
function _for_until(until, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
|
|
3695
|
+
forBranches(by, cb, iterateForUntil(until, from, step, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
|
|
3696
|
+
}
|
|
3697
|
+
function iterateForUntil(until, from, step, cb, by) {
|
|
3698
|
+
return (each) => {
|
|
3699
|
+
let index = 0;
|
|
3700
|
+
return each ? forUntil(until, from, step, (value) => {
|
|
3701
|
+
const itemKey = forStepBy(by, value);
|
|
3702
|
+
each(itemKey, itemKey === index++, value);
|
|
3703
|
+
}) : forUntil(until, from, step, cb);
|
|
3704
|
+
};
|
|
3705
|
+
}
|
|
3706
|
+
function checkLoopKeys(cb, iterate) {
|
|
3707
|
+
const seenKeys = /* @__PURE__ */ new Set();
|
|
3708
|
+
return (each) => iterate((itemKey, sameAsIndex, a, b) => {
|
|
3709
|
+
assertValidLoopKey(itemKey, seenKeys);
|
|
3710
|
+
if (each) each(itemKey, sameAsIndex, a, b);
|
|
3711
|
+
else cb(a, b);
|
|
3712
|
+
});
|
|
3713
|
+
}
|
|
3714
|
+
function forBranches(by, cb, iterate, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
|
|
3715
|
+
if (by) iterate = checkLoopKeys(cb, iterate);
|
|
3716
|
+
if (branchGuard === 0) {
|
|
3717
|
+
iterate(0);
|
|
3718
|
+
writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, "");
|
|
3719
|
+
return;
|
|
3720
|
+
}
|
|
3721
|
+
const { state } = $chunk.boundary;
|
|
3722
|
+
const resumeKeys = markerGuard !== 0;
|
|
3723
|
+
const resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag);
|
|
3724
|
+
let flushBranchIds = "";
|
|
3725
|
+
let loopScopes;
|
|
3726
|
+
iterate((itemKey, sameAsIndex, a, b) => {
|
|
3727
|
+
const branchId = _peek_scope_id();
|
|
3728
|
+
if (resumeMarker) {
|
|
3729
|
+
if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
|
|
3730
|
+
else {
|
|
3731
|
+
$chunk.writeHTML(state.mark("[", flushBranchIds));
|
|
3732
|
+
flushBranchIds = branchId + "";
|
|
3733
|
+
}
|
|
3734
|
+
}
|
|
3735
|
+
if (resumeMarker) withBranchId(branchId, cb, a, b);
|
|
3736
|
+
else cb(a, b);
|
|
3737
|
+
const branchScope = writeScope(branchId, resumeKeys && !sameAsIndex ? { [LoopKey]: itemKey } : {});
|
|
3738
|
+
if (!resumeMarker) loopScopes = push(loopScopes, branchScope);
|
|
3739
|
+
});
|
|
3740
|
+
if (loopScopes) writeScope(scopeId, { [BranchScopes + accessor]: loopScopes });
|
|
3741
|
+
writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
|
|
3742
|
+
}
|
|
3743
|
+
function _if(cb, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
|
|
3744
|
+
const resumeBranch = branchGuard !== 0;
|
|
3745
|
+
const resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag);
|
|
3746
|
+
const branchId = _peek_scope_id();
|
|
3747
|
+
const chunk = $chunk;
|
|
3748
|
+
const beforeBranch = resumeMarker && resumeBranch && !singleNode ? deferBranchStart(chunk) : void 0;
|
|
3749
|
+
const branchIndex = resumeBranch && resumeMarker ? withBranchId(branchId, cb) : cb();
|
|
3750
|
+
const shouldWriteBranch = resumeBranch && branchIndex !== void 0;
|
|
3751
|
+
if (beforeBranch !== void 0) applyBranchStart(chunk, beforeBranch, shouldWriteBranch);
|
|
3752
|
+
if (shouldWriteBranch && (branchIndex || !resumeMarker)) writeScope(scopeId, {
|
|
3753
|
+
[ConditionalRenderer + accessor]: branchIndex || void 0,
|
|
3754
|
+
[BranchScopes + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
|
|
3755
|
+
});
|
|
3756
|
+
writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, shouldWriteBranch ? " " + branchId : "");
|
|
3757
|
+
}
|
|
3758
|
+
function resumesMarker(markerGuard, branchExprGuard, parentEndTag) {
|
|
3759
|
+
return markerGuard !== 0 && (!parentEndTag || branchExprGuard !== 0);
|
|
3760
|
+
}
|
|
3761
|
+
function writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, branchIds) {
|
|
3762
|
+
const endTag = parentEndTag || "";
|
|
3763
|
+
if (resumesMarker(markerGuard, branchExprGuard, parentEndTag)) $chunk.writeHTML($chunk.boundary.state.mark(singleNode ? parentEndTag ? "}" : "|" : parentEndTag ? ")" : "]", scopeId + " " + accessor + branchIds) + endTag);
|
|
3764
|
+
else if (markerGuard !== 0) $chunk.writeHTML(endTag + _el_mark(scopeId, accessor));
|
|
3765
|
+
else $chunk.writeHTML(endTag);
|
|
3766
|
+
}
|
|
3767
|
+
function _await(scopeId, accessor, promise, content, markerGuard) {
|
|
3768
|
+
const resumeMarker = markerGuard !== 0;
|
|
3769
|
+
if (!isPromise(promise)) {
|
|
3770
|
+
if (resumeMarker) {
|
|
3771
|
+
const branchId = _peek_scope_id();
|
|
3772
|
+
$chunk.writeHTML($chunk.boundary.state.mark("[", ""));
|
|
3773
|
+
withBranchId(branchId, content, promise);
|
|
3774
|
+
$chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
|
|
3775
|
+
} else content(promise);
|
|
3776
|
+
return;
|
|
3777
|
+
}
|
|
3778
|
+
const chunk = $chunk;
|
|
3779
|
+
const { boundary } = chunk;
|
|
3780
|
+
const startId = _peek_scope_id();
|
|
3781
|
+
const after = chunk.next = chunk.forkRest(boundary);
|
|
3782
|
+
chunk.async = true;
|
|
3783
|
+
captureContext(chunk);
|
|
3784
|
+
boundary.startAsync();
|
|
3785
|
+
promise.then((value) => {
|
|
3786
|
+
if (chunk.async) {
|
|
3787
|
+
chunk.async = false;
|
|
3788
|
+
if (!boundary.aborted) {
|
|
3789
|
+
const { state } = boundary;
|
|
3790
|
+
chunk.render(() => {
|
|
3791
|
+
if (resumeMarker) {
|
|
3792
|
+
const branchId = _peek_scope_id();
|
|
3793
|
+
$chunk.writeHTML($chunk.boundary.state.mark("[", ""));
|
|
3794
|
+
withBranchId(branchId, () => withAsyncContent({ parent: getAsyncContent(chunk) }, content, value));
|
|
3795
|
+
$chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
|
|
3796
|
+
} else {
|
|
3797
|
+
const renderedSince = _peek_scope_id() !== startId;
|
|
3798
|
+
const async = { parent: getAsyncContent(chunk) };
|
|
3799
|
+
withAsyncContent(async, content, value);
|
|
3800
|
+
async.visit = renderedSince && (after.html || after.next) ? $chunk.boundary.state.mark("]", scopeId + " " + accessor) : "";
|
|
3801
|
+
if (async.resumed) $chunk.writeHTML(async.visit);
|
|
3802
|
+
async.end = $chunk;
|
|
3803
|
+
}
|
|
3804
|
+
});
|
|
3805
|
+
if (!chunk.async && boundary.pendingReorders?.delete(chunk)) state.reorder(chunk);
|
|
3806
|
+
boundary.endAsync();
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
}, (err) => {
|
|
3810
|
+
chunk.async = false;
|
|
3811
|
+
boundary.abort(err);
|
|
3812
|
+
});
|
|
3813
|
+
}
|
|
3814
|
+
function _try(scopeId, accessor, content, placeholderContent, catchContent, placeholderId, catchId) {
|
|
3815
|
+
const placeholderBranchId = placeholderContent ? _scope_id() : 0;
|
|
3816
|
+
const branchId = _peek_scope_id();
|
|
3817
|
+
const chunk = $chunk;
|
|
3818
|
+
const { boundary } = chunk;
|
|
3819
|
+
const { state } = boundary;
|
|
3820
|
+
const { resumeWrites } = boundary;
|
|
3821
|
+
const beforeBranch = deferBranchStart(chunk);
|
|
3822
|
+
const renderers = () => writeTryRenderers(branchId, catchContent && _resume(catchContent, catchId), placeholderContent && _resume(placeholderContent, placeholderId));
|
|
3823
|
+
const writesRenderers = tryBoundary(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content, catchContent, branchId, renderers);
|
|
3824
|
+
const keepsMarks = state.keepsTryMarks(chunk, resumeWrites);
|
|
3825
|
+
applyBranchStart(chunk, beforeBranch, keepsMarks);
|
|
3826
|
+
if (!keepsMarks) return;
|
|
3827
|
+
if (!writesRenderers) renderers();
|
|
3828
|
+
$chunk.writeHTML(state.mark("]", scopeId + " " + accessor + " " + branchId));
|
|
3829
|
+
}
|
|
3830
|
+
function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
|
|
3831
|
+
const chunk = $chunk;
|
|
3832
|
+
const { boundary } = chunk;
|
|
3833
|
+
const body = chunk.fork(boundary, null);
|
|
3834
|
+
if (body === body.render(content)) {
|
|
3835
|
+
chunk.append(body);
|
|
3836
|
+
return;
|
|
3837
|
+
}
|
|
3838
|
+
chunk.next = chunk.forkRest(boundary);
|
|
3839
|
+
captureContext(chunk);
|
|
3840
|
+
chunk.placeholder = {
|
|
3841
|
+
body,
|
|
3842
|
+
render: placeholder,
|
|
3843
|
+
branchId,
|
|
3844
|
+
scopeId,
|
|
3845
|
+
placeholderBranchId
|
|
3846
|
+
};
|
|
3847
|
+
}
|
|
3848
|
+
function tryBoundary(content, catchContent, branchId, renderers) {
|
|
3849
|
+
const chunk = $chunk;
|
|
3850
|
+
const { boundary } = chunk;
|
|
3851
|
+
const { state } = boundary;
|
|
3852
|
+
const bodyBoundary = new Boundary(state, void 0, boundary);
|
|
3853
|
+
if (catchContent) bodyBoundary.withinCatch = true;
|
|
3854
|
+
const body = chunk.fork(bodyBoundary, null);
|
|
3855
|
+
const bodyEnd = body.render(withBranchId, branchId, content);
|
|
3856
|
+
if (bodyBoundary.aborted) {
|
|
3857
|
+
if (!catchContent) throw bodyBoundary.reason;
|
|
3858
|
+
catchContent(bodyBoundary.reason);
|
|
3859
|
+
return true;
|
|
3860
|
+
}
|
|
3861
|
+
if (body === bodyEnd) {
|
|
3862
|
+
chunk.append(body);
|
|
3863
|
+
return false;
|
|
3864
|
+
}
|
|
3865
|
+
const renderersAtSettle = !bodyBoundary.resumeWrites;
|
|
3866
|
+
const bodyNext = bodyEnd.next = chunk.forkRest(boundary);
|
|
3867
|
+
chunk.next = body;
|
|
3868
|
+
boundary.startAsync();
|
|
3869
|
+
const reorderId = catchContent ? state.nextReorderId() : "";
|
|
3870
|
+
if (reorderId) {
|
|
3871
|
+
chunk.catchRange = {
|
|
3872
|
+
id: reorderId,
|
|
3873
|
+
end: bodyEnd
|
|
3874
|
+
};
|
|
3875
|
+
captureContext(chunk);
|
|
3876
|
+
}
|
|
3877
|
+
bodyBoundary.onNext = () => {
|
|
3878
|
+
if (boundary.aborted) return;
|
|
3879
|
+
if (bodyBoundary.aborted) {
|
|
3880
|
+
if (!reorderId) {
|
|
3881
|
+
boundary.abort(bodyBoundary.reason);
|
|
3882
|
+
return;
|
|
3883
|
+
}
|
|
3884
|
+
const streamed = !chunk.catchRange;
|
|
3885
|
+
const catchChunk = chunk.fork(boundary, null);
|
|
3886
|
+
chunk.catchRange = null;
|
|
3887
|
+
if (!renderersAtSettle) catchChunk.render(clearTryRenderers, branchId);
|
|
3888
|
+
const inOrder = catchChunk === catchChunk.render(catchContent, bodyBoundary.reason);
|
|
3889
|
+
if (boundary.aborted) return;
|
|
3890
|
+
if (bodyEnd.consumed || !inOrder) catchChunk.reorderBranch = branchId;
|
|
3891
|
+
if (bodyEnd.consumed) {
|
|
3892
|
+
catchChunk.reorderId = reorderId;
|
|
3893
|
+
state.reorder(catchChunk);
|
|
3894
|
+
} else {
|
|
3895
|
+
let reorder = null;
|
|
3896
|
+
if (!inOrder) reorder = catchChunk;
|
|
3897
|
+
else if (streamed) reorder = chunk.fork(boundary, null);
|
|
3898
|
+
if (reorder) reorder.reorderId = reorderId;
|
|
3899
|
+
const endMarker = state.mark("!", reorderId);
|
|
3900
|
+
let cut = body;
|
|
3901
|
+
while (cut.consumed) cut = cut.next;
|
|
3902
|
+
cut.async = false;
|
|
3903
|
+
cut.next = inOrder ? catchChunk : bodyNext;
|
|
3904
|
+
cut.html = streamed ? endMarker : inOrder ? "" : state.mark("!^", reorderId) + endMarker;
|
|
3905
|
+
cut.scripts = cut.effects = cut.lastEffect = "";
|
|
3906
|
+
cut.placeholder = cut.reorderId = cut.catchRange = null;
|
|
3907
|
+
cut.deferredReorder = reorder;
|
|
3908
|
+
if (inOrder) catchChunk.next = bodyNext;
|
|
3909
|
+
}
|
|
3910
|
+
boundary.endAsync();
|
|
3911
|
+
} else if (!bodyBoundary.count) {
|
|
3912
|
+
if (renderersAtSettle && bodyBoundary.resumeWrites) bodyEnd.render(renderers);
|
|
3913
|
+
chunk.catchRange = null;
|
|
3914
|
+
boundary.endAsync();
|
|
3915
|
+
} else boundary.onNext();
|
|
3916
|
+
};
|
|
3917
|
+
return renderersAtSettle;
|
|
3918
|
+
}
|
|
3919
|
+
function clearTryRenderers(branchId) {
|
|
3920
|
+
writeScope(branchId, {
|
|
3921
|
+
[CatchContent]: 0,
|
|
3922
|
+
[PlaceholderContent]: _scope_with_id(branchId)["#PlaceholderContent"] && 0
|
|
3923
|
+
});
|
|
3924
|
+
}
|
|
3925
|
+
function writeTryRenderers(branchId, catchContent, placeholderContent) {
|
|
3926
|
+
writeScope(branchId, {
|
|
3927
|
+
[CatchContent]: catchContent,
|
|
3928
|
+
[PlaceholderContent]: placeholderContent
|
|
3929
|
+
});
|
|
3930
|
+
}
|
|
3931
|
+
export { _subscribe as $, $global as A, _attrs_select_value as At, _hoist as B, _signal_read_error as Bt, _escape_comment as C, _attr_select_value as Ct, _to_text as D, _attrs_content as Dt, _escape_style_value as E, _attrs as Et, State as F, register as Ft, _resume as G, _html_mark as H, attrTag as Ht, _attr_content as I, _assert_class_toggles as It, _scope_id as J, _resume_branch as K, _el as L, _assert_hoist as Lt, Boundary as M, _style_html as Mt, Chunk as N, _textarea_value as Nt, _unescaped as O, _attrs_partial as Ot, NOOP as P, REGISTRY as Pt, _set_scope_reason as Q, _el_mark as R, _el_read_error as Rt, _escape as S, _attr_or as St, _escape_style as T, _attr_textarea_value as Tt, _id as U, attrTags as Ut, _html as V, setClassAPIRenderer as Vt, _peek_scope_id as W, _scope_with_id as X, _scope_reason as Y, _script as Z, writeLoadAsset as _, _attr_input_checkedValue as _t, _for_until as a, getChunk as at, _content_resume as b, _attr_nullish as bt, _show_start as c, joinHeldEffects as ct, forOf as d, writeScript as dt, _text_mark as et, forTo as f, _attr as ft, withPageAssets as g, _attr_input_checked as gt, withLoadAssets as h, _attr_details_or_dialog_open as ht, _for_to as i, _write_if as it, ALL_GROUPS as j, _attrs_textarea_value as jt, $chunk as k, _attrs_partial_content as kt, _try as l, withChunk as lt, _flush_head as m, _attr_class as mt, _for_in as n, _var as nt, _if as o, getScopeId as ot, forUntil as p, _attr_and as pt, _resume_locals as q, _for_of as r, _write_guard as rt, _show_end as s, isInResumedBranch as st, _await as t, _trailers as tt, forIn as u, writeScope as ut, _template as v, _attr_input_value as vt, _escape_script as w, _attr_style as wt, _dynamic_tag as x, _attr_option_value as xt, _content as y, _attr_nonce as yt, _existing_scope as z, _hoist_read_error as zt };
|