marko 6.0.155 → 6.0.156

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