marko 6.1.2 → 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.
Files changed (38) hide show
  1. package/dist/common/accessor.d.ts +5 -0
  2. package/dist/common/accessor.debug.d.ts +5 -0
  3. package/dist/common/compat-meta.d.ts +0 -1
  4. package/dist/common/opt.d.ts +3 -1
  5. package/dist/common/types.d.ts +1 -1
  6. package/dist/debug/dom.js +315 -122
  7. package/dist/debug/dom.mjs +306 -123
  8. package/dist/debug/html.js +922 -712
  9. package/dist/debug/html.mjs +920 -713
  10. package/dist/dom/compat.d.ts +3 -2
  11. package/dist/dom/control-flow.d.ts +2 -1
  12. package/dist/dom/load.d.ts +23 -0
  13. package/dist/dom/queue.d.ts +4 -2
  14. package/dist/dom/resume.d.ts +10 -8
  15. package/dist/dom/signals.d.ts +4 -3
  16. package/dist/dom.d.ts +3 -2
  17. package/dist/dom.js +195 -66
  18. package/dist/dom.mjs +195 -66
  19. package/dist/html/assets.d.ts +47 -0
  20. package/dist/html/compat.d.ts +3 -2
  21. package/dist/html/inlined-runtimes.d.ts +1 -1
  22. package/dist/html/inlined-runtimes.debug.d.ts +1 -1
  23. package/dist/html/serializer.d.ts +14 -9
  24. package/dist/html/writer.d.ts +34 -15
  25. package/dist/html.d.ts +1 -0
  26. package/dist/html.js +502 -345
  27. package/dist/html.mjs +502 -345
  28. package/dist/translator/index.d.ts +1 -0
  29. package/dist/translator/index.js +342 -76
  30. package/dist/translator/interop/index.d.ts +1 -0
  31. package/dist/translator/util/marko-config.d.ts +2 -0
  32. package/dist/translator/util/references.d.ts +1 -5
  33. package/dist/translator/util/runtime.d.ts +1 -0
  34. package/dist/translator/util/tag-name-type.d.ts +2 -0
  35. package/dist/translator/util/walks.d.ts +1 -1
  36. package/dist/translator/visitors/import-declaration.d.ts +10 -1
  37. package/dist/translator/visitors/tag/custom-tag.d.ts +7 -0
  38. package/package.json +2 -2
@@ -261,8 +261,8 @@ function schedule() {
261
261
  }
262
262
  }
263
263
  function flushAndWaitFrame() {
264
- runTask();
265
264
  requestAnimationFrame(triggerMacroTask);
265
+ runTask();
266
266
  }
