@jimka/typescript-ui 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/dist/lib/{AbstractBooleanInput-C3O4kv7_.js → AbstractBooleanInput-DSwKBAic.js} +2 -2
  2. package/dist/lib/{AbstractBooleanInput-C3O4kv7_.js.map → AbstractBooleanInput-DSwKBAic.js.map} +1 -1
  3. package/dist/lib/{AbstractInput-DFWniHqq.js → AbstractInput-BmWGJTs1.js} +2 -2
  4. package/dist/lib/{AbstractInput-DFWniHqq.js.map → AbstractInput-BmWGJTs1.js.map} +1 -1
  5. package/dist/lib/{AnchorConstraints-CSUcj8Wx.js → AnchorConstraints-CVrMP9rz.js} +2 -2
  6. package/dist/lib/{AnchorConstraints-CSUcj8Wx.js.map → AnchorConstraints-CVrMP9rz.js.map} +1 -1
  7. package/dist/lib/{AnimatedDropdown-e9urCXK1.js → AnimatedDropdown-DKas40B-.js} +2 -2
  8. package/dist/lib/{AnimatedDropdown-e9urCXK1.js.map → AnimatedDropdown-DKas40B-.js.map} +1 -1
  9. package/dist/lib/Border-Bz29z-_7.js +2 -0
  10. package/dist/lib/Border-Bz29z-_7.js.map +1 -0
  11. package/dist/lib/Button-bjpWruNc.js +2 -0
  12. package/dist/lib/{Button-B36rBMKC.js.map → Button-bjpWruNc.js.map} +1 -1
  13. package/dist/lib/{Card-P8iUH2-C.js → Card-BdfbvOD_.js} +2 -2
  14. package/dist/lib/{Card-P8iUH2-C.js.map → Card-BdfbvOD_.js.map} +1 -1
  15. package/dist/lib/ComboBox-CBw2VLLN.js +2 -0
  16. package/dist/lib/ComboBox-CBw2VLLN.js.map +1 -0
  17. package/dist/lib/Component-DHqrPwAw.js +2 -0
  18. package/dist/lib/Component-DHqrPwAw.js.map +1 -0
  19. package/dist/lib/Container-CAQpj4yb.js +2 -0
  20. package/dist/lib/{Container-xUbHk6l_.js.map → Container-CAQpj4yb.js.map} +1 -1
  21. package/dist/lib/{DOM-BeR95tE8.js → DOM-67StIm5G.js} +2 -2
  22. package/dist/lib/DOM-67StIm5G.js.map +1 -0
  23. package/dist/lib/DragChain-CYGuT7OA.js +2 -0
  24. package/dist/lib/DragChain-CYGuT7OA.js.map +1 -0
  25. package/dist/lib/DragManager-CHWCe3-8.js +2 -0
  26. package/dist/lib/DragManager-CHWCe3-8.js.map +1 -0
  27. package/dist/lib/{FieldDecorator-BaTGfKiW.js → FieldDecorator-CgAGcqCk.js} +2 -2
  28. package/dist/lib/{FieldDecorator-BaTGfKiW.js.map → FieldDecorator-CgAGcqCk.js.map} +1 -1
  29. package/dist/lib/{Fit-E-EIZv1k.js → Fit-DIYt2aQB.js} +2 -2
  30. package/dist/lib/{Fit-E-EIZv1k.js.map → Fit-DIYt2aQB.js.map} +1 -1
  31. package/dist/lib/Glyph-CeAIWyPB.js +2 -0
  32. package/dist/lib/Glyph-CeAIWyPB.js.map +1 -0
  33. package/dist/lib/{Grid-BXS2T8MT.js → Grid-ViA0joow.js} +2 -2
  34. package/dist/lib/{Grid-BXS2T8MT.js.map → Grid-ViA0joow.js.map} +1 -1
  35. package/dist/lib/GridConstraints-B1rxCw9B.js +2 -0
  36. package/dist/lib/GridConstraints-B1rxCw9B.js.map +1 -0
  37. package/dist/lib/Header-mKaqgfat.js +2 -0
  38. package/dist/lib/Header-mKaqgfat.js.map +1 -0
  39. package/dist/lib/IconText-BqwXA82-.js +2 -0
  40. package/dist/lib/IconText-BqwXA82-.js.map +1 -0
  41. package/dist/lib/{LayoutSerialization-D1OHmxSB.js → LayoutSerialization-D82UtnDD.js} +2 -2
  42. package/dist/lib/{LayoutSerialization-D1OHmxSB.js.map → LayoutSerialization-D82UtnDD.js.map} +1 -1
  43. package/dist/lib/LayoutSizes-DG9aW9k6.js +2 -0
  44. package/dist/lib/LayoutSizes-DG9aW9k6.js.map +1 -0
  45. package/dist/lib/List-CUntS8ux.js +2 -0
  46. package/dist/lib/List-CUntS8ux.js.map +1 -0
  47. package/dist/lib/MemoryStore-DT6iWWco.js.map +1 -1
  48. package/dist/lib/Menu-B_-SQj72.js +2 -0
  49. package/dist/lib/Menu-B_-SQj72.js.map +1 -0
  50. package/dist/lib/{MenuButton-Bjm1OyB-.js → MenuButton-C79l8Ysf.js} +2 -2
  51. package/dist/lib/{MenuButton-Bjm1OyB-.js.map → MenuButton-C79l8Ysf.js.map} +1 -1
  52. package/dist/lib/{Panel-D9lTLGqP.js → Panel-D2X33qR6.js} +2 -2
  53. package/dist/lib/{Panel-D9lTLGqP.js.map → Panel-D2X33qR6.js.map} +1 -1
  54. package/dist/lib/Position-Ck_KD4cR.js +2 -0
  55. package/dist/lib/Position-Ck_KD4cR.js.map +1 -0
  56. package/dist/lib/{ProgressSpinner-glv-29eK.js → ProgressSpinner-DCyq02pd.js} +2 -2
  57. package/dist/lib/{ProgressSpinner-glv-29eK.js.map → ProgressSpinner-DCyq02pd.js.map} +1 -1
  58. package/dist/lib/{RadioButton-R4S3c9WD.js → RadioButton-BJIAQkII.js} +2 -2
  59. package/dist/lib/{RadioButton-R4S3c9WD.js.map → RadioButton-BJIAQkII.js.map} +1 -1
  60. package/dist/lib/{RovingTabIndex-Dgt01LOE.js → RovingTabIndex-DFJyoveq.js} +2 -2
  61. package/dist/lib/{RovingTabIndex-Dgt01LOE.js.map → RovingTabIndex-DFJyoveq.js.map} +1 -1
  62. package/dist/lib/Scrollbar-CSFK-Y57.js +2 -0
  63. package/dist/lib/Scrollbar-CSFK-Y57.js.map +1 -0
  64. package/dist/lib/Slider-C-kQQYCj.js +2 -0
  65. package/dist/lib/Slider-C-kQQYCj.js.map +1 -0
  66. package/dist/lib/{Spacer-B57i2-_G.js → Spacer-D159iJy9.js} +2 -2
  67. package/dist/lib/{Spacer-B57i2-_G.js.map → Spacer-D159iJy9.js.map} +1 -1
  68. package/dist/lib/TabButton-CHkXBgCj.js +2 -0
  69. package/dist/lib/TabButton-CHkXBgCj.js.map +1 -0
  70. package/dist/lib/{Text-Bni4icFY.js → Text-D5pg7taZ.js} +2 -2
  71. package/dist/lib/{Text-Bni4icFY.js.map → Text-D5pg7taZ.js.map} +1 -1
  72. package/dist/lib/Tooltip-DzK6LxUt.js +3 -0
  73. package/dist/lib/{Tooltip-BUy6uFKN.js.map → Tooltip-DzK6LxUt.js.map} +1 -1
  74. package/dist/lib/VBox-BNegDPs_.js +2 -0
  75. package/dist/lib/VBox-BNegDPs_.js.map +1 -0
  76. package/dist/lib/VirtualScroller-zQr-vKrO.js +2 -0
  77. package/dist/lib/VirtualScroller-zQr-vKrO.js.map +1 -0
  78. package/dist/lib/component/button.es.js +1 -1
  79. package/dist/lib/component/chart.es.js +1 -1
  80. package/dist/lib/component/chart.es.js.map +1 -1
  81. package/dist/lib/component/container.es.js +1 -1
  82. package/dist/lib/component/container.es.js.map +1 -1
  83. package/dist/lib/component/diagram.es.js +1 -1
  84. package/dist/lib/component/diagram.es.js.map +1 -1
  85. package/dist/lib/component/display.es.js +1 -1
  86. package/dist/lib/component/display.es.js.map +1 -1
  87. package/dist/lib/component/editor.es.js +2 -2
  88. package/dist/lib/component/editor.es.js.map +1 -1
  89. package/dist/lib/component/input.es.js +1 -1
  90. package/dist/lib/component/input.es.js.map +1 -1
  91. package/dist/lib/component/list.es.js +1 -1
  92. package/dist/lib/component/list.es.js.map +1 -1
  93. package/dist/lib/component/menubar.es.js +1 -1
  94. package/dist/lib/component/menubar.es.js.map +1 -1
  95. package/dist/lib/component/table.es.js +2 -2
  96. package/dist/lib/component/table.es.js.map +1 -1
  97. package/dist/lib/component/tree.es.js +1 -1
  98. package/dist/lib/component/tree.es.js.map +1 -1
  99. package/dist/lib/core.es.js +1 -1
  100. package/dist/lib/core.es.js.map +1 -1
  101. package/dist/lib/layout.es.js +1 -1
  102. package/dist/lib/layout.es.js.map +1 -1
  103. package/dist/lib/overlay.es.js +1 -1
  104. package/dist/lib/overlay.es.js.map +1 -1
  105. package/dist/lib/primitive.es.js +1 -1
  106. package/dist/lib/router.es.js +1 -1
  107. package/dist/lib/selectionsEqual-4r5R7pTK.js +2 -0
  108. package/dist/lib/selectionsEqual-4r5R7pTK.js.map +1 -0
  109. package/dist/lib/types/component/button/TabCloseButton.d.ts +1 -1
  110. package/dist/lib/types/component/container/CollapseButton.d.ts +1 -1
  111. package/dist/lib/types/component/container/DialogBackdrop.d.ts +1 -1
  112. package/dist/lib/types/component/container/MenuItem.d.ts +4 -0
  113. package/dist/lib/types/component/container/MenuSeparator.d.ts +1 -1
  114. package/dist/lib/types/component/container/Scrollbar.d.ts +1 -0
  115. package/dist/lib/types/component/container/SplitGutter.d.ts +2 -2
  116. package/dist/lib/types/component/container/StatusBar.d.ts +1 -1
  117. package/dist/lib/types/component/container/VirtualScroller.d.ts +1 -0
  118. package/dist/lib/types/component/container/WindowBorder.d.ts +1 -1
  119. package/dist/lib/types/component/diagram/DiagramNode.d.ts +1 -1
  120. package/dist/lib/types/component/display/Canvas.d.ts +8 -2
  121. package/dist/lib/types/component/display/Glyph.d.ts +2 -1
  122. package/dist/lib/types/component/display/Header.d.ts +1 -1
  123. package/dist/lib/types/component/display/IconLabel.d.ts +1 -1
  124. package/dist/lib/types/component/display/IconText.d.ts +1 -1
  125. package/dist/lib/types/component/display/Image.d.ts +1 -1
  126. package/dist/lib/types/component/display/Video.d.ts +1 -1
  127. package/dist/lib/types/component/display/WebGLCanvas.d.ts +8 -2
  128. package/dist/lib/types/component/editor/CodeEditor.d.ts +1 -1
  129. package/dist/lib/types/component/input/AbstractPickerField.d.ts +1 -1
  130. package/dist/lib/types/component/input/AutoCompleteDropdown.d.ts +1 -1
  131. package/dist/lib/types/component/input/Link.d.ts +1 -1
  132. package/dist/lib/types/component/input/NumberSpinner.d.ts +1 -1
  133. package/dist/lib/types/component/input/PasswordField.d.ts +1 -1
  134. package/dist/lib/types/component/input/SpinButton.d.ts +1 -1
  135. package/dist/lib/types/component/input/TextArea.d.ts +1 -1
  136. package/dist/lib/types/component/input/TextField.d.ts +3 -1
  137. package/dist/lib/types/component/input/UsernameField.d.ts +1 -1
  138. package/dist/lib/types/component/list/AbstractMarkerList.d.ts +9 -1
  139. package/dist/lib/types/component/list/BulletedList.d.ts +1 -0
  140. package/dist/lib/types/component/list/ListItem.d.ts +10 -4
  141. package/dist/lib/types/component/list/NumberedList.d.ts +1 -0
  142. package/dist/lib/types/component/menubar/MenuBarButton.d.ts +1 -1
  143. package/dist/lib/types/component/menubar/ToolBar.d.ts +1 -1
  144. package/dist/lib/types/component/menubar/ToolBarSeparator.d.ts +1 -1
  145. package/dist/lib/types/component/shared/VirtualRowView.d.ts +13 -1
  146. package/dist/lib/types/component/table/Body.d.ts +15 -2
  147. package/dist/lib/types/component/table/CellGeometry.d.ts +6 -0
  148. package/dist/lib/types/component/table/Column.d.ts +4 -0
  149. package/dist/lib/types/component/table/ColumnConfig.d.ts +3 -0
  150. package/dist/lib/types/component/table/Header.d.ts +24 -2
  151. package/dist/lib/types/component/table/Row.d.ts +13 -2
  152. package/dist/lib/types/component/table/Table.d.ts +25 -4
  153. package/dist/lib/types/component/table/TableExporter.d.ts +1 -1
  154. package/dist/lib/types/component/table/TablePanel.d.ts +2 -1
  155. package/dist/lib/types/component/table/cell/Cell.d.ts +1 -1
  156. package/dist/lib/types/component/table/cell/Header.d.ts +3 -0
  157. package/dist/lib/types/component/table/index.d.ts +1 -1
  158. package/dist/lib/types/component/tree/Tree.d.ts +1 -0
  159. package/dist/lib/types/core/Aria.d.ts +1 -1
  160. package/dist/lib/types/core/Body.d.ts +8 -2
  161. package/dist/lib/types/core/Component.d.ts +6 -0
  162. package/dist/lib/types/core/DOM.d.ts +4 -0
  163. package/dist/lib/types/core/DragChain.d.ts +3 -0
  164. package/dist/lib/types/core/Favicon.d.ts +7 -0
  165. package/dist/lib/types/core/FirstLayoutGate.d.ts +5 -0
  166. package/dist/lib/types/core/Theme.d.ts +1 -0
  167. package/dist/lib/types/core/Util.d.ts +1 -0
  168. package/dist/lib/types/core/index.d.ts +2 -0
  169. package/dist/lib/types/layout/Accordion.d.ts +0 -1
  170. package/dist/lib/types/layout/FlowLayout.d.ts +4 -0
  171. package/dist/lib/types/layout/HFlow.d.ts +3 -0
  172. package/dist/lib/types/layout/VFlow.d.ts +1 -0
  173. package/dist/lib/types/overlay/AbstractWindow.d.ts +1 -1
  174. package/dist/lib/types/overlay/Dock.d.ts +1 -0
  175. package/dist/lib/types/overlay/DropZoneOverlay.d.ts +1 -0
  176. package/dist/lib/types/overlay/Popover.d.ts +1 -1
  177. package/dist/lib/validation.es.js +1 -1
  178. package/llms.txt +1 -0
  179. package/package.json +2 -2
  180. package/dist/lib/Border-Dq6dXkmS.js +0 -2
  181. package/dist/lib/Border-Dq6dXkmS.js.map +0 -1
  182. package/dist/lib/Button-B36rBMKC.js +0 -2
  183. package/dist/lib/ComboBox-BjAhXXkY.js +0 -2
  184. package/dist/lib/ComboBox-BjAhXXkY.js.map +0 -1
  185. package/dist/lib/Component-CHTzJxEf.js +0 -2
  186. package/dist/lib/Component-CHTzJxEf.js.map +0 -1
  187. package/dist/lib/Container-xUbHk6l_.js +0 -2
  188. package/dist/lib/DOM-BeR95tE8.js.map +0 -1
  189. package/dist/lib/DragManager-T5Oljd0F.js +0 -2
  190. package/dist/lib/DragManager-T5Oljd0F.js.map +0 -1
  191. package/dist/lib/Glyph-CnNslL95.js +0 -2
  192. package/dist/lib/Glyph-CnNslL95.js.map +0 -1
  193. package/dist/lib/GridConstraints-D_kbd-h2.js +0 -2
  194. package/dist/lib/GridConstraints-D_kbd-h2.js.map +0 -1
  195. package/dist/lib/HBox-Dm3xgsDE.js +0 -2
  196. package/dist/lib/HBox-Dm3xgsDE.js.map +0 -1
  197. package/dist/lib/Header-CqFc2OUx.js +0 -2
  198. package/dist/lib/Header-CqFc2OUx.js.map +0 -1
  199. package/dist/lib/IconText-CTM2r0Tv.js +0 -2
  200. package/dist/lib/IconText-CTM2r0Tv.js.map +0 -1
  201. package/dist/lib/LayoutSizes-CvMmMgHJ.js +0 -2
  202. package/dist/lib/LayoutSizes-CvMmMgHJ.js.map +0 -1
  203. package/dist/lib/List-DHeOPAK2.js +0 -2
  204. package/dist/lib/List-DHeOPAK2.js.map +0 -1
  205. package/dist/lib/Menu-B6ippw-p.js +0 -2
  206. package/dist/lib/Menu-B6ippw-p.js.map +0 -1
  207. package/dist/lib/Position-DRSlWn4Z.js +0 -2
  208. package/dist/lib/Position-DRSlWn4Z.js.map +0 -1
  209. package/dist/lib/Scrollbar-CiVV3axj.js +0 -2
  210. package/dist/lib/Scrollbar-CiVV3axj.js.map +0 -1
  211. package/dist/lib/Slider-_JVvuQ8M.js +0 -2
  212. package/dist/lib/Slider-_JVvuQ8M.js.map +0 -1
  213. package/dist/lib/TabButton-DEypdlZf.js +0 -2
  214. package/dist/lib/TabButton-DEypdlZf.js.map +0 -1
  215. package/dist/lib/Tooltip-BUy6uFKN.js +0 -3
  216. package/dist/lib/VBox-Dr7Ge9M6.js +0 -2
  217. package/dist/lib/VBox-Dr7Ge9M6.js.map +0 -1
  218. package/dist/lib/VirtualScroller-BPy6KmSX.js +0 -2
  219. package/dist/lib/VirtualScroller-BPy6KmSX.js.map +0 -1
  220. package/dist/lib/selectionsEqual-2PJrcimg.js +0 -2
  221. package/dist/lib/selectionsEqual-2PJrcimg.js.map +0 -1
