@material/web 1.0.0 → 1.0.2-nightly.33c1afe.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 (394) hide show
  1. package/all.d.ts +2 -0
  2. package/all.js +2 -0
  3. package/all.js.map +1 -1
  4. package/button/elevated-button.js +5 -1
  5. package/button/elevated-button.js.map +1 -1
  6. package/button/internal/_elevation.scss +32 -32
  7. package/button/internal/_icon.scss +22 -23
  8. package/button/internal/_outlined-button.scss +21 -19
  9. package/button/internal/_shared.scss +84 -77
  10. package/button/internal/_touch-target.scss +4 -0
  11. package/button/internal/button.d.ts +7 -11
  12. package/button/internal/button.js +52 -38
  13. package/button/internal/button.js.map +1 -1
  14. package/button/internal/elevated-button.d.ts +1 -1
  15. package/button/internal/elevated-button.js +1 -1
  16. package/button/internal/elevated-button.js.map +1 -1
  17. package/button/internal/filled-button.d.ts +1 -1
  18. package/button/internal/filled-button.js +1 -1
  19. package/button/internal/filled-button.js.map +1 -1
  20. package/button/internal/filled-tonal-button.d.ts +1 -1
  21. package/button/internal/filled-tonal-button.js +1 -1
  22. package/button/internal/filled-tonal-button.js.map +1 -1
  23. package/button/internal/outlined-button.d.ts +1 -1
  24. package/button/internal/outlined-button.js +2 -2
  25. package/button/internal/outlined-button.js.map +1 -1
  26. package/button/internal/outlined-styles.css.js +1 -1
  27. package/button/internal/outlined-styles.css.js.map +1 -1
  28. package/button/internal/shared-elevation-styles.css.js +1 -1
  29. package/button/internal/shared-elevation-styles.css.js.map +1 -1
  30. package/button/internal/shared-styles.css.js +1 -1
  31. package/button/internal/shared-styles.css.js.map +1 -1
  32. package/checkbox/internal/_checkbox.scss +6 -0
  33. package/checkbox/internal/checkbox-styles.css.js +1 -1
  34. package/checkbox/internal/checkbox-styles.css.js.map +1 -1
  35. package/checkbox/internal/checkbox.d.ts +20 -87
  36. package/checkbox/internal/checkbox.js +35 -153
  37. package/checkbox/internal/checkbox.js.map +1 -1
  38. package/chips/filter-chip.js +5 -1
  39. package/chips/filter-chip.js.map +1 -1
  40. package/chips/harness.js.map +1 -1
  41. package/chips/input-chip.js +6 -1
  42. package/chips/input-chip.js.map +1 -1
  43. package/chips/internal/_shared.scss +1 -0
  44. package/chips/internal/assist-chip.js +8 -4
  45. package/chips/internal/assist-chip.js.map +1 -1
  46. package/chips/internal/chip-set.js +6 -4
  47. package/chips/internal/chip-set.js.map +1 -1
  48. package/chips/internal/chip.d.ts +3 -0
  49. package/chips/internal/chip.js +7 -5
  50. package/chips/internal/chip.js.map +1 -1
  51. package/chips/internal/filter-chip.d.ts +2 -0
  52. package/chips/internal/filter-chip.js +11 -5
  53. package/chips/internal/filter-chip.js.map +1 -1
  54. package/chips/internal/input-chip.d.ts +2 -0
  55. package/chips/internal/input-chip.js +10 -4
  56. package/chips/internal/input-chip.js.map +1 -1
  57. package/chips/internal/multi-action-chip.js.map +1 -1
  58. package/chips/internal/shared-styles.css.js +1 -1
  59. package/chips/internal/shared-styles.css.js.map +1 -1
  60. package/chips/internal/trailing-icons.d.ts +1 -1
  61. package/chips/internal/trailing-icons.js +6 -5
  62. package/chips/internal/trailing-icons.js.map +1 -1
  63. package/common.d.ts +2 -0
  64. package/common.js +2 -0
  65. package/common.js.map +1 -1
  66. package/dialog/harness.js +1 -2
  67. package/dialog/harness.js.map +1 -1
  68. package/dialog/internal/_dialog.scss +1 -1
  69. package/dialog/internal/animations.js +14 -12
  70. package/dialog/internal/animations.js.map +1 -1
  71. package/dialog/internal/dialog-styles.css.js +1 -1
  72. package/dialog/internal/dialog-styles.css.js.map +1 -1
  73. package/dialog/internal/dialog.d.ts +6 -6
  74. package/dialog/internal/dialog.js +24 -24
  75. package/dialog/internal/dialog.js.map +1 -1
  76. package/fab/harness.js.map +1 -1
  77. package/fab/internal/_fab.scss +4 -0
  78. package/fab/internal/_shared.scss +1 -0
  79. package/fab/internal/fab-styles.css.js +1 -1
  80. package/fab/internal/fab-styles.css.js.map +1 -1
  81. package/fab/internal/fab.js.map +1 -1
  82. package/fab/internal/shared-styles.css.js +1 -1
  83. package/fab/internal/shared-styles.css.js.map +1 -1
  84. package/fab/internal/shared.js +10 -11
  85. package/fab/internal/shared.js.map +1 -1
  86. package/field/harness.js.map +1 -1
  87. package/field/internal/_content.scss +185 -174
  88. package/field/internal/_filled-field.scss +147 -135
  89. package/field/internal/_label.scss +83 -72
  90. package/field/internal/_outlined-field.scss +276 -261
  91. package/field/internal/_supporting-text.scss +53 -42
  92. package/field/internal/field.js +26 -22
  93. package/field/internal/field.js.map +1 -1
  94. package/field/internal/filled-styles.css.js +1 -1
  95. package/field/internal/filled-styles.css.js.map +1 -1
  96. package/field/internal/outlined-styles.css.js +1 -1
  97. package/field/internal/outlined-styles.css.js.map +1 -1
  98. package/field/internal/shared-styles.css.js +1 -1
  99. package/field/internal/shared-styles.css.js.map +1 -1
  100. package/focus/internal/focus-ring.d.ts +2 -0
  101. package/focus/internal/focus-ring.js +3 -3
  102. package/focus/internal/focus-ring.js.map +1 -1
  103. package/icon/internal/_icon.scss +7 -4
  104. package/icon/internal/icon-styles.css.js +1 -1
  105. package/icon/internal/icon-styles.css.js.map +1 -1
  106. package/iconbutton/internal/icon-button.d.ts +9 -4
  107. package/iconbutton/internal/icon-button.js +35 -22
  108. package/iconbutton/internal/icon-button.js.map +1 -1
  109. package/internal/aria/aria.d.ts +4 -26
  110. package/internal/aria/aria.js +10 -28
  111. package/internal/aria/aria.js.map +1 -1
  112. package/internal/aria/delegate.js +2 -2
  113. package/internal/aria/delegate.js.map +1 -1
  114. package/internal/controller/attachable-controller.js +3 -5
  115. package/internal/controller/attachable-controller.js.map +1 -1
  116. package/internal/controller/form-submitter.d.ts +3 -5
  117. package/internal/controller/form-submitter.js +5 -7
  118. package/internal/controller/form-submitter.js.map +1 -1
  119. package/internal/controller/is-rtl.js +2 -2
  120. package/internal/controller/is-rtl.js.map +1 -1
  121. package/internal/controller/string-converter.js +1 -1
  122. package/internal/controller/string-converter.js.map +1 -1
  123. package/internal/motion/animation.js.map +1 -1
  124. package/labs/behaviors/constraint-validation.d.ts +133 -0
  125. package/labs/behaviors/constraint-validation.js +114 -0
  126. package/labs/behaviors/constraint-validation.js.map +1 -0
  127. package/labs/behaviors/element-internals.d.ts +45 -0
  128. package/labs/behaviors/element-internals.js +50 -0
  129. package/labs/behaviors/element-internals.js.map +1 -0
  130. package/labs/behaviors/focusable.d.ts +39 -0
  131. package/labs/behaviors/focusable.js +82 -0
  132. package/labs/behaviors/focusable.js.map +1 -0
  133. package/labs/behaviors/form-associated.d.ts +199 -0
  134. package/labs/behaviors/form-associated.js +155 -0
  135. package/labs/behaviors/form-associated.js.map +1 -0
  136. package/labs/behaviors/mixin.d.ts +54 -0
  137. package/labs/behaviors/mixin.js +7 -0
  138. package/labs/behaviors/mixin.js.map +1 -0
  139. package/labs/behaviors/on-report-validity.d.ts +70 -0
  140. package/labs/behaviors/on-report-validity.js +150 -0
  141. package/labs/behaviors/on-report-validity.js.map +1 -0
  142. package/labs/behaviors/validators/checkbox-validator.d.ts +31 -0
  143. package/labs/behaviors/validators/checkbox-validator.js +29 -0
  144. package/labs/behaviors/validators/checkbox-validator.js.map +1 -0
  145. package/labs/behaviors/validators/select-validator.d.ts +31 -0
  146. package/labs/behaviors/validators/select-validator.js +30 -0
  147. package/labs/behaviors/validators/select-validator.js.map +1 -0
  148. package/labs/behaviors/validators/validator.d.ts +92 -0
  149. package/labs/behaviors/validators/validator.js +83 -0
  150. package/labs/behaviors/validators/validator.js.map +1 -0
  151. package/labs/card/_elevated-card.scss +6 -0
  152. package/labs/card/_filled-card.scss +6 -0
  153. package/labs/card/_outlined-card.scss +6 -0
  154. package/labs/card/elevated-card.d.ts +18 -0
  155. package/labs/card/elevated-card.js +21 -0
  156. package/labs/card/elevated-card.js.map +1 -0
  157. package/labs/card/filled-card.d.ts +18 -0
  158. package/labs/card/filled-card.js +21 -0
  159. package/labs/card/filled-card.js.map +1 -0
  160. package/labs/card/internal/_elevated-card.scss +35 -0
  161. package/labs/card/internal/_filled-card.scss +35 -0
  162. package/labs/card/internal/_outlined-card.scss +39 -0
  163. package/labs/card/internal/_shared.scss +40 -0
  164. package/labs/card/internal/card.d.ts +13 -0
  165. package/labs/card/internal/card.js +20 -0
  166. package/labs/card/internal/card.js.map +1 -0
  167. package/labs/card/internal/elevated-styles.css.js +9 -0
  168. package/labs/card/internal/elevated-styles.css.js.map +1 -0
  169. package/labs/card/internal/elevated-styles.scss +10 -0
  170. package/labs/card/internal/filled-styles.css.js +9 -0
  171. package/labs/card/internal/filled-styles.css.js.map +1 -0
  172. package/labs/card/internal/filled-styles.scss +10 -0
  173. package/labs/card/internal/outlined-styles.css.js +9 -0
  174. package/labs/card/internal/outlined-styles.css.js.map +1 -0
  175. package/labs/card/internal/outlined-styles.scss +10 -0
  176. package/labs/card/internal/shared-styles.css.js +9 -0
  177. package/labs/card/internal/shared-styles.css.js.map +1 -0
  178. package/labs/card/internal/shared-styles.scss +10 -0
  179. package/labs/card/outlined-card.d.ts +18 -0
  180. package/labs/card/outlined-card.js +21 -0
  181. package/labs/card/outlined-card.js.map +1 -0
  182. package/labs/item/internal/_item.scss +1 -1
  183. package/labs/item/internal/item-styles.css.js +1 -1
  184. package/labs/item/internal/item-styles.css.js.map +1 -1
  185. package/labs/item/internal/item.js +8 -8
  186. package/labs/item/internal/item.js.map +1 -1
  187. package/labs/navigationbar/internal/constants.js.map +1 -1
  188. package/labs/navigationbar/internal/navigation-bar.d.ts +3 -0
  189. package/labs/navigationbar/internal/navigation-bar.js +18 -11
  190. package/labs/navigationbar/internal/navigation-bar.js.map +1 -1
  191. package/labs/navigationdrawer/internal/navigation-drawer-modal.d.ts +3 -0
  192. package/labs/navigationdrawer/internal/navigation-drawer-modal.js +10 -3
  193. package/labs/navigationdrawer/internal/navigation-drawer-modal.js.map +1 -1
  194. package/labs/navigationdrawer/internal/navigation-drawer.d.ts +3 -0
  195. package/labs/navigationdrawer/internal/navigation-drawer.js +8 -1
  196. package/labs/navigationdrawer/internal/navigation-drawer.js.map +1 -1
  197. package/labs/navigationtab/harness.js.map +1 -1
  198. package/labs/navigationtab/internal/navigation-tab.d.ts +6 -0
  199. package/labs/navigationtab/internal/navigation-tab.js +43 -27
  200. package/labs/navigationtab/internal/navigation-tab.js.map +1 -1
  201. package/labs/navigationtab/internal/state.js.map +1 -1
  202. package/labs/segmentedbutton/internal/_shared.scss +1 -0
  203. package/labs/segmentedbutton/internal/segmented-button.d.ts +3 -0
  204. package/labs/segmentedbutton/internal/segmented-button.js +26 -12
  205. package/labs/segmentedbutton/internal/segmented-button.js.map +1 -1
  206. package/labs/segmentedbutton/internal/shared-styles.css.js +1 -1
  207. package/labs/segmentedbutton/internal/shared-styles.css.js.map +1 -1
  208. package/labs/segmentedbuttonset/internal/segmented-button-set.d.ts +5 -0
  209. package/labs/segmentedbuttonset/internal/segmented-button-set.js +14 -9
  210. package/labs/segmentedbuttonset/internal/segmented-button-set.js.map +1 -1
  211. package/list/harness.d.ts +3 -2
  212. package/list/harness.js.map +1 -1
  213. package/list/internal/list-controller.d.ts +1 -1
  214. package/list/internal/list-controller.js +7 -3
  215. package/list/internal/list-controller.js.map +1 -1
  216. package/list/internal/list-navigation-helpers.js.map +1 -1
  217. package/list/internal/list.d.ts +2 -2
  218. package/list/internal/list.js +8 -6
  219. package/list/internal/list.js.map +1 -1
  220. package/list/internal/listitem/_list-item.scss +19 -0
  221. package/list/internal/listitem/harness.d.ts +3 -3
  222. package/list/internal/listitem/harness.js.map +1 -1
  223. package/list/internal/listitem/list-item-styles.css.js +1 -1
  224. package/list/internal/listitem/list-item-styles.css.js.map +1 -1
  225. package/list/internal/listitem/list-item.d.ts +3 -2
  226. package/list/internal/listitem/list-item.js +20 -21
  227. package/list/internal/listitem/list-item.js.map +1 -1
  228. package/list/list-item.d.ts +4 -12
  229. package/list/list-item.js +5 -14
  230. package/list/list-item.js.map +1 -1
  231. package/menu/harness.js.map +1 -1
  232. package/menu/internal/_menu.scss +20 -1
  233. package/menu/internal/controllers/menuItemController.d.ts +7 -0
  234. package/menu/internal/controllers/menuItemController.js +17 -4
  235. package/menu/internal/controllers/menuItemController.js.map +1 -1
  236. package/menu/internal/controllers/shared.d.ts +9 -1
  237. package/menu/internal/controllers/shared.js +4 -4
  238. package/menu/internal/controllers/shared.js.map +1 -1
  239. package/menu/internal/controllers/surfacePositionController.d.ts +16 -2
  240. package/menu/internal/controllers/surfacePositionController.js +134 -56
  241. package/menu/internal/controllers/surfacePositionController.js.map +1 -1
  242. package/menu/internal/controllers/typeaheadController.js +19 -14
  243. package/menu/internal/controllers/typeaheadController.js.map +1 -1
  244. package/menu/internal/menu-styles.css.js +1 -1
  245. package/menu/internal/menu-styles.css.js.map +1 -1
  246. package/menu/internal/menu.d.ts +55 -17
  247. package/menu/internal/menu.js +175 -88
  248. package/menu/internal/menu.js.map +1 -1
  249. package/menu/internal/menuitem/_menu-item.scss +24 -0
  250. package/menu/internal/menuitem/harness.d.ts +3 -1
  251. package/menu/internal/menuitem/harness.js.map +1 -1
  252. package/menu/internal/menuitem/menu-item-styles.css.js +1 -1
  253. package/menu/internal/menuitem/menu-item-styles.css.js.map +1 -1
  254. package/menu/internal/menuitem/menu-item.d.ts +3 -2
  255. package/menu/internal/menuitem/menu-item.js +20 -20
  256. package/menu/internal/menuitem/menu-item.js.map +1 -1
  257. package/menu/internal/submenu/sub-menu.d.ts +9 -8
  258. package/menu/internal/submenu/sub-menu.js +35 -22
  259. package/menu/internal/submenu/sub-menu.js.map +1 -1
  260. package/menu/internal/types.js.map +1 -1
  261. package/menu/menu-item.js +1 -2
  262. package/menu/menu-item.js.map +1 -1
  263. package/menu/menu.js +1 -2
  264. package/menu/menu.js.map +1 -1
  265. package/package.json +1 -1
  266. package/progress/internal/_circular-progress.scss +2 -2
  267. package/progress/internal/_linear-progress.scss +1 -1
  268. package/progress/internal/circular-progress-styles.css.js +1 -1
  269. package/progress/internal/circular-progress-styles.css.js.map +1 -1
  270. package/progress/internal/circular-progress.js +11 -10
  271. package/progress/internal/circular-progress.js.map +1 -1
  272. package/progress/internal/linear-progress-styles.css.js +1 -1
  273. package/progress/internal/linear-progress-styles.css.js.map +1 -1
  274. package/progress/internal/linear-progress.d.ts +1 -1
  275. package/progress/internal/linear-progress.js +3 -3
  276. package/progress/internal/linear-progress.js.map +1 -1
  277. package/progress/internal/progress.js +4 -2
  278. package/progress/internal/progress.js.map +1 -1
  279. package/radio/internal/_radio.scss +144 -123
  280. package/radio/internal/radio-styles.css.js +1 -1
  281. package/radio/internal/radio-styles.css.js.map +1 -1
  282. package/radio/internal/radio.d.ts +12 -23
  283. package/radio/internal/radio.js +31 -50
  284. package/radio/internal/radio.js.map +1 -1
  285. package/radio/internal/single-selection-controller.js +1 -1
  286. package/radio/internal/single-selection-controller.js.map +1 -1
  287. package/radio/radio.js +1 -2
  288. package/radio/radio.js.map +1 -1
  289. package/ripple/internal/ripple.js +21 -18
  290. package/ripple/internal/ripple.js.map +1 -1
  291. package/select/filled-select.js +1 -2
  292. package/select/filled-select.js.map +1 -1
  293. package/select/harness.js +1 -1
  294. package/select/harness.js.map +1 -1
  295. package/select/internal/_shared.scss +4 -0
  296. package/select/internal/select.d.ts +26 -99
  297. package/select/internal/select.js +78 -187
  298. package/select/internal/select.js.map +1 -1
  299. package/select/internal/selectoption/select-option.d.ts +8 -6
  300. package/select/internal/selectoption/select-option.js +25 -23
  301. package/select/internal/selectoption/select-option.js.map +1 -1
  302. package/select/internal/selectoption/selectOptionController.js +1 -1
  303. package/select/internal/selectoption/selectOptionController.js.map +1 -1
  304. package/select/internal/shared-styles.css.js +1 -1
  305. package/select/internal/shared-styles.css.js.map +1 -1
  306. package/select/outlined-select.js +1 -2
  307. package/select/outlined-select.js.map +1 -1
  308. package/select/select-option.js +1 -2
  309. package/select/select-option.js.map +1 -1
  310. package/slider/harness.js +5 -5
  311. package/slider/harness.js.map +1 -1
  312. package/slider/internal/_slider.scss +68 -30
  313. package/slider/internal/slider-styles.css.js +1 -1
  314. package/slider/internal/slider-styles.css.js.map +1 -1
  315. package/slider/internal/slider.d.ts +16 -25
  316. package/slider/internal/slider.js +111 -115
  317. package/slider/internal/slider.js.map +1 -1
  318. package/switch/internal/_handle.scss +159 -141
  319. package/switch/internal/_icon.scss +95 -72
  320. package/switch/internal/_switch.scss +90 -95
  321. package/switch/internal/_track.scss +110 -77
  322. package/switch/internal/switch-styles.css.js +1 -1
  323. package/switch/internal/switch-styles.css.js.map +1 -1
  324. package/switch/internal/switch.d.ts +13 -89
  325. package/switch/internal/switch.js +32 -159
  326. package/switch/internal/switch.js.map +1 -1
  327. package/switch/switch.js +1 -2
  328. package/switch/switch.js.map +1 -1
  329. package/tabs/harness.js +3 -3
  330. package/tabs/harness.js.map +1 -1
  331. package/tabs/internal/_tab.scss +27 -35
  332. package/tabs/internal/primary-tab.d.ts +0 -2
  333. package/tabs/internal/tab-styles.css.js +1 -1
  334. package/tabs/internal/tab-styles.css.js.map +1 -1
  335. package/tabs/internal/tab.d.ts +10 -5
  336. package/tabs/internal/tab.js +43 -22
  337. package/tabs/internal/tab.js.map +1 -1
  338. package/tabs/internal/tabs.d.ts +7 -4
  339. package/tabs/internal/tabs.js +23 -22
  340. package/tabs/internal/tabs.js.map +1 -1
  341. package/textfield/filled-text-field.js +1 -2
  342. package/textfield/filled-text-field.js.map +1 -1
  343. package/textfield/harness.js +3 -2
  344. package/textfield/harness.js.map +1 -1
  345. package/textfield/internal/text-field.d.ts +33 -18
  346. package/textfield/internal/text-field.js +96 -58
  347. package/textfield/internal/text-field.js.map +1 -1
  348. package/textfield/outlined-text-field.js +1 -2
  349. package/textfield/outlined-text-field.js.map +1 -1
  350. package/tokens/_index.scss +3 -0
  351. package/tokens/_md-comp-elevated-card.scss +63 -0
  352. package/tokens/_md-comp-filled-card.scss +63 -0
  353. package/tokens/_md-comp-icon.scss +2 -0
  354. package/tokens/_md-comp-outlined-card.scss +69 -0
  355. package/tokens/_md-comp-test-table.scss +1 -0
  356. package/internal/controller/element-internals.d.ts +0 -35
  357. package/internal/controller/element-internals.js +0 -24
  358. package/internal/controller/element-internals.js.map +0 -1
  359. package/list/internal/listitem/forced-colors-styles.css.js +0 -9
  360. package/list/internal/listitem/forced-colors-styles.css.js.map +0 -1
  361. package/list/internal/listitem/forced-colors-styles.scss +0 -19
  362. package/menu/internal/forced-colors-styles.css.js +0 -9
  363. package/menu/internal/forced-colors-styles.css.js.map +0 -1
  364. package/menu/internal/forced-colors-styles.scss +0 -12
  365. package/menu/internal/menuitem/forced-colors-styles.css.js +0 -9
  366. package/menu/internal/menuitem/forced-colors-styles.css.js.map +0 -1
  367. package/menu/internal/menuitem/forced-colors-styles.scss +0 -26
  368. package/radio/internal/forced-colors-styles.css.js +0 -9
  369. package/radio/internal/forced-colors-styles.css.js.map +0 -1
  370. package/radio/internal/forced-colors-styles.scss +0 -29
  371. package/select/internal/filled-forced-colors-styles.css.d.ts +0 -1
  372. package/select/internal/filled-forced-colors-styles.css.js +0 -9
  373. package/select/internal/filled-forced-colors-styles.css.js.map +0 -1
  374. package/select/internal/filled-forced-colors-styles.scss +0 -29
  375. package/select/internal/outlined-forced-colors-styles.css.d.ts +0 -1
  376. package/select/internal/outlined-forced-colors-styles.css.js +0 -9
  377. package/select/internal/outlined-forced-colors-styles.css.js.map +0 -1
  378. package/select/internal/outlined-forced-colors-styles.scss +0 -29
  379. package/switch/internal/forced-colors-styles.css.d.ts +0 -1
  380. package/switch/internal/forced-colors-styles.css.js +0 -9
  381. package/switch/internal/forced-colors-styles.css.js.map +0 -1
  382. package/switch/internal/forced-colors-styles.scss +0 -42
  383. package/textfield/internal/filled-forced-colors-styles.css.d.ts +0 -1
  384. package/textfield/internal/filled-forced-colors-styles.css.js +0 -9
  385. package/textfield/internal/filled-forced-colors-styles.css.js.map +0 -1
  386. package/textfield/internal/filled-forced-colors-styles.scss +0 -29
  387. package/textfield/internal/outlined-forced-colors-styles.css.d.ts +0 -1
  388. package/textfield/internal/outlined-forced-colors-styles.css.js +0 -9
  389. package/textfield/internal/outlined-forced-colors-styles.css.js.map +0 -1
  390. package/textfield/internal/outlined-forced-colors-styles.scss +0 -29
  391. /package/{list/internal/listitem/forced-colors-styles.css.d.ts → labs/card/internal/elevated-styles.css.d.ts} +0 -0
  392. /package/{menu/internal/forced-colors-styles.css.d.ts → labs/card/internal/filled-styles.css.d.ts} +0 -0
  393. /package/{menu/internal/menuitem/forced-colors-styles.css.d.ts → labs/card/internal/outlined-styles.css.d.ts} +0 -0
  394. /package/{radio/internal/forced-colors-styles.css.d.ts → labs/card/internal/shared-styles.css.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"surfacePositionController.js","sourceRoot":"","sources":["surfacePositionController.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;GAEG;AACH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;IAC1B,SAAS,EAAE,WAAW;CACd,CAAC;AA0FX;;;;;GAKG;AACH,MAAM,OAAO,yBAAyB;IAUpC;;;;OAIG;IACH,YACqB,IAA4B,EAC5B,aAAwD;QADxD,SAAI,GAAJ,IAAI,CAAwB;QAC5B,kBAAa,GAAb,aAAa,CAA2C;QAhB7E,8CAA8C;QACtC,0BAAqB,GAAc;YACzC,SAAS,EAAE,MAAM;SAClB,CAAC;QACF,wEAAwE;QACxE,+CAA+C;QACvC,eAAU,GAAwC,EAAC,MAAM,EAAE,KAAK,EACjC,CAAC;QAWtC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,EACJ,SAAS,EACT,QAAQ,EACR,YAAY,EAAE,eAAe,EAC7B,aAAa,EAAE,gBAAgB,EAC/B,WAAW,EACX,OAA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K,CAAC,SAAS,CAAC;QAErC,IAAI,UAAU,IAAI,SAAS,IAAI,UAAU,EAAE;YACzC,sEAAsE;YACtE,sEAAsE;YACtE,mCAAmC;YACnC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YAEtC,IAAI,KAAK,CAAC,MAAM,EAAE;gBAChB,sEAAsE;gBACtE,kBAAkB;gBAClB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;gBAExB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACtB,KAAK,CAAC,MAAM,EAAE,CAAC;aAChB;iBAAM,IAAI,WAAW,EAAE;gBACtB,MAAM,KAAK,CAAC,WAAW,EAAE,CAAC;gBAC1B,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,KAAK,CAAC,OAAO,EAAE,CAAC;aACjB;SACF;IACH,CAAC;IAED;;OAEG;IACK,KAAK;QACX,IAAI,CAAC,qBAAqB,GAAG;YAC3B,SAAS,EAAE,MAAM;SAClB,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {ReactiveController, ReactiveControllerHost} from 'lit';\nimport {StyleInfo} from 'lit/directives/style-map.js';\n\n/**\n * An enum of supported Menu corners\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const Corner = {\n END_START: 'end-start',\n END_END: 'end-end',\n START_START: 'start-start',\n START_END: 'start-end',\n} as const;\n\n/**\n * A corner of a box in the standard logical property style of <block>_<inline>\n */\nexport type Corner = typeof Corner[keyof typeof Corner];\n\n/**\n * An interface that provides a method to customize the rect from which to\n * calculate the anchor positioning. Useful for when you want a surface to\n * anchor to an element in your shadow DOM rather than the host element.\n */\nexport interface SurfacePositionTarget extends HTMLElement {\n getSurfacePositionClientRect?: () => DOMRect;\n}\n\n/**\n * The configurable options for the surface position controller.\n */\nexport interface SurfacePositionControllerProperties {\n /**\n * The corner of the anchor to align the surface's position.\n */\n anchorCorner: Corner;\n /**\n * The corner of the surface to align to the given anchor corner.\n */\n surfaceCorner: Corner;\n /**\n * The HTMLElement reference of the surface to be positioned.\n */\n surfaceEl: SurfacePositionTarget|null;\n /**\n * The HTMLElement reference of the anchor to align to.\n */\n anchorEl: SurfacePositionTarget|null;\n /**\n * Whether the positioning algorithim should calculate relative to the parent\n * of the anchor element (absolute) or relative to the window (fixed).\n *\n * Examples for `position = 'fixed'`:\n *\n * - If there is no `position:relative` in the given parent tree and the\n * surface is `position:absolute`\n * - If the surface is `position:fixed`\n * - If the surface is in the \"top layer\"\n * - The anchor and the surface do not share a common `position:relative`\n * ancestor\n */\n positioning: 'absolute'|'fixed';\n /**\n * Whether or not the surface should be \"open\" and visible\n */\n isOpen: boolean;\n /**\n * The number of pixels in which to offset from the inline axis relative to\n * logical property.\n *\n * Positive is right in LTR and left in RTL.\n */\n xOffset: number;\n /**\n * The number of pixes in which to offset the block axis.\n *\n * Positive is down and negative is up.\n */\n yOffset: number;\n /**\n * The strategy to follow when repositioning the menu to stay inside the\n * viewport. \"move\" will simply move the surface to stay in the viewport.\n * \"resize\" will attempt to resize the surface.\n *\n * Both strategies will still attempt to flip the anchor and surface corners.\n */\n repositionStrategy: 'move'|'resize';\n /**\n * A function to call after the surface has been positioned.\n */\n onOpen: () => void;\n /**\n * A function to call before the surface should be closed. (A good time to\n * perform animations while the surface is still visible)\n */\n beforeClose: () => Promise<void>;\n /**\n * A function to call after the surface has been closed.\n */\n onClose: () => void;\n}\n\n/**\n * Given a surface, an anchor, corners, and some options, this surface will\n * calculate the position of a surface to align the two given corners and keep\n * the surface inside the window viewport. It also provides a StyleInfo map that\n * can be applied to the surface to handle visiblility and position.\n */\nexport class SurfacePositionController implements ReactiveController {\n // The current styles to apply to the surface.\n private surfaceStylesInternal: StyleInfo = {\n 'display': 'none',\n };\n // Previous values stored for change detection. Open change detection is\n // calculated separately so initialize it here.\n private lastValues: SurfacePositionControllerProperties = {isOpen: false} as\n SurfacePositionControllerProperties;\n\n /**\n * @param host The host to connect the controller to.\n * @param getProperties A function that returns the properties for the\n * controller.\n */\n constructor(\n private readonly host: ReactiveControllerHost,\n private readonly getProperties: () => SurfacePositionControllerProperties,\n ) {\n this.host.addController(this);\n }\n\n /**\n * The StyleInfo map to apply to the surface via Lit's stylemap\n */\n get surfaceStyles() {\n return this.surfaceStylesInternal;\n }\n\n /**\n * Calculates the surface's new position required so that the surface's\n * `surfaceCorner` aligns to the anchor's `anchorCorner` while keeping the\n * surface inside the window viewport. This positioning also respects RTL by\n * checking `getComputedStyle()` on the surface element.\n */\n async position() {\n const {\n surfaceEl,\n anchorEl,\n anchorCorner: anchorCornerRaw,\n surfaceCorner: surfaceCornerRaw,\n positioning,\n xOffset,\n yOffset,\n repositionStrategy,\n } = this.getProperties();\n const anchorCorner = anchorCornerRaw.toLowerCase().trim();\n const surfaceCorner = surfaceCornerRaw.toLowerCase().trim();\n\n if (!surfaceEl || !anchorEl) {\n return;\n }\n\n // Paint the surface transparently so that we can get the position and the\n // rect info of the surface.\n this.surfaceStylesInternal = {\n 'display': 'block',\n 'opacity': '0',\n };\n\n // Wait for it to be visible.\n this.host.requestUpdate();\n await this.host.updateComplete;\n\n const surfaceRect = surfaceEl.getSurfacePositionClientRect ?\n surfaceEl.getSurfacePositionClientRect() :\n surfaceEl.getBoundingClientRect();\n const anchorRect = anchorEl.getSurfacePositionClientRect ?\n anchorEl.getSurfacePositionClientRect() :\n anchorEl.getBoundingClientRect();\n const [surfaceBlock, surfaceInline] =\n surfaceCorner.split('-') as Array<'start'|'end'>;\n const [anchorBlock, anchorInline] =\n anchorCorner.split('-') as Array<'start'|'end'>;\n\n // LTR depends on the direction of the SURFACE not the anchor.\n const isLTR =\n getComputedStyle(surfaceEl as HTMLElement).direction === 'ltr';\n\n /*\n * A diagram that helps describe some of the variables used in the following\n * calculations.\n *\n * ┌───── inline/blockTopLayerOffset\n * │ │\n * │ ┌─▼───┐ Window\n * │ ┌┼─────┴────────────────────────┐\n * │ ││ │\n * └──► ││ ┌──inline/blockAnchorOffset │\n * ││ │ │ │\n * └┤ │ ┌──▼───┐ │\n * │ │ ┌┼──────┤ │\n * │ └─►│Anchor│ │\n * │ └┴──────┘ │\n * │ │\n * │ ┌────────────────────────┼────┐\n * │ │ Surface │ │\n * │ │ │ │\n * │ │ │ │\n * │ │ │ │\n * │ │ │ │\n * │ │ │ │\n * └─────┼────────────────────────┘ ├┐\n * │ inline/blockOOBCorrection ││\n * │ │ ││\n * │ ├──►││\n * │ │ ││\n * └────────────────────────┐▼───┼┘\n * └────┘\n */\n\n // Calculate the block positioning properties\n let {blockInset, blockOutOfBoundsCorrection, surfaceBlockProperty} =\n this.calculateBlock({\n surfaceRect,\n anchorRect,\n anchorBlock,\n surfaceBlock,\n yOffset,\n positioning\n });\n\n // If the surface should be out of bounds in the block direction, flip the\n // surface and anchor corner block values and recalculate\n if (blockOutOfBoundsCorrection) {\n const flippedSurfaceBlock = surfaceBlock === 'start' ? 'end' : 'start';\n const flippedAnchorBlock = anchorBlock === 'start' ? 'end' : 'start';\n\n const flippedBlock = this.calculateBlock({\n surfaceRect,\n anchorRect,\n anchorBlock: flippedAnchorBlock,\n surfaceBlock: flippedSurfaceBlock,\n yOffset,\n positioning\n });\n\n // In the case that the flipped verion would require less out of bounds\n // correcting, use the flipped corner block values\n if (blockOutOfBoundsCorrection >\n flippedBlock.blockOutOfBoundsCorrection) {\n blockInset = flippedBlock.blockInset;\n blockOutOfBoundsCorrection = flippedBlock.blockOutOfBoundsCorrection;\n surfaceBlockProperty = flippedBlock.surfaceBlockProperty;\n }\n }\n\n // Calculate the inline positioning properties\n let {inlineInset, inlineOutOfBoundsCorrection, surfaceInlineProperty} =\n this.calculateInline({\n surfaceRect,\n anchorRect,\n anchorInline,\n surfaceInline,\n xOffset,\n positioning,\n isLTR,\n });\n\n // If the surface should be out of bounds in the inline direction, flip the\n // surface and anchor corner inline values and recalculate\n if (inlineOutOfBoundsCorrection) {\n const flippedSurfaceInline = surfaceInline === 'start' ? 'end' : 'start';\n const flippedAnchorInline = anchorInline === 'start' ? 'end' : 'start';\n\n const flippedInline = this.calculateInline({\n surfaceRect,\n anchorRect,\n anchorInline: flippedAnchorInline,\n surfaceInline: flippedSurfaceInline,\n xOffset,\n positioning,\n isLTR,\n });\n\n // In the case that the flipped verion would require less out of bounds\n // correcting, use the flipped corner inline values\n if (Math.abs(inlineOutOfBoundsCorrection) >\n Math.abs(flippedInline.inlineOutOfBoundsCorrection)) {\n inlineInset = flippedInline.inlineInset;\n inlineOutOfBoundsCorrection = flippedInline.inlineOutOfBoundsCorrection;\n surfaceInlineProperty = flippedInline.surfaceInlineProperty;\n }\n }\n\n // If we are simply repositioning the surface back inside the viewport,\n // subtract the out of bounds correction values from the positioning.\n if (repositionStrategy === 'move') {\n blockInset = blockInset - blockOutOfBoundsCorrection;\n inlineInset = inlineInset - inlineOutOfBoundsCorrection;\n }\n\n this.surfaceStylesInternal = {\n 'display': 'block',\n 'opacity': '1',\n [surfaceBlockProperty]: `${blockInset}px`,\n [surfaceInlineProperty]: `${inlineInset}px`,\n };\n\n // In the case that we are resizing the surface to stay inside the viewport\n // we need to set height and width on the surface.\n if (repositionStrategy === 'resize') {\n // Add a height property to the styles if there is block height correction\n if (blockOutOfBoundsCorrection) {\n this.surfaceStylesInternal['height'] =\n `${surfaceRect.height - blockOutOfBoundsCorrection}px`;\n }\n\n // Add a width property to the styles if there is block height correction\n if (inlineOutOfBoundsCorrection) {\n this.surfaceStylesInternal['width'] =\n `${surfaceRect.width - inlineOutOfBoundsCorrection}px`;\n }\n }\n\n this.host.requestUpdate();\n }\n\n /**\n * Calculates the css property, the inset, and the out of bounds correction\n * for the surface in the block direction.\n */\n private calculateBlock(config: {\n surfaceRect: DOMRect,\n anchorRect: DOMRect,\n anchorBlock: 'start'|'end',\n surfaceBlock: 'start'|'end',\n yOffset: number,\n positioning: 'absolute'|'fixed',\n }) {\n const {\n surfaceRect,\n anchorRect,\n anchorBlock,\n surfaceBlock,\n yOffset,\n positioning,\n } = config;\n // We use number booleans to multiply values rather than `if` / ternary\n // statements because it _heavily_ cuts down on nesting and readability\n const relativeToWindow = positioning === 'fixed' ? 1 : 0;\n const isSurfaceBlockStart = surfaceBlock === 'start' ? 1 : 0;\n const isSurfaceBlockEnd = surfaceBlock === 'end' ? 1 : 0;\n const isOneBlockEnd = anchorBlock !== surfaceBlock ? 1 : 0;\n\n // Whether or not to apply the height of the anchor\n const blockAnchorOffset = isOneBlockEnd * anchorRect.height + yOffset;\n // The absolute block position of the anchor relative to window\n const blockTopLayerOffset = isSurfaceBlockStart * anchorRect.top +\n isSurfaceBlockEnd * (window.innerHeight - anchorRect.bottom);\n // If the surface's block would be out of bounds of the window, move it back\n // in\n const blockOutOfBoundsCorrection = Math.abs(Math.min(\n 0,\n window.innerHeight - blockTopLayerOffset - blockAnchorOffset -\n surfaceRect.height));\n\n\n // The block logical value of the surface\n const blockInset =\n relativeToWindow * blockTopLayerOffset + blockAnchorOffset;\n\n const surfaceBlockProperty =\n surfaceBlock === 'start' ? 'inset-block-start' : 'inset-block-end';\n\n return {blockInset, blockOutOfBoundsCorrection, surfaceBlockProperty};\n }\n\n /**\n * Calculates the css property, the inset, and the out of bounds correction\n * for the surface in the inline direction.\n */\n private calculateInline(config: {\n isLTR: boolean,\n surfaceInline: 'start'|'end',\n anchorInline: 'start'|'end',\n anchorRect: DOMRect,\n surfaceRect: DOMRect,\n xOffset: number,\n positioning: 'absolute'|'fixed',\n }) {\n const {\n isLTR: isLTRBool,\n surfaceInline,\n anchorInline,\n anchorRect,\n surfaceRect,\n xOffset,\n positioning,\n } = config;\n // We use number booleans to multiply values rather than `if` / ternary\n // statements because it _heavily_ cuts down on nesting and readability\n const relativeToWindow = positioning === 'fixed' ? 1 : 0;\n const isLTR = isLTRBool ? 1 : 0;\n const isRTL = isLTRBool ? 0 : 1;\n const isSurfaceInlineStart = surfaceInline === 'start' ? 1 : 0;\n const isSurfaceInlineEnd = surfaceInline === 'end' ? 1 : 0;\n const isOneInlineEnd = anchorInline !== surfaceInline ? 1 : 0;\n\n // Whether or not to apply the width of the anchor\n const inlineAnchorOffset = isOneInlineEnd * anchorRect.width + xOffset;\n // The inline position of the anchor relative to window in LTR\n const inlineTopLayerOffsetLTR = isSurfaceInlineStart * anchorRect.left +\n isSurfaceInlineEnd * (window.innerWidth - anchorRect.right);\n // The inline position of the anchor relative to window in RTL\n const inlineTopLayerOffsetRTL =\n isSurfaceInlineStart * (window.innerWidth - anchorRect.right) +\n isSurfaceInlineEnd * anchorRect.left;\n // The inline position of the anchor relative to window\n const inlineTopLayerOffset =\n isLTR * inlineTopLayerOffsetLTR + isRTL * inlineTopLayerOffsetRTL;\n\n // If the surface's inline would be out of bounds of the window, move it\n // back in\n const inlineOutOfBoundsCorrection = Math.abs(Math.min(\n 0,\n window.innerWidth - inlineTopLayerOffset - inlineAnchorOffset -\n surfaceRect.width));\n\n\n // The inline logical value of the surface\n const inlineInset =\n relativeToWindow * inlineTopLayerOffset + inlineAnchorOffset;\n\n const surfaceInlineProperty =\n surfaceInline === 'start' ? 'inset-inline-start' : 'inset-inline-end';\n\n return {\n inlineInset,\n inlineOutOfBoundsCorrection,\n surfaceInlineProperty,\n };\n }\n\n hostUpdate() {\n this.onUpdate();\n }\n\n hostUpdated() {\n this.onUpdate();\n }\n\n /**\n * Checks whether the properties passed into the controller have changed since\n * the last positioning. If so, it will reposition if the surface is open or\n * close it if the surface should close.\n */\n private async onUpdate() {\n const props = this.getProperties();\n let hasChanged = false;\n for (const [key, value] of Object.entries(props)) {\n // tslint:disable-next-line\n hasChanged = hasChanged || (value !== (this.lastValues as any)[key]);\n if (hasChanged) break;\n }\n\n const openChanged = this.lastValues.isOpen !== props.isOpen;\n const hasAnchor = !!props.anchorEl;\n const hasSurface = !!props.surfaceEl;\n\n if (hasChanged && hasAnchor && hasSurface) {\n // Only update isOpen, because if it's closed, we do not want to waste\n // time on a useless reposition calculation. So save the other \"dirty\"\n // values until next time it opens.\n this.lastValues.isOpen = props.isOpen;\n\n if (props.isOpen) {\n // We are going to do a reposition, so save the prop values for future\n // dirty checking.\n this.lastValues = props;\n\n await this.position();\n props.onOpen();\n } else if (openChanged) {\n await props.beforeClose();\n this.close();\n props.onClose();\n }\n }\n }\n\n /**\n * Hides the surface.\n */\n private close() {\n this.surfaceStylesInternal = {\n 'display': 'none',\n };\n this.host.requestUpdate();\n }\n}\n"]}
