@ni/fast-foundation 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (416) hide show
  1. package/README.md +58 -0
  2. package/dist/dts/accordion/accordion.d.ts +65 -0
  3. package/dist/dts/accordion/accordion.template.d.ts +8 -0
  4. package/dist/dts/accordion/index.d.ts +2 -0
  5. package/dist/dts/accordion-item/accordion-item.d.ts +76 -0
  6. package/dist/dts/accordion-item/accordion-item.template.d.ts +8 -0
  7. package/dist/dts/accordion-item/index.d.ts +2 -0
  8. package/dist/dts/anchor/anchor.d.ts +128 -0
  9. package/dist/dts/anchor/anchor.template.d.ts +8 -0
  10. package/dist/dts/anchor/index.d.ts +2 -0
  11. package/dist/dts/anchored-region/anchored-region-config.d.ts +117 -0
  12. package/dist/dts/anchored-region/anchored-region.d.ts +389 -0
  13. package/dist/dts/anchored-region/anchored-region.template.d.ts +8 -0
  14. package/dist/dts/anchored-region/index.d.ts +3 -0
  15. package/dist/dts/avatar/avatar.d.ts +62 -0
  16. package/dist/dts/avatar/avatar.template.d.ts +8 -0
  17. package/dist/dts/avatar/index.d.ts +2 -0
  18. package/dist/dts/badge/badge.d.ts +36 -0
  19. package/dist/dts/badge/badge.template.d.ts +8 -0
  20. package/dist/dts/badge/index.d.ts +2 -0
  21. package/dist/dts/breadcrumb/breadcrumb.d.ts +27 -0
  22. package/dist/dts/breadcrumb/breadcrumb.template.d.ts +8 -0
  23. package/dist/dts/breadcrumb/index.d.ts +2 -0
  24. package/dist/dts/breadcrumb-item/breadcrumb-item.d.ts +36 -0
  25. package/dist/dts/breadcrumb-item/breadcrumb-item.template.d.ts +8 -0
  26. package/dist/dts/breadcrumb-item/index.d.ts +2 -0
  27. package/dist/dts/button/button.d.ts +167 -0
  28. package/dist/dts/button/button.form-associated.d.ts +16 -0
  29. package/dist/dts/button/button.template.d.ts +8 -0
  30. package/dist/dts/button/index.d.ts +2 -0
  31. package/dist/dts/calendar/calendar.d.ts +178 -0
  32. package/dist/dts/calendar/calendar.template.d.ts +58 -0
  33. package/dist/dts/calendar/date-formatter.d.ts +124 -0
  34. package/dist/dts/calendar/index.d.ts +3 -0
  35. package/dist/dts/card/card.d.ts +10 -0
  36. package/dist/dts/card/card.template.d.ts +8 -0
  37. package/dist/dts/card/index.d.ts +2 -0
  38. package/dist/dts/checkbox/checkbox.d.ts +58 -0
  39. package/dist/dts/checkbox/checkbox.form-associated.d.ts +16 -0
  40. package/dist/dts/checkbox/checkbox.template.d.ts +8 -0
  41. package/dist/dts/checkbox/index.d.ts +2 -0
  42. package/dist/dts/combobox/combobox.d.ts +341 -0
  43. package/dist/dts/combobox/combobox.form-associated.d.ts +16 -0
  44. package/dist/dts/combobox/combobox.options.d.ts +15 -0
  45. package/dist/dts/combobox/combobox.template.d.ts +8 -0
  46. package/dist/dts/combobox/index.d.ts +3 -0
  47. package/dist/dts/data-grid/data-grid-cell.d.ts +62 -0
  48. package/dist/dts/data-grid/data-grid-cell.template.d.ts +9 -0
  49. package/dist/dts/data-grid/data-grid-row.d.ts +119 -0
  50. package/dist/dts/data-grid/data-grid-row.template.d.ts +10 -0
  51. package/dist/dts/data-grid/data-grid.d.ts +218 -0
  52. package/dist/dts/data-grid/data-grid.options.d.ts +49 -0
  53. package/dist/dts/data-grid/data-grid.template.d.ts +10 -0
  54. package/dist/dts/data-grid/index.d.ts +6 -0
  55. package/dist/dts/design-system/component-presentation.d.ts +66 -0
  56. package/dist/dts/design-system/design-system.d.ts +104 -0
  57. package/dist/dts/design-system/index.d.ts +3 -0
  58. package/dist/dts/design-system/registration-context.d.ts +106 -0
  59. package/dist/dts/design-token/custom-property-manager.d.ts +35 -0
  60. package/dist/dts/design-token/design-token.d.ts +139 -0
  61. package/dist/dts/design-token/interfaces.d.ts +31 -0
  62. package/dist/dts/di/di.d.ts +858 -0
  63. package/dist/dts/di/index.d.ts +1 -0
  64. package/dist/dts/dialog/dialog.d.ts +153 -0
  65. package/dist/dts/dialog/dialog.template.d.ts +8 -0
  66. package/dist/dts/dialog/index.d.ts +2 -0
  67. package/dist/dts/directives/reflect-attributes.d.ts +18 -0
  68. package/dist/dts/disclosure/disclosure.d.ts +59 -0
  69. package/dist/dts/disclosure/disclosure.template.d.ts +8 -0
  70. package/dist/dts/disclosure/index.d.ts +2 -0
  71. package/dist/dts/divider/divider.d.ts +28 -0
  72. package/dist/dts/divider/divider.options.d.ts +19 -0
  73. package/dist/dts/divider/divider.template.d.ts +8 -0
  74. package/dist/dts/divider/index.d.ts +2 -0
  75. package/dist/dts/flipper/flipper.d.ts +57 -0
  76. package/dist/dts/flipper/flipper.options.d.ts +13 -0
  77. package/dist/dts/flipper/flipper.template.d.ts +8 -0
  78. package/dist/dts/flipper/index.d.ts +2 -0
  79. package/dist/dts/form-associated/form-associated.d.ts +177 -0
  80. package/dist/dts/form-associated/index.d.ts +1 -0
  81. package/dist/dts/foundation-element/foundation-element.d.ts +120 -0
  82. package/dist/dts/foundation-element/index.d.ts +1 -0
  83. package/dist/dts/horizontal-scroll/horizontal-scroll.d.ts +242 -0
  84. package/dist/dts/horizontal-scroll/horizontal-scroll.template.d.ts +7 -0
  85. package/dist/dts/horizontal-scroll/index.d.ts +2 -0
  86. package/dist/dts/index-rollup.d.ts +2 -0
  87. package/dist/dts/index.d.ts +53 -0
  88. package/dist/dts/interfaces.d.ts +4 -0
  89. package/dist/dts/listbox/index.d.ts +3 -0
  90. package/dist/dts/listbox/listbox.d.ts +314 -0
  91. package/dist/dts/listbox/listbox.element.d.ts +223 -0
  92. package/dist/dts/listbox/listbox.template.d.ts +8 -0
  93. package/dist/dts/listbox-option/index.d.ts +2 -0
  94. package/dist/dts/listbox-option/listbox-option.d.ts +176 -0
  95. package/dist/dts/listbox-option/listbox-option.template.d.ts +8 -0
  96. package/dist/dts/menu/index.d.ts +2 -0
  97. package/dist/dts/menu/menu.d.ts +78 -0
  98. package/dist/dts/menu/menu.template.d.ts +8 -0
  99. package/dist/dts/menu-item/index.d.ts +2 -0
  100. package/dist/dts/menu-item/menu-item.d.ts +160 -0
  101. package/dist/dts/menu-item/menu-item.options.d.ts +29 -0
  102. package/dist/dts/menu-item/menu-item.template.d.ts +10 -0
  103. package/dist/dts/number-field/index.d.ts +2 -0
  104. package/dist/dts/number-field/number-field.d.ts +227 -0
  105. package/dist/dts/number-field/number-field.form-associated.d.ts +16 -0
  106. package/dist/dts/number-field/number-field.template.d.ts +8 -0
  107. package/dist/dts/patterns/aria-global.d.ts +189 -0
  108. package/dist/dts/patterns/index.d.ts +2 -0
  109. package/dist/dts/patterns/start-end.d.ts +65 -0
  110. package/dist/dts/picker/index.d.ts +10 -0
  111. package/dist/dts/picker/picker-list-item.d.ts +38 -0
  112. package/dist/dts/picker/picker-list-item.template.d.ts +8 -0
  113. package/dist/dts/picker/picker-list.d.ts +8 -0
  114. package/dist/dts/picker/picker-list.template.d.ts +8 -0
  115. package/dist/dts/picker/picker-menu-option.d.ts +37 -0
  116. package/dist/dts/picker/picker-menu-option.template.d.ts +8 -0
  117. package/dist/dts/picker/picker-menu.d.ts +46 -0
  118. package/dist/dts/picker/picker-menu.template.d.ts +8 -0
  119. package/dist/dts/picker/picker.d.ts +390 -0
  120. package/dist/dts/picker/picker.form-associated.d.ts +16 -0
  121. package/dist/dts/picker/picker.template.d.ts +8 -0
  122. package/dist/dts/progress/base-progress.d.ts +71 -0
  123. package/dist/dts/progress/index.d.ts +2 -0
  124. package/dist/dts/progress/progress.template.d.ts +8 -0
  125. package/dist/dts/progress-ring/index.d.ts +1 -0
  126. package/dist/dts/progress-ring/progress-ring.template.d.ts +8 -0
  127. package/dist/dts/radio/index.d.ts +2 -0
  128. package/dist/dts/radio/radio.d.ts +70 -0
  129. package/dist/dts/radio/radio.form-associated.d.ts +16 -0
  130. package/dist/dts/radio/radio.template.d.ts +8 -0
  131. package/dist/dts/radio-group/index.d.ts +2 -0
  132. package/dist/dts/radio-group/radio-group.d.ts +101 -0
  133. package/dist/dts/radio-group/radio-group.template.d.ts +8 -0
  134. package/dist/dts/search/index.d.ts +2 -0
  135. package/dist/dts/search/search.d.ts +162 -0
  136. package/dist/dts/search/search.form-associated.d.ts +16 -0
  137. package/dist/dts/search/search.template.d.ts +8 -0
  138. package/dist/dts/select/index.d.ts +3 -0
  139. package/dist/dts/select/select.d.ts +289 -0
  140. package/dist/dts/select/select.form-associated.d.ts +16 -0
  141. package/dist/dts/select/select.options.d.ts +13 -0
  142. package/dist/dts/select/select.template.d.ts +8 -0
  143. package/dist/dts/skeleton/index.d.ts +2 -0
  144. package/dist/dts/skeleton/skeleton.d.ts +47 -0
  145. package/dist/dts/skeleton/skeleton.template.d.ts +8 -0
  146. package/dist/dts/slider/index.d.ts +2 -0
  147. package/dist/dts/slider/slider-utilities.d.ts +5 -0
  148. package/dist/dts/slider/slider.d.ts +230 -0
  149. package/dist/dts/slider/slider.form-associated.d.ts +16 -0
  150. package/dist/dts/slider/slider.template.d.ts +8 -0
  151. package/dist/dts/slider-label/index.d.ts +2 -0
  152. package/dist/dts/slider-label/slider-label.d.ts +81 -0
  153. package/dist/dts/slider-label/slider-label.template.d.ts +8 -0
  154. package/dist/dts/switch/index.d.ts +2 -0
  155. package/dist/dts/switch/switch.d.ts +60 -0
  156. package/dist/dts/switch/switch.form-associated.d.ts +16 -0
  157. package/dist/dts/switch/switch.template.d.ts +8 -0
  158. package/dist/dts/tab/index.d.ts +2 -0
  159. package/dist/dts/tab/tab.d.ts +17 -0
  160. package/dist/dts/tab/tab.template.d.ts +8 -0
  161. package/dist/dts/tab-panel/index.d.ts +2 -0
  162. package/dist/dts/tab-panel/tab-panel.d.ts +10 -0
  163. package/dist/dts/tab-panel/tab-panel.template.d.ts +8 -0
  164. package/dist/dts/tabs/index.d.ts +2 -0
  165. package/dist/dts/tabs/tabs.d.ts +140 -0
  166. package/dist/dts/tabs/tabs.template.d.ts +8 -0
  167. package/dist/dts/test-utilities/fixture.d.ts +89 -0
  168. package/dist/dts/test-utilities/timeout.d.ts +4 -0
  169. package/dist/dts/text-area/index.d.ts +2 -0
  170. package/dist/dts/text-area/text-area.d.ts +149 -0
  171. package/dist/dts/text-area/text-area.form-associated.d.ts +16 -0
  172. package/dist/dts/text-area/text-area.options.d.ts +27 -0
  173. package/dist/dts/text-area/text-area.template.d.ts +8 -0
  174. package/dist/dts/text-field/index.d.ts +2 -0
  175. package/dist/dts/text-field/text-field.d.ts +166 -0
  176. package/dist/dts/text-field/text-field.form-associated.d.ts +16 -0
  177. package/dist/dts/text-field/text-field.options.d.ts +31 -0
  178. package/dist/dts/text-field/text-field.template.d.ts +8 -0
  179. package/dist/dts/toolbar/index.d.ts +2 -0
  180. package/dist/dts/toolbar/toolbar.d.ts +167 -0
  181. package/dist/dts/toolbar/toolbar.template.d.ts +9 -0
  182. package/dist/dts/tooltip/index.d.ts +2 -0
  183. package/dist/dts/tooltip/tooltip.d.ts +239 -0
  184. package/dist/dts/tooltip/tooltip.options.d.ts +69 -0
  185. package/dist/dts/tooltip/tooltip.template.d.ts +8 -0
  186. package/dist/dts/tree-item/index.d.ts +2 -0
  187. package/dist/dts/tree-item/tree-item.d.ts +141 -0
  188. package/dist/dts/tree-item/tree-item.template.d.ts +8 -0
  189. package/dist/dts/tree-view/index.d.ts +2 -0
  190. package/dist/dts/tree-view/tree-view.d.ts +99 -0
  191. package/dist/dts/tree-view/tree-view.template.d.ts +8 -0
  192. package/dist/dts/utilities/apply-mixins.d.ts +6 -0
  193. package/dist/dts/utilities/composed-contains.d.ts +12 -0
  194. package/dist/dts/utilities/composed-parent.d.ts +10 -0
  195. package/dist/dts/utilities/direction.d.ts +7 -0
  196. package/dist/dts/utilities/index.d.ts +8 -0
  197. package/dist/dts/utilities/intersection-service.d.ts +30 -0
  198. package/dist/dts/utilities/match-media-stylesheet-behavior.d.ts +124 -0
  199. package/dist/dts/utilities/property-stylesheet-behavior.d.ts +38 -0
  200. package/dist/dts/utilities/resize-observer.d.ts +31 -0
  201. package/dist/dts/utilities/root-active-element.d.ts +1 -0
  202. package/dist/dts/utilities/style/disabled.d.ts +5 -0
  203. package/dist/dts/utilities/style/display.d.ts +17 -0
  204. package/dist/dts/utilities/style/focus.d.ts +8 -0
  205. package/dist/dts/utilities/style/index.d.ts +3 -0
  206. package/dist/dts/utilities/whitespace-filter.d.ts +9 -0
  207. package/dist/esm/accordion/accordion.js +185 -0
  208. package/dist/esm/accordion/accordion.template.js +11 -0
  209. package/dist/esm/accordion/index.js +2 -0
  210. package/dist/esm/accordion-item/accordion-item.js +72 -0
  211. package/dist/esm/accordion-item/accordion-item.template.js +49 -0
  212. package/dist/esm/accordion-item/index.js +2 -0
  213. package/dist/esm/anchor/anchor.js +85 -0
  214. package/dist/esm/anchor/anchor.template.js +47 -0
  215. package/dist/esm/anchor/index.js +2 -0
  216. package/dist/esm/anchored-region/anchored-region-config.js +59 -0
  217. package/dist/esm/anchored-region/anchored-region.js +964 -0
  218. package/dist/esm/anchored-region/anchored-region.template.js +12 -0
  219. package/dist/esm/anchored-region/index.js +3 -0
  220. package/dist/esm/avatar/avatar.js +39 -0
  221. package/dist/esm/avatar/avatar.template.js +23 -0
  222. package/dist/esm/avatar/index.js +2 -0
  223. package/dist/esm/badge/badge.js +40 -0
  224. package/dist/esm/badge/badge.template.js +12 -0
  225. package/dist/esm/badge/index.js +2 -0
  226. package/dist/esm/breadcrumb/breadcrumb.js +70 -0
  227. package/dist/esm/breadcrumb/breadcrumb.template.js +14 -0
  228. package/dist/esm/breadcrumb/index.js +2 -0
  229. package/dist/esm/breadcrumb-item/breadcrumb-item.js +23 -0
  230. package/dist/esm/breadcrumb-item/breadcrumb-item.template.js +24 -0
  231. package/dist/esm/breadcrumb-item/index.js +2 -0
  232. package/dist/esm/button/button.form-associated.js +15 -0
  233. package/dist/esm/button/button.js +183 -0
  234. package/dist/esm/button/button.template.js +51 -0
  235. package/dist/esm/button/index.js +2 -0
  236. package/dist/esm/calendar/calendar.js +280 -0
  237. package/dist/esm/calendar/calendar.template.js +191 -0
  238. package/dist/esm/calendar/date-formatter.js +144 -0
  239. package/dist/esm/calendar/index.js +3 -0
  240. package/dist/esm/card/card.js +10 -0
  241. package/dist/esm/card/card.template.js +8 -0
  242. package/dist/esm/card/index.js +2 -0
  243. package/dist/esm/checkbox/checkbox.form-associated.js +15 -0
  244. package/dist/esm/checkbox/checkbox.js +75 -0
  245. package/dist/esm/checkbox/checkbox.template.js +35 -0
  246. package/dist/esm/checkbox/index.js +2 -0
  247. package/dist/esm/combobox/combobox.form-associated.js +15 -0
  248. package/dist/esm/combobox/combobox.js +587 -0
  249. package/dist/esm/combobox/combobox.options.js +10 -0
  250. package/dist/esm/combobox/combobox.template.js +66 -0
  251. package/dist/esm/combobox/index.js +3 -0
  252. package/dist/esm/data-grid/data-grid-cell.js +229 -0
  253. package/dist/esm/data-grid/data-grid-cell.template.js +23 -0
  254. package/dist/esm/data-grid/data-grid-row.js +203 -0
  255. package/dist/esm/data-grid/data-grid-row.template.js +47 -0
  256. package/dist/esm/data-grid/data-grid.js +440 -0
  257. package/dist/esm/data-grid/data-grid.options.js +31 -0
  258. package/dist/esm/data-grid/data-grid.template.js +36 -0
  259. package/dist/esm/data-grid/index.js +6 -0
  260. package/dist/esm/design-system/component-presentation.js +86 -0
  261. package/dist/esm/design-system/design-system.js +207 -0
  262. package/dist/esm/design-system/index.js +3 -0
  263. package/dist/esm/design-system/registration-context.js +1 -0
  264. package/dist/esm/design-token/custom-property-manager.js +216 -0
  265. package/dist/esm/design-token/design-token.js +657 -0
  266. package/dist/esm/design-token/interfaces.js +1 -0
  267. package/dist/esm/di/di.js +1341 -0
  268. package/dist/esm/di/index.js +1 -0
  269. package/dist/esm/dialog/dialog.js +280 -0
  270. package/dist/esm/dialog/dialog.template.js +30 -0
  271. package/dist/esm/dialog/index.js +2 -0
  272. package/dist/esm/directives/reflect-attributes.js +88 -0
  273. package/dist/esm/disclosure/disclosure.js +72 -0
  274. package/dist/esm/disclosure/disclosure.template.js +20 -0
  275. package/dist/esm/disclosure/index.js +2 -0
  276. package/dist/esm/divider/divider.js +39 -0
  277. package/dist/esm/divider/divider.options.js +14 -0
  278. package/dist/esm/divider/divider.template.js +8 -0
  279. package/dist/esm/divider/index.js +2 -0
  280. package/dist/esm/flipper/flipper.js +65 -0
  281. package/dist/esm/flipper/flipper.options.js +8 -0
  282. package/dist/esm/flipper/flipper.template.js +30 -0
  283. package/dist/esm/flipper/index.js +2 -0
  284. package/dist/esm/form-associated/form-associated.js +464 -0
  285. package/dist/esm/form-associated/index.js +1 -0
  286. package/dist/esm/foundation-element/foundation-element.js +132 -0
  287. package/dist/esm/foundation-element/index.js +1 -0
  288. package/dist/esm/horizontal-scroll/horizontal-scroll.js +380 -0
  289. package/dist/esm/horizontal-scroll/horizontal-scroll.template.js +62 -0
  290. package/dist/esm/horizontal-scroll/index.js +2 -0
  291. package/dist/esm/index-rollup.js +2 -0
  292. package/dist/esm/index.js +54 -0
  293. package/dist/esm/interfaces.js +1 -0
  294. package/dist/esm/listbox/index.js +3 -0
  295. package/dist/esm/listbox/listbox.element.js +448 -0
  296. package/dist/esm/listbox/listbox.js +528 -0
  297. package/dist/esm/listbox/listbox.template.js +27 -0
  298. package/dist/esm/listbox-option/index.js +2 -0
  299. package/dist/esm/listbox-option/listbox-option.js +200 -0
  300. package/dist/esm/listbox-option/listbox-option.template.js +25 -0
  301. package/dist/esm/menu/index.js +2 -0
  302. package/dist/esm/menu/menu.js +290 -0
  303. package/dist/esm/menu/menu.template.js +15 -0
  304. package/dist/esm/menu-item/index.js +2 -0
  305. package/dist/esm/menu-item/menu-item.js +251 -0
  306. package/dist/esm/menu-item/menu-item.options.js +26 -0
  307. package/dist/esm/menu-item/menu-item.template.js +78 -0
  308. package/dist/esm/number-field/index.js +2 -0
  309. package/dist/esm/number-field/number-field.form-associated.js +15 -0
  310. package/dist/esm/number-field/number-field.js +288 -0
  311. package/dist/esm/number-field/number-field.template.js +84 -0
  312. package/dist/esm/patterns/aria-global.js +70 -0
  313. package/dist/esm/patterns/index.js +2 -0
  314. package/dist/esm/patterns/start-end.js +84 -0
  315. package/dist/esm/picker/index.js +10 -0
  316. package/dist/esm/picker/picker-list-item.js +71 -0
  317. package/dist/esm/picker/picker-list-item.template.js +17 -0
  318. package/dist/esm/picker/picker-list.js +8 -0
  319. package/dist/esm/picker/picker-list.template.js +13 -0
  320. package/dist/esm/picker/picker-menu-option.js +61 -0
  321. package/dist/esm/picker/picker-menu-option.template.js +16 -0
  322. package/dist/esm/picker/picker-menu.js +59 -0
  323. package/dist/esm/picker/picker-menu.template.js +29 -0
  324. package/dist/esm/picker/picker.form-associated.js +15 -0
  325. package/dist/esm/picker/picker.js +759 -0
  326. package/dist/esm/picker/picker.template.js +97 -0
  327. package/dist/esm/progress/base-progress.js +69 -0
  328. package/dist/esm/progress/index.js +2 -0
  329. package/dist/esm/progress/progress.template.js +31 -0
  330. package/dist/esm/progress-ring/index.js +1 -0
  331. package/dist/esm/progress-ring/progress-ring.template.js +45 -0
  332. package/dist/esm/radio/index.js +2 -0
  333. package/dist/esm/radio/radio.form-associated.js +15 -0
  334. package/dist/esm/radio/radio.js +108 -0
  335. package/dist/esm/radio/radio.template.js +31 -0
  336. package/dist/esm/radio-group/index.js +2 -0
  337. package/dist/esm/radio-group/radio-group.js +390 -0
  338. package/dist/esm/radio-group/radio-group.template.js +29 -0
  339. package/dist/esm/search/index.js +2 -0
  340. package/dist/esm/search/search.form-associated.js +15 -0
  341. package/dist/esm/search/search.js +157 -0
  342. package/dist/esm/search/search.template.js +93 -0
  343. package/dist/esm/select/index.js +3 -0
  344. package/dist/esm/select/select.form-associated.js +15 -0
  345. package/dist/esm/select/select.js +490 -0
  346. package/dist/esm/select/select.options.js +8 -0
  347. package/dist/esm/select/select.template.js +72 -0
  348. package/dist/esm/skeleton/index.js +2 -0
  349. package/dist/esm/skeleton/skeleton.js +35 -0
  350. package/dist/esm/skeleton/skeleton.template.js +20 -0
  351. package/dist/esm/slider/index.js +2 -0
  352. package/dist/esm/slider/slider-utilities.js +11 -0
  353. package/dist/esm/slider/slider.form-associated.js +15 -0
  354. package/dist/esm/slider/slider.js +452 -0
  355. package/dist/esm/slider/slider.template.js +40 -0
  356. package/dist/esm/slider-label/index.js +2 -0
  357. package/dist/esm/slider-label/slider-label.js +158 -0
  358. package/dist/esm/slider-label/slider-label.template.js +24 -0
  359. package/dist/esm/switch/index.js +2 -0
  360. package/dist/esm/switch/switch.form-associated.js +15 -0
  361. package/dist/esm/switch/switch.js +79 -0
  362. package/dist/esm/switch/switch.template.js +37 -0
  363. package/dist/esm/tab/index.js +2 -0
  364. package/dist/esm/tab/tab.js +15 -0
  365. package/dist/esm/tab/tab.template.js +10 -0
  366. package/dist/esm/tab-panel/index.js +2 -0
  367. package/dist/esm/tab-panel/tab-panel.js +10 -0
  368. package/dist/esm/tab-panel/tab-panel.template.js +10 -0
  369. package/dist/esm/tabs/index.js +2 -0
  370. package/dist/esm/tabs/tabs.js +375 -0
  371. package/dist/esm/tabs/tabs.template.js +26 -0
  372. package/dist/esm/test-utilities/fixture.js +90 -0
  373. package/dist/esm/test-utilities/timeout.js +13 -0
  374. package/dist/esm/text-area/index.js +2 -0
  375. package/dist/esm/text-area/text-area.form-associated.js +15 -0
  376. package/dist/esm/text-area/text-area.js +146 -0
  377. package/dist/esm/text-area/text-area.options.js +22 -0
  378. package/dist/esm/text-area/text-area.template.js +64 -0
  379. package/dist/esm/text-field/index.js +2 -0
  380. package/dist/esm/text-field/text-field.form-associated.js +15 -0
  381. package/dist/esm/text-field/text-field.js +183 -0
  382. package/dist/esm/text-field/text-field.options.js +26 -0
  383. package/dist/esm/text-field/text-field.template.js +70 -0
  384. package/dist/esm/toolbar/index.js +2 -0
  385. package/dist/esm/toolbar/toolbar.js +271 -0
  386. package/dist/esm/toolbar/toolbar.template.js +37 -0
  387. package/dist/esm/tooltip/index.js +2 -0
  388. package/dist/esm/tooltip/tooltip.js +512 -0
  389. package/dist/esm/tooltip/tooltip.options.js +63 -0
  390. package/dist/esm/tooltip/tooltip.template.js +32 -0
  391. package/dist/esm/tree-item/index.js +2 -0
  392. package/dist/esm/tree-item/tree-item.js +150 -0
  393. package/dist/esm/tree-item/tree-item.template.js +52 -0
  394. package/dist/esm/tree-view/index.js +2 -0
  395. package/dist/esm/tree-view/tree-view.js +268 -0
  396. package/dist/esm/tree-view/tree-view.template.js +18 -0
  397. package/dist/esm/utilities/apply-mixins.js +20 -0
  398. package/dist/esm/utilities/composed-contains.js +22 -0
  399. package/dist/esm/utilities/composed-parent.js +23 -0
  400. package/dist/esm/utilities/direction.js +10 -0
  401. package/dist/esm/utilities/index.js +8 -0
  402. package/dist/esm/utilities/intersection-service.js +91 -0
  403. package/dist/esm/utilities/match-media-stylesheet-behavior.js +140 -0
  404. package/dist/esm/utilities/property-stylesheet-behavior.js +52 -0
  405. package/dist/esm/utilities/resize-observer.js +5 -0
  406. package/dist/esm/utilities/root-active-element.js +8 -0
  407. package/dist/esm/utilities/style/disabled.js +5 -0
  408. package/dist/esm/utilities/style/display.js +14 -0
  409. package/dist/esm/utilities/style/focus.js +9 -0
  410. package/dist/esm/utilities/style/index.js +3 -0
  411. package/dist/esm/utilities/whitespace-filter.js +13 -0
  412. package/dist/fast-foundation.d.ts +9744 -0
  413. package/dist/fast-foundation.js +19097 -0
  414. package/dist/fast-foundation.min.js +19 -0
  415. package/dist/tsdoc-metadata.json +11 -0
  416. package/package.json +101 -0
