@joniguerini/lume 0.0.0-stage → 1.9.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 (226) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +62 -2
  3. package/base.css +165 -0
  4. package/bin/lumeui.mjs +163 -0
  5. package/components/alert.css +156 -0
  6. package/components/banner.css +98 -0
  7. package/components/button.css +291 -0
  8. package/components/calendar.css +532 -0
  9. package/components/carousel.css +175 -0
  10. package/components/chart.css +813 -0
  11. package/components/chat.css +670 -0
  12. package/components/checkbox.css +212 -0
  13. package/components/chip.css +224 -0
  14. package/components/code.css +36 -0
  15. package/components/color-picker.css +192 -0
  16. package/components/command.css +148 -0
  17. package/components/content.css +211 -0
  18. package/components/editor.css +174 -0
  19. package/components/feedback.css +320 -0
  20. package/components/filters.css +103 -0
  21. package/components/form.css +455 -0
  22. package/components/image-viewer.css +237 -0
  23. package/components/layers.css +138 -0
  24. package/components/link.css +87 -0
  25. package/components/loading.css +260 -0
  26. package/components/menu.css +180 -0
  27. package/components/modal.css +209 -0
  28. package/components/navigation.css +507 -0
  29. package/components/notifications.css +186 -0
  30. package/components/number-field.css +52 -0
  31. package/components/otp.css +119 -0
  32. package/components/panel.css +208 -0
  33. package/components/picker.css +207 -0
  34. package/components/rating.css +143 -0
  35. package/components/resizable.css +173 -0
  36. package/components/scrollbar.css +110 -0
  37. package/components/select.css +477 -0
  38. package/components/shell.css +837 -0
  39. package/components/slider.css +189 -0
  40. package/components/sortable.css +287 -0
  41. package/components/surfaces.css +182 -0
  42. package/components/switch.css +115 -0
  43. package/components/table.css +228 -0
  44. package/components/tabs.css +190 -0
  45. package/components/tags.css +83 -0
  46. package/components/toast.css +164 -0
  47. package/components/toolbar.css +80 -0
  48. package/components/upload.css +181 -0
  49. package/ds.css +48 -0
  50. package/fonts/Geist-LICENSE.txt +92 -0
  51. package/fonts/Geist-Variable.woff2 +0 -0
  52. package/fonts/GeistSerif-Regular.woff2 +0 -0
  53. package/fonts/JetBrainsMono-LICENSE.txt +93 -0
  54. package/fonts/JetBrainsMono-Variable.woff2 +0 -0
  55. package/fonts.css +29 -0
  56. package/icons/icons.d.ts +5 -0
  57. package/icons/icons.js +266 -0
  58. package/js/back-to-top.d.ts +2 -0
  59. package/js/back-to-top.js +62 -0
  60. package/js/banner.js +87 -0
  61. package/js/calendar.d.ts +3 -0
  62. package/js/calendar.js +472 -0
  63. package/js/carousel.d.ts +2 -0
  64. package/js/carousel.js +258 -0
  65. package/js/charts/bar.js +361 -0
  66. package/js/charts/core.js +604 -0
  67. package/js/charts/donut.js +206 -0
  68. package/js/charts/figures.js +97 -0
  69. package/js/charts/heatmap.js +410 -0
  70. package/js/charts/line.js +268 -0
  71. package/js/charts/scatter.js +211 -0
  72. package/js/charts.d.ts +12 -0
  73. package/js/charts.js +27 -0
  74. package/js/code-block.d.ts +3 -0
  75. package/js/code-block.js +32 -0
  76. package/js/color-picker.d.ts +4 -0
  77. package/js/color-picker.js +448 -0
  78. package/js/command-palette.js +233 -0
  79. package/js/composer.js +573 -0
  80. package/js/context-menu.d.ts +2 -0
  81. package/js/context-menu.js +154 -0
  82. package/js/date-picker.d.ts +2 -0
  83. package/js/date-picker.js +430 -0
  84. package/js/drawer.js +48 -0
  85. package/js/editor.d.ts +5 -0
  86. package/js/editor.js +615 -0
  87. package/js/field-support.js +77 -0
  88. package/js/file-upload.d.ts +2 -0
  89. package/js/file-upload.js +230 -0
  90. package/js/filters.js +266 -0
  91. package/js/form.d.ts +2 -0
  92. package/js/form.js +409 -0
  93. package/js/i18n.d.ts +14 -0
  94. package/js/i18n.js +83 -0
  95. package/js/image-viewer.d.ts +4 -0
  96. package/js/image-viewer.js +275 -0
  97. package/js/menu.d.ts +4 -0
  98. package/js/menu.js +237 -0
  99. package/js/messages.js +908 -0
  100. package/js/modal.d.ts +7 -0
  101. package/js/modal.js +183 -0
  102. package/js/notifications.d.ts +4 -0
  103. package/js/notifications.js +204 -0
  104. package/js/number-field.d.ts +2 -0
  105. package/js/number-field.js +175 -0
  106. package/js/otp-field.d.ts +2 -0
  107. package/js/otp-field.js +107 -0
  108. package/js/pagination.d.ts +3 -0
  109. package/js/pagination.js +143 -0
  110. package/js/popover.d.ts +2 -0
  111. package/js/popover.js +155 -0
  112. package/js/progress-ring.js +48 -0
  113. package/js/rating.d.ts +3 -0
  114. package/js/rating.js +130 -0
  115. package/js/resizable.d.ts +2 -0
  116. package/js/resizable.js +311 -0
  117. package/js/scrollbar.d.ts +2 -0
  118. package/js/scrollbar.js +273 -0
  119. package/js/segmented.js +60 -0
  120. package/js/select.d.ts +3 -0
  121. package/js/select.js +784 -0
  122. package/js/shell.d.ts +6 -0
  123. package/js/shell.js +373 -0
  124. package/js/slider.d.ts +2 -0
  125. package/js/slider.js +89 -0
  126. package/js/sortable.d.ts +5 -0
  127. package/js/sortable.js +463 -0
  128. package/js/stepper.d.ts +2 -0
  129. package/js/stepper.js +72 -0
  130. package/js/tabs.js +99 -0
  131. package/js/tag-field.d.ts +2 -0
  132. package/js/tag-field.js +177 -0
  133. package/js/theme.d.ts +9 -0
  134. package/js/theme.js +114 -0
  135. package/js/time-picker.d.ts +2 -0
  136. package/js/time-picker.js +279 -0
  137. package/js/toast.d.ts +17 -0
  138. package/js/toast.js +171 -0
  139. package/js/toolbar.d.ts +2 -0
  140. package/js/toolbar.js +107 -0
  141. package/js/tooltip.d.ts +2 -0
  142. package/js/tooltip.js +208 -0
  143. package/js/tree.d.ts +2 -0
  144. package/js/tree.js +168 -0
  145. package/lume.css +11574 -0
  146. package/lume.d.ts +104 -0
  147. package/lume.js +67 -0
  148. package/package.json +66 -4
  149. package/react/Alert.d.ts +24 -0
  150. package/react/Alert.js +21 -0
  151. package/react/AppShell.d.ts +67 -0
  152. package/react/AppShell.js +94 -0
  153. package/react/Avatar.d.ts +39 -0
  154. package/react/Avatar.js +40 -0
  155. package/react/Badge.d.ts +17 -0
  156. package/react/Badge.js +10 -0
  157. package/react/Button.d.ts +32 -0
  158. package/react/Button.js +17 -0
  159. package/react/Calendar.d.ts +48 -0
  160. package/react/Calendar.js +67 -0
  161. package/react/Carousel.d.ts +30 -0
  162. package/react/Carousel.js +38 -0
  163. package/react/Charts.d.ts +186 -0
  164. package/react/Charts.js +58 -0
  165. package/react/Chip.d.ts +34 -0
  166. package/react/Chip.js +26 -0
  167. package/react/Choice.d.ts +72 -0
  168. package/react/Choice.js +51 -0
  169. package/react/ColorPicker.d.ts +43 -0
  170. package/react/ColorPicker.js +73 -0
  171. package/react/Content.d.ts +58 -0
  172. package/react/Content.js +42 -0
  173. package/react/Controls.d.ts +97 -0
  174. package/react/Controls.js +118 -0
  175. package/react/Editor.d.ts +28 -0
  176. package/react/Editor.js +57 -0
  177. package/react/Field.d.ts +90 -0
  178. package/react/Field.js +65 -0
  179. package/react/Form.d.ts +36 -0
  180. package/react/Form.js +45 -0
  181. package/react/Icon.d.ts +13 -0
  182. package/react/Icon.js +8 -0
  183. package/react/IconButton.d.ts +19 -0
  184. package/react/IconButton.js +12 -0
  185. package/react/ImageViewer.d.ts +20 -0
  186. package/react/ImageViewer.js +22 -0
  187. package/react/InlineAction.d.ts +15 -0
  188. package/react/InlineAction.js +12 -0
  189. package/react/Layers.d.ts +118 -0
  190. package/react/Layers.js +115 -0
  191. package/react/Link.d.ts +32 -0
  192. package/react/Link.js +26 -0
  193. package/react/Loading.d.ts +67 -0
  194. package/react/Loading.js +49 -0
  195. package/react/Navigation.d.ts +181 -0
  196. package/react/Navigation.js +197 -0
  197. package/react/Notices.d.ts +43 -0
  198. package/react/Notices.js +89 -0
  199. package/react/Panel.d.ts +57 -0
  200. package/react/Panel.js +33 -0
  201. package/react/Pickers.d.ts +83 -0
  202. package/react/Pickers.js +70 -0
  203. package/react/Rating.d.ts +39 -0
  204. package/react/Rating.js +41 -0
  205. package/react/Resizable.d.ts +44 -0
  206. package/react/Resizable.js +30 -0
  207. package/react/Select.d.ts +53 -0
  208. package/react/Select.js +79 -0
  209. package/react/Sortable.d.ts +52 -0
  210. package/react/Sortable.js +113 -0
  211. package/react/Table.d.ts +60 -0
  212. package/react/Table.js +34 -0
  213. package/react/Toolbar.d.ts +45 -0
  214. package/react/Toolbar.js +45 -0
  215. package/react/cx.d.ts +2 -0
  216. package/react/cx.js +5 -0
  217. package/react/icon-names.d.ts +1 -0
  218. package/react/icon-names.js +2 -0
  219. package/react/index.d.ts +42 -0
  220. package/react/index.js +52 -0
  221. package/react/useController.d.ts +8 -0
  222. package/react/useController.js +16 -0
  223. package/react/useLocale.d.ts +5 -0
  224. package/react/useLocale.js +15 -0
  225. package/tokens.css +739 -0
  226. package/tokens.js +4911 -0
