stimeo-ui 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/CHANGELOG.md +184 -0
  2. package/dist/controllers/announcer_controller.js.map +1 -1
  3. package/dist/controllers/aspect_ratio_controller.d.ts +3 -5
  4. package/dist/controllers/aspect_ratio_controller.js +19 -11
  5. package/dist/controllers/aspect_ratio_controller.js.map +1 -1
  6. package/dist/controllers/avatar_controller.d.ts +36 -15
  7. package/dist/controllers/avatar_controller.js +195 -40
  8. package/dist/controllers/avatar_controller.js.map +1 -1
  9. package/dist/controllers/breadcrumb_controller.js +5 -1
  10. package/dist/controllers/breadcrumb_controller.js.map +1 -1
  11. package/dist/controllers/carousel_controller.d.ts +12 -3
  12. package/dist/controllers/carousel_controller.js +90 -10
  13. package/dist/controllers/carousel_controller.js.map +1 -1
  14. package/dist/controllers/checkbox_controller.d.ts +31 -5
  15. package/dist/controllers/checkbox_controller.js +136 -25
  16. package/dist/controllers/checkbox_controller.js.map +1 -1
  17. package/dist/controllers/clipboard_controller.js +8 -3
  18. package/dist/controllers/clipboard_controller.js.map +1 -1
  19. package/dist/controllers/collapsible_controller.d.ts +1 -1
  20. package/dist/controllers/collapsible_controller.js +4 -1
  21. package/dist/controllers/collapsible_controller.js.map +1 -1
  22. package/dist/controllers/color_picker_controller.d.ts +9 -3
  23. package/dist/controllers/color_picker_controller.js +41 -11
  24. package/dist/controllers/color_picker_controller.js.map +1 -1
  25. package/dist/controllers/combobox_controller.js.map +1 -1
  26. package/dist/controllers/command_palette_controller.js.map +1 -1
  27. package/dist/controllers/context_menu_controller.d.ts +1 -1
  28. package/dist/controllers/context_menu_controller.js +2 -2
  29. package/dist/controllers/context_menu_controller.js.map +1 -1
  30. package/dist/controllers/countdown_controller.d.ts +5 -3
  31. package/dist/controllers/countdown_controller.js +5 -1
  32. package/dist/controllers/countdown_controller.js.map +1 -1
  33. package/dist/controllers/date_range_picker_controller.d.ts +23 -4
  34. package/dist/controllers/date_range_picker_controller.js +162 -31
  35. package/dist/controllers/date_range_picker_controller.js.map +1 -1
  36. package/dist/controllers/direct_upload_controller.d.ts +1 -1
  37. package/dist/controllers/direct_upload_controller.js +3 -3
  38. package/dist/controllers/direct_upload_controller.js.map +1 -1
  39. package/dist/controllers/empty_state_controller.d.ts +27 -7
  40. package/dist/controllers/empty_state_controller.js +107 -16
  41. package/dist/controllers/empty_state_controller.js.map +1 -1
  42. package/dist/controllers/file_dropzone_controller.d.ts +7 -1
  43. package/dist/controllers/file_dropzone_controller.js +26 -3
  44. package/dist/controllers/file_dropzone_controller.js.map +1 -1
  45. package/dist/controllers/flash_controller.d.ts +25 -5
  46. package/dist/controllers/flash_controller.js +161 -21
  47. package/dist/controllers/flash_controller.js.map +1 -1
  48. package/dist/controllers/focus_controller.d.ts +2 -3
  49. package/dist/controllers/focus_controller.js.map +1 -1
  50. package/dist/controllers/form_validation_controller.js +8 -2
  51. package/dist/controllers/form_validation_controller.js.map +1 -1
  52. package/dist/controllers/frame_loading_controller.d.ts +19 -2
  53. package/dist/controllers/frame_loading_controller.js +94 -22
  54. package/dist/controllers/frame_loading_controller.js.map +1 -1
  55. package/dist/controllers/highlight_controller.d.ts +8 -4
  56. package/dist/controllers/highlight_controller.js +38 -1
  57. package/dist/controllers/highlight_controller.js.map +1 -1
  58. package/dist/controllers/hover_card_controller.d.ts +2 -2
  59. package/dist/controllers/hover_card_controller.js.map +1 -1
  60. package/dist/controllers/idle_controller.d.ts +5 -4
  61. package/dist/controllers/idle_controller.js +39 -6
  62. package/dist/controllers/idle_controller.js.map +1 -1
  63. package/dist/controllers/listbox_controller.js.map +1 -1
  64. package/dist/controllers/local_time_controller.js +2 -0
  65. package/dist/controllers/local_time_controller.js.map +1 -1
  66. package/dist/controllers/masonry_controller.d.ts +1 -1
  67. package/dist/controllers/masonry_controller.js +1 -1
  68. package/dist/controllers/masonry_controller.js.map +1 -1
  69. package/dist/controllers/menubar_controller.js +5 -3
  70. package/dist/controllers/menubar_controller.js.map +1 -1
  71. package/dist/controllers/meter_controller.js +3 -1
  72. package/dist/controllers/meter_controller.js.map +1 -1
  73. package/dist/controllers/multi_select_controller.d.ts +46 -12
  74. package/dist/controllers/multi_select_controller.js +460 -151
  75. package/dist/controllers/multi_select_controller.js.map +1 -1
  76. package/dist/controllers/network_status_controller.d.ts +15 -13
  77. package/dist/controllers/network_status_controller.js +1 -3
  78. package/dist/controllers/network_status_controller.js.map +1 -1
  79. package/dist/controllers/number_input_controller.d.ts +29 -3
  80. package/dist/controllers/number_input_controller.js +455 -64
  81. package/dist/controllers/number_input_controller.js.map +1 -1
  82. package/dist/controllers/overflow_menu_controller.js +5 -1
  83. package/dist/controllers/overflow_menu_controller.js.map +1 -1
  84. package/dist/controllers/pagination_controller.js +38 -1
  85. package/dist/controllers/pagination_controller.js.map +1 -1
  86. package/dist/controllers/password_strength_controller.d.ts +4 -4
  87. package/dist/controllers/password_strength_controller.js +21 -3
  88. package/dist/controllers/password_strength_controller.js.map +1 -1
  89. package/dist/controllers/persist_controller.d.ts +4 -4
  90. package/dist/controllers/persist_controller.js +24 -5
  91. package/dist/controllers/persist_controller.js.map +1 -1
  92. package/dist/controllers/pointer_drag_controller.js +10 -0
  93. package/dist/controllers/pointer_drag_controller.js.map +1 -1
  94. package/dist/controllers/popover_controller.d.ts +2 -2
  95. package/dist/controllers/popover_controller.js.map +1 -1
  96. package/dist/controllers/portal_controller.d.ts +1 -2
  97. package/dist/controllers/portal_controller.js +10 -0
  98. package/dist/controllers/portal_controller.js.map +1 -1
  99. package/dist/controllers/progress_controller.d.ts +1 -1
  100. package/dist/controllers/progress_controller.js +7 -3
  101. package/dist/controllers/progress_controller.js.map +1 -1
  102. package/dist/controllers/radio_group_controller.d.ts +41 -15
  103. package/dist/controllers/radio_group_controller.js +540 -56
  104. package/dist/controllers/radio_group_controller.js.map +1 -1
  105. package/dist/controllers/range_slider_controller.d.ts +23 -0
  106. package/dist/controllers/range_slider_controller.js +385 -94
  107. package/dist/controllers/range_slider_controller.js.map +1 -1
  108. package/dist/controllers/rating_controller.d.ts +36 -31
  109. package/dist/controllers/rating_controller.js +274 -89
  110. package/dist/controllers/rating_controller.js.map +1 -1
  111. package/dist/controllers/relative_time_controller.js +2 -0
  112. package/dist/controllers/relative_time_controller.js.map +1 -1
  113. package/dist/controllers/resizable_controller.js +33 -0
  114. package/dist/controllers/resizable_controller.js.map +1 -1
  115. package/dist/controllers/roving_controller.d.ts +4 -0
  116. package/dist/controllers/roving_controller.js +60 -5
  117. package/dist/controllers/roving_controller.js.map +1 -1
  118. package/dist/controllers/scroll_area_controller.d.ts +7 -1
  119. package/dist/controllers/scroll_area_controller.js +155 -23
  120. package/dist/controllers/scroll_area_controller.js.map +1 -1
  121. package/dist/controllers/scroll_visibility_controller.js +33 -0
  122. package/dist/controllers/scroll_visibility_controller.js.map +1 -1
  123. package/dist/controllers/separator_controller.js +13 -17
  124. package/dist/controllers/separator_controller.js.map +1 -1
  125. package/dist/controllers/skeleton_controller.d.ts +2 -2
  126. package/dist/controllers/skeleton_controller.js +71 -3
  127. package/dist/controllers/skeleton_controller.js.map +1 -1
  128. package/dist/controllers/slider_controller.d.ts +17 -1
  129. package/dist/controllers/slider_controller.js +325 -48
  130. package/dist/controllers/slider_controller.js.map +1 -1
  131. package/dist/controllers/spinner_controller.d.ts +15 -10
  132. package/dist/controllers/spinner_controller.js +18 -3
  133. package/dist/controllers/spinner_controller.js.map +1 -1
  134. package/dist/controllers/step_indicator_controller.d.ts +1 -1
  135. package/dist/controllers/step_indicator_controller.js +3 -1
  136. package/dist/controllers/step_indicator_controller.js.map +1 -1
  137. package/dist/controllers/stepper_controller.js +2 -0
  138. package/dist/controllers/stepper_controller.js.map +1 -1
  139. package/dist/controllers/switch_controller.d.ts +12 -8
  140. package/dist/controllers/switch_controller.js +162 -18
  141. package/dist/controllers/switch_controller.js.map +1 -1
  142. package/dist/controllers/tags_input_controller.d.ts +41 -11
  143. package/dist/controllers/tags_input_controller.js +356 -120
  144. package/dist/controllers/tags_input_controller.js.map +1 -1
  145. package/dist/controllers/textarea_autosize_controller.js +1 -1
  146. package/dist/controllers/textarea_autosize_controller.js.map +1 -1
  147. package/dist/controllers/time_picker_controller.d.ts +42 -10
  148. package/dist/controllers/time_picker_controller.js +296 -104
  149. package/dist/controllers/time_picker_controller.js.map +1 -1
  150. package/dist/controllers/toggle_group_controller.d.ts +39 -13
  151. package/dist/controllers/toggle_group_controller.js +378 -55
  152. package/dist/controllers/toggle_group_controller.js.map +1 -1
  153. package/dist/controllers/toolbar_controller.js +5 -3
  154. package/dist/controllers/toolbar_controller.js.map +1 -1
  155. package/dist/controllers/tooltip_controller.d.ts +2 -2
  156. package/dist/controllers/tooltip_controller.js.map +1 -1
  157. package/dist/controllers/transition_controller.d.ts +2 -3
  158. package/dist/controllers/transition_controller.js.map +1 -1
  159. package/dist/controllers/tree_view_controller.d.ts +1 -2
  160. package/dist/controllers/tree_view_controller.js +24 -4
  161. package/dist/controllers/tree_view_controller.js.map +1 -1
  162. package/dist/index.js +3811 -1048
  163. package/dist/index.js.map +1 -1
  164. package/dist/inspector/cli.d.ts +92 -4
  165. package/dist/inspector/cli.js +174 -6
  166. package/dist/inspector/cli.js.map +1 -1
  167. package/dist/inspector/cli_bin.js +234 -8
  168. package/dist/inspector/cli_bin.js.map +1 -1
  169. package/dist/inspector/examples.json +24 -24
  170. package/dist/inspector/manifest.json +573 -59
  171. package/dist/positioning/index.d.ts +2 -2
  172. package/dist/positioning/index.js.map +1 -1
  173. package/package.json +3 -3
