@marko/runtime-tags 6.1.11 → 6.1.12

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.
@@ -24,8 +24,7 @@ export declare enum AccessorProp {
24
24
  CatchContent = "E",
25
25
  ClosestBranch = "F",
26
26
  ClosestBranchId = "G",
27
- Creating = "H",
28
- Destroyed = "I",
27
+ Gen = "H",
29
28
  DetachedAwait = "V",
30
29
  EndNode = "K",
31
30
  Id = "L",
@@ -34,6 +33,7 @@ export declare enum AccessorProp {
34
33
  ParentBranch = "N",
35
34
  PendingEffects = "J",
36
35
  PendingRenders = "W",
36
+ PendingScopes = "Y",
37
37
  PlaceholderBranch = "P",
38
38
  PlaceholderContent = "Q",
39
39
  Renderer = "R",
@@ -24,8 +24,7 @@ export declare enum AccessorProp {
24
24
  CatchContent = "#CatchContent",
25
25
  ClosestBranch = "#ClosestBranch",
26
26
  ClosestBranchId = "#ClosestBranchId",
27
- Creating = "#Creating",
28
- Destroyed = "#Destroyed",
27
+ Gen = "#Gen",
29
28
  DetachedAwait = "#DetachedAwait",
30
29
  EndNode = "#EndNode",
31
30
  Id = "#Id",
@@ -34,6 +33,7 @@ export declare enum AccessorProp {
34
33
  ParentBranch = "#ParentBranch",
35
34
  PendingEffects = "#PendingEffects",
36
35
  PendingRenders = "#PendingRenders",
36
+ PendingScopes = "#PendingScopes",
37
37
  PlaceholderBranch = "#PlaceholderBranch",
38
38
  PlaceholderContent = "#PlaceholderContent",
39
39
  Renderer = "#Renderer",
@@ -1,8 +1,6 @@
1
- import { type Scope } from "./types";
2
1
  export declare function _el_read_error(): void;
3
2
  export declare function _hoist_read_error(): void;
4
3
  export declare function _assert_hoist(value: unknown): void;
5
- export declare function _assert_init(scope: Scope, accessor: string): any;
6
4
  export declare function assertExclusiveAttrs(attrs: Record<string, unknown> | undefined, onError?: typeof throwErr): void;
7
5
  export declare function assertValidTagName(tagName: string): void;
8
6
  declare function throwErr(msg: string): void;
@@ -6,7 +6,6 @@ export interface BranchScope extends Scope {
6
6
  [AccessorProp.StartNode]: ChildNode;
7
7
  [AccessorProp.EndNode]: ChildNode;
8
8
  [AccessorProp.ParentBranch]: BranchScope | undefined;
9
- [AccessorProp.Destroyed]: 1 | undefined;
10
9
  [AccessorProp.AbortScopes]: Set<Scope> | undefined;
11
10
  [AccessorProp.BranchScopes]: Set<BranchScope> | undefined;
12
11
  [AccessorProp.Renderer]: ClientRenderer | string;
@@ -15,12 +14,13 @@ export interface BranchScope extends Scope {
15
14
  [AccessorProp.PlaceholderBranch]: BranchScope | undefined | 0;
16
15
  [AccessorProp.PendingRenders]: PendingRender[] | 0 | undefined;
17
16
  [AccessorProp.DetachedAwait]: Renderer | 0 | undefined;
17
+ [AccessorProp.PendingScopes]: Scope[] | void;
18
18
  }
19
19
  export interface Scope {
20
20
  [AccessorProp.Owner]: Scope | undefined;
21
21
  [AccessorProp.Global]: Record<string, unknown>;
22
22
  [AccessorProp.Id]: number;
23
- [AccessorProp.Creating]: 1 | 0 | undefined;
23
+ [AccessorProp.Gen]: number;
24
24
  [AccessorProp.AbortControllers]: Record<string | number, AbortController | void> | undefined;
25
25
  [AccessorProp.ClosestBranch]: BranchScope | undefined;
26
26
  [AccessorProp.ClosestBranchId]: number | undefined;
package/dist/debug/dom.js CHANGED
@@ -31,10 +31,6 @@ function _hoist_read_error() {
31
31
  function _assert_hoist(value) {
32
32
  if (typeof value !== "function") throw new Error(`Hoisted values must be functions, received type "${typeof value}".`);
33
33
  }
34
- function _assert_init(scope, accessor) {
35
- if (scope["#Creating"] || !(accessor in scope)) throw new ReferenceError(`Cannot access '${accessor}' before initialization`);
36
- return scope[accessor];
37
- }
38
34
  function assertExclusiveAttrs(attrs, onError = throwErr) {
39
35
  if (attrs) {
40
36
  let exclusiveAttrs;
@@ -202,16 +198,34 @@ function parseHTML(html, ns) {
202
198
  //#endregion
203
199
  //#region src/dom/scope.ts
204
200
  let nextScopeId = 1e6;
201
+ let collectingScopes;
205
202
  function createScope($global, closestBranch) {
206
203
  const scope = {
207
204
  ["#Id"]: nextScopeId++,
208
- ["#Creating"]: 1,
205
+ ["#Gen"]: runId,
209
206
  ["#ClosestBranch"]: closestBranch,
210
207
  ["$global"]: $global
211
208
  };
212
- pendingScopes.push(scope);
209
+ collectingScopes?.push(scope);
213
210
  return scope;
214
211
  }
212
+ function syncGen(scope) {
213
+ scope["#Gen"] = runId;
214
+ }
215
+ function _assert_init(scope, accessor) {
216
+ if (scope["#Gen"] === runId || !(accessor in scope)) throw new ReferenceError(`Cannot access '${accessor}' before initialization`);
217
+ return scope[accessor];
218
+ }
219
+ function collectScopes(fn) {
220
+ const prev = collectingScopes;
221
+ collectingScopes = [];
222
+ try {
223
+ fn();
224
+ return collectingScopes;
225
+ } finally {
226
+ collectingScopes = prev;
227
+ }
228
+ }
215
229
  function skipScope() {
216
230
  return nextScopeId++;
217
231
  }
@@ -225,13 +239,13 @@ function destroyBranch(branch) {
225
239
  destroyNestedScopes(branch);
226
240
  }
227
241
  function destroyScope(scope) {
228
- if (!scope["#Destroyed"]) {
242
+ if (scope["#Gen"]) {
229
243
  destroyNestedScopes(scope);
230
244
  resetControllers(scope);
231
245
  }
232
246
  }
233
247
  const destroyNestedScopes = function destroyNestedScopes(scope) {
234
- scope["#Destroyed"] = 1;
248
+ scope["#Gen"] = 0;
235
249
  scope["#BranchScopes"]?.forEach(destroyNestedScopes);
236
250
  scope["#AbortScopes"]?.forEach(resetControllers);
237
251
  };
@@ -290,7 +304,7 @@ function _let(id, fn) {
290
304
  id = +id.slice(id.lastIndexOf("/") + 1);
291
305
  return (scope, value) => {
292
306
  if (rendering) {
293
- if (scope["#Creating"]) {
307
+ if (scope["#Gen"] === runId) {
294
308
  scope[valueAccessor] = value;
295
309
  fn?.(scope);
296
310
  }
@@ -325,7 +339,7 @@ function _const(valueAccessor, fn) {
325
339
  }
326
340
  function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id") {
327
341
  return (scope) => {
328
- if (scope["#Creating"]) if (id in scope) {
342
+ if (scope["#Gen"] === runId) if (id in scope) {
329
343
  if (!--scope[id]) fn(scope);
330
344
  } else scope[id] = defaultPending;
331
345
  else queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
@@ -336,7 +350,7 @@ function _for_closure(ownerLoopNodeAccessor, fn) {
336
350
  const ownerSignal = (ownerScope) => {
337
351
  const scopes = toArray(ownerScope[scopeAccessor]);
338
352
  if (scopes.length) queueRender(ownerScope, () => {
339
- for (const scope of scopes) if (!scope["#Creating"] && !scope["#Destroyed"]) fn(scope);
353
+ for (const scope of scopes) if (scope["#Gen"] > 0 && scope["#Gen"] < runId) fn(scope);
340
354
  }, -1, 0, scopes[0]["#Id"]);
341
355
  };
342
356
  ownerSignal._ = fn;
@@ -347,7 +361,7 @@ function _if_closure(ownerConditionalNodeAccessor, branch, fn) {
347
361
  const branchAccessor = "ConditionalRenderer:" + ownerConditionalNodeAccessor;
348
362
  const ownerSignal = (scope) => {
349
363
  const ifScope = scope[scopeAccessor];
350
- if (ifScope && !ifScope["#Creating"] && (scope[branchAccessor] || 0) === branch) queueRender(ifScope, fn, -1);
364
+ if (ifScope && ifScope["#Gen"] > 0 && ifScope["#Gen"] < runId && (scope[branchAccessor] || 0) === branch) queueRender(ifScope, fn, -1);
351
365
  };
352
366
  ownerSignal._ = fn;
353
367
  return ownerSignal;
@@ -366,7 +380,7 @@ function _closure(...closureSignals) {
366
380
  for (let i = closureSignals.length; i--;) closureSignals[i]["index"] = i;
367
381
  return (scope) => {
368
382
  if (scope[scopeInstances]) {
369
- for (const childScope of scope[scopeInstances]) if (!childScope["#Creating"]) queueRender(childScope, closureSignals[childScope[signalIndex] || 0], -1);
383
+ for (const childScope of scope[scopeInstances]) if (childScope["#Gen"] > 0 && childScope["#Gen"] < runId) queueRender(childScope, closureSignals[childScope[signalIndex] || 0], -1);
370
384
  }
371
385
  };
372
386
  }
@@ -606,6 +620,7 @@ function init(runtimeId = "M") {
606
620
  renderId
607
621
  };
608
622
  const initScope = (scope) => {
623
+ scope["#Gen"] = 1;
609
624
  scope["$global"] = initGlobal();
610
625
  if (branchesEnabled && scope["#ClosestBranchId"]) scope["#ClosestBranch"] = getScope(scope["#ClosestBranchId"]);
611
626
  return scope;
@@ -770,7 +785,7 @@ function _attr_input_checked_default(scope, nodeAccessor, checked) {
770
785
  const el = scope[nodeAccessor];
771
786
  const normalizedChecked = isNotVoid(checked);
772
787
  if (el.defaultChecked !== normalizedChecked) {
773
- const restoreValue = scope["#Creating"] ? normalizedChecked : el.checked;
788
+ const restoreValue = scope["#Gen"] < runId ? el.checked : normalizedChecked;
774
789
  el.defaultChecked = normalizedChecked;
775
790
  if (restoreValue !== normalizedChecked) el.checked = restoreValue;
776
791
  }
@@ -780,7 +795,7 @@ function _attr_input_checked(scope, nodeAccessor, checked, checkedChange) {
780
795
  const normalizedChecked = isNotVoid(checked);
781
796
  scope["ControlledHandler:" + nodeAccessor] = checkedChange;
782
797
  scope["ControlledType:" + nodeAccessor] = checkedChange ? 0 : 5;
783
- if (checkedChange && !scope["#Creating"]) el.checked = normalizedChecked;
798
+ if (checkedChange && scope["#Gen"] < runId) el.checked = normalizedChecked;
784
799
  else _attr_input_checked_default(scope, nodeAccessor, normalizedChecked);
785
800
  }
786
801
  function _attr_input_checked_script(scope, nodeAccessor) {
@@ -808,7 +823,7 @@ function _attr_input_checkedValue(scope, nodeAccessor, checkedValue, checkedValu
808
823
  const normalizedCheckedValue = scope["ControlledValue:" + nodeAccessor] = multiple ? checkedValue.map(normalizeStrProp) : normalizeStrProp(checkedValue);
809
824
  scope["ControlledHandler:" + nodeAccessor] = checkedValueChange;
810
825
  scope["ControlledType:" + nodeAccessor] = checkedValueChange ? 1 : 5;
811
- if (checkedValueChange && !scope["#Creating"]) {
826
+ if (checkedValueChange && scope["#Gen"] < runId) {
812
827
  el.checked = multiple ? normalizedCheckedValue.includes(normalizeStrProp(value)) : normalizeStrProp(value) === normalizedCheckedValue;
813
828
  _attr(el, "value", value);
814
829
  } else _attr_input_checkedValue_default(scope, nodeAccessor, checkedValue, value);
@@ -834,7 +849,7 @@ function _attr_input_value_default(scope, nodeAccessor, value) {
834
849
  const el = scope[nodeAccessor];
835
850
  const normalizedValue = normalizeAttrValue(value) || "";
836
851
  if (el.defaultValue !== normalizedValue) {
837
- const restoreValue = scope["#Creating"] ? normalizedValue : el.value;
852
+ const restoreValue = scope["#Gen"] < runId ? el.value : normalizedValue;
838
853
  el.defaultValue = normalizedValue;
839
854
  setInputValue(el, restoreValue);
840
855
  }
@@ -845,7 +860,7 @@ function _attr_input_value(scope, nodeAccessor, value, valueChange) {
845
860
  scope["ControlledHandler:" + nodeAccessor] = valueChange;
846
861
  scope["ControlledValue:" + nodeAccessor] = normalizedValue;
847
862
  scope["ControlledType:" + nodeAccessor] = valueChange ? 2 : 5;
848
- if (valueChange && !scope["#Creating"]) setInputValue(el, normalizedValue);
863
+ if (valueChange && scope["#Gen"] < runId) setInputValue(el, normalizedValue);
849
864
  else _attr_input_value_default(scope, nodeAccessor, normalizedValue);
850
865
  }
851
866
  function _attr_input_value_script(scope, nodeAccessor) {
@@ -871,14 +886,14 @@ function setInputValue(el, value) {
871
886
  function _attr_select_value_default(scope, nodeAccessor, value) {
872
887
  let restoreValue;
873
888
  const el = scope[nodeAccessor];
874
- const existing = !scope["#Creating"];
889
+ const live = scope["#Gen"] < runId;
875
890
  const multiple = Array.isArray(value);
876
891
  const normalizedValue = multiple ? value.map(normalizeStrProp) : normalizeStrProp(value);
877
892
  pendingEffects.unshift(() => {
878
893
  for (const opt of el.options) {
879
894
  const selected = multiple ? normalizedValue.includes(opt.value) : opt.value === normalizedValue;
880
895
  if (opt.defaultSelected !== selected) {
881
- if (existing) restoreValue ??= getSelectValue(el, multiple);
896
+ if (live) restoreValue ??= getSelectValue(el, multiple);
882
897
  opt.defaultSelected = selected;
883
898
  }
884
899
  }
@@ -887,7 +902,7 @@ function _attr_select_value_default(scope, nodeAccessor, value) {
887
902
  }
888
903
  function _attr_select_value(scope, nodeAccessor, value, valueChange) {
889
904
  const el = scope[nodeAccessor];
890
- const existing = !scope["#Creating"];
905
+ const existing = scope["#Gen"] < runId;
891
906
  const multiple = Array.isArray(value);
892
907
  const normalizedValue = scope["ControlledValue:" + nodeAccessor] = multiple ? value.map(normalizeStrProp) : normalizeStrProp(value);
893
908
  scope["ControlledHandler:" + nodeAccessor] = valueChange;
@@ -935,13 +950,13 @@ function getSelectValue(el, multiple) {
935
950
  return multiple ? Array.from(el.selectedOptions, (opt) => opt.value) : el.value;
936
951
  }
937
952
  function _attr_details_or_dialog_open_default(scope, nodeAccessor, open) {
938
- if (scope["#Creating"]) scope[nodeAccessor].open = isNotVoid(open);
953
+ if (scope["#Gen"] === runId) scope[nodeAccessor].open = isNotVoid(open);
939
954
  }
940
955
  function _attr_details_or_dialog_open(scope, nodeAccessor, open, openChange) {
941
956
  const normalizedOpen = scope["ControlledValue:" + nodeAccessor] = isNotVoid(open);
942
957
  scope["ControlledHandler:" + nodeAccessor] = openChange;
943
958
  scope["ControlledType:" + nodeAccessor] = openChange ? 4 : 5;
944
- if (openChange && !scope["#Creating"]) scope[nodeAccessor].open = normalizedOpen;
959
+ if (openChange && scope["#Gen"] < runId) scope[nodeAccessor].open = normalizedOpen;
945
960
  else _attr_details_or_dialog_open_default(scope, nodeAccessor, normalizedOpen);
946
961
  }
947
962
  function _attr_details_or_dialog_open_script(scope, nodeAccessor) {
@@ -1245,7 +1260,7 @@ function _await_promise(nodeAccessor, params) {
1245
1260
  scope[promiseAccessor] = 0;
1246
1261
  queueAsyncRender(scope, () => {
1247
1262
  if ((awaitBranch = scope[branchAccessor])["#DetachedAwait"]) {
1248
- pendingScopes.push(awaitBranch);
1263
+ awaitBranch["#PendingScopes"] = awaitBranch["#PendingScopes"]?.forEach(syncGen);
1249
1264
  setupBranch(awaitBranch["#DetachedAwait"], awaitBranch);
1250
1265
  awaitBranch["#DetachedAwait"] = 0;
1251
1266
  insertBranchBefore(awaitBranch, scope[nodeAccessor].parentNode, scope[nodeAccessor]);
@@ -1286,8 +1301,8 @@ function _await_content(nodeAccessor, template, walks, setup) {
1286
1301
  const branchAccessor = "BranchScopes:" + nodeAccessor;
1287
1302
  const renderer = _content("", template, walks, setup)();
1288
1303
  return (scope) => {
1289
- (scope[branchAccessor] = createBranch(scope["$global"], renderer, scope, scope[nodeAccessor].parentNode))["#DetachedAwait"] = renderer;
1290
- pendingScopes.pop();
1304
+ const pendingScopes = collectScopes(() => (scope[branchAccessor] = createBranch(scope["$global"], renderer, scope, scope[nodeAccessor].parentNode))["#DetachedAwait"] = renderer);
1305
+ scope[branchAccessor]["#PendingScopes"] = pendingScopes;
1291
1306
  };
1292
1307
  }
1293
1308
  function addAwaitCounter(scope, tryBranch = findBranchWithKey(scope, "#PlaceholderContent")) {
@@ -1550,13 +1565,12 @@ function byFirstArg(name) {
1550
1565
  }
1551
1566
  //#endregion
1552
1567
  //#region src/dom/queue.ts
1553
- let runId = 1;
1554
- let pendingRenders = [];
1568
+ let rendering;
1569
+ let runId = 2;
1555
1570
  const caughtError = /* @__PURE__ */ new WeakSet();
1556
1571
  const placeholderShown = /* @__PURE__ */ new WeakSet();
1557
1572
  let pendingEffects = [];
1558
- let pendingScopes = [];
1559
- let rendering;
1573
+ let pendingRenders = [];
1560
1574
  const scopeKeyOffset = 1e3;
1561
1575
  function queueRender(scope, signal, signalKey, value, scopeKey = scope["#Id"]) {
1562
1576
  let render;
@@ -1649,13 +1663,11 @@ function runRenders() {
1649
1663
  }
1650
1664
  runRender(render);
1651
1665
  }
1652
- for (const scope of pendingScopes) scope["#Creating"] = 0;
1653
- pendingScopes = [];
1654
1666
  }
1655
1667
  let runRender = (render) => render["signal"](render["scope"], render["value"]);
1656
1668
  function skipDestroyedRenders() {
1657
1669
  runRender = ((runRender) => (render) => {
1658
- if (!render["scope"]["#ClosestBranch"]?.["#Destroyed"]) runRender(render);
1670
+ if (render["scope"]["#ClosestBranch"]?.["#Gen"] !== 0) runRender(render);
1659
1671
  })(runRender);
1660
1672
  }
1661
1673
  let catchEnabled;
@@ -1678,8 +1690,7 @@ function _enable_catch() {
1678
1690
  for (; i < effects.length;) {
1679
1691
  fn = effects[i++];
1680
1692
  scope = effects[i++];
1681
- branch = scope["#ClosestBranch"];
1682
- if (!branch?.["#Destroyed"] && !(checkPending && handlePendingTry(fn, scope, branch))) fn(scope);
1693
+ if ((branch = scope["#ClosestBranch"])?.["#Gen"] !== 0 && !(checkPending && handlePendingTry(fn, scope, branch))) fn(scope);
1683
1694
  }
1684
1695
  } else runEffects(effects);
1685
1696
  })(runEffects);
@@ -1903,13 +1914,12 @@ function _load_setup(nodeAccessor, childScopeAccessor, load) {
1903
1914
  }
1904
1915
  function insertLoaded(renderer, branch, marker, awaitCounter) {
1905
1916
  const parent = marker.parentNode;
1906
- branch["#Creating"] = 1;
1917
+ syncGen(branch);
1907
1918
  renderer["clone"](branch, parent.namespaceURI);
1908
1919
  setupBranch(renderer, branch);
1909
1920
  applyLoad(branch, () => {
1910
1921
  insertBranchBefore(branch, parent, marker);
1911
1922
  marker.remove();
1912
- pendingScopes.push(branch);
1913
1923
  awaitCounter?.c();
1914
1924
  });
1915
1925
  }
@@ -1925,14 +1935,11 @@ function applyLoad(scope, insert) {
1925
1935
  scope["#Load"] = 0;
1926
1936
  if (remaining = values?.size) for (const [promise, entry] of values) promise.then((signal) => {
1927
1937
  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
- }
1938
+ if (!--remaining) queueAsyncRender(scope, (scope) => {
1939
+ syncGen(scope);
1940
+ values.forEach((e) => e["signal"]._(scope, e["value"]));
1941
+ insert();
1942
+ });
1936
1943
  }, () => 0);
1937
1944
  else insert();
1938
1945
  }
@@ -1941,7 +1948,7 @@ function _load_signal(load) {
1941
1948
  let signal;
1942
1949
  return (scope, value) => {
1943
1950
  pending ||= load();
1944
- if (scope["#Load"] || !("#Load" in scope) && scope["#Creating"]) (scope["#Load"] ||= /* @__PURE__ */ new Map()).set(pending, { ["value"]: value });
1951
+ if (scope["#Load"] || !("#Load" in scope) && scope["#Gen"] === runId) (scope["#Load"] ||= /* @__PURE__ */ new Map()).set(pending, { ["value"]: value });
1945
1952
  else if (signal) signal(scope, value);
1946
1953
  else pending.then((mod) => queueAsyncRender(scope, signal = mod._, value), () => 0);
1947
1954
  };