marko 6.1.23 → 6.2.0

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.
@@ -9,6 +9,7 @@ export declare enum AccessorPrefix {
9
9
  DynamicHTMLLastChild = "H",
10
10
  EventAttributes = "I",
11
11
  Getter = "J",
12
+ KeyedScopes = "O",
12
13
  Lifecycle = "K",
13
14
  Promise = "L",
14
15
  TagVariableChange = "M"
@@ -65,6 +66,9 @@ export declare enum ClosureSignalProp {
65
66
  SignalIndexAccessor = "b",
66
67
  Index = "c"
67
68
  }
69
+ export declare enum KeyedScopesProp {
70
+ PreviousKey = "_"
71
+ }
68
72
  export declare enum LoadSignalValue {
69
73
  Value = "a",
70
74
  Signal = "b"
@@ -9,6 +9,7 @@ export declare enum AccessorPrefix {
9
9
  DynamicHTMLLastChild = "DynamicHTMLLastChild:",
10
10
  EventAttributes = "EventAttributes:",
11
11
  Getter = "Getter:",
12
+ KeyedScopes = "KeyedScopes:",
12
13
  Lifecycle = "Lifecycle:",
13
14
  Promise = "Promise:",
14
15
  TagVariableChange = "TagVariableChange:"
@@ -65,6 +66,9 @@ export declare enum ClosureSignalProp {
65
66
  SignalIndexAccessor = "signalIndexAccessor",
66
67
  Index = "index"
67
68
  }
69
+ export declare enum KeyedScopesProp {
70
+ PreviousKey = "PreviousKey:"
71
+ }
68
72
  export declare enum LoadSignalValue {
69
73
  Value = "value",
70
74
  Signal = "signal"
@@ -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;
@@ -41,7 +41,7 @@ export interface AwaitCounter {
41
41
  i: number;
42
42
  c: () => void | 1;
43
43
  }
44
- export { AccessorPrefix, AccessorProp, ClosureSignalProp, PendingRenderProp, RendererProp, } from "./accessor.debug";
44
+ export { AccessorPrefix, AccessorProp, ClosureSignalProp, KeyedScopesProp, PendingRenderProp, RendererProp, } from "./accessor.debug";
45
45
  export declare enum NodeType {
46
46
  Element = 1,
47
47
  Text = 3,
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, "\\$&").replace(/</g, "\\3C ");
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 = "";
@@ -436,6 +444,44 @@ function _for_closure(ownerLoopNodeAccessor, fn) {
436
444
  ownerSignal._ = fn;
437
445
  return ownerSignal;
438
446
  }
447
+ function _for_selector(ownerLoopNodeAccessor, ownerValueAccessor, keyValueAccessor, fn) {
448
+ const scopeAccessor = "BranchScopes:" + ownerLoopNodeAccessor;
449
+ const mapAccessor = "KeyedScopes:" + ownerLoopNodeAccessor;
450
+ const prevKeyProp = `PreviousKey:${ownerValueAccessor}`;
451
+ const ownerSignal = (ownerScope) => {
452
+ const scopes = toArray(ownerScope[scopeAccessor]);
453
+ if (ownerScope["#Gen"] < runId && scopes.length) {
454
+ const nextKey = ownerScope[ownerValueAccessor];
455
+ queueRender(ownerScope, () => {
456
+ const map = keyedScopes(ownerScope, scopeAccessor, mapAccessor, keyValueAccessor);
457
+ if (map && prevKeyProp in map) {
458
+ const prevScope = map.get(map[prevKeyProp]);
459
+ const nextScope = map.get(nextKey);
460
+ if (prevScope !== nextScope) {
461
+ runLiveBranch(prevScope, fn);
462
+ runLiveBranch(nextScope, fn);
463
+ }
464
+ } else for (const scope of toArray(ownerScope[scopeAccessor])) runLiveBranch(scope, fn);
465
+ if (map) map[prevKeyProp] = nextKey;
466
+ }, -1, 0, scopes[0]["#Id"]);
467
+ }
468
+ };
469
+ ownerSignal._ = fn;
470
+ return ownerSignal;
471
+ }
472
+ function keyedScopes(ownerScope, scopeAccessor, mapAccessor, keyValueAccessor) {
473
+ const map = ownerScope[mapAccessor] ||= /* @__PURE__ */ new Map();
474
+ if (!map.size) for (const scope of toArray(ownerScope[scopeAccessor])) {
475
+ const key = scope["#LoopKey"] ?? scope[keyValueAccessor];
476
+ if (key === void 0) return ownerScope[mapAccessor] = null;
477
+ scope["#LoopKey"] = key;
478
+ map.set(key, scope);
479
+ }
480
+ return map;
481
+ }
482
+ function runLiveBranch(scope, fn) {
483
+ if (scope && scope["#Gen"] > 0 && scope["#Gen"] < runId) fn(scope);
484
+ }
439
485
  function _if_closure(ownerConditionalNodeAccessor, branch, fn) {
440
486
  const scopeAccessor = "BranchScopes:" + ownerConditionalNodeAccessor;
441
487
  const branchAccessor = "ConditionalRenderer:" + ownerConditionalNodeAccessor;
@@ -1137,6 +1183,24 @@ function _attr_style_items(element, items) {
1137
1183
  function _attr_style_item(element, name, value) {
1138
1184
  element.style.setProperty(name, _to_text(value));
1139
1185
  }
1186
+ function _style_shell(scope, nodeAccessor) {
1187
+ const element = scope[nodeAccessor];
1188
+ const id = _id(scope);
1189
+ element.className = id;
1190
+ _text_content(element, "." + id + " ~ *{}");
1191
+ }
1192
+ function _style_rule_item(element, name, value) {
1193
+ const text = element.textContent;
1194
+ const decl = name + ":" + escapeStyleValue(_to_text(value)) + ";";
1195
+ let start = text.indexOf("{" + name + ":");
1196
+ if (start === -1) start = text.indexOf(";" + name + ":");
1197
+ if (start === -1) element.textContent = text.slice(0, -1) + decl + "}";
1198
+ else {
1199
+ let end = ++start;
1200
+ for (let c; (c = text[end]) && c !== ";"; end++) if (c === "\\") end++;
1201
+ element.textContent = text.slice(0, start) + decl + text.slice(end + 1);
1202
+ }
1203
+ }
1140
1204
  function _attr_nonce(scope, nodeAccessor) {
1141
1205
  _attr(scope[nodeAccessor], "nonce", scope["$global"].cspNonce);
1142
1206
  }
@@ -1508,6 +1572,34 @@ function _if(nodeAccessor, ...branchesArgs) {
1508
1572
  if (newBranch !== (scope[branchAccessor] ?? (scope["BranchScopes:" + nodeAccessor] && 0))) setConditionalRenderer(scope, nodeAccessor, branches[scope[branchAccessor] = newBranch], createAndSetupBranch);
1509
1573
  };
1510
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
+ }
1511
1603
  function patchDynamicTag(fn) {
1512
1604
  _dynamic_tag = fn(_dynamic_tag);
1513
1605
  }
@@ -1597,12 +1689,14 @@ const _for_until = /* @__PURE__ */ loop(([until, from, step, by = byFirstArg], c
1597
1689
  function loop(forEach) {
1598
1690
  return (nodeAccessor, template, walks, setup, params) => {
1599
1691
  const scopesAccessor = "BranchScopes:" + nodeAccessor;
1692
+ const keyedScopesAccessor = "KeyedScopes:" + nodeAccessor;
1600
1693
  const renderer = _content("", template, walks, setup)();
1601
1694
  enableBranches();
1602
1695
  return (scope, value) => {
1603
1696
  const referenceNode = scope[nodeAccessor];
1604
1697
  const oldScopes = toArray(scope[scopesAccessor]);
1605
1698
  const newScopes = scope[scopesAccessor] = [];
1699
+ scope[keyedScopesAccessor] = null;
1606
1700
  const oldLen = oldScopes.length;
1607
1701
  const parentNode = referenceNode.nodeType > 1 ? referenceNode.parentNode || oldScopes[0]?.["#StartNode"].parentNode : referenceNode;
1608
1702
  let oldScopesByKey;
@@ -1977,8 +2071,8 @@ function mount(input = {}, reference, position) {
1977
2071
  renderId: "_",
1978
2072
  ...$global
1979
2073
  };
1980
- 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.`);
1981
- 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.`);
1982
2076
  } else $global = {
1983
2077
  runtimeId: "M",
1984
2078
  renderId: "_"
@@ -2186,6 +2280,7 @@ exports._enable_catch = _enable_catch;
2186
2280
  exports._for_closure = _for_closure;
2187
2281
  exports._for_in = _for_in;
2188
2282
  exports._for_of = _for_of;
2283
+ exports._for_selector = _for_selector;
2189
2284
  exports._for_to = _for_to;
2190
2285
  exports._for_until = _for_until;
2191
2286
  exports._hoist = _hoist;
@@ -2212,6 +2307,9 @@ exports._resume_dynamic_tag = _resume_dynamic_tag;
2212
2307
  exports._return = _return;
2213
2308
  exports._return_change = _return_change;
2214
2309
  exports._script = _script;
2310
+ exports._show = _show;
2311
+ exports._style_rule_item = _style_rule_item;
2312
+ exports._style_shell = _style_shell;
2215
2313
  exports._template = _template;
2216
2314
  exports._text = _text;
2217
2315
  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, "\\$&").replace(/</g, "\\3C ");
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 = "";
@@ -434,6 +442,44 @@ function _for_closure(ownerLoopNodeAccessor, fn) {
434
442
  ownerSignal._ = fn;
435
443
  return ownerSignal;
436
444
  }
445
+ function _for_selector(ownerLoopNodeAccessor, ownerValueAccessor, keyValueAccessor, fn) {
446
+ const scopeAccessor = "BranchScopes:" + ownerLoopNodeAccessor;
447
+ const mapAccessor = "KeyedScopes:" + ownerLoopNodeAccessor;
448
+ const prevKeyProp = `PreviousKey:${ownerValueAccessor}`;
449
+ const ownerSignal = (ownerScope) => {
450
+ const scopes = toArray(ownerScope[scopeAccessor]);
451
+ if (ownerScope["#Gen"] < runId && scopes.length) {
452
+ const nextKey = ownerScope[ownerValueAccessor];
453
+ queueRender(ownerScope, () => {
454
+ const map = keyedScopes(ownerScope, scopeAccessor, mapAccessor, keyValueAccessor);
455
+ if (map && prevKeyProp in map) {
456
+ const prevScope = map.get(map[prevKeyProp]);
457
+ const nextScope = map.get(nextKey);
458
+ if (prevScope !== nextScope) {
459
+ runLiveBranch(prevScope, fn);
460
+ runLiveBranch(nextScope, fn);
461
+ }
462
+ } else for (const scope of toArray(ownerScope[scopeAccessor])) runLiveBranch(scope, fn);
463
+ if (map) map[prevKeyProp] = nextKey;
464
+ }, -1, 0, scopes[0]["#Id"]);
465
+ }
466
+ };
467
+ ownerSignal._ = fn;
468
+ return ownerSignal;
469
+ }
470
+ function keyedScopes(ownerScope, scopeAccessor, mapAccessor, keyValueAccessor) {
471
+ const map = ownerScope[mapAccessor] ||= /* @__PURE__ */ new Map();
472
+ if (!map.size) for (const scope of toArray(ownerScope[scopeAccessor])) {
473
+ const key = scope["#LoopKey"] ?? scope[keyValueAccessor];
474
+ if (key === void 0) return ownerScope[mapAccessor] = null;
475
+ scope["#LoopKey"] = key;
476
+ map.set(key, scope);
477
+ }
478
+ return map;
479
+ }
480
+ function runLiveBranch(scope, fn) {
481
+ if (scope && scope["#Gen"] > 0 && scope["#Gen"] < runId) fn(scope);
482
+ }
437
483
  function _if_closure(ownerConditionalNodeAccessor, branch, fn) {
438
484
  const scopeAccessor = "BranchScopes:" + ownerConditionalNodeAccessor;
439
485
  const branchAccessor = "ConditionalRenderer:" + ownerConditionalNodeAccessor;
@@ -1135,6 +1181,24 @@ function _attr_style_items(element, items) {
1135
1181
  function _attr_style_item(element, name, value) {
1136
1182
  element.style.setProperty(name, _to_text(value));
1137
1183
  }
1184
+ function _style_shell(scope, nodeAccessor) {
1185
+ const element = scope[nodeAccessor];
1186
+ const id = _id(scope);
1187
+ element.className = id;
1188
+ _text_content(element, "." + id + " ~ *{}");
1189
+ }
1190
+ function _style_rule_item(element, name, value) {
1191
+ const text = element.textContent;
1192
+ const decl = name + ":" + escapeStyleValue(_to_text(value)) + ";";
1193
+ let start = text.indexOf("{" + name + ":");
1194
+ if (start === -1) start = text.indexOf(";" + name + ":");
1195
+ if (start === -1) element.textContent = text.slice(0, -1) + decl + "}";
1196
+ else {
1197
+ let end = ++start;
1198
+ for (let c; (c = text[end]) && c !== ";"; end++) if (c === "\\") end++;
1199
+ element.textContent = text.slice(0, start) + decl + text.slice(end + 1);
1200
+ }
1201
+ }
1138
1202
  function _attr_nonce(scope, nodeAccessor) {
1139
1203
  _attr(scope[nodeAccessor], "nonce", scope["$global"].cspNonce);
1140
1204
  }
@@ -1506,6 +1570,34 @@ function _if(nodeAccessor, ...branchesArgs) {
1506
1570
  if (newBranch !== (scope[branchAccessor] ?? (scope["BranchScopes:" + nodeAccessor] && 0))) setConditionalRenderer(scope, nodeAccessor, branches[scope[branchAccessor] = newBranch], createAndSetupBranch);
1507
1571
  };
1508
1572
  }
1573
+ function _show(nodeAccessor, startNodeAccessor) {
1574
+ const rangeAccessor = "BranchScopes:" + nodeAccessor;
1575
+ enableBranches();
1576
+ return (scope, display) => {
1577
+ const referenceNode = scope[nodeAccessor];
1578
+ const onlyChild = referenceNode.nodeType === 1;
1579
+ const parentNode = onlyChild ? referenceNode : referenceNode.parentNode;
1580
+ let range = scope[rangeAccessor];
1581
+ if (!range) {
1582
+ range = scope[rangeAccessor] = {};
1583
+ range["#StartNode"] = onlyChild ? parentNode.firstChild : scope[startNodeAccessor];
1584
+ range["#EndNode"] = onlyChild ? parentNode.lastChild : referenceNode.previousSibling;
1585
+ }
1586
+ let startNode = range["#StartNode"];
1587
+ if (range["#Id"] && startNode === range["#EndNode"] && startNode.tagName === "T") {
1588
+ const wrapper = startNode;
1589
+ if (!wrapper.firstChild) wrapper.appendChild(new Text());
1590
+ range = scope[rangeAccessor] = {};
1591
+ range["#StartNode"] = startNode = wrapper.firstChild;
1592
+ range["#EndNode"] = wrapper.lastChild;
1593
+ wrapper.replaceWith(...wrapper.childNodes);
1594
+ }
1595
+ const inDom = startNode.parentNode === parentNode;
1596
+ if (display) {
1597
+ if (!inDom) insertBranchBefore(range, parentNode, onlyChild ? null : referenceNode);
1598
+ } else if (inDom) tempDetachBranch(range);
1599
+ };
1600
+ }
1509
1601
  function patchDynamicTag(fn) {
1510
1602
  _dynamic_tag = fn(_dynamic_tag);
1511
1603
  }
@@ -1595,12 +1687,14 @@ const _for_until = /* @__PURE__ */ loop(([until, from, step, by = byFirstArg], c
1595
1687
  function loop(forEach) {
1596
1688
  return (nodeAccessor, template, walks, setup, params) => {
1597
1689
  const scopesAccessor = "BranchScopes:" + nodeAccessor;
1690
+ const keyedScopesAccessor = "KeyedScopes:" + nodeAccessor;
1598
1691
  const renderer = _content("", template, walks, setup)();
1599
1692
  enableBranches();
1600
1693
  return (scope, value) => {
1601
1694
  const referenceNode = scope[nodeAccessor];
1602
1695
  const oldScopes = toArray(scope[scopesAccessor]);
1603
1696
  const newScopes = scope[scopesAccessor] = [];
1697
+ scope[keyedScopesAccessor] = null;
1604
1698
  const oldLen = oldScopes.length;
1605
1699
  const parentNode = referenceNode.nodeType > 1 ? referenceNode.parentNode || oldScopes[0]?.["#StartNode"].parentNode : referenceNode;
1606
1700
  let oldScopesByKey;
@@ -1975,8 +2069,8 @@ function mount(input = {}, reference, position) {
1975
2069
  renderId: "_",
1976
2070
  ...$global
1977
2071
  };
1978
- 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.`);
1979
- 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.`);
2072
+ 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.`);
2073
+ 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.`);
1980
2074
  } else $global = {
1981
2075
  runtimeId: "M",
1982
2076
  renderId: "_"
@@ -2122,4 +2216,4 @@ function getSelectorOrResolve(selector, resolve) {
2122
2216
  return document.querySelector(selector) || (console.warn(`A lazy load trigger could not find an element matching "${selector}". The module was loaded immediately.`), resolve());
2123
2217
  }
2124
2218
  //#endregion
2125
- 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_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 };
2219
+ 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, "\\$&").replace(/</g, "\\3C ");
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) {
@@ -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();
@@ -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,7 +2327,7 @@ 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
  }
@@ -2523,6 +2542,10 @@ function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange, s
2523
2542
  function _attr_nonce() {
2524
2543
  return getChunk().boundary.state.nonceAttr;
2525
2544
  }
2545
+ function _style_html(decls) {
2546
+ const id = _id();
2547
+ return `<style${_attr_nonce()} class=${id}>.${id} ~ *{${decls}}</style>`;
2548
+ }
2526
2549
  function _attr(name, value) {
2527
2550
  return isVoid(value) ? "" : nonVoidAttr(name, value);
2528
2551
  }
@@ -2758,8 +2781,8 @@ function render(input = {}) {
2758
2781
  renderId: getDefaultRenderId(this),
2759
2782
  ...$global
2760
2783
  };
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.`);
2784
+ 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.`);
2785
+ 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
2786
  } else $global = {
2764
2787
  runtimeId: "M",
2765
2788
  renderId: getDefaultRenderId(this)
@@ -2772,10 +2795,10 @@ function render(input = {}) {
2772
2795
  }
2773
2796
  function getDefaultRenderId(template) {
2774
2797
  if (template["embed"]) {
2775
- const ENCODE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789";
2798
+ const ENCODE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
2776
2799
  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];
2800
+ let r = ENCODE_CHARS[n % 52];
2801
+ for (n = n / 52 | 0; n; n = n / 63 | 0) r += ENCODE_CHARS[n % 63];
2779
2802
  return r;
2780
2803
  }
2781
2804
  return "_";
@@ -3197,6 +3220,7 @@ exports._escape = _escape;
3197
3220
  exports._escape_comment = _escape_comment;
3198
3221
  exports._escape_script = _escape_script;
3199
3222
  exports._escape_style = _escape_style;
3223
+ exports._escape_style_value = _escape_style_value;
3200
3224
  exports._existing_scope = _existing_scope;
3201
3225
  exports._flush_head = _flush_head;
3202
3226
  exports._for_in = _for_in;
@@ -3225,6 +3249,9 @@ exports._sep = _sep;
3225
3249
  exports._serialize_guard = _serialize_guard;
3226
3250
  exports._serialize_if = _serialize_if;
3227
3251
  exports._set_serialize_reason = _set_serialize_reason;
3252
+ exports._show_end = _show_end;
3253
+ exports._show_start = _show_start;
3254
+ exports._style_html = _style_html;
3228
3255
  exports._subscribe = _subscribe;
3229
3256
  exports._template = _template;
3230
3257
  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, "\\$&").replace(/</g, "\\3C ");
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) {
@@ -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();
@@ -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,7 +2325,7 @@ 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
  }
@@ -2521,6 +2540,10 @@ function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange, s
2521
2540
  function _attr_nonce() {
2522
2541
  return getChunk().boundary.state.nonceAttr;
2523
2542
  }
2543
+ function _style_html(decls) {
2544
+ const id = _id();
2545
+ return `<style${_attr_nonce()} class=${id}>.${id} ~ *{${decls}}</style>`;
2546
+ }
2524
2547
  function _attr(name, value) {
2525
2548
  return isVoid(value) ? "" : nonVoidAttr(name, value);
2526
2549
  }
@@ -2756,8 +2779,8 @@ function render(input = {}) {
2756
2779
  renderId: getDefaultRenderId(this),
2757
2780
  ...$global
2758
2781
  };
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.`);
2782
+ 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.`);
2783
+ 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
2784
  } else $global = {
2762
2785
  runtimeId: "M",
2763
2786
  renderId: getDefaultRenderId(this)
@@ -2770,10 +2793,10 @@ function render(input = {}) {
2770
2793
  }
2771
2794
  function getDefaultRenderId(template) {
2772
2795
  if (template["embed"]) {
2773
- const ENCODE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789";
2796
+ const ENCODE_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
2774
2797
  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];
2798
+ let r = ENCODE_CHARS[n % 52];
2799
+ for (n = n / 52 | 0; n; n = n / 63 | 0) r += ENCODE_CHARS[n % 63];
2777
2800
  return r;
2778
2801
  }
2779
2802
  return "_";
@@ -3157,4 +3180,4 @@ const compat = {
3157
3180
  };
3158
3181
  function NOOP() {}
3159
3182
  //#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 };
3183
+ 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;
@@ -6,6 +6,7 @@ export declare function _let_change<T>(id: EncodedAccessor, fn?: SignalFn): (sco
6
6
  export declare function _const<T>(valueAccessor: EncodedAccessor, fn?: SignalFn): Signal<T>;
7
7
  export declare function _or(id: number, fn: SignalFn, defaultPending?: number, scopeIdAccessor?: EncodedAccessor): Signal<never>;
8
8
  export declare function _for_closure(ownerLoopNodeAccessor: EncodedAccessor, fn: SignalFn): SignalFn;
9
+ export declare function _for_selector(ownerLoopNodeAccessor: EncodedAccessor, ownerValueAccessor: EncodedAccessor, keyValueAccessor: EncodedAccessor, fn: SignalFn): SignalFn;
9
10
  export declare function _if_closure(ownerConditionalNodeAccessor: EncodedAccessor, branch: number, fn: SignalFn): SignalFn;
10
11
  export declare function subscribeToScopeSet(ownerScope: Scope, accessor: Accessor, scope: Scope): void;
11
12
  export declare function _closure(...closureSignals: ReturnType<typeof _closure_get>[]): (scope: Scope) => void;