@reservi/preact 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.
package/dist/index.js ADDED
@@ -0,0 +1,939 @@
1
+ import { render as X, h as st } from "preact";
2
+ import { getLocaleText as E, dl as l, timeStringToMinutes as z, computeDrop as A, pxToSnappedMinutes as lt, computeResize as ct, themeToStyle as vt, CalendarApi as ut, eventsToICS as mt } from "@reservi/core";
3
+ import { dayGridPlugin as Kt, definePlugin as Wt, defineTheme as Xt, eventsToICS as zt, listPlugin as qt, multiMonthPlugin as Jt, parseICS as Qt, resourcePlugin as Zt, themeToStyle as te, timeGridPlugin as ee, timelinePlugin as re } from "@reservi/core";
4
+ import { jsxs as v, jsx as n, Fragment as ht } from "preact/jsx-runtime";
5
+ import "@preact/signals";
6
+ import { useRef as F, useState as R, useEffect as q } from "preact/hooks";
7
+ function x(a, t, r) {
8
+ return a ? a(t) : r;
9
+ }
10
+ function $(...a) {
11
+ return a.filter(Boolean).join(" ");
12
+ }
13
+ const I = { prev: "‹", next: "›" }, gt = /* @__PURE__ */ new Set(["", "title", "today", "prev", "next"]), yt = /month|year/i, L = (a) => String(a).padStart(2, "0");
14
+ function ft() {
15
+ return /* @__PURE__ */ v(
16
+ "svg",
17
+ {
18
+ "data-rsv": "title-icon",
19
+ width: "14",
20
+ height: "14",
21
+ viewBox: "0 0 14 14",
22
+ fill: "none",
23
+ stroke: "currentColor",
24
+ "stroke-width": "1.3",
25
+ "stroke-linecap": "round",
26
+ "stroke-linejoin": "round",
27
+ "aria-hidden": "true",
28
+ children: [
29
+ /* @__PURE__ */ n("rect", { x: "1", y: "2.5", width: "12", height: "10.5", rx: "1.5" }),
30
+ /* @__PURE__ */ n("line", { x1: "1", y1: "5.5", x2: "13", y2: "5.5" }),
31
+ /* @__PURE__ */ n("line", { x1: "4.5", y1: "1", x2: "4.5", y2: "3.5" }),
32
+ /* @__PURE__ */ n("line", { x1: "9.5", y1: "1", x2: "9.5", y2: "3.5" })
33
+ ]
34
+ }
35
+ );
36
+ }
37
+ function pt(a) {
38
+ var r;
39
+ if ((r = a.views) != null && r.length) return a.views;
40
+ const t = a.headerToolbar;
41
+ return t ? [t.start, t.center, t.end].filter((e) => !!e).flatMap((e) => e.split(/\s+/)).flatMap((e) => e.split(",")).filter((e) => !gt.has(e)) : [];
42
+ }
43
+ function bt({ api: a, title: t, activeView: r, options: e }) {
44
+ var T, _, P, j, U;
45
+ const o = E(e.locale), i = (_ = (T = e.slots) == null ? void 0 : T.toolbarStart) == null ? void 0 : _.call(T), u = (j = (P = e.slots) == null ? void 0 : P.toolbarEnd) == null ? void 0 : j.call(P), d = pt(e), s = yt.test(r), c = e.firstDay ?? o.firstDay, h = F(null), [g, f] = R(!1), p = l.toDate(a.getDate()), y = l.toDate(e.now ? l.from(e.now) : l.now()), [w, D] = R(p.getFullYear()), [k, S] = R(p.getMonth()), M = new Intl.DateTimeFormat(e.locale, { month: "short" }), at = new Intl.DateTimeFormat(e.locale, { month: "long" }), nt = new Intl.DateTimeFormat(e.locale, { weekday: "short" }), ot = Array.from({ length: 12 }, (m, b) => M.format(new Date(2020, b, 1))), N = () => {
46
+ const m = l.toDate(a.getDate());
47
+ D(m.getFullYear()), S(m.getMonth()), f(!0);
48
+ }, H = (m) => {
49
+ const b = w * 12 + k + m;
50
+ D(Math.floor(b / 12)), S((b % 12 + 12) % 12);
51
+ }, V = (m) => {
52
+ a.gotoDate(m), f(!1);
53
+ };
54
+ q(() => {
55
+ const m = (C) => {
56
+ (C.ctrlKey || C.metaKey) && (C.key === "m" || C.key === "M") ? (C.preventDefault(), N()) : C.key === "Escape" && f(!1);
57
+ }, b = (C) => {
58
+ h.current && !h.current.contains(C.target) && f(!1);
59
+ };
60
+ return document.addEventListener("keydown", m), document.addEventListener("mousedown", b), () => {
61
+ document.removeEventListener("keydown", m), document.removeEventListener("mousedown", b);
62
+ };
63
+ }, []);
64
+ const B = (() => {
65
+ if (s) return { cells: [], dows: [] };
66
+ const m = l.from(`${w}-${L(k + 1)}-01`), b = (l.dayOfWeek(m) - c + 7) % 7, C = l.subtract(m, { days: b }), K = Array.from({ length: 42 }, (W, it) => l.toDate(l.add(C, { days: it }))), dt = K.slice(0, 7).map((W) => nt.format(W));
67
+ return { cells: K, dows: dt };
68
+ })();
69
+ return /* @__PURE__ */ v("div", { "data-rsv": "toolbar-wrap", class: $((U = e.classNames) == null ? void 0 : U.toolbar), ref: h, children: [
70
+ /* @__PURE__ */ v("div", { "data-rsv": "toolbar", children: [
71
+ /* @__PURE__ */ n("div", { "data-rsv": "toolbar-section", "data-rsv-area": "start", children: i }),
72
+ /* @__PURE__ */ v("div", { "data-rsv": "toolbar-section", "data-rsv-area": "nav", children: [
73
+ /* @__PURE__ */ n(
74
+ "button",
75
+ {
76
+ type: "button",
77
+ "data-rsv": "button",
78
+ title: o.today,
79
+ "aria-label": o.today,
80
+ onClick: () => a.today(),
81
+ children: o.today
82
+ }
83
+ ),
84
+ /* @__PURE__ */ n(
85
+ "button",
86
+ {
87
+ type: "button",
88
+ "data-rsv": "button",
89
+ "data-rsv-nav": "prev",
90
+ title: o.prev,
91
+ "aria-label": o.prev,
92
+ onClick: () => a.prev(),
93
+ children: I.prev
94
+ }
95
+ ),
96
+ /* @__PURE__ */ v("div", { "data-rsv": "datepicker-anchor", children: [
97
+ /* @__PURE__ */ v(
98
+ "button",
99
+ {
100
+ type: "button",
101
+ "data-rsv": "title",
102
+ "aria-haspopup": "dialog",
103
+ "aria-expanded": g,
104
+ title: `${t} · Ctrl+M`,
105
+ onClick: () => g ? f(!1) : N(),
106
+ children: [
107
+ /* @__PURE__ */ n(ft, {}),
108
+ t
109
+ ]
110
+ }
111
+ ),
112
+ g && /* @__PURE__ */ v("div", { "data-rsv": "datepicker", "data-rsv-mode": s ? "month" : "day", role: "dialog", "aria-label": t, children: [
113
+ /* @__PURE__ */ v("div", { "data-rsv": "dp-head", children: [
114
+ /* @__PURE__ */ n(
115
+ "button",
116
+ {
117
+ type: "button",
118
+ "data-rsv": "dp-nav",
119
+ "aria-label": o.prev,
120
+ onClick: () => s ? D((m) => m - 1) : H(-1),
121
+ children: I.prev
122
+ }
123
+ ),
124
+ /* @__PURE__ */ n("span", { "data-rsv": "dp-label", children: s ? w : `${at.format(new Date(w, k, 1))} ${w}` }),
125
+ /* @__PURE__ */ n(
126
+ "button",
127
+ {
128
+ type: "button",
129
+ "data-rsv": "dp-nav",
130
+ "aria-label": o.next,
131
+ onClick: () => s ? D((m) => m + 1) : H(1),
132
+ children: I.next
133
+ }
134
+ )
135
+ ] }),
136
+ s ? /* @__PURE__ */ n("div", { "data-rsv": "dp-grid", children: ot.map((m, b) => /* @__PURE__ */ n(
137
+ "button",
138
+ {
139
+ type: "button",
140
+ "data-rsv": "dp-month",
141
+ "data-active": String(
142
+ w === p.getFullYear() && b === p.getMonth()
143
+ ),
144
+ "data-today": String(w === y.getFullYear() && b === y.getMonth()),
145
+ onClick: () => V(`${w}-${L(b + 1)}-01`),
146
+ children: m
147
+ },
148
+ m
149
+ )) }) : /* @__PURE__ */ v("div", { "data-rsv": "dp-days", children: [
150
+ B.dows.map((m, b) => /* @__PURE__ */ n("div", { "data-rsv": "dp-dow", children: m }, `dow-${b}`)),
151
+ B.cells.map((m) => {
152
+ const b = `${m.getFullYear()}-${L(m.getMonth() + 1)}-${L(m.getDate())}`;
153
+ return /* @__PURE__ */ n(
154
+ "button",
155
+ {
156
+ type: "button",
157
+ "data-rsv": "dp-day",
158
+ "data-other": String(m.getMonth() !== k),
159
+ "data-active": String(
160
+ m.getFullYear() === p.getFullYear() && m.getMonth() === p.getMonth() && m.getDate() === p.getDate()
161
+ ),
162
+ "data-today": String(
163
+ m.getFullYear() === y.getFullYear() && m.getMonth() === y.getMonth() && m.getDate() === y.getDate()
164
+ ),
165
+ onClick: () => V(b),
166
+ children: m.getDate()
167
+ },
168
+ b
169
+ );
170
+ })
171
+ ] })
172
+ ] })
173
+ ] }),
174
+ /* @__PURE__ */ n(
175
+ "button",
176
+ {
177
+ type: "button",
178
+ "data-rsv": "button",
179
+ "data-rsv-nav": "next",
180
+ title: o.next,
181
+ "aria-label": o.next,
182
+ onClick: () => a.next(),
183
+ children: I.next
184
+ }
185
+ )
186
+ ] }),
187
+ /* @__PURE__ */ v("div", { "data-rsv": "toolbar-section", "data-rsv-area": "end", children: [
188
+ u,
189
+ e.onAddClick && /* @__PURE__ */ v(
190
+ "button",
191
+ {
192
+ type: "button",
193
+ "data-rsv": "button",
194
+ "data-rsv-variant": "primary",
195
+ onClick: e.onAddClick,
196
+ children: [
197
+ /* @__PURE__ */ n("span", { "data-rsv": "add-icon", "aria-hidden": "true", children: "+" }),
198
+ e.addButtonText
199
+ ]
200
+ }
201
+ )
202
+ ] })
203
+ ] }),
204
+ d.length > 0 && /* @__PURE__ */ n("div", { "data-rsv": "toolbar-views", role: "tablist", children: d.map((m) => /* @__PURE__ */ n(
205
+ "button",
206
+ {
207
+ type: "button",
208
+ "data-rsv": "view-tab",
209
+ role: "tab",
210
+ "aria-selected": m === r,
211
+ "data-active": String(m === r),
212
+ onClick: () => a.changeView(m),
213
+ children: o.views[m] ?? m
214
+ },
215
+ m
216
+ )) })
217
+ ] });
218
+ }
219
+ function J(a, t) {
220
+ a.trigger("navLinkDay", { date: t });
221
+ const r = a.hasView("timeGridDay") ? "timeGridDay" : a.hasView("dayGridDay") ? "dayGridDay" : null;
222
+ r && (a.gotoDate(l.toISOString(t)), a.changeView(r));
223
+ }
224
+ const O = 1440;
225
+ function Q(a, t) {
226
+ const { api: r, event: e, kind: o } = t, i = z(t.snap ?? "00:30");
227
+ let u = 0;
228
+ switch (a.key) {
229
+ case "ArrowLeft":
230
+ u = -O;
231
+ break;
232
+ case "ArrowRight":
233
+ u = O;
234
+ break;
235
+ case "ArrowUp":
236
+ u = o === "timeGrid" ? -i : -O * 7;
237
+ break;
238
+ case "ArrowDown":
239
+ u = o === "timeGrid" ? i : O * 7;
240
+ break;
241
+ case "Enter":
242
+ case " ":
243
+ a.preventDefault(), r.trigger("eventClick", { event: e });
244
+ return;
245
+ default:
246
+ return;
247
+ }
248
+ a.preventDefault();
249
+ const d = A(e.start, e.end, u, l);
250
+ if (r.moveEvent(e.id, d.start, d.end)) {
251
+ const s = r.getEventById(e.id);
252
+ s && r.trigger("eventDrop", { event: s });
253
+ }
254
+ }
255
+ const wt = 1440, Dt = 4;
256
+ function Z(a, t) {
257
+ var e;
258
+ const r = document.elementFromPoint(a, t);
259
+ return ((e = r == null ? void 0 : r.closest('[data-rsv="day"]')) == null ? void 0 : e.dataset.date) ?? null;
260
+ }
261
+ function kt(a, t) {
262
+ a.stopPropagation();
263
+ const { api: r, event: e, sourceDate: o } = t, i = a.clientX, u = a.clientY;
264
+ let d = !1;
265
+ const s = (h) => {
266
+ !d && Math.hypot(h.clientX - i, h.clientY - u) > Dt && (d = !0, document.body.style.cursor = "grabbing");
267
+ }, c = (h) => {
268
+ var y;
269
+ if (document.removeEventListener("pointermove", s), document.removeEventListener("pointerup", c), document.body.style.cursor = "", !d) return;
270
+ (y = t.onMoved) == null || y.call(t);
271
+ const g = Z(h.clientX, h.clientY);
272
+ if (!g) return;
273
+ const f = l.diff(l.from(o), l.from(g), "day");
274
+ if (f === 0) return;
275
+ const p = A(e.start, e.end, f * wt, l);
276
+ if (r.moveEvent(e.id, p.start, p.end)) {
277
+ const w = r.getEventById(e.id);
278
+ w && r.trigger("eventDrop", { event: w });
279
+ }
280
+ };
281
+ document.addEventListener("pointermove", s), document.addEventListener("pointerup", c);
282
+ }
283
+ function Ct(a, t) {
284
+ if (a.target.closest('[data-rsv="event"], [data-rsv="more-anchor"], [data-nav-link="true"]'))
285
+ return;
286
+ const { api: e } = t;
287
+ let o = t.startDate, i = !1;
288
+ const u = (s) => {
289
+ const c = Z(s.clientX, s.clientY);
290
+ c && c !== t.startDate && (i = !0), c && (o = c);
291
+ }, d = () => {
292
+ var f;
293
+ if (document.removeEventListener("pointermove", u), document.removeEventListener("pointerup", d), !i) return;
294
+ (f = t.onRangeSelect) == null || f.call(t);
295
+ const s = l.from(t.startDate), c = l.from(o), [h, g] = l.isBefore(s, c) ? [s, c] : [c, s];
296
+ e.select(l.toISOString(h), l.toISOString(l.add(g, { days: 1 })));
297
+ };
298
+ document.addEventListener("pointermove", u), document.addEventListener("pointerup", d);
299
+ }
300
+ function tt({ api: a, model: t, options: r }) {
301
+ var d;
302
+ const e = r.locale ?? "en", o = new Intl.DateTimeFormat(e, { weekday: "short" }), i = ((d = t.weeks[0]) == null ? void 0 : d.days) ?? [], u = r.weekNumbers === !0;
303
+ return /* @__PURE__ */ v(
304
+ "div",
305
+ {
306
+ "data-rsv": "daygrid",
307
+ "data-weeknumbers": String(u),
308
+ style: `--rsv-cols:${t.columnCount}`,
309
+ children: [
310
+ /* @__PURE__ */ v("div", { "data-rsv": "daygrid-header", role: "row", children: [
311
+ u && /* @__PURE__ */ n("div", { "data-rsv": "daygrid-weeknum-header", role: "columnheader" }),
312
+ i.map((s) => {
313
+ var g;
314
+ const c = l.toDate(s.date), h = o.format(c);
315
+ return /* @__PURE__ */ n("div", { "data-rsv": "daygrid-dow", role: "columnheader", children: x((g = r.slots) == null ? void 0 : g.dayHeaderContent, { date: c, text: h }, h) }, s.dayOfWeek);
316
+ })
317
+ ] }),
318
+ t.weeks.map((s, c) => /* @__PURE__ */ v("div", { "data-rsv": "daygrid-week", role: "row", children: [
319
+ u && /* @__PURE__ */ n("div", { "data-rsv": "daygrid-weeknum", role: "rowheader", children: s.weekNumber }),
320
+ s.days.map((h) => /* @__PURE__ */ n(St, { api: a, cell: h, options: r }, l.toISOString(h.date)))
321
+ ] }, c))
322
+ ]
323
+ }
324
+ );
325
+ }
326
+ function St({
327
+ api: a,
328
+ cell: t,
329
+ options: r
330
+ }) {
331
+ var p;
332
+ const e = l.toDate(t.date), o = l.dayOfMonth(t.date), i = r.navLinks ? /* @__PURE__ */ n(
333
+ "a",
334
+ {
335
+ "data-rsv": "day-number",
336
+ "data-nav-link": "true",
337
+ role: "link",
338
+ tabIndex: 0,
339
+ onClick: (y) => {
340
+ y.stopPropagation(), J(a, t.date);
341
+ },
342
+ children: o
343
+ }
344
+ ) : /* @__PURE__ */ n("span", { "data-rsv": "day-number", children: o }), u = x(
345
+ (p = r.slots) == null ? void 0 : p.dayCellContent,
346
+ { date: e, dayNumber: o, isToday: t.isToday, isOther: t.isOther },
347
+ i
348
+ ), [d, s] = R(!1), c = l.toISOString(t.date), h = F(!1), g = () => {
349
+ if (h.current) {
350
+ h.current = !1;
351
+ return;
352
+ }
353
+ a.trigger("dateClick", { date: t.date }), r.selectable && a.select(c, l.toISOString(l.add(t.date, { days: 1 })));
354
+ }, f = (y) => {
355
+ y.stopPropagation(), s(!0), a.trigger("moreLinkClick", {
356
+ date: t.date,
357
+ allEvents: [...t.events, ...t.hiddenEvents],
358
+ hiddenEvents: t.hiddenEvents
359
+ });
360
+ };
361
+ return /* @__PURE__ */ v(
362
+ "div",
363
+ {
364
+ "data-rsv": "day",
365
+ role: "gridcell",
366
+ "data-date": c,
367
+ "data-today": String(t.isToday),
368
+ "data-other": String(t.isOther),
369
+ "data-weekend": String(t.isWeekend),
370
+ "data-business": String(t.isBusiness),
371
+ "data-selected": String(t.isSelected),
372
+ onClick: g,
373
+ onPointerDown: r.selectable ? (y) => Ct(y, {
374
+ api: a,
375
+ startDate: c,
376
+ onRangeSelect: () => {
377
+ h.current = !0;
378
+ }
379
+ }) : void 0,
380
+ children: [
381
+ u,
382
+ t.events.filter((y) => y.display !== "none").map((y) => /* @__PURE__ */ n(et, { api: a, event: y, options: r, sourceDate: c }, y.id)),
383
+ t.moreCount > 0 && /* @__PURE__ */ v("div", { "data-rsv": "more-anchor", children: [
384
+ /* @__PURE__ */ n("button", { type: "button", "data-rsv": "more-link", onClick: f, children: E(r.locale).more(t.moreCount) }),
385
+ d && /* @__PURE__ */ n(
386
+ xt,
387
+ {
388
+ api: a,
389
+ cell: t,
390
+ options: r,
391
+ onClose: () => s(!1)
392
+ }
393
+ )
394
+ ] })
395
+ ]
396
+ }
397
+ );
398
+ }
399
+ function xt({
400
+ api: a,
401
+ cell: t,
402
+ options: r,
403
+ onClose: e
404
+ }) {
405
+ const o = F(null), i = new Intl.DateTimeFormat(r.locale ?? "en", {
406
+ weekday: "long",
407
+ day: "numeric",
408
+ month: "long"
409
+ }), u = [...t.events, ...t.hiddenEvents].filter((d) => d.display !== "none");
410
+ return q(() => {
411
+ const d = (c) => {
412
+ o.current && !o.current.contains(c.target) && e();
413
+ }, s = (c) => {
414
+ c.key === "Escape" && e();
415
+ };
416
+ return document.addEventListener("mousedown", d), document.addEventListener("keydown", s), () => {
417
+ document.removeEventListener("mousedown", d), document.removeEventListener("keydown", s);
418
+ };
419
+ }, [e]), /* @__PURE__ */ v("div", { "data-rsv": "more-popover", role: "dialog", ref: o, onClick: (d) => d.stopPropagation(), children: [
420
+ /* @__PURE__ */ v("div", { "data-rsv": "more-popover-header", children: [
421
+ /* @__PURE__ */ n("span", { "data-rsv": "more-popover-title", children: i.format(l.toDate(t.date)) }),
422
+ /* @__PURE__ */ n("button", { type: "button", "data-rsv": "more-popover-close", "aria-label": "✕", onClick: e, children: "✕" })
423
+ ] }),
424
+ /* @__PURE__ */ n("div", { "data-rsv": "more-popover-body", children: u.map((d) => /* @__PURE__ */ n(
425
+ et,
426
+ {
427
+ api: a,
428
+ event: d,
429
+ options: r,
430
+ sourceDate: l.toISOString(t.date)
431
+ },
432
+ d.id
433
+ )) })
434
+ ] });
435
+ }
436
+ function et({
437
+ api: a,
438
+ event: t,
439
+ options: r,
440
+ sourceDate: e
441
+ }) {
442
+ var s;
443
+ const o = r.editable === !0 && t.editable !== !1, i = F(!1), u = t.allDay ? "" : l.format(t.start, "HH:mm"), d = x(
444
+ (s = r.slots) == null ? void 0 : s.eventContent,
445
+ { event: t, isAllDay: t.allDay, timeText: u },
446
+ /* @__PURE__ */ v("span", { "data-rsv": "event-title", children: [
447
+ u ? `${u} ` : "",
448
+ t.title
449
+ ] })
450
+ );
451
+ return /* @__PURE__ */ n(
452
+ "div",
453
+ {
454
+ "data-rsv": "event",
455
+ role: "button",
456
+ tabIndex: 0,
457
+ class: $(...t.classNames),
458
+ "data-all-day": String(t.allDay),
459
+ "data-display": t.display,
460
+ "data-event-id": t.id,
461
+ "data-editable": String(o),
462
+ style: `--rsv-event-bg:${t.backgroundColor};--rsv-event-fg:${t.textColor}`,
463
+ onClick: (c) => {
464
+ if (c.stopPropagation(), i.current) {
465
+ i.current = !1;
466
+ return;
467
+ }
468
+ a.trigger("eventClick", { event: t }), t.url && window.open(t.url, "_self");
469
+ },
470
+ onPointerDown: o ? (c) => kt(c, {
471
+ api: a,
472
+ event: t,
473
+ sourceDate: e,
474
+ onMoved: () => {
475
+ i.current = !0;
476
+ }
477
+ }) : void 0,
478
+ onKeyDown: o ? (c) => Q(c, { api: a, event: t, kind: "dayGrid" }) : void 0,
479
+ children: d
480
+ }
481
+ );
482
+ }
483
+ function G(a, t) {
484
+ a.preventDefault(), a.stopPropagation();
485
+ const { api: r, event: e, model: o, columnEl: i, snap: u = "00:15", edge: d } = t, s = i.getBoundingClientRect(), c = o.maxMinutes - o.minMinutes, h = s.height === 0 ? 0 : s.height / c, g = a.clientY, f = (p) => {
486
+ document.removeEventListener("pointerup", f);
487
+ const y = lt(p.clientY - g, h, u);
488
+ if (y === 0) return;
489
+ const w = d ? ct(e.start, e.end, d, y, l) : A(e.start, e.end, y, l);
490
+ if (r.moveEvent(e.id, w.start, w.end)) {
491
+ const D = r.getEventById(e.id);
492
+ D && r.trigger(d ? "eventResize" : "eventDrop", { event: D });
493
+ }
494
+ };
495
+ document.addEventListener("pointerup", f);
496
+ }
497
+ function Mt(a, t) {
498
+ if (a.target.closest('[data-rsv="event"]')) return;
499
+ const { api: r, date: e, model: o, columnEl: i, snap: u = "00:15" } = t, d = i.getBoundingClientRect(), s = o.maxMinutes - o.minMinutes, c = d.height === 0 ? 0 : d.height / s, h = z(u) || 15, g = (k) => {
500
+ const S = o.minMinutes + (c === 0 ? 0 : (k - d.top) / c), M = Math.max(o.minMinutes, Math.min(o.maxMinutes, S));
501
+ return Math.round(M / h) * h;
502
+ }, f = g(a.clientY);
503
+ let p = f, y = !1;
504
+ const w = (k) => {
505
+ const S = g(k.clientY);
506
+ S !== f && (y = !0), p = S;
507
+ }, D = () => {
508
+ if (document.removeEventListener("pointermove", w), document.removeEventListener("pointerup", D), !y) return;
509
+ const k = Math.min(f, p), S = Math.max(f, p), M = l.startOf(e, "day");
510
+ r.select(
511
+ l.toISOString(l.add(M, { minutes: k })),
512
+ l.toISOString(l.add(M, { minutes: S }))
513
+ );
514
+ };
515
+ document.addEventListener("pointermove", w), document.addEventListener("pointerup", D);
516
+ }
517
+ function Et({ api: a, model: t, options: r }) {
518
+ const e = r.locale ?? "en", o = new Intl.DateTimeFormat(e, { weekday: "short", day: "numeric" }), i = r.allDaySlot !== !1, u = `calc(var(--spacing-rsv-slot, 2.5rem) * ${t.slots.length})`;
519
+ return /* @__PURE__ */ v("div", { "data-rsv": "timegrid", style: `--rsv-tg-days:${t.days.length}`, children: [
520
+ /* @__PURE__ */ v("div", { "data-rsv": "tg-header", role: "row", children: [
521
+ /* @__PURE__ */ n("div", { "data-rsv": "tg-axis-corner" }),
522
+ t.days.map((d) => /* @__PURE__ */ n(
523
+ "div",
524
+ {
525
+ "data-rsv": "tg-col-header",
526
+ role: "columnheader",
527
+ "data-today": String(d.isToday),
528
+ "data-nav-link": r.navLinks ? "true" : void 0,
529
+ onClick: r.navLinks ? () => J(a, d.date) : void 0,
530
+ children: o.format(l.toDate(d.date))
531
+ },
532
+ l.toISOString(d.date)
533
+ ))
534
+ ] }),
535
+ i && /* @__PURE__ */ v("div", { "data-rsv": "tg-allday", role: "row", children: [
536
+ /* @__PURE__ */ n("div", { "data-rsv": "tg-axis-label", children: E(r.locale).allDay }),
537
+ t.days.map((d) => /* @__PURE__ */ n("div", { "data-rsv": "tg-allday-cell", children: d.allDayEvents.filter((s) => s.display !== "none").map((s) => /* @__PURE__ */ n(
538
+ "div",
539
+ {
540
+ "data-rsv": "event",
541
+ "data-all-day": "true",
542
+ class: $(...s.classNames),
543
+ "data-display": s.display,
544
+ style: `--rsv-event-bg:${s.backgroundColor}`,
545
+ onClick: () => {
546
+ a.trigger("eventClick", { event: s }), s.url && window.open(s.url, "_self");
547
+ },
548
+ children: s.title
549
+ },
550
+ s.id
551
+ )) }, l.toISOString(d.date)))
552
+ ] }),
553
+ /* @__PURE__ */ v("div", { "data-rsv": "tg-body", children: [
554
+ /* @__PURE__ */ n("div", { "data-rsv": "tg-axis", style: `height:${u}`, children: t.slots.map((d) => {
555
+ var s;
556
+ return /* @__PURE__ */ n("div", { "data-rsv": "tg-slot", "data-major": String(d.isMajor), children: /* @__PURE__ */ n("span", { "data-rsv": "tg-slot-label", children: x(
557
+ (s = r.slots) == null ? void 0 : s.slotLabelContent,
558
+ { text: d.label, minutes: d.offsetMin, isMajor: d.isMajor },
559
+ d.label
560
+ ) }) }, d.offsetMin);
561
+ }) }),
562
+ t.days.map((d, s) => {
563
+ var c;
564
+ return /* @__PURE__ */ v(
565
+ "div",
566
+ {
567
+ "data-rsv": "tg-col",
568
+ "data-today": String(d.isToday),
569
+ style: `height:${u}`,
570
+ onClick: () => a.trigger("dateClick", { date: d.date }),
571
+ onPointerDown: r.selectable ? (h) => Mt(h, {
572
+ api: a,
573
+ date: d.date,
574
+ model: t,
575
+ columnEl: h.currentTarget,
576
+ snap: r.snapDuration ?? r.slotDuration
577
+ }) : void 0,
578
+ children: [
579
+ r.businessHours && !d.businessPct && /* @__PURE__ */ n("div", { "data-rsv": "tg-nonbusiness", style: "top:0;height:100%" }),
580
+ d.businessPct && /* @__PURE__ */ v(ht, { children: [
581
+ /* @__PURE__ */ n("div", { "data-rsv": "tg-nonbusiness", style: `top:0;height:${d.businessPct.topPct}%` }),
582
+ /* @__PURE__ */ n(
583
+ "div",
584
+ {
585
+ "data-rsv": "tg-nonbusiness",
586
+ style: `top:${d.businessPct.bottomPct}%;height:${100 - d.businessPct.bottomPct}%`
587
+ }
588
+ )
589
+ ] }),
590
+ d.timedSegs.filter((h) => h.event.display !== "none").map((h) => /* @__PURE__ */ n($t, { api: a, seg: h, model: t, options: r }, h.event.id)),
591
+ ((c = t.nowIndicator) == null ? void 0 : c.dayIndex) === s && /* @__PURE__ */ n("div", { "data-rsv": "now-indicator", style: `top:${t.nowIndicator.topPct}%` })
592
+ ]
593
+ },
594
+ l.toISOString(d.date)
595
+ );
596
+ })
597
+ ] })
598
+ ] });
599
+ }
600
+ function $t({
601
+ api: a,
602
+ seg: t,
603
+ model: r,
604
+ options: e
605
+ }) {
606
+ var h;
607
+ const { event: o } = t, i = e.editable === !0 && o.editable !== !1, u = 100 / t.colCount, d = l.format(o.start, "HH:mm"), s = x(
608
+ (h = e.slots) == null ? void 0 : h.eventContent,
609
+ { event: o, isAllDay: !1, timeText: d },
610
+ /* @__PURE__ */ v("span", { "data-rsv": "event-title", children: [
611
+ d,
612
+ " ",
613
+ o.title
614
+ ] })
615
+ ), c = (g) => g.closest('[data-rsv="tg-col"]') ?? g;
616
+ return /* @__PURE__ */ v(
617
+ "div",
618
+ {
619
+ "data-rsv": "event",
620
+ "data-all-day": "false",
621
+ "data-display": o.display,
622
+ "data-event-id": o.id,
623
+ class: $(...o.classNames),
624
+ role: "button",
625
+ tabIndex: 0,
626
+ style: `position:absolute;top:${t.topPct}%;height:${t.heightPct}%;left:${t.col * u}%;width:${u}%;--rsv-event-bg:${o.backgroundColor};--rsv-event-fg:${o.textColor}`,
627
+ onClick: (g) => {
628
+ g.stopPropagation(), a.trigger("eventClick", { event: o }), o.url && window.open(o.url, "_self");
629
+ },
630
+ onKeyDown: i ? (g) => Q(g, {
631
+ api: a,
632
+ event: o,
633
+ kind: "timeGrid",
634
+ snap: e.snapDuration ?? e.slotDuration
635
+ }) : void 0,
636
+ onPointerDown: i ? (g) => G(g, {
637
+ api: a,
638
+ event: o,
639
+ model: r,
640
+ columnEl: c(g.currentTarget),
641
+ snap: e.snapDuration
642
+ }) : void 0,
643
+ children: [
644
+ i && /* @__PURE__ */ n(
645
+ "span",
646
+ {
647
+ "data-rsv": "resize-handle",
648
+ "data-edge": "start",
649
+ onPointerDown: (g) => G(g, {
650
+ api: a,
651
+ event: o,
652
+ model: r,
653
+ columnEl: c(g.currentTarget),
654
+ snap: e.snapDuration,
655
+ edge: "start"
656
+ })
657
+ }
658
+ ),
659
+ s,
660
+ i && /* @__PURE__ */ n(
661
+ "span",
662
+ {
663
+ "data-rsv": "resize-handle",
664
+ "data-edge": "end",
665
+ onPointerDown: (g) => G(g, {
666
+ api: a,
667
+ event: o,
668
+ model: r,
669
+ columnEl: c(g.currentTarget),
670
+ snap: e.snapDuration,
671
+ edge: "end"
672
+ })
673
+ }
674
+ )
675
+ ]
676
+ }
677
+ );
678
+ }
679
+ function Tt({ api: a, model: t, options: r }) {
680
+ const e = r.locale ?? "en", o = E(r.locale), i = new Intl.DateTimeFormat(e, {
681
+ weekday: "long",
682
+ day: "numeric",
683
+ month: "long"
684
+ });
685
+ return t.isEmpty ? /* @__PURE__ */ n("div", { "data-rsv": "list", children: /* @__PURE__ */ n("div", { "data-rsv": "list-empty", children: o.noEvents }) }) : /* @__PURE__ */ n("div", { "data-rsv": "list", role: "list", children: t.days.map((u) => /* @__PURE__ */ v("div", { "data-rsv": "list-day", "data-today": String(u.isToday), children: [
686
+ /* @__PURE__ */ n("div", { "data-rsv": "list-day-header", role: "heading", "aria-level": 3, children: i.format(l.toDate(u.date)) }),
687
+ u.events.filter((d) => d.display !== "none").map((d) => {
688
+ var c;
689
+ const s = d.allDay ? o.allDay : l.format(d.start, "HH:mm");
690
+ return /* @__PURE__ */ v(
691
+ "div",
692
+ {
693
+ "data-rsv": "list-item",
694
+ role: "listitem",
695
+ tabIndex: 0,
696
+ class: $(...d.classNames),
697
+ "data-display": d.display,
698
+ onClick: () => {
699
+ a.trigger("eventClick", { event: d }), d.url && window.open(d.url, "_self");
700
+ },
701
+ children: [
702
+ /* @__PURE__ */ n("span", { "data-rsv": "list-item-time", children: s }),
703
+ /* @__PURE__ */ n(
704
+ "span",
705
+ {
706
+ "data-rsv": "list-item-dot",
707
+ style: `--rsv-event-bg:${d.backgroundColor}`
708
+ }
709
+ ),
710
+ /* @__PURE__ */ n("span", { "data-rsv": "list-item-title", children: x(
711
+ (c = r.slots) == null ? void 0 : c.eventContent,
712
+ { event: d, isAllDay: d.allDay, timeText: s },
713
+ d.title
714
+ ) })
715
+ ]
716
+ },
717
+ d.id
718
+ );
719
+ })
720
+ ] }, l.toISOString(u.date))) });
721
+ }
722
+ function Pt({ api: a, model: t, options: r }) {
723
+ const e = r.locale ?? "en", o = new Intl.DateTimeFormat(e, { month: "long" });
724
+ return /* @__PURE__ */ n("div", { "data-rsv": "multimonth", children: t.months.map((i) => /* @__PURE__ */ v("section", { "data-rsv": "mm-month", children: [
725
+ /* @__PURE__ */ n("header", { "data-rsv": "mm-title", children: o.format(l.toDate(i.date)) }),
726
+ /* @__PURE__ */ n(tt, { api: a, model: i.dayGrid, options: r })
727
+ ] }, l.toISOString(i.date))) });
728
+ }
729
+ const Y = 1.6;
730
+ function It({ api: a, model: t, options: r }) {
731
+ return /* @__PURE__ */ v("div", { "data-rsv": "timeline", children: [
732
+ /* @__PURE__ */ n("div", { "data-rsv": "tl-axis", role: "row", children: t.slots.map((e) => /* @__PURE__ */ n("div", { "data-rsv": "tl-slot", style: `left:${e.leftPct}%`, children: e.label }, e.leftPct)) }),
733
+ /* @__PURE__ */ n("div", { "data-rsv": "tl-body", style: `height:${t.laneCount * Y + 0.5}rem`, children: t.segs.map((e) => /* @__PURE__ */ n(rt, { api: a, seg: e, options: r }, e.event.id)) })
734
+ ] });
735
+ }
736
+ function rt({
737
+ api: a,
738
+ seg: t,
739
+ options: r
740
+ }) {
741
+ var o;
742
+ const { event: e } = t;
743
+ return /* @__PURE__ */ n(
744
+ "div",
745
+ {
746
+ "data-rsv": "event",
747
+ "data-event-id": e.id,
748
+ role: "button",
749
+ tabIndex: 0,
750
+ style: `position:absolute;left:${t.leftPct}%;width:${t.widthPct}%;top:${t.lane * Y}rem;height:${Y - 0.2}rem;--rsv-event-bg:${e.backgroundColor};--rsv-event-fg:${e.textColor}`,
751
+ onClick: () => a.trigger("eventClick", { event: e }),
752
+ children: x((o = r.slots) == null ? void 0 : o.eventContent, { event: e, isAllDay: e.allDay, timeText: "" }, e.title)
753
+ }
754
+ );
755
+ }
756
+ const Lt = 1.6;
757
+ function Ot({ api: a, model: t, options: r }) {
758
+ return /* @__PURE__ */ v("div", { "data-rsv": "resource-timeline", children: [
759
+ /* @__PURE__ */ v("div", { "data-rsv": "rt-header", role: "row", children: [
760
+ /* @__PURE__ */ n("div", { "data-rsv": "resource-area-header", children: r.locale === "es" ? "Recursos" : "Resources" }),
761
+ /* @__PURE__ */ n("div", { "data-rsv": "tl-axis", children: t.slots.map((e) => /* @__PURE__ */ n("div", { "data-rsv": "tl-slot", style: `left:${e.leftPct}%`, children: e.label }, e.leftPct)) })
762
+ ] }),
763
+ t.lanes.map((e) => {
764
+ const o = e.laneCount * Lt + 0.4;
765
+ return /* @__PURE__ */ v("div", { "data-rsv": "resource-row", role: "row", children: [
766
+ /* @__PURE__ */ v(
767
+ "div",
768
+ {
769
+ "data-rsv": "resource-label",
770
+ style: `padding-inline-start:${0.5 + e.row.depth * 1}rem`,
771
+ children: [
772
+ e.row.hasChildren && /* @__PURE__ */ n(
773
+ "button",
774
+ {
775
+ type: "button",
776
+ "data-rsv": "resource-toggle",
777
+ "aria-expanded": e.row.expanded,
778
+ onClick: () => a.toggleResource(e.row.resource.id),
779
+ children: e.row.expanded ? "▾" : "▸"
780
+ }
781
+ ),
782
+ /* @__PURE__ */ n("span", { "data-rsv": "resource-title", children: e.row.resource.title })
783
+ ]
784
+ }
785
+ ),
786
+ /* @__PURE__ */ n("div", { "data-rsv": "resource-lane", style: `height:${o}rem`, children: e.segs.map((i) => /* @__PURE__ */ n(rt, { api: a, seg: i, options: r }, i.event.id)) })
787
+ ] }, e.row.resource.id);
788
+ })
789
+ ] });
790
+ }
791
+ function Rt({ api: a, model: t, options: r }) {
792
+ const e = `calc(var(--spacing-rsv-slot, 2.5rem) * ${t.slots.length})`;
793
+ return /* @__PURE__ */ v("div", { "data-rsv": "timegrid", style: `--rsv-tg-days:${t.columns.length}`, children: [
794
+ /* @__PURE__ */ v("div", { "data-rsv": "tg-header", role: "row", children: [
795
+ /* @__PURE__ */ n("div", { "data-rsv": "tg-axis-corner" }),
796
+ t.columns.map((o) => /* @__PURE__ */ n("div", { "data-rsv": "tg-col-header", role: "columnheader", children: o.row.resource.title }, o.row.resource.id))
797
+ ] }),
798
+ /* @__PURE__ */ v("div", { "data-rsv": "tg-allday", role: "row", children: [
799
+ /* @__PURE__ */ n("div", { "data-rsv": "tg-axis-label", children: E(r.locale).allDay }),
800
+ t.columns.map((o) => /* @__PURE__ */ n("div", { "data-rsv": "tg-allday-cell", children: o.allDayEvents.map((i) => /* @__PURE__ */ n(
801
+ "div",
802
+ {
803
+ "data-rsv": "event",
804
+ "data-all-day": "true",
805
+ style: `--rsv-event-bg:${i.backgroundColor}`,
806
+ onClick: () => a.trigger("eventClick", { event: i }),
807
+ children: i.title
808
+ },
809
+ i.id
810
+ )) }, o.row.resource.id))
811
+ ] }),
812
+ /* @__PURE__ */ v("div", { "data-rsv": "tg-body", children: [
813
+ /* @__PURE__ */ n("div", { "data-rsv": "tg-axis", style: `height:${e}`, children: t.slots.map((o) => /* @__PURE__ */ n("div", { "data-rsv": "tg-slot", "data-major": String(o.isMajor), children: /* @__PURE__ */ n("span", { "data-rsv": "tg-slot-label", children: o.label }) }, o.offsetMin)) }),
814
+ t.columns.map((o) => /* @__PURE__ */ v(
815
+ "div",
816
+ {
817
+ "data-rsv": "tg-col",
818
+ "data-rsv-resource-id": o.row.resource.id,
819
+ style: `height:${e}`,
820
+ children: [
821
+ o.timedSegs.map((i) => {
822
+ const u = 100 / i.colCount;
823
+ return /* @__PURE__ */ v(
824
+ "div",
825
+ {
826
+ "data-rsv": "event",
827
+ "data-all-day": "false",
828
+ "data-event-id": i.event.id,
829
+ role: "button",
830
+ tabIndex: 0,
831
+ style: `position:absolute;top:${i.topPct}%;height:${i.heightPct}%;left:${i.col * u}%;width:${u}%;--rsv-event-bg:${i.event.backgroundColor};--rsv-event-fg:${i.event.textColor}`,
832
+ onClick: (d) => {
833
+ d.stopPropagation(), a.trigger("eventClick", { event: i.event });
834
+ },
835
+ children: [
836
+ l.format(i.event.start, "HH:mm"),
837
+ " ",
838
+ i.event.title
839
+ ]
840
+ },
841
+ i.event.id
842
+ );
843
+ }),
844
+ t.nowTopPct != null && /* @__PURE__ */ n("div", { "data-rsv": "now-indicator", style: `top:${t.nowTopPct}%` })
845
+ ]
846
+ },
847
+ o.row.resource.id
848
+ ))
849
+ ] })
850
+ ] });
851
+ }
852
+ function Ft({ api: a, model: t }) {
853
+ return /* @__PURE__ */ v("div", { "data-rsv": "resource-daygrid", style: `--rsv-rdg-cols:${t.columns.length}`, children: [
854
+ /* @__PURE__ */ n("div", { "data-rsv": "rdg-header", role: "row", children: t.columns.map((r) => /* @__PURE__ */ n("div", { "data-rsv": "rdg-col-header", role: "columnheader", children: r.row.resource.title }, r.row.resource.id)) }),
855
+ /* @__PURE__ */ n("div", { "data-rsv": "rdg-body", role: "row", children: t.columns.map((r) => /* @__PURE__ */ n("div", { "data-rsv": "rdg-col", "data-rsv-resource-id": r.row.resource.id, children: r.events.map((e) => /* @__PURE__ */ v(
856
+ "div",
857
+ {
858
+ "data-rsv": "event",
859
+ "data-all-day": String(e.allDay),
860
+ "data-event-id": e.id,
861
+ role: "button",
862
+ tabIndex: 0,
863
+ style: `--rsv-event-bg:${e.backgroundColor};--rsv-event-fg:${e.textColor}`,
864
+ onClick: () => a.trigger("eventClick", { event: e }),
865
+ children: [
866
+ e.allDay ? "" : l.format(e.start, "HH:mm") + " ",
867
+ e.title
868
+ ]
869
+ },
870
+ e.id
871
+ )) }, r.row.resource.id)) })
872
+ ] });
873
+ }
874
+ function Gt({ api: a, options: t }) {
875
+ var i;
876
+ const r = a.viewModel.value, e = t.direction ?? E(t.locale).direction, o = t.themeTokens ? vt(t.themeTokens) : void 0;
877
+ return /* @__PURE__ */ v(
878
+ "div",
879
+ {
880
+ "data-rsv": "root",
881
+ dir: e,
882
+ "data-rsv-theme": t.theme,
883
+ style: o,
884
+ class: $((i = t.classNames) == null ? void 0 : i.root),
885
+ children: [
886
+ t.headerToolbar !== !1 && /* @__PURE__ */ n(bt, { api: a, title: r.title, activeView: r.type, options: t }),
887
+ /* @__PURE__ */ n("div", { "data-rsv": "view", "data-view": r.type, children: r.dayGrid ? /* @__PURE__ */ n(tt, { api: a, model: r.dayGrid, options: t }) : r.timeGrid ? /* @__PURE__ */ n(Et, { api: a, model: r.timeGrid, options: t }) : r.list ? /* @__PURE__ */ n(Tt, { api: a, model: r.list, options: t }) : r.multiMonth ? /* @__PURE__ */ n(Pt, { api: a, model: r.multiMonth, options: t }) : r.resourceTimeGrid ? /* @__PURE__ */ n(Rt, { api: a, model: r.resourceTimeGrid, options: t }) : r.resourceDayGrid ? /* @__PURE__ */ n(Ft, { api: a, model: r.resourceDayGrid, options: t }) : r.resourceTimeline ? /* @__PURE__ */ n(Ot, { api: a, model: r.resourceTimeline, options: t }) : r.timeline ? /* @__PURE__ */ n(It, { api: a, model: r.timeline, options: t }) : /* @__PURE__ */ v("div", { "data-rsv": "unsupported", children: [
888
+ 'La vista "',
889
+ r.type,
890
+ '" se implementa en una fase posterior.'
891
+ ] }) })
892
+ ]
893
+ }
894
+ );
895
+ }
896
+ function Bt(a, t) {
897
+ const r = new ut(t);
898
+ return X(st(Gt, { api: r, options: t }), a), {
899
+ api: r,
900
+ destroy() {
901
+ X(null, a), r.destroy();
902
+ }
903
+ };
904
+ }
905
+ function _t(a, t = "calendar.ics") {
906
+ if (typeof document > "u") return;
907
+ const r = mt(a), e = new Blob([r], { type: "text/calendar;charset=utf-8" }), o = URL.createObjectURL(e), i = document.createElement("a");
908
+ i.href = o, i.download = t, document.body.appendChild(i), i.click(), i.remove(), URL.revokeObjectURL(o);
909
+ }
910
+ export {
911
+ Gt as Calendar,
912
+ tt as DayGridView,
913
+ Tt as ListView,
914
+ Pt as MultiMonthView,
915
+ Ft as ResourceDayGridView,
916
+ Rt as ResourceTimeGridView,
917
+ Ot as ResourceTimelineView,
918
+ Et as TimeGridView,
919
+ It as TimelineView,
920
+ bt as Toolbar,
921
+ $ as cx,
922
+ Kt as dayGridPlugin,
923
+ Wt as definePlugin,
924
+ Xt as defineTheme,
925
+ _t as downloadICS,
926
+ zt as eventsToICS,
927
+ Q as handleEventKeydown,
928
+ qt as listPlugin,
929
+ Bt as mount,
930
+ Jt as multiMonthPlugin,
931
+ Qt as parseICS,
932
+ x as renderSlot,
933
+ Zt as resourcePlugin,
934
+ G as startEventDrag,
935
+ te as themeToStyle,
936
+ ee as timeGridPlugin,
937
+ re as timelinePlugin
938
+ };
939
+ //# sourceMappingURL=index.js.map