@govtechsg/sgds-web-component 3.0.0-rc.1 → 3.0.0-rc.2

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 (478) hide show
  1. package/README.md +5 -5
  2. package/base/button.js +1 -1
  3. package/base/form-control-element.d.ts +4 -11
  4. package/base/form-control-element.js +13 -23
  5. package/base/form-control-element.js.map +1 -1
  6. package/components/Accordion/accordion-item.js +1 -1
  7. package/components/Accordion/index.umd.js +7 -19
  8. package/components/Accordion/index.umd.js.map +1 -1
  9. package/components/Accordion/sgds-accordion-item.d.ts +3 -7
  10. package/components/Accordion/sgds-accordion-item.js +6 -18
  11. package/components/Accordion/sgds-accordion-item.js.map +1 -1
  12. package/components/ActionCard/index.umd.js +407 -329
  13. package/components/ActionCard/index.umd.js.map +1 -1
  14. package/components/Alert/alert.js +1 -1
  15. package/components/Alert/index.umd.js +553 -485
  16. package/components/Alert/index.umd.js.map +1 -1
  17. package/components/Alert/sgds-alert.d.ts +2 -2
  18. package/components/Alert/sgds-alert.js +6 -13
  19. package/components/Alert/sgds-alert.js.map +1 -1
  20. package/components/Badge/badge.js +1 -1
  21. package/components/Badge/index.umd.js +8 -9
  22. package/components/Badge/index.umd.js.map +1 -1
  23. package/components/Badge/sgds-badge.d.ts +4 -5
  24. package/components/Badge/sgds-badge.js +5 -6
  25. package/components/Badge/sgds-badge.js.map +1 -1
  26. package/components/Button/index.umd.js +8 -81
  27. package/components/Button/index.umd.js.map +1 -1
  28. package/components/Button/sgds-button.js +1 -1
  29. package/components/Button/sgds-button.js.map +1 -1
  30. package/components/Checkbox/checkbox.js +1 -1
  31. package/components/Checkbox/index.umd.js +541 -475
  32. package/components/Checkbox/index.umd.js.map +1 -1
  33. package/components/Checkbox/sgds-checkbox-group.d.ts +7 -1
  34. package/components/Checkbox/sgds-checkbox-group.js +15 -4
  35. package/components/Checkbox/sgds-checkbox-group.js.map +1 -1
  36. package/components/Checkbox/sgds-checkbox.d.ts +30 -21
  37. package/components/Checkbox/sgds-checkbox.js +77 -60
  38. package/components/Checkbox/sgds-checkbox.js.map +1 -1
  39. package/components/ComboBox/index.umd.js +385 -216
  40. package/components/ComboBox/index.umd.js.map +1 -1
  41. package/components/Datepicker/datepicker-input.d.ts +4 -2
  42. package/components/Datepicker/datepicker-input.js +24 -7
  43. package/components/Datepicker/datepicker-input.js.map +1 -1
  44. package/components/Datepicker/index.umd.js +433 -244
  45. package/components/Datepicker/index.umd.js.map +1 -1
  46. package/components/Datepicker/sgds-datepicker.d.ts +1 -1
  47. package/components/Datepicker/sgds-datepicker.js.map +1 -1
  48. package/components/Drawer/index.umd.js +2 -2
  49. package/components/Drawer/index.umd.js.map +1 -1
  50. package/components/Dropdown/index.umd.js +8 -81
  51. package/components/Dropdown/index.umd.js.map +1 -1
  52. package/components/FileUpload/file-upload.js +1 -1
  53. package/components/FileUpload/index.umd.js +579 -272
  54. package/components/FileUpload/index.umd.js.map +1 -1
  55. package/components/FileUpload/sgds-file-upload.d.ts +42 -30
  56. package/components/FileUpload/sgds-file-upload.js +147 -103
  57. package/components/FileUpload/sgds-file-upload.js.map +1 -1
  58. package/components/Footer/footer-item.js +6 -0
  59. package/components/Footer/footer-item.js.map +1 -0
  60. package/components/Footer/footer.js +1 -1
  61. package/components/Footer/index.d.ts +2 -0
  62. package/components/Footer/index.js +2 -0
  63. package/components/Footer/index.js.map +1 -1
  64. package/components/Footer/index.umd.js +93 -94
  65. package/components/Footer/index.umd.js.map +1 -1
  66. package/components/Footer/sgds-footer-item.d.ts +13 -0
  67. package/components/Footer/sgds-footer-item.js +27 -0
  68. package/components/Footer/sgds-footer-item.js.map +1 -0
  69. package/components/Footer/sgds-footer.d.ts +9 -30
  70. package/components/Footer/sgds-footer.js +65 -90
  71. package/components/Footer/sgds-footer.js.map +1 -1
  72. package/components/Icon/icon.js +6 -0
  73. package/components/Icon/icon.js.map +1 -0
  74. package/components/Icon/index.d.ts +6 -0
  75. package/components/Icon/index.js +4 -0
  76. package/components/Icon/index.js.map +1 -0
  77. package/components/Icon/index.umd.js +4389 -0
  78. package/components/Icon/index.umd.js.map +1 -0
  79. package/components/Icon/sgds-icon.d.ts +21 -0
  80. package/components/Icon/sgds-icon.js +64 -0
  81. package/components/Icon/sgds-icon.js.map +1 -0
  82. package/components/IconButton/icon-button.js +1 -1
  83. package/components/IconButton/index.umd.js +6 -9
  84. package/components/IconButton/index.umd.js.map +1 -1
  85. package/components/IconButton/sgds-icon-button.d.ts +2 -2
  86. package/components/IconButton/sgds-icon-button.js +4 -9
  87. package/components/IconButton/sgds-icon-button.js.map +1 -1
  88. package/components/Input/index.umd.js +1734 -1376
  89. package/components/Input/index.umd.js.map +1 -1
  90. package/components/Input/sgds-input.d.ts +41 -21
  91. package/components/Input/sgds-input.js +103 -66
  92. package/components/Input/sgds-input.js.map +1 -1
  93. package/components/Modal/index.umd.js +2 -2
  94. package/components/Modal/index.umd.js.map +1 -1
  95. package/components/QuantityToggle/index.umd.js +894 -316
  96. package/components/QuantityToggle/index.umd.js.map +1 -1
  97. package/components/QuantityToggle/sgds-quantity-toggle.d.ts +42 -15
  98. package/components/QuantityToggle/sgds-quantity-toggle.js +129 -62
  99. package/components/QuantityToggle/sgds-quantity-toggle.js.map +1 -1
  100. package/components/Radio/index.umd.js +516 -203
  101. package/components/Radio/index.umd.js.map +1 -1
  102. package/components/Radio/sgds-radio-group.d.ts +38 -27
  103. package/components/Radio/sgds-radio-group.js +100 -84
  104. package/components/Radio/sgds-radio-group.js.map +1 -1
  105. package/components/Radio/sgds-radio.js +1 -1
  106. package/components/Radio/sgds-radio.js.map +1 -1
  107. package/components/Stepper/index.umd.js +1 -0
  108. package/components/Stepper/index.umd.js.map +1 -1
  109. package/components/Stepper/sgds-stepper.d.ts +1 -0
  110. package/components/Stepper/sgds-stepper.js +1 -0
  111. package/components/Stepper/sgds-stepper.js.map +1 -1
  112. package/components/Switch/index.umd.js +21 -321
  113. package/components/Switch/index.umd.js.map +1 -1
  114. package/components/Switch/sgds-switch.js +1 -2
  115. package/components/Switch/sgds-switch.js.map +1 -1
  116. package/components/Textarea/index.umd.js +1554 -1336
  117. package/components/Textarea/index.umd.js.map +1 -1
  118. package/components/Textarea/sgds-textarea.d.ts +33 -22
  119. package/components/Textarea/sgds-textarea.js +78 -75
  120. package/components/Textarea/sgds-textarea.js.map +1 -1
  121. package/components/Textarea/textarea.js +1 -1
  122. package/components/Toast/index.umd.js +9 -21
  123. package/components/Toast/index.umd.js.map +1 -1
  124. package/components/Toast/sgds-toast.d.ts +2 -1
  125. package/components/Toast/sgds-toast.js +6 -18
  126. package/components/Toast/sgds-toast.js.map +1 -1
  127. package/components/Toast/toast.js +1 -1
  128. package/components/Tooltip/index.umd.js +14 -14
  129. package/components/Tooltip/index.umd.js.map +1 -1
  130. package/components/Tooltip/sgds-tooltip.d.ts +4 -7
  131. package/components/Tooltip/sgds-tooltip.js +14 -14
  132. package/components/Tooltip/sgds-tooltip.js.map +1 -1
  133. package/components/index.d.ts +1 -0
  134. package/components/index.js +1 -0
  135. package/components/index.js.map +1 -1
  136. package/components/index.umd.js +1318 -1124
  137. package/components/index.umd.js.map +1 -1
  138. package/icons/arrow-bar-down.svg +3 -0
  139. package/icons/arrow-bar-left.svg +3 -0
  140. package/icons/arrow-bar-right.svg +3 -0
  141. package/icons/arrow-bar-up.svg +3 -0
  142. package/icons/arrow-clockwise.svg +3 -0
  143. package/icons/arrow-down.svg +3 -0
  144. package/icons/arrow-left.svg +3 -0
  145. package/icons/arrow-repeat.svg +3 -0
  146. package/icons/arrow-right.svg +3 -0
  147. package/icons/arrow-up.svg +3 -0
  148. package/icons/bank-fill.svg +3 -0
  149. package/icons/bell-slash.svg +3 -0
  150. package/icons/bell.svg +3 -0
  151. package/icons/bi-funnel.svg +3 -0
  152. package/icons/bookmark-fill.svg +3 -0
  153. package/icons/bookmark.svg +3 -0
  154. package/icons/box-arrow-up-right.svg +3 -0
  155. package/icons/box-seam.svg +3 -0
  156. package/icons/building.svg +3 -0
  157. package/icons/calculator.svg +3 -0
  158. package/icons/calendar-check.svg +4 -0
  159. package/icons/calendar-x.svg +4 -0
  160. package/icons/calendar.svg +3 -0
  161. package/icons/camera.svg +3 -0
  162. package/icons/chat-left-text.svg +3 -0
  163. package/icons/check-circle-fill.svg +3 -0
  164. package/icons/check-circle.svg +3 -0
  165. package/icons/check.svg +3 -0
  166. package/icons/chevron-down.svg +3 -0
  167. package/icons/chevron-left.svg +3 -0
  168. package/icons/chevron-right.svg +3 -0
  169. package/icons/chevron-up .svg +3 -0
  170. package/icons/clock.svg +4 -0
  171. package/icons/cloud-check.svg +4 -0
  172. package/icons/cloud-download.svg +3 -0
  173. package/icons/cloud-upload.svg +3 -0
  174. package/icons/cloud.svg +3 -0
  175. package/icons/compass.svg +4 -0
  176. package/icons/cross.svg +3 -0
  177. package/icons/cursor-fill.svg +3 -0
  178. package/icons/cursor.svg +3 -0
  179. package/icons/dash-circle.svg +3 -0
  180. package/icons/dash-square.svg +3 -0
  181. package/icons/dash.svg +3 -0
  182. package/icons/download.svg +3 -0
  183. package/icons/exclamation-circle-fill.svg +3 -0
  184. package/icons/exclamation-circle.svg +4 -0
  185. package/icons/exclamation-triangle-fill.svg +3 -0
  186. package/icons/exclamation-triangle.svg +4 -0
  187. package/icons/exclamation.svg +4 -0
  188. package/icons/eye-fill.svg +3 -0
  189. package/icons/eye-slash-fill.svg +4 -0
  190. package/icons/eye-slash.svg +3 -0
  191. package/icons/eye.svg +3 -0
  192. package/icons/facebook.svg +3 -0
  193. package/icons/file-earmark-text.svg +3 -0
  194. package/icons/file-pdf.svg +4 -0
  195. package/icons/file-plus.svg +4 -0
  196. package/icons/file-text.svg +3 -0
  197. package/icons/file.svg +3 -0
  198. package/icons/files.svg +4 -0
  199. package/icons/folder-check.svg +4 -0
  200. package/icons/folder-minus.svg +4 -0
  201. package/icons/folder-plus.svg +4 -0
  202. package/icons/folder.svg +3 -0
  203. package/icons/gear.svg +3 -0
  204. package/icons/geo-alt.svg +4 -0
  205. package/icons/geo-fill.svg +4 -0
  206. package/icons/geo.svg +4 -0
  207. package/icons/google.svg +3 -0
  208. package/icons/grid-fill.svg +3 -0
  209. package/icons/hand-thumbs-down.svg +3 -0
  210. package/icons/hand-thumbs-up.svg +3 -0
  211. package/icons/hdd.svg +3 -0
  212. package/icons/house-door.svg +3 -0
  213. package/icons/house.svg +3 -0
  214. package/icons/image.svg +3 -0
  215. package/icons/inbox.svg +3 -0
  216. package/icons/info-circle-fill.svg +3 -0
  217. package/icons/info-circle.svg +4 -0
  218. package/icons/instagram.svg +3 -0
  219. package/icons/layers.svg +3 -0
  220. package/icons/layout-text-window-reverse.svg +3 -0
  221. package/icons/layout-text-window.svg +3 -0
  222. package/icons/layout.svg +3 -0
  223. package/icons/link.svg +3 -0
  224. package/icons/linkedin.svg +3 -0
  225. package/icons/list.svg +3 -0
  226. package/icons/lock-fill.svg +3 -0
  227. package/icons/lock.svg +3 -0
  228. package/icons/mail.svg +3 -0
  229. package/icons/map.svg +3 -0
  230. package/icons/paperclip.svg +3 -0
  231. package/icons/pencil.svg +3 -0
  232. package/icons/pending-circle.svg +3 -0
  233. package/icons/person-dash.svg +3 -0
  234. package/icons/person-plus.svg +3 -0
  235. package/icons/person-x.svg +3 -0
  236. package/icons/person.svg +3 -0
  237. package/icons/pin-map-fill.svg +3 -0
  238. package/icons/pin.svg +3 -0
  239. package/icons/placeholder.svg +3 -0
  240. package/icons/plus-circle.svg +3 -0
  241. package/icons/plus-square.svg +3 -0
  242. package/icons/plus.svg +3 -0
  243. package/icons/printer.svg +3 -0
  244. package/icons/question-circle.svg +4 -0
  245. package/icons/save.svg +3 -0
  246. package/icons/search.svg +3 -0
  247. package/icons/share.svg +3 -0
  248. package/icons/slash-circle.svg +3 -0
  249. package/icons/sliders.svg +3 -0
  250. package/icons/speedometer.svg +3 -0
  251. package/icons/star-fill.svg +3 -0
  252. package/icons/star.svg +3 -0
  253. package/icons/stoplights.svg +4 -0
  254. package/icons/telephone.svg +3 -0
  255. package/icons/three-dots-vertical.svg +3 -0
  256. package/icons/three-dots.svg +3 -0
  257. package/icons/toggle-off.svg +3 -0
  258. package/icons/toggle-on.svg +3 -0
  259. package/icons/trash.svg +3 -0
  260. package/icons/twitter-x.svg +3 -0
  261. package/icons/unlock.svg +3 -0
  262. package/icons/upload.svg +3 -0
  263. package/icons/window-dash.svg +4 -0
  264. package/icons/window-desktop.svg +4 -0
  265. package/icons/window-dock.svg +4 -0
  266. package/icons/window-fullscreen.svg +3 -0
  267. package/icons/window-plus.svg +4 -0
  268. package/icons/window-sidebar.svg +3 -0
  269. package/icons/window-split.svg +3 -0
  270. package/icons/window-stack.svg +3 -0
  271. package/icons/window-x.svg +4 -0
  272. package/icons/window.svg +3 -0
  273. package/icons/x-circle-fill.svg +3 -0
  274. package/icons/x-circle.svg +3 -0
  275. package/icons/youtube.svg +3 -0
  276. package/icons/zoom-in.svg +3 -0
  277. package/icons/zoom-out.svg +3 -0
  278. package/index.d.ts +1 -0
  279. package/index.js +1 -0
  280. package/index.js.map +1 -1
  281. package/index.umd.js +1338 -1119
  282. package/index.umd.js.map +1 -1
  283. package/internals/CloseButton/close-button.js +1 -1
  284. package/internals/CloseButton/sgds-close-button.js +1 -1
  285. package/internals/CloseButton/sgds-close-button.js.map +1 -1
  286. package/package.json +1 -1
  287. package/react/base/button.cjs.js +1 -1
  288. package/react/base/button.js +1 -1
  289. package/react/base/form-control-element.cjs.js +13 -23
  290. package/react/base/form-control-element.cjs.js.map +1 -1
  291. package/react/base/form-control-element.js +13 -23
  292. package/react/base/form-control-element.js.map +1 -1
  293. package/react/checkbox/index.cjs.js +2 -0
  294. package/react/checkbox/index.cjs.js.map +1 -1
  295. package/react/checkbox/index.d.ts +2 -0
  296. package/react/checkbox/index.js +2 -0
  297. package/react/checkbox/index.js.map +1 -1
  298. package/react/components/Accordion/accordion-item.cjs.js +1 -1
  299. package/react/components/Accordion/accordion-item.js +1 -1
  300. package/react/components/Accordion/sgds-accordion-item.cjs.js +6 -18
  301. package/react/components/Accordion/sgds-accordion-item.cjs.js.map +1 -1
  302. package/react/components/Accordion/sgds-accordion-item.js +6 -18
  303. package/react/components/Accordion/sgds-accordion-item.js.map +1 -1
  304. package/react/components/Alert/alert.cjs.js +1 -1
  305. package/react/components/Alert/alert.js +1 -1
  306. package/react/components/Alert/sgds-alert.cjs.js +5 -12
  307. package/react/components/Alert/sgds-alert.cjs.js.map +1 -1
  308. package/react/components/Alert/sgds-alert.js +6 -13
  309. package/react/components/Alert/sgds-alert.js.map +1 -1
  310. package/react/components/Badge/badge.cjs.js +1 -1
  311. package/react/components/Badge/badge.js +1 -1
  312. package/react/components/Badge/sgds-badge.cjs.js +5 -6
  313. package/react/components/Badge/sgds-badge.cjs.js.map +1 -1
  314. package/react/components/Badge/sgds-badge.js +5 -6
  315. package/react/components/Badge/sgds-badge.js.map +1 -1
  316. package/react/components/Button/sgds-button.cjs.js +2 -2
  317. package/react/components/Button/sgds-button.cjs.js.map +1 -1
  318. package/react/components/Button/sgds-button.js +1 -1
  319. package/react/components/Button/sgds-button.js.map +1 -1
  320. package/react/components/Checkbox/checkbox.cjs.js +1 -1
  321. package/react/components/Checkbox/checkbox.js +1 -1
  322. package/react/components/Checkbox/sgds-checkbox-group.cjs.js +15 -4
  323. package/react/components/Checkbox/sgds-checkbox-group.cjs.js.map +1 -1
  324. package/react/components/Checkbox/sgds-checkbox-group.js +15 -4
  325. package/react/components/Checkbox/sgds-checkbox-group.js.map +1 -1
  326. package/react/components/Checkbox/sgds-checkbox.cjs.js +77 -60
  327. package/react/components/Checkbox/sgds-checkbox.cjs.js.map +1 -1
  328. package/react/components/Checkbox/sgds-checkbox.js +77 -60
  329. package/react/components/Checkbox/sgds-checkbox.js.map +1 -1
  330. package/react/components/Datepicker/datepicker-input.cjs.js +24 -7
  331. package/react/components/Datepicker/datepicker-input.cjs.js.map +1 -1
  332. package/react/components/Datepicker/datepicker-input.js +24 -7
  333. package/react/components/Datepicker/datepicker-input.js.map +1 -1
  334. package/react/components/Datepicker/sgds-datepicker.cjs.js.map +1 -1
  335. package/react/components/Datepicker/sgds-datepicker.js.map +1 -1
  336. package/react/components/FileUpload/file-upload.cjs.js +1 -1
  337. package/react/components/FileUpload/file-upload.js +1 -1
  338. package/react/components/FileUpload/sgds-file-upload.cjs.js +145 -101
  339. package/react/components/FileUpload/sgds-file-upload.cjs.js.map +1 -1
  340. package/react/components/FileUpload/sgds-file-upload.js +147 -103
  341. package/react/components/FileUpload/sgds-file-upload.js.map +1 -1
  342. package/react/components/Footer/footer-item.cjs.js +11 -0
  343. package/react/components/Footer/footer-item.cjs.js.map +1 -0
  344. package/react/components/Footer/footer-item.js +7 -0
  345. package/react/components/Footer/footer-item.js.map +1 -0
  346. package/react/components/Footer/footer.cjs.js +1 -1
  347. package/react/components/Footer/footer.js +1 -1
  348. package/react/components/Footer/sgds-footer-item.cjs.js +33 -0
  349. package/react/components/Footer/sgds-footer-item.cjs.js.map +1 -0
  350. package/react/components/Footer/sgds-footer-item.js +28 -0
  351. package/react/components/Footer/sgds-footer-item.js.map +1 -0
  352. package/react/components/Footer/sgds-footer.cjs.js +65 -90
  353. package/react/components/Footer/sgds-footer.cjs.js.map +1 -1
  354. package/react/components/Footer/sgds-footer.js +65 -90
  355. package/react/components/Footer/sgds-footer.js.map +1 -1
  356. package/react/components/Icon/icon.cjs.js +11 -0
  357. package/react/components/Icon/icon.cjs.js.map +1 -0
  358. package/react/components/Icon/icon.js +7 -0
  359. package/react/components/Icon/icon.js.map +1 -0
  360. package/react/components/Icon/sgds-icon.cjs.js +70 -0
  361. package/react/components/Icon/sgds-icon.cjs.js.map +1 -0
  362. package/react/components/Icon/sgds-icon.js +65 -0
  363. package/react/components/Icon/sgds-icon.js.map +1 -0
  364. package/react/components/IconButton/icon-button.cjs.js +1 -1
  365. package/react/components/IconButton/icon-button.js +1 -1
  366. package/react/components/IconButton/sgds-icon-button.cjs.js +4 -9
  367. package/react/components/IconButton/sgds-icon-button.cjs.js.map +1 -1
  368. package/react/components/IconButton/sgds-icon-button.js +4 -9
  369. package/react/components/IconButton/sgds-icon-button.js.map +1 -1
  370. package/react/components/Input/sgds-input.cjs.js +101 -64
  371. package/react/components/Input/sgds-input.cjs.js.map +1 -1
  372. package/react/components/Input/sgds-input.js +103 -66
  373. package/react/components/Input/sgds-input.js.map +1 -1
  374. package/react/components/QuantityToggle/sgds-quantity-toggle.cjs.js +128 -61
  375. package/react/components/QuantityToggle/sgds-quantity-toggle.cjs.js.map +1 -1
  376. package/react/components/QuantityToggle/sgds-quantity-toggle.js +129 -62
  377. package/react/components/QuantityToggle/sgds-quantity-toggle.js.map +1 -1
  378. package/react/components/Radio/sgds-radio-group.cjs.js +99 -83
  379. package/react/components/Radio/sgds-radio-group.cjs.js.map +1 -1
  380. package/react/components/Radio/sgds-radio-group.js +100 -84
  381. package/react/components/Radio/sgds-radio-group.js.map +1 -1
  382. package/react/components/Radio/sgds-radio.cjs.js +1 -1
  383. package/react/components/Radio/sgds-radio.cjs.js.map +1 -1
  384. package/react/components/Radio/sgds-radio.js +1 -1
  385. package/react/components/Radio/sgds-radio.js.map +1 -1
  386. package/react/components/Stepper/sgds-stepper.cjs.js +1 -0
  387. package/react/components/Stepper/sgds-stepper.cjs.js.map +1 -1
  388. package/react/components/Stepper/sgds-stepper.js +1 -0
  389. package/react/components/Stepper/sgds-stepper.js.map +1 -1
  390. package/react/components/Switch/sgds-switch.cjs.js +1 -2
  391. package/react/components/Switch/sgds-switch.cjs.js.map +1 -1
  392. package/react/components/Switch/sgds-switch.js +1 -2
  393. package/react/components/Switch/sgds-switch.js.map +1 -1
  394. package/react/components/Textarea/sgds-textarea.cjs.js +76 -73
  395. package/react/components/Textarea/sgds-textarea.cjs.js.map +1 -1
  396. package/react/components/Textarea/sgds-textarea.js +78 -75
  397. package/react/components/Textarea/sgds-textarea.js.map +1 -1
  398. package/react/components/Textarea/textarea.cjs.js +1 -1
  399. package/react/components/Textarea/textarea.js +1 -1
  400. package/react/components/Toast/sgds-toast.cjs.js +6 -18
  401. package/react/components/Toast/sgds-toast.cjs.js.map +1 -1
  402. package/react/components/Toast/sgds-toast.js +6 -18
  403. package/react/components/Toast/sgds-toast.js.map +1 -1
  404. package/react/components/Toast/toast.cjs.js +1 -1
  405. package/react/components/Toast/toast.js +1 -1
  406. package/react/components/Tooltip/sgds-tooltip.cjs.js +14 -14
  407. package/react/components/Tooltip/sgds-tooltip.cjs.js.map +1 -1
  408. package/react/components/Tooltip/sgds-tooltip.js +14 -14
  409. package/react/components/Tooltip/sgds-tooltip.js.map +1 -1
  410. package/react/footer-item/index.cjs.js +39 -0
  411. package/react/footer-item/index.cjs.js.map +1 -0
  412. package/react/footer-item/index.d.ts +3 -0
  413. package/react/footer-item/index.js +15 -0
  414. package/react/footer-item/index.js.map +1 -0
  415. package/react/icon/index.cjs.js +42 -0
  416. package/react/icon/index.cjs.js.map +1 -0
  417. package/react/icon/index.d.ts +6 -0
  418. package/react/icon/index.js +18 -0
  419. package/react/icon/index.js.map +1 -0
  420. package/react/index.cjs.js +64 -60
  421. package/react/index.cjs.js.map +1 -1
  422. package/react/index.d.ts +2 -0
  423. package/react/index.js +2 -0
  424. package/react/index.js.map +1 -1
  425. package/react/input/index.cjs.js +3 -1
  426. package/react/input/index.cjs.js.map +1 -1
  427. package/react/input/index.d.ts +2 -0
  428. package/react/input/index.js +3 -1
  429. package/react/input/index.js.map +1 -1
  430. package/react/internals/CloseButton/close-button.cjs.js +1 -1
  431. package/react/internals/CloseButton/close-button.js +1 -1
  432. package/react/internals/CloseButton/sgds-close-button.cjs.js +1 -1
  433. package/react/internals/CloseButton/sgds-close-button.cjs.js.map +1 -1
  434. package/react/internals/CloseButton/sgds-close-button.js +1 -1
  435. package/react/internals/CloseButton/sgds-close-button.js.map +1 -1
  436. package/react/styles/form-hint.cjs.js +1 -1
  437. package/react/styles/form-hint.js +1 -1
  438. package/react/styles/form-label.cjs.js +1 -1
  439. package/react/styles/form-label.js +1 -1
  440. package/react/utils/formSubmitController.cjs.js +64 -0
  441. package/react/utils/formSubmitController.cjs.js.map +1 -0
  442. package/react/utils/formSubmitController.js +60 -0
  443. package/react/utils/formSubmitController.js.map +1 -0
  444. package/react/utils/inputValidationController.cjs.js +130 -0
  445. package/react/utils/inputValidationController.cjs.js.map +1 -0
  446. package/react/utils/inputValidationController.js +126 -0
  447. package/react/utils/inputValidationController.js.map +1 -0
  448. package/react/utils/validatorMixin.cjs.js +108 -0
  449. package/react/utils/validatorMixin.cjs.js.map +1 -0
  450. package/react/utils/validatorMixin.js +104 -0
  451. package/react/utils/validatorMixin.js.map +1 -0
  452. package/styles/form-hint.js +1 -1
  453. package/styles/form-label.js +1 -1
  454. package/themes/day.css +1 -1
  455. package/themes/night.css +3 -2
  456. package/themes/root.css +1 -0
  457. package/utils/{form.d.ts → formSubmitController.d.ts} +10 -20
  458. package/utils/formSubmitController.js +59 -0
  459. package/utils/formSubmitController.js.map +1 -0
  460. package/utils/inputValidationController.d.ts +70 -0
  461. package/utils/inputValidationController.js +125 -0
  462. package/utils/inputValidationController.js.map +1 -0
  463. package/utils/validatorMixin.d.ts +24 -0
  464. package/utils/validatorMixin.js +103 -0
  465. package/utils/validatorMixin.js.map +1 -0
  466. package/base/form-check-element.d.ts +0 -50
  467. package/base/form-check-element.js +0 -169
  468. package/base/form-check-element.js.map +0 -1
  469. package/react/base/form-check-element.cjs.js +0 -175
  470. package/react/base/form-check-element.cjs.js.map +0 -1
  471. package/react/base/form-check-element.js +0 -170
  472. package/react/base/form-check-element.js.map +0 -1
  473. package/react/utils/form.cjs.js +0 -137
  474. package/react/utils/form.cjs.js.map +0 -1
  475. package/react/utils/form.js +0 -133
  476. package/react/utils/form.js.map +0 -1
  477. package/utils/form.js +0 -132
  478. package/utils/form.js.map +0 -1