@@ -55,8 +55,23 @@ var SafeTimeout = class extends TimerRegistry {
55
55
  }
56
56
  };
57
57
 
58
+ // src/utils/string_list.ts
59
+ function parseStringList(raw, fallback = []) {
60
+ const text = raw.trim();
61
+ if (text.length === 0) return [...fallback];
62
+ let parsed;
63
+ try {
64
+ parsed = JSON.parse(text);
65
+ } catch {
66
+ return [...fallback];
67
+ }
68
+ if (!Array.isArray(parsed)) return [...fallback];
69
+ return parsed.filter((entry) => typeof entry === "string");
70
+ }
71
+
58
72
  // src/controllers/password_strength_controller.ts
59
73
  var CLASS_PATTERNS = [/[a-z]/, /[A-Z]/, /[0-9]/, /[^A-Za-z0-9]/];
74
+ var DEFAULT_LEVELS = ["weak", "fair", "good", "strong"];
60
75
  var LENGTH_MILESTONES = [8, 12, 16];
61
76
  var MAX_POINTS = LENGTH_MILESTONES.length + (CLASS_PATTERNS.length - 1);
62
77
  var STRENGTH_BANDS = ["weak", "fair", "good", "strong"];
@@ -64,7 +79,10 @@ var PasswordStrengthController = class _PasswordStrengthController extends Contr
64
79
  static targets = ["input", "meter", "label"];
65
80
  static values = {
66
81
  minScore: { type: Number, default: 0 },
67
- levels: { type: Array, default: ["weak", "fair", "good", "strong"] }
82
+ // A JSON list read through `parseStringList` rather than Stimulus's `Array`
83
+ // type: that reader throws out of the value observer before any callback
84
+ // runs, so one malformed attribute would stop the meter connecting.
85
+ levels: { type: String, default: "" }
68
86
  };
69
87
  static actions = ["evaluate"];
70
88
  static events = ["change"];
@@ -90,7 +108,7 @@ var PasswordStrengthController = class _PasswordStrengthController extends Contr
90
108
  */
91
109
  #update(options = {}) {
92
110
  const password = this.hasInputTarget ? this.inputTarget.value : "";
93
- const labels = this.levelsValue;
111
+ const labels = parseStringList(this.levelsValue, DEFAULT_LEVELS);
94
112
  const max = labels.length;
95
113
  const score = this.#score(password, max);
96
114
  const label = score > 0 ? labels[score - 1] ?? "" : "";
@@ -126,7 +144,7 @@ var PasswordStrengthController = class _PasswordStrengthController extends Contr
126
144
  this.#toggle("data-strength", band, band.length > 0);
127
145
  this.#toggle("data-below-min", "true", score > 0 && score < this.minScoreValue);
128
146
  const ratio = max > 0 ? score / max : 0;
129
- this.element.style.setProperty("--stimeo-password-strength", String(ratio));
147
+ this.element.style.setProperty("--stimeo--password-strength", String(ratio));
130
148
  }
131
149
  #writeLabel(label) {
132
150
  if (this.hasLabelTarget) this.labelTarget.textContent = label;
