@omicronenergy/oscd-ui 0.0.6 → 0.0.7

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 (464) hide show
  1. package/app-bar/OscdAppBar.d.ts +3 -3
  2. package/app-bar/OscdAppBar.js +12 -10
  3. package/app-bar/OscdAppBar.js.map +1 -1
  4. package/button/OscdFilledButton.js +2 -2
  5. package/button/OscdFilledButton.js.map +1 -1
  6. package/button/OscdOutlinedButton.js +1 -1
  7. package/button/OscdOutlinedButton.js.map +1 -1
  8. package/button/OscdTextButton.js +1 -1
  9. package/button/OscdTextButton.js.map +1 -1
  10. package/button/oscd-outlined-button.d.ts +1 -1
  11. package/button/oscd-outlined-button.js.map +1 -1
  12. package/dialog/OscdDialog.js +1 -1
  13. package/dialog/OscdDialog.js.map +1 -1
  14. package/divider/OscdDivider.js +1 -1
  15. package/divider/OscdDivider.js.map +1 -1
  16. package/elevation/OscdElevation.d.ts +1 -2
  17. package/elevation/OscdElevation.js +3 -4
  18. package/elevation/OscdElevation.js.map +1 -1
  19. package/elevation/_elevation.scss +6 -0
  20. package/elevation/internal/_elevation.scss +176 -0
  21. package/elevation/internal/elevation-styles.css +1 -0
  22. package/elevation/internal/elevation-styles.css.map +1 -0
  23. package/elevation/internal/elevation-styles.d.ts +1 -0
  24. package/elevation/internal/elevation-styles.js +10 -0
  25. package/elevation/internal/elevation-styles.js.map +1 -0
  26. package/elevation/internal/elevation-styles.scss +10 -0
  27. package/elevation/internal/elevation.d.ts +13 -0
  28. package/elevation/internal/elevation.js +21 -0
  29. package/elevation/internal/elevation.js.map +1 -0
  30. package/field/OscdFilledField.js +1 -1
  31. package/field/OscdFilledField.js.map +1 -1
  32. package/field/OscdOutlinedField.js +1 -1
  33. package/field/OscdOutlinedField.js.map +1 -1
  34. package/focus/OscdFocusRing.d.ts +5 -0
  35. package/focus/OscdFocusRing.js +6 -0
  36. package/focus/OscdFocusRing.js.map +1 -0
  37. package/focus/_focus-ring.scss +6 -0
  38. package/focus/internal/_focus-ring.scss +113 -0
  39. package/focus/internal/focus-ring-styles.css +1 -0
  40. package/focus/internal/focus-ring-styles.css.map +1 -0
  41. package/focus/internal/focus-ring-styles.d.ts +1 -0
  42. package/focus/internal/focus-ring-styles.js +10 -0
  43. package/focus/internal/focus-ring-styles.js.map +1 -0
  44. package/focus/internal/focus-ring-styles.scss +10 -0
  45. package/focus/internal/focus-ring.d.ts +39 -0
  46. package/focus/internal/focus-ring.js +101 -0
  47. package/focus/internal/focus-ring.js.map +1 -0
  48. package/focus/oscd-focus-ring.d.ts +21 -0
  49. package/focus/oscd-focus-ring.js +23 -0
  50. package/focus/oscd-focus-ring.js.map +1 -0
  51. package/icon/OscdIcon.js +1 -1
  52. package/icon/OscdIcon.js.map +1 -1
  53. package/iconbutton/OscdFilledIconButton.js +1 -1
  54. package/iconbutton/OscdFilledIconButton.js.map +1 -1
  55. package/iconbutton/OscdFilledTonalIconButton.js +1 -1
  56. package/iconbutton/OscdFilledTonalIconButton.js.map +1 -1
  57. package/iconbutton/OscdIconButton.js +1 -1
  58. package/iconbutton/OscdIconButton.js.map +1 -1
  59. package/iconbutton/OscdOutlinedIconButton.js +1 -1
  60. package/iconbutton/OscdOutlinedIconButton.js.map +1 -1
  61. package/internal/aria/aria.d.ts +103 -0
  62. package/internal/aria/aria.js +81 -0
  63. package/internal/aria/aria.js.map +1 -0
  64. package/internal/aria/delegate.d.ts +54 -0
  65. package/internal/aria/delegate.js +176 -0
  66. package/internal/aria/delegate.js.map +1 -0
  67. package/internal/controller/attachable-controller.d.ts +114 -0
  68. package/internal/controller/attachable-controller.js +121 -0
  69. package/internal/controller/attachable-controller.js.map +1 -0
  70. package/internal/controller/form-submitter.d.ts +70 -0
  71. package/internal/controller/form-submitter.js +69 -0
  72. package/internal/controller/form-submitter.js.map +1 -0
  73. package/internal/controller/is-rtl.d.ts +14 -0
  74. package/internal/controller/is-rtl.js +18 -0
  75. package/internal/controller/is-rtl.js.map +1 -0
  76. package/internal/controller/string-converter.d.ts +9 -0
  77. package/internal/controller/string-converter.js +14 -0
  78. package/internal/controller/string-converter.js.map +1 -0
  79. package/internal/events/dispatch-hooks.d.ts +85 -0
  80. package/internal/events/dispatch-hooks.js +151 -0
  81. package/internal/events/dispatch-hooks.js.map +1 -0
  82. package/internal/events/form-label-activation.d.ts +55 -0
  83. package/internal/events/form-label-activation.js +96 -0
  84. package/internal/events/form-label-activation.js.map +1 -0
  85. package/internal/events/redispatch-event.d.ts +27 -0
  86. package/internal/events/redispatch-event.js +40 -0
  87. package/internal/events/redispatch-event.js.map +1 -0
  88. package/internal/motion/_animation.scss +33 -0
  89. package/internal/motion/animation.d.ts +80 -0
  90. package/internal/motion/animation.js +101 -0
  91. package/internal/motion/animation.js.map +1 -0
  92. package/internal/sass/_string-ext.scss +195 -0
  93. package/internal/sass/_var.scss +237 -0
  94. package/labs/badge/OscdBadge.d.ts +14 -0
  95. package/labs/badge/OscdBadge.js +15 -0
  96. package/labs/badge/OscdBadge.js.map +1 -0
  97. package/labs/badge/_badge.scss +6 -0
  98. package/labs/badge/internal/_badge.scss +76 -0
  99. package/labs/badge/internal/badge-styles.css +1 -0
  100. package/labs/badge/internal/badge-styles.css.map +1 -0
  101. package/labs/badge/internal/badge-styles.d.ts +1 -0
  102. package/labs/badge/internal/badge-styles.js +10 -0
  103. package/labs/badge/internal/badge-styles.js.map +1 -0
  104. package/labs/badge/internal/badge-styles.scss +10 -0
  105. package/labs/badge/internal/badge.d.ts +13 -0
  106. package/labs/badge/internal/badge.js +28 -0
  107. package/labs/badge/internal/badge.js.map +1 -0
  108. package/labs/badge/oscd-badge.d.ts +19 -0
  109. package/labs/badge/oscd-badge.js +21 -0
  110. package/labs/badge/oscd-badge.js.map +1 -0
  111. package/labs/behaviors/constraint-validation.d.ts +133 -0
  112. package/labs/behaviors/constraint-validation.js +131 -0
  113. package/labs/behaviors/constraint-validation.js.map +1 -0
  114. package/labs/behaviors/element-internals.d.ts +45 -0
  115. package/labs/behaviors/element-internals.js +46 -0
  116. package/labs/behaviors/element-internals.js.map +1 -0
  117. package/labs/behaviors/focusable.d.ts +39 -0
  118. package/labs/behaviors/focusable.js +87 -0
  119. package/labs/behaviors/focusable.js.map +1 -0
  120. package/labs/behaviors/form-associated.d.ts +199 -0
  121. package/labs/behaviors/form-associated.js +175 -0
  122. package/labs/behaviors/form-associated.js.map +1 -0
  123. package/labs/behaviors/mixin.d.ts +54 -0
  124. package/labs/behaviors/mixin.js +7 -0
  125. package/labs/behaviors/mixin.js.map +1 -0
  126. package/labs/behaviors/on-report-validity.d.ts +71 -0
  127. package/labs/behaviors/on-report-validity.js +289 -0
  128. package/labs/behaviors/on-report-validity.js.map +1 -0
  129. package/labs/behaviors/validators/checkbox-validator.d.ts +35 -0
  130. package/labs/behaviors/validators/checkbox-validator.js +34 -0
  131. package/labs/behaviors/validators/checkbox-validator.js.map +1 -0
  132. package/labs/behaviors/validators/radio-validator.d.ts +38 -0
  133. package/labs/behaviors/validators/radio-validator.js +67 -0
  134. package/labs/behaviors/validators/radio-validator.js.map +1 -0
  135. package/labs/behaviors/validators/select-validator.d.ts +35 -0
  136. package/labs/behaviors/validators/select-validator.js +35 -0
  137. package/labs/behaviors/validators/select-validator.js.map +1 -0
  138. package/labs/behaviors/validators/text-field-validator.d.ts +110 -0
  139. package/labs/behaviors/validators/text-field-validator.js +156 -0
  140. package/labs/behaviors/validators/text-field-validator.js.map +1 -0
  141. package/labs/behaviors/validators/validator.d.ts +96 -0
  142. package/labs/behaviors/validators/validator.js +73 -0
  143. package/labs/behaviors/validators/validator.js.map +1 -0
  144. package/labs/card/OscdElevatedCard.d.ts +20 -0
  145. package/labs/card/OscdElevatedCard.js +23 -0
  146. package/labs/card/OscdElevatedCard.js.map +1 -0
  147. package/labs/card/OscdFilledCard.d.ts +20 -0
  148. package/labs/card/OscdFilledCard.js +23 -0
  149. package/labs/card/OscdFilledCard.js.map +1 -0
  150. package/labs/card/OscdOutlinedCard.d.ts +20 -0
  151. package/labs/card/OscdOutlinedCard.js +23 -0
  152. package/labs/card/OscdOutlinedCard.js.map +1 -0
  153. package/labs/card/_elevated-card.scss +6 -0
  154. package/labs/card/_filled-card.scss +6 -0
  155. package/labs/card/_outlined-card.scss +6 -0
  156. package/labs/card/demo/demo.d.ts +7 -0
  157. package/labs/card/demo/demo.js +13 -0
  158. package/labs/card/demo/demo.js.map +1 -0
  159. package/labs/card/demo/stories.d.ts +15 -0
  160. package/labs/card/demo/stories.js +104 -0
  161. package/labs/card/demo/stories.js.map +1 -0
  162. package/labs/card/internal/_elevated-card.scss +35 -0
  163. package/labs/card/internal/_filled-card.scss +35 -0
  164. package/labs/card/internal/_outlined-card.scss +40 -0
  165. package/labs/card/internal/_shared.scss +62 -0
  166. package/labs/card/internal/card.d.ts +12 -0
  167. package/labs/card/internal/card.js +21 -0
  168. package/labs/card/internal/card.js.map +1 -0
  169. package/labs/card/internal/elevated-styles.css +1 -0
  170. package/labs/card/internal/elevated-styles.css.map +1 -0
  171. package/labs/card/internal/elevated-styles.d.ts +1 -0
  172. package/labs/card/internal/elevated-styles.js +10 -0
  173. package/labs/card/internal/elevated-styles.js.map +1 -0
  174. package/labs/card/internal/elevated-styles.scss +10 -0
  175. package/labs/card/internal/filled-styles.css +1 -0
  176. package/labs/card/internal/filled-styles.css.map +1 -0
  177. package/labs/card/internal/filled-styles.d.ts +1 -0
  178. package/labs/card/internal/filled-styles.js +10 -0
  179. package/labs/card/internal/filled-styles.js.map +1 -0
  180. package/labs/card/internal/filled-styles.scss +10 -0
  181. package/labs/card/internal/outlined-styles.css +1 -0
  182. package/labs/card/internal/outlined-styles.css.map +1 -0
  183. package/labs/card/internal/outlined-styles.d.ts +1 -0
  184. package/labs/card/internal/outlined-styles.js +10 -0
  185. package/labs/card/internal/outlined-styles.js.map +1 -0
  186. package/labs/card/internal/outlined-styles.scss +10 -0
  187. package/labs/card/internal/shared-styles.css +1 -0
  188. package/labs/card/internal/shared-styles.css.map +1 -0
  189. package/labs/card/internal/shared-styles.d.ts +1 -0
  190. package/labs/card/internal/shared-styles.js +10 -0
  191. package/labs/card/internal/shared-styles.js.map +1 -0
  192. package/labs/card/internal/shared-styles.scss +10 -0
  193. package/labs/card/oscd-elevated-card.d.ts +20 -0
  194. package/labs/card/oscd-elevated-card.js +23 -0
  195. package/labs/card/oscd-elevated-card.js.map +1 -0
  196. package/labs/card/oscd-filled-card.d.ts +25 -0
  197. package/labs/card/oscd-filled-card.js +28 -0
  198. package/labs/card/oscd-filled-card.js.map +1 -0
  199. package/labs/card/oscd-outlined-card.d.ts +20 -0
  200. package/labs/card/oscd-outlined-card.js +23 -0
  201. package/labs/card/oscd-outlined-card.js.map +1 -0
  202. package/list/OscdList.js +1 -1
  203. package/list/OscdList.js.map +1 -1
  204. package/list/OscdListItem.d.ts +4 -0
  205. package/list/OscdListItem.js +13 -1
  206. package/list/OscdListItem.js.map +1 -1
  207. package/menu/OscdMenu.js +1 -1
  208. package/menu/OscdMenu.js.map +1 -1
  209. package/menu/OscdMenuItem.js +1 -1
  210. package/menu/OscdMenuItem.js.map +1 -1
  211. package/navigation-drawer/OscdNavigationDrawer.js +2 -2
  212. package/navigation-drawer/OscdNavigationDrawer.js.map +1 -1
  213. package/navigation-drawer/OscdNavigationDrawerHeader.js +2 -2
  214. package/navigation-drawer/OscdNavigationDrawerHeader.js.map +1 -1
  215. package/package.json +76 -110
  216. package/radio/OscdRadio.d.ts +31 -0
  217. package/radio/OscdRadio.js +27 -0
  218. package/radio/OscdRadio.js.map +1 -0
  219. package/radio/demo/demo.d.ts +7 -0
  220. package/radio/demo/demo.js +14 -0
  221. package/radio/demo/demo.js.map +1 -0
  222. package/radio/demo/stories.d.ts +13 -0
  223. package/radio/demo/stories.js +97 -0
  224. package/radio/demo/stories.js.map +1 -0
  225. package/radio/internal/_radio.scss +198 -0
  226. package/radio/internal/radio-styles.css +1 -0
  227. package/radio/internal/radio-styles.css.map +1 -0
  228. package/radio/internal/radio-styles.d.ts +1 -0
  229. package/radio/internal/radio-styles.js +10 -0
  230. package/radio/internal/radio-styles.js.map +1 -0
  231. package/radio/internal/radio-styles.scss +10 -0
  232. package/radio/internal/radio.d.ts +59 -0
  233. package/radio/internal/radio.js +175 -0
  234. package/radio/internal/radio.js.map +1 -0
  235. package/radio/internal/single-selection-controller.d.ts +80 -0
  236. package/radio/internal/single-selection-controller.js +199 -0
  237. package/radio/internal/single-selection-controller.js.map +1 -0
  238. package/radio/oscd-radio.d.ts +32 -0
  239. package/radio/oscd-radio.js +34 -0
  240. package/radio/oscd-radio.js.map +1 -0
  241. package/ripple/OscdRipple.d.ts +5 -0
  242. package/ripple/OscdRipple.js +6 -0
  243. package/ripple/OscdRipple.js.map +1 -0
  244. package/ripple/_ripple.scss +6 -0
  245. package/ripple/internal/_ripple.scss +92 -0
  246. package/ripple/internal/ripple-styles.css +1 -0
  247. package/ripple/internal/ripple-styles.css.map +1 -0
  248. package/ripple/internal/ripple-styles.d.ts +1 -0
  249. package/ripple/internal/ripple-styles.js +10 -0
  250. package/ripple/internal/ripple-styles.js.map +1 -0
  251. package/ripple/internal/ripple-styles.scss +10 -0
  252. package/ripple/internal/ripple.d.ts +76 -0
  253. package/ripple/internal/ripple.js +425 -0
  254. package/ripple/internal/ripple.js.map +1 -0
  255. package/ripple/oscd-ripple.d.ts +29 -0
  256. package/ripple/oscd-ripple.js +31 -0
  257. package/ripple/oscd-ripple.js.map +1 -0
  258. package/select/OscdFilledSelect.js +1 -1
  259. package/select/OscdFilledSelect.js.map +1 -1
  260. package/select/OscdOutlinedSelect.js +1 -1
  261. package/select/OscdOutlinedSelect.js.map +1 -1
  262. package/select/OscdSelectOption.js +1 -1
  263. package/select/OscdSelectOption.js.map +1 -1
  264. package/tabs/OscdPrimaryTab.js +1 -1
  265. package/tabs/OscdPrimaryTab.js.map +1 -1
  266. package/tabs/OscdSecondaryTab.js +1 -1
  267. package/tabs/OscdSecondaryTab.js.map +1 -1
  268. package/tabs/OscdTabs.js +1 -1
  269. package/tabs/OscdTabs.js.map +1 -1
  270. package/textfield/OscdFilledTextField.js +5 -2
  271. package/textfield/OscdFilledTextField.js.map +1 -1
  272. package/textfield/OscdOutlinedTextField.js +5 -2
  273. package/textfield/OscdOutlinedTextField.js.map +1 -1
  274. package/tokens/_index.scss +66 -0
  275. package/tokens/_md-comp-assist-chip.scss +153 -0
  276. package/tokens/_md-comp-badge.scss +39 -0
  277. package/tokens/_md-comp-checkbox.scss +156 -0
  278. package/tokens/_md-comp-circular-progress.scss +79 -0
  279. package/tokens/_md-comp-dialog.scss +112 -0
  280. package/tokens/_md-comp-divider.scss +43 -0
  281. package/tokens/_md-comp-elevated-button.scss +143 -0
  282. package/tokens/_md-comp-elevated-card.scss +80 -0
  283. package/tokens/_md-comp-elevation.scss +48 -0
  284. package/tokens/_md-comp-fab-branded.scss +155 -0
  285. package/tokens/_md-comp-fab.scss +296 -0
  286. package/tokens/_md-comp-filled-button.scss +143 -0
  287. package/tokens/_md-comp-filled-card.scss +80 -0
  288. package/tokens/_md-comp-filled-field.scss +293 -0
  289. package/tokens/_md-comp-filled-icon-button.scss +119 -0
  290. package/tokens/_md-comp-filled-select.scss +198 -0
  291. package/tokens/_md-comp-filled-text-field.scss +200 -0
  292. package/tokens/_md-comp-filled-tonal-button.scss +143 -0
  293. package/tokens/_md-comp-filled-tonal-icon-button.scss +123 -0
  294. package/tokens/_md-comp-filter-chip.scss +265 -0
  295. package/tokens/_md-comp-focus-ring.scss +78 -0
  296. package/tokens/_md-comp-full-screen-dialog.scss +25 -0
  297. package/tokens/_md-comp-icon-button.scss +94 -0
  298. package/tokens/_md-comp-icon.scss +46 -0
  299. package/tokens/_md-comp-input-chip.scss +247 -0
  300. package/tokens/_md-comp-item.scss +88 -0
  301. package/tokens/_md-comp-linear-progress.scss +64 -0
  302. package/tokens/_md-comp-list-item.scss +173 -0
  303. package/tokens/_md-comp-list.scss +44 -0
  304. package/tokens/_md-comp-menu-item.scss +125 -0
  305. package/tokens/_md-comp-menu.scss +59 -0
  306. package/tokens/_md-comp-navigation-bar.scss +44 -0
  307. package/tokens/_md-comp-navigation-drawer.scss +44 -0
  308. package/tokens/_md-comp-outlined-button.scss +139 -0
  309. package/tokens/_md-comp-outlined-card.scss +86 -0
  310. package/tokens/_md-comp-outlined-field.scss +268 -0
  311. package/tokens/_md-comp-outlined-icon-button.scss +117 -0
  312. package/tokens/_md-comp-outlined-segmented-button.scss +123 -0
  313. package/tokens/_md-comp-outlined-select.scss +186 -0
  314. package/tokens/_md-comp-outlined-text-field.scss +187 -0
  315. package/tokens/_md-comp-primary-tab.scss +160 -0
  316. package/tokens/_md-comp-radio.scss +86 -0
  317. package/tokens/_md-comp-ripple.scss +48 -0
  318. package/tokens/_md-comp-secondary-tab.scss +158 -0
  319. package/tokens/_md-comp-slider.scss +117 -0
  320. package/tokens/_md-comp-suggestion-chip.scss +157 -0
  321. package/tokens/_md-comp-switch.scss +187 -0
  322. package/tokens/_md-comp-test-table.scss +43 -0
  323. package/tokens/_md-comp-text-button.scss +132 -0
  324. package/tokens/_md-ref-palette.scss +112 -0
  325. package/tokens/_md-ref-typeface.scss +46 -0
  326. package/tokens/_md-sys-color.scss +119 -0
  327. package/tokens/_md-sys-elevation.scss +31 -0
  328. package/tokens/_md-sys-motion.scss +12 -0
  329. package/tokens/_md-sys-shape.scss +102 -0
  330. package/tokens/_md-sys-state.scss +12 -0
  331. package/tokens/_md-sys-typescale.scss +149 -0
  332. package/tokens/internal/_shape.scss +93 -0
  333. package/tokens/internal/_validate.scss +109 -0
  334. package/tokens/v0_192/_index.scss +107 -0
  335. package/tokens/v0_192/_md-comp-assist-chip.scss +111 -0
  336. package/tokens/v0_192/_md-comp-badge.scss +61 -0
  337. package/tokens/v0_192/_md-comp-banner.scss +76 -0
  338. package/tokens/v0_192/_md-comp-bottom-app-bar.scss +36 -0
  339. package/tokens/v0_192/_md-comp-carousel-item.scss +66 -0
  340. package/tokens/v0_192/_md-comp-checkbox.scss +129 -0
  341. package/tokens/v0_192/_md-comp-circular-progress-indicator.scss +41 -0
  342. package/tokens/v0_192/_md-comp-data-table.scss +99 -0
  343. package/tokens/v0_192/_md-comp-date-input-modal.scss +90 -0
  344. package/tokens/v0_192/_md-comp-date-picker-docked.scss +247 -0
  345. package/tokens/v0_192/_md-comp-date-picker-modal.scss +306 -0
  346. package/tokens/v0_192/_md-comp-dialog.scss +124 -0
  347. package/tokens/v0_192/_md-comp-divider.scss +28 -0
  348. package/tokens/v0_192/_md-comp-elevated-button.scss +92 -0
  349. package/tokens/v0_192/_md-comp-elevated-card.scss +60 -0
  350. package/tokens/v0_192/_md-comp-extended-fab-branded.scss +89 -0
  351. package/tokens/v0_192/_md-comp-extended-fab-primary.scss +97 -0
  352. package/tokens/v0_192/_md-comp-extended-fab-secondary.scss +98 -0
  353. package/tokens/v0_192/_md-comp-extended-fab-surface.scss +93 -0
  354. package/tokens/v0_192/_md-comp-extended-fab-tertiary.scss +98 -0
  355. package/tokens/v0_192/_md-comp-fab-branded-large.scss +63 -0
  356. package/tokens/v0_192/_md-comp-fab-branded.scss +63 -0
  357. package/tokens/v0_192/_md-comp-fab-primary-large.scss +68 -0
  358. package/tokens/v0_192/_md-comp-fab-primary-small.scss +68 -0
  359. package/tokens/v0_192/_md-comp-fab-primary.scss +68 -0
  360. package/tokens/v0_192/_md-comp-fab-secondary-large.scss +69 -0
  361. package/tokens/v0_192/_md-comp-fab-secondary-small.scss +69 -0
  362. package/tokens/v0_192/_md-comp-fab-secondary.scss +69 -0
  363. package/tokens/v0_192/_md-comp-fab-surface-large.scss +67 -0
  364. package/tokens/v0_192/_md-comp-fab-surface-small.scss +67 -0
  365. package/tokens/v0_192/_md-comp-fab-surface.scss +67 -0
  366. package/tokens/v0_192/_md-comp-fab-tertiary-large.scss +69 -0
  367. package/tokens/v0_192/_md-comp-fab-tertiary-small.scss +69 -0
  368. package/tokens/v0_192/_md-comp-fab-tertiary.scss +69 -0
  369. package/tokens/v0_192/_md-comp-filled-autocomplete.scss +239 -0
  370. package/tokens/v0_192/_md-comp-filled-button.scss +92 -0
  371. package/tokens/v0_192/_md-comp-filled-card.scss +62 -0
  372. package/tokens/v0_192/_md-comp-filled-icon-button.scss +83 -0
  373. package/tokens/v0_192/_md-comp-filled-menu-button.scss +101 -0
  374. package/tokens/v0_192/_md-comp-filled-select.scss +273 -0
  375. package/tokens/v0_192/_md-comp-filled-text-field.scss +193 -0
  376. package/tokens/v0_192/_md-comp-filled-tonal-button.scss +102 -0
  377. package/tokens/v0_192/_md-comp-filled-tonal-icon-button.scss +90 -0
  378. package/tokens/v0_192/_md-comp-filter-chip.scss +210 -0
  379. package/tokens/v0_192/_md-comp-full-screen-dialog.scss +114 -0
  380. package/tokens/v0_192/_md-comp-icon-button.scss +74 -0
  381. package/tokens/v0_192/_md-comp-input-chip.scss +187 -0
  382. package/tokens/v0_192/_md-comp-linear-progress-indicator.scss +43 -0
  383. package/tokens/v0_192/_md-comp-list.scss +255 -0
  384. package/tokens/v0_192/_md-comp-menu.scss +44 -0
  385. package/tokens/v0_192/_md-comp-navigation-bar.scss +115 -0
  386. package/tokens/v0_192/_md-comp-navigation-drawer.scss +165 -0
  387. package/tokens/v0_192/_md-comp-navigation-rail.scss +119 -0
  388. package/tokens/v0_192/_md-comp-outlined-autocomplete.scss +229 -0
  389. package/tokens/v0_192/_md-comp-outlined-button.scss +87 -0
  390. package/tokens/v0_192/_md-comp-outlined-card.scss +66 -0
  391. package/tokens/v0_192/_md-comp-outlined-icon-button.scss +83 -0
  392. package/tokens/v0_192/_md-comp-outlined-menu-button.scss +97 -0
  393. package/tokens/v0_192/_md-comp-outlined-segmented-button.scss +115 -0
  394. package/tokens/v0_192/_md-comp-outlined-select.scss +263 -0
  395. package/tokens/v0_192/_md-comp-outlined-text-field.scss +174 -0
  396. package/tokens/v0_192/_md-comp-plain-tooltip.scss +58 -0
  397. package/tokens/v0_192/_md-comp-primary-navigation-tab.scss +124 -0
  398. package/tokens/v0_192/_md-comp-radio-button.scss +71 -0
  399. package/tokens/v0_192/_md-comp-rich-tooltip.scss +122 -0
  400. package/tokens/v0_192/_md-comp-scrim.scss +28 -0
  401. package/tokens/v0_192/_md-comp-search-bar.scss +100 -0
  402. package/tokens/v0_192/_md-comp-search-view.scss +94 -0
  403. package/tokens/v0_192/_md-comp-secondary-navigation-tab.scss +87 -0
  404. package/tokens/v0_192/_md-comp-sheet-bottom.scss +46 -0
  405. package/tokens/v0_192/_md-comp-sheet-floating.scss +35 -0
  406. package/tokens/v0_192/_md-comp-sheet-side.scss +94 -0
  407. package/tokens/v0_192/_md-comp-slider.scss +118 -0
  408. package/tokens/v0_192/_md-comp-snackbar.scss +130 -0
  409. package/tokens/v0_192/_md-comp-standard-menu-button.scss +101 -0
  410. package/tokens/v0_192/_md-comp-suggestion-chip.scss +127 -0
  411. package/tokens/v0_192/_md-comp-switch.scss +141 -0
  412. package/tokens/v0_192/_md-comp-text-button.scss +80 -0
  413. package/tokens/v0_192/_md-comp-time-input.scss +220 -0
  414. package/tokens/v0_192/_md-comp-time-picker.scss +267 -0
  415. package/tokens/v0_192/_md-comp-top-app-bar-large.scss +64 -0
  416. package/tokens/v0_192/_md-comp-top-app-bar-medium.scss +64 -0
  417. package/tokens/v0_192/_md-comp-top-app-bar-small-centered.scss +71 -0
  418. package/tokens/v0_192/_md-comp-top-app-bar-small.scss +67 -0
  419. package/tokens/v0_192/_md-ref-palette.scss +109 -0
  420. package/tokens/v0_192/_md-ref-typeface.scss +23 -0
  421. package/tokens/v0_192/_md-sys-color.scss +135 -0
  422. package/tokens/v0_192/_md-sys-elevation.scss +24 -0
  423. package/tokens/v0_192/_md-sys-motion.scss +55 -0
  424. package/tokens/v0_192/_md-sys-shape.scss +33 -0
  425. package/tokens/v0_192/_md-sys-state.scss +22 -0
  426. package/tokens/v0_192/_md-sys-typescale.scss +286 -0
  427. package/tokens/v0_192/index.test.css +1 -0
  428. package/tokens/v0_192/index.test.css.map +1 -0
  429. package/tokens/v0_192/index.test.scss +584 -0
  430. package/tokens/v0_192/lib.test.css +1 -0
  431. package/tokens/v0_192/lib.test.css.map +1 -0
  432. package/tokens/v0_192/lib.test.scss +663 -0
  433. package/utils/storybook/getStorybookHelpers.js +0 -1
  434. package/utils/storybook/getStorybookHelpers.js.map +1 -1
  435. package/utils/storybook/scopedWcDecorator.js +1 -0
  436. package/utils/storybook/scopedWcDecorator.js.map +1 -1
  437. package/utils/storybook/stories/components/knob-ui-components.d.ts +103 -0
  438. package/utils/storybook/stories/components/knob-ui-components.js +414 -0
  439. package/utils/storybook/stories/components/knob-ui-components.js.map +1 -0
  440. package/utils/storybook/stories/components/stories-renderer.d.ts +40 -0
  441. package/utils/storybook/stories/components/stories-renderer.js +204 -0
  442. package/utils/storybook/stories/components/stories-renderer.js.map +1 -0
  443. package/utils/storybook/stories/components/story-knob-panel.d.ts +53 -0
  444. package/utils/storybook/stories/components/story-knob-panel.js +333 -0
  445. package/utils/storybook/stories/components/story-knob-panel.js.map +1 -0
  446. package/utils/storybook/stories/components/story-renderer.d.ts +27 -0
  447. package/utils/storybook/stories/components/story-renderer.js +84 -0
  448. package/utils/storybook/stories/components/story-renderer.js.map +1 -0
  449. package/utils/storybook/stories/index.d.ts +8 -0
  450. package/utils/storybook/stories/index.js +11 -0
  451. package/utils/storybook/stories/index.js.map +1 -0
  452. package/utils/storybook/stories/knobs.d.ts +143 -0
  453. package/utils/storybook/stories/knobs.js +177 -0
  454. package/utils/storybook/stories/knobs.js.map +1 -0
  455. package/utils/storybook/stories/material-collection.d.ts +75 -0
  456. package/utils/storybook/stories/material-collection.js +59 -0
  457. package/utils/storybook/stories/material-collection.js.map +1 -0
  458. package/utils/storybook/stories/story.d.ts +85 -0
  459. package/utils/storybook/stories/story.js +142 -0
  460. package/utils/storybook/stories/story.js.map +1 -0
  461. package/utils/storybook/stories/theme-loader.d.ts +13 -0
  462. package/utils/storybook/stories/theme-loader.js +43 -0
  463. package/utils/storybook/stories/theme-loader.js.map +1 -0
  464. package/utils/storybook/themingDecorator.d.ts +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AC;IAED,IAAI,mBAAwC,CAAC;IAC7C,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChD,IAAI,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAChC,mBAAmB,GAAG,OAAO,CAAC;YAC9B,MAAM;QACR,CAAC;IACH,CAAC;IAED,OAAO,mBAAmB,KAAK,OAAO,CAAC;AACzC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { LitElement, isServer } from 'lit';\n\nimport { ConstraintValidation } from './constraint-validation.js';\nimport { WithElementInternals, internals } from './element-internals.js';\nimport { MixinBase, MixinReturn } from './mixin.js';\n\n/**\n * A constraint validation element that has a callback for when the element\n * should report validity styles and error messages to the user.\n *\n * This is commonly used in text-field-like controls that display error styles\n * and error messages.\n */\nexport interface OnReportValidity extends ConstraintValidation {\n /**\n * A callback that is invoked when validity should be reported. Components\n * that can display their own error state can use this and update their\n * styles.\n *\n * If an invalid event is provided, the element is invalid. If `null`, the\n * element is valid.\n *\n * The invalid event's `preventDefault()` may be called to stop the platform\n * popup from displaying.\n *\n * @param invalidEvent The `invalid` event dispatched when an element is\n * invalid, or `null` if the element is valid.\n */\n [onReportValidity](invalidEvent: Event | null): void;\n\n // `mixinOnReportValidity()` implements this optional method. If overriden,\n // call `super.formAssociatedCallback(form)`.\n // (inherit jsdoc from `FormAssociated`)\n formAssociatedCallback(form: HTMLFormElement | null): void;\n}\n\n/**\n * A symbol property used for a callback when validity has been reported.\n */\nexport const onReportValidity = Symbol('onReportValidity');\n\n// Private symbol members, used to avoid name clashing.\nconst privateCleanupFormListeners = Symbol('privateCleanupFormListeners');\nconst privateDoNotReportInvalid = Symbol('privateDoNotReportInvalid');\nconst privateIsSelfReportingValidity = Symbol('privateIsSelfReportingValidity');\nconst privateCallOnReportValidity = Symbol('privateCallOnReportValidity');\n\n/**\n * Mixes in a callback for constraint validation when validity should be\n * styled and reported to the user.\n *\n * This is commonly used in text-field-like controls that display error styles\n * and error messages.\n *\n * @example\n * ```ts\n * const baseClass = mixinOnReportValidity(\n * mixinConstraintValidation(\n * mixinFormAssociated(mixinElementInternals(LitElement)),\n * ),\n * );\n *\n * class MyField extends baseClass {\n * \\@property({type: Boolean}) error = false;\n * \\@property() errorMessage = '';\n *\n * [onReportValidity](invalidEvent: Event | null) {\n * this.error = !!invalidEvent;\n * this.errorMessage = this.validationMessage;\n *\n * // Optionally prevent platform popup from displaying\n * invalidEvent?.preventDefault();\n * }\n * }\n * ```\n *\n * @param base The class to mix functionality into.\n * @return The provided class with `OnReportValidity` mixed in.\n */\nexport function mixinOnReportValidity<\n T extends MixinBase<LitElement & ConstraintValidation & WithElementInternals>,\n>(base: T): MixinReturn<T, OnReportValidity> {\n abstract class OnReportValidityElement\n extends base\n implements OnReportValidity\n {\n /**\n * Used to clean up event listeners when a new form is associated.\n */\n [privateCleanupFormListeners] = new AbortController();\n\n /**\n * Used to determine if an invalid event should report validity. Invalid\n * events from `checkValidity()` do not trigger reporting.\n */\n [privateDoNotReportInvalid] = false;\n\n /**\n * Used to determine if the control is reporting validity from itself, or\n * if a `<form>` is causing the validity report. Forms have different\n * control focusing behavior.\n */\n [privateIsSelfReportingValidity] = false;\n\n // Mixins must have a constructor with `...args: any[]`\n // tslint:disable-next-line:no-any\n constructor(...args: any[]) {\n super(...args);\n if (isServer) {\n return;\n }\n\n this.addEventListener(\n 'invalid',\n invalidEvent => {\n // Listen for invalid events dispatched by a `<form>` when it tries to\n // submit and the element is invalid. We ignore events dispatched when\n // calling `checkValidity()` as well as untrusted events, since the\n // `reportValidity()` and `<form>`-dispatched events are always\n // trusted.\n if (this[privateDoNotReportInvalid] || !invalidEvent.isTrusted) {\n return;\n }\n\n this.addEventListener(\n 'invalid',\n () => {\n // A normal bubbling phase event listener. By adding it here, we\n // ensure it's the last event listener that is called during the\n // bubbling phase.\n this[privateCallOnReportValidity](invalidEvent);\n },\n { once: true },\n );\n },\n {\n // Listen during the capture phase, which will happen before the\n // bubbling phase. That way, we can add a final event listener that\n // will run after other event listeners, and we can check if it was\n // default prevented. This works because invalid does not bubble.\n capture: true,\n },\n );\n }\n\n override checkValidity() {\n this[privateDoNotReportInvalid] = true;\n const valid = super.checkValidity();\n this[privateDoNotReportInvalid] = false;\n return valid;\n }\n\n override reportValidity() {\n this[privateIsSelfReportingValidity] = true;\n const valid = super.reportValidity();\n // Constructor's invalid listener will handle reporting invalid events.\n if (valid) {\n this[privateCallOnReportValidity](null);\n }\n\n this[privateIsSelfReportingValidity] = false;\n return valid;\n }\n\n [privateCallOnReportValidity](invalidEvent: Event | null) {\n // Since invalid events do not bubble to parent listeners, and because\n // our invalid listeners are added lazily after other listeners, we can\n // reliably read `defaultPrevented` synchronously without worrying\n // about waiting for another listener that could cancel it.\n const wasCanceled = invalidEvent?.defaultPrevented;\n if (wasCanceled) {\n return;\n }\n\n this[onReportValidity](invalidEvent);\n\n // If an implementation calls invalidEvent.preventDefault() to stop the\n // platform popup from displaying, focusing is also prevented, so we need\n // to manually focus.\n const implementationCanceledFocus =\n !wasCanceled && invalidEvent?.defaultPrevented;\n if (!implementationCanceledFocus) {\n return;\n }\n\n // The control should be focused when:\n // - `control.reportValidity()` is called (self-reporting).\n // - a form is reporting validity for its controls and this is the first\n // invalid control.\n if (\n this[privateIsSelfReportingValidity] ||\n isFirstInvalidControlInForm(this[internals].form, this)\n ) {\n this.focus();\n }\n }\n\n [onReportValidity](_invalidEvent: Event | null) {\n throw new Error(\n `Implement [onReportValidity] in ${this.constructor.name}`,\n );\n }\n\n override formAssociatedCallback(form: HTMLFormElement | null) {\n // can't use super.formAssociatedCallback?.() due to closure\n if (super.formAssociatedCallback) {\n super.formAssociatedCallback(form);\n }\n\n // Clean up previous form listeners.\n this[privateCleanupFormListeners].abort();\n if (!form) {\n return;\n }\n\n this[privateCleanupFormListeners] = new AbortController();\n\n // Add a listener that fires when the form runs constraint validation and\n // the control is valid, so that it may remove its error styles.\n //\n // This happens on `form.reportValidity()` and `form.requestSubmit()`\n // (both when the submit fails and passes).\n addFormReportValidListener(\n this,\n form,\n () => {\n this[privateCallOnReportValidity](null);\n },\n this[privateCleanupFormListeners].signal,\n );\n }\n }\n\n return OnReportValidityElement;\n}\n\n/**\n * Add a listener that fires when a form runs constraint validation on a control\n * and it is valid. This is needed to clear previously invalid styles.\n *\n * @param control The control of the form to listen for valid events.\n * @param form The control's form that can run constraint validation.\n * @param onControlValid A listener that is called when the form runs constraint\n * validation and the control is valid.\n * @param cleanup A cleanup signal to remove the listener.\n */\nfunction addFormReportValidListener(\n control: Element,\n form: HTMLFormElement,\n onControlValid: () => void,\n cleanup: AbortSignal,\n) {\n const validateHooks = getFormValidateHooks(form);\n\n // When a form validates its controls, check if an invalid event is dispatched\n // on the control. If it is not, then inform the control to report its valid\n // state.\n let controlFiredInvalid = false;\n let cleanupInvalidListener: AbortController | undefined;\n let isNextSubmitFromHook = false;\n validateHooks.addEventListener(\n 'before',\n () => {\n isNextSubmitFromHook = true;\n cleanupInvalidListener = new AbortController();\n controlFiredInvalid = false;\n control.addEventListener(\n 'invalid',\n () => {\n controlFiredInvalid = true;\n },\n {\n signal: cleanupInvalidListener.signal,\n },\n );\n },\n { signal: cleanup },\n );\n\n validateHooks.addEventListener(\n 'after',\n () => {\n isNextSubmitFromHook = false;\n cleanupInvalidListener?.abort();\n if (controlFiredInvalid) {\n return;\n }\n\n onControlValid();\n },\n { signal: cleanup },\n );\n\n // The above hooks handle imperatively submitting the form, but not\n // declaratively submitting the form. This happens when:\n // 1. A non-custom element `<button type=\"submit\">` is clicked.\n // 2. Enter is pressed on a non-custom element text editable `<input>`.\n form.addEventListener(\n 'submit',\n () => {\n // This submit was from `form.requestSubmit()`, which already calls the\n // listener.\n if (isNextSubmitFromHook) {\n return;\n }\n\n onControlValid();\n },\n {\n signal: cleanup,\n },\n );\n\n // Note: it is a known limitation that we cannot detect if a form tries to\n // submit declaratively, but fails to do so because an unrelated sibling\n // control failed its constraint validation.\n //\n // Since we cannot detect when that happens, a previously invalid control may\n // not clear its error styling when it becomes valid again.\n //\n // To work around this, call `form.reportValidity()` when submitting a form\n // declaratively. This can be down on the `<button type=\"submit\">`'s click or\n // the text editable `<input>`'s 'Enter' keydown.\n}\n\nconst FORM_VALIDATE_HOOKS = new WeakMap<HTMLFormElement, EventTarget>();\n\n/**\n * Get a hooks `EventTarget` that dispatches 'before' and 'after' events that\n * fire before a form runs constraint validation and immediately after it\n * finishes running constraint validation on its controls.\n *\n * This happens during `form.reportValidity()` and `form.requestSubmit()`.\n *\n * @param form The form to get or set up hooks for.\n * @return A hooks `EventTarget` to add listeners to.\n */\nfunction getFormValidateHooks(form: HTMLFormElement) {\n if (!FORM_VALIDATE_HOOKS.has(form)) {\n // Patch form methods to add event listener hooks. These are needed to react\n // to form behaviors that do not dispatch events, such as a form asking its\n // controls to report their validity.\n //\n // We should only patch the methods once, since multiple controls and other\n // forces may want to patch this method. We cannot reliably clean it up if\n // there are multiple patched and re-patched methods referring holding\n // references to each other.\n //\n // Instead, we never clean up the patch but add and clean up event listeners\n // added to the hooks after the patch.\n const hooks = new EventTarget();\n FORM_VALIDATE_HOOKS.set(form, hooks);\n\n // Add hooks to support notifying before and after a form has run constraint\n // validation on its controls.\n // Note: `form.submit()` does not run constraint validation per spec.\n for (const methodName of ['reportValidity', 'requestSubmit'] as const) {\n const superMethod = form[methodName];\n form[methodName] = function (this: HTMLFormElement, ...args: unknown[]) {\n hooks.dispatchEvent(new Event('before'));\n const result = Reflect.apply(superMethod, this, args);\n hooks.dispatchEvent(new Event('after'));\n return result;\n };\n }\n }\n\n return FORM_VALIDATE_HOOKS.get(form)!;\n}\n\n/**\n * Checks if a control is the first invalid control in a form.\n *\n * @param form The control's form. When `null`, the control doesn't have a form\n * and the method returns true.\n * @param control The control to check.\n * @return True if there is no form or if the control is the form's first\n * invalid control.\n */\nfunction isFirstInvalidControlInForm(\n form: HTMLFormElement | null,\n control: HTMLElement,\n) {\n if (!form) {\n return true;\n }\n\n let firstInvalidControl: Element | undefined;\n for (const element of Array.from(form.elements)) {\n if (element.matches(':invalid')) {\n firstInvalidControl = element;\n break;\n }\n }\n\n return firstInvalidControl === control;\n}\n"]}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Validator } from './validator.js';
7
+ /**
8
+ * Constraint validation properties for a checkbox.
9
+ */
10
+ export interface CheckboxState {
11
+ /**
12
+ * Whether the checkbox is checked.
13
+ */
14
+ readonly checked: boolean;
15
+ /**
16
+ * Whether the checkbox is required.
17
+ */
18
+ readonly required: boolean;
19
+ }
20
+ /**
21
+ * A validator that provides constraint validation that emulates
22
+ * `<input type="checkbox">` validation.
23
+ */
24
+ export declare class CheckboxValidator extends Validator<CheckboxState> {
25
+ private checkboxControl?;
26
+ protected computeValidity(state: CheckboxState): {
27
+ validity: ValidityState;
28
+ validationMessage: string;
29
+ };
30
+ protected equals(prev: CheckboxState, next: CheckboxState): boolean;
31
+ protected copy({ checked, required }: CheckboxState): {
32
+ checked: boolean;
33
+ required: boolean;
34
+ };
35
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Validator } from './validator.js';
7
+ /**
8
+ * A validator that provides constraint validation that emulates
9
+ * `<input type="checkbox">` validation.
10
+ */
11
+ export class CheckboxValidator extends Validator {
12
+ computeValidity(state) {
13
+ if (!this.checkboxControl) {
14
+ // Lazily create the platform input
15
+ this.checkboxControl = document.createElement('input');
16
+ this.checkboxControl.type = 'checkbox';
17
+ }
18
+ this.checkboxControl.checked = state.checked;
19
+ this.checkboxControl.required = state.required;
20
+ return {
21
+ validity: this.checkboxControl.validity,
22
+ validationMessage: this.checkboxControl.validationMessage,
23
+ };
24
+ }
25
+ // eslint-disable-next-line class-methods-use-this
26
+ equals(prev, next) {
27
+ return prev.checked === next.checked && prev.required === next.required;
28
+ }
29
+ // eslint-disable-next-line class-methods-use-this
30
+ copy({ checked, required }) {
31
+ return { checked, required };
32
+ }
33
+ }
34
+ //# sourceMappingURL=checkbox-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkbox-validator.js","sourceRoot":"","sources":["checkbox-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAiB3C;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,SAAwB;IAG1C,eAAe,CAAC,KAAoB;QACrD,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1B,mCAAmC;YACnC,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACvD,IAAI,CAAC,eAAe,CAAC,IAAI,GAAG,UAAU,CAAC;QACzC,CAAC;QAED,IAAI,CAAC,eAAe,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7C,IAAI,CAAC,eAAe,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/C,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC,QAAQ;YACvC,iBAAiB,EAAE,IAAI,CAAC,eAAe,CAAC,iBAAiB;SAC1D,CAAC;IACJ,CAAC;IAED,kDAAkD;IAC/B,MAAM,CAAC,IAAmB,EAAE,IAAmB;QAChE,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,CAAC;IAC1E,CAAC;IAED,kDAAkD;IAC/B,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAiB;QAC1D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Validator } from './validator.js';\n\n/**\n * Constraint validation properties for a checkbox.\n */\nexport interface CheckboxState {\n /**\n * Whether the checkbox is checked.\n */\n readonly checked: boolean;\n\n /**\n * Whether the checkbox is required.\n */\n readonly required: boolean;\n}\n\n/**\n * A validator that provides constraint validation that emulates\n * `<input type=\"checkbox\">` validation.\n */\nexport class CheckboxValidator extends Validator<CheckboxState> {\n private checkboxControl?: HTMLInputElement;\n\n protected override computeValidity(state: CheckboxState) {\n if (!this.checkboxControl) {\n // Lazily create the platform input\n this.checkboxControl = document.createElement('input');\n this.checkboxControl.type = 'checkbox';\n }\n\n this.checkboxControl.checked = state.checked;\n this.checkboxControl.required = state.required;\n return {\n validity: this.checkboxControl.validity,\n validationMessage: this.checkboxControl.validationMessage,\n };\n }\n\n // eslint-disable-next-line class-methods-use-this\n protected override equals(prev: CheckboxState, next: CheckboxState) {\n return prev.checked === next.checked && prev.required === next.required;\n }\n\n // eslint-disable-next-line class-methods-use-this\n protected override copy({ checked, required }: CheckboxState) {\n return { checked, required };\n }\n}\n"]}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Validator } from './validator.js';
7
+ /**
8
+ * Constraint validation properties for a radio.
9
+ */
10
+ export interface RadioState {
11
+ /**
12
+ * Whether the radio is checked.
13
+ */
14
+ readonly checked: boolean;
15
+ /**
16
+ * Whether the radio is required.
17
+ */
18
+ readonly required: boolean;
19
+ }
20
+ /**
21
+ * Radio constraint validation properties for a single radio and its siblings.
22
+ */
23
+ export type RadioGroupState = readonly [RadioState, ...RadioState[]];
24
+ /**
25
+ * A validator that provides constraint validation that emulates
26
+ * `<input type="radio">` validation.
27
+ */
28
+ export declare class RadioValidator extends Validator<RadioGroupState> {
29
+ private radioElement?;
30
+ protected computeValidity(states: RadioGroupState): {
31
+ validity: {
32
+ valueMissing: boolean;
33
+ };
34
+ validationMessage: string;
35
+ };
36
+ protected equals(prevGroup: RadioGroupState, nextGroup: RadioGroupState): boolean;
37
+ protected copy(states: RadioGroupState): RadioGroupState;
38
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Validator } from './validator.js';
7
+ /**
8
+ * A validator that provides constraint validation that emulates
9
+ * `<input type="radio">` validation.
10
+ */
11
+ export class RadioValidator extends Validator {
12
+ computeValidity(states) {
13
+ if (!this.radioElement) {
14
+ // Lazily create the radio element
15
+ this.radioElement = document.createElement('input');
16
+ this.radioElement.type = 'radio';
17
+ // A name is required for validation to run
18
+ this.radioElement.name = 'group';
19
+ }
20
+ let isRequired = false;
21
+ let isChecked = false;
22
+ for (const { checked, required } of states) {
23
+ if (required) {
24
+ isRequired = true;
25
+ }
26
+ if (checked) {
27
+ isChecked = true;
28
+ }
29
+ }
30
+ // Firefox v119 doesn't compute grouped radio validation correctly while
31
+ // they are detached from the DOM, which is why we don't render multiple
32
+ // virtual <input>s. Instead, we can check the required/checked states and
33
+ // grab the i18n'd validation message if the value is missing.
34
+ this.radioElement.checked = isChecked;
35
+ this.radioElement.required = isRequired;
36
+ return {
37
+ validity: {
38
+ valueMissing: isRequired && !isChecked,
39
+ },
40
+ validationMessage: this.radioElement.validationMessage,
41
+ };
42
+ }
43
+ // eslint-disable-next-line class-methods-use-this
44
+ equals(prevGroup, nextGroup) {
45
+ if (prevGroup.length !== nextGroup.length) {
46
+ return false;
47
+ }
48
+ for (let i = 0; i < prevGroup.length; i++) {
49
+ const prev = prevGroup[i];
50
+ const next = nextGroup[i];
51
+ if (prev.checked !== next.checked || prev.required !== next.required) {
52
+ return false;
53
+ }
54
+ }
55
+ return true;
56
+ }
57
+ // eslint-disable-next-line class-methods-use-this
58
+ copy(states) {
59
+ // Cast as unknown since typescript does not have enough information to
60
+ // infer that the array always has at least one element.
61
+ return states.map(({ checked, required }) => ({
62
+ checked,
63
+ required,
64
+ }));
65
+ }
66
+ }
67
+ //# sourceMappingURL=radio-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"radio-validator.js","sourceRoot":"","sources":["radio-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAsB3C;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,SAA0B;IAGzC,eAAe,CAAC,MAAuB;QACxD,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,kCAAkC;YAClC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACpD,IAAI,CAAC,YAAY,CAAC,IAAI,GAAG,OAAO,CAAC;YACjC,2CAA2C;YAC3C,IAAI,CAAC,YAAY,CAAC,IAAI,GAAG,OAAO,CAAC;QACnC,CAAC;QAED,IAAI,UAAU,GAAG,KAAK,CAAC;QACvB,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,KAAK,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,MAAM,EAAE,CAAC;YAC3C,IAAI,QAAQ,EAAE,CAAC;gBACb,UAAU,GAAG,IAAI,CAAC;YACpB,CAAC;YAED,IAAI,OAAO,EAAE,CAAC;gBACZ,SAAS,GAAG,IAAI,CAAC;YACnB,CAAC;QACH,CAAC;QAED,wEAAwE;QACxE,wEAAwE;QACxE,0EAA0E;QAC1E,8DAA8D;QAC9D,IAAI,CAAC,YAAY,CAAC,OAAO,GAAG,SAAS,CAAC;QACtC,IAAI,CAAC,YAAY,CAAC,QAAQ,GAAG,UAAU,CAAC;QACxC,OAAO;YACL,QAAQ,EAAE;gBACR,YAAY,EAAE,UAAU,IAAI,CAAC,SAAS;aACvC;YACD,iBAAiB,EAAE,IAAI,CAAC,YAAY,CAAC,iBAAiB;SACvD,CAAC;IACJ,CAAC;IAED,kDAAkD;IAC/B,MAAM,CACvB,SAA0B,EAC1B,SAA0B;QAE1B,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,EAAE,CAAC;YAC1C,OAAO,KAAK,CAAC;QACf,CAAC;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC1C,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YAC1B,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YAC1B,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACrE,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kDAAkD;IAC/B,IAAI,CAAC,MAAuB;QAC7C,uEAAuE;QACvE,wDAAwD;QACxD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;YAC5C,OAAO;YACP,QAAQ;SACT,CAAC,CAA+B,CAAC;IACpC,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Validator } from './validator.js';\n\n/**\n * Constraint validation properties for a radio.\n */\nexport interface RadioState {\n /**\n * Whether the radio is checked.\n */\n readonly checked: boolean;\n\n /**\n * Whether the radio is required.\n */\n readonly required: boolean;\n}\n\n/**\n * Radio constraint validation properties for a single radio and its siblings.\n */\nexport type RadioGroupState = readonly [RadioState, ...RadioState[]];\n\n/**\n * A validator that provides constraint validation that emulates\n * `<input type=\"radio\">` validation.\n */\nexport class RadioValidator extends Validator<RadioGroupState> {\n private radioElement?: HTMLInputElement;\n\n protected override computeValidity(states: RadioGroupState) {\n if (!this.radioElement) {\n // Lazily create the radio element\n this.radioElement = document.createElement('input');\n this.radioElement.type = 'radio';\n // A name is required for validation to run\n this.radioElement.name = 'group';\n }\n\n let isRequired = false;\n let isChecked = false;\n for (const { checked, required } of states) {\n if (required) {\n isRequired = true;\n }\n\n if (checked) {\n isChecked = true;\n }\n }\n\n // Firefox v119 doesn't compute grouped radio validation correctly while\n // they are detached from the DOM, which is why we don't render multiple\n // virtual <input>s. Instead, we can check the required/checked states and\n // grab the i18n'd validation message if the value is missing.\n this.radioElement.checked = isChecked;\n this.radioElement.required = isRequired;\n return {\n validity: {\n valueMissing: isRequired && !isChecked,\n },\n validationMessage: this.radioElement.validationMessage,\n };\n }\n\n // eslint-disable-next-line class-methods-use-this\n protected override equals(\n prevGroup: RadioGroupState,\n nextGroup: RadioGroupState,\n ) {\n if (prevGroup.length !== nextGroup.length) {\n return false;\n }\n\n for (let i = 0; i < prevGroup.length; i++) {\n const prev = prevGroup[i];\n const next = nextGroup[i];\n if (prev.checked !== next.checked || prev.required !== next.required) {\n return false;\n }\n }\n\n return true;\n }\n\n // eslint-disable-next-line class-methods-use-this\n protected override copy(states: RadioGroupState): RadioGroupState {\n // Cast as unknown since typescript does not have enough information to\n // infer that the array always has at least one element.\n return states.map(({ checked, required }) => ({\n checked,\n required,\n })) as unknown as RadioGroupState;\n }\n}\n"]}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Validator } from './validator.js';
7
+ /**
8
+ * Constraint validation properties for a select dropdown.
9
+ */
10
+ export interface SelectState {
11
+ /**
12
+ * The current selected value.
13
+ */
14
+ readonly value: string;
15
+ /**
16
+ * Whether the select is required.
17
+ */
18
+ readonly required: boolean;
19
+ }
20
+ /**
21
+ * A validator that provides constraint validation that emulates `<select>`
22
+ * validation.
23
+ */
24
+ export declare class SelectValidator extends Validator<SelectState> {
25
+ private selectControl?;
26
+ protected computeValidity(state: SelectState): {
27
+ validity: ValidityState;
28
+ validationMessage: string;
29
+ };
30
+ protected equals(prev: SelectState, next: SelectState): boolean;
31
+ protected copy({ value, required }: SelectState): {
32
+ value: string;
33
+ required: boolean;
34
+ };
35
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { html, render } from 'lit';
7
+ import { Validator } from './validator.js';
8
+ /**
9
+ * A validator that provides constraint validation that emulates `<select>`
10
+ * validation.
11
+ */
12
+ export class SelectValidator extends Validator {
13
+ computeValidity(state) {
14
+ if (!this.selectControl) {
15
+ // Lazily create the platform select
16
+ this.selectControl = document.createElement('select');
17
+ }
18
+ render(html `<option value=${state.value}></option>`, this.selectControl);
19
+ this.selectControl.value = state.value;
20
+ this.selectControl.required = state.required;
21
+ return {
22
+ validity: this.selectControl.validity,
23
+ validationMessage: this.selectControl.validationMessage,
24
+ };
25
+ }
26
+ // eslint-disable-next-line class-methods-use-this
27
+ equals(prev, next) {
28
+ return prev.value === next.value && prev.required === next.required;
29
+ }
30
+ // eslint-disable-next-line class-methods-use-this
31
+ copy({ value, required }) {
32
+ return { value, required };
33
+ }
34
+ }
35
+ //# sourceMappingURL=select-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-validator.js","sourceRoot":"","sources":["select-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAiB3C;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAsB;IAGtC,eAAe,CAAC,KAAkB;QACnD,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,oCAAoC;YACpC,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACxD,CAAC;QAED,MAAM,CAAC,IAAI,CAAA,iBAAiB,KAAK,CAAC,KAAK,YAAY,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAEzE,IAAI,CAAC,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACvC,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC7C,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,aAAa,CAAC,QAAQ;YACrC,iBAAiB,EAAE,IAAI,CAAC,aAAa,CAAC,iBAAiB;SACxD,CAAC;IACJ,CAAC;IAED,kDAAkD;IAC/B,MAAM,CAAC,IAAiB,EAAE,IAAiB;QAC5D,OAAO,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,CAAC;IACtE,CAAC;IAED,kDAAkD;IAC/B,IAAI,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAe;QACtD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IAC7B,CAAC;CACF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { html, render } from 'lit';\n\nimport { Validator } from './validator.js';\n\n/**\n * Constraint validation properties for a select dropdown.\n */\nexport interface SelectState {\n /**\n * The current selected value.\n */\n readonly value: string;\n\n /**\n * Whether the select is required.\n */\n readonly required: boolean;\n}\n\n/**\n * A validator that provides constraint validation that emulates `<select>`\n * validation.\n */\nexport class SelectValidator extends Validator<SelectState> {\n private selectControl?: HTMLSelectElement;\n\n protected override computeValidity(state: SelectState) {\n if (!this.selectControl) {\n // Lazily create the platform select\n this.selectControl = document.createElement('select');\n }\n\n render(html`<option value=${state.value}></option>`, this.selectControl);\n\n this.selectControl.value = state.value;\n this.selectControl.required = state.required;\n return {\n validity: this.selectControl.validity,\n validationMessage: this.selectControl.validationMessage,\n };\n }\n\n // eslint-disable-next-line class-methods-use-this\n protected override equals(prev: SelectState, next: SelectState) {\n return prev.value === next.value && prev.required === next.required;\n }\n\n // eslint-disable-next-line class-methods-use-this\n protected override copy({ value, required }: SelectState) {\n return { value, required };\n }\n}\n"]}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Validator } from './validator.js';
7
+ /**
8
+ * Constraint validation for a text field.
9
+ */
10
+ export interface TextFieldState {
11
+ /**
12
+ * The input or textarea state to validate.
13
+ */
14
+ state: InputState | TextAreaState;
15
+ /**
16
+ * The `<input>` or `<textarea>` that is rendered on the page.
17
+ *
18
+ * `minlength` and `maxlength` validation do not apply until a user has
19
+ * interacted with the control and the element is internally marked as dirty.
20
+ * This is a spec quirk, the two properties behave differently from other
21
+ * constraint validation.
22
+ *
23
+ * This means we need an actual rendered element instead of a virtual one,
24
+ * since the virtual element will never be marked as dirty.
25
+ *
26
+ * This can be `null` if the element has not yet rendered, and the validator
27
+ * will fall back to virtual elements for other constraint validation
28
+ * properties, which do apply even if the control is not dirty.
29
+ */
30
+ renderedControl: HTMLInputElement | HTMLTextAreaElement | null;
31
+ }
32
+ /**
33
+ * Constraint validation properties for an `<input>`.
34
+ */
35
+ export interface InputState extends SharedInputAndTextAreaState {
36
+ /**
37
+ * The `<input>` type.
38
+ *
39
+ * Not all constraint validation properties apply to every type. See
40
+ * https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation#validation-related_attributes
41
+ * for which properties will apply to which types.
42
+ */
43
+ readonly type: string;
44
+ /**
45
+ * The regex pattern a value must match.
46
+ */
47
+ readonly pattern: string;
48
+ /**
49
+ * The minimum value.
50
+ */
51
+ readonly min: string;
52
+ /**
53
+ * The maximum value.
54
+ */
55
+ readonly max: string;
56
+ /**
57
+ * The step interval of the value.
58
+ */
59
+ readonly step: string;
60
+ }
61
+ /**
62
+ * Constraint validation properties for a `<textarea>`.
63
+ */
64
+ export interface TextAreaState extends SharedInputAndTextAreaState {
65
+ /**
66
+ * The type, must be "textarea" to inform the validator to use `<textarea>`
67
+ * instead of `<input>`.
68
+ */
69
+ readonly type: 'textarea';
70
+ }
71
+ /**
72
+ * Constraint validation properties shared between an `<input>` and
73
+ * `<textarea>`.
74
+ */
75
+ interface SharedInputAndTextAreaState {
76
+ /**
77
+ * The current value.
78
+ */
79
+ readonly value: string;
80
+ /**
81
+ * Whether the textarea is required.
82
+ */
83
+ readonly required: boolean;
84
+ /**
85
+ * The minimum length of the value.
86
+ */
87
+ readonly minLength: number;
88
+ /**
89
+ * The maximum length of the value.
90
+ */
91
+ readonly maxLength: number;
92
+ }
93
+ /**
94
+ * A validator that provides constraint validation that emulates `<input>` and
95
+ * `<textarea>` validation.
96
+ */
97
+ export declare class TextFieldValidator extends Validator<TextFieldState> {
98
+ private inputControl?;
99
+ private textAreaControl?;
100
+ protected computeValidity({ state, renderedControl, }: TextFieldState): {
101
+ validity: ValidityState;
102
+ validationMessage: string;
103
+ };
104
+ protected equals({ state: prev }: TextFieldState, { state: next }: TextFieldState): boolean;
105
+ protected copy({ state }: TextFieldState): TextFieldState;
106
+ private copyInput;
107
+ private copyTextArea;
108
+ private copySharedState;
109
+ }
110
+ export {};
@@ -0,0 +1,156 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Validator } from './validator.js';
7
+ /**
8
+ * A validator that provides constraint validation that emulates `<input>` and
9
+ * `<textarea>` validation.
10
+ */
11
+ export class TextFieldValidator extends Validator {
12
+ computeValidity({ state, renderedControl, }) {
13
+ let inputOrTextArea = renderedControl;
14
+ if (isInputState(state) && !inputOrTextArea) {
15
+ // Get cached <input> or create it.
16
+ inputOrTextArea = this.inputControl || document.createElement('input');
17
+ // Cache the <input> to re-use it next time.
18
+ this.inputControl = inputOrTextArea;
19
+ }
20
+ else if (!inputOrTextArea) {
21
+ // Get cached <textarea> or create it.
22
+ inputOrTextArea =
23
+ this.textAreaControl || document.createElement('textarea');
24
+ // Cache the <textarea> to re-use it next time.
25
+ this.textAreaControl = inputOrTextArea;
26
+ }
27
+ // Set this variable so we can check it for input-specific properties.
28
+ const input = isInputState(state)
29
+ ? inputOrTextArea
30
+ : null;
31
+ // Set input's "type" first, since this can change the other properties
32
+ if (input) {
33
+ input.type = state.type;
34
+ }
35
+ if (inputOrTextArea.value !== state.value) {
36
+ // Only programmatically set the value if there's a difference. When using
37
+ // the rendered control, the value will always be up to date. Setting the
38
+ // property (even if it's the same string) will reset the internal <input>
39
+ // dirty flag, making minlength and maxlength validation reset.
40
+ inputOrTextArea.value = state.value;
41
+ }
42
+ inputOrTextArea.required = state.required;
43
+ // The following IDLAttribute properties will always hydrate an attribute,
44
+ // even if set to a the default value ('' or -1). The presence of the
45
+ // attribute triggers constraint validation, so we must remove the attribute
46
+ // when empty.
47
+ if (input) {
48
+ const inputState = state;
49
+ if (inputState.pattern) {
50
+ input.pattern = inputState.pattern;
51
+ }
52
+ else {
53
+ input.removeAttribute('pattern');
54
+ }
55
+ if (inputState.min) {
56
+ input.min = inputState.min;
57
+ }
58
+ else {
59
+ input.removeAttribute('min');
60
+ }
61
+ if (inputState.max) {
62
+ input.max = inputState.max;
63
+ }
64
+ else {
65
+ input.removeAttribute('max');
66
+ }
67
+ if (inputState.step) {
68
+ input.step = inputState.step;
69
+ }
70
+ else {
71
+ input.removeAttribute('step');
72
+ }
73
+ }
74
+ // Use -1 to represent no minlength and maxlength, which is what the
75
+ // platform input returns. However, it will throw an error if you try to
76
+ // manually set it to -1.
77
+ //
78
+ // While the type is `number`, it may actually be `null` at runtime.
79
+ // `null > -1` is true since `null` coerces to `0`, so we default null and
80
+ // undefined to -1.
81
+ //
82
+ // We set attributes instead of properties since setting a property may
83
+ // throw an out of bounds error in relation to the other property.
84
+ // Attributes will not throw errors while the state is updating.
85
+ if ((state.minLength ?? -1) > -1) {
86
+ inputOrTextArea.setAttribute('minlength', String(state.minLength));
87
+ }
88
+ else {
89
+ inputOrTextArea.removeAttribute('minlength');
90
+ }
91
+ if ((state.maxLength ?? -1) > -1) {
92
+ inputOrTextArea.setAttribute('maxlength', String(state.maxLength));
93
+ }
94
+ else {
95
+ inputOrTextArea.removeAttribute('maxlength');
96
+ }
97
+ return {
98
+ validity: inputOrTextArea.validity,
99
+ validationMessage: inputOrTextArea.validationMessage,
100
+ };
101
+ }
102
+ // eslint-disable-next-line class-methods-use-this
103
+ equals({ state: prev }, { state: next }) {
104
+ // Check shared input and textarea properties
105
+ const inputOrTextAreaEqual = prev.type === next.type &&
106
+ prev.value === next.value &&
107
+ prev.required === next.required &&
108
+ prev.minLength === next.minLength &&
109
+ prev.maxLength === next.maxLength;
110
+ if (!isInputState(prev) || !isInputState(next)) {
111
+ // Both are textareas, all relevant properties are equal.
112
+ return inputOrTextAreaEqual;
113
+ }
114
+ // Check additional input-specific properties.
115
+ return (inputOrTextAreaEqual &&
116
+ prev.pattern === next.pattern &&
117
+ prev.min === next.min &&
118
+ prev.max === next.max &&
119
+ prev.step === next.step);
120
+ }
121
+ copy({ state }) {
122
+ // Don't hold a reference to the rendered control when copying since we
123
+ // don't use it when checking if the state changed.
124
+ return {
125
+ state: isInputState(state)
126
+ ? this.copyInput(state)
127
+ : this.copyTextArea(state),
128
+ renderedControl: null,
129
+ };
130
+ }
131
+ copyInput(state) {
132
+ const { type, pattern, min, max, step } = state;
133
+ return {
134
+ ...this.copySharedState(state),
135
+ type,
136
+ pattern,
137
+ min,
138
+ max,
139
+ step,
140
+ };
141
+ }
142
+ copyTextArea(state) {
143
+ return {
144
+ ...this.copySharedState(state),
145
+ type: state.type,
146
+ };
147
+ }
148
+ // eslint-disable-next-line class-methods-use-this
149
+ copySharedState({ value, required, minLength, maxLength, }) {
150
+ return { value, required, minLength, maxLength };
151
+ }
152
+ }
153
+ function isInputState(state) {
154
+ return state.type !== 'textarea';
155
+ }
156
+ //# sourceMappingURL=text-field-validator.js.map
@@ -0,0 +1 @@
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,uEAAuE;QACvE,mDAAmD;QACnD,OAAO;YACL,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC;gBACxB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;gBACvB,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;YAC5B,eAAe,EAAE,IAAI;SACtB,CAAC;IACJ,CAAC;IAEO,SAAS,CAAC,KAAiB;QACjC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;QAChD,OAAO;YACL,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC;YAC9B,IAAI;YACJ,OAAO;YACP,GAAG;YACH,GAAG;YACH,IAAI;SACL,CAAC;IACJ,CAAC;IAEO,YAAY,CAAC,KAAoB;QACvC,OAAO;YACL,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC;YAC9B,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB,CAAC;IACJ,CAAC;IAED,kDAAkD;IAC1C,eAAe,CAAC,EACtB,KAAK,EACL,QAAQ,EACR,SAAS,EACT,SAAS,GACmB;QAC5B,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;IACnD,CAAC;CACF;AAED,SAAS,YAAY,CAAC,KAAiC;IACrD,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;AACnC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Validator } from './validator.js';\n\n/**\n * Constraint validation for a text field.\n */\nexport interface TextFieldState {\n /**\n * The input or textarea state to validate.\n */\n state: InputState | TextAreaState;\n\n /**\n * The `<input>` or `<textarea>` that is rendered on the page.\n *\n * `minlength` and `maxlength` validation do not apply until a user has\n * interacted with the control and the element is internally marked as dirty.\n * This is a spec quirk, the two properties behave differently from other\n * constraint validation.\n *\n * This means we need an actual rendered element instead of a virtual one,\n * since the virtual element will never be marked as dirty.\n *\n * This can be `null` if the element has not yet rendered, and the validator\n * will fall back to virtual elements for other constraint validation\n * properties, which do apply even if the control is not dirty.\n */\n renderedControl: HTMLInputElement | HTMLTextAreaElement | null;\n}\n\n/**\n * Constraint validation properties for an `<input>`.\n */\nexport interface InputState extends SharedInputAndTextAreaState {\n /**\n * The `<input>` type.\n *\n * Not all constraint validation properties apply to every type. See\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation#validation-related_attributes\n * for which properties will apply to which types.\n */\n readonly type: string;\n\n /**\n * The regex pattern a value must match.\n */\n readonly pattern: string;\n\n /**\n * The minimum value.\n */\n readonly min: string;\n\n /**\n * The maximum value.\n */\n readonly max: string;\n\n /**\n * The step interval of the value.\n */\n readonly step: string;\n}\n\n/**\n * Constraint validation properties for a `<textarea>`.\n */\nexport interface TextAreaState extends SharedInputAndTextAreaState {\n /**\n * The type, must be \"textarea\" to inform the validator to use `<textarea>`\n * instead of `<input>`.\n */\n readonly type: 'textarea';\n}\n\n/**\n * Constraint validation properties shared between an `<input>` and\n * `<textarea>`.\n */\ninterface SharedInputAndTextAreaState {\n /**\n * The current value.\n */\n readonly value: string;\n\n /**\n * Whether the textarea is required.\n */\n readonly required: boolean;\n\n /**\n * The minimum length of the value.\n */\n readonly minLength: number;\n\n /**\n * The maximum length of the value.\n */\n readonly maxLength: number;\n}\n\n/**\n * A validator that provides constraint validation that emulates `<input>` and\n * `<textarea>` validation.\n */\nexport class TextFieldValidator extends Validator<TextFieldState> {\n private inputControl?: HTMLInputElement;\n private textAreaControl?: HTMLTextAreaElement;\n\n protected override computeValidity({\n state,\n renderedControl,\n }: TextFieldState) {\n let inputOrTextArea = renderedControl;\n if (isInputState(state) && !inputOrTextArea) {\n // Get cached <input> or create it.\n inputOrTextArea = this.inputControl || document.createElement('input');\n // Cache the <input> to re-use it next time.\n this.inputControl = inputOrTextArea;\n } else if (!inputOrTextArea) {\n // Get cached <textarea> or create it.\n inputOrTextArea =\n this.textAreaControl || document.createElement('textarea');\n // Cache the <textarea> to re-use it next time.\n this.textAreaControl = inputOrTextArea;\n }\n\n // Set this variable so we can check it for input-specific properties.\n const input = isInputState(state)\n ? (inputOrTextArea as HTMLInputElement)\n : null;\n\n // Set input's \"type\" first, since this can change the other properties\n if (input) {\n input.type = state.type;\n }\n\n if (inputOrTextArea.value !== state.value) {\n // Only programmatically set the value if there's a difference. When using\n // the rendered control, the value will always be up to date. Setting the\n // property (even if it's the same string) will reset the internal <input>\n // dirty flag, making minlength and maxlength validation reset.\n inputOrTextArea.value = state.value;\n }\n\n inputOrTextArea.required = state.required;\n\n // The following IDLAttribute properties will always hydrate an attribute,\n // even if set to a the default value ('' or -1). The presence of the\n // attribute triggers constraint validation, so we must remove the attribute\n // when empty.\n if (input) {\n const inputState = state as InputState;\n if (inputState.pattern) {\n input.pattern = inputState.pattern;\n } else {\n input.removeAttribute('pattern');\n }\n\n if (inputState.min) {\n input.min = inputState.min;\n } else {\n input.removeAttribute('min');\n }\n\n if (inputState.max) {\n input.max = inputState.max;\n } else {\n input.removeAttribute('max');\n }\n\n if (inputState.step) {\n input.step = inputState.step;\n } else {\n input.removeAttribute('step');\n }\n }\n\n // Use -1 to represent no minlength and maxlength, which is what the\n // platform input returns. However, it will throw an error if you try to\n // manually set it to -1.\n //\n // While the type is `number`, it may actually be `null` at runtime.\n // `null > -1` is true since `null` coerces to `0`, so we default null and\n // undefined to -1.\n //\n // We set attributes instead of properties since setting a property may\n // throw an out of bounds error in relation to the other property.\n // Attributes will not throw errors while the state is updating.\n if ((state.minLength ?? -1) > -1) {\n inputOrTextArea.setAttribute('minlength', String(state.minLength));\n } else {\n inputOrTextArea.removeAttribute('minlength');\n }\n\n if ((state.maxLength ?? -1) > -1) {\n inputOrTextArea.setAttribute('maxlength', String(state.maxLength));\n } else {\n inputOrTextArea.removeAttribute('maxlength');\n }\n\n return {\n validity: inputOrTextArea.validity,\n validationMessage: inputOrTextArea.validationMessage,\n };\n }\n\n // eslint-disable-next-line class-methods-use-this\n protected override equals(\n { state: prev }: TextFieldState,\n { state: next }: TextFieldState,\n ) {\n // Check shared input and textarea properties\n const inputOrTextAreaEqual =\n prev.type === next.type &&\n prev.value === next.value &&\n prev.required === next.required &&\n prev.minLength === next.minLength &&\n prev.maxLength === next.maxLength;\n\n if (!isInputState(prev) || !isInputState(next)) {\n // Both are textareas, all relevant properties are equal.\n return inputOrTextAreaEqual;\n }\n\n // Check additional input-specific properties.\n return (\n inputOrTextAreaEqual &&\n prev.pattern === next.pattern &&\n prev.min === next.min &&\n prev.max === next.max &&\n prev.step === next.step\n );\n }\n\n protected override copy({ state }: TextFieldState): TextFieldState {\n // Don't hold a reference to the rendered control when copying since we\n // don't use it when checking if the state changed.\n return {\n state: isInputState(state)\n ? this.copyInput(state)\n : this.copyTextArea(state),\n renderedControl: null,\n };\n }\n\n private copyInput(state: InputState): InputState {\n const { type, pattern, min, max, step } = state;\n return {\n ...this.copySharedState(state),\n type,\n pattern,\n min,\n max,\n step,\n };\n }\n\n private copyTextArea(state: TextAreaState): TextAreaState {\n return {\n ...this.copySharedState(state),\n type: state.type,\n };\n }\n\n // eslint-disable-next-line class-methods-use-this\n private copySharedState({\n value,\n required,\n minLength,\n maxLength,\n }: SharedInputAndTextAreaState): SharedInputAndTextAreaState {\n return { value, required, minLength, maxLength };\n }\n}\n\nfunction isInputState(state: InputState | TextAreaState): state is InputState {\n return state.type !== 'textarea';\n}\n"]}