ochreui 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +153 -2
  3. package/cli/ochreui.mjs +601 -0
  4. package/mcp/core.mjs +126 -0
  5. package/mcp/docs.json +906 -0
  6. package/mcp/server.mjs +23 -0
  7. package/package.json +393 -3
  8. package/registry/agent-team.ts +350 -0
  9. package/registry/avatar.ts +300 -0
  10. package/registry/badge.ts +207 -0
  11. package/registry/breadcrumb.ts +435 -0
  12. package/registry/button.ts +238 -0
  13. package/registry/card.ts +221 -0
  14. package/registry/change-summary.ts +200 -0
  15. package/registry/checkbox.ts +204 -0
  16. package/registry/code-block.ts +332 -0
  17. package/registry/color-picker.ts +720 -0
  18. package/registry/comment-thread.ts +503 -0
  19. package/registry/context-menu.ts +281 -0
  20. package/registry/cover-flow.ts +623 -0
  21. package/registry/date-picker.ts +799 -0
  22. package/registry/decision-inbox.ts +340 -0
  23. package/registry/dialog.ts +577 -0
  24. package/registry/dropdown-menu.ts +864 -0
  25. package/registry/email-draft.ts +916 -0
  26. package/registry/empty-calendar.ts +199 -0
  27. package/registry/empty-state.ts +164 -0
  28. package/registry/enrichment-orbit.ts +164 -0
  29. package/registry/filter-menu.ts +541 -0
  30. package/registry/form-field.ts +308 -0
  31. package/registry/frost-cloud.ts +381 -0
  32. package/registry/ghosted-chat.ts +210 -0
  33. package/registry/glow-cloud.ts +402 -0
  34. package/registry/grid-background.ts +164 -0
  35. package/registry/hover-card.ts +401 -0
  36. package/registry/icon-button.ts +133 -0
  37. package/registry/index.json +2124 -0
  38. package/registry/integration-beam.ts +588 -0
  39. package/registry/integration-grid.ts +209 -0
  40. package/registry/kbd.ts +176 -0
  41. package/registry/layer-stack.ts +351 -0
  42. package/registry/lead-sourcing.ts +285 -0
  43. package/registry/logo-cluster.ts +239 -0
  44. package/registry/logo-marquee.ts +505 -0
  45. package/registry/message-actions.ts +833 -0
  46. package/registry/model-orbit.ts +583 -0
  47. package/registry/model-wheel.ts +372 -0
  48. package/registry/notification-stack.ts +301 -0
  49. package/registry/number-input.ts +552 -0
  50. package/registry/number-ticker.ts +261 -0
  51. package/registry/ochre.css +917 -0
  52. package/registry/otp-input.ts +704 -0
  53. package/registry/overlay.ts +312 -0
  54. package/registry/pagination.ts +362 -0
  55. package/registry/popover.ts +296 -0
  56. package/registry/profile-menu.ts +332 -0
  57. package/registry/progress-tracker.ts +291 -0
  58. package/registry/rating.ts +461 -0
  59. package/registry/reaction-bar.ts +322 -0
  60. package/registry/region-map.ts +537 -0
  61. package/registry/resizable.ts +489 -0
  62. package/registry/scroll-area.ts +271 -0
  63. package/registry/segmented-control.ts +433 -0
  64. package/registry/select.ts +769 -0
  65. package/registry/separator.ts +97 -0
  66. package/registry/shimmer-loader.ts +211 -0
  67. package/registry/side-folder.ts +152 -0
  68. package/registry/skeleton.ts +136 -0
  69. package/registry/skill/INSTRUCTIONS.md +11 -0
  70. package/registry/skill/SKILL.md +65 -0
  71. package/registry/skill/checklist.md +45 -0
  72. package/registry/skill/references/agent-team.md +105 -0
  73. package/registry/skill/references/avatar.md +88 -0
  74. package/registry/skill/references/badge.md +92 -0
  75. package/registry/skill/references/breadcrumb.md +99 -0
  76. package/registry/skill/references/button.md +82 -0
  77. package/registry/skill/references/card.md +111 -0
  78. package/registry/skill/references/catalog.md +114 -0
  79. package/registry/skill/references/change-summary.md +103 -0
  80. package/registry/skill/references/checkbox.md +105 -0
  81. package/registry/skill/references/code-block.md +109 -0
  82. package/registry/skill/references/color-picker.md +138 -0
  83. package/registry/skill/references/comment-thread.md +164 -0
  84. package/registry/skill/references/context-menu.md +205 -0
  85. package/registry/skill/references/cover-flow.md +128 -0
  86. package/registry/skill/references/date-picker.md +154 -0
  87. package/registry/skill/references/decision-inbox.md +126 -0
  88. package/registry/skill/references/dialog.md +155 -0
  89. package/registry/skill/references/dropdown-menu.md +144 -0
  90. package/registry/skill/references/email-draft.md +182 -0
  91. package/registry/skill/references/empty-calendar.md +74 -0
  92. package/registry/skill/references/empty-state.md +118 -0
  93. package/registry/skill/references/enrichment-orbit.md +71 -0
  94. package/registry/skill/references/filter-menu.md +143 -0
  95. package/registry/skill/references/form-field.md +118 -0
  96. package/registry/skill/references/frost-cloud.md +80 -0
  97. package/registry/skill/references/ghosted-chat.md +75 -0
  98. package/registry/skill/references/glow-cloud.md +84 -0
  99. package/registry/skill/references/grid-background.md +76 -0
  100. package/registry/skill/references/hover-card.md +125 -0
  101. package/registry/skill/references/icon-button.md +99 -0
  102. package/registry/skill/references/integration-beam.md +107 -0
  103. package/registry/skill/references/integration-grid.md +100 -0
  104. package/registry/skill/references/kbd.md +65 -0
  105. package/registry/skill/references/layer-stack.md +115 -0
  106. package/registry/skill/references/lead-sourcing.md +92 -0
  107. package/registry/skill/references/logo-cluster.md +92 -0
  108. package/registry/skill/references/logo-marquee.md +123 -0
  109. package/registry/skill/references/message-actions.md +146 -0
  110. package/registry/skill/references/model-orbit.md +106 -0
  111. package/registry/skill/references/model-wheel.md +84 -0
  112. package/registry/skill/references/notification-stack.md +138 -0
  113. package/registry/skill/references/number-input.md +117 -0
  114. package/registry/skill/references/number-ticker.md +73 -0
  115. package/registry/skill/references/otp-input.md +142 -0
  116. package/registry/skill/references/pagination.md +112 -0
  117. package/registry/skill/references/popover.md +143 -0
  118. package/registry/skill/references/profile-menu.md +123 -0
  119. package/registry/skill/references/progress-tracker.md +122 -0
  120. package/registry/skill/references/rating.md +111 -0
  121. package/registry/skill/references/reaction-bar.md +128 -0
  122. package/registry/skill/references/region-map.md +109 -0
  123. package/registry/skill/references/resizable.md +127 -0
  124. package/registry/skill/references/scroll-area.md +113 -0
  125. package/registry/skill/references/segmented-control.md +96 -0
  126. package/registry/skill/references/select.md +122 -0
  127. package/registry/skill/references/separator.md +69 -0
  128. package/registry/skill/references/shimmer-loader.md +83 -0
  129. package/registry/skill/references/side-folder.md +75 -0
  130. package/registry/skill/references/skeleton.md +95 -0
  131. package/registry/skill/references/smart-recommendation.md +132 -0
  132. package/registry/skill/references/spinner.md +84 -0
  133. package/registry/skill/references/switch.md +79 -0
  134. package/registry/skill/references/tab-overload.md +70 -0
  135. package/registry/skill/references/tag-input.md +126 -0
  136. package/registry/skill/references/team-invite.md +94 -0
  137. package/registry/skill/references/testimonial-wall.md +110 -0
  138. package/registry/skill/references/text-area.md +115 -0
  139. package/registry/skill/references/text-field.md +126 -0
  140. package/registry/skill/references/text-reveal.md +71 -0
  141. package/registry/skill/references/thinking-loader.md +87 -0
  142. package/registry/skill/references/time-picker.md +122 -0
  143. package/registry/skill/references/tips-panel.md +115 -0
  144. package/registry/skill/references/toggle-group.md +98 -0
  145. package/registry/skill/references/tool-call-card.md +151 -0
  146. package/registry/skill/references/tooltip.md +94 -0
  147. package/registry/skill/references/tree-view.md +172 -0
  148. package/registry/skill/theming.md +57 -0
  149. package/registry/smart-recommendation.ts +415 -0
  150. package/registry/spinner.ts +67 -0
  151. package/registry/switch.ts +146 -0
  152. package/registry/tab-overload.ts +211 -0
  153. package/registry/tag-input.ts +620 -0
  154. package/registry/team-invite.ts +248 -0
  155. package/registry/testimonial-wall.ts +521 -0
  156. package/registry/text-area.ts +432 -0
  157. package/registry/text-field.ts +415 -0
  158. package/registry/text-reveal.ts +175 -0
  159. package/registry/theme.ts +68 -0
  160. package/registry/thinking-loader.ts +302 -0
  161. package/registry/time-picker.ts +828 -0
  162. package/registry/tips-panel.ts +312 -0
  163. package/registry/toggle-group.ts +357 -0
  164. package/registry/tool-call-card.ts +578 -0
  165. package/registry/tooltip.ts +486 -0
  166. package/registry/tree-view.ts +454 -0
  167. package/styles/base.css +500 -0
  168. package/styles/tokens.css +415 -0
