@vonage/vivid 4.31.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (676) hide show
  1. package/{shared/definition2.cjs → accordion/definition.cjs} +20 -20
  2. package/{shared/definition2.js → accordion/definition.js} +5 -7
  3. package/accordion/index.cjs +5 -5
  4. package/accordion/index.js +129 -3
  5. package/accordion-item/definition.cjs +145 -0
  6. package/accordion-item/definition.js +139 -0
  7. package/accordion-item/index.cjs +1 -5
  8. package/accordion-item/index.js +2 -3
  9. package/{shared/definition3.cjs → action-group/definition.cjs} +12 -9
  10. package/{shared/definition3.js → action-group/definition.js} +5 -4
  11. package/action-group/index.cjs +6 -5
  12. package/action-group/index.js +49 -3
  13. package/{shared/definition4.cjs → alert/definition.cjs} +33 -31
  14. package/{shared/definition4.js → alert/definition.js} +11 -11
  15. package/alert/index.cjs +30 -5
  16. package/alert/index.js +158 -3
  17. package/{shared/definition5.cjs → audio-player/definition.cjs} +58 -57
  18. package/{shared/definition5.js → audio-player/definition.js} +11 -12
  19. package/audio-player/index.cjs +68 -4
  20. package/audio-player/index.js +309 -2
  21. package/{shared/definition6.cjs → avatar/definition.cjs} +28 -26
  22. package/{shared/definition6.js → avatar/definition.js} +7 -7
  23. package/avatar/index.cjs +18 -5
  24. package/avatar/index.js +93 -3
  25. package/{shared/definition7.cjs → badge/definition.cjs} +18 -16
  26. package/{shared/definition7.js → badge/definition.js} +6 -6
  27. package/badge/index.cjs +4 -5
  28. package/badge/index.js +66 -3
  29. package/{shared/definition8.cjs → banner/definition.cjs} +26 -25
  30. package/{shared/definition8.js → banner/definition.js} +10 -11
  31. package/banner/index.cjs +29 -4
  32. package/banner/index.js +128 -2
  33. package/{shared/definition10.cjs → breadcrumb/definition.cjs} +11 -9
  34. package/{shared/definition10.js → breadcrumb/definition.js} +5 -5
  35. package/breadcrumb/index.cjs +12 -5
  36. package/breadcrumb/index.js +69 -3
  37. package/{shared/definition9.cjs → breadcrumb-item/definition.cjs} +18 -15
  38. package/{shared/definition9.js → breadcrumb-item/definition.js} +7 -7
  39. package/breadcrumb-item/index.cjs +5 -5
  40. package/breadcrumb-item/index.js +33 -3
  41. package/bundled/_has.cjs +1 -0
  42. package/bundled/_has.js +34 -0
  43. package/bundled/affix.cjs +13 -0
  44. package/bundled/affix.js +63 -0
  45. package/bundled/anchored.cjs +4 -0
  46. package/bundled/anchored.js +67 -0
  47. package/bundled/aria.cjs +1 -0
  48. package/bundled/aria.js +7 -0
  49. package/bundled/attribute-binding-behaviour.cjs +1 -0
  50. package/bundled/attribute-binding-behaviour.js +27 -0
  51. package/bundled/base-progress.cjs +1 -0
  52. package/bundled/base-progress.js +57 -0
  53. package/bundled/breadcrumb-item.cjs +1 -0
  54. package/bundled/breadcrumb-item.js +21 -0
  55. package/bundled/button.cjs +1 -0
  56. package/bundled/button.js +106 -0
  57. package/bundled/calendar-event.cjs +1 -0
  58. package/bundled/calendar-event.js +34 -0
  59. package/bundled/calendar-picker.template.cjs +148 -0
  60. package/bundled/calendar-picker.template.js +3371 -0
  61. package/bundled/char-count.cjs +13 -0
  62. package/bundled/char-count.js +54 -0
  63. package/bundled/children.cjs +1 -0
  64. package/bundled/children.js +38 -0
  65. package/bundled/class-names.cjs +1 -0
  66. package/bundled/class-names.js +9 -0
  67. package/bundled/definition.cjs +39 -0
  68. package/bundled/definition.js +122 -0
  69. package/bundled/definition10.cjs +19 -0
  70. package/bundled/definition10.js +73 -0
  71. package/bundled/definition11.cjs +10 -0
  72. package/bundled/definition11.js +44 -0
  73. package/bundled/definition12.cjs +1 -0
  74. package/bundled/definition12.js +20 -0
  75. package/bundled/definition13.cjs +73 -0
  76. package/bundled/definition13.js +359 -0
  77. package/bundled/definition14.cjs +5 -0
  78. package/bundled/definition14.js +29 -0
  79. package/bundled/definition15.cjs +30 -0
  80. package/bundled/definition15.js +80 -0
  81. package/bundled/definition16.cjs +19 -0
  82. package/bundled/definition16.js +103 -0
  83. package/bundled/definition17.cjs +13 -0
  84. package/bundled/definition17.js +137 -0
  85. package/bundled/definition18.cjs +12 -0
  86. package/bundled/definition18.js +94 -0
  87. package/bundled/definition19.cjs +67 -0
  88. package/bundled/definition19.js +666 -0
  89. package/bundled/definition2.cjs +20 -0
  90. package/bundled/definition2.js +180 -0
  91. package/bundled/definition20.cjs +20 -0
  92. package/bundled/definition20.js +106 -0
  93. package/bundled/definition21.cjs +5 -0
  94. package/bundled/definition21.js +19 -0
  95. package/bundled/definition22.cjs +24 -0
  96. package/bundled/definition22.js +151 -0
  97. package/bundled/definition3.cjs +29 -0
  98. package/bundled/definition3.js +195 -0
  99. package/bundled/definition4.cjs +6 -0
  100. package/bundled/definition4.js +42 -0
  101. package/bundled/definition5.cjs +1 -0
  102. package/bundled/definition5.js +345 -0
  103. package/bundled/definition6.cjs +31 -0
  104. package/bundled/definition6.js +265 -0
  105. package/bundled/definition7.cjs +30 -0
  106. package/bundled/definition7.js +288 -0
  107. package/bundled/definition8.cjs +19 -0
  108. package/bundled/definition8.js +145 -0
  109. package/bundled/definition9.cjs +14 -0
  110. package/bundled/definition9.js +1406 -0
  111. package/bundled/delegates-aria.cjs +1 -0
  112. package/bundled/delegates-aria.js +77 -0
  113. package/bundled/divider.cjs +1 -0
  114. package/bundled/divider.js +34 -0
  115. package/bundled/dom.cjs +1 -0
  116. package/bundled/dom.js +6 -0
  117. package/bundled/enums.cjs +1 -0
  118. package/bundled/enums.js +9 -0
  119. package/bundled/form-associated.cjs +1 -0
  120. package/bundled/form-associated.js +320 -0
  121. package/bundled/form-element.cjs +1 -0
  122. package/bundled/form-element.js +56 -0
  123. package/bundled/host-semantics.cjs +1 -0
  124. package/bundled/host-semantics.js +57 -0
  125. package/bundled/index.cjs +1 -0
  126. package/bundled/index.js +6 -0
  127. package/bundled/key-codes.cjs +1 -0
  128. package/bundled/key-codes.js +16 -0
  129. package/bundled/linkable.cjs +15 -0
  130. package/bundled/linkable.js +49 -0
  131. package/bundled/listbox.cjs +1 -0
  132. package/bundled/listbox.js +345 -0
  133. package/bundled/localized.cjs +1 -0
  134. package/bundled/localized.js +459 -0
  135. package/bundled/mixins.cjs +33 -0
  136. package/bundled/mixins.js +226 -0
  137. package/bundled/numbers.cjs +1 -0
  138. package/bundled/numbers.js +14 -0
  139. package/bundled/option.cjs +1 -0
  140. package/bundled/option.js +158 -0
  141. package/bundled/picker-field.template.cjs +62 -0
  142. package/bundled/picker-field.template.js +234 -0
  143. package/bundled/playbackRates.cjs +1 -0
  144. package/bundled/playbackRates.js +11 -0
  145. package/bundled/ref.cjs +1 -0
  146. package/bundled/ref.js +32 -0
  147. package/bundled/repeat.cjs +1 -0
  148. package/bundled/repeat.js +341 -0
  149. package/bundled/scrollIntoView.cjs +1 -0
  150. package/bundled/scrollIntoView.js +33 -0
  151. package/bundled/single-date-picker.cjs +1 -0
  152. package/bundled/single-date-picker.js +39 -0
  153. package/bundled/single-value-picker.cjs +1 -0
  154. package/bundled/single-value-picker.js +87 -0
  155. package/bundled/slider.template.cjs +41 -0
  156. package/bundled/slider.template.js +100 -0
  157. package/bundled/slotted.cjs +1 -0
  158. package/bundled/slotted.js +81 -0
  159. package/bundled/strings.cjs +1 -0
  160. package/bundled/strings.js +7 -0
  161. package/bundled/text-field.cjs +1 -0
  162. package/bundled/text-field.js +4 -0
  163. package/bundled/time-selection-picker.template.cjs +46 -0
  164. package/bundled/time-selection-picker.template.js +575 -0
  165. package/bundled/vivid-element.cjs +1 -0
  166. package/bundled/vivid-element.js +1761 -0
  167. package/bundled/when.cjs +1 -0
  168. package/bundled/when.js +11 -0
  169. package/bundled/with-contextual-help.cjs +1 -0
  170. package/bundled/with-contextual-help.js +22 -0
  171. package/bundled/with-error-text.cjs +1 -0
  172. package/bundled/with-error-text.js +39 -0
  173. package/bundled/with-success-text.cjs +1 -0
  174. package/bundled/with-success-text.js +16 -0
  175. package/button/definition.cjs +14 -0
  176. package/button/definition.js +4 -0
  177. package/button/index.cjs +1 -5
  178. package/button/index.js +2 -3
  179. package/{shared/definition13.cjs → calendar/definition.cjs} +27 -449
  180. package/{shared/definition13.js → calendar/definition.js} +7 -431
  181. package/calendar/index.cjs +53 -5
  182. package/calendar/index.js +431 -3
  183. package/{shared/definition12.cjs → calendar-event/definition.cjs} +12 -9
  184. package/{shared/definition12.js → calendar-event/definition.js} +6 -6
  185. package/calendar-event/index.cjs +9 -5
  186. package/calendar-event/index.js +43 -3
  187. package/card/definition.cjs +186 -0
  188. package/{shared/definition14.js → card/definition.js} +10 -11
  189. package/card/index.cjs +47 -5
  190. package/card/index.js +163 -3
  191. package/{shared/definition15.cjs → checkbox/definition.cjs} +35 -30
  192. package/{shared/definition15.js → checkbox/definition.js} +17 -14
  193. package/checkbox/index.cjs +1 -5
  194. package/checkbox/index.js +2 -3
  195. package/{shared/definition16.cjs → combobox/definition.cjs} +50 -52
  196. package/{shared/definition16.js → combobox/definition.js} +19 -23
  197. package/combobox/index.cjs +65 -5
  198. package/combobox/index.js +512 -3
  199. package/contextual-help/definition.cjs +62 -0
  200. package/contextual-help/definition.js +57 -0
  201. package/contextual-help/index.cjs +1 -0
  202. package/contextual-help/index.js +2 -0
  203. package/custom-elements.json +2735 -711
  204. package/{shared/definition17.cjs → data-grid/definition.cjs} +169 -196
  205. package/{shared/definition17.js → data-grid/definition.js} +71 -100
  206. package/data-grid/index.cjs +81 -5
  207. package/data-grid/index.js +1011 -3
  208. package/{shared/definition18.cjs → date-picker/definition.cjs} +20 -17
  209. package/{shared/definition18.js → date-picker/definition.js} +12 -11
  210. package/date-picker/index.cjs +1 -5
  211. package/date-picker/index.js +115 -3
  212. package/{shared/definition19.cjs → date-range-picker/definition.cjs} +26 -23
  213. package/{shared/definition19.js → date-range-picker/definition.js} +10 -9
  214. package/date-range-picker/index.cjs +1 -5
  215. package/date-range-picker/index.js +335 -3
  216. package/{shared/definition20.cjs → date-time-picker/definition.cjs} +27 -24
  217. package/{shared/definition20.js → date-time-picker/definition.js} +13 -12
  218. package/date-time-picker/index.cjs +8 -5
  219. package/date-time-picker/index.js +216 -3
  220. package/{shared/definition21.cjs → dial-pad/definition.cjs} +39 -40
  221. package/{shared/definition21.js → dial-pad/definition.js} +9 -12
  222. package/dial-pad/index.cjs +54 -5
  223. package/dial-pad/index.js +214 -3
  224. package/{shared/definition22.cjs → dialog/definition.cjs} +48 -47
  225. package/{shared/definition22.js → dialog/definition.js} +10 -11
  226. package/dialog/index.cjs +44 -5
  227. package/dialog/index.js +257 -3
  228. package/{shared/definition23.cjs → divider/definition.cjs} +10 -6
  229. package/{shared/definition23.js → divider/definition.js} +6 -5
  230. package/divider/index.cjs +1 -5
  231. package/divider/index.js +2 -3
  232. package/elevation/definition.cjs +11 -0
  233. package/elevation/definition.js +2 -0
  234. package/elevation/index.cjs +1 -5
  235. package/elevation/index.js +2 -3
  236. package/empty-state/definition.cjs +81 -0
  237. package/empty-state/definition.js +75 -0
  238. package/empty-state/index.cjs +14 -5
  239. package/empty-state/index.js +64 -3
  240. package/fab/definition.cjs +105 -0
  241. package/fab/definition.js +99 -0
  242. package/fab/index.cjs +20 -5
  243. package/fab/index.js +86 -3
  244. package/file-picker/definition.cjs +510 -0
  245. package/file-picker/definition.js +504 -0
  246. package/file-picker/index.cjs +58 -5
  247. package/file-picker/index.js +381 -3
  248. package/{shared/definition27.cjs → header/definition.cjs} +14 -11
  249. package/{shared/definition27.js → header/definition.js} +6 -5
  250. package/header/index.cjs +19 -5
  251. package/header/index.js +57 -3
  252. package/{shared/definition28.cjs → icon/definition.cjs} +25 -149
  253. package/{shared/definition28.js → icon/definition.js} +6 -132
  254. package/icon/index.cjs +1 -5
  255. package/icon/index.js +2 -3
  256. package/index.cjs +268 -264
  257. package/index.js +72 -71
  258. package/{shared/definition29.cjs → layout/definition.cjs} +13 -10
  259. package/{shared/definition29.js → layout/definition.js} +4 -3
  260. package/layout/index.cjs +3 -5
  261. package/layout/index.js +52 -3
  262. package/lib/accordion-item/accordion-item.d.ts +42 -2
  263. package/lib/action-group/action-group.d.ts +42 -2
  264. package/lib/alert/alert.d.ts +84 -4
  265. package/lib/audio-player/audio-player.d.ts +42 -2
  266. package/lib/avatar/avatar.d.ts +42 -2
  267. package/lib/badge/badge.d.ts +42 -2
  268. package/lib/banner/banner.d.ts +126 -6
  269. package/lib/breadcrumb/breadcrumb.d.ts +42 -2
  270. package/lib/breadcrumb-item/breadcrumb-item.d.ts +42 -2
  271. package/lib/button/button.d.ts +127 -6
  272. package/lib/calendar-event/calendar-event.d.ts +42 -2
  273. package/lib/card/card.d.ts +42 -2
  274. package/lib/checkbox/checkbox.d.ts +252 -13
  275. package/lib/combobox/combobox.d.ts +252 -12
  276. package/lib/components.d.ts +1 -0
  277. package/lib/contextual-help/contextual-help.d.ts +5 -0
  278. package/lib/contextual-help/contextual-help.template.d.ts +3 -0
  279. package/lib/contextual-help/definition.d.ts +1 -0
  280. package/lib/data-grid/data-grid-cell.d.ts +418 -3
  281. package/lib/data-grid/data-grid-row.d.ts +379 -1
  282. package/lib/date-picker/date-picker.d.ts +374 -54
  283. package/lib/date-range-picker/date-range-picker.d.ts +188 -28
  284. package/lib/date-time-picker/date-time-picker.d.ts +376 -56
  285. package/lib/dial-pad/dial-pad.d.ts +42 -2
  286. package/lib/dialog/dialog.d.ts +84 -4
  287. package/lib/divider/divider.d.ts +42 -2
  288. package/lib/fab/fab.d.ts +43 -2
  289. package/lib/file-picker/accept.d.ts +1 -0
  290. package/lib/file-picker/data-transfer.d.ts +1 -0
  291. package/lib/file-picker/file-picker.d.ts +259 -31
  292. package/lib/file-picker/locale.d.ts +1 -0
  293. package/lib/header/header.d.ts +42 -2
  294. package/lib/menu/menu.d.ts +84 -4
  295. package/lib/menu-item/menu-item.d.ts +84 -4
  296. package/lib/nav/nav.d.ts +42 -2
  297. package/lib/nav-disclosure/nav-disclosure.d.ts +84 -4
  298. package/lib/nav-item/nav-item.d.ts +84 -4
  299. package/lib/note/note.d.ts +42 -2
  300. package/lib/number-field/number-field.d.ts +840 -104
  301. package/lib/option/option.d.ts +85 -4
  302. package/lib/pagination/pagination.d.ts +42 -2
  303. package/lib/progress/progress.d.ts +42 -2
  304. package/lib/progress-ring/progress-ring.d.ts +42 -2
  305. package/lib/radio/radio.d.ts +126 -7
  306. package/lib/radio-group/radio-group.d.ts +42 -2
  307. package/lib/range-slider/range-slider.d.ts +126 -6
  308. package/lib/rich-text-editor/menubar/menubar.d.ts +42 -2
  309. package/lib/rich-text-editor/rich-text-editor.d.ts +42 -2
  310. package/lib/searchable-select/option-tag.d.ts +42 -2
  311. package/lib/searchable-select/searchable-select.d.ts +336 -16
  312. package/lib/select/select.d.ts +294 -14
  313. package/lib/selectable-box/selectable-box.d.ts +42 -3
  314. package/lib/simple-color-picker/definition.d.ts +4 -0
  315. package/lib/simple-color-picker/locale.d.ts +4 -0
  316. package/lib/simple-color-picker/simple-color-picker.d.ts +1600 -0
  317. package/lib/simple-color-picker/simple-color-picker.template.d.ts +3 -0
  318. package/lib/slider/slider.d.ts +126 -6
  319. package/lib/split-button/split-button.d.ts +128 -6
  320. package/lib/switch/switch.d.ts +84 -4
  321. package/lib/tab/tab.d.ts +126 -6
  322. package/lib/tab-panel/tab-panel.d.ts +42 -2
  323. package/lib/tag/tag.d.ts +126 -6
  324. package/lib/tag-group/tag-group.d.ts +42 -2
  325. package/lib/tag-name-map.d.ts +2 -1
  326. package/lib/text-area/text-area.d.ts +787 -91
  327. package/lib/text-field/text-field.d.ts +840 -104
  328. package/lib/time-picker/time-picker.d.ts +188 -28
  329. package/lib/toggletip/toggletip.d.ts +84 -4
  330. package/lib/tooltip/tooltip.d.ts +42 -2
  331. package/lib/tree-item/tree-item.d.ts +84 -4
  332. package/lib/tree-view/tree-view.d.ts +42 -2
  333. package/lib/video-player/video-player.d.ts +42 -2
  334. package/locales/de-DE.cjs +13 -1
  335. package/locales/de-DE.js +13 -1
  336. package/locales/en-GB.cjs +13 -1
  337. package/locales/en-GB.js +13 -1
  338. package/locales/en-US.cjs +13 -1
  339. package/locales/en-US.js +13 -1
  340. package/locales/ja-JP.cjs +13 -1
  341. package/locales/ja-JP.js +13 -1
  342. package/locales/zh-CN.cjs +13 -1
  343. package/locales/zh-CN.js +13 -1
  344. package/{shared/definition31.cjs → menu/definition.cjs} +46 -46
  345. package/{shared/definition31.js → menu/definition.js} +16 -18
  346. package/menu/index.cjs +1 -5
  347. package/menu/index.js +2 -3
  348. package/menu-item/definition.cjs +14 -0
  349. package/menu-item/definition.js +3 -0
  350. package/menu-item/index.cjs +1 -5
  351. package/menu-item/index.js +2 -3
  352. package/{shared/definition34.cjs → nav/definition.cjs} +7 -4
  353. package/{shared/definition34.js → nav/definition.js} +4 -3
  354. package/nav/index.cjs +5 -5
  355. package/nav/index.js +13 -3
  356. package/nav-disclosure/definition.cjs +122 -0
  357. package/nav-disclosure/definition.js +116 -0
  358. package/nav-disclosure/index.cjs +16 -5
  359. package/nav-disclosure/index.js +96 -3
  360. package/{shared/definition33.cjs → nav-item/definition.cjs} +19 -16
  361. package/{shared/definition33.js → nav-item/definition.js} +9 -8
  362. package/nav-item/index.cjs +2 -5
  363. package/nav-item/index.js +59 -3
  364. package/{shared/definition35.cjs → note/definition.cjs} +15 -13
  365. package/{shared/definition35.js → note/definition.js} +6 -6
  366. package/note/index.cjs +9 -5
  367. package/note/index.js +44 -3
  368. package/number-field/definition.cjs +438 -0
  369. package/{shared/definition36.js → number-field/definition.js} +31 -27
  370. package/number-field/index.cjs +60 -5
  371. package/number-field/index.js +369 -3
  372. package/option/definition.cjs +84 -0
  373. package/option/definition.js +78 -0
  374. package/option/index.cjs +1 -5
  375. package/option/index.js +2 -3
  376. package/package.json +15 -4
  377. package/{shared/definition38.cjs → pagination/definition.cjs} +31 -33
  378. package/{shared/definition38.js → pagination/definition.js} +7 -11
  379. package/pagination/index.cjs +43 -5
  380. package/pagination/index.js +194 -3
  381. package/popup/definition.cjs +13 -0
  382. package/popup/definition.js +4 -0
  383. package/popup/index.cjs +1 -5
  384. package/popup/index.js +2 -3
  385. package/{shared/definition40.cjs → progress/definition.cjs} +17 -15
  386. package/{shared/definition40.js → progress/definition.js} +6 -6
  387. package/progress/index.cjs +17 -5
  388. package/progress/index.js +69 -3
  389. package/{shared/definition39.cjs → progress-ring/definition.cjs} +17 -15
  390. package/{shared/definition39.js → progress-ring/definition.js} +7 -7
  391. package/progress-ring/index.cjs +1 -5
  392. package/progress-ring/index.js +2 -3
  393. package/{shared/definition42.cjs → radio/definition.cjs} +20 -23
  394. package/{shared/definition42.js → radio/definition.js} +8 -13
  395. package/radio/index.cjs +1 -5
  396. package/radio/index.js +2 -3
  397. package/{shared/definition41.cjs → radio-group/definition.cjs} +31 -30
  398. package/{shared/definition41.js → radio-group/definition.js} +8 -9
  399. package/radio-group/index.cjs +23 -5
  400. package/radio-group/index.js +255 -3
  401. package/{shared/definition43.cjs → range-slider/definition.cjs} +62 -61
  402. package/{shared/definition43.js → range-slider/definition.js} +13 -14
  403. package/range-slider/index.cjs +68 -5
  404. package/range-slider/index.js +456 -3
  405. package/rich-text-editor/definition.cjs +1206 -0
  406. package/rich-text-editor/definition.js +1200 -0
  407. package/rich-text-editor/index.cjs +133 -4
  408. package/rich-text-editor/index.js +10386 -2
  409. package/{shared/definition45.cjs → searchable-select/definition.cjs} +119 -116
  410. package/{shared/definition45.js → searchable-select/definition.js} +25 -24
  411. package/searchable-select/index.cjs +164 -5
  412. package/searchable-select/index.js +1025 -3
  413. package/{shared/definition46.cjs → select/definition.cjs} +80 -83
  414. package/{shared/definition46.js → select/definition.js} +19 -24
  415. package/select/index.cjs +1 -5
  416. package/select/index.js +2 -3
  417. package/{shared/definition47.cjs → selectable-box/definition.cjs} +26 -32
  418. package/{shared/definition47.js → selectable-box/definition.js} +9 -17
  419. package/selectable-box/index.cjs +28 -5
  420. package/selectable-box/index.js +136 -3
  421. package/shared/aria/aria-mixin.d.ts +43 -3
  422. package/shared/aria/attribute-removal.d.ts +3 -0
  423. package/shared/aria/delegate-aria-behavior.d.ts +0 -3
  424. package/shared/aria/delegates-aria.d.ts +42 -2
  425. package/shared/aria/host-semantics.d.ts +42 -2
  426. package/shared/color-picker/index.d.ts +2 -0
  427. package/shared/color-picker/types.d.ts +4 -0
  428. package/shared/color-picker/utils.d.ts +3 -0
  429. package/shared/feedback/feedback-message.d.ts +42 -2
  430. package/shared/feedback/mixins.d.ts +84 -4
  431. package/shared/foundation/button/button.d.ts +84 -4
  432. package/shared/foundation/form-associated/form-associated.d.ts +84 -4
  433. package/shared/foundation/vivid-element/vivid-element.d.ts +43 -3
  434. package/shared/localization/Locale.d.ts +2 -0
  435. package/shared/patterns/affix.d.ts +84 -4
  436. package/shared/patterns/anchored.d.ts +84 -4
  437. package/shared/patterns/char-count/char-count.d.ts +42 -2
  438. package/shared/patterns/form-elements/form-element.d.ts +84 -4
  439. package/shared/patterns/form-elements/with-contextual-help.d.ts +1238 -0
  440. package/shared/patterns/form-elements/with-error-text.d.ts +126 -6
  441. package/shared/patterns/form-elements/with-success-text.d.ts +42 -2
  442. package/shared/patterns/linkable.d.ts +42 -2
  443. package/shared/patterns/localized.d.ts +42 -2
  444. package/shared/patterns/trapped-focus.d.ts +42 -2
  445. package/shared/picker-field/mixins/calendar-picker.d.ts +94 -14
  446. package/shared/picker-field/mixins/calendar-picker.template.d.ts +94 -14
  447. package/shared/picker-field/mixins/inline-time-picker/inline-time-picker.d.ts +42 -2
  448. package/shared/picker-field/mixins/min-max-calendar-picker.d.ts +188 -28
  449. package/shared/picker-field/mixins/single-date-picker.d.ts +280 -40
  450. package/shared/picker-field/mixins/single-value-picker.d.ts +92 -12
  451. package/shared/picker-field/mixins/time-selection-picker.d.ts +188 -28
  452. package/shared/picker-field/mixins/time-selection-picker.template.d.ts +188 -28
  453. package/shared/picker-field/picker-field.d.ts +252 -12
  454. package/{shared/definition48.cjs → side-drawer/definition.cjs} +16 -14
  455. package/{shared/definition48.js → side-drawer/definition.js} +5 -5
  456. package/side-drawer/index.cjs +17 -3
  457. package/side-drawer/index.js +100 -2
  458. package/simple-color-picker/definition.cjs +398 -0
  459. package/simple-color-picker/definition.js +392 -0
  460. package/simple-color-picker/index.cjs +31 -0
  461. package/simple-color-picker/index.js +250 -0
  462. package/{shared/definition49.cjs → slider/definition.cjs} +46 -53
  463. package/{shared/definition49.js → slider/definition.js} +11 -20
  464. package/slider/index.cjs +1 -5
  465. package/slider/index.js +2 -3
  466. package/split-button/definition.cjs +176 -0
  467. package/split-button/definition.js +170 -0
  468. package/split-button/index.cjs +26 -5
  469. package/split-button/index.js +149 -3
  470. package/styles/core/all.css +1 -1
  471. package/styles/core/theme.css +1 -1
  472. package/styles/core/typography.css +1 -1
  473. package/styles/tokens/theme-dark.css +4 -4
  474. package/styles/tokens/theme-light.css +4 -4
  475. package/styles/tokens/vivid-2-compat.css +1 -1
  476. package/{shared/definition51.cjs → switch/definition.cjs} +20 -19
  477. package/{shared/definition51.js → switch/definition.js} +8 -9
  478. package/switch/index.cjs +16 -5
  479. package/switch/index.js +102 -3
  480. package/tab/definition.cjs +127 -0
  481. package/tab/definition.js +121 -0
  482. package/tab/index.cjs +1 -5
  483. package/tab/index.js +2 -3
  484. package/{shared/definition52.cjs → tab-panel/definition.cjs} +7 -4
  485. package/{shared/definition52.js → tab-panel/definition.js} +4 -3
  486. package/tab-panel/index.cjs +1 -5
  487. package/tab-panel/index.js +2 -3
  488. package/{shared/definition54.cjs → tabs/definition.cjs} +47 -40
  489. package/{shared/definition54.js → tabs/definition.js} +19 -14
  490. package/tabs/index.cjs +31 -5
  491. package/tabs/index.js +321 -3
  492. package/tag/definition.cjs +156 -0
  493. package/tag/definition.js +150 -0
  494. package/tag/index.cjs +19 -5
  495. package/tag/index.js +118 -3
  496. package/{shared/definition55.cjs → tag-group/definition.cjs} +9 -6
  497. package/{shared/definition55.js → tag-group/definition.js} +5 -4
  498. package/tag-group/index.cjs +8 -5
  499. package/tag-group/index.js +26 -3
  500. package/text-area/definition.cjs +355 -0
  501. package/text-area/definition.js +349 -0
  502. package/text-area/index.cjs +41 -5
  503. package/text-area/index.js +293 -3
  504. package/{shared/definition58.cjs → text-field/definition.cjs} +70 -52
  505. package/{shared/definition58.js → text-field/definition.js} +40 -24
  506. package/text-field/index.cjs +1 -5
  507. package/text-field/index.js +2 -3
  508. package/time-picker/definition.cjs +43 -0
  509. package/{shared/definition59.js → time-picker/definition.js} +9 -8
  510. package/time-picker/index.cjs +1 -5
  511. package/time-picker/index.js +29 -3
  512. package/{shared/definition60.cjs → toggletip/definition.cjs} +20 -18
  513. package/{shared/definition60.js → toggletip/definition.js} +8 -8
  514. package/toggletip/index.cjs +1 -5
  515. package/toggletip/index.js +2 -3
  516. package/{shared/definition61.cjs → tooltip/definition.cjs} +16 -13
  517. package/{shared/definition61.js → tooltip/definition.js} +7 -6
  518. package/tooltip/index.cjs +1 -5
  519. package/tooltip/index.js +2 -3
  520. package/tree-item/definition.cjs +13 -0
  521. package/tree-item/definition.js +3 -0
  522. package/tree-item/index.cjs +1 -5
  523. package/tree-item/index.js +2 -3
  524. package/{shared/definition63.cjs → tree-view/definition.cjs} +42 -44
  525. package/{shared/definition63.js → tree-view/definition.js} +7 -11
  526. package/tree-view/index.cjs +13 -5
  527. package/tree-view/index.js +171 -3
  528. package/{shared → unbundled}/affix.cjs +10 -11
  529. package/{shared → unbundled}/affix.js +2 -3
  530. package/{shared → unbundled}/anchored.cjs +7 -8
  531. package/{shared → unbundled}/anchored.js +1 -2
  532. package/{shared → unbundled}/attribute-binding-behaviour.cjs +3 -3
  533. package/{shared → unbundled}/attribute-binding-behaviour.js +1 -1
  534. package/{shared → unbundled}/base-progress.cjs +6 -5
  535. package/{shared → unbundled}/base-progress.js +2 -1
  536. package/{shared → unbundled}/breadcrumb-item.cjs +3 -2
  537. package/{shared → unbundled}/breadcrumb-item.js +2 -1
  538. package/{shared → unbundled}/button.cjs +10 -9
  539. package/{shared → unbundled}/button.js +2 -1
  540. package/{shared → unbundled}/calendar-event.cjs +8 -7
  541. package/{shared → unbundled}/calendar-event.js +2 -1
  542. package/unbundled/calendar-picker.template.cjs +917 -0
  543. package/unbundled/calendar-picker.template.js +906 -0
  544. package/{shared → unbundled}/char-count.cjs +6 -7
  545. package/{shared → unbundled}/char-count.js +2 -3
  546. package/unbundled/definition.cjs +225 -0
  547. package/unbundled/definition.js +220 -0
  548. package/{shared/definition30.cjs → unbundled/definition2.cjs} +49 -46
  549. package/{shared/definition30.js → unbundled/definition2.js} +14 -11
  550. package/unbundled/definition3.cjs +207 -0
  551. package/{shared/definition62.js → unbundled/definition3.js} +6 -10
  552. package/unbundled/definition4.cjs +298 -0
  553. package/unbundled/definition4.js +293 -0
  554. package/{shared/definition65.cjs → unbundled/definition5.cjs} +7 -6
  555. package/{shared/definition65.js → unbundled/definition5.js} +3 -2
  556. package/{shared → unbundled}/delegates-aria.cjs +8 -28
  557. package/{shared → unbundled}/delegates-aria.js +6 -26
  558. package/{shared → unbundled}/divider.cjs +13 -7
  559. package/{shared → unbundled}/divider.js +11 -5
  560. package/{shared → unbundled}/form-associated.cjs +13 -13
  561. package/{shared → unbundled}/form-associated.js +2 -2
  562. package/{shared → unbundled}/form-element.cjs +3 -3
  563. package/{shared → unbundled}/form-element.js +1 -1
  564. package/{shared → unbundled}/host-semantics.cjs +2 -1
  565. package/{shared → unbundled}/host-semantics.js +2 -1
  566. package/unbundled/key-codes.cjs +10 -0
  567. package/unbundled/key-codes.js +7 -0
  568. package/{shared → unbundled}/linkable.cjs +11 -12
  569. package/{shared → unbundled}/linkable.js +1 -2
  570. package/{shared → unbundled}/listbox.cjs +22 -38
  571. package/{shared → unbundled}/listbox.js +4 -20
  572. package/{shared → unbundled}/localized.cjs +2 -2
  573. package/{shared → unbundled}/localized.js +1 -1
  574. package/{shared → unbundled}/mixins.cjs +27 -83
  575. package/{shared → unbundled}/mixins.js +6 -62
  576. package/{shared → unbundled}/option.cjs +42 -17
  577. package/{shared → unbundled}/option.js +29 -4
  578. package/{shared → unbundled}/picker-field.template.cjs +21 -21
  579. package/{shared → unbundled}/picker-field.template.js +7 -7
  580. package/{shared → unbundled}/slider.template.cjs +15 -19
  581. package/{shared → unbundled}/slider.template.js +3 -7
  582. package/unbundled/text-field.cjs +5 -0
  583. package/unbundled/text-field.js +3 -0
  584. package/{shared → unbundled}/time-selection-picker.template.cjs +28 -30
  585. package/{shared → unbundled}/time-selection-picker.template.js +4 -6
  586. package/unbundled/vivid-element.cjs +283 -0
  587. package/unbundled/vivid-element.js +274 -0
  588. package/unbundled/with-contextual-help.cjs +29 -0
  589. package/unbundled/with-contextual-help.js +27 -0
  590. package/{shared → unbundled}/with-error-text.cjs +2 -2
  591. package/{shared → unbundled}/with-error-text.js +1 -1
  592. package/{shared → unbundled}/with-success-text.cjs +2 -2
  593. package/{shared → unbundled}/with-success-text.js +1 -1
  594. package/video-player/definition.cjs +536 -0
  595. package/video-player/definition.js +530 -0
  596. package/video-player/index.cjs +536 -3
  597. package/video-player/index.js +35912 -2
  598. package/{shared/definition66.cjs → visually-hidden/definition.cjs} +6 -3
  599. package/{shared/definition66.js → visually-hidden/definition.js} +3 -2
  600. package/visually-hidden/index.cjs +1 -5
  601. package/visually-hidden/index.js +2 -3
  602. package/vivid.api.json +716 -914
  603. package/shared/_has.cjs +0 -58
  604. package/shared/_has.js +0 -54
  605. package/shared/aria.cjs +0 -11
  606. package/shared/aria.js +0 -9
  607. package/shared/calendar-picker.template.cjs +0 -6377
  608. package/shared/calendar-picker.template.js +0 -6366
  609. package/shared/children.cjs +0 -61
  610. package/shared/children.js +0 -59
  611. package/shared/class-names.cjs +0 -17
  612. package/shared/class-names.js +0 -15
  613. package/shared/definition.cjs +0 -145
  614. package/shared/definition.js +0 -141
  615. package/shared/definition11.cjs +0 -220
  616. package/shared/definition11.js +0 -215
  617. package/shared/definition14.cjs +0 -185
  618. package/shared/definition24.cjs +0 -80
  619. package/shared/definition24.js +0 -76
  620. package/shared/definition25.cjs +0 -90
  621. package/shared/definition25.js +0 -86
  622. package/shared/definition26.cjs +0 -2514
  623. package/shared/definition26.js +0 -2510
  624. package/shared/definition32.cjs +0 -120
  625. package/shared/definition32.js +0 -116
  626. package/shared/definition36.cjs +0 -432
  627. package/shared/definition37.cjs +0 -71
  628. package/shared/definition37.js +0 -68
  629. package/shared/definition44.cjs +0 -14666
  630. package/shared/definition44.js +0 -14662
  631. package/shared/definition50.cjs +0 -148
  632. package/shared/definition50.js +0 -144
  633. package/shared/definition53.cjs +0 -124
  634. package/shared/definition53.js +0 -120
  635. package/shared/definition56.cjs +0 -154
  636. package/shared/definition56.js +0 -150
  637. package/shared/definition57.cjs +0 -335
  638. package/shared/definition57.js +0 -331
  639. package/shared/definition59.cjs +0 -39
  640. package/shared/definition62.cjs +0 -211
  641. package/shared/definition64.cjs +0 -69579
  642. package/shared/definition64.js +0 -69575
  643. package/shared/definition67.cjs +0 -2227
  644. package/shared/definition67.js +0 -2222
  645. package/shared/dom.cjs +0 -10
  646. package/shared/dom.js +0 -8
  647. package/shared/key-codes.cjs +0 -32
  648. package/shared/key-codes.js +0 -18
  649. package/shared/numbers.cjs +0 -38
  650. package/shared/numbers.js +0 -34
  651. package/shared/ref.cjs +0 -43
  652. package/shared/ref.js +0 -41
  653. package/shared/repeat.cjs +0 -767
  654. package/shared/repeat.js +0 -764
  655. package/shared/slotted.cjs +0 -123
  656. package/shared/slotted.js +0 -119
  657. package/shared/strings.cjs +0 -11
  658. package/shared/strings.js +0 -9
  659. package/shared/text-field.cjs +0 -5
  660. package/shared/text-field.js +0 -3
  661. package/shared/vivid-element.cjs +0 -2771
  662. package/shared/vivid-element.js +0 -2748
  663. package/shared/when.cjs +0 -31
  664. package/shared/when.js +0 -29
  665. /package/{shared → unbundled}/enums.cjs +0 -0
  666. /package/{shared → unbundled}/enums.js +0 -0
  667. /package/{shared → unbundled}/index.cjs +0 -0
  668. /package/{shared → unbundled}/index.js +0 -0
  669. /package/{shared → unbundled}/playbackRates.cjs +0 -0
  670. /package/{shared → unbundled}/playbackRates.js +0 -0
  671. /package/{shared → unbundled}/scrollIntoView.cjs +0 -0
  672. /package/{shared → unbundled}/scrollIntoView.js +0 -0
  673. /package/{shared → unbundled}/single-date-picker.cjs +0 -0
  674. /package/{shared → unbundled}/single-date-picker.js +0 -0
  675. /package/{shared → unbundled}/single-value-picker.cjs +0 -0
  676. /package/{shared → unbundled}/single-value-picker.js +0 -0
