@tailng-ui/components 0.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 (266) hide show
  1. package/README.md +26 -0
  2. package/package.json +14 -0
  3. package/src/index.d.ts +7 -0
  4. package/src/index.d.ts.map +1 -0
  5. package/src/index.js +7 -0
  6. package/src/index.js.map +1 -0
  7. package/src/lib/feedback/empty/tng-empty.component.d.ts +14 -0
  8. package/src/lib/feedback/empty/tng-empty.component.d.ts.map +1 -0
  9. package/src/lib/feedback/empty/tng-empty.component.js +60 -0
  10. package/src/lib/feedback/empty/tng-empty.component.js.map +1 -0
  11. package/src/lib/feedback/index.d.ts +11 -0
  12. package/src/lib/feedback/index.d.ts.map +1 -0
  13. package/src/lib/feedback/index.js +11 -0
  14. package/src/lib/feedback/index.js.map +1 -0
  15. package/src/lib/feedback/progress-bar/tng-progress-bar.component.d.ts +10 -0
  16. package/src/lib/feedback/progress-bar/tng-progress-bar.component.d.ts.map +1 -0
  17. package/src/lib/feedback/progress-bar/tng-progress-bar.component.js +37 -0
  18. package/src/lib/feedback/progress-bar/tng-progress-bar.component.js.map +1 -0
  19. package/src/lib/feedback/progress-spinner/tng-progress-spinner.component.d.ts +14 -0
  20. package/src/lib/feedback/progress-spinner/tng-progress-spinner.component.d.ts.map +1 -0
  21. package/src/lib/feedback/progress-spinner/tng-progress-spinner.component.js +55 -0
  22. package/src/lib/feedback/progress-spinner/tng-progress-spinner.component.js.map +1 -0
  23. package/src/lib/feedback/skeleton/tng-skeleton.component.d.ts +10 -0
  24. package/src/lib/feedback/skeleton/tng-skeleton.component.d.ts.map +1 -0
  25. package/src/lib/feedback/skeleton/tng-skeleton.component.js +33 -0
  26. package/src/lib/feedback/skeleton/tng-skeleton.component.js.map +1 -0
  27. package/src/lib/feedback/toast/tng-toast.component.d.ts +40 -0
  28. package/src/lib/feedback/toast/tng-toast.component.d.ts.map +1 -0
  29. package/src/lib/feedback/toast/tng-toast.component.js +111 -0
  30. package/src/lib/feedback/toast/tng-toast.component.js.map +1 -0
  31. package/src/lib/form/autocomplete/tng-autocomplete.component.d.ts +26 -0
  32. package/src/lib/form/autocomplete/tng-autocomplete.component.d.ts.map +1 -0
  33. package/src/lib/form/autocomplete/tng-autocomplete.component.js +104 -0
  34. package/src/lib/form/autocomplete/tng-autocomplete.component.js.map +1 -0
  35. package/src/lib/form/button-toggle/tng-button-toggle-group.component.d.ts +44 -0
  36. package/src/lib/form/button-toggle/tng-button-toggle-group.component.d.ts.map +1 -0
  37. package/src/lib/form/button-toggle/tng-button-toggle-group.component.js +123 -0
  38. package/src/lib/form/button-toggle/tng-button-toggle-group.component.js.map +1 -0
  39. package/src/lib/form/button-toggle/tng-button-toggle.component.d.ts +14 -0
  40. package/src/lib/form/button-toggle/tng-button-toggle.component.d.ts.map +1 -0
  41. package/src/lib/form/button-toggle/tng-button-toggle.component.js +65 -0
  42. package/src/lib/form/button-toggle/tng-button-toggle.component.js.map +1 -0
  43. package/src/lib/form/checkbox/tng-checkbox.component.d.ts +38 -0
  44. package/src/lib/form/checkbox/tng-checkbox.component.d.ts.map +1 -0
  45. package/src/lib/form/checkbox/tng-checkbox.component.js +138 -0
  46. package/src/lib/form/checkbox/tng-checkbox.component.js.map +1 -0
  47. package/src/lib/form/chips/tng-chips.component.d.ts +4 -0
  48. package/src/lib/form/chips/tng-chips.component.d.ts.map +1 -0
  49. package/src/lib/form/chips/tng-chips.component.js +16 -0
  50. package/src/lib/form/chips/tng-chips.component.js.map +1 -0
  51. package/src/lib/form/combobox/tng-combobox.component.d.ts +4 -0
  52. package/src/lib/form/combobox/tng-combobox.component.d.ts.map +1 -0
  53. package/src/lib/form/combobox/tng-combobox.component.js +16 -0
  54. package/src/lib/form/combobox/tng-combobox.component.js.map +1 -0
  55. package/src/lib/form/index.d.ts +37 -0
  56. package/src/lib/form/index.d.ts.map +1 -0
  57. package/src/lib/form/index.js +37 -0
  58. package/src/lib/form/index.js.map +1 -0
  59. package/src/lib/form/input/tng-input.component.d.ts +16 -0
  60. package/src/lib/form/input/tng-input.component.d.ts.map +1 -0
  61. package/src/lib/form/input/tng-input.component.js +52 -0
  62. package/src/lib/form/input/tng-input.component.js.map +1 -0
  63. package/src/lib/form/input-otp/tng-input-otp.component.d.ts +13 -0
  64. package/src/lib/form/input-otp/tng-input-otp.component.d.ts.map +1 -0
  65. package/src/lib/form/input-otp/tng-input-otp.component.js +138 -0
  66. package/src/lib/form/input-otp/tng-input-otp.component.js.map +1 -0
  67. package/src/lib/form/label/tng-label.component.d.ts +8 -0
  68. package/src/lib/form/label/tng-label.component.d.ts.map +1 -0
  69. package/src/lib/form/label/tng-label.component.js +29 -0
  70. package/src/lib/form/label/tng-label.component.js.map +1 -0
  71. package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.component.d.ts +55 -0
  72. package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.component.d.ts.map +1 -0
  73. package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.component.js +126 -0
  74. package/src/lib/form/multi-autocomplete/tng-multi-autocomplete.component.js.map +1 -0
  75. package/src/lib/form/multiselect/tng-multiselect.component.d.ts +49 -0
  76. package/src/lib/form/multiselect/tng-multiselect.component.d.ts.map +1 -0
  77. package/src/lib/form/multiselect/tng-multiselect.component.js +112 -0
  78. package/src/lib/form/multiselect/tng-multiselect.component.js.map +1 -0
  79. package/src/lib/form/radio/tng-radio.component.d.ts +12 -0
  80. package/src/lib/form/radio/tng-radio.component.d.ts.map +1 -0
  81. package/src/lib/form/radio/tng-radio.component.js +45 -0
  82. package/src/lib/form/radio/tng-radio.component.js.map +1 -0
  83. package/src/lib/form/select/tng-select.component.d.ts +40 -0
  84. package/src/lib/form/select/tng-select.component.d.ts.map +1 -0
  85. package/src/lib/form/select/tng-select.component.js +98 -0
  86. package/src/lib/form/select/tng-select.component.js.map +1 -0
  87. package/src/lib/form/select/tng-select.slots.d.ts +25 -0
  88. package/src/lib/form/select/tng-select.slots.d.ts.map +1 -0
  89. package/src/lib/form/select/tng-select.slots.js +23 -0
  90. package/src/lib/form/select/tng-select.slots.js.map +1 -0
  91. package/src/lib/form/slider/tng-slider.component.d.ts +11 -0
  92. package/src/lib/form/slider/tng-slider.component.d.ts.map +1 -0
  93. package/src/lib/form/slider/tng-slider.component.js +48 -0
  94. package/src/lib/form/slider/tng-slider.component.js.map +1 -0
  95. package/src/lib/form/switch/tng-switch.component.d.ts +18 -0
  96. package/src/lib/form/switch/tng-switch.component.d.ts.map +1 -0
  97. package/src/lib/form/switch/tng-switch.component.js +57 -0
  98. package/src/lib/form/switch/tng-switch.component.js.map +1 -0
  99. package/src/lib/form/textarea/tng-textarea.component.d.ts +17 -0
  100. package/src/lib/form/textarea/tng-textarea.component.d.ts.map +1 -0
  101. package/src/lib/form/textarea/tng-textarea.component.js +54 -0
  102. package/src/lib/form/textarea/tng-textarea.component.js.map +1 -0
  103. package/src/lib/form/toggle/tng-toggle.component.d.ts +39 -0
  104. package/src/lib/form/toggle/tng-toggle.component.d.ts.map +1 -0
  105. package/src/lib/form/toggle/tng-toggle.component.js +152 -0
  106. package/src/lib/form/toggle/tng-toggle.component.js.map +1 -0
  107. package/src/lib/form/toggle-group/tng-toggle-group.component.d.ts +3 -0
  108. package/src/lib/form/toggle-group/tng-toggle-group.component.d.ts.map +1 -0
  109. package/src/lib/form/toggle-group/tng-toggle-group.component.js +34 -0
  110. package/src/lib/form/toggle-group/tng-toggle-group.component.js.map +1 -0
  111. package/src/lib/layout/accordion/tng-accordion.component.d.ts +11 -0
  112. package/src/lib/layout/accordion/tng-accordion.component.d.ts.map +1 -0
  113. package/src/lib/layout/accordion/tng-accordion.component.js +158 -0
  114. package/src/lib/layout/accordion/tng-accordion.component.js.map +1 -0
  115. package/src/lib/layout/bottom-sheet/tng-bottom-sheet.component.d.ts +4 -0
  116. package/src/lib/layout/bottom-sheet/tng-bottom-sheet.component.d.ts.map +1 -0
  117. package/src/lib/layout/bottom-sheet/tng-bottom-sheet.component.js +16 -0
  118. package/src/lib/layout/bottom-sheet/tng-bottom-sheet.component.js.map +1 -0
  119. package/src/lib/layout/card/tng-card.component.d.ts +42 -0
  120. package/src/lib/layout/card/tng-card.component.d.ts.map +1 -0
  121. package/src/lib/layout/card/tng-card.component.js +186 -0
  122. package/src/lib/layout/card/tng-card.component.js.map +1 -0
  123. package/src/lib/layout/collapsible/tng-collapsible.component.d.ts +11 -0
  124. package/src/lib/layout/collapsible/tng-collapsible.component.d.ts.map +1 -0
  125. package/src/lib/layout/collapsible/tng-collapsible.component.js +40 -0
  126. package/src/lib/layout/collapsible/tng-collapsible.component.js.map +1 -0
  127. package/src/lib/layout/drawer/tng-drawer.component.d.ts +12 -0
  128. package/src/lib/layout/drawer/tng-drawer.component.d.ts.map +1 -0
  129. package/src/lib/layout/drawer/tng-drawer.component.js +77 -0
  130. package/src/lib/layout/drawer/tng-drawer.component.js.map +1 -0
  131. package/src/lib/layout/grid/tng-grid.component.d.ts +4 -0
  132. package/src/lib/layout/grid/tng-grid.component.d.ts.map +1 -0
  133. package/src/lib/layout/grid/tng-grid.component.js +16 -0
  134. package/src/lib/layout/grid/tng-grid.component.js.map +1 -0
  135. package/src/lib/layout/index.d.ts +16 -0
  136. package/src/lib/layout/index.d.ts.map +1 -0
  137. package/src/lib/layout/index.js +16 -0
  138. package/src/lib/layout/index.js.map +1 -0
  139. package/src/lib/layout/separator/tng-separator.component.d.ts +6 -0
  140. package/src/lib/layout/separator/tng-separator.component.d.ts.map +1 -0
  141. package/src/lib/layout/separator/tng-separator.component.js +19 -0
  142. package/src/lib/layout/separator/tng-separator.component.js.map +1 -0
  143. package/src/lib/layout/stepper/tng-stepper.component.d.ts +4 -0
  144. package/src/lib/layout/stepper/tng-stepper.component.d.ts.map +1 -0
  145. package/src/lib/layout/stepper/tng-stepper.component.js +16 -0
  146. package/src/lib/layout/stepper/tng-stepper.component.js.map +1 -0
  147. package/src/lib/navigation/breadcrumb/tng-breadcrumb-item.component.d.ts +28 -0
  148. package/src/lib/navigation/breadcrumb/tng-breadcrumb-item.component.d.ts.map +1 -0
  149. package/src/lib/navigation/breadcrumb/tng-breadcrumb-item.component.js +86 -0
  150. package/src/lib/navigation/breadcrumb/tng-breadcrumb-item.component.js.map +1 -0
  151. package/src/lib/navigation/breadcrumb/tng-breadcrumb-link.component.d.ts +10 -0
  152. package/src/lib/navigation/breadcrumb/tng-breadcrumb-link.component.d.ts.map +1 -0
  153. package/src/lib/navigation/breadcrumb/tng-breadcrumb-link.component.js +29 -0
  154. package/src/lib/navigation/breadcrumb/tng-breadcrumb-link.component.js.map +1 -0
  155. package/src/lib/navigation/breadcrumb/tng-breadcrumb-list.component.d.ts +3 -0
  156. package/src/lib/navigation/breadcrumb/tng-breadcrumb-list.component.d.ts.map +1 -0
  157. package/src/lib/navigation/breadcrumb/tng-breadcrumb-list.component.js +15 -0
  158. package/src/lib/navigation/breadcrumb/tng-breadcrumb-list.component.js.map +1 -0
  159. package/src/lib/navigation/breadcrumb/tng-breadcrumb-separator-template.directive.d.ts +6 -0
  160. package/src/lib/navigation/breadcrumb/tng-breadcrumb-separator-template.directive.d.ts.map +1 -0
  161. package/src/lib/navigation/breadcrumb/tng-breadcrumb-separator-template.directive.js +16 -0
  162. package/src/lib/navigation/breadcrumb/tng-breadcrumb-separator-template.directive.js.map +1 -0
  163. package/src/lib/navigation/breadcrumb/tng-breadcrumb-separator.component.d.ts +6 -0
  164. package/src/lib/navigation/breadcrumb/tng-breadcrumb-separator.component.d.ts.map +1 -0
  165. package/src/lib/navigation/breadcrumb/tng-breadcrumb-separator.component.js +18 -0
  166. package/src/lib/navigation/breadcrumb/tng-breadcrumb-separator.component.js.map +1 -0
  167. package/src/lib/navigation/breadcrumb/tng-breadcrumb.component.d.ts +23 -0
  168. package/src/lib/navigation/breadcrumb/tng-breadcrumb.component.d.ts.map +1 -0
  169. package/src/lib/navigation/breadcrumb/tng-breadcrumb.component.js +155 -0
  170. package/src/lib/navigation/breadcrumb/tng-breadcrumb.component.js.map +1 -0
  171. package/src/lib/navigation/context-menu/tng-context-menu.component.d.ts +4 -0
  172. package/src/lib/navigation/context-menu/tng-context-menu.component.d.ts.map +1 -0
  173. package/src/lib/navigation/context-menu/tng-context-menu.component.js +16 -0
  174. package/src/lib/navigation/context-menu/tng-context-menu.component.js.map +1 -0
  175. package/src/lib/navigation/dropdown-menu/tng-dropdown-menu.component.d.ts +10 -0
  176. package/src/lib/navigation/dropdown-menu/tng-dropdown-menu.component.d.ts.map +1 -0
  177. package/src/lib/navigation/dropdown-menu/tng-dropdown-menu.component.js +54 -0
  178. package/src/lib/navigation/dropdown-menu/tng-dropdown-menu.component.js.map +1 -0
  179. package/src/lib/navigation/index.d.ts +27 -0
  180. package/src/lib/navigation/index.d.ts.map +1 -0
  181. package/src/lib/navigation/index.js +27 -0
  182. package/src/lib/navigation/index.js.map +1 -0
  183. package/src/lib/navigation/menu/tng-menu-trigger-for.directive.d.ts +15 -0
  184. package/src/lib/navigation/menu/tng-menu-trigger-for.directive.d.ts.map +1 -0
  185. package/src/lib/navigation/menu/tng-menu-trigger-for.directive.js +85 -0
  186. package/src/lib/navigation/menu/tng-menu-trigger-for.directive.js.map +1 -0
  187. package/src/lib/navigation/menu/tng-menu.component.d.ts +13 -0
  188. package/src/lib/navigation/menu/tng-menu.component.d.ts.map +1 -0
  189. package/src/lib/navigation/menu/tng-menu.component.js +92 -0
  190. package/src/lib/navigation/menu/tng-menu.component.js.map +1 -0
  191. package/src/lib/navigation/menubar/tng-menubar.component.d.ts +5 -0
  192. package/src/lib/navigation/menubar/tng-menubar.component.d.ts.map +1 -0
  193. package/src/lib/navigation/menubar/tng-menubar.component.js +29 -0
  194. package/src/lib/navigation/menubar/tng-menubar.component.js.map +1 -0
  195. package/src/lib/navigation/navigation-menu/tng-navigation-menu.component.d.ts +4 -0
  196. package/src/lib/navigation/navigation-menu/tng-navigation-menu.component.d.ts.map +1 -0
  197. package/src/lib/navigation/navigation-menu/tng-navigation-menu.component.js +16 -0
  198. package/src/lib/navigation/navigation-menu/tng-navigation-menu.component.js.map +1 -0
  199. package/src/lib/navigation/tabs/tng-tabs.component.d.ts +5 -0
  200. package/src/lib/navigation/tabs/tng-tabs.component.d.ts.map +1 -0
  201. package/src/lib/navigation/tabs/tng-tabs.component.js +41 -0
  202. package/src/lib/navigation/tabs/tng-tabs.component.js.map +1 -0
  203. package/src/lib/navigation/toolbar/tng-toolbar.component.d.ts +4 -0
  204. package/src/lib/navigation/toolbar/tng-toolbar.component.d.ts.map +1 -0
  205. package/src/lib/navigation/toolbar/tng-toolbar.component.js +16 -0
  206. package/src/lib/navigation/toolbar/tng-toolbar.component.js.map +1 -0
  207. package/src/lib/overlay/dialog/tng-dialog.component.d.ts +43 -0
  208. package/src/lib/overlay/dialog/tng-dialog.component.d.ts.map +1 -0
  209. package/src/lib/overlay/dialog/tng-dialog.component.js +286 -0
  210. package/src/lib/overlay/dialog/tng-dialog.component.js.map +1 -0
  211. package/src/lib/overlay/index.d.ts +7 -0
  212. package/src/lib/overlay/index.d.ts.map +1 -0
  213. package/src/lib/overlay/index.js +7 -0
  214. package/src/lib/overlay/index.js.map +1 -0
  215. package/src/lib/overlay/popover/tng-popover.component.d.ts +28 -0
  216. package/src/lib/overlay/popover/tng-popover.component.d.ts.map +1 -0
  217. package/src/lib/overlay/popover/tng-popover.component.js +133 -0
  218. package/src/lib/overlay/popover/tng-popover.component.js.map +1 -0
  219. package/src/lib/overlay/tng-overlay-runtime.d.ts +11 -0
  220. package/src/lib/overlay/tng-overlay-runtime.d.ts.map +1 -0
  221. package/src/lib/overlay/tng-overlay-runtime.js +11 -0
  222. package/src/lib/overlay/tng-overlay-runtime.js.map +1 -0
  223. package/src/lib/overlay/tooltip/tng-tooltip.component.d.ts +31 -0
  224. package/src/lib/overlay/tooltip/tng-tooltip.component.d.ts.map +1 -0
  225. package/src/lib/overlay/tooltip/tng-tooltip.component.js +111 -0
  226. package/src/lib/overlay/tooltip/tng-tooltip.component.js.map +1 -0
  227. package/src/lib/utility/avatar/tng-avatar.component.d.ts +19 -0
  228. package/src/lib/utility/avatar/tng-avatar.component.d.ts.map +1 -0
  229. package/src/lib/utility/avatar/tng-avatar.component.js +66 -0
  230. package/src/lib/utility/avatar/tng-avatar.component.js.map +1 -0
  231. package/src/lib/utility/badge/tng-badge.component.d.ts +4 -0
  232. package/src/lib/utility/badge/tng-badge.component.d.ts.map +1 -0
  233. package/src/lib/utility/badge/tng-badge.component.js +13 -0
  234. package/src/lib/utility/badge/tng-badge.component.js.map +1 -0
  235. package/src/lib/utility/button/tng-button.component.d.ts +18 -0
  236. package/src/lib/utility/button/tng-button.component.d.ts.map +1 -0
  237. package/src/lib/utility/button/tng-button.component.js +32 -0
  238. package/src/lib/utility/button/tng-button.component.js.map +1 -0
  239. package/src/lib/utility/code-block/highlighting.d.ts +96 -0
  240. package/src/lib/utility/code-block/highlighting.d.ts.map +1 -0
  241. package/src/lib/utility/code-block/highlighting.js +220 -0
  242. package/src/lib/utility/code-block/highlighting.js.map +1 -0
  243. package/src/lib/utility/code-block/tng-code-block.component.d.ts +118 -0
  244. package/src/lib/utility/code-block/tng-code-block.component.d.ts.map +1 -0
  245. package/src/lib/utility/code-block/tng-code-block.component.js +586 -0
  246. package/src/lib/utility/code-block/tng-code-block.component.js.map +1 -0
  247. package/src/lib/utility/copy-button/tng-copy-button.component.d.ts +39 -0
  248. package/src/lib/utility/copy-button/tng-copy-button.component.d.ts.map +1 -0
  249. package/src/lib/utility/copy-button/tng-copy-button.component.js +127 -0
  250. package/src/lib/utility/copy-button/tng-copy-button.component.js.map +1 -0
  251. package/src/lib/utility/index.d.ts +17 -0
  252. package/src/lib/utility/index.d.ts.map +1 -0
  253. package/src/lib/utility/index.js +16 -0
  254. package/src/lib/utility/index.js.map +1 -0
  255. package/src/lib/utility/tag/tng-tag.component.d.ts +10 -0
  256. package/src/lib/utility/tag/tng-tag.component.d.ts.map +1 -0
  257. package/src/lib/utility/tag/tng-tag.component.js +18 -0
  258. package/src/lib/utility/tag/tng-tag.component.js.map +1 -0
  259. package/src/lib/utility/tree/tng-tree.component.d.ts +72 -0
  260. package/src/lib/utility/tree/tng-tree.component.d.ts.map +1 -0
  261. package/src/lib/utility/tree/tng-tree.component.js +336 -0
  262. package/src/lib/utility/tree/tng-tree.component.js.map +1 -0
  263. package/src/test-setup.d.ts +3 -0
  264. package/src/test-setup.d.ts.map +1 -0
  265. package/src/test-setup.js +10 -0
  266. package/src/test-setup.js.map +1 -0
