@material/web 1.0.0-pre.1 → 1.0.0-pre.3

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 (683) hide show
  1. package/README.md +66 -19
  2. package/autocomplete/autocomplete-item.js.map +1 -1
  3. package/autocomplete/autocomplete-list.js.map +1 -1
  4. package/autocomplete/autocomplete-surface.js.map +1 -1
  5. package/autocomplete/filled-autocomplete.d.ts +0 -2
  6. package/autocomplete/filled-autocomplete.js +0 -7
  7. package/autocomplete/filled-autocomplete.js.map +1 -1
  8. package/autocomplete/lib/_filled-autocomplete.scss +23 -62
  9. package/autocomplete/lib/_outlined-autocomplete.scss +24 -63
  10. package/autocomplete/lib/_shared.scss +6 -10
  11. package/autocomplete/lib/autocomplete.d.ts +2 -6
  12. package/autocomplete/lib/autocomplete.js +9 -17
  13. package/autocomplete/lib/autocomplete.js.map +1 -1
  14. package/autocomplete/lib/autocompleteitem/autocomplete-item.d.ts +2 -2
  15. package/autocomplete/lib/autocompleteitem/autocomplete-item.js +2 -2
  16. package/autocomplete/lib/autocompleteitem/autocomplete-item.js.map +1 -1
  17. package/autocomplete/lib/autocompletelist/autocomplete-list-styles.scss +2 -0
  18. package/autocomplete/lib/autocompletelist/autocomplete-list.d.ts +1 -1
  19. package/autocomplete/lib/autocompletelist/autocomplete-list.js +2 -2
  20. package/autocomplete/lib/autocompletelist/autocomplete-list.js.map +1 -1
  21. package/autocomplete/lib/autocompletesurface/autocomplete-surface-styles.scss +2 -0
  22. package/autocomplete/lib/filled-styles.css.js +1 -1
  23. package/autocomplete/lib/filled-styles.css.js.map +1 -1
  24. package/autocomplete/lib/filled-styles.scss +2 -0
  25. package/autocomplete/lib/outlined-styles.css.js +1 -1
  26. package/autocomplete/lib/outlined-styles.css.js.map +1 -1
  27. package/autocomplete/lib/outlined-styles.scss +2 -0
  28. package/autocomplete/lib/shared-styles.scss +2 -0
  29. package/autocomplete/outlined-autocomplete.d.ts +0 -2
  30. package/autocomplete/outlined-autocomplete.js +0 -7
  31. package/autocomplete/outlined-autocomplete.js.map +1 -1
  32. package/badge/badge.js.map +1 -1
  33. package/badge/lib/_badge.scss +10 -13
  34. package/badge/lib/badge-styles.css.js +1 -1
  35. package/badge/lib/badge-styles.css.js.map +1 -1
  36. package/badge/lib/badge-styles.scss +2 -0
  37. package/badge/lib/badge.js.map +1 -1
  38. package/button/elevated-button.js.map +1 -1
  39. package/button/elevated-link-button.js.map +1 -1
  40. package/button/filled-button.js.map +1 -1
  41. package/button/filled-link-button.js.map +1 -1
  42. package/button/lib/_elevated-button.scss +10 -15
  43. package/button/lib/_elevation.scss +5 -2
  44. package/button/lib/_filled-button.scss +12 -14
  45. package/button/lib/_icon.scss +15 -24
  46. package/button/lib/_outlined-button.scss +10 -15
  47. package/button/lib/_shared.scss +15 -19
  48. package/button/lib/_text-button.scss +12 -14
  49. package/button/lib/_tonal-button.scss +10 -15
  50. package/button/lib/button.d.ts +0 -3
  51. package/button/lib/button.js +1 -12
  52. package/button/lib/button.js.map +1 -1
  53. package/button/lib/elevated-styles.css.js +1 -1
  54. package/button/lib/elevated-styles.css.js.map +1 -1
  55. package/button/lib/elevated-styles.scss +2 -0
  56. package/button/lib/filled-styles.css.js +1 -1
  57. package/button/lib/filled-styles.css.js.map +1 -1
  58. package/button/lib/filled-styles.scss +2 -0
  59. package/button/lib/link-button.d.ts +0 -1
  60. package/button/lib/link-button.js +0 -5
  61. package/button/lib/link-button.js.map +1 -1
  62. package/button/lib/outlined-styles.css.js +1 -1
  63. package/button/lib/outlined-styles.css.js.map +1 -1
  64. package/button/lib/outlined-styles.scss +2 -0
  65. package/button/lib/shared-elevation-styles.css.js +1 -1
  66. package/button/lib/shared-elevation-styles.css.js.map +1 -1
  67. package/button/lib/shared-elevation-styles.scss +2 -0
  68. package/button/lib/shared-styles.css.js +1 -1
  69. package/button/lib/shared-styles.css.js.map +1 -1
  70. package/button/lib/shared-styles.scss +2 -0
  71. package/button/lib/text-styles.css.js +1 -1
  72. package/button/lib/text-styles.css.js.map +1 -1
  73. package/button/lib/text-styles.scss +2 -0
  74. package/button/lib/tonal-styles.css.js +1 -1
  75. package/button/lib/tonal-styles.css.js.map +1 -1
  76. package/button/lib/tonal-styles.scss +2 -0
  77. package/button/outlined-button.js.map +1 -1
  78. package/button/outlined-link-button.js.map +1 -1
  79. package/button/text-button.js.map +1 -1
  80. package/button/text-link-button.js.map +1 -1
  81. package/button/tonal-button.js.map +1 -1
  82. package/button/tonal-link-button.js.map +1 -1
  83. package/checkbox/checkbox.d.ts +11 -2
  84. package/checkbox/checkbox.js +11 -2
  85. package/checkbox/checkbox.js.map +1 -1
  86. package/checkbox/lib/_checkbox.scss +26 -31
  87. package/checkbox/lib/checkbox-styles.css.js +1 -1
  88. package/checkbox/lib/checkbox-styles.css.js.map +1 -1
  89. package/checkbox/lib/checkbox-styles.scss +2 -0
  90. package/checkbox/lib/checkbox.d.ts +28 -0
  91. package/checkbox/lib/checkbox.js +33 -4
  92. package/checkbox/lib/checkbox.js.map +1 -1
  93. package/checkbox/lib/forced-colors-styles.scss +2 -0
  94. package/chips/action/delete-action.js.map +1 -1
  95. package/chips/action/lib/action.js +4 -4
  96. package/chips/action/lib/action.js.map +1 -1
  97. package/chips/action/lib/link-action.js +1 -1
  98. package/chips/action/lib/link-action.js.map +1 -1
  99. package/chips/action/lib/primary-action.js.map +1 -1
  100. package/chips/action/lib/selectable-action.js.map +1 -1
  101. package/chips/action/link-action.js.map +1 -1
  102. package/chips/action/presentational-action.js.map +1 -1
  103. package/chips/action/primary-action.js.map +1 -1
  104. package/chips/action/selectable-action.js.map +1 -1
  105. package/chips/chip/lib/_assist-chip-theme.scss +4 -0
  106. package/chips/chip/lib/_chip-theme.scss +30 -41
  107. package/chips/chip/lib/_chip.scss +2 -0
  108. package/chips/chip/lib/_filter-chip-theme.scss +4 -0
  109. package/chips/chip/lib/_input-chip-theme.scss +4 -0
  110. package/chips/chip/lib/_suggestion-chip-theme.scss +4 -0
  111. package/chips/chip/lib/chip.js.map +1 -1
  112. package/chips/chip/lib/foundation.js +4 -4
  113. package/chips/chip/lib/foundation.js.map +1 -1
  114. package/chips/chip/lib/link-chip.js.map +1 -1
  115. package/chips/chip/lib/selectable-chip.js.map +1 -1
  116. package/chips/chip/lib/types.d.ts +2 -2
  117. package/chips/chipset/lib/_chip-set-theme.scss +2 -0
  118. package/chips/chipset/lib/_chip-set.scss +2 -0
  119. package/chips/chipset/lib/foundation.js +3 -3
  120. package/chips/chipset/lib/foundation.js.map +1 -1
  121. package/chips/chipset/lib/types.d.ts +3 -3
  122. package/controller/events.js +4 -0
  123. package/controller/events.js.map +1 -1
  124. package/controller/form-controller.js.map +1 -1
  125. package/controller/foundation.d.ts +1 -1
  126. package/controller/observer.d.ts +2 -2
  127. package/dialog/_dialog.scss +6 -0
  128. package/dialog/dialog.d.ts +38 -0
  129. package/dialog/dialog.js +41 -0
  130. package/dialog/dialog.js.map +1 -0
  131. package/dialog/harness.d.ts +18 -0
  132. package/dialog/harness.js +58 -0
  133. package/dialog/harness.js.map +1 -0
  134. package/dialog/lib/_dialog.scss +382 -0
  135. package/dialog/lib/_tokens.scss +89 -0
  136. package/dialog/lib/dialog-styles.css.js +9 -0
  137. package/dialog/lib/dialog-styles.css.js.map +1 -0
  138. package/dialog/lib/dialog-styles.scss +10 -0
  139. package/dialog/lib/dialog.d.ts +190 -0
  140. package/dialog/lib/dialog.js +568 -0
  141. package/dialog/lib/dialog.js.map +1 -0
  142. package/divider/_divider.scss +6 -0
  143. package/divider/divider.d.ts +24 -0
  144. package/divider/divider.js +27 -0
  145. package/divider/divider.js.map +1 -0
  146. package/divider/lib/_divider.scss +56 -0
  147. package/divider/lib/divider-styles.css.js +9 -0
  148. package/divider/lib/divider-styles.css.js.map +1 -0
  149. package/divider/lib/divider-styles.scss +10 -0
  150. package/divider/lib/divider.d.ts +23 -0
  151. package/divider/lib/divider.js +41 -0
  152. package/divider/lib/divider.js.map +1 -0
  153. package/elevation/elevation.js.map +1 -1
  154. package/elevation/lib/_elevation.scss +5 -1
  155. package/elevation/lib/_md-comp-elevation.scss +5 -1
  156. package/elevation/lib/elevation-styles.css.js +1 -1
  157. package/elevation/lib/elevation-styles.css.js.map +1 -1
  158. package/elevation/lib/elevation-styles.scss +2 -0
  159. package/elevation/lib/elevation.js.map +1 -1
  160. package/fab/fab-extended.js.map +1 -1
  161. package/fab/fab.js.map +1 -1
  162. package/fab/lib/_fab-extended.scss +18 -11
  163. package/fab/lib/_fab.scss +7 -2
  164. package/fab/lib/_shared.scss +17 -9
  165. package/fab/lib/fab-extended-styles.css.js +1 -1
  166. package/fab/lib/fab-extended-styles.css.js.map +1 -1
  167. package/fab/lib/fab-extended-styles.scss +2 -0
  168. package/fab/lib/fab-shared-styles.css.js +1 -1
  169. package/fab/lib/fab-shared-styles.css.js.map +1 -1
  170. package/fab/lib/fab-shared-styles.scss +2 -0
  171. package/fab/lib/fab-shared.d.ts +9 -15
  172. package/fab/lib/fab-shared.js +21 -33
  173. package/fab/lib/fab-shared.js.map +1 -1
  174. package/fab/lib/fab-styles.css.js +1 -1
  175. package/fab/lib/fab-styles.css.js.map +1 -1
  176. package/fab/lib/fab-styles.scss +2 -0
  177. package/field/filled-field.d.ts +1 -1
  178. package/field/filled-field.js +1 -1
  179. package/field/filled-field.js.map +1 -1
  180. package/field/harness.js +1 -1
  181. package/field/harness.js.map +1 -1
  182. package/field/lib/_content.scss +35 -50
  183. package/field/lib/_filled-field.scss +60 -76
  184. package/field/lib/_label.scss +26 -63
  185. package/field/lib/_md-comp-filled-field.scss +17 -3
  186. package/field/lib/_md-comp-outlined-field.scss +16 -5
  187. package/field/lib/_outlined-field.scss +96 -110
  188. package/field/lib/_shared.scss +15 -35
  189. package/field/lib/_supporting-text.scss +25 -52
  190. package/field/lib/field.d.ts +14 -33
  191. package/field/lib/field.js +79 -101
  192. package/field/lib/field.js.map +1 -1
  193. package/field/lib/filled-field.d.ts +10 -16
  194. package/field/lib/filled-field.js +14 -37
  195. package/field/lib/filled-field.js.map +1 -1
  196. package/field/lib/filled-styles.css.js +1 -1
  197. package/field/lib/filled-styles.css.js.map +1 -1
  198. package/field/lib/outlined-field.d.ts +4 -10
  199. package/field/lib/outlined-field.js +13 -33
  200. package/field/lib/outlined-field.js.map +1 -1
  201. package/field/lib/outlined-styles.css.js +1 -1
  202. package/field/lib/outlined-styles.css.js.map +1 -1
  203. package/field/lib/shared-styles.css.js +1 -1
  204. package/field/lib/shared-styles.css.js.map +1 -1
  205. package/field/outlined-field.d.ts +1 -1
  206. package/field/outlined-field.js +1 -1
  207. package/field/outlined-field.js.map +1 -1
  208. package/focus/focus-ring.js.map +1 -1
  209. package/focus/lib/_focus-ring.scss +10 -23
  210. package/focus/lib/_md-comp-focus-ring.scss +4 -0
  211. package/focus/lib/focus-ring-styles.css.js +1 -1
  212. package/focus/lib/focus-ring-styles.css.js.map +1 -1
  213. package/focus/lib/focus-ring-styles.scss +2 -0
  214. package/focus/lib/focus-ring.d.ts +1 -4
  215. package/focus/lib/focus-ring.js +2 -11
  216. package/focus/lib/focus-ring.js.map +1 -1
  217. package/icon/icon.js.map +1 -1
  218. package/icon/lib/_icon.scss +2 -0
  219. package/icon/lib/icon-styles.scss +2 -0
  220. package/iconbutton/filled-icon-button-toggle.js.map +1 -1
  221. package/iconbutton/filled-icon-button.js.map +1 -1
  222. package/iconbutton/filled-link-icon-button.js.map +1 -1
  223. package/iconbutton/filled-tonal-icon-button-toggle.js.map +1 -1
  224. package/iconbutton/filled-tonal-icon-button.js.map +1 -1
  225. package/iconbutton/filled-tonal-link-icon-button.js.map +1 -1
  226. package/iconbutton/lib/_filled-icon-button.scss +20 -20
  227. package/iconbutton/lib/_filled-tonal-icon-button.scss +20 -20
  228. package/iconbutton/lib/_outlined-icon-button.scss +27 -21
  229. package/iconbutton/lib/_shared.scss +13 -33
  230. package/iconbutton/lib/_standard-icon-button.scss +25 -24
  231. package/iconbutton/lib/filled-styles.css.js +1 -1
  232. package/iconbutton/lib/filled-styles.css.js.map +1 -1
  233. package/iconbutton/lib/filled-styles.scss +2 -0
  234. package/iconbutton/lib/filled-tonal-styles.css.js +1 -1
  235. package/iconbutton/lib/filled-tonal-styles.css.js.map +1 -1
  236. package/iconbutton/lib/filled-tonal-styles.scss +2 -0
  237. package/iconbutton/lib/icon-button-toggle.d.ts +13 -42
  238. package/iconbutton/lib/icon-button-toggle.js +33 -103
  239. package/iconbutton/lib/icon-button-toggle.js.map +1 -1
  240. package/iconbutton/lib/icon-button.d.ts +2 -4
  241. package/iconbutton/lib/icon-button.js +3 -9
  242. package/iconbutton/lib/icon-button.js.map +1 -1
  243. package/iconbutton/lib/link-icon-button.js.map +1 -1
  244. package/iconbutton/lib/outlined-styles.css.js +1 -1
  245. package/iconbutton/lib/outlined-styles.css.js.map +1 -1
  246. package/iconbutton/lib/outlined-styles.scss +2 -0
  247. package/iconbutton/lib/shared-styles.css.js +1 -1
  248. package/iconbutton/lib/shared-styles.css.js.map +1 -1
  249. package/iconbutton/lib/shared-styles.scss +2 -0
  250. package/iconbutton/lib/standard-styles.css.js +1 -1
  251. package/iconbutton/lib/standard-styles.css.js.map +1 -1
  252. package/iconbutton/lib/standard-styles.scss +2 -0
  253. package/iconbutton/outlined-icon-button-toggle.js.map +1 -1
  254. package/iconbutton/outlined-icon-button.js.map +1 -1
  255. package/iconbutton/outlined-link-icon-button.js.map +1 -1
  256. package/iconbutton/standard-icon-button-toggle.js.map +1 -1
  257. package/iconbutton/standard-icon-button.js.map +1 -1
  258. package/iconbutton/standard-link-icon-button.js.map +1 -1
  259. package/list/lib/_list.scss +35 -39
  260. package/list/lib/avatar/_list-item-avatar.scss +3 -1
  261. package/list/lib/avatar/list-item-avatar-styles.css.js +1 -1
  262. package/list/lib/avatar/list-item-avatar-styles.css.js.map +1 -1
  263. package/list/lib/avatar/list-item-avatar-styles.scss +2 -0
  264. package/list/lib/avatar/list-item-avatar.d.ts +9 -4
  265. package/list/lib/avatar/list-item-avatar.js +24 -11
  266. package/list/lib/avatar/list-item-avatar.js.map +1 -1
  267. package/list/lib/icon/_list-item-icon.scss +7 -1
  268. package/list/lib/icon/list-item-icon-styles.css.js +1 -1
  269. package/list/lib/icon/list-item-icon-styles.css.js.map +1 -1
  270. package/list/lib/icon/list-item-icon-styles.scss +2 -0
  271. package/list/lib/icon/list-item-icon.d.ts +0 -3
  272. package/list/lib/icon/list-item-icon.js +1 -12
  273. package/list/lib/icon/list-item-icon.js.map +1 -1
  274. package/list/lib/image/_list-item-image.scss +6 -2
  275. package/list/lib/image/list-item-image-styles.css.js +1 -1
  276. package/list/lib/image/list-item-image-styles.css.js.map +1 -1
  277. package/list/lib/image/list-item-image-styles.scss +2 -0
  278. package/list/lib/image/list-item-image.d.ts +11 -4
  279. package/list/lib/image/list-item-image.js +24 -13
  280. package/list/lib/image/list-item-image.js.map +1 -1
  281. package/list/lib/list-styles.css.js +1 -1
  282. package/list/lib/list-styles.css.js.map +1 -1
  283. package/list/lib/list-styles.scss +2 -0
  284. package/list/lib/list.d.ts +99 -28
  285. package/list/lib/list.js +213 -112
  286. package/list/lib/list.js.map +1 -1
  287. package/list/lib/listitem/_list-item.scss +122 -56
  288. package/list/lib/listitem/harness.js +2 -1
  289. package/list/lib/listitem/harness.js.map +1 -1
  290. package/list/lib/listitem/list-item-private-styles.css.js +9 -0
  291. package/list/lib/listitem/list-item-private-styles.css.js.map +1 -0
  292. package/list/lib/listitem/list-item-private-styles.scss +10 -0
  293. package/list/lib/listitem/list-item-styles.css.js +1 -1
  294. package/list/lib/listitem/list-item-styles.css.js.map +1 -1
  295. package/list/lib/listitem/list-item-styles.scss +2 -0
  296. package/list/lib/listitem/list-item.d.ts +99 -43
  297. package/list/lib/listitem/list-item.js +204 -173
  298. package/list/lib/listitem/list-item.js.map +1 -1
  299. package/list/lib/listitemlink/list-item-link.d.ts +17 -0
  300. package/list/lib/listitemlink/list-item-link.js +42 -0
  301. package/list/lib/listitemlink/list-item-link.js.map +1 -0
  302. package/list/lib/video/_list-item-video.scss +15 -5
  303. package/list/lib/video/list-item-video-styles.css.js +1 -1
  304. package/list/lib/video/list-item-video-styles.css.js.map +1 -1
  305. package/list/lib/video/list-item-video-styles.scss +2 -0
  306. package/list/lib/video/list-item-video.d.ts +43 -4
  307. package/list/lib/video/list-item-video.js +90 -12
  308. package/list/lib/video/list-item-video.js.map +1 -1
  309. package/list/list-item-avatar.d.ts +2 -1
  310. package/list/list-item-avatar.js +2 -1
  311. package/list/list-item-avatar.js.map +1 -1
  312. package/list/list-item-icon.d.ts +2 -1
  313. package/list/list-item-icon.js +2 -1
  314. package/list/list-item-icon.js.map +1 -1
  315. package/list/list-item-image.d.ts +2 -1
  316. package/list/list-item-image.js +2 -1
  317. package/list/list-item-image.js.map +1 -1
  318. package/list/list-item-link.d.ts +35 -0
  319. package/list/list-item-link.js +39 -0
  320. package/list/list-item-link.js.map +1 -0
  321. package/list/list-item-video.d.ts +2 -1
  322. package/list/list-item-video.js +2 -1
  323. package/list/list-item-video.js.map +1 -1
  324. package/list/list-item.d.ts +18 -2
  325. package/list/list-item.js +20 -3
  326. package/list/list-item.js.map +1 -1
  327. package/list/list.d.ts +15 -1
  328. package/list/list.js +15 -1
  329. package/list/list.js.map +1 -1
  330. package/menu/_menu-item.scss +6 -0
  331. package/menu/_menu.scss +6 -0
  332. package/menu/harness.d.ts +5 -0
  333. package/menu/harness.js +22 -0
  334. package/menu/harness.js.map +1 -1
  335. package/menu/lib/_menu.scss +64 -62
  336. package/menu/lib/menu-styles.css.js +1 -1
  337. package/menu/lib/menu-styles.css.js.map +1 -1
  338. package/menu/lib/menu-styles.scss +2 -0
  339. package/menu/lib/menu.d.ts +177 -43
  340. package/menu/lib/menu.js +506 -246
  341. package/menu/lib/menu.js.map +1 -1
  342. package/menu/lib/menuitem/_menu-item.scss +123 -0
  343. package/menu/lib/menuitem/menu-item-private-styles.css.js +9 -0
  344. package/menu/lib/menuitem/menu-item-private-styles.css.js.map +1 -0
  345. package/menu/lib/menuitem/menu-item-private-styles.scss +10 -0
  346. package/menu/lib/menuitem/menu-item-styles.css.d.ts +1 -0
  347. package/menu/lib/menuitem/menu-item-styles.css.js +9 -0
  348. package/menu/lib/menuitem/menu-item-styles.css.js.map +1 -0
  349. package/menu/lib/menuitem/menu-item-styles.scss +10 -0
  350. package/menu/lib/menuitem/menu-item.d.ts +20 -3
  351. package/menu/lib/menuitem/menu-item.js +42 -3
  352. package/menu/lib/menuitem/menu-item.js.map +1 -1
  353. package/menu/lib/menuitemlink/menu-item-link.d.ts +25 -0
  354. package/menu/lib/menuitemlink/menu-item-link.js +51 -0
  355. package/menu/lib/menuitemlink/menu-item-link.js.map +1 -0
  356. package/menu/lib/shared.d.ts +134 -0
  357. package/menu/lib/shared.js +85 -0
  358. package/menu/lib/shared.js.map +1 -0
  359. package/menu/lib/submenuitem/harness.d.ts +11 -0
  360. package/menu/lib/submenuitem/harness.js +12 -0
  361. package/menu/lib/submenuitem/harness.js.map +1 -0
  362. package/menu/lib/submenuitem/sub-menu-item.d.ts +89 -0
  363. package/menu/lib/submenuitem/sub-menu-item.js +266 -0
  364. package/menu/lib/submenuitem/sub-menu-item.js.map +1 -0
  365. package/menu/lib/surfacePositionController.d.ts +117 -0
  366. package/menu/lib/surfacePositionController.js +196 -0
  367. package/menu/lib/surfacePositionController.js.map +1 -0
  368. package/menu/lib/typeaheadController.d.ts +144 -0
  369. package/menu/lib/typeaheadController.js +242 -0
  370. package/menu/lib/typeaheadController.js.map +1 -0
  371. package/menu/menu-item-link.d.ts +33 -0
  372. package/menu/menu-item-link.js +37 -0
  373. package/menu/menu-item-link.js.map +1 -0
  374. package/menu/menu-item.d.ts +19 -2
  375. package/menu/menu-item.js +22 -4
  376. package/menu/menu-item.js.map +1 -1
  377. package/menu/menu.d.ts +45 -0
  378. package/menu/menu.js +43 -0
  379. package/menu/menu.js.map +1 -1
  380. package/menu/sub-menu-item.d.ts +60 -0
  381. package/menu/sub-menu-item.js +64 -0
  382. package/menu/sub-menu-item.js.map +1 -0
  383. package/menusurface/lib/_md-comp-menu-surface.scss +4 -0
  384. package/menusurface/lib/_menu-surface.scss +5 -1
  385. package/menusurface/lib/foundation.js +31 -31
  386. package/menusurface/lib/foundation.js.map +1 -1
  387. package/menusurface/lib/menu-surface-styles.css.js +1 -1
  388. package/menusurface/lib/menu-surface-styles.css.js.map +1 -1
  389. package/menusurface/lib/menu-surface-styles.scss +2 -0
  390. package/menusurface/lib/menu-surface.d.ts +2 -2
  391. package/menusurface/lib/menu-surface.js.map +1 -1
  392. package/menusurface/menu-surface.js.map +1 -1
  393. package/motion/animation.d.ts +20 -3
  394. package/motion/animation.js +39 -4
  395. package/motion/animation.js.map +1 -1
  396. package/navigationbar/lib/_navigation-bar.scss +11 -9
  397. package/navigationbar/lib/constants.d.ts +1 -1
  398. package/navigationbar/lib/navigation-bar-styles.css.js +1 -1
  399. package/navigationbar/lib/navigation-bar-styles.css.js.map +1 -1
  400. package/navigationbar/lib/navigation-bar-styles.scss +2 -0
  401. package/navigationbar/lib/navigation-bar.js.map +1 -1
  402. package/navigationbar/navigation-bar.js.map +1 -1
  403. package/navigationdrawer/lib/_navigation-drawer-modal.scss +11 -2
  404. package/navigationdrawer/lib/_navigation-drawer.scss +11 -6
  405. package/navigationdrawer/lib/_shared.scss +4 -8
  406. package/navigationdrawer/lib/navigation-drawer-modal-styles.css.js +1 -1
  407. package/navigationdrawer/lib/navigation-drawer-modal-styles.css.js.map +1 -1
  408. package/navigationdrawer/lib/navigation-drawer-modal-styles.scss +2 -0
  409. package/navigationdrawer/lib/navigation-drawer-modal.js.map +1 -1
  410. package/navigationdrawer/lib/navigation-drawer-styles.css.js +1 -1
  411. package/navigationdrawer/lib/navigation-drawer-styles.css.js.map +1 -1
  412. package/navigationdrawer/lib/navigation-drawer-styles.scss +2 -0
  413. package/navigationdrawer/lib/navigation-drawer.js.map +1 -1
  414. package/navigationdrawer/lib/shared-styles.scss +2 -0
  415. package/navigationdrawer/navigation-drawer-modal.js.map +1 -1
  416. package/navigationdrawer/navigation-drawer.js.map +1 -1
  417. package/navigationtab/lib/_navigation-tab.scss +34 -41
  418. package/navigationtab/lib/navigation-tab-styles.css.js +1 -1
  419. package/navigationtab/lib/navigation-tab-styles.css.js.map +1 -1
  420. package/navigationtab/lib/navigation-tab-styles.scss +2 -0
  421. package/navigationtab/lib/navigation-tab.js +4 -4
  422. package/navigationtab/lib/navigation-tab.js.map +1 -1
  423. package/navigationtab/navigation-tab.js.map +1 -1
  424. package/package.json +2 -9
  425. package/radio/lib/_radio.scss +16 -15
  426. package/radio/lib/forced-colors-styles.scss +2 -0
  427. package/radio/lib/radio-styles.css.js +1 -1
  428. package/radio/lib/radio-styles.css.js.map +1 -1
  429. package/radio/lib/radio-styles.scss +2 -0
  430. package/radio/lib/radio.d.ts +10 -1
  431. package/radio/lib/radio.js +28 -19
  432. package/radio/lib/radio.js.map +1 -1
  433. package/radio/radio.d.ts +16 -1
  434. package/radio/radio.js +16 -1
  435. package/radio/radio.js.map +1 -1
  436. package/ripple/directive.d.ts +1 -33
  437. package/ripple/directive.js +7 -194
  438. package/ripple/directive.js.map +1 -1
  439. package/ripple/lib/_md-comp-ripple.scss +20 -19
  440. package/ripple/lib/_ripple.scss +24 -40
  441. package/ripple/lib/ripple-styles.css.js +1 -1
  442. package/ripple/lib/ripple-styles.css.js.map +1 -1
  443. package/ripple/lib/ripple-styles.scss +2 -0
  444. package/ripple/lib/ripple.d.ts +50 -48
  445. package/ripple/lib/ripple.js +215 -77
  446. package/ripple/lib/ripple.js.map +1 -1
  447. package/ripple/ripple.d.ts +9 -1
  448. package/ripple/ripple.js +9 -1
  449. package/ripple/ripple.js.map +1 -1
  450. package/sass/_assert.scss +2 -0
  451. package/sass/_color-scheme.scss +4 -0
  452. package/sass/_color.scss +4 -0
  453. package/sass/_elevation.scss +4 -0
  454. package/sass/_feature-flags.scss +2 -0
  455. package/sass/_map-ext.scss +26 -0
  456. package/sass/_resolvers.scss +4 -4
  457. package/sass/_shape.scss +75 -27
  458. package/sass/_string-ext.scss +67 -0
  459. package/sass/_theme.scss +4 -0
  460. package/sass/_typography.scss +18 -93
  461. package/sass/_var.scss +4 -0
  462. package/segmentedbutton/lib/_outlined-segmented-button.scss +4 -0
  463. package/segmentedbutton/lib/_shared.scss +18 -22
  464. package/segmentedbutton/lib/outlined-styles.css.js +1 -1
  465. package/segmentedbutton/lib/outlined-styles.css.js.map +1 -1
  466. package/segmentedbutton/lib/outlined-styles.scss +2 -0
  467. package/segmentedbutton/lib/segmented-button.js +4 -4
  468. package/segmentedbutton/lib/segmented-button.js.map +1 -1
  469. package/segmentedbutton/lib/shared-styles.css.js +1 -1
  470. package/segmentedbutton/lib/shared-styles.css.js.map +1 -1
  471. package/segmentedbutton/lib/shared-styles.scss +2 -0
  472. package/segmentedbutton/outlined-segmented-button.js.map +1 -1
  473. package/segmentedbuttonset/lib/_outlined-segmented-button-set.scss +9 -5
  474. package/segmentedbuttonset/lib/_shared.scss +0 -13
  475. package/segmentedbuttonset/lib/outlined-styles.css.js +1 -1
  476. package/segmentedbuttonset/lib/outlined-styles.css.js.map +1 -1
  477. package/segmentedbuttonset/lib/outlined-styles.scss +2 -0
  478. package/segmentedbuttonset/lib/segmented-button-set.d.ts +0 -2
  479. package/segmentedbuttonset/lib/segmented-button-set.js +0 -2
  480. package/segmentedbuttonset/lib/segmented-button-set.js.map +1 -1
  481. package/segmentedbuttonset/lib/shared-styles.scss +2 -0
  482. package/segmentedbuttonset/outlined-segmented-button-set.js.map +1 -1
  483. package/slider/_slider.scss +6 -0
  484. package/slider/harness.d.ts +20 -0
  485. package/slider/harness.js +63 -0
  486. package/slider/harness.js.map +1 -0
  487. package/slider/lib/_slider.scss +503 -0
  488. package/slider/lib/_tokens.scss +66 -0
  489. package/slider/lib/forced-colors-styles.css.d.ts +1 -0
  490. package/slider/lib/forced-colors-styles.css.js +9 -0
  491. package/slider/lib/forced-colors-styles.css.js.map +1 -0
  492. package/slider/lib/forced-colors-styles.scss +53 -0
  493. package/slider/lib/slider-styles.css.d.ts +1 -0
  494. package/slider/lib/slider-styles.css.js +9 -0
  495. package/slider/lib/slider-styles.css.js.map +1 -0
  496. package/slider/lib/slider-styles.scss +8 -0
  497. package/slider/lib/slider.d.ts +158 -0
  498. package/slider/lib/slider.js +575 -0
  499. package/slider/lib/slider.js.map +1 -0
  500. package/slider/slider.d.ts +28 -0
  501. package/slider/slider.js +32 -0
  502. package/slider/slider.js.map +1 -0
  503. package/switch/lib/README.md +55 -0
  504. package/switch/lib/_handle.scss +72 -26
  505. package/switch/lib/_icon.scss +40 -0
  506. package/switch/lib/_switch.scss +12 -133
  507. package/switch/lib/_track.scss +41 -0
  508. package/switch/lib/switch-styles.css.js +1 -1
  509. package/switch/lib/switch-styles.css.js.map +1 -1
  510. package/switch/lib/switch-styles.scss +2 -0
  511. package/switch/lib/switch.d.ts +3 -0
  512. package/switch/lib/switch.js +12 -9
  513. package/switch/lib/switch.js.map +1 -1
  514. package/switch/switch.js.map +1 -1
  515. package/textfield/filled-text-field.d.ts +1 -1
  516. package/textfield/filled-text-field.js +1 -2
  517. package/textfield/filled-text-field.js.map +1 -1
  518. package/textfield/harness.js +1 -1
  519. package/textfield/harness.js.map +1 -1
  520. package/textfield/lib/_filled-text-field.scss +29 -23
  521. package/textfield/lib/_icon.scss +41 -56
  522. package/textfield/lib/_input.scss +17 -36
  523. package/textfield/lib/_outlined-text-field.scss +29 -23
  524. package/textfield/lib/_shared.scss +10 -29
  525. package/textfield/lib/filled-forced-colors-styles.scss +2 -0
  526. package/textfield/lib/filled-styles.css.js +1 -1
  527. package/textfield/lib/filled-styles.css.js.map +1 -1
  528. package/textfield/lib/filled-styles.scss +2 -0
  529. package/textfield/lib/filled-text-field.d.ts +6 -5
  530. package/textfield/lib/filled-text-field.js +8 -7
  531. package/textfield/lib/filled-text-field.js.map +1 -1
  532. package/textfield/lib/outlined-forced-colors-styles.scss +2 -0
  533. package/textfield/lib/outlined-styles.css.js +1 -1
  534. package/textfield/lib/outlined-styles.css.js.map +1 -1
  535. package/textfield/lib/outlined-styles.scss +2 -0
  536. package/textfield/lib/outlined-text-field.d.ts +6 -5
  537. package/textfield/lib/outlined-text-field.js +8 -7
  538. package/textfield/lib/outlined-text-field.js.map +1 -1
  539. package/textfield/lib/shared-styles.css.js +1 -1
  540. package/textfield/lib/shared-styles.css.js.map +1 -1
  541. package/textfield/lib/shared-styles.scss +2 -0
  542. package/textfield/lib/text-field.d.ts +40 -90
  543. package/textfield/lib/text-field.js +194 -272
  544. package/textfield/lib/text-field.js.map +1 -1
  545. package/textfield/outlined-text-field.d.ts +1 -1
  546. package/textfield/outlined-text-field.js +1 -2
  547. package/textfield/outlined-text-field.js.map +1 -1
  548. package/tokens/_index.scss +1 -1
  549. package/tokens/{v0_150 → v0_160}/_index.scss +1 -1
  550. package/tokens/{v0_150 → v0_160}/_md-comp-assist-chip.scss +2 -2
  551. package/tokens/{v0_150 → v0_160}/_md-comp-badge.scss +2 -2
  552. package/tokens/{v0_150 → v0_160}/_md-comp-banner.scss +2 -43
  553. package/tokens/{v0_150 → v0_160}/_md-comp-bottom-app-bar.scss +3 -4
  554. package/tokens/{v0_150 → v0_160}/_md-comp-carousel-item.scss +2 -2
  555. package/tokens/{v0_150 → v0_160}/_md-comp-checkbox.scss +5 -26
  556. package/tokens/{v0_150 → v0_160}/_md-comp-circular-progress-indicator.scss +2 -2
  557. package/tokens/{v0_150 → v0_160}/_md-comp-data-table.scss +2 -6
  558. package/tokens/{v0_150 → v0_160}/_md-comp-date-input-modal.scss +11 -11
  559. package/tokens/{v0_150 → v0_160}/_md-comp-date-picker-docked.scss +24 -24
  560. package/tokens/{v0_150 → v0_160}/_md-comp-date-picker-modal.scss +35 -35
  561. package/tokens/{v0_150 → v0_160}/_md-comp-dialog.scss +2 -25
  562. package/tokens/{v0_150 → v0_160}/_md-comp-divider.scss +2 -2
  563. package/tokens/{v0_150 → v0_160}/_md-comp-elevated-button.scss +2 -2
  564. package/tokens/{v0_150 → v0_160}/_md-comp-elevated-card.scss +2 -2
  565. package/tokens/{v0_150 → v0_160}/_md-comp-extended-fab-branded.scss +2 -2
  566. package/tokens/{v0_150 → v0_160}/_md-comp-extended-fab-primary.scss +2 -2
  567. package/tokens/{v0_150 → v0_160}/_md-comp-extended-fab-secondary.scss +2 -2
  568. package/tokens/{v0_150 → v0_160}/_md-comp-extended-fab-surface.scss +2 -2
  569. package/tokens/{v0_150 → v0_160}/_md-comp-extended-fab-tertiary.scss +2 -4
  570. package/tokens/{v0_150 → v0_160}/_md-comp-fab-branded-large.scss +2 -3
  571. package/tokens/{v0_150 → v0_160}/_md-comp-fab-branded.scss +2 -2
  572. package/tokens/{v0_150 → v0_160}/_md-comp-fab-primary-large.scss +2 -2
  573. package/tokens/{v0_150 → v0_160}/_md-comp-fab-primary-small.scss +2 -2
  574. package/tokens/{v0_150 → v0_160}/_md-comp-fab-primary.scss +2 -2
  575. package/tokens/{v0_150 → v0_160}/_md-comp-fab-secondary-large.scss +2 -2
  576. package/tokens/{v0_150 → v0_160}/_md-comp-fab-secondary-small.scss +2 -2
  577. package/tokens/{v0_150 → v0_160}/_md-comp-fab-secondary.scss +2 -2
  578. package/tokens/{v0_150 → v0_160}/_md-comp-fab-surface-large.scss +2 -2
  579. package/tokens/{v0_150 → v0_160}/_md-comp-fab-surface-small.scss +2 -2
  580. package/tokens/{v0_150 → v0_160}/_md-comp-fab-surface.scss +2 -2
  581. package/tokens/{v0_150 → v0_160}/_md-comp-fab-tertiary-large.scss +2 -2
  582. package/tokens/{v0_150 → v0_160}/_md-comp-fab-tertiary-small.scss +2 -2
  583. package/tokens/{v0_150 → v0_160}/_md-comp-fab-tertiary.scss +2 -2
  584. package/tokens/{v0_150 → v0_160}/_md-comp-filled-autocomplete.scss +2 -3
  585. package/tokens/{v0_150 → v0_160}/_md-comp-filled-button.scss +2 -8
  586. package/tokens/{v0_150 → v0_160}/_md-comp-filled-card.scss +2 -4
  587. package/tokens/{v0_150 → v0_160}/_md-comp-filled-icon-button.scss +2 -2
  588. package/tokens/{v0_150 → v0_160}/_md-comp-filled-menu-button.scss +2 -2
  589. package/tokens/{v0_150 → v0_160}/_md-comp-filled-select.scss +2 -6
  590. package/tokens/{v0_150 → v0_160}/_md-comp-filled-text-field.scss +2 -3
  591. package/tokens/{v0_150 → v0_160}/_md-comp-filled-tonal-button.scss +2 -2
  592. package/tokens/{v0_150 → v0_160}/_md-comp-filled-tonal-icon-button.scss +2 -2
  593. package/tokens/{v0_150 → v0_160}/_md-comp-filter-chip.scss +2 -30
  594. package/tokens/{v0_150 → v0_160}/_md-comp-full-screen-dialog.scss +3 -53
  595. package/tokens/{v0_150 → v0_160}/_md-comp-icon-button.scss +3 -3
  596. package/tokens/{v0_150 → v0_160}/_md-comp-input-chip.scss +2 -52
  597. package/tokens/{v0_150 → v0_160}/_md-comp-linear-progress-indicator.scss +2 -2
  598. package/tokens/{v0_150 → v0_160}/_md-comp-list.scss +3 -12
  599. package/tokens/{v0_150 → v0_160}/_md-comp-menu.scss +2 -4
  600. package/tokens/{v0_150 → v0_160}/_md-comp-navigation-bar.scss +2 -9
  601. package/tokens/{v0_150 → v0_160}/_md-comp-navigation-drawer.scss +2 -8
  602. package/tokens/{v0_150 → v0_160}/_md-comp-navigation-rail.scss +2 -39
  603. package/tokens/{v0_150 → v0_160}/_md-comp-outlined-autocomplete.scss +2 -3
  604. package/tokens/{v0_150 → v0_160}/_md-comp-outlined-button.scss +2 -6
  605. package/tokens/{v0_150 → v0_160}/_md-comp-outlined-card.scss +2 -2
  606. package/tokens/{v0_150 → v0_160}/_md-comp-outlined-icon-button.scss +2 -4
  607. package/tokens/{v0_150 → v0_160}/_md-comp-outlined-menu-button.scss +2 -2
  608. package/tokens/{v0_150 → v0_160}/_md-comp-outlined-segmented-button.scss +2 -2
  609. package/tokens/{v0_150 → v0_160}/_md-comp-outlined-select.scss +2 -6
  610. package/tokens/{v0_150 → v0_160}/_md-comp-outlined-text-field.scss +2 -3
  611. package/tokens/{v0_150 → v0_160}/_md-comp-plain-tooltip.scss +2 -2
  612. package/tokens/{v0_150 → v0_160}/_md-comp-primary-navigation-tab.scss +2 -4
  613. package/tokens/{v0_150 → v0_160}/_md-comp-radio-button.scss +2 -2
  614. package/tokens/{v0_150 → v0_160}/_md-comp-rich-tooltip.scss +2 -2
  615. package/tokens/{v0_150 → v0_160}/_md-comp-scrim.scss +2 -2
  616. package/tokens/{v0_150 → v0_160}/_md-comp-search-bar.scss +2 -2
  617. package/tokens/{v0_150 → v0_160}/_md-comp-search-view.scss +2 -2
  618. package/tokens/{v0_150 → v0_160}/_md-comp-secondary-navigation-tab.scss +2 -4
  619. package/tokens/{v0_150 → v0_160}/_md-comp-sheet-bottom.scss +2 -2
  620. package/tokens/{v0_150 → v0_160}/_md-comp-sheet-floating.scss +2 -2
  621. package/tokens/{v0_150 → v0_160}/_md-comp-sheet-side.scss +13 -11
  622. package/tokens/{v0_150 → v0_160}/_md-comp-slider.scss +2 -4
  623. package/tokens/{v0_150 → v0_160}/_md-comp-snackbar.scss +2 -2
  624. package/tokens/{v0_150 → v0_160}/_md-comp-standard-menu-button.scss +2 -2
  625. package/tokens/{v0_150 → v0_160}/_md-comp-suggestion-chip.scss +2 -2
  626. package/tokens/{v0_150 → v0_160}/_md-comp-switch.scss +2 -11
  627. package/tokens/{v0_150 → v0_160}/_md-comp-text-button.scss +2 -6
  628. package/tokens/{v0_150 → v0_160}/_md-comp-time-input.scss +2 -2
  629. package/tokens/{v0_150 → v0_160}/_md-comp-time-picker.scss +2 -5
  630. package/tokens/{v0_150 → v0_160}/_md-comp-top-app-bar-large.scss +2 -2
  631. package/tokens/{v0_150 → v0_160}/_md-comp-top-app-bar-medium.scss +2 -2
  632. package/tokens/{v0_150 → v0_160}/_md-comp-top-app-bar-small-centered.scss +2 -3
  633. package/tokens/{v0_150 → v0_160}/_md-comp-top-app-bar-small.scss +2 -3
  634. package/tokens/{v0_150 → v0_160}/_md-ref-palette.scss +2 -2
  635. package/tokens/{v0_150 → v0_160}/_md-ref-typeface.scss +2 -2
  636. package/tokens/{v0_150 → v0_160}/_md-sys-color.scss +218 -20
  637. package/tokens/{v0_150 → v0_160}/_md-sys-elevation.scss +4 -13
  638. package/tokens/{v0_150 → v0_160}/_md-sys-motion.scss +2 -2
  639. package/tokens/{v0_150 → v0_160}/_md-sys-shape.scss +2 -2
  640. package/tokens/{v0_150 → v0_160}/_md-sys-state.scss +2 -2
  641. package/tokens/{v0_150 → v0_160}/_md-sys-typescale.scss +2 -3
  642. package/tokens/v0_160/index.test.css.d.ts +1 -0
  643. package/tokens/{v0_150 → v0_160}/index.test.scss +1 -1
  644. package/tokens/v0_160/lib.test.css.d.ts +1 -0
  645. package/tokens/{v0_150 → v0_160}/lib.test.scss +1 -1
  646. package/list/lib/_tokens.scss +0 -80
  647. package/list/lib/divider/_list-divider.scss +0 -46
  648. package/list/lib/divider/list-divider-styles.css.js +0 -9
  649. package/list/lib/divider/list-divider-styles.css.js.map +0 -1
  650. package/list/lib/divider/list-divider-styles.scss +0 -8
  651. package/list/lib/divider/list-divider.d.ts +0 -13
  652. package/list/lib/divider/list-divider.js +0 -32
  653. package/list/lib/divider/list-divider.js.map +0 -1
  654. package/list/list-divider.d.ts +0 -19
  655. package/list/list-divider.js +0 -22
  656. package/list/list-divider.js.map +0 -1
  657. package/menu/lib/_menu-button.scss +0 -14
  658. package/menu/lib/adapter.d.ts +0 -66
  659. package/menu/lib/adapter.js +0 -7
  660. package/menu/lib/adapter.js.map +0 -1
  661. package/menu/lib/constants.d.ts +0 -22
  662. package/menu/lib/constants.js +0 -23
  663. package/menu/lib/constants.js.map +0 -1
  664. package/menu/lib/foundation.d.ts +0 -49
  665. package/menu/lib/foundation.js +0 -123
  666. package/menu/lib/foundation.js.map +0 -1
  667. package/menu/lib/menu-button-styles.css.js +0 -9
  668. package/menu/lib/menu-button-styles.css.js.map +0 -1
  669. package/menu/lib/menu-button-styles.scss +0 -8
  670. package/menu/lib/menu-button.d.ts +0 -27
  671. package/menu/lib/menu-button.js +0 -93
  672. package/menu/lib/menu-button.js.map +0 -1
  673. package/menu/menu-button.d.ts +0 -14
  674. package/menu/menu-button.js +0 -17
  675. package/menu/menu-button.js.map +0 -1
  676. /package/{list/lib/divider/list-divider-styles.css.d.ts → dialog/lib/dialog-styles.css.d.ts} +0 -0
  677. /package/{menu/lib/menu-button-styles.css.d.ts → divider/lib/divider-styles.css.d.ts} +0 -0
  678. /package/{tokens/v0_150/index.test.css.d.ts → list/lib/listitem/list-item-private-styles.css.d.ts} +0 -0
  679. /package/{tokens/v0_150/lib.test.css.d.ts → menu/lib/menuitem/menu-item-private-styles.css.d.ts} +0 -0
  680. /package/tokens/{v0_150 → v0_160}/index.test.css.js +0 -0
  681. /package/tokens/{v0_150 → v0_160}/index.test.css.js.map +0 -0
  682. /package/tokens/{v0_150 → v0_160}/lib.test.css.js +0 -0
  683. /package/tokens/{v0_150 → v0_160}/lib.test.css.js.map +0 -0
