marko 6.0.119 → 6.0.121

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.
@@ -264,6 +264,14 @@ function stripSpacesAndPunctuation(str) {
264
264
  return str.replace(/[^\p{L}\p{N}]/gu, "");
265
265
  }
266
266
 
267
+ // src/dom/parse-html.ts
268
+ var parsers = {};
269
+ function parseHTML(html, ns) {
270
+ const parser = parsers[ns] ||= document.createElementNS(ns, "template");
271
+ parser.innerHTML = html;
272
+ return parser.content || parser;
273
+ }
274
+
267
275
  // src/dom/scope.ts
268
276
  var nextScopeId = 1e6;
269
277
  function createScope($global, closestBranch) {
@@ -327,6 +335,247 @@ function tempDetachBranch(branch) {
327
335
  );
328
336
  }
329
337
 
338
+ // src/dom/schedule.ts
339
+ var runTask;
340
+ var isScheduled;
341
+ var channel;
342
+ function schedule() {
343
+ if (!isScheduled) {
344
+ if (true) {
345
+ if (console.createTask) {
346
+ const task = console.createTask("queue");
347
+ runTask = () => task.run(run);
348
+ } else {
349
+ runTask = run;
350
+ }
351
+ }
352
+ isScheduled = 1;
353
+ queueMicrotask(flushAndWaitFrame);
354
+ }
355
+ }
356
+ function flushAndWaitFrame() {
357
+ if (true) {
358
+ runTask();
359
+ } else {
360
+ run();
361
+ }
362
+ requestAnimationFrame(triggerMacroTask);
363
+ }
364
+ function triggerMacroTask() {
365
+ if (!channel) {
366
+ channel = new MessageChannel();
367
+ channel.port1.onmessage = () => {
368
+ isScheduled = 0;
369
+ if (true) {
370
+ const run2 = runTask;
371
+ runTask = void 0;
372
+ run2();
373
+ } else {
374
+ run();
375
+ }
376
+ };
377
+ }
378
+ channel.port2.postMessage(0);
379
+ }
380
+
381
+ // src/dom/signals.ts
382
+ function _let(id, fn) {
383
+ const valueAccessor = true ? id.slice(0, id.lastIndexOf("/")) : decodeAccessor(id);
384
+ const valueChangeAccessor = "TagVariableChange:" /* TagVariableChange */ + valueAccessor;
385
+ if (true) {
386
+ id = +id.slice(id.lastIndexOf("/") + 1);
387
+ }
388
+ return (scope, value, valueChange) => {
389
+ if (rendering) {
390
+ if ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope["#Creating" /* Creating */]) {
391
+ scope[valueAccessor] = value;
392
+ fn?.(scope);
393
+ }
394
+ } else if (scope[valueChangeAccessor]) {
395
+ scope[valueChangeAccessor](value);
396
+ } else if (scope[valueAccessor] !== (scope[valueAccessor] = value) && fn) {
397
+ schedule();
398
+ queueRender(scope, fn, id);
399
+ }
400
+ return value;
401
+ };
402
+ }
403
+ function _const(valueAccessor, fn) {
404
+ if (false) valueAccessor = decodeAccessor(valueAccessor);
405
+ return (scope, value) => {
406
+ if (!(valueAccessor in scope) || scope[valueAccessor] !== value) {
407
+ scope[valueAccessor] = value;
408
+ fn?.(scope);
409
+ }
410
+ };
411
+ }
412
+ function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id" /* Id */) {
413
+ return (scope) => {
414
+ if (scope["#Creating" /* Creating */]) {
415
+ if (id in scope) {
416
+ if (!--scope[id]) {
417
+ fn(scope);
418
+ }
419
+ } else {
420
+ scope[id] = defaultPending;
421
+ }
422
+ } else {
423
+ queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
424
+ }
425
+ };
426
+ }
427
+ function _for_closure(ownerLoopNodeAccessor, fn) {
428
+ if (false)
429
+ ownerLoopNodeAccessor = decodeAccessor(ownerLoopNodeAccessor);
430
+ const scopeAccessor = "BranchScopes:" /* BranchScopes */ + ownerLoopNodeAccessor;
431
+ const ownerSignal = (ownerScope) => {
432
+ const scopes = toArray(ownerScope[scopeAccessor]);
433
+ if (scopes.length) {
434
+ queueRender(
435
+ ownerScope,
436
+ () => {
437
+ for (const scope of scopes) {
438
+ if (!scope["#Creating" /* Creating */] && !scope["#Destroyed" /* Destroyed */]) {
439
+ fn(scope);
440
+ }
441
+ }
442
+ },
443
+ -1,
444
+ 0,
445
+ scopes[0]["#Id" /* Id */]
446
+ );
447
+ }
448
+ };
449
+ ownerSignal._ = fn;
450
+ return ownerSignal;
451
+ }
452
+ function _if_closure(ownerConditionalNodeAccessor, branch, fn) {
453
+ if (false)
454
+ ownerConditionalNodeAccessor = decodeAccessor(
455
+ ownerConditionalNodeAccessor
456
+ );
457
+ const scopeAccessor = "BranchScopes:" /* BranchScopes */ + ownerConditionalNodeAccessor;
458
+ const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + ownerConditionalNodeAccessor;
459
+ const ownerSignal = (scope) => {
460
+ const ifScope = scope[scopeAccessor];
461
+ if (ifScope && !ifScope["#Creating" /* Creating */] && (scope[branchAccessor] || 0) === branch) {
462
+ queueRender(ifScope, fn, -1);
463
+ }
464
+ };
465
+ ownerSignal._ = fn;
466
+ return ownerSignal;
467
+ }
468
+ function subscribeToScopeSet(ownerScope, accessor, scope) {
469
+ const subscribers = ownerScope[accessor] ||= /* @__PURE__ */ new Set();
470
+ if (!subscribers.has(scope)) {
471
+ subscribers.add(scope);
472
+ $signal(scope, -1).addEventListener(
473
+ "abort",
474
+ () => ownerScope[accessor].delete(scope)
475
+ );
476
+ }
477
+ }
478
+ function _closure(...closureSignals) {
479
+ const [{ ___scopeInstancesAccessor, ___signalIndexAccessor }] = closureSignals;
480
+ for (let i = closureSignals.length; i--; ) {
481
+ closureSignals[i].___index = i;
482
+ }
483
+ return (scope) => {
484
+ if (scope[___scopeInstancesAccessor]) {
485
+ for (const childScope of scope[___scopeInstancesAccessor]) {
486
+ if (!childScope["#Creating" /* Creating */]) {
487
+ queueRender(
488
+ childScope,
489
+ closureSignals[childScope[___signalIndexAccessor]],
490
+ -1
491
+ );
492
+ }
493
+ }
494
+ }
495
+ };
496
+ }
497
+ function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
498
+ if (false) valueAccessor = decodeAccessor(valueAccessor);
499
+ const closureSignal = ((scope) => {
500
+ scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
501
+ fn(scope);
502
+ subscribeToScopeSet(
503
+ getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */],
504
+ closureSignal.___scopeInstancesAccessor,
505
+ scope
506
+ );
507
+ });
508
+ closureSignal.___scopeInstancesAccessor = "ClosureScopes:" /* ClosureScopes */ + valueAccessor;
509
+ closureSignal.___signalIndexAccessor = "ClosureSignalIndex:" /* ClosureSignalIndex */ + valueAccessor;
510
+ resumeId && _resume(resumeId, closureSignal);
511
+ return closureSignal;
512
+ }
513
+ function _child_setup(setup) {
514
+ setup._ = (scope, owner) => {
515
+ scope["_" /* Owner */] = owner;
516
+ queueRender(scope, setup, -1);
517
+ };
518
+ return setup;
519
+ }
520
+ function _var(scope, childAccessor, signal) {
521
+ scope[true ? childAccessor : decodeAccessor(childAccessor)]["#TagVariable" /* TagVariable */] = (value) => signal(scope, value);
522
+ }
523
+ var _return = (scope, value) => scope["#TagVariable" /* TagVariable */]?.(value);
524
+ function _return_change(scope, changeHandler) {
525
+ if (changeHandler) {
526
+ scope["#TagVariableChange" /* TagVariableChange */] = changeHandler;
527
+ }
528
+ }
529
+ var _var_change = true ? (scope, value, name = "This") => {
530
+ if (typeof scope["#TagVariableChange" /* TagVariableChange */] !== "function") {
531
+ throw new TypeError(`${name} is a readonly tag variable.`);
532
+ }
533
+ scope["#TagVariableChange" /* TagVariableChange */](value);
534
+ } : (scope, value) => scope["#TagVariableChange" /* TagVariableChange */]?.(value);
535
+ var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
536
+ function _id({ ["$global" /* Global */]: $global }) {
537
+ const id = tagIdsByGlobal.get($global) || 0;
538
+ tagIdsByGlobal.set($global, id + 1);
539
+ return "c" + $global.runtimeId + $global.renderId + id.toString(36);
540
+ }
541
+ function _script(id, fn) {
542
+ _resume(id, fn);
543
+ return (scope) => {
544
+ queueEffect(scope, fn);
545
+ };
546
+ }
547
+ function _el_read(value) {
548
+ if (rendering) {
549
+ _el_read_error();
550
+ }
551
+ return value;
552
+ }
553
+ function* traverseAllHoisted(scope, path, curIndex = path.length - 1) {
554
+ if (rendering) {
555
+ _hoist_read_error();
556
+ }
557
+ if (scope) {
558
+ if (Symbol.iterator in scope) {
559
+ for (const s of scope instanceof Map ? scope.values() : scope) {
560
+ yield* traverseAllHoisted(s, path, curIndex);
561
+ }
562
+ } else if (curIndex) {
563
+ yield* traverseAllHoisted(scope[path[curIndex]], path, curIndex - 1);
564
+ } else {
565
+ yield scope[path[0]];
566
+ }
567
+ }
568
+ }
569
+ function _hoist(...path) {
570
+ if (false)
571
+ path = path.map((p) => typeof p === "string" ? p : decodeAccessor(p));
572
+ return (scope) => {
573
+ const getOne = (...args) => iterator().next().value?.(...args);
574
+ const iterator = getOne[Symbol.iterator] = () => traverseAllHoisted(scope, path);
575
+ return getOne;
576
+ };
577
+ }
578
+
330
579
  // src/dom/walker.ts
