stimeo-ui 0.14.0 → 0.16.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 (279) hide show
  1. package/CHANGELOG.md +212 -0
  2. package/README.md +120 -0
  3. package/dist/cable/index.js +123 -29
  4. package/dist/cable/index.js.map +1 -1
  5. package/dist/controllers/accordion_controller.d.ts +30 -3
  6. package/dist/controllers/accordion_controller.js +98 -9
  7. package/dist/controllers/accordion_controller.js.map +1 -1
  8. package/dist/controllers/alert_dialog_controller.d.ts +8 -7
  9. package/dist/controllers/alert_dialog_controller.js.map +1 -1
  10. package/dist/controllers/announcer_controller.d.ts +3 -2
  11. package/dist/controllers/announcer_controller.js +96 -62
  12. package/dist/controllers/announcer_controller.js.map +1 -1
  13. package/dist/controllers/auto_submit_controller.js +83 -7
  14. package/dist/controllers/auto_submit_controller.js.map +1 -1
  15. package/dist/controllers/avatar_controller.js +1 -1
  16. package/dist/controllers/avatar_controller.js.map +1 -1
  17. package/dist/controllers/breadcrumb_controller.d.ts +10 -7
  18. package/dist/controllers/breadcrumb_controller.js +38 -11
  19. package/dist/controllers/breadcrumb_controller.js.map +1 -1
  20. package/dist/controllers/bulk_select_controller.d.ts +4 -4
  21. package/dist/controllers/bulk_select_controller.js +7 -6
  22. package/dist/controllers/bulk_select_controller.js.map +1 -1
  23. package/dist/controllers/calendar_controller.d.ts +101 -23
  24. package/dist/controllers/calendar_controller.js +340 -123
  25. package/dist/controllers/calendar_controller.js.map +1 -1
  26. package/dist/controllers/carousel_controller.d.ts +67 -22
  27. package/dist/controllers/carousel_controller.js +263 -38
  28. package/dist/controllers/carousel_controller.js.map +1 -1
  29. package/dist/controllers/character_counter_controller.d.ts +1 -1
  30. package/dist/controllers/character_counter_controller.js +40 -2
  31. package/dist/controllers/character_counter_controller.js.map +1 -1
  32. package/dist/controllers/checkbox_controller.js +81 -12
  33. package/dist/controllers/checkbox_controller.js.map +1 -1
  34. package/dist/controllers/clipboard_controller.d.ts +28 -2
  35. package/dist/controllers/clipboard_controller.js +63 -5
  36. package/dist/controllers/clipboard_controller.js.map +1 -1
  37. package/dist/controllers/collapsible_controller.d.ts +25 -1
  38. package/dist/controllers/collapsible_controller.js +99 -14
  39. package/dist/controllers/collapsible_controller.js.map +1 -1
  40. package/dist/controllers/color_picker_controller.d.ts +29 -8
  41. package/dist/controllers/color_picker_controller.js +80 -34
  42. package/dist/controllers/color_picker_controller.js.map +1 -1
  43. package/dist/controllers/combobox_controller.d.ts +10 -1
  44. package/dist/controllers/combobox_controller.js +106 -16
  45. package/dist/controllers/combobox_controller.js.map +1 -1
  46. package/dist/controllers/command_palette_controller.d.ts +3 -3
  47. package/dist/controllers/command_palette_controller.js +35 -3
  48. package/dist/controllers/command_palette_controller.js.map +1 -1
  49. package/dist/controllers/conditional_fields_controller.js +85 -17
  50. package/dist/controllers/conditional_fields_controller.js.map +1 -1
  51. package/dist/controllers/confirm_controller.js +3 -0
  52. package/dist/controllers/confirm_controller.js.map +1 -1
  53. package/dist/controllers/context_menu_controller.d.ts +6 -0
  54. package/dist/controllers/context_menu_controller.js +32 -12
  55. package/dist/controllers/context_menu_controller.js.map +1 -1
  56. package/dist/controllers/count_up_controller.js.map +1 -1
  57. package/dist/controllers/countdown_controller.d.ts +30 -1
  58. package/dist/controllers/countdown_controller.js +129 -26
  59. package/dist/controllers/countdown_controller.js.map +1 -1
  60. package/dist/controllers/currency_input_controller.d.ts +77 -16
  61. package/dist/controllers/currency_input_controller.js +221 -67
  62. package/dist/controllers/currency_input_controller.js.map +1 -1
  63. package/dist/controllers/data_grid_controller.d.ts +63 -18
  64. package/dist/controllers/data_grid_controller.js +195 -29
  65. package/dist/controllers/data_grid_controller.js.map +1 -1
  66. package/dist/controllers/date_range_picker_controller.d.ts +41 -6
  67. package/dist/controllers/date_range_picker_controller.js +151 -30
  68. package/dist/controllers/date_range_picker_controller.js.map +1 -1
  69. package/dist/controllers/dialog_controller.d.ts +10 -3
  70. package/dist/controllers/dialog_controller.js +35 -8
  71. package/dist/controllers/dialog_controller.js.map +1 -1
  72. package/dist/controllers/direct_upload_controller.js +22 -4
  73. package/dist/controllers/direct_upload_controller.js.map +1 -1
  74. package/dist/controllers/dirty_form_controller.d.ts +2 -2
  75. package/dist/controllers/dirty_form_controller.js +46 -13
  76. package/dist/controllers/dirty_form_controller.js.map +1 -1
  77. package/dist/controllers/dismissible_controller.js +1 -0
  78. package/dist/controllers/dismissible_controller.js.map +1 -1
  79. package/dist/controllers/drawer_controller.d.ts +18 -10
  80. package/dist/controllers/drawer_controller.js +54 -19
  81. package/dist/controllers/drawer_controller.js.map +1 -1
  82. package/dist/controllers/dropdown_controller.d.ts +9 -3
  83. package/dist/controllers/dropdown_controller.js +36 -9
  84. package/dist/controllers/dropdown_controller.js.map +1 -1
  85. package/dist/controllers/editable_controller.js +34 -0
  86. package/dist/controllers/editable_controller.js.map +1 -1
  87. package/dist/controllers/file_dropzone_controller.js +144 -51
  88. package/dist/controllers/file_dropzone_controller.js.map +1 -1
  89. package/dist/controllers/filter_controller.d.ts +10 -4
  90. package/dist/controllers/filter_controller.js +20 -6
  91. package/dist/controllers/filter_controller.js.map +1 -1
  92. package/dist/controllers/flash_controller.d.ts +26 -6
  93. package/dist/controllers/flash_controller.js +432 -71
  94. package/dist/controllers/flash_controller.js.map +1 -1
  95. package/dist/controllers/focus_controller.js +1 -0
  96. package/dist/controllers/focus_controller.js.map +1 -1
  97. package/dist/controllers/form_field_controller.js +7 -5
  98. package/dist/controllers/form_field_controller.js.map +1 -1
  99. package/dist/controllers/form_validation_controller.js +19 -13
  100. package/dist/controllers/form_validation_controller.js.map +1 -1
  101. package/dist/controllers/frame_loading_controller.js +45 -8
  102. package/dist/controllers/frame_loading_controller.js.map +1 -1
  103. package/dist/controllers/highlight_controller.js +82 -25
  104. package/dist/controllers/highlight_controller.js.map +1 -1
  105. package/dist/controllers/hover_card_controller.d.ts +10 -2
  106. package/dist/controllers/hover_card_controller.js +40 -14
  107. package/dist/controllers/hover_card_controller.js.map +1 -1
  108. package/dist/controllers/idle_controller.d.ts +16 -3
  109. package/dist/controllers/idle_controller.js +90 -5
  110. package/dist/controllers/idle_controller.js.map +1 -1
  111. package/dist/controllers/input_mask_controller.d.ts +5 -2
  112. package/dist/controllers/input_mask_controller.js +65 -9
  113. package/dist/controllers/input_mask_controller.js.map +1 -1
  114. package/dist/controllers/intersection_controller.js +3 -0
  115. package/dist/controllers/intersection_controller.js.map +1 -1
  116. package/dist/controllers/lazy_frame_controller.js +11 -2
  117. package/dist/controllers/lazy_frame_controller.js.map +1 -1
  118. package/dist/controllers/listbox_controller.d.ts +50 -8
  119. package/dist/controllers/listbox_controller.js +203 -45
  120. package/dist/controllers/listbox_controller.js.map +1 -1
  121. package/dist/controllers/local_time_controller.js +10 -5
  122. package/dist/controllers/local_time_controller.js.map +1 -1
  123. package/dist/controllers/masonry_controller.d.ts +3 -3
  124. package/dist/controllers/masonry_controller.js +31 -15
  125. package/dist/controllers/masonry_controller.js.map +1 -1
  126. package/dist/controllers/menu_controller.d.ts +9 -3
  127. package/dist/controllers/menu_controller.js +45 -16
  128. package/dist/controllers/menu_controller.js.map +1 -1
  129. package/dist/controllers/menubar_controller.d.ts +11 -0
  130. package/dist/controllers/menubar_controller.js +58 -24
  131. package/dist/controllers/menubar_controller.js.map +1 -1
  132. package/dist/controllers/meter_controller.js +9 -5
  133. package/dist/controllers/meter_controller.js.map +1 -1
  134. package/dist/controllers/multi_select_controller.d.ts +18 -3
  135. package/dist/controllers/multi_select_controller.js +278 -104
  136. package/dist/controllers/multi_select_controller.js.map +1 -1
  137. package/dist/controllers/navigation_menu_controller.d.ts +11 -0
  138. package/dist/controllers/navigation_menu_controller.js +48 -15
  139. package/dist/controllers/navigation_menu_controller.js.map +1 -1
  140. package/dist/controllers/nested_form_controller.js +37 -8
  141. package/dist/controllers/nested_form_controller.js.map +1 -1
  142. package/dist/controllers/network_status_controller.js +9 -1
  143. package/dist/controllers/network_status_controller.js.map +1 -1
  144. package/dist/controllers/number_input_controller.d.ts +36 -8
  145. package/dist/controllers/number_input_controller.js +124 -21
  146. package/dist/controllers/number_input_controller.js.map +1 -1
  147. package/dist/controllers/optimistic_controller.js +42 -5
  148. package/dist/controllers/optimistic_controller.js.map +1 -1
  149. package/dist/controllers/otp_controller.d.ts +22 -7
  150. package/dist/controllers/otp_controller.js +198 -55
  151. package/dist/controllers/otp_controller.js.map +1 -1
  152. package/dist/controllers/overflow_indicator_controller.d.ts +8 -12
  153. package/dist/controllers/overflow_indicator_controller.js +115 -21
  154. package/dist/controllers/overflow_indicator_controller.js.map +1 -1
  155. package/dist/controllers/overflow_menu_controller.d.ts +26 -6
  156. package/dist/controllers/overflow_menu_controller.js +141 -44
  157. package/dist/controllers/overflow_menu_controller.js.map +1 -1
  158. package/dist/controllers/pagination_controller.d.ts +19 -11
  159. package/dist/controllers/pagination_controller.js +74 -28
  160. package/dist/controllers/pagination_controller.js.map +1 -1
  161. package/dist/controllers/password_reveal_controller.d.ts +15 -1
  162. package/dist/controllers/password_reveal_controller.js +59 -2
  163. package/dist/controllers/password_reveal_controller.js.map +1 -1
  164. package/dist/controllers/persist_controller.js +30 -8
  165. package/dist/controllers/persist_controller.js.map +1 -1
  166. package/dist/controllers/pointer_drag_controller.js +131 -52
  167. package/dist/controllers/pointer_drag_controller.js.map +1 -1
  168. package/dist/controllers/popover_controller.d.ts +9 -3
  169. package/dist/controllers/popover_controller.js +45 -11
  170. package/dist/controllers/popover_controller.js.map +1 -1
  171. package/dist/controllers/portal_controller.d.ts +1 -1
  172. package/dist/controllers/portal_controller.js +6 -2
  173. package/dist/controllers/portal_controller.js.map +1 -1
  174. package/dist/controllers/preview_guard_controller.js +16 -1
  175. package/dist/controllers/preview_guard_controller.js.map +1 -1
  176. package/dist/controllers/progress_controller.js +8 -4
  177. package/dist/controllers/progress_controller.js.map +1 -1
  178. package/dist/controllers/radio_group_controller.d.ts +6 -4
  179. package/dist/controllers/radio_group_controller.js +42 -17
  180. package/dist/controllers/radio_group_controller.js.map +1 -1
  181. package/dist/controllers/range_slider_controller.d.ts +49 -1
  182. package/dist/controllers/range_slider_controller.js +88 -42
  183. package/dist/controllers/range_slider_controller.js.map +1 -1
  184. package/dist/controllers/rating_controller.d.ts +14 -3
  185. package/dist/controllers/rating_controller.js +39 -15
  186. package/dist/controllers/rating_controller.js.map +1 -1
  187. package/dist/controllers/read_more_controller.d.ts +24 -2
  188. package/dist/controllers/read_more_controller.js +100 -7
  189. package/dist/controllers/read_more_controller.js.map +1 -1
  190. package/dist/controllers/reading_progress_controller.js +65 -19
  191. package/dist/controllers/reading_progress_controller.js.map +1 -1
  192. package/dist/controllers/relative_time_controller.js +10 -5
  193. package/dist/controllers/relative_time_controller.js.map +1 -1
  194. package/dist/controllers/resizable_controller.d.ts +16 -2
  195. package/dist/controllers/resizable_controller.js +82 -22
  196. package/dist/controllers/resizable_controller.js.map +1 -1
  197. package/dist/controllers/scroll_area_controller.js +75 -27
  198. package/dist/controllers/scroll_area_controller.js.map +1 -1
  199. package/dist/controllers/scroll_restore_controller.js +37 -16
  200. package/dist/controllers/scroll_restore_controller.js.map +1 -1
  201. package/dist/controllers/scroll_visibility_controller.js +49 -30
  202. package/dist/controllers/scroll_visibility_controller.js.map +1 -1
  203. package/dist/controllers/scrollspy_controller.d.ts +3 -2
  204. package/dist/controllers/scrollspy_controller.js +71 -26
  205. package/dist/controllers/scrollspy_controller.js.map +1 -1
  206. package/dist/controllers/separator_controller.d.ts +41 -14
  207. package/dist/controllers/separator_controller.js +66 -37
  208. package/dist/controllers/separator_controller.js.map +1 -1
  209. package/dist/controllers/sidebar_controller.d.ts +20 -3
  210. package/dist/controllers/sidebar_controller.js +77 -18
  211. package/dist/controllers/sidebar_controller.js.map +1 -1
  212. package/dist/controllers/skeleton_controller.js +6 -1
  213. package/dist/controllers/skeleton_controller.js.map +1 -1
  214. package/dist/controllers/slider_controller.d.ts +45 -7
  215. package/dist/controllers/slider_controller.js +82 -47
  216. package/dist/controllers/slider_controller.js.map +1 -1
  217. package/dist/controllers/smart_sticky_header_controller.js +60 -26
  218. package/dist/controllers/smart_sticky_header_controller.js.map +1 -1
  219. package/dist/controllers/sortable_controller.js +17 -2
  220. package/dist/controllers/sortable_controller.js.map +1 -1
  221. package/dist/controllers/spinner_controller.js +10 -2
  222. package/dist/controllers/spinner_controller.js.map +1 -1
  223. package/dist/controllers/step_indicator_controller.d.ts +19 -17
  224. package/dist/controllers/step_indicator_controller.js +18 -17
  225. package/dist/controllers/step_indicator_controller.js.map +1 -1
  226. package/dist/controllers/stepper_controller.d.ts +34 -9
  227. package/dist/controllers/stepper_controller.js +101 -19
  228. package/dist/controllers/stepper_controller.js.map +1 -1
  229. package/dist/controllers/stick_to_bottom_controller.d.ts +19 -0
  230. package/dist/controllers/stick_to_bottom_controller.js +104 -8
  231. package/dist/controllers/stick_to_bottom_controller.js.map +1 -1
  232. package/dist/controllers/submit_once_controller.d.ts +3 -2
  233. package/dist/controllers/submit_once_controller.js +45 -9
  234. package/dist/controllers/submit_once_controller.js.map +1 -1
  235. package/dist/controllers/switch_controller.d.ts +29 -7
  236. package/dist/controllers/switch_controller.js +101 -10
  237. package/dist/controllers/switch_controller.js.map +1 -1
  238. package/dist/controllers/tabs_controller.d.ts +12 -0
  239. package/dist/controllers/tabs_controller.js +21 -2
  240. package/dist/controllers/tabs_controller.js.map +1 -1
  241. package/dist/controllers/tags_input_controller.d.ts +15 -3
  242. package/dist/controllers/tags_input_controller.js +209 -59
  243. package/dist/controllers/tags_input_controller.js.map +1 -1
  244. package/dist/controllers/textarea_autosize_controller.js +29 -3
  245. package/dist/controllers/textarea_autosize_controller.js.map +1 -1
  246. package/dist/controllers/theme_controller.d.ts +20 -3
  247. package/dist/controllers/theme_controller.js +64 -14
  248. package/dist/controllers/theme_controller.js.map +1 -1
  249. package/dist/controllers/time_picker_controller.js +23 -8
  250. package/dist/controllers/time_picker_controller.js.map +1 -1
  251. package/dist/controllers/toast_controller.d.ts +55 -15
  252. package/dist/controllers/toast_controller.js +451 -105
  253. package/dist/controllers/toast_controller.js.map +1 -1
  254. package/dist/controllers/toggle_group_controller.d.ts +49 -7
  255. package/dist/controllers/toggle_group_controller.js +159 -23
  256. package/dist/controllers/toggle_group_controller.js.map +1 -1
  257. package/dist/controllers/toolbar_controller.js +32 -0
  258. package/dist/controllers/toolbar_controller.js.map +1 -1
  259. package/dist/controllers/tooltip_controller.d.ts +8 -0
  260. package/dist/controllers/tooltip_controller.js +39 -13
  261. package/dist/controllers/tooltip_controller.js.map +1 -1
  262. package/dist/controllers/transition_controller.js +4 -0
  263. package/dist/controllers/transition_controller.js.map +1 -1
  264. package/dist/controllers/tree_view_controller.d.ts +39 -8
  265. package/dist/controllers/tree_view_controller.js +169 -16
  266. package/dist/controllers/tree_view_controller.js.map +1 -1
  267. package/dist/index.d.ts +28 -1
  268. package/dist/index.js +5002 -1911
  269. package/dist/index.js.map +1 -1
  270. package/dist/inspector/cli.d.ts +72 -6
  271. package/dist/inspector/cli.js +262 -51
  272. package/dist/inspector/cli.js.map +1 -1
  273. package/dist/inspector/cli_bin.js +309 -51
  274. package/dist/inspector/cli_bin.js.map +1 -1
  275. package/dist/inspector/examples.json +40 -40
  276. package/dist/inspector/manifest.json +529 -61
  277. package/dist/positioning/index.js +2 -0
  278. package/dist/positioning/index.js.map +1 -1
  279. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/authored_integer.ts","../../src/utils/reduced_motion.ts","../../src/controllers/count_up_controller.ts"],"names":[],"mappings":";;;;;AACA,IAAM,UAAA,GAAa,wBAAA;AAEnB,IAAM,WAAA,GAAc,QAAA;AAwBb,SAAS,gBAAgB,IAAA,EAA6B;AAC3D,EAAA,MAAM,UAAA,GAAa,IAAA,CAAK,IAAA,CAAK,IAAI,CAAA;AACjC,EAAA,IAAI,UAAA,KAAe,MAAM,OAAO,IAAA;AAEhC,EAAA,MAAM,KAAK,UAAA,CAAW,KAAA;AACtB,EAAA,MAAM,M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AA,EAC9E;AAAA;AAAA,EAGA,OAAA,GAAgB;AACd,IAAA,IAAI,IAAA,CAAK,MAAA,KAAW,IAAA,EAAM,oBAAA,CAAqB,KAAK,MAAM,CAAA;AAC1D,IAAA,IAAA,CAAK,MAAA,GAAS,IAAA;AACd,IAAA,MAAM,MAAA,GAAS,KAAK,YAAA,EAAa;AACjC,IAAA,IAAI,MAAA,KAAW,MAAM,IAAA,CAAK,OAAA,CAAQ,QAAQ,MAAA,CAAO,YAAA,CAAa,YAAY,CAAC,CAAA;AAC3E,IAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,oBAAA,EAAsB,MAAM,CAAA;AAAA,EACxD;AACF","file":"count_up_controller.js","sourcesContent":["/** Digits plus the characters that may separate them inside one number. */\nconst TOKEN_BODY = /\\d[\\d.,'’’    _]*\\d|\\d/;\n/** A `-` opens a token only against one of these on its left. */\nconst SIGN_OPENER = /[\\s([]/;\n\n/**\n * Reads the integer that a human-formatted string displays.\n *\n * Takes the first numeric token, drops group separators, and truncates any\n * fractional part toward zero — so `\"1,200 users\"`, `\"$1,299.99\"` and\n * `\"1.299,99\"` read 1200, 1299 and 1299 without asking the platform which\n * locale is in play. A separator counts as grouping only where the digits that\n * follow it form a run of exactly three and the leading run could head a\n * grouped number; anything else is the decimal point, and the digits after it\n * are the fraction.\n *\n * `-` counts as a sign only where it opens the token — at the start of the\n * string, or after whitespace or an opening bracket — so a hyphen inside a\n * label (`\"Sign-ups: 1,200\"`, `\"Top-10 users\"`) never becomes one.\n *\n * `\"1.200\"` is genuinely ambiguous (1200 grouped, 1.2 with a decimal point) and\n * reads as 1200: display numbers group far more often than they carry a\n * fraction in exactly three digits.\n *\n * Returns `null` when the string holds no digits at all. What that means is the\n * caller's to decide — starting nothing, or falling back to a base value.\n */\nexport function authoredInteger(text: string): number | null {\n const firstDigit = /\\d/.exec(text);\n if (firstDigit === null) return null;\n\n const at = firstDigit.index;\n const signed =\n at > 0 && text[at - 1] === \"-\" && (at === 1 || SIGN_OPENER.test(text[at - 2] as string));\n\n const body = TOKEN_BODY.exec(text.slice(at)) as RegExpExecArray;\n const runs = body[0].split(/\\D+/);\n const separators = body[0].match(/\\D+/g) ?? [];\n\n // The leading run heads a grouped number only when it is short enough to be a\n // group itself and carries no leading zero; \"0.500\" and \"012,3\" are decimals.\n const lead = runs[0] as string;\n const heads = lead.length <= 3 && !lead.startsWith(\"0\");\n let digits = lead;\n for (let i = 1; heads && i < runs.length; i += 1) {\n if (separators[i - 1]?.length !== 1 || runs[i]?.length !== 3) break;\n digits += runs[i];\n }\n\n const magnitude = Number.parseInt(digits, 10);\n return signed ? -magnitude || 0 : magnitude;\n}\n","/**\n * Shared `prefers-reduced-motion` lookup for the motion-aware controllers\n *.\n *\n * This one-liner keeps the media query string and the environment guard\n * single-sourced across them. The preference is intentionally re-read on every\n * call — the controllers check it at each animation/scroll start (WCAG 2.2\n * **2.3.3**), so flipping the OS setting takes effect immediately without any\n * listener or cache bookkeeping here.\n */\n\n/**\n * Whether the user currently requests reduced motion.\n *\n * @returns `true` when `(prefers-reduced-motion: reduce)` matches; `false`\n * otherwise, including environments without `window.matchMedia` (treated as\n * \"no preference\").\n */\nexport function prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n );\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { authoredInteger } from \"../utils/authored_integer\";\nimport { prefersReducedMotion } from \"../utils/reduced_motion\";\n\n/** The animation length used when `duration` falls outside its domain. */\nconst DEFAULT_DURATION = 1200;\n\n/**\n * Headless **count-up**: animates a number from `from` up to the value already\n * in the DOM — typically started the moment the element scrolls into view by\n * composing with the `stimeo--intersection` primitive (the classic \"animate\n * when visible\"). Distinct from `stimeo--countdown` (time-based). Core\n * (zero dependencies).\n *\n * Markup contract (identifier: `stimeo--count-up`):\n * <span data-controller=\"stimeo--intersection stimeo--count-up\"\n * data-stimeo--intersection-once-value=\"true\"\n * data-action=\"stimeo--intersection:enter->stimeo--count-up#start\">1200</span>\n *\n * The **final number stays authored in the markup** (SEO / no-JS / SR read the\n * real value); `start` animates the displayed text from `from` to it over\n * `duration` ms with an ease-out curve, then restores the exact authored text.\n * With `once` (default) later starts are ignored (`data-count-up-done` records\n * a finished run across Turbo cache restores).\n *\n * Only the text node holding the number is animated, so sibling markup — a unit\n * in a `<small>`, a label in a `<b>` — is left where the author put it.\n *\n * `end` dispatches `{ value }`.\n *\n * @remarks\n * Behavior only — no formatting is imposed: the authored text is read for the\n * integer it displays and restored verbatim at the end; intermediate frames\n * render plain integers. Accessibility: when the user prefers reduced motion the\n * animation is skipped entirely (the value just stays final — WCAG 2.3.3).\n * During a run the ticking number is wrapped in a `role=\"img\"` element named\n * with the authored text, which is where a name is allowed to live — the host\n * keeps whatever semantics it had, so a `<dd>` stays a definition. That wrapper\n * doubles as the interrupted-run record `connect()` restores from after a Turbo\n * cache snapshot taken mid-animation. The animation frame is canceled on\n * `disconnect()` (Turbo navigation included) and the authored text restored.\n */\nexport class CountUpController extends Controller<HTMLElement> {\n static override values = {\n duration: { type: Number, default: DEFAULT_DURATION },\n from: { type: Number, default: 0 },\n once: { type: Boolean, default: true },\n };\n static actions = [\"start\"] as const;\n static events = [\"end\"] as const;\n\n declare durationValue: number;\n declare fromValue: number;\n declare onceValue: boolean;\n\n #frame: number | null = null;\n\n /** The animation length, with a declaration outside its domain read as the default. */\n get #duration(): number {\n return Number.isFinite(this.durationValue) && this.durationValue > 0\n ? this.durationValue\n : DEFAULT_DURATION;\n }\n\n /** The starting value, with a declaration that is not a finite number read as zero. */\n get #from(): number {\n return Number.isFinite(this.fromValue) ? this.fromValue : 0;\n }\n\n override connect(): void {\n // Turbo snapshots the page BEFORE the body swap, so a cached page can hold\n // a mid-animation frame (disconnect()'s settle runs too late for it). The\n // wrapper this controller owns flags the interrupted run and carries the\n // authored text in the name it published.\n const ticker = this.#ownedTicker();\n if (ticker === null) return;\n const authored = ticker.getAttribute(\"aria-label\");\n this.#unwrap(ticker, authored);\n if (authored !== null) this.element.setAttribute(\"data-count-up-done\", \"true\");\n }\n\n override disconnect(): void {\n // A run cannot survive the element: settle instantly so the cached\n // snapshot holds the real value, never a mid-animation frame.\n if (this.#frame !== null) this.#settle();\n }\n\n /**\n * Starts the animation (typically from `stimeo--intersection:enter` via\n * `data-action`). No-ops while running, and after a finished run when `once`.\n */\n start(): void {\n if (this.#frame !== null) return;\n if (this.onceValue && this.element.hasAttribute(\"data-count-up-done\")) return;\n\n const node = this.#numericNode();\n if (node === null) return;\n const authored = node.data;\n const target = authoredInteger(authored) as number;\n\n // Reduced motion: no ticking, just the final value (WCAG 2.3.3).\n if (prefersReducedMotion()) {\n this.element.setAttribute(\"data-count-up-done\", \"true\");\n this.dispatch(\"end\", { detail: { value: target } });\n return;\n }\n\n // A name may not live on every host — a `<span>` prohibits one, and a role\n // that permits naming would cost a `<dd>` its own semantics — so the ticking\n // number gets a wrapper that permits naming, and the name carries the\n // authored text AT should hear instead of the ticks.\n const ticker = this.#wrap(node, authored);\n const from = this.#from;\n const started = performance.now();\n const step = (now: number): void => {\n const t = Math.min((now - started) / this.#duration, 1);\n const eased = 1 - (1 - t) ** 3; // ease-out cubic\n ticker.textContent = String(Math.round(from + (target - from) * eased));\n if (t < 1) {\n this.#frame = requestAnimationFrame(step);\n } else {\n this.#settle();\n this.dispatch(\"end\", { detail: { value: target } });\n }\n };\n this.#frame = requestAnimationFrame(step);\n }\n\n /** The first text node that displays a number, or null when the host has none. */\n #numericNode(): Text | null {\n const walker = document.createTreeWalker(this.element, NodeFilter.SHOW_TEXT);\n let node = walker.nextNode() as Text | null;\n while (node !== null && authoredInteger(node.data) === null) {\n node = walker.nextNode() as Text | null;\n }\n return node;\n }\n\n /** The wrapper this controller published, if one outlived its run. */\n #ownedTicker(): HTMLElement | null {\n return this.element.querySelector<HTMLElement>(\"[data-count-up-label]\");\n }\n\n /** Publishes the ticking number inside a named wrapper, replacing `node`. */\n #wrap(node: Text, authored: string): HTMLElement {\n const ticker = document.createElement(\"span\");\n ticker.setAttribute(\"data-count-up-label\", \"true\");\n ticker.setAttribute(\"role\", \"img\");\n ticker.setAttribute(\"aria-label\", authored);\n node.replaceWith(ticker);\n ticker.append(node);\n return ticker;\n }\n\n /** Puts `text` back where the wrapper stood, leaving the rest of the host alone. */\n #unwrap(ticker: HTMLElement, text: string | null): void {\n ticker.replaceWith(document.createTextNode(text ?? ticker.textContent ?? \"\"));\n }\n\n /** Ends the run: cancels the frame and restores the authored presentation. */\n #settle(): void {\n if (this.#frame !== null) cancelAnimationFrame(this.#frame);\n this.#frame = null;\n const ticker = this.#ownedTicker();\n if (ticker !== null) this.#unwrap(ticker, ticker.getAttribute(\"aria-label\"));\n this.element.setAttribute(\"data-count-up-done\", \"true\");\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/authored_integer.ts","../../src/utils/reduced_motion.ts","../../src/controllers/count_up_controller.ts"],"names":[],"mappings":";;;;;AACA,IAAM,UAAA,GAAa,wBAAA;AAEnB,IAAM,WAAA,GAAc,QAAA;AAwBb,SAAS,gBAAgB,IAAA,EAA6B;AAC3D,EAAA,MAAM,UAAA,GAAa,IAAA,CAAK,IAAA,CAAK,IAAI,CAAA;AACjC,EAAA,IAAI,UAAA,KAAe,MAAM,OAAO,IAAA;AAEhC,EAAA,MAAM,KAAK,UAAA,CAAW,KAAA;AACtB,EAAA,MAAM,MAAA,GACJ,EAAA,GAAK,CAAA,IAAK,IAAA,CAAK,KAAK,CAAC,CAAA,KAAM,GAAA,KAAQ,EAAA,KAAO,KAAK,WAAA,CAAY,IAAA,CAAK,IAAA,CAAK,EAAA,GAAK,CAAC,CAAW,CAAA,CAAA;AAExF,EAAA,MAAM,OAAO,UAAA,CAAW,IAAA,CAAK,IAAA,CAAK,KAAA,CAAM,EAAE,CAAC,CAAA;AAC3C,EAAA,MAAM,IAAA,GAAO,IAAA,CAAK,CAAC,CAAA,CAAE,MAAM,KAAK,CAAA;AAChC,EAAA,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AA,CAAQ,YAAA,CAAa,oBAAA,EAAsB,MAAM,CAAA;AAAA,EACxD;AACF","file":"count_up_controller.js","sourcesContent":["/** Digits plus the characters that may separate them inside one number. */\nconst TOKEN_BODY = /\\d[\\d.,'’’    _]*\\d|\\d/;\n/** A `-` opens a token only against one of these on its left. */\nconst SIGN_OPENER = /[\\s([]/;\n\n/**\n * Reads the integer that a human-formatted string displays.\n *\n * Takes the first numeric token, drops group separators, and truncates any\n * fractional part toward zero — so `\"1,200 users\"`, `\"$1,299.99\"` and\n * `\"1.299,99\"` read 1200, 1299 and 1299 without asking the platform which\n * locale is in play. A separator counts as grouping only where the digits that\n * follow it form a run of exactly three and the leading run could head a\n * grouped number; anything else is the decimal point, and the digits after it\n * are the fraction.\n *\n * `-` counts as a sign only where it opens the token — at the start of the\n * string, or after whitespace or an opening bracket — so a hyphen inside a\n * label (`\"Sign-ups: 1,200\"`, `\"Top-10 users\"`) never becomes one.\n *\n * `\"1.200\"` is genuinely ambiguous (1200 grouped, 1.2 with a decimal point) and\n * reads as 1200: display numbers group far more often than they carry a\n * fraction in exactly three digits.\n *\n * Returns `null` when the string holds no digits at all. What that means is the\n * caller's to decide — starting nothing, or falling back to a base value.\n */\nexport function authoredInteger(text: string): number | null {\n const firstDigit = /\\d/.exec(text);\n if (firstDigit === null) return null;\n\n const at = firstDigit.index;\n const signed =\n at > 0 && text[at - 1] === \"-\" && (at === 1 || SIGN_OPENER.test(text[at - 2] as string));\n\n const body = TOKEN_BODY.exec(text.slice(at)) as RegExpExecArray;\n const runs = body[0].split(/\\D+/);\n const separators = body[0].match(/\\D+/g) ?? [];\n\n // The leading run heads a grouped number only when it is short enough to be a\n // group itself and carries no leading zero; \"0.500\" and \"012,3\" are decimals.\n const lead = runs[0] as string;\n const heads = lead.length <= 3 && !lead.startsWith(\"0\");\n let digits = lead;\n for (let i = 1; heads && i < runs.length; i += 1) {\n if (separators[i - 1]?.length !== 1 || runs[i]?.length !== 3) break;\n digits += runs[i];\n }\n\n const magnitude = Number.parseInt(digits, 10);\n return signed ? -magnitude || 0 : magnitude;\n}\n","/**\n * Shared `prefers-reduced-motion` lookup for the motion-aware controllers.\n *\n * This one-liner keeps the media query string and the environment guard\n * single-sourced across them. The preference is intentionally re-read on every\n * call — the controllers check it at each animation/scroll start (WCAG 2.2\n * **2.3.3**), so flipping the OS setting takes effect immediately without any\n * listener or cache bookkeeping here.\n */\n\n/**\n * Whether the user currently requests reduced motion.\n *\n * @returns `true` when `(prefers-reduced-motion: reduce)` matches; `false`\n * otherwise, including environments without `window.matchMedia` (treated as\n * \"no preference\").\n */\nexport function prefersReducedMotion(): boolean {\n return (\n typeof window.matchMedia === \"function\" &&\n window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n );\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { authoredInteger } from \"../utils/authored_integer\";\nimport { prefersReducedMotion } from \"../utils/reduced_motion\";\n\n/** The animation length used when `duration` falls outside its domain. */\nconst DEFAULT_DURATION = 1200;\n\n/**\n * Headless **count-up**: animates a number from `from` up to the value already\n * in the DOM — typically started the moment the element scrolls into view by\n * composing with the `stimeo--intersection` primitive (the classic \"animate\n * when visible\"). Distinct from `stimeo--countdown` (time-based). Core\n * (zero dependencies).\n *\n * Markup contract (identifier: `stimeo--count-up`):\n * <span data-controller=\"stimeo--intersection stimeo--count-up\"\n * data-stimeo--intersection-once-value=\"true\"\n * data-action=\"stimeo--intersection:enter->stimeo--count-up#start\">1200</span>\n *\n * The **final number stays authored in the markup** (SEO / no-JS / SR read the\n * real value); `start` animates the displayed text from `from` to it over\n * `duration` ms with an ease-out curve, then restores the exact authored text.\n * With `once` (default) later starts are ignored (`data-count-up-done` records\n * a finished run across Turbo cache restores).\n *\n * Only the text node holding the number is animated, so sibling markup — a unit\n * in a `<small>`, a label in a `<b>` — is left where the author put it.\n *\n * `end` dispatches `{ value }`.\n *\n * @remarks\n * Behavior only — no formatting is imposed: the authored text is read for the\n * integer it displays and restored verbatim at the end; intermediate frames\n * render plain integers. Accessibility: when the user prefers reduced motion the\n * animation is skipped entirely (the value just stays final — WCAG 2.3.3).\n * During a run the ticking number is wrapped in a `role=\"img\"` element named\n * with the authored text, which is where a name is allowed to live — the host\n * keeps whatever semantics it had, so a `<dd>` stays a definition. That wrapper\n * doubles as the interrupted-run record `connect()` restores from after a Turbo\n * cache snapshot taken mid-animation. The animation frame is canceled on\n * `disconnect()` (Turbo navigation included) and the authored text restored.\n */\nexport class CountUpController extends Controller<HTMLElement> {\n static override values = {\n duration: { type: Number, default: DEFAULT_DURATION },\n from: { type: Number, default: 0 },\n once: { type: Boolean, default: true },\n };\n static actions = [\"start\"] as const;\n static events = [\"end\"] as const;\n\n declare durationValue: number;\n declare fromValue: number;\n declare onceValue: boolean;\n\n #frame: number | null = null;\n\n /** The animation length, with a declaration outside its domain read as the default. */\n get #duration(): number {\n return Number.isFinite(this.durationValue) && this.durationValue > 0\n ? this.durationValue\n : DEFAULT_DURATION;\n }\n\n /** The starting value, with a declaration that is not a finite number read as zero. */\n get #from(): number {\n return Number.isFinite(this.fromValue) ? this.fromValue : 0;\n }\n\n override connect(): void {\n // Turbo snapshots the page BEFORE the body swap, so a cached page can hold\n // a mid-animation frame (disconnect()'s settle runs too late for it). The\n // wrapper this controller owns flags the interrupted run and carries the\n // authored text in the name it published.\n const ticker = this.#ownedTicker();\n if (ticker === null) return;\n const authored = ticker.getAttribute(\"aria-label\");\n this.#unwrap(ticker, authored);\n if (authored !== null) this.element.setAttribute(\"data-count-up-done\", \"true\");\n }\n\n override disconnect(): void {\n // A run cannot survive the element: settle instantly so the cached\n // snapshot holds the real value, never a mid-animation frame.\n if (this.#frame !== null) this.#settle();\n }\n\n /**\n * Starts the animation (typically from `stimeo--intersection:enter` via\n * `data-action`). No-ops while running, and after a finished run when `once`.\n */\n start(): void {\n if (this.#frame !== null) return;\n if (this.onceValue && this.element.hasAttribute(\"data-count-up-done\")) return;\n\n const node = this.#numericNode();\n if (node === null) return;\n const authored = node.data;\n const target = authoredInteger(authored) as number;\n\n // Reduced motion: no ticking, just the final value (WCAG 2.3.3).\n if (prefersReducedMotion()) {\n this.element.setAttribute(\"data-count-up-done\", \"true\");\n this.dispatch(\"end\", { detail: { value: target } });\n return;\n }\n\n // A name may not live on every host — a `<span>` prohibits one, and a role\n // that permits naming would cost a `<dd>` its own semantics — so the ticking\n // number gets a wrapper that permits naming, and the name carries the\n // authored text AT should hear instead of the ticks.\n const ticker = this.#wrap(node, authored);\n const from = this.#from;\n const started = performance.now();\n const step = (now: number): void => {\n const t = Math.min((now - started) / this.#duration, 1);\n const eased = 1 - (1 - t) ** 3; // ease-out cubic\n ticker.textContent = String(Math.round(from + (target - from) * eased));\n if (t < 1) {\n this.#frame = requestAnimationFrame(step);\n } else {\n this.#settle();\n this.dispatch(\"end\", { detail: { value: target } });\n }\n };\n this.#frame = requestAnimationFrame(step);\n }\n\n /** The first text node that displays a number, or null when the host has none. */\n #numericNode(): Text | null {\n const walker = document.createTreeWalker(this.element, NodeFilter.SHOW_TEXT);\n let node = walker.nextNode() as Text | null;\n while (node !== null && authoredInteger(node.data) === null) {\n node = walker.nextNode() as Text | null;\n }\n return node;\n }\n\n /** The wrapper this controller published, if one outlived its run. */\n #ownedTicker(): HTMLElement | null {\n return this.element.querySelector<HTMLElement>(\"[data-count-up-label]\");\n }\n\n /** Publishes the ticking number inside a named wrapper, replacing `node`. */\n #wrap(node: Text, authored: string): HTMLElement {\n const ticker = document.createElement(\"span\");\n ticker.setAttribute(\"data-count-up-label\", \"true\");\n ticker.setAttribute(\"role\", \"img\");\n ticker.setAttribute(\"aria-label\", authored);\n node.replaceWith(ticker);\n ticker.append(node);\n return ticker;\n }\n\n /** Puts `text` back where the wrapper stood, leaving the rest of the host alone. */\n #unwrap(ticker: HTMLElement, text: string | null): void {\n ticker.replaceWith(document.createTextNode(text ?? ticker.textContent ?? \"\"));\n }\n\n /** Ends the run: cancels the frame and restores the authored presentation. */\n #settle(): void {\n if (this.#frame !== null) cancelAnimationFrame(this.#frame);\n this.#frame = null;\n const ticker = this.#ownedTicker();\n if (ticker !== null) this.#unwrap(ticker, ticker.getAttribute(\"aria-label\"));\n this.element.setAttribute(\"data-count-up-done\", \"true\");\n }\n}\n"]}