@@ -0,0 +1,196 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Given a surface, an anchor, corners, and some options, this surface will
8
+ * calculate the position of a surface to align the two given corners and keep
9
+ * the surface inside the window viewport. It also provides a StyleInfo map that
10
+ * can be applied to the surface to handle visiblility and position.
11
+ */
12
+ export class SurfacePositionController {
13
+ /**
14
+ * @param host The host to connect the controller to.
15
+ * @param getProperties A function that returns the properties for the
16
+ * controller.
17
+ */
18
+ constructor(host, getProperties) {
19
+ this.host = host;
20
+ this.getProperties = getProperties;
21
+ // The current styles to apply to the surface.
22
+ this.surfaceStylesInternal = {
23
+ 'display': 'none',
24
+ };
25
+ // Previous values stored for change detection. Open change detection is
26
+ // calculated separately so initialize it here.
27
+ this.lastValues = { isOpen: false };
28
+ this.host.addController(this);
29
+ }
30
+ /**
31
+ * The StyleInfo map to apply to the surface via Lit's stylemap
32
+ */
33
+ get surfaceStyles() {
34
+ return this.surfaceStylesInternal;
35
+ }
36
+ /**
37
+ * Calculates the surface's new position required so that the surface's
38
+ * `surfaceCorner` aligns to the anchor's `anchorCorner` while keeping the
39
+ * surface inside the window viewport. This positioning also respects RTL by
40
+ * checking `getComputedStyle()` on the surface element.
41
+ */
42
+ async position() {
43
+ const { surfaceEl, anchorEl, anchorCorner: anchorCornerRaw, surfaceCorner: surfaceCornerRaw, isTopLayer: topLayerRaw, xOffset, yOffset, } = this.getProperties();
44
+ const anchorCorner = anchorCornerRaw.toUpperCase().trim();
45
+ const surfaceCorner = surfaceCornerRaw.toUpperCase().trim();
46
+ if (!surfaceEl || !anchorEl) {
47
+ return;
48
+ }
49
+ // Paint the surface transparently so that we can get the position and the
50
+ // rect info of the surface.
51
+ this.surfaceStylesInternal = {
52
+ 'display': 'block',
53
+ 'opacity': '0',
54
+ };
55
+ // Wait for it to be visible.
56
+ this.host.requestUpdate();
57
+ await this.host.updateComplete;
58
+ const surfaceRect = surfaceEl.getBoundingClientRect();
59
+ const anchorRect = anchorEl.getBoundingClientRect();
60
+ const [surfaceBlock, surfaceInline] = surfaceCorner.split('_');
61
+ const [anchorBlock, anchorInline] = anchorCorner.split('_');
62
+ // We use number booleans to multiply values rather than `if` / ternary
63
+ // statements because it _heavily_ cuts down on nesting and readability
64
+ const isTopLayer = topLayerRaw ? 1 : 0;
65
+ // LTR depends on the direction of the SURFACE not the anchor.
66
+ const isLTR = getComputedStyle(surfaceEl).direction === 'ltr' ? 1 : 0;
67
+ const isRTL = isLTR ? 0 : 1;
68
+ const isSurfaceInlineStart = surfaceInline === 'START' ? 1 : 0;
69
+ const isSurfaceInlineEnd = surfaceInline === 'END' ? 1 : 0;
70
+ const isSurfaceBlockStart = surfaceBlock === 'START' ? 1 : 0;
71
+ const isSurfaceBlockEnd = surfaceBlock === 'END' ? 1 : 0;
72
+ const isOneInlineEnd = anchorInline !== surfaceInline ? 1 : 0;
73
+ const isOneBlockEnd = anchorBlock !== surfaceBlock ? 1 : 0;
74
+ /*
75
+ * A diagram that helps describe some of the variables used in the following
76
+ * calculations.
77
+ *
78
+ * ┌───── inline/blockTopLayerOffset
79
+ * │ │
80
+ * │ ┌─▼───┐ Window
81
+ * │ ┌┼─────┴────────────────────────┐
82
+ * │ ││ │
83
+ * └──► ││ ┌──inline/blockAnchorOffset │
84
+ * ││ │ │ │
85
+ * └┤ │ ┌──▼───┐ │
86
+ * │ │ ┌┼──────┤ │
87
+ * │ └─►│Anchor│ │
88
+ * │ └┴──────┘ │
89
+ * │ │
90
+ * │ ┌────────────────────────┼────┐
91
+ * │ │ Surface │ │
92
+ * │ │ │ │
93
+ * │ │ │ │
94
+ * │ │ │ │
95
+ * │ │ │ │
96
+ * │ │ │ │
97
+ * └─────┼────────────────────────┘ ├┐
98
+ * │ inline/blockOOBCorrection ││
99
+ * │ │ ││
100
+ * │ ├──►││
101
+ * │ │ ││
102
+ * └────────────────────────┐▼───┼┘
103
+ * └────┘
104
+ */
105
+ // Whether or not to apply the width of the anchor
106
+ const inlineAnchorOffset = isOneInlineEnd * anchorRect.width + xOffset;
107
+ // The inline position of the anchor relative to window in LTR
108
+ const inlineTopLayerOffsetLTR = isSurfaceInlineStart * anchorRect.left +
109
+ isSurfaceInlineEnd * (window.innerWidth - anchorRect.right);
110
+ // The inline position of the anchor relative to window in RTL
111
+ const inlineTopLayerOffsetRTL = isSurfaceInlineStart * (window.innerWidth - anchorRect.right) +
112
+ isSurfaceInlineEnd * anchorRect.left;
113
+ // The inline position of the anchor relative to window
114
+ const inlineTopLayerOffset = isLTR * inlineTopLayerOffsetLTR + isRTL * inlineTopLayerOffsetRTL;
115
+ // If the surface's inline would be out of bounds of the window, move it
116
+ // back in
117
+ const inlineOutOfBoundsCorrection = Math.min(0, window.innerWidth - inlineTopLayerOffset - inlineAnchorOffset -
118
+ surfaceRect.width);
119
+ // The inline logical value of the surface
120
+ const inline = isTopLayer * inlineTopLayerOffset + inlineAnchorOffset +
121
+ inlineOutOfBoundsCorrection;
122
+ // Whether or not to apply the height of the anchor
123
+ const blockAnchorOffset = isOneBlockEnd * anchorRect.height + yOffset;
124
+ // The absolute block position of the anchor relative to window
125
+ const blockTopLayerOffset = isSurfaceBlockStart * anchorRect.top +
126
+ isSurfaceBlockEnd * (window.innerHeight - anchorRect.bottom);
127
+ // If the surface's block would be out of bounds of the window, move it back
128
+ // in
129
+ const blockOutOfBoundsCorrection = Math.min(0, window.innerHeight - blockTopLayerOffset - blockAnchorOffset -
130
+ surfaceRect.height);
131
+ // The block logical value of the surface
132
+ const block = isTopLayer * blockTopLayerOffset + blockAnchorOffset +
133
+ blockOutOfBoundsCorrection;
134
+ const surfaceBlockProperty = surfaceBlock === 'START' ? 'inset-block-start' : 'inset-block-end';
135
+ const surfaceInlineProperty = surfaceInline === 'START' ? 'inset-inline-start' : 'inset-inline-end';
136
+ this.surfaceStylesInternal = {
137
+ 'display': 'block',
138
+ 'opacity': '1',
139
+ [surfaceBlockProperty]: `${block}px`,
140
+ [surfaceInlineProperty]: `${inline}px`,
141
+ };
142
+ this.host.requestUpdate();
143
+ }
144
+ hostUpdate() {
145
+ this.onUpdate();
146
+ }
147
+ hostUpdated() {
148
+ this.onUpdate();
149
+ }
150
+ /**
151
+ * Checks whether the properties passed into the controller have changed since
152
+ * the last positioning. If so, it will reposition if the surface is open or
153
+ * close it if the surface should close.
154
+ */
155
+ async onUpdate() {
156
+ const props = this.getProperties();
157
+ let hasChanged = false;
158
+ for (const [key, value] of Object.entries(props)) {
159
+ // tslint:disable-next-line
160
+ hasChanged = hasChanged || (value !== this.lastValues[key]);
161
+ if (hasChanged)
162
+ break;
163
+ }
164
+ const openChanged = this.lastValues.isOpen !== props.isOpen;
165
+ const hasAnchor = !!props.anchorEl;
166
+ const hasSurface = !!props.surfaceEl;
167
+ if (hasChanged && hasAnchor && hasSurface) {
168
+ // Only update isOpen, because if it's closed, we do not want to waste
169
+ // time on a useless reposition calculation. So save the other "dirty"
170
+ // values until next time it opens.
171
+ this.lastValues.isOpen = props.isOpen;
172
+ if (props.isOpen) {
173
+ // We are going to do a reposition, so save the prop values for future
174
+ // dirty checking.
175
+ this.lastValues = props;
176
+ await this.position();
177
+ props.onOpen();
178
+ }
179
+ else if (openChanged) {
180
+ await props.beforeClose();
181
+ this.close();
182
+ props.onClose();
183
+ }
184
+ }
185
+ }
186
+ /**
187
+ * Hides the surface.
188
+ */
189
+ close() {
190
+ this.surfaceStylesInternal = {
191
+ 'display': 'none',
192
+ };
193
+ this.host.requestUpdate();
194
+ }
195
+ }
196
+ //# sourceMappingURL=surfacePositionController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"surfacePositionController.js","sourceRoot":"","sources":["surfacePositionController.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA4EH;;;;;GAKG;AACH,MAAM,OAAO,yBAAyB;IAUpC;;;;OAIG;IACH,YACqB,IAA4B,EAC5B,aAAwD;QADxD,SAAI,GAAJ,IAAI,CAAwB;QAC5B,kBAAa,GAAb,aAAa,CAA2C;QAhB7E,8CAA8C;QACtC,0BAAqB,GAAc;YACzC,SAAS,EAAE,MAAM;SAClB,CAAC;QACF,wEAAwE;QACxE,+CAA+C;QACvC,eAAU,GAAwC,EAAC,MAAM,EAAE,KAAK,EACjC,CAAC;QAWtC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,EACJ,SAAS,EACT,QAAQ,EACR,YAAY,EAAE,eAAe,EAC7B,aAAa,EAAE,gBAAgB,EAC/B,UAAU,EAAE,WAAW,EACvB,OAAO,EACP,OAAO,GACR,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACzB,MAAM,YAAY,GAAG,eAAe,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;QAC1D,MAAM,aAAa,GAAG,gBAAgB,CAAC,WAAW,EAAE,CAA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D,2BAA2B;YAC3B,UAAU,GAAG,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 * A corner of a box in the standard logical property style of <block>_<inline>\n */\nexport type Corner = 'END_START'|'END_END'|'START_START'|'START_END';\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: HTMLElement|null;\n /**\n * The HTMLElement reference of the anchor to align to.\n */\n anchorEl: HTMLElement|null;\n /**\n * Whether or not the calculation should be relative to the top layer rather\n * than relative to the parent of the anchor.\n *\n * Examples for `isTopLayer:true`:\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 isTopLayer: boolean;\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 * 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 isTopLayer: topLayerRaw,\n xOffset,\n yOffset,\n } = this.getProperties();\n const anchorCorner = anchorCornerRaw.toUpperCase().trim();\n const surfaceCorner = surfaceCornerRaw.toUpperCase().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.getBoundingClientRect();\n const anchorRect = 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\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 isTopLayer = topLayerRaw ? 1 : 0;\n // LTR depends on the direction of the SURFACE not the anchor.\n const isLTR = getComputedStyle(surfaceEl).direction === 'ltr' ? 1 : 0;\n const isRTL = isLTR ? 0 : 1;\n const isSurfaceInlineStart = surfaceInline === 'START' ? 1 : 0;\n const isSurfaceInlineEnd = surfaceInline === 'END' ? 1 : 0;\n const isSurfaceBlockStart = surfaceBlock === 'START' ? 1 : 0;\n const isSurfaceBlockEnd = surfaceBlock === 'END' ? 1 : 0;\n const isOneInlineEnd = anchorInline !== surfaceInline ? 1 : 0;\n const isOneBlockEnd = anchorBlock !== surfaceBlock ? 1 : 0;\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 // 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 // If the surface's inline would be out of bounds of the window, move it\n // back in\n const inlineOutOfBoundsCorrection = Math.min(\n 0,\n window.innerWidth - inlineTopLayerOffset - inlineAnchorOffset -\n surfaceRect.width);\n\n // The inline logical value of the surface\n const inline = isTopLayer * inlineTopLayerOffset + inlineAnchorOffset +\n inlineOutOfBoundsCorrection;\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.min(\n 0,\n window.innerHeight - blockTopLayerOffset - blockAnchorOffset -\n surfaceRect.height);\n\n // The block logical value of the surface\n const block = isTopLayer * blockTopLayerOffset + blockAnchorOffset +\n blockOutOfBoundsCorrection;\n\n const surfaceBlockProperty =\n surfaceBlock === 'START' ? 'inset-block-start' : 'inset-block-end';\n const surfaceInlineProperty =\n surfaceInline === 'START' ? 'inset-inline-start' : 'inset-inline-end';\n\n this.surfaceStylesInternal = {\n 'display': 'block',\n 'opacity': '1',\n [surfaceBlockProperty]: `${block}px`,\n [surfaceInlineProperty]: `${inline}px`,\n };\n\n this.host.requestUpdate();\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"]}
@@ -0,0 +1,144 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { MenuItem } from './shared.js';
7
+ /**
8
+ * The options that are passed to the typeahead controller.
9
+ */
10
+ export interface TypeaheadControllerProperties {
11
+ /**
12
+ * A function that returns an array of menu items to be searched.
13
+ * @return An array of menu items to be searched by typing.
14
+ */
15
+ getItems: () => MenuItem[];
16
+ /**
17
+ * The maximum time between each keystroke to keep the current type buffer
18
+ * alive.
19
+ */
20
+ typeaheadBufferTime: number;
21
+ }
22
+ /**
23
+ * Data structure tuple that helps with indexing.
24
+ *
25
+ * [index, item, normalized header text]
26
+ */
27
+ type TypeaheadRecord = [number, MenuItem, string];
28
+ /**
29
+ * This controller listens to `keydown` events and searches the header text of
30
+ * an array of `MenuItem`s with the corresponding entered keys within the buffer
31
+ * time and activates the item.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * const typeaheadController = new TypeaheadController(() => ({
36
+ * typeaheadBufferTime: 50,
37
+ * getItems: () => Array.from(document.querySelectorAll('md-menu-item'))
38
+ * }));
39
+ * html`
40
+ * <div
41
+ * @keydown=${typeaheadController.onKeydown}
42
+ * tabindex="0"
43
+ * class="activeItemText">
44
+ * <!-- focusable element that will receive keydown events -->
45
+ * Apple
46
+ * </div>
47
+ * <div>
48
+ * <md-menu-item active header="Apple"></md-menu-item>
49
+ * <md-menu-item header="Apricot"></md-menu-item>
50
+ * <md-menu-item header="Banana"></md-menu-item>
51
+ * <md-menu-item header="Olive"></md-menu-item>
52
+ * <md-menu-item header="Orange"></md-menu-item>
53
+ * </div>
54
+ * `;
55
+ * ```
56
+ */
57
+ export declare class TypeaheadController {
58
+ protected getProperties: () => TypeaheadControllerProperties;
59
+ /**
60
+ * Array of tuples that helps with indexing.
61
+ */
62
+ protected typeaheadRecords: TypeaheadRecord[];
63
+ /**
64
+ * Currently-typed text since last buffer timeout
65
+ */
66
+ protected typaheadBuffer: string;
67
+ /**
68
+ * The timeout id from the current buffer's setTimeout
69
+ */
70
+ protected cancelTypeaheadTimeout: number;
71
+ /**
72
+ * If we are currently "typing"
73
+ */
74
+ protected isTypingAhead: boolean;
75
+ /**
76
+ * The record of the last active item.
77
+ */
78
+ protected lastActiveRecord: TypeaheadRecord | null;
79
+ /**
80
+ * @param getProperties A function that returns the options of the typeahead
81
+ * controller:
82
+ *
83
+ * {
84
+ * getItems: A function that returns an array of menu items to be searched.
85
+ * typeaheadBufferTime: The maximum time between each keystroke to keep the
86
+ * current type buffer alive.
87
+ * }
88
+ */
89
+ constructor(getProperties: () => TypeaheadControllerProperties);
90
+ protected get items(): MenuItem[];
91
+ /**
92
+ * Apply this listener to the element that will receive `keydown` events that
93
+ * should trigger this controller.
94
+ *
95
+ * @param e The native browser `KeyboardEvent` from the `keydown` event.
96
+ */
97
+ readonly onKeydown: (e: KeyboardEvent) => void;
98
+ /**
99
+ * Sets up typingahead
100
+ */
101
+ protected beginTypeahead(e: KeyboardEvent): void;
102
+ /**
103
+ * Performs the typeahead. Based on the normalized items and the current text
104
+ * buffer, finds the _next_ item with matching text and activates it.
105
+ *
106
+ * @example
107
+ *
108
+ * items: Apple, Banana, Olive, Orange, Cucumber
109
+ * buffer: ''
110
+ * user types: o
111
+ *
112
+ * activates Olive
113
+ *
114
+ * @example
115
+ *
116
+ * items: Apple, Banana, Olive (active), Orange, Cucumber
117
+ * buffer: 'o'
118
+ * user types: l
119
+ *
120
+ * activates Olive
121
+ *
122
+ * @example
123
+ *
124
+ * items: Apple, Banana, Olive (active), Orange, Cucumber
125
+ * buffer: ''
126
+ * user types: o
127
+ *
128
+ * activates Orange
129
+ *
130
+ * @example
131
+ *
132
+ * items: Apple, Banana, Olive, Orange (active), Cucumber
133
+ * buffer: ''
134
+ * user types: o
135
+ *
136
+ * activates Olive
137
+ */
138
+ protected typeahead(e: KeyboardEvent): void;
139
+ /**
140
+ * Ends the current typeahead and clears the buffer.
141
+ */
142
+ protected endTypeahead: () => void;
143
+ }
144
+ export {};
@@ -0,0 +1,242 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ // Indicies to access the TypeaheadRecord tuple
7
+ const TYPEAHEAD_INDEX = 0;
8
+ const TYPEAHEAD_ITEM = 1;
9
+ const TYPEAHEAD_TEXT = 2;
10
+ /**
11
+ * This controller listens to `keydown` events and searches the header text of
12
+ * an array of `MenuItem`s with the corresponding entered keys within the buffer
13
+ * time and activates the item.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const typeaheadController = new TypeaheadController(() => ({
18
+ * typeaheadBufferTime: 50,
19
+ * getItems: () => Array.from(document.querySelectorAll('md-menu-item'))
20
+ * }));
21
+ * html`
22
+ * <div
23
+ * @keydown=${typeaheadController.onKeydown}
24
+ * tabindex="0"
25
+ * class="activeItemText">
26
+ * <!-- focusable element that will receive keydown events -->
27
+ * Apple
28
+ * </div>
29
+ * <div>
30
+ * <md-menu-item active header="Apple"></md-menu-item>
31
+ * <md-menu-item header="Apricot"></md-menu-item>
32
+ * <md-menu-item header="Banana"></md-menu-item>
33
+ * <md-menu-item header="Olive"></md-menu-item>
34
+ * <md-menu-item header="Orange"></md-menu-item>
35
+ * </div>
36
+ * `;
37
+ * ```
38
+ */
39
+ export class TypeaheadController {
40
+ /**
41
+ * @param getProperties A function that returns the options of the typeahead
42
+ * controller:
43
+ *
44
+ * {
45
+ * getItems: A function that returns an array of menu items to be searched.
46
+ * typeaheadBufferTime: The maximum time between each keystroke to keep the
47
+ * current type buffer alive.
48
+ * }
49
+ */
50
+ constructor(getProperties) {
51
+ this.getProperties = getProperties;
52
+ /**
53
+ * Array of tuples that helps with indexing.
54
+ */
55
+ this.typeaheadRecords = [];
56
+ /**
57
+ * Currently-typed text since last buffer timeout
58
+ */
59
+ this.typaheadBuffer = '';
60
+ /**
61
+ * The timeout id from the current buffer's setTimeout
62
+ */
63
+ this.cancelTypeaheadTimeout = 0;
64
+ /**
65
+ * If we are currently "typing"
66
+ */
67
+ this.isTypingAhead = false;
68
+ /**
69
+ * The record of the last active item.
70
+ */
71
+ this.lastActiveRecord = null;
72
+ /**
73
+ * Apply this listener to the element that will receive `keydown` events that
74
+ * should trigger this controller.
75
+ *
76
+ * @param e The native browser `KeyboardEvent` from the `keydown` event.
77
+ */
78
+ this.onKeydown = (e) => {
79
+ if (this.isTypingAhead) {
80
+ this.typeahead(e);
81
+ }
82
+ else {
83
+ this.beginTypeahead(e);
84
+ }
85
+ };
86
+ /**
87
+ * Ends the current typeahead and clears the buffer.
88
+ */
89
+ this.endTypeahead = () => {
90
+ this.isTypingAhead = false;
91
+ this.typaheadBuffer = '';
92
+ this.typeaheadRecords = [];
93
+ };
94
+ }
95
+ get items() {
96
+ return this.getProperties().getItems();
97
+ }
98
+ /**
99
+ * Sets up typingahead
100
+ */
101
+ beginTypeahead(e) {
102
+ // We don't want to typeahead if the _beginning_ of the typeahead is a menu
103
+ // navigation, or a selection. We will handle "Space" only if it's in the
104
+ // middle of a typeahead
105
+ if (e.code === 'Space' || e.code === 'Enter' ||
106
+ e.code.startsWith('Arrow') || e.code === 'Escape') {
107
+ if (this.lastActiveRecord) {
108
+ this.lastActiveRecord[TYPEAHEAD_ITEM].active = false;
109
+ }
110
+ return;
111
+ }
112
+ this.isTypingAhead = true;
113
+ // Generates the record array data structure which is the index, the element
114
+ // and a normalized header.
115
+ this.typeaheadRecords = this.items.map((el, index) => [index, el, el.headline.trim().toLowerCase()]);
116
+ this.lastActiveRecord =
117
+ this.typeaheadRecords.find(record => record[TYPEAHEAD_ITEM].active) ??
118
+ null;
119
+ if (this.lastActiveRecord) {
120
+ this.lastActiveRecord[TYPEAHEAD_ITEM].active = false;
121
+ }
122
+ this.typeahead(e);
123
+ }
124
+ /**
125
+ * Performs the typeahead. Based on the normalized items and the current text
126
+ * buffer, finds the _next_ item with matching text and activates it.
127
+ *
128
+ * @example
129
+ *
130
+ * items: Apple, Banana, Olive, Orange, Cucumber
131
+ * buffer: ''
132
+ * user types: o
133
+ *
134
+ * activates Olive
135
+ *
136
+ * @example
137
+ *
138
+ * items: Apple, Banana, Olive (active), Orange, Cucumber
139
+ * buffer: 'o'
140
+ * user types: l
141
+ *
142
+ * activates Olive
143
+ *
144
+ * @example
145
+ *
146
+ * items: Apple, Banana, Olive (active), Orange, Cucumber
147
+ * buffer: ''
148
+ * user types: o
149
+ *
150
+ * activates Orange
151
+ *
152
+ * @example
153
+ *
154
+ * items: Apple, Banana, Olive, Orange (active), Cucumber
155
+ * buffer: ''
156
+ * user types: o
157
+ *
158
+ * activates Olive
159
+ */
160
+ typeahead(e) {
161
+ clearTimeout(this.cancelTypeaheadTimeout);
162
+ // Stop typingahead if one of the navigation or selection keys (except for
163
+ // Space) are pressed
164
+ if (e.code === 'Enter' || e.code.startsWith('Arrow') ||
165
+ e.code === 'Escape') {
166
+ this.endTypeahead();
167
+ if (this.lastActiveRecord) {
168
+ this.lastActiveRecord[TYPEAHEAD_ITEM].active = false;
169
+ }
170
+ return;
171
+ }
172
+ // If Space is pressed, prevent it from selecting and closing the menu
173
+ if (e.code === 'Space') {
174
+ e.stopPropagation();
175
+ }
176
+ // Start up a new keystroke buffer timeout
177
+ this.cancelTypeaheadTimeout =
178
+ setTimeout(this.endTypeahead, this.getProperties().typeaheadBufferTime);
179
+ this.typaheadBuffer += e.key.toLowerCase();
180
+ const lastActiveIndex = this.lastActiveRecord ? this.lastActiveRecord[TYPEAHEAD_INDEX] : -1;
181
+ const numRecords = this.typeaheadRecords.length;
182
+ /**
183
+ * Sorting function that will resort the items starting with the given index
184
+ *
185
+ * @example
186
+ *
187
+ * this.typeaheadRecords =
188
+ * 0: [0, <reference>, 'apple']
189
+ * 1: [1, <reference>, 'apricot']
190
+ * 2: [2, <reference>, 'banana']
191
+ * 3: [3, <reference>, 'olive'] <-- lastActiveIndex
192
+ * 4: [4, <reference>, 'orange']
193
+ * 5: [5, <reference>, 'strawberry']
194
+ *
195
+ * this.typeaheadRecords.sort((a,b) => rebaseIndexOnActive(a)
196
+ * - rebaseIndexOnActive(b)) ===
197
+ * 0: [3, <reference>, 'olive'] <-- lastActiveIndex
198
+ * 1: [4, <reference>, 'orange']
199
+ * 2: [5, <reference>, 'strawberry']
200
+ * 3: [0, <reference>, 'apple']
201
+ * 4: [1, <reference>, 'apricot']
202
+ * 5: [2, <reference>, 'banana']
203
+ */
204
+ const rebaseIndexOnActive = (record) => {
205
+ return (record[TYPEAHEAD_INDEX] + numRecords - lastActiveIndex) %
206
+ numRecords;
207
+ };
208
+ // records filtered and sorted / rebased around the last active index
209
+ const matchingRecords = this.typeaheadRecords
210
+ .filter(record => !record[TYPEAHEAD_ITEM].disabled &&
211
+ record[TYPEAHEAD_TEXT].startsWith(this.typaheadBuffer))
212
+ .sort((a, b) => rebaseIndexOnActive(a) - rebaseIndexOnActive(b));
213
+ // Just leave if there's nothing that matches. Native select will just
214
+ // choose the first thing that starts with the next letter in the alphabet
215
+ // but that's out of scope and hard to localize
216
+ if (matchingRecords.length === 0) {
217
+ clearTimeout(this.cancelTypeaheadTimeout);
218
+ if (this.lastActiveRecord) {
219
+ this.lastActiveRecord[TYPEAHEAD_ITEM].active = false;
220
+ }
221
+ this.endTypeahead();
222
+ return;
223
+ }
224
+ const isNewQuery = this.typaheadBuffer.length === 1;
225
+ let nextRecord;
226
+ // This is likely the case that someone is trying to "tab" through different
227
+ // entries that start with the same letter
228
+ if (this.lastActiveRecord === matchingRecords[0] && isNewQuery) {
229
+ nextRecord = matchingRecords[1] ?? matchingRecords[0];
230
+ }
231
+ else {
232
+ nextRecord = matchingRecords[0];
233
+ }
234
+ if (this.lastActiveRecord) {
235
+ this.lastActiveRecord[TYPEAHEAD_ITEM].active = false;
236
+ }
237
+ this.lastActiveRecord = nextRecord;
238
+ nextRecord[TYPEAHEAD_ITEM].active = true;
239
+ return;
240
+ }
241
+ }
242
+ //# sourceMappingURL=typeaheadController.js.map
@@ -0,0 +1 @@
1
+ {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CAA+C;QAC/C,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE;YAChC,YAAY,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;YAC1C,IAAI,IAAI,CAAC,gBAAgB,EAAE;gBACzB,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC;aACtD;YACD,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,OAAO;SACR;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,CAAC;QACpD,IAAI,UAA2B,CAAC;QAEhC,4EAA4E;QAC5E,0CAA0C;QAC1C,IAAI,IAAI,CAAC,gBAAgB,KAAK,eAAe,CAAC,CAAC,CAAC,IAAI,UAAU,EAAE;YAC9D,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC;SACvD;aAAM;YACL,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;SACjC;QAED,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACzB,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC;SACtD;QAED,IAAI,CAAC,gBAAgB,GAAG,UAAU,CAAC;QACnC,UAAU,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC;QACzC,OAAO;IACT,CAAC;CAUF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {MenuItem} from './shared.js';\n\n/**\n * The options that are passed to the typeahead controller.\n */\nexport interface TypeaheadControllerProperties {\n /**\n * A function that returns an array of menu items to be searched.\n * @return An array of menu items to be searched by typing.\n */\n getItems: () => MenuItem[];\n /**\n * The maximum time between each keystroke to keep the current type buffer\n * alive.\n */\n typeaheadBufferTime: number;\n}\n\n/**\n * Data structure tuple that helps with indexing.\n *\n * [index, item, normalized header text]\n */\ntype TypeaheadRecord = [number, MenuItem, string];\n// Indicies to access the TypeaheadRecord tuple\nconst TYPEAHEAD_INDEX = 0;\nconst TYPEAHEAD_ITEM = 1;\nconst TYPEAHEAD_TEXT = 2;\n\n/**\n * This controller listens to `keydown` events and searches the header text of\n * an array of `MenuItem`s with the corresponding entered keys within the buffer\n * time and activates the item.\n *\n * @example\n * ```ts\n * const typeaheadController = new TypeaheadController(() => ({\n * typeaheadBufferTime: 50,\n * getItems: () => Array.from(document.querySelectorAll('md-menu-item'))\n * }));\n * html`\n * <div\n * @keydown=${typeaheadController.onKeydown}\n * tabindex=\"0\"\n * class=\"activeItemText\">\n * <!-- focusable element that will receive keydown events -->\n * Apple\n * </div>\n * <div>\n * <md-menu-item active header=\"Apple\"></md-menu-item>\n * <md-menu-item header=\"Apricot\"></md-menu-item>\n * <md-menu-item header=\"Banana\"></md-menu-item>\n * <md-menu-item header=\"Olive\"></md-menu-item>\n * <md-menu-item header=\"Orange\"></md-menu-item>\n * </div>\n * `;\n * ```\n */\nexport class TypeaheadController {\n /**\n * Array of tuples that helps with indexing.\n */\n protected typeaheadRecords: TypeaheadRecord[] = [];\n /**\n * Currently-typed text since last buffer timeout\n */\n protected typaheadBuffer = '';\n /**\n * The timeout id from the current buffer's setTimeout\n */\n protected cancelTypeaheadTimeout = 0;\n /**\n * If we are currently \"typing\"\n */\n protected isTypingAhead = false;\n /**\n * The record of the last active item.\n */\n protected lastActiveRecord: TypeaheadRecord|null = null;\n\n /**\n * @param getProperties A function that returns the options of the typeahead\n * controller:\n *\n * {\n * getItems: A function that returns an array of menu items to be searched.\n * typeaheadBufferTime: The maximum time between each keystroke to keep the\n * current type buffer alive.\n * }\n */\n constructor(\n protected getProperties: () => TypeaheadControllerProperties,\n ) {}\n\n protected get items() {\n return this.getProperties().getItems();\n }\n\n /**\n * Apply this listener to the element that will receive `keydown` events that\n * should trigger this controller.\n *\n * @param e The native browser `KeyboardEvent` from the `keydown` event.\n */\n readonly onKeydown = (e: KeyboardEvent) => {\n if (this.isTypingAhead) {\n this.typeahead(e);\n } else {\n this.beginTypeahead(e);\n }\n };\n\n /**\n * Sets up typingahead\n */\n protected beginTypeahead(e: KeyboardEvent) {\n // We don't want to typeahead if the _beginning_ of the typeahead is a menu\n // navigation, or a selection. We will handle \"Space\" only if it's in the\n // middle of a typeahead\n if (e.code === 'Space' || e.code === 'Enter' ||\n e.code.startsWith('Arrow') || e.code === 'Escape') {\n if (this.lastActiveRecord) {\n this.lastActiveRecord[TYPEAHEAD_ITEM].active = false;\n }\n return;\n }\n\n this.isTypingAhead = true;\n // Generates the record array data structure which is the index, the element\n // and a normalized header.\n this.typeaheadRecords = this.items.map(\n (el, index) => [index, el, el.headline.trim().toLowerCase()]);\n this.lastActiveRecord =\n this.typeaheadRecords.find(record => record[TYPEAHEAD_ITEM].active) ??\n null;\n if (this.lastActiveRecord) {\n this.lastActiveRecord[TYPEAHEAD_ITEM].active = false;\n }\n this.typeahead(e);\n }\n\n /**\n * Performs the typeahead. Based on the normalized items and the current text\n * buffer, finds the _next_ item with matching text and activates it.\n *\n * @example\n *\n * items: Apple, Banana, Olive, Orange, Cucumber\n * buffer: ''\n * user types: o\n *\n * activates Olive\n *\n * @example\n *\n * items: Apple, Banana, Olive (active), Orange, Cucumber\n * buffer: 'o'\n * user types: l\n *\n * activates Olive\n *\n * @example\n *\n * items: Apple, Banana, Olive (active), Orange, Cucumber\n * buffer: ''\n * user types: o\n *\n * activates Orange\n *\n * @example\n *\n * items: Apple, Banana, Olive, Orange (active), Cucumber\n * buffer: ''\n * user types: o\n *\n * activates Olive\n */\n protected typeahead(e: KeyboardEvent) {\n clearTimeout(this.cancelTypeaheadTimeout);\n // Stop typingahead if one of the navigation or selection keys (except for\n // Space) are pressed\n if (e.code === 'Enter' || e.code.startsWith('Arrow') ||\n e.code === 'Escape') {\n this.endTypeahead();\n if (this.lastActiveRecord) {\n this.lastActiveRecord[TYPEAHEAD_ITEM].active = false;\n }\n return;\n }\n\n // If Space is pressed, prevent it from selecting and closing the menu\n if (e.code === 'Space') {\n e.stopPropagation();\n }\n\n // Start up a new keystroke buffer timeout\n this.cancelTypeaheadTimeout =\n setTimeout(this.endTypeahead, this.getProperties().typeaheadBufferTime);\n\n this.typaheadBuffer += e.key.toLowerCase();\n\n const lastActiveIndex =\n this.lastActiveRecord ? this.lastActiveRecord[TYPEAHEAD_INDEX] : -1;\n const numRecords = this.typeaheadRecords.length;\n\n /**\n * Sorting function that will resort the items starting with the given index\n *\n * @example\n * \n * this.typeaheadRecords = \n * 0: [0, <reference>, 'apple']\n * 1: [1, <reference>, 'apricot']\n * 2: [2, <reference>, 'banana']\n * 3: [3, <reference>, 'olive'] <-- lastActiveIndex\n * 4: [4, <reference>, 'orange']\n * 5: [5, <reference>, 'strawberry']\n * \n * this.typeaheadRecords.sort((a,b) => rebaseIndexOnActive(a)\n * - rebaseIndexOnActive(b)) ===\n * 0: [3, <reference>, 'olive'] <-- lastActiveIndex\n * 1: [4, <reference>, 'orange']\n * 2: [5, <reference>, 'strawberry']\n * 3: [0, <reference>, 'apple']\n * 4: [1, <reference>, 'apricot']\n * 5: [2, <reference>, 'banana']\n */\n const rebaseIndexOnActive = (record: TypeaheadRecord) => {\n return (record[TYPEAHEAD_INDEX] + numRecords - lastActiveIndex) %\n numRecords;\n };\n\n // records filtered and sorted / rebased around the last active index\n const matchingRecords =\n this.typeaheadRecords\n .filter(\n record => !record[TYPEAHEAD_ITEM].disabled &&\n record[TYPEAHEAD_TEXT].startsWith(this.typaheadBuffer))\n .sort(\n (a, b) => rebaseIndexOnActive(a) - rebaseIndexOnActive(b));\n\n // Just leave if there's nothing that matches. Native select will just\n // choose the first thing that starts with the next letter in the alphabet\n // but that's out of scope and hard to localize\n if (matchingRecords.length === 0) {\n clearTimeout(this.cancelTypeaheadTimeout);\n if (this.lastActiveRecord) {\n this.lastActiveRecord[TYPEAHEAD_ITEM].active = false;\n }\n this.endTypeahead();\n return;\n }\n\n const isNewQuery = this.typaheadBuffer.length === 1;\n let nextRecord: TypeaheadRecord;\n\n // This is likely the case that someone is trying to \"tab\" through different\n // entries that start with the same letter\n if (this.lastActiveRecord === matchingRecords[0] && isNewQuery) {\n nextRecord = matchingRecords[1] ?? matchingRecords[0];\n } else {\n nextRecord = matchingRecords[0];\n }\n\n if (this.lastActiveRecord) {\n this.lastActiveRecord[TYPEAHEAD_ITEM].active = false;\n }\n\n this.lastActiveRecord = nextRecord;\n nextRecord[TYPEAHEAD_ITEM].active = true;\n return;\n }\n\n /**\n * Ends the current typeahead and clears the buffer.\n */\n protected endTypeahead = () => {\n this.isTypingAhead = false;\n this.typaheadBuffer = '';\n this.typeaheadRecords = [];\n };\n}\n"]}