331
580
  var walker = /* @__PURE__ */ document.createTreeWalker(document);
332
581
  function walk(startNode, walkCodes, branch) {
@@ -345,14 +594,14 @@ function walkInternal(currentWalkIndex, walkCodes, scope) {
345
594
  storedMultiplier = 0;
346
595
  if (value === 32 /* Get */) {
347
596
  const node = walker.currentNode;
348
- scope[id = true ? getDebugKey(currentScopeIndex++, node) : decodeAccessor(currentScopeIndex++)] = node;
597
+ scope[id = true ? getDebugKey(currentScopeIndex++, node) : decodeAccessor2(currentScopeIndex++)] = node;
349
598
  scope["Getter:" /* Getter */ + id] = () => node;
350
599
  } else if (value === 37 /* Replace */ || value === 49 /* DynamicTagWithVar */) {
351
600
  walker.currentNode.replaceWith(
352
- walker.currentNode = scope[true ? getDebugKey(currentScopeIndex++, "#text") : decodeAccessor(currentScopeIndex++)] = new Text()
601
+ walker.currentNode = scope[true ? getDebugKey(currentScopeIndex++, "#text") : decodeAccessor2(currentScopeIndex++)] = new Text()
353
602
  );
354
603
  if (value === 49 /* DynamicTagWithVar */) {
355
- scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : decodeAccessor(currentScopeIndex++)] = skipScope();
604
+ scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : decodeAccessor2(currentScopeIndex++)] = skipScope();
356
605
  }
357
606
  } else if (value === 38 /* EndChild */) {
358
607
  return currentWalkIndex;
@@ -360,13 +609,13 @@ function walkInternal(currentWalkIndex, walkCodes, scope) {
360
609
  currentWalkIndex = walkInternal(
361
610
  currentWalkIndex,
362
611
  walkCodes,
363
- scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : decodeAccessor(currentScopeIndex++)] = createScope(
612
+ scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : decodeAccessor2(currentScopeIndex++)] = createScope(
364
613
  scope["$global" /* Global */],
365
614
  scope["#ClosestBranch" /* ClosestBranch */]
366
615
  )
367
616
  );
368
617
  if (value === 48 /* BeginChildWithVar */) {
369
- scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : decodeAccessor(currentScopeIndex++)] = skipScope();
618
+ scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : decodeAccessor2(currentScopeIndex++)] = skipScope();
370
619
  }
