ngwr 16.5.0 → 16.6.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 (287) hide show
  1. package/back-top/styles/_index.scss +6 -0
  2. package/breadcrumbs/styles/_rules.scss +34 -0
  3. package/cascader/styles/_rules.scss +7 -0
  4. package/charts/chart-legend/styles/_index.scss +1 -9
  5. package/counter/styles/_index.scss +1 -8
  6. package/date-picker/styles/_index.scss +15 -9
  7. package/dialog/styles/_index.scss +37 -0
  8. package/editor/styles/_index.scss +1 -8
  9. package/event-calendar/styles/_index.scss +2 -6
  10. package/fesm2022/ngwr-affix.mjs +1 -1
  11. package/fesm2022/ngwr-affix.mjs.map +1 -1
  12. package/fesm2022/ngwr-anchor.mjs +9 -2
  13. package/fesm2022/ngwr-anchor.mjs.map +1 -1
  14. package/fesm2022/ngwr-animations-aurora.mjs.map +1 -1
  15. package/fesm2022/ngwr-animations-blur-reveal.mjs.map +1 -1
  16. package/fesm2022/ngwr-animations-click-sparks.mjs.map +1 -1
  17. package/fesm2022/ngwr-animations-confetti.mjs.map +1 -1
  18. package/fesm2022/ngwr-animations-decode.mjs.map +1 -1
  19. package/fesm2022/ngwr-animations-destruct.mjs.map +1 -1
  20. package/fesm2022/ngwr-animations-dot-grid.mjs.map +1 -1
  21. package/fesm2022/ngwr-animations-falling-letters.mjs.map +1 -1
  22. package/fesm2022/ngwr-animations-flow-lines.mjs.map +1 -1
  23. package/fesm2022/ngwr-animations-fluid-cursor.mjs.map +1 -1
  24. package/fesm2022/ngwr-animations-glitch.mjs.map +1 -1
  25. package/fesm2022/ngwr-animations-glow-border.mjs.map +1 -1
  26. package/fesm2022/ngwr-animations-gradient-flow.mjs.map +1 -1
  27. package/fesm2022/ngwr-animations-marquee.mjs.map +1 -1
  28. package/fesm2022/ngwr-animations-orbit.mjs.map +1 -1
  29. package/fesm2022/ngwr-animations-reveal.mjs.map +1 -1
  30. package/fesm2022/ngwr-animations-ripple-grid.mjs.map +1 -1
  31. package/fesm2022/ngwr-animations-rotate-reveal.mjs.map +1 -1
  32. package/fesm2022/ngwr-animations-shimmer.mjs.map +1 -1
  33. package/fesm2022/ngwr-animations-spotlight.mjs.map +1 -1
  34. package/fesm2022/ngwr-animations-thread-lines.mjs.map +1 -1
  35. package/fesm2022/ngwr-animations-tilt.mjs +20 -13
  36. package/fesm2022/ngwr-animations-tilt.mjs.map +1 -1
  37. package/fesm2022/ngwr-animations-typewriter.mjs.map +1 -1
  38. package/fesm2022/ngwr-breadcrumbs.mjs +40 -7
  39. package/fesm2022/ngwr-breadcrumbs.mjs.map +1 -1
  40. package/fesm2022/ngwr-button.mjs +12 -3
  41. package/fesm2022/ngwr-button.mjs.map +1 -1
  42. package/fesm2022/ngwr-carousel.mjs +8 -2
  43. package/fesm2022/ngwr-carousel.mjs.map +1 -1
  44. package/fesm2022/ngwr-cascader.mjs +24 -4
  45. package/fesm2022/ngwr-cascader.mjs.map +1 -1
  46. package/fesm2022/ngwr-charts-core.mjs +12 -5
  47. package/fesm2022/ngwr-charts-core.mjs.map +1 -1
  48. package/fesm2022/ngwr-charts-meter-group.mjs +4 -2
  49. package/fesm2022/ngwr-charts-meter-group.mjs.map +1 -1
  50. package/fesm2022/ngwr-checkbox.mjs +3 -2
  51. package/fesm2022/ngwr-checkbox.mjs.map +1 -1
  52. package/fesm2022/ngwr-color-picker.mjs +21 -1
  53. package/fesm2022/ngwr-color-picker.mjs.map +1 -1
  54. package/fesm2022/ngwr-context-menu.mjs +4 -5
  55. package/fesm2022/ngwr-context-menu.mjs.map +1 -1
  56. package/fesm2022/ngwr-date-picker-testing.mjs.map +1 -1
  57. package/fesm2022/ngwr-date-picker.mjs +49 -1
  58. package/fesm2022/ngwr-date-picker.mjs.map +1 -1
  59. package/fesm2022/ngwr-dialog.mjs +16 -6
  60. package/fesm2022/ngwr-dialog.mjs.map +1 -1
  61. package/fesm2022/ngwr-directives.mjs +9 -6
  62. package/fesm2022/ngwr-directives.mjs.map +1 -1
  63. package/fesm2022/ngwr-event-calendar.mjs +20 -9
  64. package/fesm2022/ngwr-event-calendar.mjs.map +1 -1
  65. package/fesm2022/ngwr-form.mjs +170 -3
  66. package/fesm2022/ngwr-form.mjs.map +1 -1
  67. package/fesm2022/ngwr-i18n-ar.mjs +15 -0
  68. package/fesm2022/ngwr-i18n-ar.mjs.map +1 -1
  69. package/fesm2022/ngwr-i18n-cs.mjs +15 -0
  70. package/fesm2022/ngwr-i18n-cs.mjs.map +1 -1
  71. package/fesm2022/ngwr-i18n-de.mjs +15 -0
  72. package/fesm2022/ngwr-i18n-de.mjs.map +1 -1
  73. package/fesm2022/ngwr-i18n-en.mjs +15 -0
  74. package/fesm2022/ngwr-i18n-en.mjs.map +1 -1
  75. package/fesm2022/ngwr-i18n-es.mjs +15 -0
  76. package/fesm2022/ngwr-i18n-es.mjs.map +1 -1
  77. package/fesm2022/ngwr-i18n-fr.mjs +15 -0
  78. package/fesm2022/ngwr-i18n-fr.mjs.map +1 -1
  79. package/fesm2022/ngwr-i18n-he.mjs +15 -0
  80. package/fesm2022/ngwr-i18n-he.mjs.map +1 -1
  81. package/fesm2022/ngwr-i18n-hi.mjs +15 -0
  82. package/fesm2022/ngwr-i18n-hi.mjs.map +1 -1
  83. package/fesm2022/ngwr-i18n-id.mjs +15 -0
  84. package/fesm2022/ngwr-i18n-id.mjs.map +1 -1
  85. package/fesm2022/ngwr-i18n-it.mjs +15 -0
  86. package/fesm2022/ngwr-i18n-it.mjs.map +1 -1
  87. package/fesm2022/ngwr-i18n-ja.mjs +15 -0
  88. package/fesm2022/ngwr-i18n-ja.mjs.map +1 -1
  89. package/fesm2022/ngwr-i18n-ko.mjs +15 -0
  90. package/fesm2022/ngwr-i18n-ko.mjs.map +1 -1
  91. package/fesm2022/ngwr-i18n-nl.mjs +15 -0
  92. package/fesm2022/ngwr-i18n-nl.mjs.map +1 -1
  93. package/fesm2022/ngwr-i18n-pl.mjs +15 -0
  94. package/fesm2022/ngwr-i18n-pl.mjs.map +1 -1
  95. package/fesm2022/ngwr-i18n-pt.mjs +15 -0
  96. package/fesm2022/ngwr-i18n-pt.mjs.map +1 -1
  97. package/fesm2022/ngwr-i18n-ru.mjs +15 -0
  98. package/fesm2022/ngwr-i18n-ru.mjs.map +1 -1
  99. package/fesm2022/ngwr-i18n-sv.mjs +15 -0
  100. package/fesm2022/ngwr-i18n-sv.mjs.map +1 -1
  101. package/fesm2022/ngwr-i18n-tr.mjs +15 -0
  102. package/fesm2022/ngwr-i18n-tr.mjs.map +1 -1
  103. package/fesm2022/ngwr-i18n-uk.mjs +15 -0
  104. package/fesm2022/ngwr-i18n-uk.mjs.map +1 -1
  105. package/fesm2022/ngwr-i18n-vi.mjs +15 -0
  106. package/fesm2022/ngwr-i18n-vi.mjs.map +1 -1
  107. package/fesm2022/ngwr-i18n-zh-tw.mjs +15 -0
  108. package/fesm2022/ngwr-i18n-zh-tw.mjs.map +1 -1
  109. package/fesm2022/ngwr-i18n-zh.mjs +15 -0
  110. package/fesm2022/ngwr-i18n-zh.mjs.map +1 -1
  111. package/fesm2022/ngwr-i18n.mjs +82 -11
  112. package/fesm2022/ngwr-i18n.mjs.map +1 -1
  113. package/fesm2022/ngwr-input-number.mjs +24 -1
  114. package/fesm2022/ngwr-input-number.mjs.map +1 -1
  115. package/fesm2022/ngwr-input-otp.mjs +2 -2
  116. package/fesm2022/ngwr-input-otp.mjs.map +1 -1
  117. package/fesm2022/ngwr-input.mjs +10 -2
  118. package/fesm2022/ngwr-input.mjs.map +1 -1
  119. package/fesm2022/ngwr-layout.mjs.map +1 -1
  120. package/fesm2022/ngwr-list.mjs +1 -1
  121. package/fesm2022/ngwr-list.mjs.map +1 -1
  122. package/fesm2022/ngwr-loading-bar-router.mjs.map +1 -1
  123. package/fesm2022/ngwr-loading-bar.mjs +2 -2
  124. package/fesm2022/ngwr-loading-bar.mjs.map +1 -1
  125. package/fesm2022/ngwr-mention.mjs +8 -0
  126. package/fesm2022/ngwr-mention.mjs.map +1 -1
  127. package/fesm2022/ngwr-meta.mjs +9 -6
  128. package/fesm2022/ngwr-meta.mjs.map +1 -1
  129. package/fesm2022/ngwr-page-header.mjs +21 -0
  130. package/fesm2022/ngwr-page-header.mjs.map +1 -1
  131. package/fesm2022/ngwr-pagination.mjs +2 -0
  132. package/fesm2022/ngwr-pagination.mjs.map +1 -1
  133. package/fesm2022/ngwr-pipes.mjs +8 -1
  134. package/fesm2022/ngwr-pipes.mjs.map +1 -1
  135. package/fesm2022/ngwr-popconfirm.mjs +2 -1
  136. package/fesm2022/ngwr-popconfirm.mjs.map +1 -1
  137. package/fesm2022/ngwr-popover.mjs +47 -3
  138. package/fesm2022/ngwr-popover.mjs.map +1 -1
  139. package/fesm2022/ngwr-qr.mjs +6 -2
  140. package/fesm2022/ngwr-qr.mjs.map +1 -1
  141. package/fesm2022/ngwr-radio.mjs +71 -5
  142. package/fesm2022/ngwr-radio.mjs.map +1 -1
  143. package/fesm2022/ngwr-schema-form.mjs +10 -1
  144. package/fesm2022/ngwr-schema-form.mjs.map +1 -1
  145. package/fesm2022/ngwr-scroll.mjs +1 -3
  146. package/fesm2022/ngwr-scroll.mjs.map +1 -1
  147. package/fesm2022/ngwr-segmented.mjs +20 -0
  148. package/fesm2022/ngwr-segmented.mjs.map +1 -1
  149. package/fesm2022/ngwr-select.mjs +80 -9
  150. package/fesm2022/ngwr-select.mjs.map +1 -1
  151. package/fesm2022/ngwr-sortable-list.mjs +16 -4
  152. package/fesm2022/ngwr-sortable-list.mjs.map +1 -1
  153. package/fesm2022/ngwr-storage.mjs +1 -1
  154. package/fesm2022/ngwr-storage.mjs.map +1 -1
  155. package/fesm2022/ngwr-switch.mjs +2 -2
  156. package/fesm2022/ngwr-switch.mjs.map +1 -1
  157. package/fesm2022/ngwr-table.mjs +41 -7
  158. package/fesm2022/ngwr-table.mjs.map +1 -1
  159. package/fesm2022/ngwr-tabs-router.mjs.map +1 -1
  160. package/fesm2022/ngwr-textarea.mjs +2 -2
  161. package/fesm2022/ngwr-textarea.mjs.map +1 -1
  162. package/fesm2022/ngwr-toast.mjs +28 -0
  163. package/fesm2022/ngwr-toast.mjs.map +1 -1
  164. package/fesm2022/ngwr-tour.mjs +2 -2
  165. package/fesm2022/ngwr-tour.mjs.map +1 -1
  166. package/fesm2022/ngwr-typography.mjs +20 -0
  167. package/fesm2022/ngwr-typography.mjs.map +1 -1
  168. package/fesm2022/ngwr-utils-router.mjs.map +1 -1
  169. package/fesm2022/ngwr-utils.mjs +46 -4
  170. package/fesm2022/ngwr-utils.mjs.map +1 -1
  171. package/fesm2022/ngwr-validators.mjs +33 -1
  172. package/fesm2022/ngwr-validators.mjs.map +1 -1
  173. package/fesm2022/ngwr-version.mjs +1 -1
  174. package/fesm2022/ngwr-version.mjs.map +1 -1
  175. package/form/styles/_index.scss +37 -0
  176. package/graph/styles/_index.scss +1 -9
  177. package/i18n/ar.json +15 -0
  178. package/i18n/cs.json +15 -0
  179. package/i18n/de.json +15 -0
  180. package/i18n/en.json +15 -0
  181. package/i18n/es.json +15 -0
  182. package/i18n/fr.json +15 -0
  183. package/i18n/he.json +15 -0
  184. package/i18n/hi.json +15 -0
  185. package/i18n/id.json +15 -0
  186. package/i18n/it.json +15 -0
  187. package/i18n/ja.json +15 -0
  188. package/i18n/ko.json +15 -0
  189. package/i18n/nl.json +15 -0
  190. package/i18n/pl.json +15 -0
  191. package/i18n/pt.json +15 -0
  192. package/i18n/ru.json +15 -0
  193. package/i18n/sv.json +15 -0
  194. package/i18n/tr.json +15 -0
  195. package/i18n/uk.json +15 -0
  196. package/i18n/vi.json +15 -0
  197. package/i18n/zh-TW.json +15 -0
  198. package/i18n/zh.json +15 -0
  199. package/image-cropper/styles/_index.scss +1 -9
  200. package/input-number/styles/_index.scss +7 -0
  201. package/layout/styles/_index.scss +13 -1
  202. package/llms-full.txt +10 -10
  203. package/loading-bar/styles/_rules.scss +6 -0
  204. package/package.json +2 -2
  205. package/page-header/styles/_index.scss +18 -0
  206. package/popover/styles/_index.scss +7 -0
  207. package/schematics/use/symbol-map.json +2 -0
  208. package/segmented/styles/_index.scss +7 -0
  209. package/select/styles/_index.scss +7 -0
  210. package/sidebar/styles/_index.scss +6 -0
  211. package/skills/ngwr/references/catalog.md +1 -1
  212. package/sortable-list/styles/_rules.scss +1 -9
  213. package/speed-dial/styles/_index.scss +6 -0
  214. package/stepper/styles/_index.scss +1 -9
  215. package/table/styles/_index.scss +49 -0
  216. package/theme/_index.scss +12 -1
  217. package/theme/styles/_colors.scss +11 -0
  218. package/theme/styles/_contrast.scss +6 -0
  219. package/theme/styles/_index.scss +1 -0
  220. package/theme/styles/_mixins.scss +45 -0
  221. package/theme/styles/_print.scss +17 -0
  222. package/toast/styles/_index.scss +7 -0
  223. package/tour/styles/_index.scss +8 -0
  224. package/tree/styles/_index.scss +1 -9
  225. package/types/ngwr-anchor.d.ts +3 -0
  226. package/types/ngwr-animations-aurora.d.ts +6 -0
  227. package/types/ngwr-animations-blur-reveal.d.ts +6 -0
  228. package/types/ngwr-animations-click-sparks.d.ts +6 -0
  229. package/types/ngwr-animations-confetti.d.ts +6 -0
  230. package/types/ngwr-animations-decode.d.ts +6 -0
  231. package/types/ngwr-animations-destruct.d.ts +6 -0
  232. package/types/ngwr-animations-dot-grid.d.ts +6 -0
  233. package/types/ngwr-animations-falling-letters.d.ts +6 -0
  234. package/types/ngwr-animations-flow-lines.d.ts +6 -0
  235. package/types/ngwr-animations-fluid-cursor.d.ts +6 -0
  236. package/types/ngwr-animations-glitch.d.ts +6 -0
  237. package/types/ngwr-animations-glow-border.d.ts +6 -0
  238. package/types/ngwr-animations-gradient-flow.d.ts +6 -0
  239. package/types/ngwr-animations-marquee.d.ts +6 -0
  240. package/types/ngwr-animations-orbit.d.ts +6 -0
  241. package/types/ngwr-animations-reveal.d.ts +6 -0
  242. package/types/ngwr-animations-ripple-grid.d.ts +6 -0
  243. package/types/ngwr-animations-rotate-reveal.d.ts +6 -0
  244. package/types/ngwr-animations-shimmer.d.ts +6 -0
  245. package/types/ngwr-animations-spotlight.d.ts +6 -0
  246. package/types/ngwr-animations-thread-lines.d.ts +6 -0
  247. package/types/ngwr-animations-tilt.d.ts +10 -0
  248. package/types/ngwr-animations-typewriter.d.ts +6 -0
  249. package/types/ngwr-breadcrumbs.d.ts +25 -0
  250. package/types/ngwr-button.d.ts +23 -3
  251. package/types/ngwr-carousel.d.ts +2 -0
  252. package/types/ngwr-cascader.d.ts +7 -0
  253. package/types/ngwr-charts-core.d.ts +16 -0
  254. package/types/ngwr-charts-meter-group.d.ts +2 -0
  255. package/types/ngwr-checkbox.d.ts +1 -0
  256. package/types/ngwr-color-picker.d.ts +1 -0
  257. package/types/ngwr-context-menu.d.ts +1 -1
  258. package/types/ngwr-date-picker.d.ts +19 -0
  259. package/types/ngwr-dialog.d.ts +39 -8
  260. package/types/ngwr-directives.d.ts +12 -4
  261. package/types/ngwr-drawer.d.ts +1 -1
  262. package/types/ngwr-dropdown.d.ts +1 -1
  263. package/types/ngwr-event-calendar.d.ts +4 -0
  264. package/types/ngwr-form.d.ts +85 -1
  265. package/types/ngwr-i18n.d.ts +65 -5
  266. package/types/ngwr-input-number.d.ts +8 -0
  267. package/types/ngwr-input.d.ts +7 -0
  268. package/types/ngwr-layout.d.ts +1 -1
  269. package/types/ngwr-loading-bar-router.d.ts +6 -0
  270. package/types/ngwr-page-header.d.ts +23 -1
  271. package/types/ngwr-popconfirm.d.ts +1 -1
  272. package/types/ngwr-popover.d.ts +28 -4
  273. package/types/ngwr-radio.d.ts +47 -5
  274. package/types/ngwr-segmented.d.ts +7 -0
  275. package/types/ngwr-select.d.ts +57 -13
  276. package/types/ngwr-sortable-list.d.ts +20 -7
  277. package/types/ngwr-table.d.ts +58 -5
  278. package/types/ngwr-tabs-router.d.ts +6 -0
  279. package/types/ngwr-toast.d.ts +11 -0
  280. package/types/ngwr-tour.d.ts +0 -1
  281. package/types/ngwr-typography.d.ts +7 -0
  282. package/types/ngwr-utils-router.d.ts +6 -0
  283. package/types/ngwr-utils.d.ts +56 -2
  284. package/types/ngwr-validators.d.ts +49 -1
  285. package/types/ngwr-version.d.ts +1 -1
  286. package/typography/styles/_index.scss +4 -0
  287. package/window/styles/_index.scss +1 -9