1
+ {"version":3,"file":"surfacePositionController.js","sourceRoot":"","sources":["surfacePositionController.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoBH;;GAEG;AACH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;IAC1B,SAAS,EAAE,WAAW;CACd,CAAC;AA0FX;;;;;GAKG;AACH,MAAM,OAAO,yBAAyB;IAWpC;;;;OAIG;IACH,YACmB,IAA4B,EAC5B,aAAwD;QADxD,SAAI,GAAJ,IAAI,CAAwB;QAC5B,kBAAa,GAAb,aAAa,CAA2C;QAjB3E,8CAA8C;QACtC,0BAAqB,GAAc;YACzC,SAAS,EAAE,MAAM;SAClB,CAAC;QACF,wEAAwE;QACxE,+CAA+C;QACvC,eAAU,GAAwC;YACxD,MAAM,EAAE,KAAK;SACyB,CAAC;QAWvC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,EACJ,SAAS,EACT,QAAQ,EACR,YAAY,EAAE,eAAe,EAC7B,aAAa,EAAE,gBAAgB,EAC/B,WAAW,EACX,OAAO,EACP,OAAO,EACP,kBAAkB,GACnB,GAAG,I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AAM,KAAK,CAAC,WAAW,EAAE,CAAC;gBAC1B,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,KAAK,CAAC,OAAO,EAAE,CAAC;aACjB;SACF;IACH,CAAC;IAED;;OAEG;IACK,KAAK;QACX,IAAI,CAAC,qBAAqB,GAAG;YAC3B,SAAS,EAAE,MAAM;SAClB,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;QAC1B,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,SAAS,CAAC;QAEjD,4EAA4E;QAC5E,mBAAmB;QACnB,IACG,SAA2C,EAAE,OAAO;YACrD,SAAS,EAAE,WAAW,EACtB;YACC,SAAkD,CAAC,WAAW,EAAE,CAAC;SACnE;IACH,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {ReactiveController, ReactiveControllerHost} from 'lit';\nimport {StyleInfo} from 'lit/directives/style-map.js';\n\n/**\n * Declare popoverAPI functions and properties. See\n * https://developer.mozilla.org/en-US/docs/Web/API/Popover_API\n * Without this, closure will rename these functions. Can remove once these\n * functions make it into the typescript lib.\n */\ndeclare global {\n interface HTMLElement {\n showPopover(): void;\n hidePopover(): void;\n togglePopover(force: boolean): void;\n popover: string | null;\n }\n}\n\n/**\n * An enum of supported Menu corners\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const Corner = {\n END_START: 'end-start',\n END_END: 'end-end',\n START_START: 'start-start',\n START_END: 'start-end',\n} as const;\n\n/**\n * A corner of a box in the standard logical property style of <block>_<inline>\n */\nexport type Corner = (typeof Corner)[keyof typeof Corner];\n\n/**\n * An interface that provides a method to customize the rect from which to\n * calculate the anchor positioning. Useful for when you want a surface to\n * anchor to an element in your shadow DOM rather than the host element.\n */\nexport interface SurfacePositionTarget extends HTMLElement {\n getSurfacePositionClientRect?: () => DOMRect;\n}\n\n/**\n * The configurable options for the surface position controller.\n */\nexport interface SurfacePositionControllerProperties {\n /**\n * The corner of the anchor to align the surface's position.\n */\n anchorCorner: Corner;\n /**\n * The corner of the surface to align to the given anchor corner.\n */\n surfaceCorner: Corner;\n /**\n * The HTMLElement reference of the surface to be positioned.\n */\n surfaceEl: SurfacePositionTarget | null;\n /**\n * The HTMLElement reference of the anchor to align to.\n */\n anchorEl: SurfacePositionTarget | null;\n /**\n * Whether the positioning algorithim should calculate relative to the parent\n * of the anchor element (absolute) or relative to the window (fixed).\n *\n * Examples for `position = 'fixed'`:\n *\n * - If there is no `position:relative` in the given parent tree and the\n * surface is `position:absolute`\n * - If the surface is `position:fixed`\n * - If the surface is in the \"top layer\"\n * - The anchor and the surface do not share a common `position:relative`\n * ancestor\n */\n positioning: 'absolute' | 'fixed' | 'document';\n /**\n * Whether or not the surface should be \"open\" and visible\n */\n isOpen: boolean;\n /**\n * The number of pixels in which to offset from the inline axis relative to\n * logical property.\n *\n * Positive is right in LTR and left in RTL.\n */\n xOffset: number;\n /**\n * The number of pixes in which to offset the block axis.\n *\n * Positive is down and negative is up.\n */\n yOffset: number;\n /**\n * The strategy to follow when repositioning the menu to stay inside the\n * viewport. \"move\" will simply move the surface to stay in the viewport.\n * \"resize\" will attempt to resize the surface.\n *\n * Both strategies will still attempt to flip the anchor and surface corners.\n */\n repositionStrategy: 'move' | 'resize';\n /**\n * A function to call after the surface has been positioned.\n */\n onOpen: () => void;\n /**\n * A function to call before the surface should be closed. (A good time to\n * perform animations while the surface is still visible)\n */\n beforeClose: () => Promise<void>;\n /**\n * A function to call after the surface has been closed.\n */\n onClose: () => void;\n}\n\n/**\n * Given a surface, an anchor, corners, and some options, this surface will\n * calculate the position of a surface to align the two given corners and keep\n * the surface inside the window viewport. It also provides a StyleInfo map that\n * can be applied to the surface to handle visiblility and position.\n */\nexport class SurfacePositionController implements ReactiveController {\n // The current styles to apply to the surface.\n private surfaceStylesInternal: StyleInfo = {\n 'display': 'none',\n };\n // Previous values stored for change detection. Open change detection is\n // calculated separately so initialize it here.\n private lastValues: SurfacePositionControllerProperties = {\n isOpen: false,\n } as SurfacePositionControllerProperties;\n\n /**\n * @param host The host to connect the controller to.\n * @param getProperties A function that returns the properties for the\n * controller.\n */\n constructor(\n private readonly host: ReactiveControllerHost,\n private readonly getProperties: () => SurfacePositionControllerProperties,\n ) {\n this.host.addController(this);\n }\n\n /**\n * The StyleInfo map to apply to the surface via Lit's stylemap\n */\n get surfaceStyles() {\n return this.surfaceStylesInternal;\n }\n\n /**\n * Calculates the surface's new position required so that the surface's\n * `surfaceCorner` aligns to the anchor's `anchorCorner` while keeping the\n * surface inside the window viewport. This positioning also respects RTL by\n * checking `getComputedStyle()` on the surface element.\n */\n async position() {\n const {\n surfaceEl,\n anchorEl,\n anchorCorner: anchorCornerRaw,\n surfaceCorner: surfaceCornerRaw,\n positioning,\n xOffset,\n yOffset,\n repositionStrategy,\n } = this.getProperties();\n const anchorCorner = anchorCornerRaw.toLowerCase().trim();\n const surfaceCorner = surfaceCornerRaw.toLowerCase().trim();\n\n if (!surfaceEl || !anchorEl) {\n return;\n }\n\n // Store these before we potentially resize the window with the next set of\n // lines\n const windowInnerWidth = window.innerWidth;\n const windowInnerHeight = window.innerHeight;\n\n const div = document.createElement('div');\n div.style.opacity = '0';\n div.style.position = 'fixed';\n div.style.display = 'block';\n div.style.inset = '0';\n document.body.appendChild(div);\n const scrollbarTestRect = div.getBoundingClientRect();\n div.remove();\n\n // Calculate the widths of the scrollbars in the inline and block directions\n // to account for window-relative calculations.\n const blockScrollbarHeight = window.innerHeight - scrollbarTestRect.bottom;\n const inlineScrollbarWidth = window.innerWidth - scrollbarTestRect.right;\n\n // Paint the surface transparently so that we can get the position and the\n // rect info of the surface.\n this.surfaceStylesInternal = {\n 'display': 'block',\n 'opacity': '0',\n };\n\n // Wait for it to be visible.\n this.host.requestUpdate();\n await this.host.updateComplete;\n\n // Safari has a bug that makes popovers render incorrectly if the node is\n // made visible + Animation Frame before calling showPopover().\n // https://bugs.webkit.org/show_bug.cgi?id=264069\n // also the cast is required due to differing TS types in Google and OSS.\n if (\n (surfaceEl as unknown as {popover: string}).popover &&\n surfaceEl.isConnected\n ) {\n (surfaceEl as unknown as {showPopover: () => void}).showPopover();\n }\n\n const surfaceRect = surfaceEl.getSurfacePositionClientRect\n ? surfaceEl.getSurfacePositionClientRect()\n : surfaceEl.getBoundingClientRect();\n const anchorRect = anchorEl.getSurfacePositionClientRect\n ? anchorEl.getSurfacePositionClientRect()\n : anchorEl.getBoundingClientRect();\n const [surfaceBlock, surfaceInline] = surfaceCorner.split('-') as Array<\n 'start' | 'end'\n >;\n const [anchorBlock, anchorInline] = anchorCorner.split('-') as Array<\n 'start' | 'end'\n >;\n\n // LTR depends on the direction of the SURFACE not the anchor.\n const isLTR =\n getComputedStyle(surfaceEl as HTMLElement).direction === 'ltr';\n\n /*\n * For more on inline and block dimensions, see MDN article:\n * https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values\n *\n * ┌───── inline/blockDocumentOffset inlineScrollbarWidth\n * │ │ │\n * │ ┌─▼─────┐ │Document\n * │ ┌┼───────┴──────────────────────────────┼────────┐\n * │ ││ │ │\n * └──► ││ ┌───── inline/blockWindowOffset │ │\n * ││ │ │ ▼ │\n * ││ │ ┌─▼───┐ Window┌┐ │\n * └┤ │ ┌┼─────┴───────────────────────┼│ │\n * │ │ ││ ││ │\n * │ └──► ││ ┌──inline/blockAnchorOffset││ │\n * │ ││ │ │ ││ │\n * │ └┤ │ ┌──▼───┐ ││ │\n * │ │ │ ┌┼──────┤ ││ │\n * │ │ └─►│Anchor│ ││ │\n * │ │ └┴──────┘ ││ │\n * │ │ ││ │\n * │ │ ┌───────────────────────┼┼────┐ │\n * │ │ │ Surface ││ │ │\n * │ │ │ ││ │ │\n * │ │ │ ││ │ │\n * │ │ │ ││ │ │\n * │ │ │ ││ │ │\n * │ ┌┼─────┼───────────────────────┼│ │ │\n * │ ┌─►┴──────┼────────────────────────┘ ├┐ │\n * │ │ │ inline/blockOOBCorrection ││ │\n * │ │ │ │ ││ │\n * │ │ │ ├──►├│ │\n * │ │ │ │ ││ │\n * │ │ └────────────────────────┐▼───┼┘ │\n * │ blockScrollbarHeight └────┘ │\n * │ │\n * └───────────────────────────────────────────────┘\n */\n\n // Calculate the block positioning properties\n let {blockInset, blockOutOfBoundsCorrection, surfaceBlockProperty} =\n this.calculateBlock({\n surfaceRect,\n anchorRect,\n anchorBlock,\n surfaceBlock,\n yOffset,\n positioning,\n windowInnerHeight,\n blockScrollbarHeight,\n });\n\n // If the surface should be out of bounds in the block direction, flip the\n // surface and anchor corner block values and recalculate\n if (blockOutOfBoundsCorrection) {\n const flippedSurfaceBlock = surfaceBlock === 'start' ? 'end' : 'start';\n const flippedAnchorBlock = anchorBlock === 'start' ? 'end' : 'start';\n\n const flippedBlock = this.calculateBlock({\n surfaceRect,\n anchorRect,\n anchorBlock: flippedAnchorBlock,\n surfaceBlock: flippedSurfaceBlock,\n yOffset,\n positioning,\n windowInnerHeight,\n blockScrollbarHeight,\n });\n\n // In the case that the flipped verion would require less out of bounds\n // correcting, use the flipped corner block values\n if (\n blockOutOfBoundsCorrection > flippedBlock.blockOutOfBoundsCorrection\n ) {\n blockInset = flippedBlock.blockInset;\n blockOutOfBoundsCorrection = flippedBlock.blockOutOfBoundsCorrection;\n surfaceBlockProperty = flippedBlock.surfaceBlockProperty;\n }\n }\n\n // Calculate the inline positioning properties\n let {inlineInset, inlineOutOfBoundsCorrection, surfaceInlineProperty} =\n this.calculateInline({\n surfaceRect,\n anchorRect,\n anchorInline,\n surfaceInline,\n xOffset,\n positioning,\n isLTR,\n windowInnerWidth,\n inlineScrollbarWidth,\n });\n\n // If the surface should be out of bounds in the inline direction, flip the\n // surface and anchor corner inline values and recalculate\n if (inlineOutOfBoundsCorrection) {\n const flippedSurfaceInline = surfaceInline === 'start' ? 'end' : 'start';\n const flippedAnchorInline = anchorInline === 'start' ? 'end' : 'start';\n\n const flippedInline = this.calculateInline({\n surfaceRect,\n anchorRect,\n anchorInline: flippedAnchorInline,\n surfaceInline: flippedSurfaceInline,\n xOffset,\n positioning,\n isLTR,\n windowInnerWidth,\n inlineScrollbarWidth,\n });\n\n // In the case that the flipped verion would require less out of bounds\n // correcting, use the flipped corner inline values\n if (\n Math.abs(inlineOutOfBoundsCorrection) >\n Math.abs(flippedInline.inlineOutOfBoundsCorrection)\n ) {\n inlineInset = flippedInline.inlineInset;\n inlineOutOfBoundsCorrection = flippedInline.inlineOutOfBoundsCorrection;\n surfaceInlineProperty = flippedInline.surfaceInlineProperty;\n }\n }\n\n // If we are simply repositioning the surface back inside the viewport,\n // subtract the out of bounds correction values from the positioning.\n if (repositionStrategy === 'move') {\n blockInset = blockInset - blockOutOfBoundsCorrection;\n inlineInset = inlineInset - inlineOutOfBoundsCorrection;\n }\n\n this.surfaceStylesInternal = {\n 'display': 'block',\n 'opacity': '1',\n [surfaceBlockProperty]: `${blockInset}px`,\n [surfaceInlineProperty]: `${inlineInset}px`,\n };\n\n // In the case that we are resizing the surface to stay inside the viewport\n // we need to set height and width on the surface.\n if (repositionStrategy === 'resize') {\n // Add a height property to the styles if there is block height correction\n if (blockOutOfBoundsCorrection) {\n this.surfaceStylesInternal['height'] = `${\n surfaceRect.height - blockOutOfBoundsCorrection\n }px`;\n }\n\n // Add a width property to the styles if there is block height correction\n if (inlineOutOfBoundsCorrection) {\n this.surfaceStylesInternal['width'] = `${\n surfaceRect.width - inlineOutOfBoundsCorrection\n }px`;\n }\n }\n\n this.host.requestUpdate();\n }\n\n /**\n * Calculates the css property, the inset, and the out of bounds correction\n * for the surface in the block direction.\n */\n private calculateBlock(config: {\n surfaceRect: DOMRect;\n anchorRect: DOMRect;\n anchorBlock: 'start' | 'end';\n surfaceBlock: 'start' | 'end';\n yOffset: number;\n positioning: 'absolute' | 'fixed' | 'document';\n windowInnerHeight: number;\n blockScrollbarHeight: number;\n }) {\n const {\n surfaceRect,\n anchorRect,\n anchorBlock,\n surfaceBlock,\n yOffset,\n positioning,\n windowInnerHeight,\n blockScrollbarHeight,\n } = config;\n // We use number booleans to multiply values rather than `if` / ternary\n // statements because it _heavily_ cuts down on nesting and readability\n const relativeToWindow =\n positioning === 'fixed' || positioning === 'document' ? 1 : 0;\n const relativeToDocument = positioning === 'document' ? 1 : 0;\n const isSurfaceBlockStart = surfaceBlock === 'start' ? 1 : 0;\n const isSurfaceBlockEnd = surfaceBlock === 'end' ? 1 : 0;\n const isOneBlockEnd = anchorBlock !== surfaceBlock ? 1 : 0;\n\n // Whether or not to apply the height of the anchor\n const blockAnchorOffset = isOneBlockEnd * anchorRect.height + yOffset;\n // The absolute block position of the anchor relative to window\n const blockTopLayerOffset =\n isSurfaceBlockStart * anchorRect.top +\n isSurfaceBlockEnd *\n (windowInnerHeight - anchorRect.bottom - blockScrollbarHeight);\n const blockDocumentOffset =\n isSurfaceBlockStart * window.scrollY - isSurfaceBlockEnd * window.scrollY;\n\n // If the surface's block would be out of bounds of the window, move it back\n // in\n const blockOutOfBoundsCorrection = Math.abs(\n Math.min(\n 0,\n windowInnerHeight -\n blockTopLayerOffset -\n blockAnchorOffset -\n surfaceRect.height,\n ),\n );\n\n // The block logical value of the surface\n const blockInset =\n relativeToWindow * blockTopLayerOffset +\n relativeToDocument * blockDocumentOffset +\n blockAnchorOffset;\n\n const surfaceBlockProperty =\n surfaceBlock === 'start' ? 'inset-block-start' : 'inset-block-end';\n\n return {blockInset, blockOutOfBoundsCorrection, surfaceBlockProperty};\n }\n\n /**\n * Calculates the css property, the inset, and the out of bounds correction\n * for the surface in the inline direction.\n */\n private calculateInline(config: {\n isLTR: boolean;\n surfaceInline: 'start' | 'end';\n anchorInline: 'start' | 'end';\n anchorRect: DOMRect;\n surfaceRect: DOMRect;\n xOffset: number;\n positioning: 'absolute' | 'fixed' | 'document';\n windowInnerWidth: number;\n inlineScrollbarWidth: number;\n }) {\n const {\n isLTR: isLTRBool,\n surfaceInline,\n anchorInline,\n anchorRect,\n surfaceRect,\n xOffset,\n positioning,\n windowInnerWidth,\n inlineScrollbarWidth,\n } = config;\n // We use number booleans to multiply values rather than `if` / ternary\n // statements because it _heavily_ cuts down on nesting and readability\n const relativeToWindow =\n positioning === 'fixed' || positioning === 'document' ? 1 : 0;\n const relativeToDocument = positioning === 'document' ? 1 : 0;\n const isLTR = isLTRBool ? 1 : 0;\n const isRTL = isLTRBool ? 0 : 1;\n const isSurfaceInlineStart = surfaceInline === 'start' ? 1 : 0;\n const isSurfaceInlineEnd = surfaceInline === 'end' ? 1 : 0;\n const isOneInlineEnd = anchorInline !== surfaceInline ? 1 : 0;\n\n // Whether or not to apply the width of the anchor\n const inlineAnchorOffset = isOneInlineEnd * anchorRect.width + xOffset;\n // The inline position of the anchor relative to window in LTR\n const inlineTopLayerOffsetLTR =\n isSurfaceInlineStart * anchorRect.left +\n isSurfaceInlineEnd *\n (windowInnerWidth - anchorRect.right - inlineScrollbarWidth);\n // The inline position of the anchor relative to window in RTL\n const inlineTopLayerOffsetRTL =\n isSurfaceInlineStart *\n (windowInnerWidth - anchorRect.right - inlineScrollbarWidth) +\n isSurfaceInlineEnd * anchorRect.left;\n // The inline position of the anchor relative to window\n const inlineTopLayerOffset =\n isLTR * inlineTopLayerOffsetLTR + isRTL * inlineTopLayerOffsetRTL;\n\n // The inline position of the anchor relative to window in LTR\n const inlineDocumentOffsetLTR =\n isSurfaceInlineStart * window.scrollX -\n isSurfaceInlineEnd * window.scrollX;\n // The inline position of the anchor relative to window in RTL\n const inlineDocumentOffsetRTL =\n isSurfaceInlineEnd * window.scrollX -\n isSurfaceInlineStart * window.scrollX;\n // The inline position of the anchor relative to window\n const inlineDocumentOffset =\n isLTR * inlineDocumentOffsetLTR + isRTL * inlineDocumentOffsetRTL;\n\n // If the surface's inline would be out of bounds of the window, move it\n // back in\n const inlineOutOfBoundsCorrection = Math.abs(\n Math.min(\n 0,\n windowInnerWidth -\n inlineTopLayerOffset -\n inlineAnchorOffset -\n surfaceRect.width,\n ),\n );\n\n // The inline logical value of the surface\n const inlineInset =\n relativeToWindow * inlineTopLayerOffset +\n inlineAnchorOffset +\n relativeToDocument * inlineDocumentOffset;\n\n let surfaceInlineProperty =\n surfaceInline === 'start' ? 'inset-inline-start' : 'inset-inline-end';\n\n // There are cases where the element is RTL but the root of the page is not.\n // In these cases we want to not use logical properties.\n if (positioning === 'document' || positioning === 'fixed') {\n if (\n (surfaceInline === 'start' && isLTRBool) ||\n (surfaceInline === 'end' && !isLTRBool)\n ) {\n surfaceInlineProperty = 'left';\n } else {\n surfaceInlineProperty = 'right';\n }\n }\n\n return {\n inlineInset,\n inlineOutOfBoundsCorrection,\n surfaceInlineProperty,\n };\n }\n\n hostUpdate() {\n this.onUpdate();\n }\n\n hostUpdated() {\n this.onUpdate();\n }\n\n /**\n * Checks whether the properties passed into the controller have changed since\n * the last positioning. If so, it will reposition if the surface is open or\n * close it if the surface should close.\n */\n private async onUpdate() {\n const props = this.getProperties();\n let hasChanged = false;\n for (const [key, value] of Object.entries(props)) {\n // tslint:disable-next-line\n hasChanged = hasChanged || value !== (this.lastValues as any)[key];\n if (hasChanged) break;\n }\n\n const openChanged = this.lastValues.isOpen !== props.isOpen;\n const hasAnchor = !!props.anchorEl;\n const hasSurface = !!props.surfaceEl;\n\n if (hasChanged && hasAnchor && hasSurface) {\n // Only update isOpen, because if it's closed, we do not want to waste\n // time on a useless reposition calculation. So save the other \"dirty\"\n // values until next time it opens.\n this.lastValues.isOpen = props.isOpen;\n\n if (props.isOpen) {\n // We are going to do a reposition, so save the prop values for future\n // dirty checking.\n this.lastValues = props;\n\n await this.position();\n props.onOpen();\n } else if (openChanged) {\n await props.beforeClose();\n this.close();\n props.onClose();\n }\n }\n }\n\n /**\n * Hides the surface.\n */\n private close() {\n this.surfaceStylesInternal = {\n 'display': 'none',\n };\n this.host.requestUpdate();\n const surfaceEl = this.getProperties().surfaceEl;\n\n // The following type casts are required due to differing TS types in Google\n // and open source.\n if (\n (surfaceEl as unknown as {popover?: string})?.popover &&\n surfaceEl?.isConnected\n ) {\n (surfaceEl as unknown as {hidePopover: () => void}).hidePopover();\n }\n }\n}\n"]}
@@ -112,17 +112,22 @@ export class TypeaheadController {
112
112
  // We don't want to typeahead if the _beginning_ of the typeahead is a menu
113
113
  // navigation, or a selection. We will handle "Space" only if it's in the
114
114
  // middle of a typeahead
115
- if (event.code === 'Space' || event.code === 'Enter' ||
116
- event.code.startsWith('Arrow') || event.code === 'Escape') {
115
+ if (event.code === 'Space' ||
116
+ event.code === 'Enter' ||
117
+ event.code.startsWith('Arrow') ||
118
+ event.code === 'Escape') {
117
119
  return;
118
120
  }
119
121
  this.isTypingAhead = true;
120
122
  // Generates the record array data structure which is the index, the element
121
123
  // and a normalized header.
122
- this.typeaheadRecords = this.items.map((el, index) => [index, el, el.typeaheadText.trim().toLowerCase()]);
124
+ this.typeaheadRecords = this.items.map((el, index) => [
125
+ index,
126
+ el,
127
+ el.typeaheadText.trim().toLowerCase(),
128
+ ]);
123
129
  this.lastActiveRecord =
124
- this.typeaheadRecords.find(record => (record[TYPEAHEAD_RECORD.ITEM].tabIndex === 0)) ??
125
- null;
130
+ this.typeaheadRecords.find((record) => record[TYPEAHEAD_RECORD.ITEM].tabIndex === 0) ?? null;
126
131
  if (this.lastActiveRecord) {
127
132
  this.lastActiveRecord[TYPEAHEAD_RECORD.ITEM].tabIndex = -1;
128
133
  }
@@ -170,7 +175,8 @@ export class TypeaheadController {
170
175
  clearTimeout(this.cancelTypeaheadTimeout);
171
176
  // Stop typingahead if one of the navigation or selection keys (except for
172
177
  // Space) are pressed
173
- if (event.code === 'Enter' || event.code.startsWith('Arrow') ||
178
+ if (event.code === 'Enter' ||
179
+ event.code.startsWith('Arrow') ||
174
180
  event.code === 'Escape') {
175
181
  this.endTypeahead();
176
182
  if (this.lastActiveRecord) {
@@ -183,12 +189,11 @@ export class TypeaheadController {
183
189
  event.preventDefault();
184
190
  }
185
191
  // Start up a new keystroke buffer timeout
186
- this.cancelTypeaheadTimeout =
187
- setTimeout(this.endTypeahead, this.getProperties().typeaheadBufferTime);
192
+ this.cancelTypeaheadTimeout = setTimeout(this.endTypeahead, this.getProperties().typeaheadBufferTime);
188
193
  this.typaheadBuffer += event.key.toLowerCase();
189
- const lastActiveIndex = this.lastActiveRecord ?
190
- this.lastActiveRecord[TYPEAHEAD_RECORD.INDEX] :
191
- -1;
194
+ const lastActiveIndex = this.lastActiveRecord
195
+ ? this.lastActiveRecord[TYPEAHEAD_RECORD.INDEX]
196
+ : -1;
192
197
  const numRecords = this.typeaheadRecords.length;
193
198
  /**
194
199
  * Sorting function that will resort the items starting with the given index
@@ -213,12 +218,12 @@ export class TypeaheadController {
213
218
  * 5: [2, <reference>, 'banana']
214
219
  */
215
220
  const rebaseIndexOnActive = (record) => {
216
- return (record[TYPEAHEAD_RECORD.INDEX] + numRecords - lastActiveIndex) %
217
- numRecords;
221
+ return ((record[TYPEAHEAD_RECORD.INDEX] + numRecords - lastActiveIndex) %
222
+ numRecords);
218
223
  };
219
224
  // records filtered and sorted / rebased around the last active index
220
225
  const matchingRecords = this.typeaheadRecords
221
- .filter(record => !record[TYPEAHEAD_RECORD.ITEM].disabled &&
226
+ .filter((record) => !record[TYPEAHEAD_RECORD.ITEM].disabled &&
222
227
  record[TYPEAHEAD_RECORD.TEXT].startsWith(this.typaheadBuffer))
223
228
  .sort((a, b) => rebaseIndexOnActive(a) - rebaseIndexOnActive(b));
224
229
  // Just leave if there's nothing that matches. Native select will just
@@ -1 +1 @@
1
- {"version":3,"file":"typeaheadController.js","sourceRoot":"","sources":["typeaheadController.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA8BH;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;CACC,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,mBAAmB;IAsB9B;;;;;;;;;OASG;IACH,YACqB,aAAkD;QAA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YAC1C,IAAI,IAAI,CAAC,gBAAgB,EAAE;gBACzB,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;aAC5D;YACD,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,OAAO;SACR;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,CAAC;QACpD,IAAI,UAA2B,CAAC;QAEhC,4EAA4E;QAC5E,0CAA0C;QAC1C,IAAI,IAAI,CAAC,gBAAgB,KAAK,eAAe,CAAC,CAAC,CAAC,IAAI,UAAU,EAAE;YAC9D,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC;SACvD;aAAM;YACL,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;SACjC;QAED,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACzB,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;SAC5D;QAED,IAAI,CAAC,gBAAgB,GAAG,UAAU,CAAC;QACnC,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;QAC/C,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;QAC1C,OAAO;IACT,CAAC;CAUF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {MenuItem} from './menuItemController.js';\n\n/**\n * The options that are passed to the typeahead controller.\n */\nexport interface TypeaheadControllerProperties {\n /**\n * A function that returns an array of menu items to be searched.\n * @return An array of menu items to be searched by typing.\n */\n getItems: () => MenuItem[];\n /**\n * The maximum time between each keystroke to keep the current type buffer\n * alive.\n */\n typeaheadBufferTime: number;\n /**\n * Whether or not the typeahead should listen for keystrokes or not.\n */\n active: boolean;\n}\n\n/**\n * Data structure tuple that helps with indexing.\n *\n * [index, item, normalized header text]\n */\ntype TypeaheadRecord = [number, MenuItem, string];\n/**\n * Indicies to access the TypeaheadRecord tuple type.\n */\nexport const TYPEAHEAD_RECORD = {\n INDEX: 0,\n ITEM: 1,\n TEXT: 2,\n} as const;\n\n/**\n * This controller listens to `keydown` events and searches the header text of\n * an array of `MenuItem`s with the corresponding entered keys within the buffer\n * time and activates the item.\n *\n * @example\n * ```ts\n * const typeaheadController = new TypeaheadController(() => ({\n * typeaheadBufferTime: 50,\n * getItems: () => Array.from(document.querySelectorAll('md-menu-item'))\n * }));\n * html`\n * <div\n * @keydown=${typeaheadController.onKeydown}\n * tabindex=\"0\"\n * class=\"activeItemText\">\n * <!-- focusable element that will receive keydown events -->\n * Apple\n * </div>\n * <div>\n * <md-menu-item active header=\"Apple\"></md-menu-item>\n * <md-menu-item header=\"Apricot\"></md-menu-item>\n * <md-menu-item header=\"Banana\"></md-menu-item>\n * <md-menu-item header=\"Olive\"></md-menu-item>\n * <md-menu-item header=\"Orange\"></md-menu-item>\n * </div>\n * `;\n * ```\n */\nexport class TypeaheadController {\n /**\n * Array of tuples that helps with indexing.\n */\n private typeaheadRecords: TypeaheadRecord[] = [];\n /**\n * Currently-typed text since last buffer timeout\n */\n private typaheadBuffer = '';\n /**\n * The timeout id from the current buffer's setTimeout\n */\n private cancelTypeaheadTimeout = 0;\n /**\n * If we are currently \"typing\"\n */\n isTypingAhead = false;\n /**\n * The record of the last active item.\n */\n lastActiveRecord: TypeaheadRecord|null = null;\n\n /**\n * @param getProperties A function that returns the options of the typeahead\n * controller:\n *\n * {\n * getItems: A function that returns an array of menu items to be searched.\n * typeaheadBufferTime: The maximum time between each keystroke to keep the\n * current type buffer alive.\n * }\n */\n constructor(\n private readonly getProperties: () => TypeaheadControllerProperties,\n ) {}\n\n private get items() {\n return this.getProperties().getItems();\n }\n\n private get active() {\n return this.getProperties().active;\n }\n\n /**\n * Apply this listener to the element that will receive `keydown` events that\n * should trigger this controller.\n *\n * @param event The native browser `KeyboardEvent` from the `keydown` event.\n */\n readonly onKeydown = (event: KeyboardEvent) => {\n if (this.isTypingAhead) {\n this.typeahead(event);\n } else {\n this.beginTypeahead(event);\n }\n };\n\n /**\n * Sets up typingahead\n */\n private beginTypeahead(event: KeyboardEvent) {\n if (!this.active) {\n return;\n }\n\n // We don't want to typeahead if the _beginning_ of the typeahead is a menu\n // navigation, or a selection. We will handle \"Space\" only if it's in the\n // middle of a typeahead\n if (event.code === 'Space' || event.code === 'Enter' ||\n event.code.startsWith('Arrow') || event.code === 'Escape') {\n return;\n }\n\n this.isTypingAhead = true;\n // Generates the record array data structure which is the index, the element\n // and a normalized header.\n this.typeaheadRecords = this.items.map(\n (el, index) => [index, el, el.typeaheadText.trim().toLowerCase()]);\n this.lastActiveRecord =\n this.typeaheadRecords.find(\n record => (record[TYPEAHEAD_RECORD.ITEM].tabIndex === 0)) ??\n null;\n if (this.lastActiveRecord) {\n this.lastActiveRecord[TYPEAHEAD_RECORD.ITEM].tabIndex = -1;\n }\n this.typeahead(event);\n }\n\n /**\n * Performs the typeahead. Based on the normalized items and the current text\n * buffer, finds the _next_ item with matching text and activates it.\n *\n * @example\n *\n * items: Apple, Banana, Olive, Orange, Cucumber\n * buffer: ''\n * user types: o\n *\n * activates Olive\n *\n * @example\n *\n * items: Apple, Banana, Olive (active), Orange, Cucumber\n * buffer: 'o'\n * user types: l\n *\n * activates Olive\n *\n * @example\n *\n * items: Apple, Banana, Olive (active), Orange, Cucumber\n * buffer: ''\n * user types: o\n *\n * activates Orange\n *\n * @example\n *\n * items: Apple, Banana, Olive, Orange (active), Cucumber\n * buffer: ''\n * user types: o\n *\n * activates Olive\n */\n private typeahead(event: KeyboardEvent) {\n if (event.defaultPrevented) return;\n clearTimeout(this.cancelTypeaheadTimeout);\n // Stop typingahead if one of the navigation or selection keys (except for\n // Space) are pressed\n if (event.code === 'Enter' || event.code.startsWith('Arrow') ||\n event.code === 'Escape') {\n this.endTypeahead();\n if (this.lastActiveRecord) {\n this.lastActiveRecord[TYPEAHEAD_RECORD.ITEM].tabIndex = -1;\n }\n return;\n }\n\n // If Space is pressed, prevent it from selecting and closing the menu\n if (event.code === 'Space') {\n event.preventDefault();\n }\n\n // Start up a new keystroke buffer timeout\n this.cancelTypeaheadTimeout =\n setTimeout(this.endTypeahead, this.getProperties().typeaheadBufferTime);\n\n this.typaheadBuffer += event.key.toLowerCase();\n\n const lastActiveIndex = this.lastActiveRecord ?\n this.lastActiveRecord[TYPEAHEAD_RECORD.INDEX] :\n -1;\n const numRecords = this.typeaheadRecords.length;\n\n /**\n * Sorting function that will resort the items starting with the given index\n *\n * @example\n *\n * this.typeaheadRecords =\n * 0: [0, <reference>, 'apple']\n * 1: [1, <reference>, 'apricot']\n * 2: [2, <reference>, 'banana']\n * 3: [3, <reference>, 'olive'] <-- lastActiveIndex\n * 4: [4, <reference>, 'orange']\n * 5: [5, <reference>, 'strawberry']\n *\n * this.typeaheadRecords.sort((a,b) => rebaseIndexOnActive(a)\n * - rebaseIndexOnActive(b)) ===\n * 0: [3, <reference>, 'olive'] <-- lastActiveIndex\n * 1: [4, <reference>, 'orange']\n * 2: [5, <reference>, 'strawberry']\n * 3: [0, <reference>, 'apple']\n * 4: [1, <reference>, 'apricot']\n * 5: [2, <reference>, 'banana']\n */\n const rebaseIndexOnActive = (record: TypeaheadRecord) => {\n return (record[TYPEAHEAD_RECORD.INDEX] + numRecords - lastActiveIndex) %\n numRecords;\n };\n\n // records filtered and sorted / rebased around the last active index\n const matchingRecords =\n this.typeaheadRecords\n .filter(\n record => !record[TYPEAHEAD_RECORD.ITEM].disabled &&\n record[TYPEAHEAD_RECORD.TEXT].startsWith(\n this.typaheadBuffer))\n .sort((a, b) => rebaseIndexOnActive(a) - rebaseIndexOnActive(b));\n\n // Just leave if there's nothing that matches. Native select will just\n // choose the first thing that starts with the next letter in the alphabet\n // but that's out of scope and hard to localize\n if (matchingRecords.length === 0) {\n clearTimeout(this.cancelTypeaheadTimeout);\n if (this.lastActiveRecord) {\n this.lastActiveRecord[TYPEAHEAD_RECORD.ITEM].tabIndex = -1;\n }\n this.endTypeahead();\n return;\n }\n\n const isNewQuery = this.typaheadBuffer.length === 1;\n let nextRecord: TypeaheadRecord;\n\n // This is likely the case that someone is trying to \"tab\" through different\n // entries that start with the same letter\n if (this.lastActiveRecord === matchingRecords[0] && isNewQuery) {\n nextRecord = matchingRecords[1] ?? matchingRecords[0];\n } else {\n nextRecord = matchingRecords[0];\n }\n\n if (this.lastActiveRecord) {\n this.lastActiveRecord[TYPEAHEAD_RECORD.ITEM].tabIndex = -1;\n }\n\n this.lastActiveRecord = nextRecord;\n nextRecord[TYPEAHEAD_RECORD.ITEM].tabIndex = 0;\n nextRecord[TYPEAHEAD_RECORD.ITEM].focus();\n return;\n }\n\n /**\n * Ends the current typeahead and clears the buffer.\n */\n private readonly endTypeahead = () => {\n this.isTypingAhead = false;\n this.typaheadBuffer = '';\n this.typeaheadRecords = [];\n };\n}\n"]}
1
+ {"version":3,"file":"typeaheadController.js","sourceRoot":"","sources":["typeaheadController.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA8BH;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;CACC,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,mBAAmB;IAsB9B;;;;;;;;;OASG;IACH,YACmB,aAAkD;QAAlD,kBAAa,GAAb,aAAa,CAAqC;QAhCrE;;WAEG;QACK,qBAAgB,GAAsB,EAAE,CAAC;QACjD;;WAEG;QACK,mBAAc,GAAG,EAAE,CAAC;QAC5B;;WAEG;QACK,2BAAsB,GAAG,CAAC,CAAC;QACnC;;WAEG;QACH,kBAAa,GAAG,KAAK,CAAC;QACtB;;WAEG;QACH,qBAAgB,GAA2B,IAAI,CAAC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AAC,CAAC;QACpD,IAAI,UAA2B,CAAC;QAEhC,4EAA4E;QAC5E,0CAA0C;QAC1C,IAAI,IAAI,CAAC,gBAAgB,KAAK,eAAe,CAAC,CAAC,CAAC,IAAI,UAAU,EAAE;YAC9D,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC;SACvD;aAAM;YACL,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;SACjC;QAED,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACzB,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;SAC5D;QAED,IAAI,CAAC,gBAAgB,GAAG,UAAU,CAAC;QACnC,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;QAC/C,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;QAC1C,OAAO;IACT,CAAC;CAUF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {MenuItem} from './menuItemController.js';\n\n/**\n * The options that are passed to the typeahead controller.\n */\nexport interface TypeaheadControllerProperties {\n /**\n * A function that returns an array of menu items to be searched.\n * @return An array of menu items to be searched by typing.\n */\n getItems: () => MenuItem[];\n /**\n * The maximum time between each keystroke to keep the current type buffer\n * alive.\n */\n typeaheadBufferTime: number;\n /**\n * Whether or not the typeahead should listen for keystrokes or not.\n */\n active: boolean;\n}\n\n/**\n * Data structure tuple that helps with indexing.\n *\n * [index, item, normalized header text]\n */\ntype TypeaheadRecord = [number, MenuItem, string];\n/**\n * Indicies to access the TypeaheadRecord tuple type.\n */\nexport const TYPEAHEAD_RECORD = {\n INDEX: 0,\n ITEM: 1,\n TEXT: 2,\n} as const;\n\n/**\n * This controller listens to `keydown` events and searches the header text of\n * an array of `MenuItem`s with the corresponding entered keys within the buffer\n * time and activates the item.\n *\n * @example\n * ```ts\n * const typeaheadController = new TypeaheadController(() => ({\n * typeaheadBufferTime: 50,\n * getItems: () => Array.from(document.querySelectorAll('md-menu-item'))\n * }));\n * html`\n * <div\n * @keydown=${typeaheadController.onKeydown}\n * tabindex=\"0\"\n * class=\"activeItemText\">\n * <!-- focusable element that will receive keydown events -->\n * Apple\n * </div>\n * <div>\n * <md-menu-item active header=\"Apple\"></md-menu-item>\n * <md-menu-item header=\"Apricot\"></md-menu-item>\n * <md-menu-item header=\"Banana\"></md-menu-item>\n * <md-menu-item header=\"Olive\"></md-menu-item>\n * <md-menu-item header=\"Orange\"></md-menu-item>\n * </div>\n * `;\n * ```\n */\nexport class TypeaheadController {\n /**\n * Array of tuples that helps with indexing.\n */\n private typeaheadRecords: TypeaheadRecord[] = [];\n /**\n * Currently-typed text since last buffer timeout\n */\n private typaheadBuffer = '';\n /**\n * The timeout id from the current buffer's setTimeout\n */\n private cancelTypeaheadTimeout = 0;\n /**\n * If we are currently \"typing\"\n */\n isTypingAhead = false;\n /**\n * The record of the last active item.\n */\n lastActiveRecord: TypeaheadRecord | null = null;\n\n /**\n * @param getProperties A function that returns the options of the typeahead\n * controller:\n *\n * {\n * getItems: A function that returns an array of menu items to be searched.\n * typeaheadBufferTime: The maximum time between each keystroke to keep the\n * current type buffer alive.\n * }\n */\n constructor(\n private readonly getProperties: () => TypeaheadControllerProperties,\n ) {}\n\n private get items() {\n return this.getProperties().getItems();\n }\n\n private get active() {\n return this.getProperties().active;\n }\n\n /**\n * Apply this listener to the element that will receive `keydown` events that\n * should trigger this controller.\n *\n * @param event The native browser `KeyboardEvent` from the `keydown` event.\n */\n readonly onKeydown = (event: KeyboardEvent) => {\n if (this.isTypingAhead) {\n this.typeahead(event);\n } else {\n this.beginTypeahead(event);\n }\n };\n\n /**\n * Sets up typingahead\n */\n private beginTypeahead(event: KeyboardEvent) {\n if (!this.active) {\n return;\n }\n\n // We don't want to typeahead if the _beginning_ of the typeahead is a menu\n // navigation, or a selection. We will handle \"Space\" only if it's in the\n // middle of a typeahead\n if (\n event.code === 'Space' ||\n event.code === 'Enter' ||\n event.code.startsWith('Arrow') ||\n event.code === 'Escape'\n ) {\n return;\n }\n\n this.isTypingAhead = true;\n // Generates the record array data structure which is the index, the element\n // and a normalized header.\n this.typeaheadRecords = this.items.map((el, index) => [\n index,\n el,\n el.typeaheadText.trim().toLowerCase(),\n ]);\n this.lastActiveRecord =\n this.typeaheadRecords.find(\n (record) => record[TYPEAHEAD_RECORD.ITEM].tabIndex === 0,\n ) ?? null;\n if (this.lastActiveRecord) {\n this.lastActiveRecord[TYPEAHEAD_RECORD.ITEM].tabIndex = -1;\n }\n this.typeahead(event);\n }\n\n /**\n * Performs the typeahead. Based on the normalized items and the current text\n * buffer, finds the _next_ item with matching text and activates it.\n *\n * @example\n *\n * items: Apple, Banana, Olive, Orange, Cucumber\n * buffer: ''\n * user types: o\n *\n * activates Olive\n *\n * @example\n *\n * items: Apple, Banana, Olive (active), Orange, Cucumber\n * buffer: 'o'\n * user types: l\n *\n * activates Olive\n *\n * @example\n *\n * items: Apple, Banana, Olive (active), Orange, Cucumber\n * buffer: ''\n * user types: o\n *\n * activates Orange\n *\n * @example\n *\n * items: Apple, Banana, Olive, Orange (active), Cucumber\n * buffer: ''\n * user types: o\n *\n * activates Olive\n */\n private typeahead(event: KeyboardEvent) {\n if (event.defaultPrevented) return;\n clearTimeout(this.cancelTypeaheadTimeout);\n // Stop typingahead if one of the navigation or selection keys (except for\n // Space) are pressed\n if (\n event.code === 'Enter' ||\n event.code.startsWith('Arrow') ||\n event.code === 'Escape'\n ) {\n this.endTypeahead();\n if (this.lastActiveRecord) {\n this.lastActiveRecord[TYPEAHEAD_RECORD.ITEM].tabIndex = -1;\n }\n return;\n }\n\n // If Space is pressed, prevent it from selecting and closing the menu\n if (event.code === 'Space') {\n event.preventDefault();\n }\n\n // Start up a new keystroke buffer timeout\n this.cancelTypeaheadTimeout = setTimeout(\n this.endTypeahead,\n this.getProperties().typeaheadBufferTime,\n );\n\n this.typaheadBuffer += event.key.toLowerCase();\n\n const lastActiveIndex = this.lastActiveRecord\n ? this.lastActiveRecord[TYPEAHEAD_RECORD.INDEX]\n : -1;\n const numRecords = this.typeaheadRecords.length;\n\n /**\n * Sorting function that will resort the items starting with the given index\n *\n * @example\n *\n * this.typeaheadRecords =\n * 0: [0, <reference>, 'apple']\n * 1: [1, <reference>, 'apricot']\n * 2: [2, <reference>, 'banana']\n * 3: [3, <reference>, 'olive'] <-- lastActiveIndex\n * 4: [4, <reference>, 'orange']\n * 5: [5, <reference>, 'strawberry']\n *\n * this.typeaheadRecords.sort((a,b) => rebaseIndexOnActive(a)\n * - rebaseIndexOnActive(b)) ===\n * 0: [3, <reference>, 'olive'] <-- lastActiveIndex\n * 1: [4, <reference>, 'orange']\n * 2: [5, <reference>, 'strawberry']\n * 3: [0, <reference>, 'apple']\n * 4: [1, <reference>, 'apricot']\n * 5: [2, <reference>, 'banana']\n */\n const rebaseIndexOnActive = (record: TypeaheadRecord) => {\n return (\n (record[TYPEAHEAD_RECORD.INDEX] + numRecords - lastActiveIndex) %\n numRecords\n );\n };\n\n // records filtered and sorted / rebased around the last active index\n const matchingRecords = this.typeaheadRecords\n .filter(\n (record) =>\n !record[TYPEAHEAD_RECORD.ITEM].disabled &&\n record[TYPEAHEAD_RECORD.TEXT].startsWith(this.typaheadBuffer),\n )\n .sort((a, b) => rebaseIndexOnActive(a) - rebaseIndexOnActive(b));\n\n // Just leave if there's nothing that matches. Native select will just\n // choose the first thing that starts with the next letter in the alphabet\n // but that's out of scope and hard to localize\n if (matchingRecords.length === 0) {\n clearTimeout(this.cancelTypeaheadTimeout);\n if (this.lastActiveRecord) {\n this.lastActiveRecord[TYPEAHEAD_RECORD.ITEM].tabIndex = -1;\n }\n this.endTypeahead();\n return;\n }\n\n const isNewQuery = this.typaheadBuffer.length === 1;\n let nextRecord: TypeaheadRecord;\n\n // This is likely the case that someone is trying to \"tab\" through different\n // entries that start with the same letter\n if (this.lastActiveRecord === matchingRecords[0] && isNewQuery) {\n nextRecord = matchingRecords[1] ?? matchingRecords[0];\n } else {\n nextRecord = matchingRecords[0];\n }\n\n if (this.lastActiveRecord) {\n this.lastActiveRecord[TYPEAHEAD_RECORD.ITEM].tabIndex = -1;\n }\n\n this.lastActiveRecord = nextRecord;\n nextRecord[TYPEAHEAD_RECORD.ITEM].tabIndex = 0;\n nextRecord[TYPEAHEAD_RECORD.ITEM].focus();\n return;\n }\n\n /**\n * Ends the current typeahead and clears the buffer.\n */\n private readonly endTypeahead = () => {\n this.isTypingAhead = false;\n this.typaheadBuffer = '';\n this.typeaheadRecords = [];\n };\n}\n"]}
@@ -4,6 +4,6 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { css } from 'lit';
7
- export const styles = css `:host{--md-elevation-level: var(--md-menu-container-elevation, 2);--md-elevation-shadow-color: var(--md-menu-container-shadow-color, var(--md-sys-color-shadow, #000));min-width:112px;color:unset;display:contents}md-focus-ring{--md-focus-ring-shape: var(--md-menu-container-shape, 4px)}.menu{border-radius:var(--md-menu-container-shape, 4px);display:none;opacity:0;z-index:20;position:absolute;user-select:none;max-height:inherit;height:inherit;min-width:inherit;max-width:inherit}.fixed{position:fixed}.items{display:block;list-style-type:none;margin:0;outline:none;box-sizing:border-box;background-color:var(--md-menu-container-color, var(--md-sys-color-surface-container, #f3edf7));height:inherit;max-height:inherit;overflow:auto;min-width:inherit;max-width:inherit;border-radius:inherit}.item-padding{padding-block:8px}.has-overflow .items{overflow:visible}.animating .items{overflow:hidden}.has-overflow.animating .items{pointer-events:none}.animating ::slotted(.md-menu-hidden){opacity:0}slot{display:block;height:inherit;max-height:inherit}::slotted(:is(md-divider,[role=separator])){margin:8px 0}/*# sourceMappingURL=menu-styles.css.map */
7
+ export const styles = css `:host{--md-elevation-level: var(--md-menu-container-elevation, 2);--md-elevation-shadow-color: var(--md-menu-container-shadow-color, var(--md-sys-color-shadow, #000));min-width:112px;color:unset;display:contents}md-focus-ring{--md-focus-ring-shape: var(--md-menu-container-shape, 4px)}.menu{border-radius:var(--md-menu-container-shape, 4px);display:none;inset:auto;border:none;padding:0px;overflow:visible;background-color:rgba(0,0,0,0);opacity:0;z-index:20;position:absolute;user-select:none;max-height:inherit;height:inherit;min-width:inherit;max-width:inherit}.menu::backdrop{display:none}.fixed{position:fixed}.items{display:block;list-style-type:none;margin:0;outline:none;box-sizing:border-box;background-color:var(--md-menu-container-color, var(--md-sys-color-surface-container, #f3edf7));height:inherit;max-height:inherit;overflow:auto;min-width:inherit;max-width:inherit;border-radius:inherit}.item-padding{padding-block:8px}.has-overflow:not([popover]) .items{overflow:visible}.has-overflow.animating .items,.animating .items{overflow:hidden}.has-overflow.animating .items{pointer-events:none}.animating ::slotted(.md-menu-hidden){opacity:0}slot{display:block;height:inherit;max-height:inherit}::slotted(:is(md-divider,[role=separator])){margin:8px 0}@media(forced-colors: active){.menu{border-style:solid;border-color:CanvasText;border-width:1px}}/*# sourceMappingURL=menu-styles.css.map */
8
8
  `;
9
9
  //# sourceMappingURL=menu-styles.css.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"menu-styles.css.js","sourceRoot":"","sources":["menu-styles.css.ts"],"names":[],"mappings":"AAAA;;;;IAII;AACH,OAAO,EAAC,GAAG,EAAC,MAAM,KAAK,CAAC;AACxB,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;CACzB,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n import {css} from 'lit';\n export const styles = css`:host{--md-elevation-level: var(--md-menu-container-elevation, 2);--md-elevation-shadow-color: var(--md-menu-container-shadow-color, var(--md-sys-color-shadow, #000));min-width:112px;color:unset;display:contents}md-focus-ring{--md-focus-ring-shape: var(--md-menu-container-shape, 4px)}.menu{border-radius:var(--md-menu-container-shape, 4px);display:none;opacity:0;z-index:20;position:absolute;user-select:none;max-height:inherit;height:inherit;min-width:inherit;max-width:inherit}.fixed{position:fixed}.items{display:block;list-style-type:none;margin:0;outline:none;box-sizing:border-box;background-color:var(--md-menu-container-color, var(--md-sys-color-surface-container, #f3edf7));height:inherit;max-height:inherit;overflow:auto;min-width:inherit;max-width:inherit;border-radius:inherit}.item-padding{padding-block:8px}.has-overflow .items{overflow:visible}.animating .items{overflow:hidden}.has-overflow.animating .items{pointer-events:none}.animating ::slotted(.md-menu-hidden){opacity:0}slot{display:block;height:inherit;max-height:inherit}::slotted(:is(md-divider,[role=separator])){margin:8px 0}/*# sourceMappingURL=menu-styles.css.map */\n`;\n "]}
1
+ {"version":3,"file":"menu-styles.css.js","sourceRoot":"","sources":["menu-styles.css.ts"],"names":[],"mappings":"AAAA;;;;IAII;AACH,OAAO,EAAC,GAAG,EAAC,MAAM,KAAK,CAAC;AACxB,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;CACzB,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n import {css} from 'lit';\n export const styles = css`:host{--md-elevation-level: var(--md-menu-container-elevation, 2);--md-elevation-shadow-color: var(--md-menu-container-shadow-color, var(--md-sys-color-shadow, #000));min-width:112px;color:unset;display:contents}md-focus-ring{--md-focus-ring-shape: var(--md-menu-container-shape, 4px)}.menu{border-radius:var(--md-menu-container-shape, 4px);display:none;inset:auto;border:none;padding:0px;overflow:visible;background-color:rgba(0,0,0,0);opacity:0;z-index:20;position:absolute;user-select:none;max-height:inherit;height:inherit;min-width:inherit;max-width:inherit}.menu::backdrop{display:none}.fixed{position:fixed}.items{display:block;list-style-type:none;margin:0;outline:none;box-sizing:border-box;background-color:var(--md-menu-container-color, var(--md-sys-color-surface-container, #f3edf7));height:inherit;max-height:inherit;overflow:auto;min-width:inherit;max-width:inherit;border-radius:inherit}.item-padding{padding-block:8px}.has-overflow:not([popover]) .items{overflow:visible}.has-overflow.animating .items,.animating .items{overflow:hidden}.has-overflow.animating .items{pointer-events:none}.animating ::slotted(.md-menu-hidden){opacity:0}slot{display:block;height:inherit;max-height:inherit}::slotted(:is(md-divider,[role=separator])){margin:8px 0}@media(forced-colors: active){.menu{border-style:solid;border-color:CanvasText;border-width:1px}}/*# sourceMappingURL=menu-styles.css.map */\n`;\n "]}
@@ -3,8 +3,8 @@
3
3
  * Copyright 2023 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import '../../focus/md-focus-ring.js';
7
6
  import '../../elevation/elevation.js';
7
+ import '../../focus/md-focus-ring.js';
8
8
  import { LitElement, PropertyValues } from 'lit';
9
9
  import { MenuItem } from './controllers/menuItemController.js';
10
10
  import { FocusState } from './controllers/shared.js';
@@ -16,10 +16,10 @@ export { Corner } from './controllers/surfacePositionController.js';
16
16
  */
17
17
  export declare const DEFAULT_TYPEAHEAD_BUFFER_TIME = 200;
18
18
  /**
19
- * @fires opening Fired before the opening animation begins
20
- * @fires opened Fired once the menu is open, after any animations
21
- * @fires closing Fired before the closing animation begins
22
- * @fires closed Fired once the menu is closed, after any animations
19
+ * @fires opening {Event} Fired before the opening animation begins
20
+ * @fires opened {Event} Fired once the menu is open, after any animations
21
+ * @fires closing {Event} Fired before the closing animation begins
22
+ * @fires closed {Event} Fired once the menu is closed, after any animations
23
23
  */
24
24
  export declare abstract class Menu extends LitElement {
25
25
  private readonly surfaceEl;
@@ -34,9 +34,12 @@ export declare abstract class Menu extends LitElement {
34
34
  anchor: string;
35
35
  /**
36
36
  * Whether the positioning algorithim should calculate relative to the parent
37
- * of the anchor element (absolute) or relative to the window (fixed).
37
+ * of the anchor element (`absolute`), relative to the window (`fixed`), or
38
+ * relative to the document (`document`). `popover` will use the popover API
39
+ * to render the menu in the top-layer. If your browser does not support the
40
+ * popover API, it will fall back to `fixed`.
38
41
  *
39
- * Examples for `position = 'fixed'`:
42
+ * __Examples for `position = 'fixed'`:__
40
43
  *
41
44
  * - If there is no `position:relative` in the given parent tree and the
42
45
  * surface is `position:absolute`
@@ -45,20 +48,36 @@ export declare abstract class Menu extends LitElement {
45
48
  * - The anchor and the surface do not share a common `position:relative`
46
49
  * ancestor
47
50
  *
48
- * When using positioning = fixed, in most cases, the menu should position
51
+ * When using `positioning=fixed`, in most cases, the menu should position
49
52
  * itself above most other `position:absolute` or `position:fixed` elements
50
53
  * when placed inside of them. e.g. using a menu inside of an `md-dialog`.
51
54
  *
52
55
  * __NOTE__: Fixed menus will not scroll with the page and will be fixed to
53
56
  * the window instead.
57
+ *
58
+ * __Examples for `position = 'document'`:__
59
+ *
60
+ * - There is no parent that creates a relative positioning context e.g.
61
+ * `position: relative`, `position: absolute`, `transform: translate(x, y)`,
62
+ * etc.
63
+ * - You put the effort into hoisting the menu to the top of the DOM like the
64
+ * end of the `<body>` to render over everything or in a top-layer.
65
+ * - You are reusing a single `md-menu` element that dynamically renders
66
+ * content.
67
+ *
68
+ * __Examples for `position = 'popover'`:__
69
+ *
70
+ * - Your browser supports `popover`.
71
+ * - Most cases. Once popover is in browsers, this will become the default.
54
72
  */
55
- positioning: 'absolute' | 'fixed';
73
+ positioning: 'absolute' | 'fixed' | 'document' | 'popover';
56
74
  /**
57
75
  * Skips the opening and closing animations.
58
76
  */
59
77
  quick: boolean;
60
78
  /**
61
- * Displays overflow content like a submenu.
79
+ * Displays overflow content like a submenu. Not required in most cases when
80
+ * using `positioning="popover"`.
62
81
  *
63
82
  * __NOTE__: This may cause adverse effects if you set
64
83
  * `md-menu {max-height:...}`
@@ -147,7 +166,10 @@ export declare abstract class Menu extends LitElement {
147
166
  * The event path of the last window pointerdown event.
148
167
  */
149
168
  private pointerPath;
150
- private isPointerDown;
169
+ /**
170
+ * Whether or not the menu is repositoining due to window / document resize
171
+ */
172
+ private isRepositioning;
151
173
  private readonly openCloseAnimationSignal;
152
174
  private readonly listController;
153
175
  /**
@@ -169,8 +191,8 @@ export declare abstract class Menu extends LitElement {
169
191
  * non-empty idref string, then `anchorEl` will resolve to the element with
170
192
  * the given id in the same root node. Otherwise, `null`.
171
193
  */
172
- get anchorElement(): HTMLElement & Partial<SurfacePositionTarget> | null;
173
- set anchorElement(element: HTMLElement & Partial<SurfacePositionTarget> | null);
194
+ get anchorElement(): (HTMLElement & Partial<SurfacePositionTarget>) | null;
195
+ set anchorElement(element: (HTMLElement & Partial<SurfacePositionTarget>) | null);
174
196
  private readonly internals;
175
197
  constructor();
176
198
  /**
@@ -184,6 +206,10 @@ export declare abstract class Menu extends LitElement {
184
206
  */
185
207
  get items(): MenuItem[];
186
208
  protected willUpdate(changed: PropertyValues<Menu>): void;
209
+ update(changed: PropertyValues<Menu>): void;
210
+ private readonly onWindowResize;
211
+ connectedCallback(): void;
212
+ disconnectedCallback(): void;
187
213
  protected render(): import("lit-html").TemplateResult<1>;
188
214
  /**
189
215
  * Renders the positionable surface element and its contents.
@@ -228,11 +254,16 @@ export declare abstract class Menu extends LitElement {
228
254
  * https://direct.googleplex.com/#/spec/295000003+271060003
229
255
  */
230
256
  private animateClose;
231
- connectedCallback(): void;
232
- disconnectedCallback(): void;
257
+ private handleKeydown;
258
+ private setUpGlobalEventListeners;
259
+ private cleanUpGlobalEventListeners;
233
260
  private readonly onWindowPointerdown;
234
- private readonly onWindowPointerup;
235
- private readonly onWindowClick;
261
+ /**
262
+ * We cannot listen to window click because Safari on iOS will not bubble a
263
+ * click event on window if the item clicked is not a "clickable" item such as
264
+ * <body>
265
+ */
266
+ private readonly onDocumentClick;
236
267
  private onCloseMenu;
237
268
  private onDeactivateItems;
238
269
  private onRequestActivation;
@@ -256,4 +287,11 @@ export declare abstract class Menu extends LitElement {
256
287
  * @return The activated menu item or `null` if there are no items.
257
288
  */
258
289
  activatePreviousItem(): MenuItem;
290
+ /**
291
+ * Repositions the menu if it is open.
292
+ *
293
+ * Useful for the case where document or window-positioned menus have their
294
+ * anchors moved while open.
295
+ */
296
+ reposition(): void;
259
297
  }