@@ -1197,421 +1197,147 @@
1197
1197
  * Copyright 2017 Google LLC
1198
1198
  * SPDX-License-Identifier: BSD-3-Clause
1199
1199
  */
1200
+ // Allows minifiers to rename references to globalThis
1201
+ const global$2 = globalThis;
1202
+ /**
1203
+ * Useful for visualizing and logging insights into what the Lit template system is doing.
1204
+ *
1205
+ * Compiled out of prod mode builds.
1206
+ */
1207
+ const debugLogEvent$1 = (event) => {
1208
+ const shouldEmit = global$2
1209
+ .emitLitDebugLogEvents;
1210
+ if (!shouldEmit) {
1211
+ return;
1212
+ }
1213
+ global$2.dispatchEvent(new CustomEvent('lit-debug', {
1214
+ detail: event,
1215
+ }));
1216
+ }
1217
+ ;
1218
+ // Used for connecting beginRender and endRender events when there are nested
1219
+ // renders when errors are thrown preventing an endRender event from being
1220
+ // called.
1221
+ let debugLogRenderId = 0;
1200
1222
  let issueWarning$4;
1201
1223
  {
1202
- // Ensure warnings are issued only 1x, even if multiple versions of Lit
1203
- // are loaded.
1204
- const issuedWarnings = (globalThis.litIssuedWarnings ??= new Set());
1224
+ global$2.litIssuedWarnings ??= new Set();
1205
1225
  // Issue a warning, if we haven't already.
1206
1226
  issueWarning$4 = (code, warning) => {
1207
- warning += ` See https://lit.dev/msg/${code} for more information.`;
1208
- if (!issuedWarnings.has(warning)) {
1227
+ warning += code
1228
+ ? ` See https://lit.dev/msg/${code} for more information.`
1229
+ : '';
1230
+ if (!global$2.litIssuedWarnings.has(warning)) {
1209
1231
  console.warn(warning);
1210
- issuedWarnings.add(warning);
1232
+ global$2.litIssuedWarnings.add(warning);
1211
1233
  }
1212
1234
  };
1235
+ issueWarning$4('dev-mode', `Lit is in dev mode. Not recommended for production!`);
1213
1236
  }
1214
- const legacyProperty = (options, proto, name) => {
1215
- const hasOwnProperty = proto.hasOwnProperty(name);
1216
- proto.constructor.createProperty(name, hasOwnProperty ? { ...options, wrapped: true } : options);
1217
- // For accessors (which have a descriptor on the prototype) we need to
1218
- // return a descriptor, otherwise TypeScript overwrites the descriptor we
1219
- // define in createProperty() with the original descriptor. We don't do this
1220
- // for fields, which don't have a descriptor, because this could overwrite
1221
- // descriptor defined by other decorators.
1222
- return hasOwnProperty
1223
- ? Object.getOwnPropertyDescriptor(proto, name)
1224
- : undefined;
1225
- };
1226
- // This is duplicated from a similar variable in reactive-element.ts, but
1227
- // actually makes sense to have this default defined with the decorator, so
1228
- // that different decorators could have different defaults.
1229
- const defaultPropertyDeclaration$1 = {
1230
- attribute: true,
1231
- type: String,
1232
- converter: defaultConverter$1,
1233
- reflect: false,
1234
- hasChanged: notEqual$1,
1235
- };
1237
+ const wrap = global$2.ShadyDOM?.inUse &&
1238
+ global$2.ShadyDOM?.noPatch === true
1239
+ ? global$2.ShadyDOM.wrap
1240
+ : (node) => node;
1241
+ const trustedTypes$1 = global$2.trustedTypes;
1236
1242
  /**
1237
- * Wraps a class accessor or setter so that `requestUpdate()` is called with the
1238
- * property name and old value when the accessor is set.
1243
+ * Our TrustedTypePolicy for HTML which is declared using the html template
1244
+ * tag function.
1245
+ *
1246
+ * That HTML is a developer-authored constant, and is parsed with innerHTML
1247
+ * before any untrusted expressions have been mixed in. Therefor it is
1248
+ * considered safe by construction.
1239
1249
  */
1240
- const standardProperty = (options = defaultPropertyDeclaration$1, target, context) => {
1241
- const { kind, metadata } = context;
1242
- if (metadata == null) {
1243
- issueWarning$4('missing-class-metadata', `The class ${target} is missing decorator metadata. This ` +
1244
- `could mean that you're using a compiler that supports decorators ` +
1245
- `but doesn't support decorator metadata, such as TypeScript 5.1. ` +
1246
- `Please update your compiler.`);
1247
- }
1248
- // Store the property options
1249
- let properties = globalThis.litPropertyMetadata.get(metadata);
1250
- if (properties === undefined) {
1251
- globalThis.litPropertyMetadata.set(metadata, (properties = new Map()));
1252
- }
1253
- properties.set(context.name, options);
1254
- if (kind === 'accessor') {
1255
- // Standard decorators cannot dynamically modify the class, so we can't
1256
- // replace a field with accessors. The user must use the new `accessor`
1257
- // keyword instead.
1258
- const { name } = context;
1259
- return {
1260
- set(v) {
1261
- const oldValue = target.get.call(this);
1262
- target.set.call(this, v);
1263
- this.requestUpdate(name, oldValue, options);
1264
- },
1265
- init(v) {
1266
- if (v !== undefined) {
1267
- this._$changeProperty(name, undefined, options);
1268
- }
1269
- return v;
1270
- },
1271
- };
1272
- }
1273
- else if (kind === 'setter') {
1274
- const { name } = context;
1275
- return function (value) {
1276
- const oldValue = this[name];
1277
- target.call(this, value);
1278
- this.requestUpdate(name, oldValue, options);
1279
- };
1250
+ const policy = trustedTypes$1
1251
+ ? trustedTypes$1.createPolicy('lit-html', {
1252
+ createHTML: (s) => s,
1253
+ })
1254
+ : undefined;
1255
+ const identityFunction = (value) => value;
1256
+ const noopSanitizer = (_node, _name, _type) => identityFunction;
1257
+ /** Sets the global sanitizer factory. */
1258
+ const setSanitizer = (newSanitizer) => {
1259
+ if (sanitizerFactoryInternal !== noopSanitizer) {
1260
+ throw new Error(`Attempted to overwrite existing lit-html security policy.` +
1261
+ ` setSanitizeDOMValueFactory should be called at most once.`);
1280
1262
  }
1281
- throw new Error(`Unsupported decorator location: ${kind}`);
1263
+ sanitizerFactoryInternal = newSanitizer;
1282
1264
  };
1283
1265
  /**
1284
- * A class field or accessor decorator which creates a reactive property that
1285
- * reflects a corresponding attribute value. When a decorated property is set
1286
- * the element will update and render. A {@linkcode PropertyDeclaration} may
1287
- * optionally be supplied to configure property features.
1288
- *
1289
- * This decorator should only be used for public fields. As public fields,
1290
- * properties should be considered as primarily settable by element users,
1291
- * either via attribute or the property itself.
1292
- *
1293
- * Generally, properties that are changed by the element should be private or
1294
- * protected fields and should use the {@linkcode state} decorator.
1295
- *
1296
- * However, sometimes element code does need to set a public property. This
1297
- * should typically only be done in response to user interaction, and an event
1298
- * should be fired informing the user; for example, a checkbox sets its
1299
- * `checked` property when clicked and fires a `changed` event. Mutating public
1300
- * properties should typically not be done for non-primitive (object or array)
1301
- * properties. In other cases when an element needs to manage state, a private
1302
- * property decorated via the {@linkcode state} decorator should be used. When
1303
- * needed, state properties can be initialized via public properties to
1304
- * facilitate complex interactions.
1305
- *
1306
- * ```ts
1307
- * class MyElement {
1308
- * @property({ type: Boolean })
1309
- * clicked = false;
1310
- * }
1311
- * ```
1312
- * @category Decorator
1313
- * @ExportDecoratedItems
1266
+ * Only used in internal tests, not a part of the public API.
1314
1267
  */
1315
- function property(options) {
1316
- return (protoOrTarget, nameOrContext
1268
+ const _testOnlyClearSanitizerFactoryDoNotCallOrElse = () => {
1269
+ sanitizerFactoryInternal = noopSanitizer;
1270
+ };
1271
+ const createSanitizer = (node, name, type) => {
1272
+ return sanitizerFactoryInternal(node, name, type);
1273
+ };
1274
+ // Added to an attribute name to mark the attribute as bound so we can find
1275
+ // it easily.
1276
+ const boundAttributeSuffix = '$lit$';
1277
+ // This marker is used in many syntactic positions in HTML, so it must be
1278
+ // a valid element name and attribute name. We don't support dynamic names (yet)
1279
+ // but this at least ensures that the parse tree is closer to the template
1280
+ // intention.
1281
+ const marker = `lit$${Math.random().toFixed(9).slice(2)}$`;
1282
+ // String used to tell if a comment is a marker comment
1283
+ const markerMatch = '?' + marker;
1284
+ // Text used to insert a comment marker node. We use processing instruction
1285
+ // syntax because it's slightly smaller, but parses as a comment node.
1286
+ const nodeMarker = `<${markerMatch}>`;
1287
+ const d = document;
1288
+ // Creates a dynamic marker. We never have to search for these in the DOM.
1289
+ const createMarker = () => d.createComment('');
1290
+ const isPrimitive = (value) => value === null || (typeof value != 'object' && typeof value != 'function');
1291
+ const isArray = Array.isArray;
1292
+ const isIterable = (value) => isArray(value) ||
1317
1293
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1318
- ) => {
1319
- return (typeof nameOrContext === 'object'
1320
- ? standardProperty(options, protoOrTarget, nameOrContext)
1321
- : legacyProperty(options, protoOrTarget, nameOrContext));
1322
- };
1323
- }
1324
-
1294
+ typeof value?.[Symbol.iterator] === 'function';
1295
+ const SPACE_CHAR = `[ \t\n\f\r]`;
1296
+ const ATTR_VALUE_CHAR = `[^ \t\n\f\r"'\`<>=]`;
1297
+ const NAME_CHAR = `[^\\s"'>=/]`;
1298
+ // These regexes represent the five parsing states that we care about in the
1299
+ // Template's HTML scanner. They match the *end* of the state they're named
1300
+ // after.
1301
+ // Depending on the match, we transition to a new state. If there's no match,
1302
+ // we stay in the same state.
1303
+ // Note that the regexes are stateful. We utilize lastIndex and sync it
1304
+ // across the multiple regexes used. In addition to the five regexes below
1305
+ // we also dynamically create a regex to find the matching end tags for raw
1306
+ // text elements.
1325
1307
  /**
1326
- * @license
1327
- * Copyright 2017 Google LLC
1328
- * SPDX-License-Identifier: BSD-3-Clause
1308
+ * End of text is: `<` followed by:
1309
+ * (comment start) or (tag) or (dynamic tag binding)
1310
+ */
1311
+ const textEndRegex = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g;
1312
+ const COMMENT_START = 1;
1313
+ const TAG_NAME = 2;
1314
+ const DYNAMIC_TAG_NAME = 3;
1315
+ const commentEndRegex = /-->/g;
1316
+ /**
1317
+ * Comments not started with <!--, like </{, can be ended by a single `>`
1329
1318
  */
1319
+ const comment2EndRegex = />/g;
1330
1320
  /**
1331
- * Wraps up a few best practices when returning a property descriptor from a
1332
- * decorator.
1321
+ * The tagEnd regex matches the end of the "inside an opening" tag syntax
1322
+ * position. It either matches a `>`, an attribute-like sequence, or the end
1323
+ * of the string after a space (attribute-name position ending).
1333
1324
  *
1334
- * Marks the defined property as configurable, and enumerable, and handles
1335
- * the case where we have a busted Reflect.decorate zombiefill (e.g. in Angular
1336
- * apps).
1325
+ * See attributes in the HTML spec:
1326
+ * https://www.w3.org/TR/html5/syntax.html#elements-attributes
1337
1327
  *
1338
- * @internal
1339
- */
1340
- const desc = (obj, name, descriptor) => {
1341
- // For backwards compatibility, we keep them configurable and enumerable.
1342
- descriptor.configurable = true;
1343
- descriptor.enumerable = true;
1344
- if (
1345
- // We check for Reflect.decorate each time, in case the zombiefill
1346
- // is applied via lazy loading some Angular code.
1347
- Reflect.decorate &&
1348
- typeof name !== 'object') {
1349
- // If we're called as a legacy decorator, and Reflect.decorate is present
1350
- // then we have no guarantees that the returned descriptor will be
1351
- // defined on the class, so we must apply it directly ourselves.
1352
- Object.defineProperty(obj, name, descriptor);
1353
- }
1354
- return descriptor;
1355
- };
1356
-
1357
- /**
1358
- * @license
1359
- * Copyright 2017 Google LLC
1360
- * SPDX-License-Identifier: BSD-3-Clause
1361
- */
1362
- let issueWarning$3;
1363
- {
1364
- // Ensure warnings are issued only 1x, even if multiple versions of Lit
1365
- // are loaded.
1366
- const issuedWarnings = (globalThis.litIssuedWarnings ??= new Set());
1367
- // Issue a warning, if we haven't already.
1368
- issueWarning$3 = (code, warning) => {
1369
- warning += code
1370
- ? ` See https://lit.dev/msg/${code} for more information.`
1371
- : '';
1372
- if (!issuedWarnings.has(warning)) {
1373
- console.warn(warning);
1374
- issuedWarnings.add(warning);
1375
- }
1376
- };
1377
- }
1378
- /**
1379
- * A property decorator that converts a class property into a getter that
1380
- * executes a querySelector on the element's renderRoot.
1381
- *
1382
- * @param selector A DOMString containing one or more selectors to match.
1383
- * @param cache An optional boolean which when true performs the DOM query only
1384
- * once and caches the result.
1385
- *
1386
- * See: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
1387
- *
1388
- * ```ts
1389
- * class MyElement {
1390
- * @query('#first')
1391
- * first: HTMLDivElement;
1392
- *
1393
- * render() {
1394
- * return html`
1395
- * <div id="first"></div>
1396
- * <div id="second"></div>
1397
- * `;
1398
- * }
1399
- * }
1400
- * ```
1401
- * @category Decorator
1402
- */
1403
- function query(selector, cache) {
1404
- return ((protoOrTarget, nameOrContext, descriptor) => {
1405
- const doQuery = (el) => {
1406
- const result = (el.renderRoot?.querySelector(selector) ?? null);
1407
- if (result === null && cache && !el.hasUpdated) {
1408
- const name = typeof nameOrContext === 'object'
1409
- ? nameOrContext.name
1410
- : nameOrContext;
1411
- issueWarning$3('', `@query'd field ${JSON.stringify(String(name))} with the 'cache' ` +
1412
- `flag set for selector '${selector}' has been accessed before ` +
1413
- `the first update and returned null. This is expected if the ` +
1414
- `renderRoot tree has not been provided beforehand (e.g. via ` +
1415
- `Declarative Shadow DOM). Therefore the value hasn't been cached.`);
1416
- }
1417
- // TODO: if we want to allow users to assert that the query will never
1418
- // return null, we need a new option and to throw here if the result
1419
- // is null.
1420
- return result;
1421
- };
1422
- if (cache) {
1423
- // Accessors to wrap from either:
1424
- // 1. The decorator target, in the case of standard decorators
1425
- // 2. The property descriptor, in the case of experimental decorators
1426
- // on auto-accessors.
1427
- // 3. Functions that access our own cache-key property on the instance,
1428
- // in the case of experimental decorators on fields.
1429
- const { get, set } = typeof nameOrContext === 'object'
1430
- ? protoOrTarget
1431
- : descriptor ??
1432
- (() => {
1433
- const key = Symbol(`${String(nameOrContext)} (@query() cache)`)
1434
- ;
1435
- return {
1436
- get() {
1437
- return this[key];
1438
- },
1439
- set(v) {
1440
- this[key] = v;
1441
- },
1442
- };
1443
- })();
1444
- return desc(protoOrTarget, nameOrContext, {
1445
- get() {
1446
- let result = get.call(this);
1447
- if (result === undefined) {
1448
- result = doQuery(this);
1449
- if (result !== null || this.hasUpdated) {
1450
- set.call(this, result);
1451
- }
1452
- }
1453
- return result;
1454
- },
1455
- });
1456
- }
1457
- else {
1458
- // This object works as the return type for both standard and
1459
- // experimental decorators.
1460
- return desc(protoOrTarget, nameOrContext, {
1461
- get() {
1462
- return doQuery(this);
1463
- },
1464
- });
1465
- }
1466
- });
1467
- }
1468
-
1469
- /**
1470
- * @license
1471
- * Copyright 2017 Google LLC
1472
- * SPDX-License-Identifier: BSD-3-Clause
1473
- */
1474
- // Allows minifiers to rename references to globalThis
1475
- const global$2 = globalThis;
1476
- /**
1477
- * Useful for visualizing and logging insights into what the Lit template system is doing.
1478
- *
1479
- * Compiled out of prod mode builds.
1480
- */
1481
- const debugLogEvent$1 = (event) => {
1482
- const shouldEmit = global$2
1483
- .emitLitDebugLogEvents;
1484
- if (!shouldEmit) {
1485
- return;
1486
- }
1487
- global$2.dispatchEvent(new CustomEvent('lit-debug', {
1488
- detail: event,
1489
- }));
1490
- }
1491
- ;
1492
- // Used for connecting beginRender and endRender events when there are nested
1493
- // renders when errors are thrown preventing an endRender event from being
1494
- // called.
1495
- let debugLogRenderId = 0;
1496
- let issueWarning$2;
1497
- {
1498
- global$2.litIssuedWarnings ??= new Set();
1499
- // Issue a warning, if we haven't already.
1500
- issueWarning$2 = (code, warning) => {
1501
- warning += code
1502
- ? ` See https://lit.dev/msg/${code} for more information.`
1503
- : '';
1504
- if (!global$2.litIssuedWarnings.has(warning)) {
1505
- console.warn(warning);
1506
- global$2.litIssuedWarnings.add(warning);
1507
- }
1508
- };
1509
- issueWarning$2('dev-mode', `Lit is in dev mode. Not recommended for production!`);
1510
- }
1511
- const wrap = global$2.ShadyDOM?.inUse &&
1512
- global$2.ShadyDOM?.noPatch === true
1513
- ? global$2.ShadyDOM.wrap
1514
- : (node) => node;
1515
- const trustedTypes$1 = global$2.trustedTypes;
1516
- /**
1517
- * Our TrustedTypePolicy for HTML which is declared using the html template
1518
- * tag function.
1519
- *
1520
- * That HTML is a developer-authored constant, and is parsed with innerHTML
1521
- * before any untrusted expressions have been mixed in. Therefor it is
1522
- * considered safe by construction.
1523
- */
1524
- const policy = trustedTypes$1
1525
- ? trustedTypes$1.createPolicy('lit-html', {
1526
- createHTML: (s) => s,
1527
- })
1528
- : undefined;
1529
- const identityFunction = (value) => value;
1530
- const noopSanitizer = (_node, _name, _type) => identityFunction;
1531
- /** Sets the global sanitizer factory. */
1532
- const setSanitizer = (newSanitizer) => {
1533
- if (sanitizerFactoryInternal !== noopSanitizer) {
1534
- throw new Error(`Attempted to overwrite existing lit-html security policy.` +
1535
- ` setSanitizeDOMValueFactory should be called at most once.`);
1536
- }
1537
- sanitizerFactoryInternal = newSanitizer;
1538
- };
1539
- /**
1540
- * Only used in internal tests, not a part of the public API.
1541
- */
1542
- const _testOnlyClearSanitizerFactoryDoNotCallOrElse = () => {
1543
- sanitizerFactoryInternal = noopSanitizer;
1544
- };
1545
- const createSanitizer = (node, name, type) => {
1546
- return sanitizerFactoryInternal(node, name, type);
1547
- };
1548
- // Added to an attribute name to mark the attribute as bound so we can find
1549
- // it easily.
1550
- const boundAttributeSuffix = '$lit$';
1551
- // This marker is used in many syntactic positions in HTML, so it must be
1552
- // a valid element name and attribute name. We don't support dynamic names (yet)
1553
- // but this at least ensures that the parse tree is closer to the template
1554
- // intention.
1555
- const marker = `lit$${Math.random().toFixed(9).slice(2)}$`;
1556
- // String used to tell if a comment is a marker comment
1557
- const markerMatch = '?' + marker;
1558
- // Text used to insert a comment marker node. We use processing instruction
1559
- // syntax because it's slightly smaller, but parses as a comment node.
1560
- const nodeMarker = `<${markerMatch}>`;
1561
- const d = document;
1562
- // Creates a dynamic marker. We never have to search for these in the DOM.
1563
- const createMarker = () => d.createComment('');
1564
- const isPrimitive = (value) => value === null || (typeof value != 'object' && typeof value != 'function');
1565
- const isArray = Array.isArray;
1566
- const isIterable = (value) => isArray(value) ||
1567
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1568
- typeof value?.[Symbol.iterator] === 'function';
1569
- const SPACE_CHAR = `[ \t\n\f\r]`;
1570
- const ATTR_VALUE_CHAR = `[^ \t\n\f\r"'\`<>=]`;
1571
- const NAME_CHAR = `[^\\s"'>=/]`;
1572
- // These regexes represent the five parsing states that we care about in the
1573
- // Template's HTML scanner. They match the *end* of the state they're named
1574
- // after.
1575
- // Depending on the match, we transition to a new state. If there's no match,
1576
- // we stay in the same state.
1577
- // Note that the regexes are stateful. We utilize lastIndex and sync it
1578
- // across the multiple regexes used. In addition to the five regexes below
1579
- // we also dynamically create a regex to find the matching end tags for raw
1580
- // text elements.
1581
- /**
1582
- * End of text is: `<` followed by:
1583
- * (comment start) or (tag) or (dynamic tag binding)
1584
- */
1585
- const textEndRegex = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g;
1586
- const COMMENT_START = 1;
1587
- const TAG_NAME = 2;
1588
- const DYNAMIC_TAG_NAME = 3;
1589
- const commentEndRegex = /-->/g;
1590
- /**
1591
- * Comments not started with <!--, like </{, can be ended by a single `>`
1592
- */
1593
- const comment2EndRegex = />/g;
1594
- /**
1595
- * The tagEnd regex matches the end of the "inside an opening" tag syntax
1596
- * position. It either matches a `>`, an attribute-like sequence, or the end
1597
- * of the string after a space (attribute-name position ending).
1598
- *
1599
- * See attributes in the HTML spec:
1600
- * https://www.w3.org/TR/html5/syntax.html#elements-attributes
1601
- *
1602
- * " \t\n\f\r" are HTML space characters:
1603
- * https://infra.spec.whatwg.org/#ascii-whitespace
1604
- *
1605
- * So an attribute is:
1606
- * * The name: any character except a whitespace character, ("), ('), ">",
1607
- * "=", or "/". Note: this is different from the HTML spec which also excludes control characters.
1608
- * * Followed by zero or more space characters
1609
- * * Followed by "="
1610
- * * Followed by zero or more space characters
1611
- * * Followed by:
1612
- * * Any character except space, ('), ("), "<", ">", "=", (`), or
1613
- * * (") then any non-("), or
1614
- * * (') then any non-(')
1328
+ * " \t\n\f\r" are HTML space characters:
1329
+ * https://infra.spec.whatwg.org/#ascii-whitespace
1330
+ *
1331
+ * So an attribute is:
1332
+ * * The name: any character except a whitespace character, ("), ('), ">",
1333
+ * "=", or "/". Note: this is different from the HTML spec which also excludes control characters.
1334
+ * * Followed by zero or more space characters
1335
+ * * Followed by "="
1336
+ * * Followed by zero or more space characters
1337
+ * * Followed by:
1338
+ * * Any character except space, ('), ("), "<", ">", "=", (`), or
1339
+ * * (") then any non-("), or
1340
+ * * (') then any non-(')
1615
1341
  */
1616
1342
  const tagEndRegex = new RegExp(`>|${SPACE_CHAR}(?:(${NAME_CHAR}+)(${SPACE_CHAR}*=${SPACE_CHAR}*(?:${ATTR_VALUE_CHAR}|("|')|))|$)`, 'g');
1617
1343
  const ENTIRE_MATCH = 0;
@@ -1657,7 +1383,7 @@
1657
1383
  // handle. Instead we know that static values must have the field
1658
1384
  // `_$litStatic$`.
1659
1385
  if (values.some((val) => val?.['_$litStatic$'])) {
1660
- issueWarning$2('', `Static values 'literal' or 'unsafeStatic' cannot be used as values to non-static templates.\n` +
1386
+ issueWarning$4('', `Static values 'literal' or 'unsafeStatic' cannot be used as values to non-static templates.\n` +
1661
1387
  `Please use the static 'html' tag function. See https://lit.dev/docs/templates/expressions/#static-expressions`);
1662
1388
  }
1663
1389
  }
@@ -1937,7 +1663,7 @@
1937
1663
  throw new Error(m);
1938
1664
  }
1939
1665
  else
1940
- issueWarning$2('', m);
1666
+ issueWarning$4('', m);
1941
1667
  }
1942
1668
  }