@@ -24,6 +24,22 @@ import { Controller } from '@hotwired/stimulus';
24
24
  * slot free of live-region semantics: with `announceText` set it would say the
25
25
  * same thing twice.
26
26
  *
27
+ * The slot is shared with the consumer. Completion writes the label in force and
28
+ * marks it with `data-<identifier>-owns-status`, whose value is that text; while
29
+ * the slot still shows that text and nothing else, the controller keeps it on the
30
+ * current `completeLabel` and takes it back once the timer leaves the complete
31
+ * state — `reset`, `start()` counting on from it, or a completion the new reading
32
+ * does not settle (a deadline moved forward or a count turned `up`, in place or
33
+ * before a restore). All but `start()` leave it `paused`, so `resume()` counts
34
+ * again.
35
+ * An empty label puts no text there, so it never displaces what the slot already
36
+ * holds; completing with one claims an empty slot — no text and no element — with
37
+ * an empty marker, which owns the slot whenever it is empty. Text the consumer put
38
+ * there stays theirs while it is there, and so does a slot they put an element in,
39
+ * whatever its text: the label is neither followed into it nor taken back out of
40
+ * it, and its marker stays, until the element is gone. Only a completion with a
41
+ * label writes over either.
42
+ *
27
43
  * `complete` dispatches `{}`; `tick` dispatches