371
620
  } else if (value < 91 /* NextEnd */ + 1) {
372
621
  value = 20 /* Next */ * currentMultiplier + value - 67 /* Next */;
@@ -405,19 +654,116 @@ function getDebugKey(index, node) {
405
654
  return index;
406
655
  }
407
656
 
408
- // src/dom/resume.ts
409
- var registeredValues = {};
410
- var branchesEnabled;
411
- function enableBranches() {
412
- branchesEnabled = 1;
413
- }
414
- function init(runtimeId = DEFAULT_RUNTIME_ID) {
657
+ // src/dom/renderer.ts
658
+ function createBranch($global, renderer, parentScope, parentNode) {
659
+ const branch = createScope($global);
660
+ branch["_" /* Owner */] = renderer.___owner || parentScope;
661
+ setParentBranch(branch, parentScope?.["#ClosestBranch" /* ClosestBranch */]);
415
662
  if (true) {
416
- const descriptor = Object.getOwnPropertyDescriptor(self, runtimeId);
417
- if (descriptor && (descriptor.set || descriptor.configurable === false)) {
418
- throw new Error(
419
- `Marko initialized multiple times with the same $global.runtimeId of ${JSON.stringify(runtimeId)}. It could be that there are multiple copies of Marko running on the page.`
420
- );
663
+ branch["#Renderer" /* Renderer */] = renderer;
664
+ }
665
+ renderer.___clone?.(
666
+ branch,
667
+ parentNode.namespaceURI
668
+ );
669
+ return branch;
670
+ }
671
+ function setParentBranch(branch, parentBranch) {
672
+ if (parentBranch) {
673
+ branch["#ParentBranch" /* ParentBranch */] = parentBranch;
674
+ (parentBranch["#BranchScopes" /* BranchScopes */] ||= /* @__PURE__ */ new Set()).add(branch);
675
+ }
676
+ branch["#ClosestBranch" /* ClosestBranch */] = branch;
677
+ }
678
+ function createAndSetupBranch($global, renderer, parentScope, parentNode) {
679
+ return setupBranch(
680
+ renderer,
681
+ createBranch($global, renderer, parentScope, parentNode)
682
+ );
683
+ }
684
+ function setupBranch(renderer, branch) {
685
+ if (renderer.___setup) {
686
+ queueRender(branch, renderer.___setup, -1);
687
+ }
688
+ return branch;
689
+ }
690
+ function _content(id, template, walks, setup, params, dynamicScopesAccessor) {
691
+ walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
692
+ setup = setup ? setup._ || setup : void 0;
693
+ params ||= void 0;
694
+ const clone = template ? (branch, ns) => {
695
+ ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
696
+ template,
697
+ ns
698
+ ))(branch, walks);
699
+ } : (branch) => {
700
+ walk(
701
+ branch["#StartNode" /* StartNode */] = branch["#EndNode" /* EndNode */] = new Text(),
702
+ walks,
703
+ branch
704
+ );
705
+ };
706
+ return (owner) => {
707
+ return {
708
+ ___id: id,
709
+ ___clone: clone,
710
+ ___owner: owner,
711
+ ___setup: setup,
712
+ ___params: params,
713
+ ___accessor: dynamicScopesAccessor
714
+ };
715
+ };
716
+ }
717
+ function _content_resume(id, template, walks, setup, params, dynamicScopesAccessor) {
718
+ return _resume(
719
+ id,
720
+ _content(id, template, walks, setup, params, dynamicScopesAccessor)
721
+ );
722
+ }
723
+ function _content_closures(renderer, closureFns) {
724
+ const closureSignals = {};
725
+ for (const key in closureFns) {
726
+ closureSignals[key] = _const(true ? key : +key, closureFns[key]);
727
+ }
728
+ return (owner, closureValues) => {
729
+ const instance = renderer(owner);
730
+ instance.___localClosures = closureSignals;
731
+ instance.___localClosureValues = closureValues;
732
+ return instance;
733
+ };
734
+ }
735
+ var cloneCache = {};
736
+ function createCloneableHTML(html, ns) {
737
+ const { firstChild, lastChild } = parseHTML(html, ns);
738
+ const parent = document.createElementNS(ns, "t");
739
+ insertChildNodes(parent, null, firstChild, lastChild);
740
+ return firstChild === lastChild && firstChild.nodeType < 8 /* Comment */ ? (branch, walks) => {
741
+ walk(
742
+ branch["#StartNode" /* StartNode */] = branch["#EndNode" /* EndNode */] = firstChild.cloneNode(true),
743
+ walks,
744
+ branch
745
+ );
746
+ } : (branch, walks) => {
747
+ const clone = parent.cloneNode(true);
748
+ walk(clone.firstChild, walks, branch);
749
+ branch["#StartNode" /* StartNode */] = clone.firstChild;
750
+ branch["#EndNode" /* EndNode */] = clone.lastChild;
751
+ };
752
+ }
753
+
754
+ // src/dom/resume.ts
755
+ var registeredValues = {};
756
+ var branchesEnabled;
757
+ function enableBranches() {
758
+ branchesEnabled = 1;
759
+ }
760
+ function init(runtimeId = DEFAULT_RUNTIME_ID) {
761
+ if (true) {
762
+ const descriptor = Object.getOwnPropertyDescriptor(self, runtimeId);
763
+ if (descriptor && (descriptor.set || descriptor.configurable === false)) {
764
+ throw new Error(
765
+ `Marko initialized multiple times with the same $global.runtimeId of ${JSON.stringify(runtimeId)}. It could be that there are multiple copies of Marko running on the page.`
766
+ );
421
767
  }
422
768
  }
423
769
  const renders = self[runtimeId];
@@ -433,7 +779,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
433
779
  _: registeredValues
434
780
  };
435
781
  const visitBranches = branchesEnabled && /* @__PURE__ */ ((branchScopesStack = [], branchStarts = [], orphanBranches = [], curBranchScopes) => {
436
- return (branchId, branch, childBranch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
782
+ return (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
437
783
  if (visitType !== "[" /* BranchStart */) {
438
784
  visitScope["Getter:" /* Getter */ + nextToken(
439
785
  /* read accessor */
@@ -452,7 +798,10 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
452
798
  ["#Id" /* Id */]: branchId
453
799
  }
454
800
  );
455
- branch["#ClosestBranch" /* ClosestBranch */] = branch;
801
+ setParentBranch(branch, branch["#ClosestBranch" /* ClosestBranch */]);
802
+ if (branch["#AwaitCounter" /* AwaitCounter */] = render.p?.[branchId]) {
803
+ branch["#AwaitCounter" /* AwaitCounter */].m = render.m;
804
+ }
456
805
  if (singleNode) {
457
806
  while (startVisit.previousSibling && ~visits.indexOf(
458
807
  startVisit = startVisit.previousSibling
@@ -475,10 +824,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
475
824
  branch["#EndNode" /* EndNode */] = visit.previousSibling === startVisit ? startVisit : parent.insertBefore(new Text(), visit);
476
825
  }
477
826
  while (i && orphanBranches[--i]["#Id" /* Id */] > branchId) {
478
- (childBranch = orphanBranches.pop())["#ParentBranch" /* ParentBranch */] = branch;
479
- (branch["#BranchScopes" /* BranchScopes */] ||= /* @__PURE__ */ new Set()).add(
480
- childBranch
481
- );
827
+ setParentBranch(orphanBranches.pop(), branch);
482
828
  }
483
829
  nextToken(
484
830
  /* read optional next branchId */
@@ -608,7 +954,7 @@ function _var_resume(id, signal) {
608
954
  return signal;
609
955
  }
610
956
  function _el(id, accessor) {
611
- const getterAccessor = "Getter:" /* Getter */ + (true ? accessor : decodeAccessor2(accessor));
957
+ const getterAccessor = "Getter:" /* Getter */ + (true ? accessor : decodeAccessor3(accessor));
612
958
  return _resume(id, (scope) => () => {
613
959
  return scope[getterAccessor]();
614
960
  });
@@ -770,463 +1116,120 @@ function setSelectOptions(el, value, valueChange) {
770
1116
  } else {
771
1117
  for (const opt of el.options) {
772
1118
  opt.defaultSelected = opt.value === normalizedValue;
773
- }
774
- }
775
- }
776
- }
777
- function _attr_details_or_dialog_open(scope, nodeAccessor, open, openChange) {
778
- scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor] = openChange;
779
- if (openChange) {
780
- scope["ControlledType:" /* ControlledType */ + nodeAccessor] = 4 /* DetailsOrDialogOpen */;
781
- } else {
782
- scope["ControlledType:" /* ControlledType */ + nodeAccessor] = 5 /* None */;
783
- }
784
- scope[nodeAccessor].open = scope["ControlledValue:" /* ControlledValue */ + nodeAccessor] = normalizeBoolProp(open);
785
- }
786
- function _attr_details_or_dialog_open_script(scope, nodeAccessor) {
787
- const el = scope[nodeAccessor];
788
- const hasChanged = () => el.open !== scope["ControlledValue:" /* ControlledValue */ + nodeAccessor];
789
- syncControllable(
790
- el,
791
- el.tagName === "DIALOG" ? "close" : "toggle",
792
- hasChanged,
793
- () => {
794
- const openChange = scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor];
795
- if (openChange && hasChanged()) {
796
- const newValue = el.open;
797
- el.open = !newValue;
798
- openChange(newValue);
799
- run();
800
- }
801
- }
802
- );
803
- }
804
- var inputType = "";
805
- function setValueAndUpdateSelection(el, value) {
806
- if (el.value !== value) {
807
- const updatedPosition = resolveCursorPosition(
808
- inputType,
809
- el.getRootNode().activeElement === el && el.selectionStart,
810
- el.value,
811
- el.value = value
812
- );
813
- if (~updatedPosition) {
814
- el.setSelectionRange(updatedPosition, updatedPosition);
815
- }
816
- }
817
- }
818
- function setCheckboxValue(scope, nodeAccessor, type, checked, checkedChange) {
819
- scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor] = checkedChange;
820
- if (checkedChange) {
821
- scope["ControlledType:" /* ControlledType */ + nodeAccessor] = type;
822
- scope[nodeAccessor].checked = checked;
823
- } else {
824
- scope["ControlledType:" /* ControlledType */ + nodeAccessor] = 5 /* None */;
825
- scope[nodeAccessor].defaultChecked = checked;
826
- }
827
- }
828
- var controllableDelegate = createDelegator();
829
- function syncControllable(el, event, hasChanged, onChange) {
830
- if (!el._) {
831
- controllableDelegate(el, event, handleChange);
832
- if (el.form) {
833
- controllableDelegate(el.form, "reset", handleFormReset);
834
- }
835
- if (isResuming && hasChanged(el)) {
836
- queueMicrotask(onChange);
837
- }
838
- }
839
- el._ = onChange;
840
- }
841
- function handleChange(ev) {
842
- ev.target._?.(ev);
843
- }
844
- function handleFormReset(ev) {
845
- const handlers = [];
846
- for (const el of ev.target.elements) {
847
- if (el._ && hasFormElementChanged(el)) {
848
- handlers.push(el._);
849
- }
850
- }
851
- requestAnimationFrame(() => {
852
- if (!ev.defaultPrevented) {
853
- for (const change of handlers) {
854
- change();
855
- }
856
- }
857
- });
858
- }
859
- function hasValueChanged(el) {
860
- return el.value !== el.defaultValue;
861
- }
862
- function hasCheckboxChanged(el) {
863
- return el.checked !== el.defaultChecked;
864
- }
865
- function hasSelectChanged(el) {
866
- for (const opt of el.options) {
867
- if (opt.selected !== opt.defaultSelected) {
868
- return true;
869
- }
870
- }
871
- }
872
- function hasFormElementChanged(el) {
873
- return el.options ? hasSelectChanged(el) : hasValueChanged(el) || hasCheckboxChanged(el);
874
- }
875
- function normalizeStrProp(value) {
876
- return normalizeAttrValue(value) || "";
877
- }
878
- function normalizeBoolProp(value) {
879
- return value != null && value !== false;
880
- }
881
- function updateList(arr, val, push2) {
882
- const index = arr.indexOf(val);
883
- return (push2 ? !~index && [...arr, val] : ~index && arr.slice(0, index).concat(arr.slice(index + 1))) || arr;
884
- }
885
- function toValueProp(it) {
886
- return it.value;
887
- }
888
-
889
- // src/dom/parse-html.ts
890
- var parsers = {};
891
- function parseHTML(html, ns) {
892
- const parser = parsers[ns] ||= document.createElementNS(ns, "template");
893
- parser.innerHTML = html;
894
- return parser.content || parser;
895
- }
896
-
897
- // src/dom/schedule.ts
898
- var runTask;
899
- var isScheduled;
900
- var channel;
901
- function schedule() {
902
- if (!isScheduled) {
903
- if (true) {
904
- if (console.createTask) {
905
- const task = console.createTask("queue");
906
- runTask = () => task.run(run);
907
- } else {
908
- runTask = run;
909
- }
910
- }
911
- isScheduled = 1;
912
- queueMicrotask(flushAndWaitFrame);
913
- }
914
- }
915
- function flushAndWaitFrame() {
916
- if (true) {
917
- runTask();
918
- } else {
919
- run();
920
- }
921
- requestAnimationFrame(triggerMacroTask);
922
- }
923
- function triggerMacroTask() {
924
- if (!channel) {
925
- channel = new MessageChannel();
926
- channel.port1.onmessage = () => {
927
- isScheduled = 0;
928
- if (true) {
929
- const run2 = runTask;
930
- runTask = void 0;
931
- run2();
932
- } else {
933
- run();
934
- }
935
- };
936
- }
937
- channel.port2.postMessage(0);
938
- }
939
-
940
- // src/dom/signals.ts
941
- function _let(id, fn) {
942
- const valueAccessor = true ? id.slice(0, id.lastIndexOf("/")) : decodeAccessor3(id);
943
- const valueChangeAccessor = "TagVariableChange:" /* TagVariableChange */ + valueAccessor;
944
- if (true) {
945
- id = +id.slice(id.lastIndexOf("/") + 1);
946
- }
947
- return (scope, value, valueChange) => {
948
- if (rendering) {
949
- if ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope["#Creating" /* Creating */]) {
950
- scope[valueAccessor] = value;
951
- fn?.(scope);
952
- }
953
- } else if (scope[valueChangeAccessor]) {
954
- scope[valueChangeAccessor](value);
955
- } else if (scope[valueAccessor] !== (scope[valueAccessor] = value) && fn) {
956
- schedule();
957
- queueRender(scope, fn, id);
958
- }
959
- return value;
960
- };
961
- }
962
- function _const(valueAccessor, fn) {
963
- if (false) valueAccessor = decodeAccessor3(valueAccessor);
964
- return (scope, value) => {
965
- if (!(valueAccessor in scope) || scope[valueAccessor] !== value) {
966
- scope[valueAccessor] = value;
967
- fn?.(scope);
968
- }
969
- };
970
- }
971
- function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id" /* Id */) {
972
- return (scope) => {
973
- if (scope["#Creating" /* Creating */]) {
974
- if (id in scope) {
975
- if (!--scope[id]) {
976
- fn(scope);
977
- }
978
- } else {
979
- scope[id] = defaultPending;
980
- }
981
- } else {
982
- queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
983
- }
984
- };
985
- }
986
- function _for_closure(ownerLoopNodeAccessor, fn) {
987
- if (false)
988
- ownerLoopNodeAccessor = decodeAccessor3(ownerLoopNodeAccessor);
989
- const scopeAccessor = "BranchScopes:" /* BranchScopes */ + ownerLoopNodeAccessor;
990
- const ownerSignal = (ownerScope) => {
991
- const scopes = toArray(ownerScope[scopeAccessor]);
992
- if (scopes.length) {
993
- queueRender(
994
- ownerScope,
995
- () => {
996
- for (const scope of scopes) {
997
- if (!scope["#Creating" /* Creating */] && !scope["#Destroyed" /* Destroyed */]) {
998
- fn(scope);
999
- }
1000
- }
1001
- },
1002
- -1,
1003
- 0,
1004
- scopes[0]["#Id" /* Id */]
1005
- );
1006
- }
1007
- };
1008
- ownerSignal._ = fn;
1009
- return ownerSignal;
1010
- }
1011
- function _if_closure(ownerConditionalNodeAccessor, branch, fn) {
1012
- if (false)
1013
- ownerConditionalNodeAccessor = decodeAccessor3(
1014
- ownerConditionalNodeAccessor
1015
- );
1016
- const scopeAccessor = "BranchScopes:" /* BranchScopes */ + ownerConditionalNodeAccessor;
1017
- const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + ownerConditionalNodeAccessor;
1018
- const ownerSignal = (scope) => {
1019
- const ifScope = scope[scopeAccessor];
1020
- if (ifScope && !ifScope["#Creating" /* Creating */] && (scope[branchAccessor] || 0) === branch) {
1021
- queueRender(ifScope, fn, -1);
1022
- }
1023
- };
1024
- ownerSignal._ = fn;
1025
- return ownerSignal;
1026
- }
1027
- function subscribeToScopeSet(ownerScope, accessor, scope) {
1028
- const subscribers = ownerScope[accessor] ||= /* @__PURE__ */ new Set();
1029
- if (!subscribers.has(scope)) {
1030
- subscribers.add(scope);
1031
- $signal(scope, -1).addEventListener(
1032
- "abort",
1033
- () => ownerScope[accessor].delete(scope)
1034
- );
1035
- }
1036
- }
1037
- function _closure(...closureSignals) {
1038
- const [{ ___scopeInstancesAccessor, ___signalIndexAccessor }] = closureSignals;
1039
- for (let i = closureSignals.length; i--; ) {
1040
- closureSignals[i].___index = i;
1041
- }
1042
- return (scope) => {
1043
- if (scope[___scopeInstancesAccessor]) {
1044
- for (const childScope of scope[___scopeInstancesAccessor]) {
1045
- if (!childScope["#Creating" /* Creating */]) {
1046
- queueRender(
1047
- childScope,
1048
- closureSignals[childScope[___signalIndexAccessor]],
1049
- -1
1050
- );
1051
- }
1052
- }
1053
- }
1054
- };
1055
- }
1056
- function _closure_get(valueAccessor, fn, getOwnerScope) {
1057
- if (false) valueAccessor = decodeAccessor3(valueAccessor);
1058
- const closureSignal = ((scope) => {
1059
- scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
1060
- fn(scope);
1061
- subscribeToScopeSet(
1062
- getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */],
1063
- closureSignal.___scopeInstancesAccessor,
1064
- scope
1065
- );
1066
- });
1067
- closureSignal.___scopeInstancesAccessor = "ClosureScopes:" /* ClosureScopes */ + valueAccessor;
1068
- closureSignal.___signalIndexAccessor = "ClosureSignalIndex:" /* ClosureSignalIndex */ + valueAccessor;
1069
- return closureSignal;
1070
- }
1071
- function _child_setup(setup) {
1072
- setup._ = (scope, owner) => {
1073
- scope["_" /* Owner */] = owner;
1074
- queueRender(scope, setup, -1);
1075
- };
1076
- return setup;
1077
- }
1078
- function _var(scope, childAccessor, signal) {
1079
- scope[true ? childAccessor : decodeAccessor3(childAccessor)]["#TagVariable" /* TagVariable */] = (value) => signal(scope, value);
1080
- }
1081
- var _return = (scope, value) => scope["#TagVariable" /* TagVariable */]?.(value);
1082
- function _return_change(scope, changeHandler) {
1083
- if (changeHandler) {
1084
- scope["#TagVariableChange" /* TagVariableChange */] = changeHandler;
1119
+ }
1120
+ }
1085
1121
  }
1086
1122
  }