267
267
  function triggerMacroTask() {
268
268
  if (!channel) {
@@ -282,29 +282,41 @@ function triggerMacroTask() {
282
282
  //#region src/dom/signals.ts
283
283
  function _let(id, fn) {
284
284
  const valueAccessor = id.slice(0, id.lastIndexOf("/"));
285
- const valueChangeAccessor = "TagVariableChange:" + valueAccessor;
286
285
  id = +id.slice(id.lastIndexOf("/") + 1);
287
- return (scope, value, valueChange) => {
286
+ return (scope, value) => {
288
287
  if (rendering) {
289
- if ((scope[valueChangeAccessor] = valueChange) && scope[valueAccessor] !== value || scope["#Creating"]) {
288
+ if (scope["#Creating"]) {
290
289
  scope[valueAccessor] = value;
291
290
  fn?.(scope);
292
291
  }
293
- } else if (scope[valueChangeAccessor]) scope[valueChangeAccessor](value);
294
- else if (scope[valueAccessor] !== (scope[valueAccessor] = value) && fn) {
292
+ } else if ((scope[valueAccessor] !== value || !(valueAccessor in scope)) && (scope[valueAccessor] = value, fn)) {
295
293
  schedule();
296
294
  queueRender(scope, fn, id);
297
295
  }
298
296
  return value;
299
297
  };
300
298
  }
299
+ function _let_change(id, fn) {
300
+ const valueAccessor = id.slice(0, id.lastIndexOf("/"));
301
+ const valueChangeAccessor = "TagVariableChange:" + valueAccessor;
302
+ const base = _let(id, fn);
303
+ return (scope, value, valueChange) => {
304
+ if (rendering) if ((scope[valueChangeAccessor] = valueChange) && (scope[valueAccessor] !== value || !(valueAccessor in scope))) {
305
+ scope[valueAccessor] = value;
306
+ fn?.(scope);
307
+ } else base(scope, value);
308
+ else if (scope[valueChangeAccessor]) scope[valueChangeAccessor](value);
309
+ else base(scope, value);
310
+ return value;
311
+ };
312
+ }
301
313
  function _const(valueAccessor, fn) {
302
- return (scope, value) => {
303
- if (scope["#Creating"] || scope[valueAccessor] !== value) {
314
+ return ((scope, value) => {
315
+ if (scope[valueAccessor] !== value || !(valueAccessor in scope)) {
304
316
  scope[valueAccessor] = value;
305
317
  fn?.(scope);
306
318
  }
307
- };
319
+ });
308
320
  }
309
321
  function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id") {
310
322
  return (scope) => {
@@ -540,53 +552,73 @@ function createCloneableHTML(html, ns) {
540
552
  //#endregion
541
553
  //#region src/dom/resume.ts
542
554
  const registeredValues = {};
543
- let curRuntimeId;
544
- let readyLookup;
555
+ let curRenders;
545
556
  let branchesEnabled;
546
- let embedEnabled;
557
+ let embedRenders;
558
+ let readyIds;
547
559
  function enableBranches() {
548
- branchesEnabled = 1;
560
+ if (!branchesEnabled) {
561
+ branchesEnabled = 1;
562
+ skipDestroyedRenders();
563
+ }
549
564
  }
550
- const ready = /* @__PURE__ */ ((_) => (id) => {
551
- const cb = readyLookup[id];
552
- readyLookup[id] = 1;
553
- cb?.();
554
- })(readyLookup = {});
555
- function initEmbedded(readyId, runtimeId) {
556
- embedEnabled = 1;
557
- ready(readyId);
565
+ function ready(readyId, runtimeId) {
566
+ (readyIds ||= /* @__PURE__ */ new Set()).add(readyId);
558
567
  init(runtimeId);
559
- new MutationObserver(() => {
560
- const renders = self[curRuntimeId];
561
- for (const renderId in renders) {
562
- const { s, n } = renders[renderId];
563
- if (n && !n.isConnected) {
564
- delete renders[renderId];
565
- 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]);
566
578
  }
567
- }
568
- }).observe(document.body, {
569
- childList: true,
570
- subtree: true
571
- });
579
+ }).observe(document, {
580
+ childList: true,
581
+ subtree: true
582
+ });
583
+ }
584
+ ready(readyId, runtimeId);
572
585
  }
573
586
  function init(runtimeId = "M") {
574
- if (curRuntimeId) {
575
- 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.`);
576
589
  return;
577
590
  }
578
- curRuntimeId = runtimeId;
579
- let resumeRender;
580
591
  const renders = self[runtimeId];
581
592
  const defineRuntime = (desc) => Object.defineProperty(self, runtimeId, desc);
582
593
  const initRuntime = (renders) => {
583
- defineRuntime({ value: resumeRender = ((renderId) => {
584
- const render = resumeRender[renderId] = renders[renderId] || renders(renderId);
594
+ defineRuntime({ value: curRenders = ((renderId) => {
595
+ const render = curRenders[renderId] = renders[renderId] || renders(renderId);
585
596
  const walk = render.w;
586
- const scopeLookup = render.s = {};
587
- const getScope = (id) => scopeLookup[id] ||= { ["#Id"]: +id };
588
- const serializeContext = { _: registeredValues };
589
- 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) => {
590
622
  return (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
591
623
  if (visitType !== "[") {
592
624
  visitScope[nextToken()] = visitType === ")" || visitType === "}" ? parent : visit;
@@ -617,7 +649,7 @@ function init(runtimeId = "M") {
617
649
  nextToken();
618
650
  }
619
651
  if (endedBranches) {
620
- orphanBranches.push(...endedBranches);
652
+ for (const ended of endedBranches) orphanBranches.push(ended);
621
653
  if (singleNode) visitScope[accessor] = endedBranches.length > 1 ? endedBranches.reverse() : endedBranches[0];
622
654
  }
623
655
  if (visitType === "[") {
@@ -628,46 +660,51 @@ function init(runtimeId = "M") {
628
660
  branchStarts.push(visit);
629
661
  }
630
662
  };
631
- })();
663
+ };
632
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
+ };
633
685
  let $global;
634
686
  let lastEffect;
635
687
  let visits;
636
- let resumes;
637
688
  let visit;
638
689
  let visitText;
639
690
  let visitType;
640
691
  let visitScope;
641
692
  let lastToken;
642
693
  let lastTokenIndex;
643
- let lastScopeId = 0;
694
+ let visitBranches;
695
+ let embedAnchor;
696
+ serializeContext._ = registeredValues;
644
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.`);
645
- render.m = (effects = []) => {
646
- if (readyLookup) {
647
- for (const readyId in render.b) if (readyLookup[readyId] !== 1) {
648
- readyLookup[readyId] = ((prev) => () => {
649
- runResumeEffects(render);
650
- prev?.();
651
- })(readyLookup[readyId]);
652
- 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;
653
705
  }
654
- render.b = 0;
655
- }
656
- for (const serialized of resumes = render.r || []) if (typeof serialized === "string") {
657
- lastTokenIndex = 0;
658
- visitText = serialized;
659
- while (nextToken()) if (/\D/.test(lastToken)) lastEffect = registeredValues[lastToken];
660
- else effects.push(lastEffect, getScope(lastToken));
661
- } else for (const scope of serialized(serializeContext)) if (!$global) {
662
- $global = scope || {};
663
- $global.runtimeId = runtimeId;
664
- $global.renderId = renderId;
665
- } else if (typeof scope === "number") lastScopeId += scope;
666
- else {
667
- scopeLookup[scope["#Id"] = ++lastScopeId] = scope;
668
- scope["$global"] = $global;
669
- if (branchesEnabled) scope["#ClosestBranch"] = getScope(scope["#ClosestBranchId"]);
670
706
  }
707
+ let retained = 0;
671
708
  for (visit of visits = render.v) {
672
709
  lastTokenIndex = render.i.length;
673
710
  visitText = visit.data;
@@ -676,10 +713,11 @@ function init(runtimeId = "M") {
676
713
  if (visitType === "*") {
677
714
  const prev = visit.previousSibling;
678
715
  visitScope[nextToken()] = prev && (prev.nodeType < 8 || prev.data) ? prev : visit.parentNode.insertBefore(new Text(), visit);
679
- } else if (branchesEnabled) visitBranches();
716
+ } else if (branchesEnabled) (visitBranches ||= createVisitBranches())();
717
+ else if (render.b) visits[retained++] = visit;
680
718
  }
681
- if (embedEnabled) render.n ||= visit?.parentNode.insertBefore(new Text(), visit.nextSibling);
682
- 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;
683
721
  return effects;
684
722
  };
685
723
  render.w = () => {
@@ -691,7 +729,7 @@ function init(runtimeId = "M") {
691
729
  };
692
730
  if (renders) {
693
731
  initRuntime(renders);
694
- for (const renderId in renders) runResumeEffects(resumeRender(renderId));
732
+ for (const renderId in renders) runResumeEffects(curRenders(renderId));
695
733
  } else defineRuntime({
696
734
  configurable: true,
697
735
  set: initRuntime
@@ -701,7 +739,7 @@ let isResuming;
701
739
  function runResumeEffects(render) {
702
740
  try {
703
741
  isResuming = 1;
704
- runEffects(render.m(), 1);
742
+ runEffects(render.m([]), 1);
705
743
  } finally {
706
744
  isResuming = 0;
707
745
  }
@@ -1170,50 +1208,41 @@ function _await_promise(nodeAccessor, params) {
1170
1208
  _enable_catch();
1171
1209
  return (scope, promise) => {
1172
1210
  let awaitBranch = scope[branchAccessor];
1173
- const tryBranch = findBranchWithKey(scope, "#PlaceholderContent") || awaitBranch;
1211
+ const tryPlaceholder = findBranchWithKey(scope, "#PlaceholderContent");
1212
+ const tryBranch = tryPlaceholder || awaitBranch;
1174
1213
  let awaitCounter = tryBranch["#AwaitCounter"];
1175
- if (!awaitCounter?.i) awaitCounter = tryBranch["#AwaitCounter"] = {
1176
- i: 0,
1177
- c() {
1178
- if (--awaitCounter.i) return 1;
1179
- if (tryBranch === scope[branchAccessor]) {
1180
- if (scope[nodeAccessor].parentNode) scope[nodeAccessor].replaceWith(scope[branchAccessor]["#StartNode"].parentNode);
1181
- } else {
1182
- const placeholderBranch = tryBranch["#PlaceholderBranch"];
1183
- if (placeholderBranch) {
1184
- tryBranch["#PlaceholderBranch"] = 0;
1185
- placeholderBranch["#StartNode"].parentNode.insertBefore(tryBranch["#StartNode"].parentNode, placeholderBranch["#StartNode"]);
1186
- removeAndDestroyBranch(placeholderBranch);
1187
- }
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);
1188
1229
  }
1189
- queueEffect(tryBranch, (scope) => {
1190
- const pendingEffects = scope["#PendingEffects"];
1191
- if (pendingEffects) {
1192
- scope["#PendingEffects"] = [];
1193
- 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);
1194
1237
  }
1195
- });
1238
+ }, -1))));
1196
1239
  }
1197
- };
1198
- placeholderShown.add(pendingEffects);
1199
- if (!scope[promiseAccessor]) {
1200
- if (awaitBranch) awaitBranch["#PendingRenders"] ||= [];
1201
- if (!awaitCounter.i++) requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(tryBranch === awaitBranch ? scope : tryBranch, () => {
1202
- if (tryBranch["#PlaceholderContent"]) {
1203
- insertBranchBefore(tryBranch["#PlaceholderBranch"] = createAndSetupBranch(scope["$global"], tryBranch["#PlaceholderContent"], tryBranch["_"], tryBranch["#StartNode"].parentNode), tryBranch["#StartNode"].parentNode, tryBranch["#StartNode"]);
1204
- tempDetachBranch(tryBranch);
1205
- } else if (!awaitBranch["#DetachedAwait"]) {
1206
- awaitBranch["#StartNode"].parentNode.insertBefore(scope[nodeAccessor], awaitBranch["#StartNode"]);
1207
- tempDetachBranch(tryBranch);
1208
- }
1209
- }, -1))));
1210
1240
  }
1211
1241
  const thisPromise = scope[promiseAccessor] = promise.then((data) => {
1212
1242
  if (thisPromise === scope[promiseAccessor]) {
1213
1243
  const referenceNode = scope[nodeAccessor];
1214
1244
  scope[promiseAccessor] = 0;
1215
- queueMicrotask(run);
1216
- queueRender(scope, () => {
1245
+ queueAsyncRender(scope, () => {
1217
1246
  if ((awaitBranch = scope[branchAccessor])["#DetachedAwait"]) {
1218
1247
  pendingScopes.push(awaitBranch);
1219
1248
  setupBranch(awaitBranch["#DetachedAwait"], awaitBranch);
@@ -1229,7 +1258,7 @@ function _await_promise(nodeAccessor, params) {
1229
1258
  awaitCounter.c();
1230
1259
  if (awaitCounter.m) {
1231
1260
  const fnScopes = /* @__PURE__ */ new Map();
1232
- const effects = awaitCounter.m();
1261
+ const effects = awaitCounter.m([]);
1233
1262
  for (let i = 0; i < pendingEffects.length;) {
1234
1263
  const fn = pendingEffects[i++];
1235
1264
  let scopes = fnScopes.get(fn);
@@ -1242,13 +1271,12 @@ function _await_promise(nodeAccessor, params) {
1242
1271
  if (!fnScopes.get(fn)?.has(scope)) queueEffect(scope, fn);
1243
1272
  }
1244
1273
  }
1245
- }, -1);
1274
+ });
1246
1275
  }
1247
1276
  }, (error) => {
1248
1277
  if (thisPromise === scope[promiseAccessor]) {
1249
1278
  awaitCounter.i = scope[promiseAccessor] = 0;
1250
- schedule();
1251
- queueRender(scope, renderCatch, -1, error);
1279
+ queueAsyncRender(scope, renderCatch, error);
1252
1280
  }
1253
1281
  });
1254
1282
  };
@@ -1261,6 +1289,39 @@ function _await_content(nodeAccessor, template, walks, setup) {
1261
1289
  pendingScopes.pop();
1262
1290
  };
1263
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
+ }
1264
1325
  function _try(nodeAccessor, template, walks, setup) {
1265
1326
  const branchAccessor = "BranchScopes:" + nodeAccessor;
1266
1327
  const renderer = _content("", template, walks, setup)();
@@ -1539,6 +1600,10 @@ function run() {
1539
1600
  }
1540
1601
  runEffects(effects);
1541
1602
  }
1603
+ function queueAsyncRender(scope, signal, value) {
1604
+ queueRender(scope, signal, -1, value);
1605
+ queueMicrotask(run);
1606
+ }
1542
1607
  function prepareEffects(fn) {
1543
1608
  const prevRenders = pendingRenders;
1544
1609
  const prevEffects = pendingEffects;
@@ -1583,12 +1648,17 @@ function runRenders() {
1583
1648
  }
1584
1649
  pendingRenders[i] = item;
1585
1650
  }
1586
- if (!render["scope"]["#ClosestBranch"]?.["#Destroyed"]) runRender(render);
1651
+ runRender(render);
1587
1652
  }
1588
1653
  for (const scope of pendingScopes) scope["#Creating"] = 0;
1589
1654
  pendingScopes = [];
1590
1655
  }
