@editora/ui-core 0.1.12 → 0.1.14

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.
Files changed (141) hide show
  1. package/README.md +95 -5
  2. package/dist/alert-dialog.cjs.js +18 -18
  3. package/dist/alert-dialog.esm.js +130 -117
  4. package/dist/app-header.cjs.js +22 -2
  5. package/dist/app-header.esm.js +22 -2
  6. package/dist/badge.cjs.js +5 -5
  7. package/dist/badge.esm.js +9 -8
  8. package/dist/color-picker.cjs.js +4 -4
  9. package/dist/color-picker.esm.js +40 -31
  10. package/dist/combobox.cjs.js +21 -21
  11. package/dist/combobox.esm.js +79 -40
  12. package/dist/command-palette.cjs.js +1 -1
  13. package/dist/command-palette.esm.js +2 -2
  14. package/dist/components/date-time-utils.d.ts +2 -1
  15. package/dist/components/date-time-utils.d.ts.map +1 -1
  16. package/dist/components/ui-alert-dialog.d.ts +2 -0
  17. package/dist/components/ui-alert-dialog.d.ts.map +1 -1
  18. package/dist/components/ui-app-header.d.ts.map +1 -1
  19. package/dist/components/ui-badge.d.ts.map +1 -1
  20. package/dist/components/ui-color-picker.d.ts.map +1 -1
  21. package/dist/components/ui-combobox.d.ts +4 -1
  22. package/dist/components/ui-combobox.d.ts.map +1 -1
  23. package/dist/components/ui-context-menu.d.ts +6 -0
  24. package/dist/components/ui-context-menu.d.ts.map +1 -1
  25. package/dist/components/ui-date-picker.d.ts +3 -0
  26. package/dist/components/ui-date-picker.d.ts.map +1 -1
  27. package/dist/components/ui-date-range-picker.d.ts +3 -0
  28. package/dist/components/ui-date-range-picker.d.ts.map +1 -1
  29. package/dist/components/ui-date-range-time-picker.d.ts +3 -0
  30. package/dist/components/ui-date-range-time-picker.d.ts.map +1 -1
  31. package/dist/components/ui-date-time-picker.d.ts +3 -0
  32. package/dist/components/ui-date-time-picker.d.ts.map +1 -1
  33. package/dist/components/ui-dialog.d.ts +3 -0
  34. package/dist/components/ui-dialog.d.ts.map +1 -1
  35. package/dist/components/ui-drawer.d.ts +14 -0
  36. package/dist/components/ui-drawer.d.ts.map +1 -1
  37. package/dist/components/ui-floating-toolbar.d.ts +3 -0
  38. package/dist/components/ui-floating-toolbar.d.ts.map +1 -1
  39. package/dist/components/ui-gantt.d.ts +30 -1
  40. package/dist/components/ui-gantt.d.ts.map +1 -1
  41. package/dist/components/ui-hover-card.d.ts +3 -0
  42. package/dist/components/ui-hover-card.d.ts.map +1 -1
  43. package/dist/components/ui-menu.d.ts +1 -0
  44. package/dist/components/ui-menu.d.ts.map +1 -1
  45. package/dist/components/ui-menubar.d.ts +1 -0
  46. package/dist/components/ui-menubar.d.ts.map +1 -1
  47. package/dist/components/ui-positioner.d.ts.map +1 -1
  48. package/dist/components/ui-quick-actions.d.ts.map +1 -1
  49. package/dist/components/ui-radio.d.ts +47 -0
  50. package/dist/components/ui-radio.d.ts.map +1 -0
  51. package/dist/components/ui-select.d.ts +8 -0
  52. package/dist/components/ui-select.d.ts.map +1 -1
  53. package/dist/components/ui-selection-popup.d.ts.map +1 -1
  54. package/dist/components/ui-stepper.d.ts.map +1 -1
  55. package/dist/components/ui-time-picker.d.ts +3 -0
  56. package/dist/components/ui-time-picker.d.ts.map +1 -1
  57. package/dist/context-menu.cjs.js +12 -12
  58. package/dist/context-menu.esm.js +160 -133
  59. package/dist/date-field.cjs.js +1 -1
  60. package/dist/date-field.esm.js +3 -2
  61. package/dist/date-picker.cjs.js +13 -13
  62. package/dist/date-picker.esm.js +101 -67
  63. package/dist/date-range-picker.cjs.js +14 -14
  64. package/dist/date-range-picker.esm.js +99 -65
  65. package/dist/date-range-time-picker.cjs.js +13 -13
  66. package/dist/date-range-time-picker.esm.js +77 -45
  67. package/dist/date-time-picker.cjs.js +13 -13
  68. package/dist/date-time-picker.esm.js +133 -101
  69. package/dist/date-time-utils-66480de4.js +1 -0
  70. package/dist/date-time-utils-a2c7af25.mjs +307 -0
  71. package/dist/dialog.cjs.js +29 -20
  72. package/dist/dialog.esm.js +90 -70
  73. package/dist/drawer.cjs.js +16 -16
  74. package/dist/drawer.esm.js +216 -98
  75. package/dist/floating-toolbar.cjs.js +6 -16
  76. package/dist/floating-toolbar.esm.js +57 -40
  77. package/dist/gantt.cjs.js +656 -74
  78. package/dist/gantt.esm.js +1050 -100
  79. package/dist/hover-card.cjs.js +4 -4
  80. package/dist/hover-card.esm.js +62 -39
  81. package/dist/index.cjs.js +1 -1
  82. package/dist/index.d.ts +2 -0
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.esm.js +300 -286
  85. package/dist/menu.cjs.js +2 -2
  86. package/dist/menu.esm.js +118 -110
  87. package/dist/menubar.cjs.js +5 -5
  88. package/dist/menubar.esm.js +83 -78
  89. package/dist/{overlayManager-ece06517.js → overlayManager-0eda4e08.js} +1 -1
  90. package/dist/{overlayManager-86454af7.mjs → overlayManager-5bbd4dc3.mjs} +1 -1
  91. package/dist/popover.cjs.js +1 -1
  92. package/dist/popover.esm.js +2 -2
  93. package/dist/portal-c69756c0.js +1 -0
  94. package/dist/portal-fe73e5cc.mjs +123 -0
  95. package/dist/portal.d.ts +29 -3
  96. package/dist/portal.d.ts.map +1 -1
  97. package/dist/positioner-33529bb8.js +1 -0
  98. package/dist/positioner-e9770c66.mjs +582 -0
  99. package/dist/positioner.cjs.js +2 -2
  100. package/dist/positioner.esm.js +36 -26
  101. package/dist/primitives/positioner.d.ts +199 -1
  102. package/dist/primitives/positioner.d.ts.map +1 -1
  103. package/dist/quick-actions.cjs.js +10 -4
  104. package/dist/quick-actions.esm.js +27 -21
  105. package/dist/radio.cjs.js +259 -0
  106. package/dist/radio.esm.js +455 -0
  107. package/dist/{runtime-4ac0107b.mjs → runtime-161f68a2.mjs} +24 -23
  108. package/dist/runtime-3f13807b.js +1 -0
  109. package/dist/runtime.cjs.js +1 -1
  110. package/dist/runtime.d.ts +2 -0
  111. package/dist/runtime.d.ts.map +1 -1
  112. package/dist/runtime.esm.js +39 -24
  113. package/dist/scroll-lock-31da444f.mjs +56 -0
  114. package/dist/scroll-lock-d7b0df21.js +1 -0
  115. package/dist/scroll-lock.d.ts.map +1 -1
  116. package/dist/select.cjs.js +14 -15
  117. package/dist/select.esm.js +117 -97
  118. package/dist/selection-popup.cjs.js +4 -7
  119. package/dist/selection-popup.esm.js +8 -11
  120. package/dist/split-button.cjs.js +1 -1
  121. package/dist/split-button.esm.js +2 -2
  122. package/dist/standalone/radio.d.ts +2 -0
  123. package/dist/standalone/radio.d.ts.map +1 -0
  124. package/dist/stepper.cjs.js +19 -50
  125. package/dist/stepper.esm.js +17 -48
  126. package/dist/time-field.cjs.js +1 -1
  127. package/dist/time-field.esm.js +3 -2
  128. package/dist/time-picker.cjs.js +15 -15
  129. package/dist/time-picker.esm.js +100 -68
  130. package/dist/tooltip.cjs.js +1 -1
  131. package/dist/tooltip.esm.js +2 -1
  132. package/package.json +1 -1
  133. package/dist/date-time-utils-5cf58cd0.js +0 -1
  134. package/dist/date-time-utils-bdceb7af.mjs +0 -273
  135. package/dist/portal-1cf392ca.mjs +0 -114
  136. package/dist/portal-d8d7fbca.js +0 -1
  137. package/dist/positioner-accc6e5f.js +0 -1
  138. package/dist/positioner-fbd61bf1.mjs +0 -132
  139. package/dist/runtime-5f282bc8.js +0 -1
  140. package/dist/scroll-lock-48793569.js +0 -1
  141. package/dist/scroll-lock-9de6d328.mjs +0 -53
