marko 6.1.24 → 6.2.1

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.
@@ -4,6 +4,7 @@ export declare function getWrongAttrSuggestion(name: string): string | undefined
4
4
  export declare function _call<T>(fn: (v: T) => unknown, v: T): T;
5
5
  export declare function stringifyClassObject(name: string, value: unknown): string;
6
6
  export declare function stringifyStyleObject(name: string, value: unknown): string;
7
+ export declare function escapeStyleValue(str: string): string;
7
8
  export declare const toDelimitedString: (val: unknown, delimiter: string, stringify: (n: string, v: unknown) => string | undefined) => string;
8
9
  export declare function isEventHandler(name: string): name is `on${string}`;
9
10
  export declare function getEventHandlerName(name: `on${string}`): string;
package/dist/debug/dom.js CHANGED
@@ -71,6 +71,14 @@ function stringifyClassObject(name, value) {
71
71
  function stringifyStyleObject(name, value) {
72
72
  return value || value === 0 ? name + ":" + value : "";
73
73
  }
74
+ function escapeStyleValue(str) {
75
+ let closers = "";
76
+ const result = str.replace(/[\\"'{};<>]|\/(?=\*)/g, (c) => c === "<" ? "\\3C " : c === ";" ? "\\3B " : c === "{" ? "\\7B " : "\\" + c);
77
+ for (const c of result) if (c === "(") closers = ")" + closers;
78
+ else if (c === "[") closers = "]" + closers;
79
+ else if (c === closers[0]) closers = closers.slice(1);
80
+ return result + closers;
81
+ }
74
82
  const toDelimitedString = function toDelimitedString(val, delimiter, stringify) {
75
83
  let str = "";
76
84
  let sep = "";
@@ -225,6 +233,10 @@ const DYNAMIC_TAG_SCRIPT_REGISTER_ID = "_dynamicTagScript";
225
233
  function toArray(opt) {
226
234
  return opt ? Array.isArray(opt) ? opt : [opt] : [];
227
235
  }
236
+ function forEach(opt, cb) {
237
+ if (opt) if (Array.isArray(opt)) for (const item of opt) cb(item);
238
+ else cb(opt);
239
+ }
228
240
  function push(opt, item) {
229
241
  return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
230
242
  }
@@ -770,12 +782,14 @@ function init(runtimeId = "M") {
770
782
  if (branch["#AwaitCounter"] = render.p?.[branchId]) branch["#AwaitCounter"].m = render.m;
771
783
  if (singleNode) {
772
784
  while (startVisit.previousSibling && ~visits.indexOf(startVisit = startVisit.previousSibling));
785
+ branch["_"] ??= visitScope;
773
786
  branch["#EndNode"] = branch["#StartNode"] = startVisit;
774
787
  if (visitType === "'") branch[getDebugKey(0, startVisit)] = startVisit;
775
788
  } else {
776
789
  curBranchScopes = push(curBranchScopes, branch);
777
790
  if (accessor) {
778
791
  visitScope[accessor] = curBranchScopes;
792
+ forEach(curBranchScopes, (scope) => scope["_"] ??= visitScope);
779
793
  curBranchScopes = branchScopesStack.pop();
780
794
  }
781
795
  startVisit = branchStarts.pop();
@@ -1175,6 +1189,20 @@ function _attr_style_items(element, items) {
1175
1189
  function _attr_style_item(element, name, value) {
1176
1190
  element.style.setProperty(name, _to_text(value));
1177
1191
  }
1192
+ function _style_shell(scope, nodeAccessor) {
1193
+ const element = scope[nodeAccessor];
1194
+ const id = _id(scope);
1195
+ _attr_nonce(scope, nodeAccessor);
1196
+ element.className = id;
1197
+ _text_content(element, "." + id + "~*{}");
1198
+ }
1199
+ function _style_rule_item(element, name, value) {
1200
+ const text = element.textContent;
1201
+ const decl = name + ":" + escapeStyleValue(_to_text(value)) + ";";
1202
+ let start = text.indexOf("{" + name + ":");
1203
+ if (!~start) start = text.indexOf(";" + name + ":");
1204
+ _text_content(element, ~start ? text.slice(0, ++start) + decl + text.slice(text.indexOf(";", start) + 1) : text.slice(0, -1) + decl + "}");
1205
+ }
1178
1206
  function _attr_nonce(scope, nodeAccessor) {
1179
1207
  _attr(scope[nodeAccessor], "nonce", scope["$global"].cspNonce);
1180
1208
  }
@@ -1546,6 +1574,34 @@ function _if(nodeAccessor, ...branchesArgs) {
1546
1574
  if (newBranch !== (scope[branchAccessor] ?? (scope["BranchScopes:" + nodeAccessor] && 0))) setConditionalRenderer(scope, nodeAccessor, branches[scope[branchAccessor] = newBranch], createAndSetupBranch);
1547
1575
  };
1548
1576
  }
1577
+ function _show(nodeAccessor, startNodeAccessor) {
1578
+ const rangeAccessor = "BranchScopes:" + nodeAccessor;
1579
+ enableBranches();
1580
+ return (scope, display) => {
1581
+ const referenceNode = scope[nodeAccessor];
1582
+ const onlyChild = referenceNode.nodeType === 1;
1583
+ const parentNode = onlyChild ? referenceNode : referenceNode.parentNode;
1584
+ let range = scope[rangeAccessor];
1585
+ if (!range) {
1586
+ range = scope[rangeAccessor] = {};
1587
+ range["#StartNode"] = onlyChild ? parentNode.firstChild : scope[startNodeAccessor];
1588
+ range["#EndNode"] = onlyChild ? parentNode.lastChild : referenceNode.previousSibling;
1589
+ }
1590
+ let startNode = range["#StartNode"];
1591
+ if (range["#Id"] && startNode === range["#EndNode"] && startNode.tagName === "T") {
1592
+ const wrapper = startNode;
1593
+ if (!wrapper.firstChild) wrapper.appendChild(new Text());
1594
+ range = scope[rangeAccessor] = {};
1595
+ range["#StartNode"] = startNode = wrapper.firstChild;
1596
+ range["#EndNode"] = wrapper.lastChild;
1597
+ wrapper.replaceWith(...wrapper.childNodes);
1598
+ }
1599
+ const inDom = startNode.parentNode === parentNode;
1600
+ if (display) {
1601
+ if (!inDom) insertBranchBefore(range, parentNode, onlyChild ? null : referenceNode);
1602
+ } else if (inDom) tempDetachBranch(range);
1603
+ };
1604
+ }
1549
1605
  function patchDynamicTag(fn) {
1550
1606
  _dynamic_tag = fn(_dynamic_tag);
1551
1607
  }
@@ -2017,8 +2073,8 @@ function mount(input = {}, reference, position) {
2017
2073
  renderId: "_",
2018
2074
  ...$global
2019
2075
  };
2020
- if (!String($global.runtimeId).match(/^[_$a-z][_$a-z0-9]*$/i)) throw new Error(`Invalid runtimeId: "${$global.runtimeId}". The runtimeId must be a valid JavaScript identifier.`);
2021
- if (!String($global.renderId).match(/^[_$a-z][_$a-z0-9]*$/i)) throw new Error(`Invalid renderId: "${$global.renderId}". The renderId must be a valid JavaScript identifier.`);
2076
+ if (!String($global.runtimeId).match(/^[_a-z][_a-z0-9]*$/i)) throw new Error(`Invalid runtimeId: "${$global.runtimeId}". The runtimeId must start with a letter or underscore and only contain letters, numbers, and underscores.`);
2077
+ if (!String($global.renderId).match(/^[_a-z][_a-z0-9]*$/i)) throw new Error(`Invalid renderId: "${$global.renderId}". The renderId must start with a letter or underscore and only contain letters, numbers, and underscores.`);
2022
2078
  } else $global = {
2023
2079
  runtimeId: "M",
2024
2080
  renderId: "_"
@@ -2253,6 +2309,9 @@ exports._resume_dynamic_tag = _resume_dynamic_tag;
2253
2309
  exports._return = _return;
2254
2310
  exports._return_change = _return_change;
2255
2311
  exports._script = _script;
2312
+ exports._show = _show;
2313
+ exports._style_rule_item = _style_rule_item;
2314
+ exports._style_shell = _style_shell;
2256
2315
  exports._template = _template;
2257
2316
  exports._text = _text;
2258
2317
  exports._text_content = _text_content;
@@ -69,6 +69,14 @@ function stringifyClassObject(name, value) {
69
69
  function stringifyStyleObject(name, value) {
70
70
  return value || value === 0 ? name + ":" + value : "";
71
71
  }
72
+ function escapeStyleValue(str) {
73
+ let closers = "";
74
+ const result = str.replace(/[\\"'{};<>]|\/(?=\*)/g, (c) => c === "<" ? "\\3C " : c === ";" ? "\\3B " : c === "{" ? "\\7B " : "\\" + c);
75
+ for (const c of result) if (c === "(") closers = ")" + closers;
76
+ else if (c === "[") closers = "]" + closers;
77
+ else if (c === closers[0]) closers = closers.slice(1);
78
+ return result + closers;
79
+ }
72
80
  const toDelimitedString = function toDelimitedString(val, delimiter, stringify) {
73
81
  let str = "";
74
82
  let sep = "";
@@ -223,6 +231,10 @@ const DYNAMIC_TAG_SCRIPT_REGISTER_ID = "_dynamicTagScript";
223
231
  function toArray(opt) {
224
232
  return opt ? Array.isArray(opt) ? opt : [opt] : [];
225
233
  }
234
+ function forEach(opt, cb) {
235
+ if (opt) if (Array.isArray(opt)) for (const item of opt) cb(item);
236
+ else cb(opt);
237
+ }
226
238
  function push(opt, item) {
227
239
  return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
228
240
  }
@@ -768,12 +780,14 @@ function init(runtimeId = "M") {
768
780
  if (branch["#AwaitCounter"] = render.p?.[branchId]) branch["#AwaitCounter"].m = render.m;
769
781
  if (singleNode) {
770
782
  while (startVisit.previousSibling && ~visits.indexOf(startVisit = startVisit.previousSibling));
783
+ branch["_"] ??= visitScope;
771
784
  branch["#EndNode"] = branch["#StartNode"] = startVisit;
772
785
  if (visitType === "'") branch[getDebugKey(0, startVisit)] = startVisit;
773
786
  } else {
774
787
  curBranchScopes = push(curBranchScopes, branch);
775
788
  if (accessor) {
776
789
  visitScope[accessor] = curBranchScopes;
790
+ forEach(curBranchScopes, (scope) => scope["_"] ??= visitScope);
777
791
  curBranchScopes = branchScopesStack.pop();
778
792
  }
779
793
  startVisit = branchStarts.pop();
@@ -1173,6 +1187,20 @@ function _attr_style_items(element, items) {
1173
1187
  function _attr_style_item(element, name, value) {
1174
1188
  element.style.setProperty(name, _to_text(value));
1175
1189
  }
1190
+ function _style_shell(scope, nodeAccessor) {
1191
+ const element = scope[nodeAccessor];
1192
+ const id = _id(scope);
1193
+ _attr_nonce(scope, nodeAccessor);
1194
+ element.className = id;
1195
+ _text_content(element, "." + id + "~*{}");
1196
+ }
1197
+ function _style_rule_item(element, name, value) {
1198
+ const text = element.textContent;
1199
+ const decl = name + ":" + escapeStyleValue(_to_text(value)) + ";";
1200
+ let start = text.indexOf("{" + name + ":");
1201
+ if (!~start) start = text.indexOf(";" + name + ":");
1202
+ _text_content(element, ~start ? text.slice(0, ++start) + decl + text.slice(text.indexOf(";", start) + 1) : text.slice(0, -1) + decl + "}");
1203
+ }
1176
1204
  function _attr_nonce(scope, nodeAccessor) {
1177
1205
  _attr(scope[nodeAccessor], "nonce", scope["$global"].cspNonce);
1178
1206
  }
@@ -1544,6 +1572,34 @@ function _if(nodeAccessor, ...branchesArgs) {
1544
1572
  if (newBranch !== (scope[branchAccessor] ?? (scope["BranchScopes:" + nodeAccessor] && 0))) setConditionalRenderer(scope, nodeAccessor, branches[scope[branchAccessor] = newBranch], createAndSetupBranch);
1545
1573
  };
1546
1574
  }
1575
+ function _show(nodeAccessor, startNodeAccessor) {
1576
+ const rangeAccessor = "BranchScopes:" + nodeAccessor;
1577
+ enableBranches();
1578
+ return (scope, display) => {
1579
+ const referenceNode = scope[nodeAccessor];
1580
+ const onlyChild = referenceNode.nodeType === 1;
1581
+ const parentNode = onlyChild ? referenceNode : referenceNode.parentNode;
1582
+ let range = scope[rangeAccessor];
1583
+ if (!range) {
1584
+ range = scope[rangeAccessor] = {};
1585
+ range["#StartNode"] = onlyChild ? parentNode.firstChild : scope[startNodeAccessor];
1586
+ range["#EndNode"] = onlyChild ? parentNode.lastChild : referenceNode.previousSibling;
1587
+ }
1588
+ let startNode = range["#StartNode"];
1589
+ if (range["#Id"] && startNode === range["#EndNode"] && startNode.tagName === "T") {
1590
+ const wrapper = startNode;
1591
+ if (!wrapper.firstChild) wrapper.appendChild(new Text());
1592
+ range = scope[rangeAccessor] = {};
1593
+ range["#StartNode"] = startNode = wrapper.firstChild;
1594
+ range["#EndNode"] = wrapper.lastChild;
1595
+ wrapper.replaceWith(...wrapper.childNodes);
1596
+ }
1597
+ const inDom = startNode.parentNode === parentNode;
1598
+ if (display) {
1599
+ if (!inDom) insertBranchBefore(range, parentNode, onlyChild ? null : referenceNode);
1600
+ } else if (inDom) tempDetachBranch(range);
1601
+ };
1602
+ }
1547
1603
  function patchDynamicTag(fn) {
1548
1604
  _dynamic_tag = fn(_dynamic_tag);
1549
1605
  }
@@ -2015,8 +2071,8 @@ function mount(input = {}, reference, position) {
2015
2071
  renderId: "_",
2016
2072
  ...$global
2017
2073
  };
2018
- if (!String($global.runtimeId).match(/^[_$a-z][_$a-z0-9]*$/i)) throw new Error(`Invalid runtimeId: "${$global.runtimeId}". The runtimeId must be a valid JavaScript identifier.`);
2019
- if (!String($global.renderId).match(/^[_$a-z][_$a-z0-9]*$/i)) throw new Error(`Invalid renderId: "${$global.renderId}". The renderId must be a valid JavaScript identifier.`);
2074
+ if (!String($global.runtimeId).match(/^[_a-z][_a-z0-9]*$/i)) throw new Error(`Invalid runtimeId: "${$global.runtimeId}". The runtimeId must start with a letter or underscore and only contain letters, numbers, and underscores.`);
2075
+ if (!String($global.renderId).match(/^[_a-z][_a-z0-9]*$/i)) throw new Error(`Invalid renderId: "${$global.renderId}". The renderId must start with a letter or underscore and only contain letters, numbers, and underscores.`);
2020
2076
  } else $global = {
2021
2077
  runtimeId: "M",
2022
2078
  renderId: "_"
@@ -2162,4 +2218,4 @@ function getSelectorOrResolve(selector, resolve) {
2162
2218
  return document.querySelector(selector) || (console.warn(`A lazy load trigger could not find an element matching "${selector}". The module was loaded immediately.`), resolve());
2163
2219
  }
2164
2220
  //#endregion
2165
- 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, _dynamic_tag_content, _el, _el_read, _enable_catch, _for_closure, _for_in, _for_of, _for_selector, _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 };
2221
+ 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, _dynamic_tag_content, _el, _el_read, _enable_catch, _for_closure, _for_in, _for_of, _for_selector, _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, _show, _style_rule_item, _style_shell, _template, _text, _text_content, _to_text, _try, _var, _var_change, _var_resume, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, init, initEmbedded, ready, run };
@@ -67,6 +67,14 @@ function stringifyClassObject(name, value) {
67
67
  function stringifyStyleObject(name, value) {
68
68
  return value || value === 0 ? name + ":" + value : "";
69
69
  }
70
+ function escapeStyleValue(str) {
71
+ let closers = "";
72
+ const result = str.replace(/[\\"'{};<>]|\/(?=\*)/g, (c) => c === "<" ? "\\3C " : c === ";" ? "\\3B " : c === "{" ? "\\7B " : "\\" + c);
73
+ for (const c of result) if (c === "(") closers = ")" + closers;
74
+ else if (c === "[") closers = "]" + closers;
75
+ else if (c === closers[0]) closers = closers.slice(1);
76
+ return result + closers;
77
+ }
70
78
  const toDelimitedString = function toDelimitedString(val, delimiter, stringify) {
71
79
  let str = "";
72
80
  let sep = "";
@@ -227,6 +235,10 @@ function _escape_style(val) {
227
235
  assertValidTextValue(val);
228
236
  return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
229
237
  }
238
+ function _escape_style_value(val) {
239
+ assertValidTextValue(val);
240
+ return val || val === 0 ? escapeStyleValue(val + "") : "";
241
+ }
230
242
  const unsafeCommentReg = />/g;
231
243
  const escapeCommentStr = (str) => unsafeCommentReg.test(str) ? str.replace(unsafeCommentReg, "&gt;") : str;
232
244
  function _escape_comment(val) {
@@ -1549,9 +1561,6 @@ const REORDER_RUNTIME_CODE = `((runtime) => {
1549
1561
  nextSibling,
1550
1562
  placeholders = runtime.p = {},
1551
1563
  replace = (id, container) => runtime.l[id].replaceWith(...container.childNodes);
1552
- runtime.d.head.append(
1553
- runtime.d.querySelector("style[" + runtime.i + "]") || ""
1554
- );
1555
1564
  runtime.j = {};
1556
1565
  runtime.x = (op, id, node, placeholderRoot, placeholderCb) => {
1557
1566
  if (node == nextSibling) {
@@ -1714,7 +1723,7 @@ function _scope_reason() {
1714
1723
  return reason;
1715
1724
  }
1716
1725
  function _serialize_if(condition, key) {
1717
- return condition && (condition === 1 || condition[key]) ? 1 : void 0;
1726
+ return condition && (condition === 1 || (typeof condition === "number" ? condition >>> key + 1 & 1 : condition[key])) ? 1 : void 0;
1718
1727
  }
1719
1728
  function _serialize_guard(condition, key) {
1720
1729
  return _serialize_if(condition, key) || 0;
@@ -1836,6 +1845,17 @@ function writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, p
1836
1845
  } else $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
1837
1846
  else $chunk.writeHTML(endTag);
1838
1847
  }
1848
+ function _show_start(display, mark) {
1849
+ if (display) {
1850
+ if (mark) $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
1851
+ } else $chunk.writeHTML("<t hidden>");
1852
+ }
1853
+ function _show_end(scopeId, accessor, display, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1854
+ const branchId = _scope_id();
1855
+ const wrap = !display;
1856
+ if (wrap) $chunk.writeHTML("</t>");
1857
+ writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
1858
+ }
1839
1859
  let writeScope = (scopeId, partialScope) => {
1840
1860
  const { state } = $chunk.boundary;
1841
1861
  const target = $chunk.serializeState;
@@ -2240,7 +2260,7 @@ var Chunk = class Chunk {
2240
2260
  flushScript() {
2241
2261
  const { boundary } = this;
2242
2262
  const { state } = boundary;
2243
- const { $global, runtimePrefix, nonceAttr } = state;
2263
+ const { $global, runtimePrefix } = state;
2244
2264
  let needsWalk = state.walkOnNextFlush;
2245
2265
  if (needsWalk) state.walkOnNextFlush = false;
2246
2266
  let readyResumeScripts = this.flushReadyScripts();
@@ -2251,7 +2271,7 @@ var Chunk = class Chunk {
2251
2271
  readyResumeScripts = concatScripts(readyResumeScripts, state.writeReady(channel.readyId, concatSequence(depsMarker(deps), resumes)));
2252
2272
  }
2253
2273
  if (readyResumeScripts) needsWalk = true;
2254
- const { effects } = this;
2274
+ const effects = this.async ? "" : this.effects;
2255
2275
  let { html, scripts } = this;
2256
2276
  if (state.needsMainRuntime && !state.hasMainRuntime) {
2257
2277
  state.hasMainRuntime = true;
@@ -2271,7 +2291,6 @@ var Chunk = class Chunk {
2271
2291
  needsWalk = true;
2272
2292
  if (!state.hasReorderRuntime) {
2273
2293
  state.hasReorderRuntime = true;
2274
- html += "<style " + state.commentPrefix + nonceAttr + ">t{display:none}</style>";
2275
2294
  scripts = concatScripts(scripts, REORDER_RUNTIME_CODE + "(" + runtimePrefix + ")");
2276
2295
  }
2277
2296
  for (const reorderedChunk of state.writeReorders) {
@@ -2308,14 +2327,15 @@ var Chunk = class Chunk {
2308
2327
  }
2309
2328
  for (const reservation of readyReservations) scripts = concatScripts(scripts, reservation);
2310
2329
  scripts = concatScripts(scripts, reorderScripts && runtimePrefix + ".j" + toAccess(reorderId) + "=_=>{" + reorderScripts + "}");
2311
- html += "<t " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
2330
+ html += "<t hidden " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
2312
2331
  }
2313
2332
  state.writeReorders = null;
2314
2333
  }
2315
2334
  if (needsWalk) scripts = concatScripts(scripts, runtimePrefix + ".w()");
2316
2335
  this.html = html;
2317
2336
  this.scripts = scripts;
2318
- this.effects = this.lastEffect = state.resumes = "";
2337
+ if (!this.async) this.effects = this.lastEffect = "";
2338
+ state.resumes = "";
2319
2339
  return this;
2320
2340
  }
2321
2341
  flushHTML() {
@@ -2523,6 +2543,10 @@ function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange, s
2523
2543
  function _attr_nonce() {
2524
2544
  return getChunk().boundary.state.nonceAttr;
2525
2545
  }
2546
+ function _style_html(decls) {
2547
+ const id = _id();
2548
+ return `<style${_attr_nonce()} class=${id}>.${id}~*{${decls}}</style>`;
2549
+ }
2526
2550
  function _attr(name, value) {
2527
2551
  return isVoid(value) ? "" : nonVoidAttr(name, value);
2528
2552
  }
@@ -2758,8 +2782,8 @@ function render(input = {}) {
2758
2782
  renderId: getDefaultRenderId(this),
2759
2783
  ...$global
2760
2784
  };
2761
- if (!String($global.runtimeId).match(/^[_$a-z][_$a-z0-9]*$/i)) throw new Error(`Invalid runtimeId: "${$global.runtimeId}". The runtimeId must be a valid JavaScript identifier.`);
2762
- if (!String($global.renderId).match(/^[_$a-z][_$a-z0-9]*$/i)) throw new Error(`Invalid renderId: "${$global.renderId}". The renderId must be a valid JavaScript identifier.`);
2785
+ if (!String($global.runtimeId).match(/^[_a-z][_a-z0-9]*$/i)) throw new Error(`Invalid runtimeId: "${$global.runtimeId}". The runtimeId must start with a letter or underscore and only contain letters, numbers, and underscores.`);
2786
+ if (!String($global.renderId).match(/^[_a-z][_a-z0-9]*$/i)) throw new Error(`Invalid renderId: "${$global.renderId}". The renderId must start with a letter or underscore and only contain letters, numbers, and underscores.`);
2763
2787
  } else $global = {
2764
2788
  runtimeId: "M",
2765
2789
  renderId: getDefaultRenderId(this)
@@ -2772,10 +2796,10 @@ function render(input = {}) {
2772
2796
  }
2773
2797
  function getDefaultRenderId(template) {
2774
2798
  if (template["embed"]) {
2775
- const ENCODE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789";
2799
+ const ENCODE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
2776
2800
  let n = Math.random() * 4294967296 >>> 0;
2777
- let r = ENCODE_CHARS[n % 53];
2778
- for (n = n / 53 | 0; n; n >>>= 6) r += ENCODE_CHARS[n & 63];
2801
+ let r = ENCODE_CHARS[n % 52];
2802
+ for (n = n / 52 | 0; n; n = n / 63 | 0) r += ENCODE_CHARS[n % 63];
2779
2803
  return r;
2780
2804
  }
2781
2805
  return "_";
@@ -3197,6 +3221,7 @@ exports._escape = _escape;
3197
3221
  exports._escape_comment = _escape_comment;
3198
3222
  exports._escape_script = _escape_script;
3199
3223
  exports._escape_style = _escape_style;
3224
+ exports._escape_style_value = _escape_style_value;
3200
3225
  exports._existing_scope = _existing_scope;
3201
3226
  exports._flush_head = _flush_head;
3202
3227
  exports._for_in = _for_in;
@@ -3225,6 +3250,9 @@ exports._sep = _sep;
3225
3250
  exports._serialize_guard = _serialize_guard;
3226
3251
  exports._serialize_if = _serialize_if;
3227
3252
  exports._set_serialize_reason = _set_serialize_reason;
3253
+ exports._show_end = _show_end;
3254
+ exports._show_start = _show_start;
3255
+ exports._style_html = _style_html;
3228
3256
  exports._subscribe = _subscribe;
3229
3257
  exports._template = _template;
3230
3258
  exports._to_text = _to_text;
@@ -65,6 +65,14 @@ function stringifyClassObject(name, value) {
65
65
  function stringifyStyleObject(name, value) {
66
66
  return value || value === 0 ? name + ":" + value : "";
67
67
  }
68
+ function escapeStyleValue(str) {
69
+ let closers = "";
70
+ const result = str.replace(/[\\"'{};<>]|\/(?=\*)/g, (c) => c === "<" ? "\\3C " : c === ";" ? "\\3B " : c === "{" ? "\\7B " : "\\" + c);
71
+ for (const c of result) if (c === "(") closers = ")" + closers;
72
+ else if (c === "[") closers = "]" + closers;
73
+ else if (c === closers[0]) closers = closers.slice(1);
74
+ return result + closers;
75
+ }
68
76
  const toDelimitedString = function toDelimitedString(val, delimiter, stringify) {
69
77
  let str = "";
70
78
  let sep = "";
@@ -225,6 +233,10 @@ function _escape_style(val) {
225
233
  assertValidTextValue(val);
226
234
  return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
227
235
  }
236
+ function _escape_style_value(val) {
237
+ assertValidTextValue(val);
238
+ return val || val === 0 ? escapeStyleValue(val + "") : "";
239
+ }
228
240
  const unsafeCommentReg = />/g;
229
241
  const escapeCommentStr = (str) => unsafeCommentReg.test(str) ? str.replace(unsafeCommentReg, "&gt;") : str;
230
242
  function _escape_comment(val) {
@@ -1547,9 +1559,6 @@ const REORDER_RUNTIME_CODE = `((runtime) => {
1547
1559
  nextSibling,
1548
1560
  placeholders = runtime.p = {},
1549
1561
  replace = (id, container) => runtime.l[id].replaceWith(...container.childNodes);
1550
- runtime.d.head.append(
1551
- runtime.d.querySelector("style[" + runtime.i + "]") || ""
1552
- );
1553
1562
  runtime.j = {};
1554
1563
  runtime.x = (op, id, node, placeholderRoot, placeholderCb) => {
1555
1564
  if (node == nextSibling) {
@@ -1712,7 +1721,7 @@ function _scope_reason() {
1712
1721
  return reason;
1713
1722
  }
1714
1723
  function _serialize_if(condition, key) {
1715
- return condition && (condition === 1 || condition[key]) ? 1 : void 0;
1724
+ return condition && (condition === 1 || (typeof condition === "number" ? condition >>> key + 1 & 1 : condition[key])) ? 1 : void 0;
1716
1725
  }
1717
1726
  function _serialize_guard(condition, key) {
1718
1727
  return _serialize_if(condition, key) || 0;
@@ -1834,6 +1843,17 @@ function writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, p
1834
1843
  } else $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
1835
1844
  else $chunk.writeHTML(endTag);
1836
1845
  }
1846
+ function _show_start(display, mark) {
1847
+ if (display) {
1848
+ if (mark) $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
1849
+ } else $chunk.writeHTML("<t hidden>");
1850
+ }
1851
+ function _show_end(scopeId, accessor, display, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1852
+ const branchId = _scope_id();
1853
+ const wrap = !display;
1854
+ if (wrap) $chunk.writeHTML("</t>");
1855
+ writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
1856
+ }
1837
1857
  let writeScope = (scopeId, partialScope) => {
1838
1858
  const { state } = $chunk.boundary;
1839
1859
  const target = $chunk.serializeState;
@@ -2238,7 +2258,7 @@ var Chunk = class Chunk {
2238
2258
  flushScript() {
2239
2259
  const { boundary } = this;
2240
2260
  const { state } = boundary;
2241
- const { $global, runtimePrefix, nonceAttr } = state;
2261
+ const { $global, runtimePrefix } = state;
2242
2262
  let needsWalk = state.walkOnNextFlush;
2243
2263
  if (needsWalk) state.walkOnNextFlush = false;
2244
2264
  let readyResumeScripts = this.flushReadyScripts();
@@ -2249,7 +2269,7 @@ var Chunk = class Chunk {
2249
2269
  readyResumeScripts = concatScripts(readyResumeScripts, state.writeReady(channel.readyId, concatSequence(depsMarker(deps), resumes)));
2250
2270
  }
2251
2271
  if (readyResumeScripts) needsWalk = true;
2252
- const { effects } = this;
2272
+ const effects = this.async ? "" : this.effects;
2253
2273
  let { html, scripts } = this;
2254
2274
  if (state.needsMainRuntime && !state.hasMainRuntime) {
2255
2275
  state.hasMainRuntime = true;
@@ -2269,7 +2289,6 @@ var Chunk = class Chunk {
2269
2289
  needsWalk = true;
2270
2290
  if (!state.hasReorderRuntime) {
2271
2291
  state.hasReorderRuntime = true;
2272
- html += "<style " + state.commentPrefix + nonceAttr + ">t{display:none}</style>";
2273
2292
  scripts = concatScripts(scripts, REORDER_RUNTIME_CODE + "(" + runtimePrefix + ")");
2274
2293
  }
2275
2294
  for (const reorderedChunk of state.writeReorders) {
@@ -2306,14 +2325,15 @@ var Chunk = class Chunk {
2306
2325
  }
2307
2326
  for (const reservation of readyReservations) scripts = concatScripts(scripts, reservation);
2308
2327
  scripts = concatScripts(scripts, reorderScripts && runtimePrefix + ".j" + toAccess(reorderId) + "=_=>{" + reorderScripts + "}");
2309
- html += "<t " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
2328
+ html += "<t hidden " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
2310
2329
  }
2311
2330
  state.writeReorders = null;
2312
2331
  }
2313
2332
  if (needsWalk) scripts = concatScripts(scripts, runtimePrefix + ".w()");
2314
2333
  this.html = html;
2315
2334
  this.scripts = scripts;
2316
- this.effects = this.lastEffect = state.resumes = "";
2335
+ if (!this.async) this.effects = this.lastEffect = "";
2336
+ state.resumes = "";
2317
2337
  return this;
2318
2338
  }
2319
2339
  flushHTML() {
@@ -2521,6 +2541,10 @@ function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange, s
2521
2541
  function _attr_nonce() {
2522
2542
  return getChunk().boundary.state.nonceAttr;
2523
2543
  }
2544
+ function _style_html(decls) {
2545
+ const id = _id();
2546
+ return `<style${_attr_nonce()} class=${id}>.${id}~*{${decls}}</style>`;
2547
+ }
2524
2548
  function _attr(name, value) {
2525
2549
  return isVoid(value) ? "" : nonVoidAttr(name, value);
2526
2550
  }
@@ -2756,8 +2780,8 @@ function render(input = {}) {
2756
2780
  renderId: getDefaultRenderId(this),
2757
2781
  ...$global
2758
2782
  };
2759
- if (!String($global.runtimeId).match(/^[_$a-z][_$a-z0-9]*$/i)) throw new Error(`Invalid runtimeId: "${$global.runtimeId}". The runtimeId must be a valid JavaScript identifier.`);
2760
- if (!String($global.renderId).match(/^[_$a-z][_$a-z0-9]*$/i)) throw new Error(`Invalid renderId: "${$global.renderId}". The renderId must be a valid JavaScript identifier.`);
2783
+ if (!String($global.runtimeId).match(/^[_a-z][_a-z0-9]*$/i)) throw new Error(`Invalid runtimeId: "${$global.runtimeId}". The runtimeId must start with a letter or underscore and only contain letters, numbers, and underscores.`);
2784
+ if (!String($global.renderId).match(/^[_a-z][_a-z0-9]*$/i)) throw new Error(`Invalid renderId: "${$global.renderId}". The renderId must start with a letter or underscore and only contain letters, numbers, and underscores.`);
2761
2785
  } else $global = {
2762
2786
  runtimeId: "M",
2763
2787
  renderId: getDefaultRenderId(this)
@@ -2770,10 +2794,10 @@ function render(input = {}) {
2770
2794
  }
2771
2795
  function getDefaultRenderId(template) {
2772
2796
  if (template["embed"]) {
2773
- const ENCODE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789";
2797
+ const ENCODE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
2774
2798
  let n = Math.random() * 4294967296 >>> 0;
2775
- let r = ENCODE_CHARS[n % 53];
2776
- for (n = n / 53 | 0; n; n >>>= 6) r += ENCODE_CHARS[n & 63];
2799
+ let r = ENCODE_CHARS[n % 52];
2800
+ for (n = n / 52 | 0; n; n = n / 63 | 0) r += ENCODE_CHARS[n % 63];
2777
2801
  return r;
2778
2802
  }
2779
2803
  return "_";
@@ -3157,4 +3181,4 @@ const compat = {
3157
3181
  };
3158
3182
  function NOOP() {}
3159
3183
  //#endregion
3160
- export { $global, _assert_hoist, _attr, _attr_and, _attr_class, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_input_checked, _attr_input_checkedValue, _attr_input_value, _attr_nonce, _attr_nullish, _attr_option_value, _attr_or, _attr_select_value, _attr_style, _attr_textarea_value, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _await, _content, _content_resume, _dynamic_tag, _el, _el_read_error, _el_resume, _escape, _escape_comment, _escape_script, _escape_style, _existing_scope, _flush_head, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_read_error, _html, _id, _if, _peek_scope_id, _resume, _resume_branch, writeScope as _scope, _scope_id, _scope_reason, _scope_with_id, _script, _sep, _serialize_guard, _serialize_if, _set_serialize_reason, _subscribe, _template, _to_text, _trailers, _try, _unescaped, _var, attrTag, attrTags, compat, forIn, forInBy, forOf, forOfBy, forStepBy, forTo, forUntil, withLoadAssets, withPageAssets };
3184
+ export { $global, _assert_hoist, _attr, _attr_and, _attr_class, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_input_checked, _attr_input_checkedValue, _attr_input_value, _attr_nonce, _attr_nullish, _attr_option_value, _attr_or, _attr_select_value, _attr_style, _attr_textarea_value, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _await, _content, _content_resume, _dynamic_tag, _el, _el_read_error, _el_resume, _escape, _escape_comment, _escape_script, _escape_style, _escape_style_value, _existing_scope, _flush_head, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_read_error, _html, _id, _if, _peek_scope_id, _resume, _resume_branch, writeScope as _scope, _scope_id, _scope_reason, _scope_with_id, _script, _sep, _serialize_guard, _serialize_if, _set_serialize_reason, _show_end, _show_start, _style_html, _subscribe, _template, _to_text, _trailers, _try, _unescaped, _var, attrTag, attrTags, compat, forIn, forInBy, forOf, forOfBy, forStepBy, forTo, forUntil, withLoadAssets, withPageAssets };
@@ -10,6 +10,7 @@ export declare function _try(nodeAccessor: EncodedAccessor, template?: string |
10
10
  }) => void;
11
11
  export declare function renderCatch(scope: Scope, error: unknown): void;
12
12
  export declare function _if(nodeAccessor: EncodedAccessor, ...branchesArgs: (string | SetupFn | 0)[]): (scope: Scope, newBranch: number) => void;
13
+ export declare function _show(nodeAccessor: EncodedAccessor, startNodeAccessor?: EncodedAccessor): (scope: Scope, display: unknown) => void;
13
14
  export declare function patchDynamicTag(fn: <T extends typeof _dynamic_tag>(cond: T) => T): void;
14
15
  export declare let _dynamic_tag: (nodeAccessor: EncodedAccessor, getContent?: ((scope: Scope) => Renderer) | 0, getTagVar?: (() => Signal<unknown>) | 0, inputIsArgs?: 1) => Signal<Renderer | string | undefined>;
15
16
  export declare function _dynamic_tag_content(nodeAccessor: EncodedAccessor): Signal<Renderer | undefined>;
package/dist/dom/dom.d.ts CHANGED
@@ -7,6 +7,8 @@ export declare function _attr_class_item(element: Element, name: string, value:
7
7
  export declare function _attr_style(element: Element, value: unknown): void;
8
8
  export declare function _attr_style_items(element: HTMLElement, items: Record<string, unknown>): void;
9
9
  export declare function _attr_style_item(element: HTMLElement, name: string, value: unknown): void;
10
+ export declare function _style_shell(scope: Scope, nodeAccessor: Accessor): void;
11
+ export declare function _style_rule_item(element: HTMLStyleElement, name: string, value: unknown): void;
10
12
  export declare function _attr_nonce(scope: Scope, nodeAccessor: Accessor): void;
11
13
  export declare function _text(node: Text | Comment, value: unknown): void;
12
14
  export declare function _text_content(node: ParentNode, value: unknown): void;
package/dist/dom.d.ts CHANGED
@@ -4,9 +4,9 @@ export { forIn, forOf, forTo, forUntil } from "./common/for";
4
4
  export { _call } from "./common/helpers";
5
5
  export { $signal, $signalReset } from "./dom/abort-signal";
6
6
  export { compat } from "./dom/compat";
7
- export { _await_content, _await_promise, _dynamic_tag, _dynamic_tag_content, _for_in, _for_of, _for_to, _for_until, _if, _resume_dynamic_tag, _try, } from "./dom/control-flow";
7
+ export { _await_content, _await_promise, _dynamic_tag, _dynamic_tag_content, _for_in, _for_of, _for_to, _for_until, _if, _resume_dynamic_tag, _show, _try, } from "./dom/control-flow";
8
8
  export { _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open_default as _attr_details_open_default, _attr_details_or_dialog_open_script as _attr_details_open_script, _attr_details_or_dialog_open as _attr_dialog_open, _attr_details_or_dialog_open_default as _attr_dialog_open_default, _attr_details_or_dialog_open_script as _attr_dialog_open_script, _attr_input_checked, _attr_input_checked_default, _attr_input_checked_script, _attr_input_checkedValue, _attr_input_checkedValue_default, _attr_input_checkedValue_script, _attr_input_value, _attr_input_value_default, _attr_input_value_script, _attr_select_value, _attr_select_value_default, _attr_select_value_script, _attr_input_value as _attr_textarea_value, _attr_input_value_default as _attr_textarea_value_default, _attr_input_value_script as _attr_textarea_value_script, } from "./dom/controllable";
9
- export { _attr, _attr_class, _attr_class_item, _attr_class_items, _attr_content, _attr_nonce, _attr_style, _attr_style_item, _attr_style_items, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_script, _html, _lifecycle, _text, _text_content, _to_text, } from "./dom/dom";
9
+ export { _attr, _attr_class, _attr_class_item, _attr_class_items, _attr_content, _attr_nonce, _attr_style, _attr_style_item, _attr_style_items, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_script, _html, _lifecycle, _style_rule_item, _style_shell, _text, _text_content, _to_text, } from "./dom/dom";
10
10
  export { _on } from "./dom/event";
11
11
  export { _load_event_trigger, _load_idle_trigger, _load_media_trigger, _load_race_trigger, _load_setup, _load_signal, _load_template, _load_visible_trigger, } from "./dom/load";
12
12
  export { _enable_catch, run } from "./dom/queue";