@@ -0,0 +1,586 @@
1
+ import { __decorate } from "tslib";
2
+ import { booleanAttribute, Component, computed, effect, inject, input, output, signal, } from '@angular/core';
3
+ import { DomSanitizer } from '@angular/platform-browser';
4
+ import { TngCodeBlock as TngCodeBlockPrimitive, TngCodeBlockBody as TngCodeBlockBodyPrimitive, TngCodeBlockCode as TngCodeBlockCodePrimitive, TngCodeBlockGutter as TngCodeBlockGutterPrimitive, TngCodeBlockHeader as TngCodeBlockHeaderPrimitive, TngCopy, } from '@tailng-ui/primitives';
5
+ import { escapeTngCodeHtml, normalizeTngCodeLanguage, resolveTngCodeHighlightResult, TNG_CODE_HIGHLIGHTING_CONFIG, } from './highlighting';
6
+ const defaultCopyResetDuration = 1500;
7
+ const highlightModeSet = new Set(['auto', 'off', 'on']);
8
+ function normalizeOptionalString(value) {
9
+ if (value === null || value === undefined) {
10
+ return null;
11
+ }
12
+ const normalized = value.trim();
13
+ return normalized.length > 0 ? normalized : null;
14
+ }
15
+ function toRoundedPositiveNumber(value) {
16
+ return Math.max(0, Math.round(value));
17
+ }
18
+ function coerceOptionalBoolean(value) {
19
+ if (value === undefined || value === null) {
20
+ return undefined;
21
+ }
22
+ return booleanAttribute(value);
23
+ }
24
+ function coercePositiveInteger(value, fallback) {
25
+ const numericValue = typeof value === 'number' ? value : Number(value);
26
+ if (!Number.isFinite(numericValue)) {
27
+ return fallback;
28
+ }
29
+ return Math.max(1, Math.round(numericValue));
30
+ }
31
+ function coerceOptionalPositiveNumber(value) {
32
+ if (value === undefined) {
33
+ return undefined;
34
+ }
35
+ const numericValue = typeof value === 'number' ? value : Number(value);
36
+ if (!Number.isFinite(numericValue)) {
37
+ return undefined;
38
+ }
39
+ return toRoundedPositiveNumber(numericValue);
40
+ }
41
+ function coerceTngCodeBlockCopyMode(value) {
42
+ if (value === 'auto' || value === undefined || value === null) {
43
+ return 'auto';
44
+ }
45
+ if (value === '' || value === true || value === 'true') {
46
+ return true;
47
+ }
48
+ if (value === false || value === 'false') {
49
+ return false;
50
+ }
51
+ return 'auto';
52
+ }
53
+ function coerceTngCodeBlockLineNumbersMode(value) {
54
+ if (value === 'auto') {
55
+ return 'auto';
56
+ }
57
+ if (value === undefined || value === null) {
58
+ return false;
59
+ }
60
+ if (value === '' || value === true || value === 'true') {
61
+ return true;
62
+ }
63
+ if (value === false || value === 'false') {
64
+ return false;
65
+ }
66
+ return false;
67
+ }
68
+ function coerceTngCodeBlockSanitizeHtml(value) {
69
+ if (value === undefined || value === null || value === 'auto') {
70
+ return 'auto';
71
+ }
72
+ if (value === '' || value === true || value === 'true') {
73
+ return true;
74
+ }
75
+ if (value === false || value === 'false') {
76
+ return false;
77
+ }
78
+ return 'auto';
79
+ }
80
+ function normalizeHighlightLineNumber(value) {
81
+ if (!Number.isFinite(value)) {
82
+ return null;
83
+ }
84
+ const normalized = Math.round(value);
85
+ return normalized > 0 ? normalized : null;
86
+ }
87
+ function toNormalizedHighlightLineSet(value) {
88
+ if (value === undefined || value === null || value.length === 0) {
89
+ return new Set();
90
+ }
91
+ const normalizedValues = new Set();
92
+ for (const entry of value) {
93
+ if (typeof entry === 'number') {
94
+ const normalized = normalizeHighlightLineNumber(entry);
95
+ if (normalized !== null) {
96
+ normalizedValues.add(normalized);
97
+ }
98
+ continue;
99
+ }
100
+ const [start, end] = entry;
101
+ const normalizedStart = normalizeHighlightLineNumber(start);
102
+ const normalizedEnd = normalizeHighlightLineNumber(end);
103
+ if (normalizedStart === null || normalizedEnd === null) {
104
+ continue;
105
+ }
106
+ const from = Math.min(normalizedStart, normalizedEnd);
107
+ const to = Math.max(normalizedStart, normalizedEnd);
108
+ for (let current = from; current <= to; current += 1) {
109
+ normalizedValues.add(current);
110
+ }
111
+ }
112
+ return normalizedValues;
113
+ }
114
+ function tokenClassNameToAttributeValue(className) {
115
+ if (className === null || className === undefined) {
116
+ return '';
117
+ }
118
+ return className
119
+ .trim()
120
+ .split(/\s+/)
121
+ .filter((token) => token.length > 0)
122
+ .join(' ');
123
+ }
124
+ function renderToken(token) {
125
+ const escapedContent = escapeTngCodeHtml(token.content);
126
+ const normalizedClassName = tokenClassNameToAttributeValue(token.className);
127
+ if (normalizedClassName.length === 0) {
128
+ return escapedContent;
129
+ }
130
+ return `<span class="${escapeTngCodeHtml(normalizedClassName)}">${escapedContent}</span>`;
131
+ }
132
+ function renderTokenLine(line) {
133
+ return line.map((token) => renderToken(token)).join('');
134
+ }
135
+ function splitCodeLines(code) {
136
+ if (code.length === 0) {
137
+ return [''];
138
+ }
139
+ const lines = code.split('\n');
140
+ if (lines.length > 1 && lines[lines.length - 1] === '') {
141
+ lines.pop();
142
+ }
143
+ return lines;
144
+ }
145
+ function toNormalizedCopyError(value) {
146
+ if (value instanceof Error) {
147
+ return value;
148
+ }
149
+ if (typeof value === 'object' && value !== null && 'error' in value) {
150
+ const nestedError = value.error;
151
+ if (nestedError instanceof Error) {
152
+ return nestedError;
153
+ }
154
+ }
155
+ return new Error('Copy failed.');
156
+ }
157
+ function toCssSizeValue(value) {
158
+ if (value === undefined || value === null) {
159
+ return null;
160
+ }
161
+ if (typeof value === 'number') {
162
+ if (!Number.isFinite(value)) {
163
+ return null;
164
+ }
165
+ return `${Math.max(0, value)}px`;
166
+ }
167
+ const normalized = value.trim();
168
+ return normalized.length > 0 ? normalized : null;
169
+ }
170
+ function shouldHighlight(mode) {
171
+ return mode === 'auto' || mode === 'on';
172
+ }
173
+ export function coerceTngCodeBlockHighlightMode(value) {
174
+ if (highlightModeSet.has(value)) {
175
+ return value;
176
+ }
177
+ return 'auto';
178
+ }
179
+ export function coerceTngCodeBlockCopyResetDuration(value) {
180
+ const numericValue = typeof value === 'number' ? value : Number(value);
181
+ if (!Number.isFinite(numericValue)) {
182
+ return defaultCopyResetDuration;
183
+ }
184
+ return toRoundedPositiveNumber(numericValue);
185
+ }
186
+ export function coerceTngCodeBlockStartingLineNumber(value) {
187
+ return coercePositiveInteger(value, 1);
188
+ }
189
+ export function normalizeTngCodeBlockCode(value) {
190
+ if (value === null || value === undefined) {
191
+ return '';
192
+ }
193
+ return value.replace(/\r\n?/g, '\n');
194
+ }
195
+ export function toTngCodeBlockLineNumbers(code, startingLineNumber = 1) {
196
+ const normalizedStart = Math.max(1, Math.round(startingLineNumber));
197
+ return splitCodeLines(code).map((_, index) => normalizedStart + index);
198
+ }
199
+ let TngCodeBlockComponent = class TngCodeBlockComponent {
200
+ adapter = input(null);
201
+ caption = input(null);
202
+ code = input('');
203
+ copyMode = input('auto', {
204
+ alias: 'copy',
205
+ transform: coerceTngCodeBlockCopyMode,
206
+ });
207
+ copyLabel = input('Copy code');
208
+ copiedLabel = input('Copied');
209
+ copyResetDuration = input(defaultCopyResetDuration, {
210
+ transform: coerceTngCodeBlockCopyResetDuration,
211
+ });
212
+ copySuccessDurationMs = input(undefined, {
213
+ transform: coerceOptionalPositiveNumber,
214
+ });
215
+ copyText = input(null);
216
+ errorLabel = input('Copy failed');
217
+ focusLines = input(false, {
218
+ transform: booleanAttribute,
219
+ });
220
+ highlight = input(true, {
221
+ transform: booleanAttribute,
222
+ });
223
+ highlightDebounceMs = input(0, {
224
+ transform: coerceTngCodeBlockCopyResetDuration,
225
+ });
226
+ highlightLines = input(null);
227
+ highlightMode = input('auto', {
228
+ transform: coerceTngCodeBlockHighlightMode,
229
+ });
230
+ language = input(null);
231
+ lineNumbersMode = input(false, {
232
+ alias: 'lineNumbers',
233
+ transform: coerceTngCodeBlockLineNumbersMode,
234
+ });
235
+ maxHeight = input(null);
236
+ sanitizeHtml = input('auto', {
237
+ transform: coerceTngCodeBlockSanitizeHtml,
238
+ });
239
+ showHeader = input(true, {
240
+ transform: booleanAttribute,
241
+ });
242
+ showLanguageBadge = input(true, {
243
+ transform: booleanAttribute,
244
+ });
245
+ showLineNumbers = input(undefined, {
246
+ transform: coerceOptionalBoolean,
247
+ });
248
+ startingLineNumber = input(1, {
249
+ transform: coerceTngCodeBlockStartingLineNumber,
250
+ });
251
+ theme = input(null);
252
+ title = input(null);
253
+ variant = input('default');
254
+ wrap = input(false, {
255
+ transform: booleanAttribute,
256
+ });
257
+ copy = output();
258
+ copyError = output();
259
+ copySuccess = output();
260
+ renderStateChange = output();
261
+ tngCopied = output();
262
+ tngCopyError = output();
263
+ copyButtonLabel = computed(() => {
264
+ const state = this.copyState();
265
+ if (state === 'copied') {
266
+ return this.copiedLabel();
267
+ }
268
+ if (state === 'error') {
269
+ return this.errorLabel();
270
+ }
271
+ return this.copyLabel();
272
+ });
273
+ copyPayload = computed(() => {
274
+ const value = this.copyText();
275
+ if (typeof value === 'function') {
276
+ try {
277
+ return value({
278
+ code: this.normalizedCode(),
279
+ language: this.languageForBadge(),
280
+ theme: normalizeTngCodeLanguage(this.theme()),
281
+ });
282
+ }
283
+ catch {
284
+ return this.normalizedCode();
285
+ }
286
+ }
287
+ if (typeof value === 'string') {
288
+ return value;
289
+ }
290
+ return this.normalizedCode();
291
+ });
292
+ dataHasCopy = computed(() => this.shouldShowCopyAction() ? 'true' : 'false');
293
+ dataHasTitle = computed(() => this.titleText() === null ? 'false' : 'true');
294
+ dataHighlighted = computed(() => this.renderState() === 'highlighted' ? 'true' : 'false');
295
+ dataWrap = computed(() => (this.wrap() ? 'true' : 'false'));
296
+ effectiveCopyResetDuration = computed(() => {
297
+ return this.copySuccessDurationMs() ?? this.copyResetDuration();
298
+ });
299
+ effectiveLineNumbers = computed(() => {
300
+ const legacyValue = this.showLineNumbers();
301
+ if (legacyValue !== undefined) {
302
+ return legacyValue;
303
+ }
304
+ const mode = this.lineNumbersMode();
305
+ if (mode === 'auto') {
306
+ return splitCodeLines(this.normalizedCode()).length > 1;
307
+ }
308
+ return mode;
309
+ });
310
+ hasHeaderContent = computed(() => {
311
+ return this.titleText() !== null || this.hasLanguageBadge() || this.shouldShowCopyAction();
312
+ });
313
+ hasLanguageBadge = computed(() => {
314
+ return this.showLanguageBadge() && this.languageForBadge() !== null;
315
+ });
316
+ highlightLineSet = computed(() => toNormalizedHighlightLineSet(this.highlightLines()));
317
+ isHighlighting = computed(() => this.renderState() === 'highlighting');
318
+ languageForBadge = computed(() => {
319
+ return this.resolvedLanguage() ?? this.normalizedLanguage();
320
+ });
321
+ languageLabel = computed(() => {
322
+ return this.languageForBadge() ?? 'text';
323
+ });
324
+ lineNumbers = computed(() => {
325
+ return this.renderedLines().map((line) => line.lineNumber);
326
+ });
327
+ maxHeightCssValue = computed(() => toCssSizeValue(this.maxHeight()));
328
+ normalizedCode = computed(() => normalizeTngCodeBlockCode(this.code()));
329
+ renderState = signal('idle');
330
+ renderedLines = computed(() => {
331
+ const baseLines = this.baseLineHtml();
332
+ const start = this.startingLineNumber();
333
+ const highlightSet = this.highlightLineSet();
334
+ const shouldDim = this.focusLines() && highlightSet.size > 0;
335
+ return baseLines.map((html, index) => {
336
+ const lineNumber = start + index;
337
+ const highlighted = highlightSet.has(lineNumber);
338
+ return {
339
+ dimmed: shouldDim && !highlighted,
340
+ highlighted,
341
+ html,
342
+ lineNumber,
343
+ };
344
+ });
345
+ });
346
+ shouldRenderBodyLineNumbers = computed(() => this.effectiveLineNumbers());
347
+ shouldRenderHeader = computed(() => {
348
+ return this.showHeader() && this.hasHeaderContent();
349
+ });
350
+ shouldShowCopyAction = computed(() => {
351
+ const mode = this.copyMode();
352
+ if (mode === 'auto') {
353
+ return this.normalizedCode().length > 0;
354
+ }
355
+ return mode;
356
+ });
357
+ titleText = computed(() => normalizeOptionalString(this.title()));
358
+ baseLineHtml = signal(['']);
359
+ copyState = signal('idle');
360
+ domSanitizer = inject(DomSanitizer);
361
+ highlightingConfig = inject(TNG_CODE_HIGHLIGHTING_CONFIG);
362
+ normalizedLanguage = computed(() => normalizeTngCodeLanguage(this.language()));
363
+ resolvedLanguage = signal(null);
364
+ copyResetTimer = null;
365
+ destroyed = false;
366
+ highlightDebounceTimer = null;
367
+ highlightRequestId = 0;
368
+ lastEmittedRenderState = 'idle';
369
+ renderCache = new Map();
370
+ constructor() {
371
+ effect(() => {
372
+ const request = {
373
+ adapter: normalizeTngCodeLanguage(this.adapter()),
374
+ code: this.normalizedCode(),
375
+ includeLineWrappers: this.shouldIncludeLineWrappers(),
376
+ language: this.normalizedLanguage(),
377
+ theme: normalizeTngCodeLanguage(this.theme()),
378
+ };
379
+ this.enqueueRenderRequest({
380
+ request,
381
+ shouldHighlight: this.shouldHighlightCode(),
382
+ });
383
+ });
384
+ }
385
+ ngOnDestroy() {
386
+ this.destroyed = true;
387
+ this.highlightRequestId += 1;
388
+ this.clearCopyResetTimer();
389
+ this.clearHighlightDebounceTimer();
390
+ }
391
+ onPrimitiveCopy(...args) {
392
+ const [event] = args;
393
+ if (typeof event === 'object' &&
394
+ event !== null &&
395
+ 'text' in event &&
396
+ 'trigger' in event &&
397
+ typeof event.text === 'string' &&
398
+ typeof event.trigger === 'string') {
399
+ this.copy.emit(event);
400
+ }
401
+ }
402
+ onPrimitiveCopyError(...args) {
403
+ const [event] = args;
404
+ const normalizedError = toNormalizedCopyError(event);
405
+ this.copyState.set('error');
406
+ this.tngCopyError.emit(normalizedError);
407
+ if (typeof event === 'object' && event !== null && 'error' in event) {
408
+ this.copyError.emit(event);
409
+ }
410
+ else {
411
+ this.copyError.emit({ error: normalizedError });
412
+ }
413
+ this.scheduleCopyStateReset();
414
+ }
415
+ onPrimitiveCopySuccess(...args) {
416
+ const [event] = args;
417
+ if (typeof event !== 'object' ||
418
+ event === null ||
419
+ !('text' in event) ||
420
+ !('method' in event) ||
421
+ typeof event.text !== 'string' ||
422
+ typeof event.method !== 'string') {
423
+ return;
424
+ }
425
+ const payload = event;
426
+ this.copyState.set('copied');
427
+ this.copySuccess.emit(payload);
428
+ this.tngCopied.emit(payload.text);
429
+ this.scheduleCopyStateReset();
430
+ }
431
+ applyPlainText(code, language) {
432
+ this.resolvedLanguage.set(language);
433
+ this.baseLineHtml.set(splitCodeLines(code).map((line) => escapeTngCodeHtml(line)));
434
+ }
435
+ applyResolvedHighlightResult(result, request) {
436
+ this.resolvedLanguage.set(result.language ?? request.language);
437
+ if (result.kind === 'tokens') {
438
+ if (result.tokens.length === 0) {
439
+ return false;
440
+ }
441
+ this.baseLineHtml.set(result.tokens.map((line) => renderTokenLine(line)));
442
+ return true;
443
+ }
444
+ const htmlLines = result.html.split('\n');
445
+ if (htmlLines.length === 0 || (htmlLines.length === 1 && htmlLines[0].length === 0)) {
446
+ return false;
447
+ }
448
+ const shouldBypassSanitization = this.sanitizeHtml() === false && result.trustedHtml;
449
+ if (shouldBypassSanitization) {
450
+ this.baseLineHtml.set(htmlLines.map((line) => this.domSanitizer.bypassSecurityTrustHtml(line)));
451
+ return true;
452
+ }
453
+ this.baseLineHtml.set(htmlLines);
454
+ return true;
455
+ }
456
+ buildCacheKey(request) {
457
+ return [
458
+ request.adapter ?? '',
459
+ request.language ?? '',
460
+ request.theme ?? '',
461
+ request.includeLineWrappers ? '1' : '0',
462
+ request.code,
463
+ ].join('\u241f');
464
+ }
465
+ clearCopyResetTimer() {
466
+ if (this.copyResetTimer === null) {
467
+ return;
468
+ }
469
+ clearTimeout(this.copyResetTimer);
470
+ this.copyResetTimer = null;
471
+ }
472
+ clearHighlightDebounceTimer() {
473
+ if (this.highlightDebounceTimer === null) {
474
+ return;
475
+ }
476
+ clearTimeout(this.highlightDebounceTimer);
477
+ this.highlightDebounceTimer = null;
478
+ }
479
+ enqueueRenderRequest(input) {
480
+ this.clearHighlightDebounceTimer();
481
+ const debounceMs = this.highlightDebounceMs();
482
+ if (debounceMs <= 0) {
483
+ void this.renderRequest(input);
484
+ return;
485
+ }
486
+ this.highlightDebounceTimer = setTimeout(() => {
487
+ this.highlightDebounceTimer = null;
488
+ void this.renderRequest(input);
489
+ }, debounceMs);
490
+ }
491
+ isStaleRequest(requestId) {
492
+ return this.destroyed || requestId !== this.highlightRequestId;
493
+ }
494
+ scheduleCopyStateReset() {
495
+ this.clearCopyResetTimer();
496
+ this.copyResetTimer = setTimeout(() => {
497
+ this.copyState.set('idle');
498
+ this.copyResetTimer = null;
499
+ }, this.effectiveCopyResetDuration());
500
+ }
501
+ setRenderState(state, error) {
502
+ this.renderState.set(state);
503
+ if (this.lastEmittedRenderState === state) {
504
+ return;
505
+ }
506
+ this.lastEmittedRenderState = state;
507
+ if (state === 'error') {
508
+ this.renderStateChange.emit({ error, state });
509
+ return;
510
+ }
511
+ this.renderStateChange.emit({ state });
512
+ }
513
+ shouldHighlightCode() {
514
+ if (!this.highlight()) {
515
+ return false;
516
+ }
517
+ return shouldHighlight(this.highlightMode());
518
+ }
519
+ shouldIncludeLineWrappers() {
520
+ return this.effectiveLineNumbers() || this.highlightLineSet().size > 0 || this.focusLines();
521
+ }
522
+ toHighlightRequest(request) {
523
+ return {
524
+ adapter: request.adapter,
525
+ code: request.code,
526
+ includeLineWrappers: request.includeLineWrappers,
527
+ language: request.language,
528
+ theme: request.theme,
529
+ };
530
+ }
531
+ async renderRequest(input) {
532
+ const requestId = this.highlightRequestId + 1;
533
+ this.highlightRequestId = requestId;
534
+ if (!input.shouldHighlight) {
535
+ this.applyPlainText(input.request.code, input.request.language);
536
+ this.setRenderState('idle');
537
+ return;
538
+ }
539
+ this.setRenderState('highlighting');
540
+ try {
541
+ const cacheKey = this.buildCacheKey(input.request);
542
+ let resolvedResult = this.renderCache.get(cacheKey);
543
+ if (resolvedResult === undefined) {
544
+ resolvedResult = await resolveTngCodeHighlightResult(this.toHighlightRequest(input.request), this.highlightingConfig);
545
+ this.renderCache.set(cacheKey, resolvedResult);
546
+ }
547
+ if (this.isStaleRequest(requestId)) {
548
+ return;
549
+ }
550
+ if (resolvedResult === null) {
551
+ this.applyPlainText(input.request.code, input.request.language);
552
+ this.setRenderState('highlighted');
553
+ return;
554
+ }
555
+ const didRenderHighlight = this.applyResolvedHighlightResult(resolvedResult, input.request);
556
+ if (!didRenderHighlight) {
557
+ this.applyPlainText(input.request.code, input.request.language);
558
+ }
559
+ this.setRenderState('highlighted');
560
+ }
561
+ catch (error) {
562
+ if (this.isStaleRequest(requestId)) {
563
+ return;
564
+ }
565
+ this.applyPlainText(input.request.code, input.request.language);
566
+ this.setRenderState('error', error);
567
+ }
568
+ }
569
+ };
570
+ TngCodeBlockComponent = __decorate([
571
+ Component({
572
+ selector: 'tng-code-block',
573
+ imports: [
574
+ TngCodeBlockPrimitive,
575
+ TngCodeBlockHeaderPrimitive,
576
+ TngCodeBlockBodyPrimitive,
577
+ TngCodeBlockGutterPrimitive,
578
+ TngCodeBlockCodePrimitive,
579
+ TngCopy,
580
+ ],
581
+ templateUrl: './tng-code-block.component.html',
582
+ styleUrl: './tng-code-block.component.css',
583
+ })
584
+ ], TngCodeBlockComponent);
585
+ export { TngCodeBlockComponent };
586
+ //# sourceMappingURL=tng-code-block.component.js.map