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.
package/dist/debug/dom.js CHANGED
@@ -370,6 +370,14 @@ function stripSpacesAndPunctuation(str) {
370
370
  return str.replace(/[^\p{L}\p{N}]/gu, "");
371
371
  }
372
372
 
373
+ // src/dom/parse-html.ts
374
+ var parsers = {};
375
+ function parseHTML(html, ns) {
376
+ const parser = parsers[ns] ||= document.createElementNS(ns, "template");
377
+ parser.innerHTML = html;
378
+ return parser.content || parser;
379
+ }
380
+
373
381
  // src/dom/scope.ts
374
382
  var nextScopeId = 1e6;
375
383
  function createScope($global, closestBranch) {
@@ -433,6 +441,247 @@ function tempDetachBranch(branch) {
433
441
  );
434
442
  }
435
443
 
444
+ // src/dom/schedule.ts
445
+ var runTask;
446
+ var isScheduled;
447
+ var channel;
448
+ function schedule() {
449
+ if (!isScheduled) {
450
+ if (true) {
451
+ if (console.createTask) {
452
+ const task = console.createTask("queue");
453
+ runTask = () => task.run(run);
454
+ } else {
455
+ runTask = run;
456
+ }
457
+ }
458
+ isScheduled = 1;
459
+ queueMicrotask(flushAndWaitFrame);
460
+ }
461
+ }
462
+ function flushAndWaitFrame() {
463
+ if (true) {
464
+ runTask();
465
+ } else {
466
+ run();
467
+ }
468
+ requestAnimationFrame(triggerMacroTask);
469
+ }
470
+ function triggerMacroTask() {
471
+ if (!channel) {
472
+ channel = new MessageChannel();
473
+ channel.port1.onmessage = () => {
474
+ isScheduled = 0;
475
+ if (true) {
476
+ const run2 = runTask;
477
+ runTask = void 0;
478
+ run2();
479
+ } else {
480
+ run();
481
+ }
482
+ };
483
+ }
484
+ channel.port2.postMessage(0);
485
+ }
486
+
487
+ // src/dom/signals.ts
488
+ function _let(id, fn) {
489
+ const valueAccessor = true ? id.slice(0, id.lastIndexOf("/")) : decodeAccessor(id);
490
+ const valueChangeAccessor = "TagVariableChange:" /* TagVariableChange */ + valueAccessor;
491
+ if (true) {
492
+ id = +id.slice(id.lastIndexOf("/") + 1);
493
+ }
494
+ return (scope, value, valueChange) => {
495
+ if (rendering) {
496
+ if ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope["#Creating" /* Creating */]) {
497
+ scope[valueAccessor] = value;
498
+ fn?.(scope);
499
+ }
500
+ } else if (scope[valueChangeAccessor]) {
501
+ scope[valueChangeAccessor](value);
502
+ } else if (scope[valueAccessor] !== (scope[valueAccessor] = value) && fn) {
503
+ schedule();
504
+ queueRender(scope, fn, id);
505
+ }
506
+ return value;
507
+ };
508
+ }
509
+ function _const(valueAccessor, fn) {
510
+ if (false) valueAccessor = decodeAccessor(valueAccessor);
511
+ return (scope, value) => {
512
+ if (!(valueAccessor in scope) || scope[valueAccessor] !== value) {
513
+ scope[valueAccessor] = value;
514
+ fn?.(scope);
515
+ }
516
+ };
517
+ }
518
+ function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id" /* Id */) {
519
+ return (scope) => {
520
+ if (scope["#Creating" /* Creating */]) {
521
+ if (id in scope) {
522
+ if (!--scope[id]) {
523
+ fn(scope);
524
+ }
525
+ } else {
526
+ scope[id] = defaultPending;
527
+ }
528
+ } else {
529
+ queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
530
+ }
531
+ };
532
+ }
533
+ function _for_closure(ownerLoopNodeAccessor, fn) {
534
+ if (false)
535
+ ownerLoopNodeAccessor = decodeAccessor(ownerLoopNodeAccessor);
536
+ const scopeAccessor = "BranchScopes:" /* BranchScopes */ + ownerLoopNodeAccessor;
537
+ const ownerSignal = (ownerScope) => {
538
+ const scopes = toArray(ownerScope[scopeAccessor]);
539
+ if (scopes.length) {
540
+ queueRender(
541
+ ownerScope,
542
+ () => {
543
+ for (const scope of scopes) {
544
+ if (!scope["#Creating" /* Creating */] && !scope["#Destroyed" /* Destroyed */]) {
545
+ fn(scope);
546
+ }
547
+ }
548
+ },
549
+ -1,
550
+ 0,
551
+ scopes[0]["#Id" /* Id */]
552
+ );
553
+ }
554
+ };
555
+ ownerSignal._ = fn;
556
+ return ownerSignal;
557
+ }
558
+ function _if_closure(ownerConditionalNodeAccessor, branch, fn) {
559
+ if (false)
560
+ ownerConditionalNodeAccessor = decodeAccessor(
561
+ ownerConditionalNodeAccessor
562
+ );
563
+ const scopeAccessor = "BranchScopes:" /* BranchScopes */ + ownerConditionalNodeAccessor;
564
+ const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + ownerConditionalNodeAccessor;
565
+ const ownerSignal = (scope) => {
566
+ const ifScope = scope[scopeAccessor];
567
+ if (ifScope && !ifScope["#Creating" /* Creating */] && (scope[branchAccessor] || 0) === branch) {
568
+ queueRender(ifScope, fn, -1);
569
+ }
570
+ };
571
+ ownerSignal._ = fn;
572
+ return ownerSignal;
573
+ }
574
+ function subscribeToScopeSet(ownerScope, accessor, scope) {
575
+ const subscribers = ownerScope[accessor] ||= /* @__PURE__ */ new Set();
576
+ if (!subscribers.has(scope)) {
577
+ subscribers.add(scope);
578
+ $signal(scope, -1).addEventListener(
579
+ "abort",
580
+ () => ownerScope[accessor].delete(scope)
581
+ );
582
+ }
583
+ }
584
+ function _closure(...closureSignals) {
585
+ const [{ ___scopeInstancesAccessor, ___signalIndexAccessor }] = closureSignals;
586
+ for (let i = closureSignals.length; i--; ) {
587
+ closureSignals[i].___index = i;
588
+ }
589
+ return (scope) => {
590
+ if (scope[___scopeInstancesAccessor]) {
591
+ for (const childScope of scope[___scopeInstancesAccessor]) {
592
+ if (!childScope["#Creating" /* Creating */]) {
593
+ queueRender(
594
+ childScope,
595
+ closureSignals[childScope[___signalIndexAccessor]],
596
+ -1
597
+ );
598
+ }
599
+ }
600
+ }
601
+ };
602
+ }
603
+ function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
604
+ if (false) valueAccessor = decodeAccessor(valueAccessor);
605
+ const closureSignal = ((scope) => {
606
+ scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
607
+ fn(scope);
608
+ subscribeToScopeSet(
609
+ getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */],
610
+ closureSignal.___scopeInstancesAccessor,
611
+ scope
612
+ );
613
+ });
614
+ closureSignal.___scopeInstancesAccessor = "ClosureScopes:" /* ClosureScopes */ + valueAccessor;
615
+ closureSignal.___signalIndexAccessor = "ClosureSignalIndex:" /* ClosureSignalIndex */ + valueAccessor;
616
+ resumeId && _resume(resumeId, closureSignal);
617
+ return closureSignal;
618
+ }
619
+ function _child_setup(setup) {
620
+ setup._ = (scope, owner) => {
621
+ scope["_" /* Owner */] = owner;
622
+ queueRender(scope, setup, -1);
623
+ };
624
+ return setup;
625
+ }
626
+ function _var(scope, childAccessor, signal) {
627
+ scope[true ? childAccessor : decodeAccessor(childAccessor)]["#TagVariable" /* TagVariable */] = (value) => signal(scope, value);
628
+ }
629
+ var _return = (scope, value) => scope["#TagVariable" /* TagVariable */]?.(value);
630
+ function _return_change(scope, changeHandler) {
631
+ if (changeHandler) {
632
+ scope["#TagVariableChange" /* TagVariableChange */] = changeHandler;
633
+ }
634
+ }
635
+ var _var_change = true ? (scope, value, name = "This") => {
636
+ if (typeof scope["#TagVariableChange" /* TagVariableChange */] !== "function") {
637
+ throw new TypeError(`${name} is a readonly tag variable.`);
638
+ }
639
+ scope["#TagVariableChange" /* TagVariableChange */](value);
640
+ } : (scope, value) => scope["#TagVariableChange" /* TagVariableChange */]?.(value);
641
+ var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
642
+ function _id({ ["$global" /* Global */]: $global }) {
643
+ const id = tagIdsByGlobal.get($global) || 0;
644
+ tagIdsByGlobal.set($global, id + 1);
645
+ return "c" + $global.runtimeId + $global.renderId + id.toString(36);
646
+ }
647
+ function _script(id, fn) {
648
+ _resume(id, fn);
649
+ return (scope) => {
650
+ queueEffect(scope, fn);
651
+ };
652
+ }
653
+ function _el_read(value) {
654
+ if (rendering) {
655
+ _el_read_error();
656
+ }
657
+ return value;
658
+ }
659
+ function* traverseAllHoisted(scope, path, curIndex = path.length - 1) {
660
+ if (rendering) {
661
+ _hoist_read_error();
662
+ }
663
+ if (scope) {
664
+ if (Symbol.iterator in scope) {
665
+ for (const s of scope instanceof Map ? scope.values() : scope) {
666
+ yield* traverseAllHoisted(s, path, curIndex);
667
+ }
668
+ } else if (curIndex) {
669
+ yield* traverseAllHoisted(scope[path[curIndex]], path, curIndex - 1);
670
+ } else {
671
+ yield scope[path[0]];
672
+ }
673
+ }
674
+ }
675
+ function _hoist(...path) {
676
+ if (false)
677
+ path = path.map((p) => typeof p === "string" ? p : decodeAccessor(p));
678
+ return (scope) => {
679
+ const getOne = (...args) => iterator().next().value?.(...args);
680
+ const iterator = getOne[Symbol.iterator] = () => traverseAllHoisted(scope, path);
681
+ return getOne;
682
+ };
683
+ }
684
+
436
685
  // src/dom/walker.ts
