@directo-ui/astro 1.0.0 → 1.1.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 (67) hide show
  1. package/README.md +14 -0
  2. package/components.css +326 -0
  3. package/index.d.ts +31 -31
  4. package/index.js +31 -31
  5. package/package.json +19 -1
  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/WariDateField.astro +56 -0
  37. package/src/components/WariSchedule.astro +48 -0
  38. package/src/components/WariSelect.astro +76 -0
  39. package/src/components/WariServiceMeta.astro +19 -0
  40. package/src/components/WariStatusSelect.astro +20 -0
  41. package/src/components/WariStepper.astro +40 -0
  42. package/src/components/WariSwitchList.astro +33 -0
  43. package/src/components/WariTimeField.astro +50 -0
  44. package/src/components/WariTripAttributes.astro +60 -0
  45. package/src/modal.d.ts +3 -3
  46. package/src/modal.js +39 -39
  47. package/src/pagination.d.ts +2 -2
  48. package/src/pagination.js +16 -16
  49. package/src/toast.d.ts +9 -9
  50. package/src/toast.js +66 -66
  51. package/src/wari/datetime.d.ts +57 -0
  52. package/src/wari/datetime.js +151 -0
  53. package/src/wari/logic.d.ts +8 -0
  54. package/src/wari/logic.js +41 -0
  55. package/src/wari/multiselect.d.ts +2 -0
  56. package/src/wari/multiselect.js +169 -0
  57. package/src/wari/pickers.d.ts +2 -0
  58. package/src/wari/pickers.js +369 -0
  59. package/src/wari/statuses.d.ts +14 -0
  60. package/src/wari/statuses.js +15 -0
  61. package/src/wari/trip-client.d.ts +4 -0
  62. package/src/wari/trip-client.js +222 -0
  63. package/src/wari/trip.d.ts +56 -0
  64. package/src/wari/trip.js +69 -0
  65. package/styles.css +3 -3
  66. package/wari.d.ts +20 -0
  67. package/wari.js +16 -0