1591
1656
  let runRender = (render) => render["signal"](render["scope"], render["value"]);
1657
+ function skipDestroyedRenders() {
1658
+ runRender = ((runRender) => (render) => {
1659
+ if (!render["scope"]["#ClosestBranch"]?.["#Destroyed"]) runRender(render);
1660
+ })(runRender);
1661
+ }
1592
1662
  let catchEnabled;
1593
1663
  function _enable_catch() {
1594
1664
  if (!catchEnabled) {
@@ -1649,23 +1719,33 @@ function abort(ctrl) {
1649
1719
  }
1650
1720
  //#endregion
1651
1721
  //#region src/common/compat-meta.ts
1652
- const RENDERER_REGISTER_ID = "$compat_renderer";
1653
1722
  const SET_SCOPE_REGISTER_ID = "$compat_setScope";
1654
1723
  const RENDER_BODY_ID = "$compat_renderBody";
1655
1724
  //#endregion
1656
1725
  //#region src/dom/compat.ts
1657
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
+ };
1658
1734
  const compat = {
1659
1735
  patchDynamicTag,
1660
1736
  queueEffect,
1661
1737
  init(warp10Noop) {
1662
- _resume(SET_SCOPE_REGISTER_ID, (branch) => {
1663
- 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);
1664
1741
  });
1665
1742
  _resume(RENDER_BODY_ID, warp10Noop);
1666
1743
  },
1667
- registerRenderer(fn) {
1668
- _resume(RENDERER_REGISTER_ID, fn);
1744
+ getScope($global, scopeId) {
1745
+ return getRenderScopes($global)?.[scopeId];
1746
+ },
1747
+ setRendererId(renderer, id) {
1748
+ renderer["id"] = id;
1669
1749
  },
1670
1750
  isRenderer(renderer) {
1671
1751
  return renderer["clone"];
@@ -1684,7 +1764,7 @@ const compat = {
1684
1764
  if (this.scope) destroyBranch(this.scope);
1685
1765
  },
1686
1766
  resolveRegistered(value, $global) {
1687
- 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]]);
1688
1768
  return value;
1689
1769
  },
1690
1770
  createRenderer(params, clone) {
@@ -1790,4 +1870,107 @@ function mount(input = {}, reference, position) {
1790
1870
  };
1791
1871
  }
1792
1872
  //#endregion
1793
- 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, _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 };