package/js/calendar.js ADDED
@@ -0,0 +1,472 @@
1
+ /**
2
+ * Calendário — visões de mês, semana e dia, com eventos.
3
+ *
4
+ * const cal = createCalendar(document.querySelector('#agenda'), {
5
+ * view: 'month', // 'month' | 'week' | 'day'
6
+ * date: new Date(), // dia em foco
7
+ * events: [
8
+ * { id: 'a', title: 'Revisão do roteiro', start: new Date(…), end: new Date(…), tone: 'brand' },
9
+ * { id: 'b', title: 'Feriado', start: new Date(…), end: new Date(…), allDay: true, tone: 'success' },
10
+ * ],
11
+ * onEventClick: (event) => abrir(event),
12
+ * onChange: ({ view, date }) => salvar(view, date),
13
+ * });
14
+ * cal.setView('week'); cal.setDate(d); cal.today(); cal.prev(); cal.next();
15
+ * cal.setEvents(lista); cal.destroy();
16
+ *
17
+ * Opções: weekStartsOn (0 domingo · 1 segunda; padrão: o do idioma), scrollToHour (8: a grade de horas
18
+ * abre nessa hora), views (['month', 'week', 'day']: as que aparecem no seletor), onDateClick(date)
19
+ * (padrão: abre a visão do dia).
20
+ * Tons dos eventos: neutral (padrão) · brand · info · success · warning · danger.
21
+ * Fim exclusivo: um evento de 9:00 às 10:00 termina em 10:00; um de dia todo, à meia-noite do dia seguinte.
22
+ *
23
+ * Teclado (visão do mês, padrão de grade): setas andam um dia ou uma semana, Home/End vão ao começo
24
+ * e ao fim da semana, PageUp/PageDown trocam de mês, Enter abre o dia. Nas grades de horas, cada evento
25
+ * é um botão com nome, horário e dia. Textos e datas no idioma atual (Intl).
26
+ */
27
+ import { icon } from '../icons/icons.js';
28
+ import { msg, locale, dateFormat } from './i18n.js';
29
+
30
+ const VIEWS = ['month', 'week', 'day'];
31
+ const TONES = ['neutral', 'brand', 'info', 'success', 'warning', 'danger'];
32
+ const HOUR = 60 * 60 * 1000;
33
+ const MAX_IN_CELL = 3;
34
+ const MIN_MINUTES = 24; // evento curto ganha altura para o texto caber (e conta assim nas sobreposições)
35
+ let uid = 0;
36
+
37
+ const escape = (s) => String(s ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
38
+ const capitalize = (s) => s.charAt(0).toLocaleUpperCase(locale()) + s.slice(1);
39
+
40
+ /* ───────── Datas (sempre no horário local) ───────── */
41
+
42
+ const startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
43
+ const addDays = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
44
+ const addMonths = (d, n) => {
45
+ const target = new Date(d.getFullYear(), d.getMonth() + n, 1);
46
+ const last = new Date(target.getFullYear(), target.getMonth() + 1, 0).getDate();
47
+ return new Date(target.getFullYear(), target.getMonth(), Math.min(d.getDate(), last));
48
+ };
49
+ const sameDay = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
50
+ const key = (d) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
51
+ const fromKey = (k) => {
52
+ const [y, m, d] = k.split('-').map(Number);
53
+ return new Date(y, m - 1, d);
54
+ };
55
+ const startOfWeek = (d, weekStartsOn) => addDays(startOfDay(d), -((d.getDay() - weekStartsOn + 7) % 7));
56
+ const minutesOf = (d) => d.getHours() * 60 + d.getMinutes();
57
+
58
+ /** Primeiro dia da semana no idioma (Intl.Locale.weekInfo, onde houver). */
59
+ export function localeWeekStart(tag = locale()) {
60
+ try {
61
+ const loc = new Intl.Locale(tag);
62
+ const info = loc.getWeekInfo?.() ?? loc.weekInfo;
63
+ if (info?.firstDay) return info.firstDay % 7;
64
+ } catch {}
65
+ return tag.startsWith('es') ? 1 : 0;
66
+ }
67
+
68
+ /** O evento acontece neste dia? (fim exclusivo) */
69
+ const onDay = (event, day) => {
70
+ const dayStart = startOfDay(day);
71
+ const dayEnd = addDays(dayStart, 1);
72
+ return event.start < dayEnd && (event.end > dayStart || +event.start === +event.end);
73
+ };
74
+
75
+ function normalize(list) {
76
+ return (list ?? [])
77
+ .map((e, i) => {
78
+ const start = new Date(e.start);
79
+ const end = e.end ? new Date(e.end) : e.allDay ? addDays(startOfDay(start), 1) : new Date(+start + HOUR);
80
+ return { ...e, id: e.id ?? `evento-${i}`, start, end, allDay: Boolean(e.allDay), tone: TONES.includes(e.tone) ? e.tone : 'neutral' };
81
+ })
82
+ .sort((a, b) => b.allDay - a.allDay || a.start - b.start || b.end - b.start - (a.end - a.start));
83
+ }
84
+
85
+ /** Colunas para eventos que se sobrepõem num dia: grupos encadeados dividem a largura. */
86
+ function layoutDay(events) {
87
+ const placed = [];
88
+ let cluster = [];
89
+ let clusterEnd = 0;
90
+ let columns = [];
91
+ const flush = () => {
92
+ cluster.forEach((p) => (p.cols = columns.length));
93
+ cluster = [];
94
+ columns = [];
95
+ };
96
+ for (const event of events) {
97
+ const end = Math.max(+event.end, +event.start + MIN_MINUTES * 60000);
98
+ if (cluster.length && +event.start >= clusterEnd) flush();
99
+ let col = columns.findIndex((e) => e <= +event.start);
100
+ if (col === -1) {
101
+ col = columns.length;
102
+ columns.push(end);
103
+ } else columns[col] = end;
104
+ const p = { event, col, cols: 1 };
105
+ cluster.push(p);
106
+ placed.push(p);
107
+ clusterEnd = Math.max(clusterEnd, end);
108
+ }
109
+ flush();
110
+ return placed;
111
+ }
112
+
113
+ /* ───────── Componente ───────── */
114
+
115
+ export function createCalendar(root, options = {}) {
116
+ const o = {
117
+ view: 'month',
118
+ date: new Date(),
119
+ events: [],
120
+ scrollToHour: 8,
121
+ views: VIEWS,
122
+ ...options,
123
+ };
124
+ const id = `ds-calendar-${++uid}`;
125
+ let view = VIEWS.includes(o.view) ? o.view : 'month';
126
+ let date = startOfDay(new Date(o.date));
127
+ let events = normalize(o.events);
128
+ let focusKey = key(date);
129
+ let nowTimer = null;
130
+ let scrollTop = null;
131
+
132
+ const weekStart = () => o.weekStartsOn ?? localeWeekStart();
133
+ const fmt = {
134
+ time: () => {
135
+ const h12 = new Intl.DateTimeFormat(locale(), { hour: 'numeric' }).resolvedOptions().hour12;
136
+ return dateFormat(h12 ? { hour: 'numeric', minute: '2-digit' } : { hour: '2-digit', minute: '2-digit' });
137
+ },
138
+ hour: () => {
139
+ const h12 = new Intl.DateTimeFormat(locale(), { hour: 'numeric' }).resolvedOptions().hour12;
140
+ return dateFormat(h12 ? { hour: 'numeric' } : { hour: '2-digit', minute: '2-digit' });
141
+ },
142
+ };
143
+
144
+ root.classList.add('ds-calendar');
145
+
146
+ /* Título e navegação */
147
+
148
+ function range() {
149
+ if (view === 'month') {
150
+ const first = new Date(date.getFullYear(), date.getMonth(), 1);
151
+ const start = startOfWeek(first, weekStart());
152
+ const last = new Date(date.getFullYear(), date.getMonth() + 1, 0);
153
+ const weeks = Math.ceil(((last - start) / (24 * HOUR) + 1) / 7);
154
+ return { start, days: weeks * 7 };
155
+ }
156
+ if (view === 'week') return { start: startOfWeek(date, weekStart()), days: 7 };
157
+ return { start: date, days: 1 };
158
+ }
159
+
160
+ function title() {
161
+ if (view === 'month') return capitalize(dateFormat({ month: 'long', year: 'numeric' }).format(date));
162
+ if (view === 'week') {
163
+ const { start } = range();
164
+ const end = addDays(start, 6);
165
+ const f = dateFormat({ day: 'numeric', month: 'long', year: 'numeric' });
166
+ return capitalize(f.formatRange ? f.formatRange(start, end) : `${f.format(start)} – ${f.format(end)}`);
167
+ }
168
+ return capitalize(dateFormat({ weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }).format(date));
169
+ }
170
+
171
+ const header = () => `<header class="ds-calendar__header">
172
+ <h2 class="ds-calendar__title" id="${id}-title" aria-live="polite">${escape(title())}</h2>
173
+ <div class="ds-calendar__nav">
174
+ <button type="button" class="ds-btn ds-btn--secondary ds-btn--sm" data-cal="today">${msg('calendar.today')}</button>
175
+ <button type="button" class="ds-icon-btn ds-icon-btn--sm" data-cal="prev" aria-label="${msg(`calendar.prev.${view}`)}" data-ds-tooltip="${msg(`calendar.prev.${view}`)}">${icon('chevron-left', { size: 18 })}</button>
176
+ <button type="button" class="ds-icon-btn ds-icon-btn--sm" data-cal="next" aria-label="${msg(`calendar.next.${view}`)}" data-ds-tooltip="${msg(`calendar.next.${view}`)}">${icon('chevron-right', { size: 18 })}</button>
177
+ </div>
178
+ ${
179
+ o.views.length > 1
180
+ ? `<div class="ds-segmented ds-calendar__views" role="radiogroup" aria-label="${msg('calendar.view')}">
181
+ ${o.views
182
+ .map((v) => `<button type="button" class="ds-segmented__item" role="radio" data-cal-view="${v}" aria-checked="${v === view}" tabindex="${v === view ? 0 : -1}">${msg(`calendar.${v}`)}</button>`)
183
+ .join('')}
184
+ </div>`
185
+ : ''
186
+ }
187
+ </header>`;
188
+
189
+ /* Visão do mês */
190
+
191
+ const eventLabel = (e) => {
192
+ const when = e.allDay ? msg('calendar.allDay') : dateFormat({ hour: 'numeric', minute: '2-digit' }).formatRange?.(e.start, e.end) ?? `${fmt.time().format(e.start)}–${fmt.time().format(e.end)}`;
193
+ return `${e.title}, ${when}, ${dateFormat({ weekday: 'long', day: 'numeric', month: 'long' }).format(e.start)}`;
194
+ };
195
+
196
+ function monthView() {
197
+ const { start, days } = range();
198
+ const today = new Date();
199
+ const weekdays = Array.from({ length: 7 }, (_, i) => addDays(start, i));
200
+ const short = dateFormat({ weekday: 'short' });
201
+ const long = dateFormat({ weekday: 'long' });
202
+ const cellLabel = dateFormat({ weekday: 'long', day: 'numeric', month: 'long' });
203
+ const time = fmt.time();
204
+ const rows = [];
205
+ for (let w = 0; w < days / 7; w++) {
206
+ const cells = [];
207
+ for (let i = 0; i < 7; i++) {
208
+ const day = addDays(start, w * 7 + i);
209
+ const k = key(day);
210
+ const list = events.filter((e) => onDay(e, day));
211
+ const shown = list.length > MAX_IN_CELL ? list.slice(0, MAX_IN_CELL - 1) : list;
212
+ const extra = list.length - shown.length;
213
+ const isToday = sameDay(day, today);
214
+ const outside = day.getMonth() !== date.getMonth();
215
+ const label = [cellLabel.format(day), isToday ? msg('calendar.isToday') : '', msg('calendar.events', list.length)].filter(Boolean).join(', ');
216
+ cells.push(`<div class="ds-calendar__day" role="gridcell" data-date="${k}" tabindex="${k === focusKey ? 0 : -1}" aria-label="${escape(label)}"${isToday ? ' data-today aria-current="date"' : ''}${outside ? ' data-outside' : ''}>
217
+ <span class="ds-calendar__date" aria-hidden="true">${day.getDate()}</span>
218
+ ${
219
+ list.length
220
+ ? `<div class="ds-calendar__items" aria-hidden="true">
221
+ ${shown
222
+ .map((e) =>
223
+ e.allDay
224
+ ? `<span class="ds-calendar__chip ds-calendar__chip--${e.tone}" data-event-id="${escape(e.id)}" title="${escape(e.title)}">${escape(e.title)}</span>`
225
+ : `<span class="ds-calendar__item ds-calendar__item--${e.tone}" data-event-id="${escape(e.id)}" title="${escape(e.title)}"><span class="ds-calendar__dot"></span><span class="ds-calendar__item-time">${time.format(e.start)}</span><span class="ds-calendar__item-title">${escape(e.title)}</span></span>`,
226
+ )
227
+ .join('')}
228
+ ${extra ? `<span class="ds-calendar__more">${msg('calendar.more', extra)}</span>` : ''}
229
+ </div>`
230
+ : ''
231
+ }
232
+ </div>`);
233
+ }
234
+ rows.push(`<div class="ds-calendar__week" role="row">${cells.join('')}</div>`);
235
+ }
236
+ return `<div class="ds-calendar__month" role="grid" aria-labelledby="${id}-title" style="--_weeks: ${days / 7}">
237
+ <div class="ds-calendar__weekdays" role="row">
238
+ ${weekdays.map((d) => `<div class="ds-calendar__weekday" role="columnheader"><abbr title="${escape(long.format(d))}">${escape(short.format(d).replace('.', ''))}</abbr></div>`).join('')}
239
+ </div>
240
+ ${rows.join('')}
241
+ </div>`;
242
+ }
243
+
244
+ /* Visões de semana e dia: grade de horas */
245
+
246
+ function timeView() {
247
+ const { start, days } = range();
248
+ const list = Array.from({ length: days }, (_, i) => addDays(start, i));
249
+ const today = new Date();
250
+ const hour = fmt.hour();
251
+ const time = fmt.time();
252
+ const weekday = dateFormat({ weekday: 'short' });
253
+ const allDay = list.map((d) => events.filter((e) => e.allDay && onDay(e, d)));
254
+ const hasAllDay = allDay.some((l) => l.length);
255
+ const cols = `--_days: ${days}`;
256
+
257
+ const head = `<div class="ds-calendar__cols-head" style="${cols}">
258
+ <span class="ds-calendar__gutter" aria-hidden="true"></span>
259
+ ${list
260
+ .map((d) => {
261
+ const isToday = sameDay(d, today);
262
+ const label = dateFormat({ weekday: 'long', day: 'numeric', month: 'long' }).format(d);
263
+ const inner = `<span class="ds-calendar__col-weekday">${escape(weekday.format(d).replace('.', ''))}</span><span class="ds-calendar__col-date">${d.getDate()}</span>`;
264
+ return view === 'week'
265
+ ? `<button type="button" class="ds-calendar__col-head" data-cal-open="${key(d)}" aria-label="${escape(label)}"${isToday ? ' data-today aria-current="date"' : ''}>${inner}</button>`
266
+ : `<div class="ds-calendar__col-head"${isToday ? ' data-today' : ''}>${inner}</div>`;
267
+ })
268
+ .join('')}
269
+ </div>`;
270
+
271
+ const allDayRow = hasAllDay
272
+ ? `<div class="ds-calendar__allday" style="${cols}">
273
+ <span class="ds-calendar__gutter ds-calendar__allday-label">${msg('calendar.allDay')}</span>
274
+ ${allDay
275
+ .map((l) => `<div class="ds-calendar__allday-cell">${l.map((e) => `<button type="button" class="ds-calendar__chip ds-calendar__chip--${e.tone}" data-event-id="${escape(e.id)}" aria-label="${escape(eventLabel(e))}">${escape(e.title)}</button>`).join('')}</div>`)
276
+ .join('')}
277
+ </div>`
278
+ : '';
279
+
280
+ const hours = Array.from({ length: 24 }, (_, h) => `<span class="ds-calendar__hour">${h ? escape(hour.format(new Date(2026, 0, 1, h))) : ''}</span>`).join('');
281
+
282
+ const columns = list
283
+ .map((d, i) => {
284
+ const dayStart = startOfDay(d);
285
+ const timed = events.filter((e) => !e.allDay && onDay(e, d));
286
+ const blocks = layoutDay(timed).map(({ event: e, col, cols: n }) => {
287
+ const from = Math.max(0, (e.start - dayStart) / 60000);
288
+ const to = Math.min(24 * 60, (e.end - dayStart) / 60000);
289
+ const short = to - from < 45;
290
+ return `<button type="button" class="ds-calendar__event ds-calendar__event--${e.tone}${short ? ' ds-calendar__event--short' : ''}" data-event-id="${escape(e.id)}" aria-label="${escape(eventLabel(e))}"
291
+ style="--_from: ${from}; --_len: ${Math.max(to - from, MIN_MINUTES)}; --_col: ${col}; --_cols: ${n}">
292
+ <span class="ds-calendar__event-title">${escape(e.title)}</span>
293
+ <span class="ds-calendar__event-time">${time.format(e.start)}</span>
294
+ </button>`;
295
+ });
296
+ const isToday = sameDay(d, today);
297
+ return `<div class="ds-calendar__col" style="grid-column: ${i + 2}"${isToday ? ' data-today' : ''}>
298
+ ${isToday ? `<span class="ds-calendar__now" aria-hidden="true" style="--_from: ${minutesOf(today)}"></span>` : ''}
299
+ ${blocks.join('')}
300
+ </div>`;
301
+ })
302
+ .join('');
303
+
304
+ return `<div class="ds-calendar__time" role="region" aria-labelledby="${id}-title">
305
+ ${head}
306
+ ${allDayRow}
307
+ <div class="ds-calendar__scroll" data-cal-scroll tabindex="-1">
308
+ <div class="ds-calendar__grid" style="${cols}">
309
+ <div class="ds-calendar__hours" aria-hidden="true">${hours}</div>
310
+ <div class="ds-calendar__lines" aria-hidden="true">${'<span></span>'.repeat(24)}</div>
311
+ ${columns}
312
+ </div>
313
+ </div>
314
+ </div>`;
315
+ }
316
+
317
+ /* Desenho */
318
+
319
+ function render({ focus = false } = {}) {
320
+ const scroller = root.querySelector('[data-cal-scroll]');
321
+ if (scroller && view !== 'month') scrollTop = scroller.scrollTop;
322
+ root.dataset.view = view;
323
+ root.innerHTML = `${header()}<div class="ds-calendar__body">${view === 'month' ? monthView() : timeView()}</div>`;
324
+ clearInterval(nowTimer);
325
+ if (view !== 'month') {
326
+ const next = root.querySelector('[data-cal-scroll]');
327
+ const hourPx = parseFloat(getComputedStyle(root).getPropertyValue('--ds-calendar-hour')) || 48;
328
+ next.scrollTop = scrollTop ?? Math.max(0, o.scrollToHour * hourPx - 8);
329
+ nowTimer = setInterval(() => {
330
+ const now = root.querySelector('.ds-calendar__now');
331
+ if (now) now.style.setProperty('--_from', minutesOf(new Date()));
332
+ }, 60 * 1000);
333
+ }
334
+ if (focus && view === 'month') root.querySelector(`.ds-calendar__day[data-date="${focusKey}"]`)?.focus();
335
+ }
336
+
337
+ const changed = () => o.onChange?.({ view, date: new Date(date) });
338
+
339
+ function setView(next, { focus = false } = {}) {
340
+ if (!VIEWS.includes(next)) return;
341
+ if (next !== view) scrollTop = null;
342
+ view = next;
343
+ focusKey = key(date);
344
+ render();
345
+ if (focus) root.querySelector(`[data-cal-view="${view}"]`)?.focus();
346
+ changed();
347
+ }
348
+
349
+ function setDate(next, { focus = false } = {}) {
350
+ date = startOfDay(new Date(next));
351
+ focusKey = key(date);
352
+ render({ focus });
353
+ changed();
354
+ }
355
+
356
+ const step = (dir) => {
357
+ if (view === 'month') setDate(addMonths(date, dir));
358
+ else setDate(addDays(date, view === 'week' ? 7 * dir : dir));
359
+ };
360
+
361
+ const openDay = (day) => {
362
+ if (o.onDateClick) return o.onDateClick(new Date(day));
363
+ date = startOfDay(day);
364
+ setView('day');
365
+ };
366
+
367
+ /* Eventos do DOM */
368
+
369
+ const findEvent = (el) => events.find((e) => String(e.id) === el.dataset.eventId);
370
+
371
+ const onClick = (event) => {
372
+ const act = event.target.closest('[data-cal]')?.dataset.cal;
373
+ if (act === 'today') return setDate(new Date());
374
+ if (act === 'prev') return step(-1);
375
+ if (act === 'next') return step(1);
376
+ const v = event.target.closest('[data-cal-view]')?.dataset.calView;
377
+ if (v) return setView(v);
378
+ const open = event.target.closest('[data-cal-open]');
379
+ if (open) return openDay(fromKey(open.dataset.calOpen));
380
+ const chip = event.target.closest('[data-event-id]');
381
+ if (chip && o.onEventClick) {
382
+ const found = findEvent(chip);
383
+ if (found) return o.onEventClick({ ...found });
384
+ }
385
+ const cell = event.target.closest('.ds-calendar__day');
386
+ if (cell) {
387
+ focusKey = cell.dataset.date;
388
+ openDay(fromKey(cell.dataset.date));
389
+ }
390
+ };
391
+
392
+ const onKeydown = (event) => {
393
+ const views = event.target.closest('.ds-calendar__views');
394
+ if (views) {
395
+ const delta = { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 }[event.key];
396
+ if (!delta) return;
397
+ event.preventDefault();
398
+ const i = o.views.indexOf(view);
399
+ setView(o.views[(i + delta + o.views.length) % o.views.length], { focus: true });
400
+ return;
401
+ }
402
+ const cell = event.target.closest('.ds-calendar__day');
403
+ if (!cell) return;
404
+ const day = fromKey(cell.dataset.date);
405
+ const ws = weekStart();
406
+ const moves = {
407
+ ArrowRight: () => addDays(day, 1),
408
+ ArrowLeft: () => addDays(day, -1),
409
+ ArrowDown: () => addDays(day, 7),
410
+ ArrowUp: () => addDays(day, -7),
411
+ Home: () => startOfWeek(day, ws),
412
+ End: () => addDays(startOfWeek(day, ws), 6),
413
+ PageDown: () => addMonths(day, 1),
414
+ PageUp: () => addMonths(day, -1),
415
+ };
416
+ if (event.key === 'Enter' || event.key === ' ') {
417
+ event.preventDefault();
418
+ openDay(day);
419
+ return;
420
+ }
421
+ const move = moves[event.key];
422
+ if (!move) return;
423
+ event.preventDefault();
424
+ const target = move();
425
+ focusKey = key(target);
426
+ if (target.getMonth() !== date.getMonth() || target.getFullYear() !== date.getFullYear()) {
427
+ date = target;
428
+ render({ focus: true });
429
+ changed();
430
+ } else {
431
+ root.querySelectorAll('.ds-calendar__day[tabindex="0"]').forEach((c) => (c.tabIndex = -1));
432
+ const next = root.querySelector(`.ds-calendar__day[data-date="${focusKey}"]`);
433
+ next.tabIndex = 0;
434
+ next.focus();
435
+ }
436
+ };
437
+
438
+ // textos e datas acompanham a troca de idioma
439
+ const onLocale = () => render();
440
+
441
+ root.addEventListener('click', onClick);
442
+ root.addEventListener('keydown', onKeydown);
443
+ document.documentElement.addEventListener('ds:localechange', onLocale);
444
+ render();
445
+
446
+ return {
447
+ get view() {
448
+ return view;
449
+ },
450
+ get date() {
451
+ return new Date(date);
452
+ },
453
+ setView: (v) => setView(v),
454
+ setDate: (d) => setDate(d),
455
+ today: () => setDate(new Date()),
456
+ prev: () => step(-1),
457
+ next: () => step(1),
458
+ setEvents(list) {
459
+ events = normalize(list);
460
+ render();
461
+ },
462
+ destroy() {
463
+ clearInterval(nowTimer);
464
+ root.removeEventListener('click', onClick);
465
+ root.removeEventListener('keydown', onKeydown);
466
+ document.documentElement.removeEventListener('ds:localechange', onLocale);
467
+ root.innerHTML = '';
468
+ root.classList.remove('ds-calendar');
469
+ delete root.dataset.view;
470
+ },
471
+ };
472
+ }
@@ -0,0 +1,2 @@
1
+ // Gerado por scripts/build-react.mjs. Não edite.
2
+ export declare function createCarousel(root: HTMLElement, options?: Record<string, unknown>): { index: number; paused: boolean; goTo(index: number): void; next(): void; prev(): void; pause(): void; play(): void; destroy(): void };