@@ -1,2771 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * A reference to globalThis, with support
5
- * for browsers that don't yet support the spec.
6
- * @public
7
- */
8
- const $global = (function () {
9
- if (typeof globalThis !== "undefined") {
10
- // We're running in a modern environment.
11
- return globalThis;
12
- }
13
- if (typeof global !== "undefined") {
14
- // We're running in NodeJS
15
- return global;
16
- }
17
- if (typeof self !== "undefined") {
18
- // We're running in a worker.
19
- return self;
20
- }
21
- if (typeof window !== "undefined") {
22
- // We're running in the browser's main thread.
23
- return window;
24
- }
25
- try {
26
- // Hopefully we never get here...
27
- // Not all environments allow eval and Function. Use only as a last resort:
28
- // eslint-disable-next-line no-new-func
29
- return new Function("return this")();
30
- }
31
- catch (_a) {
32
- // If all fails, give up and create an object.
33
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
34
- return {};
35
- }
36
- })();
37
- // API-only Polyfill for trustedTypes
38
- if ($global.trustedTypes === void 0) {
39
- $global.trustedTypes = { createPolicy: (n, r) => r };
40
- }
41
- const propConfig = {
42
- configurable: false,
43
- enumerable: false,
44
- writable: false,
45
- };
46
- if ($global.FAST === void 0) {
47
- Reflect.defineProperty($global, "FAST", Object.assign({ value: Object.create(null) }, propConfig));
48
- }
49
- /**
50
- * The FAST global.
51
- * @internal
52
- */
53
- const FAST = $global.FAST;
54
- if (FAST.getById === void 0) {
55
- const storage = Object.create(null);
56
- Reflect.defineProperty(FAST, "getById", Object.assign({ value(id, initialize) {
57
- let found = storage[id];
58
- if (found === void 0) {
59
- found = initialize ? (storage[id] = initialize()) : null;
60
- }
61
- return found;
62
- } }, propConfig));
63
- }
64
- /**
65
- * A readonly, empty array.
66
- * @remarks
67
- * Typically returned by APIs that return arrays when there are
68
- * no actual items to return.
69
- * @internal
70
- */
71
- const emptyArray = Object.freeze([]);
72
- /**
73
- * Creates a function capable of locating metadata associated with a type.
74
- * @returns A metadata locator function.
75
- * @internal
76
- */
77
- function createMetadataLocator() {
78
- const metadataLookup = new WeakMap();
79
- return function (target) {
80
- let metadata = metadataLookup.get(target);
81
- if (metadata === void 0) {
82
- let currentTarget = Reflect.getPrototypeOf(target);
83
- while (metadata === void 0 && currentTarget !== null) {
84
- metadata = metadataLookup.get(currentTarget);
85
- currentTarget = Reflect.getPrototypeOf(currentTarget);
86
- }
87
- metadata = metadata === void 0 ? [] : metadata.slice(0);
88
- metadataLookup.set(target, metadata);
89
- }
90
- return metadata;
91
- };
92
- }
93
-
94
- const updateQueue = $global.FAST.getById(1 /* updateQueue */, () => {
95
- const tasks = [];
96
- const pendingErrors = [];
97
- function throwFirstError() {
98
- if (pendingErrors.length) {
99
- throw pendingErrors.shift();
100
- }
101
- }
102
- function tryRunTask(task) {
103
- try {
104
- task.call();
105
- }
106
- catch (error) {
107
- pendingErrors.push(error);
108
- setTimeout(throwFirstError, 0);
109
- }
110
- }
111
- function process() {
112
- const capacity = 1024;
113
- let index = 0;
114
- while (index < tasks.length) {
115
- tryRunTask(tasks[index]);
116
- index++;
117
- // Prevent leaking memory for long chains of recursive calls to `DOM.queueUpdate`.
118
- // If we call `DOM.queueUpdate` within a task scheduled by `DOM.queueUpdate`, the queue will
119
- // grow, but to avoid an O(n) walk for every task we execute, we don't
120
- // shift tasks off the queue after they have been executed.
121
- // Instead, we periodically shift 1024 tasks off the queue.
122
- if (index > capacity) {
123
- // Manually shift all values starting at the index back to the
124
- // beginning of the queue.
125
- for (let scan = 0, newLength = tasks.length - index; scan < newLength; scan++) {
126
- tasks[scan] = tasks[scan + index];
127
- }
128
- tasks.length -= index;
129
- index = 0;
130
- }
131
- }
132
- tasks.length = 0;
133
- }
134
- function enqueue(callable) {
135
- if (tasks.length < 1) {
136
- $global.requestAnimationFrame(process);
137
- }
138
- tasks.push(callable);
139
- }
140
- return Object.freeze({
141
- enqueue,
142
- process,
143
- });
144
- });
145
- /* eslint-disable */
146
- const fastHTMLPolicy = $global.trustedTypes.createPolicy("fast-html", {
147
- createHTML: html => html,
148
- });
149
- /* eslint-enable */
150
- let htmlPolicy = fastHTMLPolicy;
151
- const marker = `fast-${Math.random().toString(36).substring(2, 8)}`;
152
- /** @internal */
153
- const _interpolationStart = `${marker}{`;
154
- /** @internal */
155
- const _interpolationEnd = `}${marker}`;
156
- /**
157
- * Common DOM APIs.
158
- * @public
159
- */
160
- const DOM = Object.freeze({
161
- /**
162
- * Indicates whether the DOM supports the adoptedStyleSheets feature.
163
- */
164
- supportsAdoptedStyleSheets: Array.isArray(document.adoptedStyleSheets) &&
165
- "replace" in CSSStyleSheet.prototype,
166
- /**
167
- * Sets the HTML trusted types policy used by the templating engine.
168
- * @param policy - The policy to set for HTML.
169
- * @remarks
170
- * This API can only be called once, for security reasons. It should be
171
- * called by the application developer at the start of their program.
172
- */
173
- setHTMLPolicy(policy) {
174
- if (htmlPolicy !== fastHTMLPolicy) {
175
- throw new Error("The HTML policy can only be set once.");
176
- }
177
- htmlPolicy = policy;
178
- },
179
- /**
180
- * Turns a string into trusted HTML using the configured trusted types policy.
181
- * @param html - The string to turn into trusted HTML.
182
- * @remarks
183
- * Used internally by the template engine when creating templates
184
- * and setting innerHTML.
185
- */
186
- createHTML(html) {
187
- return htmlPolicy.createHTML(html);
188
- },
189
- /**
190
- * Determines if the provided node is a template marker used by the runtime.
191
- * @param node - The node to test.
192
- */
193
- isMarker(node) {
194
- return node && node.nodeType === 8 && node.data.startsWith(marker);
195
- },
196
- /**
197
- * Given a marker node, extract the {@link HTMLDirective} index from the placeholder.
198
- * @param node - The marker node to extract the index from.
199
- */
200
- extractDirectiveIndexFromMarker(node) {
201
- return parseInt(node.data.replace(`${marker}:`, ""));
202
- },
203
- /**
204
- * Creates a placeholder string suitable for marking out a location *within*
205
- * an attribute value or HTML content.
206
- * @param index - The directive index to create the placeholder for.
207
- * @remarks
208
- * Used internally by binding directives.
209
- */
210
- createInterpolationPlaceholder(index) {
211
- return `${_interpolationStart}${index}${_interpolationEnd}`;
212
- },
213
- /**
214
- * Creates a placeholder that manifests itself as an attribute on an
215
- * element.
216
- * @param attributeName - The name of the custom attribute.
217
- * @param index - The directive index to create the placeholder for.
218
- * @remarks
219
- * Used internally by attribute directives such as `ref`, `slotted`, and `children`.
220
- */
221
- createCustomAttributePlaceholder(attributeName, index) {
222
- return `${attributeName}="${this.createInterpolationPlaceholder(index)}"`;
223
- },
224
- /**
225
- * Creates a placeholder that manifests itself as a marker within the DOM structure.
226
- * @param index - The directive index to create the placeholder for.
227
- * @remarks
228
- * Used internally by structural directives such as `repeat`.
229
- */
230
- createBlockPlaceholder(index) {
231
- return `<!--${marker}:${index}-->`;
232
- },
233
- /**
234
- * Schedules DOM update work in the next async batch.
235
- * @param callable - The callable function or object to queue.
236
- */
237
- queueUpdate: updateQueue.enqueue,
238
- /**
239
- * Immediately processes all work previously scheduled
240
- * through queueUpdate.
241
- * @remarks
242
- * This also forces nextUpdate promises
243
- * to resolve.
244
- */
245
- processUpdates: updateQueue.process,
246
- /**
247
- * Resolves with the next DOM update.
248
- */
249
- nextUpdate() {
250
- return new Promise(updateQueue.enqueue);
251
- },
252
- /**
253
- * Sets an attribute value on an element.
254
- * @param element - The element to set the attribute value on.
255
- * @param attributeName - The attribute name to set.
256
- * @param value - The value of the attribute to set.
257
- * @remarks
258
- * If the value is `null` or `undefined`, the attribute is removed, otherwise
259
- * it is set to the provided value using the standard `setAttribute` API.
260
- */
261
- setAttribute(element, attributeName, value) {
262
- if (value === null || value === undefined) {
263
- element.removeAttribute(attributeName);
264
- }
265
- else {
266
- element.setAttribute(attributeName, value);
267
- }
268
- },
269
- /**
270
- * Sets a boolean attribute value.
271
- * @param element - The element to set the boolean attribute value on.
272
- * @param attributeName - The attribute name to set.
273
- * @param value - The value of the attribute to set.
274
- * @remarks
275
- * If the value is true, the attribute is added; otherwise it is removed.
276
- */
277
- setBooleanAttribute(element, attributeName, value) {
278
- value
279
- ? element.setAttribute(attributeName, "")
280
- : element.removeAttribute(attributeName);
281
- },
282
- /**
283
- * Removes all the child nodes of the provided parent node.
284
- * @param parent - The node to remove the children from.
285
- */
286
- removeChildNodes(parent) {
287
- for (let child = parent.firstChild; child !== null; child = parent.firstChild) {
288
- parent.removeChild(child);
289
- }
290
- },
291
- /**
292
- * Creates a TreeWalker configured to walk a template fragment.
293
- * @param fragment - The fragment to walk.
294
- */
295
- createTemplateWalker(fragment) {
296
- return document.createTreeWalker(fragment, 133, // element, text, comment
297
- null, false);
298
- },
299
- });
300
-
301
- /**
302
- * An implementation of {@link Notifier} that efficiently keeps track of
303
- * subscribers interested in a specific change notification on an
304
- * observable source.
305
- *
306
- * @remarks
307
- * This set is optimized for the most common scenario of 1 or 2 subscribers.
308
- * With this in mind, it can store a subscriber in an internal field, allowing it to avoid Array#push operations.
309
- * If the set ever exceeds two subscribers, it upgrades to an array automatically.
310
- * @public
311
- */
312
- class SubscriberSet {
313
- /**
314
- * Creates an instance of SubscriberSet for the specified source.
315
- * @param source - The object source that subscribers will receive notifications from.
316
- * @param initialSubscriber - An initial subscriber to changes.
317
- */
318
- constructor(source, initialSubscriber) {
319
- this.sub1 = void 0;
320
- this.sub2 = void 0;
321
- this.spillover = void 0;
322
- this.source = source;
323
- this.sub1 = initialSubscriber;
324
- }
325
- /**
326
- * Checks whether the provided subscriber has been added to this set.
327
- * @param subscriber - The subscriber to test for inclusion in this set.
328
- */
329
- has(subscriber) {
330
- return this.spillover === void 0
331
- ? this.sub1 === subscriber || this.sub2 === subscriber
332
- : this.spillover.indexOf(subscriber) !== -1;
333
- }
334
- /**
335
- * Subscribes to notification of changes in an object's state.
336
- * @param subscriber - The object that is subscribing for change notification.
337
- */
338
- subscribe(subscriber) {
339
- const spillover = this.spillover;
340
- if (spillover === void 0) {
341
- if (this.has(subscriber)) {
342
- return;
343
- }
344
- if (this.sub1 === void 0) {
345
- this.sub1 = subscriber;
346
- return;
347
- }
348
- if (this.sub2 === void 0) {
349
- this.sub2 = subscriber;
350
- return;
351
- }
352
- this.spillover = [this.sub1, this.sub2, subscriber];
353
- this.sub1 = void 0;
354
- this.sub2 = void 0;
355
- }
356
- else {
357
- const index = spillover.indexOf(subscriber);
358
- if (index === -1) {
359
- spillover.push(subscriber);
360
- }
361
- }
362
- }
363
- /**
364
- * Unsubscribes from notification of changes in an object's state.
365
- * @param subscriber - The object that is unsubscribing from change notification.
366
- */
367
- unsubscribe(subscriber) {
368
- const spillover = this.spillover;
369
- if (spillover === void 0) {
370
- if (this.sub1 === subscriber) {
371
- this.sub1 = void 0;
372
- }
373
- else if (this.sub2 === subscriber) {
374
- this.sub2 = void 0;
375
- }
376
- }
377
- else {
378
- const index = spillover.indexOf(subscriber);
379
- if (index !== -1) {
380
- spillover.splice(index, 1);
381
- }
382
- }
383
- }
384
- /**
385
- * Notifies all subscribers.
386
- * @param args - Data passed along to subscribers during notification.
387
- */
388
- notify(args) {
389
- const spillover = this.spillover;
390
- const source = this.source;
391
- if (spillover === void 0) {
392
- const sub1 = this.sub1;
393
- const sub2 = this.sub2;
394
- if (sub1 !== void 0) {
395
- sub1.handleChange(source, args);
396
- }
397
- if (sub2 !== void 0) {
398
- sub2.handleChange(source, args);
399
- }
400
- }
401
- else {
402
- for (let i = 0, ii = spillover.length; i < ii; ++i) {
403
- spillover[i].handleChange(source, args);
404
- }
405
- }
406
- }
407
- }
408
- /**
409
- * An implementation of Notifier that allows subscribers to be notified
410
- * of individual property changes on an object.
411
- * @public
412
- */
413
- class PropertyChangeNotifier {
414
- /**
415
- * Creates an instance of PropertyChangeNotifier for the specified source.
416
- * @param source - The object source that subscribers will receive notifications from.
417
- */
418
- constructor(source) {
419
- this.subscribers = {};
420
- this.sourceSubscribers = null;
421
- this.source = source;
422
- }
423
- /**
424
- * Notifies all subscribers, based on the specified property.
425
- * @param propertyName - The property name, passed along to subscribers during notification.
426
- */
427
- notify(propertyName) {
428
- var _a;
429
- const subscribers = this.subscribers[propertyName];
430
- if (subscribers !== void 0) {
431
- subscribers.notify(propertyName);
432
- }
433
- (_a = this.sourceSubscribers) === null || _a === void 0 ? void 0 : _a.notify(propertyName);
434
- }
435
- /**
436
- * Subscribes to notification of changes in an object's state.
437
- * @param subscriber - The object that is subscribing for change notification.
438
- * @param propertyToWatch - The name of the property that the subscriber is interested in watching for changes.
439
- */
440
- subscribe(subscriber, propertyToWatch) {
441
- var _a;
442
- if (propertyToWatch) {
443
- let subscribers = this.subscribers[propertyToWatch];
444
- if (subscribers === void 0) {
445
- this.subscribers[propertyToWatch] = subscribers = new SubscriberSet(this.source);
446
- }
447
- subscribers.subscribe(subscriber);
448
- }
449
- else {
450
- this.sourceSubscribers =
451
- (_a = this.sourceSubscribers) !== null && _a !== void 0 ? _a : new SubscriberSet(this.source);
452
- this.sourceSubscribers.subscribe(subscriber);
453
- }
454
- }
455
- /**
456
- * Unsubscribes from notification of changes in an object's state.
457
- * @param subscriber - The object that is unsubscribing from change notification.
458
- * @param propertyToUnwatch - The name of the property that the subscriber is no longer interested in watching.
459
- */
460
- unsubscribe(subscriber, propertyToUnwatch) {
461
- var _a;
462
- if (propertyToUnwatch) {
463
- const subscribers = this.subscribers[propertyToUnwatch];
464
- if (subscribers !== void 0) {
465
- subscribers.unsubscribe(subscriber);
466
- }
467
- }
468
- else {
469
- (_a = this.sourceSubscribers) === null || _a === void 0 ? void 0 : _a.unsubscribe(subscriber);
470
- }
471
- }
472
- }
473
-
474
- /**
475
- * Common Observable APIs.
476
- * @public
477
- */
478
- const Observable = FAST.getById(2 /* observable */, () => {
479
- const volatileRegex = /(:|&&|\|\||if)/;
480
- const notifierLookup = new WeakMap();
481
- const queueUpdate = DOM.queueUpdate;
482
- let watcher = void 0;
483
- let createArrayObserver = (array) => {
484
- throw new Error("Must call enableArrayObservation before observing arrays.");
485
- };
486
- function getNotifier(source) {
487
- let found = source.$fastController || notifierLookup.get(source);
488
- if (found === void 0) {
489
- if (Array.isArray(source)) {
490
- found = createArrayObserver(source);
491
- }
492
- else {
493
- notifierLookup.set(source, (found = new PropertyChangeNotifier(source)));
494
- }
495
- }
496
- return found;
497
- }
498
- const getAccessors = createMetadataLocator();
499
- class DefaultObservableAccessor {
500
- constructor(name) {
501
- this.name = name;
502
- this.field = `_${name}`;
503
- this.callback = `${name}Changed`;
504
- }
505
- getValue(source) {
506
- if (watcher !== void 0) {
507
- watcher.watch(source, this.name);
508
- }
509
- return source[this.field];
510
- }
511
- setValue(source, newValue) {
512
- const field = this.field;
513
- const oldValue = source[field];
514
- if (oldValue !== newValue) {
515
- source[field] = newValue;
516
- const callback = source[this.callback];
517
- if (typeof callback === "function") {
518
- callback.call(source, oldValue, newValue);
519
- }
520
- getNotifier(source).notify(this.name);
521
- }
522
- }
523
- }
524
- class BindingObserverImplementation extends SubscriberSet {
525
- constructor(binding, initialSubscriber, isVolatileBinding = false) {
526
- super(binding, initialSubscriber);
527
- this.binding = binding;
528
- this.isVolatileBinding = isVolatileBinding;
529
- this.needsRefresh = true;
530
- this.needsQueue = true;
531
- this.first = this;
532
- this.last = null;
533
- this.propertySource = void 0;
534
- this.propertyName = void 0;
535
- this.notifier = void 0;
536
- this.next = void 0;
537
- }
538
- observe(source, context) {
539
- if (this.needsRefresh && this.last !== null) {
540
- this.disconnect();
541
- }
542
- const previousWatcher = watcher;
543
- watcher = this.needsRefresh ? this : void 0;
544
- this.needsRefresh = this.isVolatileBinding;
545
- const result = this.binding(source, context);
546
- watcher = previousWatcher;
547
- return result;
548
- }
549
- disconnect() {
550
- if (this.last !== null) {
551
- let current = this.first;
552
- while (current !== void 0) {
553
- current.notifier.unsubscribe(this, current.propertyName);
554
- current = current.next;
555
- }
556
- this.last = null;
557
- this.needsRefresh = this.needsQueue = true;
558
- }
559
- }
560
- watch(propertySource, propertyName) {
561
- const prev = this.last;
562
- const notifier = getNotifier(propertySource);
563
- const current = prev === null ? this.first : {};
564
- current.propertySource = propertySource;
565
- current.propertyName = propertyName;
566
- current.notifier = notifier;
567
- notifier.subscribe(this, propertyName);
568
- if (prev !== null) {
569
- if (!this.needsRefresh) {
570
- // Declaring the variable prior to assignment below circumvents
571
- // a bug in Angular's optimization process causing infinite recursion
572
- // of this watch() method. Details https://github.com/microsoft/fast/issues/4969
573
- let prevValue;
574
- watcher = void 0;
575
- /* eslint-disable-next-line */
576
- prevValue = prev.propertySource[prev.propertyName];
577
- /* eslint-disable-next-line @typescript-eslint/no-this-alias */
578
- watcher = this;
579
- if (propertySource === prevValue) {
580
- this.needsRefresh = true;
581
- }
582
- }
583
- prev.next = current;
584
- }
585
- this.last = current;
586
- }
587
- handleChange() {
588
- if (this.needsQueue) {
589
- this.needsQueue = false;
590
- queueUpdate(this);
591
- }
592
- }
593
- call() {
594
- if (this.last !== null) {
595
- this.needsQueue = true;
596
- this.notify(this);
597
- }
598
- }
599
- records() {
600
- let next = this.first;
601
- return {
602
- next: () => {
603
- const current = next;
604
- if (current === undefined) {
605
- return { value: void 0, done: true };
606
- }
607
- else {
608
- next = next.next;
609
- return {
610
- value: current,
611
- done: false,
612
- };
613
- }
614
- },
615
- [Symbol.iterator]: function () {
616
- return this;
617
- },
618
- };
619
- }
620
- }
621
- return Object.freeze({
622
- /**
623
- * @internal
624
- * @param factory - The factory used to create array observers.
625
- */
626
- setArrayObserverFactory(factory) {
627
- createArrayObserver = factory;
628
- },
629
- /**
630
- * Gets a notifier for an object or Array.
631
- * @param source - The object or Array to get the notifier for.
632
- */
633
- getNotifier,
634
- /**
635
- * Records a property change for a source object.
636
- * @param source - The object to record the change against.
637
- * @param propertyName - The property to track as changed.
638
- */
639
- track(source, propertyName) {
640
- if (watcher !== void 0) {
641
- watcher.watch(source, propertyName);
642
- }
643
- },
644
- /**
645
- * Notifies watchers that the currently executing property getter or function is volatile
646
- * with respect to its observable dependencies.
647
- */
648
- trackVolatile() {
649
- if (watcher !== void 0) {
650
- watcher.needsRefresh = true;
651
- }
652
- },
653
- /**
654
- * Notifies subscribers of a source object of changes.
655
- * @param source - the object to notify of changes.
656
- * @param args - The change args to pass to subscribers.
657
- */
658
- notify(source, args) {
659
- getNotifier(source).notify(args);
660
- },
661
- /**
662
- * Defines an observable property on an object or prototype.
663
- * @param target - The target object to define the observable on.
664
- * @param nameOrAccessor - The name of the property to define as observable;
665
- * or a custom accessor that specifies the property name and accessor implementation.
666
- */
667
- defineProperty(target, nameOrAccessor) {
668
- if (typeof nameOrAccessor === "string") {
669
- nameOrAccessor = new DefaultObservableAccessor(nameOrAccessor);
670
- }
671
- getAccessors(target).push(nameOrAccessor);
672
- Reflect.defineProperty(target, nameOrAccessor.name, {
673
- enumerable: true,
674
- get: function () {
675
- return nameOrAccessor.getValue(this);
676
- },
677
- set: function (newValue) {
678
- nameOrAccessor.setValue(this, newValue);
679
- },
680
- });
681
- },
682
- /**
683
- * Finds all the observable accessors defined on the target,
684
- * including its prototype chain.
685
- * @param target - The target object to search for accessor on.
686
- */
687
- getAccessors,
688
- /**
689
- * Creates a {@link BindingObserver} that can watch the
690
- * provided {@link Binding} for changes.
691
- * @param binding - The binding to observe.
692
- * @param initialSubscriber - An initial subscriber to changes in the binding value.
693
- * @param isVolatileBinding - Indicates whether the binding's dependency list must be re-evaluated on every value evaluation.
694
- */
695
- binding(binding, initialSubscriber, isVolatileBinding = this.isVolatileBinding(binding)) {
696
- return new BindingObserverImplementation(binding, initialSubscriber, isVolatileBinding);
697
- },
698
- /**
699
- * Determines whether a binding expression is volatile and needs to have its dependency list re-evaluated
700
- * on every evaluation of the value.
701
- * @param binding - The binding to inspect.
702
- */
703
- isVolatileBinding(binding) {
704
- return volatileRegex.test(binding.toString());
705
- },
706
- });
707
- });
708
- /**
709
- * Decorator: Defines an observable property on the target.
710
- * @param target - The target to define the observable on.
711
- * @param nameOrAccessor - The property name or accessor to define the observable as.
712
- * @public
713
- */
714
- function observable(target, nameOrAccessor) {
715
- Observable.defineProperty(target, nameOrAccessor);
716
- }
717
- /**
718
- * Decorator: Marks a property getter as having volatile observable dependencies.
719
- * @param target - The target that the property is defined on.
720
- * @param name - The property name.
721
- * @param name - The existing descriptor.
722
- * @public
723
- */
724
- function volatile(target, name, descriptor) {
725
- return Object.assign({}, descriptor, {
726
- get: function () {
727
- Observable.trackVolatile();
728
- return descriptor.get.apply(this);
729
- },
730
- });
731
- }
732
- const contextEvent = FAST.getById(3 /* contextEvent */, () => {
733
- let current = null;
734
- return {
735
- get() {
736
- return current;
737
- },
738
- set(event) {
739
- current = event;
740
- },
741
- };
742
- });
743
- /**
744
- * Provides additional contextual information available to behaviors and expressions.
745
- * @public
746
- */
747
- class ExecutionContext {
748
- constructor() {
749
- /**
750
- * The index of the current item within a repeat context.
751
- */
752
- this.index = 0;
753
- /**
754
- * The length of the current collection within a repeat context.
755
- */
756
- this.length = 0;
757
- /**
758
- * The parent data object within a repeat context.
759
- */
760
- this.parent = null;
761
- /**
762
- * The parent execution context when in nested context scenarios.
763
- */
764
- this.parentContext = null;
765
- }
766
- /**
767
- * The current event within an event handler.
768
- */
769
- get event() {
770
- return contextEvent.get();
771
- }
772
- /**
773
- * Indicates whether the current item within a repeat context
774
- * has an even index.
775
- */
776
- get isEven() {
777
- return this.index % 2 === 0;
778
- }
779
- /**
780
- * Indicates whether the current item within a repeat context
781
- * has an odd index.
782
- */
783
- get isOdd() {
784
- return this.index % 2 !== 0;
785
- }
786
- /**
787
- * Indicates whether the current item within a repeat context
788
- * is the first item in the collection.
789
- */
790
- get isFirst() {
791
- return this.index === 0;
792
- }
793
- /**
794
- * Indicates whether the current item within a repeat context
795
- * is somewhere in the middle of the collection.
796
- */
797
- get isInMiddle() {
798
- return !this.isFirst && !this.isLast;
799
- }
800
- /**
801
- * Indicates whether the current item within a repeat context
802
- * is the last item in the collection.
803
- */
804
- get isLast() {
805
- return this.index === this.length - 1;
806
- }
807
- /**
808
- * Sets the event for the current execution context.
809
- * @param event - The event to set.
810
- * @internal
811
- */
812
- static setEvent(event) {
813
- contextEvent.set(event);
814
- }
815
- }
816
- Observable.defineProperty(ExecutionContext.prototype, "index");
817
- Observable.defineProperty(ExecutionContext.prototype, "length");
818
- /**
819
- * The default execution context used in binding expressions.
820
- * @public
821
- */
822
- const defaultExecutionContext = Object.seal(new ExecutionContext());
823
-
824
- /**
825
- * Instructs the template engine to apply behavior to a node.
826
- * @public
827
- */
828
- class HTMLDirective {
829
- constructor() {
830
- /**
831
- * The index of the DOM node to which the created behavior will apply.
832
- */
833
- this.targetIndex = 0;
834
- }
835
- }
836
- /**
837
- * A {@link HTMLDirective} that targets a named attribute or property on a node.
838
- * @public
839
- */
840
- class TargetedHTMLDirective extends HTMLDirective {
841
- constructor() {
842
- super(...arguments);
843
- /**
844
- * Creates a placeholder string based on the directive's index within the template.
845
- * @param index - The index of the directive within the template.
846
- */
847
- this.createPlaceholder = DOM.createInterpolationPlaceholder;
848
- }
849
- }
850
- /**
851
- * A directive that attaches special behavior to an element via a custom attribute.
852
- * @public
853
- */
854
- class AttachedBehaviorHTMLDirective extends HTMLDirective {
855
- /**
856
- *
857
- * @param name - The name of the behavior; used as a custom attribute on the element.
858
- * @param behavior - The behavior to instantiate and attach to the element.
859
- * @param options - Options to pass to the behavior during creation.
860
- */
861
- constructor(name, behavior, options) {
862
- super();
863
- this.name = name;
864
- this.behavior = behavior;
865
- this.options = options;
866
- }
867
- /**
868
- * Creates a placeholder string based on the directive's index within the template.
869
- * @param index - The index of the directive within the template.
870
- * @remarks
871
- * Creates a custom attribute placeholder.
872
- */
873
- createPlaceholder(index) {
874
- return DOM.createCustomAttributePlaceholder(this.name, index);
875
- }
876
- /**
877
- * Creates a behavior for the provided target node.
878
- * @param target - The node instance to create the behavior for.
879
- * @remarks
880
- * Creates an instance of the `behavior` type this directive was constructed with
881
- * and passes the target and options to that `behavior`'s constructor.
882
- */
883
- createBehavior(target) {
884
- return new this.behavior(target, this.options);
885
- }
886
- }
887
-
888
- function normalBind(source, context) {
889
- this.source = source;
890
- this.context = context;
891
- if (this.bindingObserver === null) {
892
- this.bindingObserver = Observable.binding(this.binding, this, this.isBindingVolatile);
893
- }
894
- this.updateTarget(this.bindingObserver.observe(source, context));
895
- }
896
- function triggerBind(source, context) {
897
- this.source = source;
898
- this.context = context;
899
- this.target.addEventListener(this.targetName, this);
900
- }
901
- function normalUnbind() {
902
- this.bindingObserver.disconnect();
903
- this.source = null;
904
- this.context = null;
905
- }
906
- function contentUnbind() {
907
- this.bindingObserver.disconnect();
908
- this.source = null;
909
- this.context = null;
910
- const view = this.target.$fastView;
911
- if (view !== void 0 && view.isComposed) {
912
- view.unbind();
913
- view.needsBindOnly = true;
914
- }
915
- }
916
- function triggerUnbind() {
917
- this.target.removeEventListener(this.targetName, this);
918
- this.source = null;
919
- this.context = null;
920
- }
921
- function updateAttributeTarget(value) {
922
- DOM.setAttribute(this.target, this.targetName, value);
923
- }
924
- function updateBooleanAttributeTarget(value) {
925
- DOM.setBooleanAttribute(this.target, this.targetName, value);
926
- }
927
- function updateContentTarget(value) {
928
- // If there's no actual value, then this equates to the
929
- // empty string for the purposes of content bindings.
930
- if (value === null || value === undefined) {
931
- value = "";
932
- }
933
- // If the value has a "create" method, then it's a template-like.
934
- if (value.create) {
935
- this.target.textContent = "";
936
- let view = this.target.$fastView;
937
- // If there's no previous view that we might be able to
938
- // reuse then create a new view from the template.
939
- if (view === void 0) {
940
- view = value.create();
941
- }
942
- else {
943
- // If there is a previous view, but it wasn't created
944
- // from the same template as the new value, then we
945
- // need to remove the old view if it's still in the DOM
946
- // and create a new view from the template.
947
- if (this.target.$fastTemplate !== value) {
948
- if (view.isComposed) {
949
- view.remove();
950
- view.unbind();
951
- }
952
- view = value.create();
953
- }
954
- }
955
- // It's possible that the value is the same as the previous template
956
- // and that there's actually no need to compose it.
957
- if (!view.isComposed) {
958
- view.isComposed = true;
959
- view.bind(this.source, this.context);
960
- view.insertBefore(this.target);
961
- this.target.$fastView = view;
962
- this.target.$fastTemplate = value;
963
- }
964
- else if (view.needsBindOnly) {
965
- view.needsBindOnly = false;
966
- view.bind(this.source, this.context);
967
- }
968
- }
969
- else {
970
- const view = this.target.$fastView;
971
- // If there is a view and it's currently composed into
972
- // the DOM, then we need to remove it.
973
- if (view !== void 0 && view.isComposed) {
974
- view.isComposed = false;
975
- view.remove();
976
- if (view.needsBindOnly) {
977
- view.needsBindOnly = false;
978
- }
979
- else {
980
- view.unbind();
981
- }
982
- }
983
- this.target.textContent = value;
984
- }
985
- }
986
- function updatePropertyTarget(value) {
987
- this.target[this.targetName] = value;
988
- }
989
- function updateClassTarget(value) {
990
- const classVersions = this.classVersions || Object.create(null);
991
- const target = this.target;
992
- let version = this.version || 0;
993
- // Add the classes, tracking the version at which they were added.
994
- if (value !== null && value !== undefined && value.length) {
995
- const names = value.split(/\s+/);
996
- for (let i = 0, ii = names.length; i < ii; ++i) {
997
- const currentName = names[i];
998
- if (currentName === "") {
999
- continue;
1000
- }
1001
- classVersions[currentName] = version;
1002
- target.classList.add(currentName);
1003
- }
1004
- }
1005
- this.classVersions = classVersions;
1006
- this.version = version + 1;
1007
- // If this is the first call to add classes, there's no need to remove old ones.
1008
- if (version === 0) {
1009
- return;
1010
- }
1011
- // Remove classes from the previous version.
1012
- version -= 1;
1013
- for (const name in classVersions) {
1014
- if (classVersions[name] === version) {
1015
- target.classList.remove(name);
1016
- }
1017
- }
1018
- }
1019
- /**
1020
- * A directive that configures data binding to element content and attributes.
1021
- * @public
1022
- */
1023
- class HTMLBindingDirective extends TargetedHTMLDirective {
1024
- /**
1025
- * Creates an instance of BindingDirective.
1026
- * @param binding - A binding that returns the data used to update the DOM.
1027
- */
1028
- constructor(binding) {
1029
- super();
1030
- this.binding = binding;
1031
- this.bind = normalBind;
1032
- this.unbind = normalUnbind;
1033
- this.updateTarget = updateAttributeTarget;
1034
- this.isBindingVolatile = Observable.isVolatileBinding(this.binding);
1035
- }
1036
- /**
1037
- * Gets/sets the name of the attribute or property that this
1038
- * binding is targeting.
1039
- */
1040
- get targetName() {
1041
- return this.originalTargetName;
1042
- }
1043
- set targetName(value) {
1044
- this.originalTargetName = value;
1045
- if (value === void 0) {
1046
- return;
1047
- }
1048
- switch (value[0]) {
1049
- case ":":
1050
- this.cleanedTargetName = value.substr(1);
1051
- this.updateTarget = updatePropertyTarget;
1052
- if (this.cleanedTargetName === "innerHTML") {
1053
- const binding = this.binding;
1054
- this.binding = (s, c) => DOM.createHTML(binding(s, c));
1055
- }
1056
- break;
1057
- case "?":
1058
- this.cleanedTargetName = value.substr(1);
1059
- this.updateTarget = updateBooleanAttributeTarget;
1060
- break;
1061
- case "@":
1062
- this.cleanedTargetName = value.substr(1);
1063
- this.bind = triggerBind;
1064
- this.unbind = triggerUnbind;
1065
- break;
1066
- default:
1067
- this.cleanedTargetName = value;
1068
- if (value === "class") {
1069
- this.updateTarget = updateClassTarget;
1070
- }
1071
- break;
1072
- }
1073
- }
1074
- /**
1075
- * Makes this binding target the content of an element rather than
1076
- * a particular attribute or property.
1077
- */
1078
- targetAtContent() {
1079
- this.updateTarget = updateContentTarget;
1080
- this.unbind = contentUnbind;
1081
- }
1082
- /**
1083
- * Creates the runtime BindingBehavior instance based on the configuration
1084
- * information stored in the BindingDirective.
1085
- * @param target - The target node that the binding behavior should attach to.
1086
- */
1087
- createBehavior(target) {
1088
- /* eslint-disable-next-line @typescript-eslint/no-use-before-define */
1089
- return new BindingBehavior(target, this.binding, this.isBindingVolatile, this.bind, this.unbind, this.updateTarget, this.cleanedTargetName);
1090
- }
1091
- }
1092
- /**
1093
- * A behavior that updates content and attributes based on a configured
1094
- * BindingDirective.
1095
- * @public
1096
- */
1097
- class BindingBehavior {
1098
- /**
1099
- * Creates an instance of BindingBehavior.
1100
- * @param target - The target of the data updates.
1101
- * @param binding - The binding that returns the latest value for an update.
1102
- * @param isBindingVolatile - Indicates whether the binding has volatile dependencies.
1103
- * @param bind - The operation to perform during binding.
1104
- * @param unbind - The operation to perform during unbinding.
1105
- * @param updateTarget - The operation to perform when updating.
1106
- * @param targetName - The name of the target attribute or property to update.
1107
- */
1108
- constructor(target, binding, isBindingVolatile, bind, unbind, updateTarget, targetName) {
1109
- /** @internal */
1110
- this.source = null;
1111
- /** @internal */
1112
- this.context = null;
1113
- /** @internal */
1114
- this.bindingObserver = null;
1115
- this.target = target;
1116
- this.binding = binding;
1117
- this.isBindingVolatile = isBindingVolatile;
1118
- this.bind = bind;
1119
- this.unbind = unbind;
1120
- this.updateTarget = updateTarget;
1121
- this.targetName = targetName;
1122
- }
1123
- /** @internal */
1124
- handleChange() {
1125
- this.updateTarget(this.bindingObserver.observe(this.source, this.context));
1126
- }
1127
- /** @internal */
1128
- handleEvent(event) {
1129
- ExecutionContext.setEvent(event);
1130
- const result = this.binding(this.source, this.context);
1131
- ExecutionContext.setEvent(null);
1132
- if (result !== true) {
1133
- event.preventDefault();
1134
- }
1135
- }
1136
- }
1137
-
1138
- let sharedContext = null;
1139
- class CompilationContext {
1140
- addFactory(factory) {
1141
- factory.targetIndex = this.targetIndex;
1142
- this.behaviorFactories.push(factory);
1143
- }
1144
- captureContentBinding(directive) {
1145
- directive.targetAtContent();
1146
- this.addFactory(directive);
1147
- }
1148
- reset() {
1149
- this.behaviorFactories = [];
1150
- this.targetIndex = -1;
1151
- }
1152
- release() {
1153
- /* eslint-disable-next-line @typescript-eslint/no-this-alias */
1154
- sharedContext = this;
1155
- }
1156
- static borrow(directives) {
1157
- const shareable = sharedContext || new CompilationContext();
1158
- shareable.directives = directives;
1159
- shareable.reset();
1160
- sharedContext = null;
1161
- return shareable;
1162
- }
1163
- }
1164
- function createAggregateBinding(parts) {
1165
- if (parts.length === 1) {
1166
- return parts[0];
1167
- }
1168
- let targetName;
1169
- const partCount = parts.length;
1170
- const finalParts = parts.map((x) => {
1171
- if (typeof x === "string") {
1172
- return () => x;
1173
- }
1174
- targetName = x.targetName || targetName;
1175
- return x.binding;
1176
- });
1177
- const binding = (scope, context) => {
1178
- let output = "";
1179
- for (let i = 0; i < partCount; ++i) {
1180
- output += finalParts[i](scope, context);
1181
- }
1182
- return output;
1183
- };
1184
- const directive = new HTMLBindingDirective(binding);
1185
- directive.targetName = targetName;
1186
- return directive;
1187
- }
1188
- const interpolationEndLength = _interpolationEnd.length;
1189
- function parseContent(context, value) {
1190
- const valueParts = value.split(_interpolationStart);
1191
- if (valueParts.length === 1) {
1192
- return null;
1193
- }
1194
- const bindingParts = [];
1195
- for (let i = 0, ii = valueParts.length; i < ii; ++i) {
1196
- const current = valueParts[i];
1197
- const index = current.indexOf(_interpolationEnd);
1198
- let literal;
1199
- if (index === -1) {
1200
- literal = current;
1201
- }
1202
- else {
1203
- const directiveIndex = parseInt(current.substring(0, index));
1204
- bindingParts.push(context.directives[directiveIndex]);
1205
- literal = current.substring(index + interpolationEndLength);
1206
- }
1207
- if (literal !== "") {
1208
- bindingParts.push(literal);
1209
- }
1210
- }
1211
- return bindingParts;
1212
- }
1213
- function compileAttributes(context, node, includeBasicValues = false) {
1214
- const attributes = node.attributes;
1215
- for (let i = 0, ii = attributes.length; i < ii; ++i) {
1216
- const attr = attributes[i];
1217
- const attrValue = attr.value;
1218
- const parseResult = parseContent(context, attrValue);
1219
- let result = null;
1220
- if (parseResult === null) {
1221
- if (includeBasicValues) {
1222
- result = new HTMLBindingDirective(() => attrValue);
1223
- result.targetName = attr.name;
1224
- }
1225
- }
1226
- else {
1227
- result = createAggregateBinding(parseResult);
1228
- }
1229
- if (result !== null) {
1230
- node.removeAttributeNode(attr);
1231
- i--;
1232
- ii--;
1233
- context.addFactory(result);
1234
- }
1235
- }
1236
- }
1237
- function compileContent(context, node, walker) {
1238
- const parseResult = parseContent(context, node.textContent);
1239
- if (parseResult !== null) {
1240
- let lastNode = node;
1241
- for (let i = 0, ii = parseResult.length; i < ii; ++i) {
1242
- const currentPart = parseResult[i];
1243
- const currentNode = i === 0
1244
- ? node
1245
- : lastNode.parentNode.insertBefore(document.createTextNode(""), lastNode.nextSibling);
1246
- if (typeof currentPart === "string") {
1247
- currentNode.textContent = currentPart;
1248
- }
1249
- else {
1250
- currentNode.textContent = " ";
1251
- context.captureContentBinding(currentPart);
1252
- }
1253
- lastNode = currentNode;
1254
- context.targetIndex++;
1255
- if (currentNode !== node) {
1256
- walker.nextNode();
1257
- }
1258
- }
1259
- context.targetIndex--;
1260
- }
1261
- }
1262
- /**
1263
- * Compiles a template and associated directives into a raw compilation
1264
- * result which include a cloneable DocumentFragment and factories capable
1265
- * of attaching runtime behavior to nodes within the fragment.
1266
- * @param template - The template to compile.
1267
- * @param directives - The directives referenced by the template.
1268
- * @remarks
1269
- * The template that is provided for compilation is altered in-place
1270
- * and cannot be compiled again. If the original template must be preserved,
1271
- * it is recommended that you clone the original and pass the clone to this API.
1272
- * @public
1273
- */
1274
- function compileTemplate(template, directives) {
1275
- const fragment = template.content;
1276
- // https://bugs.chromium.org/p/chromium/issues/detail?id=1111864
1277
- document.adoptNode(fragment);
1278
- const context = CompilationContext.borrow(directives);
1279
- compileAttributes(context, template, true);
1280
- const hostBehaviorFactories = context.behaviorFactories;
1281
- context.reset();
1282
- const walker = DOM.createTemplateWalker(fragment);
1283
- let node;
1284
- while ((node = walker.nextNode())) {
1285
- context.targetIndex++;
1286
- switch (node.nodeType) {
1287
- case 1: // element node
1288
- compileAttributes(context, node);
1289
- break;
1290
- case 3: // text node
1291
- compileContent(context, node, walker);
1292
- break;
1293
- case 8: // comment
1294
- if (DOM.isMarker(node)) {
1295
- context.addFactory(directives[DOM.extractDirectiveIndexFromMarker(node)]);
1296
- }
1297
- }
1298
- }
1299
- let targetOffset = 0;
1300
- if (
1301
- // If the first node in a fragment is a marker, that means it's an unstable first node,
1302
- // because something like a when, repeat, etc. could add nodes before the marker.
1303
- // To mitigate this, we insert a stable first node. However, if we insert a node,
1304
- // that will alter the result of the TreeWalker. So, we also need to offset the target index.
1305
- DOM.isMarker(fragment.firstChild) ||
1306
- // Or if there is only one node and a directive, it means the template's content
1307
- // is *only* the directive. In that case, HTMLView.dispose() misses any nodes inserted by
1308
- // the directive. Inserting a new node ensures proper disposal of nodes added by the directive.
1309
- (fragment.childNodes.length === 1 && directives.length)) {
1310
- fragment.insertBefore(document.createComment(""), fragment.firstChild);
1311
- targetOffset = -1;
1312
- }
1313
- const viewBehaviorFactories = context.behaviorFactories;
1314
- context.release();
1315
- return {
1316
- fragment,
1317
- viewBehaviorFactories,
1318
- hostBehaviorFactories,
1319
- targetOffset,
1320
- };
1321
- }
1322
-
1323
- // A singleton Range instance used to efficiently remove ranges of DOM nodes.
1324
- // See the implementation of HTMLView below for further details.
1325
- const range = document.createRange();
1326
- /**
1327
- * The standard View implementation, which also implements ElementView and SyntheticView.
1328
- * @public
1329
- */
1330
- class HTMLView {
1331
- /**
1332
- * Constructs an instance of HTMLView.
1333
- * @param fragment - The html fragment that contains the nodes for this view.
1334
- * @param behaviors - The behaviors to be applied to this view.
1335
- */
1336
- constructor(fragment, behaviors) {
1337
- this.fragment = fragment;
1338
- this.behaviors = behaviors;
1339
- /**
1340
- * The data that the view is bound to.
1341
- */
1342
- this.source = null;
1343
- /**
1344
- * The execution context the view is running within.
1345
- */
1346
- this.context = null;
1347
- this.firstChild = fragment.firstChild;
1348
- this.lastChild = fragment.lastChild;
1349
- }
1350
- /**
1351
- * Appends the view's DOM nodes to the referenced node.
1352
- * @param node - The parent node to append the view's DOM nodes to.
1353
- */
1354
- appendTo(node) {
1355
- node.appendChild(this.fragment);
1356
- }
1357
- /**
1358
- * Inserts the view's DOM nodes before the referenced node.
1359
- * @param node - The node to insert the view's DOM before.
1360
- */
1361
- insertBefore(node) {
1362
- if (this.fragment.hasChildNodes()) {
1363
- node.parentNode.insertBefore(this.fragment, node);
1364
- }
1365
- else {
1366
- const end = this.lastChild;
1367
- if (node.previousSibling === end)
1368
- return;
1369
- const parentNode = node.parentNode;
1370
- let current = this.firstChild;
1371
- let next;
1372
- while (current !== end) {
1373
- next = current.nextSibling;
1374
- parentNode.insertBefore(current, node);
1375
- current = next;
1376
- }
1377
- parentNode.insertBefore(end, node);
1378
- }
1379
- }
1380
- /**
1381
- * Removes the view's DOM nodes.
1382
- * The nodes are not disposed and the view can later be re-inserted.
1383
- */
1384
- remove() {
1385
- const fragment = this.fragment;
1386
- const end = this.lastChild;
1387
- let current = this.firstChild;
1388
- let next;
1389
- while (current !== end) {
1390
- next = current.nextSibling;
1391
- fragment.appendChild(current);
1392
- current = next;
1393
- }
1394
- fragment.appendChild(end);
1395
- }
1396
- /**
1397
- * Removes the view and unbinds its behaviors, disposing of DOM nodes afterward.
1398
- * Once a view has been disposed, it cannot be inserted or bound again.
1399
- */
1400
- dispose() {
1401
- const parent = this.firstChild.parentNode;
1402
- const end = this.lastChild;
1403
- let current = this.firstChild;
1404
- let next;
1405
- while (current !== end) {
1406
- next = current.nextSibling;
1407
- parent.removeChild(current);
1408
- current = next;
1409
- }
1410
- parent.removeChild(end);
1411
- const behaviors = this.behaviors;
1412
- const oldSource = this.source;
1413
- for (let i = 0, ii = behaviors.length; i < ii; ++i) {
1414
- behaviors[i].unbind(oldSource);
1415
- }
1416
- }
1417
- /**
1418
- * Binds a view's behaviors to its binding source.
1419
- * @param source - The binding source for the view's binding behaviors.
1420
- * @param context - The execution context to run the behaviors within.
1421
- */
1422
- bind(source, context) {
1423
- const behaviors = this.behaviors;
1424
- if (this.source === source) {
1425
- return;
1426
- }
1427
- else if (this.source !== null) {
1428
- const oldSource = this.source;
1429
- this.source = source;
1430
- this.context = context;
1431
- for (let i = 0, ii = behaviors.length; i < ii; ++i) {
1432
- const current = behaviors[i];
1433
- current.unbind(oldSource);
1434
- current.bind(source, context);
1435
- }
1436
- }
1437
- else {
1438
- this.source = source;
1439
- this.context = context;
1440
- for (let i = 0, ii = behaviors.length; i < ii; ++i) {
1441
- behaviors[i].bind(source, context);
1442
- }
1443
- }
1444
- }
1445
- /**
1446
- * Unbinds a view's behaviors from its binding source.
1447
- */
1448
- unbind() {
1449
- if (this.source === null) {
1450
- return;
1451
- }
1452
- const behaviors = this.behaviors;
1453
- const oldSource = this.source;
1454
- for (let i = 0, ii = behaviors.length; i < ii; ++i) {
1455
- behaviors[i].unbind(oldSource);
1456
- }
1457
- this.source = null;
1458
- }
1459
- /**
1460
- * Efficiently disposes of a contiguous range of synthetic view instances.
1461
- * @param views - A contiguous range of views to be disposed.
1462
- */
1463
- static disposeContiguousBatch(views) {
1464
- if (views.length === 0) {
1465
- return;
1466
- }
1467
- range.setStartBefore(views[0].firstChild);
1468
- range.setEndAfter(views[views.length - 1].lastChild);
1469
- range.deleteContents();
1470
- for (let i = 0, ii = views.length; i < ii; ++i) {
1471
- const view = views[i];
1472
- const behaviors = view.behaviors;
1473
- const oldSource = view.source;
1474
- for (let j = 0, jj = behaviors.length; j < jj; ++j) {
1475
- behaviors[j].unbind(oldSource);
1476
- }
1477
- }
1478
- }
1479
- }
1480
-
1481
- /**
1482
- * A template capable of creating HTMLView instances or rendering directly to DOM.
1483
- * @public
1484
- */
1485
- /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
1486
- class ViewTemplate {
1487
- /**
1488
- * Creates an instance of ViewTemplate.
1489
- * @param html - The html representing what this template will instantiate, including placeholders for directives.
1490
- * @param directives - The directives that will be connected to placeholders in the html.
1491
- */
1492
- constructor(html, directives) {
1493
- this.behaviorCount = 0;
1494
- this.hasHostBehaviors = false;
1495
- this.fragment = null;
1496
- this.targetOffset = 0;
1497
- this.viewBehaviorFactories = null;
1498
- this.hostBehaviorFactories = null;
1499
- this.html = html;
1500
- this.directives = directives;
1501
- }
1502
- /**
1503
- * Creates an HTMLView instance based on this template definition.
1504
- * @param hostBindingTarget - The element that host behaviors will be bound to.
1505
- */
1506
- create(hostBindingTarget) {
1507
- if (this.fragment === null) {
1508
- let template;
1509
- const html = this.html;
1510
- if (typeof html === "string") {
1511
- template = document.createElement("template");
1512
- template.innerHTML = DOM.createHTML(html);
1513
- const fec = template.content.firstElementChild;
1514
- if (fec !== null && fec.tagName === "TEMPLATE") {
1515
- template = fec;
1516
- }
1517
- }
1518
- else {
1519
- template = html;
1520
- }
1521
- const result = compileTemplate(template, this.directives);
1522
- this.fragment = result.fragment;
1523
- this.viewBehaviorFactories = result.viewBehaviorFactories;
1524
- this.hostBehaviorFactories = result.hostBehaviorFactories;
1525
- this.targetOffset = result.targetOffset;
1526
- this.behaviorCount =
1527
- this.viewBehaviorFactories.length + this.hostBehaviorFactories.length;
1528
- this.hasHostBehaviors = this.hostBehaviorFactories.length > 0;
1529
- }
1530
- const fragment = this.fragment.cloneNode(true);
1531
- const viewFactories = this.viewBehaviorFactories;
1532
- const behaviors = new Array(this.behaviorCount);
1533
- const walker = DOM.createTemplateWalker(fragment);
1534
- let behaviorIndex = 0;
1535
- let targetIndex = this.targetOffset;
1536
- let node = walker.nextNode();
1537
- for (let ii = viewFactories.length; behaviorIndex < ii; ++behaviorIndex) {
1538
- const factory = viewFactories[behaviorIndex];
1539
- const factoryIndex = factory.targetIndex;
1540
- while (node !== null) {
1541
- if (targetIndex === factoryIndex) {
1542
- behaviors[behaviorIndex] = factory.createBehavior(node);
1543
- break;
1544
- }
1545
- else {
1546
- node = walker.nextNode();
1547
- targetIndex++;
1548
- }
1549
- }
1550
- }
1551
- if (this.hasHostBehaviors) {
1552
- const hostFactories = this.hostBehaviorFactories;
1553
- for (let i = 0, ii = hostFactories.length; i < ii; ++i, ++behaviorIndex) {
1554
- behaviors[behaviorIndex] = hostFactories[i].createBehavior(hostBindingTarget);
1555
- }
1556
- }
1557
- return new HTMLView(fragment, behaviors);
1558
- }
1559
- /**
1560
- * Creates an HTMLView from this template, binds it to the source, and then appends it to the host.
1561
- * @param source - The data source to bind the template to.
1562
- * @param host - The Element where the template will be rendered.
1563
- * @param hostBindingTarget - An HTML element to target the host bindings at if different from the
1564
- * host that the template is being attached to.
1565
- */
1566
- render(source, host, hostBindingTarget) {
1567
- if (typeof host === "string") {
1568
- host = document.getElementById(host);
1569
- }
1570
- if (hostBindingTarget === void 0) {
1571
- hostBindingTarget = host;
1572
- }
1573
- const view = this.create(hostBindingTarget);
1574
- view.bind(source, defaultExecutionContext);
1575
- view.appendTo(host);
1576
- return view;
1577
- }
1578
- }
1579
- // Much thanks to LitHTML for working this out!
1580
- const lastAttributeNameRegex =
1581
- /* eslint-disable-next-line no-control-regex */
1582
- /([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;
1583
- /**
1584
- * Transforms a template literal string into a renderable ViewTemplate.
1585
- * @param strings - The string fragments that are interpolated with the values.
1586
- * @param values - The values that are interpolated with the string fragments.
1587
- * @remarks
1588
- * The html helper supports interpolation of strings, numbers, binding expressions,
1589
- * other template instances, and Directive instances.
1590
- * @public
1591
- */
1592
- function html(strings, ...values) {
1593
- const directives = [];
1594
- let html = "";
1595
- for (let i = 0, ii = strings.length - 1; i < ii; ++i) {
1596
- const currentString = strings[i];
1597
- let value = values[i];
1598
- html += currentString;
1599
- if (value instanceof ViewTemplate) {
1600
- const template = value;
1601
- value = () => template;
1602
- }
1603
- if (typeof value === "function") {
1604
- value = new HTMLBindingDirective(value);
1605
- }
1606
- if (value instanceof TargetedHTMLDirective) {
1607
- const match = lastAttributeNameRegex.exec(currentString);
1608
- if (match !== null) {
1609
- value.targetName = match[2];
1610
- }
1611
- }
1612
- if (value instanceof HTMLDirective) {
1613
- // Since not all values are directives, we can't use i
1614
- // as the index for the placeholder. Instead, we need to
1615
- // use directives.length to get the next index.
1616
- html += value.createPlaceholder(directives.length);
1617
- directives.push(value);
1618
- }
1619
- else {
1620
- html += value;
1621
- }
1622
- }
1623
- html += strings[strings.length - 1];
1624
- return new ViewTemplate(html, directives);
1625
- }
1626
-
1627
- /**
1628
- * Represents styles that can be applied to a custom element.
1629
- * @public
1630
- */
1631
- class ElementStyles {
1632
- constructor() {
1633
- this.targets = new WeakSet();
1634
- }
1635
- /** @internal */
1636
- addStylesTo(target) {
1637
- this.targets.add(target);
1638
- }
1639
- /** @internal */
1640
- removeStylesFrom(target) {
1641
- this.targets.delete(target);
1642
- }
1643
- /** @internal */
1644
- isAttachedTo(target) {
1645
- return this.targets.has(target);
1646
- }
1647
- /**
1648
- * Associates behaviors with this set of styles.
1649
- * @param behaviors - The behaviors to associate.
1650
- */
1651
- withBehaviors(...behaviors) {
1652
- this.behaviors =
1653
- this.behaviors === null ? behaviors : this.behaviors.concat(behaviors);
1654
- return this;
1655
- }
1656
- }
1657
- /**
1658
- * Create ElementStyles from ComposableStyles.
1659
- */
1660
- ElementStyles.create = (() => {
1661
- if (DOM.supportsAdoptedStyleSheets) {
1662
- const styleSheetCache = new Map();
1663
- return (styles) =>
1664
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
1665
- new AdoptedStyleSheetsStyles(styles, styleSheetCache);
1666
- }
1667
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
1668
- return (styles) => new StyleElementStyles(styles);
1669
- })();
1670
- function reduceStyles(styles) {
1671
- return styles
1672
- .map((x) => x instanceof ElementStyles ? reduceStyles(x.styles) : [x])
1673
- .reduce((prev, curr) => prev.concat(curr), []);
1674
- }
1675
- function reduceBehaviors(styles) {
1676
- return styles
1677
- .map((x) => (x instanceof ElementStyles ? x.behaviors : null))
1678
- .reduce((prev, curr) => {
1679
- if (curr === null) {
1680
- return prev;
1681
- }
1682
- if (prev === null) {
1683
- prev = [];
1684
- }
1685
- return prev.concat(curr);
1686
- }, null);
1687
- }
1688
- /**
1689
- * A Symbol that can be added to a CSSStyleSheet to cause it to be prepended (rather than appended) to adoptedStyleSheets.
1690
- * @public
1691
- */
1692
- const prependToAdoptedStyleSheetsSymbol = Symbol("prependToAdoptedStyleSheets");
1693
- function separateSheetsToPrepend(sheets) {
1694
- const prepend = [];
1695
- const append = [];
1696
- sheets.forEach(x => (x[prependToAdoptedStyleSheetsSymbol] ? prepend : append).push(x));
1697
- return { prepend, append };
1698
- }
1699
- let addAdoptedStyleSheets = (target, sheets) => {
1700
- const { prepend, append } = separateSheetsToPrepend(sheets);
1701
- target.adoptedStyleSheets = [...prepend, ...target.adoptedStyleSheets, ...append];
1702
- };
1703
- let removeAdoptedStyleSheets = (target, sheets) => {
1704
- target.adoptedStyleSheets = target.adoptedStyleSheets.filter((x) => sheets.indexOf(x) === -1);
1705
- };
1706
- if (DOM.supportsAdoptedStyleSheets) {
1707
- try {
1708
- // Test if browser implementation uses FrozenArray.
1709
- // If not, use push / splice to alter the stylesheets
1710
- // in place. This circumvents a bug in Safari 16.4 where
1711
- // periodically, assigning the array would previously
1712
- // cause sheets to be removed.
1713
- document.adoptedStyleSheets.push();
1714
- document.adoptedStyleSheets.splice();
1715
- addAdoptedStyleSheets = (target, sheets) => {
1716
- const { prepend, append } = separateSheetsToPrepend(sheets);
1717
- target.adoptedStyleSheets.splice(0, 0, ...prepend);
1718
- target.adoptedStyleSheets.push(...append);
1719
- };
1720
- removeAdoptedStyleSheets = (target, sheets) => {
1721
- for (const sheet of sheets) {
1722
- const index = target.adoptedStyleSheets.indexOf(sheet);
1723
- if (index !== -1) {
1724
- target.adoptedStyleSheets.splice(index, 1);
1725
- }
1726
- }
1727
- };
1728
- }
1729
- catch (e) {
1730
- // Do nothing if an error is thrown, the default
1731
- // case handles FrozenArray.
1732
- }
1733
- }
1734
- /**
1735
- * https://wicg.github.io/construct-stylesheets/
1736
- * https://developers.google.com/web/updates/2019/02/constructable-stylesheets
1737
- *
1738
- * @internal
1739
- */
1740
- class AdoptedStyleSheetsStyles extends ElementStyles {
1741
- constructor(styles, styleSheetCache) {
1742
- super();
1743
- this.styles = styles;
1744
- this.styleSheetCache = styleSheetCache;
1745
- this._styleSheets = void 0;
1746
- this.behaviors = reduceBehaviors(styles);
1747
- }
1748
- get styleSheets() {
1749
- if (this._styleSheets === void 0) {
1750
- const styles = this.styles;
1751
- const styleSheetCache = this.styleSheetCache;
1752
- this._styleSheets = reduceStyles(styles).map((x) => {
1753
- if (x instanceof CSSStyleSheet) {
1754
- return x;
1755
- }
1756
- let sheet = styleSheetCache.get(x);
1757
- if (sheet === void 0) {
1758
- sheet = new CSSStyleSheet();
1759
- sheet.replaceSync(x);
1760
- styleSheetCache.set(x, sheet);
1761
- }
1762
- return sheet;
1763
- });
1764
- }
1765
- return this._styleSheets;
1766
- }
1767
- addStylesTo(target) {
1768
- addAdoptedStyleSheets(target, this.styleSheets);
1769
- super.addStylesTo(target);
1770
- }
1771
- removeStylesFrom(target) {
1772
- removeAdoptedStyleSheets(target, this.styleSheets);
1773
- super.removeStylesFrom(target);
1774
- }
1775
- }
1776
- let styleClassId = 0;
1777
- function getNextStyleClass() {
1778
- return `fast-style-class-${++styleClassId}`;
1779
- }
1780
- /**
1781
- * @internal
1782
- */
1783
- class StyleElementStyles extends ElementStyles {
1784
- constructor(styles) {
1785
- super();
1786
- this.styles = styles;
1787
- this.behaviors = null;
1788
- this.behaviors = reduceBehaviors(styles);
1789
- this.styleSheets = reduceStyles(styles);
1790
- this.styleClass = getNextStyleClass();
1791
- }
1792
- addStylesTo(target) {
1793
- const styleSheets = this.styleSheets;
1794
- const styleClass = this.styleClass;
1795
- target = this.normalizeTarget(target);
1796
- for (let i = 0; i < styleSheets.length; i++) {
1797
- const element = document.createElement("style");
1798
- element.innerHTML = styleSheets[i];
1799
- element.className = styleClass;
1800
- target.append(element);
1801
- }
1802
- super.addStylesTo(target);
1803
- }
1804
- removeStylesFrom(target) {
1805
- target = this.normalizeTarget(target);
1806
- const styles = target.querySelectorAll(`.${this.styleClass}`);
1807
- for (let i = 0, ii = styles.length; i < ii; ++i) {
1808
- target.removeChild(styles[i]);
1809
- }
1810
- super.removeStylesFrom(target);
1811
- }
1812
- isAttachedTo(target) {
1813
- return super.isAttachedTo(this.normalizeTarget(target));
1814
- }
1815
- normalizeTarget(target) {
1816
- return target === document ? document.body : target;
1817
- }
1818
- }
1819
-
1820
- /**
1821
- * Metadata used to configure a custom attribute's behavior.
1822
- * @public
1823
- */
1824
- const AttributeConfiguration = Object.freeze({
1825
- /**
1826
- * Locates all attribute configurations associated with a type.
1827
- */
1828
- locate: createMetadataLocator(),
1829
- });
1830
- /**
1831
- * A {@link ValueConverter} that converts to and from `boolean` values.
1832
- * @remarks
1833
- * Used automatically when the `boolean` {@link AttributeMode} is selected.
1834
- * @public
1835
- */
1836
- const booleanConverter = {
1837
- toView(value) {
1838
- return value ? "true" : "false";
1839
- },
1840
- fromView(value) {
1841
- if (value === null ||
1842
- value === void 0 ||
1843
- value === "false" ||
1844
- value === false ||
1845
- value === 0) {
1846
- return false;
1847
- }
1848
- return true;
1849
- },
1850
- };
1851
- /**
1852
- * A {@link ValueConverter} that converts to and from `number` values.
1853
- * @remarks
1854
- * This converter allows for nullable numbers, returning `null` if the
1855
- * input was `null`, `undefined`, or `NaN`.
1856
- * @public
1857
- */
1858
- const nullableNumberConverter = {
1859
- toView(value) {
1860
- if (value === null || value === undefined) {
1861
- return null;
1862
- }
1863
- const number = value * 1;
1864
- return isNaN(number) ? null : number.toString();
1865
- },
1866
- fromView(value) {
1867
- if (value === null || value === undefined) {
1868
- return null;
1869
- }
1870
- const number = value * 1;
1871
- return isNaN(number) ? null : number;
1872
- },
1873
- };
1874
- /**
1875
- * An implementation of {@link Accessor} that supports reactivity,
1876
- * change callbacks, attribute reflection, and type conversion for
1877
- * custom elements.
1878
- * @public
1879
- */
1880
- class AttributeDefinition {
1881
- /**
1882
- * Creates an instance of AttributeDefinition.
1883
- * @param Owner - The class constructor that owns this attribute.
1884
- * @param name - The name of the property associated with the attribute.
1885
- * @param attribute - The name of the attribute in HTML.
1886
- * @param mode - The {@link AttributeMode} that describes the behavior of this attribute.
1887
- * @param converter - A {@link ValueConverter} that integrates with the property getter/setter
1888
- * to convert values to and from a DOM string.
1889
- */
1890
- constructor(Owner, name, attribute = name.toLowerCase(), mode = "reflect", converter) {
1891
- this.guards = new Set();
1892
- this.Owner = Owner;
1893
- this.name = name;
1894
- this.attribute = attribute;
1895
- this.mode = mode;
1896
- this.converter = converter;
1897
- this.fieldName = `_${name}`;
1898
- this.callbackName = `${name}Changed`;
1899
- this.hasCallback = this.callbackName in Owner.prototype;
1900
- if (mode === "boolean" && converter === void 0) {
1901
- this.converter = booleanConverter;
1902
- }
1903
- }
1904
- /**
1905
- * Sets the value of the attribute/property on the source element.
1906
- * @param source - The source element to access.
1907
- * @param value - The value to set the attribute/property to.
1908
- */
1909
- setValue(source, newValue) {
1910
- const oldValue = source[this.fieldName];
1911
- const converter = this.converter;
1912
- if (converter !== void 0) {
1913
- newValue = converter.fromView(newValue);
1914
- }
1915
- if (oldValue !== newValue) {
1916
- source[this.fieldName] = newValue;
1917
- this.tryReflectToAttribute(source);
1918
- if (this.hasCallback) {
1919
- source[this.callbackName](oldValue, newValue);
1920
- }
1921
- source.$fastController.notify(this.name);
1922
- }
1923
- }
1924
- /**
1925
- * Gets the value of the attribute/property on the source element.
1926
- * @param source - The source element to access.
1927
- */
1928
- getValue(source) {
1929
- Observable.track(source, this.name);
1930
- return source[this.fieldName];
1931
- }
1932
- /** @internal */
1933
- onAttributeChangedCallback(element, value) {
1934
- if (this.guards.has(element)) {
1935
- return;
1936
- }
1937
- this.guards.add(element);
1938
- this.setValue(element, value);
1939
- this.guards.delete(element);
1940
- }
1941
- tryReflectToAttribute(element) {
1942
- const mode = this.mode;
1943
- const guards = this.guards;
1944
- if (guards.has(element) || mode === "fromView") {
1945
- return;
1946
- }
1947
- DOM.queueUpdate(() => {
1948
- guards.add(element);
1949
- const latestValue = element[this.fieldName];
1950
- switch (mode) {
1951
- case "reflect":
1952
- const converter = this.converter;
1953
- DOM.setAttribute(element, this.attribute, converter !== void 0 ? converter.toView(latestValue) : latestValue);
1954
- break;
1955
- case "boolean":
1956
- DOM.setBooleanAttribute(element, this.attribute, latestValue);
1957
- break;
1958
- }
1959
- guards.delete(element);
1960
- });
1961
- }
1962
- /**
1963
- * Collects all attribute definitions associated with the owner.
1964
- * @param Owner - The class constructor to collect attribute for.
1965
- * @param attributeLists - Any existing attributes to collect and merge with those associated with the owner.
1966
- * @internal
1967
- */
1968
- static collect(Owner, ...attributeLists) {
1969
- const attributes = [];
1970
- attributeLists.push(AttributeConfiguration.locate(Owner));
1971
- for (let i = 0, ii = attributeLists.length; i < ii; ++i) {
1972
- const list = attributeLists[i];
1973
- if (list === void 0) {
1974
- continue;
1975
- }
1976
- for (let j = 0, jj = list.length; j < jj; ++j) {
1977
- const config = list[j];
1978
- if (typeof config === "string") {
1979
- attributes.push(new AttributeDefinition(Owner, config));
1980
- }
1981
- else {
1982
- attributes.push(new AttributeDefinition(Owner, config.property, config.attribute, config.mode, config.converter));
1983
- }
1984
- }
1985
- }
1986
- return attributes;
1987
- }
1988
- }
1989
- function attr(configOrTarget, prop) {
1990
- let config;
1991
- function decorator($target, $prop) {
1992
- if (arguments.length > 1) {
1993
- // Non invocation:
1994
- // - @attr
1995
- // Invocation with or w/o opts:
1996
- // - @attr()
1997
- // - @attr({...opts})
1998
- config.property = $prop;
1999
- }
2000
- AttributeConfiguration.locate($target.constructor).push(config);
2001
- }
2002
- if (arguments.length > 1) {
2003
- // Non invocation:
2004
- // - @attr
2005
- config = {};
2006
- decorator(configOrTarget, prop);
2007
- return;
2008
- }
2009
- // Invocation with or w/o opts:
2010
- // - @attr()
2011
- // - @attr({...opts})
2012
- config = configOrTarget === void 0 ? {} : configOrTarget;
2013
- return decorator;
2014
- }
2015
-
2016
- const defaultShadowOptions = { mode: "open" };
2017
- const defaultElementOptions = {};
2018
- const fastRegistry = FAST.getById(4 /* elementRegistry */, () => {
2019
- const typeToDefinition = new Map();
2020
- return Object.freeze({
2021
- register(definition) {
2022
- if (typeToDefinition.has(definition.type)) {
2023
- return false;
2024
- }
2025
- typeToDefinition.set(definition.type, definition);
2026
- return true;
2027
- },
2028
- getByType(key) {
2029
- return typeToDefinition.get(key);
2030
- },
2031
- });
2032
- });
2033
- /**
2034
- * Defines metadata for a FASTElement.
2035
- * @public
2036
- */
2037
- class FASTElementDefinition {
2038
- /**
2039
- * Creates an instance of FASTElementDefinition.
2040
- * @param type - The type this definition is being created for.
2041
- * @param nameOrConfig - The name of the element to define or a config object
2042
- * that describes the element to define.
2043
- */
2044
- constructor(type, nameOrConfig = type.definition) {
2045
- if (typeof nameOrConfig === "string") {
2046
- nameOrConfig = { name: nameOrConfig };
2047
- }
2048
- this.type = type;
2049
- this.name = nameOrConfig.name;
2050
- this.template = nameOrConfig.template;
2051
- const attributes = AttributeDefinition.collect(type, nameOrConfig.attributes);
2052
- const observedAttributes = new Array(attributes.length);
2053
- const propertyLookup = {};
2054
- const attributeLookup = {};
2055
- for (let i = 0, ii = attributes.length; i < ii; ++i) {
2056
- const current = attributes[i];
2057
- observedAttributes[i] = current.attribute;
2058
- propertyLookup[current.name] = current;
2059
- attributeLookup[current.attribute] = current;
2060
- }
2061
- this.attributes = attributes;
2062
- this.observedAttributes = observedAttributes;
2063
- this.propertyLookup = propertyLookup;
2064
- this.attributeLookup = attributeLookup;
2065
- this.shadowOptions =
2066
- nameOrConfig.shadowOptions === void 0
2067
- ? defaultShadowOptions
2068
- : nameOrConfig.shadowOptions === null
2069
- ? void 0
2070
- : Object.assign(Object.assign({}, defaultShadowOptions), nameOrConfig.shadowOptions);
2071
- this.elementOptions =
2072
- nameOrConfig.elementOptions === void 0
2073
- ? defaultElementOptions
2074
- : Object.assign(Object.assign({}, defaultElementOptions), nameOrConfig.elementOptions);
2075
- this.styles =
2076
- nameOrConfig.styles === void 0
2077
- ? void 0
2078
- : Array.isArray(nameOrConfig.styles)
2079
- ? ElementStyles.create(nameOrConfig.styles)
2080
- : nameOrConfig.styles instanceof ElementStyles
2081
- ? nameOrConfig.styles
2082
- : ElementStyles.create([nameOrConfig.styles]);
2083
- }
2084
- /**
2085
- * Indicates if this element has been defined in at least one registry.
2086
- */
2087
- get isDefined() {
2088
- return !!fastRegistry.getByType(this.type);
2089
- }
2090
- /**
2091
- * Defines a custom element based on this definition.
2092
- * @param registry - The element registry to define the element in.
2093
- */
2094
- define(registry = customElements) {
2095
- const type = this.type;
2096
- if (fastRegistry.register(this)) {
2097
- const attributes = this.attributes;
2098
- const proto = type.prototype;
2099
- for (let i = 0, ii = attributes.length; i < ii; ++i) {
2100
- Observable.defineProperty(proto, attributes[i]);
2101
- }
2102
- Reflect.defineProperty(type, "observedAttributes", {
2103
- value: this.observedAttributes,
2104
- enumerable: true,
2105
- });
2106
- }
2107
- if (!registry.get(this.name)) {
2108
- registry.define(this.name, type, this.elementOptions);
2109
- }
2110
- return this;
2111
- }
2112
- }
2113
- /**
2114
- * Gets the element definition associated with the specified type.
2115
- * @param type - The custom element type to retrieve the definition for.
2116
- */
2117
- FASTElementDefinition.forType = fastRegistry.getByType;
2118
-
2119
- const shadowRoots = new WeakMap();
2120
- const defaultEventOptions = {
2121
- bubbles: true,
2122
- composed: true,
2123
- cancelable: true,
2124
- };
2125
- function getShadowRoot(element) {
2126
- return element.shadowRoot || shadowRoots.get(element) || null;
2127
- }
2128
- /**
2129
- * Controls the lifecycle and rendering of a `FASTElement`.
2130
- * @public
2131
- */
2132
- class Controller extends PropertyChangeNotifier {
2133
- /**
2134
- * Creates a Controller to control the specified element.
2135
- * @param element - The element to be controlled by this controller.
2136
- * @param definition - The element definition metadata that instructs this
2137
- * controller in how to handle rendering and other platform integrations.
2138
- * @internal
2139
- */
2140
- constructor(element, definition) {
2141
- super(element);
2142
- this.boundObservables = null;
2143
- this.behaviors = null;
2144
- this.needsInitialization = true;
2145
- this._template = null;
2146
- this._styles = null;
2147
- this._isConnected = false;
2148
- /**
2149
- * This allows Observable.getNotifier(...) to return the Controller
2150
- * when the notifier for the Controller itself is being requested. The
2151
- * result is that the Observable system does not need to create a separate
2152
- * instance of Notifier for observables on the Controller. The component and
2153
- * the controller will now share the same notifier, removing one-object construct
2154
- * per web component instance.
2155
- */
2156
- this.$fastController = this;
2157
- /**
2158
- * The view associated with the custom element.
2159
- * @remarks
2160
- * If `null` then the element is managing its own rendering.
2161
- */
2162
- this.view = null;
2163
- this.element = element;
2164
- this.definition = definition;
2165
- const shadowOptions = definition.shadowOptions;
2166
- if (shadowOptions !== void 0) {
2167
- const shadowRoot = element.attachShadow(shadowOptions);
2168
- if (shadowOptions.mode === "closed") {
2169
- shadowRoots.set(element, shadowRoot);
2170
- }
2171
- }
2172
- // Capture any observable values that were set by the binding engine before
2173
- // the browser upgraded the element. Then delete the property since it will
2174
- // shadow the getter/setter that is required to make the observable operate.
2175
- // Later, in the connect callback, we'll re-apply the values.
2176
- const accessors = Observable.getAccessors(element);
2177
- if (accessors.length > 0) {
2178
- const boundObservables = (this.boundObservables = Object.create(null));
2179
- for (let i = 0, ii = accessors.length; i < ii; ++i) {
2180
- const propertyName = accessors[i].name;
2181
- const value = element[propertyName];
2182
- if (value !== void 0) {
2183
- delete element[propertyName];
2184
- boundObservables[propertyName] = value;
2185
- }
2186
- }
2187
- }
2188
- }
2189
- /**
2190
- * Indicates whether or not the custom element has been
2191
- * connected to the document.
2192
- */
2193
- get isConnected() {
2194
- Observable.track(this, "isConnected");
2195
- return this._isConnected;
2196
- }
2197
- setIsConnected(value) {
2198
- this._isConnected = value;
2199
- Observable.notify(this, "isConnected");
2200
- }
2201
- /**
2202
- * Gets/sets the template used to render the component.
2203
- * @remarks
2204
- * This value can only be accurately read after connect but can be set at any time.
2205
- */
2206
- get template() {
2207
- return this._template;
2208
- }
2209
- set template(value) {
2210
- if (this._template === value) {
2211
- return;
2212
- }
2213
- this._template = value;
2214
- if (!this.needsInitialization) {
2215
- this.renderTemplate(value);
2216
- }
2217
- }
2218
- /**
2219
- * Gets/sets the primary styles used for the component.
2220
- * @remarks
2221
- * This value can only be accurately read after connect but can be set at any time.
2222
- */
2223
- get styles() {
2224
- return this._styles;
2225
- }
2226
- set styles(value) {
2227
- if (this._styles === value) {
2228
- return;
2229
- }
2230
- if (this._styles !== null) {
2231
- this.removeStyles(this._styles);
2232
- }
2233
- this._styles = value;
2234
- if (!this.needsInitialization && value !== null) {
2235
- this.addStyles(value);
2236
- }
2237
- }
2238
- /**
2239
- * Adds styles to this element. Providing an HTMLStyleElement will attach the element instance to the shadowRoot.
2240
- * @param styles - The styles to add.
2241
- */
2242
- addStyles(styles) {
2243
- const target = getShadowRoot(this.element) ||
2244
- this.element.getRootNode();
2245
- if (styles instanceof HTMLStyleElement) {
2246
- target.append(styles);
2247
- }
2248
- else if (!styles.isAttachedTo(target)) {
2249
- const sourceBehaviors = styles.behaviors;
2250
- styles.addStylesTo(target);
2251
- if (sourceBehaviors !== null) {
2252
- this.addBehaviors(sourceBehaviors);
2253
- }
2254
- }
2255
- }
2256
- /**
2257
- * Removes styles from this element. Providing an HTMLStyleElement will detach the element instance from the shadowRoot.
2258
- * @param styles - the styles to remove.
2259
- */
2260
- removeStyles(styles) {
2261
- const target = getShadowRoot(this.element) ||
2262
- this.element.getRootNode();
2263
- if (styles instanceof HTMLStyleElement) {
2264
- target.removeChild(styles);
2265
- }
2266
- else if (styles.isAttachedTo(target)) {
2267
- const sourceBehaviors = styles.behaviors;
2268
- styles.removeStylesFrom(target);
2269
- if (sourceBehaviors !== null) {
2270
- this.removeBehaviors(sourceBehaviors);
2271
- }
2272
- }
2273
- }
2274
- /**
2275
- * Adds behaviors to this element.
2276
- * @param behaviors - The behaviors to add.
2277
- */
2278
- addBehaviors(behaviors) {
2279
- const targetBehaviors = this.behaviors || (this.behaviors = new Map());
2280
- const length = behaviors.length;
2281
- const behaviorsToBind = [];
2282
- for (let i = 0; i < length; ++i) {
2283
- const behavior = behaviors[i];
2284
- if (targetBehaviors.has(behavior)) {
2285
- targetBehaviors.set(behavior, targetBehaviors.get(behavior) + 1);
2286
- }
2287
- else {
2288
- targetBehaviors.set(behavior, 1);
2289
- behaviorsToBind.push(behavior);
2290
- }
2291
- }
2292
- if (this._isConnected) {
2293
- const element = this.element;
2294
- for (let i = 0; i < behaviorsToBind.length; ++i) {
2295
- behaviorsToBind[i].bind(element, defaultExecutionContext);
2296
- }
2297
- }
2298
- }
2299
- /**
2300
- * Removes behaviors from this element.
2301
- * @param behaviors - The behaviors to remove.
2302
- * @param force - Forces unbinding of behaviors.
2303
- */
2304
- removeBehaviors(behaviors, force = false) {
2305
- const targetBehaviors = this.behaviors;
2306
- if (targetBehaviors === null) {
2307
- return;
2308
- }
2309
- const length = behaviors.length;
2310
- const behaviorsToUnbind = [];
2311
- for (let i = 0; i < length; ++i) {
2312
- const behavior = behaviors[i];
2313
- if (targetBehaviors.has(behavior)) {
2314
- const count = targetBehaviors.get(behavior) - 1;
2315
- count === 0 || force
2316
- ? targetBehaviors.delete(behavior) && behaviorsToUnbind.push(behavior)
2317
- : targetBehaviors.set(behavior, count);
2318
- }
2319
- }
2320
- if (this._isConnected) {
2321
- const element = this.element;
2322
- for (let i = 0; i < behaviorsToUnbind.length; ++i) {
2323
- behaviorsToUnbind[i].unbind(element);
2324
- }
2325
- }
2326
- }
2327
- /**
2328
- * Runs connected lifecycle behavior on the associated element.
2329
- */
2330
- onConnectedCallback() {
2331
- if (this._isConnected) {
2332
- return;
2333
- }
2334
- const element = this.element;
2335
- if (this.needsInitialization) {
2336
- this.finishInitialization();
2337
- }
2338
- else if (this.view !== null) {
2339
- this.view.bind(element, defaultExecutionContext);
2340
- }
2341
- const behaviors = this.behaviors;
2342
- if (behaviors !== null) {
2343
- for (const [behavior] of behaviors) {
2344
- behavior.bind(element, defaultExecutionContext);
2345
- }
2346
- }
2347
- this.setIsConnected(true);
2348
- }
2349
- /**
2350
- * Runs disconnected lifecycle behavior on the associated element.
2351
- */
2352
- onDisconnectedCallback() {
2353
- if (!this._isConnected) {
2354
- return;
2355
- }
2356
- this.setIsConnected(false);
2357
- const view = this.view;
2358
- if (view !== null) {
2359
- view.unbind();
2360
- }
2361
- const behaviors = this.behaviors;
2362
- if (behaviors !== null) {
2363
- const element = this.element;
2364
- for (const [behavior] of behaviors) {
2365
- behavior.unbind(element);
2366
- }
2367
- }
2368
- }
2369
- /**
2370
- * Runs the attribute changed callback for the associated element.
2371
- * @param name - The name of the attribute that changed.
2372
- * @param oldValue - The previous value of the attribute.
2373
- * @param newValue - The new value of the attribute.
2374
- */
2375
- onAttributeChangedCallback(name, oldValue, newValue) {
2376
- const attrDef = this.definition.attributeLookup[name];
2377
- if (attrDef !== void 0) {
2378
- attrDef.onAttributeChangedCallback(this.element, newValue);
2379
- }
2380
- }
2381
- /**
2382
- * Emits a custom HTML event.
2383
- * @param type - The type name of the event.
2384
- * @param detail - The event detail object to send with the event.
2385
- * @param options - The event options. By default bubbles and composed.
2386
- * @remarks
2387
- * Only emits events if connected.
2388
- */
2389
- emit(type, detail, options) {
2390
- if (this._isConnected) {
2391
- return this.element.dispatchEvent(new CustomEvent(type, Object.assign(Object.assign({ detail }, defaultEventOptions), options)));
2392
- }
2393
- return false;
2394
- }
2395
- finishInitialization() {
2396
- const element = this.element;
2397
- const boundObservables = this.boundObservables;
2398
- // If we have any observables that were bound, re-apply their values.
2399
- if (boundObservables !== null) {
2400
- const propertyNames = Object.keys(boundObservables);
2401
- for (let i = 0, ii = propertyNames.length; i < ii; ++i) {
2402
- const propertyName = propertyNames[i];
2403
- element[propertyName] = boundObservables[propertyName];
2404
- }
2405
- this.boundObservables = null;
2406
- }
2407
- const definition = this.definition;
2408
- // 1. Template overrides take top precedence.
2409
- if (this._template === null) {
2410
- if (this.element.resolveTemplate) {
2411
- // 2. Allow for element instance overrides next.
2412
- this._template = this.element.resolveTemplate();
2413
- }
2414
- else if (definition.template) {
2415
- // 3. Default to the static definition.
2416
- this._template = definition.template || null;
2417
- }
2418
- }
2419
- // If we have a template after the above process, render it.
2420
- // If there's no template, then the element author has opted into
2421
- // custom rendering and they will managed the shadow root's content themselves.
2422
- if (this._template !== null) {
2423
- this.renderTemplate(this._template);
2424
- }
2425
- // 1. Styles overrides take top precedence.
2426
- if (this._styles === null) {
2427
- if (this.element.resolveStyles) {
2428
- // 2. Allow for element instance overrides next.
2429
- this._styles = this.element.resolveStyles();
2430
- }
2431
- else if (definition.styles) {
2432
- // 3. Default to the static definition.
2433
- this._styles = definition.styles || null;
2434
- }
2435
- }
2436
- // If we have styles after the above process, add them.
2437
- if (this._styles !== null) {
2438
- this.addStyles(this._styles);
2439
- }
2440
- this.needsInitialization = false;
2441
- }
2442
- renderTemplate(template) {
2443
- const element = this.element;
2444
- // When getting the host to render to, we start by looking
2445
- // up the shadow root. If there isn't one, then that means
2446
- // we're doing a Light DOM render to the element's direct children.
2447
- const host = getShadowRoot(element) || element;
2448
- if (this.view !== null) {
2449
- // If there's already a view, we need to unbind and remove through dispose.
2450
- this.view.dispose();
2451
- this.view = null;
2452
- }
2453
- else if (!this.needsInitialization) {
2454
- // If there was previous custom rendering, we need to clear out the host.
2455
- DOM.removeChildNodes(host);
2456
- }
2457
- if (template) {
2458
- // If a new template was provided, render it.
2459
- this.view = template.render(element, host, element);
2460
- }
2461
- }
2462
- /**
2463
- * Locates or creates a controller for the specified element.
2464
- * @param element - The element to return the controller for.
2465
- * @remarks
2466
- * The specified element must have a {@link FASTElementDefinition}
2467
- * registered either through the use of the {@link customElement}
2468
- * decorator or a call to `FASTElement.define`.
2469
- */
2470
- static forCustomElement(element) {
2471
- const controller = element.$fastController;
2472
- if (controller !== void 0) {
2473
- return controller;
2474
- }
2475
- const definition = FASTElementDefinition.forType(element.constructor);
2476
- if (definition === void 0) {
2477
- throw new Error("Missing FASTElement definition.");
2478
- }
2479
- return (element.$fastController = new Controller(element, definition));
2480
- }
2481
- }
2482
-
2483
- /* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */
2484
- function createFASTElement(BaseType) {
2485
- return class extends BaseType {
2486
- constructor() {
2487
- /* eslint-disable-next-line */
2488
- super();
2489
- Controller.forCustomElement(this);
2490
- }
2491
- $emit(type, detail, options) {
2492
- return this.$fastController.emit(type, detail, options);
2493
- }
2494
- connectedCallback() {
2495
- this.$fastController.onConnectedCallback();
2496
- }
2497
- disconnectedCallback() {
2498
- this.$fastController.onDisconnectedCallback();
2499
- }
2500
- attributeChangedCallback(name, oldValue, newValue) {
2501
- this.$fastController.onAttributeChangedCallback(name, oldValue, newValue);
2502
- }
2503
- };
2504
- }
2505
- /**
2506
- * A minimal base class for FASTElements that also provides
2507
- * static helpers for working with FASTElements.
2508
- * @public
2509
- */
2510
- const FASTElement = Object.assign(createFASTElement(HTMLElement), {
2511
- /**
2512
- * Creates a new FASTElement base class inherited from the
2513
- * provided base type.
2514
- * @param BaseType - The base element type to inherit from.
2515
- */
2516
- from(BaseType) {
2517
- return createFASTElement(BaseType);
2518
- },
2519
- /**
2520
- * Defines a platform custom element based on the provided type and definition.
2521
- * @param type - The custom element type to define.
2522
- * @param nameOrDef - The name of the element to define or a definition object
2523
- * that describes the element to define.
2524
- */
2525
- define(type, nameOrDef) {
2526
- return new FASTElementDefinition(type, nameOrDef).define().type;
2527
- },
2528
- });
2529
-
2530
- function resolve(templateOrResolveFunction, ctx) {
2531
- if (templateOrResolveFunction instanceof Function) {
2532
- return templateOrResolveFunction(ctx);
2533
- } else {
2534
- return templateOrResolveFunction;
2535
- }
2536
- }
2537
- const registeredTags = /* @__PURE__ */ new Set();
2538
- const tagByType = /* @__PURE__ */ new Map();
2539
- const createRegisterFunction = (definition) => (prefix = "vwc") => {
2540
- const prefixed = (name) => `${prefix}-${name}`;
2541
- const registerComponent = (componentDefinition) => {
2542
- const tag = prefixed(componentDefinition.name);
2543
- let type = componentDefinition.type;
2544
- type.componentName = componentDefinition.name;
2545
- if (registeredTags.has(tag)) {
2546
- return;
2547
- } else if (tagByType.has(type) && tagByType.get(type) !== tag) {
2548
- type = class extends type {
2549
- };
2550
- }
2551
- registeredTags.add(tag);
2552
- tagByType.set(type, tag);
2553
- for (const dependency of componentDefinition.dependencies) {
2554
- registerComponent(dependency);
2555
- }
2556
- const tagByDependencyType = new Map([
2557
- [componentDefinition.type, tag],
2558
- ...componentDefinition.dependencies.map(
2559
- (dependency) => [dependency.type, prefixed(dependency.name)]
2560
- )
2561
- ]);
2562
- const elementDefinitionContext = {
2563
- tagFor(type2) {
2564
- if (!tagByDependencyType.has(type2)) {
2565
- throw new Error(
2566
- `Could not get tag for ${type2.name} as it is not a dependency of ${componentDefinition.name}.`
2567
- );
2568
- }
2569
- return tagByDependencyType.get(type2);
2570
- },
2571
- tagForNonDependency(name) {
2572
- return prefixed(name);
2573
- }
2574
- };
2575
- new FASTElementDefinition(type, {
2576
- ...componentDefinition.options,
2577
- template: resolve(
2578
- componentDefinition.template,
2579
- elementDefinitionContext
2580
- ),
2581
- name: `${prefix}-${componentDefinition.name}`
2582
- }).define();
2583
- };
2584
- registerComponent(definition);
2585
- };
2586
-
2587
- const defineVividComponent = (name, type, template, dependencies, options) => ({
2588
- name,
2589
- type,
2590
- template,
2591
- dependencies,
2592
- options
2593
- });
2594
-
2595
- const ariaChangeSubscribers = /* @__PURE__ */ new WeakMap();
2596
- const getSubscribers = (source) => {
2597
- let subscribers = ariaChangeSubscribers.get(source);
2598
- if (!subscribers) {
2599
- subscribers = [];
2600
- ariaChangeSubscribers.set(source, subscribers);
2601
- }
2602
- return subscribers;
2603
- };
2604
- const subscribeToAriaPropertyChanges = (source, listener) => {
2605
- getSubscribers(source).push(listener);
2606
- };
2607
- const unsubscribeFromAriaPropertyChanges = (source, listener) => {
2608
- getSubscribers(source).splice(getSubscribers(source).indexOf(listener), 1);
2609
- };
2610
- const publishAriaPropertyChange = (source, changedAriaProperty) => {
2611
- getSubscribers(source).forEach((s) => s(source, changedAriaProperty));
2612
- };
2613
-
2614
- const ariaMixinProperties = [
2615
- "role",
2616
- "ariaAtomic",
2617
- "ariaAutoComplete",
2618
- "ariaBusy",
2619
- "ariaChecked",
2620
- "ariaColCount",
2621
- "ariaColIndex",
2622
- "ariaColIndexText",
2623
- "ariaColSpan",
2624
- "ariaCurrent",
2625
- "ariaDescription",
2626
- "ariaDisabled",
2627
- "ariaExpanded",
2628
- "ariaHasPopup",
2629
- "ariaHidden",
2630
- "ariaInvalid",
2631
- "ariaKeyShortcuts",
2632
- "ariaLabel",
2633
- "ariaLevel",
2634
- "ariaLive",
2635
- "ariaModal",
2636
- "ariaMultiLine",
2637
- "ariaMultiSelectable",
2638
- "ariaOrientation",
2639
- "ariaPlaceholder",
2640
- "ariaPosInSet",
2641
- "ariaPressed",
2642
- "ariaReadOnly",
2643
- "ariaRequired",
2644
- "ariaRoleDescription",
2645
- "ariaRowCount",
2646
- "ariaRowIndex",
2647
- "ariaRowIndexText",
2648
- "ariaRowSpan",
2649
- "ariaSelected",
2650
- "ariaSetSize",
2651
- "ariaSort",
2652
- "ariaValueMax",
2653
- "ariaValueMin",
2654
- "ariaValueNow",
2655
- "ariaValueText",
2656
- "ariaRelevant"
2657
- // Non-standard
2658
- ];
2659
- const ariaAttributeName = (ariaPropertyName) => ariaPropertyName.replace("aria", "aria-").toLowerCase();
2660
- const AriaMixin = (Base) => {
2661
- class AriaMixinElement extends Base {
2662
- constructor(...args) {
2663
- super(args);
2664
- this.specialHandling = false;
2665
- this._vividAriaBehaviour = "default";
2666
- for (const ariaProperty of ariaMixinProperties) {
2667
- this[ariaProperty] = null;
2668
- }
2669
- }
2670
- }
2671
- for (const ariaProperty of ariaMixinProperties) {
2672
- attr({
2673
- attribute: ariaAttributeName(ariaProperty),
2674
- mode: "reflect"
2675
- })(AriaMixinElement.prototype, ariaProperty);
2676
- AriaMixinElement.prototype[`${ariaProperty}Changed`] = function() {
2677
- if (this._vividAriaBehaviour !== "default") {
2678
- publishAriaPropertyChange(this, ariaProperty);
2679
- }
2680
- };
2681
- }
2682
- return AriaMixinElement;
2683
- };
2684
-
2685
- const locateReplacedPropMetadata = createMetadataLocator();
2686
- const replaces = (config) => ($target, $prop) => {
2687
- locateReplacedPropMetadata($target.constructor).push({
2688
- newPropertyName: $prop,
2689
- ...config
2690
- });
2691
- };
2692
- const ReplacedPropHandling = (Base) => {
2693
- class ReplacedPropHandlingElement extends Base {
2694
- #handleReplacedProp(replacedProp) {
2695
- let newDirty = false;
2696
- let deprecatedDirty = false;
2697
- const changeCouldBeFromDeprecated = (source) => deprecatedDirty && replacedProp.fromDeprecated(
2698
- source[replacedProp.deprecatedPropertyName]
2699
- ) === source[replacedProp.newPropertyName];
2700
- const changeCouldBeFromNew = (source) => newDirty && replacedProp.toDeprecated && replacedProp.toDeprecated(source[replacedProp.newPropertyName]) === source[replacedProp.deprecatedPropertyName];
2701
- const subscriber = {
2702
- handleChange(source, propertyName) {
2703
- if (propertyName === replacedProp.newPropertyName) {
2704
- newDirty = true;
2705
- if (!replacedProp.toDeprecated || changeCouldBeFromDeprecated(source)) {
2706
- return;
2707
- }
2708
- source[replacedProp.deprecatedPropertyName] = replacedProp.toDeprecated(source[replacedProp.newPropertyName]);
2709
- }
2710
- if (propertyName === replacedProp.deprecatedPropertyName) {
2711
- deprecatedDirty = true;
2712
- if (changeCouldBeFromNew(source)) {
2713
- return;
2714
- }
2715
- source[replacedProp.newPropertyName] = replacedProp.fromDeprecated(
2716
- source[replacedProp.deprecatedPropertyName]
2717
- );
2718
- }
2719
- }
2720
- };
2721
- const notifier = Observable.getNotifier(this);
2722
- notifier.subscribe(subscriber, replacedProp.newPropertyName);
2723
- notifier.subscribe(subscriber, replacedProp.deprecatedPropertyName);
2724
- }
2725
- constructor(...args) {
2726
- super(...args);
2727
- for (const replacedProp of locateReplacedPropMetadata(this.constructor)) {
2728
- this.#handleReplacedProp(replacedProp);
2729
- }
2730
- }
2731
- }
2732
- return ReplacedPropHandlingElement;
2733
- };
2734
-
2735
- class VividElement extends AriaMixin(ReplacedPropHandling(FASTElement)) {
2736
- static {
2737
- this.VIVID_VERSION = "4.31.0";
2738
- }
2739
- /**
2740
- * Add data-vvd-component attribute with component name globally,
2741
- * for referring to the elements in CSS, testing or debugging
2742
- */
2743
- connectedCallback() {
2744
- super.connectedCallback();
2745
- const name = this.constructor.componentName;
2746
- this.setAttribute("data-vvd-component", name);
2747
- }
2748
- }
2749
-
2750
- exports.AttachedBehaviorHTMLDirective = AttachedBehaviorHTMLDirective;
2751
- exports.DOM = DOM;
2752
- exports.ElementStyles = ElementStyles;
2753
- exports.HTMLDirective = HTMLDirective;
2754
- exports.HTMLView = HTMLView;
2755
- exports.Observable = Observable;
2756
- exports.SubscriberSet = SubscriberSet;
2757
- exports.VividElement = VividElement;
2758
- exports.ariaAttributeName = ariaAttributeName;
2759
- exports.ariaMixinProperties = ariaMixinProperties;
2760
- exports.attr = attr;
2761
- exports.createRegisterFunction = createRegisterFunction;
2762
- exports.defaultExecutionContext = defaultExecutionContext;
2763
- exports.defineVividComponent = defineVividComponent;
2764
- exports.emptyArray = emptyArray;
2765
- exports.html = html;
2766
- exports.nullableNumberConverter = nullableNumberConverter;
2767
- exports.observable = observable;
2768
- exports.replaces = replaces;
2769
- exports.subscribeToAriaPropertyChanges = subscribeToAriaPropertyChanges;
2770
- exports.unsubscribeFromAriaPropertyChanges = unsubscribeFromAriaPropertyChanges;
2771
- exports.volatile = volatile;