package/dist/menu.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("./ElementBase-1b301e7f.js"),y=require("./portal-d8d7fbca.js"),x=require("./dismissable-layer-193e3bed.js"),A=require("./positioner-accc6e5f.js"),E=require("./menu-item-styles-83ad1e22.js");function g(r){return r==="top"||r==="left"||r==="right"?r:"bottom"}function k(r){return r==="sm"||r==="1"||r==="compact"?"sm":r==="lg"||r==="3"||r==="comfortable"?"lg":"md"}function S(r){return!r||r==="default"?null:r==="none"?"0px":r==="sm"?"8px":r==="md"?"12px":r==="lg"?"16px":r==="full"?"999px":r==="square"?"6px":r==="soft"?"14px":/^\d+(\.\d+)?$/.test(r)?`${r}px`:/^\d+(\.\d+)?(px|rem|em|%)$/.test(r)?r:null}function l(r,e){return r.getAttribute(e)||""}function h(r,e){if(r==null)return e;const t=String(r).toLowerCase();return t!=="false"&&t!=="0"}function u(){return['[role="menuitem"]','[role="menuitemcheckbox"]','[role="menuitemradio"]',".item","[data-menu-item]"].join(", ")}function m(r){return r.hasAttribute("disabled")||r.getAttribute("aria-disabled")==="true"||!!r.disabled}function p(r){const e=typeof r.composedPath=="function"?r.composedPath():[];for(const i of e)if(i instanceof HTMLElement&&i.matches(u()))return i;const t=r.target;return t instanceof HTMLElement?t.closest(u()):null}const w=new Set(["variant","density","shape","elevation","tone","size","radius"]),I=["--ui-menu-bg","--ui-menu-color","--ui-menu-border-color","--ui-menu-border","--ui-menu-shadow","--ui-menu-radius","--ui-menu-padding","--ui-menu-min-width","--ui-menu-ring","--ui-menu-backdrop","--ui-menu-z","--ui-menu-item-radius","--ui-menu-item-gap","--ui-menu-item-min-height","--ui-menu-item-pad-y","--ui-menu-item-pad-x","--ui-menu-item-font-size","--ui-menu-item-line-height","--ui-menu-separator-margin","--ui-menu-item-hover-bg","--ui-menu-item-active-color"],C=`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("./ElementBase-1b301e7f.js"),y=require("./portal-c69756c0.js"),x=require("./dismissable-layer-193e3bed.js"),A=require("./positioner-33529bb8.js"),E=require("./menu-item-styles-83ad1e22.js");function g(n){return n==="top"||n==="left"||n==="right"?n:"bottom"}function k(n){return n==="sm"||n==="1"||n==="compact"?"sm":n==="lg"||n==="3"||n==="comfortable"?"lg":"md"}function S(n){return!n||n==="default"?null:n==="none"?"0px":n==="sm"?"8px":n==="md"?"12px":n==="lg"?"16px":n==="full"?"999px":n==="square"?"6px":n==="soft"?"14px":/^\d+(\.\d+)?$/.test(n)?`${n}px`:/^\d+(\.\d+)?(px|rem|em|%)$/.test(n)?n:null}function l(n,e){return n.getAttribute(e)||""}function h(n,e){if(n==null)return e;const i=String(n).toLowerCase();return i!=="false"&&i!=="0"}function u(){return['[role="menuitem"]','[role="menuitemcheckbox"]','[role="menuitemradio"]',".item","[data-menu-item]"].join(", ")}function m(n){return n.hasAttribute("disabled")||n.getAttribute("aria-disabled")==="true"||!!n.disabled}function p(n){const e=typeof n.composedPath=="function"?n.composedPath():[];for(const t of e)if(t instanceof HTMLElement&&t.matches(u()))return t;const i=n.target;return i instanceof HTMLElement?i.closest(u()):null}const w=new Set(["variant","density","shape","elevation","tone","size","radius"]),I=["--ui-menu-bg","--ui-menu-color","--ui-menu-border-color","--ui-menu-border","--ui-menu-shadow","--ui-menu-radius","--ui-menu-padding","--ui-menu-min-width","--ui-menu-ring","--ui-menu-backdrop","--ui-menu-z","--ui-menu-item-radius","--ui-menu-item-gap","--ui-menu-item-min-height","--ui-menu-item-pad-y","--ui-menu-item-pad-x","--ui-menu-item-font-size","--ui-menu-item-line-height","--ui-menu-separator-margin","--ui-menu-item-hover-bg","--ui-menu-item-active-color"],C=`
2
2
  :host {
3
3
  --ui-menu-bg: var(--base-menu-bg, var(--color-panel-solid, var(--ui-color-surface, var(--ui-surface, #ffffff))));
4
4
  --ui-menu-color: var(--ui-color-text, var(--ui-text, #0f172a));
@@ -262,7 +262,7 @@
262
262
  box-shadow: none;
263
263
  }
264
264
  }
265
- `;class _ extends v.ElementBase{constructor(){super(),this._isOpen=!1,this._portalEl=null,this._positioner=null,this._dismissableLayer=null,this._restoreFocusEl=null,this._typeaheadBuffer="",this._typeaheadTimer=null,this._globalListenersBound=!1,this._menuClickHandler=null,this._menuId=`ui-menu-${Math.random().toString(36).slice(2,10)}`,this._onHostClick=this._onHostClick.bind(this),this._onDocumentKeyDown=this._onDocumentKeyDown.bind(this),this._onDocumentScroll=this._onDocumentScroll.bind(this),this._onSlotChange=this._onSlotChange.bind(this)}static get observedAttributes(){return["open","disabled","placement","variant","size","density","radius","shape","elevation","tone","close-on-select","close-on-scroll","typeahead"]}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this._onHostClick),this.root.addEventListener("slotchange",this._onSlotChange),this._syncOpenState(),this._syncTriggerA11y()}disconnectedCallback(){this.removeEventListener("click",this._onHostClick),this.root.removeEventListener("slotchange",this._onSlotChange),this._unbindGlobalListeners(),this._teardownPortal(),super.disconnectedCallback()}attributeChangedCallback(e,t,i){if(t!==i){if(e==="open"){this._syncOpenState();return}if(!(e==="close-on-select"||e==="close-on-scroll"||e==="typeahead")){if(e==="disabled"){this.hasAttribute("disabled")&&this.close(),this._syncTriggerA11y();return}if(e==="placement"&&this._isOpen){this._rebuildPositioner();return}w.has(e)&&this._isOpen&&this._syncPortalVisualState()}}}open(){this.hasAttribute("disabled")||this.setAttribute("open","")}close(){this.removeAttribute("open")}toggle(){this.hasAttribute("open")?this.close():this.open()}get closeOnSelect(){return h(this.getAttribute("close-on-select"),!0)}set closeOnSelect(e){this.setAttribute("close-on-select",e?"true":"false")}get closeOnScroll(){return h(this.getAttribute("close-on-scroll"),!0)}set closeOnScroll(e){this.setAttribute("close-on-scroll",e?"true":"false")}get typeahead(){return h(this.getAttribute("typeahead"),!0)}set typeahead(e){this.setAttribute("typeahead",e?"true":"false")}_getTrigger(){return this.querySelector('[slot="trigger"]')}_getContentSource(){return this.querySelector('[slot="content"]')}_getItemSources(){return Array.from(this.querySelectorAll('[slot="item"]'))}_onSlotChange(){this._isOpen&&this._rebuildPortalContent()}_syncTriggerA11y(){const e=this._getTrigger();if(e){if(e.setAttribute("aria-haspopup","menu"),e.setAttribute("aria-expanded",this._isOpen?"true":"false"),e.setAttribute("aria-controls",this._menuId),this.hasAttribute("disabled")){e.setAttribute("aria-disabled","true"),e.setAttribute("tabindex","-1");return}e.getAttribute("aria-disabled")==="true"&&e.removeAttribute("aria-disabled"),e.getAttribute("tabindex")==="-1"&&e.removeAttribute("tabindex")}}_syncOpenState(){var i;const e=this.hasAttribute("open")&&!this.hasAttribute("disabled");if(e===this._isOpen){this._syncTriggerA11y(),e&&!this._portalEl?this._mountPortal():e&&((i=this._positioner)==null||i.update());return}if(this._isOpen=e,this._syncTriggerA11y(),e){this._bindGlobalListeners(),this._restoreFocusEl=document.activeElement,this._mountPortal(),this.dispatchEvent(new CustomEvent("open",{bubbles:!0})),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{open:!0}})),requestAnimationFrame(()=>this._focusFirstItem());return}this._unbindGlobalListeners(),this._teardownPortal(),this.dispatchEvent(new CustomEvent("close",{bubbles:!0})),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{open:!1}}));const t=this._getTrigger();if(t)try{t.focus({preventScroll:!0})}catch{t.focus()}this._restoreFocusEl=null}_bindGlobalListeners(){this._globalListenersBound||(document.addEventListener("keydown",this._onDocumentKeyDown),document.addEventListener("scroll",this._onDocumentScroll,!0),this._globalListenersBound=!0)}_unbindGlobalListeners(){this._globalListenersBound&&(document.removeEventListener("keydown",this._onDocumentKeyDown),document.removeEventListener("scroll",this._onDocumentScroll,!0),this._globalListenersBound=!1)}_clearActiveState(){this._portalEl&&this._portalEl.querySelectorAll(u()).forEach(e=>e.removeAttribute("data-active"))}_queryItems(){return this._portalEl?Array.from(this._portalEl.querySelectorAll(u())).filter(e=>!m(e)):[]}_focusItem(e){if(e){this._clearActiveState(),e.setAttribute("data-active","true");try{e.focus({preventScroll:!0})}catch{e.focus()}typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}}_focusFirstItem(){this._focusItem(this._queryItems()[0]||null)}_focusLastItem(){const e=this._queryItems();this._focusItem(e[e.length-1]||null)}_moveFocus(e){const t=this._queryItems();if(!t.length)return;const i=document.activeElement,n=i?t.findIndex(o=>o===i||o.contains(i)):-1,a=n===-1?0:Math.max(0,Math.min(t.length-1,n+e));this._focusItem(t[a]||null)}_resetTypeahead(){this._typeaheadBuffer="",this._typeaheadTimer!=null&&(window.clearTimeout(this._typeaheadTimer),this._typeaheadTimer=null)}_isTypeaheadKey(e){return e.ctrlKey||e.metaKey||e.altKey?!1:e.key.length===1&&/\S/.test(e.key)}_handleTypeahead(e){if(!this.typeahead||!this._isTypeaheadKey(e))return!1;this._typeaheadBuffer=`${this._typeaheadBuffer}${e.key.toLowerCase()}`.slice(0,24),this._typeaheadTimer!=null&&window.clearTimeout(this._typeaheadTimer),this._typeaheadTimer=window.setTimeout(()=>this._resetTypeahead(),420);const t=document.activeElement,i=this._queryItems();if(!i.length)return!1;const n=t?i.findIndex(s=>s===t||s.contains(t)):-1,o=(n>=0?[...i.slice(n+1),...i.slice(0,n+1)]:i).find(s=>(s.textContent||"").trim().toLowerCase().startsWith(this._typeaheadBuffer));return o?(e.preventDefault(),this._focusItem(o),!0):!1}_applySelectionBehavior(e){const t=e.getAttribute("role");if(t==="menuitemcheckbox"){const n=e.getAttribute("aria-checked")==="true";e.setAttribute("aria-checked",n?"false":"true"),e.setAttribute("data-state",n?"unchecked":"checked");return}if(t!=="menuitemradio"||!this._portalEl)return;const i=e.getAttribute("data-group")||e.getAttribute("name")||"";this._portalEl.querySelectorAll('[role="menuitemradio"]').forEach(n=>{const a=n.getAttribute("data-group")||n.getAttribute("name")||"";i&&a!==i||(n.setAttribute("aria-checked",n===e?"true":"false"),n.setAttribute("data-state",n===e?"checked":"unchecked"))})}_handleItemSelect(e){var n;this._applySelectionBehavior(e);const t=e.getAttribute("data-index"),i=t!=null&&!Number.isNaN(Number(t))?Number(t):void 0;this.dispatchEvent(new CustomEvent("select",{bubbles:!0,detail:{index:i,value:e.getAttribute("data-value")||e.getAttribute("value")||void 0,label:e.getAttribute("aria-label")||((n=e.textContent)==null?void 0:n.trim())||void 0,checked:e.getAttribute("aria-checked")==="true",item:e}})),this.closeOnSelect?this.close():this._focusItem(e)}_buildLegacyItems(e){const t=this._getItemSources();return t.forEach((i,n)=>{const a=i.cloneNode(!0);a.removeAttribute("slot"),a.getAttribute("role")||a.setAttribute("role","menuitem"),a.classList.contains("item")||a.classList.add("item"),a.hasAttribute("tabindex")||a.setAttribute("tabindex","-1"),a.hasAttribute("data-index")||a.setAttribute("data-index",String(n)),e.appendChild(a)}),t.length}_hydrateMenuItems(e){const t=Array.from(e.querySelectorAll(u()));return t.forEach((i,n)=>{i.getAttribute("role")||i.setAttribute("role","menuitem"),i.hasAttribute("tabindex")||i.setAttribute("tabindex","-1"),i.classList.contains("item")||i.classList.add("item"),i.hasAttribute("data-index")||i.setAttribute("data-index",String(n))}),t.length}_applyPortalTokens(e){const t=window.getComputedStyle(this);I.forEach(i=>{const n=t.getPropertyValue(i).trim();n?e.style.setProperty(i,n):e.style.removeProperty(i)})}_applyPortalVariantData(e){const t=l(this,"variant"),i=k(this.getAttribute("size")||this.getAttribute("density")),n=l(this,"density"),a=this.getAttribute("radius"),o=l(this,"shape"),s=l(this,"elevation"),c=l(this,"tone"),f=t==="default"||t===""?"":t==="line"?"outline":t==="glass"?"soft":t;f?e.setAttribute("data-variant",f):e.removeAttribute("data-variant"),i!=="md"?e.setAttribute("data-size",i):e.removeAttribute("data-size"),n&&n!=="default"?e.setAttribute("data-density",n):e.removeAttribute("data-density"),s&&s!=="default"?e.setAttribute("data-elevation",s):e.removeAttribute("data-elevation");const b=c==="default"||c==="brand"||c===""?"":c;b?e.setAttribute("data-tone",b):e.removeAttribute("data-tone");const d=S(a||o||null);d?(e.style.setProperty("--ui-menu-radius",d),e.style.setProperty("--ui-menu-item-radius",d==="999px"?"999px":`calc(${d} - 2px)`)):(e.style.removeProperty("--ui-menu-radius"),e.style.removeProperty("--ui-menu-item-radius"))}_syncPortalVisualState(){this._portalEl&&(this._applyPortalTokens(this._portalEl),this._applyPortalVariantData(this._portalEl),this._portalEl.setAttribute("aria-hidden","false"),this._portalEl.setAttribute("aria-busy","false"),this._portalEl.style.display="block",this._portalEl.style.visibility="visible",this._portalEl.style.opacity="1",this._portalEl.style.transform="translateY(0px) scale(1)",this._portalEl.style.pointerEvents="auto")}_attachMenuEvents(e){this._menuClickHandler=t=>{const i=p(t);!i||m(i)||this._handleItemSelect(i)},e.addEventListener("click",this._menuClickHandler),e.addEventListener("mouseover",t=>{const i=p(t);!i||m(i)||this._focusItem(i)}),e.addEventListener("focusin",t=>{const i=p(t);!i||m(i)||this._focusItem(i)}),e.addEventListener("mouseleave",()=>this._clearActiveState())}_buildPortalElement(){const e=document.createElement("div");e.className="surface menu",e.id=this._menuId,e.setAttribute("part","menu"),e.setAttribute("role","menu"),e.setAttribute("tabindex","-1"),e.setAttribute("aria-hidden","false"),e.setAttribute("aria-busy","false"),e.setAttribute("data-placement",g(this.getAttribute("placement")));const t=document.createElement("style");t.textContent=T,e.appendChild(t);const i=this._getContentSource();let n=0;if(i){const a=i.cloneNode(!0);a.removeAttribute("slot"),e.appendChild(a)}else n=this._buildLegacyItems(e);if(n=this._hydrateMenuItems(e)||n,n===0){const a=document.createElement("div");a.className="empty-state",a.textContent="No items",e.appendChild(a)}return this._applyPortalTokens(e),this._applyPortalVariantData(e),e.style.display="block",e.style.visibility="visible",e.style.opacity="1",e.style.transform="translateY(0px) scale(1)",e.style.pointerEvents="auto",this._attachMenuEvents(e),e}_rebuildPortalContent(){if(!this._portalEl)return;const e=this._portalEl.parentElement;if(!e)return;const t=this._portalEl,i=this._buildPortalElement();e.replaceChild(i,t),this._portalEl=i,this._rebuildPositioner()}_rebuildPositioner(){var t;const e=this._getTrigger();!this._portalEl||!e||((t=this._positioner)==null||t.destroy(),this._positioner=A.createPositioner({anchor:e,floating:this._portalEl,placement:g(this.getAttribute("placement")),offset:6,flip:!0,shift:!0,fitViewport:!0,observeScroll:!1}))}_mountPortal(){var t;const e=this._getTrigger();if(e){if(this._portalEl)this._syncPortalVisualState();else{this._portalEl=this._buildPortalElement();const i=y.createPortalContainer();if(!i){this._portalEl=null;return}i.appendChild(this._portalEl)}this._rebuildPositioner(),(t=this._dismissableLayer)==null||t.destroy(),this._dismissableLayer=x.createDismissableLayer({node:this._portalEl,trigger:e,closeOnEscape:!0,closeOnPointerOutside:!0,onDismiss:()=>this.close()})}}_teardownPortal(){var e,t,i;if((e=this._dismissableLayer)==null||e.destroy(),this._dismissableLayer=null,(t=this._positioner)==null||t.destroy(),this._positioner=null,(i=this._portalEl)!=null&&i.parentElement)try{this._portalEl.parentElement.removeChild(this._portalEl)}catch{}this._portalEl=null,this._menuClickHandler=null,this._resetTypeahead()}_isEventInsideTrigger(e){const t=this._getTrigger();return!!t&&e.composedPath().includes(t)}_isEventInsideMenu(e){return!!this._portalEl&&e.composedPath().includes(this._portalEl)}_onHostClick(e){this.hasAttribute("disabled")||this._isEventInsideTrigger(e)&&(e.preventDefault(),this.toggle())}_onDocumentScroll(e){if(!this._isOpen||!this.closeOnScroll)return;const t=typeof e.composedPath=="function"?e.composedPath():[];this._portalEl&&t.includes(this._portalEl)||this.close()}_onDocumentKeyDown(e){var t;if(!this._isOpen){if(e.key!=="ArrowDown"&&e.key!=="ArrowUp"||!this._isEventInsideTrigger(e))return;e.preventDefault(),this.open(),requestAnimationFrame(()=>{e.key==="ArrowUp"?this._focusLastItem():this._focusFirstItem()});return}if(!(!this._isEventInsideTrigger(e)&&!this._isEventInsideMenu(e))&&!this._handleTypeahead(e)){if(e.key==="Escape"){e.preventDefault(),e.stopPropagation(),this.close();return}if(e.key==="ArrowDown"){e.preventDefault(),this._moveFocus(1);return}if(e.key==="ArrowUp"){e.preventDefault(),this._moveFocus(-1);return}if(e.key==="Home"){e.preventDefault(),this._focusFirstItem();return}if(e.key==="End"){e.preventDefault(),this._focusLastItem();return}if(e.key==="Tab"){this.close();return}if(e.key==="Enter"||e.key===" "){const i=document.activeElement;if(!i||!((t=this._portalEl)!=null&&t.contains(i)))return;const n=i.closest(u());if(!n||m(n))return;e.preventDefault(),this._handleItemSelect(n)}}}render(){var e;this.setContent(`
265
+ `;class _ extends v.ElementBase{constructor(){super(),this._isOpen=!1,this._portalEl=null,this._positioner=null,this._dismissableLayer=null,this._restoreFocusEl=null,this._typeaheadBuffer="",this._typeaheadTimer=null,this._globalListenersBound=!1,this._menuClickHandler=null,this._menuId=`ui-menu-${Math.random().toString(36).slice(2,10)}`,this._onHostClick=this._onHostClick.bind(this),this._onDocumentKeyDown=this._onDocumentKeyDown.bind(this),this._onDocumentScroll=this._onDocumentScroll.bind(this),this._onSlotChange=this._onSlotChange.bind(this)}static get observedAttributes(){return["open","disabled","placement","variant","size","density","radius","shape","elevation","tone","close-on-select","close-on-scroll","typeahead"]}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this._onHostClick),this.root.addEventListener("slotchange",this._onSlotChange),this._syncOpenState(),this._syncTriggerA11y()}disconnectedCallback(){this.removeEventListener("click",this._onHostClick),this.root.removeEventListener("slotchange",this._onSlotChange),this._unbindGlobalListeners(),this._teardownPortal(),super.disconnectedCallback()}attributeChangedCallback(e,i,t){if(i!==t){if(e==="open"){this._syncOpenState();return}if(!(e==="close-on-select"||e==="close-on-scroll"||e==="typeahead")){if(e==="disabled"){this.hasAttribute("disabled")&&this.close(),this._syncTriggerA11y();return}if(e==="placement"&&this._isOpen){this._rebuildPositioner();return}w.has(e)&&this._isOpen&&this._syncPortalVisualState()}}}open(){this.hasAttribute("disabled")||this.setAttribute("open","")}close(){this.removeAttribute("open")}toggle(){this.hasAttribute("open")?this.close():this.open()}get closeOnSelect(){return h(this.getAttribute("close-on-select"),!0)}set closeOnSelect(e){this.setAttribute("close-on-select",e?"true":"false")}get closeOnScroll(){return h(this.getAttribute("close-on-scroll"),!0)}set closeOnScroll(e){this.setAttribute("close-on-scroll",e?"true":"false")}get typeahead(){return h(this.getAttribute("typeahead"),!0)}set typeahead(e){this.setAttribute("typeahead",e?"true":"false")}_getTrigger(){return this.querySelector('[slot="trigger"]')}_getContentSource(){return this.querySelector('[slot="content"]')}_getItemSources(){return Array.from(this.querySelectorAll('[slot="item"]'))}_onSlotChange(){this._isOpen&&this._rebuildPortalContent()}_syncTriggerA11y(){const e=this._getTrigger();if(e){if(e.setAttribute("aria-haspopup","menu"),e.setAttribute("aria-expanded",this._isOpen?"true":"false"),e.setAttribute("aria-controls",this._menuId),this.hasAttribute("disabled")){e.setAttribute("aria-disabled","true"),e.setAttribute("tabindex","-1");return}e.getAttribute("aria-disabled")==="true"&&e.removeAttribute("aria-disabled"),e.getAttribute("tabindex")==="-1"&&e.removeAttribute("tabindex")}}_syncOpenState(){var t;const e=this.hasAttribute("open")&&!this.hasAttribute("disabled");if(e===this._isOpen){this._syncTriggerA11y(),e&&!this._portalEl?this._mountPortal():e&&((t=this._positioner)==null||t.update());return}if(this._isOpen=e,this._syncTriggerA11y(),e){this._bindGlobalListeners(),this._restoreFocusEl=document.activeElement,this._mountPortal(),this.dispatchEvent(new CustomEvent("open",{bubbles:!0})),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{open:!0}})),requestAnimationFrame(()=>this._focusFirstItem());return}this._unbindGlobalListeners(),this._teardownPortal(),this.dispatchEvent(new CustomEvent("close",{bubbles:!0})),this.dispatchEvent(new CustomEvent("change",{bubbles:!0,detail:{open:!1}}));const i=this._getTrigger();if(i)try{i.focus({preventScroll:!0})}catch{i.focus()}this._restoreFocusEl=null}_bindGlobalListeners(){this._globalListenersBound||(document.addEventListener("keydown",this._onDocumentKeyDown),document.addEventListener("scroll",this._onDocumentScroll,{passive:!0,capture:!0}),this._globalListenersBound=!0)}_unbindGlobalListeners(){this._globalListenersBound&&(document.removeEventListener("keydown",this._onDocumentKeyDown),document.removeEventListener("scroll",this._onDocumentScroll,!0),this._globalListenersBound=!1)}_clearActiveState(){this._portalEl&&this._portalEl.querySelectorAll(u()).forEach(e=>e.removeAttribute("data-active"))}_queryItems(){return this._portalEl?Array.from(this._portalEl.querySelectorAll(u())).filter(e=>!m(e)):[]}_focusItem(e){if(e){this._clearActiveState(),e.setAttribute("data-active","true");try{e.focus({preventScroll:!0})}catch{e.focus()}typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}}_focusFirstItem(){this._focusItem(this._queryItems()[0]||null)}_focusLastItem(){const e=this._queryItems();this._focusItem(e[e.length-1]||null)}_moveFocus(e){const i=this._queryItems();if(!i.length)return;const t=document.activeElement,r=t?i.findIndex(o=>o===t||o.contains(t)):-1,a=r===-1?0:Math.max(0,Math.min(i.length-1,r+e));this._focusItem(i[a]||null)}_resetTypeahead(){this._typeaheadBuffer="",this._typeaheadTimer!=null&&(window.clearTimeout(this._typeaheadTimer),this._typeaheadTimer=null)}_isTypeaheadKey(e){return e.ctrlKey||e.metaKey||e.altKey?!1:e.key.length===1&&/\S/.test(e.key)}_handleTypeahead(e){if(!this.typeahead||!this._isTypeaheadKey(e))return!1;this._typeaheadBuffer=`${this._typeaheadBuffer}${e.key.toLowerCase()}`.slice(0,24),this._typeaheadTimer!=null&&window.clearTimeout(this._typeaheadTimer),this._typeaheadTimer=window.setTimeout(()=>this._resetTypeahead(),420);const i=document.activeElement,t=this._queryItems();if(!t.length)return!1;const r=i?t.findIndex(s=>s===i||s.contains(i)):-1,o=(r>=0?[...t.slice(r+1),...t.slice(0,r+1)]:t).find(s=>(s.textContent||"").trim().toLowerCase().startsWith(this._typeaheadBuffer));return o?(e.preventDefault(),this._focusItem(o),!0):!1}_applySelectionBehavior(e){const i=e.getAttribute("role");if(i==="menuitemcheckbox"){const r=e.getAttribute("aria-checked")==="true";e.setAttribute("aria-checked",r?"false":"true"),e.setAttribute("data-state",r?"unchecked":"checked");return}if(i!=="menuitemradio"||!this._portalEl)return;const t=e.getAttribute("data-group")||e.getAttribute("name")||"";this._portalEl.querySelectorAll('[role="menuitemradio"]').forEach(r=>{const a=r.getAttribute("data-group")||r.getAttribute("name")||"";t&&a!==t||(r.setAttribute("aria-checked",r===e?"true":"false"),r.setAttribute("data-state",r===e?"checked":"unchecked"))})}_handleItemSelect(e){var r;this._applySelectionBehavior(e);const i=e.getAttribute("data-index"),t=i!=null&&!Number.isNaN(Number(i))?Number(i):void 0;this.dispatchEvent(new CustomEvent("select",{bubbles:!0,detail:{index:t,value:e.getAttribute("data-value")||e.getAttribute("value")||void 0,label:e.getAttribute("aria-label")||((r=e.textContent)==null?void 0:r.trim())||void 0,checked:e.getAttribute("aria-checked")==="true",item:e}})),this.closeOnSelect?this.close():this._focusItem(e)}_buildLegacyItems(e){const i=this._getItemSources();return i.forEach((t,r)=>{const a=t.cloneNode(!0);a.removeAttribute("slot"),a.getAttribute("role")||a.setAttribute("role","menuitem"),a.classList.contains("item")||a.classList.add("item"),a.hasAttribute("tabindex")||a.setAttribute("tabindex","-1"),a.hasAttribute("data-index")||a.setAttribute("data-index",String(r)),e.appendChild(a)}),i.length}_hydrateMenuItems(e){const i=Array.from(e.querySelectorAll(u()));return i.forEach((t,r)=>{t.getAttribute("role")||t.setAttribute("role","menuitem"),t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1"),t.classList.contains("item")||t.classList.add("item"),t.hasAttribute("data-index")||t.setAttribute("data-index",String(r))}),i.length}_applyPortalTokens(e){const i=window.getComputedStyle(this);I.forEach(t=>{const r=i.getPropertyValue(t).trim();r?e.style.setProperty(t,r):e.style.removeProperty(t)})}_applyPortalVariantData(e){const i=l(this,"variant"),t=k(this.getAttribute("size")||this.getAttribute("density")),r=l(this,"density"),a=this.getAttribute("radius"),o=l(this,"shape"),s=l(this,"elevation"),c=l(this,"tone"),f=i==="default"||i===""?"":i==="line"?"outline":i==="glass"?"soft":i;f?e.setAttribute("data-variant",f):e.removeAttribute("data-variant"),t!=="md"?e.setAttribute("data-size",t):e.removeAttribute("data-size"),r&&r!=="default"?e.setAttribute("data-density",r):e.removeAttribute("data-density"),s&&s!=="default"?e.setAttribute("data-elevation",s):e.removeAttribute("data-elevation");const b=c==="default"||c==="brand"||c===""?"":c;b?e.setAttribute("data-tone",b):e.removeAttribute("data-tone");const d=S(a||o||null);d?(e.style.setProperty("--ui-menu-radius",d),e.style.setProperty("--ui-menu-item-radius",d==="999px"?"999px":`calc(${d} - 2px)`)):(e.style.removeProperty("--ui-menu-radius"),e.style.removeProperty("--ui-menu-item-radius"))}_syncPortalVisualState(){this._portalEl&&(this._applyPortalTokens(this._portalEl),this._applyPortalVariantData(this._portalEl),this._portalEl.setAttribute("aria-hidden","false"),this._portalEl.setAttribute("aria-busy","false"),this._portalEl.style.display="block",this._portalEl.style.visibility="visible",this._portalEl.style.opacity="1",this._portalEl.style.transform="translateY(0px) scale(1)",this._portalEl.style.pointerEvents="auto")}_attachMenuEvents(e){this._menuClickHandler=i=>{const t=p(i);!t||m(t)||this._handleItemSelect(t)},e.addEventListener("click",this._menuClickHandler),e.addEventListener("mouseover",i=>{const t=p(i);!t||m(t)||this._focusItem(t)}),e.addEventListener("focusin",i=>{const t=p(i);!t||m(t)||this._focusItem(t)}),e.addEventListener("mouseleave",()=>this._clearActiveState())}_buildPortalElement(){const e=document.createElement("div");e.className="surface menu",e.id=this._menuId,e.setAttribute("part","menu"),e.setAttribute("role","menu"),e.setAttribute("tabindex","-1"),e.setAttribute("aria-hidden","false"),e.setAttribute("aria-busy","false"),e.setAttribute("data-placement",g(this.getAttribute("placement")));const i=document.createElement("style");i.textContent=T,e.appendChild(i);const t=this._getContentSource();let r=0;if(t){const a=t.cloneNode(!0);a.removeAttribute("slot"),e.appendChild(a)}else r=this._buildLegacyItems(e);if(r=this._hydrateMenuItems(e)||r,r===0){const a=document.createElement("div");a.className="empty-state",a.textContent="No items",e.appendChild(a)}return this._applyPortalTokens(e),this._applyPortalVariantData(e),e.style.display="block",e.style.visibility="visible",e.style.opacity="1",e.style.transform="translateY(0px) scale(1)",e.style.pointerEvents="auto",this._attachMenuEvents(e),e}_rebuildPortalContent(){if(!this._portalEl)return;const e=this._portalEl.parentElement;if(!e)return;const i=this._portalEl,t=this._buildPortalElement();e.replaceChild(t,i),this._portalEl=t,this._rebuildPositioner()}_rebuildPositioner(){var i;const e=this._getTrigger();!this._portalEl||!e||((i=this._positioner)==null||i.destroy(),this._positioner=A.createPositioner({anchor:e,floating:this._portalEl,placement:g(this.getAttribute("placement")),offset:6,flip:!0,shift:!0,fitViewport:!0,observeScroll:!1}))}_mountPortal(){var i;const e=this._getTrigger();if(e){if(this._portalEl)this._syncPortalVisualState();else{this._portalEl=this._buildPortalElement();const t=y.createPortalContainer();if(!t){this._portalEl=null;return}t.appendChild(this._portalEl)}this._rebuildPositioner(),(i=this._dismissableLayer)==null||i.destroy(),this._dismissableLayer=x.createDismissableLayer({node:this._portalEl,trigger:e,closeOnEscape:!0,closeOnPointerOutside:!0,onDismiss:()=>this.close()})}}_teardownPortal(){var e,i,t;if((e=this._dismissableLayer)==null||e.destroy(),this._dismissableLayer=null,(i=this._positioner)==null||i.destroy(),this._positioner=null,(t=this._portalEl)!=null&&t.parentElement)try{this._portalEl.parentElement.removeChild(this._portalEl)}catch{}this._portalEl=null,this._menuClickHandler=null,this._resetTypeahead()}_isEventInsideTrigger(e){const i=this._getTrigger();return!!i&&e.composedPath().includes(i)}_isEventInsideMenu(e){return!!this._portalEl&&e.composedPath().includes(this._portalEl)}_isInternalScrollEvent(e){var a;const i=typeof e.composedPath=="function"?e.composedPath():[];if(this._portalEl&&i.includes(this._portalEl))return!0;const t=this._getTrigger();if(t&&i.includes(t))return!0;const r=e.target;return!!(r instanceof Node&&((a=this._portalEl)!=null&&a.contains(r)||t!=null&&t.contains(r)))}_onHostClick(e){this.hasAttribute("disabled")||this._isEventInsideTrigger(e)&&(e.preventDefault(),this.toggle())}_onDocumentScroll(e){!this._isOpen||!this.closeOnScroll||this._isInternalScrollEvent(e)||this.close()}_onDocumentKeyDown(e){var i;if(!this._isOpen){if(e.key!=="ArrowDown"&&e.key!=="ArrowUp"||!this._isEventInsideTrigger(e))return;e.preventDefault(),this.open(),requestAnimationFrame(()=>{e.key==="ArrowUp"?this._focusLastItem():this._focusFirstItem()});return}if(!(!this._isEventInsideTrigger(e)&&!this._isEventInsideMenu(e))&&!this._handleTypeahead(e)){if(e.key==="Escape"){e.preventDefault(),e.stopPropagation(),this.close();return}if(e.key==="ArrowDown"){e.preventDefault(),this._moveFocus(1);return}if(e.key==="ArrowUp"){e.preventDefault(),this._moveFocus(-1);return}if(e.key==="Home"){e.preventDefault(),this._focusFirstItem();return}if(e.key==="End"){e.preventDefault(),this._focusLastItem();return}if(e.key==="Tab"){this.close();return}if(e.key==="Enter"||e.key===" "){const t=document.activeElement;if(!t||!((i=this._portalEl)!=null&&i.contains(t)))return;const r=t.closest(u());if(!r||m(r))return;e.preventDefault(),this._handleItemSelect(r)}}}render(){var e;this.setContent(`
266
266
  <style>${C}</style>
267
267
  <div class="trigger" part="trigger">
268
268
  <slot name="trigger"></slot>
package/dist/menu.esm.js CHANGED
@@ -1,25 +1,25 @@
1
1
  import { E as _ } from "./ElementBase-909688f3.mjs";
2
- import { c as v } from "./portal-1cf392ca.mjs";
2
+ import { c as v } from "./portal-fe73e5cc.mjs";
3
3
  import { c as y } from "./dismissable-layer-9c7e6b58.mjs";
4
- import { a as x } from "./positioner-fbd61bf1.mjs";
4
+ import { l as x } from "./positioner-e9770c66.mjs";
5
5
  import { c as A } from "./menu-item-styles-27fdbac4.mjs";
6
- function g(r) {
7
- return r === "top" || r === "left" || r === "right" ? r : "bottom";
6
+ function g(n) {
7
+ return n === "top" || n === "left" || n === "right" ? n : "bottom";
8
8
  }
9
- function E(r) {
10
- return r === "sm" || r === "1" || r === "compact" ? "sm" : r === "lg" || r === "3" || r === "comfortable" ? "lg" : "md";
9
+ function E(n) {
10
+ return n === "sm" || n === "1" || n === "compact" ? "sm" : n === "lg" || n === "3" || n === "comfortable" ? "lg" : "md";
11
11
  }
12
- function k(r) {
13
- return !r || r === "default" ? null : r === "none" ? "0px" : r === "sm" ? "8px" : r === "md" ? "12px" : r === "lg" ? "16px" : r === "full" ? "999px" : r === "square" ? "6px" : r === "soft" ? "14px" : /^\d+(\.\d+)?$/.test(r) ? `${r}px` : /^\d+(\.\d+)?(px|rem|em|%)$/.test(r) ? r : null;
12
+ function k(n) {
13
+ return !n || n === "default" ? null : n === "none" ? "0px" : n === "sm" ? "8px" : n === "md" ? "12px" : n === "lg" ? "16px" : n === "full" ? "999px" : n === "square" ? "6px" : n === "soft" ? "14px" : /^\d+(\.\d+)?$/.test(n) ? `${n}px` : /^\d+(\.\d+)?(px|rem|em|%)$/.test(n) ? n : null;
14
14
  }
15
- function l(r, e) {
16
- return r.getAttribute(e) || "";
15
+ function l(n, e) {
16
+ return n.getAttribute(e) || "";
17
17
  }
18
- function h(r, e) {
19
- if (r == null)
18
+ function h(n, e) {
19
+ if (n == null)
20
20
  return e;
21
- const t = String(r).toLowerCase();
22
- return t !== "false" && t !== "0";
21
+ const i = String(n).toLowerCase();
22
+ return i !== "false" && i !== "0";
23
23
  }
24
24
  function u() {
25
25
  return [
@@ -30,16 +30,16 @@ function u() {
30
30
  "[data-menu-item]"
31
31
  ].join(", ");
32
32
  }
33
- function m(r) {
34
- return r.hasAttribute("disabled") || r.getAttribute("aria-disabled") === "true" || !!r.disabled;
33
+ function m(n) {
34
+ return n.hasAttribute("disabled") || n.getAttribute("aria-disabled") === "true" || !!n.disabled;
35
35
  }
36
- function p(r) {
37
- const e = typeof r.composedPath == "function" ? r.composedPath() : [];
38
- for (const i of e)
39
- if (i instanceof HTMLElement && i.matches(u()))
40
- return i;
41
- const t = r.target;
42
- return t instanceof HTMLElement ? t.closest(u()) : null;
36
+ function p(n) {
37
+ const e = typeof n.composedPath == "function" ? n.composedPath() : [];
38
+ for (const t of e)
39
+ if (t instanceof HTMLElement && t.matches(u()))
40
+ return t;
41
+ const i = n.target;
42
+ return i instanceof HTMLElement ? i.closest(u()) : null;
43
43
  }
44
44
  const w = /* @__PURE__ */ new Set(["variant", "density", "shape", "elevation", "tone", "size", "radius"]), S = [
45
45
  "--ui-menu-bg",
@@ -63,7 +63,7 @@ const w = /* @__PURE__ */ new Set(["variant", "density", "shape", "elevation", "
63
63
  "--ui-menu-separator-margin",
64
64
  "--ui-menu-item-hover-bg",
65
65
  "--ui-menu-item-active-color"
66
- ], C = `
66
+ ], I = `
67
67
  :host {
68
68
  --ui-menu-bg: var(--base-menu-bg, var(--color-panel-solid, var(--ui-color-surface, var(--ui-surface, #ffffff))));
69
69
  --ui-menu-color: var(--ui-color-text, var(--ui-text, #0f172a));
@@ -105,7 +105,7 @@ const w = /* @__PURE__ */ new Set(["variant", "density", "shape", "elevation", "
105
105
  pointer-events: none;
106
106
  opacity: 0.62;
107
107
  }
108
- `, I = `
108
+ `, C = `
109
109
  .menu {
110
110
  position: absolute;
111
111
  display: flex;
@@ -366,8 +366,8 @@ class T extends _ {
366
366
  disconnectedCallback() {
367
367
  this.removeEventListener("click", this._onHostClick), this.root.removeEventListener("slotchange", this._onSlotChange), this._unbindGlobalListeners(), this._teardownPortal(), super.disconnectedCallback();
368
368
  }
369
- attributeChangedCallback(e, t, i) {
370
- if (t !== i) {
369
+ attributeChangedCallback(e, i, t) {
370
+ if (i !== t) {
371
371
  if (e === "open") {
372
372
  this._syncOpenState();
373
373
  return;
@@ -435,10 +435,10 @@ class T extends _ {
435
435
  }
436
436
  }
437
437
  _syncOpenState() {
438
- var i;
438
+ var t;
439
439
  const e = this.hasAttribute("open") && !this.hasAttribute("disabled");
440
440
  if (e === this._isOpen) {
441
- this._syncTriggerA11y(), e && !this._portalEl ? this._mountPortal() : e && ((i = this._positioner) == null || i.update());
441
+ this._syncTriggerA11y(), e && !this._portalEl ? this._mountPortal() : e && ((t = this._positioner) == null || t.update());
442
442
  return;
443
443
  }
444
444
  if (this._isOpen = e, this._syncTriggerA11y(), e) {
@@ -446,17 +446,17 @@ class T extends _ {
446
446
  return;
447
447
  }
448
448
  this._unbindGlobalListeners(), this._teardownPortal(), this.dispatchEvent(new CustomEvent("close", { bubbles: !0 })), this.dispatchEvent(new CustomEvent("change", { bubbles: !0, detail: { open: !1 } }));
449
- const t = this._getTrigger();
450
- if (t)
449
+ const i = this._getTrigger();
450
+ if (i)
451
451
  try {
452
- t.focus({ preventScroll: !0 });
452
+ i.focus({ preventScroll: !0 });
453
453
  } catch {
454
- t.focus();
454
+ i.focus();
455
455
  }
456
456
  this._restoreFocusEl = null;
457
457
  }
458
458
  _bindGlobalListeners() {
459
- this._globalListenersBound || (document.addEventListener("keydown", this._onDocumentKeyDown), document.addEventListener("scroll", this._onDocumentScroll, !0), this._globalListenersBound = !0);
459
+ this._globalListenersBound || (document.addEventListener("keydown", this._onDocumentKeyDown), document.addEventListener("scroll", this._onDocumentScroll, { passive: !0, capture: !0 }), this._globalListenersBound = !0);
460
460
  }
461
461
  _unbindGlobalListeners() {
462
462
  this._globalListenersBound && (document.removeEventListener("keydown", this._onDocumentKeyDown), document.removeEventListener("scroll", this._onDocumentScroll, !0), this._globalListenersBound = !1);
@@ -486,11 +486,11 @@ class T extends _ {
486
486
  this._focusItem(e[e.length - 1] || null);
487
487
  }
488
488
  _moveFocus(e) {
489
- const t = this._queryItems();
490
- if (!t.length)
489
+ const i = this._queryItems();
490
+ if (!i.length)
491
491
  return;
492
- const i = document.activeElement, n = i ? t.findIndex((o) => o === i || o.contains(i)) : -1, a = n === -1 ? 0 : Math.max(0, Math.min(t.length - 1, n + e));
493
- this._focusItem(t[a] || null);
492
+ const t = document.activeElement, r = t ? i.findIndex((o) => o === t || o.contains(t)) : -1, a = r === -1 ? 0 : Math.max(0, Math.min(i.length - 1, r + e));
493
+ this._focusItem(i[a] || null);
494
494
  }
495
495
  _resetTypeahead() {
496
496
  this._typeaheadBuffer = "", this._typeaheadTimer != null && (window.clearTimeout(this._typeaheadTimer), this._typeaheadTimer = null);
@@ -502,38 +502,38 @@ class T extends _ {
502
502
  if (!this.typeahead || !this._isTypeaheadKey(e))
503
503
  return !1;
504
504
  this._typeaheadBuffer = `${this._typeaheadBuffer}${e.key.toLowerCase()}`.slice(0, 24), this._typeaheadTimer != null && window.clearTimeout(this._typeaheadTimer), this._typeaheadTimer = window.setTimeout(() => this._resetTypeahead(), 420);
505
- const t = document.activeElement, i = this._queryItems();
506
- if (!i.length)
505
+ const i = document.activeElement, t = this._queryItems();
506
+ if (!t.length)
507
507
  return !1;
508
- const n = t ? i.findIndex((s) => s === t || s.contains(t)) : -1, o = (n >= 0 ? [...i.slice(n + 1), ...i.slice(0, n + 1)] : i).find((s) => (s.textContent || "").trim().toLowerCase().startsWith(this._typeaheadBuffer));
508
+ const r = i ? t.findIndex((s) => s === i || s.contains(i)) : -1, o = (r >= 0 ? [...t.slice(r + 1), ...t.slice(0, r + 1)] : t).find((s) => (s.textContent || "").trim().toLowerCase().startsWith(this._typeaheadBuffer));
509
509
  return o ? (e.preventDefault(), this._focusItem(o), !0) : !1;
510
510
  }
511
511
  _applySelectionBehavior(e) {
512
- const t = e.getAttribute("role");
513
- if (t === "menuitemcheckbox") {
514
- const n = e.getAttribute("aria-checked") === "true";
515
- e.setAttribute("aria-checked", n ? "false" : "true"), e.setAttribute("data-state", n ? "unchecked" : "checked");
512
+ const i = e.getAttribute("role");
513
+ if (i === "menuitemcheckbox") {
514
+ const r = e.getAttribute("aria-checked") === "true";
515
+ e.setAttribute("aria-checked", r ? "false" : "true"), e.setAttribute("data-state", r ? "unchecked" : "checked");
516
516
  return;
517
517
  }
518
- if (t !== "menuitemradio" || !this._portalEl)
518
+ if (i !== "menuitemradio" || !this._portalEl)
519
519
  return;
520
- const i = e.getAttribute("data-group") || e.getAttribute("name") || "";
521
- this._portalEl.querySelectorAll('[role="menuitemradio"]').forEach((n) => {
522
- const a = n.getAttribute("data-group") || n.getAttribute("name") || "";
523
- i && a !== i || (n.setAttribute("aria-checked", n === e ? "true" : "false"), n.setAttribute("data-state", n === e ? "checked" : "unchecked"));
520
+ const t = e.getAttribute("data-group") || e.getAttribute("name") || "";
521
+ this._portalEl.querySelectorAll('[role="menuitemradio"]').forEach((r) => {
522
+ const a = r.getAttribute("data-group") || r.getAttribute("name") || "";
523
+ t && a !== t || (r.setAttribute("aria-checked", r === e ? "true" : "false"), r.setAttribute("data-state", r === e ? "checked" : "unchecked"));
524
524
  });
525
525
  }
526
526
  _handleItemSelect(e) {
527
- var n;
527
+ var r;
528
528
  this._applySelectionBehavior(e);
529
- const t = e.getAttribute("data-index"), i = t != null && !Number.isNaN(Number(t)) ? Number(t) : void 0;
529
+ const i = e.getAttribute("data-index"), t = i != null && !Number.isNaN(Number(i)) ? Number(i) : void 0;
530
530
  this.dispatchEvent(
531
531
  new CustomEvent("select", {
532
532
  bubbles: !0,
533
533
  detail: {
534
- index: i,
534
+ index: t,
535
535
  value: e.getAttribute("data-value") || e.getAttribute("value") || void 0,
536
- label: e.getAttribute("aria-label") || ((n = e.textContent) == null ? void 0 : n.trim()) || void 0,
536
+ label: e.getAttribute("aria-label") || ((r = e.textContent) == null ? void 0 : r.trim()) || void 0,
537
537
  checked: e.getAttribute("aria-checked") === "true",
538
538
  item: e
539
539
  }
@@ -541,28 +541,28 @@ class T extends _ {
541
541
  ), this.closeOnSelect ? this.close() : this._focusItem(e);
542
542
  }
543
543
  _buildLegacyItems(e) {
544
- const t = this._getItemSources();
545
- return t.forEach((i, n) => {
546
- const a = i.cloneNode(!0);
547
- a.removeAttribute("slot"), a.getAttribute("role") || a.setAttribute("role", "menuitem"), a.classList.contains("item") || a.classList.add("item"), a.hasAttribute("tabindex") || a.setAttribute("tabindex", "-1"), a.hasAttribute("data-index") || a.setAttribute("data-index", String(n)), e.appendChild(a);
548
- }), t.length;
544
+ const i = this._getItemSources();
545
+ return i.forEach((t, r) => {
546
+ const a = t.cloneNode(!0);
547
+ a.removeAttribute("slot"), a.getAttribute("role") || a.setAttribute("role", "menuitem"), a.classList.contains("item") || a.classList.add("item"), a.hasAttribute("tabindex") || a.setAttribute("tabindex", "-1"), a.hasAttribute("data-index") || a.setAttribute("data-index", String(r)), e.appendChild(a);
548
+ }), i.length;
549
549
  }
550
550
  _hydrateMenuItems(e) {
551
- const t = Array.from(e.querySelectorAll(u()));
552
- return t.forEach((i, n) => {
553
- i.getAttribute("role") || i.setAttribute("role", "menuitem"), i.hasAttribute("tabindex") || i.setAttribute("tabindex", "-1"), i.classList.contains("item") || i.classList.add("item"), i.hasAttribute("data-index") || i.setAttribute("data-index", String(n));
554
- }), t.length;
551
+ const i = Array.from(e.querySelectorAll(u()));
552
+ return i.forEach((t, r) => {
553
+ t.getAttribute("role") || t.setAttribute("role", "menuitem"), t.hasAttribute("tabindex") || t.setAttribute("tabindex", "-1"), t.classList.contains("item") || t.classList.add("item"), t.hasAttribute("data-index") || t.setAttribute("data-index", String(r));
554
+ }), i.length;
555
555
  }
556
556
  _applyPortalTokens(e) {
557
- const t = window.getComputedStyle(this);
558
- S.forEach((i) => {
559
- const n = t.getPropertyValue(i).trim();
560
- n ? e.style.setProperty(i, n) : e.style.removeProperty(i);
557
+ const i = window.getComputedStyle(this);
558
+ S.forEach((t) => {
559
+ const r = i.getPropertyValue(t).trim();
560
+ r ? e.style.setProperty(t, r) : e.style.removeProperty(t);
561
561
  });
562
562
  }
563
563
  _applyPortalVariantData(e) {
564
- const t = l(this, "variant"), i = E(this.getAttribute("size") || this.getAttribute("density")), n = l(this, "density"), a = this.getAttribute("radius"), o = l(this, "shape"), s = l(this, "elevation"), c = l(this, "tone"), f = t === "default" || t === "" ? "" : t === "line" ? "outline" : t === "glass" ? "soft" : t;
565
- f ? e.setAttribute("data-variant", f) : e.removeAttribute("data-variant"), i !== "md" ? e.setAttribute("data-size", i) : e.removeAttribute("data-size"), n && n !== "default" ? e.setAttribute("data-density", n) : e.removeAttribute("data-density"), s && s !== "default" ? e.setAttribute("data-elevation", s) : e.removeAttribute("data-elevation");
564
+ const i = l(this, "variant"), t = E(this.getAttribute("size") || this.getAttribute("density")), r = l(this, "density"), a = this.getAttribute("radius"), o = l(this, "shape"), s = l(this, "elevation"), c = l(this, "tone"), f = i === "default" || i === "" ? "" : i === "line" ? "outline" : i === "glass" ? "soft" : i;
565
+ f ? e.setAttribute("data-variant", f) : e.removeAttribute("data-variant"), t !== "md" ? e.setAttribute("data-size", t) : e.removeAttribute("data-size"), r && r !== "default" ? e.setAttribute("data-density", r) : e.removeAttribute("data-density"), s && s !== "default" ? e.setAttribute("data-elevation", s) : e.removeAttribute("data-elevation");
566
566
  const b = c === "default" || c === "brand" || c === "" ? "" : c;
567
567
  b ? e.setAttribute("data-tone", b) : e.removeAttribute("data-tone");
568
568
  const d = k(a || o || null);
@@ -572,30 +572,30 @@ class T extends _ {
572
572
  this._portalEl && (this._applyPortalTokens(this._portalEl), this._applyPortalVariantData(this._portalEl), this._portalEl.setAttribute("aria-hidden", "false"), this._portalEl.setAttribute("aria-busy", "false"), this._portalEl.style.display = "block", this._portalEl.style.visibility = "visible", this._portalEl.style.opacity = "1", this._portalEl.style.transform = "translateY(0px) scale(1)", this._portalEl.style.pointerEvents = "auto");
573
573
  }
574
574
  _attachMenuEvents(e) {
575
- this._menuClickHandler = (t) => {
576
- const i = p(t);
577
- !i || m(i) || this._handleItemSelect(i);
578
- }, e.addEventListener("click", this._menuClickHandler), e.addEventListener("mouseover", (t) => {
579
- const i = p(t);
580
- !i || m(i) || this._focusItem(i);
581
- }), e.addEventListener("focusin", (t) => {
582
- const i = p(t);
583
- !i || m(i) || this._focusItem(i);
575
+ this._menuClickHandler = (i) => {
576
+ const t = p(i);
577
+ !t || m(t) || this._handleItemSelect(t);
578
+ }, e.addEventListener("click", this._menuClickHandler), e.addEventListener("mouseover", (i) => {
579
+ const t = p(i);
580
+ !t || m(t) || this._focusItem(t);
581
+ }), e.addEventListener("focusin", (i) => {
582
+ const t = p(i);
583
+ !t || m(t) || this._focusItem(t);
584
584
  }), e.addEventListener("mouseleave", () => this._clearActiveState());
585
585
  }
586
586
  _buildPortalElement() {
587
587
  const e = document.createElement("div");
588
588
  e.className = "surface menu", e.id = this._menuId, e.setAttribute("part", "menu"), e.setAttribute("role", "menu"), e.setAttribute("tabindex", "-1"), e.setAttribute("aria-hidden", "false"), e.setAttribute("aria-busy", "false"), e.setAttribute("data-placement", g(this.getAttribute("placement")));
589
- const t = document.createElement("style");
590
- t.textContent = I, e.appendChild(t);
591
- const i = this._getContentSource();
592
- let n = 0;
593
- if (i) {
594
- const a = i.cloneNode(!0);
589
+ const i = document.createElement("style");
590
+ i.textContent = C, e.appendChild(i);
591
+ const t = this._getContentSource();
592
+ let r = 0;
593
+ if (t) {
594
+ const a = t.cloneNode(!0);
595
595
  a.removeAttribute("slot"), e.appendChild(a);
596
596
  } else
597
- n = this._buildLegacyItems(e);
598
- if (n = this._hydrateMenuItems(e) || n, n === 0) {
597
+ r = this._buildLegacyItems(e);
598
+ if (r = this._hydrateMenuItems(e) || r, r === 0) {
599
599
  const a = document.createElement("div");
600
600
  a.className = "empty-state", a.textContent = "No items", e.appendChild(a);
601
601
  }
@@ -607,13 +607,13 @@ class T extends _ {
607
607
  const e = this._portalEl.parentElement;
608
608
  if (!e)
609
609
  return;
610
- const t = this._portalEl, i = this._buildPortalElement();
611
- e.replaceChild(i, t), this._portalEl = i, this._rebuildPositioner();
610
+ const i = this._portalEl, t = this._buildPortalElement();
611
+ e.replaceChild(t, i), this._portalEl = t, this._rebuildPositioner();
612
612
  }
613
613
  _rebuildPositioner() {
614
- var t;
614
+ var i;
615
615
  const e = this._getTrigger();
616
- !this._portalEl || !e || ((t = this._positioner) == null || t.destroy(), this._positioner = x({
616
+ !this._portalEl || !e || ((i = this._positioner) == null || i.destroy(), this._positioner = x({
617
617
  anchor: e,
618
618
  floating: this._portalEl,
619
619
  placement: g(this.getAttribute("placement")),
@@ -625,21 +625,21 @@ class T extends _ {
625
625
  }));
626
626
  }
627
627
  _mountPortal() {
628
- var t;
628
+ var i;
629
629
  const e = this._getTrigger();
630
630
  if (e) {
631
631
  if (this._portalEl)
632
632
  this._syncPortalVisualState();
633
633
  else {
634
634
  this._portalEl = this._buildPortalElement();
635
- const i = v();
636
- if (!i) {
635
+ const t = v();
636
+ if (!t) {
637
637
  this._portalEl = null;
638
638
  return;
639
639
  }
640
- i.appendChild(this._portalEl);
640
+ t.appendChild(this._portalEl);
641
641
  }
642
- this._rebuildPositioner(), (t = this._dismissableLayer) == null || t.destroy(), this._dismissableLayer = y({
642
+ this._rebuildPositioner(), (i = this._dismissableLayer) == null || i.destroy(), this._dismissableLayer = y({
643
643
  node: this._portalEl,
644
644
  trigger: e,
645
645
  closeOnEscape: !0,
@@ -649,8 +649,8 @@ class T extends _ {
649
649
  }
650
650
  }
651
651
  _teardownPortal() {
652
- var e, t, i;
653
- if ((e = this._dismissableLayer) == null || e.destroy(), this._dismissableLayer = null, (t = this._positioner) == null || t.destroy(), this._positioner = null, (i = this._portalEl) != null && i.parentElement)
652
+ var e, i, t;
653
+ if ((e = this._dismissableLayer) == null || e.destroy(), this._dismissableLayer = null, (i = this._positioner) == null || i.destroy(), this._positioner = null, (t = this._portalEl) != null && t.parentElement)
654
654
  try {
655
655
  this._portalEl.parentElement.removeChild(this._portalEl);
656
656
  } catch {
@@ -658,23 +658,31 @@ class T extends _ {
658
658
  this._portalEl = null, this._menuClickHandler = null, this._resetTypeahead();
659
659
  }
660
660
  _isEventInsideTrigger(e) {
661
- const t = this._getTrigger();
662
- return !!t && e.composedPath().includes(t);
661
+ const i = this._getTrigger();
662
+ return !!i && e.composedPath().includes(i);
663
663
  }
664
664
  _isEventInsideMenu(e) {
665
665
  return !!this._portalEl && e.composedPath().includes(this._portalEl);
666
666
  }
667
+ _isInternalScrollEvent(e) {
668
+ var a;
669
+ const i = typeof e.composedPath == "function" ? e.composedPath() : [];
670
+ if (this._portalEl && i.includes(this._portalEl))
671
+ return !0;
672
+ const t = this._getTrigger();
673
+ if (t && i.includes(t))
674
+ return !0;
675
+ const r = e.target;
676
+ return !!(r instanceof Node && ((a = this._portalEl) != null && a.contains(r) || t != null && t.contains(r)));
677
+ }
667
678
  _onHostClick(e) {
668
679
  this.hasAttribute("disabled") || this._isEventInsideTrigger(e) && (e.preventDefault(), this.toggle());
669
680
  }
670
681
  _onDocumentScroll(e) {
671
- if (!this._isOpen || !this.closeOnScroll)
672
- return;
673
- const t = typeof e.composedPath == "function" ? e.composedPath() : [];
674
- this._portalEl && t.includes(this._portalEl) || this.close();
682
+ !this._isOpen || !this.closeOnScroll || this._isInternalScrollEvent(e) || this.close();
675
683
  }
676
684
  _onDocumentKeyDown(e) {
677
- var t;
685
+ var i;
678
686
  if (!this._isOpen) {
679
687
  if (e.key !== "ArrowDown" && e.key !== "ArrowUp" || !this._isEventInsideTrigger(e))
680
688
  return;
@@ -709,20 +717,20 @@ class T extends _ {
709
717
  return;
710
718
  }
711
719
  if (e.key === "Enter" || e.key === " ") {
712
- const i = document.activeElement;
713
- if (!i || !((t = this._portalEl) != null && t.contains(i)))
720
+ const t = document.activeElement;
721
+ if (!t || !((i = this._portalEl) != null && i.contains(t)))
714
722
  return;
715
- const n = i.closest(u());
716
- if (!n || m(n))
723
+ const r = t.closest(u());
724
+ if (!r || m(r))
717
725
  return;
718
- e.preventDefault(), this._handleItemSelect(n);
726
+ e.preventDefault(), this._handleItemSelect(r);
719
727
  }
720
728
  }
721
729
  }
722
730
  render() {
723
731
  var e;
724
732
  this.setContent(`
725
- <style>${C}</style>
733
+ <style>${I}</style>
726
734
  <div class="trigger" part="trigger">
727
735
  <slot name="trigger"></slot>
728
736
  </div>