marko 6.3.24 → 6.3.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dom.mjs CHANGED
@@ -4,7 +4,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
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), 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) {
7
+ }, decodeAccessor = (num) => (num + (num < 26 ? 10 : num < 962 ? 334 : 11998)).toString(36), delegate = (type, handler) => handler[type] ||= (document.addEventListener(type, handler, !0), 1), 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;
@@ -14,13 +14,13 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
14
14
  } else if (value === 37 || value === 49) walker.currentNode.replaceWith(walker.currentNode = scope[decodeAccessor(currentScopeIndex++)] = new Text()), value === 49 && (scope[decodeAccessor(currentScopeIndex++)] = skipScope());
15
15
  else if (value === 38) return currentWalkIndex;
16
16
  else if (value === 47 || value === 48) currentWalkIndex = walkInternal(currentWalkIndex, walkCodes, scope[decodeAccessor(currentScopeIndex++)] = createScope(scope.$, scope.F)), value === 48 && (scope[decodeAccessor(currentScopeIndex++)] = skipScope());
17
- else if (value < 92) for (value = 20 * currentMultiplier + value - 67; value--;) walker.nextNode();
17
+ else if (value < 92) for (value = 25 * currentMultiplier + value - 67; value--;) walker.nextNode();
18
18
  else if (value < 107) for (value = 10 * currentMultiplier + value - 97; value--;) walker.nextSibling();
19
19
  else if (value < 117) {
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 = "", _dynamic_tag = function(nodeAccessor, getContent, getTagVar, inputIsArgs) {
23
+ }, registeredValues = {}, curRenders, branchesEnabled, embedRenders, readyIds, isResuming, cloneCache = {}, R = /[^\p{L}\p{N}]/gu, inputType = "", controllableScripts = {}, controllableRenders = {}, _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) => {
@@ -33,7 +33,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
33
33
  } else normalizedRenderer?.f && subscribeToScopeSet(normalizedRenderer.e, normalizedRenderer.f, scope[childScopeAccessor]);
