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.js CHANGED
@@ -227,17 +227,17 @@ var DEFAULT_RUNTIME_ID = "M", DEFAULT_RENDER_ID = "_";
227
227
  var registeredValues = {}, Render = class {
228
228
  n = [];
229
229
  o = {};
230
- z = {
230
+ A = {
231
231
  _: registeredValues
232
232
  };
233
233
  constructor(renders, runtimeId, renderId) {
234
- this.A = renders, this.B = runtimeId, this.p = renderId, this.q = renders[renderId], this.s();
234
+ this.B = renders, this.C = runtimeId, this.p = renderId, this.q = renders[renderId], this.s();
235
235
  }
236
236
  w() {
237
237
  this.q.w(), this.s();
238
238
  }
239
239
  s() {
240
- let data2 = this.q, serializeContext = this.z, scopeLookup = this.o, visits = data2.v, branchIds = /* @__PURE__ */ new Set(), parentBranchIds = /* @__PURE__ */ new Map();
240
+ let data2 = this.q, serializeContext = this.A, scopeLookup = this.o, visits = data2.v, branchIds = /* @__PURE__ */ new Set(), parentBranchIds = /* @__PURE__ */ new Map();
241
241
  if (visits.length) {
242
242
  let commentPrefixLen = data2.i.length, closestBranchMarkers = /* @__PURE__ */ new Map(), visitNodes = new Set(visits), lastEndNode;
243
243
  data2.v = [];
@@ -288,7 +288,7 @@ var registeredValues = {}, Render = class {
288
288
  let resumeData = resumes[i++];
289
289
  if (typeof resumeData == "function") {
290
290
  let scopes = resumeData(serializeContext), { $global } = scopeLookup;
291
- $global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = this.B, $global.renderId = this.p);
291
+ $global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = this.C, $global.renderId = this.p);
292
292
  for (let scopeId in scopes)
293
293
  if (scopeId !== "$") {
294
294
  let scope = scopes[scopeId], prevScope = scopeLookup[scopeId];
@@ -302,7 +302,7 @@ var registeredValues = {}, Render = class {
302
302
  branch.f = +scopeId, scope.c = branch, parentBranch && (branch.t = parentBranch, (parentBranch.k ||= /* @__PURE__ */ new Set()).add(branch));
303
303
  }
304
304
  }
305
- } else i === len || typeof resumes[i] != "string" ? delete this.A[this.p] : registeredValues[resumes[i++]](
305
+ } else i === len || typeof resumes[i] != "string" ? delete this.B[this.p] : registeredValues[resumes[i++]](
306
306
  scopeLookup[resumeData],
307
307
  scopeLookup[resumeData]
308
308
  );
@@ -340,7 +340,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
340
340
  }
341
341
  }
342
342
  function registerSubscriber(id, signal) {
343
- return register(id, signal.C), signal;
343
+ return register(id, signal.D), signal;
344
344
  }
345
345
  function nodeRef(id, key) {
346
346
  return register(id, (scope) => () => scope[key]);
@@ -519,22 +519,10 @@ function toValueProp(it) {
519
519
  }
520
520
 
521
521
  // src/dom/parse-html.ts
522
- var parser = /* @__PURE__ */ document.createElement("template");
523
- function parseHTML(html2) {
524
- return parser.innerHTML = html2, parser.content;
525
- }
526
- function parseHTMLOrSingleNode(html2) {
527
- let content = parseHTML(html2);
528
- if (content.firstChild) {
529
- if (content.firstChild === content.lastChild && // If the firstChild is a comment it's possible its
530
- // a single replaced node, in which case the walker can't replace
531
- // the node itself.
532
- content.firstChild.nodeType !== 8)
533
- return content.firstChild;
534
- let fragment = new DocumentFragment();
535
- return fragment.appendChild(content), fragment;
536
- }
537
- return new Text();
522
+ var parsers = {};
523
+ function parseHTML(html2, ns) {
524
+ let parser = parsers[ns] ||= document.createElementNS(ns, "template"), content = (parser.innerHTML = html2, parser.content || parser);
525
+ return content.firstChild || content.appendChild(new Text()), content;
538
526
  }
539
527
 
540
528
  // src/dom/dom.ts
@@ -674,11 +662,16 @@ function attrsEvents(scope, nodeAccessor) {
674
662
  on(el, name, events[name]);
675
663
  }
676
664
  function html(scope, value2, accessor) {
677
- let firstChild = scope[accessor], lastChild = scope[accessor + "-" /* DynamicPlaceholderLastChild */] || firstChild, newContent = parseHTML(
678
- value2 || value2 === 0 ? value2 + "" : "<!>"
679
- // TODO: is the comment needed
665
+ let firstChild = scope[accessor], parentNode = firstChild.parentNode, lastChild = scope[accessor + "-" /* DynamicPlaceholderLastChild */] || firstChild, newContent = parseHTML(
666
+ value2 || value2 === 0 ? value2 + "" : "",
667
+ parentNode.namespaceURI
680
668
  );
681
- scope[accessor] = newContent.firstChild, scope[accessor + "-" /* DynamicPlaceholderLastChild */] = newContent.lastChild, firstChild.parentNode.insertBefore(newContent, firstChild), removeChildNodes(firstChild, lastChild);
669
+ insertChildNodes(
670
+ parentNode,
671
+ firstChild,
672
+ scope[accessor] = newContent.firstChild,
673
+ scope[accessor + "-" /* DynamicPlaceholderLastChild */] = newContent.lastChild
674
+ ), removeChildNodes(firstChild, lastChild);
682
675
  }
683
676
  function props(scope, nodeIndex, index) {
684
677
  let nextProps = scope[index], prevProps = scope[index + "-"], node = scope[nodeIndex];
@@ -710,6 +703,18 @@ function removeChildNodes(startNode, endNode) {
710
703
  current.remove(), current = next;
711
704
  }
712
705
  }
706
+ function insertChildNodes(parentNode, referenceNode, startNode, endNode) {
707
+ parentNode.insertBefore(toInsertNode(startNode, endNode), referenceNode);
708
+ }
709
+ function toInsertNode(startNode, endNode) {
710
+ if (startNode === endNode) return startNode;
711
+ let parent = new DocumentFragment(), stop = endNode.nextSibling, current = startNode;
712
+ for (; current !== stop; ) {
713
+ let next = current.nextSibling;
714
+ parent.appendChild(current), current = next;
715
+ }
716
+ return parent;
717
+ }
713
718
 
714
719
  // src/dom/scope.ts
715
720
  var pendingScopes = [];
@@ -733,7 +738,7 @@ function destroyBranch(branch) {
733
738
  branch.t?.k?.delete(branch), destroyNestedBranches(branch);
734
739
  }
735
740
  function destroyNestedBranches(branch) {
736
- branch.D = 1, branch.k?.forEach(destroyNestedBranches), branch.E?.forEach((scope) => {
741
+ branch.E = 1, branch.k?.forEach(destroyNestedBranches), branch.F?.forEach((scope) => {
737
742
  for (let id in scope.h)
738
743
  scope.h[id]?.abort();
739
744
  });
@@ -742,11 +747,12 @@ function removeAndDestroyBranch(branch) {
742
747
  destroyBranch(branch), removeChildNodes(branch.a, branch.b);
743
748
  }
744
749
  function insertBranchBefore(branch, parentNode, nextSibling) {
745
- let current = branch.a, stop = branch.b.nextSibling;
746
- for (; current !== stop; ) {
747
- let next = current.nextSibling;
748
- parentNode.insertBefore(current, nextSibling), current = next;
749
- }
750
+ insertChildNodes(
751
+ parentNode,
752
+ nextSibling,
753
+ branch.a,
754
+ branch.b
755
+ );
750
756
  }
751
757
 
752
758
  // src/dom/reconcile.ts
@@ -868,35 +874,35 @@ function walkInternal(walkCodes, scope, currentWalkIndex) {
868
874
  }
869
875
 
870
876
  // src/dom/renderer.ts
871
- function createBranchScopeWithRenderer(renderer, $global, parentScope) {
877
+ function createBranchScopeWithRenderer(renderer, $global, parentScope, parentNode) {
872
878
  let branch = createBranch(
873
879
  $global,
874
880
  renderer.u || parentScope,
875
881
  parentScope
876
882
  );
877
- return initBranch(renderer, branch), branch;
883
+ return initBranch(renderer, branch, parentNode), branch;
878
884
  }
879
- function createBranchScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, parentScope) {
885
+ function createBranchScopeWithTagNameOrRenderer(tagNameOrRenderer, $global, parentScope, parentNode) {
880
886
  if (typeof tagNameOrRenderer != "string")
881
887
  return createBranchScopeWithRenderer(
882
888
  tagNameOrRenderer,
883
889
  $global,
884
- parentScope
890
+ parentScope,
891
+ parentNode
885
892
  );
886
893
  let branch = createBranch($global, parentScope, parentScope);
887
- return branch[0] = branch.a = branch.b = document.createElement(tagNameOrRenderer), branch;
894
+ return branch[0] = branch.a = branch.b = document.createElementNS(
895
+ tagNameOrRenderer === "svg" ? "http://www.w3.org/2000/svg" : tagNameOrRenderer === "math" ? "http://www.w3.org/1998/Math/MathML" : parentNode.namespaceURI,
896
+ tagNameOrRenderer
897
+ ), branch;
888
898
  }
889
899
  function createBranch($global, ownerScope, parentScope) {
890
900
  let branch = createScope($global), parentBranch = parentScope.c;
891
901
  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;
892
902
  }
893
- function initBranch(renderer, branch) {
894
- let dom = renderer.l();
895
- return walk(
896
- dom.nodeType === 11 /* DocumentFragment */ ? dom.firstChild : dom,
897
- renderer.F,
898
- branch
899
- ), 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;
903
+ function initBranch(renderer, branch, parentNode) {
904
+ let clone = renderer.l(parentNode.namespaceURI), cloneParent = clone.parentNode;
905
+ walk(cloneParent?.firstChild || clone, renderer.G, branch), branch.a = cloneParent?.firstChild || clone, branch.b = cloneParent?.lastChild || clone, renderer.x && queueRender(branch, renderer.x);
900
906
  }
901
907
  function dynamicTagAttrs(nodeAccessor, getContent, inputIsArgs) {
902
908
  return (scope, attrsOrOp) => {
@@ -927,12 +933,12 @@ function createRendererWithOwner(template, rawWalks, setup, getArgs) {
927
933
  let args, id = {}, walks = rawWalks ? /* @__PURE__ */ trimWalkString(rawWalks) : " ";
928
934
  return (owner) => ({
929
935
  j: id,
930
- G: template,
931
- F: walks,
936
+ y: template,
937
+ G: walks,
932
938
  x: setup,
933
939
  l: _clone,
934
940
  u: owner,
935
- H: void 0,
941
+ J: void 0,
936
942
  get d() {
937
943
  return args ||= getArgs?.();
938
944
  }
@@ -941,10 +947,16 @@ function createRendererWithOwner(template, rawWalks, setup, getArgs) {
941
947
  function createRenderer(template, walks, setup, getArgs) {
942
948
  return createRendererWithOwner(template, walks, setup, getArgs)();
943
949
  }
944
- function _clone() {
945
- return (this.H ||= parseHTMLOrSingleNode(
946
- this.G
947
- )).cloneNode(!0);
950
+ function _clone(ns) {
951
+ return ((cloneCache[ns] ||= {})[this.y] ||= createCloneableHTML(
952
+ this.y,
953
+ ns
954
+ ))();
955
+ }
956
+ var cloneCache = {};
957
+ function createCloneableHTML(html2, ns) {
958
+ let { firstChild, lastChild } = parseHTML(html2, ns), parent = document.createElementNS(ns, "t");
959
+ return insertChildNodes(parent, null, firstChild, lastChild), firstChild === lastChild && firstChild.nodeType < 8 /* Comment */ ? () => firstChild.cloneNode(!0) : () => parent.cloneNode(!0).firstChild;
948
960
  }
949
961
 
950
962
  // src/dom/control-flow.ts
@@ -964,7 +976,12 @@ var conditional = function(nodeAccessor, fn, getIntersection) {
964
976
  };
965
977
  };
966
978
  function setConditionalRenderer(scope, nodeAccessor, newRenderer) {
967
- let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyBranch(scope[nodeAccessor]), newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : getEmptyBranch(scope[nodeAccessor]);
979
+ let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */] || getEmptyBranch(scope[nodeAccessor]), newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(
980
+ newRenderer,
981
+ scope.$global,
982
+ scope,
983
+ prevBranch.b.parentNode
984
+ ) : getEmptyBranch(scope[nodeAccessor]);
968
985
  insertBranchBefore(
969
986
  newBranch,
970
987
  prevBranch.b.parentNode,
@@ -988,7 +1005,12 @@ var conditionalOnlyChild = function(nodeAccessor, fn, getIntersection) {
988
1005
  };
989
1006
  };
990
1007
  function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
991
- let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor], newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(newRenderer, scope.$global, scope) : void 0;
1008
+ let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor], newBranch = newRenderer ? createBranchScopeWithTagNameOrRenderer(
1009
+ newRenderer,
1010
+ scope.$global,
1011
+ scope,
1012
+ referenceNode
1013
+ ) : void 0;
992
1014
  referenceNode.textContent = "", newBranch && insertBranchBefore(newBranch, referenceNode, null), prevBranch && destroyBranch(prevBranch), scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
993
1015
  }
994
1016
  var emptyMarkerMap = /* @__PURE__ */ new Map([
@@ -1033,20 +1055,16 @@ function loop(nodeAccessor, renderer, forEach) {
1033
1055
  params?.(branch, valueOrOp);
1034
1056
  return;
1035
1057
  }
1036
- 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;
1037
- if (forEach(valueOrOp, (key, args) => {
1058
+ 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;
1059
+ forEach(valueOrOp, (key, args) => {
1038
1060
  let branch = oldMap.get(key);
1039
- 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]);
1040
- }), newMap || (referenceIsMarker ? (newMap = emptyMarkerMap, newArray = emptyMarkerArray, getEmptyBranch(referenceNode)) : (oldArray.forEach(destroyBranch), referenceNode.textContent = "", newMap = emptyMap, newArray = emptyArray, needsReconciliation = !1)), needsReconciliation) {
1041
- if (referenceIsMarker) {
1042
- oldMap === emptyMarkerMap && getEmptyBranch(referenceNode);
1043
- let oldLastChild = oldArray[oldArray.length - 1];
1044
- afterReference = oldLastChild.b.nextSibling, parentNode = oldLastChild.a.parentNode;
1045
- } else
1046
- afterReference = null, parentNode = referenceNode;
1047
- reconcile(parentNode, oldArray, newArray, afterReference);
1048
- }
1049
- scope[nodeAccessor + "(" /* LoopScopeMap */] = newMap, scope[nodeAccessor + "!" /* LoopScopeArray */] = newArray;
1061
+ branch || (branch = createBranchScopeWithRenderer(
1062
+ renderer,
1063
+ scope.$global,
1064
+ scope,
1065
+ parentNode
1066
+ )), params && params(branch, args), newMap ? (newMap.set(key, branch), newArray.push(branch)) : (newMap = /* @__PURE__ */ new Map([[key, branch]]), newArray = [branch]);
1067
+ }), 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;
1050
1068
  };
1051
1069
  }
1052
1070
  function bySecondArg(_item, index) {
@@ -1122,7 +1140,7 @@ function dynamicClosure(fn, getOwnerScope = defaultGetOwnerScope, getIntersectio
1122
1140
  getOwnerScope(scope)[ownerSubscribersAccessor].delete(scope);
1123
1141
  });
1124
1142
  };
1125
- return helperSignal._ = setupSignal, helperSignal.C = subscribe, helperSignal;
1143
+ return helperSignal._ = setupSignal, helperSignal.D = subscribe, helperSignal;
1126
1144
  }
1127
1145
  function setTagVar(scope, childAccessor, tagVarSignal2) {
1128
1146
  scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
@@ -1164,9 +1182,9 @@ function queueSource(scope, signal, value2) {
1164
1182
  function queueRender(scope, signal, value2) {
1165
1183
  let i = pendingRenders.length, render = {
1166
1184
  m: scope,
1167
- I: signal,
1168
- J: value2,
1169
- y: i
1185
+ H: signal,
1186
+ I: value2,
1187
+ z: i
1170
1188
  };
1171
1189
  for (pendingRenders.push(render); i; ) {
1172
1190
  let parentIndex = i - 1 >> 1, parent = pendingRenders[parentIndex];
@@ -1219,12 +1237,12 @@ function runRenders() {
1219
1237
  }
1220
1238
  pendingRenders[i] = item;
1221
1239
  }
1222
- render.m.c?.D || render.I(render.m, render.J);
1240
+ render.m.c?.E || render.H(render.m, render.I);
1223
1241
  }
1224
1242
  finishPendingScopes();
1225
1243
  }
1226
1244
  function comparePendingRenders(a, b) {
1227
- return getBranchDepth(a) - getBranchDepth(b) || a.y - b.y;
1245
+ return getBranchDepth(a) - getBranchDepth(b) || a.z - b.z;
1228
1246
  }
1229
1247
  function getBranchDepth(render) {
1230
1248
  return render.m.c?.f || 0;
@@ -1236,7 +1254,7 @@ function resetAbortSignal(scope, id) {
1236
1254
  ctrl && (queueEffect(ctrl, abort), scope.h[id] = void 0);
1237
1255
  }
1238
1256
  function getAbortSignal(scope, id) {
1239
- return scope.c && (scope.c.E ||= /* @__PURE__ */ new Set()).add(scope), ((scope.h ||= {})[id] ||= new AbortController()).signal;
1257
+ return scope.c && (scope.c.F ||= /* @__PURE__ */ new Set()).add(scope), ((scope.h ||= {})[id] ||= new AbortController()).signal;
1240
1258
  }
1241
1259
  function abort(ctrl) {
1242
1260
  ctrl.abort();
@@ -1298,9 +1316,9 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
1298
1316
  normalizedInput[key === "renderBody" ? "content" : key] = input[key];
1299
1317
  }
1300
1318
  if (component.effects = prepareEffects(() => {
1301
- branch ? (applyArgs(branch, MARK), existing = !0) : (branch = component.scope = createScope(out.global), branch._ = renderer.u, initBranch(renderer, branch)), applyArgs(branch, args);
1319
+ branch ? (applyArgs(branch, MARK), existing = !0) : (branch = component.scope = createScope(out.global), branch._ = renderer.u, initBranch(renderer, branch, document.body)), applyArgs(branch, args);
1302
1320
  }), !existing)
1303
- return branch.a === branch.b ? branch.a : branch.a.parentNode;
1321
+ return toInsertNode(branch.a, branch.b);
1304
1322
  }
1305
1323
  };
1306
1324
  function noop() {
@@ -1312,7 +1330,7 @@ var createTemplate = (templateId, ...rendererArgs) => {
1312
1330
  return renderer.mount = mount, renderer._ = renderer, register(templateId, renderer);
1313
1331
  };
1314
1332
  function mount(input = {}, reference, position) {
1315
- let branch, dom, parentNode = reference, nextSibling = null, { $global } = input;
1333
+ let branch, parentNode = reference, nextSibling = null, { $global } = input;
1316
1334
  switch ($global ? ({ $global, ...input } = input, $global = {
1317
1335
  runtimeId: DEFAULT_RUNTIME_ID,
1318
1336
  renderId: DEFAULT_RENDER_ID,
@@ -1332,9 +1350,14 @@ function mount(input = {}, reference, position) {
1332
1350
  break;
1333
1351
  }
1334
1352
  let args = this.d, effects = prepareEffects(() => {
1335
- branch = createScope($global), dom = initBranch(this, branch), args?.(branch, [input]);
1353
+ branch = createScope($global), initBranch(this, branch, parentNode), args?.(branch, [input]);
1336
1354
  });
1337
- return parentNode.insertBefore(dom, nextSibling), runEffects(effects), {
1355
+ return insertChildNodes(
1356
+ parentNode,
1357
+ nextSibling,
1358
+ branch.a,
1359
+ branch.b
1360
+ ), runEffects(effects), {
1338
1361
  update: (newInput) => {
1339
1362
  args && runEffects(
1340
1363
  prepareEffects(() => {