marko 6.1.18 → 6.1.21

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.
@@ -875,8 +875,11 @@ function writeDate(state, val) {
875
875
  state.buf.push("new Date(" + +val + ")");
876
876
  return true;
877
877
  }
878
+ const unsafeRegExpSourceReg = /\\[\s\S]|</g;
879
+ const replaceUnsafeRegExpSourceChar = (match) => match === "<" || match === "\\<" ? "\\x3C" : match;
878
880
  function writeRegExp(state, val) {
879
- state.buf.push(val + "");
881
+ const { source } = val;
882
+ state.buf.push("/" + (source.includes("<") ? source.replace(unsafeRegExpSourceReg, replaceUnsafeRegExpSourceChar) : source) + "/" + val.flags);
880
883
  return true;
881
884
  }
882
885
  function writePromise(state, val, ref) {
@@ -1006,7 +1009,7 @@ function writeWeakMap(state) {
1006
1009
  }
1007
1010
  function writeError(state, val, ref) {
1008
1011
  const result = "new " + val.constructor.name + "(" + quote(val.message + "", 0);
1009
- if (val.cause) {
1012
+ if (val.cause !== void 0) {
1010
1013
  state.buf.push(result + ",{cause:");
1011
1014
  writeProp(state, val.cause, ref, "cause");
1012
1015
  state.buf.push("})");
@@ -2462,7 +2465,8 @@ function _attr_style(value) {
2462
2465
  }
2463
2466
  function _attr_option_value(value) {
2464
2467
  const valueAttr = _attr("value", value);
2465
- if (normalizedValueMatches(getContext(kSelectedValue), value)) {
2468
+ const selectedValue = getContext(kSelectedValue);
2469
+ if (selectedValue !== void 0 && normalizedValueMatches(selectedValue, value)) {
2466
2470
  {
2467
2471
  const matched = getContext(kSelectedValueMatched);
2468
2472
  if (matched) matched.value = true;
@@ -2473,29 +2477,29 @@ function _attr_option_value(value) {
2473
2477
  }
2474
2478
  const kSelectedValue = Symbol("selectedValue");
2475
2479
  const kSelectedValueMatched = Symbol("selectedValueMatched");
2476
- function _attr_select_value(scopeId, nodeAccessor, value, valueChange, content) {
2477
- if (valueChange) writeControlledScope(3, scopeId, nodeAccessor, void 0, valueChange);
2480
+ function _attr_select_value(scopeId, nodeAccessor, value, valueChange, content, serializeType) {
2481
+ if (valueChange) writeControlledScope(3, scopeId, nodeAccessor, void 0, valueChange, serializeType);
2478
2482
  if (content) if (valueChange) {
2479
2483
  const matched = { value: false };
2480
2484
  withContext(kSelectedValue, value, () => withContext(kSelectedValueMatched, matched, content));
2481
2485
  if (!matched.value && (Array.isArray(value) ? value.some((v) => normalizeStrAttrValue(v) !== "") : normalizeStrAttrValue(value) !== "")) console.error("A controlled `<select>`'s `value` has no matching `<option>`:", value);
2482
2486
  } else withContext(kSelectedValue, value, content);
2483
2487
  }
2484
- function _attr_textarea_value(scopeId, nodeAccessor, value, valueChange) {
2485
- if (valueChange) writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange);
2488
+ function _attr_textarea_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
2489
+ if (valueChange) writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType);
2486
2490
  return _escape(value);
2487
2491
  }
2488
- function _attr_input_value(scopeId, nodeAccessor, value, valueChange) {
2489
- if (valueChange) writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange);
2492
+ function _attr_input_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
2493
+ if (valueChange) writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType);
2490
2494
  return _attr("value", value);
2491
2495
  }
2492
- function _attr_input_checked(scopeId, nodeAccessor, checked, checkedChange) {
2493
- if (checkedChange) writeControlledScope(0, scopeId, nodeAccessor, void 0, checkedChange);
2496
+ function _attr_input_checked(scopeId, nodeAccessor, checked, checkedChange, serializeType) {
2497
+ if (checkedChange) writeControlledScope(0, scopeId, nodeAccessor, void 0, checkedChange, serializeType);
2494
2498
  return isNotVoid(checked) ? " checked" : "";
2495
2499
  }
2496
- function _attr_input_checkedValue(scopeId, nodeAccessor, checkedValue, checkedValueChange, value) {
2500
+ function _attr_input_checkedValue(scopeId, nodeAccessor, checkedValue, checkedValueChange, value, serializeType) {
2497
2501
  const valueAttr = _attr("value", value);
2498
- if (checkedValueChange) writeControlledScope(1, scopeId, nodeAccessor, getCheckedValueRef(checkedValue), checkedValueChange);
2502
+ if (checkedValueChange) writeControlledScope(1, scopeId, nodeAccessor, getCheckedValueRef(checkedValue), checkedValueChange, serializeType);
2499
2503
  return normalizedValueMatches(checkedValue, value) ? valueAttr + " checked" : valueAttr;
2500
2504
  }
2501
2505
  const checkedValuesRefs = /* @__PURE__ */ new WeakMap();
@@ -2509,9 +2513,9 @@ function getCheckedValueRef(checkedValue) {
2509
2513
  return ref;
2510
2514
  }
2511
2515
  }
2512
- function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange) {
2516
+ function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange, serializeType) {
2513
2517
  const normalizedOpen = isNotVoid(open);
2514
- if (openChange) writeControlledScope(4, scopeId, nodeAccessor, normalizedOpen || void 0, openChange);
2518
+ if (openChange) writeControlledScope(4, scopeId, nodeAccessor, normalizedOpen || void 0, openChange, serializeType);
2515
2519
  return normalizedOpen ? " open" : "";
2516
2520
  }
2517
2521
  function _attr_nonce() {
@@ -2527,11 +2531,16 @@ function _attrs(data, nodeAccessor, scopeId, tagName) {
2527
2531
  switch (tagName) {
2528
2532
  case "input":
2529
2533
  assertExclusiveAttrs(data);
2530
- if (data.checkedChange) result += _attr_input_checked(scopeId, nodeAccessor, data.checked, data.checkedChange);
2531
- else if ("checkedValue" in data || data.checkedValueChange) result += _attr_input_checkedValue(scopeId, nodeAccessor, data.checkedValue, data.checkedValueChange, data.value);
2532
- else if (data.valueChange) result += _attr_input_value(scopeId, nodeAccessor, data.value, data.valueChange);
2533
- else break;
2534
- skip = /^(?:value|checked(?:Value)?)(?:Change)?$|[\s/>"'=]/;
2534
+ if (data.checkedChange) {
2535
+ result += _attr_input_checked(scopeId, nodeAccessor, data.checked, data.checkedChange, 1);
2536
+ skip = /^checked(?:Value)?(?:Change)?$|[\s/>"'=]/;
2537
+ } else if ("checkedValue" in data || data.checkedValueChange) {
2538
+ result += _attr_input_checkedValue(scopeId, nodeAccessor, data.checkedValue, data.checkedValueChange, data.value, 1);
2539
+ skip = /^(?:value|checked(?:Value)?)(?:Change)?$|[\s/>"'=]/;
2540
+ } else if (data.valueChange) {
2541
+ result += _attr_input_value(scopeId, nodeAccessor, data.value, data.valueChange, 1);
2542
+ skip = /^value(?:Change)?$|[\s/>"'=]/;
2543
+ } else break;
2535
2544
  break;
2536
2545
  case "select":
2537
2546
  case "textarea":
@@ -2546,7 +2555,7 @@ function _attrs(data, nodeAccessor, scopeId, tagName) {
2546
2555
  case "details":
2547
2556
  case "dialog":
2548
2557
  if (data.openChange) {
2549
- result += _attr_details_or_dialog_open(scopeId, nodeAccessor, data.open, data.openChange);
2558
+ result += _attr_details_or_dialog_open(scopeId, nodeAccessor, data.open, data.openChange, 1);
2550
2559
  skip = /^open(?:Change)?$|[\s/>"'=]/;
2551
2560
  }
2552
2561
  break;
@@ -2592,12 +2601,15 @@ function _attrs_partial_content(data, skip, nodeAccessor, scopeId, tagName, seri
2592
2601
  _html(`${_attrs_partial(data, skip, nodeAccessor, scopeId, tagName)}>`);
2593
2602
  _attr_content(nodeAccessor, scopeId, data?.content, serializeReason);
2594
2603
  }
2595
- function writeControlledScope(type, scopeId, nodeAccessor, value, valueChange) {
2604
+ function writeControlledScope(type, scopeId, nodeAccessor, value, valueChange, serializeType) {
2596
2605
  assertHandlerIsFunction("valueChange", valueChange);
2597
- writeScope(scopeId, {
2606
+ writeScope(scopeId, serializeType ? {
2598
2607
  ["ControlledType:" + nodeAccessor]: type,
2599
2608
  ["ControlledValue:" + nodeAccessor]: value,
2600
2609
  ["ControlledHandler:" + nodeAccessor]: valueChange
2610
+ } : {
2611
+ ["ControlledValue:" + nodeAccessor]: value,
2612
+ ["ControlledHandler:" + nodeAccessor]: valueChange
2601
2613
  });
2602
2614
  }
2603
2615
  function stringAttr(name, value) {
@@ -2663,10 +2675,10 @@ let _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, s
2663
2675
  const renderContent = content || normalizeDynamicRenderer(input.content);
2664
2676
  if (renderer === "textarea") {
2665
2677
  if (renderContent) throw new Error("A dynamic tag rendering a `<textarea>` cannot have `content` and must use the `value` attribute instead.");
2666
- _html(_attr_textarea_value(branchId, `#${renderer}/0`, input.value, input.valueChange));
2678
+ _html(_attr_textarea_value(branchId, `#${renderer}/0`, input.value, input.valueChange, 1));
2667
2679
  } else if (renderContent) {
2668
2680
  if (typeof renderContent !== "function") throw new Error(`Body content is not supported for the \`<${renderer}>\` tag.`);
2669
- if (renderer === "select" && ("value" in input || "valueChange" in input)) _attr_select_value(branchId, `#${renderer}/0`, input.value, input.valueChange, renderContent);
2681
+ if (renderer === "select" && ("value" in input || "valueChange" in input)) _attr_select_value(branchId, `#${renderer}/0`, input.value, input.valueChange, renderContent, 1);
2670
2682
  else _dynamic_tag(branchId, `#${renderer}/0`, renderContent, void 0, 0, void 0, serializeReason);
2671
2683
  }
2672
2684
  _html(`</${renderer}>`);
@@ -1,4 +1,4 @@
1
1
  type EventNames = keyof GlobalEventHandlersEventMap;
2
2
  export declare function _on<T extends EventNames, H extends false | null | undefined | ((ev: GlobalEventHandlersEventMap[T], target: Element) => void)>(element: Element, type: T, handler: H): void;
3
- export declare function createDelegator(): (node: Node, type: string, handler: EventListener) => void;
3
+ export declare const delegate: (type: string, handler: EventListener) => any;
4
4
  export {};
package/dist/dom.js CHANGED
@@ -4,7 +4,7 @@ let empty = [], rest = Symbol(), toDelimitedString = function toDelimitedString(
4
4
  else if (Array.isArray(val)) for (let v of val) part = toDelimitedString(v, delimiter, stringify), part && (str += sep + part, sep = delimiter);
5
5
  else for (let name in val) part = stringify(name, val[name]), part && (str += sep + part, sep = delimiter);
6
6
  return str;
7
- }, decodeAccessor = (num) => (num + (num < 26 ? 10 : num < 962 ? 334 : 11998)).toString(36), defaultDelegator = /* @__PURE__ */ createDelegator(), R = /[^\p{L}\p{N}]/gu, parsers = {}, nextScopeId = 1e6, collectingScopes, destroyNestedScopes = function destroyNestedScopes(scope) {
7
+ }, decodeAccessor = (num) => (num + (num < 26 ? 10 : num < 962 ? 334 : 11998)).toString(36), delegate = (type, handler) => handler[type] ||= (document.addEventListener(type, handler, !0), 1), R = /[^\p{L}\p{N}]/gu, parsers = {}, nextScopeId = 1e6, collectingScopes, destroyNestedScopes = function destroyNestedScopes(scope) {
8
8
  scope.H = 0, scope.D?.forEach(destroyNestedScopes), scope.B?.forEach(resetControllers);
9
9
  }, isScheduled, channel, _return = (scope, value) => scope.T?.(value), _var_change = (scope, value) => scope.U?.(value), tagIdsByGlobal = /* @__PURE__ */ new WeakMap(), walker = /* @__PURE__ */ document.createTreeWalker(document), walkInternal = function walkInternal(currentWalkIndex, walkCodes, scope) {
10
10
  let value, currentMultiplier, storedMultiplier = 0, currentScopeIndex = 0;
@@ -20,7 +20,7 @@ let empty = [], rest = Symbol(), toDelimitedString = function toDelimitedString(
20
20
  for (value = 10 * currentMultiplier + value - 107; value--;) walker.parentNode();
21
21
  walker.nextSibling();
22
22
  } else storedMultiplier = currentMultiplier * 10 + value - 117;
23
- }, cloneCache = {}, registeredValues = {}, curRenders, branchesEnabled, embedRenders, readyIds, isResuming, inputType = "", controllableDelegate = /* @__PURE__ */ createDelegator(), _dynamic_tag = function(nodeAccessor, getContent, getTagVar, inputIsArgs) {
23
+ }, cloneCache = {}, registeredValues = {}, curRenders, branchesEnabled, embedRenders, readyIds, isResuming, inputType = "", _dynamic_tag = function(nodeAccessor, getContent, getTagVar, inputIsArgs) {
24
24
  nodeAccessor = decodeAccessor(nodeAccessor);
25
25
  let childScopeAccessor = "A" + nodeAccessor, rendererAccessor = "D" + nodeAccessor;
26
26
  return enableBranches(), (scope, newRenderer, getInput) => {
@@ -98,7 +98,7 @@ let empty = [], rest = Symbol(), toDelimitedString = function toDelimitedString(
98
98
  },
99
99
  render(out, component, renderer, args) {
100
100
  let branch = component.scope, created = 0;
101
- if (!branch && (branch = classIdToBranch.get(component.id)) && (component.scope = branch, classIdToBranch.delete(component.id)), typeof args[0] == "object" && "renderBody" in args[0]) {
101
+ if (!branch && (branch = classIdToBranch.get(component.id)) && (component.scope = branch, classIdToBranch.delete(component.id)), args[0] && typeof args[0] == "object" && "renderBody" in args[0]) {
102
102
  let input = args[0], normalizedInput = args[0] = {};
103
103
  for (let key in input) normalizedInput[key === "renderBody" ? "content" : key] = input[key];
104
104
  }
@@ -182,14 +182,7 @@ function push(opt, item) {
182
182
  //#endregion
183
183
  //#region src/dom/event.ts
184
184
  function _on(element, type, handler) {
185
- element["$" + type] === void 0 && defaultDelegator(element, type, handleDelegated), element["$" + type] = handler || null;
186
- }
187
- /* @__NO_SIDE_EFFECTS__ */
188
- function createDelegator() {
189
- let kEvents = Symbol();
190
- return function(node, type, handler) {
191
- ((node = node.getRootNode())[kEvents] ||= {})[type] ||= (node.addEventListener(type, handler, !0), 1);
192
- };
185
+ element["$" + type] === void 0 && delegate(type, handleDelegated), element["$" + type] = handler || null;
193
186
  }
194
187
  function handleDelegated(ev) {
195
188
  let target = !rendering && ev.target;
@@ -464,20 +457,24 @@ function init(runtimeId = "M") {
464
457
  let partial = partials[i];
465
458
  typeof partial == "number" ? scopeId += partial : (scopeId ? initScope(Object.assign(scopeLookup[scopeId] ||= (partial.L = scopeId, partial), partial)) : Object.assign(initGlobal(), partial), scopeId++);
466
459
  }
467
- }, serializeContext = ((data, registryId) => typeof data == "number" ? registryId ? registeredValues[registryId](getScope(data)) : getScope(data) : applyScopes(data)), createVisitBranches = (branchScopesStack = [], branchStarts = [], orphanBranches = [], curBranchScopes) => (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
460
+ }, serializeContext = ((data, registryId) => typeof data == "number" ? registryId ? registeredValues[registryId](getScope(data)) : getScope(data) : applyScopes(data)), createVisitBranches = (branchScopesStack = [], branchStarts = [], orphanBranches = [], deferredOwners = [], curBranchScopes) => (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length, j = deferredOwners.length) => {
468
461
  for (visitType !== "[" && (visitScope[nextToken()] = visitType === ")" || visitType === "}" ? parent : visit, accessor = "A" + lastToken, singleNode = visitType !== "]" && visitType !== ")", nextToken()); branchId = +lastToken;) {
469
462
  if ((endedBranches ||= []).push(branch = getScope(branchId)), setParentBranch(branch, branch.F), (branch.O = render.p?.[branchId]) && (branch.O.m = render.m), singleNode) {
470
463
  for (; startVisit.previousSibling && ~visits.indexOf(startVisit = startVisit.previousSibling););
471
464
  branch.K = branch.S = startVisit, visitType === "'" && (branch.a = startVisit);
472
465
  } else curBranchScopes = push(curBranchScopes, branch), accessor && (visitScope[accessor] = curBranchScopes, curBranchScopes = branchScopesStack.pop()), startVisit = branchStarts.pop(), parent !== startVisit.parentNode && parent.prepend(startVisit), branch.S = startVisit, branch.K = visit.previousSibling === startVisit ? startVisit : parent.insertBefore(new Text(), visit);
473
466
  for (; i && orphanBranches[--i].L > branchId;) setParentBranch(orphanBranches.pop(), branch);
467
+ for (; j && deferredOwners[--j].L > branchId;) {
468
+ let owner = deferredOwners.pop();
469
+ owner.F !== owner && (owner.F = branch);
470
+ }
474
471
  nextToken();
475
472
  }
476
473
  if (endedBranches) {
477
474
  for (let ended of endedBranches) orphanBranches.push(ended);
478
475
  singleNode && (visitScope[accessor] = endedBranches.length > 1 ? endedBranches.reverse() : endedBranches[0]);
479
476
  }
480
- visitType === "[" && (endedBranches || (branchScopesStack.push(curBranchScopes), curBranchScopes = void 0), branchStarts.push(visit));
477
+ visitType === "[" ? (endedBranches || (branchScopesStack.push(curBranchScopes), curBranchScopes = void 0), branchStarts.push(visit)) : deferredOwners.push(visitScope);
481
478
  }, nextToken = () => lastToken = visitText.slice(lastTokenIndex, (lastTokenIndex = visitText.indexOf(" ", lastTokenIndex) + 1 || visitText.length + 1) - 1), processResumes = (resumes = [], effects) => {
482
479
  let i = 0;
483
480
  for (; i < resumes.length; i++) {
@@ -577,7 +574,7 @@ function _attr_input_checkedValue_script(scope, nodeAccessor) {
577
574
  let checkedValueChange = scope["E" + nodeAccessor];
578
575
  if (checkedValueChange) {
579
576
  let oldValue = scope["G" + nodeAccessor], newValue = Array.isArray(oldValue) ? updateList(oldValue, el.value, el.checked) : el.checked ? el.value : void 0;
580
- if (el.name && el.type[0] === "r") for (let radio of el.getRootNode().querySelectorAll(`[type=radio][name=${CSS.escape(el.name)}]`)) radio.form === el.form && (radio.checked = Array.isArray(oldValue) ? oldValue.includes(radio.value) : oldValue === radio.value);
577
+ if (el.name && el.type[0] === "r") for (let radio of document.querySelectorAll(`[type=radio][name=${CSS.escape(el.name)}]`)) radio.form === el.form && (radio.checked = Array.isArray(oldValue) ? oldValue.includes(radio.value) : oldValue === radio.value);
581
578
  else el.checked = !el.checked;
582
579
  checkedValueChange(newValue), run();
583
580
  }
@@ -603,7 +600,7 @@ function _attr_input_value_script(scope, nodeAccessor) {
603
600
  }
604
601
  function setInputValue(el, value) {
605
602
  if (el.value !== value) {
606
- let updatedPosition = resolveCursorPosition(inputType, el.getRootNode().activeElement === el && el.selectionStart, el.value, el.value = value);
603
+ let updatedPosition = resolveCursorPosition(inputType, document.activeElement === el && el.selectionStart, el.value, el.value = value);
607
604
  ~updatedPosition && el.setSelectionRange(updatedPosition, updatedPosition);
608
605
  }
609
606
  }
@@ -675,7 +672,7 @@ function _attr_details_or_dialog_open_script(scope, nodeAccessor) {
675
672
  });
676
673
  }
677
674
  function syncControllableFormInput(el, hasChanged, onChange) {
678
- el._ = onChange, controllableDelegate(el, "input", handleChange), el.form && controllableDelegate(el.form, "reset", handleFormReset), isResuming && hasChanged(el) && queueMicrotask(onChange);
675
+ el._ = onChange, delegate("input", handleChange), el.form && delegate("reset", handleFormReset), isResuming && hasChanged(el) && queueMicrotask(onChange);
679
676
  }
680
677
  function handleChange(ev) {
681
678
  ev.target._?.(ev);
@@ -780,11 +777,10 @@ function attrsInternal(scope, nodeAccessor, nextAttrs) {
780
777
  for (let name in events) events[name] = 0;
781
778
  switch (scope["F" + nodeAccessor] = 5, scope["E" + nodeAccessor] = 0, el.tagName) {
782
779
  case "INPUT":
783
- if ("checked" in nextAttrs || "checkedChange" in nextAttrs) _attr_input_checked(scope, nodeAccessor, nextAttrs.checked, nextAttrs.checkedChange);
784
- else if ("checkedValue" in nextAttrs || "checkedValueChange" in nextAttrs) _attr_input_checkedValue(scope, nodeAccessor, nextAttrs.checkedValue, nextAttrs.checkedValueChange, nextAttrs.value);
785
- else if ("value" in nextAttrs || "valueChange" in nextAttrs) _attr_input_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange);
780
+ if ("checked" in nextAttrs || "checkedChange" in nextAttrs) _attr_input_checked(scope, nodeAccessor, nextAttrs.checked, nextAttrs.checkedChange), skip = /^checked(?:Value)?(?:Change)?$/;
781
+ else if ("checkedValue" in nextAttrs || "checkedValueChange" in nextAttrs) _attr_input_checkedValue(scope, nodeAccessor, nextAttrs.checkedValue, nextAttrs.checkedValueChange, nextAttrs.value), skip = /^(?:value|checked(?:Value)?)(?:Change)?$/;
782
+ else if ("value" in nextAttrs || "valueChange" in nextAttrs) _attr_input_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange), skip = /^value(?:Change)?$/;
786
783
  else break;
787
- skip = /^(?:value|checked(?:Value)?)(?:Change)?$/;
788
784
  break;
789
785
  case "SELECT":
790
786
  ("value" in nextAttrs || "valueChange" in nextAttrs) && (_attr_select_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange), skip = /^value(?:Change)?$/);
@@ -891,7 +887,14 @@ function _await_promise(nodeAccessor, params) {
891
887
  i: 0,
892
888
  c() {
893
889
  if (--awaitCounter.i) return 1;
894
- tryBranch === scope[branchAccessor] ? scope[nodeAccessor].parentNode && scope[nodeAccessor].replaceWith(scope[branchAccessor].S.parentNode) : dismissPlaceholder(tryBranch), queueEffect(tryBranch, runPendingEffects);
890
+ if (tryBranch === scope[branchAccessor]) {
891
+ let anchor = scope[nodeAccessor];
892
+ if (anchor.parentNode) {
893
+ let detachedParent = scope[branchAccessor].S.parentNode;
894
+ detachedParent === anchor.parentNode ? anchor.remove() : anchor.replaceWith(detachedParent);
895
+ }
896
+ } else dismissPlaceholder(tryBranch);
897
+ queueEffect(tryBranch, runPendingEffects);
895
898
  }
896
899
  }), scope[promiseAccessor] || (awaitBranch && (awaitBranch.W ||= []), awaitCounter.i++ || requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(scope, () => {
897
900
  awaitBranch.V || (awaitBranch.S.parentNode.insertBefore(scope[nodeAccessor], awaitBranch.S), tempDetachBranch(tryBranch));
@@ -1231,25 +1234,21 @@ function _load_setup(nodeAccessor, childScopeAccessor, load) {
1231
1234
  };
1232
1235
  }
1233
1236
  function insertLoaded(renderer, branch, marker, awaitCounter) {
1234
- let parent = marker.parentNode;
1235
- syncGen(branch), renderer.b(branch, parent.namespaceURI), setupBranch(renderer, branch), applyLoad(branch, () => {
1237
+ let parent = marker.parentNode, values = branch.X, insert = () => {
1236
1238
  insertBranchBefore(branch, parent, marker), marker.remove(), awaitCounter?.c();
1237
- });
1239
+ }, remaining;
1240
+ if (syncGen(branch), renderer.b(branch, parent.namespaceURI), branch.X = 0, remaining = values?.size) for (let [promise, entry] of values) promise.then((signal) => {
1241
+ entry.b = signal, --remaining || queueAsyncRender(branch, (branch) => {
1242
+ syncGen(branch), renderer.c?.(branch), values.forEach((e) => e.b._(branch, e.a)), insert();
1243
+ });
1244
+ }, () => 0);
1245
+ else setupBranch(renderer, branch), insert();
1238
1246
  }
1239
1247
  function loadFailed(scope, awaitCounter) {
1240
1248
  return (error) => {
1241
1249
  awaitCounter && (awaitCounter.i = 0), queueAsyncRender(scope, renderCatch, error);
1242
1250
  };
1243
1251
  }
1244
- function applyLoad(scope, insert) {
1245
- let values = scope.X, remaining;
1246
- if (scope.X = 0, remaining = values?.size) for (let [promise, entry] of values) promise.then((signal) => {
1247
- entry.b = signal, --remaining || queueAsyncRender(scope, (scope) => {
1248
- syncGen(scope), values.forEach((e) => e.b._(scope, e.a)), insert();
1249
- });
1250
- }, () => 0);
1251
- else insert();
1252
- }
1253
1252
  function _load_signal(load) {
1254
1253
  let pending, signal;
1255
1254
  return (scope, value) => {
package/dist/dom.mjs CHANGED
@@ -4,7 +4,7 @@ let empty = [], rest = Symbol(), toDelimitedString = function toDelimitedString(
4
4
  else if (Array.isArray(val)) for (let v of val) part = toDelimitedString(v, delimiter, stringify), part && (str += sep + part, sep = delimiter);
5
5
  else for (let name in val) part = stringify(name, val[name]), part && (str += sep + part, sep = delimiter);
6
6
  return str;
7
- }, decodeAccessor = (num) => (num + (num < 26 ? 10 : num < 962 ? 334 : 11998)).toString(36), defaultDelegator = /* @__PURE__ */ createDelegator(), R = /[^\p{L}\p{N}]/gu, parsers = {}, nextScopeId = 1e6, collectingScopes, destroyNestedScopes = function destroyNestedScopes(scope) {
7
+ }, decodeAccessor = (num) => (num + (num < 26 ? 10 : num < 962 ? 334 : 11998)).toString(36), delegate = (type, handler) => handler[type] ||= (document.addEventListener(type, handler, !0), 1), R = /[^\p{L}\p{N}]/gu, parsers = {}, nextScopeId = 1e6, collectingScopes, destroyNestedScopes = function destroyNestedScopes(scope) {
8
8
  scope.H = 0, scope.D?.forEach(destroyNestedScopes), scope.B?.forEach(resetControllers);
9
9
  }, isScheduled, channel, _return = (scope, value) => scope.T?.(value), _var_change = (scope, value) => scope.U?.(value), tagIdsByGlobal = /* @__PURE__ */ new WeakMap(), walker = /* @__PURE__ */ document.createTreeWalker(document), walkInternal = function walkInternal(currentWalkIndex, walkCodes, scope) {
10
10
  let value, currentMultiplier, storedMultiplier = 0, currentScopeIndex = 0;
@@ -20,7 +20,7 @@ let empty = [], rest = Symbol(), toDelimitedString = function toDelimitedString(
20
20
  for (value = 10 * currentMultiplier + value - 107; value--;) walker.parentNode();
21
21
  walker.nextSibling();
22
22
  } else storedMultiplier = currentMultiplier * 10 + value - 117;
23
- }, cloneCache = {}, registeredValues = {}, curRenders, branchesEnabled, embedRenders, readyIds, isResuming, inputType = "", controllableDelegate = /* @__PURE__ */ createDelegator(), _dynamic_tag = function(nodeAccessor, getContent, getTagVar, inputIsArgs) {
23
+ }, cloneCache = {}, registeredValues = {}, curRenders, branchesEnabled, embedRenders, readyIds, isResuming, inputType = "", _dynamic_tag = function(nodeAccessor, getContent, getTagVar, inputIsArgs) {
24
24
  nodeAccessor = decodeAccessor(nodeAccessor);
25
25
  let childScopeAccessor = "A" + nodeAccessor, rendererAccessor = "D" + nodeAccessor;
26
26
  return enableBranches(), (scope, newRenderer, getInput) => {
@@ -98,7 +98,7 @@ let empty = [], rest = Symbol(), toDelimitedString = function toDelimitedString(
98
98
  },
99
99
  render(out, component, renderer, args) {
100
100
  let branch = component.scope, created = 0;
101
- if (!branch && (branch = classIdToBranch.get(component.id)) && (component.scope = branch, classIdToBranch.delete(component.id)), typeof args[0] == "object" && "renderBody" in args[0]) {
101
+ if (!branch && (branch = classIdToBranch.get(component.id)) && (component.scope = branch, classIdToBranch.delete(component.id)), args[0] && typeof args[0] == "object" && "renderBody" in args[0]) {
102
102
  let input = args[0], normalizedInput = args[0] = {};
103
103
  for (let key in input) normalizedInput[key === "renderBody" ? "content" : key] = input[key];
104
104
  }
@@ -181,14 +181,7 @@ function push(opt, item) {
181
181
  //#endregion
182
182
  //#region src/dom/event.ts
183
183
  function _on(element, type, handler) {
184
- element["$" + type] === void 0 && defaultDelegator(element, type, handleDelegated), element["$" + type] = handler || null;
185
- }
186
- /* @__NO_SIDE_EFFECTS__ */
187
- function createDelegator() {
188
- let kEvents = Symbol();
189
- return function(node, type, handler) {
190
- ((node = node.getRootNode())[kEvents] ||= {})[type] ||= (node.addEventListener(type, handler, !0), 1);
191
- };
184
+ element["$" + type] === void 0 && delegate(type, handleDelegated), element["$" + type] = handler || null;
192
185
  }
193
186
  function handleDelegated(ev) {
194
187
  let target = !rendering && ev.target;
@@ -463,20 +456,24 @@ function init(runtimeId = "M") {
463
456
  let partial = partials[i];
464
457
  typeof partial == "number" ? scopeId += partial : (scopeId ? initScope(Object.assign(scopeLookup[scopeId] ||= (partial.L = scopeId, partial), partial)) : Object.assign(initGlobal(), partial), scopeId++);
465
458
  }
466
- }, serializeContext = ((data, registryId) => typeof data == "number" ? registryId ? registeredValues[registryId](getScope(data)) : getScope(data) : applyScopes(data)), createVisitBranches = (branchScopesStack = [], branchStarts = [], orphanBranches = [], curBranchScopes) => (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length) => {
459
+ }, serializeContext = ((data, registryId) => typeof data == "number" ? registryId ? registeredValues[registryId](getScope(data)) : getScope(data) : applyScopes(data)), createVisitBranches = (branchScopesStack = [], branchStarts = [], orphanBranches = [], deferredOwners = [], curBranchScopes) => (branchId, branch, endedBranches, accessor, singleNode, parent = visit.parentNode, startVisit = visit, i = orphanBranches.length, j = deferredOwners.length) => {
467
460
  for (visitType !== "[" && (visitScope[nextToken()] = visitType === ")" || visitType === "}" ? parent : visit, accessor = "A" + lastToken, singleNode = visitType !== "]" && visitType !== ")", nextToken()); branchId = +lastToken;) {
468
461
  if ((endedBranches ||= []).push(branch = getScope(branchId)), setParentBranch(branch, branch.F), (branch.O = render.p?.[branchId]) && (branch.O.m = render.m), singleNode) {
469
462
  for (; startVisit.previousSibling && ~visits.indexOf(startVisit = startVisit.previousSibling););
470
463
  branch.K = branch.S = startVisit, visitType === "'" && (branch.a = startVisit);
471
464
  } else curBranchScopes = push(curBranchScopes, branch), accessor && (visitScope[accessor] = curBranchScopes, curBranchScopes = branchScopesStack.pop()), startVisit = branchStarts.pop(), parent !== startVisit.parentNode && parent.prepend(startVisit), branch.S = startVisit, branch.K = visit.previousSibling === startVisit ? startVisit : parent.insertBefore(new Text(), visit);
472
465
  for (; i && orphanBranches[--i].L > branchId;) setParentBranch(orphanBranches.pop(), branch);
466
+ for (; j && deferredOwners[--j].L > branchId;) {
467
+ let owner = deferredOwners.pop();
468
+ owner.F !== owner && (owner.F = branch);
469
+ }
473
470
  nextToken();
474
471
  }
475
472
  if (endedBranches) {
476
473
  for (let ended of endedBranches) orphanBranches.push(ended);
477
474
  singleNode && (visitScope[accessor] = endedBranches.length > 1 ? endedBranches.reverse() : endedBranches[0]);
478
475
  }
479
- visitType === "[" && (endedBranches || (branchScopesStack.push(curBranchScopes), curBranchScopes = void 0), branchStarts.push(visit));
476
+ visitType === "[" ? (endedBranches || (branchScopesStack.push(curBranchScopes), curBranchScopes = void 0), branchStarts.push(visit)) : deferredOwners.push(visitScope);
480
477
  }, nextToken = () => lastToken = visitText.slice(lastTokenIndex, (lastTokenIndex = visitText.indexOf(" ", lastTokenIndex) + 1 || visitText.length + 1) - 1), processResumes = (resumes = [], effects) => {
481
478
  let i = 0;
482
479
  for (; i < resumes.length; i++) {
@@ -576,7 +573,7 @@ function _attr_input_checkedValue_script(scope, nodeAccessor) {
576
573
  let checkedValueChange = scope["E" + nodeAccessor];
577
574
  if (checkedValueChange) {
578
575
  let oldValue = scope["G" + nodeAccessor], newValue = Array.isArray(oldValue) ? updateList(oldValue, el.value, el.checked) : el.checked ? el.value : void 0;
579
- if (el.name && el.type[0] === "r") for (let radio of el.getRootNode().querySelectorAll(`[type=radio][name=${CSS.escape(el.name)}]`)) radio.form === el.form && (radio.checked = Array.isArray(oldValue) ? oldValue.includes(radio.value) : oldValue === radio.value);
576
+ if (el.name && el.type[0] === "r") for (let radio of document.querySelectorAll(`[type=radio][name=${CSS.escape(el.name)}]`)) radio.form === el.form && (radio.checked = Array.isArray(oldValue) ? oldValue.includes(radio.value) : oldValue === radio.value);
580
577
  else el.checked = !el.checked;
581
578
  checkedValueChange(newValue), run();
582
579
  }
@@ -602,7 +599,7 @@ function _attr_input_value_script(scope, nodeAccessor) {
602
599
  }
603
600
  function setInputValue(el, value) {
604
601
  if (el.value !== value) {
605
- let updatedPosition = resolveCursorPosition(inputType, el.getRootNode().activeElement === el && el.selectionStart, el.value, el.value = value);
602
+ let updatedPosition = resolveCursorPosition(inputType, document.activeElement === el && el.selectionStart, el.value, el.value = value);
606
603
  ~updatedPosition && el.setSelectionRange(updatedPosition, updatedPosition);
607
604
  }
608
605
  }
@@ -674,7 +671,7 @@ function _attr_details_or_dialog_open_script(scope, nodeAccessor) {
674
671
  });
675
672
  }
676
673
  function syncControllableFormInput(el, hasChanged, onChange) {
677
- el._ = onChange, controllableDelegate(el, "input", handleChange), el.form && controllableDelegate(el.form, "reset", handleFormReset), isResuming && hasChanged(el) && queueMicrotask(onChange);
674
+ el._ = onChange, delegate("input", handleChange), el.form && delegate("reset", handleFormReset), isResuming && hasChanged(el) && queueMicrotask(onChange);
678
675
  }
679
676
  function handleChange(ev) {
680
677
  ev.target._?.(ev);
@@ -779,11 +776,10 @@ function attrsInternal(scope, nodeAccessor, nextAttrs) {
779
776
  for (let name in events) events[name] = 0;
780
777
  switch (scope["F" + nodeAccessor] = 5, scope["E" + nodeAccessor] = 0, el.tagName) {
781
778
  case "INPUT":
782
- if ("checked" in nextAttrs || "checkedChange" in nextAttrs) _attr_input_checked(scope, nodeAccessor, nextAttrs.checked, nextAttrs.checkedChange);
783
- else if ("checkedValue" in nextAttrs || "checkedValueChange" in nextAttrs) _attr_input_checkedValue(scope, nodeAccessor, nextAttrs.checkedValue, nextAttrs.checkedValueChange, nextAttrs.value);
784
- else if ("value" in nextAttrs || "valueChange" in nextAttrs) _attr_input_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange);
779
+ if ("checked" in nextAttrs || "checkedChange" in nextAttrs) _attr_input_checked(scope, nodeAccessor, nextAttrs.checked, nextAttrs.checkedChange), skip = /^checked(?:Value)?(?:Change)?$/;
780
+ else if ("checkedValue" in nextAttrs || "checkedValueChange" in nextAttrs) _attr_input_checkedValue(scope, nodeAccessor, nextAttrs.checkedValue, nextAttrs.checkedValueChange, nextAttrs.value), skip = /^(?:value|checked(?:Value)?)(?:Change)?$/;
781
+ else if ("value" in nextAttrs || "valueChange" in nextAttrs) _attr_input_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange), skip = /^value(?:Change)?$/;
785
782
  else break;
786
- skip = /^(?:value|checked(?:Value)?)(?:Change)?$/;
787
783
  break;
788
784
  case "SELECT":
789
785
  ("value" in nextAttrs || "valueChange" in nextAttrs) && (_attr_select_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange), skip = /^value(?:Change)?$/);
@@ -890,7 +886,14 @@ function _await_promise(nodeAccessor, params) {
890
886
  i: 0,
891
887
  c() {
892
888
  if (--awaitCounter.i) return 1;
893
- tryBranch === scope[branchAccessor] ? scope[nodeAccessor].parentNode && scope[nodeAccessor].replaceWith(scope[branchAccessor].S.parentNode) : dismissPlaceholder(tryBranch), queueEffect(tryBranch, runPendingEffects);
889
+ if (tryBranch === scope[branchAccessor]) {
890
+ let anchor = scope[nodeAccessor];
891
+ if (anchor.parentNode) {
892
+ let detachedParent = scope[branchAccessor].S.parentNode;
893
+ detachedParent === anchor.parentNode ? anchor.remove() : anchor.replaceWith(detachedParent);
894
+ }
895
+ } else dismissPlaceholder(tryBranch);
896
+ queueEffect(tryBranch, runPendingEffects);
894
897
  }
895
898
  }), scope[promiseAccessor] || (awaitBranch && (awaitBranch.W ||= []), awaitCounter.i++ || requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(scope, () => {
896
899
  awaitBranch.V || (awaitBranch.S.parentNode.insertBefore(scope[nodeAccessor], awaitBranch.S), tempDetachBranch(tryBranch));
@@ -1230,25 +1233,21 @@ function _load_setup(nodeAccessor, childScopeAccessor, load) {
1230
1233
  };
1231
1234
  }
1232
1235
  function insertLoaded(renderer, branch, marker, awaitCounter) {
1233
- let parent = marker.parentNode;
1234
- syncGen(branch), renderer.b(branch, parent.namespaceURI), setupBranch(renderer, branch), applyLoad(branch, () => {
1236
+ let parent = marker.parentNode, values = branch.X, insert = () => {
1235
1237
  insertBranchBefore(branch, parent, marker), marker.remove(), awaitCounter?.c();
1236
- });
1238
+ }, remaining;
1239
+ if (syncGen(branch), renderer.b(branch, parent.namespaceURI), branch.X = 0, remaining = values?.size) for (let [promise, entry] of values) promise.then((signal) => {
1240
+ entry.b = signal, --remaining || queueAsyncRender(branch, (branch) => {
1241
+ syncGen(branch), renderer.c?.(branch), values.forEach((e) => e.b._(branch, e.a)), insert();
1242
+ });
1243
+ }, () => 0);
1244
+ else setupBranch(renderer, branch), insert();
1237
1245
  }
1238
1246
  function loadFailed(scope, awaitCounter) {
1239
1247
  return (error) => {
1240
1248
  awaitCounter && (awaitCounter.i = 0), queueAsyncRender(scope, renderCatch, error);
1241
1249
  };
1242
1250
  }
1243
- function applyLoad(scope, insert) {
1244
- let values = scope.X, remaining;
1245
- if (scope.X = 0, remaining = values?.size) for (let [promise, entry] of values) promise.then((signal) => {
1246
- entry.b = signal, --remaining || queueAsyncRender(scope, (scope) => {
1247
- syncGen(scope), values.forEach((e) => e.b._(scope, e.a)), insert();
1248
- });
1249
- }, () => 0);
1250
- else insert();
1251
- }
1252
1251
  function _load_signal(load) {
1253
1252
  let pending, signal;
1254
1253
  return (scope, value) => {
@@ -2,12 +2,12 @@ import { type Accessor } from "../common/types";
2
2
  export declare function _attr_class(value: unknown): string;
3
3
  export declare function _attr_style(value: unknown): string;
4
4
  export declare function _attr_option_value(value: unknown): string;
5
- export declare function _attr_select_value(scopeId: number, nodeAccessor: Accessor, value: unknown, valueChange: unknown, content?: () => void): void;
6
- export declare function _attr_textarea_value(scopeId: number, nodeAccessor: Accessor, value: unknown, valueChange: unknown): string;
7
- export declare function _attr_input_value(scopeId: number, nodeAccessor: Accessor, value: unknown, valueChange: unknown): string;
8
- export declare function _attr_input_checked(scopeId: number, nodeAccessor: Accessor, checked: unknown, checkedChange: unknown): "" | " checked";
9
- export declare function _attr_input_checkedValue(scopeId: number, nodeAccessor: Accessor, checkedValue: unknown, checkedValueChange: unknown, value: unknown): string;
10
- export declare function _attr_details_or_dialog_open(scopeId: number, nodeAccessor: Accessor, open: unknown, openChange: unknown): "" | " open";
5
+ export declare function _attr_select_value(scopeId: number, nodeAccessor: Accessor, value: unknown, valueChange: unknown, content?: () => void, serializeType?: 1): void;
6
+ export declare function _attr_textarea_value(scopeId: number, nodeAccessor: Accessor, value: unknown, valueChange: unknown, serializeType?: 1): string;
7
+ export declare function _attr_input_value(scopeId: number, nodeAccessor: Accessor, value: unknown, valueChange: unknown, serializeType?: 1): string;
8
+ export declare function _attr_input_checked(scopeId: number, nodeAccessor: Accessor, checked: unknown, checkedChange: unknown, serializeType?: 1): "" | " checked";
9
+ export declare function _attr_input_checkedValue(scopeId: number, nodeAccessor: Accessor, checkedValue: unknown, checkedValueChange: unknown, value: unknown, serializeType?: 1): string;
10
+ export declare function _attr_details_or_dialog_open(scopeId: number, nodeAccessor: Accessor, open: unknown, openChange: unknown, serializeType?: 1): "" | " open";
11
11
  export declare function _attr_nonce(): string;
12
12
  export declare function _attr(name: string, value: unknown): string;
13
13
  export declare function _attrs(data: Record<string, unknown>, nodeAccessor: Accessor, scopeId: number, tagName: string): string;