@@ -1 +1 @@
1
- {"version":3,"file":"ngwr-tour.mjs","names":[],"sources":["../../../projects/lib/tour/tour-popup.ts","../../../projects/lib/tour/tour-popup.html","../../../projects/lib/tour/tour.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { Component, InjectionToken, ViewEncapsulation, computed, inject } from '@angular/core';\n\nimport { WrButton } from 'ngwr/button';\nimport { wrReadI18nText, useI18nFormatter } from 'ngwr/i18n';\nimport { wrCheckStyles, wrRandomId } from 'ngwr/utils';\n\nimport type { WrTourStep } from './types';\n\n/** What the popup needs from the running tour, without importing the service (cycle). */\nexport interface WrTourController {\n readonly index: () => number;\n readonly total: () => number;\n readonly step: () => WrTourStep | null;\n /**\n * Whether this is the last step the user will actually see — the service looks\n * ahead for a reachable one, because a trailing step whose target is missing gets\n * skipped and the raw count would call the final card \"Next\".\n */\n readonly isLast: () => boolean;\n /**\n * Whether this is the first step the user will actually see — the service looks\n * BEHIND for a reachable one, for the mirror reason: a leading step whose target\n * is missing gets skipped, so the tour opens on a later index and the raw one\n * would put a Back button on the very first card.\n */\n readonly isFirst: () => boolean;\n /** Whether the card opens with focus on Next: the tour's `autoFocus` is `'first-tabbable'`. */\n readonly focusNext: () => boolean;\n next(): void;\n prev(): void;\n stop(): void;\n}\n\n/** Provided by `WrTour` when it attaches the popup portal. */\nexport const WR_TOUR_STEP = new InjectionToken<WrTourController>('WR_TOUR_STEP');\n\n/**\n * The card a tour shows next to the spotlit element. Rendered by `WrTour` into\n * a CDK overlay — not something you place yourself.\n *\n * @see https://ngwr.dev/reference/services/tour\n */\n@Component({\n selector: 'wr-tour-popup',\n templateUrl: './tour-popup.html',\n encapsulation: ViewEncapsulation.None,\n host: {\n class: 'wr-tour-popup',\n role: 'dialog',\n 'aria-modal': 'true',\n '[attr.aria-labelledby]': 'labelledBy()',\n '[attr.aria-describedby]': 'contentId',\n },\n imports: [WrButton],\n})\nexport class WrTourPopup {\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('tour');\n }\n\n protected readonly tour = inject(WR_TOUR_STEP);\n\n // `wrReadI18nText`, not `useI18nText`: these have no consumer-facing input to\n // forward. Both helpers are reactive.\n protected readonly nextLabel = wrReadI18nText('tour.next', 'Next');\n protected readonly backLabel = wrReadI18nText('tour.back', 'Back');\n protected readonly doneLabel = wrReadI18nText('tour.done', 'Done');\n protected readonly skipLabel = wrReadI18nText('tour.skip', 'Skip tour');\n\n /** `Step {{current}} of {{total}}`, the second half of the dialog's name. */\n protected readonly progress = useI18nFormatter('tour.progress', 'Step {{current}} of {{total}}');\n\n // From the service, not `index() >= total() - 1`: a trailing step whose target is\n // missing gets skipped, so the raw count called the final card \"Next\" and then\n // ended the tour when it was pressed.\n protected readonly isLast = computed(() => this.tour.isLast());\n // Same story at the other end, and the same fix: `index() <= 0` rendered a Back\n // button on the first card of a tour whose leading step had been skipped, and\n // `prev()` walks off the start and returns — so the button did nothing at all.\n protected readonly isFirst = computed(() => this.tour.isFirst());\n\n protected readonly progressText = computed(() =>\n this.progress({ current: this.tour.index() + 1, total: this.tour.total() })\n );\n\n protected readonly titleId = wrRandomId('wr-tour-title');\n protected readonly progressId = wrRandomId('wr-tour-progress');\n protected readonly contentId = wrRandomId('wr-tour-content');\n\n /**\n * The dialog is named by its title and the progress line, or by the progress\n * line alone for an untitled step, and described by the step's text: a screen\n * reader reads a dialog's name and description when focus enters it, and\n * nothing else of what it holds.\n */\n protected readonly labelledBy = computed(() =>\n this.tour.step()?.title ? `${this.titleId} ${this.progressId}` : this.progressId\n );\n}\n","@let step = tour.step();\n\n<p class=\"wr-tour-popup__progress\" [id]=\"progressId\">{{ progressText() }}</p>\n\n@if (step?.title; as title) {\n <h2 class=\"wr-tour-popup__title\" [id]=\"titleId\">{{ title }}</h2>\n}\n\n<p class=\"wr-tour-popup__content\" [id]=\"contentId\">{{ step?.content }}</p>\n\n<div class=\"wr-tour-popup__actions\">\n <!-- The three buttons are told apart by a class rather than by their position in\n the row: the back button is conditional, so an index means one thing on the\n first step and another everywhere else — and the labels are translated. -->\n <button\n wr-btn\n type=\"button\"\n size=\"sm\"\n outlined\n class=\"wr-tour-popup__action wr-tour-popup__action--skip\"\n (click)=\"tour.stop()\"\n >\n {{ skipLabel() }}\n </button>\n\n <span class=\"wr-tour-popup__spacer\"></span>\n\n @if (!isFirst()) {\n <button\n wr-btn\n type=\"button\"\n size=\"sm\"\n outlined\n class=\"wr-tour-popup__action wr-tour-popup__action--back\"\n (click)=\"tour.prev()\"\n >\n {{ backLabel() }}\n </button>\n }\n <!-- Under `autoFocus: 'first-tabbable'` focus opens on the button that walks the\n tour, not on Skip, the first in the row: the focus trap reads\n `cdkFocusInitial`, as the confirm dialog has it. -->\n <button\n wr-btn\n type=\"button\"\n size=\"sm\"\n color=\"primary\"\n class=\"wr-tour-popup__action wr-tour-popup__action--next\"\n [attr.cdkFocusInitial]=\"tour.focusNext() ? '' : null\"\n (click)=\"tour.next()\"\n >\n {{ isLast() ? doneLabel() : nextLabel() }}\n </button>\n</div>\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { type ConfigurableFocusTrap, ConfigurableFocusTrapFactory } from '@angular/cdk/a11y';\nimport { Directionality } from '@angular/cdk/bidi';\nimport { type ConnectedPosition, type OverlayRef, ScrollStrategyOptions } from '@angular/cdk/overlay';\nimport { ComponentPortal } from '@angular/cdk/portal';\nimport { Location, isPlatformBrowser } from '@angular/common';\nimport {\n DOCUMENT,\n DestroyRef,\n EnvironmentInjector,\n Injector,\n PLATFORM_ID,\n Service,\n computed,\n inject,\n signal,\n} from '@angular/core';\n\nimport { WR_OVERLAY, type WrOverlayAutoFocus, wrFocusOverlay, wrFollowDirection, wrMirrorOffsets } from 'ngwr/overlay';\nimport { wrToClassList } from 'ngwr/utils';\n\nimport { WR_TOUR_STEP, WrTourPopup } from './tour-popup';\nimport type { WrTourOptions, WrTourPlacement, WrTourStep } from './types';\n\n/** Fallback order per preferred side — the opposite side first, then the sides. */\nconst FALLBACKS: Record<WrTourPlacement, readonly WrTourPlacement[]> = {\n bottom: ['bottom', 'top', 'right', 'left'],\n top: ['top', 'bottom', 'right', 'left'],\n left: ['left', 'right', 'bottom', 'top'],\n right: ['right', 'left', 'bottom', 'top'],\n};\n\nconst CONNECTED: Record<\n WrTourPlacement,\n {\n originX: 'start' | 'center' | 'end';\n originY: 'top' | 'center' | 'bottom';\n overlayX: 'start' | 'center' | 'end';\n overlayY: 'top' | 'center' | 'bottom';\n }\n> = {\n bottom: { originX: 'center', originY: 'bottom', overlayX: 'center', overlayY: 'top' },\n top: { originX: 'center', originY: 'top', overlayX: 'center', overlayY: 'bottom' },\n left: { originX: 'start', originY: 'center', overlayX: 'end', overlayY: 'center' },\n right: { originX: 'end', originY: 'center', overlayX: 'start', overlayY: 'center' },\n};\n\n/**\n * Guided product tour: a spotlight over one element at a time plus a popup\n * explaining it.\n *\n * Steps are data, not markup — call `start()` with an array and the service owns\n * the overlay, the cut-out, focus and the keyboard. A step whose target is not\n * on the page is skipped rather than shown floating, so a tour survives a\n * feature being hidden behind a flag or a permission.\n *\n * @example\n * ```ts\n * private readonly tour = inject(WrTour);\n *\n * showMeAround(): void {\n * this.tour.start([\n * { target: '[data-tour=\"search\"]', title: 'Search', content: 'Find anything by name.' },\n * { target: '[data-tour=\"filters\"]', content: 'Narrow the list down.', placement: 'right' },\n * ]);\n * }\n * ```\n *\n * @see https://ngwr.dev/reference/services/tour\n */\n@Service()\nexport class WrTour {\n private readonly overlay = inject(WR_OVERLAY);\n private readonly dir = inject(Directionality, { optional: true });\n private readonly scrollStrategies = inject(ScrollStrategyOptions);\n private readonly injector = inject(EnvironmentInjector);\n private readonly focusTrapFactory = inject(ConfigurableFocusTrapFactory);\n private readonly document = inject(DOCUMENT);\n private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n private readonly location = inject(Location);\n\n private readonly steps = signal<readonly WrTourStep[]>([]);\n private readonly cursor = signal(-1);\n\n private overlayRef: OverlayRef | null = null;\n private focusTrap: ConfigurableFocusTrap | null = null;\n private spotlight: HTMLElement | null = null;\n private detachKeydown: (() => void) | null = null;\n private detachReposition: (() => void) | null = null;\n private restoreFocus: HTMLElement | null = null;\n private autoFocus: WrOverlayAutoFocus = 'dialog';\n /** `focusNext` for the card, see {@link WrTourController}. */\n readonly focusNext = (): boolean => this.autoFocus === 'first-tabbable';\n private stopWatchingUrl: (() => void) | null = null;\n\n /** Whether a tour is running. */\n readonly active = computed(() => this.cursor() >= 0);\n\n /** Zero-based index of the current step, `-1` when idle. */\n readonly index = computed(() => this.cursor());\n\n /** How many steps this tour has. */\n readonly total = computed(() => this.steps().length);\n\n /** The step being shown, or `null` when idle. */\n readonly step = computed<WrTourStep | null>(() => this.steps()[this.cursor()] ?? null);\n\n // Whether any step AFTER the current one can actually be shown. Settled once per\n // move, in `goTo`, because reachability is a DOM question and not a signal.\n private readonly noStepAfter = signal(false);\n\n // The same question looking the other way. Settled in `goTo` for the same reason.\n //\n // `true` at rest, and the asymmetry with `noStepAfter` is deliberate: with no\n // tour running there is no step, so both questions are vacuous, and the pair\n // is set to whatever keeps a naive template honest. `@if (!tour.isFirst())`\n // around a Back button is the obvious way to write it, and at `false` that\n // button appears with no tour on screen.\n private readonly noStepBefore = signal(true);\n\n /**\n * Whether this is the last step the user will see. Not `index() === total() - 1`:\n * a trailing step whose target is missing is skipped, so comparing against the\n * raw count left the primary button reading \"Next\" on the final card and then\n * ending the tour when it was pressed. `false` while no tour is running.\n */\n readonly isLast = computed(() => this.noStepAfter());\n\n /**\n * Whether this is the first step the user will see. Not `index() === 0`, for the\n * mirror of the reason above: a LEADING step whose target is missing is skipped,\n * so the tour opens on a later index and the raw one put a Back button on the\n * first card — one that did nothing at all, because `prev()` walks off the start\n * and returns without moving. `true` while no tour is running — see the signal\n * it reads.\n */\n readonly isFirst = computed(() => this.noStepBefore());\n\n constructor() {\n // Everything this service owns lives OUTSIDE its own injector: a CDK overlay, a\n // div appended to `document.body`, a document keydown listener and two window\n // listeners. Nothing removes them when the injector goes, so a tour running at\n // teardown left its cut-out on the page.\n inject(DestroyRef).onDestroy(() => this.stop());\n }\n\n /**\n * Begin a tour. Restarts if one is already running. A no-op under SSR — a\n * tour is a client-side affordance and there is nothing to spotlight on the\n * server.\n */\n start(steps: readonly WrTourStep[], options: WrTourOptions = {}): void {\n if (!this.isBrowser || steps.length === 0) return;\n this.stop();\n this.steps.set(steps);\n this.autoFocus = options.autoFocus ?? 'dialog';\n this.restoreFocus = this.document.activeElement as HTMLElement | null;\n // A tour belongs to the page it was started on, the way `WrDialog` and\n // `WrDrawerManager` tie a modal to its URL. Nothing ended it on navigation,\n // so following a link mid-tour left the card pointing at an element the\n // router had just removed — the cut-out collapsed to a 12px box at the\n // corner, its 9999px shadow dimming the whole new page, and focus trapped in\n // a card about the page the user had left. `onUrlChange` rather than\n // `subscribe()`, which hears popstate alone and misses `router.navigate()`.\n this.stopWatchingUrl = this.location.onUrlChange(() => this.stop());\n this.goTo(0, 1);\n }\n\n /** Advance; finishes the tour past the last step. */\n next(): void {\n this.goTo(this.cursor() + 1, 1);\n }\n\n /** Go back; stays put on the first step. */\n prev(): void {\n this.goTo(this.cursor() - 1, -1);\n }\n\n /** End the tour and return focus where it was. */\n stop(): void {\n // Unhooked a microtask late, as `WrDialog` does: `Location` notifies with a\n // `forEach`, and unregistering from inside that notification splices the\n // array it is walking, which would skip the listener after ours.\n const unwatch = this.stopWatchingUrl;\n this.stopWatchingUrl = null;\n if (unwatch) queueMicrotask(unwatch);\n this.teardownStep();\n this.steps.set([]);\n this.cursor.set(-1);\n // Back to their resting answers. Without this a finished tour left both\n // holding whatever its last step said, so `isFirst` and `isLast` were the\n // only two signals here that still described a tour that had ended — while\n // `active`, `index`, `total` and `step` all reported idle.\n this.noStepAfter.set(false);\n this.noStepBefore.set(true);\n this.restoreFocus?.focus?.();\n this.restoreFocus = null;\n }\n\n /**\n * Move to `index`, skipping steps whose target is not in the DOM. `direction`\n * says which way to keep skipping, so a missing step never traps the tour\n * between two dead ends.\n */\n private goTo(index: number, direction: 1 | -1): void {\n const steps = this.steps();\n let i = index;\n while (i >= 0 && i < steps.length && this.resolve(steps[i]) === null) i += direction;\n\n if (i < 0) {\n // Ran off the start while going back — stay where we were.\n return;\n }\n if (i >= steps.length) {\n this.stop();\n return;\n }\n\n // Focus inside the card that is about to go stays in the tour: the next card\n // takes it, whatever `autoFocus` says about a card opening.\n const active = this.document.activeElement;\n const hadFocus = !!active && !!this.overlayRef?.overlayElement.contains(active);\n this.teardownStep();\n this.cursor.set(i);\n this.noStepAfter.set(!this.anyResolvableAfter(i));\n this.noStepBefore.set(!this.anyResolvableBefore(i));\n this.openStep(steps[i], hadFocus);\n }\n\n /** Whether the tour has a step past `index` that can actually be shown. */\n private anyResolvableAfter(index: number): boolean {\n const steps = this.steps();\n for (let i = index + 1; i < steps.length; i += 1) {\n if (this.resolve(steps[i]) !== null) return true;\n }\n return false;\n }\n\n /** Whether the tour has a step before `index` that can actually be shown. */\n private anyResolvableBefore(index: number): boolean {\n const steps = this.steps();\n for (let i = index - 1; i >= 0; i -= 1) {\n if (this.resolve(steps[i]) !== null) return true;\n }\n return false;\n }\n\n private resolve(step: WrTourStep): HTMLElement | null {\n if (typeof step.target !== 'string') return step.target.isConnected ? step.target : null;\n return this.document.querySelector<HTMLElement>(step.target);\n }\n\n private openStep(step: WrTourStep, hadFocus: boolean): void {\n const target = this.resolve(step);\n if (!target) return;\n\n target.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'smooth' });\n\n // The cut-out is a bare element sized to the target with an enormous spread\n // shadow: everything outside it dims, the target itself stays untouched.\n // Cheaper and far more robust than a clip-path polygon, and it needs no\n // recompute when the page reflows beyond moving the box.\n const spotlight = this.document.createElement('div');\n spotlight.className = 'wr-tour__spotlight';\n spotlight.setAttribute('aria-hidden', 'true');\n this.document.body.appendChild(spotlight);\n this.spotlight = spotlight;\n this.placeSpotlight(target);\n\n const placement = step.placement ?? 'bottom';\n const positionStrategy = this.overlay\n .position()\n .flexibleConnectedTo(target)\n .withPositions(this.stepPositions(placement, this.isRtl()))\n .withPush(true);\n\n this.overlayRef = this.overlay.create({\n positionStrategy,\n scrollStrategy: this.scrollStrategies.reposition(),\n panelClass: wrToClassList('wr-tour-overlay', step.panelClass),\n });\n\n // The CDK read the direction once, just now. A tour is long-lived by nature\n // — a step can sit on screen while the user changes a language setting — and\n // without this the card keeps the direction the step opened in, with the\n // 12px gap that held it clear of the spotlight now pointing into it.\n // Per step, because every move disposes this ref and builds the next.\n //\n // The cut-out moves with it. The target itself changes place when the page\n // mirrors, and the spotlight is re-measured only on scroll and resize, so a\n // flip left it highlighting empty space while the card, re-placed by the CDK,\n // pointed at the target sitting under the dim. The flip has already been laid\n // out by the time this runs — the CDK measures the same element right after.\n wrFollowDirection(this.overlayRef, this.dir, this.injector, direction => {\n positionStrategy.withPositions(this.stepPositions(placement, direction === 'rtl'));\n this.placeSpotlight(target);\n });\n\n const portal = new ComponentPortal(\n WrTourPopup,\n null,\n Injector.create({ parent: this.injector, providers: [{ provide: WR_TOUR_STEP, useValue: this }] })\n );\n const ref = this.overlayRef.attach(portal);\n\n // Kept on the instance, not in a local: a trap registers with CDK's\n // `FocusTrapManager` and installs a capture-phase document focus listener, so an\n // undestroyed one leaks per STEP and every tour left a stack of them behind.\n const card = ref.location.nativeElement as HTMLElement;\n this.focusTrap = this.focusTrapFactory.create(card);\n // Onto Next only when asked. Otherwise the card itself takes focus, so the\n // keyboard is in the tour and no button is lit; under `false` only when the\n // card before it held focus, which would otherwise fall to `<body>`.\n wrFocusOverlay(\n card,\n this.focusTrap,\n this.autoFocus === false && hadFocus ? 'dialog' : this.autoFocus,\n this.injector\n );\n\n const onKey = (event: KeyboardEvent): void => {\n // The listener is on the document, so a step shown over a dialog would see the\n // Escape that dialog just handled and close the tour too.\n if (event.key === 'Escape' && !event.defaultPrevented) {\n event.preventDefault();\n this.stop();\n }\n };\n this.document.addEventListener('keydown', onKey);\n this.detachKeydown = () => this.document.removeEventListener('keydown', onKey);\n\n const reposition = (): void => this.placeSpotlight(target);\n window.addEventListener('scroll', reposition, true);\n window.addEventListener('resize', reposition);\n this.detachReposition = () => {\n window.removeEventListener('scroll', reposition, true);\n window.removeEventListener('resize', reposition);\n };\n }\n\n /**\n * The card's fallback table for one placement, with its inline offsets already\n * mirrored. Built per call rather than per step: the direction can change while\n * the step is on screen, and a table is what has to be rebuilt when it does.\n */\n private stepPositions(placement: WrTourPlacement, isRtl: boolean): ConnectedPosition[] {\n return wrMirrorOffsets(\n FALLBACKS[placement].map(side => ({\n ...CONNECTED[side],\n offsetY: side === 'bottom' ? 12 : side === 'top' ? -12 : 0,\n offsetX: side === 'right' ? 12 : side === 'left' ? -12 : 0,\n })),\n isRtl\n );\n }\n\n private placeSpotlight(target: HTMLElement): void {\n const el = this.spotlight;\n if (!el) return;\n const r = target.getBoundingClientRect();\n const pad = 6;\n el.style.top = `${r.top - pad}px`;\n el.style.left = `${r.left - pad}px`;\n el.style.width = `${r.width + pad * 2}px`;\n el.style.height = `${r.height + pad * 2}px`;\n }\n\n private teardownStep(): void {\n this.focusTrap?.destroy();\n this.focusTrap = null;\n this.detachKeydown?.();\n this.detachKeydown = null;\n this.detachReposition?.();\n this.detachReposition = null;\n this.overlayRef?.dispose();\n this.overlayRef = null;\n this.spotlight?.remove();\n this.spotlight = null;\n }\n\n /**\n * Whether the app reads right-to-left.\n *\n * Optional inject: `Directionality` is root-provided, so this is never null in\n * an app — but a bare `TestBed` that provides nothing should still get a\n * component that works, and defaulting to LTR is the honest fallback.\n */\n private isRtl(): boolean {\n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EAAC,GACF,KAAK;CAET;CAEQ,eAAe,QAAmB;EACxC,MAAM,KAAK,KAAK;EAChB,IAAI,CAAC,IAAI;EACT,MAAM,IAAI,OAAO,sBAAqB;EACtC,MAAM,MAAM;EACZ,GAAG,MAAM,MAAM,GAAG,EAAE,MAAM,IAAG;EAC7B,GAAG,MAAM,OAAO,GAAG,EAAE,OAAO,IAAG;EAC/B,GAAG,MAAM,QAAQ,GAAG,EAAE,QAAQ,GAAO;EACrC,GAAG,MAAM,SAAS,GAAG,EAAE,SAAS,GAAO;CACzC;CAEQ,eAAY;EAClB,KAAK,WAAW,QAAO;EACvB,KAAK,YAAY;EACjB,KAAK,gBAAe;EACpB,KAAK,gBAAgB;EACrB,KAAK,mBAAkB;EACvB,KAAK,mBAAmB;EACxB,KAAK,YAAY,QAAO;EACxB,KAAK,aAAa;EAClB,KAAK,WAAW,OAAM;EACtB,KAAK,YAAY;CACnB;CASQ,QAAK;EACX,OAAO,KAAK,KAAK,UAAU;CAC7B;CA9TW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAM,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAN,OAAA,QAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;CAAM,CAAA;;AAAN,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAM,YAAA,CAAA,EADlB,MAAA,Q"}
1
+ {"version":3,"file":"ngwr-tour.mjs","names":[],"sources":["../../../projects/lib/tour/tour-popup.ts","../../../projects/lib/tour/tour-popup.html","../../../projects/lib/tour/tour.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { Component, InjectionToken, ViewEncapsulation, computed, inject } from '@angular/core';\n\nimport { WrButton } from 'ngwr/button';\nimport { wrReadI18nText, useI18nFormatter } from 'ngwr/i18n';\nimport { wrCheckStyles, wrRandomId } from 'ngwr/utils';\n\nimport type { WrTourStep } from './types';\n\n/** What the popup needs from the running tour, without importing the service (cycle). */\nexport interface WrTourController {\n readonly index: () => number;\n readonly total: () => number;\n readonly step: () => WrTourStep | null;\n /**\n * Whether this is the last step the user will actually see — the service looks\n * ahead for a reachable one, because a trailing step whose target is missing gets\n * skipped and the raw count would call the final card \"Next\".\n */\n readonly isLast: () => boolean;\n /**\n * Whether this is the first step the user will actually see — the service looks\n * BEHIND for a reachable one, for the mirror reason: a leading step whose target\n * is missing gets skipped, so the tour opens on a later index and the raw one\n * would put a Back button on the very first card.\n */\n readonly isFirst: () => boolean;\n /** Whether the card opens with focus on Next: the tour's `autoFocus` is `'first-tabbable'`. */\n readonly focusNext: () => boolean;\n next(): void;\n prev(): void;\n stop(): void;\n}\n\n/** Provided by `WrTour` when it attaches the popup portal. */\nexport const WR_TOUR_STEP = new InjectionToken<WrTourController>('WR_TOUR_STEP');\n\n/**\n * The card a tour shows next to the spotlit element. Rendered by `WrTour` into\n * a CDK overlay — not something you place yourself.\n *\n * @see https://ngwr.dev/reference/services/tour\n */\n@Component({\n selector: 'wr-tour-popup',\n templateUrl: './tour-popup.html',\n encapsulation: ViewEncapsulation.None,\n host: {\n class: 'wr-tour-popup',\n role: 'dialog',\n 'aria-modal': 'true',\n '[attr.aria-labelledby]': 'labelledBy()',\n '[attr.aria-describedby]': 'contentId',\n },\n imports: [WrButton],\n})\nexport class WrTourPopup {\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('tour');\n }\n\n protected readonly tour = inject(WR_TOUR_STEP);\n\n // `wrReadI18nText`, not `useI18nText`: these have no consumer-facing input to\n // forward. Both helpers are reactive.\n protected readonly nextLabel = wrReadI18nText('tour.next', 'Next');\n protected readonly backLabel = wrReadI18nText('tour.back', 'Back');\n protected readonly doneLabel = wrReadI18nText('tour.done', 'Done');\n protected readonly skipLabel = wrReadI18nText('tour.skip', 'Skip tour');\n\n /** `Step {{current}} of {{total}}`, the second half of the dialog's name. */\n protected readonly progress = useI18nFormatter('tour.progress', 'Step {{current}} of {{total}}');\n\n // From the service, not `index() >= total() - 1`: a trailing step whose target is\n // missing gets skipped, so the raw count called the final card \"Next\" and then\n // ended the tour when it was pressed.\n protected readonly isLast = computed(() => this.tour.isLast());\n // Same story at the other end, and the same fix: `index() <= 0` rendered a Back\n // button on the first card of a tour whose leading step had been skipped, and\n // `prev()` walks off the start and returns — so the button did nothing at all.\n protected readonly isFirst = computed(() => this.tour.isFirst());\n\n protected readonly progressText = computed(() =>\n this.progress({ current: this.tour.index() + 1, total: this.tour.total() })\n );\n\n protected readonly titleId = wrRandomId('wr-tour-title');\n protected readonly progressId = wrRandomId('wr-tour-progress');\n protected readonly contentId = wrRandomId('wr-tour-content');\n\n /**\n * The dialog is named by its title and the progress line, or by the progress\n * line alone for an untitled step, and described by the step's text: a screen\n * reader reads a dialog's name and description when focus enters it, and\n * nothing else of what it holds.\n */\n protected readonly labelledBy = computed(() =>\n this.tour.step()?.title ? `${this.titleId} ${this.progressId}` : this.progressId\n );\n}\n","@let step = tour.step();\n\n<p class=\"wr-tour-popup__progress\" [id]=\"progressId\">{{ progressText() }}</p>\n\n@if (step?.title; as title) {\n <h2 class=\"wr-tour-popup__title\" [id]=\"titleId\">{{ title }}</h2>\n}\n\n<p class=\"wr-tour-popup__content\" [id]=\"contentId\">{{ step?.content }}</p>\n\n<div class=\"wr-tour-popup__actions\">\n <!-- The three buttons are told apart by a class rather than by their position in\n the row: the back button is conditional, so an index means one thing on the\n first step and another everywhere else — and the labels are translated. -->\n <button\n wr-btn\n type=\"button\"\n size=\"sm\"\n outlined\n class=\"wr-tour-popup__action wr-tour-popup__action--skip\"\n (click)=\"tour.stop()\"\n >\n {{ skipLabel() }}\n </button>\n\n <span class=\"wr-tour-popup__spacer\"></span>\n\n @if (!isFirst()) {\n <button\n wr-btn\n type=\"button\"\n size=\"sm\"\n outlined\n class=\"wr-tour-popup__action wr-tour-popup__action--back\"\n (click)=\"tour.prev()\"\n >\n {{ backLabel() }}\n </button>\n }\n <!-- Under `autoFocus: 'first-tabbable'` focus opens on the button that walks the\n tour, not on Skip, the first in the row: the focus trap reads\n `cdkFocusInitial`, as the confirm dialog has it. -->\n <button\n wr-btn\n type=\"button\"\n size=\"sm\"\n color=\"primary\"\n class=\"wr-tour-popup__action wr-tour-popup__action--next\"\n [attr.cdkFocusInitial]=\"tour.focusNext() ? '' : null\"\n (click)=\"tour.next()\"\n >\n {{ isLast() ? doneLabel() : nextLabel() }}\n </button>\n</div>\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { type ConfigurableFocusTrap, ConfigurableFocusTrapFactory } from '@angular/cdk/a11y';\nimport { Directionality } from '@angular/cdk/bidi';\nimport { type ConnectedPosition, type OverlayRef, ScrollStrategyOptions } from '@angular/cdk/overlay';\nimport { ComponentPortal } from '@angular/cdk/portal';\nimport { Location, isPlatformBrowser } from '@angular/common';\nimport {\n DOCUMENT,\n DestroyRef,\n EnvironmentInjector,\n Injector,\n PLATFORM_ID,\n Service,\n computed,\n inject,\n signal,\n} from '@angular/core';\n\nimport { WR_OVERLAY, type WrOverlayAutoFocus, wrFocusOverlay, wrFollowDirection, wrMirrorOffsets } from 'ngwr/overlay';\nimport { wrRestoreFocus, wrToClassList } from 'ngwr/utils';\n\nimport { WR_TOUR_STEP, WrTourPopup } from './tour-popup';\nimport type { WrTourOptions, WrTourPlacement, WrTourStep } from './types';\n\n/** Fallback order per preferred side — the opposite side first, then the sides. */\nconst FALLBACKS: Record<WrTourPlacement, readonly WrTourPlacement[]> = {\n bottom: ['bottom', 'top', 'right', 'left'],\n top: ['top', 'bottom', 'right', 'left'],\n left: ['left', 'right', 'bottom', 'top'],\n right: ['right', 'left', 'bottom', 'top'],\n};\n\nconst CONNECTED: Record<\n WrTourPlacement,\n {\n originX: 'start' | 'center' | 'end';\n originY: 'top' | 'center' | 'bottom';\n overlayX: 'start' | 'center' | 'end';\n overlayY: 'top' | 'center' | 'bottom';\n }\n> = {\n bottom: { originX: 'center', originY: 'bottom', overlayX: 'center', overlayY: 'top' },\n top: { originX: 'center', originY: 'top', overlayX: 'center', overlayY: 'bottom' },\n left: { originX: 'start', originY: 'center', overlayX: 'end', overlayY: 'center' },\n right: { originX: 'end', originY: 'center', overlayX: 'start', overlayY: 'center' },\n};\n\n/**\n * Guided product tour: a spotlight over one element at a time plus a popup\n * explaining it.\n *\n * Steps are data, not markup — call `start()` with an array and the service owns\n * the overlay, the cut-out, focus and the keyboard. A step whose target is not\n * on the page is skipped rather than shown floating, so a tour survives a\n * feature being hidden behind a flag or a permission.\n *\n * @example\n * ```ts\n * private readonly tour = inject(WrTour);\n *\n * showMeAround(): void {\n * this.tour.start([\n * { target: '[data-tour=\"search\"]', title: 'Search', content: 'Find anything by name.' },\n * { target: '[data-tour=\"filters\"]', content: 'Narrow the list down.', placement: 'right' },\n * ]);\n * }\n * ```\n *\n * @see https://ngwr.dev/reference/services/tour\n */\n@Service()\nexport class WrTour {\n private readonly overlay = inject(WR_OVERLAY);\n private readonly dir = inject(Directionality, { optional: true });\n private readonly scrollStrategies = inject(ScrollStrategyOptions);\n private readonly injector = inject(EnvironmentInjector);\n private readonly focusTrapFactory = inject(ConfigurableFocusTrapFactory);\n private readonly document = inject(DOCUMENT);\n private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n private readonly location = inject(Location);\n\n private readonly steps = signal<readonly WrTourStep[]>([]);\n private readonly cursor = signal(-1);\n\n private overlayRef: OverlayRef | null = null;\n private focusTrap: ConfigurableFocusTrap | null = null;\n private spotlight: HTMLElement | null = null;\n private detachKeydown: (() => void) | null = null;\n private detachReposition: (() => void) | null = null;\n private restoreFocus: HTMLElement | null = null;\n private autoFocus: WrOverlayAutoFocus = 'dialog';\n /** `focusNext` for the card, see {@link WrTourController}. */\n readonly focusNext = (): boolean => this.autoFocus === 'first-tabbable';\n private stopWatchingUrl: (() => void) | null = null;\n\n /** Whether a tour is running. */\n readonly active = computed(() => this.cursor() >= 0);\n\n /** Zero-based index of the current step, `-1` when idle. */\n readonly index = computed(() => this.cursor());\n\n /** How many steps this tour has. */\n readonly total = computed(() => this.steps().length);\n\n /** The step being shown, or `null` when idle. */\n readonly step = computed<WrTourStep | null>(() => this.steps()[this.cursor()] ?? null);\n\n // Whether any step AFTER the current one can actually be shown. Settled once per\n // move, in `goTo`, because reachability is a DOM question and not a signal.\n private readonly noStepAfter = signal(false);\n\n // The same question looking the other way. Settled in `goTo` for the same reason.\n //\n // `true` at rest, and the asymmetry with `noStepAfter` is deliberate: with no\n // tour running there is no step, so both questions are vacuous, and the pair\n // is set to whatever keeps a naive template honest. `@if (!tour.isFirst())`\n // around a Back button is the obvious way to write it, and at `false` that\n // button appears with no tour on screen.\n private readonly noStepBefore = signal(true);\n\n /**\n * Whether this is the last step the user will see. Not `index() === total() - 1`:\n * a trailing step whose target is missing is skipped, so comparing against the\n * raw count left the primary button reading \"Next\" on the final card and then\n * ending the tour when it was pressed. `false` while no tour is running.\n */\n readonly isLast = computed(() => this.noStepAfter());\n\n /**\n * Whether this is the first step the user will see. Not `index() === 0`, for the\n * mirror of the reason above: a LEADING step whose target is missing is skipped,\n * so the tour opens on a later index and the raw one put a Back button on the\n * first card — one that did nothing at all, because `prev()` walks off the start\n * and returns without moving. `true` while no tour is running — see the signal\n * it reads.\n */\n readonly isFirst = computed(() => this.noStepBefore());\n\n constructor() {\n // Everything this service owns lives OUTSIDE its own injector: a CDK overlay, a\n // div appended to `document.body`, a document keydown listener and two window\n // listeners. Nothing removes them when the injector goes, so a tour running at\n // teardown left its cut-out on the page.\n inject(DestroyRef).onDestroy(() => this.stop());\n }\n\n /**\n * Begin a tour. Restarts if one is already running. A no-op under SSR — a\n * tour is a client-side affordance and there is nothing to spotlight on the\n * server.\n */\n start(steps: readonly WrTourStep[], options: WrTourOptions = {}): void {\n if (!this.isBrowser || steps.length === 0) return;\n this.stop();\n this.steps.set(steps);\n this.autoFocus = options.autoFocus ?? 'dialog';\n this.restoreFocus = this.document.activeElement as HTMLElement | null;\n // A tour belongs to the page it was started on, the way `WrDialog` and\n // `WrDrawerManager` tie a modal to its URL. Nothing ended it on navigation,\n // so following a link mid-tour left the card pointing at an element the\n // router had just removed — the cut-out collapsed to a 12px box at the\n // corner, its 9999px shadow dimming the whole new page, and focus trapped in\n // a card about the page the user had left. `onUrlChange` rather than\n // `subscribe()`, which hears popstate alone and misses `router.navigate()`.\n this.stopWatchingUrl = this.location.onUrlChange(() => this.stop());\n this.goTo(0, 1);\n }\n\n /** Advance; finishes the tour past the last step. */\n next(): void {\n this.goTo(this.cursor() + 1, 1);\n }\n\n /** Go back; stays put on the first step. */\n prev(): void {\n this.goTo(this.cursor() - 1, -1);\n }\n\n /** End the tour and return focus where it was. */\n stop(): void {\n // Unhooked a microtask late, as `WrDialog` does: `Location` notifies with a\n // `forEach`, and unregistering from inside that notification splices the\n // array it is walking, which would skip the listener after ours.\n const unwatch = this.stopWatchingUrl;\n this.stopWatchingUrl = null;\n if (unwatch) queueMicrotask(unwatch);\n this.teardownStep();\n this.steps.set([]);\n this.cursor.set(-1);\n // Back to their resting answers. Without this a finished tour left both\n // holding whatever its last step said, so `isFirst` and `isLast` were the\n // only two signals here that still described a tour that had ended — while\n // `active`, `index`, `total` and `step` all reported idle.\n this.noStepAfter.set(false);\n this.noStepBefore.set(true);\n if (this.restoreFocus && typeof this.restoreFocus.focus === 'function') wrRestoreFocus(this.restoreFocus);\n this.restoreFocus = null;\n }\n\n /**\n * Move to `index`, skipping steps whose target is not in the DOM. `direction`\n * says which way to keep skipping, so a missing step never traps the tour\n * between two dead ends.\n */\n private goTo(index: number, direction: 1 | -1): void {\n const steps = this.steps();\n let i = index;\n while (i >= 0 && i < steps.length && this.resolve(steps[i]) === null) i += direction;\n\n if (i < 0) {\n // Ran off the start while going back — stay where we were.\n return;\n }\n if (i >= steps.length) {\n this.stop();\n return;\n }\n\n // Focus inside the card that is about to go stays in the tour: the next card\n // takes it, whatever `autoFocus` says about a card opening.\n const active = this.document.activeElement;\n const hadFocus = !!active && !!this.overlayRef?.overlayElement.contains(active);\n this.teardownStep();\n this.cursor.set(i);\n this.noStepAfter.set(!this.anyResolvableAfter(i));\n this.noStepBefore.set(!this.anyResolvableBefore(i));\n this.openStep(steps[i], hadFocus);\n }\n\n /** Whether the tour has a step past `index` that can actually be shown. */\n private anyResolvableAfter(index: number): boolean {\n const steps = this.steps();\n for (let i = index + 1; i < steps.length; i += 1) {\n if (this.resolve(steps[i]) !== null) return true;\n }\n return false;\n }\n\n /** Whether the tour has a step before `index` that can actually be shown. */\n private anyResolvableBefore(index: number): boolean {\n const steps = this.steps();\n for (let i = index - 1; i >= 0; i -= 1) {\n if (this.resolve(steps[i]) !== null) return true;\n }\n return false;\n }\n\n private resolve(step: WrTourStep): HTMLElement | null {\n if (typeof step.target !== 'string') return step.target.isConnected ? step.target : null;\n return this.document.querySelector<HTMLElement>(step.target);\n }\n\n private openStep(step: WrTourStep, hadFocus: boolean): void {\n const target = this.resolve(step);\n if (!target) return;\n\n target.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'smooth' });\n\n // The cut-out is a bare element sized to the target with an enormous spread\n // shadow: everything outside it dims, the target itself stays untouched.\n // Cheaper and far more robust than a clip-path polygon, and it needs no\n // recompute when the page reflows beyond moving the box.\n const spotlight = this.document.createElement('div');\n spotlight.className = 'wr-tour__spotlight';\n spotlight.setAttribute('aria-hidden', 'true');\n this.document.body.appendChild(spotlight);\n this.spotlight = spotlight;\n this.placeSpotlight(target);\n\n const placement = step.placement ?? 'bottom';\n const positionStrategy = this.overlay\n .position()\n .flexibleConnectedTo(target)\n .withPositions(this.stepPositions(placement, this.isRtl()))\n .withPush(true);\n\n this.overlayRef = this.overlay.create({\n positionStrategy,\n scrollStrategy: this.scrollStrategies.reposition(),\n panelClass: wrToClassList('wr-tour-overlay', step.panelClass),\n });\n\n // The CDK read the direction once, just now. A tour is long-lived by nature\n // — a step can sit on screen while the user changes a language setting — and\n // without this the card keeps the direction the step opened in, with the\n // 12px gap that held it clear of the spotlight now pointing into it.\n // Per step, because every move disposes this ref and builds the next.\n //\n // The cut-out moves with it. The target itself changes place when the page\n // mirrors, and the spotlight is re-measured only on scroll and resize, so a\n // flip left it highlighting empty space while the card, re-placed by the CDK,\n // pointed at the target sitting under the dim. The flip has already been laid\n // out by the time this runs — the CDK measures the same element right after.\n wrFollowDirection(this.overlayRef, this.dir, this.injector, direction => {\n positionStrategy.withPositions(this.stepPositions(placement, direction === 'rtl'));\n this.placeSpotlight(target);\n });\n\n const portal = new ComponentPortal(\n WrTourPopup,\n null,\n Injector.create({ parent: this.injector, providers: [{ provide: WR_TOUR_STEP, useValue: this }] })\n );\n const ref = this.overlayRef.attach(portal);\n\n // Kept on the instance, not in a local: a trap registers with CDK's\n // `FocusTrapManager` and installs a capture-phase document focus listener, so an\n // undestroyed one leaks per STEP and every tour left a stack of them behind.\n const card = ref.location.nativeElement as HTMLElement;\n this.focusTrap = this.focusTrapFactory.create(card);\n // Onto Next only when asked. Otherwise the card itself takes focus, so the\n // keyboard is in the tour and no button is lit; under `false` only when the\n // card before it held focus, which would otherwise fall to `<body>`.\n wrFocusOverlay(\n card,\n this.focusTrap,\n this.autoFocus === false && hadFocus ? 'dialog' : this.autoFocus,\n this.injector\n );\n\n const onKey = (event: KeyboardEvent): void => {\n // The listener is on the document, so a step shown over a dialog would see the\n // Escape that dialog just handled and close the tour too.\n if (event.key === 'Escape' && !event.defaultPrevented) {\n event.preventDefault();\n this.stop();\n }\n };\n this.document.addEventListener('keydown', onKey);\n this.detachKeydown = () => this.document.removeEventListener('keydown', onKey);\n\n const reposition = (): void => this.placeSpotlight(target);\n window.addEventListener('scroll', reposition, true);\n window.addEventListener('resize', reposition);\n this.detachReposition = () => {\n window.removeEventListener('scroll', reposition, true);\n window.removeEventListener('resize', reposition);\n };\n }\n\n /**\n * The card's fallback table for one placement, with its inline offsets already\n * mirrored. Built per call rather than per step: the direction can change while\n * the step is on screen, and a table is what has to be rebuilt when it does.\n */\n private stepPositions(placement: WrTourPlacement, isRtl: boolean): ConnectedPosition[] {\n return wrMirrorOffsets(\n FALLBACKS[placement].map(side => ({\n ...CONNECTED[side],\n offsetY: side === 'bottom' ? 12 : side === 'top' ? -12 : 0,\n offsetX: side === 'right' ? 12 : side === 'left' ? -12 : 0,\n })),\n isRtl\n );\n }\n\n private placeSpotlight(target: HTMLElement): void {\n const el = this.spotlight;\n if (!el) return;\n const r = target.getBoundingClientRect();\n const pad = 6;\n el.style.top = `${r.top - pad}px`;\n el.style.left = `${r.left - pad}px`;\n el.style.width = `${r.width + pad * 2}px`;\n el.style.height = `${r.height + pad * 2}px`;\n }\n\n private teardownStep(): void {\n this.focusTrap?.destroy();\n this.focusTrap = null;\n this.detachKeydown?.();\n this.detachKeydown = null;\n this.detachReposition?.();\n this.detachReposition = null;\n this.overlayRef?.dispose();\n this.overlayRef = null;\n this.spotlight?.remove();\n this.spotlight = null;\n }\n\n /**\n * Whether the app reads right-to-left.\n *\n * Optional inject: `Directionality` is root-provided, so this is never null in\n * an app — but a bare `TestBed` that provides nothing should still get a\n * component that works, and defaulting to LTR is the honest fallback.\n */\n private isRtl(): boolean {\n return this.dir?.value === 'rtl';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyCA,MAAa,eAAe,IAAI,eAAiC,cAAc;AAqB/E,IAAa,cAAb,MAAa,YAAW;CACtB,cAAA;EACE,IAAI,OAAO,cAAc,eAAe,WAAW,cAAc,MAAM;CACzE;CAEmB,OAAO,OAAO,YAAY;CAI1B,YAAY,eAAe,aAAa,MAAM;CAC9C,YAAY,eAAe,aAAa,MAAM;CAC9C,YAAY,eAAe,aAAa,MAAM;CAC9C,YAAY,eAAe,aAAa,WAAW;CAGnD,WAAW,iBAAiB,iBAAiB,+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SAAS,GAAO;CACzC;CAEQ,eAAY;EAClB,KAAK,WAAW,QAAO;EACvB,KAAK,YAAY;EACjB,KAAK,gBAAe;EACpB,KAAK,gBAAgB;EACrB,KAAK,mBAAkB;EACvB,KAAK,mBAAmB;EACxB,KAAK,YAAY,QAAO;EACxB,KAAK,aAAa;EAClB,KAAK,WAAW,OAAM;EACtB,KAAK,YAAY;CACnB;CASQ,QAAK;EACX,OAAO,KAAK,KAAK,UAAU;CAC7B;CA9TW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAM,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAN,OAAA,QAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;CAAM,CAAA;;AAAN,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAM,YAAA,CAAA,EADlB,MAAA,Q"}
@@ -23,6 +23,10 @@ var WrTypography = class WrTypography {
23
23
  ...ngDevMode ? { debugName: "mono" } : /* istanbul ignore next */ {},
24
24
  transform: coerceBooleanProperty
25
25
  });
26
+ numeric = input(false, {
27
+ ...ngDevMode ? { debugName: "numeric" } : /* istanbul ignore next */ {},
28
+ transform: coerceBooleanProperty
29
+ });
26
30
  classes = computed(() => {
27
31
  const parts = [`wr-typography--${this.variant()}`];
28
32
  const tone = this.tone();
@@ -31,6 +35,7 @@ var WrTypography = class WrTypography {
31
35
  if (align) parts.push(`wr-typography--align-${align}`);
32
36
  if (this.truncate()) parts.push("wr-typography--truncate");
33
37
  if (this.mono() || this.variant() === "code") parts.push("wr-typography--mono");
38
+ if (this.numeric()) parts.push("wr-typography--numeric");
34
39
  return parts.join(" ");
35
40
  }, ...ngDevMode ? [{ debugName: "classes" }] : /* istanbul ignore next */ []);
36
41
  static ɵfac = i0.ɵɵngDeclareFactory({
@@ -82,6 +87,13 @@ var WrTypography = class WrTypography {
82
87
  isSignal: true,
83
88
  isRequired: false,
84
89
  transformFunction: null
90
+ },
91
+ numeric: {
92
+ classPropertyName: "numeric",
93
+ publicName: "numeric",
94
+ isSignal: true,
95
+ isRequired: false,
96
+ transformFunction: null
85
97
  }
86
98
  },
87
99
  host: {
@@ -147,6 +159,14 @@ i0.ɵɵngDeclareClassMetadata({
147
159
  alias: "mono",
148
160
  required: false
149
161
  }]
162
+ }],
163
+ numeric: [{
164
+ type: i0.Input,
165
+ args: [{
166
+ isSignal: true,
167
+ alias: "numeric",
168
+ required: false
169
+ }]
150
170
  }]
151
171
  }
152
172
  });
