marko 6.0.0-next.3.50 → 6.0.0-next.3.52

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
@@ -43,6 +43,7 @@ __export(dom_exports, {
43
43
  createTemplate: () => createTemplate,
44
44
  data: () => data,
45
45
  dynamicClosure: () => dynamicClosure,
46
+ dynamicClosureRead: () => dynamicClosureRead,
46
47
  dynamicTag: () => dynamicTag,
47
48
  effect: () => effect,
48
49
  forIn: () => forIn,
@@ -66,7 +67,6 @@ __export(dom_exports, {
66
67
  register: () => register,
67
68
  registerBoundSignal: () => registerBoundSignal,
68
69
  registerContent: () => registerContent,
69
- registerDynamicClosure: () => registerDynamicClosure,
70
70
  resetAbortSignal: () => resetAbortSignal,
71
71
  run: () => run,
72
72
  setTagVar: () => setTagVar,
@@ -199,19 +199,19 @@ var DEFAULT_RUNTIME_ID = "M", DEFAULT_RENDER_ID = "_";
199
199
 
200
200
  // src/dom/resume.ts
201
201
  var registeredValues = {}, Render = class {
202
- p = [];
203
- q = {};
204
- B = {
202
+ q = [];
203
+ s = {};
204
+ F = {
205
205
  _: registeredValues
206
206
  };
207
207
  constructor(renders, runtimeId, renderId) {
208
- this.C = renders, this.D = runtimeId, this.s = renderId, this.t = renders[renderId], this.u();
208
+ this.G = renders, this.H = runtimeId, this.t = renderId, this.u = renders[renderId], this.x();
209
209
  }
210
210
  w() {
211
- this.t.w(), this.u();
211
+ this.u.w(), this.x();
212
212
  }
213
- u() {
214
- let data2 = this.t, serializeContext = this.B, scopeLookup = this.q, visits = data2.v, branchIds = /* @__PURE__ */ new Set(), parentBranchIds = /* @__PURE__ */ new Map();
213
+ x() {
214
+ let data2 = this.u, serializeContext = this.F, scopeLookup = this.s, visits = data2.v, branchIds = /* @__PURE__ */ new Set(), parentBranchIds = /* @__PURE__ */ new Map();
215
215
  if (visits.length) {
216
216
  let commentPrefixLen = data2.i.length, closestBranchMarkers = /* @__PURE__ */ new Map(), visitNodes = new Set(visits), lastEndNode;
217
217
  data2.v = [];
@@ -234,7 +234,7 @@ var registeredValues = {}, Render = class {
234
234
  } else if (token === "$" /* ClosestBranch */)
235
235
  closestBranchMarkers.set(scopeId, visit);
236
236
  else if (token === "[" /* BranchStart */)
237
- this.f && (dataIndex && branchEnd(this.f, visit, visit), this.p.push(this.f)), this.f = scopeId, scope.a = visit;
237
+ this.f && (dataIndex && branchEnd(this.f, visit, visit), this.q.push(this.f)), this.f = scopeId, scope.a = visit;
238
238
  else if (token === "]" /* BranchEnd */) {
239
239
  scope[data3] = visit;
240
240
  let curParent = visit.parentNode, startNode = branchEnd(
@@ -242,7 +242,7 @@ var registeredValues = {}, Render = class {
242
242
  visit,
243
243
  visit
244
244
  ).a;
245
- curParent !== startNode.parentNode && curParent.prepend(startNode), this.f = this.p.pop();
245
+ curParent !== startNode.parentNode && curParent.prepend(startNode), this.f = this.q.pop();
246
246
  } else if (token === "|" /* BranchSingleNode */ || token === "=" /* BranchSingleNodeOnlyChildInParent */) {
247
247
  let next = data3.indexOf(" "), curNode = visit;
248
248
  for (scope[~next ? data3.slice(0, next) : data3] = token === "=" /* BranchSingleNodeOnlyChildInParent */ ? visit.parentNode : visit; ~next; ) {
@@ -263,7 +263,7 @@ var registeredValues = {}, Render = class {
263
263
  let resumeData = resumes[i++];
264
264
  if (typeof resumeData == "function") {
265
265
  let scopes = resumeData(serializeContext), { $global } = scopeLookup;
266
- $global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = this.D, $global.renderId = this.s, $global.g = 1e6);
266
+ $global || (scopeLookup.$global = $global = scopes.$ || {}, $global.runtimeId = this.H, $global.renderId = this.t, $global.g = 1e6);
267
267
  for (let scopeId in scopes)
268
268
  if (scopeId !== "$") {
269
269
  let scope = scopes[scopeId], prevScope = scopeLookup[scopeId];
@@ -274,10 +274,10 @@ var registeredValues = {}, Render = class {
274
274
  let parentBranchId = parentBranchIds.get(scopeId);
275
275
  if (parentBranchId && (scope.c = scopes[parentBranchId]), branchIds.has(scopeId)) {
276
276
  let branch = scope, parentBranch = branch.c;
277
- scope.c = branch, parentBranch && (branch.x = parentBranch, (parentBranch.n ||= /* @__PURE__ */ new Set()).add(branch));
277
+ scope.c = branch, parentBranch && (branch.y = parentBranch, (parentBranch.n ||= /* @__PURE__ */ new Set()).add(branch));
278
278
  }
279
279
  }
280
- } else i === len || typeof resumes[i] != "string" ? delete this.C[this.s] : registeredValues[resumes[i++]](
280
+ } else i === len || typeof resumes[i] != "string" ? delete this.G[this.t] : registeredValues[resumes[i++]](
281
281
  scopeLookup[resumeData],
282
282
  scopeLookup[resumeData]
283
283
  );
@@ -729,10 +729,10 @@ function finishPendingScopes() {
729
729
  pendingScopes = [];
730
730
  }
731
731
  function destroyBranch(branch) {
732
- branch.x?.n?.delete(branch), destroyNestedBranches(branch);
732
+ branch.y?.n?.delete(branch), destroyNestedBranches(branch);
733
733
  }
734
734
  function destroyNestedBranches(branch) {
735
- branch.y = 1, branch.n?.forEach(destroyNestedBranches), branch.E?.forEach((scope) => {
735
+ branch.z = 1, branch.n?.forEach(destroyNestedBranches), branch.I?.forEach((scope) => {
736
736
  for (let id in scope.k)
737
737
  scope.k[id]?.abort();
738
738
  });
@@ -754,13 +754,13 @@ var pendingRenders = [], pendingRendersLookup = /* @__PURE__ */ new Map(), pendi
754
754
  function queueRender(scope, signal, signalKey, value2, scopeKey = scope.d) {
755
755
  let key = scopeKey * scopeKeyOffset + signalKey, existingRender = signalKey >= 0 && pendingRendersLookup.get(key);
756
756
  if (existingRender)
757
- existingRender.z = value2;
757
+ existingRender.A = value2;
758
758
  else {
759
759
  let render = {
760
760
  j: key,
761
- A: scope,
762
- F: signal,
763
- z: value2
761
+ B: scope,
762
+ J: signal,
763
+ A: value2
764
764
  }, i = pendingRenders.push(render) - 1;
765
765
  for (; i; ) {
766
766
  let parentIndex = i - 1 >> 1, parent = pendingRenders[parentIndex];
@@ -812,7 +812,7 @@ function runRenders() {
812
812
  }
813
813
  pendingRenders[i] = item;
814
814
  }
815
- render.A.c?.y || render.F(render.A, render.z);
815
+ render.B.c?.z || render.J(render.B, render.A);
816
816
  }
817
817
  finishPendingScopes();
818
818
  }
@@ -823,7 +823,7 @@ function resetAbortSignal(scope, id) {
823
823
  ctrl && (queueEffect(ctrl, abort), scope.k[id] = void 0);
824
824
  }
825
825
  function getAbortSignal(scope, id) {
826
- return scope.c && (scope.c.E ||= /* @__PURE__ */ new Set()).add(scope), ((scope.k ||= {})[id] ||= new AbortController()).signal;
826
+ return scope.c && (scope.c.I ||= /* @__PURE__ */ new Set()).add(scope), ((scope.k ||= {})[id] ||= new AbortController()).signal;
827
827
  }
828
828
  function abort(ctrl) {
829
829
  ctrl.abort();
@@ -947,57 +947,68 @@ function walkInternal(currentWalkIndex, walkCodes, scope) {
947
947
  }
948
948
 
949
949
  // src/dom/renderer.ts
950
- function createBranchWithTagNameOrRenderer($global, tagNameOrRenderer, parentScope, parentNode) {
951
- let branch = createBranch(
952
- $global,
953
- tagNameOrRenderer,
954
- parentScope,
955
- parentNode
956
- );
957
- return typeof tagNameOrRenderer == "string" && (branch[0] = branch.a = branch.b = document.createElementNS(
958
- tagNameOrRenderer === "svg" ? "http://www.w3.org/2000/svg" : tagNameOrRenderer === "math" ? "http://www.w3.org/1998/Math/MathML" : parentNode.namespaceURI,
959
- tagNameOrRenderer
960
- )), branch;
961
- }
962
950
  function createBranch($global, renderer, parentScope, parentNode) {
963
951
  let branch = createScope($global), parentBranch = parentScope?.c;
964
- return branch._ = renderer.l || parentScope, branch.c = branch, parentBranch && (branch.x = parentBranch, (parentBranch.n ||= /* @__PURE__ */ new Set()).add(branch)), renderer.o?.(
952
+ return branch._ = renderer.l || parentScope, branch.c = branch, parentBranch && (branch.y = parentBranch, (parentBranch.n ||= /* @__PURE__ */ new Set()).add(branch)), renderer.o?.(
965
953
  branch,
966
954
  parentNode.namespaceURI
967
955
  ), branch;
968
956
  }
969
- function createContent(id, template, walks, setup, getArgs, dynamicScopesAccessor) {
970
- walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
971
- let args, init2 = template ? (branch, ns) => {
957
+ function createAndSetupBranch($global, renderer, parentScope, parentNode) {
958
+ return setupBranch(
959
+ renderer,
960
+ createBranch($global, renderer, parentScope, parentNode)
961
+ );
962
+ }
963
+ function setupBranch(renderer, branch) {
964
+ return (renderer.p || renderer.C) && queueRender(
965
+ branch,
966
+ (branch2) => {
967
+ renderer.p?.(branch2), renderer.C?.(branch2);
968
+ },
969
+ -1
970
+ ), branch;
971
+ }
972
+ function createContent(id, template, walks, setup, params, closures, dynamicScopesAccessor) {
973
+ walks = walks ? walks.replace(/[^\0-1]+$/, "") : "", setup ||= void 0, params ||= void 0, closures ||= void 0;
974
+ let clone = template ? (branch, ns) => {
972
975
  ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
973
976
  template,
974
977
  ns
975
- ))(branch, walks), setup && queueRender(branch, setup, -1);
978
+ ))(branch, walks);
976
979
  } : (branch) => {
977
980
  walk(
978
981
  branch.a = branch.b = new Text(),
979
982
  walks,
980
983
  branch
981
- ), setup && queueRender(branch, setup, -1);
984
+ );
982
985
  };
983
986
  return (owner) => ({
984
987
  d: id,
985
- o: init2,
988
+ o: clone,
986
989
  l: owner,
987
- m: dynamicScopesAccessor,
988
- get e() {
989
- return args ||= getArgs ? getArgs() : void 0;
990
- }
990
+ p: setup,
991
+ e: params,
992
+ C: closures,
993
+ m: dynamicScopesAccessor
991
994
  });
992
995
  }
993
- function registerContent(id, template, walks, setup, getArgs, dynamicScopesAccessor) {
996
+ function registerContent(id, template, walks, setup, params, closures, dynamicScopesAccessor) {
994
997
  return register(
995
998
  id,
996
- createContent(id, template, walks, setup, getArgs, dynamicScopesAccessor)
999
+ createContent(
1000
+ id,
1001
+ template,
1002
+ walks,
1003
+ setup,
1004
+ params,
1005
+ closures,
1006
+ dynamicScopesAccessor
1007
+ )
997
1008
  );
998
1009
  }
999
- function createRenderer(template, walks, setup, getArgs) {
1000
- return createContent("", template, walks, setup, getArgs)();
1010
+ function createRenderer(template, walks, setup, params, closures) {
1011
+ return createContent("", template, walks, setup, params, closures)();
1001
1012
  }
1002
1013
  var cloneCache = {};
1003
1014
  function createCloneableHTML(html2, ns) {
@@ -1051,7 +1062,6 @@ function value(valueAccessor, fn = () => {
1051
1062
  (!(valueAccessor in scope) || scope[valueAccessor] !== value2) && (scope[valueAccessor] = value2, fn(scope, value2));
1052
1063
  };
1053
1064
  }
1054
- var accessorId = 0;
1055
1065
  function intersection(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__ */ "d") {
1056
1066
  return (scope) => {
1057
1067
  scope.h ? scope[id] === void 0 ? scope[id] = defaultPending : --scope[id] || fn(scope) : queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
@@ -1064,7 +1074,7 @@ function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
1064
1074
  ownerScope,
1065
1075
  () => {
1066
1076
  for (let scope of scopes)
1067
- !scope.h && !scope.y && childSignal(scope);
1077
+ !scope.h && !scope.z && childSignal(scope);
1068
1078
  },
1069
1079
  -1,
1070
1080
  0,
@@ -1087,24 +1097,29 @@ function subscribeToScopeSet(ownerScope, accessor, scope) {
1087
1097
  () => ownerScope[accessor].delete(scope)
1088
1098
  ));
1089
1099
  }
1090
- function dynamicClosure(valueAccessor, fn, getOwnerScope) {
1091
- let subscribersAccessor = "?" /* Dynamic */ + accessorId++, childSignal = closure(valueAccessor, fn, getOwnerScope), ownerSignal = (ownerScope) => {
1092
- let subscribers = ownerScope[subscribersAccessor];
1093
- if (subscribers)
1094
- for (let subscriber of subscribers)
1095
- subscriber.h || queueRender(subscriber, childSignal, -1);
1096
- }, subscribe = ownerSignal.G = (scope) => subscribeToScopeSet(
1097
- getOwnerScope ? getOwnerScope(scope) : scope._,
1098
- subscribersAccessor,
1099
- scope
1100
- );
1101
- return ownerSignal._ = (scope) => {
1102
- childSignal(scope), subscribe(scope);
1103
- }, ownerSignal;
1100
+ function dynamicClosure(...closureSignals) {
1101
+ let [{ D: ___scopeInstancesAccessor, E: ___signalIndexAccessor }] = closureSignals;
1102
+ for (let i = closureSignals.length; i--; )
1103
+ closureSignals[i].K = i;
1104
+ return (scope) => {
1105
+ if (scope[___scopeInstancesAccessor])
1106
+ for (let childScope of scope[___scopeInstancesAccessor])
1107
+ childScope.h || queueRender(
1108
+ childScope,
1109
+ closureSignals[childScope[___signalIndexAccessor]],
1110
+ -1
1111
+ );
1112
+ };
1104
1113
  }
1105
- function registerDynamicClosure(registryId, valueAccessor, fn, getOwnerScope) {
1106
- let signal = dynamicClosure(valueAccessor, fn, getOwnerScope);
1107
- return register(registryId, signal.G), signal;
1114
+ function dynamicClosureRead(valueAccessor, fn, getOwnerScope) {
1115
+ let childSignal = closure(valueAccessor, fn, getOwnerScope), closureSignal = (scope) => {
1116
+ scope[closureSignal.E] = closureSignal.K, childSignal(scope), subscribeToScopeSet(
1117
+ getOwnerScope ? getOwnerScope(scope) : scope._,
1118
+ closureSignal.D,
1119
+ scope
1120
+ );
1121
+ };
1122
+ return closureSignal.D = valueAccessor + "!" /* ClosureScopes */, closureSignal.E = valueAccessor + "(" /* ClosureSignalIndex */, closureSignal;
1108
1123
  }
1109
1124
  function closure(valueAccessor, fn, getOwnerScope) {
1110
1125
  return (scope) => {
@@ -1150,7 +1165,7 @@ function conditional(nodeAccessor, ...branches) {
1150
1165
  scope,
1151
1166
  nodeAccessor,
1152
1167
  branches[scope[branchAccessor] = newBranch],
1153
- createBranch
1168
+ createAndSetupBranch
1154
1169
  );
1155
1170
  };
1156
1171
  }
@@ -1174,7 +1189,7 @@ var dynamicTag = function(nodeAccessor, getContent, getTagVar, inputIsArgs) {
1174
1189
  scope[childScopeAccessor],
1175
1190
  0,
1176
1191
  content,
1177
- createBranch
1192
+ createAndSetupBranch
1178
1193
  ), content.m && subscribeToScopeSet(
1179
1194
  content.l,
1180
1195
  content.m,
@@ -1250,13 +1265,25 @@ function loop(nodeAccessor, renderer, forEach) {
1250
1265
  ...oldMap.values()
1251
1266
  ] : [], parentNode = referenceNode.nodeType > 1 /* Element */ ? referenceNode.parentNode || oldArray[0].a.parentNode : referenceNode, newMap = scope[nodeAccessor + "(" /* LoopScopeMap */] = /* @__PURE__ */ new Map(), newArray = scope[nodeAccessor + "!" /* LoopScopeArray */] = [];
1252
1267
  forEach(value2, (key, args) => {
1253
- let branch = oldMap?.get(key) || createBranch(scope.$global, renderer, scope, parentNode);
1268
+ let branch = oldMap?.get(key) || createAndSetupBranch(scope.$global, renderer, scope, parentNode);
1254
1269
  params?.(branch, args), newMap.set(key, branch), newArray.push(branch);
1255
1270
  });
1256
1271
  let afterReference = null;
1257
1272
  referenceNode !== parentNode && (oldArray.length ? (afterReference = oldArray[oldArray.length - 1].b.nextSibling, newArray.length || parentNode.insertBefore(referenceNode, afterReference)) : newArray.length && (afterReference = referenceNode.nextSibling, referenceNode.remove())), reconcile(parentNode, oldArray, newArray, afterReference);
1258
1273
  };
1259
1274
  }
1275
+ function createBranchWithTagNameOrRenderer($global, tagNameOrRenderer, parentScope, parentNode) {
1276
+ let branch = createBranch(
1277
+ $global,
1278
+ tagNameOrRenderer,
1279
+ parentScope,
1280
+ parentNode
1281
+ );
1282
+ return typeof tagNameOrRenderer == "string" ? branch[0] = branch.a = branch.b = document.createElementNS(
1283
+ tagNameOrRenderer === "svg" ? "http://www.w3.org/2000/svg" : tagNameOrRenderer === "math" ? "http://www.w3.org/1998/Math/MathML" : parentNode.namespaceURI,
1284
+ tagNameOrRenderer
1285
+ ) : setupBranch(tagNameOrRenderer, branch), branch;
1286
+ }
1260
1287
  function bySecondArg(_item, index) {
1261
1288
  return index;
1262
1289
  }
@@ -1297,11 +1324,11 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
1297
1324
  }) {
1298
1325
  return Array.isArray(value2) && typeof value2[0] == "string" ? getRegisteredWithScope(
1299
1326
  value2[0],
1300
- value2.length === 2 && window[runtimeId]?.[componentIdPrefix === "s" ? "_" : componentIdPrefix]?.q[value2[1]]
1327
+ value2.length === 2 && window[runtimeId]?.[componentIdPrefix === "s" ? "_" : componentIdPrefix]?.s[value2[1]]
1301
1328
  ) : value2;
1302
1329
  },
1303
- createRenderer(args, clone) {
1304
- let renderer = createRenderer(0, 0, 0, () => args);
1330
+ createRenderer(params, clone) {
1331
+ let renderer = createRenderer(0, 0, 0, params);
1305
1332
  return renderer.o = (branch) => {
1306
1333
  let cloned = clone();
1307
1334
  branch.a = cloned.startNode, branch.b = cloned.endNode;
@@ -1317,7 +1344,7 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
1317
1344
  normalizedInput[key === "renderBody" ? "content" : key] = input[key];
1318
1345
  }
1319
1346
  if (component.effects = prepareEffects(() => {
1320
- branch ? existing = !0 : (out.global.g ||= 0, branch = component.scope = createBranch(
1347
+ branch ? existing = !0 : (out.global.g ||= 0, branch = component.scope = createAndSetupBranch(
1321
1348
  out.global,
1322
1349
  renderer,
1323
1350
  renderer.l,
@@ -1335,7 +1362,7 @@ var createTemplate = (id, template, walks, setup, inputSignal) => {
1335
1362
  template,
1336
1363
  walks,
1337
1364
  setup,
1338
- inputSignal && (() => inputSignal)
1365
+ inputSignal
1339
1366
  )();
1340
1367
  return renderer.mount = mount, renderer._ = renderer, register(id, renderer);
1341
1368
  };
@@ -1367,7 +1394,7 @@ function mount(input = {}, reference, position) {
1367
1394
  this,
1368
1395
  void 0,
1369
1396
  parentNode
1370
- ), args?.(branch, input);
1397
+ ), this.p?.(branch), args?.(branch, input);
1371
1398
  });
1372
1399
  return insertChildNodes(
1373
1400
  parentNode,