@super-calendar/core 2.1.5 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -51,6 +51,41 @@ interface RecurrenceRule {
51
51
  * the event's time of day. Omit to repeat on the start date's own weekday.
52
52
  */
53
53
  weekdays?: WeekStartsOn[];
54
+ /**
55
+ * For `monthly`/`yearly`: repeat on the Nth weekday of the period instead of the
56
+ * start date's day-of-month — e.g. `{ week: 3, weekday: 1 }` is the 3rd Monday.
57
+ * `week` is 1–5, or -1 for the last such weekday. Maps to an ordinal iCal `BYDAY`
58
+ * (e.g. `3MO`, `-1FR`).
59
+ */
60
+ nthWeekday?: {
61
+ week: number;
62
+ weekday: WeekStartsOn;
63
+ };
64
+ /**
65
+ * For `monthly`: the day(s) of the month to repeat on — 1–31, or negative to
66
+ * count from the month's end (-1 is the last day, -2 the second-to-last). Days
67
+ * that don't exist in a given month (e.g. the 31st in February) are skipped.
68
+ * Takes precedence over the start date's own day-of-month. Maps to iCal
69
+ * `BYMONTHDAY`.
70
+ */
71
+ monthDays?: number[];
72
+ /**
73
+ * For `yearly`: the month(s) to repeat in (1 = January … 12 = December), keeping
74
+ * the start date's day-of-month. Years where a listed month lacks that day are
75
+ * skipped. Maps to iCal `BYMONTH`.
76
+ */
77
+ months?: number[];
78
+ /**
79
+ * Dates to skip (exceptions). An occurrence whose day matches one of these is
80
+ * dropped by `expandRecurringEvents`. Maps to iCal `EXDATE`.
81
+ */
82
+ exdates?: Date[];
83
+ /**
84
+ * Extra one-off start dates added to the set, even ones the rule wouldn't
85
+ * produce. Merged in chronological order and de-duplicated against rule
86
+ * occurrences; `exdates` still apply. Maps to iCal `RDATE`.
87
+ */
88
+ rdates?: Date[];
54
89
  }
55
90
  /**
56
91
  * An event carrying arbitrary extra fields `T` alongside the required shape.
@@ -333,6 +368,26 @@ declare function eventAccessibilityLabel(args: {
333
368
  ampm: boolean; /** Spoken text for an all-day event. Default "all day". */
334
369
  allDayLabel?: string;
335
370
  }): string;
371
+ /**
372
+ * Context describing how an event is being rendered, passed to a consumer's
373
+ * {@link EventAccessibilityLabeler} so the label can adapt to the view (e.g. omit
374
+ * the time in month mode, or read the 12-hour clock when `ampm` is set).
375
+ */
376
+ interface EventAccessibilityLabelContext {
377
+ /** The view the event is rendered in. */
378
+ mode: CalendarMode;
379
+ /** Whether the event sits in the all-day lane (or is an all-day event in month view). */
380
+ isAllDay: boolean;
381
+ /** Whether times are formatted as 12-hour AM/PM. */
382
+ ampm: boolean;
383
+ }
384
+ /**
385
+ * Override for an event's screen-reader label. Return the full text to announce
386
+ * for `event`; each renderer uses it verbatim in place of the built-in
387
+ * {@link eventAccessibilityLabel}. Shared by both renderers, so a custom label
388
+ * reads the same on web and native.
389
+ */
390
+ type EventAccessibilityLabeler<T = unknown> = (event: CalendarEvent<T>, context: EventAccessibilityLabelContext) => string;
336
391
  /**
337
392
  * Month cells and the all-day lane show a single clipped line; timed-grid titles
338
393
  * (`undefined`) wrap to fill the box.
@@ -418,6 +473,47 @@ declare function monthEventCapacity(availableHeightPx: number, chipRowHeightPx:
418
473
  */
419
474
  declare function monthVisibleCount(total: number, capacity: MonthEventCapacity): number;
420
475
  //#endregion