34
34
  if (normalizedRenderer) {
35
35
  let childScope = scope[childScopeAccessor], args = getInput?.();
36
- if (typeof normalizedRenderer == "string") (getContent ? _attrs : _attrs_content)(childScope, "a", (inputIsArgs ? args[0] : args) || {}), (childScope.Ia || childScope.Ea) && queueEffect(childScope, dynamicTagScript);
36
+ if (typeof normalizedRenderer == "string") (getContent ? _attrs : _attrs_content)(childScope, "a", (inputIsArgs ? args[0] : args) || {}, controllableRenders[childScope.a.tagName]), (childScope.Ia || childScope.Ea) && queueEffect(childScope, dynamicTagScript);
37
37
  else {
38
38
  for (let accessor in normalizedRenderer.g) normalizedRenderer.g[accessor](childScope, normalizedRenderer.h[accessor]);
39
39
  if (normalizedRenderer.d) if (inputIsArgs) normalizedRenderer.d(childScope, normalizedRenderer._ ? args[0] : args);
@@ -206,19 +206,6 @@ function handleDelegated(ev) {
206
206
  for (; target;) target["$" + ev.type]?.(ev, target), target = ev.bubbles && !ev.cancelBubble && target.parentNode;
207
207
  }
208
208
  //#endregion
209
- //#region src/dom/resolve-cursor-position.ts
210
- function resolveCursorPosition(inputType, initialPosition, initialValue, updatedValue) {
211
- if ((initialPosition || initialPosition === 0) && (initialPosition !== initialValue.length || /kw/.test(inputType))) {
212
- let before = initialValue.slice(0, initialPosition), after = initialValue.slice(initialPosition);
213
- if (updatedValue.startsWith(before)) return initialPosition;
214
- if (updatedValue.endsWith(after)) return updatedValue.length - after.length;
215
- let count = before.replace(R, "").length, pos = 0;
216
- for (; count && updatedValue[pos];) updatedValue[pos++].replace(R, "") && count--;
217
- return pos;
218
- }
219
- return -1;
220
- }
221
- //#endregion
222
209
  //#region src/dom/parse-html.ts
223
210
  function parseHTML(html, ns) {
224
211
  let parser = parsers[ns] ||= document.createElementNS(ns, "template");
@@ -421,57 +408,6 @@ function walk(startNode, walkCodes, branch) {
421
408
  walker.currentNode = startNode, walkInternal(0, walkCodes, branch);
422
409
  }
423
410
  //#endregion
424
- //#region src/dom/renderer.ts
425
- function createBranch($global, renderer, parentScope, parentNode) {
426
- let branch = createScope($global);
427
- return branch._ = renderer.e || parentScope, setParentBranch(branch, parentScope?.F), renderer.b?.(branch, parentNode.namespaceURI), branch;
428
- }
429
- function setParentBranch(branch, parentBranch) {
430
- parentBranch && (branch.N = parentBranch, (parentBranch.D ||= /* @__PURE__ */ new Set()).add(branch)), branch.F = branch;
431
- }
432
- function createAndSetupBranch($global, renderer, parentScope, parentNode) {
433
- return setupBranch(renderer, createBranch($global, renderer, parentScope, parentNode));
434
- }
435
- function setupBranch(renderer, branch) {
436
- return renderer.c && queueRender(branch, renderer.c, -1), branch;
437
- }
438
- function _content(id, template, walks, setup, params, dynamicScopesAccessor) {
439
- walks = walks ? walks.replace(/[^\0-1]+$/, "") : "", setup = setup ? setup._ || setup : void 0, params ||= void 0;
440
- let clone = template ? (branch, ns) => {
441
- ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(template, ns))(branch, walks);
442
- } : (branch) => {
443
- walk(branch.S = branch.K = new Text(), walks, branch);
444
- };
445
- return (owner) => ({
446
- a: id,
447
- b: clone,
448
- e: owner,
449
- c: setup,
450
- d: params,
451
- f: dynamicScopesAccessor
452
- });
453
- }
454
- function _content_resume(id, template, walks, setup, params, dynamicScopesAccessor) {
455
- return _resume(id, _content(id, template, walks, setup, params, dynamicScopesAccessor));
456
- }
457
- function _content_closures(renderer, closureFns) {
458
- let closureSignals = {};
459
- for (let key in closureFns) closureSignals[key] = _const(+key, closureFns[key]);
460
- return (owner, closureValues) => {
461
- let instance = renderer(owner);
462
- return instance.g = closureSignals, instance.h = closureValues, instance;
463
- };
464
- }
465
- function createCloneableHTML(html, ns) {
466
- let { firstChild, lastChild } = parseHTML(html, ns), parent = document.createElementNS(ns, "t");
467
- return insertChildNodes(parent, null, firstChild, lastChild), firstChild === lastChild && firstChild.nodeType < 8 ? (branch, walks) => {
468
- walk(branch.S = branch.K = firstChild.cloneNode(!0), walks, branch);
469
- } : (branch, walks) => {
470
- let clone = parent.cloneNode(!0);
471
- walk(clone.firstChild, walks, branch), branch.S = clone.firstChild, branch.K = clone.lastChild;
472
- };
473
- }
474
- //#endregion
475
411
  //#region src/dom/resume.ts
476
412
  function enableBranches() {
477
413
  branchesEnabled || (branchesEnabled = 1, skipDestroyedRenders());
@@ -586,6 +522,210 @@ function _el(id, accessor) {
586
522
  return accessor = decodeAccessor(accessor), _resume(id, (scope) => () => scope[accessor]);
587
523
  }
588
524
  //#endregion
525
+ //#region src/dom/renderer.ts
526
+ function createBranch($global, renderer, parentScope, parentNode) {
527
+ let branch = createScope($global);
528
+ return branch._ = renderer.e || parentScope, setParentBranch(branch, parentScope?.F), renderer.b?.(branch, parentNode.namespaceURI), branch;
529
+ }
530
+ function setParentBranch(branch, parentBranch) {
531
+ parentBranch && (branch.N = parentBranch, (parentBranch.D ||= /* @__PURE__ */ new Set()).add(branch)), branch.F = branch;
532
+ }
533
+ function createAndSetupBranch($global, renderer, parentScope, parentNode) {
534
+ return setupBranch(renderer, createBranch($global, renderer, parentScope, parentNode));
535
+ }
536
+ function setupBranch(renderer, branch) {
537
+ return renderer.c && queueRender(branch, renderer.c, -1), branch;
538
+ }
539
+ function _content(id, template, walks, setup, params, dynamicScopesAccessor) {
540
+ walks = walks ? walks.replace(/[^\0-1]+$/, "") : "", setup = setup ? setup._ || setup : void 0, params ||= void 0;
541
+ let clone = template ? (branch, ns) => {
542
+ ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(template, ns))(branch, walks);
543
+ } : (branch) => {
544
+ walk(branch.S = branch.K = new Text(), walks, branch);
545
+ };
546
+ return (owner) => ({
547
+ a: id,
548
+ b: clone,
549
+ e: owner,
550
+ c: setup,
551
+ d: params,
552
+ f: dynamicScopesAccessor
553
+ });
554
+ }
555
+ function _content_resume(id, template, walks, setup, params, dynamicScopesAccessor) {
556
+ return _resume(id, _content(id, template, walks, setup, params, dynamicScopesAccessor));
557
+ }
558
+ function _content_closures(renderer, closureFns) {
559
+ let closureSignals = {};
560
+ for (let key in closureFns) closureSignals[key] = _const(+key, closureFns[key]);
561
+ return (owner, closureValues) => {
562
+ let instance = renderer(owner);
563
+ return instance.g = closureSignals, instance.h = closureValues, instance;
564
+ };
565
+ }
566
+ function createCloneableHTML(html, ns) {
567
+ let { firstChild, lastChild } = parseHTML(html, ns), parent = document.createElementNS(ns, "t");
568
+ return insertChildNodes(parent, null, firstChild, lastChild), firstChild === lastChild && firstChild.nodeType < 8 ? (branch, walks) => {
569
+ walk(branch.S = branch.K = firstChild.cloneNode(!0), walks, branch);
570
+ } : (branch, walks) => {
571
+ let clone = parent.cloneNode(!0);
572
+ walk(clone.firstChild, walks, branch), branch.S = clone.firstChild, branch.K = clone.lastChild;
573
+ };
574
+ }
575
+ //#endregion
576
+ //#region src/dom/dom.ts
577
+ function _to_text(value) {
578
+ return value || value === 0 ? value + "" : "";
579
+ }
580
+ function _attr(element, name, value) {
581
+ setAttribute(element, name, normalizeAttrValue(value));
582
+ }
583
+ function setAttribute(element, name, value) {
584
+ element.getAttribute(name) != value && (value === void 0 ? element.removeAttribute(name) : element.setAttribute(name, value));
585
+ }
586
+ function _attr_class(element, value) {
587
+ setAttribute(element, "class", toDelimitedString(value, " ", stringifyClassObject) || void 0);
588
+ }
589
+ function _attr_class_items(element, items) {
590
+ for (let key in items) _attr_class_item(element, key, items[key]);
591
+ }
592
+ function _attr_class_item(element, name, value) {
593
+ element.classList.toggle(name, !!value);
594
+ }
595
+ function _attr_style(element, value) {
596
+ setAttribute(element, "style", toDelimitedString(value, ";", stringifyStyleObject) || void 0);
597
+ }
598
+ function _attr_style_items(element, items) {
599
+ for (let key in items) _attr_style_item(element, key, items[key]);
600
+ }
601
+ function _attr_style_item(element, name, value) {
602
+ element.style.setProperty(name, _to_text(value));
603
+ }
604
+ function _style_shell(scope, nodeAccessor) {
605
+ let element = scope[nodeAccessor], id = _id(scope);
606
+ _attr_nonce(scope, nodeAccessor), element.className = id, _text_content(element, "." + id + "~*{}");
607
+ }
608
+ function _style_rule_item(element, name, value) {
609
+ let text = element.textContent, decl = name + ":" + escapeStyleValue(_to_text(value)) + ";", start = text.indexOf("{" + name + ":");
610
+ ~start || (start = text.indexOf(";" + name + ":")), _text_content(element, ~start ? text.slice(0, ++start) + decl + text.slice(text.indexOf(";", start) + 1) : text.slice(0, -1) + decl + "}");
611
+ }
612
+ function _attr_nonce(scope, nodeAccessor) {
613
+ _attr(scope[nodeAccessor], "nonce", scope.$.cspNonce);
614
+ }
615
+ function _text(node, value) {
616
+ let normalizedValue = _to_text(value);
617
+ node.data !== normalizedValue && (node.data = normalizedValue);
618
+ }
619
+ function _text_content(node, value) {
620
+ let normalizedValue = _to_text(value);
621
+ node.textContent !== normalizedValue && (node.textContent = normalizedValue);
622
+ }
623
+ function _attrs(scope, nodeAccessor, nextAttrs, controllable) {
624
+ let el = scope[nodeAccessor];
625
+ for (let i = el.attributes.length; i--;) {
626
+ let { name } = el.attributes.item(i);
627
+ nextAttrs && (name in nextAttrs || hasAttrAlias(el, name, nextAttrs)) || el.removeAttribute(name);
628
+ }
629
+ attrsInternal(scope, nodeAccessor, nextAttrs, controllable);
630
+ }
631
+ function _attrs_content(scope, nodeAccessor, nextAttrs, controllable) {
632
+ _attrs(scope, nodeAccessor, nextAttrs, controllable), _attr_content(scope, nodeAccessor, nextAttrs?.content);
633
+ }
634
+ function hasAttrAlias(element, attr, nextAttrs) {
635
+ return attr === "checked" && element.tagName === "INPUT" && "checkedValue" in nextAttrs;
636
+ }
637
+ function _attrs_partial(scope, nodeAccessor, nextAttrs, skip, controllable) {
638
+ let el = scope[nodeAccessor], partial = {};
639
+ for (let i = el.attributes.length; i--;) {
640
+ let { name } = el.attributes.item(i);
641
+ !skip[name] && !(nextAttrs && name in nextAttrs) && el.removeAttribute(name);
642
+ }
643
+ for (let name in nextAttrs) {
644
+ let key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
645
+ skip[key] || (partial[key] = nextAttrs[name]);
646
+ }
647
+ attrsInternal(scope, nodeAccessor, partial, controllable);
648
+ }
649
+ function _attrs_partial_content(scope, nodeAccessor, nextAttrs, skip, controllable) {
650
+ _attrs_partial(scope, nodeAccessor, nextAttrs, skip, controllable), _attr_content(scope, nodeAccessor, nextAttrs?.content);
651
+ }
652
+ function attrsInternal(scope, nodeAccessor, nextAttrs, controllable) {
653
+ let el = scope[nodeAccessor], events = scope["I" + nodeAccessor], skip;
654
+ for (let name in events) events[name] = 0;
655
+ controllable && (scope["F" + nodeAccessor] = 5, scope["E" + nodeAccessor] = 0, nextAttrs && (skip = controllable(scope, nodeAccessor, nextAttrs)));
656
+ for (let name in nextAttrs) {
657
+ let value = nextAttrs[name];
658
+ switch (name) {
659
+ case "class":
660
+ _attr_class(el, value);
661
+ break;
662
+ case "style":
663
+ _attr_style(el, value);
664
+ break;
665
+ default:
666
+ isEventHandler(name) ? (events ||= scope["I" + nodeAccessor] = {})[getEventHandlerName(name)] = value : skip?.test(name) || name === "content" && el.tagName !== "META" || _attr(el, name, value);
667
+ break;
668
+ }
669
+ }
670
+ }
671
+ function _attr_content(scope, nodeAccessor, value) {
672
+ let content = normalizeClientRender(value);
673
+ scope["D" + nodeAccessor] !== (scope["D" + nodeAccessor] = content?.a) && (setConditionalRenderer(scope, nodeAccessor, content, createAndSetupBranch), content?.f && subscribeToScopeSet(content.e, content.f, scope["A" + nodeAccessor]));
674
+ for (let accessor in content?.g) content.g[accessor](scope["A" + nodeAccessor], content.h[accessor]);
675
+ }
676
+ function _attrs_script(scope, nodeAccessor) {
677
+ let el = scope[nodeAccessor], events = scope["I" + nodeAccessor];
678
+ controllableScripts[scope["F" + nodeAccessor]]?.(scope, nodeAccessor);
679
+ for (let name in events) _on(el, name, events[name]);
680
+ }
681
+ function _html(scope, value, accessor) {
682
+ let firstChild = scope[accessor], parentNode = firstChild.parentNode, lastChild = scope["H" + accessor] || firstChild, newContent = parseHTML(_to_text(value), parentNode.namespaceURI);
683
+ insertChildNodes(parentNode, firstChild, scope[accessor] = newContent.firstChild || newContent.appendChild(new Text()), scope["H" + accessor] = newContent.lastChild), removeChildNodes(firstChild, lastChild);
684
+ }
685
+ function normalizeClientRender(value) {
686
+ let renderer = normalizeDynamicRenderer(value);
687
+ if (renderer && renderer.a) return renderer;
688
+ }
689
+ function normalizeAttrValue(value) {
690
+ if (isNotVoid(value)) return value === !0 ? "" : value + "";
691
+ }
692
+ function _lifecycle(scope, thisObj, index = 0) {
693
+ let accessor = "K" + index, instance = scope[accessor];
694
+ instance ? (Object.assign(instance, thisObj), instance.onUpdate?.()) : (scope[accessor] = thisObj, Object.assign(thisObj, thisObj.onMount?.()), $signal(scope, accessor).onabort = () => thisObj.onDestroy?.());
695
+ }
696
+ function removeChildNodes(startNode, endNode) {
697
+ let stop = endNode.nextSibling;
698
+ for (; startNode !== stop;) {
699
+ let next = startNode.nextSibling;
700
+ startNode.remove(), startNode = next;
701
+ }
702
+ }
703
+ function insertChildNodes(parentNode, referenceNode, startNode, endNode) {
704
+ parentNode.insertBefore(toInsertNode(startNode, endNode), referenceNode);
705
+ }
706
+ function toInsertNode(startNode, endNode) {
707
+ if (startNode === endNode) return startNode;
708
+ let parent = new DocumentFragment(), stop = endNode.nextSibling;
709
+ for (; startNode !== stop;) {
710
+ let next = startNode.nextSibling;
711
+ parent.appendChild(startNode), startNode = next;
712
+ }
713
+ return parent;
714
+ }
715
+ //#endregion
716
+ //#region src/dom/resolve-cursor-position.ts
717
+ function resolveCursorPosition(inputType, initialPosition, initialValue, updatedValue) {
718
+ if ((initialPosition || initialPosition === 0) && (initialPosition !== initialValue.length || /kw/.test(inputType))) {
719
+ let before = initialValue.slice(0, initialPosition), after = initialValue.slice(initialPosition);
720
+ if (updatedValue.startsWith(before)) return initialPosition;
721
+ if (updatedValue.endsWith(after)) return updatedValue.length - after.length;
722
+ let count = before.replace(R, "").length, pos = 0;
723
+ for (; count && updatedValue[pos];) updatedValue[pos++].replace(R, "") && count--;
724
+ return pos;
725
+ }
726
+ return -1;
727
+ }
728
+ //#endregion
589
729
  //#region src/dom/controllable.ts
590
730
  function _attr_input_checked_default(scope, nodeAccessor, checked) {
591
731
  let el = scope[nodeAccessor], normalizedChecked = isNotVoid(checked);
@@ -594,6 +734,26 @@ function _attr_input_checked_default(scope, nodeAccessor, checked) {
594
734
  el.defaultChecked = normalizedChecked, restoreValue !== normalizedChecked && (el.checked = restoreValue);
595
735
  }
596
736
  }
737
+ /** Filled by the latches a compiled page emits, so a page carries only the
738
+ * control kinds its tags can be (`_attrs_script` resolves the kind at run time). */
739
+ /** The render pass equivalent, for a tag whose name is only known at run time;
740
+ * a statically named tag passes its claim to `_attrs` instead. */
741
+ function _enable_controllable_input() {
742
+ controllableScripts[0] = _attr_input_checked_script, controllableScripts[1] = _attr_input_checkedValue_script, controllableScripts[2] = _attr_input_value_script;
743
+ }
744
+ function _enable_controllable_textarea() {
745
+ controllableScripts[2] = _attr_input_value_script;
746
+ }
747
+ function _enable_controllable_select() {
748
+ controllableScripts[3] = _attr_select_value_script;
749
+ }
750
+ function _enable_controllable_open() {
751
+ controllableScripts[4] = _attr_details_or_dialog_open_script;
752
+ }
753
+ /** A run-time tag name can be any controllable, so its page enables them all. */
754
+ function _enable_controllable() {
755
+ _enable_controllable_input(), _enable_controllable_select(), _enable_controllable_open(), controllableRenders.INPUT = _controllable_input, controllableRenders.TEXTAREA = _controllable_textarea, controllableRenders.SELECT = _controllable_select, controllableRenders.DETAILS = controllableRenders.DIALOG = _controllable_open;
756
+ }
597
757
  function _attr_input_checked(scope, nodeAccessor, checked, checkedChange) {
598
758
  let el = scope[nodeAccessor], normalizedChecked = isNotVoid(checked);
599
759
  scope["E" + nodeAccessor] = checkedChange, scope["F" + nodeAccessor] = checkedChange ? 0 : 5, checkedChange && scope.H < runId ? el.checked = normalizedChecked : _attr_input_checked_default(scope, nodeAccessor, normalizedChecked);
@@ -691,12 +851,12 @@ function _attr_select_value_script(scope, nodeAccessor) {
691
851
  break;
692
852
  }
693
853
  }
694
- syncControllableFormInput(el, hasSelectChanged, onChange), new MutationObserver(() => {
695
- let value = scope["G" + nodeAccessor];
696
- (Array.isArray(value) ? value.length !== el.selectedOptions.length || value.some((_, i) => !value.includes(el.selectedOptions[i].value)) : el.value !== value) && onChange();
697
- }).observe(el, {
854
+ syncControllableFormInput(el, hasSelectChanged, onChange), observeOnce(scope, nodeAccessor, {
698
855
  childList: !0,
699
856
  subtree: !0
857
+ }, () => {
858
+ let value = scope["G" + nodeAccessor];
859
+ (Array.isArray(value) ? value.length !== el.selectedOptions.length || value.some((_, i) => !value.includes(el.selectedOptions[i].value)) : el.value !== value) && onChange();
700
860
  });
701
861
  }
702
862
  function setSelectValue(el, value, multiple) {
@@ -715,17 +875,20 @@ function _attr_details_or_dialog_open(scope, nodeAccessor, open, openChange) {
715
875
  }
716
876
  function _attr_details_or_dialog_open_script(scope, nodeAccessor) {
717
877
  let el = scope[nodeAccessor];
718
- new MutationObserver(() => {
878
+ observeOnce(scope, nodeAccessor, {
879
+ attributes: !0,
880
+ attributeFilter: ["open"]
881
+ }, () => {
719
882
  let openChange = scope["E" + nodeAccessor];
720
883
  if (openChange && el.open === !scope["G" + nodeAccessor]) {
721
884
  let newValue = el.open;
722
885
  el.open = !newValue, openChange(newValue), run();
723
886
  }
724
- }).observe(el, {
725
- attributes: !0,
726
- attributeFilter: ["open"]
727
887
  });
728
888
  }
889
+ function observeOnce(scope, nodeAccessor, init, callback) {
890
+ (scope["N" + nodeAccessor] ||= new MutationObserver(callback)).observe(scope[nodeAccessor], init);
891
+ }
729
892
  function syncControllableFormInput(el, hasChanged, onChange) {
730
893
  el._ = onChange, delegate("input", handleChange), el.form && delegate("reset", handleFormReset), isResuming && hasChanged(el) && queueMicrotask(onChange);
731
894
  }
@@ -758,175 +921,17 @@ function updateList(arr, val, push) {
758
921
  let index = arr.indexOf(val);
759
922
  return (push ? !~index && [...arr, val] : ~index && arr.slice(0, index).concat(arr.slice(index + 1))) || arr;
760
923
  }
761
- //#endregion
762
- //#region src/dom/dom.ts
763
- function _to_text(value) {
764
- return value || value === 0 ? value + "" : "";
765
- }
766
- function _attr(element, name, value) {
767
- setAttribute(element, name, normalizeAttrValue(value));
768
- }
769
- function setAttribute(element, name, value) {
770
- element.getAttribute(name) != value && (value === void 0 ? element.removeAttribute(name) : element.setAttribute(name, value));
771
- }
772
- function _attr_class(element, value) {
773
- setAttribute(element, "class", toDelimitedString(value, " ", stringifyClassObject) || void 0);
774
- }
775
- function _attr_class_items(element, items) {
776
- for (let key in items) _attr_class_item(element, key, items[key]);
777
- }
778
- function _attr_class_item(element, name, value) {
779
- element.classList.toggle(name, !!value);
780
- }
781
- function _attr_style(element, value) {
782
- setAttribute(element, "style", toDelimitedString(value, ";", stringifyStyleObject) || void 0);
783
- }
784
- function _attr_style_items(element, items) {
785
- for (let key in items) _attr_style_item(element, key, items[key]);
786
- }
787
- function _attr_style_item(element, name, value) {
788
- element.style.setProperty(name, _to_text(value));
789
- }
790
- function _style_shell(scope, nodeAccessor) {
791
- let element = scope[nodeAccessor], id = _id(scope);
792
- _attr_nonce(scope, nodeAccessor), element.className = id, _text_content(element, "." + id + "~*{}");
793
- }
794
- function _style_rule_item(element, name, value) {
795
- let text = element.textContent, decl = name + ":" + escapeStyleValue(_to_text(value)) + ";", start = text.indexOf("{" + name + ":");
796
- ~start || (start = text.indexOf(";" + name + ":")), _text_content(element, ~start ? text.slice(0, ++start) + decl + text.slice(text.indexOf(";", start) + 1) : text.slice(0, -1) + decl + "}");
797
- }
798
- function _attr_nonce(scope, nodeAccessor) {
799
- _attr(scope[nodeAccessor], "nonce", scope.$.cspNonce);
800
- }
801
- function _text(node, value) {
802
- let normalizedValue = _to_text(value);
803
- node.data !== normalizedValue && (node.data = normalizedValue);
804
- }
805
- function _text_content(node, value) {
806
- let normalizedValue = _to_text(value);
807
- node.textContent !== normalizedValue && (node.textContent = normalizedValue);
808
- }
809
- function _attrs(scope, nodeAccessor, nextAttrs) {
810
- let el = scope[nodeAccessor];
811
- for (let i = el.attributes.length; i--;) {
812
- let { name } = el.attributes.item(i);
813
- nextAttrs && (name in nextAttrs || hasAttrAlias(el, name, nextAttrs)) || el.removeAttribute(name);
814
- }
815
- attrsInternal(scope, nodeAccessor, nextAttrs);
816
- }
817
- function _attrs_content(scope, nodeAccessor, nextAttrs) {
818
- _attrs(scope, nodeAccessor, nextAttrs), _attr_content(scope, nodeAccessor, nextAttrs?.content);
819
- }
820
- function hasAttrAlias(element, attr, nextAttrs) {
821
- return attr === "checked" && element.tagName === "INPUT" && "checkedValue" in nextAttrs;
822
- }
823
- function _attrs_partial(scope, nodeAccessor, nextAttrs, skip) {
824
- let el = scope[nodeAccessor], partial = {};
825
- for (let i = el.attributes.length; i--;) {
826
- let { name } = el.attributes.item(i);
827
- !skip[name] && !(nextAttrs && name in nextAttrs) && el.removeAttribute(name);
828
- }
829
- for (let name in nextAttrs) {
830
- let key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
831
- skip[key] || (partial[key] = nextAttrs[name]);
832
- }
833
- attrsInternal(scope, nodeAccessor, partial);
834
- }
835
- function _attrs_partial_content(scope, nodeAccessor, nextAttrs, skip) {
836
- _attrs_partial(scope, nodeAccessor, nextAttrs, skip), _attr_content(scope, nodeAccessor, nextAttrs?.content);
837
- }
838
- function attrsInternal(scope, nodeAccessor, nextAttrs) {
839
- let el = scope[nodeAccessor], events = scope["I" + nodeAccessor], skip;
840
- for (let name in events) events[name] = 0;
841
- switch (scope["F" + nodeAccessor] = 5, scope["E" + nodeAccessor] = 0, nextAttrs && el.tagName) {
842
- case "INPUT":
843
- "checked" in nextAttrs || "checkedChange" in nextAttrs ? (_attr_input_checked(scope, nodeAccessor, nextAttrs.checked, nextAttrs.checkedChange), skip = /^checked(?:Value)?(?:Change)?$/) : "checkedValue" in nextAttrs || "checkedValueChange" in nextAttrs ? (_attr_input_checkedValue(scope, nodeAccessor, nextAttrs.checkedValue, nextAttrs.checkedValueChange, nextAttrs.value), skip = /^(?:value|checked(?:Value)?)(?:Change)?$/) : ("value" in nextAttrs || "valueChange" in nextAttrs) && (_attr_input_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange, _attr_input_value_dynamic_default), skip = /^value(?:Change)?$/);
844
- break;
845
- case "SELECT":
846
- ("value" in nextAttrs || "valueChange" in nextAttrs) && (_attr_select_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange), skip = /^value(?:Change)?$/);
847
- break;
848
- case "TEXTAREA":
849
- ("value" in nextAttrs || "valueChange" in nextAttrs) && (_attr_input_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange), skip = /^value(?:Change)?$/);
850
- break;
851
- case "DETAILS":
852
- case "DIALOG":
853
- ("open" in nextAttrs || "openChange" in nextAttrs) && (_attr_details_or_dialog_open(scope, nodeAccessor, nextAttrs.open, nextAttrs.openChange), skip = /^open(?:Change)?$/);
854
- break;
855
- }
856
- for (let name in nextAttrs) {
857
- let value = nextAttrs[name];
858
- switch (name) {
859
- case "class":
860
- _attr_class(el, value);
861
- break;
862
- case "style":
863
- _attr_style(el, value);
864
- break;
865
- default:
866
- isEventHandler(name) ? (events ||= scope["I" + nodeAccessor] = {})[getEventHandlerName(name)] = value : skip?.test(name) || name === "content" && el.tagName !== "META" || _attr(el, name, value);
867
- break;
868
- }
869
- }
870
- }
871
- function _attr_content(scope, nodeAccessor, value) {
872
- let content = normalizeClientRender(value);
873
- scope["D" + nodeAccessor] !== (scope["D" + nodeAccessor] = content?.a) && (setConditionalRenderer(scope, nodeAccessor, content, createAndSetupBranch), content?.f && subscribeToScopeSet(content.e, content.f, scope["A" + nodeAccessor]));
874
- for (let accessor in content?.g) content.g[accessor](scope["A" + nodeAccessor], content.h[accessor]);
924
+ function _controllable_input(scope, nodeAccessor, nextAttrs) {
925
+ return "checked" in nextAttrs || "checkedChange" in nextAttrs ? (_attr_input_checked(scope, nodeAccessor, nextAttrs.checked, nextAttrs.checkedChange), /^checked(?:Value)?(?:Change)?$/) : "checkedValue" in nextAttrs || "checkedValueChange" in nextAttrs ? (_attr_input_checkedValue(scope, nodeAccessor, nextAttrs.checkedValue, nextAttrs.checkedValueChange, nextAttrs.value), /^(?:value|checked(?:Value)?)(?:Change)?$/) : _controllable_textarea(scope, nodeAccessor, nextAttrs, _attr_input_value_dynamic_default);
875
926
  }
876
- function _attrs_script(scope, nodeAccessor) {
877
- let el = scope[nodeAccessor], events = scope["I" + nodeAccessor];
878
- switch (scope["F" + nodeAccessor]) {
879
- case 0:
880
- _attr_input_checked_script(scope, nodeAccessor);
881
- break;
882
- case 1:
883
- _attr_input_checkedValue_script(scope, nodeAccessor);
884
- break;
885
- case 2:
886
- _attr_input_value_script(scope, nodeAccessor);
887
- break;
888
- case 3:
889
- _attr_select_value_script(scope, nodeAccessor);
890
- break;
891
- case 4:
892
- _attr_details_or_dialog_open_script(scope, nodeAccessor);
893
- break;
894
- }
895
- for (let name in events) _on(el, name, events[name]);
927
+ function _controllable_textarea(scope, nodeAccessor, nextAttrs, dynamicDefault) {
928
+ if ("value" in nextAttrs || "valueChange" in nextAttrs) return _attr_input_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange, dynamicDefault), /^value(?:Change)?$/;
896
929
  }
897
- function _html(scope, value, accessor) {
898
- let firstChild = scope[accessor], parentNode = firstChild.parentNode, lastChild = scope["H" + accessor] || firstChild, newContent = parseHTML(_to_text(value), parentNode.namespaceURI);
899
- insertChildNodes(parentNode, firstChild, scope[accessor] = newContent.firstChild || newContent.appendChild(new Text()), scope["H" + accessor] = newContent.lastChild), removeChildNodes(firstChild, lastChild);
930
+ function _controllable_select(scope, nodeAccessor, nextAttrs) {
931
+ if ("value" in nextAttrs || "valueChange" in nextAttrs) return _attr_select_value(scope, nodeAccessor, nextAttrs.value, nextAttrs.valueChange), /^value(?:Change)?$/;
900
932
  }
901
- function normalizeClientRender(value) {
902
- let renderer = normalizeDynamicRenderer(value);
903
- if (renderer && renderer.a) return renderer;
904
- }
905
- function normalizeAttrValue(value) {
906
- if (isNotVoid(value)) return value === !0 ? "" : value + "";
907
- }
908
- function _lifecycle(scope, thisObj, index = 0) {
909
- let accessor = "K" + index, instance = scope[accessor];
910
- instance ? (Object.assign(instance, thisObj), instance.onUpdate?.()) : (scope[accessor] = thisObj, Object.assign(thisObj, thisObj.onMount?.()), $signal(scope, accessor).onabort = () => thisObj.onDestroy?.());
911
- }
912
- function removeChildNodes(startNode, endNode) {
913
- let stop = endNode.nextSibling;
914
- for (; startNode !== stop;) {
915
- let next = startNode.nextSibling;
916
- startNode.remove(), startNode = next;
917
- }
918
- }
919
- function insertChildNodes(parentNode, referenceNode, startNode, endNode) {
920
- parentNode.insertBefore(toInsertNode(startNode, endNode), referenceNode);
921
- }
922
- function toInsertNode(startNode, endNode) {
923
- if (startNode === endNode) return startNode;
924
- let parent = new DocumentFragment(), stop = endNode.nextSibling;
925
- for (; startNode !== stop;) {
926
- let next = startNode.nextSibling;
927
- parent.appendChild(startNode), startNode = next;
928
- }
929
- return parent;
933
+ function _controllable_open(scope, nodeAccessor, nextAttrs) {
934
+ if ("open" in nextAttrs || "openChange" in nextAttrs) return _attr_details_or_dialog_open(scope, nodeAccessor, nextAttrs.open, nextAttrs.openChange), /^open(?:Change)?$/;
930
935
  }
931
936
  //#endregion
932
937
  //#region src/dom/control-flow.ts
@@ -963,7 +968,11 @@ function _await_promise(nodeAccessor, params) {
963
968
  let thisPromise = scope[promiseAccessor] = promise.then((data) => {
964
969
  if (thisPromise === scope[promiseAccessor]) {
965
970
  let referenceNode = scope[nodeAccessor];
966
- scope[promiseAccessor] = 0, queueAsyncRender(scope, () => {
971
+ if (scope[promiseAccessor] = 0, scope.F?.H === 0) {
972
+ awaitCounter.c(), run();
973
+ return;
974
+ }
975
+ queueAsyncRender(scope, () => {
967
976
  awaitBranch = resolveAwait(scope, referenceNode, data);
968
977
  let pendingRenders = awaitBranch.W;
969
978
  if (awaitBranch.W = 0, pendingRenders?.forEach(queuePendingRender), placeholderShown.add(pendingEffects), awaitCounter.c(), awaitCounter.m) {
@@ -1229,7 +1238,7 @@ function _enable_catch() {
1229
1238
  //#region src/dom/abort-signal.ts
1230
1239
  function $signalReset(scope, id) {
1231
1240
  let ctrl = scope.A?.[id];
1232
- ctrl && (queueEffect(ctrl, abort), scope.A[id] = void 0);
1241
+ ctrl && (scope.A[id] = void 0, rendering ? queueEffect(ctrl, abort) : abort(ctrl));
1233
1242
  }
1234
1243
  function $signal(scope, id) {
1235
1244
  return scope.F && (scope.F.B ||= /* @__PURE__ */ new Set()).add(scope), ((scope.A ||= {})[id] ||= new AbortController()).signal;
@@ -1275,10 +1284,10 @@ function mount(input = {}, reference, position) {
1275
1284
  set value(newValue) {
1276
1285
  _var_change(branch, newValue);
1277
1286
  },
1278
- update(newInput) {
1279
- args && runEffects(prepareEffects(() => {
1287
+ update(newInput = {}) {
1288
+ args && (newInput.$global && ({$global, ...newInput} = newInput), runEffects(prepareEffects(() => {
1280
1289
  args(branch, newInput);
1281
- }));
1290
+ })));
1282
1291
  },
1283
1292
  destroy() {
1284
1293
  removeAndDestroyBranch(branch);
@@ -1359,4 +1368,4 @@ function getSelectorOrResolve(selector, resolve) {
1359
1368
  return document.querySelector(selector) || resolve();
1360
1369
  }
1361
1370
  //#endregion
1362
- 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_attribute_default, _attr_input_value_default, _attr_input_value_default as _attr_textarea_value_default, _attr_input_value_dynamic_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 };
1371
+ 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_attribute_default, _attr_input_value_default, _attr_input_value_default as _attr_textarea_value_default, _attr_input_value_dynamic_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, _controllable_input, _controllable_open, _controllable_select, _controllable_textarea, _dynamic_tag, _dynamic_tag_content, _el, _el_read, _enable_catch, _enable_controllable, _enable_controllable_input, _enable_controllable_open, _enable_controllable_select, _enable_controllable_textarea, _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 };
package/dist/html.js CHANGED
@@ -957,11 +957,15 @@ function writeGenerator(state, iter, ref) {
957
957
  needsId ||= isDedupedMember(value), yields.push(value);
958
958
  }
959
959
  if (returnValue === void 0 && !yields.length) return state.buf.push("(function*(){})()"), !0;
960
- if (state.buf.push(returnValue === void 0 ? "(function*(a){yield*a})(" : "(function*(a,r){yield*a;return r})("), needsId) {
960
+ let heldReturn = returnValue !== void 0 && isAncestorMember(state, ref, returnValue);
961
+ if (state.buf.push(returnValue === void 0 ? "(function*(a){yield*a})(" : heldReturn ? "(function*(a,r){yield*a;return r.v})(" : "(function*(a,r){yield*a;return r})("), needsId) {
961
962
  let arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
962
963
  state.buf.push(arrayRef.id + "="), writeArray(state, yields, arrayRef);
963
964
  } else writeArray(state, yields, new Reference(ref, null, state.flush, state.buf.length));
964
- if (returnValue !== void 0) {
965
+ if (heldReturn) {
966
+ let holder = new Reference(ref, null, state.flush, null, nextRefAccess(state));
967
+ state.buf.push("," + holder.id + "={}"), writeProp(state, returnValue, holder, "v");
968
+ } else if (returnValue !== void 0) {
965
969
  let sepIndex = state.buf.push(",") - 1;
966
970
  if (writeProp(state, returnValue, ref, "") && isDedupedMember(returnValue)) {
967
971
  let retRef = typeof returnValue == "string" ? state.strs.get(returnValue) : state.refs.get(returnValue);
@@ -1820,7 +1824,8 @@ function _attr_textarea_value(scopeId, nodeAccessor, value, valueChange, seriali
1820
1824
  return valueChange && writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType), _textarea_value(value);
1821
1825
  }
1822
1826
  function _textarea_value(value) {
1823
- return _escape(normalizeStrAttrValue(value));
1827
+ let escaped = _escape(normalizeStrAttrValue(value));
1828
+ return escaped[0] === "\n" || escaped[0] === "\r" ? "\n" + escaped : escaped;
1824
1829
  }
1825
1830
  function _attr_input_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
1826
1831
  return valueChange && writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType), _attr("value", value);