@@ -0,0 +1,828 @@
1
+ // Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
2
+ /**
3
+ * Time Picker, from Ochre (https://ochreui.dev).
4
+ * Needs ochre.css (`npx ochreui init`) and overlay.ts (`npx ochreui add overlay`).
5
+ *
6
+ * <ui-time-picker label="Send at" hint="…"><input uiTimePicker [formField]="form.sendAt" /></ui-time-picker>
7
+ * Your own <input> shows "9:30 AM" or "09:30" by locale; the form gets "09:30" (signal forms, reactive forms,
8
+ * ngModel or [(value)]). Type "930", "9:30 pm" or "21.30", or pick from a list every `step` minutes.
9
+ *
10
+ * Public styling hooks (set them on the element or any ancestor):
11
+ * --ui-text-field-edge resting edge (default: the hairline), shared with Text Field
12
+ * --ui-text-field-edge-hover edge on hover
13
+ * --ui-text-field-edge-focus edge while focused (default: the input border, 3:1 or more)
14
+ * --ui-text-field-radius corners (default 7px; Classic 10px)
15
+ * --ui-time-picker-list-max-height tallest the list gets before it scrolls (default 264px)
16
+ */
17
+ import {
18
+ Component,
19
+ DOCUMENT,
20
+ DestroyRef,
21
+ Directive,
22
+ ElementRef,
23
+ LOCALE_ID,
24
+ PLATFORM_ID,
25
+ afterNextRender,
26
+ afterRenderEffect,
27
+ booleanAttribute,
28
+ computed,
29
+ contentChild,
30
+ effect,
31
+ forwardRef,
32
+ inject,
33
+ input,
34
+ isDevMode,
35
+ model,
36
+ numberAttribute,
37
+ signal,
38
+ untracked,
39
+ viewChild,
40
+ } from '@angular/core';
41
+ import { isPlatformBrowser } from '@angular/common';
42
+ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
43
+ import { OverlayOptions, OverlayRef, placeOverlay } from './overlay';
44
+
45
+ export type TimePickerSize = 'sm' | 'md' | 'lg';
46
+
47
+ export interface TimePickerLabels {
48
+ optional: string;
49
+ showTimes: string;
50
+ }
51
+
52
+ const LABELS: TimePickerLabels = { optional: 'Optional', showTimes: 'Show times' };
53
+ const OFFSET = 4;
54
+ const MIN_ROOM = 160;
55
+ const DAY_END = 24 * 60 - 1;
56
+
57
+ let nextId = 0;
58
+
59
+ const pad = (n: number) => String(n).padStart(2, '0');
60
+ const toText = (m: number) => `${pad(Math.floor(m / 60))}:${pad(m % 60)}`;
61
+ /** Minutes after midnight of an "HH:mm" (or "HH:mm:ss") string, else null. */
62
+ const toMinutes = (v: unknown) => {
63
+ const m = typeof v === 'string' ? /^(\d{1,2}):(\d{2})(?::\d{2}(?:\.\d+)?)?$/.exec(v.trim()) : null;
64
+ return m && +m[1] < 24 && +m[2] < 60 ? +m[1] * 60 + +m[2] : null;
65
+ };
66
+ const asTime = (v: unknown) => {
67
+ const m = toMinutes(v);
68
+ return m === null ? null : toText(m);
69
+ };
70
+
71
+ const PERIODS = new Map<string, string[][]>();
72
+ const squash = (s: string) => s.toLowerCase().replace(/[\s.:]/g, '');
73
+
74
+ /** The words for before and after noon in `locale`, plus a / am and p / pm. */
75
+ function periods(locale: string) {
76
+ let found = PERIODS.get(locale);
77
+ if (!found) {
78
+ const word = (h: number) => {
79
+ try {
80
+ const f = new Intl.DateTimeFormat(locale, { hour: 'numeric', hourCycle: 'h12', timeZone: 'UTC' });
81
+ return squash(f.formatToParts(Date.UTC(2000, 0, 1, h)).find((p) => p.type === 'dayPeriod')?.value ?? '');
82
+ } catch {
83
+ return '';
84
+ }
85
+ };
86
+ found = [['a', 'am', word(1)], ['p', 'pm', word(13)]].map((l) => l.filter(Boolean));
87
+ PERIODS.set(locale, found);
88
+ }
89
+ return found;
90
+ }
91
+
92
+ /** Reads a typed time ("930", "9:30 pm", "21.30", "9h30") as "HH:mm", else null; `partial` accepts "9:3" as 09:30. */
93
+ export function parseTime(text: string, opts: { locale?: string; partial?: boolean } = {}): string | null {
94
+ const partial = !!opts.partial;
95
+ const m = /^(\D*?)(\d(?:[\d\s:.h]*\d)?)(\D*)$/.exec(text.normalize('NFKC').toLowerCase().trim());
96
+ if (!m) return null;
97
+ const [, before, core, after] = m;
98
+ const said = squash(before + after);
99
+ const word = said === 'h' ? '' : said;
100
+ const [am, pm] = periods(opts.locale ?? 'en-US');
101
+ const period = !word ? 0 : am.includes(word) ? 1 : pm.includes(word) ? 2 : -1;
102
+ if (period < 0 || (squash(before) && squash(after))) return null;
103
+ const parts = core.split(/[\s:.h]+/);
104
+ let h: number;
105
+ let min: number;
106
+ if (parts.length > 2 || parts[0].length > 4 || (parts.length > 1 && parts[0].length > 2)) return null;
107
+ if (parts.length === 2) {
108
+ const tail = parts[1];
109
+ if (tail.length > 2 || (tail.length < 2 && !partial)) return null;
110
+ h = +parts[0];
111
+ min = +tail.padEnd(2, '0');
112
+ } else {
113
+ const d = parts[0];
114
+ [h, min] = d.length > 2 ? [+d.slice(0, -2), +d.slice(-2)] : [+d, 0];
115
+ if (partial && d.length === 2 && h > 24) [h, min] = [+d[0], 0];
116
+ if (partial && d.length === 3 && min > 59) [h, min] = [+d.slice(0, 2), +d[2] * 10];
117
+ }
118
+ if (min > 59) return null;
119
+ if (period) {
120
+ if (h < 1 || h > 12) return null;
121
+ h = (h % 12) + (period === 2 ? 12 : 0);
122
+ } else if (h === 24 && !min) h = 0;
123
+ else if (h > 23) return null;
124
+ return toText(h * 60 + min);
125
+ }
126
+
127
+ export interface TimeRow {
128
+ /** "HH:mm" */
129
+ v: string;
130
+ /** Minutes after midnight. */
131
+ m: number;
132
+ /** As shown, e.g. "9:30 AM". */
133
+ label: string;
134
+ }
135
+
136
+ /** Put it on the `<input>` inside a `<ui-time-picker>`. It owns the "HH:mm" value, the typing and the ARIA. */
137
+ @Directive({
138
+ selector: 'input[uiTimePicker]',
139
+ exportAs: 'uiTimePicker',
140
+ providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => UiTimeInput), multi: true }],
141
+ host: {
142
+ class: 'ui-input',
143
+ type: 'text',
144
+ role: 'combobox',
145
+ 'aria-autocomplete': 'list',
146
+ autocomplete: 'off',
147
+ autocorrect: 'off',
148
+ inputmode: 'text',
149
+ spellcheck: 'false',
150
+ style: 'outline: 0; font-variant-numeric: tabular-nums',
151
+ '[id]': 'id()',
152
+ '[attr.name]': 'null',
153
+ '[attr.required]': 'null',
154
+ '[placeholder]': 'placeholder() ?? display(540)',
155
+ '[attr.aria-expanded]': 'open()',
156
+ '[attr.aria-controls]': 'open() ? field.listId : null',
157
+ '[attr.aria-activedescendant]': 'open() ? field.activeId() : null',
158
+ '[attr.aria-describedby]': 'describedBy()',
159
+ '[attr.aria-invalid]': 'field.invalid() || null',
160
+ '[attr.aria-required]': 'required() || null',
161
+ '(input)': 'typed($event)',
162
+ '(compositionend)': 'typed()',
163
+ '(click)': 'field.clicked()',
164
+ '(keydown)': 'field.key($event)',
165
+ '(blur)': 'blurred()',
166
+ '(document:reset)': 'reset($event)',
167
+ },
168
+ })
169
+ export class UiTimeInput implements ControlValueAccessor {
170
+ /** The time as "HH:mm" (24 h), or null when empty. Bind `[(value)]`, `[formField]`, `formControlName` or `ngModel`. */
171
+ readonly value = model<string | null>(null);
172
+ /** Whether the list is showing. Bind `[(open)]` to open it from code. */
173
+ readonly open = model(false);
174
+ /** Minutes between listed times, counted from `min`; 5 or more. Typing can still set any minute. */
175
+ readonly step = input(15, { transform: (v: unknown) => Math.max(5, Math.round(numberAttribute(v, 15))) });
176
+ /** Earliest time, "HH:mm". The list starts here; earlier typed times are put back. With `[formField]`, set it on `<ui-time-picker>`. */
177
+ readonly min = input<string | null, unknown>(null, { transform: asTime });
178
+ /** Latest time, "HH:mm". Ignored when it lies before `min`. With `[formField]`, set it on `<ui-time-picker>`. */
179
+ readonly max = input<string | null, unknown>(null, { transform: asTime });
180
+ /** 12 (9:30 PM) or 24 (21:30). Default: what the locale uses. */
181
+ readonly hourCycle = input<12 | 24 | null, unknown>(null, { transform: (v: unknown) => (+v! === 12 || +v! === 24 ? (+v! as 12 | 24) : null) });
182
+ /** Display locale; its own AM / PM words can be typed too. Default: the app's LOCALE_ID. */
183
+ readonly locale = input<string>();
184
+ /** Grey text while empty. Default: 9:00 in the field's format. */
185
+ readonly placeholder = input<string>();
186
+ /** Submits "HH:mm" with a native form, through a hidden input. Signal forms set it from the field. */
187
+ readonly name = input<string>();
188
+ /** Sets `aria-required`. Signal forms set it from the schema. */
189
+ readonly required = input(false, { transform: booleanAttribute });
190
+ readonly id = input(`ui-time-picker-${nextId++}`);
191
+ /** Your own descriptions, kept alongside the field's. Set it as `aria-describedby="…"`, not `[attr.aria-describedby]`. */
192
+ readonly ariaDescribedby = input<string>(undefined, { alias: 'aria-describedby' });
193
+
194
+ readonly el = inject<ElementRef<HTMLInputElement>>(ElementRef).nativeElement;
195
+ protected readonly field = inject(UiTimePicker);
196
+ private readonly appLocale = inject(LOCALE_ID);
197
+ readonly disabled = signal(false);
198
+ private initial: string | null = null;
199
+ private onChange: (v: string | null) => void = () => {};
200
+ private onTouched: () => void = () => {};
201
+
202
+ private readonly lang = computed(() => this.locale() || this.appLocale);
203
+ readonly twelve = computed(() => {
204
+ const cycle = this.hourCycle();
205
+ if (cycle) return cycle === 12;
206
+ try {
207
+ return /h1[12]/.test(new Intl.DateTimeFormat(this.lang(), { hour: 'numeric' }).resolvedOptions().hourCycle ?? '');
208
+ } catch {
209
+ return false;
210
+ }
211
+ });
212
+ private readonly fmt = computed(() => {
213
+ const twelve = this.twelve();
214
+ const opts: Intl.DateTimeFormatOptions = { hour: twelve ? 'numeric' : '2-digit', minute: '2-digit', hourCycle: twelve ? 'h12' : 'h23', timeZone: 'UTC' };
215
+ let f: Intl.DateTimeFormat;
216
+ try {
217
+ f = new Intl.DateTimeFormat(this.lang(), opts);
218
+ } catch {
219
+ f = new Intl.DateTimeFormat('en-US', opts);
220
+ }
221
+ return (m: number) => f.format(Date.UTC(2000, 0, 1, 0, m));
222
+ });
223
+ /** The first and last minute a value may take. */
224
+ readonly bounds = computed(() => {
225
+ const lo = toMinutes(this.min() ?? this.field.min()) ?? 0;
226
+ const hi = toMinutes(this.max() ?? this.field.max()) ?? DAY_END;
227
+ return [lo, hi < lo ? DAY_END : hi] as const;
228
+ });
229
+ readonly rows = computed<TimeRow[]>(() => {
230
+ const [lo, hi] = this.bounds();
231
+ const [step, fmt] = [this.step(), this.fmt()];
232
+ const out: TimeRow[] = [];
233
+ for (let m = lo; m <= hi; m += step) out.push({ v: toText(m), m, label: fmt(m) });
234
+ return out;
235
+ });
236
+ /** The value as "HH:mm", or null. */
237
+ readonly chosen = computed(() => asTime(this.value()));
238
+ protected readonly describedBy = computed(
239
+ () => [this.ariaDescribedby(), ...this.field.describers()].filter(Boolean).join(' ') || null,
240
+ );
241
+
242
+ constructor() {
243
+ const destroy = inject(DestroyRef);
244
+ effect(() => {
245
+ this.chosen();
246
+ this.fmt();
247
+ untracked(() => this.revert());
248
+ });
249
+ afterNextRender(() => {
250
+ const el = this.el;
251
+ this.initial = this.value();
252
+ const read = () => this.disabled.set(el.disabled);
253
+ read();
254
+ const view = el.ownerDocument.defaultView;
255
+ if (!view?.MutationObserver) return;
256
+ const watch = new view.MutationObserver(read);
257
+ watch.observe(el, { attributes: true, attributeFilter: ['disabled'] });
258
+ destroy.onDestroy(() => watch.disconnect());
259
+ });
260
+ }
261
+
262
+ display(m: number | null) {
263
+ return m === null ? '' : this.fmt()(m);
264
+ }
265
+
266
+ /** True while the text differs from the shown value. */
267
+ dirty() {
268
+ return this.el.value !== this.display(toMinutes(this.chosen()));
269
+ }
270
+
271
+ /** Shows the value again, dropping what was typed. */
272
+ revert() {
273
+ const text = this.display(toMinutes(this.chosen()));
274
+ if (this.el.value !== text) this.el.value = text;
275
+ }
276
+
277
+ /** Sets the value as a pick does: forms hear it, and the text shows it formatted. */
278
+ choose(v: string | null) {
279
+ if (v !== this.chosen()) {
280
+ this.value.set(v);
281
+ this.onChange(v);
282
+ this.el.dispatchEvent(new Event('change', { bubbles: true }));
283
+ }
284
+ this.revert();
285
+ }
286
+
287
+ /** Reads the text: an empty field is null; a whole time in range is kept; anything else is put back. */
288
+ commit() {
289
+ const text = this.el.value.trim();
290
+ if (!text) return this.choose(null);
291
+ const v = parseTime(text, { locale: this.lang() });
292
+ const m = toMinutes(v);
293
+ const [lo, hi] = this.bounds();
294
+ if (m === null || m < lo || m > hi) return this.revert();
295
+ this.choose(v);
296
+ }
297
+
298
+ /** The list row that `text` points at while it is being typed, or -1. */
299
+ match(text: string) {
300
+ const m = toMinutes(parseTime(text, { locale: this.lang(), partial: true }));
301
+ const rows = this.rows();
302
+ if (m === null || !rows.length) return -1;
303
+ const i = rows.findIndex((r) => r.m >= m);
304
+ return i < 0 ? rows.length - 1 : i;
305
+ }
306
+
307
+ protected typed(e?: Event) {
308
+ if ((e as InputEvent | undefined)?.isComposing) return;
309
+ this.field.typed(this.el.value);
310
+ }
311
+
312
+ protected blurred() {
313
+ if (this.dirty()) this.commit();
314
+ this.onTouched();
315
+ this.open.set(false);
316
+ }
317
+
318
+ /** A native form reset puts back the time it started with. */
319
+ protected reset(event: Event) {
320
+ if (event.target !== this.el.form) return;
321
+ setTimeout(() => {
322
+ if (event.defaultPrevented) return;
323
+ this.open.set(false);
324
+ this.choose(asTime(this.initial));
325
+ });
326
+ }
327
+
328
+ writeValue(v: unknown) {
329
+ this.value.set(typeof v === 'string' && v ? v : null);
330
+ }
331
+
332
+ registerOnChange(fn: (v: string | null) => void) {
333
+ this.onChange = fn;
334
+ }
335
+
336
+ registerOnTouched(fn: () => void) {
337
+ this.onTouched = fn;
338
+ }
339
+
340
+ setDisabledState(disabled: boolean) {
341
+ this.el.disabled = disabled;
342
+ this.disabled.set(disabled);
343
+ }
344
+ }
345
+
346
+ const space = (n: string) => `var(--ui-space-${n})`;
347
+ const SIZES: Record<TimePickerSize, Record<string, string>> = {
348
+ sm: { '--_h0': 'var(--ui-control-h-sm)', '--_ht': `calc(${space('8')} + ${space('0-5')})` },
349
+ md: { '--_h0': 'var(--ui-control-h-md)', '--_ht': `calc(${space('8')} + ${space('1-5')})` },
350
+ lg: { '--_h0': `calc(var(--ui-control-h-md) + ${space('1')})`, '--_ht': `calc(${space('10')} + ${space('0-5')})` },
351
+ };
352
+
353
+ /** The overlay layer, placed at the field's width: below while 160px of room is left there, else where there is more. */
354
+ class TimeOverlay extends OverlayRef {
355
+ constructor(
356
+ el: HTMLElement,
357
+ doc: Document,
358
+ private readonly opts: OverlayOptions,
359
+ ) {
360
+ super(el, doc, opts);
361
+ }
362
+
363
+ override place() {
364
+ const { el } = this;
365
+ const anchor = this.opts.anchor();
366
+ if (!anchor?.isConnected || !el.hasAttribute('data-open')) return;
367
+ const r = anchor.getBoundingClientRect();
368
+ const root = el.ownerDocument.documentElement;
369
+ el.style.inlineSize = `${r.width}px`;
370
+ el.style.setProperty('--_room', '100vh');
371
+ const height = el.offsetHeight;
372
+ const rtl = el.ownerDocument.defaultView?.getComputedStyle(anchor).direction === 'rtl';
373
+ const view = { width: root.clientWidth, height: root.clientHeight };
374
+ const spot = placeOverlay(r, { width: r.width, height: Math.min(height, MIN_ROOM) }, view, 'bottom', 'start', OFFSET, rtl);
375
+ const shown = Math.min(height, spot.maxHeight);
376
+ el.style.setProperty('--_room', `${spot.maxHeight}px`);
377
+ Object.assign(el.style, {
378
+ left: `${spot.x}px`,
379
+ top: `${spot.side === 'top' ? r.top - OFFSET - shown : spot.y}px`,
380
+ transformOrigin: spot.origin,
381
+ });
382
+ el.dataset['side'] = spot.side;
383
+ }
384
+ }
385
+
386
+ /** The list of a `<ui-time-picker>`, in the top layer while open. Used by `UiTimePicker` only. */
387
+ @Component({
388
+ selector: 'ui-time-picker-list',
389
+ template: `
390
+ <span class="glow" aria-hidden="true"></span>
391
+ @if (field.open()) {
392
+ @for (r of field.rows(); track r.v; let i = $index) {
393
+ <div class="row" role="option" [id]="field.listId + '-' + i" [attr.aria-selected]="r.v === field.chosen()" [attr.data-active]="i === field.active() || null"
394
+ (pointermove)="field.hover(i, $event)" (click)="field.pick(r.v)">
395
+ <span class="txt">{{ r.label }}</span>
396
+ <span class="check" aria-hidden="true">
397
+ @if (r.v === field.chosen()) {<svg class="ui-icon" viewBox="0 0 16 16"><path class="ui-draw" pathLength="1" d="M3.5 8.5l3 3 6-7" /></svg>}
398
+ </span>
399
+ </div>
400
+ }
401
+ }
402
+ `,
403
+ styles: `
404
+ :host {
405
+ --_p: calc(var(--ui-space-1) + 1px * var(--_t));
406
+ --_r: calc(var(--ui-radius-sm) + 3px * var(--_t));
407
+ --_y: 0;
408
+ position: fixed;
409
+ inset: auto;
410
+ z-index: var(--ui-z-popover);
411
+ box-sizing: border-box;
412
+ max-block-size: min(var(--ui-time-picker-list-max-height, 264px), var(--_room, 264px));
413
+ margin: 0;
414
+ padding: var(--_p);
415
+ overflow-y: auto;
416
+ overscroll-behavior: contain;
417
+ scrollbar-width: thin;
418
+ border: 0;
419
+ border-radius: calc(var(--_r) + var(--_p));
420
+ background: var(--ui-bg-overlay);
421
+ box-shadow: var(--ui-shadow-md);
422
+ color: var(--ui-text);
423
+ font-size: calc(var(--ui-text-base) + 0.5px * var(--_t));
424
+ line-height: var(--ui-leading-base);
425
+ font-variant-numeric: tabular-nums;
426
+ text-align: start;
427
+ transition: var(--ui-duration-3) var(--ui-ease-out);
428
+ transition-property: opacity, scale, translate;
429
+ }
430
+ @container style(--ui-look-tray: 1) { :host { box-shadow: var(--ui-shadow-lg); } }
431
+ :host(:not([data-open])) { display: none !important; }
432
+ :host([data-side='top']) { --_y: var(--ui-space-1); }
433
+ :host([data-side='bottom']) { --_y: calc(var(--ui-space-1) * -1); }
434
+ :host([data-enter]) { opacity: 0; scale: 0.98; translate: 0 var(--_y); transition: none; }
435
+ .glow {
436
+ position: absolute;
437
+ inset-inline: var(--_p);
438
+ top: 0;
439
+ border-radius: var(--_r);
440
+ background: color-mix(in srgb, var(--ui-text) 6%, var(--ui-bg-overlay));
441
+ pointer-events: none;
442
+ transition: calc(var(--ui-duration-3) * (0.8 + 0.1 * var(--_t))) var(--ui-ease-out);
443
+ transition-property: translate, block-size;
444
+ }
445
+ .row {
446
+ position: relative;
447
+ display: flex;
448
+ align-items: center;
449
+ gap: var(--ui-space-2);
450
+ block-size: calc(var(--ui-space-8) + 2px * var(--_t));
451
+ padding-inline: calc(var(--ui-space-2) + 2px * var(--_t));
452
+ cursor: pointer;
453
+ user-select: none;
454
+ -webkit-tap-highlight-color: transparent;
455
+ }
456
+ .txt { flex: 1; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
457
+ [aria-selected='true'] .txt { font-weight: var(--ui-weight-medium); }
458
+ .check { display: flex; flex: none; align-items: center; justify-content: center; inline-size: var(--ui-icon-md); block-size: var(--ui-icon-md); }
459
+ svg { inline-size: var(--ui-icon-sm); block-size: var(--ui-icon-sm); stroke-width: calc(var(--ui-icon-stroke) + 0.25px); }
460
+ @media (pointer: coarse) {
461
+ .row { block-size: var(--ui-space-10); font-size: calc(var(--ui-text-md) + 1px); }
462
+ }
463
+ @media (forced-colors: active) {
464
+ :host { border: 1px solid CanvasText; }
465
+ .glow { forced-color-adjust: none; background: Highlight; }
466
+ [data-active] { forced-color-adjust: none; color: HighlightText; }
467
+ }
468
+ `,
469
+ })
470
+ export class UiTimePickerList {
471
+ protected readonly field = inject(UiTimePicker);
472
+ }
473
+
474
+ type Scroll = 'center' | 'near' | 'none';
475
+
476
+ @Component({
477
+ selector: 'ui-time-picker',
478
+ imports: [UiTimePickerList],
479
+ host: {
480
+ '[attr.data-size]': 'size()',
481
+ '[attr.data-open]': 'open() || null',
482
+ '[attr.data-invalid]': 'invalid() || null',
483
+ '[attr.data-disabled]': 'control()?.disabled() || null',
484
+ '[style]': 'sizes[size()]',
485
+ },
486
+ template: `
487
+ @if (label()) {
488
+ <div class="top">
489
+ <label [id]="labelId" [for]="control()?.id()" (click)="focusInput($event)">{{ label() }}@if (optional()) {<span class="ui-sr"> ({{ t().optional }})</span>}</label>
490
+ @if (optional()) {<span class="opt" aria-hidden="true">{{ t().optional }}</span>}
491
+ </div>
492
+ }
493
+ <div #box class="box" [attr.data-nudge]="nudge() || null" (pointerdown)="press($event)" (animationend)="$event.target === $event.currentTarget && nudge.set(false)" (animationcancel)="$event.target === $event.currentTarget && nudge.set(false)">
494
+ <svg class="clock ui-icon" viewBox="0 0 16 16" aria-hidden="true"><circle cx="8" cy="8" r="6.25" /><path d="M8 5.25V8l1.75 1.25" /></svg>
495
+ <ng-content select="input" />
496
+ <button type="button" class="chev ui-btn-icon" tabindex="-1" [id]="buttonId" [attr.aria-label]="t().showTimes"
497
+ [attr.aria-labelledby]="label() ? buttonId + ' ' + labelId : null" [disabled]="control()?.disabled()" (click)="toggle()">
498
+ <svg class="ui-icon" viewBox="0 0 16 16" aria-hidden="true"><path d="M4.5 6.25 8 9.75l3.5-3.5" /></svg>
499
+ </button>
500
+ </div>
501
+ <ui-time-picker-list #panel popover="manual" role="listbox" [id]="listId" [attr.aria-labelledby]="label() ? labelId : null"
502
+ [attr.aria-label]="label() ? null : control()?.el?.getAttribute('aria-label')" [attr.data-kbd]="kbd() || null" (pointerdown)="$event.preventDefault()" />
503
+ <div class="foot" [class.ui-sr]="!message()">
504
+ <p #msg [id]="messageId" dir="auto" aria-live="polite">{{ message() }}</p>
505
+ </div>
506
+ @if (control()?.name(); as name) {<input type="hidden" [name]="name" [value]="control()?.chosen() ?? ''" />}
507
+ `,
508
+ styles: `
509
+ :host {
510
+ --_t: var(--ui-look-tray, 0);
511
+ --_h: calc(var(--_h0) + var(--ui-space-1) * var(--_t));
512
+ --_e: var(--ui-text-field-edge, var(--ui-hairline));
513
+ --_w: calc(0.5px + 0.5px * var(--_t));
514
+ --_fill: var(--ui-bg-surface);
515
+ --ui-text-placeholder: light-dark(color-mix(in srgb, var(--ui-text-muted) 49%, var(--_fill)), color-mix(in srgb, var(--ui-text-muted) 51%, var(--_fill)));
516
+ display: flex;
517
+ flex-direction: column;
518
+ gap: calc(var(--ui-space-1-5) + 1px * var(--_t));
519
+ min-inline-size: 0;
520
+ color: var(--ui-text);
521
+ font: var(--ui-text-base) / var(--ui-leading-base) var(--ui-font-sans);
522
+ }
523
+ .top { display: flex; align-items: baseline; gap: var(--ui-space-1-5); padding-inline: calc(2px * var(--_t)); }
524
+ label { font-weight: var(--ui-weight-medium); }
525
+ .opt, .foot { color: var(--ui-text-muted); font-size: calc(var(--ui-text-sm) + 0.5px * var(--_t)); line-height: calc(var(--ui-leading-xs) + 1px * var(--_t)); }
526
+ .box {
527
+ display: flex;
528
+ align-items: center;
529
+ gap: var(--ui-space-2);
530
+ box-sizing: border-box;
531
+ block-size: var(--_h);
532
+ padding-inline: calc(var(--ui-space-2-5) + 2px * var(--_t) - 1px) calc(var(--ui-space-1) + 2px * var(--_t) - 1px);
533
+ border: 1px solid transparent;
534
+ border-radius: var(--ui-text-field-radius, calc(var(--ui-radius-sm) + 1px + 3px * var(--_t)));
535
+ background: var(--_fill);
536
+ box-shadow: 0 0 0 var(--_w) var(--_e), 0 1px 2px color-mix(in srgb, var(--ui-gray-1000) 6%, transparent);
537
+ font-size: calc(var(--ui-text-base) + 0.5px * var(--_t));
538
+ cursor: text;
539
+ transition: var(--ui-duration-2) var(--ui-ease-out);
540
+ transition-property: box-shadow, background;
541
+ }
542
+ @media (hover: hover) { .box:hover { --_e: var(--ui-text-field-edge-hover, color-mix(in srgb, var(--ui-text) 18%, transparent)); } }
543
+ .box:focus-within, :host([data-open]) .box { --_w: 1px; --_e: var(--ui-text-field-edge-focus, var(--ui-border-input)); }
544
+ :host([data-invalid]) .box {
545
+ --_w: 1px;
546
+ --_e: color-mix(in srgb, var(--ui-danger) 55%, transparent);
547
+ --_fill: color-mix(in srgb, var(--ui-danger-soft) calc(50% * var(--_t)), var(--ui-bg-surface));
548
+ }
549
+ :host([data-invalid]) .box:focus-within { --_e: var(--ui-danger); }
550
+ :host([data-disabled]) { opacity: var(--ui-disabled-opacity); }
551
+ :host([data-disabled]) .box { cursor: not-allowed; --_e: var(--ui-hairline); }
552
+ :host([data-disabled]) .chev { opacity: 1; }
553
+ .box[data-nudge] { animation: ui-nudge calc(var(--ui-duration-4) * 1.07) var(--ui-ease-out); }
554
+ .clock { inline-size: var(--ui-icon-md); block-size: var(--ui-icon-md); color: var(--ui-icon); stroke-width: calc(var(--ui-icon-stroke) * 0.85); }
555
+ .chev svg { inline-size: var(--ui-icon-sm); block-size: var(--ui-icon-sm); transition: rotate calc(var(--ui-duration-4) * 0.8) var(--ui-ease-out); }
556
+ :host([data-open]) .chev svg { rotate: 180deg; }
557
+ .foot { padding-inline: calc(2px * var(--_t)); }
558
+ p { margin: 0; }
559
+ :host([data-invalid]) p { color: var(--ui-danger); }
560
+ @media (pointer: coarse) {
561
+ :host { --_h: calc(var(--_ht) + 2px * var(--_t)); }
562
+ .box { font-size: var(--ui-text-field-touch); }
563
+ .chev { --_s: calc(var(--ui-space-8) + 2px * var(--_t)); touch-action: manipulation; }
564
+ }
565
+ @media (forced-colors: active) {
566
+ .box { border-color: CanvasText; }
567
+ .box:focus-within, :host([data-open]) .box { outline: 2px solid Highlight; }
568
+ :host([data-invalid]) .box { outline: 1px solid CanvasText; }
569
+ }
570
+ `,
571
+ })
572
+ export class UiTimePicker {
573
+ /** Shown above the field, and the name of the field and of its list. Clicking it focuses the field. */
574
+ readonly label = input<string>();
575
+ /** A quiet line under the field. The error takes its place while there is one. */
576
+ readonly hint = input<string>();
577
+ /** Marks the field invalid and shows this message where the hint was. */
578
+ readonly error = input<string | null | undefined>();
579
+ /** 28, 32 or 36px tall; Classic 32, 36 or 40px. Taller, with 16px text, on touch screens. */
580
+ readonly size = input<TimePickerSize>('md');
581
+ /** Adds "Optional" after the label. */
582
+ readonly optional = input(false, { transform: booleanAttribute });
583
+ /** Earliest time, "HH:mm", when the input has none: use it with `[formField]`, which keeps `min` off the input. */
584
+ readonly min = input<string | null, unknown>(null, { transform: asTime });
585
+ /** Latest time, "HH:mm", when the input has none. */
586
+ readonly max = input<string | null, unknown>(null, { transform: asTime });
587
+ /** Words to translate: the "Optional" tag and the list button's name. */
588
+ readonly labels = input<Partial<TimePickerLabels>>({});
589
+
590
+ readonly control = contentChild(UiTimeInput);
591
+ protected readonly sizes = SIZES;
592
+ protected readonly t = computed(() => ({ ...LABELS, ...this.labels() }));
593
+ private readonly uid = nextId++;
594
+ readonly listId = `ui-time-picker-list-${this.uid}`;
595
+ protected readonly labelId = `ui-time-picker-label-${this.uid}`;
596
+ protected readonly buttonId = `ui-time-picker-button-${this.uid}`;
597
+ protected readonly messageId = `ui-time-picker-msg-${this.uid}`;
598
+
599
+ readonly invalid = computed(() => !!this.error());
600
+ protected readonly message = computed(() => this.error() || this.hint() || '');
601
+ readonly describers = computed(() => (this.message() ? [this.messageId] : []));
602
+ readonly open = computed(() => !!this.control()?.open());
603
+ readonly rows = computed(() => this.control()?.rows() ?? []);
604
+ readonly chosen = computed(() => this.control()?.chosen() ?? null);
605
+ readonly active = signal(-1, { equal: () => false });
606
+ readonly activeId = computed(() => (this.rows()[this.active()] ? `${this.listId}-${this.active()}` : null));
607
+ protected readonly kbd = signal(false);
608
+ protected readonly nudge = signal(false);
609
+
610
+ private readonly box = viewChild.required<ElementRef<HTMLElement>>('box');
611
+ private readonly panel = viewChild.required('panel', { read: ElementRef<HTMLElement> });
612
+ private readonly msg = viewChild<ElementRef<HTMLElement>>('msg');
613
+ private readonly doc = inject(DOCUMENT);
614
+ private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
615
+ private readonly browser = isPlatformBrowser(inject(PLATFORM_ID));
616
+ private overlay?: TimeOverlay;
617
+ private fresh = false;
618
+ private primed = false;
619
+ private typing = false;
620
+ private scroll: Scroll = 'center';
621
+ private pointer = '';
622
+
623
+ constructor() {
624
+ const destroy = inject(DestroyRef);
625
+ let was: boolean | undefined;
626
+ effect(() => {
627
+ const now = this.invalid();
628
+ if (now && was === false) this.nudge.set(true);
629
+ was = now;
630
+ });
631
+ effect(() => {
632
+ if (this.control()?.disabled()) untracked(() => this.close());
633
+ });
634
+ let shown: string | undefined;
635
+ afterRenderEffect(() => {
636
+ const text = this.message();
637
+ const p = this.msg()?.nativeElement;
638
+ const motion = this.motion();
639
+ if (shown !== undefined && text !== shown && p?.animate && motion) {
640
+ p.animate([{ opacity: 0, filter: 'blur(2px)', transform: 'translateY(-2px)' }, {}], { duration: 260 * motion, easing: 'ease-out' });
641
+ }
642
+ shown = text;
643
+ });
644
+ afterRenderEffect(() => {
645
+ const on = this.open();
646
+ untracked(() => this.sync(on));
647
+ });
648
+ afterRenderEffect(() => {
649
+ const i = this.active();
650
+ if (this.open()) untracked(() => this.glide(i));
651
+ });
652
+ afterNextRender(() => {
653
+ const el = this.control()?.el;
654
+ if (isDevMode() && el && !this.label() && !el.hasAttribute('aria-label') && !el.hasAttribute('aria-labelledby')) {
655
+ console.warn('ui-time-picker: give it a label, or an aria-label on the input.', el);
656
+ }
657
+ });
658
+ destroy.onDestroy(() => this.overlay?.hide(false));
659
+ }
660
+
661
+ /** Opens the list on the chosen time, else the next listed time from now. `keyboard` shows the ring on the active row. */
662
+ show(keyboard: boolean) {
663
+ const c = this.control();
664
+ if (!c || c.disabled()) return;
665
+ this.kbd.set(keyboard);
666
+ if (!c.open()) this.prime();
667
+ c.open.set(true);
668
+ }
669
+
670
+ close() {
671
+ this.control()?.open.set(false);
672
+ }
673
+
674
+ toggle() {
675
+ if (this.open()) return this.close();
676
+ this.control()?.el.focus();
677
+ this.show(false);
678
+ }
679
+
680
+ clicked() {
681
+ if (!this.open()) this.show(false);
682
+ }
683
+
684
+ pick(v: string) {
685
+ this.control()?.choose(v);
686
+ this.close();
687
+ }
688
+
689
+ hover(i: number, event: PointerEvent) {
690
+ const at = `${event.clientX},${event.clientY}`;
691
+ if (at === this.pointer) return;
692
+ this.pointer = at;
693
+ this.kbd.set(false);
694
+ this.go(i, 'none');
695
+ }
696
+
697
+ /** While typing: the list jumps to what the text reads as so far. */
698
+ typed(text: string) {
699
+ const c = this.control();
700
+ if (!c || c.disabled()) return;
701
+ if (!c.open()) this.show(true);
702
+ this.kbd.set(true);
703
+ this.typing = true;
704
+ const i = c.match(text);
705
+ if (i >= 0) this.go(i, 'near');
706
+ }
707
+
708
+ key(e: KeyboardEvent) {
709
+ const c = this.control();
710
+ if (!c || c.disabled() || e.isComposing) return;
711
+ const open = c.open();
712
+ const rows = this.rows();
713
+ const move = (by: number) => {
714
+ e.preventDefault();
715
+ if (!open) return this.show(true);
716
+ this.kbd.set(true);
717
+ this.typing = false;
718
+ this.go(Math.min(rows.length - 1, Math.max(0, this.active() + by)), 'near');
719
+ };
720
+ switch (e.key) {
721
+ case 'ArrowDown':
722
+ case 'ArrowUp':
723
+ return move(e.key === 'ArrowDown' ? 1 : -1);
724
+ case 'PageDown':
725
+ case 'PageUp':
726
+ if (open) move(Math.max(1, Math.round(60 / c.step())) * (e.key === 'PageDown' ? 1 : -1));
727
+ return;
728
+ case 'Enter':
729
+ if (!open) return c.dirty() ? c.commit() : undefined;
730
+ e.preventDefault();
731
+ if (this.typing && c.dirty()) c.commit();
732
+ else if (rows[this.active()]) c.choose(rows[this.active()].v);
733
+ return this.close();
734
+ case 'Escape':
735
+ if (open || !c.dirty()) return;
736
+ e.preventDefault();
737
+ e.stopPropagation();
738
+ return c.revert();
739
+ case 'Tab':
740
+ return this.close();
741
+ }
742
+ }
743
+
744
+ protected focusInput(event: MouseEvent) {
745
+ event.preventDefault();
746
+ this.control()?.el.focus();
747
+ }
748
+
749
+ /** Presses on the box, the icon or the button keep focus in the input. */
750
+ protected press(event: PointerEvent) {
751
+ const el = this.control()?.el;
752
+ if (!el || event.target === el) return;
753
+ event.preventDefault();
754
+ if (!el.disabled) el.focus();
755
+ }
756
+
757
+ private go(i: number, scroll: Scroll) {
758
+ this.scroll = scroll;
759
+ this.active.set(i);
760
+ }
761
+
762
+ /** The chosen row, else the next listed time after the value or after now, else the last. */
763
+ private prime() {
764
+ const c = this.control();
765
+ const rows = this.rows();
766
+ const now = new Date();
767
+ const target = toMinutes(c?.chosen()) ?? now.getHours() * 60 + now.getMinutes();
768
+ const i = rows.findIndex((r) => r.m >= target);
769
+ this.go(i < 0 ? rows.length - 1 : i, 'center');
770
+ this.typing = false;
771
+ this.primed = true;
772
+ }
773
+
774
+ private sync(on: boolean) {
775
+ if (!this.browser) return;
776
+ this.overlay ??= new TimeOverlay(this.panel().nativeElement, this.doc, {
777
+ anchor: () => this.box().nativeElement,
778
+ trigger: () => this.box().nativeElement,
779
+ side: () => 'bottom',
780
+ align: () => 'start',
781
+ offset: () => OFFSET,
782
+ dismiss: () => this.close(),
783
+ });
784
+ if (!on) {
785
+ this.overlay.hide(false);
786
+ this.kbd.set(false);
787
+ this.primed = false;
788
+ this.typing = false;
789
+ return;
790
+ }
791
+ if (!this.primed) this.prime();
792
+ this.primed = false;
793
+ this.fresh = true;
794
+ this.overlay.show(false);
795
+ }
796
+
797
+ /** Slides the soft highlight to the active row and keeps it in view; centered on open. */
798
+ private glide(i: number) {
799
+ const panel = this.panel().nativeElement;
800
+ const glow = panel.firstElementChild as HTMLElement;
801
+ const row = panel.children[i + 1] as HTMLElement | undefined;
802
+ const [fresh, scroll] = [this.fresh, this.scroll];
803
+ this.fresh = false;
804
+ this.scroll = 'near';
805
+ glow.style.opacity = row ? '' : '0';
806
+ if (!row) return;
807
+ if (fresh) glow.style.transition = 'none';
808
+ glow.style.translate = `0 ${row.offsetTop}px`;
809
+ glow.style.blockSize = `${row.offsetHeight}px`;
810
+ if (fresh) {
811
+ void glow.offsetWidth;
812
+ glow.style.transition = '';
813
+ }
814
+ const [top, h, view] = [row.offsetTop, row.offsetHeight, panel.clientHeight];
815
+ if (scroll === 'center') panel.scrollTop = top - (view - h) / 2;
816
+ else if (scroll === 'none') return;
817
+ else if (top < panel.scrollTop) panel.scrollTop = top;
818
+ else if (top + h > panel.scrollTop + view) panel.scrollTop = top + h - view;
819
+ }
820
+
821
+ /** 0 under reduced motion, otherwise the app's motion scale (1 by default). */
822
+ private motion() {
823
+ const view = this.doc.defaultView;
824
+ if (!view?.matchMedia || view.matchMedia('(prefers-reduced-motion: reduce)').matches) return 0;
825
+ const scale = parseFloat(view.getComputedStyle(this.host).getPropertyValue('--ui-motion-scale'));
826
+ return Number.isNaN(scale) ? 1 : scale;
827
+ }
828
+ }