@directo-ui/astro 1.0.0 → 1.2.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 (77) hide show
  1. package/README.md +16 -0
  2. package/components.css +661 -0
  3. package/index.d.ts +31 -31
  4. package/index.js +31 -31
  5. package/package.json +29 -7
  6. package/src/components/Accordion.astro +8 -8
  7. package/src/components/AccordionItem.astro +14 -14
  8. package/src/components/Alert.astro +42 -42
  9. package/src/components/Avatar.astro +21 -21
  10. package/src/components/Badge.astro +13 -13
  11. package/src/components/BottomSheet.astro +23 -23
  12. package/src/components/Breadcrumb.astro +18 -18
  13. package/src/components/Button.astro +31 -31
  14. package/src/components/Card.astro +25 -25
  15. package/src/components/Checkbox.astro +14 -14
  16. package/src/components/DatePicker.astro +25 -25
  17. package/src/components/Divider.astro +11 -11
  18. package/src/components/Dropdown.astro +71 -71
  19. package/src/components/EmptyState.astro +15 -15
  20. package/src/components/IconButton.astro +18 -18
  21. package/src/components/Modal.astro +34 -34
  22. package/src/components/MultiSelect.astro +108 -0
  23. package/src/components/Pagination.astro +30 -30
  24. package/src/components/Progress.astro +20 -20
  25. package/src/components/RadioGroup.astro +24 -24
  26. package/src/components/Select.astro +29 -29
  27. package/src/components/Skeleton.astro +13 -13
  28. package/src/components/Spinner.astro +17 -17
  29. package/src/components/StatusTag.astro +18 -0
  30. package/src/components/Switch.astro +13 -13
  31. package/src/components/Tabs.astro +60 -60
  32. package/src/components/TextField.astro +24 -24
  33. package/src/components/Textarea.astro +41 -41
  34. package/src/components/Toaster.astro +8 -8
  35. package/src/components/Tooltip.astro +31 -31
  36. package/src/components/WariClientDetails.astro +87 -0
  37. package/src/components/WariClientSearch.astro +88 -0
  38. package/src/components/WariDateField.astro +56 -0
  39. package/src/components/WariPassengerField.astro +84 -0
  40. package/src/components/WariRoute.astro +49 -0
  41. package/src/components/WariSchedule.astro +48 -0
  42. package/src/components/WariSelect.astro +76 -0
  43. package/src/components/WariServiceMeta.astro +19 -0
  44. package/src/components/WariStatusSelect.astro +20 -0
  45. package/src/components/WariStepper.astro +45 -0
  46. package/src/components/WariSwitchList.astro +111 -0
  47. package/src/components/WariTimeField.astro +50 -0
  48. package/src/components/WariTripAttributes.astro +60 -0
  49. package/src/modal.d.ts +3 -3
  50. package/src/modal.js +39 -39
  51. package/src/pagination.d.ts +2 -2
  52. package/src/pagination.js +16 -16
  53. package/src/toast.d.ts +9 -9
  54. package/src/toast.js +66 -66
  55. package/src/wari/datetime.d.ts +57 -0
  56. package/src/wari/datetime.js +151 -0
  57. package/src/wari/logic.d.ts +8 -0
  58. package/src/wari/logic.js +41 -0
  59. package/src/wari/motion.d.ts +14 -0
  60. package/src/wari/motion.js +60 -0
  61. package/src/wari/multiselect.d.ts +2 -0
  62. package/src/wari/multiselect.js +169 -0
  63. package/src/wari/pickers.d.ts +2 -0
  64. package/src/wari/pickers.js +369 -0
  65. package/src/wari/route-client.d.ts +10 -0
  66. package/src/wari/route-client.js +270 -0
  67. package/src/wari/route.d.ts +48 -0
  68. package/src/wari/route.js +71 -0
  69. package/src/wari/statuses.d.ts +14 -0
  70. package/src/wari/statuses.js +15 -0
  71. package/src/wari/trip-client.d.ts +4 -0
  72. package/src/wari/trip-client.js +370 -0
  73. package/src/wari/trip.d.ts +107 -0
  74. package/src/wari/trip.js +129 -0
  75. package/styles.css +3 -3
  76. package/wari.d.ts +26 -0
  77. package/wari.js +21 -0
