@f-ewald/components 1.27.1 → 1.27.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +95 -3
- package/dist/calendar-day.d.ts +22 -0
- package/dist/calendar-day.d.ts.map +1 -1
- package/dist/calendar-day.js +153 -13
- package/dist/calendar-day.js.map +1 -1
- package/dist/calendar-entry.d.ts +1 -0
- package/dist/calendar-entry.d.ts.map +1 -1
- package/dist/calendar-entry.js +2 -1
- package/dist/calendar-entry.js.map +1 -1
- package/dist/calendar-month.d.ts +4 -3
- package/dist/calendar-month.d.ts.map +1 -1
- package/dist/calendar-month.js +61 -10
- package/dist/calendar-month.js.map +1 -1
- package/dist/calendar-week.d.ts +1 -0
- package/dist/calendar-week.d.ts.map +1 -1
- package/dist/calendar-week.js +57 -13
- package/dist/calendar-week.js.map +1 -1
- package/dist/utils/calendar.d.ts +1 -0
- package/dist/utils/calendar.d.ts.map +1 -1
- package/dist/utils/calendar.js +2 -0
- package/dist/utils/calendar.js.map +1 -1
- package/docs/calendar-day.md +8 -1
- package/docs/calendar-entry.md +2 -0
- package/docs/calendar-month.md +4 -0
- package/docs/calendar-week.md +6 -1
- package/llms.txt +12 -5
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calendar.js","sourceRoot":"","sources":["../../src/utils/calendar.ts"],"names":[],"mappings":"AAyBA,MAAM,gBAAgB,GAAG,2BAA2B,CAAC;AACrD,MAAM,oBAAoB,GAAG,2CAA2C,CAAC;AAEzE,uEAAuE;AACvE,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5F,uEAAuE;AACvE,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,KAAa;IACrD,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CA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,CAAC;AACJ,CAAC","sourcesContent":["import type { StatusPillColor } from \"../status-pill.js\";\nimport type { CalendarEntry } from \"../calendar-entry.js\";\n\n/** Plain data extracted from a `calendar-entry` element's properties. */\nexport interface CalendarEntryData {\n start: string;\n end: string;\n label: string;\n details?: string[];\n footer?: string;\n color: StatusPillColor;\n href?: string;\n}\n\n/** A `CalendarEntryData` with its date strings resolved to local `Date`s. */\nexport interface ResolvedCalendarEntry extends CalendarEntryData {\n startDate: Date;\n endDate: Date;\n}\n\n/** A `ResolvedCalendarEntry` assigned a stacking column by `assignLanes`. */\nexport interface LanedEntry extends ResolvedCalendarEntry {\n lane: number;\n}\n\nconst ISO_DATE_PATTERN = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\nconst ISO_DATETIME_PATTERN = /^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2})$/;\n\n/** Attributes whose mutations can change a rendered calendar entry. */\nexport const CALENDAR_ENTRY_ATTRIBUTES = [\"start\", \"end\", \"label\", \"color\", \"href\", \"slot\"];\n\n/** Number of days in `month` (1-12) of `year`, leap years included. */\nexport function daysInMonth(year: number, month: number): number {\n return new Date(year, month, 0).getDate();\n}\n\n/**\n * Parses `\"YYYY-MM-DD\"` as a local-midnight `Date`. Returns `null` for\n * anything that doesn't match or doesn't round-trip (e.g. \"2026-02-30\") —\n * deliberately never uses `new Date(iso)`/`.toISOString()`, both of which\n * are UTC-based and would silently shift the date in negative-UTC-offset\n * timezones.\n */\nexport function parseIsoDate(iso: string): Date | null {\n const match = ISO_DATE_PATTERN.exec(iso);\n if (!match) return null;\n\n const year = Number(match[1]);\n const month = Number(match[2]);\n const day = Number(match[3]);\n const date = new Date(year, month - 1, day);\n if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {\n return null;\n }\n return date;\n}\n\n/** Formats a `Date`'s local year/month/day as `\"YYYY-MM-DD\"`. */\nexport function toIsoDate(date: Date): string {\n const year = String(date.getFullYear()).padStart(4, \"0\");\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n return `${year}-${month}-${day}`;\n}\n\nconst monthNameFormatter = new Intl.DateTimeFormat(undefined, { month: \"long\" });\n\n/** Locale-aware full month name for `month` (1-12). */\nexport function monthName(month: number): string {\n return monthNameFormatter.format(new Date(2000, month - 1, 1));\n}\n\n/** Sunday-first weekday abbreviations, indexed by `Date.getDay()` (0 = Sunday). */\nexport const WEEKDAY_ABBR: readonly string[] = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\n\n/**\n * Whether `date` falls on a Saturday or Sunday, per JS's `Date.getDay()`\n * convention (Sunday = 0 .. Saturday = 6) — note this differs from Python's\n * `calendar` module (Monday = 0), which the original reference\n * implementation this component's layout is based on used.\n */\nexport function isWeekend(date: Date): boolean {\n const day = date.getDay();\n return day === 0 || day === 6;\n}\n\n/** Reads normalized plain-text content from direct children assigned to a named slot. */\nfunction slottedText(el: CalendarEntry, slotName: string): string[] {\n return Array.from(el.querySelectorAll<HTMLElement>(`:scope > [slot=\"${slotName}\"]`))\n .map((node) => (node.textContent ?? \"\").replace(/\\s+/g, \" \").trim());\n}\n\n/** Reads a `calendar-entry` element's properties and named text slots into plain data. */\nexport function readCalendarEntryElement(el: CalendarEntry): CalendarEntryData {\n const title = slottedText(el, \"title\").find((line) => line.length > 0);\n const footer = slottedText(el, \"footer\").find((line) => line.length > 0);\n return {\n start: el.start,\n end: el.end,\n label: title ?? el.label,\n details: slottedText(el, \"detail\"),\n footer,\n color: el.color,\n href: el.href,\n };\n}\n\n/**\n * Resolves a `CalendarEntryData`'s date strings to `Date`s. Returns `null`\n * when `start` is missing or unparseable — such entries are dropped\n * silently rather than thrown, since this reads declarative markup a\n * consumer authored, not validated user input. A blank `end` defaults to\n * `start` (single-day entry); an `end` before `start` is clamped up to\n * `start` rather than treated as an error.\n */\nexport function resolveEntry(data: CalendarEntryData): ResolvedCalendarEntry | null {\n const startDate = parseIsoDate(data.start);\n if (!startDate) return null;\n\n const endDate = parseIsoDate(data.end) ?? startDate;\n return {\n ...data,\n details: data.details ?? [],\n startDate,\n endDate: endDate < startDate ? startDate : endDate,\n };\n}\n\n/** Whether `entry`'s inclusive date range intersects the inclusive `[rangeStart, rangeEnd]` range. */\nexport function overlapsRange(entry: ResolvedCalendarEntry, rangeStart: Date, rangeEnd: Date): boolean {\n return entry.startDate <= rangeEnd && entry.endDate >= rangeStart;\n}\n\n/**\n * Assigns each entry a 0-based stacking lane via greedy interval\n * partitioning (\"meeting rooms II\"): entries are sorted by start date, then\n * each is placed in the lowest-numbered lane whose current occupant ends\n * strictly before the entry starts. Because entry ranges are\n * inclusive-inclusive, an entry ending on day X and one starting on day X\n * both occupy day X and must not share a lane — hence the strict `<`.\n *\n * Lane assignment is meant to be computed independently per `calendar-month`\n * (from only the entries overlapping that month); an entry spanning a month\n * boundary may therefore land in a different lane in adjacent months. This\n * is an accepted v1 limitation, not a bug.\n */\nexport function assignLanes(entries: ResolvedCalendarEntry[]): {\n entries: LanedEntry[];\n laneCount: number;\n} {\n const sorted = entries\n .map((entry, index) => ({ entry, index }))\n .sort((a, b) => {\n const startDiff = a.entry.startDate.getTime() - b.entry.startDate.getTime();\n if (startDiff !== 0) return startDiff;\n const endDiff = a.entry.endDate.getTime() - b.entry.endDate.getTime();\n if (endDiff !== 0) return endDiff;\n return a.index - b.index;\n });\n\n const laneEnds: Date[] = [];\n const laned: LanedEntry[] = [];\n for (const { entry } of sorted) {\n let lane = laneEnds.findIndex((end) => end < entry.startDate);\n if (lane === -1) {\n lane = laneEnds.length;\n laneEnds.push(entry.endDate);\n } else {\n laneEnds[lane] = entry.endDate;\n }\n laned.push({ ...entry, lane });\n }\n\n return { entries: laned, laneCount: laneEnds.length };\n}\n\n/** Adds `days` (negative to subtract) to `date`, returning a new local `Date`. */\nexport function addDays(date: Date, days: number): Date {\n const result = new Date(date);\n result.setDate(result.getDate() + days);\n return result;\n}\n\n/** The Sunday (local midnight) of the week containing `date`, per `WEEKDAY_ABBR`'s Sunday-first convention. */\nexport function startOfWeek(date: Date): Date {\n return addDays(date, -date.getDay());\n}\n\n/** Minutes elapsed since local midnight on `date`'s day, for hour-grid vertical positioning. */\nexport function minutesSinceMidnight(date: Date): number {\n return date.getHours() * 60 + date.getMinutes();\n}\n\n/** Whether `iso` carries a time-of-day component (`\"YYYY-MM-DDTHH:MM\"`) rather than being date-only. */\nexport function hasTimeComponent(iso: string): boolean {\n return ISO_DATETIME_PATTERN.test(iso);\n}\n\n/**\n * Parses `\"YYYY-MM-DDTHH:MM\"` as a local `Date`, falling back to\n * `parseIsoDate` (local midnight) for a plain `\"YYYY-MM-DD\"` string. Returns\n * `null` for anything else, including a datetime whose components don't\n * round-trip (e.g. an invalid hour).\n */\nexport function parseIsoDateTime(iso: string): Date | null {\n const match = ISO_DATETIME_PATTERN.exec(iso);\n if (!match) return parseIsoDate(iso);\n\n const year = Number(match[1]);\n const month = Number(match[2]);\n const day = Number(match[3]);\n const hours = Number(match[4]);\n const minutes = Number(match[5]);\n const date = new Date(year, month - 1, day, hours, minutes);\n if (\n date.getFullYear() !== year ||\n date.getMonth() !== month - 1 ||\n date.getDate() !== day ||\n date.getHours() !== hours ||\n date.getMinutes() !== minutes\n ) {\n return null;\n }\n return date;\n}\n\n/**\n * A `CalendarEntryData` resolved for hour-grid (`calendar-day`/`calendar-week`)\n * rendering. Reuses the `startDate`/`endDate` field names from\n * `ResolvedCalendarEntry` so it stays structurally compatible with\n * `assignLanes`/`overlapsRange` — both operate purely on those two `Date`\n * fields via `.getTime()`, which already generalizes correctly to sub-day\n * time granularity and multi-day ranges with no changes needed.\n */\nexport interface ResolvedTimedEntry extends CalendarEntryData {\n startDate: Date;\n endDate: Date;\n /** True when neither `start` nor `end` carries a time-of-day component. */\n allDay: boolean;\n}\n\n/**\n * Resolves a `CalendarEntryData`'s date/datetime strings for hour-grid\n * rendering. Returns `null` when `start` is missing or unparseable. A blank\n * `end` defaults to `start`; when `start` has a time but `end` doesn't (or is\n * blank), `end` defaults to one hour after `start` rather than clamping to\n * `start`'s instant, so a timed entry with no explicit end still renders as\n * a visible block. `allDay` is true only when neither endpoint carries a\n * time-of-day component — this is a separate, additive resolution path from\n * `resolveEntry`/`ResolvedCalendarEntry`, which stay date-only and are used\n * unchanged by `calendar-month`/`calendar-year`.\n */\nexport function resolveTimedEntry(data: CalendarEntryData): ResolvedTimedEntry | null {\n const startDate = parseIsoDateTime(data.start);\n if (!startDate) return null;\n\n const startHasTime = hasTimeComponent(data.start);\n const endHasTime = hasTimeComponent(data.end);\n const allDay = !startHasTime && !endHasTime;\n\n let endDate = data.end ? parseIsoDateTime(data.end) : null;\n if (!endDate) {\n endDate = startHasTime ? new Date(startDate.getTime() + 60 * 60 * 1000) : startDate;\n }\n\n return {\n ...data,\n details: data.details ?? [],\n startDate,\n endDate: endDate < startDate ? startDate : endDate,\n allDay,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"calendar.js","sourceRoot":"","sources":["../../src/utils/calendar.ts"],"names":[],"mappings":"AA0BA,MAAM,gBAAgB,GAAG,2BAA2B,CAAC;AACrD,MAAM,oBAAoB,GAAG,2CAA2C,CAAC;AAEzE,uEAAuE;AACvE,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5F,uEAAuE;AACvE,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,KAAa;IACrD,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AAC5C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAExB,MAA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-pill.js\";\nimport type { CalendarEntry } from \"../calendar-entry.js\";\n\n/** Plain data extracted from a `calendar-entry` element's properties. */\nexport interface CalendarEntryData {\n start: string;\n end: string;\n label: string;\n details?: string[];\n footer?: string;\n location?: string;\n color: StatusPillColor;\n href?: string;\n}\n\n/** A `CalendarEntryData` with its date strings resolved to local `Date`s. */\nexport interface ResolvedCalendarEntry extends CalendarEntryData {\n startDate: Date;\n endDate: Date;\n}\n\n/** A `ResolvedCalendarEntry` assigned a stacking column by `assignLanes`. */\nexport interface LanedEntry extends ResolvedCalendarEntry {\n lane: number;\n}\n\nconst ISO_DATE_PATTERN = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\nconst ISO_DATETIME_PATTERN = /^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2})$/;\n\n/** Attributes whose mutations can change a rendered calendar entry. */\nexport const CALENDAR_ENTRY_ATTRIBUTES = [\"start\", \"end\", \"label\", \"color\", \"href\", \"slot\"];\n\n/** Number of days in `month` (1-12) of `year`, leap years included. */\nexport function daysInMonth(year: number, month: number): number {\n return new Date(year, month, 0).getDate();\n}\n\n/**\n * Parses `\"YYYY-MM-DD\"` as a local-midnight `Date`. Returns `null` for\n * anything that doesn't match or doesn't round-trip (e.g. \"2026-02-30\") —\n * deliberately never uses `new Date(iso)`/`.toISOString()`, both of which\n * are UTC-based and would silently shift the date in negative-UTC-offset\n * timezones.\n */\nexport function parseIsoDate(iso: string): Date | null {\n const match = ISO_DATE_PATTERN.exec(iso);\n if (!match) return null;\n\n const year = Number(match[1]);\n const month = Number(match[2]);\n const day = Number(match[3]);\n const date = new Date(year, month - 1, day);\n if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {\n return null;\n }\n return date;\n}\n\n/** Formats a `Date`'s local year/month/day as `\"YYYY-MM-DD\"`. */\nexport function toIsoDate(date: Date): string {\n const year = String(date.getFullYear()).padStart(4, \"0\");\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n return `${year}-${month}-${day}`;\n}\n\nconst monthNameFormatter = new Intl.DateTimeFormat(undefined, { month: \"long\" });\n\n/** Locale-aware full month name for `month` (1-12). */\nexport function monthName(month: number): string {\n return monthNameFormatter.format(new Date(2000, month - 1, 1));\n}\n\n/** Sunday-first weekday abbreviations, indexed by `Date.getDay()` (0 = Sunday). */\nexport const WEEKDAY_ABBR: readonly string[] = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\n\n/**\n * Whether `date` falls on a Saturday or Sunday, per JS's `Date.getDay()`\n * convention (Sunday = 0 .. Saturday = 6) — note this differs from Python's\n * `calendar` module (Monday = 0), which the original reference\n * implementation this component's layout is based on used.\n */\nexport function isWeekend(date: Date): boolean {\n const day = date.getDay();\n return day === 0 || day === 6;\n}\n\n/** Reads normalized plain-text content from direct children assigned to a named slot. */\nfunction slottedText(el: CalendarEntry, slotName: string): string[] {\n return Array.from(el.querySelectorAll<HTMLElement>(`:scope > [slot=\"${slotName}\"]`))\n .map((node) => (node.textContent ?? \"\").replace(/\\s+/g, \" \").trim());\n}\n\n/** Reads a `calendar-entry` element's properties and named text slots into plain data. */\nexport function readCalendarEntryElement(el: CalendarEntry): CalendarEntryData {\n const title = slottedText(el, \"title\").find((line) => line.length > 0);\n const footer = slottedText(el, \"footer\").find((line) => line.length > 0);\n const location = slottedText(el, \"location\").find((line) => line.length > 0);\n return {\n start: el.start,\n end: el.end,\n label: title ?? el.label,\n details: slottedText(el, \"detail\"),\n footer,\n location,\n color: el.color,\n href: el.href,\n };\n}\n\n/**\n * Resolves a `CalendarEntryData`'s date strings to `Date`s. Returns `null`\n * when `start` is missing or unparseable — such entries are dropped\n * silently rather than thrown, since this reads declarative markup a\n * consumer authored, not validated user input. A blank `end` defaults to\n * `start` (single-day entry); an `end` before `start` is clamped up to\n * `start` rather than treated as an error.\n */\nexport function resolveEntry(data: CalendarEntryData): ResolvedCalendarEntry | null {\n const startDate = parseIsoDate(data.start);\n if (!startDate) return null;\n\n const endDate = parseIsoDate(data.end) ?? startDate;\n return {\n ...data,\n details: data.details ?? [],\n startDate,\n endDate: endDate < startDate ? startDate : endDate,\n };\n}\n\n/** Whether `entry`'s inclusive date range intersects the inclusive `[rangeStart, rangeEnd]` range. */\nexport function overlapsRange(entry: ResolvedCalendarEntry, rangeStart: Date, rangeEnd: Date): boolean {\n return entry.startDate <= rangeEnd && entry.endDate >= rangeStart;\n}\n\n/**\n * Assigns each entry a 0-based stacking lane via greedy interval\n * partitioning (\"meeting rooms II\"): entries are sorted by start date, then\n * each is placed in the lowest-numbered lane whose current occupant ends\n * strictly before the entry starts. Because entry ranges are\n * inclusive-inclusive, an entry ending on day X and one starting on day X\n * both occupy day X and must not share a lane — hence the strict `<`.\n *\n * Lane assignment is meant to be computed independently per `calendar-month`\n * (from only the entries overlapping that month); an entry spanning a month\n * boundary may therefore land in a different lane in adjacent months. This\n * is an accepted v1 limitation, not a bug.\n */\nexport function assignLanes(entries: ResolvedCalendarEntry[]): {\n entries: LanedEntry[];\n laneCount: number;\n} {\n const sorted = entries\n .map((entry, index) => ({ entry, index }))\n .sort((a, b) => {\n const startDiff = a.entry.startDate.getTime() - b.entry.startDate.getTime();\n if (startDiff !== 0) return startDiff;\n const endDiff = a.entry.endDate.getTime() - b.entry.endDate.getTime();\n if (endDiff !== 0) return endDiff;\n return a.index - b.index;\n });\n\n const laneEnds: Date[] = [];\n const laned: LanedEntry[] = [];\n for (const { entry } of sorted) {\n let lane = laneEnds.findIndex((end) => end < entry.startDate);\n if (lane === -1) {\n lane = laneEnds.length;\n laneEnds.push(entry.endDate);\n } else {\n laneEnds[lane] = entry.endDate;\n }\n laned.push({ ...entry, lane });\n }\n\n return { entries: laned, laneCount: laneEnds.length };\n}\n\n/** Adds `days` (negative to subtract) to `date`, returning a new local `Date`. */\nexport function addDays(date: Date, days: number): Date {\n const result = new Date(date);\n result.setDate(result.getDate() + days);\n return result;\n}\n\n/** The Sunday (local midnight) of the week containing `date`, per `WEEKDAY_ABBR`'s Sunday-first convention. */\nexport function startOfWeek(date: Date): Date {\n return addDays(date, -date.getDay());\n}\n\n/** Minutes elapsed since local midnight on `date`'s day, for hour-grid vertical positioning. */\nexport function minutesSinceMidnight(date: Date): number {\n return date.getHours() * 60 + date.getMinutes();\n}\n\n/** Whether `iso` carries a time-of-day component (`\"YYYY-MM-DDTHH:MM\"`) rather than being date-only. */\nexport function hasTimeComponent(iso: string): boolean {\n return ISO_DATETIME_PATTERN.test(iso);\n}\n\n/**\n * Parses `\"YYYY-MM-DDTHH:MM\"` as a local `Date`, falling back to\n * `parseIsoDate` (local midnight) for a plain `\"YYYY-MM-DD\"` string. Returns\n * `null` for anything else, including a datetime whose components don't\n * round-trip (e.g. an invalid hour).\n */\nexport function parseIsoDateTime(iso: string): Date | null {\n const match = ISO_DATETIME_PATTERN.exec(iso);\n if (!match) return parseIsoDate(iso);\n\n const year = Number(match[1]);\n const month = Number(match[2]);\n const day = Number(match[3]);\n const hours = Number(match[4]);\n const minutes = Number(match[5]);\n const date = new Date(year, month - 1, day, hours, minutes);\n if (\n date.getFullYear() !== year ||\n date.getMonth() !== month - 1 ||\n date.getDate() !== day ||\n date.getHours() !== hours ||\n date.getMinutes() !== minutes\n ) {\n return null;\n }\n return date;\n}\n\n/**\n * A `CalendarEntryData` resolved for hour-grid (`calendar-day`/`calendar-week`)\n * rendering. Reuses the `startDate`/`endDate` field names from\n * `ResolvedCalendarEntry` so it stays structurally compatible with\n * `assignLanes`/`overlapsRange` — both operate purely on those two `Date`\n * fields via `.getTime()`, which already generalizes correctly to sub-day\n * time granularity and multi-day ranges with no changes needed.\n */\nexport interface ResolvedTimedEntry extends CalendarEntryData {\n startDate: Date;\n endDate: Date;\n /** True when neither `start` nor `end` carries a time-of-day component. */\n allDay: boolean;\n}\n\n/**\n * Resolves a `CalendarEntryData`'s date/datetime strings for hour-grid\n * rendering. Returns `null` when `start` is missing or unparseable. A blank\n * `end` defaults to `start`; when `start` has a time but `end` doesn't (or is\n * blank), `end` defaults to one hour after `start` rather than clamping to\n * `start`'s instant, so a timed entry with no explicit end still renders as\n * a visible block. `allDay` is true only when neither endpoint carries a\n * time-of-day component — this is a separate, additive resolution path from\n * `resolveEntry`/`ResolvedCalendarEntry`, which stay date-only and are used\n * unchanged by `calendar-month`/`calendar-year`.\n */\nexport function resolveTimedEntry(data: CalendarEntryData): ResolvedTimedEntry | null {\n const startDate = parseIsoDateTime(data.start);\n if (!startDate) return null;\n\n const startHasTime = hasTimeComponent(data.start);\n const endHasTime = hasTimeComponent(data.end);\n const allDay = !startHasTime && !endHasTime;\n\n let endDate = data.end ? parseIsoDateTime(data.end) : null;\n if (!endDate) {\n endDate = startHasTime ? new Date(startDate.getTime() + 60 * 60 * 1000) : startDate;\n }\n\n return {\n ...data,\n details: data.details ?? [],\n startDate,\n endDate: endDate < startDate ? startDate : endDate,\n allDay,\n };\n}\n"]}
|
package/docs/calendar-day.md
CHANGED
|
@@ -21,11 +21,12 @@ import "@f-ewald/components/calendar-day.js";
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
23
|
```html
|
|
24
|
-
<calendar-day date="2026-07-15">
|
|
24
|
+
<calendar-day date="2026-07-15" time-marker>
|
|
25
25
|
<calendar-entry start="2026-07-15" end="2026-07-15" label="Company holiday" color="neutral"></calendar-entry>
|
|
26
26
|
<calendar-entry start="2026-07-15T09:00" end="2026-07-15T09:30" label="Standup" color="info"></calendar-entry>
|
|
27
27
|
<calendar-entry start="2026-07-15T09:15" end="2026-07-15T10:00" label="Design review" color="primary" href="#review">
|
|
28
28
|
<span slot="detail">Walk through the new onboarding flow</span>
|
|
29
|
+
<span slot="location">Room A</span>
|
|
29
30
|
</calendar-entry>
|
|
30
31
|
</calendar-day>
|
|
31
32
|
```
|
|
@@ -35,6 +36,8 @@ import "@f-ewald/components/calendar-day.js";
|
|
|
35
36
|
| Property | Attribute | Type | Default | Description |
|
|
36
37
|
| --- | --- | --- | --- | --- |
|
|
37
38
|
| `date` | `date` | `string` | `—` | The day shown, `"YYYY-MM-DD"`. |
|
|
39
|
+
| `timeMarker` | `time-marker` | `boolean` | `false` | Shows a fine live line marking the current time, Google-Calendar-style. Only rendered when `date` is today. |
|
|
40
|
+
| `minWidth` | `min-width` | `string` | `""` | Minimum width for the day column, as a CSS length (e.g. `"18rem"`). Unset leaves the host's width fully controlled by its container — useful as the sizing floor when placing several `calendar-day` elements in a scrollable row. |
|
|
38
41
|
|
|
39
42
|
## Events
|
|
40
43
|
|
|
@@ -45,6 +48,7 @@ _None._
|
|
|
45
48
|
| Slot | Description |
|
|
46
49
|
| --- | --- |
|
|
47
50
|
| `(default)` | Declarative `calendar-entry` elements to render for this day. |
|
|
51
|
+
| `actions` | Optional controls rendered beside the day name (e.g. day-navigation buttons). |
|
|
48
52
|
|
|
49
53
|
## CSS custom properties
|
|
50
54
|
|
|
@@ -56,7 +60,9 @@ _None._
|
|
|
56
60
|
| `--ui-font` |
|
|
57
61
|
| `--ui-font-size-lg` |
|
|
58
62
|
| `--ui-font-size-sm` |
|
|
63
|
+
| `--ui-font-size-xs` |
|
|
59
64
|
| `--ui-font-weight-medium` |
|
|
65
|
+
| `--ui-font-weight-regular` |
|
|
60
66
|
| `--ui-font-weight-semibold` |
|
|
61
67
|
| `--ui-hover-overlay` |
|
|
62
68
|
| `--ui-info` |
|
|
@@ -65,6 +71,7 @@ _None._
|
|
|
65
71
|
| `--ui-radius-sm` |
|
|
66
72
|
| `--ui-success` |
|
|
67
73
|
| `--ui-surface` |
|
|
74
|
+
| `--ui-surface-muted` |
|
|
68
75
|
| `--ui-text` |
|
|
69
76
|
| `--ui-text-muted` |
|
|
70
77
|
| `--ui-warning` |
|
package/docs/calendar-entry.md
CHANGED
|
@@ -20,6 +20,7 @@ import "@f-ewald/components/calendar-entry.js";
|
|
|
20
20
|
color="success"
|
|
21
21
|
>
|
|
22
22
|
<span slot="title">Vacation</span>
|
|
23
|
+
<span slot="location">Beach house</span>
|
|
23
24
|
<span slot="detail">Out of office</span>
|
|
24
25
|
<span slot="detail">Road trip along the California coast with several scenic stops</span>
|
|
25
26
|
<span slot="footer">Return July 19 at 6 PM</span>
|
|
@@ -47,6 +48,7 @@ _None._
|
|
|
47
48
|
| `title` | Plain-text title shown instead of the `label` fallback. |
|
|
48
49
|
| `detail` | Repeatable plain-text details rendered inside the shared body spanning all remaining days. |
|
|
49
50
|
| `footer` | Plain-text ending note pinned to the bottom of the shared body. |
|
|
51
|
+
| `location` | Plain-text location, shown on its own line with a leading marker icon. |
|
|
50
52
|
|
|
51
53
|
## CSS custom properties
|
|
52
54
|
|
package/docs/calendar-month.md
CHANGED
|
@@ -36,6 +36,9 @@ import "@f-ewald/components/calendar-month.js";
|
|
|
36
36
|
<span slot="detail">Talks and workshops</span>
|
|
37
37
|
<span slot="footer">Closing keynote · July 20</span>
|
|
38
38
|
</calendar-entry>
|
|
39
|
+
<calendar-entry start="2026-07-27" end="2026-07-28" label="Client lunch" color="neutral">
|
|
40
|
+
<span slot="location">Downtown bistro</span>
|
|
41
|
+
</calendar-entry>
|
|
39
42
|
</calendar-month>
|
|
40
43
|
```
|
|
41
44
|
|
|
@@ -55,6 +58,7 @@ _None._
|
|
|
55
58
|
| Slot | Description |
|
|
56
59
|
| --- | --- |
|
|
57
60
|
| `(default)` | Declarative `calendar-entry` elements to render for this month. |
|
|
61
|
+
| `actions` | Optional controls rendered beside the month name (e.g. month-navigation buttons). |
|
|
58
62
|
|
|
59
63
|
## CSS custom properties
|
|
60
64
|
|
package/docs/calendar-week.md
CHANGED
|
@@ -26,7 +26,9 @@ import "@f-ewald/components/calendar-week.js";
|
|
|
26
26
|
<calendar-week date="2026-07-15">
|
|
27
27
|
<calendar-entry start="2026-07-13" end="2026-07-15" label="Offsite" color="primary" href="#offsite"></calendar-entry>
|
|
28
28
|
<calendar-entry start="2026-07-14T09:00" end="2026-07-14T09:30" label="Standup" color="info"></calendar-entry>
|
|
29
|
-
<calendar-entry start="2026-07-16T14:00" end="2026-07-16T15:00" label="Customer demo" color="success"
|
|
29
|
+
<calendar-entry start="2026-07-16T14:00" end="2026-07-16T15:00" label="Customer demo" color="success">
|
|
30
|
+
<span slot="location">Main conference room</span>
|
|
31
|
+
</calendar-entry>
|
|
30
32
|
</calendar-week>
|
|
31
33
|
```
|
|
32
34
|
|
|
@@ -45,6 +47,7 @@ _None._
|
|
|
45
47
|
| Slot | Description |
|
|
46
48
|
| --- | --- |
|
|
47
49
|
| `(default)` | Declarative `calendar-entry` elements to render for this week. |
|
|
50
|
+
| `actions` | Optional controls rendered beside the day headers (e.g. week-navigation buttons). |
|
|
48
51
|
|
|
49
52
|
## CSS custom properties
|
|
50
53
|
|
|
@@ -56,7 +59,9 @@ _None._
|
|
|
56
59
|
| `--ui-font` |
|
|
57
60
|
| `--ui-font-size-lg` |
|
|
58
61
|
| `--ui-font-size-sm` |
|
|
62
|
+
| `--ui-font-size-xs` |
|
|
59
63
|
| `--ui-font-weight-medium` |
|
|
64
|
+
| `--ui-font-weight-regular` |
|
|
60
65
|
| `--ui-font-weight-semibold` |
|
|
61
66
|
| `--ui-hover-overlay` |
|
|
62
67
|
| `--ui-info` |
|
package/llms.txt
CHANGED
|
@@ -400,17 +400,18 @@ interaction sync with `calendar-week` via `CalendarTimelineBase`.
|
|
|
400
400
|
|
|
401
401
|
Import: `import "@f-ewald/components/calendar-day.js";`
|
|
402
402
|
|
|
403
|
-
Properties: `date` (attribute `date`) : string, default
|
|
403
|
+
Properties: `date` (attribute `date`) : string, default —; `timeMarker` (attribute `time-marker`) : boolean, default false; `minWidth` (attribute `min-width`) : string, default ""
|
|
404
404
|
Events: none
|
|
405
|
-
CSS custom properties: `--ui-border`, `--ui-danger`, `--ui-focus-ring`, `--ui-font`, `--ui-font-size-lg`, `--ui-font-size-sm`, `--ui-font-weight-medium`, `--ui-font-weight-semibold`, `--ui-hover-overlay`, `--ui-info`, `--ui-line-height-tight`, `--ui-primary`, `--ui-radius-sm`, `--ui-success`, `--ui-surface`, `--ui-text`, `--ui-text-muted`, `--ui-warning`
|
|
405
|
+
CSS custom properties: `--ui-border`, `--ui-danger`, `--ui-focus-ring`, `--ui-font`, `--ui-font-size-lg`, `--ui-font-size-sm`, `--ui-font-size-xs`, `--ui-font-weight-medium`, `--ui-font-weight-regular`, `--ui-font-weight-semibold`, `--ui-hover-overlay`, `--ui-info`, `--ui-line-height-tight`, `--ui-primary`, `--ui-radius-sm`, `--ui-success`, `--ui-surface`, `--ui-surface-muted`, `--ui-text`, `--ui-text-muted`, `--ui-warning`
|
|
406
406
|
|
|
407
407
|
Example:
|
|
408
408
|
```html
|
|
409
|
-
<calendar-day date="2026-07-15">
|
|
409
|
+
<calendar-day date="2026-07-15" time-marker>
|
|
410
410
|
<calendar-entry start="2026-07-15" end="2026-07-15" label="Company holiday" color="neutral"></calendar-entry>
|
|
411
411
|
<calendar-entry start="2026-07-15T09:00" end="2026-07-15T09:30" label="Standup" color="info"></calendar-entry>
|
|
412
412
|
<calendar-entry start="2026-07-15T09:15" end="2026-07-15T10:00" label="Design review" color="primary" href="#review">
|
|
413
413
|
<span slot="detail">Walk through the new onboarding flow</span>
|
|
414
|
+
<span slot="location">Room A</span>
|
|
414
415
|
</calendar-entry>
|
|
415
416
|
</calendar-day>
|
|
416
417
|
```
|
|
@@ -436,6 +437,7 @@ Example:
|
|
|
436
437
|
color="success"
|
|
437
438
|
>
|
|
438
439
|
<span slot="title">Vacation</span>
|
|
440
|
+
<span slot="location">Beach house</span>
|
|
439
441
|
<span slot="detail">Out of office</span>
|
|
440
442
|
<span slot="detail">Road trip along the California coast with several scenic stops</span>
|
|
441
443
|
<span slot="footer">Return July 19 at 6 PM</span>
|
|
@@ -479,6 +481,9 @@ Example:
|
|
|
479
481
|
<span slot="detail">Talks and workshops</span>
|
|
480
482
|
<span slot="footer">Closing keynote · July 20</span>
|
|
481
483
|
</calendar-entry>
|
|
484
|
+
<calendar-entry start="2026-07-27" end="2026-07-28" label="Client lunch" color="neutral">
|
|
485
|
+
<span slot="location">Downtown bistro</span>
|
|
486
|
+
</calendar-entry>
|
|
482
487
|
</calendar-month>
|
|
483
488
|
```
|
|
484
489
|
|
|
@@ -502,14 +507,16 @@ Import: `import "@f-ewald/components/calendar-week.js";`
|
|
|
502
507
|
|
|
503
508
|
Properties: `date` (attribute `date`) : string, default —
|
|
504
509
|
Events: none
|
|
505
|
-
CSS custom properties: `--ui-border`, `--ui-danger`, `--ui-focus-ring`, `--ui-font`, `--ui-font-size-lg`, `--ui-font-size-sm`, `--ui-font-weight-medium`, `--ui-font-weight-semibold`, `--ui-hover-overlay`, `--ui-info`, `--ui-primary`, `--ui-radius-sm`, `--ui-success`, `--ui-surface`, `--ui-text`, `--ui-text-muted`, `--ui-warning`
|
|
510
|
+
CSS custom properties: `--ui-border`, `--ui-danger`, `--ui-focus-ring`, `--ui-font`, `--ui-font-size-lg`, `--ui-font-size-sm`, `--ui-font-size-xs`, `--ui-font-weight-medium`, `--ui-font-weight-regular`, `--ui-font-weight-semibold`, `--ui-hover-overlay`, `--ui-info`, `--ui-primary`, `--ui-radius-sm`, `--ui-success`, `--ui-surface`, `--ui-text`, `--ui-text-muted`, `--ui-warning`
|
|
506
511
|
|
|
507
512
|
Example:
|
|
508
513
|
```html
|
|
509
514
|
<calendar-week date="2026-07-15">
|
|
510
515
|
<calendar-entry start="2026-07-13" end="2026-07-15" label="Offsite" color="primary" href="#offsite"></calendar-entry>
|
|
511
516
|
<calendar-entry start="2026-07-14T09:00" end="2026-07-14T09:30" label="Standup" color="info"></calendar-entry>
|
|
512
|
-
<calendar-entry start="2026-07-16T14:00" end="2026-07-16T15:00" label="Customer demo" color="success"
|
|
517
|
+
<calendar-entry start="2026-07-16T14:00" end="2026-07-16T15:00" label="Customer demo" color="success">
|
|
518
|
+
<span slot="location">Main conference room</span>
|
|
519
|
+
</calendar-entry>
|
|
513
520
|
</calendar-week>
|
|
514
521
|
```
|
|
515
522
|
|