437
686
  var walker = /* @__PURE__ */ document.createTreeWalker(document);
438
687
  function walk(startNode, walkCodes, branch) {
@@ -451,14 +700,14 @@ function walkInternal(currentWalkIndex, walkCodes, scope) {
451
700
  storedMultiplier = 0;
452
701
  if (value === 32 /* Get */) {
453
702
  const node = walker.currentNode;
454
- scope[id = true ? getDebugKey(currentScopeIndex++, node) : decodeAccessor(currentScopeIndex++)] = node;
703
+ scope[id = true ? getDebugKey(currentScopeIndex++, node) : decodeAccessor2(currentScopeIndex++)] = node;
455
704
  scope["Getter:" /* Getter */ + id] = () => node;
456
705
  } else if (value === 37 /* Replace */ || value === 49 /* DynamicTagWithVar */) {
457
706
  walker.currentNode.replaceWith(
458
- walker.currentNode = scope[true ? getDebugKey(currentScopeIndex++, "#text") : decodeAccessor(currentScopeIndex++)] = new Text()
707
+ walker.currentNode = scope[true ? getDebugKey(currentScopeIndex++, "#text") : decodeAccessor2(currentScopeIndex++)] = new Text()
459
708
  );
460
709
  if (value === 49 /* DynamicTagWithVar */) {
461
- scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : decodeAccessor(currentScopeIndex++)] = skipScope();
710
+ scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : decodeAccessor2(currentScopeIndex++)] = skipScope();
462
711
  }
463
712
  } else if (value === 38 /* EndChild */) {
464
713
  return currentWalkIndex;
@@ -466,13 +715,13 @@ function walkInternal(currentWalkIndex, walkCodes, scope) {
466
715
  currentWalkIndex = walkInternal(
467
716
  currentWalkIndex,
468
717
  walkCodes,
469
- scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : decodeAccessor(currentScopeIndex++)] = createScope(
718
+ scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : decodeAccessor2(currentScopeIndex++)] = createScope(
470
719
  scope["$global" /* Global */],
471
720
  scope["#ClosestBranch" /* ClosestBranch */]
472
721
  )
473
722
  );
474
723
  if (value === 48 /* BeginChildWithVar */) {
475
- scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : decodeAccessor(currentScopeIndex++)] = skipScope();
724
+ scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : decodeAccessor2(currentScopeIndex++)] = skipScope();
476
725
  }
