@ebarooni/capacitor-calendar 8.11.0 → 8.12.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/README.md +279 -103
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +37 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CalendarChangeObserver.kt +181 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt +58 -8
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/data/EventDeleteInfo.kt +6 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/StartListeningInput.kt +20 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/utils/ImplementationHelper.kt +88 -67
- package/dist/docs.json +1383 -976
- package/dist/esm/definitions.d.ts +2 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +12 -2
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.d.ts +2 -2
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.js +2 -2
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.js.map +1 -1
- package/dist/esm/schemas/interfaces/calendar-changed-event.d.ts +52 -0
- package/dist/esm/schemas/interfaces/calendar-changed-event.js +2 -0
- package/dist/esm/schemas/interfaces/calendar-changed-event.js.map +1 -0
- package/dist/esm/schemas/interfaces/calendar-links.d.ts +32 -0
- package/dist/esm/schemas/interfaces/calendar-links.js +2 -0
- package/dist/esm/schemas/interfaces/calendar-links.js.map +1 -0
- package/dist/esm/schemas/interfaces/create-event-options.d.ts +18 -0
- package/dist/esm/schemas/interfaces/create-event-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-event-with-prompt-options.d.ts +9 -0
- package/dist/esm/schemas/interfaces/create-event-with-prompt-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-ics-file-options.d.ts +20 -0
- package/dist/esm/schemas/interfaces/create-ics-file-options.js +2 -0
- package/dist/esm/schemas/interfaces/create-ics-file-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/open-calendar-options.d.ts +9 -0
- package/dist/esm/schemas/interfaces/open-calendar-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/share-ics-file-options.d.ts +17 -0
- package/dist/esm/schemas/interfaces/share-ics-file-options.js +2 -0
- package/dist/esm/schemas/interfaces/share-ics-file-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/start-listening-options.d.ts +46 -0
- package/dist/esm/schemas/interfaces/start-listening-options.js +2 -0
- package/dist/esm/schemas/interfaces/start-listening-options.js.map +1 -0
- package/dist/esm/schemas/types/calendar-day-view-provider.d.ts +7 -0
- package/dist/esm/schemas/types/calendar-day-view-provider.js +2 -0
- package/dist/esm/schemas/types/calendar-day-view-provider.js.map +1 -0
- package/dist/esm/schemas/types/calendar-link-provider.d.ts +6 -0
- package/dist/esm/schemas/types/calendar-link-provider.js +2 -0
- package/dist/esm/schemas/types/calendar-link-provider.js.map +1 -0
- package/dist/esm/sub-definitions/calendar-listening.d.ts +49 -0
- package/dist/esm/sub-definitions/calendar-listening.js +2 -0
- package/dist/esm/sub-definitions/calendar-listening.js.map +1 -0
- package/dist/esm/sub-definitions/calendar-operations.d.ts +2 -1
- package/dist/esm/sub-definitions/calendar-operations.js.map +1 -1
- package/dist/esm/web/calendar-links.d.ts +26 -0
- package/dist/esm/web/calendar-links.js +114 -0
- package/dist/esm/web/calendar-links.js.map +1 -0
- package/dist/esm/web/create-ics-file.d.ts +21 -0
- package/dist/esm/web/create-ics-file.js +30 -0
- package/dist/esm/web/create-ics-file.js.map +1 -0
- package/dist/esm/web/ics.d.ts +11 -0
- package/dist/esm/web/ics.js +48 -32
- package/dist/esm/web/ics.js.map +1 -1
- package/dist/esm/web/share-ics-file.d.ts +21 -0
- package/dist/esm/web/share-ics-file.js +46 -0
- package/dist/esm/web/share-ics-file.js.map +1 -0
- package/dist/esm/web.d.ts +4 -1
- package/dist/esm/web.js +18 -4
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +292 -72
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +292 -72
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorCalendarPlugin.swift +19 -0
- package/ios/Plugin/Implementation/CalendarChangeObserver.swift +259 -0
- package/ios/Plugin/Implementation/CapacitorCalendar.swift +15 -1
- package/ios/Plugin/Models/Inputs/DeleteReminderInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/DeleteReminderWithPromptInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/DeleteRemindersListInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/GetReminderByIdInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/ModifyReminderInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/StartListeningInput.swift +26 -0
- package/ios/Plugin/Models/Inputs/UpdateRemindersListInput.swift +1 -1
- package/ios/Plugin/PluginConfig.swift +2 -0
- package/ios/Plugin/PluginError.swift +25 -3
- package/ios/Plugin/Utils/ImplementationHelper.swift +16 -30
- package/ios/Plugin/Utils/PluginCallRejecter.swift +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-listening.js","sourceRoot":"","sources":["../../../src/sub-definitions/calendar-listening.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nimport type { CalendarChangedEvent } from '../schemas/interfaces/calendar-changed-event';\nimport type { StartListeningOptions } from '../schemas/interfaces/start-listening-options';\n\nexport interface CalendarListening {\n /**\n * Starts to watch the calendar for changes in a time window.\n * Call `addListener('calendarChanged', ...)` to receive them.\n * A new call replaces the previous window.\n * The plugin reads the window once as a baseline. It then compares the window after each change.\n * Changes made by this plugin also trigger the listener.\n * Changes made while the app is stopped are not sent.\n * Needs calendar read access.\n *\n * @example\n * const handle = await CapacitorCalendar.addListener('calendarChanged', (change) => {\n * console.log(change.created, change.updated, change.deletedIds);\n * });\n * await CapacitorCalendar.startListening({ from: Date.now(), to: Date.now() + 30 * 24 * 60 * 60 * 1000 });\n *\n * @throws {Error} `From date must be provided.` — when `from` is missing.\n * @throws {Error} `To date must be provided.` — when `to` is missing.\n * @throws {Error} `Calendar not found.` — when a `calendarIds` entry does not match a calendar.\n *\n * @platform Android, iOS\n * @since 8.12.0\n */\n startListening(options: StartListeningOptions): Promise<void>;\n /**\n * Stops to watch the calendar. Does nothing when no watch is active.\n * Listeners stay registered. Remove them with their handle or `removeAllListeners`.\n *\n * @platform Android, iOS\n * @since 8.12.0\n */\n stopListening(): Promise<void>;\n /**\n * Adds a listener for calendar changes. Call `startListening` to start the events.\n *\n * @platform Android, iOS\n * @since 8.12.0\n */\n addListener(\n eventName: 'calendarChanged',\n listenerFunc: (event: CalendarChangedEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Removes all listeners of this plugin.\n *\n * @since 8.12.0\n */\n removeAllListeners(): Promise<void>;\n}\n"]}
|
|
@@ -72,11 +72,12 @@ export interface CalendarOperations {
|
|
|
72
72
|
}>;
|
|
73
73
|
/**
|
|
74
74
|
* Opens the calendar app.
|
|
75
|
+
* On Web, opens a web calendar in a new tab when `provider` is set, and rejects otherwise.
|
|
75
76
|
*
|
|
76
77
|
* @example
|
|
77
78
|
* CapacitorCalendar.openCalendar({ date: Date.now() });
|
|
78
79
|
*
|
|
79
|
-
* @platform Android, iOS
|
|
80
|
+
* @platform Android, iOS, Web
|
|
80
81
|
* @since 7.1.0
|
|
81
82
|
*/
|
|
82
83
|
openCalendar(options?: OpenCalendarOptions): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calendar-operations.js","sourceRoot":"","sources":["../../../src/sub-definitions/calendar-operations.ts"],"names":[],"mappings":"","sourcesContent":["import type { Calendar } from '../schemas/interfaces/calendar';\nimport type { CreateCalendarOptions } from '../schemas/interfaces/create-calendar-options';\nimport type { CreateCalendarResult } from '../schemas/interfaces/create-calendar-result';\nimport type { DeleteCalendarOptions } from '../schemas/interfaces/delete-calendar-options';\nimport type { FetchAllCalendarSourcesResult } from '../schemas/interfaces/fetch-all-calendar-sources-result';\nimport type { GetDefaultCalendarOptions } from '../schemas/interfaces/get-default-calendar-options';\nimport type { ListCalendarsResult } from '../schemas/interfaces/list-calendars-result';\nimport type { ModifyCalendarOptions } from '../schemas/interfaces/modify-calendar-options';\nimport type { OpenCalendarOptions } from '../schemas/interfaces/open-calendar-options';\nimport type { SelectCalendarsWithPromptOptions } from '../schemas/interfaces/select-calendars-with-prompt-options';\nimport type { SelectCalendarsWithPromptResult } from '../schemas/interfaces/select-calendars-with-prompt-result';\n\nexport interface CalendarOperations {\n /**\n * Saves pending calendar changes.\n *\n * @platform iOS\n * @since 7.1.0\n */\n commit(): Promise<void>;\n /**\n * Opens a system interface to choose one or multiple calendars.\n *\n * Calendar access is expected. Call `requestFullCalendarAccess()` first.\n * Without authorization the chooser can look empty.\n *\n * On confirm, `result` contains the calendars the user selected.\n * On cancel, `result` is an empty array.\n *\n * If a chooser is already presented, a new call is rejected; the in-flight\n * call continues until the user confirms or cancels.\n *\n * @platform iOS\n * @since 0.2.0\n */\n selectCalendarsWithPrompt(options?: SelectCalendarsWithPromptOptions): Promise<SelectCalendarsWithPromptResult>;\n /**\n * Retrieves a list of calendar sources.\n *\n * Requires calendar access. Without authorization, `result` is typically\n * an empty array. This method does not reject solely for missing permission.\n *\n * @platform iOS\n * @since 6.6.0\n */\n fetchAllCalendarSources(): Promise<FetchAllCalendarSourcesResult>;\n /**\n * Retrieves a list of all available calendars.\n *\n * Requires calendar read access. On Android, missing permission typically\n * rejects. On iOS, missing authorization typically returns an empty `result`.\n *\n * @platform Android, iOS\n * @since 7.1.0\n */\n listCalendars(): Promise<ListCalendarsResult>;\n /**\n * Retrieves the default calendar.\n *\n * Requires calendar read access. On Android, missing permission typically\n * rejects. On iOS, missing authorization typically yields `result: null`.\n *\n * The system default is the primary calendar on Android and\n * `defaultCalendarForNewEvents` on iOS. When neither exists and\n * `useFallbackCalendar` is true, the first available calendar is returned.\n * Otherwise the method returns `null` when there is no system default.\n *\n * @platform Android, iOS\n * @since 0.3.0\n */\n getDefaultCalendar(options?: GetDefaultCalendarOptions): Promise<{ result: Calendar | null }>;\n /**\n * Opens the calendar app.\n *\n * @example\n * CapacitorCalendar.openCalendar({ date: Date.now() });\n *\n * @platform Android, iOS\n * @since 7.1.0\n */\n openCalendar(options?: OpenCalendarOptions): Promise<void>;\n /**\n * Creates a calendar.\n *\n * `title` is required. `color` is optional and defaults to `#007AFF`.\n * On Android, `accountName` and `ownerAccount` are required at runtime.\n *\n * @example\n * CapacitorCalendar.createCalendar({\n * title: 'Work',\n * accountName: 'plugin@example.com',\n * ownerAccount: 'plugin@example.com',\n * });\n *\n * @throws {Error} `Title must be provided.` — when `title` is missing.\n * @throws {Error} `Invalid color format.` — when `color` is present but invalid.\n * @throws {Error} `Account name must be provided.` — when `accountName` is missing on Android.\n * @throws {Error} `Owner account must be provided.` — when `ownerAccount` is missing on Android.\n * @throws {Error} `Calendar source not found.` — when `sourceId` is set and no EventKit source matches (iOS).\n * @throws {Error} `Failed to retrieve calendar ID.` — when the calendar is created but no id is returned.\n *\n * @platform Android, iOS\n * @since 5.2.0\n */\n createCalendar(options: CreateCalendarOptions): Promise<CreateCalendarResult>;\n /**\n * Deletes a calendar by id.\n *\n * @throws {Error} `Calendar ID must be provided.` — when `id` is missing.\n * @throws {Error} `Invalid calendar ID.` — when `id` is not a numeric Android calendar id.\n * @throws {Error} `Calendar not found.` — when no calendar exists for `id`.\n *\n * @platform Android, iOS\n * @since 5.2.0\n */\n deleteCalendar(options: DeleteCalendarOptions): Promise<void>;\n /**\n * Modifies a calendar with options.\n *\n * @throws {Error} `Calendar ID must be provided.` — when `id` is missing.\n * @throws {Error} `Invalid calendar ID.` — when `id` is not a numeric Android calendar id.\n * @throws {Error} `At least one of title or color must be provided.` — when both are omitted.\n * @throws {Error} `Invalid color format.` — when `color` is present but invalid.\n * @throws {Error} `Calendar not found.` — when no calendar exists for `id`.\n * @throws {Error} `Calendar is not modifiable.` — when the calendar cannot be modified (iOS).\n *\n * @platform Android, iOS\n * @since 7.2.0\n */\n modifyCalendar(options: ModifyCalendarOptions): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"calendar-operations.js","sourceRoot":"","sources":["../../../src/sub-definitions/calendar-operations.ts"],"names":[],"mappings":"","sourcesContent":["import type { Calendar } from '../schemas/interfaces/calendar';\nimport type { CreateCalendarOptions } from '../schemas/interfaces/create-calendar-options';\nimport type { CreateCalendarResult } from '../schemas/interfaces/create-calendar-result';\nimport type { DeleteCalendarOptions } from '../schemas/interfaces/delete-calendar-options';\nimport type { FetchAllCalendarSourcesResult } from '../schemas/interfaces/fetch-all-calendar-sources-result';\nimport type { GetDefaultCalendarOptions } from '../schemas/interfaces/get-default-calendar-options';\nimport type { ListCalendarsResult } from '../schemas/interfaces/list-calendars-result';\nimport type { ModifyCalendarOptions } from '../schemas/interfaces/modify-calendar-options';\nimport type { OpenCalendarOptions } from '../schemas/interfaces/open-calendar-options';\nimport type { SelectCalendarsWithPromptOptions } from '../schemas/interfaces/select-calendars-with-prompt-options';\nimport type { SelectCalendarsWithPromptResult } from '../schemas/interfaces/select-calendars-with-prompt-result';\n\nexport interface CalendarOperations {\n /**\n * Saves pending calendar changes.\n *\n * @platform iOS\n * @since 7.1.0\n */\n commit(): Promise<void>;\n /**\n * Opens a system interface to choose one or multiple calendars.\n *\n * Calendar access is expected. Call `requestFullCalendarAccess()` first.\n * Without authorization the chooser can look empty.\n *\n * On confirm, `result` contains the calendars the user selected.\n * On cancel, `result` is an empty array.\n *\n * If a chooser is already presented, a new call is rejected; the in-flight\n * call continues until the user confirms or cancels.\n *\n * @platform iOS\n * @since 0.2.0\n */\n selectCalendarsWithPrompt(options?: SelectCalendarsWithPromptOptions): Promise<SelectCalendarsWithPromptResult>;\n /**\n * Retrieves a list of calendar sources.\n *\n * Requires calendar access. Without authorization, `result` is typically\n * an empty array. This method does not reject solely for missing permission.\n *\n * @platform iOS\n * @since 6.6.0\n */\n fetchAllCalendarSources(): Promise<FetchAllCalendarSourcesResult>;\n /**\n * Retrieves a list of all available calendars.\n *\n * Requires calendar read access. On Android, missing permission typically\n * rejects. On iOS, missing authorization typically returns an empty `result`.\n *\n * @platform Android, iOS\n * @since 7.1.0\n */\n listCalendars(): Promise<ListCalendarsResult>;\n /**\n * Retrieves the default calendar.\n *\n * Requires calendar read access. On Android, missing permission typically\n * rejects. On iOS, missing authorization typically yields `result: null`.\n *\n * The system default is the primary calendar on Android and\n * `defaultCalendarForNewEvents` on iOS. When neither exists and\n * `useFallbackCalendar` is true, the first available calendar is returned.\n * Otherwise the method returns `null` when there is no system default.\n *\n * @platform Android, iOS\n * @since 0.3.0\n */\n getDefaultCalendar(options?: GetDefaultCalendarOptions): Promise<{ result: Calendar | null }>;\n /**\n * Opens the calendar app.\n * On Web, opens a web calendar in a new tab when `provider` is set, and rejects otherwise.\n *\n * @example\n * CapacitorCalendar.openCalendar({ date: Date.now() });\n *\n * @platform Android, iOS, Web\n * @since 7.1.0\n */\n openCalendar(options?: OpenCalendarOptions): Promise<void>;\n /**\n * Creates a calendar.\n *\n * `title` is required. `color` is optional and defaults to `#007AFF`.\n * On Android, `accountName` and `ownerAccount` are required at runtime.\n *\n * @example\n * CapacitorCalendar.createCalendar({\n * title: 'Work',\n * accountName: 'plugin@example.com',\n * ownerAccount: 'plugin@example.com',\n * });\n *\n * @throws {Error} `Title must be provided.` — when `title` is missing.\n * @throws {Error} `Invalid color format.` — when `color` is present but invalid.\n * @throws {Error} `Account name must be provided.` — when `accountName` is missing on Android.\n * @throws {Error} `Owner account must be provided.` — when `ownerAccount` is missing on Android.\n * @throws {Error} `Calendar source not found.` — when `sourceId` is set and no EventKit source matches (iOS).\n * @throws {Error} `Failed to retrieve calendar ID.` — when the calendar is created but no id is returned.\n *\n * @platform Android, iOS\n * @since 5.2.0\n */\n createCalendar(options: CreateCalendarOptions): Promise<CreateCalendarResult>;\n /**\n * Deletes a calendar by id.\n *\n * @throws {Error} `Calendar ID must be provided.` — when `id` is missing.\n * @throws {Error} `Invalid calendar ID.` — when `id` is not a numeric Android calendar id.\n * @throws {Error} `Calendar not found.` — when no calendar exists for `id`.\n *\n * @platform Android, iOS\n * @since 5.2.0\n */\n deleteCalendar(options: DeleteCalendarOptions): Promise<void>;\n /**\n * Modifies a calendar with options.\n *\n * @throws {Error} `Calendar ID must be provided.` — when `id` is missing.\n * @throws {Error} `Invalid calendar ID.` — when `id` is not a numeric Android calendar id.\n * @throws {Error} `At least one of title or color must be provided.` — when both are omitted.\n * @throws {Error} `Invalid color format.` — when `color` is present but invalid.\n * @throws {Error} `Calendar not found.` — when no calendar exists for `id`.\n * @throws {Error} `Calendar is not modifiable.` — when the calendar cannot be modified (iOS).\n *\n * @platform Android, iOS\n * @since 7.2.0\n */\n modifyCalendar(options: ModifyCalendarOptions): Promise<void>;\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CalendarLinks } from '../schemas/interfaces/calendar-links';
|
|
2
|
+
import type { CreateEventOptions } from '../schemas/interfaces/create-event-options';
|
|
3
|
+
import type { CalendarDayViewProvider } from '../schemas/types/calendar-day-view-provider';
|
|
4
|
+
/**
|
|
5
|
+
* Builds links that open a web calendar with the event already filled in.
|
|
6
|
+
* The user must confirm in the web calendar. Nothing is saved without that step.
|
|
7
|
+
*
|
|
8
|
+
* Supported fields: `title`, `startDate`, `endDate`, `duration`, `isAllDay`, `description`, `location`.
|
|
9
|
+
* Google Calendar also gets `recurrence` and `attendees`. Alerts and `availability` are not part of any link.
|
|
10
|
+
* Outlook and Yahoo links ignore `recurrence`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const { google, outlook } = getCalendarLinks({ title: 'Team standup', startDate: Date.now() });
|
|
14
|
+
* window.open(google, '_blank', 'noopener');
|
|
15
|
+
*
|
|
16
|
+
* @since 8.12.0
|
|
17
|
+
*/
|
|
18
|
+
export declare function getCalendarLinks(options: CreateEventOptions): CalendarLinks;
|
|
19
|
+
/**
|
|
20
|
+
* Builds the link that opens the day view of a web calendar.
|
|
21
|
+
*
|
|
22
|
+
* @throws If `provider` is not `google`, `outlook`, or `office365`.
|
|
23
|
+
*
|
|
24
|
+
* @since 8.12.0
|
|
25
|
+
*/
|
|
26
|
+
export declare function getCalendarDayLink(provider: CalendarDayViewProvider, date: number): string;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { formatDateOnlyLocal, formatDateTimeUtc, resolveEndDate, toRRule } from './ics';
|
|
2
|
+
/**
|
|
3
|
+
* Builds links that open a web calendar with the event already filled in.
|
|
4
|
+
* The user must confirm in the web calendar. Nothing is saved without that step.
|
|
5
|
+
*
|
|
6
|
+
* Supported fields: `title`, `startDate`, `endDate`, `duration`, `isAllDay`, `description`, `location`.
|
|
7
|
+
* Google Calendar also gets `recurrence` and `attendees`. Alerts and `availability` are not part of any link.
|
|
8
|
+
* Outlook and Yahoo links ignore `recurrence`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const { google, outlook } = getCalendarLinks({ title: 'Team standup', startDate: Date.now() });
|
|
12
|
+
* window.open(google, '_blank', 'noopener');
|
|
13
|
+
*
|
|
14
|
+
* @since 8.12.0
|
|
15
|
+
*/
|
|
16
|
+
export function getCalendarLinks(options) {
|
|
17
|
+
var _a;
|
|
18
|
+
const startDate = (_a = options.startDate) !== null && _a !== void 0 ? _a : Date.now();
|
|
19
|
+
const isAllDay = options.isAllDay === true;
|
|
20
|
+
const endDate = resolveEndDate(startDate, options.endDate, options.duration, isAllDay);
|
|
21
|
+
return {
|
|
22
|
+
google: buildGoogleLink(options, startDate, endDate, isAllDay),
|
|
23
|
+
outlook: buildOutlookLink('https://outlook.live.com', options, startDate, endDate, isAllDay),
|
|
24
|
+
office365: buildOutlookLink('https://outlook.office.com', options, startDate, endDate, isAllDay),
|
|
25
|
+
yahoo: buildYahooLink(options, startDate, endDate, isAllDay),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Builds the link that opens the day view of a web calendar.
|
|
30
|
+
*
|
|
31
|
+
* @throws If `provider` is not `google`, `outlook`, or `office365`.
|
|
32
|
+
*
|
|
33
|
+
* @since 8.12.0
|
|
34
|
+
*/
|
|
35
|
+
export function getCalendarDayLink(provider, date) {
|
|
36
|
+
const day = new Date(date);
|
|
37
|
+
const datePath = `${day.getFullYear()}/${day.getMonth() + 1}/${day.getDate()}`;
|
|
38
|
+
switch (provider) {
|
|
39
|
+
case 'google':
|
|
40
|
+
return `https://calendar.google.com/calendar/r/day/${datePath}`;
|
|
41
|
+
case 'outlook':
|
|
42
|
+
return `https://outlook.live.com/calendar/0/view/day/${datePath}`;
|
|
43
|
+
case 'office365':
|
|
44
|
+
return `https://outlook.office.com/calendar/0/view/day/${datePath}`;
|
|
45
|
+
default:
|
|
46
|
+
throw new Error(`Unsupported calendar provider: ${String(provider)}. Use google, outlook, or office365.`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function buildGoogleLink(options, startDate, endDate, isAllDay) {
|
|
50
|
+
var _a;
|
|
51
|
+
const params = new URLSearchParams();
|
|
52
|
+
params.set('action', 'TEMPLATE');
|
|
53
|
+
params.set('text', options.title);
|
|
54
|
+
params.set('dates', `${formatCompactDate(startDate, isAllDay)}/${formatCompactDate(endDate, isAllDay)}`);
|
|
55
|
+
setIfPresent(params, 'details', options.description);
|
|
56
|
+
setIfPresent(params, 'location', options.location);
|
|
57
|
+
if (options.recurrence != null) {
|
|
58
|
+
params.set('recur', `RRULE:${toRRule(options.recurrence, isAllDay)}`);
|
|
59
|
+
}
|
|
60
|
+
const emails = ((_a = options.attendees) !== null && _a !== void 0 ? _a : []).map((guest) => guest.email).filter((email) => email.length > 0);
|
|
61
|
+
if (emails.length > 0) {
|
|
62
|
+
params.set('add', emails.join(','));
|
|
63
|
+
}
|
|
64
|
+
return `https://calendar.google.com/calendar/render?${toQuery(params)}`;
|
|
65
|
+
}
|
|
66
|
+
function buildOutlookLink(host, options, startDate, endDate, isAllDay) {
|
|
67
|
+
const params = new URLSearchParams();
|
|
68
|
+
params.set('path', '/calendar/action/compose');
|
|
69
|
+
params.set('rru', 'addevent');
|
|
70
|
+
params.set('subject', options.title);
|
|
71
|
+
params.set('startdt', isAllDay ? formatIsoDate(startDate) : new Date(startDate).toISOString());
|
|
72
|
+
params.set('enddt', isAllDay ? formatIsoDate(endDate) : new Date(endDate).toISOString());
|
|
73
|
+
if (isAllDay) {
|
|
74
|
+
params.set('allday', 'true');
|
|
75
|
+
}
|
|
76
|
+
setIfPresent(params, 'body', options.description);
|
|
77
|
+
setIfPresent(params, 'location', options.location);
|
|
78
|
+
return `${host}/calendar/0/deeplink/compose?${toQuery(params)}`;
|
|
79
|
+
}
|
|
80
|
+
function buildYahooLink(options, startDate, endDate, isAllDay) {
|
|
81
|
+
const params = new URLSearchParams();
|
|
82
|
+
params.set('v', '60');
|
|
83
|
+
params.set('title', options.title);
|
|
84
|
+
params.set('st', formatCompactDate(startDate, isAllDay));
|
|
85
|
+
if (isAllDay) {
|
|
86
|
+
params.set('dur', 'allday');
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
params.set('et', formatCompactDate(endDate, false));
|
|
90
|
+
}
|
|
91
|
+
setIfPresent(params, 'desc', options.description);
|
|
92
|
+
setIfPresent(params, 'in_loc', options.location);
|
|
93
|
+
return `https://calendar.yahoo.com/?${toQuery(params)}`;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Encodes spaces as `%20`, not `+`.
|
|
97
|
+
* Outlook shows a literal `+` when the link goes through its sign-in redirect.
|
|
98
|
+
*/
|
|
99
|
+
function toQuery(params) {
|
|
100
|
+
return [...params].map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('&');
|
|
101
|
+
}
|
|
102
|
+
function setIfPresent(params, key, value) {
|
|
103
|
+
if (value != null && value.length > 0) {
|
|
104
|
+
params.set(key, value);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function formatCompactDate(ms, isAllDay) {
|
|
108
|
+
return isAllDay ? formatDateOnlyLocal(ms) : formatDateTimeUtc(ms);
|
|
109
|
+
}
|
|
110
|
+
function formatIsoDate(ms) {
|
|
111
|
+
const compact = formatDateOnlyLocal(ms);
|
|
112
|
+
return `${compact.slice(0, 4)}-${compact.slice(4, 6)}-${compact.slice(6, 8)}`;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=calendar-links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-links.js","sourceRoot":"","sources":["../../../src/web/calendar-links.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAExF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA2B;;IAC1D,MAAM,SAAS,GAAG,MAAA,OAAO,CAAC,SAAS,mCAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IAClD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,KAAK,IAAI,CAAC;IAC3C,MAAM,OAAO,GAAG,cAAc,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAEvF,OAAO;QACL,MAAM,EAAE,eAAe,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC;QAC9D,OAAO,EAAE,gBAAgB,CAAC,0BAA0B,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC;QAC5F,SAAS,EAAE,gBAAgB,CAAC,4BAA4B,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC;QAChG,KAAK,EAAE,cAAc,C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C,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,kBAAkB,CAAC,GAAG,CAAC,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChH,CAAC;AAED,SAAS,YAAY,CAAC,MAAuB,EAAE,GAAW,EAAE,KAAyB;IACnF,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACzB,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,EAAU,EAAE,QAAiB;IACtD,OAAO,QAAQ,CAAC,CAAC,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;AACpE,CAAC;AAED,SAAS,aAAa,CAAC,EAAU;IAC/B,MAAM,OAAO,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAC;IACxC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AAChF,CAAC","sourcesContent":["import type { CalendarLinks } from '../schemas/interfaces/calendar-links';\nimport type { CreateEventOptions } from '../schemas/interfaces/create-event-options';\nimport type { CalendarDayViewProvider } from '../schemas/types/calendar-day-view-provider';\n\nimport { formatDateOnlyLocal, formatDateTimeUtc, resolveEndDate, toRRule } from './ics';\n\n/**\n * Builds links that open a web calendar with the event already filled in.\n * The user must confirm in the web calendar. Nothing is saved without that step.\n *\n * Supported fields: `title`, `startDate`, `endDate`, `duration`, `isAllDay`, `description`, `location`.\n * Google Calendar also gets `recurrence` and `attendees`. Alerts and `availability` are not part of any link.\n * Outlook and Yahoo links ignore `recurrence`.\n *\n * @example\n * const { google, outlook } = getCalendarLinks({ title: 'Team standup', startDate: Date.now() });\n * window.open(google, '_blank', 'noopener');\n *\n * @since 8.12.0\n */\nexport function getCalendarLinks(options: CreateEventOptions): CalendarLinks {\n const startDate = options.startDate ?? Date.now();\n const isAllDay = options.isAllDay === true;\n const endDate = resolveEndDate(startDate, options.endDate, options.duration, isAllDay);\n\n return {\n google: buildGoogleLink(options, startDate, endDate, isAllDay),\n outlook: buildOutlookLink('https://outlook.live.com', options, startDate, endDate, isAllDay),\n office365: buildOutlookLink('https://outlook.office.com', options, startDate, endDate, isAllDay),\n yahoo: buildYahooLink(options, startDate, endDate, isAllDay),\n };\n}\n\n/**\n * Builds the link that opens the day view of a web calendar.\n *\n * @throws If `provider` is not `google`, `outlook`, or `office365`.\n *\n * @since 8.12.0\n */\nexport function getCalendarDayLink(provider: CalendarDayViewProvider, date: number): string {\n const day = new Date(date);\n const datePath = `${day.getFullYear()}/${day.getMonth() + 1}/${day.getDate()}`;\n switch (provider) {\n case 'google':\n return `https://calendar.google.com/calendar/r/day/${datePath}`;\n case 'outlook':\n return `https://outlook.live.com/calendar/0/view/day/${datePath}`;\n case 'office365':\n return `https://outlook.office.com/calendar/0/view/day/${datePath}`;\n default:\n throw new Error(`Unsupported calendar provider: ${String(provider)}. Use google, outlook, or office365.`);\n }\n}\n\nfunction buildGoogleLink(options: CreateEventOptions, startDate: number, endDate: number, isAllDay: boolean): string {\n const params = new URLSearchParams();\n params.set('action', 'TEMPLATE');\n params.set('text', options.title);\n params.set('dates', `${formatCompactDate(startDate, isAllDay)}/${formatCompactDate(endDate, isAllDay)}`);\n setIfPresent(params, 'details', options.description);\n setIfPresent(params, 'location', options.location);\n if (options.recurrence != null) {\n params.set('recur', `RRULE:${toRRule(options.recurrence, isAllDay)}`);\n }\n const emails = (options.attendees ?? []).map((guest) => guest.email).filter((email) => email.length > 0);\n if (emails.length > 0) {\n params.set('add', emails.join(','));\n }\n return `https://calendar.google.com/calendar/render?${toQuery(params)}`;\n}\n\nfunction buildOutlookLink(\n host: string,\n options: CreateEventOptions,\n startDate: number,\n endDate: number,\n isAllDay: boolean,\n): string {\n const params = new URLSearchParams();\n params.set('path', '/calendar/action/compose');\n params.set('rru', 'addevent');\n params.set('subject', options.title);\n params.set('startdt', isAllDay ? formatIsoDate(startDate) : new Date(startDate).toISOString());\n params.set('enddt', isAllDay ? formatIsoDate(endDate) : new Date(endDate).toISOString());\n if (isAllDay) {\n params.set('allday', 'true');\n }\n setIfPresent(params, 'body', options.description);\n setIfPresent(params, 'location', options.location);\n return `${host}/calendar/0/deeplink/compose?${toQuery(params)}`;\n}\n\nfunction buildYahooLink(options: CreateEventOptions, startDate: number, endDate: number, isAllDay: boolean): string {\n const params = new URLSearchParams();\n params.set('v', '60');\n params.set('title', options.title);\n params.set('st', formatCompactDate(startDate, isAllDay));\n if (isAllDay) {\n params.set('dur', 'allday');\n } else {\n params.set('et', formatCompactDate(endDate, false));\n }\n setIfPresent(params, 'desc', options.description);\n setIfPresent(params, 'in_loc', options.location);\n return `https://calendar.yahoo.com/?${toQuery(params)}`;\n}\n\n/**\n * Encodes spaces as `%20`, not `+`.\n * Outlook shows a literal `+` when the link goes through its sign-in redirect.\n */\nfunction toQuery(params: URLSearchParams): string {\n return [...params].map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('&');\n}\n\nfunction setIfPresent(params: URLSearchParams, key: string, value: string | undefined): void {\n if (value != null && value.length > 0) {\n params.set(key, value);\n }\n}\n\nfunction formatCompactDate(ms: number, isAllDay: boolean): string {\n return isAllDay ? formatDateOnlyLocal(ms) : formatDateTimeUtc(ms);\n}\n\nfunction formatIsoDate(ms: number): string {\n const compact = formatDateOnlyLocal(ms);\n return `${compact.slice(0, 4)}-${compact.slice(4, 6)}-${compact.slice(6, 8)}`;\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CreateEventOptions } from '../schemas/interfaces/create-event-options';
|
|
2
|
+
import type { CreateIcsFileOptions } from '../schemas/interfaces/create-ics-file-options';
|
|
3
|
+
/**
|
|
4
|
+
* Builds an `.ics` `File` with one `VEVENT` for each event.
|
|
5
|
+
* Use it to export many events in one file, or to cancel events you exported before.
|
|
6
|
+
*
|
|
7
|
+
* @throws If `events` is empty.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const file = createIcsFile([
|
|
11
|
+
* { title: 'Kickoff', startDate: Date.now(), uid: 'kickoff-1' },
|
|
12
|
+
* { title: 'Review', startDate: Date.now() + 86400000, uid: 'review-1' },
|
|
13
|
+
* ], { fileName: 'project.ics' });
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Ask calendar apps to remove an event that was imported before
|
|
17
|
+
* const file = createIcsFile({ title: 'Kickoff', uid: 'kickoff-1', sequence: 1 }, { method: 'CANCEL' });
|
|
18
|
+
*
|
|
19
|
+
* @since 8.12.0
|
|
20
|
+
*/
|
|
21
|
+
export declare function createIcsFile(events: CreateEventOptions | CreateEventOptions[], options?: CreateIcsFileOptions): File;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { buildCalendarIcs, resolveIcsFileName } from './ics';
|
|
2
|
+
/**
|
|
3
|
+
* Builds an `.ics` `File` with one `VEVENT` for each event.
|
|
4
|
+
* Use it to export many events in one file, or to cancel events you exported before.
|
|
5
|
+
*
|
|
6
|
+
* @throws If `events` is empty.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const file = createIcsFile([
|
|
10
|
+
* { title: 'Kickoff', startDate: Date.now(), uid: 'kickoff-1' },
|
|
11
|
+
* { title: 'Review', startDate: Date.now() + 86400000, uid: 'review-1' },
|
|
12
|
+
* ], { fileName: 'project.ics' });
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Ask calendar apps to remove an event that was imported before
|
|
16
|
+
* const file = createIcsFile({ title: 'Kickoff', uid: 'kickoff-1', sequence: 1 }, { method: 'CANCEL' });
|
|
17
|
+
*
|
|
18
|
+
* @since 8.12.0
|
|
19
|
+
*/
|
|
20
|
+
export function createIcsFile(events, options = {}) {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
const list = Array.isArray(events) ? events : [events];
|
|
23
|
+
if (list.length === 0) {
|
|
24
|
+
throw new Error('createIcsFile requires at least one event.');
|
|
25
|
+
}
|
|
26
|
+
const content = buildCalendarIcs(list, (_a = options.method) !== null && _a !== void 0 ? _a : 'PUBLISH');
|
|
27
|
+
const name = resolveIcsFileName({ icsFileName: (_b = options.fileName) !== null && _b !== void 0 ? _b : list[0].icsFileName, title: list[0].title });
|
|
28
|
+
return new File([content], name, { type: 'text/calendar;charset=utf-8' });
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=create-ics-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-ics-file.js","sourceRoot":"","sources":["../../../src/web/create-ics-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE7D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAiD,EACjD,UAAgC,EAAE;;IAElC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACvD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,EAAE,MAAA,OAAO,CAAC,MAAM,mCAAI,SAAS,CAAC,CAAC;IACpE,MAAM,IAAI,GAAG,kBAAkB,CAAC,EAAE,WAAW,EAAE,MAAA,OAAO,CAAC,QAAQ,mCAAI,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IAChH,OAAO,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,6BAA6B,EAAE,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["import type { CreateEventOptions } from '../schemas/interfaces/create-event-options';\nimport type { CreateIcsFileOptions } from '../schemas/interfaces/create-ics-file-options';\n\nimport { buildCalendarIcs, resolveIcsFileName } from './ics';\n\n/**\n * Builds an `.ics` `File` with one `VEVENT` for each event.\n * Use it to export many events in one file, or to cancel events you exported before.\n *\n * @throws If `events` is empty.\n *\n * @example\n * const file = createIcsFile([\n * { title: 'Kickoff', startDate: Date.now(), uid: 'kickoff-1' },\n * { title: 'Review', startDate: Date.now() + 86400000, uid: 'review-1' },\n * ], { fileName: 'project.ics' });\n *\n * @example\n * // Ask calendar apps to remove an event that was imported before\n * const file = createIcsFile({ title: 'Kickoff', uid: 'kickoff-1', sequence: 1 }, { method: 'CANCEL' });\n *\n * @since 8.12.0\n */\nexport function createIcsFile(\n events: CreateEventOptions | CreateEventOptions[],\n options: CreateIcsFileOptions = {},\n): File {\n const list = Array.isArray(events) ? events : [events];\n if (list.length === 0) {\n throw new Error('createIcsFile requires at least one event.');\n }\n const content = buildCalendarIcs(list, options.method ?? 'PUBLISH');\n const name = resolveIcsFileName({ icsFileName: options.fileName ?? list[0].icsFileName, title: list[0].title });\n return new File([content], name, { type: 'text/calendar;charset=utf-8' });\n}\n"]}
|
package/dist/esm/web/ics.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { CreateEventOptions } from '../schemas/interfaces/create-event-options';
|
|
2
|
+
import type { EventRecurrenceRule } from '../schemas/interfaces/event-recurrence-rule';
|
|
3
|
+
export type IcsMethod = 'PUBLISH' | 'CANCEL';
|
|
2
4
|
/**
|
|
3
5
|
* Builds an RFC 5545 `VCALENDAR` document with one `VEVENT` from CreateEventOptions.
|
|
4
6
|
* End comes from `endDate`, else `duration` (RFC 2445), else one hour (or next day if all-day).
|
|
5
7
|
* All-day ends that fall on the start's local day bump to the next day (exclusive `DTEND`).
|
|
6
8
|
*/
|
|
7
9
|
export declare function buildEventIcs(options: CreateEventOptions): string;
|
|
10
|
+
/**
|
|
11
|
+
* Builds one `VCALENDAR` document with one `VEVENT` for each item in `events`.
|
|
12
|
+
* With method `CANCEL`, each event gets `STATUS:CANCELLED` and a `SEQUENCE` of at least 1.
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildCalendarIcs(events: CreateEventOptions[], method?: IcsMethod): string;
|
|
8
15
|
/**
|
|
9
16
|
* Resolves the `.ics` download filename.
|
|
10
17
|
* Uses `icsFileName` when set; otherwise derives a name from `title` (fallback `event.ics`).
|
|
@@ -17,11 +24,15 @@ export declare function resolveIcsFileName(options: Pick<CreateEventOptions, 'ic
|
|
|
17
24
|
* All-day ends that fall on the start's local day bump to the next day (exclusive `DTEND`).
|
|
18
25
|
*/
|
|
19
26
|
export declare function resolveEndDate(startDate: number, endDate: number | undefined, duration: string | undefined, isAllDay: boolean): number;
|
|
27
|
+
export declare function toRRule(rule: EventRecurrenceRule, isAllDay: boolean): string;
|
|
28
|
+
export declare function formatDateTimeUtc(ms: number): string;
|
|
29
|
+
export declare function formatDateOnlyLocal(ms: number): string;
|
|
20
30
|
/**
|
|
21
31
|
* Escapes TEXT values per RFC 5545 §3.3.11.
|
|
22
32
|
*/
|
|
23
33
|
export declare function escapeText(value: string): string;
|
|
24
34
|
/**
|
|
25
35
|
* Folds a content line so each physical line is at most 75 octets (RFC 5545 §3.1).
|
|
36
|
+
* A continuation line starts with one space, so it holds at most 74 octets of content.
|
|
26
37
|
*/
|
|
27
38
|
export declare function foldLine(line: string): string;
|
package/dist/esm/web/ics.js
CHANGED
|
@@ -8,18 +8,34 @@ const CRLF = '\r\n';
|
|
|
8
8
|
* All-day ends that fall on the start's local day bump to the next day (exclusive `DTEND`).
|
|
9
9
|
*/
|
|
10
10
|
export function buildEventIcs(options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
return buildCalendarIcs([options]);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Builds one `VCALENDAR` document with one `VEVENT` for each item in `events`.
|
|
15
|
+
* With method `CANCEL`, each event gets `STATUS:CANCELLED` and a `SEQUENCE` of at least 1.
|
|
16
|
+
*/
|
|
17
|
+
export function buildCalendarIcs(events, method = 'PUBLISH') {
|
|
15
18
|
const lines = [
|
|
16
19
|
'BEGIN:VCALENDAR',
|
|
17
20
|
'VERSION:2.0',
|
|
18
21
|
'PRODID:-//ebarooni/capacitor-calendar//EN',
|
|
19
22
|
'CALSCALE:GREGORIAN',
|
|
20
|
-
|
|
23
|
+
`METHOD:${method}`,
|
|
24
|
+
];
|
|
25
|
+
for (const event of events) {
|
|
26
|
+
lines.push(...buildEventLines(event, method));
|
|
27
|
+
}
|
|
28
|
+
lines.push('END:VCALENDAR');
|
|
29
|
+
return lines.map(foldLine).join(CRLF) + CRLF;
|
|
30
|
+
}
|
|
31
|
+
function buildEventLines(options, method) {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const startDate = (_a = options.startDate) !== null && _a !== void 0 ? _a : Date.now();
|
|
34
|
+
const isAllDay = options.isAllDay === true;
|
|
35
|
+
const endDate = resolveEndDate(startDate, options.endDate, options.duration, isAllDay);
|
|
36
|
+
const lines = [
|
|
21
37
|
'BEGIN:VEVENT',
|
|
22
|
-
`UID:${generateUid()}`,
|
|
38
|
+
`UID:${options.uid != null && options.uid.length > 0 ? escapeText(options.uid) : generateUid()}`,
|
|
23
39
|
`DTSTAMP:${formatDateTimeUtc(Date.now())}`,
|
|
24
40
|
];
|
|
25
41
|
if (isAllDay) {
|
|
@@ -64,8 +80,15 @@ export function buildEventIcs(options) {
|
|
|
64
80
|
lines.push(...buildAlarm(minutes));
|
|
65
81
|
}
|
|
66
82
|
}
|
|
67
|
-
|
|
68
|
-
|
|
83
|
+
if (method === 'CANCEL') {
|
|
84
|
+
lines.push('STATUS:CANCELLED');
|
|
85
|
+
}
|
|
86
|
+
const sequence = method === 'CANCEL' ? Math.max(1, (_b = options.sequence) !== null && _b !== void 0 ? _b : 1) : options.sequence;
|
|
87
|
+
if (sequence != null && sequence > 0) {
|
|
88
|
+
lines.push(`SEQUENCE:${Math.floor(sequence)}`);
|
|
89
|
+
}
|
|
90
|
+
lines.push('END:VEVENT');
|
|
91
|
+
return lines;
|
|
69
92
|
}
|
|
70
93
|
/**
|
|
71
94
|
* Resolves the `.ics` download filename.
|
|
@@ -157,7 +180,7 @@ function mapTransparency(availability) {
|
|
|
157
180
|
}
|
|
158
181
|
return 'OPAQUE';
|
|
159
182
|
}
|
|
160
|
-
function toRRule(rule, isAllDay) {
|
|
183
|
+
export function toRRule(rule, isAllDay) {
|
|
161
184
|
var _a;
|
|
162
185
|
const parts = [`FREQ=${rule.frequency.toUpperCase()}`, `INTERVAL=${Math.max(1, (_a = rule.interval) !== null && _a !== void 0 ? _a : 1)}`];
|
|
163
186
|
if (rule.count != null) {
|
|
@@ -217,7 +240,7 @@ function generateUid() {
|
|
|
217
240
|
}
|
|
218
241
|
return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}@capacitor-calendar`;
|
|
219
242
|
}
|
|
220
|
-
function formatDateTimeUtc(ms) {
|
|
243
|
+
export function formatDateTimeUtc(ms) {
|
|
221
244
|
const date = new Date(ms);
|
|
222
245
|
const fullYear = date.getUTCFullYear();
|
|
223
246
|
const month = padTwoDigits(date.getUTCMonth() + 1);
|
|
@@ -227,7 +250,7 @@ function formatDateTimeUtc(ms) {
|
|
|
227
250
|
const seconds = padTwoDigits(date.getUTCSeconds());
|
|
228
251
|
return `${fullYear}${month}${dayOfMonth}T${hours}${minutes}${seconds}Z`;
|
|
229
252
|
}
|
|
230
|
-
function formatDateOnlyLocal(ms) {
|
|
253
|
+
export function formatDateOnlyLocal(ms) {
|
|
231
254
|
const date = new Date(ms);
|
|
232
255
|
return `${date.getFullYear()}${padTwoDigits(date.getMonth() + 1)}${padTwoDigits(date.getDate())}`;
|
|
233
256
|
}
|
|
@@ -257,36 +280,29 @@ function formatParamValue(value) {
|
|
|
257
280
|
}
|
|
258
281
|
/**
|
|
259
282
|
* Folds a content line so each physical line is at most 75 octets (RFC 5545 §3.1).
|
|
283
|
+
* A continuation line starts with one space, so it holds at most 74 octets of content.
|
|
260
284
|
*/
|
|
261
285
|
export function foldLine(line) {
|
|
262
286
|
const max = 75;
|
|
263
287
|
if (byteLength(line) <= max) {
|
|
264
288
|
return line;
|
|
265
289
|
}
|
|
266
|
-
const
|
|
267
|
-
let result = '';
|
|
290
|
+
const parts = [];
|
|
268
291
|
let current = '';
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
result += `${CRLF} ${current}`;
|
|
278
|
-
current = '';
|
|
279
|
-
break;
|
|
280
|
-
}
|
|
292
|
+
let currentBytes = 0;
|
|
293
|
+
for (const ch of line) {
|
|
294
|
+
const chBytes = byteLength(ch);
|
|
295
|
+
const limit = parts.length === 0 ? max : max - 1;
|
|
296
|
+
if (currentBytes + chBytes > limit && current.length > 0) {
|
|
297
|
+
parts.push(current);
|
|
298
|
+
current = '';
|
|
299
|
+
currentBytes = 0;
|
|
281
300
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
if (current.length > 0) {
|
|
287
|
-
result += result.length === 0 ? current : `${CRLF} ${current}`;
|
|
301
|
+
current += ch;
|
|
302
|
+
currentBytes += chBytes;
|
|
288
303
|
}
|
|
289
|
-
|
|
304
|
+
parts.push(current);
|
|
305
|
+
return parts.join(`${CRLF} `);
|
|
290
306
|
}
|
|
291
307
|
function byteLength(s) {
|
|
292
308
|
return new TextEncoder().encode(s).length;
|
package/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;gBACb,MAAM;YACR,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,IAAI,CAAC;QACjB,CAAC;IACH,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC;IACjE,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAC5C,CAAC","sourcesContent":["import { EventAvailability } from '../schemas/enums/event-availability';\nimport type { CreateEventOptions } from '../schemas/interfaces/create-event-options';\nimport type { EventRecurrenceRule } from '../schemas/interfaces/event-recurrence-rule';\n\nconst HOUR_MS = 60 * 60 * 1000;\nconst DAY_MS = 24 * HOUR_MS;\nconst CRLF = '\\r\\n';\n\n/**\n * Builds an RFC 5545 `VCALENDAR` document with one `VEVENT` from CreateEventOptions.\n * End comes from `endDate`, else `duration` (RFC 2445), else one hour (or next day if all-day).\n * All-day ends that fall on the start's local day bump to the next day (exclusive `DTEND`).\n */\nexport function buildEventIcs(options: CreateEventOptions): string {\n const startDate = options.startDate ?? Date.now();\n const isAllDay = options.isAllDay === true;\n const endDate = resolveEndDate(startDate, options.endDate, options.duration, isAllDay);\n\n const lines: string[] = [\n 'BEGIN:VCALENDAR',\n 'VERSION:2.0',\n 'PRODID:-//ebarooni/capacitor-calendar//EN',\n 'CALSCALE:GREGORIAN',\n 'METHOD:PUBLISH',\n 'BEGIN:VEVENT',\n `UID:${generateUid()}`,\n `DTSTAMP:${formatDateTimeUtc(Date.now())}`,\n ];\n\n if (isAllDay) {\n lines.push(`DTSTART;VALUE=DATE:${formatDateOnlyLocal(startDate)}`);\n lines.push(`DTEND;VALUE=DATE:${formatDateOnlyLocal(endDate)}`);\n } else {\n lines.push(`DTSTART:${formatDateTimeUtc(startDate)}`);\n lines.push(`DTEND:${formatDateTimeUtc(endDate)}`);\n }\n\n lines.push(`SUMMARY:${escapeText(options.title)}`);\n\n if (options.description != null && options.description.length > 0) {\n lines.push(`DESCRIPTION:${escapeText(options.description)}`);\n }\n if (options.location != null && options.location.length > 0) {\n lines.push(`LOCATION:${escapeText(options.location)}`);\n }\n if (options.url != null && options.url.length > 0) {\n lines.push(`URL:${escapeText(options.url)}`);\n }\n if (options.organizer != null && options.organizer.length > 0) {\n lines.push(`ORGANIZER:mailto:${escapeText(options.organizer)}`);\n }\n\n const transp = mapTransparency(options.availability);\n if (transp != null) {\n lines.push(`TRANSP:${transp}`);\n }\n\n if (options.recurrence != null) {\n lines.push(`RRULE:${toRRule(options.recurrence, isAllDay)}`);\n }\n\n if (options.attendees != null) {\n for (const guest of options.attendees) {\n if (guest.email.length === 0) {\n continue;\n }\n const cn = guest.name != null && guest.name.length > 0 ? `;CN=${formatParamValue(guest.name)}` : '';\n lines.push(`ATTENDEE${cn}:mailto:${escapeText(guest.email)}`);\n }\n }\n\n if (options.alerts != null) {\n for (const minutes of options.alerts) {\n lines.push(...buildAlarm(minutes));\n }\n }\n\n lines.push('END:VEVENT', 'END:VCALENDAR');\n\n return lines.map(foldLine).join(CRLF) + CRLF;\n}\n\n/**\n * Resolves the `.ics` download filename.\n * Uses `icsFileName` when set; otherwise derives a name from `title` (fallback `event.ics`).\n * Appends `.ics` when the chosen name has no such extension.\n */\nexport function resolveIcsFileName(options: Pick<CreateEventOptions, 'icsFileName' | 'title'>): string {\n const custom = options.icsFileName?.trim();\n if (custom != null && custom.length > 0) {\n return /\\.ics$/i.test(custom) ? custom : `${custom}.ics`;\n }\n return fileNameFromTitle(options.title);\n}\n\nfunction fileNameFromTitle(title?: string): string {\n const base = (title ?? 'event')\n .trim()\n .replace(/[^\\w\\s-]+/g, '')\n .replace(/\\s+/g, '-')\n .replace(/-+/g, '-')\n .replace(/^-|-$/g, '')\n .slice(0, 64);\n return `${base.length > 0 ? base : 'event'}.ics`;\n}\n\n/**\n * Resolves event end milliseconds the same way ICS export does.\n * Prefers `endDate`, else `duration` (RFC 2445), else one hour (or next day if all-day).\n * All-day ends that fall on the start's local day bump to the next day (exclusive `DTEND`).\n */\nexport function resolveEndDate(\n startDate: number,\n endDate: number | undefined,\n duration: string | undefined,\n isAllDay: boolean,\n): number {\n let resolved: number;\n if (endDate != null) {\n resolved = endDate;\n } else if (duration != null && duration.trim().length > 0) {\n resolved = startDate + parseRfc2445DurationMs(duration.trim());\n } else {\n resolved = isAllDay ? startDate + DAY_MS : startDate + HOUR_MS;\n }\n\n if (!isAllDay) {\n return resolved;\n }\n\n // ICS all-day DTEND is exclusive; same local date as DTSTART is zero-length.\n // Also covers short durations (e.g. PT1H) on all-day events — treat as one whole day.\n if (formatDateOnlyLocal(resolved) <= formatDateOnlyLocal(startDate)) {\n return startDate + DAY_MS;\n }\n return resolved;\n}\n\n/**\n * Parses an RFC 2445 / RFC 5545 duration string into milliseconds.\n * Supports forms such as `PT1H`, `P1D`, `P3W`, `P2DT4H30M`.\n *\n * @throws If the string is empty, negative, zero-length, or not a valid duration.\n */\nfunction parseRfc2445DurationMs(value: string): number {\n const match = /^([+-])?P(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?$/i.exec(value);\n if (match == null) {\n throw new Error(`Invalid duration: ${value}`);\n }\n\n const sign = match[1] === '-' ? -1 : 1;\n const weeks = Number(match[2] ?? 0);\n const days = Number(match[3] ?? 0);\n const hours = Number(match[4] ?? 0);\n const minutes = Number(match[5] ?? 0);\n const seconds = Number(match[6] ?? 0);\n\n // Require at least one unit so bare \"P\" / \"PT\" are rejected.\n if (weeks === 0 && days === 0 && hours === 0 && minutes === 0 && seconds === 0) {\n throw new Error(`Invalid duration: ${value}`);\n }\n\n const ms = weeks * 7 * DAY_MS + days * DAY_MS + hours * HOUR_MS + minutes * 60 * 1000 + seconds * 1000;\n const signed = sign * ms;\n if (signed <= 0) {\n throw new Error(`Invalid duration: ${value}`);\n }\n return signed;\n}\n\nfunction mapTransparency(availability: EventAvailability | undefined): 'OPAQUE' | 'TRANSPARENT' | null {\n if (availability == null) {\n return null;\n }\n if (availability === EventAvailability.FREE) {\n return 'TRANSPARENT';\n }\n if (availability === EventAvailability.BUSY) {\n return 'OPAQUE';\n }\n return 'OPAQUE';\n}\n\nfunction toRRule(rule: EventRecurrenceRule, isAllDay: boolean): string {\n const parts: string[] = [`FREQ=${rule.frequency.toUpperCase()}`, `INTERVAL=${Math.max(1, rule.interval ?? 1)}`];\n\n if (rule.count != null) {\n parts.push(`COUNT=${rule.count}`);\n } else if (rule.end != null) {\n // RFC 5545: UNTIL must match DTSTART value type (DATE vs DATE-TIME).\n parts.push(`UNTIL=${isAllDay ? formatDateOnlyLocal(rule.end) : formatDateTimeUtc(rule.end)}`);\n }\n\n if (rule.byWeekDay != null && rule.byWeekDay.length > 0) {\n const mapped = rule.byWeekDay.map(mapWeekday).filter((d): d is string => d != null);\n if (mapped.length > 0) {\n parts.push(`BYDAY=${[...new Set(mapped)].join(',')}`);\n }\n }\n\n if (rule.byMonthDay != null && rule.byMonthDay.length > 0) {\n parts.push(`BYMONTHDAY=${rule.byMonthDay.join(',')}`);\n }\n if (rule.byMonth != null && rule.byMonth.length > 0) {\n parts.push(`BYMONTH=${rule.byMonth.join(',')}`);\n }\n if (rule.weeksOfTheYear != null && rule.weeksOfTheYear.length > 0) {\n parts.push(`BYWEEKNO=${rule.weeksOfTheYear.join(',')}`);\n }\n if (rule.daysOfTheYear != null && rule.daysOfTheYear.length > 0) {\n parts.push(`BYYEARDAY=${rule.daysOfTheYear.join(',')}`);\n }\n\n return parts.join(';');\n}\n\nfunction mapWeekday(day: number): string | null {\n switch (day) {\n case 1:\n return 'MO';\n case 2:\n return 'TU';\n case 3:\n return 'WE';\n case 4:\n return 'TH';\n case 5:\n return 'FR';\n case 6:\n return 'SA';\n case 7:\n return 'SU';\n default:\n return null;\n }\n}\n\nfunction buildAlarm(minutes: number): string[] {\n const trigger = minutes < 0 ? `-PT${Math.abs(minutes)}M` : `PT${minutes}M`;\n return ['BEGIN:VALARM', 'ACTION:DISPLAY', 'DESCRIPTION:Reminder', `TRIGGER:${trigger}`, 'END:VALARM'];\n}\n\nfunction generateUid(): string {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return `${crypto.randomUUID()}@capacitor-calendar`;\n }\n return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}@capacitor-calendar`;\n}\n\nfunction formatDateTimeUtc(ms: number): string {\n const date = new Date(ms);\n const fullYear = date.getUTCFullYear();\n const month = padTwoDigits(date.getUTCMonth() + 1);\n const dayOfMonth = padTwoDigits(date.getUTCDate());\n const hours = padTwoDigits(date.getUTCHours());\n const minutes = padTwoDigits(date.getUTCMinutes());\n const seconds = padTwoDigits(date.getUTCSeconds());\n return `${fullYear}${month}${dayOfMonth}T${hours}${minutes}${seconds}Z`;\n}\n\nfunction formatDateOnlyLocal(ms: number): string {\n const date = new Date(ms);\n return `${date.getFullYear()}${padTwoDigits(date.getMonth() + 1)}${padTwoDigits(date.getDate())}`;\n}\n\nfunction padTwoDigits(value: number): string {\n return value < 10 ? `0${value}` : String(value);\n}\n\n/**\n * Escapes TEXT values per RFC 5545 §3.3.11.\n */\nexport function escapeText(value: string): string {\n return value\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/;/g, '\\\\;')\n .replace(/,/g, '\\\\,')\n .replace(/\\r\\n|\\n|\\r/g, '\\\\n');\n}\n\n/**\n * Formats a property parameter value per RFC 5545 §3.2.\n * Values with COMMA, SEMICOLON, or COLON are quoted; DQUOTE and line breaks are sanitized.\n */\nfunction formatParamValue(value: string): string {\n const sanitized = value.replace(/[\\r\\n]+/g, ' ').replace(/\"/g, \"'\");\n if (/[;:,]/.test(sanitized)) {\n return `\"${sanitized}\"`;\n }\n return sanitized;\n}\n\n/**\n * Folds a content line so each physical line is at most 75 octets (RFC 5545 §3.1).\n */\nexport function foldLine(line: string): string {\n const max = 75;\n if (byteLength(line) <= max) {\n return line;\n }\n\n const chars = [...line];\n let result = '';\n let current = '';\n\n for (const ch of chars) {\n const next = current + ch;\n if (byteLength(next) > max) {\n result += result.length === 0 ? current : `${CRLF} ${current}`;\n current = ch;\n // Continuations are limited to 74 octets of content + leading space = 75\n while (byteLength(current) > max - 1) {\n // Extremely rare for a single code point; split by taking first unit as-is\n result += `${CRLF} ${current}`;\n current = '';\n break;\n }\n } else {\n current = next;\n }\n }\n\n if (current.length > 0) {\n result += result.length === 0 ? current : `${CRLF} ${current}`;\n }\n\n return result;\n}\n\nfunction byteLength(s: string): number {\n return new TextEncoder().encode(s).length;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ics.js","sourceRoot":"","sources":["../../../src/web/ics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAIxE,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC/B,MAAM,MAAM,GAAG,EAAE,GAAG,OAAO,CAAC;AAC5B,MAAM,IAAI,GAAG,MAAM,CAAC;AAIpB;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,OAA2B;IACvD,OAAO,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;AACrC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAA4B,EAAE,SAAoB,SAAS;IAC1F,MAAM,KAAK,GAAa;QACtB,iBAAiB;QACjB,aAAa;QACb,2CAA2C;QAC3C,oBAAoB;QACpB,UAAU,MAAM,EAAE;KACnB,CAAC;IACF,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAChD,CAAC;IAC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QACjD,IAAI,YAAY,GAAG,OAAO,GAAG,KAAK,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACpB,OAAO,GAAG,EAAE,CAAC;YACb,YAAY,GAAG,CAAC,CAAC;QACnB,CAAC;QACD,OAAO,IAAI,EAAE,CAAC;QACd,YAAY,IAAI,OAAO,CAAC;IAC1B,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAEpB,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAC5C,CAAC","sourcesContent":["import { EventAvailability } from '../schemas/enums/event-availability';\nimport type { CreateEventOptions } from '../schemas/interfaces/create-event-options';\nimport type { EventRecurrenceRule } from '../schemas/interfaces/event-recurrence-rule';\n\nconst HOUR_MS = 60 * 60 * 1000;\nconst DAY_MS = 24 * HOUR_MS;\nconst CRLF = '\\r\\n';\n\nexport type IcsMethod = 'PUBLISH' | 'CANCEL';\n\n/**\n * Builds an RFC 5545 `VCALENDAR` document with one `VEVENT` from CreateEventOptions.\n * End comes from `endDate`, else `duration` (RFC 2445), else one hour (or next day if all-day).\n * All-day ends that fall on the start's local day bump to the next day (exclusive `DTEND`).\n */\nexport function buildEventIcs(options: CreateEventOptions): string {\n return buildCalendarIcs([options]);\n}\n\n/**\n * Builds one `VCALENDAR` document with one `VEVENT` for each item in `events`.\n * With method `CANCEL`, each event gets `STATUS:CANCELLED` and a `SEQUENCE` of at least 1.\n */\nexport function buildCalendarIcs(events: CreateEventOptions[], method: IcsMethod = 'PUBLISH'): string {\n const lines: string[] = [\n 'BEGIN:VCALENDAR',\n 'VERSION:2.0',\n 'PRODID:-//ebarooni/capacitor-calendar//EN',\n 'CALSCALE:GREGORIAN',\n `METHOD:${method}`,\n ];\n for (const event of events) {\n lines.push(...buildEventLines(event, method));\n }\n lines.push('END:VCALENDAR');\n return lines.map(foldLine).join(CRLF) + CRLF;\n}\n\nfunction buildEventLines(options: CreateEventOptions, method: IcsMethod): string[] {\n const startDate = options.startDate ?? Date.now();\n const isAllDay = options.isAllDay === true;\n const endDate = resolveEndDate(startDate, options.endDate, options.duration, isAllDay);\n\n const lines: string[] = [\n 'BEGIN:VEVENT',\n `UID:${options.uid != null && options.uid.length > 0 ? escapeText(options.uid) : generateUid()}`,\n `DTSTAMP:${formatDateTimeUtc(Date.now())}`,\n ];\n if (isAllDay) {\n lines.push(`DTSTART;VALUE=DATE:${formatDateOnlyLocal(startDate)}`);\n lines.push(`DTEND;VALUE=DATE:${formatDateOnlyLocal(endDate)}`);\n } else {\n lines.push(`DTSTART:${formatDateTimeUtc(startDate)}`);\n lines.push(`DTEND:${formatDateTimeUtc(endDate)}`);\n }\n\n lines.push(`SUMMARY:${escapeText(options.title)}`);\n\n if (options.description != null && options.description.length > 0) {\n lines.push(`DESCRIPTION:${escapeText(options.description)}`);\n }\n if (options.location != null && options.location.length > 0) {\n lines.push(`LOCATION:${escapeText(options.location)}`);\n }\n if (options.url != null && options.url.length > 0) {\n lines.push(`URL:${escapeText(options.url)}`);\n }\n if (options.organizer != null && options.organizer.length > 0) {\n lines.push(`ORGANIZER:mailto:${escapeText(options.organizer)}`);\n }\n\n const transp = mapTransparency(options.availability);\n if (transp != null) {\n lines.push(`TRANSP:${transp}`);\n }\n\n if (options.recurrence != null) {\n lines.push(`RRULE:${toRRule(options.recurrence, isAllDay)}`);\n }\n\n if (options.attendees != null) {\n for (const guest of options.attendees) {\n if (guest.email.length === 0) {\n continue;\n }\n const cn = guest.name != null && guest.name.length > 0 ? `;CN=${formatParamValue(guest.name)}` : '';\n lines.push(`ATTENDEE${cn}:mailto:${escapeText(guest.email)}`);\n }\n }\n\n if (options.alerts != null) {\n for (const minutes of options.alerts) {\n lines.push(...buildAlarm(minutes));\n }\n }\n\n if (method === 'CANCEL') {\n lines.push('STATUS:CANCELLED');\n }\n\n const sequence = method === 'CANCEL' ? Math.max(1, options.sequence ?? 1) : options.sequence;\n if (sequence != null && sequence > 0) {\n lines.push(`SEQUENCE:${Math.floor(sequence)}`);\n }\n\n lines.push('END:VEVENT');\n return lines;\n}\n\n/**\n * Resolves the `.ics` download filename.\n * Uses `icsFileName` when set; otherwise derives a name from `title` (fallback `event.ics`).\n * Appends `.ics` when the chosen name has no such extension.\n */\nexport function resolveIcsFileName(options: Pick<CreateEventOptions, 'icsFileName' | 'title'>): string {\n const custom = options.icsFileName?.trim();\n if (custom != null && custom.length > 0) {\n return /\\.ics$/i.test(custom) ? custom : `${custom}.ics`;\n }\n return fileNameFromTitle(options.title);\n}\n\nfunction fileNameFromTitle(title?: string): string {\n const base = (title ?? 'event')\n .trim()\n .replace(/[^\\w\\s-]+/g, '')\n .replace(/\\s+/g, '-')\n .replace(/-+/g, '-')\n .replace(/^-|-$/g, '')\n .slice(0, 64);\n return `${base.length > 0 ? base : 'event'}.ics`;\n}\n\n/**\n * Resolves event end milliseconds the same way ICS export does.\n * Prefers `endDate`, else `duration` (RFC 2445), else one hour (or next day if all-day).\n * All-day ends that fall on the start's local day bump to the next day (exclusive `DTEND`).\n */\nexport function resolveEndDate(\n startDate: number,\n endDate: number | undefined,\n duration: string | undefined,\n isAllDay: boolean,\n): number {\n let resolved: number;\n if (endDate != null) {\n resolved = endDate;\n } else if (duration != null && duration.trim().length > 0) {\n resolved = startDate + parseRfc2445DurationMs(duration.trim());\n } else {\n resolved = isAllDay ? startDate + DAY_MS : startDate + HOUR_MS;\n }\n\n if (!isAllDay) {\n return resolved;\n }\n\n // ICS all-day DTEND is exclusive; same local date as DTSTART is zero-length.\n // Also covers short durations (e.g. PT1H) on all-day events — treat as one whole day.\n if (formatDateOnlyLocal(resolved) <= formatDateOnlyLocal(startDate)) {\n return startDate + DAY_MS;\n }\n return resolved;\n}\n\n/**\n * Parses an RFC 2445 / RFC 5545 duration string into milliseconds.\n * Supports forms such as `PT1H`, `P1D`, `P3W`, `P2DT4H30M`.\n *\n * @throws If the string is empty, negative, zero-length, or not a valid duration.\n */\nfunction parseRfc2445DurationMs(value: string): number {\n const match = /^([+-])?P(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?$/i.exec(value);\n if (match == null) {\n throw new Error(`Invalid duration: ${value}`);\n }\n\n const sign = match[1] === '-' ? -1 : 1;\n const weeks = Number(match[2] ?? 0);\n const days = Number(match[3] ?? 0);\n const hours = Number(match[4] ?? 0);\n const minutes = Number(match[5] ?? 0);\n const seconds = Number(match[6] ?? 0);\n\n // Require at least one unit so bare \"P\" / \"PT\" are rejected.\n if (weeks === 0 && days === 0 && hours === 0 && minutes === 0 && seconds === 0) {\n throw new Error(`Invalid duration: ${value}`);\n }\n\n const ms = weeks * 7 * DAY_MS + days * DAY_MS + hours * HOUR_MS + minutes * 60 * 1000 + seconds * 1000;\n const signed = sign * ms;\n if (signed <= 0) {\n throw new Error(`Invalid duration: ${value}`);\n }\n return signed;\n}\n\nfunction mapTransparency(availability: EventAvailability | undefined): 'OPAQUE' | 'TRANSPARENT' | null {\n if (availability == null) {\n return null;\n }\n if (availability === EventAvailability.FREE) {\n return 'TRANSPARENT';\n }\n if (availability === EventAvailability.BUSY) {\n return 'OPAQUE';\n }\n return 'OPAQUE';\n}\n\nexport function toRRule(rule: EventRecurrenceRule, isAllDay: boolean): string {\n const parts: string[] = [`FREQ=${rule.frequency.toUpperCase()}`, `INTERVAL=${Math.max(1, rule.interval ?? 1)}`];\n\n if (rule.count != null) {\n parts.push(`COUNT=${rule.count}`);\n } else if (rule.end != null) {\n // RFC 5545: UNTIL must match DTSTART value type (DATE vs DATE-TIME).\n parts.push(`UNTIL=${isAllDay ? formatDateOnlyLocal(rule.end) : formatDateTimeUtc(rule.end)}`);\n }\n\n if (rule.byWeekDay != null && rule.byWeekDay.length > 0) {\n const mapped = rule.byWeekDay.map(mapWeekday).filter((d): d is string => d != null);\n if (mapped.length > 0) {\n parts.push(`BYDAY=${[...new Set(mapped)].join(',')}`);\n }\n }\n\n if (rule.byMonthDay != null && rule.byMonthDay.length > 0) {\n parts.push(`BYMONTHDAY=${rule.byMonthDay.join(',')}`);\n }\n if (rule.byMonth != null && rule.byMonth.length > 0) {\n parts.push(`BYMONTH=${rule.byMonth.join(',')}`);\n }\n if (rule.weeksOfTheYear != null && rule.weeksOfTheYear.length > 0) {\n parts.push(`BYWEEKNO=${rule.weeksOfTheYear.join(',')}`);\n }\n if (rule.daysOfTheYear != null && rule.daysOfTheYear.length > 0) {\n parts.push(`BYYEARDAY=${rule.daysOfTheYear.join(',')}`);\n }\n\n return parts.join(';');\n}\n\nfunction mapWeekday(day: number): string | null {\n switch (day) {\n case 1:\n return 'MO';\n case 2:\n return 'TU';\n case 3:\n return 'WE';\n case 4:\n return 'TH';\n case 5:\n return 'FR';\n case 6:\n return 'SA';\n case 7:\n return 'SU';\n default:\n return null;\n }\n}\n\nfunction buildAlarm(minutes: number): string[] {\n const trigger = minutes < 0 ? `-PT${Math.abs(minutes)}M` : `PT${minutes}M`;\n return ['BEGIN:VALARM', 'ACTION:DISPLAY', 'DESCRIPTION:Reminder', `TRIGGER:${trigger}`, 'END:VALARM'];\n}\n\nfunction generateUid(): string {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return `${crypto.randomUUID()}@capacitor-calendar`;\n }\n return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}@capacitor-calendar`;\n}\n\nexport function formatDateTimeUtc(ms: number): string {\n const date = new Date(ms);\n const fullYear = date.getUTCFullYear();\n const month = padTwoDigits(date.getUTCMonth() + 1);\n const dayOfMonth = padTwoDigits(date.getUTCDate());\n const hours = padTwoDigits(date.getUTCHours());\n const minutes = padTwoDigits(date.getUTCMinutes());\n const seconds = padTwoDigits(date.getUTCSeconds());\n return `${fullYear}${month}${dayOfMonth}T${hours}${minutes}${seconds}Z`;\n}\n\nexport function formatDateOnlyLocal(ms: number): string {\n const date = new Date(ms);\n return `${date.getFullYear()}${padTwoDigits(date.getMonth() + 1)}${padTwoDigits(date.getDate())}`;\n}\n\nfunction padTwoDigits(value: number): string {\n return value < 10 ? `0${value}` : String(value);\n}\n\n/**\n * Escapes TEXT values per RFC 5545 §3.3.11.\n */\nexport function escapeText(value: string): string {\n return value\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/;/g, '\\\\;')\n .replace(/,/g, '\\\\,')\n .replace(/\\r\\n|\\n|\\r/g, '\\\\n');\n}\n\n/**\n * Formats a property parameter value per RFC 5545 §3.2.\n * Values with COMMA, SEMICOLON, or COLON are quoted; DQUOTE and line breaks are sanitized.\n */\nfunction formatParamValue(value: string): string {\n const sanitized = value.replace(/[\\r\\n]+/g, ' ').replace(/\"/g, \"'\");\n if (/[;:,]/.test(sanitized)) {\n return `\"${sanitized}\"`;\n }\n return sanitized;\n}\n\n/**\n * Folds a content line so each physical line is at most 75 octets (RFC 5545 §3.1).\n * A continuation line starts with one space, so it holds at most 74 octets of content.\n */\nexport function foldLine(line: string): string {\n const max = 75;\n if (byteLength(line) <= max) {\n return line;\n }\n\n const parts: string[] = [];\n let current = '';\n let currentBytes = 0;\n\n for (const ch of line) {\n const chBytes = byteLength(ch);\n const limit = parts.length === 0 ? max : max - 1;\n if (currentBytes + chBytes > limit && current.length > 0) {\n parts.push(current);\n current = '';\n currentBytes = 0;\n }\n current += ch;\n currentBytes += chBytes;\n }\n parts.push(current);\n\n return parts.join(`${CRLF} `);\n}\n\nfunction byteLength(s: string): number {\n return new TextEncoder().encode(s).length;\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ShareIcsFileOptions } from '../schemas/interfaces/share-ics-file-options';
|
|
2
|
+
/**
|
|
3
|
+
* Opens the share sheet of the device for an `.ics` `File`.
|
|
4
|
+
* When the browser cannot share files, the file downloads instead.
|
|
5
|
+
* Call it from a user action, such as a click. Browsers reject the share sheet otherwise.
|
|
6
|
+
* Build the file synchronously (for example with `createIcsFile`) so the click still counts when the sheet opens.
|
|
7
|
+
* Some browsers, such as Chrome, do not share `.ics` files and download them instead.
|
|
8
|
+
* Chrome can report that it shares the file and then reject with `NotAllowedError`, so that error also falls back to a download.
|
|
9
|
+
*
|
|
10
|
+
* Resolves `'shared'` after the user picks a target, `'cancelled'` when the user closes the sheet,
|
|
11
|
+
* and `'downloaded'` when the browser fell back to a download.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* button.addEventListener('click', async () => {
|
|
15
|
+
* const file = createIcsFile({ title: 'Team standup', startDate: Date.now() });
|
|
16
|
+
* await shareIcsFile(file, { title: 'Team standup' });
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* @since 8.12.0
|
|
20
|
+
*/
|
|
21
|
+
export declare function shareIcsFile(file: File, options?: ShareIcsFileOptions): Promise<'shared' | 'cancelled' | 'downloaded'>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { downloadIcsFile } from './download-ics-file';
|
|
2
|
+
/**
|
|
3
|
+
* Opens the share sheet of the device for an `.ics` `File`.
|
|
4
|
+
* When the browser cannot share files, the file downloads instead.
|
|
5
|
+
* Call it from a user action, such as a click. Browsers reject the share sheet otherwise.
|
|
6
|
+
* Build the file synchronously (for example with `createIcsFile`) so the click still counts when the sheet opens.
|
|
7
|
+
* Some browsers, such as Chrome, do not share `.ics` files and download them instead.
|
|
8
|
+
* Chrome can report that it shares the file and then reject with `NotAllowedError`, so that error also falls back to a download.
|
|
9
|
+
*
|
|
10
|
+
* Resolves `'shared'` after the user picks a target, `'cancelled'` when the user closes the sheet,
|
|
11
|
+
* and `'downloaded'` when the browser fell back to a download.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* button.addEventListener('click', async () => {
|
|
15
|
+
* const file = createIcsFile({ title: 'Team standup', startDate: Date.now() });
|
|
16
|
+
* await shareIcsFile(file, { title: 'Team standup' });
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* @since 8.12.0
|
|
20
|
+
*/
|
|
21
|
+
export async function shareIcsFile(file, options = {}) {
|
|
22
|
+
const shareData = { files: [file], title: options.title, text: options.text };
|
|
23
|
+
if (typeof navigator === 'undefined' ||
|
|
24
|
+
typeof navigator.share !== 'function' ||
|
|
25
|
+
typeof navigator.canShare !== 'function' ||
|
|
26
|
+
!navigator.canShare(shareData)) {
|
|
27
|
+
await downloadIcsFile(file);
|
|
28
|
+
return 'downloaded';
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
await navigator.share(shareData);
|
|
32
|
+
return 'shared';
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
36
|
+
return 'cancelled';
|
|
37
|
+
}
|
|
38
|
+
// Chrome: canShare() accepts the file, but share() rejects the file type with "Permission denied"
|
|
39
|
+
if (error instanceof DOMException && error.name === 'NotAllowedError') {
|
|
40
|
+
await downloadIcsFile(file);
|
|
41
|
+
return 'downloaded';
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=share-ics-file.js.map
|