@avento-space/ts-ui 1.2.7 → 1.2.8

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.
@@ -1,4 +1,4 @@
1
- import { UElement, buttonStyles, inputStyles, boxStyles, listStyles, textStyles, stackStyles, gridStyles, overlayStyles, fieldStyles, checkboxStyles, selectStyles, linkStyles, containerStyles, dialogStyles, tooltipStyles, textareaStyles, radioStyles, switchStyles, labelStyles, treeStyles, tableStyles, breadcrumbStyles, tabsStyles, visuallyHiddenStyles, presenceStyles, animateKeyframes, modalStyles, drawerStyles, popoverStyles, dropdownStyles, accordionStyles, comboboxStyles, calendarStyles, dataTableStyles, commandPaletteStyles, toastStyles, contextMenuStyles, sortableStyles, formStyles, badgeStyles, cardStyles } from './chunk-XN2J666Y.js';
1
+ import { UElement, buttonStyles, inputStyles, boxStyles, listStyles, textStyles, stackStyles, gridStyles, overlayStyles, fieldStyles, checkboxStyles, selectStyles, linkStyles, containerStyles, dialogStyles, tooltipStyles, textareaStyles, radioStyles, switchStyles, labelStyles, treeStyles, tableStyles, breadcrumbStyles, tabsStyles, visuallyHiddenStyles, presenceStyles, animateKeyframes, modalStyles, drawerStyles, popoverStyles, dropdownStyles, accordionStyles, comboboxStyles, calendarStyles, dataTableStyles, commandPaletteStyles, toastStyles, contextMenuStyles, sortableStyles, formStyles, badgeStyles, cardStyles } from './chunk-UVAJNPHY.js';
2
2
  import { signal, effect } from './chunk-Q5RCPPCF.js';
3
3
 
4
4
  // src/components/button.wc.ts
@@ -9,7 +9,7 @@ var UButton = class extends UElement {
9
9
  this._size = "md";
10
10
  this._disabled = false;
11
11
  this._buttonType = "button";
12
- this._root.innerHTML = `<style>${buttonStyles}</style><button part="button"><slot></slot></button>`;
12
+ this._root.innerHTML = `<style>@layer components {${buttonStyles}}</style><button part="button"><slot></slot></button>`;
13
13
  }
