marko 6.3.30 → 6.3.32
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/cheatsheet.md +36 -18
- package/dist/common/helpers.d.ts +2 -0
- package/dist/debug/dom/catch.feat.js +38 -0
- package/dist/debug/dom/catch.feat.mjs +37 -0
- package/dist/debug/dom/controllable-input.feat.js +7 -0
- package/dist/debug/dom/controllable-input.feat.mjs +6 -0
- package/dist/debug/dom/controllable-open.feat.js +5 -0
- package/dist/debug/dom/controllable-open.feat.mjs +4 -0
- package/dist/debug/dom/controllable-select.feat.js +5 -0
- package/dist/debug/dom/controllable-select.feat.mjs +4 -0
- package/dist/debug/dom/controllable-textarea.feat.js +5 -0
- package/dist/debug/dom/controllable-textarea.feat.mjs +4 -0
- package/dist/debug/dom/controllable.feat.js +11 -0
- package/dist/debug/dom/controllable.feat.mjs +10 -0
- package/dist/debug/dom-BJ93mcSe.mjs +2016 -0
- package/dist/debug/dom-CiFITSPN.js +2814 -0
- package/dist/debug/dom.js +156 -2245
- package/dist/debug/dom.mjs +6 -2089
- package/dist/dom/catch.feat.d.ts +1 -0
- package/dist/dom/catch.feat.js +25 -0
- package/dist/dom/catch.feat.mjs +26 -0
- package/dist/dom/control-flow.d.ts +3 -3
- package/dist/dom/controllable-input.feat.d.ts +1 -0
- package/dist/dom/controllable-input.feat.js +3 -0
- package/dist/dom/controllable-input.feat.mjs +3 -0
- package/dist/dom/controllable-open.feat.d.ts +1 -0
- package/dist/dom/controllable-open.feat.js +4 -0
- package/dist/dom/controllable-open.feat.mjs +4 -0
- package/dist/dom/controllable-select.feat.d.ts +1 -0
- package/dist/dom/controllable-select.feat.js +4 -0
- package/dist/dom/controllable-select.feat.mjs +4 -0
- package/dist/dom/controllable-textarea.feat.d.ts +1 -0
- package/dist/dom/controllable-textarea.feat.js +4 -0
- package/dist/dom/controllable-textarea.feat.mjs +4 -0
- package/dist/dom/controllable.d.ts +3 -8
- package/dist/dom/controllable.feat.d.ts +3 -0
- package/dist/dom/controllable.feat.js +3 -0
- package/dist/dom/controllable.feat.mjs +6 -0
- package/dist/dom/queue.d.ts +2 -2
- package/dist/dom/resume.d.ts +0 -1
- package/dist/dom/walker.d.ts +0 -1
- package/dist/dom-CI-06TZb.js +1721 -0
- package/dist/dom-Cj4HQ7T_.mjs +1137 -0
- package/dist/dom.d.ts +2 -2
- package/dist/dom.js +36 -1221
- package/dist/dom.mjs +4 -1188
- package/dist/translator/index.js +628 -534
- package/dist/translator/util/constants/structure-kind.d.ts +7 -0
- package/dist/translator/util/get-tag-name.d.ts +2 -1
- package/dist/translator/util/import-reference.d.ts +3 -0
- package/dist/translator/util/runtime.d.ts +2 -0
- package/dist/translator/util/sections.d.ts +28 -1
- package/dist/translator/util/{walks.d.ts → structure.d.ts} +20 -9
- package/dist/translator/util/writer.d.ts +0 -8
- package/dist/translator/visitors/placeholder.d.ts +4 -3
- package/dist/translator/visitors/tag/native-tag.d.ts +9 -6
- package/dist/translator/visitors/text.d.ts +3 -7
- package/package.json +3 -3
|
@@ -0,0 +1,2016 @@
|
|
|
1
|
+
//#region src/common/constants/accessor-prefix.debug.ts
|
|
2
|
+
const BranchScopes$1 = "BranchScopes:";
|
|
3
|
+
const ClosureScopes = "ClosureScopes:";
|
|
4
|
+
const ClosureSignalIndex = "ClosureSignalIndex:";
|
|
5
|
+
const ConditionalRenderer = "ConditionalRenderer:";
|
|
6
|
+
const ControlledObserver = "ControlledObserver:";
|
|
7
|
+
const ControlledHandler = "ControlledHandler:";
|
|
8
|
+
const ControlledType = "ControlledType:";
|
|
9
|
+
const ControlledValue = "ControlledValue:";
|
|
10
|
+
const DynamicHTMLLastChild = "DynamicHTMLLastChild:";
|
|
11
|
+
const EventAttributes = "EventAttributes:";
|
|
12
|
+
const KeyedScopes = "KeyedScopes:";
|
|
13
|
+
const Lifecycle = "Lifecycle:";
|
|
14
|
+
const Promise$1 = "Promise:";
|
|
15
|
+
const TagVariableChange$1 = "TagVariableChange:";
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/common/constants/accessor-prop.debug.ts
|
|
18
|
+
const Global = "$global";
|
|
19
|
+
const AbortControllers = "#AbortControllers";
|
|
20
|
+
const AbortScopes = "#AbortScopes";
|
|
21
|
+
const AwaitCounter = "#AwaitCounter";
|
|
22
|
+
const BranchAccessor = "#BranchAccessor";
|
|
23
|
+
const BranchScopes = "#BranchScopes";
|
|
24
|
+
const CatchContent = "#CatchContent";
|
|
25
|
+
const ClosestBranch = "#ClosestBranch";
|
|
26
|
+
const ClosestBranchId = "#ClosestBranchId";
|
|
27
|
+
const Gen$1 = "#Gen";
|
|
28
|
+
const DetachedAwait = "#DetachedAwait";
|
|
29
|
+
const EndNode = "#EndNode";
|
|
30
|
+
const Load = "#Load";
|
|
31
|
+
const LoopKey = "#LoopKey";
|
|
32
|
+
const ParentBranch = "#ParentBranch";
|
|
33
|
+
const PendingEffects = "#PendingEffects";
|
|
34
|
+
const PendingRenders = "#PendingRenders";
|
|
35
|
+
const PendingScopes = "#PendingScopes";
|
|
36
|
+
const PlaceholderBranch = "#PlaceholderBranch";
|
|
37
|
+
const PlaceholderContent = "#PlaceholderContent";
|
|
38
|
+
const Renderer = "#Renderer";
|
|
39
|
+
const StartNode = "#StartNode";
|
|
40
|
+
const Subscriptions = "#Subscriptions";
|
|
41
|
+
const TagVariable = "#TagVariable";
|
|
42
|
+
const TagVariableChange = "#TagVariableChange";
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/common/constants/closure-signal-prop.debug.ts
|
|
45
|
+
const ScopeInstancesAccessor = "scopeInstancesAccessor";
|
|
46
|
+
const SignalIndexAccessor = "signalIndexAccessor";
|
|
47
|
+
const Index = "index";
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/common/constants/keyed-scopes-prop.debug.ts
|
|
50
|
+
const PreviousKey = "PreviousKey:";
|
|
51
|
+
const Scope = "scope";
|
|
52
|
+
const Signal = "signal";
|
|
53
|
+
const Value = "value";
|
|
54
|
+
const Pending = "pending";
|
|
55
|
+
const Clone = "clone";
|
|
56
|
+
const Setup = "setup";
|
|
57
|
+
const Params = "params";
|
|
58
|
+
const Owner = "owner";
|
|
59
|
+
const Accessor = "accessor";
|
|
60
|
+
const LocalClosures = "localClosures";
|
|
61
|
+
const LocalClosureValues = "localClosureValues";
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/common/helpers.ts
|
|
64
|
+
const htmlAttrNameReg = /^[^a-z_]|[^a-z0-9._:-]/i;
|
|
65
|
+
const knownWrongAttrs = {
|
|
66
|
+
className: "class",
|
|
67
|
+
classList: "class",
|
|
68
|
+
htmlFor: "for",
|
|
69
|
+
acceptCharset: "accept-charset",
|
|
70
|
+
httpEquiv: "http-equiv",
|
|
71
|
+
defaultValue: "value",
|
|
72
|
+
defaultChecked: "checked",
|
|
73
|
+
dangerouslySetInnerHTML: "$!{html}",
|
|
74
|
+
key: "<for by>",
|
|
75
|
+
ref: "<tag/ref>",
|
|
76
|
+
"v-if": "<if>",
|
|
77
|
+
"v-else": "<else>",
|
|
78
|
+
"v-else-if": "<else if>",
|
|
79
|
+
"v-for": "<for>",
|
|
80
|
+
"v-show": "<if>",
|
|
81
|
+
"v-model": "value:=state",
|
|
82
|
+
"v-bind": "...attrs",
|
|
83
|
+
"v-html": "$!{html}",
|
|
84
|
+
"v-text": "${text}"
|
|
85
|
+
};
|
|
86
|
+
function getWrongAttrSuggestion(name) {
|
|
87
|
+
if (Object.hasOwn(knownWrongAttrs, name)) return knownWrongAttrs[name];
|
|
88
|
+
const colon = name.indexOf(":");
|
|
89
|
+
if (colon > 0) {
|
|
90
|
+
const rest = name.slice(colon + 1);
|
|
91
|
+
switch (name.slice(0, colon)) {
|
|
92
|
+
case "class": return `class={ ${rest}: condition }`;
|
|
93
|
+
case "style": return `style={ ${rest}: value }`;
|
|
94
|
+
case "on":
|
|
95
|
+
case "v-on": return `on${rest.charAt(0).toUpperCase()}${rest.slice(1)}`;
|
|
96
|
+
case "bind":
|
|
97
|
+
case "v-model": return `${rest}:=state`;
|
|
98
|
+
case "v-bind": return rest;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function _call(fn, v) {
|
|
103
|
+
fn(v);
|
|
104
|
+
return v;
|
|
105
|
+
}
|
|
106
|
+
function stringifyClassObject(name, value) {
|
|
107
|
+
return value ? name : "";
|
|
108
|
+
}
|
|
109
|
+
const warnedStyleKeys = /* @__PURE__ */ new Set();
|
|
110
|
+
function stringifyStyleObject(name, value) {
|
|
111
|
+
if (/[A-Z]/.test(name) && !name.includes("-") && !warnedStyleKeys.has(name)) {
|
|
112
|
+
warnedStyleKeys.add(name);
|
|
113
|
+
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-")}\`.`);
|
|
114
|
+
}
|
|
115
|
+
return value || value === 0 ? escapeStyleAttr(name) + ":" + escapeStyleAttr(value + "") : "";
|
|
116
|
+
}
|
|
117
|
+
const unsafeStyleAttrReg = /[\\;]/g;
|
|
118
|
+
const replaceUnsafeStyleAttr = (c) => c === ";" ? "\\3B " : "\\\\";
|
|
119
|
+
function escapeStyleAttr(str) {
|
|
120
|
+
return unsafeStyleAttrReg.test(str) ? str.replace(unsafeStyleAttrReg, replaceUnsafeStyleAttr) : str;
|
|
121
|
+
}
|
|
122
|
+
function escapeStyleValue(str) {
|
|
123
|
+
let closers = "";
|
|
124
|
+
const result = str.replace(/[\\"'{};<>]|\/(?=\*)/g, (c) => c === "<" ? "\\3C " : c === ";" ? "\\3B " : c === "{" ? "\\7B " : "\\" + c);
|
|
125
|
+
for (const c of result) if (c === "(") closers = ")" + closers;
|
|
126
|
+
else if (c === "[") closers = "]" + closers;
|
|
127
|
+
else if (c === closers[0]) closers = closers.slice(1);
|
|
128
|
+
return result + closers;
|
|
129
|
+
}
|
|
130
|
+
const toDelimitedString = function toDelimitedString(val, delimiter, stringify) {
|
|
131
|
+
let str = "";
|
|
132
|
+
let sep = "";
|
|
133
|
+
let part;
|
|
134
|
+
if (val) if (typeof val !== "object") str += val;
|
|
135
|
+
else if (Array.isArray(val)) for (const v of val) {
|
|
136
|
+
part = toDelimitedString(v, delimiter, stringify);
|
|
137
|
+
if (part) {
|
|
138
|
+
str += sep + part;
|
|
139
|
+
sep = delimiter;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else for (const name in val) {
|
|
143
|
+
part = stringify(name, val[name]);
|
|
144
|
+
if (part) {
|
|
145
|
+
str += sep + part;
|
|
146
|
+
sep = delimiter;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return str;
|
|
150
|
+
};
|
|
151
|
+
function isEventHandler(name) {
|
|
152
|
+
return /^on[A-Z-]/.test(name);
|
|
153
|
+
}
|
|
154
|
+
function getEventHandlerName(name) {
|
|
155
|
+
return name[2] === "-" ? name.slice(3) : name.slice(2).toLowerCase();
|
|
156
|
+
}
|
|
157
|
+
function isNotVoid(value) {
|
|
158
|
+
return value != null && value !== false;
|
|
159
|
+
}
|
|
160
|
+
function isPromise(value) {
|
|
161
|
+
return value != null && typeof value.then === "function";
|
|
162
|
+
}
|
|
163
|
+
function normalizeDynamicRenderer(value) {
|
|
164
|
+
if (value) {
|
|
165
|
+
if (typeof value === "string") return value;
|
|
166
|
+
const normalized = value.content || value.default || value;
|
|
167
|
+
if (!((typeof normalized === "object" || typeof normalized === "function") && "id" in normalized)) {
|
|
168
|
+
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.`);
|
|
169
|
+
if (typeof value !== "object" && typeof value !== "function") throw new Error(`A dynamic tag must be a string tag name (like \`"div"\`) or a Marko template/component, but received a ${typeof value}.`);
|
|
170
|
+
}
|
|
171
|
+
if ("id" in normalized) return normalized;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
let branchesEnabled;
|
|
175
|
+
function withBranches(runtime) {
|
|
176
|
+
branchesEnabled = 1;
|
|
177
|
+
return runtime;
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/common/errors.ts
|
|
181
|
+
const lowercaseEventHandlerReg = /^on[a-z]/;
|
|
182
|
+
function assertValidAttrValue(name, value) {
|
|
183
|
+
if (value && typeof value !== "string" && lowercaseEventHandlerReg.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.`);
|
|
184
|
+
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." : ""}`);
|
|
185
|
+
const unrenderable = describeUnrenderable(value);
|
|
186
|
+
if (unrenderable) throw new Error(`The \`${name}\` attribute cannot be ${unrenderable}.`);
|
|
187
|
+
}
|
|
188
|
+
function assertValidTextValue(value) {
|
|
189
|
+
const unrenderable = describeUnrenderable(value);
|
|
190
|
+
if (unrenderable) throw new Error(`Text content cannot be ${unrenderable}.`);
|
|
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") throw new Error(`A \`<for>\` tag's \`by\` attribute must return a string or number for each item, but received ${key === null ? "null" : `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 assertValidRangeBound(name, value) {
|
|
215
|
+
if (!isFinite(value)) throw new Error(`A \`<for>\` tag's \`${name}\` attribute must be a finite number, but received ${describeForValue(value)}.`);
|
|
216
|
+
}
|
|
217
|
+
function describeForValue(value) {
|
|
218
|
+
return typeof value === "number" || typeof value === "bigint" ? `\`${value}\`` : value === null ? "null" : `type "${typeof value}"`;
|
|
219
|
+
}
|
|
220
|
+
function assertValidAttrName(name) {
|
|
221
|
+
if (htmlAttrNameReg.test(name)) throw new Error(`Invalid attribute name: ${JSON.stringify(name)}`);
|
|
222
|
+
const suggestion = getWrongAttrSuggestion(name);
|
|
223
|
+
if (suggestion) throw new Error(`\`${name}\` is not a valid attribute, did you mean \`${suggestion}\`?`);
|
|
224
|
+
}
|
|
225
|
+
function _el_read_error() {
|
|
226
|
+
throw new Error("Element references can only be read in scripts and event handlers.");
|
|
227
|
+
}
|
|
228
|
+
function _hoist_read_error() {
|
|
229
|
+
throw new Error("Hoisted values can only be read in scripts and event handlers.");
|
|
230
|
+
}
|
|
231
|
+
function _assert_hoist(value) {
|
|
232
|
+
if (typeof value !== "function") throw new Error(`Hoisted values must be functions, received type "${typeof value}".`);
|
|
233
|
+
}
|
|
234
|
+
function assertExclusiveAttrs(attrs, onError = throwErr) {
|
|
235
|
+
if (attrs) {
|
|
236
|
+
let exclusiveAttrs;
|
|
237
|
+
if (attrs.checkedChange) (exclusiveAttrs ||= []).push("checkedChange");
|
|
238
|
+
if ("checkedValue" in attrs) {
|
|
239
|
+
(exclusiveAttrs ||= []).push("checkedValue");
|
|
240
|
+
if ("checked" in attrs) exclusiveAttrs.push("checked");
|
|
241
|
+
} else if (attrs.checkedValueChange) {
|
|
242
|
+
(exclusiveAttrs ||= []).push("checkedValueChange");
|
|
243
|
+
if ("checked" in attrs) exclusiveAttrs.push("checked");
|
|
244
|
+
}
|
|
245
|
+
if (attrs.valueChange) (exclusiveAttrs ||= []).push("valueChange");
|
|
246
|
+
if (exclusiveAttrs && exclusiveAttrs.length > 1) onError(`The attributes ${joinWithAnd(exclusiveAttrs)} are mutually exclusive.`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function assertHandlerIsFunction(name, value) {
|
|
250
|
+
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}".`);
|
|
251
|
+
}
|
|
252
|
+
function assertValidTagName(tagName) {
|
|
253
|
+
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.`);
|
|
254
|
+
}
|
|
255
|
+
function throwErr(msg) {
|
|
256
|
+
throw new Error(msg);
|
|
257
|
+
}
|
|
258
|
+
function joinWithAnd(a) {
|
|
259
|
+
switch (a.length) {
|
|
260
|
+
case 0: return "";
|
|
261
|
+
case 1: return a[0];
|
|
262
|
+
case 2: return `${a[0]} and ${a[1]}`;
|
|
263
|
+
default: return `${a.slice(0, -1).join(", ")}, and ${a[a.length - 1]}`;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/common/for.ts
|
|
268
|
+
function forIn(obj, cb) {
|
|
269
|
+
for (const key in obj) cb(key, obj[key]);
|
|
270
|
+
}
|
|
271
|
+
function forOf(list, cb) {
|
|
272
|
+
assertValidList(list);
|
|
273
|
+
if (list) {
|
|
274
|
+
let i = 0;
|
|
275
|
+
for (const item of list) cb(item, i++);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function forTo(to, from, step, cb) {
|
|
279
|
+
assertValidRangeBound("to", to);
|
|
280
|
+
const start = from || 0;
|
|
281
|
+
const delta = step || 1;
|
|
282
|
+
for (let steps = (to - start) / delta, i = 0; i <= steps; i++) cb(start + i * delta);
|
|
283
|
+
}
|
|
284
|
+
function forUntil(until, from, step, cb) {
|
|
285
|
+
assertValidRangeBound("until", until);
|
|
286
|
+
const start = from || 0;
|
|
287
|
+
const delta = step || 1;
|
|
288
|
+
for (let steps = (until - start) / delta, i = 0; i < steps; i++) cb(start + i * delta);
|
|
289
|
+
}
|
|
290
|
+
//#endregion
|
|
291
|
+
//#region src/dom/queue.ts
|
|
292
|
+
let rendering;
|
|
293
|
+
let runId = 2;
|
|
294
|
+
const caughtError = /* @__PURE__ */ new WeakSet();
|
|
295
|
+
const placeholderShown = /* @__PURE__ */ new WeakSet();
|
|
296
|
+
let pendingEffects = [];
|
|
297
|
+
let pendingRenders = [];
|
|
298
|
+
const scopeKeyOffset = 1e6;
|
|
299
|
+
function queueRender(scope, signal, signalKey, value, scopeKey = scope["#Id"]) {
|
|
300
|
+
let render;
|
|
301
|
+
if (signalKey >= 0 && (render = scope[signalKey])) {
|
|
302
|
+
render[Value] = value;
|
|
303
|
+
if (render["gen"] === runId || catchEnabled && render["pending"]) return;
|
|
304
|
+
render["gen"] = runId;
|
|
305
|
+
} else {
|
|
306
|
+
render = {
|
|
307
|
+
["key"]: scopeKey * scopeKeyOffset + signalKey,
|
|
308
|
+
[Scope]: scope,
|
|
309
|
+
[Signal]: signal,
|
|
310
|
+
[Value]: value,
|
|
311
|
+
["gen"]: runId
|
|
312
|
+
};
|
|
313
|
+
if (signalKey >= 0) scope[signalKey] = render;
|
|
314
|
+
}
|
|
315
|
+
queuePendingRender(render);
|
|
316
|
+
}
|
|
317
|
+
function queuePendingRender(render) {
|
|
318
|
+
let i = pendingRenders.push(render) - 1;
|
|
319
|
+
while (i) {
|
|
320
|
+
const parentIndex = i - 1 >> 1;
|
|
321
|
+
const parent = pendingRenders[parentIndex];
|
|
322
|
+
if (render["key"] - parent["key"] >= 0) break;
|
|
323
|
+
pendingRenders[i] = parent;
|
|
324
|
+
i = parentIndex;
|
|
325
|
+
}
|
|
326
|
+
pendingRenders[i] = render;
|
|
327
|
+
}
|
|
328
|
+
function queueEffect(scope, fn) {
|
|
329
|
+
pendingEffects.push(fn, scope);
|
|
330
|
+
}
|
|
331
|
+
function run() {
|
|
332
|
+
const effects = pendingEffects;
|
|
333
|
+
try {
|
|
334
|
+
rendering = 1;
|
|
335
|
+
runRenders();
|
|
336
|
+
} finally {
|
|
337
|
+
runId++;
|
|
338
|
+
rendering = 0;
|
|
339
|
+
pendingRenders = [];
|
|
340
|
+
pendingEffects = [];
|
|
341
|
+
}
|
|
342
|
+
runEffects(effects);
|
|
343
|
+
}
|
|
344
|
+
function queueAsyncRender(scope, signal, value) {
|
|
345
|
+
queueRender(scope, signal, -1, value);
|
|
346
|
+
queueMicrotask(run);
|
|
347
|
+
}
|
|
348
|
+
function prepareEffects(fn) {
|
|
349
|
+
const prevRenders = pendingRenders;
|
|
350
|
+
const prevEffects = pendingEffects;
|
|
351
|
+
const preparedEffects = pendingEffects = [];
|
|
352
|
+
pendingRenders = [];
|
|
353
|
+
try {
|
|
354
|
+
rendering = 1;
|
|
355
|
+
fn();
|
|
356
|
+
runRenders();
|
|
357
|
+
} finally {
|
|
358
|
+
runId++;
|
|
359
|
+
rendering = 0;
|
|
360
|
+
pendingRenders = prevRenders;
|
|
361
|
+
pendingEffects = prevEffects;
|
|
362
|
+
}
|
|
363
|
+
return preparedEffects;
|
|
364
|
+
}
|
|
365
|
+
let runEffects = ((effects) => {
|
|
366
|
+
for (let i = 0; i < effects.length;) effects[i++](effects[i++]);
|
|
367
|
+
});
|
|
368
|
+
let runRender = (render) => {
|
|
369
|
+
if (!branchesEnabled || render["scope"]["#ClosestBranch"]?.["#Gen"] !== 0) render[Signal](render[Scope], render[Value]);
|
|
370
|
+
};
|
|
371
|
+
let catchEnabled;
|
|
372
|
+
function installCatch(wrapEffects, wrapRender) {
|
|
373
|
+
catchEnabled = 1;
|
|
374
|
+
withBranches();
|
|
375
|
+
runEffects = wrapEffects(runEffects);
|
|
376
|
+
runRender = wrapRender(runRender);
|
|
377
|
+
}
|
|
378
|
+
function runRenders() {
|
|
379
|
+
while (pendingRenders.length) {
|
|
380
|
+
const render = pendingRenders[0];
|
|
381
|
+
const item = pendingRenders.pop();
|
|
382
|
+
if (render !== item) {
|
|
383
|
+
let i = 0;
|
|
384
|
+
const mid = pendingRenders.length >> 1;
|
|
385
|
+
const key = (pendingRenders[0] = item)["key"];
|
|
386
|
+
while (i < mid) {
|
|
387
|
+
let bestChild = (i << 1) + 1;
|
|
388
|
+
const right = bestChild + 1;
|
|
389
|
+
if (right < pendingRenders.length && pendingRenders[right]["key"] - pendingRenders[bestChild]["key"] < 0) bestChild = right;
|
|
390
|
+
if (pendingRenders[bestChild]["key"] - key >= 0) break;
|
|
391
|
+
else {
|
|
392
|
+
pendingRenders[i] = pendingRenders[bestChild];
|
|
393
|
+
i = bestChild;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
pendingRenders[i] = item;
|
|
397
|
+
}
|
|
398
|
+
runRender(render);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
//#endregion
|
|
402
|
+
//#region src/dom/abort-signal.ts
|
|
403
|
+
function $signalReset(scope, id) {
|
|
404
|
+
const ctrl = scope[AbortControllers]?.[id];
|
|
405
|
+
if (ctrl) {
|
|
406
|
+
scope[AbortControllers][id] = void 0;
|
|
407
|
+
if (rendering) queueEffect(ctrl, abort);
|
|
408
|
+
else abort(ctrl);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
function $signal(scope, id) {
|
|
412
|
+
trackCleanup(scope);
|
|
413
|
+
return ((scope[AbortControllers] ||= {})[id] ||= new AbortController()).signal;
|
|
414
|
+
}
|
|
415
|
+
/** Enrols `scope` with its branch so destroying the branch cleans it up. */
|
|
416
|
+
function trackCleanup(scope, subscribers) {
|
|
417
|
+
const branch = scope[ClosestBranch];
|
|
418
|
+
if (branch) (branch[AbortScopes] ||= /* @__PURE__ */ new Set()).add(scope);
|
|
419
|
+
if (subscribers) (scope[Subscriptions] ||= []).push(subscribers);
|
|
420
|
+
}
|
|
421
|
+
function abort(ctrl) {
|
|
422
|
+
ctrl.abort();
|
|
423
|
+
}
|
|
424
|
+
//#endregion
|
|
425
|
+
//#region src/common/meta.ts
|
|
426
|
+
const DYNAMIC_TAG_SCRIPT_REGISTER_ID = "_dynamicTagScript";
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/common/opt.ts
|
|
429
|
+
function toArray(opt) {
|
|
430
|
+
return opt ? Array.isArray(opt) ? opt : [opt] : [];
|
|
431
|
+
}
|
|
432
|
+
function forEach(opt, cb) {
|
|
433
|
+
if (opt) if (Array.isArray(opt)) for (const item of opt) cb(item);
|
|
434
|
+
else cb(opt);
|
|
435
|
+
}
|
|
436
|
+
function push(opt, item) {
|
|
437
|
+
return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
|
|
438
|
+
}
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region src/dom/event.ts
|
|
441
|
+
function _on(element, type, handler) {
|
|
442
|
+
assertHandlerIsFunction("on" + type[0].toUpperCase() + type.slice(1), handler);
|
|
443
|
+
if (element["$" + type] === void 0) delegate(type, handleDelegated);
|
|
444
|
+
element["$" + type] = handler || null;
|
|
445
|
+
}
|
|
446
|
+
const delegate = (type, handler) => handler[type] ||= (document.addEventListener(type, handler, true), 1);
|
|
447
|
+
function handleDelegated(ev) {
|
|
448
|
+
let target = !rendering && ev.target;
|
|
449
|
+
Object.defineProperty(ev, "currentTarget", {
|
|
450
|
+
configurable: true,
|
|
451
|
+
get() {
|
|
452
|
+
console.error("Event.currentTarget is not supported in Marko's delegated events. Instead use an element reference or the second parameter of the event handler.");
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
while (target) {
|
|
457
|
+
target["$" + ev.type]?.(ev, target);
|
|
458
|
+
target = ev.bubbles && !ev.cancelBubble && target.parentNode;
|
|
459
|
+
}
|
|
460
|
+
delete ev.currentTarget;
|
|
461
|
+
}
|
|
462
|
+
//#endregion
|
|
463
|
+
//#region src/dom/parse-html.ts
|
|
464
|
+
const parsers = {};
|
|
465
|
+
function parseHTML(html, ns) {
|
|
466
|
+
const parser = parsers[ns] ||= document.createElementNS(ns, "template");
|
|
467
|
+
parser.innerHTML = html;
|
|
468
|
+
return parser.content || parser;
|
|
469
|
+
}
|
|
470
|
+
//#endregion
|
|
471
|
+
//#region src/dom/scope.ts
|
|
472
|
+
let nextScopeId = 1e6;
|
|
473
|
+
let collectingScopes;
|
|
474
|
+
function createScope($global, closestBranch) {
|
|
475
|
+
const scope = {
|
|
476
|
+
["#Id"]: nextScopeId++,
|
|
477
|
+
[Gen$1]: runId,
|
|
478
|
+
[ClosestBranch]: closestBranch,
|
|
479
|
+
[Global]: $global
|
|
480
|
+
};
|
|
481
|
+
collectingScopes?.push(scope);
|
|
482
|
+
return scope;
|
|
483
|
+
}
|
|
484
|
+
function syncGen(scope) {
|
|
485
|
+
scope[Gen$1] = runId;
|
|
486
|
+
}
|
|
487
|
+
function _assert_init(scope, accessor) {
|
|
488
|
+
if (scope["#Gen"] === runId || !(accessor in scope)) throw new ReferenceError(`Cannot access '${accessor}' before initialization`);
|
|
489
|
+
return scope[accessor];
|
|
490
|
+
}
|
|
491
|
+
function collectScopes(fn) {
|
|
492
|
+
const prev = collectingScopes;
|
|
493
|
+
collectingScopes = [];
|
|
494
|
+
try {
|
|
495
|
+
fn();
|
|
496
|
+
return collectingScopes;
|
|
497
|
+
} finally {
|
|
498
|
+
collectingScopes = prev;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
function skipScope() {
|
|
502
|
+
return nextScopeId++;
|
|
503
|
+
}
|
|
504
|
+
function findBranchWithKey(scope, key) {
|
|
505
|
+
let branch = scope[ClosestBranch];
|
|
506
|
+
while (branch && branch[key] == null) branch = branch[ParentBranch];
|
|
507
|
+
return branch;
|
|
508
|
+
}
|
|
509
|
+
function destroyBranch(branch) {
|
|
510
|
+
branch[ParentBranch]?.[BranchScopes]?.delete(branch);
|
|
511
|
+
destroyNestedScopes(branch);
|
|
512
|
+
}
|
|
513
|
+
function destroyScope(scope) {
|
|
514
|
+
if (scope["#Gen"]) {
|
|
515
|
+
destroyNestedScopes(scope);
|
|
516
|
+
cleanupScope(scope);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
const destroyNestedScopes = function destroyNestedScopes(scope) {
|
|
520
|
+
scope[Gen$1] = 0;
|
|
521
|
+
scope[BranchScopes]?.forEach(destroyNestedScopes);
|
|
522
|
+
scope[AbortScopes]?.forEach(cleanupScope);
|
|
523
|
+
};
|
|
524
|
+
function cleanupScope(scope) {
|
|
525
|
+
scope[Subscriptions]?.forEach(unsubscribe, scope);
|
|
526
|
+
for (const id in scope[AbortControllers]) $signalReset(scope, id);
|
|
527
|
+
}
|
|
528
|
+
function unsubscribe(subscribers) {
|
|
529
|
+
subscribers.delete(this);
|
|
530
|
+
}
|
|
531
|
+
function removeAndDestroyBranch(branch) {
|
|
532
|
+
destroyBranch(branch);
|
|
533
|
+
removeChildNodes(branch[StartNode], branch[EndNode]);
|
|
534
|
+
}
|
|
535
|
+
function insertBranchBefore(branch, parentNode, nextSibling) {
|
|
536
|
+
insertChildNodes(parentNode, nextSibling, branch[StartNode], branch[EndNode]);
|
|
537
|
+
}
|
|
538
|
+
function tempDetachBranch(branch) {
|
|
539
|
+
const fragment = new DocumentFragment();
|
|
540
|
+
fragment.namespaceURI = branch[StartNode].parentNode.namespaceURI;
|
|
541
|
+
insertChildNodes(fragment, null, branch[StartNode], branch[EndNode]);
|
|
542
|
+
}
|
|
543
|
+
//#endregion
|
|
544
|
+
//#region src/dom/schedule.ts
|
|
545
|
+
let runTask;
|
|
546
|
+
let isScheduled;
|
|
547
|
+
let channel;
|
|
548
|
+
function schedule() {
|
|
549
|
+
if (!isScheduled) {
|
|
550
|
+
if (console.createTask) {
|
|
551
|
+
const task = console.createTask("queue");
|
|
552
|
+
runTask = () => task.run(run);
|
|
553
|
+
} else runTask = run;
|
|
554
|
+
isScheduled = 1;
|
|
555
|
+
queueMicrotask(flushAndWaitFrame);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
function flushAndWaitFrame() {
|
|
559
|
+
requestAnimationFrame(triggerMacroTask);
|
|
560
|
+
runTask();
|
|
561
|
+
}
|
|
562
|
+
function triggerMacroTask() {
|
|
563
|
+
if (!channel) {
|
|
564
|
+
channel = new MessageChannel();
|
|
565
|
+
channel.port1.onmessage = () => {
|
|
566
|
+
isScheduled = 0;
|
|
567
|
+
{
|
|
568
|
+
const run = runTask;
|
|
569
|
+
runTask = void 0;
|
|
570
|
+
run();
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
channel.port2.postMessage(0);
|
|
575
|
+
}
|
|
576
|
+
//#endregion
|
|
577
|
+
//#region src/dom/signals.ts
|
|
578
|
+
function _let(id, fn) {
|
|
579
|
+
const valueAccessor = id.slice(0, id.lastIndexOf("/"));
|
|
580
|
+
id = +id.slice(id.lastIndexOf("/") + 1);
|
|
581
|
+
return (scope, value) => {
|
|
582
|
+
if (rendering) {
|
|
583
|
+
if (scope["#Gen"] === runId) {
|
|
584
|
+
scope[valueAccessor] = value;
|
|
585
|
+
fn?.(scope);
|
|
586
|
+
}
|
|
587
|
+
} else if ((scope[valueAccessor] !== value || !(valueAccessor in scope)) && (scope[valueAccessor] = value, fn)) {
|
|
588
|
+
schedule();
|
|
589
|
+
queueRender(scope, fn, id);
|
|
590
|
+
}
|
|
591
|
+
return value;
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
function _let_change(id, fn) {
|
|
595
|
+
const valueAccessor = id.slice(0, id.lastIndexOf("/"));
|
|
596
|
+
const valueChangeAccessor = TagVariableChange$1 + valueAccessor;
|
|
597
|
+
const base = _let(id, fn);
|
|
598
|
+
return (scope, value, valueChange) => {
|
|
599
|
+
if (rendering) if ((scope[valueChangeAccessor] = valueChange) && (scope[valueAccessor] !== value || !(valueAccessor in scope))) {
|
|
600
|
+
scope[valueAccessor] = value;
|
|
601
|
+
fn?.(scope);
|
|
602
|
+
} else base(scope, value);
|
|
603
|
+
else if (scope[valueChangeAccessor]) scope[valueChangeAccessor](value);
|
|
604
|
+
else base(scope, value);
|
|
605
|
+
return value;
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
function _const(valueAccessor, fn) {
|
|
609
|
+
return ((scope, value) => {
|
|
610
|
+
if (scope[valueAccessor] !== value || !(valueAccessor in scope)) {
|
|
611
|
+
scope[valueAccessor] = value;
|
|
612
|
+
fn?.(scope);
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id") {
|
|
617
|
+
return (scope) => {
|
|
618
|
+
if (scope["#Gen"] === runId) if (~id in scope) {
|
|
619
|
+
if (!--scope[~id]) fn(scope);
|
|
620
|
+
} else scope[~id] = defaultPending;
|
|
621
|
+
else queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
function _for_closure(ownerLoopNodeAccessor, fn) {
|
|
625
|
+
const scopeAccessor = BranchScopes$1 + ownerLoopNodeAccessor;
|
|
626
|
+
const ownerSignal = (ownerScope) => {
|
|
627
|
+
const scopes = toArray(ownerScope[scopeAccessor]);
|
|
628
|
+
if (scopes.length) queueRender(ownerScope, () => {
|
|
629
|
+
for (const scope of scopes) if (scope["#Gen"] > 0 && scope["#Gen"] < runId) fn(scope);
|
|
630
|
+
}, -1, 0, scopes[0]["#Id"]);
|
|
631
|
+
};
|
|
632
|
+
ownerSignal._ = fn;
|
|
633
|
+
return ownerSignal;
|
|
634
|
+
}
|
|
635
|
+
function _for_selector(ownerLoopNodeAccessor, ownerValueAccessor, keyValueAccessor, fn) {
|
|
636
|
+
const scopeAccessor = BranchScopes$1 + ownerLoopNodeAccessor;
|
|
637
|
+
const mapAccessor = KeyedScopes + ownerLoopNodeAccessor;
|
|
638
|
+
const prevKeyProp = `${PreviousKey}${ownerValueAccessor}`;
|
|
639
|
+
const ownerSignal = (ownerScope) => {
|
|
640
|
+
const scopes = toArray(ownerScope[scopeAccessor]);
|
|
641
|
+
if (ownerScope["#Gen"] < runId && scopes.length) {
|
|
642
|
+
const nextKey = ownerScope[ownerValueAccessor];
|
|
643
|
+
queueRender(ownerScope, () => {
|
|
644
|
+
const map = keyedScopes(ownerScope, scopeAccessor, mapAccessor, keyValueAccessor);
|
|
645
|
+
if (map && prevKeyProp in map) {
|
|
646
|
+
const prevScope = map.get(map[prevKeyProp]);
|
|
647
|
+
const nextScope = map.get(nextKey);
|
|
648
|
+
if (prevScope !== nextScope) {
|
|
649
|
+
runLiveBranch(prevScope, fn);
|
|
650
|
+
runLiveBranch(nextScope, fn);
|
|
651
|
+
}
|
|
652
|
+
} else for (const scope of toArray(ownerScope[scopeAccessor])) runLiveBranch(scope, fn);
|
|
653
|
+
if (map) map[prevKeyProp] = nextKey;
|
|
654
|
+
}, -1, 0, scopes[0]["#Id"]);
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
ownerSignal._ = fn;
|
|
658
|
+
return ownerSignal;
|
|
659
|
+
}
|
|
660
|
+
function keyedScopes(ownerScope, scopeAccessor, mapAccessor, keyValueAccessor) {
|
|
661
|
+
const map = ownerScope[mapAccessor] ||= /* @__PURE__ */ new Map();
|
|
662
|
+
if (!map.size) for (const scope of toArray(ownerScope[scopeAccessor])) {
|
|
663
|
+
const key = scope["#LoopKey"] ?? scope[keyValueAccessor];
|
|
664
|
+
if (key === void 0) return ownerScope[mapAccessor] = null;
|
|
665
|
+
scope[LoopKey] = key;
|
|
666
|
+
map.set(key, scope);
|
|
667
|
+
}
|
|
668
|
+
return map;
|
|
669
|
+
}
|
|
670
|
+
function runLiveBranch(scope, fn) {
|
|
671
|
+
if (scope && scope["#Gen"] > 0 && scope["#Gen"] < runId) fn(scope);
|
|
672
|
+
}
|
|
673
|
+
function _if_closure(ownerConditionalNodeAccessor, branch, fn) {
|
|
674
|
+
const scopeAccessor = BranchScopes$1 + ownerConditionalNodeAccessor;
|
|
675
|
+
const branchAccessor = ConditionalRenderer + ownerConditionalNodeAccessor;
|
|
676
|
+
const ownerSignal = (scope) => {
|
|
677
|
+
const ifScope = scope[scopeAccessor];
|
|
678
|
+
if (ifScope && ifScope["#Gen"] > 0 && ifScope["#Gen"] < runId && (scope[branchAccessor] || 0) === branch) queueRender(ifScope, fn, -1);
|
|
679
|
+
};
|
|
680
|
+
ownerSignal._ = fn;
|
|
681
|
+
return ownerSignal;
|
|
682
|
+
}
|
|
683
|
+
function subscribeToScopeSet(ownerScope, accessor, scope) {
|
|
684
|
+
const subscribers = ownerScope[accessor] ||= /* @__PURE__ */ new Set();
|
|
685
|
+
const { size } = subscribers;
|
|
686
|
+
if (subscribers.add(scope).size !== size) trackCleanup(scope, subscribers);
|
|
687
|
+
}
|
|
688
|
+
function _closure(...closureSignals) {
|
|
689
|
+
const [firstSignal] = closureSignals;
|
|
690
|
+
const scopeInstances = firstSignal[ScopeInstancesAccessor];
|
|
691
|
+
const signalIndex = firstSignal[SignalIndexAccessor];
|
|
692
|
+
for (let i = closureSignals.length; i--;) closureSignals[i][Index] = i;
|
|
693
|
+
return (scope) => {
|
|
694
|
+
if (scope[scopeInstances]) {
|
|
695
|
+
for (const childScope of scope[scopeInstances]) if (childScope["#Gen"] > 0 && childScope["#Gen"] < runId) queueRender(childScope, closureSignals[childScope[signalIndex] || 0], -1);
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
|
|
700
|
+
const closureSignal = ((scope) => {
|
|
701
|
+
scope[closureSignal[SignalIndexAccessor]] = closureSignal[Index];
|
|
702
|
+
fn(scope);
|
|
703
|
+
subscribeToScopeSet(getOwnerScope ? getOwnerScope(scope) : scope["_"], closureSignal[ScopeInstancesAccessor], scope);
|
|
704
|
+
});
|
|
705
|
+
closureSignal[ScopeInstancesAccessor] = ClosureScopes + valueAccessor;
|
|
706
|
+
closureSignal[SignalIndexAccessor] = ClosureSignalIndex + valueAccessor;
|
|
707
|
+
resumeId && _resume(resumeId, closureSignal);
|
|
708
|
+
return closureSignal;
|
|
709
|
+
}
|
|
710
|
+
function _child_setup(setup) {
|
|
711
|
+
setup._ = (scope, owner) => {
|
|
712
|
+
scope["_"] = owner;
|
|
713
|
+
queueRender(scope, setup, -1);
|
|
714
|
+
};
|
|
715
|
+
return setup;
|
|
716
|
+
}
|
|
717
|
+
function _var(scope, childAccessor, signal) {
|
|
718
|
+
scope[childAccessor][TagVariable] = (value) => signal(scope, value);
|
|
719
|
+
}
|
|
720
|
+
const _return = (scope, value) => scope[TagVariable]?.(value);
|
|
721
|
+
function _return_change(scope, changeHandler) {
|
|
722
|
+
if (changeHandler) scope[TagVariableChange] = changeHandler;
|
|
723
|
+
}
|
|
724
|
+
const _var_change = (scope, value, name = "This") => {
|
|
725
|
+
if (typeof scope["#TagVariableChange"] !== "function") throw new TypeError(`${name} is a readonly tag variable.`);
|
|
726
|
+
scope[TagVariableChange](value);
|
|
727
|
+
};
|
|
728
|
+
const tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
|
|
729
|
+
function _id({ [Global]: $global }) {
|
|
730
|
+
const id = tagIdsByGlobal.get($global) || 0;
|
|
731
|
+
tagIdsByGlobal.set($global, id + 1);
|
|
732
|
+
return "c" + $global.runtimeId + $global.renderId + id.toString(36);
|
|
733
|
+
}
|
|
734
|
+
function _script(id, fn) {
|
|
735
|
+
_resume(id, fn);
|
|
736
|
+
return (scope) => {
|
|
737
|
+
queueEffect(scope, fn);
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
function _el_read(value) {
|
|
741
|
+
if (rendering) _el_read_error();
|
|
742
|
+
return value;
|
|
743
|
+
}
|
|
744
|
+
function* traverse(scope, path, i = path.length - 1) {
|
|
745
|
+
if (rendering) _hoist_read_error();
|
|
746
|
+
if (scope) if (Symbol.iterator in scope) for (const childScope of scope.values()) yield* traverse(childScope, path, i);
|
|
747
|
+
else {
|
|
748
|
+
const item = scope[path[i]];
|
|
749
|
+
if (i) yield* traverse(item, path, i - 1);
|
|
750
|
+
else yield typeof item === "function" ? item() : item;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
function _hoist(...path) {
|
|
754
|
+
return (scope) => {
|
|
755
|
+
const fn = () => traverse(scope, path).next().value;
|
|
756
|
+
fn[Symbol.iterator] = () => traverse(scope, path);
|
|
757
|
+
return fn;
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
function _hoist_resume(id, ...path) {
|
|
761
|
+
return _resume(id, _hoist(...path));
|
|
762
|
+
}
|
|
763
|
+
//#endregion
|
|
764
|
+
//#region src/dom/walker.ts
|
|
765
|
+
/** Cloned templates are small, where a TreeWalker's per-step cost dominates. */
|
|
766
|
+
let currentNode;
|
|
767
|
+
function walk(startNode, walkCodes, branch) {
|
|
768
|
+
currentNode = startNode;
|
|
769
|
+
walkInternal(0, walkCodes, branch);
|
|
770
|
+
}
|
|
771
|
+
const walkInternal = function walkInternal(currentWalkIndex, walkCodes, scope) {
|
|
772
|
+
let value;
|
|
773
|
+
let currentMultiplier;
|
|
774
|
+
let storedMultiplier = 0;
|
|
775
|
+
let currentScopeIndex = 0;
|
|
776
|
+
for (; currentWalkIndex < walkCodes.length;) {
|
|
777
|
+
value = walkCodes.charCodeAt(currentWalkIndex++);
|
|
778
|
+
currentMultiplier = storedMultiplier;
|
|
779
|
+
storedMultiplier = 0;
|
|
780
|
+
if (value === 32) scope[getDebugKey(currentScopeIndex++, currentNode)] = currentNode;
|
|
781
|
+
else if (value === 37 || value === 49) {
|
|
782
|
+
currentNode.replaceWith(currentNode = scope[getDebugKey(currentScopeIndex++, "#text")] = new Text());
|
|
783
|
+
if (value === 49) scope[getDebugKey(currentScopeIndex++, "#scopeOffset")] = skipScope();
|
|
784
|
+
} else if (value === 38) return currentWalkIndex;
|
|
785
|
+
else if (value === 47 || value === 48) {
|
|
786
|
+
currentWalkIndex = walkInternal(currentWalkIndex, walkCodes, scope[getDebugKey(currentScopeIndex++, "#childScope")] = createScope(scope[Global], scope[ClosestBranch]));
|
|
787
|
+
if (value === 48) scope[getDebugKey(currentScopeIndex++, "#scopeOffset")] = skipScope();
|
|
788
|
+
} else if (value < 92) {
|
|
789
|
+
value = 25 * currentMultiplier + value - 67;
|
|
790
|
+
while (value--) walkNextNode();
|
|
791
|
+
} else if (value < 107) {
|
|
792
|
+
value = 10 * currentMultiplier + value - 97;
|
|
793
|
+
while (value--) walkNextSibling();
|
|
794
|
+
} else if (value < 117) {
|
|
795
|
+
value = 10 * currentMultiplier + value - 107;
|
|
796
|
+
while (value--) currentNode = currentNode.parentNode || currentNode;
|
|
797
|
+
walkNextSibling();
|
|
798
|
+
} else {
|
|
799
|
+
if (value < 117 || value > 126) throw new Error(`Unknown walk code: ${value}`);
|
|
800
|
+
storedMultiplier = currentMultiplier * 10 + value - 117;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
function getDebugKey(index, node) {
|
|
805
|
+
if (typeof node === "string") return `${node}/${index}`;
|
|
806
|
+
else if (node.nodeType === 3) return `#text/${index}`;
|
|
807
|
+
else if (node.nodeType === 8) return `#comment/${index}`;
|
|
808
|
+
else if (node.nodeType === 1) return `#${node.tagName.toLowerCase()}/${index}`;
|
|
809
|
+
return index;
|
|
810
|
+
}
|
|
811
|
+
const walkNextNode = () => {
|
|
812
|
+
if (currentNode.firstChild) return currentNode = currentNode.firstChild;
|
|
813
|
+
while (!currentNode.nextSibling && currentNode.parentNode) currentNode = currentNode.parentNode;
|
|
814
|
+
walkNextSibling();
|
|
815
|
+
};
|
|
816
|
+
const walkNextSibling = () => currentNode = currentNode.nextSibling || currentNode;
|
|
817
|
+
//#endregion
|
|
818
|
+
//#region src/dom/resume.ts
|
|
819
|
+
const registeredValues = {};
|
|
820
|
+
let curRenders;
|
|
821
|
+
let embedRenders;
|
|
822
|
+
let readyIds;
|
|
823
|
+
function ready(readyId) {
|
|
824
|
+
(readyIds ||= /* @__PURE__ */ new Set()).add(readyId);
|
|
825
|
+
for (const renderId in curRenders) runResumeEffects(curRenders[renderId]);
|
|
826
|
+
}
|
|
827
|
+
function initEmbedded(readyId, runtimeId) {
|
|
828
|
+
if (!embedRenders) {
|
|
829
|
+
embedRenders = /* @__PURE__ */ new Map();
|
|
830
|
+
new MutationObserver(() => {
|
|
831
|
+
for (const [anchor, [renderId, scopes]] of embedRenders) if (!anchor.isConnected) {
|
|
832
|
+
embedRenders.delete(anchor);
|
|
833
|
+
delete curRenders[renderId];
|
|
834
|
+
for (const id in scopes) destroyScope(scopes[id]);
|
|
835
|
+
}
|
|
836
|
+
}).observe(document, {
|
|
837
|
+
childList: true,
|
|
838
|
+
subtree: true
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
ready(readyId);
|
|
842
|
+
init(runtimeId);
|
|
843
|
+
}
|
|
844
|
+
function init(runtimeId = "M") {
|
|
845
|
+
if (curRenders) {
|
|
846
|
+
if (curRenders !== self[runtimeId]) throw new Error(`Marko initialized multiple times with different $global.runtimeId's.`);
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
const renders = self[runtimeId];
|
|
850
|
+
const defineRuntime = (desc) => Object.defineProperty(self, runtimeId, desc);
|
|
851
|
+
const initRuntime = (renders) => {
|
|
852
|
+
defineRuntime({ value: curRenders = ((renderId) => {
|
|
853
|
+
const render = curRenders[renderId] = renders[renderId] || renders(renderId);
|
|
854
|
+
const walk = render.w;
|
|
855
|
+
const scopeLookup = {};
|
|
856
|
+
const getScope = (id) => scopeLookup[id] || (+id ? initScope(scopeLookup[id] = { ["#Id"]: +id }) : initGlobal());
|
|
857
|
+
const initGlobal = () => scopeLookup[0] ||= {
|
|
858
|
+
runtimeId,
|
|
859
|
+
renderId
|
|
860
|
+
};
|
|
861
|
+
const initScope = (scope) => {
|
|
862
|
+
scope[Gen$1] = 1;
|
|
863
|
+
scope[Global] = initGlobal();
|
|
864
|
+
if (branchesEnabled && scope["#ClosestBranchId"]) scope[ClosestBranch] = getScope(scope[ClosestBranchId]);
|
|
865
|
+
return scope;
|
|
866
|
+
};
|
|
867
|
+
const applyScopes = (partials) => {
|
|
868
|
+
let scopeId = partials[0];
|
|
869
|
+
for (let i = 1; i < partials.length; i++) {
|
|
870
|
+
const partial = partials[i];
|
|
871
|
+
if (typeof partial === "number") scopeId += partial;
|
|
872
|
+
else {
|
|
873
|
+
if (scopeId) initScope(Object.assign(scopeLookup[scopeId] ||= (partial["#Id"] = scopeId, partial), partial));
|
|
874
|
+
else Object.assign(initGlobal(), partial);
|
|
875
|
+
scopeId++;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
const serializeContext = ((data, registryId) => typeof data === "number" ? registryId ? registeredValues[registryId](getScope(data)) : getScope(data) : applyScopes(data));
|
|
880
|
+
const createVisitBranches = (branchScopesStack = [], branchStarts = [], orphanBranches = [], deferredOwners = [], curBranchScopes) => {
|
|
881
|
+
return (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length, j = deferredOwners.length) => {
|
|
882
|
+
if (visitType !== "[") {
|
|
883
|
+
visitScope[nextToken()] = visitType === ")" || visitType === "}" ? parent : visit;
|
|
884
|
+
accessor = BranchScopes$1 + lastToken;
|
|
885
|
+
singleNode = visitType !== "]" && visitType !== ")";
|
|
886
|
+
nextToken();
|
|
887
|
+
}
|
|
888
|
+
while (branchId = +lastToken) {
|
|
889
|
+
(endedBranches ||= []).push(branch = getScope(branchId));
|
|
890
|
+
setParentBranch(branch, branch[ClosestBranch]);
|
|
891
|
+
if (branch["#AwaitCounter"] = render.p?.[branchId]) branch[AwaitCounter].m = render.m;
|
|
892
|
+
if (singleNode) {
|
|
893
|
+
while (startVisit.previousSibling && ~visits.indexOf(startVisit = startVisit.previousSibling));
|
|
894
|
+
branch["_"] ??= visitScope;
|
|
895
|
+
branch[EndNode] = branch[StartNode] = startVisit;
|
|
896
|
+
if (visitType === "'") branch[getDebugKey(0, startVisit)] = startVisit;
|
|
897
|
+
} else {
|
|
898
|
+
curBranchScopes = push(curBranchScopes, branch);
|
|
899
|
+
if (accessor) {
|
|
900
|
+
visitScope[accessor] = curBranchScopes;
|
|
901
|
+
forEach(curBranchScopes, (scope) => scope["_"] ??= visitScope);
|
|
902
|
+
curBranchScopes = branchScopesStack.pop();
|
|
903
|
+
}
|
|
904
|
+
startVisit = branchStarts.pop();
|
|
905
|
+
if (parent !== startVisit.parentNode) parent.prepend(startVisit);
|
|
906
|
+
branch[StartNode] = startVisit;
|
|
907
|
+
branch[EndNode] = visit.previousSibling === startVisit ? startVisit : parent.insertBefore(new Text(), visit);
|
|
908
|
+
}
|
|
909
|
+
while (i && orphanBranches[i - 1]["#Id"] > branchId) {
|
|
910
|
+
i--;
|
|
911
|
+
setParentBranch(orphanBranches.pop(), branch);
|
|
912
|
+
}
|
|
913
|
+
while (j && deferredOwners[j - 1]["#Id"] > branchId) {
|
|
914
|
+
j--;
|
|
915
|
+
const owner = deferredOwners.pop();
|
|
916
|
+
if (owner["#ClosestBranch"] !== owner) owner[ClosestBranch] = branch;
|
|
917
|
+
}
|
|
918
|
+
nextToken();
|
|
919
|
+
}
|
|
920
|
+
if (endedBranches) {
|
|
921
|
+
for (const ended of endedBranches) orphanBranches.push(ended);
|
|
922
|
+
if (singleNode) visitScope[accessor] = endedBranches.length > 1 ? endedBranches.reverse() : endedBranches[0];
|
|
923
|
+
}
|
|
924
|
+
if (visitType === "[") {
|
|
925
|
+
if (!endedBranches) {
|
|
926
|
+
branchScopesStack.push(curBranchScopes);
|
|
927
|
+
curBranchScopes = void 0;
|
|
928
|
+
}
|
|
929
|
+
branchStarts.push(visit);
|
|
930
|
+
} else deferredOwners.push(visitScope);
|
|
931
|
+
};
|
|
932
|
+
};
|
|
933
|
+
const nextToken = () => lastToken = visitText.slice(lastTokenIndex, (lastTokenIndex = visitText.indexOf(" ", lastTokenIndex) + 1 || visitText.length + 1) - 1);
|
|
934
|
+
const processResumes = (resumes = [], effects) => {
|
|
935
|
+
let i = 0;
|
|
936
|
+
for (; i < resumes.length; i++) {
|
|
937
|
+
const serialized = resumes[i];
|
|
938
|
+
if (typeof serialized === "string") {
|
|
939
|
+
lastTokenIndex = 0;
|
|
940
|
+
visitText = serialized;
|
|
941
|
+
while (nextToken()) if (/\D/.test(lastToken)) lastEffect = registeredValues[lastToken];
|
|
942
|
+
else effects.push(lastEffect, getScope(lastToken));
|
|
943
|
+
} else if (Array.isArray(serialized)) {
|
|
944
|
+
if (!(readyIds && serialized.every((dep) => readyIds.has(dep) && !render.b[dep].length))) break;
|
|
945
|
+
} else if (readyIds && typeof serialized === "number") break;
|
|
946
|
+
else {
|
|
947
|
+
const scopes = serialized(serializeContext);
|
|
948
|
+
if (Array.isArray(scopes)) applyScopes(scopes);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
resumes.splice(0, i);
|
|
952
|
+
return i;
|
|
953
|
+
};
|
|
954
|
+
let lastEffect;
|
|
955
|
+
let visits;
|
|
956
|
+
let visit;
|
|
957
|
+
let visitText;
|
|
958
|
+
let visitType;
|
|
959
|
+
let visitScope;
|
|
960
|
+
let lastToken;
|
|
961
|
+
let lastTokenIndex;
|
|
962
|
+
let visitBranches;
|
|
963
|
+
let embedAnchor;
|
|
964
|
+
serializeContext._ = registeredValues;
|
|
965
|
+
if (render.m) throw new Error(`Marko rendered multiple times with $global.runtimeId as ${JSON.stringify(runtimeId)} and $global.renderId as ${JSON.stringify(renderId)}. Ensure each render into a page has a unique $global.renderId.`);
|
|
966
|
+
render.m = (effects) => {
|
|
967
|
+
processResumes(render.r, effects);
|
|
968
|
+
if (readyIds && render.b) for (let progress = 1; progress;) {
|
|
969
|
+
progress = 0;
|
|
970
|
+
for (const readyId of readyIds) {
|
|
971
|
+
const resumes = render.b[readyId];
|
|
972
|
+
if (resumes && processResumes(resumes, effects)) progress = 1;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
let retained = 0;
|
|
976
|
+
for (visit of visits = render.v) {
|
|
977
|
+
lastTokenIndex = render.i.length;
|
|
978
|
+
visitText = visit.data;
|
|
979
|
+
visitType = visitText[lastTokenIndex++];
|
|
980
|
+
visitScope = getScope(nextToken());
|
|
981
|
+
if (visitType === "*") {
|
|
982
|
+
const prev = visit.previousSibling;
|
|
983
|
+
visitScope[nextToken()] = prev && (prev.nodeType < 8 || prev.data) ? prev : visit.parentNode.insertBefore(new Text(), visit);
|
|
984
|
+
} else if (branchesEnabled) (visitBranches ||= createVisitBranches())();
|
|
985
|
+
else if (render.b) visits[retained++] = visit;
|
|
986
|
+
}
|
|
987
|
+
if (embedRenders && !embedAnchor && visit) embedRenders.set(embedAnchor = visit.parentNode.insertBefore(new Text(), visit.nextSibling), [renderId, scopeLookup]);
|
|
988
|
+
visits.length = retained;
|
|
989
|
+
return effects;
|
|
990
|
+
};
|
|
991
|
+
render.w = () => {
|
|
992
|
+
walk();
|
|
993
|
+
runResumeEffects(render);
|
|
994
|
+
};
|
|
995
|
+
return render;
|
|
996
|
+
}) });
|
|
997
|
+
};
|
|
998
|
+
if (renders) {
|
|
999
|
+
initRuntime(renders);
|
|
1000
|
+
for (const renderId in renders) runResumeEffects(curRenders(renderId));
|
|
1001
|
+
} else defineRuntime({
|
|
1002
|
+
configurable: true,
|
|
1003
|
+
set: initRuntime
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
let isResuming;
|
|
1007
|
+
function runResumeEffects(render) {
|
|
1008
|
+
try {
|
|
1009
|
+
isResuming = 1;
|
|
1010
|
+
runEffects(render.m([]), 1);
|
|
1011
|
+
} finally {
|
|
1012
|
+
isResuming = 0;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
function getRegisteredWithScope(id, scope) {
|
|
1016
|
+
const val = registeredValues[id];
|
|
1017
|
+
return scope ? val(scope) : val;
|
|
1018
|
+
}
|
|
1019
|
+
function _resume(id, obj) {
|
|
1020
|
+
return registeredValues[id] = obj;
|
|
1021
|
+
}
|
|
1022
|
+
function _var_resume(id, signal) {
|
|
1023
|
+
_resume(id, (scope) => (value) => signal(scope, value));
|
|
1024
|
+
return signal;
|
|
1025
|
+
}
|
|
1026
|
+
function _el(id, accessor) {
|
|
1027
|
+
return _resume(id, (scope) => () => _el_read(scope[accessor]));
|
|
1028
|
+
}
|
|
1029
|
+
//#endregion
|
|
1030
|
+
//#region src/dom/renderer.ts
|
|
1031
|
+
function createBranch($global, renderer, parentScope, parentNode) {
|
|
1032
|
+
const branch = createScope($global);
|
|
1033
|
+
branch["_"] = renderer["owner"] || parentScope;
|
|
1034
|
+
setParentBranch(branch, parentScope?.[ClosestBranch]);
|
|
1035
|
+
branch[Renderer] = renderer;
|
|
1036
|
+
renderer[Clone]?.(branch, parentNode.namespaceURI);
|
|
1037
|
+
return branch;
|
|
1038
|
+
}
|
|
1039
|
+
function setParentBranch(branch, parentBranch) {
|
|
1040
|
+
if (parentBranch) {
|
|
1041
|
+
branch[ParentBranch] = parentBranch;
|
|
1042
|
+
(parentBranch[BranchScopes] ||= /* @__PURE__ */ new Set()).add(branch);
|
|
1043
|
+
}
|
|
1044
|
+
branch[ClosestBranch] = branch;
|
|
1045
|
+
}
|
|
1046
|
+
function createAndSetupBranch($global, renderer, parentScope, parentNode) {
|
|
1047
|
+
return setupBranch(renderer, createBranch($global, renderer, parentScope, parentNode));
|
|
1048
|
+
}
|
|
1049
|
+
function setupBranch(renderer, branch) {
|
|
1050
|
+
if (renderer["setup"]) queueRender(branch, renderer[Setup], -1);
|
|
1051
|
+
return branch;
|
|
1052
|
+
}
|
|
1053
|
+
function _content(id, template, walks, setup, params, dynamicScopesAccessor) {
|
|
1054
|
+
walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
|
|
1055
|
+
setup = setup ? setup._ || setup : void 0;
|
|
1056
|
+
params ||= void 0;
|
|
1057
|
+
const clone = template ? (branch, ns) => {
|
|
1058
|
+
((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(template, ns))(branch, walks);
|
|
1059
|
+
} : (branch) => {
|
|
1060
|
+
walk(branch[StartNode] = branch[EndNode] = new Text(), walks, branch);
|
|
1061
|
+
};
|
|
1062
|
+
return (owner) => {
|
|
1063
|
+
return {
|
|
1064
|
+
["id"]: id,
|
|
1065
|
+
[Clone]: clone,
|
|
1066
|
+
[Owner]: owner,
|
|
1067
|
+
[Setup]: setup,
|
|
1068
|
+
[Params]: params,
|
|
1069
|
+
[Accessor]: dynamicScopesAccessor
|
|
1070
|
+
};
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
function _content_resume(id, template, walks, setup, params, dynamicScopesAccessor) {
|
|
1074
|
+
return _resume(id, _content(id, template, walks, setup, params, dynamicScopesAccessor));
|
|
1075
|
+
}
|
|
1076
|
+
function _content_closures(renderer, closureFns) {
|
|
1077
|
+
const closureSignals = {};
|
|
1078
|
+
for (const key in closureFns) closureSignals[key] = _const(key, closureFns[key]);
|
|
1079
|
+
return (owner, closureValues) => {
|
|
1080
|
+
const instance = renderer(owner);
|
|
1081
|
+
instance[LocalClosures] = closureSignals;
|
|
1082
|
+
instance[LocalClosureValues] = closureValues;
|
|
1083
|
+
return instance;
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
const cloneCache = {};
|
|
1087
|
+
function createCloneableHTML(html, ns) {
|
|
1088
|
+
const { firstChild, lastChild } = parseHTML(html, ns);
|
|
1089
|
+
const parent = document.createElementNS(ns, "t");
|
|
1090
|
+
insertChildNodes(parent, null, firstChild, lastChild);
|
|
1091
|
+
return firstChild === lastChild && firstChild.nodeType < 8 ? (branch, walks) => {
|
|
1092
|
+
walk(branch[StartNode] = branch[EndNode] = firstChild.cloneNode(true), walks, branch);
|
|
1093
|
+
} : (branch, walks) => {
|
|
1094
|
+
const clone = parent.cloneNode(true);
|
|
1095
|
+
walk(clone.firstChild, walks, branch);
|
|
1096
|
+
branch[StartNode] = clone.firstChild;
|
|
1097
|
+
branch[EndNode] = clone.lastChild;
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
//#endregion
|
|
1101
|
+
//#region src/dom/dom.ts
|
|
1102
|
+
function _to_text(value) {
|
|
1103
|
+
assertValidTextValue(value);
|
|
1104
|
+
return value || value === 0 ? value + "" : "";
|
|
1105
|
+
}
|
|
1106
|
+
function _attr(element, name, value) {
|
|
1107
|
+
assertValidAttrValue(name, value);
|
|
1108
|
+
setAttribute(element, name, normalizeAttrValue(value));
|
|
1109
|
+
}
|
|
1110
|
+
function setAttribute(element, name, value) {
|
|
1111
|
+
if (element.getAttribute(name) != value) if (value === void 0) element.removeAttribute(name);
|
|
1112
|
+
else element.setAttribute(name, value);
|
|
1113
|
+
}
|
|
1114
|
+
function _attr_class(element, value) {
|
|
1115
|
+
setAttribute(element, "class", toDelimitedString(value, " ", stringifyClassObject) || void 0);
|
|
1116
|
+
}
|
|
1117
|
+
function _attr_class_items(element, items) {
|
|
1118
|
+
for (const key in items) _attr_class_item(element, key, items[key]);
|
|
1119
|
+
}
|
|
1120
|
+
function _attr_class_item(element, name, value) {
|
|
1121
|
+
element.classList.toggle(name, !!value);
|
|
1122
|
+
}
|
|
1123
|
+
function _attr_style(element, value) {
|
|
1124
|
+
setAttribute(element, "style", toDelimitedString(value, ";", stringifyStyleObject) || void 0);
|
|
1125
|
+
}
|
|
1126
|
+
function _attr_style_items(element, items) {
|
|
1127
|
+
for (const key in items) _attr_style_item(element, key, items[key]);
|
|
1128
|
+
}
|
|
1129
|
+
function _attr_style_item(element, name, value) {
|
|
1130
|
+
element.style.setProperty(name, _to_text(value));
|
|
1131
|
+
}
|
|
1132
|
+
function _style_shell(scope, nodeAccessor) {
|
|
1133
|
+
const element = scope[nodeAccessor];
|
|
1134
|
+
const id = _id(scope);
|
|
1135
|
+
_attr_nonce(scope, nodeAccessor);
|
|
1136
|
+
element.className = id;
|
|
1137
|
+
_text_content(element, "." + id + "~*{}");
|
|
1138
|
+
}
|
|
1139
|
+
function _style_rule_item(element, name, value) {
|
|
1140
|
+
const text = element.textContent;
|
|
1141
|
+
const decl = name + ":" + escapeStyleValue(_to_text(value)) + ";";
|
|
1142
|
+
let start = text.indexOf("{" + name + ":");
|
|
1143
|
+
if (!~start) start = text.indexOf(";" + name + ":");
|
|
1144
|
+
_text_content(element, ~start ? text.slice(0, ++start) + decl + text.slice(text.indexOf(";", start) + 1) : text.slice(0, -1) + decl + "}");
|
|
1145
|
+
}
|
|
1146
|
+
function _attr_nonce(scope, nodeAccessor) {
|
|
1147
|
+
_attr(scope[nodeAccessor], "nonce", scope[Global].cspNonce);
|
|
1148
|
+
}
|
|
1149
|
+
function _text(node, value) {
|
|
1150
|
+
const normalizedValue = _to_text(value);
|
|
1151
|
+
if (node.data !== normalizedValue) node.data = normalizedValue;
|
|
1152
|
+
}
|
|
1153
|
+
function _text_content(node, value) {
|
|
1154
|
+
const normalizedValue = _to_text(value);
|
|
1155
|
+
if (node.textContent !== normalizedValue) node.textContent = normalizedValue;
|
|
1156
|
+
}
|
|
1157
|
+
function _attrs(scope, nodeAccessor, nextAttrs, controllable) {
|
|
1158
|
+
const el = scope[nodeAccessor];
|
|
1159
|
+
for (let i = el.attributes.length; i--;) {
|
|
1160
|
+
const { name } = el.attributes.item(i);
|
|
1161
|
+
if (!(nextAttrs && (name in nextAttrs || hasAttrAlias(el, name, nextAttrs)))) el.removeAttribute(name);
|
|
1162
|
+
}
|
|
1163
|
+
assertExclusiveAttrs(nextAttrs);
|
|
1164
|
+
attrsInternal(scope, nodeAccessor, nextAttrs, controllable);
|
|
1165
|
+
}
|
|
1166
|
+
function _attrs_content(scope, nodeAccessor, nextAttrs, controllable) {
|
|
1167
|
+
_attrs(scope, nodeAccessor, nextAttrs, controllable);
|
|
1168
|
+
_attr_content(scope, nodeAccessor, nextAttrs?.content);
|
|
1169
|
+
}
|
|
1170
|
+
function hasAttrAlias(element, attr, nextAttrs) {
|
|
1171
|
+
return attr === "checked" && element.tagName === "INPUT" && "checkedValue" in nextAttrs;
|
|
1172
|
+
}
|
|
1173
|
+
function _attrs_partial(scope, nodeAccessor, nextAttrs, skip, controllable) {
|
|
1174
|
+
const el = scope[nodeAccessor];
|
|
1175
|
+
const partial = {};
|
|
1176
|
+
for (let i = el.attributes.length; i--;) {
|
|
1177
|
+
const { name } = el.attributes.item(i);
|
|
1178
|
+
if (!skip[name] && !(nextAttrs && name in nextAttrs)) el.removeAttribute(name);
|
|
1179
|
+
}
|
|
1180
|
+
for (const name in nextAttrs) {
|
|
1181
|
+
const key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
|
|
1182
|
+
if (!skip[key]) partial[key] = nextAttrs[name];
|
|
1183
|
+
}
|
|
1184
|
+
assertExclusiveAttrs({
|
|
1185
|
+
...nextAttrs,
|
|
1186
|
+
...skip
|
|
1187
|
+
});
|
|
1188
|
+
attrsInternal(scope, nodeAccessor, partial, controllable);
|
|
1189
|
+
}
|
|
1190
|
+
function _attrs_partial_content(scope, nodeAccessor, nextAttrs, skip, controllable) {
|
|
1191
|
+
_attrs_partial(scope, nodeAccessor, nextAttrs, skip, controllable);
|
|
1192
|
+
_attr_content(scope, nodeAccessor, nextAttrs?.content);
|
|
1193
|
+
}
|
|
1194
|
+
function attrsInternal(scope, nodeAccessor, nextAttrs, controllable) {
|
|
1195
|
+
const el = scope[nodeAccessor];
|
|
1196
|
+
let events = scope[EventAttributes + nodeAccessor];
|
|
1197
|
+
let skip = void 0;
|
|
1198
|
+
for (const name in events) events[name] = 0;
|
|
1199
|
+
if (controllable) {
|
|
1200
|
+
scope[ControlledType + nodeAccessor] = 5;
|
|
1201
|
+
scope[ControlledHandler + nodeAccessor] = 0;
|
|
1202
|
+
if (nextAttrs) skip = controllable(scope, nodeAccessor, nextAttrs);
|
|
1203
|
+
}
|
|
1204
|
+
for (const name in nextAttrs) {
|
|
1205
|
+
const value = nextAttrs[name];
|
|
1206
|
+
switch (name) {
|
|
1207
|
+
case "class":
|
|
1208
|
+
_attr_class(el, value);
|
|
1209
|
+
break;
|
|
1210
|
+
case "style":
|
|
1211
|
+
_attr_style(el, value);
|
|
1212
|
+
break;
|
|
1213
|
+
default:
|
|
1214
|
+
assertValidAttrName(name);
|
|
1215
|
+
if (isEventHandler(name)) (events ||= scope[EventAttributes + nodeAccessor] = {})[getEventHandlerName(name)] = value;
|
|
1216
|
+
else if (!(skip?.test(name) || name === "content" && el.tagName !== "META")) _attr(el, name, value);
|
|
1217
|
+
break;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
function _attr_content(scope, nodeAccessor, value) {
|
|
1222
|
+
const content = normalizeClientRender(value);
|
|
1223
|
+
if (scope["ConditionalRenderer:" + nodeAccessor] !== (scope["ConditionalRenderer:" + nodeAccessor] = content?.["id"])) {
|
|
1224
|
+
setConditionalRenderer(scope, nodeAccessor, content, createAndSetupBranch);
|
|
1225
|
+
if (content?.["accessor"]) subscribeToScopeSet(content[Owner], content[Accessor], scope[BranchScopes$1 + nodeAccessor]);
|
|
1226
|
+
}
|
|
1227
|
+
for (const accessor in content?.[LocalClosures]) content[LocalClosures][accessor](scope[BranchScopes$1 + nodeAccessor], content[LocalClosureValues][accessor]);
|
|
1228
|
+
}
|
|
1229
|
+
function _attrs_script(scope, nodeAccessor) {
|
|
1230
|
+
const el = scope[nodeAccessor];
|
|
1231
|
+
const events = scope[EventAttributes + nodeAccessor];
|
|
1232
|
+
controllableScripts[scope[ControlledType + nodeAccessor]]?.(scope, nodeAccessor);
|
|
1233
|
+
for (const name in events) _on(el, name, events[name]);
|
|
1234
|
+
}
|
|
1235
|
+
function _html(scope, value, accessor) {
|
|
1236
|
+
const firstChild = scope[accessor];
|
|
1237
|
+
const parentNode = firstChild.parentNode;
|
|
1238
|
+
const lastChild = scope["DynamicHTMLLastChild:" + accessor] || firstChild;
|
|
1239
|
+
const newContent = parseHTML(_to_text(value), parentNode.namespaceURI);
|
|
1240
|
+
insertChildNodes(parentNode, firstChild, scope[accessor] = newContent.firstChild || newContent.appendChild(new Text()), scope[DynamicHTMLLastChild + accessor] = newContent.lastChild);
|
|
1241
|
+
removeChildNodes(firstChild, lastChild);
|
|
1242
|
+
}
|
|
1243
|
+
function normalizeClientRender(value) {
|
|
1244
|
+
const renderer = normalizeDynamicRenderer(value);
|
|
1245
|
+
if (renderer) if (renderer["id"]) return renderer;
|
|
1246
|
+
else throw new Error(`Invalid \`content\` attribute. Received ${typeof value}`);
|
|
1247
|
+
}
|
|
1248
|
+
function normalizeAttrValue(value) {
|
|
1249
|
+
if (isNotVoid(value)) return value === true ? "" : value + "";
|
|
1250
|
+
}
|
|
1251
|
+
function _lifecycle(scope, thisObj, index = 0) {
|
|
1252
|
+
const accessor = Lifecycle + index;
|
|
1253
|
+
const instance = scope[accessor];
|
|
1254
|
+
if (instance) {
|
|
1255
|
+
Object.assign(instance, thisObj);
|
|
1256
|
+
instance.onUpdate?.();
|
|
1257
|
+
} else {
|
|
1258
|
+
scope[accessor] = thisObj;
|
|
1259
|
+
{
|
|
1260
|
+
const snapshot = { ...thisObj };
|
|
1261
|
+
Object.assign(thisObj, thisObj.onMount?.());
|
|
1262
|
+
for (const prop in snapshot) if (!Object.is(snapshot[prop], thisObj[prop])) throw new Error(`Tried to overwrite existing property "${prop}" in <lifecycle> onMount.`);
|
|
1263
|
+
}
|
|
1264
|
+
$signal(scope, accessor).onabort = () => thisObj.onDestroy?.();
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
function removeChildNodes(startNode, endNode) {
|
|
1268
|
+
const stop = endNode.nextSibling;
|
|
1269
|
+
while (startNode !== stop) {
|
|
1270
|
+
const next = startNode.nextSibling;
|
|
1271
|
+
startNode.remove();
|
|
1272
|
+
startNode = next;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
function insertChildNodes(parentNode, referenceNode, startNode, endNode) {
|
|
1276
|
+
if (parentNode.isConnected) parentNode.insertBefore(toInsertNode(startNode, endNode), referenceNode);
|
|
1277
|
+
else {
|
|
1278
|
+
const stop = endNode.nextSibling;
|
|
1279
|
+
while (startNode !== stop) {
|
|
1280
|
+
const next = startNode.nextSibling;
|
|
1281
|
+
parentNode.insertBefore(startNode, referenceNode);
|
|
1282
|
+
startNode = next;
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
return parentNode;
|
|
1286
|
+
}
|
|
1287
|
+
function toInsertNode(startNode, endNode) {
|
|
1288
|
+
return startNode === endNode ? startNode : insertChildNodes(new DocumentFragment(), null, startNode, endNode);
|
|
1289
|
+
}
|
|
1290
|
+
//#endregion
|
|
1291
|
+
//#region src/dom/resolve-cursor-position.ts
|
|
1292
|
+
const R = /[^\p{L}\p{N}]/gu;
|
|
1293
|
+
function resolveCursorPosition(inputType, initialPosition, initialValue, updatedValue) {
|
|
1294
|
+
if ((initialPosition || initialPosition === 0) && (initialPosition !== initialValue.length || /kw/.test(inputType))) {
|
|
1295
|
+
const before = initialValue.slice(0, initialPosition);
|
|
1296
|
+
const after = initialValue.slice(initialPosition);
|
|
1297
|
+
if (updatedValue.startsWith(before)) return initialPosition;
|
|
1298
|
+
if (updatedValue.endsWith(after)) return updatedValue.length - after.length;
|
|
1299
|
+
let count = before.replace(R, "").length;
|
|
1300
|
+
let pos = 0;
|
|
1301
|
+
while (count && updatedValue[pos]) if (updatedValue[pos++].replace(R, "")) count--;
|
|
1302
|
+
return pos;
|
|
1303
|
+
}
|
|
1304
|
+
return -1;
|
|
1305
|
+
}
|
|
1306
|
+
//#endregion
|
|
1307
|
+
//#region src/dom/controllable.ts
|
|
1308
|
+
let inputType = "";
|
|
1309
|
+
function _attr_input_checked_default(scope, nodeAccessor, checked) {
|
|
1310
|
+
const el = scope[nodeAccessor];
|
|
1311
|
+
const normalizedChecked = isNotVoid(checked);
|
|
1312
|
+
if (el.defaultChecked !== normalizedChecked) {
|
|
1313
|
+
const restoreValue = scope["#Gen"] < runId ? el.checked : normalizedChecked;
|
|
1314
|
+
el.defaultChecked = normalizedChecked;
|
|
1315
|
+
if (restoreValue !== normalizedChecked) el.checked = restoreValue;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
/** Filled by the `controllable-*.feat` modules a compiled page imports, so a
|
|
1319
|
+
* page carries only the control kinds its tags can be (`_attrs_script`
|
|
1320
|
+
* resolves the kind at run time). */
|
|
1321
|
+
const controllableScripts = {};
|
|
1322
|
+
/** The render pass equivalent, for a tag whose name is only known at run time;
|
|
1323
|
+
* a statically named tag passes its claim to `_attrs` instead. */
|
|
1324
|
+
const controllableRenders = {};
|
|
1325
|
+
function _attr_input_checked(scope, nodeAccessor, checked, checkedChange) {
|
|
1326
|
+
const el = scope[nodeAccessor];
|
|
1327
|
+
const normalizedChecked = isNotVoid(checked);
|
|
1328
|
+
assertHandlerIsFunction("checkedChange", checkedChange);
|
|
1329
|
+
scope[ControlledHandler + nodeAccessor] = checkedChange;
|
|
1330
|
+
scope[ControlledType + nodeAccessor] = checkedChange ? 0 : 5;
|
|
1331
|
+
if (checkedChange && scope["#Gen"] < runId) el.checked = normalizedChecked;
|
|
1332
|
+
else _attr_input_checked_default(scope, nodeAccessor, normalizedChecked);
|
|
1333
|
+
}
|
|
1334
|
+
function _attr_input_checked_script(scope, nodeAccessor) {
|
|
1335
|
+
const el = scope[nodeAccessor];
|
|
1336
|
+
syncControllableFormInput(el, hasCheckboxChanged, () => {
|
|
1337
|
+
const checkedChange = scope[ControlledHandler + nodeAccessor];
|
|
1338
|
+
if (checkedChange) {
|
|
1339
|
+
const newValue = el.checked;
|
|
1340
|
+
el.checked = !newValue;
|
|
1341
|
+
checkedChange(newValue);
|
|
1342
|
+
run();
|
|
1343
|
+
}
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
function _attr_input_checkedValue_default(scope, nodeAccessor, checkedValue, value) {
|
|
1347
|
+
const multiple = Array.isArray(checkedValue);
|
|
1348
|
+
const normalizedValue = normalizeStrProp(value);
|
|
1349
|
+
const normalizedCheckedValue = multiple ? checkedValue.map(normalizeStrProp) : normalizeStrProp(checkedValue);
|
|
1350
|
+
_attr(scope[nodeAccessor], "value", value);
|
|
1351
|
+
_attr_input_checked_default(scope, nodeAccessor, multiple ? normalizedCheckedValue.includes(normalizedValue) : normalizedValue === normalizedCheckedValue);
|
|
1352
|
+
}
|
|
1353
|
+
function _attr_input_checkedValue(scope, nodeAccessor, checkedValue, checkedValueChange, value) {
|
|
1354
|
+
const el = scope[nodeAccessor];
|
|
1355
|
+
const multiple = Array.isArray(checkedValue);
|
|
1356
|
+
const normalizedCheckedValue = scope[ControlledValue + nodeAccessor] = multiple ? checkedValue.map(normalizeStrProp) : normalizeStrProp(checkedValue);
|
|
1357
|
+
assertHandlerIsFunction("checkedValueChange", checkedValueChange);
|
|
1358
|
+
scope[ControlledHandler + nodeAccessor] = checkedValueChange;
|
|
1359
|
+
scope[ControlledType + nodeAccessor] = checkedValueChange ? 1 : 5;
|
|
1360
|
+
if (checkedValueChange && scope["#Gen"] < runId) {
|
|
1361
|
+
el.checked = multiple ? normalizedCheckedValue.includes(normalizeStrProp(value)) : normalizeStrProp(value) === normalizedCheckedValue;
|
|
1362
|
+
_attr(el, "value", value);
|
|
1363
|
+
} else _attr_input_checkedValue_default(scope, nodeAccessor, checkedValue, value);
|
|
1364
|
+
}
|
|
1365
|
+
function _attr_input_checkedValue_script(scope, nodeAccessor) {
|
|
1366
|
+
const el = scope[nodeAccessor];
|
|
1367
|
+
if (isResuming && el.defaultChecked) if (scope["ControlledValue:" + nodeAccessor]) scope[ControlledValue + nodeAccessor].push(el.value);
|
|
1368
|
+
else scope[ControlledValue + nodeAccessor] = el.value;
|
|
1369
|
+
syncControllableFormInput(el, hasCheckboxChanged, () => {
|
|
1370
|
+
const checkedValueChange = scope[ControlledHandler + nodeAccessor];
|
|
1371
|
+
if (checkedValueChange) {
|
|
1372
|
+
const controlledValueKey = ControlledValue + nodeAccessor;
|
|
1373
|
+
const oldValue = scope[controlledValueKey];
|
|
1374
|
+
let newValue = Array.isArray(oldValue) ? updateList(oldValue, el.value, el.checked) : el.checked ? el.value : void 0;
|
|
1375
|
+
if (el.name && el.type[0] === "r") {
|
|
1376
|
+
for (const radio of document.querySelectorAll(`[type=radio][name=${CSS.escape(el.name)}]`)) if (radio.form === el.form) {
|
|
1377
|
+
if (newValue === void 0 && radio.defaultChecked) newValue = radio.value;
|
|
1378
|
+
radio.checked = Array.isArray(oldValue) ? oldValue.includes(radio.value) : controlledValueKey in scope ? oldValue === radio.value : radio.defaultChecked;
|
|
1379
|
+
}
|
|
1380
|
+
} else el.checked = !el.checked;
|
|
1381
|
+
checkedValueChange(newValue);
|
|
1382
|
+
run();
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
function _attr_input_value_default(scope, nodeAccessor, value) {
|
|
1387
|
+
const el = scope[nodeAccessor];
|
|
1388
|
+
const normalizedValue = normalizeAttrValue(value) || "";
|
|
1389
|
+
if (el.defaultValue !== normalizedValue) {
|
|
1390
|
+
const restoreValue = scope["#Gen"] < runId ? el.value : normalizedValue;
|
|
1391
|
+
el.defaultValue = normalizedValue;
|
|
1392
|
+
setInputValue(el, restoreValue);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
function _attr_input_value_dynamic_default(scope, nodeAccessor, value) {
|
|
1396
|
+
const el = scope[nodeAccessor];
|
|
1397
|
+
if (/i[ot]|e[cns]|^[bi]/.test(el.type)) _attr(el, "value", value);
|
|
1398
|
+
else _attr_input_value_default(scope, nodeAccessor, value);
|
|
1399
|
+
}
|
|
1400
|
+
function _attr_input_value(scope, nodeAccessor, value, valueChange, setDefault = _attr_input_value_default) {
|
|
1401
|
+
const el = scope[nodeAccessor];
|
|
1402
|
+
const normalizedValue = normalizeAttrValue(value) || "";
|
|
1403
|
+
assertHandlerIsFunction("valueChange", valueChange);
|
|
1404
|
+
scope[ControlledHandler + nodeAccessor] = valueChange;
|
|
1405
|
+
scope[ControlledValue + nodeAccessor] = normalizedValue;
|
|
1406
|
+
scope[ControlledType + nodeAccessor] = valueChange ? 2 : 5;
|
|
1407
|
+
if (valueChange && scope["#Gen"] < runId) setInputValue(el, normalizedValue);
|
|
1408
|
+
else setDefault(scope, nodeAccessor, normalizedValue);
|
|
1409
|
+
}
|
|
1410
|
+
function _attr_input_value_attribute_default(scope, nodeAccessor, value) {
|
|
1411
|
+
_attr(scope[nodeAccessor], "value", value);
|
|
1412
|
+
}
|
|
1413
|
+
function _attr_input_value_script(scope, nodeAccessor) {
|
|
1414
|
+
const el = scope[nodeAccessor];
|
|
1415
|
+
if (isResuming) scope[ControlledValue + nodeAccessor] = el.defaultValue;
|
|
1416
|
+
syncControllableFormInput(el, hasValueChanged, (ev) => {
|
|
1417
|
+
const valueChange = scope[ControlledHandler + nodeAccessor];
|
|
1418
|
+
if (valueChange) {
|
|
1419
|
+
inputType = ev?.inputType;
|
|
1420
|
+
valueChange(el.value);
|
|
1421
|
+
run();
|
|
1422
|
+
setInputValue(el, scope[ControlledValue + nodeAccessor]);
|
|
1423
|
+
inputType = "";
|
|
1424
|
+
}
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
function setInputValue(el, value) {
|
|
1428
|
+
if (el.value !== value) {
|
|
1429
|
+
const updatedPosition = resolveCursorPosition(inputType, document.activeElement === el && el.selectionStart, el.value, el.value = value);
|
|
1430
|
+
if (~updatedPosition) el.setSelectionRange(updatedPosition, updatedPosition);
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
function _attr_select_value_default(scope, nodeAccessor, value) {
|
|
1434
|
+
let restoreValue;
|
|
1435
|
+
const el = scope[nodeAccessor];
|
|
1436
|
+
const live = scope[Gen$1] < runId;
|
|
1437
|
+
const multiple = Array.isArray(value);
|
|
1438
|
+
const normalizedValue = multiple ? value.map(normalizeStrProp) : normalizeStrProp(value);
|
|
1439
|
+
pendingEffects.unshift(() => {
|
|
1440
|
+
for (const opt of el.options) {
|
|
1441
|
+
const selected = multiple ? normalizedValue.includes(opt.value) : opt.value === normalizedValue;
|
|
1442
|
+
if (opt.defaultSelected !== selected) {
|
|
1443
|
+
if (live) restoreValue ??= getSelectValue(el, multiple);
|
|
1444
|
+
opt.defaultSelected = selected;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
if (restoreValue !== void 0) setSelectValue(el, restoreValue, multiple);
|
|
1448
|
+
}, scope);
|
|
1449
|
+
}
|
|
1450
|
+
function _attr_select_value(scope, nodeAccessor, value, valueChange) {
|
|
1451
|
+
const el = scope[nodeAccessor];
|
|
1452
|
+
const existing = scope[Gen$1] < runId;
|
|
1453
|
+
const multiple = Array.isArray(value);
|
|
1454
|
+
const normalizedValue = scope[ControlledValue + nodeAccessor] = multiple ? value.map(normalizeStrProp) : normalizeStrProp(value);
|
|
1455
|
+
assertHandlerIsFunction("valueChange", valueChange);
|
|
1456
|
+
scope[ControlledHandler + nodeAccessor] = valueChange;
|
|
1457
|
+
scope[ControlledType + nodeAccessor] = valueChange ? 3 : 5;
|
|
1458
|
+
if (valueChange) pendingEffects.unshift(() => assertSelectValueMatchesOption(el, normalizedValue, value), scope);
|
|
1459
|
+
if (valueChange && existing) pendingEffects.unshift(() => setSelectValue(el, normalizedValue, multiple), scope);
|
|
1460
|
+
else _attr_select_value_default(scope, nodeAccessor, normalizedValue);
|
|
1461
|
+
}
|
|
1462
|
+
function _attr_select_value_script(scope, nodeAccessor) {
|
|
1463
|
+
const el = scope[nodeAccessor];
|
|
1464
|
+
const onChange = () => {
|
|
1465
|
+
const valueChange = scope[ControlledHandler + nodeAccessor];
|
|
1466
|
+
if (valueChange) {
|
|
1467
|
+
const oldValue = scope[ControlledValue + nodeAccessor];
|
|
1468
|
+
const multiple = Array.isArray(oldValue);
|
|
1469
|
+
const newValue = getSelectValue(el, multiple);
|
|
1470
|
+
setSelectValue(el, oldValue, multiple);
|
|
1471
|
+
valueChange(newValue);
|
|
1472
|
+
run();
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
if (isResuming) if (el.multiple) {
|
|
1476
|
+
scope[ControlledValue + nodeAccessor] = [];
|
|
1477
|
+
for (const opt of el.options) if (opt.defaultSelected) scope[ControlledValue + nodeAccessor].push(opt.value);
|
|
1478
|
+
} else {
|
|
1479
|
+
scope[ControlledValue + nodeAccessor] = "";
|
|
1480
|
+
for (const opt of el.options) if (opt.defaultSelected) {
|
|
1481
|
+
scope[ControlledValue + nodeAccessor] = opt.value;
|
|
1482
|
+
break;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
syncControllableFormInput(el, hasSelectChanged, onChange);
|
|
1486
|
+
observeOnce(scope, nodeAccessor, {
|
|
1487
|
+
childList: true,
|
|
1488
|
+
subtree: true
|
|
1489
|
+
}, () => {
|
|
1490
|
+
const value = scope[ControlledValue + nodeAccessor];
|
|
1491
|
+
if (Array.isArray(value) ? value.length !== el.selectedOptions.length || value.some((_, i) => !value.includes(el.selectedOptions[i].value)) : el.value !== value) onChange();
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
function setSelectValue(el, value, multiple) {
|
|
1495
|
+
if (multiple) for (const opt of el.options) opt.selected = value.includes(opt.value);
|
|
1496
|
+
else el.value = value;
|
|
1497
|
+
}
|
|
1498
|
+
function getSelectValue(el, multiple) {
|
|
1499
|
+
return multiple ? Array.from(el.selectedOptions, (opt) => opt.value) : el.value;
|
|
1500
|
+
}
|
|
1501
|
+
function assertSelectValueMatchesOption(el, normalizedValue, value) {
|
|
1502
|
+
const multiple = Array.isArray(normalizedValue);
|
|
1503
|
+
if (multiple ? normalizedValue.some(Boolean) : normalizedValue) {
|
|
1504
|
+
for (const opt of el.options) if (multiple ? normalizedValue.includes(opt.value) : opt.value === normalizedValue) return;
|
|
1505
|
+
console.error("A controlled `<select>`'s `value` has no matching `<option>`:", value);
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
function _attr_details_or_dialog_open_default(scope, nodeAccessor, open) {
|
|
1509
|
+
if (scope["#Gen"] === runId) scope[nodeAccessor].open = isNotVoid(open);
|
|
1510
|
+
}
|
|
1511
|
+
function _attr_details_or_dialog_open(scope, nodeAccessor, open, openChange) {
|
|
1512
|
+
const normalizedOpen = scope[ControlledValue + nodeAccessor] = isNotVoid(open);
|
|
1513
|
+
assertHandlerIsFunction("openChange", openChange);
|
|
1514
|
+
scope[ControlledHandler + nodeAccessor] = openChange;
|
|
1515
|
+
scope[ControlledType + nodeAccessor] = openChange ? 4 : 5;
|
|
1516
|
+
if (openChange && scope["#Gen"] < runId) scope[nodeAccessor].open = normalizedOpen;
|
|
1517
|
+
else _attr_details_or_dialog_open_default(scope, nodeAccessor, normalizedOpen);
|
|
1518
|
+
}
|
|
1519
|
+
function _attr_details_or_dialog_open_script(scope, nodeAccessor) {
|
|
1520
|
+
const el = scope[nodeAccessor];
|
|
1521
|
+
observeOnce(scope, nodeAccessor, {
|
|
1522
|
+
attributes: true,
|
|
1523
|
+
attributeFilter: ["open"]
|
|
1524
|
+
}, () => {
|
|
1525
|
+
const openChange = scope[ControlledHandler + nodeAccessor];
|
|
1526
|
+
if (openChange && el.open === !scope["ControlledValue:" + nodeAccessor]) {
|
|
1527
|
+
const newValue = el.open;
|
|
1528
|
+
el.open = !newValue;
|
|
1529
|
+
openChange(newValue);
|
|
1530
|
+
run();
|
|
1531
|
+
}
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
function observeOnce(scope, nodeAccessor, init, callback) {
|
|
1535
|
+
(scope[ControlledObserver + nodeAccessor] ||= new MutationObserver(callback)).observe(scope[nodeAccessor], init);
|
|
1536
|
+
}
|
|
1537
|
+
function syncControllableFormInput(el, hasChanged, onChange) {
|
|
1538
|
+
el._ = onChange;
|
|
1539
|
+
delegate("input", handleChange);
|
|
1540
|
+
if (el.form) delegate("reset", handleFormReset);
|
|
1541
|
+
if (isResuming && hasChanged(el)) queueMicrotask(onChange);
|
|
1542
|
+
}
|
|
1543
|
+
function handleChange(ev) {
|
|
1544
|
+
ev.target._?.(ev);
|
|
1545
|
+
}
|
|
1546
|
+
function handleFormReset(ev) {
|
|
1547
|
+
const handlers = [];
|
|
1548
|
+
for (const el of ev.target.elements) if (el._ && hasFormElementChanged(el)) handlers.push(el._);
|
|
1549
|
+
requestAnimationFrame(() => {
|
|
1550
|
+
if (!ev.defaultPrevented) for (const change of handlers) change();
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
function hasValueChanged(el) {
|
|
1554
|
+
return el.value !== el.defaultValue;
|
|
1555
|
+
}
|
|
1556
|
+
function hasCheckboxChanged(el) {
|
|
1557
|
+
return el.checked !== el.defaultChecked;
|
|
1558
|
+
}
|
|
1559
|
+
function hasSelectChanged(el) {
|
|
1560
|
+
for (const opt of el.options) if (opt.selected !== opt.defaultSelected) return true;
|
|
1561
|
+
}
|
|
1562
|
+
function hasFormElementChanged(el) {
|
|
1563
|
+
return el.options ? hasSelectChanged(el) : hasValueChanged(el) || hasCheckboxChanged(el);
|
|
1564
|
+
}
|
|
1565
|
+
function normalizeStrProp(value) {
|
|
1566
|
+
return normalizeAttrValue(value) || "";
|
|
1567
|
+
}
|
|
1568
|
+
function updateList(arr, val, push) {
|
|
1569
|
+
const index = arr.indexOf(val);
|
|
1570
|
+
return (push ? !~index && [...arr, val] : ~index && arr.slice(0, index).concat(arr.slice(index + 1))) || arr;
|
|
1571
|
+
}
|
|
1572
|
+
function _controllable_input(scope, nodeAccessor, nextAttrs) {
|
|
1573
|
+
if ("checked" in nextAttrs || "checkedChange" in nextAttrs) {
|
|
1574
|
+
_attr_input_checked(scope, nodeAccessor, nextAttrs.checked, nextAttrs.checkedChange);
|
|
1575
|
+
return /^checked(?:Value)?(?:Change)?$/;
|
|
1576
|
+
}
|
|
1577
|
+
if ("checkedValue" in nextAttrs || "checkedValueChange" in nextAttrs) {
|
|
1578
|
+
_attr_input_checkedValue(scope, nodeAccessor, nextAttrs.checkedValue, nextAttrs.checkedValueChange, nextAttrs.value);
|
|
1579
|
+
return /^(?:value|checked(?:Value)?)(?:Change)?$/;
|
|
1580
|
+
}
|
|
1581
|
+
return _controllable_textarea(scope, nodeAccessor, nextAttrs, _attr_input_value_dynamic_default);
|
|
1582
|
+
}
|
|
1583
|
+
function _controllable_textarea(scope, nodeAccessor, nextAttrs, dynamicDefault) {
|
|
1584
|
+
if ("value" in nextAttrs || "valueChange" in nextAttrs) {
|
|
1585
|
+
_attr_input_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange, dynamicDefault);
|
|
1586
|
+
return /^value(?:Change)?$/;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
function _controllable_select(scope, nodeAccessor, nextAttrs) {
|
|
1590
|
+
if ("value" in nextAttrs || "valueChange" in nextAttrs) {
|
|
1591
|
+
_attr_select_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange);
|
|
1592
|
+
return /^value(?:Change)?$/;
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
function _controllable_open(scope, nodeAccessor, nextAttrs) {
|
|
1596
|
+
if ("open" in nextAttrs || "openChange" in nextAttrs) {
|
|
1597
|
+
_attr_details_or_dialog_open(scope, nodeAccessor, nextAttrs.open, nextAttrs.openChange);
|
|
1598
|
+
return /^open(?:Change)?$/;
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
//#endregion
|
|
1602
|
+
//#region src/dom/control-flow.ts
|
|
1603
|
+
function _await_promise(nodeAccessor, params) {
|
|
1604
|
+
const promiseAccessor = Promise$1 + nodeAccessor;
|
|
1605
|
+
const branchAccessor = BranchScopes$1 + nodeAccessor;
|
|
1606
|
+
const resolveAwait = (scope, referenceNode, value) => {
|
|
1607
|
+
const awaitBranch = scope[branchAccessor];
|
|
1608
|
+
if (awaitBranch["#DetachedAwait"]) {
|
|
1609
|
+
awaitBranch[PendingScopes] = awaitBranch[PendingScopes]?.forEach(syncGen);
|
|
1610
|
+
setupBranch(awaitBranch[DetachedAwait], awaitBranch);
|
|
1611
|
+
awaitBranch[DetachedAwait] = 0;
|
|
1612
|
+
insertBranchBefore(awaitBranch, scope[nodeAccessor].parentNode, scope[nodeAccessor]);
|
|
1613
|
+
referenceNode.remove();
|
|
1614
|
+
}
|
|
1615
|
+
params?.(awaitBranch, [value]);
|
|
1616
|
+
return awaitBranch;
|
|
1617
|
+
};
|
|
1618
|
+
const awaitPromise = (scope, promise) => {
|
|
1619
|
+
if (!isPromise(promise) && scope[promiseAccessor]) promise = Promise.resolve(promise);
|
|
1620
|
+
let awaitBranch = scope[branchAccessor];
|
|
1621
|
+
const tryPlaceholder = findBranchWithKey(scope, PlaceholderContent);
|
|
1622
|
+
const tryBranch = tryPlaceholder || awaitBranch;
|
|
1623
|
+
if (!(isPromise(promise) ? tryBranch : awaitBranch)) {
|
|
1624
|
+
scope[promiseAccessor] = () => awaitPromise(scope, promise);
|
|
1625
|
+
return;
|
|
1626
|
+
}
|
|
1627
|
+
if (!isPromise(promise)) {
|
|
1628
|
+
resolveAwait(scope, scope[nodeAccessor], promise);
|
|
1629
|
+
return;
|
|
1630
|
+
}
|
|
1631
|
+
let awaitCounter = tryBranch[AwaitCounter];
|
|
1632
|
+
placeholderShown.add(pendingEffects);
|
|
1633
|
+
if (!tryPlaceholder && !awaitCounter?.i) awaitCounter = createAwaitCounter(tryBranch, () => {
|
|
1634
|
+
if (tryBranch === scope[branchAccessor]) {
|
|
1635
|
+
const anchor = scope[nodeAccessor];
|
|
1636
|
+
if (anchor.parentNode) {
|
|
1637
|
+
const detachedParent = scope[branchAccessor][StartNode].parentNode;
|
|
1638
|
+
if (detachedParent === anchor.parentNode) anchor.remove();
|
|
1639
|
+
else anchor.replaceWith(detachedParent);
|
|
1640
|
+
}
|
|
1641
|
+
} else dismissPlaceholder(tryBranch);
|
|
1642
|
+
});
|
|
1643
|
+
if (!scope[promiseAccessor]) {
|
|
1644
|
+
if (awaitBranch) awaitBranch[PendingRenders] ||= [];
|
|
1645
|
+
if (tryPlaceholder) awaitCounter = addAwaitCounter(scope, tryPlaceholder);
|
|
1646
|
+
else if (!awaitCounter.i++) requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(scope, () => {
|
|
1647
|
+
if (!awaitBranch["#DetachedAwait"]) {
|
|
1648
|
+
awaitBranch["#StartNode"].parentNode.insertBefore(scope[nodeAccessor], awaitBranch["#StartNode"]);
|
|
1649
|
+
tempDetachBranch(tryBranch);
|
|
1650
|
+
}
|
|
1651
|
+
}, -1))));
|
|
1652
|
+
}
|
|
1653
|
+
const thisPromise = scope[promiseAccessor] = promise.then((data) => {
|
|
1654
|
+
if (thisPromise === scope[promiseAccessor]) {
|
|
1655
|
+
const referenceNode = scope[nodeAccessor];
|
|
1656
|
+
scope[promiseAccessor] = 0;
|
|
1657
|
+
if (scope["#ClosestBranch"]?.["#Gen"] === 0) {
|
|
1658
|
+
awaitCounter.c();
|
|
1659
|
+
run();
|
|
1660
|
+
return;
|
|
1661
|
+
}
|
|
1662
|
+
queueAsyncRender(scope, () => {
|
|
1663
|
+
awaitBranch = resolveAwait(scope, referenceNode, data);
|
|
1664
|
+
const pendingRenders = awaitBranch[PendingRenders];
|
|
1665
|
+
awaitBranch[PendingRenders] = 0;
|
|
1666
|
+
pendingRenders?.forEach(queuePendingRender);
|
|
1667
|
+
placeholderShown.add(pendingEffects);
|
|
1668
|
+
awaitCounter.c();
|
|
1669
|
+
if (awaitCounter.m) {
|
|
1670
|
+
const fnScopes = /* @__PURE__ */ new Map();
|
|
1671
|
+
const effects = awaitCounter.m([]);
|
|
1672
|
+
for (let i = 0; i < pendingEffects.length;) {
|
|
1673
|
+
const fn = pendingEffects[i++];
|
|
1674
|
+
let scopes = fnScopes.get(fn);
|
|
1675
|
+
if (!scopes) fnScopes.set(fn, scopes = /* @__PURE__ */ new Set());
|
|
1676
|
+
scopes.add(pendingEffects[i++]);
|
|
1677
|
+
}
|
|
1678
|
+
for (let i = 0; i < effects.length;) {
|
|
1679
|
+
const fn = effects[i++];
|
|
1680
|
+
const scope = effects[i++];
|
|
1681
|
+
if (!fnScopes.get(fn)?.has(scope)) queueEffect(scope, fn);
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1686
|
+
}, (error) => {
|
|
1687
|
+
if (thisPromise === scope[promiseAccessor]) {
|
|
1688
|
+
scope[promiseAccessor] = 0;
|
|
1689
|
+
if (tryPlaceholder && !awaitCounter.m) awaitCounter.c();
|
|
1690
|
+
else awaitCounter.i = 0;
|
|
1691
|
+
queueAsyncRender(scope, renderCatch, error);
|
|
1692
|
+
}
|
|
1693
|
+
});
|
|
1694
|
+
};
|
|
1695
|
+
return awaitPromise;
|
|
1696
|
+
}
|
|
1697
|
+
function _await_content(nodeAccessor, template, walks, setup) {
|
|
1698
|
+
const branchAccessor = BranchScopes$1 + nodeAccessor;
|
|
1699
|
+
const promiseAccessor = Promise$1 + nodeAccessor;
|
|
1700
|
+
const renderer = _content("", template, walks, setup)();
|
|
1701
|
+
return (scope) => {
|
|
1702
|
+
const pendingScopes = collectScopes(() => (scope[branchAccessor] = createBranch(scope[Global], renderer, scope, scope[nodeAccessor].parentNode))[DetachedAwait] = renderer);
|
|
1703
|
+
scope[branchAccessor][PendingScopes] = pendingScopes;
|
|
1704
|
+
const resolveSync = scope[promiseAccessor];
|
|
1705
|
+
if (typeof resolveSync === "function") {
|
|
1706
|
+
scope[promiseAccessor] = 0;
|
|
1707
|
+
resolveSync();
|
|
1708
|
+
}
|
|
1709
|
+
};
|
|
1710
|
+
}
|
|
1711
|
+
function addAwaitCounter(scope, tryBranch = findBranchWithKey(scope, PlaceholderContent)) {
|
|
1712
|
+
if (!tryBranch) return;
|
|
1713
|
+
let awaitCounter = tryBranch[AwaitCounter];
|
|
1714
|
+
if (!awaitCounter?.i) awaitCounter = createAwaitCounter(tryBranch, () => dismissPlaceholder(tryBranch));
|
|
1715
|
+
placeholderShown.add(pendingEffects);
|
|
1716
|
+
if (!awaitCounter.i++) requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(tryBranch, () => {
|
|
1717
|
+
insertBranchBefore(tryBranch["#PlaceholderBranch"] = createAndSetupBranch(tryBranch["$global"], tryBranch["#PlaceholderContent"], tryBranch["_"], tryBranch["#StartNode"].parentNode), tryBranch["#StartNode"].parentNode, tryBranch["#StartNode"]);
|
|
1718
|
+
tempDetachBranch(tryBranch);
|
|
1719
|
+
}, -1))));
|
|
1720
|
+
return awaitCounter;
|
|
1721
|
+
}
|
|
1722
|
+
function createAwaitCounter(tryBranch, done) {
|
|
1723
|
+
const awaitCounter = tryBranch[AwaitCounter] = {
|
|
1724
|
+
i: 0,
|
|
1725
|
+
c() {
|
|
1726
|
+
if (--awaitCounter.i) return 1;
|
|
1727
|
+
done();
|
|
1728
|
+
queueEffect(tryBranch, runPendingEffects);
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
return awaitCounter;
|
|
1732
|
+
}
|
|
1733
|
+
function runPendingEffects(scope) {
|
|
1734
|
+
const effects = scope[PendingEffects];
|
|
1735
|
+
if (effects) {
|
|
1736
|
+
scope[PendingEffects] = [];
|
|
1737
|
+
runEffects(effects, 1);
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
function dismissPlaceholder(tryBranch) {
|
|
1741
|
+
const placeholderBranch = tryBranch[PlaceholderBranch];
|
|
1742
|
+
if (placeholderBranch) {
|
|
1743
|
+
tryBranch[PlaceholderBranch] = 0;
|
|
1744
|
+
placeholderBranch[StartNode].parentNode.insertBefore(tryBranch[StartNode].parentNode, placeholderBranch[StartNode]);
|
|
1745
|
+
removeAndDestroyBranch(placeholderBranch);
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
function _try(nodeAccessor, template, walks, setup) {
|
|
1749
|
+
const branchAccessor = BranchScopes$1 + nodeAccessor;
|
|
1750
|
+
const renderer = _content("", template, walks, setup)();
|
|
1751
|
+
return (scope, input) => {
|
|
1752
|
+
if (!scope[branchAccessor]) setConditionalRenderer(scope, nodeAccessor, renderer, createAndSetupBranch);
|
|
1753
|
+
const branch = scope[branchAccessor];
|
|
1754
|
+
if (branch) {
|
|
1755
|
+
branch[BranchAccessor] = nodeAccessor;
|
|
1756
|
+
branch[CatchContent] = input.catch && (normalizeDynamicRenderer(input.catch) || 0);
|
|
1757
|
+
branch[PlaceholderContent] = normalizeDynamicRenderer(input.placeholder);
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1760
|
+
}
|
|
1761
|
+
function renderCatch(scope, error) {
|
|
1762
|
+
const tryWithCatch = findBranchWithKey(scope, CatchContent);
|
|
1763
|
+
if (!tryWithCatch) throw error;
|
|
1764
|
+
else {
|
|
1765
|
+
const owner = tryWithCatch["_"];
|
|
1766
|
+
const placeholderBranch = tryWithCatch[PlaceholderBranch];
|
|
1767
|
+
if (placeholderBranch) {
|
|
1768
|
+
if (tryWithCatch["#AwaitCounter"]) tryWithCatch[AwaitCounter].i = 0;
|
|
1769
|
+
owner[BranchScopes$1 + tryWithCatch[BranchAccessor]] = placeholderBranch;
|
|
1770
|
+
destroyBranch(tryWithCatch);
|
|
1771
|
+
}
|
|
1772
|
+
caughtError.add(pendingEffects);
|
|
1773
|
+
setConditionalRenderer(owner, tryWithCatch[BranchAccessor], tryWithCatch[CatchContent], createAndSetupBranch);
|
|
1774
|
+
tryWithCatch[CatchContent]?.[Params]?.(owner[BranchScopes$1 + tryWithCatch[BranchAccessor]], [error]);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
const _if = /*@__PURE__*/ withBranches((nodeAccessor, ...branchesArgs) => {
|
|
1778
|
+
const branchAccessor = ConditionalRenderer + nodeAccessor;
|
|
1779
|
+
const branches = [];
|
|
1780
|
+
let i = 0;
|
|
1781
|
+
while (i < branchesArgs.length) branches.push(_content("", branchesArgs[i++], branchesArgs[i++], branchesArgs[i++])());
|
|
1782
|
+
return (scope, newBranch) => {
|
|
1783
|
+
if (newBranch !== (scope[branchAccessor] ?? (scope["BranchScopes:" + nodeAccessor] && 0))) setConditionalRenderer(scope, nodeAccessor, branches[scope[branchAccessor] = newBranch], createAndSetupBranch);
|
|
1784
|
+
};
|
|
1785
|
+
});
|
|
1786
|
+
const _show = /*@__PURE__*/ withBranches((nodeAccessor, startNodeAccessor, endNodeAccessor) => {
|
|
1787
|
+
const rangeAccessor = BranchScopes$1 + nodeAccessor;
|
|
1788
|
+
return (scope, display) => {
|
|
1789
|
+
const referenceNode = scope[nodeAccessor];
|
|
1790
|
+
const onlyChild = referenceNode.nodeType === 1;
|
|
1791
|
+
const parentNode = onlyChild ? referenceNode : referenceNode.parentNode;
|
|
1792
|
+
let range = scope[rangeAccessor];
|
|
1793
|
+
if (!range) {
|
|
1794
|
+
range = scope[rangeAccessor] = {};
|
|
1795
|
+
range[StartNode] = onlyChild ? parentNode.firstChild : scope[startNodeAccessor];
|
|
1796
|
+
range[EndNode] = onlyChild ? parentNode.lastChild : endNodeAccessor === void 0 ? referenceNode.previousSibling : scope[endNodeAccessor];
|
|
1797
|
+
}
|
|
1798
|
+
let startNode = range[StartNode];
|
|
1799
|
+
if (range["#Id"] && startNode === range["#EndNode"] && startNode.tagName === "T") {
|
|
1800
|
+
const wrapper = startNode;
|
|
1801
|
+
if (!wrapper.firstChild) wrapper.appendChild(new Text());
|
|
1802
|
+
range = scope[rangeAccessor] = {};
|
|
1803
|
+
range[StartNode] = startNode = wrapper.firstChild;
|
|
1804
|
+
range[EndNode] = wrapper.lastChild;
|
|
1805
|
+
wrapper.replaceWith(...wrapper.childNodes);
|
|
1806
|
+
}
|
|
1807
|
+
const inDom = onlyChild ? !!parentNode.firstChild : startNode.parentNode === parentNode;
|
|
1808
|
+
if (display) {
|
|
1809
|
+
if (!inDom) insertBranchBefore(range, parentNode, onlyChild ? null : referenceNode);
|
|
1810
|
+
} else if (inDom) {
|
|
1811
|
+
if (onlyChild) {
|
|
1812
|
+
range[StartNode] = parentNode.firstChild;
|
|
1813
|
+
range[EndNode] = parentNode.lastChild;
|
|
1814
|
+
}
|
|
1815
|
+
tempDetachBranch(range);
|
|
1816
|
+
}
|
|
1817
|
+
};
|
|
1818
|
+
});
|
|
1819
|
+
function patchDynamicTag(fn) {
|
|
1820
|
+
_dynamic_tag = fn(_dynamic_tag);
|
|
1821
|
+
}
|
|
1822
|
+
let _dynamic_tag = /*@__PURE__*/ withBranches((nodeAccessor, getContent, getTagVar, inputIsArgs) => {
|
|
1823
|
+
const childScopeAccessor = BranchScopes$1 + nodeAccessor;
|
|
1824
|
+
const rendererAccessor = ConditionalRenderer + nodeAccessor;
|
|
1825
|
+
return (scope, newRenderer, getInput) => {
|
|
1826
|
+
const normalizedRenderer = normalizeDynamicRenderer(newRenderer);
|
|
1827
|
+
if (scope[rendererAccessor] !== (scope[rendererAccessor] = normalizedRenderer?.["id"] || normalizedRenderer) || getContent && !(normalizedRenderer || scope[childScopeAccessor])) {
|
|
1828
|
+
setConditionalRenderer(scope, nodeAccessor, normalizedRenderer || (getContent ? getContent(scope) : void 0), createBranchWithTagNameOrRenderer);
|
|
1829
|
+
if (getTagVar) scope[childScopeAccessor][TagVariable] = (value) => getTagVar()(scope, value);
|
|
1830
|
+
if (typeof normalizedRenderer === "string") {
|
|
1831
|
+
if (getContent) {
|
|
1832
|
+
const content = getContent(scope);
|
|
1833
|
+
setConditionalRenderer(scope[childScopeAccessor], `#${normalizedRenderer}/0`, content, createAndSetupBranch);
|
|
1834
|
+
if (content["accessor"]) subscribeToScopeSet(content[Owner], content[Accessor], scope[childScopeAccessor][`BranchScopes:#${normalizedRenderer}/0`]);
|
|
1835
|
+
}
|
|
1836
|
+
} else if (normalizedRenderer?.["accessor"]) subscribeToScopeSet(normalizedRenderer[Owner], normalizedRenderer[Accessor], scope[childScopeAccessor]);
|
|
1837
|
+
}
|
|
1838
|
+
if (normalizedRenderer) {
|
|
1839
|
+
const childScope = scope[childScopeAccessor];
|
|
1840
|
+
const args = getInput?.();
|
|
1841
|
+
if (typeof normalizedRenderer === "string") {
|
|
1842
|
+
const nodeAccessor = `#${normalizedRenderer}/0`;
|
|
1843
|
+
(getContent ? _attrs : _attrs_content)(childScope, nodeAccessor, (inputIsArgs ? args[0] : args) || {}, controllableRenders[childScope[nodeAccessor].tagName]);
|
|
1844
|
+
if (childScope["EventAttributes:" + nodeAccessor] || childScope["ControlledHandler:" + nodeAccessor]) queueEffect(childScope, dynamicTagScript);
|
|
1845
|
+
} else {
|
|
1846
|
+
for (const accessor in normalizedRenderer[LocalClosures]) normalizedRenderer[LocalClosures][accessor](childScope, normalizedRenderer[LocalClosureValues][accessor]);
|
|
1847
|
+
if (normalizedRenderer["params"]) if (inputIsArgs) normalizedRenderer[Params](childScope, normalizedRenderer._ ? args[0] : args);
|
|
1848
|
+
else {
|
|
1849
|
+
const inputWithContent = getContent ? {
|
|
1850
|
+
...args,
|
|
1851
|
+
content: getContent(scope)
|
|
1852
|
+
} : args || {};
|
|
1853
|
+
normalizedRenderer[Params](childScope, normalizedRenderer._ ? inputWithContent : [inputWithContent]);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
};
|
|
1858
|
+
});
|
|
1859
|
+
const _dynamic_tag_content = /*@__PURE__*/ withBranches((nodeAccessor) => {
|
|
1860
|
+
const childScopeAccessor = BranchScopes$1 + nodeAccessor;
|
|
1861
|
+
const rendererAccessor = ConditionalRenderer + nodeAccessor;
|
|
1862
|
+
return (scope, renderer) => {
|
|
1863
|
+
if (scope[rendererAccessor] !== (scope[rendererAccessor] = renderer?.["id"] || renderer)) {
|
|
1864
|
+
setConditionalRenderer(scope, nodeAccessor, renderer, createAndSetupBranch);
|
|
1865
|
+
if (renderer?.["accessor"]) subscribeToScopeSet(renderer[Owner], renderer[Accessor], scope[childScopeAccessor]);
|
|
1866
|
+
}
|
|
1867
|
+
if (renderer) for (const accessor in renderer[LocalClosures]) renderer[LocalClosures][accessor](scope[childScopeAccessor], renderer[LocalClosureValues][accessor]);
|
|
1868
|
+
};
|
|
1869
|
+
});
|
|
1870
|
+
function _resume_dynamic_tag() {
|
|
1871
|
+
_resume(DYNAMIC_TAG_SCRIPT_REGISTER_ID, dynamicTagScript);
|
|
1872
|
+
}
|
|
1873
|
+
function dynamicTagScript(branch) {
|
|
1874
|
+
_attrs_script(branch, `#${branch[Renderer]}/0`);
|
|
1875
|
+
}
|
|
1876
|
+
function setConditionalRenderer(scope, nodeAccessor, newRenderer, createBranch) {
|
|
1877
|
+
const referenceNode = scope[nodeAccessor];
|
|
1878
|
+
const prevBranch = scope[BranchScopes$1 + nodeAccessor];
|
|
1879
|
+
const parentNode = referenceNode.nodeType > 1 ? (prevBranch?.["#StartNode"] || referenceNode).parentNode : referenceNode;
|
|
1880
|
+
const newBranch = scope[BranchScopes$1 + nodeAccessor] = newRenderer && createBranch(scope["$global"], newRenderer, scope, parentNode);
|
|
1881
|
+
if (referenceNode === parentNode) {
|
|
1882
|
+
if (prevBranch) {
|
|
1883
|
+
destroyBranch(prevBranch);
|
|
1884
|
+
referenceNode.textContent = "";
|
|
1885
|
+
}
|
|
1886
|
+
if (newBranch) insertBranchBefore(newBranch, parentNode, null);
|
|
1887
|
+
} else if (prevBranch) {
|
|
1888
|
+
if (newBranch) insertBranchBefore(newBranch, parentNode, prevBranch[StartNode]);
|
|
1889
|
+
else parentNode.insertBefore(referenceNode, prevBranch[StartNode]);
|
|
1890
|
+
removeAndDestroyBranch(prevBranch);
|
|
1891
|
+
} else if (newBranch) {
|
|
1892
|
+
insertBranchBefore(newBranch, parentNode, referenceNode);
|
|
1893
|
+
referenceNode.remove();
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
const loop = /*@__PURE__*/ withBranches((forEach) => (nodeAccessor, template, walks, setup, params) => {
|
|
1897
|
+
const scopesAccessor = BranchScopes$1 + nodeAccessor;
|
|
1898
|
+
const keyedScopesAccessor = KeyedScopes + nodeAccessor;
|
|
1899
|
+
const renderer = _content("", template, walks, setup)();
|
|
1900
|
+
return (scope, value) => {
|
|
1901
|
+
const referenceNode = scope[nodeAccessor];
|
|
1902
|
+
const oldScopes = toArray(scope[scopesAccessor]);
|
|
1903
|
+
const newScopes = scope[scopesAccessor] = [];
|
|
1904
|
+
scope[keyedScopesAccessor] = null;
|
|
1905
|
+
const oldLen = oldScopes.length;
|
|
1906
|
+
const parentNode = referenceNode.nodeType > 1 ? referenceNode.parentNode || oldScopes[0]?.["#StartNode"].parentNode : referenceNode;
|
|
1907
|
+
let oldScopesByKey;
|
|
1908
|
+
let hasPotentialMoves;
|
|
1909
|
+
let start = 0;
|
|
1910
|
+
var seenKeys = /* @__PURE__ */ new Set();
|
|
1911
|
+
forEach(value, (key, args) => {
|
|
1912
|
+
assertValidLoopKey(key, seenKeys);
|
|
1913
|
+
const i = newScopes.length;
|
|
1914
|
+
const oldScope = oldScopes[i];
|
|
1915
|
+
let branch = oldLen && (oldScopesByKey || key !== (oldScope?.["#LoopKey"] ?? i) ? (oldScopesByKey ||= oldScopes.reduce((map, scope, j) => j < i ? map : (scope["#LoopIndex"] = j, map.set(scope["#LoopKey"] ?? j, scope)), /* @__PURE__ */ new Map())).get(key) : oldScope && (start++, oldScope));
|
|
1916
|
+
if (branch) {
|
|
1917
|
+
hasPotentialMoves = true;
|
|
1918
|
+
oldScopesByKey?.delete(key);
|
|
1919
|
+
} else branch = createAndSetupBranch(scope[Global], renderer, scope, parentNode);
|
|
1920
|
+
branch[LoopKey] = key;
|
|
1921
|
+
newScopes.push(branch);
|
|
1922
|
+
params?.(branch, args);
|
|
1923
|
+
});
|
|
1924
|
+
const newLen = newScopes.length;
|
|
1925
|
+
const hasSiblings = referenceNode !== parentNode;
|
|
1926
|
+
let afterReference = null;
|
|
1927
|
+
let oldEnd = oldLen - 1;
|
|
1928
|
+
let newEnd = newLen - 1;
|
|
1929
|
+
if (hasSiblings) {
|
|
1930
|
+
if (oldLen) {
|
|
1931
|
+
afterReference = oldScopes[oldEnd][EndNode].nextSibling;
|
|
1932
|
+
if (!newLen) parentNode.insertBefore(referenceNode, afterReference);
|
|
1933
|
+
} else if (newLen) {
|
|
1934
|
+
afterReference = referenceNode.nextSibling;
|
|
1935
|
+
referenceNode.remove();
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
if (!hasPotentialMoves) {
|
|
1939
|
+
if (oldLen) {
|
|
1940
|
+
oldScopes.forEach(hasSiblings ? removeAndDestroyBranch : destroyBranch);
|
|
1941
|
+
if (!hasSiblings) parentNode.textContent = "";
|
|
1942
|
+
}
|
|
1943
|
+
for (const newScope of newScopes) insertBranchBefore(newScope, parentNode, afterReference);
|
|
1944
|
+
return;
|
|
1945
|
+
}
|
|
1946
|
+
if (oldScopesByKey) oldScopesByKey.forEach(removeAndDestroyBranch);
|
|
1947
|
+
else for (let i = newLen; i < oldLen; i++) removeAndDestroyBranch(oldScopes[i]);
|
|
1948
|
+
while (oldEnd >= start && newEnd >= start && oldScopes[oldEnd] === newScopes[newEnd]) {
|
|
1949
|
+
oldEnd--;
|
|
1950
|
+
newEnd--;
|
|
1951
|
+
}
|
|
1952
|
+
if (oldEnd + 1 < oldLen) afterReference = oldScopes[oldEnd + 1][StartNode];
|
|
1953
|
+
if (start > oldEnd || start > newEnd) {
|
|
1954
|
+
for (let i = start; i <= newEnd; i++) insertBranchBefore(newScopes[i], parentNode, afterReference);
|
|
1955
|
+
return;
|
|
1956
|
+
}
|
|
1957
|
+
const diffLen = newEnd - start + 1;
|
|
1958
|
+
const sources = new Array(diffLen);
|
|
1959
|
+
const pred = new Array(diffLen);
|
|
1960
|
+
const tails = [];
|
|
1961
|
+
let tail = -1;
|
|
1962
|
+
let lo;
|
|
1963
|
+
let hi;
|
|
1964
|
+
let mid;
|
|
1965
|
+
for (let i = diffLen; i--;) sources[i] = newScopes[start + i]["#LoopIndex"] ?? -1;
|
|
1966
|
+
for (let i = 0; i < diffLen; i++) if (~sources[i]) if (tail < 0 || sources[tails[tail]] < sources[i]) {
|
|
1967
|
+
if (~tail) pred[i] = tails[tail];
|
|
1968
|
+
tails[++tail] = i;
|
|
1969
|
+
} else {
|
|
1970
|
+
lo = 0;
|
|
1971
|
+
hi = tail;
|
|
1972
|
+
while (lo < hi) {
|
|
1973
|
+
mid = (lo + hi) / 2 | 0;
|
|
1974
|
+
if (sources[tails[mid]] < sources[i]) lo = mid + 1;
|
|
1975
|
+
else hi = mid;
|
|
1976
|
+
}
|
|
1977
|
+
if (sources[i] < sources[tails[lo]]) {
|
|
1978
|
+
if (lo > 0) pred[i] = tails[lo - 1];
|
|
1979
|
+
tails[lo] = i;
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
hi = tails[tail];
|
|
1983
|
+
lo = tail + 1;
|
|
1984
|
+
while (lo-- > 0) {
|
|
1985
|
+
tails[lo] = hi;
|
|
1986
|
+
hi = pred[hi];
|
|
1987
|
+
}
|
|
1988
|
+
for (let i = diffLen; i--;) {
|
|
1989
|
+
if (~tail && i === tails[tail]) tail--;
|
|
1990
|
+
else insertBranchBefore(newScopes[start + i], parentNode, afterReference);
|
|
1991
|
+
afterReference = newScopes[start + i][StartNode];
|
|
1992
|
+
}
|
|
1993
|
+
};
|
|
1994
|
+
});
|
|
1995
|
+
const _for_of = /*@__PURE__*/ loop(([all, by = bySecondArg], cb) => {
|
|
1996
|
+
if (typeof by === "string") forOf(all, (item, i) => cb(item[by], [item, i]));
|
|
1997
|
+
else forOf(all, (item, i) => cb(by(item, i), [item, i]));
|
|
1998
|
+
});
|
|
1999
|
+
const _for_in = /*@__PURE__*/ loop(([obj, by = byFirstArg], cb) => forIn(obj, (key, value) => cb(by(key, value), [key, value])));
|
|
2000
|
+
const _for_to = /*@__PURE__*/ loop(([to, from, step, by = byFirstArg], cb) => forTo(to, from, step, (v) => cb(by(v), [v])));
|
|
2001
|
+
const _for_until = /*@__PURE__*/ loop(([until, from, step, by = byFirstArg], cb) => forUntil(until, from, step, (v) => cb(by(v), [v])));
|
|
2002
|
+
function createBranchWithTagNameOrRenderer($global, tagNameOrRenderer, parentScope, parentNode) {
|
|
2003
|
+
if (typeof tagNameOrRenderer === "string") assertValidTagName(tagNameOrRenderer);
|
|
2004
|
+
const branch = createBranch($global, tagNameOrRenderer, parentScope, parentNode);
|
|
2005
|
+
if (typeof tagNameOrRenderer === "string") branch[`#${tagNameOrRenderer}/0`] = branch[StartNode] = branch[EndNode] = document.createElementNS(tagNameOrRenderer === "svg" ? "http://www.w3.org/2000/svg" : tagNameOrRenderer === "math" ? "http://www.w3.org/1998/Math/MathML" : parentNode.namespaceURI, tagNameOrRenderer);
|
|
2006
|
+
else setupBranch(tagNameOrRenderer, branch);
|
|
2007
|
+
return branch;
|
|
2008
|
+
}
|
|
2009
|
+
function bySecondArg(_item, index) {
|
|
2010
|
+
return index;
|
|
2011
|
+
}
|
|
2012
|
+
function byFirstArg(name) {
|
|
2013
|
+
return name;
|
|
2014
|
+
}
|
|
2015
|
+
//#endregion
|
|
2016
|
+
export { _html as $, queueEffect as $t, _attr_select_value as A, _id as At, _attr_class as B, _assert_init as Bt, _attr_input_checked_default as C, PendingRenders as Cn, _closure_get as Ct, _attr_input_value_default as D, _for_selector as Dt, _attr_input_value_attribute_default as E, _for_closure as Et, _controllable_select as F, _return as Ft, _attr_style as G, _on as Gt, _attr_class_items as H, insertBranchBefore as Ht, _controllable_textarea as I, _return_change as It, _attrs as J, caughtError as Jt, _attr_style_item as K, $signal as Kt, controllableRenders as L, _script as Lt, _attr_select_value_script as M, _let as Mt, _controllable_input as N, _let_change as Nt, _attr_input_value_dynamic_default as O, _hoist as Ot, _controllable_open as P, _or as Pt, _attrs_script as Q, queueAsyncRender as Qt, controllableScripts as R, _var as Rt, _attr_input_checkedValue_script as S, PendingEffects as Sn, _closure as St, _attr_input_value as T, TagVariable as Tn, _el_read as Tt, _attr_content as U, removeAndDestroyBranch as Ut, _attr_class_item as V, destroyBranch as Vt, _attr_nonce as W, syncGen as Wt, _attrs_partial as X, placeholderShown as Xt, _attrs_content as Y, installCatch as Yt, _attrs_partial_content as Z, prepareEffects as Zt, _attr_details_or_dialog_open_default as _, EndNode as _n, getRegisteredWithScope as _t, _for_in as a, forTo as an, _to_text as at, _attr_input_checkedValue as b, Load as bn, ready as bt, _for_until as c, _call as cn, _content as ct, _show as d, Params as dn, createAndSetupBranch as dt, run as en, _lifecycle as et, _try as f, Setup as fn, createBranch as ft, _attr_details_or_dialog_open as g, ClosestBranch as gn, _var_resume as gt, renderCatch as h, AwaitCounter as hn, _resume as ht, _dynamic_tag_content as i, forOf as in, _text_content as it, _attr_select_value_default as j, _if_closure as jt, _attr_input_value_script as k, _hoist_resume as kt, _if as l, Clone as ln, _content_closures as lt, patchDynamicTag as m, Scope as mn, _el as mt, _await_promise as n, runId as nn, _style_shell as nt, _for_of as o, forUntil as on, insertChildNodes as ot, addAwaitCounter as p, Pending as pn, setupBranch as pt, _attr_style_items as q, $signalReset as qt, _dynamic_tag as r, forIn as rn, _text as rt, _for_to as s, _assert_hoist as sn, toInsertNode as st, _await_content as t, runEffects as tn, _style_rule_item as tt, _resume_dynamic_tag as u, Owner as un, _content_resume as ut, _attr_details_or_dialog_open_script as v, Gen$1 as vn, init as vt, _attr_input_checked_script as w, StartNode as wn, _const as wt, _attr_input_checkedValue_default as x, ParentBranch as xn, _child_setup as xt, _attr_input_checked as y, Global as yn, initEmbedded as yt, _attr as z, _var_change as zt };
|