marko 6.1.3 → 6.1.5

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.
@@ -29,6 +29,7 @@ export declare enum AccessorProp {
29
29
  DetachedAwait = "V",
30
30
  EndNode = "K",
31
31
  Id = "L",
32
+ Load = "X",
32
33
  LoopKey = "M",
33
34
  ParentBranch = "N",
34
35
  PendingEffects = "J",
@@ -62,3 +63,7 @@ export declare enum ClosureSignalProp {
62
63
  SignalIndexAccessor = "b",
63
64
  Index = "c"
64
65
  }
66
+ export declare enum LoadSignalValue {
67
+ Value = "a",
68
+ Signal = "b"
69
+ }
@@ -29,6 +29,7 @@ export declare enum AccessorProp {
29
29
  DetachedAwait = "#DetachedAwait",
30
30
  EndNode = "#EndNode",
31
31
  Id = "#Id",
32
+ Load = "#Load",
32
33
  LoopKey = "#LoopKey",
33
34
  ParentBranch = "#ParentBranch",
34
35
  PendingEffects = "#PendingEffects",
@@ -62,3 +63,7 @@ export declare enum ClosureSignalProp {
62
63
  SignalIndexAccessor = "signalIndexAccessor",
63
64
  Index = "index"
64
65
  }
66
+ export declare enum LoadSignalValue {
67
+ Value = "value",
68
+ Signal = "signal"
69
+ }
@@ -1,3 +1,2 @@
1
- export declare const RENDERER_REGISTER_ID: string;
2
1
  export declare const SET_SCOPE_REGISTER_ID: string;
3
2
  export declare const RENDER_BODY_ID: string;
@@ -1,6 +1,8 @@
1
1
  export type OneMany<T> = T[] | T;
2
- export type Opt<T> = OneMany<T> | undefined;
2
+ export type Opt<T> = OneMany<T> | undefined | null;
3
3
  export declare function toArray<T>(oneMany: OneMany<T>): [T, ...T[]];
4
4
  export declare function toArray<T>(opt: Opt<T>): T[];
5
+ export declare function forEach<T>(opt: Opt<T>, cb: (item: T) => void): void;
5
6
  export declare function push<T>(opt: Opt<T>, item: T): OneMany<T>;
6
7
  export declare function push<T>(oneMany: OneMany<T>, item: T): T[];
8
+ export declare function concat<T>(opt: Opt<T>, other: Opt<T>): Opt<T>;
@@ -37,7 +37,7 @@ export declare enum ResumeSymbol {
37
37
  BranchEndSingleNodeOnlyChildInParent = "}"
38
38
  }
39
39
  export interface AwaitCounter {
40
- m?: () => unknown[];
40
+ m?: (effects: unknown[]) => unknown[];
41
41
  i: number;
42
42
  c: () => void | 1;
43
43
  }
package/dist/debug/dom.js CHANGED
@@ -554,56 +554,73 @@ function createCloneableHTML(html, ns) {
554
554
  //#endregion
555
555
  //#region src/dom/resume.ts
556
556
  const registeredValues = {};
557
- let curRuntimeId;
558
- let readyLookup;
557
+ let curRenders;
559
558
  let branchesEnabled;
560
- let embedEnabled;
559
+ let embedRenders;
560
+ let readyIds;
561
561
  function enableBranches() {
562
562
  if (!branchesEnabled) {
563
563
  branchesEnabled = 1;
564
564
  skipDestroyedRenders();
565
565
  }
566
566
  }
567
- const ready = /* @__PURE__ */ ((_) => (id) => {
568
- const cb = readyLookup[id];
569
- readyLookup[id] = 1;
570
- cb?.();
571
- })(readyLookup = {});
572
- function initEmbedded(readyId, runtimeId) {
573
- embedEnabled = 1;
574
- ready(readyId);
567
+ function ready(readyId, runtimeId) {
568
+ (readyIds ||= /* @__PURE__ */ new Set()).add(readyId);
575
569
  init(runtimeId);
576
- new MutationObserver(() => {
577
- const renders = self[curRuntimeId];
578
- for (const renderId in renders) {
579
- const { s, n } = renders[renderId];
580
- if (n && !n.isConnected) {
581
- delete renders[renderId];
582
- for (const id in s) destroyScope(s[id]);
570
+ for (const renderId in curRenders) runResumeEffects(curRenders[renderId]);
571
+ }
572
+ function initEmbedded(readyId, runtimeId) {
573
+ if (!embedRenders) {
574
+ embedRenders = /* @__PURE__ */ new Map();
575
+ new MutationObserver(() => {
576
+ for (const [anchor, [renderId, scopes]] of embedRenders) if (!anchor.isConnected) {
577
+ embedRenders.delete(anchor);
578
+ delete curRenders[renderId];
579
+ for (const id in scopes) destroyScope(scopes[id]);
583
580
  }
584
- }
585
- }).observe(document.body, {
586
- childList: true,
587
- subtree: true
588
- });
581
+ }).observe(document, {
582
+ childList: true,
583
+ subtree: true
584
+ });
585
+ }
586
+ ready(readyId, runtimeId);
589
587
  }
590
588
  function init(runtimeId = "M") {
591
- if (curRuntimeId) {
592
- if (curRuntimeId !== runtimeId) throw new Error(`Marko initialized multiple times with different $global.runtimeId's of ${JSON.stringify(runtimeId)} and ${JSON.stringify(curRuntimeId)}.`);
589
+ if (curRenders) {
590
+ if (curRenders !== self[runtimeId]) throw new Error(`Marko initialized multiple times with different $global.runtimeId's.`);
593
591
  return;
594
592
  }
595
- curRuntimeId = runtimeId;
596
- let resumeRender;
597
593
  const renders = self[runtimeId];
598
594
  const defineRuntime = (desc) => Object.defineProperty(self, runtimeId, desc);
599
595
  const initRuntime = (renders) => {
600
- defineRuntime({ value: resumeRender = ((renderId) => {
601
- const render = resumeRender[renderId] = renders[renderId] || renders(renderId);
596
+ defineRuntime({ value: curRenders = ((renderId) => {
597
+ const render = curRenders[renderId] = renders[renderId] || renders(renderId);
602
598
  const walk = render.w;
603
- const scopeLookup = render.s = {};
604
- const getScope = (id) => scopeLookup[id] ||= { ["#Id"]: +id };
605
- const serializeContext = { _: registeredValues };
606
- const visitBranches = branchesEnabled && ((branchScopesStack = [], branchStarts = [], orphanBranches = [], curBranchScopes) => {
599
+ const scopeLookup = {};
600
+ const getScope = (id) => scopeLookup[id] || initScope(scopeLookup[id] = { ["#Id"]: +id });
601
+ const initGlobal = () => $global ||= {
602
+ runtimeId,
603
+ renderId
604
+ };
605
+ const initScope = (scope) => {
606
+ scope["$global"] = initGlobal();
607
+ if (branchesEnabled && scope["#ClosestBranchId"]) scope["#ClosestBranch"] = getScope(scope["#ClosestBranchId"]);
608
+ return scope;
609
+ };
610
+ const applyScopes = (partials) => {
611
+ let scopeId = partials[0];
612
+ for (let i = 1; i < partials.length; i++) {
613
+ const partial = partials[i];
614
+ if (typeof partial === "number") scopeId += partial;
615
+ else {
616
+ if (scopeId) initScope(Object.assign(scopeLookup[scopeId] ||= (partial["#Id"] = scopeId, partial), partial));
617
+ else Object.assign(initGlobal(), partial);
618
+ scopeId++;
619
+ }
620
+ }
621
+ };
622
+ const serializeContext = ((data, registryId) => typeof data === "number" ? registryId ? registeredValues[registryId](getScope(data)) : getScope(data) : applyScopes(data));
623
+ const createVisitBranches = (branchScopesStack = [], branchStarts = [], orphanBranches = [], curBranchScopes) => {
607
624
  return (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
608
625
  if (visitType !== "[") {
609
626
  visitScope[nextToken()] = visitType === ")" || visitType === "}" ? parent : visit;
@@ -634,7 +651,7 @@ function init(runtimeId = "M") {
634
651
  nextToken();
635
652
  }
636
653
  if (endedBranches) {
637
- orphanBranches.push(...endedBranches);
654
+ for (const ended of endedBranches) orphanBranches.push(ended);
638
655
  if (singleNode) visitScope[accessor] = endedBranches.length > 1 ? endedBranches.reverse() : endedBranches[0];
639
656
  }
640
657
  if (visitType === "[") {
@@ -645,46 +662,51 @@ function init(runtimeId = "M") {
645
662
  branchStarts.push(visit);
646
663
  }
647
664
  };
648
- })();
665
+ };
649
666
  const nextToken = () => lastToken = visitText.slice(lastTokenIndex, (lastTokenIndex = visitText.indexOf(" ", lastTokenIndex) + 1 || visitText.length + 1) - 1);
667
+ const processResumes = (resumes = [], effects) => {
668
+ let i = 0;
669
+ for (; i < resumes.length; i++) {
670
+ const serialized = resumes[i];
671
+ 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 if (Array.isArray(serialized)) {
677
+ if (!(readyIds && serialized.every((dep) => readyIds.has(dep) && !render.b[dep].length))) break;
678
+ } else if (readyIds && typeof serialized === "number") break;
679
+ else {
680
+ const scopes = serialized(serializeContext);
681
+ if (Array.isArray(scopes)) applyScopes(scopes);
682
+ }
683
+ }
684
+ resumes.splice(0, i);
685
+ return i;
686
+ };
650
687
  let $global;
651
688
  let lastEffect;
652
689
  let visits;
653
- let resumes;
654
690
  let visit;
655
691
  let visitText;
656
692
  let visitType;
657
693
  let visitScope;
658
694
  let lastToken;
659
695
  let lastTokenIndex;
660
- let lastScopeId = 0;
696
+ let visitBranches;
697
+ let embedAnchor;
698
+ serializeContext._ = registeredValues;
661
699
  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.`);
662
- render.m = (effects = []) => {
663
- if (readyLookup) {
664
- for (const readyId in render.b) if (readyLookup[readyId] !== 1) {
665
- readyLookup[readyId] = ((prev) => () => {
666
- runResumeEffects(render);
667
- prev?.();
668
- })(readyLookup[readyId]);
669
- return effects;
700
+ render.m = (effects) => {
701
+ processResumes(render.r, effects);
702
+ if (readyIds && render.b) for (let progress = 1; progress;) {
703
+ progress = 0;
704
+ for (const readyId of readyIds) {
705
+ const resumes = render.b[readyId];
706
+ if (resumes && processResumes(resumes, effects)) progress = 1;
670
707
  }
671
- render.b = 0;
672
- }
673
- for (const serialized of resumes = render.r || []) if (typeof serialized === "string") {
674
- lastTokenIndex = 0;
675
- visitText = serialized;
676
- while (nextToken()) if (/\D/.test(lastToken)) lastEffect = registeredValues[lastToken];
677
- else effects.push(lastEffect, getScope(lastToken));
678
- } else for (const scope of serialized(serializeContext)) if (!$global) {
679
- $global = scope || {};
680
- $global.runtimeId = runtimeId;
681
- $global.renderId = renderId;
682
- } else if (typeof scope === "number") lastScopeId += scope;
683
- else {
684
- scopeLookup[scope["#Id"] = ++lastScopeId] = scope;
685
- scope["$global"] = $global;
686
- if (branchesEnabled) scope["#ClosestBranch"] = getScope(scope["#ClosestBranchId"]);
687
708
  }
709
+ let retained = 0;
688
710
  for (visit of visits = render.v) {
689
711
  lastTokenIndex = render.i.length;
690
712
  visitText = visit.data;
@@ -693,10 +715,11 @@ function init(runtimeId = "M") {
693
715
  if (visitType === "*") {
694
716
  const prev = visit.previousSibling;
695
717
  visitScope[nextToken()] = prev && (prev.nodeType < 8 || prev.data) ? prev : visit.parentNode.insertBefore(new Text(), visit);
696
- } else if (branchesEnabled) visitBranches();
718
+ } else if (branchesEnabled) (visitBranches ||= createVisitBranches())();
719
+ else if (render.b) visits[retained++] = visit;
697
720
  }
698
- if (embedEnabled) render.n ||= visit?.parentNode.insertBefore(new Text(), visit.nextSibling);
699
- visits.length = resumes.length = 0;
721
+ if (embedRenders && !embedAnchor && visit) embedRenders.set(embedAnchor = visit.parentNode.insertBefore(new Text(), visit.nextSibling), [renderId, scopeLookup]);
722
+ visits.length = retained;
700
723
  return effects;
701
724
  };
702
725
  render.w = () => {
@@ -708,7 +731,7 @@ function init(runtimeId = "M") {
708
731
  };
709
732
  if (renders) {
710
733
  initRuntime(renders);
711
- for (const renderId in renders) runResumeEffects(resumeRender(renderId));
734
+ for (const renderId in renders) runResumeEffects(curRenders(renderId));
712
735
  } else defineRuntime({
713
736
  configurable: true,
714
737
  set: initRuntime
@@ -718,7 +741,7 @@ let isResuming;
718
741
  function runResumeEffects(render) {
719
742
  try {
720
743
  isResuming = 1;
721
- runEffects(render.m(), 1);
744
+ runEffects(render.m([]), 1);
722
745
  } finally {
723
746
  isResuming = 0;
724
747
  }
@@ -1187,50 +1210,41 @@ function _await_promise(nodeAccessor, params) {
1187
1210
  _enable_catch();
1188
1211
  return (scope, promise) => {
1189
1212
  let awaitBranch = scope[branchAccessor];
1190
- const tryBranch = findBranchWithKey(scope, "#PlaceholderContent") || awaitBranch;
1213
+ const tryPlaceholder = findBranchWithKey(scope, "#PlaceholderContent");
1214
+ const tryBranch = tryPlaceholder || awaitBranch;
1191
1215
  let awaitCounter = tryBranch["#AwaitCounter"];
1192
- if (!awaitCounter?.i) awaitCounter = tryBranch["#AwaitCounter"] = {
1193
- i: 0,
1194
- c() {
1195
- if (--awaitCounter.i) return 1;
1196
- if (tryBranch === scope[branchAccessor]) {
1197
- if (scope[nodeAccessor].parentNode) scope[nodeAccessor].replaceWith(scope[branchAccessor]["#StartNode"].parentNode);
1198
- } else {
1199
- const placeholderBranch = tryBranch["#PlaceholderBranch"];
1200
- if (placeholderBranch) {
1201
- tryBranch["#PlaceholderBranch"] = 0;
1202
- placeholderBranch["#StartNode"].parentNode.insertBefore(tryBranch["#StartNode"].parentNode, placeholderBranch["#StartNode"]);
1203
- removeAndDestroyBranch(placeholderBranch);
1204
- }
1216
+ placeholderShown.add(pendingEffects);
1217
+ if (tryPlaceholder) {
1218
+ if (!scope[promiseAccessor]) {
1219
+ if (awaitBranch) awaitBranch["#PendingRenders"] ||= [];
1220
+ awaitCounter = addAwaitCounter(scope, tryPlaceholder);
1221
+ }
1222
+ } else {
1223
+ if (!awaitCounter?.i) awaitCounter = tryBranch["#AwaitCounter"] = {
1224
+ i: 0,
1225
+ c() {
1226
+ if (--awaitCounter.i) return 1;
1227
+ if (tryBranch === scope[branchAccessor]) {
1228
+ if (scope[nodeAccessor].parentNode) scope[nodeAccessor].replaceWith(scope[branchAccessor]["#StartNode"].parentNode);
1229
+ } else dismissPlaceholder(tryBranch);
1230
+ queueEffect(tryBranch, runPendingEffects);
1205
1231
  }
1206
- queueEffect(tryBranch, (scope) => {
1207
- const pendingEffects = scope["#PendingEffects"];
1208
- if (pendingEffects) {
1209
- scope["#PendingEffects"] = [];
1210
- runEffects(pendingEffects, 1);
1232
+ };
1233
+ if (!scope[promiseAccessor]) {
1234
+ if (awaitBranch) awaitBranch["#PendingRenders"] ||= [];
1235
+ if (!awaitCounter.i++) requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(scope, () => {
1236
+ if (!awaitBranch["#DetachedAwait"]) {
1237
+ awaitBranch["#StartNode"].parentNode.insertBefore(scope[nodeAccessor], awaitBranch["#StartNode"]);
1238
+ tempDetachBranch(tryBranch);
1211
1239
  }
1212
- });
1240
+ }, -1))));
1213
1241
  }
1214
- };
1215
- placeholderShown.add(pendingEffects);
1216
- if (!scope[promiseAccessor]) {
1217
- if (awaitBranch) awaitBranch["#PendingRenders"] ||= [];
1218
- if (!awaitCounter.i++) requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(tryBranch === awaitBranch ? scope : tryBranch, () => {
1219
- if (tryBranch["#PlaceholderContent"]) {
1220
- insertBranchBefore(tryBranch["#PlaceholderBranch"] = createAndSetupBranch(scope["$global"], tryBranch["#PlaceholderContent"], tryBranch["_"], tryBranch["#StartNode"].parentNode), tryBranch["#StartNode"].parentNode, tryBranch["#StartNode"]);
1221
- tempDetachBranch(tryBranch);
1222
- } else if (!awaitBranch["#DetachedAwait"]) {
1223
- awaitBranch["#StartNode"].parentNode.insertBefore(scope[nodeAccessor], awaitBranch["#StartNode"]);
1224
- tempDetachBranch(tryBranch);
1225
- }
1226
- }, -1))));
1227
1242
  }
1228
1243
  const thisPromise = scope[promiseAccessor] = promise.then((data) => {
1229
1244
  if (thisPromise === scope[promiseAccessor]) {
1230
1245
  const referenceNode = scope[nodeAccessor];
1231
1246
  scope[promiseAccessor] = 0;
1232
- queueMicrotask(run);
1233
- queueRender(scope, () => {
1247
+ queueAsyncRender(scope, () => {
1234
1248
  if ((awaitBranch = scope[branchAccessor])["#DetachedAwait"]) {
1235
1249
  pendingScopes.push(awaitBranch);
1236
1250
  setupBranch(awaitBranch["#DetachedAwait"], awaitBranch);
@@ -1246,7 +1260,7 @@ function _await_promise(nodeAccessor, params) {
1246
1260
  awaitCounter.c();
1247
1261
  if (awaitCounter.m) {
1248
1262
  const fnScopes = /* @__PURE__ */ new Map();
1249
- const effects = awaitCounter.m();
1263
+ const effects = awaitCounter.m([]);
1250
1264
  for (let i = 0; i < pendingEffects.length;) {
1251
1265
  const fn = pendingEffects[i++];
1252
1266
  let scopes = fnScopes.get(fn);
@@ -1259,13 +1273,12 @@ function _await_promise(nodeAccessor, params) {
1259
1273
  if (!fnScopes.get(fn)?.has(scope)) queueEffect(scope, fn);
1260
1274
  }
1261
1275
  }
1262
- }, -1);
1276
+ });
1263
1277
  }
1264
1278
  }, (error) => {
1265
1279
  if (thisPromise === scope[promiseAccessor]) {
1266
1280
  awaitCounter.i = scope[promiseAccessor] = 0;
1267
- schedule();
1268
- queueRender(scope, renderCatch, -1, error);
1281
+ queueAsyncRender(scope, renderCatch, error);
1269
1282
  }
1270
1283
  });
1271
1284
  };
@@ -1278,6 +1291,39 @@ function _await_content(nodeAccessor, template, walks, setup) {
1278
1291
  pendingScopes.pop();
1279
1292
  };
1280
1293
  }
1294
+ function addAwaitCounter(scope, tryBranch = findBranchWithKey(scope, "#PlaceholderContent")) {
1295
+ if (!tryBranch) return;
1296
+ let awaitCounter = tryBranch["#AwaitCounter"];
1297
+ if (!awaitCounter?.i) awaitCounter = tryBranch["#AwaitCounter"] = {
1298
+ i: 0,
1299
+ c() {
1300
+ if (--awaitCounter.i) return 1;
1301
+ dismissPlaceholder(tryBranch);
1302
+ queueEffect(tryBranch, runPendingEffects);
1303
+ }
1304
+ };
1305
+ placeholderShown.add(pendingEffects);
1306
+ if (!awaitCounter.i++) requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(tryBranch, () => {
1307
+ insertBranchBefore(tryBranch["#PlaceholderBranch"] = createAndSetupBranch(tryBranch["$global"], tryBranch["#PlaceholderContent"], tryBranch["_"], tryBranch["#StartNode"].parentNode), tryBranch["#StartNode"].parentNode, tryBranch["#StartNode"]);
1308
+ tempDetachBranch(tryBranch);
1309
+ }, -1))));
1310
+ return awaitCounter;
1311
+ }
1312
+ function runPendingEffects(scope) {
1313
+ const effects = scope["#PendingEffects"];
1314
+ if (effects) {
1315
+ scope["#PendingEffects"] = [];
1316
+ runEffects(effects, 1);
1317
+ }
1318
+ }
1319
+ function dismissPlaceholder(tryBranch) {
1320
+ const placeholderBranch = tryBranch["#PlaceholderBranch"];
1321
+ if (placeholderBranch) {
1322
+ tryBranch["#PlaceholderBranch"] = 0;
1323
+ placeholderBranch["#StartNode"].parentNode.insertBefore(tryBranch["#StartNode"].parentNode, placeholderBranch["#StartNode"]);
1324
+ removeAndDestroyBranch(placeholderBranch);
1325
+ }
1326
+ }
1281
1327
  function _try(nodeAccessor, template, walks, setup) {
1282
1328
  const branchAccessor = "BranchScopes:" + nodeAccessor;
1283
1329
  const renderer = _content("", template, walks, setup)();
@@ -1556,6 +1602,10 @@ function run() {
1556
1602
  }
1557
1603
  runEffects(effects);
1558
1604
  }
1605
+ function queueAsyncRender(scope, signal, value) {
1606
+ queueRender(scope, signal, -1, value);
1607
+ queueMicrotask(run);
1608
+ }
1559
1609
  function prepareEffects(fn) {
1560
1610
  const prevRenders = pendingRenders;
1561
1611
  const prevEffects = pendingEffects;
@@ -1671,23 +1721,33 @@ function abort(ctrl) {
1671
1721
  }
1672
1722
  //#endregion
1673
1723
  //#region src/common/compat-meta.ts
1674
- const RENDERER_REGISTER_ID = "$compat_renderer";
1675
1724
  const SET_SCOPE_REGISTER_ID = "$compat_setScope";
1676
1725
  const RENDER_BODY_ID = "$compat_renderBody";
1677
1726
  //#endregion
1678
1727
  //#region src/dom/compat.ts
1679
1728
  const classIdToBranch = /* @__PURE__ */ new Map();
1729
+ const scopesByRender = /* @__PURE__ */ new WeakMap();
1730
+ const getRenderScopes = ($global) => {
1731
+ const render = self[$global.runtimeId]?.[$global.renderId];
1732
+ let scopes = render && scopesByRender.get(render);
1733
+ if (render && !scopes) scopesByRender.set(render, scopes = {});
1734
+ return scopes;
1735
+ };
1680
1736
  const compat = {
1681
1737
  patchDynamicTag,
1682
1738
  queueEffect,
1683
1739
  init(warp10Noop) {
1684
- _resume(SET_SCOPE_REGISTER_ID, (branch) => {
1685
- classIdToBranch.set(branch.m5c, branch);
1740
+ _resume(SET_SCOPE_REGISTER_ID, (scope) => {
1741
+ getRenderScopes(scope["$global"])[scope["#Id"]] = scope;
1742
+ if (scope.m5c) classIdToBranch.set(scope.m5c, scope);
1686
1743
  });
1687
1744
  _resume(RENDER_BODY_ID, warp10Noop);
1688
1745
  },
1689
- registerRenderer(fn) {
1690
- _resume(RENDERER_REGISTER_ID, fn);
1746
+ getScope($global, scopeId) {
1747
+ return getRenderScopes($global)?.[scopeId];
1748
+ },
1749
+ setRendererId(renderer, id) {
1750
+ renderer["id"] = id;
1691
1751
  },
1692
1752
  isRenderer(renderer) {
1693
1753
  return renderer["clone"];
@@ -1706,7 +1766,7 @@ const compat = {
1706
1766
  if (this.scope) destroyBranch(this.scope);
1707
1767
  },
1708
1768
  resolveRegistered(value, $global) {
1709
- if (Array.isArray(value) && typeof value[0] === "string") return getRegisteredWithScope(value[0], value.length === 2 && self[$global.runtimeId]?.[$global.renderId]?.s[value[1]]);
1769
+ if (Array.isArray(value) && typeof value[0] === "string") return getRegisteredWithScope(value[0], getRenderScopes($global)?.[value[1]]);
1710
1770
  return value;
1711
1771
  },
1712
1772
  createRenderer(params, clone) {
@@ -1812,6 +1872,109 @@ function mount(input = {}, reference, position) {
1812
1872
  };
1813
1873
  }
1814
1874
  //#endregion
1875
+ //#region src/dom/load.ts
1876
+ function _load_template(id, load) {
1877
+ _enable_catch();
1878
+ let pending;
1879
+ const lazyTemplate = _template(id, 0, 0, (branch) => {
1880
+ const awaitCounter = addAwaitCounter(branch);
1881
+ branch["#Load"] ||= /* @__PURE__ */ new Map();
1882
+ (pending ||= load()).then((renderer) => {
1883
+ Object.assign(lazyTemplate, renderer);
1884
+ queueAsyncRender(branch, (branch) => insertLoaded(renderer, branch, branch["#StartNode"], awaitCounter));
1885
+ }, loadFailed(branch, awaitCounter));
1886
+ }, _load_signal(() => (pending ||= load()).then((r) => ({ _: r["params"] }))));
1887
+ return lazyTemplate;
1888
+ }
1889
+ function _load_setup(nodeAccessor, childScopeAccessor, load) {
1890
+ let pending;
1891
+ let renderer;
1892
+ _enable_catch();
1893
+ return (owner) => {
1894
+ const child = owner[childScopeAccessor];
1895
+ if (renderer) insertLoaded(renderer, child, owner[nodeAccessor]);
1896
+ else {
1897
+ const awaitCounter = addAwaitCounter(owner);
1898
+ child["#Load"] ||= /* @__PURE__ */ new Map();
1899
+ (pending ||= load()).then((mod) => {
1900
+ renderer = _content("", ...mod._)();
1901
+ queueAsyncRender(child, (child) => insertLoaded(renderer, child, owner[nodeAccessor], awaitCounter));
1902
+ }, loadFailed(child, awaitCounter));
1903
+ }
1904
+ };
1905
+ }
1906
+ function insertLoaded(renderer, branch, marker, awaitCounter) {
1907
+ const parent = marker.parentNode;
1908
+ branch["#Creating"] = 1;
1909
+ renderer["clone"](branch, parent.namespaceURI);
1910
+ setupBranch(renderer, branch);
1911
+ applyLoad(branch, () => {
1912
+ insertBranchBefore(branch, parent, marker);
1913
+ marker.remove();
1914
+ pendingScopes.push(branch);
1915
+ awaitCounter?.c();
1916
+ });
1917
+ }
1918
+ function loadFailed(scope, awaitCounter) {
1919
+ return (error) => {
1920
+ if (awaitCounter) awaitCounter.i = 0;
1921
+ queueAsyncRender(scope, renderCatch, error);
1922
+ };
1923
+ }
1924
+ function applyLoad(scope, insert) {
1925
+ const values = scope["#Load"];
1926
+ let remaining;
1927
+ scope["#Load"] = 0;
1928
+ if (remaining = values?.size) for (const [promise, entry] of values) promise.then((signal) => {
1929
+ entry["signal"] = signal;
1930
+ if (!--remaining) {
1931
+ scope["#Creating"] = 1;
1932
+ pendingScopes.push(scope);
1933
+ queueAsyncRender(scope, (scope) => {
1934
+ values.forEach((e) => e["signal"]._(scope, e["value"]));
1935
+ insert();
1936
+ });
1937
+ }
1938
+ }, () => 0);
1939
+ else insert();
1940
+ }
1941
+ function _load_signal(load) {
1942
+ let pending;
1943
+ let signal;
1944
+ return (scope, value) => {
1945
+ pending ||= load();
1946
+ if (scope["#Load"] || !("#Load" in scope) && scope["#Creating"]) (scope["#Load"] ||= /* @__PURE__ */ new Map()).set(pending, { ["value"]: value });
1947
+ else if (signal) signal(scope, value);
1948
+ else pending.then((mod) => queueAsyncRender(scope, signal = mod._, value), () => 0);
1949
+ };
1950
+ }
1951
+ function _load_visible_trigger(selector, options) {
1952
+ let pending;
1953
+ let el;
1954
+ 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);
1955
+ }
1956
+ function _load_idle_trigger(options) {
1957
+ let pending;
1958
+ return (load) => () => (pending ||= new Promise((resolve) => (self.requestIdleCallback || resolve)(resolve, options))).then(load);
1959
+ }
1960
+ function _load_event_trigger(event, selector) {
1961
+ let pending;
1962
+ return (load) => () => (pending ||= new Promise((resolve) => getSelectorOrResolve(selector, resolve)?.addEventListener(event, resolve, { once: true }))).then(load);
1963
+ }
1964
+ function _load_media_trigger(query) {
1965
+ let pending;
1966
+ let mql;
1967
+ return (load) => () => (pending ||= new Promise((resolve) => (mql = matchMedia(query)).matches ? resolve() : mql.addEventListener("change", resolve, { once: true }))).then(load);
1968
+ }
1969
+ function _load_race_trigger(...triggers) {
1970
+ const noop = () => Promise.resolve();
1971
+ let pending;
1972
+ return (load) => () => (pending ||= Promise.race(triggers.map((t) => t(noop)()))).then(load);
1973
+ }
1974
+ function getSelectorOrResolve(selector, resolve) {
1975
+ return document.querySelector(selector) || (console.warn(`A lazy load trigger could not find an element matching "${selector}". The module was loaded immediately.`), resolve());
1976
+ }
1977
+ //#endregion
1815
1978
  exports.$signal = $signal;
1816
1979
  exports.$signalReset = $signalReset;
1817
1980
  exports._assert_hoist = _assert_hoist;
@@ -1884,6 +2047,14 @@ exports._if_closure = _if_closure;
1884
2047
  exports._let = _let;
1885
2048
  exports._let_change = _let_change;
1886
2049
  exports._lifecycle = _lifecycle;
2050
+ exports._load_event_trigger = _load_event_trigger;
2051
+ exports._load_idle_trigger = _load_idle_trigger;
2052
+ exports._load_media_trigger = _load_media_trigger;
2053
+ exports._load_race_trigger = _load_race_trigger;
2054
+ exports._load_setup = _load_setup;
2055
+ exports._load_signal = _load_signal;
2056
+ exports._load_template = _load_template;
2057
+ exports._load_visible_trigger = _load_visible_trigger;
1887
2058
  exports._on = _on;
1888
2059
  exports._or = _or;
1889
2060
  exports._resume = _resume;
@@ -1908,4 +2079,5 @@ exports.forTo = forTo;
1908
2079
  exports.forUntil = forUntil;
1909
2080
  exports.init = init;
1910
2081
  exports.initEmbedded = initEmbedded;
2082
+ exports.ready = ready;
1911
2083
  exports.run = run;