477
726
  } else if (value < 91 /* NextEnd */ + 1) {
478
727
  value = 20 /* Next */ * currentMultiplier + value - 67 /* Next */;
@@ -511,19 +760,116 @@ function getDebugKey(index, node) {
511
760
  return index;
512
761
  }
513
762
 
514
- // src/dom/resume.ts
515
- var registeredValues = {};
516
- var branchesEnabled;
517
- function enableBranches() {
518
- branchesEnabled = 1;
519
- }
520
- function init(runtimeId = DEFAULT_RUNTIME_ID) {
763
+ // src/dom/renderer.ts
764
+ function createBranch($global, renderer, parentScope, parentNode) {
765
+ const branch = createScope($global);
766
+ branch["_" /* Owner */] = renderer.___owner || parentScope;
767
+ setParentBranch(branch, parentScope?.["#ClosestBranch" /* ClosestBranch */]);
521
768
  if (true) {
522
- const descriptor = Object.getOwnPropertyDescriptor(self, runtimeId);
523
- if (descriptor && (descriptor.set || descriptor.configurable === false)) {
524
- throw new Error(
525
- `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.`
526
- );
769
+ branch["#Renderer" /* Renderer */] = renderer;
770
+ }
771
+ renderer.___clone?.(
772
+ branch,
773
+ parentNode.namespaceURI
774
+ );
775
+ return branch;
776
+ }
777
+ function setParentBranch(branch, parentBranch) {
778
+ if (parentBranch) {
779
+ branch["#ParentBranch" /* ParentBranch */] = parentBranch;
780
+ (parentBranch["#BranchScopes" /* BranchScopes */] ||= /* @__PURE__ */ new Set()).add(branch);
781
+ }
782
+ branch["#ClosestBranch" /* ClosestBranch */] = branch;
783
+ }
784
+ function createAndSetupBranch($global, renderer, parentScope, parentNode) {
785
+ return setupBranch(
786
+ renderer,
787
+ createBranch($global, renderer, parentScope, parentNode)
788
+ );
789
+ }
790
+ function setupBranch(renderer, branch) {
791
+ if (renderer.___setup) {
792
+ queueRender(branch, renderer.___setup, -1);
793
+ }
794
+ return branch;
795
+ }
796
+ function _content(id, template, walks, setup, params, dynamicScopesAccessor) {
797
+ walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
798
+ setup = setup ? setup._ || setup : void 0;
799
+ params ||= void 0;
800
+ const clone = template ? (branch, ns) => {
801
+ ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
802
+ template,
803
+ ns
804
+ ))(branch, walks);
805
+ } : (branch) => {
806
+ walk(
807
+ branch["#StartNode" /* StartNode */] = branch["#EndNode" /* EndNode */] = new Text(),
808
+ walks,
809
+ branch
810
+ );
811
+ };
812
+ return (owner) => {
813
+ return {
814
+ ___id: id,
815
+ ___clone: clone,
816
+ ___owner: owner,
817
+ ___setup: setup,
818
+ ___params: params,
819
+ ___accessor: dynamicScopesAccessor
820
+ };
821
+ };
822
+ }
823
+ function _content_resume(id, template, walks, setup, params, dynamicScopesAccessor) {
824
+ return _resume(
825
+ id,
826
+ _content(id, template, walks, setup, params, dynamicScopesAccessor)
827
+ );
828
+ }
829
+ function _content_closures(renderer, closureFns) {
830
+ const closureSignals = {};
831
+ for (const key in closureFns) {
832
+ closureSignals[key] = _const(true ? key : +key, closureFns[key]);
833
+ }
834
+ return (owner, closureValues) => {
835
+ const instance = renderer(owner);
836
+ instance.___localClosures = closureSignals;
837
+ instance.___localClosureValues = closureValues;
838
+ return instance;
839
+ };
840
+ }
841
+ var cloneCache = {};
842
+ function createCloneableHTML(html, ns) {
843
+ const { firstChild, lastChild } = parseHTML(html, ns);
844
+ const parent = document.createElementNS(ns, "t");
845
+ insertChildNodes(parent, null, firstChild, lastChild);
846
+ return firstChild === lastChild && firstChild.nodeType < 8 /* Comment */ ? (branch, walks) => {
847
+ walk(
848
+ branch["#StartNode" /* StartNode */] = branch["#EndNode" /* EndNode */] = firstChild.cloneNode(true),
849
+ walks,
850
+ branch
851
+ );
852
+ } : (branch, walks) => {
853
+ const clone = parent.cloneNode(true);
854
+ walk(clone.firstChild, walks, branch);
855
+ branch["#StartNode" /* StartNode */] = clone.firstChild;
856
+ branch["#EndNode" /* EndNode */] = clone.lastChild;
857
+ };
858
+ }
859
+
860
+ // src/dom/resume.ts
861
+ var registeredValues = {};
862
+ var branchesEnabled;
863
+ function enableBranches() {
864
+ branchesEnabled = 1;
865
+ }
866
+ function init(runtimeId = DEFAULT_RUNTIME_ID) {
867
+ if (true) {
868
+ const descriptor = Object.getOwnPropertyDescriptor(self, runtimeId);
869
+ if (descriptor && (descriptor.set || descriptor.configurable === false)) {
870
+ throw new Error(
871
+ `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.`
872
+ );
527
873
  }
528
874
  }
529
875
  const renders = self[runtimeId];
@@ -539,7 +885,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
539
885
  _: registeredValues
540
886
  };
541
887
  const visitBranches = branchesEnabled && /* @__PURE__ */ ((branchScopesStack = [], branchStarts = [], orphanBranches = [], curBranchScopes) => {
542
- return (branchId, branch, childBranch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
888
+ return (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
543
889
  if (visitType !== "[" /* BranchStart */) {
544
890
  visitScope["Getter:" /* Getter */ + nextToken(
545
891
  /* read accessor */
@@ -558,7 +904,10 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
558
904
  ["#Id" /* Id */]: branchId
559
905
  }
560
906
  );
561
- branch["#ClosestBranch" /* ClosestBranch */] = branch;
907
+ setParentBranch(branch, branch["#ClosestBranch" /* ClosestBranch */]);
908
+ if (branch["#AwaitCounter" /* AwaitCounter */] = render.p?.[branchId]) {
909
+ branch["#AwaitCounter" /* AwaitCounter */].m = render.m;
910
+ }
562
911
  if (singleNode) {
563
912
  while (startVisit.previousSibling && ~visits.indexOf(
564
913
  startVisit = startVisit.previousSibling
@@ -581,10 +930,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
581
930
  branch["#EndNode" /* EndNode */] = visit.previousSibling === startVisit ? startVisit : parent.insertBefore(new Text(), visit);
582
931
  }
583
932
  while (i && orphanBranches[--i]["#Id" /* Id */] > branchId) {
584
- (childBranch = orphanBranches.pop())["#ParentBranch" /* ParentBranch */] = branch;
585
- (branch["#BranchScopes" /* BranchScopes */] ||= /* @__PURE__ */ new Set()).add(
586
- childBranch
587
- );
933
+ setParentBranch(orphanBranches.pop(), branch);
588
934
  }
589
935
  nextToken(
590
936
  /* read optional next branchId */
@@ -714,7 +1060,7 @@ function _var_resume(id, signal) {
714
1060
  return signal;
715
1061
  }
716
1062
  function _el(id, accessor) {
717
- const getterAccessor = "Getter:" /* Getter */ + (true ? accessor : decodeAccessor2(accessor));
1063
+ const getterAccessor = "Getter:" /* Getter */ + (true ? accessor : decodeAccessor3(accessor));
718
1064
  return _resume(id, (scope) => () => {
719
1065
  return scope[getterAccessor]();
720
1066
  });
@@ -876,463 +1222,120 @@ function setSelectOptions(el, value, valueChange) {
876
1222
  } else {
877
1223
  for (const opt of el.options) {
878
1224
  opt.defaultSelected = opt.value === normalizedValue;
879
- }
880
- }
881
- }
882
- }
883
- function _attr_details_or_dialog_open(scope, nodeAccessor, open, openChange) {
884
- scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor] = openChange;
885
- if (openChange) {
886
- scope["ControlledType:" /* ControlledType */ + nodeAccessor] = 4 /* DetailsOrDialogOpen */;
887
- } else {
888
- scope["ControlledType:" /* ControlledType */ + nodeAccessor] = 5 /* None */;
889
- }
890
- scope[nodeAccessor].open = scope["ControlledValue:" /* ControlledValue */ + nodeAccessor] = normalizeBoolProp(open);
891
- }
892
- function _attr_details_or_dialog_open_script(scope, nodeAccessor) {
893
- const el = scope[nodeAccessor];
894
- const hasChanged = () => el.open !== scope["ControlledValue:" /* ControlledValue */ + nodeAccessor];
895
- syncControllable(
896
- el,
897
- el.tagName === "DIALOG" ? "close" : "toggle",
898
- hasChanged,
899
- () => {
900
- const openChange = scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor];
901
- if (openChange && hasChanged()) {
902
- const newValue = el.open;
903
- el.open = !newValue;
904
- openChange(newValue);
905
- run();
906
- }
907
- }
908
- );
909
- }
910
- var inputType = "";
911
- function setValueAndUpdateSelection(el, value) {
912
- if (el.value !== value) {
913
- const updatedPosition = resolveCursorPosition(
914
- inputType,
915
- el.getRootNode().activeElement === el && el.selectionStart,
916
- el.value,
917
- el.value = value
918
- );
919
- if (~updatedPosition) {
920
- el.setSelectionRange(updatedPosition, updatedPosition);
921
- }
922
- }
923
- }
924
- function setCheckboxValue(scope, nodeAccessor, type, checked, checkedChange) {
925
- scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor] = checkedChange;
926
- if (checkedChange) {
927
- scope["ControlledType:" /* ControlledType */ + nodeAccessor] = type;
928
- scope[nodeAccessor].checked = checked;
929
- } else {
930
- scope["ControlledType:" /* ControlledType */ + nodeAccessor] = 5 /* None */;
931
- scope[nodeAccessor].defaultChecked = checked;
932
- }
933
- }
934
- var controllableDelegate = createDelegator();
935
- function syncControllable(el, event, hasChanged, onChange) {
936
- if (!el._) {
937
- controllableDelegate(el, event, handleChange);
938
- if (el.form) {
939
- controllableDelegate(el.form, "reset", handleFormReset);
940
- }
941
- if (isResuming && hasChanged(el)) {
942
- queueMicrotask(onChange);
943
- }
944
- }
945
- el._ = onChange;
946
- }
947
- function handleChange(ev) {
948
- ev.target._?.(ev);
949
- }
950
- function handleFormReset(ev) {
951
- const handlers = [];
952
- for (const el of ev.target.elements) {
953
- if (el._ && hasFormElementChanged(el)) {
954
- handlers.push(el._);
955
- }
956
- }
957
- requestAnimationFrame(() => {
958
- if (!ev.defaultPrevented) {
959
- for (const change of handlers) {
960
- change();
961
- }
962
- }
963
- });
964
- }
965
- function hasValueChanged(el) {
966
- return el.value !== el.defaultValue;
967
- }
968
- function hasCheckboxChanged(el) {
969
- return el.checked !== el.defaultChecked;
970
- }
971
- function hasSelectChanged(el) {
972
- for (const opt of el.options) {
973
- if (opt.selected !== opt.defaultSelected) {
974
- return true;
975
- }
976
- }
977
- }
978
- function hasFormElementChanged(el) {
979
- return el.options ? hasSelectChanged(el) : hasValueChanged(el) || hasCheckboxChanged(el);
980
- }
981
- function normalizeStrProp(value) {
982
- return normalizeAttrValue(value) || "";
983
- }
984
- function normalizeBoolProp(value) {
985
- return value != null && value !== false;
986
- }
987
- function updateList(arr, val, push2) {
988
- const index = arr.indexOf(val);
989
- return (push2 ? !~index && [...arr, val] : ~index && arr.slice(0, index).concat(arr.slice(index + 1))) || arr;
990
- }
991
- function toValueProp(it) {
992
- return it.value;
993
- }
994
-
995
- // src/dom/parse-html.ts
996
- var parsers = {};
997
- function parseHTML(html, ns) {
998
- const parser = parsers[ns] ||= document.createElementNS(ns, "template");
999
- parser.innerHTML = html;
1000
- return parser.content || parser;
1001
- }
1002
-
1003
- // src/dom/schedule.ts
1004
- var runTask;
1005
- var isScheduled;
1006
- var channel;
1007
- function schedule() {
1008
- if (!isScheduled) {
1009
- if (true) {
1010
- if (console.createTask) {
1011
- const task = console.createTask("queue");
1012
- runTask = () => task.run(run);
1013
- } else {
1014
- runTask = run;
1015
- }
1016
- }
1017
- isScheduled = 1;
1018
- queueMicrotask(flushAndWaitFrame);
1019
- }
1020
- }
1021
- function flushAndWaitFrame() {
1022
- if (true) {
1023
- runTask();
1024
- } else {
1025
- run();
1026
- }
1027
- requestAnimationFrame(triggerMacroTask);
1028
- }
1029
- function triggerMacroTask() {
1030
- if (!channel) {
1031
- channel = new MessageChannel();
1032
- channel.port1.onmessage = () => {
1033
- isScheduled = 0;
1034
- if (true) {
1035
- const run2 = runTask;
1036
- runTask = void 0;
1037
- run2();
1038
- } else {
1039
- run();
1040
- }
1041
- };
1042
- }
1043
- channel.port2.postMessage(0);
1044
- }
1045
-
1046
- // src/dom/signals.ts
1047
- function _let(id, fn) {
1048
- const valueAccessor = true ? id.slice(0, id.lastIndexOf("/")) : decodeAccessor3(id);
1049
- const valueChangeAccessor = "TagVariableChange:" /* TagVariableChange */ + valueAccessor;
1050
- if (true) {
1051
- id = +id.slice(id.lastIndexOf("/") + 1);
1052
- }
1053
- return (scope, value, valueChange) => {
1054
- if (rendering) {
1055
- if ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope["#Creating" /* Creating */]) {
1056
- scope[valueAccessor] = value;
1057
- fn?.(scope);
1058
- }
1059
- } else if (scope[valueChangeAccessor]) {
1060
- scope[valueChangeAccessor](value);
1061
- } else if (scope[valueAccessor] !== (scope[valueAccessor] = value) && fn) {
1062
- schedule();
1063
- queueRender(scope, fn, id);
1064
- }
1065
- return value;
1066
- };
1067
- }
1068
- function _const(valueAccessor, fn) {
1069
- if (false) valueAccessor = decodeAccessor3(valueAccessor);
1070
- return (scope, value) => {
1071
- if (!(valueAccessor in scope) || scope[valueAccessor] !== value) {
1072
- scope[valueAccessor] = value;
1073
- fn?.(scope);
1074
- }
1075
- };
1076
- }
1077
- function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id" /* Id */) {
1078
- return (scope) => {
1079
- if (scope["#Creating" /* Creating */]) {
1080
- if (id in scope) {
1081
- if (!--scope[id]) {
1082
- fn(scope);
1083
- }
1084
- } else {
1085
- scope[id] = defaultPending;
1086
- }
1087
- } else {
1088
- queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
1089
- }
1090
- };
1091
- }
1092
- function _for_closure(ownerLoopNodeAccessor, fn) {
1093
- if (false)
1094
- ownerLoopNodeAccessor = decodeAccessor3(ownerLoopNodeAccessor);
1095
- const scopeAccessor = "BranchScopes:" /* BranchScopes */ + ownerLoopNodeAccessor;
1096
- const ownerSignal = (ownerScope) => {
1097
- const scopes = toArray(ownerScope[scopeAccessor]);
1098
- if (scopes.length) {
1099
- queueRender(
1100
- ownerScope,
1101
- () => {
1102
- for (const scope of scopes) {
1103
- if (!scope["#Creating" /* Creating */] && !scope["#Destroyed" /* Destroyed */]) {
1104
- fn(scope);
1105
- }
1106
- }
1107
- },
1108
- -1,
1109
- 0,
1110
- scopes[0]["#Id" /* Id */]
1111
- );
1112
- }
1113
- };
1114
- ownerSignal._ = fn;
1115
- return ownerSignal;
1116
- }
1117
- function _if_closure(ownerConditionalNodeAccessor, branch, fn) {
1118
- if (false)
1119
- ownerConditionalNodeAccessor = decodeAccessor3(
1120
- ownerConditionalNodeAccessor
1121
- );
1122
- const scopeAccessor = "BranchScopes:" /* BranchScopes */ + ownerConditionalNodeAccessor;
1123
- const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + ownerConditionalNodeAccessor;
1124
- const ownerSignal = (scope) => {
1125
- const ifScope = scope[scopeAccessor];
1126
- if (ifScope && !ifScope["#Creating" /* Creating */] && (scope[branchAccessor] || 0) === branch) {
1127
- queueRender(ifScope, fn, -1);
1128
- }
1129
- };
1130
- ownerSignal._ = fn;
1131
- return ownerSignal;
1132
- }
1133
- function subscribeToScopeSet(ownerScope, accessor, scope) {
1134
- const subscribers = ownerScope[accessor] ||= /* @__PURE__ */ new Set();
1135
- if (!subscribers.has(scope)) {
1136
- subscribers.add(scope);
1137
- $signal(scope, -1).addEventListener(
1138
- "abort",
1139
- () => ownerScope[accessor].delete(scope)
1140
- );
1141
- }
1142
- }
1143
- function _closure(...closureSignals) {
1144
- const [{ ___scopeInstancesAccessor, ___signalIndexAccessor }] = closureSignals;
1145
- for (let i = closureSignals.length; i--; ) {
1146
- closureSignals[i].___index = i;
1147
- }
1148
- return (scope) => {
1149
- if (scope[___scopeInstancesAccessor]) {
1150
- for (const childScope of scope[___scopeInstancesAccessor]) {
1151
- if (!childScope["#Creating" /* Creating */]) {
1152
- queueRender(
1153
- childScope,
1154
- closureSignals[childScope[___signalIndexAccessor]],
1155
- -1
1156
- );
1157
- }
1158
- }
1159
- }
1160
- };
1161
- }
1162
- function _closure_get(valueAccessor, fn, getOwnerScope) {
1163
- if (false) valueAccessor = decodeAccessor3(valueAccessor);
1164
- const closureSignal = ((scope) => {
1165
- scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
1166
- fn(scope);
1167
- subscribeToScopeSet(
1168
- getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */],
1169
- closureSignal.___scopeInstancesAccessor,
1170
- scope
1171
- );
1172
- });
1173
- closureSignal.___scopeInstancesAccessor = "ClosureScopes:" /* ClosureScopes */ + valueAccessor;
1174
- closureSignal.___signalIndexAccessor = "ClosureSignalIndex:" /* ClosureSignalIndex */ + valueAccessor;
1175
- return closureSignal;
1176
- }
1177
- function _child_setup(setup) {
1178
- setup._ = (scope, owner) => {
1179
- scope["_" /* Owner */] = owner;
1180
- queueRender(scope, setup, -1);
1181
- };
1182
- return setup;
1183
- }
1184
- function _var(scope, childAccessor, signal) {
1185
- scope[true ? childAccessor : decodeAccessor3(childAccessor)]["#TagVariable" /* TagVariable */] = (value) => signal(scope, value);
1186
- }
1187
- var _return = (scope, value) => scope["#TagVariable" /* TagVariable */]?.(value);
1188
- function _return_change(scope, changeHandler) {
1189
- if (changeHandler) {
1190
- scope["#TagVariableChange" /* TagVariableChange */] = changeHandler;
1225
+ }
1226
+ }
1191
1227
  }
1192
1228
  }
