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.
@@ -87,564 +87,62 @@ function triggerMacroTask() {
87
87
  port2.postMessage(0);
88
88
  }
89
89
 
90
- // src/common/meta.ts
91
- var DEFAULT_RUNTIME_ID = "M";
92
- var DEFAULT_RENDER_ID = "_";
93
-
94
- // src/dom/scope.ts
95
- var debugID = 0;
96
- function createScope($global) {
97
- const scope = {
98
- ___client: 1,
99
- $global
100
- };
101
- if (true) {
102
- scope.___debugId = debugID++;
103
- }
104
- return scope;
105
- }
106
- var emptyScope = createScope({});
107
- function getEmptyScope(marker) {
108
- emptyScope.___startNode = emptyScope.___endNode = marker;
109
- return emptyScope;
110
- }
111
- function destroyScope(scope) {
112
- _destroyScope(scope);
113
- scope.___cleanupOwner?.___cleanup?.delete(scope);
114
- const closureSignals = scope.___renderer?.___closureSignals;
115
- if (closureSignals) {
116
- for (const signal of closureSignals) {
117
- signal.___unsubscribe?.(scope);
118
- }
119
- }
120
- return scope;
121
- }
122
- function _destroyScope(scope) {
123
- scope.___cleanup?.forEach(_destroyScope);
124
- const controllers = scope.___abortControllers;
125
- if (controllers) {
126
- for (const ctrl of controllers.values()) {
127
- ctrl.abort();
128
- }
129
- }
130
- }
131
- function onDestroy(scope) {
132
- let parentScope = scope.___cleanupOwner;
133
- while (parentScope && !parentScope.___cleanup?.has(scope)) {
134
- (parentScope.___cleanup ||= /* @__PURE__ */ new Set()).add(scope);
135
- scope = parentScope;
136
- parentScope = scope.___cleanupOwner;
137
- }
138
- }
139
- function removeAndDestroyScope(scope) {
140
- destroyScope(scope);
141
- let current = scope.___startNode;
142
- const stop = scope.___endNode.nextSibling;
143
- while (current !== stop) {
144
- const next = current.nextSibling;
145
- current.remove();
146
- current = next;
147
- }
148
- }
149
- function insertBefore(scope, parent, nextSibling) {
150
- let current = scope.___startNode;
151
- const stop = scope.___endNode.nextSibling;
152
- while (current !== stop) {
153
- const next = current.nextSibling;
154
- parent.insertBefore(current, nextSibling);
155
- current = next;
156
- }
157
- }
158
-
159
- // src/dom/resume.ts
160
- var registeredValues = {};
161
- var Render = class {
162
- ___scopeStack = [];
163
- ___scopeLookup = {};
164
- ___serializeContext = {
165
- _: registeredValues
166
- };
167
- constructor(renders, runtimeId, renderId) {
168
- this.___renders = renders;
169
- this.___runtimeId = runtimeId;
170
- this.___renderId = renderId;
171
- this.___data = renders[renderId];
172
- this.___resume();
173
- }
174
- w() {
175
- this.___data.w();
176
- this.___resume();
177
- }
178
- ___resume() {
179
- const data2 = this.___data;
180
- const serializeContext = this.___serializeContext;
181
- const scopeLookup = this.___scopeLookup;
182
- const visits = data2.v;
183
- const cleanupOwners = /* @__PURE__ */ new Map();
184
- if (visits.length) {
185
- const commentPrefix = data2.i;
186
- const commentPrefixLen = commentPrefix.length;
187
- const cleanupMarkers = /* @__PURE__ */ new Map();
188
- data2.v = [];
189
- const sectionEnd = (visit, scopeId = this.___currentScopeId, curNode = visit) => {
190
- const scope = scopeLookup[scopeId] ||= {};
191
- let endNode = curNode;
192
- while ((endNode = endNode.previousSibling).nodeType === 8) ;
193
- scope.___endNode = endNode;
194
- const startNode = scope.___startNode ||= endNode;
195
- let len = cleanupMarkers.size;
196
- for (const [markerScopeId, markerNode] of cleanupMarkers) {
197
- if (!len--) break;
198
- if (markerScopeId !== scopeId && startNode.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2) {
199
- cleanupOwners.set("" + markerScopeId, scopeId);
200
- cleanupMarkers.delete(markerScopeId);
201
- }
202
- }
203
- cleanupMarkers.set(scopeId, visit);
204
- return scope;
205
- };
206
- for (const visit of visits) {
207
- const commentText = visit.data;
208
- const token = commentText[commentPrefixLen];
209
- const scopeId = parseInt(commentText.slice(commentPrefixLen + 1));
210
- const scope = scopeLookup[scopeId] ||= {};
211
- const dataIndex = commentText.indexOf(" ") + 1;
212
- const data3 = dataIndex ? commentText.slice(dataIndex) : "";
213
- if (token === "*" /* Node */) {
214
- scope[data3] = visit.previousSibling;
215
- } else if (token === "$" /* Cleanup */) {
216
- cleanupMarkers.set(scopeId, visit);
217
- } else if (token === "[" /* SectionStart */) {
218
- if (this.___currentScopeId) {
219
- if (data3) {
220
- sectionEnd(visit);
221
- }
222
- this.___scopeStack.push(this.___currentScopeId);
223
- }
224
- this.___currentScopeId = scopeId;
225
- scope.___startNode = visit;
226
- } else if (token === "]" /* SectionEnd */) {
227
- scope[data3] = visit;
228
- if (scopeId < this.___currentScopeId) {
229
- const currParent = visit.parentNode;
230
- const startNode = sectionEnd(visit).___startNode;
231
- if (currParent && currParent !== startNode.parentNode) {
232
- currParent.prepend(startNode);
233
- }
234
- this.___currentScopeId = this.___scopeStack.pop();
235
- }
236
- } else if (token === "|" /* SectionSingleNodesEnd */) {
237
- scope[true ? data3.slice(0, data3.indexOf(" ")) : parseInt(data3)] = visit;
238
- const childScopeIds = JSON.parse(
239
- "[" + data3.slice(data3.indexOf(" ") + 1) + "]"
240
- );
241
- let curNode = visit;
242
- for (let i = childScopeIds.length - 1; i >= 0; i--) {
243
- curNode = sectionEnd(visit, childScopeIds[i], curNode).___endNode;
244
- }
245
- }
246
- }
247
- }
248
- const resumes = data2.r;
249
- if (resumes) {
250
- data2.r = [];
251
- const len = resumes.length;
252
- let i = 0;
253
- try {
254
- isResuming = true;
255
- while (i < len) {
256
- const resumeData = resumes[i++];
257
- if (typeof resumeData === "function") {
258
- const scopes = resumeData(serializeContext);
259
- let { $global } = scopeLookup;
260
- if (!$global) {
261
- scopeLookup.$global = $global = scopes.$ || {};
262
- $global.runtimeId = this.___runtimeId;
263
- $global.renderId = this.___renderId;
264
- }
265
- for (const scopeId in scopes) {
266
- if (scopeId !== "$") {
267
- const scope = scopes[scopeId];
268
- const prevScope = scopeLookup[scopeId];
269
- scope.$global = $global;
270
- if (prevScope !== scope) {
271
- scopeLookup[scopeId] = Object.assign(
272
- scope,
273
- prevScope
274
- );
275
- }
276
- const cleanupOwnerId = cleanupOwners.get(scopeId);
277
- if (cleanupOwnerId) {
278
- scope.___cleanupOwner = scopes[cleanupOwnerId];
279
- onDestroy(scope);
280
- }
281
- }
282
- }
283
- } else if (i === len || typeof resumes[i] !== "string") {
284
- delete this.___renders[this.___renderId];
285
- } else {
286
- registeredValues[resumes[i++]](
287
- scopeLookup[resumeData],
288
- scopeLookup[resumeData]
289
- );
290
- }
291
- }
292
- } finally {
293
- isResuming = false;
294
- }
295
- }
296
- }
297
- };
298
- var isResuming = false;
299
- function register(id, obj) {
300
- registeredValues[id] = obj;
301
- return obj;
302
- }
303
- function registerBoundSignal(id, signal) {
304
- registeredValues[id] = (scope) => (valueOrOp) => signal(scope, valueOrOp);
305
- return signal;
306
- }
307
- function getRegisteredWithScope(id, scope) {
308
- const val = registeredValues[id];
309
- return scope ? val(scope) : val;
310
- }
311
- function init(runtimeId = DEFAULT_RUNTIME_ID) {
312
- if (true) {
313
- if (!runtimeId.match(/^[_$a-z][_$a-z0-9]*$/i)) {
314
- throw new Error(
315
- `Invalid runtimeId: "${runtimeId}". The runtimeId must be a valid JavaScript identifier.`
316
- );
317
- }
318
- }
319
- const resumeRender = (renderId) => resumeRender[renderId] = renders[renderId] = new Render(renders, runtimeId, renderId);
320
- let renders;
321
- if (window[runtimeId]) {
322
- setRenders(window[runtimeId]);
323
- } else {
324
- Object.defineProperty(window, runtimeId, {
325
- configurable: true,
326
- set: setRenders
327
- });
328
- }
329
- function setRenders(v) {
330
- if (true) {
331
- if (renders) {
332
- throw new Error(
333
- "Marko tried to initialize multiple times. It could be that there are multiple instances of Marko running on the page."
334
- );
335
- }
336
- }
337
- renders = v;
338
- for (const renderId in v) {
339
- resumeRender(renderId);
340
- }
341
- Object.defineProperty(window, runtimeId, {
342
- configurable: true,
343
- value: resumeRender
344
- });
345
- }
346
- }
347
- function registerSubscriber(id, signal) {
348
- register(id, signal.___subscribe);
349
- return signal;
350
- }
351
- function nodeRef(id, key) {
352
- return register(id, (scope) => () => scope[key]);
353
- }
354
-
355
- // src/dom/signals.ts
356
- var MARK = true ? Symbol("mark") : {};
357
- var CLEAN = true ? Symbol("clean") : {};
358
- var DIRTY = true ? Symbol("dirty") : {};
359
- function state(valueAccessor, fn, getIntersection) {
360
- const valueSignal = value(valueAccessor, fn, getIntersection);
361
- const markAccessor = valueAccessor + "#" /* Mark */;
362
- const valueChangeAccessor = valueAccessor + "@" /* TagVariableChange */;
363
- return (scope, valueOrOp, valueChange) => {
364
- if (rendering) {
365
- const valueIsOp = valueOrOp === MARK || valueOrOp === CLEAN || valueOrOp === DIRTY;
366
- valueSignal(
367
- scope,
368
- valueIsOp || (scope[valueChangeAccessor] = valueChange) || scope[markAccessor] === void 0 ? valueOrOp : CLEAN
369
- );
370
- } else if (scope[valueChangeAccessor]) {
371
- scope[valueChangeAccessor](valueOrOp);
372
- } else {
373
- queueSource(scope, valueSignal, valueOrOp);
374
- }
375
- return valueOrOp;
376
- };
377
- }
378
- function value(valueAccessor, fn, getIntersection) {
379
- const markAccessor = valueAccessor + "#" /* Mark */;
380
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
381
- return (scope, valueOrOp) => {
382
- if (valueOrOp === MARK) {
383
- if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
384
- intersection2?.(scope, MARK);
385
- }
386
- } else if (valueOrOp !== DIRTY) {
387
- const existing = scope[markAccessor] !== void 0;
388
- if ((scope[markAccessor] ||= 1) === 1) {
389
- if (valueOrOp === CLEAN || existing && scope[valueAccessor] === valueOrOp) {
390
- intersection2?.(scope, CLEAN);
391
- } else {
392
- scope[valueAccessor] = valueOrOp;
393
- fn && fn(scope, valueOrOp);
394
- intersection2?.(scope, DIRTY);
395
- }
396
- }
397
- scope[markAccessor]--;
398
- }
399
- };
400
- }
401
- var accessorId = 0;
402
- function intersection(count, fn, getIntersection) {
403
- const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
404
- const markAccessor = dirtyAccessor + "#" /* Mark */;
405
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
406
- return (scope, op) => {
407
- if (op === MARK) {
408
- if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
409
- intersection2?.(scope, MARK);
410
- }
411
- } else if (scope[markAccessor] === void 0) {
412
- scope[markAccessor] = count - 1;
413
- scope[dirtyAccessor] = true;
414
- } else if (--scope[markAccessor] === 0) {
415
- if (op === DIRTY || scope[dirtyAccessor]) {
416
- scope[dirtyAccessor] = false;
417
- fn(scope, 0);
418
- intersection2?.(scope, DIRTY);
419
- } else {
420
- intersection2?.(scope, CLEAN);
421
- }
422
- } else {
423
- scope[dirtyAccessor] ||= op === DIRTY;
424
- }
425
- };
426
- }
427
- var defaultGetOwnerScope = (scope) => scope._;
428
- function closure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
429
- const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
430
- const markAccessor = dirtyAccessor + 1;
431
- const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
432
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
433
- return (scope, op) => {
434
- if (op === MARK) {
435
- if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
436
- intersection2?.(scope, MARK);
437
- }
438
- } else {
439
- let ownerScope, ownerValueAccessor2;
440
- if (scope[markAccessor] === void 0) {
441
- ownerScope = getOwnerScope(scope);
442
- ownerValueAccessor2 = getOwnerValueAccessor(scope);
443
- const ownerMark = ownerScope[ownerValueAccessor2 + "#" /* Mark */];
444
- const ownerHasRun = ownerMark === void 0 ? !ownerScope.___client : ownerMark === 0;
445
- scope[markAccessor] = ownerHasRun ? 1 : 2;
446
- op = DIRTY;
447
- }
448
- if (--scope[markAccessor] === 0) {
449
- if (op === DIRTY || scope[dirtyAccessor]) {
450
- scope[dirtyAccessor] = false;
451
- ownerScope ||= getOwnerScope(scope);
452
- ownerValueAccessor2 ||= getOwnerValueAccessor(scope);
453
- fn && fn(scope, ownerScope[ownerValueAccessor2]);
454
- intersection2?.(scope, DIRTY);
455
- } else {
456
- intersection2?.(scope, CLEAN);
457
- }
458
- } else {
459
- scope[dirtyAccessor] ||= op === DIRTY;
460
- }
461
- }
462
- };
463
- }
464
- function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
465
- const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
466
- const signalFn = closure(
467
- getOwnerValueAccessor,
468
- fn,
469
- getOwnerScope,
470
- getIntersection
471
- );
472
- const subscribeFns = /* @__PURE__ */ new WeakMap();
473
- signalFn.___subscribe = (scope) => {
474
- const subscribeFn = (value2) => signalFn(scope, value2);
475
- const ownerScope = getOwnerScope(scope);
476
- const providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
477
- subscribeFns.set(scope, subscribeFn);
478
- (ownerScope[providerSubscriptionsAccessor] ||= /* @__PURE__ */ new Set()).add(subscribeFn);
479
- };
480
- signalFn.___unsubscribe = (scope) => {
481
- const ownerScope = getOwnerScope(scope);
482
- const providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
483
- ownerScope[providerSubscriptionsAccessor]?.delete(subscribeFns.get(scope));
484
- subscribeFns.delete(scope);
485
- };
486
- return signalFn;
487
- }
488
- function childClosures(closureSignals, childAccessor) {
489
- const signal = (scope, op) => {
490
- const childScope = scope[childAccessor];
491
- for (const closureSignal of closureSignals) {
492
- closureSignal(childScope, op);
493
- }
494
- };
495
- signal.___subscribe = (scope) => {
496
- const childScope = scope[childAccessor];
497
- for (const closureSignal of closureSignals) {
498
- closureSignal.___subscribe?.(childScope);
499
- }
500
- };
501
- signal.___unsubscribe = (scope) => {
502
- const childScope = scope[childAccessor];
503
- for (const closureSignal of closureSignals) {
504
- closureSignal.___unsubscribe?.(childScope);
505
- }
506
- };
507
- return signal;
508
- }
509
- function dynamicSubscribers(valueAccessor) {
510
- const subscribersAccessor = valueAccessor + "*" /* Subscribers */;
511
- return (scope, op) => {
512
- const subscribers = scope[subscribersAccessor];
513
- if (subscribers) {
514
- for (const subscriber of subscribers) {
515
- subscriber(op);
516
- }
517
- }
518
- };
519
- }
520
- function setTagVar(scope, childAccessor, tagVarSignal2) {
521
- scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
522
- }
523
- var tagVarSignal = (scope, valueOrOp) => scope["/" /* TagVariable */]?.(valueOrOp);
524
- function setTagVarChange(scope, changeHandler) {
525
- scope["@" /* TagVariableChange */] = changeHandler;
526
- }
527
- var tagVarSignalChange = (scope, value2) => scope["@" /* TagVariableChange */]?.(value2);
528
- var contentClosures = (content, childScope, op) => {
529
- const signals = content?.___closureSignals;
530
- if (signals) {
531
- for (const signal of signals) {
532
- signal(childScope, op);
533
- }
534
- }
535
- };
536
- var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
537
- function nextTagId({ $global }) {
538
- const id = tagIdsByGlobal.get($global) || 0;
539
- tagIdsByGlobal.set($global, id + 1);
540
- return "c" + $global.runtimeId + $global.renderId + id.toString(36);
541
- }
542
- function inChild(childAccessor, signal) {
543
- return (scope, valueOrOp) => {
544
- signal(scope[childAccessor], valueOrOp);
545
- };
546
- }
547
- function intersections(signals) {
548
- return (scope, op) => {
549
- for (const signal of signals) {
550
- signal(scope, op);
551
- }
552
- };
553
- }
554
- function effect(id, fn) {
555
- register(id, fn);
556
- return (scope) => {
557
- queueEffect(scope, fn);
90
+ // src/dom/scope.ts
91
+ var pendingScopes = [];
92
+ var debugID = 0;
93
+ function createScope($global) {
94
+ const scope = {
95
+ ___pending: 1,
96
+ $global
558
97
  };
559
- }
560
-
561
- // src/dom/queue.ts
562
- var pendingSignals = [];
563
- var pendingEffects = [];
564
- var rendering = false;
565
- function queueSource(scope, signal, value2) {
566
- schedule();
567
- rendering = true;
568
- signal(scope, MARK);
569
- rendering = false;
570
- pendingSignals.push(scope, signal, value2);
571
- return value2;
572
- }
573
- function queueEffect(scope, fn) {
574
- pendingEffects.push(scope, fn);
575
- }
576
- function run() {
577
- const signals = pendingSignals;
578
- const effects = pendingEffects;
579
- try {
580
- rendering = true;
581
- pendingSignals = [];
582
- runSignals(signals);
583
- } finally {
584
- rendering = false;
98
+ if (true) {
99
+ scope.___debugId = "client-" + debugID++;
585
100
  }
586
- pendingEffects = [];
587
- runEffects(effects);
101
+ pendingScopes.push(scope);
102
+ return scope;
588
103
  }
589
- function prepareEffects(fn) {
590
- const prevSignals = pendingSignals;
591
- const prevEffects = pendingEffects;
592
- const preparedEffects = pendingEffects = [];
593
- const preparedSignals = pendingSignals = [];
594
- try {
595
- rendering = true;
596
- fn();
597
- pendingSignals = prevSignals;
598
- runSignals(preparedSignals);
599
- } finally {
600
- rendering = false;
601
- pendingSignals = prevSignals;
602
- pendingEffects = prevEffects;
104
+ function finishPendingScopes() {
105
+ for (const scope of pendingScopes) {
106
+ scope.___pending = 0;
603
107
  }
604
- return preparedEffects;
108
+ pendingScopes = [];
605
109
  }
606
- function runEffects(effects = pendingEffects) {
607
- for (let i = 0; i < effects.length; i += 2 /* Total */) {
608
- const scope = effects[i];
609
- const fn = effects[i + 1];
610
- fn(scope, scope);
611
- }
110
+ var emptyScope = createScope({});
111
+ function getEmptyScope(marker) {
112
+ emptyScope.___startNode = emptyScope.___endNode = marker;
113
+ return emptyScope;
612
114
  }
613
- function runSignals(signals) {
614
- for (let i = 0; i < signals.length; i += 3 /* Total */) {
615
- const scope = signals[i + 0 /* Scope */];
616
- const signal = signals[i + 1 /* Signal */];
617
- const value2 = signals[i + 2 /* Value */];
618
- signal(scope, value2);
115
+ function destroyBranch(branch) {
116
+ branch.___destroyed = 1;
117
+ branch.___branchScopes?.forEach(destroyBranch);
118
+ if (branch.___abortScopes) {
119
+ for (const scope of branch.___abortScopes) {
120
+ for (const id in scope.___abortControllers) {
121
+ scope.___abortControllers[id]?.abort();
122
+ }
123
+ }
619
124
  }
620
125
  }
621
-
622
- // src/dom/abort-signal.ts
623
- function resetAbortSignal(scope, id) {
624
- const controllers = scope.___abortControllers;
625
- if (controllers) {
626
- const ctrl = controllers.get(id);
627
- if (ctrl) {
628
- queueEffect(null, () => ctrl.abort());
629
- controllers.delete(id);
630
- }
126
+ function removeAndDestroyBranch(branch) {
127
+ destroyBranch(branch);
128
+ let current = branch.___startNode;
129
+ const stop = branch.___endNode.nextSibling;
130
+ while (current !== stop) {
131
+ const next = current.nextSibling;
132
+ current.remove();
133
+ current = next;
631
134
  }
632
135
  }
633
- function getAbortSignal(scope, id) {
634
- const controllers = scope.___abortControllers ||= /* @__PURE__ */ new Map();
635
- let controller = controllers.get(id);
636
- if (!controller) {
637
- onDestroy(scope);
638
- controllers.set(id, controller = new AbortController());
136
+ function insertBefore(scope, parent, nextSibling) {
137
+ let current = scope.___startNode;
138
+ const stop = scope.___endNode.nextSibling;
139
+ while (current !== stop) {
140
+ const next = current.nextSibling;
141
+ parent.insertBefore(current, nextSibling);
142
+ current = next;
639
143
  }
640
- return controller.signal;
641
144
  }
642
145
 
643
- // src/common/compat-meta.ts
644
- var prefix = true ? "$compat_" : "$C_";
645
- var RENDERER_REGISTER_ID = prefix + (true ? "renderer" : "r");
646
- var SET_SCOPE_REGISTER_ID = prefix + (true ? "setScope" : "s");
647
-
648
146
  // src/common/helpers.ts
649
147
  function classValue(value2) {
650
148
  return toDelimitedString(value2, " ", stringifyClassObject);
@@ -702,57 +200,57 @@ function normalizeDynamicRenderer(value2) {
702
200
 
703
201
  // src/dom/reconcile.ts
704
202
  var WRONG_POS = 2147483647;
705
- function reconcile(parent, oldScopes, newScopes, afterReference) {
203
+ function reconcile(parent, oldBranches, newBranches, afterReference) {
706
204
  let oldStart = 0;
707
205
  let newStart = 0;
708
- let oldEnd = oldScopes.length - 1;
709
- let newEnd = newScopes.length - 1;
710
- let oldStartScope = oldScopes[oldStart];
711
- let newStartScope = newScopes[newStart];
712
- let oldEndScope = oldScopes[oldEnd];
713
- let newEndScope = newScopes[newEnd];
206
+ let oldEnd = oldBranches.length - 1;
207
+ let newEnd = newBranches.length - 1;
208
+ let oldStartBranch = oldBranches[oldStart];
209
+ let newStartBranch = newBranches[newStart];
210
+ let oldEndBranch = oldBranches[oldEnd];
211
+ let newEndBranch = newBranches[newEnd];
714
212
  let i;
715
213
  let j;
716
214
  let k;
717
215
  let nextSibling;
718
- let oldScope;
719
- let newScope;
216
+ let oldBranch;
217
+ let newBranch;
720
218
  outer: {
721
- while (oldStartScope === newStartScope) {
219
+ while (oldStartBranch === newStartBranch) {
722
220
  ++oldStart;
723
221
  ++newStart;
724
222
  if (oldStart > oldEnd || newStart > newEnd) {
725
223
  break outer;
726
224
  }
727
- oldStartScope = oldScopes[oldStart];
728
- newStartScope = newScopes[newStart];
225
+ oldStartBranch = oldBranches[oldStart];
226
+ newStartBranch = newBranches[newStart];
729
227
  }
730
- while (oldEndScope === newEndScope) {
228
+ while (oldEndBranch === newEndBranch) {
731
229
  --oldEnd;
732
230
  --newEnd;
733
231
  if (oldStart > oldEnd || newStart > newEnd) {
734
232
  break outer;
735
233
  }
736
- oldEndScope = oldScopes[oldEnd];
737
- newEndScope = newScopes[newEnd];
234
+ oldEndBranch = oldBranches[oldEnd];
235
+ newEndBranch = newBranches[newEnd];
738
236
  }
739
237
  }
740
238
  if (oldStart > oldEnd) {
741
239
  if (newStart <= newEnd) {
742
240
  k = newEnd + 1;
743
- nextSibling = k < newScopes.length ? newScopes[k].___startNode : afterReference;
241
+ nextSibling = k < newBranches.length ? newBranches[k].___startNode : afterReference;
744
242
  do {
745
- insertBefore(newScopes[newStart++], parent, nextSibling);
243
+ insertBefore(newBranches[newStart++], parent, nextSibling);
746
244
  } while (newStart <= newEnd);
747
245
  }
748
246
  } else if (newStart > newEnd) {
749
247
  do {
750
- removeAndDestroyScope(oldScopes[oldStart++]);
248
+ removeAndDestroyBranch(oldBranches[oldStart++]);
751
249
  } while (oldStart <= oldEnd);
752
250
  } else {
753
251
  const oldLength = oldEnd - oldStart + 1;
754
252
  const newLength = newEnd - newStart + 1;
755
- const aNullable = oldScopes;
253
+ const aNullable = oldBranches;
756
254
  const sources = new Array(newLength);
757
255
  for (i = 0; i < newLength; ++i) {
758
256
  sources[i] = -1;
@@ -761,64 +259,64 @@ function reconcile(parent, oldScopes, newScopes, afterReference) {
761
259
  let synced = 0;
762
260
  const keyIndex = /* @__PURE__ */ new Map();
763
261
  for (j = newStart; j <= newEnd; ++j) {
764
- keyIndex.set(newScopes[j], j);
262
+ keyIndex.set(newBranches[j], j);
765
263
  }
766
264
  for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
767
- oldScope = oldScopes[i];
768
- j = keyIndex.get(oldScope);
265
+ oldBranch = oldBranches[i];
266
+ j = keyIndex.get(oldBranch);
769
267
  if (j !== void 0) {
770
268
  pos = pos > j ? WRONG_POS : j;
771
269
  ++synced;
772
- newScope = newScopes[j];
270
+ newBranch = newBranches[j];
773
271
  sources[j - newStart] = i;
774
272
  aNullable[i] = null;
775
273
  }
776
274
  }
777
- if (oldLength === oldScopes.length && synced === 0) {
275
+ if (oldLength === oldBranches.length && synced === 0) {
778
276
  for (; newStart < newLength; ++newStart) {
779
- insertBefore(newScopes[newStart], parent, afterReference);
277
+ insertBefore(newBranches[newStart], parent, afterReference);
780
278
  }
781
279
  for (; oldStart < oldLength; ++oldStart) {
782
- removeAndDestroyScope(oldScopes[oldStart]);
280
+ removeAndDestroyBranch(oldBranches[oldStart]);
783
281
  }
784
282
  } else {
785
283
  i = oldLength - synced;
786
284
  while (i > 0) {
787
- oldScope = aNullable[oldStart++];
788
- if (oldScope !== null) {
789
- removeAndDestroyScope(oldScope);
285
+ oldBranch = aNullable[oldStart++];
286
+ if (oldBranch !== null) {
287
+ removeAndDestroyBranch(oldBranch);
790
288
  i--;
791
289
  }
792
290
  }
793
291
  if (pos === WRONG_POS) {
794
292
  const seq = longestIncreasingSubsequence(sources);
795
293
  j = seq.length - 1;
796
- k = newScopes.length;
294
+ k = newBranches.length;
797
295
  for (i = newLength - 1; i >= 0; --i) {
798
296
  if (sources[i] === -1) {
799
297
  pos = i + newStart;
800
- newScope = newScopes[pos++];
801
- nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
802
- insertBefore(newScope, parent, nextSibling);
298
+ newBranch = newBranches[pos++];
299
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
300
+ insertBefore(newBranch, parent, nextSibling);
803
301
  } else {
804
302
  if (j < 0 || i !== seq[j]) {
805
303
  pos = i + newStart;
806
- newScope = newScopes[pos++];
807
- nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
808
- insertBefore(newScope, parent, nextSibling);
304
+ newBranch = newBranches[pos++];
305
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
306
+ insertBefore(newBranch, parent, nextSibling);
809
307
  } else {
810
308
  --j;
811
309
  }
812
310
  }
813
311
  }
814
312
  } else if (synced !== newLength) {
815
- k = newScopes.length;
313
+ k = newBranches.length;
816
314
  for (i = newLength - 1; i >= 0; --i) {
817
315
  if (sources[i] === -1) {
818
316
  pos = i + newStart;
819
- newScope = newScopes[pos++];
820
- nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
821
- insertBefore(newScope, parent, nextSibling);
317
+ newBranch = newBranches[pos++];
318
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
319
+ insertBefore(newBranch, parent, nextSibling);
822
320
  }
823
321
  }
824
322
  }
@@ -900,7 +398,7 @@ function handleDelegated(ev) {
900
398
  const handlersByElement = elementHandlersByEvent.get(ev.type);
901
399
  handlersByElement.get(target)?.(ev, target);
902
400
  if (ev.bubbles) {
903
- while ((target = target.parentElement) && !ev.cancelBubble) {
401
+ while ((target = target.parentNode) && !ev.cancelBubble) {
904
402
  handlersByElement.get(target)?.(ev, target);
905
403
  }
906
404
  }
@@ -928,10 +426,226 @@ function resolveCursorPosition(updatedValue, initialValue, initialPosition, inpu
928
426
  return pos;
929
427
  }
930
428
  }
931
- return -1;
429
+ return -1;
430
+ }
431
+ function stripSpacesAndPunctuation(str) {
432
+ return str.replace(/[^\p{L}\p{N}]/gu, "");
433
+ }
434
+
435
+ // src/common/meta.ts
436
+ var DEFAULT_RUNTIME_ID = "M";
437
+ var DEFAULT_RENDER_ID = "_";
438
+
439
+ // src/dom/resume.ts
440
+ var registeredValues = {};
441
+ var Render = class {
442
+ ___scopeStack = [];
443
+ ___scopeLookup = {};
444
+ ___serializeContext = {
445
+ _: registeredValues
446
+ };
447
+ constructor(renders, runtimeId, renderId) {
448
+ this.___renders = renders;
449
+ this.___runtimeId = runtimeId;
450
+ this.___renderId = renderId;
451
+ this.___data = renders[renderId];
452
+ this.___resume();
453
+ }
454
+ w() {
455
+ this.___data.w();
456
+ this.___resume();
457
+ }
458
+ ___resume() {
459
+ const data2 = this.___data;
460
+ const serializeContext = this.___serializeContext;
461
+ const scopeLookup = this.___scopeLookup;
462
+ const visits = data2.v;
463
+ const branchIds = /* @__PURE__ */ new Set();
464
+ const parentBranchIds = /* @__PURE__ */ new Map();
465
+ if (visits.length) {
466
+ const commentPrefix = data2.i;
467
+ const commentPrefixLen = commentPrefix.length;
468
+ const closestBranchMarkers = /* @__PURE__ */ new Map();
469
+ data2.v = [];
470
+ const branchEnd = (branchId, visit, curNode) => {
471
+ const branch = scopeLookup[branchId] ||= {};
472
+ let endNode = curNode;
473
+ while ((endNode = endNode.previousSibling).nodeType === 8) ;
474
+ branch.___endNode = endNode;
475
+ branch.___startNode ||= endNode;
476
+ for (const [markerScopeId, markerNode] of closestBranchMarkers) {
477
+ if (branch.___startNode.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2) {
478
+ parentBranchIds.set(markerScopeId, branchId);
479
+ closestBranchMarkers.delete(markerScopeId);
480
+ }
481
+ }
482
+ branchIds.add(branchId);
483
+ closestBranchMarkers.set(branchId, visit);
484
+ return branch;
485
+ };
486
+ for (const visit of visits) {
487
+ const commentText = visit.data;
488
+ const dataIndex = commentText.indexOf(" ") + 1;
489
+ const scopeId = commentText.slice(
490
+ commentPrefixLen + 1,
491
+ dataIndex ? dataIndex - 1 : commentText.length
492
+ );
493
+ const scope = scopeLookup[scopeId] ||= {};
494
+ const data3 = dataIndex ? commentText.slice(dataIndex) : "";
495
+ const token = commentText[commentPrefixLen];
496
+ if (token === "*" /* Node */) {
497
+ scope[data3] = visit.previousSibling;
498
+ } else if (token === "$" /* ClosestBranch */) {
499
+ closestBranchMarkers.set(scopeId, visit);
500
+ } else if (token === "[" /* BranchStart */) {
501
+ if (this.___currentScopeId) {
502
+ if (dataIndex) {
503
+ branchEnd(this.___currentScopeId, visit, visit);
504
+ }
505
+ this.___scopeStack.push(this.___currentScopeId);
506
+ }
507
+ this.___currentScopeId = scopeId;
508
+ scope.___startNode = visit;
509
+ } else if (token === "]" /* BranchEnd */) {
510
+ scope[data3] = visit;
511
+ const curParent = visit.parentNode;
512
+ const startNode = branchEnd(
513
+ this.___currentScopeId,
514
+ visit,
515
+ visit
516
+ ).___startNode;
517
+ if (curParent !== startNode.parentNode) {
518
+ curParent.prepend(startNode);
519
+ }
520
+ this.___currentScopeId = this.___scopeStack.pop();
521
+ } else if (token === "|" /* BranchSingleNode */) {
522
+ let next = data3.indexOf(" ");
523
+ let curNode = scope[~next ? data3.slice(0, next) : data3] = visit;
524
+ while (~next) {
525
+ const start = next + 1;
526
+ next = data3.indexOf(" ", start);
527
+ const childScopeId = data3.slice(start, ~next ? next : data3.length);
528
+ curNode = branchEnd(childScopeId, visit, curNode).___endNode;
529
+ }
530
+ }
531
+ }
532
+ }
533
+ const resumes = data2.r;
534
+ if (resumes) {
535
+ data2.r = [];
536
+ const len = resumes.length;
537
+ let i = 0;
538
+ try {
539
+ isResuming = true;
540
+ while (i < len) {
541
+ const resumeData = resumes[i++];
542
+ if (typeof resumeData === "function") {
543
+ const scopes = resumeData(serializeContext);
544
+ let { $global } = scopeLookup;
545
+ if (!$global) {
546
+ scopeLookup.$global = $global = scopes.$ || {};
547
+ $global.runtimeId = this.___runtimeId;
548
+ $global.renderId = this.___renderId;
549
+ }
550
+ for (const scopeId in scopes) {
551
+ if (scopeId !== "$") {
552
+ const scope = scopes[scopeId];
553
+ const prevScope = scopeLookup[scopeId];
554
+ scope.$global = $global;
555
+ if (prevScope !== scope) {
556
+ scopeLookup[scopeId] = Object.assign(
557
+ scope,
558
+ prevScope
559
+ );
560
+ }
561
+ const parentBranchId = parentBranchIds.get(scopeId);
562
+ if (parentBranchId) {
563
+ scope.___closestBranch = scopes[parentBranchId];
564
+ }
565
+ if (branchIds.has(scopeId)) {
566
+ const branch = scope;
567
+ const parentBranch = branch.___closestBranch;
568
+ scope.___closestBranch = branch;
569
+ if (parentBranch) {
570
+ branch.___parentBranch = parentBranch;
571
+ (parentBranch.___branchScopes ||= /* @__PURE__ */ new Set()).add(branch);
572
+ }
573
+ }
574
+ if (true) {
575
+ scope.___debugId = "server-" + scopeId;
576
+ }
577
+ }
578
+ }
579
+ } else if (i === len || typeof resumes[i] !== "string") {
580
+ delete this.___renders[this.___renderId];
581
+ } else {
582
+ registeredValues[resumes[i++]](
583
+ scopeLookup[resumeData],
584
+ scopeLookup[resumeData]
585
+ );
586
+ }
587
+ }
588
+ } finally {
589
+ isResuming = false;
590
+ }
591
+ }
592
+ }
593
+ };
594
+ var isResuming = false;
595
+ function register(id, obj) {
596
+ registeredValues[id] = obj;
597
+ return obj;
598
+ }
599
+ function registerBoundSignal(id, signal) {
600
+ registeredValues[id] = (scope) => (valueOrOp) => signal(scope, valueOrOp);
601
+ return signal;
602
+ }
603
+ function getRegisteredWithScope(id, scope) {
604
+ const val = registeredValues[id];
605
+ return scope ? val(scope) : val;
606
+ }
607
+ function init(runtimeId = DEFAULT_RUNTIME_ID) {
608
+ if (true) {
609
+ if (!runtimeId.match(/^[_$a-z][_$a-z0-9]*$/i)) {
610
+ throw new Error(
611
+ `Invalid runtimeId: "${runtimeId}". The runtimeId must be a valid JavaScript identifier.`
612
+ );
613
+ }
614
+ }
615
+ const resumeRender = (renderId) => resumeRender[renderId] = renders[renderId] = new Render(renders, runtimeId, renderId);
616
+ let renders;
617
+ if (window[runtimeId]) {
618
+ setRenders(window[runtimeId]);
619
+ } else {
620
+ Object.defineProperty(window, runtimeId, {
621
+ configurable: true,
622
+ set: setRenders
623
+ });
624
+ }
625
+ function setRenders(v) {
626
+ if (true) {
627
+ if (renders) {
628
+ throw new Error(
629
+ "Marko tried to initialize multiple times. It could be that there are multiple instances of Marko running on the page."
630
+ );
631
+ }
632
+ }
633
+ renders = v;
634
+ for (const renderId in v) {
635
+ resumeRender(renderId);
636
+ }
637
+ Object.defineProperty(window, runtimeId, {
638
+ configurable: true,
639
+ value: resumeRender
640
+ });
641
+ }
932
642
  }
933
- function stripSpacesAndPunctuation(str) {
934
- return str.replace(/[^\p{L}\p{N}]/gu, "");
643
+ function registerSubscriber(id, signal) {
644
+ register(id, signal.___subscribe);
645
+ return signal;
646
+ }
647
+ function nodeRef(id, key) {
648
+ return register(id, (scope) => () => scope[key]);
935
649
  }
936
650
 
937
651
  // src/dom/controllable.ts
@@ -1033,10 +747,13 @@ function controllable_select_value(scope, nodeAccessor, value2, valueChange) {
1033
747
  } else {
1034
748
  scope[nodeAccessor + "=" /* ControlledType */] = 5 /* None */;
1035
749
  }
1036
- setSelectOptions(
1037
- scope[nodeAccessor],
1038
- value2,
1039
- valueChange
750
+ pendingEffects.unshift(
751
+ scope,
752
+ () => setSelectOptions(
753
+ scope[nodeAccessor],
754
+ value2,
755
+ valueChange
756
+ )
1040
757
  );
1041
758
  }
1042
759
  function controllable_select_value_effect(scope, nodeAccessor) {
@@ -1202,18 +919,26 @@ function toValueProp(it) {
1202
919
  }
1203
920
 
1204
921
  // src/dom/parse-html.ts
1205
- var fallback = /* @__PURE__ */ document.createTextNode("");
1206
- var parser = /* @__PURE__ */ new Range();
922
+ var fallback = /* @__PURE__ */ new Text();
923
+ var parser = /* @__PURE__ */ document.createElement("template");
1207
924
  function parseHTML(html2) {
1208
- return parser.createContextualFragment(html2);
925
+ parser.innerHTML = html2;
926
+ return parser.content;
1209
927
  }
1210
928
  function parseHTMLOrSingleNode(html2) {
1211
929
  const content = parseHTML(html2);
1212
- if (!content.firstChild) return fallback;
1213
- return content.firstChild === content.lastChild && // If the firstChild is a comment it's possible its
1214
- // a single replaced node, in which case the walker can't replace
1215
- // the node itself.
1216
- content.firstChild.nodeType !== 8 ? content.firstChild : content;
930
+ if (content.firstChild) {
931
+ if (content.firstChild === content.lastChild && // If the firstChild is a comment it's possible its
932
+ // a single replaced node, in which case the walker can't replace
933
+ // the node itself.
934
+ content.firstChild.nodeType !== 8) {
935
+ return content.firstChild;
936
+ }
937
+ const fragment = new DocumentFragment();
938
+ fragment.appendChild(content);
939
+ return fragment;
940
+ }
941
+ return fallback;
1217
942
  }
1218
943
 
1219
944
  // src/dom/dom.ts
@@ -1249,7 +974,8 @@ function textContent(node, value2) {
1249
974
  }
1250
975
  function attrs(scope, nodeAccessor, nextAttrs) {
1251
976
  const el = scope[nodeAccessor];
1252
- for (const { name } of el.attributes) {
977
+ for (let i = el.attributes.length; i--; ) {
978
+ const { name } = el.attributes.item(i);
1253
979
  if (!(nextAttrs && (name in nextAttrs || hasAttrAlias(el, name, nextAttrs)))) {
1254
980
  el.removeAttribute(name);
1255
981
  }
@@ -1262,7 +988,8 @@ function hasAttrAlias(element, attr2, nextAttrs) {
1262
988
  function partialAttrs(scope, nodeAccessor, nextAttrs, skip) {
1263
989
  const el = scope[nodeAccessor];
1264
990
  const partial = {};
1265
- for (const { name } of el.attributes) {
991
+ for (let i = el.attributes.length; i--; ) {
992
+ const { name } = el.attributes.item(i);
1266
993
  if (!skip[name] && !(nextAttrs && name in nextAttrs)) {
1267
994
  el.removeAttribute(name);
1268
995
  }
@@ -1449,17 +1176,14 @@ function trimWalkString(walkString) {
1449
1176
  }
1450
1177
  function walk(startNode, walkCodes, scope) {
1451
1178
  walker.currentNode = startNode;
1452
- walkInternal(walkCodes, scope, scope, 0);
1453
- walker.currentNode = document.documentElement;
1179
+ walkInternal(walkCodes, scope, 0);
1180
+ walker.currentNode = document;
1454
1181
  }
1455
- function walkInternal(walkCodes, scope, cleanupOwnerScope, currentWalkIndex) {
1182
+ function walkInternal(walkCodes, scope, currentWalkIndex) {
1456
1183
  let value2;
1457
1184
  let storedMultiplier = 0;
1458
1185
  let currentMultiplier = 0;
1459
1186
  let currentScopeIndex = 0;
1460
- if (cleanupOwnerScope !== scope) {
1461
- scope.___cleanupOwner = cleanupOwnerScope;
1462
- }
1463
1187
  while (value2 = walkCodes.charCodeAt(currentWalkIndex++)) {
1464
1188
  currentMultiplier = storedMultiplier;
1465
1189
  storedMultiplier = 0;
@@ -1482,18 +1206,16 @@ function walkInternal(walkCodes, scope, cleanupOwnerScope, currentWalkIndex) {
1482
1206
  walker.nextNode();
1483
1207
  }
1484
1208
  } else if (value2 === 47 /* BeginChild */) {
1485
- currentWalkIndex = walkInternal(
1486
- walkCodes,
1487
- scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global),
1488
- cleanupOwnerScope,
1489
- currentWalkIndex
1490
- );
1209
+ const childScope = scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global);
1210
+ childScope.___startNode = walker.currentNode;
1211
+ childScope.___closestBranch = scope.___closestBranch;
1212
+ currentWalkIndex = walkInternal(walkCodes, childScope, currentWalkIndex);
1491
1213
  } else if (value2 === 38 /* EndChild */) {
1492
1214
  return currentWalkIndex;
1493
1215
  } else if (value2 === 32 /* Get */) {
1494
1216
  scope[true ? getDebugKey(currentScopeIndex++, walker.currentNode) : currentScopeIndex++] = walker.currentNode;
1495
1217
  } else {
1496
- const newNode = scope[true ? getDebugKey(currentScopeIndex++, "#text") : currentScopeIndex++] = document.createTextNode("");
1218
+ const newNode = scope[true ? getDebugKey(currentScopeIndex++, "#text") : currentScopeIndex++] = new Text();
1497
1219
  const current = walker.currentNode;
1498
1220
  const parentNode = current.parentNode;
1499
1221
  if (value2 !== 37 /* Replace */) {
@@ -1519,26 +1241,40 @@ function getDebugKey(index, node) {
1519
1241
  }
1520
1242
 
1521
1243
  // src/dom/renderer.ts
1522
- function createScopeWithRenderer(renderer, $global, ownerScope) {
1523
- const newScope = createScope($global);
1524
- newScope._ = newScope.___cleanupOwner = renderer.___owner || ownerScope;
1525
- newScope.___renderer = renderer;
1526
- initRenderer(renderer, newScope);
1527
- if (renderer.___closureSignals) {
1528
- for (const signal of renderer.___closureSignals) {
1529
- signal.___subscribe?.(newScope);
1530
- }
1244
+ function createBranchScopeWithRenderer(renderer, $global, parentScope) {
1245
+ const branch = createBranch(
1246
+ $global,
1247
+ renderer.___owner || parentScope,
1248
+ parentScope
1249
+ );
1250
+ if (true) {
1251
+ branch.___renderer = renderer;
1531
1252
  }
1532
- return newScope;
1253
+ initRenderer(renderer, branch);
1254
+ return branch;
1533
1255
  }
1534
- function createScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, ownerScope) {
1256
+ function createBranchScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, parentScope) {
1535
1257
  if (typeof tagNameOrRenderer !== "string") {
1536
- return createScopeWithRenderer(tagNameOrRenderer, $global, ownerScope);
1258
+ return createBranchScopeWithRenderer(
1259
+ tagNameOrRenderer,
1260
+ $global,
1261
+ parentScope
1262
+ );
1263
+ }
1264
+ const branch = createBranch($global, parentScope, parentScope);
1265
+ branch[true ? `#${tagNameOrRenderer}/0` : 0] = branch.___startNode = branch.___endNode = document.createElement(tagNameOrRenderer);
1266
+ return branch;
1267
+ }
1268
+ function createBranch($global, ownerScope, parentScope) {
1269
+ const branch = createScope($global);
1270
+ const parentBranch = parentScope.___closestBranch;
1271
+ branch._ = ownerScope;
1272
+ branch.___closestBranch = branch;
1273
+ if (parentBranch) {
1274
+ branch.___parentBranch = parentBranch;
1275
+ (parentBranch.___branchScopes ||= /* @__PURE__ */ new Set()).add(branch);
1537
1276
  }
1538
- const newScope = createScope($global);
1539
- newScope._ = newScope.___cleanupOwner = ownerScope;
1540
- newScope[true ? `#${tagNameOrRenderer}/0` : 0] = newScope.___startNode = newScope.___endNode = document.createElement(tagNameOrRenderer);
1541
- return newScope;
1277
+ return branch;
1542
1278
  }
1543
1279
  function initRenderer(renderer, scope) {
1544
1280
  const dom = renderer.___clone();
@@ -1550,7 +1286,7 @@ function initRenderer(renderer, scope) {
1550
1286
  scope.___startNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom;
1551
1287
  scope.___endNode = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom;
1552
1288
  if (renderer.___setup) {
1553
- renderer.___setup(scope);
1289
+ queueRender(scope, renderer.___setup);
1554
1290
  }
1555
1291
  return dom;
1556
1292
  }
@@ -1588,9 +1324,8 @@ function dynamicTagAttrs(nodeAccessor, getContent, inputIsArgs) {
1588
1324
  }
1589
1325
  };
1590
1326
  }
1591
- function createRendererWithOwner(template, rawWalks, setup, getClosureSignals, getArgs) {
1327
+ function createRendererWithOwner(template, rawWalks, setup, getArgs) {
1592
1328
  let args;
1593
- let closureSignals;
1594
1329
  const id = true ? Symbol("Marko Renderer") : {};
1595
1330
  const walks = rawWalks ? /* @__PURE__ */ trimWalkString(rawWalks) : " ";
1596
1331
  return (owner) => {
@@ -1604,21 +1339,12 @@ function createRendererWithOwner(template, rawWalks, setup, getClosureSignals, g
1604
1339
  ___sourceNode: void 0,
1605
1340
  get ___args() {
1606
1341
  return args ||= getArgs?.();
1607
- },
1608
- get ___closureSignals() {
1609
- return closureSignals ||= new Set(getClosureSignals?.());
1610
1342
  }
1611
1343
  };
1612
1344
  };
1613
1345
  }
1614
- function createRenderer(template, walks, setup, getClosureSignals, getArgs) {
1615
- return createRendererWithOwner(
1616
- template,
1617
- walks,
1618
- setup,
1619
- getClosureSignals,
1620
- getArgs
1621
- )();
1346
+ function createRenderer(template, walks, setup, getArgs) {
1347
+ return createRendererWithOwner(template, walks, setup, getArgs)();
1622
1348
  }
1623
1349
  function _clone() {
1624
1350
  return (this.___sourceNode ||= parseHTMLOrSingleNode(
@@ -1633,16 +1359,14 @@ function patchConditionals(fn) {
1633
1359
  }
1634
1360
  var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
1635
1361
  const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
1636
- const childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
1637
1362
  let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1638
1363
  return (scope, newRendererOrOp) => {
1639
1364
  if (newRendererOrOp === DIRTY) return;
1640
- let currentRenderer = scope[rendererAccessor];
1365
+ const currentRenderer = scope[rendererAccessor];
1641
1366
  let op = newRendererOrOp;
1642
1367
  if (newRendererOrOp !== MARK && newRendererOrOp !== CLEAN) {
1643
1368
  const normalizedRenderer = normalizeDynamicRenderer(newRendererOrOp);
1644
1369
  if (isDifferentRenderer(normalizedRenderer, currentRenderer)) {
1645
- currentRenderer = scope[rendererAccessor] = normalizedRenderer;
1646
1370
  setConditionalRenderer(scope, nodeAccessor, normalizedRenderer);
1647
1371
  fn && fn(scope);
1648
1372
  op = DIRTY;
@@ -1651,46 +1375,22 @@ var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
1651
1375
  }
1652
1376
  }
1653
1377
  intersection2?.(scope, op);
1654
- contentClosures(currentRenderer, scope[childScopeAccessor], op);
1655
1378
  };
1656
1379
  };
1657
- function inConditionalScope(signal, nodeAccessor) {
1658
- const scopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
1659
- const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
1660
- return (scope, op) => {
1661
- const conditionalScope = scope[scopeAccessor];
1662
- if (conditionalScope) {
1663
- const conditionalRenderer = scope[rendererAccessor];
1664
- if (!conditionalRenderer?.___closureSignals || conditionalRenderer.___closureSignals.has(signal)) {
1665
- signal(conditionalScope, op);
1666
- }
1667
- }
1668
- };
1669
- }
1670
1380
  function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
1671
- let newScope;
1672
- let prevScope = scope[nodeAccessor + "!" /* ConditionalScope */];
1673
- if (newRenderer) {
1674
- newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithTagNameOrRenderer(
1675
- newRenderer,
1676
- scope.$global,
1677
- scope
1678
- );
1679
- prevScope = prevScope || getEmptyScope(scope[nodeAccessor]);
1680
- } else {
1681
- newScope = getEmptyScope(scope[nodeAccessor]);
1682
- scope[nodeAccessor + "!" /* ConditionalScope */] = void 0;
1683
- }
1381
+ const newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0;
1382
+ const prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyScope(scope[nodeAccessor]);
1684
1383
  insertBefore(
1685
- newScope,
1686
- prevScope.___startNode.parentNode,
1687
- prevScope.___startNode
1384
+ newBranch || getEmptyScope(scope[nodeAccessor]),
1385
+ prevBranch.___startNode.parentNode,
1386
+ prevBranch.___startNode
1688
1387
  );
1689
- removeAndDestroyScope(prevScope);
1388
+ removeAndDestroyBranch(prevBranch);
1389
+ scope[nodeAccessor + "(" /* ConditionalRenderer */] = newRenderer;
1390
+ scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
1690
1391
  }
1691
1392
  var conditionalOnlyChild = function conditional3(nodeAccessor, fn, getIntersection) {
1692
1393
  const rendererAccessor = nodeAccessor + "(" /* ConditionalRenderer */;
1693
- const childScopeAccessor = nodeAccessor + "!" /* ConditionalScope */;
1694
1394
  let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1695
1395
  return (scope, newRendererOrOp) => {
1696
1396
  if (newRendererOrOp === DIRTY) return;
@@ -1712,20 +1412,22 @@ var conditionalOnlyChild = function conditional3(nodeAccessor, fn, getIntersecti
1712
1412
  }
1713
1413
  }
1714
1414
  intersection2?.(scope, op);
1715
- contentClosures(currentRenderer, scope[childScopeAccessor], op);
1716
1415
  };
1717
1416
  };
1718
1417
  function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
1719
- const prevScope = scope[nodeAccessor + "!" /* ConditionalScope */];
1418
+ const prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */];
1720
1419
  const referenceNode = scope[nodeAccessor];
1420
+ const newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0;
1721
1421
  referenceNode.textContent = "";
1722
- if (newRenderer) {
1723
- const newScope = scope[nodeAccessor + "!" /* ConditionalScope */] = createScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope);
1724
- insertBefore(newScope, referenceNode, null);
1422
+ if (newBranch) {
1423
+ insertBefore(newBranch, referenceNode, null);
1725
1424
  }
1726
- prevScope && destroyScope(prevScope);
1425
+ prevBranch && destroyBranch(prevBranch);
1426
+ scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
1727
1427
  }
1728
- var emptyMarkerMap = /* @__PURE__ */ new Map([[Symbol(), getEmptyScope(void 0)]]);
1428
+ var emptyMarkerMap = /* @__PURE__ */ new Map([
1429
+ [Symbol(), getEmptyScope(void 0)]
1430
+ ]);
1729
1431
  var emptyMarkerArray = [
1730
1432
  /* @__PURE__ */ getEmptyScope(void 0)
1731
1433
  ];
@@ -1763,18 +1465,14 @@ function loopTo(nodeAccessor, renderer) {
1763
1465
  }
1764
1466
  function loop(nodeAccessor, renderer, forEach) {
1765
1467
  const loopScopeAccessor = nodeAccessor + "!" /* LoopScopeArray */;
1766
- const closureSignals = renderer.___closureSignals;
1767
1468
  const params = renderer.___args;
1768
1469
  return (scope, valueOrOp) => {
1769
1470
  if (valueOrOp === DIRTY) return;
1770
1471
  if (valueOrOp === MARK || valueOrOp === CLEAN) {
1771
- const loopScopes = scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1772
- if (loopScopes !== emptyMarkerArray) {
1773
- for (const childScope of loopScopes) {
1774
- params?.(childScope, valueOrOp);
1775
- for (const signal of closureSignals) {
1776
- signal(childScope, valueOrOp);
1777
- }
1472
+ const loopBranches = scope[loopScopeAccessor] ?? scope[nodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1473
+ if (loopBranches !== emptyMarkerArray) {
1474
+ for (const branch of loopBranches) {
1475
+ params?.(branch, valueOrOp);
1778
1476
  }
1779
1477
  }
1780
1478
  return;
@@ -1789,27 +1487,20 @@ function loop(nodeAccessor, renderer, forEach) {
1789
1487
  let parentNode;
1790
1488
  let needsReconciliation = true;
1791
1489
  forEach(valueOrOp, (key, args) => {
1792
- let childScope = oldMap.get(key);
1793
- let closureOp = CLEAN;
1794
- if (!childScope) {
1795
- childScope = createScopeWithRenderer(renderer, scope.$global, scope);
1796
- closureOp = DIRTY;
1490
+ let branch = oldMap.get(key);
1491
+ if (!branch) {
1492
+ branch = createBranchScopeWithRenderer(renderer, scope.$global, scope);
1797
1493
  } else {
1798
1494
  }
1799
1495
  if (params) {
1800
- params(childScope, args);
1801
- }
1802
- if (closureSignals) {
1803
- for (const signal of closureSignals) {
1804
- signal(childScope, closureOp);
1805
- }
1496
+ params(branch, args);
1806
1497
  }
1807
1498
  if (newMap) {
1808
- newMap.set(key, childScope);
1809
- newArray.push(childScope);
1499
+ newMap.set(key, branch);
1500
+ newArray.push(branch);
1810
1501
  } else {
1811
- newMap = /* @__PURE__ */ new Map([[key, childScope]]);
1812
- newArray = [childScope];
1502
+ newMap = /* @__PURE__ */ new Map([[key, branch]]);
1503
+ newArray = [branch];
1813
1504
  }
1814
1505
  });
1815
1506
  if (!newMap) {
@@ -1818,7 +1509,7 @@ function loop(nodeAccessor, renderer, forEach) {
1818
1509
  newArray = emptyMarkerArray;
1819
1510
  getEmptyScope(referenceNode);
1820
1511
  } else {
1821
- oldArray.forEach(destroyScope);
1512
+ oldArray.forEach(destroyBranch);
1822
1513
  referenceNode.textContent = "";
1823
1514
  newMap = emptyMap;
1824
1515
  newArray = emptyArray;
@@ -1843,17 +1534,6 @@ function loop(nodeAccessor, renderer, forEach) {
1843
1534
  scope[nodeAccessor + "!" /* LoopScopeArray */] = newArray;
1844
1535
  };
1845
1536
  }
1846
- function inLoopScope(signal, loopNodeAccessor) {
1847
- const loopScopeAccessor = loopNodeAccessor + "!" /* LoopScopeArray */;
1848
- return (scope, op) => {
1849
- const loopScopes = scope[loopScopeAccessor] ?? scope[loopNodeAccessor + "(" /* LoopScopeMap */]?.values() ?? [];
1850
- if (loopScopes !== emptyMarkerArray) {
1851
- for (const scope2 of loopScopes) {
1852
- signal(scope2, op);
1853
- }
1854
- }
1855
- };
1856
- }
1857
1537
  function bySecondArg(_item, index) {
1858
1538
  return index;
1859
1539
  }
@@ -1864,6 +1544,298 @@ function isDifferentRenderer(a, b) {
1864
1544
  return a !== b && (a?.___id || 0) !== b?.___id;
1865
1545
  }
1866
1546
 
1547
+ // src/dom/signals.ts
1548
+ var MARK = true ? Symbol("mark") : {};
1549
+ var CLEAN = true ? Symbol("clean") : {};
1550
+ var DIRTY = true ? Symbol("dirty") : {};
1551
+ function state(valueAccessor, fn, getIntersection) {
1552
+ const valueSignal = value(valueAccessor, fn, getIntersection);
1553
+ const markAccessor = valueAccessor + "#" /* Mark */;
1554
+ const valueChangeAccessor = valueAccessor + "@" /* TagVariableChange */;
1555
+ return (scope, valueOrOp, valueChange) => {
1556
+ if (rendering) {
1557
+ const valueIsOp = valueOrOp === MARK || valueOrOp === CLEAN || valueOrOp === DIRTY;
1558
+ valueSignal(
1559
+ scope,
1560
+ valueIsOp || (scope[valueChangeAccessor] = valueChange) || scope[markAccessor] === void 0 ? valueOrOp : CLEAN
1561
+ );
1562
+ } else if (scope[valueChangeAccessor]) {
1563
+ scope[valueChangeAccessor](valueOrOp);
1564
+ } else {
1565
+ queueSource(scope, valueSignal, valueOrOp);
1566
+ }
1567
+ return valueOrOp;
1568
+ };
1569
+ }
1570
+ function value(valueAccessor, fn, getIntersection) {
1571
+ const markAccessor = valueAccessor + "#" /* Mark */;
1572
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1573
+ return (scope, valueOrOp) => {
1574
+ if (valueOrOp === MARK) {
1575
+ if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
1576
+ intersection2?.(scope, MARK);
1577
+ }
1578
+ } else if (valueOrOp !== DIRTY) {
1579
+ const existing = scope[markAccessor] !== void 0;
1580
+ if ((scope[markAccessor] ||= 1) === 1) {
1581
+ if (valueOrOp === CLEAN || existing && scope[valueAccessor] === valueOrOp) {
1582
+ intersection2?.(scope, CLEAN);
1583
+ } else {
1584
+ scope[valueAccessor] = valueOrOp;
1585
+ fn && fn(scope, valueOrOp);
1586
+ intersection2?.(scope, DIRTY);
1587
+ }
1588
+ }
1589
+ scope[markAccessor]--;
1590
+ }
1591
+ };
1592
+ }
1593
+ var accessorId = 0;
1594
+ function intersection(count, fn, getIntersection) {
1595
+ const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
1596
+ const markAccessor = dirtyAccessor + "#" /* Mark */;
1597
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1598
+ return (scope, op) => {
1599
+ if (op === MARK) {
1600
+ if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
1601
+ intersection2?.(scope, MARK);
1602
+ }
1603
+ } else if (scope[markAccessor] === void 0) {
1604
+ scope[markAccessor] = count - 1;
1605
+ scope[dirtyAccessor] = true;
1606
+ } else if (--scope[markAccessor] === 0) {
1607
+ if (op === DIRTY || scope[dirtyAccessor]) {
1608
+ scope[dirtyAccessor] = false;
1609
+ fn(scope, 0);
1610
+ intersection2?.(scope, DIRTY);
1611
+ } else {
1612
+ intersection2?.(scope, CLEAN);
1613
+ }
1614
+ } else {
1615
+ scope[dirtyAccessor] ||= op === DIRTY;
1616
+ }
1617
+ };
1618
+ }
1619
+ function closure(fn, getIntersection) {
1620
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1621
+ return (scope, valueOrOp) => {
1622
+ if (valueOrOp === MARK) {
1623
+ intersection2?.(scope, MARK);
1624
+ } else {
1625
+ fn && fn(scope, valueOrOp);
1626
+ intersection2?.(scope, DIRTY);
1627
+ }
1628
+ };
1629
+ }
1630
+ function loopClosure(ownerLoopNodeAccessor, fn, getIntersection) {
1631
+ const signal = closure(fn, getIntersection);
1632
+ const loopScopeAccessor = ownerLoopNodeAccessor + "!" /* LoopScopeArray */;
1633
+ const loopScopeMapAccessor = ownerLoopNodeAccessor + "(" /* LoopScopeMap */;
1634
+ const helperSignal = (ownerScope, value2) => {
1635
+ const loopScopes = ownerScope[loopScopeAccessor] ?? ownerScope[loopScopeMapAccessor]?.values() ?? [];
1636
+ if (loopScopes !== emptyMarkerArray) {
1637
+ for (const scope of loopScopes) {
1638
+ if (!scope.___pending) {
1639
+ queueSource(scope, signal, value2);
1640
+ }
1641
+ }
1642
+ }
1643
+ };
1644
+ helperSignal._ = signal;
1645
+ return helperSignal;
1646
+ }
1647
+ function conditionalClosure(ownerConditionalNodeAccessor, getRenderer, fn, getIntersection) {
1648
+ const signal = closure(fn, getIntersection);
1649
+ const scopeAccessor = ownerConditionalNodeAccessor + "!" /* ConditionalScope */;
1650
+ const rendererAccessor = ownerConditionalNodeAccessor + "(" /* ConditionalRenderer */;
1651
+ const helperSignal = (scope, value2) => {
1652
+ const conditionalScope = scope[scopeAccessor];
1653
+ if (conditionalScope && !conditionalScope.___pending && scope[rendererAccessor]?.___id === getRenderer().___id) {
1654
+ queueSource(conditionalScope, signal, value2);
1655
+ }
1656
+ };
1657
+ helperSignal._ = signal;
1658
+ return helperSignal;
1659
+ }
1660
+ var defaultGetOwnerScope = (scope) => scope._;
1661
+ function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
1662
+ const ownerSubscribersAccessor = ownerValueAccessor + "*" /* Subscribers */;
1663
+ const _signal = closure(fn, getIntersection);
1664
+ const helperSignal = (ownerScope, value2) => {
1665
+ const subscribers = ownerScope[ownerSubscribersAccessor];
1666
+ if (subscribers) {
1667
+ for (const subscriber of subscribers) {
1668
+ if (!subscriber.___pending) {
1669
+ queueSource(subscriber, _signal, value2);
1670
+ }
1671
+ }
1672
+ }
1673
+ };
1674
+ const setupSignal = (scope, value2) => {
1675
+ _signal(scope, value2);
1676
+ subscribe(scope);
1677
+ };
1678
+ const subscribe = (scope) => {
1679
+ (getOwnerScope(scope)[ownerSubscribersAccessor] ||= /* @__PURE__ */ new Set()).add(scope);
1680
+ getAbortSignal(scope, -1).addEventListener("abort", () => {
1681
+ getOwnerScope(scope)[ownerSubscribersAccessor].delete(scope);
1682
+ });
1683
+ };
1684
+ helperSignal._ = setupSignal;
1685
+ helperSignal.___subscribe = subscribe;
1686
+ return helperSignal;
1687
+ }
1688
+ function setTagVar(scope, childAccessor, tagVarSignal2) {
1689
+ scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
1690
+ }
1691
+ var tagVarSignal = (scope, valueOrOp) => scope["/" /* TagVariable */]?.(valueOrOp);
1692
+ function setTagVarChange(scope, changeHandler) {
1693
+ scope["@" /* TagVariableChange */] = changeHandler;
1694
+ }
1695
+ var tagVarSignalChange = (scope, value2) => scope["@" /* TagVariableChange */]?.(value2);
1696
+ var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
1697
+ function nextTagId({ $global }) {
1698
+ const id = tagIdsByGlobal.get($global) || 0;
1699
+ tagIdsByGlobal.set($global, id + 1);
1700
+ return "c" + $global.runtimeId + $global.renderId + id.toString(36);
1701
+ }
1702
+ function inChild(childAccessor, signal) {
1703
+ return (scope, valueOrOp) => {
1704
+ signal(scope[childAccessor], valueOrOp);
1705
+ };
1706
+ }
1707
+ function intersections(signals) {
1708
+ return (scope, op) => {
1709
+ for (const signal of signals) {
1710
+ signal(scope, op);
1711
+ }
1712
+ };
1713
+ }
1714
+ function effect(id, fn) {
1715
+ register(id, fn);
1716
+ return (scope) => {
1717
+ queueEffect(scope, fn);
1718
+ };
1719
+ }
1720
+
1721
+ // src/dom/queue.ts
1722
+ var pendingRender;
1723
+ var pendingEffects = [];
1724
+ var rendering = false;
1725
+ function queueSource(scope, signal, value2) {
1726
+ schedule();
1727
+ const prevRendering = rendering;
1728
+ rendering = true;
1729
+ signal(scope, MARK);
1730
+ rendering = prevRendering;
1731
+ queueRender(scope, signal, value2);
1732
+ return value2;
1733
+ }
1734
+ function queueRender(scope, signal, value2) {
1735
+ const nextRender = {
1736
+ ___scope: scope,
1737
+ ___signal: signal,
1738
+ ___value: value2,
1739
+ ___next: void 0
1740
+ };
1741
+ if (!pendingRender) {
1742
+ pendingRender = nextRender;
1743
+ } else if (comparePendingRenders(pendingRender, nextRender) < 0) {
1744
+ if (rendering) {
1745
+ throw new Error(
1746
+ "attempted to queue a render before the currently executing render"
1747
+ );
1748
+ }
1749
+ nextRender.___next = pendingRender;
1750
+ pendingRender = nextRender;
1751
+ } else {
1752
+ let curRender = pendingRender;
1753
+ while (curRender.___next && comparePendingRenders(curRender.___next, nextRender) >= 0) {
1754
+ curRender = curRender.___next;
1755
+ }
1756
+ nextRender.___next = curRender.___next;
1757
+ curRender.___next = nextRender;
1758
+ }
1759
+ }
1760
+ function queueEffect(scope, fn) {
1761
+ pendingEffects.push(scope, fn);
1762
+ }
1763
+ function run() {
1764
+ const effects = pendingEffects;
1765
+ try {
1766
+ rendering = true;
1767
+ runRenders();
1768
+ } finally {
1769
+ pendingRender = void 0;
1770
+ rendering = false;
1771
+ }
1772
+ pendingEffects = [];
1773
+ runEffects(effects);
1774
+ }
1775
+ function prepareEffects(fn) {
1776
+ const prevRender = pendingRender;
1777
+ const prevEffects = pendingEffects;
1778
+ const preparedEffects = pendingEffects = [];
1779
+ pendingRender = void 0;
1780
+ try {
1781
+ rendering = true;
1782
+ fn();
1783
+ runRenders();
1784
+ } finally {
1785
+ rendering = false;
1786
+ pendingRender = prevRender;
1787
+ pendingEffects = prevEffects;
1788
+ }
1789
+ return preparedEffects;
1790
+ }
1791
+ function runEffects(effects = pendingEffects) {
1792
+ for (let i = 0; i < effects.length; i += 2 /* Total */) {
1793
+ const scope = effects[i];
1794
+ const fn = effects[i + 1];
1795
+ fn(scope, scope);
1796
+ }
1797
+ }
1798
+ function runRenders() {
1799
+ while (pendingRender) {
1800
+ if (!pendingRender.___scope.___closestBranch?.___destroyed) {
1801
+ pendingRender.___signal(pendingRender.___scope, pendingRender.___value);
1802
+ }
1803
+ pendingRender = pendingRender.___next;
1804
+ }
1805
+ finishPendingScopes();
1806
+ }
1807
+ function comparePendingRenders(a, b) {
1808
+ const aStart = ownerStartNode(a.___scope);
1809
+ const bStart = ownerStartNode(b.___scope);
1810
+ return aStart === bStart ? 0 : aStart ? bStart ? aStart.compareDocumentPosition(bStart) & 2 ? -1 : 1 : -1 : 1;
1811
+ }
1812
+ function ownerStartNode(scope) {
1813
+ return (scope.___closestBranch || scope).___startNode;
1814
+ }
1815
+
1816
+ // src/dom/abort-signal.ts
1817
+ function resetAbortSignal(scope, id) {
1818
+ const ctrl = scope.___abortControllers?.[id];
1819
+ if (ctrl) {
1820
+ queueEffect(ctrl, abort);
1821
+ scope.___abortControllers[id] = void 0;
1822
+ }
1823
+ }
1824
+ function getAbortSignal(scope, id) {
1825
+ if (scope.___closestBranch) {
1826
+ (scope.___closestBranch.___abortScopes ||= /* @__PURE__ */ new Set()).add(scope);
1827
+ }
1828
+ return ((scope.___abortControllers ||= {})[id] ||= new AbortController()).signal;
1829
+ }
1830
+ function abort(ctrl) {
1831
+ ctrl.abort();
1832
+ }
1833
+
1834
+ // src/common/compat-meta.ts
1835
+ var prefix = true ? "$compat_" : "$C_";
1836
+ var RENDERER_REGISTER_ID = prefix + (true ? "renderer" : "r");
1837
+ var SET_SCOPE_REGISTER_ID = prefix + (true ? "setScope" : "s");
1838
+
1867
1839
  // src/dom/compat.ts
1868
1840
  var classIdToScope = /* @__PURE__ */ new Map();
1869
1841
  var compat = {
@@ -1893,6 +1865,11 @@ var compat = {
1893
1865
  runComponentEffects() {
1894
1866
  runEffects(this.effects);
1895
1867
  },
1868
+ runComponentDestroy() {
1869
+ if (this.scope) {
1870
+ destroyBranch(this.scope);
1871
+ }
1872
+ },
1896
1873
  resolveRegistered(value2, {
1897
1874
  runtimeId,
1898
1875
  componentIdPrefix
@@ -1906,13 +1883,7 @@ var compat = {
1906
1883
  return value2;
1907
1884
  },
1908
1885
  createRenderer(setup, clone, args) {
1909
- const renderer = createRenderer(
1910
- "",
1911
- void 0,
1912
- setup,
1913
- void 0,
1914
- args && (() => args)
1915
- );
1886
+ const renderer = createRenderer("", void 0, setup, args && (() => args));
1916
1887
  renderer.___clone = clone;
1917
1888
  return renderer;
1918
1889
  },
@@ -1936,13 +1907,9 @@ var compat = {
1936
1907
  }
1937
1908
  component.effects = prepareEffects(() => {
1938
1909
  if (!scope) {
1939
- scope = component.scope = createScopeWithRenderer(renderer, out.global);
1940
- const closures = renderer.___closureSignals;
1941
- if (closures) {
1942
- for (const signal of closures) {
1943
- signal(component.scope, CLEAN);
1944
- }
1945
- }
1910
+ scope = component.scope = createScope(out.global);
1911
+ scope._ = renderer.___owner;
1912
+ initRenderer(renderer, scope);
1946
1913
  } else {
1947
1914
  applyArgs(scope, MARK);
1948
1915
  existing = true;
@@ -1972,7 +1939,7 @@ var createTemplate = (templateId, ...rendererArgs) => {
1972
1939
  return register(templateId, renderer);
1973
1940
  };
1974
1941
  function mount(input = {}, reference, position) {
1975
- let scope, dom;
1942
+ let branch, dom;
1976
1943
  let { $global } = input;
1977
1944
  if ($global) {
1978
1945
  ({ $global, ...input } = input);
@@ -1989,21 +1956,21 @@ function mount(input = {}, reference, position) {
1989
1956
  }
1990
1957
  const args = this.___args;
1991
1958
  const effects = prepareEffects(() => {
1992
- scope = createScope($global);
1993
- dom = initRenderer(this, scope);
1959
+ branch = createScope($global);
1960
+ dom = initRenderer(this, branch);
1994
1961
  if (args) {
1995
- args(scope, [input]);
1962
+ args(branch, [input]);
1996
1963
  }
1997
1964
  });
1998
1965
  switch (position) {
1966
+ case "beforebegin":
1967
+ reference.parentNode.insertBefore(dom, reference);
1968
+ break;
1999
1969
  case "afterbegin":
2000
1970
  reference.insertBefore(dom, reference.firstChild);
2001
1971
  break;
2002
1972
  case "afterend":
2003
- reference.parentElement.insertBefore(dom, reference.nextSibling);
2004
- break;
2005
- case "beforebegin":
2006
- reference.parentElement.insertBefore(dom, reference);
1973
+ reference.parentNode.insertBefore(dom, reference.nextSibling);
2007
1974
  break;
2008
1975
  default:
2009
1976
  reference.appendChild(dom);
@@ -2015,14 +1982,14 @@ function mount(input = {}, reference, position) {
2015
1982
  if (args) {
2016
1983
  runEffects(
2017
1984
  prepareEffects(() => {
2018
- args(scope, MARK);
2019
- args(scope, [newInput]);
1985
+ args(branch, MARK);
1986
+ args(branch, [newInput]);
2020
1987
  })
2021
1988
  );
2022
1989
  }
2023
1990
  },
2024
1991
  destroy: () => {
2025
- removeAndDestroyScope(scope);
1992
+ removeAndDestroyBranch(branch);
2026
1993
  }
2027
1994
  };
2028
1995
  }
@@ -2032,11 +1999,10 @@ export {
2032
1999
  attrTags,
2033
2000
  attrs,
2034
2001
  attrsEvents,
2035
- childClosures,
2036
2002
  classAttr,
2037
- closure,
2038
2003
  compat,
2039
2004
  conditional,
2005
+ conditionalClosure,
2040
2006
  conditionalOnlyChild,
2041
2007
  controllable_detailsOrDialog_open,
2042
2008
  controllable_detailsOrDialog_open_effect,
@@ -2056,7 +2022,6 @@ export {
2056
2022
  createTemplate,
2057
2023
  data,
2058
2024
  dynamicClosure,
2059
- dynamicSubscribers,
2060
2025
  dynamicTagAttrs,
2061
2026
  effect,
2062
2027
  forIn,
@@ -2065,12 +2030,11 @@ export {
2065
2030
  getAbortSignal,
2066
2031
  html,
2067
2032
  inChild,
2068
- inConditionalScope,
2069
- inLoopScope,
2070
2033
  init,
2071
2034
  intersection,
2072
2035
  intersections,
2073
2036
  lifecycle,
2037
+ loopClosure,
2074
2038
  loopIn,
2075
2039
  loopOf,
2076
2040
  loopTo,