@@ -0,0 +1,369 @@
1
+ // Client behaviour for <WariDateField>, <WariTimeField> and <WariSchedule>. Safe to call many times.
2
+ // Each field emits a bubbling "ds-change" CustomEvent with its value ("YYYY-MM-DD" or "HH:mm") as detail.
3
+ import {
4
+ addMonths, calendarWeeks, dialPoint, dialValue, formatDisplayDate, formatDisplayTime, formatTime24, from12h,
5
+ isDateInRange, longDateLabel, monthNames, pad2, parseDisplayDate, parseDisplayTime, parseISODate, parseTime24,
6
+ shiftDate, shiftMonth, to12h, todayISO, weekdayNames,
7
+ } from './datetime.js';
8
+
9
+ const icon = {
10
+ left: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m14.5 6-6 6 6 6"/></svg>',
11
+ right: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9.5 6 6 6-6 6"/></svg>',
12
+ caret: '<svg width="18" height="18" viewBox="0 0 24 24" aria-hidden="true"><path d="m7 10 5 5 5-5" fill="currentColor"/></svg>',
13
+ check: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12.5 4.5 4.5L19 7.5"/></svg>',
14
+ keyboard: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2.5" y="6" width="19" height="12" rx="2"/><path d="M6 9.5h.01M9 9.5h.01M12 9.5h.01M15 9.5h.01M18 9.5h.01M7 14.5h10"/></svg>',
15
+ clock: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="8.5"/><path d="M12 7.5V12l3 2"/></svg>',
16
+ };
17
+ const escapeHtml = text => String(text).replace(/[&<>"]/g, char => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[char]);
18
+ const pad = (value, size = 2) => String(value).padStart(size, '0');
19
+
20
+ export function initWariFields(scope = document) {
21
+ scope.querySelectorAll('[data-ds-wfield]:not([data-ds-ready])').forEach(root => {
22
+ root.dataset.dsReady = '';
23
+ if (root.dataset.dsWfield === 'time') setupTime(root); else setupDate(root);
24
+ });
25
+ }
26
+
27
+ /** Shared wiring: text input, hidden value, trigger, outside click and change events. */
28
+ function base(root, { format, parse, triggerLabel }) {
29
+ const input = root.querySelector('.ds-input-shell > input');
30
+ const trigger = root.querySelector('.ds-wfield-trigger');
31
+ const anchor = root.querySelector('.ds-wfield-anchor');
32
+ const hidden = root.querySelector('[data-ds-value]');
33
+ let popover = null;
34
+ let editing = false;
35
+
36
+ const field = {
37
+ input, trigger, anchor,
38
+ get value() { return hidden.value; },
39
+ set(next) {
40
+ input.value = format(next);
41
+ trigger.setAttribute('aria-label', triggerLabel(next));
42
+ if (next === hidden.value) return;
43
+ hidden.value = next;
44
+ root.dispatchEvent(new CustomEvent('ds-change', { detail: next, bubbles: true }));
45
+ },
46
+ get open() { return Boolean(popover); },
47
+ mount(element) {
48
+ popover = element;
49
+ anchor.append(element);
50
+ root.dataset.open = 'true';
51
+ trigger.setAttribute('aria-expanded', 'true');
52
+ },
53
+ close(returnFocus = true) {
54
+ if (!popover) return;
55
+ popover.remove();
56
+ popover = null;
57
+ root.dataset.open = 'false';
58
+ trigger.setAttribute('aria-expanded', 'false');
59
+ if (returnFocus) trigger.focus();
60
+ },
61
+ };
62
+
63
+ const commitText = () => {
64
+ if (!editing) return;
65
+ editing = false;
66
+ if (!input.value.trim()) { field.set(''); return; }
67
+ const parsed = parse(input.value);
68
+ if (parsed) field.set(parsed); else input.value = format(hidden.value);
69
+ };
70
+ input.addEventListener('focus', () => { editing = true; });
71
+ input.addEventListener('blur', commitText);
72
+ input.addEventListener('keydown', event => {
73
+ if (event.key === 'Enter') { event.preventDefault(); commitText(); }
74
+ if (event.key === 'ArrowDown' && (event.altKey || !field.open)) { event.preventDefault(); commitText(); field.onOpen(); }
75
+ });
76
+ trigger.addEventListener('click', () => (field.open ? field.close() : field.onOpen()));
77
+ // Only when focus moves to another element outside: re-rendering the calendar replaces the focused button,
78
+ // which fires focusout without a relatedTarget. Outside clicks are handled by pointerdown.
79
+ root.addEventListener('focusout', event => { if (field.open && event.relatedTarget && !root.contains(event.relatedTarget)) field.close(false); });
80
+ document.addEventListener('pointerdown', event => { if (field.open && !root.contains(event.target)) field.close(false); });
81
+ return field;
82
+ }
83
+
84
+ function setupDate(root) {
85
+ const { min = '', max = '', locale = 'es', cancelLabel = 'Cancelar', okLabel = 'Aceptar' } = root.dataset;
86
+ const weekStartsOn = Number(root.dataset.weekStart ?? 0) === 1 ? 1 : 0;
87
+ const today = todayISO();
88
+ const clamp = iso => (min && iso < min ? min : max && iso > max ? max : iso);
89
+ const field = base(root, {
90
+ format: formatDisplayDate,
91
+ parse: text => { const iso = parseDisplayDate(text); return iso && isDateInRange(iso, min, max) ? iso : null; },
92
+ triggerLabel: value => `Elegir fecha${value ? `, ${longDateLabel(value, locale)}` : ''}`,
93
+ });
94
+ const months = monthNames(locale, 'long');
95
+ const shortMonths = monthNames(locale, 'short');
96
+ const weekdays = weekdayNames(locale, weekStartsOn);
97
+ const weekdayLong = weekdayNames(locale, weekStartsOn, 'long');
98
+ let state;
99
+
100
+ const minYear = () => parseISODate(min)?.year ?? state.year - 50;
101
+ const maxYear = () => parseISODate(max)?.year ?? state.year + 50;
102
+
103
+ function html() {
104
+ const { year, month, view, draft, focused } = state;
105
+ const prev = addMonths(year, month, -1);
106
+ const next = addMonths(year, month, 1);
107
+ const prevDisabled = (min && `${prev.year}-${pad(prev.month + 1)}-31` < min) || view !== 'days';
108
+ const nextDisabled = (max && `${next.year}-${pad(next.month + 1)}-01` > max) || view !== 'days';
109
+ const nav = (part, prevAction, nextAction, label, text, prevOff, nextOff, expanded) => `
110
+ <div class="ds-wpicker-nav" data-part="${part}">
111
+ <button type="button" class="ds-wpicker-icon" data-action="${prevAction}" aria-label="${part === 'month' ? 'Mes anterior' : 'Año anterior'}" ${prevOff ? 'disabled' : ''}>${icon.left}</button>
112
+ <button type="button" class="ds-wpicker-menu" data-action="view-${part}s" aria-haspopup="listbox" aria-expanded="${expanded}" aria-label="${escapeHtml(label)}">${escapeHtml(text)}${icon.caret}</button>
113
+ <button type="button" class="ds-wpicker-icon" data-action="${nextAction}" aria-label="${part === 'month' ? 'Mes siguiente' : 'Año siguiente'}" ${nextOff ? 'disabled' : ''}>${icon.right}</button>
114
+ </div>`;
115
+ let body = '';
116
+ if (view === 'days') {
117
+ body = `<table class="ds-wpicker-grid" role="grid" aria-label="${escapeHtml(`${months[month]} ${year}`)}">
118
+ <thead><tr>${weekdays.map((day, i) => `<th scope="col" abbr="${escapeHtml(weekdayLong[i])}">${escapeHtml(day)}</th>`).join('')}</tr></thead>
119
+ <tbody>${calendarWeeks(year, month, weekStartsOn).map(week => `<tr>${week.map(day => {
120
+ const blocked = !isDateInRange(day.iso, min, max);
121
+ return `<td><button type="button" class="ds-wpicker-day" data-action="day" data-iso="${day.iso}" data-outside="${day.outside}" data-today="${day.iso === today}"
122
+ aria-selected="${day.iso === draft}" ${blocked ? 'aria-disabled="true"' : ''} aria-label="${escapeHtml(longDateLabel(day.iso, locale))}" tabindex="${day.iso === focused ? 0 : -1}">${day.day}</button></td>`;
123
+ }).join('')}</tr>`).join('')}</tbody></table>`;
124
+ } else if (view === 'months') {
125
+ body = `<div class="ds-wpicker-list" role="listbox" aria-label="Meses">${months.map((name, i) => `<button type="button" role="option" class="ds-wpicker-option" data-action="month" data-value="${i}" aria-selected="${i === month}" tabindex="${i === month ? 0 : -1}">${icon.check}${escapeHtml(name)}</button>`).join('')}</div>`;
126
+ } else {
127
+ const years = Array.from({ length: maxYear() - minYear() + 1 }, (_, i) => minYear() + i);
128
+ body = `<div class="ds-wpicker-list" role="listbox" aria-label="Años">${years.map(y => `<button type="button" role="option" class="ds-wpicker-option" data-action="year" data-value="${y}" aria-selected="${y === year}" tabindex="${y === year ? 0 : -1}">${icon.check}${y}</button>`).join('')}</div>`;
129
+ }
130
+ return `<div class="ds-wpicker-head">
131
+ ${nav('month', 'prev-month', 'next-month', `Elegir mes, ${months[month]}`, shortMonths[month], prevDisabled, nextDisabled, view === 'months')}
132
+ ${nav('year', 'prev-year', 'next-year', `Elegir año, ${year}`, year, year - 1 < minYear() || view !== 'days', year + 1 > maxYear() || view !== 'days', view === 'years')}
133
+ </div>${body}
134
+ <div class="ds-wpicker-actions">
135
+ <button type="button" class="ds-wpicker-action" data-action="cancel">${escapeHtml(cancelLabel)}</button>
136
+ <button type="button" class="ds-wpicker-action" data-action="ok">${escapeHtml(okLabel)}</button>
137
+ </div>`;
138
+ }
139
+
140
+ let popover;
141
+ function render(moveFocus = true) {
142
+ popover.dataset.view = state.view;
143
+ popover.innerHTML = html();
144
+ if (!moveFocus) return;
145
+ const target = state.view === 'days'
146
+ ? popover.querySelector(`[data-iso="${state.focused}"]`)
147
+ : popover.querySelector('.ds-wpicker-option[tabindex="0"]');
148
+ target?.focus();
149
+ if (state.view !== 'days') target?.scrollIntoView?.({ block: 'center' });
150
+ }
151
+ const focusDay = iso => {
152
+ const target = clamp(iso);
153
+ const parts = parseISODate(target);
154
+ state = { ...state, focused: target, year: parts.year, month: parts.month };
155
+ render();
156
+ };
157
+
158
+ field.onOpen = () => {
159
+ if (field.input.disabled) return;
160
+ const current = parseISODate(field.value) ? field.value : '';
161
+ const start = clamp(current || today);
162
+ const parts = parseISODate(start);
163
+ state = { year: parts.year, month: parts.month, view: 'days', draft: current, focused: start };
164
+ popover = document.createElement('div');
165
+ popover.className = 'ds-wpicker';
166
+ popover.dataset.kind = 'date';
167
+ popover.setAttribute('role', 'dialog');
168
+ popover.setAttribute('aria-label', 'Elegir fecha');
169
+ field.mount(popover);
170
+ render();
171
+
172
+ popover.addEventListener('click', event => {
173
+ const button = event.target.closest('[data-action]');
174
+ if (!button || button.disabled) return;
175
+ const action = button.dataset.action;
176
+ const value = button.dataset.value;
177
+ const moveBy = delta => { const n = addMonths(state.year, state.month, delta); state = { ...state, ...n }; render(false); };
178
+ if (action === 'prev-month') moveBy(-1);
179
+ else if (action === 'next-month') moveBy(1);
180
+ else if (action === 'prev-year') moveBy(-12);
181
+ else if (action === 'next-year') moveBy(12);
182
+ else if (action === 'view-months' || action === 'view-years') {
183
+ const view = action === 'view-months' ? 'months' : 'years';
184
+ state = { ...state, view: state.view === view ? 'days' : view };
185
+ render();
186
+ } else if (action === 'month' || action === 'year') {
187
+ const year = action === 'year' ? Number(value) : state.year;
188
+ const month = action === 'month' ? Number(value) : state.month;
189
+ const day = parseISODate(state.focused)?.day ?? 1;
190
+ const last = new Date(year, month + 1, 0).getDate();
191
+ state = { ...state, year, month, view: 'days', focused: clamp(`${pad(year, 4)}-${pad(month + 1)}-${pad(Math.min(day, last))}`) };
192
+ render();
193
+ } else if (action === 'day') {
194
+ if (button.getAttribute('aria-disabled') === 'true') return;
195
+ state = { ...state, draft: button.dataset.iso };
196
+ focusDay(button.dataset.iso);
197
+ } else if (action === 'cancel') field.close();
198
+ else if (action === 'ok') { if (state.draft) field.set(state.draft); field.close(); }
199
+ });
200
+
201
+ popover.addEventListener('keydown', event => {
202
+ if (event.key === 'Escape') {
203
+ event.preventDefault();
204
+ event.stopPropagation();
205
+ if (state.view !== 'days') { state = { ...state, view: 'days' }; render(); } else field.close();
206
+ return;
207
+ }
208
+ if (event.target.matches('.ds-wpicker-day')) {
209
+ const f = state.focused;
210
+ const weekday = (new Date(`${f}T00:00`).getDay() - weekStartsOn + 7) % 7;
211
+ const moves = {
212
+ ArrowLeft: () => shiftDate(f, -1), ArrowRight: () => shiftDate(f, 1), ArrowUp: () => shiftDate(f, -7), ArrowDown: () => shiftDate(f, 7),
213
+ PageUp: () => shiftMonth(f, event.shiftKey ? -12 : -1), PageDown: () => shiftMonth(f, event.shiftKey ? 12 : 1),
214
+ Home: () => shiftDate(f, -weekday), End: () => shiftDate(f, 6 - weekday),
215
+ };
216
+ if (moves[event.key]) { event.preventDefault(); focusDay(moves[event.key]()); }
217
+ } else if (event.target.matches('.ds-wpicker-option')) {
218
+ const options = [...popover.querySelectorAll('.ds-wpicker-option')];
219
+ const index = options.indexOf(event.target);
220
+ const next = { ArrowDown: index + 1, ArrowUp: index - 1, Home: 0, End: options.length - 1 }[event.key];
221
+ if (next !== undefined) { event.preventDefault(); options[Math.max(0, Math.min(next, options.length - 1))]?.focus(); }
222
+ }
223
+ });
224
+ };
225
+ }
226
+
227
+ function setupTime(root) {
228
+ const { title = 'Selecciona la hora', cancelLabel = 'Cancelar', okLabel = 'Aceptar' } = root.dataset;
229
+ const DIAL = 256, CENTER = 128, RADIUS = 100;
230
+ const HOURS = [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
231
+ const MINUTES = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55];
232
+ const field = base(root, {
233
+ format: formatDisplayTime,
234
+ parse: parseDisplayTime,
235
+ triggerLabel: value => `Elegir hora${value ? `, ${formatDisplayTime(value)}` : ''}`,
236
+ });
237
+
238
+ field.onOpen = () => {
239
+ if (field.input.disabled) return;
240
+ const parts = parseTime24(field.value) ?? { hours: 12, minutes: 0 };
241
+ const twelve = to12h(parts.hours);
242
+ const state = { hour: twelve.hour, minute: parts.minutes, period: twelve.period, mode: 'hour', input: 'dial' };
243
+
244
+ const popover = document.createElement('div');
245
+ popover.className = 'ds-wpicker';
246
+ popover.dataset.kind = 'time';
247
+ popover.dataset.input = 'dial';
248
+ popover.setAttribute('role', 'dialog');
249
+ popover.setAttribute('aria-label', title);
250
+ popover.innerHTML = `<div class="ds-wpicker-title">${escapeHtml(title)}</div>
251
+ <div class="ds-wtime-body">
252
+ <div class="ds-wtime-inputs">
253
+ <div class="ds-wtime-fields">
254
+ <input class="ds-wtime-box" data-kind="hour" inputmode="numeric" aria-label="Hora" />
255
+ <span class="ds-wtime-sep" aria-hidden="true">:</span>
256
+ <input class="ds-wtime-box" data-kind="minute" inputmode="numeric" aria-label="Minutos" />
257
+ </div>
258
+ <div class="ds-wtime-period" role="group" aria-label="AM o PM">
259
+ <button type="button" data-period="AM">AM</button><button type="button" data-period="PM">PM</button>
260
+ </div>
261
+ </div>
262
+ <div class="ds-wtime-dial" aria-hidden="true"><span class="ds-wtime-hand" style="width:${RADIUS}px"></span><span class="ds-wtime-center"></span></div>
263
+ </div>
264
+ <div class="ds-wpicker-actions">
265
+ <button type="button" class="ds-wpicker-mode" data-action="mode"></button>
266
+ <span class="ds-wpicker-actions-spacer"></span>
267
+ <button type="button" class="ds-wpicker-action" data-action="cancel">${escapeHtml(cancelLabel)}</button>
268
+ <button type="button" class="ds-wpicker-action" data-action="ok">${escapeHtml(okLabel)}</button>
269
+ </div>`;
270
+ field.mount(popover);
271
+
272
+ const hourBox = popover.querySelector('[data-kind="hour"]');
273
+ const minuteBox = popover.querySelector('[data-kind="minute"]');
274
+ const dial = popover.querySelector('.ds-wtime-dial');
275
+ const hand = popover.querySelector('.ds-wtime-hand');
276
+ const modeButton = popover.querySelector('[data-action="mode"]');
277
+
278
+ // `typing` is the box whose input event is being handled: it formats its own value.
279
+ const update = typing => {
280
+ if (typing !== hourBox) hourBox.value = pad2(state.hour);
281
+ if (typing !== minuteBox) minuteBox.value = pad2(state.minute);
282
+ hourBox.dataset.active = String(state.mode === 'hour');
283
+ minuteBox.dataset.active = String(state.mode === 'minute');
284
+ popover.querySelectorAll('[data-period]').forEach(b => b.setAttribute('aria-pressed', String(b.dataset.period === state.period)));
285
+ popover.dataset.input = state.input;
286
+ // Only when the mode changes: replacing the icon mid-click would swallow the click event.
287
+ if (modeButton.dataset.mode !== state.input) {
288
+ modeButton.dataset.mode = state.input;
289
+ modeButton.setAttribute('aria-label', state.input === 'dial' ? 'Escribir la hora' : 'Usar el reloj');
290
+ modeButton.innerHTML = state.input === 'dial' ? icon.keyboard : icon.clock;
291
+ }
292
+ const numbers = state.mode === 'hour' ? HOURS : MINUTES;
293
+ const selected = state.mode === 'hour' ? state.hour : state.minute;
294
+ dial.querySelectorAll('.ds-wtime-num').forEach(n => n.remove());
295
+ numbers.forEach(n => {
296
+ const point = dialPoint(n, state.mode === 'hour' ? 12 : 60, RADIUS, CENTER);
297
+ const span = document.createElement('span');
298
+ span.className = 'ds-wtime-num';
299
+ span.dataset.selected = String(n === selected);
300
+ span.style.left = `${(point.x / DIAL) * 100}%`;
301
+ span.style.top = `${(point.y / DIAL) * 100}%`;
302
+ span.textContent = state.mode === 'hour' ? String(n) : pad2(n);
303
+ dial.append(span);
304
+ });
305
+ hand.style.transform = `rotate(${(state.mode === 'hour' ? (state.hour % 12) * 30 : state.minute * 6) - 90}deg)`;
306
+ };
307
+ const accept = () => { field.set(formatTime24(from12h(state.hour, state.period), state.minute)); field.close(); };
308
+ const focusMinutes = () => { state.mode = 'minute'; update(); minuteBox.focus(); minuteBox.select(); };
309
+
310
+ for (const box of [hourBox, minuteBox]) {
311
+ const kind = box.dataset.kind;
312
+ box.addEventListener('focus', () => { state.mode = kind; update(); box.select(); });
313
+ box.addEventListener('blur', update);
314
+ box.addEventListener('keydown', event => {
315
+ const delta = event.key === 'ArrowUp' ? 1 : event.key === 'ArrowDown' ? -1 : 0;
316
+ if (delta) {
317
+ event.preventDefault();
318
+ if (kind === 'hour') state.hour = ((state.hour - 1 + delta + 12) % 12) + 1;
319
+ else state.minute = (state.minute + delta + 60) % 60;
320
+ box.value = pad2(kind === 'hour' ? state.hour : state.minute);
321
+ update();
322
+ }
323
+ if (event.key === 'Enter') { event.preventDefault(); accept(); }
324
+ });
325
+ box.addEventListener('input', () => {
326
+ const digits = box.value.replace(/\D/g, '').slice(-2);
327
+ if (digits) {
328
+ const number = Number(digits);
329
+ if (kind === 'hour') {
330
+ if (number >= 1 && number <= 12) state.hour = number;
331
+ else if (number > 12 && Number(digits.slice(-1)) >= 1) state.hour = Number(digits.slice(-1));
332
+ box.value = pad2(state.hour);
333
+ if (digits.length === 2 || number > 1) { focusMinutes(); return; }
334
+ } else state.minute = number <= 59 ? number : Number(digits.slice(-1));
335
+ }
336
+ box.value = pad2(kind === 'hour' ? state.hour : state.minute);
337
+ update(box);
338
+ });
339
+ }
340
+
341
+ let dragging = false;
342
+ const fromPointer = event => {
343
+ const rect = dial.getBoundingClientRect();
344
+ const scale = DIAL / rect.width;
345
+ const value = dialValue((event.clientX - rect.left) * scale, (event.clientY - rect.top) * scale, CENTER, state.mode);
346
+ if (state.mode === 'hour') state.hour = value; else state.minute = value;
347
+ update();
348
+ };
349
+ dial.addEventListener('pointerdown', event => { dragging = true; dial.setPointerCapture?.(event.pointerId); event.preventDefault(); fromPointer(event); });
350
+ dial.addEventListener('pointermove', event => { if (dragging) fromPointer(event); });
351
+ dial.addEventListener('pointerup', () => { dragging = false; if (state.mode === 'hour') focusMinutes(); });
352
+
353
+ popover.addEventListener('click', event => {
354
+ const period = event.target.closest('[data-period]');
355
+ if (period) { state.period = period.dataset.period; update(); return; }
356
+ const action = event.target.closest('[data-action]')?.dataset.action;
357
+ if (action === 'mode') { state.input = state.input === 'dial' ? 'keyboard' : 'dial'; update(); }
358
+ else if (action === 'cancel') field.close();
359
+ else if (action === 'ok') accept();
360
+ });
361
+ popover.addEventListener('keydown', event => {
362
+ if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); field.close(); }
363
+ });
364
+
365
+ update();
366
+ hourBox.focus();
367
+ hourBox.select();
368
+ };
369
+ }
@@ -0,0 +1,10 @@
1
+ import type { WariRouteValue } from './route';
2
+ export interface WariRouteOptions {
3
+ title?: string; headingLevel?: 2 | 3 | 4; maxStops?: number; maxTolls?: number; showPassengers?: boolean; showTolls?: boolean;
4
+ disabled?: boolean; invertingLabel?: string; invertedMessage?: string; routePassengerNote?: string; inverting?: boolean; inverted?: boolean;
5
+ }
6
+ export declare const routeDefaults: Required<Omit<WariRouteOptions, 'inverting' | 'inverted'>>;
7
+ /** HTML interno de la tarjeta de ruta (el mismo que React y Angular). */
8
+ export declare function routeHtml(value: Partial<WariRouteValue> | null | undefined, options?: WariRouteOptions, baseId?: string): string;
9
+ /** Inicializa las tarjetas <WariRoute>. Idempotente. Cada tarjeta expone dsSetValue(ruta) y dsGetValue(). */
10
+ export declare function initWariRoute(scope?: ParentNode): void;