476
+ //#region src/utils/ical.d.ts
477
+ /** An event parsed from iCal, carrying the standard fields it also round-trips. */
478
+ interface ICalEvent extends ICalendarEvent {
479
+ /** The VEVENT `UID`, if present. */
480
+ uid?: string;
481
+ /** The VEVENT `DESCRIPTION`, if present. */
482
+ description?: string;
483
+ /** The VEVENT `LOCATION`, if present. */
484
+ location?: string;
485
+ }
486
+ /** Options for {@link toICalendar}. */
487
+ interface ToICalendarOptions {
488
+ /** `PRODID` written to the calendar header. Default `-//super-calendar//EN`. */
489
+ prodId?: string;
490
+ /** The `DTSTAMP` stamped on every event (when it was written). Default: now. */
491
+ now?: Date;
492
+ }
493
+ /**
494
+ * Parse an iCalendar (`.ics`) string into events. Reads every `VEVENT`; ignores
495
+ * VTODO/VJOURNAL/VTIMEZONE and unknown properties. Events without a usable
496
+ * `DTSTART` are skipped. All-day events (`VALUE=DATE`) with no `DTEND` get a
497
+ * one-day span.
498
+ *
499
+ * @example
500
+ * ```ts
501
+ * const events = parseICalendar(await file.text());
502
+ * ```
503
+ */
504
+ declare function parseICalendar(ics: string): ICalEvent[];
505
+ /**
506
+ * Serialize events to an iCalendar (`.ics`) string. Timed events are written in
507
+ * UTC (`...Z`); all-day events (`allDay: true`) use `VALUE=DATE`. A `recurrence`
508
+ * becomes an `RRULE`, and `uid` / `description` / `location` round-trip.
509
+ *
510
+ * @example
511
+ * ```ts
512
+ * const ics = toICalendar(events);
513
+ * ```
514
+ */
515
+ declare function toICalendar(events: ICalEvent[], options?: ToICalendarOptions): string;
516
+ //#endregion
421
517
  //#region src/utils/layout.d.ts
422
518
  /** An event placed on a single day's time grid by {@link layoutDayEvents}, with its vertical span and overlap column. */
