marko 6.0.0-next.3.28 → 6.0.0-next.3.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dom.mjs CHANGED
@@ -143,17 +143,17 @@ var DEFAULT_RUNTIME_ID = "M", DEFAULT_RENDER_ID = "_";
143
143
  var registeredValues = {}, Render = class {
144
144
  n = [];
145
145
  o = {};
146
- z = {
146
+ A = {
147
147
  _: registeredValues
148
148
  };
149
149
  constructor(renders, runtimeId, renderId) {
150
- this.A = renders, this.B = runtimeId, this.p = renderId, this.q = renders[renderId], this.s();
150
+ this.B = renders, this.C = runtimeId, this.p = renderId, this.q = renders[renderId], this.s();
151
151
  }
152
152
  w() {
153
153
  this.q.w(), this.s();
154
154
  }
155
155
  s() {
156
- let data2 = this.q, serializeContext = this.z, scopeLookup = this.o, visits = data2.v, branchIds = /* @__PURE__ */ new Set(), parentBranchIds = /* @__PURE__ */ new Map();
156
+ let data2 = this.q, serializeContext = this.A, scopeLookup = this.o, visits = data2.v, branchIds = /* @__PURE__ */ new Set(), parentBranchIds = /* @__PURE__ */ new Map();
157
157
  if (visits.length) {
158
158
  let commentPrefixLen = data2.i.length, closestBranchMarkers = /* @__PURE__ */ new Map(), visitNodes = new Set(visits), lastEndNode;
159
159
  data2.v = [];
@@ -204,7 +204,7 @@ var registeredValues = {}, Render = class {
204
204
  let resumeData = resumes[i++];
205
205
  if (typeof resumeData == "function") {
206
206
  let scopes = resumeData(serializeContext), { $global } = scopeLookup;
207
- $global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = this.B, $global.renderId = this.p);
207
+ $global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = this.C, $global.renderId = this.p);
208
208
  for (let scopeId in scopes)
209
209
  if (scopeId !== "$") {
210
210
  let scope = scopes[scopeId], prevScope = scopeLookup[scopeId];
@@ -218,7 +218,7 @@ var registeredValues = {}, Render = class {
218
218
  branch.f = +scopeId, scope.c = branch, parentBranch && (branch.t = parentBranch, (parentBranch.k ||= /* @__PURE__ */ new Set()).add(branch));
219
219
  }
220
220
  }
221
- } else i === len || typeof resumes[i] != "string" ? delete this.A[this.p] : registeredValues[resumes[i++]](
221
+ } else i === len || typeof resumes[i] != "string" ? delete this.B[this.p] : registeredValues[resumes[i++]](
222
222
  scopeLookup[resumeData],
223
223
  scopeLookup[resumeData]
224
224
  );
@@ -256,7 +256,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
256
256
  }
257
257
  }
258
258
  function registerSubscriber(id, signal) {
259
- return register(id, signal.C), signal;
259
+ return register(id, signal.D), signal;
260
260
  }
261
261
  function nodeRef(id, key) {
262
262
  return register(id, (scope) => () => scope[key]);
@@ -435,22 +435,10 @@ function toValueProp(it) {
435
435
  }
436
436
 
437
437
  // src/dom/parse-html.ts
438
- var parser = /* @__PURE__ */ document.createElement("template");
439
- function parseHTML(html2) {
440
- return parser.innerHTML = html2, parser.content;
441
- }
442
- function parseHTMLOrSingleNode(html2) {
443
- let content = parseHTML(html2);
444
- if (content.firstChild) {
445
- if (content.firstChild === content.lastChild && // If the firstChild is a comment it's possible its
446
- // a single replaced node, in which case the walker can't replace
447
- // the node itself.
448
- content.firstChild.nodeType !== 8)
449
- return content.firstChild;
450
- let fragment = new DocumentFragment();
451
- return fragment.appendChild(content), fragment;
452
- }
453
- return new Text();
438
+ var parsers = {};
439
+ function parseHTML(html2, ns) {
440
+ let parser = parsers[ns] ||= document.createElementNS(ns, "template"), content = (parser.innerHTML = html2, parser.content || parser);
441
+ return content.firstChild || content.appendChild(new Text()), content;
454
442
  }
455
443
 
456
444
  // src/dom/dom.ts
@@ -590,11 +578,16 @@ function attrsEvents(scope, nodeAccessor) {
590
578
  on(el, name, events[name]);
591
579
  }
592
580
  function html(scope, value2, accessor) {
593
- let firstChild = scope[accessor], lastChild = scope[accessor + "-" /* DynamicPlaceholderLastChild */] || firstChild, newContent = parseHTML(
594
- value2 || value2 === 0 ? value2 + "" : "<!>"
595
- // TODO: is the comment needed
581
+ let firstChild = scope[accessor], parentNode = firstChild.parentNode, lastChild = scope[accessor + "-" /* DynamicPlaceholderLastChild */] || firstChild, newContent = parseHTML(
582
+ value2 || value2 === 0 ? value2 + "" : "",
583
+ parentNode.namespaceURI
596
584
  );
597
- scope[accessor] = newContent.firstChild, scope[accessor + "-" /* DynamicPlaceholderLastChild */] = newContent.lastChild, firstChild.parentNode.insertBefore(newContent, firstChild), removeChildNodes(firstChild, lastChild);
585
+ insertChildNodes(
586
+ parentNode,
587
+ firstChild,
588
+ scope[accessor] = newContent.firstChild,
589
+ scope[accessor + "-" /* DynamicPlaceholderLastChild */] = newContent.lastChild
590
+ ), removeChildNodes(firstChild, lastChild);
598
591
  }
599
592
  function props(scope, nodeIndex, index) {
600
593
  let nextProps = scope[index], prevProps = scope[index + "-"], node = scope[nodeIndex];
@@ -626,6 +619,18 @@ function removeChildNodes(startNode, endNode) {
626
619
  current.remove(), current = next;
627
620
  }
628
621
  }
622
+ function insertChildNodes(parentNode, referenceNode, startNode, endNode) {
623
+ parentNode.insertBefore(toInsertNode(startNode, endNode), referenceNode);
624
+ }
625
+ function toInsertNode(startNode, endNode) {
626
+ if (startNode === endNode) return startNode;
627
+ let parent = new DocumentFragment(), stop = endNode.nextSibling, current = startNode;
628
+ for (; current !== stop; ) {
629
+ let next = current.nextSibling;
630
+ parent.appendChild(current), current = next;
631
+ }
632
+ return parent;
633
+ }
629
634
 
630
635
  // src/dom/scope.ts
631
636
  var pendingScopes = [];
@@ -649,7 +654,7 @@ function destroyBranch(branch) {
649
654
  branch.t?.k?.delete(branch), destroyNestedBranches(branch);
650
655
  }
651
656
  function destroyNestedBranches(branch) {
652
- branch.D = 1, branch.k?.forEach(destroyNestedBranches), branch.E?.forEach((scope) => {
657
+ branch.E = 1, branch.k?.forEach(destroyNestedBranches), branch.F?.forEach((scope) => {
653
658
  for (let id in scope.h)
654
659
  scope.h[id]?.abort();
655
660
  });
@@ -658,11 +663,12 @@ function removeAndDestroyBranch(branch) {
658
663
  destroyBranch(branch), removeChildNodes(branch.a, branch.b);
659
664
  }
660
665
  function insertBranchBefore(branch, parentNode, nextSibling) {
661
- let current = branch.a, stop = branch.b.nextSibling;
662
- for (; current !== stop; ) {
663
- let next = current.nextSibling;
664
- parentNode.insertBefore(current, nextSibling), current = next;
665
- }
666
+ insertChildNodes(
667
+ parentNode,
668
+ nextSibling,
669
+ branch.a,
670
+ branch.b
671
+ );
666
672
  }
667
673
 
668
674
  // src/dom/reconcile.ts
@@ -784,35 +790,35 @@ function walkInternal(walkCodes, scope, currentWalkIndex) {
784
790
  }
785
791
 
786
792
  // src/dom/renderer.ts
787
- function createBranchScopeWithRenderer(renderer, $global, parentScope) {
793
+ function createBranchScopeWithRenderer(renderer, $global, parentScope, parentNode) {
788
794
  let branch = createBranch(
789
795
  $global,
790
796
  renderer.u || parentScope,
791
797
  parentScope
792
798
  );
793
- return initBranch(renderer, branch), branch;
799
+ return initBranch(renderer, branch, parentNode), branch;
794
800
  }
795
- function createBranchScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, parentScope) {
801
+ function createBranchScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, parentScope, parentNode) {
796
802
  if (typeof tagNameOrRenderer != "string")
797
803
  return createBranchScopeWithRenderer(
798
804
  tagNameOrRenderer,
799
805
  $global,
800
- parentScope
806
+ parentScope,
807
+ parentNode
801
808
  );
802
809
  let branch = createBranch($global, parentScope, parentScope);
803
- return branch[0] = branch.a = branch.b = document.createElement(tagNameOrRenderer), branch;
810
+ return branch[0] = branch.a = branch.b = document.createElementNS(
811
+ tagNameOrRenderer === "svg" ? "http://www.w3.org/2000/svg" : tagNameOrRenderer === "math" ? "http://www.w3.org/1998/Math/MathML" : parentNode.namespaceURI,
812
+ tagNameOrRenderer
813
+ ), branch;
804
814
  }
805
815
  function createBranch($global, ownerScope, parentScope) {
806
816
  let branch = createScope($global), parentBranch = parentScope.c;
807
817
  return branch._ = ownerScope, branch.c = branch, parentBranch ? (branch.f = parentBranch.f + 1, branch.t = parentBranch, (parentBranch.k ||= /* @__PURE__ */ new Set()).add(branch)) : branch.f = 1, branch;
808
818
  }
809
- function initBranch(renderer, branch) {
810
- let dom = renderer.l();
811
- return walk(
812
- dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom,
813
- renderer.F,
814
- branch
815
- ), branch.a = dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom, branch.b = dom.nodeType === 11 /* DocumentFragment */ ? dom.lastChild : dom, renderer.x && queueRender(branch, renderer.x), dom;
819
+ function initBranch(renderer, branch, parentNode) {
820
+ let clone = renderer.l(parentNode.namespaceURI), cloneParent = clone.parentNode;
821
+ walk(cloneParent?.firstChild || clone, renderer.G, branch), branch.a = cloneParent?.firstChild || clone, branch.b = cloneParent?.lastChild || clone, renderer.x && queueRender(branch, renderer.x);
816
822
  }
817
823
  function dynamicTagAttrs(nodeAccessor, getContent, inputIsArgs) {
818
824
  return (scope, attrsOrOp) => {
@@ -843,12 +849,12 @@ function createRendererWithOwner(template, rawWalks, setup, getArgs) {
843
849
  let args, id = {}, walks = rawWalks ? /* @__PURE__ */ trimWalkString(rawWalks) : " ";
844
850
  return (owner) => ({
845
851
  j: id,
846
- G: template,
847
- F: walks,
852
+ y: template,
853
+ G: walks,
848
854
  x: setup,
849
855
  l: _clone,
850
856
  u: owner,
851
- H: void 0,
857
+ J: void 0,
852
858
  get d() {
853
859
  return args ||= getArgs?.();
854
860
  }
@@ -857,10 +863,16 @@ function createRendererWithOwner(template, rawWalks, setup, getArgs) {
857
863
  function createRenderer(template, walks, setup, getArgs) {
858
864
  return createRendererWithOwner(template, walks, setup, getArgs)();
859
865
  }
860
- function _clone() {
861
- return (this.H ||= parseHTMLOrSingleNode(
862
- this.G
863
- )).cloneNode(!0);
866
+ function _clone(ns) {
867
+ return ((cloneCache[ns] ||= {})[this.y] ||= createCloneableHTML(
868
+ this.y,
869
+ ns
870
+ ))();
871
+ }
872
+ var cloneCache = {};
873
+ function createCloneableHTML(html2, ns) {
874
+ let { firstChild, lastChild } = parseHTML(html2, ns), parent = document.createElementNS(ns, "t");
875
+ return insertChildNodes(parent, null, firstChild, lastChild), firstChild === lastChild && firstChild.nodeType < 8 /* Comment */ ? () => firstChild.cloneNode(!0) : () => parent.cloneNode(!0).firstChild;
864
876
  }
865
877
 
866
878
  // src/dom/control-flow.ts
@@ -880,7 +892,12 @@ var conditional = function(nodeAccessor, fn, getIntersection) {
880
892
  };
881
893
  };
882
894
  function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
883
- let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyBranch(scope[nodeAccessor]), newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : getEmptyBranch(scope[nodeAccessor]);
895
+ let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyBranch(scope[nodeAccessor]), newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(
896
+ newRenderer,
897
+ scope.$global,
898
+ scope,
899
+ prevBranch.b.parentNode
900
+ ) : getEmptyBranch(scope[nodeAccessor]);
884
901
  insertBranchBefore(
885
902
  newBranch,
886
903
  prevBranch.b.parentNode,
@@ -904,7 +921,12 @@ var conditionalOnlyChild = function(nodeAccessor, fn, getIntersection) {
904
921
  };
905
922
  };
906
923
  function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
907
- let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor], newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0;
924
+ let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor], newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(
925
+ newRenderer,
926
+ scope.$global,
927
+ scope,
928
+ referenceNode
929
+ ) : void 0;
908
930
  referenceNode.textContent = "", newBranch && insertBranchBefore(newBranch, referenceNode, null), prevBranch && destroyBranch(prevBranch), scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
909
931
  }
910
932
  var emptyMarkerMap = /* @__PURE__ */ new Map([
@@ -949,20 +971,16 @@ function loop(nodeAccessor, renderer, forEach) {
949
971
  params?.(branch, valueOrOp);
950
972
  return;
951
973
  }
952
- let referenceNode = scope[nodeAccessor], referenceIsMarker = referenceNode.nodeType === 8 || referenceNode.nodeType === 3, oldMap = scope[nodeAccessor + "(" /* LoopScopeMap */] || (referenceIsMarker ? emptyMarkerMap : emptyMap), oldArray = scope[nodeAccessor + "!" /* LoopScopeArray */] || Array.from(oldMap.values()), newMap, newArray, afterReference, parentNode, needsReconciliation = !0;
953
- if (forEach(valueOrOp, (key, args) => {
974
+ let referenceNode = scope[nodeAccessor], referenceIsMarker = referenceNode.nodeType > 1 /* Element */, oldMap = scope[nodeAccessor + "(" /* LoopScopeMap */] || (referenceIsMarker ? emptyMarkerMap : emptyMap), oldArray = scope[nodeAccessor + "!" /* LoopScopeArray */] || Array.from(oldMap.values()), parentNode = referenceIsMarker ? referenceNode.parentNode || oldArray[0].a.parentNode : referenceNode, newMap, newArray, afterReference, needsReconciliation = !0;
975
+ forEach(valueOrOp, (key, args) => {
954
976
  let branch = oldMap.get(key);
955
- branch || (branch = createBranchScopeWithRenderer(renderer, scope.$global, scope)), params && params(branch, args), newMap ? (newMap.set(key, branch), newArray.push(branch)) : (newMap = /* @__PURE__ */ new Map([[key, branch]]), newArray = [branch]);
956
- }), newMap || (referenceIsMarker ? (newMap = emptyMarkerMap, newArray = emptyMarkerArray, getEmptyBranch(referenceNode)) : (oldArray.forEach(destroyBranch), referenceNode.textContent = "", newMap = emptyMap, newArray = emptyArray, needsReconciliation = !1)), needsReconciliation) {
957
- if (referenceIsMarker) {
958
- oldMap === emptyMarkerMap && getEmptyBranch(referenceNode);
959
- let oldLastChild = oldArray[oldArray.length - 1];
960
- afterReference = oldLastChild.b.nextSibling, parentNode = oldLastChild.a.parentNode;
961
- } else
962
- afterReference = null, parentNode = referenceNode;
963
- reconcile(parentNode, oldArray, newArray, afterReference);
964
- }
965
- scope[nodeAccessor + "(" /* LoopScopeMap */] = newMap, scope[nodeAccessor + "!" /* LoopScopeArray */] = newArray;
977
+ branch || (branch = createBranchScopeWithRenderer(
978
+ renderer,
979
+ scope.$global,
980
+ scope,
981
+ parentNode
982
+ )), params && params(branch, args), newMap ? (newMap.set(key, branch), newArray.push(branch)) : (newMap = /* @__PURE__ */ new Map([[key, branch]]), newArray = [branch]);
983
+ }), newMap || (referenceIsMarker ? (newMap = emptyMarkerMap, newArray = emptyMarkerArray, getEmptyBranch(referenceNode)) : (oldArray.forEach(destroyBranch), referenceNode.textContent = "", newMap = emptyMap, newArray = emptyArray, needsReconciliation = !1)), needsReconciliation && (referenceIsMarker ? (oldMap === emptyMarkerMap && getEmptyBranch(referenceNode), afterReference = oldArray[oldArray.length - 1].b.nextSibling) : afterReference = null, reconcile(parentNode, oldArray, newArray, afterReference)), scope[nodeAccessor + "(" /* LoopScopeMap */] = newMap, scope[nodeAccessor + "!" /* LoopScopeArray */] = newArray;
966
984
  };
967
985
  }
968
986
  function bySecondArg(_item, index) {
@@ -1038,7 +1056,7 @@ function dynamicClosure(fn, getOwnerScope = defaultGetOwnerScope, getIntersectio
1038
1056
  getOwnerScope(scope)[ownerSubscribersAccessor].delete(scope);
1039
1057
  });
1040
1058
  };
1041
- return helperSignal._ = setupSignal, helperSignal.C = subscribe, helperSignal;
1059
+ return helperSignal._ = setupSignal, helperSignal.D = subscribe, helperSignal;
1042
1060
  }
1043
1061
  function setTagVar(scope, childAccessor, tagVarSignal2) {
1044
1062
  scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
@@ -1080,9 +1098,9 @@ function queueSource(scope, signal, value2) {
1080
1098
  function queueRender(scope, signal, value2) {
1081
1099
  let i = pendingRenders.length, render = {
1082
1100
  m: scope,
1083
- I: signal,
1084
- J: value2,
1085
- y: i
1101
+ H: signal,
1102
+ I: value2,
1103
+ z: i
1086
1104
  };
1087
1105
  for (pendingRenders.push(render); i; ) {
1088
1106
  let parentIndex = i - 1 >> 1, parent = pendingRenders[parentIndex];
@@ -1135,12 +1153,12 @@ function runRenders() {
1135
1153
  }
1136
1154
  pendingRenders[i] = item;
1137
1155
  }
1138
- render.m.c?.D || render.I(render.m, render.J);
1156
+ render.m.c?.E || render.H(render.m, render.I);
1139
1157
  }
1140
1158
  finishPendingScopes();
1141
1159
  }
1142
1160
  function comparePendingRenders(a, b) {
1143
- return getBranchDepth(a) - getBranchDepth(b) || a.y - b.y;
1161
+ return getBranchDepth(a) - getBranchDepth(b) || a.z - b.z;
1144
1162
  }
1145
1163
  function getBranchDepth(render) {
1146
1164
  return render.m.c?.f || 0;
@@ -1152,7 +1170,7 @@ function resetAbortSignal(scope, id) {
1152
1170
  ctrl && (queueEffect(ctrl, abort), scope.h[id] = void 0);
1153
1171
  }
1154
1172
  function getAbortSignal(scope, id) {
1155
- return scope.c && (scope.c.E ||= /* @__PURE__ */ new Set()).add(scope), ((scope.h ||= {})[id] ||= new AbortController()).signal;
1173
+ return scope.c && (scope.c.F ||= /* @__PURE__ */ new Set()).add(scope), ((scope.h ||= {})[id] ||= new AbortController()).signal;
1156
1174
  }
1157
1175
  function abort(ctrl) {
1158
1176
  ctrl.abort();
@@ -1214,9 +1232,9 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
1214
1232
  normalizedInput[key === "renderBody" ? "content" : key] = input[key];
1215
1233
  }
1216
1234
  if (component.effects = prepareEffects(() => {
1217
- branch ? (applyArgs(branch, MARK), existing = !0) : (branch = component.scope = createScope(out.global), branch._ = renderer.u, initBranch(renderer, branch)), applyArgs(branch, args);
1235
+ branch ? (applyArgs(branch, MARK), existing = !0) : (branch = component.scope = createScope(out.global), branch._ = renderer.u, initBranch(renderer, branch, document.body)), applyArgs(branch, args);
1218
1236
  }), !existing)
1219
- return branch.a === branch.b ? branch.a : branch.a.parentNode;
1237
+ return toInsertNode(branch.a, branch.b);
1220
1238
  }
1221
1239
  };
1222
1240
  function noop() {
@@ -1228,7 +1246,7 @@ var createTemplate = (templateId, ...rendererArgs) => {
1228
1246
  return renderer.mount = mount, renderer._ = renderer, register(templateId, renderer);
1229
1247
  };
1230
1248
  function mount(input = {}, reference, position) {
1231
- let branch, dom, parentNode = reference, nextSibling = null, { $global } = input;
1249
+ let branch, parentNode = reference, nextSibling = null, { $global } = input;
1232
1250
  switch ($global ? ({ $global, ...input } = input, $global = {
1233
1251
  runtimeId: DEFAULT_RUNTIME_ID,
1234
1252
  renderId: DEFAULT_RENDER_ID,
@@ -1248,9 +1266,14 @@ function mount(input = {}, reference, position) {
1248
1266
  break;
1249
1267
  }
1250
1268
  let args = this.d, effects = prepareEffects(() => {
1251
- branch = createScope($global), dom = initBranch(this, branch), args?.(branch, [input]);
1269
+ branch = createScope($global), initBranch(this, branch, parentNode), args?.(branch, [input]);
1252
1270
  });
1253
- return parentNode.insertBefore(dom, nextSibling), runEffects(effects), {
1271
+ return insertChildNodes(
1272
+ parentNode,
1273
+ nextSibling,
1274
+ branch.a,
1275
+ branch.b
1276
+ ), runEffects(effects), {
1254
1277
  update: (newInput) => {
1255
1278
  args && runEffects(
1256
1279
  prepareEffects(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.0-next.3.28",
3
+ "version": "6.0.0-next.3.29",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",