@@ -0,0 +1,1341 @@
1
+ /**
2
+ * Big thanks to https://github.com/fkleuver and the https://github.com/aurelia/aurelia project
3
+ * for the bulk of this code and many of the associated tests.
4
+ */
5
+ import { emptyArray, FASTElement } from "@ni/fast-element";
6
+ // Tiny polyfill for TypeScript's Reflect metadata API.
7
+ const metadataByTarget = new Map();
8
+ if (!("metadata" in Reflect)) {
9
+ Reflect.metadata = function (key, value) {
10
+ return function (target) {
11
+ Reflect.defineMetadata(key, value, target);
12
+ };
13
+ };
14
+ Reflect.defineMetadata = function (key, value, target) {
15
+ let metadata = metadataByTarget.get(target);
16
+ if (metadata === void 0) {
17
+ metadataByTarget.set(target, (metadata = new Map()));
18
+ }
19
+ metadata.set(key, value);
20
+ };
21
+ Reflect.getOwnMetadata = function (key, target) {
22
+ const metadata = metadataByTarget.get(target);
23
+ if (metadata !== void 0) {
24
+ return metadata.get(key);
25
+ }
26
+ return void 0;
27
+ };
28
+ }
29
+ /**
30
+ * A utility class used that constructs and registers resolvers for a dependency
31
+ * injection container. Supports a standard set of object lifetimes.
32
+ * @public
33
+ */
34
+ export class ResolverBuilder {
35
+ /**
36
+ *
37
+ * @param container - The container to create resolvers for.
38
+ * @param key - The key to register resolvers under.
39
+ */
40
+ constructor(container, key) {
41
+ this.container = container;
42
+ this.key = key;
43
+ }
44
+ /**
45
+ * Creates a resolver for an existing object instance.
46
+ * @param value - The instance to resolve.
47
+ * @returns The resolver.
48
+ */
49
+ instance(value) {
50
+ return this.registerResolver(0 /* ResolverStrategy.instance */, value);
51
+ }
52
+ /**
53
+ * Creates a resolver that enforces a singleton lifetime.
54
+ * @param value - The type to create and cache the singleton for.
55
+ * @returns The resolver.
56
+ */
57
+ singleton(value) {
58
+ return this.registerResolver(1 /* ResolverStrategy.singleton */, value);
59
+ }
60
+ /**
61
+ * Creates a resolver that creates a new instance for every dependency request.
62
+ * @param value - The type to create instances of.
63
+ * @returns - The resolver.
64
+ */
65
+ transient(value) {
66
+ return this.registerResolver(2 /* ResolverStrategy.transient */, value);
67
+ }
68
+ /**
69
+ * Creates a resolver that invokes a callback function for every dependency resolution
70
+ * request, allowing custom logic to return the dependency.
71
+ * @param value - The callback to call during resolution.
72
+ * @returns The resolver.
73
+ */
74
+ callback(value) {
75
+ return this.registerResolver(3 /* ResolverStrategy.callback */, value);
76
+ }
77
+ /**
78
+ * Creates a resolver that invokes a callback function the first time that a dependency
79
+ * resolution is requested. The returned value is then cached and provided for all
80
+ * subsequent requests.
81
+ * @param value - The callback to call during the first resolution.
82
+ * @returns The resolver.
83
+ */
84
+ cachedCallback(value) {
85
+ return this.registerResolver(3 /* ResolverStrategy.callback */, cacheCallbackResult(value));
86
+ }
87
+ /**
88
+ * Aliases the current key to a different key.
89
+ * @param destinationKey - The key to point the alias to.
90
+ * @returns The resolver.
91
+ */
92
+ aliasTo(destinationKey) {
93
+ return this.registerResolver(5 /* ResolverStrategy.alias */, destinationKey);
94
+ }
95
+ registerResolver(strategy, state) {
96
+ const { container, key } = this;
97
+ /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
98
+ this.container = this.key = (void 0);
99
+ return container.registerResolver(key, new ResolverImpl(key, strategy, state));
100
+ }
101
+ }
102
+ function cloneArrayWithPossibleProps(source) {
103
+ const clone = source.slice();
104
+ const keys = Object.keys(source);
105
+ const len = keys.length;
106
+ let key;
107
+ for (let i = 0; i < len; ++i) {
108
+ key = keys[i];
109
+ if (!isArrayIndex(key)) {
110
+ clone[key] = source[key];
111
+ }
112
+ }
113
+ return clone;
114
+ }
115
+ /**
116
+ * A set of default resolvers useful in configuring a container.
117
+ * @public
118
+ */
119
+ export const DefaultResolver = Object.freeze({
120
+ /**
121
+ * Disables auto-registration and throws for all un-registered dependencies.
122
+ * @param key - The key to create the resolver for.
123
+ */
124
+ none(key) {
125
+ throw Error(`${key.toString()} not registered, did you forget to add @singleton()?`);
126
+ },
127
+ /**
128
+ * Provides default singleton resolution behavior during auto-registration.
129
+ * @param key - The key to create the resolver for.
130
+ * @returns The resolver.
131
+ */
132
+ singleton(key) {
133
+ return new ResolverImpl(key, 1 /* ResolverStrategy.singleton */, key);
134
+ },
135
+ /**
136
+ * Provides default transient resolution behavior during auto-registration.
137
+ * @param key - The key to create the resolver for.
138
+ * @returns The resolver.
139
+ */
140
+ transient(key) {
141
+ return new ResolverImpl(key, 2 /* ResolverStrategy.transient */, key);
142
+ },
143
+ });
144
+ /**
145
+ * Configuration for a dependency injection container.
146
+ * @public
147
+ */
148
+ export const ContainerConfiguration = Object.freeze({
149
+ /**
150
+ * The default configuration used when creating a DOM-disconnected container.
151
+ * @remarks
152
+ * The default creates a root container, with no parent container. It does not handle
153
+ * owner requests and it uses singleton resolution behavior for auto-registration.
154
+ */
155
+ default: Object.freeze({
156
+ parentLocator: () => null,
157
+ responsibleForOwnerRequests: false,
158
+ defaultResolver: DefaultResolver.singleton,
159
+ }),
160
+ });
161
+ const dependencyLookup = new Map();
162
+ function getParamTypes(key) {
163
+ return (Type) => {
164
+ return Reflect.getOwnMetadata(key, Type);
165
+ };
166
+ }
167
+ let rootDOMContainer = null;
168
+ /**
169
+ * The gateway to dependency injection APIs.
170
+ * @public
171
+ */
172
+ export const DI = Object.freeze({
173
+ /**
174
+ * Creates a new dependency injection container.
175
+ * @param config - The configuration for the container.
176
+ * @returns A newly created dependency injection container.
177
+ */
178
+ createContainer(config) {
179
+ return new ContainerImpl(null, Object.assign({}, ContainerConfiguration.default, config));
180
+ },
181
+ /**
182
+ * Finds the dependency injection container responsible for providing dependencies
183
+ * to the specified node.
184
+ * @param node - The node to find the responsible container for.
185
+ * @returns The container responsible for providing dependencies to the node.
186
+ * @remarks
187
+ * This will be the same as the parent container if the specified node
188
+ * does not itself host a container configured with responsibleForOwnerRequests.
189
+ */
190
+ findResponsibleContainer(node) {
191
+ const owned = node.$$container$$;
192
+ if (owned && owned.responsibleForOwnerRequests) {
193
+ return owned;
194
+ }
195
+ return DI.findParentContainer(node);
196
+ },
197
+ /**
198
+ * Find the dependency injection container up the DOM tree from this node.
199
+ * @param node - The node to find the parent container for.
200
+ * @returns The parent container of this node.
201
+ * @remarks
202
+ * This will be the same as the responsible container if the specified node
203
+ * does not itself host a container configured with responsibleForOwnerRequests.
204
+ */
205
+ findParentContainer(node) {
206
+ const event = new CustomEvent(DILocateParentEventType, {
207
+ bubbles: true,
208
+ composed: true,
209
+ cancelable: true,
210
+ detail: { container: void 0 },
211
+ });
212
+ node.dispatchEvent(event);
213
+ return event.detail.container || DI.getOrCreateDOMContainer();
214
+ },
215
+ /**
216
+ * Returns a dependency injection container if one is explicitly owned by the specified
217
+ * node. If one is not owned, then a new container is created and assigned to the node.
218
+ * @param node - The node to find or create the container for.
219
+ * @param config - The configuration for the container if one needs to be created.
220
+ * @returns The located or created container.
221
+ * @remarks
222
+ * This API does not search for a responsible or parent container. It looks only for a container
223
+ * directly defined on the specified node and creates one at that location if one does not
224
+ * already exist.
225
+ */
226
+ getOrCreateDOMContainer(node, config) {
227
+ if (!node) {
228
+ return (rootDOMContainer ||
229
+ (rootDOMContainer = new ContainerImpl(null, Object.assign({}, ContainerConfiguration.default, config, {
230
+ parentLocator: () => null,
231
+ }))));
232
+ }
233
+ return (node.$$container$$ ||
234
+ new ContainerImpl(node, Object.assign({}, ContainerConfiguration.default, config, {
235
+ parentLocator: DI.findParentContainer,
236
+ })));
237
+ },
238
+ /**
239
+ * Gets the "design:paramtypes" metadata for the specified type.
240
+ * @param Type - The type to get the metadata for.
241
+ * @returns The metadata array or undefined if no metadata is found.
242
+ */
243
+ getDesignParamtypes: getParamTypes("design:paramtypes"),
244
+ /**
245
+ * Gets the "di:paramtypes" metadata for the specified type.
246
+ * @param Type - The type to get the metadata for.
247
+ * @returns The metadata array or undefined if no metadata is found.
248
+ */
249
+ getAnnotationParamtypes: getParamTypes("di:paramtypes"),
250
+ /**
251
+ *
252
+ * @param Type - Gets the "di:paramtypes" metadata for the specified type. If none is found,
253
+ * an empty metadata array is created and added.
254
+ * @returns The metadata array.
255
+ */
256
+ getOrCreateAnnotationParamTypes(Type) {
257
+ let annotationParamtypes = this.getAnnotationParamtypes(Type);
258
+ if (annotationParamtypes === void 0) {
259
+ Reflect.defineMetadata("di:paramtypes", (annotationParamtypes = []), Type);
260
+ }
261
+ return annotationParamtypes;
262
+ },
263
+ /**
264
+ * Gets the dependency keys representing what is needed to instantiate the specified type.
265
+ * @param Type - The type to get the dependencies for.
266
+ * @returns An array of dependency keys.
267
+ */
268
+ getDependencies(Type) {
269
+ // Note: Every detail of this getDependencies method is pretty deliberate at the moment, and probably not yet 100% tested from every possible angle,
270
+ // so be careful with making changes here as it can have a huge impact on complex end user apps.
271
+ // Preferably, only make changes to the dependency resolution process via a RFC.
272
+ let dependencies = dependencyLookup.get(Type);
273
+ if (dependencies === void 0) {
274
+ // Type.length is the number of constructor parameters. If this is 0, it could mean the class has an empty constructor
275
+ // but it could also mean the class has no constructor at all (in which case it inherits the constructor from the prototype).
276
+ // Non-zero constructor length + no paramtypes means emitDecoratorMetadata is off, or the class has no decorator.
277
+ // We're not doing anything with the above right now, but it's good to keep in mind for any future issues.
278
+ const inject = Type.inject;
279
+ if (inject === void 0) {
280
+ // design:paramtypes is set by tsc when emitDecoratorMetadata is enabled.
281
+ const designParamtypes = DI.getDesignParamtypes(Type);
282
+ // di:paramtypes is set by the parameter decorator from DI.createInterface or by @inject
283
+ const annotationParamtypes = DI.getAnnotationParamtypes(Type);
284
+ if (designParamtypes === void 0) {
285
+ if (annotationParamtypes === void 0) {
286
+ // Only go up the prototype if neither static inject nor any of the paramtypes is defined, as
287
+ // there is no sound way to merge a type's deps with its prototype's deps
288
+ const Proto = Object.getPrototypeOf(Type);
289
+ if (typeof Proto === "function" && Proto !== Function.prototype) {
290
+ dependencies = cloneArrayWithPossibleProps(DI.getDependencies(Proto));
291
+ }
292
+ else {
293
+ dependencies = [];
294
+ }
295
+ }
296
+ else {
297
+ // No design:paramtypes so just use the di:paramtypes
298
+ dependencies = cloneArrayWithPossibleProps(annotationParamtypes);
299
+ }
300
+ }
301
+ else if (annotationParamtypes === void 0) {
302
+ // No di:paramtypes so just use the design:paramtypes
303
+ dependencies = cloneArrayWithPossibleProps(designParamtypes);
304
+ }
305
+ else {
306
+ // We've got both, so merge them (in case of conflict on same index, di:paramtypes take precedence)
307
+ dependencies = cloneArrayWithPossibleProps(designParamtypes);
308
+ let len = annotationParamtypes.length;
309
+ let auAnnotationParamtype;
310
+ for (let i = 0; i < len; ++i) {
311
+ auAnnotationParamtype = annotationParamtypes[i];
312
+ if (auAnnotationParamtype !== void 0) {
313
+ dependencies[i] = auAnnotationParamtype;
314
+ }
315
+ }
316
+ const keys = Object.keys(annotationParamtypes);
317
+ len = keys.length;
318
+ let key;
319
+ for (let i = 0; i < len; ++i) {
320
+ key = keys[i];
321
+ if (!isArrayIndex(key)) {
322
+ dependencies[key] = annotationParamtypes[key];
323
+ }
324
+ }
325
+ }
326
+ }
327
+ else {
328
+ // Ignore paramtypes if we have static inject
329
+ dependencies = cloneArrayWithPossibleProps(inject);
330
+ }
331
+ dependencyLookup.set(Type, dependencies);
332
+ }
333
+ return dependencies;
334
+ },
335
+ /**
336
+ * Defines a property on a web component class. The value of this property will
337
+ * be resolved from the dependency injection container responsible for the element
338
+ * instance, based on where it is connected in the DOM.
339
+ * @param target - The target to define the property on.
340
+ * @param propertyName - The name of the property to define.
341
+ * @param key - The dependency injection key.
342
+ * @param respectConnection - Indicates whether or not to update the property value if the
343
+ * hosting component is disconnected and then re-connected at a different location in the DOM.
344
+ * @remarks
345
+ * The respectConnection option is only applicable to elements that descend from FASTElement.
346
+ */
347
+ defineProperty(target, propertyName, key, respectConnection = false) {
348
+ const diPropertyKey = `$di_${propertyName}`;
349
+ Reflect.defineProperty(target, propertyName, {
350
+ get: function () {
351
+ let value = this[diPropertyKey];
352
+ if (value === void 0) {
353
+ const container = this instanceof HTMLElement
354
+ ? DI.findResponsibleContainer(this)
355
+ : DI.getOrCreateDOMContainer();
356
+ value = container.get(key);
357
+ this[diPropertyKey] = value;
358
+ if (respectConnection && this instanceof FASTElement) {
359
+ const notifier = this.$fastController;
360
+ const handleChange = () => {
361
+ const newContainer = DI.findResponsibleContainer(this);
362
+ const newValue = newContainer.get(key);
363
+ const oldValue = this[diPropertyKey];
364
+ if (newValue !== oldValue) {
365
+ this[diPropertyKey] = value;
366
+ notifier.notify(propertyName);
367
+ }
368
+ };
369
+ notifier.subscribe({ handleChange }, "isConnected");
370
+ }
371
+ }
372
+ return value;
373
+ },
374
+ });
375
+ },
376
+ /**
377
+ * Creates a dependency injection key.
378
+ * @param nameConfigOrCallback - A friendly name for the key or a lambda that configures a
379
+ * default resolution for the dependency.
380
+ * @param configuror - If a friendly name was provided for the first parameter, then an optional
381
+ * lambda that configures a default resolution for the dependency can be provided second.
382
+ * @returns The created key.
383
+ * @remarks
384
+ * The created key can be used as a property decorator or constructor parameter decorator,
385
+ * in addition to its standard use in an inject array or through direct container APIs.
386
+ */
387
+ createInterface(nameConfigOrCallback, configuror) {
388
+ const configure = typeof nameConfigOrCallback === "function"
389
+ ? nameConfigOrCallback
390
+ : configuror;
391
+ const friendlyName = typeof nameConfigOrCallback === "string"
392
+ ? nameConfigOrCallback
393
+ : nameConfigOrCallback && "friendlyName" in nameConfigOrCallback
394
+ ? nameConfigOrCallback.friendlyName || defaultFriendlyName
395
+ : defaultFriendlyName;
396
+ const respectConnection = typeof nameConfigOrCallback === "string"
397
+ ? false
398
+ : nameConfigOrCallback && "respectConnection" in nameConfigOrCallback
399
+ ? nameConfigOrCallback.respectConnection || false
400
+ : false;
401
+ const Interface = function (target, property, index) {
402
+ if (target == null || new.target !== undefined) {
403
+ throw new Error(`No registration for interface: '${Interface.friendlyName}'`);
404
+ }
405
+ if (property) {
406
+ DI.defineProperty(target, property, Interface, respectConnection);
407
+ }
408
+ else {
409
+ const annotationParamtypes = DI.getOrCreateAnnotationParamTypes(target);
410
+ annotationParamtypes[index] = Interface;
411
+ }
412
+ };
413
+ Interface.$isInterface = true;
414
+ Interface.friendlyName = friendlyName == null ? "(anonymous)" : friendlyName;
415
+ if (configure != null) {
416
+ Interface.register = function (container, key) {
417
+ return configure(new ResolverBuilder(container, key !== null && key !== void 0 ? key : Interface));
418
+ };
419
+ }
420
+ Interface.toString = function toString() {
421
+ return `InterfaceSymbol<${Interface.friendlyName}>`;
422
+ };
423
+ return Interface;
424
+ },
425
+ /**
426
+ * A decorator that specifies what to inject into its target.
427
+ * @param dependencies - The dependencies to inject.
428
+ * @returns The decorator to be applied to the target class.
429
+ * @remarks
430
+ * The decorator can be used to decorate a class, listing all of the classes dependencies.
431
+ * Or it can be used to decorate a constructor paramter, indicating what to inject for that
432
+ * parameter.
433
+ * Or it can be used for a web component property, indicating what that property should resolve to.
434
+ */
435
+ inject(...dependencies) {
436
+ return function (target, key, descriptor) {
437
+ if (typeof descriptor === "number") {
438
+ // It's a parameter decorator.
439
+ const annotationParamtypes = DI.getOrCreateAnnotationParamTypes(target);
440
+ const dep = dependencies[0];
441
+ if (dep !== void 0) {
442
+ annotationParamtypes[descriptor] = dep;
443
+ }
444
+ }
445
+ else if (key) {
446
+ DI.defineProperty(target, key, dependencies[0]);
447
+ }
448
+ else {
449
+ const annotationParamtypes = descriptor
450
+ ? DI.getOrCreateAnnotationParamTypes(descriptor.value)
451
+ : DI.getOrCreateAnnotationParamTypes(target);
452
+ let dep;
453
+ for (let i = 0; i < dependencies.length; ++i) {
454
+ dep = dependencies[i];
455
+ if (dep !== void 0) {
456
+ annotationParamtypes[i] = dep;
457
+ }
458
+ }
459
+ }
460
+ };
461
+ },
462
+ /**
463
+ * Registers the `target` class as a transient dependency; each time the dependency is resolved
464
+ * a new instance will be created.
465
+ *
466
+ * @param target - The class / constructor function to register as transient.
467
+ * @returns The same class, with a static `register` method that takes a container and returns the appropriate resolver.
468
+ *
469
+ * @example
470
+ * On an existing class
471
+ * ```ts
472
+ * class Foo { }
473
+ * DI.transient(Foo);
474
+ * ```
475
+ *
476
+ * @example
477
+ * Inline declaration
478
+ *
479
+ * ```ts
480
+ * const Foo = DI.transient(class { });
481
+ * // Foo is now strongly typed with register
482
+ * Foo.register(container);
483
+ * ```
484
+ *
485
+ * @public
486
+ */
487
+ transient(target) {
488
+ target.register = function register(container) {
489
+ const registration = Registration.transient(target, target);
490
+ return registration.register(container);
491
+ };
492
+ target.registerInRequestor = false;
493
+ return target;
494
+ },
495
+ /**
496
+ * Registers the `target` class as a singleton dependency; the class will only be created once. Each
497
+ * consecutive time the dependency is resolved, the same instance will be returned.
498
+ *
499
+ * @param target - The class / constructor function to register as a singleton.
500
+ * @returns The same class, with a static `register` method that takes a container and returns the appropriate resolver.
501
+ * @example
502
+ * On an existing class
503
+ * ```ts
504
+ * class Foo { }
505
+ * DI.singleton(Foo);
506
+ * ```
507
+ *
508
+ * @example
509
+ * Inline declaration
510
+ * ```ts
511
+ * const Foo = DI.singleton(class { });
512
+ * // Foo is now strongly typed with register
513
+ * Foo.register(container);
514
+ * ```
515
+ *
516
+ * @public
517
+ */
518
+ singleton(target, options = defaultSingletonOptions) {
519
+ target.register = function register(container) {
520
+ const registration = Registration.singleton(target, target);
521
+ return registration.register(container);
522
+ };
523
+ target.registerInRequestor = options.scoped;
524
+ return target;
525
+ },
526
+ });
527
+ /**
528
+ * The interface key that resolves the dependency injection container itself.
529
+ * @public
530
+ */
531
+ export const Container = DI.createInterface("Container");
532
+ /**
533
+ * The interface key that resolves the service locator itself.
534
+ * @public
535
+ */
536
+ export const ServiceLocator = Container;
537
+ function createResolver(getter) {
538
+ return function (key) {
539
+ const resolver = function (target, property, descriptor) {
540
+ DI.inject(resolver)(target, property, descriptor);
541
+ };
542
+ resolver.$isResolver = true;
543
+ resolver.resolve = function (handler, requestor) {
544
+ return getter(key, handler, requestor);
545
+ };
546
+ return resolver;
547
+ };
548
+ }
549
+ /**
550
+ * A decorator that specifies what to inject into its target.
551
+ * @param dependencies - The dependencies to inject.
552
+ * @returns The decorator to be applied to the target class.
553
+ * @remarks
554
+ * The decorator can be used to decorate a class, listing all of the classes dependencies.
555
+ * Or it can be used to decorate a constructor paramter, indicating what to inject for that
556
+ * parameter.
557
+ * Or it can be used for a web component property, indicating what that property should resolve to.
558
+ *
559
+ * @public
560
+ */
561
+ export const inject = DI.inject;
562
+ function transientDecorator(target) {
563
+ return DI.transient(target);
564
+ }
565
+ export function transient(target) {
566
+ return target == null ? transientDecorator : transientDecorator(target);
567
+ }
568
+ const defaultSingletonOptions = { scoped: false };
569
+ function singletonDecorator(target) {
570
+ return DI.singleton(target);
571
+ }
572
+ /**
573
+ * @public
574
+ */
575
+ export function singleton(targetOrOptions) {
576
+ if (typeof targetOrOptions === "function") {
577
+ return DI.singleton(targetOrOptions);
578
+ }
579
+ return function ($target) {
580
+ return DI.singleton($target, targetOrOptions);
581
+ };
582
+ }
583
+ function createAllResolver(getter) {
584
+ return function (key, searchAncestors) {
585
+ searchAncestors = !!searchAncestors;
586
+ const resolver = function (target, property, descriptor) {
587
+ DI.inject(resolver)(target, property, descriptor);
588
+ };
589
+ resolver.$isResolver = true;
590
+ resolver.resolve = function (handler, requestor) {
591
+ /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
592
+ return getter(key, handler, requestor, searchAncestors);
593
+ };
594
+ return resolver;
595
+ };
596
+ }
597
+ /**
598
+ * A decorator and DI resolver that will resolve an array of all dependencies
599
+ * registered with the specified key.
600
+ * @param key - The key to resolve all dependencies for.
601
+ * @param searchAncestors - [optional] Indicates whether to search ancestor containers.
602
+ * @public
603
+ */
604
+ export const all = createAllResolver((key, handler, requestor, searchAncestors) => requestor.getAll(key, searchAncestors));
605
+ /**
606
+ * A decorator that lazily injects a dependency depending on whether the `Key` is present at the time of function call.
607
+ *
608
+ * @example
609
+ * You need to make your argument a function that returns the type, for example
610
+ * ```ts
611
+ * class Foo {
612
+ * constructor( @lazy('random') public random: () => number )
613
+ * }
614
+ * const foo = container.get(Foo); // instanceof Foo
615
+ * foo.random(); // throws
616
+ * ```
617
+ * would throw an exception because you haven't registered `'random'` before calling the method.
618
+ * @example
619
+ * This, would give you a new 'Math.random()' number each time.
620
+ * ```ts
621
+ * class Foo {
622
+ * constructor( @lazy('random') public random: () => random )
623
+ * }
624
+ * container.register(Registration.callback('random', Math.random ));
625
+ * container.get(Foo).random(); // some random number
626
+ * container.get(Foo).random(); // another random number
627
+ * ```
628
+ *
629
+ * `@lazy` does not manage the lifecycle of the underlying key. If you want a singleton, you have to register as a
630
+ * `singleton`, `transient` would also behave as you would expect, providing you a new instance each time.
631
+ *
632
+ * @param key - The key to lazily resolve.
633
+ * see {@link DI.createInterface} on interactions with interfaces
634
+ *
635
+ * @public
636
+ */
637
+ export const lazy = createResolver((key, handler, requestor) => {
638
+ return () => requestor.get(key);
639
+ });
640
+ /**
641
+ * A decorator that allows you to optionally inject a dependency depending on whether the [[`Key`]] is present, for example:
642
+ * @example
643
+ * ```ts
644
+ * class Foo {
645
+ * constructor( @inject('mystring') public str: string = 'somestring' )
646
+ * }
647
+ * container.get(Foo); // throws
648
+ * ```
649
+ * would fail
650
+ *
651
+ * @example
652
+ * ```ts
653
+ * class Foo {
654
+ * constructor( @optional('mystring') public str: string = 'somestring' )
655
+ * }
656
+ * container.get(Foo).str // somestring
657
+ * ```
658
+ * if you use it without a default it will inject `undefined`, so remember to mark your input type as
659
+ * possibly `undefined`!
660
+ *
661
+ * @param key - The key to optionally resolve.
662
+ * see {@link DI.createInterface} on interactions with interfaces
663
+ *
664
+ * @public
665
+ */
666
+ export const optional = createResolver((key, handler, requestor) => {
667
+ if (requestor.has(key, true)) {
668
+ return requestor.get(key);
669
+ }
670
+ else {
671
+ return undefined;
672
+ }
673
+ });
674
+ /**
675
+ * A decorator that tells the container not to try to inject a dependency.
676
+ *
677
+ * @public
678
+ */
679
+ export function ignore(target, property, descriptor) {
680
+ DI.inject(ignore)(target, property, descriptor);
681
+ }
682
+ // Hack: casting below used to prevent TS from generate a namespace which can't be commented
683
+ // and results in documentation validation errors.
684
+ ignore.$isResolver = true;
685
+ ignore.resolve = () => undefined;
686
+ /**
687
+ * A decorator that indicates that a new instance should be injected scoped to the
688
+ * container that requested the instance.
689
+ * @param key - The dependency key for the new instance.
690
+ * @remarks
691
+ * This creates a resolver with an instance strategy pointing to the new instance, effectively
692
+ * making this a singleton, scoped to the container or DOM's subtree.
693
+ *
694
+ * @public
695
+ */
696
+ export const newInstanceForScope = createResolver((key, handler, requestor) => {
697
+ const instance = createNewInstance(key, handler);
698
+ const resolver = new ResolverImpl(key, 0 /* ResolverStrategy.instance */, instance);
699
+ requestor.registerResolver(key, resolver);
700
+ return instance;
701
+ });
702
+ /**
703
+ * A decorator that indicates that a new instance should be injected.
704
+ * @param key - The dependency key for the new instance.
705
+ * @remarks
706
+ * The instance is not internally cached with a resolver as newInstanceForScope does.
707
+ *
708
+ * @public
709
+ */
710
+ export const newInstanceOf = createResolver((key, handler, _requestor) => createNewInstance(key, handler));
711
+ function createNewInstance(key, handler) {
712
+ /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
713
+ return handler.getFactory(key).construct(handler);
714
+ }
715
+ /** @internal */
716
+ export class ResolverImpl {
717
+ constructor(key, strategy, state) {
718
+ this.key = key;
719
+ this.strategy = strategy;
720
+ this.state = state;
721
+ this.resolving = false;
722
+ }
723
+ get $isResolver() {
724
+ return true;
725
+ }
726
+ register(container) {
727
+ return container.registerResolver(this.key, this);
728
+ }
729
+ resolve(handler, requestor) {
730
+ switch (this.strategy) {
731
+ case 0 /* ResolverStrategy.instance */:
732
+ return this.state;
733
+ case 1 /* ResolverStrategy.singleton */: {
734
+ if (this.resolving) {
735
+ throw new Error(`Cyclic dependency found: ${this.state.name}`);
736
+ }
737
+ this.resolving = true;
738
+ this.state = handler
739
+ .getFactory(this.state)
740
+ .construct(requestor);
741
+ this.strategy = 0 /* ResolverStrategy.instance */;
742
+ this.resolving = false;
743
+ return this.state;
744
+ }
745
+ case 2 /* ResolverStrategy.transient */: {
746
+ // Always create transients from the requesting container
747
+ const factory = handler.getFactory(this.state);
748
+ if (factory === null) {
749
+ throw new Error(`Resolver for ${String(this.key)} returned a null factory`);
750
+ }
751
+ return factory.construct(requestor);
752
+ }
753
+ case 3 /* ResolverStrategy.callback */:
754
+ return this.state(handler, requestor, this);
755
+ case 4 /* ResolverStrategy.array */:
756
+ return this.state[0].resolve(handler, requestor);
757
+ case 5 /* ResolverStrategy.alias */:
758
+ return requestor.get(this.state);
759
+ default:
760
+ throw new Error(`Invalid resolver strategy specified: ${this.strategy}.`);
761
+ }
762
+ }
763
+ getFactory(container) {
764
+ var _a, _b, _c;
765
+ switch (this.strategy) {
766
+ case 1 /* ResolverStrategy.singleton */:
767
+ case 2 /* ResolverStrategy.transient */:
768
+ return container.getFactory(this.state);
769
+ case 5 /* ResolverStrategy.alias */:
770
+ return (_c = (_b = (_a = container.getResolver(this.state)) === null || _a === void 0 ? void 0 : _a.getFactory) === null || _b === void 0 ? void 0 : _b.call(_a, container)) !== null && _c !== void 0 ? _c : null;
771
+ default:
772
+ return null;
773
+ }
774
+ }
775
+ }
776
+ function containerGetKey(d) {
777
+ return this.get(d);
778
+ }
779
+ function transformInstance(inst, transform) {
780
+ return transform(inst);
781
+ }
782
+ /** @internal */
783
+ export class FactoryImpl {
784
+ constructor(Type, dependencies) {
785
+ this.Type = Type;
786
+ this.dependencies = dependencies;
787
+ this.transformers = null;
788
+ }
789
+ construct(container, dynamicDependencies) {
790
+ let instance;
791
+ if (dynamicDependencies === void 0) {
792
+ instance = new this.Type(...this.dependencies.map(containerGetKey, container));
793
+ }
794
+ else {
795
+ instance = new this.Type(...this.dependencies.map(containerGetKey, container), ...dynamicDependencies);
796
+ }
797
+ if (this.transformers == null) {
798
+ return instance;
799
+ }
800
+ return this.transformers.reduce(transformInstance, instance);
801
+ }
802
+ registerTransformer(transformer) {
803
+ (this.transformers || (this.transformers = [])).push(transformer);
804
+ }
805
+ }
806
+ const containerResolver = {
807
+ $isResolver: true,
808
+ resolve(handler, requestor) {
809
+ return requestor;
810
+ },
811
+ };
812
+ function isRegistry(obj) {
813
+ return typeof obj.register === "function";
814
+ }
815
+ function isSelfRegistry(obj) {
816
+ return isRegistry(obj) && typeof obj.registerInRequestor === "boolean";
817
+ }
818
+ function isRegisterInRequester(obj) {
819
+ return isSelfRegistry(obj) && obj.registerInRequestor;
820
+ }
821
+ function isClass(obj) {
822
+ return obj.prototype !== void 0;
823
+ }
824
+ const InstrinsicTypeNames = new Set([
825
+ "Array",
826
+ "ArrayBuffer",
827
+ "Boolean",
828
+ "DataView",
829
+ "Date",
830
+ "Error",
831
+ "EvalError",
832
+ "Float32Array",
833
+ "Float64Array",
834
+ "Function",
835
+ "Int8Array",
836
+ "Int16Array",
837
+ "Int32Array",
838
+ "Map",
839
+ "Number",
840
+ "Object",
841
+ "Promise",
842
+ "RangeError",
843
+ "ReferenceError",
844
+ "RegExp",
845
+ "Set",
846
+ "SharedArrayBuffer",
847
+ "String",
848
+ "SyntaxError",
849
+ "TypeError",
850
+ "Uint8Array",
851
+ "Uint8ClampedArray",
852
+ "Uint16Array",
853
+ "Uint32Array",
854
+ "URIError",
855
+ "WeakMap",
856
+ "WeakSet",
857
+ ]);
858
+ const DILocateParentEventType = "__DI_LOCATE_PARENT__";
859
+ const factories = new Map();
860
+ /**
861
+ * @internal
862
+ */
863
+ export class ContainerImpl {
864
+ get parent() {
865
+ if (this._parent === void 0) {
866
+ this._parent = this.config.parentLocator(this.owner);
867
+ }
868
+ return this._parent;
869
+ }
870
+ get depth() {
871
+ return this.parent === null ? 0 : this.parent.depth + 1;
872
+ }
873
+ get responsibleForOwnerRequests() {
874
+ return this.config.responsibleForOwnerRequests;
875
+ }
876
+ constructor(owner, config) {
877
+ this.owner = owner;
878
+ this.config = config;
879
+ this._parent = void 0;
880
+ this.registerDepth = 0;
881
+ this.context = null;
882
+ if (owner !== null) {
883
+ owner.$$container$$ = this;
884
+ }
885
+ this.resolvers = new Map();
886
+ this.resolvers.set(Container, containerResolver);
887
+ if (owner instanceof Node) {
888
+ owner.addEventListener(DILocateParentEventType, (e) => {
889
+ if (e.composedPath()[0] !== this.owner) {
890
+ e.detail.container = this;
891
+ e.stopImmediatePropagation();
892
+ }
893
+ });
894
+ }
895
+ }
896
+ registerWithContext(context, ...params) {
897
+ this.context = context;
898
+ this.register(...params);
899
+ this.context = null;
900
+ return this;
901
+ }
902
+ register(...params) {
903
+ if (++this.registerDepth === 100) {
904
+ throw new Error("Unable to autoregister dependency");
905
+ // Most likely cause is trying to register a plain object that does not have a
906
+ // register method and is not a class constructor
907
+ }
908
+ let current;
909
+ let keys;
910
+ let value;
911
+ let j;
912
+ let jj;
913
+ const context = this.context;
914
+ for (let i = 0, ii = params.length; i < ii; ++i) {
915
+ current = params[i];
916
+ if (!isObject(current)) {
917
+ continue;
918
+ }
919
+ if (isRegistry(current)) {
920
+ current.register(this, context);
921
+ }
922
+ else if (isClass(current)) {
923
+ Registration.singleton(current, current).register(this);
924
+ }
925
+ else {
926
+ keys = Object.keys(current);
927
+ j = 0;
928
+ jj = keys.length;
929
+ for (; j < jj; ++j) {
930
+ value = current[keys[j]];
931
+ if (!isObject(value)) {
932
+ continue;
933
+ }
934
+ // note: we could remove this if-branch and call this.register directly
935
+ // - the extra check is just a perf tweak to create fewer unnecessary arrays by the spread operator
936
+ if (isRegistry(value)) {
937
+ value.register(this, context);
938
+ }
939
+ else {
940
+ this.register(value);
941
+ }
942
+ }
943
+ }
944
+ }
945
+ --this.registerDepth;
946
+ return this;
947
+ }
948
+ registerResolver(key, resolver) {
949
+ validateKey(key);
950
+ const resolvers = this.resolvers;
951
+ const result = resolvers.get(key);
952
+ if (result == null) {
953
+ resolvers.set(key, resolver);
954
+ }
955
+ else if (result instanceof ResolverImpl &&
956
+ result.strategy === 4 /* ResolverStrategy.array */) {
957
+ result.state.push(resolver);
958
+ }
959
+ else {
960
+ resolvers.set(key, new ResolverImpl(key, 4 /* ResolverStrategy.array */, [result, resolver]));
961
+ }
962
+ return resolver;
963
+ }
964
+ registerTransformer(key, transformer) {
965
+ const resolver = this.getResolver(key);
966
+ if (resolver == null) {
967
+ return false;
968
+ }
969
+ if (resolver.getFactory) {
970
+ const factory = resolver.getFactory(this);
971
+ if (factory == null) {
972
+ return false;
973
+ }
974
+ // This type cast is a bit of a hacky one, necessary due to the duplicity of IResolverLike.
975
+ // Problem is that that interface's type arg can be of type Key, but the getFactory method only works on
976
+ // type Constructable. So the return type of that optional method has this additional constraint, which
977
+ // seems to confuse the type checker.
978
+ factory.registerTransformer(transformer);
979
+ return true;
980
+ }
981
+ return false;
982
+ }
983
+ getResolver(key, autoRegister = true) {
984
+ validateKey(key);
985
+ if (key.resolve !== void 0) {
986
+ return key;
987
+ }
988
+ /* eslint-disable-next-line @typescript-eslint/no-this-alias */
989
+ let current = this;
990
+ let resolver;
991
+ while (current != null) {
992
+ resolver = current.resolvers.get(key);
993
+ if (resolver == null) {
994
+ if (current.parent == null) {
995
+ const handler = isRegisterInRequester(key)
996
+ ? this
997
+ : current;
998
+ return autoRegister ? this.jitRegister(key, handler) : null;
999
+ }
1000
+ current = current.parent;
1001
+ }
1002
+ else {
1003
+ return resolver;
1004
+ }
1005
+ }
1006
+ return null;
1007
+ }
1008
+ has(key, searchAncestors = false) {
1009
+ return this.resolvers.has(key)
1010
+ ? true
1011
+ : searchAncestors && this.parent != null
1012
+ ? this.parent.has(key, true)
1013
+ : false;
1014
+ }
1015
+ get(key) {
1016
+ validateKey(key);
1017
+ if (key.$isResolver) {
1018
+ return key.resolve(this, this);
1019
+ }
1020
+ /* eslint-disable-next-line @typescript-eslint/no-this-alias */
1021
+ let current = this;
1022
+ let resolver;
1023
+ while (current != null) {
1024
+ resolver = current.resolvers.get(key);
1025
+ if (resolver == null) {
1026
+ if (current.parent == null) {
1027
+ const handler = isRegisterInRequester(key)
1028
+ ? this
1029
+ : current;
1030
+ resolver = this.jitRegister(key, handler);
1031
+ return resolver.resolve(current, this);
1032
+ }
1033
+ current = current.parent;
1034
+ }
1035
+ else {
1036
+ return resolver.resolve(current, this);
1037
+ }
1038
+ }
1039
+ throw new Error(`Unable to resolve key: ${String(key)}`);
1040
+ }
1041
+ getAll(key, searchAncestors = false) {
1042
+ validateKey(key);
1043
+ /* eslint-disable-next-line @typescript-eslint/no-this-alias */
1044
+ const requestor = this;
1045
+ let current = requestor;
1046
+ let resolver;
1047
+ if (searchAncestors) {
1048
+ let resolutions = emptyArray;
1049
+ while (current != null) {
1050
+ resolver = current.resolvers.get(key);
1051
+ if (resolver != null) {
1052
+ resolutions = resolutions.concat(
1053
+ /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
1054
+ buildAllResponse(resolver, current, requestor));
1055
+ }
1056
+ current = current.parent;
1057
+ }
1058
+ return resolutions;
1059
+ }
1060
+ else {
1061
+ while (current != null) {
1062
+ resolver = current.resolvers.get(key);
1063
+ if (resolver == null) {
1064
+ current = current.parent;
1065
+ if (current == null) {
1066
+ return emptyArray;
1067
+ }
1068
+ }
1069
+ else {
1070
+ return buildAllResponse(resolver, current, requestor);
1071
+ }
1072
+ }
1073
+ }
1074
+ return emptyArray;
1075
+ }
1076
+ getFactory(Type) {
1077
+ let factory = factories.get(Type);
1078
+ if (factory === void 0) {
1079
+ if (isNativeFunction(Type)) {
1080
+ throw new Error(`${Type.name} is a native function and therefore cannot be safely constructed by DI. If this is intentional, please use a callback or cachedCallback resolver.`);
1081
+ }
1082
+ factories.set(Type, (factory = new FactoryImpl(Type, DI.getDependencies(Type))));
1083
+ }
1084
+ return factory;
1085
+ }
1086
+ registerFactory(key, factory) {
1087
+ factories.set(key, factory);
1088
+ }
1089
+ createChild(config) {
1090
+ return new ContainerImpl(null, Object.assign({}, this.config, config, { parentLocator: () => this }));
1091
+ }
1092
+ jitRegister(keyAsValue, handler) {
1093
+ if (typeof keyAsValue !== "function") {
1094
+ throw new Error(`Attempted to jitRegister something that is not a constructor: '${keyAsValue}'. Did you forget to register this dependency?`);
1095
+ }
1096
+ if (InstrinsicTypeNames.has(keyAsValue.name)) {
1097
+ throw new Error(`Attempted to jitRegister an intrinsic type: ${keyAsValue.name}. Did you forget to add @inject(Key)`);
1098
+ }
1099
+ if (isRegistry(keyAsValue)) {
1100
+ const registrationResolver = keyAsValue.register(handler);
1101
+ if (!(registrationResolver instanceof Object) ||
1102
+ registrationResolver.resolve == null) {
1103
+ const newResolver = handler.resolvers.get(keyAsValue);
1104
+ if (newResolver != void 0) {
1105
+ return newResolver;
1106
+ }
1107
+ throw new Error("A valid resolver was not returned from the static register method");
1108
+ }
1109
+ return registrationResolver;
1110
+ }
1111
+ else if (keyAsValue.$isInterface) {
1112
+ throw new Error(`Attempted to jitRegister an interface: ${keyAsValue.friendlyName}`);
1113
+ }
1114
+ else {
1115
+ const resolver = this.config.defaultResolver(keyAsValue, handler);
1116
+ handler.resolvers.set(keyAsValue, resolver);
1117
+ return resolver;
1118
+ }
1119
+ }
1120
+ }
1121
+ const cache = new WeakMap();
1122
+ function cacheCallbackResult(fun) {
1123
+ return function (handler, requestor, resolver) {
1124
+ if (cache.has(resolver)) {
1125
+ return cache.get(resolver);
1126
+ }
1127
+ const t = fun(handler, requestor, resolver);
1128
+ cache.set(resolver, t);
1129
+ return t;
1130
+ };
1131
+ }
1132
+ /**
1133
+ * You can use the resulting Registration of any of the factory methods
1134
+ * to register with the container.
1135
+ *
1136
+ * @example
1137
+ * ```
1138
+ * class Foo {}
1139
+ * const container = DI.createContainer();
1140
+ * container.register(Registration.instance(Foo, new Foo()));
1141
+ * container.get(Foo);
1142
+ * ```
1143
+ *
1144
+ * @public
1145
+ */
1146
+ export const Registration = Object.freeze({
1147
+ /**
1148
+ * Allows you to pass an instance.
1149
+ * Every time you request this {@link Key} you will get this instance back.
1150
+ *
1151
+ * @example
1152
+ * ```
1153
+ * Registration.instance(Foo, new Foo()));
1154
+ * ```
1155
+ *
1156
+ * @param key - The key to register the instance under.
1157
+ * @param value - The instance to return when the key is requested.
1158
+ */
1159
+ instance(key, value) {
1160
+ return new ResolverImpl(key, 0 /* ResolverStrategy.instance */, value);
1161
+ },
1162
+ /**
1163
+ * Creates an instance from the class.
1164
+ * Every time you request this {@link Key} you will get the same one back.
1165
+ *
1166
+ * @example
1167
+ * ```
1168
+ * Registration.singleton(Foo, Foo);
1169
+ * ```
1170
+ *
1171
+ * @param key - The key to register the singleton under.
1172
+ * @param value - The class to instantiate as a singleton when first requested.
1173
+ */
1174
+ singleton(key, value) {
1175
+ return new ResolverImpl(key, 1 /* ResolverStrategy.singleton */, value);
1176
+ },
1177
+ /**
1178
+ * Creates an instance from a class.
1179
+ * Every time you request this {@link Key} you will get a new instance.
1180
+ *
1181
+ * @example
1182
+ * ```
1183
+ * Registration.instance(Foo, Foo);
1184
+ * ```
1185
+ *
1186
+ * @param key - The key to register the instance type under.
1187
+ * @param value - The class to instantiate each time the key is requested.
1188
+ */
1189
+ transient(key, value) {
1190
+ return new ResolverImpl(key, 2 /* ResolverStrategy.transient */, value);
1191
+ },
1192
+ /**
1193
+ * Delegates to a callback function to provide the dependency.
1194
+ * Every time you request this {@link Key} the callback will be invoked to provide
1195
+ * the dependency.
1196
+ *
1197
+ * @example
1198
+ * ```
1199
+ * Registration.callback(Foo, () => new Foo());
1200
+ * Registration.callback(Bar, (c: Container) => new Bar(c.get(Foo)));
1201
+ * ```
1202
+ *
1203
+ * @param key - The key to register the callback for.
1204
+ * @param callback - The function that is expected to return the dependency.
1205
+ */
1206
+ callback(key, callback) {
1207
+ return new ResolverImpl(key, 3 /* ResolverStrategy.callback */, callback);
1208
+ },
1209
+ /**
1210
+ * Delegates to a callback function to provide the dependency and then caches the
1211
+ * dependency for future requests.
1212
+ *
1213
+ * @example
1214
+ * ```
1215
+ * Registration.cachedCallback(Foo, () => new Foo());
1216
+ * Registration.cachedCallback(Bar, (c: Container) => new Bar(c.get(Foo)));
1217
+ * ```
1218
+ *
1219
+ * @param key - The key to register the callback for.
1220
+ * @param callback - The function that is expected to return the dependency.
1221
+ * @remarks
1222
+ * If you pass the same Registration to another container, the same cached value will be used.
1223
+ * Should all references to the resolver returned be removed, the cache will expire.
1224
+ */
1225
+ cachedCallback(key, callback) {
1226
+ return new ResolverImpl(key, 3 /* ResolverStrategy.callback */, cacheCallbackResult(callback));
1227
+ },
1228
+ /**
1229
+ * Creates an alternate {@link Key} to retrieve an instance by.
1230
+ *
1231
+ * @example
1232
+ * ```
1233
+ * Register.singleton(Foo, Foo)
1234
+ * Register.aliasTo(Foo, MyFoos);
1235
+ *
1236
+ * container.getAll(MyFoos) // contains an instance of Foo
1237
+ * ```
1238
+ *
1239
+ * @param originalKey - The original key that has been registered.
1240
+ * @param aliasKey - The alias to the original key.
1241
+ */
1242
+ aliasTo(originalKey, aliasKey) {
1243
+ return new ResolverImpl(aliasKey, 5 /* ResolverStrategy.alias */, originalKey);
1244
+ },
1245
+ });
1246
+ /** @internal */
1247
+ export function validateKey(key) {
1248
+ if (key === null || key === void 0) {
1249
+ throw new Error("key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?");
1250
+ }
1251
+ }
1252
+ function buildAllResponse(resolver, handler, requestor) {
1253
+ if (resolver instanceof ResolverImpl &&
1254
+ resolver.strategy === 4 /* ResolverStrategy.array */) {
1255
+ const state = resolver.state;
1256
+ let i = state.length;
1257
+ const results = new Array(i);
1258
+ while (i--) {
1259
+ results[i] = state[i].resolve(handler, requestor);
1260
+ }
1261
+ return results;
1262
+ }
1263
+ return [resolver.resolve(handler, requestor)];
1264
+ }
1265
+ const defaultFriendlyName = "(anonymous)";
1266
+ function isObject(value) {
1267
+ return (typeof value === "object" && value !== null) || typeof value === "function";
1268
+ }
1269
+ /**
1270
+ * Determine whether the value is a native function.
1271
+ *
1272
+ * @param fn - The function to check.
1273
+ * @returns `true` is the function is a native function, otherwise `false`
1274
+ */
1275
+ const isNativeFunction = (function () {
1276
+ const lookup = new WeakMap();
1277
+ let isNative = false;
1278
+ let sourceText = "";
1279
+ let i = 0;
1280
+ return function (fn) {
1281
+ isNative = lookup.get(fn);
1282
+ if (isNative === void 0) {
1283
+ sourceText = fn.toString();
1284
+ i = sourceText.length;
1285
+ // http://www.ecma-international.org/ecma-262/#prod-NativeFunction
1286
+ isNative =
1287
+ // 29 is the length of 'function () { [native code] }' which is the smallest length of a native function string
1288
+ i >= 29 &&
1289
+ // 100 seems to be a safe upper bound of the max length of a native function. In Chrome and FF it's 56, in Edge it's 61.
1290
+ i <= 100 &&
1291
+ // This whole heuristic *could* be tricked by a comment. Do we need to care about that?
1292
+ sourceText.charCodeAt(i - 1) === 0x7d && // }
1293
+ // TODO: the spec is a little vague about the precise constraints, so we do need to test this across various browsers to make sure just one whitespace is a safe assumption.
1294
+ sourceText.charCodeAt(i - 2) <= 0x20 && // whitespace
1295
+ sourceText.charCodeAt(i - 3) === 0x5d && // ]
1296
+ sourceText.charCodeAt(i - 4) === 0x65 && // e
1297
+ sourceText.charCodeAt(i - 5) === 0x64 && // d
1298
+ sourceText.charCodeAt(i - 6) === 0x6f && // o
1299
+ sourceText.charCodeAt(i - 7) === 0x63 && // c
1300
+ sourceText.charCodeAt(i - 8) === 0x20 && //
1301
+ sourceText.charCodeAt(i - 9) === 0x65 && // e
1302
+ sourceText.charCodeAt(i - 10) === 0x76 && // v
1303
+ sourceText.charCodeAt(i - 11) === 0x69 && // i
1304
+ sourceText.charCodeAt(i - 12) === 0x74 && // t
1305
+ sourceText.charCodeAt(i - 13) === 0x61 && // a
1306
+ sourceText.charCodeAt(i - 14) === 0x6e && // n
1307
+ sourceText.charCodeAt(i - 15) === 0x58; // [
1308
+ lookup.set(fn, isNative);
1309
+ }
1310
+ return isNative;
1311
+ };
1312
+ })();
1313
+ const isNumericLookup = {};
1314
+ function isArrayIndex(value) {
1315
+ switch (typeof value) {
1316
+ case "number":
1317
+ return value >= 0 && (value | 0) === value;
1318
+ case "string": {
1319
+ const result = isNumericLookup[value];
1320
+ if (result !== void 0) {
1321
+ return result;
1322
+ }
1323
+ const length = value.length;
1324
+ if (length === 0) {
1325
+ return (isNumericLookup[value] = false);
1326
+ }
1327
+ let ch = 0;
1328
+ for (let i = 0; i < length; ++i) {
1329
+ ch = value.charCodeAt(i);
1330
+ if ((i === 0 && ch === 0x30 && length > 1) /* must not start with 0 */ ||
1331
+ ch < 0x30 /* 0 */ ||
1332
+ ch > 0x39 /* 9 */) {
1333
+ return (isNumericLookup[value] = false);
1334
+ }
1335
+ }
1336
+ return (isNumericLookup[value] = true);
1337
+ }
1338
+ default:
1339
+ return false;
1340
+ }
1341
+ }