marko 6.0.0-next.3.68 → 6.0.0-next.3.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/html.d.ts CHANGED
@@ -2,7 +2,7 @@ export { attrTag, attrTags } from "./common/attr-tag";
2
2
  export { attr, attrs, classAttr, controllable_detailsOrDialog_open, controllable_input_checked, controllable_input_checkedValue, controllable_input_value, controllable_select_value, controllable_textarea_value, optionValueAttr, partialAttrs, styleAttr, } from "./html/attrs";
3
3
  export { compat } from "./html/compat";
4
4
  export { escapeScript, escapeStyle, escapeXML, toString } from "./html/content";
5
- export { createContent, dynamicTagArgs, dynamicTagId, dynamicTagInput, registerContent, } from "./html/dynamic-tag";
5
+ export { createContent, dynamicTag, registerContent } from "./html/dynamic-tag";
6
6
  export { forIn, forInBy, forOf, forOfBy, forTo, forToBy } from "./html/for";
7
7
  export { createTemplate } from "./html/template";
8
8
  export { $global, ensureScopeWithId, fork, getScopeById, hoist, markResumeNode, nextScopeId, nextTagId, nodeRef, peekNextScope, register, resumeClosestBranch, resumeConditional, resumeForIn, resumeForOf, resumeForTo, resumeSingleNodeConditional, resumeSingleNodeForIn, resumeSingleNodeForOf, resumeSingleNodeForTo, setTagVar, tryContent, write, writeEffect, writeExistingScope, writeScope, writeSubscribe, writeTrailers, } from "./html/writer";
