@marko/runtime-tags 0.1.1
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/helpers.d.ts +4 -0
- package/dist/common/types.d.ts +90 -0
- package/dist/debug/dom.js +1411 -0
- package/dist/debug/dom.js.map +7 -0
- package/dist/debug/dom.mjs +1388 -0
- package/dist/debug/dom.mjs.map +7 -0
- package/dist/debug/html.js +1323 -0
- package/dist/debug/html.js.map +7 -0
- package/dist/debug/html.mjs +1263 -0
- package/dist/debug/html.mjs.map +7 -0
- package/dist/dom/abort-signal.d.ts +3 -0
- package/dist/dom/control-flow.d.ts +14 -0
- package/dist/dom/dom.d.ts +14 -0
- package/dist/dom/event.d.ts +3 -0
- package/dist/dom/queue.d.ts +10 -0
- package/dist/dom/reconcile-domdiff.d.ts +2 -0
- package/dist/dom/reconcile-listdiff.d.ts +2 -0
- package/dist/dom/reconcile-longest-increasing-subsequence.d.ts +2 -0
- package/dist/dom/reconcile.d.ts +1 -0
- package/dist/dom/renderer.d.ts +20 -0
- package/dist/dom/resume.d.ts +8 -0
- package/dist/dom/schedule.d.ts +2 -0
- package/dist/dom/scope.d.ts +13 -0
- package/dist/dom/signals.d.ts +31 -0
- package/dist/dom/template.d.ts +11 -0
- package/dist/dom/walker.d.ts +4 -0
- package/dist/dom.d.ts +11 -0
- package/dist/dom.js +904 -0
- package/dist/dom.js.map +7 -0
- package/dist/dom.mjs +884 -0
- package/dist/dom.mjs.map +7 -0
- package/dist/html/attrs.d.ts +4 -0
- package/dist/html/content.d.ts +5 -0
- package/dist/html/dynamic-tag.d.ts +12 -0
- package/dist/html/reorder-runtime.d.ts +1 -0
- package/dist/html/serializer.d.ts +38 -0
- package/dist/html/template.d.ts +9 -0
- package/dist/html/writer.d.ts +40 -0
- package/dist/html.d.ts +6 -0
- package/dist/html.js +933 -0
- package/dist/html.js.map +7 -0
- package/dist/html.mjs +876 -0
- package/dist/html.mjs.map +7 -0
- package/package.json +39 -0
|
@@ -0,0 +1,1323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/html.ts
|
|
21
|
+
var html_exports = {};
|
|
22
|
+
__export(html_exports, {
|
|
23
|
+
$_streamData: () => $_streamData,
|
|
24
|
+
attr: () => attr,
|
|
25
|
+
attrs: () => attrs,
|
|
26
|
+
classAttr: () => classAttr,
|
|
27
|
+
createRenderFn: () => createRenderFn,
|
|
28
|
+
createRenderer: () => createRenderer,
|
|
29
|
+
createTemplate: () => createTemplate,
|
|
30
|
+
dynamicTagArgs: () => dynamicTagArgs,
|
|
31
|
+
dynamicTagInput: () => dynamicTagInput,
|
|
32
|
+
escapeAttrValue: () => escapeAttrValue,
|
|
33
|
+
escapeScript: () => escapeScript,
|
|
34
|
+
escapeStyle: () => escapeStyle,
|
|
35
|
+
escapeXML: () => escapeXML,
|
|
36
|
+
fork: () => fork,
|
|
37
|
+
getRegistryInfo: () => getRegistryInfo,
|
|
38
|
+
makeSerializable: () => makeSerializable,
|
|
39
|
+
markResumeControlEnd: () => markResumeControlEnd,
|
|
40
|
+
markResumeControlSingleNodeEnd: () => markResumeControlSingleNodeEnd,
|
|
41
|
+
markResumeNode: () => markResumeNode,
|
|
42
|
+
markResumeScopeStart: () => markResumeScopeStart,
|
|
43
|
+
maybeFlush: () => maybeFlush,
|
|
44
|
+
nextScopeId: () => nextScopeId,
|
|
45
|
+
nextTagId: () => nextTagId,
|
|
46
|
+
patchDynamicTag: () => patchDynamicTag,
|
|
47
|
+
peekSerializedScope: () => peekSerializedScope,
|
|
48
|
+
register: () => register,
|
|
49
|
+
serializedScope: () => serializedScope,
|
|
50
|
+
styleAttr: () => styleAttr,
|
|
51
|
+
toString: () => toString,
|
|
52
|
+
tryCatch: () => tryCatch,
|
|
53
|
+
tryPlaceholder: () => tryPlaceholder,
|
|
54
|
+
write: () => write,
|
|
55
|
+
writeEffect: () => writeEffect,
|
|
56
|
+
writeScope: () => writeScope
|
|
57
|
+
});
|
|
58
|
+
module.exports = __toCommonJS(html_exports);
|
|
59
|
+
|
|
60
|
+
// src/html/content.ts
|
|
61
|
+
function toString(val) {
|
|
62
|
+
return val || val === 0 ? val + "" : "";
|
|
63
|
+
}
|
|
64
|
+
var escapeXML = escapeIfNeeded((val) => {
|
|
65
|
+
let result = "";
|
|
66
|
+
let lastPos = 0;
|
|
67
|
+
for (let i = 0, len = val.length; i < len; i++) {
|
|
68
|
+
let replacement;
|
|
69
|
+
switch (val[i]) {
|
|
70
|
+
case "<":
|
|
71
|
+
replacement = "<";
|
|
72
|
+
break;
|
|
73
|
+
case "&":
|
|
74
|
+
replacement = "&";
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
result += val.slice(lastPos, i) + replacement;
|
|
80
|
+
lastPos = i + 1;
|
|
81
|
+
}
|
|
82
|
+
if (lastPos) {
|
|
83
|
+
return result + val.slice(lastPos);
|
|
84
|
+
}
|
|
85
|
+
return val;
|
|
86
|
+
});
|
|
87
|
+
var escapeScript = escapeIfNeeded(escapeTagEnding("script"));
|
|
88
|
+
var escapeStyle = escapeIfNeeded(escapeTagEnding("style"));
|
|
89
|
+
function escapeTagEnding(tagName) {
|
|
90
|
+
const openTag = `</${tagName}`;
|
|
91
|
+
const escaped = `<\\/${tagName}`;
|
|
92
|
+
return (val) => {
|
|
93
|
+
let result = "";
|
|
94
|
+
let lastPos = 0;
|
|
95
|
+
let i = val.indexOf(openTag, lastPos);
|
|
96
|
+
while (i !== -1) {
|
|
97
|
+
result += val.slice(lastPos, i) + escaped;
|
|
98
|
+
lastPos = i + 1;
|
|
99
|
+
i = val.indexOf(openTag, lastPos);
|
|
100
|
+
}
|
|
101
|
+
if (lastPos) {
|
|
102
|
+
return result + val.slice(lastPos);
|
|
103
|
+
}
|
|
104
|
+
return val;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function escapeAttrValue(val) {
|
|
108
|
+
const len = val.length;
|
|
109
|
+
let i = 0;
|
|
110
|
+
do {
|
|
111
|
+
switch (val[i]) {
|
|
112
|
+
case '"':
|
|
113
|
+
return quoteValue(val, i + 1, "'", "'");
|
|
114
|
+
case "'":
|
|
115
|
+
case ">":
|
|
116
|
+
case " ":
|
|
117
|
+
case " ":
|
|
118
|
+
case "\n":
|
|
119
|
+
case "\r":
|
|
120
|
+
case "\f":
|
|
121
|
+
return quoteValue(val, i + 1, '"', """);
|
|
122
|
+
default:
|
|
123
|
+
i++;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
} while (i < len);
|
|
127
|
+
return val;
|
|
128
|
+
}
|
|
129
|
+
function escapeIfNeeded(escape) {
|
|
130
|
+
return (val) => {
|
|
131
|
+
if (!val && val !== 0) {
|
|
132
|
+
return "‍";
|
|
133
|
+
}
|
|
134
|
+
switch (typeof val) {
|
|
135
|
+
case "string":
|
|
136
|
+
return escape(val);
|
|
137
|
+
case "boolean":
|
|
138
|
+
return "true";
|
|
139
|
+
case "number":
|
|
140
|
+
return val + "";
|
|
141
|
+
default:
|
|
142
|
+
return escape(val + "");
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function quoteValue(val, startPos, quote2, escaped) {
|
|
147
|
+
let result = quote2;
|
|
148
|
+
let lastPos = 0;
|
|
149
|
+
for (let i = startPos, len = val.length; i < len; i++) {
|
|
150
|
+
if (val[i] === quote2) {
|
|
151
|
+
result += val.slice(lastPos, i) + escaped;
|
|
152
|
+
lastPos = i + 1;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return result + (lastPos ? val.slice(lastPos) : val) + quote2;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/common/helpers.ts
|
|
159
|
+
function classValue(value) {
|
|
160
|
+
return toDelimitedString(value, " ", stringifyClassObject);
|
|
161
|
+
}
|
|
162
|
+
function stringifyClassObject(name, value) {
|
|
163
|
+
if (isVoid(value)) {
|
|
164
|
+
return "";
|
|
165
|
+
}
|
|
166
|
+
return name;
|
|
167
|
+
}
|
|
168
|
+
function styleValue(value) {
|
|
169
|
+
return toDelimitedString(value, ";", stringifyStyleObject);
|
|
170
|
+
}
|
|
171
|
+
var NON_DIMENSIONAL = /^(--|ta|or|li|z)|n-c|i(do|nk|m|t)|w$|we/;
|
|
172
|
+
function stringifyStyleObject(name, value) {
|
|
173
|
+
if (isVoid(value)) {
|
|
174
|
+
return "";
|
|
175
|
+
}
|
|
176
|
+
if (typeof value === "number" && value && !NON_DIMENSIONAL.test(name)) {
|
|
177
|
+
value += "px";
|
|
178
|
+
}
|
|
179
|
+
return `${name}:${value}`;
|
|
180
|
+
}
|
|
181
|
+
function toDelimitedString(val, delimiter, stringify) {
|
|
182
|
+
switch (typeof val) {
|
|
183
|
+
case "string":
|
|
184
|
+
return val;
|
|
185
|
+
case "object":
|
|
186
|
+
if (val !== null) {
|
|
187
|
+
let result = "";
|
|
188
|
+
let curDelimiter = "";
|
|
189
|
+
if (Array.isArray(val)) {
|
|
190
|
+
for (const v of val) {
|
|
191
|
+
const part = toDelimitedString(v, delimiter, stringify);
|
|
192
|
+
if (part !== "") {
|
|
193
|
+
result += curDelimiter + part;
|
|
194
|
+
curDelimiter = delimiter;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
for (const name in val) {
|
|
199
|
+
const v = val[name];
|
|
200
|
+
const part = stringify(name, v);
|
|
201
|
+
if (part !== "") {
|
|
202
|
+
result += curDelimiter + part;
|
|
203
|
+
curDelimiter = delimiter;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return "";
|
|
211
|
+
}
|
|
212
|
+
function isVoid(value) {
|
|
213
|
+
return value == null || value === false;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/html/attrs.ts
|
|
217
|
+
function classAttr(val) {
|
|
218
|
+
return stringAttr("class", classValue(val));
|
|
219
|
+
}
|
|
220
|
+
function styleAttr(val) {
|
|
221
|
+
return stringAttr("style", styleValue(val));
|
|
222
|
+
}
|
|
223
|
+
function attr(name, val) {
|
|
224
|
+
return isVoid(val) ? "" : nonVoidUntypedAttr(name, val);
|
|
225
|
+
}
|
|
226
|
+
function attrs(data) {
|
|
227
|
+
let result = "";
|
|
228
|
+
for (const name in data) {
|
|
229
|
+
if (/^on[A-Z-]/.test(name)) {
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
const val = data[name];
|
|
233
|
+
switch (name) {
|
|
234
|
+
case "class":
|
|
235
|
+
result += classAttr(val);
|
|
236
|
+
break;
|
|
237
|
+
case "style":
|
|
238
|
+
result += styleAttr(val);
|
|
239
|
+
break;
|
|
240
|
+
case "renderBody":
|
|
241
|
+
break;
|
|
242
|
+
default:
|
|
243
|
+
if (!(isVoid(val) || isInvalidAttrName(name))) {
|
|
244
|
+
result += nonVoidUntypedAttr(name, val);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
function stringAttr(name, val) {
|
|
251
|
+
return val && ` ${name}=${escapeAttrValue(val)}`;
|
|
252
|
+
}
|
|
253
|
+
function nonVoidUntypedAttr(name, val) {
|
|
254
|
+
switch (typeof val) {
|
|
255
|
+
case "string":
|
|
256
|
+
return ` ${name + attrAssignment(val)}`;
|
|
257
|
+
case "boolean":
|
|
258
|
+
return ` ${name}`;
|
|
259
|
+
case "number":
|
|
260
|
+
return ` ${name}=${val}`;
|
|
261
|
+
case "object":
|
|
262
|
+
if (val instanceof RegExp) {
|
|
263
|
+
return ` ${name}=${escapeAttrValue(val.source)}`;
|
|
264
|
+
}
|
|
265
|
+
default:
|
|
266
|
+
return ` ${name + attrAssignment(val + "")}`;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function attrAssignment(val) {
|
|
270
|
+
return val ? `=${escapeAttrValue(val)}` : "";
|
|
271
|
+
}
|
|
272
|
+
function isInvalidAttrName(name) {
|
|
273
|
+
for (let i = name.length; i--; ) {
|
|
274
|
+
if (name[i] === ">") {
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/html/serializer.ts
|
|
282
|
+
var { hasOwnProperty } = Object.prototype;
|
|
283
|
+
var PARAM_BIND = "b";
|
|
284
|
+
var PARAM_SCOPE = "s";
|
|
285
|
+
var REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_";
|
|
286
|
+
var REF_START_CHARS_LEN = REF_START_CHARS.length;
|
|
287
|
+
var REF_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_";
|
|
288
|
+
var REF_CHARS_LEN = REF_CHARS.length;
|
|
289
|
+
var SYMBOL_REGISTRY_ID = Symbol("REGISTRY_ID");
|
|
290
|
+
var SYMBOL_SCOPE = Symbol("SCOPE");
|
|
291
|
+
var SYMBOL_SERIALIZE = Symbol("SERIALIZE");
|
|
292
|
+
var Scope = class {
|
|
293
|
+
};
|
|
294
|
+
var serializedScope = (scopeId) => {
|
|
295
|
+
const scope = new Scope();
|
|
296
|
+
if (true) {
|
|
297
|
+
scope.id = scopeId;
|
|
298
|
+
}
|
|
299
|
+
return makeSerializable(scope, (s, a) => {
|
|
300
|
+
s.value(s.scopeLookup.get(scopeId), a);
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
function register(entry, registryId, scopeId) {
|
|
304
|
+
entry[SYMBOL_REGISTRY_ID] = registryId;
|
|
305
|
+
entry[SYMBOL_SCOPE] = scopeId;
|
|
306
|
+
return entry;
|
|
307
|
+
}
|
|
308
|
+
function getRegistryInfo(entry) {
|
|
309
|
+
return [entry[SYMBOL_REGISTRY_ID], entry[SYMBOL_SCOPE]];
|
|
310
|
+
}
|
|
311
|
+
function makeSerializable(object, serialize) {
|
|
312
|
+
object[SYMBOL_SERIALIZE] = serialize;
|
|
313
|
+
return object;
|
|
314
|
+
}
|
|
315
|
+
var Serializer = class {
|
|
316
|
+
// TODO: hoist these back out?
|
|
317
|
+
STACK = [];
|
|
318
|
+
BUFFER = [""];
|
|
319
|
+
ASSIGNMENTS = /* @__PURE__ */ new Map();
|
|
320
|
+
INDEX_OR_REF = /* @__PURE__ */ new WeakMap();
|
|
321
|
+
REF_COUNT = 0;
|
|
322
|
+
// These stay
|
|
323
|
+
PARENTS = /* @__PURE__ */ new WeakMap();
|
|
324
|
+
KEYS = /* @__PURE__ */ new WeakMap();
|
|
325
|
+
VALUES = /* @__PURE__ */ new Map();
|
|
326
|
+
scopeLookup;
|
|
327
|
+
constructor(scopeLookup) {
|
|
328
|
+
this.scopeLookup = scopeLookup;
|
|
329
|
+
this.BUFFER.pop();
|
|
330
|
+
}
|
|
331
|
+
stringify(root) {
|
|
332
|
+
if (this.writeProp(root, "")) {
|
|
333
|
+
const { BUFFER, REF_COUNT, ASSIGNMENTS, INDEX_OR_REF } = this;
|
|
334
|
+
let result = BUFFER[0];
|
|
335
|
+
for (let i = 1, len = BUFFER.length; i < len; i++) {
|
|
336
|
+
result += BUFFER[i];
|
|
337
|
+
}
|
|
338
|
+
if (REF_COUNT) {
|
|
339
|
+
if (ASSIGNMENTS.size) {
|
|
340
|
+
let ref = INDEX_OR_REF.get(root);
|
|
341
|
+
if (typeof ref === "number") {
|
|
342
|
+
ref = toRefParam(this.REF_COUNT++);
|
|
343
|
+
result = ref + "=" + result;
|
|
344
|
+
}
|
|
345
|
+
for (const [assignmentRef, assignments] of ASSIGNMENTS) {
|
|
346
|
+
result += "," + assignments + assignmentRef;
|
|
347
|
+
}
|
|
348
|
+
result += "," + ref;
|
|
349
|
+
this.ASSIGNMENTS = /* @__PURE__ */ new Map();
|
|
350
|
+
}
|
|
351
|
+
result = "(" + PARAM_BIND + "," + PARAM_SCOPE + "," + this.refParamsString() + ")=>(" + result + ")";
|
|
352
|
+
} else if (root && root.constructor === Object) {
|
|
353
|
+
result = "(" + PARAM_BIND + "," + PARAM_SCOPE + ")=>(" + result + ")";
|
|
354
|
+
}
|
|
355
|
+
BUFFER.length = 0;
|
|
356
|
+
this.INDEX_OR_REF = /* @__PURE__ */ new WeakMap();
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
return "void 0";
|
|
360
|
+
}
|
|
361
|
+
code(code) {
|
|
362
|
+
this.BUFFER.push(code);
|
|
363
|
+
return this;
|
|
364
|
+
}
|
|
365
|
+
value(value, accessor = "") {
|
|
366
|
+
if (!this.writeProp(value, accessor) && !this.STACK.includes(value)) {
|
|
367
|
+
this.BUFFER.push("void 0");
|
|
368
|
+
}
|
|
369
|
+
return this;
|
|
370
|
+
}
|
|
371
|
+
writeProp(cur, accessor) {
|
|
372
|
+
const { BUFFER } = this;
|
|
373
|
+
switch (typeof cur) {
|
|
374
|
+
case "string":
|
|
375
|
+
BUFFER.push(quote(cur, 0));
|
|
376
|
+
break;
|
|
377
|
+
case "number":
|
|
378
|
+
BUFFER.push(cur + "");
|
|
379
|
+
break;
|
|
380
|
+
case "boolean":
|
|
381
|
+
BUFFER.push(cur ? "!0" : "!1");
|
|
382
|
+
break;
|
|
383
|
+
case "function":
|
|
384
|
+
case "object":
|
|
385
|
+
if (cur === null) {
|
|
386
|
+
BUFFER.push("null");
|
|
387
|
+
} else {
|
|
388
|
+
const ref = this.getRef(cur, accessor);
|
|
389
|
+
switch (ref) {
|
|
390
|
+
case true:
|
|
391
|
+
return false;
|
|
392
|
+
case false:
|
|
393
|
+
switch (cur.constructor) {
|
|
394
|
+
case Object:
|
|
395
|
+
this.writeObject(cur);
|
|
396
|
+
break;
|
|
397
|
+
case Array:
|
|
398
|
+
this.writeArray(cur);
|
|
399
|
+
break;
|
|
400
|
+
case Date:
|
|
401
|
+
BUFFER.push(
|
|
402
|
+
'new Date("' + cur.toISOString() + '")'
|
|
403
|
+
);
|
|
404
|
+
break;
|
|
405
|
+
case RegExp:
|
|
406
|
+
BUFFER.push(cur + "");
|
|
407
|
+
break;
|
|
408
|
+
case Map:
|
|
409
|
+
BUFFER.push("new Map(");
|
|
410
|
+
this.writeArray(
|
|
411
|
+
Array.from(cur)
|
|
412
|
+
);
|
|
413
|
+
BUFFER.push(")");
|
|
414
|
+
break;
|
|
415
|
+
case Set:
|
|
416
|
+
BUFFER.push("new Set(");
|
|
417
|
+
this.writeArray(
|
|
418
|
+
Array.from(cur)
|
|
419
|
+
);
|
|
420
|
+
BUFFER.push(")");
|
|
421
|
+
break;
|
|
422
|
+
case void 0:
|
|
423
|
+
BUFFER.push("Object.assign(Object.create(null),");
|
|
424
|
+
this.writeObject(cur);
|
|
425
|
+
BUFFER.push("))");
|
|
426
|
+
break;
|
|
427
|
+
default:
|
|
428
|
+
return this.writeRegistered(
|
|
429
|
+
cur,
|
|
430
|
+
accessor
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
break;
|
|
434
|
+
default:
|
|
435
|
+
BUFFER.push(ref);
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
break;
|
|
440
|
+
default:
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
445
|
+
writeRegistered(value, accessor) {
|
|
446
|
+
const {
|
|
447
|
+
[SYMBOL_REGISTRY_ID]: registryId,
|
|
448
|
+
[SYMBOL_SCOPE]: scopeId,
|
|
449
|
+
[SYMBOL_SERIALIZE]: serialize
|
|
450
|
+
} = value;
|
|
451
|
+
const { BUFFER } = this;
|
|
452
|
+
if (registryId) {
|
|
453
|
+
const scope = scopeId !== void 0 ? this.scopeLookup.get(scopeId) ?? false : void 0;
|
|
454
|
+
const ref = scope && this.getRef(scope, "");
|
|
455
|
+
if (ref === true) {
|
|
456
|
+
const { STACK, INDEX_OR_REF, ASSIGNMENTS } = this;
|
|
457
|
+
const parent = STACK[STACK.length - 1];
|
|
458
|
+
const parentRef = INDEX_OR_REF.get(parent);
|
|
459
|
+
const resolvedRef = INDEX_OR_REF.get(scope);
|
|
460
|
+
ASSIGNMENTS.set(
|
|
461
|
+
`${PARAM_BIND}("${registryId}",${resolvedRef})`,
|
|
462
|
+
(ASSIGNMENTS.get(ref) || "") + toAssignment(parentRef, accessor) + "="
|
|
463
|
+
);
|
|
464
|
+
return false;
|
|
465
|
+
} else if (ref === false) {
|
|
466
|
+
throw new Error(
|
|
467
|
+
"The scope has not yet been defined. This needs to be fixed in the serializer."
|
|
468
|
+
);
|
|
469
|
+
} else {
|
|
470
|
+
BUFFER.push(`${PARAM_BIND}("${registryId}"${ref ? "," + ref : ""})`);
|
|
471
|
+
return true;
|
|
472
|
+
}
|
|
473
|
+
} else if (serialize) {
|
|
474
|
+
const prevSize = BUFFER.length;
|
|
475
|
+
serialize(this, accessor);
|
|
476
|
+
return prevSize !== BUFFER.length;
|
|
477
|
+
}
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
writeObject(obj) {
|
|
481
|
+
const { STACK, BUFFER } = this;
|
|
482
|
+
let sep = "{";
|
|
483
|
+
STACK.push(obj);
|
|
484
|
+
for (const key in obj) {
|
|
485
|
+
if (hasOwnProperty.call(obj, key)) {
|
|
486
|
+
const val = obj[key];
|
|
487
|
+
const escapedKey = toObjectKey(key);
|
|
488
|
+
BUFFER.push(sep + escapedKey + ":");
|
|
489
|
+
if (this.writeProp(val, escapedKey)) {
|
|
490
|
+
sep = ",";
|
|
491
|
+
} else {
|
|
492
|
+
BUFFER.pop();
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (sep === "{") {
|
|
497
|
+
BUFFER.push("{}");
|
|
498
|
+
} else {
|
|
499
|
+
BUFFER.push("}");
|
|
500
|
+
}
|
|
501
|
+
STACK.pop();
|
|
502
|
+
}
|
|
503
|
+
writeArray(arr) {
|
|
504
|
+
const { STACK, BUFFER } = this;
|
|
505
|
+
BUFFER.push("[");
|
|
506
|
+
STACK.push(arr);
|
|
507
|
+
this.writeProp(arr[0], 0);
|
|
508
|
+
for (let i = 1, len = arr.length; i < len; i++) {
|
|
509
|
+
BUFFER.push(",");
|
|
510
|
+
this.writeProp(arr[i], i);
|
|
511
|
+
}
|
|
512
|
+
STACK.pop();
|
|
513
|
+
BUFFER.push("]");
|
|
514
|
+
}
|
|
515
|
+
getRef(cur, accessor) {
|
|
516
|
+
const { STACK, BUFFER, INDEX_OR_REF, ASSIGNMENTS, PARENTS, KEYS } = this;
|
|
517
|
+
let ref = INDEX_OR_REF.get(cur);
|
|
518
|
+
if (ref === void 0) {
|
|
519
|
+
INDEX_OR_REF.set(cur, BUFFER.length);
|
|
520
|
+
let knownParent = PARENTS.get(cur);
|
|
521
|
+
if (knownParent === void 0) {
|
|
522
|
+
const parent = STACK[STACK.length - 1];
|
|
523
|
+
if (!parent) {
|
|
524
|
+
} else {
|
|
525
|
+
PARENTS.set(cur, parent);
|
|
526
|
+
KEYS.set(cur, toObjectKey(accessor));
|
|
527
|
+
}
|
|
528
|
+
return false;
|
|
529
|
+
} else {
|
|
530
|
+
let ref2 = "";
|
|
531
|
+
while (knownParent) {
|
|
532
|
+
ref2 = toPropertyAccess(KEYS.get(cur)) + ref2;
|
|
533
|
+
knownParent = PARENTS.get(cur = knownParent);
|
|
534
|
+
}
|
|
535
|
+
return PARAM_SCOPE + ref2;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
if (typeof ref === "number") {
|
|
539
|
+
ref = this.insertAndGetRef(cur, ref);
|
|
540
|
+
}
|
|
541
|
+
if (STACK.includes(cur)) {
|
|
542
|
+
const parent = STACK[STACK.length - 1];
|
|
543
|
+
let parentRef = INDEX_OR_REF.get(parent);
|
|
544
|
+
if (typeof parentRef === "number") {
|
|
545
|
+
parentRef = this.insertAndGetRef(parent, parentRef);
|
|
546
|
+
}
|
|
547
|
+
if (accessor !== "") {
|
|
548
|
+
ASSIGNMENTS.set(
|
|
549
|
+
ref,
|
|
550
|
+
(ASSIGNMENTS.get(ref) || "") + toAssignment(parentRef, accessor) + "="
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
return true;
|
|
554
|
+
}
|
|
555
|
+
return ref;
|
|
556
|
+
}
|
|
557
|
+
insertAndGetRef(obj, pos) {
|
|
558
|
+
const ref = toRefParam(this.REF_COUNT++);
|
|
559
|
+
this.INDEX_OR_REF.set(obj, ref);
|
|
560
|
+
if (pos) {
|
|
561
|
+
this.BUFFER[pos - 1] += ref + "=";
|
|
562
|
+
} else {
|
|
563
|
+
this.BUFFER[pos] = ref + "=" + this.BUFFER[pos];
|
|
564
|
+
}
|
|
565
|
+
return ref;
|
|
566
|
+
}
|
|
567
|
+
refParamsString() {
|
|
568
|
+
let result = REF_START_CHARS[0];
|
|
569
|
+
for (let i = 1; i < this.REF_COUNT; i++) {
|
|
570
|
+
result += "," + toRefParam(i);
|
|
571
|
+
}
|
|
572
|
+
this.REF_COUNT = 0;
|
|
573
|
+
return result;
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
function toAssignment(parent, key) {
|
|
577
|
+
return parent + toPropertyAccess(key);
|
|
578
|
+
}
|
|
579
|
+
function toPropertyAccess(key) {
|
|
580
|
+
return typeof key === "number" || key[0] === '"' ? "[" + key + "]" : "." + key;
|
|
581
|
+
}
|
|
582
|
+
function toObjectKey(name) {
|
|
583
|
+
if (typeof name !== "string")
|
|
584
|
+
return name;
|
|
585
|
+
let char = name[0];
|
|
586
|
+
if (char >= "0" && char <= "9") {
|
|
587
|
+
for (let i = 1, len = name.length; i < len; i++) {
|
|
588
|
+
char = name[i];
|
|
589
|
+
if (!(char >= "0" && char <= "9")) {
|
|
590
|
+
return quote(name, i);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return parseInt(name, 10);
|
|
594
|
+
} else {
|
|
595
|
+
for (let i = 0, len = name.length; i < len; i++) {
|
|
596
|
+
char = name[i];
|
|
597
|
+
if (!(char >= "a" && char <= "z" || char >= "A" && char <= "Z" || char >= "0" && char <= "9" || char === "$" || char === "_")) {
|
|
598
|
+
return quote(name, i);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return name;
|
|
603
|
+
}
|
|
604
|
+
function quote(str, startPos) {
|
|
605
|
+
let result = "";
|
|
606
|
+
let lastPos = 0;
|
|
607
|
+
for (let i = startPos, len = str.length; i < len; i++) {
|
|
608
|
+
let replacement;
|
|
609
|
+
switch (str[i]) {
|
|
610
|
+
case '"':
|
|
611
|
+
replacement = '\\"';
|
|
612
|
+
break;
|
|
613
|
+
case "\\":
|
|
614
|
+
replacement = "\\\\";
|
|
615
|
+
break;
|
|
616
|
+
case "<":
|
|
617
|
+
replacement = "\\x3C";
|
|
618
|
+
break;
|
|
619
|
+
case "\n":
|
|
620
|
+
replacement = "\\n";
|
|
621
|
+
break;
|
|
622
|
+
case "\r":
|
|
623
|
+
replacement = "\\r";
|
|
624
|
+
break;
|
|
625
|
+
case "\u2028":
|
|
626
|
+
replacement = "\\u2028";
|
|
627
|
+
break;
|
|
628
|
+
case "\u2029":
|
|
629
|
+
replacement = "\\u2029";
|
|
630
|
+
break;
|
|
631
|
+
default:
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
result += str.slice(lastPos, i) + replacement;
|
|
635
|
+
lastPos = i + 1;
|
|
636
|
+
}
|
|
637
|
+
if (lastPos === startPos) {
|
|
638
|
+
result = str;
|
|
639
|
+
} else {
|
|
640
|
+
result += str.slice(lastPos);
|
|
641
|
+
}
|
|
642
|
+
return '"' + result + '"';
|
|
643
|
+
}
|
|
644
|
+
function toRefParam(index) {
|
|
645
|
+
let mod = index % REF_START_CHARS_LEN;
|
|
646
|
+
let ref = REF_START_CHARS[mod];
|
|
647
|
+
index = (index - mod) / REF_START_CHARS_LEN;
|
|
648
|
+
while (index > 0) {
|
|
649
|
+
mod = index % REF_CHARS_LEN;
|
|
650
|
+
ref += REF_CHARS[mod];
|
|
651
|
+
index = (index - mod) / REF_CHARS_LEN;
|
|
652
|
+
}
|
|
653
|
+
return ref;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// src/html/reorder-runtime.ts
|
|
657
|
+
function reorder_runtime_default(id, doc, walker, node, replacementNode, targetParent, targetNode, refNode, nextNode, runtimePrefix) {
|
|
658
|
+
runtimePrefix = "RUNTIME_ID$";
|
|
659
|
+
id = runtimePrefix + id;
|
|
660
|
+
doc = document;
|
|
661
|
+
walker = doc[runtimePrefix + "w"] || (doc[runtimePrefix + "w"] = doc.createTreeWalker(
|
|
662
|
+
doc,
|
|
663
|
+
128
|
|
664
|
+
));
|
|
665
|
+
while (node = walker.nextNode()) {
|
|
666
|
+
if (node.data.indexOf(runtimePrefix) === 0) {
|
|
667
|
+
walker[node.data] = node;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
replacementNode = doc.getElementById(id);
|
|
671
|
+
targetNode = walker[id];
|
|
672
|
+
targetParent = targetNode.parentNode;
|
|
673
|
+
while (refNode = replacementNode.firstChild) {
|
|
674
|
+
targetParent.insertBefore(refNode, targetNode);
|
|
675
|
+
}
|
|
676
|
+
nextNode = replacementNode.parentNode;
|
|
677
|
+
nextNode.removeChild(replacementNode.nextSibling);
|
|
678
|
+
nextNode.removeChild(replacementNode);
|
|
679
|
+
refNode = walker[id + "/"];
|
|
680
|
+
while (targetNode && (nextNode = targetNode.nextSibling, targetParent.removeChild(targetNode) !== refNode)) {
|
|
681
|
+
targetNode = nextNode;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// src/html/writer.ts
|
|
686
|
+
var runtimeId = "M" /* DefaultRuntimeId */;
|
|
687
|
+
var reorderRuntimeString = String(reorder_runtime_default).replace(
|
|
688
|
+
"RUNTIME_ID",
|
|
689
|
+
runtimeId
|
|
690
|
+
);
|
|
691
|
+
var $_buffer = null;
|
|
692
|
+
var $_streamData = null;
|
|
693
|
+
function createRenderFn(renderer) {
|
|
694
|
+
return (stream, input = {}, $global, streamState = {}) => {
|
|
695
|
+
let remainingChildren = 1;
|
|
696
|
+
const originalBuffer = $_buffer;
|
|
697
|
+
const originalStreamState = $_streamData;
|
|
698
|
+
const reject = (err) => {
|
|
699
|
+
stream.emit("error", err);
|
|
700
|
+
};
|
|
701
|
+
const async = (complete) => {
|
|
702
|
+
remainingChildren += complete ? -1 : 1;
|
|
703
|
+
if (!remainingChildren) {
|
|
704
|
+
setImmediate(() => stream.end());
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
$_buffer = createInitialBuffer(stream);
|
|
708
|
+
streamState.global = $global;
|
|
709
|
+
$_streamData = createStreamState(streamState);
|
|
710
|
+
$_buffer.onReject = reject;
|
|
711
|
+
$_buffer.onAsync = async;
|
|
712
|
+
try {
|
|
713
|
+
scheduleFlush();
|
|
714
|
+
renderer(input);
|
|
715
|
+
async(true);
|
|
716
|
+
} catch (err) {
|
|
717
|
+
reject(err);
|
|
718
|
+
} finally {
|
|
719
|
+
$_buffer = originalBuffer;
|
|
720
|
+
$_streamData = originalStreamState;
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
function write(data) {
|
|
725
|
+
$_buffer.content += data;
|
|
726
|
+
}
|
|
727
|
+
var TARGET_BUFFER_SIZE = 64e3;
|
|
728
|
+
function maybeFlush() {
|
|
729
|
+
if (!$_buffer.prev && $_buffer.content.length > TARGET_BUFFER_SIZE) {
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
function scheduleFlush() {
|
|
733
|
+
const buffer = $_buffer;
|
|
734
|
+
const streamState = $_streamData;
|
|
735
|
+
if (!buffer.prev) {
|
|
736
|
+
setImmediate(() => flushToStream(buffer, streamState));
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
function flushToStream(buffer, streamState) {
|
|
740
|
+
while (buffer.prev)
|
|
741
|
+
buffer = buffer.prev;
|
|
742
|
+
if (buffer.disabled)
|
|
743
|
+
return;
|
|
744
|
+
const stream = buffer.stream;
|
|
745
|
+
let { content, calls, scopes } = buffer;
|
|
746
|
+
buffer.flushed = true;
|
|
747
|
+
while (!buffer.pending && buffer.next) {
|
|
748
|
+
clearBuffer(buffer);
|
|
749
|
+
buffer = buffer.next;
|
|
750
|
+
buffer.prev = null;
|
|
751
|
+
buffer.flushed = true;
|
|
752
|
+
content += buffer.content;
|
|
753
|
+
calls += buffer.calls;
|
|
754
|
+
if (buffer.scopes) {
|
|
755
|
+
if (scopes) {
|
|
756
|
+
Object.assign(scopes, buffer.scopes);
|
|
757
|
+
} else {
|
|
758
|
+
scopes = buffer.scopes;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
const data = content + getResumeScript(calls, scopes, streamState);
|
|
763
|
+
if (data) {
|
|
764
|
+
stream.write(data);
|
|
765
|
+
stream.flush?.();
|
|
766
|
+
}
|
|
767
|
+
clearBuffer(buffer);
|
|
768
|
+
}
|
|
769
|
+
function createStreamState(state) {
|
|
770
|
+
state.scopeId ??= 0;
|
|
771
|
+
state.tagId ??= 0;
|
|
772
|
+
state.placeholderId ??= 0;
|
|
773
|
+
state.scopeLookup ??= /* @__PURE__ */ new Map();
|
|
774
|
+
state.runtimeFlushed ??= false;
|
|
775
|
+
return state;
|
|
776
|
+
}
|
|
777
|
+
function createNextBuffer(prevBuffer) {
|
|
778
|
+
const newBuffer = {
|
|
779
|
+
stream: prevBuffer.stream,
|
|
780
|
+
pending: false,
|
|
781
|
+
flushed: false,
|
|
782
|
+
disabled: false,
|
|
783
|
+
prev: prevBuffer,
|
|
784
|
+
next: prevBuffer?.next ?? null,
|
|
785
|
+
content: "",
|
|
786
|
+
calls: "",
|
|
787
|
+
scopes: null,
|
|
788
|
+
onReject: prevBuffer.onReject,
|
|
789
|
+
onAsync: prevBuffer.onAsync
|
|
790
|
+
};
|
|
791
|
+
if (prevBuffer.next) {
|
|
792
|
+
prevBuffer.next.prev = prevBuffer;
|
|
793
|
+
}
|
|
794
|
+
prevBuffer.next = newBuffer;
|
|
795
|
+
return newBuffer;
|
|
796
|
+
}
|
|
797
|
+
function createDetatchedBuffer(parentBuffer) {
|
|
798
|
+
return {
|
|
799
|
+
stream: parentBuffer.stream,
|
|
800
|
+
pending: false,
|
|
801
|
+
flushed: false,
|
|
802
|
+
disabled: true,
|
|
803
|
+
prev: null,
|
|
804
|
+
next: null,
|
|
805
|
+
content: "",
|
|
806
|
+
calls: "",
|
|
807
|
+
scopes: null,
|
|
808
|
+
onReject: parentBuffer.onReject,
|
|
809
|
+
onAsync: parentBuffer.onAsync
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
function createInitialBuffer(stream) {
|
|
813
|
+
return {
|
|
814
|
+
stream,
|
|
815
|
+
pending: false,
|
|
816
|
+
flushed: false,
|
|
817
|
+
disabled: false,
|
|
818
|
+
prev: null,
|
|
819
|
+
next: null,
|
|
820
|
+
content: "",
|
|
821
|
+
calls: "",
|
|
822
|
+
scopes: null,
|
|
823
|
+
onReject: void 0,
|
|
824
|
+
onAsync: void 0
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
async function fork(promise, renderResult) {
|
|
828
|
+
const originalBuffer = $_buffer;
|
|
829
|
+
const originalStreamState = $_streamData;
|
|
830
|
+
scheduleFlush();
|
|
831
|
+
$_buffer.pending = true;
|
|
832
|
+
$_buffer.onAsync?.(false);
|
|
833
|
+
$_buffer = createNextBuffer($_buffer);
|
|
834
|
+
try {
|
|
835
|
+
let result;
|
|
836
|
+
try {
|
|
837
|
+
result = await promise;
|
|
838
|
+
originalBuffer.pending = false;
|
|
839
|
+
} finally {
|
|
840
|
+
$_buffer = originalBuffer;
|
|
841
|
+
$_streamData = originalStreamState;
|
|
842
|
+
scheduleFlush();
|
|
843
|
+
}
|
|
844
|
+
renderResult(result);
|
|
845
|
+
} catch (err) {
|
|
846
|
+
$_buffer.onReject?.(err);
|
|
847
|
+
} finally {
|
|
848
|
+
$_buffer.onAsync?.(true);
|
|
849
|
+
clearScope();
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
function tryCatch(renderBody, renderError) {
|
|
853
|
+
const id = nextPlaceholderId();
|
|
854
|
+
let err = null;
|
|
855
|
+
const originalBuffer = $_buffer;
|
|
856
|
+
const tryBuffer = createDetatchedBuffer(originalBuffer);
|
|
857
|
+
let finalTryBuffer;
|
|
858
|
+
tryBuffer.onReject = (asyncErr) => {
|
|
859
|
+
const errorBuffer = createDetatchedBuffer(originalBuffer);
|
|
860
|
+
$_buffer = errorBuffer;
|
|
861
|
+
renderError(asyncErr);
|
|
862
|
+
const finalErrorBuffer = $_buffer;
|
|
863
|
+
replaceBuffers(
|
|
864
|
+
id,
|
|
865
|
+
tryBuffer,
|
|
866
|
+
finalTryBuffer,
|
|
867
|
+
errorBuffer,
|
|
868
|
+
finalErrorBuffer
|
|
869
|
+
);
|
|
870
|
+
};
|
|
871
|
+
try {
|
|
872
|
+
$_buffer = tryBuffer;
|
|
873
|
+
renderBody();
|
|
874
|
+
} catch (_err) {
|
|
875
|
+
err = _err;
|
|
876
|
+
} finally {
|
|
877
|
+
if (err) {
|
|
878
|
+
$_buffer = originalBuffer;
|
|
879
|
+
renderError(err);
|
|
880
|
+
} else {
|
|
881
|
+
tryBuffer.disabled = false;
|
|
882
|
+
originalBuffer.next = tryBuffer;
|
|
883
|
+
tryBuffer.prev = originalBuffer;
|
|
884
|
+
if ($_buffer !== tryBuffer) {
|
|
885
|
+
tryBuffer.content = `<!${marker(id)}>` + tryBuffer.content;
|
|
886
|
+
markReplaceEnd(id);
|
|
887
|
+
finalTryBuffer = $_buffer;
|
|
888
|
+
$_buffer = createNextBuffer(finalTryBuffer);
|
|
889
|
+
}
|
|
890
|
+
$_buffer.onReject = originalBuffer.onReject;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
function tryPlaceholder(renderBody, renderPlaceholder) {
|
|
895
|
+
const originalBuffer = $_buffer;
|
|
896
|
+
const asyncBuffer = createDetatchedBuffer(originalBuffer);
|
|
897
|
+
let id, placeholderBuffer, finalPlaceholderBuffer, finalAsyncBuffer;
|
|
898
|
+
let remainingChildren = 0;
|
|
899
|
+
let remainingPlaceholders = 0;
|
|
900
|
+
asyncBuffer.onAsync = (complete, isPlaceholder) => {
|
|
901
|
+
const delta = complete ? -1 : 1;
|
|
902
|
+
if (isPlaceholder) {
|
|
903
|
+
remainingPlaceholders += delta;
|
|
904
|
+
} else {
|
|
905
|
+
remainingChildren += delta;
|
|
906
|
+
}
|
|
907
|
+
if (!remainingChildren) {
|
|
908
|
+
if (!isPlaceholder) {
|
|
909
|
+
replaceBuffers(
|
|
910
|
+
id,
|
|
911
|
+
placeholderBuffer,
|
|
912
|
+
finalPlaceholderBuffer,
|
|
913
|
+
asyncBuffer,
|
|
914
|
+
finalAsyncBuffer
|
|
915
|
+
);
|
|
916
|
+
}
|
|
917
|
+
if (!remainingPlaceholders) {
|
|
918
|
+
originalBuffer.onAsync?.(true, true);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
$_buffer = asyncBuffer;
|
|
923
|
+
renderBody();
|
|
924
|
+
if ($_buffer === asyncBuffer) {
|
|
925
|
+
originalBuffer.next = asyncBuffer;
|
|
926
|
+
asyncBuffer.prev = originalBuffer;
|
|
927
|
+
asyncBuffer.disabled = false;
|
|
928
|
+
asyncBuffer.onAsync = originalBuffer.onAsync;
|
|
929
|
+
} else {
|
|
930
|
+
id = nextPlaceholderId();
|
|
931
|
+
placeholderBuffer = createNextBuffer(originalBuffer);
|
|
932
|
+
finalAsyncBuffer = $_buffer;
|
|
933
|
+
$_buffer = placeholderBuffer;
|
|
934
|
+
markReplaceStart(id);
|
|
935
|
+
renderPlaceholder();
|
|
936
|
+
markReplaceEnd(id);
|
|
937
|
+
finalPlaceholderBuffer = $_buffer;
|
|
938
|
+
$_buffer = createNextBuffer(finalPlaceholderBuffer);
|
|
939
|
+
originalBuffer.onAsync?.(false, true);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
function clearBuffer(buffer) {
|
|
943
|
+
buffer.content = "";
|
|
944
|
+
buffer.calls = "";
|
|
945
|
+
buffer.scopes = null;
|
|
946
|
+
}
|
|
947
|
+
function clearScope() {
|
|
948
|
+
$_buffer = $_streamData = null;
|
|
949
|
+
}
|
|
950
|
+
function markReplaceStart(id) {
|
|
951
|
+
return $_buffer.content += `<!${marker(id)}>`;
|
|
952
|
+
}
|
|
953
|
+
function markReplaceEnd(id) {
|
|
954
|
+
return $_buffer.content += `<!${marker(id)}/>`;
|
|
955
|
+
}
|
|
956
|
+
function replaceBuffers(id, placeholderStart, placeholderEnd, replacementStart, replacementEnd) {
|
|
957
|
+
if (placeholderStart.flushed) {
|
|
958
|
+
addReplacementWrapper(id, replacementStart, replacementEnd);
|
|
959
|
+
let next = placeholderEnd.next;
|
|
960
|
+
if (placeholderEnd.flushed) {
|
|
961
|
+
while (next && !next.pending && next.flushed) {
|
|
962
|
+
next = next.next;
|
|
963
|
+
}
|
|
964
|
+
} else {
|
|
965
|
+
}
|
|
966
|
+
if (next) {
|
|
967
|
+
replacementStart.next = next;
|
|
968
|
+
next.prev = replacementEnd;
|
|
969
|
+
}
|
|
970
|
+
$_buffer = replacementStart;
|
|
971
|
+
scheduleFlush();
|
|
972
|
+
} else {
|
|
973
|
+
const prev = placeholderStart.prev;
|
|
974
|
+
const next = placeholderEnd.next;
|
|
975
|
+
if (prev) {
|
|
976
|
+
prev.next = replacementStart;
|
|
977
|
+
replacementStart.prev = prev;
|
|
978
|
+
}
|
|
979
|
+
if (next) {
|
|
980
|
+
next.prev = replacementEnd;
|
|
981
|
+
replacementEnd.next = next;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
replacementStart.disabled = false;
|
|
985
|
+
}
|
|
986
|
+
function addReplacementWrapper(id, replacementStart, replacementEnd) {
|
|
987
|
+
let runtimeCall = runtimeId + "$r" /* VarReorderRuntime */;
|
|
988
|
+
if (!$_streamData.runtimeFlushed) {
|
|
989
|
+
runtimeCall = `(${runtimeCall}=${reorderRuntimeString})`;
|
|
990
|
+
$_streamData.runtimeFlushed = true;
|
|
991
|
+
}
|
|
992
|
+
replacementStart.content = `<t id="${marker(id)}">` + replacementStart.content;
|
|
993
|
+
replacementEnd.content += `</t><script>${runtimeCall}(${id})</script>`;
|
|
994
|
+
}
|
|
995
|
+
function marker(id) {
|
|
996
|
+
return `${runtimeId}$${id}`;
|
|
997
|
+
}
|
|
998
|
+
function nextTagId() {
|
|
999
|
+
return "s" + $_streamData.tagId++;
|
|
1000
|
+
}
|
|
1001
|
+
function nextPlaceholderId() {
|
|
1002
|
+
return $_streamData.placeholderId++;
|
|
1003
|
+
}
|
|
1004
|
+
function nextScopeId() {
|
|
1005
|
+
return $_streamData.scopeId++;
|
|
1006
|
+
}
|
|
1007
|
+
function peekNextScopeId() {
|
|
1008
|
+
return $_streamData.scopeId;
|
|
1009
|
+
}
|
|
1010
|
+
function peekSerializedScope() {
|
|
1011
|
+
return serializedScope(peekNextScopeId());
|
|
1012
|
+
}
|
|
1013
|
+
function writeEffect(scopeId, fnId) {
|
|
1014
|
+
$_buffer.calls += `${scopeId},"${fnId}",`;
|
|
1015
|
+
}
|
|
1016
|
+
function writeScope(scopeId, scope, assignTo = $_streamData.scopeLookup.get(scopeId)) {
|
|
1017
|
+
if (assignTo !== void 0) {
|
|
1018
|
+
if (Array.isArray(assignTo)) {
|
|
1019
|
+
assignTo.push(scope);
|
|
1020
|
+
} else {
|
|
1021
|
+
scope = Object.assign(assignTo, scope);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
$_buffer.scopes ??= {
|
|
1025
|
+
$global: getFilteredGlobals($_streamData.global)
|
|
1026
|
+
};
|
|
1027
|
+
$_buffer.scopes[scopeId] = scope;
|
|
1028
|
+
$_streamData.scopeLookup.set(scopeId, scope);
|
|
1029
|
+
}
|
|
1030
|
+
function markResumeNode(scopeId, index) {
|
|
1031
|
+
return `<!${runtimeId}${"*" /* Node */}${scopeId} ${index}>`;
|
|
1032
|
+
}
|
|
1033
|
+
function markResumeScopeStart(scopeId, key) {
|
|
1034
|
+
return `<!${runtimeId}${"[" /* SectionStart */}${scopeId}${key ? " " + key : ""}>`;
|
|
1035
|
+
}
|
|
1036
|
+
function markResumeControlEnd(scopeId, index) {
|
|
1037
|
+
return `<!${runtimeId}${"]" /* SectionEnd */}${scopeId} ${index}>`;
|
|
1038
|
+
}
|
|
1039
|
+
function markResumeControlSingleNodeEnd(scopeId, index, childScopeIds) {
|
|
1040
|
+
return `<!${runtimeId}${"|" /* SectionSingleNodesEnd */}${scopeId} ${index} ${childScopeIds ?? ""}>`;
|
|
1041
|
+
}
|
|
1042
|
+
function getResumeScript(calls, scopes, streamState) {
|
|
1043
|
+
if (calls || scopes) {
|
|
1044
|
+
let isFirstFlush;
|
|
1045
|
+
let serializer = streamState.serializer;
|
|
1046
|
+
if (isFirstFlush = !serializer) {
|
|
1047
|
+
serializer = streamState.serializer = new Serializer(
|
|
1048
|
+
streamState.scopeLookup
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
return `<script>${isFirstFlush ? `(${runtimeId + "$h" /* VarResume */}=[])` : runtimeId + "$h" /* VarResume */}.push(${serializer.stringify(scopes)},[${calls}])</script>`;
|
|
1052
|
+
}
|
|
1053
|
+
return "";
|
|
1054
|
+
}
|
|
1055
|
+
function getFilteredGlobals($global) {
|
|
1056
|
+
if (!$global)
|
|
1057
|
+
return void 0;
|
|
1058
|
+
const serializedGlobals = $global.serializedGlobals;
|
|
1059
|
+
if (!serializedGlobals)
|
|
1060
|
+
return void 0;
|
|
1061
|
+
let filtered;
|
|
1062
|
+
if (Array.isArray(serializedGlobals)) {
|
|
1063
|
+
for (const key of serializedGlobals) {
|
|
1064
|
+
const value = $global[key];
|
|
1065
|
+
if (value !== void 0) {
|
|
1066
|
+
if (filtered) {
|
|
1067
|
+
filtered[key] = value;
|
|
1068
|
+
} else {
|
|
1069
|
+
filtered = { [key]: value };
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
} else {
|
|
1074
|
+
for (const key in serializedGlobals) {
|
|
1075
|
+
if (serializedGlobals[key]) {
|
|
1076
|
+
const value = $global[key];
|
|
1077
|
+
if (value !== void 0) {
|
|
1078
|
+
if (filtered) {
|
|
1079
|
+
filtered[key] = value;
|
|
1080
|
+
} else {
|
|
1081
|
+
filtered = { [key]: value };
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
return filtered;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
// src/html/dynamic-tag.ts
|
|
1091
|
+
var voidElements = /* @__PURE__ */ new Set([
|
|
1092
|
+
"area",
|
|
1093
|
+
"base",
|
|
1094
|
+
"br",
|
|
1095
|
+
"col",
|
|
1096
|
+
"embed",
|
|
1097
|
+
"hr",
|
|
1098
|
+
"img",
|
|
1099
|
+
"input",
|
|
1100
|
+
"link",
|
|
1101
|
+
"meta",
|
|
1102
|
+
"param",
|
|
1103
|
+
"source",
|
|
1104
|
+
"track",
|
|
1105
|
+
"wbr"
|
|
1106
|
+
]);
|
|
1107
|
+
function dynamicTagInput(tag, input, renderBody) {
|
|
1108
|
+
if (!tag && !renderBody)
|
|
1109
|
+
return void 0;
|
|
1110
|
+
const futureScopeId = peekNextScopeId();
|
|
1111
|
+
const futureScope = serializedScope(futureScopeId);
|
|
1112
|
+
write(`${markResumeScopeStart(futureScopeId)}`);
|
|
1113
|
+
writeScope(futureScopeId, {});
|
|
1114
|
+
if (!tag) {
|
|
1115
|
+
renderBody();
|
|
1116
|
+
return futureScope;
|
|
1117
|
+
}
|
|
1118
|
+
if (typeof tag === "string") {
|
|
1119
|
+
nextScopeId();
|
|
1120
|
+
write(`<${tag}${attrs(input)}>`);
|
|
1121
|
+
if (!voidElements.has(tag)) {
|
|
1122
|
+
if (renderBody) {
|
|
1123
|
+
renderBody();
|
|
1124
|
+
}
|
|
1125
|
+
write(`</${tag}>`);
|
|
1126
|
+
} else if (renderBody) {
|
|
1127
|
+
throw new Error(
|
|
1128
|
+
`A renderBody was provided for a "${tag}" tag, which cannot have children.`
|
|
1129
|
+
);
|
|
1130
|
+
}
|
|
1131
|
+
return futureScope;
|
|
1132
|
+
}
|
|
1133
|
+
const renderer = getDynamicRenderer(tag);
|
|
1134
|
+
if (typeof renderer === "function") {
|
|
1135
|
+
renderer(renderBody ? { ...input, renderBody } : input);
|
|
1136
|
+
return futureScope;
|
|
1137
|
+
} else if (true) {
|
|
1138
|
+
throw new Error(`Invalid renderer passed for dynamic tag: ${tag}`);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
function dynamicTagArgs(tag, args) {
|
|
1142
|
+
if (!tag)
|
|
1143
|
+
return void 0;
|
|
1144
|
+
const futureScopeId = peekNextScopeId();
|
|
1145
|
+
const futureScope = serializedScope(futureScopeId);
|
|
1146
|
+
write(`${markResumeScopeStart(futureScopeId)}`);
|
|
1147
|
+
writeScope(futureScopeId, {});
|
|
1148
|
+
if (typeof tag === "string") {
|
|
1149
|
+
nextScopeId();
|
|
1150
|
+
write(`<${tag}${attrs(args[0])}></${tag}>`);
|
|
1151
|
+
return futureScope;
|
|
1152
|
+
}
|
|
1153
|
+
const renderer = getDynamicRenderer(tag);
|
|
1154
|
+
if (typeof renderer === "function") {
|
|
1155
|
+
renderer(...args);
|
|
1156
|
+
return futureScope;
|
|
1157
|
+
} else if (true) {
|
|
1158
|
+
throw new Error(`Invalid renderer passed for dynamic tag: ${tag}`);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
var getDynamicRenderer = (tag) => tag._ || tag.renderBody || tag;
|
|
1162
|
+
var createRenderer = (fn) => fn;
|
|
1163
|
+
function patchDynamicTag(newGetDynamicRenderer, newCreateRenderer) {
|
|
1164
|
+
getDynamicRenderer = newGetDynamicRenderer;
|
|
1165
|
+
createRenderer = newCreateRenderer;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
// src/html/template.ts
|
|
1169
|
+
var createTemplate = (renderer, id = "") => register(new ServerTemplate(renderer), id);
|
|
1170
|
+
function deferred() {
|
|
1171
|
+
let resolve;
|
|
1172
|
+
let reject;
|
|
1173
|
+
const promise = new Promise((res, rej) => {
|
|
1174
|
+
resolve = res;
|
|
1175
|
+
reject = rej;
|
|
1176
|
+
});
|
|
1177
|
+
return { promise, resolve, reject };
|
|
1178
|
+
}
|
|
1179
|
+
async function stringFromAsync(iterable) {
|
|
1180
|
+
let str = "";
|
|
1181
|
+
for await (const part of iterable) {
|
|
1182
|
+
str += part;
|
|
1183
|
+
}
|
|
1184
|
+
return str;
|
|
1185
|
+
}
|
|
1186
|
+
var ServerRenderResult = class {
|
|
1187
|
+
#iterable;
|
|
1188
|
+
#promise;
|
|
1189
|
+
constructor(iterable) {
|
|
1190
|
+
this.#iterable = iterable;
|
|
1191
|
+
}
|
|
1192
|
+
[Symbol.asyncIterator]() {
|
|
1193
|
+
return this.#iterable;
|
|
1194
|
+
}
|
|
1195
|
+
[Symbol.toStringTag] = "RenderResult";
|
|
1196
|
+
then(onfulfilled, onrejected) {
|
|
1197
|
+
return (this.#promise ||= stringFromAsync(this.#iterable)).then(
|
|
1198
|
+
onfulfilled,
|
|
1199
|
+
onrejected
|
|
1200
|
+
);
|
|
1201
|
+
}
|
|
1202
|
+
catch(onrejected) {
|
|
1203
|
+
return this.then(void 0, onrejected);
|
|
1204
|
+
}
|
|
1205
|
+
finally(onfinally) {
|
|
1206
|
+
return this.then(void 0, void 0).finally(onfinally);
|
|
1207
|
+
}
|
|
1208
|
+
toReadable() {
|
|
1209
|
+
return new ReadableStream({
|
|
1210
|
+
start: async (controller) => {
|
|
1211
|
+
try {
|
|
1212
|
+
for await (const chunk of this.#iterable) {
|
|
1213
|
+
if (chunk) {
|
|
1214
|
+
controller.enqueue(chunk);
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
controller.close();
|
|
1218
|
+
} catch (err) {
|
|
1219
|
+
controller.error(err);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
var ServerTemplate = class {
|
|
1226
|
+
#writeTo;
|
|
1227
|
+
_;
|
|
1228
|
+
constructor(renderer) {
|
|
1229
|
+
this._ = renderer;
|
|
1230
|
+
this.#writeTo = createRenderFn(renderer);
|
|
1231
|
+
}
|
|
1232
|
+
mount() {
|
|
1233
|
+
throw new Error(
|
|
1234
|
+
`mount() is not implemented for the HTML compilation of a Marko template`
|
|
1235
|
+
);
|
|
1236
|
+
}
|
|
1237
|
+
render(templateInput = {}) {
|
|
1238
|
+
const { $global, ...input } = templateInput;
|
|
1239
|
+
let buffer = "";
|
|
1240
|
+
let done = false;
|
|
1241
|
+
let pending = deferred();
|
|
1242
|
+
this.#writeTo(
|
|
1243
|
+
{
|
|
1244
|
+
write(data) {
|
|
1245
|
+
buffer += data;
|
|
1246
|
+
},
|
|
1247
|
+
flush() {
|
|
1248
|
+
pending.resolve({
|
|
1249
|
+
value: buffer,
|
|
1250
|
+
done: false
|
|
1251
|
+
});
|
|
1252
|
+
buffer = "";
|
|
1253
|
+
pending = deferred();
|
|
1254
|
+
},
|
|
1255
|
+
emit(name, error) {
|
|
1256
|
+
if (name === "error") {
|
|
1257
|
+
pending.reject(error);
|
|
1258
|
+
}
|
|
1259
|
+
},
|
|
1260
|
+
end() {
|
|
1261
|
+
done = true;
|
|
1262
|
+
pending.resolve({
|
|
1263
|
+
value: "",
|
|
1264
|
+
done
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
},
|
|
1268
|
+
input,
|
|
1269
|
+
$global
|
|
1270
|
+
);
|
|
1271
|
+
return new ServerRenderResult({
|
|
1272
|
+
[Symbol.asyncIterator]() {
|
|
1273
|
+
return this;
|
|
1274
|
+
},
|
|
1275
|
+
async next() {
|
|
1276
|
+
if (buffer || done) {
|
|
1277
|
+
const value = buffer;
|
|
1278
|
+
buffer = "";
|
|
1279
|
+
return { value, done };
|
|
1280
|
+
}
|
|
1281
|
+
return pending.promise;
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1287
|
+
0 && (module.exports = {
|
|
1288
|
+
$_streamData,
|
|
1289
|
+
attr,
|
|
1290
|
+
attrs,
|
|
1291
|
+
classAttr,
|
|
1292
|
+
createRenderFn,
|
|
1293
|
+
createRenderer,
|
|
1294
|
+
createTemplate,
|
|
1295
|
+
dynamicTagArgs,
|
|
1296
|
+
dynamicTagInput,
|
|
1297
|
+
escapeAttrValue,
|
|
1298
|
+
escapeScript,
|
|
1299
|
+
escapeStyle,
|
|
1300
|
+
escapeXML,
|
|
1301
|
+
fork,
|
|
1302
|
+
getRegistryInfo,
|
|
1303
|
+
makeSerializable,
|
|
1304
|
+
markResumeControlEnd,
|
|
1305
|
+
markResumeControlSingleNodeEnd,
|
|
1306
|
+
markResumeNode,
|
|
1307
|
+
markResumeScopeStart,
|
|
1308
|
+
maybeFlush,
|
|
1309
|
+
nextScopeId,
|
|
1310
|
+
nextTagId,
|
|
1311
|
+
patchDynamicTag,
|
|
1312
|
+
peekSerializedScope,
|
|
1313
|
+
register,
|
|
1314
|
+
serializedScope,
|
|
1315
|
+
styleAttr,
|
|
1316
|
+
toString,
|
|
1317
|
+
tryCatch,
|
|
1318
|
+
tryPlaceholder,
|
|
1319
|
+
write,
|
|
1320
|
+
writeEffect,
|
|
1321
|
+
writeScope
|
|
1322
|
+
});
|
|
1323
|
+
//# sourceMappingURL=html.js.map
|