1943
1669
  // TODO (justinfagnani): for attempted dynamic tag names, we don't
@@ -2783,7 +2509,7 @@
2783
2509
  // This line will be used in regexes to search for lit-html usage.
2784
2510
  (global$2.litHtmlVersions ??= []).push('3.2.0');
2785
2511
  if (global$2.litHtmlVersions.length > 1) {
2786
- issueWarning$2('multiple-versions', `Multiple versions of Lit loaded. ` +
2512
+ issueWarning$4('multiple-versions', `Multiple versions of Lit loaded. ` +
2787
2513
  `Loading multiple versions is not recommended.`);
2788
2514
  }
2789
2515
  /**
@@ -2862,589 +2588,249 @@
2862
2588
 
2863
2589
  /**
2864
2590
  * @license
2865
- * Copyright 2017 Google LLC
2591
+ * Copyright 2019 Google LLC
2866
2592
  * SPDX-License-Identifier: BSD-3-Clause
2867
2593
  */
2868
- const PartType = {
2869
- ATTRIBUTE: 1,
2870
- CHILD: 2,
2871
- PROPERTY: 3,
2872
- BOOLEAN_ATTRIBUTE: 4,
2873
- EVENT: 5,
2874
- ELEMENT: 6,
2875
- };
2876
- /**
2877
- * Creates a user-facing directive function from a Directive class. This
2878
- * function has the same parameters as the directive's render() method.
2879
- */
2880
- const directive = (c) => (...values) => ({
2881
- // This property needs to remain unminified.
2882
- ['_$litDirective$']: c,
2883
- values,
2884
- });
2594
+ const NODE_MODE = false;
2595
+ // Allows minifiers to rename references to globalThis
2596
+ const global$1 = globalThis;
2885
2597
  /**
2886
- * Base class for creating custom directives. Users should extend this class,
2887
- * implement `render` and/or `update`, and then pass their subclass to
2888
- * `directive`.
2598
+ * Whether the current browser supports `adoptedStyleSheets`.
2889
2599
  */
2890
- class Directive {
2891
- constructor(_partInfo) { }
2892
- // See comment in Disconnectable interface for why this is a getter
2893
- get _$isConnected() {
2894
- return this._$parent._$isConnected;
2895
- }
2896
- /** @internal */
2897
- _$initialize(part, parent, attributeIndex) {
2898
- this.__part = part;
2899
- this._$parent = parent;
2900
- this.__attributeIndex = attributeIndex;
2901
- }
2902
- /** @internal */
2903
- _$resolve(part, props) {
2904
- return this.update(part, props);
2905
- }
2906
- update(_part, props) {
2907
- return this.render(...props);
2908
- }
2909
- }
2910
-
2600
+ const supportsAdoptingStyleSheets = global$1.ShadowRoot &&
2601
+ (global$1.ShadyCSS === undefined || global$1.ShadyCSS.nativeShadow) &&
2602
+ 'adoptedStyleSheets' in Document.prototype &&
2603
+ 'replace' in CSSStyleSheet.prototype;
2604
+ const constructionToken = Symbol();
2605
+ const cssTagCache = new WeakMap();
2911
2606
  /**
2912
- * @license
2913
- * Copyright 2018 Google LLC
2914
- * SPDX-License-Identifier: BSD-3-Clause
2607
+ * A container for a string of CSS text, that may be used to create a CSSStyleSheet.
2608
+ *
2609
+ * CSSResult is the return value of `css`-tagged template literals and
2610
+ * `unsafeCSS()`. In order to ensure that CSSResults are only created via the
2611
+ * `css` tag and `unsafeCSS()`, CSSResult cannot be constructed directly.
2915
2612
  */
2916
- class ClassMapDirective extends Directive {
2917
- constructor(partInfo) {
2918
- super(partInfo);
2919
- if (partInfo.type !== PartType.ATTRIBUTE ||
2920
- partInfo.name !== 'class' ||
2921
- partInfo.strings?.length > 2) {
2922
- throw new Error('`classMap()` can only be used in the `class` attribute ' +
2923
- 'and must be the only part in the attribute.');
2613
+ class CSSResult {
2614
+ constructor(cssText, strings, safeToken) {
2615
+ // This property needs to remain unminified.
2616
+ this['_$cssResult$'] = true;
2617
+ if (safeToken !== constructionToken) {
2618
+ throw new Error('CSSResult is not constructable. Use `unsafeCSS` or `css` instead.');
2924
2619
  }
2620
+ this.cssText = cssText;
2621
+ this._strings = strings;
2925
2622
  }
2926
- render(classInfo) {
2927
- // Add spaces to ensure separation from static classes
2928
- return (' ' +
2929
- Object.keys(classInfo)
2930
- .filter((key) => classInfo[key])
2931
- .join(' ') +
2932
- ' ');
2933
- }
2934
- update(part, [classInfo]) {
2935
- // Remember dynamic classes on the first render
2936
- if (this._previousClasses === undefined) {
2937
- this._previousClasses = new Set();
2938
- if (part.strings !== undefined) {
2939
- this._staticClasses = new Set(part.strings
2940
- .join(' ')
2941
- .split(/\s/)
2942
- .filter((s) => s !== ''));
2943
- }
2944
- for (const name in classInfo) {
2945
- if (classInfo[name] && !this._staticClasses?.has(name)) {
2946
- this._previousClasses.add(name);
2947
- }
2948
- }
2949
- return this.render(classInfo);
2950
- }
2951
- const classList = part.element.classList;
2952
- // Remove old classes that no longer apply
2953
- for (const name of this._previousClasses) {
2954
- if (!(name in classInfo)) {
2955
- classList.remove(name);
2956
- this._previousClasses.delete(name);
2623
+ // This is a getter so that it's lazy. In practice, this means stylesheets
2624
+ // are not created until the first element instance is made.
2625
+ get styleSheet() {
2626
+ // If `supportsAdoptingStyleSheets` is true then we assume CSSStyleSheet is
2627
+ // constructable.
2628
+ let styleSheet = this._styleSheet;
2629
+ const strings = this._strings;
2630
+ if (supportsAdoptingStyleSheets && styleSheet === undefined) {
2631
+ const cacheable = strings !== undefined && strings.length === 1;
2632
+ if (cacheable) {
2633
+ styleSheet = cssTagCache.get(strings);
2957
2634
  }
2958
- }
2959
- // Add or remove classes based on their classMap value
2960
- for (const name in classInfo) {
2961
- // We explicitly want a loose truthy check of `value` because it seems
2962
- // more convenient that '' and 0 are skipped.
2963
- const value = !!classInfo[name];
2964
- if (value !== this._previousClasses.has(name) &&
2965
- !this._staticClasses?.has(name)) {
2966
- if (value) {
2967
- classList.add(name);
2968
- this._previousClasses.add(name);
2969
- }
2970
- else {
2971
- classList.remove(name);
2972
- this._previousClasses.delete(name);
2635
+ if (styleSheet === undefined) {
2636
+ (this._styleSheet = styleSheet = new CSSStyleSheet()).replaceSync(this.cssText);
2637
+ if (cacheable) {
2638
+ cssTagCache.set(strings, styleSheet);
2973
2639
  }
2974
2640
  }
2975
2641
  }
2976
- return noChange;
2642
+ return styleSheet;
2643
+ }
2644
+ toString() {
2645
+ return this.cssText;
2977
2646
  }
2978
2647
  }
2648
+ const textFromCSSResult = (value) => {
2649
+ // This property needs to remain unminified.
2650
+ if (value['_$cssResult$'] === true) {
2651
+ return value.cssText;
2652
+ }
2653
+ else if (typeof value === 'number') {
2654
+ return value;
2655
+ }
2656
+ else {
2657
+ throw new Error(`Value passed to 'css' function must be a 'css' function result: ` +
2658
+ `${value}. Use 'unsafeCSS' to pass non-literal values, but take care ` +
2659
+ `to ensure page security.`);
2660
+ }
2661
+ };
2979
2662
  /**
2980
- * A directive that applies dynamic CSS classes.
2981
- *
2982
- * This must be used in the `class` attribute and must be the only part used in
2983
- * the attribute. It takes each property in the `classInfo` argument and adds
2984
- * the property name to the element's `classList` if the property value is
2985
- * truthy; if the property value is falsy, the property name is removed from
2986
- * the element's `class`.
2987
- *
2988
- * For example `{foo: bar}` applies the class `foo` if the value of `bar` is
2989
- * truthy.
2663
+ * Wrap a value for interpolation in a {@linkcode css} tagged template literal.
2990
2664
  *
2991
- * @param classInfo
2665
+ * This is unsafe because untrusted CSS text can be used to phone home
2666
+ * or exfiltrate data to an attacker controlled site. Take care to only use
2667
+ * this with trusted input.
2992
2668
  */
2993
- const classMap = directive(ClassMapDirective);
2994
-
2669
+ const unsafeCSS = (value) => new CSSResult(typeof value === 'string' ? value : String(value), undefined, constructionToken);
2995
2670
  /**
2996
- * @license
2997
- * Copyright 2018 Google LLC
2998
- * SPDX-License-Identifier: BSD-3-Clause
2671
+ * A template literal tag which can be used with LitElement's
2672
+ * {@linkcode LitElement.styles} property to set element styles.
2673
+ *
2674
+ * For security reasons, only literal string values and number may be used in
2675
+ * embedded expressions. To incorporate non-literal values {@linkcode unsafeCSS}
2676
+ * may be used inside an expression.
2999
2677
  */
2678
+ const css = (strings, ...values) => {
2679
+ const cssText = strings.length === 1
2680
+ ? strings[0]
2681
+ : values.reduce((acc, v, idx) => acc + textFromCSSResult(v) + strings[idx + 1], strings[0]);
2682
+ return new CSSResult(cssText, strings, constructionToken);
2683
+ };
3000
2684
  /**
3001
- * For AttributeParts, sets the attribute if the value is defined and removes
3002
- * the attribute if the value is undefined.
3003
- *
3004
- * For other part types, this directive is a no-op.
2685
+ * Applies the given styles to a `shadowRoot`. When Shadow DOM is
2686
+ * available but `adoptedStyleSheets` is not, styles are appended to the
2687
+ * `shadowRoot` to [mimic spec behavior](https://wicg.github.io/construct-stylesheets/#using-constructed-stylesheets).
2688
+ * Note, when shimming is used, any styles that are subsequently placed into
2689
+ * the shadowRoot should be placed *before* any shimmed adopted styles. This
2690
+ * will match spec behavior that gives adopted sheets precedence over styles in
2691
+ * shadowRoot.
3005
2692
  */
3006
- const ifDefined = (value) => value ?? nothing;
2693
+ const adoptStyles = (renderRoot, styles) => {
2694
+ if (supportsAdoptingStyleSheets) {
2695
+ renderRoot.adoptedStyleSheets = styles.map((s) => s instanceof CSSStyleSheet ? s : s.styleSheet);
2696
+ }
2697
+ else {
2698
+ for (const s of styles) {
2699
+ const style = document.createElement('style');
2700
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2701
+ const nonce = global$1['litNonce'];
2702
+ if (nonce !== undefined) {
2703
+ style.setAttribute('nonce', nonce);
2704
+ }
2705
+ style.textContent = s.cssText;
2706
+ renderRoot.appendChild(style);
2707
+ }
2708
+ }
2709
+ };
2710
+ const cssResultFromStyleSheet = (sheet) => {
2711
+ let cssText = '';
2712
+ for (const rule of sheet.cssRules) {
2713
+ cssText += rule.cssText;
2714
+ }
2715
+ return unsafeCSS(cssText);
2716
+ };
2717
+ const getCompatibleStyle = supportsAdoptingStyleSheets ||
2718
+ (NODE_MODE )
2719
+ ? (s) => s
2720
+ : (s) => s instanceof CSSStyleSheet ? cssResultFromStyleSheet(s) : s;
3007
2721
 
3008
2722
  /**
3009
2723
  * @license
3010
- * Copyright 2020 Google LLC
2724
+ * Copyright 2017 Google LLC
3011
2725
  * SPDX-License-Identifier: BSD-3-Clause
3012
2726
  */
3013
- window.ShadyDOM?.inUse &&
3014
- window.ShadyDOM?.noPatch === true
3015
- ? window.ShadyDOM.wrap
3016
- : (node) => node;
3017
- /**
3018
- * Tests whether a part has only a single-expression with no strings to
3019
- * interpolate between.
3020
- *
3021
- * Only AttributePart and PropertyPart can have multiple expressions.
3022
- * Multi-expression parts have a `strings` property and single-expression
3023
- * parts do not.
3024
- */
3025
- const isSingleExpression = (part) => part.strings === undefined;
3026
- // A sentinel value that can never appear as a part value except when set by
3027
- // live(). Used to force a dirty-check to fail and cause a re-render.
3028
- const RESET_VALUE = {};
3029
- /**
3030
- * Sets the committed value of a ChildPart directly without triggering the
3031
- * commit stage of the part.
3032
- *
3033
- * This is useful in cases where a directive needs to update the part such
3034
- * that the next update detects a value change or not. When value is omitted,
3035
- * the next update will be guaranteed to be detected as a change.
3036
- *
3037
- * @param part
3038
- * @param value
3039
- */
3040
- const setCommittedValue = (part, value = RESET_VALUE) => (part._$committedValue = value);
3041
-
3042
- /**
3043
- * @license
3044
- * Copyright 2020 Google LLC
3045
- * SPDX-License-Identifier: BSD-3-Clause
3046
- */
3047
- class LiveDirective extends Directive {
3048
- constructor(partInfo) {
3049
- super(partInfo);
3050
- if (!(partInfo.type === PartType.PROPERTY ||
3051
- partInfo.type === PartType.ATTRIBUTE ||
3052
- partInfo.type === PartType.BOOLEAN_ATTRIBUTE)) {
3053
- throw new Error('The `live` directive is not allowed on child or event bindings');
3054
- }
3055
- if (!isSingleExpression(partInfo)) {
3056
- throw new Error('`live` bindings can only contain a single expression');
3057
- }
3058
- }
3059
- render(value) {
3060
- return value;
3061
- }
3062
- update(part, [value]) {
3063
- if (value === noChange || value === nothing) {
3064
- return value;
3065
- }
3066
- const element = part.element;
3067
- const name = part.name;
3068
- if (part.type === PartType.PROPERTY) {
3069
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3070
- if (value === element[name]) {
3071
- return noChange;
3072
- }
3073
- }
3074
- else if (part.type === PartType.BOOLEAN_ATTRIBUTE) {
3075
- if (!!value === element.hasAttribute(name)) {
3076
- return noChange;
3077
- }
3078
- }
3079
- else if (part.type === PartType.ATTRIBUTE) {
3080
- if (element.getAttribute(name) === String(value)) {
3081
- return noChange;
3082
- }
2727
+ // TODO (justinfagnani): Add `hasOwn` here when we ship ES2022
2728
+ const { is, defineProperty, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, } = Object;
2729
+ // Lets a minifier replace globalThis references with a minified name
2730
+ const global = globalThis;
2731
+ let issueWarning$3;
2732
+ const trustedTypes = global
2733
+ .trustedTypes;
2734
+ // Temporary workaround for https://crbug.com/993268
2735
+ // Currently, any attribute starting with "on" is considered to be a
2736
+ // TrustedScript source. Such boolean attributes must be set to the equivalent
2737
+ // trusted emptyScript value.
2738
+ const emptyStringForBooleanAttribute = trustedTypes
2739
+ ? trustedTypes.emptyScript
2740
+ : '';
2741
+ const polyfillSupport$1 = global.reactiveElementPolyfillSupportDevMode
2742
+ ;
2743
+ {
2744
+ // Ensure warnings are issued only 1x, even if multiple versions of Lit
2745
+ // are loaded.
2746
+ const issuedWarnings = (global.litIssuedWarnings ??=
2747
+ new Set());
2748
+ // Issue a warning, if we haven't already.
2749
+ issueWarning$3 = (code, warning) => {
2750
+ warning += ` See https://lit.dev/msg/${code} for more information.`;
2751
+ if (!issuedWarnings.has(warning)) {
2752
+ console.warn(warning);
2753
+ issuedWarnings.add(warning);
3083
2754
  }
3084
- // Resets the part's value, causing its dirty-check to fail so that it
3085
- // always sets the value.
3086
- setCommittedValue(part);
3087
- return value;
2755
+ };
2756
+ issueWarning$3('dev-mode', `Lit is in dev mode. Not recommended for production!`);
2757
+ // Issue polyfill support warning.
2758
+ if (global.ShadyDOM?.inUse && polyfillSupport$1 === undefined) {
2759
+ issueWarning$3('polyfill-support-missing', `Shadow DOM is being polyfilled via \`ShadyDOM\` but ` +
2760
+ `the \`polyfill-support\` module has not been loaded.`);
3088
2761
  }
3089
2762
  }
3090
2763
  /**
3091
- * Checks binding values against live DOM values, instead of previously bound
3092
- * values, when determining whether to update the value.
3093
- *
3094
- * This is useful for cases where the DOM value may change from outside of
3095
- * lit-html, such as with a binding to an `<input>` element's `value` property,
3096
- * a content editable elements text, or to a custom element that changes it's
3097
- * own properties or attributes.
3098
- *
3099
- * In these cases if the DOM value changes, but the value set through lit-html
3100
- * bindings hasn't, lit-html won't know to update the DOM value and will leave
3101
- * it alone. If this is not what you want--if you want to overwrite the DOM
3102
- * value with the bound value no matter what--use the `live()` directive:
3103
- *
3104
- * ```js
3105
- * html`<input .value=${live(x)}>`
3106
- * ```
3107
- *
3108
- * `live()` performs a strict equality check against the live DOM value, and if
3109
- * the new value is equal to the live value, does nothing. This means that
3110
- * `live()` should not be used when the binding will cause a type conversion. If
3111
- * you use `live()` with an attribute binding, make sure that only strings are
3112
- * passed in, or the binding will update every render.
3113
- */
3114
- const live = directive(LiveDirective);
3115
-
3116
- /**
3117
- * @license
3118
- * Copyright 2020 Google LLC
3119
- * SPDX-License-Identifier: BSD-3-Clause
3120
- */
3121
- /**
3122
- * Prevents JSON injection attacks.
3123
- *
3124
- * The goals of this brand:
3125
- * 1) fast to check
3126
- * 2) code is small on the wire
3127
- * 3) multiple versions of Lit in a single page will all produce mutually
3128
- * interoperable StaticValues
3129
- * 4) normal JSON.parse (without an unusual reviver) can not produce a
3130
- * StaticValue
2764
+ * Useful for visualizing and logging insights into what the Lit template system is doing.
3131
2765
  *
3132
- * Symbols satisfy (1), (2), and (4). We use Symbol.for to satisfy (3), but
3133
- * we don't care about the key, so we break ties via (2) and use the empty
3134
- * string.
2766
+ * Compiled out of prod mode builds.
3135
2767
  */
3136
- const brand = Symbol.for('');
3137
- /** Safely extracts the string part of a StaticValue. */
3138
- const unwrapStaticValue = (value) => {
3139
- if (value?.r !== brand) {
3140
- return undefined;
2768
+ const debugLogEvent = (event) => {
2769
+ const shouldEmit = global
2770
+ .emitLitDebugLogEvents;
2771
+ if (!shouldEmit) {
2772
+ return;
2773
+ }
2774
+ global.dispatchEvent(new CustomEvent('lit-debug', {
2775
+ detail: event,
2776
+ }));
3141
2777
  }
3142
- return value?.['_$litStatic$'];
3143
- };
3144
- const stringsCache = new Map();
3145
- /**
3146
- * Wraps a lit-html template tag (`html` or `svg`) to add static value support.
2778
+ ;
2779
+ /*
2780
+ * When using Closure Compiler, JSCompiler_renameProperty(property, object) is
2781
+ * replaced at compile time by the munged name for object[property]. We cannot
2782
+ * alias this function, so we have to use a small shim that has the same
2783
+ * behavior when not compiling.
3147
2784
  */
3148
- const withStatic = (coreTag) => (strings, ...values) => {
3149
- const l = values.length;
3150
- let staticValue;
3151
- let dynamicValue;
3152
- const staticStrings = [];
3153
- const dynamicValues = [];
3154
- let i = 0;
3155
- let hasStatics = false;
3156
- let s;
3157
- while (i < l) {
3158
- s = strings[i];
3159
- // Collect any unsafeStatic values, and their following template strings
3160
- // so that we treat a run of template strings and unsafe static values as
3161
- // a single template string.
3162
- while (i < l &&
3163
- ((dynamicValue = values[i]),
3164
- (staticValue = unwrapStaticValue(dynamicValue))) !== undefined) {
3165
- s += staticValue + strings[++i];
3166
- hasStatics = true;
3167
- }
3168
- // If the last value is static, we don't need to push it.
3169
- if (i !== l) {
3170
- dynamicValues.push(dynamicValue);
2785
+ /*@__INLINE__*/
2786
+ const JSCompiler_renameProperty$1 = (prop, _obj) => prop;
2787
+ const defaultConverter = {
2788
+ toAttribute(value, type) {
2789
+ switch (type) {
2790
+ case Boolean:
2791
+ value = value ? emptyStringForBooleanAttribute : null;
2792
+ break;
2793
+ case Object:
2794
+ case Array:
2795
+ // if the value is `null` or `undefined` pass this through
2796
+ // to allow removing/no change behavior.
2797
+ value = value == null ? value : JSON.stringify(value);
2798
+ break;
3171
2799
  }
3172
- staticStrings.push(s);
3173
- i++;
3174
- }
3175
- // If the last value isn't static (which would have consumed the last
3176
- // string), then we need to add the last string.
3177
- if (i === l) {
3178
- staticStrings.push(strings[l]);
3179
- }
3180
- if (hasStatics) {
3181
- const key = staticStrings.join('$$lit$$');
3182
- strings = stringsCache.get(key);
3183
- if (strings === undefined) {
3184
- // Beware: in general this pattern is unsafe, and doing so may bypass
3185
- // lit's security checks and allow an attacker to execute arbitrary
3186
- // code and inject arbitrary content.
3187
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3188
- staticStrings.raw = staticStrings;
3189
- stringsCache.set(key, (strings = staticStrings));
2800
+ return value;
2801
+ },
2802
+ fromAttribute(value, type) {
2803
+ let fromValue = value;
2804
+ switch (type) {
2805
+ case Boolean:
2806
+ fromValue = value !== null;
2807
+ break;
2808
+ case Number:
2809
+ fromValue = value === null ? null : Number(value);
2810
+ break;
2811
+ case Object:
2812
+ case Array:
2813
+ // Do *not* generate exception when invalid JSON is set as elements
2814
+ // don't normally complain on being mis-configured.
2815
+ // TODO(sorvell): Do generate exception in *dev mode*.
2816
+ try {
2817
+ // Assert to adhere to Bazel's "must type assert JSON parse" rule.
2818
+ fromValue = JSON.parse(value);
2819
+ }
2820
+ catch (e) {
2821
+ fromValue = null;
2822
+ }
2823
+ break;
3190
2824
  }
3191
- values = dynamicValues;
3192
- }
3193
- return coreTag(strings, ...values);
2825
+ return fromValue;
2826
+ },
3194
2827
  };
3195
2828
  /**
3196
- * Interprets a template literal as an HTML template that can efficiently
3197
- * render to and update a container.
3198
- *
3199
- * Includes static value support from `lit-html/static.js`.
3200
- */
3201
- const html = withStatic(html$1);
3202
-
3203
- /**
3204
- * @license
3205
- * Copyright 2019 Google LLC
3206
- * SPDX-License-Identifier: BSD-3-Clause
3207
- */
3208
- const NODE_MODE = false;
3209
- // Allows minifiers to rename references to globalThis
3210
- const global$1 = globalThis;
3211
- /**
3212
- * Whether the current browser supports `adoptedStyleSheets`.
3213
- */
3214
- const supportsAdoptingStyleSheets = global$1.ShadowRoot &&
3215
- (global$1.ShadyCSS === undefined || global$1.ShadyCSS.nativeShadow) &&
3216
- 'adoptedStyleSheets' in Document.prototype &&
3217
- 'replace' in CSSStyleSheet.prototype;
3218
- const constructionToken = Symbol();
3219
- const cssTagCache = new WeakMap();
3220
- /**
3221
- * A container for a string of CSS text, that may be used to create a CSSStyleSheet.
3222
- *
3223
- * CSSResult is the return value of `css`-tagged template literals and
3224
- * `unsafeCSS()`. In order to ensure that CSSResults are only created via the
3225
- * `css` tag and `unsafeCSS()`, CSSResult cannot be constructed directly.
3226
- */
3227
- class CSSResult {
3228
- constructor(cssText, strings, safeToken) {
3229
- // This property needs to remain unminified.
3230
- this['_$cssResult$'] = true;
3231
- if (safeToken !== constructionToken) {
3232
- throw new Error('CSSResult is not constructable. Use `unsafeCSS` or `css` instead.');
3233
- }
3234
- this.cssText = cssText;
3235
- this._strings = strings;
3236
- }
3237
- // This is a getter so that it's lazy. In practice, this means stylesheets
3238
- // are not created until the first element instance is made.
3239
- get styleSheet() {
3240
- // If `supportsAdoptingStyleSheets` is true then we assume CSSStyleSheet is
3241
- // constructable.
3242
- let styleSheet = this._styleSheet;
3243
- const strings = this._strings;
3244
- if (supportsAdoptingStyleSheets && styleSheet === undefined) {
3245
- const cacheable = strings !== undefined && strings.length === 1;
3246
- if (cacheable) {
3247
- styleSheet = cssTagCache.get(strings);
3248
- }
3249
- if (styleSheet === undefined) {
3250
- (this._styleSheet = styleSheet = new CSSStyleSheet()).replaceSync(this.cssText);
3251
- if (cacheable) {
3252
- cssTagCache.set(strings, styleSheet);
3253
- }
3254
- }
3255
- }
3256
- return styleSheet;
3257
- }
3258
- toString() {
3259
- return this.cssText;
3260
- }
3261
- }
3262
- const textFromCSSResult = (value) => {
3263
- // This property needs to remain unminified.
3264
- if (value['_$cssResult$'] === true) {
3265
- return value.cssText;
3266
- }
3267
- else if (typeof value === 'number') {
3268
- return value;
3269
- }
3270
- else {
3271
- throw new Error(`Value passed to 'css' function must be a 'css' function result: ` +
3272
- `${value}. Use 'unsafeCSS' to pass non-literal values, but take care ` +
3273
- `to ensure page security.`);
3274
- }
3275
- };
3276
- /**
3277
- * Wrap a value for interpolation in a {@linkcode css} tagged template literal.
3278
- *
3279
- * This is unsafe because untrusted CSS text can be used to phone home
3280
- * or exfiltrate data to an attacker controlled site. Take care to only use
3281
- * this with trusted input.
3282
- */
3283
- const unsafeCSS = (value) => new CSSResult(typeof value === 'string' ? value : String(value), undefined, constructionToken);
3284
- /**
3285
- * A template literal tag which can be used with LitElement's
3286
- * {@linkcode LitElement.styles} property to set element styles.
3287
- *
3288
- * For security reasons, only literal string values and number may be used in
3289
- * embedded expressions. To incorporate non-literal values {@linkcode unsafeCSS}
3290
- * may be used inside an expression.
3291
- */
3292
- const css = (strings, ...values) => {
3293
- const cssText = strings.length === 1
3294
- ? strings[0]
3295
- : values.reduce((acc, v, idx) => acc + textFromCSSResult(v) + strings[idx + 1], strings[0]);
3296
- return new CSSResult(cssText, strings, constructionToken);
3297
- };
3298
- /**
3299
- * Applies the given styles to a `shadowRoot`. When Shadow DOM is
3300
- * available but `adoptedStyleSheets` is not, styles are appended to the
3301
- * `shadowRoot` to [mimic spec behavior](https://wicg.github.io/construct-stylesheets/#using-constructed-stylesheets).
3302
- * Note, when shimming is used, any styles that are subsequently placed into
3303
- * the shadowRoot should be placed *before* any shimmed adopted styles. This
3304
- * will match spec behavior that gives adopted sheets precedence over styles in
3305
- * shadowRoot.
3306
- */
3307
- const adoptStyles = (renderRoot, styles) => {
3308
- if (supportsAdoptingStyleSheets) {
3309
- renderRoot.adoptedStyleSheets = styles.map((s) => s instanceof CSSStyleSheet ? s : s.styleSheet);
3310
- }
3311
- else {
3312
- for (const s of styles) {
3313
- const style = document.createElement('style');
3314
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3315
- const nonce = global$1['litNonce'];
3316
- if (nonce !== undefined) {
3317
- style.setAttribute('nonce', nonce);
3318
- }
3319
- style.textContent = s.cssText;
3320
- renderRoot.appendChild(style);
3321
- }
3322
- }
3323
- };
3324
- const cssResultFromStyleSheet = (sheet) => {
3325
- let cssText = '';
3326
- for (const rule of sheet.cssRules) {
3327
- cssText += rule.cssText;
3328
- }
3329
- return unsafeCSS(cssText);
3330
- };
3331
- const getCompatibleStyle = supportsAdoptingStyleSheets ||
3332
- (NODE_MODE )
3333
- ? (s) => s
3334
- : (s) => s instanceof CSSStyleSheet ? cssResultFromStyleSheet(s) : s;
3335
-
3336
- /**
3337
- * @license
3338
- * Copyright 2017 Google LLC
3339
- * SPDX-License-Identifier: BSD-3-Clause
3340
- */
3341
- // TODO (justinfagnani): Add `hasOwn` here when we ship ES2022
3342
- const { is, defineProperty, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, } = Object;
3343
- // Lets a minifier replace globalThis references with a minified name
3344
- const global = globalThis;
3345
- let issueWarning$1;
3346
- const trustedTypes = global
3347
- .trustedTypes;
3348
- // Temporary workaround for https://crbug.com/993268
3349
- // Currently, any attribute starting with "on" is considered to be a
3350
- // TrustedScript source. Such boolean attributes must be set to the equivalent
3351
- // trusted emptyScript value.
3352
- const emptyStringForBooleanAttribute = trustedTypes
3353
- ? trustedTypes.emptyScript
3354
- : '';
3355
- const polyfillSupport$1 = global.reactiveElementPolyfillSupportDevMode
3356
- ;
3357
- {
3358
- // Ensure warnings are issued only 1x, even if multiple versions of Lit
3359
- // are loaded.
3360
- const issuedWarnings = (global.litIssuedWarnings ??=
3361
- new Set());
3362
- // Issue a warning, if we haven't already.
3363
- issueWarning$1 = (code, warning) => {
3364
- warning += ` See https://lit.dev/msg/${code} for more information.`;
3365
- if (!issuedWarnings.has(warning)) {
3366
- console.warn(warning);
3367
- issuedWarnings.add(warning);
3368
- }
3369
- };
3370
- issueWarning$1('dev-mode', `Lit is in dev mode. Not recommended for production!`);
3371
- // Issue polyfill support warning.
3372
- if (global.ShadyDOM?.inUse && polyfillSupport$1 === undefined) {
3373
- issueWarning$1('polyfill-support-missing', `Shadow DOM is being polyfilled via \`ShadyDOM\` but ` +
3374
- `the \`polyfill-support\` module has not been loaded.`);
3375
- }
3376
- }
3377
- /**
3378
- * Useful for visualizing and logging insights into what the Lit template system is doing.
3379
- *
3380
- * Compiled out of prod mode builds.
3381
- */
3382
- const debugLogEvent = (event) => {
3383
- const shouldEmit = global
3384
- .emitLitDebugLogEvents;
3385
- if (!shouldEmit) {
3386
- return;
3387
- }
3388
- global.dispatchEvent(new CustomEvent('lit-debug', {
3389
- detail: event,
3390
- }));
3391
- }
3392
- ;
3393
- /*
3394
- * When using Closure Compiler, JSCompiler_renameProperty(property, object) is
3395
- * replaced at compile time by the munged name for object[property]. We cannot
3396
- * alias this function, so we have to use a small shim that has the same
3397
- * behavior when not compiling.
3398
- */
3399
- /*@__INLINE__*/
3400
- const JSCompiler_renameProperty$1 = (prop, _obj) => prop;
3401
- const defaultConverter = {
3402
- toAttribute(value, type) {
3403
- switch (type) {
3404
- case Boolean:
3405
- value = value ? emptyStringForBooleanAttribute : null;
3406
- break;
3407
- case Object:
3408
- case Array:
3409
- // if the value is `null` or `undefined` pass this through
3410
- // to allow removing/no change behavior.
3411
- value = value == null ? value : JSON.stringify(value);
3412
- break;
3413
- }
3414
- return value;
3415
- },
3416
- fromAttribute(value, type) {
3417
- let fromValue = value;
3418
- switch (type) {
3419
- case Boolean:
3420
- fromValue = value !== null;
3421
- break;
3422
- case Number:
3423
- fromValue = value === null ? null : Number(value);
3424
- break;
3425
- case Object:
3426
- case Array:
3427
- // Do *not* generate exception when invalid JSON is set as elements
3428
- // don't normally complain on being mis-configured.
3429
- // TODO(sorvell): Do generate exception in *dev mode*.
3430
- try {
3431
- // Assert to adhere to Bazel's "must type assert JSON parse" rule.
3432
- fromValue = JSON.parse(value);
3433
- }
3434
- catch (e) {
3435
- fromValue = null;
3436
- }
3437
- break;
3438
- }
3439
- return fromValue;
3440
- },
3441
- };
3442
- /**
3443
- * Change function that returns true if `value` is different from `oldValue`.
3444
- * This method is used as the default for a property's `hasChanged` function.
2829
+ * Change function that returns true if `value` is different from `oldValue`.
2830
+ * This method is used as the default for a property's `hasChanged` function.
3445
2831
  */
3446
2832
  const notEqual = (value, old) => !is(value, old);
3447
- const defaultPropertyDeclaration = {
2833
+ const defaultPropertyDeclaration$1 = {
3448
2834
  attribute: true,
3449
2835
  type: String,
3450
2836
  converter: defaultConverter,
@@ -3550,7 +2936,7 @@
3550
2936
  * @nocollapse
3551
2937
  * @category properties
3552
2938
  */
3553
- static createProperty(name, options = defaultPropertyDeclaration) {
2939
+ static createProperty(name, options = defaultPropertyDeclaration$1) {
3554
2940
  // If this is a state property, force the attribute to false.
3555
2941
  if (options.state) {
3556
2942
  options.attribute = false;
@@ -3611,7 +2997,7 @@
3611
2997
  `but it's actually declared as a value on the prototype. ` +
3612
2998
  `Usually this is due to using @property or @state on a method.`);
3613
2999
  }
3614
- issueWarning$1('reactive-property-without-getter', `Field ${JSON.stringify(String(name))} on ` +
3000
+ issueWarning$3('reactive-property-without-getter', `Field ${JSON.stringify(String(name))} on ` +
3615
3001
  `${this.name} was declared as a reactive property ` +
3616
3002
  `but it does not have a getter. This will be an error in a ` +
3617
3003
  `future version of Lit.`);
@@ -3644,7 +3030,7 @@
3644
3030
  * @category properties
3645
3031
  */
3646
3032
  static getPropertyOptions(name) {
3647
- return this.elementProperties.get(name) ?? defaultPropertyDeclaration;
3033
+ return this.elementProperties.get(name) ?? defaultPropertyDeclaration$1;
3648
3034
  }
3649
3035
  /**
3650
3036
  * Initializes static own properties of the class used in bookkeeping
@@ -3723,11 +3109,11 @@
3723
3109
  this.elementStyles = this.finalizeStyles(this.styles);
3724
3110
  {
3725
3111
  if (this.hasOwnProperty('createProperty')) {
3726
- issueWarning$1('no-override-create-property', 'Overriding ReactiveElement.createProperty() is deprecated. ' +
3112
+ issueWarning$3('no-override-create-property', 'Overriding ReactiveElement.createProperty() is deprecated. ' +
3727
3113
  'The override will not be called with standard decorators');
3728
3114
  }
3729
3115
  if (this.hasOwnProperty('getPropertyDescriptor')) {
3730
- issueWarning$1('no-override-get-property-descriptor', 'Overriding ReactiveElement.getPropertyDescriptor() is deprecated. ' +
3116
+ issueWarning$3('no-override-get-property-descriptor', 'Overriding ReactiveElement.getPropertyDescriptor() is deprecated. ' +
3731
3117
  'The override will not be called with standard decorators');
3732
3118
  }
3733
3119
  }
@@ -3935,7 +3321,7 @@
3935
3321
  const attrValue = converter.toAttribute(value, options.type);
3936
3322
  if (this.constructor.enabledWarnings.includes('migration') &&
3937
3323
  attrValue === undefined) {
3938
- issueWarning$1('undefined-attribute-value', `The attribute value for the ${name} property is ` +
3324
+ issueWarning$3('undefined-attribute-value', `The attribute value for the ${name} property is ` +
3939
3325
  `undefined on element ${this.localName}. The attribute will be ` +
3940
3326
  `removed, but in the previous version of \`ReactiveElement\`, ` +
3941
3327
  `the attribute would not have changed.`);
@@ -4001,7 +3387,7 @@
4001
3387
  // If we have a property key, perform property update steps.
4002
3388
  if (name !== undefined) {
4003
3389
  if (name instanceof Event) {
4004
- issueWarning$1(``, `The requestUpdate() method was called with an Event as the property name. This is probably a mistake caused by binding this.requestUpdate as an event listener. Instead bind a function that will call it with no arguments: () => this.requestUpdate()`);
3390
+ issueWarning$3(``, `The requestUpdate() method was called with an Event as the property name. This is probably a mistake caused by binding this.requestUpdate as an event listener. Instead bind a function that will call it with no arguments: () => this.requestUpdate()`);
4005
3391
  }
4006
3392
  options ??= this.constructor.getPropertyOptions(name);
4007
3393
  const hasChanged = options.hasChanged ?? notEqual;
@@ -4083,7 +3469,7 @@
4083
3469
  if (this.constructor.enabledWarnings.includes('async-perform-update') &&
4084
3470
  typeof result?.then ===
4085
3471
  'function') {
4086
- issueWarning$1('async-perform-update', `Element ${this.localName} returned a Promise from performUpdate(). ` +
3472
+ issueWarning$3('async-perform-update', `Element ${this.localName} returned a Promise from performUpdate(). ` +
4087
3473
  `This behavior is deprecated and will be removed in a future ` +
4088
3474
  `version of ReactiveElement.`);
4089
3475
  }
@@ -4219,7 +3605,7 @@
4219
3605
  this.updated(changedProperties);
4220
3606
  if (this.isUpdatePending &&
4221
3607
  this.constructor.enabledWarnings.includes('change-in-update')) {
4222
- issueWarning$1('change-in-update', `Element ${this.localName} scheduled an update ` +
3608
+ issueWarning$3('change-in-update', `Element ${this.localName} scheduled an update ` +
4223
3609
  `(generally because a property was set) ` +
4224
3610
  `after an update completed, causing a new update to be scheduled. ` +
4225
3611
  `This is inefficient and should be avoided unless the next update ` +
@@ -4332,223 +3718,924 @@
4332
3718
  firstUpdated(_changedProperties) { }
4333
3719
  }
4334
3720
  /**
4335
- * Memoized list of all element styles.
4336
- * Created lazily on user subclasses when finalizing the class.
4337
- * @nocollapse
4338
- * @category styles
3721
+ * Memoized list of all element styles.
3722
+ * Created lazily on user subclasses when finalizing the class.
3723
+ * @nocollapse
3724
+ * @category styles
3725
+ */
3726
+ ReactiveElement.elementStyles = [];
3727
+ /**
3728
+ * Options used when calling `attachShadow`. Set this property to customize
3729
+ * the options for the shadowRoot; for example, to create a closed
3730
+ * shadowRoot: `{mode: 'closed'}`.
3731
+ *
3732
+ * Note, these options are used in `createRenderRoot`. If this method
3733
+ * is customized, options should be respected if possible.
3734
+ * @nocollapse
3735
+ * @category rendering
3736
+ */
3737
+ ReactiveElement.shadowRootOptions = { mode: 'open' };
3738
+ // Assigned here to work around a jscompiler bug with static fields
3739
+ // when compiling to ES5.
3740
+ // https://github.com/google/closure-compiler/issues/3177
3741
+ ReactiveElement[JSCompiler_renameProperty$1('elementProperties')] = new Map();
3742
+ ReactiveElement[JSCompiler_renameProperty$1('finalized')] = new Map();
3743
+ // Apply polyfills if available
3744
+ polyfillSupport$1?.({ ReactiveElement });
3745
+ // Dev mode warnings...
3746
+ {
3747
+ // Default warning set.
3748
+ ReactiveElement.enabledWarnings = [
3749
+ 'change-in-update',
3750
+ 'async-perform-update',
3751
+ ];
3752
+ const ensureOwnWarnings = function (ctor) {
3753
+ if (!ctor.hasOwnProperty(JSCompiler_renameProperty$1('enabledWarnings'))) {
3754
+ ctor.enabledWarnings = ctor.enabledWarnings.slice();
3755
+ }
3756
+ };
3757
+ ReactiveElement.enableWarning = function (warning) {
3758
+ ensureOwnWarnings(this);
3759
+ if (!this.enabledWarnings.includes(warning)) {
3760
+ this.enabledWarnings.push(warning);
3761
+ }
3762
+ };
3763
+ ReactiveElement.disableWarning = function (warning) {
3764
+ ensureOwnWarnings(this);
3765
+ const i = this.enabledWarnings.indexOf(warning);
3766
+ if (i >= 0) {
3767
+ this.enabledWarnings.splice(i, 1);
3768
+ }
3769
+ };
3770
+ }
3771
+ // IMPORTANT: do not change the property name or the assignment expression.
3772
+ // This line will be used in regexes to search for ReactiveElement usage.
3773
+ (global.reactiveElementVersions ??= []).push('2.0.4');
3774
+ if (global.reactiveElementVersions.length > 1) {
3775
+ issueWarning$3('multiple-versions', `Multiple versions of Lit loaded. Loading multiple versions ` +
3776
+ `is not recommended.`);
3777
+ }
3778
+
3779
+ /**
3780
+ * @license
3781
+ * Copyright 2017 Google LLC
3782
+ * SPDX-License-Identifier: BSD-3-Clause
3783
+ */
3784
+ /*
3785
+ * When using Closure Compiler, JSCompiler_renameProperty(property, object) is
3786
+ * replaced at compile time by the munged name for object[property]. We cannot
3787
+ * alias this function, so we have to use a small shim that has the same
3788
+ * behavior when not compiling.
3789
+ */
3790
+ /*@__INLINE__*/
3791
+ const JSCompiler_renameProperty = (prop, _obj) => prop;
3792
+ let issueWarning$2;
3793
+ {
3794
+ // Ensure warnings are issued only 1x, even if multiple versions of Lit
3795
+ // are loaded.
3796
+ const issuedWarnings = (globalThis.litIssuedWarnings ??= new Set());
3797
+ // Issue a warning, if we haven't already.
3798
+ issueWarning$2 = (code, warning) => {
3799
+ warning += ` See https://lit.dev/msg/${code} for more information.`;
3800
+ if (!issuedWarnings.has(warning)) {
3801
+ console.warn(warning);
3802
+ issuedWarnings.add(warning);
3803
+ }
3804
+ };
3805
+ }
3806
+ /**
3807
+ * Base element class that manages element properties and attributes, and
3808
+ * renders a lit-html template.
3809
+ *
3810
+ * To define a component, subclass `LitElement` and implement a
3811
+ * `render` method to provide the component's template. Define properties
3812
+ * using the {@linkcode LitElement.properties properties} property or the
3813
+ * {@linkcode property} decorator.
3814
+ */
3815
+ class LitElement extends ReactiveElement {
3816
+ constructor() {
3817
+ super(...arguments);
3818
+ /**
3819
+ * @category rendering
3820
+ */
3821
+ this.renderOptions = { host: this };
3822
+ this.__childPart = undefined;
3823
+ }
3824
+ /**
3825
+ * @category rendering
3826
+ */
3827
+ createRenderRoot() {
3828
+ const renderRoot = super.createRenderRoot();
3829
+ // When adoptedStyleSheets are shimmed, they are inserted into the
3830
+ // shadowRoot by createRenderRoot. Adjust the renderBefore node so that
3831
+ // any styles in Lit content render before adoptedStyleSheets. This is
3832
+ // important so that adoptedStyleSheets have precedence over styles in
3833
+ // the shadowRoot.
3834
+ this.renderOptions.renderBefore ??= renderRoot.firstChild;
3835
+ return renderRoot;
3836
+ }
3837
+ /**
3838
+ * Updates the element. This method reflects property values to attributes
3839
+ * and calls `render` to render DOM via lit-html. Setting properties inside
3840
+ * this method will *not* trigger another update.
3841
+ * @param changedProperties Map of changed properties with old values
3842
+ * @category updates
3843
+ */
3844
+ update(changedProperties) {
3845
+ // Setting properties in `render` should not trigger an update. Since
3846
+ // updates are allowed after super.update, it's important to call `render`
3847
+ // before that.
3848
+ const value = this.render();
3849
+ if (!this.hasUpdated) {
3850
+ this.renderOptions.isConnected = this.isConnected;
3851
+ }
3852
+ super.update(changedProperties);
3853
+ this.__childPart = render(value, this.renderRoot, this.renderOptions);
3854
+ }
3855
+ /**
3856
+ * Invoked when the component is added to the document's DOM.
3857
+ *
3858
+ * In `connectedCallback()` you should setup tasks that should only occur when
3859
+ * the element is connected to the document. The most common of these is
3860
+ * adding event listeners to nodes external to the element, like a keydown
3861
+ * event handler added to the window.
3862
+ *
3863
+ * ```ts
3864
+ * connectedCallback() {
3865
+ * super.connectedCallback();
3866
+ * addEventListener('keydown', this._handleKeydown);
3867
+ * }
3868
+ * ```
3869
+ *
3870
+ * Typically, anything done in `connectedCallback()` should be undone when the
3871
+ * element is disconnected, in `disconnectedCallback()`.
3872
+ *
3873
+ * @category lifecycle
3874
+ */
3875
+ connectedCallback() {
3876
+ super.connectedCallback();
3877
+ this.__childPart?.setConnected(true);
3878
+ }
3879
+ /**
3880
+ * Invoked when the component is removed from the document's DOM.
3881
+ *
3882
+ * This callback is the main signal to the element that it may no longer be
3883
+ * used. `disconnectedCallback()` should ensure that nothing is holding a
3884
+ * reference to the element (such as event listeners added to nodes external
3885
+ * to the element), so that it is free to be garbage collected.
3886
+ *
3887
+ * ```ts
3888
+ * disconnectedCallback() {
3889
+ * super.disconnectedCallback();
3890
+ * window.removeEventListener('keydown', this._handleKeydown);
3891
+ * }
3892
+ * ```
3893
+ *
3894
+ * An element may be re-connected after being disconnected.
3895
+ *
3896
+ * @category lifecycle
3897
+ */
3898
+ disconnectedCallback() {
3899
+ super.disconnectedCallback();
3900
+ this.__childPart?.setConnected(false);
3901
+ }
3902
+ /**
3903
+ * Invoked on each update to perform rendering tasks. This method may return
3904
+ * any value renderable by lit-html's `ChildPart` - typically a
3905
+ * `TemplateResult`. Setting properties inside this method will *not* trigger
3906
+ * the element to update.
3907
+ * @category rendering
3908
+ */
3909
+ render() {
3910
+ return noChange;
3911
+ }
3912
+ }
3913
+ // This property needs to remain unminified.
3914
+ LitElement['_$litElement$'] = true;
3915
+ /**
3916
+ * Ensure this class is marked as `finalized` as an optimization ensuring
3917
+ * it will not needlessly try to `finalize`.
3918
+ *
3919
+ * Note this property name is a string to prevent breaking Closure JS Compiler
3920
+ * optimizations. See @lit/reactive-element for more information.
3921
+ */
3922
+ LitElement[JSCompiler_renameProperty('finalized')] = true;
3923
+ // Install hydration if available
3924
+ globalThis.litElementHydrateSupport?.({ LitElement });
3925
+ // Apply polyfills if available
3926
+ const polyfillSupport = globalThis.litElementPolyfillSupportDevMode
3927
+ ;
3928
+ polyfillSupport?.({ LitElement });
3929
+ // IMPORTANT: do not change the property name or the assignment expression.
3930
+ // This line will be used in regexes to search for LitElement usage.
3931
+ (globalThis.litElementVersions ??= []).push('4.1.0');
3932
+ if (globalThis.litElementVersions.length > 1) {
3933
+ issueWarning$2('multiple-versions', `Multiple versions of Lit loaded. Loading multiple versions ` +
3934
+ `is not recommended.`);
3935
+ }
3936
+
3937
+ /**
3938
+ * @license
3939
+ * Copyright 2017 Google LLC
3940
+ * SPDX-License-Identifier: BSD-3-Clause
3941
+ */
3942
+ let issueWarning$1;
3943
+ {
3944
+ // Ensure warnings are issued only 1x, even if multiple versions of Lit
3945
+ // are loaded.
3946
+ const issuedWarnings = (globalThis.litIssuedWarnings ??= new Set());
3947
+ // Issue a warning, if we haven't already.
3948
+ issueWarning$1 = (code, warning) => {
3949
+ warning += ` See https://lit.dev/msg/${code} for more information.`;
3950
+ if (!issuedWarnings.has(warning)) {
3951
+ console.warn(warning);
3952
+ issuedWarnings.add(warning);
3953
+ }
3954
+ };
3955
+ }
3956
+ const legacyProperty = (options, proto, name) => {
3957
+ const hasOwnProperty = proto.hasOwnProperty(name);
3958
+ proto.constructor.createProperty(name, hasOwnProperty ? { ...options, wrapped: true } : options);
3959
+ // For accessors (which have a descriptor on the prototype) we need to
3960
+ // return a descriptor, otherwise TypeScript overwrites the descriptor we
3961
+ // define in createProperty() with the original descriptor. We don't do this
3962
+ // for fields, which don't have a descriptor, because this could overwrite
3963
+ // descriptor defined by other decorators.
3964
+ return hasOwnProperty
3965
+ ? Object.getOwnPropertyDescriptor(proto, name)
3966
+ : undefined;
3967
+ };
3968
+ // This is duplicated from a similar variable in reactive-element.ts, but
3969
+ // actually makes sense to have this default defined with the decorator, so
3970
+ // that different decorators could have different defaults.
3971
+ const defaultPropertyDeclaration = {
3972
+ attribute: true,
3973
+ type: String,
3974
+ converter: defaultConverter$1,
3975
+ reflect: false,
3976
+ hasChanged: notEqual$1,
3977
+ };
3978
+ /**
3979
+ * Wraps a class accessor or setter so that `requestUpdate()` is called with the
3980
+ * property name and old value when the accessor is set.
3981
+ */
3982
+ const standardProperty = (options = defaultPropertyDeclaration, target, context) => {
3983
+ const { kind, metadata } = context;
3984
+ if (metadata == null) {
3985
+ issueWarning$1('missing-class-metadata', `The class ${target} is missing decorator metadata. This ` +
3986
+ `could mean that you're using a compiler that supports decorators ` +
3987
+ `but doesn't support decorator metadata, such as TypeScript 5.1. ` +
3988
+ `Please update your compiler.`);
3989
+ }
3990
+ // Store the property options
3991
+ let properties = globalThis.litPropertyMetadata.get(metadata);
3992
+ if (properties === undefined) {
3993
+ globalThis.litPropertyMetadata.set(metadata, (properties = new Map()));
3994
+ }
3995
+ properties.set(context.name, options);
3996
+ if (kind === 'accessor') {
3997
+ // Standard decorators cannot dynamically modify the class, so we can't
3998
+ // replace a field with accessors. The user must use the new `accessor`
3999
+ // keyword instead.
4000
+ const { name } = context;
4001
+ return {
4002
+ set(v) {
4003
+ const oldValue = target.get.call(this);
4004
+ target.set.call(this, v);
4005
+ this.requestUpdate(name, oldValue, options);
4006
+ },
4007
+ init(v) {
4008
+ if (v !== undefined) {
4009
+ this._$changeProperty(name, undefined, options);
4010
+ }
4011
+ return v;
4012
+ },
4013
+ };
4014
+ }
4015
+ else if (kind === 'setter') {
4016
+ const { name } = context;
4017
+ return function (value) {
4018
+ const oldValue = this[name];
4019
+ target.call(this, value);
4020
+ this.requestUpdate(name, oldValue, options);
4021
+ };
4022
+ }
4023
+ throw new Error(`Unsupported decorator location: ${kind}`);
4024
+ };
4025
+ /**
4026
+ * A class field or accessor decorator which creates a reactive property that
4027
+ * reflects a corresponding attribute value. When a decorated property is set
4028
+ * the element will update and render. A {@linkcode PropertyDeclaration} may
4029
+ * optionally be supplied to configure property features.
4030
+ *
4031
+ * This decorator should only be used for public fields. As public fields,
4032
+ * properties should be considered as primarily settable by element users,
4033
+ * either via attribute or the property itself.
4034
+ *
4035
+ * Generally, properties that are changed by the element should be private or
4036
+ * protected fields and should use the {@linkcode state} decorator.
4037
+ *
4038
+ * However, sometimes element code does need to set a public property. This
4039
+ * should typically only be done in response to user interaction, and an event
4040
+ * should be fired informing the user; for example, a checkbox sets its
4041
+ * `checked` property when clicked and fires a `changed` event. Mutating public
4042
+ * properties should typically not be done for non-primitive (object or array)
4043
+ * properties. In other cases when an element needs to manage state, a private
4044
+ * property decorated via the {@linkcode state} decorator should be used. When
4045
+ * needed, state properties can be initialized via public properties to
4046
+ * facilitate complex interactions.
4047
+ *
4048
+ * ```ts
4049
+ * class MyElement {
4050
+ * @property({ type: Boolean })
4051
+ * clicked = false;
4052
+ * }
4053
+ * ```
4054
+ * @category Decorator
4055
+ * @ExportDecoratedItems
4056
+ */
4057
+ function property(options) {
4058
+ return (protoOrTarget, nameOrContext
4059
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4060
+ ) => {
4061
+ return (typeof nameOrContext === 'object'
4062
+ ? standardProperty(options, protoOrTarget, nameOrContext)
4063
+ : legacyProperty(options, protoOrTarget, nameOrContext));
4064
+ };
4065
+ }
4066
+
4067
+ /**
4068
+ * @license
4069
+ * Copyright 2017 Google LLC
4070
+ * SPDX-License-Identifier: BSD-3-Clause
4071
+ */
4072
+ /**
4073
+ * Declares a private or protected reactive property that still triggers
4074
+ * updates to the element when it changes. It does not reflect from the
4075
+ * corresponding attribute.
4076
+ *
4077
+ * Properties declared this way must not be used from HTML or HTML templating
4078
+ * systems, they're solely for properties internal to the element. These
4079
+ * properties may be renamed by optimization tools like closure compiler.
4080
+ * @category Decorator
4081
+ */
4082
+ function state(options) {
4083
+ return property({
4084
+ ...options,
4085
+ // Add both `state` and `attribute` because we found a third party
4086
+ // controller that is keying off of PropertyOptions.state to determine
4087
+ // whether a field is a private internal property or not.
4088
+ state: true,
4089
+ attribute: false,
4090
+ });
4091
+ }
4092
+
4093
+ /**
4094
+ * @license
4095
+ * Copyright 2017 Google LLC
4096
+ * SPDX-License-Identifier: BSD-3-Clause
4097
+ */
4098
+ /**
4099
+ * Wraps up a few best practices when returning a property descriptor from a
4100
+ * decorator.
4101
+ *
4102
+ * Marks the defined property as configurable, and enumerable, and handles
4103
+ * the case where we have a busted Reflect.decorate zombiefill (e.g. in Angular
4104
+ * apps).
4105
+ *
4106
+ * @internal
4107
+ */
4108
+ const desc = (obj, name, descriptor) => {
4109
+ // For backwards compatibility, we keep them configurable and enumerable.
4110
+ descriptor.configurable = true;
4111
+ descriptor.enumerable = true;
4112
+ if (
4113
+ // We check for Reflect.decorate each time, in case the zombiefill
4114
+ // is applied via lazy loading some Angular code.
4115
+ Reflect.decorate &&
4116
+ typeof name !== 'object') {
4117
+ // If we're called as a legacy decorator, and Reflect.decorate is present
4118
+ // then we have no guarantees that the returned descriptor will be
4119
+ // defined on the class, so we must apply it directly ourselves.
4120
+ Object.defineProperty(obj, name, descriptor);
4121
+ }
4122
+ return descriptor;
4123
+ };
4124
+
4125
+ /**
4126
+ * @license
4127
+ * Copyright 2017 Google LLC
4128
+ * SPDX-License-Identifier: BSD-3-Clause
4129
+ */
4130
+ let issueWarning;
4131
+ {
4132
+ // Ensure warnings are issued only 1x, even if multiple versions of Lit
4133
+ // are loaded.
4134
+ const issuedWarnings = (globalThis.litIssuedWarnings ??= new Set());
4135
+ // Issue a warning, if we haven't already.
4136
+ issueWarning = (code, warning) => {
4137
+ warning += code
4138
+ ? ` See https://lit.dev/msg/${code} for more information.`
4139
+ : '';
4140
+ if (!issuedWarnings.has(warning)) {
4141
+ console.warn(warning);
4142
+ issuedWarnings.add(warning);
4143
+ }
4144
+ };
4145
+ }
4146
+ /**
4147
+ * A property decorator that converts a class property into a getter that
4148
+ * executes a querySelector on the element's renderRoot.
4149
+ *
4150
+ * @param selector A DOMString containing one or more selectors to match.
4151
+ * @param cache An optional boolean which when true performs the DOM query only
4152
+ * once and caches the result.
4153
+ *
4154
+ * See: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
4155
+ *
4156
+ * ```ts
4157
+ * class MyElement {
4158
+ * @query('#first')
4159
+ * first: HTMLDivElement;
4160
+ *
4161
+ * render() {
4162
+ * return html`
4163
+ * <div id="first"></div>
4164
+ * <div id="second"></div>
4165
+ * `;
4166
+ * }
4167
+ * }
4168
+ * ```
4169
+ * @category Decorator
4170
+ */
4171
+ function query(selector, cache) {
4172
+ return ((protoOrTarget, nameOrContext, descriptor) => {
4173
+ const doQuery = (el) => {
4174
+ const result = (el.renderRoot?.querySelector(selector) ?? null);
4175
+ if (result === null && cache && !el.hasUpdated) {
4176
+ const name = typeof nameOrContext === 'object'
4177
+ ? nameOrContext.name
4178
+ : nameOrContext;
4179
+ issueWarning('', `@query'd field ${JSON.stringify(String(name))} with the 'cache' ` +
4180
+ `flag set for selector '${selector}' has been accessed before ` +
4181
+ `the first update and returned null. This is expected if the ` +
4182
+ `renderRoot tree has not been provided beforehand (e.g. via ` +
4183
+ `Declarative Shadow DOM). Therefore the value hasn't been cached.`);
4184
+ }
4185
+ // TODO: if we want to allow users to assert that the query will never
4186
+ // return null, we need a new option and to throw here if the result
4187
+ // is null.
4188
+ return result;
4189
+ };
4190
+ if (cache) {
4191
+ // Accessors to wrap from either:
4192
+ // 1. The decorator target, in the case of standard decorators
4193
+ // 2. The property descriptor, in the case of experimental decorators
4194
+ // on auto-accessors.
4195
+ // 3. Functions that access our own cache-key property on the instance,
4196
+ // in the case of experimental decorators on fields.
4197
+ const { get, set } = typeof nameOrContext === 'object'
4198
+ ? protoOrTarget
4199
+ : descriptor ??
4200
+ (() => {
4201
+ const key = Symbol(`${String(nameOrContext)} (@query() cache)`)
4202
+ ;
4203
+ return {
4204
+ get() {
4205
+ return this[key];
4206
+ },
4207
+ set(v) {
4208
+ this[key] = v;
4209
+ },
4210
+ };
4211
+ })();
4212
+ return desc(protoOrTarget, nameOrContext, {
4213
+ get() {
4214
+ let result = get.call(this);
4215
+ if (result === undefined) {
4216
+ result = doQuery(this);
4217
+ if (result !== null || this.hasUpdated) {
4218
+ set.call(this, result);
4219
+ }
4220
+ }
4221
+ return result;
4222
+ },
4223
+ });
4224
+ }
4225
+ else {
4226
+ // This object works as the return type for both standard and
4227
+ // experimental decorators.
4228
+ return desc(protoOrTarget, nameOrContext, {
4229
+ get() {
4230
+ return doQuery(this);
4231
+ },
4232
+ });
4233
+ }
4234
+ });
4235
+ }
4236
+
4237
+ /**
4238
+ * @license
4239
+ * Copyright 2017 Google LLC
4240
+ * SPDX-License-Identifier: BSD-3-Clause
4241
+ */
4242
+ // Note, in the future, we may extend this decorator to support the use case
4243
+ // where the queried element may need to do work to become ready to interact
4244
+ // with (e.g. load some implementation code). If so, we might elect to
4245
+ // add a second argument defining a function that can be run to make the
4246
+ // queried element loaded/updated/ready.
4247
+ /**
4248
+ * A property decorator that converts a class property into a getter that
4249
+ * returns a promise that resolves to the result of a querySelector on the
4250
+ * element's renderRoot done after the element's `updateComplete` promise
4251
+ * resolves. When the queried property may change with element state, this
4252
+ * decorator can be used instead of requiring users to await the
4253
+ * `updateComplete` before accessing the property.
4254
+ *
4255
+ * @param selector A DOMString containing one or more selectors to match.
4256
+ *
4257
+ * See: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
4258
+ *
4259
+ * ```ts
4260
+ * class MyElement {
4261
+ * @queryAsync('#first')
4262
+ * first: Promise<HTMLDivElement>;
4263
+ *
4264
+ * render() {
4265
+ * return html`
4266
+ * <div id="first"></div>
4267
+ * <div id="second"></div>
4268
+ * `;
4269
+ * }
4270
+ * }
4271
+ *
4272
+ * // external usage
4273
+ * async doSomethingWithFirst() {
4274
+ * (await aMyElement.first).doSomething();
4275
+ * }
4276
+ * ```
4277
+ * @category Decorator
4278
+ */
4279
+ function queryAsync(selector) {
4280
+ return ((obj, name) => {
4281
+ return desc(obj, name, {
4282
+ async get() {
4283
+ await this.updateComplete;
4284
+ return this.renderRoot?.querySelector(selector) ?? null;
4285
+ },
4286
+ });
4287
+ });
4288
+ }
4289
+
4290
+ /**
4291
+ * @license
4292
+ * Copyright 2017 Google LLC
4293
+ * SPDX-License-Identifier: BSD-3-Clause
4294
+ */
4295
+ const PartType = {
4296
+ ATTRIBUTE: 1,
4297
+ CHILD: 2,
4298
+ PROPERTY: 3,
4299
+ BOOLEAN_ATTRIBUTE: 4,
4300
+ EVENT: 5,
4301
+ ELEMENT: 6,
4302
+ };
4303
+ /**
4304
+ * Creates a user-facing directive function from a Directive class. This
4305
+ * function has the same parameters as the directive's render() method.
4306
+ */
4307
+ const directive = (c) => (...values) => ({
4308
+ // This property needs to remain unminified.
4309
+ ['_$litDirective$']: c,
4310
+ values,
4311
+ });
4312
+ /**
4313
+ * Base class for creating custom directives. Users should extend this class,
4314
+ * implement `render` and/or `update`, and then pass their subclass to
4315
+ * `directive`.
4316
+ */
4317
+ class Directive {
4318
+ constructor(_partInfo) { }
4319
+ // See comment in Disconnectable interface for why this is a getter
4320
+ get _$isConnected() {
4321
+ return this._$parent._$isConnected;
4322
+ }
4323
+ /** @internal */
4324
+ _$initialize(part, parent, attributeIndex) {
4325
+ this.__part = part;
4326
+ this._$parent = parent;
4327
+ this.__attributeIndex = attributeIndex;
4328
+ }
4329
+ /** @internal */
4330
+ _$resolve(part, props) {
4331
+ return this.update(part, props);
4332
+ }
4333
+ update(_part, props) {
4334
+ return this.render(...props);
4335
+ }
4336
+ }
4337
+
4338
+ /**
4339
+ * @license
4340
+ * Copyright 2018 Google LLC
4341
+ * SPDX-License-Identifier: BSD-3-Clause
4342
+ */
4343
+ class ClassMapDirective extends Directive {
4344
+ constructor(partInfo) {
4345
+ super(partInfo);
4346
+ if (partInfo.type !== PartType.ATTRIBUTE ||
4347
+ partInfo.name !== 'class' ||
4348
+ partInfo.strings?.length > 2) {
4349
+ throw new Error('`classMap()` can only be used in the `class` attribute ' +
4350
+ 'and must be the only part in the attribute.');
4351
+ }
4352
+ }
4353
+ render(classInfo) {
4354
+ // Add spaces to ensure separation from static classes
4355
+ return (' ' +
4356
+ Object.keys(classInfo)
4357
+ .filter((key) => classInfo[key])
4358
+ .join(' ') +
4359
+ ' ');
4360
+ }
4361
+ update(part, [classInfo]) {
4362
+ // Remember dynamic classes on the first render
4363
+ if (this._previousClasses === undefined) {
4364
+ this._previousClasses = new Set();
4365
+ if (part.strings !== undefined) {
4366
+ this._staticClasses = new Set(part.strings
4367
+ .join(' ')
4368
+ .split(/\s/)
4369
+ .filter((s) => s !== ''));
4370
+ }
4371
+ for (const name in classInfo) {
4372
+ if (classInfo[name] && !this._staticClasses?.has(name)) {
4373
+ this._previousClasses.add(name);
4374
+ }
4375
+ }
4376
+ return this.render(classInfo);
4377
+ }
4378
+ const classList = part.element.classList;
4379
+ // Remove old classes that no longer apply
4380
+ for (const name of this._previousClasses) {
4381
+ if (!(name in classInfo)) {
4382
+ classList.remove(name);
4383
+ this._previousClasses.delete(name);
4384
+ }
4385
+ }
4386
+ // Add or remove classes based on their classMap value
4387
+ for (const name in classInfo) {
4388
+ // We explicitly want a loose truthy check of `value` because it seems
4389
+ // more convenient that '' and 0 are skipped.
4390
+ const value = !!classInfo[name];
4391
+ if (value !== this._previousClasses.has(name) &&
4392
+ !this._staticClasses?.has(name)) {
4393
+ if (value) {
4394
+ classList.add(name);
4395
+ this._previousClasses.add(name);
4396
+ }
4397
+ else {
4398
+ classList.remove(name);
4399
+ this._previousClasses.delete(name);
4400
+ }
4401
+ }
4402
+ }
4403
+ return noChange;
4404
+ }
4405
+ }
4406
+ /**
4407
+ * A directive that applies dynamic CSS classes.
4408
+ *
4409
+ * This must be used in the `class` attribute and must be the only part used in
4410
+ * the attribute. It takes each property in the `classInfo` argument and adds
4411
+ * the property name to the element's `classList` if the property value is
4412
+ * truthy; if the property value is falsy, the property name is removed from
4413
+ * the element's `class`.
4414
+ *
4415
+ * For example `{foo: bar}` applies the class `foo` if the value of `bar` is
4416
+ * truthy.
4417
+ *
4418
+ * @param classInfo
4419
+ */
4420
+ const classMap = directive(ClassMapDirective);
4421
+
4422
+ /**
4423
+ * @license
4424
+ * Copyright 2018 Google LLC
4425
+ * SPDX-License-Identifier: BSD-3-Clause
4426
+ */
4427
+ /**
4428
+ * For AttributeParts, sets the attribute if the value is defined and removes
4429
+ * the attribute if the value is undefined.
4430
+ *
4431
+ * For other part types, this directive is a no-op.
4432
+ */
4433
+ const ifDefined = (value) => value ?? nothing;
4434
+
4435
+ /**
4436
+ * @license
4437
+ * Copyright 2020 Google LLC
4438
+ * SPDX-License-Identifier: BSD-3-Clause
4439
+ */
4440
+ window.ShadyDOM?.inUse &&
4441
+ window.ShadyDOM?.noPatch === true
4442
+ ? window.ShadyDOM.wrap
4443
+ : (node) => node;
4444
+ /**
4445
+ * Tests whether a part has only a single-expression with no strings to
4446
+ * interpolate between.
4447
+ *
4448
+ * Only AttributePart and PropertyPart can have multiple expressions.
4449
+ * Multi-expression parts have a `strings` property and single-expression
4450
+ * parts do not.
4339
4451
  */
4340
- ReactiveElement.elementStyles = [];
4452
+ const isSingleExpression = (part) => part.strings === undefined;
4453
+ // A sentinel value that can never appear as a part value except when set by
4454
+ // live(). Used to force a dirty-check to fail and cause a re-render.
4455
+ const RESET_VALUE = {};
4341
4456
  /**
4342
- * Options used when calling `attachShadow`. Set this property to customize
4343
- * the options for the shadowRoot; for example, to create a closed
4344
- * shadowRoot: `{mode: 'closed'}`.
4457
+ * Sets the committed value of a ChildPart directly without triggering the
4458
+ * commit stage of the part.
4345
4459
  *
4346
- * Note, these options are used in `createRenderRoot`. If this method
4347
- * is customized, options should be respected if possible.
4348
- * @nocollapse
4349
- * @category rendering
4460
+ * This is useful in cases where a directive needs to update the part such
4461
+ * that the next update detects a value change or not. When value is omitted,
4462
+ * the next update will be guaranteed to be detected as a change.
4463
+ *
4464
+ * @param part
4465
+ * @param value
4350
4466
  */
4351
- ReactiveElement.shadowRootOptions = { mode: 'open' };
4352
- // Assigned here to work around a jscompiler bug with static fields
4353
- // when compiling to ES5.
4354
- // https://github.com/google/closure-compiler/issues/3177
4355
- ReactiveElement[JSCompiler_renameProperty$1('elementProperties')] = new Map();
4356
- ReactiveElement[JSCompiler_renameProperty$1('finalized')] = new Map();
4357
- // Apply polyfills if available
4358
- polyfillSupport$1?.({ ReactiveElement });
4359
- // Dev mode warnings...
4360
- {
4361
- // Default warning set.
4362
- ReactiveElement.enabledWarnings = [
4363
- 'change-in-update',
4364
- 'async-perform-update',
4365
- ];
4366
- const ensureOwnWarnings = function (ctor) {
4367
- if (!ctor.hasOwnProperty(JSCompiler_renameProperty$1('enabledWarnings'))) {
4368
- ctor.enabledWarnings = ctor.enabledWarnings.slice();
4467
+ const setCommittedValue = (part, value = RESET_VALUE) => (part._$committedValue = value);
4468
+
4469
+ /**
4470
+ * @license
4471
+ * Copyright 2020 Google LLC
4472
+ * SPDX-License-Identifier: BSD-3-Clause
4473
+ */
4474
+ class LiveDirective extends Directive {
4475
+ constructor(partInfo) {
4476
+ super(partInfo);
4477
+ if (!(partInfo.type === PartType.PROPERTY ||
4478
+ partInfo.type === PartType.ATTRIBUTE ||
4479
+ partInfo.type === PartType.BOOLEAN_ATTRIBUTE)) {
4480
+ throw new Error('The `live` directive is not allowed on child or event bindings');
4369
4481
  }
4370
- };
4371
- ReactiveElement.enableWarning = function (warning) {
4372
- ensureOwnWarnings(this);
4373
- if (!this.enabledWarnings.includes(warning)) {
4374
- this.enabledWarnings.push(warning);
4482
+ if (!isSingleExpression(partInfo)) {
4483
+ throw new Error('`live` bindings can only contain a single expression');
4375
4484
  }
4376
- };
4377
- ReactiveElement.disableWarning = function (warning) {
4378
- ensureOwnWarnings(this);
4379
- const i = this.enabledWarnings.indexOf(warning);
4380
- if (i >= 0) {
4381
- this.enabledWarnings.splice(i, 1);
4485
+ }
4486
+ render(value) {
4487
+ return value;
4488
+ }
4489
+ update(part, [value]) {
4490
+ if (value === noChange || value === nothing) {
4491
+ return value;
4382
4492
  }
4383
- };
4384
- }
4385
- // IMPORTANT: do not change the property name or the assignment expression.
4386
- // This line will be used in regexes to search for ReactiveElement usage.
4387
- (global.reactiveElementVersions ??= []).push('2.0.4');
4388
- if (global.reactiveElementVersions.length > 1) {
4389
- issueWarning$1('multiple-versions', `Multiple versions of Lit loaded. Loading multiple versions ` +
4390
- `is not recommended.`);
4493
+ const element = part.element;
4494
+ const name = part.name;
4495
+ if (part.type === PartType.PROPERTY) {
4496
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4497
+ if (value === element[name]) {
4498
+ return noChange;
4499
+ }
4500
+ }
4501
+ else if (part.type === PartType.BOOLEAN_ATTRIBUTE) {
4502
+ if (!!value === element.hasAttribute(name)) {
4503
+ return noChange;
4504
+ }
4505
+ }
4506
+ else if (part.type === PartType.ATTRIBUTE) {
4507
+ if (element.getAttribute(name) === String(value)) {
4508
+ return noChange;
4509
+ }
4510
+ }
4511
+ // Resets the part's value, causing its dirty-check to fail so that it
4512
+ // always sets the value.
4513
+ setCommittedValue(part);
4514
+ return value;
4515
+ }
4391
4516
  }
4517
+ /**
4518
+ * Checks binding values against live DOM values, instead of previously bound
4519
+ * values, when determining whether to update the value.
4520
+ *
4521
+ * This is useful for cases where the DOM value may change from outside of
4522
+ * lit-html, such as with a binding to an `<input>` element's `value` property,
4523
+ * a content editable elements text, or to a custom element that changes it's
4524
+ * own properties or attributes.
4525
+ *
4526
+ * In these cases if the DOM value changes, but the value set through lit-html
4527
+ * bindings hasn't, lit-html won't know to update the DOM value and will leave
4528
+ * it alone. If this is not what you want--if you want to overwrite the DOM
4529
+ * value with the bound value no matter what--use the `live()` directive:
4530
+ *
4531
+ * ```js
4532
+ * html`<input .value=${live(x)}>`
4533
+ * ```
4534
+ *
4535
+ * `live()` performs a strict equality check against the live DOM value, and if
4536
+ * the new value is equal to the live value, does nothing. This means that
4537
+ * `live()` should not be used when the binding will cause a type conversion. If
4538
+ * you use `live()` with an attribute binding, make sure that only strings are
4539
+ * passed in, or the binding will update every render.
4540
+ */
4541
+ const live = directive(LiveDirective);
4392
4542
 
4393
4543
  /**
4394
4544
  * @license
4395
- * Copyright 2017 Google LLC
4545
+ * Copyright 2020 Google LLC
4396
4546
  * SPDX-License-Identifier: BSD-3-Clause
4397
4547
  */
4398
- /*
4399
- * When using Closure Compiler, JSCompiler_renameProperty(property, object) is
4400
- * replaced at compile time by the munged name for object[property]. We cannot
4401
- * alias this function, so we have to use a small shim that has the same
4402
- * behavior when not compiling.
4403
- */
4404
- /*@__INLINE__*/
4405
- const JSCompiler_renameProperty = (prop, _obj) => prop;
4406
- let issueWarning;
4407
- {
4408
- // Ensure warnings are issued only 1x, even if multiple versions of Lit
4409
- // are loaded.
4410
- const issuedWarnings = (globalThis.litIssuedWarnings ??= new Set());
4411
- // Issue a warning, if we haven't already.
4412
- issueWarning = (code, warning) => {
4413
- warning += ` See https://lit.dev/msg/${code} for more information.`;
4414
- if (!issuedWarnings.has(warning)) {
4415
- console.warn(warning);
4416
- issuedWarnings.add(warning);
4417
- }
4418
- };
4419
- }
4420
4548
  /**
4421
- * Base element class that manages element properties and attributes, and
4422
- * renders a lit-html template.
4549
+ * Prevents JSON injection attacks.
4423
4550
  *
4424
- * To define a component, subclass `LitElement` and implement a
4425
- * `render` method to provide the component's template. Define properties
4426
- * using the {@linkcode LitElement.properties properties} property or the
4427
- * {@linkcode property} decorator.
4551
+ * The goals of this brand:
4552
+ * 1) fast to check
4553
+ * 2) code is small on the wire
4554
+ * 3) multiple versions of Lit in a single page will all produce mutually
4555
+ * interoperable StaticValues
4556
+ * 4) normal JSON.parse (without an unusual reviver) can not produce a
4557
+ * StaticValue
4558
+ *
4559
+ * Symbols satisfy (1), (2), and (4). We use Symbol.for to satisfy (3), but
4560
+ * we don't care about the key, so we break ties via (2) and use the empty
4561
+ * string.
4428
4562
  */
4429
- class LitElement extends ReactiveElement {
4430
- constructor() {
4431
- super(...arguments);
4432
- /**
4433
- * @category rendering
4434
- */
4435
- this.renderOptions = { host: this };
4436
- this.__childPart = undefined;
4437
- }
4438
- /**
4439
- * @category rendering
4440
- */
4441
- createRenderRoot() {
4442
- const renderRoot = super.createRenderRoot();
4443
- // When adoptedStyleSheets are shimmed, they are inserted into the
4444
- // shadowRoot by createRenderRoot. Adjust the renderBefore node so that
4445
- // any styles in Lit content render before adoptedStyleSheets. This is
4446
- // important so that adoptedStyleSheets have precedence over styles in
4447
- // the shadowRoot.
4448
- this.renderOptions.renderBefore ??= renderRoot.firstChild;
4449
- return renderRoot;
4450
- }
4451
- /**
4452
- * Updates the element. This method reflects property values to attributes
4453
- * and calls `render` to render DOM via lit-html. Setting properties inside
4454
- * this method will *not* trigger another update.
4455
- * @param changedProperties Map of changed properties with old values
4456
- * @category updates
4457
- */
4458
- update(changedProperties) {
4459
- // Setting properties in `render` should not trigger an update. Since
4460
- // updates are allowed after super.update, it's important to call `render`
4461
- // before that.
4462
- const value = this.render();
4463
- if (!this.hasUpdated) {
4464
- this.renderOptions.isConnected = this.isConnected;
4465
- }
4466
- super.update(changedProperties);
4467
- this.__childPart = render(value, this.renderRoot, this.renderOptions);
4563
+ const brand = Symbol.for('');
4564
+ /** Safely extracts the string part of a StaticValue. */
4565
+ const unwrapStaticValue = (value) => {
4566
+ if (value?.r !== brand) {
4567
+ return undefined;
4468
4568
  }
4469
- /**
4470
- * Invoked when the component is added to the document's DOM.
4471
- *
4472
- * In `connectedCallback()` you should setup tasks that should only occur when
4473
- * the element is connected to the document. The most common of these is
4474
- * adding event listeners to nodes external to the element, like a keydown
4475
- * event handler added to the window.
4476
- *
4477
- * ```ts
4478
- * connectedCallback() {
4479
- * super.connectedCallback();
4480
- * addEventListener('keydown', this._handleKeydown);
4481
- * }
4482
- * ```
4483
- *
4484
- * Typically, anything done in `connectedCallback()` should be undone when the
4485
- * element is disconnected, in `disconnectedCallback()`.
4486
- *
4487
- * @category lifecycle
4488
- */
4489
- connectedCallback() {
4490
- super.connectedCallback();
4491
- this.__childPart?.setConnected(true);
4569
+ return value?.['_$litStatic$'];
4570
+ };
4571
+ const stringsCache = new Map();
4572
+ /**
4573
+ * Wraps a lit-html template tag (`html` or `svg`) to add static value support.
4574
+ */
4575
+ const withStatic = (coreTag) => (strings, ...values) => {
4576
+ const l = values.length;
4577
+ let staticValue;
4578
+ let dynamicValue;
4579
+ const staticStrings = [];
4580
+ const dynamicValues = [];
4581
+ let i = 0;
4582
+ let hasStatics = false;
4583
+ let s;
4584
+ while (i < l) {
4585
+ s = strings[i];
4586
+ // Collect any unsafeStatic values, and their following template strings
4587
+ // so that we treat a run of template strings and unsafe static values as
4588
+ // a single template string.
4589
+ while (i < l &&
4590
+ ((dynamicValue = values[i]),
4591
+ (staticValue = unwrapStaticValue(dynamicValue))) !== undefined) {
4592
+ s += staticValue + strings[++i];
4593
+ hasStatics = true;
4594
+ }
4595
+ // If the last value is static, we don't need to push it.
4596
+ if (i !== l) {
4597
+ dynamicValues.push(dynamicValue);
4598
+ }
4599
+ staticStrings.push(s);
4600
+ i++;
4492
4601
  }
4493
- /**
4494
- * Invoked when the component is removed from the document's DOM.
4495
- *
4496
- * This callback is the main signal to the element that it may no longer be
4497
- * used. `disconnectedCallback()` should ensure that nothing is holding a
4498
- * reference to the element (such as event listeners added to nodes external
4499
- * to the element), so that it is free to be garbage collected.
4500
- *
4501
- * ```ts
4502
- * disconnectedCallback() {
4503
- * super.disconnectedCallback();
4504
- * window.removeEventListener('keydown', this._handleKeydown);
4505
- * }
4506
- * ```
4507
- *
4508
- * An element may be re-connected after being disconnected.
4509
- *
4510
- * @category lifecycle
4511
- */
4512
- disconnectedCallback() {
4513
- super.disconnectedCallback();
4514
- this.__childPart?.setConnected(false);
4602
+ // If the last value isn't static (which would have consumed the last
4603
+ // string), then we need to add the last string.
4604
+ if (i === l) {
4605
+ staticStrings.push(strings[l]);
4515
4606
  }
4516
- /**
4517
- * Invoked on each update to perform rendering tasks. This method may return
4518
- * any value renderable by lit-html's `ChildPart` - typically a
4519
- * `TemplateResult`. Setting properties inside this method will *not* trigger
4520
- * the element to update.
4521
- * @category rendering
4522
- */
4523
- render() {
4524
- return noChange;
4607
+ if (hasStatics) {
4608
+ const key = staticStrings.join('$$lit$$');
4609
+ strings = stringsCache.get(key);
4610
+ if (strings === undefined) {
4611
+ // Beware: in general this pattern is unsafe, and doing so may bypass
4612
+ // lit's security checks and allow an attacker to execute arbitrary
4613
+ // code and inject arbitrary content.
4614
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4615
+ staticStrings.raw = staticStrings;
4616
+ stringsCache.set(key, (strings = staticStrings));
4617
+ }
4618
+ values = dynamicValues;
4525
4619
  }
4526
- }
4527
- // This property needs to remain unminified.
4528
- LitElement['_$litElement$'] = true;
4620
+ return coreTag(strings, ...values);
4621
+ };
4529
4622
  /**
4530
- * Ensure this class is marked as `finalized` as an optimization ensuring
4531
- * it will not needlessly try to `finalize`.
4623
+ * Interprets a template literal as an HTML template that can efficiently
4624
+ * render to and update a container.
4532
4625
  *
4533
- * Note this property name is a string to prevent breaking Closure JS Compiler
4534
- * optimizations. See @lit/reactive-element for more information.
4626
+ * Includes static value support from `lit-html/static.js`.
4535
4627
  */
4536
- LitElement[JSCompiler_renameProperty('finalized')] = true;
4537
- // Install hydration if available
4538
- globalThis.litElementHydrateSupport?.({ LitElement });
4539
- // Apply polyfills if available
4540
- const polyfillSupport = globalThis.litElementPolyfillSupportDevMode
4541
- ;
4542
- polyfillSupport?.({ LitElement });
4543
- // IMPORTANT: do not change the property name or the assignment expression.
4544
- // This line will be used in regexes to search for LitElement usage.
4545
- (globalThis.litElementVersions ??= []).push('4.1.0');
4546
- if (globalThis.litElementVersions.length > 1) {
4547
- issueWarning('multiple-versions', `Multiple versions of Lit loaded. Loading multiple versions ` +
4548
- `is not recommended.`);
4549
- }
4628
+ const html = withStatic(html$1);
4629
+
4630
+ var css_248z$5 = css`.invalid-feedback-container{display:flex;gap:var(--sgds-form-gap-sm)}.invalid-feedback{color:var(--sgds-form-danger-color);font-size:var(--sgds-font-size-1);font-weight:var(--sgds-font-weight-regular)}`;
4550
4631
 
4551
- var css_248z$5 = css`:host{-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0,0,0,0);color:var(--sgds-body-color);font-family:var(--sgds-font-family-brand);font-size:var(--sgds-font-size-2);font-weight:var(--sgds-font-weight-regular);line-height:var(--sgds-line-height-heading);margin:0;*,:after,:before{box-sizing:border-box}:disabled{cursor:not-allowed}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}::slotted(a[target=_blank]):after{background-color:currentColor;content:"/";display:inline-block;margin:0 .125rem;-webkit-mask-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-box-arrow-up-right"><path fill-rule="evenodd" d="M8.636 3.5a.5.5 0 0 0-.5-.5H1.5A1.5 1.5 0 0 0 0 4.5v10A1.5 1.5 0 0 0 1.5 16h10a1.5 1.5 0 0 0 1.5-1.5V7.864a.5.5 0 0 0-1 0V14.5a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h6.636a.5.5 0 0 0 .5-.5z"/><path fill-rule="evenodd" d="M16 .5a.5.5 0 0 0-.5-.5h-5a.5.5 0 0 0 0 1h3.793L6.146 9.146a.5.5 0 1 0 .708.708L15 1.707V5.5a.5.5 0 0 0 1 0v-5z"/></svg>');mask-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-box-arrow-up-right"><path fill-rule="evenodd" d="M8.636 3.5a.5.5 0 0 0-.5-.5H1.5A1.5 1.5 0 0 0 0 4.5v10A1.5 1.5 0 0 0 1.5 16h10a1.5 1.5 0 0 0 1.5-1.5V7.864a.5.5 0 0 0-1 0V14.5a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h6.636a.5.5 0 0 0 .5-.5z"/><path fill-rule="evenodd" d="M16 .5a.5.5 0 0 0-.5-.5h-5a.5.5 0 0 0 0 1h3.793L6.146 9.146a.5.5 0 1 0 .708.708L15 1.707V5.5a.5.5 0 0 0 1 0v-5z"/></svg>');-webkit-mask-position:center;mask-position:center;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;mask-size:73%;-webkit-mask-size:73%;padding:0 .45em}::slotted(a){color:var(--sgds-link);text-decoration:var(--sgds-link-decoration)}::slotted(a:hover){color:var(--sgds-link-hover-color)}::slotted(svg){vertical-align:middle}}`;
4632
+ var css_248z$4 = css`.form-text{color:var(--sgds-form-color-subtle);font-size:var(--sgds-font-size-1)}.form-text.disabled{opacity:var(--sgds-opacity-50)}`;
4633
+
4634
+ var css_248z$3 = css`.form-label{color:var(--sgds-form-color);margin-bottom:0}.form-label.disabled{opacity:var(--sgds-opacity-50)}.form-check-label{color:var(--sgds-form-color)}.form-check-input:disabled~.form-check-label,.form-check-input[disabled]~.form-check-label{cursor:not-allowed}`;
4635
+
4636
+ var css_248z$2 = css`.form-control::placeholder{color:var(--sgds-form-color-subtle);font-family:var(--sgds-font-family-brand);font-weight:var(--sgds-font-weight-light);line-height:var(--sgds-line-height-heading)}`;
4637
+
4638
+ var css_248z$1 = css`:host{-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0,0,0,0);color:var(--sgds-body-color);font-family:var(--sgds-font-family-brand);font-size:var(--sgds-font-size-2);font-weight:var(--sgds-font-weight-regular);line-height:var(--sgds-line-height-heading);margin:0;*,:after,:before{box-sizing:border-box}:disabled{cursor:not-allowed}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}::slotted(a[target=_blank]):after{background-color:currentColor;content:"/";display:inline-block;margin:0 .125rem;-webkit-mask-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-box-arrow-up-right"><path fill-rule="evenodd" d="M8.636 3.5a.5.5 0 0 0-.5-.5H1.5A1.5 1.5 0 0 0 0 4.5v10A1.5 1.5 0 0 0 1.5 16h10a1.5 1.5 0 0 0 1.5-1.5V7.864a.5.5 0 0 0-1 0V14.5a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h6.636a.5.5 0 0 0 .5-.5z"/><path fill-rule="evenodd" d="M16 .5a.5.5 0 0 0-.5-.5h-5a.5.5 0 0 0 0 1h3.793L6.146 9.146a.5.5 0 1 0 .708.708L15 1.707V5.5a.5.5 0 0 0 1 0v-5z"/></svg>');mask-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-box-arrow-up-right"><path fill-rule="evenodd" d="M8.636 3.5a.5.5 0 0 0-.5-.5H1.5A1.5 1.5 0 0 0 0 4.5v10A1.5 1.5 0 0 0 1.5 16h10a1.5 1.5 0 0 0 1.5-1.5V7.864a.5.5 0 0 0-1 0V14.5a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h6.636a.5.5 0 0 0 .5-.5z"/><path fill-rule="evenodd" d="M16 .5a.5.5 0 0 0-.5-.5h-5a.5.5 0 0 0 0 1h3.793L6.146 9.146a.5.5 0 1 0 .708.708L15 1.707V5.5a.5.5 0 0 0 1 0v-5z"/></svg>');-webkit-mask-position:center;mask-position:center;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;mask-size:73%;-webkit-mask-size:73%;padding:0 .45em}::slotted(a){color:var(--sgds-link);text-decoration:var(--sgds-link-decoration)}::slotted(a:hover){color:var(--sgds-link-hover-color)}::slotted(svg){vertical-align:middle}}`;
4552
4639
 
4553
4640
  /**
4554
4641
  * @cssprop --sgds-{stateColor} - State colors in hexadecimal value
@@ -4566,7 +4653,53 @@
4566
4653
  return event;
4567
4654
  }
4568
4655
  }
4569
- SgdsElement.styles = [css_248z$5];
4656
+ SgdsElement.styles = [css_248z$1];
4657
+
4658
+ function generateId (componentName = "", elementName = "") {
4659
+ return `id-${Math.random().toString().substring(2, 6)}-sgds-${componentName}-${elementName}`;
4660
+ }
4661
+
4662
+ class FormControlElement extends SgdsElement {
4663
+ constructor() {
4664
+ super(...arguments);
4665
+ /** The input's label */
4666
+ this.label = "";
4667
+ /** The input's hint text */
4668
+ this.hintText = "";
4669
+ /** Disables the input. */
4670
+ this.disabled = false;
4671
+ /** Marks the component as invalid. Replace the pseudo :invalid selector for absent in custom elements */
4672
+ this.invalid = false;
4673
+ this._controlId = generateId("input");
4674
+ this._labelId = generateId("label");
4675
+ }
4676
+ /** Programatically sets the invalid state of the input. Pass in boolean value in the argument */
4677
+ setInvalid(bool) {
4678
+ this.invalid = bool;
4679
+ if (bool) {
4680
+ this.emit("sgds-invalid");
4681
+ }
4682
+ else {
4683
+ this.emit("sgds-valid");
4684
+ }
4685
+ }
4686
+ }
4687
+ FormControlElement.styles = [...SgdsElement.styles, css_248z$5, css_248z$4, css_248z$3, css_248z$2];
4688
+ __decorate([
4689
+ property({ reflect: true })
4690
+ ], FormControlElement.prototype, "label", void 0);
4691
+ __decorate([
4692
+ property({ reflect: true })
4693
+ ], FormControlElement.prototype, "hintText", void 0);
4694
+ __decorate([
4695
+ property({ reflect: true })
4696
+ ], FormControlElement.prototype, "name", void 0);
4697
+ __decorate([
4698
+ property({ type: Boolean, reflect: true })
4699
+ ], FormControlElement.prototype, "disabled", void 0);
4700
+ __decorate([
4701
+ property({ type: Boolean, reflect: true })
4702
+ ], FormControlElement.prototype, "invalid", void 0);
4570
4703
 
4571
4704
  // @defaultValue decorator
4572
4705
  const defaultValue = (propertyName = "value") => (proto, key) => {
@@ -4588,139 +4721,225 @@
4588
4721
  };
4589
4722
  };
4590
4723
 
4591
- const reportValidityOverloads = new WeakMap();
4592
- class FormSubmitController {
4724
+ /**
4725
+ * SGDS custom form validation methods and behaviours
4726
+ */
4727
+ class InputValidationController {
4593
4728
  constructor(host, options) {
4594
4729
  (this.host = host).addController(this);
4595
- this.options = Object.assign({ form: (input) => {
4596
- return input.closest("form");
4597
- }, name: (input) => input.name, value: (input) => input.value, defaultValue: (input) => input.defaultValue, disabled: (input) => input.disabled, reportValidity: (input) => {
4598
- return typeof input.reportValidity === "function" ? input.reportValidity() : true;
4599
- }, setValue: (input, value) => {
4600
- input.value = value;
4601
- } }, options);
4602
- this.handleFormData = this.handleFormData.bind(this);
4603
- this.handleFormSubmit = this.handleFormSubmit.bind(this);
4604
- this.handleFormReset = this.handleFormReset.bind(this);
4605
- this.reportFormValidity = this.reportFormValidity.bind(this);
4730
+ this._internals = this.host.attachInternals();
4731
+ this.options = Object.assign({ setInvalid: (host, value) => {
4732
+ host.invalid = value;
4733
+ }, value: (host) => {
4734
+ return host.value;
4735
+ }, input: (host) => host.input }, options);
4606
4736
  }
4607
4737
  hostConnected() {
4608
- this.form = this.options.form(this.host);
4609
- if (this.form) {
4610
- this.form.addEventListener("formdata", this.handleFormData);
4611
- this.form.addEventListener("submit", this.handleFormSubmit);
4612
- this.form.addEventListener("reset", this.handleFormReset);
4613
- // Overload the form's reportValidity() method so it looks at Shoelace form controls
4614
- if (!reportValidityOverloads.has(this.form)) {
4615
- reportValidityOverloads.set(this.form, this.form.reportValidity);
4616
- this.form.reportValidity = () => this.reportFormValidity();
4617
- }
4618
- }
4738
+ this.host.addEventListener("invalid", e => this.handleInvalid(e));
4619
4739
  }
4620
4740
  hostDisconnected() {
4621
- if (this.form) {
4622
- this.form.removeEventListener("formdata", this.handleFormData);
4623
- this.form.removeEventListener("submit", this.handleFormSubmit);
4624
- this.form.removeEventListener("reset", this.handleFormReset);
4625
- // Remove the overload and restore the original method
4626
- if (reportValidityOverloads.has(this.form)) {
4627
- this.form.reportValidity = reportValidityOverloads.get(this.form);
4628
- reportValidityOverloads.delete(this.form);
4629
- }
4630
- this.form = undefined;
4631
- }
4741
+ this.host.removeEventListener("invalid", e => this.handleInvalid(e));
4742
+ }
4743
+ /**
4744
+ * Prevents the native browser error message pop up when reportValidity() called by
4745
+ * associated form or the component's reportValidity during constraint validation
4746
+ * Sets invalid reactive prop to true
4747
+ */
4748
+ handleInvalid(e) {
4749
+ e.preventDefault();
4750
+ this.options.setInvalid(this.host, true);
4751
+ }
4752
+ /**
4753
+ * Sets invalid to false when invoked and
4754
+ * Updates the ValidityState based on new value, but
4755
+ * does not update invalid reactive prop
4756
+ * @param e
4757
+ */
4758
+ handleInput(e) {
4759
+ const input = e.target;
4760
+ this.options.setInvalid(this.host, false);
4761
+ this.validateInput(input);
4762
+ }
4763
+ /**
4764
+ * Validate the input's new value after onChange and
4765
+ * update invalid reactive prop
4766
+ * @param e
4767
+ */
4768
+ handleChange(e) {
4769
+ const input = e.target;
4770
+ this.validateInput(input);
4771
+ this.options.setInvalid(this.host, !this.checkValidity());
4772
+ }
4773
+ get form() {
4774
+ return this._internals.form;
4775
+ }
4776
+ get validity() {
4777
+ return this._internals.validity;
4778
+ }
4779
+ get validationMessage() {
4780
+ return this._internals.validationMessage;
4781
+ }
4782
+ get willValidate() {
4783
+ return this._internals.willValidate;
4784
+ }
4785
+ /**
4786
+ * Checks the validity and updates the invalid reactive prop of form components
4787
+ */
4788
+ updateInvalidState() {
4789
+ this.options.setInvalid(this.host, !this.checkValidity());
4790
+ }
4791
+ /**
4792
+ * Resets the ValidityState of the control
4793
+ */
4794
+ resetValidity() {
4795
+ return this._internals.setValidity({});
4796
+ }
4797
+ /**
4798
+ * Reports the validity
4799
+ */
4800
+ checkValidity() {
4801
+ return this._internals.checkValidity();
4802
+ }
4803
+ /**
4804
+ * Reports the validity with a error popup message
4805
+ */
4806
+ reportValidity() {
4807
+ return this._internals.reportValidity();
4632
4808
  }
4633
- handleFormData(event) {
4634
- const disabled = this.options.disabled(this.host);
4635
- const name = this.options.name(this.host);
4809
+ /**
4810
+ * Sets the form control value into FormData,
4811
+ * making the value of control accessible via FormData
4812
+ */
4813
+ setFormValue() {
4636
4814
  const value = this.options.value(this.host);
4637
- if (!disabled && typeof name === "string" && typeof value !== "undefined") {
4638
- if (Array.isArray(value)) {
4639
- value.forEach(val => {
4640
- event.formData.append(name, val.toString());
4641
- });
4642
- }
4643
- else {
4644
- event.formData.append(name, value.toString());
4645
- }
4646
- }
4815
+ this._internals.setFormValue(value);
4647
4816
  }
4648
- handleFormSubmit(event) {
4649
- const disabled = this.options.disabled(this.host);
4650
- const reportValidity = this.options.reportValidity;
4651
- if (this.form && !this.form.noValidate && !disabled && !reportValidity(this.host)) {
4652
- event.preventDefault();
4653
- event.stopImmediatePropagation();
4654
- }
4655
- }
4656
- handleFormReset() {
4657
- this.options.setValue(this.host, this.options.defaultValue(this.host));
4658
- }
4659
- reportFormValidity() {
4660
- //
4661
- // Shoelace form controls work hard to act like regular form controls. They support the Constraint Validation API
4662
- // and its associated methods such as setCustomValidity() and reportValidity(). However, the HTMLFormElement also
4663
- // has a reportValidity() method that will trigger validation on all child controls. Since we're not yet using
4664
- // ElementInternals, we need to overload this method so it looks for any element with the reportValidity() method.
4665
- //
4666
- // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger
4667
- // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't
4668
- // be necessary once we can use ElementInternals.
4669
- //
4670
- // Note that we're also honoring the form's novalidate attribute.
4671
- //
4672
- if (this.form && !this.form.noValidate) {
4673
- // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom
4674
- // elements that support the constraint validation API.
4675
- const elements = this.form.querySelectorAll("*");
4676
- for (const element of elements) {
4677
- if (typeof element.reportValidity === "function") {
4678
- if (!element.reportValidity()) {
4679
- return false;
4680
- }
4817
+ /**
4818
+ * Updates the ValidityState of the input in form component at current state
4819
+ */
4820
+ validateInput(input) {
4821
+ /** When the form control is disabled, its always valid */
4822
+ if (this.options.input(this.host).disabled) {
4823
+ return this._internals.setValidity({});
4824
+ }
4825
+ // get the validity of the internal <input>
4826
+ const validState = input.validity;
4827
+ // if the input is invalid, show the correct error
4828
+ if (!validState.valid) {
4829
+ // loop through the error reasons
4830
+ for (const state in validState) {
4831
+ // if there is an error and corresponding attribute holding
4832
+ // the message
4833
+ if (validState[state]) {
4834
+ this.validationError = state.toString();
4835
+ // set the validity error reason and the corresponding
4836
+ // message
4837
+ this._internals.setValidity({ [this.validationError]: true }, input.validationMessage, input);
4681
4838
  }
4682
4839
  }
4683
4840
  }
4684
- return true;
4685
- }
4686
- doAction(type, invoker) {
4687
- if (this.form) {
4688
- const button = document.createElement("button");
4689
- button.type = type;
4690
- button.style.position = "absolute";
4691
- button.style.width = "0";
4692
- button.style.height = "0";
4693
- button.style.clipPath = "inset(50%)";
4694
- button.style.overflow = "hidden";
4695
- button.style.whiteSpace = "nowrap";
4696
- // Pass form attributes through to the temporary button
4697
- if (invoker) {
4698
- ["formaction", "formmethod", "formnovalidate", "formtarget"].forEach(attr => {
4699
- if (invoker.hasAttribute(attr)) {
4700
- button.setAttribute(attr, invoker.getAttribute(attr));
4701
- }
4702
- });
4703
- }
4704
- this.form.append(button);
4705
- button.click();
4706
- button.remove();
4841
+ else {
4842
+ this._internals.setValidity({});
4707
4843
  }
4708
4844
  }
4709
- /** Resets the form, restoring all the control to their default value */
4710
- reset(invoker) {
4711
- this.doAction("reset", invoker);
4712
- }
4713
- /** Submits the form, triggering validation and form data injection. */
4714
- submit(invoker) {
4715
- // Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a
4716
- // native submit button into the form, "click" it, then remove it to simulate a standard form submission.
4717
- this.doAction("submit", invoker);
4718
- }
4719
4845
  }
4720
4846
 
4721
- function genId (componentName = "", elementName = "") {
4722
- return `id-${Math.random().toString().substring(2, 6)}-sgds-${componentName}-${elementName}`;
4723
- }
4847
+ /**
4848
+ * @summary The FormValidationMixin used by the form components
4849
+ * @param superClass
4850
+ * @returns
4851
+ */
4852
+ const SgdsFormValidatorMixin = (superClass) => {
4853
+ class ToBeValidatedElement extends superClass {
4854
+ constructor() {
4855
+ super(...arguments);
4856
+ this._isTouched = false;
4857
+ }
4858
+ connectedCallback() {
4859
+ super.connectedCallback();
4860
+ this.inputValidationController = new InputValidationController(this);
4861
+ }
4862
+ async firstUpdated(changedProperties) {
4863
+ super.firstUpdated(changedProperties);
4864
+ /* Either input or sgds-input. For example, quantity-toggle uses sgds-input */
4865
+ this.input =
4866
+ this.shadowRoot.querySelector("input") || (await this.sgdsInput) || this.shadowRoot.querySelector("textarea");
4867
+ this._mixinValidate(this.input);
4868
+ }
4869
+ /**
4870
+ * Native lifecycle of Form-Associated Custom Element Callbacks
4871
+ */
4872
+ formResetCallback() {
4873
+ if (this._mixinResetFormControl) {
4874
+ this._mixinResetFormControl();
4875
+ }
4876
+ else {
4877
+ this.value = this.defaultValue;
4878
+ this._mixinResetValidity(this.input);
4879
+ }
4880
+ this._mixinSetFormValue();
4881
+ }
4882
+ /**
4883
+ *
4884
+ * Methods use by classes using this mixin
4885
+ */
4886
+ /**
4887
+ * OnChange of form component
4888
+ * 1. Make value of control accessible via FormData
4889
+ * 2. Run change handler
4890
+ */
4891
+ _mixinHandleChange(e) {
4892
+ this._mixinSetFormValue();
4893
+ this.inputValidationController.handleChange(e);
4894
+ }
4895
+ /**
4896
+ * OnChange of form component
4897
+ * 1. Make value of control accessible via FormData
4898
+ * 2. Run input handler
4899
+ */
4900
+ _mixinHandleInputChange(e) {
4901
+ this._mixinSetFormValue();
4902
+ this.inputValidationController.handleInput(e);
4903
+ }
4904
+ /**
4905
+ * During form resetting,
4906
+ * 1. ValidityState is reset
4907
+ * 2. invalid reactive prop is updated after the reset
4908
+ * 3. Revalidates the ValidityState (but do not update invalid prop)
4909
+ * to prepare for the next validity check
4910
+ * 4. Reset touched state to false for a pristine form
4911
+ */
4912
+ _mixinResetValidity(input) {
4913
+ this.inputValidationController.resetValidity();
4914
+ this.inputValidationController.updateInvalidState();
4915
+ this.inputValidationController.validateInput(input);
4916
+ this._isTouched ? (this._isTouched = false) : null;
4917
+ }
4918
+ _mixinValidate(input) {
4919
+ this.inputValidationController.validateInput(input);
4920
+ }
4921
+ _mixinSetFormValue() {
4922
+ this.inputValidationController.setFormValue();
4923
+ }
4924
+ _mixinCheckValidity() {
4925
+ return this.inputValidationController.checkValidity();
4926
+ }
4927
+ _mixinReportValidity() {
4928
+ return this.inputValidationController.reportValidity();
4929
+ }
4930
+ _mixinGetValidity() {
4931
+ return this.inputValidationController.validity;
4932
+ }
4933
+ _mixinGetValidationMessage() {
4934
+ return this.inputValidationController.validationMessage;
4935
+ }
4936
+ }
4937
+ ToBeValidatedElement.formAssociated = true;
4938
+ __decorate([
4939
+ queryAsync("sgds-input")
4940
+ ], ToBeValidatedElement.prototype, "sgdsInput", void 0);
4941
+ return ToBeValidatedElement;
4942
+ };
4724
4943
 
4725
4944
  // @watch decorator
4726
4945
  //
@@ -4759,15 +4978,7 @@
4759
4978
  };
4760
4979
  }
4761
4980
 
4762
- var css_248z$4 = css`.form-control-container{display:flex;flex-direction:column;gap:var(--sgds-form-gap-md)}.form-control-container.disabled{opacity:var(--sgds-opacity-50)}textarea{font-family:inherit;font-size:inherit;line-height:inherit;margin:0;resize:vertical}.form-control{appearance:none;background-clip:padding-box;background-color:var(--sgds-form-bg);border:var(--sgds-form-border-width-default) solid var(--sgds-form-border-color);border-radius:var(--sgds-form-border-radius-md);color:var(--sgds-form-color);min-height:var(--sgds-dimension-136);padding:var(--sgds-form-padding-y) var(--sgds-form-padding-x);transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out;width:100%}.form-control[readonly]{border-color:var(--sgds-form-border-color-muted)}@media (prefers-reduced-motion:reduce){.form-control{transition:none}}.form-control:not([disabled]):not(.is-invalid):hover{border:var(--sgds-form-border-width-thick) solid var(--sgds-form-border-color-emphasis)}.form-control:not([disabled]):not(.is-invalid):focus,.form-control:not([disabled]):not(.is-invalid):focus-visible{border:var(--sgds-form-border-width-thick) solid var(--sgds-form-border-color-emphasis);box-shadow:var(--sgds-form-box-shadow-focus);outline:0}.form-control.is-invalid{border:var(--sgds-form-border-width-thick) solid var(--sgds-form-danger-border-color)}.form-control:disabled{background-color:var(--sgds-form-bg-muted)}.textarea-resize-none{resize:none}.textarea-resize-vertical{resize:vertical}.textarea-resize-auto{height:auto;overflow-y:hidden;resize:none}.textarea-info-container{display:flex;justify-content:space-between}.word-count{margin-left:auto}`;
4763
-
4764
- var css_248z$3 = css`.invalid-feedback-container{display:flex;gap:var(--sgds-form-gap-sm)}.invalid-feedback{color:var(--sgds-form-danger-color);font-size:var(--sgds-font-size-1);font-weight:var(--sgds-font-weight-regular)}`;
4765
-
4766
- var css_248z$2 = css`.form-label{margin-bottom:0}.form-check-label,.form-label{color:var(--sgds-form-color)}.form-check-input:disabled~.form-check-label,.form-check-input[disabled]~.form-check-label{cursor:not-allowed}`;
4767
-
4768
- var css_248z$1 = css`.form-text{color:var(--sgds-form-color-subtle);font-size:var(--sgds-font-size-1)}`;
4769
-
4770
- var css_248z = css`.form-control::placeholder{color:var(--sgds-form-color-subtle);font-family:var(--sgds-font-family-brand);font-weight:var(--sgds-font-weight-light);line-height:var(--sgds-line-height-heading)}`;
4981
+ var css_248z = css`.form-control-container{display:flex;flex-direction:column;gap:var(--sgds-form-gap-md)}.form-control-container.disabled{opacity:var(--sgds-opacity-50)}textarea{font-family:inherit;font-size:inherit;line-height:inherit;margin:0;resize:vertical}.form-control{appearance:none;background-clip:padding-box;background-color:var(--sgds-form-bg);border:var(--sgds-form-border-width-default) solid var(--sgds-form-border-color);border-radius:var(--sgds-form-border-radius-md);color:var(--sgds-form-color);min-height:var(--sgds-dimension-136);outline:0;padding:var(--sgds-form-padding-y) var(--sgds-form-padding-x);transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out;width:100%}.form-control[readonly]{border-color:var(--sgds-form-border-color-muted)}@media (prefers-reduced-motion:reduce){.form-control{transition:none}}.form-control:not([disabled]):not(.is-invalid):hover{border:var(--sgds-form-border-width-thick) solid var(--sgds-form-border-color-emphasis)}.form-control:not([disabled]):not(.is-invalid):focus,.form-control:not([disabled]):not(.is-invalid):focus-visible{border:var(--sgds-form-border-width-thick) solid var(--sgds-form-border-color-emphasis);box-shadow:var(--sgds-form-box-shadow-focus)}.form-control.is-invalid{border:var(--sgds-form-border-width-thick) solid var(--sgds-form-danger-border-color)}.form-control:disabled{background-color:var(--sgds-form-bg-muted)}.textarea-resize-none{resize:none}.textarea-resize-vertical{resize:vertical}.textarea-resize-auto{height:auto;overflow-y:hidden;resize:none}.textarea-info-container{display:flex;justify-content:space-between}.word-count{margin-left:auto}`;
4771
4982
 
4772
4983
  /**
4773
4984
  * @summary Text areas allow for the collection of input longer than a single line.
@@ -4777,13 +4988,9 @@
4777
4988
  * @event sgds-focus - Emitted when textarea is in focus.
4778
4989
  * @event sgds-blur - Emitted when textarea loses focus.
4779
4990
  */
4780
- class SgdsTextarea extends SgdsElement {
4991
+ class SgdsTextarea extends SgdsFormValidatorMixin(FormControlElement) {
4781
4992
  constructor() {
4782
4993
  super(...arguments);
4783
- /**@internal */
4784
- this.formSubmitController = new FormSubmitController(this);
4785
- /**The textarea's label */
4786
- this.label = "label";
4787
4994
  /**The textarea's value attribute. */
4788
4995
  this.value = "";
4789
4996
  /**Enables spell checking on the textarea */
@@ -4792,14 +4999,10 @@
4792
4999
  this.rows = 4;
4793
5000
  /**The textarea's placeholder text. */
4794
5001
  this.placeholder = "Placeholder";
4795
- /**Feedback text for error state when validated */
5002
+ /** Custom feedback text for error state when validated */
4796
5003
  this.invalidFeedback = "";
4797
5004
  /**Autofocus the textarea */
4798
5005
  this.autofocus = false;
4799
- /**Disables the textarea. */
4800
- this.disabled = false;
4801
- /**Makes the textarea a required field. */
4802
- this.required = false;
4803
5006
  /** Makes the textarea readonly. */
4804
5007
  this.readonly = false;
4805
5008
  /** Controls how the textarea can be resized. */
@@ -4808,32 +5011,44 @@
4808
5011
  this.defaultValue = "";
4809
5012
  /** Allows invalidFeedback, invalid and valid styles to be visible with the input */
4810
5013
  this.hasFeedback = false;
4811
- /** Marks the component as invalid. Replace the pseudo :invalid selector for absent in custom elements */
4812
- this.invalid = false;
5014
+ /** Makes the textarea as a required field. */
5015
+ this.required = false;
4813
5016
  /** The textarea's hint text */
4814
5017
  this.hintText = "";
4815
- /** @internal The textarea's unique id */
4816
- this.textareaId = genId("textarea", "input");
4817
- }
4818
- connectedCallback() {
4819
- super.connectedCallback();
4820
- this.resizeObserver = new ResizeObserver(() => this._setTextareaHeight());
4821
- this.updateComplete.then(() => {
4822
- this._setTextareaHeight();
4823
- this.resizeObserver.observe(this.textarea);
4824
- });
4825
- }
4826
- disconnectedCallback() {
4827
- super.disconnectedCallback();
4828
- this.resizeObserver.unobserve(this.textarea);
5018
+ this._isTouched = false;
4829
5019
  }
4830
5020
  /** Sets focus on the textarea. */
4831
5021
  focus(options) {
4832
5022
  this.textarea.focus(options);
4833
5023
  }
4834
- /** Checks for validity and shows the browser's validation message if the control is invalid. */
5024
+ /** Sets blur on the textarea. */
5025
+ blur() {
5026
+ this.textarea.blur();
5027
+ }
5028
+ /**
5029
+ * Checks for validity. Under the hood, HTMLFormElement's reportValidity method calls this method to check for component's validity state
5030
+ * Note that the native error popup is prevented for SGDS form components by default. Instead the validation message shows up in the feedback container of SgdsInput
5031
+ */
4835
5032
  reportValidity() {
4836
- return this.textarea.reportValidity();
5033
+ return this._mixinReportValidity();
5034
+ }
5035
+ /**
5036
+ * Checks for validity without any native error popup message
5037
+ */
5038
+ checkValidity() {
5039
+ return this._mixinCheckValidity();
5040
+ }
5041
+ /**
5042
+ * Returns the ValidityState object
5043
+ */
5044
+ get validity() {
5045
+ return this._mixinGetValidity();
5046
+ }
5047
+ /**
5048
+ * Returns the validation message based on the ValidityState
5049
+ */
5050
+ get validationMessage() {
5051
+ return this._mixinGetValidationMessage();
4837
5052
  }
4838
5053
  /** Selects all the text in the textarea. */
4839
5054
  select() {
@@ -4843,14 +5058,21 @@
4843
5058
  e.preventDefault();
4844
5059
  this.invalid = true;
4845
5060
  }
4846
- _handleChange(event) {
4847
- this.value = this.textarea.value;
4848
- this.emit(event);
5061
+ _handleChange(e) {
5062
+ this.value = this.input.value;
5063
+ this.emit("sgds-change");
5064
+ super._mixinHandleChange(e);
5065
+ }
5066
+ _handleInputChange(e) {
5067
+ this.value = this.input.value;
5068
+ this.emit("sgds-input");
5069
+ super._mixinHandleInputChange(e);
4849
5070
  }
4850
5071
  _handleFocus() {
4851
5072
  this.emit("sgds-focus");
4852
5073
  }
4853
- handleBlur() {
5074
+ _handleBlur() {
5075
+ this._isTouched = true;
4854
5076
  this.emit("sgds-blur");
4855
5077
  }
4856
5078
  /** @internal */
@@ -4867,23 +5089,26 @@
4867
5089
  }
4868
5090
  }
4869
5091
  /** @internal */
5092
+ _handleIsTouched() {
5093
+ if (this._isTouched) {
5094
+ this.invalid = !this.textarea.checkValidity();
5095
+ }
5096
+ }
5097
+ /** @internal */
4870
5098
  _handleDisabledChange() {
4871
5099
  // Disabled form controls are always valid, so we need to recheck validity when the state changes
4872
- this.textarea.disabled = this.disabled;
4873
- this.invalid = !this.textarea.checkValidity();
5100
+ this.setInvalid(false);
4874
5101
  }
4875
5102
  /** @internal */
4876
5103
  _handleValueChange() {
4877
- this.invalid = !this.textarea.checkValidity();
4878
5104
  this.updateComplete.then(() => this._setTextareaHeight());
4879
5105
  }
4880
5106
  _renderHintText() {
4881
- const hintTextTemplate = html ` <div id="${this.textareaId}Help" class="form-text">${this.hintText}</div> `;
5107
+ const hintTextTemplate = html ` <div id="${this._controlId}Help" class="form-text">${this.hintText}</div> `;
4882
5108
  return this.hintText && hintTextTemplate;
4883
5109
  }
4884
- render() {
4885
- // if maxlength is defined
4886
- const wordCount = html `
5110
+ _wordCount() {
5111
+ return html `
4887
5112
  <div
4888
5113
  class="form-text word-count ${classMap({
4889
5114
  "invalid-feedback": this.invalid && this.hasFeedback
@@ -4892,13 +5117,15 @@
4892
5117
  ${this.value.length}/${this.maxlength}
4893
5118
  </div>
4894
5119
  `;
5120
+ }
5121
+ render() {
4895
5122
  return html `
4896
5123
  <div
4897
5124
  class="form-control-container ${classMap({
4898
5125
  disabled: this.disabled
4899
5126
  })}"
4900
5127
  >
4901
- <label for=${this.textareaId} class="form-label">${this.label}</label>
5128
+ <label for=${this._controlId} class="form-label">${this.label}</label>
4902
5129
  <textarea
4903
5130
  class=${classMap({
4904
5131
  "form-control": true,
@@ -4907,7 +5134,7 @@
4907
5134
  "textarea-resize-vertical": this.resize === "vertical",
4908
5135
  "textarea-resize-auto": this.resize === "auto"
4909
5136
  })}
4910
- id=${this.textareaId}
5137
+ id=${this._controlId}
4911
5138
  name=${ifDefined(this.name)}
4912
5139
  rows=${ifDefined(this.rows)}
4913
5140
  placeholder=${ifDefined(this.placeholder)}
@@ -4922,13 +5149,12 @@
4922
5149
  ?autofocus=${this.autofocus}
4923
5150
  autocorrect=${ifDefined(this.autocorrect)}
4924
5151
  inputmode=${ifDefined(this.inputmode)}
4925
- @input=${() => this._handleChange("sgds-input")}
4926
- @change=${() => this._handleChange("sgds-change")}
5152
+ @input=${(e) => this._handleInputChange(e)}
5153
+ @change=${(e) => this._handleChange(e)}
4927
5154
  @invalid=${(e) => this._handleInvalid(e)}
4928
5155
  @focus=${this._handleFocus}
4929
- @blur=${this.handleBlur}
4930
- >
4931
- </textarea>
5156
+ @blur=${this._handleBlur}
5157
+ ></textarea>
4932
5158
  <div class="textarea-info-container">
4933
5159
  ${this.invalid && this.hasFeedback
4934
5160
  ? html `
@@ -4939,30 +5165,22 @@
4939
5165
  fill="#B90000"
4940
5166
  />
4941
5167
  </svg>
4942
- <div id="${this.textareaId}-invalid" class="invalid-feedback">${this.invalidFeedback}</div>
5168
+ <div id="${this._controlId}-invalid" class="invalid-feedback">
5169
+ ${this.invalidFeedback ? this.invalidFeedback : this.input.validationMessage}
5170
+ </div>
4943
5171
  </div>
4944
5172
  `
4945
5173
  : html `${this._renderHintText()}`}
4946
- ${this.maxlength > 0 ? wordCount : undefined}
5174
+ ${this.maxlength > 0 ? this._wordCount() : nothing}
4947
5175
  </div>
4948
5176
  </div>
4949
5177
  `;
4950
5178
  }
4951
5179
  }
4952
- SgdsTextarea.styles = [
4953
- ...SgdsElement.styles,
4954
- css_248z$1,
4955
- css_248z$2,
4956
- css_248z$3,
4957
- css_248z,
4958
- css_248z$4
4959
- ];
5180
+ SgdsTextarea.styles = [...FormControlElement.styles, css_248z];
4960
5181
  __decorate([
4961
5182
  query("textarea.form-control")
4962
5183
  ], SgdsTextarea.prototype, "textarea", void 0);
4963
- __decorate([
4964
- property({ type: String, reflect: true })
4965
- ], SgdsTextarea.prototype, "label", void 0);
4966
5184
  __decorate([
4967
5185
  property({ type: String, reflect: true })
4968
5186
  ], SgdsTextarea.prototype, "name", void 0);
@@ -4990,12 +5208,6 @@
4990
5208
  __decorate([
4991
5209
  property({ type: Boolean, reflect: true })
4992
5210
  ], SgdsTextarea.prototype, "autofocus", void 0);
4993
- __decorate([
4994
- property({ type: Boolean, reflect: true })
4995
- ], SgdsTextarea.prototype, "disabled", void 0);
4996
- __decorate([
4997
- property({ type: Boolean, reflect: true })
4998
- ], SgdsTextarea.prototype, "required", void 0);
4999
5211
  __decorate([
5000
5212
  property({ type: Boolean, reflect: true })
5001
5213
  ], SgdsTextarea.prototype, "readonly", void 0);
@@ -5016,13 +5228,19 @@
5016
5228
  ], SgdsTextarea.prototype, "hasFeedback", void 0);
5017
5229
  __decorate([
5018
5230
  property({ type: Boolean, reflect: true })
5019
- ], SgdsTextarea.prototype, "invalid", void 0);
5231
+ ], SgdsTextarea.prototype, "required", void 0);
5020
5232
  __decorate([
5021
5233
  property({ reflect: true })
5022
5234
  ], SgdsTextarea.prototype, "hintText", void 0);
5235
+ __decorate([
5236
+ state()
5237
+ ], SgdsTextarea.prototype, "_isTouched", void 0);
5023
5238
  __decorate([
5024
5239
  watch("rows", { waitUntilFirstUpdate: true })
5025
5240
  ], SgdsTextarea.prototype, "_handleRowsChange", null);
5241
+ __decorate([
5242
+ watch("_isTouched", { waitUntilFirstUpdate: true })
5243
+ ], SgdsTextarea.prototype, "_handleIsTouched", null);
5026
5244
  __decorate([
5027
5245
  watch("disabled", { waitUntilFirstUpdate: true })
5028
5246
  ], SgdsTextarea.prototype, "_handleDisabledChange", null);