marko 6.0.0-next.3.22 → 6.0.0-next.3.23

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/dom.mjs CHANGED
@@ -45,346 +45,46 @@ function triggerMacroTask() {
45
45
  port2.postMessage(0);
46
46
  }
47
47
 
48
- // src/common/meta.ts
49
- var DEFAULT_RUNTIME_ID = "M", DEFAULT_RENDER_ID = "_";
50
-
51
48
  // src/dom/scope.ts
49
+ var pendingScopes = [];
52
50
  function createScope($global) {
53
- return {
54
- u: 1,
51
+ let scope = {
52
+ g: 1,
55
53
  $global
56
54
  };
55
+ return pendingScopes.push(scope), scope;
56
+ }
57
+ function finishPendingScopes() {
58
+ for (let scope of pendingScopes)
59
+ scope.g = 0;
60
+ pendingScopes = [];
57
61
  }
58
62
  var emptyScope = createScope({});
59
63
  function getEmptyScope(marker) {
60
- return emptyScope.a = emptyScope.b = marker, emptyScope;
61
- }
62
- function destroyScope(scope) {
63
- _destroyScope(scope), scope.d?.h?.delete(scope);
64
- let closureSignals = scope.x?.c;
65
- if (closureSignals)
66
- for (let signal of closureSignals)
67
- signal.j?.(scope);
68
- return scope;
69
- }
70
- function _destroyScope(scope) {
71
- scope.h?.forEach(_destroyScope);
72
- let controllers = scope.l;
73
- if (controllers)
74
- for (let ctrl of controllers.values())
75
- ctrl.abort();
76
- }
77
- function onDestroy(scope) {
78
- let parentScope = scope.d;
79
- for (; parentScope && !parentScope.h?.has(scope); )
80
- (parentScope.h ||= /* @__PURE__ */ new Set()).add(scope), scope = parentScope, parentScope = scope.d;
81
- }
82
- function removeAndDestroyScope(scope) {
83
- destroyScope(scope);
84
- let current = scope.a, stop = scope.b.nextSibling;
64
+ return emptyScope.a = emptyScope.c = marker, emptyScope;
65
+ }
66
+ function destroyBranch(branch) {
67
+ if (branch.y = 1, branch.m?.forEach(destroyBranch), branch.n)
68
+ for (let scope of branch.n)
69
+ for (let id in scope.h)
70
+ scope.h[id]?.abort();
71
+ }
72
+ function removeAndDestroyBranch(branch) {
73
+ destroyBranch(branch);
74
+ let current = branch.a, stop = branch.c.nextSibling;
85
75
  for (; current !== stop; ) {
86
76
  let next = current.nextSibling;
87
77
  current.remove(), current = next;
88
78
  }
89
79
  }
90
80
  function insertBefore(scope, parent, nextSibling) {
91
- let current = scope.a, stop = scope.b.nextSibling;
81
+ let current = scope.a, stop = scope.c.nextSibling;
92
82
  for (; current !== stop; ) {
93
83
  let next = current.nextSibling;
94
84
  parent.insertBefore(current, nextSibling), current = next;
95
85
  }
96
86
  }
97
87
 
98
- // src/dom/resume.ts
99
- var registeredValues = {}, Render = class {
100
- m = [];
101
- n = {};
102
- y = {
103
- _: registeredValues
104
- };
105
- constructor(renders, runtimeId, renderId) {
106
- this.z = renders, this.A = runtimeId, this.o = renderId, this.p = renders[renderId], this.q();
107
- }
108
- w() {
109
- this.p.w(), this.q();
110
- }
111
- q() {
112
- let data2 = this.p, serializeContext = this.y, scopeLookup = this.n, visits = data2.v, cleanupOwners = /* @__PURE__ */ new Map();
113
- if (visits.length) {
114
- let commentPrefixLen = data2.i.length, cleanupMarkers = /* @__PURE__ */ new Map();
115
- data2.v = [];
116
- let sectionEnd = (visit, scopeId = this.f, curNode = visit) => {
117
- let scope = scopeLookup[scopeId] ||= {}, endNode = curNode;
118
- for (; (endNode = endNode.previousSibling).nodeType === 8; ) ;
119
- scope.b = endNode;
120
- let startNode = scope.a ||= endNode, len = cleanupMarkers.size;
121
- for (let [markerScopeId, markerNode] of cleanupMarkers) {
122
- if (!len--) break;
123
- markerScopeId !== scopeId && startNode.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2 && (cleanupOwners.set("" + markerScopeId, scopeId), cleanupMarkers.delete(markerScopeId));
124
- }
125
- return cleanupMarkers.set(scopeId, visit), scope;
126
- };
127
- for (let visit of visits) {
128
- let commentText = visit.data, token = commentText[commentPrefixLen], scopeId = parseInt(commentText.slice(commentPrefixLen + 1)), scope = scopeLookup[scopeId] ||= {}, dataIndex = commentText.indexOf(" ") + 1, data3 = dataIndex ? commentText.slice(dataIndex) : "";
129
- if (token === "*" /* Node */)
130
- scope[data3] = visit.previousSibling;
131
- else if (token === "$" /* Cleanup */)
132
- cleanupMarkers.set(scopeId, visit);
133
- else if (token === "[" /* SectionStart */)
134
- this.f && (data3 && sectionEnd(visit), this.m.push(this.f)), this.f = scopeId, scope.a = visit;
135
- else if (token === "]" /* SectionEnd */) {
136
- if (scope[data3] = visit, scopeId < this.f) {
137
- let currParent = visit.parentNode, startNode = sectionEnd(visit).a;
138
- currParent && currParent !== startNode.parentNode && currParent.prepend(startNode), this.f = this.m.pop();
139
- }
140
- } else if (token === "|" /* SectionSingleNodesEnd */) {
141
- scope[parseInt(data3)] = visit;
142
- let childScopeIds = JSON.parse(
143
- "[" + data3.slice(data3.indexOf(" ") + 1) + "]"
144
- ), curNode = visit;
145
- for (let i = childScopeIds.length - 1; i >= 0; i--)
146
- curNode = sectionEnd(visit, childScopeIds[i], curNode).b;
147
- }
148
- }
149
- }
150
- let resumes = data2.r;
151
- if (resumes) {
152
- data2.r = [];
153
- let len = resumes.length, i = 0;
154
- try {
155
- for (isResuming = !0; i < len; ) {
156
- let resumeData = resumes[i++];
157
- if (typeof resumeData == "function") {
158
- let scopes = resumeData(serializeContext), { $global } = scopeLookup;
159
- $global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = this.A, $global.renderId = this.o);
160
- for (let scopeId in scopes)
161
- if (scopeId !== "$") {
162
- let scope = scopes[scopeId], prevScope = scopeLookup[scopeId];
163
- scope.$global = $global, prevScope !== scope && (scopeLookup[scopeId] = Object.assign(
164
- scope,
165
- prevScope
166
- ));
167
- let cleanupOwnerId = cleanupOwners.get(scopeId);
168
- cleanupOwnerId && (scope.d = scopes[cleanupOwnerId], onDestroy(scope));
169
- }
170
- } else i === len || typeof resumes[i] != "string" ? delete this.z[this.o] : registeredValues[resumes[i++]](
171
- scopeLookup[resumeData],
172
- scopeLookup[resumeData]
173
- );
174
- }
175
- } finally {
176
- isResuming = !1;
177
- }
178
- }
179
- }
180
- }, isResuming = !1;
181
- function register(id, obj) {
182
- return registeredValues[id] = obj, obj;
183
- }
184
- function registerBoundSignal(id, signal) {
185
- return registeredValues[id] = (scope) => (valueOrOp) => signal(scope, valueOrOp), signal;
186
- }
187
- function getRegisteredWithScope(id, scope) {
188
- let val = registeredValues[id];
189
- return scope ? val(scope) : val;
190
- }
191
- function init(runtimeId = DEFAULT_RUNTIME_ID) {
192
- let resumeRender = (renderId) => resumeRender[renderId] = renders[renderId] = new Render(renders, runtimeId, renderId), renders;
193
- window[runtimeId] ? setRenders(window[runtimeId]) : Object.defineProperty(window, runtimeId, {
194
- configurable: !0,
195
- set: setRenders
196
- });
197
- function setRenders(v) {
198
- renders = v;
199
- for (let renderId in v)
200
- resumeRender(renderId);
201
- Object.defineProperty(window, runtimeId, {
202
- configurable: !0,
203
- value: resumeRender
204
- });
205
- }
206
- }
207
- function registerSubscriber(id, signal) {
208
- return register(id, signal.g), signal;
209
- }
210
- function nodeRef(id, key) {
211
- return register(id, (scope) => () => scope[key]);
212
- }
213
-
214
- // src/dom/signals.ts
215
- var MARK = {}, CLEAN = {}, DIRTY = {};
216
- function state(valueAccessor, fn, getIntersection) {
217
- let valueSignal = value(valueAccessor, fn, getIntersection), markAccessor = valueAccessor + "#" /* Mark */, valueChangeAccessor = valueAccessor + "@" /* TagVariableChange */;
218
- return (scope, valueOrOp, valueChange) => (rendering ? valueSignal(
219
- scope,
220
- valueOrOp === MARK || valueOrOp === CLEAN || valueOrOp === DIRTY || (scope[valueChangeAccessor] = valueChange) || scope[markAccessor] === void 0 ? valueOrOp : CLEAN
221
- ) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](valueOrOp) : queueSource(scope, valueSignal, valueOrOp), valueOrOp);
222
- }
223
- function value(valueAccessor, fn, getIntersection) {
224
- let markAccessor = valueAccessor + "#" /* Mark */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
225
- return (scope, valueOrOp) => {
226
- if (valueOrOp === MARK)
227
- (scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1 && intersection2?.(scope, MARK);
228
- else if (valueOrOp !== DIRTY) {
229
- let existing = scope[markAccessor] !== void 0;
230
- (scope[markAccessor] ||= 1) === 1 && (valueOrOp === CLEAN || existing && scope[valueAccessor] === valueOrOp ? intersection2?.(scope, CLEAN) : (scope[valueAccessor] = valueOrOp, fn && fn(scope, valueOrOp), intersection2?.(scope, DIRTY))), scope[markAccessor]--;
231
- }
232
- };
233
- }
234
- var accessorId = 0;
235
- function intersection(count, fn, getIntersection) {
236
- let dirtyAccessor = "?" /* Dynamic */ + accessorId++, markAccessor = dirtyAccessor + "#" /* Mark */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
237
- return (scope, op) => {
238
- op === MARK ? (scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1 && intersection2?.(scope, MARK) : scope[markAccessor] === void 0 ? (scope[markAccessor] = count - 1, scope[dirtyAccessor] = !0) : --scope[markAccessor] === 0 ? op === DIRTY || scope[dirtyAccessor] ? (scope[dirtyAccessor] = !1, fn(scope, 0), intersection2?.(scope, DIRTY)) : intersection2?.(scope, CLEAN) : scope[dirtyAccessor] ||= op === DIRTY;
239
- };
240
- }
241
- var defaultGetOwnerScope = (scope) => scope._;
242
- function closure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
243
- let dirtyAccessor = "?" /* Dynamic */ + accessorId++, markAccessor = dirtyAccessor + 1, getOwnerValueAccessor = typeof ownerValueAccessor == "function" ? ownerValueAccessor : () => ownerValueAccessor, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
244
- return (scope, op) => {
245
- if (op === MARK)
246
- (scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1 && intersection2?.(scope, MARK);
247
- else {
248
- let ownerScope, ownerValueAccessor2;
249
- if (scope[markAccessor] === void 0) {
250
- ownerScope = getOwnerScope(scope), ownerValueAccessor2 = getOwnerValueAccessor(scope);
251
- let ownerMark = ownerScope[ownerValueAccessor2 + "#" /* Mark */], ownerHasRun = ownerMark === void 0 ? !ownerScope.u : ownerMark === 0;
252
- scope[markAccessor] = ownerHasRun ? 1 : 2, op = DIRTY;
253
- }
254
- --scope[markAccessor] === 0 ? op === DIRTY || scope[dirtyAccessor] ? (scope[dirtyAccessor] = !1, ownerScope ||= getOwnerScope(scope), ownerValueAccessor2 ||= getOwnerValueAccessor(scope), fn && fn(scope, ownerScope[ownerValueAccessor2]), intersection2?.(scope, DIRTY)) : intersection2?.(scope, CLEAN) : scope[dirtyAccessor] ||= op === DIRTY;
255
- }
256
- };
257
- }
258
- function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
259
- let getOwnerValueAccessor = typeof ownerValueAccessor == "function" ? ownerValueAccessor : () => ownerValueAccessor, signalFn = closure(
260
- getOwnerValueAccessor,
261
- fn,
262
- getOwnerScope,
263
- getIntersection
264
- ), subscribeFns = /* @__PURE__ */ new WeakMap();
265
- return signalFn.g = (scope) => {
266
- let subscribeFn = (value2) => signalFn(scope, value2), ownerScope = getOwnerScope(scope), providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
267
- subscribeFns.set(scope, subscribeFn), (ownerScope[providerSubscriptionsAccessor] ||= /* @__PURE__ */ new Set()).add(subscribeFn);
268
- }, signalFn.j = (scope) => {
269
- let ownerScope = getOwnerScope(scope), providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
270
- ownerScope[providerSubscriptionsAccessor]?.delete(subscribeFns.get(scope)), subscribeFns.delete(scope);
271
- }, signalFn;
272
- }
273
- function childClosures(closureSignals, childAccessor) {
274
- let signal = (scope, op) => {
275
- let childScope = scope[childAccessor];
276
- for (let closureSignal of closureSignals)
277
- closureSignal(childScope, op);
278
- };
279
- return signal.g = (scope) => {
280
- let childScope = scope[childAccessor];
281
- for (let closureSignal of closureSignals)
282
- closureSignal.g?.(childScope);
283
- }, signal.j = (scope) => {
284
- let childScope = scope[childAccessor];
285
- for (let closureSignal of closureSignals)
286
- closureSignal.j?.(childScope);
287
- }, signal;
288
- }
289
- function dynamicSubscribers(valueAccessor) {
290
- let subscribersAccessor = valueAccessor + "*" /* Subscribers */;
291
- return (scope, op) => {
292
- let subscribers = scope[subscribersAccessor];
293
- if (subscribers)
294
- for (let subscriber of subscribers)
295
- subscriber(op);
296
- };
297
- }
298
- function setTagVar(scope, childAccessor, tagVarSignal2) {
299
- scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
300
- }
301
- var tagVarSignal = (scope, valueOrOp) => scope["/" /* TagVariable */]?.(valueOrOp);
302
- function setTagVarChange(scope, changeHandler) {
303
- scope["@" /* TagVariableChange */] = changeHandler;
304
- }
305
- var tagVarSignalChange = (scope, value2) => scope["@" /* TagVariableChange */]?.(value2), contentClosures = (content, childScope, op) => {
306
- let signals = content?.c;
307
- if (signals)
308
- for (let signal of signals)
309
- signal(childScope, op);
310
- };
311
- var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
312
- function nextTagId({ $global }) {
313
- let id = tagIdsByGlobal.get($global) || 0;
314
- return tagIdsByGlobal.set($global, id + 1), "c" + $global.runtimeId + $global.renderId + id.toString(36);
315
- }
316
- function inChild(childAccessor, signal) {
317
- return (scope, valueOrOp) => {
318
- signal(scope[childAccessor], valueOrOp);
319
- };
320
- }
321
- function intersections(signals) {
322
- return (scope, op) => {
323
- for (let signal of signals)
324
- signal(scope, op);
325
- };
326
- }
327
- function effect(id, fn) {
328
- return register(id, fn), (scope) => {
329
- queueEffect(scope, fn);
330
- };
331
- }
332
-
333
- // src/dom/queue.ts
334
- var pendingSignals = [], pendingEffects = [], rendering = !1;
335
- function queueSource(scope, signal, value2) {
336
- return schedule(), rendering = !0, signal(scope, MARK), rendering = !1, pendingSignals.push(scope, signal, value2), value2;
337
- }
338
- function queueEffect(scope, fn) {
339
- pendingEffects.push(scope, fn);
340
- }
341
- function run() {
342
- let signals = pendingSignals, effects = pendingEffects;
343
- try {
344
- rendering = !0, pendingSignals = [], runSignals(signals);
345
- } finally {
346
- rendering = !1;
347
- }
348
- pendingEffects = [], runEffects(effects);
349
- }
350
- function prepareEffects(fn) {
351
- let prevSignals = pendingSignals, prevEffects = pendingEffects, preparedEffects = pendingEffects = [], preparedSignals = pendingSignals = [];
352
- try {
353
- rendering = !0, fn(), pendingSignals = prevSignals, runSignals(preparedSignals);
354
- } finally {
355
- rendering = !1, pendingSignals = prevSignals, pendingEffects = prevEffects;
356
- }
357
- return preparedEffects;
358
- }
359
- function runEffects(effects = pendingEffects) {
360
- for (let i = 0; i < effects.length; i += 2 /* Total */) {
361
- let scope = effects[i], fn = effects[i + 1];
362
- fn(scope, scope);
363
- }
364
- }
365
- function runSignals(signals) {
366
- for (let i = 0; i < signals.length; i += 3 /* Total */) {
367
- let scope = signals[i + 0 /* Scope */], signal = signals[i + 1 /* Signal */], value2 = signals[i + 2 /* Value */];
368
- signal(scope, value2);
369
- }
370
- }
371
-
372
- // src/dom/abort-signal.ts
373
- function resetAbortSignal(scope, id) {
374
- let controllers = scope.l;
375
- if (controllers) {
376
- let ctrl = controllers.get(id);
377
- ctrl && (queueEffect(null, () => ctrl.abort()), controllers.delete(id));
378
- }
379
- }
380
- function getAbortSignal(scope, id) {
381
- let controllers = scope.l ||= /* @__PURE__ */ new Map(), controller = controllers.get(id);
382
- return controller || (onDestroy(scope), controllers.set(id, controller = new AbortController())), controller.signal;
383
- }
384
-
385
- // src/common/compat-meta.ts
386
- var prefix = "$C_", RENDERER_REGISTER_ID = prefix + "r", SET_SCOPE_REGISTER_ID = prefix + "s";
387
-
388
88
  // src/common/helpers.ts
389
89
  function classValue(value2) {
390
90
  return toDelimitedString(value2, " ", stringifyClassObject);
@@ -433,55 +133,55 @@ function normalizeDynamicRenderer(value2) {
433
133
 
434
134
  // src/dom/reconcile.ts
435
135
  var WRONG_POS = 2147483647;
436
- function reconcile(parent, oldScopes, newScopes, afterReference) {
437
- 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;
136
+ function reconcile(parent, oldBranches, newBranches, afterReference) {
137
+ let oldStart = 0, newStart = 0, oldEnd = oldBranches.length - 1, newEnd = newBranches.length - 1, oldStartBranch = oldBranches[oldStart], newStartBranch = newBranches[newStart], oldEndBranch = oldBranches[oldEnd], newEndBranch = newBranches[newEnd], i, j, k, nextSibling, oldBranch, newBranch;
438
138
  outer: {
439
- for (; oldStartScope === newStartScope; ) {
139
+ for (; oldStartBranch === newStartBranch; ) {
440
140
  if (++oldStart, ++newStart, oldStart > oldEnd || newStart > newEnd)
441
141
  break outer;
442
- oldStartScope = oldScopes[oldStart], newStartScope = newScopes[newStart];
142
+ oldStartBranch = oldBranches[oldStart], newStartBranch = newBranches[newStart];
443
143
  }
444
- for (; oldEndScope === newEndScope; ) {
144
+ for (; oldEndBranch === newEndBranch; ) {
445
145
  if (--oldEnd, --newEnd, oldStart > oldEnd || newStart > newEnd)
446
146
  break outer;
447
- oldEndScope = oldScopes[oldEnd], newEndScope = newScopes[newEnd];
147
+ oldEndBranch = oldBranches[oldEnd], newEndBranch = newBranches[newEnd];
448
148
  }
449
149
  }
450
150
  if (oldStart > oldEnd) {
451
151
  if (newStart <= newEnd) {
452
- k = newEnd + 1, nextSibling = k < newScopes.length ? newScopes[k].a : afterReference;
152
+ k = newEnd + 1, nextSibling = k < newBranches.length ? newBranches[k].a : afterReference;
453
153
  do
454
- insertBefore(newScopes[newStart++], parent, nextSibling);
154
+ insertBefore(newBranches[newStart++], parent, nextSibling);
455
155
  while (newStart <= newEnd);
456
156
  }
457
157
  } else if (newStart > newEnd)
458
158
  do
459
- removeAndDestroyScope(oldScopes[oldStart++]);
159
+ removeAndDestroyBranch(oldBranches[oldStart++]);
460
160
  while (oldStart <= oldEnd);
461
161
  else {
462
- let oldLength = oldEnd - oldStart + 1, newLength = newEnd - newStart + 1, aNullable = oldScopes, sources = new Array(newLength);
162
+ let oldLength = oldEnd - oldStart + 1, newLength = newEnd - newStart + 1, aNullable = oldBranches, sources = new Array(newLength);
463
163
  for (i = 0; i < newLength; ++i)
464
164
  sources[i] = -1;
465
165
  let pos = 0, synced = 0, keyIndex = /* @__PURE__ */ new Map();
466
166
  for (j = newStart; j <= newEnd; ++j)
467
- keyIndex.set(newScopes[j], j);
167
+ keyIndex.set(newBranches[j], j);
468
168
  for (i = oldStart; i <= oldEnd && synced < newLength; ++i)
469
- 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);
470
- if (oldLength === oldScopes.length && synced === 0) {
169
+ oldBranch = oldBranches[i], j = keyIndex.get(oldBranch), j !== void 0 && (pos = pos > j ? WRONG_POS : j, ++synced, newBranch = newBranches[j], sources[j - newStart] = i, aNullable[i] = null);
170
+ if (oldLength === oldBranches.length && synced === 0) {
471
171
  for (; newStart < newLength; ++newStart)
472
- insertBefore(newScopes[newStart], parent, afterReference);
172
+ insertBefore(newBranches[newStart], parent, afterReference);
473
173
  for (; oldStart < oldLength; ++oldStart)
474
- removeAndDestroyScope(oldScopes[oldStart]);
174
+ removeAndDestroyBranch(oldBranches[oldStart]);
475
175
  } else {
476
176
  for (i = oldLength - synced; i > 0; )
477
- oldScope = aNullable[oldStart++], oldScope !== null && (removeAndDestroyScope(oldScope), i--);
177
+ oldBranch = aNullable[oldStart++], oldBranch !== null && (removeAndDestroyBranch(oldBranch), i--);
478
178
  if (pos === WRONG_POS) {
479
179
  let seq = longestIncreasingSubsequence(sources);
480
- for (j = seq.length - 1, k = newScopes.length, i = newLength - 1; i >= 0; --i)
481
- 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;
180
+ for (j = seq.length - 1, k = newBranches.length, i = newLength - 1; i >= 0; --i)
181
+ sources[i] === -1 ? (pos = i + newStart, newBranch = newBranches[pos++], nextSibling = pos < k ? newBranches[pos].a : afterReference, insertBefore(newBranch, parent, nextSibling)) : j < 0 || i !== seq[j] ? (pos = i + newStart, newBranch = newBranches[pos++], nextSibling = pos < k ? newBranches[pos].a : afterReference, insertBefore(newBranch, parent, nextSibling)) : --j;
482
182
  } else if (synced !== newLength)
483
- for (k = newScopes.length, i = newLength - 1; i >= 0; --i)
484
- sources[i] === -1 && (pos = i + newStart, newScope = newScopes[pos++], nextSibling = pos < k ? newScopes[pos].a : afterReference, insertBefore(newScope, parent, nextSibling));
183
+ for (k = newBranches.length, i = newLength - 1; i >= 0; --i)
184
+ sources[i] === -1 && (pos = i + newStart, newBranch = newBranches[pos++], nextSibling = pos < k ? newBranches[pos].a : afterReference, insertBefore(newBranch, parent, nextSibling));
485
185
  }
486
186
  }
487
187
  }
@@ -553,6 +253,132 @@ function stripSpacesAndPunctuation(str) {
553
253
  return str.replace(/[^\p{L}\p{N}]/gu, "");
554
254
  }
555
255
 
256
+ // src/common/meta.ts
257
+ var DEFAULT_RUNTIME_ID = "M", DEFAULT_RENDER_ID = "_";
258
+
259
+ // src/dom/resume.ts
260
+ var registeredValues = {}, Render = class {
261
+ o = [];
262
+ p = {};
263
+ z = {
264
+ _: registeredValues
265
+ };
266
+ constructor(renders, runtimeId, renderId) {
267
+ this.A = renders, this.B = runtimeId, this.q = renderId, this.s = renders[renderId], this.t();
268
+ }
269
+ w() {
270
+ this.s.w(), this.t();
271
+ }
272
+ t() {
273
+ let data2 = this.s, serializeContext = this.z, scopeLookup = this.p, visits = data2.v, branchIds = /* @__PURE__ */ new Set(), parentBranchIds = /* @__PURE__ */ new Map();
274
+ if (visits.length) {
275
+ let commentPrefixLen = data2.i.length, closestBranchMarkers = /* @__PURE__ */ new Map();
276
+ data2.v = [];
277
+ let branchEnd = (branchId, visit, curNode) => {
278
+ let branch = scopeLookup[branchId] ||= {}, endNode = curNode;
279
+ for (; (endNode = endNode.previousSibling).nodeType === 8; ) ;
280
+ branch.c = endNode, branch.a ||= endNode;
281
+ for (let [markerScopeId, markerNode] of closestBranchMarkers)
282
+ branch.a.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2 && (parentBranchIds.set(markerScopeId, branchId), closestBranchMarkers.delete(markerScopeId));
283
+ return branchIds.add(branchId), closestBranchMarkers.set(branchId, visit), branch;
284
+ };
285
+ for (let visit of visits) {
286
+ let commentText = visit.data, dataIndex = commentText.indexOf(" ") + 1, scopeId = commentText.slice(
287
+ commentPrefixLen + 1,
288
+ dataIndex ? dataIndex - 1 : commentText.length
289
+ ), scope = scopeLookup[scopeId] ||= {}, data3 = dataIndex ? commentText.slice(dataIndex) : "", token = commentText[commentPrefixLen];
290
+ if (token === "*" /* Node */)
291
+ scope[data3] = visit.previousSibling;
292
+ else if (token === "$" /* ClosestBranch */)
293
+ closestBranchMarkers.set(scopeId, visit);
294
+ else if (token === "[" /* BranchStart */)
295
+ this.f && (dataIndex && branchEnd(this.f, visit, visit), this.o.push(this.f)), this.f = scopeId, scope.a = visit;
296
+ else if (token === "]" /* BranchEnd */) {
297
+ scope[data3] = visit;
298
+ let curParent = visit.parentNode, startNode = branchEnd(
299
+ this.f,
300
+ visit,
301
+ visit
302
+ ).a;
303
+ curParent !== startNode.parentNode && curParent.prepend(startNode), this.f = this.o.pop();
304
+ } else if (token === "|" /* BranchSingleNode */) {
305
+ let next = data3.indexOf(" "), curNode = scope[~next ? data3.slice(0, next) : data3] = visit;
306
+ for (; ~next; ) {
307
+ let start = next + 1;
308
+ next = data3.indexOf(" ", start);
309
+ let childScopeId = data3.slice(start, ~next ? next : data3.length);
310
+ curNode = branchEnd(childScopeId, visit, curNode).c;
311
+ }
312
+ }
313
+ }
314
+ }
315
+ let resumes = data2.r;
316
+ if (resumes) {
317
+ data2.r = [];
318
+ let len = resumes.length, i = 0;
319
+ try {
320
+ for (isResuming = !0; i < len; ) {
321
+ let resumeData = resumes[i++];
322
+ if (typeof resumeData == "function") {
323
+ let scopes = resumeData(serializeContext), { $global } = scopeLookup;
324
+ $global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = this.B, $global.renderId = this.q);
325
+ for (let scopeId in scopes)
326
+ if (scopeId !== "$") {
327
+ let scope = scopes[scopeId], prevScope = scopeLookup[scopeId];
328
+ scope.$global = $global, prevScope !== scope && (scopeLookup[scopeId] = Object.assign(
329
+ scope,
330
+ prevScope
331
+ ));
332
+ let parentBranchId = parentBranchIds.get(scopeId);
333
+ if (parentBranchId && (scope.b = scopes[parentBranchId]), branchIds.has(scopeId)) {
334
+ let branch = scope, parentBranch = branch.b;
335
+ scope.b = branch, parentBranch && (branch.C = parentBranch, (parentBranch.m ||= /* @__PURE__ */ new Set()).add(branch));
336
+ }
337
+ }
338
+ } else i === len || typeof resumes[i] != "string" ? delete this.A[this.q] : registeredValues[resumes[i++]](
339
+ scopeLookup[resumeData],
340
+ scopeLookup[resumeData]
341
+ );
342
+ }
343
+ } finally {
344
+ isResuming = !1;
345
+ }
346
+ }
347
+ }
348
+ }, isResuming = !1;
349
+ function register(id, obj) {
350
+ return registeredValues[id] = obj, obj;
351
+ }
352
+ function registerBoundSignal(id, signal) {
353
+ return registeredValues[id] = (scope) => (valueOrOp) => signal(scope, valueOrOp), signal;
354
+ }
355
+ function getRegisteredWithScope(id, scope) {
356
+ let val = registeredValues[id];
357
+ return scope ? val(scope) : val;
358
+ }
359
+ function init(runtimeId = DEFAULT_RUNTIME_ID) {
360
+ let resumeRender = (renderId) => resumeRender[renderId] = renders[renderId] = new Render(renders, runtimeId, renderId), renders;
361
+ window[runtimeId] ? setRenders(window[runtimeId]) : Object.defineProperty(window, runtimeId, {
362
+ configurable: !0,
363
+ set: setRenders
364
+ });
365
+ function setRenders(v) {
366
+ renders = v;
367
+ for (let renderId in v)
368
+ resumeRender(renderId);
369
+ Object.defineProperty(window, runtimeId, {
370
+ configurable: !0,
371
+ value: resumeRender
372
+ });
373
+ }
374
+ }
375
+ function registerSubscriber(id, signal) {
376
+ return register(id, signal.D), signal;
377
+ }
378
+ function nodeRef(id, key) {
379
+ return register(id, (scope) => () => scope[key]);
380
+ }
381
+
556
382
  // src/dom/controllable.ts
557
383
  function controllable_input_checked(scope, nodeAccessor, checked, checkedChange) {
558
384
  setCheckboxValue(
@@ -606,10 +432,13 @@ function controllable_input_value_effect(scope, nodeAccessor) {
606
432
  });
607
433
  }
608
434
  function controllable_select_value(scope, nodeAccessor, value2, valueChange) {
609
- scope[nodeAccessor + ";" /* ControlledHandler */] = valueChange, valueChange ? (scope[nodeAccessor + "=" /* ControlledType */] = 3 /* SelectValue */, scope[nodeAccessor + ":" /* ControlledValue */] = value2) : scope[nodeAccessor + "=" /* ControlledType */] = 5 /* None */, setSelectOptions(
610
- scope[nodeAccessor],
611
- value2,
612
- valueChange
435
+ scope[nodeAccessor + ";" /* ControlledHandler */] = valueChange, valueChange ? (scope[nodeAccessor + "=" /* ControlledType */] = 3 /* SelectValue */, scope[nodeAccessor + ":" /* ControlledValue */] = value2) : scope[nodeAccessor + "=" /* ControlledType */] = 5 /* None */, pendingEffects.unshift(
436
+ scope,
437
+ () => setSelectOptions(
438
+ scope[nodeAccessor],
439
+ value2,
440
+ valueChange
441
+ )
613
442
  );
614
443
  }
615
444
  function controllable_select_value_effect(scope, nodeAccessor) {
@@ -758,8 +587,10 @@ function textContent(node, value2) {
758
587
  }
759
588
  function attrs(scope, nodeAccessor, nextAttrs) {
760
589
  let el = scope[nodeAccessor];
761
- for (let { name } of el.attributes)
590
+ for (let i = el.attributes.length; i--; ) {
591
+ let { name } = el.attributes.item(i);
762
592
  nextAttrs && (name in nextAttrs || hasAttrAlias(el, name, nextAttrs)) || el.removeAttribute(name);
593
+ }
763
594
  attrsInternal(scope, nodeAccessor, nextAttrs);
764
595
  }
765
596
  function hasAttrAlias(element, attr2, nextAttrs) {
@@ -767,8 +598,10 @@ function hasAttrAlias(element, attr2, nextAttrs) {
767
598
  }
768
599
  function partialAttrs(scope, nodeAccessor, nextAttrs, skip) {
769
600
  let el = scope[nodeAccessor], partial = {};
770
- for (let { name } of el.attributes)
601
+ for (let i = el.attributes.length; i--; ) {
602
+ let { name } = el.attributes.item(i);
771
603
  !skip[name] && !(nextAttrs && name in nextAttrs) && el.removeAttribute(name);
604
+ }
772
605
  for (let key in nextAttrs)
773
606
  skip[key] || (partial[key] = nextAttrs[key]);
774
607
  attrsInternal(scope, nodeAccessor, partial);
@@ -908,11 +741,11 @@ function trimWalkString(walkString) {
908
741
  return walkString.slice(0, end + 1);
909
742
  }
910
743
  function walk(startNode, walkCodes, scope) {
911
- walker.currentNode = startNode, walkInternal(walkCodes, scope, scope, 0), walker.currentNode = document.documentElement;
744
+ walker.currentNode = startNode, walkInternal(walkCodes, scope, 0), walker.currentNode = document;
912
745
  }
913
- function walkInternal(walkCodes, scope, cleanupOwnerScope, currentWalkIndex) {
746
+ function walkInternal(walkCodes, scope, currentWalkIndex) {
914
747
  let value2, storedMultiplier = 0, currentMultiplier = 0, currentScopeIndex = 0;
915
- for (cleanupOwnerScope !== scope && (scope.d = cleanupOwnerScope); value2 = walkCodes.charCodeAt(currentWalkIndex++); )
748
+ for (; value2 = walkCodes.charCodeAt(currentWalkIndex++); )
916
749
  if (currentMultiplier = storedMultiplier, storedMultiplier = 0, value2 >= 117 /* Multiplier */)
917
750
  storedMultiplier = currentMultiplier * 10 /* Multiplier */ + value2 - 117 /* Multiplier */;
918
751
  else if (value2 >= 107 /* Out */) {
@@ -925,14 +758,10 @@ function walkInternal(walkCodes, scope, cleanupOwnerScope, currentWalkIndex) {
925
758
  else if (value2 >= 67 /* Next */)
926
759
  for (value2 = 20 /* Next */ * currentMultiplier + value2 - 67 /* Next */; value2--; )
927
760
  walker.nextNode();
928
- else if (value2 === 47 /* BeginChild */)
929
- currentWalkIndex = walkInternal(
930
- walkCodes,
931
- scope[currentScopeIndex++] = createScope(scope.$global),
932
- cleanupOwnerScope,
933
- currentWalkIndex
934
- );
935
- else {
761
+ else if (value2 === 47 /* BeginChild */) {
762
+ let childScope = scope[currentScopeIndex++] = createScope(scope.$global);
763
+ childScope.a = walker.currentNode, childScope.b = scope.b, currentWalkIndex = walkInternal(walkCodes, childScope, currentWalkIndex);
764
+ } else {
936
765
  if (value2 === 38 /* EndChild */)
937
766
  return currentWalkIndex;
938
767
  if (value2 === 32 /* Get */)
@@ -946,26 +775,35 @@ function walkInternal(walkCodes, scope, cleanupOwnerScope, currentWalkIndex) {
946
775
  }
947
776
 
948
777
  // src/dom/renderer.ts
949
- function createScopeWithRenderer(renderer, $global, ownerScope) {
950
- let newScope = createScope($global);
951
- if (newScope._ = newScope.d = renderer.B || ownerScope, newScope.x = renderer, initRenderer(renderer, newScope), renderer.c)
952
- for (let signal of renderer.c)
953
- signal.g?.(newScope);
954
- return newScope;
955
- }
956
- function createScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, ownerScope) {
778
+ function createBranchScopeWithRenderer(renderer, $global, parentScope) {
779
+ let branch = createBranch(
780
+ $global,
781
+ renderer.u || parentScope,
782
+ parentScope
783
+ );
784
+ return initRenderer(renderer, branch), branch;
785
+ }
786
+ function createBranchScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, parentScope) {
957
787
  if (typeof tagNameOrRenderer != "string")
958
- return createScopeWithRenderer(tagNameOrRenderer, $global, ownerScope);
959
- let newScope = createScope($global);
960
- return newScope._ = newScope.d = ownerScope, newScope[0] = newScope.a = newScope.b = document.createElement(tagNameOrRenderer), newScope;
788
+ return createBranchScopeWithRenderer(
789
+ tagNameOrRenderer,
790
+ $global,
791
+ parentScope
792
+ );
793
+ let branch = createBranch($global, parentScope, parentScope);
794
+ return branch[0] = branch.a = branch.c = document.createElement(tagNameOrRenderer), branch;
795
+ }
796
+ function createBranch($global, ownerScope, parentScope) {
797
+ let branch = createScope($global), parentBranch = parentScope.b;
798
+ return branch._ = ownerScope, branch.b = branch, parentBranch && (branch.C = parentBranch, (parentBranch.m ||= /* @__PURE__ */ new Set()).add(branch)), branch;
961
799
  }
962
800
  function initRenderer(renderer, scope) {
963
- let dom = renderer.k();
801
+ let dom = renderer.l();
964
802
  return walk(
965
803
  dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom,
966
- renderer.C,
804
+ renderer.E,
967
805
  scope
968
- ), scope.a = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom, scope.b = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom, renderer.s && renderer.s(scope), dom;
806
+ ), scope.a = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom, scope.c = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom, renderer.x && queueRender(scope, renderer.x), dom;
969
807
  }
970
808
  function dynamicTagAttrs(nodeAccessor, getContent, inputIsArgs) {
971
809
  return (scope, attrsOrOp) => {
@@ -992,36 +830,27 @@ function dynamicTagAttrs(nodeAccessor, getContent, inputIsArgs) {
992
830
  }
993
831
  };
994
832
  }
995
- function createRendererWithOwner(template, rawWalks, setup, getClosureSignals, getArgs) {
996
- let args, closureSignals, id = {}, walks = rawWalks ? /* @__PURE__ */ trimWalkString(rawWalks) : " ";
833
+ function createRendererWithOwner(template, rawWalks, setup, getArgs) {
834
+ let args, id = {}, walks = rawWalks ? /* @__PURE__ */ trimWalkString(rawWalks) : " ";
997
835
  return (owner) => ({
998
- t: id,
999
- D: template,
1000
- C: walks,
1001
- s: setup,
1002
- k: _clone,
1003
- B: owner,
1004
- E: void 0,
836
+ j: id,
837
+ F: template,
838
+ E: walks,
839
+ x: setup,
840
+ l: _clone,
841
+ u: owner,
842
+ G: void 0,
1005
843
  get e() {
1006
844
  return args ||= getArgs?.();
1007
- },
1008
- get c() {
1009
- return closureSignals ||= new Set(getClosureSignals?.());
1010
845
  }
1011
846
  });
1012
847
  }
1013
- function createRenderer(template, walks, setup, getClosureSignals, getArgs) {
1014
- return createRendererWithOwner(
1015
- template,
1016
- walks,
1017
- setup,
1018
- getClosureSignals,
1019
- getArgs
1020
- )();
848
+ function createRenderer(template, walks, setup, getArgs) {
849
+ return createRendererWithOwner(template, walks, setup, getArgs)();
1021
850
  }
1022
851
  function _clone() {
1023
- return (this.E ||= parseHTMLOrSingleNode(
1024
- this.D
852
+ return (this.G ||= parseHTMLOrSingleNode(
853
+ this.F
1025
854
  )).cloneNode(!0);
1026
855
  }
1027
856
 
@@ -1030,41 +859,27 @@ function patchConditionals(fn) {
1030
859
  conditional = fn(conditional), conditionalOnlyChild = fn(conditionalOnlyChild);
1031
860
  }
1032
861
  var conditional = function(nodeAccessor, fn, getIntersection) {
1033
- let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
862
+ let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1034
863
  return (scope, newRendererOrOp) => {
1035
864
  if (newRendererOrOp === DIRTY) return;
1036
865
  let currentRenderer = scope[rendererAccessor], op = newRendererOrOp;
1037
866
  if (newRendererOrOp !== MARK && newRendererOrOp !== CLEAN) {
1038
867
  let normalizedRenderer = normalizeDynamicRenderer(newRendererOrOp);
1039
- isDifferentRenderer(normalizedRenderer, currentRenderer) ? (currentRenderer = scope[rendererAccessor] = normalizedRenderer, setConditionalRenderer(scope, nodeAccessor, normalizedRenderer), fn && fn(scope), op = DIRTY) : op = CLEAN;
868
+ isDifferentRenderer(normalizedRenderer, currentRenderer) ? (setConditionalRenderer(scope, nodeAccessor, normalizedRenderer), fn && fn(scope), op = DIRTY) : op = CLEAN;
1040
869
  }
1041
- intersection2?.(scope, op), contentClosures(currentRenderer, scope[childScopeAccessor], op);
870
+ intersection2?.(scope, op);
1042
871
  };
1043
872
  };
1044
- function inConditionalScope(signal, nodeAccessor) {
1045
- let scopeAccessor = nodeAccessor + "!" /* ConditionalScope */, rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
1046
- return (scope, op) => {
1047
- let conditionalScope = scope[scopeAccessor];
1048
- if (conditionalScope) {
1049
- let conditionalRenderer = scope[rendererAccessor];
1050
- (!conditionalRenderer?.c || conditionalRenderer.c.has(signal)) && signal(conditionalScope, op);
1051
- }
1052
- };
1053
- }
1054
873
  function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
1055
- let newScope, prevScope = scope[nodeAccessor + "!" /* ConditionalScope */];
1056
- newRenderer ? (newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithTagNameOrRenderer(
1057
- newRenderer,
1058
- scope.$global,
1059
- scope
1060
- ), prevScope = prevScope || getEmptyScope(scope[nodeAccessor])) : (newScope = getEmptyScope(scope[nodeAccessor]), scope[nodeAccessor + "!" /* ConditionalScope */] = void 0), insertBefore(
1061
- newScope,
1062
- prevScope.a.parentNode,
1063
- prevScope.a
1064
- ), removeAndDestroyScope(prevScope);
874
+ let newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0, prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyScope(scope[nodeAccessor]);
875
+ insertBefore(
876
+ newBranch || getEmptyScope(scope[nodeAccessor]),
877
+ prevBranch.a.parentNode,
878
+ prevBranch.a
879
+ ), removeAndDestroyBranch(prevBranch), scope[nodeAccessor + "(" /* ConditionalRenderer */] = newRenderer, scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
1065
880
  }
1066
881
  var conditionalOnlyChild = function(nodeAccessor, fn, getIntersection) {
1067
- let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
882
+ let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1068
883
  return (scope, newRendererOrOp) => {
1069
884
  if (newRendererOrOp === DIRTY) return;
1070
885
  let currentRenderer = scope[rendererAccessor], op = newRendererOrOp;
@@ -1076,18 +891,16 @@ var conditionalOnlyChild = function(nodeAccessor, fn, getIntersection) {
1076
891
  normalizedRenderer
1077
892
  ), fn && fn(scope), op = DIRTY) : op = CLEAN;
1078
893
  }
1079
- intersection2?.(scope, op), contentClosures(currentRenderer, scope[childScopeAccessor], op);
894
+ intersection2?.(scope, op);
1080
895
  };
1081
896
  };
1082
897
  function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
1083
- let prevScope = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor];
1084
- if (referenceNode.textContent = "", newRenderer) {
1085
- let newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope);
1086
- insertBefore(newScope, referenceNode, null);
1087
- }
1088
- prevScope && destroyScope(prevScope);
898
+ let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor], newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0;
899
+ referenceNode.textContent = "", newBranch && insertBefore(newBranch, referenceNode, null), prevBranch && destroyBranch(prevBranch), scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
1089
900
  }
1090
- var emptyMarkerMap = /* @__PURE__ */ new Map([[Symbol(), getEmptyScope(void 0)]]), emptyMarkerArray = [
901
+ var emptyMarkerMap = /* @__PURE__ */ new Map([
902
+ [Symbol(), getEmptyScope(void 0)]
903
+ ]), emptyMarkerArray = [
1091
904
  /* @__PURE__ */ getEmptyScope(void 0)
1092
905
  ], emptyMap = /* @__PURE__ */ new Map(), emptyArray = [];
1093
906
  function loopOf(nodeAccessor, renderer) {
@@ -1117,31 +930,25 @@ function loopTo(nodeAccessor, renderer) {
1117
930
  );
1118
931
  }
1119
932
  function loop(nodeAccessor, renderer, forEach) {
1120
- let loopScopeAccessor = nodeAccessor + "!" /* LoopScopeArray */, closureSignals = renderer.c, params = renderer.e;
933
+ let loopScopeAccessor = nodeAccessor + "!" /* LoopScopeArray */, params = renderer.e;
1121
934
  return (scope, valueOrOp) => {
1122
935
  if (valueOrOp === DIRTY) return;
1123
936
  if (valueOrOp === MARK || valueOrOp === CLEAN) {
1124
- let loopScopes = scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1125
- if (loopScopes !== emptyMarkerArray)
1126
- for (let childScope of loopScopes) {
1127
- params?.(childScope, valueOrOp);
1128
- for (let signal of closureSignals)
1129
- signal(childScope, valueOrOp);
1130
- }
937
+ let loopBranches = scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
938
+ if (loopBranches !== emptyMarkerArray)
939
+ for (let branch of loopBranches)
940
+ params?.(branch, valueOrOp);
1131
941
  return;
1132
942
  }
1133
943
  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;
1134
944
  if (forEach(valueOrOp, (key, args) => {
1135
- let childScope = oldMap.get(key), closureOp = CLEAN;
1136
- if (childScope || (childScope = createScopeWithRenderer(renderer, scope.$global, scope), closureOp = DIRTY), params && params(childScope, args), closureSignals)
1137
- for (let signal of closureSignals)
1138
- signal(childScope, closureOp);
1139
- newMap ? (newMap.set(key, childScope), newArray.push(childScope)) : (newMap = /* @__PURE__ */ new Map([[key, childScope]]), newArray = [childScope]);
1140
- }), newMap || (referenceIsMarker ? (newMap = emptyMarkerMap, newArray = emptyMarkerArray, getEmptyScope(referenceNode)) : (oldArray.forEach(destroyScope), referenceNode.textContent = "", newMap = emptyMap, newArray = emptyArray, needsReconciliation = !1)), needsReconciliation) {
945
+ let branch = oldMap.get(key);
946
+ branch || (branch = createBranchScopeWithRenderer(renderer, scope.$global, scope)), params && params(branch, args), newMap ? (newMap.set(key, branch), newArray.push(branch)) : (newMap = /* @__PURE__ */ new Map([[key, branch]]), newArray = [branch]);
947
+ }), newMap || (referenceIsMarker ? (newMap = emptyMarkerMap, newArray = emptyMarkerArray, getEmptyScope(referenceNode)) : (oldArray.forEach(destroyBranch), referenceNode.textContent = "", newMap = emptyMap, newArray = emptyArray, needsReconciliation = !1)), needsReconciliation) {
1141
948
  if (referenceIsMarker) {
1142
949
  oldMap === emptyMarkerMap && getEmptyScope(referenceNode);
1143
950
  let oldLastChild = oldArray[oldArray.length - 1];
1144
- afterReference = oldLastChild.b.nextSibling, parentNode = oldLastChild.a.parentNode;
951
+ afterReference = oldLastChild.c.nextSibling, parentNode = oldLastChild.a.parentNode;
1145
952
  } else
1146
953
  afterReference = null, parentNode = referenceNode;
1147
954
  reconcile(parentNode, oldArray, newArray, afterReference);
@@ -1149,15 +956,6 @@ function loop(nodeAccessor, renderer, forEach) {
1149
956
  scope[nodeAccessor + "(" /* LoopScopeMap */] = newMap, scope[nodeAccessor + "!" /* LoopScopeArray */] = newArray;
1150
957
  };
1151
958
  }
1152
- function inLoopScope(signal, loopNodeAccessor) {
1153
- let loopScopeAccessor = loopNodeAccessor + "!" /* LoopScopeArray */;
1154
- return (scope, op) => {
1155
- let loopScopes = scope[loopScopeAccessor] ?? scope[loopNodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1156
- if (loopScopes !== emptyMarkerArray)
1157
- for (let scope2 of loopScopes)
1158
- signal(scope2, op);
1159
- };
1160
- }
1161
959
  function bySecondArg(_item, index) {
1162
960
  return index;
1163
961
  }
@@ -1165,9 +963,185 @@ function byFirstArg(name) {
1165
963
  return name;
1166
964
  }
1167
965
  function isDifferentRenderer(a, b) {
1168
- return a !== b && (a?.t || 0) !== b?.t;
966
+ return a !== b && (a?.j || 0) !== b?.j;
1169
967
  }
1170
968
 
969
+ // src/dom/signals.ts
970
+ var MARK = {}, CLEAN = {}, DIRTY = {};
971
+ function state(valueAccessor, fn, getIntersection) {
972
+ let valueSignal = value(valueAccessor, fn, getIntersection), markAccessor = valueAccessor + "#" /* Mark */, valueChangeAccessor = valueAccessor + "@" /* TagVariableChange */;
973
+ return (scope, valueOrOp, valueChange) => (rendering ? valueSignal(
974
+ scope,
975
+ valueOrOp === MARK || valueOrOp === CLEAN || valueOrOp === DIRTY || (scope[valueChangeAccessor] = valueChange) || scope[markAccessor] === void 0 ? valueOrOp : CLEAN
976
+ ) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](valueOrOp) : queueSource(scope, valueSignal, valueOrOp), valueOrOp);
977
+ }
978
+ function value(valueAccessor, fn, getIntersection) {
979
+ let markAccessor = valueAccessor + "#" /* Mark */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
980
+ return (scope, valueOrOp) => {
981
+ if (valueOrOp === MARK)
982
+ (scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1 && intersection2?.(scope, MARK);
983
+ else if (valueOrOp !== DIRTY) {
984
+ let existing = scope[markAccessor] !== void 0;
985
+ (scope[markAccessor] ||= 1) === 1 && (valueOrOp === CLEAN || existing && scope[valueAccessor] === valueOrOp ? intersection2?.(scope, CLEAN) : (scope[valueAccessor] = valueOrOp, fn && fn(scope, valueOrOp), intersection2?.(scope, DIRTY))), scope[markAccessor]--;
986
+ }
987
+ };
988
+ }
989
+ var accessorId = 0;
990
+ function intersection(count, fn, getIntersection) {
991
+ let dirtyAccessor = "?" /* Dynamic */ + accessorId++, markAccessor = dirtyAccessor + "#" /* Mark */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
992
+ return (scope, op) => {
993
+ op === MARK ? (scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1 && intersection2?.(scope, MARK) : scope[markAccessor] === void 0 ? (scope[markAccessor] = count - 1, scope[dirtyAccessor] = !0) : --scope[markAccessor] === 0 ? op === DIRTY || scope[dirtyAccessor] ? (scope[dirtyAccessor] = !1, fn(scope, 0), intersection2?.(scope, DIRTY)) : intersection2?.(scope, CLEAN) : scope[dirtyAccessor] ||= op === DIRTY;
994
+ };
995
+ }
996
+ function closure(fn, getIntersection) {
997
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
998
+ return (scope, valueOrOp) => {
999
+ valueOrOp === MARK ? intersection2?.(scope, MARK) : (fn && fn(scope, valueOrOp), intersection2?.(scope, DIRTY));
1000
+ };
1001
+ }
1002
+ function loopClosure(ownerLoopNodeAccessor, fn, getIntersection) {
1003
+ let signal = closure(fn, getIntersection), loopScopeAccessor = ownerLoopNodeAccessor + "!" /* LoopScopeArray */, loopScopeMapAccessor = ownerLoopNodeAccessor + "(" /* LoopScopeMap */, helperSignal = (ownerScope, value2) => {
1004
+ let loopScopes = ownerScope[loopScopeAccessor] ?? ownerScope[loopScopeMapAccessor]?.values() ?? [];
1005
+ if (loopScopes !== emptyMarkerArray)
1006
+ for (let scope of loopScopes)
1007
+ scope.g || queueSource(scope, signal, value2);
1008
+ };
1009
+ return helperSignal._ = signal, helperSignal;
1010
+ }
1011
+ function conditionalClosure(ownerConditionalNodeAccessor, getRenderer, fn, getIntersection) {
1012
+ let signal = closure(fn, getIntersection), scopeAccessor = ownerConditionalNodeAccessor + "!" /* ConditionalScope */, rendererAccessor = ownerConditionalNodeAccessor + "(" /* ConditionalRenderer */, helperSignal = (scope, value2) => {
1013
+ let conditionalScope = scope[scopeAccessor];
1014
+ conditionalScope && !conditionalScope.g && scope[rendererAccessor]?.j === getRenderer().j && queueSource(conditionalScope, signal, value2);
1015
+ };
1016
+ return helperSignal._ = signal, helperSignal;
1017
+ }
1018
+ var defaultGetOwnerScope = (scope) => scope._;
1019
+ function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
1020
+ let ownerSubscribersAccessor = ownerValueAccessor + "*" /* Subscribers */, _signal = closure(fn, getIntersection), helperSignal = (ownerScope, value2) => {
1021
+ let subscribers = ownerScope[ownerSubscribersAccessor];
1022
+ if (subscribers)
1023
+ for (let subscriber of subscribers)
1024
+ subscriber.g || queueSource(subscriber, _signal, value2);
1025
+ }, setupSignal = (scope, value2) => {
1026
+ _signal(scope, value2), subscribe(scope);
1027
+ }, subscribe = (scope) => {
1028
+ (getOwnerScope(scope)[ownerSubscribersAccessor] ||= /* @__PURE__ */ new Set()).add(scope), getAbortSignal(scope, -1).addEventListener("abort", () => {
1029
+ getOwnerScope(scope)[ownerSubscribersAccessor].delete(scope);
1030
+ });
1031
+ };
1032
+ return helperSignal._ = setupSignal, helperSignal.D = subscribe, helperSignal;
1033
+ }
1034
+ function setTagVar(scope, childAccessor, tagVarSignal2) {
1035
+ scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
1036
+ }
1037
+ var tagVarSignal = (scope, valueOrOp) => scope["/" /* TagVariable */]?.(valueOrOp);
1038
+ function setTagVarChange(scope, changeHandler) {
1039
+ scope["@" /* TagVariableChange */] = changeHandler;
1040
+ }
1041
+ var tagVarSignalChange = (scope, value2) => scope["@" /* TagVariableChange */]?.(value2);
1042
+ var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
1043
+ function nextTagId({ $global }) {
1044
+ let id = tagIdsByGlobal.get($global) || 0;
1045
+ return tagIdsByGlobal.set($global, id + 1), "c" + $global.runtimeId + $global.renderId + id.toString(36);
1046
+ }
1047
+ function inChild(childAccessor, signal) {
1048
+ return (scope, valueOrOp) => {
1049
+ signal(scope[childAccessor], valueOrOp);
1050
+ };
1051
+ }
1052
+ function intersections(signals) {
1053
+ return (scope, op) => {
1054
+ for (let signal of signals)
1055
+ signal(scope, op);
1056
+ };
1057
+ }
1058
+ function effect(id, fn) {
1059
+ return register(id, fn), (scope) => {
1060
+ queueEffect(scope, fn);
1061
+ };
1062
+ }
1063
+
1064
+ // src/dom/queue.ts
1065
+ var pendingRender, pendingEffects = [], rendering = !1;
1066
+ function queueSource(scope, signal, value2) {
1067
+ schedule();
1068
+ let prevRendering = rendering;
1069
+ return rendering = !0, signal(scope, MARK), rendering = prevRendering, queueRender(scope, signal, value2), value2;
1070
+ }
1071
+ function queueRender(scope, signal, value2) {
1072
+ let nextRender = {
1073
+ k: scope,
1074
+ H: signal,
1075
+ I: value2,
1076
+ d: void 0
1077
+ };
1078
+ if (!pendingRender)
1079
+ pendingRender = nextRender;
1080
+ else if (comparePendingRenders(pendingRender, nextRender) < 0)
1081
+ nextRender.d = pendingRender, pendingRender = nextRender;
1082
+ else {
1083
+ let curRender = pendingRender;
1084
+ for (; curRender.d && comparePendingRenders(curRender.d, nextRender) >= 0; )
1085
+ curRender = curRender.d;
1086
+ nextRender.d = curRender.d, curRender.d = nextRender;
1087
+ }
1088
+ }
1089
+ function queueEffect(scope, fn) {
1090
+ pendingEffects.push(scope, fn);
1091
+ }
1092
+ function run() {
1093
+ let effects = pendingEffects;
1094
+ try {
1095
+ rendering = !0, runRenders();
1096
+ } finally {
1097
+ pendingRender = void 0, rendering = !1;
1098
+ }
1099
+ pendingEffects = [], runEffects(effects);
1100
+ }
1101
+ function prepareEffects(fn) {
1102
+ let prevRender = pendingRender, prevEffects = pendingEffects, preparedEffects = pendingEffects = [];
1103
+ pendingRender = void 0;
1104
+ try {
1105
+ rendering = !0, fn(), runRenders();
1106
+ } finally {
1107
+ rendering = !1, pendingRender = prevRender, pendingEffects = prevEffects;
1108
+ }
1109
+ return preparedEffects;
1110
+ }
1111
+ function runEffects(effects = pendingEffects) {
1112
+ for (let i = 0; i < effects.length; i += 2 /* Total */) {
1113
+ let scope = effects[i], fn = effects[i + 1];
1114
+ fn(scope, scope);
1115
+ }
1116
+ }
1117
+ function runRenders() {
1118
+ for (; pendingRender; )
1119
+ pendingRender.k.b?.y || pendingRender.H(pendingRender.k, pendingRender.I), pendingRender = pendingRender.d;
1120
+ finishPendingScopes();
1121
+ }
1122
+ function comparePendingRenders(a, b) {
1123
+ let aStart = ownerStartNode(a.k), bStart = ownerStartNode(b.k);
1124
+ return aStart === bStart ? 0 : aStart ? bStart ? aStart.compareDocumentPosition(bStart) & 2 ? -1 : 1 : -1 : 1;
1125
+ }
1126
+ function ownerStartNode(scope) {
1127
+ return (scope.b || scope).a;
1128
+ }
1129
+
1130
+ // src/dom/abort-signal.ts
1131
+ function resetAbortSignal(scope, id) {
1132
+ let ctrl = scope.h?.[id];
1133
+ ctrl && (queueEffect(ctrl, abort), scope.h[id] = void 0);
1134
+ }
1135
+ function getAbortSignal(scope, id) {
1136
+ return scope.b && (scope.b.n ||= /* @__PURE__ */ new Set()).add(scope), ((scope.h ||= {})[id] ||= new AbortController()).signal;
1137
+ }
1138
+ function abort(ctrl) {
1139
+ ctrl.abort();
1140
+ }
1141
+
1142
+ // src/common/compat-meta.ts
1143
+ var prefix = "$C_", RENDERER_REGISTER_ID = prefix + "r", SET_SCOPE_REGISTER_ID = prefix + "s";
1144
+
1171
1145
  // src/dom/compat.ts
1172
1146
  var classIdToScope = /* @__PURE__ */ new Map(), compat = {
1173
1147
  patchConditionals,
@@ -1184,35 +1158,32 @@ var classIdToScope = /* @__PURE__ */ new Map(), compat = {
1184
1158
  return value2 === MARK || value2 === CLEAN || value2 === DIRTY;
1185
1159
  },
1186
1160
  isRenderer(renderer) {
1187
- return renderer.k !== void 0;
1161
+ return renderer.l !== void 0;
1188
1162
  },
1189
1163
  getStartNode(scope) {
1190
1164
  return scope.a;
1191
1165
  },
1192
1166
  setScopeNodes(scope, startNode, endNode) {
1193
- scope.a = startNode, scope.b = endNode;
1167
+ scope.a = startNode, scope.c = endNode;
1194
1168
  },
1195
1169
  runComponentEffects() {
1196
1170
  runEffects(this.effects);
1197
1171
  },
1172
+ runComponentDestroy() {
1173
+ this.scope && destroyBranch(this.scope);
1174
+ },
1198
1175
  resolveRegistered(value2, {
1199
1176
  runtimeId,
1200
1177
  componentIdPrefix
1201
1178
  }) {
1202
1179
  return Array.isArray(value2) && typeof value2[0] == "string" ? getRegisteredWithScope(
1203
1180
  value2[0],
1204
- value2.length === 2 && window[runtimeId]?.[componentIdPrefix === "s" ? "_" : componentIdPrefix]?.n[value2[1]]
1181
+ value2.length === 2 && window[runtimeId]?.[componentIdPrefix === "s" ? "_" : componentIdPrefix]?.p[value2[1]]
1205
1182
  ) : value2;
1206
1183
  },
1207
1184
  createRenderer(setup, clone, args) {
1208
- let renderer = createRenderer(
1209
- "",
1210
- void 0,
1211
- setup,
1212
- void 0,
1213
- args && (() => args)
1214
- );
1215
- return renderer.k = clone, renderer;
1185
+ let renderer = createRenderer("", void 0, setup, args && (() => args));
1186
+ return renderer.l = clone, renderer;
1216
1187
  },
1217
1188
  render(out, component, renderer, args) {
1218
1189
  let scope = component.scope;
@@ -1224,18 +1195,9 @@ var classIdToScope = /* @__PURE__ */ new Map(), compat = {
1224
1195
  normalizedInput[key === "renderBody" ? "content" : key] = input[key];
1225
1196
  }
1226
1197
  if (component.effects = prepareEffects(() => {
1227
- if (scope)
1228
- applyArgs(scope, MARK), existing = !0;
1229
- else {
1230
- scope = component.scope = createScopeWithRenderer(renderer, out.global);
1231
- let closures = renderer.c;
1232
- if (closures)
1233
- for (let signal of closures)
1234
- signal(component.scope, CLEAN);
1235
- }
1236
- applyArgs(scope, args);
1198
+ scope ? (applyArgs(scope, MARK), existing = !0) : (scope = component.scope = createScope(out.global), scope._ = renderer.u, initRenderer(renderer, scope)), applyArgs(scope, args);
1237
1199
  }), !existing)
1238
- return scope.a === scope.b ? scope.a : scope.a.parentNode;
1200
+ return scope.a === scope.c ? scope.a : scope.a.parentNode;
1239
1201
  }
1240
1202
  };
1241
1203
  function noop() {
@@ -1247,7 +1209,7 @@ var createTemplate = (templateId, ...rendererArgs) => {
1247
1209
  return renderer.mount = mount, renderer._ = renderer, register(templateId, renderer);
1248
1210
  };
1249
1211
  function mount(input = {}, reference, position) {
1250
- let scope, dom, { $global } = input;
1212
+ let branch, dom, { $global } = input;
1251
1213
  $global ? ({ $global, ...input } = input, $global = {
1252
1214
  runtimeId: DEFAULT_RUNTIME_ID,
1253
1215
  renderId: DEFAULT_RENDER_ID,
@@ -1257,7 +1219,7 @@ function mount(input = {}, reference, position) {
1257
1219
  renderId: DEFAULT_RENDER_ID
1258
1220
  };
1259
1221
  let args = this.e, effects = prepareEffects(() => {
1260
- scope = createScope($global), dom = initRenderer(this, scope), args && args(scope, [input]);
1222
+ branch = createScope($global), dom = initRenderer(this, branch), args && args(branch, [input]);
1261
1223
  });
1262
1224
  switch (position) {
1263
1225
  case "afterbegin":
@@ -1277,12 +1239,12 @@ function mount(input = {}, reference, position) {
1277
1239
  update: (newInput) => {
1278
1240
  args && runEffects(
1279
1241
  prepareEffects(() => {
1280
- args(scope, MARK), args(scope, [newInput]);
1242
+ args(branch, MARK), args(branch, [newInput]);
1281
1243
  })
1282
1244
  );
1283
1245
  },
1284
1246
  destroy: () => {
1285
- removeAndDestroyScope(scope);
1247
+ removeAndDestroyBranch(branch);
1286
1248
  }
1287
1249
  };
1288
1250
  }
@@ -1292,11 +1254,10 @@ export {
1292
1254
  attrTags,
1293
1255
  attrs,
1294
1256
  attrsEvents,
1295
- childClosures,
1296
1257
  classAttr,
1297
- closure,
1298
1258
  compat,
1299
1259
  conditional,
1260
+ conditionalClosure,
1300
1261
  conditionalOnlyChild,
1301
1262
  controllable_detailsOrDialog_open,
1302
1263
  controllable_detailsOrDialog_open_effect,
@@ -1316,7 +1277,6 @@ export {
1316
1277
  createTemplate,
1317
1278
  data,
1318
1279
  dynamicClosure,
1319
- dynamicSubscribers,
1320
1280
  dynamicTagAttrs,
1321
1281
  effect,
1322
1282
  forIn,
@@ -1325,12 +1285,11 @@ export {
1325
1285
  getAbortSignal,
1326
1286
  html,
1327
1287
  inChild,
1328
- inConditionalScope,
1329
- inLoopScope,
1330
1288
  init,
1331
1289
  intersection,
1332
1290
  intersections,
1333
1291
  lifecycle,
1292
+ loopClosure,
1334
1293
  loopIn,
1335
1294
  loopOf,
1336
1295
  loopTo,