@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AG,QAAQ,CAAC,CAAA;AAAA,EAC5C;AACF","file":"password_strength_controller.js","sourcesContent":["/**\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 * 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 { SafeTimeout } from \"../utils/safe_timeout\";\n\n/** Character classes that contribute to password variety (one point each beyond the first). */\nconst CLASS_PATTERNS: readonly RegExp[] = [/[a-z]/, /[A-Z]/, /[0-9]/, /[^A-Za-z0-9]/];\n\n/** Length milestones that each add a strength point. */\nconst LENGTH_MILESTONES: readonly number[] = [8, 12, 16];\n\n/** Upper bound of the raw heuristic points, used to bucket into the level scale. */\nconst MAX_POINTS = LENGTH_MILESTONES.length + (CLASS_PATTERNS.length - 1);\n\n/**\n * Fixed, locale-independent styling bands `data-strength` is drawn from. Kept\n * separate from the (localizable) `levels` labels so `data-strength` stays a\n * stable CSS hook (e.g. `[data-strength=\"weak\"]`) even when `levels` is\n * translated. Ascending: weakest → strongest.\n */\nconst STRENGTH_BANDS = [\"weak\", \"fair\", \"good\", \"strong\"] as const;\n\n/**\n * Headless password-strength behavior: scores the field with a lightweight\n * zero-dependency heuristic and drives a meter plus an `aria-live` label. No\n * dedicated APG pattern; the meter display follows {@link MeterController}.\n *\n * Markup contract (identifier: `stimeo--password-strength`):\n * <div data-controller=\"stimeo--password-strength\">\n * <input type=\"password\" data-stimeo--password-strength-target=\"input\"\n * data-action=\"input->stimeo--password-strength#evaluate\" aria-describedby=\"pw\">\n * <div data-stimeo--password-strength-target=\"meter\" role=\"meter\"\n * aria-valuemin=\"0\" aria-valuemax=\"4\"></div>\n * <span id=\"pw\" data-stimeo--password-strength-target=\"label\" aria-live=\"polite\"></span>\n * </div>\n *\n * On each input the controller scores the password (length milestones + character\n * variety, capped for trivial repetition), syncs the meter's `aria-valuenow`,\n * reflects a stable band on `data-strength`, the `0–1` fill on\n * `--stimeo-password-strength`, and (when `minScore` is set) `data-below-min`,\n * and writes the level label into the label target.\n *\n * @remarks\n * Behavior only — the meter/bar look is the consumer's, keyed off the data hooks.\n * `data-strength` is one of the fixed {@link STRENGTH_BANDS} (not the localizable\n * `levels` text), so consumers can style by it regardless of locale; the visible\n * label receives the matching `levels` entry. Non-text state (meter ARIA,\n * `data-strength`/`data-below-min`, the custom property, and the `change` event)\n * updates **immediately** on every keystroke so styling and consumers stay\n * responsive, while the label — in an `aria-live=\"polite\"` region — is written on\n * a short debounce so a screen reader is not flooded mid-typing. The score is a\n * pure function of the input value (no module-scope state), so `connect()`\n * re-evaluates idempotently after a Turbo cache restore; the debounce timer is\n * owned by {@link SafeTimeout} and torn down on `disconnect()` (Turbo included).\n * The estimator is intentionally not a dictionary/zxcvbn-grade one (kept\n * zero-dep); swap a stronger one in on the consumer side if needed.\n */\nexport class PasswordStrengthController extends Controller<HTMLElement> {\n static override targets = [\"input\", \"meter\", \"label\"];\n static override values = {\n minScore: { type: Number, default: 0 },\n levels: { type: Array, default: [\"weak\", \"fair\", \"good\", \"strong\"] },\n };\n static actions = [\"evaluate\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly inputTarget: HTMLInputElement;\n declare readonly meterTarget: HTMLElement;\n declare readonly labelTarget: HTMLElement;\n declare readonly hasInputTarget: boolean;\n declare readonly hasMeterTarget: boolean;\n declare readonly hasLabelTarget: boolean;\n\n declare minScoreValue: number;\n declare levelsValue: string[];\n\n /** Delay (ms) before the polite live-region label is written, to throttle SR flooding. */\n static readonly #announceDelay = 200;\n\n readonly #timers = new SafeTimeout();\n #announceId: number | null = null;\n\n override connect(): void {\n // Reflect the current value synchronously (no announce): an autofilled or\n // cache-restored field shows the right strength without queuing an SR message.\n this.#update({ announce: false });\n }\n\n override disconnect(): void {\n this.#timers.clearAll();\n this.#announceId = null;\n }\n\n /** Re-evaluates strength from the input. Bound via `data-action` (`input`). */\n evaluate(): void {\n this.#update();\n }\n\n /**\n * Recomputes the strength. The meter ARIA, data hooks, the custom property and\n * the `change` event apply immediately; the live-region label text is debounced\n * unless `announce` is `false` (the initial render).\n */\n #update(options: { announce?: boolean } = {}): void {\n const password = this.hasInputTarget ? this.inputTarget.value : \"\";\n const labels = this.levelsValue;\n const max = labels.length;\n const score = this.#score(password, max);\n const label = score > 0 ? (labels[score - 1] ?? \"\") : \"\";\n\n this.#reflectMeter(score, max);\n this.#reflectRoot(score, max);\n\n if (options.announce === false) {\n // Initial render (connect / cache-restore): reflect without a change event\n // or a queued screen-reader announcement.\n this.#writeLabel(label);\n return;\n }\n\n this.dispatch(\"change\", {\n detail: { score, level: label, max, meetsMin: score > 0 && score >= this.minScoreValue },\n });\n\n if (this.#announceId !== null) this.#timers.clear(this.#announceId);\n this.#announceId = this.#timers.set(() => {\n this.#writeLabel(label);\n this.#announceId = null;\n }, PasswordStrengthController.#announceDelay);\n }\n\n /** Syncs the meter target's ARIA value attributes (`0..levels.length`). */\n #reflectMeter(score: number, max: number): void {\n if (!this.hasMeterTarget) return;\n this.meterTarget.setAttribute(\"aria-valuemin\", \"0\");\n this.meterTarget.setAttribute(\"aria-valuemax\", String(max));\n this.meterTarget.setAttribute(\"aria-valuenow\", String(score));\n }\n\n /**\n * Reflects the level onto the root: the stable `data-strength` band (absent when\n * empty), the `data-below-min` hook when the score is under `minScore`, and the\n * `0–1` fill the consumer's CSS turns into the bar width.\n */\n #reflectRoot(score: number, max: number): void {\n const band = this.#band(score, max);\n this.#toggle(\"data-strength\", band, band.length > 0);\n // Empty/pristine input (`score === 0`) is never \"below min\": that would let CSS\n // flag an untouched field as failing. Mirror the `change` event's `meetsMin`\n // (`score > 0 && …`) so the hook only marks a *non-empty* password under the\n // threshold. `minScore` defaults to 0, leaving the hook inert until set positive.\n this.#toggle(\"data-below-min\", \"true\", score > 0 && score < this.minScoreValue);\n const ratio = max > 0 ? score / max : 0;\n this.element.style.setProperty(\"--stimeo-password-strength\", String(ratio));\n }\n\n #writeLabel(label: string): void {\n if (this.hasLabelTarget) this.labelTarget.textContent = label;\n }\n\n /**\n * Locale-independent styling band (one of {@link STRENGTH_BANDS}) for `score`\n * out of `max`. Empty input → `\"\"`. Quantizes the `score/max` ratio into the\n * four fixed bands, so a non-default level count still maps onto a stable hook.\n */\n #band(score: number, max: number): string {\n if (score <= 0 || max <= 0) return \"\";\n const index = Math.ceil((score / max) * STRENGTH_BANDS.length) - 1;\n return STRENGTH_BANDS[Math.min(STRENGTH_BANDS.length - 1, Math.max(0, index))] ?? \"\";\n }\n\n /** Sets `name` to `value` when `on`, else removes it (value/presence data hook). */\n #toggle(name: string, value: string, on: boolean): void {\n if (on) {\n this.element.setAttribute(name, value);\n } else {\n this.element.removeAttribute(name);\n }\n }\n\n /**\n * Lightweight zero-dependency strength heuristic returning an integer in\n * `[0, max]` (`max` = number of levels). Empty input is `0` (no level); any\n * non-empty password is at least `1`. Points accrue from length milestones and\n * character-class variety, then bucket into the level scale. A tiny alphabet\n * (≤ 2 distinct characters, e.g. \"aaaa\") is capped as the weakest, so length\n * alone cannot mask trivial repetition.\n */\n #score(password: string, max: number): number {\n if (password.length === 0 || max === 0) return 0;\n\n let points = 0;\n for (const milestone of LENGTH_MILESTONES) {\n if (password.length >= milestone) points += 1;\n }\n // The first present character class is free; each additional one adds a point.\n points += CLASS_PATTERNS.filter((re) => re.test(password)).length - 1;\n\n if (new Set(password).size <= 2) points = 0; // trivial repetition → weakest\n\n const bucketed = Math.round((points / MAX_POINTS) * max);\n return Math.min(max, Math.max(1, bucketed));\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/safe_timeout.ts","../../src/utils/string_list.ts","../../src/controllers/password_strength_controller.ts"],"names":[],"mappings":";;;;;AAwBA,IAAe,gBAAf,MAA6B;AAAA;AAAA,EAER,GAAA,uBAAU,GAAA,EAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAczC,MAAM,EAAA,EAAkB;AACtB,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,MAAA,CAAO,EAAE,CAAA,EAAG;AACvB,MAAA,IAAA,CAAK,OAAO,EAAE,CAAA;AAAA,IAChB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QAAA,GAAiB;AACf,IAAA,KAAA,MAAW,EAAA,IAAM,KAAK,GAAA,EAAK;AACzB,MAAA,IAAA,CAAK,OAAO,EAAE,CAAA;AAAA,IAChB;AACA,IAAA,IAAA,CAAK,IAAI,KAAA,EAAM;AAAA,EACjB;AAAA;AAAA,EAGA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,KAAK,GAAA,CAAI,IAAA;AAAA,EAClB;AACF,CAAA;AAmBO,IAAM,WAAA,GAAN,cAA0B,aAAA,CAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO7C,GAAA,CAAI,UAAsB,KAAA,EAAuB;AAC/C,IAAA,MAAM,EAAA,GAAK,IAAA,C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AA,IAAK,EAAA;AAAA,EACpF;AAAA;AAAA,EAGA,OAAA,CAAQ,IAAA,EAAc,KAAA,EAAe,EAAA,EAAmB;AACtD,IAAA,IAAI,EAAA,EAAI;AACN,MAAA,IAAA,CAAK,OAAA,CAAQ,YAAA,CAAa,IAAA,EAAM,KAAK,CAAA;AAAA,IACvC,CAAA,MAAO;AACL,MAAA,IAAA,CAAK,OAAA,CAAQ,gBAAgB,IAAI,CAAA;AAAA,IACnC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAA,CAAO,UAAkB,GAAA,EAAqB;AAC5C,IAAA,IAAI,QAAA,CAAS,MAAA,KAAW,CAAA,IAAK,GAAA,KAAQ,GAAG,OAAO,CAAA;AAE/C,IAAA,IAAI,MAAA,GAAS,CAAA;AACb,IAAA,KAAA,MAAW,aAAa,iBAAA,EAAmB;AACzC,MAAA,IAAI,QAAA,CAAS,MAAA,IAAU,SAAA,EAAW,MAAA,IAAU,CAAA;AAAA,IAC9C;AAEA,IAAA,MAAA,IAAU,cAAA,CAAe,OAAO,CAAC,EAAA,KAAO,GAAG,IAAA,CAAK,QAAQ,CAAC,CAAA,CAAE,MAAA,GAAS,CAAA;AAEpE,IAAA,IAAI,IAAI,GAAA,CAAI,QAAQ,CAAA,CAAE,IAAA,IAAQ,GAAG,MAAA,GAAS,CAAA;AAE1C,IAAA,MAAM,QAAA,GAAW,IAAA,CAAK,KAAA,CAAO,MAAA,GAAS,aAAc,GAAG,CAAA;AACvD,IAAA,OAAO,KAAK,GAAA,CAAI,GAAA,EAAK,KAAK,GAAA,CAAI,CAAA,EAAG,QAAQ,CAAC,CAAA;AAAA,EAC5C;AACF","file":"password_strength_controller.js","sourcesContent":["/**\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 * 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","/**\n * JSON string-list parsing for the controllers that take a list as a Value.\n *\n * Stimulus offers an `Array` Value type, but its reader runs `JSON.parse` inside\n * the value observer — **before** the `<name>ValueChanged` callback — and\n * rethrows on malformed text. The throw propagates out of the observer that runs\n * during connection, so a single unparseable attribute stops the controller from\n * connecting at all: no lifecycle callback runs and the element is left inert\n * rather than degraded. A consumer cannot guard against it either, because the\n * callback that would hold the `try` never runs.\n *\n * Declaring the attribute as a `String` Value and parsing it here keeps a\n * malformed declaration local to the value it declares. The attribute text is\n * identical either way (`'[\"a\", \"b\"]'`), so markup does not change with the\n * declaration.\n */\n\n/**\n * Parses `raw` as a JSON array of strings.\n *\n * Returns `fallback` when the text is absent, unparseable, or not an array, so a\n * malformed declaration behaves like an omitted one. A parsed array keeps only\n * its string entries: every caller indexes or compares strings, and a stray\n * number would otherwise sit in the list without ever matching.\n *\n * An explicit `\"[]\"` is honoured as an empty list rather than falling back — it\n * is the only way to declare \"none\" against a non-empty default.\n *\n * @param raw - the attribute text, e.g. `'[\"password\"]'`.\n * @param fallback - the list to use when `raw` declares nothing usable.\n */\nexport function parseStringList(raw: string, fallback: readonly string[] = []): string[] {\n // The common case is an undeclared attribute, and `JSON.parse(\"\")` answers it\n // by throwing. Reaching the same fallback without building an exception keeps\n // the callers that ask per element off that path.\n const text = raw.trim();\n if (text.length === 0) return [...fallback];\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(text);\n } catch {\n return [...fallback];\n }\n\n if (!Array.isArray(parsed)) return [...fallback];\n return parsed.filter((entry): entry is string => typeof entry === \"string\");\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\nimport { parseStringList } from \"../utils/string_list\";\n\n/** Character classes that contribute to password variety (one point each beyond the first). */\nconst CLASS_PATTERNS: readonly RegExp[] = [/[a-z]/, /[A-Z]/, /[0-9]/, /[^A-Za-z0-9]/];\n\n/** Strength labels used unless the consumer declares its own scale. */\nconst DEFAULT_LEVELS = [\"weak\", \"fair\", \"good\", \"strong\"];\n\n/** Length milestones that each add a strength point. */\nconst LENGTH_MILESTONES: readonly number[] = [8, 12, 16];\n\n/** Upper bound of the raw heuristic points, used to bucket into the level scale. */\nconst MAX_POINTS = LENGTH_MILESTONES.length + (CLASS_PATTERNS.length - 1);\n\n/**\n * Fixed, locale-independent styling bands `data-strength` is drawn from. Kept\n * separate from the (localizable) `levels` labels so `data-strength` stays a\n * stable CSS hook (e.g. `[data-strength=\"weak\"]`) even when `levels` is\n * translated. Ascending: weakest → strongest.\n */\nconst STRENGTH_BANDS = [\"weak\", \"fair\", \"good\", \"strong\"] as const;\n\n/**\n * Headless password-strength behavior: scores the field with a lightweight\n * zero-dependency heuristic and drives a meter plus an `aria-live` label. No\n * dedicated APG pattern; the meter display follows {@link MeterController}.\n *\n * Markup contract (identifier: `stimeo--password-strength`):\n * <div data-controller=\"stimeo--password-strength\">\n * <input type=\"password\" data-stimeo--password-strength-target=\"input\"\n * data-action=\"input->stimeo--password-strength#evaluate\" aria-describedby=\"pw\">\n * <div data-stimeo--password-strength-target=\"meter\" role=\"meter\"\n * aria-valuemin=\"0\" aria-valuemax=\"4\"></div>\n * <span id=\"pw\" data-stimeo--password-strength-target=\"label\" aria-live=\"polite\"></span>\n * </div>\n *\n * On each input the controller scores the password (length milestones + character\n * variety, capped for trivial repetition), syncs the meter's `aria-valuenow`,\n * reflects a stable band on `data-strength`, the `0–1` fill on\n * `--stimeo--password-strength`, and (when `minScore` is set) `data-below-min`,\n * and writes the level label into the label target.\n *\n * @remarks\n * Behavior only — the meter/bar look is the consumer's, keyed off the data hooks.\n * `data-strength` is one of the fixed {@link STRENGTH_BANDS} (not the localizable\n * `levels` text), so consumers can style by it regardless of locale; the visible\n * label receives the matching `levels` entry. Non-text state (meter ARIA,\n * `data-strength`/`data-below-min`, the custom property, and the `change` event)\n * updates **immediately** on every keystroke so styling and consumers stay\n * responsive, while the label — in an `aria-live=\"polite\"` region — is written on\n * a short debounce so a screen reader is not flooded mid-typing. The score is a\n * pure function of the input value (no module-scope state), so `connect()`\n * re-evaluates idempotently after a Turbo cache restore; the debounce timer is\n * owned by {@link SafeTimeout} and torn down on `disconnect()` (Turbo included).\n * The estimator is intentionally not a dictionary/zxcvbn-grade one (kept\n * zero-dep); swap a stronger one in on the consumer side if needed.\n */\nexport class PasswordStrengthController extends Controller<HTMLElement> {\n static override targets = [\"input\", \"meter\", \"label\"];\n static override values = {\n minScore: { type: Number, default: 0 },\n // A JSON list read through `parseStringList` rather than Stimulus's `Array`\n // type: that reader throws out of the value observer before any callback\n // runs, so one malformed attribute would stop the meter connecting.\n levels: { type: String, default: \"\" },\n };\n static actions = [\"evaluate\"] as const;\n static events = [\"change\"] as const;\n\n declare readonly inputTarget: HTMLInputElement;\n declare readonly meterTarget: HTMLElement;\n declare readonly labelTarget: HTMLElement;\n declare readonly hasInputTarget: boolean;\n declare readonly hasMeterTarget: boolean;\n declare readonly hasLabelTarget: boolean;\n\n declare minScoreValue: number;\n declare levelsValue: string;\n\n /** Delay (ms) before the polite live-region label is written, to throttle SR flooding. */\n static readonly #announceDelay = 200;\n\n readonly #timers = new SafeTimeout();\n #announceId: number | null = null;\n\n override connect(): void {\n // Reflect the current value synchronously (no announce): an autofilled or\n // cache-restored field shows the right strength without queuing an SR message.\n this.#update({ announce: false });\n }\n\n override disconnect(): void {\n this.#timers.clearAll();\n this.#announceId = null;\n }\n\n /** Re-evaluates strength from the input. Bound via `data-action` (`input`). */\n evaluate(): void {\n this.#update();\n }\n\n /**\n * Recomputes the strength. The meter ARIA, data hooks, the custom property and\n * the `change` event apply immediately; the live-region label text is debounced\n * unless `announce` is `false` (the initial render).\n */\n #update(options: { announce?: boolean } = {}): void {\n const password = this.hasInputTarget ? this.inputTarget.value : \"\";\n const labels = parseStringList(this.levelsValue, DEFAULT_LEVELS);\n const max = labels.length;\n const score = this.#score(password, max);\n const label = score > 0 ? (labels[score - 1] ?? \"\") : \"\";\n\n this.#reflectMeter(score, max);\n this.#reflectRoot(score, max);\n\n if (options.announce === false) {\n // Initial render (connect / cache-restore): reflect without a change event\n // or a queued screen-reader announcement.\n this.#writeLabel(label);\n return;\n }\n\n this.dispatch(\"change\", {\n detail: { score, level: label, max, meetsMin: score > 0 && score >= this.minScoreValue },\n });\n\n if (this.#announceId !== null) this.#timers.clear(this.#announceId);\n this.#announceId = this.#timers.set(() => {\n this.#writeLabel(label);\n this.#announceId = null;\n }, PasswordStrengthController.#announceDelay);\n }\n\n /** Syncs the meter target's ARIA value attributes (`0..levels.length`). */\n #reflectMeter(score: number, max: number): void {\n if (!this.hasMeterTarget) return;\n this.meterTarget.setAttribute(\"aria-valuemin\", \"0\");\n this.meterTarget.setAttribute(\"aria-valuemax\", String(max));\n this.meterTarget.setAttribute(\"aria-valuenow\", String(score));\n }\n\n /**\n * Reflects the level onto the root: the stable `data-strength` band (absent when\n * empty), the `data-below-min` hook when the score is under `minScore`, and the\n * `0–1` fill the consumer's CSS turns into the bar width.\n */\n #reflectRoot(score: number, max: number): void {\n const band = this.#band(score, max);\n this.#toggle(\"data-strength\", band, band.length > 0);\n // Empty/pristine input (`score === 0`) is never \"below min\": that would let CSS\n // flag an untouched field as failing. Mirror the `change` event's `meetsMin`\n // (`score > 0 && …`) so the hook only marks a *non-empty* password under the\n // threshold. `minScore` defaults to 0, leaving the hook inert until set positive.\n this.#toggle(\"data-below-min\", \"true\", score > 0 && score < this.minScoreValue);\n const ratio = max > 0 ? score / max : 0;\n this.element.style.setProperty(\"--stimeo--password-strength\", String(ratio));\n }\n\n #writeLabel(label: string): void {\n if (this.hasLabelTarget) this.labelTarget.textContent = label;\n }\n\n /**\n * Locale-independent styling band (one of {@link STRENGTH_BANDS}) for `score`\n * out of `max`. Empty input → `\"\"`. Quantizes the `score/max` ratio into the\n * four fixed bands, so a non-default level count still maps onto a stable hook.\n */\n #band(score: number, max: number): string {\n if (score <= 0 || max <= 0) return \"\";\n const index = Math.ceil((score / max) * STRENGTH_BANDS.length) - 1;\n return STRENGTH_BANDS[Math.min(STRENGTH_BANDS.length - 1, Math.max(0, index))] ?? \"\";\n }\n\n /** Sets `name` to `value` when `on`, else removes it (value/presence data hook). */\n #toggle(name: string, value: string, on: boolean): void {\n if (on) {\n this.element.setAttribute(name, value);\n } else {\n this.element.removeAttribute(name);\n }\n }\n\n /**\n * Lightweight zero-dependency strength heuristic returning an integer in\n * `[0, max]` (`max` = number of levels). Empty input is `0` (no level); any\n * non-empty password is at least `1`. Points accrue from length milestones and\n * character-class variety, then bucket into the level scale. A tiny alphabet\n * (≤ 2 distinct characters, e.g. \"aaaa\") is capped as the weakest, so length\n * alone cannot mask trivial repetition.\n */\n #score(password: string, max: number): number {\n if (password.length === 0 || max === 0) return 0;\n\n let points = 0;\n for (const milestone of LENGTH_MILESTONES) {\n if (password.length >= milestone) points += 1;\n }\n // The first present character class is free; each additional one adds a point.\n points += CLASS_PATTERNS.filter((re) => re.test(password)).length - 1;\n\n if (new Set(password).size <= 2) points = 0; // trivial repetition → weakest\n\n const bucketed = Math.round((points / MAX_POINTS) * max);\n return Math.min(max, Math.max(1, bucketed));\n }\n}\n"]}
@@ -5,7 +5,7 @@ type PersistField = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
5
5
  /**
6
6
  * Headless draft-autosave behavior: persists a form's field values to
7
7
  * `localStorage` and restores them across Turbo navigations and reloads (no APG
8
- * pattern; a state-holding utility). The Alpine `persist` equivalent.
8
+ * pattern; a state-holding utility).
9
9
  *
10
10
  * Markup contract (identifier: `stimeo--persist`):
11
11
  * <form data-controller="stimeo--persist"
@@ -38,8 +38,8 @@ declare class PersistController extends Controller<HTMLElement> {
38
38
  default: number;
39
39
  };
40
40
  exclude: {
41
- type: ArrayConstructor;
42
- default: string[];
41
+ type: StringConstructor;
42
+ default: string;
43
43
  };
44
44
  clearOn: {
45
45
  type: StringConstructor;
@@ -52,7 +52,7 @@ declare class PersistController extends Controller<HTMLElement> {
52
52
  readonly hasFieldTarget: boolean;
53
53
  keyValue: string;
54
54
  debounceValue: number;
55
- excludeValue: string[];
55
+ excludeValue: string;
56
56
  clearOnValue: string;
57
57
  connect(): void;
58
58
  disconnect(): void;
@@ -55,8 +55,23 @@ var SafeTimeout = class extends TimerRegistry {
55
55
  }
56
56
  };
57
57
 
58
+ // src/utils/string_list.ts
59
+ function parseStringList(raw, fallback = []) {
60
+ const text = raw.trim();
61
+ if (text.length === 0) return [...fallback];
62
+ let parsed;
63
+ try {
64
+ parsed = JSON.parse(text);
65
+ } catch {
66
+ return [...fallback];
67
+ }
68
+ if (!Array.isArray(parsed)) return [...fallback];
69
+ return parsed.filter((entry) => typeof entry === "string");
70
+ }
71
+
58
72
  // src/controllers/persist_controller.ts
59
73
  var NON_VALUE_TYPES = /* @__PURE__ */ new Set(["file", "submit", "reset", "button", "image"]);
