@material/web 1.0.0 → 1.0.2-nightly.6a1fb38.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 (370) 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 +16 -23
  36. package/checkbox/internal/checkbox.js +38 -52
  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/assist-chip.js +8 -4
  44. package/chips/internal/assist-chip.js.map +1 -1
  45. package/chips/internal/chip-set.js +6 -4
  46. package/chips/internal/chip-set.js.map +1 -1
  47. package/chips/internal/chip.d.ts +3 -0
  48. package/chips/internal/chip.js +7 -5
  49. package/chips/internal/chip.js.map +1 -1
  50. package/chips/internal/filter-chip.d.ts +2 -0
  51. package/chips/internal/filter-chip.js +11 -5
  52. package/chips/internal/filter-chip.js.map +1 -1
  53. package/chips/internal/input-chip.d.ts +2 -0
  54. package/chips/internal/input-chip.js +10 -4
  55. package/chips/internal/input-chip.js.map +1 -1
  56. package/chips/internal/multi-action-chip.js.map +1 -1
  57. package/chips/internal/trailing-icons.d.ts +1 -1
  58. package/chips/internal/trailing-icons.js +6 -5
  59. package/chips/internal/trailing-icons.js.map +1 -1
  60. package/common.d.ts +2 -0
  61. package/common.js +2 -0
  62. package/common.js.map +1 -1
  63. package/dialog/harness.js +1 -2
  64. package/dialog/harness.js.map +1 -1
  65. package/dialog/internal/_dialog.scss +1 -1
  66. package/dialog/internal/animations.js +14 -12
  67. package/dialog/internal/animations.js.map +1 -1
  68. package/dialog/internal/dialog-styles.css.js +1 -1
  69. package/dialog/internal/dialog-styles.css.js.map +1 -1
  70. package/dialog/internal/dialog.d.ts +6 -6
  71. package/dialog/internal/dialog.js +24 -24
  72. package/dialog/internal/dialog.js.map +1 -1
  73. package/fab/harness.js.map +1 -1
  74. package/fab/internal/_fab.scss +4 -0
  75. package/fab/internal/fab-styles.css.js +1 -1
  76. package/fab/internal/fab-styles.css.js.map +1 -1
  77. package/fab/internal/fab.js.map +1 -1
  78. package/fab/internal/shared.js +10 -11
  79. package/fab/internal/shared.js.map +1 -1
  80. package/field/harness.js.map +1 -1
  81. package/field/internal/_content.scss +185 -174
  82. package/field/internal/_filled-field.scss +147 -135
  83. package/field/internal/_label.scss +83 -72
  84. package/field/internal/_outlined-field.scss +276 -261
  85. package/field/internal/_supporting-text.scss +53 -42
  86. package/field/internal/field.js +26 -22
  87. package/field/internal/field.js.map +1 -1
  88. package/field/internal/filled-styles.css.js +1 -1
  89. package/field/internal/filled-styles.css.js.map +1 -1
  90. package/field/internal/outlined-styles.css.js +1 -1
  91. package/field/internal/outlined-styles.css.js.map +1 -1
  92. package/field/internal/shared-styles.css.js +1 -1
  93. package/field/internal/shared-styles.css.js.map +1 -1
  94. package/focus/internal/focus-ring.d.ts +2 -0
  95. package/focus/internal/focus-ring.js +3 -3
  96. package/focus/internal/focus-ring.js.map +1 -1
  97. package/icon/internal/_icon.scss +7 -4
  98. package/icon/internal/icon-styles.css.js +1 -1
  99. package/icon/internal/icon-styles.css.js.map +1 -1
  100. package/iconbutton/internal/icon-button.d.ts +9 -4
  101. package/iconbutton/internal/icon-button.js +35 -22
  102. package/iconbutton/internal/icon-button.js.map +1 -1
  103. package/internal/aria/aria.d.ts +4 -26
  104. package/internal/aria/aria.js +10 -28
  105. package/internal/aria/aria.js.map +1 -1
  106. package/internal/aria/delegate.js +2 -2
  107. package/internal/aria/delegate.js.map +1 -1
  108. package/internal/controller/attachable-controller.js +3 -5
  109. package/internal/controller/attachable-controller.js.map +1 -1
  110. package/internal/controller/form-submitter.d.ts +3 -5
  111. package/internal/controller/form-submitter.js +5 -7
  112. package/internal/controller/form-submitter.js.map +1 -1
  113. package/internal/controller/is-rtl.js +2 -2
  114. package/internal/controller/is-rtl.js.map +1 -1
  115. package/internal/controller/string-converter.js +1 -1
  116. package/internal/controller/string-converter.js.map +1 -1
  117. package/internal/motion/animation.js.map +1 -1
  118. package/labs/behaviors/element-internals.d.ts +45 -0
  119. package/labs/behaviors/element-internals.js +50 -0
  120. package/labs/behaviors/element-internals.js.map +1 -0
  121. package/labs/behaviors/focusable.d.ts +39 -0
  122. package/labs/behaviors/focusable.js +82 -0
  123. package/labs/behaviors/focusable.js.map +1 -0
  124. package/labs/behaviors/form-associated.d.ts +199 -0
  125. package/labs/behaviors/form-associated.js +155 -0
  126. package/labs/behaviors/form-associated.js.map +1 -0
  127. package/labs/behaviors/mixin.d.ts +54 -0
  128. package/labs/behaviors/mixin.js +7 -0
  129. package/labs/behaviors/mixin.js.map +1 -0
  130. package/labs/card/_elevated-card.scss +6 -0
  131. package/labs/card/_filled-card.scss +6 -0
  132. package/labs/card/_outlined-card.scss +6 -0
  133. package/labs/card/elevated-card.d.ts +18 -0
  134. package/labs/card/elevated-card.js +21 -0
  135. package/labs/card/elevated-card.js.map +1 -0
  136. package/labs/card/filled-card.d.ts +18 -0
  137. package/labs/card/filled-card.js +21 -0
  138. package/labs/card/filled-card.js.map +1 -0
  139. package/labs/card/internal/_elevated-card.scss +35 -0
  140. package/labs/card/internal/_filled-card.scss +35 -0
  141. package/labs/card/internal/_outlined-card.scss +39 -0
  142. package/labs/card/internal/_shared.scss +40 -0
  143. package/labs/card/internal/card.d.ts +13 -0
  144. package/labs/card/internal/card.js +20 -0
  145. package/labs/card/internal/card.js.map +1 -0
  146. package/labs/card/internal/elevated-styles.css.js +9 -0
  147. package/labs/card/internal/elevated-styles.css.js.map +1 -0
  148. package/labs/card/internal/elevated-styles.scss +10 -0
  149. package/labs/card/internal/filled-styles.css.js +9 -0
  150. package/labs/card/internal/filled-styles.css.js.map +1 -0
  151. package/labs/card/internal/filled-styles.scss +10 -0
  152. package/labs/card/internal/outlined-styles.css.js +9 -0
  153. package/labs/card/internal/outlined-styles.css.js.map +1 -0
  154. package/labs/card/internal/outlined-styles.scss +10 -0
  155. package/labs/card/internal/shared-styles.css.js +9 -0
  156. package/labs/card/internal/shared-styles.css.js.map +1 -0
  157. package/labs/card/internal/shared-styles.scss +10 -0
  158. package/labs/card/outlined-card.d.ts +18 -0
  159. package/labs/card/outlined-card.js +21 -0
  160. package/labs/card/outlined-card.js.map +1 -0
  161. package/labs/item/internal/_item.scss +1 -1
  162. package/labs/item/internal/item-styles.css.js +1 -1
  163. package/labs/item/internal/item-styles.css.js.map +1 -1
  164. package/labs/item/internal/item.js +8 -8
  165. package/labs/item/internal/item.js.map +1 -1
  166. package/labs/navigationbar/internal/constants.js.map +1 -1
  167. package/labs/navigationbar/internal/navigation-bar.d.ts +3 -0
  168. package/labs/navigationbar/internal/navigation-bar.js +18 -11
  169. package/labs/navigationbar/internal/navigation-bar.js.map +1 -1
  170. package/labs/navigationdrawer/internal/navigation-drawer-modal.d.ts +3 -0
  171. package/labs/navigationdrawer/internal/navigation-drawer-modal.js +10 -3
  172. package/labs/navigationdrawer/internal/navigation-drawer-modal.js.map +1 -1
  173. package/labs/navigationdrawer/internal/navigation-drawer.d.ts +3 -0
  174. package/labs/navigationdrawer/internal/navigation-drawer.js +8 -1
  175. package/labs/navigationdrawer/internal/navigation-drawer.js.map +1 -1
  176. package/labs/navigationtab/harness.js.map +1 -1
  177. package/labs/navigationtab/internal/navigation-tab.d.ts +6 -0
  178. package/labs/navigationtab/internal/navigation-tab.js +43 -27
  179. package/labs/navigationtab/internal/navigation-tab.js.map +1 -1
  180. package/labs/navigationtab/internal/state.js.map +1 -1
  181. package/labs/segmentedbutton/internal/segmented-button.d.ts +3 -0
  182. package/labs/segmentedbutton/internal/segmented-button.js +26 -12
  183. package/labs/segmentedbutton/internal/segmented-button.js.map +1 -1
  184. package/labs/segmentedbuttonset/internal/segmented-button-set.d.ts +5 -0
  185. package/labs/segmentedbuttonset/internal/segmented-button-set.js +14 -9
  186. package/labs/segmentedbuttonset/internal/segmented-button-set.js.map +1 -1
  187. package/list/harness.d.ts +3 -2
  188. package/list/harness.js.map +1 -1
  189. package/list/internal/list-controller.d.ts +1 -1
  190. package/list/internal/list-controller.js +7 -3
  191. package/list/internal/list-controller.js.map +1 -1
  192. package/list/internal/list-navigation-helpers.js.map +1 -1
  193. package/list/internal/list.d.ts +2 -2
  194. package/list/internal/list.js +8 -6
  195. package/list/internal/list.js.map +1 -1
  196. package/list/internal/listitem/_list-item.scss +18 -0
  197. package/list/internal/listitem/harness.d.ts +3 -3
  198. package/list/internal/listitem/harness.js.map +1 -1
  199. package/list/internal/listitem/list-item-styles.css.js +1 -1
  200. package/list/internal/listitem/list-item-styles.css.js.map +1 -1
  201. package/list/internal/listitem/list-item.d.ts +3 -2
  202. package/list/internal/listitem/list-item.js +20 -21
  203. package/list/internal/listitem/list-item.js.map +1 -1
  204. package/list/list-item.d.ts +4 -12
  205. package/list/list-item.js +5 -14
  206. package/list/list-item.js.map +1 -1
  207. package/menu/harness.js.map +1 -1
  208. package/menu/internal/_menu.scss +20 -1
  209. package/menu/internal/controllers/menuItemController.d.ts +7 -0
  210. package/menu/internal/controllers/menuItemController.js +17 -4
  211. package/menu/internal/controllers/menuItemController.js.map +1 -1
  212. package/menu/internal/controllers/shared.d.ts +9 -1
  213. package/menu/internal/controllers/shared.js +4 -4
  214. package/menu/internal/controllers/shared.js.map +1 -1
  215. package/menu/internal/controllers/surfacePositionController.d.ts +15 -2
  216. package/menu/internal/controllers/surfacePositionController.js +134 -56
  217. package/menu/internal/controllers/surfacePositionController.js.map +1 -1
  218. package/menu/internal/controllers/typeaheadController.js +19 -14
  219. package/menu/internal/controllers/typeaheadController.js.map +1 -1
  220. package/menu/internal/menu-styles.css.js +1 -1
  221. package/menu/internal/menu-styles.css.js.map +1 -1
  222. package/menu/internal/menu.d.ts +55 -17
  223. package/menu/internal/menu.js +175 -88
  224. package/menu/internal/menu.js.map +1 -1
  225. package/menu/internal/menuitem/_menu-item.scss +24 -0
  226. package/menu/internal/menuitem/harness.d.ts +3 -1
  227. package/menu/internal/menuitem/harness.js.map +1 -1
  228. package/menu/internal/menuitem/menu-item-styles.css.js +1 -1
  229. package/menu/internal/menuitem/menu-item-styles.css.js.map +1 -1
  230. package/menu/internal/menuitem/menu-item.d.ts +3 -2
  231. package/menu/internal/menuitem/menu-item.js +20 -20
  232. package/menu/internal/menuitem/menu-item.js.map +1 -1
  233. package/menu/internal/submenu/sub-menu.d.ts +9 -8
  234. package/menu/internal/submenu/sub-menu.js +35 -22
  235. package/menu/internal/submenu/sub-menu.js.map +1 -1
  236. package/menu/internal/types.js.map +1 -1
  237. package/menu/menu-item.js +1 -2
  238. package/menu/menu-item.js.map +1 -1
  239. package/menu/menu.js +1 -2
  240. package/menu/menu.js.map +1 -1
  241. package/package.json +1 -1
  242. package/progress/internal/_circular-progress.scss +2 -2
  243. package/progress/internal/_linear-progress.scss +1 -1
  244. package/progress/internal/circular-progress-styles.css.js +1 -1
  245. package/progress/internal/circular-progress-styles.css.js.map +1 -1
  246. package/progress/internal/circular-progress.js +11 -10
  247. package/progress/internal/circular-progress.js.map +1 -1
  248. package/progress/internal/linear-progress-styles.css.js +1 -1
  249. package/progress/internal/linear-progress-styles.css.js.map +1 -1
  250. package/progress/internal/linear-progress.d.ts +1 -1
  251. package/progress/internal/linear-progress.js +3 -3
  252. package/progress/internal/linear-progress.js.map +1 -1
  253. package/progress/internal/progress.js +4 -2
  254. package/progress/internal/progress.js.map +1 -1
  255. package/radio/internal/_radio.scss +144 -123
  256. package/radio/internal/radio-styles.css.js +1 -1
  257. package/radio/internal/radio-styles.css.js.map +1 -1
  258. package/radio/internal/radio.d.ts +12 -23
  259. package/radio/internal/radio.js +31 -50
  260. package/radio/internal/radio.js.map +1 -1
  261. package/radio/internal/single-selection-controller.js +1 -1
  262. package/radio/internal/single-selection-controller.js.map +1 -1
  263. package/radio/radio.js +1 -2
  264. package/radio/radio.js.map +1 -1
  265. package/ripple/internal/ripple.js +21 -18
  266. package/ripple/internal/ripple.js.map +1 -1
  267. package/select/filled-select.js +1 -2
  268. package/select/filled-select.js.map +1 -1
  269. package/select/harness.js +1 -1
  270. package/select/harness.js.map +1 -1
  271. package/select/internal/_shared.scss +4 -0
  272. package/select/internal/select.d.ts +25 -34
  273. package/select/internal/select.js +101 -91
  274. package/select/internal/select.js.map +1 -1
  275. package/select/internal/selectoption/select-option.d.ts +8 -6
  276. package/select/internal/selectoption/select-option.js +25 -23
  277. package/select/internal/selectoption/select-option.js.map +1 -1
  278. package/select/internal/selectoption/selectOptionController.js +1 -1
  279. package/select/internal/selectoption/selectOptionController.js.map +1 -1
  280. package/select/internal/shared-styles.css.js +1 -1
  281. package/select/internal/shared-styles.css.js.map +1 -1
  282. package/select/outlined-select.js +1 -2
  283. package/select/outlined-select.js.map +1 -1
  284. package/select/select-option.js +1 -2
  285. package/select/select-option.js.map +1 -1
  286. package/slider/harness.js +5 -5
  287. package/slider/harness.js.map +1 -1
  288. package/slider/internal/_slider.scss +68 -30
  289. package/slider/internal/slider-styles.css.js +1 -1
  290. package/slider/internal/slider-styles.css.js.map +1 -1
  291. package/slider/internal/slider.d.ts +16 -25
  292. package/slider/internal/slider.js +111 -115
  293. package/slider/internal/slider.js.map +1 -1
  294. package/switch/internal/_handle.scss +159 -141
  295. package/switch/internal/_icon.scss +95 -72
  296. package/switch/internal/_switch.scss +90 -95
  297. package/switch/internal/_track.scss +110 -77
  298. package/switch/internal/switch-styles.css.js +1 -1
  299. package/switch/internal/switch-styles.css.js.map +1 -1
  300. package/switch/internal/switch.d.ts +9 -25
  301. package/switch/internal/switch.js +31 -57
  302. package/switch/internal/switch.js.map +1 -1
  303. package/switch/switch.js +1 -2
  304. package/switch/switch.js.map +1 -1
  305. package/tabs/harness.js +3 -3
  306. package/tabs/harness.js.map +1 -1
  307. package/tabs/internal/_tab.scss +27 -35
  308. package/tabs/internal/primary-tab.d.ts +0 -2
  309. package/tabs/internal/tab-styles.css.js +1 -1
  310. package/tabs/internal/tab-styles.css.js.map +1 -1
  311. package/tabs/internal/tab.d.ts +10 -5
  312. package/tabs/internal/tab.js +43 -22
  313. package/tabs/internal/tab.js.map +1 -1
  314. package/tabs/internal/tabs.d.ts +7 -4
  315. package/tabs/internal/tabs.js +23 -22
  316. package/tabs/internal/tabs.js.map +1 -1
  317. package/textfield/filled-text-field.js +1 -2
  318. package/textfield/filled-text-field.js.map +1 -1
  319. package/textfield/harness.js +3 -2
  320. package/textfield/harness.js.map +1 -1
  321. package/textfield/internal/text-field.d.ts +33 -18
  322. package/textfield/internal/text-field.js +96 -58
  323. package/textfield/internal/text-field.js.map +1 -1
  324. package/textfield/outlined-text-field.js +1 -2
  325. package/textfield/outlined-text-field.js.map +1 -1
  326. package/tokens/_index.scss +3 -0
  327. package/tokens/_md-comp-elevated-card.scss +63 -0
  328. package/tokens/_md-comp-filled-card.scss +63 -0
  329. package/tokens/_md-comp-icon.scss +2 -0
  330. package/tokens/_md-comp-outlined-card.scss +69 -0
  331. package/tokens/_md-comp-test-table.scss +1 -0
  332. package/internal/controller/element-internals.d.ts +0 -35
  333. package/internal/controller/element-internals.js +0 -24
  334. package/internal/controller/element-internals.js.map +0 -1
  335. package/list/internal/listitem/forced-colors-styles.css.js +0 -9
  336. package/list/internal/listitem/forced-colors-styles.css.js.map +0 -1
  337. package/list/internal/listitem/forced-colors-styles.scss +0 -19
  338. package/menu/internal/forced-colors-styles.css.js +0 -9
  339. package/menu/internal/forced-colors-styles.css.js.map +0 -1
  340. package/menu/internal/forced-colors-styles.scss +0 -12
  341. package/menu/internal/menuitem/forced-colors-styles.css.js +0 -9
  342. package/menu/internal/menuitem/forced-colors-styles.css.js.map +0 -1
  343. package/menu/internal/menuitem/forced-colors-styles.scss +0 -26
  344. package/radio/internal/forced-colors-styles.css.js +0 -9
  345. package/radio/internal/forced-colors-styles.css.js.map +0 -1
  346. package/radio/internal/forced-colors-styles.scss +0 -29
  347. package/select/internal/filled-forced-colors-styles.css.d.ts +0 -1
  348. package/select/internal/filled-forced-colors-styles.css.js +0 -9
  349. package/select/internal/filled-forced-colors-styles.css.js.map +0 -1
  350. package/select/internal/filled-forced-colors-styles.scss +0 -29
  351. package/select/internal/outlined-forced-colors-styles.css.d.ts +0 -1
  352. package/select/internal/outlined-forced-colors-styles.css.js +0 -9
  353. package/select/internal/outlined-forced-colors-styles.css.js.map +0 -1
  354. package/select/internal/outlined-forced-colors-styles.scss +0 -29
  355. package/switch/internal/forced-colors-styles.css.d.ts +0 -1
  356. package/switch/internal/forced-colors-styles.css.js +0 -9
  357. package/switch/internal/forced-colors-styles.css.js.map +0 -1
  358. package/switch/internal/forced-colors-styles.scss +0 -42
  359. package/textfield/internal/filled-forced-colors-styles.css.d.ts +0 -1
  360. package/textfield/internal/filled-forced-colors-styles.css.js +0 -9
  361. package/textfield/internal/filled-forced-colors-styles.css.js.map +0 -1
  362. package/textfield/internal/filled-forced-colors-styles.scss +0 -29
  363. package/textfield/internal/outlined-forced-colors-styles.css.d.ts +0 -1
  364. package/textfield/internal/outlined-forced-colors-styles.css.js +0 -9
  365. package/textfield/internal/outlined-forced-colors-styles.css.js.map +0 -1
  366. package/textfield/internal/outlined-forced-colors-styles.scss +0 -29
  367. /package/{list/internal/listitem/forced-colors-styles.css.d.ts → labs/card/internal/elevated-styles.css.d.ts} +0 -0
  368. /package/{menu/internal/forced-colors-styles.css.d.ts → labs/card/internal/filled-styles.css.d.ts} +0 -0
  369. /package/{menu/internal/menuitem/forced-colors-styles.css.d.ts → labs/card/internal/outlined-styles.css.d.ts} +0 -0
  370. /package/{radio/internal/forced-colors-styles.css.d.ts → labs/card/internal/shared-styles.css.d.ts} +0 -0