package/dist/html.js CHANGED
@@ -32,19 +32,17 @@ __export(html_exports, {
32
32
  controllable_textarea_value: () => controllable_textarea_value,
33
33
  createContent: () => createContent,
34
34
  createTemplate: () => createTemplate,
35
- dynamicTagArgs: () => dynamicTagArgs,
36
- dynamicTagId: () => dynamicTagId,
37
- dynamicTagInput: () => dynamicTagInput,
35
+ dynamicTag: () => dynamicTag,
38
36
  ensureScopeWithId: () => ensureScopeWithId,
39
37
  escapeScript: () => escapeScript,
40
38
  escapeStyle: () => escapeStyle,
41
39
  escapeXML: () => escapeXML,
42
40
  forIn: () => forIn,
43
- forInBy: () => forInBy,
41
+ forInBy: () => forInBy2,
44
42
  forOf: () => forOf,
45
- forOfBy: () => forOfBy,
43
+ forOfBy: () => forOfBy2,
46
44
  forTo: () => forTo,
47
- forToBy: () => forToBy,
45
+ forToBy: () => forToBy2,
48
46
  fork: () => fork,
49
47
  getScopeById: () => getScopeById,
50
48
  hoist: () => hoist,
@@ -492,10 +490,7 @@ function register(id, val, scope) {
492
490
  function getRegistered(val) {
493
491
  let registered = REGISTRY.get(val);
494
492
  if (registered)
495
- return {
496
- id: registered.id,
497
- scope: registered.scope
498
- };
493
+ return { id: registered.id, scope: registered.scope };
499
494
  }
500
495
  function writeRoot(state, root) {
501
496
  let { buf, assigned, mutations } = state, hadBuf = buf.length !== 0, result = "";
@@ -591,7 +586,7 @@ function writeRegistered(state, val, parent, accessor, { access, scope, getter }
591
586
  return newScopeRef && ensureId(state, newScopeRef), !0;
592
587
  }
593
588
  if (scopeRef) {
594
- if (isCircular(parent, scopeRef))
589
+ if (parent && (state.assigned.has(scopeRef) || isCircular(parent, scopeRef)))
595
590
  return state.assigned.add(parent), state.assigned.add(fnRef), fnRef.init = access + "(" + ensureId(state, scopeRef) + ")", addAssignment(fnRef, ensureId(state, parent) + toAccess(accessor)), !1;
596
591
  state.buf.push(access + "(" + ensureId(state, scopeRef) + ")");
597
592
  } else {
@@ -1093,7 +1088,7 @@ function withContext(key, value, cb) {
1093
1088
  let ctx = $chunk.context ||= { [kPendingContexts]: 0 }, prev = ctx[key];
1094
1089
  ctx[kPendingContexts]++, ctx[key] = value;
1095
1090
  try {
1096
- cb();
1091
+ return cb();
1097
1092
  } finally {
1098
1093
  ctx[kPendingContexts]--, ctx[key] = prev;
1099
1094
  }
@@ -1141,20 +1136,26 @@ function hoist(scopeId, id) {
1141
1136
  }
1142
1137
  function resumeClosestBranch(scopeId) {
1143
1138
  let branchId = $chunk.context?.[branchIdKey];
1144
- branchId !== void 0 && branchId !== scopeId && writeScope(scopeId, {
1145
- g: branchId
1146
- });
1139
+ branchId !== void 0 && branchId !== scopeId && writeScope(scopeId, { g: branchId });
1147
1140
  }
1148
1141
  var branchIdKey = Symbol();
1149
- function resumeForOf(list, cb, scopeId, accessor) {
1150
- forOf(list, (item, i) => {
1142
+ function withBranchId(branchId, cb) {
1143
+ return withContext(branchIdKey, branchId, cb);
1144
+ }
1145
+ function resumeForOf(list, cb, by, scopeId, accessor) {
1146
+ let loopScopes = /* @__PURE__ */ new Map();
1147
+ forOf(list, (item, index) => {
1151
1148
  let branchId = peekNextScopeId();
1152
1149
  $chunk.writeHTML(
1153
1150
  $chunk.boundary.state.mark(
1154
1151
  "[" /* BranchStart */,
1155
- branchId + (i ? " " : "")
1152
+ branchId + (index ? " " : "")
1156
1153
  )
1157
- ), withContext(branchIdKey, branchId, () => cb(item, i));
1154
+ ), withBranchId(branchId, () => {
1155
+ cb(item, index), loopScopes.set(forOfBy(by, item, index), writeScope(branchId, {}));
1156
+ });
1157
+ }), loopScopes.size && writeScope(scopeId, {
1158
+ ["m" /* LoopScopeMap */ + accessor]: loopScopes
1158
1159
  }), $chunk.writeHTML(
1159
1160
  $chunk.boundary.state.mark(
1160
1161
  "]" /* BranchEnd */,
@@ -1162,11 +1163,15 @@ function resumeForOf(list, cb, scopeId, accessor) {
1162
1163
  )
1163
1164
  );
1164
1165
  }
1165
- function resumeSingleNodeForOf(list, cb, scopeId, accessor, onlyChildInParent) {
1166
- let branchIds = "";
1166
+ function resumeSingleNodeForOf(list, cb, by, scopeId, accessor, onlyChildInParent) {
1167
+ let loopScopes = /* @__PURE__ */ new Map(), branchIds = "";
1167
1168
  forOf(list, (item, index) => {
1168
1169
  let branchId = peekNextScopeId();
1169
- branchIds = " " + branchId + branchIds, withContext(branchIdKey, branchId, () => cb(item, index));
1170
+ branchIds = " " + branchId + branchIds, withBranchId(branchId, () => {
1171
+ cb(item, index), loopScopes.set(forOfBy(by, item, index), writeScope(branchId, {}));
1172
+ });
1173
+ }), loopScopes.size && writeScope(scopeId, {
1174
+ ["m" /* LoopScopeMap */ + accessor]: loopScopes
1170
1175
  }), $chunk.writeHTML(
1171
1176
  $chunk.boundary.state.mark(
1172
1177
  onlyChildInParent ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
@@ -1174,13 +1179,20 @@ function resumeSingleNodeForOf(list, cb, scopeId, accessor, onlyChildInParent) {
1174
1179
  )
1175
1180
  );
1176
1181
  }
1177
- function resumeForIn(obj, cb, scopeId, accessor) {
1178
- let sep = "";
1182
+ function forOfBy(by, item, index) {
1183
+ return by ? typeof by == "string" ? item[by] : by(item, index) : index;
1184
+ }
1185
+ function resumeForIn(obj, cb, by, scopeId, accessor) {
1186
+ let loopScopes = /* @__PURE__ */ new Map(), sep = "";
1179
1187
  forIn(obj, (key, value) => {
1180
1188
  let branchId = peekNextScopeId();
1181
1189
  $chunk.writeHTML(
1182
1190
  $chunk.boundary.state.mark("[" /* BranchStart */, branchId + sep)
1183
- ), sep = " ", withContext(branchIdKey, branchId, () => cb(key, value));
1191
+ ), sep = " ", withBranchId(branchId, () => {
1192
+ cb(key, value), loopScopes.set(forInBy(by, key, value), writeScope(branchId, {}));
1193
+ });
1194
+ }), loopScopes.size && writeScope(scopeId, {
1195
+ ["m" /* LoopScopeMap */ + accessor]: loopScopes
1184
1196
  }), $chunk.writeHTML(
1185
1197
  $chunk.boundary.state.mark(
1186
1198
  "]" /* BranchEnd */,
@@ -1188,11 +1200,15 @@ function resumeForIn(obj, cb, scopeId, accessor) {
1188
1200
  )
1189
1201
  );
1190
1202
  }
1191
- function resumeSingleNodeForIn(obj, cb, scopeId, accessor, onlyChild) {
1192
- let branchIds = "";
1203
+ function resumeSingleNodeForIn(obj, cb, by, scopeId, accessor, onlyChild) {
1204
+ let loopScopes = /* @__PURE__ */ new Map(), branchIds = "";
1193
1205
  forIn(obj, (key, value) => {
1194
1206
  let branchId = peekNextScopeId();
1195
- branchIds = " " + branchId + branchIds, withContext(branchIdKey, branchId, () => cb(key, value));
1207
+ branchIds = " " + branchId + branchIds, withBranchId(branchId, () => {
1208
+ cb(key, value), loopScopes.set(forInBy(by, key, value), writeScope(branchId, {}));
1209
+ });
1210
+ }), loopScopes.size && writeScope(scopeId, {
1211
+ ["m" /* LoopScopeMap */ + accessor]: loopScopes
1196
1212
  }), $chunk.writeHTML(
1197
1213
  $chunk.boundary.state.mark(
1198
1214
  onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
@@ -1200,13 +1216,20 @@ function resumeSingleNodeForIn(obj, cb, scopeId, accessor, onlyChild) {
1200
1216
  )
1201
1217
  );
1202
1218
  }
1203
- function resumeForTo(to, from, step, cb, scopeId, accessor) {
1204
- let sep = "";
1219
+ function forInBy(by, name, value) {
1220
+ return by ? by(name, value) : name;
1221
+ }
1222
+ function resumeForTo(to, from, step, cb, by, scopeId, accessor) {
1223
+ let loopScopes = /* @__PURE__ */ new Map(), sep = "";
1205
1224
  forTo(to, from, step, (index) => {
1206
1225
  let branchId = peekNextScopeId();
1207
1226
  $chunk.writeHTML(
1208
1227
  $chunk.boundary.state.mark("[" /* BranchStart */, branchId + sep)
1209
- ), sep = " ", withContext(branchIdKey, branchId, () => cb(index));
1228
+ ), sep = " ", withBranchId(branchId, () => {
1229
+ cb(index), loopScopes.set(forToBy(by, index), writeScope(branchId, {}));
1230
+ });
1231
+ }), loopScopes.size && writeScope(scopeId, {
1232
+ ["m" /* LoopScopeMap */ + accessor]: loopScopes
1210
1233
  }), $chunk.writeHTML(
1211
1234
  $chunk.boundary.state.mark(
1212
1235
  "]" /* BranchEnd */,
@@ -1214,11 +1237,15 @@ function resumeForTo(to, from, step, cb, scopeId, accessor) {
1214
1237
  )
1215
1238
  );
1216
1239
  }
1217
- function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor, onlyChild) {
1218
- let branchIds = "";
1240
+ function resumeSingleNodeForTo(to, from, step, cb, by, scopeId, accessor, onlyChild) {
1241
+ let loopScopes = /* @__PURE__ */ new Map(), branchIds = "";
1219
1242
  forTo(to, from, step, (index) => {
1220
1243
  let branchId = peekNextScopeId();
1221
- branchIds = " " + branchId + branchIds, withContext(branchIdKey, branchId, () => cb(index));
1244
+ branchIds = " " + branchId + branchIds, withBranchId(branchId, () => {
1245
+ cb(index), loopScopes.set(forToBy(by, index), writeScope(branchId, {}));
1246
+ });
1247
+ }), loopScopes.size && writeScope(scopeId, {
1248
+ ["m" /* LoopScopeMap */ + accessor]: loopScopes
1222
1249
  }), $chunk.writeHTML(
1223
1250
  $chunk.boundary.state.mark(
1224
1251
  onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
@@ -1226,22 +1253,31 @@ function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor, onlyChild)
1226
1253
  )
1227
1254
  );
1228
1255
  }
1229
- function resumeConditional(cb, scopeId, accessor) {
1256
+ function forToBy(by, index) {
1257
+ return by ? by(index) : index;
1258
+ }
1259
+ function resumeConditional(cb, scopeId, accessor, dynamic) {
1230
1260
  let branchId = peekNextScopeId();
1231
- $chunk.writeHTML(
1261
+ dynamic && $chunk.writeHTML(
1232
1262
  $chunk.boundary.state.mark("[" /* BranchStart */, branchId + "")
1233
- ), withContext(branchIdKey, branchId, cb), peekNextScopeId() !== branchId ? writeScope(branchId, {}) : nextScopeId(), $chunk.writeHTML(
1263
+ );
1264
+ let branchIndex = withBranchId(branchId, cb);
1265
+ branchIndex !== void 0 ? writeScope(scopeId, {
1266
+ ["c" /* ConditionalRenderer */ + accessor]: dynamic ? branchIndex : void 0,
1267
+ ["d" /* ConditionalScope */ + accessor]: writeScope(branchId, {})
1268
+ }) : nextScopeId(), dynamic && $chunk.writeHTML(
1234
1269
  $chunk.boundary.state.mark(
1235
1270
  "]" /* BranchEnd */,
1236
1271
  scopeId + " " + accessor
1237
1272
  )
1238
1273
  );
1239
1274
  }
1240
- function resumeSingleNodeConditional(cb, scopeId, accessor, onlyChild) {
1241
- let branchId = peekNextScopeId();
1242
- withContext(branchIdKey, branchId, cb);
1243
- let rendered = peekNextScopeId() !== branchId;
1244
- rendered ? writeScope(branchId, {}) : nextScopeId(), $chunk.writeHTML(
1275
+ function resumeSingleNodeConditional(cb, scopeId, accessor, dynamic, onlyChild) {
1276
+ let branchId = peekNextScopeId(), branchIndex = withBranchId(branchId, cb), rendered = branchIndex !== void 0;
1277
+ rendered ? writeScope(scopeId, {
1278
+ ["c" /* ConditionalRenderer */ + accessor]: dynamic ? branchIndex : void 0,
1279
+ ["d" /* ConditionalScope */ + accessor]: writeScope(branchId, {})
1280
+ }) : nextScopeId(), dynamic && $chunk.writeHTML(
1245
1281
  $chunk.boundary.state.mark(
1246
1282
  onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
1247
1283
  scopeId + " " + accessor + (rendered ? " " + branchId : "")
@@ -1794,80 +1830,51 @@ var prefix = "$C_", RENDERER_REGISTER_ID = prefix + "r", SET_SCOPE_REGISTER_ID =
1794
1830
  var DEFAULT_RUNTIME_ID = "M", DEFAULT_RENDER_ID = "_";
1795
1831
 
1796
1832
  // src/html/dynamic-tag.ts
1797
- var voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/;
1798
- function dynamicTagId(tagName) {
1799
- let normalizedRenderer = normalizeDynamicRenderer(tagName);
1800
- return normalizedRenderer?.h || normalizedRenderer;
1801
- }
1802
- var dynamicTagInput = (scopeId, accessor, tag, input, content) => {
1803
- if (!tag && !content) {
1804
- nextScopeId();
1805
- return;
1806
- }
1807
- if (!tag) {
1808
- resumeConditional(content, scopeId, accessor);
1809
- return;
1810
- }
1811
- if (typeof tag == "string") {
1812
- resumeSingleNodeConditional(
1813
- () => {
1814
- nextScopeId(), write(`<${tag}${attrs(input, accessor, scopeId, tag)}>`), voidElementsReg.test(tag) || (tag === "textarea" ? write(
1815
- controllable_textarea_value(
1816
- scopeId,
1817
- accessor,
1818
- input.value,
1819
- input.valueChange
1820
- )
1821
- ) : content && (tag === "select" && ("value" in input || "valueChange" in input) ? controllable_select_value(
1833
+ var voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/, dynamicTag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, resume) => {
1834
+ let renderer = normalizeDynamicRenderer(tag), chunk = getChunk(), branchId = peekNextScopeId(), result;
1835
+ if (typeof renderer == "string") {
1836
+ let input = (inputIsArgs ? inputOrArgs[0] : inputOrArgs) || {};
1837
+ nextScopeId(), write(`<${renderer}${attrs(input, accessor, scopeId, renderer)}>`), voidElementsReg.test(renderer) || (withBranchId(branchId, () => {
1838
+ renderer === "textarea" ? write(
1839
+ controllable_textarea_value(
1822
1840
  scopeId,
1823
1841
  accessor,
1824
1842
  input.value,
1825
- input.valueChange,
1826
- content
1827
- ) : content()), write(`</${tag}>`));
1828
- },
1829
- scopeId,
1830
- accessor
1843
+ input.valueChange
1844
+ )
1845
+ ) : content && (renderer === "select" && ("value" in input || "valueChange" in input) ? controllable_select_value(
1846
+ scopeId,
1847
+ accessor,
1848
+ input.value,
1849
+ input.valueChange,
1850
+ content
1851
+ ) : content());
1852
+ }), write(`</${renderer}>`)), resume && chunk.writeHTML(
1853
+ chunk.boundary.state.mark(
1854
+ "|" /* BranchSingleNode */,
1855
+ scopeId + " " + accessor + " " + branchId
1856
+ )
1831
1857
  );
1832
- return;
1833
- }
1834
- let renderer = normalizeDynamicRenderer(
1835
- tag
1836
- ), result;
1837
- return resumeConditional(
1838
- () => {
1839
- result = renderer(content ? { ...input, content } : input);
1840
- },
1841
- scopeId,
1842
- accessor
1843
- ), result;
1844
- }, dynamicTagArgs = (scopeId, accessor, tag, args) => {
1845
- if (!tag) {
1846
- nextScopeId();
1847
- return;
1848
- }
1849
- if (typeof tag == "string") {
1850
- resumeSingleNodeConditional(
1851
- () => {
1852
- nextScopeId(), write(
1853
- `<${tag}${attrs(args[0], accessor, scopeId, tag)}>`
1854
- ), voidElementsReg.test(tag) || write(`</${tag}>`);
1855
- },
1856
- scopeId,
1857
- accessor
1858
+ } else
1859
+ resume && chunk.writeHTML(
1860
+ chunk.boundary.state.mark("[" /* BranchStart */, branchId + "")
1861
+ ), result = withBranchId(branchId, () => {
1862
+ if (renderer)
1863
+ return inputIsArgs ? renderer(...inputOrArgs) : renderer(
1864
+ content ? { ...inputOrArgs, content } : inputOrArgs
1865
+ );
1866
+ if (content)
1867
+ return content();
1868
+ }), resume && chunk.writeHTML(
1869
+ chunk.boundary.state.mark(
1870
+ "]" /* BranchEnd */,
1871
+ scopeId + " " + accessor
1872
+ )
1858
1873
  );
1859
- return;
1860
- }
1861
- let renderer = normalizeDynamicRenderer(
1862
- tag
1863
- ), result;
1864
- return resumeConditional(
1865
- () => {
1866
- result = renderer(...args);
1867
- },
1868
- scopeId,
1869
- accessor
1870
- ), result;
1874
+ return peekNextScopeId() !== branchId ? resume && writeScope(scopeId, {
1875
+ ["d" /* ConditionalScope */ + accessor]: writeScope(branchId, {}),
1876
+ ["c" /* ConditionalRenderer */ + accessor]: renderer?.h || renderer
1877
+ }) : nextScopeId(), result;
1871
1878
  };
1872
1879
  function createContent(id, fn) {
1873
1880
  return fn.h = id, fn;
@@ -1876,18 +1883,18 @@ function registerContent(id, fn, scopeId) {
1876
1883
  return register2(createContent(id, fn), id, scopeId);
1877
1884
  }
1878
1885
  function patchDynamicTag(patch) {
1879
- dynamicTagInput = /* @__PURE__ */ ((originalDynamicTagInput) => (scopeId, accessor, tag, input, content) => originalDynamicTagInput(
1880
- scopeId,
1881
- accessor,
1882
- patch(scopeId, accessor, tag),
1883
- input,
1884
- content
1885
- ))(dynamicTagInput), dynamicTagArgs = /* @__PURE__ */ ((originalDynamicTagArgs) => (scopeId, accessor, tag, args) => originalDynamicTagArgs(
1886
- scopeId,
1887
- accessor,
1888
- patch(scopeId, accessor, tag),
1889
- args
1890
- ))(dynamicTagArgs);
1886
+ dynamicTag = /* @__PURE__ */ ((originalDynamicTag) => (scopeId, accessor, tag, input, content, inputIsArgs, resume) => {
1887
+ let patched = patch(scopeId, accessor, tag);
1888
+ return patched.h = tag, originalDynamicTag(
1889
+ scopeId,
1890
+ accessor,
1891
+ patched,
1892
+ input,
1893
+ content,
1894
+ inputIsArgs,
1895
+ resume
1896
+ );
1897
+ })(dynamicTag);
1891
1898
  }
1892
1899
 
1893
1900
  // src/html/compat.ts
@@ -1962,13 +1969,13 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
1962
1969
  };
1963
1970
 
1964
1971
  // src/html/for.ts
1965
- function forOfBy(by, item, index) {
1972
+ function forOfBy2(by, item, index) {
1966
1973
  return by ? typeof by == "string" ? item[by] : by(item, index) : index;
1967
1974
  }
1968
- function forInBy(by, name, value) {
1975
+ function forInBy2(by, name, value) {
1969
1976
  return by ? by(name, value) : name;
1970
1977
  }
1971
- function forToBy(by, index) {
1978
+ function forToBy2(by, index) {
1972
1979
  return by ? by(index) : index;
1973
1980
  }
1974
1981
 
@@ -2129,9 +2136,7 @@ function NOOP2() {
2129
2136
  controllable_textarea_value,
2130
2137
  createContent,
2131
2138
  createTemplate,
2132
- dynamicTagArgs,
2133
- dynamicTagId,
2134
- dynamicTagInput,
2139
+ dynamicTag,
2135
2140
  ensureScopeWithId,
2136
2141
  escapeScript,
2137
2142
  escapeStyle,