marko 6.0.79 → 6.0.81

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 (39) hide show
  1. package/dist/debug/dom.js +8 -0
  2. package/dist/debug/dom.mjs +8 -0
  3. package/dist/debug/html.js +261 -252
  4. package/dist/debug/html.mjs +259 -252
  5. package/dist/dom/signals.d.ts +7 -0
  6. package/dist/dom.d.ts +1 -1
  7. package/dist/dom.js +6 -0
  8. package/dist/dom.mjs +6 -0
  9. package/dist/html/compat.d.ts +1 -1
  10. package/dist/html/dynamic-tag.d.ts +1 -1
  11. package/dist/html/writer.d.ts +3 -0
  12. package/dist/html.d.ts +1 -1
  13. package/dist/html.js +168 -157
  14. package/dist/html.mjs +166 -157
  15. package/dist/translator/index.js +2183 -1900
  16. package/dist/translator/util/binding-prop-tree.d.ts +8 -0
  17. package/dist/translator/util/entry-builder.d.ts +0 -1
  18. package/dist/translator/util/generate-uid.d.ts +2 -1
  19. package/dist/translator/util/is-event-or-change-handler.d.ts +1 -0
  20. package/dist/translator/util/known-tag.d.ts +23 -0
  21. package/dist/translator/util/nested-attribute-tags.d.ts +1 -0
  22. package/dist/translator/util/optional.d.ts +2 -1
  23. package/dist/translator/util/references.d.ts +9 -4
  24. package/dist/translator/util/sections.d.ts +8 -5
  25. package/dist/translator/util/serialize-guard.d.ts +5 -0
  26. package/dist/translator/util/serialize-reasons.d.ts +13 -18
  27. package/dist/translator/util/set-tag-sections-downstream.d.ts +4 -0
  28. package/dist/translator/util/signals.d.ts +2 -1
  29. package/dist/translator/util/walks.d.ts +1 -1
  30. package/dist/translator/util/writer.d.ts +7 -3
  31. package/dist/translator/visitors/function.d.ts +4 -0
  32. package/dist/translator/visitors/program/html.d.ts +0 -4
  33. package/dist/translator/visitors/program/index.d.ts +10 -17
  34. package/dist/translator/visitors/tag/custom-tag.d.ts +0 -12
  35. package/dist/translator/visitors/tag/dynamic-tag.d.ts +2 -0
  36. package/package.json +2 -2
  37. package/tags/debug.d.marko +1 -1
  38. package/tags/log.d.marko +1 -1
  39. package/tags/do.d.marko +0 -5
