marko 6.0.0-next.3.22 → 6.0.0-next.3.24

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.js CHANGED
@@ -22,11 +22,10 @@ __export(dom_exports, {
22
22
  attrTags: () => attrTags,
23
23
  attrs: () => attrs,
24
24
  attrsEvents: () => attrsEvents,
25
- childClosures: () => childClosures,
26
25
  classAttr: () => classAttr,
27
- closure: () => closure,
28
26
  compat: () => compat,
29
27
  conditional: () => conditional,
28
+ conditionalClosure: () => conditionalClosure,
30
29
  conditionalOnlyChild: () => conditionalOnlyChild,
31
30
  controllable_detailsOrDialog_open: () => controllable_detailsOrDialog_open,
32
31
  controllable_detailsOrDialog_open_effect: () => controllable_detailsOrDialog_open_effect,
@@ -46,7 +45,6 @@ __export(dom_exports, {
46
45
  createTemplate: () => createTemplate,
47
46
  data: () => data,
48
47
  dynamicClosure: () => dynamicClosure,
49
- dynamicSubscribers: () => dynamicSubscribers,
50
48
  dynamicTagAttrs: () => dynamicTagAttrs,
51
49
  effect: () => effect,
52
50
  forIn: () => forIn,
@@ -55,12 +53,11 @@ __export(dom_exports, {
55
53
  getAbortSignal: () => getAbortSignal,
56
54
  html: () => html,
57
55
  inChild: () => inChild,
58
- inConditionalScope: () => inConditionalScope,
59
- inLoopScope: () => inLoopScope,
60
56
  init: () => init,
61
57
  intersection: () => intersection,
62
58
  intersections: () => intersections,
63
59
  lifecycle: () => lifecycle,
60
+ loopClosure: () => loopClosure,
64
61
  loopIn: () => loopIn,
65
62
  loopOf: () => loopOf,
66
63
  loopTo: () => loopTo,
@@ -132,346 +129,46 @@ function triggerMacroTask() {
132
129
  port2.postMessage(0);
133
130
  }
134
131
 
135
- // src/common/meta.ts
136
- var DEFAULT_RUNTIME_ID = "M", DEFAULT_RENDER_ID = "_";
137
-
138
132
  // src/dom/scope.ts
133
+ var pendingScopes = [];
139
134
  function createScope($global) {
140
- return {
141
- u: 1,
135
+ let scope = {
136
+ g: 1,
142
137
  $global
143
138
  };
139
+ return pendingScopes.push(scope), scope;
140
+ }
141
+ function finishPendingScopes() {
142
+ for (let scope of pendingScopes)
143
+ scope.g = 0;
144
+ pendingScopes = [];
144
145
  }
145
146
  var emptyScope = createScope({});
146
147
  function getEmptyScope(marker) {
147
- return emptyScope.a = emptyScope.b = marker, emptyScope;
148
- }
149
- function destroyScope(scope) {
150
- _destroyScope(scope), scope.d?.h?.delete(scope);
151
- let closureSignals = scope.x?.c;
152
- if (closureSignals)
153
- for (let signal of closureSignals)
154
- signal.j?.(scope);
155
- return scope;
156
- }
157
- function _destroyScope(scope) {
158
- scope.h?.forEach(_destroyScope);
159
- let controllers = scope.l;
160
- if (controllers)
161
- for (let ctrl of controllers.values())
162
- ctrl.abort();
163
- }
164
- function onDestroy(scope) {
165
- let parentScope = scope.d;
166
- for (; parentScope && !parentScope.h?.has(scope); )
167
- (parentScope.h ||= /* @__PURE__ */ new Set()).add(scope), scope = parentScope, parentScope = scope.d;
168
- }
169
- function removeAndDestroyScope(scope) {
170
- destroyScope(scope);
171
- let current = scope.a, stop = scope.b.nextSibling;
148
+ return emptyScope.a = emptyScope.c = marker, emptyScope;
149
+ }
150
+ function destroyBranch(branch) {
151
+ if (branch.y = 1, branch.m?.forEach(destroyBranch), branch.n)
152
+ for (let scope of branch.n)
153
+ for (let id in scope.h)
154
+ scope.h[id]?.abort();
155
+ }
156
+ function removeAndDestroyBranch(branch) {
157
+ destroyBranch(branch);
158
+ let current = branch.a, stop = branch.c.nextSibling;
172
159
  for (; current !== stop; ) {
173
160
  let next = current.nextSibling;
174
161
  current.remove(), current = next;
175
162
  }
176
163
  }
177
164
  function insertBefore(scope, parent, nextSibling) {
178
- let current = scope.a, stop = scope.b.nextSibling;
165
+ let current = scope.a, stop = scope.c.nextSibling;
179
166
  for (; current !== stop; ) {
180
167
  let next = current.nextSibling;
181
168
  parent.insertBefore(current, nextSibling), current = next;
182
169
  }
183
170
  }
184
171
 
185
- // src/dom/resume.ts
186
- var registeredValues = {}, Render = class {
187
- m = [];
188
- n = {};
189
- y = {
190
- _: registeredValues
191
- };
192
- constructor(renders, runtimeId, renderId) {
193
- this.z = renders, this.A = runtimeId, this.o = renderId, this.p = renders[renderId], this.q();
194
- }
195
- w() {
196
- this.p.w(), this.q();
197
- }
198
- q() {
199
- let data2 = this.p, serializeContext = this.y, scopeLookup = this.n, visits = data2.v, cleanupOwners = /* @__PURE__ */ new Map();
200
- if (visits.length) {
201
- let commentPrefixLen = data2.i.length, cleanupMarkers = /* @__PURE__ */ new Map();
202
- data2.v = [];
203
- let sectionEnd = (visit, scopeId = this.f, curNode = visit) => {
204
- let scope = scopeLookup[scopeId] ||= {}, endNode = curNode;
205
- for (; (endNode = endNode.previousSibling).nodeType === 8; ) ;
206
- scope.b = endNode;
207
- let startNode = scope.a ||= endNode, len = cleanupMarkers.size;
208
- for (let [markerScopeId, markerNode] of cleanupMarkers) {
209
- if (!len--) break;
210
- markerScopeId !== scopeId && startNode.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2 && (cleanupOwners.set("" + markerScopeId, scopeId), cleanupMarkers.delete(markerScopeId));
211
- }
212
- return cleanupMarkers.set(scopeId, visit), scope;
213
- };
214
- for (let visit of visits) {
215
- 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) : "";
216
- if (token === "*" /* Node */)
217
- scope[data3] = visit.previousSibling;
218
- else if (token === "$" /* Cleanup */)
219
- cleanupMarkers.set(scopeId, visit);
220
- else if (token === "[" /* SectionStart */)
221
- this.f && (data3 && sectionEnd(visit), this.m.push(this.f)), this.f = scopeId, scope.a = visit;
222
- else if (token === "]" /* SectionEnd */) {
223
- if (scope[data3] = visit, scopeId < this.f) {
224
- let currParent = visit.parentNode, startNode = sectionEnd(visit).a;
225
- currParent && currParent !== startNode.parentNode && currParent.prepend(startNode), this.f = this.m.pop();
226
- }
227
- } else if (token === "|" /* SectionSingleNodesEnd */) {
228
- scope[parseInt(data3)] = visit;
229
- let childScopeIds = JSON.parse(
230
- "[" + data3.slice(data3.indexOf(" ") + 1) + "]"
231
- ), curNode = visit;
232
- for (let i = childScopeIds.length - 1; i >= 0; i--)
233
- curNode = sectionEnd(visit, childScopeIds[i], curNode).b;
234
- }
235
- }
236
- }
237
- let resumes = data2.r;
238
- if (resumes) {
239
- data2.r = [];
240
- let len = resumes.length, i = 0;
241
- try {
242
- for (isResuming = !0; i < len; ) {
243
- let resumeData = resumes[i++];
244
- if (typeof resumeData == "function") {
245
- let scopes = resumeData(serializeContext), { $global } = scopeLookup;
246
- $global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = this.A, $global.renderId = this.o);
247
- for (let scopeId in scopes)
248
- if (scopeId !== "$") {
249
- let scope = scopes[scopeId], prevScope = scopeLookup[scopeId];
250
- scope.$global = $global, prevScope !== scope && (scopeLookup[scopeId] = Object.assign(
251
- scope,
252
- prevScope
253
- ));
254
- let cleanupOwnerId = cleanupOwners.get(scopeId);
255
- cleanupOwnerId && (scope.d = scopes[cleanupOwnerId], onDestroy(scope));
256
- }
257
- } else i === len || typeof resumes[i] != "string" ? delete this.z[this.o] : registeredValues[resumes[i++]](
258
- scopeLookup[resumeData],
259
- scopeLookup[resumeData]
260
- );
261
- }
262
- } finally {
263
- isResuming = !1;
264
- }
265
- }
266
- }
267
- }, isResuming = !1;
268
- function register(id, obj) {
269
- return registeredValues[id] = obj, obj;
270
- }
271
- function registerBoundSignal(id, signal) {
272
- return registeredValues[id] = (scope) => (valueOrOp) => signal(scope, valueOrOp), signal;
273
- }
274
- function getRegisteredWithScope(id, scope) {
275
- let val = registeredValues[id];
276
- return scope ? val(scope) : val;
277
- }
278
- function init(runtimeId = DEFAULT_RUNTIME_ID) {
279
- let resumeRender = (renderId) => resumeRender[renderId] = renders[renderId] = new Render(renders, runtimeId, renderId), renders;
280
- window[runtimeId] ? setRenders(window[runtimeId]) : Object.defineProperty(window, runtimeId, {
281
- configurable: !0,
282
- set: setRenders
283
- });
284
- function setRenders(v) {
285
- renders = v;
286
- for (let renderId in v)
287
- resumeRender(renderId);
288
- Object.defineProperty(window, runtimeId, {
289
- configurable: !0,
290
- value: resumeRender
291
- });
292
- }
293
- }
294
- function registerSubscriber(id, signal) {
295
- return register(id, signal.g), signal;
296
- }
297
- function nodeRef(id, key) {
298
- return register(id, (scope) => () => scope[key]);
299
- }
300
-
301
- // src/dom/signals.ts
302
- var MARK = {}, CLEAN = {}, DIRTY = {};
303
- function state(valueAccessor, fn, getIntersection) {
304
- let valueSignal = value(valueAccessor, fn, getIntersection), markAccessor = valueAccessor + "#" /* Mark */, valueChangeAccessor = valueAccessor + "@" /* TagVariableChange */;
305
- return (scope, valueOrOp, valueChange) => (rendering ? valueSignal(
306
- scope,
307
- valueOrOp === MARK || valueOrOp === CLEAN || valueOrOp === DIRTY || (scope[valueChangeAccessor] = valueChange) || scope[markAccessor] === void 0 ? valueOrOp : CLEAN
308
- ) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](valueOrOp) : queueSource(scope, valueSignal, valueOrOp), valueOrOp);
309
- }
310
- function value(valueAccessor, fn, getIntersection) {
311
- let markAccessor = valueAccessor + "#" /* Mark */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
312
- return (scope, valueOrOp) => {
313
- if (valueOrOp === MARK)
314
- (scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1 && intersection2?.(scope, MARK);
315
- else if (valueOrOp !== DIRTY) {
316
- let existing = scope[markAccessor] !== void 0;
317
- (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]--;
318
- }
319
- };
320
- }
321
- var accessorId = 0;
322
- function intersection(count, fn, getIntersection) {
323
- let dirtyAccessor = "?" /* Dynamic */ + accessorId++, markAccessor = dirtyAccessor + "#" /* Mark */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
324
- return (scope, op) => {
325
- 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;
326
- };
327
- }
328
- var defaultGetOwnerScope = (scope) => scope._;
329
- function closure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
330
- let dirtyAccessor = "?" /* Dynamic */ + accessorId++, markAccessor = dirtyAccessor + 1, getOwnerValueAccessor = typeof ownerValueAccessor == "function" ? ownerValueAccessor : () => ownerValueAccessor, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
331
- return (scope, op) => {
332
- if (op === MARK)
333
- (scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1 && intersection2?.(scope, MARK);
334
- else {
335
- let ownerScope, ownerValueAccessor2;
336
- if (scope[markAccessor] === void 0) {
337
- ownerScope = getOwnerScope(scope), ownerValueAccessor2 = getOwnerValueAccessor(scope);
338
- let ownerMark = ownerScope[ownerValueAccessor2 + "#" /* Mark */], ownerHasRun = ownerMark === void 0 ? !ownerScope.u : ownerMark === 0;
339
- scope[markAccessor] = ownerHasRun ? 1 : 2, op = DIRTY;
340
- }
341
- --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;
342
- }
343
- };
344
- }
345
- function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
346
- let getOwnerValueAccessor = typeof ownerValueAccessor == "function" ? ownerValueAccessor : () => ownerValueAccessor, signalFn = closure(
347
- getOwnerValueAccessor,
348
- fn,
349
- getOwnerScope,
350
- getIntersection
351
- ), subscribeFns = /* @__PURE__ */ new WeakMap();
352
- return signalFn.g = (scope) => {
353
- let subscribeFn = (value2) => signalFn(scope, value2), ownerScope = getOwnerScope(scope), providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
354
- subscribeFns.set(scope, subscribeFn), (ownerScope[providerSubscriptionsAccessor] ||= /* @__PURE__ */ new Set()).add(subscribeFn);
355
- }, signalFn.j = (scope) => {
356
- let ownerScope = getOwnerScope(scope), providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
357
- ownerScope[providerSubscriptionsAccessor]?.delete(subscribeFns.get(scope)), subscribeFns.delete(scope);
358
- }, signalFn;
359
- }
360
- function childClosures(closureSignals, childAccessor) {
361
- let signal = (scope, op) => {
362
- let childScope = scope[childAccessor];
363
- for (let closureSignal of closureSignals)
364
- closureSignal(childScope, op);
365
- };
366
- return signal.g = (scope) => {
367
- let childScope = scope[childAccessor];
368
- for (let closureSignal of closureSignals)
369
- closureSignal.g?.(childScope);
370
- }, signal.j = (scope) => {
371
- let childScope = scope[childAccessor];
372
- for (let closureSignal of closureSignals)
373
- closureSignal.j?.(childScope);
374
- }, signal;
375
- }
376
- function dynamicSubscribers(valueAccessor) {
377
- let subscribersAccessor = valueAccessor + "*" /* Subscribers */;
378
- return (scope, op) => {
379
- let subscribers = scope[subscribersAccessor];
380
- if (subscribers)
381
- for (let subscriber of subscribers)
382
- subscriber(op);
383
- };
384
- }
385
- function setTagVar(scope, childAccessor, tagVarSignal2) {
386
- scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
387
- }
388
- var tagVarSignal = (scope, valueOrOp) => scope["/" /* TagVariable */]?.(valueOrOp);
389
- function setTagVarChange(scope, changeHandler) {
390
- scope["@" /* TagVariableChange */] = changeHandler;
391
- }
392
- var tagVarSignalChange = (scope, value2) => scope["@" /* TagVariableChange */]?.(value2), contentClosures = (content, childScope, op) => {
393
- let signals = content?.c;
394
- if (signals)
395
- for (let signal of signals)
396
- signal(childScope, op);
397
- };
398
- var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
399
- function nextTagId({ $global }) {
400
- let id = tagIdsByGlobal.get($global) || 0;
401
- return tagIdsByGlobal.set($global, id + 1), "c" + $global.runtimeId + $global.renderId + id.toString(36);
402
- }
403
- function inChild(childAccessor, signal) {
404
- return (scope, valueOrOp) => {
405
- signal(scope[childAccessor], valueOrOp);
406
- };
407
- }
408
- function intersections(signals) {
409
- return (scope, op) => {
410
- for (let signal of signals)
411
- signal(scope, op);
412
- };
413
- }
414
- function effect(id, fn) {
415
- return register(id, fn), (scope) => {
416
- queueEffect(scope, fn);
417
- };
418
- }
419
-
420
- // src/dom/queue.ts
421
- var pendingSignals = [], pendingEffects = [], rendering = !1;
422
- function queueSource(scope, signal, value2) {
423
- return schedule(), rendering = !0, signal(scope, MARK), rendering = !1, pendingSignals.push(scope, signal, value2), value2;
424
- }
425
- function queueEffect(scope, fn) {
426
- pendingEffects.push(scope, fn);
427
- }
428
- function run() {
429
- let signals = pendingSignals, effects = pendingEffects;
430
- try {
431
- rendering = !0, pendingSignals = [], runSignals(signals);
432
- } finally {
433
- rendering = !1;
434
- }
435
- pendingEffects = [], runEffects(effects);
436
- }
437
- function prepareEffects(fn) {
438
- let prevSignals = pendingSignals, prevEffects = pendingEffects, preparedEffects = pendingEffects = [], preparedSignals = pendingSignals = [];
439
- try {
440
- rendering = !0, fn(), pendingSignals = prevSignals, runSignals(preparedSignals);
441
- } finally {
442
- rendering = !1, pendingSignals = prevSignals, pendingEffects = prevEffects;
443
- }
444
- return preparedEffects;
445
- }
446
- function runEffects(effects = pendingEffects) {
447
- for (let i = 0; i < effects.length; i += 2 /* Total */) {
448
- let scope = effects[i], fn = effects[i + 1];
449
- fn(scope, scope);
450
- }
451
- }
452
- function runSignals(signals) {
453
- for (let i = 0; i < signals.length; i += 3 /* Total */) {
454
- let scope = signals[i + 0 /* Scope */], signal = signals[i + 1 /* Signal */], value2 = signals[i + 2 /* Value */];
455
- signal(scope, value2);
456
- }
457
- }
458
-
459
- // src/dom/abort-signal.ts
460
- function resetAbortSignal(scope, id) {
461
- let controllers = scope.l;
462
- if (controllers) {
463
- let ctrl = controllers.get(id);
464
- ctrl && (queueEffect(null, () => ctrl.abort()), controllers.delete(id));
465
- }
466
- }
467
- function getAbortSignal(scope, id) {
468
- let controllers = scope.l ||= /* @__PURE__ */ new Map(), controller = controllers.get(id);
469
- return controller || (onDestroy(scope), controllers.set(id, controller = new AbortController())), controller.signal;
470
- }
471
-
472
- // src/common/compat-meta.ts
473
- var prefix = "$C_", RENDERER_REGISTER_ID = prefix + "r", SET_SCOPE_REGISTER_ID = prefix + "s";
474
-
475
172
  // src/common/helpers.ts
476
173
  function classValue(value2) {
477
174
  return toDelimitedString(value2, " ", stringifyClassObject);
@@ -520,55 +217,55 @@ function normalizeDynamicRenderer(value2) {
520
217
 
521
218
  // src/dom/reconcile.ts
522
219
  var WRONG_POS = 2147483647;
523
- function reconcile(parent, oldScopes, newScopes, afterReference) {
524
- 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;
220
+ function reconcile(parent, oldBranches, newBranches, afterReference) {
221
+ 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;
525
222
  outer: {
526
- for (; oldStartScope === newStartScope; ) {
223
+ for (; oldStartBranch === newStartBranch; ) {
527
224
  if (++oldStart, ++newStart, oldStart > oldEnd || newStart > newEnd)
528
225
  break outer;
529
- oldStartScope = oldScopes[oldStart], newStartScope = newScopes[newStart];
226
+ oldStartBranch = oldBranches[oldStart], newStartBranch = newBranches[newStart];
530
227
  }
531
- for (; oldEndScope === newEndScope; ) {
228
+ for (; oldEndBranch === newEndBranch; ) {
532
229
  if (--oldEnd, --newEnd, oldStart > oldEnd || newStart > newEnd)
533
230
  break outer;
534
- oldEndScope = oldScopes[oldEnd], newEndScope = newScopes[newEnd];
231
+ oldEndBranch = oldBranches[oldEnd], newEndBranch = newBranches[newEnd];
535
232
  }
536
233
  }
537
234
  if (oldStart > oldEnd) {
538
235
  if (newStart <= newEnd) {
539
- k = newEnd + 1, nextSibling = k < newScopes.length ? newScopes[k].a : afterReference;
236
+ k = newEnd + 1, nextSibling = k < newBranches.length ? newBranches[k].a : afterReference;
540
237
  do
541
- insertBefore(newScopes[newStart++], parent, nextSibling);
238
+ insertBefore(newBranches[newStart++], parent, nextSibling);
542
239
  while (newStart <= newEnd);
543
240
  }
544
241
  } else if (newStart > newEnd)
545
242
  do
546
- removeAndDestroyScope(oldScopes[oldStart++]);
243
+ removeAndDestroyBranch(oldBranches[oldStart++]);
547
244
  while (oldStart <= oldEnd);
548
245
  else {
549
- let oldLength = oldEnd - oldStart + 1, newLength = newEnd - newStart + 1, aNullable = oldScopes, sources = new Array(newLength);
246
+ let oldLength = oldEnd - oldStart + 1, newLength = newEnd - newStart + 1, aNullable = oldBranches, sources = new Array(newLength);
550
247
  for (i = 0; i < newLength; ++i)
551
248
  sources[i] = -1;
552
249
  let pos = 0, synced = 0, keyIndex = /* @__PURE__ */ new Map();
553
250
  for (j = newStart; j <= newEnd; ++j)
554
- keyIndex.set(newScopes[j], j);
251
+ keyIndex.set(newBranches[j], j);
555
252
  for (i = oldStart; i <= oldEnd && synced < newLength; ++i)
556
- 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);
557
- if (oldLength === oldScopes.length && synced === 0) {
253
+ 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);
254
+ if (oldLength === oldBranches.length && synced === 0) {
558
255
  for (; newStart < newLength; ++newStart)
559
- insertBefore(newScopes[newStart], parent, afterReference);
256
+ insertBefore(newBranches[newStart], parent, afterReference);
560
257
  for (; oldStart < oldLength; ++oldStart)
561
- removeAndDestroyScope(oldScopes[oldStart]);
258
+ removeAndDestroyBranch(oldBranches[oldStart]);
562
259
  } else {
563
260
  for (i = oldLength - synced; i > 0; )
564
- oldScope = aNullable[oldStart++], oldScope !== null && (removeAndDestroyScope(oldScope), i--);
261
+ oldBranch = aNullable[oldStart++], oldBranch !== null && (removeAndDestroyBranch(oldBranch), i--);
565
262
  if (pos === WRONG_POS) {
566
263
  let seq = longestIncreasingSubsequence(sources);
567
- for (j = seq.length - 1, k = newScopes.length, i = newLength - 1; i >= 0; --i)
568
- 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;
264
+ for (j = seq.length - 1, k = newBranches.length, i = newLength - 1; i >= 0; --i)
265
+ 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;
569
266
  } else if (synced !== newLength)
570
- for (k = newScopes.length, i = newLength - 1; i >= 0; --i)
571
- sources[i] === -1 && (pos = i + newStart, newScope = newScopes[pos++], nextSibling = pos < k ? newScopes[pos].a : afterReference, insertBefore(newScope, parent, nextSibling));
267
+ for (k = newBranches.length, i = newLength - 1; i >= 0; --i)
268
+ sources[i] === -1 && (pos = i + newStart, newBranch = newBranches[pos++], nextSibling = pos < k ? newBranches[pos].a : afterReference, insertBefore(newBranch, parent, nextSibling));
572
269
  }
573
270
  }
574
271
  }
@@ -613,7 +310,7 @@ function handleDelegated(ev) {
613
310
  if (target) {
614
311
  let handlersByElement = elementHandlersByEvent.get(ev.type);
615
312
  if (handlersByElement.get(target)?.(ev, target), ev.bubbles)
616
- for (; (target = target.parentElement) && !ev.cancelBubble; )
313
+ for (; (target = target.parentNode) && !ev.cancelBubble; )
617
314
  handlersByElement.get(target)?.(ev, target);
618
315
  }
619
316
  }
@@ -640,6 +337,132 @@ function stripSpacesAndPunctuation(str) {
640
337
  return str.replace(/[^\p{L}\p{N}]/gu, "");
641
338
  }
642
339
 
340
+ // src/common/meta.ts
341
+ var DEFAULT_RUNTIME_ID = "M", DEFAULT_RENDER_ID = "_";
342
+
343
+ // src/dom/resume.ts
344
+ var registeredValues = {}, Render = class {
345
+ o = [];
346
+ p = {};
347
+ z = {
348
+ _: registeredValues
349
+ };
350
+ constructor(renders, runtimeId, renderId) {
351
+ this.A = renders, this.B = runtimeId, this.q = renderId, this.s = renders[renderId], this.t();
352
+ }
353
+ w() {
354
+ this.s.w(), this.t();
355
+ }
356
+ t() {
357
+ let data2 = this.s, serializeContext = this.z, scopeLookup = this.p, visits = data2.v, branchIds = /* @__PURE__ */ new Set(), parentBranchIds = /* @__PURE__ */ new Map();
358
+ if (visits.length) {
359
+ let commentPrefixLen = data2.i.length, closestBranchMarkers = /* @__PURE__ */ new Map();
360
+ data2.v = [];
361
+ let branchEnd = (branchId, visit, curNode) => {
362
+ let branch = scopeLookup[branchId] ||= {}, endNode = curNode;
363
+ for (; (endNode = endNode.previousSibling).nodeType === 8; ) ;
364
+ branch.c = endNode, branch.a ||= endNode;
365
+ for (let [markerScopeId, markerNode] of closestBranchMarkers)
366
+ branch.a.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2 && (parentBranchIds.set(markerScopeId, branchId), closestBranchMarkers.delete(markerScopeId));
367
+ return branchIds.add(branchId), closestBranchMarkers.set(branchId, visit), branch;
368
+ };
369
+ for (let visit of visits) {
370
+ let commentText = visit.data, dataIndex = commentText.indexOf(" ") + 1, scopeId = commentText.slice(
371
+ commentPrefixLen + 1,
372
+ dataIndex ? dataIndex - 1 : commentText.length
373
+ ), scope = scopeLookup[scopeId] ||= {}, data3 = dataIndex ? commentText.slice(dataIndex) : "", token = commentText[commentPrefixLen];
374
+ if (token === "*" /* Node */)
375
+ scope[data3] = visit.previousSibling;
376
+ else if (token === "$" /* ClosestBranch */)
377
+ closestBranchMarkers.set(scopeId, visit);
378
+ else if (token === "[" /* BranchStart */)
379
+ this.f && (dataIndex && branchEnd(this.f, visit, visit), this.o.push(this.f)), this.f = scopeId, scope.a = visit;
380
+ else if (token === "]" /* BranchEnd */) {
381
+ scope[data3] = visit;
382
+ let curParent = visit.parentNode, startNode = branchEnd(
383
+ this.f,
384
+ visit,
385
+ visit
386
+ ).a;
387
+ curParent !== startNode.parentNode && curParent.prepend(startNode), this.f = this.o.pop();
388
+ } else if (token === "|" /* BranchSingleNode */) {
389
+ let next = data3.indexOf(" "), curNode = scope[~next ? data3.slice(0, next) : data3] = visit;
390
+ for (; ~next; ) {
391
+ let start = next + 1;
392
+ next = data3.indexOf(" ", start);
393
+ let childScopeId = data3.slice(start, ~next ? next : data3.length);
394
+ curNode = branchEnd(childScopeId, visit, curNode).c;
395
+ }
396
+ }
397
+ }
398
+ }
399
+ let resumes = data2.r;
400
+ if (resumes) {
401
+ data2.r = [];
402
+ let len = resumes.length, i = 0;
403
+ try {
404
+ for (isResuming = !0; i < len; ) {
405
+ let resumeData = resumes[i++];
406
+ if (typeof resumeData == "function") {
407
+ let scopes = resumeData(serializeContext), { $global } = scopeLookup;
408
+ $global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = this.B, $global.renderId = this.q);
409
+ for (let scopeId in scopes)
410
+ if (scopeId !== "$") {
411
+ let scope = scopes[scopeId], prevScope = scopeLookup[scopeId];
412
+ scope.$global = $global, prevScope !== scope && (scopeLookup[scopeId] = Object.assign(
413
+ scope,
414
+ prevScope
415
+ ));
416
+ let parentBranchId = parentBranchIds.get(scopeId);
417
+ if (parentBranchId && (scope.b = scopes[parentBranchId]), branchIds.has(scopeId)) {
418
+ let branch = scope, parentBranch = branch.b;
419
+ scope.b = branch, parentBranch && (branch.C = parentBranch, (parentBranch.m ||= /* @__PURE__ */ new Set()).add(branch));
420
+ }
421
+ }
422
+ } else i === len || typeof resumes[i] != "string" ? delete this.A[this.q] : registeredValues[resumes[i++]](
423
+ scopeLookup[resumeData],
424
+ scopeLookup[resumeData]
425
+ );
426
+ }
427
+ } finally {
428
+ isResuming = !1;
429
+ }
430
+ }
431
+ }
432
+ }, isResuming = !1;
433
+ function register(id, obj) {
434
+ return registeredValues[id] = obj, obj;
435
+ }
436
+ function registerBoundSignal(id, signal) {
437
+ return registeredValues[id] = (scope) => (valueOrOp) => signal(scope, valueOrOp), signal;
438
+ }
439
+ function getRegisteredWithScope(id, scope) {
440
+ let val = registeredValues[id];
441
+ return scope ? val(scope) : val;
442
+ }
443
+ function init(runtimeId = DEFAULT_RUNTIME_ID) {
444
+ let resumeRender = (renderId) => resumeRender[renderId] = renders[renderId] = new Render(renders, runtimeId, renderId), renders;
445
+ window[runtimeId] ? setRenders(window[runtimeId]) : Object.defineProperty(window, runtimeId, {
446
+ configurable: !0,
447
+ set: setRenders
448
+ });
449
+ function setRenders(v) {
450
+ renders = v;
451
+ for (let renderId in v)
452
+ resumeRender(renderId);
453
+ Object.defineProperty(window, runtimeId, {
454
+ configurable: !0,
455
+ value: resumeRender
456
+ });
457
+ }
458
+ }
459
+ function registerSubscriber(id, signal) {
460
+ return register(id, signal.D), signal;
461
+ }
462
+ function nodeRef(id, key) {
463
+ return register(id, (scope) => () => scope[key]);
464
+ }
465
+
643
466
  // src/dom/controllable.ts
644
467
  function controllable_input_checked(scope, nodeAccessor, checked, checkedChange) {
645
468
  setCheckboxValue(
@@ -693,10 +516,13 @@ function controllable_input_value_effect(scope, nodeAccessor) {
693
516
  });
694
517
  }
695
518
  function controllable_select_value(scope, nodeAccessor, value2, valueChange) {
696
- scope[nodeAccessor + ";" /* ControlledHandler */] = valueChange, valueChange ? (scope[nodeAccessor + "=" /* ControlledType */] = 3 /* SelectValue */, scope[nodeAccessor + ":" /* ControlledValue */] = value2) : scope[nodeAccessor + "=" /* ControlledType */] = 5 /* None */, setSelectOptions(
697
- scope[nodeAccessor],
698
- value2,
699
- valueChange
519
+ scope[nodeAccessor + ";" /* ControlledHandler */] = valueChange, valueChange ? (scope[nodeAccessor + "=" /* ControlledType */] = 3 /* SelectValue */, scope[nodeAccessor + ":" /* ControlledValue */] = value2) : scope[nodeAccessor + "=" /* ControlledType */] = 5 /* None */, pendingEffects.unshift(
520
+ scope,
521
+ () => setSelectOptions(
522
+ scope[nodeAccessor],
523
+ value2,
524
+ valueChange
525
+ )
700
526
  );
701
527
  }
702
528
  function controllable_select_value_effect(scope, nodeAccessor) {
@@ -810,16 +636,22 @@ function toValueProp(it) {
810
636
  }
811
637
 
812
638
  // src/dom/parse-html.ts
813
- var fallback = /* @__PURE__ */ document.createTextNode(""), parser = /* @__PURE__ */ new Range();
639
+ var fallback = /* @__PURE__ */ new Text(), parser = /* @__PURE__ */ document.createElement("template");
814
640
  function parseHTML(html2) {
815
- return parser.createContextualFragment(html2);
641
+ return parser.innerHTML = html2, parser.content;
816
642
  }
817
643
  function parseHTMLOrSingleNode(html2) {
818
644
  let content = parseHTML(html2);
819
- return content.firstChild ? content.firstChild === content.lastChild && // If the firstChild is a comment it's possible its
820
- // a single replaced node, in which case the walker can't replace
821
- // the node itself.
822
- content.firstChild.nodeType !== 8 ? content.firstChild : content : fallback;
645
+ if (content.firstChild) {
646
+ if (content.firstChild === content.lastChild && // If the firstChild is a comment it's possible its
647
+ // a single replaced node, in which case the walker can't replace
648
+ // the node itself.
649
+ content.firstChild.nodeType !== 8)
650
+ return content.firstChild;
651
+ let fragment = new DocumentFragment();
652
+ return fragment.appendChild(content), fragment;
653
+ }
654
+ return fallback;
823
655
  }
824
656
 
825
657
  // src/dom/dom.ts
@@ -845,8 +677,10 @@ function textContent(node, value2) {
845
677
  }
846
678
  function attrs(scope, nodeAccessor, nextAttrs) {
847
679
  let el = scope[nodeAccessor];
848
- for (let { name } of el.attributes)
680
+ for (let i = el.attributes.length; i--; ) {
681
+ let { name } = el.attributes.item(i);
849
682
  nextAttrs && (name in nextAttrs || hasAttrAlias(el, name, nextAttrs)) || el.removeAttribute(name);
683
+ }
850
684
  attrsInternal(scope, nodeAccessor, nextAttrs);
851
685
  }
852
686
  function hasAttrAlias(element, attr2, nextAttrs) {
@@ -854,8 +688,10 @@ function hasAttrAlias(element, attr2, nextAttrs) {
854
688
  }
855
689
  function partialAttrs(scope, nodeAccessor, nextAttrs, skip) {
856
690
  let el = scope[nodeAccessor], partial = {};
857
- for (let { name } of el.attributes)
691
+ for (let i = el.attributes.length; i--; ) {
692
+ let { name } = el.attributes.item(i);
858
693
  !skip[name] && !(nextAttrs && name in nextAttrs) && el.removeAttribute(name);
694
+ }
859
695
  for (let key in nextAttrs)
860
696
  skip[key] || (partial[key] = nextAttrs[key]);
861
697
  attrsInternal(scope, nodeAccessor, partial);
@@ -995,11 +831,11 @@ function trimWalkString(walkString) {
995
831
  return walkString.slice(0, end + 1);
996
832
  }
997
833
  function walk(startNode, walkCodes, scope) {
998
- walker.currentNode = startNode, walkInternal(walkCodes, scope, scope, 0), walker.currentNode = document.documentElement;
834
+ walker.currentNode = startNode, walkInternal(walkCodes, scope, 0), walker.currentNode = document;
999
835
  }
1000
- function walkInternal(walkCodes, scope, cleanupOwnerScope, currentWalkIndex) {
836
+ function walkInternal(walkCodes, scope, currentWalkIndex) {
1001
837
  let value2, storedMultiplier = 0, currentMultiplier = 0, currentScopeIndex = 0;
1002
- for (cleanupOwnerScope !== scope && (scope.d = cleanupOwnerScope); value2 = walkCodes.charCodeAt(currentWalkIndex++); )
838
+ for (; value2 = walkCodes.charCodeAt(currentWalkIndex++); )
1003
839
  if (currentMultiplier = storedMultiplier, storedMultiplier = 0, value2 >= 117 /* Multiplier */)
1004
840
  storedMultiplier = currentMultiplier * 10 /* Multiplier */ + value2 - 117 /* Multiplier */;
1005
841
  else if (value2 >= 107 /* Out */) {
@@ -1012,20 +848,16 @@ function walkInternal(walkCodes, scope, cleanupOwnerScope, currentWalkIndex) {
1012
848
  else if (value2 >= 67 /* Next */)
1013
849
  for (value2 = 20 /* Next */ * currentMultiplier + value2 - 67 /* Next */; value2--; )
1014
850
  walker.nextNode();
1015
- else if (value2 === 47 /* BeginChild */)
1016
- currentWalkIndex = walkInternal(
1017
- walkCodes,
1018
- scope[currentScopeIndex++] = createScope(scope.$global),
1019
- cleanupOwnerScope,
1020
- currentWalkIndex
1021
- );
1022
- else {
851
+ else if (value2 === 47 /* BeginChild */) {
852
+ let childScope = scope[currentScopeIndex++] = createScope(scope.$global);
853
+ childScope.a = walker.currentNode, childScope.b = scope.b, currentWalkIndex = walkInternal(walkCodes, childScope, currentWalkIndex);
854
+ } else {
1023
855
  if (value2 === 38 /* EndChild */)
1024
856
  return currentWalkIndex;
1025
857
  if (value2 === 32 /* Get */)
1026
858
  scope[currentScopeIndex++] = walker.currentNode;
1027
859
  else {
1028
- let newNode = scope[currentScopeIndex++] = document.createTextNode(""), current = walker.currentNode;
860
+ let newNode = scope[currentScopeIndex++] = new Text(), current = walker.currentNode;
1029
861
  current.parentNode.replaceChild(newNode, current), walker.currentNode = newNode;
1030
862
  }
1031
863
  }
@@ -1033,26 +865,35 @@ function walkInternal(walkCodes, scope, cleanupOwnerScope, currentWalkIndex) {
1033
865
  }
1034
866
 
1035
867
  // src/dom/renderer.ts
1036
- function createScopeWithRenderer(renderer, $global, ownerScope) {
1037
- let newScope = createScope($global);
1038
- if (newScope._ = newScope.d = renderer.B || ownerScope, newScope.x = renderer, initRenderer(renderer, newScope), renderer.c)
1039
- for (let signal of renderer.c)
1040
- signal.g?.(newScope);
1041
- return newScope;
1042
- }
1043
- function createScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, ownerScope) {
868
+ function createBranchScopeWithRenderer(renderer, $global, parentScope) {
869
+ let branch = createBranch(
870
+ $global,
871
+ renderer.u || parentScope,
872
+ parentScope
873
+ );
874
+ return initRenderer(renderer, branch), branch;
875
+ }
876
+ function createBranchScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, parentScope) {
1044
877
  if (typeof tagNameOrRenderer != "string")
1045
- return createScopeWithRenderer(tagNameOrRenderer, $global, ownerScope);
1046
- let newScope = createScope($global);
1047
- return newScope._ = newScope.d = ownerScope, newScope[0] = newScope.a = newScope.b = document.createElement(tagNameOrRenderer), newScope;
878
+ return createBranchScopeWithRenderer(
879
+ tagNameOrRenderer,
880
+ $global,
881
+ parentScope
882
+ );
883
+ let branch = createBranch($global, parentScope, parentScope);
884
+ return branch[0] = branch.a = branch.c = document.createElement(tagNameOrRenderer), branch;
885
+ }
886
+ function createBranch($global, ownerScope, parentScope) {
887
+ let branch = createScope($global), parentBranch = parentScope.b;
888
+ return branch._ = ownerScope, branch.b = branch, parentBranch && (branch.C = parentBranch, (parentBranch.m ||= /* @__PURE__ */ new Set()).add(branch)), branch;
1048
889
  }
1049
890
  function initRenderer(renderer, scope) {
1050
- let dom = renderer.k();
891
+ let dom = renderer.l();
1051
892
  return walk(
1052
893
  dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom,
1053
- renderer.C,
894
+ renderer.E,
1054
895
  scope
1055
- ), scope.a = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom, scope.b = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom, renderer.s && renderer.s(scope), dom;
896
+ ), 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;
1056
897
  }
1057
898
  function dynamicTagAttrs(nodeAccessor, getContent, inputIsArgs) {
1058
899
  return (scope, attrsOrOp) => {
@@ -1079,36 +920,27 @@ function dynamicTagAttrs(nodeAccessor, getContent, inputIsArgs) {
1079
920
  }
1080
921
  };
1081
922
  }
1082
- function createRendererWithOwner(template, rawWalks, setup, getClosureSignals, getArgs) {
1083
- let args, closureSignals, id = {}, walks = rawWalks ? /* @__PURE__ */ trimWalkString(rawWalks) : " ";
923
+ function createRendererWithOwner(template, rawWalks, setup, getArgs) {
924
+ let args, id = {}, walks = rawWalks ? /* @__PURE__ */ trimWalkString(rawWalks) : " ";
1084
925
  return (owner) => ({
1085
- t: id,
1086
- D: template,
1087
- C: walks,
1088
- s: setup,
1089
- k: _clone,
1090
- B: owner,
1091
- E: void 0,
926
+ j: id,
927
+ F: template,
928
+ E: walks,
929
+ x: setup,
930
+ l: _clone,
931
+ u: owner,
932
+ G: void 0,
1092
933
  get e() {
1093
934
  return args ||= getArgs?.();
1094
- },
1095
- get c() {
1096
- return closureSignals ||= new Set(getClosureSignals?.());
1097
935
  }
1098
936
  });
1099
937
  }
1100
- function createRenderer(template, walks, setup, getClosureSignals, getArgs) {
1101
- return createRendererWithOwner(
1102
- template,
1103
- walks,
1104
- setup,
1105
- getClosureSignals,
1106
- getArgs
1107
- )();
938
+ function createRenderer(template, walks, setup, getArgs) {
939
+ return createRendererWithOwner(template, walks, setup, getArgs)();
1108
940
  }
1109
941
  function _clone() {
1110
- return (this.E ||= parseHTMLOrSingleNode(
1111
- this.D
942
+ return (this.G ||= parseHTMLOrSingleNode(
943
+ this.F
1112
944
  )).cloneNode(!0);
1113
945
  }
1114
946
 
@@ -1117,41 +949,27 @@ function patchConditionals(fn) {
1117
949
  conditional = fn(conditional), conditionalOnlyChild = fn(conditionalOnlyChild);
1118
950
  }
1119
951
  var conditional = function(nodeAccessor, fn, getIntersection) {
1120
- let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
952
+ let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1121
953
  return (scope, newRendererOrOp) => {
1122
954
  if (newRendererOrOp === DIRTY) return;
1123
955
  let currentRenderer = scope[rendererAccessor], op = newRendererOrOp;
1124
956
  if (newRendererOrOp !== MARK && newRendererOrOp !== CLEAN) {
1125
957
  let normalizedRenderer = normalizeDynamicRenderer(newRendererOrOp);
1126
- isDifferentRenderer(normalizedRenderer, currentRenderer) ? (currentRenderer = scope[rendererAccessor] = normalizedRenderer, setConditionalRenderer(scope, nodeAccessor, normalizedRenderer), fn && fn(scope), op = DIRTY) : op = CLEAN;
958
+ isDifferentRenderer(normalizedRenderer, currentRenderer) ? (setConditionalRenderer(scope, nodeAccessor, normalizedRenderer), fn && fn(scope), op = DIRTY) : op = CLEAN;
1127
959
  }
1128
- intersection2?.(scope, op), contentClosures(currentRenderer, scope[childScopeAccessor], op);
960
+ intersection2?.(scope, op);
1129
961
  };
1130
962
  };
1131
- function inConditionalScope(signal, nodeAccessor) {
1132
- let scopeAccessor = nodeAccessor + "!" /* ConditionalScope */, rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
1133
- return (scope, op) => {
1134
- let conditionalScope = scope[scopeAccessor];
1135
- if (conditionalScope) {
1136
- let conditionalRenderer = scope[rendererAccessor];
1137
- (!conditionalRenderer?.c || conditionalRenderer.c.has(signal)) && signal(conditionalScope, op);
1138
- }
1139
- };
1140
- }
1141
963
  function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
1142
- let newScope, prevScope = scope[nodeAccessor + "!" /* ConditionalScope */];
1143
- newRenderer ? (newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithTagNameOrRenderer(
1144
- newRenderer,
1145
- scope.$global,
1146
- scope
1147
- ), prevScope = prevScope || getEmptyScope(scope[nodeAccessor])) : (newScope = getEmptyScope(scope[nodeAccessor]), scope[nodeAccessor + "!" /* ConditionalScope */] = void 0), insertBefore(
1148
- newScope,
1149
- prevScope.a.parentNode,
1150
- prevScope.a
1151
- ), removeAndDestroyScope(prevScope);
964
+ let newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0, prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyScope(scope[nodeAccessor]);
965
+ insertBefore(
966
+ newBranch || getEmptyScope(scope[nodeAccessor]),
967
+ prevBranch.a.parentNode,
968
+ prevBranch.a
969
+ ), removeAndDestroyBranch(prevBranch), scope[nodeAccessor + "(" /* ConditionalRenderer */] = newRenderer, scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
1152
970
  }
1153
971
  var conditionalOnlyChild = function(nodeAccessor, fn, getIntersection) {
1154
- let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
972
+ let rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1155
973
  return (scope, newRendererOrOp) => {
1156
974
  if (newRendererOrOp === DIRTY) return;
1157
975
  let currentRenderer = scope[rendererAccessor], op = newRendererOrOp;
@@ -1163,18 +981,16 @@ var conditionalOnlyChild = function(nodeAccessor, fn, getIntersection) {
1163
981
  normalizedRenderer
1164
982
  ), fn && fn(scope), op = DIRTY) : op = CLEAN;
1165
983
  }
1166
- intersection2?.(scope, op), contentClosures(currentRenderer, scope[childScopeAccessor], op);
984
+ intersection2?.(scope, op);
1167
985
  };
1168
986
  };
1169
987
  function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
1170
- let prevScope = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor];
1171
- if (referenceNode.textContent = "", newRenderer) {
1172
- let newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope);
1173
- insertBefore(newScope, referenceNode, null);
1174
- }
1175
- prevScope && destroyScope(prevScope);
988
+ let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor], newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0;
989
+ referenceNode.textContent = "", newBranch && insertBefore(newBranch, referenceNode, null), prevBranch && destroyBranch(prevBranch), scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
1176
990
  }
1177
- var emptyMarkerMap = /* @__PURE__ */ new Map([[Symbol(), getEmptyScope(void 0)]]), emptyMarkerArray = [
991
+ var emptyMarkerMap = /* @__PURE__ */ new Map([
992
+ [Symbol(), getEmptyScope(void 0)]
993
+ ]), emptyMarkerArray = [
1178
994
  /* @__PURE__ */ getEmptyScope(void 0)
1179
995
  ], emptyMap = /* @__PURE__ */ new Map(), emptyArray = [];
1180
996
  function loopOf(nodeAccessor, renderer) {
@@ -1204,31 +1020,25 @@ function loopTo(nodeAccessor, renderer) {
1204
1020
  );
1205
1021
  }
1206
1022
  function loop(nodeAccessor, renderer, forEach) {
1207
- let loopScopeAccessor = nodeAccessor + "!" /* LoopScopeArray */, closureSignals = renderer.c, params = renderer.e;
1023
+ let loopScopeAccessor = nodeAccessor + "!" /* LoopScopeArray */, params = renderer.e;
1208
1024
  return (scope, valueOrOp) => {
1209
1025
  if (valueOrOp === DIRTY) return;
1210
1026
  if (valueOrOp === MARK || valueOrOp === CLEAN) {
1211
- let loopScopes = scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1212
- if (loopScopes !== emptyMarkerArray)
1213
- for (let childScope of loopScopes) {
1214
- params?.(childScope, valueOrOp);
1215
- for (let signal of closureSignals)
1216
- signal(childScope, valueOrOp);
1217
- }
1027
+ let loopBranches = scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1028
+ if (loopBranches !== emptyMarkerArray)
1029
+ for (let branch of loopBranches)
1030
+ params?.(branch, valueOrOp);
1218
1031
  return;
1219
1032
  }
1220
1033
  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;
1221
1034
  if (forEach(valueOrOp, (key, args) => {
1222
- let childScope = oldMap.get(key), closureOp = CLEAN;
1223
- if (childScope || (childScope = createScopeWithRenderer(renderer, scope.$global, scope), closureOp = DIRTY), params && params(childScope, args), closureSignals)
1224
- for (let signal of closureSignals)
1225
- signal(childScope, closureOp);
1226
- newMap ? (newMap.set(key, childScope), newArray.push(childScope)) : (newMap = /* @__PURE__ */ new Map([[key, childScope]]), newArray = [childScope]);
1227
- }), newMap || (referenceIsMarker ? (newMap = emptyMarkerMap, newArray = emptyMarkerArray, getEmptyScope(referenceNode)) : (oldArray.forEach(destroyScope), referenceNode.textContent = "", newMap = emptyMap, newArray = emptyArray, needsReconciliation = !1)), needsReconciliation) {
1035
+ let branch = oldMap.get(key);
1036
+ 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]);
1037
+ }), newMap || (referenceIsMarker ? (newMap = emptyMarkerMap, newArray = emptyMarkerArray, getEmptyScope(referenceNode)) : (oldArray.forEach(destroyBranch), referenceNode.textContent = "", newMap = emptyMap, newArray = emptyArray, needsReconciliation = !1)), needsReconciliation) {
1228
1038
  if (referenceIsMarker) {
1229
1039
  oldMap === emptyMarkerMap && getEmptyScope(referenceNode);
1230
1040
  let oldLastChild = oldArray[oldArray.length - 1];
1231
- afterReference = oldLastChild.b.nextSibling, parentNode = oldLastChild.a.parentNode;
1041
+ afterReference = oldLastChild.c.nextSibling, parentNode = oldLastChild.a.parentNode;
1232
1042
  } else
1233
1043
  afterReference = null, parentNode = referenceNode;
1234
1044
  reconcile(parentNode, oldArray, newArray, afterReference);
@@ -1236,15 +1046,6 @@ function loop(nodeAccessor, renderer, forEach) {
1236
1046
  scope[nodeAccessor + "(" /* LoopScopeMap */] = newMap, scope[nodeAccessor + "!" /* LoopScopeArray */] = newArray;
1237
1047
  };
1238
1048
  }
1239
- function inLoopScope(signal, loopNodeAccessor) {
1240
- let loopScopeAccessor = loopNodeAccessor + "!" /* LoopScopeArray */;
1241
- return (scope, op) => {
1242
- let loopScopes = scope[loopScopeAccessor] ?? scope[loopNodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1243
- if (loopScopes !== emptyMarkerArray)
1244
- for (let scope2 of loopScopes)
1245
- signal(scope2, op);
1246
- };
1247
- }
1248
1049
  function bySecondArg(_item, index) {
1249
1050
  return index;
1250
1051
  }
@@ -1252,9 +1053,185 @@ function byFirstArg(name) {
1252
1053
  return name;
1253
1054
  }
1254
1055
  function isDifferentRenderer(a, b) {
1255
- return a !== b && (a?.t || 0) !== b?.t;
1056
+ return a !== b && (a?.j || 0) !== b?.j;
1057
+ }
1058
+
1059
+ // src/dom/signals.ts
1060
+ var MARK = {}, CLEAN = {}, DIRTY = {};
1061
+ function state(valueAccessor, fn, getIntersection) {
1062
+ let valueSignal = value(valueAccessor, fn, getIntersection), markAccessor = valueAccessor + "#" /* Mark */, valueChangeAccessor = valueAccessor + "@" /* TagVariableChange */;
1063
+ return (scope, valueOrOp, valueChange) => (rendering ? valueSignal(
1064
+ scope,
1065
+ valueOrOp === MARK || valueOrOp === CLEAN || valueOrOp === DIRTY || (scope[valueChangeAccessor] = valueChange) || scope[markAccessor] === void 0 ? valueOrOp : CLEAN
1066
+ ) : scope[valueChangeAccessor] ? scope[valueChangeAccessor](valueOrOp) : queueSource(scope, valueSignal, valueOrOp), valueOrOp);
1067
+ }
1068
+ function value(valueAccessor, fn, getIntersection) {
1069
+ let markAccessor = valueAccessor + "#" /* Mark */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1070
+ return (scope, valueOrOp) => {
1071
+ if (valueOrOp === MARK)
1072
+ (scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1 && intersection2?.(scope, MARK);
1073
+ else if (valueOrOp !== DIRTY) {
1074
+ let existing = scope[markAccessor] !== void 0;
1075
+ (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]--;
1076
+ }
1077
+ };
1078
+ }
1079
+ var accessorId = 0;
1080
+ function intersection(count, fn, getIntersection) {
1081
+ let dirtyAccessor = "?" /* Dynamic */ + accessorId++, markAccessor = dirtyAccessor + "#" /* Mark */, intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1082
+ return (scope, op) => {
1083
+ 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;
1084
+ };
1085
+ }
1086
+ function closure(fn, getIntersection) {
1087
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1088
+ return (scope, valueOrOp) => {
1089
+ valueOrOp === MARK ? intersection2?.(scope, MARK) : (fn && fn(scope, valueOrOp), intersection2?.(scope, DIRTY));
1090
+ };
1091
+ }
1092
+ function loopClosure(ownerLoopNodeAccessor, fn, getIntersection) {
1093
+ let signal = closure(fn, getIntersection), loopScopeAccessor = ownerLoopNodeAccessor + "!" /* LoopScopeArray */, loopScopeMapAccessor = ownerLoopNodeAccessor + "(" /* LoopScopeMap */, helperSignal = (ownerScope, value2) => {
1094
+ let loopScopes = ownerScope[loopScopeAccessor] ?? ownerScope[loopScopeMapAccessor]?.values() ?? [];
1095
+ if (loopScopes !== emptyMarkerArray)
1096
+ for (let scope of loopScopes)
1097
+ scope.g || queueSource(scope, signal, value2);
1098
+ };
1099
+ return helperSignal._ = signal, helperSignal;
1100
+ }
1101
+ function conditionalClosure(ownerConditionalNodeAccessor, getRenderer, fn, getIntersection) {
1102
+ let signal = closure(fn, getIntersection), scopeAccessor = ownerConditionalNodeAccessor + "!" /* ConditionalScope */, rendererAccessor = ownerConditionalNodeAccessor + "(" /* ConditionalRenderer */, helperSignal = (scope, value2) => {
1103
+ let conditionalScope = scope[scopeAccessor];
1104
+ conditionalScope && !conditionalScope.g && scope[rendererAccessor]?.j === getRenderer().j && queueSource(conditionalScope, signal, value2);
1105
+ };
1106
+ return helperSignal._ = signal, helperSignal;
1107
+ }
1108
+ var defaultGetOwnerScope = (scope) => scope._;
1109
+ function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
1110
+ let ownerSubscribersAccessor = ownerValueAccessor + "*" /* Subscribers */, _signal = closure(fn, getIntersection), helperSignal = (ownerScope, value2) => {
1111
+ let subscribers = ownerScope[ownerSubscribersAccessor];
1112
+ if (subscribers)
1113
+ for (let subscriber of subscribers)
1114
+ subscriber.g || queueSource(subscriber, _signal, value2);
1115
+ }, setupSignal = (scope, value2) => {
1116
+ _signal(scope, value2), subscribe(scope);
1117
+ }, subscribe = (scope) => {
1118
+ (getOwnerScope(scope)[ownerSubscribersAccessor] ||= /* @__PURE__ */ new Set()).add(scope), getAbortSignal(scope, -1).addEventListener("abort", () => {
1119
+ getOwnerScope(scope)[ownerSubscribersAccessor].delete(scope);
1120
+ });
1121
+ };
1122
+ return helperSignal._ = setupSignal, helperSignal.D = subscribe, helperSignal;
1123
+ }
1124
+ function setTagVar(scope, childAccessor, tagVarSignal2) {
1125
+ scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
1126
+ }
1127
+ var tagVarSignal = (scope, valueOrOp) => scope["/" /* TagVariable */]?.(valueOrOp);
1128
+ function setTagVarChange(scope, changeHandler) {
1129
+ scope["@" /* TagVariableChange */] = changeHandler;
1130
+ }
1131
+ var tagVarSignalChange = (scope, value2) => scope["@" /* TagVariableChange */]?.(value2);
1132
+ var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
1133
+ function nextTagId({ $global }) {
1134
+ let id = tagIdsByGlobal.get($global) || 0;
1135
+ return tagIdsByGlobal.set($global, id + 1), "c" + $global.runtimeId + $global.renderId + id.toString(36);
1136
+ }
1137
+ function inChild(childAccessor, signal) {
1138
+ return (scope, valueOrOp) => {
1139
+ signal(scope[childAccessor], valueOrOp);
1140
+ };
1141
+ }
1142
+ function intersections(signals) {
1143
+ return (scope, op) => {
1144
+ for (let signal of signals)
1145
+ signal(scope, op);
1146
+ };
1147
+ }
1148
+ function effect(id, fn) {
1149
+ return register(id, fn), (scope) => {
1150
+ queueEffect(scope, fn);
1151
+ };
1152
+ }
1153
+
1154
+ // src/dom/queue.ts
1155
+ var pendingRender, pendingEffects = [], rendering = !1;
1156
+ function queueSource(scope, signal, value2) {
1157
+ schedule();
1158
+ let prevRendering = rendering;
1159
+ return rendering = !0, signal(scope, MARK), rendering = prevRendering, queueRender(scope, signal, value2), value2;
1160
+ }
1161
+ function queueRender(scope, signal, value2) {
1162
+ let nextRender = {
1163
+ k: scope,
1164
+ H: signal,
1165
+ I: value2,
1166
+ d: void 0
1167
+ };
1168
+ if (!pendingRender)
1169
+ pendingRender = nextRender;
1170
+ else if (comparePendingRenders(pendingRender, nextRender) < 0)
1171
+ nextRender.d = pendingRender, pendingRender = nextRender;
1172
+ else {
1173
+ let curRender = pendingRender;
1174
+ for (; curRender.d && comparePendingRenders(curRender.d, nextRender) >= 0; )
1175
+ curRender = curRender.d;
1176
+ nextRender.d = curRender.d, curRender.d = nextRender;
1177
+ }
1178
+ }
1179
+ function queueEffect(scope, fn) {
1180
+ pendingEffects.push(scope, fn);
1181
+ }
1182
+ function run() {
1183
+ let effects = pendingEffects;
1184
+ try {
1185
+ rendering = !0, runRenders();
1186
+ } finally {
1187
+ pendingRender = void 0, rendering = !1;
1188
+ }
1189
+ pendingEffects = [], runEffects(effects);
1190
+ }
1191
+ function prepareEffects(fn) {
1192
+ let prevRender = pendingRender, prevEffects = pendingEffects, preparedEffects = pendingEffects = [];
1193
+ pendingRender = void 0;
1194
+ try {
1195
+ rendering = !0, fn(), runRenders();
1196
+ } finally {
1197
+ rendering = !1, pendingRender = prevRender, pendingEffects = prevEffects;
1198
+ }
1199
+ return preparedEffects;
1200
+ }
1201
+ function runEffects(effects = pendingEffects) {
1202
+ for (let i = 0; i < effects.length; i += 2 /* Total */) {
1203
+ let scope = effects[i], fn = effects[i + 1];
1204
+ fn(scope, scope);
1205
+ }
1206
+ }
1207
+ function runRenders() {
1208
+ for (; pendingRender; )
1209
+ pendingRender.k.b?.y || pendingRender.H(pendingRender.k, pendingRender.I), pendingRender = pendingRender.d;
1210
+ finishPendingScopes();
1211
+ }
1212
+ function comparePendingRenders(a, b) {
1213
+ let aStart = ownerStartNode(a.k), bStart = ownerStartNode(b.k);
1214
+ return aStart === bStart ? 0 : aStart ? bStart ? aStart.compareDocumentPosition(bStart) & 2 ? -1 : 1 : -1 : 1;
1215
+ }
1216
+ function ownerStartNode(scope) {
1217
+ return (scope.b || scope).a;
1218
+ }
1219
+
1220
+ // src/dom/abort-signal.ts
1221
+ function resetAbortSignal(scope, id) {
1222
+ let ctrl = scope.h?.[id];
1223
+ ctrl && (queueEffect(ctrl, abort), scope.h[id] = void 0);
1224
+ }
1225
+ function getAbortSignal(scope, id) {
1226
+ return scope.b && (scope.b.n ||= /* @__PURE__ */ new Set()).add(scope), ((scope.h ||= {})[id] ||= new AbortController()).signal;
1227
+ }
1228
+ function abort(ctrl) {
1229
+ ctrl.abort();
1256
1230
  }
1257
1231
 
1232
+ // src/common/compat-meta.ts
1233
+ var prefix = "$C_", RENDERER_REGISTER_ID = prefix + "r", SET_SCOPE_REGISTER_ID = prefix + "s";
1234
+
1258
1235
  // src/dom/compat.ts
1259
1236
  var classIdToScope = /* @__PURE__ */ new Map(), compat = {
1260
1237
  patchConditionals,
@@ -1271,35 +1248,32 @@ var classIdToScope = /* @__PURE__ */ new Map(), compat = {
1271
1248
  return value2 === MARK || value2 === CLEAN || value2 === DIRTY;
1272
1249
  },
1273
1250
  isRenderer(renderer) {
1274
- return renderer.k !== void 0;
1251
+ return renderer.l !== void 0;
1275
1252
  },
1276
1253
  getStartNode(scope) {
1277
1254
  return scope.a;
1278
1255
  },
1279
1256
  setScopeNodes(scope, startNode, endNode) {
1280
- scope.a = startNode, scope.b = endNode;
1257
+ scope.a = startNode, scope.c = endNode;
1281
1258
  },
1282
1259
  runComponentEffects() {
1283
1260
  runEffects(this.effects);
1284
1261
  },
1262
+ runComponentDestroy() {
1263
+ this.scope && destroyBranch(this.scope);
1264
+ },
1285
1265
  resolveRegistered(value2, {
1286
1266
  runtimeId,
1287
1267
  componentIdPrefix
1288
1268
  }) {
1289
1269
  return Array.isArray(value2) && typeof value2[0] == "string" ? getRegisteredWithScope(
1290
1270
  value2[0],
1291
- value2.length === 2 && window[runtimeId]?.[componentIdPrefix === "s" ? "_" : componentIdPrefix]?.n[value2[1]]
1271
+ value2.length === 2 && window[runtimeId]?.[componentIdPrefix === "s" ? "_" : componentIdPrefix]?.p[value2[1]]
1292
1272
  ) : value2;
1293
1273
  },
1294
1274
  createRenderer(setup, clone, args) {
1295
- let renderer = createRenderer(
1296
- "",
1297
- void 0,
1298
- setup,
1299
- void 0,
1300
- args && (() => args)
1301
- );
1302
- return renderer.k = clone, renderer;
1275
+ let renderer = createRenderer("", void 0, setup, args && (() => args));
1276
+ return renderer.l = clone, renderer;
1303
1277
  },
1304
1278
  render(out, component, renderer, args) {
1305
1279
  let scope = component.scope;
@@ -1311,18 +1285,9 @@ var classIdToScope = /* @__PURE__ */ new Map(), compat = {
1311
1285
  normalizedInput[key === "renderBody" ? "content" : key] = input[key];
1312
1286
  }
1313
1287
  if (component.effects = prepareEffects(() => {
1314
- if (scope)
1315
- applyArgs(scope, MARK), existing = !0;
1316
- else {
1317
- scope = component.scope = createScopeWithRenderer(renderer, out.global);
1318
- let closures = renderer.c;
1319
- if (closures)
1320
- for (let signal of closures)
1321
- signal(component.scope, CLEAN);
1322
- }
1323
- applyArgs(scope, args);
1288
+ scope ? (applyArgs(scope, MARK), existing = !0) : (scope = component.scope = createScope(out.global), scope._ = renderer.u, initRenderer(renderer, scope)), applyArgs(scope, args);
1324
1289
  }), !existing)
1325
- return scope.a === scope.b ? scope.a : scope.a.parentNode;
1290
+ return scope.a === scope.c ? scope.a : scope.a.parentNode;
1326
1291
  }
1327
1292
  };
1328
1293
  function noop() {
@@ -1334,7 +1299,7 @@ var createTemplate = (templateId, ...rendererArgs) => {
1334
1299
  return renderer.mount = mount, renderer._ = renderer, register(templateId, renderer);
1335
1300
  };
1336
1301
  function mount(input = {}, reference, position) {
1337
- let scope, dom, { $global } = input;
1302
+ let branch, dom, { $global } = input;
1338
1303
  $global ? ({ $global, ...input } = input, $global = {
1339
1304
  runtimeId: DEFAULT_RUNTIME_ID,
1340
1305
  renderId: DEFAULT_RENDER_ID,
@@ -1344,17 +1309,17 @@ function mount(input = {}, reference, position) {
1344
1309
  renderId: DEFAULT_RENDER_ID
1345
1310
  };
1346
1311
  let args = this.e, effects = prepareEffects(() => {
1347
- scope = createScope($global), dom = initRenderer(this, scope), args && args(scope, [input]);
1312
+ branch = createScope($global), dom = initRenderer(this, branch), args && args(branch, [input]);
1348
1313
  });
1349
1314
  switch (position) {
1315
+ case "beforebegin":
1316
+ reference.parentNode.insertBefore(dom, reference);
1317
+ break;
1350
1318
  case "afterbegin":
1351
1319
  reference.insertBefore(dom, reference.firstChild);
1352
1320
  break;
1353
1321
  case "afterend":
1354
- reference.parentElement.insertBefore(dom, reference.nextSibling);
1355
- break;
1356
- case "beforebegin":
1357
- reference.parentElement.insertBefore(dom, reference);
1322
+ reference.parentNode.insertBefore(dom, reference.nextSibling);
1358
1323
  break;
1359
1324
  default:
1360
1325
  reference.appendChild(dom);
@@ -1364,12 +1329,12 @@ function mount(input = {}, reference, position) {
1364
1329
  update: (newInput) => {
1365
1330
  args && runEffects(
1366
1331
  prepareEffects(() => {
1367
- args(scope, MARK), args(scope, [newInput]);
1332
+ args(branch, MARK), args(branch, [newInput]);
1368
1333
  })
1369
1334
  );
1370
1335
  },
1371
1336
  destroy: () => {
1372
- removeAndDestroyScope(scope);
1337
+ removeAndDestroyBranch(branch);
1373
1338
  }
1374
1339
  };
1375
1340
  }