1193
- var _var_change = true ? (scope, value, name = "This") => {
1194
- if (typeof scope["#TagVariableChange" /* TagVariableChange */] !== "function") {
1195
- throw new TypeError(`${name} is a readonly tag variable.`);
1229
+ function _attr_details_or_dialog_open(scope, nodeAccessor, open, openChange) {
1230
+ scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor] = openChange;
1231
+ if (openChange) {
1232
+ scope["ControlledType:" /* ControlledType */ + nodeAccessor] = 4 /* DetailsOrDialogOpen */;
1233
+ } else {
1234
+ scope["ControlledType:" /* ControlledType */ + nodeAccessor] = 5 /* None */;
1196
1235
  }
1197
- scope["#TagVariableChange" /* TagVariableChange */](value);
1198
- } : (scope, value) => scope["#TagVariableChange" /* TagVariableChange */]?.(value);
1199
- var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
1200
- function _id({ ["$global" /* Global */]: $global }) {
1201
- const id = tagIdsByGlobal.get($global) || 0;
1202
- tagIdsByGlobal.set($global, id + 1);
1203
- return "c" + $global.runtimeId + $global.renderId + id.toString(36);
1236
+ scope[nodeAccessor].open = scope["ControlledValue:" /* ControlledValue */ + nodeAccessor] = normalizeBoolProp(open);
1204
1237
  }
1205
- function _script(id, fn) {
1206
- _resume(id, fn);
1207
- return (scope) => {
1208
- queueEffect(scope, fn);
1209
- };
1238
+ function _attr_details_or_dialog_open_script(scope, nodeAccessor) {
1239
+ const el = scope[nodeAccessor];
1240
+ const hasChanged = () => el.open !== scope["ControlledValue:" /* ControlledValue */ + nodeAccessor];
1241
+ syncControllable(
1242
+ el,
1243
+ el.tagName === "DIALOG" ? "close" : "toggle",
1244
+ hasChanged,
1245
+ () => {
1246
+ const openChange = scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor];
1247
+ if (openChange && hasChanged()) {
1248
+ const newValue = el.open;
1249
+ el.open = !newValue;
1250
+ openChange(newValue);
1251
+ run();
1252
+ }
1253
+ }
1254
+ );
1210
1255
  }
1211
- function _el_read(value) {
1212
- if (rendering) {
1213
- _el_read_error();
1256
+ var inputType = "";
1257
+ function setValueAndUpdateSelection(el, value) {
1258
+ if (el.value !== value) {
1259
+ const updatedPosition = resolveCursorPosition(
1260
+ inputType,
1261
+ el.getRootNode().activeElement === el && el.selectionStart,
1262
+ el.value,
1263
+ el.value = value
1264
+ );
1265
+ if (~updatedPosition) {
1266
+ el.setSelectionRange(updatedPosition, updatedPosition);
1267
+ }
1214
1268
  }
1215
- return value;
1216
1269
  }
1217
- function* traverseAllHoisted(scope, path, curIndex = path.length - 1) {
1218
- if (rendering) {
1219
- _hoist_read_error();
1270
+ function setCheckboxValue(scope, nodeAccessor, type, checked, checkedChange) {
1271
+ scope["ControlledHandler:" /* ControlledHandler */ + nodeAccessor] = checkedChange;
1272
+ if (checkedChange) {
1273
+ scope["ControlledType:" /* ControlledType */ + nodeAccessor] = type;
1274
+ scope[nodeAccessor].checked = checked;
1275
+ } else {
1276
+ scope["ControlledType:" /* ControlledType */ + nodeAccessor] = 5 /* None */;
1277
+ scope[nodeAccessor].defaultChecked = checked;
1220
1278
  }
1221
- if (scope) {
1222
- if (Symbol.iterator in scope) {
1223
- for (const s of scope instanceof Map ? scope.values() : scope) {
1224
- yield* traverseAllHoisted(s, path, curIndex);
1225
- }
1226
- } else if (curIndex) {
1227
- yield* traverseAllHoisted(scope[path[curIndex]], path, curIndex - 1);
1228
- } else {
1229
- yield scope[path[0]];
1279
+ }
1280
+ var controllableDelegate = createDelegator();
1281
+ function syncControllable(el, event, hasChanged, onChange) {
1282
+ if (!el._) {
1283
+ controllableDelegate(el, event, handleChange);
1284
+ if (el.form) {
1285
+ controllableDelegate(el.form, "reset", handleFormReset);
1286
+ }
1287
+ if (isResuming && hasChanged(el)) {
1288
+ queueMicrotask(onChange);
1230
1289
  }
1231
1290
  }
1291
+ el._ = onChange;
1232
1292
  }
1233
- function _hoist(...path) {
1234
- if (false)
1235
- path = path.map((p) => typeof p === "string" ? p : decodeAccessor3(p));
1236
- return (scope) => {
1237
- const getOne = (...args) => iterator().next().value?.(...args);
1238
- const iterator = getOne[Symbol.iterator] = () => traverseAllHoisted(scope, path);
1239
- return getOne;
1240
- };
1293
+ function handleChange(ev) {
1294
+ ev.target._?.(ev);
1241
1295
  }
1242
-
1243
- // src/dom/renderer.ts
1244
- function createBranch($global, renderer, parentScope, parentNode) {
1245
- const branch = createScope($global);
1246
- const parentBranch = parentScope?.["#ClosestBranch" /* ClosestBranch */];
1247
- branch["_" /* Owner */] = renderer.___owner || parentScope;
1248
- branch["#ClosestBranch" /* ClosestBranch */] = branch;
1249
- if (parentBranch) {
1250
- branch["#ParentBranch" /* ParentBranch */] = parentBranch;
1251
- (parentBranch["#BranchScopes" /* BranchScopes */] ||= /* @__PURE__ */ new Set()).add(branch);
1252
- }
1253
- if (true) {
1254
- branch["#Renderer" /* Renderer */] = renderer;
1296
+ function handleFormReset(ev) {
1297
+ const handlers = [];
1298
+ for (const el of ev.target.elements) {
1299
+ if (el._ && hasFormElementChanged(el)) {
1300
+ handlers.push(el._);
1301
+ }
1255
1302
  }
1256
- renderer.___clone?.(
1257
- branch,
1258
- parentNode.namespaceURI
1259
- );
1260
- return branch;
1303
+ requestAnimationFrame(() => {
1304
+ if (!ev.defaultPrevented) {
1305
+ for (const change of handlers) {
1306
+ change();
1307
+ }
1308
+ }
1309
+ });
1261
1310
  }
1262
- function createAndSetupBranch($global, renderer, parentScope, parentNode) {
1263
- return setupBranch(
1264
- renderer,
1265
- createBranch($global, renderer, parentScope, parentNode)
1266
- );
1311
+ function hasValueChanged(el) {
1312
+ return el.value !== el.defaultValue;
1267
1313
  }
1268
- function setupBranch(renderer, branch) {
1269
- if (renderer.___setup) {
1270
- queueRender(branch, renderer.___setup, -1);
1314
+ function hasCheckboxChanged(el) {
1315
+ return el.checked !== el.defaultChecked;
1316
+ }
1317
+ function hasSelectChanged(el) {
1318
+ for (const opt of el.options) {
1319
+ if (opt.selected !== opt.defaultSelected) {
1320
+ return true;
1321
+ }
1271
1322
  }
1272
- return branch;
1273
1323
  }
1274
- function _content(id, template, walks, setup, params, dynamicScopesAccessor) {
1275
- walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
1276
- setup = setup ? setup._ || setup : void 0;
1277
- params ||= void 0;
1278
- const clone = template ? (branch, ns) => {
1279
- ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
1280
- template,
1281
- ns
1282
- ))(branch, walks);
1283
- } : (branch) => {
1284
- walk(
1285
- branch["#StartNode" /* StartNode */] = branch["#EndNode" /* EndNode */] = new Text(),
1286
- walks,
1287
- branch
1288
- );
1289
- };
1290
- return (owner) => {
1291
- return {
1292
- ___id: id,
1293
- ___clone: clone,
1294
- ___owner: owner,
1295
- ___setup: setup,
1296
- ___params: params,
1297
- ___accessor: dynamicScopesAccessor
1298
- };
1299
- };
1324
+ function hasFormElementChanged(el) {
1325
+ return el.options ? hasSelectChanged(el) : hasValueChanged(el) || hasCheckboxChanged(el);
1300
1326
  }
1301
- function _content_resume(id, template, walks, setup, params, dynamicScopesAccessor) {
1302
- return _resume(
1303
- id,
1304
- _content(id, template, walks, setup, params, dynamicScopesAccessor)
1305
- );
1327
+ function normalizeStrProp(value) {
1328
+ return normalizeAttrValue(value) || "";
1306
1329
  }
1307
- function _content_closures(renderer, closureFns) {
1308
- const closureSignals = {};
1309
- for (const key in closureFns) {
1310
- closureSignals[key] = _const(true ? key : +key, closureFns[key]);
1311
- }
1312
- return (owner, closureValues) => {
1313
- const instance = renderer(owner);
1314
- instance.___localClosures = closureSignals;
1315
- instance.___localClosureValues = closureValues;
1316
- return instance;
1317
- };
1330
+ function normalizeBoolProp(value) {
1331
+ return value != null && value !== false;
1318
1332
  }
1319
- var cloneCache = {};
1320
- function createCloneableHTML(html, ns) {
1321
- const { firstChild, lastChild } = parseHTML(html, ns);
1322
- const parent = document.createElementNS(ns, "t");
1323
- insertChildNodes(parent, null, firstChild, lastChild);
1324
- return firstChild === lastChild && firstChild.nodeType < 8 /* Comment */ ? (branch, walks) => {
1325
- walk(
1326
- branch["#StartNode" /* StartNode */] = branch["#EndNode" /* EndNode */] = firstChild.cloneNode(true),
1327
- walks,
1328
- branch
1329
- );
1330
- } : (branch, walks) => {
1331
- const clone = parent.cloneNode(true);
1332
- walk(clone.firstChild, walks, branch);
1333
- branch["#StartNode" /* StartNode */] = clone.firstChild;
1334
- branch["#EndNode" /* EndNode */] = clone.lastChild;
1335
- };
1333
+ function updateList(arr, val, push2) {
1334
+ const index = arr.indexOf(val);
1335
+ return (push2 ? !~index && [...arr, val] : ~index && arr.slice(0, index).concat(arr.slice(index + 1))) || arr;
1336
+ }
1337
+ function toValueProp(it) {
1338
+ return it.value;
1336
1339
  }
1337
1340
 
1338
1341
  // src/dom/dom.ts
@@ -1798,63 +1801,74 @@ function _await_promise(nodeAccessor, params) {
1798
1801
  if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
1799
1802
  const promiseAccessor = "Promise:" /* Promise */ + nodeAccessor;
1800
1803
  const branchAccessor = "BranchScopes:" /* BranchScopes */ + nodeAccessor;
1801
- const rendererAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + nodeAccessor;
1802
1804
  _enable_catch();
1803
1805
  return (scope, promise) => {
1804
- let awaitCounter;
1805
- let renderData;
1806
- const tryWithPlaceholder = findBranchWithKey(
1807
- scope,
1808
- "#PlaceholderContent" /* PlaceholderContent */
1809
- );
1810
- if (tryWithPlaceholder) {
1811
- renderData = self[tryWithPlaceholder["$global" /* Global */].runtimeId]?.[tryWithPlaceholder["$global" /* Global */].renderId];
1812
- awaitCounter = tryWithPlaceholder["#AwaitCounter" /* AwaitCounter */] ||= renderData?.p?.[tryWithPlaceholder["#Id" /* Id */]];
1813
- if (!awaitCounter?.i) {
1814
- awaitCounter = tryWithPlaceholder["#AwaitCounter" /* AwaitCounter */] = {
1815
- d: 1,
1816
- i: 0,
1817
- c() {
1818
- if (!--awaitCounter.i) {
1819
- const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */];
1820
- tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = 0;
1821
- if (placeholderBranch) {
1822
- placeholderBranch["#StartNode" /* StartNode */].parentNode.insertBefore(
1823
- tryWithPlaceholder["#StartNode" /* StartNode */].parentNode,
1824
- placeholderBranch["#StartNode" /* StartNode */]
1825
- );
1826
- removeAndDestroyBranch(placeholderBranch);
1827
- }
1828
- queueEffect(tryWithPlaceholder, (scope2) => {
1829
- const pendingEffects2 = scope2["#PendingEffects" /* PendingEffects */];
1830
- if (pendingEffects2) {
1831
- scope2["#PendingEffects" /* PendingEffects */] = [];
1832
- runEffects(pendingEffects2, true);
1833
- }
1834
- });
1806
+ let awaitBranch = scope[branchAccessor];
1807
+ const tryBranch = findBranchWithKey(scope, "#PlaceholderContent" /* PlaceholderContent */) || awaitBranch;
1808
+ let awaitCounter = tryBranch["#AwaitCounter" /* AwaitCounter */];
1809
+ if (!awaitCounter?.i) {
1810
+ awaitCounter = tryBranch["#AwaitCounter" /* AwaitCounter */] = {
1811
+ i: 0,
1812
+ c() {
1813
+ if (--awaitCounter.i) return 1;
1814
+ if (tryBranch === scope[branchAccessor]) {
1815
+ if (scope[nodeAccessor].parentNode) {
1816
+ scope[nodeAccessor].replaceWith(
1817
+ scope[branchAccessor]["#StartNode" /* StartNode */].parentNode
1818
+ );
1819
+ }
1820
+ } else {
1821
+ const placeholderBranch = tryBranch["#PlaceholderBranch" /* PlaceholderBranch */];
1822
+ if (placeholderBranch) {
1823
+ tryBranch["#PlaceholderBranch" /* PlaceholderBranch */] = 0;
1824
+ placeholderBranch["#StartNode" /* StartNode */].parentNode.insertBefore(
1825
+ tryBranch["#StartNode" /* StartNode */].parentNode,
1826
+ placeholderBranch["#StartNode" /* StartNode */]
1827
+ );
1828
+ removeAndDestroyBranch(placeholderBranch);
1835
1829
  }
1836
1830
  }
1837
- };
1831
+ queueEffect(tryBranch, (scope2) => {
1832
+ const pendingEffects2 = scope2["#PendingEffects" /* PendingEffects */];
1833
+ if (pendingEffects2) {
1834
+ scope2["#PendingEffects" /* PendingEffects */] = [];
1835
+ runEffects(pendingEffects2, 1);
1836
+ }
1837
+ });
1838
+ }
1839
+ };
1840
+ }
1841
+ placeholderShown.add(pendingEffects);
1842
+ if (!scope[promiseAccessor]) {
1843
+ if (awaitBranch) {
1844
+ awaitBranch["#PendingRenders" /* PendingRenders */] ||= [];
1838
1845
  }
1839
- placeholderShown.add(pendingEffects);
1840
- if (!scope[promiseAccessor] && !awaitCounter.i++) {
1846
+ if (!awaitCounter.i++) {
1841
1847
  requestAnimationFrame(
1842
1848
  () => awaitCounter.i && runEffects(
1843
1849
  prepareEffects(
1844
1850
  () => queueRender(
1845
- tryWithPlaceholder,
1851
+ tryBranch === awaitBranch ? scope : tryBranch,
1846
1852
  () => {
1847
- insertBranchBefore(
1848
- tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1849
- scope["$global" /* Global */],
1850
- tryWithPlaceholder["#PlaceholderContent" /* PlaceholderContent */],
1851
- tryWithPlaceholder["_" /* Owner */],
1852
- tryWithPlaceholder["#StartNode" /* StartNode */].parentNode
1853
- ),
1854
- tryWithPlaceholder["#StartNode" /* StartNode */].parentNode,
1855
- tryWithPlaceholder["#StartNode" /* StartNode */]
1856
- );
1857
- tempDetachBranch(tryWithPlaceholder);
1853
+ if (tryBranch["#PlaceholderContent" /* PlaceholderContent */]) {
1854
+ insertBranchBefore(
1855
+ tryBranch["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1856
+ scope["$global" /* Global */],
1857
+ tryBranch["#PlaceholderContent" /* PlaceholderContent */],
1858
+ tryBranch["_" /* Owner */],
1859
+ tryBranch["#StartNode" /* StartNode */].parentNode
1860
+ ),
1861
+ tryBranch["#StartNode" /* StartNode */].parentNode,
1862
+ tryBranch["#StartNode" /* StartNode */]
1863
+ );
1864
+ tempDetachBranch(tryBranch);
1865
+ } else if (!awaitBranch["#DetachedAwait" /* DetachedAwait */]) {
1866
+ awaitBranch["#StartNode" /* StartNode */].parentNode.insertBefore(
1867
+ scope[nodeAccessor],
1868
+ awaitBranch["#StartNode" /* StartNode */]
1869
+ );
1870
+ tempDetachBranch(tryBranch);
1871
+ }
1858
1872
  },
1859
1873
  -1
1860
1874
  )
@@ -1862,61 +1876,52 @@ function _await_promise(nodeAccessor, params) {
1862
1876
  )
1863
1877
  );
1864
1878
  }
1865
- } else if (scope[branchAccessor] && !scope[promiseAccessor]) {
1866
- scope[branchAccessor]["#StartNode" /* StartNode */].parentNode.insertBefore(
1867
- scope[nodeAccessor],
1868
- scope[branchAccessor]["#StartNode" /* StartNode */]
1869
- );
1870
- tempDetachBranch(scope[branchAccessor]);
1871
1879
  }
1872
1880
  const thisPromise = scope[promiseAccessor] = promise.then(
1873
1881
  (data) => {
1874
1882
  if (thisPromise === scope[promiseAccessor]) {
1883
+ const referenceNode = scope[nodeAccessor];
1875
1884
  scope[promiseAccessor] = 0;
1876
- schedule();
1885
+ queueMicrotask(run);
1877
1886
  queueRender(
1878
1887
  scope,
1879
1888
  () => {
1880
- if (scope[branchAccessor]) {
1881
- if (!tryWithPlaceholder) {
1882
- scope[nodeAccessor].replaceWith(
1883
- scope[branchAccessor]["#StartNode" /* StartNode */].parentNode
1884
- );
1885
- }
1886
- } else {
1889
+ if ((awaitBranch = scope[branchAccessor])["#DetachedAwait" /* DetachedAwait */]) {
1890
+ pendingScopes.push(awaitBranch);
1891
+ setupBranch(
1892
+ awaitBranch["#DetachedAwait" /* DetachedAwait */],
1893
+ awaitBranch
1894
+ );
1895
+ awaitBranch["#DetachedAwait" /* DetachedAwait */] = 0;
1887
1896
  insertBranchBefore(
1888
- scope[branchAccessor] = createAndSetupBranch(
1889
- scope["$global" /* Global */],
1890
- scope[rendererAccessor],
1891
- scope,
1892
- scope[nodeAccessor].parentNode
1893
- ),
1897
+ awaitBranch,
1894
1898
  scope[nodeAccessor].parentNode,
1895
1899
  scope[nodeAccessor]
1896
1900
  );
1897
- scope[nodeAccessor].remove();
1901
+ referenceNode.remove();
1898
1902
  }
1899
- params?.(scope[branchAccessor], [data]);
1900
- if (awaitCounter) {
1901
- placeholderShown.add(pendingEffects);
1902
- awaitCounter.c();
1903
- if (!awaitCounter.d) {
1904
- const fnScopes = /* @__PURE__ */ new Map();
1905
- const effects = renderData.m();
1906
- for (let i = 0; i < pendingEffects.length; ) {
1907
- const fn = pendingEffects[i++];
1908
- let scopes = fnScopes.get(fn);
1909
- if (!scopes) {
1910
- fnScopes.set(fn, scopes = /* @__PURE__ */ new Set());
1911
- }
1912
- scopes.add(pendingEffects[i++]);
1903
+ params?.(awaitBranch, [data]);
1904
+ const pendingRenders2 = awaitBranch["#PendingRenders" /* PendingRenders */];
1905
+ awaitBranch["#PendingRenders" /* PendingRenders */] = 0;
1906
+ pendingRenders2?.forEach(queuePendingRender);
1907
+ placeholderShown.add(pendingEffects);
1908
+ awaitCounter.c();
1909
+ if (awaitCounter.m) {
1910
+ const fnScopes = /* @__PURE__ */ new Map();
1911
+ const effects = awaitCounter.m();
1912
+ for (let i = 0; i < pendingEffects.length; ) {
1913
+ const fn = pendingEffects[i++];
1914
+ let scopes = fnScopes.get(fn);
1915
+ if (!scopes) {
1916
+ fnScopes.set(fn, scopes = /* @__PURE__ */ new Set());
1913
1917
  }
1914
- for (let i = 0; i < effects.length; ) {
1915
- const fn = effects[i++];
1916
- const scope2 = effects[i++];
1917
- if (!fnScopes.get(fn)?.has(scope2)) {
1918
- queueEffect(scope2, fn);
1919
- }
1918
+ scopes.add(pendingEffects[i++]);
1919
+ }
1920
+ for (let i = 0; i < effects.length; ) {
1921
+ const fn = effects[i++];
1922
+ const scope2 = effects[i++];
1923
+ if (!fnScopes.get(fn)?.has(scope2)) {
1924
+ queueEffect(scope2, fn);
1920
1925
  }
1921
1926
  }
1922
1927
  }
@@ -1927,8 +1932,7 @@ function _await_promise(nodeAccessor, params) {
1927
1932
  },
1928
1933
  (error) => {
1929
1934
  if (thisPromise === scope[promiseAccessor]) {
1930
- if (awaitCounter) awaitCounter.i = 0;
1931
- scope[promiseAccessor] = 0;
1935
+ awaitCounter.i = scope[promiseAccessor] = 0;
1932
1936
  schedule();
1933
1937
  queueRender(scope, renderCatch, -1, error);
1934
1938
  }
@@ -1937,10 +1941,17 @@ function _await_promise(nodeAccessor, params) {
1937
1941
  };
1938
1942
  }
1939
1943
  function _await_content(nodeAccessor, template, walks, setup) {
1940
- const rendererAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + (true ? nodeAccessor : decodeAccessor4(nodeAccessor));
1944
+ if (false) nodeAccessor = decodeAccessor4(nodeAccessor);
1945
+ const branchAccessor = "BranchScopes:" /* BranchScopes */ + nodeAccessor;
1941
1946
  const renderer = _content("", template, walks, setup)();
1942
1947
  return (scope) => {
1943
- scope[rendererAccessor] = renderer;
1948
+ (scope[branchAccessor] = createBranch(
1949
+ scope["$global" /* Global */],
1950
+ renderer,
1951
+ scope,
1952
+ scope[nodeAccessor].parentNode
1953
+ ))["#DetachedAwait" /* DetachedAwait */] = renderer;
1954
+ pendingScopes.pop();
1944
1955
  };
1945
1956
  }
1946
1957
  function _try(nodeAccessor, template, walks, setup) {
@@ -2243,6 +2254,7 @@ function byFirstArg(name) {
2243
2254
  // src/dom/queue.ts
2244
2255
  var pendingRenders = [];
2245
2256
  var pendingRendersLookup = /* @__PURE__ */ new Map();
2257
+ var asyncRendersLookup;
2246
2258
  var caughtError = /* @__PURE__ */ new WeakSet();
2247
2259
  var placeholderShown = /* @__PURE__ */ new WeakSet();
2248
2260
  var pendingEffects = [];
@@ -2251,50 +2263,56 @@ var rendering;
2251
2263
  var scopeKeyOffset = 1e3;
2252
2264
  function queueRender(scope, signal, signalKey, value, scopeKey = scope["#Id" /* Id */]) {
2253
2265
  const key = scopeKey * scopeKeyOffset + signalKey;
2254
- const existingRender = signalKey >= 0 && pendingRendersLookup.get(key);
2255
- if (existingRender) {
2256
- existingRender.___value = value;
2266
+ let render = signalKey >= 0 && pendingRendersLookup.get(key);
2267
+ if (render) {
2268
+ render.___value = value;
2257
2269
  } else {
2258
- const render = {
2259
- ___key: key,
2260
- ___scope: scope,
2261
- ___signal: signal,
2262
- ___value: value
2263
- };
2264
- let i = pendingRenders.push(render) - 1;
2265
- while (i) {
2266
- const parentIndex = i - 1 >> 1;
2267
- const parent = pendingRenders[parentIndex];
2268
- if (key - parent.___key >= 0) break;
2269
- pendingRenders[i] = parent;
2270
- i = parentIndex;
2271
- }
2270
+ queuePendingRender(
2271
+ render = {
2272
+ ___key: key,
2273
+ ___scope: scope,
2274
+ ___signal: signal,
2275
+ ___value: value
2276
+ }
2277
+ );
2272
2278
  signalKey >= 0 && pendingRendersLookup.set(key, render);
2273
- pendingRenders[i] = render;
2274
2279
  }
2275
2280
  }
2281
+ function queuePendingRender(render) {
2282
+ let i = pendingRenders.push(render) - 1;
2283
+ while (i) {
2284
+ const parentIndex = i - 1 >> 1;
2285
+ const parent = pendingRenders[parentIndex];
2286
+ if (render.___key - parent.___key >= 0) break;
2287
+ pendingRenders[i] = parent;
2288
+ i = parentIndex;
2289
+ }
2290
+ pendingRenders[i] = render;
2291
+ }
2276
2292
  function queueEffect(scope, fn) {
2277
2293
  pendingEffects.push(fn, scope);
2278
2294
  }
2279
2295
  function run() {
2280
2296
  const effects = pendingEffects;
2297
+ asyncRendersLookup = /* @__PURE__ */ new Map();
2281
2298
  try {
2282
2299
  rendering = 1;
2283
2300
  runRenders();
2284
2301
  } finally {
2302
+ pendingRendersLookup = asyncRendersLookup;
2303
+ asyncRendersLookup = rendering = 0;
2285
2304
  pendingRenders = [];
2286
- pendingRendersLookup = /* @__PURE__ */ new Map();
2287
2305
  pendingEffects = [];
2288
- rendering = 0;
2289
2306
  }
2290
2307
  runEffects(effects);
2291
2308
  }
2292
2309
  function prepareEffects(fn) {
2293
2310
  const prevRenders = pendingRenders;
2294
- const prevRendersLookup = pendingRendersLookup;
2295
2311
  const prevEffects = pendingEffects;
2312
+ const prevLookup = asyncRendersLookup;
2296
2313
  const preparedEffects = pendingEffects = [];
2297
2314
  pendingRenders = [];
2315
+ asyncRendersLookup = pendingRendersLookup;
2298
2316
  pendingRendersLookup = /* @__PURE__ */ new Map();
2299
2317
  try {
2300
2318
  rendering = 1;
@@ -2302,8 +2320,9 @@ function prepareEffects(fn) {
2302
2320
  runRenders();
2303
2321
  } finally {
2304
2322
  rendering = 0;
2323
+ pendingRendersLookup = asyncRendersLookup;
2324
+ asyncRendersLookup = prevLookup;
2305
2325
  pendingRenders = prevRenders;
2306
- pendingRendersLookup = prevRendersLookup;
2307
2326
  pendingEffects = prevEffects;
2308
2327
  }
2309
2328
  return preparedEffects;
@@ -2378,6 +2397,17 @@ var _enable_catch = () => {
2378
2397
  })(runEffects);
2379
2398
  runRender = /* @__PURE__ */ ((runRender2) => (render) => {
2380
2399
  try {
2400
+ let branch = render.___scope["#ClosestBranch" /* ClosestBranch */];
2401
+ while (branch) {
2402
+ if (branch["#PendingRenders" /* PendingRenders */]) {
2403
+ asyncRendersLookup.set(
2404
+ render.___key,
2405
+ render
2406
+ );
2407
+ return branch["#PendingRenders" /* PendingRenders */].push(render);
2408
+ }
2409
+ branch = branch["#ParentBranch" /* ParentBranch */];
2410
+ }
2381
2411
  runRender2(render);
2382
2412
  } catch (error) {
2383
2413
  renderCatch(render.___scope, error);