@@ -0,0 +1,50 @@
1
+ ---
2
+ import { formatDisplayTime } from '../wari/datetime.js';
3
+
4
+ export interface Props {
5
+ label?: string;
6
+ /** Hora inicial "HH:mm" (24 h). */
7
+ value?: string;
8
+ /** Nombre del campo enviado en el <form> (valor "HH:mm"). */
9
+ name?: string;
10
+ id?: string;
11
+ placeholder?: string;
12
+ supportingText?: string;
13
+ error?: boolean;
14
+ required?: boolean;
15
+ disabled?: boolean;
16
+ title?: string;
17
+ cancelLabel?: string;
18
+ okLabel?: string;
19
+ align?: 'start' | 'end';
20
+ class?: string;
21
+ }
22
+
23
+ const {
24
+ label, value = '', name, placeholder = 'hh:mm', supportingText, error = false, required = false, disabled = false,
25
+ title = 'Selecciona la hora', cancelLabel = 'Cancelar', okLabel = 'Aceptar', align = 'start', class: className,
26
+ } = Astro.props;
27
+ const id = Astro.props.id ?? `ds-wtime-${Math.random().toString(36).slice(2, 9)}`;
28
+ ---
29
+ <div class:list={['ds-input', 'ds-wfield', className]} data-ds-wfield="time" data-open="false" data-align={align}
30
+ data-error={String(error)} data-disabled={String(disabled)} data-title={title} data-cancel-label={cancelLabel} data-ok-label={okLabel}>
31
+ {label && <label for={id}>{label}{required && <span class="ds-input-required" aria-hidden="true">*</span>}</label>}
32
+ <div class="ds-wfield-anchor">
33
+ <div class="ds-input-shell">
34
+ <input id={id} type="text" autocomplete="off" placeholder={placeholder} value={formatDisplayTime(value)}
35
+ disabled={disabled} required={required} aria-invalid={error ? 'true' : undefined} aria-describedby={supportingText ? `${id}-hint` : undefined} />
36
+ <button type="button" class="ds-wfield-trigger" disabled={disabled} aria-haspopup="dialog" aria-expanded="false"
37
+ aria-label={`Elegir hora${value ? `, ${formatDisplayTime(value)}` : ''}`}>
38
+ <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>
39
+ </button>
40
+ </div>
41
+ </div>
42
+ {supportingText && <small id={`${id}-hint`}>{supportingText}</small>}
43
+ <input type="hidden" name={name} value={value} data-ds-value />
44
+ </div>
45
+
46
+ <script>
47
+ import { initWariFields } from '../wari/pickers.js';
48
+ initWariFields();
49
+ document.addEventListener('astro:page-load', () => initWariFields());
50
+ </script>
@@ -0,0 +1,60 @@
1
+ ---
2
+ import WariSelect from './WariSelect.astro';
3
+ import WariStepper from './WariStepper.astro';
4
+ import WariSwitchList from './WariSwitchList.astro';
5
+ import { defaultTripAttributes, wariExtras, wariPaymentMethods, wariServices } from '../wari/trip.js';
6
+ import type { WariOption, WariService, WariTripAttributesValue } from '../wari/trip';
7
+
8
+ interface Props {
9
+ title?: string;
10
+ headingLevel?: 2 | 3 | 4;
11
+ value?: Partial<WariTripAttributesValue>;
12
+ services?: WariService[];
13
+ extras?: WariOption[];
14
+ paymentMethods?: WariOption[];
15
+ maxVehicles?: number;
16
+ /** Prefijo de los campos del <form>: name.service, name.mode, name.extras, name.vehicles, name.payment. */
17
+ name?: string;
18
+ disabled?: boolean;
19
+ serviceLabel?: string;
20
+ vehiclesLabel?: string;
21
+ paymentLabel?: string;
22
+ hourlyLabel?: string;
23
+ deliveryLabel?: string;
24
+ class?: string;
25
+ }
26
+
27
+ const {
28
+ title = 'Atributos del viaje', headingLevel = 3, services = wariServices, extras = wariExtras, paymentMethods = wariPaymentMethods,
29
+ maxVehicles = 10, name, disabled = false, serviceLabel = 'Tipo de servicio', vehiclesLabel = 'Cantidad de vehículos',
30
+ paymentLabel = 'Método de pago', hourlyLabel = 'Por horas', deliveryLabel = 'Envíos', class: className,
31
+ } = Astro.props;
32
+ const value = { ...defaultTripAttributes, ...Astro.props.value };
33
+ const field = (key: string) => (name ? `${name}.${key}` : undefined);
34
+ const titleId = `ds-wtrip-${Math.random().toString(36).slice(2, 9)}`;
35
+ const Heading = `h${headingLevel}`;
36
+ const modes = [{ value: 'hourly', label: hourlyLabel }, { value: 'delivery', label: deliveryLabel }];
37
+ ---
38
+ <section class:list={['ds-wcard', 'ds-wtrip', className]} aria-labelledby={titleId} data-ds-wtrip data-services={JSON.stringify(services)}>
39
+ <header class="ds-wcard-header">
40
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 4v8M6 16v4M12 4v2M12 10v10M18 4v10M18 18v2M4 14h4M10 8h4M16 16h4"/></svg>
41
+ <Heading id={titleId} class="ds-wcard-title">{title}</Heading>
42
+ </header>
43
+ <div class="ds-wcard-body">
44
+ <div class="ds-wtrip-service">
45
+ <WariSelect label={serviceLabel} name={field('service')} value={value.service} disabled={disabled} hourly={value.hourly} delivery={value.delivery}
46
+ options={services.map(service => ({ value: service.value, label: service.label, disabled: service.disabled, service }))} />
47
+ <WariSwitchList legend="Modalidad del viaje" orientation="horizontal" items={modes} name={field('mode')} disabled={disabled}
48
+ value={[value.hourly ? 'hourly' : '', value.delivery ? 'delivery' : ''].filter(Boolean)} />
49
+ </div>
50
+ <WariSwitchList legend="Extras" items={extras} value={value.extras} name={field('extras')} disabled={disabled} />
51
+ <WariStepper label={vehiclesLabel} value={value.vehicles} min={1} max={maxVehicles} name={field('vehicles')} disabled={disabled} />
52
+ <WariSelect label={paymentLabel} options={paymentMethods} value={value.payment} name={field('payment')} disabled={disabled} />
53
+ </div>
54
+ </section>
55
+
56
+ <script>
57
+ import { initWariTripFields } from '../wari/trip-client.js';
58
+ initWariTripFields();
59
+ document.addEventListener('astro:page-load', () => initWariTripFields());
60
+ </script>
package/src/modal.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export declare function initModals(root?: ParentNode): void;
2
- export declare function openModal(id: string, opener?: HTMLElement): void;
3
- export declare function closeModal(id: string): void;
1
+ export declare function initModals(root?: ParentNode): void;
2
+ export declare function openModal(id: string, opener?: HTMLElement): void;
3
+ export declare function closeModal(id: string): void;
package/src/modal.js CHANGED
@@ -1,39 +1,39 @@
1
- /**
2
- * Wires native <dialog data-ds-modal> elements:
3
- * - any element with data-ds-open="<dialog id>" opens it as a modal,
4
- * - any [data-ds-close] inside closes it, as does a backdrop click or Escape,
5
- * - focus returns to the opener. Safe to call repeatedly.
6
- * @param {ParentNode} [root=document]
7
- */
8
- export function initModals(root = document) {
9
- root.querySelectorAll('[data-ds-open]:not([data-ds-ready])').forEach(trigger => {
10
- trigger.dataset.dsReady = '';
11
- trigger.setAttribute('aria-haspopup', 'dialog');
12
- trigger.addEventListener('click', () => openModal(trigger.dataset.dsOpen ?? '', trigger));
13
- });
14
- root.querySelectorAll('dialog[data-ds-modal]:not([data-ds-ready])').forEach(dialog => {
15
- dialog.dataset.dsReady = '';
16
- dialog.addEventListener('click', event => {
17
- const target = event.target;
18
- if (target === dialog || (target instanceof Element && target.closest('[data-ds-close]'))) dialog.close();
19
- });
20
- if (dialog.hasAttribute('data-ds-open-initially')) dialog.showModal();
21
- });
22
- }
23
-
24
- const openers = new WeakMap();
25
-
26
- /** @param {string} id @param {HTMLElement} [opener] */
27
- export function openModal(id, opener) {
28
- const dialog = document.getElementById(id);
29
- if (!(dialog instanceof HTMLDialogElement) || dialog.open) return;
30
- if (opener) openers.set(dialog, opener);
31
- dialog.showModal();
32
- dialog.addEventListener('close', () => openers.get(dialog)?.focus({ preventScroll: true }), { once: true });
33
- }
34
-
35
- /** @param {string} id */
36
- export function closeModal(id) {
37
- const dialog = document.getElementById(id);
38
- if (dialog instanceof HTMLDialogElement) dialog.close();
39
- }
1
+ /**
2
+ * Wires native <dialog data-ds-modal> elements:
3
+ * - any element with data-ds-open="<dialog id>" opens it as a modal,
4
+ * - any [data-ds-close] inside closes it, as does a backdrop click or Escape,
5
+ * - focus returns to the opener. Safe to call repeatedly.
6
+ * @param {ParentNode} [root=document]
7
+ */
8
+ export function initModals(root = document) {
9
+ root.querySelectorAll('[data-ds-open]:not([data-ds-ready])').forEach(trigger => {
10
+ trigger.dataset.dsReady = '';
11
+ trigger.setAttribute('aria-haspopup', 'dialog');
12
+ trigger.addEventListener('click', () => openModal(trigger.dataset.dsOpen ?? '', trigger));
13
+ });
14
+ root.querySelectorAll('dialog[data-ds-modal]:not([data-ds-ready])').forEach(dialog => {
15
+ dialog.dataset.dsReady = '';
16
+ dialog.addEventListener('click', event => {
17
+ const target = event.target;
18
+ if (target === dialog || (target instanceof Element && target.closest('[data-ds-close]'))) dialog.close();
19
+ });
20
+ if (dialog.hasAttribute('data-ds-open-initially')) dialog.showModal();
21
+ });
22
+ }
23
+
24
+ const openers = new WeakMap();
25
+
26
+ /** @param {string} id @param {HTMLElement} [opener] */
27
+ export function openModal(id, opener) {
28
+ const dialog = document.getElementById(id);
29
+ if (!(dialog instanceof HTMLDialogElement) || dialog.open) return;
30
+ if (opener) openers.set(dialog, opener);
31
+ dialog.showModal();
32
+ dialog.addEventListener('close', () => openers.get(dialog)?.focus({ preventScroll: true }), { once: true });
33
+ }
34
+
35
+ /** @param {string} id */
36
+ export function closeModal(id) {
37
+ const dialog = document.getElementById(id);
38
+ if (dialog instanceof HTMLDialogElement) dialog.close();
39
+ }
@@ -1,2 +1,2 @@
1
- export type PageToken = number | 'ellipsis-start' | 'ellipsis-end';
2
- export declare function paginationRange(page: number, totalPages: number, siblings?: number): PageToken[];
1
+ export type PageToken = number | 'ellipsis-start' | 'ellipsis-end';
2
+ export declare function paginationRange(page: number, totalPages: number, siblings?: number): PageToken[];
package/src/pagination.js CHANGED
@@ -1,16 +1,16 @@
1
- /**
2
- * Pages to display: always first/last, `siblings` around the current page, and ellipses.
3
- * @param {number} page @param {number} totalPages @param {number} [siblings=1]
4
- * @returns {(number | 'ellipsis-start' | 'ellipsis-end')[]}
5
- */
6
- export function paginationRange(page, totalPages, siblings = 1) {
7
- const total = Math.max(1, Math.floor(totalPages));
8
- const current = Math.min(Math.max(1, Math.floor(page)), total);
9
- const edge = 3 + siblings * 2;
10
- if (total <= edge + 2) return Array.from({ length: total }, (_, i) => i + 1);
11
- const left = Math.max(current - siblings, 1);
12
- const right = Math.min(current + siblings, total);
13
- if (left <= 3) return [...Array.from({ length: edge }, (_, i) => i + 1), 'ellipsis-end', total];
14
- if (right >= total - 2) return [1, 'ellipsis-start', ...Array.from({ length: edge }, (_, i) => total - edge + i + 1)];
15
- return [1, 'ellipsis-start', ...Array.from({ length: right - left + 1 }, (_, i) => left + i), 'ellipsis-end', total];
16
- }
1
+ /**
2
+ * Pages to display: always first/last, `siblings` around the current page, and ellipses.
3
+ * @param {number} page @param {number} totalPages @param {number} [siblings=1]
4
+ * @returns {(number | 'ellipsis-start' | 'ellipsis-end')[]}
5
+ */
6
+ export function paginationRange(page, totalPages, siblings = 1) {
7
+ const total = Math.max(1, Math.floor(totalPages));
8
+ const current = Math.min(Math.max(1, Math.floor(page)), total);
9
+ const edge = 3 + siblings * 2;
10
+ if (total <= edge + 2) return Array.from({ length: total }, (_, i) => i + 1);
11
+ const left = Math.max(current - siblings, 1);
12
+ const right = Math.min(current + siblings, total);
13
+ if (left <= 3) return [...Array.from({ length: edge }, (_, i) => i + 1), 'ellipsis-end', total];
14
+ if (right >= total - 2) return [1, 'ellipsis-start', ...Array.from({ length: edge }, (_, i) => total - edge + i + 1)];
15
+ return [1, 'ellipsis-start', ...Array.from({ length: right - left + 1 }, (_, i) => left + i), 'ellipsis-end', total];
16
+ }
package/src/toast.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export interface ToastOptions {
2
- title: string;
3
- description?: string;
4
- variant?: 'info' | 'success' | 'warning' | 'error';
5
- /** Milliseconds before auto-dismiss; 0 keeps it until closed. Default 5000. */
6
- duration?: number;
7
- }
8
- export declare function toast(options: ToastOptions): HTMLLIElement;
9
- export declare function dismissToast(item: HTMLElement): void;
1
+ export interface ToastOptions {
2
+ title: string;
3
+ description?: string;
4
+ variant?: 'info' | 'success' | 'warning' | 'error';
5
+ /** Milliseconds before auto-dismiss; 0 keeps it until closed. Default 5000. */
6
+ duration?: number;
7
+ }
8
+ export declare function toast(options: ToastOptions): HTMLLIElement;
9
+ export declare function dismissToast(item: HTMLElement): void;
package/src/toast.js CHANGED
@@ -1,66 +1,66 @@
1
- // Client helper for <Toaster />. Usage inside a <script>:
2
- // import { toast } from '@directo-ui/astro/toast';
3
- // toast({ title: 'Guardado', variant: 'success' });
4
-
5
- const paths = {
6
- info: 'M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24Zm-4 48a12 12 0 1 1-12 12 12 12 0 0 1 12-12Zm12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16 16 16 0 0 1 16 16v40a8 8 0 0 1 0 16Z',
7
- success: 'M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24Zm45.66 85.66-56 56a8 8 0 0 1-11.32 0l-24-24a8 8 0 0 1 11.32-11.32L112 148.69l50.34-50.35a8 8 0 0 1 11.32 11.32Z',
8
- warning: 'M236.8 188.09 149.35 36.22a24.76 24.76 0 0 0-42.7 0L19.2 188.09a23.51 23.51 0 0 0 0 23.72A24.35 24.35 0 0 0 40.55 224h174.9a24.35 24.35 0 0 0 21.33-12.19 23.51 23.51 0 0 0 .02-23.72ZM120 104a8 8 0 0 1 16 0v40a8 8 0 0 1-16 0Zm8 88a12 12 0 1 1 12-12 12 12 0 0 1-12 12Z',
9
- error: 'M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24Zm-8 56a8 8 0 0 1 16 0v56a8 8 0 0 1-16 0Zm8 104a12 12 0 1 1 12-12 12 12 0 0 1-12 12Z',
10
- };
11
-
12
- function region() {
13
- let toaster = document.querySelector('[data-ds-toaster]');
14
- if (!toaster) {
15
- toaster = document.createElement('ol');
16
- toaster.className = 'ds-toaster';
17
- toaster.setAttribute('aria-label', 'Notificaciones');
18
- toaster.setAttribute('data-ds-toaster', '');
19
- document.body.append(toaster);
20
- }
21
- return toaster;
22
- }
23
-
24
- export function dismissToast(item) {
25
- if (!item || item.dataset.state === 'closing') return;
26
- item.dataset.state = 'closing';
27
- setTimeout(() => item.remove(), 180);
28
- }
29
-
30
- /** @param {{ title: string, description?: string, variant?: 'info'|'success'|'warning'|'error', duration?: number }} options */
31
- export function toast({ title, description, variant = 'info', duration = 5000 }) {
32
- const toaster = region();
33
- while (toaster.children.length >= 5) toaster.firstElementChild?.remove();
34
- const item = document.createElement('li');
35
- item.className = 'ds-toast';
36
- item.dataset.variant = variant;
37
- item.dataset.state = 'open';
38
- item.setAttribute('role', variant === 'error' ? 'alert' : 'status');
39
- item.setAttribute('aria-atomic', 'true');
40
- const icon = document.createElement('span');
41
- icon.className = 'ds-toast-icon';
42
- icon.setAttribute('aria-hidden', 'true');
43
- icon.innerHTML = `<svg viewBox="0 0 256 256" fill="currentColor"><path d="${paths[variant] ?? paths.info}"/></svg>`;
44
- const content = document.createElement('div');
45
- content.className = 'ds-toast-content';
46
- const heading = document.createElement('span');
47
- heading.className = 'ds-toast-title';
48
- heading.textContent = title;
49
- content.append(heading);
50
- if (description) {
51
- const text = document.createElement('p');
52
- text.className = 'ds-toast-description';
53
- text.textContent = description;
54
- content.append(text);
55
- }
56
- const close = document.createElement('button');
57
- close.type = 'button';
58
- close.className = 'ds-toast-close';
59
- close.setAttribute('aria-label', 'Cerrar notificación');
60
- close.textContent = '×';
61
- close.addEventListener('click', () => dismissToast(item));
62
- item.append(icon, content, close);
63
- toaster.append(item);
64
- if (duration > 0) setTimeout(() => dismissToast(item), duration);
65
- return item;
66
- }
1
+ // Client helper for <Toaster />. Usage inside a <script>:
2
+ // import { toast } from '@directo-ui/astro/toast';
3
+ // toast({ title: 'Guardado', variant: 'success' });
4
+
5
+ const paths = {
6
+ info: 'M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24Zm-4 48a12 12 0 1 1-12 12 12 12 0 0 1 12-12Zm12 112a16 16 0 0 1-16-16v-40a8 8 0 0 1 0-16 16 16 0 0 1 16 16v40a8 8 0 0 1 0 16Z',
7
+ success: 'M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24Zm45.66 85.66-56 56a8 8 0 0 1-11.32 0l-24-24a8 8 0 0 1 11.32-11.32L112 148.69l50.34-50.35a8 8 0 0 1 11.32 11.32Z',
8
+ warning: 'M236.8 188.09 149.35 36.22a24.76 24.76 0 0 0-42.7 0L19.2 188.09a23.51 23.51 0 0 0 0 23.72A24.35 24.35 0 0 0 40.55 224h174.9a24.35 24.35 0 0 0 21.33-12.19 23.51 23.51 0 0 0 .02-23.72ZM120 104a8 8 0 0 1 16 0v40a8 8 0 0 1-16 0Zm8 88a12 12 0 1 1 12-12 12 12 0 0 1-12 12Z',
9
+ error: 'M128 24a104 104 0 1 0 104 104A104.11 104.11 0 0 0 128 24Zm-8 56a8 8 0 0 1 16 0v56a8 8 0 0 1-16 0Zm8 104a12 12 0 1 1 12-12 12 12 0 0 1-12 12Z',
10
+ };
11
+
12
+ function region() {
13
+ let toaster = document.querySelector('[data-ds-toaster]');
14
+ if (!toaster) {
15
+ toaster = document.createElement('ol');
16
+ toaster.className = 'ds-toaster';
17
+ toaster.setAttribute('aria-label', 'Notificaciones');
18
+ toaster.setAttribute('data-ds-toaster', '');
19
+ document.body.append(toaster);
20
+ }
21
+ return toaster;
22
+ }
23
+
24
+ export function dismissToast(item) {
25
+ if (!item || item.dataset.state === 'closing') return;
26
+ item.dataset.state = 'closing';
27
+ setTimeout(() => item.remove(), 180);
28
+ }
29
+
30
+ /** @param {{ title: string, description?: string, variant?: 'info'|'success'|'warning'|'error', duration?: number }} options */
31
+ export function toast({ title, description, variant = 'info', duration = 5000 }) {
32
+ const toaster = region();
33
+ while (toaster.children.length >= 5) toaster.firstElementChild?.remove();
34
+ const item = document.createElement('li');
35
+ item.className = 'ds-toast';
36
+ item.dataset.variant = variant;
37
+ item.dataset.state = 'open';
38
+ item.setAttribute('role', variant === 'error' ? 'alert' : 'status');
39
+ item.setAttribute('aria-atomic', 'true');
40
+ const icon = document.createElement('span');
41
+ icon.className = 'ds-toast-icon';
42
+ icon.setAttribute('aria-hidden', 'true');
43
+ icon.innerHTML = `<svg viewBox="0 0 256 256" fill="currentColor"><path d="${paths[variant] ?? paths.info}"/></svg>`;
44
+ const content = document.createElement('div');
45
+ content.className = 'ds-toast-content';
46
+ const heading = document.createElement('span');
47
+ heading.className = 'ds-toast-title';
48
+ heading.textContent = title;
49
+ content.append(heading);
50
+ if (description) {
51
+ const text = document.createElement('p');
52
+ text.className = 'ds-toast-description';
53
+ text.textContent = description;
54
+ content.append(text);
55
+ }
56
+ const close = document.createElement('button');
57
+ close.type = 'button';
58
+ close.className = 'ds-toast-close';
59
+ close.setAttribute('aria-label', 'Cerrar notificación');
60
+ close.textContent = '×';
61
+ close.addEventListener('click', () => dismissToast(item));
62
+ item.append(icon, content, close);
63
+ toaster.append(item);
64
+ if (duration > 0) setTimeout(() => dismissToast(item), duration);
65
+ return item;
66
+ }
@@ -0,0 +1,57 @@
1
+ export interface CalendarDay {
2
+ iso: string;
3
+ day: number;
4
+ /** Belongs to the previous or next month. */
5
+ outside: boolean;
6
+ }
7
+ export interface TimeParts {
8
+ hours: number;
9
+ minutes: number;
10
+ }
11
+ export type Period = 'AM' | 'PM';
12
+ export declare function toISODate(year: number, month: number, day: number): string;
13
+ /** Returns { year, month (0-11), day } or null when the string is not a real date. */
14
+ export declare function parseISODate(value: string | null | undefined): {
15
+ year: number;
16
+ month: number;
17
+ day: number;
18
+ } | null;
19
+ export declare function todayISO(now?: Date): string;
20
+ /** "2026-05-27" → "27/05/26" (formato del diseño de Wari). */
21
+ export declare function formatDisplayDate(iso: string | null | undefined): string;
22
+ /** Accepts d/m/aa, d/m/aaaa, d-m-aaaa or d.m.aa. Two-digit years are 2000-2099. */
23
+ export declare function parseDisplayDate(text: string): string | null;
24
+ export declare function isDateInRange(iso: string, min?: string | null, max?: string | null): boolean;
25
+ export declare function addMonths(year: number, month: number, delta: number): {
26
+ year: number;
27
+ month: number;
28
+ };
29
+ /** Always 6 weeks × 7 days, like the design (days of the neighbour months are marked `outside`). */
30
+ export declare function calendarWeeks(year: number, month: number, weekStartsOn?: 0 | 1): CalendarDay[][];
31
+ /** Day `delta` days after `iso` (negative goes back). */
32
+ export declare function shiftDate(iso: string, delta: number): string;
33
+ /** Same day in another month, clamped to that month's length (31 ene + 1 mes → 28/29 feb). */
34
+ export declare function shiftMonth(iso: string, delta: number): string;
35
+ export declare function monthNames(locale?: string, format?: 'long' | 'short'): string[];
36
+ /** Narrow weekday names starting on `weekStartsOn` (0 = domingo). */
37
+ export declare function weekdayNames(locale?: string, weekStartsOn?: 0 | 1, format?: 'narrow' | 'long'): string[];
38
+ export declare function longDateLabel(iso: string, locale?: string): string;
39
+ export declare function parseTime24(value: string | null | undefined): TimeParts | null;
40
+ export declare function formatTime24(hours: number, minutes: number): string;
41
+ export declare function to12h(hours: number): {
42
+ hour: number;
43
+ period: Period;
44
+ };
45
+ export declare function from12h(hour: number, period: Period): number;
46
+ /** "23:50" → "11:50 PM" (formato del diseño de Wari). */
47
+ export declare function formatDisplayTime(value: string | null | undefined): string;
48
+ /** Accepts "11:50 pm", "11:50PM", "23:50", "7 pm", "7", "0730". Returns "HH:mm" or null. */
49
+ export declare function parseDisplayTime(text: string): string | null;
50
+ /** Position (px) of a dial number. `step` is 12 for hours and 60 for minutes. */
51
+ export declare function dialPoint(value: number, step: 12 | 60, radius: number, center: number): {
52
+ x: number;
53
+ y: number;
54
+ };
55
+ /** Hour (1-12) or minute (0-59) under a pointer at (x, y) relative to the dial's top-left corner. */
56
+ export declare function dialValue(x: number, y: number, center: number, mode: 'hour' | 'minute'): number;
57
+ export declare const pad2: (value: number) => string;
@@ -0,0 +1,151 @@
1
+ // Generated from web/components/src/wari/datetime.ts (same behaviour in React, Angular and Astro).
2
+ // Pure date/time helpers for the Wari date and time fields (no framework code, easy to test).
3
+ // Values travel as ISO strings: dates "YYYY-MM-DD" and times "HH:mm" (24 h).
4
+ const pad = (value, size = 2) => String(value).padStart(size, '0');
5
+ export function toISODate(year, month, day) {
6
+ return `${pad(year, 4)}-${pad(month + 1)}-${pad(day)}`;
7
+ }
8
+ /** Returns { year, month (0-11), day } or null when the string is not a real date. */
9
+ export function parseISODate(value) {
10
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value ?? '');
11
+ if (!match)
12
+ return null;
13
+ const year = Number(match[1]);
14
+ const month = Number(match[2]) - 1;
15
+ const day = Number(match[3]);
16
+ const date = new Date(year, month, day);
17
+ return date.getFullYear() === year && date.getMonth() === month && date.getDate() === day ? { year, month, day } : null;
18
+ }
19
+ export function todayISO(now = new Date()) {
20
+ return toISODate(now.getFullYear(), now.getMonth(), now.getDate());
21
+ }
22
+ /** "2026-05-27" → "27/05/26" (formato del diseño de Wari). */
23
+ export function formatDisplayDate(iso) {
24
+ const parts = parseISODate(iso);
25
+ return parts ? `${pad(parts.day)}/${pad(parts.month + 1)}/${pad(parts.year % 100)}` : '';
26
+ }
27
+ /** Accepts d/m/aa, d/m/aaaa, d-m-aaaa or d.m.aa. Two-digit years are 2000-2099. */
28
+ export function parseDisplayDate(text) {
29
+ const match = /^\s*(\d{1,2})[/.-](\d{1,2})[/.-](\d{2}|\d{4})\s*$/.exec(text);
30
+ if (!match)
31
+ return null;
32
+ const year = match[3].length === 2 ? 2000 + Number(match[3]) : Number(match[3]);
33
+ const iso = toISODate(year, Number(match[2]) - 1, Number(match[1]));
34
+ return parseISODate(iso) ? iso : null;
35
+ }
36
+ export function isDateInRange(iso, min, max) {
37
+ return (!min || iso >= min) && (!max || iso <= max);
38
+ }
39
+ export function addMonths(year, month, delta) {
40
+ const date = new Date(year, month + delta, 1);
41
+ return { year: date.getFullYear(), month: date.getMonth() };
42
+ }
43
+ /** Always 6 weeks × 7 days, like the design (days of the neighbour months are marked `outside`). */
44
+ export function calendarWeeks(year, month, weekStartsOn = 0) {
45
+ const first = new Date(year, month, 1);
46
+ const offset = (first.getDay() - weekStartsOn + 7) % 7;
47
+ const weeks = [];
48
+ for (let week = 0; week < 6; week++) {
49
+ const days = [];
50
+ for (let weekday = 0; weekday < 7; weekday++) {
51
+ const date = new Date(year, month, 1 - offset + week * 7 + weekday);
52
+ days.push({ iso: toISODate(date.getFullYear(), date.getMonth(), date.getDate()), day: date.getDate(), outside: date.getMonth() !== month });
53
+ }
54
+ weeks.push(days);
55
+ }
56
+ return weeks;
57
+ }
58
+ /** Day `delta` days after `iso` (negative goes back). */
59
+ export function shiftDate(iso, delta) {
60
+ const parts = parseISODate(iso);
61
+ if (!parts)
62
+ return iso;
63
+ const date = new Date(parts.year, parts.month, parts.day + delta);
64
+ return toISODate(date.getFullYear(), date.getMonth(), date.getDate());
65
+ }
66
+ /** Same day in another month, clamped to that month's length (31 ene + 1 mes → 28/29 feb). */
67
+ export function shiftMonth(iso, delta) {
68
+ const parts = parseISODate(iso);
69
+ if (!parts)
70
+ return iso;
71
+ const target = addMonths(parts.year, parts.month, delta);
72
+ const last = new Date(target.year, target.month + 1, 0).getDate();
73
+ return toISODate(target.year, target.month, Math.min(parts.day, last));
74
+ }
75
+ export function monthNames(locale = 'es', format = 'long') {
76
+ const formatter = new Intl.DateTimeFormat(locale, { month: format, timeZone: 'UTC' });
77
+ return Array.from({ length: 12 }, (_, month) => formatter.format(new Date(Date.UTC(2024, month, 1))).replace('.', ''));
78
+ }
79
+ /** Narrow weekday names starting on `weekStartsOn` (0 = domingo). */
80
+ export function weekdayNames(locale = 'es', weekStartsOn = 0, format = 'narrow') {
81
+ const formatter = new Intl.DateTimeFormat(locale, { weekday: format, timeZone: 'UTC' });
82
+ // 2024-01-07 was a Sunday.
83
+ return Array.from({ length: 7 }, (_, index) => formatter.format(new Date(Date.UTC(2024, 0, 7 + ((index + weekStartsOn) % 7)))));
84
+ }
85
+ export function longDateLabel(iso, locale = 'es') {
86
+ const parts = parseISODate(iso);
87
+ if (!parts)
88
+ return '';
89
+ return new Intl.DateTimeFormat(locale, { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC' })
90
+ .format(new Date(Date.UTC(parts.year, parts.month, parts.day)));
91
+ }
92
+ // ---------------------------------------------------------------- time
93
+ export function parseTime24(value) {
94
+ const match = /^(\d{1,2}):(\d{2})$/.exec(value ?? '');
95
+ if (!match)
96
+ return null;
97
+ const hours = Number(match[1]);
98
+ const minutes = Number(match[2]);
99
+ return hours < 24 && minutes < 60 ? { hours, minutes } : null;
100
+ }
101
+ export function formatTime24(hours, minutes) {
102
+ return `${pad(hours)}:${pad(minutes)}`;
103
+ }
104
+ export function to12h(hours) {
105
+ return { hour: hours % 12 === 0 ? 12 : hours % 12, period: hours < 12 ? 'AM' : 'PM' };
106
+ }
107
+ export function from12h(hour, period) {
108
+ return (hour % 12) + (period === 'PM' ? 12 : 0);
109
+ }
110
+ /** "23:50" → "11:50 PM" (formato del diseño de Wari). */
111
+ export function formatDisplayTime(value) {
112
+ const parts = parseTime24(value);
113
+ if (!parts)
114
+ return '';
115
+ const { hour, period } = to12h(parts.hours);
116
+ return `${pad(hour)}:${pad(parts.minutes)} ${period}`;
117
+ }
118
+ /** Accepts "11:50 pm", "11:50PM", "23:50", "7 pm", "7", "0730". Returns "HH:mm" or null. */
119
+ export function parseDisplayTime(text) {
120
+ const match = /^\s*(\d{1,2})(?::?(\d{2}))?\s*([ap])?\.?\s*m?\.?\s*$/i.exec(text);
121
+ if (!match)
122
+ return null;
123
+ let hours = Number(match[1]);
124
+ const minutes = match[2] ? Number(match[2]) : 0;
125
+ const suffix = match[3]?.toLowerCase();
126
+ if (minutes > 59)
127
+ return null;
128
+ if (suffix) {
129
+ if (hours < 1 || hours > 12)
130
+ return null;
131
+ hours = from12h(hours, suffix === 'p' ? 'PM' : 'AM');
132
+ }
133
+ else if (hours > 23)
134
+ return null;
135
+ return formatTime24(hours, minutes);
136
+ }
137
+ /** Position (px) of a dial number. `step` is 12 for hours and 60 for minutes. */
138
+ export function dialPoint(value, step, radius, center) {
139
+ const angle = ((value % step) / step) * Math.PI * 2;
140
+ return { x: center + radius * Math.sin(angle), y: center - radius * Math.cos(angle) };
141
+ }
142
+ /** Hour (1-12) or minute (0-59) under a pointer at (x, y) relative to the dial's top-left corner. */
143
+ export function dialValue(x, y, center, mode) {
144
+ const degrees = (Math.atan2(x - center, center - y) * 180 / Math.PI + 360) % 360;
145
+ if (mode === 'hour') {
146
+ const hour = Math.round(degrees / 30) % 12;
147
+ return hour === 0 ? 12 : hour;
148
+ }
149
+ return Math.round(degrees / 6) % 60;
150
+ }
151
+ export const pad2 = (value) => pad(value);
@@ -0,0 +1,8 @@
1
+ export interface SelectableOption { value: string; label: string; disabled?: boolean }
2
+ export type SelectionState = 'none' | 'some' | 'all';
3
+ export declare function normalizeSearch(text: string): string;
4
+ export declare function filterOptions<T extends SelectableOption>(options: readonly T[], query: string): T[];
5
+ export declare function toggleValue(values: readonly string[], value: string, options: readonly SelectableOption[]): string[];
6
+ export declare function selectionState(values: readonly string[], options: readonly SelectableOption[]): SelectionState;
7
+ export declare function toggleAll(values: readonly string[], options: readonly SelectableOption[]): string[];
8
+ export declare function selectionSummary(count: number): string;