@@ -0,0 +1,2 @@
1
+ import{t as e}from"./DOM-67StIm5G.js";import{l as t,n}from"./Position-Ck_KD4cR.js";import{S as r,h as i,t as a}from"./Component-DHqrPwAw.js";import{t as o}from"./Glyph-CeAIWyPB.js";import{a as s,i as c,n as l}from"./Tooltip-DzK6LxUt.js";import{n as u,r as d}from"./AnimatedDropdown-DKas40B-.js";import{t as f}from"./Text-D5pg7taZ.js";import{n as p}from"./VBox-BNegDPs_.js";var m=i(class MenuItem extends a{static HEIGHT=24;static SEPARATOR_HEIGHT=9;static TEXT_INSET=8;static ICON_ZONE=24;static CHEVRON_ZONE=16;static RIGHT_PAD=8;static TEXT_GAP=10;_config;_onActivate;_onOpenSubmenu;_cssVarPrefix;_iconText=null;_iconGlyph=null;_titleText=null;_shortcutText=null;_chevronText=null;_iconStart=null;_titleColumn=null;_submenuTimer=null;_onMouseOver;_onMouseOut;_onClick;constructor(e,t,n,i=`menu-bar`,a){if(super(),this._config=e,this._onActivate=t,this._onOpenSubmenu=n,this._cssVarPrefix=i,e.separator){this.setHeight(MenuItem.SEPARATOR_HEIGHT),this.setPreferredSize({width:0,height:MenuItem.SEPARATOR_HEIGHT}),this.setBackgroundColor(`transparent`),this.setElementCSSRule(`borderTop`,`1px solid var(--ts-ui-${i}-separator-color, rgb(220, 220, 220))`),this.setElementCSSRule(`margin`,`4px 0`),this.getAria().setRole(`separator`),this._onMouseOver=()=>{},this._onMouseOut=()=>{},this._onClick=()=>{},a&&this.applyOptions(a);return}let s=e.enabled!==!1;this.setHeight(MenuItem.HEIGHT),this.setPreferredSize({width:0,height:MenuItem.HEIGHT}),this.setBackgroundColor(`transparent`),this.setElementCSSRule(`fontSize`,`var(--ts-ui-button-font-size, var(--ts-ui-font-size))`),this.setCursor(s?`pointer`:`default`),this.getAria().setRole(`menuitem`),s||(this.setForegroundColor(`var(--ts-ui-${i}-item-disabled-color, rgb(170, 170, 170))`),this.getAria().setDisabled(!0)),e.glyph?(this._iconGlyph=new o(e.glyph),this._iconGlyph.setPointerEvents(`none`),this._iconGlyph.setPreferredSize({width:16,height:16}),e.glyphColor&&this._iconGlyph.setForegroundColor(e.glyphColor),this.addComponent(this._iconGlyph)):(this._iconText=new f(e.icon??``),this._iconText.setPointerEvents(`none`),this._iconText.setVisible(!!e.icon),this.addComponent(this._iconText)),this._titleText=new f(e.text??``),this._titleText.setPointerEvents(`none`),this._titleText.setWhiteSpace(`nowrap`),this._titleText.setOverflow(`hidden`),this._titleText.setTextOverflow(`ellipsis`),this.addComponent(this._titleText),e.shortcut&&(this._shortcutText=new f(e.shortcut),this._shortcutText.setPointerEvents(`none`),this._shortcutText.setTextAlign(`left`),this._shortcutText.setForegroundColor(`var(--ts-ui-${i}-item-shortcut-color, rgb(140, 140, 140))`),this.addComponent(this._shortcutText)),this.hasSubmenu()&&(this._chevronText=new f(`▶`),this._chevronText.setPointerEvents(`none`),this._chevronText.setTextAlign(`center`),this._chevronText.setForegroundColor(`var(--ts-ui-${i}-item-shortcut-color, rgb(140, 140, 140))`),this.addComponent(this._chevronText),this.getAria().setHasPopup(`menu`),this.getAria().setExpanded(!1)),this._onMouseOver=()=>{this.setFocused(!0),s&&this.hasSubmenu()?this._submenuTimer=setTimeout(()=>{this._submenuTimer=null,this._onOpenSubmenu(this)},150):this._onOpenSubmenu(this)},this._onMouseOut=()=>{this.setFocused(!1),this._submenuTimer!==null&&(clearTimeout(this._submenuTimer),this._submenuTimer=null)},this._onClick=()=>{s&&!this.hasSubmenu()&&this._onActivate()},r.addListener(this,`mouseover`,this._onMouseOver),r.addListener(this,`mouseout`,this._onMouseOut),r.addListener(this,`click`,this._onClick),a&&this.applyOptions(a),this.updateLabelHeights()}applyOptions(e){return super.applyOptions(e),e.text!==void 0&&this._titleText&&this._titleText.setText(e.text),e.enabled!==void 0&&(this.getAria().setDisabled(!e.enabled),this.setCursor(e.enabled?`pointer`:`default`)),e.focused!==void 0&&this.setFocused(e.focused),this}hasSubmenu(){return!!this._config.submenu}hasIcon(){return!!this._config.icon||!!this._config.glyph}titleTextWidth(){return Math.ceil(this._titleText?.getPreferredSize()?.width??0)}shortcutTextWidth(){return!this._config.shortcut||this._shortcutText===null?0:Math.ceil(this._shortcutText.getPreferredSize()?.width??0)}setColumns(e,t){this._iconStart=e,this._titleColumn=t,this.scheduleLayout()}getSubmenuConfig(){return this._config.submenu??null}setFocused(e){return this.setBackgroundColor(e?`var(--ts-ui-${this._cssVarPrefix}-item-hover-bg, rgba(30, 100, 200, 0.12))`:`transparent`),this}isSeparator(){return!!this._config.separator}isEnabled(){return this._config.enabled!==!1}activate(){this.isSeparator()||!this.isEnabled()||(this.hasSubmenu()?this._onOpenSubmenu(this):this._onActivate())}destructor(){this._submenuTimer!==null&&(clearTimeout(this._submenuTimer),this._submenuTimer=null),r.removeListener(this,`mouseover`,this._onMouseOver),r.removeListener(this,`mouseout`,this._onMouseOut),r.removeListener(this,`click`,this._onClick),super.destructor()}getBaseline(){return this._titleText===null?null:this.wrapInnerBaseline(this._titleText.getBaseline())}updateLabelHeights(){let e=this.getPerimeterSize(),t=Math.max(1,MenuItem.HEIGHT-e.top-e.bottom);this._iconText?.centerInHeight(t),this._titleText?.centerInHeight(t),this._shortcutText?.centerInHeight(t),this._chevronText?.centerInHeight(t)}setBorder(e){return super.setBorder(e),this.updateLabelHeights(),this}clearBorder(){return super.clearBorder(),this.updateLabelHeights(),this}doLayout(){if(super.doLayout(),this._config.separator)return this;let e=this.getContentBounds();if(!e)return this;let t=e.height,n=e.width,r=!!this._config.shortcut&&this._shortcutText!==null,i=this.hasSubmenu(),a=this._iconStart??(this.hasIcon()?MenuItem.ICON_ZONE:MenuItem.TEXT_INSET),o=this._titleColumn??this.titleTextWidth();if(this._iconGlyph){let n=this._iconGlyph.getPreferredSize()??{width:16,height:16},r=Math.max(0,Math.floor((t-n.height)/2));this._iconGlyph.setX(e.x+4),this._iconGlyph.setY(e.y+r),this._iconGlyph.setWidth(n.width),this._iconGlyph.setHeight(n.height)}else this._iconText&&(this._iconText.setX(e.x+4),this._iconText.setY(e.y),this._iconText.setWidth(20),this._iconText.setHeight(t));return this._titleText&&(this._titleText.setX(e.x+a),this._titleText.setY(e.y),this._titleText.setWidth(o),this._titleText.setHeight(t)),i&&this._chevronText&&(this._chevronText.setX(e.x+n-MenuItem.RIGHT_PAD-MenuItem.CHEVRON_ZONE),this._chevronText.setY(e.y),this._chevronText.setWidth(MenuItem.CHEVRON_ZONE),this._chevronText.setHeight(t)),r&&this._shortcutText&&(this._shortcutText.setX(e.x+a+o+MenuItem.TEXT_GAP),this._shortcutText.setY(e.y),this._shortcutText.setWidth(this.shortcutTextWidth()),this._shortcutText.setHeight(t)),this}}),h={},g=i(class MenuSeparator extends a{static HEIGHT=9;constructor(e=`menu-bar`,t,n){super(t,{...h,...n??{}}),this.setHeight(MenuSeparator.HEIGHT),this.setPreferredSize({width:0,height:MenuSeparator.HEIGHT}),this.setBackgroundColor(`transparent`),this.setElementCSSRule(`borderTop`,`1px solid var(--ts-ui-${e}-separator-color, rgb(220, 220, 220))`),this.setElementCSSRule(`margin`,`4px 0`),this.getAria().setRole(`separator`)}}),_=120,v=360,y=120,b=4;function pointRect(e,t){return{x:e,y:t,left:e,top:t,right:e,bottom:t,width:0,height:0}}function resolvePlacement(e,t,n){let r=c(e.top,e.bottom,t.height,n.height,b);return{x:l(e.left,e.right,t.width,n.width,b),y:r.start,available:r.available}}var x=i(class Menu extends a{_persistent;_itemsProvider;_onClose;_menuItems=[];_fadeShowAnimation=null;_fadeHideAnimation=null;_focusedIndex=-1;_openSubmenuPanel=null;_openSubmenuItem=null;_excludedEl=null;_menuWidth=null;_rebuildOnClose=null;_currentOpener=null;_scrollToBottomOnShow=!1;constructor(e,t){super(),this._persistent=e!==void 0,this._itemsProvider=typeof e==`function`?e:null,this._onClose=t??null;let n=new p;n.setComponentSpacing(0),n.setStretching(!0),this.setLayoutManager(n),this._persistent?(this.applyPersistentChrome(),this._itemsProvider===null&&this.buildPersistentItems(e)):this.applyRebuildChrome()}layOutColumns(){let e=this._menuItems.filter(e=>e instanceof m&&!e.isSeparator()),t=e.some(e=>e.hasIcon())?m.ICON_ZONE:m.TEXT_INSET,n=e.reduce((e,t)=>Math.max(e,t.titleTextWidth()),0),r=e.reduce((e,t)=>Math.max(e,t.shortcutTextWidth()),0),i=e.some(e=>e.hasSubmenu()),a=Math.max(r,i?m.CHEVRON_ZONE:0),o=a>0?m.TEXT_GAP+a:0,s=t+n+o+m.RIGHT_PAD,c=Math.min(v,Math.max(_,s)),l=Math.min(n,c-t-o-m.RIGHT_PAD);for(let n of e)n.setColumns(t,l);return c}show(n,r,i,a,o){this.assertRebuildMode(`show`);let s=e.source.getViewportSize();return this.showAnchored(pointRect(t.clamp(n,0,s.width),t.clamp(r,0,s.height)),i,a??null,o??null)}showAnchored(t,r,i,a){this._rebuildOnClose=i,this._excludedEl=a;for(let e of this._menuItems)e instanceof m&&e.dispose();this._menuItems=[],this.removeAllComponents(),this.pauseLayout();for(let e of r){let t=e.separator===!0?new g(`context-menu`):new m(e,()=>{e.action?.(),this.hide()},e=>{this.handleItemOpenSubmenu(e)},`context-menu`);this.addComponent(t),this._menuItems.push(t)}this.resumeLayout();let o=this.layOutColumns(),c=this._menuWidth??o;this.setWidth(c),this.setMaxSize({width:Number.MAX_VALUE,height:Number.MAX_VALUE});let l=this.getPreferredSize()?.height??0,u=this.getElement(!0),d=e.source.getViewportSize(),f=l>resolvePlacement(t,{width:c,height:l},d).available?e.source.getScrollBarWidth():0;this.setInsets(new n(4,f,4,0)),this.setWidth(c+f);let p=resolvePlacement(t,{width:this.getWidth(),height:l},d);return this.setX(p.x),this.setY(p.y),this.applyViewportHeightClamp(p.available,l),this.scheduleLayout(),s.mount(u),this.setVisible(!0),this.fadeIn(),s.register(this),this.setZIndex(s.getZIndex(this)),this._scrollToBottomOnShow&&(this.flushLayout(),this.setScrollTop(this.getMaxScrollTop())),this}toggleFor(e,t,n,r){return this.assertRebuildMode(`toggleFor`),this._currentOpener===e?(this.hide(),this):n.length===0?(r?.(),this):(this.showAnchored(t,n,r??null,e),this._currentOpener=e,this)}hide(){this.assertRebuildMode(`hide`),this.closeOpenSubmenu(),s.unregister(this),this.fadeOutAndDetach(),this._currentOpener=null;let e=this._rebuildOnClose;return this._rebuildOnClose=null,e?.(),this}getMenuWidth(){return this.getWidth()}setMenuWidth(e){return this.assertRebuildMode(`setMenuWidth`),this._menuWidth=e,this}setScrollToBottomOnShow(e){return this.assertRebuildMode(`setScrollToBottomOnShow`),this._scrollToBottomOnShow=e,this}open(t,n){this.assertPersistentMode(`open`),this._itemsProvider&&this.rebuildPersistentItems(this._itemsProvider()),this.setMaxSize({width:Number.MAX_VALUE,height:Number.MAX_VALUE});let r=this.getPreferredSize()?.height??this._menuItems.length*m.HEIGHT+8,i=this.getWidth(),a=this.getElement(!0);s.mount(a);let o=e.source.getViewportSize();if(n){let a=n.getElement(),s=a?e.source.getElementRect(a):{left:0,right:0,top:0,bottom:0},c=e.source.getElementRect(t),l=s.right;l+i>o.width&&(l=s.left-i);let u=this.placeVertically(c.top,c.top,r,o.height);this.setAutoCommitStyle(!1),this.setX(Math.max(0,l)),this.setY(Math.max(0,u)),this.setAutoCommitStyle(!0)}else{let n=e.source.getElementRect(t),a=n.left;a+i>o.width&&(a=o.width-i);let s=this.placeVertically(n.bottom,n.top,r,o.height);this.setAutoCommitStyle(!1),this.setX(Math.max(0,a)),this.setY(Math.max(0,s)),this.setAutoCommitStyle(!0)}let c=e.source.getId(t);return c&&this.getAria().setLabelledBy(c),this.setVisible(!0),this.doLayout(),this.fadeIn(),s.register(this),this.setZIndex(s.getZIndex(this)),this}close(){return this.assertPersistentMode(`close`),this.closeOpenSubmenu(),this.setFocusedIndex(-1),this.clearItemHighlights(),s.unregister(this),this.fadeOutAndDetach(),this}clearItemHighlights(){for(let e of this._menuItems)e instanceof m&&e.setFocused(!1)}fadeIn(){this._fadeShowAnimation?.cancel(),this._fadeShowAnimation=d(this,{durationMs:y})}fadeOutAndDetach(){this._fadeHideAnimation?.cancel(),this._fadeHideAnimation=u(this,{durationMs:y})}destructor(){this._fadeShowAnimation?.cancel(),this._fadeShowAnimation=null,this._fadeHideAnimation?.cancel(),this._fadeHideAnimation=null,super.destructor()}focusItem(e){return this.assertPersistentMode(`focusItem`),this.setFocusedIndex(e),this}focusNext(){this.assertPersistentMode(`focusNext`);let e=this._focusedIndex+1;for(;e<this._menuItems.length&&this.isItemSeparator(e);)e++;if(e>=this._menuItems.length)for(e=0;e<this._menuItems.length&&this.isItemSeparator(e);)e++;return this.setFocusedIndex(e),this}focusPrev(){this.assertPersistentMode(`focusPrev`);let e=this._focusedIndex-1;for(;e>=0&&this.isItemSeparator(e);)e--;if(e<0)for(e=this._menuItems.length-1;e>=0&&this.isItemSeparator(e);)e--;return this.setFocusedIndex(e),this}activateFocused(){if(this.assertPersistentMode(`activateFocused`),this._focusedIndex<0||this._focusedIndex>=this._menuItems.length)return;let e=this._menuItems[this._focusedIndex];e instanceof m&&!e.isSeparator()&&e.isEnabled()&&e.activate()}getFocusedIndex(){return this.assertPersistentMode(`getFocusedIndex`),this._focusedIndex}setExcludedElement(e){return this.assertPersistentMode(`setExcludedElement`),this._excludedEl=e,this}getExcludedElement(){return this._excludedEl}applyPersistentChrome(){this.setBackgroundColor(`var(--ts-ui-menu-bar-panel-bg, rgb(255, 255, 255))`),this.setInsets(new n(4,0,4,0)),this.setBorder({border:`1px solid var(--ts-ui-menu-bar-panel-border, rgb(200, 200, 200))`}),this.setBorderRadius(`var(--ts-ui-border-radius, 4px)`),this.setShadow(`var(--ts-ui-menu-bar-panel-shadow, 2px 4px 8px rgba(0, 0, 0, 0.15))`),this.getAria().setRole(`menu`),this.setContain(`layout`),this.enableVerticalScroll()}applyRebuildChrome(){this.setVisible(!1),this.setBackgroundColor(`var(--ts-ui-context-menu-bg, rgb(255, 255, 255))`),this.setInsets(new n(4,0,4,0)),this.setBorder({border:`1px solid var(--ts-ui-context-menu-border, rgb(200, 200, 200))`}),this.setBorderRadius(`var(--ts-ui-border-radius, 4px)`),this.setShadow(`var(--ts-ui-context-menu-shadow, 2px 4px 8px rgba(0, 0, 0, 0.15))`),this.setContain(`layout`),this.enableVerticalScroll()}enableVerticalScroll(){this.setOverflowX(`hidden`),this.setOverflowY(`auto`),this.getLayoutManager().setOverflowing(!1,!0)}applyViewportHeightClamp(e,t){this.setMaxSize({width:Number.MAX_VALUE,height:Math.max(0,e)}),this.setHeight(t)}placeVertically(e,t,n,r){let{start:i,available:a}=c(t,e,n,r,b);return this.applyViewportHeightClamp(a,n),i}rebuildPersistentItems(e){this.closeOpenSubmenu();for(let e of this._menuItems)e instanceof m&&e.dispose();this._menuItems=[],this._focusedIndex=-1,this.removeAllComponents(),this.buildPersistentItems(e)}buildPersistentItems(e){this.pauseLayout();for(let t of e){let e=new m(t,()=>{t.action?.(),this._onClose()},e=>{this.handleItemOpenSubmenu(e)});this.addComponent(e),this._menuItems.push(e)}this.resumeLayout(),this.setWidth(this.layOutColumns())}setFocusedIndex(e){if(this._focusedIndex>=0&&this._focusedIndex<this._menuItems.length){let e=this._menuItems[this._focusedIndex];e instanceof m&&e.setFocused(!1)}if(this._focusedIndex=e,e>=0&&e<this._menuItems.length){let t=this._menuItems[e];t instanceof m&&t.setFocused(!0)}}isItemSeparator(e){let t=this._menuItems[e];return t instanceof g||t instanceof m&&t.isSeparator()}closeOpenSubmenu(){this._openSubmenuPanel&&(this._openSubmenuPanel.close(),this._openSubmenuItem?.getAria().setExpanded(!1),this._openSubmenuPanel=null,this._openSubmenuItem=null)}dismissAll(){this._persistent?this._onClose():this.hide()}getLayerElement(){return this.getElement()??null}getDismissMode(){return`click-outside`}requestClose(){this.dismissAll()}getAnchorElement(){return this._excludedEl}getBand(){return s.Band.Dropdown}onZIndexChanged(e){this.setZIndex(e)}handleItemOpenSubmenu(e){if(!e.hasSubmenu()||!e.isEnabled()){this.closeOpenSubmenu();return}if(this._openSubmenuItem===e)return;this.closeOpenSubmenu();let t=new Menu(e.getSubmenuConfig().items,()=>{this.dismissAll()});this._openSubmenuPanel=t,this._openSubmenuItem=e,e.getAria().setExpanded(!0),t.setExcludedElement(this.getElement(!0)),t.open(e.getElement(!0),this)}assertRebuildMode(e){if(this._persistent)throw Error(`Menu.${e}() is only valid in rebuild mode (constructed without arguments).`)}assertPersistentMode(e){if(!this._persistent)throw Error(`Menu.${e}() is only valid in persistent mode (constructed with items and onClose).`)}});export{g as n,m as r,x as t};
2
+ //# sourceMappingURL=Menu-B_-SQj72.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Menu-B_-SQj72.js","names":[],"sources":["../../src/typescript/lib/component/container/MenuItem.ts","../../src/typescript/lib/component/container/MenuSeparator.ts","../../src/typescript/lib/overlay/Menu.ts"],"sourcesContent":["// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0\n\nimport { Component, ComponentOptions } from \"~/core/Component.js\";\nimport { Event } from \"~/core/Event.js\";\nimport { Text } from \"~/component/input/Text.js\";\nimport { Glyph } from \"~/component/display/Glyph.js\";\nimport { BorderOptions } from \"~/primitive/Border.js\";\nimport { callable } from \"~/core/Callable.js\";\n\n/**\n * Construction-time component-level options for {@link MenuItem}. Use this\n * for cosmetic/layout overrides on the item row; the menu data (text, action,\n * shortcut, submenu) still comes through {@link MenuItemConfig}.\n *\n * @category Components\n */\nexport interface MenuItemOptions extends ComponentOptions {\n text?: string;\n enabled?: boolean;\n focused?: boolean;\n}\n\n/**\n * Selects which CSS-variable family a `MenuItem` reads its colours from.\n *\n * `'menu-bar'` resolves to `--ts-ui-menu-bar-item-*` tokens; `'context-menu'`\n * resolves to `--ts-ui-context-menu-item-*` tokens. The [`Menu`](/api/overlay/classes/Menu) class chooses\n * the prefix based on its mode.\n */\nexport type MenuItemCSSVarPrefix = \"menu-bar\" | \"context-menu\";\n\n/**\n * Describes a leaf action item, submenu trigger, or separator row inside a [`Menu`](/api/overlay/classes/Menu).\n *\n * @remarks When `separator` is true all other fields are ignored; the item renders as\n * a thin horizontal rule. When `submenu` is set the item opens a child [`Menu`](/api/overlay/classes/Menu)\n * instead of calling `action`.\n *\n * @category Components\n */\nexport interface MenuItemConfig {\n /** Display label shown in the menu row. */\n text?: string;\n /** Called when the item is activated (click or Enter). Ignored when `submenu` is set. */\n action?: () => void;\n /** Defaults to `true`. Disabled items are dimmed and non-interactive. */\n enabled?: boolean;\n /** Keyboard shortcut hint displayed on the right (e.g. `\"Ctrl+S\"`). */\n shortcut?: string;\n /**\n * Icon displayed on the left (e.g. a Unicode character).\n *\n * @remarks Prefer `glyph` for crisp SVG output from the framework's glyph\n * registry; `icon` remains supported for callers that want to embed a raw\n * character.\n */\n icon?: string;\n /**\n * Registry glyph name displayed on the left of the item row. Takes\n * precedence over `icon` when both are provided.\n */\n glyph?: string;\n /**\n * Optional colour for the leading `glyph`, overriding the item's default\n * foreground (e.g. a severity tint). Any CSS colour string. Ignored when the\n * row has no `glyph`.\n */\n glyphColor?: string;\n /** When present this item opens a submenu rather than calling `action`. */\n submenu?: MenuConfig;\n /** When `true` the item renders as a separator; all other fields are ignored. */\n separator?: true;\n}\n\n/**\n * Describes one top-level entry in a [`MenuBar`](/api/component/menubar/classes/MenuBar).\n *\n * @category Components\n */\nexport interface MenuConfig {\n /** Label shown in the bar button (e.g. `\"File\"`). */\n label: string;\n /**\n * The items in the dropdown panel: either a fixed array, or a provider called\n * to produce them when the panel is built. A submenu panel is (re)built each\n * time it opens, so a provider on a submenu's `items` is re-invoked on every\n * open — letting the submenu reflect current state (e.g. an export chooser\n * whose labels track the active tab) without the parent menu rebuilding.\n */\n items: MenuItemConfig[] | (() => MenuItemConfig[]);\n /**\n * Optional registry glyph name displayed to the left of the bar button's\n * label (e.g. `\"file\"`, `\"eye\"`, `\"info-circle\"`). Omit for a text-only\n * menu button.\n */\n glyph?: string;\n}\n\n/**\n * A single row inside a [`Menu`](/api/overlay/classes/Menu) panel.\n *\n * Renders a four-zone layout: icon | text | shortcut | chevron. When\n * `config.separator` is true the item renders instead as a thin horizontal\n * rule and ignores all other config fields.\n *\n * Mouse hover triggers the submenu open callback after a 150 ms delay.\n * Keyboard focus is applied programmatically via `setFocused`.\n *\n * @category Components\n */\nclass MenuItem extends Component {\n\n /** Fixed pixel height for every non-separator menu item. */\n static readonly HEIGHT: number = 24;\n\n private static readonly SEPARATOR_HEIGHT: number = 9;\n /** Title left inset when the menu reserves no icon column. */\n static readonly TEXT_INSET: number = 8;\n /** Title left offset when the menu reserves an icon column. */\n static readonly ICON_ZONE: number = 24;\n /** Width reserved for a submenu chevron in the right zone. */\n static readonly CHEVRON_ZONE: number = 16;\n /** Padding after the right zone, at the panel's inner edge. */\n static readonly RIGHT_PAD: number = 8;\n /**\n * Gap between the title column and the shortcut/chevron right zone, so a\n * content-sized menu never butts the label against them.\n */\n static readonly TEXT_GAP: number = 10;\n\n private readonly _config: MenuItemConfig;\n private readonly _onActivate: () => void;\n private readonly _onOpenSubmenu: (item: MenuItem) => void;\n private readonly _cssVarPrefix: MenuItemCSSVarPrefix;\n\n private _iconText: Text | null = null;\n private _iconGlyph: Glyph | null = null;\n private _titleText: Text | null = null;\n private _shortcutText: Text | null = null;\n private _chevronText: Text | null = null;\n\n // Column geometry applied by the parent Menu so every item lines up: the\n // title's left offset and the shared title-column width the right zone begins\n // after. Null until the menu sets them (a standalone item falls back to its\n // own natural metrics).\n private _iconStart: number | null = null;\n private _titleColumn: number | null = null;\n\n private _submenuTimer: ReturnType<typeof setTimeout> | null = null;\n\n private readonly _onMouseOver: () => void;\n private readonly _onMouseOut: () => void;\n private readonly _onClick: () => void;\n\n /**\n * Constructs a MenuItem from a config descriptor.\n *\n * @param config - The item descriptor including text, action, shortcut, icon, and submenu.\n * @param onActivate - Called when this item is activated (click or Enter on a leaf item).\n * @param onOpenSubmenu - Called when this item's submenu should open (or close others when no submenu).\n * @param cssVarPrefix - Selects which CSS-variable family supplies disabled, hover, and shortcut colours. Defaults to `'menu-bar'`.\n */\n constructor(\n config: MenuItemConfig,\n onActivate: () => void,\n onOpenSubmenu: (item: MenuItem) => void,\n cssVarPrefix: MenuItemCSSVarPrefix = \"menu-bar\",\n options?: MenuItemOptions\n ) {\n // Child components are built first; options are applied via applyOptions at the constructor tail.\n // eslint-disable-next-line local/forward-super-options\n super();\n\n this._config = config;\n this._onActivate = onActivate;\n this._onOpenSubmenu = onOpenSubmenu;\n this._cssVarPrefix = cssVarPrefix;\n\n if (config.separator) {\n this.setHeight(MenuItem.SEPARATOR_HEIGHT);\n this.setPreferredSize({ width: 0, height: MenuItem.SEPARATOR_HEIGHT });\n this.setBackgroundColor(\"transparent\");\n this.setElementCSSRule(\n \"borderTop\",\n `1px solid var(--ts-ui-${cssVarPrefix}-separator-color, rgb(220, 220, 220))`\n );\n this.setElementCSSRule(\"margin\", \"4px 0\");\n this.getAria().setRole(\"separator\");\n\n this._onMouseOver = () => {};\n this._onMouseOut = () => {};\n this._onClick = () => {};\n\n if (options) {\n this.applyOptions(options);\n }\n\n return;\n }\n\n const enabled = config.enabled !== false;\n\n this.setHeight(MenuItem.HEIGHT);\n this.setPreferredSize({ width: 0, height: MenuItem.HEIGHT });\n this.setBackgroundColor(\"transparent\");\n this.setElementCSSRule(\"fontSize\", \"var(--ts-ui-button-font-size, var(--ts-ui-font-size))\");\n this.setCursor(enabled ? \"pointer\" : \"default\");\n this.getAria().setRole(\"menuitem\");\n\n if (!enabled) {\n this.setForegroundColor(\n `var(--ts-ui-${cssVarPrefix}-item-disabled-color, rgb(170, 170, 170))`\n );\n this.getAria().setDisabled(true);\n }\n\n if (config.glyph) {\n this._iconGlyph = new Glyph(config.glyph);\n this._iconGlyph.setPointerEvents(\"none\");\n this._iconGlyph.setPreferredSize({ width: 16, height: 16 });\n\n if (config.glyphColor) {\n this._iconGlyph.setForegroundColor(config.glyphColor);\n }\n\n this.addComponent(this._iconGlyph);\n } else {\n this._iconText = new Text(config.icon ?? \"\");\n this._iconText.setPointerEvents(\"none\");\n this._iconText.setVisible(!!config.icon);\n this.addComponent(this._iconText);\n }\n\n this._titleText = new Text(config.text ?? \"\");\n this._titleText.setPointerEvents(\"none\");\n this._titleText.setWhiteSpace(\"nowrap\");\n this._titleText.setOverflow(\"hidden\");\n this._titleText.setTextOverflow(\"ellipsis\");\n this.addComponent(this._titleText);\n\n if (config.shortcut) {\n this._shortcutText = new Text(config.shortcut);\n this._shortcutText.setPointerEvents(\"none\");\n this._shortcutText.setTextAlign(\"left\");\n this._shortcutText.setForegroundColor(\n `var(--ts-ui-${cssVarPrefix}-item-shortcut-color, rgb(140, 140, 140))`\n );\n this.addComponent(this._shortcutText);\n }\n\n if (this.hasSubmenu()) {\n this._chevronText = new Text(\"▶\");\n this._chevronText.setPointerEvents(\"none\");\n this._chevronText.setTextAlign(\"center\");\n this._chevronText.setForegroundColor(\n `var(--ts-ui-${cssVarPrefix}-item-shortcut-color, rgb(140, 140, 140))`\n );\n this.addComponent(this._chevronText);\n this.getAria().setHasPopup(\"menu\");\n this.getAria().setExpanded(false);\n }\n\n this._onMouseOver = () => {\n this.setFocused(true);\n\n // A disabled item never opens its own submenu; it still signals the\n // parent (the else branch) so hovering it closes any sibling submenu.\n if (enabled && this.hasSubmenu()) {\n this._submenuTimer = setTimeout(() => {\n this._submenuTimer = null;\n this._onOpenSubmenu(this);\n }, 150);\n } else {\n this._onOpenSubmenu(this);\n }\n };\n\n this._onMouseOut = () => {\n this.setFocused(false);\n\n if (this._submenuTimer !== null) {\n clearTimeout(this._submenuTimer);\n this._submenuTimer = null;\n }\n };\n\n this._onClick = () => {\n if (enabled && !this.hasSubmenu()) {\n this._onActivate();\n }\n };\n\n Event.addListener(this, \"mouseover\", this._onMouseOver);\n Event.addListener(this, \"mouseout\", this._onMouseOut);\n Event.addListener(this, \"click\", this._onClick);\n\n if (options) {\n this.applyOptions(options);\n }\n\n this.updateLabelHeights();\n }\n\n /**\n * Applies a {@link MenuItemOptions} bag, dispatching menu item label,\n * enabled state, and focus highlight after inherited Component fields.\n *\n * @param options - The options bag carrying the values to apply.\n */\n protected applyOptions(options: MenuItemOptions): this {\n super.applyOptions(options);\n\n if (options.text !== undefined && this._titleText) {\n this._titleText.setText(options.text);\n }\n\n if (options.enabled !== undefined) {\n this.getAria().setDisabled(!options.enabled);\n this.setCursor(options.enabled ? \"pointer\" : \"default\");\n }\n\n if (options.focused !== undefined) {\n this.setFocused(options.focused);\n }\n\n return this;\n }\n\n /**\n * Returns `true` if this item has a child submenu.\n *\n * @returns Whether a `submenu` config was provided.\n */\n hasSubmenu(): boolean {\n return !!this._config.submenu;\n }\n\n /** True when the item reserves an icon column (has a glyph or icon slot). */\n hasIcon(): boolean {\n return !!this._config.icon || !!this._config.glyph;\n }\n\n /** The item's measured title width, feeding the menu's shared title column. */\n titleTextWidth(): number {\n return Math.ceil(this._titleText?.getPreferredSize()?.width ?? 0);\n }\n\n /** The item's measured shortcut width, or 0 when it has no shortcut. */\n shortcutTextWidth(): number {\n if (!this._config.shortcut || this._shortcutText === null) {\n return 0;\n }\n\n return Math.ceil(this._shortcutText.getPreferredSize()?.width ?? 0);\n }\n\n /**\n * Applies the menu-computed column geometry so every item lines up: the title\n * left offset (icon column, or the bare inset) and the shared title-column\n * width the shortcut/chevron right zone begins after.\n *\n * @param iconStart - The title's left offset in pixels.\n * @param titleColumn - The shared title-column width across the menu's items.\n */\n setColumns(iconStart: number, titleColumn: number): void {\n this._iconStart = iconStart;\n this._titleColumn = titleColumn;\n\n this.scheduleLayout();\n }\n\n /**\n * Returns the submenu config, or `null` if this item has no submenu.\n *\n * @returns The [`MenuConfig`](/api/component/container/interfaces/MenuConfig) for the child panel, or null.\n */\n getSubmenuConfig(): MenuConfig | null {\n return this._config.submenu ?? null;\n }\n\n /**\n * Applies or removes the keyboard-focus highlight background.\n *\n * @param focused - `true` to highlight, `false` to clear.\n */\n setFocused(focused: boolean): this {\n this.setBackgroundColor(\n focused\n ? `var(--ts-ui-${this._cssVarPrefix}-item-hover-bg, rgba(30, 100, 200, 0.12))`\n : \"transparent\"\n );\n\n return this;\n }\n\n /**\n * Returns `true` when this item was constructed with `separator: true`.\n *\n * @returns Whether this item is a non-interactive separator row.\n */\n isSeparator(): boolean {\n return !!this._config.separator;\n }\n\n /**\n * Returns `true` when the item is interactive (not disabled).\n *\n * @returns Whether `enabled` was not explicitly set to `false`.\n */\n isEnabled(): boolean {\n return this._config.enabled !== false;\n }\n\n /**\n * Activates this item as if the user clicked or pressed Enter.\n *\n * For submenu items, calls `onOpenSubmenu` immediately (skipping the hover delay).\n * For leaf items, calls `onActivate`. Does nothing for disabled or separator items.\n */\n activate(): void {\n if (this.isSeparator() || !this.isEnabled()) {\n return;\n }\n\n if (this.hasSubmenu()) {\n this._onOpenSubmenu(this);\n } else {\n this._onActivate();\n }\n }\n\n /**\n * Removes all Event listeners registered by this item, cancels any pending\n * submenu timer, then defers to the base class for the rest of teardown.\n */\n protected destructor(): void {\n if (this._submenuTimer !== null) {\n clearTimeout(this._submenuTimer);\n this._submenuTimer = null;\n }\n\n Event.removeListener(this, \"mouseover\", this._onMouseOver);\n Event.removeListener(this, \"mouseout\", this._onMouseOut);\n Event.removeListener(this, \"click\", this._onClick);\n\n super.destructor();\n }\n\n /**\n * Returns the offset from the top of the menu item to the title text's baseline.\n *\n * @returns The baseline offset in pixels, or `null` when the title has no baseline\n * (e.g. for a separator row).\n */\n getBaseline(): number | null {\n if (this._titleText === null) {\n return null;\n }\n\n return this.wrapInnerBaseline(this._titleText.getBaseline());\n }\n\n /**\n * Re-pins the four labels' line boxes to the item's CONTENT height —\n * `MenuItem.HEIGHT` less this item's own vertical chrome. `centerInHeight`\n * pins a label's minimum height as well as its line box, so a label pinned to\n * the outer height cannot shrink into a bordered item's content box and is\n * clipped. Called from the constructor tail and whenever the border changes.\n */\n private updateLabelHeights(): void {\n const perimeter = this.getPerimeterSize();\n // Floor of 1: chrome at or past the row height leaves nothing to centre\n // in, and a zero or negative line-height is not a value CSS should see.\n // The label clips in that case either way — the floor only keeps the\n // written value sane.\n const height = Math.max(1, MenuItem.HEIGHT - perimeter.top - perimeter.bottom);\n\n // Optional chaining, not null checks: a separator has none of these, and a\n // border arriving through the options bag could in principle reach here\n // before the field initializers have run.\n this._iconText?.centerInHeight(height);\n this._titleText?.centerInHeight(height);\n this._shortcutText?.centerInHeight(height);\n this._chevronText?.centerInHeight(height);\n }\n\n /**\n * Applies a border, then re-pins the four labels' line boxes to the item's\n * new content height so a bordered item's labels shrink to fit instead of\n * overrunning the smaller content box.\n *\n * @param options - Border configuration, or a CSS `border` shorthand string.\n * @returns This component, for method chaining.\n */\n setBorder(options: BorderOptions | string): this {\n super.setBorder(options);\n this.updateLabelHeights();\n\n return this;\n }\n\n /**\n * Clears the border, then re-pins the four labels' line boxes back to the\n * item's now-larger content height.\n *\n * @returns This component, for method chaining.\n */\n clearBorder(): this {\n super.clearBorder();\n this.updateLabelHeights();\n\n return this;\n }\n\n /**\n * Positions the four label zones within the item's content box.\n *\n * @returns This component, for method chaining.\n */\n doLayout(): this {\n super.doLayout();\n\n if (this._config.separator) {\n return this;\n }\n\n const box = this.getContentBounds();\n\n if (!box) {\n return this;\n }\n\n // Heights come from the content box, not MenuItem.HEIGHT: the constant\n // is the item's outer height. With no border the two are the same\n // number. The texts' line boxes are pinned to match by\n // updateLabelHeights, so they fit this box rather than overrunning it.\n const H = box.height;\n const totalWidth = box.width;\n const hasShortcut = !!this._config.shortcut && this._shortcutText !== null;\n const hasSub = this.hasSubmenu();\n\n // The menu aligns every item into shared columns; a standalone item falls\n // back to its own icon offset and natural title width.\n const iconStart = this._iconStart ?? (this.hasIcon() ? MenuItem.ICON_ZONE : MenuItem.TEXT_INSET);\n const titleColumn = this._titleColumn ?? this.titleTextWidth();\n\n if (this._iconGlyph) {\n const size = this._iconGlyph.getPreferredSize() ?? { width: 16, height: 16 };\n const iconY = Math.max(0, Math.floor((H - size.height) / 2));\n\n this._iconGlyph.setX(box.x + 4);\n this._iconGlyph.setY(box.y + iconY);\n this._iconGlyph.setWidth(size.width);\n this._iconGlyph.setHeight(size.height);\n } else if (this._iconText) {\n this._iconText.setX(box.x + 4);\n this._iconText.setY(box.y);\n this._iconText.setWidth(20);\n this._iconText.setHeight(H);\n }\n\n // Title fills the shared title column, left-aligned from the icon offset.\n if (this._titleText) {\n this._titleText.setX(box.x + iconStart);\n this._titleText.setY(box.y);\n this._titleText.setWidth(titleColumn);\n this._titleText.setHeight(H);\n }\n\n // Chevron: right-justified at the panel's inner edge.\n if (hasSub && this._chevronText) {\n this._chevronText.setX(box.x + totalWidth - MenuItem.RIGHT_PAD - MenuItem.CHEVRON_ZONE);\n this._chevronText.setY(box.y);\n this._chevronText.setWidth(MenuItem.CHEVRON_ZONE);\n this._chevronText.setHeight(H);\n }\n\n // Shortcut: left-justified in the right zone, one gap past the title column.\n if (hasShortcut && this._shortcutText) {\n this._shortcutText.setX(box.x + iconStart + titleColumn + MenuItem.TEXT_GAP);\n this._shortcutText.setY(box.y);\n this._shortcutText.setWidth(this.shortcutTextWidth());\n this._shortcutText.setHeight(H);\n }\n\n return this;\n }\n}\n\nconst MenuItemCallable = callable(MenuItem);\ntype MenuItemCallable = MenuItem;\nexport {\n MenuItem as _MenuItem,\n MenuItemCallable as MenuItem\n};\n","// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0\n\nimport { Component, ComponentOptions } from \"~/core/Component.js\";\nimport type { MenuItemCSSVarPrefix } from \"~/component/container/MenuItem.js\";\nimport { callable } from \"~/core/Callable.js\";\n\n/**\n * Construction-time options for {@link MenuSeparator}.\n *\n * @category Components\n */\nexport interface MenuSeparatorOptions extends ComponentOptions {\n}\n\n/**\n * Empty subclass-default const so the super call follows the framework's\n * `(options, defaults)` shape uniformly. MenuSeparator owns no class-level\n * option overrides today; the const exists so a future field has a place to\n * land without reshuffling the super call.\n */\nconst _defaultMenuSeparatorOptions: Partial<MenuSeparatorOptions> = {};\n\n/**\n * A horizontal separator rule used inside a [`Menu`](/api/overlay/classes/Menu) panel to visually group menu items.\n *\n * Renders as a thin border line. Width is set externally by `Menu.doLayout()`.\n *\n * @category Components\n */\nclass MenuSeparator extends Component<MenuSeparatorOptions> {\n\n /** Fixed pixel height of every separator. */\n static readonly HEIGHT: number = 9;\n\n /**\n * Constructs a MenuSeparator with a thin horizontal rule appearance.\n *\n * @param cssVarPrefix - Selects which CSS-variable family supplies the border colour. Defaults to `'menu-bar'`.\n * @param options - Optional construction options.\n * @param subclassDefaults - Per-subclass default bag layered over this\n * class's defaults; subclasses forward their `_defaultXxxOptions`\n * constant here.\n */\n constructor(\n cssVarPrefix: MenuItemCSSVarPrefix = \"menu-bar\",\n options?: MenuSeparatorOptions,\n subclassDefaults?: Partial<MenuSeparatorOptions>,\n ) {\n super(options, { ..._defaultMenuSeparatorOptions, ...(subclassDefaults ?? {}) });\n\n this.setHeight(MenuSeparator.HEIGHT);\n this.setPreferredSize({ width: 0, height: MenuSeparator.HEIGHT });\n this.setBackgroundColor(\"transparent\");\n this.setElementCSSRule(\n \"borderTop\",\n `1px solid var(--ts-ui-${cssVarPrefix}-separator-color, rgb(220, 220, 220))`\n );\n this.setElementCSSRule(\"margin\", \"4px 0\");\n this.getAria().setRole(\"separator\");\n }\n}\n\nconst MenuSeparatorCallable = callable(MenuSeparator);\ntype MenuSeparatorCallable = MenuSeparator;\nexport {\n MenuSeparator as _MenuSeparator,\n MenuSeparatorCallable as MenuSeparator\n};\n","// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0\n\nimport { Component } from \"~/core/Component.js\";\nimport { DOM } from \"~/core/DOM.js\";\nimport type { Handle, Rect } from \"~/core/DOM.js\";\nimport { LayerManager, DismissableLayer, LayerDismissMode } from \"~/core/LayerManager.js\";\nimport { positionAligned, positionFlexibleAnchored } from \"~/core/OverlayPosition.js\";\nimport { fadeShow, fadeHideAndDetach } from \"~/core/AnimatedDropdown.js\";\nimport type { Animation } from \"~/core/Animation.js\";\nimport { Insets } from \"~/primitive/Insets.js\";\nimport type { Size } from \"~/primitive/Size.js\";\nimport { VBox } from \"~/layout/VBox.js\";\nimport { MenuItem, MenuItemConfig } from \"~/component/container/MenuItem.js\";\nimport { MenuSeparator } from \"~/component/container/MenuSeparator.js\";\nimport { callable } from \"~/core/Callable.js\";\nimport { Util } from \"~/core/Util.js\";\n\n/**\n * Pixel bounds a content-sized menu panel clamps to. Menus size to their widest\n * item (via the layout manager's preferred width); the floor keeps a short menu\n * from looking cramped, and the ceiling stops a very long label running off-screen\n * (the item's title ellipsizes past it).\n */\nconst MIN_MENU_WIDTH = 120;\nconst MAX_MENU_WIDTH = 360;\n\n/** Duration (ms) of the fade-in / fade-out transitions on every menu panel. */\nconst MENU_ANIM_DURATION_MS = 120;\n\n/** Pixels kept between a clamped menu and the viewport edge so the panel\n * border and shadow are never flush against the screen. Mirrors the small\n * inset used by other floating panels; purely cosmetic breathing room. */\nconst VIEWPORT_MARGIN = 4;\n\n/** A resolved rebuild-mode placement: the panel's top-left plus the height room at it. */\ninterface MenuPlacement { x: number; y: number; available: number; }\n\n/**\n * A zero-size rect at a cursor point. A cursor is a degenerate anchor: with\n * `left === right` and `top === bottom`, the adjacency and alignment flips\n * collapse to the same operation — grow down-right from the point, or end at it.\n * That is native context-menu behaviour, so a pointer needs no separate path.\n */\nfunction pointRect(x: number, y: number): Rect {\n return { x, y, left: x, top: y, right: x, bottom: y, width: 0, height: 0 };\n}\n\n/**\n * Resolves a rebuild-mode panel's placement against `anchorRect` at `size`.\n * Vertically the panel is size-flexible (it caps its height and scrolls), so it\n * grows below the anchor and flips to end at the anchor's top when the room below\n * is short. Horizontally it is fixed-size (a natural width, no horizontal scroll),\n * so its left edge aligns with the anchor's left and flips to align its right edge\n * with the anchor's right when the left alignment overflows.\n *\n * @param anchorRect - The trigger rect, or a zero-size rect at the cursor.\n * @param size - The panel's current width/height to place.\n * @param vp - The viewport size to flip/clamp within.\n * @returns The resolved top-left coordinate and the vertical room available there.\n */\nfunction resolvePlacement(anchorRect: Rect, size: Size, vp: Size): MenuPlacement {\n const v = positionFlexibleAnchored(anchorRect.top, anchorRect.bottom, size.height, vp.height, VIEWPORT_MARGIN);\n const x = positionAligned(anchorRect.left, anchorRect.right, size.width, vp.width, VIEWPORT_MARGIN);\n\n // `available` is the room on the side the panel actually landed on — never\n // re-derive it from `v.start`, which measures the wrong side for a flipped\n // panel and lets an over-tall menu grow back across the cursor.\n return { x, y: v.start, available: v.available };\n}\n\n/**\n * A floating menu panel that operates in one of two modes:\n *\n * - **Rebuild mode** (`new Menu()`): a right-click context menu. Items are passed per\n * `show(x, y, items)` call and disposed on the next show or hide.\n * - **Persistent mode** (`new Menu(items, onClose)`): a [`MenuBar`](/api/component/menubar/classes/MenuBar) dropdown. Items are\n * built once in the constructor and reused across `open()` / `close()` cycles.\n *\n * The two API surfaces are disjoint by mode:\n * `show()` / `hide()` / `setMenuWidth()` are valid only in rebuild mode;\n * `open()` / `close()` / focus and submenu methods are valid only in persistent mode.\n *\n * @example\n * ```typescript\n * // Rebuild mode — right-click context menu\n * const menu = new Menu();\n * Event.addListener(myComponent, 'contextmenu', (e: MouseEvent) => {\n * e.preventDefault();\n * menu.show(e.clientX, e.clientY, [\n * { text: 'Cut', action: () => cut() },\n * { separator: true },\n * { text: 'Paste', action: () => paste() },\n * ]);\n * });\n *\n * // Persistent mode — MenuBar dropdown\n * const panel = new Menu(\n * [{ text: 'Save', shortcut: 'Ctrl+S', action: () => save() }],\n * () => bar.closeMenu()\n * );\n * panel.open(buttonElement);\n * ```\n *\n * @category Components\n */\nclass Menu extends Component implements DismissableLayer {\n\n private readonly _persistent: boolean;\n // A persistent menu's items provider, kept so each open() re-resolves it —\n // null when the items were passed as a fixed array (built once, never rebuilt).\n private readonly _itemsProvider: (() => MenuItemConfig[]) | null;\n private readonly _onClose: (() => void) | null;\n // In both modes every entry is registered via `addComponent` (see\n // `showAnchored` / `buildPersistentItems`), so the `destructor()` override\n // below has no item disposal to do — the base class's recursive teardown\n // already disposes each item; the override exists only to cancel the\n // in-flight fades. (A prior override manually\n // re-disposed them here, guarded to persistent mode only via\n // `assertPersistentMode`. That guard was never reachable through ancestor\n // teardown — no `Menu` anywhere in the library is itself registered via\n // `addComponent` (`Table._columnContextMenu` / `TabBar._contextMenu` are\n // plain fields, never added as children), so an ancestor's `destructor()`\n // recursion can never reach a `Menu` at all. The loop was removed simply\n // because it was redundant, not because the guard made it unsafe.)\n private _menuItems: Array<MenuItem | MenuSeparator> = [];\n\n // In-flight fades, cancelled on teardown so their fallback timers cannot\n // fire against this menu's released element handle.\n private _fadeShowAnimation: Animation.CancelHandle | null = null;\n private _fadeHideAnimation: Animation.CancelHandle | null = null;\n private _focusedIndex: number = -1;\n private _openSubmenuPanel: Menu | null = null;\n private _openSubmenuItem: MenuItem | null = null;\n private _excludedEl: Handle | null = null;\n // An explicit rebuild-mode width set via setMenuWidth; null means size to\n // content (the widest item, clamped to [MIN_MENU_WIDTH, MAX_MENU_WIDTH]).\n private _menuWidth: number | null = null;\n private _rebuildOnClose: (() => void) | null = null;\n private _currentOpener: Handle | null = null;\n // Rebuild-mode: when true, each show() scrolls the menu to the bottom after\n // layout so the latest (bottom-most) items are visible on open.\n private _scrollToBottomOnShow: boolean = false;\n\n /**\n * Constructs a Menu. With no arguments, a rebuild-mode (right-click context)\n * menu whose items are supplied per `show()` call. With `items` (and `onClose`),\n * a persistent-mode ([`MenuBar`](/api/component/menubar/classes/MenuBar) dropdown)\n * menu whose items are built immediately and reused across `open()` / `close()`\n * cycles.\n *\n * A single optional-parameter signature, deliberately not an overload pair: the\n * `callable()` export's construct/call type is derived via TS `ConstructorParameters`,\n * which captures only the *last* overload — an overload pair would drop the\n * no-arg form and make `Menu()` a type error for consumers.\n *\n * @param items - The menu item configurations, or a provider called once now\n * to produce them. A submenu is rebuilt on each open, so a provider passed\n * for a submenu's items is re-invoked every time that submenu opens. Omit for\n * a rebuild-mode context menu.\n * @param onClose - Callback invoked when the panel should close (item activated or outside click).\n */\n constructor(items?: MenuItemConfig[] | (() => MenuItemConfig[]), onClose?: () => void) {\n super();\n\n this._persistent = items !== undefined;\n this._itemsProvider = typeof items === \"function\" ? items : null;\n this._onClose = onClose ?? null;\n\n const vbox = new VBox();\n\n vbox.setComponentSpacing(0);\n vbox.setStretching(true);\n\n this.setLayoutManager(vbox);\n\n if (this._persistent) {\n this.applyPersistentChrome();\n // Fixed array: build once now. A provider defers to open(), which\n // re-resolves it on every open (so the sole resolution is per-open).\n if (this._itemsProvider === null) {\n this.buildPersistentItems(items as MenuItemConfig[]);\n }\n } else {\n this.applyRebuildChrome();\n }\n }\n\n /**\n * Lays the menu's items into aligned columns and returns the panel width.\n * Every title shares one column sized to the widest title; the shortcut/chevron\n * right zone is the widest of the shortcut column and a submenu chevron, so\n * shortcuts left-justify in a column and chevrons right-justify at the edge.\n * The width is clamped to `[MIN_MENU_WIDTH, MAX_MENU_WIDTH]`; when the ceiling\n * bites, the title column shrinks and its titles ellipsize. Measured from the\n * items directly so a menu reused across shows re-measures its new content.\n *\n * @returns The clamped panel width in pixels.\n */\n private layOutColumns(): number {\n const items = this._menuItems.filter(\n (i): i is MenuItem => i instanceof MenuItem && !i.isSeparator()\n );\n\n const iconStart = items.some(i => i.hasIcon()) ? MenuItem.ICON_ZONE : MenuItem.TEXT_INSET;\n const maxTitle = items.reduce((m, i) => Math.max(m, i.titleTextWidth()), 0);\n const maxShortcut = items.reduce((m, i) => Math.max(m, i.shortcutTextWidth()), 0);\n const hasChevron = items.some(i => i.hasSubmenu());\n const rightZone = Math.max(maxShortcut, hasChevron ? MenuItem.CHEVRON_ZONE : 0);\n const rightReserve = rightZone > 0 ? MenuItem.TEXT_GAP + rightZone : 0;\n\n const natural = iconStart + maxTitle + rightReserve + MenuItem.RIGHT_PAD;\n const width = Math.min(MAX_MENU_WIDTH, Math.max(MIN_MENU_WIDTH, natural));\n\n // When the ceiling bites, the title column absorbs the shortfall (titles\n // ellipsize); otherwise it is the full widest-title width.\n const titleColumn = Math.min(maxTitle, width - iconStart - rightReserve - MenuItem.RIGHT_PAD);\n\n for (const item of items) {\n item.setColumns(iconStart, titleColumn);\n }\n\n return width;\n }\n\n /**\n * Shows the menu at the given viewport coordinates, replacing any previously\n * displayed items with the new list. **Rebuild-mode only.**\n *\n * The menu grows down-right from the cursor; when there is no room it flips\n * so its bottom / right edge ends at the cursor, never covering it. A menu\n * taller than the room on the side it lands on is capped there and scrolls.\n *\n * @param x - Horizontal viewport coordinate (e.g. `MouseEvent.clientX`).\n * @param y - Vertical viewport coordinate (e.g. `MouseEvent.clientY`).\n * @param configs - Ordered list of item descriptors to render.\n * @param onClose - Optional callback invoked once when the menu next closes\n * (item activated or dismissed by an outside click), letting the opener\n * revert an open-state affordance such as a rotated dropdown chevron.\n * @param excludeEl - Optional element whose subtree is exempt from the\n * outside-click-to-close check. Pass the trigger that opened the menu (e.g.\n * a [`SplitButton`](/api/component/button/classes/SplitButton) chevron) so a\n * pointerdown on it does not self-close the menu before the trigger's own\n * click can toggle it shut — mirroring [`MenuBar`](/api/component/menubar/classes/MenuBar)'s\n * dropdown-button exclusion.\n */\n show(x: number, y: number, configs: MenuItemConfig[], onClose?: () => void, excludeEl?: Handle | null): this {\n this.assertRebuildMode(\"show\");\n\n // The placement primitives only guarantee an on-screen result for an anchor\n // inside the viewport. A cursor from a real event always is; show() is public,\n // so pin it here rather than in showAnchored, which also takes real trigger\n // rects that may legitimately extend past a viewport edge.\n const vp = DOM.source.getViewportSize();\n\n return this.showAnchored(\n pointRect(Util.clamp(x, 0, vp.width), Util.clamp(y, 0, vp.height)),\n configs, onClose ?? null, excludeEl ?? null,\n );\n }\n\n /**\n * Rebuild-mode geometry-and-content core shared by {@link show} (pointer-anchored)\n * and {@link toggleFor} (rect-anchored). Both grow down-right from `anchorRect`\n * and flip per axis when the room runs short. Tears down and rebuilds the item\n * list, then resolves `anchorRect` to a placement and applies the resulting\n * position and height clamp.\n *\n * @param anchorRect - The cursor point (as a zero-size rect) or trigger rect to\n * place the panel against.\n * @param configs - Ordered list of item descriptors to render.\n * @param onClose - Callback invoked once when the menu next closes, or `null`.\n * @param excludeEl - Element whose subtree is exempt from the outside-click\n * check, or `null`.\n */\n private showAnchored(anchorRect: Rect, configs: MenuItemConfig[], onClose: (() => void) | null, excludeEl: Handle | null): this {\n this._rebuildOnClose = onClose;\n this._excludedEl = excludeEl;\n\n for (const item of this._menuItems) {\n if (item instanceof MenuItem) {\n item.dispose();\n }\n }\n\n this._menuItems = [];\n this.removeAllComponents();\n\n this.pauseLayout();\n\n for (const config of configs) {\n const item: MenuItem | MenuSeparator = config.separator === true\n ? new MenuSeparator(\"context-menu\")\n : new MenuItem(\n config,\n () => {\n config.action?.();\n this.hide();\n },\n (hoveredItem) => { this.handleItemOpenSubmenu(hoveredItem); },\n \"context-menu\"\n );\n\n this.addComponent(item);\n this._menuItems.push(item);\n }\n\n this.resumeLayout();\n\n const contentWidth = this.layOutColumns();\n const naturalWidth = this._menuWidth ?? contentWidth;\n\n this.setWidth(naturalWidth);\n\n // A reused menu still carries the previous show's max-height — set by\n // `applyViewportHeightClamp` to that show's available room. Because\n // `getPreferredSize` clamps to the component's own max, leaving it in\n // place would cap the new content at the old height, so a menu that\n // grew past its previous size would neither expand nor reserve a\n // scrollbar gutter on reopen. Clear it before measuring.\n this.setMaxSize({ width: Number.MAX_VALUE, height: Number.MAX_VALUE });\n\n const totalHeight = this.getPreferredSize()?.height ?? 0;\n\n const el = this.getElement(true)!;\n\n const vp = DOM.source.getViewportSize();\n\n // First pass at the natural width resolves the vertical room. Width does not\n // affect the vertical placement, so `available` stays correct after the\n // scrollbar-gutter widening below; only `x` needs the second pass.\n const available = resolvePlacement(anchorRect, { width: naturalWidth, height: totalHeight }, vp).available;\n\n // When the content is taller than the room on the side the menu lands on,\n // `applyViewportHeightClamp` caps the height and the `overflow-y: auto`\n // scrollbar engages. Reserve its width as a right inset — and widen the\n // content-sized panel to match — so items lay out beside the native\n // scrollbar instead of beneath it. `Component.getInnerSize` subtracts the\n // inset, so the VBox stretches items to `naturalWidth`, unchanged from the\n // no-scroll case.\n const gutter = totalHeight > available ? DOM.source.getScrollBarWidth() : 0;\n\n this.setInsets(new Insets(4, gutter, 4, 0));\n this.setWidth(naturalWidth + gutter);\n\n const placement = resolvePlacement(anchorRect, { width: this.getWidth(), height: totalHeight }, vp);\n\n this.setX(placement.x);\n this.setY(placement.y);\n this.applyViewportHeightClamp(placement.available, totalHeight);\n\n this.scheduleLayout();\n\n LayerManager.mount(el);\n\n this.setVisible(true);\n this.fadeIn();\n\n // Join the central layer tree: the manager owns the outside-pointerdown /\n // window-blur / Escape dismissal and stamps the z-index. Registering while\n // whatever opened the menu is topmost links it under that layer, so a\n // context menu raised over a modal dialog inherits the dialog band and\n // paints in front of it.\n LayerManager.register(this);\n this.setZIndex(LayerManager.getZIndex(this));\n\n // Optionally reveal the bottom of the list on open (e.g. a history menu\n // whose latest entries sit at the bottom). Flush the scheduled layout\n // first so the item heights are committed and `getMaxScrollTop` is\n // accurate; when nothing overflows the offset is 0 and this is a no-op.\n if (this._scrollToBottomOnShow) {\n this.flushLayout();\n this.setScrollTop(this.getMaxScrollTop());\n }\n\n return this;\n }\n\n /**\n * Opens or closes the menu for a given opener element. **Rebuild-mode only.**\n *\n * This is the toggle form of {@link show} for a left-click dropdown trigger\n * (e.g. a [`SplitButton`](/api/component/button/classes/SplitButton) chevron\n * or a [`ToolBar`](/api/component/menubar/classes/ToolBar) overflow button):\n * the opener is excluded from the outside-click dismissal (so its own\n * pointerdown does not self-close the menu) and remembered, so a second press\n * of the *same* opener closes the menu instead of reopening it. Pressing a\n * *different* opener while the menu is open switches it to that opener. The\n * menu opens below `anchorRect` and flips above it when the room below is\n * short, right-aligning to it when the left alignment overflows. Plain\n * {@link show} stays the right call for right-click context menus, which\n * should reposition — not close — on a repeat trigger; the remaining\n * distinction from `toggleFor` is the toggle identity, the opener exclusion,\n * and the empty-list suppression below.\n *\n * An empty `configs` opens nothing: the menu is not shown, `onClose` fires once\n * so the opener can revert an open-state affordance, and no opener state is\n * recorded. A repeat press of the *same* opener still closes an open menu — the\n * toggle-shut branch runs before the empty check.\n *\n * @param openerEl - The element that triggers the menu; excluded from the\n * outside-click check and used as the toggle identity.\n * @param anchorRect - The trigger's viewport rect (e.g.\n * `DOM.source.getViewportRect(button)`); the menu opens below it and flips\n * above it when the room below is short.\n * @param configs - Ordered list of item descriptors to render. An empty list\n * opens nothing (see above).\n * @param onClose - Optional callback invoked once when the menu next closes,\n * or when an empty `configs` suppresses the open.\n *\n * @returns This menu, for method chaining.\n */\n toggleFor(openerEl: Handle, anchorRect: Rect, configs: MenuItemConfig[], onClose?: () => void): this {\n this.assertRebuildMode(\"toggleFor\");\n\n // Same opener fired again while its menu is open: close it. Its pointerdown\n // was excluded from the dismissal above, so this click is the toggle-shut.\n // MUST stay ahead of the empty check below — a provider that has since gone\n // empty must still be able to close the panel it opened.\n if (this._currentOpener === openerEl) {\n this.hide();\n\n return this;\n }\n\n // Nothing to show: an empty panel is never useful, so open nothing. `onClose`\n // still fires so the opener reverts an optimistic open-state affordance (e.g.\n // SplitButton's spun-up chevron), and `_currentOpener` stays untouched, so the\n // next press of this opener is a fresh open rather than a stale toggle-shut.\n if (configs.length === 0) {\n onClose?.();\n\n return this;\n }\n\n // Closed, or open for a different opener: (re)show anchored for this one.\n this.showAnchored(anchorRect, configs, onClose ?? null, openerEl);\n this._currentOpener = openerEl;\n\n return this;\n }\n\n /**\n * Hides the menu and detaches it from the DOM. **Rebuild-mode only.**\n *\n * The instance remains alive and can be shown again by calling `show()`.\n */\n hide(): this {\n this.assertRebuildMode(\"hide\");\n\n this.closeOpenSubmenu();\n\n LayerManager.unregister(this);\n\n this.fadeOutAndDetach();\n\n // Forget the toggle opener so the next `toggleFor` for it opens rather\n // than seeing a stale match and closing an already-closed menu.\n this._currentOpener = null;\n\n // Fire the per-show close callback exactly once, clearing it first so a\n // later bare `hide()` (or re-show) can't re-invoke a stale opener's hook.\n const onClose = this._rebuildOnClose;\n this._rebuildOnClose = null;\n onClose?.();\n\n return this;\n }\n\n /**\n * Returns the current pixel width of the rebuild-mode menu panel (the\n * content-fit width, or an explicit override set via {@link setMenuWidth}).\n *\n * @returns The current panel width in pixels.\n */\n getMenuWidth(): number {\n return this.getWidth();\n }\n\n /**\n * Pins the rebuild-mode menu panel to an explicit width, overriding the\n * default content-fit sizing. **Rebuild-mode only.**\n *\n * @param width - Width in pixels.\n */\n setMenuWidth(width: number): this {\n this.assertRebuildMode(\"setMenuWidth\");\n\n this._menuWidth = width;\n\n return this;\n }\n\n /**\n * Controls whether the menu scrolls to the bottom of its item list each time\n * it is shown. **Rebuild-mode only.**\n *\n * Use this for a menu whose latest entries sit at the bottom (e.g. a\n * chronological notification history), so the most recent items are visible\n * on open rather than the user having to scroll down. A no-op when the list\n * fits without scrolling.\n *\n * @param value - `true` to scroll to the bottom on every show.\n *\n * @returns This menu, for method chaining.\n */\n setScrollToBottomOnShow(value: boolean): this {\n this.assertRebuildMode(\"setScrollToBottomOnShow\");\n\n this._scrollToBottomOnShow = value;\n\n return this;\n }\n\n /**\n * Opens this panel positioned below the anchor element (top-level) or to the\n * right of the parent panel (submenu). Appends to `document.documentElement`.\n * **Persistent-mode only.**\n *\n * @param anchorEl - The `HTMLElement` of the triggering button or menu item.\n * @param parentPanel - When set, positions the panel as a submenu of this parent.\n */\n open(anchorEl: Handle, parentPanel?: Menu): this {\n this.assertPersistentMode(\"open\");\n\n // A provider-sourced menu re-resolves its items on every open, so labels\n // and enabled state reflect current state each time it is shown (a submenu\n // is a fresh panel per open, but a reused top-level dropdown is not).\n if (this._itemsProvider) {\n this.rebuildPersistentItems(this._itemsProvider());\n }\n\n // Clear the previous open's max-height (set by `applyViewportHeightClamp`)\n // before measuring, so a provider-sourced dropdown that grew reflects its\n // new content height rather than being capped at the old available room.\n this.setMaxSize({ width: Number.MAX_VALUE, height: Number.MAX_VALUE });\n\n const totalHeight = this.getPreferredSize()?.height ?? (this._menuItems.length * MenuItem.HEIGHT + 8);\n const width = this.getWidth();\n\n const el = this.getElement(true)!;\n LayerManager.mount(el);\n\n const vp = DOM.source.getViewportSize();\n\n if (parentPanel) {\n const parentEl = parentPanel.getElement();\n const parentRect = parentEl\n ? DOM.source.getElementRect(parentEl)\n : { left: 0, right: 0, top: 0, bottom: 0 };\n const anchorRect = DOM.source.getElementRect(anchorEl);\n\n let x = parentRect.right;\n\n if (x + width > vp.width) {\n x = parentRect.left - width;\n }\n\n // A submenu grows down from the anchor item's top, and flips up\n // against that same top edge when there is more room above.\n const y = this.placeVertically(anchorRect.top, anchorRect.top, totalHeight, vp.height);\n\n this.setAutoCommitStyle(false);\n this.setX(Math.max(0, x));\n this.setY(Math.max(0, y));\n this.setAutoCommitStyle(true);\n } else {\n const anchorRect = DOM.source.getElementRect(anchorEl);\n\n let x = anchorRect.left;\n\n if (x + width > vp.width) {\n x = vp.width - width;\n }\n\n // A top-level dropdown grows down from the anchor's bottom, and\n // flips up against the anchor's top when there is more room above.\n const y = this.placeVertically(anchorRect.bottom, anchorRect.top, totalHeight, vp.height);\n\n this.setAutoCommitStyle(false);\n this.setX(Math.max(0, x));\n this.setY(Math.max(0, y));\n this.setAutoCommitStyle(true);\n }\n\n const anchorId = DOM.source.getId(anchorEl);\n\n if (anchorId) {\n this.getAria().setLabelledBy(anchorId);\n }\n\n this.setVisible(true);\n this.doLayout();\n this.fadeIn();\n\n // Join the central layer tree so the manager owns dismissal and the\n // z-stamp. A submenu opened via `open(item, this)` registers while its\n // parent menu is topmost, so it links under the parent — a pointerdown\n // inside the submenu counts as inside the parent (cross-portal\n // containment) and keeps the whole chain open.\n LayerManager.register(this);\n this.setZIndex(LayerManager.getZIndex(this));\n\n return this;\n }\n\n /**\n * Closes this panel and any open child submenus. Detaches from the DOM.\n * **Persistent-mode only.**\n */\n close(): this {\n this.assertPersistentMode(\"close\");\n\n this.closeOpenSubmenu();\n\n this.setFocusedIndex(-1);\n this.clearItemHighlights();\n\n LayerManager.unregister(this);\n\n this.fadeOutAndDetach();\n\n return this;\n }\n\n /**\n * Clears the hover highlight from every item. A click that activates an item\n * dismisses the menu, detaching the panel from the DOM under the pointer; the\n * browser fires no `mouseout` for an element removed under a stationary\n * pointer, so the hovered item's `setFocused(true)` is never undone by\n * `_onMouseOut`. `setFocusedIndex(-1)` only resets the keyboard-tracked item,\n * not one highlighted purely by hover. Persistent-mode menus reuse these item\n * elements across open/close, so without this sweep the stale highlight\n * reappears the next time the menu opens.\n */\n private clearItemHighlights(): void {\n for (const item of this._menuItems) {\n if (item instanceof MenuItem) {\n item.setFocused(false);\n }\n }\n }\n\n /**\n * Plays the standard menu-panel entrance fade. Cancels any in-flight\n * fade-out so the deferred detach skips removing the still-visible panel.\n */\n private fadeIn(): void {\n this._fadeShowAnimation?.cancel();\n this._fadeShowAnimation = fadeShow(this, { durationMs: MENU_ANIM_DURATION_MS });\n }\n\n /**\n * Plays the standard menu-panel exit fade, then hides and detaches the\n * panel from the DOM when the transition completes. A fresh `show()` /\n * `open()` during the fade cancels the deferred detach.\n */\n private fadeOutAndDetach(): void {\n this._fadeHideAnimation?.cancel();\n this._fadeHideAnimation = fadeHideAndDetach(this, { durationMs: MENU_ANIM_DURATION_MS });\n }\n\n /**\n * Cancels any in-flight fade, then defers to the base class. Cancelling\n * first keeps a fade's fallback timer from firing after `super.destructor()`\n * has released this menu's element handle.\n */\n protected destructor(): void {\n this._fadeShowAnimation?.cancel();\n this._fadeShowAnimation = null;\n this._fadeHideAnimation?.cancel();\n this._fadeHideAnimation = null;\n\n super.destructor();\n }\n\n /**\n * Moves keyboard focus to the item at the given index. Pass `-1` to clear focus.\n * **Persistent-mode only.**\n *\n * @param index - Zero-based item index, or `-1` to clear.\n */\n focusItem(index: number): this {\n this.assertPersistentMode(\"focusItem\");\n\n this.setFocusedIndex(index);\n\n return this;\n }\n\n /**\n * Moves focus to the next focusable item, wrapping around and skipping separators.\n * **Persistent-mode only.**\n */\n focusNext(): this {\n this.assertPersistentMode(\"focusNext\");\n\n let next = this._focusedIndex + 1;\n\n while (next < this._menuItems.length && this.isItemSeparator(next)) {\n next++;\n }\n\n if (next >= this._menuItems.length) {\n next = 0;\n\n while (next < this._menuItems.length && this.isItemSeparator(next)) {\n next++;\n }\n }\n\n this.setFocusedIndex(next);\n\n return this;\n }\n\n /**\n * Moves focus to the previous focusable item, wrapping around and skipping separators.\n * **Persistent-mode only.**\n */\n focusPrev(): this {\n this.assertPersistentMode(\"focusPrev\");\n\n let prev = this._focusedIndex - 1;\n\n while (prev >= 0 && this.isItemSeparator(prev)) {\n prev--;\n }\n\n if (prev < 0) {\n prev = this._menuItems.length - 1;\n\n while (prev >= 0 && this.isItemSeparator(prev)) {\n prev--;\n }\n }\n\n this.setFocusedIndex(prev);\n\n return this;\n }\n\n /**\n * Activates the currently focused item. No-op when no item is focused or the item\n * is disabled or a separator. **Persistent-mode only.**\n */\n activateFocused(): void {\n this.assertPersistentMode(\"activateFocused\");\n\n if (this._focusedIndex < 0 || this._focusedIndex >= this._menuItems.length) {\n return;\n }\n\n const item = this._menuItems[this._focusedIndex];\n\n if (item instanceof MenuItem && !item.isSeparator() && item.isEnabled()) {\n item.activate();\n }\n }\n\n /**\n * Returns the index of the currently focused item, or `-1` if no item is focused.\n * **Persistent-mode only.**\n *\n * @returns The focused item index, or -1.\n */\n getFocusedIndex(): number {\n this.assertPersistentMode(\"getFocusedIndex\");\n\n return this._focusedIndex;\n }\n\n /**\n * Sets an element whose subtree is excluded from the outside-click-to-close check.\n * **Persistent-mode only.**\n *\n * Used by [`MenuBar`](/api/component/menubar/classes/MenuBar) to prevent a pointerdown on its own buttons from closing the panel\n * before the button's click handler has a chance to toggle the menu.\n *\n * @param el - The element to exclude, or `null` to clear.\n */\n setExcludedElement(el: Handle | null): this {\n this.assertPersistentMode(\"setExcludedElement\");\n\n this._excludedEl = el;\n\n return this;\n }\n\n /**\n * Returns the element whose subtree is currently excluded from the\n * outside-click-to-close check, or `null` if none is set.\n *\n * @returns The excluded element, or null.\n */\n getExcludedElement(): Handle | null {\n return this._excludedEl;\n }\n\n /**\n * Applies the persistent-mode chrome (MenuBar dropdown CSS variables, aria role).\n */\n private applyPersistentChrome(): void {\n this.setBackgroundColor(\"var(--ts-ui-menu-bar-panel-bg, rgb(255, 255, 255))\");\n this.setInsets(new Insets(4, 0, 4, 0));\n this.setBorder({ border: \"1px solid var(--ts-ui-menu-bar-panel-border, rgb(200, 200, 200))\" });\n this.setBorderRadius(\"var(--ts-ui-border-radius, 4px)\");\n this.setShadow(\"var(--ts-ui-menu-bar-panel-shadow, 2px 4px 8px rgba(0, 0, 0, 0.15))\");\n this.getAria().setRole(\"menu\");\n this.setContain(\"layout\");\n\n this.enableVerticalScroll();\n }\n\n /**\n * Applies the rebuild-mode chrome (right-click context-menu CSS variables).\n */\n private applyRebuildChrome(): void {\n this.setVisible(false);\n this.setBackgroundColor(\"var(--ts-ui-context-menu-bg, rgb(255, 255, 255))\");\n this.setInsets(new Insets(4, 0, 4, 0));\n this.setBorder({ border: \"1px solid var(--ts-ui-context-menu-border, rgb(200, 200, 200))\" });\n this.setBorderRadius(\"var(--ts-ui-border-radius, 4px)\");\n this.setShadow(\"var(--ts-ui-context-menu-shadow, 2px 4px 8px rgba(0, 0, 0, 0.15))\");\n this.setContain(\"layout\");\n\n this.enableVerticalScroll();\n }\n\n /**\n * Wires the native vertical-scroll primitives so an over-tall menu scrolls\n * its items instead of overflowing the clamped panel height. This is the\n * `\"y\"` case of [`Panel.setAutoScroll`](/api/core/classes/Panel#setautoscroll)\n * replicated directly: `overflow-x: hidden` (so a `visible` x-axis does not\n * compute to `auto` and sprout a spurious horizontal scrollbar), `overflow-y:\n * auto`, and the layout manager's vertical overflow flag so the `VBox` lays\n * items out past the clamped inner height rather than compressing them.\n */\n private enableVerticalScroll(): void {\n this.setOverflowX(\"hidden\");\n this.setOverflowY(\"auto\");\n\n (this.getLayoutManager() as VBox).setOverflowing(false, true);\n }\n\n /**\n * Caps the menu's height to the vertical room available at its anchored\n * position, then applies the content height. Because `Menu` is a\n * `clampsToContentSize()` component, `setHeight` runs `contentHeight` through\n * `clampHeight`, which caps it at `availableHeight`; when the content fits no\n * clamp fires, and when it overflows the height is capped and the\n * `overflow-y: auto` scrollbar engages. Width is left unconstrained via the\n * `Number.MAX_VALUE` \"no constraint\" sentinel — horizontal scroll is a\n * non-goal.\n *\n * @param availableHeight - Vertical room (px) the menu may occupy at its anchor.\n * @param contentHeight - The unclamped preferred height (px) of the menu's items.\n */\n private applyViewportHeightClamp(availableHeight: number, contentHeight: number): void {\n this.setMaxSize({ width: Number.MAX_VALUE, height: Math.max(0, availableHeight) });\n this.setHeight(contentHeight);\n }\n\n /**\n * Resolves the persistent-mode panel's top coordinate and applies the\n * matching height clamp. The menu grows downward from `growTop` unless the\n * content overflows the room below *and* the room above the anchor is\n * larger, in which case it flips to grow upward from `anchorTop`. Delegates\n * the room/flip arithmetic to {@link positionFlexibleAnchored}, which measures\n * the room against the side the menu actually grows toward — never re-derived\n * from a clamped top, which would let a flipped, viewport-pinned menu grow\n * back down across its anchor.\n *\n * @param growTop - The viewport edge the menu grows downward from.\n * @param anchorTop - The anchor edge the menu flips up against.\n * @param totalHeight - The unclamped preferred height (px) of the menu's items.\n * @param viewportHeight - The current viewport height (px).\n * @returns The resolved top coordinate (px) for the panel.\n */\n private placeVertically(growTop: number, anchorTop: number, totalHeight: number, viewportHeight: number): number {\n const { start, available } = positionFlexibleAnchored(anchorTop, growTop, totalHeight, viewportHeight, VIEWPORT_MARGIN);\n\n this.applyViewportHeightClamp(available, totalHeight);\n\n return start;\n }\n\n /**\n * Tear down the current persistent items and rebuild them from `configs`.\n * Used by `open()` to re-resolve a provider-sourced dropdown each time it\n * shows, so its labels / enabled state track current state. Mirrors the\n * rebuild-mode `show()` teardown, then defers to {@link buildPersistentItems}.\n *\n * @param configs - The freshly-resolved item configurations.\n */\n private rebuildPersistentItems(configs: MenuItemConfig[]): void {\n this.closeOpenSubmenu();\n\n for (const item of this._menuItems) {\n if (item instanceof MenuItem) {\n item.dispose();\n }\n }\n\n this._menuItems = [];\n this._focusedIndex = -1;\n this.removeAllComponents();\n\n this.buildPersistentItems(configs);\n }\n\n /**\n * Builds the item list for persistent mode and sets the panel width.\n *\n * @param items - The item configs from the constructor.\n */\n private buildPersistentItems(items: MenuItemConfig[]): void {\n this.pauseLayout();\n\n for (const config of items) {\n const item = new MenuItem(\n config,\n () => { config.action?.(); this._onClose!(); },\n (hoveredItem) => { this.handleItemOpenSubmenu(hoveredItem); }\n );\n\n this.addComponent(item);\n this._menuItems.push(item);\n }\n\n this.resumeLayout();\n\n this.setWidth(this.layOutColumns());\n }\n\n /**\n * Updates the focused-item highlight, clearing the previous item and setting the new one.\n *\n * @param index - The new focused index, or -1 to clear.\n */\n private setFocusedIndex(index: number): void {\n if (this._focusedIndex >= 0 && this._focusedIndex < this._menuItems.length) {\n const prev = this._menuItems[this._focusedIndex];\n\n if (prev instanceof MenuItem) {\n prev.setFocused(false);\n }\n }\n\n this._focusedIndex = index;\n\n if (index >= 0 && index < this._menuItems.length) {\n const next = this._menuItems[index];\n\n if (next instanceof MenuItem) {\n next.setFocused(true);\n }\n }\n }\n\n /**\n * Returns `true` if the item at the given index should be skipped during focus traversal.\n *\n * @param index - Zero-based item index.\n * @returns Whether the item is a separator (or [`MenuSeparator`](/api/component/container/classes/MenuSeparator) instance).\n */\n private isItemSeparator(index: number): boolean {\n const item = this._menuItems[index];\n\n if (item instanceof MenuSeparator) {\n return true;\n }\n\n if (item instanceof MenuItem) {\n return item.isSeparator();\n }\n\n return false;\n }\n\n /**\n * Closes and forgets this menu's open child submenu, if any. Shared by the\n * teardown paths (`hide` / `close`) and by the submenu switch in\n * `handleItemOpenSubmenu` when a different item takes the child slot.\n */\n private closeOpenSubmenu(): void {\n if (this._openSubmenuPanel) {\n this._openSubmenuPanel.close();\n this._openSubmenuItem?.getAria().setExpanded(false);\n this._openSubmenuPanel = null;\n this._openSubmenuItem = null;\n }\n }\n\n /**\n * Closes the whole menu chain through the current mode's close path: the\n * persistent-mode `onClose` callback (a menubar dropdown), or `hide()` for a\n * rebuild-mode context menu — which also tears down any open child submenu.\n * Used by an activated submenu leaf and the outside-click / window-blur\n * dismissals, so a submenu selection closes the parent context menu too.\n */\n private dismissAll(): void {\n if (this._persistent) {\n this._onClose!();\n } else {\n this.hide();\n }\n }\n\n // ----- DismissableLayer -----\n\n /**\n * Returns the menu panel's root element for the central layer tree.\n *\n * @returns The menu's element, or null when not yet rendered.\n */\n getLayerElement(): Handle | null {\n return this.getElement() ?? null;\n }\n\n /**\n * Returns the dismiss mode the document-level handlers consult. A menu is\n * `\"click-outside\"`: dismissed by a `pointerdown` outside its layer subtree\n * (and its excluded trigger) and by a window blur, but never by a focus\n * move — exactly the pointerdown + window-blur behaviour the menu owned\n * before it joined the layer tree.\n *\n * @returns The layer dismiss mode.\n */\n getDismissMode(): LayerDismissMode {\n return \"click-outside\";\n }\n\n /**\n * Advisory close request from the manager (an outside `pointerdown`, a\n * window blur, or Escape). Routes through the mode-aware close chain: a\n * persistent (MenuBar) menu fires its `onClose`, a rebuild (context) menu\n * calls `hide()`; either way any open submenu is torn down.\n */\n requestClose(): void {\n this.dismissAll();\n }\n\n /**\n * Returns the trigger element excluded from the manager's outside-pointerdown\n * test — the context-menu opener passed to {@link show} / {@link toggleFor},\n * or the [`MenuBar`](/api/component/menubar/classes/MenuBar) button set via\n * {@link setExcludedElement} — so the gesture that opened the menu does not\n * immediately re-close it.\n *\n * @returns The excluded element, or null.\n */\n getAnchorElement(): Handle | null {\n return this._excludedEl;\n }\n\n /**\n * Returns the dropdown z-index band so an unrelated top-level menu stacks in\n * the dropdown family. A submenu — or a menu opened while another layer is\n * topmost — inherits its opener's band instead, so it rises above the\n * surface it was opened from.\n *\n * @returns The dropdown band base.\n */\n getBand(): number {\n return LayerManager.Band.Dropdown;\n }\n\n /**\n * Mirrors a manager-allocated z-index onto the element when the layer this\n * menu was opened inside is raised via the manager's bring-to-front path,\n * so an open menu never falls behind the surface it belongs to.\n *\n * @param zIndex - The fresh z-index assigned by the manager.\n */\n onZIndexChanged(zIndex: number): void {\n this.setZIndex(zIndex);\n }\n\n /**\n * Handles the open-submenu signal from a hovered or activated [`MenuItem`](/api/component/container/classes/MenuItem).\n *\n * Closes any existing child submenu when the item has no submenu (or is\n * disabled); opens or switches to the child panel when it does.\n *\n * @param item - The [`MenuItem`](/api/component/container/classes/MenuItem) that triggered the signal.\n */\n private handleItemOpenSubmenu(item: MenuItem): void {\n // A disabled item opens no submenu (even though it has one); like a plain\n // item, hovering it just closes any sibling submenu that is open.\n if (!item.hasSubmenu() || !item.isEnabled()) {\n this.closeOpenSubmenu();\n\n return;\n }\n\n if (this._openSubmenuItem === item) {\n return;\n }\n\n this.closeOpenSubmenu();\n\n const submenuPanel = new Menu(\n item.getSubmenuConfig()!.items,\n () => { this.dismissAll(); }\n );\n\n this._openSubmenuPanel = submenuPanel;\n this._openSubmenuItem = item;\n item.getAria().setExpanded(true);\n\n submenuPanel.setExcludedElement(this.getElement(true)!);\n submenuPanel.open(item.getElement(true)!, this);\n }\n\n /**\n * Throws if the method called is not valid in the current mode (rebuild-only check).\n *\n * @param method - Name of the method that was invoked, used in the error message.\n */\n private assertRebuildMode(method: string): void {\n if (this._persistent) {\n throw new Error(`Menu.${method}() is only valid in rebuild mode (constructed without arguments).`);\n }\n }\n\n /**\n * Throws if the method called is not valid in the current mode (persistent-only check).\n *\n * @param method - Name of the method that was invoked, used in the error message.\n */\n private assertPersistentMode(method: string): void {\n if (!this._persistent) {\n throw new Error(`Menu.${method}() is only valid in persistent mode (constructed with items and onClose).`);\n }\n }\n}\n\nconst MenuCallable = callable(Menu);\ntype MenuCallable = Menu;\nexport {\n Menu as _Menu,\n MenuCallable as Menu\n};\n"],"mappings":"qXA6kBA,IAAM,EAAmB,EAAS,MA/d5B,iBAAiB,CAAU,CAG7B,OAAgB,OAAiB,GAEjC,OAAwB,iBAA2B,EAEnD,OAAgB,WAAqB,EAErC,OAAgB,UAAoB,GAEpC,OAAgB,aAAuB,GAEvC,OAAgB,UAAoB,EAKpC,OAAgB,SAAmB,GAEnC,QACA,YACA,eACA,cAEA,UAAiC,KACjC,WAAmC,KACnC,WAAkC,KAClC,cAAqC,KACrC,aAAoC,KAMpC,WAAoC,KACpC,aAAsC,KAEtC,cAA8D,KAE9D,aACA,YACA,SAUA,YACI,EACA,EACA,EACA,EAAqC,WACrC,EACF,CAUE,GAPA,MAAM,EAEN,KAAK,QAAU,EACf,KAAK,YAAc,EACnB,KAAK,eAAiB,EACtB,KAAK,cAAgB,EAEjB,EAAO,UAAW,CAClB,KAAK,UAAU,SAAS,gBAAgB,EACxC,KAAK,iBAAiB,CAAE,MAAO,EAAG,OAAQ,SAAS,gBAAiB,CAAC,EACrE,KAAK,mBAAmB,aAAa,EACrC,KAAK,kBACD,YACA,yBAAyB,EAAa,sCAC1C,EACA,KAAK,kBAAkB,SAAU,OAAO,EACxC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AK,WAAW,EAAI,CAAE,EACtD,EAAa,KAAK,EAAK,WAAW,EAAI,EAAI,IAAI,CAClD,CAOA,kBAA0B,EAAsB,CAC5C,GAAI,KAAK,YACL,MAAU,MAAM,QAAQ,EAAO,kEAAkE,CAEzG,CAOA,qBAA6B,EAAsB,CAC/C,GAAI,CAAC,KAAK,YACN,MAAU,MAAM,QAAQ,EAAO,0EAA0E,CAEjH,CACJ,CAEkC"}
@@ -1,2 +1,2 @@
1
- import{t as e}from"./DOM-BeR95tE8.js";import{m as t}from"./Component-CHTzJxEf.js";import{t as n}from"./Button-B36rBMKC.js";import{t as r}from"./Menu-B6ippw-p.js";var i=t(class MenuButton extends n{_menu=null;_boundToggleMenu=()=>{this.toggleMenu()};constructor(e,t,n){let r;typeof e==`string`?r=e:e!==void 0&&(t=e),super(r,t,n),this.on(`action`,this._boundToggleMenu),Object.getPrototypeOf(this)===MenuButton.prototype&&this.applyListeners(t?.listeners)}setMenuItems(e){return this._options.menuItems=e,this}getMenuItems(){return this._options.menuItems??this._defaultOptions.menuItems??null}isScrollToBottomOnShow(){return this._options.scrollToBottomOnShow??this._defaultOptions.scrollToBottomOnShow??!1}applyOptions(e){return super.applyOptions(e),e.menuItems!==void 0&&this.setMenuItems(e.menuItems),e.scrollToBottomOnShow!==void 0&&(this._options.scrollToBottomOnShow=e.scrollToBottomOnShow),this}toggleMenu(){let t=this.getElement();t&&(this._menu??=new r().setScrollToBottomOnShow(this.isScrollToBottomOnShow()),this._menu.toggleFor(t,e.source.getViewportRect(this),this.resolveMenuItems()))}resolveMenuItems(){let e=this.getMenuItems();return typeof e==`function`?e():e??[]}});export{i as t};
2
- //# sourceMappingURL=MenuButton-Bjm1OyB-.js.map
1
+ import{t as e}from"./DOM-67StIm5G.js";import{h as t}from"./Component-DHqrPwAw.js";import{t as n}from"./Button-bjpWruNc.js";import{t as r}from"./Menu-B_-SQj72.js";var i=t(class MenuButton extends n{_menu=null;_boundToggleMenu=()=>{this.toggleMenu()};constructor(e,t,n){let r;typeof e==`string`?r=e:e!==void 0&&(t=e),super(r,t,n),this.on(`action`,this._boundToggleMenu),Object.getPrototypeOf(this)===MenuButton.prototype&&this.applyListeners(t?.listeners)}setMenuItems(e){return this._options.menuItems=e,this}getMenuItems(){return this._options.menuItems??this._defaultOptions.menuItems??null}isScrollToBottomOnShow(){return this._options.scrollToBottomOnShow??this._defaultOptions.scrollToBottomOnShow??!1}applyOptions(e){return super.applyOptions(e),e.menuItems!==void 0&&this.setMenuItems(e.menuItems),e.scrollToBottomOnShow!==void 0&&(this._options.scrollToBottomOnShow=e.scrollToBottomOnShow),this}toggleMenu(){let t=this.getElement();t&&(this._menu??=new r().setScrollToBottomOnShow(this.isScrollToBottomOnShow()),this._menu.toggleFor(t,e.source.getViewportRect(this),this.resolveMenuItems()))}resolveMenuItems(){let e=this.getMenuItems();return typeof e==`function`?e():e??[]}});export{i as t};
2
+ //# sourceMappingURL=MenuButton-C79l8Ysf.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MenuButton-Bjm1OyB-.js","names":[],"sources":["../../src/typescript/lib/component/button/MenuButton.ts"],"sourcesContent":["// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0\n\nimport { Button, ButtonOptions } from \"~/component/button/Button.js\";\nimport { DOM } from \"~/core/DOM.js\";\nimport { Menu } from \"~/overlay/Menu.js\";\nimport { MenuItemConfig } from \"~/component/container/MenuItem.js\";\nimport { callable } from \"~/core/Callable.js\";\n\n/**\n * Construction-time options for {@link MenuButton}.\n *\n * @category Components\n */\nexport interface MenuButtonOptions extends ButtonOptions {\n /** Items for the dropdown, or a provider re-invoked on every open. */\n menuItems?: MenuItemConfig[] | (() => MenuItemConfig[]);\n /** Open the menu scrolled to the bottom of its item list. Default `false`. */\n scrollToBottomOnShow?: boolean;\n}\n\n/**\n * A push button whose click toggles a rebuild-mode dropdown [`Menu`](/api/overlay/classes/Menu)\n * anchored under its bottom-left corner. The menu opens below the button, and\n * flips above it when the room below is short — see\n * [`Menu.toggleFor`](/api/overlay/classes/Menu#togglefor). A provider resolving\n * to an empty item list opens nothing (the click is a no-op beyond the\n * `\"action\"` event still firing).\n *\n * The dropdown panel is created lazily on first open and reused across opens;\n * `menuItems` accepts either a fixed array or a provider function, and the\n * provider is re-invoked on every open so its output (e.g. relative\n * timestamps, current record counts) is always current.\n *\n * @example\n * ```typescript\n * import { MenuButton } from '@jimka/typescript-ui/component/button';\n *\n * const exportBtn = MenuButton({\n * glyph: 'file-export',\n * menuItems: [\n * { text: 'Export as CSV', action: () => exportCsv() },\n * { text: 'Export as JSON', action: () => exportJson() },\n * ],\n * });\n * toolbar.addComponent(exportBtn);\n * ```\n *\n * @category Components\n */\nclass MenuButton<TOptions extends MenuButtonOptions = MenuButtonOptions> extends Button<TOptions> {\n\n // Lazily created on first open and reused across opens; a rebuild-mode Menu\n // rebuilds its items on every toggle, so a provider's output is always current.\n private _menu: Menu | null = null;\n\n private readonly _boundToggleMenu: () => void = () => { this.toggleMenu(); };\n\n /**\n * Constructs a MenuButton with an optional title and options bag (both\n * optional — an empty MenuButton renders as a chrome-shaped placeholder).\n *\n * @example\n * ```typescript\n * new MenuButton('Export', { menuItems: [ … ] });\n * MenuButton({ glyph: 'file-export', menuItems: [ … ] });\n * ```\n */\n constructor(text?: string, options?: TOptions, subclassDefaults?: Partial<TOptions>);\n constructor(options: TOptions);\n constructor(\n textOrOptions?: string | TOptions,\n options?: TOptions,\n subclassDefaults?: Partial<TOptions>,\n ) {\n // Normalise the overload: a non-string first argument is the options bag.\n // Copied from Button.ts:437-443 in shape. Legal before super() because it\n // touches no `this` (TS >= 4.6); the field initializers still run after\n // super() returns.\n let text: string | undefined;\n\n if (typeof textOrOptions === \"string\") {\n text = textOrOptions;\n } else if (textOrOptions !== undefined) {\n options = textOrOptions;\n }\n\n super(text, options, subclassDefaults);\n\n this.on(\"action\", this._boundToggleMenu);\n\n // Button wires the listener bag only when it is the directly-constructed\n // class; mirror its instance-identity guard so a MenuButton subclass wires\n // its own bag once, from its own constructor.\n if (Object.getPrototypeOf(this) === MenuButton.prototype) {\n this.applyListeners(options?.listeners);\n }\n }\n\n /**\n * Replaces the configured dropdown items — a fixed array, or a provider\n * re-invoked on every open.\n *\n * @param items - The new item configurations or provider.\n *\n * @returns This button, for method chaining.\n */\n setMenuItems(items: MenuItemConfig[] | (() => MenuItemConfig[])): this {\n this._options.menuItems = items;\n\n return this;\n }\n\n /**\n * Returns the configured dropdown items or provider — the caller value,\n * else the class default, else `null` when neither is set.\n *\n * @returns The configured items/provider, or `null`.\n */\n getMenuItems(): MenuItemConfig[] | (() => MenuItemConfig[]) | null {\n return this._options.menuItems ?? this._defaultOptions.menuItems ?? null;\n }\n\n /**\n * Returns whether the menu opens scrolled to the bottom of its item list —\n * the caller value, else the class default, else `false`.\n *\n * @returns Whether the menu opens scrolled to the bottom.\n */\n isScrollToBottomOnShow(): boolean {\n return this._options.scrollToBottomOnShow ?? this._defaultOptions.scrollToBottomOnShow ?? false;\n }\n\n /**\n * Applies a {@link MenuButtonOptions} bag, dispatching `menuItems` after\n * the inherited Button fields cascade.\n *\n * @param options - The options bag carrying the values to apply.\n *\n * @returns This button, for method chaining.\n */\n protected applyOptions(options: TOptions): this {\n super.applyOptions(options);\n\n if (options.menuItems !== undefined) {\n this.setMenuItems(options.menuItems);\n }\n\n // No setter: a construction-time-only option read once when the lazy\n // Menu is created, so a pure bag write is all that is needed.\n if (options.scrollToBottomOnShow !== undefined) {\n this._options.scrollToBottomOnShow = options.scrollToBottomOnShow;\n }\n\n return this;\n }\n\n /**\n * Toggles the menu anchored under the button's bottom-left corner, flipping\n * above the button when the room below is short. No-op when the button is not\n * yet attached (no anchor rect to read), or when the items resolve to an empty\n * list — `Menu.toggleFor` owns that suppression, so no check is needed here.\n */\n private toggleMenu(): void {\n const el = this.getElement();\n\n if (!el) {\n return;\n }\n\n this._menu ??= new Menu().setScrollToBottomOnShow(this.isScrollToBottomOnShow());\n\n // Items are resolved eagerly as an argument, so a provider re-runs on\n // every toggle — including a toggle that only closes the menu, whose\n // result Menu.toggleFor discards. Keeping toggleFor the single source of\n // truth for open-vs-close is worth that spare provider call; the\n // alternative (asking the menu whether it is open before resolving)\n // reintroduces the open-state desync toggleFor exists to avoid.\n this._menu.toggleFor(el, DOM.source.getViewportRect(this), this.resolveMenuItems());\n }\n\n /** Resolves the configured items — invoking the provider form on every open. */\n private resolveMenuItems(): MenuItemConfig[] {\n const items = this.getMenuItems();\n\n if (typeof items === \"function\") {\n return items();\n }\n\n return items ?? [];\n }\n}\n\nconst MenuButtonCallable = callable(MenuButton);\ntype MenuButtonCallable<TOptions extends MenuButtonOptions = MenuButtonOptions> = MenuButton<TOptions>;\nexport {\n MenuButton as _MenuButton,\n MenuButtonCallable as MenuButton,\n};\n"],"mappings":"kKAgMA,IAAM,EAAqB,EAAS,MA/I9B,mBAA2E,CAAiB,CAI9F,MAA6B,KAE7B,qBAAsD,CAAE,KAAK,WAAW,CAAG,EAc3E,YACI,EACA,EACA,EACF,CAKE,IAAI,EAEA,OAAO,GAAkB,SACzB,EAAO,EACA,IAAkB,IAAA,KACzB,EAAU,GAGd,MAAM,EAAM,EAAS,CAAgB,EAErC,KAAK,GAAG,SAAU,KAAK,gBAAgB,EAKnC,OAAO,eAAe,IAAI,IAAM,WAAW,WAC3C,KAAK,eAAe,GAAS,SAAS,CAE9C,CAUA,aAAa,EAA0D,CAGnE,MAFA,MAAK,SAAS,UAAY,EAEnB,IACX,CAQA,cAAmE,CAC/D,OAAO,KAAK,SAAS,WAAa,KAAK,gBAAgB,WAAa,IACxE,CAQA,wBAAkC,CAC9B,OAAO,KAAK,SAAS,sBAAwB,KAAK,gBAAgB,sBAAwB,EAC9F,CAUA,aAAuB,EAAyB,CAa5C,OAZA,MAAM,aAAa,CAAO,EAEtB,EAAQ,YAAc,IAAA,IACtB,KAAK,aAAa,EAAQ,SAAS,EAKnC,EAAQ,uBAAyB,IAAA,KACjC,KAAK,SAAS,qBAAuB,EAAQ,sBAG1C,IACX,CAQA,YAA2B,CACvB,IAAM,EAAK,KAAK,WAAW,EAEtB,IAIL,KAAK,QAAU,IAAI,EAAK,CAAC,CAAC,wBAAwB,KAAK,uBAAuB,CAAC,EAQ/E,KAAK,MAAM,UAAU,EAAI,EAAI,OAAO,gBAAgB,IAAI,EAAG,KAAK,iBAAiB,CAAC,EACtF,CAGA,kBAA6C,CACzC,IAAM,EAAQ,KAAK,aAAa,EAMhC,OAJI,OAAO,GAAU,WACV,EAAM,EAGV,GAAS,CAAC,CACrB,CACJ,CAE8C"}
1
+ {"version":3,"file":"MenuButton-C79l8Ysf.js","names":[],"sources":["../../src/typescript/lib/component/button/MenuButton.ts"],"sourcesContent":["// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0\n\nimport { Button, ButtonOptions } from \"~/component/button/Button.js\";\nimport { DOM } from \"~/core/DOM.js\";\nimport { Menu } from \"~/overlay/Menu.js\";\nimport { MenuItemConfig } from \"~/component/container/MenuItem.js\";\nimport { callable } from \"~/core/Callable.js\";\n\n/**\n * Construction-time options for {@link MenuButton}.\n *\n * @category Components\n */\nexport interface MenuButtonOptions extends ButtonOptions {\n /** Items for the dropdown, or a provider re-invoked on every open. */\n menuItems?: MenuItemConfig[] | (() => MenuItemConfig[]);\n /** Open the menu scrolled to the bottom of its item list. Default `false`. */\n scrollToBottomOnShow?: boolean;\n}\n\n/**\n * A push button whose click toggles a rebuild-mode dropdown [`Menu`](/api/overlay/classes/Menu)\n * anchored under its bottom-left corner. The menu opens below the button, and\n * flips above it when the room below is short — see\n * [`Menu.toggleFor`](/api/overlay/classes/Menu#togglefor). A provider resolving\n * to an empty item list opens nothing (the click is a no-op beyond the\n * `\"action\"` event still firing).\n *\n * The dropdown panel is created lazily on first open and reused across opens;\n * `menuItems` accepts either a fixed array or a provider function, and the\n * provider is re-invoked on every open so its output (e.g. relative\n * timestamps, current record counts) is always current.\n *\n * @example\n * ```typescript\n * import { MenuButton } from '@jimka/typescript-ui/component/button';\n *\n * const exportBtn = MenuButton({\n * glyph: 'file-export',\n * menuItems: [\n * { text: 'Export as CSV', action: () => exportCsv() },\n * { text: 'Export as JSON', action: () => exportJson() },\n * ],\n * });\n * toolbar.addComponent(exportBtn);\n * ```\n *\n * @category Components\n */\nclass MenuButton<TOptions extends MenuButtonOptions = MenuButtonOptions> extends Button<TOptions> {\n\n // Lazily created on first open and reused across opens; a rebuild-mode Menu\n // rebuilds its items on every toggle, so a provider's output is always current.\n private _menu: Menu | null = null;\n\n private readonly _boundToggleMenu: () => void = () => { this.toggleMenu(); };\n\n /**\n * Constructs a MenuButton with an optional title and options bag (both\n * optional — an empty MenuButton renders as a chrome-shaped placeholder).\n *\n * @example\n * ```typescript\n * new MenuButton('Export', { menuItems: [ … ] });\n * MenuButton({ glyph: 'file-export', menuItems: [ … ] });\n * ```\n */\n constructor(text?: string, options?: TOptions, subclassDefaults?: Partial<TOptions>);\n constructor(options: TOptions);\n constructor(\n textOrOptions?: string | TOptions,\n options?: TOptions,\n subclassDefaults?: Partial<TOptions>,\n ) {\n // Normalise the overload: a non-string first argument is the options bag.\n // Copied from Button.ts:437-443 in shape. Legal before super() because it\n // touches no `this` (TS >= 4.6); the field initializers still run after\n // super() returns.\n let text: string | undefined;\n\n if (typeof textOrOptions === \"string\") {\n text = textOrOptions;\n } else if (textOrOptions !== undefined) {\n options = textOrOptions;\n }\n\n super(text, options, subclassDefaults);\n\n this.on(\"action\", this._boundToggleMenu);\n\n // Button wires the listener bag only when it is the directly-constructed\n // class; mirror its instance-identity guard so a MenuButton subclass wires\n // its own bag once, from its own constructor.\n if (Object.getPrototypeOf(this) === MenuButton.prototype) {\n this.applyListeners(options?.listeners);\n }\n }\n\n /**\n * Replaces the configured dropdown items — a fixed array, or a provider\n * re-invoked on every open.\n *\n * @param items - The new item configurations or provider.\n *\n * @returns This button, for method chaining.\n */\n setMenuItems(items: MenuItemConfig[] | (() => MenuItemConfig[])): this {\n this._options.menuItems = items;\n\n return this;\n }\n\n /**\n * Returns the configured dropdown items or provider — the caller value,\n * else the class default, else `null` when neither is set.\n *\n * @returns The configured items/provider, or `null`.\n */\n getMenuItems(): MenuItemConfig[] | (() => MenuItemConfig[]) | null {\n return this._options.menuItems ?? this._defaultOptions.menuItems ?? null;\n }\n\n /**\n * Returns whether the menu opens scrolled to the bottom of its item list —\n * the caller value, else the class default, else `false`.\n *\n * @returns Whether the menu opens scrolled to the bottom.\n */\n isScrollToBottomOnShow(): boolean {\n return this._options.scrollToBottomOnShow ?? this._defaultOptions.scrollToBottomOnShow ?? false;\n }\n\n /**\n * Applies a {@link MenuButtonOptions} bag, dispatching `menuItems` after\n * the inherited Button fields cascade.\n *\n * @param options - The options bag carrying the values to apply.\n *\n * @returns This button, for method chaining.\n */\n protected applyOptions(options: TOptions): this {\n super.applyOptions(options);\n\n if (options.menuItems !== undefined) {\n this.setMenuItems(options.menuItems);\n }\n\n // No setter: a construction-time-only option read once when the lazy\n // Menu is created, so a pure bag write is all that is needed.\n if (options.scrollToBottomOnShow !== undefined) {\n this._options.scrollToBottomOnShow = options.scrollToBottomOnShow;\n }\n\n return this;\n }\n\n /**\n * Toggles the menu anchored under the button's bottom-left corner, flipping\n * above the button when the room below is short. No-op when the button is not\n * yet attached (no anchor rect to read), or when the items resolve to an empty\n * list — `Menu.toggleFor` owns that suppression, so no check is needed here.\n */\n private toggleMenu(): void {\n const el = this.getElement();\n\n if (!el) {\n return;\n }\n\n this._menu ??= new Menu().setScrollToBottomOnShow(this.isScrollToBottomOnShow());\n\n // Items are resolved eagerly as an argument, so a provider re-runs on\n // every toggle — including a toggle that only closes the menu, whose\n // result Menu.toggleFor discards. Keeping toggleFor the single source of\n // truth for open-vs-close is worth that spare provider call; the\n // alternative (asking the menu whether it is open before resolving)\n // reintroduces the open-state desync toggleFor exists to avoid.\n this._menu.toggleFor(el, DOM.source.getViewportRect(this), this.resolveMenuItems());\n }\n\n /** Resolves the configured items — invoking the provider form on every open. */\n private resolveMenuItems(): MenuItemConfig[] {\n const items = this.getMenuItems();\n\n if (typeof items === \"function\") {\n return items();\n }\n\n return items ?? [];\n }\n}\n\nconst MenuButtonCallable = callable(MenuButton);\ntype MenuButtonCallable<TOptions extends MenuButtonOptions = MenuButtonOptions> = MenuButton<TOptions>;\nexport {\n MenuButton as _MenuButton,\n MenuButtonCallable as MenuButton,\n};\n"],"mappings":"kKAgMA,IAAM,EAAqB,EAAS,MA/I9B,mBAA2E,CAAiB,CAI9F,MAA6B,KAE7B,qBAAsD,CAAE,KAAK,WAAW,CAAG,EAc3E,YACI,EACA,EACA,EACF,CAKE,IAAI,EAEA,OAAO,GAAkB,SACzB,EAAO,EACA,IAAkB,IAAA,KACzB,EAAU,GAGd,MAAM,EAAM,EAAS,CAAgB,EAErC,KAAK,GAAG,SAAU,KAAK,gBAAgB,EAKnC,OAAO,eAAe,IAAI,IAAM,WAAW,WAC3C,KAAK,eAAe,GAAS,SAAS,CAE9C,CAUA,aAAa,EAA0D,CAGnE,MAFA,MAAK,SAAS,UAAY,EAEnB,IACX,CAQA,cAAmE,CAC/D,OAAO,KAAK,SAAS,WAAa,KAAK,gBAAgB,WAAa,IACxE,CAQA,wBAAkC,CAC9B,OAAO,KAAK,SAAS,sBAAwB,KAAK,gBAAgB,sBAAwB,EAC9F,CAUA,aAAuB,EAAyB,CAa5C,OAZA,MAAM,aAAa,CAAO,EAEtB,EAAQ,YAAc,IAAA,IACtB,KAAK,aAAa,EAAQ,SAAS,EAKnC,EAAQ,uBAAyB,IAAA,KACjC,KAAK,SAAS,qBAAuB,EAAQ,sBAG1C,IACX,CAQA,YAA2B,CACvB,IAAM,EAAK,KAAK,WAAW,EAEtB,IAIL,KAAK,QAAU,IAAI,EAAK,CAAC,CAAC,wBAAwB,KAAK,uBAAuB,CAAC,EAQ/E,KAAK,MAAM,UAAU,EAAI,EAAI,OAAO,gBAAgB,IAAI,EAAG,KAAK,iBAAiB,CAAC,EACtF,CAGA,kBAA6C,CACzC,IAAM,EAAQ,KAAK,aAAa,EAMhC,OAJI,OAAO,GAAU,WACV,EAAM,EAGV,GAAS,CAAC,CACrB,CACJ,CAE8C"}
@@ -1,2 +1,2 @@
1
- import{t as e}from"./DOM-BeR95tE8.js";import{n as t}from"./Position-DRSlWn4Z.js";import{m as n,v as r,x as i,y as a}from"./Component-CHTzJxEf.js";import{i as o,n as s,r as c,t as l}from"./Scrollbar-CiVV3axj.js";import{t as u}from"./Container-xUbHk6l_.js";var d={tag:`div`,insets:new t(4,4,4,4),autoScroll:`none`,scrollShadows:!0,scrollbarStyle:`overlay`},f=`PanelOverlayScroller`,p=null;function ensureOverlayScrollerClassRule(){p||=[new a({scope:`class`,name:f,styles:{scrollbarWidth:`none`}}),new a({scope:`selector`,name:`.${f}::-webkit-scrollbar`,styles:{display:`none`}})]}var Panel=class extends u{_shadowOverlayStyle=new r;_lastChildCount=0;_overlayScrollStyle=new r;_onOverlayScrollV=e=>{this.setScrollTop(e)};_onOverlayScrollH=e=>{this.setScrollLeft(e)};constructor(e,n){let r=e?.flush?{insets:new t(0,0,0,0)}:{};super(e,{...d,...n??{},...r})}applyOptions(e){return super.applyOptions(e),this.setScrollbarGutter(0,0),this._shadowEdges={top:0,bottom:0,left:0,right:0},this._lastContentExtent={width:0,height:0},this.setAutoScroll(e.autoScroll??this.getAutoScroll()),this._shadowOverlay=null,this._shadowScrollHandler=null,this.setScrollShadows(e.scrollShadows??this.getScrollShadows()),this._overlayScrollElement=null,this._scrollbarV=null,this._scrollbarH=null,this._overlayScrollHandler=null,this.setScrollbarStyle(e.scrollbarStyle??this.getScrollbarStyle()),this}setAutoScroll(e){switch(this._autoScroll=e,e){case`none`:this.setOverflowX(`hidden`).setOverflowY(`hidden`);break;case`auto`:this.setOverflowX(`auto`).setOverflowY(`auto`);break;case`x`:this.setOverflowX(`auto`).setOverflowY(`hidden`);break;case`y`:this.setOverflowX(`hidden`).setOverflowY(`auto`);break;case`both`:this.setOverflowX(`scroll`).setOverflowY(`scroll`);break}e===`none`&&(this._scrollbarGutter.right!==0||this._scrollbarGutter.bottom!==0)&&this.setScrollbarGutter(0,0);let t=this.scrollableAxes();return this.getLayoutManager()?.setOverflowing(t.x,t.y),this.refreshOverlayScrollbars(),this.refreshScrollShadows(),this}setLayoutManager(e){return super.setLayoutManager(e),this.setAutoScroll(this._autoScroll),this}getAutoScroll(){return this._autoScroll??this._defaultOptions.autoScroll}clearAutoScroll(){return this.setAutoScroll(`none`)}setScrollShadows(e){return this._scrollShadows=e,this.refreshScrollShadows(),this}getScrollShadows(){return this._scrollShadows??this._defaultOptions.scrollShadows}setScrollbarStyle(e){return this._scrollbarStyle=e,this.refreshOverlayScrollbars(),this.refreshScrollShadows(),this}getScrollbarStyle(){return this._scrollbarStyle??this._defaultOptions.scrollbarStyle}getScrollElement(){return this._overlayScrollElement??this.getElement()}getInnerSize(){let e=super.getInnerSize();return e?{width:e.width-this._scrollbarGutter.right,height:e.height-this._scrollbarGutter.bottom}:null}doLayout(){return super.doLayout(),this.commitElementStyle(),this.resizeScrollShadowOverlay(),this.measureScrollbarGutter(),this.updateScrollShadows(),this.scheduleGutterSettleOnShrink(),this}scheduleGutterSettleOnShrink(){if(this._autoScroll===`none`)return;let e=this.getComponents().length,t=e<this._lastChildCount;this._lastChildCount=e;let n=!1;if(this.showsScrollAffordance()){let e=this.getPreferredSize(),t=e?e.width:0,r=e?e.height:0;n=t<this._lastContentExtent.width||r<this._lastContentExtent.height,this._lastContentExtent={width:t,height:r}}(t||n)&&this.scheduleLayout()}showsScrollAffordance(){return this._scrollbarGutter.right>0||this._scrollbarGutter.bottom>0||this._shadowEdges.top>0||this._shadowEdges.bottom>0||this._shadowEdges.left>0||this._shadowEdges.right>0}init(e){super.init(e);let t=e??this.getElement();return t&&this._scrollbarStyle===`overlay`&&this._autoScroll!==`none`&&(this.installOverlayScrollbars(t),this.layoutOverlayScrollbars(t)),t&&this._scrollShadows&&this._autoScroll!==`none`&&(this.installScrollShadows(t),this.updateScrollShadows(t)),this}destructor(){this.removeScrollShadows(),this.removeOverlayScrollbars(),super.destructor()}scrollableAxes(){let e=this._autoScroll;return{x:e===`x`||e===`auto`||e===`both`,y:e===`y`||e===`auto`||e===`both`}}setScrollbarGutter(e,t){this._scrollbarGutter={right:e,bottom:t}}measureScrollbarGutter(){if(this._autoScroll===`none`)return;if(this._scrollbarStyle===`overlay`){this.layoutOverlayScrollbars();return}let t=this.getElement();if(!t)return;let n=e.source.getScrollBarWidth();if(n===0)return;let r,i;if(this._autoScroll===`both`)r=!0,i=!0;else{let n=this.scrollableAxes(),a=e.source.getScrollMetrics(t);r=n.y&&a.scrollHeight>a.clientHeight,i=n.x&&a.scrollWidth>a.clientWidth}let a=r?n:0,o=i?n:0;a===this._scrollbarGutter.right&&o===this._scrollbarGutter.bottom||(this.setScrollbarGutter(a,o),this.scheduleLayout())}refreshScrollShadows(){if(!this._scrollShadows||this._autoScroll===`none`){this.removeScrollShadows();return}let e=this.getElement();e&&(this.installScrollShadows(e),this.updateScrollShadows(e))}installScrollShadows(e){if(this._shadowOverlay||this.createScrollShadowOverlay(e),!this._shadowScrollHandler){let handler=()=>{this.updateScrollShadows()};this._shadowScrollHandler=handler,i.addSubtreeListener(this,`scroll`,handler)}}createScrollShadowOverlay(t){let n=e.sink.createElement(`div`);this._shadowOverlayStyle.attach(n),this._shadowOverlayStyle.setMany({position:`sticky`,left:`0px`,top:`0px`,pointerEvents:`none`,zIndex:`1`,boxShadow:s()}),e.sink.appendChild(t,n),this.trackHandle(n),this._shadowOverlay=n}removeScrollShadows(){this._shadowScrollHandler&&=(i.removeSubtreeListener(this,`scroll`,this._shadowScrollHandler),null),this._shadowOverlay&&(e.sink.removeElement(this._shadowOverlay),this.untrackHandle(this._shadowOverlay),e.sink.release(this._shadowOverlay),this._shadowOverlay=null,this._shadowOverlayStyle=new r),this._shadowEdges={top:0,bottom:0,left:0,right:0}}resizeScrollShadowOverlay(t){let n=t??this.getElement();if(!n||!this._shadowOverlay)return;let{clientWidth:r,clientHeight:i}=e.source.getScrollMetrics(n),a=this._scrollbarStyle===`overlay`?this._scrollbarGutter.right:0,o=this._scrollbarStyle===`overlay`?this._scrollbarGutter.bottom:0;this._shadowOverlayStyle.setMany({width:r-a+`px`,height:i-o+`px`})}updateScrollShadows(t){let n=t??this.getElement();if(!n||!this._shadowOverlay)return;let{scrollTop:r,scrollLeft:i,scrollWidth:a,scrollHeight:s,clientWidth:c,clientHeight:l}=e.source.getScrollMetrics(this.getScrollElement()??n);this.resizeScrollShadowOverlay(n);let u=s-l,d=a-c,f=o,p=this.scrollableAxes();this.setShadowEdge(`top`,`--ts-ss-top`,p.y?f(r):0),this.setShadowEdge(`bottom`,`--ts-ss-bottom`,p.y?f(u-r):0),this.setShadowEdge(`left`,`--ts-ss-left`,p.x?f(i):0),this.setShadowEdge(`right`,`--ts-ss-right`,p.x?f(d-i):0)}setShadowEdge(e,t,n){let r=Math.round(n*100);this._shadowEdges[e]!==r&&(this._shadowEdges[e]=r,this._shadowOverlayStyle.set(t,c(r)))}refreshOverlayScrollbars(){if(this._scrollbarStyle!==`overlay`||this._autoScroll===`none`){this.removeOverlayScrollbars();return}let e=this.getElement();e&&(this.installOverlayScrollbars(e),this.layoutOverlayScrollbars(e))}installOverlayScrollbars(t){if(!this._overlayScrollElement){ensureOverlayScrollerClassRule();let n=e.sink.createElement(`div`);this._overlayScrollStyle.attach(n),this._overlayScrollStyle.setMany({position:`absolute`,left:`0px`,top:`0px`,width:`100%`,height:`100%`}),e.sink.apply(n,{addClass:[f]}),e.sink.appendChild(t,n),this.reparentContent(t,n),this.trackHandle(n),this._overlayScrollElement=n}let n=this.scrollableAxes();if(this._overlayScrollStyle.setMany({overflowX:n.x?`auto`:`hidden`,overflowY:n.y?`auto`:`hidden`}),this._scrollbarV||(this._scrollbarV=new l(`vertical`),this._scrollbarV.setZIndex(2),e.sink.appendChild(t,this._scrollbarV.getElement(!0)),this._scrollbarV.on(`scroll`,this._onOverlayScrollV)),this._scrollbarH||(this._scrollbarH=new l(`horizontal`),this._scrollbarH.setZIndex(2),e.sink.appendChild(t,this._scrollbarH.getElement(!0)),this._scrollbarH.on(`scroll`,this._onOverlayScrollH)),!this._overlayScrollHandler){let handler=()=>{this.syncOverlayScrollbars()};this._overlayScrollHandler=handler,i.addSubtreeListener(this,`scroll`,handler)}this.setNativeScrollbarHidden(!0)}removeOverlayScrollbars(){if(this._overlayScrollHandler&&=(i.removeSubtreeListener(this,`scroll`,this._overlayScrollHandler),null),this._scrollbarV&&=(this._scrollbarV.off(`scroll`,this._onOverlayScrollV),this._scrollbarV.removeElement(),null),this._scrollbarH&&=(this._scrollbarH.off(`scroll`,this._onOverlayScrollH),this._scrollbarH.removeElement(),null),this._overlayScrollElement){let t=this.getElement();t&&this.reparentContent(this._overlayScrollElement,t),e.sink.removeElement(this._overlayScrollElement),this.untrackHandle(this._overlayScrollElement),e.sink.release(this._overlayScrollElement),this._overlayScrollElement=null,this._overlayScrollStyle=new r}this.setNativeScrollbarHidden(!1),this.setScrollbarGutter(0,0)}setNativeScrollbarHidden(e){this.setElementCSSRule(`scrollbarWidth`,e?`none`:null),this.createStyleRule(`::-webkit-scrollbar`).set(`display`,e?`none`:null)}layoutOverlayScrollbars(t){let n=t??this.getElement(),r=this._overlayScrollElement;if(!n||!r||!this._scrollbarV||!this._scrollbarH)return;let i=this._scrollbarV.getTrackWidth(),a=e.source.getScrollMetrics(n),o=a.clientWidth,s=a.clientHeight,c=this._scrollbarGutter.right,l=this._scrollbarGutter.bottom;this._overlayScrollStyle.setMany({width:o-c+`px`,height:s-l+`px`});let u=e.source.getScrollMetrics(r),d=this.scrollableAxes(),f=d.y&&u.scrollHeight>u.clientHeight,p=d.x&&u.scrollWidth>u.clientWidth,m=o-(f?i:0),h=s-(p?i:0);(m!==o-c||h!==s-l)&&this._overlayScrollStyle.setMany({width:m+`px`,height:h+`px`}),this._scrollbarV.setX(m),this._scrollbarV.setY(0),this._scrollbarV.setHeight(h),this._scrollbarV.setMetrics(h,u.scrollHeight,u.scrollTop),this._scrollbarH.setX(0),this._scrollbarH.setY(h),this._scrollbarH.setWidth(m),this._scrollbarH.setMetrics(m,u.scrollWidth,u.scrollLeft);let g=f?i:0,_=p?i:0;(g!==c||_!==l)&&(this.setScrollbarGutter(g,_),this.scheduleLayout())}syncOverlayScrollbars(){let t=this._overlayScrollElement;if(!t||!this._scrollbarV||!this._scrollbarH)return;let n=e.source.getScrollMetrics(t);this._scrollbarV.setMetrics(n.clientHeight,n.scrollHeight,n.scrollTop),this._scrollbarH.setMetrics(n.clientWidth,n.scrollWidth,n.scrollLeft)}},m=n(Panel);export{m as t};
2
- //# sourceMappingURL=Panel-D9lTLGqP.js.map
1
+ import{t as e}from"./DOM-67StIm5G.js";import{n as t}from"./Position-Ck_KD4cR.js";import{S as n,b as r,h as i,y as a}from"./Component-DHqrPwAw.js";import{i as o,n as s,r as c,t as l}from"./Scrollbar-CSFK-Y57.js";import{t as u}from"./Container-CAQpj4yb.js";var d={tag:`div`,insets:new t(4,4,4,4),autoScroll:`none`,scrollShadows:!0,scrollbarStyle:`overlay`},f=`PanelOverlayScroller`,p=null;function ensureOverlayScrollerClassRule(){p||=[new r({scope:`class`,name:f,styles:{scrollbarWidth:`none`}}),new r({scope:`selector`,name:`.${f}::-webkit-scrollbar`,styles:{display:`none`}})]}var Panel=class extends u{_shadowOverlayStyle=new a;_lastChildCount=0;_overlayScrollStyle=new a;_onOverlayScrollV=e=>{this.setScrollTop(e)};_onOverlayScrollH=e=>{this.setScrollLeft(e)};constructor(e,n){let r=e?.flush?{insets:new t(0,0,0,0)}:{};super(e,{...d,...n??{},...r})}applyOptions(e){return super.applyOptions(e),this.setScrollbarGutter(0,0),this._shadowEdges={top:0,bottom:0,left:0,right:0},this._lastContentExtent={width:0,height:0},this.setAutoScroll(e.autoScroll??this.getAutoScroll()),this._shadowOverlay=null,this._shadowScrollHandler=null,this.setScrollShadows(e.scrollShadows??this.getScrollShadows()),this._overlayScrollElement=null,this._scrollbarV=null,this._scrollbarH=null,this._overlayScrollHandler=null,this.setScrollbarStyle(e.scrollbarStyle??this.getScrollbarStyle()),this}setAutoScroll(e){switch(this._autoScroll=e,e){case`none`:this.setOverflowX(`hidden`).setOverflowY(`hidden`);break;case`auto`:this.setOverflowX(`auto`).setOverflowY(`auto`);break;case`x`:this.setOverflowX(`auto`).setOverflowY(`hidden`);break;case`y`:this.setOverflowX(`hidden`).setOverflowY(`auto`);break;case`both`:this.setOverflowX(`scroll`).setOverflowY(`scroll`);break}e===`none`&&(this._scrollbarGutter.right!==0||this._scrollbarGutter.bottom!==0)&&this.setScrollbarGutter(0,0);let t=this.scrollableAxes();return this.getLayoutManager()?.setOverflowing(t.x,t.y),this.refreshOverlayScrollbars(),this.refreshScrollShadows(),this}setLayoutManager(e){return super.setLayoutManager(e),this.setAutoScroll(this._autoScroll),this}getAutoScroll(){return this._autoScroll??this._defaultOptions.autoScroll}clearAutoScroll(){return this.setAutoScroll(`none`)}setScrollShadows(e){return this._scrollShadows=e,this.refreshScrollShadows(),this}getScrollShadows(){return this._scrollShadows??this._defaultOptions.scrollShadows}setScrollbarStyle(e){return this._scrollbarStyle=e,this.refreshOverlayScrollbars(),this.refreshScrollShadows(),this}getScrollbarStyle(){return this._scrollbarStyle??this._defaultOptions.scrollbarStyle}getScrollElement(){return this._overlayScrollElement??this.getElement()}getInnerSize(){let e=super.getInnerSize();return e?{width:e.width-this._scrollbarGutter.right,height:e.height-this._scrollbarGutter.bottom}:null}doLayout(){return super.doLayout(),this.commitElementStyle(),this.resizeScrollShadowOverlay(),this.measureScrollbarGutter(),this.updateScrollShadows(),this.scheduleGutterSettleOnShrink(),this}scheduleGutterSettleOnShrink(){if(this._autoScroll===`none`)return;let e=this.getComponents().length,t=e<this._lastChildCount;this._lastChildCount=e;let n=!1;if(this.showsScrollAffordance()){let e=this.getPreferredSize(),t=e?e.width:0,r=e?e.height:0;n=t<this._lastContentExtent.width||r<this._lastContentExtent.height,this._lastContentExtent={width:t,height:r}}(t||n)&&this.scheduleLayout()}showsScrollAffordance(){return this._scrollbarGutter.right>0||this._scrollbarGutter.bottom>0||this._shadowEdges.top>0||this._shadowEdges.bottom>0||this._shadowEdges.left>0||this._shadowEdges.right>0}init(e){super.init(e);let t=e??this.getElement();return t&&this._scrollbarStyle===`overlay`&&this._autoScroll!==`none`&&(this.installOverlayScrollbars(t),this.layoutOverlayScrollbars(t)),t&&this._scrollShadows&&this._autoScroll!==`none`&&(this.installScrollShadows(t),this.updateScrollShadows(t)),this}destructor(){this.removeScrollShadows(),this.removeOverlayScrollbars(),super.destructor()}scrollableAxes(){let e=this._autoScroll;return{x:e===`x`||e===`auto`||e===`both`,y:e===`y`||e===`auto`||e===`both`}}setScrollbarGutter(e,t){this._scrollbarGutter={right:e,bottom:t}}measureScrollbarGutter(){if(this._autoScroll===`none`)return;if(this._scrollbarStyle===`overlay`){this.layoutOverlayScrollbars();return}let t=this.getElement();if(!t)return;let n=e.source.getScrollBarWidth();if(n===0)return;let r,i;if(this._autoScroll===`both`)r=!0,i=!0;else{let n=this.scrollableAxes(),a=e.source.getScrollMetrics(t);r=n.y&&a.scrollHeight>a.clientHeight,i=n.x&&a.scrollWidth>a.clientWidth}let a=r?n:0,o=i?n:0;a===this._scrollbarGutter.right&&o===this._scrollbarGutter.bottom||(this.setScrollbarGutter(a,o),this.scheduleLayout())}refreshScrollShadows(){if(!this._scrollShadows||this._autoScroll===`none`){this.removeScrollShadows();return}let e=this.getElement();e&&(this.installScrollShadows(e),this.updateScrollShadows(e))}installScrollShadows(e){if(this._shadowOverlay||this.createScrollShadowOverlay(e),!this._shadowScrollHandler){let handler=()=>{this.updateScrollShadows()};this._shadowScrollHandler=handler,n.addSubtreeListener(this,`scroll`,handler)}}createScrollShadowOverlay(t){let n=e.sink.createElement(`div`);this._shadowOverlayStyle.attach(n),this._shadowOverlayStyle.setMany({position:`sticky`,left:`0px`,top:`0px`,pointerEvents:`none`,zIndex:`1`,boxShadow:s()}),e.sink.appendChild(t,n),this.trackHandle(n),this._shadowOverlay=n}removeScrollShadows(){this._shadowScrollHandler&&=(n.removeSubtreeListener(this,`scroll`,this._shadowScrollHandler),null),this._shadowOverlay&&(e.sink.removeElement(this._shadowOverlay),this.untrackHandle(this._shadowOverlay),e.sink.release(this._shadowOverlay),this._shadowOverlay=null,this._shadowOverlayStyle=new a),this._shadowEdges={top:0,bottom:0,left:0,right:0}}resizeScrollShadowOverlay(t){let n=t??this.getElement();if(!n||!this._shadowOverlay)return;let{clientWidth:r,clientHeight:i}=e.source.getScrollMetrics(n),a=this._scrollbarStyle===`overlay`?this._scrollbarGutter.right:0,o=this._scrollbarStyle===`overlay`?this._scrollbarGutter.bottom:0;this._shadowOverlayStyle.setMany({width:r-a+`px`,height:i-o+`px`})}updateScrollShadows(t){let n=t??this.getElement();if(!n||!this._shadowOverlay)return;let{scrollTop:r,scrollLeft:i,scrollWidth:a,scrollHeight:s,clientWidth:c,clientHeight:l}=e.source.getScrollMetrics(this.getScrollElement()??n);this.resizeScrollShadowOverlay(n);let u=s-l,d=a-c,f=o,p=this.scrollableAxes();this.setShadowEdge(`top`,`--ts-ss-top`,p.y?f(r):0),this.setShadowEdge(`bottom`,`--ts-ss-bottom`,p.y?f(u-r):0),this.setShadowEdge(`left`,`--ts-ss-left`,p.x?f(i):0),this.setShadowEdge(`right`,`--ts-ss-right`,p.x?f(d-i):0)}setShadowEdge(e,t,n){let r=Math.round(n*100);this._shadowEdges[e]!==r&&(this._shadowEdges[e]=r,this._shadowOverlayStyle.set(t,c(r)))}refreshOverlayScrollbars(){if(this._scrollbarStyle!==`overlay`||this._autoScroll===`none`){this.removeOverlayScrollbars();return}let e=this.getElement();e&&(this.installOverlayScrollbars(e),this.layoutOverlayScrollbars(e))}installOverlayScrollbars(t){if(!this._overlayScrollElement){ensureOverlayScrollerClassRule();let n=e.sink.createElement(`div`);this._overlayScrollStyle.attach(n),this._overlayScrollStyle.setMany({position:`absolute`,left:`0px`,top:`0px`,width:`100%`,height:`100%`}),e.sink.apply(n,{addClass:[f]}),e.sink.appendChild(t,n),this.reparentContent(t,n),this.trackHandle(n),this._overlayScrollElement=n}let r=this.scrollableAxes();if(this._overlayScrollStyle.setMany({overflowX:r.x?`auto`:`hidden`,overflowY:r.y?`auto`:`hidden`}),this._scrollbarV||(this._scrollbarV=new l(`vertical`),this._scrollbarV.setZIndex(2),e.sink.appendChild(t,this._scrollbarV.getElement(!0)),this._scrollbarV.on(`scroll`,this._onOverlayScrollV)),this._scrollbarH||(this._scrollbarH=new l(`horizontal`),this._scrollbarH.setZIndex(2),e.sink.appendChild(t,this._scrollbarH.getElement(!0)),this._scrollbarH.on(`scroll`,this._onOverlayScrollH)),!this._overlayScrollHandler){let handler=()=>{this.syncOverlayScrollbars()};this._overlayScrollHandler=handler,n.addSubtreeListener(this,`scroll`,handler)}this.setNativeScrollbarHidden(!0)}removeOverlayScrollbars(){if(this._overlayScrollHandler&&=(n.removeSubtreeListener(this,`scroll`,this._overlayScrollHandler),null),this._scrollbarV&&=(this._scrollbarV.off(`scroll`,this._onOverlayScrollV),this._scrollbarV.dispose(),null),this._scrollbarH&&=(this._scrollbarH.off(`scroll`,this._onOverlayScrollH),this._scrollbarH.dispose(),null),this._overlayScrollElement){let t=this.getElement();t&&this.reparentContent(this._overlayScrollElement,t),e.sink.removeElement(this._overlayScrollElement),this.untrackHandle(this._overlayScrollElement),e.sink.release(this._overlayScrollElement),this._overlayScrollElement=null,this._overlayScrollStyle=new a}this.setNativeScrollbarHidden(!1),this.setScrollbarGutter(0,0)}setNativeScrollbarHidden(e){this.setElementCSSRule(`scrollbarWidth`,e?`none`:null),this.createStyleRule(`::-webkit-scrollbar`).set(`display`,e?`none`:null)}layoutOverlayScrollbars(t){let n=t??this.getElement(),r=this._overlayScrollElement;if(!n||!r||!this._scrollbarV||!this._scrollbarH)return;let i=this._scrollbarV.getTrackWidth(),a=e.source.getScrollMetrics(n),o=a.clientWidth,s=a.clientHeight,c=this._scrollbarGutter.right,l=this._scrollbarGutter.bottom;this._overlayScrollStyle.setMany({width:o-c+`px`,height:s-l+`px`});let u=e.source.getScrollMetrics(r),d=this.scrollableAxes(),f=d.y&&u.scrollHeight>u.clientHeight,p=d.x&&u.scrollWidth>u.clientWidth,m=o-(f?i:0),h=s-(p?i:0);(m!==o-c||h!==s-l)&&this._overlayScrollStyle.setMany({width:m+`px`,height:h+`px`}),this._scrollbarV.setX(m),this._scrollbarV.setY(0),this._scrollbarV.setHeight(h),this._scrollbarV.setMetrics(h,u.scrollHeight,u.scrollTop),this._scrollbarH.setX(0),this._scrollbarH.setY(h),this._scrollbarH.setWidth(m),this._scrollbarH.setMetrics(m,u.scrollWidth,u.scrollLeft);let g=f?i:0,_=p?i:0;(g!==c||_!==l)&&(this.setScrollbarGutter(g,_),this.scheduleLayout())}syncOverlayScrollbars(){let t=this._overlayScrollElement;if(!t||!this._scrollbarV||!this._scrollbarH)return;let n=e.source.getScrollMetrics(t);this._scrollbarV.setMetrics(n.clientHeight,n.scrollHeight,n.scrollTop),this._scrollbarH.setMetrics(n.clientWidth,n.scrollWidth,n.scrollLeft)}},m=i(Panel);export{m as t};
2
+ //# sourceMappingURL=Panel-D2X33qR6.js.map