/*! Fiesta 1.1.0 | MPL-2.0 | https://fiesta.rastrillo.org */ (function (global) { "use strict"; function firstDayOfWeek(locale) { var info = null, loc; try { loc = new Intl.Locale(locale || "en"); info = typeof loc.getWeekInfo === "function" ? loc.getWeekInfo() : loc.weekInfo; } catch (e) { info = null; } if (info && typeof info.firstDay === "number" && info.firstDay >= 1 && info.firstDay <= 7) { return info.firstDay % 7; } return 1; } function monthGrid(year, month, first) { var start = new Date(year, month, 1); var back = (start.getDay() - first + 7) % 7; var out = [], i; for (i = 0; i < 42; i++) out.push(new Date(year, month, 1 - back + i)); return out; } function weekdayNames(locale, first) { var out = [], i, day, probe, shortFmt = null, longFmt = null; try { shortFmt = new Intl.DateTimeFormat(locale, { weekday: "short", timeZone: "UTC" }); longFmt = new Intl.DateTimeFormat(locale, { weekday: "long", timeZone: "UTC" }); } catch (e) { shortFmt = null; longFmt = null; } for (i = 0; i < 7; i++) { day = (first + i) % 7; probe = new Date(Date.UTC(2026, 1, 1 + day)); out.push({ day: day, short: shortFmt ? shortFmt.format(probe) : String(day), long: longFmt ? longFmt.format(probe) : String(day) }); } return out; } if (typeof document !== "undefined") { var CHEVRON = ''; function pad(n) { return (n < 10 ? "0" : "") + n; } function dayKey(d) { return d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate()); } function sameDay(a, b) { return !!a && !!b && dayKey(a) === dayKey(b); } function shift(d, days) { return new Date(d.getFullYear(), d.getMonth(), d.getDate() + days); } function shiftMonths(d, months) { var y = d.getFullYear(), m = d.getMonth() + months, day = d.getDate(); var last = new Date(y, m + 1, 0).getDate(); return new Date(y, m, day > last ? last : day); } function fmt(locale, opts) { try { return new Intl.DateTimeFormat(locale, opts); } catch (e) { return null; } } function makePanel(cfg) { var locale = cfg.locale; var first = firstDayOfWeek(locale); var heads = weekdayNames(locale, first); var titleFmt = fmt(locale, { month: "long", year: "numeric" }); var fullFmt = fmt(locale, { weekday: "long", day: "numeric", month: "long", year: "numeric" }); var numFmt; try { numFmt = new Intl.NumberFormat(locale, { useGrouping: false }); } catch (e) { numFmt = null; } var view = null; var cursor = null; var preview = null; var cells = []; var el = document.createElement("div"); el.setAttribute("rst-cal", ""); el.hidden = true; el.setAttribute("role", "dialog"); el.setAttribute("aria-label", cfg.labels.calendar); var head = document.createElement("div"); head.setAttribute("rst-cal-head", ""); function navButton(label, which) { var b = document.createElement("button"); b.type = "button"; b.setAttribute("rst-cal-nav", which); b.setAttribute("aria-label", label); b.innerHTML = CHEVRON; return b; } var prevBtn = navButton(cfg.labels.prev, "prev"); var nextBtn = navButton(cfg.labels.next, "next"); var title = document.createElement("div"); title.setAttribute("rst-cal-title", ""); title.id = cfg.id + "-cal-title"; title.setAttribute("aria-live", "polite"); head.appendChild(prevBtn); head.appendChild(title); head.appendChild(nextBtn); var table = document.createElement("table"); table.setAttribute("rst-cal-grid", ""); table.setAttribute("role", "grid"); table.setAttribute("aria-labelledby", title.id); var thead = document.createElement("thead"); var headRow = document.createElement("tr"); headRow.setAttribute("role", "row"); for (var h = 0; h < heads.length; h++) { var th = document.createElement("th"); th.setAttribute("scope", "col"); th.setAttribute("role", "columnheader"); var eye = document.createElement("span"); eye.setAttribute("aria-hidden", "true"); eye.textContent = heads[h].short; var said = document.createElement("span"); said.className = "rst-sr-only"; said.textContent = heads[h].long; th.appendChild(eye); th.appendChild(said); headRow.appendChild(th); } thead.appendChild(headRow); var tbody = document.createElement("tbody"); table.appendChild(thead); table.appendChild(tbody); el.appendChild(head); el.appendChild(table); function outOfBounds(d) { var b = cfg.bounds ? cfg.bounds() : null; if (!b) return false; if (b.min && dayKey(d) < dayKey(b.min)) return true; if (b.max && dayKey(d) > dayKey(b.max)) return true; return false; } function monthReachable(d) { var b = cfg.bounds ? cfg.bounds() : null; if (!b) return true; var lo = new Date(d.getFullYear(), d.getMonth(), 1); var hi = new Date(d.getFullYear(), d.getMonth() + 1, 0); if (b.min && dayKey(hi) < dayKey(b.min)) return false; if (b.max && dayKey(lo) > dayKey(b.max)) return false; return true; } function render() { var today = new Date(); var chosen = cfg.value ? cfg.value() : null; var days = monthGrid(view.getFullYear(), view.getMonth(), first); var i, row, td, d, focusable = -1; title.textContent = titleFmt ? titleFmt.format(view) : view.getFullYear() + "-" + pad(view.getMonth() + 1); prevBtn.disabled = !monthReachable(shiftMonths(new Date(view.getFullYear(), view.getMonth(), 1), -1)); nextBtn.disabled = !monthReachable(shiftMonths(new Date(view.getFullYear(), view.getMonth(), 1), 1)); tbody.textContent = ""; cells = []; for (i = 0; i < days.length; i++) { if (i % 7 === 0) { row = document.createElement("tr"); row.setAttribute("role", "row"); tbody.appendChild(row); } d = days[i]; td = document.createElement("td"); td.setAttribute("rst-cal-day", ""); td.setAttribute("role", "gridcell"); td.tabIndex = -1; td.textContent = numFmt ? numFmt.format(d.getDate()) : String(d.getDate()); td.setAttribute("aria-label", fullFmt ? fullFmt.format(d) : dayKey(d)); td.setAttribute("data-rst-day", dayKey(d)); if (d.getMonth() !== view.getMonth()) td.classList.add("is-outside"); if (sameDay(d, today)) { td.classList.add("is-today"); td.setAttribute("aria-current", "date"); } td.setAttribute("aria-selected", sameDay(d, chosen) ? "true" : "false"); if (sameDay(d, chosen)) td.classList.add("is-selected"); if (sameDay(d, preview)) td.classList.add("is-preview"); if (outOfBounds(d)) { td.classList.add("is-disabled"); td.setAttribute("aria-disabled", "true"); } if (sameDay(d, cursor)) focusable = i; row.appendChild(td); cells.push({ td: td, date: d }); } if (focusable < 0) { for (i = 0; i < cells.length; i++) { if (cells[i].date.getMonth() === view.getMonth()) { focusable = i; break; } } if (focusable >= 0) cursor = cells[focusable].date; } if (focusable >= 0) cells[focusable].td.tabIndex = 0; } function cellFor(d) { var key = dayKey(d), i; for (i = 0; i < cells.length; i++) if (dayKey(cells[i].date) === key) return cells[i].td; return null; } function moveTo(d, focus) { cursor = d; if (d.getFullYear() !== view.getFullYear() || d.getMonth() !== view.getMonth()) { view = new Date(d.getFullYear(), d.getMonth(), 1); } render(); if (focus) { var td = cellFor(d); if (td) td.focus(); } } function pick(d) { if (outOfBounds(d)) return; if (cfg.onPick) cfg.onPick(new Date(d.getFullYear(), d.getMonth(), d.getDate())); } function dayAt(node) { while (node && node !== tbody) { if (node.getAttribute && node.getAttribute("data-rst-day")) return node; node = node.parentNode; } return null; } tbody.addEventListener("mousedown", function (e) { var td = dayAt(e.target); if (td) e.preventDefault(); }); tbody.addEventListener("click", function (e) { var td = dayAt(e.target), i; if (!td) return; for (i = 0; i < cells.length; i++) if (cells[i].td === td) return pick(cells[i].date); }); function rtl() { try { return getComputedStyle(el).direction === "rtl"; } catch (e) { return false; } } table.addEventListener("keydown", function (e) { var step = rtl() ? -1 : 1, at = cursor || view; switch (e.key) { case "ArrowLeft": e.preventDefault(); return moveTo(shift(at, -step), true); case "ArrowRight": e.preventDefault(); return moveTo(shift(at, step), true); case "ArrowUp": e.preventDefault(); return moveTo(shift(at, -7), true); case "ArrowDown": e.preventDefault(); return moveTo(shift(at, 7), true); case "Home": e.preventDefault(); return moveTo(shift(at, -((at.getDay() - first + 7) % 7)), true); case "End": e.preventDefault(); return moveTo(shift(at, 6 - ((at.getDay() - first + 7) % 7)), true); case "PageUp": e.preventDefault(); return moveTo(shiftMonths(at, e.shiftKey ? -12 : -1), true); case "PageDown": e.preventDefault(); return moveTo(shiftMonths(at, e.shiftKey ? 12 : 1), true); case "Enter": case " ": e.preventDefault(); return pick(at); case "Escape": e.preventDefault(); if (cfg.onDismiss) cfg.onDismiss(); return; } }); prevBtn.addEventListener("mousedown", function (e) { e.preventDefault(); }); nextBtn.addEventListener("mousedown", function (e) { e.preventDefault(); }); prevBtn.addEventListener("click", function () { view = shiftMonths(new Date(view.getFullYear(), view.getMonth(), 1), -1); render(); }); nextBtn.addEventListener("click", function () { view = shiftMonths(new Date(view.getFullYear(), view.getMonth(), 1), 1); render(); }); return { el: el, open: function (at) { var start = at || (cfg.value ? cfg.value() : null) || new Date(); preview = at ? new Date(at.getFullYear(), at.getMonth(), at.getDate()) : null; cursor = new Date(start.getFullYear(), start.getMonth(), start.getDate()); view = new Date(start.getFullYear(), start.getMonth(), 1); render(); el.hidden = false; }, close: function () { el.hidden = true; preview = null; }, isOpen: function () { return !el.hidden; }, show: function (d) { if (el.hidden) return; preview = d ? new Date(d.getFullYear(), d.getMonth(), d.getDate()) : null; if (preview) moveTo(preview, false); else render(); }, focusGrid: function () { if (el.hidden) return false; var td = cursor ? cellFor(cursor) : null; if (!td) return false; td.focus(); return true; } }; } global.fiestaCalendar = makePanel; } if (typeof module !== "undefined" && module && module.exports) { module.exports = { firstDayOfWeek: firstDayOfWeek, monthGrid: monthGrid, weekdayNames: weekdayNames }; } })(typeof globalThis !== "undefined" ? globalThis : this);