marko 6.0.40 → 6.0.41

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.
@@ -648,895 +648,930 @@ function parseHTML(html2, ns) {
648
648
  return parser.content || parser;
649
649
  }
650
650
 
651
- // src/dom/dom.ts
652
- function attr(element, name, value2) {
653
- setAttribute(element, name, normalizeAttrValue(value2));
651
+ // src/dom/scope.ts
652
+ function createScope($global, closestBranch) {
653
+ const scope = {
654
+ ___id: $global.___nextScopeId++,
655
+ ___creating: 1,
656
+ ___closestBranch: closestBranch,
657
+ $global
658
+ };
659
+ pendingScopes.push(scope);
660
+ return scope;
654
661
  }
655
- function setAttribute(element, name, value2) {
656
- if (element.getAttribute(name) != value2) {
657
- if (value2 === void 0) {
658
- element.removeAttribute(name);
659
- } else {
660
- element.setAttribute(name, value2);
661
- }
662
+ function skipScope(scope) {
663
+ return scope.$global.___nextScopeId++;
664
+ }
665
+ function findBranchWithKey(scope, key) {
666
+ let branch = scope.___closestBranch;
667
+ while (branch && !branch[key]) {
668
+ branch = branch.___parentBranch;
662
669
  }
670
+ return branch;
663
671
  }
664
- function classAttr(element, value2) {
665
- setAttribute(element, "class", classValue(value2) || void 0);
672
+ function destroyBranch(branch) {
673
+ branch.___parentBranch?.___branchScopes?.delete(branch);
674
+ destroyNestedBranches(branch);
666
675
  }
667
- function classItems(element, items) {
668
- for (const key in items) {
669
- classItem(element, key, items[key]);
670
- }
676
+ function destroyNestedBranches(branch) {
677
+ branch.___destroyed = 1;
678
+ branch.___branchScopes?.forEach(destroyNestedBranches);
679
+ branch.___abortScopes?.forEach((scope) => {
680
+ for (const id in scope.___abortControllers) {
681
+ scope.___abortControllers[id]?.abort();
682
+ }
683
+ });
671
684
  }
672
- function classItem(element, name, value2) {
673
- element.classList.toggle(name, !!value2);
685
+ function removeAndDestroyBranch(branch) {
686
+ destroyBranch(branch);
687
+ removeChildNodes(branch.___startNode, branch.___endNode);
674
688
  }
675
- function styleAttr(element, value2) {
676
- setAttribute(element, "style", styleValue(value2) || void 0);
689
+ function insertBranchBefore(branch, parentNode, nextSibling) {
690
+ insertChildNodes(
691
+ parentNode,
692
+ nextSibling,
693
+ branch.___startNode,
694
+ branch.___endNode
695
+ );
677
696
  }
678
- function styleItems(element, items) {
679
- for (const key in items) {
680
- styleItem(element, key, items[key]);
697
+ function tempDetachBranch(branch) {
698
+ const fragment = new DocumentFragment();
699
+ fragment.namespaceURI = branch.___startNode.parentNode.namespaceURI;
700
+ insertChildNodes(fragment, null, branch.___startNode, branch.___endNode);
701
+ }
702
+
703
+ // src/dom/schedule.ts
704
+ var runTask;
705
+ var isScheduled;
706
+ var channel;
707
+ function schedule() {
708
+ if (!isScheduled) {
709
+ if (true) {
710
+ if (console.createTask) {
711
+ const task = console.createTask("queue");
712
+ runTask = () => task.run(run);
713
+ } else {
714
+ runTask = run;
715
+ }
716
+ }
717
+ isScheduled = 1;
718
+ queueMicrotask(flushAndWaitFrame);
681
719
  }
682
720
  }
683
- function styleItem(element, name, value2) {
684
- element.style.setProperty(name, value2 || value2 === 0 ? value2 + "" : "");
721
+ function flushAndWaitFrame() {
722
+ if (true) {
723
+ runTask();
724
+ } else {
725
+ run();
726
+ }
727
+ requestAnimationFrame(triggerMacroTask);
685
728
  }
686
- function data(node, value2) {
687
- const normalizedValue = normalizeString(value2);
688
- if (node.data !== normalizedValue) {
689
- node.data = normalizedValue;
729
+ function triggerMacroTask() {
730
+ if (!channel) {
731
+ channel = new MessageChannel();
732
+ channel.port1.onmessage = () => {
733
+ isScheduled = 0;
734
+ if (true) {
735
+ const run2 = runTask;
736
+ runTask = void 0;
737
+ run2();
738
+ } else {
739
+ run();
740
+ }
741
+ };
690
742
  }
743
+ channel.port2.postMessage(0);
691
744
  }
692
- function textContent(node, value2) {
693
- const normalizedValue = normalizeString(value2);
694
- if (node.textContent !== normalizedValue) {
695
- node.textContent = normalizedValue;
745
+
746
+ // src/dom/signals.ts
747
+ function state(valueAccessor, fn) {
748
+ if (true) {
749
+ var id = +valueAccessor.slice(
750
+ valueAccessor.lastIndexOf("/") + 1
751
+ );
752
+ valueAccessor = valueAccessor.slice(
753
+ 0,
754
+ valueAccessor.lastIndexOf("/")
755
+ );
696
756
  }
757
+ const valueChangeAccessor = "TagVariableChange:" /* TagVariableChange */ + valueAccessor;
758
+ const update = (scope, value2) => {
759
+ if (scope[valueAccessor] !== value2) {
760
+ scope[valueAccessor] = value2;
761
+ fn(scope, value2);
762
+ }
763
+ };
764
+ return (scope, value2, valueChange) => {
765
+ if (rendering) {
766
+ if ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value2 || !(valueAccessor in scope)) {
767
+ scope[valueAccessor] = value2;
768
+ fn(scope, value2);
769
+ }
770
+ } else if (scope[valueChangeAccessor]) {
771
+ scope[valueChangeAccessor](value2);
772
+ } else {
773
+ schedule();
774
+ queueRender(
775
+ scope,
776
+ update,
777
+ true ? id : valueAccessor,
778
+ value2
779
+ );
780
+ }
781
+ return value2;
782
+ };
697
783
  }
698
- function attrs(scope, nodeAccessor, nextAttrs) {
699
- const el = scope[nodeAccessor];
700
- for (let i = el.attributes.length; i--; ) {
701
- const { name } = el.attributes.item(i);
702
- if (!(nextAttrs && (name in nextAttrs || hasAttrAlias(el, name, nextAttrs)))) {
703
- el.removeAttribute(name);
784
+ function value(valueAccessor, fn = () => {
785
+ }) {
786
+ return (scope, value2) => {
787
+ if (!(valueAccessor in scope) || scope[valueAccessor] !== value2) {
788
+ scope[valueAccessor] = value2;
789
+ fn(scope, value2);
704
790
  }
705
- }
706
- attrsInternal(scope, nodeAccessor, nextAttrs);
791
+ };
707
792
  }
708
- function hasAttrAlias(element, attr2, nextAttrs) {
709
- return attr2 === "checked" && element.tagName === "INPUT" && "checkedValue" in nextAttrs;
793
+ function intersection(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__ */ "___id") {
794
+ return (scope) => {
795
+ if (scope.___creating) {
796
+ if (scope[id] === void 0) {
797
+ scope[id] = defaultPending;
798
+ } else if (!--scope[id]) {
799
+ fn(scope);
800
+ }
801
+ } else {
802
+ queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
803
+ }
804
+ };
710
805
  }
711
- function partialAttrs(scope, nodeAccessor, nextAttrs, skip) {
712
- const el = scope[nodeAccessor];
713
- const partial = {};
714
- for (let i = el.attributes.length; i--; ) {
715
- const { name } = el.attributes.item(i);
716
- if (!skip[name] && !(nextAttrs && name in nextAttrs)) {
717
- el.removeAttribute(name);
806
+ function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
807
+ const childSignal = closure(valueAccessor, fn);
808
+ const loopScopeAccessor = "LoopScopeArray:" /* LoopScopeArray */ + ownerLoopNodeAccessor;
809
+ const loopScopeMapAccessor = "LoopScopeMap:" /* LoopScopeMap */ + ownerLoopNodeAccessor;
810
+ const ownerSignal = (ownerScope) => {
811
+ const scopes = ownerScope[loopScopeAccessor] ||= ownerScope[loopScopeMapAccessor] ? [...ownerScope[loopScopeMapAccessor].values()] : [];
812
+ const [firstScope] = scopes;
813
+ if (firstScope) {
814
+ queueRender(
815
+ ownerScope,
816
+ () => {
817
+ for (const scope of scopes) {
818
+ if (!scope.___creating && !scope.___destroyed) {
819
+ childSignal(scope);
820
+ }
821
+ }
822
+ },
823
+ -1,
824
+ 0,
825
+ firstScope.___id
826
+ );
827
+ }
828
+ };
829
+ ownerSignal._ = childSignal;
830
+ return ownerSignal;
831
+ }
832
+ function conditionalClosure(valueAccessor, ownerConditionalNodeAccessor, branch, fn) {
833
+ const childSignal = closure(valueAccessor, fn);
834
+ const scopeAccessor = "ConditionalScope:" /* ConditionalScope */ + ownerConditionalNodeAccessor;
835
+ const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + ownerConditionalNodeAccessor;
836
+ const ownerSignal = (scope) => {
837
+ const ifScope = scope[scopeAccessor];
838
+ if (ifScope && !ifScope.___creating && scope[branchAccessor] === branch) {
839
+ queueRender(ifScope, childSignal, -1);
718
840
  }
841
+ };
842
+ ownerSignal._ = childSignal;
843
+ return ownerSignal;
844
+ }
845
+ function subscribeToScopeSet(ownerScope, accessor, scope) {
846
+ const subscribers = ownerScope[accessor] ||= /* @__PURE__ */ new Set();
847
+ if (!subscribers.has(scope)) {
848
+ subscribers.add(scope);
849
+ getAbortSignal(scope, -1).addEventListener(
850
+ "abort",
851
+ () => ownerScope[accessor].delete(scope)
852
+ );
719
853
  }
720
- for (const key in nextAttrs) {
721
- if (!skip[key]) partial[key] = nextAttrs[key];
854
+ }
855
+ function dynamicClosure(...closureSignals) {
856
+ const [{ ___scopeInstancesAccessor, ___signalIndexAccessor }] = closureSignals;
857
+ for (let i = closureSignals.length; i--; ) {
858
+ closureSignals[i].___index = i;
722
859
  }
723
- attrsInternal(scope, nodeAccessor, partial);
860
+ return (scope) => {
861
+ if (scope[___scopeInstancesAccessor]) {
862
+ for (const childScope of scope[___scopeInstancesAccessor]) {
863
+ if (!childScope.___creating) {
864
+ queueRender(
865
+ childScope,
866
+ closureSignals[childScope[___signalIndexAccessor]],
867
+ -1
868
+ );
869
+ }
870
+ }
871
+ }
872
+ };
724
873
  }
725
- function attrsInternal(scope, nodeAccessor, nextAttrs) {
726
- const el = scope[nodeAccessor];
727
- let events;
728
- let skip;
729
- switch (el.tagName) {
730
- case "INPUT":
731
- if ("checked" in nextAttrs || "checkedChange" in nextAttrs) {
732
- controllable_input_checked(
733
- scope,
734
- nodeAccessor,
735
- nextAttrs.checked,
736
- nextAttrs.checkedChange
737
- );
738
- } else if ("checkedValue" in nextAttrs || "checkedValueChange" in nextAttrs) {
739
- controllable_input_checkedValue(
740
- scope,
741
- nodeAccessor,
742
- nextAttrs.checkedValue,
743
- nextAttrs.checkedValueChange,
744
- nextAttrs.value
745
- );
746
- } else if ("value" in nextAttrs || "valueChange" in nextAttrs) {
747
- controllable_input_value(
748
- scope,
749
- nodeAccessor,
750
- nextAttrs.value,
751
- nextAttrs.valueChange
752
- );
753
- } else {
754
- break;
874
+ function dynamicClosureRead(valueAccessor, fn, getOwnerScope) {
875
+ const childSignal = closure(valueAccessor, fn, getOwnerScope);
876
+ const closureSignal = (scope) => {
877
+ scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
878
+ childSignal(scope);
879
+ subscribeToScopeSet(
880
+ getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */],
881
+ closureSignal.___scopeInstancesAccessor,
882
+ scope
883
+ );
884
+ };
885
+ closureSignal.___scopeInstancesAccessor = "ClosureScopes:" /* ClosureScopes */ + valueAccessor;
886
+ closureSignal.___signalIndexAccessor = "ClosureSignalIndex:" /* ClosureSignalIndex */ + valueAccessor;
887
+ return closureSignal;
888
+ }
889
+ function closure(valueAccessor, fn, getOwnerScope) {
890
+ return (scope) => {
891
+ fn(
892
+ scope,
893
+ (getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */])[valueAccessor]
894
+ );
895
+ };
896
+ }
897
+ function setTagVar(scope, childAccessor, tagVarSignal2) {
898
+ scope[childAccessor]["#TagVariable" /* TagVariable */] = (value2) => tagVarSignal2(scope, value2);
899
+ }
900
+ var tagVarSignal = (scope, value2) => scope["#TagVariable" /* TagVariable */]?.(value2);
901
+ function setTagVarChange(scope, changeHandler) {
902
+ scope["#TagVariableChange" /* TagVariableChange */] = changeHandler;
903
+ }
904
+ var tagVarSignalChange = (scope, value2) => scope["#TagVariableChange" /* TagVariableChange */]?.(value2);
905
+ var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
906
+ function nextTagId({ $global }) {
907
+ const id = tagIdsByGlobal.get($global) || 0;
908
+ tagIdsByGlobal.set($global, id + 1);
909
+ return "c" + $global.runtimeId + $global.renderId + id.toString(36);
910
+ }
911
+ function effect(id, fn) {
912
+ register(id, fn);
913
+ return (scope) => {
914
+ queueEffect(scope, fn);
915
+ };
916
+ }
917
+ function* traverseAllHoisted(scope, path, curIndex = path.length - 1) {
918
+ if (scope) {
919
+ if (Symbol.iterator in scope) {
920
+ for (const s of scope instanceof Map ? scope.values() : scope) {
921
+ yield* traverseAllHoisted(s, path, curIndex);
755
922
  }
756
- skip = /^(?:value|checked(?:Value)?)(?:Change)?$/;
757
- break;
758
- case "SELECT":
759
- if ("value" in nextAttrs || "valueChange" in nextAttrs) {
760
- controllable_select_value(
761
- scope,
762
- nodeAccessor,
763
- nextAttrs.value,
764
- nextAttrs.valueChange
765
- );
766
- skip = /^value(?:Change)?$/;
923
+ } else if (curIndex) {
924
+ yield* traverseAllHoisted(scope[path[curIndex]], path, curIndex - 1);
925
+ } else {
926
+ yield scope[path[0]];
927
+ }
928
+ }
929
+ }
930
+ function hoist(...path) {
931
+ return (scope) => {
932
+ const getOne = (...args) => iterator().next().value(...args);
933
+ const iterator = getOne[Symbol.iterator] = () => traverseAllHoisted(scope, path);
934
+ return getOne;
935
+ };
936
+ }
937
+
938
+ // src/dom/walker.ts
939
+ var walker = /* @__PURE__ */ document.createTreeWalker(document);
940
+ function walk(startNode, walkCodes, branch) {
941
+ walker.currentNode = startNode;
942
+ walkInternal(0, walkCodes, branch);
943
+ }
944
+ function walkInternal(currentWalkIndex, walkCodes, scope) {
945
+ let value2;
946
+ let storedMultiplier = 0;
947
+ let currentMultiplier = 0;
948
+ let currentScopeIndex = 0;
949
+ for (; currentWalkIndex < walkCodes.length; ) {
950
+ value2 = walkCodes.charCodeAt(currentWalkIndex++);
951
+ currentMultiplier = storedMultiplier;
952
+ storedMultiplier = 0;
953
+ if (value2 === 32 /* Get */) {
954
+ const node = walker.currentNode;
955
+ scope[true ? getDebugKey(currentScopeIndex, walker.currentNode) : currentScopeIndex] = node;
956
+ scope["Getter:" /* Getter */ + (true ? getDebugKey(currentScopeIndex++, walker.currentNode) : currentScopeIndex++)] = () => node;
957
+ } else if (value2 === 37 /* Replace */ || value2 === 49 /* DynamicTagWithVar */) {
958
+ walker.currentNode.replaceWith(
959
+ walker.currentNode = scope[true ? getDebugKey(currentScopeIndex++, "#text") : currentScopeIndex++] = new Text()
960
+ );
961
+ if (value2 === 49 /* DynamicTagWithVar */) {
962
+ scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : currentScopeIndex++] = skipScope(scope);
767
963
  }
768
- break;
769
- case "TEXTAREA":
770
- if ("value" in nextAttrs || "valueChange" in nextAttrs) {
771
- controllable_input_value(
772
- scope,
773
- nodeAccessor,
774
- nextAttrs.value,
775
- nextAttrs.valueChange
776
- );
777
- skip = /^value(?:Change)?$/;
964
+ } else if (value2 === 38 /* EndChild */) {
965
+ return currentWalkIndex;
966
+ } else if (value2 === 47 /* BeginChild */ || value2 === 48 /* BeginChildWithVar */) {
967
+ currentWalkIndex = walkInternal(
968
+ currentWalkIndex,
969
+ walkCodes,
970
+ scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global, scope.___closestBranch)
971
+ );
972
+ if (value2 === 48 /* BeginChildWithVar */) {
973
+ scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : currentScopeIndex++] = skipScope(scope);
778
974
  }
779
- break;
780
- case "DETAILS":
781
- case "DIALOG":
782
- if ("open" in nextAttrs || "openChange" in nextAttrs) {
783
- controllable_detailsOrDialog_open(
784
- scope,
785
- nodeAccessor,
786
- nextAttrs.open,
787
- nextAttrs.openChange
788
- );
789
- skip = /^open(?:Change)?$/;
975
+ } else if (value2 < 91 /* NextEnd */ + 1) {
976
+ value2 = 20 /* Next */ * currentMultiplier + value2 - 67 /* Next */;
977
+ while (value2--) {
978
+ walker.nextNode();
790
979
  }
791
- break;
792
- }
793
- for (const name in nextAttrs) {
794
- const value2 = nextAttrs[name];
795
- switch (name) {
796
- case "class":
797
- classAttr(el, value2);
798
- break;
799
- case "style":
800
- styleAttr(el, value2);
801
- break;
802
- case "content":
803
- break;
804
- default: {
805
- if (isEventHandler(name)) {
806
- (events ||= scope["EventAttributes:" /* EventAttributes */ + nodeAccessor] = {})[getEventHandlerName(name)] = value2;
807
- } else if (!skip?.test(name)) {
808
- attr(el, name, value2);
809
- }
980
+ } else if (value2 < 106 /* OverEnd */ + 1) {
981
+ value2 = 10 /* Over */ * currentMultiplier + value2 - 97 /* Over */;
982
+ while (value2--) {
983
+ walker.nextSibling();
984
+ }
985
+ } else if (value2 < 116 /* OutEnd */ + 1) {
986
+ value2 = 10 /* Out */ * currentMultiplier + value2 - 107 /* Out */;
987
+ while (value2--) {
988
+ walker.parentNode();
989
+ }
990
+ walker.nextSibling();
991
+ } else {
992
+ if (value2 < 117 /* Multiplier */ || value2 > 126 /* MultiplierEnd */) {
993
+ throw new Error(`Unknown walk code: ${value2}`);
810
994
  }
995
+ storedMultiplier = currentMultiplier * 10 /* Multiplier */ + value2 - 117 /* Multiplier */;
811
996
  }
812
997
  }
813
998
  }
814
- function attrsEvents(scope, nodeAccessor) {
815
- const el = scope[nodeAccessor];
816
- const events = scope["EventAttributes:" /* EventAttributes */ + nodeAccessor];
817
- switch (scope["ControlledType:" /* ControlledType */ + nodeAccessor]) {
818
- case 0 /* InputChecked */:
819
- controllable_input_checked_effect(scope, nodeAccessor);
820
- break;
821
- case 1 /* InputCheckedValue */:
822
- controllable_input_checkedValue_effect(scope, nodeAccessor);
823
- break;
824
- case 2 /* InputValue */:
825
- controllable_input_value_effect(scope, nodeAccessor);
826
- break;
827
- case 3 /* SelectValue */:
828
- controllable_select_value_effect(scope, nodeAccessor);
829
- break;
830
- case 4 /* DetailsOrDialogOpen */:
831
- controllable_detailsOrDialog_open_effect(scope, nodeAccessor);
832
- break;
833
- }
834
- for (const name in events) {
835
- on(el, name, events[name]);
999
+ function getDebugKey(index, node) {
1000
+ if (typeof node === "string") {
1001
+ return `${node}/${index}`;
1002
+ } else if (node.nodeType === 3 /* Text */) {
1003
+ return `#text/${index}`;
1004
+ } else if (node.nodeType === 8 /* Comment */) {
1005
+ return `#comment/${index}`;
1006
+ } else if (node.nodeType === 1 /* Element */) {
1007
+ return `#${node.tagName.toLowerCase()}/${index}`;
836
1008
  }
1009
+ return index;
837
1010
  }
838
- function html(scope, value2, accessor) {
839
- const firstChild = scope[accessor];
840
- const parentNode = firstChild.parentNode;
841
- const lastChild = scope["DynamicPlaceholderLastChild:" /* DynamicPlaceholderLastChild */ + accessor] || firstChild;
842
- const newContent = parseHTML(
843
- value2 || value2 === 0 ? value2 + "" : "",
1011
+
1012
+ // src/dom/renderer.ts
1013
+ function createBranch($global, renderer, parentScope, parentNode) {
1014
+ const branch = createScope($global);
1015
+ const parentBranch = parentScope?.___closestBranch;
1016
+ branch["_" /* Owner */] = renderer.___owner || parentScope;
1017
+ branch.___closestBranch = branch;
1018
+ if (parentBranch) {
1019
+ branch.___parentBranch = parentBranch;
1020
+ (parentBranch.___branchScopes ||= /* @__PURE__ */ new Set()).add(branch);
1021
+ }
1022
+ if (true) {
1023
+ branch.___renderer = renderer;
1024
+ }
1025
+ renderer.___clone?.(
1026
+ branch,
844
1027
  parentNode.namespaceURI
845
1028
  );
846
- insertChildNodes(
847
- parentNode,
848
- firstChild,
849
- scope[accessor] = newContent.firstChild || newContent.appendChild(new Text()),
850
- scope["DynamicPlaceholderLastChild:" /* DynamicPlaceholderLastChild */ + accessor] = newContent.lastChild
851
- );
852
- removeChildNodes(firstChild, lastChild);
1029
+ return branch;
853
1030
  }
854
- function props(scope, nodeIndex, index) {
855
- const nextProps = scope[index];
856
- const prevProps = scope[index + "-"];
857
- const node = scope[nodeIndex];
858
- if (prevProps) {
859
- for (const name in prevProps) {
860
- if (!(name in nextProps)) {
861
- node[name] = void 0;
862
- }
863
- }
864
- }
865
- for (const name in nextProps) {
866
- node[name] = nextProps[name];
867
- }
868
- scope[index + "-"] = nextProps;
1031
+ function createAndSetupBranch($global, renderer, parentScope, parentNode) {
1032
+ return setupBranch(
1033
+ renderer,
1034
+ createBranch($global, renderer, parentScope, parentNode)
1035
+ );
869
1036
  }
870
- function normalizeAttrValue(value2) {
871
- if (value2 || value2 === 0) {
872
- return value2 === true ? "" : value2 + "";
1037
+ function setupBranch(renderer, branch) {
1038
+ if (renderer.___setup) {
1039
+ queueRender(branch, renderer.___setup, -1);
873
1040
  }
1041
+ return branch;
874
1042
  }
875
- function normalizeString(value2) {
876
- return value2 || value2 === 0 ? value2 + "" : "\u200D";
1043
+ function createContent(id, template, walks, setup, params, dynamicScopesAccessor) {
1044
+ walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
1045
+ setup = setup ? setup._ || setup : void 0;
1046
+ params ||= void 0;
1047
+ const clone = template ? (branch, ns) => {
1048
+ ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
1049
+ template,
1050
+ ns
1051
+ ))(branch, walks);
1052
+ } : (branch) => {
1053
+ walk(
1054
+ branch.___startNode = branch.___endNode = new Text(),
1055
+ walks,
1056
+ branch
1057
+ );
1058
+ };
1059
+ return (owner) => {
1060
+ return {
1061
+ ___id: id,
1062
+ ___clone: clone,
1063
+ ___owner: owner,
1064
+ ___setup: setup,
1065
+ ___params: params,
1066
+ ___accessor: dynamicScopesAccessor
1067
+ };
1068
+ };
877
1069
  }
878
- function lifecycle(scope, index, thisObj) {
879
- const instance = scope[index];
880
- if (instance) {
881
- Object.assign(instance, thisObj);
882
- instance.onUpdate?.();
883
- } else {
884
- scope[index] = thisObj;
885
- thisObj.onMount?.();
886
- getAbortSignal(
887
- scope,
888
- "LifecycleAbortController:" /* LifecycleAbortController */ + index
889
- ).onabort = () => thisObj.onDestroy?.();
890
- }
1070
+ function registerContent(id, template, walks, setup, params, dynamicScopesAccessor) {
1071
+ return register(
1072
+ id,
1073
+ createContent(id, template, walks, setup, params, dynamicScopesAccessor)
1074
+ );
891
1075
  }
892
- function removeChildNodes(startNode, endNode) {
893
- const stop = endNode.nextSibling;
894
- let current = startNode;
895
- while (current !== stop) {
896
- const next = current.nextSibling;
897
- current.remove();
898
- current = next;
1076
+ function localClosures(renderer, closureFns) {
1077
+ const closureSignals = {};
1078
+ for (const key in closureFns) {
1079
+ closureSignals[key] = value(key, closureFns[key]);
899
1080
  }
1081
+ return (owner, closureValues) => {
1082
+ const instance = renderer(owner);
1083
+ instance.___localClosures = closureSignals;
1084
+ instance.___localClosureValues = closureValues;
1085
+ return instance;
1086
+ };
900
1087
  }
901
- function insertChildNodes(parentNode, referenceNode, startNode, endNode) {
902
- parentNode.insertBefore(toInsertNode(startNode, endNode), referenceNode);
1088
+ function createRenderer(template, walks, setup, params) {
1089
+ return createContent("", template, walks, setup, params)();
903
1090
  }
904
- function toInsertNode(startNode, endNode) {
905
- if (startNode === endNode) return startNode;
906
- const parent = new DocumentFragment();
907
- const stop = endNode.nextSibling;
908
- let current = startNode;
909
- while (current !== stop) {
910
- const next = current.nextSibling;
911
- parent.appendChild(current);
912
- current = next;
913
- }
914
- return parent;
1091
+ var cloneCache = {};
1092
+ function createCloneableHTML(html2, ns) {
1093
+ const { firstChild, lastChild } = parseHTML(html2, ns);
1094
+ const parent = document.createElementNS(ns, "t");
1095
+ insertChildNodes(parent, null, firstChild, lastChild);
1096
+ return firstChild === lastChild && firstChild.nodeType < 8 /* Comment */ ? (branch, walks) => {
1097
+ walk(
1098
+ branch.___startNode = branch.___endNode = firstChild.cloneNode(true),
1099
+ walks,
1100
+ branch
1101
+ );
1102
+ } : (branch, walks) => {
1103
+ const clone = parent.cloneNode(true);
1104
+ walk(clone.firstChild, walks, branch);
1105
+ branch.___startNode = clone.firstChild;
1106
+ branch.___endNode = clone.lastChild;
1107
+ };
915
1108
  }
916
1109
 
917
- // src/dom/scope.ts
918
- function createScope($global, closestBranch) {
919
- const scope = {
920
- ___id: $global.___nextScopeId++,
921
- ___creating: 1,
922
- ___closestBranch: closestBranch,
923
- $global
924
- };
925
- pendingScopes.push(scope);
926
- return scope;
1110
+ // src/dom/dom.ts
1111
+ function attr(element, name, value2) {
1112
+ setAttribute(element, name, normalizeAttrValue(value2));
927
1113
  }
928
- function skipScope(scope) {
929
- return scope.$global.___nextScopeId++;
1114
+ function setAttribute(element, name, value2) {
1115
+ if (element.getAttribute(name) != value2) {
1116
+ if (value2 === void 0) {
1117
+ element.removeAttribute(name);
1118
+ } else {
1119
+ element.setAttribute(name, value2);
1120
+ }
1121
+ }
930
1122
  }
931
- function findBranchWithKey(scope, key) {
932
- let branch = scope.___closestBranch;
933
- while (branch && !branch[key]) {
934
- branch = branch.___parentBranch;
1123
+ function classAttr(element, value2) {
1124
+ setAttribute(element, "class", classValue(value2) || void 0);
1125
+ }
1126
+ function classItems(element, items) {
1127
+ for (const key in items) {
1128
+ classItem(element, key, items[key]);
935
1129
  }
936
- return branch;
937
1130
  }
938
- function destroyBranch(branch) {
939
- branch.___parentBranch?.___branchScopes?.delete(branch);
940
- destroyNestedBranches(branch);
1131
+ function classItem(element, name, value2) {
1132
+ element.classList.toggle(name, !!value2);
941
1133
  }
942
- function destroyNestedBranches(branch) {
943
- branch.___destroyed = 1;
944
- branch.___branchScopes?.forEach(destroyNestedBranches);
945
- branch.___abortScopes?.forEach((scope) => {
946
- for (const id in scope.___abortControllers) {
947
- scope.___abortControllers[id]?.abort();
948
- }
949
- });
1134
+ function styleAttr(element, value2) {
1135
+ setAttribute(element, "style", styleValue(value2) || void 0);
950
1136
  }
951
- function removeAndDestroyBranch(branch) {
952
- destroyBranch(branch);
953
- removeChildNodes(branch.___startNode, branch.___endNode);
1137
+ function styleItems(element, items) {
1138
+ for (const key in items) {
1139
+ styleItem(element, key, items[key]);
1140
+ }
954
1141
  }
955
- function insertBranchBefore(branch, parentNode, nextSibling) {
956
- insertChildNodes(
957
- parentNode,
958
- nextSibling,
959
- branch.___startNode,
960
- branch.___endNode
961
- );
1142
+ function styleItem(element, name, value2) {
1143
+ element.style.setProperty(name, value2 || value2 === 0 ? value2 + "" : "");
962
1144
  }
963
- function tempDetachBranch(branch) {
964
- const fragment = new DocumentFragment();
965
- fragment.namespaceURI = branch.___startNode.parentNode.namespaceURI;
966
- insertChildNodes(fragment, null, branch.___startNode, branch.___endNode);
1145
+ function data(node, value2) {
1146
+ const normalizedValue = normalizeString(value2);
1147
+ if (node.data !== normalizedValue) {
1148
+ node.data = normalizedValue;
1149
+ }
967
1150
  }
968
-
969
- // src/dom/reconcile.ts
970
- var WRONG_POS = 2147483647;
971
- function reconcile(parent, oldBranches, newBranches, afterReference) {
972
- let oldStart = 0;
973
- let newStart = 0;
974
- let oldEnd = oldBranches.length - 1;
975
- let newEnd = newBranches.length - 1;
976
- let oldStartBranch = oldBranches[oldStart];
977
- let newStartBranch = newBranches[newStart];
978
- let oldEndBranch = oldBranches[oldEnd];
979
- let newEndBranch = newBranches[newEnd];
980
- let i;
981
- let j;
982
- let k;
983
- let nextSibling;
984
- let oldBranch;
985
- let newBranch;
986
- outer: {
987
- while (oldStartBranch === newStartBranch) {
988
- ++oldStart;
989
- ++newStart;
990
- if (oldStart > oldEnd || newStart > newEnd) {
991
- break outer;
992
- }
993
- oldStartBranch = oldBranches[oldStart];
994
- newStartBranch = newBranches[newStart];
995
- }
996
- while (oldEndBranch === newEndBranch) {
997
- --oldEnd;
998
- --newEnd;
999
- if (oldStart > oldEnd || newStart > newEnd) {
1000
- break outer;
1001
- }
1002
- oldEndBranch = oldBranches[oldEnd];
1003
- newEndBranch = newBranches[newEnd];
1004
- }
1151
+ function textContent(node, value2) {
1152
+ const normalizedValue = normalizeString(value2);
1153
+ if (node.textContent !== normalizedValue) {
1154
+ node.textContent = normalizedValue;
1005
1155
  }
1006
- if (oldStart > oldEnd) {
1007
- if (newStart <= newEnd) {
1008
- k = newEnd + 1;
1009
- nextSibling = k < newBranches.length ? newBranches[k].___startNode : afterReference;
1010
- do {
1011
- insertBranchBefore(newBranches[newStart++], parent, nextSibling);
1012
- } while (newStart <= newEnd);
1156
+ }
1157
+ function attrs(scope, nodeAccessor, nextAttrs) {
1158
+ const el = scope[nodeAccessor];
1159
+ for (let i = el.attributes.length; i--; ) {
1160
+ const { name } = el.attributes.item(i);
1161
+ if (!(nextAttrs && (name in nextAttrs || hasAttrAlias(el, name, nextAttrs)))) {
1162
+ el.removeAttribute(name);
1013
1163
  }
1014
- } else if (newStart > newEnd) {
1015
- do {
1016
- removeAndDestroyBranch(oldBranches[oldStart++]);
1017
- } while (oldStart <= oldEnd);
1018
- } else {
1019
- const oldLength = oldEnd - oldStart + 1;
1020
- const newLength = newEnd - newStart + 1;
1021
- const aNullable = oldBranches;
1022
- const sources = new Array(newLength);
1023
- for (i = 0; i < newLength; ++i) {
1024
- sources[i] = -1;
1025
- }
1026
- let pos = 0;
1027
- let synced = 0;
1028
- const keyIndex = /* @__PURE__ */ new Map();
1029
- for (j = newStart; j <= newEnd; ++j) {
1030
- keyIndex.set(newBranches[j], j);
1031
- }
1032
- for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
1033
- oldBranch = oldBranches[i];
1034
- j = keyIndex.get(oldBranch);
1035
- if (j !== void 0) {
1036
- pos = pos > j ? WRONG_POS : j;
1037
- ++synced;
1038
- newBranch = newBranches[j];
1039
- sources[j - newStart] = i;
1040
- aNullable[i] = null;
1041
- }
1164
+ }
1165
+ attrsInternal(scope, nodeAccessor, nextAttrs);
1166
+ }
1167
+ function attrsAndContent(scope, nodeAccessor, nextAttrs) {
1168
+ attrs(scope, nodeAccessor, nextAttrs);
1169
+ insertContent(scope, nodeAccessor, nextAttrs?.content);
1170
+ }
1171
+ function hasAttrAlias(element, attr2, nextAttrs) {
1172
+ return attr2 === "checked" && element.tagName === "INPUT" && "checkedValue" in nextAttrs;
1173
+ }
1174
+ function partialAttrs(scope, nodeAccessor, nextAttrs, skip) {
1175
+ const el = scope[nodeAccessor];
1176
+ const partial = {};
1177
+ for (let i = el.attributes.length; i--; ) {
1178
+ const { name } = el.attributes.item(i);
1179
+ if (!skip[name] && !(nextAttrs && name in nextAttrs)) {
1180
+ el.removeAttribute(name);
1042
1181
  }
1043
- if (oldLength === oldBranches.length && synced === 0) {
1044
- for (; newStart < newLength; ++newStart) {
1045
- insertBranchBefore(newBranches[newStart], parent, afterReference);
1182
+ }
1183
+ for (const key in nextAttrs) {
1184
+ if (!skip[key]) partial[key] = nextAttrs[key];
1185
+ }
1186
+ attrsInternal(scope, nodeAccessor, partial);
1187
+ }
1188
+ function partialAttrsAndContent(scope, nodeAccessor, nextAttrs, skip) {
1189
+ partialAttrs(scope, nodeAccessor, nextAttrs, skip);
1190
+ insertContent(scope, nodeAccessor, nextAttrs?.content);
1191
+ }
1192
+ function attrsInternal(scope, nodeAccessor, nextAttrs) {
1193
+ const el = scope[nodeAccessor];
1194
+ let events;
1195
+ let skip;
1196
+ switch (el.tagName) {
1197
+ case "INPUT":
1198
+ if ("checked" in nextAttrs || "checkedChange" in nextAttrs) {
1199
+ controllable_input_checked(
1200
+ scope,
1201
+ nodeAccessor,
1202
+ nextAttrs.checked,
1203
+ nextAttrs.checkedChange
1204
+ );
1205
+ } else if ("checkedValue" in nextAttrs || "checkedValueChange" in nextAttrs) {
1206
+ controllable_input_checkedValue(
1207
+ scope,
1208
+ nodeAccessor,
1209
+ nextAttrs.checkedValue,
1210
+ nextAttrs.checkedValueChange,
1211
+ nextAttrs.value
1212
+ );
1213
+ } else if ("value" in nextAttrs || "valueChange" in nextAttrs) {
1214
+ controllable_input_value(
1215
+ scope,
1216
+ nodeAccessor,
1217
+ nextAttrs.value,
1218
+ nextAttrs.valueChange
1219
+ );
1220
+ } else {
1221
+ break;
1046
1222
  }
1047
- for (; oldStart < oldLength; ++oldStart) {
1048
- removeAndDestroyBranch(oldBranches[oldStart]);
1223
+ skip = /^(?:value|checked(?:Value)?)(?:Change)?$/;
1224
+ break;
1225
+ case "SELECT":
1226
+ if ("value" in nextAttrs || "valueChange" in nextAttrs) {
1227
+ controllable_select_value(
1228
+ scope,
1229
+ nodeAccessor,
1230
+ nextAttrs.value,
1231
+ nextAttrs.valueChange
1232
+ );
1233
+ skip = /^value(?:Change)?$/;
1049
1234
  }
1050
- } else {
1051
- i = oldLength - synced;
1052
- while (i > 0) {
1053
- oldBranch = aNullable[oldStart++];
1054
- if (oldBranch !== null) {
1055
- removeAndDestroyBranch(oldBranch);
1056
- i--;
1057
- }
1235
+ break;
1236
+ case "TEXTAREA":
1237
+ if ("value" in nextAttrs || "valueChange" in nextAttrs) {
1238
+ controllable_input_value(
1239
+ scope,
1240
+ nodeAccessor,
1241
+ nextAttrs.value,
1242
+ nextAttrs.valueChange
1243
+ );
1244
+ skip = /^value(?:Change)?$/;
1058
1245
  }
1059
- if (pos === WRONG_POS) {
1060
- const seq = longestIncreasingSubsequence(sources);
1061
- j = seq.length - 1;
1062
- k = newBranches.length;
1063
- for (i = newLength - 1; i >= 0; --i) {
1064
- if (sources[i] === -1) {
1065
- pos = i + newStart;
1066
- newBranch = newBranches[pos++];
1067
- nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
1068
- insertBranchBefore(newBranch, parent, nextSibling);
1069
- } else {
1070
- if (j < 0 || i !== seq[j]) {
1071
- pos = i + newStart;
1072
- newBranch = newBranches[pos++];
1073
- nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
1074
- insertBranchBefore(newBranch, parent, nextSibling);
1075
- } else {
1076
- --j;
1077
- }
1078
- }
1079
- }
1080
- } else if (synced !== newLength) {
1081
- k = newBranches.length;
1082
- for (i = newLength - 1; i >= 0; --i) {
1083
- if (sources[i] === -1) {
1084
- pos = i + newStart;
1085
- newBranch = newBranches[pos++];
1086
- nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
1087
- insertBranchBefore(newBranch, parent, nextSibling);
1088
- }
1089
- }
1246
+ break;
1247
+ case "DETAILS":
1248
+ case "DIALOG":
1249
+ if ("open" in nextAttrs || "openChange" in nextAttrs) {
1250
+ controllable_detailsOrDialog_open(
1251
+ scope,
1252
+ nodeAccessor,
1253
+ nextAttrs.open,
1254
+ nextAttrs.openChange
1255
+ );
1256
+ skip = /^open(?:Change)?$/;
1090
1257
  }
1091
- }
1258
+ break;
1092
1259
  }
1093
- }
1094
- function longestIncreasingSubsequence(a) {
1095
- const p = a.slice();
1096
- const result = [0];
1097
- let u;
1098
- let v;
1099
- for (let i = 0, il = a.length; i < il; ++i) {
1100
- if (a[i] === -1) {
1101
- continue;
1102
- }
1103
- const j = result[result.length - 1];
1104
- if (a[j] < a[i]) {
1105
- p[i] = j;
1106
- result.push(i);
1107
- continue;
1108
- }
1109
- u = 0;
1110
- v = result.length - 1;
1111
- while (u < v) {
1112
- const c = (u + v) / 2 | 0;
1113
- if (a[result[c]] < a[i]) {
1114
- u = c + 1;
1115
- } else {
1116
- v = c;
1260
+ for (const name in nextAttrs) {
1261
+ const value2 = nextAttrs[name];
1262
+ switch (name) {
1263
+ case "class":
1264
+ classAttr(el, value2);
1265
+ break;
1266
+ case "style":
1267
+ styleAttr(el, value2);
1268
+ break;
1269
+ case "content": {
1270
+ break;
1117
1271
  }
1118
- }
1119
- if (a[i] < a[result[u]]) {
1120
- if (u > 0) {
1121
- p[i] = result[u - 1];
1272
+ default: {
1273
+ if (isEventHandler(name)) {
1274
+ (events ||= scope["EventAttributes:" /* EventAttributes */ + nodeAccessor] = {})[getEventHandlerName(name)] = value2;
1275
+ } else if (!skip?.test(name)) {
1276
+ attr(el, name, value2);
1277
+ }
1122
1278
  }
1123
- result[u] = i;
1124
1279
  }
1125
1280
  }
1126
- u = result.length;
1127
- v = result[u - 1];
1128
- while (u-- > 0) {
1129
- result[u] = v;
1130
- v = p[v];
1131
- }
1132
- return result;
1133
1281
  }
1134
-
1135
- // src/dom/schedule.ts
1136
- var runTask;
1137
- var isScheduled;
1138
- var channel;
1139
- function schedule() {
1140
- if (!isScheduled) {
1141
- if (true) {
1142
- if (console.createTask) {
1143
- const task = console.createTask("queue");
1144
- runTask = () => task.run(run);
1145
- } else {
1146
- runTask = run;
1147
- }
1282
+ function insertContent(scope, nodeAccessor, value2) {
1283
+ const content = normalizeClientRender(value2);
1284
+ const rendererAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + nodeAccessor;
1285
+ if (scope[rendererAccessor] !== (scope[rendererAccessor] = content?.___id)) {
1286
+ setConditionalRenderer(scope, nodeAccessor, content, createAndSetupBranch);
1287
+ if (content?.___accessor) {
1288
+ subscribeToScopeSet(
1289
+ content.___owner,
1290
+ content.___accessor,
1291
+ scope["ConditionalScope:" /* ConditionalScope */ + nodeAccessor]
1292
+ );
1148
1293
  }
1149
- isScheduled = 1;
1150
- queueMicrotask(flushAndWaitFrame);
1151
1294
  }
1152
1295
  }
1153
- function flushAndWaitFrame() {
1154
- if (true) {
1155
- runTask();
1156
- } else {
1157
- run();
1296
+ function attrsEvents(scope, nodeAccessor) {
1297
+ const el = scope[nodeAccessor];
1298
+ const events = scope["EventAttributes:" /* EventAttributes */ + nodeAccessor];
1299
+ switch (scope["ControlledType:" /* ControlledType */ + nodeAccessor]) {
1300
+ case 0 /* InputChecked */:
1301
+ controllable_input_checked_effect(scope, nodeAccessor);
1302
+ break;
1303
+ case 1 /* InputCheckedValue */:
1304
+ controllable_input_checkedValue_effect(scope, nodeAccessor);
1305
+ break;
1306
+ case 2 /* InputValue */:
1307
+ controllable_input_value_effect(scope, nodeAccessor);
1308
+ break;
1309
+ case 3 /* SelectValue */:
1310
+ controllable_select_value_effect(scope, nodeAccessor);
1311
+ break;
1312
+ case 4 /* DetailsOrDialogOpen */:
1313
+ controllable_detailsOrDialog_open_effect(scope, nodeAccessor);
1314
+ break;
1315
+ }
1316
+ for (const name in events) {
1317
+ on(el, name, events[name]);
1158
1318
  }
1159
- requestAnimationFrame(triggerMacroTask);
1160
1319
  }
1161
- function triggerMacroTask() {
1162
- if (!channel) {
1163
- channel = new MessageChannel();
1164
- channel.port1.onmessage = () => {
1165
- isScheduled = 0;
1166
- if (true) {
1167
- const run2 = runTask;
1168
- runTask = void 0;
1169
- run2();
1170
- } else {
1171
- run();
1172
- }
1173
- };
1174
- }
1175
- channel.port2.postMessage(0);
1320
+ function html(scope, value2, accessor) {
1321
+ const firstChild = scope[accessor];
1322
+ const parentNode = firstChild.parentNode;
1323
+ const lastChild = scope["DynamicPlaceholderLastChild:" /* DynamicPlaceholderLastChild */ + accessor] || firstChild;
1324
+ const newContent = parseHTML(
1325
+ value2 || value2 === 0 ? value2 + "" : "",
1326
+ parentNode.namespaceURI
1327
+ );
1328
+ insertChildNodes(
1329
+ parentNode,
1330
+ firstChild,
1331
+ scope[accessor] = newContent.firstChild || newContent.appendChild(new Text()),
1332
+ scope["DynamicPlaceholderLastChild:" /* DynamicPlaceholderLastChild */ + accessor] = newContent.lastChild
1333
+ );
1334
+ removeChildNodes(firstChild, lastChild);
1176
1335
  }
1177
-
1178
- // src/dom/signals.ts
1179
- function state(valueAccessor, fn) {
1180
- if (true) {
1181
- var id = +valueAccessor.slice(
1182
- valueAccessor.lastIndexOf("/") + 1
1183
- );
1184
- valueAccessor = valueAccessor.slice(
1185
- 0,
1186
- valueAccessor.lastIndexOf("/")
1187
- );
1188
- }
1189
- const valueChangeAccessor = "TagVariableChange:" /* TagVariableChange */ + valueAccessor;
1190
- const update = (scope, value2) => {
1191
- if (scope[valueAccessor] !== value2) {
1192
- scope[valueAccessor] = value2;
1193
- fn(scope, value2);
1194
- }
1195
- };
1196
- return (scope, value2, valueChange) => {
1197
- if (rendering) {
1198
- if ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value2 || !(valueAccessor in scope)) {
1199
- scope[valueAccessor] = value2;
1200
- fn(scope, value2);
1201
- }
1202
- } else if (scope[valueChangeAccessor]) {
1203
- scope[valueChangeAccessor](value2);
1204
- } else {
1205
- schedule();
1206
- queueRender(
1207
- scope,
1208
- update,
1209
- true ? id : valueAccessor,
1210
- value2
1336
+ function normalizeClientRender(value2) {
1337
+ const renderer = normalizeDynamicRenderer(value2);
1338
+ if (renderer) {
1339
+ if (renderer.___id) {
1340
+ return renderer;
1341
+ } else if (true) {
1342
+ throw new Error(
1343
+ `Invalid \`content\` attribute. Received ${typeof value2}`
1211
1344
  );
1212
1345
  }
1213
- return value2;
1214
- };
1215
- }
1216
- function value(valueAccessor, fn = () => {
1217
- }) {
1218
- return (scope, value2) => {
1219
- if (!(valueAccessor in scope) || scope[valueAccessor] !== value2) {
1220
- scope[valueAccessor] = value2;
1221
- fn(scope, value2);
1222
- }
1223
- };
1346
+ }
1224
1347
  }
1225
- function intersection(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__ */ "___id") {
1226
- return (scope) => {
1227
- if (scope.___creating) {
1228
- if (scope[id] === void 0) {
1229
- scope[id] = defaultPending;
1230
- } else if (!--scope[id]) {
1231
- fn(scope);
1348
+ function props(scope, nodeIndex, index) {
1349
+ const nextProps = scope[index];
1350
+ const prevProps = scope[index + "-"];
1351
+ const node = scope[nodeIndex];
1352
+ if (prevProps) {
1353
+ for (const name in prevProps) {
1354
+ if (!(name in nextProps)) {
1355
+ node[name] = void 0;
1232
1356
  }
1233
- } else {
1234
- queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
1235
- }
1236
- };
1237
- }
1238
- function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
1239
- const childSignal = closure(valueAccessor, fn);
1240
- const loopScopeAccessor = "LoopScopeArray:" /* LoopScopeArray */ + ownerLoopNodeAccessor;
1241
- const loopScopeMapAccessor = "LoopScopeMap:" /* LoopScopeMap */ + ownerLoopNodeAccessor;
1242
- const ownerSignal = (ownerScope) => {
1243
- const scopes = ownerScope[loopScopeAccessor] ||= ownerScope[loopScopeMapAccessor] ? [...ownerScope[loopScopeMapAccessor].values()] : [];
1244
- const [firstScope] = scopes;
1245
- if (firstScope) {
1246
- queueRender(
1247
- ownerScope,
1248
- () => {
1249
- for (const scope of scopes) {
1250
- if (!scope.___creating && !scope.___destroyed) {
1251
- childSignal(scope);
1252
- }
1253
- }
1254
- },
1255
- -1,
1256
- 0,
1257
- firstScope.___id
1258
- );
1259
- }
1260
- };
1261
- ownerSignal._ = childSignal;
1262
- return ownerSignal;
1263
- }
1264
- function conditionalClosure(valueAccessor, ownerConditionalNodeAccessor, branch, fn) {
1265
- const childSignal = closure(valueAccessor, fn);
1266
- const scopeAccessor = "ConditionalScope:" /* ConditionalScope */ + ownerConditionalNodeAccessor;
1267
- const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + ownerConditionalNodeAccessor;
1268
- const ownerSignal = (scope) => {
1269
- const ifScope = scope[scopeAccessor];
1270
- if (ifScope && !ifScope.___creating && scope[branchAccessor] === branch) {
1271
- queueRender(ifScope, childSignal, -1);
1272
1357
  }
1273
- };
1274
- ownerSignal._ = childSignal;
1275
- return ownerSignal;
1276
- }
1277
- function subscribeToScopeSet(ownerScope, accessor, scope) {
1278
- const subscribers = ownerScope[accessor] ||= /* @__PURE__ */ new Set();
1279
- if (!subscribers.has(scope)) {
1280
- subscribers.add(scope);
1281
- getAbortSignal(scope, -1).addEventListener(
1282
- "abort",
1283
- () => ownerScope[accessor].delete(scope)
1284
- );
1285
1358
  }
1359
+ for (const name in nextProps) {
1360
+ node[name] = nextProps[name];
1361
+ }
1362
+ scope[index + "-"] = nextProps;
1286
1363
  }
1287
- function dynamicClosure(...closureSignals) {
1288
- const [{ ___scopeInstancesAccessor, ___signalIndexAccessor }] = closureSignals;
1289
- for (let i = closureSignals.length; i--; ) {
1290
- closureSignals[i].___index = i;
1364
+ function normalizeAttrValue(value2) {
1365
+ if (value2 || value2 === 0) {
1366
+ return value2 === true ? "" : value2 + "";
1291
1367
  }
1292
- return (scope) => {
1293
- if (scope[___scopeInstancesAccessor]) {
1294
- for (const childScope of scope[___scopeInstancesAccessor]) {
1295
- if (!childScope.___creating) {
1296
- queueRender(
1297
- childScope,
1298
- closureSignals[childScope[___signalIndexAccessor]],
1299
- -1
1300
- );
1301
- }
1302
- }
1303
- }
1304
- };
1305
1368
  }
1306
- function dynamicClosureRead(valueAccessor, fn, getOwnerScope) {
1307
- const childSignal = closure(valueAccessor, fn, getOwnerScope);
1308
- const closureSignal = (scope) => {
1309
- scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
1310
- childSignal(scope);
1311
- subscribeToScopeSet(
1312
- getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */],
1313
- closureSignal.___scopeInstancesAccessor,
1314
- scope
1315
- );
1316
- };
1317
- closureSignal.___scopeInstancesAccessor = "ClosureScopes:" /* ClosureScopes */ + valueAccessor;
1318
- closureSignal.___signalIndexAccessor = "ClosureSignalIndex:" /* ClosureSignalIndex */ + valueAccessor;
1319
- return closureSignal;
1369
+ function normalizeString(value2) {
1370
+ return value2 || value2 === 0 ? value2 + "" : "\u200D";
1320
1371
  }
1321
- function closure(valueAccessor, fn, getOwnerScope) {
1322
- return (scope) => {
1323
- fn(
1372
+ function lifecycle(scope, index, thisObj) {
1373
+ const instance = scope[index];
1374
+ if (instance) {
1375
+ Object.assign(instance, thisObj);
1376
+ instance.onUpdate?.();
1377
+ } else {
1378
+ scope[index] = thisObj;
1379
+ thisObj.onMount?.();
1380
+ getAbortSignal(
1324
1381
  scope,
1325
- (getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */])[valueAccessor]
1326
- );
1327
- };
1328
- }
1329
- function setTagVar(scope, childAccessor, tagVarSignal2) {
1330
- scope[childAccessor]["#TagVariable" /* TagVariable */] = (value2) => tagVarSignal2(scope, value2);
1331
- }
1332
- var tagVarSignal = (scope, value2) => scope["#TagVariable" /* TagVariable */]?.(value2);
1333
- function setTagVarChange(scope, changeHandler) {
1334
- scope["#TagVariableChange" /* TagVariableChange */] = changeHandler;
1382
+ "LifecycleAbortController:" /* LifecycleAbortController */ + index
1383
+ ).onabort = () => thisObj.onDestroy?.();
1384
+ }
1335
1385
  }
1336
- var tagVarSignalChange = (scope, value2) => scope["#TagVariableChange" /* TagVariableChange */]?.(value2);
1337
- var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
1338
- function nextTagId({ $global }) {
1339
- const id = tagIdsByGlobal.get($global) || 0;
1340
- tagIdsByGlobal.set($global, id + 1);
1341
- return "c" + $global.runtimeId + $global.renderId + id.toString(36);
1386
+ function removeChildNodes(startNode, endNode) {
1387
+ const stop = endNode.nextSibling;
1388
+ let current = startNode;
1389
+ while (current !== stop) {
1390
+ const next = current.nextSibling;
1391
+ current.remove();
1392
+ current = next;
1393
+ }
1342
1394
  }
1343
- function effect(id, fn) {
1344
- register(id, fn);
1345
- return (scope) => {
1346
- queueEffect(scope, fn);
1347
- };
1395
+ function insertChildNodes(parentNode, referenceNode, startNode, endNode) {
1396
+ parentNode.insertBefore(toInsertNode(startNode, endNode), referenceNode);
1348
1397
  }
1349
- function* traverseAllHoisted(scope, path, curIndex = path.length - 1) {
1350
- if (scope) {
1351
- if (Symbol.iterator in scope) {
1352
- for (const s of scope instanceof Map ? scope.values() : scope) {
1353
- yield* traverseAllHoisted(s, path, curIndex);
1354
- }
1355
- } else if (curIndex) {
1356
- yield* traverseAllHoisted(scope[path[curIndex]], path, curIndex - 1);
1357
- } else {
1358
- yield scope[path[0]];
1359
- }
1398
+ function toInsertNode(startNode, endNode) {
1399
+ if (startNode === endNode) return startNode;
1400
+ const parent = new DocumentFragment();
1401
+ const stop = endNode.nextSibling;
1402
+ let current = startNode;
1403
+ while (current !== stop) {
1404
+ const next = current.nextSibling;
1405
+ parent.appendChild(current);
1406
+ current = next;
1360
1407
  }
1361
- }
1362
- function hoist(...path) {
1363
- return (scope) => {
1364
- const getOne = (...args) => iterator().next().value(...args);
1365
- const iterator = getOne[Symbol.iterator] = () => traverseAllHoisted(scope, path);
1366
- return getOne;
1367
- };
1408
+ return parent;
1368
1409
  }
1369
1410
 
1370
- // src/dom/walker.ts
1371
- var walker = /* @__PURE__ */ document.createTreeWalker(document);
1372
- function walk(startNode, walkCodes, branch) {
1373
- walker.currentNode = startNode;
1374
- walkInternal(0, walkCodes, branch);
1375
- }
1376
- function walkInternal(currentWalkIndex, walkCodes, scope) {
1377
- let value2;
1378
- let storedMultiplier = 0;
1379
- let currentMultiplier = 0;
1380
- let currentScopeIndex = 0;
1381
- for (; currentWalkIndex < walkCodes.length; ) {
1382
- value2 = walkCodes.charCodeAt(currentWalkIndex++);
1383
- currentMultiplier = storedMultiplier;
1384
- storedMultiplier = 0;
1385
- if (value2 === 32 /* Get */) {
1386
- const node = walker.currentNode;
1387
- scope[true ? getDebugKey(currentScopeIndex, walker.currentNode) : currentScopeIndex] = node;
1388
- scope["Getter:" /* Getter */ + (true ? getDebugKey(currentScopeIndex++, walker.currentNode) : currentScopeIndex++)] = () => node;
1389
- } else if (value2 === 37 /* Replace */ || value2 === 49 /* DynamicTagWithVar */) {
1390
- walker.currentNode.replaceWith(
1391
- walker.currentNode = scope[true ? getDebugKey(currentScopeIndex++, "#text") : currentScopeIndex++] = new Text()
1392
- );
1393
- if (value2 === 49 /* DynamicTagWithVar */) {
1394
- scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : currentScopeIndex++] = skipScope(scope);
1411
+ // src/dom/reconcile.ts
1412
+ var WRONG_POS = 2147483647;
1413
+ function reconcile(parent, oldBranches, newBranches, afterReference) {
1414
+ let oldStart = 0;
1415
+ let newStart = 0;
1416
+ let oldEnd = oldBranches.length - 1;
1417
+ let newEnd = newBranches.length - 1;
1418
+ let oldStartBranch = oldBranches[oldStart];
1419
+ let newStartBranch = newBranches[newStart];
1420
+ let oldEndBranch = oldBranches[oldEnd];
1421
+ let newEndBranch = newBranches[newEnd];
1422
+ let i;
1423
+ let j;
1424
+ let k;
1425
+ let nextSibling;
1426
+ let oldBranch;
1427
+ let newBranch;
1428
+ outer: {
1429
+ while (oldStartBranch === newStartBranch) {
1430
+ ++oldStart;
1431
+ ++newStart;
1432
+ if (oldStart > oldEnd || newStart > newEnd) {
1433
+ break outer;
1395
1434
  }
1396
- } else if (value2 === 38 /* EndChild */) {
1397
- return currentWalkIndex;
1398
- } else if (value2 === 47 /* BeginChild */ || value2 === 48 /* BeginChildWithVar */) {
1399
- currentWalkIndex = walkInternal(
1400
- currentWalkIndex,
1401
- walkCodes,
1402
- scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global, scope.___closestBranch)
1403
- );
1404
- if (value2 === 48 /* BeginChildWithVar */) {
1405
- scope[true ? getDebugKey(currentScopeIndex++, "#scopeOffset") : currentScopeIndex++] = skipScope(scope);
1435
+ oldStartBranch = oldBranches[oldStart];
1436
+ newStartBranch = newBranches[newStart];
1437
+ }
1438
+ while (oldEndBranch === newEndBranch) {
1439
+ --oldEnd;
1440
+ --newEnd;
1441
+ if (oldStart > oldEnd || newStart > newEnd) {
1442
+ break outer;
1406
1443
  }
1407
- } else if (value2 < 91 /* NextEnd */ + 1) {
1408
- value2 = 20 /* Next */ * currentMultiplier + value2 - 67 /* Next */;
1409
- while (value2--) {
1410
- walker.nextNode();
1444
+ oldEndBranch = oldBranches[oldEnd];
1445
+ newEndBranch = newBranches[newEnd];
1446
+ }
1447
+ }
1448
+ if (oldStart > oldEnd) {
1449
+ if (newStart <= newEnd) {
1450
+ k = newEnd + 1;
1451
+ nextSibling = k < newBranches.length ? newBranches[k].___startNode : afterReference;
1452
+ do {
1453
+ insertBranchBefore(newBranches[newStart++], parent, nextSibling);
1454
+ } while (newStart <= newEnd);
1455
+ }
1456
+ } else if (newStart > newEnd) {
1457
+ do {
1458
+ removeAndDestroyBranch(oldBranches[oldStart++]);
1459
+ } while (oldStart <= oldEnd);
1460
+ } else {
1461
+ const oldLength = oldEnd - oldStart + 1;
1462
+ const newLength = newEnd - newStart + 1;
1463
+ const aNullable = oldBranches;
1464
+ const sources = new Array(newLength);
1465
+ for (i = 0; i < newLength; ++i) {
1466
+ sources[i] = -1;
1467
+ }
1468
+ let pos = 0;
1469
+ let synced = 0;
1470
+ const keyIndex = /* @__PURE__ */ new Map();
1471
+ for (j = newStart; j <= newEnd; ++j) {
1472
+ keyIndex.set(newBranches[j], j);
1473
+ }
1474
+ for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
1475
+ oldBranch = oldBranches[i];
1476
+ j = keyIndex.get(oldBranch);
1477
+ if (j !== void 0) {
1478
+ pos = pos > j ? WRONG_POS : j;
1479
+ ++synced;
1480
+ newBranch = newBranches[j];
1481
+ sources[j - newStart] = i;
1482
+ aNullable[i] = null;
1411
1483
  }
1412
- } else if (value2 < 106 /* OverEnd */ + 1) {
1413
- value2 = 10 /* Over */ * currentMultiplier + value2 - 97 /* Over */;
1414
- while (value2--) {
1415
- walker.nextSibling();
1484
+ }
1485
+ if (oldLength === oldBranches.length && synced === 0) {
1486
+ for (; newStart < newLength; ++newStart) {
1487
+ insertBranchBefore(newBranches[newStart], parent, afterReference);
1416
1488
  }
1417
- } else if (value2 < 116 /* OutEnd */ + 1) {
1418
- value2 = 10 /* Out */ * currentMultiplier + value2 - 107 /* Out */;
1419
- while (value2--) {
1420
- walker.parentNode();
1489
+ for (; oldStart < oldLength; ++oldStart) {
1490
+ removeAndDestroyBranch(oldBranches[oldStart]);
1421
1491
  }
1422
- walker.nextSibling();
1423
1492
  } else {
1424
- if (value2 < 117 /* Multiplier */ || value2 > 126 /* MultiplierEnd */) {
1425
- throw new Error(`Unknown walk code: ${value2}`);
1493
+ i = oldLength - synced;
1494
+ while (i > 0) {
1495
+ oldBranch = aNullable[oldStart++];
1496
+ if (oldBranch !== null) {
1497
+ removeAndDestroyBranch(oldBranch);
1498
+ i--;
1499
+ }
1500
+ }
1501
+ if (pos === WRONG_POS) {
1502
+ const seq = longestIncreasingSubsequence(sources);
1503
+ j = seq.length - 1;
1504
+ k = newBranches.length;
1505
+ for (i = newLength - 1; i >= 0; --i) {
1506
+ if (sources[i] === -1) {
1507
+ pos = i + newStart;
1508
+ newBranch = newBranches[pos++];
1509
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
1510
+ insertBranchBefore(newBranch, parent, nextSibling);
1511
+ } else {
1512
+ if (j < 0 || i !== seq[j]) {
1513
+ pos = i + newStart;
1514
+ newBranch = newBranches[pos++];
1515
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
1516
+ insertBranchBefore(newBranch, parent, nextSibling);
1517
+ } else {
1518
+ --j;
1519
+ }
1520
+ }
1521
+ }
1522
+ } else if (synced !== newLength) {
1523
+ k = newBranches.length;
1524
+ for (i = newLength - 1; i >= 0; --i) {
1525
+ if (sources[i] === -1) {
1526
+ pos = i + newStart;
1527
+ newBranch = newBranches[pos++];
1528
+ nextSibling = pos < k ? newBranches[pos].___startNode : afterReference;
1529
+ insertBranchBefore(newBranch, parent, nextSibling);
1530
+ }
1531
+ }
1426
1532
  }
1427
- storedMultiplier = currentMultiplier * 10 /* Multiplier */ + value2 - 117 /* Multiplier */;
1428
1533
  }
1429
1534
  }
1430
1535
  }
1431
- function getDebugKey(index, node) {
1432
- if (typeof node === "string") {
1433
- return `${node}/${index}`;
1434
- } else if (node.nodeType === 3 /* Text */) {
1435
- return `#text/${index}`;
1436
- } else if (node.nodeType === 8 /* Comment */) {
1437
- return `#comment/${index}`;
1438
- } else if (node.nodeType === 1 /* Element */) {
1439
- return `#${node.tagName.toLowerCase()}/${index}`;
1440
- }
1441
- return index;
1442
- }
1443
-
1444
- // src/dom/renderer.ts
1445
- function createBranch($global, renderer, parentScope, parentNode) {
1446
- const branch = createScope($global);
1447
- const parentBranch = parentScope?.___closestBranch;
1448
- branch["_" /* Owner */] = renderer.___owner || parentScope;
1449
- branch.___closestBranch = branch;
1450
- if (parentBranch) {
1451
- branch.___parentBranch = parentBranch;
1452
- (parentBranch.___branchScopes ||= /* @__PURE__ */ new Set()).add(branch);
1453
- }
1454
- if (true) {
1455
- branch.___renderer = renderer;
1456
- }
1457
- renderer.___clone?.(
1458
- branch,
1459
- parentNode.namespaceURI
1460
- );
1461
- return branch;
1462
- }
1463
- function createAndSetupBranch($global, renderer, parentScope, parentNode) {
1464
- return setupBranch(
1465
- renderer,
1466
- createBranch($global, renderer, parentScope, parentNode)
1467
- );
1468
- }
1469
- function setupBranch(renderer, branch) {
1470
- if (renderer.___setup) {
1471
- queueRender(branch, renderer.___setup, -1);
1536
+ function longestIncreasingSubsequence(a) {
1537
+ const p = a.slice();
1538
+ const result = [0];
1539
+ let u;
1540
+ let v;
1541
+ for (let i = 0, il = a.length; i < il; ++i) {
1542
+ if (a[i] === -1) {
1543
+ continue;
1544
+ }
1545
+ const j = result[result.length - 1];
1546
+ if (a[j] < a[i]) {
1547
+ p[i] = j;
1548
+ result.push(i);
1549
+ continue;
1550
+ }
1551
+ u = 0;
1552
+ v = result.length - 1;
1553
+ while (u < v) {
1554
+ const c = (u + v) / 2 | 0;
1555
+ if (a[result[c]] < a[i]) {
1556
+ u = c + 1;
1557
+ } else {
1558
+ v = c;
1559
+ }
1560
+ }
1561
+ if (a[i] < a[result[u]]) {
1562
+ if (u > 0) {
1563
+ p[i] = result[u - 1];
1564
+ }
1565
+ result[u] = i;
1566
+ }
1472
1567
  }
1473
- return branch;
1474
- }
1475
- function createContent(id, template, walks, setup, params, dynamicScopesAccessor) {
1476
- walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
1477
- setup = setup ? setup._ || setup : void 0;
1478
- params ||= void 0;
1479
- const clone = template ? (branch, ns) => {
1480
- ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
1481
- template,
1482
- ns
1483
- ))(branch, walks);
1484
- } : (branch) => {
1485
- walk(
1486
- branch.___startNode = branch.___endNode = new Text(),
1487
- walks,
1488
- branch
1489
- );
1490
- };
1491
- return (owner) => {
1492
- return {
1493
- ___id: id,
1494
- ___clone: clone,
1495
- ___owner: owner,
1496
- ___setup: setup,
1497
- ___params: params,
1498
- ___accessor: dynamicScopesAccessor
1499
- };
1500
- };
1501
- }
1502
- function registerContent(id, template, walks, setup, params, dynamicScopesAccessor) {
1503
- return register(
1504
- id,
1505
- createContent(id, template, walks, setup, params, dynamicScopesAccessor)
1506
- );
1507
- }
1508
- function localClosures(renderer, closureFns) {
1509
- const closureSignals = {};
1510
- for (const key in closureFns) {
1511
- closureSignals[key] = value(key, closureFns[key]);
1568
+ u = result.length;
1569
+ v = result[u - 1];
1570
+ while (u-- > 0) {
1571
+ result[u] = v;
1572
+ v = p[v];
1512
1573
  }
1513
- return (owner, closureValues) => {
1514
- const instance = renderer(owner);
1515
- instance.___localClosures = closureSignals;
1516
- instance.___localClosureValues = closureValues;
1517
- return instance;
1518
- };
1519
- }
1520
- function createRenderer(template, walks, setup, params) {
1521
- return createContent("", template, walks, setup, params)();
1522
- }
1523
- var cloneCache = {};
1524
- function createCloneableHTML(html2, ns) {
1525
- const { firstChild, lastChild } = parseHTML(html2, ns);
1526
- const parent = document.createElementNS(ns, "t");
1527
- insertChildNodes(parent, null, firstChild, lastChild);
1528
- return firstChild === lastChild && firstChild.nodeType < 8 /* Comment */ ? (branch, walks) => {
1529
- walk(
1530
- branch.___startNode = branch.___endNode = firstChild.cloneNode(true),
1531
- walks,
1532
- branch
1533
- );
1534
- } : (branch, walks) => {
1535
- const clone = parent.cloneNode(true);
1536
- walk(clone.firstChild, walks, branch);
1537
- branch.___startNode = clone.firstChild;
1538
- branch.___endNode = clone.lastChild;
1539
- };
1574
+ return result;
1540
1575
  }
1541
1576
 
1542
1577
  // src/dom/control-flow.ts
@@ -2258,6 +2293,7 @@ export {
2258
2293
  attrTag,
2259
2294
  attrTags,
2260
2295
  attrs,
2296
+ attrsAndContent,
2261
2297
  attrsEvents,
2262
2298
  awaitTag,
2263
2299
  classAttr,
@@ -2295,6 +2331,7 @@ export {
2295
2331
  hoist,
2296
2332
  html,
2297
2333
  init,
2334
+ insertContent,
2298
2335
  intersection,
2299
2336
  lifecycle,
2300
2337
  localClosures,
@@ -2306,6 +2343,7 @@ export {
2306
2343
  nodeRef,
2307
2344
  on,
2308
2345
  partialAttrs,
2346
+ partialAttrsAndContent,
2309
2347
  props,
2310
2348
  register,
2311
2349
  registerBoundSignal,