marko 6.0.155 → 6.0.157

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
@@ -20,6 +20,7 @@ __export(dom_exports, {
20
20
  $signal: () => $signal,
21
21
  $signalReset: () => $signalReset,
22
22
  _assert_hoist: () => _assert_hoist,
23
+ _assert_init: () => _assert_init,
23
24
  _attr: () => _attr,
24
25
  _attr_class: () => _attr_class,
25
26
  _attr_class_item: () => _attr_class_item,
@@ -105,6 +106,7 @@ __export(dom_exports, {
105
106
  forTo: () => forTo,
106
107
  forUntil: () => forUntil,
107
108
  init: () => init,
109
+ initEmbedded: () => initEmbedded,
108
110
  run: () => run
109
111
  });
110
112
  module.exports = __toCommonJS(dom_exports);
@@ -124,6 +126,9 @@ function* attrTagIterator() {
124
126
  // src/common/errors.ts
125
127
  function _assert_hoist(value) {
126
128
  }
129
+ function _assert_init(scope, accessor) {
130
+ return scope[accessor];
131
+ }
127
132
 
128
133
  // src/common/for.ts
129
134
  function forIn(obj, cb) {
@@ -187,7 +192,7 @@ function normalizeDynamicRenderer(value) {
187
192
  if (value) {
188
193
  if (typeof value == "string") return value;
189
194
  let normalized = value.content || value.default || value;
190
- if (/* @__KEY__ */ "f" in normalized)
195
+ if (/* @__KEY__ */ "g" in normalized)
191
196
  return normalized;
192
197
  }
193
198
  }
@@ -275,10 +280,13 @@ function findBranchWithKey(scope, key) {
275
280
  function destroyBranch(branch) {
276
281
  branch.N?.D?.delete(
277
282
  branch
278
- ), destroyNestedBranches(branch);
283
+ ), destroyNestedScopes(branch);
284
+ }
285
+ function destroyScope(scope) {
286
+ scope.I || (destroyNestedScopes(scope), resetControllers(scope));
279
287
  }
280
- function destroyNestedBranches(branch) {
281
- branch.I = 1, branch.D?.forEach(destroyNestedBranches), branch.B?.forEach(resetControllers);
288
+ function destroyNestedScopes(scope) {
289
+ scope.I = 1, scope.D?.forEach(destroyNestedScopes), scope.B?.forEach(resetControllers);
282
290
  }
283
291
  function resetControllers(scope) {
284
292
  for (let id in scope.A)
@@ -372,9 +380,9 @@ function subscribeToScopeSet(ownerScope, accessor, scope) {
372
380
  ));
373
381
  }
374
382
  function _closure(...closureSignals) {
375
- let [{ l: ___scopeInstancesAccessor, n: ___signalIndexAccessor }] = closureSignals;
383
+ let [{ o: ___scopeInstancesAccessor, q: ___signalIndexAccessor }] = closureSignals;
376
384
  for (let i = closureSignals.length; i--; )
377
- closureSignals[i].t = i;
385
+ closureSignals[i].x = i;
378
386
  return (scope) => {
379
387
  if (scope[___scopeInstancesAccessor])
380
388
  for (let childScope of scope[___scopeInstancesAccessor])
@@ -388,13 +396,13 @@ function _closure(...closureSignals) {
388
396
  function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
389
397
  valueAccessor = decodeAccessor(valueAccessor);
390
398
  let closureSignal = ((scope) => {
391
- scope[closureSignal.n] = closureSignal.t, fn(scope), subscribeToScopeSet(
399
+ scope[closureSignal.q] = closureSignal.x, fn(scope), subscribeToScopeSet(
392
400
  getOwnerScope ? getOwnerScope(scope) : scope._,
393
- closureSignal.l,
401
+ closureSignal.o,
394
402
  scope
395
403
  );
396
404
  });
397
- return closureSignal.l = "B" /* ClosureScopes */ + valueAccessor, closureSignal.n = "C" /* ClosureSignalIndex */ + valueAccessor, resumeId && _resume(resumeId, closureSignal), closureSignal;
405
+ return closureSignal.o = "B" /* ClosureScopes */ + valueAccessor, closureSignal.q = "C" /* ClosureSignalIndex */ + valueAccessor, resumeId && _resume(resumeId, closureSignal), closureSignal;
398
406
  }
399
407
  function _child_setup(setup) {
400
408
  return setup._ = (scope, owner) => {
@@ -486,7 +494,7 @@ function walkInternal(currentWalkIndex, walkCodes, scope) {
486
494
  // src/dom/renderer.ts
487
495
  function createBranch($global, renderer, parentScope, parentNode) {
488
496
  let branch = createScope($global);
489
- return branch._ = renderer.e || parentScope, setParentBranch(branch, parentScope?.F), renderer.j?.(
497
+ return branch._ = renderer.f || parentScope, setParentBranch(branch, parentScope?.F), renderer.k?.(
490
498
  branch,
491
499
  parentNode.namespaceURI
492
500
  ), branch;
@@ -501,7 +509,7 @@ function createAndSetupBranch($global, renderer, parentScope, parentNode) {
501
509
  );
502
510
  }
503
511
  function setupBranch(renderer, branch) {
504
- return renderer.k && queueRender(branch, renderer.k, -1), branch;
512
+ return renderer.l && queueRender(branch, renderer.l, -1), branch;
505
513
  }
506
514
  function _content(id, template, walks, setup, params, dynamicScopesAccessor) {
507
515
  walks = walks ? walks.replace(/[^\0-1]+$/, "") : "", setup = setup ? setup._ || setup : void 0, params ||= void 0;
@@ -518,12 +526,12 @@ function _content(id, template, walks, setup, params, dynamicScopesAccessor) {
518
526
  );
519
527
  };
520
528
  return (owner) => ({
521
- f: id,
522
- j: clone,
523
- e: owner,
524
- k: setup,
525
- b: params,
526
- d: dynamicScopesAccessor
529
+ g: id,
530
+ k: clone,
531
+ f: owner,
532
+ l: setup,
533
+ d: params,
534
+ e: dynamicScopesAccessor
527
535
  });
528
536
  }
529
537
  function _content_resume(id, template, walks, setup, params, dynamicScopesAccessor) {
@@ -538,7 +546,7 @@ function _content_closures(renderer, closureFns) {
538
546
  closureSignals[key] = _const(+key, closureFns[key]);
539
547
  return (owner, closureValues) => {
540
548
  let instance = renderer(owner);
541
- return instance.g = closureSignals, instance.o = closureValues, instance;
549
+ return instance.h = closureSignals, instance.t = closureValues, instance;
542
550
  };
543
551
  }
544
552
  var cloneCache = {};
@@ -557,12 +565,31 @@ function createCloneableHTML(html, ns) {
557
565
  }
558
566
 
559
567
  // src/dom/resume.ts
560
- var registeredValues = {}, branchesEnabled;
568
+ var registeredValues = {}, curRuntimeId, readyLookup, branchesEnabled, embedEnabled;
561
569
  function enableBranches() {
562
570
  branchesEnabled = 1;
563
571
  }
572
+ var ready = /* @__PURE__ */ ((_) => (id) => {
573
+ readyLookup[id]?.(), readyLookup[id] = 1;
574
+ })(readyLookup = {});
575
+ function initEmbedded(readyId, runtimeId) {
576
+ embedEnabled = 1, ready(readyId), init(runtimeId), new MutationObserver(() => {
577
+ let renders = self[curRuntimeId];
578
+ for (let renderId in renders) {
579
+ let { s, n } = renders[renderId];
580
+ if (n && !n.isConnected) {
581
+ delete renders[renderId];
582
+ for (let id in s)
583
+ destroyScope(s[id]);
584
+ }
585
+ }
586
+ }).observe(document.body, { childList: !0, subtree: !0 });
587
+ }
564
588
  function init(runtimeId = "M") {
565
- let renders = self[runtimeId], defineRuntime = (desc) => Object.defineProperty(self, runtimeId, desc), resumeRender, initRuntime = (renders2) => {
589
+ if (curRuntimeId)
590
+ return;
591
+ curRuntimeId = runtimeId;
592
+ let resumeRender, renders = self[runtimeId], defineRuntime = (desc) => Object.defineProperty(self, runtimeId, desc), initRuntime = (renders2) => {
566
593
  defineRuntime({
567
594
  value: resumeRender = ((renderId) => {
568
595
  let render = resumeRender[renderId] = renders2[renderId] || renders2(renderId), walk2 = render.w, scopeLookup = render.s = {}, getScope = (id) => scopeLookup[id] ||= { L: +id }, serializeContext = {
@@ -589,11 +616,19 @@ function init(runtimeId = "M") {
589
616
  );
590
617
  }
591
618
  endedBranches && (orphanBranches.push(...endedBranches), singleNode && (visitScope[accessor] = endedBranches.length > 1 ? endedBranches.reverse() : endedBranches[0])), visitType === "[" /* BranchStart */ && (endedBranches || (branchScopesStack.push(curBranchScopes), curBranchScopes = void 0), branchStarts.push(visit));
592
- })(), $global, lastEffect, visits, resumes, visit, visitText, visitType, visitScope, lastToken, lastTokenIndex, lastScopeId = 0, nextToken = () => lastToken = visitText.slice(
619
+ })(), nextToken = () => lastToken = visitText.slice(
593
620
  lastTokenIndex,
594
621
  (lastTokenIndex = visitText.indexOf(" ", lastTokenIndex) + 1 || visitText.length + 1) - 1
595
- );
622
+ ), $global, lastEffect, visits, resumes, visit, visitText, visitType, visitScope, lastToken, lastTokenIndex, lastScopeId = 0;
596
623
  return render.m = (effects = []) => {
624
+ if (readyLookup) {
625
+ for (let readyId in render.b)
626
+ if (readyLookup[readyId] !== 1)
627
+ return readyLookup[readyId] = /* @__PURE__ */ ((prev) => () => {
628
+ render.m(), prev?.();
629
+ })(readyLookup[readyId]), effects;
630
+ render.b = 0;
631
+ }
597
632
  for (let serialized of resumes = render.r || [])
598
633
  if (typeof serialized == "string")
599
634
  for (lastTokenIndex = 0, visitText = serialized; nextToken(); )
@@ -609,7 +644,10 @@ function init(runtimeId = "M") {
609
644
  )), visitType === "*" /* Node */ ? visitScope[nextToken(
610
645
  /* read accessor */
611
646
  )] = visit.previousSibling : branchesEnabled && visitBranches();
612
- return visits.length = resumes.length = 0, effects;
647
+ return embedEnabled && (render.n ||= visit?.parentNode.insertBefore(
648
+ new Text(),
649
+ visit.nextSibling
650
+ )), visits.length = resumes.length = 0, effects;
613
651
  }, render.w = () => {
614
652
  walk2(), runResumeEffects(render);
615
653
  }, render;
@@ -991,15 +1029,15 @@ function attrsInternal(scope, nodeAccessor, nextAttrs) {
991
1029
  }
992
1030
  function _attr_content(scope, nodeAccessor, value) {
993
1031
  let content = normalizeClientRender(value);
994
- scope["D" /* ConditionalRenderer */ + nodeAccessor] !== (scope["D" /* ConditionalRenderer */ + nodeAccessor] = content?.f) && (setConditionalRenderer(scope, nodeAccessor, content, createAndSetupBranch), content?.d && subscribeToScopeSet(
1032
+ scope["D" /* ConditionalRenderer */ + nodeAccessor] !== (scope["D" /* ConditionalRenderer */ + nodeAccessor] = content?.g) && (setConditionalRenderer(scope, nodeAccessor, content, createAndSetupBranch), content?.e && subscribeToScopeSet(
1033
+ content.f,
995
1034
  content.e,
996
- content.d,
997
1035
  scope["A" /* BranchScopes */ + nodeAccessor]
998
1036
  ));
999
- for (let accessor in content?.g)
1000
- content.g[accessor](
1037
+ for (let accessor in content?.h)
1038
+ content.h[accessor](
1001
1039
  scope["A" /* BranchScopes */ + nodeAccessor],
1002
- content.o[accessor]
1040
+ content.t[accessor]
1003
1041
  );
1004
1042
  }
1005
1043
  function _attrs_script(scope, nodeAccessor) {
@@ -1038,7 +1076,7 @@ function _html(scope, value, accessor) {
1038
1076
  }
1039
1077
  function normalizeClientRender(value) {
1040
1078
  let renderer = normalizeDynamicRenderer(value);
1041
- if (renderer && renderer.f)
1079
+ if (renderer && renderer.g)
1042
1080
  return renderer;
1043
1081
  }
1044
1082
  function normalizeAttrValue(value) {
@@ -1198,7 +1236,7 @@ function renderCatch(scope, error) {
1198
1236
  tryWithCatch.C,
1199
1237
  tryWithCatch.E,
1200
1238
  createAndSetupBranch
1201
- ), tryWithCatch.E.b?.(
1239
+ ), tryWithCatch.E.d?.(
1202
1240
  owner["A" /* BranchScopes */ + tryWithCatch.C],
1203
1241
  [error]
1204
1242
  );
@@ -1234,7 +1272,7 @@ var _dynamic_tag = function(nodeAccessor, getContent, getTagVar, inputIsArgs) {
1234
1272
  let childScopeAccessor = "A" /* BranchScopes */ + nodeAccessor, rendererAccessor = "D" /* ConditionalRenderer */ + nodeAccessor;
1235
1273
  return enableBranches(), (scope, newRenderer, getInput) => {
1236
1274
  let normalizedRenderer = normalizeDynamicRenderer(newRenderer);
1237
- if (scope[rendererAccessor] !== (scope[rendererAccessor] = normalizedRenderer?.f || normalizedRenderer) || getContent && !(normalizedRenderer || scope[childScopeAccessor]))
1275
+ if (scope[rendererAccessor] !== (scope[rendererAccessor] = normalizedRenderer?.g || normalizedRenderer) || getContent && !(normalizedRenderer || scope[childScopeAccessor]))
1238
1276
  if (setConditionalRenderer(
1239
1277
  scope,
1240
1278
  nodeAccessor,
@@ -1248,15 +1286,15 @@ var _dynamic_tag = function(nodeAccessor, getContent, getTagVar, inputIsArgs) {
1248
1286
  "a",
1249
1287
  content,
1250
1288
  createAndSetupBranch
1251
- ), content.d && subscribeToScopeSet(
1289
+ ), content.e && subscribeToScopeSet(
1290
+ content.f,
1252
1291
  content.e,
1253
- content.d,
1254
1292
  scope[childScopeAccessor]["Aa"]
1255
1293
  );
1256
1294
  }
1257
- } else normalizedRenderer?.d && subscribeToScopeSet(
1295
+ } else normalizedRenderer?.e && subscribeToScopeSet(
1296
+ normalizedRenderer.f,
1258
1297
  normalizedRenderer.e,
1259
- normalizedRenderer.d,
1260
1298
  scope[childScopeAccessor]
1261
1299
  );
1262
1300
  if (normalizedRenderer) {
@@ -1268,20 +1306,20 @@ var _dynamic_tag = function(nodeAccessor, getContent, getTagVar, inputIsArgs) {
1268
1306
  (inputIsArgs ? args[0] : args) || {}
1269
1307
  ), (childScope["Ia"] || childScope["Ea"]) && queueEffect(childScope, dynamicTagScript);
1270
1308
  else {
1271
- for (let accessor in normalizedRenderer.g)
1272
- normalizedRenderer.g[accessor](
1309
+ for (let accessor in normalizedRenderer.h)
1310
+ normalizedRenderer.h[accessor](
1273
1311
  childScope,
1274
- normalizedRenderer.o[accessor]
1312
+ normalizedRenderer.t[accessor]
1275
1313
  );
1276
- if (normalizedRenderer.b)
1314
+ if (normalizedRenderer.d)
1277
1315
  if (inputIsArgs)
1278
- normalizedRenderer.b(
1316
+ normalizedRenderer.d(
1279
1317
  childScope,
1280
1318
  normalizedRenderer._ ? args[0] : args
1281
1319
  );
1282
1320
  else {
1283
1321
  let inputWithContent = getContent ? { ...args, content: getContent(scope) } : args || {};
1284
- normalizedRenderer.b(
1322
+ normalizedRenderer.d(
1285
1323
  childScope,
1286
1324
  normalizedRenderer._ ? inputWithContent : [inputWithContent]
1287
1325
  );
@@ -1408,12 +1446,12 @@ function byFirstArg(name) {
1408
1446
  var pendingRenders = [], pendingRendersLookup = /* @__PURE__ */ new Map(), asyncRendersLookup, caughtError = /* @__PURE__ */ new WeakSet(), placeholderShown = /* @__PURE__ */ new WeakSet(), pendingEffects = [], pendingScopes = [], rendering, scopeKeyOffset = 1e3;
1409
1447
  function queueRender(scope, signal, signalKey, value, scopeKey = scope.L) {
1410
1448
  let key = scopeKey * scopeKeyOffset + signalKey, render = signalKey >= 0 && pendingRendersLookup.get(key);
1411
- render ? render.q = value : (queuePendingRender(
1449
+ render ? render.u = value : (queuePendingRender(
1412
1450
  render = {
1413
1451
  a: key,
1414
- h: scope,
1415
- u: signal,
1416
- q: value
1452
+ j: scope,
1453
+ y: signal,
1454
+ u: value
1417
1455
  }
1418
1456
  ), signalKey >= 0 && pendingRendersLookup.set(key, render));
1419
1457
  }
@@ -1466,13 +1504,13 @@ function runRenders() {
1466
1504
  }
1467
1505
  pendingRenders[i] = item;
1468
1506
  }
1469
- render.h.F?.I || runRender(render);
1507
+ render.j.F?.I || runRender(render);
1470
1508
  }
1471
1509
  for (let scope of pendingScopes)
1472
1510
  scope.H = 0;
1473
1511
  pendingScopes = [];
1474
1512
  }
1475
- var runRender = (render) => render.u(render.h, render.q), _enable_catch = () => {
1513
+ var runRender = (render) => render.y(render.j, render.u), _enable_catch = () => {
1476
1514
  _enable_catch = () => {
1477
1515
  }, enableBranches();
1478
1516
  let handlePendingTry = (fn, scope, branch) => {
@@ -1491,7 +1529,7 @@ var runRender = (render) => render.u(render.h, render.q), _enable_catch = () =>
1491
1529
  runEffects2(effects);
1492
1530
  })(runEffects), runRender = /* @__PURE__ */ ((runRender2) => (render) => {
1493
1531
  try {
1494
- let branch = render.h.F;
1532
+ let branch = render.j.F;
1495
1533
  for (; branch; ) {
1496
1534
  if (branch.W)
1497
1535
  return asyncRendersLookup.set(
@@ -1502,7 +1540,7 @@ var runRender = (render) => render.u(render.h, render.q), _enable_catch = () =>
1502
1540
  }
1503
1541
  runRender2(render);
1504
1542
  } catch (error) {
1505
- renderCatch(render.h, error);
1543
+ renderCatch(render.j, error);
1506
1544
  }
1507
1545
  })(runRender);
1508
1546
  };
@@ -1535,7 +1573,7 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
1535
1573
  _resume(RENDERER_REGISTER_ID, fn);
1536
1574
  },
1537
1575
  isRenderer(renderer) {
1538
- return renderer.j;
1576
+ return renderer.k;
1539
1577
  },
1540
1578
  getStartNode(branch) {
1541
1579
  return branch.S;
@@ -1557,7 +1595,7 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
1557
1595
  },
1558
1596
  createRenderer(params, clone) {
1559
1597
  let renderer = _content("", 0, 0, 0, params)();
1560
- return renderer.j = (branch) => {
1598
+ return renderer.k = (branch) => {
1561
1599
  let cloned = clone();
1562
1600
  branch.S = cloned.startNode, branch.K = cloned.endNode;
1563
1601
  }, renderer;
@@ -1573,9 +1611,9 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
1573
1611
  branch || (created = 1, branch = component.scope = createAndSetupBranch(
1574
1612
  out.global,
1575
1613
  renderer,
1576
- renderer.e,
1614
+ renderer.f,
1577
1615
  document.body
1578
- )), renderer.b?.(branch, renderer._ ? args[0] : args);
1616
+ )), renderer.d?.(branch, renderer._ ? args[0] : args);
1579
1617
  }), created)
1580
1618
  return toInsertNode(
1581
1619
  branch.S,
@@ -1615,7 +1653,7 @@ function mount(input = {}, reference, position) {
1615
1653
  parentNode = reference.parentNode, nextSibling = reference.nextSibling;
1616
1654
  break;
1617
1655
  }
1618
- let curValue, args = this.b, effects = prepareEffects(() => {
1656
+ let curValue, args = this.d, effects = prepareEffects(() => {
1619
1657
  branch = createBranch(
1620
1658
  $global,
1621
1659
  this,
@@ -1623,7 +1661,7 @@ function mount(input = {}, reference, position) {
1623
1661
  parentNode
1624
1662
  ), branch.T = (newValue) => {
1625
1663
  curValue = newValue;
1626
- }, this.k?.(branch), args?.(branch, input);
1664
+ }, this.l?.(branch), args?.(branch, input);
1627
1665
  });
1628
1666
  return insertChildNodes(
1629
1667
  parentNode,