@marko/runtime-tags 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/helpers.d.ts +4 -0
- package/dist/common/types.d.ts +90 -0
- package/dist/debug/dom.js +1411 -0
- package/dist/debug/dom.js.map +7 -0
- package/dist/debug/dom.mjs +1388 -0
- package/dist/debug/dom.mjs.map +7 -0
- package/dist/debug/html.js +1323 -0
- package/dist/debug/html.js.map +7 -0
- package/dist/debug/html.mjs +1263 -0
- package/dist/debug/html.mjs.map +7 -0
- package/dist/dom/abort-signal.d.ts +3 -0
- package/dist/dom/control-flow.d.ts +14 -0
- package/dist/dom/dom.d.ts +14 -0
- package/dist/dom/event.d.ts +3 -0
- package/dist/dom/queue.d.ts +10 -0
- package/dist/dom/reconcile-domdiff.d.ts +2 -0
- package/dist/dom/reconcile-listdiff.d.ts +2 -0
- package/dist/dom/reconcile-longest-increasing-subsequence.d.ts +2 -0
- package/dist/dom/reconcile.d.ts +1 -0
- package/dist/dom/renderer.d.ts +20 -0
- package/dist/dom/resume.d.ts +8 -0
- package/dist/dom/schedule.d.ts +2 -0
- package/dist/dom/scope.d.ts +13 -0
- package/dist/dom/signals.d.ts +31 -0
- package/dist/dom/template.d.ts +11 -0
- package/dist/dom/walker.d.ts +4 -0
- package/dist/dom.d.ts +11 -0
- package/dist/dom.js +904 -0
- package/dist/dom.js.map +7 -0
- package/dist/dom.mjs +884 -0
- package/dist/dom.mjs.map +7 -0
- package/dist/html/attrs.d.ts +4 -0
- package/dist/html/content.d.ts +5 -0
- package/dist/html/dynamic-tag.d.ts +12 -0
- package/dist/html/reorder-runtime.d.ts +1 -0
- package/dist/html/serializer.d.ts +38 -0
- package/dist/html/template.d.ts +9 -0
- package/dist/html/writer.d.ts +40 -0
- package/dist/html.d.ts +6 -0
- package/dist/html.js +933 -0
- package/dist/html.js.map +7 -0
- package/dist/html.mjs +876 -0
- package/dist/html.mjs.map +7 -0
- package/package.json +39 -0
package/dist/dom.js
ADDED
|
@@ -0,0 +1,904 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
16
|
+
|
|
17
|
+
// src/dom.ts
|
|
18
|
+
var dom_exports = {};
|
|
19
|
+
__export(dom_exports, {
|
|
20
|
+
attr: () => attr,
|
|
21
|
+
attrs: () => attrs,
|
|
22
|
+
bindFunction: () => bindFunction,
|
|
23
|
+
bindRenderer: () => bindRenderer,
|
|
24
|
+
childClosures: () => childClosures,
|
|
25
|
+
classAttr: () => classAttr,
|
|
26
|
+
closure: () => closure,
|
|
27
|
+
conditional: () => conditional,
|
|
28
|
+
conditionalOnlyChild: () => conditionalOnlyChild,
|
|
29
|
+
createRenderer: () => createRenderer,
|
|
30
|
+
createScope: () => createScope,
|
|
31
|
+
createScopeWithRenderer: () => createScopeWithRenderer,
|
|
32
|
+
createTemplate: () => createTemplate,
|
|
33
|
+
data: () => data,
|
|
34
|
+
dynamicClosure: () => dynamicClosure,
|
|
35
|
+
dynamicSubscribers: () => dynamicSubscribers,
|
|
36
|
+
dynamicTagAttrs: () => dynamicTagAttrs,
|
|
37
|
+
getAbortSignal: () => getAbortSignal,
|
|
38
|
+
getRegisteredWithScope: () => getRegisteredWithScope,
|
|
39
|
+
html: () => html,
|
|
40
|
+
inChild: () => inChild,
|
|
41
|
+
inConditionalScope: () => inConditionalScope,
|
|
42
|
+
inLoopScope: () => inLoopScope,
|
|
43
|
+
init: () => init,
|
|
44
|
+
initValue: () => initValue,
|
|
45
|
+
intersection: () => intersection,
|
|
46
|
+
intersections: () => intersections,
|
|
47
|
+
lifecycle: () => lifecycle,
|
|
48
|
+
loopIn: () => loopIn,
|
|
49
|
+
loopOf: () => loopOf,
|
|
50
|
+
loopTo: () => loopTo,
|
|
51
|
+
nextTagId: () => nextTagId,
|
|
52
|
+
on: () => on,
|
|
53
|
+
patchConditionals: () => patchConditionals,
|
|
54
|
+
prepare: () => prepare,
|
|
55
|
+
props: () => props,
|
|
56
|
+
queueEffect: () => queueEffect,
|
|
57
|
+
queueSource: () => queueSource,
|
|
58
|
+
register: () => register,
|
|
59
|
+
registerSubscriber: () => registerSubscriber,
|
|
60
|
+
resetAbortSignal: () => resetAbortSignal,
|
|
61
|
+
run: () => run,
|
|
62
|
+
runEffects: () => runEffects,
|
|
63
|
+
scopeLookup: () => scopeLookup,
|
|
64
|
+
setTagVar: () => setTagVar,
|
|
65
|
+
styleAttr: () => styleAttr,
|
|
66
|
+
tagVarSignal: () => tagVarSignal,
|
|
67
|
+
value: () => value,
|
|
68
|
+
values: () => values,
|
|
69
|
+
write: () => write
|
|
70
|
+
});
|
|
71
|
+
module.exports = __toCommonJS(dom_exports);
|
|
72
|
+
|
|
73
|
+
// src/dom/scope.ts
|
|
74
|
+
function createScope($global) {
|
|
75
|
+
let scope = {};
|
|
76
|
+
return scope.o = !0, scope.$global = $global, scope;
|
|
77
|
+
}
|
|
78
|
+
var emptyScope = createScope({});
|
|
79
|
+
function getEmptyScope(marker) {
|
|
80
|
+
return emptyScope.a = emptyScope.c = marker, emptyScope;
|
|
81
|
+
}
|
|
82
|
+
function write(scope, localIndex, value2) {
|
|
83
|
+
return scope[localIndex] !== value2 ? (scope[localIndex] = value2, 1) : 0;
|
|
84
|
+
}
|
|
85
|
+
function binder(bind) {
|
|
86
|
+
return (scope, value2) => {
|
|
87
|
+
scope.h ??= /* @__PURE__ */ new Map();
|
|
88
|
+
let bound = scope.h.get(value2);
|
|
89
|
+
return bound || (bound = bind(scope, value2), scope.h.set(value2, bound)), bound;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
var bindRenderer = binder(
|
|
93
|
+
(ownerScope, renderer) => renderer && {
|
|
94
|
+
...renderer,
|
|
95
|
+
i: ownerScope
|
|
96
|
+
}
|
|
97
|
+
), bindFunction = binder(
|
|
98
|
+
(boundScope, fn) => fn.length ? function(...args) {
|
|
99
|
+
return fn.call(this, boundScope, ...args);
|
|
100
|
+
} : function() {
|
|
101
|
+
return fn.call(this, boundScope);
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
function destroyScope(scope) {
|
|
105
|
+
_destroyScope(scope), scope._?.f?.delete(scope);
|
|
106
|
+
let closureSignals = scope.p?.b;
|
|
107
|
+
if (closureSignals)
|
|
108
|
+
for (let signal of closureSignals)
|
|
109
|
+
signal.g?.(scope);
|
|
110
|
+
return scope;
|
|
111
|
+
}
|
|
112
|
+
function _destroyScope(scope) {
|
|
113
|
+
let cleanup = scope.f;
|
|
114
|
+
if (cleanup)
|
|
115
|
+
for (let instance of cleanup)
|
|
116
|
+
_destroyScope(instance);
|
|
117
|
+
let controllers = scope.j;
|
|
118
|
+
if (controllers)
|
|
119
|
+
for (let ctrl of controllers.values())
|
|
120
|
+
ctrl.abort();
|
|
121
|
+
}
|
|
122
|
+
function onDestroy(scope) {
|
|
123
|
+
let parentScope = scope._;
|
|
124
|
+
for (; parentScope && !parentScope.f?.has(scope); )
|
|
125
|
+
(parentScope.f ||= /* @__PURE__ */ new Set()).add(scope), scope = parentScope, parentScope = scope._;
|
|
126
|
+
}
|
|
127
|
+
function removeAndDestroyScope(scope) {
|
|
128
|
+
destroyScope(scope);
|
|
129
|
+
let current = scope.a, stop = scope.c.nextSibling;
|
|
130
|
+
for (; current !== stop; ) {
|
|
131
|
+
let next = current.nextSibling;
|
|
132
|
+
current.remove(), current = next;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function insertBefore(scope, parent, nextSibling) {
|
|
136
|
+
let current = scope.a, stop = scope.c.nextSibling;
|
|
137
|
+
for (; current !== stop; ) {
|
|
138
|
+
let next = current.nextSibling;
|
|
139
|
+
parent.insertBefore(current, nextSibling), current = next;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/dom/reconcile-longest-increasing-subsequence.ts
|
|
144
|
+
var WRONG_POS = 2147483647;
|
|
145
|
+
function reconcile(parent, oldScopes, newScopes, afterReference) {
|
|
146
|
+
let oldStart = 0, newStart = 0, oldEnd = oldScopes.length - 1, newEnd = newScopes.length - 1, oldStartScope = oldScopes[oldStart], newStartScope = newScopes[newStart], oldEndScope = oldScopes[oldEnd], newEndScope = newScopes[newEnd], i, j, k, nextSibling, oldScope, newScope;
|
|
147
|
+
outer: {
|
|
148
|
+
for (; oldStartScope === newStartScope; ) {
|
|
149
|
+
if (++oldStart, ++newStart, oldStart > oldEnd || newStart > newEnd)
|
|
150
|
+
break outer;
|
|
151
|
+
oldStartScope = oldScopes[oldStart], newStartScope = newScopes[newStart];
|
|
152
|
+
}
|
|
153
|
+
for (; oldEndScope === newEndScope; ) {
|
|
154
|
+
if (--oldEnd, --newEnd, oldStart > oldEnd || newStart > newEnd)
|
|
155
|
+
break outer;
|
|
156
|
+
oldEndScope = oldScopes[oldEnd], newEndScope = newScopes[newEnd];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (oldStart > oldEnd) {
|
|
160
|
+
if (newStart <= newEnd) {
|
|
161
|
+
k = newEnd + 1, nextSibling = k < newScopes.length ? newScopes[k].a : afterReference;
|
|
162
|
+
do
|
|
163
|
+
insertBefore(newScopes[newStart++], parent, nextSibling);
|
|
164
|
+
while (newStart <= newEnd);
|
|
165
|
+
}
|
|
166
|
+
} else if (newStart > newEnd)
|
|
167
|
+
do
|
|
168
|
+
removeAndDestroyScope(oldScopes[oldStart++]);
|
|
169
|
+
while (oldStart <= oldEnd);
|
|
170
|
+
else {
|
|
171
|
+
let oldLength = oldEnd - oldStart + 1, newLength = newEnd - newStart + 1, aNullable = oldScopes, sources = new Array(newLength);
|
|
172
|
+
for (i = 0; i < newLength; ++i)
|
|
173
|
+
sources[i] = -1;
|
|
174
|
+
let pos = 0, synced = 0, keyIndex = /* @__PURE__ */ new Map();
|
|
175
|
+
for (j = newStart; j <= newEnd; ++j)
|
|
176
|
+
keyIndex.set(newScopes[j], j);
|
|
177
|
+
for (i = oldStart; i <= oldEnd && synced < newLength; ++i)
|
|
178
|
+
oldScope = oldScopes[i], j = keyIndex.get(oldScope), j !== void 0 && (pos = pos > j ? WRONG_POS : j, ++synced, newScope = newScopes[j], sources[j - newStart] = i, aNullable[i] = null);
|
|
179
|
+
if (oldLength === oldScopes.length && synced === 0) {
|
|
180
|
+
for (; newStart < newLength; ++newStart)
|
|
181
|
+
insertBefore(newScopes[newStart], parent, afterReference);
|
|
182
|
+
for (; oldStart < oldLength; ++oldStart)
|
|
183
|
+
removeAndDestroyScope(oldScopes[oldStart]);
|
|
184
|
+
} else {
|
|
185
|
+
for (i = oldLength - synced; i > 0; )
|
|
186
|
+
oldScope = aNullable[oldStart++], oldScope !== null && (removeAndDestroyScope(oldScope), i--);
|
|
187
|
+
if (pos === WRONG_POS) {
|
|
188
|
+
let seq = longestIncreasingSubsequence(sources);
|
|
189
|
+
for (j = seq.length - 1, k = newScopes.length, i = newLength - 1; i >= 0; --i)
|
|
190
|
+
sources[i] === -1 ? (pos = i + newStart, newScope = newScopes[pos++], nextSibling = pos < k ? newScopes[pos].a : afterReference, insertBefore(newScope, parent, nextSibling)) : j < 0 || i !== seq[j] ? (pos = i + newStart, newScope = newScopes[pos++], nextSibling = pos < k ? newScopes[pos].a : afterReference, insertBefore(newScope, parent, nextSibling)) : --j;
|
|
191
|
+
} else if (synced !== newLength)
|
|
192
|
+
for (k = newScopes.length, i = newLength - 1; i >= 0; --i)
|
|
193
|
+
sources[i] === -1 && (pos = i + newStart, newScope = newScopes[pos++], nextSibling = pos < k ? newScopes[pos].a : afterReference, insertBefore(newScope, parent, nextSibling));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function longestIncreasingSubsequence(a) {
|
|
198
|
+
let p = a.slice(), result = [];
|
|
199
|
+
result.push(0);
|
|
200
|
+
let u, v;
|
|
201
|
+
for (let i = 0, il = a.length; i < il; ++i) {
|
|
202
|
+
if (a[i] === -1)
|
|
203
|
+
continue;
|
|
204
|
+
let j = result[result.length - 1];
|
|
205
|
+
if (a[j] < a[i]) {
|
|
206
|
+
p[i] = j, result.push(i);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
for (u = 0, v = result.length - 1; u < v; ) {
|
|
210
|
+
let c = (u + v) / 2 | 0;
|
|
211
|
+
a[result[c]] < a[i] ? u = c + 1 : v = c;
|
|
212
|
+
}
|
|
213
|
+
a[i] < a[result[u]] && (u > 0 && (p[i] = result[u - 1]), result[u] = i);
|
|
214
|
+
}
|
|
215
|
+
for (u = result.length, v = result[u - 1]; u-- > 0; )
|
|
216
|
+
result[u] = v, v = p[v];
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/common/helpers.ts
|
|
221
|
+
function classValue(value2) {
|
|
222
|
+
return toDelimitedString(value2, " ", stringifyClassObject);
|
|
223
|
+
}
|
|
224
|
+
function stringifyClassObject(name, value2) {
|
|
225
|
+
return isVoid(value2) ? "" : name;
|
|
226
|
+
}
|
|
227
|
+
function styleValue(value2) {
|
|
228
|
+
return toDelimitedString(value2, ";", stringifyStyleObject);
|
|
229
|
+
}
|
|
230
|
+
var NON_DIMENSIONAL = /^(--|ta|or|li|z)|n-c|i(do|nk|m|t)|w$|we/;
|
|
231
|
+
function stringifyStyleObject(name, value2) {
|
|
232
|
+
return isVoid(value2) ? "" : (typeof value2 == "number" && value2 && !NON_DIMENSIONAL.test(name) && (value2 += "px"), `${name}:${value2}`);
|
|
233
|
+
}
|
|
234
|
+
function toDelimitedString(val, delimiter, stringify) {
|
|
235
|
+
switch (typeof val) {
|
|
236
|
+
case "string":
|
|
237
|
+
return val;
|
|
238
|
+
case "object":
|
|
239
|
+
if (val !== null) {
|
|
240
|
+
let result = "", curDelimiter = "";
|
|
241
|
+
if (Array.isArray(val))
|
|
242
|
+
for (let v of val) {
|
|
243
|
+
let part = toDelimitedString(v, delimiter, stringify);
|
|
244
|
+
part !== "" && (result += curDelimiter + part, curDelimiter = delimiter);
|
|
245
|
+
}
|
|
246
|
+
else
|
|
247
|
+
for (let name in val) {
|
|
248
|
+
let v = val[name], part = stringify(name, v);
|
|
249
|
+
part !== "" && (result += curDelimiter + part, curDelimiter = delimiter);
|
|
250
|
+
}
|
|
251
|
+
return result;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return "";
|
|
255
|
+
}
|
|
256
|
+
function isVoid(value2) {
|
|
257
|
+
return value2 == null || value2 === !1;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// src/dom/abort-signal.ts
|
|
261
|
+
function resetAbortSignal(scope, id) {
|
|
262
|
+
let controllers = scope.j;
|
|
263
|
+
if (controllers) {
|
|
264
|
+
let ctrl = controllers.get(id);
|
|
265
|
+
ctrl && (ctrl.abort(), controllers.delete(id));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function getAbortSignal(scope, id) {
|
|
269
|
+
let controllers = scope.j ??= /* @__PURE__ */ new Map(), controller = controllers.get(id);
|
|
270
|
+
return controller || (onDestroy(scope), controllers.set(id, controller = new AbortController())), controller.signal;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/dom/dom.ts
|
|
274
|
+
function attr(element, name, value2) {
|
|
275
|
+
let normalizedValue = normalizeAttrValue(value2);
|
|
276
|
+
normalizedValue === void 0 ? element.removeAttribute(name) : element.setAttribute(name, normalizedValue);
|
|
277
|
+
}
|
|
278
|
+
function classAttr(element, value2) {
|
|
279
|
+
attr(element, "class", classValue(value2) || !1);
|
|
280
|
+
}
|
|
281
|
+
function styleAttr(element, value2) {
|
|
282
|
+
attr(element, "style", styleValue(value2) || !1);
|
|
283
|
+
}
|
|
284
|
+
function data(node, value2) {
|
|
285
|
+
let normalizedValue = normalizeString(value2);
|
|
286
|
+
node.data !== normalizedValue && (node.data = normalizedValue);
|
|
287
|
+
}
|
|
288
|
+
function attrs(scope, elementAccessor, nextAttrs) {
|
|
289
|
+
let prevAttrs = scope[elementAccessor + "~" /* PreviousAttributes */], element = scope[elementAccessor];
|
|
290
|
+
if (prevAttrs)
|
|
291
|
+
for (let name in prevAttrs)
|
|
292
|
+
nextAttrs && name in nextAttrs || element.removeAttribute(name);
|
|
293
|
+
for (let name in nextAttrs)
|
|
294
|
+
prevAttrs && nextAttrs[name] === prevAttrs[name] || (name === "class" ? classAttr(element, nextAttrs[name]) : name === "style" ? styleAttr(element, nextAttrs[name]) : name !== "renderBody" && attr(element, name, nextAttrs[name]));
|
|
295
|
+
scope[elementAccessor + "~" /* PreviousAttributes */] = nextAttrs;
|
|
296
|
+
}
|
|
297
|
+
var doc = document, parser = /* @__PURE__ */ doc.createElement("template");
|
|
298
|
+
function html(scope, value2, index) {
|
|
299
|
+
let firstChild = scope[index], lastChild = scope[index + "-"] || firstChild, parentNode = firstChild.parentNode, afterReference = lastChild.nextSibling;
|
|
300
|
+
parser.innerHTML = value2 || value2 === 0 ? `${value2}` : "<!>";
|
|
301
|
+
let newContent = parser.content;
|
|
302
|
+
write(scope, index, newContent.firstChild), write(scope, index + "-", newContent.lastChild), parentNode.insertBefore(newContent, firstChild);
|
|
303
|
+
let current = firstChild;
|
|
304
|
+
for (; current !== afterReference; ) {
|
|
305
|
+
let next = current.nextSibling;
|
|
306
|
+
current.remove(), current = next;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function props(scope, nodeIndex, index) {
|
|
310
|
+
let nextProps = scope[index], prevProps = scope[index + "-"], node = scope[nodeIndex];
|
|
311
|
+
if (prevProps)
|
|
312
|
+
for (let name in prevProps)
|
|
313
|
+
name in nextProps || (node[name] = void 0);
|
|
314
|
+
for (let name in nextProps)
|
|
315
|
+
node[name] = nextProps[name];
|
|
316
|
+
scope[index + "-"] = nextProps;
|
|
317
|
+
}
|
|
318
|
+
function normalizeAttrValue(value2) {
|
|
319
|
+
if (value2 || value2 === 0)
|
|
320
|
+
return value2 === !0 ? "" : value2 + "";
|
|
321
|
+
}
|
|
322
|
+
function normalizeString(value2) {
|
|
323
|
+
return value2 || value2 === 0 ? value2 + "" : "\u200D";
|
|
324
|
+
}
|
|
325
|
+
function lifecycle(scope, index, thisObj) {
|
|
326
|
+
let instance = scope[index];
|
|
327
|
+
instance ? (Object.assign(instance, thisObj), instance.onUpdate?.()) : (scope[index] = thisObj, thisObj.onMount?.(), getAbortSignal(
|
|
328
|
+
scope,
|
|
329
|
+
"-" /* LifecycleAbortController */ + index
|
|
330
|
+
).onabort = () => thisObj.onDestroy?.());
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// src/dom/walker.ts
|
|
334
|
+
var walker = /* @__PURE__ */ document.createTreeWalker(document);
|
|
335
|
+
function trimWalkString(walkString) {
|
|
336
|
+
let end = walkString.length;
|
|
337
|
+
for (; walkString.charCodeAt(--end) > 47 /* BeginChild */; )
|
|
338
|
+
;
|
|
339
|
+
return walkString.slice(0, end + 1);
|
|
340
|
+
}
|
|
341
|
+
function walk(startNode, walkCodes, scope) {
|
|
342
|
+
walker.currentNode = startNode, walkInternal(walkCodes, scope, 0), walker.currentNode = document.documentElement;
|
|
343
|
+
}
|
|
344
|
+
function walkInternal(walkCodes, scope, currentWalkIndex) {
|
|
345
|
+
let value2, storedMultiplier = 0, currentMultiplier = 0, currentScopeIndex = 0;
|
|
346
|
+
for (; value2 = walkCodes.charCodeAt(currentWalkIndex++); )
|
|
347
|
+
if (currentMultiplier = storedMultiplier, storedMultiplier = 0, value2 >= 117 /* Multiplier */)
|
|
348
|
+
storedMultiplier = currentMultiplier * 10 /* Multiplier */ + value2 - 117 /* Multiplier */;
|
|
349
|
+
else if (value2 >= 107 /* Out */) {
|
|
350
|
+
for (value2 = 10 /* Out */ * currentMultiplier + value2 - 107 /* Out */; value2--; )
|
|
351
|
+
walker.parentNode();
|
|
352
|
+
walker.nextSibling();
|
|
353
|
+
} else if (value2 >= 97 /* Over */)
|
|
354
|
+
for (value2 = 10 /* Over */ * currentMultiplier + value2 - 97 /* Over */; value2--; )
|
|
355
|
+
!walker.nextSibling() && walker.nextNode();
|
|
356
|
+
else if (value2 >= 67 /* Next */)
|
|
357
|
+
for (value2 = 20 /* Next */ * currentMultiplier + value2 - 67 /* Next */; value2--; )
|
|
358
|
+
walker.nextNode();
|
|
359
|
+
else if (value2 === 47 /* BeginChild */)
|
|
360
|
+
currentWalkIndex = walkInternal(
|
|
361
|
+
walkCodes,
|
|
362
|
+
scope[currentScopeIndex++] = createScope(scope.$global),
|
|
363
|
+
currentWalkIndex
|
|
364
|
+
);
|
|
365
|
+
else {
|
|
366
|
+
if (value2 === 38 /* EndChild */)
|
|
367
|
+
return currentWalkIndex;
|
|
368
|
+
if (value2 === 32 /* Get */)
|
|
369
|
+
scope[currentScopeIndex++] = walker.currentNode;
|
|
370
|
+
else {
|
|
371
|
+
let newNode = scope[currentScopeIndex++] = document.createTextNode(""), current = walker.currentNode, parentNode = current.parentNode;
|
|
372
|
+
value2 === 33 /* Before */ ? parentNode.insertBefore(newNode, current) : (value2 === 35 /* After */ ? parentNode.insertBefore(newNode, current.nextSibling) : parentNode.replaceChild(newNode, current), walker.currentNode = newNode);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return currentWalkIndex;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// src/dom/renderer.ts
|
|
379
|
+
function createScopeWithRenderer(renderer, $global, ownerScope) {
|
|
380
|
+
let newScope = createScope($global);
|
|
381
|
+
if (newScope._ = renderer.i || ownerScope, newScope.p = renderer, initRenderer(renderer, newScope), renderer.b)
|
|
382
|
+
for (let signal of renderer.b)
|
|
383
|
+
signal.e?.(newScope);
|
|
384
|
+
return newScope;
|
|
385
|
+
}
|
|
386
|
+
function initRenderer(renderer, scope) {
|
|
387
|
+
let dom = typeof renderer == "string" ? document.createElement(renderer) : renderer.q();
|
|
388
|
+
return walk(
|
|
389
|
+
dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom,
|
|
390
|
+
renderer.k ?? " ",
|
|
391
|
+
scope
|
|
392
|
+
), scope.a = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom, scope.c = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom, renderer.l && renderer.l(scope), dom;
|
|
393
|
+
}
|
|
394
|
+
function dynamicTagAttrs(nodeAccessor, renderBody, inputIsArgs) {
|
|
395
|
+
return (scope, getAttrs, clean) => {
|
|
396
|
+
let renderer = scope[nodeAccessor + "(" /* ConditionalRenderer */];
|
|
397
|
+
if (!renderer || renderer === renderBody || clean && !renderer.d)
|
|
398
|
+
return;
|
|
399
|
+
let childScope = scope[nodeAccessor + "!" /* ConditionalScope */];
|
|
400
|
+
if (typeof renderer == "string")
|
|
401
|
+
attrs(childScope, 0, getAttrs()), setConditionalRendererOnlyChild(
|
|
402
|
+
childScope,
|
|
403
|
+
0,
|
|
404
|
+
renderBody && bindRenderer(scope, renderBody)
|
|
405
|
+
);
|
|
406
|
+
else if (renderer.d)
|
|
407
|
+
if (clean)
|
|
408
|
+
renderer.d(childScope, null, clean);
|
|
409
|
+
else {
|
|
410
|
+
let attributes = getAttrs();
|
|
411
|
+
renderer.d(
|
|
412
|
+
childScope,
|
|
413
|
+
inputIsArgs ? attributes : [
|
|
414
|
+
renderBody ? {
|
|
415
|
+
...attributes,
|
|
416
|
+
renderBody: bindRenderer(scope, renderBody)
|
|
417
|
+
} : attributes
|
|
418
|
+
],
|
|
419
|
+
clean
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
function createRenderer(template, walks, setup, closureSignals, hasUserEffects = 0, args) {
|
|
425
|
+
return {
|
|
426
|
+
m: template,
|
|
427
|
+
k: walks && /* @__PURE__ */ trimWalkString(walks),
|
|
428
|
+
l: setup,
|
|
429
|
+
q: _clone,
|
|
430
|
+
b: new Set(closureSignals),
|
|
431
|
+
r: hasUserEffects,
|
|
432
|
+
n: void 0,
|
|
433
|
+
d: args,
|
|
434
|
+
i: void 0
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
function _clone() {
|
|
438
|
+
let sourceNode = this.n;
|
|
439
|
+
if (!sourceNode) {
|
|
440
|
+
let walks = this.k, ensureFragment = walks && walks.length < 4 && walks.charCodeAt(walks.length - 1) !== 32 /* Get */;
|
|
441
|
+
this.n = sourceNode = parse(
|
|
442
|
+
this.m,
|
|
443
|
+
ensureFragment
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
return sourceNode.cloneNode(!0);
|
|
447
|
+
}
|
|
448
|
+
var doc2 = document, parser2 = /* @__PURE__ */ doc2.createElement("template");
|
|
449
|
+
function parse(template, ensureFragment) {
|
|
450
|
+
let node;
|
|
451
|
+
parser2.innerHTML = template;
|
|
452
|
+
let content = parser2.content;
|
|
453
|
+
return ensureFragment || (node = content.firstChild) !== content.lastChild || node && node.nodeType === 8 /* Comment */ ? (node = doc2.createDocumentFragment(), node.appendChild(content)) : node || (node = doc2.createTextNode("")), node;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// src/dom/signals.ts
|
|
457
|
+
function initValue(valueAccessor, fn) {
|
|
458
|
+
let markAccessor = valueAccessor + "#" /* Mark */;
|
|
459
|
+
return (scope, nextValue, clean) => {
|
|
460
|
+
clean !== 1 && scope[markAccessor] === void 0 && fn(scope, nextValue, clean);
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function value(valueAccessor, render, intersection2, valueWithIntersection) {
|
|
464
|
+
let markAccessor = valueAccessor + "#" /* Mark */;
|
|
465
|
+
return (scope, nextValue, clean) => {
|
|
466
|
+
let creation, currentMark;
|
|
467
|
+
clean === 1 ? currentMark = scope[markAccessor] = (scope[markAccessor] ?? 0) + 1 : (creation = scope[markAccessor] === void 0, currentMark = scope[markAccessor] ||= 1), currentMark === 1 && (clean !== 1 && (creation || !(clean ||= scope[valueAccessor] === nextValue)) ? (scope[valueAccessor] = nextValue, render?.(scope, nextValue)) : valueWithIntersection?.(scope, 0, clean), intersection2?.(scope, clean)), clean !== 1 && scope[markAccessor]--;
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
var accessorId = 0;
|
|
471
|
+
function intersection(count, fn, intersection2, valueWithIntersection) {
|
|
472
|
+
let cleanAccessor = "?" /* Dynamic */ + accessorId++, markAccessor = cleanAccessor + "#" /* Mark */;
|
|
473
|
+
return (scope, clean) => {
|
|
474
|
+
let currentMark;
|
|
475
|
+
clean === 1 ? currentMark = scope[markAccessor] = (scope[markAccessor] ?? 0) + 1 : scope[markAccessor] === void 0 ? (scope[markAccessor] = count - 1, clean = void 0) : (currentMark = scope[markAccessor]--, clean = scope[cleanAccessor] &&= clean), currentMark === 1 && (clean ? valueWithIntersection?.(scope, 0, clean) : (scope[cleanAccessor] = !0, fn(scope, clean)), intersection2?.(scope, clean));
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
var defaultGetOwnerScope = (scope) => scope._;
|
|
479
|
+
function closure(ownerValueAccessor, fn, _getOwnerScope, intersection2, valueWithIntersection) {
|
|
480
|
+
let cleanAccessor = "?" /* Dynamic */ + accessorId++, markAccessor = cleanAccessor + 1, getOwnerScope = _getOwnerScope || defaultGetOwnerScope, getOwnerValueAccessor = typeof ownerValueAccessor == "function" ? ownerValueAccessor : () => ownerValueAccessor;
|
|
481
|
+
return (scope, clean) => {
|
|
482
|
+
let ownerScope, ownerValueAccessor2, currentMark;
|
|
483
|
+
if (clean === 1)
|
|
484
|
+
currentMark = scope[markAccessor] = (scope[markAccessor] ?? 0) + 1;
|
|
485
|
+
else if (scope[markAccessor] === void 0) {
|
|
486
|
+
ownerScope = getOwnerScope(scope), ownerValueAccessor2 = getOwnerValueAccessor(scope);
|
|
487
|
+
let ownerMark = ownerScope[ownerValueAccessor2 + "#" /* Mark */], ownerHasRun = ownerMark === void 0 ? !ownerScope.o : ownerMark === 0;
|
|
488
|
+
scope[markAccessor] = (currentMark = ownerHasRun ? 1 : 2) - 1, clean = void 0;
|
|
489
|
+
} else
|
|
490
|
+
currentMark = scope[markAccessor]--, clean = scope[cleanAccessor] &&= clean;
|
|
491
|
+
currentMark === 1 && (clean ? valueWithIntersection?.(scope, 0, clean) : (scope[cleanAccessor] = !1, ownerScope ??= getOwnerScope(scope), ownerValueAccessor2 ??= getOwnerValueAccessor(scope), fn?.(scope, ownerScope[ownerValueAccessor2])), intersection2?.(scope, clean));
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
function dynamicClosure(ownerValueAccessor, fn, _getOwnerScope, intersection2, valueWithIntersection) {
|
|
495
|
+
let getOwnerScope = _getOwnerScope || defaultGetOwnerScope, getOwnerValueAccessor = typeof ownerValueAccessor == "function" ? ownerValueAccessor : () => ownerValueAccessor, signalFn = closure(
|
|
496
|
+
getOwnerValueAccessor,
|
|
497
|
+
fn,
|
|
498
|
+
getOwnerScope,
|
|
499
|
+
intersection2,
|
|
500
|
+
valueWithIntersection
|
|
501
|
+
);
|
|
502
|
+
return Object.assign(signalFn, {
|
|
503
|
+
e(scope) {
|
|
504
|
+
let ownerScope = getOwnerScope(scope), providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
|
|
505
|
+
ownerScope[providerSubscriptionsAccessor] ??= /* @__PURE__ */ new Set(), ownerScope[providerSubscriptionsAccessor].add(
|
|
506
|
+
bindFunction(scope, signalFn)
|
|
507
|
+
);
|
|
508
|
+
},
|
|
509
|
+
g(scope) {
|
|
510
|
+
let ownerScope = getOwnerScope(scope), providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
|
|
511
|
+
ownerScope[providerSubscriptionsAccessor]?.delete(
|
|
512
|
+
bindFunction(scope, signalFn)
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
function childClosures(closureSignals, childAccessor) {
|
|
518
|
+
return Object.assign((scope, clean) => {
|
|
519
|
+
let childScope = scope[childAccessor];
|
|
520
|
+
for (let closureSignal of closureSignals)
|
|
521
|
+
closureSignal(childScope, clean);
|
|
522
|
+
}, {
|
|
523
|
+
e(scope) {
|
|
524
|
+
let childScope = scope[childAccessor];
|
|
525
|
+
for (let closureSignal of closureSignals)
|
|
526
|
+
closureSignal.e?.(childScope);
|
|
527
|
+
},
|
|
528
|
+
g(scope) {
|
|
529
|
+
let childScope = scope[childAccessor];
|
|
530
|
+
for (let closureSignal of closureSignals)
|
|
531
|
+
closureSignal.g?.(childScope);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
function dynamicSubscribers(valueAccessor) {
|
|
536
|
+
let subscribersAccessor = valueAccessor + "*" /* Subscribers */;
|
|
537
|
+
return (scope, clean) => {
|
|
538
|
+
let subscribers = scope[subscribersAccessor];
|
|
539
|
+
if (subscribers)
|
|
540
|
+
for (let subscriber of subscribers)
|
|
541
|
+
subscriber(clean);
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
function setTagVar(scope, childAccessor, tagVarSignal2) {
|
|
545
|
+
scope[childAccessor]["/" /* TagVariable */] = bindFunction(
|
|
546
|
+
scope,
|
|
547
|
+
tagVarSignal2
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
var tagVarSignal = (scope, value2, clean) => scope["/" /* TagVariable */]?.(value2, clean), renderBodyClosures = (renderBody, childScope, clean) => {
|
|
551
|
+
let signals = renderBody?.b;
|
|
552
|
+
if (signals)
|
|
553
|
+
for (let signal of signals)
|
|
554
|
+
signal(childScope, clean);
|
|
555
|
+
};
|
|
556
|
+
var tagId = 0;
|
|
557
|
+
function nextTagId() {
|
|
558
|
+
return "c" + tagId++;
|
|
559
|
+
}
|
|
560
|
+
function inChild(childAccessor, signal) {
|
|
561
|
+
return (scope, _, clean) => {
|
|
562
|
+
signal(scope[childAccessor], _, clean);
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
function intersections(signals) {
|
|
566
|
+
return (scope, clean) => {
|
|
567
|
+
for (let signal of signals)
|
|
568
|
+
signal(scope, clean);
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
function values(signals) {
|
|
572
|
+
return (scope, _, clean) => {
|
|
573
|
+
for (let signal of signals)
|
|
574
|
+
signal(scope, _, clean);
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// src/dom/control-flow.ts
|
|
579
|
+
function patchConditionals(fn) {
|
|
580
|
+
conditional = fn(conditional), conditionalOnlyChild = fn(conditionalOnlyChild);
|
|
581
|
+
}
|
|
582
|
+
var conditional = function(nodeAccessor, dynamicTagAttrs2, intersection2, valueWithIntersection) {
|
|
583
|
+
let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
|
|
584
|
+
return (scope, newRenderer, clean) => {
|
|
585
|
+
newRenderer = newRenderer ? newRenderer._ || newRenderer : void 0;
|
|
586
|
+
let currentRenderer = scope[rendererAccessor];
|
|
587
|
+
!clean && !(clean = currentRenderer === newRenderer) ? (currentRenderer = scope[rendererAccessor] = newRenderer, setConditionalRenderer(scope, nodeAccessor, newRenderer), dynamicTagAttrs2?.(scope)) : valueWithIntersection?.(scope, 0, clean), intersection2?.(scope, clean), renderBodyClosures(currentRenderer, scope[childScopeAccessor], clean);
|
|
588
|
+
};
|
|
589
|
+
};
|
|
590
|
+
function inConditionalScope(signal, nodeAccessor) {
|
|
591
|
+
let scopeAccessor = nodeAccessor + "!" /* ConditionalScope */, rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
|
|
592
|
+
return (scope, clean) => {
|
|
593
|
+
let conditionalScope = scope[scopeAccessor];
|
|
594
|
+
if (conditionalScope) {
|
|
595
|
+
let conditionalRenderer = scope[rendererAccessor];
|
|
596
|
+
(!conditionalRenderer?.b || conditionalRenderer.b.has(signal)) && signal(conditionalScope, clean);
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
|
|
601
|
+
let newScope, prevScope = scope[nodeAccessor + "!" /* ConditionalScope */];
|
|
602
|
+
newRenderer ? (newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithRenderer(newRenderer, scope.$global, scope), prevScope = prevScope || getEmptyScope(scope[nodeAccessor])) : (newScope = getEmptyScope(scope[nodeAccessor]), scope[nodeAccessor + "!" /* ConditionalScope */] = void 0), insertBefore(
|
|
603
|
+
newScope,
|
|
604
|
+
prevScope.a.parentNode,
|
|
605
|
+
prevScope.a
|
|
606
|
+
), removeAndDestroyScope(prevScope);
|
|
607
|
+
}
|
|
608
|
+
var conditionalOnlyChild = function(nodeAccessor, action) {
|
|
609
|
+
let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
|
|
610
|
+
return (scope, newRenderer, clean) => {
|
|
611
|
+
let currentRenderer = scope[rendererAccessor];
|
|
612
|
+
!clean && currentRenderer !== newRenderer && (currentRenderer = scope[rendererAccessor] = newRenderer, setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer)), renderBodyClosures(currentRenderer, scope[childScopeAccessor], clean), action?.(scope, currentRenderer, clean);
|
|
613
|
+
};
|
|
614
|
+
};
|
|
615
|
+
function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
|
|
616
|
+
let prevScope = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor];
|
|
617
|
+
if (referenceNode.textContent = "", newRenderer) {
|
|
618
|
+
let newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithRenderer(newRenderer, scope.$global, scope);
|
|
619
|
+
insertBefore(newScope, referenceNode, null);
|
|
620
|
+
}
|
|
621
|
+
prevScope && destroyScope(prevScope);
|
|
622
|
+
}
|
|
623
|
+
var emptyMarkerMap = (/* @__PURE__ */ new Map()).set(Symbol("empty"), getEmptyScope(void 0)), emptyMarkerArray = [
|
|
624
|
+
/* @__PURE__ */ getEmptyScope(void 0)
|
|
625
|
+
], emptyMap = /* @__PURE__ */ new Map(), emptyArray = [];
|
|
626
|
+
function loopOf(nodeAccessor, renderer) {
|
|
627
|
+
return loop(nodeAccessor, renderer, (value2, cb) => {
|
|
628
|
+
let [all, getKey = keyBySecondArg] = value2, i = 0;
|
|
629
|
+
for (let item of all)
|
|
630
|
+
cb(getKey(item, i), [item, i, all]), i++;
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
function loopIn(nodeAccessor, renderer) {
|
|
634
|
+
return loop(nodeAccessor, renderer, (value2, cb) => {
|
|
635
|
+
let [all, getKey = keyByFirstArg] = value2;
|
|
636
|
+
for (let key in all) {
|
|
637
|
+
let v = all[key];
|
|
638
|
+
cb(getKey(key, v), [key, v, all]);
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
function loopTo(nodeAccessor, renderer) {
|
|
643
|
+
return loop(nodeAccessor, renderer, (value2, cb) => {
|
|
644
|
+
let [to, from = 0, step = 1, getKey = keyByFirstArg] = value2, steps = (to - from) / step;
|
|
645
|
+
for (let i = 0; i <= steps; i++) {
|
|
646
|
+
let v = from + i * step;
|
|
647
|
+
cb(getKey(v), [v]);
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
function loop(nodeAccessor, renderer, forEach) {
|
|
652
|
+
let loopScopeAccessor = nodeAccessor + "!" /* LoopScopeArray */, closureSignals = renderer.b, params = renderer.d;
|
|
653
|
+
return (scope, value2, clean) => {
|
|
654
|
+
if (clean) {
|
|
655
|
+
for (let childScope of scope[loopScopeAccessor]) {
|
|
656
|
+
params?.(childScope, null, clean);
|
|
657
|
+
for (let signal of closureSignals)
|
|
658
|
+
signal(childScope, clean);
|
|
659
|
+
}
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
let referenceNode = scope[nodeAccessor], referenceIsMarker = referenceNode.nodeType === 8 || referenceNode.nodeType === 3, oldMap = scope[nodeAccessor + "(" /* LoopScopeMap */] || (referenceIsMarker ? emptyMarkerMap : emptyMap), oldArray = scope[nodeAccessor + "!" /* LoopScopeArray */] || Array.from(oldMap.values()), newMap, newArray, afterReference, parentNode, needsReconciliation = !0;
|
|
663
|
+
if (forEach(value2, (key, args) => {
|
|
664
|
+
let childScope = oldMap.get(key), isNew = !childScope;
|
|
665
|
+
if (childScope || (childScope = createScopeWithRenderer(renderer, scope.$global, scope)), params && params(childScope, args), closureSignals)
|
|
666
|
+
for (let signal of closureSignals)
|
|
667
|
+
signal(childScope, isNew);
|
|
668
|
+
newMap ? (newMap.set(key, childScope), newArray.push(childScope)) : (newMap = /* @__PURE__ */ new Map([[key, childScope]]), newArray = [childScope]);
|
|
669
|
+
}), !newMap)
|
|
670
|
+
if (referenceIsMarker)
|
|
671
|
+
newMap = emptyMarkerMap, newArray = emptyMarkerArray, getEmptyScope(referenceNode);
|
|
672
|
+
else {
|
|
673
|
+
if (renderer.r)
|
|
674
|
+
for (let i = 0; i < oldArray.length; i++)
|
|
675
|
+
destroyScope(oldArray[i]);
|
|
676
|
+
referenceNode.textContent = "", newMap = emptyMap, newArray = emptyArray, needsReconciliation = !1;
|
|
677
|
+
}
|
|
678
|
+
if (needsReconciliation) {
|
|
679
|
+
if (referenceIsMarker) {
|
|
680
|
+
oldMap === emptyMarkerMap && getEmptyScope(referenceNode);
|
|
681
|
+
let oldLastChild = oldArray[oldArray.length - 1];
|
|
682
|
+
afterReference = oldLastChild.c.nextSibling, parentNode = oldLastChild.a.parentNode;
|
|
683
|
+
} else
|
|
684
|
+
afterReference = null, parentNode = referenceNode;
|
|
685
|
+
reconcile(parentNode, oldArray, newArray, afterReference);
|
|
686
|
+
}
|
|
687
|
+
scope[nodeAccessor + "(" /* LoopScopeMap */] = newMap, scope[nodeAccessor + "!" /* LoopScopeArray */] = newArray;
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
function inLoopScope(signal, loopNodeAccessor) {
|
|
691
|
+
let loopScopeAccessor = loopNodeAccessor + "!" /* LoopScopeArray */;
|
|
692
|
+
return (scope, clean) => {
|
|
693
|
+
let loopScopes = scope[loopScopeAccessor] ?? scope[loopNodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
|
|
694
|
+
for (let scope2 of loopScopes)
|
|
695
|
+
signal(scope2, clean);
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
function keyBySecondArg(_item, index) {
|
|
699
|
+
return index;
|
|
700
|
+
}
|
|
701
|
+
function keyByFirstArg(name) {
|
|
702
|
+
return name;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// src/dom/event.ts
|
|
706
|
+
var elementHandlersByEvent = /* @__PURE__ */ new Map(), delegatedEventsByRoot = /* @__PURE__ */ new WeakMap(), eventOpts = { capture: !0 };
|
|
707
|
+
function on(element, type, handler) {
|
|
708
|
+
let handlersByElement = elementHandlersByEvent.get(type);
|
|
709
|
+
handlersByElement || elementHandlersByEvent.set(type, handlersByElement = /* @__PURE__ */ new WeakMap()), handlersByElement.has(element) || ensureDelegated(element, type), handlersByElement.set(element, handler || void 0);
|
|
710
|
+
}
|
|
711
|
+
function ensureDelegated(node, type) {
|
|
712
|
+
let root = node.getRootNode(), delegatedEvents = delegatedEventsByRoot.get(root);
|
|
713
|
+
delegatedEvents || delegatedEventsByRoot.set(root, delegatedEvents = /* @__PURE__ */ new Set()), delegatedEvents.has(type) || (delegatedEvents.add(type), root.addEventListener(type, handleDelegated, eventOpts));
|
|
714
|
+
}
|
|
715
|
+
function handleDelegated(ev) {
|
|
716
|
+
let target = ev.target;
|
|
717
|
+
if (target) {
|
|
718
|
+
let handlersByElement = elementHandlersByEvent.get(ev.type);
|
|
719
|
+
if (handlersByElement.get(target)?.(ev, target), ev.bubbles)
|
|
720
|
+
for (; (target = target.parentElement) && !ev.cancelBubble; )
|
|
721
|
+
handlersByElement.get(target)?.(ev, target);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// src/dom/resume.ts
|
|
726
|
+
var registeredObjects = /* @__PURE__ */ new Map(), doc3 = document;
|
|
727
|
+
function register(id, obj) {
|
|
728
|
+
return registeredObjects.set(id, obj), obj;
|
|
729
|
+
}
|
|
730
|
+
function getRegisteredWithScope(registryId, scope) {
|
|
731
|
+
let obj = registeredObjects.get(registryId);
|
|
732
|
+
return scope ? obj.m ? bindRenderer(scope, obj) : bindFunction(scope, obj) : obj;
|
|
733
|
+
}
|
|
734
|
+
var scopeLookup = {};
|
|
735
|
+
function init(runtimeId = "M" /* DefaultRuntimeId */) {
|
|
736
|
+
let runtimeLength = runtimeId.length, resumeVar = runtimeId + "$h" /* VarResume */, initialHydration = window[resumeVar], walker2 = doc3.createTreeWalker(
|
|
737
|
+
doc3,
|
|
738
|
+
128
|
|
739
|
+
/** NodeFilter.SHOW_COMMENT */
|
|
740
|
+
), currentScopeId, currentNode, getScope = (id) => scopeLookup[id] ?? (scopeLookup[id] = {}), stack = [], fakeArray = { push: resume };
|
|
741
|
+
if (initialHydration)
|
|
742
|
+
for (let i = 0; i < initialHydration.length; i += 2)
|
|
743
|
+
resume(initialHydration[i], initialHydration[i + 1]);
|
|
744
|
+
else
|
|
745
|
+
window[resumeVar] = fakeArray;
|
|
746
|
+
function resume(scopesFn, calls) {
|
|
747
|
+
if (doc3.readyState !== "loading" && (walker2.currentNode = doc3), scopesFn) {
|
|
748
|
+
let scopes = scopesFn(getRegisteredWithScope, scopeLookup);
|
|
749
|
+
scopeLookup.$global ||= scopes.$global || {};
|
|
750
|
+
for (let scopeIdAsString in scopes) {
|
|
751
|
+
if (scopeIdAsString === "$global")
|
|
752
|
+
continue;
|
|
753
|
+
let scopeId = parseInt(scopeIdAsString), scope = scopes[scopeId], storedScope = scopeLookup[scopeId];
|
|
754
|
+
scope.$global = scopes.$global, storedScope !== scope && (scopeLookup[scopeId] = Object.assign(scope, storedScope));
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
for (; currentNode = walker2.nextNode(); ) {
|
|
758
|
+
let nodeValue = currentNode.nodeValue;
|
|
759
|
+
if (nodeValue.startsWith(runtimeId)) {
|
|
760
|
+
let token = nodeValue[runtimeLength], scopeId = parseInt(nodeValue.slice(runtimeLength + 1)), scope = getScope(scopeId), data2 = nodeValue.slice(nodeValue.indexOf(" ") + 1);
|
|
761
|
+
if (token === "*" /* Node */)
|
|
762
|
+
scope[data2] = currentNode.previousSibling;
|
|
763
|
+
else if (token === "[" /* SectionStart */)
|
|
764
|
+
stack.push(currentScopeId), currentScopeId = scopeId, scope.a = currentNode;
|
|
765
|
+
else if (token === "]" /* SectionEnd */) {
|
|
766
|
+
if (scope[data2] = currentNode, scopeId < currentScopeId) {
|
|
767
|
+
let currScope = scopeLookup[currentScopeId], currParent = currentNode.parentNode, startNode = currScope.a;
|
|
768
|
+
currParent !== startNode.parentNode && currParent.prepend(startNode), currScope.c = currentNode.previousSibling, currentScopeId = stack.pop();
|
|
769
|
+
}
|
|
770
|
+
} else if (token === "|" /* SectionSingleNodesEnd */) {
|
|
771
|
+
scope[parseInt(data2)] = currentNode;
|
|
772
|
+
let childScopeIds = JSON.parse(
|
|
773
|
+
"[" + data2.slice(data2.indexOf(" ") + 1) + "]"
|
|
774
|
+
);
|
|
775
|
+
for (let i = childScopeIds.length - 1; i >= 0; i--) {
|
|
776
|
+
let childScope = getScope(childScopeIds[i]);
|
|
777
|
+
for (; (currentNode = currentNode.previousSibling).nodeType === 8; )
|
|
778
|
+
;
|
|
779
|
+
childScope.a = childScope.c = currentNode;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
for (let i = 0; i < calls.length; i += 2)
|
|
785
|
+
registeredObjects.get(calls[i + 1])(
|
|
786
|
+
scopeLookup[calls[i]]
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
function registerSubscriber(id, signal) {
|
|
791
|
+
return register(id, signal.e), signal;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// src/dom/schedule.ts
|
|
795
|
+
var port2 = /* @__PURE__ */ (() => {
|
|
796
|
+
let { port1, port2: port22 } = new MessageChannel();
|
|
797
|
+
return port1.onmessage = () => {
|
|
798
|
+
isScheduled = !1, run();
|
|
799
|
+
}, port22;
|
|
800
|
+
})(), isScheduled;
|
|
801
|
+
function schedule() {
|
|
802
|
+
isScheduled || (isScheduled = !0, queueMicrotask(flushAndWaitFrame));
|
|
803
|
+
}
|
|
804
|
+
function flushAndWaitFrame() {
|
|
805
|
+
run(), requestAnimationFrame(triggerMacroTask);
|
|
806
|
+
}
|
|
807
|
+
function triggerMacroTask() {
|
|
808
|
+
port2.postMessage(0);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// src/dom/queue.ts
|
|
812
|
+
var currentBatch = [], currentEffects = [];
|
|
813
|
+
function queueSource(scope, signal, value2) {
|
|
814
|
+
return schedule(), signal(scope, 0, 1), currentBatch.push(scope, signal, value2), value2;
|
|
815
|
+
}
|
|
816
|
+
function queueEffect(scope, fn) {
|
|
817
|
+
currentEffects.push(scope, fn);
|
|
818
|
+
}
|
|
819
|
+
function run() {
|
|
820
|
+
try {
|
|
821
|
+
runBatch();
|
|
822
|
+
} finally {
|
|
823
|
+
currentBatch = [];
|
|
824
|
+
}
|
|
825
|
+
try {
|
|
826
|
+
runEffects();
|
|
827
|
+
} finally {
|
|
828
|
+
currentEffects = [];
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
function runSync(fn) {
|
|
832
|
+
let prevBatch = currentBatch, prevEffects = currentEffects;
|
|
833
|
+
currentBatch = [], currentEffects = [];
|
|
834
|
+
try {
|
|
835
|
+
fn(), runBatch(), currentBatch = prevBatch, runEffects();
|
|
836
|
+
} finally {
|
|
837
|
+
currentBatch = prevBatch, currentEffects = prevEffects;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
function prepare(fn) {
|
|
841
|
+
let prevBatch = currentBatch, prevEffects = currentEffects, preparedEffects = currentEffects = [];
|
|
842
|
+
currentBatch = [];
|
|
843
|
+
try {
|
|
844
|
+
fn(), runBatch();
|
|
845
|
+
} finally {
|
|
846
|
+
currentBatch = prevBatch, currentEffects = prevEffects;
|
|
847
|
+
}
|
|
848
|
+
return preparedEffects;
|
|
849
|
+
}
|
|
850
|
+
function runEffects(effects = currentEffects) {
|
|
851
|
+
for (let i = 0; i < effects.length; i += 2 /* Total */) {
|
|
852
|
+
let scope = effects[i], fn = effects[i + 1];
|
|
853
|
+
fn(scope);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
function runBatch() {
|
|
857
|
+
for (let i = 0; i < currentBatch.length; i += 3 /* Total */) {
|
|
858
|
+
let scope = currentBatch[i + 0 /* Scope */], signal = currentBatch[i + 1 /* Signal */], value2 = currentBatch[i + 2 /* Value */];
|
|
859
|
+
signal(scope, value2);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// src/dom/template.ts
|
|
864
|
+
var createTemplate = (renderer, templateId) => register(templateId, new ClientTemplate(renderer)), ClientTemplate = class {
|
|
865
|
+
_;
|
|
866
|
+
constructor(renderer) {
|
|
867
|
+
this._ = renderer;
|
|
868
|
+
}
|
|
869
|
+
mount(templateInput = {}, reference, position) {
|
|
870
|
+
let scope, dom, { $global = {}, ...input } = templateInput, args = this._.d, effects = prepare(() => {
|
|
871
|
+
scope = createScope($global), dom = initRenderer(this._, scope), args && args(scope, [input]);
|
|
872
|
+
});
|
|
873
|
+
switch (position) {
|
|
874
|
+
case "afterbegin":
|
|
875
|
+
reference.insertBefore(dom, reference.firstChild);
|
|
876
|
+
break;
|
|
877
|
+
case "afterend":
|
|
878
|
+
reference.parentElement.insertBefore(dom, reference.nextSibling);
|
|
879
|
+
break;
|
|
880
|
+
case "beforebegin":
|
|
881
|
+
reference.parentElement.insertBefore(dom, reference);
|
|
882
|
+
break;
|
|
883
|
+
default:
|
|
884
|
+
reference.appendChild(dom);
|
|
885
|
+
break;
|
|
886
|
+
}
|
|
887
|
+
return runEffects(effects), {
|
|
888
|
+
update: (newInput) => {
|
|
889
|
+
args && runSync(() => {
|
|
890
|
+
args(scope, null, 1), args(scope, [newInput]);
|
|
891
|
+
});
|
|
892
|
+
},
|
|
893
|
+
destroy: () => {
|
|
894
|
+
removeAndDestroyScope(scope);
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
render() {
|
|
899
|
+
throw new Error(
|
|
900
|
+
"render() is not implemented for the DOM compilation of a Marko template"
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
//# sourceMappingURL=dom.js.map
|