marko 6.1.3 → 6.1.4

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.
@@ -552,56 +552,73 @@ function createCloneableHTML(html, ns) {
552
552
  //#endregion
553
553
  //#region src/dom/resume.ts
554
554
  const registeredValues = {};
555
- let curRuntimeId;
556
- let readyLookup;
555
+ let curRenders;
557
556
  let branchesEnabled;
558
- let embedEnabled;
557
+ let embedRenders;
558
+ let readyIds;
559
559
  function enableBranches() {
560
560
  if (!branchesEnabled) {
561
561
  branchesEnabled = 1;
562
562
  skipDestroyedRenders();
563
563
  }
564
564
  }
565
- const ready = /* @__PURE__ */ ((_) => (id) => {
566
- const cb = readyLookup[id];
567
- readyLookup[id] = 1;
568
- cb?.();
569
- })(readyLookup = {});
570
- function initEmbedded(readyId, runtimeId) {
571
- embedEnabled = 1;
572
- ready(readyId);
565
+ function ready(readyId, runtimeId) {
566
+ (readyIds ||= /* @__PURE__ */ new Set()).add(readyId);
573
567
  init(runtimeId);
574
- new MutationObserver(() => {
575
- const renders = self[curRuntimeId];
576
- for (const renderId in renders) {
577
- const { s, n } = renders[renderId];
578
- if (n && !n.isConnected) {
579
- delete renders[renderId];
580
- for (const id in s) destroyScope(s[id]);
568
+ for (const renderId in curRenders) runResumeEffects(curRenders[renderId]);
569
+ }
570
+ function initEmbedded(readyId, runtimeId) {
571
+ if (!embedRenders) {
572
+ embedRenders = /* @__PURE__ */ new Map();
573
+ new MutationObserver(() => {
574
+ for (const [anchor, [renderId, scopes]] of embedRenders) if (!anchor.isConnected) {
575
+ embedRenders.delete(anchor);
576
+ delete curRenders[renderId];
577
+ for (const id in scopes) destroyScope(scopes[id]);
581
578
  }
582
- }
583
- }).observe(document.body, {
584
- childList: true,
585
- subtree: true
586
- });
579
+ }).observe(document, {
580
+ childList: true,
581
+ subtree: true
582
+ });
583
+ }
584
+ ready(readyId, runtimeId);
587
585
  }
588
586
  function init(runtimeId = "M") {
589
- if (curRuntimeId) {
590
- if (curRuntimeId !== runtimeId) throw new Error(`Marko initialized multiple times with different $global.runtimeId's of ${JSON.stringify(runtimeId)} and ${JSON.stringify(curRuntimeId)}.`);
587
+ if (curRenders) {
588
+ if (curRenders !== self[runtimeId]) throw new Error(`Marko initialized multiple times with different $global.runtimeId's.`);
591
589
  return;
592
590
  }
593
- curRuntimeId = runtimeId;
594
- let resumeRender;
595
591
  const renders = self[runtimeId];
596
592
  const defineRuntime = (desc) => Object.defineProperty(self, runtimeId, desc);
597
593
  const initRuntime = (renders) => {
598
- defineRuntime({ value: resumeRender = ((renderId) => {
599
- const render = resumeRender[renderId] = renders[renderId] || renders(renderId);
594
+ defineRuntime({ value: curRenders = ((renderId) => {
595
+ const render = curRenders[renderId] = renders[renderId] || renders(renderId);
600
596
  const walk = render.w;
601
- const scopeLookup = render.s = {};
602
- const getScope = (id) => scopeLookup[id] ||= { ["#Id"]: +id };
603
- const serializeContext = { _: registeredValues };
604
- const visitBranches = branchesEnabled && ((branchScopesStack = [], branchStarts = [], orphanBranches = [], curBranchScopes) => {
597
+ const scopeLookup = {};
598
+ const getScope = (id) => scopeLookup[id] || initScope(scopeLookup[id] = { ["#Id"]: +id });
599
+ const initGlobal = () => $global ||= {
600
+ runtimeId,
601
+ renderId
602
+ };
603
+ const initScope = (scope) => {
604
+ scope["$global"] = initGlobal();
605
+ if (branchesEnabled && scope["#ClosestBranchId"]) scope["#ClosestBranch"] = getScope(scope["#ClosestBranchId"]);
606
+ return scope;
607
+ };
608
+ const applyScopes = (partials) => {
609
+ let scopeId = partials[0];
610
+ for (let i = 1; i < partials.length; i++) {
611
+ const partial = partials[i];
612
+ if (typeof partial === "number") scopeId += partial;
613
+ else {
614
+ if (scopeId) initScope(Object.assign(scopeLookup[scopeId] ||= (partial["#Id"] = scopeId, partial), partial));
615
+ else Object.assign(initGlobal(), partial);
616
+ scopeId++;
617
+ }
618
+ }
619
+ };
620
+ const serializeContext = ((data, registryId) => typeof data === "number" ? registryId ? registeredValues[registryId](getScope(data)) : getScope(data) : applyScopes(data));
621
+ const createVisitBranches = (branchScopesStack = [], branchStarts = [], orphanBranches = [], curBranchScopes) => {
605
622
  return (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
606
623
  if (visitType !== "[") {
607
624
  visitScope[nextToken()] = visitType === ")" || visitType === "}" ? parent : visit;
@@ -632,7 +649,7 @@ function init(runtimeId = "M") {
632
649
  nextToken();
633
650
  }
634
651
  if (endedBranches) {
635
- orphanBranches.push(...endedBranches);
652
+ for (const ended of endedBranches) orphanBranches.push(ended);
636
653
  if (singleNode) visitScope[accessor] = endedBranches.length > 1 ? endedBranches.reverse() : endedBranches[0];
637
654
  }
638
655
  if (visitType === "[") {
@@ -643,46 +660,51 @@ function init(runtimeId = "M") {
643
660
  branchStarts.push(visit);
644
661
  }
645
662
  };
646
- })();
663
+ };
647
664
  const nextToken = () => lastToken = visitText.slice(lastTokenIndex, (lastTokenIndex = visitText.indexOf(" ", lastTokenIndex) + 1 || visitText.length + 1) - 1);
665
+ const processResumes = (resumes = [], effects) => {
666
+ let i = 0;
667
+ for (; i < resumes.length; i++) {
668
+ const serialized = resumes[i];
669
+ if (typeof serialized === "string") {
670
+ lastTokenIndex = 0;
671
+ visitText = serialized;
672
+ while (nextToken()) if (/\D/.test(lastToken)) lastEffect = registeredValues[lastToken];
673
+ else effects.push(lastEffect, getScope(lastToken));
674
+ } else if (Array.isArray(serialized)) {
675
+ if (!(readyIds && serialized.every((dep) => readyIds.has(dep) && !render.b[dep].length))) break;
676
+ } else if (readyIds && typeof serialized === "number") break;
677
+ else {
678
+ const scopes = serialized(serializeContext);
679
+ if (Array.isArray(scopes)) applyScopes(scopes);
680
+ }
681
+ }
682
+ resumes.splice(0, i);
683
+ return i;
684
+ };
648
685
  let $global;
649
686
  let lastEffect;
650
687
  let visits;
651
- let resumes;
652
688
  let visit;
653
689
  let visitText;
654
690
  let visitType;
655
691
  let visitScope;
656
692
  let lastToken;
657
693
  let lastTokenIndex;
658
- let lastScopeId = 0;
694
+ let visitBranches;
695
+ let embedAnchor;
696
+ serializeContext._ = registeredValues;
659
697
  if (render.m) throw new Error(`Marko rendered multiple times with $global.runtimeId as ${JSON.stringify(runtimeId)} and $global.renderId as ${JSON.stringify(renderId)}. Ensure each render into a page has a unique $global.renderId.`);
660
- render.m = (effects = []) => {
661
- if (readyLookup) {
662
- for (const readyId in render.b) if (readyLookup[readyId] !== 1) {
663
- readyLookup[readyId] = ((prev) => () => {
664
- runResumeEffects(render);
665
- prev?.();
666
- })(readyLookup[readyId]);
667
- return effects;
698
+ render.m = (effects) => {
699
+ processResumes(render.r, effects);
700
+ if (readyIds && render.b) for (let progress = 1; progress;) {
701
+ progress = 0;
702
+ for (const readyId of readyIds) {
703
+ const resumes = render.b[readyId];
704
+ if (resumes && processResumes(resumes, effects)) progress = 1;
668
705
  }
669
- render.b = 0;
670
- }
671
- for (const serialized of resumes = render.r || []) if (typeof serialized === "string") {
672
- lastTokenIndex = 0;
673
- visitText = serialized;
674
- while (nextToken()) if (/\D/.test(lastToken)) lastEffect = registeredValues[lastToken];
675
- else effects.push(lastEffect, getScope(lastToken));
676
- } else for (const scope of serialized(serializeContext)) if (!$global) {
677
- $global = scope || {};
678
- $global.runtimeId = runtimeId;
679
- $global.renderId = renderId;
680
- } else if (typeof scope === "number") lastScopeId += scope;
681
- else {
682
- scopeLookup[scope["#Id"] = ++lastScopeId] = scope;
683
- scope["$global"] = $global;
684
- if (branchesEnabled) scope["#ClosestBranch"] = getScope(scope["#ClosestBranchId"]);
685
706
  }
707
+ let retained = 0;
686
708
  for (visit of visits = render.v) {
687
709
  lastTokenIndex = render.i.length;
688
710
  visitText = visit.data;
@@ -691,10 +713,11 @@ function init(runtimeId = "M") {
691
713
  if (visitType === "*") {
692
714
  const prev = visit.previousSibling;
693
715
  visitScope[nextToken()] = prev && (prev.nodeType < 8 || prev.data) ? prev : visit.parentNode.insertBefore(new Text(), visit);
694
- } else if (branchesEnabled) visitBranches();
716
+ } else if (branchesEnabled) (visitBranches ||= createVisitBranches())();
717
+ else if (render.b) visits[retained++] = visit;
695
718
  }
696
- if (embedEnabled) render.n ||= visit?.parentNode.insertBefore(new Text(), visit.nextSibling);
697
- visits.length = resumes.length = 0;
719
+ if (embedRenders && !embedAnchor && visit) embedRenders.set(embedAnchor = visit.parentNode.insertBefore(new Text(), visit.nextSibling), [renderId, scopeLookup]);
720
+ visits.length = retained;
698
721
  return effects;
699
722
  };
700
723
  render.w = () => {
@@ -706,7 +729,7 @@ function init(runtimeId = "M") {
706
729
  };
707
730
  if (renders) {
708
731
  initRuntime(renders);
709
- for (const renderId in renders) runResumeEffects(resumeRender(renderId));
732
+ for (const renderId in renders) runResumeEffects(curRenders(renderId));
710
733
  } else defineRuntime({
711
734
  configurable: true,
712
735
  set: initRuntime
@@ -716,7 +739,7 @@ let isResuming;
716
739
  function runResumeEffects(render) {
717
740
  try {
718
741
  isResuming = 1;
719
- runEffects(render.m(), 1);
742
+ runEffects(render.m([]), 1);
720
743
  } finally {
721
744
  isResuming = 0;
722
745
  }
@@ -1185,50 +1208,41 @@ function _await_promise(nodeAccessor, params) {
1185
1208
  _enable_catch();
1186
1209
  return (scope, promise) => {
1187
1210
  let awaitBranch = scope[branchAccessor];
1188
- const tryBranch = findBranchWithKey(scope, "#PlaceholderContent") || awaitBranch;
1211
+ const tryPlaceholder = findBranchWithKey(scope, "#PlaceholderContent");
1212
+ const tryBranch = tryPlaceholder || awaitBranch;
1189
1213
  let awaitCounter = tryBranch["#AwaitCounter"];
1190
- if (!awaitCounter?.i) awaitCounter = tryBranch["#AwaitCounter"] = {
1191
- i: 0,
1192
- c() {
1193
- if (--awaitCounter.i) return 1;
1194
- if (tryBranch === scope[branchAccessor]) {
1195
- if (scope[nodeAccessor].parentNode) scope[nodeAccessor].replaceWith(scope[branchAccessor]["#StartNode"].parentNode);
1196
- } else {
1197
- const placeholderBranch = tryBranch["#PlaceholderBranch"];
1198
- if (placeholderBranch) {
1199
- tryBranch["#PlaceholderBranch"] = 0;
1200
- placeholderBranch["#StartNode"].parentNode.insertBefore(tryBranch["#StartNode"].parentNode, placeholderBranch["#StartNode"]);
1201
- removeAndDestroyBranch(placeholderBranch);
1202
- }
1214
+ placeholderShown.add(pendingEffects);
1215
+ if (tryPlaceholder) {
1216
+ if (!scope[promiseAccessor]) {
1217
+ if (awaitBranch) awaitBranch["#PendingRenders"] ||= [];
1218
+ awaitCounter = addAwaitCounter(scope, tryPlaceholder);
1219
+ }
1220
+ } else {
1221
+ if (!awaitCounter?.i) awaitCounter = tryBranch["#AwaitCounter"] = {
1222
+ i: 0,
1223
+ c() {
1224
+ if (--awaitCounter.i) return 1;
1225
+ if (tryBranch === scope[branchAccessor]) {
1226
+ if (scope[nodeAccessor].parentNode) scope[nodeAccessor].replaceWith(scope[branchAccessor]["#StartNode"].parentNode);
1227
+ } else dismissPlaceholder(tryBranch);
1228
+ queueEffect(tryBranch, runPendingEffects);
1203
1229
  }
1204
- queueEffect(tryBranch, (scope) => {
1205
- const pendingEffects = scope["#PendingEffects"];
1206
- if (pendingEffects) {
1207
- scope["#PendingEffects"] = [];
1208
- runEffects(pendingEffects, 1);
1230
+ };
1231
+ if (!scope[promiseAccessor]) {
1232
+ if (awaitBranch) awaitBranch["#PendingRenders"] ||= [];
1233
+ if (!awaitCounter.i++) requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(scope, () => {
1234
+ if (!awaitBranch["#DetachedAwait"]) {
1235
+ awaitBranch["#StartNode"].parentNode.insertBefore(scope[nodeAccessor], awaitBranch["#StartNode"]);
1236
+ tempDetachBranch(tryBranch);
1209
1237
  }
1210
- });
1238
+ }, -1))));
1211
1239
  }
1212
- };
1213
- placeholderShown.add(pendingEffects);
1214
- if (!scope[promiseAccessor]) {
1215
- if (awaitBranch) awaitBranch["#PendingRenders"] ||= [];
1216
- if (!awaitCounter.i++) requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(tryBranch === awaitBranch ? scope : tryBranch, () => {
1217
- if (tryBranch["#PlaceholderContent"]) {
1218
- insertBranchBefore(tryBranch["#PlaceholderBranch"] = createAndSetupBranch(scope["$global"], tryBranch["#PlaceholderContent"], tryBranch["_"], tryBranch["#StartNode"].parentNode), tryBranch["#StartNode"].parentNode, tryBranch["#StartNode"]);
1219
- tempDetachBranch(tryBranch);
1220
- } else if (!awaitBranch["#DetachedAwait"]) {
1221
- awaitBranch["#StartNode"].parentNode.insertBefore(scope[nodeAccessor], awaitBranch["#StartNode"]);
1222
- tempDetachBranch(tryBranch);
1223
- }
1224
- }, -1))));
1225
1240
  }
1226
1241
  const thisPromise = scope[promiseAccessor] = promise.then((data) => {
1227
1242
  if (thisPromise === scope[promiseAccessor]) {
1228
1243
  const referenceNode = scope[nodeAccessor];
1229
1244
  scope[promiseAccessor] = 0;
1230
- queueMicrotask(run);
1231
- queueRender(scope, () => {
1245
+ queueAsyncRender(scope, () => {
1232
1246
  if ((awaitBranch = scope[branchAccessor])["#DetachedAwait"]) {
1233
1247
  pendingScopes.push(awaitBranch);
1234
1248
  setupBranch(awaitBranch["#DetachedAwait"], awaitBranch);
@@ -1244,7 +1258,7 @@ function _await_promise(nodeAccessor, params) {
1244
1258
  awaitCounter.c();
1245
1259
  if (awaitCounter.m) {
1246
1260
  const fnScopes = /* @__PURE__ */ new Map();
1247
- const effects = awaitCounter.m();
1261
+ const effects = awaitCounter.m([]);
1248
1262
  for (let i = 0; i < pendingEffects.length;) {
1249
1263
  const fn = pendingEffects[i++];
1250
1264
  let scopes = fnScopes.get(fn);
@@ -1257,13 +1271,12 @@ function _await_promise(nodeAccessor, params) {
1257
1271
  if (!fnScopes.get(fn)?.has(scope)) queueEffect(scope, fn);
1258
1272
  }
1259
1273
  }
1260
- }, -1);
1274
+ });
1261
1275
  }
1262
1276
  }, (error) => {
1263
1277
  if (thisPromise === scope[promiseAccessor]) {
1264
1278
  awaitCounter.i = scope[promiseAccessor] = 0;
1265
- schedule();
1266
- queueRender(scope, renderCatch, -1, error);
1279
+ queueAsyncRender(scope, renderCatch, error);
1267
1280
  }
1268
1281
  });
1269
1282
  };
@@ -1276,6 +1289,39 @@ function _await_content(nodeAccessor, template, walks, setup) {
1276
1289
  pendingScopes.pop();
1277
1290
  };
1278
1291
  }
1292
+ function addAwaitCounter(scope, tryBranch = findBranchWithKey(scope, "#PlaceholderContent")) {
1293
+ if (!tryBranch) return;
1294
+ let awaitCounter = tryBranch["#AwaitCounter"];
1295
+ if (!awaitCounter?.i) awaitCounter = tryBranch["#AwaitCounter"] = {
1296
+ i: 0,
1297
+ c() {
1298
+ if (--awaitCounter.i) return 1;
1299
+ dismissPlaceholder(tryBranch);
1300
+ queueEffect(tryBranch, runPendingEffects);
1301
+ }
1302
+ };
1303
+ placeholderShown.add(pendingEffects);
1304
+ if (!awaitCounter.i++) requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(tryBranch, () => {
1305
+ insertBranchBefore(tryBranch["#PlaceholderBranch"] = createAndSetupBranch(tryBranch["$global"], tryBranch["#PlaceholderContent"], tryBranch["_"], tryBranch["#StartNode"].parentNode), tryBranch["#StartNode"].parentNode, tryBranch["#StartNode"]);
1306
+ tempDetachBranch(tryBranch);
1307
+ }, -1))));
1308
+ return awaitCounter;
1309
+ }
1310
+ function runPendingEffects(scope) {
1311
+ const effects = scope["#PendingEffects"];
1312
+ if (effects) {
1313
+ scope["#PendingEffects"] = [];
1314
+ runEffects(effects, 1);
1315
+ }
1316
+ }
1317
+ function dismissPlaceholder(tryBranch) {
1318
+ const placeholderBranch = tryBranch["#PlaceholderBranch"];
1319
+ if (placeholderBranch) {
1320
+ tryBranch["#PlaceholderBranch"] = 0;
1321
+ placeholderBranch["#StartNode"].parentNode.insertBefore(tryBranch["#StartNode"].parentNode, placeholderBranch["#StartNode"]);
1322
+ removeAndDestroyBranch(placeholderBranch);
1323
+ }
1324
+ }
1279
1325
  function _try(nodeAccessor, template, walks, setup) {
1280
1326
  const branchAccessor = "BranchScopes:" + nodeAccessor;
1281
1327
  const renderer = _content("", template, walks, setup)();
@@ -1554,6 +1600,10 @@ function run() {
1554
1600
  }
1555
1601
  runEffects(effects);
1556
1602
  }
1603
+ function queueAsyncRender(scope, signal, value) {
1604
+ queueRender(scope, signal, -1, value);
1605
+ queueMicrotask(run);
1606
+ }
1557
1607
  function prepareEffects(fn) {
1558
1608
  const prevRenders = pendingRenders;
1559
1609
  const prevEffects = pendingEffects;
@@ -1669,23 +1719,33 @@ function abort(ctrl) {
1669
1719
  }
1670
1720
  //#endregion
1671
1721
  //#region src/common/compat-meta.ts
1672
- const RENDERER_REGISTER_ID = "$compat_renderer";
1673
1722
  const SET_SCOPE_REGISTER_ID = "$compat_setScope";
1674
1723
  const RENDER_BODY_ID = "$compat_renderBody";
1675
1724
  //#endregion
1676
1725
  //#region src/dom/compat.ts
1677
1726
  const classIdToBranch = /* @__PURE__ */ new Map();
1727
+ const scopesByRender = /* @__PURE__ */ new WeakMap();
1728
+ const getRenderScopes = ($global) => {
1729
+ const render = self[$global.runtimeId]?.[$global.renderId];
1730
+ let scopes = render && scopesByRender.get(render);
1731
+ if (render && !scopes) scopesByRender.set(render, scopes = {});
1732
+ return scopes;
1733
+ };
1678
1734
  const compat = {
1679
1735
  patchDynamicTag,
1680
1736
  queueEffect,
1681
1737
  init(warp10Noop) {
1682
- _resume(SET_SCOPE_REGISTER_ID, (branch) => {
1683
- classIdToBranch.set(branch.m5c, branch);
1738
+ _resume(SET_SCOPE_REGISTER_ID, (scope) => {
1739
+ getRenderScopes(scope["$global"])[scope["#Id"]] = scope;
1740
+ if (scope.m5c) classIdToBranch.set(scope.m5c, scope);
1684
1741
  });
1685
1742
  _resume(RENDER_BODY_ID, warp10Noop);
1686
1743
  },
1687
- registerRenderer(fn) {
1688
- _resume(RENDERER_REGISTER_ID, fn);
1744
+ getScope($global, scopeId) {
1745
+ return getRenderScopes($global)?.[scopeId];
1746
+ },
1747
+ setRendererId(renderer, id) {
1748
+ renderer["id"] = id;
1689
1749
  },
1690
1750
  isRenderer(renderer) {
1691
1751
  return renderer["clone"];
@@ -1704,7 +1764,7 @@ const compat = {
1704
1764
  if (this.scope) destroyBranch(this.scope);
1705
1765
  },
1706
1766
  resolveRegistered(value, $global) {
1707
- if (Array.isArray(value) && typeof value[0] === "string") return getRegisteredWithScope(value[0], value.length === 2 && self[$global.runtimeId]?.[$global.renderId]?.s[value[1]]);
1767
+ if (Array.isArray(value) && typeof value[0] === "string") return getRegisteredWithScope(value[0], getRenderScopes($global)?.[value[1]]);
1708
1768
  return value;
1709
1769
  },
1710
1770
  createRenderer(params, clone) {
@@ -1810,4 +1870,107 @@ function mount(input = {}, reference, position) {
1810
1870
  };
1811
1871
  }
1812
1872
  //#endregion
1813
- export { $signal, $signalReset, _assert_hoist, _assert_init, _attr, _attr_class, _attr_class_item, _attr_class_items, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_details_or_dialog_open_default as _attr_details_open_default, _attr_details_or_dialog_open_default as _attr_dialog_open_default, _attr_details_or_dialog_open_script as _attr_details_open_script, _attr_details_or_dialog_open_script as _attr_dialog_open_script, _attr_input_checked, _attr_input_checkedValue, _attr_input_checkedValue_default, _attr_input_checkedValue_script, _attr_input_checked_default, _attr_input_checked_script, _attr_input_value, _attr_input_value as _attr_textarea_value, _attr_input_value_default, _attr_input_value_default as _attr_textarea_value_default, _attr_input_value_script, _attr_input_value_script as _attr_textarea_value_script, _attr_nonce, _attr_select_value, _attr_select_value_default, _attr_select_value_script, _attr_style, _attr_style_item, _attr_style_items, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_script, _await_content, _await_promise, _call, _child_setup, _closure, _closure_get, _const, _content, _content_closures, _content_resume, _dynamic_tag, _el, _el_read, _enable_catch, _for_closure, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_resume, _html, _id, _if, _if_closure, _let, _let_change, _lifecycle, _on, _or, _resume, _resume_dynamic_tag, _return, _return_change, _script, _template, _text, _text_content, _to_text, _try, _var, _var_change, _var_resume, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, init, initEmbedded, run };
1873
+ //#region src/dom/load.ts
1874
+ function _load_template(id, load) {
1875
+ _enable_catch();
1876
+ let pending;
1877
+ const lazyTemplate = _template(id, 0, 0, (branch) => {
1878
+ const awaitCounter = addAwaitCounter(branch);
1879
+ branch["#Load"] ||= /* @__PURE__ */ new Map();
1880
+ (pending ||= load()).then((renderer) => {
1881
+ Object.assign(lazyTemplate, renderer);
1882
+ queueAsyncRender(branch, (branch) => insertLoaded(renderer, branch, branch["#StartNode"], awaitCounter));
1883
+ }, loadFailed(branch, awaitCounter));
1884
+ }, _load_signal(() => (pending ||= load()).then((r) => ({ _: r["params"] }))));
1885
+ return lazyTemplate;
1886
+ }
1887
+ function _load_setup(nodeAccessor, childScopeAccessor, load) {
1888
+ let pending;
1889
+ let renderer;
1890
+ _enable_catch();
1891
+ return (owner) => {
1892
+ const child = owner[childScopeAccessor];
1893
+ if (renderer) insertLoaded(renderer, child, owner[nodeAccessor]);
1894
+ else {
1895
+ const awaitCounter = addAwaitCounter(owner);
1896
+ child["#Load"] ||= /* @__PURE__ */ new Map();
1897
+ (pending ||= load()).then((mod) => {
1898
+ renderer = _content("", ...mod._)();
1899
+ queueAsyncRender(child, (child) => insertLoaded(renderer, child, owner[nodeAccessor], awaitCounter));
1900
+ }, loadFailed(child, awaitCounter));
1901
+ }
1902
+ };
1903
+ }
1904
+ function insertLoaded(renderer, branch, marker, awaitCounter) {
1905
+ const parent = marker.parentNode;
1906
+ branch["#Creating"] = 1;
1907
+ renderer["clone"](branch, parent.namespaceURI);
1908
+ setupBranch(renderer, branch);
1909
+ applyLoad(branch, () => {
1910
+ insertBranchBefore(branch, parent, marker);
1911
+ marker.remove();
1912
+ pendingScopes.push(branch);
1913
+ awaitCounter?.c();
1914
+ });
1915
+ }
1916
+ function loadFailed(scope, awaitCounter) {
1917
+ return (error) => {
1918
+ if (awaitCounter) awaitCounter.i = 0;
1919
+ queueAsyncRender(scope, renderCatch, error);
1920
+ };
1921
+ }
1922
+ function applyLoad(scope, insert) {
1923
+ const values = scope["#Load"];
1924
+ let remaining;
1925
+ scope["#Load"] = 0;
1926
+ if (remaining = values?.size) for (const [promise, entry] of values) promise.then((signal) => {
1927
+ entry["signal"] = signal;
1928
+ if (!--remaining) {
1929
+ scope["#Creating"] = 1;
1930
+ pendingScopes.push(scope);
1931
+ queueAsyncRender(scope, (scope) => {
1932
+ values.forEach((e) => e["signal"]._(scope, e["value"]));
1933
+ insert();
1934
+ });
1935
+ }
1936
+ }, () => 0);
1937
+ else insert();
1938
+ }
1939
+ function _load_signal(load) {
1940
+ let pending;
1941
+ let signal;
1942
+ return (scope, value) => {
1943
+ pending ||= load();
1944
+ if (scope["#Load"] || !("#Load" in scope) && scope["#Creating"]) (scope["#Load"] ||= /* @__PURE__ */ new Map()).set(pending, { ["value"]: value });
1945
+ else if (signal) signal(scope, value);
1946
+ else pending.then((mod) => queueAsyncRender(scope, signal = mod._, value), () => 0);
1947
+ };
1948
+ }
1949
+ function _load_visible_trigger(selector, options) {
1950
+ let pending;
1951
+ let el;
1952
+ return (load) => () => (pending ||= new Promise((resolve) => (el = getSelectorOrResolve(selector, resolve)) && new IntersectionObserver((entries, io) => entries.some((entry) => entry.isIntersecting) && resolve(io.disconnect()), options).observe(el))).then(load);
1953
+ }
1954
+ function _load_idle_trigger(options) {
1955
+ let pending;
1956
+ return (load) => () => (pending ||= new Promise((resolve) => (self.requestIdleCallback || resolve)(resolve, options))).then(load);
1957
+ }
1958
+ function _load_event_trigger(event, selector) {
1959
+ let pending;
1960
+ return (load) => () => (pending ||= new Promise((resolve) => getSelectorOrResolve(selector, resolve)?.addEventListener(event, resolve, { once: true }))).then(load);
1961
+ }
1962
+ function _load_media_trigger(query) {
1963
+ let pending;
1964
+ let mql;
1965
+ return (load) => () => (pending ||= new Promise((resolve) => (mql = matchMedia(query)).matches ? resolve() : mql.addEventListener("change", resolve, { once: true }))).then(load);
1966
+ }
1967
+ function _load_race_trigger(...triggers) {
1968
+ const noop = () => Promise.resolve();
1969
+ let pending;
1970
+ return (load) => () => (pending ||= Promise.race(triggers.map((t) => t(noop)()))).then(load);
1971
+ }
1972
+ function getSelectorOrResolve(selector, resolve) {
1973
+ return document.querySelector(selector) || (console.warn(`A lazy load trigger could not find an element matching "${selector}". The module was loaded immediately.`), resolve());
1974
+ }
1975
+ //#endregion
1976
+ export { $signal, $signalReset, _assert_hoist, _assert_init, _attr, _attr_class, _attr_class_item, _attr_class_items, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_details_or_dialog_open_default as _attr_details_open_default, _attr_details_or_dialog_open_default as _attr_dialog_open_default, _attr_details_or_dialog_open_script as _attr_details_open_script, _attr_details_or_dialog_open_script as _attr_dialog_open_script, _attr_input_checked, _attr_input_checkedValue, _attr_input_checkedValue_default, _attr_input_checkedValue_script, _attr_input_checked_default, _attr_input_checked_script, _attr_input_value, _attr_input_value as _attr_textarea_value, _attr_input_value_default, _attr_input_value_default as _attr_textarea_value_default, _attr_input_value_script, _attr_input_value_script as _attr_textarea_value_script, _attr_nonce, _attr_select_value, _attr_select_value_default, _attr_select_value_script, _attr_style, _attr_style_item, _attr_style_items, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_script, _await_content, _await_promise, _call, _child_setup, _closure, _closure_get, _const, _content, _content_closures, _content_resume, _dynamic_tag, _el, _el_read, _enable_catch, _for_closure, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_resume, _html, _id, _if, _if_closure, _let, _let_change, _lifecycle, _load_event_trigger, _load_idle_trigger, _load_media_trigger, _load_race_trigger, _load_setup, _load_signal, _load_template, _load_visible_trigger, _on, _or, _resume, _resume_dynamic_tag, _return, _return_change, _script, _template, _text, _text_content, _to_text, _try, _var, _var_change, _var_resume, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, init, initEmbedded, ready, run };