package/dist/html.js CHANGED
@@ -49,6 +49,7 @@ __export(html_exports, {
49
49
  _for_of: () => _for_of,
50
50
  _for_to: () => _for_to,
51
51
  _for_until: () => _for_until,
52
+ _get_serialize_reason: () => _get_serialize_reason,
52
53
  _hoist: () => _hoist,
53
54
  _html: () => _html,
54
55
  _id: () => _id,
@@ -63,6 +64,7 @@ __export(html_exports, {
63
64
  _sep: () => _sep,
64
65
  _serialize_guard: () => _serialize_guard,
65
66
  _serialize_if: () => _serialize_if,
67
+ _set_serialize_reason: () => _set_serialize_reason,
66
68
  _subscribe: () => _subscribe,
67
69
  _template: () => _template,
68
70
  _trailers: () => _trailers,
@@ -1163,6 +1165,13 @@ function getScopeById(scopeId) {
1163
1165
  if (scopeId !== void 0)
1164
1166
  return $chunk.boundary.state.scopes.get(scopeId);
1165
1167
  }
1168
+ function _set_serialize_reason(reason) {
1169
+ $chunk.boundary.state.serializeReason = reason;
1170
+ }
1171
+ function _get_serialize_reason() {
1172
+ let reason = $chunk.boundary.state.serializeReason;
1173
+ return $chunk.boundary.state.serializeReason = void 0, reason;
1174
+ }
1166
1175
  function _serialize_if(condition, key) {
1167
1176
  return condition && (condition === 1 || condition[key]) ? 1 : void 0;
1168
1177
  }
@@ -1477,6 +1486,7 @@ var State2 = class {
1477
1486
  writeReorders = null;
1478
1487
  scopes = /* @__PURE__ */ new Map();
1479
1488
  writeScopes = null;
1489
+ serializeReason;
1480
1490
  get runtimePrefix() {
1481
1491
  let { $global: $global2 } = this;
1482
1492
  return $global2.runtimeId + "." + $global2.renderId;
@@ -1896,151 +1906,6 @@ function replaceUnsafeDoubleQuoteAttrChar(match) {
1896
1906
  // src/common/compat-meta.ts
1897
1907
  var RENDERER_REGISTER_ID = "$C_r", SET_SCOPE_REGISTER_ID = "$C_s", RENDER_BODY_ID = "$C_b";
1898
1908
 
1899
- // src/html/template.ts
1900
- var _template = (templateId, renderer) => (renderer.render = render, renderer._ = renderer, _content_resume(templateId, renderer));
1901
- function isTemplate(renderer) {
1902
- return !!renderer._;
1903
- }
1904
- function render(input = {}) {
1905
- let { $global: $global2 } = input;
1906
- $global2 ? ({ $global: $global2, ...input } = input, $global2 = {
1907
- runtimeId: "M",
1908
- renderId: "_",
1909
- ...$global2
1910
- }) : $global2 = { runtimeId: "M", renderId: "_" };
1911
- let head = new Chunk(
1912
- new Boundary(new State2($global2), $global2.signal),
1913
- null,
1914
- null
1915
- );
1916
- return head.render(this, input), new ServerRendered(head);
1917
- }
1918
- var ServerRendered = class {
1919
- #head;
1920
- #cachedPromise = null;
1921
- constructor(head) {
1922
- this.#head = head;
1923
- }
1924
- [Symbol.asyncIterator]() {
1925
- let resolve, reject, value = "", done = !1, aborted = !1, reason, boundary = this.#read(
1926
- (html) => {
1927
- value += html, resolve && (resolve({ value, done }), value = "");
1928
- },
1929
- (err) => {
1930
- aborted = !0, reason = err, reject && reject(err);
1931
- },
1932
- () => {
1933
- done = !0, resolve && (resolve({ value, done: !value }), value = "");
1934
- }
1935
- );
1936
- return {
1937
- next() {
1938
- if (aborted)
1939
- return Promise.reject(reason);
1940
- if (value) {
1941
- let result = { value, done: !1 };
1942
- return value = "", Promise.resolve(result);
1943
- } else return done ? Promise.resolve({ value: "", done }) : new Promise(exec);
1944
- },
1945
- throw(error) {
1946
- return done || aborted || boundary?.abort(error), Promise.resolve({ value: "", done: !0 });
1947
- },
1948
- return(value2) {
1949
- return done || aborted || boundary?.abort(new Error("Iterator returned before consumed.")), Promise.resolve({ value: value2, done: !0 });
1950
- }
1951
- };
1952
- function exec(_resolve, _reject) {
1953
- resolve = _resolve, reject = _reject;
1954
- }
1955
- }
1956
- pipe(stream) {
1957
- this.#read(
1958
- (html) => {
1959
- stream.write(html);
1960
- },
1961
- (err) => {
1962
- let socket = "socket" in stream && stream.socket;
1963
- if (socket && typeof socket.destroySoon == "function" && socket.destroySoon(), !stream.emit?.("error", err))
1964
- throw err;
1965
- },
1966
- () => {
1967
- stream.end();
1968
- }
1969
- );
1970
- }
1971
- toReadable() {
1972
- let cancelled = !1, boundary, encoder = new TextEncoder();
1973
- return new ReadableStream({
1974
- start: (ctrl) => {
1975
- boundary = this.#read(
1976
- (html) => {
1977
- ctrl.enqueue(encoder.encode(html));
1978
- },
1979
- (err) => {
1980
- boundary = void 0, cancelled || ctrl.error(err);
1981
- },
1982
- () => {
1983
- boundary = void 0, ctrl.close();
1984
- }
1985
- );
1986
- },
1987
- cancel: (reason) => {
1988
- cancelled = !0, boundary?.abort(reason);
1989
- }
1990
- });
1991
- }
1992
- then(onfulfilled, onrejected) {
1993
- return this.#promise().then(onfulfilled, onrejected);
1994
- }
1995
- catch(onrejected) {
1996
- return this.#promise().catch(onrejected);
1997
- }
1998
- finally(onfinally) {
1999
- return this.#promise().finally(onfinally);
2000
- }
2001
- #promise() {
2002
- return this.#cachedPromise ||= new Promise((resolve, reject) => {
2003
- let head = this.#head;
2004
- if (this.#head = null, !head)
2005
- return reject(new Error("Cannot read from a consumed render result"));
2006
- let { boundary } = head;
2007
- (boundary.onNext = () => {
2008
- boundary.signal.aborted ? (boundary.onNext = NOOP2, reject(boundary.signal.reason)) : !boundary.count && boundary.done && resolve(head.consume().flushHTML());
2009
- })();
2010
- });
2011
- }
2012
- #read(onWrite, onAbort, onClose) {
2013
- let tick2 = !0, head = this.#head;
2014
- if (this.#head = null, !head) {
2015
- onAbort(new Error("Cannot read from a consumed render result"));
2016
- return;
2017
- }
2018
- let { boundary } = head, onNext = boundary.onNext = (write) => {
2019
- if (boundary.signal.aborted)
2020
- tick2 || offTick(onNext), boundary.onNext = NOOP2, onAbort(boundary.signal.reason);
2021
- else {
2022
- let { done } = boundary;
2023
- if (done || write) {
2024
- let html = (head = head.consume()).flushHTML();
2025
- html && onWrite(html), done ? (tick2 || offTick(onNext), onClose()) : tick2 = !0;
2026
- } else tick2 && (tick2 = !1, queueTick(onNext));
2027
- }
2028
- };
2029
- return onNext(), boundary;
2030
- }
2031
- toString() {
2032
- let head = this.#head;
2033
- if (this.#head = null, !head) throw new Error("Cannot read from a consumed render result");
2034
- let { boundary } = head;
2035
- if (!boundary.done)
2036
- throw new Error("Cannot consume asynchronous render with 'toString'");
2037
- if (boundary.signal.aborted) throw boundary.signal.reason;
2038
- return head.consume().flushHTML();
2039
- }
2040
- };
2041
- function NOOP2() {
2042
- }
2043
-
2044
1909
  // src/html/dynamic-tag.ts
2045
1910
  var voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/, _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, serializeReason) => {
2046
1911
  let shouldResume = serializeReason !== 0, renderer = normalizeDynamicRenderer(tag), state = getState(), branchId = _peek_scope_id(), rendered = !1, result;
@@ -2091,18 +1956,15 @@ var voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|p
2091
1956
  } else {
2092
1957
  shouldResume && _html(state.mark("[" /* BranchStart */, ""));
2093
1958
  let render2 = () => {
2094
- if (renderer) {
2095
- if (isTemplate(renderer)) {
2096
- let input = inputIsArgs ? inputOrArgs[0] : inputOrArgs;
2097
- return renderer(
2098
- content ? { ...input, content } : input,
2099
- shouldResume ? 1 : 0
1959
+ if (renderer)
1960
+ try {
1961
+ return _set_serialize_reason(shouldResume ? 1 : 0), inputIsArgs ? renderer(...inputOrArgs) : renderer(
1962
+ content ? { ...inputOrArgs, content } : inputOrArgs
2100
1963
  );
1964
+ } finally {
1965
+ _set_serialize_reason(void 0);
2101
1966
  }
2102
- return inputIsArgs ? renderer(...inputOrArgs) : renderer(
2103
- content ? { ...inputOrArgs, content } : inputOrArgs
2104
- );
2105
- } else if (content)
1967
+ else if (content)
2106
1968
  return content();
2107
1969
  };
2108
1970
  result = shouldResume ? withBranchId(branchId, render2) : render2(), rendered = _peek_scope_id() !== branchId, shouldResume && _html(
@@ -2204,11 +2066,16 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2204
2066
  let scopeId = _peek_scope_id();
2205
2067
  writeScope(scopeId, { m5c: component.id }), _script(scopeId, SET_SCOPE_REGISTER_ID);
2206
2068
  }
2207
- isTemplate(renderer) && willRerender ? renderer(normalizedInput, 1) : renderer(normalizedInput);
2069
+ _set_serialize_reason(willRerender ? 1 : 0);
2070
+ try {
2071
+ renderer(normalizedInput);
2072
+ } finally {
2073
+ _set_serialize_reason(void 0);
2074
+ }
2208
2075
  let asyncOut = classAPIOut.beginAsync({ last: !0, timeout: -1 });
2209
2076
  classAPIOut.onLast((next) => {
2210
2077
  (boundary.onNext = () => {
2211
- boundary.signal.aborted ? (asyncOut.error(boundary.signal.reason), boundary.onNext = NOOP3) : boundary.count || (boundary.onNext = NOOP3, head = head.consume(), asyncOut.write(head.html), asyncOut.script(head.scripts), asyncOut.end(), head.html = head.scripts = "", completeChunks.push(head), next());
2078
+ boundary.signal.aborted ? (asyncOut.error(boundary.signal.reason), boundary.onNext = NOOP2) : boundary.count || (boundary.onNext = NOOP2, head = head.consume(), asyncOut.write(head.html), asyncOut.script(head.scripts), asyncOut.end(), head.html = head.scripts = "", completeChunks.push(head), next());
2212
2079
  })();
2213
2080
  });
2214
2081
  });
@@ -2225,6 +2092,148 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
2225
2092
  register(RENDER_BODY_ID, fn);
2226
2093
  }
2227
2094
  };
