(function() { // \0rolldown/runtime.js var __defProp = Object.defineProperty; var __exportAll = (all, no_symbols) => { let target = {}; for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" }); return target; }; // src/extra/shared.js var HTMLElementBase = class extends (globalThis.HTMLElement ?? class {}) { get spacing() { return this.getAttribute("spacing") ?? "inherit"; } set spacing(value) { if (value == null || value === "inherit") this.removeAttribute("spacing"); else this.setAttribute("spacing", String(value)); } }; var baseStyles = ` :host { box-sizing: border-box; color-scheme: inherit; color: var(--biscuit-color, light-dark(#24252b,#f3f4f8)); font: 400 1rem/1.5 system-ui,sans-serif; } :host([spacing="compact"]) { --biscuit-space-scale: 0.8; } :host([spacing="normal"]) { --biscuit-space-scale: 1; } :host([spacing="spacious"]) { --biscuit-space-scale: 1.3; } :host([theme="light"]) { color-scheme: light; --biscuit-focus-color: #6b63db; --biscuit-on-accent: #fff; } :host([theme="dark"]) { color-scheme: dark; --biscuit-focus-color: #aaa2ff; --biscuit-on-accent: #211b3c; } :host([theme="deep-dark"]) { color-scheme: dark; --biscuit-surface: #000; --biscuit-color: #fff; --biscuit-border-color: #fff; --biscuit-focus-color: #fff; --biscuit-on-accent: #000; --biscuit-switch-track: #000; --biscuit-switch-checked-track: #fff; --biscuit-switch-checked-thumb: #000; } :host([theme="auto"]) { color-scheme: light dark; --biscuit-focus-color: light-dark(#6b63db,#aaa2ff); --biscuit-on-accent: light-dark(#fff,#211b3c); } *, *::before, *::after { box-sizing: border-box; } button, input, select { font: inherit; } button:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--biscuit-focus-color,#786fc6); outline-offset: 2px; } `; var surface = "var(--biscuit-surface,light-dark(#fff,#292c37))"; var border = "var(--biscuit-border-color,light-dark(#c9ccd5,#626777))"; function style(root, css) { const node = document.createElement("style"); node.textContent = baseStyles + css; root.append(node); } function define(tag, constructor) { const registry = globalThis.customElements; if (!registry) return constructor; const prior = registry.get(tag); if (prior && prior !== constructor) throw new Error(`<${tag}> is already registered by another library`); if (!prior) registry.define(tag, constructor); return constructor; } function event(element, type, detail, cancelable = false) { return element.dispatchEvent(new CustomEvent(type, { detail, bubbles: true, composed: true, cancelable })); } function options(element, source, keys) { for (const key of keys) if (Object.hasOwn(source ?? {}, key)) element[key] = source[key]; if (Object.hasOwn(source ?? {}, "spacing")) element.spacing = source.spacing; return element; } function themeProperty(constructor) { Object.defineProperty(constructor.prototype, "theme", { get() { return this.getAttribute("theme") ?? "inherit"; }, set(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } }); } function boolProperty(constructor, property, attribute = property) { Object.defineProperty(constructor.prototype, property, { get() { return this.hasAttribute(attribute); }, set(value) { this.toggleAttribute(attribute, Boolean(value)); } }); } function stringProperty(constructor, property, attribute = property, fallback = "") { Object.defineProperty(constructor.prototype, property, { get() { return this.getAttribute(attribute) ?? fallback; }, set(value) { if (value == null) this.removeAttribute(attribute); else this.setAttribute(attribute, String(value)); } }); } function syncFormValue(host, value) { host._internals?.setFormValue(value); if (!host._internals) { if (!host._fallback) { host._fallback = document.createElement("input"); host._fallback.type = "hidden"; host.append(host._fallback); } host._fallback.name = host.name ?? ""; host._fallback.value = value ?? ""; host._fallback.disabled = value == null || host.disabled || !host.name; } } function syncValidity(host, control) { if (!host._internals || !control?.validity) return; const validity = control.validity; if (validity.valid) host._internals.setValidity({}); else { const flags = {}; for (const key of [ "valueMissing", "typeMismatch", "patternMismatch", "tooLong", "tooShort", "rangeUnderflow", "rangeOverflow", "stepMismatch", "badInput", "customError" ]) if (validity[key]) flags[key] = true; host._internals.setValidity(flags, control.validationMessage, control); } } function positionPanel(panel, anchor, offset = 6) { if (!panel || !anchor) return; const box = anchor.getBoundingClientRect(); const width = panel.offsetWidth || 240; const height = panel.offsetHeight || 100; let left = Math.min(Math.max(8, box.left), Math.max(8, innerWidth - width - 8)); let top = box.bottom + offset; if (top + height > innerHeight - 8 && box.top - height - offset >= 8) top = box.top - height - offset; else top = Math.min(top, Math.max(8, innerHeight - height - 8)); panel.style.left = `${left}px`; panel.style.top = `${top}px`; } // src/charts/calendar.js var DAY = 864e5; var weekdays = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]; var monthFormatter = new Intl.DateTimeFormat("en", { month: "short", timeZone: "UTC" }); function dayStamp(value) { if (value == null || value === "") return null; if (typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value)) { const [year, month, day] = value.split("-").map(Number); const stamp = Date.UTC(year, month - 1, day); return iso$1(stamp) === value ? stamp : null; } const date = value instanceof Date ? value : new Date(typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value) ? `${value}T00:00:00Z` : value); if (!Number.isFinite(date.getTime())) return null; const stamp = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()); return Number.isFinite(stamp) ? stamp : null; } var iso$1 = (stamp) => new Date(stamp).toISOString().slice(0, 10); var boundedYear = (value) => { const year = Number(value); return Number.isInteger(year) && year >= 1e3 && year <= 9999 ? year : null; }; function calendarDomain(series, width, height, options = {}) { const points = series.flatMap((spec) => spec.points); const today = dayStamp(options.endDate) ?? dayStamp(/* @__PURE__ */ new Date()); const firstDate = points.map((point) => dayStamp(point.x)).find((stamp) => stamp != null); const year = boundedYear(options.year) ?? new Date(firstDate ?? today).getUTCFullYear(); const style = options.calendarStyle === "activity" ? "activity" : "calendar"; const rolling = style === "activity" && options.calendarRange === "rolling"; const month = Math.max(1, Math.min(12, Math.floor(Number(options.month) || new Date(firstDate ?? today).getUTCMonth() + 1))); const start = style === "calendar" ? Date.UTC(year, month - 1, 1) : rolling ? today - 364 * DAY : Date.UTC(year, 0, 1); const end = style === "calendar" ? Date.UTC(year, month, 1) - DAY : rolling ? today : Date.UTC(year + 1, 0, 1) - DAY; const weekStart = Math.max(0, Math.min(6, Math.floor(Number(options.weekStart) || 0))); const leading = (new Date(start).getUTCDay() - weekStart + 7) % 7; const weeks = Math.ceil((leading + (end - start) / DAY + 1) / 7); const left = style === "activity" ? 36 : 12, top = style === "activity" ? 28 : 42; const step = style === "activity" ? Math.max(14, Math.min(18, (Math.max(width, 760) - left - 20) / weeks)) : Math.max(48, (Math.max(width, 360) - left - 12) / 7); const size = style === "activity" ? step - 3 : step - 4; const rowHeight = style === "activity" ? step : Math.max(74, Number(options.dayHeight) || 92); const chartWidth = style === "activity" ? Math.max(width, Math.ceil(left + weeks * step + 20)) : Math.max(width, Math.ceil(left + 7 * step + 12)); const chartHeight = style === "activity" ? Math.max(height, Math.ceil(top + 7 * step + 38)) : Math.max(height, Math.ceil(top + weeks * rowHeight + 12)); const totals = /* @__PURE__ */ new Map(); for (const point of points) { const stamp = dayStamp(point.x); if (stamp == null || stamp < start || stamp > end) continue; const value = Number(point.y); if (!Number.isFinite(value) || value < 0) continue; const current = totals.get(stamp); totals.set(stamp, { value: (current?.value ?? 0) + value, row: point.row }); } const days = []; const months = []; let max = 0, total = 0, active = 0, previousMonth = -1; for (let stamp = start; stamp <= end; stamp += DAY) { const date = new Date(stamp), offset = (stamp - start) / DAY, week = Math.floor((offset + leading) / 7), weekday = (date.getUTCDay() - weekStart + 7) % 7; const entry = totals.get(stamp), value = entry?.value ?? 0; max = Math.max(max, value); total += value; if (value > 0) active++; days.push({ date: iso$1(stamp), stamp, value, row: entry?.row ?? null, week, weekday }); const month = date.getUTCMonth(); if (month !== previousMonth) { months.push({ label: monthFormatter.format(date), x: left + week * step }); previousMonth = month; } } return { series, width: chartWidth, height: chartHeight, xKind: "calendar", yKind: "number", xDomain: [start, end], yDomain: [0, max], xScale: null, yScale: null, plot: { left, top, right: chartWidth - 12, bottom: chartHeight - 12 }, calendar: { days, months, weekdays, weekStart, step, size, rowHeight, left, top, weeks, year, month, rolling, total, active, max, style } }; } function calendarGeometry(model) { const { days, left, top, step, size, rowHeight, max, style } = model.calendar; return days.map((day, index) => ({ kind: "calendar", shape: "rect", series: 0, label: model.series[0]?.name || "Activity", point: { x: day.date, y: day.value, value: day.value, row: day.row ?? { date: day.date, value: day.value }, index, series: 0 }, row: day.row, x: style === "activity" ? left + day.week * step : left + day.weekday * step, y: style === "activity" ? top + day.weekday * step : top + day.week * rowHeight, width: size, height: style === "activity" ? size : rowHeight - 4, level: day.value ? Math.max(1, Math.min(4, Math.ceil(day.value / Math.max(1, max) * 4))) : 0, date: day.date })); } function calendarSummary(model) { const { total, active, days, rolling, year, month, style } = model.calendar; return `${new Intl.NumberFormat().format(total)} activities across ${active} active days in ${style === "calendar" ? `${monthFormatter.format(new Date(Date.UTC(year, month - 1, 1)))} ${year}` : rolling ? "the last " + days.length + " days" : year}`; } function normalizeHex(value) { if (typeof value !== "string" || !/^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(value)) return null; return value.length === 4 || value.length === 5 ? "#" + [...value.slice(1)].map((digit) => digit + digit).join("").toLowerCase() : value.toLowerCase(); } function mixHex(from, to, amount) { const a = normalizeHex(from), b = normalizeHex(to); if (!a || !b) return null; const t = Math.max(0, Math.min(1, Number(amount) || 0)); return "#" + (a.length === 9 || b.length === 9 ? [ 0, 2, 4, 6 ] : [ 0, 2, 4 ]).map((index) => Math.round(parseInt(a.slice(index + 1, index + 3) || "ff", 16) * (1 - t) + parseInt(b.slice(index + 1, index + 3) || "ff", 16) * t).toString(16).padStart(2, "0")).join(""); } function calendarPalette(theme = "light", mode = "color", style = "calendar", override = null, accent = null) { if (mode === "monochrome") return theme === "light" ? [ "#ebedf0", "#c6c9ce", "#9b9fa6", "#686d75", "#333840" ] : [ "#161616", "#454545", "#777", "#b3b3b3", "#fff" ]; const base = normalizeHex(accent); if (Array.isArray(override) && override.length === 5 && override.every((color) => normalizeHex(color))) return override.map(normalizeHex); if (base) { const empty = theme === "light" ? "#ebedf0" : theme === "deep-dark" ? "#111111" : "#242a32", surface = theme === "light" ? "#ffffff" : theme === "deep-dark" ? "#000000" : "#242733"; return [empty, ...[ .25, .5, .75, 1 ].map((weight) => mixHex(surface, base, weight))]; } if (style === "activity") return theme === "light" ? [ "#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39" ] : theme === "deep-dark" ? [ "#111", "#0e4429", "#006d32", "#26a641", "#39d353" ] : [ "#242a32", "#0e4429", "#006d32", "#26a641", "#39d353" ]; return theme === "light" ? [ "#ececf3", "#ddd7fa", "#bcb0f3", "#9180e2", "#6352b8" ] : theme === "deep-dark" ? [ "#151515", "#3c345c", "#6654a1", "#9884ed", "#c8bcff" ] : [ "#2c2d3a", "#4b456c", "#6e5caa", "#9983e2", "#c8bcff" ]; } function calendarValueColor(value, max, palette, scale = "steps") { if (!(value > 0)) return palette[0]; if (scale !== "continuous") return palette[Math.max(1, Math.min(4, Math.ceil(value / Math.max(1, max) * 4)))]; const position = Math.max(0, Math.min(1, value / Math.max(1, max))) * 3; const low = Math.min(3, Math.floor(position)); return mixHex(palette[low + 1], palette[low + 2] ?? palette[4], position - low); } function calendarAxesSvg(model, { theme = "light", colorMode = "color", calendarColors = null, calendarColor = null, colorScale = "steps", id = "chart" } = {}) { const info = model.calendar; if (!info) return ""; const ink = theme === "light" ? "#687082" : theme === "deep-dark" ? "#eee" : "#b8bdcd"; const palette = calendarPalette(theme, colorMode, info.style, calendarColors, calendarColor); let out = ""; if (info.style === "calendar") { const title = new Intl.DateTimeFormat("en", { month: "long", year: "numeric", timeZone: "UTC" }).format(new Date(Date.UTC(info.year, info.month - 1, 1))); out += `${title}`; for (let index = 0; index < 7; index++) out += `${info.weekdays[(info.weekStart + index) % 7]}`; return out; } for (const month of info.months) out += `${month.label}`; for (const index of [ 1, 3, 5 ]) { const day = info.weekdays[(info.weekStart + index) % 7]; out += `${day}`; } const y = info.top + 7 * info.step + 19, start = Math.max(info.left, model.width - 137); out += `Less`; if (colorScale === "continuous") out += ``; else palette.forEach((color, index) => { out += ``; }); out += `More`; return out; } // src/groups/calendar.js var iso = (stamp) => new Date(stamp).toISOString().slice(0, 10); var dateValue = (value) => { const stamp = dayStamp(value); return stamp == null ? "" : iso(stamp); }; var days = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]; var css$1 = `${baseStyles} :host{display:block;min-width:0;--_surface:var(--biscuit-surface,light-dark(#fff,#292c37));--_ink:var(--biscuit-color,light-dark(#24252b,#f3f4f8));--_line:var(--biscuit-border-color,light-dark(#d6d8df,#626777));--_accent:var(--biscuit-focus-color,light-dark(#6b63db,#aaa2ff));color:var(--_ink)} :host([theme="deep-dark"]){--_surface:#000;--_ink:#fff;--_line:#fff;--_accent:#fff} .calendar{background:var(--_surface);border:1px solid var(--_line);border-radius:12px;padding:calc(12px * var(--biscuit-space-scale,1));max-width:100%}.head{display:flex;justify-content:space-between;align-items:center;gap:8px;margin-bottom:10px}.head strong{font-size:1.05rem}.head button,.day{color:inherit;background:transparent;border:0;cursor:pointer}.head button{width:34px;height:34px;border:1px solid var(--_line);border-radius:7px}.grid{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));gap:3px}.weekday{text-align:center;color:color-mix(in srgb,var(--_ink) 65%,transparent);font-size:.75rem;padding:4px}.cell{min-width:0;min-height:var(--biscuit-calendar-day-height,72px);border:1px solid var(--_line);border-radius:6px;overflow:hidden;padding:3px}.cell.outside{visibility:hidden}.day{display:grid;place-items:center;width:28px;height:28px;border-radius:50%;font-size:.82rem}.day:hover{background:color-mix(in srgb,var(--_accent) 14%,transparent)}.day[aria-selected="true"]{background:var(--_accent);color:var(--biscuit-on-accent,#fff)}.day[aria-current="date"]{outline:1px solid var(--_accent)}.day:disabled{opacity:.35;cursor:default}.content{min-width:0;font-size:.72rem;overflow:auto;max-height:calc(var(--biscuit-calendar-day-height,72px) - 35px)}.content slot::slotted(*){max-width:100%}button:focus-visible{outline:2px solid var(--_accent);outline-offset:2px}@media(max-width:520px){.calendar{padding:6px}.grid{gap:1px}.cell{min-height:var(--biscuit-calendar-day-height,54px);padding:1px}.day{width:24px;height:24px}.content{max-height:25px}} `; var BiscuitCalendarView = class extends HTMLElementBase { static observedAttributes = [ "year", "month", "value", "week-start", "min", "max", "theme", "spacing" ]; constructor() { super(); if (this.attachShadow) { this._root = this.attachShadow({ mode: "open" }); this._root.innerHTML = `
`; this._root.querySelector(".previous").addEventListener("click", () => this.navigate(-1)); this._root.querySelector(".next").addEventListener("click", () => this.navigate(1)); this._root.querySelector(".grid").addEventListener("click", (e) => { const button = e.target.closest("button[data-date]"); if (button && !button.disabled) this._choose(button.dataset.date); }); this._root.querySelector(".grid").addEventListener("keydown", (e) => this._onKey(e)); } } connectedCallback() { this._observer = typeof MutationObserver !== "undefined" ? new MutationObserver(() => this._render()) : null; this._observer?.observe(this, { childList: true, subtree: true, attributes: true, attributeFilter: ["date"] }); this._render(); } disconnectedCallback() { this._observer?.disconnect(); } attributeChangedCallback() { this._render(); } get year() { return Number(this.getAttribute("year")) || (/* @__PURE__ */ new Date()).getFullYear(); } set year(value) { this.setAttribute("year", String(value)); } get month() { return Number(this.getAttribute("month")) || (/* @__PURE__ */ new Date()).getMonth() + 1; } set month(value) { this.setAttribute("month", String(value)); } get weekStart() { return Number(this.getAttribute("week-start")) || 0; } set weekStart(value) { this.setAttribute("week-start", String(value)); } get value() { return this.getAttribute("value") || ""; } set value(value) { const normalized = dateValue(value); if (normalized) this.setAttribute("value", normalized); else this.removeAttribute("value"); } get min() { return this.getAttribute("min") || ""; } set min(value) { if (value == null || value === "") this.removeAttribute("min"); else this.setAttribute("min", dateValue(value)); } get max() { return this.getAttribute("max") || ""; } set max(value) { if (value == null || value === "") this.removeAttribute("max"); else this.setAttribute("max", dateValue(value)); } navigate(offset) { const date = new Date(Date.UTC(this.year, this.month - 1 + offset, 1)); this.year = date.getUTCFullYear(); this.month = date.getUTCMonth() + 1; event(this, "monthchange", { year: this.year, month: this.month }); } setDayContent(date, content) { const key = dateValue(date); if (!key) throw new TypeError("Expected a valid date"); let day = [...this.querySelectorAll(":scope > biscuit-calendar-day")].find((node) => node.getAttribute("date") === key); if (!day) { day = document.createElement("biscuit-calendar-day"); day.setAttribute("date", key); this.append(day); } day.replaceChildren(...(Array.isArray(content) ? content : [content]).filter(Boolean).map((item) => typeof item === "string" ? document.createTextNode(item) : item)); this._render(); return day; } _choose(date) { const previous = this.value; this.value = date; event(this, "input", { value: date, date }); if (previous !== date) event(this, "change", { value: date, date }); } _onKey(e) { const focused = this._root.activeElement?.dataset?.date; if (!focused) return; const delta = { ArrowLeft: -1, ArrowRight: 1, ArrowUp: -7, ArrowDown: 7 }[e.key]; if (delta === void 0 && e.key !== "Home" && e.key !== "End") return; e.preventDefault(); const target = /* @__PURE__ */ new Date(`${focused}T00:00:00Z`); if (delta !== void 0) target.setUTCDate(target.getUTCDate() + delta); else target.setUTCDate(e.key === "Home" ? 1 : new Date(Date.UTC(target.getUTCFullYear(), target.getUTCMonth() + 1, 0)).getUTCDate()); if (target.getUTCMonth() + 1 !== this.month || target.getUTCFullYear() !== this.year) { this.year = target.getUTCFullYear(); this.month = target.getUTCMonth() + 1; } this._root.querySelector(`button[data-date="${iso(target.getTime())}"]`)?.focus(); } _render() { if (!this._root) return; let year = this.year, month = this.month; if (!Number.isInteger(year) || year < 1e3 || year > 9999) year = (/* @__PURE__ */ new Date()).getFullYear(); if (!Number.isInteger(month) || month < 1 || month > 12) month = 1; const first = Date.UTC(year, month - 1, 1), count = new Date(Date.UTC(year, month, 0)).getUTCDate(), leading = (new Date(first).getUTCDay() - this.weekStart + 7) % 7; this._root.querySelector(".title").textContent = new Intl.DateTimeFormat(void 0, { month: "long", year: "numeric", timeZone: "UTC" }).format(new Date(first)); const grid = this._root.querySelector(".grid"); grid.replaceChildren(); for (let i = 0; i < 7; i++) { const label = document.createElement("span"); label.className = "weekday"; label.textContent = days[(i + this.weekStart) % 7]; grid.append(label); } const today = dateValue(/* @__PURE__ */ new Date()), min = this.getAttribute("min"), max = this.getAttribute("max"); for (let i = 0; i < Math.ceil((leading + count) / 7) * 7; i++) { const number = i - leading + 1, cell = document.createElement("div"); cell.className = "cell"; cell.setAttribute("part", "day"); if (number < 1 || number > count) { cell.classList.add("outside"); grid.append(cell); continue; } const date = iso(Date.UTC(year, month - 1, number)), button = document.createElement("button"); button.className = "day"; button.type = "button"; button.dataset.date = date; button.textContent = String(number); button.setAttribute("aria-label", new Intl.DateTimeFormat(void 0, { dateStyle: "full", timeZone: "UTC" }).format(/* @__PURE__ */ new Date(`${date}T00:00:00Z`))); button.setAttribute("aria-pressed", String(this.value === date)); if (today === date) button.setAttribute("aria-current", "date"); button.disabled = Boolean(min && date < min || max && date > max); cell.append(button); const matching = [...this.querySelectorAll(":scope > biscuit-calendar-day[date]")].find((day) => day.getAttribute("date") === date); if (matching) { const slotName = `day-${date}`; if (matching.slot !== slotName) matching.slot = slotName; const content = document.createElement("div"); content.className = "content"; const slot = document.createElement("slot"); slot.name = slotName; content.append(slot); cell.append(content); } grid.append(cell); } } }; themeProperty(BiscuitCalendarView); var pickerCss = `${baseStyles}:host{display:inline-block;position:relative;min-width:13rem;color:var(--biscuit-color,light-dark(#24252b,#f3f4f8))}:host([theme="deep-dark"]){--biscuit-surface:#000;--biscuit-color:#fff;--biscuit-border-color:#fff}label{display:block;margin-bottom:5px;font-weight:600}.row{display:flex;align-items:center;border:1px solid var(--biscuit-border-color,light-dark(#a5a8b3,#656b7a));border-radius:8px;background:var(--biscuit-surface,light-dark(#fff,#292c37));overflow:hidden}.row input{width:100%;min-width:0;border:0;padding:9px;color:inherit;background:transparent}.row button{border:0;border-left:1px solid var(--biscuit-border-color,light-dark(#a5a8b3,#656b7a));padding:8px 12px;color:inherit;background:transparent;cursor:pointer}.popup{position:absolute;z-index:30;top:calc(100% + 5px);left:0;width:min(360px,95vw);box-shadow:0 12px 32px #0003}.popup[hidden]{display:none}@media(max-width:420px){.popup{left:auto;right:0}}`; var BiscuitDatePickerView = class extends HTMLElementBase { static formAssociated = true; static observedAttributes = [ "value", "name", "label", "min", "max", "disabled", "required", "theme", "spacing" ]; constructor() { super(); this._internals = this.attachInternals?.() ?? null; if (!this._internals?.setFormValue) this._internals = null; if (this.attachShadow) { this._root = this.attachShadow({ mode: "open" }); this._root.innerHTML = `
`; this._input = this._root.querySelector("input"); this._button = this._root.querySelector("button"); this._popup = this._root.querySelector(".popup"); this._calendar = this._root.querySelector("biscuit-calendarview"); this._button.addEventListener("click", (e) => { e.stopPropagation(); this.open ? this.hide() : this.show(); }); this._calendar.addEventListener("change", (e) => { e.stopPropagation(); this.value = e.detail.value; event(this, "input", { value: this.value }); event(this, "change", { value: this.value }); this.hide(); this._button.focus(); }); this._root.addEventListener("keydown", (e) => { if (e.key === "Escape" && this.open) { e.preventDefault(); this.hide(); this._button.focus(); } }); this._outside = (e) => { if (!e.composedPath().includes(this)) this.hide(); }; } } connectedCallback() { this._defaultValue ??= this.value; this._render(); } disconnectedCallback() { document.removeEventListener("pointerdown", this._outside); } attributeChangedCallback() { this._render(); } get name() { return this.getAttribute("name") || ""; } set name(v) { this.setAttribute("name", String(v)); } get value() { return this.getAttribute("value") || ""; } set value(v) { const normalized = dateValue(v); if (normalized) this.setAttribute("value", normalized); else this.removeAttribute("value"); } get label() { return this.getAttribute("label") || ""; } set label(v) { this.setAttribute("label", String(v)); } get min() { return this.getAttribute("min") || ""; } set min(v) { if (v == null || v === "") this.removeAttribute("min"); else this.setAttribute("min", dateValue(v)); } get max() { return this.getAttribute("max") || ""; } set max(v) { if (v == null || v === "") this.removeAttribute("max"); else this.setAttribute("max", dateValue(v)); } get required() { return this.hasAttribute("required"); } set required(v) { this.toggleAttribute("required", Boolean(v)); } get disabled() { return this.hasAttribute("disabled"); } set disabled(v) { this.toggleAttribute("disabled", Boolean(v)); } get open() { return !this._popup.hidden; } show() { if (this.hasAttribute("disabled")) return; this._calendar.year = Number(this.value.slice(0, 4)) || (/* @__PURE__ */ new Date()).getFullYear(); this._calendar.month = Number(this.value.slice(5, 7)) || (/* @__PURE__ */ new Date()).getMonth() + 1; this._popup.hidden = false; this._button.setAttribute("aria-expanded", "true"); setTimeout(() => { if (this.open && this.isConnected) document.addEventListener("pointerdown", this._outside); }, 0); this._calendar.shadowRoot.querySelector(".day:not(:disabled)")?.focus(); } hide() { this._popup.hidden = true; this._button.setAttribute("aria-expanded", "false"); document.removeEventListener("pointerdown", this._outside); } formResetCallback() { this.value = this._defaultValue ?? ""; } checkValidity() { return (!this.hasAttribute("required") || Boolean(this.value)) && (!this.value || !this.getAttribute("min") || this.value >= this.getAttribute("min")) && (!this.value || !this.getAttribute("max") || this.value <= this.getAttribute("max")); } reportValidity() { if (this.checkValidity()) return true; this.show(); return false; } _render() { if (!this._root) return; this._root.querySelector("label").textContent = this.getAttribute("label") || ""; this._root.querySelector("label").hidden = !this.hasAttribute("label"); this._input.value = this.value; this._input.setAttribute("aria-label", this.getAttribute("label") || "Date"); this._button.disabled = this.hasAttribute("disabled"); this._calendar.value = this.value; for (const name of [ "min", "max", "theme", "spacing" ]) { const value = this.getAttribute(name); if (value == null) this._calendar.removeAttribute(name); else this._calendar.setAttribute(name, value); } syncFormValue(this, this.hasAttribute("disabled") ? null : this.value || null); const invalid = this.value && this.getAttribute("min") && this.value < this.getAttribute("min") ? { rangeUnderflow: true } : this.value && this.getAttribute("max") && this.value > this.getAttribute("max") ? { rangeOverflow: true } : { valueMissing: true }; this._internals?.setValidity(this.checkValidity() ? {} : invalid, this.checkValidity() ? "" : "Choose a date within the allowed range.", this._input); } }; themeProperty(BiscuitDatePickerView); function defineCalendarView() { return define("biscuit-calendarview", BiscuitCalendarView); } function defineDatePickerView() { defineCalendarView(); return define("biscuit-datepickerview", BiscuitDatePickerView); } function createCalendarView(options = {}) { defineCalendarView(); const view = document.createElement("biscuit-calendarview"); for (const key of [ "theme", "spacing", "year", "month", "weekStart", "value" ]) if (Object.hasOwn(options, key)) view[key] = options[key]; for (const key of ["min", "max"]) if (Object.hasOwn(options, key)) view.setAttribute(key, String(options[key])); return view; } function createDatePickerView(options = {}) { defineDatePickerView(); const view = document.createElement("biscuit-datepickerview"); for (const key of [ "theme", "spacing", "name", "value" ]) if (Object.hasOwn(options, key)) view[key] = options[key]; for (const key of [ "label", "min", "max", "required", "disabled" ]) if (Object.hasOwn(options, key)) { if (typeof options[key] === "boolean") view.toggleAttribute(key, options[key]); else view.setAttribute(key, String(options[key])); } return view; } // src/groups/shared.js var themeStyles = ` :host([spacing="compact"]) { --biscuit-space-scale: 0.8; } :host([spacing="normal"]) { --biscuit-space-scale: 1; } :host([spacing="spacious"]) { --biscuit-space-scale: 1.3; } :host([theme]) { --biscuit-on-accent: light-dark(#fff, #211b3c); --biscuit-theme-surface: light-dark(#fff, #292c37); --biscuit-theme-color: light-dark(#24252b, #f3f4f8); --biscuit-theme-textview-border-color: light-dark(#a5a8b3, #656b7a); --biscuit-theme-cardview-border-color: light-dark(#d6d8df, #656b7a); --biscuit-theme-focus-color: light-dark(#6b63db, #aaa2ff); --biscuit-theme-cardview-shadow: light-dark(0 2px 8px rgb(36 37 43 / 8%), 0 3px 14px rgb(0 0 0 / 25%)); --biscuit-theme-option-background: light-dark(#efedff, #45415f); --biscuit-theme-option-color: light-dark(#38306e, #fff); --biscuit-theme-button-primary-background: light-dark(#6256ad, #c0bbff); --biscuit-theme-button-primary-color: light-dark(#fff, #211b3c); --biscuit-theme-button-danger-background: light-dark(#be3e4a, #ff8d94); --biscuit-theme-button-danger-color: light-dark(#fff, #281215); --biscuit-theme-badge-neutral: light-dark(#555b69, #d2d5df); --biscuit-theme-badge-accent: light-dark(#5b4bb1, #c3baff); --biscuit-theme-badge-success: light-dark(#176d4b, #8ce0ae); --biscuit-theme-badge-warning: light-dark(#8b5600, #ffd27a); --biscuit-theme-badge-danger: light-dark(#ad3442, #ff9ca4); --biscuit-theme-badge-background: color-mix(in srgb, var(--_badge-tone) 12%, var(--biscuit-theme-surface)); --biscuit-theme-badge-border: 1px solid color-mix(in srgb, var(--_badge-tone) 30%, transparent); } :host([theme="light"]) { color-scheme: light; } :host([theme="dark"]) { color-scheme: dark; } :host([theme="auto"]) { color-scheme: light dark; } :host([theme="deep-dark"]) { color-scheme: dark; --biscuit-on-accent: #000; --biscuit-switch-track: #000; --biscuit-switch-checked-track: #fff; --biscuit-switch-checked-thumb: #000; --biscuit-theme-surface: #000; --biscuit-theme-color: #fff; --biscuit-theme-textview-border-color: #fff; --biscuit-theme-cardview-border-color: #fff; --biscuit-theme-focus-color: #fff; --biscuit-theme-cardview-shadow: none; --biscuit-theme-option-background: #fff; --biscuit-theme-option-color: #000; --biscuit-theme-button-primary-background: #fff; --biscuit-theme-button-primary-color: #000; --biscuit-theme-button-danger-background: #fff; --biscuit-theme-button-danger-color: #000; --biscuit-theme-badge-neutral: #fff; --biscuit-theme-badge-accent: #fff; --biscuit-theme-badge-success: #fff; --biscuit-theme-badge-warning: #fff; --biscuit-theme-badge-danger: #fff; --biscuit-theme-badge-background: #000; --biscuit-theme-badge-border: 1px solid #fff; } `; function createConfiguredElement(tag, options) { const element = document.createElement(tag); if (Object.hasOwn(options, "spacing")) element.spacing = options.spacing; return element; } // src/icon-data.js var iconSvgs = Object.freeze({ "file": "", "folder": "", "html-file": "", "js-file": "JS", "css-file": "", "image-file": "", "code-file": "", "svg-file": "", "sun": "", "moon": "", "system": "", "deep-dark": "", "spacing-compact": "", "spacing-normal": "", "spacing-spacious": "", "x": "", "check": "", "chevron-right": "", "chevron-down": "", "search": "", "plus": "", "refresh": "", "upload": "", "download": "" }); // src/groups/icons.js var iconNames = Object.freeze(Object.keys(iconSvgs)); function getIconSvg(name) { const svg = iconSvgs[String(name)]; if (!svg) throw new RangeError(`Unknown Biscuit icon: ${name}`); return svg; } function createIcon(name, { label } = {}) { if (!globalThis.document) throw new Error("Biscuit icons require a browser document"); const element = document.createElement("span"); element.className = "biscuit-icon"; element.style.display = "inline-flex"; element.style.alignItems = "center"; element.style.justifyContent = "center"; element.style.flex = "none"; element.style.width = "1em"; element.style.height = "1em"; element.innerHTML = getIconSvg(name); if (label) { element.setAttribute("role", "img"); element.setAttribute("aria-label", String(label)); } else element.setAttribute("aria-hidden", "true"); return element; } // src/groups/core.js var core_exports = /* @__PURE__ */ __exportAll({ BiscuitBadgeView: () => BiscuitBadgeView, BiscuitButtonView: () => BiscuitButtonView, BiscuitCalendarView: () => BiscuitCalendarView, BiscuitCardView: () => BiscuitCardView, BiscuitDatePickerView: () => BiscuitDatePickerView, BiscuitDropdownView: () => BiscuitDropdownView, BiscuitLoadingIndicator: () => BiscuitLoadingIndicator, BiscuitPageLoaderView: () => BiscuitPageLoaderView, BiscuitTextView: () => BiscuitTextView, createBadgeView: () => createBadgeView, createButtonView: () => createButtonView, createCalendarView: () => createCalendarView, createCardView: () => createCardView, createDatePickerView: () => createDatePickerView, createDropdownView: () => createDropdownView, createLoadingIndicator: () => createLoadingIndicator, createPageLoaderView: () => createPageLoaderView, createTextView: () => createTextView, defineBadgeView: () => defineBadgeView, defineButtonView: () => defineButtonView, defineCalendarView: () => defineCalendarView, defineCardView: () => defineCardView, defineCore: () => defineCore, defineDatePickerView: () => defineDatePickerView, defineDropdownView: () => defineDropdownView, defineLoadingIndicator: () => defineLoadingIndicator, definePageLoaderView: () => definePageLoaderView, defineTextView: () => defineTextView }); var TEXTVIEW_TAG_NAME = "biscuit-textview"; var CARDVIEW_TAG_NAME = "biscuit-cardview"; var DROPDOWNVIEW_TAG_NAME = "biscuit-dropdownview"; var BUTTONVIEW_TAG_NAME = "biscuit-buttonview"; var LOADINGINDICATOR_TAG_NAME = "biscuit-loadingindicator"; var PAGELOADERVIEW_TAG_NAME = "biscuit-pageloaderview"; var BADGEVIEW_TAG_NAME = "biscuit-badgeview"; var dropdownListId = 0; var pageLoaderInertLocks = /* @__PURE__ */ new WeakMap(); var pageLoaderPositionLocks = /* @__PURE__ */ new WeakMap(); var textViewStyles = ` :host { box-sizing: border-box; display: inline-block; color-scheme: inherit; min-width: var(--biscuit-textview-min-width, 12rem); padding: var(--biscuit-textview-padding, calc(0.5rem * var(--biscuit-space-scale, 1)) calc(0.625rem * var(--biscuit-space-scale, 1))); border: var(--biscuit-textview-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-textview-border-color, light-dark(#a5a8b3, #656b7a)))); border-radius: var(--biscuit-textview-radius, 0.375rem); background: var(--biscuit-textview-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); color: var(--biscuit-textview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); font: var(--biscuit-textview-font, 400 1rem/1.5 system-ui, sans-serif); vertical-align: middle; resize: none; } ${themeStyles} :host([resizable]) { min-height: 3rem; overflow: auto; resize: both; } :host([resizable][limit-resize-to-parent]) { max-width: var(--biscuit-textview-parent-max-width, 100%); max-height: var(--biscuit-textview-parent-max-height, 100%); min-width: min(var(--biscuit-textview-min-width, 12rem), var(--biscuit-textview-parent-max-width, 100%)); min-height: min(3rem, var(--biscuit-textview-parent-max-height, 100%)); } :host([editable]:focus-within) { outline: 2px solid var(--biscuit-textview-focus-color, var(--biscuit-focus-color, var(--biscuit-theme-focus-color, light-dark(#6b63db, #aaa2ff)))); outline-offset: 2px; } [hidden] { display: none !important; } [part="text"] { display: block; min-height: 1.5em; white-space: pre-wrap; overflow-wrap: anywhere; } [part="editor"] { box-sizing: border-box; display: block; width: 100%; height: 100%; min-height: 1.5em; padding: 0; border: 0; outline: 0; resize: none; color: inherit; background: transparent; font: inherit; } `; var cardViewStyles = ` :host { box-sizing: border-box; display: block; color-scheme: inherit; padding: var(--biscuit-cardview-padding, calc(1.25rem * var(--biscuit-space-scale, 1))); border: var(--biscuit-cardview-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a)))); border-radius: var(--biscuit-cardview-radius, 0.75rem); background: var(--biscuit-cardview-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); box-shadow: var(--biscuit-cardview-shadow, var(--biscuit-theme-cardview-shadow, light-dark(0 2px 8px rgb(36 37 43 / 8%), 0 3px 14px rgb(0 0 0 / 25%)))); color: var(--biscuit-cardview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); font: var(--biscuit-cardview-font, inherit); } ${themeStyles} [hidden] { display: none !important; } [part="heading"] { margin: 0 0 var(--biscuit-cardview-gap, calc(0.75rem * var(--biscuit-space-scale, 1))); font-size: var(--biscuit-cardview-heading-size, 1.125rem); line-height: 1.3; } [part="body"] { min-width: 0; } `; var dropdownViewStyles = ` :host { box-sizing: border-box; display: inline-block; position: relative; min-width: var(--biscuit-dropdownview-min-width, 12rem); color-scheme: inherit; color: var(--biscuit-dropdownview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); font: var(--biscuit-dropdownview-font, 400 1rem/1.5 system-ui, sans-serif); } ${themeStyles} :host([open]) { z-index: 20; } :host([icon-only][data-selected-icon]) { min-width: 0; } [hidden] { display: none !important; } [part="trigger"] { box-sizing: border-box; display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; width: 100%; min-height: 2.75rem; padding: var(--biscuit-dropdownview-padding, calc(0.55rem * var(--biscuit-space-scale, 1)) calc(0.75rem * var(--biscuit-space-scale, 1))); border: var(--biscuit-dropdownview-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-textview-border-color, light-dark(#a5a8b3, #656b7a)))); border-radius: var(--biscuit-dropdownview-radius, 0.5rem); background: var(--biscuit-dropdownview-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); color: inherit; font: inherit; text-align: left; cursor: pointer; } [part="trigger"]:focus-visible { outline: 2px solid var(--biscuit-dropdownview-focus-color, var(--biscuit-focus-color, var(--biscuit-theme-focus-color, light-dark(#6b63db, #aaa2ff)))); outline-offset: 2px; } [part="trigger"]:disabled { cursor: not-allowed; opacity: 0.55; } :host([icon-only][data-selected-icon]) [part="trigger"] { justify-content: center; width: 2.75rem; padding: 0.55rem; } :host([icon-only][data-selected-icon]) [part="value"] > span, :host([icon-only][data-selected-icon]) [part="chevron"] { display: none; } [part="value"], [part="option-content"] { display: inline-flex; align-items: center; gap: 0.5rem; min-width: 0; } [part="value"] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } [part="icon"] { flex: none; width: 1.1em; height: 1.1em; } [part="chevron"] { flex: none; width: 0.5rem; height: 0.5rem; margin: -0.25rem 0.125rem 0 0; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform 120ms ease; } :host([open]) [part="chevron"] { transform: translateY(0.25rem) rotate(225deg); } [part="listbox"] { box-sizing: border-box; position: absolute; top: calc(100% + 0.375rem); left: 0; width: 100%; max-height: min(16rem, 70vh); overflow: auto; padding: 0.3rem; border: var(--biscuit-dropdownview-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-textview-border-color, light-dark(#a5a8b3, #656b7a)))); border-radius: var(--biscuit-dropdownview-radius, 0.5rem); background: var(--biscuit-dropdownview-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); box-shadow: var(--biscuit-dropdownview-shadow, 0 12px 32px rgb(0 0 0 / 20%)); color: inherit; } :host([icon-only]) [part="listbox"] { left: auto; right: 0; width: max-content; min-width: 12rem; } :host([icon-only][drop-left]) [part="listbox"] { left: 0; right: auto; } :host([drop-up]) [part="listbox"] { top: auto; bottom: calc(100% + 0.375rem); } [part="option"] { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.5rem 0.65rem; border-radius: 0.35rem; cursor: pointer; } [part="option"][data-active] { background: var(--biscuit-dropdownview-active-background, var(--biscuit-theme-option-background, light-dark(#efedff, #45415f))); color: var(--biscuit-dropdownview-active-color, var(--biscuit-theme-option-color, light-dark(#38306e, #fff))); } [part="option"][aria-selected="true"]::after { content: "✓"; font-weight: 700; } [part="option"][aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; } `; var buttonViewStyles = ` :host { box-sizing: border-box; display: inline-block; color-scheme: inherit; font: var(--biscuit-buttonview-font, 600 0.9375rem/1.4 system-ui, sans-serif); vertical-align: middle; } ${themeStyles} [hidden] { display: none !important; } [part="button"] { box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; gap: 0.55rem; width: 100%; min-height: var(--biscuit-buttonview-min-height, 2.75rem); padding: var(--biscuit-buttonview-padding, calc(0.625rem * var(--biscuit-space-scale, 1)) calc(1rem * var(--biscuit-space-scale, 1))); border: var(--biscuit-buttonview-border, 1px solid transparent); border-radius: var(--biscuit-buttonview-radius, 0.55rem); background: var(--biscuit-buttonview-background, var(--biscuit-theme-button-primary-background, light-dark(#6256ad, #c0bbff))); color: var(--biscuit-buttonview-color, var(--biscuit-theme-button-primary-color, light-dark(#fff, #211b3c))); font: inherit; white-space: nowrap; cursor: pointer; transition: background 120ms ease, filter 120ms ease, transform 120ms ease; } [part="button"]:hover:not(:disabled) { filter: brightness(1.08); } [part="button"]:active:not(:disabled) { transform: translateY(1px); } [part="button"]:focus-visible { outline: 2px solid var(--biscuit-buttonview-focus-color, var(--biscuit-focus-color, var(--biscuit-theme-focus-color, light-dark(#6b63db, #aaa2ff)))); outline-offset: 2px; } [part="button"]:disabled { cursor: not-allowed; opacity: 0.55; } :host([loading]) [part="button"]:disabled { opacity: 0.8; } [part="loading-indicator"] { --biscuit-loadingindicator-size: 0.9em; --biscuit-loadingindicator-color: inherit; color: inherit; } @media (prefers-reduced-motion: reduce) { [part="button"] { transition: none; } } :host([variant="secondary"]) [part="button"] { border: var(--biscuit-buttonview-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a)))); background: var(--biscuit-buttonview-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); color: var(--biscuit-buttonview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); } :host([variant="ghost"]) [part="button"] { background: var(--biscuit-buttonview-background, transparent); color: var(--biscuit-buttonview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); } :host([variant="danger"]) [part="button"] { background: var(--biscuit-buttonview-background, var(--biscuit-theme-button-danger-background, light-dark(#be3e4a, #ff8d94))); color: var(--biscuit-buttonview-color, var(--biscuit-theme-button-danger-color, light-dark(#fff, #281215))); } `; var loadingIndicatorStyles = ` :host { box-sizing: border-box; display: inline-flex; align-items: center; gap: var(--biscuit-loadingindicator-gap, 0.55rem); color-scheme: inherit; color: var(--biscuit-loadingindicator-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); font: var(--biscuit-loadingindicator-font, 500 0.9375rem/1.4 system-ui, sans-serif); vertical-align: middle; } ${themeStyles} [part="spinner"] { box-sizing: border-box; width: var(--biscuit-loadingindicator-size, 1.1em); height: var(--biscuit-loadingindicator-size, 1.1em); flex: none; border: var(--biscuit-loadingindicator-stroke, 2px) solid currentColor; border-right-color: transparent; border-radius: 50%; animation: biscuit-loading-spin 700ms linear infinite; } [part="label"]:empty { display: none; } :host([size="small"]) { --biscuit-loadingindicator-size: 0.85em; } :host([size="large"]) { --biscuit-loadingindicator-size: 1.5em; } @keyframes biscuit-loading-spin { to { transform: rotate(360deg); } } @media (prefers-reduced-motion: reduce) { [part="spinner"] { animation-duration: 2s; } } `; var pageLoaderViewStyles = ` :host { box-sizing: border-box; position: fixed; inset: 0; z-index: var(--biscuit-pageloaderview-z-index, 2000); display: grid; place-items: center; overflow: auto; overscroll-behavior: contain; color-scheme: inherit; background: var(--biscuit-pageloaderview-backdrop, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #171920)))); color: var(--biscuit-pageloaderview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); font: var(--biscuit-pageloaderview-font, 400 1rem/1.5 system-ui, sans-serif); } ${themeStyles} :host(:not([open])) { display: none; } :host([mode="container"]) { position: absolute; z-index: var(--biscuit-pageloaderview-container-z-index, 1); } [part="panel"] { box-sizing: border-box; display: grid; justify-items: center; gap: 0.85rem; width: min(var(--biscuit-pageloaderview-panel-width, 24rem), calc(100% - 2rem)); padding: var(--biscuit-pageloaderview-padding, 2rem 1.5rem); border: var(--biscuit-pageloaderview-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a)))); border-radius: var(--biscuit-pageloaderview-radius, 0.875rem); background: var(--biscuit-pageloaderview-panel-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); box-shadow: var(--biscuit-pageloaderview-shadow, 0 12px 36px rgb(0 0 0 / 12%)); text-align: center; } [part="panel"]:focus { outline: none; } [part="indicator"] { --biscuit-loadingindicator-size: 1.75rem; --biscuit-loadingindicator-gap: 0.85rem; --biscuit-loadingindicator-font: 650 1rem/1.4 system-ui, sans-serif; } [part="content"][hidden] { display: none; } ::slotted(*) { margin: 0; color: inherit; } :host([mode="container"]) [part="panel"] { width: min(var(--biscuit-pageloaderview-panel-width, 20rem), calc(100% - 1.5rem)); padding: var(--biscuit-pageloaderview-padding, 1.5rem 1rem); } :host([indicator-only]) [part="panel"] { width: auto; padding: 0; border: 0; background: transparent; box-shadow: none; } :host([indicator-only]) [part="indicator"] { --biscuit-loadingindicator-size: var(--biscuit-pageloaderview-indicator-size, 4rem); --biscuit-loadingindicator-stroke: var(--biscuit-pageloaderview-indicator-stroke, 4px); } :host([indicator-only]) [part="indicator"]::part(label), :host([indicator-only]) [part="content"] { display: none; } `; var badgeViewStyles = ` :host { --_badge-tone: var(--biscuit-theme-badge-neutral, light-dark(#555b69, #d2d5df)); box-sizing: border-box; display: inline-flex; align-items: center; max-width: 100%; vertical-align: middle; color-scheme: inherit; border: var(--biscuit-badgeview-border, var(--biscuit-theme-badge-border, 1px solid color-mix(in srgb, var(--_badge-tone) 30%, transparent))); border-radius: var(--biscuit-badgeview-radius, 999px); padding: var(--biscuit-badgeview-padding, calc(0.2rem * var(--biscuit-space-scale, 1)) calc(0.65rem * var(--biscuit-space-scale, 1))); background: var(--biscuit-badgeview-background, var(--biscuit-theme-badge-background, color-mix(in srgb, var(--_badge-tone) 12%, var(--biscuit-theme-surface, light-dark(#fff, #292c37))))); color: var(--biscuit-badgeview-color, var(--_badge-tone)); font: var(--biscuit-badgeview-font, 650 0.75rem/1.35 system-ui, sans-serif); white-space: nowrap; } ${themeStyles} :host([variant="accent"]) { --_badge-tone: var(--biscuit-theme-badge-accent, light-dark(#5b4bb1, #c3baff)); } :host([variant="success"]) { --_badge-tone: var(--biscuit-theme-badge-success, light-dark(#176d4b, #8ce0ae)); } :host([variant="warning"]) { --_badge-tone: var(--biscuit-theme-badge-warning, light-dark(#8b5600, #ffd27a)); } :host([variant="danger"]) { --_badge-tone: var(--biscuit-theme-badge-danger, light-dark(#ad3442, #ff9ca4)); } :host([size="small"]) { padding: var(--biscuit-badgeview-padding, 0.12rem 0.45rem); font-size: 0.6875rem; } :host([size="large"]) { padding: var(--biscuit-badgeview-padding, 0.3rem 0.8rem); font-size: 0.875rem; } :host([dot]) { --_badge-dot-size: 0.7rem; width: var(--biscuit-badgeview-dot-size, var(--_badge-dot-size)); height: var(--biscuit-badgeview-dot-size, var(--_badge-dot-size)); min-width: var(--biscuit-badgeview-dot-size, var(--_badge-dot-size)); padding: 0; border: 0; background: var(--biscuit-badgeview-dot-color, var(--_badge-tone)); } :host([dot][size="small"]) { --_badge-dot-size: 0.55rem; } :host([dot][size="large"]) { --_badge-dot-size: 0.9rem; } [part="badge"] { min-width: 0; overflow: hidden; text-overflow: ellipsis; } [hidden] { display: none !important; } :host([dot]) [part="badge"] { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } [part="accessible-count"] { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } `; var BiscuitTextView = class extends HTMLElementBase { static formAssociated = true; static get observedAttributes() { return [ "text", "editable", "resizable", "limit-resize-to-parent", "placeholder", "aria-label", "name", "required", "disabled" ]; } constructor() { super(); this._internals = this.attachInternals?.() ?? null; if (!this._internals?.setFormValue) this._internals = null; this._text = ""; this._resizeMaxWidth = null; this._resizeMaxHeight = null; this._onResizeStart = () => this._updateResizeLimit(false); this._onWindowResize = () => this._updateResizeLimit(true); this.addEventListener("pointerdown", this._onResizeStart); const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = textViewStyles; this._display = document.createElement("span"); this._display.setAttribute("part", "text"); this._editor = document.createElement("textarea"); this._editor.setAttribute("part", "editor"); this._editor.rows = 1; this._editor.addEventListener("input", () => { this.text = this._editor.value; this.dispatchEvent(new Event("input", { bubbles: true, composed: true })); }); this._editor.addEventListener("change", () => this.dispatchEvent(new Event("change", { bubbles: true, composed: true }))); root.append(style, this._display, this._editor); this._renderMode(); } connectedCallback() { this._defaultText ??= this.getAttribute("text") ?? ""; this._syncForm(); this._updateResizeLimit(true); if (globalThis.ResizeObserver && this.parentElement) { this._parentObserver = new ResizeObserver(() => this._updateResizeLimit(false)); this._parentObserver.observe(this.parentElement); } globalThis.addEventListener?.("resize", this._onWindowResize); } disconnectedCallback() { this._parentObserver?.disconnect(); this._parentObserver = null; globalThis.removeEventListener?.("resize", this._onWindowResize); } attributeChangedCallback(name, oldValue, newValue) { if (oldValue === newValue) return; if (name === "text") { this._text = newValue ?? ""; this._display.textContent = this._text; if (this._editor.value !== this._text) this._editor.value = this._text; this._syncForm(); } else if (name === "editable") { this._renderMode(); this._syncForm(); } else if (name === "resizable" || name === "limit-resize-to-parent") this._updateResizeLimit(true); else if (name === "placeholder") this._editor.placeholder = newValue ?? ""; else if (name === "aria-label") this._editor.setAttribute("aria-label", newValue ?? "Text"); else if (name === "name" || name === "required" || name === "disabled") this._syncForm(); } get text() { return this._text; } set text(value) { this.setAttribute("text", String(value ?? "")); } get name() { return this.getAttribute("name") ?? ""; } set name(value) { if (value == null) this.removeAttribute("name"); else this.setAttribute("name", String(value)); } get value() { return this.text; } set value(value) { this.text = value; } get required() { return this.hasAttribute("required"); } set required(value) { this.toggleAttribute("required", Boolean(value)); } get disabled() { return this.hasAttribute("disabled"); } set disabled(value) { this.toggleAttribute("disabled", Boolean(value)); } get validity() { return this._editor.validity; } get validationMessage() { return this._editor.validationMessage; } checkValidity() { this._syncForm(); return this._editor.checkValidity(); } reportValidity() { this._syncForm(); return this._editor.reportValidity(); } formResetCallback() { this.text = this._defaultText ?? ""; } formDisabledCallback() { this._syncForm(); } _syncForm() { if (!this._editor) return; this._editor.disabled = this.disabled || !this.editable; this._editor.required = this.required && this.editable; syncFormValue(this, this.name && this.editable && !this.disabled ? this.text : null); if (this._internals) this._internals.setValidity(this._editor.validity?.valid === false ? { valueMissing: true } : {}, this._editor.validationMessage || "", this._editor); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } get editable() { return this.hasAttribute("editable"); } set editable(value) { this.toggleAttribute("editable", Boolean(value)); } get resizable() { return this.hasAttribute("resizable"); } set resizable(value) { this.toggleAttribute("resizable", Boolean(value)); } get limitResizeToParent() { return this.hasAttribute("limit-resize-to-parent"); } set limitResizeToParent(value) { this.toggleAttribute("limit-resize-to-parent", Boolean(value)); } get placeholder() { return this.getAttribute("placeholder") ?? ""; } set placeholder(value) { if (value == null) this.removeAttribute("placeholder"); else this.setAttribute("placeholder", String(value)); } focus(options) { if (this.editable) this._editor.focus(options); else super.focus(options); } _renderMode() { const editable = this.editable; this._display.hidden = editable; this._editor.hidden = !editable; if (editable && !this._editor.hasAttribute("aria-label")) this._editor.setAttribute("aria-label", this.getAttribute("aria-label") ?? "Text"); } _updateResizeLimit(allowGrowth) { if (!this.resizable || !this.limitResizeToParent) { this._resizeMaxWidth = null; this._resizeMaxHeight = null; this.style.removeProperty("--biscuit-textview-parent-max-width"); this.style.removeProperty("--biscuit-textview-parent-max-height"); return; } if (!this.isConnected || !this.parentElement) return; const parentRect = this.parentElement.getBoundingClientRect(); const viewRect = this.getBoundingClientRect(); const availableWidth = Math.max(0, parentRect.right - viewRect.left); const availableHeight = Math.max(0, parentRect.bottom - viewRect.top); if (!parentRect.width || !parentRect.height) return; this._resizeMaxWidth = allowGrowth || this._resizeMaxWidth == null ? availableWidth : Math.min(this._resizeMaxWidth, availableWidth); this._resizeMaxHeight = allowGrowth || this._resizeMaxHeight == null ? availableHeight : Math.min(this._resizeMaxHeight, availableHeight); this.style.setProperty("--biscuit-textview-parent-max-width", `${this._resizeMaxWidth}px`); this.style.setProperty("--biscuit-textview-parent-max-height", `${this._resizeMaxHeight}px`); } }; var BiscuitCardView = class extends HTMLElementBase { static get observedAttributes() { return ["heading"]; } constructor() { super(); const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = cardViewStyles; const card = document.createElement("article"); card.setAttribute("part", "card"); this._heading = document.createElement("h3"); this._heading.setAttribute("part", "heading"); this._heading.hidden = true; const body = document.createElement("div"); body.setAttribute("part", "body"); body.append(document.createElement("slot")); card.append(this._heading, body); root.append(style, card); } attributeChangedCallback(name, oldValue, newValue) { if (name !== "heading" || oldValue === newValue) return; this._heading.textContent = newValue ?? ""; this._heading.hidden = !newValue; } get heading() { return this.getAttribute("heading") ?? ""; } set heading(value) { if (value == null) this.removeAttribute("heading"); else this.setAttribute("heading", String(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } }; var BiscuitDropdownView = class extends HTMLElementBase { static formAssociated = true; static get observedAttributes() { return [ "value", "placeholder", "disabled", "aria-label", "name", "required", "icon-only" ]; } constructor() { super(); this._internals = this.attachInternals?.() ?? null; if (!this._internals?.setFormValue) this._internals = null; this._options = []; this._optionNodes = []; this._value = ""; this._activeIndex = -1; this._isOpen = false; this._onDocumentPointerDown = (event) => { if (!event.composedPath().includes(this)) this._setOpen(false); }; const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = dropdownViewStyles; this._button = document.createElement("button"); this._button.type = "button"; this._button.setAttribute("part", "trigger"); this._button.setAttribute("role", "combobox"); this._button.setAttribute("aria-haspopup", "listbox"); this._button.setAttribute("aria-expanded", "false"); this._button.addEventListener("click", () => this._setOpen(!this._isOpen)); this._button.addEventListener("keydown", (event) => this._onKeyDown(event)); this._buttonLabel = document.createElement("span"); this._buttonLabel.setAttribute("part", "value"); const chevron = document.createElement("span"); chevron.setAttribute("part", "chevron"); chevron.setAttribute("aria-hidden", "true"); this._button.append(this._buttonLabel, chevron); this._list = document.createElement("div"); this._list.setAttribute("part", "listbox"); this._list.setAttribute("role", "listbox"); this._list.id = `biscuit-dropdown-list-${++dropdownListId}`; this._list.hidden = true; this._button.setAttribute("aria-controls", this._list.id); root.append(style, this._button, this._list); } connectedCallback() { this._syncOptions(); if (globalThis.MutationObserver) { this._observer = new MutationObserver(() => this._syncOptions()); this._observer.observe(this, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: [ "value", "label", "icon", "selected", "disabled" ] }); } } disconnectedCallback() { this._observer?.disconnect(); this._observer = null; this._setOpen(false); } attributeChangedCallback(name, oldValue, newValue) { if (oldValue !== newValue && this._button) this._syncOptions(); } get value() { return this._value; } get iconOnly() { return this.hasAttribute("icon-only"); } set iconOnly(value) { this.toggleAttribute("icon-only", Boolean(value)); } get name() { return this.getAttribute("name") ?? ""; } set name(value) { if (value == null) this.removeAttribute("name"); else this.setAttribute("name", String(value)); } get required() { return this.hasAttribute("required"); } set required(value) { this.toggleAttribute("required", Boolean(value)); } checkValidity() { this._syncOptions(); return !this.required || Boolean(this._value); } reportValidity() { const valid = this.checkValidity(); if (!valid) this._button.focus(); return valid; } formResetCallback() { this.removeAttribute("value"); this._syncOptions(); } formDisabledCallback() { this._syncOptions(); } set value(value) { this.setAttribute("value", String(value ?? "")); } get placeholder() { return this.getAttribute("placeholder") ?? ""; } set placeholder(value) { if (value == null) this.removeAttribute("placeholder"); else this.setAttribute("placeholder", String(value)); } get disabled() { return this.hasAttribute("disabled"); } set disabled(value) { this.toggleAttribute("disabled", Boolean(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } focus(options) { this._button.focus(options); } _syncOptions() { this._options = Array.from(this.children).filter((child) => child.tagName === "OPTION").map((child) => ({ value: child.getAttribute("value") ?? child.textContent.trim(), label: child.getAttribute("label") ?? child.textContent.trim(), icon: child.getAttribute("icon"), disabled: child.hasAttribute("disabled"), selected: child.hasAttribute("selected") })); const requested = this.getAttribute("value"); let selectedIndex = requested === null ? this._options.findIndex((option) => option.selected && !option.disabled) : this._options.findIndex((option) => option.value === requested && !option.disabled); if (requested === null && selectedIndex < 0 && !this.hasAttribute("placeholder")) selectedIndex = this._options.findIndex((option) => !option.disabled); this._value = selectedIndex < 0 ? "" : this._options[selectedIndex].value; syncFormValue(this, this.name && !this.disabled && this._value ? this._value : null); this._internals?.setValidity(this.required && !this._value ? { valueMissing: true } : {}, this.required && !this._value ? "Choose an option." : "", this._button); const label = selectedIndex < 0 ? this.placeholder || "Select…" : this._options[selectedIndex].label; const selectedIcon = selectedIndex < 0 ? null : this._options[selectedIndex].icon; this.toggleAttribute("data-selected-icon", Boolean(selectedIcon && iconSvgs[selectedIcon])); this._buttonLabel.replaceChildren(); if (selectedIcon && iconSvgs[selectedIcon]) { const icon = createIcon(selectedIcon); icon.setAttribute("part", "icon"); const text = document.createElement("span"); text.textContent = label; this._buttonLabel.append(icon, text); } else this._buttonLabel.textContent = label; this._button.disabled = this.disabled || !this._options.some((option) => !option.disabled); const accessibleLabel = this.getAttribute("aria-label"); if (accessibleLabel || this.iconOnly) this._button.setAttribute("aria-label", accessibleLabel ? `${accessibleLabel}: ${label}` : label); else this._button.removeAttribute("aria-label"); if (accessibleLabel) this._list.setAttribute("aria-label", accessibleLabel); else this._list.removeAttribute("aria-label"); this._optionNodes = this._options.map((option, index) => { const node = document.createElement("div"); node.id = `${this._list.id}-option-${index}`; node.setAttribute("part", "option"); node.setAttribute("role", "option"); node.setAttribute("aria-selected", String(index === selectedIndex)); if (option.disabled) node.setAttribute("aria-disabled", "true"); if (option.icon && iconSvgs[option.icon]) { const content = document.createElement("span"); content.setAttribute("part", "option-content"); const icon = createIcon(option.icon); icon.setAttribute("part", "icon"); const label = document.createElement("span"); label.textContent = option.label; content.append(icon, label); node.append(content); } else node.textContent = option.label; node.addEventListener("pointerenter", () => { if (!option.disabled) this._setActive(index); }); node.addEventListener("click", () => this._select(index)); return node; }); this._list.replaceChildren(...this._optionNodes); if (this._isOpen && this._button.disabled) this._setOpen(false); else if (this._isOpen) this._setActive(selectedIndex < 0 ? this._firstEnabled() : selectedIndex); } _firstEnabled() { return this._options.findIndex((option) => !option.disabled); } _setActive(index) { this._activeIndex = index; this._optionNodes.forEach((node, nodeIndex) => { if (nodeIndex === index) node.setAttribute("data-active", ""); else node.removeAttribute("data-active"); }); if (index < 0) this._button.removeAttribute("aria-activedescendant"); else { this._button.setAttribute("aria-activedescendant", this._optionNodes[index].id); this._optionNodes[index].scrollIntoView?.({ block: "nearest" }); } } _setOpen(open) { if (open && (this.disabled || this._firstEnabled() < 0)) return; if (open === this._isOpen) return; this._isOpen = open; this.toggleAttribute("open", open); this._list.hidden = !open; this._button.setAttribute("aria-expanded", String(open)); if (open) { const selectedIndex = this._options.findIndex((option) => option.value === this._value && !option.disabled); this._setActive(selectedIndex < 0 ? this._firstEnabled() : selectedIndex); const bounds = this.getBoundingClientRect?.(); if (bounds && globalThis.innerHeight) this.toggleAttribute("drop-up", globalThis.innerHeight - bounds.bottom < this._list.offsetHeight + 8 && bounds.top > globalThis.innerHeight - bounds.bottom); if (bounds && this.iconOnly && globalThis.innerWidth) this.toggleAttribute("drop-left", bounds.right - this._list.offsetWidth < 8 && globalThis.innerWidth - bounds.left >= this._list.offsetWidth + 8); document.addEventListener("pointerdown", this._onDocumentPointerDown); } else { this._button.removeAttribute("aria-activedescendant"); this.removeAttribute("drop-up"); this.removeAttribute("drop-left"); document.removeEventListener("pointerdown", this._onDocumentPointerDown); } } _moveActive(direction) { const enabled = this._options.flatMap((option, index) => option.disabled ? [] : [index]); if (!enabled.length) return; const next = (enabled.indexOf(this._activeIndex) + direction + enabled.length) % enabled.length; this._setActive(enabled[next]); } _onKeyDown(event) { if (this.disabled) return; if (event.key === "ArrowDown" || event.key === "ArrowUp") { event.preventDefault(); if (!this._isOpen) this._setOpen(true); else this._moveActive(event.key === "ArrowDown" ? 1 : -1); } else if (event.key === "Home" || event.key === "End") { event.preventDefault(); this._setOpen(true); const index = event.key === "Home" ? this._firstEnabled() : this._options.findLastIndex((option) => !option.disabled); if (index >= 0) this._setActive(index); } else if (event.key === "Enter" || event.key === " ") { event.preventDefault(); if (this._isOpen) this._select(this._activeIndex); else this._setOpen(true); } else if (event.key === "Escape" && this._isOpen) { event.preventDefault(); this._setOpen(false); } else if (event.key === "Tab") this._setOpen(false); } _select(index) { const option = this._options[index]; if (!option || option.disabled) return; const previous = this._value; this.value = option.value; this._setOpen(false); this._button.focus(); if (this._value !== previous) { this.dispatchEvent(new Event("input", { bubbles: true, composed: true })); this.dispatchEvent(new Event("change", { bubbles: true, composed: true })); } } }; var BiscuitLoadingIndicator = class extends HTMLElementBase { static get observedAttributes() { return ["label"]; } constructor() { super(); const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = loadingIndicatorStyles; const spinner = document.createElement("span"); spinner.setAttribute("part", "spinner"); spinner.setAttribute("aria-hidden", "true"); this._label = document.createElement("span"); this._label.setAttribute("part", "label"); root.append(style, spinner, this._label); this._renderLabel(); } connectedCallback() { if (!this.hasAttribute("role")) this.setAttribute("role", "status"); if (!this.hasAttribute("aria-live")) this.setAttribute("aria-live", "polite"); } attributeChangedCallback(name, oldValue, newValue) { if (name === "label" && oldValue !== newValue) this._renderLabel(); } get label() { return this.getAttribute("label") ?? "Loading…"; } set label(value) { if (value == null) this.removeAttribute("label"); else this.setAttribute("label", String(value)); } get size() { return this.getAttribute("size") ?? "medium"; } set size(value) { if (value == null || value === "medium") this.removeAttribute("size"); else this.setAttribute("size", String(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } _renderLabel() { this._label.textContent = this.label; } }; var BiscuitPageLoaderView = class extends HTMLElementBase { static get observedAttributes() { return [ "open", "mode", "message" ]; } constructor() { super(); this._inertSiblings = null; this._containerInertSiblings = null; this._containerParent = null; this._positionedParent = null; this._restoreFocus = null; const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = pageLoaderViewStyles; this._panel = document.createElement("div"); this._panel.setAttribute("part", "panel"); this._panel.tabIndex = -1; this._indicator = document.createElement(LOADINGINDICATOR_TAG_NAME); this._indicator.setAttribute("part", "indicator"); this._indicator.setAttribute("size", "large"); this._indicator.setAttribute("aria-hidden", "true"); this._contentSlot = document.createElement("slot"); this._contentSlot.setAttribute("part", "content"); this._contentSlot.hidden = true; this._contentSlot.addEventListener("slotchange", () => this._syncSlot()); this._panel.append(this._indicator, this._contentSlot); root.append(style, this._panel); this._renderMessage(); } connectedCallback() { this._syncSlot(); this._syncState(); } disconnectedCallback() { this._releasePage(); this._releaseContainer(); } attributeChangedCallback(name, oldValue, newValue) { if (oldValue === newValue) return; if (name === "message") this._renderMessage(); else this._syncState(); } get open() { return this.hasAttribute("open"); } set open(value) { this.toggleAttribute("open", Boolean(value)); } get mode() { return this.getAttribute("mode") === "container" ? "container" : "page"; } set mode(value) { if (value === "container") this.setAttribute("mode", "container"); else this.removeAttribute("mode"); } get message() { return this.getAttribute("message") ?? "Loading…"; } set message(value) { if (value == null) this.removeAttribute("message"); else this.setAttribute("message", String(value)); } get indicatorOnly() { return this.hasAttribute("indicator-only"); } set indicatorOnly(value) { this.toggleAttribute("indicator-only", Boolean(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } show() { this.open = true; } hide() { this.open = false; } _renderMessage() { this._indicator.label = this.message; this._panel.setAttribute("aria-label", this.message); } _syncSlot() { const nodes = this._contentSlot.assignedNodes?.({ flatten: true }) ?? this.children; this._contentSlot.hidden = !Array.from(nodes).some((node) => node.nodeType === 1 || node.textContent?.trim()); } _syncState() { const active = this.open && this.isConnected; const page = this.mode === "page"; this._panel.setAttribute("role", page ? "dialog" : "status"); if (page) this._panel.setAttribute("aria-modal", "true"); else this._panel.removeAttribute("aria-modal"); this._panel.setAttribute("aria-live", "polite"); this.setAttribute("aria-busy", String(Boolean(active))); if (active && page) { this._releaseContainer(); this._lockPage(); } else if (active) { this._releasePage(); this._lockContainer(); } else { this._releasePage(); this._releaseContainer(); } } _lockPage() { if (this._inertSiblings) return; this._restoreFocus = document.activeElement; this._inertSiblings = []; let node = this; while (node.parentElement) { const parent = node.parentElement; for (const sibling of parent.children) { if (sibling === node) continue; this._makeInert(sibling); this._inertSiblings.push(sibling); } node = parent; if (parent === document.body) break; } this._panel.focus(); } _releasePage() { if (!this._inertSiblings) return; for (const sibling of this._inertSiblings) this._restoreInert(sibling); this._inertSiblings = null; this._restoreFocus?.focus?.(); this._restoreFocus = null; } _lockContainer() { const parent = this.parentElement; if (!parent || this._containerParent === parent) return; this._releaseContainer(); this._containerParent = parent; this._containerInertSiblings = []; for (const sibling of parent.children) { if (sibling === this) continue; this._makeInert(sibling); this._containerInertSiblings.push(sibling); } const lock = pageLoaderPositionLocks.get(parent); if (lock) lock.count += 1; else { const position = globalThis.getComputedStyle?.(parent).position ?? parent.style.getPropertyValue("position") ?? "static"; if (position !== "static" && position !== "") return; pageLoaderPositionLocks.set(parent, { count: 1, original: parent.style.getPropertyValue("position"), priority: parent.style.getPropertyPriority?.("position") ?? "" }); parent.style.setProperty("position", "relative"); } this._positionedParent = parent; } _releaseContainer() { if (this._containerInertSiblings) { for (const sibling of this._containerInertSiblings) this._restoreInert(sibling); this._containerInertSiblings = null; } this._containerParent = null; if (!this._positionedParent) return; const parent = this._positionedParent; const lock = pageLoaderPositionLocks.get(parent); if (lock) { lock.count -= 1; if (lock.count === 0) { if (parent.style.getPropertyValue("position") === "relative") { if (lock.original) parent.style.setProperty("position", lock.original, lock.priority); else parent.style.removeProperty("position"); } pageLoaderPositionLocks.delete(parent); } } this._positionedParent = null; } _makeInert(element) { const lock = pageLoaderInertLocks.get(element); if (lock) lock.count += 1; else pageLoaderInertLocks.set(element, { count: 1, original: element.inert }); element.inert = true; } _restoreInert(element) { const lock = pageLoaderInertLocks.get(element); if (!lock) return; lock.count -= 1; if (lock.count === 0) { element.inert = lock.original; pageLoaderInertLocks.delete(element); } } }; var BiscuitBadgeView = class extends HTMLElementBase { static get observedAttributes() { return [ "label", "count", "max", "dot" ]; } constructor() { super(); const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = badgeViewStyles; this._badge = document.createElement("span"); this._badge.setAttribute("part", "badge"); this._text = document.createElement("span"); this._text.setAttribute("part", "text"); this._slot = document.createElement("slot"); this._slot.setAttribute("part", "content"); this._slot.addEventListener("slotchange", () => this._render()); this._accessibleCount = document.createElement("span"); this._accessibleCount.setAttribute("part", "accessible-count"); this._badge.append(this._text, this._slot, this._accessibleCount); root.append(style, this._badge); this._render(); } connectedCallback() { this._render(); } attributeChangedCallback(name, oldValue, newValue) { if (oldValue !== newValue) this._render(); } get label() { return this.getAttribute("label") ?? ""; } set label(value) { if (value == null) this.removeAttribute("label"); else this.setAttribute("label", String(value)); } get count() { if (!this.hasAttribute("count")) return null; const count = Number(this.getAttribute("count")); return Number.isInteger(count) && count >= 0 ? count : null; } set count(value) { if (value == null) this.removeAttribute("count"); else { const count = Number(value); if (!Number.isInteger(count) || count < 0) throw new RangeError("BadgeView count must be a non-negative integer"); this.setAttribute("count", String(count)); } } get max() { const max = Number(this.getAttribute("max")); return this.hasAttribute("max") && Number.isInteger(max) && max >= 0 ? max : 99; } set max(value) { if (value == null) this.removeAttribute("max"); else { const max = Number(value); if (!Number.isInteger(max) || max < 0) throw new RangeError("BadgeView max must be a non-negative integer"); this.setAttribute("max", String(max)); } } get dot() { return this.hasAttribute("dot"); } set dot(value) { this.toggleAttribute("dot", Boolean(value)); } get variant() { return this.getAttribute("variant") ?? "neutral"; } set variant(value) { if (value == null || value === "neutral") this.removeAttribute("variant"); else this.setAttribute("variant", String(value)); } get size() { return this.getAttribute("size") ?? "medium"; } set size(value) { if (value == null || value === "medium") this.removeAttribute("size"); else this.setAttribute("size", String(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } _render() { const count = this.count; const label = this.label; if (this.dot) { this._text.textContent = label || this.textContent?.trim() || ""; this._text.hidden = false; this._text.removeAttribute("aria-hidden"); this._slot.hidden = true; this._accessibleCount.hidden = true; } else if (count !== null) { this._text.textContent = count > this.max ? `${this.max}+` : String(count); this._text.hidden = false; if (label) this._text.setAttribute("aria-hidden", "true"); else this._text.removeAttribute("aria-hidden"); this._slot.hidden = true; this._accessibleCount.textContent = label ? `${count} ${label}` : ""; this._accessibleCount.hidden = !label; } else { this._text.textContent = label; this._text.hidden = !label; this._text.removeAttribute("aria-hidden"); this._slot.hidden = Boolean(label); this._accessibleCount.hidden = true; } } }; var BiscuitButtonView = class extends HTMLElementBase { static get observedAttributes() { return [ "disabled", "loading", "loading-label", "aria-label" ]; } constructor() { super(); this.action = null; const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = buttonViewStyles; this._button = document.createElement("button"); this._button.type = "button"; this._button.setAttribute("part", "button"); this._button.addEventListener("click", () => { if (typeof this.action === "function") this.run().catch(() => {}); }); this._content = document.createElement("span"); this._content.setAttribute("part", "content"); this._content.append(document.createElement("slot")); this._indicator = document.createElement(LOADINGINDICATOR_TAG_NAME); this._indicator.setAttribute("part", "loading-indicator"); this._indicator.setAttribute("aria-hidden", "true"); this._indicator.setAttribute("label", ""); this._loadingText = document.createElement("span"); this._loadingText.setAttribute("part", "loading-label"); this._loadingText.setAttribute("role", "status"); this._button.append(this._content, this._indicator, this._loadingText); root.append(style, this._button); this._renderState(); } attributeChangedCallback(name, oldValue, newValue) { if (oldValue !== newValue && this._button) this._renderState(); } get disabled() { return this.hasAttribute("disabled"); } set disabled(value) { this.toggleAttribute("disabled", Boolean(value)); } get loading() { return this.hasAttribute("loading"); } set loading(value) { this.toggleAttribute("loading", Boolean(value)); } get loadingLabel() { return this.getAttribute("loading-label") ?? "Working…"; } set loadingLabel(value) { if (value == null) this.removeAttribute("loading-label"); else this.setAttribute("loading-label", String(value)); } get variant() { return this.getAttribute("variant") ?? "primary"; } set variant(value) { if (value == null || value === "primary") this.removeAttribute("variant"); else this.setAttribute("variant", String(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } focus(options) { this._button.focus(options); } click() { this._button.click(); } async run(action = this.action) { if (this.disabled || this.loading || typeof action !== "function") return; let result; try { result = action(this); } catch (error) { this._reportActionError(error); throw error; } if (!result || typeof result.then !== "function") return result; this.loading = true; try { return await result; } catch (error) { this._reportActionError(error); throw error; } finally { this.loading = false; } } _reportActionError(error) { const event = new Event("actionerror", { bubbles: true, composed: true }); Object.defineProperty(event, "detail", { value: error }); this.dispatchEvent(event); } _renderState() { const loading = this.loading; this._button.disabled = this.disabled || loading; this._button.setAttribute("aria-busy", String(loading)); this._content.hidden = loading; this._indicator.hidden = !loading; this._loadingText.hidden = !loading; this._loadingText.textContent = this.loadingLabel; const label = this.getAttribute("aria-label"); if (loading) this._button.setAttribute("aria-label", this.loadingLabel || "Working…"); else if (label) this._button.setAttribute("aria-label", label); else this._button.removeAttribute("aria-label"); } }; function defineTextView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit TextView requires a browser with Custom Elements"); const existing = registry.get(TEXTVIEW_TAG_NAME); if (existing && existing !== BiscuitTextView) throw new Error(`<${TEXTVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(TEXTVIEW_TAG_NAME, BiscuitTextView); return BiscuitTextView; } function defineCardView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit CardView requires a browser with Custom Elements"); const existing = registry.get(CARDVIEW_TAG_NAME); if (existing && existing !== BiscuitCardView) throw new Error(`<${CARDVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(CARDVIEW_TAG_NAME, BiscuitCardView); return BiscuitCardView; } function defineDropdownView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit DropdownView requires a browser with Custom Elements"); const existing = registry.get(DROPDOWNVIEW_TAG_NAME); if (existing && existing !== BiscuitDropdownView) throw new Error(`<${DROPDOWNVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(DROPDOWNVIEW_TAG_NAME, BiscuitDropdownView); return BiscuitDropdownView; } function defineLoadingIndicator() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit LoadingIndicator requires a browser with Custom Elements"); const existing = registry.get(LOADINGINDICATOR_TAG_NAME); if (existing && existing !== BiscuitLoadingIndicator) throw new Error(`<${LOADINGINDICATOR_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(LOADINGINDICATOR_TAG_NAME, BiscuitLoadingIndicator); return BiscuitLoadingIndicator; } function definePageLoaderView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit PageLoaderView requires a browser with Custom Elements"); defineLoadingIndicator(); const existing = registry.get(PAGELOADERVIEW_TAG_NAME); if (existing && existing !== BiscuitPageLoaderView) throw new Error(`<${PAGELOADERVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(PAGELOADERVIEW_TAG_NAME, BiscuitPageLoaderView); return BiscuitPageLoaderView; } function defineBadgeView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit BadgeView requires a browser with Custom Elements"); const existing = registry.get(BADGEVIEW_TAG_NAME); if (existing && existing !== BiscuitBadgeView) throw new Error(`<${BADGEVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(BADGEVIEW_TAG_NAME, BiscuitBadgeView); return BiscuitBadgeView; } function defineButtonView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit ButtonView requires a browser with Custom Elements"); defineLoadingIndicator(); const existing = registry.get(BUTTONVIEW_TAG_NAME); if (existing && existing !== BiscuitButtonView) throw new Error(`<${BUTTONVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(BUTTONVIEW_TAG_NAME, BiscuitButtonView); return BiscuitButtonView; } function createTextView(options = {}) { if (!globalThis.document) throw new Error("Biscuit TextView requires a browser document"); defineTextView(); const element = createConfiguredElement(TEXTVIEW_TAG_NAME, options); if (Object.hasOwn(options, "text")) element.text = options.text; if (Object.hasOwn(options, "theme")) element.theme = options.theme; if (Object.hasOwn(options, "editable")) element.editable = options.editable; if (Object.hasOwn(options, "resizable")) element.resizable = options.resizable; if (Object.hasOwn(options, "limitResizeToParent")) element.limitResizeToParent = options.limitResizeToParent; if (Object.hasOwn(options, "placeholder")) element.placeholder = options.placeholder; if (Object.hasOwn(options, "ariaLabel")) element.setAttribute("aria-label", String(options.ariaLabel)); return element; } function createCardView(options = {}) { if (!globalThis.document) throw new Error("Biscuit CardView requires a browser document"); defineCardView(); const element = createConfiguredElement(CARDVIEW_TAG_NAME, options); if (Object.hasOwn(options, "heading")) element.heading = options.heading; if (Object.hasOwn(options, "theme")) element.theme = options.theme; if (options.content != null) element.append(options.content); return element; } function createDropdownView(options = {}) { if (!globalThis.document) throw new Error("Biscuit DropdownView requires a browser document"); defineDropdownView(); const element = createConfiguredElement(DROPDOWNVIEW_TAG_NAME, options); if (Object.hasOwn(options, "theme")) element.theme = options.theme; if (Object.hasOwn(options, "placeholder")) element.placeholder = options.placeholder; if (Object.hasOwn(options, "disabled")) element.disabled = options.disabled; if (Object.hasOwn(options, "iconOnly")) element.iconOnly = options.iconOnly; if (Object.hasOwn(options, "ariaLabel")) element.setAttribute("aria-label", String(options.ariaLabel)); for (const item of options.options ?? []) { const option = document.createElement("option"); if (typeof item === "string") { option.setAttribute("value", item); option.textContent = item; } else { option.setAttribute("value", String(item.value)); option.textContent = String(item.label ?? item.value); if (item.icon) option.setAttribute("icon", String(item.icon)); if (item.disabled) option.setAttribute("disabled", ""); } element.append(option); } if (Object.hasOwn(options, "value")) element.value = options.value; else element._syncOptions(); return element; } function createLoadingIndicator(options = {}) { if (!globalThis.document) throw new Error("Biscuit LoadingIndicator requires a browser document"); defineLoadingIndicator(); const element = createConfiguredElement(LOADINGINDICATOR_TAG_NAME, options); if (Object.hasOwn(options, "label")) element.label = options.label; if (Object.hasOwn(options, "size")) element.size = options.size; if (Object.hasOwn(options, "theme")) element.theme = options.theme; return element; } function createPageLoaderView(options = {}) { if (!globalThis.document) throw new Error("Biscuit PageLoaderView requires a browser document"); definePageLoaderView(); const element = createConfiguredElement(PAGELOADERVIEW_TAG_NAME, options); if (Object.hasOwn(options, "message")) element.message = options.message; if (Object.hasOwn(options, "mode")) element.mode = options.mode; if (Object.hasOwn(options, "indicatorOnly")) element.indicatorOnly = options.indicatorOnly; if (Object.hasOwn(options, "theme")) element.theme = options.theme; if (options.content != null) element.append(options.content); if (Object.hasOwn(options, "open")) element.open = options.open; return element; } function createBadgeView(options = {}) { if (!globalThis.document) throw new Error("Biscuit BadgeView requires a browser document"); defineBadgeView(); const element = createConfiguredElement(BADGEVIEW_TAG_NAME, options); for (const name of [ "label", "count", "max", "dot", "variant", "size", "theme" ]) if (Object.hasOwn(options, name)) element[name] = options[name]; if (options.content != null) element.append(options.content); return element; } function createButtonView(options = {}) { if (!globalThis.document) throw new Error("Biscuit ButtonView requires a browser document"); defineButtonView(); const element = createConfiguredElement(BUTTONVIEW_TAG_NAME, options); if (Object.hasOwn(options, "label")) element.textContent = String(options.label ?? ""); if (Object.hasOwn(options, "variant")) element.variant = options.variant; if (Object.hasOwn(options, "theme")) element.theme = options.theme; if (Object.hasOwn(options, "disabled")) element.disabled = options.disabled; if (Object.hasOwn(options, "loading")) element.loading = options.loading; if (Object.hasOwn(options, "loadingLabel")) element.loadingLabel = options.loadingLabel; if (Object.hasOwn(options, "ariaLabel")) element.setAttribute("aria-label", String(options.ariaLabel)); if (Object.hasOwn(options, "action")) element.action = options.action; return element; } function defineCore() { defineTextView(); defineCardView(); defineDropdownView(); defineLoadingIndicator(); definePageLoaderView(); defineBadgeView(); defineButtonView(); defineCalendarView(); defineDatePickerView(); } // src/groups/layout.js var layout_exports = /* @__PURE__ */ __exportAll({ BiscuitFooterView: () => BiscuitFooterView, BiscuitNavBarView: () => BiscuitNavBarView, BiscuitSidebarView: () => BiscuitSidebarView, BiscuitSplitView: () => BiscuitSplitView, BiscuitTabLayout: () => BiscuitTabLayout, createFooterView: () => createFooterView, createNavBarView: () => createNavBarView, createSidebarView: () => createSidebarView, createSplitView: () => createSplitView, createTabLayout: () => createTabLayout, defineFooterView: () => defineFooterView, defineLayout: () => defineLayout, defineNavBarView: () => defineNavBarView, defineSidebarView: () => defineSidebarView, defineSplitView: () => defineSplitView, defineTabLayout: () => defineTabLayout }); var TABLAYOUT_TAG_NAME = "biscuit-tablayout"; var SPLITVIEW_TAG_NAME = "biscuit-splitview"; var NAVBARVIEW_TAG_NAME = "biscuit-navbarview"; var FOOTERVIEW_TAG_NAME = "biscuit-footerview"; var SIDEBARVIEW_TAG_NAME = "biscuit-sidebarview"; var tabLayoutId = 0; var sidebarViewId = 0; var splitViewId = 0; var navBarViewId = 0; var footerViewId = 0; var tabLayoutStyles = ` :host { box-sizing: border-box; display: block; min-width: 0; color-scheme: inherit; border: var(--biscuit-tablayout-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a)))); border-radius: var(--biscuit-tablayout-radius, 0.75rem); background: var(--biscuit-tablayout-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); color: var(--biscuit-tablayout-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); font: var(--biscuit-tablayout-font, inherit); } ${themeStyles} [hidden] { display: none !important; } [part="layout"] { min-width: 0; } [part="tablist"] { display: flex; gap: 0.25rem; min-width: 0; overflow-x: auto; padding: 0.5rem 0.625rem 0; border-bottom: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); } [part="tab"] { flex: none; position: relative; min-height: 2.5rem; padding: var(--biscuit-tablayout-tab-padding, calc(0.5rem * var(--biscuit-space-scale, 1)) calc(0.875rem * var(--biscuit-space-scale, 1))); border: 0; border-radius: var(--biscuit-tablayout-tab-radius, 0.4rem 0.4rem 0 0); background: transparent; color: inherit; font: inherit; font-weight: 550; white-space: nowrap; cursor: pointer; } [part="tab"]:hover:not(:disabled) { background: var(--biscuit-tablayout-hover-background, light-dark(#f2f0ff, #373947)); } [part="tab"]:focus-visible { outline: 2px solid var(--biscuit-tablayout-focus-color, var(--biscuit-focus-color, var(--biscuit-theme-focus-color, light-dark(#6b63db, #aaa2ff)))); outline-offset: -2px; } [part="tab"][aria-selected="true"] { color: var(--biscuit-tablayout-active-color, var(--biscuit-focus-color, var(--biscuit-theme-focus-color, light-dark(#5e55bc, #c5bfff)))); } [part="tab"][aria-selected="true"]::after { content: ""; position: absolute; right: 0.5rem; bottom: 0; left: 0.5rem; height: 2px; border-radius: 2px; background: currentColor; } [part="tab"]:disabled { opacity: 0.45; cursor: not-allowed; } [part="tabpanel"] { min-width: 0; min-height: var(--biscuit-tablayout-panel-min-height, 6rem); padding: var(--biscuit-tablayout-panel-padding, calc(1.25rem * var(--biscuit-space-scale, 1))); } ::slotted(biscuit-tab) { display: block; } :host([orientation="vertical"]) [part="layout"] { display: grid; grid-template-columns: max-content minmax(0, 1fr); } :host([orientation="vertical"]) [part="tablist"] { flex-direction: column; align-items: stretch; overflow-x: visible; padding: 0.625rem 0 0.625rem 0.625rem; border-right: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); border-bottom: 0; } :host([orientation="vertical"]) [part="tab"] { width: 100%; border-radius: var(--biscuit-tablayout-tab-radius, 0.4rem 0 0 0.4rem); text-align: left; } :host([orientation="vertical"]) [part="tab"][aria-selected="true"]::after { top: 0.5rem; right: 0; bottom: 0.5rem; left: auto; width: 2px; height: auto; } :host([variant="pills"]) [part="tablist"] { gap: 0.375rem; padding-bottom: 0.5rem; border: 0; } :host([variant="pills"]) [part="tab"] { border-radius: var(--biscuit-tablayout-tab-radius, 0.5rem); } :host([variant="pills"]) [part="tab"][aria-selected="true"] { background: var(--biscuit-tablayout-active-background, var(--biscuit-theme-option-background, light-dark(#efedff, #45415f))); color: var(--biscuit-tablayout-active-color, var(--biscuit-theme-option-color, light-dark(#38306e, #fff))); } :host([variant="pills"]) [part="tab"][aria-selected="true"]::after { content: none; } :host([orientation="vertical"][variant="pills"]) [part="tablist"] { padding-right: 0.625rem; } @media (max-width: 420px) { :host([orientation="vertical"]) [part="layout"] { grid-template-columns: minmax(0, 1fr); } :host([orientation="vertical"]) [part="tablist"] { flex-direction: row; overflow-x: auto; padding: 0.5rem 0.625rem; border-right: 0; border-bottom: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); } :host([orientation="vertical"]) [part="tab"] { width: auto; text-align: center; } } `; var splitViewStyles = ` :host { box-sizing: border-box; display: block; width: 100%; height: var(--biscuit-splitview-height, 14rem); min-width: 0; min-height: 0; overflow: hidden; color-scheme: inherit; border: var(--biscuit-splitview-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a)))); border-radius: var(--biscuit-splitview-radius, 0.75rem); background: var(--biscuit-splitview-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); color: var(--biscuit-splitview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); font: var(--biscuit-splitview-font, 400 0.875rem/1.45 system-ui, sans-serif); } ${themeStyles} [part="layout"] { display: grid; width: 100%; height: 100%; min-width: 0; min-height: 0; grid-template-columns: minmax(0, var(--_split-first, 50fr)) minmax(0, var(--_split-second, 50fr)); } :host([resizable]) [part="layout"] { grid-template-columns: minmax(0, var(--_split-first, 50fr)) var(--biscuit-splitview-handle-size, 0.75rem) minmax(0, var(--_split-second, 50fr)); } :host([orientation="vertical"]) [part="layout"] { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, var(--_split-first, 50fr)) minmax(0, var(--_split-second, 50fr)); } :host([orientation="vertical"][resizable]) [part="layout"] { grid-template-rows: minmax(0, var(--_split-first, 50fr)) var(--biscuit-splitview-handle-size, 0.75rem) minmax(0, var(--_split-second, 50fr)); } [part~="pane"] { min-width: 0; min-height: 0; overflow: auto; padding: var(--biscuit-splitview-pane-padding, calc(1rem * var(--biscuit-space-scale, 1))); } [part~="first"] { border-right: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); } :host([orientation="vertical"]) [part~="first"] { border-right: 0; border-bottom: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); } :host([resizable]) [part~="first"] { border: 0; } [part="handle"] { display: none; align-items: center; justify-content: center; min-width: 0; min-height: 0; padding: 0; border: 0; background: var(--biscuit-splitview-handle-background, color-mix(in srgb, currentColor 8%, transparent)); color: inherit; touch-action: none; cursor: col-resize; } :host([resizable]) [part="handle"] { display: flex; } :host([orientation="vertical"]) [part="handle"] { cursor: row-resize; } [part="handle"]::before { content: ""; display: block; width: 2px; height: 2rem; border-radius: 2px; background: var(--biscuit-splitview-grip-color, color-mix(in srgb, currentColor 55%, transparent)); } :host([orientation="vertical"]) [part="handle"]::before { width: 2rem; height: 2px; } [part="handle"]:hover { background: var(--biscuit-splitview-handle-hover-background, color-mix(in srgb, currentColor 15%, transparent)); } [part="handle"]:focus-visible { outline: 2px solid var(--biscuit-splitview-focus-color, var(--biscuit-focus-color, var(--biscuit-theme-focus-color, light-dark(#6b63db, #aaa2ff)))); outline-offset: -2px; } ::slotted(*) { min-width: 0; } `; var navBarViewStyles = ` :host { box-sizing: border-box; display: block; min-width: 0; color-scheme: inherit; border: var(--biscuit-navbarview-border, 0); border-bottom: var(--biscuit-navbarview-bottom-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a)))); border-radius: var(--biscuit-navbarview-radius, 0); background: var(--biscuit-navbarview-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); color: var(--biscuit-navbarview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); font: var(--biscuit-navbarview-font, 550 0.875rem/1.4 system-ui, sans-serif); } ${themeStyles} :host([sticky]) { position: sticky; top: var(--biscuit-navbarview-sticky-top, 0px); z-index: var(--biscuit-navbarview-sticky-z-index, 20); } :host(:not([contained])), :host([full-width]) { width: 100%; border-right: 0; border-left: 0; border-radius: 0; } [hidden] { display: none !important; } [part="nav"] { display: flex; align-items: center; gap: calc(1rem * var(--biscuit-space-scale, 1)); min-width: 0; min-height: 3.5rem; padding: var(--biscuit-navbarview-padding, calc(0.55rem * var(--biscuit-space-scale, 1)) calc(0.75rem * var(--biscuit-space-scale, 1))); } [part="brand"] { flex: none; color: inherit; font-size: 1rem; font-weight: 750; text-decoration: none; white-space: nowrap; } [part="menu"] { display: flex; flex: 1; align-items: center; justify-content: space-between; gap: 0.75rem; min-width: 0; } [part="links"], [part="actions"] { display: flex; align-items: center; gap: 0.25rem; min-width: 0; } [part="links"] { flex-wrap: wrap; } ::slotted(a) { display: inline-flex; align-items: center; min-height: 2.25rem; padding: 0.4rem 0.65rem; border-radius: 0.45rem; color: inherit; text-decoration: none; white-space: nowrap; } ::slotted(a:hover), ::slotted(a[aria-current="page"]) { background: var(--biscuit-navbarview-active-background, var(--biscuit-theme-option-background, light-dark(#efedff, #45415f))); color: var(--biscuit-navbarview-active-color, var(--biscuit-theme-option-color, light-dark(#38306e, #fff))); } ::slotted(a[slot="actions"]) { border: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); font-weight: 650; } [part="toggle"] { flex: none; align-items: center; justify-content: center; gap: 0.4rem; min-height: 2.25rem; padding: 0.4rem 0.65rem; border: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); border-radius: 0.45rem; background: transparent; color: inherit; font: inherit; cursor: pointer; } [part="brand"]:focus-visible, [part="toggle"]:focus-visible, ::slotted(a:focus-visible) { outline: 2px solid var(--biscuit-navbarview-focus-color, var(--biscuit-focus-color, var(--biscuit-theme-focus-color, light-dark(#6b63db, #aaa2ff)))); outline-offset: 2px; } :host([data-mobile]) [part="nav"] { flex-wrap: wrap; } :host([data-mobile]) [part="brand"] { flex: 1; } :host([data-mobile]) [part="toggle"] { display: inline-flex; } :host([data-mobile]) [part="menu"] { flex: 0 0 100%; flex-direction: column; align-items: stretch; gap: 0.5rem; padding-top: 0.65rem; border-top: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); } :host([data-mobile]) [part="links"], :host([data-mobile]) [part="actions"] { flex-direction: column; align-items: stretch; } :host([data-mobile]) ::slotted(a) { width: 100%; } `; var footerViewStyles = ` :host { box-sizing: border-box; display: block; width: 100%; color-scheme: inherit; border: var(--biscuit-footerview-border, 0); border-top: var(--biscuit-footerview-top-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a)))); border-radius: var(--biscuit-footerview-radius, 0); background: var(--biscuit-footerview-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); color: var(--biscuit-footerview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); font: var(--biscuit-footerview-font, 400 0.9375rem/1.5 system-ui, sans-serif); } ${themeStyles} :host([contained]:not([full-width])) { border: var(--biscuit-footerview-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a)))); border-radius: var(--biscuit-footerview-radius, .75rem); } [hidden] { display: none !important; } [part="footer"] { box-sizing: border-box; width: 100%; } [part="inner"] { box-sizing: border-box; max-width: var(--biscuit-footerview-max-width, 80rem); margin-inline: auto; padding: var(--biscuit-footerview-padding, calc(2.5rem * var(--biscuit-space-scale, 1)) calc(1.25rem * var(--biscuit-space-scale, 1))); } [part="main"] { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 2fr); gap: calc(2rem * var(--biscuit-space-scale, 1)); } :host(:not([data-has-groups])) [part="main"] { grid-template-columns: minmax(0, 1fr); } [part="intro"] { display: grid; align-content: start; gap: calc(.75rem * var(--biscuit-space-scale, 1)); min-width: 0; } [part="brand"] { font-size: 1.1rem; font-weight: 750; } [part="brand"] a { color: inherit; text-decoration: none; } [part="description"] { max-width: 38ch; color: var(--biscuit-footerview-muted-color, color-mix(in srgb, currentColor 72%, transparent)); } [part="description"] p { margin: 0; } [part="actions"] { display: flex; flex-wrap: wrap; align-items: center; gap: calc(.6rem * var(--biscuit-space-scale, 1)); } slot[name="actions"]::slotted(a) { display: inline-flex; align-items: center; min-height: 2.25rem; padding: .4rem .7rem; border: 1px solid currentColor; border-radius: .45rem; color: inherit; font-weight: 650; text-decoration: none; } slot[name="actions"]::slotted(a:hover) { background: color-mix(in srgb, currentColor 10%, transparent); } slot[name="actions"]::slotted(a:focus-visible) { outline: 2px solid var(--biscuit-footerview-focus-color, var(--biscuit-focus-color, var(--biscuit-theme-focus-color, light-dark(#6b63db, #aaa2ff)))); outline-offset: 3px; } [part="groups"] { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); gap: calc(1.5rem * var(--biscuit-space-scale, 1)); min-width: 0; } [part="group"] { min-width: 0; } [part="group-heading"] { display: block; margin: 0 0 calc(.55rem * var(--biscuit-space-scale, 1)); font: inherit; font-weight: 700; } [part="group-links"] { display: grid; justify-items: start; gap: calc(.3rem * var(--biscuit-space-scale, 1)); } [part="group-links"]::slotted(a) { color: inherit; text-decoration: none; border-radius: .25rem; } [part="group-links"]::slotted(a:hover) { text-decoration: underline; } [part="group-links"]::slotted(a:focus-visible), [part="brand"] a:focus-visible { outline: 2px solid var(--biscuit-footerview-focus-color, var(--biscuit-focus-color, var(--biscuit-theme-focus-color, light-dark(#6b63db, #aaa2ff)))); outline-offset: 3px; } [part="bottom"] { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: calc(.75rem * var(--biscuit-space-scale, 1)); margin-top: calc(2rem * var(--biscuit-space-scale, 1)); padding-top: calc(1rem * var(--biscuit-space-scale, 1)); border-top: 1px solid var(--biscuit-footerview-divider-color, var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a)))); font-size: .875rem; color: var(--biscuit-footerview-muted-color, color-mix(in srgb, currentColor 72%, transparent)); } @media (max-width: 640px) { [part="main"] { grid-template-columns: minmax(0, 1fr); } [part="groups"] { grid-template-columns: repeat(2, minmax(0, 1fr)); } } @media (max-width: 420px) { [part="groups"] { grid-template-columns: minmax(0, 1fr); } } `; var sidebarViewStyles = ` :host { box-sizing: border-box; display: block; width: var(--biscuit-sidebarview-width, 16rem); max-width: 100%; min-width: 0; color-scheme: inherit; font: var(--biscuit-sidebarview-font, 400 0.9375rem/1.45 system-ui, sans-serif); } ${themeStyles} :host([sticky]:not([data-mobile])) { position: sticky; top: var(--biscuit-sidebarview-sticky-top, 0px); align-self: start; } :host([sticky]:not([data-mobile])) [part="panel"] { height: calc(100dvh - var(--biscuit-sidebarview-sticky-top, 0px)); overflow-y: auto; scrollbar-width: thin; } [hidden] { display: none !important; } [part="toggle"] { align-items: center; gap: 0.55rem; min-height: 2.75rem; padding: 0.55rem 0.8rem; border: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); border-radius: 0.5rem; background: var(--biscuit-sidebarview-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); color: var(--biscuit-sidebarview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); font: inherit; font-weight: 650; cursor: pointer; } [part="toggle"]:focus-visible, [part="close"]:focus-visible, [part="link"]:focus-visible, [part="category-link"]:focus-visible, ::slotted(a:focus-visible) { outline: 2px solid var(--biscuit-sidebarview-focus-color, var(--biscuit-focus-color, var(--biscuit-theme-focus-color, light-dark(#6b63db, #aaa2ff)))); outline-offset: 2px; } [part="toggle-icon"] { font-size: 1.2em; line-height: 1; } [part="backdrop"] { position: fixed; inset: 0; z-index: 1000; background: var(--biscuit-sidebarview-backdrop, rgb(0 0 0 / 55%)); } [part="panel"] { box-sizing: border-box; width: 100%; min-height: 12rem; padding: var(--biscuit-sidebarview-padding, calc(0.9rem * var(--biscuit-space-scale, 1))); border: var(--biscuit-sidebarview-border, 0); border-right: var(--biscuit-sidebarview-divider, 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a)))); border-radius: var(--biscuit-sidebarview-radius, 0); background: var(--biscuit-sidebarview-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); box-shadow: var(--biscuit-sidebarview-shadow, none); color: var(--biscuit-sidebarview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); } [part="header"] { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.75rem; padding: 0.2rem 0.35rem 0.8rem; border-bottom: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); } [part="title"] { font-size: 1rem; font-weight: 750; } [part="close"] { width: 2rem; height: 2rem; border: 0; border-radius: 0.4rem; background: transparent; color: inherit; font: inherit; font-size: 1.25rem; cursor: pointer; } [part="close"]:hover { background: var(--biscuit-sidebarview-hover-background, light-dark(#f2f0ff, #373947)); } [part="body"], [part="items"] { display: grid; gap: 0.25rem; } [part="category"] { display: grid; gap: 0.15rem; margin-top: 0.55rem; } [part="category"]:first-child { margin-top: 0; } [part="category-items"] { display: grid; gap: 0.15rem; margin-left: 0.55rem; padding-left: 0.55rem; border-left: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); } [part="category-label"], [part="category-link"] { display: block; padding: 0.5rem 0.65rem 0.3rem; font-size: 0.75rem; font-weight: 750; letter-spacing: 0.055em; text-transform: uppercase; color: inherit; text-decoration: none; } [part="category"][data-active] > [part="category-label"], [part="category"][data-active] > [part="category-link"]:not([aria-current]):not([data-tracked]), [part="category"][data-current] > [part="category-label"], [part="category"][data-current] > [part="category-link"]:not([aria-current]):not([data-tracked]) { color: var(--biscuit-sidebarview-category-active-color, inherit); } [part="link"] { display: block; padding: calc(0.48rem * var(--biscuit-space-scale, 1)) calc(0.65rem * var(--biscuit-space-scale, 1)); border-radius: 0.45rem; color: inherit; text-decoration: none; } ::slotted(a) { display: block; padding: 0.55rem 0.75rem; border-radius: 0.45rem; color: inherit; text-decoration: none; } ::slotted(a:hover), ::slotted(a[aria-current="page"]), ::slotted(a[aria-current="location"]), ::slotted(a[data-tracked]), [part="link"]:hover, [part="link"][aria-current], [part="link"][data-tracked], [part="category-link"][aria-current], [part="category-link"][data-tracked] { background: var(--biscuit-sidebarview-active-background, var(--biscuit-theme-option-background, light-dark(#efedff, #45415f))); color: var(--biscuit-sidebarview-active-color, var(--biscuit-theme-option-color, light-dark(#38306e, #fff))); } :host([track-scroll-behavior="smooth"]) ::slotted(a), :host([track-scroll-behavior="smooth"]) [part="link"], :host([track-scroll-behavior="smooth"]) [part="category-link"] { transition: background-color var(--biscuit-sidebarview-selection-fade-duration, 110ms) ease-out, color var(--biscuit-sidebarview-selection-fade-duration, 110ms) ease-out; } :host([track-scroll-behavior="smooth"]) ::slotted(a[data-tracked]), :host([track-scroll-behavior="smooth"]) [part="link"][data-tracked], :host([track-scroll-behavior="smooth"]) [part="category-link"][data-tracked] { transition-duration: 0ms; } :host([data-mobile]) { width: auto; } :host([data-mobile]) [part="toggle"] { display: inline-flex; } :host([data-mobile]) [part="panel"] { position: fixed; z-index: 1001; top: 0; bottom: 0; left: 0; width: min(var(--biscuit-sidebarview-mobile-width, 18rem), calc(100vw - 3rem)); min-height: 0; overflow-y: auto; overscroll-behavior: contain; border-radius: 0 var(--biscuit-sidebarview-radius, 0) var(--biscuit-sidebarview-radius, 0) 0; box-shadow: var(--biscuit-sidebarview-mobile-shadow, 0 12px 32px rgb(0 0 0 / 25%)); visibility: hidden; transform: translateX(-100%); transition: transform 180ms ease, visibility 180ms ease; } :host([data-mobile][open]) [part="panel"] { visibility: visible; transform: none; } :host([data-mobile][side="right"]) [part="panel"] { right: 0; left: auto; border-radius: var(--biscuit-sidebarview-radius, 0) 0 0 var(--biscuit-sidebarview-radius, 0); transform: translateX(100%); } :host([data-mobile][side="right"][open]) [part="panel"] { transform: none; } @media (prefers-reduced-motion: reduce) { :host([data-mobile]) [part="panel"] { transition: none; } :host([track-scroll-behavior="smooth"]) ::slotted(a), :host([track-scroll-behavior="smooth"]) [part="link"], :host([track-scroll-behavior="smooth"]) [part="category-link"] { transition: none; } } `; var BiscuitSplitView = class extends HTMLElementBase { static get observedAttributes() { return [ "orientation", "resizable", "value", "min", "max", "left-min", "left-max", "right-min", "right-max", "top-min", "top-max", "bottom-min", "bottom-max", "aria-label" ]; } constructor() { super(); this._dragging = null; const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = splitViewStyles; this._layout = document.createElement("div"); this._layout.setAttribute("part", "layout"); this._firstPane = document.createElement("div"); this._firstPane.setAttribute("part", "pane first"); this._firstPane.id = "biscuit-split-first-" + ++splitViewId; const firstSlot = document.createElement("slot"); firstSlot.name = "first"; this._firstPane.append(firstSlot); this._handle = document.createElement("div"); this._handle.setAttribute("part", "handle"); this._handle.setAttribute("role", "separator"); this._handle.setAttribute("aria-controls", this._firstPane.id); this._handle.addEventListener("keydown", (event) => this._onKeyDown(event)); this._handle.addEventListener("pointerdown", (event) => this._onPointerDown(event)); this._handle.addEventListener("pointermove", (event) => this._onPointerMove(event)); this._handle.addEventListener("pointerup", (event) => this._onPointerUp(event)); this._handle.addEventListener("pointercancel", (event) => this._onPointerCancel(event)); this._handle.addEventListener("lostpointercapture", () => this._finishDrag()); this._secondPane = document.createElement("div"); this._secondPane.setAttribute("part", "pane second"); const secondSlot = document.createElement("slot"); secondSlot.name = "second"; this._secondPane.append(secondSlot); this._layout.append(this._firstPane, this._handle, this._secondPane); root.append(style, this._layout); this._syncState(); } disconnectedCallback() { this._dragging = null; } attributeChangedCallback(name, oldValue, newValue) { if (oldValue !== newValue) this._syncState(); } get orientation() { return this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal"; } set orientation(value) { if (value === "vertical") this.setAttribute("orientation", "vertical"); else if (value === "horizontal") this.removeAttribute("orientation"); else throw new TypeError("SplitView orientation must be \"horizontal\" or \"vertical\""); } get resizable() { return this.hasAttribute("resizable"); } set resizable(value) { this.toggleAttribute("resizable", Boolean(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } _bound(name, fallback) { const raw = this.getAttribute(name); const number = raw == null ? fallback : Number(raw); return Number.isFinite(number) ? Math.max(0, Math.min(100, number)) : fallback; } get min() { return this._bound("min", 10); } set min(value) { this.setAttribute("min", String(value)); } get max() { return Math.max(this.min, this._bound("max", 90)); } set max(value) { this.setAttribute("max", String(value)); } get leftMin() { return this._bound("left-min", this.min); } set leftMin(value) { this.setAttribute("left-min", String(value)); } get leftMax() { return Math.max(this.leftMin, this._bound("left-max", this.max)); } set leftMax(value) { this.setAttribute("left-max", String(value)); } get rightMin() { return this._bound("right-min", this.min); } set rightMin(value) { this.setAttribute("right-min", String(value)); } get rightMax() { return Math.max(this.rightMin, this._bound("right-max", this.max)); } set rightMax(value) { this.setAttribute("right-max", String(value)); } get topMin() { return this._bound("top-min", this.min); } set topMin(value) { this.setAttribute("top-min", String(value)); } get topMax() { return Math.max(this.topMin, this._bound("top-max", this.max)); } set topMax(value) { this.setAttribute("top-max", String(value)); } get bottomMin() { return this._bound("bottom-min", this.min); } set bottomMin(value) { this.setAttribute("bottom-min", String(value)); } get bottomMax() { return Math.max(this.bottomMin, this._bound("bottom-max", this.max)); } set bottomMax(value) { this.setAttribute("bottom-max", String(value)); } get _effectiveBounds() { const firstMin = this.orientation === "horizontal" ? this.leftMin : this.topMin; const firstMax = this.orientation === "horizontal" ? this.leftMax : this.topMax; const secondMin = this.orientation === "horizontal" ? this.rightMin : this.bottomMin; const secondMax = this.orientation === "horizontal" ? this.rightMax : this.bottomMax; const min = Math.max(firstMin, 100 - secondMax); return { min, max: Math.max(min, Math.min(firstMax, 100 - secondMin)) }; } get value() { const raw = this.getAttribute("value"); const number = raw == null ? 50 : Number(raw); const { min, max } = this._effectiveBounds; return Math.max(min, Math.min(max, Number.isFinite(number) ? number : 50)); } set value(value) { const number = Number(value); if (!Number.isFinite(number)) throw new TypeError("SplitView value must be a finite percentage"); const { min, max } = this._effectiveBounds; this.setAttribute("value", String(Math.max(min, Math.min(max, number)))); } _syncState() { if (!this._layout) return; this._layout.style.setProperty("--_split-first", this.value + "fr"); this._layout.style.setProperty("--_split-second", 100 - this.value + "fr"); this._handle.hidden = !this.resizable; this._handle.tabIndex = this.resizable ? 0 : -1; this._handle.setAttribute("aria-label", this.getAttribute("aria-label") || "Resize panels"); this._handle.setAttribute("aria-orientation", this.orientation === "horizontal" ? "vertical" : "horizontal"); this._handle.setAttribute("aria-valuemin", String(this._effectiveBounds.min)); this._handle.setAttribute("aria-valuemax", String(this._effectiveBounds.max)); this._handle.setAttribute("aria-valuenow", String(this.value)); } _setUserValue(next) { const before = this.value; this.value = next; if (this.value === before) return; this.dispatchEvent(new Event("input", { bubbles: true, composed: true })); } _onKeyDown(event) { if (!this.resizable) return; const step = event.shiftKey ? 10 : 5; let next; if (event.key === "Home") next = this._effectiveBounds.min; else if (event.key === "End") next = this._effectiveBounds.max; else if (this.orientation === "horizontal" && event.key === "ArrowLeft") next = this.value - step; else if (this.orientation === "horizontal" && event.key === "ArrowRight") next = this.value + step; else if (this.orientation === "vertical" && event.key === "ArrowUp") next = this.value - step; else if (this.orientation === "vertical" && event.key === "ArrowDown") next = this.value + step; else return; event.preventDefault(); const before = this.value; this._setUserValue(next); if (this.value !== before) this.dispatchEvent(new Event("change", { bubbles: true, composed: true })); } _onPointerDown(event) { if (!this.resizable || event.button != null && event.button !== 0) return; event.preventDefault(); this._dragging = { pointerId: event.pointerId, startValue: this.value }; this._handle.focus(); this._handle.setPointerCapture?.(event.pointerId); } _onPointerMove(event) { if (!this._dragging || event.pointerId !== this._dragging.pointerId) return; const rect = this.getBoundingClientRect(); const handleRect = this._handle.getBoundingClientRect(); const horizontal = this.orientation === "horizontal"; const handleSize = horizontal ? handleRect.width : handleRect.height; const length = (horizontal ? rect.width : rect.height) - handleSize; if (length <= 0) return; const position = (horizontal ? event.clientX - rect.left : event.clientY - rect.top) - handleSize / 2; this._setUserValue(Math.round(position / length * 1e3) / 10); } _onPointerUp(event) { if (!this._dragging || event.pointerId !== this._dragging.pointerId) return; this._finishDrag(); this._handle.releasePointerCapture?.(event.pointerId); } _onPointerCancel(event) { if (!this._dragging || event.pointerId !== this._dragging.pointerId) return; this._dragging = null; this._handle.releasePointerCapture?.(event.pointerId); } _finishDrag() { if (!this._dragging) return; const changed = this.value !== this._dragging.startValue; this._dragging = null; if (changed) this.dispatchEvent(new Event("change", { bubbles: true, composed: true })); } }; var BiscuitTabLayout = class extends HTMLElementBase { static get observedAttributes() { return ["value", "aria-label"]; } constructor() { super(); this._id = ++tabLayoutId; this._tabs = []; this._buttons = []; this._panels = []; this._value = ""; const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = tabLayoutStyles; const layout = document.createElement("div"); layout.setAttribute("part", "layout"); this._tablist = document.createElement("div"); this._tablist.setAttribute("part", "tablist"); this._tablist.setAttribute("role", "tablist"); this._panelsContainer = document.createElement("div"); this._panelsContainer.setAttribute("part", "panels"); layout.append(this._tablist, this._panelsContainer); root.append(style, layout); this._syncLabel(); } connectedCallback() { this._syncTabs(); if (globalThis.MutationObserver) { this._observer = new MutationObserver((mutations) => { if (mutations.some((mutation) => mutation.type === "childList" && mutation.target === this || mutation.type === "attributes" && mutation.target.parentElement === this)) this._syncTabs(); }); this._observer.observe(this, { childList: true, subtree: true, attributes: true, attributeFilter: [ "value", "label", "disabled", "selected" ] }); } } disconnectedCallback() { this._observer?.disconnect(); this._observer = null; } attributeChangedCallback(name, oldValue, newValue) { if (oldValue === newValue) return; if (name === "value") this._applySelection(); else if (name === "aria-label") this._syncLabel(); } get value() { return this._value; } set value(value) { this.setAttribute("value", String(value ?? "")); } get orientation() { return this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal"; } set orientation(value) { if (value === "vertical") this.setAttribute("orientation", "vertical"); else this.removeAttribute("orientation"); } get variant() { return this.getAttribute("variant") === "pills" ? "pills" : "underline"; } set variant(value) { if (value === "pills") this.setAttribute("variant", "pills"); else this.removeAttribute("variant"); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } _syncLabel() { const label = this.getAttribute("aria-label"); if (label) this._tablist.setAttribute("aria-label", label); else this._tablist.removeAttribute("aria-label"); } _syncTabs() { this._tabs = Array.from(this.children).filter((child) => child.tagName === "BISCUIT-TAB").map((child, index) => ({ element: child, value: child.getAttribute("value") ?? `tab-${index + 1}`, label: child.getAttribute("label") ?? `Tab ${index + 1}`, disabled: child.hasAttribute("disabled"), selected: child.hasAttribute("selected") })); this._buttons = this._tabs.map((tab, index) => { tab.element.setAttribute("slot", `biscuit-tab-${this._id}-${index}`); const button = document.createElement("button"); button.type = "button"; button.setAttribute("part", "tab"); button.setAttribute("role", "tab"); button.id = `biscuit-tab-${this._id}-${index}`; button.setAttribute("aria-controls", `biscuit-panel-${this._id}-${index}`); button.textContent = tab.label; button.disabled = tab.disabled; button.addEventListener("click", () => this._selectIndex(index)); button.addEventListener("keydown", (event) => this._onTabKeyDown(event, index)); return button; }); this._panels = this._tabs.map((tab, index) => { const panel = document.createElement("div"); panel.setAttribute("part", "tabpanel"); panel.setAttribute("role", "tabpanel"); panel.id = `biscuit-panel-${this._id}-${index}`; panel.setAttribute("aria-labelledby", `biscuit-tab-${this._id}-${index}`); panel.tabIndex = 0; const slot = document.createElement("slot"); slot.name = `biscuit-tab-${this._id}-${index}`; panel.append(slot); return panel; }); this._tablist.replaceChildren(...this._buttons); this._panelsContainer.replaceChildren(...this._panels); this._applySelection(); } _applySelection() { const requested = this.getAttribute("value"); let selectedIndex = requested === null ? this._tabs.findIndex((tab) => tab.selected && !tab.disabled) : this._tabs.findIndex((tab) => tab.value === requested && !tab.disabled); if (selectedIndex < 0) selectedIndex = this._tabs.findIndex((tab) => !tab.disabled); this._value = selectedIndex < 0 ? "" : this._tabs[selectedIndex].value; this._buttons.forEach((button, index) => { const selected = index === selectedIndex; button.setAttribute("aria-selected", String(selected)); button.tabIndex = selected || selectedIndex < 0 && index === 0 ? 0 : -1; this._panels[index].hidden = !selected; }); } _selectIndex(index) { const tab = this._tabs[index]; if (!tab || tab.disabled) return; const previous = this._value; this.value = tab.value; this._buttons[index].focus(); if (this._value !== previous) this.dispatchEvent(new Event("change", { bubbles: true, composed: true })); } _onTabKeyDown(event, index) { const horizontal = this.orientation === "horizontal"; const direction = horizontal && event.key === "ArrowRight" || !horizontal && event.key === "ArrowDown" ? 1 : horizontal && event.key === "ArrowLeft" || !horizontal && event.key === "ArrowUp" ? -1 : 0; if (!direction && event.key !== "Home" && event.key !== "End") return; event.preventDefault(); const enabled = this._tabs.flatMap((tab, tabIndex) => tab.disabled ? [] : [tabIndex]); if (!enabled.length) return; let next; if (event.key === "Home") next = enabled[0]; else if (event.key === "End") next = enabled[enabled.length - 1]; else next = enabled[(enabled.indexOf(index) + direction + enabled.length) % enabled.length]; this._selectIndex(next); } }; var BiscuitNavBarView = class extends HTMLElementBase { static get observedAttributes() { return [ "brand", "brand-href", "mode", "open", "aria-label" ]; } constructor() { super(); this._isMobile = false; this._connected = false; this._onMediaChange = () => this._syncMode(); this._onDocumentKeyDown = (event) => { if (event.key === "Escape" && this._isMobile && this.open) { event.preventDefault(); this._setOpen(false); this._toggle.focus(); } }; this._onDocumentPointerDown = (event) => { if (!event.composedPath?.().includes(this)) this._setOpen(false); }; const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = navBarViewStyles; this._nav = document.createElement("nav"); this._nav.setAttribute("part", "nav"); this._brandLink = document.createElement("a"); this._brandLink.setAttribute("part", "brand"); const brandSlot = document.createElement("slot"); brandSlot.name = "brand"; this._brandText = document.createElement("span"); brandSlot.append(this._brandText); this._brandLink.append(brandSlot); this._toggle = document.createElement("button"); this._toggle.type = "button"; this._toggle.setAttribute("part", "toggle"); const icon = document.createElement("span"); icon.setAttribute("aria-hidden", "true"); icon.textContent = "☰"; const toggleText = document.createElement("span"); toggleText.textContent = "Menu"; this._toggle.append(icon, toggleText); this._toggle.addEventListener("click", () => this._setOpen(!this.open)); this._menu = document.createElement("div"); this._menu.setAttribute("part", "menu"); this._menu.id = `biscuit-navbar-menu-${++navBarViewId}`; this._toggle.setAttribute("aria-controls", this._menu.id); this._links = document.createElement("div"); this._links.setAttribute("part", "links"); this._links.append(document.createElement("slot")); this._actions = document.createElement("div"); this._actions.setAttribute("part", "actions"); const actionsSlot = document.createElement("slot"); actionsSlot.name = "actions"; actionsSlot.addEventListener("slotchange", () => this._syncActions()); this._actions.append(actionsSlot); this._menu.append(this._links, this._actions); this._menu.addEventListener("click", (event) => { if (!this._isMobile) return; if (event.composedPath?.().some((node) => node.tagName === "A" && node.hasAttribute("href"))) this._setOpen(false); }); this._nav.append(this._brandLink, this._toggle, this._menu); root.append(style, this._nav); this._renderState(); } connectedCallback() { this._connected = true; this._media = globalThis.matchMedia?.("(max-width: 720px)"); this._media?.addEventListener?.("change", this._onMediaChange); this._syncActions(); this._syncMode(); } disconnectedCallback() { this._connected = false; this._media?.removeEventListener?.("change", this._onMediaChange); this._media = null; document.removeEventListener("keydown", this._onDocumentKeyDown); document.removeEventListener("pointerdown", this._onDocumentPointerDown); } attributeChangedCallback(name, oldValue, newValue) { if (oldValue === newValue || !this._nav) return; if (name === "mode") this._syncMode(); else this._renderState(); } get brand() { return this.getAttribute("brand") ?? "Biscuit"; } set brand(value) { if (value == null) this.removeAttribute("brand"); else this.setAttribute("brand", String(value)); } get brandHref() { return this.getAttribute("brand-href") ?? "#"; } set brandHref(value) { if (value == null) this.removeAttribute("brand-href"); else this.setAttribute("brand-href", String(value)); } get mode() { return this.getAttribute("mode") ?? "auto"; } set mode(value) { if (value == null || value === "auto") this.removeAttribute("mode"); else if (value === "mobile" || value === "desktop") this.setAttribute("mode", value); else throw new TypeError("NavBarView mode must be \"auto\", \"mobile\", or \"desktop\""); } get open() { return this.hasAttribute("open"); } set open(value) { this.toggleAttribute("open", Boolean(value)); } get sticky() { return this.hasAttribute("sticky"); } set sticky(value) { this.toggleAttribute("sticky", Boolean(value)); } get fullWidth() { return !this.hasAttribute("contained") || this.hasAttribute("full-width"); } set fullWidth(value) { this.toggleAttribute("contained", !Boolean(value)); this.toggleAttribute("full-width", Boolean(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } toggle() { this._setOpen(!this.open); } _syncActions() { this._actions.hidden = !Array.from(this.children ?? []).some((child) => child.getAttribute?.("slot") === "actions"); } _syncMode() { this._isMobile = this.mode === "mobile" || this.mode !== "desktop" && Boolean(this._media?.matches); this.toggleAttribute("data-mobile", this._isMobile); if (!this._isMobile && this.open) this.open = false; this._renderState(); } _setOpen(open) { if (!this._isMobile || this.open === open) return; this.open = open; this.dispatchEvent(new Event("change", { bubbles: true, composed: true })); } _renderState() { const label = this.getAttribute("aria-label") || "Primary navigation"; this._nav.setAttribute("aria-label", label); this._brandText.textContent = this.brand; this._brandLink.setAttribute("href", this.brandHref); this._toggle.hidden = !this._isMobile; this._toggle.setAttribute("aria-label", `${this.open ? "Close" : "Open"} ${label} menu`); this._toggle.setAttribute("aria-expanded", String(this._isMobile && this.open)); this._menu.hidden = this._isMobile && !this.open; this._menu.inert = this._isMobile && !this.open; document.removeEventListener("keydown", this._onDocumentKeyDown); document.removeEventListener("pointerdown", this._onDocumentPointerDown); if (this._connected && this._isMobile && this.open) { document.addEventListener("keydown", this._onDocumentKeyDown); document.addEventListener("pointerdown", this._onDocumentPointerDown); } } }; var BiscuitFooterView = class extends HTMLElementBase { static get observedAttributes() { return [ "brand", "brand-href", "description", "copyright", "aria-label" ]; } constructor() { super(); this._id = ++footerViewId; this._groupData = []; this._generatedLinks = []; const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = footerViewStyles; this._footer = document.createElement("footer"); this._footer.setAttribute("part", "footer"); const inner = document.createElement("div"); inner.setAttribute("part", "inner"); const main = document.createElement("div"); main.setAttribute("part", "main"); const intro = document.createElement("div"); intro.setAttribute("part", "intro"); this._brandWrap = document.createElement("div"); this._brandWrap.setAttribute("part", "brand"); const brandSlot = document.createElement("slot"); brandSlot.name = "brand"; this._brandLink = document.createElement("a"); this._brandText = document.createElement("strong"); brandSlot.append(this._brandLink, this._brandText); this._brandWrap.append(brandSlot); this._descriptionWrap = document.createElement("div"); this._descriptionWrap.setAttribute("part", "description"); const descriptionSlot = document.createElement("slot"); descriptionSlot.name = "description"; this._descriptionText = document.createElement("p"); descriptionSlot.append(this._descriptionText); this._descriptionWrap.append(descriptionSlot); this._actionsWrap = document.createElement("div"); this._actionsWrap.setAttribute("part", "actions"); const actionsSlot = document.createElement("slot"); actionsSlot.name = "actions"; this._actionsWrap.append(actionsSlot); intro.append(this._brandWrap, this._descriptionWrap, this._actionsWrap); this._groupsWrap = document.createElement("div"); this._groupsWrap.setAttribute("part", "groups"); main.append(intro, this._groupsWrap); this._bottomWrap = document.createElement("div"); this._bottomWrap.setAttribute("part", "bottom"); const bottomSlot = document.createElement("slot"); bottomSlot.name = "bottom"; this._copyrightText = document.createElement("span"); bottomSlot.append(this._copyrightText); this._bottomWrap.append(bottomSlot); inner.append(main, this._bottomWrap); this._footer.append(inner); root.append(style, this._footer); this._syncContent(); } connectedCallback() { this._syncGroups(); this._syncContent(); if (globalThis.MutationObserver) { this._observer = new MutationObserver(() => { this._syncGroups(); this._syncContent(); }); this._observer.observe(this, { childList: true, attributes: true, attributeFilter: ["data-footer-group", "slot"] }); } } disconnectedCallback() { this._observer?.disconnect(); this._observer = null; } attributeChangedCallback() { if (this._footer) this._syncContent(); } get brand() { return this.getAttribute("brand") ?? ""; } set brand(value) { if (value == null) this.removeAttribute("brand"); else this.setAttribute("brand", String(value)); } get brandHref() { return this.getAttribute("brand-href") ?? ""; } set brandHref(value) { if (value == null || value === "") this.removeAttribute("brand-href"); else this.setAttribute("brand-href", String(value)); } get description() { return this.getAttribute("description") ?? ""; } set description(value) { if (value == null) this.removeAttribute("description"); else this.setAttribute("description", String(value)); } get copyright() { return this.getAttribute("copyright") ?? ""; } set copyright(value) { if (value == null) this.removeAttribute("copyright"); else this.setAttribute("copyright", String(value)); } get fullWidth() { return !this.hasAttribute("contained") || this.hasAttribute("full-width"); } set fullWidth(value) { this.toggleAttribute("contained", !Boolean(value)); this.toggleAttribute("full-width", Boolean(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } get groups() { return this._groupData.map((group) => ({ ...group, links: group.links.map((link) => ({ ...link })) })); } set groups(value) { if (!Array.isArray(value)) throw new TypeError("FooterView groups must be an array"); const groups = value.map((group) => { if (!Array.isArray(group?.links)) throw new TypeError("Each FooterView group needs a links array"); return { label: String(group.label ?? "Links"), links: group.links.map((link) => ({ label: String(link.label ?? ""), href: String(link.href ?? "#"), target: link.target, rel: link.rel })) }; }); for (const link of this._generatedLinks) link.remove(); this._generatedLinks = []; this._groupData = groups; for (const group of groups) for (const item of group.links) { const link = document.createElement("a"); link.href = item.href; link.textContent = item.label; link.setAttribute("data-footer-group", group.label); if (item.target) link.target = String(item.target); if (item.rel) link.rel = String(item.rel); this.append(link); this._generatedLinks.push(link); } this._syncGroups(); } _syncContent() { const slotted = (name) => Array.from(this.children ?? []).some((child) => child.getAttribute?.("slot") === name); const brand = this.brand; const brandHref = this.brandHref; this._brandLink.textContent = brand; this._brandText.textContent = brand; this._brandLink.hidden = !brandHref; this._brandText.hidden = Boolean(brandHref); if (brandHref) this._brandLink.setAttribute("href", brandHref); else this._brandLink.removeAttribute("href"); this._descriptionText.textContent = this.description; this._copyrightText.textContent = this.copyright; this._brandWrap.hidden = !brand && !slotted("brand"); this._descriptionWrap.hidden = !this.description && !slotted("description"); this._actionsWrap.hidden = !slotted("actions"); this._bottomWrap.hidden = !this.copyright && !slotted("bottom"); if (this.hasAttribute("aria-label")) this._footer.setAttribute("aria-label", this.getAttribute("aria-label")); else this._footer.removeAttribute("aria-label"); } _syncGroups() { const links = Array.from(this.children ?? []).filter((child) => child.tagName === "A" && (!child.hasAttribute("slot") || child.getAttribute("slot").startsWith("footer-links-"))); const groups = /* @__PURE__ */ new Map(); for (const link of links) { const label = link.getAttribute("data-footer-group")?.trim() || "Links"; if (!groups.has(label)) groups.set(label, []); groups.get(label).push(link); } this._groupsWrap.replaceChildren(); let index = 0; for (const [label, groupLinks] of groups) { const nav = document.createElement("nav"); nav.setAttribute("part", "group"); const heading = document.createElement("strong"); heading.setAttribute("part", "group-heading"); heading.id = `biscuit-footer-group-${this._id}-${index}`; heading.textContent = label; nav.setAttribute("aria-labelledby", heading.id); const slot = document.createElement("slot"); slot.name = `footer-links-${index}`; slot.setAttribute("part", "group-links"); for (const link of groupLinks) if (link.getAttribute("slot") !== slot.name) link.setAttribute("slot", slot.name); nav.append(heading, slot); this._groupsWrap.append(nav); index++; } this._groupsWrap.hidden = groups.size === 0; this.toggleAttribute("data-has-groups", groups.size > 0); } }; var BiscuitSidebarView = class extends HTMLElementBase { static get observedAttributes() { return [ "open", "mode", "label", "track-scroll", "track-scroll-behavior", "track-scroll-position", "track-scroll-offset" ]; } constructor() { super(); this._isMobile = false; this._itemsData = null; this._scrollContainer = null; this._activeSectionLink = null; this._activeSectionHref = null; this._trackingScrollFrame = null; this._onMediaChange = () => this._syncMode(); this._onDocumentKeyDown = (event) => this._handleKeyDown(event); this._onTrackingScroll = () => this._scheduleTrackingUpdate(); const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = sidebarViewStyles; this._toggle = document.createElement("button"); this._toggle.type = "button"; this._toggle.setAttribute("part", "toggle"); this._toggle.setAttribute("aria-expanded", "false"); this._toggle.addEventListener("click", () => this.toggle()); const toggleIcon = document.createElement("span"); toggleIcon.setAttribute("part", "toggle-icon"); toggleIcon.setAttribute("aria-hidden", "true"); toggleIcon.textContent = "☰"; const toggleText = document.createElement("span"); toggleText.textContent = "Menu"; this._toggle.append(toggleIcon, toggleText); this._backdrop = document.createElement("div"); this._backdrop.setAttribute("part", "backdrop"); this._backdrop.setAttribute("aria-hidden", "true"); this._backdrop.addEventListener("click", () => this._setOpen(false)); this._panel = document.createElement("div"); this._panel.setAttribute("part", "panel"); this._panel.id = `biscuit-sidebar-${++sidebarViewId}`; this._panel.tabIndex = -1; this._toggle.setAttribute("aria-controls", this._panel.id); this._panel.addEventListener("click", (event) => { if (!this._isMobile) return; if (event.composedPath?.().find((node) => node.tagName === "A" && node.hasAttribute("href"))) this._setOpen(false, false); }); const header = document.createElement("div"); header.setAttribute("part", "header"); this._title = document.createElement("strong"); this._title.setAttribute("part", "title"); this._close = document.createElement("button"); this._close.type = "button"; this._close.setAttribute("part", "close"); this._close.textContent = "×"; this._close.addEventListener("click", () => this._setOpen(false)); header.append(this._title, this._close); const body = document.createElement("div"); body.setAttribute("part", "body"); this._slot = document.createElement("slot"); this._items = document.createElement("div"); this._items.setAttribute("part", "items"); this._items.hidden = true; body.append(this._slot, this._items); this._panel.append(header, body); root.append(style, this._toggle, this._backdrop, this._panel); this._renderState(); } connectedCallback() { this._media = globalThis.matchMedia?.("(max-width: 720px)"); this._media?.addEventListener?.("change", this._onMediaChange); this._syncMode(); this._renderItems(); if (this.ownerDocument && globalThis.MutationObserver) { this._sourceObserver = new MutationObserver(() => { if (this._itemsData === null) this._renderItems(); this.refreshTracking(); }); this._sourceObserver.observe(this, { childList: true, subtree: true, attributes: true, attributeFilter: [ "href", "label", "aria-current" ] }); } this._syncTracking(); } disconnectedCallback() { this._media?.removeEventListener?.("change", this._onMediaChange); this._media = null; this._sourceObserver?.disconnect(); this._sourceObserver = null; this._stopTracking(); document.removeEventListener("keydown", this._onDocumentKeyDown); } attributeChangedCallback(name, oldValue, newValue) { if (oldValue === newValue || !this._panel) return; if (name === "track-scroll") this._syncTracking(); else if (name === "track-scroll-offset") this.refreshTracking(); else if (name === "track-scroll-behavior" || name === "track-scroll-position") { if (this._activeSectionLink) this._revealTrackedLink(this._activeSectionLink); } else if (name === "mode") this._syncMode(); else this._renderState(); } get open() { return this.hasAttribute("open"); } set open(value) { this.toggleAttribute("open", Boolean(value)); } get sticky() { return this.hasAttribute("sticky"); } set sticky(value) { this.toggleAttribute("sticky", Boolean(value)); } get trackScroll() { return this.hasAttribute("track-scroll"); } set trackScroll(value) { this.toggleAttribute("track-scroll", Boolean(value)); } get trackScrollBehavior() { return this.getAttribute("track-scroll-behavior") === "smooth" ? "smooth" : "auto"; } set trackScrollBehavior(value) { if (value == null || value === "auto") this.removeAttribute("track-scroll-behavior"); else if (value === "smooth") this.setAttribute("track-scroll-behavior", value); else throw new TypeError("trackScrollBehavior must be \"auto\" or \"smooth\""); } get trackScrollPosition() { const value = this.getAttribute("track-scroll-position"); return [ "start", "center", "end" ].includes(value) ? value : "nearest"; } set trackScrollPosition(value) { if (value == null || value === "nearest") this.removeAttribute("track-scroll-position"); else if ([ "start", "center", "end" ].includes(value)) this.setAttribute("track-scroll-position", value); else throw new TypeError("trackScrollPosition must be \"nearest\", \"start\", \"center\", or \"end\""); } get trackScrollOffset() { const value = this.getAttribute("track-scroll-offset"); return value == null ? null : Math.max(0, Number(value) || 0); } set trackScrollOffset(value) { if (value == null) this.removeAttribute("track-scroll-offset"); else if (Number.isFinite(Number(value)) && Number(value) >= 0) this.setAttribute("track-scroll-offset", String(value)); else throw new TypeError("trackScrollOffset must be a non-negative number or null"); } get scrollContainer() { return this._scrollContainer; } set scrollContainer(value) { this._scrollContainer = value ?? null; this._syncTracking(); } get activeSection() { return this._activeSectionHref; } get items() { return this._itemsData; } set items(value) { this._itemsData = Array.isArray(value) ? value : null; this._renderItems(); this._syncTracking(); } get mode() { return this.getAttribute("mode") ?? "auto"; } set mode(value) { if (value == null || value === "auto") this.removeAttribute("mode"); else this.setAttribute("mode", String(value)); } get side() { return this.getAttribute("side") === "right" ? "right" : "left"; } set side(value) { if (value === "right") this.setAttribute("side", "right"); else this.removeAttribute("side"); } get label() { return this.getAttribute("label") ?? "Navigation"; } set label(value) { if (value == null) this.removeAttribute("label"); else this.setAttribute("label", String(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } _readDeclarativeItems() { const source = Array.from(this.children ?? []); if (!source.some((node) => node.tagName === "BISCUIT-SIDEBAR-CATEGORY")) return null; const read = (nodes) => nodes.flatMap((node) => { if (node.tagName === "A") return [{ label: node.textContent.trim(), href: node.getAttribute("href"), current: node.hasAttribute("aria-current"), trackSection: node.getAttribute("data-track-section") }]; if (node.tagName === "BISCUIT-SIDEBAR-CATEGORY") return [{ label: node.getAttribute("label") ?? "Category", href: node.getAttribute("href"), trackSection: node.getAttribute("data-track-section"), children: read(Array.from(node.children)) }]; return []; }); return read(source); } _renderItems() { if (!this._items || !this._slot) return; const items = this._itemsData ?? this._readDeclarativeItems(); this._items.hidden = items === null; this._slot.hidden = items !== null; if (items === null) { this._items.replaceChildren(); return; } const render = (item) => { const children = Array.isArray(item.children) ? item.children : Array.isArray(item.items) ? item.items : null; if (children) { const category = document.createElement("section"); category.setAttribute("part", "category"); const containsCurrent = (entry) => Boolean(entry.current || (entry.children ?? entry.items ?? []).some(containsCurrent)); if (children.some(containsCurrent)) category.setAttribute("data-current", ""); const heading = document.createElement(item.href ? "a" : "strong"); heading.setAttribute("part", item.href ? "category-link" : "category-label"); heading.textContent = String(item.label ?? "Category"); if (item.href) heading.setAttribute("href", String(item.href)); if (item.trackSection) heading.setAttribute("data-track-section", String(item.trackSection)); if (item.current && item.href) heading.setAttribute("aria-current", "page"); const nested = document.createElement("div"); nested.setAttribute("part", "category-items"); nested.append(...children.map(render)); category.append(heading, nested); return category; } const link = document.createElement("a"); link.setAttribute("part", "link"); link.setAttribute("href", String(item.href ?? "#")); if (item.trackSection) link.setAttribute("data-track-section", String(item.trackSection)); link.textContent = String(item.label ?? item.href ?? "Link"); if (item.current) link.setAttribute("aria-current", "page"); return link; }; this._items.replaceChildren(...items.map(render)); } _stopTracking() { this._cancelTrackingScroll(); this._trackingRoot?.removeEventListener?.("scroll", this._onTrackingScroll); this.ownerDocument?.defaultView?.removeEventListener?.("resize", this._onTrackingScroll); this._trackingRoot = null; if (this._trackingFrame != null) this.ownerDocument?.defaultView?.cancelAnimationFrame?.(this._trackingFrame); this._trackingFrame = null; if (this._activeSectionLink?.getAttribute("aria-current") === "location") this._activeSectionLink.removeAttribute("aria-current"); this._activeSectionLink?.removeAttribute("data-tracked"); this._activeSectionLink = null; this._activeSectionHref = null; this._items?.querySelectorAll?.("[part=\"category\"][data-active]").forEach((node) => node.removeAttribute("data-active")); } _syncTracking() { this._stopTracking(); if (!this.isConnected || !this.trackScroll) return; this._trackingRoot = this._scrollContainer ?? this.ownerDocument?.defaultView; this._trackingRoot?.addEventListener?.("scroll", this._onTrackingScroll, { passive: true }); this.ownerDocument?.defaultView?.addEventListener?.("resize", this._onTrackingScroll); this.refreshTracking(); } _scheduleTrackingUpdate() { if (this._trackingFrame != null) return; const view = this.ownerDocument?.defaultView; if (!view?.requestAnimationFrame) { this.refreshTracking(); return; } this._trackingFrame = view.requestAnimationFrame(() => { this._trackingFrame = null; this.refreshTracking(); }); } _cancelTrackingScroll() { if (this._trackingScrollFrame != null) this.ownerDocument?.defaultView?.cancelAnimationFrame?.(this._trackingScrollFrame); this._trackingScrollFrame = null; } refreshTracking() { if (!this.trackScroll || !this.isConnected) return; const doc = this.ownerDocument; const location = doc?.defaultView?.location; if (!doc || !location) return; const sections = (this._items.hidden ? Array.from(this.querySelectorAll?.("a[href]") ?? []) : Array.from(this._items.querySelectorAll("a[href]"))).flatMap((link) => { let id; const explicit = link.getAttribute("data-track-section"); if (explicit != null) id = explicit.replace(/^#/, ""); else { let url; try { url = new URL(link.getAttribute("href"), location.href); } catch { return []; } if (url.origin !== location.origin || url.pathname !== location.pathname || !url.hash) return []; try { id = decodeURIComponent(url.hash.slice(1)); } catch { return []; } } if (!id) return []; const target = doc.getElementById(id); return target ? [{ link, target, href: link.getAttribute("href"), id, explicit: explicit != null }] : []; }); if (!sections.length) return; const viewport = this._trackingRoot?.getBoundingClientRect?.(); const top = viewport?.top ?? 0; const height = viewport?.height ?? doc.defaultView.innerHeight; const threshold = top + (this.trackScrollOffset ?? Math.min(160, height * .28)); let active = sections[0]; let activeTop = -Infinity; for (const section of sections) { const sectionTop = section.target.getBoundingClientRect().top; if (sectionTop <= threshold && sectionTop > activeTop + 1) { active = section; activeTop = sectionTop; } } const scrollElement = this._trackingRoot?.scrollHeight != null ? this._trackingRoot : doc.scrollingElement ?? doc.documentElement; const scrollHeight = scrollElement?.scrollHeight ?? 0; const clientHeight = scrollElement?.clientHeight || height; const scrollTop = Math.max(scrollElement?.scrollTop ?? 0, this._trackingRoot === doc.defaultView ? doc.defaultView.scrollY ?? 0 : 0); if (scrollHeight > clientHeight + 2 && scrollTop + clientHeight >= scrollHeight - 2) active = sections.at(-1); if (this._activeSectionLink === active.link) return; if (this._activeSectionLink?.getAttribute("aria-current") === "location") this._activeSectionLink.removeAttribute("aria-current"); this._activeSectionLink?.removeAttribute("data-tracked"); this._items.querySelectorAll("[part=\"category\"][data-active]").forEach((node) => node.removeAttribute("data-active")); this._activeSectionLink = active.link; this._activeSectionHref = active.href; active.link.setAttribute("data-tracked", ""); if (!active.explicit && !active.link.hasAttribute("aria-current")) active.link.setAttribute("aria-current", "location"); for (let parent = active.link.parentElement; parent && parent !== this._items; parent = parent.parentElement) if (parent.getAttribute("part") === "category") parent.setAttribute("data-active", ""); this._revealTrackedLink(active.link); this.dispatchEvent(new CustomEvent("sectionchange", { detail: { href: active.href, id: active.id }, bubbles: true, composed: true })); } _revealTrackedLink(link) { this._cancelTrackingScroll(); if (this._isMobile && !this.open) return; const box = [this._panel, this].find((node) => node.scrollHeight > node.clientHeight + 2); if (!box) return; const bounds = box.getBoundingClientRect(); const linkBounds = link.getBoundingClientRect(); const inset = 8; const position = this.trackScrollPosition; let delta = 0; if (position === "start") delta = linkBounds.top - bounds.top - inset; else if (position === "center") delta = linkBounds.top - bounds.top - (box.clientHeight - linkBounds.height) / 2; else if (position === "end") delta = linkBounds.bottom - bounds.bottom + inset; else { if (linkBounds.top < bounds.top + inset) delta = linkBounds.top - bounds.top - inset; else if (link.getAttribute("part") === "category-link") { const groupBounds = link.closest("[part=\"category\"]")?.getBoundingClientRect(); if (groupBounds?.bottom > bounds.bottom - inset) delta = groupBounds.height <= box.clientHeight - 16 ? groupBounds.bottom - bounds.bottom + inset : linkBounds.top - bounds.top - inset; } if (!delta && linkBounds.bottom > bounds.bottom - inset) delta = linkBounds.bottom - bounds.bottom + inset; } if (Math.abs(delta) < 1) return; const top = Math.max(0, Math.min(box.scrollHeight - box.clientHeight, box.scrollTop + delta)); const view = this.ownerDocument?.defaultView; const reducedMotion = view?.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches; if (Math.abs(top - box.scrollTop) < 1) return; if (this.trackScrollBehavior === "smooth" && !reducedMotion && view?.requestAnimationFrame) { const start = box.scrollTop; const distance = top - start; const duration = Math.min(210, 120 + Math.abs(distance) * .11); const startTime = view.performance?.now?.() ?? 0; const step = (time) => { const progress = Math.min(1, Math.max(0, (time - startTime) / duration)); const eased = 1 - (1 - progress) ** 3; box.scrollTop = start + distance * eased; if (progress < 1) this._trackingScrollFrame = view.requestAnimationFrame(step); else this._trackingScrollFrame = null; }; this._trackingScrollFrame = view.requestAnimationFrame(step); } else box.scrollTop = top; } toggle() { this._setOpen(!this.open); } _setOpen(open, restoreFocus = true) { if (!this._isMobile || open === this.open) return; if (!open && restoreFocus) this._toggle.focus({ preventScroll: true }); else if (!open && this.contains?.(document.activeElement)) document.activeElement?.blur?.(); this.open = open; if (open) { const focusInside = () => { if (!this.open || !this._isMobile) return; (this._activeSectionLink ?? this._focusables()[0] ?? this._panel).focus({ preventScroll: true }); if (this._activeSectionLink) this._revealTrackedLink(this._activeSectionLink); }; setTimeout(focusInside, 200); } this.dispatchEvent(new Event("change", { bubbles: true, composed: true })); } _focusables() { const nodes = (this._items && !this._items.hidden ? this._items : this).querySelectorAll?.("a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])") ?? []; return Array.from(nodes).filter((node) => !node.getClientRects || node.getClientRects().length > 0); } _handleKeyDown(event) { if (!this._isMobile || !this.open) return; if (event.key === "Escape") { event.preventDefault(); this._setOpen(false); } else if (event.key === "Tab") { const nodes = [this._close, ...this._focusables()]; const active = nodes.find((node) => node === document.activeElement || node === this.shadowRoot.activeElement); const first = nodes[0]; const last = nodes[nodes.length - 1]; if (!active || event.shiftKey && active === first || !event.shiftKey && active === last) { event.preventDefault(); (event.shiftKey ? last : first).focus(); } } } _syncMode() { const wasMobile = this._isMobile; this._isMobile = this.mode === "mobile" || this.mode !== "desktop" && Boolean(this._media?.matches); this.toggleAttribute("data-mobile", this._isMobile); if (wasMobile && !this._isMobile && this.open) this.open = false; this._renderState(); } _renderState() { const mobile = this._isMobile; const open = this.open; const label = this.label; this._title.textContent = label; this._toggle.hidden = !mobile; this._toggle.setAttribute("aria-label", `${open ? "Close" : "Open"} ${label}`); this._toggle.setAttribute("aria-expanded", String(mobile && open)); this._close.hidden = !mobile; this._close.setAttribute("aria-label", `Close ${label}`); this._backdrop.hidden = !mobile || !open; this._panel.inert = mobile && !open; this._panel.setAttribute("role", mobile ? "dialog" : "navigation"); this._panel.setAttribute("aria-label", label); if (mobile && open) this._panel.setAttribute("aria-modal", "true"); else this._panel.removeAttribute("aria-modal"); if (mobile && !open) this._panel.setAttribute("aria-hidden", "true"); else this._panel.removeAttribute("aria-hidden"); document.removeEventListener("keydown", this._onDocumentKeyDown); if (this.isConnected && mobile && open) document.addEventListener("keydown", this._onDocumentKeyDown); } }; function defineTabLayout() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit TabLayout requires a browser with Custom Elements"); const existing = registry.get(TABLAYOUT_TAG_NAME); if (existing && existing !== BiscuitTabLayout) throw new Error(`<${TABLAYOUT_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(TABLAYOUT_TAG_NAME, BiscuitTabLayout); return BiscuitTabLayout; } function defineSplitView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit SplitView requires a browser with Custom Elements"); const existing = registry.get(SPLITVIEW_TAG_NAME); if (existing && existing !== BiscuitSplitView) throw new Error(`<${SPLITVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(SPLITVIEW_TAG_NAME, BiscuitSplitView); return BiscuitSplitView; } function defineNavBarView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit NavBarView requires a browser with Custom Elements"); const existing = registry.get(NAVBARVIEW_TAG_NAME); if (existing && existing !== BiscuitNavBarView) throw new Error(`<${NAVBARVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(NAVBARVIEW_TAG_NAME, BiscuitNavBarView); return BiscuitNavBarView; } function defineFooterView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit FooterView requires a browser with Custom Elements"); const existing = registry.get(FOOTERVIEW_TAG_NAME); if (existing && existing !== BiscuitFooterView) throw new Error(`<${FOOTERVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(FOOTERVIEW_TAG_NAME, BiscuitFooterView); return BiscuitFooterView; } function defineSidebarView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit SidebarView requires a browser with Custom Elements"); const existing = registry.get(SIDEBARVIEW_TAG_NAME); if (existing && existing !== BiscuitSidebarView) throw new Error(`<${SIDEBARVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(SIDEBARVIEW_TAG_NAME, BiscuitSidebarView); return BiscuitSidebarView; } function createTabLayout(options = {}) { if (!globalThis.document) throw new Error("Biscuit TabLayout requires a browser document"); defineTabLayout(); const element = createConfiguredElement(TABLAYOUT_TAG_NAME, options); if (Object.hasOwn(options, "theme")) element.theme = options.theme; if (Object.hasOwn(options, "orientation")) element.orientation = options.orientation; if (Object.hasOwn(options, "variant")) element.variant = options.variant; if (Object.hasOwn(options, "ariaLabel")) element.setAttribute("aria-label", String(options.ariaLabel)); for (const item of options.tabs ?? []) { const tab = document.createElement("biscuit-tab"); if (Object.hasOwn(item, "value")) tab.setAttribute("value", String(item.value)); tab.setAttribute("label", String(item.label ?? item.value ?? "Tab")); if (item.disabled) tab.setAttribute("disabled", ""); if (item.selected) tab.setAttribute("selected", ""); if (item.content != null) tab.append(item.content); element.append(tab); } if (Object.hasOwn(options, "value")) element.value = options.value; element._syncTabs(); return element; } function createSplitView(options = {}) { if (!globalThis.document) throw new Error("Biscuit SplitView requires a browser document"); defineSplitView(); const element = createConfiguredElement(SPLITVIEW_TAG_NAME, options); for (const key of [ "orientation", "resizable", "min", "max", "leftMin", "leftMax", "rightMin", "rightMax", "topMin", "topMax", "bottomMin", "bottomMax", "value", "theme" ]) if (Object.hasOwn(options, key)) element[key] = options[key]; if (Object.hasOwn(options, "ariaLabel")) element.setAttribute("aria-label", String(options.ariaLabel)); for (const slot of ["first", "second"]) { if (options[slot] == null) continue; const content = options[slot]; const pane = typeof content.setAttribute === "function" ? content : document.createElement("div"); if (pane !== content) pane.textContent = String(content); pane.setAttribute("slot", slot); element.append(pane); } return element; } function createSidebarView(options = {}) { if (!globalThis.document) throw new Error("Biscuit SidebarView requires a browser document"); defineSidebarView(); const element = createConfiguredElement(SIDEBARVIEW_TAG_NAME, options); if (Object.hasOwn(options, "label")) element.label = options.label; if (Object.hasOwn(options, "theme")) element.theme = options.theme; if (Object.hasOwn(options, "side")) element.side = options.side; if (Object.hasOwn(options, "mode")) element.mode = options.mode; if (Object.hasOwn(options, "open")) element.open = options.open; if (Object.hasOwn(options, "sticky")) element.sticky = options.sticky; if (Object.hasOwn(options, "scrollContainer")) element.scrollContainer = options.scrollContainer; if (options.items?.some((item) => Array.isArray(item.children) || Array.isArray(item.items))) element.items = options.items; else for (const item of options.items ?? []) { const link = document.createElement("a"); link.setAttribute("href", String(item.href)); if (item.trackSection) link.setAttribute("data-track-section", String(item.trackSection)); link.textContent = String(item.label); if (item.current) link.setAttribute("aria-current", "page"); element.append(link); } if (options.content != null) element.append(options.content); if (Object.hasOwn(options, "trackScroll")) element.trackScroll = options.trackScroll; if (Object.hasOwn(options, "trackScrollBehavior")) element.trackScrollBehavior = options.trackScrollBehavior; if (Object.hasOwn(options, "trackScrollPosition")) element.trackScrollPosition = options.trackScrollPosition; if (Object.hasOwn(options, "trackScrollOffset")) element.trackScrollOffset = options.trackScrollOffset; return element; } function createNavBarView(options = {}) { if (!globalThis.document) throw new Error("Biscuit NavBarView requires a browser document"); defineNavBarView(); const element = createConfiguredElement(NAVBARVIEW_TAG_NAME, options); for (const key of [ "brand", "brandHref", "mode", "open", "sticky", "fullWidth", "theme" ]) if (Object.hasOwn(options, key)) element[key] = options[key]; if (Object.hasOwn(options, "ariaLabel")) element.setAttribute("aria-label", String(options.ariaLabel)); for (const item of options.items ?? []) { const link = document.createElement("a"); link.setAttribute("href", String(item.href)); link.textContent = String(item.label); if (item.current) link.setAttribute("aria-current", "page"); element.append(link); } if (options.actions != null) { const actions = Array.isArray(options.actions) ? options.actions : [options.actions]; for (const action of actions) { if (typeof action?.setAttribute !== "function") throw new TypeError("NavBarView actions must be elements"); action.setAttribute("slot", "actions"); element.append(action); } } element._syncActions(); return element; } function createFooterView(options = {}) { if (!globalThis.document) throw new Error("Biscuit FooterView requires a browser document"); defineFooterView(); const element = createConfiguredElement(FOOTERVIEW_TAG_NAME, options); for (const key of [ "brand", "brandHref", "description", "copyright", "fullWidth", "theme" ]) if (Object.hasOwn(options, key)) element[key] = options[key]; if (Object.hasOwn(options, "ariaLabel")) element.setAttribute("aria-label", String(options.ariaLabel)); if (options.groups != null) element.groups = options.groups; for (const [name, content] of [ ["brand", options.brandContent], ["description", options.descriptionContent], ["actions", options.actions], ["bottom", options.bottom] ]) { if (content == null) continue; for (const node of Array.isArray(content) ? content : [content]) { if (typeof node?.setAttribute !== "function") throw new TypeError(`FooterView ${name} content must be elements`); node.setAttribute("slot", name); element.append(node); } } element._syncContent(); return element; } function defineLayout() { defineSplitView(); defineTabLayout(); defineNavBarView(); defineFooterView(); defineSidebarView(); } // src/groups/media.js var media_exports = /* @__PURE__ */ __exportAll({ BiscuitCarouselView: () => BiscuitCarouselView, BiscuitFileBrowserView: () => BiscuitFileBrowserView, BiscuitIconGridView: () => BiscuitIconGridView, BiscuitImageView: () => BiscuitImageView, createCarouselView: () => createCarouselView, createFileBrowserView: () => createFileBrowserView, createIconGridView: () => createIconGridView, createImageView: () => createImageView, defineCarouselView: () => defineCarouselView, defineFileBrowserView: () => defineFileBrowserView, defineIconGridView: () => defineIconGridView, defineImageView: () => defineImageView, defineMedia: () => defineMedia }); var IMAGEVIEW_TAG_NAME = "biscuit-imageview"; var CAROUSELVIEW_TAG_NAME = "biscuit-carouselview"; var ICONGRIDVIEW_TAG_NAME = "biscuit-icongridview"; var FILEBROWSERVIEW_TAG_NAME = "biscuit-filebrowserview"; var carouselViewId = 0; var iconGridViewStyles = ` :host { box-sizing: border-box; display: block; min-width: 0; padding: var(--biscuit-icongridview-padding, calc(1.5rem * var(--biscuit-space-scale, 1))); border-radius: var(--biscuit-icongridview-radius, 1rem); background: var(--biscuit-icongridview-background, light-dark(#f3f4f8, #171920)); color: var(--biscuit-icongridview-color, var(--biscuit-theme-color, light-dark(#252936, #f4f6fa))); color-scheme: inherit; font: 400 0.875rem/1.4 system-ui, sans-serif; } ${themeStyles} [part="heading"] { display: block; margin: 0 0 1.25rem; font-size: 1.5rem; font-weight: 750; } [part="heading"][hidden], [part="label"][hidden] { display: none; } [part="grid"] { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--biscuit-icongridview-tile-min-width, 7rem)), 1fr)); gap: var(--biscuit-icongridview-gap, calc(1rem * var(--biscuit-space-scale, 1))); } [part="tile"] { box-sizing: border-box; display: grid; justify-items: center; align-content: center; gap: 0.75rem; min-height: 7rem; padding: 1rem 0.5rem; border: 1px solid var(--biscuit-icongridview-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #535b6a))); border-radius: var(--biscuit-icongridview-tile-radius, 0.9rem); background: var(--biscuit-icongridview-tile-background, var(--biscuit-theme-surface, light-dark(#fff, #292c37))); } [part="icon"] { display: inline-flex; align-items: center; justify-content: center; width: 1em; height: 1em; font-size: var(--biscuit-icongridview-icon-size, 2.5rem); line-height: 1; } [part="icon"] > svg, [part="icon"] > img { display: block; width: 100%; height: 100%; object-fit: contain; } [part="label"] { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--biscuit-icongridview-label-color, light-dark(#687080, #b9c0cc)); font-size: 0.8rem; } :host([theme="deep-dark"]) { --biscuit-icongridview-background: #000; --biscuit-icongridview-color: #fff; --biscuit-icongridview-tile-background: #000; --biscuit-icongridview-border-color: #fff; --biscuit-icongridview-label-color: #fff; } `; var fileBrowserViewStyles = ` :host { box-sizing: border-box; display: block; min-width: 0; width: 100%; overflow: hidden; color-scheme: inherit; border: var(--biscuit-filebrowserview-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a)))); border-radius: var(--biscuit-filebrowserview-radius, 0.65rem); background: var(--biscuit-filebrowserview-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); color: var(--biscuit-filebrowserview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); font: var(--biscuit-filebrowserview-font, 400 0.875rem/1.4 system-ui, sans-serif); } ${themeStyles} [hidden] { display: none !important; } [part="toolbar"] { display: flex; align-items: center; gap: 0.75rem; min-height: 2.75rem; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); } [part="title"] { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 750; } [part="search-wrap"] { display: flex; align-items: center; gap: 0.35rem; width: min(12rem, 55%); padding: 0.3rem 0.5rem; border: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); border-radius: 0.4rem; } [part="search-icon"] { opacity: 0.65; } [part="search"] { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: inherit; font: inherit; } [part="search"]::placeholder { color: inherit; opacity: 0.55; } [part="tree"] { max-height: var(--biscuit-filebrowserview-height, 23rem); overflow: auto; padding: 0.45rem; } [part="row"] { box-sizing: border-box; display: flex; align-items: center; gap: 0.55rem; width: 100%; min-height: 2rem; padding: 0.25rem 0.65rem 0.25rem calc(0.65rem + var(--depth) * 1.2rem); border: 0; border-radius: 0.4rem; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; } [part="row"]:hover { background: var(--biscuit-filebrowserview-hover-background, color-mix(in srgb, currentColor 9%, transparent)); } [part="row"][aria-selected="true"] { background: var(--biscuit-filebrowserview-selected-background, var(--biscuit-theme-option-background, light-dark(#efedff, #45415f))); color: var(--biscuit-filebrowserview-selected-color, var(--biscuit-theme-option-color, light-dark(#38306e, #fff))); } [part="row"]:focus-visible, [part="search"]:focus-visible { outline: 2px solid var(--biscuit-filebrowserview-focus-color, var(--biscuit-focus-color, var(--biscuit-theme-focus-color, light-dark(#6b63db, #aaa2ff)))); outline-offset: -2px; } [part="chevron"], [part="spacer"] { display: inline-flex; align-items: center; justify-content: center; width: 0.9rem; height: 0.9rem; flex: none; font-size: 0.8rem; } [part="icon"] { font-size: 1.15rem; line-height: 1; } [part="name"] { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } [part="empty"] { padding: 1rem; opacity: 0.7; } :host([theme="deep-dark"]) { --biscuit-filebrowserview-hover-background: #222; --biscuit-filebrowserview-selected-background: #fff; --biscuit-filebrowserview-selected-color: #000; } `; var imageViewStyles = ` :host { box-sizing: border-box; display: block; min-width: 0; overflow: hidden; color-scheme: inherit; border: var(--biscuit-imageview-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a)))); border-radius: var(--biscuit-imageview-radius, 0.75rem); background: var(--biscuit-imageview-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); color: var(--biscuit-imageview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); font: var(--biscuit-imageview-font, 400 0.875rem/1.45 system-ui, sans-serif); } ${themeStyles} [hidden] { display: none !important; } [part="figure"] { margin: 0; } [part="frame"] { display: grid; place-items: center; position: relative; width: 100%; aspect-ratio: var(--biscuit-imageview-aspect-ratio, 16 / 9); overflow: hidden; background: var(--biscuit-imageview-frame-background, light-dark(#f0f1f5, #20232c)); } [part="image"] { display: block; width: 100%; height: 100%; min-height: 0; object-fit: var(--biscuit-imageview-fit, cover); object-position: var(--biscuit-imageview-position, center); opacity: 0; } :host([data-state="loaded"]) [part="image"] { opacity: 1; } [part="loading"], [part="fallback"] { position: absolute; inset: 0; display: grid; place-items: center; padding: 1rem; text-align: center; } [part="fallback"] { color: var(--biscuit-imageview-muted-color, light-dark(#646677, #b1b5c5)); } .image-spinner { width: 1.25rem; height: 1.25rem; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: biscuit-image-spin .8s linear infinite; } @keyframes biscuit-image-spin { to { transform: rotate(360deg); } } @media (prefers-reduced-motion: reduce) { .image-spinner { animation: none; } } [part="caption"] { padding: var(--biscuit-imageview-caption-padding, 0.75rem 0.9rem); } `; var carouselViewStyles = ` :host { box-sizing: border-box; display: block; min-width: 0; color-scheme: inherit; border: var(--biscuit-carouselview-border, 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a)))); border-radius: var(--biscuit-carouselview-radius, 0.75rem); background: var(--biscuit-carouselview-background, var(--biscuit-surface, var(--biscuit-theme-surface, light-dark(#fff, #292c37)))); color: var(--biscuit-carouselview-color, var(--biscuit-color, var(--biscuit-theme-color, light-dark(#24252b, #f3f4f8)))); font: var(--biscuit-carouselview-font, 400 0.9375rem/1.45 system-ui, sans-serif); } ${themeStyles} [hidden] { display: none !important; } [part="viewport"] { min-width: 0; overflow: hidden; touch-action: pan-y; } [part="viewport"]:focus-visible, [part="previous"]:focus-visible, [part="next"]:focus-visible, [part="dot"]:focus-visible { outline: 2px solid var(--biscuit-carouselview-focus-color, var(--biscuit-focus-color, var(--biscuit-theme-focus-color, light-dark(#6b63db, #aaa2ff)))); outline-offset: -2px; } [part="slide"] { min-width: 0; min-height: var(--biscuit-carouselview-slide-min-height, 12rem); } ::slotted(biscuit-slide) { display: block; } [part="controls"] { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: var(--biscuit-carouselview-controls-padding, 0.65rem 0.8rem); } [part="previous"], [part="next"] { flex: none; display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border: 1px solid var(--biscuit-border-color, var(--biscuit-theme-cardview-border-color, light-dark(#d6d8df, #656b7a))); border-radius: 50%; background: var(--biscuit-carouselview-control-background, transparent); color: inherit; font: inherit; font-size: 1.4rem; line-height: 1; cursor: pointer; } [part="previous"]:hover:not(:disabled), [part="next"]:hover:not(:disabled) { background: var(--biscuit-carouselview-hover-background, var(--biscuit-theme-option-background, light-dark(#efedff, #45415f))); color: var(--biscuit-carouselview-hover-color, var(--biscuit-theme-option-color, light-dark(#38306e, #fff))); } [part="previous"]:disabled, [part="next"]:disabled { opacity: 0.4; cursor: not-allowed; } [part="dots"] { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.45rem; } [part="dot"] { width: 0.7rem; height: 0.7rem; padding: 0; border: 0; border-radius: 50%; background: var(--biscuit-carouselview-dot-color, light-dark(#b4b7c3, #6d7280)); cursor: pointer; } [part="dot"][aria-current="true"] { background: var(--biscuit-carouselview-active-dot-color, var(--biscuit-focus-color, var(--biscuit-theme-focus-color, light-dark(#6b63db, #aaa2ff)))); transform: scale(1.2); } [part="status"] { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } `; function normalizeIconGridItems(items) { if (!Array.isArray(items)) throw new TypeError("IconGridView icons must be an array"); return items.map((entry) => { if (typeof entry === "string") { getIconSvg(entry); return { name: entry, label: entry, icon: entry }; } if (!entry || typeof entry !== "object") throw new TypeError("IconGridView icons must be names or icon objects"); const name = String(entry.name ?? entry.label ?? "").trim(); if (!name) throw new TypeError("Custom icons need a name or label"); const label = String(entry.label ?? name); const src = entry.src == null ? null : String(entry.src).trim(); const element = entry.element ?? null; if (src && element) throw new TypeError("Custom icons need either src or element, not both"); if (element && (element.nodeType !== 1 || typeof element.cloneNode !== "function")) throw new TypeError("Custom icon element must be a DOM element"); const icon = src || element ? null : String(entry.icon ?? name); if (icon) getIconSvg(icon); if (entry.src != null && !src) throw new TypeError("Custom icon src must not be empty"); return { name, label, icon, src, element }; }); } var BiscuitIconGridView = class extends HTMLElementBase { static get observedAttributes() { return ["heading", "hide-labels"]; } constructor() { super(); this._icons = null; const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = iconGridViewStyles; this._heading = document.createElement("strong"); this._heading.setAttribute("part", "heading"); this._grid = document.createElement("div"); this._grid.setAttribute("part", "grid"); root.append(style, this._heading, this._grid); this._render(); } connectedCallback() { this._render(); if (globalThis.MutationObserver) { this._observer = new MutationObserver(() => { if (this._icons === null) this._render(); }); this._observer.observe(this, { childList: true, subtree: true, attributes: true }); } } disconnectedCallback() { this._observer?.disconnect(); } attributeChangedCallback() { this._render(); } get icons() { return this._icons?.slice() ?? this._readMarkup(); } set icons(value) { if (value !== null) normalizeIconGridItems(value); this._icons = value?.slice() ?? null; this._render(); } get heading() { return this.getAttribute("heading") ?? "Biscuit icons"; } set heading(value) { if (value == null) this.removeAttribute("heading"); else this.setAttribute("heading", String(value)); } get showLabels() { return !this.hasAttribute("hide-labels"); } set showLabels(value) { this.toggleAttribute("hide-labels", !Boolean(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } _readMarkup() { const nodes = Array.from(this.children ?? []).filter((node) => (node.localName ?? node.tagName?.toLowerCase()) === "biscuit-icon"); if (!nodes.length) return iconNames.slice(); return nodes.map((node) => ({ name: node.getAttribute("name") ?? node.getAttribute("label"), label: node.getAttribute("label") ?? void 0, icon: node.getAttribute("icon") ?? void 0, src: node.getAttribute("src") ?? void 0, element: node.firstElementChild ?? void 0 })); } _render() { if (!this._grid) return; this._heading.textContent = this.heading; this._heading.hidden = !this.heading; const tiles = normalizeIconGridItems(this.icons).map(({ name, label: caption, icon: iconName, src, element }) => { const tile = document.createElement("div"); tile.setAttribute("part", "tile"); let icon; if (iconName) icon = createIcon(iconName, this.showLabels ? {} : { label: caption }); else { icon = document.createElement("span"); if (src) { const image = document.createElement("img"); image.src = src; image.alt = this.showLabels ? "" : caption; icon.append(image); } else { icon.append(element.cloneNode(true)); if (this.showLabels) icon.setAttribute("aria-hidden", "true"); else { icon.setAttribute("role", "img"); icon.setAttribute("aria-label", caption); } } } icon.setAttribute("part", "icon"); const label = document.createElement("span"); label.setAttribute("part", "label"); label.hidden = !this.showLabels; label.textContent = caption; tile.append(icon, label); return tile; }); this._grid.replaceChildren(...tiles); } }; function normalizeFileBrowserItems(items, parentPath = "") { if (!Array.isArray(items)) throw new TypeError("FileBrowserView items must be an array"); return items.map((entry) => { const item = typeof entry === "string" ? { name: entry } : entry; if (!item || typeof item !== "object" || !String(item.name ?? "").trim()) throw new TypeError("FileBrowserView items need a name"); const name = String(item.name); const path = String(item.path ?? (parentPath ? `${parentPath}/${name}` : name)); const folder = item.type === "folder" || item.type === "directory" || Array.isArray(item.children); return { name, path, folder, expanded: Boolean(item.expanded), icon: item.icon && Object.hasOwn(iconSvgs, item.icon) ? String(item.icon) : null, children: folder ? normalizeFileBrowserItems(item.children ?? [], path) : [] }; }); } function fileBrowserIcon(item) { if (item.icon) return item.icon; if (item.folder) return "folder"; const ext = item.name.split(".").at(-1).toLowerCase(); if (["html", "htm"].includes(ext)) return "html-file"; if ([ "js", "mjs", "cjs", "jsx" ].includes(ext)) return "js-file"; if (ext === "css") return "css-file"; if (ext === "svg") return "svg-file"; if ([ "png", "jpg", "jpeg", "gif", "webp", "avif", "bmp", "ico" ].includes(ext)) return "image-file"; if ([ "ts", "tsx", "java", "py", "rb", "go", "rs", "php", "sh", "json", "xml", "yaml", "yml", "md" ].includes(ext)) return "code-file"; return "file"; } var BiscuitFileBrowserView = class extends HTMLElementBase { static get observedAttributes() { return [ "label", "searchable", "value" ]; } constructor() { super(); this._items = null; this._expanded = /* @__PURE__ */ new Set(); this._focusedPath = null; this._visible = []; this._rows = /* @__PURE__ */ new Map(); const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = fileBrowserViewStyles; this._toolbar = document.createElement("div"); this._toolbar.setAttribute("part", "toolbar"); this._title = document.createElement("strong"); this._title.setAttribute("part", "title"); this._searchWrap = document.createElement("label"); this._searchWrap.setAttribute("part", "search-wrap"); const searchIcon = createIcon("search"); searchIcon.setAttribute("part", "search-icon"); this._search = document.createElement("input"); this._search.type = "search"; this._search.placeholder = "Find a file"; this._search.setAttribute("part", "search"); this._search.setAttribute("aria-label", "Find a file"); this._search.addEventListener("input", () => this._render()); this._searchWrap.append(searchIcon, this._search); this._toolbar.append(this._title, this._searchWrap); this._tree = document.createElement("div"); this._tree.setAttribute("part", "tree"); this._tree.setAttribute("role", "tree"); root.append(style, this._toolbar, this._tree); this._render(); } connectedCallback() { if (!this._items && !this._markupInitialized) { this._collectInitiallyExpanded(this._readMarkup()); this._markupInitialized = true; } this._render(); if (globalThis.MutationObserver) { this._observer = new MutationObserver(() => { if (!this._items) this._render(); }); this._observer.observe(this, { childList: true, subtree: true, attributes: true }); } } disconnectedCallback() { this._observer?.disconnect(); } attributeChangedCallback() { if (this._tree) this._render(); } get items() { return this._items ?? this._readMarkup(); } set items(value) { this._items = normalizeFileBrowserItems(value); this._expanded.clear(); this._collectInitiallyExpanded(this._items); this._render(); } get label() { return this.getAttribute("label") ?? "Files"; } set label(value) { if (value == null) this.removeAttribute("label"); else this.setAttribute("label", String(value)); } get searchable() { return this.hasAttribute("searchable"); } set searchable(value) { this.toggleAttribute("searchable", Boolean(value)); } get value() { return this.getAttribute("value") ?? ""; } set value(value) { if (value == null || value === "") this.removeAttribute("value"); else this.setAttribute("value", String(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } openAll() { this._collectAllFolders(this.items); this._render(); } collapseAll() { this._expanded.clear(); this._render(); } refresh() { this._render(); } _readMarkup() { const parse = (parent) => Array.from(parent.children ?? []).flatMap((node) => { const tag = node.localName ?? node.tagName?.toLowerCase(); if (tag !== "biscuit-folder" && tag !== "biscuit-file") return []; return [{ name: node.getAttribute("name") ?? node.textContent?.trim(), path: node.getAttribute("path") ?? void 0, type: tag === "biscuit-folder" ? "folder" : "file", expanded: node.hasAttribute("open"), icon: node.getAttribute("icon") ?? void 0, children: tag === "biscuit-folder" ? parse(node) : void 0 }]; }); return normalizeFileBrowserItems(parse(this)); } _collectInitiallyExpanded(items) { for (const item of items) { if (item.folder && item.expanded) this._expanded.add(item.path); this._collectInitiallyExpanded(item.children); } } _collectAllFolders(items) { for (const item of items) { if (item.folder) this._expanded.add(item.path); this._collectAllFolders(item.children); } } _render() { if (!this._tree) return; const items = this.items; this._title.textContent = this.label; this._tree.setAttribute("aria-label", this.label); this._searchWrap.hidden = !this.searchable; const query = this.searchable ? this._search.value.trim().toLowerCase() : ""; const matches = (item) => !query || item.name.toLowerCase().includes(query) || item.children.some(matches); const visible = []; const walk = (entries, depth, parentPath = "") => { for (const item of entries) { if (!matches(item)) continue; visible.push({ item, depth, parentPath }); if (item.folder && (query || this._expanded.has(item.path))) walk(item.children, depth + 1, item.path); } }; walk(items, 0); this._visible = visible; if (!visible.some(({ item }) => item.path === this._focusedPath)) this._focusedPath = visible[0]?.item.path ?? null; this._rows = /* @__PURE__ */ new Map(); const nodes = visible.map(({ item, depth }) => { const row = document.createElement("button"); row.type = "button"; row.setAttribute("part", "row"); row.setAttribute("role", "treeitem"); row.setAttribute("aria-level", String(depth + 1)); row.setAttribute("aria-selected", String(!item.folder && this.value === item.path)); row.setAttribute("aria-label", item.path); if (item.folder) row.setAttribute("aria-expanded", String(Boolean(query || this._expanded.has(item.path)))); row.style.setProperty("--depth", String(depth)); row.tabIndex = item.path === this._focusedPath ? 0 : -1; const chevron = document.createElement("span"); chevron.setAttribute("part", item.folder ? "chevron" : "spacer"); if (item.folder) chevron.append(createIcon(query || this._expanded.has(item.path) ? "chevron-down" : "chevron-right")); const icon = createIcon(fileBrowserIcon(item)); icon.setAttribute("part", "icon"); const name = document.createElement("span"); name.setAttribute("part", "name"); name.textContent = item.name; row.append(chevron, icon, name); row.addEventListener("focus", () => { this._focusedPath = item.path; }); row.addEventListener("click", () => this._activate(item)); row.addEventListener("keydown", (event) => this._onRowKeyDown(event, item)); this._rows.set(item.path, row); return row; }); if (!nodes.length) { const empty = document.createElement("div"); empty.setAttribute("part", "empty"); empty.textContent = query ? "No matching files" : "No files"; nodes.push(empty); } this._tree.replaceChildren(...nodes); } _activate(item) { this._focusedPath = item.path; if (item.folder) { if (this.searchable && this._search.value.trim()) return; const expanded = !this._expanded.has(item.path); if (expanded) this._expanded.add(item.path); else this._expanded.delete(item.path); this._render(); this._focusPath(item.path); const event = new Event("toggle", { bubbles: true, composed: true }); event.detail = { item, path: item.path, expanded }; this.dispatchEvent(event); return; } this.value = item.path; this._focusPath(item.path); for (const type of ["select", "change"]) { const event = new Event(type, { bubbles: true, composed: true }); event.detail = { item, path: item.path }; this.dispatchEvent(event); } } _focusPath(path) { this._focusedPath = path; for (const [key, row] of this._rows) row.tabIndex = key === path ? 0 : -1; this._rows.get(path)?.focus(); } _onRowKeyDown(event, item) { const index = this._visible.findIndex(({ item: entry }) => entry.path === item.path); let target = null; if (event.key === "ArrowDown") target = this._visible[index + 1]?.item.path; else if (event.key === "ArrowUp") target = this._visible[index - 1]?.item.path; else if (event.key === "Home") target = this._visible[0]?.item.path; else if (event.key === "End") target = this._visible.at(-1)?.item.path; else if (event.key === "ArrowRight" && item.folder) { if (!this._expanded.has(item.path)) this._activate(item); else if (this._visible[index + 1]?.depth > this._visible[index]?.depth) target = this._visible[index + 1].item.path; } else if (event.key === "ArrowLeft") { if (item.folder && this._expanded.has(item.path)) this._activate(item); else target = this._visible[index]?.parentPath; } else if (event.key === "Enter" || event.key === " ") { event.preventDefault(); this._activate(item); return; } else return; event.preventDefault(); if (target) this._focusPath(target); } }; var BiscuitImageView = class extends HTMLElementBase { static get observedAttributes() { return [ "src", "alt", "fit", "aspect-ratio", "caption", "fallback", "loading", "srcset", "sizes" ]; } constructor() { super(); const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = imageViewStyles; const figure = document.createElement("figure"); figure.setAttribute("part", "figure"); this._frame = document.createElement("div"); this._frame.setAttribute("part", "frame"); this._image = document.createElement("img"); this._image.setAttribute("part", "image"); this._image.setAttribute("alt", ""); this._image.setAttribute("loading", "lazy"); this._image.addEventListener("load", () => { if (!this.src) return; this._setState("loaded"); this.dispatchEvent(new Event("load")); }); this._image.addEventListener("error", () => { if (!this.src) return; this._setState("error"); this.dispatchEvent(new Event("error")); }); this._loading = document.createElement("div"); this._loading.setAttribute("part", "loading"); const indicator = document.createElement("span"); indicator.className = "image-spinner"; indicator.setAttribute("role", "status"); indicator.setAttribute("aria-label", "Loading image"); this._loading.append(indicator); this._fallback = document.createElement("div"); this._fallback.setAttribute("part", "fallback"); this._caption = document.createElement("figcaption"); this._caption.setAttribute("part", "caption"); this._caption.hidden = true; this._frame.append(this._image, this._loading, this._fallback); figure.append(this._frame, this._caption); root.append(style, figure); } connectedCallback() { if (!this.hasAttribute("data-state")) this._syncSource(); else if (this.src && this._image.complete && this._image.naturalWidth > 0) this._setState("loaded"); } attributeChangedCallback(name, oldValue, newValue) { if (oldValue === newValue) return; if (name === "src") this._syncSource(); if (name === "alt") this._image.setAttribute("alt", newValue ?? ""); if (name === "fit") { if (newValue && [ "cover", "contain", "fill", "none", "scale-down" ].includes(newValue)) this._image.style.setProperty("object-fit", newValue); else this._image.style.removeProperty("object-fit"); } if (name === "aspect-ratio") { if (newValue) this._frame.style.setProperty("aspect-ratio", newValue); else this._frame.style.removeProperty("aspect-ratio"); } if (name === "caption") { this._caption.textContent = newValue ?? ""; this._caption.hidden = !newValue; } if (name === "fallback") this._syncFallback(); if (name === "loading") this._image.setAttribute("loading", newValue || "lazy"); if (name === "srcset" || name === "sizes") { if (newValue) this._image.setAttribute(name, newValue); else this._image.removeAttribute(name); } } _syncSource() { const src = this.src; if (src) { this._setState("loading"); this._image.setAttribute("src", src); if (this._image.complete && this._image.naturalWidth > 0) this._setState("loaded"); } else { this._image.removeAttribute("src"); this._setState("empty"); } } _syncFallback() { this._fallback.textContent = this.fallback || (this.state === "error" ? "Image unavailable" : "No image selected"); } _setState(state) { this.setAttribute("data-state", state); this._loading.hidden = state !== "loading"; this._fallback.hidden = state !== "empty" && state !== "error"; this._syncFallback(); } get state() { return this.getAttribute("data-state") ?? "empty"; } get src() { return this.getAttribute("src") ?? ""; } set src(value) { if (value == null || value === "") this.removeAttribute("src"); else this.setAttribute("src", String(value)); } get alt() { return this.getAttribute("alt") ?? ""; } set alt(value) { this.setAttribute("alt", String(value ?? "")); } get fit() { return this.getAttribute("fit") ?? "cover"; } set fit(value) { this.setAttribute("fit", String(value ?? "cover")); } get aspectRatio() { return this.getAttribute("aspect-ratio") ?? "16 / 9"; } set aspectRatio(value) { if (value == null || value === "") this.removeAttribute("aspect-ratio"); else this.setAttribute("aspect-ratio", String(value)); } get caption() { return this.getAttribute("caption") ?? ""; } set caption(value) { if (value == null || value === "") this.removeAttribute("caption"); else this.setAttribute("caption", String(value)); } get fallback() { return this.getAttribute("fallback") ?? ""; } set fallback(value) { if (value == null || value === "") this.removeAttribute("fallback"); else this.setAttribute("fallback", String(value)); } get loading() { return this.getAttribute("loading") ?? "lazy"; } set loading(value) { this.setAttribute("loading", String(value ?? "lazy")); } get srcset() { return this.getAttribute("srcset") ?? ""; } set srcset(value) { if (value == null || value === "") this.removeAttribute("srcset"); else this.setAttribute("srcset", String(value)); } get sizes() { return this.getAttribute("sizes") ?? ""; } set sizes(value) { if (value == null || value === "") this.removeAttribute("sizes"); else this.setAttribute("sizes", String(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } }; var BiscuitCarouselView = class extends HTMLElementBase { static get observedAttributes() { return ["value", "loop"]; } constructor() { super(); this._id = ++carouselViewId; this._slides = []; this._panels = []; this._dots = []; this._value = ""; this._selectedIndex = -1; this._pointerStart = null; const root = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = carouselViewStyles; this._viewport = document.createElement("div"); this._viewport.setAttribute("part", "viewport"); this._viewport.tabIndex = 0; this._viewport.addEventListener("keydown", (event) => this._onKeyDown(event)); this._viewport.addEventListener("pointerdown", (event) => this._onPointerDown(event)); this._viewport.addEventListener("pointerup", (event) => this._onPointerUp(event)); this._viewport.addEventListener("pointercancel", () => { this._pointerStart = null; }); this._controls = document.createElement("div"); this._controls.setAttribute("part", "controls"); this._previous = document.createElement("button"); this._previous.type = "button"; this._previous.setAttribute("part", "previous"); this._previous.setAttribute("aria-label", "Previous slide"); this._previous.textContent = "‹"; this._previous.addEventListener("click", () => this.previous()); this._dotList = document.createElement("div"); this._dotList.setAttribute("part", "dots"); this._next = document.createElement("button"); this._next.type = "button"; this._next.setAttribute("part", "next"); this._next.setAttribute("aria-label", "Next slide"); this._next.textContent = "›"; this._next.addEventListener("click", () => this.next()); this._controls.append(this._previous, this._dotList, this._next); this._status = document.createElement("div"); this._status.setAttribute("part", "status"); this._status.setAttribute("aria-live", "polite"); root.append(style, this._viewport, this._controls, this._status); } connectedCallback() { if (!this.hasAttribute("role")) this.setAttribute("role", "region"); if (!this.hasAttribute("aria-roledescription")) this.setAttribute("aria-roledescription", "carousel"); if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Carousel"); this._syncSlides(); if (globalThis.MutationObserver) { this._observer = new MutationObserver((mutations) => { if (mutations.some((mutation) => mutation.type === "childList" && mutation.target === this || mutation.type === "attributes" && mutation.target.parentElement === this)) this._syncSlides(); }); this._observer.observe(this, { childList: true, subtree: true, attributes: true, attributeFilter: [ "value", "label", "selected" ] }); } } disconnectedCallback() { this._observer?.disconnect(); this._observer = null; this._pointerStart = null; } attributeChangedCallback(name, oldValue, newValue) { if (oldValue !== newValue) this._applySelection(); } get value() { return this._value; } set value(value) { this.setAttribute("value", String(value ?? "")); } get selectedIndex() { return this._selectedIndex; } get loop() { return this.hasAttribute("loop"); } set loop(value) { this.toggleAttribute("loop", Boolean(value)); } get theme() { return this.getAttribute("theme") ?? "inherit"; } set theme(value) { if (value == null || value === "inherit") this.removeAttribute("theme"); else this.setAttribute("theme", String(value)); } next() { if (this._slides.length < 2) return; const next = this._selectedIndex + 1; if (next < this._slides.length) this._selectIndex(next); else if (this.loop) this._selectIndex(0); } previous() { if (this._slides.length < 2) return; const previous = this._selectedIndex - 1; if (previous >= 0) this._selectIndex(previous); else if (this.loop) this._selectIndex(this._slides.length - 1); } _syncSlides() { this._slides = Array.from(this.children).filter((child) => child.tagName === "BISCUIT-SLIDE").map((element, index) => ({ element, value: element.getAttribute("value") ?? `slide-${index + 1}`, label: element.getAttribute("label") ?? `Slide ${index + 1}`, selected: element.hasAttribute("selected") })); this._panels = this._slides.map((slide, index) => { slide.element.setAttribute("slot", `biscuit-slide-${this._id}-${index}`); const panel = document.createElement("div"); panel.setAttribute("part", "slide"); panel.setAttribute("role", "group"); panel.setAttribute("aria-roledescription", "slide"); panel.setAttribute("aria-label", `${index + 1} of ${this._slides.length}: ${slide.label}`); panel.id = `biscuit-carousel-slide-${this._id}-${index}`; const slot = document.createElement("slot"); slot.name = `biscuit-slide-${this._id}-${index}`; panel.append(slot); return panel; }); this._dots = this._slides.map((slide, index) => { const dot = document.createElement("button"); dot.type = "button"; dot.setAttribute("part", "dot"); dot.setAttribute("aria-label", `Go to ${slide.label}`); dot.setAttribute("aria-controls", `biscuit-carousel-slide-${this._id}-${index}`); dot.addEventListener("click", () => this._selectIndex(index)); return dot; }); this._viewport.replaceChildren(...this._panels); this._dotList.replaceChildren(...this._dots); this._applySelection(); } _applySelection() { const requested = this.getAttribute("value"); let index = requested === null ? this._slides.findIndex((slide) => slide.selected) : this._slides.findIndex((slide) => slide.value === requested); if (index < 0 && this._slides.length) index = 0; this._selectedIndex = index; this._value = index < 0 ? "" : this._slides[index].value; this._panels.forEach((panel, slideIndex) => { panel.hidden = slideIndex !== index; }); this._dots.forEach((dot, slideIndex) => { if (slideIndex === index) dot.setAttribute("aria-current", "true"); else dot.removeAttribute("aria-current"); }); this._controls.hidden = this._slides.length < 2; this._previous.disabled = index < 1 && !this.loop; this._next.disabled = (index < 0 || index >= this._slides.length - 1) && !this.loop; this._status.textContent = index < 0 ? "No slides" : `${index + 1} of ${this._slides.length}: ${this._slides[index].label}`; } _selectIndex(index) { if (index < 0 || index >= this._slides.length || index === this._selectedIndex) return; this.value = this._slides[index].value; this.dispatchEvent(new Event("change", { bubbles: true, composed: true })); } _onKeyDown(event) { if (event.target !== this._viewport) return; if (event.key === "ArrowRight") { event.preventDefault(); this.next(); } else if (event.key === "ArrowLeft") { event.preventDefault(); this.previous(); } else if (event.key === "Home") { event.preventDefault(); this._selectIndex(0); } else if (event.key === "End") { event.preventDefault(); this._selectIndex(this._slides.length - 1); } } _onPointerDown(event) { if (event.pointerType === "mouse") return; this._pointerStart = { x: event.clientX, y: event.clientY }; this._viewport.setPointerCapture?.(event.pointerId); } _onPointerUp(event) { if (!this._pointerStart) return; const dx = event.clientX - this._pointerStart.x; const dy = event.clientY - this._pointerStart.y; this._pointerStart = null; if (Math.abs(dx) < 50 || Math.abs(dx) <= Math.abs(dy) * 1.2) return; if (dx < 0) this.next(); else this.previous(); } }; function defineIconGridView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit IconGridView requires a browser with Custom Elements"); const existing = registry.get(ICONGRIDVIEW_TAG_NAME); if (existing && existing !== BiscuitIconGridView) throw new Error(`<${ICONGRIDVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(ICONGRIDVIEW_TAG_NAME, BiscuitIconGridView); return BiscuitIconGridView; } function defineFileBrowserView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit FileBrowserView requires a browser with Custom Elements"); const existing = registry.get(FILEBROWSERVIEW_TAG_NAME); if (existing && existing !== BiscuitFileBrowserView) throw new Error(`<${FILEBROWSERVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(FILEBROWSERVIEW_TAG_NAME, BiscuitFileBrowserView); return BiscuitFileBrowserView; } function defineImageView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit ImageView requires a browser with Custom Elements"); const existing = registry.get(IMAGEVIEW_TAG_NAME); if (existing && existing !== BiscuitImageView) throw new Error(`<${IMAGEVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(IMAGEVIEW_TAG_NAME, BiscuitImageView); return BiscuitImageView; } function defineCarouselView() { const registry = globalThis.customElements; if (!registry) throw new Error("Biscuit CarouselView requires a browser with Custom Elements"); const existing = registry.get(CAROUSELVIEW_TAG_NAME); if (existing && existing !== BiscuitCarouselView) throw new Error(`<${CAROUSELVIEW_TAG_NAME}> is already registered by another library`); if (!existing) registry.define(CAROUSELVIEW_TAG_NAME, BiscuitCarouselView); return BiscuitCarouselView; } function createIconGridView(options = {}) { if (!globalThis.document) throw new Error("Biscuit IconGridView requires a browser document"); defineIconGridView(); const element = createConfiguredElement(ICONGRIDVIEW_TAG_NAME, options); for (const key of [ "heading", "icons", "showLabels", "theme" ]) if (Object.hasOwn(options, key)) element[key] = options[key]; return element; } function createFileBrowserView(options = {}) { if (!globalThis.document) throw new Error("Biscuit FileBrowserView requires a browser document"); defineFileBrowserView(); const element = createConfiguredElement(FILEBROWSERVIEW_TAG_NAME, options); for (const key of [ "label", "items", "searchable", "value", "theme" ]) if (Object.hasOwn(options, key)) element[key] = options[key]; return element; } function createImageView(options = {}) { if (!globalThis.document) throw new Error("Biscuit ImageView requires a browser document"); defineImageView(); const element = createConfiguredElement(IMAGEVIEW_TAG_NAME, options); for (const name of [ "alt", "fit", "aspectRatio", "caption", "fallback", "loading", "srcset", "sizes", "theme" ]) if (Object.hasOwn(options, name)) element[name] = options[name]; if (Object.hasOwn(options, "src")) element.src = options.src; return element; } function createCarouselView(options = {}) { if (!globalThis.document) throw new Error("Biscuit CarouselView requires a browser document"); defineCarouselView(); const element = createConfiguredElement(CAROUSELVIEW_TAG_NAME, options); if (Object.hasOwn(options, "theme")) element.theme = options.theme; if (Object.hasOwn(options, "loop")) element.loop = options.loop; if (Object.hasOwn(options, "ariaLabel")) element.setAttribute("aria-label", String(options.ariaLabel)); for (const item of options.slides ?? []) { const slide = document.createElement("biscuit-slide"); if (Object.hasOwn(item, "value")) slide.setAttribute("value", String(item.value)); if (Object.hasOwn(item, "label")) slide.setAttribute("label", String(item.label)); if (item.selected) slide.setAttribute("selected", ""); if (item.content != null) slide.append(item.content); element.append(slide); } if (Object.hasOwn(options, "value")) element.value = options.value; element._syncSlides(); return element; } function defineMedia() { defineIconGridView(); defineFileBrowserView(); defineImageView(); defineCarouselView(); } // src/groups/code.js var code_exports = /* @__PURE__ */ __exportAll({ BiscuitCodeExampleView: () => BiscuitCodeExampleView, BiscuitCodeView: () => BiscuitCodeView, BiscuitCopyButtonView: () => BiscuitCopyButtonView, BiscuitSuggestionView: () => BiscuitSuggestionView, createCodeExampleView: () => createCodeExampleView, createCodeView: () => createCodeView, createCopyButtonView: () => createCopyButtonView, createSuggestionView: () => createSuggestionView, defineCode: () => defineCode, defineCodeExampleView: () => defineCodeExampleView, defineCodeView: () => defineCodeView, defineCopyButtonView: () => defineCopyButtonView, defineSuggestionView: () => defineSuggestionView, detectCodeLanguage: () => detectCodeLanguage, registerCodeCompletionProvider: () => registerCodeCompletionProvider, registerCodeLanguage: () => registerCodeLanguage, tokenizeCode: () => tokenizeCode }); var CODEVIEW_TAG_NAME = "biscuit-codeview"; var CODEVIEW_LARGE_FILE_LINE_LIMIT = 5e4; var JAVASCRIPT_COMPLETION_CONTEXT_CHARS = 32768; var CODEEXAMPLEVIEW_TAG_NAME = "biscuit-codeexampleview"; var COPYBUTTONVIEW_TAG_NAME = "biscuit-copybuttonview"; var SUGGESTIONVIEW_TAG_NAME = "biscuit-suggestionview"; var codeExampleViewId = 0; var codeCompletionId = 0; var codeLargeWarningId = 0; var codeLanguages = /* @__PURE__ */ new Map(); var codeLanguageAliases = /* @__PURE__ */ new Map(); var codeLanguageListeners = /* @__PURE__ */ new Set(); var codeCompletionProviders = /* @__PURE__ */ new Map(); function pushCodeToken(tokens, type, value) { if (!value) return; const previous = tokens[tokens.length - 1]; if (previous?.type === type) previous.text += value; else tokens.push({ type, text: value }); } function registerCodeLanguage(name, definition) { const key = String(name).toLowerCase(); if (!/^[a-z][a-z0-9-]*$/.test(key)) throw new TypeError("Invalid code language name"); if (!definition || !Array.isArray(definition.rules) && typeof definition.tokenizeLine !== "function") throw new TypeError("A code language needs rules or tokenizeLine"); const aliases = [key, ...(definition.aliases ?? []).map((alias) => String(alias).toLowerCase())]; for (const alias of aliases) if (!/^[a-z][a-z0-9-]*$/.test(alias) || codeLanguageAliases.has(alias)) throw new Error("Code language name or alias already registered: " + alias); const rules = definition.rules?.map(({ type, pattern }) => { if (!/^[a-z][a-z0-9-]*$/.test(type) || !(pattern instanceof RegExp)) throw new TypeError("Code rules need a type and RegExp pattern"); const flags = pattern.flags.replace(/[gy]/g, ""); const matcher = new RegExp("^(?:" + pattern.source + ")", flags); if (matcher.test("")) throw new TypeError("Code rules cannot match empty text"); return { type, matcher }; }); codeLanguages.set(key, { initialState: definition.initialState ?? "", tokenizeLine: definition.tokenizeLine, rules, detect: definition.detect }); for (const alias of aliases) codeLanguageAliases.set(alias, key); for (const listener of codeLanguageListeners) listener(); } function resolveCodeLanguage(language) { return codeLanguageAliases.get(String(language ?? "plain").toLowerCase()) ?? "plain"; } function scanCodeLine(line, language, state = "") { const definition = codeLanguages.get(resolveCodeLanguage(language)); if (!definition) return { tokens: line ? [{ type: "text", text: line }] : [], state: "" }; let result; if (definition.tokenizeLine) result = definition.tokenizeLine(line, state); else { const tokens = []; let index = 0; while (index < line.length) { let matched = false; for (const rule of definition.rules) { const match = rule.matcher.exec(line.slice(index)); if (!match) continue; pushCodeToken(tokens, rule.type, match[0]); index += match[0].length; matched = true; break; } if (!matched) pushCodeToken(tokens, "text", line[index++]); } result = { tokens, state }; } if (!result || !Array.isArray(result.tokens) || result.tokens.map((token) => token.text).join("") !== line) throw new Error("Code language tokenizer must preserve each line exactly"); return { tokens: result.tokens, state: result.state ?? "" }; } function detectCodeLanguage(source) { const sample = String(source ?? "").slice(0, 65536); if (!sample.trim()) return "plain"; let best = "plain"; let bestScore = 0; let nextScore = 0; for (const [name, definition] of codeLanguages) { if (!definition.detect || name === "plain") continue; let score = 0; try { score = Number(definition.detect(sample)) || 0; } catch {} if (score > bestScore) { nextScore = bestScore; bestScore = score; best = name; } else if (score > nextScore) nextScore = score; } return bestScore >= .65 && bestScore - nextScore >= .15 ? best : "plain"; } function tokenizeCode(source, language = "plain") { const value = String(source ?? ""); const selected = String(language).toLowerCase() === "auto" ? detectCodeLanguage(value) : language; const tokens = []; let state = codeLanguages.get(resolveCodeLanguage(selected))?.initialState ?? ""; let start = 0; while (start < value.length) { let end = start; while (end < value.length && value[end] !== "\n" && value[end] !== "\r") end++; const result = scanCodeLine(value.slice(start, end), selected, state); for (const token of result.tokens) pushCodeToken(tokens, token.type, token.text); state = result.state; const breakEnd = value[end] === "\r" && value[end + 1] === "\n" ? end + 2 : Math.min(end + 1, value.length); pushCodeToken(tokens, "text", value.slice(end, breakEnd)); start = breakEnd; } return tokens; } var javascriptWords = new Set("async await break case catch class const continue debugger default delete do else export extends false finally for from function get if import in instanceof let new null of return set static super switch this throw true try typeof undefined var void while yield".split(" ")); var javaWords = new Set("abstract assert boolean break byte case catch char class const continue default do double else enum extends false final finally float for if implements import instanceof int interface long native new null package private protected public record return sealed permits short static strictfp super switch synchronized this throw throws transient true try var void volatile while yield".split(" ")); function consumeCodeQuote(line, index, quote) { let cursor = index + quote.length; while (cursor < line.length) { if (line[cursor] === "\\") { cursor += 2; continue; } if (line.startsWith(quote, cursor)) return { end: cursor + quote.length, closed: true }; cursor++; } return { end: line.length, closed: false }; } function scanScriptCodeLine(line, previousState, java = false) { const tokens = []; let index = 0; let state = previousState || ""; while (index < line.length) { if (state === "comment") { const end = line.indexOf("*/", index); const stop = end < 0 ? line.length : end + 2; pushCodeToken(tokens, "comment", line.slice(index, stop)); index = stop; if (end >= 0) state = ""; continue; } if (state.startsWith("quote:")) { const quote = state.slice(6); const result = consumeCodeQuote(line, index - quote.length, quote); const stop = Math.max(index, result.end); pushCodeToken(tokens, "string", line.slice(index, stop)); index = stop; if (result.closed) state = ""; continue; } if (line.startsWith("//", index)) { pushCodeToken(tokens, "comment", line.slice(index)); break; } if (line.startsWith("/*", index)) { state = "comment"; continue; } const quote = java && line.startsWith("\"\"\"", index) ? "\"\"\"" : line[index]; if (quote === "'" || quote === "\"" || !java && quote === "`" || quote === "\"\"\"") { const result = consumeCodeQuote(line, index, quote); pushCodeToken(tokens, "string", line.slice(index, result.end)); index = result.end; if (!result.closed && (quote === "`" || quote === "\"\"\"" || line.endsWith("\\"))) state = "quote:" + quote; continue; } const number = /^(?:0[xX][\da-fA-F]+|0[bB][01]+|\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)[fFdDlLnN]?/.exec(line.slice(index)); if (number) { pushCodeToken(tokens, "number", number[0]); index += number[0].length; continue; } const identifier = /^[A-Za-z_$][\w$]*/.exec(line.slice(index)); if (identifier) { pushCodeToken(tokens, (java ? javaWords : javascriptWords).has(identifier[0]) ? "keyword" : "text", identifier[0]); index += identifier[0].length; continue; } pushCodeToken(tokens, /[+*\/%=&|!<>?:~-]/.test(line[index]) ? "operator" : "text", line[index++]); } return { tokens, state }; } function scanCssCodeLine(line, previousState) { const tokens = []; const pieces = (previousState || "0|0|0").split("|"); let comment = pieces[0] === "1"; let depth = Number(pieces[1]) || 0; let value = pieces[2] === "1"; let quote = pieces[3] || ""; let index = 0; while (index < line.length) { if (comment) { const end = line.indexOf("*/", index); const stop = end < 0 ? line.length : end + 2; pushCodeToken(tokens, "comment", line.slice(index, stop)); index = stop; if (end >= 0) comment = false; continue; } if (quote) { const result = consumeCodeQuote(line, index - 1, quote); pushCodeToken(tokens, "string", line.slice(index, result.end)); index = result.end; if (result.closed) quote = ""; continue; } if (line.startsWith("/*", index)) { comment = true; continue; } if (line[index] === "'" || line[index] === "\"") { const result = consumeCodeQuote(line, index, line[index]); pushCodeToken(tokens, "string", line.slice(index, result.end)); quote = result.closed ? "" : line[index]; index = result.end; continue; } if (line[index] === "{") { pushCodeToken(tokens, "operator", "{"); depth++; value = false; index++; continue; } if (line[index] === "}") { pushCodeToken(tokens, "operator", "}"); depth = Math.max(0, depth - 1); value = false; index++; continue; } if (line[index] === ":") { pushCodeToken(tokens, "operator", ":"); if (depth) value = true; index++; continue; } if (line[index] === ";") { pushCodeToken(tokens, "operator", ";"); value = false; index++; continue; } const at = /^@[\w-]+/.exec(line.slice(index)); if (at) { pushCodeToken(tokens, "at-rule", at[0]); index += at[0].length; continue; } const word = /^(?:--[\w-]+|[\w.-]+)/.exec(line.slice(index)); if (word) { pushCodeToken(tokens, !depth ? "selector" : value ? /^\d/.test(word[0]) ? "number" : "text" : "property", word[0]); index += word[0].length; continue; } pushCodeToken(tokens, !depth ? "selector" : "text", line[index++]); } return { tokens, state: [ comment ? 1 : 0, depth, value ? 1 : 0, quote ].join("|") }; } function scanHtmlCodeLine(line, previousState) { const tokens = []; const state = previousState ? JSON.parse(previousState) : { mode: "text", tag: "", quote: "", embedded: "" }; let index = 0; while (index < line.length) { if (state.mode === "script" || state.mode === "style") { const match = new RegExp("", index); const stop = end < 0 ? line.length : end + 3; pushCodeToken(tokens, "comment", line.slice(index, stop)); index = stop; if (end >= 0) state.mode = "text"; continue; } if (state.mode === "tag") { if (state.quote) { const result = consumeCodeQuote(line, index - 1, state.quote); pushCodeToken(tokens, "string", line.slice(index, result.end)); index = result.end; if (result.closed) state.quote = ""; continue; } const character = line[index]; if (character === "'" || character === "\"") { const result = consumeCodeQuote(line, index, character); pushCodeToken(tokens, "string", line.slice(index, result.end)); state.quote = result.closed ? "" : character; index = result.end; } else if (character === ">") { pushCodeToken(tokens, "operator", ">"); index++; state.mode = state.tag === "script" || state.tag === "style" ? state.tag : "text"; state.tag = ""; } else { const attr = /^[\w:-]+/.exec(line.slice(index)); if (attr) { pushCodeToken(tokens, "attribute", attr[0]); index += attr[0].length; } else { pushCodeToken(tokens, /[=\/]/.test(character) ? "operator" : "text", character); index++; } } continue; } if (line.startsWith("