28
44
  * `{ remaining: number, direction: "down" | "up" }`, where `remaining` is in
29
45
  * milliseconds.
@@ -92,7 +108,20 @@ declare class CountdownController extends Controller<HTMLElement> {
92
108
  deadlineValueChanged(): void;
93
109
  /** Re-derives the display when a morph flips the counting direction in place. */
94
110
  directionValueChanged(): void;
95
- /** Starts (or restarts after pause) ticking toward the deadline. */
111
+ /**
112
+ * Follows a completion label swapped in place by a morph.
113
+ *
114
+ * Render only: `complete` is neither dispatched nor announced again. The status
115
+ * changes only after the countdown has completed, and only while it still shows
116
+ * the text this controller wrote there and nothing else, so text or an element
117
+ * the consumer put in the slot stays. A change delivered ahead of `connect()` is
118
+ * left to `connect()`.
119
+ */
120
+ completeLabelValueChanged(): void;
121
+ /**
122
+ * Starts (or restarts after pause) ticking toward the deadline. Counting on from a
123
+ * completion takes this controller's completion text back out of the status.
124
+ */
96
125
  start(): void;
97
126
  /** Pauses ticking, preserving the currently displayed amount. */
98
127
  pause(): void;
@@ -99,7 +99,12 @@ var SafeInterval = class extends TimerRegistry {
99
99
 
100
100
  // src/controllers/countdown_controller.ts
101
101
  var SECOND_MS = 1e3;
102
+ var OWNED_STATUS = "owns-status";
102
103
  var CountdownController = class extends Controller {
104
+ /** The status marker, in the namespace this controller is registered under. */
105
+ get #ownedStatus() {
106
+ return `data-${this.identifier}-${OWNED_STATUS}`;
107
+ }
103
108
  static targets = ["days", "hours", "minutes", "seconds", "status"];
104
109
  static values = {
105
110
  deadline: { type: String, default: "" },
@@ -115,6 +120,12 @@ var CountdownController = class extends Controller {
115
120
  #intervalId = null;
116
121
  /** Collapses a morph that swaps several render inputs at once into one re-derive. */
117
122
  #resync = new MicrotaskCoalescer(() => this.#resyncToValues());
123
+ /**
124
+ * Whether `connect()` has run for this connection. Stimulus delivers Value
125
+ * callbacks ahead of it, while the run state is still the markup's own and not
126
+ * yet settled; `connect()` brings the status up to date once it is.
127
+ */
128
+ #connected = false;
118
129
  /** Epoch-ms anchor: the deadline (down) or the count-up origin (up). */
119
130
  #reference = 0;
120
131
  /** Amount (ms) captured at pause, so resume can restore the same display. */
@@ -127,28 +138,25 @@ var CountdownController = class extends Controller {
127
138
  */
128
139
  #renderedAmount = 0;
129
140
  connect() {
141
+ this.#connected = true;
130
142
  this.#resync.activate();
131
143
  this.#initReference();
132
144
  const amount = this.#currentAmount();
133
145
  this.#render(amount);
134
146
  this.#pausedAmount = this.#renderedAmount;
135
147
  const authored = this.element.getAttribute("data-state");
148
+ const settled = authored === "complete" && this.#isSettled(amount);
136
149
  if (authored === null) {
137
- if (this.autostartValue && this.#isValidDeadline) {
138
- this.start();
139
- return;
140
- }
150
+ if (this.autostartValue && this.#isValidDeadline) this.start();
151
+ else this.element.setAttribute("data-state", "paused");
152
+ } else if (!settled) {
141
153
  this.element.setAttribute("data-state", "paused");
142
- return;
154
+ if (authored === "running") this.start();
143
155
  }
144
- if (authored === "complete" && this.#isDown && amount <= 0) {
145
- return;
146
- }
147
- const wasRunning = authored === "running";
148
- this.element.setAttribute("data-state", "paused");
149
- if (wasRunning) this.start();
156
+ this.#syncStatus();
150
157
  }
151
158
  disconnect() {
159
+ this.#connected = false;
152
160
  this.#resync.cancel();
153
161
  this.#intervals.clearAll();
154
162
  this.#intervalId = null;
@@ -161,6 +169,31 @@ var CountdownController = class extends Controller {
161
169
  directionValueChanged() {
162
170
  this.#resync.schedule();
163
171
  }
172
+ /**
173
+ * Follows a completion label swapped in place by a morph.
174
+ *
175
+ * Render only: `complete` is neither dispatched nor announced again. The status
176
+ * changes only after the countdown has completed, and only while it still shows
177
+ * the text this controller wrote there and nothing else, so text or an element
178
+ * the consumer put in the slot stays. A change delivered ahead of `connect()` is
179
+ * left to `connect()`.
180
+ */
181
+ completeLabelValueChanged() {
182
+ if (this.#connected) this.#syncStatus();
183
+ }
184
+ /**
185
+ * Keeps a status that still shows this controller's text, and nothing else, on
186
+ * what the run state calls for: the label in force while complete; otherwise the
187
+ * text is taken back, marker and all. A status holding anything else is the
188
+ * consumer's and is left alone, marker included.
189
+ *
190
+ * @stimeoRenderRoot
191
+ */
192
+ #syncStatus() {
193
+ if (!this.hasStatusTarget || !this.#ownsStatus(this.statusTarget)) return;
194
+ if (this.#state === "complete") this.#writeStatus(this.statusTarget, this.completeLabelValue);
195
+ else this.#releaseStatus(this.statusTarget);
196
+ }
164
197
  /**
165
198
  * Points the anchor at the current `deadline` / `direction` and repaints.
166
199
  *
@@ -168,13 +201,27 @@ var CountdownController = class extends Controller {
168
201
  * paused timer run or replay a milestone. A running one needs no restart either —
169
202
  * every tick reads the anchor, so moving it is enough. While paused the stored
170
203
  * amount follows the new reading, or resume would continue from the old deadline.
204
+ * A completion the new reading no longer settles (a deadline moved forward, or a
205
+ * count turned `up`) is handed back paused, as `connect()` hands back a restored
206
+ * one, so `resume()` counts again; the completion text this controller wrote goes
207
+ * with it, from a status slot that still shows it and nothing else.
208
+ *
209
+ * @stimeoRenderRoot
171
210
  */
172
211
  #resyncToValues() {
173
212
  this.#initReference();
174
- this.#render(this.#currentAmount());
213
+ const amount = this.#currentAmount();
214
+ this.#render(amount);
215
+ if (this.#state === "complete" && !this.#isSettled(amount)) {
216
+ this.element.setAttribute("data-state", "paused");
217
+ this.#syncStatus();
218
+ }
175
219
  if (this.#state !== "running") this.#pausedAmount = this.#renderedAmount;
176
220
  }
177
- /** Starts (or restarts after pause) ticking toward the deadline. */
221
+ /**
222
+ * Starts (or restarts after pause) ticking toward the deadline. Counting on from a
223
+ * completion takes this controller's completion text back out of the status.
224
+ */
178
225
  start() {
179
226
  if (this.#state === "running" || !this.#isValidDeadline) return;
180
227
  if (this.#isDown && this.#currentAmount() <= 0) {
@@ -212,10 +259,8 @@ var CountdownController = class extends Controller {
212
259
  this.#initReference();
213
260
  const amount = this.#currentAmount();
214
261
  this.#render(amount);
215
- if (this.hasStatusTarget && this.statusTarget.textContent === this.completeLabelValue) {
216
- this.statusTarget.textContent = "";
217
- }
218
262
  this.element.setAttribute("data-state", "paused");
263
+ this.#syncStatus();
219
264
  if (wasRunning && this.#isValidDeadline) {
220
265
  this.#pausedAmount = 0;
221
266
  this.start();
@@ -223,9 +268,19 @@ var CountdownController = class extends Controller {
223
268
  this.#pausedAmount = this.#renderedAmount;
224
269
  }
225
270
  }
226
- /** Schedules the repeating tick and marks the timer running. */
271
+ /**
272
+ * Schedules the repeating tick and marks the timer running. This is the one way
273
+ * into `running`, and a running timer keeps none of this controller's completion
274
+ * text in the status, so the status is settled here as on every other way out of
275
+ * `complete`: `start()` leaves a completion directly when `direction` flips to
276
+ * `up` and `start()` runs in the same task, ahead of the direction callback.
277
+ *
278
+ * @stimeoRuntimeOnly `interval` is the period of the one timer this call arms; the running state
279
+ * it writes does not depend on a Value.
280
+ */
227
281
  #runInterval() {
228
282
  this.element.setAttribute("data-state", "running");
283
+ this.#syncStatus();
229
284
  this.#intervalId = this.#intervals.set(() => this.#tick(), this.intervalValue);
230
285
  }
231
286
  /** Cancels the repeating tick, if any. */
@@ -246,21 +301,73 @@ var CountdownController = class extends Controller {
246
301
  this.#complete();
247
302
  }
248
303
  }
249
- /** Stops at zero, marks completion, announces it, and emits `complete`. */
304
+ /**
305
+ * Stops at zero, marks completion, writes the completion label, emits `complete`,
306
+ * and announces it.
307
+ *
308
+ * @stimeoRenderRoot
309
+ */
250
310
  #complete() {
251
311
  this.#teardownInterval();
252
312
  this.#render(0);
253
313
  this.element.setAttribute("data-state", "complete");
254
- if (this.hasStatusTarget && this.completeLabelValue.length > 0) {
255
- this.statusTarget.textContent = this.completeLabelValue;
256
- }
314
+ this.#claimStatus();
257
315
  this.dispatch("complete", { detail: {} });
316
+ this.#announceCompletion();
317
+ }
318
+ /**
319
+ * Writes the label in force into the status slot as this controller's text. An
320
+ * empty label puts no text there: it claims a slot that is already empty — no
321
+ * text and no element — empties one that is still this controller's, and leaves
322
+ * any other slot, the consumer's, alone.
323
+ */
324
+ #claimStatus() {
325
+ if (!this.hasStatusTarget) return;
326
+ const status = this.statusTarget;
327
+ const label = this.completeLabelValue;
328
+ if (label === "" && !this.#isEmpty(status) && !this.#ownsStatus(status)) return;
329
+ this.#writeStatus(status, label);
330
+ }
331
+ /**
332
+ * Whether the status slot shows the text this controller wrote there and nothing
333
+ * else: the text matches the marker, and the slot holds no element. Writing the
334
+ * slot's text replaces every child node, so an element the consumer puts in the
335
+ * slot makes it theirs even while the text still matches. An empty marker
336
+ * matches the slot whenever it is empty.
337
+ */
338
+ #ownsStatus(status) {
339
+ return status.getAttribute(this.#ownedStatus) === status.textContent && status.firstElementChild === null;
340
+ }
341
+ /** Whether the status slot holds nothing at all: no text and no element. */
342
+ #isEmpty(status) {
343
+ return status.textContent === "" && status.firstElementChild === null;
344
+ }
345
+ /** Puts `text` into the status slot and records it as this controller's. */
346
+ #writeStatus(status, text) {
347
+ if (status.textContent !== text) status.textContent = text;
348
+ status.setAttribute(this.#ownedStatus, text);
349
+ }
350
+ /** Takes this controller's text out of the status slot, marker and all. */
351
+ #releaseStatus(status) {
352
+ status.textContent = "";
353
+ status.removeAttribute(this.#ownedStatus);
354
+ }
355
+ /**
356
+ * Reads the completion out through the shared announcer.
357
+ *
358
+ * @stimeoRuntimeOnly `announceText` words the one announcement a completion makes.
359
+ */
360
+ #announceCompletion() {
258
361
  announce(fillTemplate(this.announceTextValue, {}));
259
362
  }
260
363
  /** Sets the time anchor from the `deadline` value. */
261
364
  #initReference() {
262
365
  this.#reference = Date.parse(this.deadlineValue);
263
366
  }
367
+ /** Whether a reading of `amount` leaves nothing to count: only a countdown at zero. */
368
+ #isSettled(amount) {
369
+ return this.#isDown && amount <= 0;
370
+ }
264
371
  /** Remaining (down) or elapsed (up) ms, never negative. */
265
372
  #currentAmount() {
266
373
  if (!this.#isValidDeadline) return 0;
@@ -268,11 +375,7 @@ var CountdownController = class extends Controller {
268
375
  const raw = this.#isDown ? this.#reference - now : now - this.#reference;
269
376
  return Math.max(0, raw);
270
377
  }
271
- /**
272
- * Writes the amount into the day/hour/minute/second slots.
273
- *
274
- * @stimeoRenderRoot
275
- */
378
+ /** Writes the amount into the day/hour/minute/second slots. */
276
379
  #render(amount) {
277
380
  const totalSeconds = Math.floor(amount / SECOND_MS);
278
381
  this.#renderedAmount = totalSeconds * SECOND_MS;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/announce.ts","../../src/utils/microtask_coalescer.ts","../../src/utils/safe_timeout.ts","../../src/controllers/countdown_controller.ts"],"names":[],"mappings":";;;;;AAoBO,SAAS,QAAA,CAAS,OAAA,EAAiB,OAAA,GAAmC,EAAC,EAAS;AACrF,EAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,EAAK;AAC1B,EAAA,IAAI,IAAA,CAAK,WAAW,CAAA,EAAG;AACvB,EAAA,MAAA,CAAO,aAAA;AAAA,IACL,IAAI,YAA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AACF","file":"countdown_controller.js","sourcesContent":["/**\n * Sends one message to the page's shared `stimeo--announcer`.\n *\n * A component that has to reach assistive tech does not carry a live region of its\n * own: a region only announces what changes *after* assistive tech already knows\n * about it, which a region that appears (or is un-hidden) with its message cannot\n * satisfy. The one region that can is the announcer sitting in the page from the\n * start, so state changes are handed to it as an event and it does the reading.\n *\n * The event goes to `window` because the announcer is usually a sibling high in the\n * document rather than an ancestor of the component dispatching it.\n *\n * Wording comes from the consumer — the library ships no English strings — so an\n * empty message is silently dropped and nothing is announced.\n *\n * @example\n * ```ts\n * announce(this.announceTextValue, { assertive: false });\n * ```\n */\nexport function announce(message: string, options: { assertive?: boolean } = {}): void {\n const text = message.trim();\n if (text.length === 0) return;\n window.dispatchEvent(\n new CustomEvent(\"stimeo--announcer:announce\", {\n detail: { message: text, assertive: options.assertive === true },\n }),\n );\n}\n\n/**\n * Fills `{name}` placeholders in an announcement template from `values`.\n *\n * The same substitution the value-text templates use, so a consumer writes\n * `\"{percent}% complete\"` in one attribute and gets the same rules everywhere. A\n * placeholder with no matching entry is left as authored rather than blanked, which\n * keeps a typo visible instead of silently swallowing the word.\n */\nexport function fillTemplate(template: string, values: Record<string, string | number>): string {\n return template.replace(/\\{([a-zA-Z][a-zA-Z0-9]*)\\}/g, (match, name: string) => {\n const replacement = values[name];\n return replacement === undefined ? match : String(replacement);\n });\n}\n","/**\n * Collapses many Stimulus lifecycle callbacks from one DOM mutation into a\n * single pass.\n *\n * Stimulus fires `<name>TargetConnected` / `Disconnected` once per element and\n * `<name>ValueChanged` once per changed attribute. Replacing a list of N options\n * or morphing several render Values therefore delivers N callbacks — but the\n * useful unit of work is \"reconcile against the resulting declarative input\",\n * once, after the batch has settled. Every controller with reconcilable targets\n * or render Values needs the same shape: a `queued` flag plus `queueMicrotask`.\n *\n * **A microtask is the right horizon, and the reason is specific.** Stimulus\n * drives these callbacks from a `MutationObserver`, whose own callback already\n * runs as a microtask with the whole batch in hand; scheduling one more lands\n * after the last sibling callback of that batch and still before paint or any\n * event handler. A timer would be later than it needs to be, and reconciling\n * synchronously would run once per element against a half-applied DOM.\n *\n * **The two guards are not the same guard.** Scheduling is refused before the\n * controller connects, and running is refused after it disconnects:\n *\n * - **Before `connect()`** — Stimulus delivers initial target and Value callbacks\n * ahead of `connect()`. Reconciling there would compute output against a\n * controller whose own state has not been initialised, and `connect()` is\n * about to do a full pass anyway.\n * - **After `disconnect()`** — Stimulus fires a callback for **every** target\n * during teardown, and a microtask queued just before it would otherwise run\n * against a detached tree. {@link MicrotaskCoalescer.cancel} exists for the\n * teardown path to drop the pending pass outright.\n *\n * Both guards are part of one contract here rather than something each consumer\n * has to remember separately.\n *\n * Scope is the scheduling only. *What* to reconcile — keep the surviving active\n * option, fall back to the next / previous / first visible one, rebuild derived\n * chips or hidden fields — stays in the controller, because no two consumers\n * answer it the same way.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());\n *\n * connect() { this.#reconcile.activate(); }\n * disconnect() { this.#reconcile.cancel(); }\n *\n * optionTargetConnected() { this.#reconcile.schedule(); }\n * optionTargetDisconnected() { this.#reconcile.schedule(); }\n * ```\n */\nexport class MicrotaskCoalescer {\n readonly #run: () => void;\n #queued = false;\n #active = false;\n #generation = 0;\n\n /** @param run - the single reconciliation pass, invoked at most once per batch. */\n constructor(run: () => void) {\n this.#run = run;\n }\n\n /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */\n activate(): void {\n this.#active = true;\n }\n\n /** Closes the window and drops any pending pass; call from `disconnect()`. */\n cancel(): void {\n this.#active = false;\n this.#queued = false;\n this.#generation += 1;\n }\n\n /** Requests one pass after the batch settles. Idempotent; inert outside the window. */\n schedule(): void {\n if (!this.#active || this.#queued) return;\n this.#queued = true;\n const generation = this.#generation;\n queueMicrotask(() => {\n // A cancelled callback must not consume a pass queued after reconnect.\n if (generation !== this.#generation || !this.#queued || !this.#active) return;\n this.#queued = false;\n this.#run();\n });\n }\n}\n","/**\n * Self-cleaning timer registries shared by Stimeo controllers.\n *\n * Stimulus controllers frequently schedule `setTimeout` / `setInterval` work\n * (auto-dismiss, debouncing, polling). When the element leaves the DOM — a\n * Turbo Drive navigation, a Turbo Stream replacement, or any `disconnect()` —\n * orphaned timers keep firing against a detached controller, leaking memory and\n * mutating stale state. {@link SafeTimeout} and {@link SafeInterval} track every\n * timer they create so a single {@link TimerRegistry.clearAll | clearAll()} call\n * in `disconnect()` tears them all down.\n *\n * These are intentionally low-level primitives: they own *registration and\n * cleanup only*. Higher-level policy (pause/resume, remaining-time accounting)\n * stays in the individual controllers so per-widget semantics are not flattened\n * into a lowest-common-denominator helper.\n */\n\n/**\n * Largest delay a timer can hold: the platform stores it in a 32-bit signed\n * integer, and anything larger overflows to `1`, so a delay meant to be far in\n * the future fires almost immediately. A declared delay above this bound names\n * no delay at all, and a controller reading one falls back to its default.\n */\nexport const MAX_TIMER_DELAY_MS = 2_147_483_647;\n\n/**\n * Shared registry bookkeeping for the timeout/interval variants.\n *\n * Subclasses provide the scheduling primitive ({@link schedule}) and its matching\n * canceller ({@link cancel}); this base owns the set of live ids plus the\n * per-id and bulk teardown shared by both.\n */\nabstract class TimerRegistry {\n /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */\n protected readonly ids = new Set<number>();\n\n /** Schedules the underlying platform timer and returns its id. */\n protected abstract schedule(callback: () => void, delay: number): number;\n\n /** Cancels the underlying platform timer for `id`. */\n protected abstract cancel(id: number): void;\n\n /**\n * Cancels a single tracked timer.\n *\n * No-ops if the id is unknown (already cleared, fired, or never owned by this\n * registry), so callers can clear defensively without guarding.\n */\n clear(id: number): void {\n if (this.ids.delete(id)) {\n this.cancel(id);\n }\n }\n\n /**\n * Cancels every tracked timer. Call this from a controller's `disconnect()`\n * to guarantee no timer outlives the element.\n */\n clearAll(): void {\n for (const id of this.ids) {\n this.cancel(id);\n }\n this.ids.clear();\n }\n\n /** Number of timers currently tracked (pending). */\n get size(): number {\n return this.ids.size;\n }\n}\n\n/**\n * `setTimeout` wrapper that auto-forgets each timer once it fires and supports\n * bulk teardown on disconnect.\n *\n * @example\n * ```ts\n * #timers = new SafeTimeout();\n *\n * connect() {\n * this.#timers.set(() => this.dismiss(), 5000);\n * }\n *\n * disconnect() {\n * this.#timers.clearAll();\n * }\n * ```\n */\nexport class SafeTimeout extends TimerRegistry {\n /**\n * Schedules `callback` after `delay` ms and returns the timer id.\n *\n * The id is removed from the registry automatically when the timeout fires,\n * so {@link TimerRegistry.size | size} reflects only still-pending timers.\n */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(() => {\n this.ids.delete(id);\n callback();\n }, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setTimeout(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearTimeout(id);\n }\n}\n\n/**\n * `setInterval` wrapper that tracks every interval for bulk teardown on\n * disconnect. Unlike {@link SafeTimeout}, intervals are retained until they are\n * explicitly cleared because they fire repeatedly.\n *\n * @example\n * ```ts\n * #intervals = new SafeInterval();\n *\n * connect() {\n * this.#intervals.set(() => this.tick(), 1000);\n * }\n *\n * disconnect() {\n * this.#intervals.clearAll();\n * }\n * ```\n */\nexport class SafeInterval extends TimerRegistry {\n /** Schedules a repeating `callback` every `delay` ms and returns the timer id. */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(callback, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setInterval(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearInterval(id);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { announce, fillTemplate } from \"../utils/announce\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\nimport { SafeInterval } from \"../utils/safe_timeout\";\n\n/** Display granularity: the slots render whole seconds, so amounts snap to these. */\nconst SECOND_MS = 1000;\n\n/**\n * Headless countdown/timer behavior built on the live-region `role=\"timer\"`\n * practice (no dedicated APG pattern).\n *\n * Markup contract (identifier: `stimeo--countdown`):\n * <div data-controller=\"stimeo--countdown\" role=\"timer\" aria-live=\"off\"\n * data-stimeo--countdown-deadline-value=\"2026-12-31T23:59:59+09:00\"\n * data-action=\"countdown:pause->stimeo--countdown#pause\n * countdown:resume->stimeo--countdown#resume\">\n * <span data-stimeo--countdown-target=\"days\">0</span>\n * <span data-stimeo--countdown-target=\"hours\">00</span>\n * <span data-stimeo--countdown-target=\"minutes\">00</span>\n * <span data-stimeo--countdown-target=\"seconds\">00</span>\n * </div>\n *\n * Computes the time remaining to `deadline` (or elapsed since it, in\n * `direction=\"up\"`), formats it into the day/hour/minute/second slots, and ticks\n * on `interval`. `aria-live=\"off\"` is recommended so the timer is not announced\n * every second; only the milestone (completion) is surfaced — read out through\n * `announceText`, shown in the optional `status` slot when a `completeLabel` is\n * provided, and handed to the consumer as the `complete` event. Keep the `status`\n * slot free of live-region semantics: with `announceText` set it would say the\n * same thing twice.\n *\n * `complete` dispatches `{}`; `tick` dispatches\n * `{ remaining: number, direction: \"down\" | \"up\" }`, where `remaining` is in\n * milliseconds.\n *\n * @remarks\n * Behavior only — slot text is updated, not styled. Pause/resume shifts an\n * internal time anchor so the displayed amount is preserved across a pause, down\n * to the second actually on screen: resuming continues from that reading rather\n * than from the fraction behind it, so the first tick after a resume steps by one\n * unit like every other. The run state lives in `data-state` and the markup is its\n * source of truth — `autostart` only decides the state of a timer whose markup does\n * not carry one. The interval is owned by `SafeInterval` and torn down on\n * `disconnect()` (Turbo navigation included); nothing else needs carrying across,\n * because every reading is re-derived from `deadline` and the wall clock.\n */\nexport class CountdownController extends Controller<HTMLElement> {\n static override targets = [\"days\", \"hours\", \"minutes\", \"seconds\", \"status\"];\n static override values = {\n deadline: { type: String, default: \"\" },\n interval: { type: Number, default: 1000 },\n direction: { type: String, default: \"down\" },\n autostart: { type: Boolean, default: true },\n completeLabel: { type: String, default: \"\" },\n announceText: { type: String, default: \"\" },\n };\n static actions = [\"pause\", \"reset\", \"resume\", \"start\"] as const;\n static events = [\"complete\", \"tick\"] as const;\n\n declare readonly daysTarget: HTMLElement;\n declare readonly hoursTarget: HTMLElement;\n declare readonly minutesTarget: HTMLElement;\n declare readonly secondsTarget: HTMLElement;\n declare readonly statusTarget: HTMLElement;\n declare readonly hasDaysTarget: boolean;\n declare readonly hasHoursTarget: boolean;\n declare readonly hasMinutesTarget: boolean;\n declare readonly hasSecondsTarget: boolean;\n declare readonly hasStatusTarget: boolean;\n\n declare deadlineValue: string;\n declare intervalValue: number;\n declare directionValue: string;\n declare autostartValue: boolean;\n declare completeLabelValue: string;\n declare announceTextValue: string;\n\n readonly #intervals = new SafeInterval();\n #intervalId: number | null = null;\n /** Collapses a morph that swaps several render inputs at once into one re-derive. */\n readonly #resync = new MicrotaskCoalescer(() => this.#resyncToValues());\n\n /** Epoch-ms anchor: the deadline (down) or the count-up origin (up). */\n #reference = 0;\n /** Amount (ms) captured at pause, so resume can restore the same display. */\n #pausedAmount = 0;\n /**\n * The amount the slots are currently showing, floored to the second they render.\n * It lags {@link #currentAmount} by up to one tick, and it — not the live reading —\n * is what a pause has to preserve: storing the fraction behind the display instead\n * makes the first tick after a resume step by two units.\n */\n #renderedAmount = 0;\n\n override connect(): void {\n this.#resync.activate();\n this.#initReference();\n const amount = this.#currentAmount();\n this.#render(amount);\n // Remember what is on screen so resume() continues from it instead of snapping\n // the anchor to now (which would settle a countdown at once).\n this.#pausedAmount = this.#renderedAmount;\n\n const authored = this.element.getAttribute(\"data-state\");\n if (authored === null) {\n // Nothing to honor: this is the declarative first render, which is the only\n // thing `autostart` governs.\n if (this.autostartValue && this.#isValidDeadline) {\n this.start();\n return;\n }\n this.element.setAttribute(\"data-state\", \"paused\");\n return;\n }\n if (authored === \"complete\" && this.#isDown && amount <= 0) {\n // Still settled, so the milestone stands. Dropping it to the resting state\n // would let a later resume() cross zero a second time and announce the same\n // completion again; only a deadline moved forward re-arms it.\n return;\n }\n // A pause the user made survives the round trip, but nothing carries a live timer\n // across it — a restored \"running\" has to be re-armed here or it renders once and\n // freezes, because start() is a no-op while the attribute still says \"running\".\n const wasRunning = authored === \"running\";\n this.element.setAttribute(\"data-state\", \"paused\");\n if (wasRunning) this.start();\n }\n\n override disconnect(): void {\n this.#resync.cancel();\n this.#intervals.clearAll();\n this.#intervalId = null;\n }\n\n /** Re-derives the display when a morph swaps the deadline in place. */\n deadlineValueChanged(): void {\n this.#resync.schedule();\n }\n\n /** Re-derives the display when a morph flips the counting direction in place. */\n directionValueChanged(): void {\n this.#resync.schedule();\n }\n\n /**\n * Points the anchor at the current `deadline` / `direction` and repaints.\n *\n * Render only: it starts no interval and emits no event, so a morph cannot make a\n * paused timer run or replay a milestone. A running one needs no restart either —\n * every tick reads the anchor, so moving it is enough. While paused the stored\n * amount follows the new reading, or resume would continue from the old deadline.\n */\n #resyncToValues(): void {\n this.#initReference();\n this.#render(this.#currentAmount());\n if (this.#state !== \"running\") this.#pausedAmount = this.#renderedAmount;\n }\n\n /** Starts (or restarts after pause) ticking toward the deadline. */\n start(): void {\n if (this.#state === \"running\" || !this.#isValidDeadline) return;\n if (this.#isDown && this.#currentAmount() <= 0) {\n // Already settled — a restored snapshot keeps data-state=\"complete\". The\n // milestone was announced in the visit that reached zero, so completing again\n // here would re-emit `complete` on every reconnect.\n if (this.#state !== \"complete\") this.#complete();\n return;\n }\n this.#runInterval();\n }\n\n /** Pauses ticking, preserving the currently displayed amount. */\n pause(): void {\n if (this.#state !== \"running\") return;\n this.#pausedAmount = this.#renderedAmount;\n this.#teardownInterval();\n this.element.setAttribute(\"data-state\", \"paused\");\n }\n\n /** Resumes from a pause, continuing from the preserved amount. */\n resume(): void {\n if (this.#state !== \"paused\" || !this.#isValidDeadline) return;\n const now = Date.now();\n this.#reference = this.#isDown ? now + this.#pausedAmount : now - this.#pausedAmount;\n this.start();\n }\n\n /**\n * Re-syncs to the deadline and clears any pause offset, **preserving the current\n * run state**: a running timer keeps counting down from the reset amount, while a\n * paused (or completed) one resets the displayed amount but stays paused until the\n * user resumes — it never silently restarts. The run state is read from the DOM,\n * not re-derived from the declarative `autostart` Value (which governs only markup\n * that states no run state at all); re-deriving it would override a user's pause —\n * the DOM, not a re-run of declarative config, is the source of truth.\n */\n reset(): void {\n const wasRunning = this.#state === \"running\";\n this.#teardownInterval();\n this.#initReference();\n const amount = this.#currentAmount();\n this.#render(amount);\n // A prior complete() may have written a completion message into the status\n // slot; clear it so a reset timer does not keep showing the stale \"finished\"\n // text. Only that message is ours to take back — `complete()` declines to write\n // when `completeLabel` is empty, so anything else in there belongs to the\n // consumer.\n if (this.hasStatusTarget && this.statusTarget.textContent === this.completeLabelValue) {\n this.statusTarget.textContent = \"\";\n }\n // teardownInterval() leaves data-state untouched; drop any lingering \"running\" to a\n // resting \"paused\" so start() (a no-op while \"running\") can re-arm when we resume.\n this.element.setAttribute(\"data-state\", \"paused\");\n if (wasRunning && this.#isValidDeadline) {\n // Was counting down: re-arm and keep running from the reset amount.\n this.#pausedAmount = 0;\n this.start();\n } else {\n // Was paused/complete: hold at the reset amount and wait for the user to resume.\n // Remember what is on screen so resume() restores it instead of snapping the\n // anchor to 0.\n this.#pausedAmount = this.#renderedAmount;\n }\n }\n\n /** Schedules the repeating tick and marks the timer running. */\n #runInterval(): void {\n this.element.setAttribute(\"data-state\", \"running\");\n this.#intervalId = this.#intervals.set(() => this.#tick(), this.intervalValue);\n }\n\n /** Cancels the repeating tick, if any. */\n #teardownInterval(): void {\n if (this.#intervalId !== null) {\n this.#intervals.clear(this.#intervalId);\n this.#intervalId = null;\n }\n }\n\n /** Recomputes, renders, emits `tick`, and completes when a countdown hits 0. */\n #tick(): void {\n const amount = this.#currentAmount();\n this.#render(amount);\n // `remaining` is the displayed amount (time left when counting down, elapsed\n // when counting up); `direction` lets consumers disambiguate the two.\n this.dispatch(\"tick\", {\n detail: { remaining: amount, direction: this.#isDown ? \"down\" : \"up\" },\n });\n if (this.#isDown && this.#reference - Date.now() <= 0) {\n this.#complete();\n }\n }\n\n /** Stops at zero, marks completion, announces it, and emits `complete`. */\n #complete(): void {\n this.#teardownInterval();\n this.#render(0);\n this.element.setAttribute(\"data-state\", \"complete\");\n if (this.hasStatusTarget && this.completeLabelValue.length > 0) {\n this.statusTarget.textContent = this.completeLabelValue;\n }\n this.dispatch(\"complete\", { detail: {} });\n // Reaching zero is the transition; the ticking numbers in between are state\n // the consumer can see, and reading each one would be unusable.\n announce(fillTemplate(this.announceTextValue, {}));\n }\n\n /** Sets the time anchor from the `deadline` value. */\n #initReference(): void {\n this.#reference = Date.parse(this.deadlineValue);\n }\n\n /** Remaining (down) or elapsed (up) ms, never negative. */\n #currentAmount(): number {\n if (!this.#isValidDeadline) return 0;\n const now = Date.now();\n const raw = this.#isDown ? this.#reference - now : now - this.#reference;\n return Math.max(0, raw);\n }\n\n /**\n * Writes the amount into the day/hour/minute/second slots.\n *\n * @stimeoRenderRoot\n */\n #render(amount: number): void {\n const totalSeconds = Math.floor(amount / SECOND_MS);\n this.#renderedAmount = totalSeconds * SECOND_MS;\n const days = Math.floor(totalSeconds / 86400);\n const hours = Math.floor((totalSeconds % 86400) / 3600);\n const minutes = Math.floor((totalSeconds % 3600) / 60);\n const seconds = totalSeconds % 60;\n\n if (this.hasDaysTarget) this.daysTarget.textContent = String(days);\n if (this.hasHoursTarget) this.hoursTarget.textContent = this.#pad(hours);\n if (this.hasMinutesTarget) this.minutesTarget.textContent = this.#pad(minutes);\n if (this.hasSecondsTarget) this.secondsTarget.textContent = this.#pad(seconds);\n }\n\n /** Zero-pads a unit to two digits. */\n #pad(unit: number): string {\n return String(unit).padStart(2, \"0\");\n }\n\n get #isDown(): boolean {\n return this.directionValue !== \"up\";\n }\n\n get #isValidDeadline(): boolean {\n return !Number.isNaN(this.#reference);\n }\n\n /** Current lifecycle phase as reflected on `data-state`. */\n get #state(): string {\n return this.element.getAttribute(\"data-state\") ?? \"paused\";\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/announce.ts","../../src/utils/microtask_coalescer.ts","../../src/utils/safe_timeout.ts","../../src/controllers/countdown_controller.ts"],"names":[],"mappings":";;;;;AAoBO,SAAS,QAAA,CAAS,OAAA,EAAiB,OAAA,GAAmC,EAAC,EAAS;AACrF,EAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,EAAK;AAC1B,EAAA,IAAI,IAAA,CAAK,WAAW,CAAA,EAAG;AACvB,EAAA,MAAA,CAAO,aAAA;AAAA,IACL,IAAI,YAAY,4BAAA,EAA8B;AAAA,MAC5C,QAAQ,EAAE,OAAA,EAAS,MAAM,SAAA,EAAW,OAAA,CAAQ,cAAc,IAAA;AAAK,KAChE;AAAA,GACH;AACF;AAUO,SAAS,YAAA,CAAa,UAAkB,MAAA,EAAiD;AAC9F,EAAA,OAAO,QAAA,CAAS,OAAA,CAAQ,6BAAA,EAA+B,CAAC,OAAO,IAAA,KAAiB;AAC9E,IAAA,MAAM,WAAA,GAAc,OAAO,IAAI,CAAA;AAC/B,IAAA,OAAO,WAAA,KAAgB,MAAA,GAAY,KAAA,GAAQ,MAAA,CAAO,WAAW,CAAA;AAAA,EAC/D,CAAC,CAAA;AACH;;;ACUO,IAAM,qBAAN,MAAyB;AAAA,EACrB,IAAA;AAAA,EACT,OAAA,GAAU,KAAA;AAAA,EACV,OAAA,GAAU,KAAA;AAAA,EACV,WAAA,GAAc,CAAA;AAAA;AAAA,EAGd,YAAY,GAAA,EAAiB;AAC3B,IAAA,IAAA,CAAK,IAAA,GAAO,GAAA;AAAA,EACd;AAAA;AAAA,EAGA,QAAA,GAAiB;AACf,IAAA,IAAA,CAAK,OAAA,GAAU,IAAA;AAAA,EACjB;AAAA;AAAA,EAGA,MAAA,GAAe;AACb,IAAA,IAAA,CAAK,OAAA,GAAU,KAAA;AACf,IAAA,IAAA,CAAK,OAAA,GAAU,KAAA;AACf,IAAA,IAAA,CAAK,WAAA,IAAe,CAA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,CAAM,IAAA,CAAK,UAAU,CAAA;AAAA,EACtC;AAAA;AAAA,EAGA,IAAI,MAAA,GAAiB;AACnB,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,YAAY,CAAA,IAAK,QAAA;AAAA,EACpD;AACF","file":"countdown_controller.js","sourcesContent":["/**\n * Sends one message to the page's shared `stimeo--announcer`.\n *\n * A component that has to reach assistive tech does not carry a live region of its\n * own: a region only announces what changes *after* assistive tech already knows\n * about it, which a region that appears (or is un-hidden) with its message cannot\n * satisfy. The one region that can is the announcer sitting in the page from the\n * start, so state changes are handed to it as an event and it does the reading.\n *\n * The event goes to `window` because the announcer is usually a sibling high in the\n * document rather than an ancestor of the component dispatching it.\n *\n * Wording comes from the consumer — the library ships no English strings — so an\n * empty message is silently dropped and nothing is announced.\n *\n * @example\n * ```ts\n * announce(this.announceTextValue, { assertive: false });\n * ```\n */\nexport function announce(message: string, options: { assertive?: boolean } = {}): void {\n const text = message.trim();\n if (text.length === 0) return;\n window.dispatchEvent(\n new CustomEvent(\"stimeo--announcer:announce\", {\n detail: { message: text, assertive: options.assertive === true },\n }),\n );\n}\n\n/**\n * Fills `{name}` placeholders in an announcement template from `values`.\n *\n * The same substitution the value-text templates use, so a consumer writes\n * `\"{percent}% complete\"` in one attribute and gets the same rules everywhere. A\n * placeholder with no matching entry is left as authored rather than blanked, which\n * keeps a typo visible instead of silently swallowing the word.\n */\nexport function fillTemplate(template: string, values: Record<string, string | number>): string {\n return template.replace(/\\{([a-zA-Z][a-zA-Z0-9]*)\\}/g, (match, name: string) => {\n const replacement = values[name];\n return replacement === undefined ? match : String(replacement);\n });\n}\n","/**\n * Collapses many Stimulus lifecycle callbacks from one DOM mutation into a\n * single pass.\n *\n * Stimulus fires `<name>TargetConnected` / `Disconnected` once per element and\n * `<name>ValueChanged` once per changed attribute. Replacing a list of N options\n * or morphing several render Values therefore delivers N callbacks — but the\n * useful unit of work is \"reconcile against the resulting declarative input\",\n * once, after the batch has settled. Every controller with reconcilable targets\n * or render Values needs the same shape: a `queued` flag plus `queueMicrotask`.\n *\n * **A microtask is the right horizon, and the reason is specific.** Stimulus\n * drives these callbacks from a `MutationObserver`, whose own callback already\n * runs as a microtask with the whole batch in hand; scheduling one more lands\n * after the last sibling callback of that batch and still before paint or any\n * event handler. A timer would be later than it needs to be, and reconciling\n * synchronously would run once per element against a half-applied DOM.\n *\n * **The two guards are not the same guard.** Scheduling is refused before the\n * controller connects, and running is refused after it disconnects:\n *\n * - **Before `connect()`** — Stimulus delivers initial target and Value callbacks\n * ahead of `connect()`. Reconciling there would compute output against a\n * controller whose own state has not been initialised, and `connect()` is\n * about to do a full pass anyway.\n * - **After `disconnect()`** — Stimulus fires a callback for **every** target\n * during teardown, and a microtask queued just before it would otherwise run\n * against a detached tree. {@link MicrotaskCoalescer.cancel} exists for the\n * teardown path to drop the pending pass outright.\n *\n * Both guards are part of one contract here rather than something each consumer\n * has to remember separately.\n *\n * Scope is the scheduling only. *What* to reconcile — keep the surviving active\n * option, fall back to the next / previous / first visible one, rebuild derived\n * chips or hidden fields — stays in the controller, because no two consumers\n * answer it the same way.\n *\n * This file's own doc block is dropped from `dist`, but every member comment is\n * inlined into each consumer entry (`tsup` builds with `splitting: false`), so\n * rationale belongs here and only the contract belongs on the members.\n *\n * @example\n * ```ts\n * readonly #reconcile = new MicrotaskCoalescer(() => this.#reconcileOptions());\n *\n * connect() { this.#reconcile.activate(); }\n * disconnect() { this.#reconcile.cancel(); }\n *\n * optionTargetConnected() { this.#reconcile.schedule(); }\n * optionTargetDisconnected() { this.#reconcile.schedule(); }\n * ```\n */\nexport class MicrotaskCoalescer {\n readonly #run: () => void;\n #queued = false;\n #active = false;\n #generation = 0;\n\n /** @param run - the single reconciliation pass, invoked at most once per batch. */\n constructor(run: () => void) {\n this.#run = run;\n }\n\n /** Opens the window in which {@link schedule} is honoured; call from `connect()`. */\n activate(): void {\n this.#active = true;\n }\n\n /** Closes the window and drops any pending pass; call from `disconnect()`. */\n cancel(): void {\n this.#active = false;\n this.#queued = false;\n this.#generation += 1;\n }\n\n /** Requests one pass after the batch settles. Idempotent; inert outside the window. */\n schedule(): void {\n if (!this.#active || this.#queued) return;\n this.#queued = true;\n const generation = this.#generation;\n queueMicrotask(() => {\n // A cancelled callback must not consume a pass queued after reconnect.\n if (generation !== this.#generation || !this.#queued || !this.#active) return;\n this.#queued = false;\n this.#run();\n });\n }\n}\n","/**\n * Self-cleaning timer registries shared by Stimeo controllers.\n *\n * Stimulus controllers frequently schedule `setTimeout` / `setInterval` work\n * (auto-dismiss, debouncing, polling). When the element leaves the DOM — a\n * Turbo Drive navigation, a Turbo Stream replacement, or any `disconnect()` —\n * orphaned timers keep firing against a detached controller, leaking memory and\n * mutating stale state. {@link SafeTimeout} and {@link SafeInterval} track every\n * timer they create so a single {@link TimerRegistry.clearAll | clearAll()} call\n * in `disconnect()` tears them all down.\n *\n * These are intentionally low-level primitives: they own *registration and\n * cleanup only*. Higher-level policy (pause/resume, remaining-time accounting)\n * stays in the individual controllers so per-widget semantics are not flattened\n * into a lowest-common-denominator helper.\n */\n\n/**\n * Largest delay a timer can hold: the platform stores it in a 32-bit signed\n * integer, and anything larger overflows to `1`, so a delay meant to be far in\n * the future fires almost immediately. A declared delay above this bound names\n * no delay at all, and a controller reading one falls back to its default.\n */\nexport const MAX_TIMER_DELAY_MS = 2_147_483_647;\n\n/**\n * Shared registry bookkeeping for the timeout/interval variants.\n *\n * Subclasses provide the scheduling primitive ({@link schedule}) and its matching\n * canceller ({@link cancel}); this base owns the set of live ids plus the\n * per-id and bulk teardown shared by both.\n */\nabstract class TimerRegistry {\n /** Live timer ids that have not yet been cleared (or, for timeouts, fired). */\n protected readonly ids = new Set<number>();\n\n /** Schedules the underlying platform timer and returns its id. */\n protected abstract schedule(callback: () => void, delay: number): number;\n\n /** Cancels the underlying platform timer for `id`. */\n protected abstract cancel(id: number): void;\n\n /**\n * Cancels a single tracked timer.\n *\n * No-ops if the id is unknown (already cleared, fired, or never owned by this\n * registry), so callers can clear defensively without guarding.\n */\n clear(id: number): void {\n if (this.ids.delete(id)) {\n this.cancel(id);\n }\n }\n\n /**\n * Cancels every tracked timer. Call this from a controller's `disconnect()`\n * to guarantee no timer outlives the element.\n */\n clearAll(): void {\n for (const id of this.ids) {\n this.cancel(id);\n }\n this.ids.clear();\n }\n\n /** Number of timers currently tracked (pending). */\n get size(): number {\n return this.ids.size;\n }\n}\n\n/**\n * `setTimeout` wrapper that auto-forgets each timer once it fires and supports\n * bulk teardown on disconnect.\n *\n * @example\n * ```ts\n * #timers = new SafeTimeout();\n *\n * connect() {\n * this.#timers.set(() => this.dismiss(), 5000);\n * }\n *\n * disconnect() {\n * this.#timers.clearAll();\n * }\n * ```\n */\nexport class SafeTimeout extends TimerRegistry {\n /**\n * Schedules `callback` after `delay` ms and returns the timer id.\n *\n * The id is removed from the registry automatically when the timeout fires,\n * so {@link TimerRegistry.size | size} reflects only still-pending timers.\n */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(() => {\n this.ids.delete(id);\n callback();\n }, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setTimeout(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearTimeout(id);\n }\n}\n\n/**\n * `setInterval` wrapper that tracks every interval for bulk teardown on\n * disconnect. Unlike {@link SafeTimeout}, intervals are retained until they are\n * explicitly cleared because they fire repeatedly.\n *\n * @example\n * ```ts\n * #intervals = new SafeInterval();\n *\n * connect() {\n * this.#intervals.set(() => this.tick(), 1000);\n * }\n *\n * disconnect() {\n * this.#intervals.clearAll();\n * }\n * ```\n */\nexport class SafeInterval extends TimerRegistry {\n /** Schedules a repeating `callback` every `delay` ms and returns the timer id. */\n set(callback: () => void, delay: number): number {\n const id = this.schedule(callback, delay);\n this.ids.add(id);\n return id;\n }\n\n protected schedule(callback: () => void, delay: number): number {\n return window.setInterval(callback, delay);\n }\n\n protected cancel(id: number): void {\n window.clearInterval(id);\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { announce, fillTemplate } from \"../utils/announce\";\nimport { MicrotaskCoalescer } from \"../utils/microtask_coalescer\";\nimport { SafeInterval } from \"../utils/safe_timeout\";\n\n/** Display granularity: the slots render whole seconds, so amounts snap to these. */\nconst SECOND_MS = 1000;\n\n/**\n * Suffix of the marker on the text this controller wrote into the `status` slot;\n * the marker holds that text as its value. The slot is this controller's only while\n * it shows that text and nothing else: the two still agree, and the slot holds no\n * element. While the marker holds text, a slot the consumer rewrites or empties\n * afterwards is theirs; a marker with an empty value owns the empty slot, including\n * one the consumer empties again after writing into it. An element the consumer\n * puts in the slot makes it theirs either way, for as long as it is there. A\n * restored page carries the claim along with the text.\n */\nconst OWNED_STATUS = \"owns-status\";\n\n/**\n * Headless countdown/timer behavior built on the live-region `role=\"timer\"`\n * practice (no dedicated APG pattern).\n *\n * Markup contract (identifier: `stimeo--countdown`):\n * <div data-controller=\"stimeo--countdown\" role=\"timer\" aria-live=\"off\"\n * data-stimeo--countdown-deadline-value=\"2026-12-31T23:59:59+09:00\"\n * data-action=\"countdown:pause->stimeo--countdown#pause\n * countdown:resume->stimeo--countdown#resume\">\n * <span data-stimeo--countdown-target=\"days\">0</span>\n * <span data-stimeo--countdown-target=\"hours\">00</span>\n * <span data-stimeo--countdown-target=\"minutes\">00</span>\n * <span data-stimeo--countdown-target=\"seconds\">00</span>\n * </div>\n *\n * Computes the time remaining to `deadline` (or elapsed since it, in\n * `direction=\"up\"`), formats it into the day/hour/minute/second slots, and ticks\n * on `interval`. `aria-live=\"off\"` is recommended so the timer is not announced\n * every second; only the milestone (completion) is surfaced — read out through\n * `announceText`, shown in the optional `status` slot when a `completeLabel` is\n * provided, and handed to the consumer as the `complete` event. Keep the `status`\n * slot free of live-region semantics: with `announceText` set it would say the\n * same thing twice.\n *\n * The slot is shared with the consumer. Completion writes the label in force and\n * marks it with `data-<identifier>-owns-status`, whose value is that text; while\n * the slot still shows that text and nothing else, the controller keeps it on the\n * current `completeLabel` and takes it back once the timer leaves the complete\n * state — `reset`, `start()` counting on from it, or a completion the new reading\n * does not settle (a deadline moved forward or a count turned `up`, in place or\n * before a restore). All but `start()` leave it `paused`, so `resume()` counts\n * again.\n * An empty label puts no text there, so it never displaces what the slot already\n * holds; completing with one claims an empty slot — no text and no element — with\n * an empty marker, which owns the slot whenever it is empty. Text the consumer put\n * there stays theirs while it is there, and so does a slot they put an element in,\n * whatever its text: the label is neither followed into it nor taken back out of\n * it, and its marker stays, until the element is gone. Only a completion with a\n * label writes over either.\n *\n * `complete` dispatches `{}`; `tick` dispatches\n * `{ remaining: number, direction: \"down\" | \"up\" }`, where `remaining` is in\n * milliseconds.\n *\n * @remarks\n * Behavior only — slot text is updated, not styled. Pause/resume shifts an\n * internal time anchor so the displayed amount is preserved across a pause, down\n * to the second actually on screen: resuming continues from that reading rather\n * than from the fraction behind it, so the first tick after a resume steps by one\n * unit like every other. The run state lives in `data-state` and the markup is its\n * source of truth — `autostart` only decides the state of a timer whose markup does\n * not carry one. The interval is owned by `SafeInterval` and torn down on\n * `disconnect()` (Turbo navigation included); nothing else needs carrying across,\n * because every reading is re-derived from `deadline` and the wall clock.\n */\nexport class CountdownController extends Controller<HTMLElement> {\n /** The status marker, in the namespace this controller is registered under. */\n get #ownedStatus(): string {\n return `data-${this.identifier}-${OWNED_STATUS}`;\n }\n\n static override targets = [\"days\", \"hours\", \"minutes\", \"seconds\", \"status\"];\n static override values = {\n deadline: { type: String, default: \"\" },\n interval: { type: Number, default: 1000 },\n direction: { type: String, default: \"down\" },\n autostart: { type: Boolean, default: true },\n completeLabel: { type: String, default: \"\" },\n announceText: { type: String, default: \"\" },\n };\n static actions = [\"pause\", \"reset\", \"resume\", \"start\"] as const;\n static events = [\"complete\", \"tick\"] as const;\n\n declare readonly daysTarget: HTMLElement;\n declare readonly hoursTarget: HTMLElement;\n declare readonly minutesTarget: HTMLElement;\n declare readonly secondsTarget: HTMLElement;\n declare readonly statusTarget: HTMLElement;\n declare readonly hasDaysTarget: boolean;\n declare readonly hasHoursTarget: boolean;\n declare readonly hasMinutesTarget: boolean;\n declare readonly hasSecondsTarget: boolean;\n declare readonly hasStatusTarget: boolean;\n\n declare deadlineValue: string;\n declare intervalValue: number;\n declare directionValue: string;\n declare autostartValue: boolean;\n declare completeLabelValue: string;\n declare announceTextValue: string;\n\n readonly #intervals = new SafeInterval();\n #intervalId: number | null = null;\n /** Collapses a morph that swaps several render inputs at once into one re-derive. */\n readonly #resync = new MicrotaskCoalescer(() => this.#resyncToValues());\n /**\n * Whether `connect()` has run for this connection. Stimulus delivers Value\n * callbacks ahead of it, while the run state is still the markup's own and not\n * yet settled; `connect()` brings the status up to date once it is.\n */\n #connected = false;\n\n /** Epoch-ms anchor: the deadline (down) or the count-up origin (up). */\n #reference = 0;\n /** Amount (ms) captured at pause, so resume can restore the same display. */\n #pausedAmount = 0;\n /**\n * The amount the slots are currently showing, floored to the second they render.\n * It lags {@link #currentAmount} by up to one tick, and it — not the live reading —\n * is what a pause has to preserve: storing the fraction behind the display instead\n * makes the first tick after a resume step by two units.\n */\n #renderedAmount = 0;\n\n override connect(): void {\n this.#connected = true;\n this.#resync.activate();\n this.#initReference();\n const amount = this.#currentAmount();\n this.#render(amount);\n // Remember what is on screen so resume() continues from it instead of snapping\n // the anchor to now (which would settle a countdown at once).\n this.#pausedAmount = this.#renderedAmount;\n\n const authored = this.element.getAttribute(\"data-state\");\n // A completion that is still settled stands. Dropping it to the resting state\n // would let a later resume() cross zero a second time and announce the same\n // completion again; only a reading that no longer settles it — a deadline\n // moved forward, or a count turned `up` — re-arms it.\n const settled = authored === \"complete\" && this.#isSettled(amount);\n if (authored === null) {\n // Nothing to honor: this is the declarative first render, which is the only\n // thing `autostart` governs.\n if (this.autostartValue && this.#isValidDeadline) this.start();\n else this.element.setAttribute(\"data-state\", \"paused\");\n } else if (!settled) {\n // A pause the user made survives the round trip, but nothing carries a live\n // timer across it — a restored \"running\" has to be re-armed here or it renders\n // once and freezes, because start() is a no-op while the attribute still says\n // \"running\".\n this.element.setAttribute(\"data-state\", \"paused\");\n if (authored === \"running\") this.start();\n }\n // Value callbacks ran ahead of this, before the run state above was settled, so a\n // status still holding this controller's text is brought up to date here.\n this.#syncStatus();\n }\n\n override disconnect(): void {\n this.#connected = false;\n this.#resync.cancel();\n this.#intervals.clearAll();\n this.#intervalId = null;\n }\n\n /** Re-derives the display when a morph swaps the deadline in place. */\n deadlineValueChanged(): void {\n this.#resync.schedule();\n }\n\n /** Re-derives the display when a morph flips the counting direction in place. */\n directionValueChanged(): void {\n this.#resync.schedule();\n }\n\n /**\n * Follows a completion label swapped in place by a morph.\n *\n * Render only: `complete` is neither dispatched nor announced again. The status\n * changes only after the countdown has completed, and only while it still shows\n * the text this controller wrote there and nothing else, so text or an element\n * the consumer put in the slot stays. A change delivered ahead of `connect()` is\n * left to `connect()`.\n */\n completeLabelValueChanged(): void {\n if (this.#connected) this.#syncStatus();\n }\n\n /**\n * Keeps a status that still shows this controller's text, and nothing else, on\n * what the run state calls for: the label in force while complete; otherwise the\n * text is taken back, marker and all. A status holding anything else is the\n * consumer's and is left alone, marker included.\n *\n * @stimeoRenderRoot\n */\n #syncStatus(): void {\n if (!this.hasStatusTarget || !this.#ownsStatus(this.statusTarget)) return;\n if (this.#state === \"complete\") this.#writeStatus(this.statusTarget, this.completeLabelValue);\n else this.#releaseStatus(this.statusTarget);\n }\n\n /**\n * Points the anchor at the current `deadline` / `direction` and repaints.\n *\n * Render only: it starts no interval and emits no event, so a morph cannot make a\n * paused timer run or replay a milestone. A running one needs no restart either —\n * every tick reads the anchor, so moving it is enough. While paused the stored\n * amount follows the new reading, or resume would continue from the old deadline.\n * A completion the new reading no longer settles (a deadline moved forward, or a\n * count turned `up`) is handed back paused, as `connect()` hands back a restored\n * one, so `resume()` counts again; the completion text this controller wrote goes\n * with it, from a status slot that still shows it and nothing else.\n *\n * @stimeoRenderRoot\n */\n #resyncToValues(): void {\n this.#initReference();\n const amount = this.#currentAmount();\n this.#render(amount);\n if (this.#state === \"complete\" && !this.#isSettled(amount)) {\n this.element.setAttribute(\"data-state\", \"paused\");\n this.#syncStatus();\n }\n if (this.#state !== \"running\") this.#pausedAmount = this.#renderedAmount;\n }\n\n /**\n * Starts (or restarts after pause) ticking toward the deadline. Counting on from a\n * completion takes this controller's completion text back out of the status.\n */\n start(): void {\n if (this.#state === \"running\" || !this.#isValidDeadline) return;\n if (this.#isDown && this.#currentAmount() <= 0) {\n // Already settled — a restored snapshot keeps data-state=\"complete\". The\n // milestone was announced in the visit that reached zero, so completing again\n // here would re-emit `complete` on every reconnect.\n if (this.#state !== \"complete\") this.#complete();\n return;\n }\n this.#runInterval();\n }\n\n /** Pauses ticking, preserving the currently displayed amount. */\n pause(): void {\n if (this.#state !== \"running\") return;\n this.#pausedAmount = this.#renderedAmount;\n this.#teardownInterval();\n this.element.setAttribute(\"data-state\", \"paused\");\n }\n\n /** Resumes from a pause, continuing from the preserved amount. */\n resume(): void {\n if (this.#state !== \"paused\" || !this.#isValidDeadline) return;\n const now = Date.now();\n this.#reference = this.#isDown ? now + this.#pausedAmount : now - this.#pausedAmount;\n this.start();\n }\n\n /**\n * Re-syncs to the deadline and clears any pause offset, **preserving the current\n * run state**: a running timer keeps counting down from the reset amount, while a\n * paused (or completed) one resets the displayed amount but stays paused until the\n * user resumes — it never silently restarts. The run state is read from the DOM,\n * not re-derived from the declarative `autostart` Value (which governs only markup\n * that states no run state at all); re-deriving it would override a user's pause —\n * the DOM, not a re-run of declarative config, is the source of truth.\n */\n reset(): void {\n const wasRunning = this.#state === \"running\";\n this.#teardownInterval();\n this.#initReference();\n const amount = this.#currentAmount();\n this.#render(amount);\n // teardownInterval() leaves data-state untouched; drop any lingering \"running\" to a\n // resting \"paused\" so start() (a no-op while \"running\") can re-arm when we resume.\n this.element.setAttribute(\"data-state\", \"paused\");\n // A reset timer has left the complete state, so the completion text this\n // controller wrote leaves the status slot with it; a slot the consumer rewrote or\n // put an element in stays as it is.\n this.#syncStatus();\n if (wasRunning && this.#isValidDeadline) {\n // Was counting down: re-arm and keep running from the reset amount.\n this.#pausedAmount = 0;\n this.start();\n } else {\n // Was paused/complete: hold at the reset amount and wait for the user to resume.\n // Remember what is on screen so resume() restores it instead of snapping the\n // anchor to 0.\n this.#pausedAmount = this.#renderedAmount;\n }\n }\n\n /**\n * Schedules the repeating tick and marks the timer running. This is the one way\n * into `running`, and a running timer keeps none of this controller's completion\n * text in the status, so the status is settled here as on every other way out of\n * `complete`: `start()` leaves a completion directly when `direction` flips to\n * `up` and `start()` runs in the same task, ahead of the direction callback.\n *\n * @stimeoRuntimeOnly `interval` is the period of the one timer this call arms; the running state\n * it writes does not depend on a Value.\n */\n #runInterval(): void {\n this.element.setAttribute(\"data-state\", \"running\");\n this.#syncStatus();\n this.#intervalId = this.#intervals.set(() => this.#tick(), this.intervalValue);\n }\n\n /** Cancels the repeating tick, if any. */\n #teardownInterval(): void {\n if (this.#intervalId !== null) {\n this.#intervals.clear(this.#intervalId);\n this.#intervalId = null;\n }\n }\n\n /** Recomputes, renders, emits `tick`, and completes when a countdown hits 0. */\n #tick(): void {\n const amount = this.#currentAmount();\n this.#render(amount);\n // `remaining` is the displayed amount (time left when counting down, elapsed\n // when counting up); `direction` lets consumers disambiguate the two.\n this.dispatch(\"tick\", {\n detail: { remaining: amount, direction: this.#isDown ? \"down\" : \"up\" },\n });\n if (this.#isDown && this.#reference - Date.now() <= 0) {\n this.#complete();\n }\n }\n\n /**\n * Stops at zero, marks completion, writes the completion label, emits `complete`,\n * and announces it.\n *\n * @stimeoRenderRoot\n */\n #complete(): void {\n this.#teardownInterval();\n this.#render(0);\n this.element.setAttribute(\"data-state\", \"complete\");\n this.#claimStatus();\n this.dispatch(\"complete\", { detail: {} });\n this.#announceCompletion();\n }\n\n /**\n * Writes the label in force into the status slot as this controller's text. An\n * empty label puts no text there: it claims a slot that is already empty — no\n * text and no element — empties one that is still this controller's, and leaves\n * any other slot, the consumer's, alone.\n */\n #claimStatus(): void {\n if (!this.hasStatusTarget) return;\n const status = this.statusTarget;\n const label = this.completeLabelValue;\n if (label === \"\" && !this.#isEmpty(status) && !this.#ownsStatus(status)) return;\n this.#writeStatus(status, label);\n }\n\n /**\n * Whether the status slot shows the text this controller wrote there and nothing\n * else: the text matches the marker, and the slot holds no element. Writing the\n * slot's text replaces every child node, so an element the consumer puts in the\n * slot makes it theirs even while the text still matches. An empty marker\n * matches the slot whenever it is empty.\n */\n #ownsStatus(status: HTMLElement): boolean {\n return (\n status.getAttribute(this.#ownedStatus) === status.textContent &&\n status.firstElementChild === null\n );\n }\n\n /** Whether the status slot holds nothing at all: no text and no element. */\n #isEmpty(status: HTMLElement): boolean {\n return status.textContent === \"\" && status.firstElementChild === null;\n }\n\n /** Puts `text` into the status slot and records it as this controller's. */\n #writeStatus(status: HTMLElement, text: string): void {\n if (status.textContent !== text) status.textContent = text;\n status.setAttribute(this.#ownedStatus, text);\n }\n\n /** Takes this controller's text out of the status slot, marker and all. */\n #releaseStatus(status: HTMLElement): void {\n status.textContent = \"\";\n status.removeAttribute(this.#ownedStatus);\n }\n\n /**\n * Reads the completion out through the shared announcer.\n *\n * @stimeoRuntimeOnly `announceText` words the one announcement a completion makes.\n */\n #announceCompletion(): void {\n // Reaching zero is the transition; the ticking numbers in between are state\n // the consumer can see, and reading each one would be unusable.\n announce(fillTemplate(this.announceTextValue, {}));\n }\n\n /** Sets the time anchor from the `deadline` value. */\n #initReference(): void {\n this.#reference = Date.parse(this.deadlineValue);\n }\n\n /** Whether a reading of `amount` leaves nothing to count: only a countdown at zero. */\n #isSettled(amount: number): boolean {\n return this.#isDown && amount <= 0;\n }\n\n /** Remaining (down) or elapsed (up) ms, never negative. */\n #currentAmount(): number {\n if (!this.#isValidDeadline) return 0;\n const now = Date.now();\n const raw = this.#isDown ? this.#reference - now : now - this.#reference;\n return Math.max(0, raw);\n }\n\n /** Writes the amount into the day/hour/minute/second slots. */\n #render(amount: number): void {\n const totalSeconds = Math.floor(amount / SECOND_MS);\n this.#renderedAmount = totalSeconds * SECOND_MS;\n const days = Math.floor(totalSeconds / 86400);\n const hours = Math.floor((totalSeconds % 86400) / 3600);\n const minutes = Math.floor((totalSeconds % 3600) / 60);\n const seconds = totalSeconds % 60;\n\n if (this.hasDaysTarget) this.daysTarget.textContent = String(days);\n if (this.hasHoursTarget) this.hoursTarget.textContent = this.#pad(hours);\n if (this.hasMinutesTarget) this.minutesTarget.textContent = this.#pad(minutes);\n if (this.hasSecondsTarget) this.secondsTarget.textContent = this.#pad(seconds);\n }\n\n /** Zero-pads a unit to two digits. */\n #pad(unit: number): string {\n return String(unit).padStart(2, \"0\");\n }\n\n get #isDown(): boolean {\n return this.directionValue !== \"up\";\n }\n\n get #isValidDeadline(): boolean {\n return !Number.isNaN(this.#reference);\n }\n\n /** Current lifecycle phase as reflected on `data-state`. */\n get #state(): string {\n return this.element.getAttribute(\"data-state\") ?? \"paused\";\n }\n}\n"]}