@@ -1 +1 @@
1
- {"version":3,"file":"ngwr-typography.mjs","names":[],"sources":["../../../projects/lib/typography/typography.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { coerceBooleanProperty } from '@angular/cdk/coercion';\nimport { Directive, computed, input } from '@angular/core';\n\nimport { wrCheckStyles } from 'ngwr/utils';\n\nimport type { WrTypographyAlign, WrTypographyTone, WrTypographyVariant } from './types';\n\n/**\n * Semantic typography directive. Attaches to any native element and\n * applies the visual treatment for the chosen `variant` (`h1`–`h6`,\n * `display`, `lead`, `body`, `small`, `caption`, `overline`, `code`, `list`,\n * `link`).\n *\n * Reads from the same `--wr-text-*` / `--wr-font-weight-*` / `--wr-leading-*`\n * tokens used by the opt-in typography utility classes — themeable by\n * overriding tokens at `:root`.\n *\n * @example\n * ```html\n * <h1 wrTypography variant=\"display\">Build interfaces</h1>\n * <h2 wrTypography variant=\"h2\" tone=\"primary\">that feel alive.</h2>\n * <p wrTypography variant=\"lead\">A developer-first library.</p>\n * <span wrTypography variant=\"caption\" tone=\"muted\">v1.6.0 — released today</span>\n * <code wrTypography variant=\"code\">inject(WrTheme)</code>\n * ```\n *\n * @see https://ngwr.dev/guides/typography/overview\n */\n@Directive({\n selector: '[wrTypography]',\n host: { class: 'wr-typography', '[class]': 'classes()' },\n})\nexport class WrTypography {\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('typography');\n }\n\n /** Visual variant. @default 'body' */\n readonly variant = input<WrTypographyVariant>('body');\n\n /**\n * Color tone. `null` (default) keeps the variant's own color — the page ink\n * for headings and body, the muted role for `lead`, `caption`, `overline`\n * and `list`, primary for links. `tone=\"base\"` pulls a muted variant back to\n * the page ink.\n * Every other tone is emphasis only: a tone never carries a state on its\n * own. Four of the five intents share one lightness, and `success` against\n * `danger` is 1.05:1 as text, so the words have to name the state\n * (`500 Server Error`, not a red `Request`) — or reach for `<wr-alert>`,\n * which draws a glyph per type.\n */\n readonly tone = input<WrTypographyTone | null>(null);\n\n /** Horizontal alignment. */\n readonly align = input<WrTypographyAlign | null>(null);\n\n /** Truncate to single line with ellipsis. @default false */\n readonly truncate = input(false, { transform: coerceBooleanProperty });\n\n /** Render with monospace font. @default false (auto-true for `code`) */\n readonly mono = input(false, { transform: coerceBooleanProperty });\n\n protected readonly classes = computed(() => {\n const parts = [`wr-typography--${this.variant()}`];\n const tone = this.tone();\n if (tone) parts.push(`wr-typography--tone-${tone}`);\n const align = this.align();\n if (align) parts.push(`wr-typography--align-${align}`);\n if (this.truncate()) parts.push('wr-typography--truncate');\n if (this.mono() || this.variant() === 'code') parts.push('wr-typography--mono');\n return parts.join(' ');\n });\n}\n"],"mappings":";;;;;;;;;;AAuCA,IAAa,eAAb,MAAa,aAAY;CACvB,cAAA;EACE,IAAI,OAAO,cAAc,eAAe,WAAW,cAAc,YAAY;CAC/E;CAGS,UAAU,MAA2B,QAAO,GAAA,YAAA,CAAA,EAAA,WAAA,UAAA,CAAA,+BAAA,CAAA,CAAA;CAa5C,OAAO,MAA+B,MAAK,GAAA,YAAA,CAAA,EAAA,WAAA,OAAA,CAAA,+BAAA,CAAA,CAAA;CAG3C,QAAQ,MAAgC,MAAK,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+B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;GAAA,MAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;EAAA;EAAA,MAAA;GAAA,YAAA,EAAA,SAAA,YAAA;GAAA,gBAAA;EAAA;EAAA,UAAA;CAAA,CAAA;;AAAZ,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAY,YAAA,CAAA;EAJxB,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,MAAM;IAAE,OAAO;IAAiB,WAAW;GAAW;EACvD,CAAA"}
1
+ {"version":3,"file":"ngwr-typography.mjs","names":[],"sources":["../../../projects/lib/typography/typography.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { coerceBooleanProperty } from '@angular/cdk/coercion';\nimport { Directive, computed, input } from '@angular/core';\n\nimport { wrCheckStyles } from 'ngwr/utils';\n\nimport type { WrTypographyAlign, WrTypographyTone, WrTypographyVariant } from './types';\n\n/**\n * Semantic typography directive. Attaches to any native element and\n * applies the visual treatment for the chosen `variant` (`h1`–`h6`,\n * `display`, `lead`, `body`, `small`, `caption`, `overline`, `code`, `list`,\n * `link`).\n *\n * Reads from the same `--wr-text-*` / `--wr-font-weight-*` / `--wr-leading-*`\n * tokens used by the opt-in typography utility classes — themeable by\n * overriding tokens at `:root`.\n *\n * @example\n * ```html\n * <h1 wrTypography variant=\"display\">Build interfaces</h1>\n * <h2 wrTypography variant=\"h2\" tone=\"primary\">that feel alive.</h2>\n * <p wrTypography variant=\"lead\">A developer-first library.</p>\n * <span wrTypography variant=\"caption\" tone=\"muted\">v1.6.0 — released today</span>\n * <code wrTypography variant=\"code\">inject(WrTheme)</code>\n * ```\n *\n * @see https://ngwr.dev/guides/typography/overview\n */\n@Directive({\n selector: '[wrTypography]',\n host: { class: 'wr-typography', '[class]': 'classes()' },\n})\nexport class WrTypography {\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('typography');\n }\n\n /** Visual variant. @default 'body' */\n readonly variant = input<WrTypographyVariant>('body');\n\n /**\n * Color tone. `null` (default) keeps the variant's own color — the page ink\n * for headings and body, the muted role for `lead`, `caption`, `overline`\n * and `list`, primary for links. `tone=\"base\"` pulls a muted variant back to\n * the page ink.\n * Every other tone is emphasis only: a tone never carries a state on its\n * own. Four of the five intents share one lightness, and `success` against\n * `danger` is 1.05:1 as text, so the words have to name the state\n * (`500 Server Error`, not a red `Request`) — or reach for `<wr-alert>`,\n * which draws a glyph per type.\n */\n readonly tone = input<WrTypographyTone | null>(null);\n\n /** Horizontal alignment. */\n readonly align = input<WrTypographyAlign | null>(null);\n\n /** Truncate to single line with ellipsis. @default false */\n readonly truncate = input(false, { transform: coerceBooleanProperty });\n\n /** Render with monospace font. @default false (auto-true for `code`) */\n readonly mono = input(false, { transform: coerceBooleanProperty });\n\n /** Tabular digits: every digit takes the same width, so amounts line up in a column. @default false */\n readonly numeric = input(false, { transform: coerceBooleanProperty });\n\n protected readonly classes = computed(() => {\n const parts = [`wr-typography--${this.variant()}`];\n const tone = this.tone();\n if (tone) parts.push(`wr-typography--tone-${tone}`);\n const align = this.align();\n if (align) parts.push(`wr-typography--align-${align}`);\n if (this.truncate()) parts.push('wr-typography--truncate');\n if (this.mono() || this.variant() === 'code') parts.push('wr-typography--mono');\n if (this.numeric()) parts.push('wr-typography--numeric');\n return parts.join(' ');\n });\n}\n"],"mappings":";;;;;;;;;;AAuCA,IAAa,eAAb,MAAa,aAAY;CACvB,cAAA;EACE,IAAI,OAAO,cAAc,eAAe,WAAW,cAAc,YAAY;CAC/E;CAGS,UAAU,MAA2B,QAAO,GAAA,YAAA,CAAA,EAAA,WAAA,UAAA,CAAA,+BAAA,CAAA,CAAA;CAa5C,OAAO,MAA+B,MAAK,GAAA,YAAA,CAAA,EAAA,WAAA,OAAA,CAAA,+BAAA,CAAA,CAAA;CAG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AA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,OAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,UAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,MAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,SAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;EAAA;EAAA,MAAA;GAAA,YAAA,EAAA,SAAA,YAAA;GAAA,gBAAA;EAAA;EAAA,UAAA;CAAA,CAAA;;AAAZ,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAY,YAAA,CAAA;EAJxB,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,MAAM;IAAE,OAAO;IAAiB,WAAW;GAAW;EACvD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"ngwr-utils-router.mjs","names":[],"sources":["../../../projects/lib/utils/router/query-param.ts","../../../projects/lib/utils/router/render-on-navigation.ts","../../../projects/lib/utils/router/public-api.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { isPlatformBrowser } from '@angular/common';\nimport {\n DestroyRef,\n PLATFORM_ID,\n Service,\n type WritableSignal,\n assertInInjectionContext,\n inject,\n signal,\n untracked,\n} from '@angular/core';\nimport {\n NavigationCancel,\n NavigationEnd,\n NavigationError,\n NavigationSkipped,\n NavigationStart,\n type Params,\n Router,\n} from '@angular/router';\n\nimport type { WrQueryParamOptions, WrQueryParamStringOptions } from './types';\n\n/** One signal following one parameter. */\ninterface Follower {\n readonly name: string;\n /** The raw value the signal last agreed with, `null` for absent. */\n raw: string | null;\n readonly decode: (raw: string | null) => unknown;\n /** The setter the signal was born with: moves it without writing the address. */\n readonly write: (value: unknown) => void;\n}\n\n/**\n * The one writer behind every {@link wrQueryParam}: collects the writes of a\n * task and navigates once with all of them, and moves every follower when a\n * navigation settles.\n */\n@Service()\nclass WrQueryParams {\n private readonly router = inject(Router);\n private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n private readonly followers = new Set<Follower>();\n /** Writes not yet navigated, per parameter: the raw value, `null` to remove. */\n private readonly batch = new Map<string, { readonly from: Follower; readonly raw: string | null }>();\n private replaceUrl = false;\n private scheduled = false;\n private inFlight: boolean;\n\n constructor() {\n this.inFlight = untracked(this.router.currentNavigation) !== null;\n const sub = this.router.events.subscribe(event => {\n if (event instanceof NavigationStart) this.inFlight = true;\n else if (\n event instanceof NavigationEnd ||\n event instanceof NavigationCancel ||\n event instanceof NavigationError ||\n event instanceof NavigationSkipped\n ) {\n this.inFlight = false;\n this.settle();\n }\n });\n inject(DestroyRef).onDestroy(() => sub.unsubscribe());\n }\n\n /** The parameter as the router holds it: the first value of a repeated one. */\n raw(name: string): string | null {\n return this.router.routerState.snapshot.root.queryParamMap.get(name);\n }\n\n follow(follower: Follower): () => void {\n this.followers.add(follower);\n return () => this.followers.delete(follower);\n }\n\n write(from: Follower, raw: string | null, replaceUrl: boolean): void {\n if (!this.isBrowser) return;\n this.replaceUrl = this.batch.size === 0 ? replaceUrl : this.replaceUrl && replaceUrl;\n this.batch.set(from.name, { from, raw });\n this.schedule();\n }\n\n private schedule(): void {\n if (this.scheduled) return;\n this.scheduled = true;\n queueMicrotask(() => {\n this.scheduled = false;\n this.flush();\n });\n }\n\n private flush(): void {\n // A navigation in flight is left to land; `settle()` flushes after it, onto\n // the address it produced. Navigating now would supersede it, and a link\n // the user clicked would be lost to a keystroke.\n if (this.batch.size === 0 || this.inFlight) return;\n const current = this.router.routerState.snapshot.root.queryParams;\n const queryParams: Params = {};\n let changed = false;\n for (const [name, { raw }] of this.batch) {\n queryParams[name] = raw;\n const was: unknown = current[name];\n if (raw !== (typeof was === 'string' ? was : was == null ? null : undefined)) changed = true;\n }\n const replaceUrl = this.replaceUrl;\n this.batch.clear();\n if (!changed) {\n // Two signals of one parameter can write opposite values in a task.\n this.settle();\n return;\n }\n void this.router.navigate([], { queryParams, queryParamsHandling: 'merge', preserveFragment: true, replaceUrl });\n }\n\n /** Every follower takes the address as it stands, except one with a write still to go. */\n private settle(): void {\n // A write that waited for the navigation which destroyed its signal belongs\n // to the page that navigation left, not to the address it produced.\n for (const [name, { from }] of this.batch) if (!this.followers.has(from)) this.batch.delete(name);\n for (const follower of this.followers) {\n if (this.batch.has(follower.name)) continue;\n const raw = this.raw(follower.name);\n if (raw === follower.raw) continue;\n follower.raw = raw;\n follower.write(follower.decode(raw));\n }\n if (this.batch.size > 0) this.schedule();\n }\n}\n\n/**\n * A writable signal linked to one query parameter.\n *\n * ```ts\n * readonly q = wrQueryParam('q');\n * readonly page = wrQueryParam<number>('page', { default: 1, parse: raw => Number(raw) || 1, serialize: String });\n * ```\n *\n * - **Reads** follow the address: Back, Forward and any navigation that\n * changes the parameter move the signal. An absent parameter reads as\n * `default`; a repeated one reads its first value.\n * - **Writes** are `set` and `update`, as on any signal. The signal takes the\n * value at once, and one navigation per task carries every write made in\n * it, across every `wrQueryParam` signal of the app. Other parameters and\n * the fragment survive it. Writing `default` removes the parameter, and a\n * write that changes nothing navigates nothing.\n * - **`replaceUrl`** is per signal. When writes with and without it meet in one\n * task, the navigation pushes: a history entry replaced by mistake is lost,\n * one pushed by mistake is one more Back.\n * - **A write during a navigation** waits for it, then lands on the address\n * it produced. A navigation of this signal's own that is cancelled, fails\n * or is superseded leaves the address as it was, and the signal reads it\n * again: a lost write is read back, never kept.\n * - **A string needs no options.** Any other `T` needs `default`, `parse` and\n * `serialize`. The address is user input: a `parse` that throws reads as\n * `default`, and what else it cannot read is for it to decide.\n * - **Lifetime.** Needs an injection context and follows the address until that\n * context is destroyed. A write already made is navigated all the same,\n * unless it was waiting for the navigation that destroyed the context: the\n * address that navigation produced belongs to another page.\n * - **On the server** it reads the parameter from the router, and a write\n * moves the signal only; nothing navigates during prerender. Hydration\n * navigates nothing either, since reading never does.\n *\n * Lives in `ngwr/utils/router`, since `@angular/router` is an optional peer.\n *\n * @param name - The parameter's name in the address.\n * @param options - `default` and `replaceUrl`, plus `parse` and `serialize` for a type other than `string`.\n * @returns The signal.\n */\nexport function wrQueryParam(name: string, options?: WrQueryParamStringOptions): WritableSignal<string>;\n// eslint-disable-next-line no-redeclare -- an overload, so `T` is inferred from `parse`\nexport function wrQueryParam<T>(name: string, options: WrQueryParamOptions<T>): WritableSignal<T>;\n// eslint-disable-next-line no-redeclare -- the implementation behind the two overloads\nexport function wrQueryParam<T>(\n name: string,\n options: WrQueryParamStringOptions | WrQueryParamOptions<T> = {}\n): WritableSignal<T> {\n assertInInjectionContext(wrQueryParam);\n const params = inject(WrQueryParams);\n const typed = 'parse' in options ? options : null;\n const fallback = (typed ? typed.default : (options.default ?? '')) as T;\n const parse = typed ? typed.parse : (raw: string): T => raw as T;\n const serialize = typed ? typed.serialize : (value: T): string => value as string;\n const replaceUrl = options.replaceUrl ?? false;\n\n let fallbackRaw: string | undefined;\n try {\n fallbackRaw = serialize(fallback);\n } catch {\n fallbackRaw = undefined;\n }\n\n const decode = (raw: string | null): T => {\n if (raw === null) return fallback;\n try {\n return parse(raw);\n } catch {\n return fallback;\n }\n };\n const encode = (value: T): string | null => {\n if (Object.is(value, fallback)) return null;\n const raw = serialize(value);\n return raw === fallbackRaw ? null : raw;\n };\n\n const raw = params.raw(name);\n const sig = signal<T>(decode(raw));\n const write = sig.set.bind(sig);\n const follower: Follower = { name, raw, decode, write: write as (value: unknown) => void };\n\n sig.set = value => {\n const next = encode(value);\n follower.raw = next;\n write(value);\n params.write(follower, next, replaceUrl);\n };\n sig.update = fn => sig.set(fn(untracked(sig)));\n\n inject(DestroyRef).onDestroy(params.follow(follower));\n return sig;\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { ApplicationRef, DestroyRef, inject, provideAppInitializer } from '@angular/core';\nimport { NavigationEnd, Router } from '@angular/router';\n\nimport { type WrFeature, wrFeature } from 'ngwr/utils';\n\n/**\n * `provideWr()` feature: render a routed page in the task that inserted it.\n *\n * Zoneless, the router inserts the new page into the DOM in one task and its\n * first change detection runs in a later one (Angular schedules it as a\n * macrotask, by design: angular/angular#57528). A browser that styles the page\n * in between sees elements without their bound classes and attributes, and any\n * CSS transition on them then fades from the browser's defaults to the app's\n * look on every page switch. Ticking right after `NavigationEnd`, before the\n * task ends, binds the page before the browser paints it. The scheduled tick is\n * cancelled by this one, so nothing runs twice.\n *\n * ngwr's own components carry their base class statically and do not depend on\n * this; it covers the app's own bindings on a routed page.\n *\n * @example\n * ```ts\n * provideWr(withRenderOnNavigation())\n * ```\n */\nexport function withRenderOnNavigation(): WrFeature<'render-on-navigation'> {\n return wrFeature('render-on-navigation', [\n provideAppInitializer(() => {\n const appRef = inject(ApplicationRef);\n const subscription = inject(Router).events.subscribe(event => {\n // A microtask, not `afterNextRender`: it has to run before the task that\n // inserted the page ends, and a tick inside the router's own event\n // emission could re-enter one already running.\n if (event instanceof NavigationEnd) queueMicrotask(() => appRef.tick());\n });\n inject(DestroyRef).onDestroy(() => subscription.unsubscribe());\n }),\n ]);\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nexport { wrQueryParam } from './query-param';\nexport { withRenderOnNavigation } from './render-on-navigation';\nexport type { WrQueryParamOptions, WrQueryParamStringOptions } from './types';\n"],"mappings":";;;;;;;;;;;AA6CA,IACM,gBADN,MACM,cAAa;CACA,SAAS,OAAO,MAAM;CACtB,YAAY,kBAAkB,OAAO,WAAW,CAAC;CACjD,4BAAY,IAAI,IAAG;C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","names":[],"sources":["../../../projects/lib/utils/router/query-param.ts","../../../projects/lib/utils/router/render-on-navigation.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { isPlatformBrowser } from '@angular/common';\nimport {\n DestroyRef,\n PLATFORM_ID,\n Service,\n type WritableSignal,\n assertInInjectionContext,\n inject,\n signal,\n untracked,\n} from '@angular/core';\nimport {\n NavigationCancel,\n NavigationEnd,\n NavigationError,\n NavigationSkipped,\n NavigationStart,\n type Params,\n Router,\n} from '@angular/router';\n\nimport type { WrQueryParamOptions, WrQueryParamStringOptions } from './types';\n\n/** One signal following one parameter. */\ninterface Follower {\n readonly name: string;\n /** The raw value the signal last agreed with, `null` for absent. */\n raw: string | null;\n readonly decode: (raw: string | null) => unknown;\n /** The setter the signal was born with: moves it without writing the address. */\n readonly write: (value: unknown) => void;\n}\n\n/**\n * The one writer behind every {@link wrQueryParam}: collects the writes of a\n * task and navigates once with all of them, and moves every follower when a\n * navigation settles.\n */\n@Service()\nclass WrQueryParams {\n private readonly router = inject(Router);\n private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n private readonly followers = new Set<Follower>();\n /** Writes not yet navigated, per parameter: the raw value, `null` to remove. */\n private readonly batch = new Map<string, { readonly from: Follower; readonly raw: string | null }>();\n private replaceUrl = false;\n private scheduled = false;\n private inFlight: boolean;\n\n constructor() {\n this.inFlight = untracked(this.router.currentNavigation) !== null;\n const sub = this.router.events.subscribe(event => {\n if (event instanceof NavigationStart) this.inFlight = true;\n else if (\n event instanceof NavigationEnd ||\n event instanceof NavigationCancel ||\n event instanceof NavigationError ||\n event instanceof NavigationSkipped\n ) {\n this.inFlight = false;\n this.settle();\n }\n });\n inject(DestroyRef).onDestroy(() => sub.unsubscribe());\n }\n\n /** The parameter as the router holds it: the first value of a repeated one. */\n raw(name: string): string | null {\n return this.router.routerState.snapshot.root.queryParamMap.get(name);\n }\n\n follow(follower: Follower): () => void {\n this.followers.add(follower);\n return () => this.followers.delete(follower);\n }\n\n write(from: Follower, raw: string | null, replaceUrl: boolean): void {\n if (!this.isBrowser) return;\n this.replaceUrl = this.batch.size === 0 ? replaceUrl : this.replaceUrl && replaceUrl;\n this.batch.set(from.name, { from, raw });\n this.schedule();\n }\n\n private schedule(): void {\n if (this.scheduled) return;\n this.scheduled = true;\n queueMicrotask(() => {\n this.scheduled = false;\n this.flush();\n });\n }\n\n private flush(): void {\n // A navigation in flight is left to land; `settle()` flushes after it, onto\n // the address it produced. Navigating now would supersede it, and a link\n // the user clicked would be lost to a keystroke.\n if (this.batch.size === 0 || this.inFlight) return;\n const current = this.router.routerState.snapshot.root.queryParams;\n const queryParams: Params = {};\n let changed = false;\n for (const [name, { raw }] of this.batch) {\n queryParams[name] = raw;\n const was: unknown = current[name];\n if (raw !== (typeof was === 'string' ? was : was == null ? null : undefined)) changed = true;\n }\n const replaceUrl = this.replaceUrl;\n this.batch.clear();\n if (!changed) {\n // Two signals of one parameter can write opposite values in a task.\n this.settle();\n return;\n }\n void this.router.navigate([], { queryParams, queryParamsHandling: 'merge', preserveFragment: true, replaceUrl });\n }\n\n /** Every follower takes the address as it stands, except one with a write still to go. */\n private settle(): void {\n // A write that waited for the navigation which destroyed its signal belongs\n // to the page that navigation left, not to the address it produced.\n for (const [name, { from }] of this.batch) if (!this.followers.has(from)) this.batch.delete(name);\n for (const follower of this.followers) {\n if (this.batch.has(follower.name)) continue;\n const raw = this.raw(follower.name);\n if (raw === follower.raw) continue;\n follower.raw = raw;\n follower.write(follower.decode(raw));\n }\n if (this.batch.size > 0) this.schedule();\n }\n}\n\n/**\n * A writable signal linked to one query parameter.\n *\n * ```ts\n * readonly q = wrQueryParam('q');\n * readonly page = wrQueryParam<number>('page', { default: 1, parse: raw => Number(raw) || 1, serialize: String });\n * ```\n *\n * - **Reads** follow the address: Back, Forward and any navigation that\n * changes the parameter move the signal. An absent parameter reads as\n * `default`; a repeated one reads its first value.\n * - **Writes** are `set` and `update`, as on any signal. The signal takes the\n * value at once, and one navigation per task carries every write made in\n * it, across every `wrQueryParam` signal of the app. Other parameters and\n * the fragment survive it. Writing `default` removes the parameter, and a\n * write that changes nothing navigates nothing.\n * - **`replaceUrl`** is per signal. When writes with and without it meet in one\n * task, the navigation pushes: a history entry replaced by mistake is lost,\n * one pushed by mistake is one more Back.\n * - **A write during a navigation** waits for it, then lands on the address\n * it produced. A navigation of this signal's own that is cancelled, fails\n * or is superseded leaves the address as it was, and the signal reads it\n * again: a lost write is read back, never kept.\n * - **A string needs no options.** Any other `T` needs `default`, `parse` and\n * `serialize`. The address is user input: a `parse` that throws reads as\n * `default`, and what else it cannot read is for it to decide.\n * - **Lifetime.** Needs an injection context and follows the address until that\n * context is destroyed. A write already made is navigated all the same,\n * unless it was waiting for the navigation that destroyed the context: the\n * address that navigation produced belongs to another page.\n * - **On the server** it reads the parameter from the router, and a write\n * moves the signal only; nothing navigates during prerender. Hydration\n * navigates nothing either, since reading never does.\n *\n * Lives in `ngwr/utils/router`, since `@angular/router` is an optional peer.\n *\n * @param name - The parameter's name in the address.\n * @param options - `default` and `replaceUrl`, plus `parse` and `serialize` for a type other than `string`.\n * @returns The signal.\n */\nexport function wrQueryParam(name: string, options?: WrQueryParamStringOptions): WritableSignal<string>;\n// eslint-disable-next-line no-redeclare -- an overload, so `T` is inferred from `parse`\nexport function wrQueryParam<T>(name: string, options: WrQueryParamOptions<T>): WritableSignal<T>;\n// eslint-disable-next-line no-redeclare -- the implementation behind the two overloads\nexport function wrQueryParam<T>(\n name: string,\n options: WrQueryParamStringOptions | WrQueryParamOptions<T> = {}\n): WritableSignal<T> {\n assertInInjectionContext(wrQueryParam);\n const params = inject(WrQueryParams);\n const typed = 'parse' in options ? options : null;\n const fallback = (typed ? typed.default : (options.default ?? '')) as T;\n const parse = typed ? typed.parse : (raw: string): T => raw as T;\n const serialize = typed ? typed.serialize : (value: T): string => value as string;\n const replaceUrl = options.replaceUrl ?? false;\n\n let fallbackRaw: string | undefined;\n try {\n fallbackRaw = serialize(fallback);\n } catch {\n fallbackRaw = undefined;\n }\n\n const decode = (raw: string | null): T => {\n if (raw === null) return fallback;\n try {\n return parse(raw);\n } catch {\n return fallback;\n }\n };\n const encode = (value: T): string | null => {\n if (Object.is(value, fallback)) return null;\n const raw = serialize(value);\n return raw === fallbackRaw ? null : raw;\n };\n\n const raw = params.raw(name);\n const sig = signal<T>(decode(raw));\n const write = sig.set.bind(sig);\n const follower: Follower = { name, raw, decode, write: write as (value: unknown) => void };\n\n sig.set = value => {\n const next = encode(value);\n follower.raw = next;\n write(value);\n params.write(follower, next, replaceUrl);\n };\n sig.update = fn => sig.set(fn(untracked(sig)));\n\n inject(DestroyRef).onDestroy(params.follow(follower));\n return sig;\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { ApplicationRef, DestroyRef, inject, provideAppInitializer } from '@angular/core';\nimport { NavigationEnd, Router } from '@angular/router';\n\nimport { type WrFeature, wrFeature } from 'ngwr/utils';\n\n/**\n * `provideWr()` feature: render a routed page in the task that inserted it.\n *\n * Zoneless, the router inserts the new page into the DOM in one task and its\n * first change detection runs in a later one (Angular schedules it as a\n * macrotask, by design: angular/angular#57528). A browser that styles the page\n * in between sees elements without their bound classes and attributes, and any\n * CSS transition on them then fades from the browser's defaults to the app's\n * look on every page switch. Ticking right after `NavigationEnd`, before the\n * task ends, binds the page before the browser paints it. The scheduled tick is\n * cancelled by this one, so nothing runs twice.\n *\n * ngwr's own components carry their base class statically and do not depend on\n * this; it covers the app's own bindings on a routed page.\n *\n * @example\n * ```ts\n * provideWr(withRenderOnNavigation())\n * ```\n */\nexport function withRenderOnNavigation(): WrFeature<'render-on-navigation'> {\n return wrFeature('render-on-navigation', [\n provideAppInitializer(() => {\n const appRef = inject(ApplicationRef);\n const subscription = inject(Router).events.subscribe(event => {\n // A microtask, not `afterNextRender`: it has to run before the task that\n // inserted the page ends, and a tick inside the router's own event\n // emission could re-enter one already running.\n if (event instanceof NavigationEnd) queueMicrotask(() => appRef.tick());\n });\n inject(DestroyRef).onDestroy(() => subscription.unsubscribe());\n }),\n ]);\n}\n"],"mappings":";;;;;;;;;;;AA6CA,IACM,gBADN,MACM,cAAa;CACA,SAAS,OAAO,MAAM;CACtB,YAAY,kBAAkB,OAAO,WAAW,CAAC;CACjD,4BAAY,IAAI,IAAG;CAEnB,wBAAQ,IAAI,IAAG;CACxB,aAAa;CACb,YAAY;CACZ;CAER,cAAA;EACE,KAAK,WAAW,UAAU,KAAK,OAAO,iBAAiB,MAAM;EAC7D,MAAM,MAAM,KAAK,OAAO,OAAO,WAAU,UAAQ;GAC/C,IAAI,iBAAiB,iBAAiB,KAAK,WAAW;QACjD,IACH,iBAAiB,iBACjB,iBAAiB,oBACjB,iBAAiB,mBACjB,iBAAiB,mBACjB;IACA,KAAK,WAAW;IAChB,KAAK,OAAM;GACb;EACF,CAAC;EACD,OAAO,UAAU,CAAC,CAAC,gBAAgB,IAAI,YAAW,CAAE;CACtD;CAGA,IAAI,MAAY;EACd,OAAO,KAAK,OAAO,YAAY,SAAS,KAAK,cAAc,IAAI,IAAI;CACrE;CAEA,OAAO,UAAkB;EACvB,KAAK,UAAU,IAAI,QAAQ;EAC3B,aAAa,KAAK,UAAU,OAAO,QAAQ;CAC7C;CAEA,MAAM,MAAgB,KAAoB,YAAmB;EAC3D,IAAI,CAAC,KAAK,WAAW;EACrB,KAAK,aAAa,KAAK,MAAM,SAAS,IAAI,aAAa,KAAK,cAAc;EAC1E,KAAK,MAAM,IAAI,KAAK,MAAM;GAAE;GAAM;EAAG,CAAE;EACvC,KAAK,SAAQ;CACf;CAEQ,WAAQ;EACd,IAAI,KAAK,WAAW;EACpB,KAAK,YAAY;EACjB,qBAAoB;GAClB,KAAK,YAAY;GACjB,KAAK,MAAK;EACZ,CAAC;CACH;CAEQ,QAAK;EAI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AO,UAAU,wBAAwB,CACvC,4BAA2B;EACzB,MAAM,SAAS,OAAO,cAAc;EACpC,MAAM,eAAe,OAAO,MAAM,CAAC,CAAC,OAAO,WAAU,UAAQ;GAI3D,IAAI,iBAAiB,eAAe,qBAAqB,OAAO,KAAI,CAAE;EACxE,CAAC;EACD,OAAO,UAAU,CAAC,CAAC,gBAAgB,aAAa,YAAW,CAAE;CAC/D,CAAC,CACF,CAAA;AACH"}
@@ -156,7 +156,8 @@ function wrDecimalRound(value, decimals) {
156
156
  }
157
157
  function wrRound(value, decimals = 0) {
158
158
  const factor = 10 ** decimals;
159
- return Math.round((value + Number.EPSILON) * factor) / factor;
159
+ const rounded = Math.round((Math.abs(value) + Number.EPSILON) * factor) / factor;
160
+ return value < 0 ? -rounded || 0 : rounded;
160
161
  }
161
162
  const wrNumAttr = (fallback) => (value) => coerceNumberProperty(value, fallback);
162
163
  /**
@@ -334,6 +335,7 @@ function wrGetRootFontSize(fallback = 16) {
334
335
  * Use of this source code is governed by an MIT-style license that can be
335
336
  * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE
336
337
  */
338
+ let lastRestored = null;
337
339
  const FOCUSABLE_SELECTOR = [
338
340
  "a[href]",
339
341
  "area[href]",
@@ -353,6 +355,15 @@ function isRendered(el) {
353
355
  if (el.getClientRects().length === 0) return false;
354
356
  return el.ownerDocument.defaultView?.getComputedStyle(el).visibility !== "hidden";
355
357
  }
358
+ const INVALID_CONTROL = "[aria-invalid=\"true\"]";
359
+ const INVALID_SELECTOR = `${INVALID_CONTROL}, .wr-form-field--invalid`;
360
+ function findFirstInvalid(root) {
361
+ for (const mark of root.querySelectorAll(INVALID_SELECTOR)) {
362
+ if (!mark.matches(INVALID_CONTROL) && mark.querySelector(INVALID_CONTROL)) continue;
363
+ const target = mark.matches(FOCUSABLE_SELECTOR) && isRendered(mark) ? mark : wrGetFocusableElements(mark)[0];
364
+ if (target) return target;
365
+ }
366
+ }
356
367
  function wrGetFocusableElements(root) {
357
368
  return Array.from(root.querySelectorAll(FOCUSABLE_SELECTOR)).filter((el) => isRendered(el) || el === document.activeElement);
358
369
  }
@@ -375,9 +386,40 @@ function wrTrapFocus(root, event) {
375
386
  }
376
387
  return false;
377
388
  }
389
+ function wrNoteFocusReturn(el) {
390
+ lastRestored = new WeakRef(el);
391
+ }
378
392
  function wrRestoreFocus(el, monitor) {
379
- if (monitor) monitor.focusVia(el, "program");
380
- else el.focus();
393
+ const fallback = lastRestored?.deref();
394
+ const target = !el.isConnected && fallback?.isConnected ? fallback : el;
395
+ wrNoteFocusReturn(target);
396
+ const focus = () => monitor ? monitor.focusVia(target, "program") : target.focus();
397
+ focus();
398
+ if (target.ownerDocument.activeElement === target || target.hasAttribute("tabindex")) return;
399
+ target.setAttribute("tabindex", "-1");
400
+ focus();
401
+ target.addEventListener("blur", () => target.removeAttribute("tabindex"), { once: true });
402
+ }
403
+ function wrFocusFirstInvalid(root, options = {}) {
404
+ const { injector, scroll } = options;
405
+ if (typeof document === "undefined" || injector && injector.get(PLATFORM_ID) !== "browser") return Promise.resolve(false);
406
+ const run = () => {
407
+ const target = findFirstInvalid(root);
408
+ if (!target) return false;
409
+ target.focus({ preventScroll: scroll !== false });
410
+ if (scroll !== false) {
411
+ const reduced = target.ownerDocument.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
412
+ (target.closest(".wr-form-field") ?? target).scrollIntoView?.({
413
+ block: "center",
414
+ behavior: "smooth",
415
+ ...scroll,
416
+ ...reduced ? { behavior: "instant" } : null
417
+ });
418
+ }
419
+ return true;
420
+ };
421
+ if (!injector) return Promise.resolve(run());
422
+ return new Promise((resolve) => afterNextRender(() => resolve(run()), { injector }));
381
423
  }
382
424
  /**
383
425
  * @license
@@ -1038,6 +1080,6 @@ function wrResourceValue(resource, fallback) {
1038
1080
  effect(() => value());
1039
1081
  return value.asReadonly();
1040
1082
  }
1041
- export { WR_KEYS, WR_KEY_LABELS, WR_LIVE_LOCALE, wrAction, wrBadgeError, wrBadgeLog, wrBadgeWarn, wrCheckStyles, wrClamp, wrContentDispositionFileName, wrDebounce, wrDecimal, wrDecimalAdd, wrDecimalCompare, wrDecimalDivide, wrDecimalMultiply, wrDecimalRound, wrDecimalSubtract, wrDownloadBlob, wrFeature, wrGetFocusableElements, wrGetRootFontSize, wrHasModifier, wrInitials, wrIsComposing, wrIsDefined, wrIsNonEmptyArray, wrIsObservable, wrIsPrintableKey, wrIsSafeCssValue, wrKeyedAction, wrNoop, wrNumAttr, wrRandomId, wrResolveCssColor, wrResolveCssColorChannels, wrResolveCssSize, wrResourceValue, wrRestoreFocus, wrRound, wrThrottle, wrToClassList, wrTrapFocus, wrTypeahead, wrWatchColorScheme, wrWatchDragCancel };
1083
+ export { WR_KEYS, WR_KEY_LABELS, WR_LIVE_LOCALE, wrAction, wrBadgeError, wrBadgeLog, wrBadgeWarn, wrCheckStyles, wrClamp, wrContentDispositionFileName, wrDebounce, wrDecimal, wrDecimalAdd, wrDecimalCompare, wrDecimalDivide, wrDecimalMultiply, wrDecimalRound, wrDecimalSubtract, wrDownloadBlob, wrFeature, wrFocusFirstInvalid, wrGetFocusableElements, wrGetRootFontSize, wrHasModifier, wrInitials, wrIsComposing, wrIsDefined, wrIsNonEmptyArray, wrIsObservable, wrIsPrintableKey, wrIsSafeCssValue, wrKeyedAction, wrNoop, wrNoteFocusReturn, wrNumAttr, wrRandomId, wrResolveCssColor, wrResolveCssColorChannels, wrResolveCssSize, wrResourceValue, wrRestoreFocus, wrRound, wrThrottle, wrToClassList, wrTrapFocus, wrTypeahead, wrWatchColorScheme, wrWatchDragCancel };
1042
1084
 
1043
1085
  //# sourceMappingURL=ngwr-utils.mjs.map