2095
+ function NOOP2() {
2096
+ }
2097
+
2098
+ // src/html/template.ts
2099
+ var _template = (templateId, renderer) => (renderer.render = render, renderer._ = renderer, _content_resume(templateId, renderer));
2100
+ function render(input = {}) {
2101
+ let { $global: $global2 } = input;
2102
+ $global2 ? ({ $global: $global2, ...input } = input, $global2 = {
2103
+ runtimeId: "M",
2104
+ renderId: "_",
2105
+ ...$global2
2106
+ }) : $global2 = { runtimeId: "M", renderId: "_" };
2107
+ let head = new Chunk(
2108
+ new Boundary(new State2($global2), $global2.signal),
2109
+ null,
2110
+ null
2111
+ );
2112
+ return head.render(this, input), new ServerRendered(head);
2113
+ }
2114
+ var ServerRendered = class {
2115
+ #head;
2116
+ #cachedPromise = null;
2117
+ constructor(head) {
2118
+ this.#head = head;
2119
+ }
2120
+ [Symbol.asyncIterator]() {
2121
+ let resolve, reject, value = "", done = !1, aborted = !1, reason, boundary = this.#read(
2122
+ (html) => {
2123
+ value += html, resolve && (resolve({ value, done }), value = "");
2124
+ },
2125
+ (err) => {
2126
+ aborted = !0, reason = err, reject && reject(err);
2127
+ },
2128
+ () => {
2129
+ done = !0, resolve && (resolve({ value, done: !value }), value = "");
2130
+ }
2131
+ );
2132
+ return {
2133
+ next() {
2134
+ if (aborted)
2135
+ return Promise.reject(reason);
2136
+ if (value) {
2137
+ let result = { value, done: !1 };
2138
+ return value = "", Promise.resolve(result);
2139
+ } else return done ? Promise.resolve({ value: "", done }) : new Promise(exec);
2140
+ },
2141
+ throw(error) {
2142
+ return done || aborted || boundary?.abort(error), Promise.resolve({ value: "", done: !0 });
2143
+ },
2144
+ return(value2) {
2145
+ return done || aborted || boundary?.abort(new Error("Iterator returned before consumed.")), Promise.resolve({ value: value2, done: !0 });
2146
+ }
2147
+ };
2148
+ function exec(_resolve, _reject) {
2149
+ resolve = _resolve, reject = _reject;
2150
+ }
2151
+ }
2152
+ pipe(stream) {
2153
+ this.#read(
2154
+ (html) => {
2155
+ stream.write(html);
2156
+ },
2157
+ (err) => {
2158
+ let socket = "socket" in stream && stream.socket;
2159
+ if (socket && typeof socket.destroySoon == "function" && socket.destroySoon(), !stream.emit?.("error", err))
2160
+ throw err;
2161
+ },
2162
+ () => {
2163
+ stream.end();
2164
+ }
2165
+ );
2166
+ }
2167
+ toReadable() {
2168
+ let cancelled = !1, boundary, encoder = new TextEncoder();
2169
+ return new ReadableStream({
2170
+ start: (ctrl) => {
2171
+ boundary = this.#read(
2172
+ (html) => {
2173
+ ctrl.enqueue(encoder.encode(html));
2174
+ },
2175
+ (err) => {
2176
+ boundary = void 0, cancelled || ctrl.error(err);
2177
+ },
2178
+ () => {
2179
+ boundary = void 0, ctrl.close();
2180
+ }
2181
+ );
2182
+ },
2183
+ cancel: (reason) => {
2184
+ cancelled = !0, boundary?.abort(reason);
2185
+ }
2186
+ });
2187
+ }
2188
+ then(onfulfilled, onrejected) {
2189
+ return this.#promise().then(onfulfilled, onrejected);
2190
+ }
2191
+ catch(onrejected) {
2192
+ return this.#promise().catch(onrejected);
2193
+ }
2194
+ finally(onfinally) {
2195
+ return this.#promise().finally(onfinally);
2196
+ }
2197
+ #promise() {
2198
+ return this.#cachedPromise ||= new Promise((resolve, reject) => {
2199
+ let head = this.#head;
2200
+ if (this.#head = null, !head)
2201
+ return reject(new Error("Cannot read from a consumed render result"));
2202
+ let { boundary } = head;
2203
+ (boundary.onNext = () => {
2204
+ boundary.signal.aborted ? (boundary.onNext = NOOP3, reject(boundary.signal.reason)) : !boundary.count && boundary.done && resolve(head.consume().flushHTML());
2205
+ })();
2206
+ });
2207
+ }
2208
+ #read(onWrite, onAbort, onClose) {
2209
+ let tick2 = !0, head = this.#head;
2210
+ if (this.#head = null, !head) {
2211
+ onAbort(new Error("Cannot read from a consumed render result"));
2212
+ return;
2213
+ }
2214
+ let { boundary } = head, onNext = boundary.onNext = (write) => {
2215
+ if (boundary.signal.aborted)
2216
+ tick2 || offTick(onNext), boundary.onNext = NOOP3, onAbort(boundary.signal.reason);
2217
+ else {
2218
+ let { done } = boundary;
2219
+ if (done || write) {
2220
+ let html = (head = head.consume()).flushHTML();
2221
+ html && onWrite(html), done ? (tick2 || offTick(onNext), onClose()) : tick2 = !0;
2222
+ } else tick2 && (tick2 = !1, queueTick(onNext));
2223
+ }
2224
+ };
2225
+ return onNext(), boundary;
2226
+ }
2227
+ toString() {
2228
+ let head = this.#head;
2229
+ if (this.#head = null, !head) throw new Error("Cannot read from a consumed render result");
2230
+ let { boundary } = head;
2231
+ if (!boundary.done)
2232
+ throw new Error("Cannot consume asynchronous render with 'toString'");
2233
+ if (boundary.signal.aborted) throw boundary.signal.reason;
2234
+ return head.consume().flushHTML();
2235
+ }
2236
+ };
2228
2237
  function NOOP3() {
2229
2238
  }
2230
2239
  // Annotate the CommonJS export names for ESM import in node:
@@ -2261,6 +2270,7 @@ function NOOP3() {
2261
2270
  _for_of,
2262
2271
  _for_to,
2263
2272
  _for_until,
2273
+ _get_serialize_reason,
2264
2274
  _hoist,
2265
2275
  _html,
2266
2276
  _id,
@@ -2275,6 +2285,7 @@ function NOOP3() {
2275
2285
  _sep,
2276
2286
  _serialize_guard,
2277
2287
  _serialize_if,
2288
+ _set_serialize_reason,
2278
2289
  _subscribe,
2279
2290
  _template,
2280
2291
  _trailers,