74
+ var DEFAULT_EXCLUDE = ["password"];
60
75
  var STORAGE_PREFIX = "stimeo--persist:";
61
76
  var OCCURRENCE_SEP = "\0";
62
77
  var PersistController = class extends Controller {
@@ -64,7 +79,10 @@ var PersistController = class extends Controller {
64
79
  static values = {
65
80
  key: { type: String, default: "" },
66
81
  debounce: { type: Number, default: 400 },
67
- exclude: { type: Array, default: ["password"] },
82
+ // A JSON list read through `parseStringList` rather than Stimulus's `Array`
83
+ // type: that reader throws out of the value observer before any callback
84
+ // runs, so one malformed attribute would stop the controller connecting.
85
+ exclude: { type: String, default: "" },
68
86
  clearOn: { type: String, default: "" }
69
87
  };
70
88
  static actions = ["clear"];
@@ -208,15 +226,16 @@ var PersistController = class extends Controller {
208
226
  /** The fields to persist: `field` targets, or the element's named controls. */
209
227
  #fields() {
210
228
  const candidates = this.hasFieldTarget ? this.fieldTargets : Array.from(this.element.querySelectorAll("input, textarea, select"));
211
- return candidates.filter((field) => this.#persistable(field));
229
+ const excluded = parseStringList(this.excludeValue, DEFAULT_EXCLUDE);
230
+ return candidates.filter((field) => this.#persistable(field, excluded));
212
231
  }
213
232
  /** Whether a field carries a restorable, non-excluded value. */
214
- #persistable(field) {
233
+ #persistable(field, excluded) {
215
234
  if (this.#keyOf(field) === null) return false;
216
235
  const type = field instanceof HTMLInputElement ? field.type : "";
217
236
  if (NON_VALUE_TYPES.has(type)) return false;
218
- if (this.excludeValue.includes(type)) return false;
219
- if (field.name.length > 0 && this.excludeValue.includes(field.name)) return false;
237
+ if (excluded.includes(type)) return false;
238
+ if (field.name.length > 0 && excluded.includes(field.name)) return false;
220
239
  return true;
221
240
  }
222
241
  /** A stable storage sub-key for a field (its name, else id). */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/safe_timeout.ts","../../src/controllers/persist_controller.ts"],"names":[],"mappings":";;;;;AAwBA,IAAe,gBAAf,MAA6B;AAAA;AAAA,EAER,GAAA,uBAAU,GAAA,EAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAczC,MAAM,EAAA,EAAkB;AACtB,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,MAAA,CA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AA,OAAO,KAAA,CAAM,IAAA,IAAQ,KAAA,CAAM,EAAA,IAAM,IAAA;AAAA,EACnC;AAAA;AAAA,EAGA,IAAI,WAAA,GAA6B;AAC/B,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,QAAA,IAAY,IAAA,CAAK,OAAA,CAAQ,EAAA;AAC1C,IAAA,OAAO,GAAA,CAAI,MAAA,GAAS,CAAA,GAAI,GAAA,GAAM,IAAA;AAAA,EAChC;AAAA;AAAA,EAGA,IAAI,WAAA,GAA6B;AAC/B,IAAA,MAAM,UAAU,IAAA,CAAK,WAAA;AACrB,IAAA,OAAO,YAAY,IAAA,GAAO,IAAA,GAAO,CAAA,EAAG,cAAc,GAAG,OAAO,CAAA,CAAA;AAAA,EAC9D;AAAA,EAEA,SAAS,GAAA,EAA4B;AACnC,IAAA,IAAI;AACF,MAAA,OAAO,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,GAAG,CAAA;AAAA,IACxC,CAAA,CAAA,MAAQ;AACN,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AAAA,EAEA,QAAA,CAAS,KAAa,KAAA,EAAqB;AACzC,IAAA,IAAI;AACF,MAAA,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,GAAA,EAAK,KAAK,CAAA;AAAA,IACxC,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF;AAAA,EAEA,YAAY,GAAA,EAAmB;AAC7B,IAAA,IAAI;AACF,MAAA,MAAA,CAAO,YAAA,CAAa,WAAW,GAAG,CAAA;AAAA,IACpC,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF;AACF","file":"persist_controller.js","sourcesContent":["/**\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 * 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 { SafeTimeout } from \"../utils/safe_timeout\";\n\n/** Field controls this controller can persist. */\ntype PersistField = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;\n\n/** Input types that carry no meaningful, restorable value. */\nconst NON_VALUE_TYPES = new Set([\"file\", \"submit\", \"reset\", \"button\", \"image\"]);\n/** localStorage key prefix so drafts never clobber unrelated app storage. */\nconst STORAGE_PREFIX = \"stimeo--persist:\";\n/** Separator for disambiguating repeated same-name fields (cannot occur in a real field name). */\nconst OCCURRENCE_SEP = \"\\u0000\";\n\n/**\n * Headless draft-autosave behavior: persists a form's field values to\n * `localStorage` and restores them across Turbo navigations and reloads (no APG\n * pattern; a state-holding utility). The Alpine `persist` equivalent.\n *\n * Markup contract (identifier: `stimeo--persist`):\n * <form data-controller=\"stimeo--persist\"\n * data-stimeo--persist-key-value=\"contact-draft\">\n * <input name=\"name\">\n * <textarea name=\"message\"></textarea>\n * </form>\n *\n * On connect it restores any saved values under `key` (falling back to the\n * element's `id`), then debounce-saves on every input/change. Password fields (and\n * anything in `exclude`) are never written. A `clear()` action — or the `clearOn`\n * event (e.g. `submit`) — drops the draft. Restoring never moves focus.\n *\n * @remarks\n * Behavior only. State lives entirely in `localStorage` (no module-scope state), so\n * instances never interfere. The input listener and debounce timer are removed on\n * `disconnect()` (Turbo navigation included), where a pending save is flushed first\n * so an in-flight edit is not lost.\n */\nexport class PersistController extends Controller<HTMLElement> {\n static override targets = [\"field\"];\n static override values = {\n key: { type: String, default: \"\" },\n debounce: { type: Number, default: 400 },\n exclude: { type: Array, default: [\"password\"] },\n clearOn: { type: String, default: \"\" },\n };\n static actions = [\"clear\"] as const;\n static events = [\"restore\", \"save\", \"clear\"] as const;\n\n declare readonly fieldTargets: PersistField[];\n declare readonly hasFieldTarget: boolean;\n\n declare keyValue: string;\n declare debounceValue: number;\n declare excludeValue: string[];\n declare clearOnValue: string;\n\n readonly #timeouts = new SafeTimeout();\n #saveId: number | null = null;\n\n readonly #onInput = (): void => {\n this.#scheduleSave();\n };\n\n readonly #onClearEvent = (): void => {\n this.clear();\n };\n\n override connect(): void {\n if (this.#storageKey === null) return;\n this.#restore();\n this.element.addEventListener(\"input\", this.#onInput);\n this.element.addEventListener(\"change\", this.#onInput);\n if (this.clearOnValue.length > 0) {\n this.element.addEventListener(this.clearOnValue, this.#onClearEvent);\n }\n }\n\n override disconnect(): void {\n this.element.removeEventListener(\"input\", this.#onInput);\n this.element.removeEventListener(\"change\", this.#onInput);\n if (this.clearOnValue.length > 0) {\n this.element.removeEventListener(this.clearOnValue, this.#onClearEvent);\n }\n // Flush a pending save so an in-flight edit survives a Turbo navigation.\n if (this.#saveId !== null) {\n this.#timeouts.clear(this.#saveId);\n this.#saveId = null;\n this.#write();\n }\n this.#timeouts.clearAll();\n }\n\n /** Drops the saved draft and clears the restored marker. */\n clear(): void {\n const key = this.#storageKey;\n if (key === null) return;\n if (this.#saveId !== null) {\n this.#timeouts.clear(this.#saveId);\n this.#saveId = null;\n }\n this.#removeItem(key);\n this.element.removeAttribute(\"data-persist-restored\");\n this.dispatch(\"clear\", { detail: { key: this.#logicalKey } });\n }\n\n /** Schedules a debounced save. */\n #scheduleSave(): void {\n if (this.#saveId !== null) this.#timeouts.clear(this.#saveId);\n this.#saveId = this.#timeouts.set(() => {\n this.#saveId = null;\n this.#save();\n }, this.debounceValue);\n }\n\n /** Writes the current values and emits `save`. */\n #save(): void {\n this.#write();\n this.dispatch(\"save\", { detail: { key: this.#logicalKey } });\n }\n\n /** Serializes persistable fields and stores them under the storage key. */\n #write(): void {\n const key = this.#storageKey;\n if (key === null) return;\n const data: Record<string, unknown> = {};\n for (const { field, key: fieldKey } of this.#fieldEntries()) {\n if (field instanceof HTMLInputElement && field.type === \"checkbox\") {\n data[fieldKey] = field.checked;\n } else if (field instanceof HTMLInputElement && field.type === \"radio\") {\n if (field.checked) data[fieldKey] = field.value;\n } else if (field instanceof HTMLSelectElement && field.multiple) {\n data[fieldKey] = Array.from(field.selectedOptions).map((o) => o.value);\n } else {\n data[fieldKey] = field.value;\n }\n }\n this.#setItem(key, JSON.stringify(data));\n }\n\n /** Applies any saved values to the fields, without moving focus. */\n #restore(): void {\n const key = this.#storageKey;\n if (key === null) return;\n const raw = this.#getItem(key);\n if (raw === null) return;\n let data: Record<string, unknown>;\n try {\n data = JSON.parse(raw) as Record<string, unknown>;\n } catch {\n return;\n }\n let restoredAny = false;\n for (const { field, key: fieldKey } of this.#fieldEntries()) {\n if (!Object.hasOwn(data, fieldKey)) continue;\n this.#applyValue(field, data[fieldKey]);\n restoredAny = true;\n }\n if (restoredAny) {\n this.element.setAttribute(\"data-persist-restored\", \"true\");\n this.dispatch(\"restore\", { detail: { key: this.#logicalKey } });\n }\n }\n\n /** Sets a single field's value from a stored entry. */\n #applyValue(field: PersistField, value: unknown): void {\n if (field instanceof HTMLInputElement && field.type === \"checkbox\") {\n field.checked = Boolean(value);\n } else if (field instanceof HTMLInputElement && field.type === \"radio\") {\n field.checked = field.value === value;\n } else if (field instanceof HTMLSelectElement && field.multiple) {\n const selected = new Set(Array.isArray(value) ? value.map(String) : []);\n for (const option of Array.from(field.options)) {\n option.selected = selected.has(option.value);\n }\n } else {\n field.value = String(value);\n }\n }\n\n /**\n * Persistable fields paired with a stable storage key. Uniquely-named fields key\n * by their name. Repeated same-name fields (e.g. a `tags[]` checkbox group or\n * array text inputs) are disambiguated by DOM-order occurrence — the first keeps\n * its plain `name`, later ones get a NUL-separated index suffix — so each is\n * stored and restored individually instead of the last one clobbering the rest.\n * Radios are the exception: a group intentionally shares one key (one value per\n * name).\n */\n #fieldEntries(): Array<{ field: PersistField; key: string }> {\n const entries: Array<{ field: PersistField; key: string }> = [];\n const occurrence = new Map<string, number>();\n for (const field of this.#fields()) {\n const name = this.#keyOf(field);\n if (name === null) continue;\n if (field instanceof HTMLInputElement && field.type === \"radio\") {\n entries.push({ field, key: name });\n continue;\n }\n const seen = occurrence.get(name) ?? 0;\n occurrence.set(name, seen + 1);\n entries.push({ field, key: seen === 0 ? name : `${name}${OCCURRENCE_SEP}${seen}` });\n }\n return entries;\n }\n\n /** The fields to persist: `field` targets, or the element's named controls. */\n #fields(): PersistField[] {\n const candidates = this.hasFieldTarget\n ? this.fieldTargets\n : Array.from(this.element.querySelectorAll<PersistField>(\"input, textarea, select\"));\n return candidates.filter((field) => this.#persistable(field));\n }\n\n /** Whether a field carries a restorable, non-excluded value. */\n #persistable(field: PersistField): boolean {\n if (this.#keyOf(field) === null) return false;\n const type = field instanceof HTMLInputElement ? field.type : \"\";\n if (NON_VALUE_TYPES.has(type)) return false;\n if (this.excludeValue.includes(type)) return false;\n if (field.name.length > 0 && this.excludeValue.includes(field.name)) return false;\n return true;\n }\n\n /** A stable storage sub-key for a field (its name, else id). */\n #keyOf(field: PersistField): string | null {\n return field.name || field.id || null;\n }\n\n /** The logical key (key Value or element id), or null when neither is set. */\n get #logicalKey(): string | null {\n const key = this.keyValue || this.element.id;\n return key.length > 0 ? key : null;\n }\n\n /** The prefixed localStorage key, or null when persistence is disabled. */\n get #storageKey(): string | null {\n const logical = this.#logicalKey;\n return logical === null ? null : `${STORAGE_PREFIX}${logical}`;\n }\n\n #getItem(key: string): string | null {\n try {\n return window.localStorage.getItem(key);\n } catch {\n return null;\n }\n }\n\n #setItem(key: string, value: string): void {\n try {\n window.localStorage.setItem(key, value);\n } catch {\n // Storage full or unavailable (private mode): persistence is best-effort.\n }\n }\n\n #removeItem(key: string): void {\n try {\n window.localStorage.removeItem(key);\n } catch {\n // Ignore: nothing to clear if storage is unavailable.\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/utils/safe_timeout.ts","../../src/utils/string_list.ts","../../src/controllers/persist_controller.ts"],"names":[],"mappings":";;;;;AAwBA,IAAe,gBAAf,MAA6B;AAAA;AAAA,EAER,GAAA,uBAAU,GAAA,EAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAczC,MAAM,EAAA,EAAkB;AACtB,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,MAAA,CAAO,EAAE,CAAA,EAAG;AACvB,MAAA,IAAA,CAAK,OAAO,EAAE,CAAA;AAAA,IAChB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QAAA,GAAiB;AACf,IAAA,KAAA,MAAW,EAAA,IAAM,KAAK,GAAA,EAAK;AACzB,MAAA,IAAA,CAAK,OAAO,EAAE,CAAA;AAAA,IAChB;AACA,IAAA,IAAA,CAAK,IAAI,KAAA,EAAM;AAAA,EACjB;AAAA;AAAA,EAGA,IAAI,IAAA,GAAe;AACjB,IAAA,OAAO,KAAK,GAAA,CAAI,IAAA;AAAA,EAClB;AACF,CAAA;AAmBO,IAAM,WAAA,GAAN,cAA0B,aAAA,CAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO7C,GAAA,CAAI,UAAsB,KAAA,EAAuB;AAC/C,IAAA,MAAM,EAAA,GAAK,IAAA,CAAK,QAAA,CAAS,MAAM;AAC7B,MAAA,IAA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AO,KAAA;AACnE,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA,EAGA,OAAO,KAAA,EAAoC;AACzC,IAAA,OAAO,KAAA,CAAM,IAAA,IAAQ,KAAA,CAAM,EAAA,IAAM,IAAA;AAAA,EACnC;AAAA;AAAA,EAGA,IAAI,WAAA,GAA6B;AAC/B,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,QAAA,IAAY,IAAA,CAAK,OAAA,CAAQ,EAAA;AAC1C,IAAA,OAAO,GAAA,CAAI,MAAA,GAAS,CAAA,GAAI,GAAA,GAAM,IAAA;AAAA,EAChC;AAAA;AAAA,EAGA,IAAI,WAAA,GAA6B;AAC/B,IAAA,MAAM,UAAU,IAAA,CAAK,WAAA;AACrB,IAAA,OAAO,YAAY,IAAA,GAAO,IAAA,GAAO,CAAA,EAAG,cAAc,GAAG,OAAO,CAAA,CAAA;AAAA,EAC9D;AAAA,EAEA,SAAS,GAAA,EAA4B;AACnC,IAAA,IAAI;AACF,MAAA,OAAO,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,GAAG,CAAA;AAAA,IACxC,CAAA,CAAA,MAAQ;AACN,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AAAA,EAEA,QAAA,CAAS,KAAa,KAAA,EAAqB;AACzC,IAAA,IAAI;AACF,MAAA,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,GAAA,EAAK,KAAK,CAAA;AAAA,IACxC,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF;AAAA,EAEA,YAAY,GAAA,EAAmB;AAC7B,IAAA,IAAI;AACF,MAAA,MAAA,CAAO,YAAA,CAAa,WAAW,GAAG,CAAA;AAAA,IACpC,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF;AACF","file":"persist_controller.js","sourcesContent":["/**\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 * 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","/**\n * JSON string-list parsing for the controllers that take a list as a Value.\n *\n * Stimulus offers an `Array` Value type, but its reader runs `JSON.parse` inside\n * the value observer — **before** the `<name>ValueChanged` callback — and\n * rethrows on malformed text. The throw propagates out of the observer that runs\n * during connection, so a single unparseable attribute stops the controller from\n * connecting at all: no lifecycle callback runs and the element is left inert\n * rather than degraded. A consumer cannot guard against it either, because the\n * callback that would hold the `try` never runs.\n *\n * Declaring the attribute as a `String` Value and parsing it here keeps a\n * malformed declaration local to the value it declares. The attribute text is\n * identical either way (`'[\"a\", \"b\"]'`), so markup does not change with the\n * declaration.\n */\n\n/**\n * Parses `raw` as a JSON array of strings.\n *\n * Returns `fallback` when the text is absent, unparseable, or not an array, so a\n * malformed declaration behaves like an omitted one. A parsed array keeps only\n * its string entries: every caller indexes or compares strings, and a stray\n * number would otherwise sit in the list without ever matching.\n *\n * An explicit `\"[]\"` is honoured as an empty list rather than falling back — it\n * is the only way to declare \"none\" against a non-empty default.\n *\n * @param raw - the attribute text, e.g. `'[\"password\"]'`.\n * @param fallback - the list to use when `raw` declares nothing usable.\n */\nexport function parseStringList(raw: string, fallback: readonly string[] = []): string[] {\n // The common case is an undeclared attribute, and `JSON.parse(\"\")` answers it\n // by throwing. Reaching the same fallback without building an exception keeps\n // the callers that ask per element off that path.\n const text = raw.trim();\n if (text.length === 0) return [...fallback];\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(text);\n } catch {\n return [...fallback];\n }\n\n if (!Array.isArray(parsed)) return [...fallback];\n return parsed.filter((entry): entry is string => typeof entry === \"string\");\n}\n","import { Controller } from \"@hotwired/stimulus\";\nimport { SafeTimeout } from \"../utils/safe_timeout\";\nimport { parseStringList } from \"../utils/string_list\";\n\n/** Field controls this controller can persist. */\ntype PersistField = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;\n\n/** Input types that carry no meaningful, restorable value. */\nconst NON_VALUE_TYPES = new Set([\"file\", \"submit\", \"reset\", \"button\", \"image\"]);\n/** Field types and names skipped unless the consumer declares its own list. */\nconst DEFAULT_EXCLUDE = [\"password\"];\n/** localStorage key prefix so drafts never clobber unrelated app storage. */\nconst STORAGE_PREFIX = \"stimeo--persist:\";\n/** Separator for disambiguating repeated same-name fields (cannot occur in a real field name). */\nconst OCCURRENCE_SEP = \"\\u0000\";\n\n/**\n * Headless draft-autosave behavior: persists a form's field values to\n * `localStorage` and restores them across Turbo navigations and reloads (no APG\n * pattern; a state-holding utility).\n *\n * Markup contract (identifier: `stimeo--persist`):\n * <form data-controller=\"stimeo--persist\"\n * data-stimeo--persist-key-value=\"contact-draft\">\n * <input name=\"name\">\n * <textarea name=\"message\"></textarea>\n * </form>\n *\n * On connect it restores any saved values under `key` (falling back to the\n * element's `id`), then debounce-saves on every input/change. Password fields (and\n * anything in `exclude`) are never written. A `clear()` action — or the `clearOn`\n * event (e.g. `submit`) — drops the draft. Restoring never moves focus.\n *\n * @remarks\n * Behavior only. State lives entirely in `localStorage` (no module-scope state), so\n * instances never interfere. The input listener and debounce timer are removed on\n * `disconnect()` (Turbo navigation included), where a pending save is flushed first\n * so an in-flight edit is not lost.\n */\nexport class PersistController extends Controller<HTMLElement> {\n static override targets = [\"field\"];\n static override values = {\n key: { type: String, default: \"\" },\n debounce: { type: Number, default: 400 },\n // A JSON list read through `parseStringList` rather than Stimulus's `Array`\n // type: that reader throws out of the value observer before any callback\n // runs, so one malformed attribute would stop the controller connecting.\n exclude: { type: String, default: \"\" },\n clearOn: { type: String, default: \"\" },\n };\n static actions = [\"clear\"] as const;\n static events = [\"restore\", \"save\", \"clear\"] as const;\n\n declare readonly fieldTargets: PersistField[];\n declare readonly hasFieldTarget: boolean;\n\n declare keyValue: string;\n declare debounceValue: number;\n declare excludeValue: string;\n declare clearOnValue: string;\n\n readonly #timeouts = new SafeTimeout();\n #saveId: number | null = null;\n\n readonly #onInput = (): void => {\n this.#scheduleSave();\n };\n\n readonly #onClearEvent = (): void => {\n this.clear();\n };\n\n override connect(): void {\n if (this.#storageKey === null) return;\n this.#restore();\n this.element.addEventListener(\"input\", this.#onInput);\n this.element.addEventListener(\"change\", this.#onInput);\n if (this.clearOnValue.length > 0) {\n this.element.addEventListener(this.clearOnValue, this.#onClearEvent);\n }\n }\n\n override disconnect(): void {\n this.element.removeEventListener(\"input\", this.#onInput);\n this.element.removeEventListener(\"change\", this.#onInput);\n if (this.clearOnValue.length > 0) {\n this.element.removeEventListener(this.clearOnValue, this.#onClearEvent);\n }\n // Flush a pending save so an in-flight edit survives a Turbo navigation.\n if (this.#saveId !== null) {\n this.#timeouts.clear(this.#saveId);\n this.#saveId = null;\n this.#write();\n }\n this.#timeouts.clearAll();\n }\n\n /** Drops the saved draft and clears the restored marker. */\n clear(): void {\n const key = this.#storageKey;\n if (key === null) return;\n if (this.#saveId !== null) {\n this.#timeouts.clear(this.#saveId);\n this.#saveId = null;\n }\n this.#removeItem(key);\n this.element.removeAttribute(\"data-persist-restored\");\n this.dispatch(\"clear\", { detail: { key: this.#logicalKey } });\n }\n\n /** Schedules a debounced save. */\n #scheduleSave(): void {\n if (this.#saveId !== null) this.#timeouts.clear(this.#saveId);\n this.#saveId = this.#timeouts.set(() => {\n this.#saveId = null;\n this.#save();\n }, this.debounceValue);\n }\n\n /** Writes the current values and emits `save`. */\n #save(): void {\n this.#write();\n this.dispatch(\"save\", { detail: { key: this.#logicalKey } });\n }\n\n /** Serializes persistable fields and stores them under the storage key. */\n #write(): void {\n const key = this.#storageKey;\n if (key === null) return;\n const data: Record<string, unknown> = {};\n for (const { field, key: fieldKey } of this.#fieldEntries()) {\n if (field instanceof HTMLInputElement && field.type === \"checkbox\") {\n data[fieldKey] = field.checked;\n } else if (field instanceof HTMLInputElement && field.type === \"radio\") {\n if (field.checked) data[fieldKey] = field.value;\n } else if (field instanceof HTMLSelectElement && field.multiple) {\n data[fieldKey] = Array.from(field.selectedOptions).map((o) => o.value);\n } else {\n data[fieldKey] = field.value;\n }\n }\n this.#setItem(key, JSON.stringify(data));\n }\n\n /** Applies any saved values to the fields, without moving focus. */\n #restore(): void {\n const key = this.#storageKey;\n if (key === null) return;\n const raw = this.#getItem(key);\n if (raw === null) return;\n let data: Record<string, unknown>;\n try {\n data = JSON.parse(raw) as Record<string, unknown>;\n } catch {\n return;\n }\n let restoredAny = false;\n for (const { field, key: fieldKey } of this.#fieldEntries()) {\n if (!Object.hasOwn(data, fieldKey)) continue;\n this.#applyValue(field, data[fieldKey]);\n restoredAny = true;\n }\n if (restoredAny) {\n this.element.setAttribute(\"data-persist-restored\", \"true\");\n this.dispatch(\"restore\", { detail: { key: this.#logicalKey } });\n }\n }\n\n /** Sets a single field's value from a stored entry. */\n #applyValue(field: PersistField, value: unknown): void {\n if (field instanceof HTMLInputElement && field.type === \"checkbox\") {\n field.checked = Boolean(value);\n } else if (field instanceof HTMLInputElement && field.type === \"radio\") {\n field.checked = field.value === value;\n } else if (field instanceof HTMLSelectElement && field.multiple) {\n const selected = new Set(Array.isArray(value) ? value.map(String) : []);\n for (const option of Array.from(field.options)) {\n option.selected = selected.has(option.value);\n }\n } else {\n field.value = String(value);\n }\n }\n\n /**\n * Persistable fields paired with a stable storage key. Uniquely-named fields key\n * by their name. Repeated same-name fields (e.g. a `tags[]` checkbox group or\n * array text inputs) are disambiguated by DOM-order occurrence — the first keeps\n * its plain `name`, later ones get a NUL-separated index suffix — so each is\n * stored and restored individually instead of the last one clobbering the rest.\n * Radios are the exception: a group intentionally shares one key (one value per\n * name).\n */\n #fieldEntries(): Array<{ field: PersistField; key: string }> {\n const entries: Array<{ field: PersistField; key: string }> = [];\n const occurrence = new Map<string, number>();\n for (const field of this.#fields()) {\n const name = this.#keyOf(field);\n if (name === null) continue;\n if (field instanceof HTMLInputElement && field.type === \"radio\") {\n entries.push({ field, key: name });\n continue;\n }\n const seen = occurrence.get(name) ?? 0;\n occurrence.set(name, seen + 1);\n entries.push({ field, key: seen === 0 ? name : `${name}${OCCURRENCE_SEP}${seen}` });\n }\n return entries;\n }\n\n /** The fields to persist: `field` targets, or the element's named controls. */\n #fields(): PersistField[] {\n const candidates = this.hasFieldTarget\n ? this.fieldTargets\n : Array.from(this.element.querySelectorAll<PersistField>(\"input, textarea, select\"));\n // The exclusion list is fixed for the pass, so it is read once here rather\n // than per candidate.\n const excluded = parseStringList(this.excludeValue, DEFAULT_EXCLUDE);\n return candidates.filter((field) => this.#persistable(field, excluded));\n }\n\n /** Whether a field carries a restorable, non-excluded value. */\n #persistable(field: PersistField, excluded: readonly string[]): boolean {\n if (this.#keyOf(field) === null) return false;\n const type = field instanceof HTMLInputElement ? field.type : \"\";\n if (NON_VALUE_TYPES.has(type)) return false;\n if (excluded.includes(type)) return false;\n if (field.name.length > 0 && excluded.includes(field.name)) return false;\n return true;\n }\n\n /** A stable storage sub-key for a field (its name, else id). */\n #keyOf(field: PersistField): string | null {\n return field.name || field.id || null;\n }\n\n /** The logical key (key Value or element id), or null when neither is set. */\n get #logicalKey(): string | null {\n const key = this.keyValue || this.element.id;\n return key.length > 0 ? key : null;\n }\n\n /** The prefixed localStorage key, or null when persistence is disabled. */\n get #storageKey(): string | null {\n const logical = this.#logicalKey;\n return logical === null ? null : `${STORAGE_PREFIX}${logical}`;\n }\n\n #getItem(key: string): string | null {\n try {\n return window.localStorage.getItem(key);\n } catch {\n return null;\n }\n }\n\n #setItem(key: string, value: string): void {\n try {\n window.localStorage.setItem(key, value);\n } catch {\n // Storage full or unavailable (private mode): persistence is best-effort.\n }\n }\n\n #removeItem(key: string): void {\n try {\n window.localStorage.removeItem(key);\n } catch {\n // Ignore: nothing to clear if storage is unavailable.\n }\n }\n}\n"]}
@@ -12,6 +12,16 @@ function isReservedArrowChord(event, allow = []) {
12
12
  var DetachGate = class _DetachGate {
13
13
  /** Set while a probe is queued, waiting for a reconnect to cancel it. */
14
14
  #pending = false;
15
+ /**
16
+ * True while a probe is queued — the last disconnect was ambiguous and no
17
+ * reconnect has cancelled it yet. Read it from `connect()` to tell the
18
+ * reconnect half of an in-page move from a first connect: a controller whose
19
+ * initialisation restarts a measurement (a min-duration floor, an elapsed
20
+ * counter) must skip it for the move, where nothing actually restarted.
21
+ */
22
+ get pending() {
23
+ return this.#pending;
24
+ }
15
25
  /**
16
26
  * True when the disconnect is definitely a real detach — the element left
17
27
  * the document, or `data-controller` no longer lists the identifier. False