14
14
  static get observedAttributes() {
15
15
  return ["variant", "size", "disabled", "type", "class"];
@@ -98,7 +98,7 @@ var UInput = class extends UElement {
98
98
  this._readonly = false;
99
99
  this._inputType = "text";
100
100
  this._inputName = "";
101
- this._root.innerHTML = `<style>${inputStyles}</style><div part="wrapper" class="input-wrapper"><input part="input" /></div>`;
101
+ this._root.innerHTML = `<style>@layer components {${inputStyles}}</style><div part="wrapper" class="input-wrapper"><input part="input" /></div>`;
102
102
  }
103
103
  static get observedAttributes() {
104
104
  return ["placeholder", "disabled", "readonly", "type", "name", "class"];
@@ -466,19 +466,9 @@ var UPortal = class extends HTMLElement {
466
466
  super();
467
467
  this._container = null;
468
468
  this._observer = null;
469
- this.style.display = "none";
470
- }
471
- static get observedAttributes() {
472
- return ["target"];
473
- }
474
- get target() {
475
- return this.getAttribute("target");
476
- }
477
- set target(val) {
478
- if (val) this.setAttribute("target", val);
479
- else this.removeAttribute("target");
480
469
  }
481
470
  connectedCallback() {
471
+ this.style.display = "none";
482
472
  this._open();
483
473
  }
484
474
  disconnectedCallback() {
@@ -941,6 +931,7 @@ var UDismissableLayer = class extends UElement {
941
931
  connectedCallback() {
942
932
  super.connectedCallback();
943
933
  if (this._enabled) this._enable();
934
+ this._sync();
944
935
  }
945
936
  disconnectedCallback() {
946
937
  super.disconnectedCallback();
@@ -953,12 +944,20 @@ var UDismissableLayer = class extends UElement {
953
944
  if (this._enabled) this._enable();
954
945
  else this._disable();
955
946
  }
947
+ if (name === "class") this._sync();
948
+ }
949
+ _sync() {
950
+ const el = this._root.querySelector('[part="layer"]');
951
+ el.className = this.className;
956
952
  }
957
953
  _enable() {
958
954
  this._disable();
959
955
  this._handleOutsideClick = (e) => {
960
- const composed = e.composedPath();
961
- if (!composed.includes(this)) {
956
+ const composed = e.composedPath ? e.composedPath() : e.path || [];
957
+ const root = this.getRootNode();
958
+ const host = root instanceof ShadowRoot ? root.host : null;
959
+ const isInsideHost = host ? composed.includes(host) : false;
960
+ if (!composed.includes(this) && !isInsideHost) {
962
961
  this.dispatchEvent(new CustomEvent("u-dismiss", { bubbles: false, composed: true }));
963
962
  }
964
963
  };
@@ -1550,10 +1549,16 @@ var UHoverable = class extends UElement {
1550
1549
  }
1551
1550
  connectedCallback() {
1552
1551
  super.connectedCallback();
1552
+ this._sync();
1553
1553
  }
1554
1554
  attributeChangedCallback(name, oldVal, newVal) {
1555
1555
  if (oldVal === newVal) return;
1556
1556
  if (name === "disabled") this._disabled = newVal !== null;
1557
+ this._sync();
1558
+ }
1559
+ _sync() {
1560
+ const el = this._root.querySelector('[part="hoverable"]');
1561
+ el.className = this.className;
1557
1562
  }
1558
1563
  _mount() {
1559
1564
  const el = this._root.querySelector('[part="hoverable"]');
@@ -1632,6 +1637,15 @@ var UFocusTrap = class extends UElement {
1632
1637
  };
1633
1638
 
1634
1639
  // src/core/position.ts
1640
+ function computeHostRelativePosition(hostRect, trigger, popup, options = {}) {
1641
+ const result = computePosition(trigger, popup, options);
1642
+ return {
1643
+ ...result,
1644
+ top: result.top - hostRect.top,
1645
+ left: result.left - hostRect.left,
1646
+ position: "absolute"
1647
+ };
1648
+ }
1635
1649
  var SAFE_MARGIN = 8;
1636
1650
  function isMobileViewport() {
1637
1651
  return window.innerWidth < 640;
@@ -1713,24 +1727,35 @@ function computePosition(trigger, popup, options = {}) {
1713
1727
  }
1714
1728
  }
1715
1729
  const finalBase = currentPlacement.split("-")[0];
1730
+ const finalAlign = currentPlacement.split("-")[1];
1731
+ if (finalBase === "top") {
1732
+ maxHeight = trigger.top - offset - margin;
1733
+ } else if (finalBase === "bottom") {
1734
+ maxHeight = vh - (trigger.bottom + offset) - margin;
1735
+ } else if (finalBase === "left" || finalBase === "right") {
1736
+ maxHeight = vh - margin * 2;
1737
+ }
1738
+ const actualHeight = maxHeight && maxHeight > 0 ? Math.min(popup.height, maxHeight) : popup.height;
1739
+ if (finalBase === "top") {
1740
+ top = trigger.top - actualHeight - offset;
1741
+ } else if (finalBase === "left" || finalBase === "right") {
1742
+ if (finalAlign === "end") top = trigger.bottom - actualHeight;
1743
+ else if (!finalAlign) top = trigger.top + (trigger.height - actualHeight) / 2;
1744
+ }
1745
+ let width;
1716
1746
  const isVertical = finalBase === "top" || finalBase === "bottom";
1717
1747
  if (isMobile && isVertical) {
1718
1748
  left = margin;
1719
- const maxWidth = vw - margin * 2;
1720
- if (popup.width > maxWidth) ;
1749
+ width = vw - margin * 2;
1721
1750
  }
1722
1751
  left = Math.max(margin, Math.min(left, vw - popup.width - margin));
1723
- top = Math.max(margin, Math.min(top, vh - popup.height - margin));
1724
- if (finalBase === "top") {
1725
- maxHeight = top - margin;
1726
- } else if (finalBase === "bottom") {
1727
- maxHeight = vh - top - margin;
1728
- }
1752
+ top = Math.max(margin, Math.min(top, vh - actualHeight - margin));
1729
1753
  return {
1730
1754
  top: Math.round(top),
1731
1755
  left: Math.round(left),
1732
1756
  placement: currentPlacement,
1733
1757
  maxHeight: maxHeight && maxHeight > 0 ? maxHeight : void 0,
1758
+ width,
1734
1759
  overflowX: Math.max(0, left + popup.width + margin - vw),
1735
1760
  overflowY: Math.max(0, top + popup.height + margin - vh)
1736
1761
  };
@@ -1908,6 +1933,8 @@ var UDialogRoot = class extends UElement {
1908
1933
  _sync() {
1909
1934
  this.setAttribute("role", "dialog");
1910
1935
  this.setAttribute("aria-modal", String(this._modal));
1936
+ const dialogRoot = this._root.querySelector('[part="dialog-root"]');
1937
+ dialogRoot.className = this.className;
1911
1938
  if (!this._synced) {
1912
1939
  this._synced = true;
1913
1940
  this._updateOpenState();
@@ -1984,6 +2011,38 @@ var UDialogRoot = class extends UElement {
1984
2011
  }
1985
2012
  };
1986
2013
 
2014
+ // src/core/portal-float.ts
2015
+ var originals = /* @__PURE__ */ new WeakMap();
2016
+ function portalFloat(el) {
2017
+ if (originals.has(el)) return;
2018
+ const root = el.getRootNode();
2019
+ let styleClone = null;
2020
+ if (root instanceof ShadowRoot) {
2021
+ const styleEl = root.querySelector("style");
2022
+ if (styleEl) {
2023
+ styleClone = styleEl.cloneNode(true);
2024
+ el.appendChild(styleClone);
2025
+ }
2026
+ }
2027
+ originals.set(el, { parent: el.parentNode, nextSibling: el.nextSibling, styleClone });
2028
+ document.body.appendChild(el);
2029
+ }
2030
+ function unportalFloat(el) {
2031
+ const saved = originals.get(el);
2032
+ if (!saved) return;
2033
+ originals.delete(el);
2034
+ if (saved.styleClone && saved.styleClone.parentNode === el) {
2035
+ el.removeChild(saved.styleClone);
2036
+ }
2037
+ if (saved.parent) {
2038
+ if (saved.nextSibling) {
2039
+ saved.parent.insertBefore(el, saved.nextSibling);
2040
+ } else {
2041
+ saved.parent.appendChild(el);
2042
+ }
2043
+ }
2044
+ }
2045
+
1987
2046
  // src/components/tooltip-root.wc.ts
1988
2047
  var UTooltipRoot = class extends UElement {
1989
2048
  constructor() {
@@ -1994,7 +2053,13 @@ var UTooltipRoot = class extends UElement {
1994
2053
  this._disabled = false;
1995
2054
  this._showTimeout = null;
1996
2055
  this._hideTimeout = null;
2056
+ this._tipEl = null;
2057
+ this._triggerEl = null;
2058
+ this._arrowEl = null;
1997
2059
  this._root.innerHTML = `<style>${tooltipStyles}</style><div part="trigger" class="tooltip-trigger" style="display:inline-flex"><slot></slot></div><div part="tooltip" class="tooltip" role="tooltip" hidden><!-- @deprecated tooltip-content \u2192 use part="content" --><div part="tooltip-content content" class="tooltip-content"></div><div part="arrow" class="tooltip-arrow"></div></div>`;
2060
+ this._tipEl = this._root.querySelector('[part="tooltip"]');
2061
+ this._triggerEl = this._root.querySelector('[part="trigger"]');
2062
+ this._arrowEl = this._root.querySelector('[part="arrow"]');
1998
2063
  }
1999
2064
  static get observedAttributes() {
2000
2065
  return ["content", "placement", "delay", "disabled", "class"];
@@ -2021,6 +2086,12 @@ var UTooltipRoot = class extends UElement {
2021
2086
  super.connectedCallback();
2022
2087
  this._sync();
2023
2088
  }
2089
+ disconnectedCallback() {
2090
+ super.disconnectedCallback();
2091
+ if (this._showTimeout) clearTimeout(this._showTimeout);
2092
+ if (this._hideTimeout) clearTimeout(this._hideTimeout);
2093
+ if (this._tipEl) unportalFloat(this._tipEl);
2094
+ }
2024
2095
  attributeChangedCallback(name, oldVal, newVal) {
2025
2096
  if (oldVal === newVal) return;
2026
2097
  switch (name) {
@@ -2049,8 +2120,9 @@ var UTooltipRoot = class extends UElement {
2049
2120
  if (this._disabled || !this._content) return;
2050
2121
  if (this._hideTimeout) clearTimeout(this._hideTimeout);
2051
2122
  this._showTimeout = setTimeout(() => {
2052
- const tip = this._root.querySelector('[part="tooltip"]');
2123
+ const tip = this._tipEl;
2053
2124
  tip.removeAttribute("hidden");
2125
+ portalFloat(tip);
2054
2126
  requestAnimationFrame(() => this._position());
2055
2127
  this.dispatchEvent(new CustomEvent("u-tooltip-show", { bubbles: true, composed: true }));
2056
2128
  }, this._delay);
@@ -2058,14 +2130,15 @@ var UTooltipRoot = class extends UElement {
2058
2130
  hide() {
2059
2131
  if (this._showTimeout) clearTimeout(this._showTimeout);
2060
2132
  this._hideTimeout = setTimeout(() => {
2061
- const tip = this._root.querySelector('[part="tooltip"]');
2133
+ const tip = this._tipEl;
2062
2134
  tip.setAttribute("hidden", "");
2135
+ unportalFloat(tip);
2063
2136
  this.dispatchEvent(new CustomEvent("u-tooltip-hide", { bubbles: true, composed: true }));
2064
2137
  }, 50);
2065
2138
  }
2066
2139
  _position() {
2067
- const tip = this._root.querySelector('[part="tooltip"]');
2068
- const trigger = this._root.querySelector('[part="trigger"]');
2140
+ const tip = this._tipEl;
2141
+ const trigger = this._triggerEl;
2069
2142
  if (tip.hidden) return;
2070
2143
  const result = computePosition(
2071
2144
  trigger.getBoundingClientRect(),
@@ -2075,12 +2148,12 @@ var UTooltipRoot = class extends UElement {
2075
2148
  tip.style.position = "fixed";
2076
2149
  tip.style.top = `${result.top}px`;
2077
2150
  tip.style.left = `${result.left}px`;
2078
- const arrow = this._root.querySelector('[part="arrow"]');
2151
+ const arrow = this._arrowEl;
2079
2152
  const base = result.placement.split("-")[0];
2080
2153
  arrow.className = `tooltip-arrow arrow-${base}`;
2081
2154
  }
2082
2155
  _mount() {
2083
- const trigger = this._root.querySelector('[part="trigger"]');
2156
+ const trigger = this._triggerEl;
2084
2157
  trigger.addEventListener("pointerenter", () => this.show());
2085
2158
  trigger.addEventListener("pointerleave", () => this.hide());
2086
2159
  trigger.addEventListener("focusin", () => this.show());
@@ -3605,7 +3678,7 @@ var UModal = class extends UElement {
3605
3678
  this._closeOnOverlay = true;
3606
3679
  this._previousActive = null;
3607
3680
  this._unlockScroll = null;
3608
- this._root.innerHTML = `<style>${modalStyles}</style>
3681
+ this._root.innerHTML = `<style>@layer components {${modalStyles}}</style>
3609
3682
  <div part="backdrop" class="modal-backdrop" hidden></div>
3610
3683
  <div part="modal" class="modal" role="dialog" aria-modal="true" hidden>
3611
3684
  <div part="modal-wrapper" class="modal-wrapper modal-md">
@@ -3711,16 +3784,18 @@ var UModal = class extends UElement {
3711
3784
  this._previousActive = document.activeElement;
3712
3785
  backdrop.removeAttribute("hidden");
3713
3786
  modal.removeAttribute("hidden");
3714
- this._unlockScroll = lockScroll();
3787
+ if (!this._unlockScroll) {
3788
+ this._unlockScroll = lockScroll();
3789
+ }
3715
3790
  this._updateSize();
3716
3791
  this._focusFirst();
3717
3792
  } else {
3718
- backdrop.setAttribute("hidden", "");
3719
- modal.setAttribute("hidden", "");
3720
3793
  if (this._unlockScroll) {
3721
3794
  this._unlockScroll();
3722
3795
  this._unlockScroll = null;
3723
3796
  }
3797
+ backdrop.setAttribute("hidden", "");
3798
+ modal.setAttribute("hidden", "");
3724
3799
  if (this._previousActive && this._previousActive.focus) {
3725
3800
  this._previousActive.focus();
3726
3801
  this._previousActive = null;
@@ -3905,18 +3980,24 @@ var UDrawer = class extends UElement {
3905
3980
  backdrop.removeAttribute("hidden");
3906
3981
  drawer.removeAttribute("hidden");
3907
3982
  this._applyDrawerSize(content);
3908
- this._unlockScroll = lockScroll();
3909
- void drawer.offsetHeight;
3910
- drawer.classList.add("drawer-open");
3983
+ if (!this._unlockScroll) {
3984
+ this._unlockScroll = lockScroll();
3985
+ }
3986
+ drawer.classList.remove("drawer-open");
3987
+ void content.offsetHeight;
3988
+ requestAnimationFrame(() => {
3989
+ if (!this._open) return;
3990
+ drawer.classList.add("drawer-open");
3991
+ });
3911
3992
  this._focusFirst();
3912
3993
  } else {
3913
- drawer.classList.remove("drawer-open");
3914
- backdrop.setAttribute("hidden", "");
3915
- drawer.setAttribute("hidden", "");
3916
3994
  if (this._unlockScroll) {
3917
3995
  this._unlockScroll();
3918
3996
  this._unlockScroll = null;
3919
3997
  }
3998
+ drawer.classList.remove("drawer-open");
3999
+ backdrop.setAttribute("hidden", "");
4000
+ drawer.setAttribute("hidden", "");
3920
4001
  if (this._previousActive && this._previousActive.focus) {
3921
4002
  this._previousActive.focus();
3922
4003
  this._previousActive = null;
@@ -3981,10 +4062,13 @@ var UPopover = class extends UElement {
3981
4062
  this._offset = 8;
3982
4063
  this._closeOnEscape = true;
3983
4064
  this._closeOnOutsideClick = true;
4065
+ this._popoverEl = null;
4066
+ this._triggerEl = null;
4067
+ this._arrowEl = null;
3984
4068
  this._handleOutsideClick = (e) => {
3985
4069
  if (!this._open || !this._closeOnOutsideClick) return;
3986
4070
  const path = e.composedPath();
3987
- if (!path.includes(this)) {
4071
+ if (!path.includes(this) && (!this._popoverEl || !path.includes(this._popoverEl))) {
3988
4072
  this.closePopover();
3989
4073
  }
3990
4074
  };
@@ -4003,6 +4087,9 @@ var UPopover = class extends UElement {
4003
4087
  <slot></slot>
4004
4088
  </div>
4005
4089
  </div>`;
4090
+ this._popoverEl = this._root.querySelector('[part="popover"]');
4091
+ this._triggerEl = this._root.querySelector('[part="trigger"]');
4092
+ this._arrowEl = this._root.querySelector('[part="arrow"]');
4006
4093
  }
4007
4094
  static get observedAttributes() {
4008
4095
  return ["open", "placement", "offset", "close-on-escape", "close-on-outside-click", "class"];
@@ -4037,6 +4124,12 @@ var UPopover = class extends UElement {
4037
4124
  super.connectedCallback();
4038
4125
  this._sync();
4039
4126
  }
4127
+ disconnectedCallback() {
4128
+ super.disconnectedCallback();
4129
+ document.removeEventListener("pointerdown", this._handleOutsideClick);
4130
+ document.removeEventListener("keydown", this._handleEscape);
4131
+ if (this._popoverEl) unportalFloat(this._popoverEl);
4132
+ }
4040
4133
  attributeChangedCallback(name, oldVal, newVal) {
4041
4134
  if (oldVal === newVal) return;
4042
4135
  switch (name) {
@@ -4062,29 +4155,46 @@ var UPopover = class extends UElement {
4062
4155
  }
4063
4156
  }
4064
4157
  _sync() {
4065
- const popoverEl = this._root.querySelector('[part="popover"]');
4158
+ const popoverEl = this._popoverEl;
4066
4159
  popoverEl.className = `popover ${this.className}`.trim();
4067
4160
  }
4068
4161
  _updateOpenState() {
4069
- const popover = this._root.querySelector('[part="popover"]');
4162
+ const popover = this._popoverEl;
4163
+ const contentEl = popover.querySelector(".popover-content");
4070
4164
  if (this._open) {
4165
+ const slot = contentEl.querySelector("slot:not([name])");
4166
+ if (slot) {
4167
+ const assigned = slot.assignedNodes({ flatten: true });
4168
+ slot.remove();
4169
+ for (const node of assigned) {
4170
+ contentEl.appendChild(node.cloneNode(true));
4171
+ }
4172
+ }
4071
4173
  popover.removeAttribute("hidden");
4174
+ portalFloat(popover);
4072
4175
  requestAnimationFrame(() => this._position());
4073
4176
  this.dispatchEvent(new CustomEvent("u-popover-open", { bubbles: true, composed: true }));
4074
4177
  } else {
4075
4178
  popover.setAttribute("hidden", "");
4179
+ unportalFloat(popover);
4180
+ const existingSlot = contentEl.querySelector("slot:not([name])");
4181
+ if (!existingSlot) {
4182
+ while (contentEl.firstChild) contentEl.removeChild(contentEl.firstChild);
4183
+ const newSlot = document.createElement("slot");
4184
+ contentEl.appendChild(newSlot);
4185
+ }
4076
4186
  this.dispatchEvent(new CustomEvent("u-popover-close", { bubbles: true, composed: true }));
4077
4187
  }
4078
4188
  }
4079
4189
  _position() {
4080
- const popover = this._root.querySelector('[part="popover"]');
4081
- const trigger = this._root.querySelector('[part="trigger"]');
4190
+ const popover = this._popoverEl;
4191
+ const trigger = this._triggerEl;
4082
4192
  const result = computePosition(
4083
4193
  trigger.getBoundingClientRect(),
4084
4194
  { width: popover.offsetWidth || 0, height: popover.offsetHeight || 0 },
4085
4195
  { placement: this._placement, offset: this._offset, flip: true }
4086
4196
  );
4087
- const arrow = this._root.querySelector('[part="arrow"]');
4197
+ const arrow = this._arrowEl;
4088
4198
  const resultBase = result.placement.split("-")[0];
4089
4199
  arrow.className = `popover-arrow arrow-${resultBase}`;
4090
4200
  popover.style.position = "fixed";
@@ -4092,7 +4202,7 @@ var UPopover = class extends UElement {
4092
4202
  popover.style.left = `${result.left}px`;
4093
4203
  }
4094
4204
  _mount() {
4095
- const triggerSlot = this._root.querySelector('[part="trigger"]');
4205
+ const triggerSlot = this._triggerEl;
4096
4206
  triggerSlot.addEventListener("click", () => this.toggle());
4097
4207
  document.addEventListener("pointerdown", this._handleOutsideClick);
4098
4208
  document.addEventListener("keydown", this._handleEscape);
@@ -4157,7 +4267,7 @@ var UDropdown = class extends UElement {
4157
4267
  this._handleOutsideClick = (e) => {
4158
4268
  if (!this._open) return;
4159
4269
  const path = e.composedPath();
4160
- if (!path.includes(this)) {
4270
+ if (!path.includes(this) && (!this._menuEl || !path.includes(this._menuEl))) {
4161
4271
  this.closeDropdown();
4162
4272
  }
4163
4273
  };
@@ -4216,6 +4326,12 @@ var UDropdown = class extends UElement {
4216
4326
  this._sync();
4217
4327
  this._renderItems();
4218
4328
  }
4329
+ disconnectedCallback() {
4330
+ super.disconnectedCallback();
4331
+ document.removeEventListener("pointerdown", this._handleOutsideClick);
4332
+ document.removeEventListener("keydown", this._handleEscape);
4333
+ if (this._menuEl) unportalFloat(this._menuEl);
4334
+ }
4219
4335
  attributeChangedCallback(name, oldVal, newVal) {
4220
4336
  if (oldVal === newVal) return;
4221
4337
  switch (name) {
@@ -4309,34 +4425,19 @@ var UDropdown = class extends UElement {
4309
4425
  _updateOpenState() {
4310
4426
  if (this._open) {
4311
4427
  this._menuEl.removeAttribute("hidden");
4428
+ portalFloat(this._menuEl);
4312
4429
  this._menuEl.focus({ preventScroll: true });
4313
4430
  this._activeIndex = -1;
4314
4431
  requestAnimationFrame(() => this._position());
4315
4432
  } else {
4316
4433
  this._menuEl.setAttribute("hidden", "");
4434
+ unportalFloat(this._menuEl);
4317
4435
  this._activeIndex = -1;
4318
4436
  }
4319
4437
  }
4320
4438
  _position() {
4321
4439
  const trigRect = this._triggerEl.getBoundingClientRect();
4322
4440
  this._menuEl.style.minWidth = `${Math.min(trigRect.width, window.innerWidth - 16)}px`;
4323
- const isMobile = window.innerWidth < 640;
4324
- if (isMobile) {
4325
- const margin = 8;
4326
- this._menuEl.style.position = "fixed";
4327
- this._menuEl.style.left = `${margin}px`;
4328
- this._menuEl.style.width = `${window.innerWidth - margin * 2}px`;
4329
- const spaceBelow = window.innerHeight - trigRect.bottom;
4330
- const spaceAbove = trigRect.top;
4331
- if (spaceBelow > 200 || spaceBelow >= spaceAbove) {
4332
- this._menuEl.style.top = `${trigRect.bottom + 4}px`;
4333
- this._menuEl.style.maxHeight = `${Math.min(spaceBelow - 8, 320)}px`;
4334
- } else {
4335
- this._menuEl.style.top = `${Math.max(8, trigRect.top - 8 - 320)}px`;
4336
- this._menuEl.style.maxHeight = `${Math.min(spaceAbove - 8, 320)}px`;
4337
- }
4338
- return;
4339
- }
4340
4441
  const result = computePosition(
4341
4442
  trigRect,
4342
4443
  { width: this._menuEl.offsetWidth || trigRect.width, height: this._menuEl.offsetHeight || 0 },
@@ -4345,7 +4446,7 @@ var UDropdown = class extends UElement {
4345
4446
  this._menuEl.style.position = "fixed";
4346
4447
  this._menuEl.style.top = `${result.top}px`;
4347
4448
  this._menuEl.style.left = `${result.left}px`;
4348
- this._menuEl.style.width = "";
4449
+ this._menuEl.style.width = result.width ? `${result.width}px` : "";
4349
4450
  if (result.maxHeight) this._menuEl.style.maxHeight = `${result.maxHeight}px`;
4350
4451
  }
4351
4452
  _getSelectableItems() {
@@ -4428,6 +4529,7 @@ var UAccordion = class extends UElement {
4428
4529
  super.connectedCallback();
4429
4530
  this._sync();
4430
4531
  this._initItems();
4532
+ this._syncItems();
4431
4533
  }
4432
4534
  attributeChangedCallback(name, oldVal, newVal) {
4433
4535
  if (oldVal === newVal) return;
@@ -4442,7 +4544,7 @@ var UAccordion = class extends UElement {
4442
4544
  _initItems() {
4443
4545
  const items = this.querySelectorAll(":scope > u-accordion-item");
4444
4546
  items.forEach((item) => {
4445
- const key = item.getAttribute("data-value") || "";
4547
+ const key = item.getAttribute("value") || "";
4446
4548
  if (item.hasAttribute("open")) {
4447
4549
  this._value.add(key);
4448
4550
  }
@@ -4471,11 +4573,13 @@ var UAccordion = class extends UElement {
4471
4573
  _syncItems() {
4472
4574
  const items = this.querySelectorAll(":scope > u-accordion-item");
4473
4575
  items.forEach((item) => {
4474
- const key = item.getAttribute("data-value") || "";
4475
- const content = item.querySelector('[part="accordion-content"]');
4576
+ const key = item.getAttribute("value") || "";
4577
+ const content = item.shadowRoot?.querySelector('[part="accordion-content"]');
4476
4578
  if (this._value.has(key)) {
4477
4579
  item.setAttribute("open", "");
4478
- if (content) content.style.height = `${content.scrollHeight}px`;
4580
+ if (content) {
4581
+ content.style.height = `${content.scrollHeight}px`;
4582
+ }
4479
4583
  } else {
4480
4584
  item.removeAttribute("open");
4481
4585
  if (content) content.style.height = "0";
@@ -4484,11 +4588,21 @@ var UAccordion = class extends UElement {
4484
4588
  }
4485
4589
  _mount() {
4486
4590
  this.addEventListener("click", (e) => {
4487
- const header = e.target.closest('[part="accordion-header"]');
4591
+ const path = typeof e.composedPath === "function" ? e.composedPath() : e.path || [];
4592
+ if (!Array.isArray(path)) return;
4593
+ const header = path.find(
4594
+ (el) => el instanceof HTMLElement && el.getAttribute("part") === "accordion-header"
4595
+ );
4488
4596
  if (!header) return;
4489
- const item = header.closest("u-accordion-item");
4597
+ let item = header.closest("u-accordion-item");
4598
+ if (!item && header.getRootNode() instanceof ShadowRoot) {
4599
+ const host = header.getRootNode().host;
4600
+ if (host instanceof HTMLElement && host.tagName.toLowerCase() === "u-accordion-item") {
4601
+ item = host;
4602
+ }
4603
+ }
4490
4604
  if (!item) return;
4491
- const key = item.getAttribute("data-value") || "";
4605
+ const key = item.getAttribute("value") || "";
4492
4606
  this.toggle(key);
4493
4607
  });
4494
4608
  }
@@ -4548,7 +4662,6 @@ var UAccordionItem = class extends UElement {
4548
4662
  };
4549
4663
 
4550
4664
  // src/components/combobox.wc.ts
4551
- var MOBILE_BREAKPOINT = 640;
4552
4665
  var UCombobox = class extends UElement {
4553
4666
  constructor() {
4554
4667
  super();
@@ -4667,33 +4780,19 @@ var UCombobox = class extends UElement {
4667
4780
  _position() {
4668
4781
  const listbox = this._root.querySelector('[part="listbox"]');
4669
4782
  const wrapper = this._root.querySelector('[part="input-wrapper"]');
4783
+ const hostRect = this.getBoundingClientRect();
4670
4784
  const rect = wrapper.getBoundingClientRect();
4671
- const isMobile = window.innerWidth < MOBILE_BREAKPOINT;
4672
- if (isMobile) {
4673
- const margin = 8;
4674
- listbox.style.position = "fixed";
4675
- listbox.style.left = `${margin}px`;
4676
- listbox.style.width = `${window.innerWidth - margin * 2}px`;
4677
- const spaceBelow = window.innerHeight - rect.bottom;
4678
- const spaceAbove = rect.top;
4679
- if (spaceBelow > 200 || spaceBelow >= spaceAbove) {
4680
- listbox.style.top = `${rect.bottom + 2}px`;
4681
- listbox.style.maxHeight = `${Math.min(spaceBelow - 8, 240)}px`;
4682
- } else {
4683
- listbox.style.top = `${Math.max(8, rect.top - 242)}px`;
4684
- listbox.style.maxHeight = `${Math.min(spaceAbove - 8, 240)}px`;
4685
- }
4686
- return;
4687
- }
4688
- const result = computePosition(
4785
+ const result = computeHostRelativePosition(
4786
+ hostRect,
4689
4787
  rect,
4690
4788
  { width: listbox.offsetWidth || rect.width, height: listbox.offsetHeight || 240 },
4691
4789
  { placement: "bottom-start", offset: 2, flip: true }
4692
4790
  );
4693
- listbox.style.position = "fixed";
4791
+ listbox.style.position = "absolute";
4694
4792
  listbox.style.top = `${result.top}px`;
4695
4793
  listbox.style.left = `${result.left}px`;
4696
- listbox.style.width = `${rect.width}px`;
4794
+ listbox.style.width = result.width ? `${result.width}px` : `${rect.width}px`;
4795
+ if (result.maxHeight) listbox.style.maxHeight = `${result.maxHeight}px`;
4697
4796
  }
4698
4797
  _filterOptions(query) {
4699
4798
  if (!this._filterable) return;
@@ -5600,10 +5699,13 @@ var UContextMenu = class extends UElement {
5600
5699
  this._items = [];
5601
5700
  this._open = false;
5602
5701
  this._selectedIndex = -1;
5702
+ this._menuEl = null;
5703
+ this._itemsContainer = null;
5603
5704
  this._handleOutsideClick = (e) => {
5604
5705
  if (!this._open) return;
5605
5706
  const path = e.composedPath();
5606
- if (!path.includes(this)) {
5707
+ const menu = this._menuEl;
5708
+ if (!path.includes(this) && (!menu || !path.includes(menu))) {
5607
5709
  this._closeMenu();
5608
5710
  }
5609
5711
  };
@@ -5612,6 +5714,8 @@ var UContextMenu = class extends UElement {
5612
5714
  <div part="menu" class="cm-menu" role="menu" hidden>
5613
5715
  <div part="items" class="cm-items"></div>
5614
5716
  </div>`;
5717
+ this._menuEl = this._root.querySelector('[part="menu"]');
5718
+ this._itemsContainer = this._root.querySelector('[part="items"]');
5615
5719
  }
5616
5720
  static get observedAttributes() {
5617
5721
  return ["class"];
@@ -5629,6 +5733,11 @@ var UContextMenu = class extends UElement {
5629
5733
  this._renderItems();
5630
5734
  this._sync();
5631
5735
  }
5736
+ disconnectedCallback() {
5737
+ super.disconnectedCallback();
5738
+ document.removeEventListener("pointerdown", this._handleOutsideClick);
5739
+ if (this._menuEl) unportalFloat(this._menuEl);
5740
+ }
5632
5741
  attributeChangedCallback(name, oldVal, newVal) {
5633
5742
  if (oldVal === newVal) return;
5634
5743
  if (name === "class") this._sync();
@@ -5645,7 +5754,7 @@ var UContextMenu = class extends UElement {
5645
5754
  if (parsed.length > 0) this._items = parsed;
5646
5755
  }
5647
5756
  _renderItems() {
5648
- const container = this._root.querySelector('[part="items"]');
5757
+ const container = this._itemsContainer;
5649
5758
  container.innerHTML = "";
5650
5759
  this._items.forEach((item, i) => {
5651
5760
  if (item.divider) {
@@ -5678,23 +5787,26 @@ var UContextMenu = class extends UElement {
5678
5787
  });
5679
5788
  }
5680
5789
  _sync() {
5681
- const menu = this._root.querySelector('[part="menu"]');
5790
+ const menu = this._menuEl;
5682
5791
  menu.className = `cm-menu ${this.className}`.trim();
5683
5792
  }
5684
5793
  _openMenu(x, y) {
5685
- const menu = this._root.querySelector('[part="menu"]');
5686
- const itemsContainer = this._root.querySelector('[part="items"]');
5794
+ const menu = this._menuEl;
5795
+ const itemsContainer = this._itemsContainer;
5687
5796
  menu.style.animation = "none";
5688
5797
  menu.removeAttribute("hidden");
5689
5798
  void menu.offsetHeight;
5799
+ portalFloat(menu);
5690
5800
  const trigger = new DOMRect(x, y, 0, 0);
5691
5801
  const result = computePosition(
5692
5802
  trigger,
5693
5803
  { width: menu.offsetWidth || 0, height: menu.offsetHeight || 0 },
5694
5804
  { placement: "bottom-start", margin: 8, flip: true }
5695
5805
  );
5806
+ menu.style.position = "fixed";
5696
5807
  menu.style.left = `${result.left}px`;
5697
5808
  menu.style.top = `${result.top}px`;
5809
+ if (result.width) menu.style.width = `${result.width}px`;
5698
5810
  menu.style.maxHeight = `${result.maxHeight ?? 320}px`;
5699
5811
  itemsContainer.style.maxHeight = `${(result.maxHeight ?? 320) - 16}px`;
5700
5812
  void menu.offsetHeight;
@@ -5713,8 +5825,9 @@ var UContextMenu = class extends UElement {
5713
5825
  }
5714
5826
  _closeMenu() {
5715
5827
  if (!this._open) return;
5716
- const menu = this._root.querySelector('[part="menu"]');
5828
+ const menu = this._menuEl;
5717
5829
  menu.setAttribute("hidden", "");
5830
+ unportalFloat(menu);
5718
5831
  this._open = false;
5719
5832
  this._selectedIndex = -1;
5720
5833
  this.dispatchEvent(
@@ -5725,7 +5838,7 @@ var UContextMenu = class extends UElement {
5725
5838
  );
5726
5839
  }
5727
5840
  _focusFirst() {
5728
- const btns = this._root.querySelectorAll(".cm-item:not([disabled])");
5841
+ const btns = this._itemsContainer.querySelectorAll(".cm-item:not([disabled])");
5729
5842
  if (btns.length > 0) {
5730
5843
  btns[0].focus();
5731
5844
  }
@@ -5739,8 +5852,8 @@ var UContextMenu = class extends UElement {
5739
5852
  this._renderItems();
5740
5853
  this._openMenu(ce.clientX, ce.clientY);
5741
5854
  });
5742
- const menu = this._root.querySelector('[part="menu"]');
5743
- const itemsContainer = this._root.querySelector('[part="items"]');
5855
+ const menu = this._menuEl;
5856
+ const itemsContainer = this._itemsContainer;
5744
5857
  menu.addEventListener("click", (e) => {
5745
5858
  const btn = e.target.closest(".cm-item");
5746
5859
  if (!btn || btn.hasAttribute("disabled")) return;
@@ -6051,7 +6164,7 @@ var UBadge = class extends UElement {
6051
6164
  this._size = "md";
6052
6165
  this._dot = false;
6053
6166
  this._pill = true;
6054
- this._root.innerHTML = `<style>${badgeStyles}</style><span part="badge" class="badge badge-default badge-md badge-pill"><slot></slot></span>`;
6167
+ this._root.innerHTML = `<style>@layer components {${badgeStyles}}</style><span part="badge" class="badge badge-default badge-md badge-pill"><slot></slot></span>`;
6055
6168
  }
6056
6169
  static get observedAttributes() {
6057
6170
  return ["variant", "size", "dot", "pill", "class"];
@@ -6126,7 +6239,7 @@ var UCard = class extends UElement {
6126
6239
  this._variant = "default";
6127
6240
  this._padding = "md";
6128
6241
  this._hoverable = false;
6129
- this._root.innerHTML = `<style>${cardStyles}</style>
6242
+ this._root.innerHTML = `<style>@layer components {${cardStyles}}</style>
6130
6243
  <div part="card" class="card card-default card-padding-md">
6131
6244
  <div part="image" class="card-image card-image-top">
6132
6245
  <slot name="image"></slot>
@@ -6205,5 +6318,5 @@ var UCard = class extends UElement {
6205
6318
  };
6206
6319
 
6207
6320
  export { UAccordion, UAccordionItem, UAnimate, UBadge, UBox, UBreadcrumb, UButton, UCalendar, UCard, UCheckbox, UCollection, UCombobox, UCommandPalette, UContainer, UContextMenu, UDataTable, UDialogRoot, UDismissableLayer, UDrawer, UDropdown, UField, UFocusManager, UFocusScope, UFocusTrap, UForm, UGrid, UHStack, UHoverable, UInput, UKeyboardNavigation, ULabel, ULink, UList, ULiveRegion, UModal, UOverlay, UPopover, UPopper, UPortal, UPresence, UPressable, URadio, URadioGroup, URouterView, USelect, USlot, USortable, USpacer, UStack, USwitch, UTable, UTabs, UText, UTextarea, UToast, UTooltipRoot, UTransition, UTree, UVirtualList, UVisuallyHidden, createControlledInput, setPortalRoot };
6208
- //# sourceMappingURL=chunk-EDV6KYRZ.js.map
6209
- //# sourceMappingURL=chunk-EDV6KYRZ.js.map
6321
+ //# sourceMappingURL=chunk-AZSJNOZV.js.map
6322
+ //# sourceMappingURL=chunk-AZSJNOZV.js.map