@@ -56,6 +56,14 @@ export interface MenuSelf {
56
56
  * An array of items managed by the list.
57
57
  */
58
58
  items: MenuItem[];
59
+ /**
60
+ * The positioning strategy of the menu.
61
+ *
62
+ * - `absolute` is relative to the anchor element.
63
+ * - `fixed` is relative to the window
64
+ * - `document` is relative to the document
65
+ */
66
+ positioning?: 'absolute' | 'fixed' | 'document';
59
67
  /**
60
68
  * Opens the menu.
61
69
  */
@@ -217,5 +225,5 @@ export declare const FocusState: {
217
225
  /**
218
226
  * Element to focus on when menu is first opened.
219
227
  */
220
- export type FocusState = typeof FocusState[keyof typeof FocusState];
228
+ export type FocusState = (typeof FocusState)[keyof typeof FocusState];
221
229
  export {};
@@ -10,7 +10,7 @@ export function createCloseMenuEvent(initiator, reason) {
10
10
  return new CustomEvent('close-menu', {
11
11
  bubbles: true,
12
12
  composed: true,
13
- detail: { initiator, reason, itemPath: [initiator] }
13
+ detail: { initiator, reason, itemPath: [initiator] },
14
14
  });
15
15
  }
16
16
  /**
@@ -88,7 +88,7 @@ export const KeydownCloseKey = {
88
88
  * menu.
89
89
  */
90
90
  export function isClosableKey(code) {
91
- return Object.values(KeydownCloseKey).some(value => (value === code));
91
+ return Object.values(KeydownCloseKey).some((value) => value === code);
92
92
  }
93
93
  /**
94
94
  * Determines whether the given key code is a key code that should select a menu
@@ -99,7 +99,7 @@ export function isClosableKey(code) {
99
99
  * menu item.
100
100
  */
101
101
  export function isSelectableKey(code) {
102
- return Object.values(SelectionKey).some(value => (value === code));
102
+ return Object.values(SelectionKey).some((value) => value === code);
103
103
  }
104
104
  /**
105
105
  * Determines whether a target element is contained inside another element's
@@ -132,6 +132,6 @@ export const FocusState = {
132
132
  NONE: 'none',
133
133
  LIST_ROOT: 'list-root',
134
134
  FIRST_ITEM: 'first-item',
135
- LAST_ITEM: 'last-item'
135
+ LAST_ITEM: 'last-item',
136
136
  };
137
137
  //# sourceMappingURL=shared.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAuGH;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAChC,SAAmB,EAAE,MAAS;IAChC,OAAO,IAAI,WAAW,CACsC,YAAY,EAAE;QACxE,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAC;KACnD,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,6BAA6B;IAC3C,OAAO,IAAI,KAAK,CAAC,uBAAuB,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;AAC7E,CAAC;AAED;;;GAGG;AACH,MAA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} from './menuItemController.js';\nimport type {Corner, SurfacePositionTarget} from './surfacePositionController.js';\n\n/**\n * The interface needed for a Menu to work with other md-menu elements.\n */\nexport interface MenuSelf {\n /**\n * Whether or not the menu is currently opened.\n */\n open: boolean;\n /**\n * Skips the opening and closing animations.\n */\n quick: boolean;\n /**\n * Displays overflow content like a submenu.\n *\n * __NOTE__: This may cause adverse effects if you set\n * `md-menu {max-height:...}`\n * and have items overflowing items in the \"y\" direction.\n */\n hasOverflow: boolean;\n /**\n * Communicates to the menu that it is a submenu and should not handle the\n * ArrowLeft button in LTR and ArrowRight button in RTL.\n */\n isSubmenu: boolean;\n /**\n * After closing, does not restore focus to the last focused element before\n * the menu was opened.\n */\n skipRestoreFocus: boolean;\n /**\n * The corner of the anchor in which the menu should anchor to.\n */\n anchorCorner: Corner;\n /**\n * The corner of the menu in which the menu should anchor from.\n */\n menuCorner: Corner;\n /**\n * The element the menu should anchor to.\n */\n anchorElement: (HTMLElement&Partial<SurfacePositionTarget>)|null;\n /**\n * What the menu should focus by default when opened.\n */\n defaultFocus: FocusState;\n /**\n * An array of items managed by the list.\n */\n items: MenuItem[];\n /**\n * Opens the menu.\n */\n show: () => void;\n /**\n * Closes the menu.\n */\n close: () => void;\n}\n\n/**\n * The interface needed for a Menu to work with other md-menu elements. Useful\n * for keeping your types safe when wrapping `md-menu`.\n */\nexport type Menu = MenuSelf&LitElement;\n\n/**\n * The reason the `close-menu` event was dispatched.\n */\nexport interface Reason {\n kind: string;\n}\n\n/**\n * The click selection reason for the `close-menu` event. The menu was closed\n * because an item was selected via user click.\n */\nexport interface ClickReason extends Reason {\n kind: typeof CloseReason.CLICK_SELECTION;\n}\n\n/**\n * The keydown reason for the `close-menu` event. The menu was closed\n * because a specific key was pressed. The default closing keys for\n * `md-menu-item` are, Space, Enter or Escape.\n */\nexport interface KeydownReason extends Reason {\n kind: typeof CloseReason.KEYDOWN;\n key: string;\n}\n\n/**\n * The default menu closing reasons for the material md-menu package.\n */\nexport type DefaultReasons = ClickReason|KeydownReason;\n\n/**\n * Creates an event that closes any parent menus.\n */\nexport function createCloseMenuEvent<T extends Reason = DefaultReasons>(\n initiator: MenuItem, reason: T) {\n return new CustomEvent<\n {initiator: MenuItem, itemPath: MenuItem[], reason: T}>('close-menu', {\n bubbles: true,\n composed: true,\n detail: {initiator, reason, itemPath: [initiator]}\n });\n}\n\n/**\n * Creates an event that signals to the menu that it should stay open on the\n * focusout event.\n */\nexport function createStayOpenOnFocusoutEvent() {\n return new Event('stay-open-on-focusout', {bubbles: true, composed: true});\n}\n\n/**\n * Creates an event that signals to the menu that it should close open on the\n * focusout event.\n */\nexport function createCloseOnFocusoutEvent() {\n return new Event('close-on-focusout', {bubbles: true, composed: true});\n}\n\n/**\n * Creates a default close menu event used by md-menu.\n */\nexport const createDefaultCloseMenuEvent = createCloseMenuEvent<DefaultReasons>;\n\n/**\n * The type of the default close menu event used by md-menu.\n */\n// tslint:disable-next-line\nexport type CloseMenuEvent<T extends Reason = DefaultReasons> =\n ReturnType<typeof createCloseMenuEvent<T>>;\n\n/**\n * Creates an event that requests the given item be selected.\n */\nexport function createDeactivateTypeaheadEvent() {\n return new Event('deactivate-typeahead', {bubbles: true, composed: true});\n}\n\n/**\n * The type of the event that requests the typeahead functionality of containing\n * menu be deactivated.\n */\nexport type DeactivateTypeaheadEvent =\n ReturnType<typeof createDeactivateTypeaheadEvent>;\n\n/**\n * Creates an event that requests the typeahead functionality of containing menu\n * be activated.\n */\nexport function createActivateTypeaheadEvent() {\n return new Event('activate-typeahead', {bubbles: true, composed: true});\n}\n\n/**\n * The type of the event that requests the typeahead functionality of containing\n * menu be activated.\n */\nexport type ActivateTypeaheadEvent =\n ReturnType<typeof createActivateTypeaheadEvent>;\n\n/**\n * Keys that are used to navigate menus.\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const NavigableKey = {\n UP: 'ArrowUp',\n DOWN: 'ArrowDown',\n RIGHT: 'ArrowRight',\n LEFT: 'ArrowLeft',\n} as const;\n\n/**\n * Keys that are used for selection in menus.\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const SelectionKey = {\n SPACE: 'Space',\n ENTER: 'Enter',\n} as const;\n\n/**\n * Default close `Reason` kind values.\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const CloseReason = {\n CLICK_SELECTION: 'click-selection',\n KEYDOWN: 'keydown',\n} as const;\n\n/**\n * Keys that can close menus.\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const KeydownCloseKey = {\n ESCAPE: 'Escape',\n SPACE: SelectionKey.SPACE,\n ENTER: SelectionKey.ENTER,\n} as const;\n\ntype Values<T> = T[keyof T];\n\n/**\n * Determines whether the given key code is a key code that should close the\n * menu.\n *\n * @param code The KeyboardEvent code to check.\n * @return Whether or not the key code is in the predetermined list to close the\n * menu.\n */\nexport function isClosableKey(code: string):\n code is Values<typeof KeydownCloseKey> {\n return Object.values(KeydownCloseKey).some(value => (value === code));\n}\n\n/**\n * Determines whether the given key code is a key code that should select a menu\n * item.\n *\n * @param code They KeyboardEvent code to check.\n * @return Whether or not the key code is in the predetermined list to select a\n * menu item.\n */\nexport function isSelectableKey(code: string):\n code is Values<typeof SelectionKey> {\n return Object.values(SelectionKey).some(value => (value === code));\n}\n\n/**\n * Determines whether a target element is contained inside another element's\n * composed tree.\n *\n * @param target The potential contained element.\n * @param container The potential containing element of the target.\n * @returns Whether the target element is contained inside the container's\n * composed subtree\n */\nexport function isElementInSubtree(\n target: EventTarget, container: EventTarget) {\n // Dispatch a composed, bubbling event to check its path to see if the\n // newly-focused element is contained in container's subtree\n const focusEv = new Event('md-contains', {bubbles: true, composed: true});\n let composedPath: EventTarget[] = [];\n const listener = (ev: Event) => {\n composedPath = ev.composedPath();\n };\n\n container.addEventListener('md-contains', listener);\n target.dispatchEvent(focusEv);\n container.removeEventListener('md-contains', listener);\n\n const isContained = composedPath.length > 0;\n return isContained;\n}\n\n/**\n * Element to focus on when menu is first opened.\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const FocusState = {\n NONE: 'none',\n LIST_ROOT: 'list-root',\n FIRST_ITEM: 'first-item',\n LAST_ITEM: 'last-item'\n} as const;\n\n/**\n * Element to focus on when menu is first opened.\n */\nexport type FocusState = typeof FocusState[keyof typeof FocusState];"]}
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA+GH;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAmB,EACnB,MAAS;IAET,OAAO,IAAI,WAAW,CAInB,YAAY,EAAE;QACf,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAC;KACnD,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,6BAA6B;IAC3C,OAAO,IAAI,KAAK,CAAC,uBAAuB,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;AAC7E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO,IAAI,KAAK,CAAC,mBAAmB,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;AACzE,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAA,oBAAoC,CAAA,CAAC;AAUhF;;GAEG;AACH,MAAM,UAAU,8BAA8B;IAC5C,OAAO,IAAI,KAAK,CAAC,sBAAsB,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;AAC5E,CAAC;AAUD;;;GAGG;AACH,MAAM,UAAU,4BAA4B;IAC1C,OAAO,IAAI,KAAK,CAAC,oBAAoB,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE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,IAAI,EAAC,CAAC,CAAC;IAC1E,IAAI,YAAY,GAAkB,EAAE,CAAC;IACrC,MAAM,QAAQ,GAAG,CAAC,EAAS,EAAE,EAAE;QAC7B,YAAY,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC;IACnC,CAAC,CAAC;IAEF,SAAS,CAAC,gBAAgB,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IACpD,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC9B,SAAS,CAAC,mBAAmB,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IAEvD,MAAM,WAAW,GAAG,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;IAC5C,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,WAAW;IACtB,UAAU,EAAE,YAAY;IACxB,SAAS,EAAE,WAAW;CACd,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {LitElement} from 'lit';\n\nimport {MenuItem} from './menuItemController.js';\nimport type {Corner, SurfacePositionTarget} from './surfacePositionController.js';\n\n/**\n * The interface needed for a Menu to work with other md-menu elements.\n */\nexport interface MenuSelf {\n /**\n * Whether or not the menu is currently opened.\n */\n open: boolean;\n /**\n * Skips the opening and closing animations.\n */\n quick: boolean;\n /**\n * Displays overflow content like a submenu.\n *\n * __NOTE__: This may cause adverse effects if you set\n * `md-menu {max-height:...}`\n * and have items overflowing items in the \"y\" direction.\n */\n hasOverflow: boolean;\n /**\n * Communicates to the menu that it is a submenu and should not handle the\n * ArrowLeft button in LTR and ArrowRight button in RTL.\n */\n isSubmenu: boolean;\n /**\n * After closing, does not restore focus to the last focused element before\n * the menu was opened.\n */\n skipRestoreFocus: boolean;\n /**\n * The corner of the anchor in which the menu should anchor to.\n */\n anchorCorner: Corner;\n /**\n * The corner of the menu in which the menu should anchor from.\n */\n menuCorner: Corner;\n /**\n * The element the menu should anchor to.\n */\n anchorElement: (HTMLElement & Partial<SurfacePositionTarget>) | null;\n /**\n * What the menu should focus by default when opened.\n */\n defaultFocus: FocusState;\n /**\n * An array of items managed by the list.\n */\n items: MenuItem[];\n /**\n * The positioning strategy of the menu.\n *\n * - `absolute` is relative to the anchor element.\n * - `fixed` is relative to the window\n * - `document` is relative to the document\n */\n positioning?: 'absolute' | 'fixed' | 'document';\n /**\n * Opens the menu.\n */\n show: () => void;\n /**\n * Closes the menu.\n */\n close: () => void;\n}\n\n/**\n * The interface needed for a Menu to work with other md-menu elements. Useful\n * for keeping your types safe when wrapping `md-menu`.\n */\nexport type Menu = MenuSelf & LitElement;\n\n/**\n * The reason the `close-menu` event was dispatched.\n */\nexport interface Reason {\n kind: string;\n}\n\n/**\n * The click selection reason for the `close-menu` event. The menu was closed\n * because an item was selected via user click.\n */\nexport interface ClickReason extends Reason {\n kind: typeof CloseReason.CLICK_SELECTION;\n}\n\n/**\n * The keydown reason for the `close-menu` event. The menu was closed\n * because a specific key was pressed. The default closing keys for\n * `md-menu-item` are, Space, Enter or Escape.\n */\nexport interface KeydownReason extends Reason {\n kind: typeof CloseReason.KEYDOWN;\n key: string;\n}\n\n/**\n * The default menu closing reasons for the material md-menu package.\n */\nexport type DefaultReasons = ClickReason | KeydownReason;\n\n/**\n * Creates an event that closes any parent menus.\n */\nexport function createCloseMenuEvent<T extends Reason = DefaultReasons>(\n initiator: MenuItem,\n reason: T,\n) {\n return new CustomEvent<{\n initiator: MenuItem;\n itemPath: MenuItem[];\n reason: T;\n }>('close-menu', {\n bubbles: true,\n composed: true,\n detail: {initiator, reason, itemPath: [initiator]},\n });\n}\n\n/**\n * Creates an event that signals to the menu that it should stay open on the\n * focusout event.\n */\nexport function createStayOpenOnFocusoutEvent() {\n return new Event('stay-open-on-focusout', {bubbles: true, composed: true});\n}\n\n/**\n * Creates an event that signals to the menu that it should close open on the\n * focusout event.\n */\nexport function createCloseOnFocusoutEvent() {\n return new Event('close-on-focusout', {bubbles: true, composed: true});\n}\n\n/**\n * Creates a default close menu event used by md-menu.\n */\nexport const createDefaultCloseMenuEvent = createCloseMenuEvent<DefaultReasons>;\n\n/**\n * The type of the default close menu event used by md-menu.\n */\n// tslint:disable-next-line\nexport type CloseMenuEvent<T extends Reason = DefaultReasons> = ReturnType<\n typeof createCloseMenuEvent<T>\n>;\n\n/**\n * Creates an event that requests the given item be selected.\n */\nexport function createDeactivateTypeaheadEvent() {\n return new Event('deactivate-typeahead', {bubbles: true, composed: true});\n}\n\n/**\n * The type of the event that requests the typeahead functionality of containing\n * menu be deactivated.\n */\nexport type DeactivateTypeaheadEvent = ReturnType<\n typeof createDeactivateTypeaheadEvent\n>;\n\n/**\n * Creates an event that requests the typeahead functionality of containing menu\n * be activated.\n */\nexport function createActivateTypeaheadEvent() {\n return new Event('activate-typeahead', {bubbles: true, composed: true});\n}\n\n/**\n * The type of the event that requests the typeahead functionality of containing\n * menu be activated.\n */\nexport type ActivateTypeaheadEvent = ReturnType<\n typeof createActivateTypeaheadEvent\n>;\n\n/**\n * Keys that are used to navigate menus.\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const NavigableKey = {\n UP: 'ArrowUp',\n DOWN: 'ArrowDown',\n RIGHT: 'ArrowRight',\n LEFT: 'ArrowLeft',\n} as const;\n\n/**\n * Keys that are used for selection in menus.\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const SelectionKey = {\n SPACE: 'Space',\n ENTER: 'Enter',\n} as const;\n\n/**\n * Default close `Reason` kind values.\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const CloseReason = {\n CLICK_SELECTION: 'click-selection',\n KEYDOWN: 'keydown',\n} as const;\n\n/**\n * Keys that can close menus.\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const KeydownCloseKey = {\n ESCAPE: 'Escape',\n SPACE: SelectionKey.SPACE,\n ENTER: SelectionKey.ENTER,\n} as const;\n\ntype Values<T> = T[keyof T];\n\n/**\n * Determines whether the given key code is a key code that should close the\n * menu.\n *\n * @param code The KeyboardEvent code to check.\n * @return Whether or not the key code is in the predetermined list to close the\n * menu.\n */\nexport function isClosableKey(\n code: string,\n): code is Values<typeof KeydownCloseKey> {\n return Object.values(KeydownCloseKey).some((value) => value === code);\n}\n\n/**\n * Determines whether the given key code is a key code that should select a menu\n * item.\n *\n * @param code They KeyboardEvent code to check.\n * @return Whether or not the key code is in the predetermined list to select a\n * menu item.\n */\nexport function isSelectableKey(\n code: string,\n): code is Values<typeof SelectionKey> {\n return Object.values(SelectionKey).some((value) => value === code);\n}\n\n/**\n * Determines whether a target element is contained inside another element's\n * composed tree.\n *\n * @param target The potential contained element.\n * @param container The potential containing element of the target.\n * @returns Whether the target element is contained inside the container's\n * composed subtree\n */\nexport function isElementInSubtree(\n target: EventTarget,\n container: EventTarget,\n) {\n // Dispatch a composed, bubbling event to check its path to see if the\n // newly-focused element is contained in container's subtree\n const focusEv = new Event('md-contains', {bubbles: true, composed: true});\n let composedPath: EventTarget[] = [];\n const listener = (ev: Event) => {\n composedPath = ev.composedPath();\n };\n\n container.addEventListener('md-contains', listener);\n target.dispatchEvent(focusEv);\n container.removeEventListener('md-contains', listener);\n\n const isContained = composedPath.length > 0;\n return isContained;\n}\n\n/**\n * Element to focus on when menu is first opened.\n */\n// tslint:disable-next-line:enforce-name-casing We are mimicking enum style\nexport const FocusState = {\n NONE: 'none',\n LIST_ROOT: 'list-root',\n FIRST_ITEM: 'first-item',\n LAST_ITEM: 'last-item',\n} as const;\n\n/**\n * Element to focus on when menu is first opened.\n */\nexport type FocusState = (typeof FocusState)[keyof typeof FocusState];\n"]}
@@ -5,6 +5,19 @@
5
5
  */
6
6
  import { ReactiveController, ReactiveControllerHost } from 'lit';
7
7
  import { StyleInfo } from 'lit/directives/style-map.js';
8
+ /**
9
+ * Declare popoverAPI functions. See
10
+ * https://developer.mozilla.org/en-US/docs/Web/API/Popover_API
11
+ * Without this, closure will rename these functions. Can remove once these
12
+ * functions make it into the typescript lib.
13
+ */
14
+ declare global {
15
+ interface HTMLElement {
16
+ showPopover(): void;
17
+ hidePopover(): void;
18
+ togglePopover(force: boolean): void;
19
+ }
20
+ }
8
21
  /**
9
22
  * An enum of supported Menu corners
10
23
  */
@@ -17,7 +30,7 @@ export declare const Corner: {
17
30
  /**
18
31
  * A corner of a box in the standard logical property style of <block>_<inline>
19
32
  */
20
- export type Corner = typeof Corner[keyof typeof Corner];
33
+ export type Corner = (typeof Corner)[keyof typeof Corner];
21
34
  /**
22
35
  * An interface that provides a method to customize the rect from which to
23
36
  * calculate the anchor positioning. Useful for when you want a surface to
@@ -59,7 +72,7 @@ export interface SurfacePositionControllerProperties {
59
72
  * - The anchor and the surface do not share a common `position:relative`
60
73
  * ancestor
61
74
  */
62
- positioning: 'absolute' | 'fixed';
75
+ positioning: 'absolute' | 'fixed' | 'document';
63
76
  /**
64
77
  * Whether or not the surface should be "open" and visible
65
78
  */
@@ -34,7 +34,9 @@ export class SurfacePositionController {
34
34
  };
35
35
  // Previous values stored for change detection. Open change detection is
36
36
  // calculated separately so initialize it here.
37
- this.lastValues = { isOpen: false };
37
+ this.lastValues = {
38
+ isOpen: false,
39
+ };
38
40
  this.host.addController(this);
39
41
  }
40
42
  /**
@@ -56,6 +58,22 @@ export class SurfacePositionController {
56
58
  if (!surfaceEl || !anchorEl) {
57
59
  return;
58
60
  }
61
+ // Store these before we potentially resize the window with the next set of
62
+ // lines
63
+ const windowInnerWidth = window.innerWidth;
64
+ const windowInnerHeight = window.innerHeight;
65
+ const div = document.createElement('div');
66
+ div.style.opacity = '0';
67
+ div.style.position = 'fixed';
68
+ div.style.display = 'block';
69
+ div.style.inset = '0';
70
+ document.body.appendChild(div);
71
+ const scrollbarTestRect = div.getBoundingClientRect();
72
+ div.remove();
73
+ // Calculate the widths of the scrollbars in the inline and block directions
74
+ // to account for window-relative calculations.
75
+ const blockScrollbarHeight = window.innerHeight - scrollbarTestRect.bottom;
76
+ const inlineScrollbarWidth = window.innerWidth - scrollbarTestRect.right;
59
77
  // Paint the surface transparently so that we can get the position and the
60
78
  // rect info of the surface.
61
79
  this.surfaceStylesInternal = {
@@ -65,46 +83,61 @@ export class SurfacePositionController {
65
83
  // Wait for it to be visible.
66
84
  this.host.requestUpdate();
67
85
  await this.host.updateComplete;
68
- const surfaceRect = surfaceEl.getSurfacePositionClientRect ?
69
- surfaceEl.getSurfacePositionClientRect() :
70
- surfaceEl.getBoundingClientRect();
71
- const anchorRect = anchorEl.getSurfacePositionClientRect ?
72
- anchorEl.getSurfacePositionClientRect() :
73
- anchorEl.getBoundingClientRect();
86
+ // Safari has a bug that makes popovers render incorrectly if the node is
87
+ // made visible + Animation Frame before calling showPopover().
88
+ // https://bugs.webkit.org/show_bug.cgi?id=264069
89
+ // also the cast is required due to differing TS types in Google and OSS.
90
+ if (surfaceEl.popover &&
91
+ surfaceEl.isConnected) {
92
+ surfaceEl.showPopover();
93
+ }
94
+ const surfaceRect = surfaceEl.getSurfacePositionClientRect
95
+ ? surfaceEl.getSurfacePositionClientRect()
96
+ : surfaceEl.getBoundingClientRect();
97
+ const anchorRect = anchorEl.getSurfacePositionClientRect
98
+ ? anchorEl.getSurfacePositionClientRect()
99
+ : anchorEl.getBoundingClientRect();
74
100
  const [surfaceBlock, surfaceInline] = surfaceCorner.split('-');
75
101
  const [anchorBlock, anchorInline] = anchorCorner.split('-');
76
102
  // LTR depends on the direction of the SURFACE not the anchor.
77
103
  const isLTR = getComputedStyle(surfaceEl).direction === 'ltr';
78
104
  /*
79
- * A diagram that helps describe some of the variables used in the following
80
- * calculations.
105
+ * For more on inline and block dimensions, see MDN article:
106
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values
81
107
  *
82
- * ┌───── inline/blockTopLayerOffset
83
- * │ │
84
- * │ ┌─▼───┐ Window
85
- * │ ┌┼─────┴────────────────────────┐
86
- * │ ││
87
- * └──► ││ ┌──inline/blockAnchorOffset
88
- * ││
89
- * └┤ ┌──▼───┐
90
- * ┌┼──────┤ │
91
- * │ └─►│Anchor
92
- * │ └┴──────┘
93
- * │
94
- * │ ┌────────────────────────┼────┐
95
- * │ Surface
96
- * │
97
- * │
98
- * │
99
- * │ │ │ │
100
- * │ │
101
- * └─────┼────────────────────────┘ ├┐
102
- * inline/blockOOBCorrection ││
103
- * ││
104
- * ├──►││
105
- * ││
106
- * └────────────────────────┐▼───┼┘
107
- * └────┘
108
+ * ┌───── inline/blockDocumentOffset inlineScrollbarWidth
109
+ * │ │
110
+ * │ ┌─▼─────┐ │Document
111
+ * │ ┌┼───────┴──────────────────────────────┼────────┐
112
+ * │ ││
113
+ * └──► ││ ┌───── inline/blockWindowOffset
114
+ * ││
115
+ * ││ ┌─▼───┐ Window┌┐
116
+ * └┤ ┌┼─────┴───────────────────────┼│
117
+ * │ ││ ││
118
+ * │ └──► ││ ┌──inline/blockAnchorOffset││
119
+ * │ ││ │ ││ │
120
+ * │ └┤ │ ┌──▼───┐ ││ │
121
+ * │ ┌┼──────┤ ││
122
+ * │ └─►│Anchor ││
123
+ * │ └┴──────┘ ││
124
+ * │ ││
125
+ * │ ┌───────────────────────┼┼────┐
126
+ * │ Surface ││
127
+ * │ │ │ ││ │ │
128
+ * │ │ ││ │
129
+ * │ ││ │
130
+ * │ │ ││ │ │
131
+ * ┌┼─────┼───────────────────────┼│
132
+ * │ ┌─►┴──────┼────────────────────────┘ ├┐ │
133
+ * │ │ │ inline/blockOOBCorrection ││ │
134
+ * │ │ │ │ ││ │
135
+ * │ │ │ ├──►├│ │
136
+ * │ │ │ │ ││ │
137
+ * │ │ └────────────────────────┐▼───┼┘ │
138
+ * │ blockScrollbarHeight └────┘ │
139
+ * │ │
140
+ * └───────────────────────────────────────────────┘
108
141
  */
109
142
  // Calculate the block positioning properties
110
143
  let { blockInset, blockOutOfBoundsCorrection, surfaceBlockProperty } = this.calculateBlock({
@@ -113,7 +146,9 @@ export class SurfacePositionController {
113
146
  anchorBlock,
114
147
  surfaceBlock,
115
148
  yOffset,
116
- positioning
149
+ positioning,
150
+ windowInnerHeight,
151
+ blockScrollbarHeight,
117
152
  });
118
153
  // If the surface should be out of bounds in the block direction, flip the
119
154
  // surface and anchor corner block values and recalculate
@@ -126,12 +161,13 @@ export class SurfacePositionController {
126
161
  anchorBlock: flippedAnchorBlock,
127
162
  surfaceBlock: flippedSurfaceBlock,
128
163
  yOffset,
129
- positioning
164
+ positioning,
165
+ windowInnerHeight,
166
+ blockScrollbarHeight,
130
167
  });
131
168
  // In the case that the flipped verion would require less out of bounds
132
169
  // correcting, use the flipped corner block values
133
- if (blockOutOfBoundsCorrection >
134
- flippedBlock.blockOutOfBoundsCorrection) {
170
+ if (blockOutOfBoundsCorrection > flippedBlock.blockOutOfBoundsCorrection) {
135
171
  blockInset = flippedBlock.blockInset;
136
172
  blockOutOfBoundsCorrection = flippedBlock.blockOutOfBoundsCorrection;
137
173
  surfaceBlockProperty = flippedBlock.surfaceBlockProperty;
@@ -146,6 +182,8 @@ export class SurfacePositionController {
146
182
  xOffset,
147
183
  positioning,
148
184
  isLTR,
185
+ windowInnerWidth,
186
+ inlineScrollbarWidth,
149
187
  });
150
188
  // If the surface should be out of bounds in the inline direction, flip the
151
189
  // surface and anchor corner inline values and recalculate
@@ -160,6 +198,8 @@ export class SurfacePositionController {
160
198
  xOffset,
161
199
  positioning,
162
200
  isLTR,
201
+ windowInnerWidth,
202
+ inlineScrollbarWidth,
163
203
  });
164
204
  // In the case that the flipped verion would require less out of bounds
165
205
  // correcting, use the flipped corner inline values
@@ -187,13 +227,11 @@ export class SurfacePositionController {
187
227
  if (repositionStrategy === 'resize') {
188
228
  // Add a height property to the styles if there is block height correction
189
229
  if (blockOutOfBoundsCorrection) {
190
- this.surfaceStylesInternal['height'] =
191
- `${surfaceRect.height - blockOutOfBoundsCorrection}px`;
230
+ this.surfaceStylesInternal['height'] = `${surfaceRect.height - blockOutOfBoundsCorrection}px`;
192
231
  }
193
232
  // Add a width property to the styles if there is block height correction
194
233
  if (inlineOutOfBoundsCorrection) {
195
- this.surfaceStylesInternal['width'] =
196
- `${surfaceRect.width - inlineOutOfBoundsCorrection}px`;
234
+ this.surfaceStylesInternal['width'] = `${surfaceRect.width - inlineOutOfBoundsCorrection}px`;
197
235
  }
198
236
  }
199
237
  this.host.requestUpdate();
@@ -203,10 +241,11 @@ export class SurfacePositionController {
203
241
  * for the surface in the block direction.
204
242
  */
205
243
  calculateBlock(config) {
206
- const { surfaceRect, anchorRect, anchorBlock, surfaceBlock, yOffset, positioning, } = config;
244
+ const { surfaceRect, anchorRect, anchorBlock, surfaceBlock, yOffset, positioning, windowInnerHeight, blockScrollbarHeight, } = config;
207
245
  // We use number booleans to multiply values rather than `if` / ternary
208
246
  // statements because it _heavily_ cuts down on nesting and readability
209
- const relativeToWindow = positioning === 'fixed' ? 1 : 0;
247
+ const relativeToWindow = positioning === 'fixed' || positioning === 'document' ? 1 : 0;
248
+ const relativeToDocument = positioning === 'document' ? 1 : 0;
210
249
  const isSurfaceBlockStart = surfaceBlock === 'start' ? 1 : 0;
211
250
  const isSurfaceBlockEnd = surfaceBlock === 'end' ? 1 : 0;
212
251
  const isOneBlockEnd = anchorBlock !== surfaceBlock ? 1 : 0;
@@ -214,13 +253,19 @@ export class SurfacePositionController {
214
253
  const blockAnchorOffset = isOneBlockEnd * anchorRect.height + yOffset;
215
254
  // The absolute block position of the anchor relative to window
216
255
  const blockTopLayerOffset = isSurfaceBlockStart * anchorRect.top +
217
- isSurfaceBlockEnd * (window.innerHeight - anchorRect.bottom);
256
+ isSurfaceBlockEnd *
257
+ (windowInnerHeight - anchorRect.bottom - blockScrollbarHeight);
258
+ const blockDocumentOffset = isSurfaceBlockStart * window.scrollY - isSurfaceBlockEnd * window.scrollY;
218
259
  // If the surface's block would be out of bounds of the window, move it back
219
260
  // in
220
- const blockOutOfBoundsCorrection = Math.abs(Math.min(0, window.innerHeight - blockTopLayerOffset - blockAnchorOffset -
261
+ const blockOutOfBoundsCorrection = Math.abs(Math.min(0, windowInnerHeight -
262
+ blockTopLayerOffset -
263
+ blockAnchorOffset -
221
264
  surfaceRect.height));
222
265
  // The block logical value of the surface
223
- const blockInset = relativeToWindow * blockTopLayerOffset + blockAnchorOffset;
266
+ const blockInset = relativeToWindow * blockTopLayerOffset +
267
+ relativeToDocument * blockDocumentOffset +
268
+ blockAnchorOffset;
224
269
  const surfaceBlockProperty = surfaceBlock === 'start' ? 'inset-block-start' : 'inset-block-end';
225
270
  return { blockInset, blockOutOfBoundsCorrection, surfaceBlockProperty };
226
271
  }
@@ -229,10 +274,11 @@ export class SurfacePositionController {
229
274
  * for the surface in the inline direction.
230
275
  */
231
276
  calculateInline(config) {
232
- const { isLTR: isLTRBool, surfaceInline, anchorInline, anchorRect, surfaceRect, xOffset, positioning, } = config;
277
+ const { isLTR: isLTRBool, surfaceInline, anchorInline, anchorRect, surfaceRect, xOffset, positioning, windowInnerWidth, inlineScrollbarWidth, } = config;
233
278
  // We use number booleans to multiply values rather than `if` / ternary
234
279
  // statements because it _heavily_ cuts down on nesting and readability
235
- const relativeToWindow = positioning === 'fixed' ? 1 : 0;
280
+ const relativeToWindow = positioning === 'fixed' || positioning === 'document' ? 1 : 0;
281
+ const relativeToDocument = positioning === 'document' ? 1 : 0;
236
282
  const isLTR = isLTRBool ? 1 : 0;
237
283
  const isRTL = isLTRBool ? 0 : 1;
238
284
  const isSurfaceInlineStart = surfaceInline === 'start' ? 1 : 0;
@@ -242,19 +288,44 @@ export class SurfacePositionController {
242
288
  const inlineAnchorOffset = isOneInlineEnd * anchorRect.width + xOffset;
243
289
  // The inline position of the anchor relative to window in LTR
244
290
  const inlineTopLayerOffsetLTR = isSurfaceInlineStart * anchorRect.left +
245
- isSurfaceInlineEnd * (window.innerWidth - anchorRect.right);
291
+ isSurfaceInlineEnd *
292
+ (windowInnerWidth - anchorRect.right - inlineScrollbarWidth);
246
293
  // The inline position of the anchor relative to window in RTL
247
- const inlineTopLayerOffsetRTL = isSurfaceInlineStart * (window.innerWidth - anchorRect.right) +
294
+ const inlineTopLayerOffsetRTL = isSurfaceInlineStart *
295
+ (windowInnerWidth - anchorRect.right - inlineScrollbarWidth) +
248
296
  isSurfaceInlineEnd * anchorRect.left;
249
297
  // The inline position of the anchor relative to window
250
298
  const inlineTopLayerOffset = isLTR * inlineTopLayerOffsetLTR + isRTL * inlineTopLayerOffsetRTL;
299
+ // The inline position of the anchor relative to window in LTR
300
+ const inlineDocumentOffsetLTR = isSurfaceInlineStart * window.scrollX -
301
+ isSurfaceInlineEnd * window.scrollX;
302
+ // The inline position of the anchor relative to window in RTL
303
+ const inlineDocumentOffsetRTL = isSurfaceInlineEnd * window.scrollX -
304
+ isSurfaceInlineStart * window.scrollX;
305
+ // The inline position of the anchor relative to window
306
+ const inlineDocumentOffset = isLTR * inlineDocumentOffsetLTR + isRTL * inlineDocumentOffsetRTL;
251
307
  // If the surface's inline would be out of bounds of the window, move it
252
308
  // back in
253
- const inlineOutOfBoundsCorrection = Math.abs(Math.min(0, window.innerWidth - inlineTopLayerOffset - inlineAnchorOffset -
309
+ const inlineOutOfBoundsCorrection = Math.abs(Math.min(0, windowInnerWidth -
310
+ inlineTopLayerOffset -
311
+ inlineAnchorOffset -
254
312
  surfaceRect.width));
255
313
  // The inline logical value of the surface
256
- const inlineInset = relativeToWindow * inlineTopLayerOffset + inlineAnchorOffset;
257
- const surfaceInlineProperty = surfaceInline === 'start' ? 'inset-inline-start' : 'inset-inline-end';
314
+ const inlineInset = relativeToWindow * inlineTopLayerOffset +
315
+ inlineAnchorOffset +
316
+ relativeToDocument * inlineDocumentOffset;
317
+ let surfaceInlineProperty = surfaceInline === 'start' ? 'inset-inline-start' : 'inset-inline-end';
318
+ // There are cases where the element is RTL but the root of the page is not.
319
+ // In these cases we want to not use logical properties.
320
+ if (positioning === 'document' || positioning === 'fixed') {
321
+ if ((surfaceInline === 'start' && isLTRBool) ||
322
+ (surfaceInline === 'end' && !isLTRBool)) {
323
+ surfaceInlineProperty = 'left';
324
+ }
325
+ else {
326
+ surfaceInlineProperty = 'right';
327
+ }
328
+ }
258
329
  return {
259
330
  inlineInset,
260
331
  inlineOutOfBoundsCorrection,
@@ -277,7 +348,7 @@ export class SurfacePositionController {
277
348
  let hasChanged = false;
278
349
  for (const [key, value] of Object.entries(props)) {
279
350
  // tslint:disable-next-line
280
- hasChanged = hasChanged || (value !== this.lastValues[key]);
351
+ hasChanged = hasChanged || value !== this.lastValues[key];
281
352
  if (hasChanged)
282
353
  break;
283
354
  }
@@ -311,6 +382,13 @@ export class SurfacePositionController {
311
382
  'display': 'none',
312
383
  };
313
384
  this.host.requestUpdate();
385
+ const surfaceEl = this.getProperties().surfaceEl;
386
+ // The following type casts are required due to differing TS types in Google
387
+ // and open source.
388
+ if (surfaceEl?.popover &&
389
+ surfaceEl?.isConnected) {
390
+ surfaceEl.hidePopover();
391
+ }
314
392
  }
315
393
  }
316
394
  //# sourceMappingURL=surfacePositionController.js.map
@@ -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,CAA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UAAU,IAAI,CAAC,KAAK,KAAM,IAAI,CAAC,UAAkB,CAAC,GAAG,CAAC,CAAC,CAAC;YACrE,IAAI,UAAU;gBAAE,MAAM;SACvB;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,CAAC;QAC5D,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;QACnC,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,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;AAmBH;;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,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C;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;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. 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 }\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"]}