1087
- var _var_change = true ? (scope, value, name = "This") => {
1088
- if (typeof scope["#TagVariableChange" /* TagVariableChange */] !== "function") {
1089
- throw new TypeError(`${name} is a readonly tag variable.`);
1123
+ function _attr_details_or_dialog_open(scope, nodeAccessor, open, openChange) {
1124
+ scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor] = openChange;
1125
+ if (openChange) {
1126
+ scope["ControlledType:" /* ControlledType */ + nodeAccessor] = 4 /* DetailsOrDialogOpen */;
1127
+ } else {
1128
+ scope["ControlledType:" /* ControlledType */ + nodeAccessor] = 5 /* None */;
1090
1129
  }
1091
- scope["#TagVariableChange" /* TagVariableChange */](value);
1092
- } : (scope, value) => scope["#TagVariableChange" /* TagVariableChange */]?.(value);
1093
- var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
1094
- function _id({ ["$global" /* Global */]: $global }) {
1095
- const id = tagIdsByGlobal.get($global) || 0;
1096
- tagIdsByGlobal.set($global, id + 1);
1097
- return "c" + $global.runtimeId + $global.renderId + id.toString(36);
1130
+ scope[nodeAccessor].open = scope["ControlledValue:" /* ControlledValue */ + nodeAccessor] = normalizeBoolProp(open);
1098
1131
  }
1099
- function _script(id, fn) {
1100
- _resume(id, fn);
1101
- return (scope) => {
1102
- queueEffect(scope, fn);
1103
- };
1132
+ function _attr_details_or_dialog_open_script(scope, nodeAccessor) {
1133
+ const el = scope[nodeAccessor];
1134
+ const hasChanged = () => el.open !== scope["ControlledValue:" /* ControlledValue */ + nodeAccessor];
1135
+ syncControllable(
1136
+ el,
1137
+ el.tagName === "DIALOG" ? "close" : "toggle",
1138
+ hasChanged,
1139
+ () => {
1140
+ const openChange = scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor];
1141
+ if (openChange && hasChanged()) {
1142
+ const newValue = el.open;
1143
+ el.open = !newValue;
1144
+ openChange(newValue);
1145
+ run();
1146
+ }
1147
+ }
1148
+ );
1104
1149
  }
1105
- function _el_read(value) {
1106
- if (rendering) {
1107
- _el_read_error();
1150
+ var inputType = "";
1151
+ function setValueAndUpdateSelection(el, value) {
1152
+ if (el.value !== value) {
1153
+ const updatedPosition = resolveCursorPosition(
1154
+ inputType,
1155
+ el.getRootNode().activeElement === el && el.selectionStart,
1156
+ el.value,
1157
+ el.value = value
1158
+ );
1159
+ if (~updatedPosition) {
1160
+ el.setSelectionRange(updatedPosition, updatedPosition);
1161
+ }
1108
1162
  }
1109
- return value;
1110
1163
  }
1111
- function* traverseAllHoisted(scope, path, curIndex = path.length - 1) {
1112
- if (rendering) {
1113
- _hoist_read_error();
1164
+ function setCheckboxValue(scope, nodeAccessor, type, checked, checkedChange) {
1165
+ scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor] = checkedChange;
1166
+ if (checkedChange) {
1167
+ scope["ControlledType:" /* ControlledType */ + nodeAccessor] = type;
1168
+ scope[nodeAccessor].checked = checked;
1169
+ } else {
1170
+ scope["ControlledType:" /* ControlledType */ + nodeAccessor] = 5 /* None */;
1171
+ scope[nodeAccessor].defaultChecked = checked;
1114
1172
  }
1115
- if (scope) {
1116
- if (Symbol.iterator in scope) {
1117
- for (const s of scope instanceof Map ? scope.values() : scope) {
1118
- yield* traverseAllHoisted(s, path, curIndex);
1119
- }
1120
- } else if (curIndex) {
1121
- yield* traverseAllHoisted(scope[path[curIndex]], path, curIndex - 1);
1122
- } else {
1123
- yield scope[path[0]];
1173
+ }
1174
+ var controllableDelegate = createDelegator();
1175
+ function syncControllable(el, event, hasChanged, onChange) {
1176
+ if (!el._) {
1177
+ controllableDelegate(el, event, handleChange);
1178
+ if (el.form) {
1179
+ controllableDelegate(el.form, "reset", handleFormReset);
1180
+ }
1181
+ if (isResuming && hasChanged(el)) {
1182
+ queueMicrotask(onChange);
1124
1183
  }
1125
1184
  }
1185
+ el._ = onChange;
1126
1186
  }
1127
- function _hoist(...path) {
1128
- if (false)
1129
- path = path.map((p) => typeof p === "string" ? p : decodeAccessor3(p));
1130
- return (scope) => {
1131
- const getOne = (...args) => iterator().next().value?.(...args);
1132
- const iterator = getOne[Symbol.iterator] = () => traverseAllHoisted(scope, path);
1133
- return getOne;
1134
- };
1187
+ function handleChange(ev) {
1188
+ ev.target._?.(ev);
1135
1189
  }
1136
-
1137
- // src/dom/renderer.ts
1138
- function createBranch($global, renderer, parentScope, parentNode) {
1139
- const branch = createScope($global);
1140
- const parentBranch = parentScope?.["#ClosestBranch" /* ClosestBranch */];
1141
- branch["_" /* Owner */] = renderer.___owner || parentScope;
1142
- branch["#ClosestBranch" /* ClosestBranch */] = branch;
1143
- if (parentBranch) {
1144
- branch["#ParentBranch" /* ParentBranch */] = parentBranch;
1145
- (parentBranch["#BranchScopes" /* BranchScopes */] ||= /* @__PURE__ */ new Set()).add(branch);
1146
- }
1147
- if (true) {
1148
- branch["#Renderer" /* Renderer */] = renderer;
1190
+ function handleFormReset(ev) {
1191
+ const handlers = [];
1192
+ for (const el of ev.target.elements) {
1193
+ if (el._ && hasFormElementChanged(el)) {
1194
+ handlers.push(el._);
1195
+ }
1149
1196
  }
1150
- renderer.___clone?.(
1151
- branch,
1152
- parentNode.namespaceURI
1153
- );
1154
- return branch;
1197
+ requestAnimationFrame(() => {
1198
+ if (!ev.defaultPrevented) {
1199
+ for (const change of handlers) {
1200
+ change();
1201
+ }
1202
+ }
1203
+ });
1155
1204
  }
1156
- function createAndSetupBranch($global, renderer, parentScope, parentNode) {
1157
- return setupBranch(
1158
- renderer,
1159
- createBranch($global, renderer, parentScope, parentNode)
1160
- );
1205
+ function hasValueChanged(el) {
1206
+ return el.value !== el.defaultValue;
1161
1207
  }
1162
- function setupBranch(renderer, branch) {
1163
- if (renderer.___setup) {
1164
- queueRender(branch, renderer.___setup, -1);
1208
+ function hasCheckboxChanged(el) {
1209
+ return el.checked !== el.defaultChecked;
1210
+ }
1211
+ function hasSelectChanged(el) {
1212
+ for (const opt of el.options) {
1213
+ if (opt.selected !== opt.defaultSelected) {
1214
+ return true;
1215
+ }
1165
1216
  }
1166
- return branch;
1167
1217
  }
1168
- function _content(id, template, walks, setup, params, dynamicScopesAccessor) {
1169
- walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
1170
- setup = setup ? setup._ || setup : void 0;
1171
- params ||= void 0;
1172
- const clone = template ? (branch, ns) => {
1173
- ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
1174
- template,
1175
- ns
1176
- ))(branch, walks);
1177
- } : (branch) => {
1178
- walk(
1179
- branch["#StartNode" /* StartNode */] = branch["#EndNode" /* EndNode */] = new Text(),
1180
- walks,
1181
- branch
1182
- );
1183
- };
1184
- return (owner) => {
1185
- return {
1186
- ___id: id,
1187
- ___clone: clone,
1188
- ___owner: owner,
1189
- ___setup: setup,
1190
- ___params: params,
1191
- ___accessor: dynamicScopesAccessor
1192
- };
1193
- };
1218
+ function hasFormElementChanged(el) {
1219
+ return el.options ? hasSelectChanged(el) : hasValueChanged(el) || hasCheckboxChanged(el);
1194
1220
  }
1195
- function _content_resume(id, template, walks, setup, params, dynamicScopesAccessor) {
1196
- return _resume(
1197
- id,
1198
- _content(id, template, walks, setup, params, dynamicScopesAccessor)
1199
- );
1221
+ function normalizeStrProp(value) {
1222
+ return normalizeAttrValue(value) || "";
1200
1223
  }
1201
- function _content_closures(renderer, closureFns) {
1202
- const closureSignals = {};
1203
- for (const key in closureFns) {
1204
- closureSignals[key] = _const(true ? key : +key, closureFns[key]);
1205
- }
1206
- return (owner, closureValues) => {
1207
- const instance = renderer(owner);
1208
- instance.___localClosures = closureSignals;
1209
- instance.___localClosureValues = closureValues;
1210
- return instance;
1211
- };
1224
+ function normalizeBoolProp(value) {
1225
+ return value != null && value !== false;
1212
1226
  }
1213
- var cloneCache = {};
1214
- function createCloneableHTML(html, ns) {
1215
- const { firstChild, lastChild } = parseHTML(html, ns);
1216
- const parent = document.createElementNS(ns, "t");
1217
- insertChildNodes(parent, null, firstChild, lastChild);
1218
- return firstChild === lastChild && firstChild.nodeType < 8 /* Comment */ ? (branch, walks) => {
1219
- walk(
1220
- branch["#StartNode" /* StartNode */] = branch["#EndNode" /* EndNode */] = firstChild.cloneNode(true),
1221
- walks,
1222
- branch
1223
- );
1224
- } : (branch, walks) => {
1225
- const clone = parent.cloneNode(true);
1226
- walk(clone.firstChild, walks, branch);
1227
- branch["#StartNode" /* StartNode */] = clone.firstChild;
1228
- branch["#EndNode" /* EndNode */] = clone.lastChild;
1229
- };
1227
+ function updateList(arr, val, push2) {
1228
+ const index = arr.indexOf(val);
1229
+ return (push2 ? !~index && [...arr, val] : ~index && arr.slice(0, index).concat(arr.slice(index + 1))) || arr;
1230
+ }
1231
+ function toValueProp(it) {
1232
+ return it.value;
1230
1233
  }
1231
1234
 
1232
1235
  // src/dom/dom.ts
@@ -1692,63 +1695,74 @@ function _await_promise(nodeAccessor, params) {
1692
1695
  if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
1693
1696
  const promiseAccessor = "Promise:" /* Promise */ + nodeAccessor;
1694
1697
  const branchAccessor = "BranchScopes:" /* BranchScopes */ + nodeAccessor;
1695
- const rendererAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + nodeAccessor;
1696
1698
  _enable_catch();
1697
1699
  return (scope, promise) => {
1698
- let awaitCounter;
1699
- let renderData;
1700
- const tryWithPlaceholder = findBranchWithKey(
1701
- scope,
1702
- "#PlaceholderContent" /* PlaceholderContent */
1703
- );
1704
- if (tryWithPlaceholder) {
1705
- renderData = self[tryWithPlaceholder["$global" /* Global */].runtimeId]?.[tryWithPlaceholder["$global" /* Global */].renderId];
1706
- awaitCounter = tryWithPlaceholder["#AwaitCounter" /* AwaitCounter */] ||= renderData?.p?.[tryWithPlaceholder["#Id" /* Id */]];
1707
- if (!awaitCounter?.i) {
1708
- awaitCounter = tryWithPlaceholder["#AwaitCounter" /* AwaitCounter */] = {
1709
- d: 1,
1710
- i: 0,
1711
- c() {
1712
- if (!--awaitCounter.i) {
1713
- const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */];
1714
- tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = 0;
1715
- if (placeholderBranch) {
1716
- placeholderBranch["#StartNode" /* StartNode */].parentNode.insertBefore(
1717
- tryWithPlaceholder["#StartNode" /* StartNode */].parentNode,
1718
- placeholderBranch["#StartNode" /* StartNode */]
1719
- );
1720
- removeAndDestroyBranch(placeholderBranch);
1721
- }
1722
- queueEffect(tryWithPlaceholder, (scope2) => {
1723
- const pendingEffects2 = scope2["#PendingEffects" /* PendingEffects */];
1724
- if (pendingEffects2) {
1725
- scope2["#PendingEffects" /* PendingEffects */] = [];
1726
- runEffects(pendingEffects2, true);
1727
- }
1728
- });
1700
+ let awaitBranch = scope[branchAccessor];
1701
+ const tryBranch = findBranchWithKey(scope, "#PlaceholderContent" /* PlaceholderContent */) || awaitBranch;
1702
+ let awaitCounter = tryBranch["#AwaitCounter" /* AwaitCounter */];
1703
+ if (!awaitCounter?.i) {
1704
+ awaitCounter = tryBranch["#AwaitCounter" /* AwaitCounter */] = {
1705
+ i: 0,
1706
+ c() {
1707
+ if (--awaitCounter.i) return 1;
1708
+ if (tryBranch === scope[branchAccessor]) {
1709
+ if (scope[nodeAccessor].parentNode) {
1710
+ scope[nodeAccessor].replaceWith(
1711
+ scope[branchAccessor]["#StartNode" /* StartNode */].parentNode
1712
+ );
1713
+ }
1714
+ } else {
1715
+ const placeholderBranch = tryBranch["#PlaceholderBranch" /* PlaceholderBranch */];
1716
+ if (placeholderBranch) {
1717
+ tryBranch["#PlaceholderBranch" /* PlaceholderBranch */] = 0;
1718
+ placeholderBranch["#StartNode" /* StartNode */].parentNode.insertBefore(
1719
+ tryBranch["#StartNode" /* StartNode */].parentNode,
1720
+ placeholderBranch["#StartNode" /* StartNode */]
1721
+ );
1722
+ removeAndDestroyBranch(placeholderBranch);
1729
1723
  }
1730
1724
  }
1731
- };
1725
+ queueEffect(tryBranch, (scope2) => {
1726
+ const pendingEffects2 = scope2["#PendingEffects" /* PendingEffects */];
1727
+ if (pendingEffects2) {
1728
+ scope2["#PendingEffects" /* PendingEffects */] = [];
1729
+ runEffects(pendingEffects2, 1);
1730
+ }
1731
+ });
1732
+ }
1733
+ };
1734
+ }
1735
+ placeholderShown.add(pendingEffects);
1736
+ if (!scope[promiseAccessor]) {
1737
+ if (awaitBranch) {
1738
+ awaitBranch["#PendingRenders" /* PendingRenders */] ||= [];
1732
1739
  }
1733
- placeholderShown.add(pendingEffects);
1734
- if (!scope[promiseAccessor] && !awaitCounter.i++) {
1740
+ if (!awaitCounter.i++) {
1735
1741
  requestAnimationFrame(
1736
1742
  () => awaitCounter.i && runEffects(
1737
1743
  prepareEffects(
1738
1744
  () => queueRender(
1739
- tryWithPlaceholder,
1745
+ tryBranch === awaitBranch ? scope : tryBranch,
1740
1746
  () => {
1741
- insertBranchBefore(
1742
- tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1743
- scope["$global" /* Global */],
1744
- tryWithPlaceholder["#PlaceholderContent" /* PlaceholderContent */],
1745
- tryWithPlaceholder["_" /* Owner */],
1746
- tryWithPlaceholder["#StartNode" /* StartNode */].parentNode
1747
- ),
1748
- tryWithPlaceholder["#StartNode" /* StartNode */].parentNode,
1749
- tryWithPlaceholder["#StartNode" /* StartNode */]
1750
- );
1751
- tempDetachBranch(tryWithPlaceholder);
1747
+ if (tryBranch["#PlaceholderContent" /* PlaceholderContent */]) {
1748
+ insertBranchBefore(
1749
+ tryBranch["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1750
+ scope["$global" /* Global */],
1751
+ tryBranch["#PlaceholderContent" /* PlaceholderContent */],
1752
+ tryBranch["_" /* Owner */],
1753
+ tryBranch["#StartNode" /* StartNode */].parentNode
1754
+ ),
1755
+ tryBranch["#StartNode" /* StartNode */].parentNode,
1756
+ tryBranch["#StartNode" /* StartNode */]
1757
+ );
1758
+ tempDetachBranch(tryBranch);
1759
+ } else if (!awaitBranch["#DetachedAwait" /* DetachedAwait */]) {
1760
+ awaitBranch["#StartNode" /* StartNode */].parentNode.insertBefore(
1761
+ scope[nodeAccessor],
1762
+ awaitBranch["#StartNode" /* StartNode */]
1763
+ );
1764
+ tempDetachBranch(tryBranch);
1765
+ }
1752
1766
  },
1753
1767
  -1
1754
1768
  )
@@ -1756,61 +1770,52 @@ function _await_promise(nodeAccessor, params) {
1756
1770
  )
1757
1771
  );
1758
1772
  }
1759
- } else if (scope[branchAccessor] && !scope[promiseAccessor]) {
1760
- scope[branchAccessor]["#StartNode" /* StartNode */].parentNode.insertBefore(
1761
- scope[nodeAccessor],
1762
- scope[branchAccessor]["#StartNode" /* StartNode */]
1763
- );
1764
- tempDetachBranch(scope[branchAccessor]);
1765
1773
  }
1766
1774
  const thisPromise = scope[promiseAccessor] = promise.then(
1767
1775
  (data) => {
1768
1776
  if (thisPromise === scope[promiseAccessor]) {
1777
+ const referenceNode = scope[nodeAccessor];
1769
1778
  scope[promiseAccessor] = 0;
1770
- schedule();
1779
+ queueMicrotask(run);
1771
1780
  queueRender(
1772
1781
  scope,
1773
1782
  () => {
1774
- if (scope[branchAccessor]) {
1775
- if (!tryWithPlaceholder) {
1776
- scope[nodeAccessor].replaceWith(
1777
- scope[branchAccessor]["#StartNode" /* StartNode */].parentNode
1778
- );
1779
- }
1780
- } else {
1783
+ if ((awaitBranch = scope[branchAccessor])["#DetachedAwait" /* DetachedAwait */]) {
1784
+ pendingScopes.push(awaitBranch);
1785
+ setupBranch(
1786
+ awaitBranch["#DetachedAwait" /* DetachedAwait */],
1787
+ awaitBranch
1788
+ );
1789
+ awaitBranch["#DetachedAwait" /* DetachedAwait */] = 0;
1781
1790
  insertBranchBefore(
1782
- scope[branchAccessor] = createAndSetupBranch(
1783
- scope["$global" /* Global */],
1784
- scope[rendererAccessor],
1785
- scope,
1786
- scope[nodeAccessor].parentNode
1787
- ),
1791
+ awaitBranch,
1788
1792
  scope[nodeAccessor].parentNode,
1789
1793
  scope[nodeAccessor]
1790
1794
  );
1791
- scope[nodeAccessor].remove();
1795
+ referenceNode.remove();
1792
1796
  }
1793
- params?.(scope[branchAccessor], [data]);
1794
- if (awaitCounter) {
1795
- placeholderShown.add(pendingEffects);
1796
- awaitCounter.c();
1797
- if (!awaitCounter.d) {
1798
- const fnScopes = /* @__PURE__ */ new Map();
1799
- const effects = renderData.m();
1800
- for (let i = 0; i < pendingEffects.length; ) {
1801
- const fn = pendingEffects[i++];
1802
- let scopes = fnScopes.get(fn);
1803
- if (!scopes) {
1804
- fnScopes.set(fn, scopes = /* @__PURE__ */ new Set());
1805
- }
1806
- scopes.add(pendingEffects[i++]);
1797
+ params?.(awaitBranch, [data]);
1798
+ const pendingRenders2 = awaitBranch["#PendingRenders" /* PendingRenders */];
1799
+ awaitBranch["#PendingRenders" /* PendingRenders */] = 0;
1800
+ pendingRenders2?.forEach(queuePendingRender);
1801
+ placeholderShown.add(pendingEffects);
1802
+ awaitCounter.c();
1803
+ if (awaitCounter.m) {
1804
+ const fnScopes = /* @__PURE__ */ new Map();
1805
+ const effects = awaitCounter.m();
1806
+ for (let i = 0; i < pendingEffects.length; ) {
1807
+ const fn = pendingEffects[i++];
1808
+ let scopes = fnScopes.get(fn);
1809
+ if (!scopes) {
1810
+ fnScopes.set(fn, scopes = /* @__PURE__ */ new Set());
1807
1811
  }
1808
- for (let i = 0; i < effects.length; ) {
1809
- const fn = effects[i++];
1810
- const scope2 = effects[i++];
1811
- if (!fnScopes.get(fn)?.has(scope2)) {
1812
- queueEffect(scope2, fn);
1813
- }
1812
+ scopes.add(pendingEffects[i++]);
1813
+ }
1814
+ for (let i = 0; i < effects.length; ) {
1815
+ const fn = effects[i++];
1816
+ const scope2 = effects[i++];
1817
+ if (!fnScopes.get(fn)?.has(scope2)) {
1818
+ queueEffect(scope2, fn);
1814
1819
  }
1815
1820
  }
1816
1821
  }
@@ -1821,8 +1826,7 @@ function _await_promise(nodeAccessor, params) {
1821
1826
  },
1822
1827
  (error) => {
1823
1828
  if (thisPromise === scope[promiseAccessor]) {
1824
- if (awaitCounter) awaitCounter.i = 0;
1825
- scope[promiseAccessor] = 0;
1829
+ awaitCounter.i = scope[promiseAccessor] = 0;
1826
1830
  schedule();
1827
1831
  queueRender(scope, renderCatch, -1, error);
1828
1832
  }
@@ -1831,10 +1835,17 @@ function _await_promise(nodeAccessor, params) {
1831
1835
  };
1832
1836
  }
1833
1837
  function _await_content(nodeAccessor, template, walks, setup) {
1834
- const rendererAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + (true ? nodeAccessor : decodeAccessor4(nodeAccessor));
1838
+ if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
1839
+ const branchAccessor = "BranchScopes:" /* BranchScopes */ + nodeAccessor;
1835
1840
  const renderer = _content("", template, walks, setup)();
1836
1841
  return (scope) => {
1837
- scope[rendererAccessor] = renderer;
1842
+ (scope[branchAccessor] = createBranch(
1843
+ scope["$global" /* Global */],
1844
+ renderer,
1845
+ scope,
1846
+ scope[nodeAccessor].parentNode
1847
+ ))["#DetachedAwait" /* DetachedAwait */] = renderer;
1848
+ pendingScopes.pop();
1838
1849
  };
1839
1850
  }
1840
1851
  function _try(nodeAccessor, template, walks, setup) {
@@ -2137,6 +2148,7 @@ function byFirstArg(name) {
2137
2148
  // src/dom/queue.ts
2138
2149
  var pendingRenders = [];
2139
2150
  var pendingRendersLookup = /* @__PURE__ */ new Map();
2151
+ var asyncRendersLookup;
2140
2152
  var caughtError = /* @__PURE__ */ new WeakSet();
2141
2153
  var placeholderShown = /* @__PURE__ */ new WeakSet();
2142
2154
  var pendingEffects = [];
@@ -2145,50 +2157,56 @@ var rendering;
2145
2157
  var scopeKeyOffset = 1e3;
2146
2158
  function queueRender(scope, signal, signalKey, value, scopeKey = scope["#Id" /* Id */]) {
2147
2159
  const key = scopeKey * scopeKeyOffset + signalKey;
2148
- const existingRender = signalKey >= 0 && pendingRendersLookup.get(key);
2149
- if (existingRender) {
2150
- existingRender.___value = value;
2160
+ let render = signalKey >= 0 && pendingRendersLookup.get(key);
2161
+ if (render) {
2162
+ render.___value = value;
2151
2163
  } else {
2152
- const render = {
2153
- ___key: key,
2154
- ___scope: scope,
2155
- ___signal: signal,
2156
- ___value: value
2157
- };
2158
- let i = pendingRenders.push(render) - 1;
2159
- while (i) {
2160
- const parentIndex = i - 1 >> 1;
2161
- const parent = pendingRenders[parentIndex];
2162
- if (key - parent.___key >= 0) break;
2163
- pendingRenders[i] = parent;
2164
- i = parentIndex;
2165
- }
2164
+ queuePendingRender(
2165
+ render = {
2166
+ ___key: key,
2167
+ ___scope: scope,
2168
+ ___signal: signal,
2169
+ ___value: value
2170
+ }
2171
+ );
2166
2172
  signalKey >= 0 && pendingRendersLookup.set(key, render);
2167
- pendingRenders[i] = render;
2168
2173
  }
2169
2174
  }
2175
+ function queuePendingRender(render) {
2176
+ let i = pendingRenders.push(render) - 1;
2177
+ while (i) {
2178
+ const parentIndex = i - 1 >> 1;
2179
+ const parent = pendingRenders[parentIndex];
2180
+ if (render.___key - parent.___key >= 0) break;
2181
+ pendingRenders[i] = parent;
2182
+ i = parentIndex;
2183
+ }
2184
+ pendingRenders[i] = render;
2185
+ }
2170
2186
  function queueEffect(scope, fn) {
2171
2187
  pendingEffects.push(fn, scope);
2172
2188
  }
2173
2189
  function run() {
2174
2190
  const effects = pendingEffects;
2191
+ asyncRendersLookup = /* @__PURE__ */ new Map();
2175
2192
  try {
2176
2193
  rendering = 1;
2177
2194
  runRenders();
2178
2195
  } finally {
2196
+ pendingRendersLookup = asyncRendersLookup;
2197
+ asyncRendersLookup = rendering = 0;
2179
2198
  pendingRenders = [];
2180
- pendingRendersLookup = /* @__PURE__ */ new Map();
2181
2199
  pendingEffects = [];
2182
- rendering = 0;
2183
2200
  }
2184
2201
  runEffects(effects);
2185
2202
  }
2186
2203
  function prepareEffects(fn) {
2187
2204
  const prevRenders = pendingRenders;
2188
- const prevRendersLookup = pendingRendersLookup;
2189
2205
  const prevEffects = pendingEffects;
2206
+ const prevLookup = asyncRendersLookup;
2190
2207
  const preparedEffects = pendingEffects = [];
2191
2208
  pendingRenders = [];
2209
+ asyncRendersLookup = pendingRendersLookup;
2192
2210
  pendingRendersLookup = /* @__PURE__ */ new Map();
2193
2211
  try {
2194
2212
  rendering = 1;
@@ -2196,8 +2214,9 @@ function prepareEffects(fn) {
2196
2214
  runRenders();
2197
2215
  } finally {
2198
2216
  rendering = 0;
2217
+ pendingRendersLookup = asyncRendersLookup;
2218
+ asyncRendersLookup = prevLookup;
2199
2219
  pendingRenders = prevRenders;
2200
- pendingRendersLookup = prevRendersLookup;
2201
2220
  pendingEffects = prevEffects;
2202
2221
  }
2203
2222
  return preparedEffects;
@@ -2272,6 +2291,17 @@ var _enable_catch = () => {
2272
2291
  })(runEffects);
2273
2292
  runRender = /* @__PURE__ */ ((runRender2) => (render) => {
2274
2293
  try {
2294
+ let branch = render.___scope["#ClosestBranch" /* ClosestBranch */];
2295
+ while (branch) {
2296
+ if (branch["#PendingRenders" /* PendingRenders */]) {
2297
+ asyncRendersLookup.set(
2298
+ render.___key,
2299
+ render
2300
+ );
2301
+ return branch["#PendingRenders" /* PendingRenders */].push(render);
2302
+ }
2303
+ branch = branch["#ParentBranch" /* ParentBranch */];
2304
+ }
2275
2305
  runRender2(render);
2276
2306
  } catch (error) {
2277
2307
  renderCatch(render.___scope, error);