423
519
  type PositionedEvent<T> = {
@@ -521,10 +617,23 @@ interface MonthGrid {
521
617
  /** The weekday header cells, in display order. */
522
618
  weekdays: MonthGridWeekday[];
523
619
  }
620
+ /**
621
+ * Weekday header label width: `narrow` ("M"), `short` ("Mon", the default), or
622
+ * `long` ("Monday").
623
+ */
624
+ type WeekdayFormat = "narrow" | "short" | "long";
625
+ /**
626
+ * The date-fns format token for a {@link WeekdayFormat}. Exposed so a renderer
627
+ * that formats its own weekday header (rather than reading {@link buildMonthGrid})
628
+ * keeps the same mapping.
629
+ */
630
+ declare function weekdayFormatToken(format: WeekdayFormat): string;
524
631
  /** Options for {@link buildMonthGrid} and {@link useMonthGrid}. */
525
632
  interface UseMonthGridOptions extends DateSelectionConstraints {
526
633
  /** First day of the week. Sunday = 0 (default) … Saturday = 6. */
527
634
  weekStartsOn?: WeekStartsOn;
635
+ /** Weekday header label width. Default `short` ("Mon"). */
636
+ weekdayFormat?: WeekdayFormat;
528
637
  /** Always return six week rows for a fixed-height grid. Default false. */
529
638
  showSixWeeks?: boolean;
530
639
  /** Reverse each week's day order (right-to-left). Default false. */
@@ -575,6 +684,14 @@ declare function expandRecurringEvents<T>(events: CalendarEvent<T>[], rangeStart
575
684
  * original UTC instant, so don't round-trip it back to a real time.
576
685
  */
577
686
  declare function toZonedTime(date: Date, timeZone: string): Date;
687
+ /**
688
+ * The inverse of {@link toZonedTime}: given a wall-clock time in `timeZone`,
689
+ * return the absolute UTC instant. Pass the wall clock as a `Date` whose **UTC**
690
+ * fields hold the components (e.g. `new Date(Date.UTC(y, m, d, h, min))`). Used to
691
+ * resolve iCal `TZID` times; DST-correct via a two-pass offset (ambiguous
692
+ * fall-back times resolve to the post-transition offset).
693
+ */
694
+ declare function zonedTimeToUtc(wallClock: Date, timeZone: string): Date;
578
695
  /**
579
696
  * Map every event's `start`/`end` through {@link toZonedTime} so the calendar
580
697
  * displays them in `timeZone`. Other fields are preserved. Memoize the result
@@ -582,4 +699,4 @@ declare function toZonedTime(date: Date, timeZone: string): Date;
582
699
  */
583
700
  declare function eventsInTimeZone<T>(events: CalendarEvent<T>[], timeZone: string): CalendarEvent<T>[];
584
701
  //#endregion
585
- export { BusinessHours, CalendarColors, CalendarEvent, CalendarMode, CalendarSelection, CalendarSelectionProvider, DateRange, DateSelectionConstraints, DayBadgeKind, DaySelectionState, EventChipLayout, EventKeyExtractor, ICalendarEvent, MIN_BOX_HEIGHT_FOR_TIME, MonthEventCapacity, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, PositionedEvent, RangeBandKind, RecurrenceFrequency, RecurrenceRule, TimeGridMode, UseDateRangeOptions, UseDateRangeResult, UseMonthGridOptions, WeekStartsOn, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventDayKeys, eventTimeLabel, eventsInTimeZone, expandRecurringEvents, formatHour, getIsToday, getViewDays, getWeekDays, groupEventsByDay, isAllDayEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isTimeVisibleAtHeight, isWeekend, isWithinDateRange, layoutDayEvents, lightColors, minutesIntoDay, monthEventCapacity, monthVisibleCount, nextDateRange, rangeBandKind, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toZonedTime, useCalendarSelection, useDateRange, useMonthGrid, viewDayCount, weekDaysCount };
702
+ export { BusinessHours, CalendarColors, CalendarEvent, CalendarMode, CalendarSelection, CalendarSelectionProvider, DateRange, DateSelectionConstraints, DayBadgeKind, DaySelectionState, EventAccessibilityLabelContext, EventAccessibilityLabeler, EventChipLayout, EventKeyExtractor, ICalEvent, ICalendarEvent, MIN_BOX_HEIGHT_FOR_TIME, MonthEventCapacity, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, PositionedEvent, RangeBandKind, RecurrenceFrequency, RecurrenceRule, TimeGridMode, ToICalendarOptions, UseDateRangeOptions, UseDateRangeResult, UseMonthGridOptions, WeekStartsOn, WeekdayFormat, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventDayKeys, eventTimeLabel, eventsInTimeZone, expandRecurringEvents, formatHour, getIsToday, getViewDays, getWeekDays, groupEventsByDay, isAllDayEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isTimeVisibleAtHeight, isWeekend, isWithinDateRange, layoutDayEvents, lightColors, minutesIntoDay, monthEventCapacity, monthVisibleCount, nextDateRange, parseICalendar, rangeBandKind, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, useCalendarSelection, useDateRange, useMonthGrid, viewDayCount, weekDaysCount, weekdayFormatToken, zonedTimeToUtc };
package/dist/index.d.ts CHANGED
@@ -51,6 +51,41 @@ interface RecurrenceRule {
51
51
  * the event's time of day. Omit to repeat on the start date's own weekday.
52
52
  */
53
53
  weekdays?: WeekStartsOn[];
54
+ /**
55
+ * For `monthly`/`yearly`: repeat on the Nth weekday of the period instead of the
56
+ * start date's day-of-month — e.g. `{ week: 3, weekday: 1 }` is the 3rd Monday.
57
+ * `week` is 1–5, or -1 for the last such weekday. Maps to an ordinal iCal `BYDAY`
58
+ * (e.g. `3MO`, `-1FR`).
59
+ */
60
+ nthWeekday?: {
61
+ week: number;
62
+ weekday: WeekStartsOn;
63
+ };
64
+ /**
65
+ * For `monthly`: the day(s) of the month to repeat on — 1–31, or negative to
66
+ * count from the month's end (-1 is the last day, -2 the second-to-last). Days
67
+ * that don't exist in a given month (e.g. the 31st in February) are skipped.
68
+ * Takes precedence over the start date's own day-of-month. Maps to iCal
69
+ * `BYMONTHDAY`.
70
+ */
71
+ monthDays?: number[];
72
+ /**
73
+ * For `yearly`: the month(s) to repeat in (1 = January … 12 = December), keeping
74
+ * the start date's day-of-month. Years where a listed month lacks that day are
75
+ * skipped. Maps to iCal `BYMONTH`.
76
+ */
77
+ months?: number[];
78
+ /**
79
+ * Dates to skip (exceptions). An occurrence whose day matches one of these is
80
+ * dropped by `expandRecurringEvents`. Maps to iCal `EXDATE`.
81
+ */
82
+ exdates?: Date[];
83
+ /**
84
+ * Extra one-off start dates added to the set, even ones the rule wouldn't
85
+ * produce. Merged in chronological order and de-duplicated against rule
86
+ * occurrences; `exdates` still apply. Maps to iCal `RDATE`.
87
+ */
88
+ rdates?: Date[];
54
89
  }
55
90
  /**
56
91
  * An event carrying arbitrary extra fields `T` alongside the required shape.
@@ -333,6 +368,26 @@ declare function eventAccessibilityLabel(args: {
333
368
  ampm: boolean; /** Spoken text for an all-day event. Default "all day". */
334
369
  allDayLabel?: string;
335
370
  }): string;
371
+ /**
372
+ * Context describing how an event is being rendered, passed to a consumer's
373
+ * {@link EventAccessibilityLabeler} so the label can adapt to the view (e.g. omit
374
+ * the time in month mode, or read the 12-hour clock when `ampm` is set).
375
+ */
376
+ interface EventAccessibilityLabelContext {
377
+ /** The view the event is rendered in. */
378
+ mode: CalendarMode;
379
+ /** Whether the event sits in the all-day lane (or is an all-day event in month view). */
380
+ isAllDay: boolean;
381
+ /** Whether times are formatted as 12-hour AM/PM. */
382
+ ampm: boolean;
383
+ }
384
+ /**
385
+ * Override for an event's screen-reader label. Return the full text to announce
386
+ * for `event`; each renderer uses it verbatim in place of the built-in
387
+ * {@link eventAccessibilityLabel}. Shared by both renderers, so a custom label
388
+ * reads the same on web and native.
389
+ */
390
+ type EventAccessibilityLabeler<T = unknown> = (event: CalendarEvent<T>, context: EventAccessibilityLabelContext) => string;
336
391
  /**
337
392
  * Month cells and the all-day lane show a single clipped line; timed-grid titles
338
393
  * (`undefined`) wrap to fill the box.
@@ -418,6 +473,47 @@ declare function monthEventCapacity(availableHeightPx: number, chipRowHeightPx:
418
473
  */
419
474
  declare function monthVisibleCount(total: number, capacity: MonthEventCapacity): number;
420
475
  //#endregion
476
+ //#region src/utils/ical.d.ts
477
+ /** An event parsed from iCal, carrying the standard fields it also round-trips. */
478
+ interface ICalEvent extends ICalendarEvent {
479
+ /** The VEVENT `UID`, if present. */
480
+ uid?: string;
481
+ /** The VEVENT `DESCRIPTION`, if present. */
482
+ description?: string;
483
+ /** The VEVENT `LOCATION`, if present. */
484
+ location?: string;
485
+ }
486
+ /** Options for {@link toICalendar}. */
487
+ interface ToICalendarOptions {
488
+ /** `PRODID` written to the calendar header. Default `-//super-calendar//EN`. */
489
+ prodId?: string;
490
+ /** The `DTSTAMP` stamped on every event (when it was written). Default: now. */
491
+ now?: Date;
492
+ }
493
+ /**
494
+ * Parse an iCalendar (`.ics`) string into events. Reads every `VEVENT`; ignores
495
+ * VTODO/VJOURNAL/VTIMEZONE and unknown properties. Events without a usable
496
+ * `DTSTART` are skipped. All-day events (`VALUE=DATE`) with no `DTEND` get a
497
+ * one-day span.
498
+ *
499
+ * @example
500
+ * ```ts
501
+ * const events = parseICalendar(await file.text());
502
+ * ```
503
+ */
504
+ declare function parseICalendar(ics: string): ICalEvent[];
505
+ /**
506
+ * Serialize events to an iCalendar (`.ics`) string. Timed events are written in
507
+ * UTC (`...Z`); all-day events (`allDay: true`) use `VALUE=DATE`. A `recurrence`
508
+ * becomes an `RRULE`, and `uid` / `description` / `location` round-trip.
509
+ *
510
+ * @example
511
+ * ```ts
512
+ * const ics = toICalendar(events);
513
+ * ```
514
+ */
515
+ declare function toICalendar(events: ICalEvent[], options?: ToICalendarOptions): string;
516
+ //#endregion
421
517
  //#region src/utils/layout.d.ts
422
518
  /** An event placed on a single day's time grid by {@link layoutDayEvents}, with its vertical span and overlap column. */
423
519
  type PositionedEvent<T> = {
@@ -521,10 +617,23 @@ interface MonthGrid {
521
617
  /** The weekday header cells, in display order. */
522
618
  weekdays: MonthGridWeekday[];
523
619
  }
620
+ /**
621
+ * Weekday header label width: `narrow` ("M"), `short` ("Mon", the default), or
622
+ * `long` ("Monday").
623
+ */
624
+ type WeekdayFormat = "narrow" | "short" | "long";
625
+ /**
626
+ * The date-fns format token for a {@link WeekdayFormat}. Exposed so a renderer
627
+ * that formats its own weekday header (rather than reading {@link buildMonthGrid})
628
+ * keeps the same mapping.
629
+ */
630
+ declare function weekdayFormatToken(format: WeekdayFormat): string;
524
631
  /** Options for {@link buildMonthGrid} and {@link useMonthGrid}. */
525
632
  interface UseMonthGridOptions extends DateSelectionConstraints {
526
633
  /** First day of the week. Sunday = 0 (default) … Saturday = 6. */
527
634
  weekStartsOn?: WeekStartsOn;
635
+ /** Weekday header label width. Default `short` ("Mon"). */
636
+ weekdayFormat?: WeekdayFormat;
528
637
  /** Always return six week rows for a fixed-height grid. Default false. */
529
638
  showSixWeeks?: boolean;
530
639
  /** Reverse each week's day order (right-to-left). Default false. */
@@ -575,6 +684,14 @@ declare function expandRecurringEvents<T>(events: CalendarEvent<T>[], rangeStart
575
684
  * original UTC instant, so don't round-trip it back to a real time.
576
685
  */
577
686
  declare function toZonedTime(date: Date, timeZone: string): Date;
687
+ /**
688
+ * The inverse of {@link toZonedTime}: given a wall-clock time in `timeZone`,
689
+ * return the absolute UTC instant. Pass the wall clock as a `Date` whose **UTC**
690
+ * fields hold the components (e.g. `new Date(Date.UTC(y, m, d, h, min))`). Used to
691
+ * resolve iCal `TZID` times; DST-correct via a two-pass offset (ambiguous
692
+ * fall-back times resolve to the post-transition offset).
693
+ */
694
+ declare function zonedTimeToUtc(wallClock: Date, timeZone: string): Date;
578
695
  /**
579
696
  * Map every event's `start`/`end` through {@link toZonedTime} so the calendar
580
697
  * displays them in `timeZone`. Other fields are preserved. Memoize the result
@@ -582,4 +699,4 @@ declare function toZonedTime(date: Date, timeZone: string): Date;
582
699
  */
583
700
  declare function eventsInTimeZone<T>(events: CalendarEvent<T>[], timeZone: string): CalendarEvent<T>[];
584
701
  //#endregion
585
- export { BusinessHours, CalendarColors, CalendarEvent, CalendarMode, CalendarSelection, CalendarSelectionProvider, DateRange, DateSelectionConstraints, DayBadgeKind, DaySelectionState, EventChipLayout, EventKeyExtractor, ICalendarEvent, MIN_BOX_HEIGHT_FOR_TIME, MonthEventCapacity, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, PositionedEvent, RangeBandKind, RecurrenceFrequency, RecurrenceRule, TimeGridMode, UseDateRangeOptions, UseDateRangeResult, UseMonthGridOptions, WeekStartsOn, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventDayKeys, eventTimeLabel, eventsInTimeZone, expandRecurringEvents, formatHour, getIsToday, getViewDays, getWeekDays, groupEventsByDay, isAllDayEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isTimeVisibleAtHeight, isWeekend, isWithinDateRange, layoutDayEvents, lightColors, minutesIntoDay, monthEventCapacity, monthVisibleCount, nextDateRange, rangeBandKind, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toZonedTime, useCalendarSelection, useDateRange, useMonthGrid, viewDayCount, weekDaysCount };
702
+ export { BusinessHours, CalendarColors, CalendarEvent, CalendarMode, CalendarSelection, CalendarSelectionProvider, DateRange, DateSelectionConstraints, DayBadgeKind, DaySelectionState, EventAccessibilityLabelContext, EventAccessibilityLabeler, EventChipLayout, EventKeyExtractor, ICalEvent, ICalendarEvent, MIN_BOX_HEIGHT_FOR_TIME, MonthEventCapacity, MonthGrid, MonthGridDay, MonthGridWeek, MonthGridWeekday, PositionedEvent, RangeBandKind, RecurrenceFrequency, RecurrenceRule, TimeGridMode, ToICalendarOptions, UseDateRangeOptions, UseDateRangeResult, UseMonthGridOptions, WeekStartsOn, WeekdayFormat, bandRounding, buildMonthGrid, buildMonthWeeks, cellRangeFromDrag, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventDayKeys, eventTimeLabel, eventsInTimeZone, expandRecurringEvents, formatHour, getIsToday, getViewDays, getWeekDays, groupEventsByDay, isAllDayEvent, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isTimeVisibleAtHeight, isWeekend, isWithinDateRange, layoutDayEvents, lightColors, minutesIntoDay, monthEventCapacity, monthVisibleCount, nextDateRange, parseICalendar, rangeBandKind, resolveDraggedBounds, shiftMinutes, snapDeltaMinutes, titleEllipsizeMode, titleNumberOfLines, toICalendar, toZonedTime, useCalendarSelection, useDateRange, useMonthGrid, viewDayCount, weekDaysCount, weekdayFormatToken, zonedTimeToUtc };