@ebarooni/capacitor-calendar 8.4.0 → 8.5.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.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @since 8.5.0
3
+ */
4
+ export interface CreateEventResult {
5
+ /**
6
+ * An `.ics` file (`text/calendar`) with one `VEVENT`.
7
+ * Present only on Web. The plugin does not write to a calendar store or start a download;
8
+ * use `downloadIcsFile(...)` or pass the `File` to another API.
9
+ *
10
+ * @platform Web
11
+ * @since 8.5.0
12
+ */
13
+ ics?: File;
14
+ /**
15
+ * The identifier of the created event.
16
+ * Always `null` on Web.
17
+ * Present on Android and iOS after a successful create.
18
+ *
19
+ * @platform Android, iOS
20
+ * @since 0.4.0
21
+ */
22
+ id: string | null;
23
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=create-event-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-event-result.js","sourceRoot":"","sources":["../../../../src/schemas/interfaces/create-event-result.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * @since 8.5.0\n */\nexport interface CreateEventResult {\n /**\n * An `.ics` file (`text/calendar`) with one `VEVENT`.\n * Present only on Web. The plugin does not write to a calendar store or start a download;\n * use `downloadIcsFile(...)` or pass the `File` to another API.\n *\n * @platform Web\n * @since 8.5.0\n */\n ics?: File;\n /**\n * The identifier of the created event.\n * Always `null` on Web.\n * Present on Android and iOS after a successful create.\n *\n * @platform Android, iOS\n * @since 0.4.0\n */\n id: string | null;\n}\n"]}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @since 8.5.0
3
+ */
4
+ export interface CreateEventWithPromptResult {
5
+ /**
6
+ * The identifier of the created event.
7
+ * Always `null` on Android.
8
+ * Present on iOS when the user saves.
9
+ *
10
+ * @platform Android, iOS
11
+ * @since 0.1.0
12
+ */
13
+ id: string | null;
14
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=create-event-with-prompt-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-event-with-prompt-result.js","sourceRoot":"","sources":["../../../../src/schemas/interfaces/create-event-with-prompt-result.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * @since 8.5.0\n */\nexport interface CreateEventWithPromptResult {\n /**\n * The identifier of the created event.\n * Always `null` on Android.\n * Present on iOS when the user saves.\n *\n * @platform Android, iOS\n * @since 0.1.0\n */\n id: string | null;\n}\n"]}
@@ -1,6 +1,8 @@
1
1
  import type { CalendarEvent } from '../schemas/interfaces/calendar-event';
2
2
  import type { CreateEventOptions } from '../schemas/interfaces/create-event-options';
3
+ import type { CreateEventResult } from '../schemas/interfaces/create-event-result';
3
4
  import type { CreateEventWithPromptOptions } from '../schemas/interfaces/create-event-with-prompt-options';
5
+ import type { CreateEventWithPromptResult } from '../schemas/interfaces/create-event-with-prompt-result';
4
6
  import type { DeleteEventOptions } from '../schemas/interfaces/delete-event-options';
5
7
  import type { DeleteEventWithPromptOptions } from '../schemas/interfaces/delete-event-with-prompt-options';
6
8
  import type { DeleteEventsByIdOptions } from '../schemas/interfaces/delete-events-by-id-options';
@@ -11,7 +13,7 @@ import type { EventEditAction } from '../schemas/types/event-edit-action';
11
13
  export interface EventOperations {
12
14
  /**
13
15
  * Opens the system calendar interface to create a new event.
14
- * On Android always returns `null`.
16
+ * On Android always returns `null` for `id`.
15
17
  * Fetch the events to find the ID of the newly created event.
16
18
  *
17
19
  * @example
@@ -24,9 +26,7 @@ export interface EventOperations {
24
26
  * @platform Android, iOS
25
27
  * @since 0.1.0
26
28
  */
27
- createEventWithPrompt(options?: CreateEventWithPromptOptions): Promise<{
28
- id: string | null;
29
- }>;
29
+ createEventWithPrompt(options?: CreateEventWithPromptOptions): Promise<CreateEventWithPromptResult>;
30
30
  /**
31
31
  * Opens a system calendar interface to modify an event.
32
32
  * On Android always returns `null`.
@@ -46,13 +46,25 @@ export interface EventOperations {
46
46
  }>;
47
47
  /**
48
48
  * Creates an event in the calendar.
49
+ * On Android and iOS, inserts into the system calendar and returns its `id`.
50
+ * On Web, there is no system calendar store: builds an `.ics` `File` as `ics`.
51
+ * The app must download or open that file (for example with `downloadIcsFile(...)`);
52
+ * this method does not trigger a download.
53
+ *
54
+ * @example
55
+ * const { id, ics } = await CapacitorCalendar.createEvent({
56
+ * title: 'Team standup',
57
+ * startDate: Date.now(),
58
+ * icsFileName: 'team-standup.ics',
59
+ * });
60
+ * if (ics) {
61
+ * await downloadIcsFile(ics);
62
+ * }
49
63
  *
50
- * @platform iOS, Android
64
+ * @platform Android, iOS, Web
51
65
  * @since 0.4.0
52
66
  */
53
- createEvent(options: CreateEventOptions): Promise<{
54
- id: string;
55
- }>;
67
+ createEvent(options: CreateEventOptions): Promise<CreateEventResult>;
56
68
  /**
57
69
  * Modifies an event.
58
70
  *
@@ -1 +1 @@
1
- {"version":3,"file":"event-operations.js","sourceRoot":"","sources":["../../../src/sub-definitions/event-operations.ts"],"names":[],"mappings":"","sourcesContent":["import type { CalendarEvent } from '../schemas/interfaces/calendar-event';\nimport type { CreateEventOptions } from '../schemas/interfaces/create-event-options';\nimport type { CreateEventWithPromptOptions } from '../schemas/interfaces/create-event-with-prompt-options';\nimport type { DeleteEventOptions } from '../schemas/interfaces/delete-event-options';\nimport type { DeleteEventWithPromptOptions } from '../schemas/interfaces/delete-event-with-prompt-options';\nimport type { DeleteEventsByIdOptions } from '../schemas/interfaces/delete-events-by-id-options';\nimport type { ListEventsInRangeOptions } from '../schemas/interfaces/list-events-in-range-options';\nimport type { ModifyEventOptions } from '../schemas/interfaces/modify-event-options';\nimport type { ModifyEventWithPromptOptions } from '../schemas/interfaces/modify-event-with-prompt-options';\nimport type { EventEditAction } from '../schemas/types/event-edit-action';\n\nexport interface EventOperations {\n /**\n * Opens the system calendar interface to create a new event.\n * On Android always returns `null`.\n * Fetch the events to find the ID of the newly created event.\n *\n * @example\n * const options = {\n * title: 'Test event',\n * startDate: Date.now(),\n * }\n * await CapacitorCalendar.createEventWithPrompt(options)\n *\n * @platform Android, iOS\n * @since 0.1.0\n */\n createEventWithPrompt(options?: CreateEventWithPromptOptions): Promise<{ id: string | null }>;\n /**\n * Opens a system calendar interface to modify an event.\n * On Android always returns `null`.\n *\n * @example\n * const options = {\n * id: 'EVENT_ID',\n * title: 'New title',\n * }\n * await CapacitorCalendar.modifyEventWithPrompt(options);\n *\n * @platform Android, iOS\n * @since 6.6.0\n */\n modifyEventWithPrompt(options: ModifyEventWithPromptOptions): Promise<{ result: EventEditAction | null }>;\n /**\n * Creates an event in the calendar.\n *\n * @platform iOS, Android\n * @since 0.4.0\n */\n createEvent(options: CreateEventOptions): Promise<{ id: string }>;\n /**\n * Modifies an event.\n *\n * @platform Android, iOS\n * @since 6.6.0\n */\n modifyEvent(options: ModifyEventOptions): Promise<void>;\n /**\n * Deletes multiple events.\n *\n * @deprecated Use `deleteEvent(...)`.\n * @platform Android, iOS\n * @since 0.11.0\n */\n deleteEventsById(options: DeleteEventsByIdOptions): Promise<{ result: DeleteEventsByIdResult }>;\n /**\n * Deletes an event.\n *\n * @platform Android, iOS\n * @since 7.1.0\n */\n deleteEvent(options: DeleteEventOptions): Promise<void>;\n /**\n * Opens a dialog to delete an event.\n *\n * @platform Android, iOS\n * @since 7.1.0\n */\n deleteEventWithPrompt(options: DeleteEventWithPromptOptions): Promise<{ deleted: boolean }>;\n /**\n * Retrieves events that overlap a date range.\n *\n * An event is included when its time interval intersects `[from, to]`, including\n * multi-day events that span the range without starting or ending inside it.\n *\n * @example\n * const startOfDay = new Date();\n * startOfDay.setHours(0, 0, 0, 0);\n * const startOfNextDay = new Date(startOfDay);\n * startOfNextDay.setDate(startOfNextDay.getDate() + 1);\n *\n * const { result } = await CapacitorCalendar.listEventsInRange({\n * from: startOfDay.getTime(),\n * to: startOfNextDay.getTime(),\n * });\n *\n * @platform Android, iOS\n * @since 0.10.0\n */\n listEventsInRange(options: ListEventsInRangeOptions): Promise<{ result: CalendarEvent[] }>;\n}\n\n/**\n * @since 7.1.0\n */\nexport interface DeleteEventsByIdResult {\n /**\n * @since 7.1.0\n */\n deleted: string[];\n /**\n * @since 7.1.0\n */\n failed: string[];\n}\n"]}
1
+ {"version":3,"file":"event-operations.js","sourceRoot":"","sources":["../../../src/sub-definitions/event-operations.ts"],"names":[],"mappings":"","sourcesContent":["import type { CalendarEvent } from '../schemas/interfaces/calendar-event';\nimport type { CreateEventOptions } from '../schemas/interfaces/create-event-options';\nimport type { CreateEventResult } from '../schemas/interfaces/create-event-result';\nimport type { CreateEventWithPromptOptions } from '../schemas/interfaces/create-event-with-prompt-options';\nimport type { CreateEventWithPromptResult } from '../schemas/interfaces/create-event-with-prompt-result';\nimport type { DeleteEventOptions } from '../schemas/interfaces/delete-event-options';\nimport type { DeleteEventWithPromptOptions } from '../schemas/interfaces/delete-event-with-prompt-options';\nimport type { DeleteEventsByIdOptions } from '../schemas/interfaces/delete-events-by-id-options';\nimport type { ListEventsInRangeOptions } from '../schemas/interfaces/list-events-in-range-options';\nimport type { ModifyEventOptions } from '../schemas/interfaces/modify-event-options';\nimport type { ModifyEventWithPromptOptions } from '../schemas/interfaces/modify-event-with-prompt-options';\nimport type { EventEditAction } from '../schemas/types/event-edit-action';\n\nexport interface EventOperations {\n /**\n * Opens the system calendar interface to create a new event.\n * On Android always returns `null` for `id`.\n * Fetch the events to find the ID of the newly created event.\n *\n * @example\n * const options = {\n * title: 'Test event',\n * startDate: Date.now(),\n * }\n * await CapacitorCalendar.createEventWithPrompt(options)\n *\n * @platform Android, iOS\n * @since 0.1.0\n */\n createEventWithPrompt(options?: CreateEventWithPromptOptions): Promise<CreateEventWithPromptResult>;\n /**\n * Opens a system calendar interface to modify an event.\n * On Android always returns `null`.\n *\n * @example\n * const options = {\n * id: 'EVENT_ID',\n * title: 'New title',\n * }\n * await CapacitorCalendar.modifyEventWithPrompt(options);\n *\n * @platform Android, iOS\n * @since 6.6.0\n */\n modifyEventWithPrompt(options: ModifyEventWithPromptOptions): Promise<{ result: EventEditAction | null }>;\n /**\n * Creates an event in the calendar.\n * On Android and iOS, inserts into the system calendar and returns its `id`.\n * On Web, there is no system calendar store: builds an `.ics` `File` as `ics`.\n * The app must download or open that file (for example with `downloadIcsFile(...)`);\n * this method does not trigger a download.\n *\n * @example\n * const { id, ics } = await CapacitorCalendar.createEvent({\n * title: 'Team standup',\n * startDate: Date.now(),\n * icsFileName: 'team-standup.ics',\n * });\n * if (ics) {\n * await downloadIcsFile(ics);\n * }\n *\n * @platform Android, iOS, Web\n * @since 0.4.0\n */\n createEvent(options: CreateEventOptions): Promise<CreateEventResult>;\n /**\n * Modifies an event.\n *\n * @platform Android, iOS\n * @since 6.6.0\n */\n modifyEvent(options: ModifyEventOptions): Promise<void>;\n /**\n * Deletes multiple events.\n *\n * @deprecated Use `deleteEvent(...)`.\n * @platform Android, iOS\n * @since 0.11.0\n */\n deleteEventsById(options: DeleteEventsByIdOptions): Promise<{ result: DeleteEventsByIdResult }>;\n /**\n * Deletes an event.\n *\n * @platform Android, iOS\n * @since 7.1.0\n */\n deleteEvent(options: DeleteEventOptions): Promise<void>;\n /**\n * Opens a dialog to delete an event.\n *\n * @platform Android, iOS\n * @since 7.1.0\n */\n deleteEventWithPrompt(options: DeleteEventWithPromptOptions): Promise<{ deleted: boolean }>;\n /**\n * Retrieves events that overlap a date range.\n *\n * An event is included when its time interval intersects `[from, to]`, including\n * multi-day events that span the range without starting or ending inside it.\n *\n * @example\n * const startOfDay = new Date();\n * startOfDay.setHours(0, 0, 0, 0);\n * const startOfNextDay = new Date(startOfDay);\n * startOfNextDay.setDate(startOfNextDay.getDate() + 1);\n *\n * const { result } = await CapacitorCalendar.listEventsInRange({\n * from: startOfDay.getTime(),\n * to: startOfNextDay.getTime(),\n * });\n *\n * @platform Android, iOS\n * @since 0.10.0\n */\n listEventsInRange(options: ListEventsInRangeOptions): Promise<{ result: CalendarEvent[] }>;\n}\n\n/**\n * @since 7.1.0\n */\nexport interface DeleteEventsByIdResult {\n /**\n * @since 7.1.0\n */\n deleted: string[];\n /**\n * @since 7.1.0\n */\n failed: string[];\n}\n"]}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Triggers a browser download for an `.ics` `File`.
3
+ * Resolves after the object URL is revoked.
4
+ *
5
+ * @throws If `document` or `URL` is not available.
6
+ *
7
+ * @example
8
+ * const { ics } = await CapacitorCalendar.createEvent({
9
+ * title: 'Team standup',
10
+ * icsFileName: 'team-standup.ics',
11
+ * });
12
+ * if (ics) {
13
+ * await downloadIcsFile(ics);
14
+ * }
15
+ *
16
+ * @since 8.5.0
17
+ */
18
+ export declare function downloadIcsFile(file: File): Promise<void>;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Triggers a browser download for an `.ics` `File`.
3
+ * Resolves after the object URL is revoked.
4
+ *
5
+ * @throws If `document` or `URL` is not available.
6
+ *
7
+ * @example
8
+ * const { ics } = await CapacitorCalendar.createEvent({
9
+ * title: 'Team standup',
10
+ * icsFileName: 'team-standup.ics',
11
+ * });
12
+ * if (ics) {
13
+ * await downloadIcsFile(ics);
14
+ * }
15
+ *
16
+ * @since 8.5.0
17
+ */
18
+ export async function downloadIcsFile(file) {
19
+ if (typeof document === 'undefined' || typeof URL === 'undefined') {
20
+ throw new Error('downloadIcsFile requires a browser document environment.');
21
+ }
22
+ const url = URL.createObjectURL(file);
23
+ const link = document.createElement('a');
24
+ link.href = url;
25
+ link.download = file.name.length > 0 ? file.name : 'event.ics';
26
+ document.body.appendChild(link);
27
+ link.click();
28
+ link.remove();
29
+ // Delay revoke so the browser can start the download
30
+ await new Promise((resolve) => setTimeout(resolve, 1000));
31
+ URL.revokeObjectURL(url);
32
+ }
33
+ //# sourceMappingURL=download-ics-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download-ics-file.js","sourceRoot":"","sources":["../../../src/web/download-ics-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAU;IAC9C,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,OAAO,GAAG,KAAK,WAAW,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAChB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC;IAC/D,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK,EAAE,CAAC;IACb,IAAI,CAAC,MAAM,EAAE,CAAC;IACd,qDAAqD;IACrD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1D,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["/**\n * Triggers a browser download for an `.ics` `File`.\n * Resolves after the object URL is revoked.\n *\n * @throws If `document` or `URL` is not available.\n *\n * @example\n * const { ics } = await CapacitorCalendar.createEvent({\n * title: 'Team standup',\n * icsFileName: 'team-standup.ics',\n * });\n * if (ics) {\n * await downloadIcsFile(ics);\n * }\n *\n * @since 8.5.0\n */\nexport async function downloadIcsFile(file: File): Promise<void> {\n if (typeof document === 'undefined' || typeof URL === 'undefined') {\n throw new Error('downloadIcsFile requires a browser document environment.');\n }\n\n const url = URL.createObjectURL(file);\n const link = document.createElement('a');\n link.href = url;\n link.download = file.name.length > 0 ? file.name : 'event.ics';\n document.body.appendChild(link);\n link.click();\n link.remove();\n // Delay revoke so the browser can start the download\n await new Promise((resolve) => setTimeout(resolve, 1000));\n URL.revokeObjectURL(url);\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import type { CreateEventOptions } from '../schemas/interfaces/create-event-options';
2
+ /**
3
+ * Builds an RFC 5545 `VCALENDAR` document with one `VEVENT` from CreateEventOptions.
4
+ * When `startDate` is omitted, uses the current time. When `endDate` is omitted, uses
5
+ * one hour after the start (or the next day for all-day events).
6
+ */
7
+ export declare function buildEventIcs(options: CreateEventOptions): string;
8
+ /**
9
+ * Resolves the `.ics` download filename.
10
+ * Uses `icsFileName` when set; otherwise derives a name from `title` (fallback `event.ics`).
11
+ * Appends `.ics` when the chosen name has no such extension.
12
+ */
13
+ export declare function resolveIcsFileName(options: Pick<CreateEventOptions, 'icsFileName' | 'title'>): string;
14
+ /**
15
+ * Escapes TEXT values per RFC 5545 §3.3.11.
16
+ */
17
+ export declare function escapeText(value: string): string;
18
+ /**
19
+ * Folds a content line so each physical line is at most 75 octets (RFC 5545 §3.1).
20
+ */
21
+ export declare function foldLine(line: string): string;
@@ -0,0 +1,252 @@
1
+ import { EventAvailability } from '../schemas/enums/event-availability';
2
+ const HOUR_MS = 60 * 60 * 1000;
3
+ const DAY_MS = 24 * HOUR_MS;
4
+ const CRLF = '\r\n';
5
+ /**
6
+ * Builds an RFC 5545 `VCALENDAR` document with one `VEVENT` from CreateEventOptions.
7
+ * When `startDate` is omitted, uses the current time. When `endDate` is omitted, uses
8
+ * one hour after the start (or the next day for all-day events).
9
+ */
10
+ export function buildEventIcs(options) {
11
+ var _a;
12
+ const startDate = (_a = options.startDate) !== null && _a !== void 0 ? _a : Date.now();
13
+ const isAllDay = options.isAllDay === true;
14
+ const endDate = resolveEndDate(startDate, options.endDate, isAllDay);
15
+ const lines = [
16
+ 'BEGIN:VCALENDAR',
17
+ 'VERSION:2.0',
18
+ 'PRODID:-//ebarooni/capacitor-calendar//EN',
19
+ 'CALSCALE:GREGORIAN',
20
+ 'METHOD:PUBLISH',
21
+ 'BEGIN:VEVENT',
22
+ `UID:${generateUid()}`,
23
+ `DTSTAMP:${formatDateTimeUtc(Date.now())}`,
24
+ ];
25
+ if (isAllDay) {
26
+ lines.push(`DTSTART;VALUE=DATE:${formatDateOnlyLocal(startDate)}`);
27
+ lines.push(`DTEND;VALUE=DATE:${formatDateOnlyLocal(endDate)}`);
28
+ }
29
+ else {
30
+ lines.push(`DTSTART:${formatDateTimeUtc(startDate)}`);
31
+ lines.push(`DTEND:${formatDateTimeUtc(endDate)}`);
32
+ }
33
+ lines.push(`SUMMARY:${escapeText(options.title)}`);
34
+ if (options.description != null && options.description.length > 0) {
35
+ lines.push(`DESCRIPTION:${escapeText(options.description)}`);
36
+ }
37
+ if (options.location != null && options.location.length > 0) {
38
+ lines.push(`LOCATION:${escapeText(options.location)}`);
39
+ }
40
+ if (options.url != null && options.url.length > 0) {
41
+ lines.push(`URL:${escapeText(options.url)}`);
42
+ }
43
+ if (options.organizer != null && options.organizer.length > 0) {
44
+ lines.push(`ORGANIZER:mailto:${escapeText(options.organizer)}`);
45
+ }
46
+ const transp = mapTransparency(options.availability);
47
+ if (transp != null) {
48
+ lines.push(`TRANSP:${transp}`);
49
+ }
50
+ if (options.recurrence != null) {
51
+ lines.push(`RRULE:${toRRule(options.recurrence, isAllDay)}`);
52
+ }
53
+ if (options.attendees != null) {
54
+ for (const guest of options.attendees) {
55
+ if (guest.email.length === 0) {
56
+ continue;
57
+ }
58
+ const cn = guest.name != null && guest.name.length > 0 ? `;CN=${formatParamValue(guest.name)}` : '';
59
+ lines.push(`ATTENDEE${cn}:mailto:${escapeText(guest.email)}`);
60
+ }
61
+ }
62
+ if (options.alerts != null) {
63
+ for (const minutes of options.alerts) {
64
+ lines.push(...buildAlarm(minutes));
65
+ }
66
+ }
67
+ lines.push('END:VEVENT', 'END:VCALENDAR');
68
+ return lines.map(foldLine).join(CRLF) + CRLF;
69
+ }
70
+ /**
71
+ * Resolves the `.ics` download filename.
72
+ * Uses `icsFileName` when set; otherwise derives a name from `title` (fallback `event.ics`).
73
+ * Appends `.ics` when the chosen name has no such extension.
74
+ */
75
+ export function resolveIcsFileName(options) {
76
+ var _a;
77
+ const custom = (_a = options.icsFileName) === null || _a === void 0 ? void 0 : _a.trim();
78
+ if (custom != null && custom.length > 0) {
79
+ return /\.ics$/i.test(custom) ? custom : `${custom}.ics`;
80
+ }
81
+ return fileNameFromTitle(options.title);
82
+ }
83
+ function fileNameFromTitle(title) {
84
+ const base = (title !== null && title !== void 0 ? title : 'event')
85
+ .trim()
86
+ .replace(/[^\w\s-]+/g, '')
87
+ .replace(/\s+/g, '-')
88
+ .replace(/-+/g, '-')
89
+ .replace(/^-|-$/g, '')
90
+ .slice(0, 64);
91
+ return `${base.length > 0 ? base : 'event'}.ics`;
92
+ }
93
+ function resolveEndDate(startDate, endDate, isAllDay) {
94
+ if (!isAllDay) {
95
+ return endDate !== null && endDate !== void 0 ? endDate : startDate + HOUR_MS;
96
+ }
97
+ if (endDate == null) {
98
+ return startDate + DAY_MS;
99
+ }
100
+ // ICS all-day DTEND is exclusive; same local date as DTSTART is zero-length.
101
+ if (formatDateOnlyLocal(endDate) <= formatDateOnlyLocal(startDate)) {
102
+ return startDate + DAY_MS;
103
+ }
104
+ return endDate;
105
+ }
106
+ function mapTransparency(availability) {
107
+ if (availability == null) {
108
+ return null;
109
+ }
110
+ if (availability === EventAvailability.FREE) {
111
+ return 'TRANSPARENT';
112
+ }
113
+ if (availability === EventAvailability.BUSY) {
114
+ return 'OPAQUE';
115
+ }
116
+ return 'OPAQUE';
117
+ }
118
+ function toRRule(rule, isAllDay) {
119
+ var _a;
120
+ const parts = [`FREQ=${rule.frequency.toUpperCase()}`, `INTERVAL=${Math.max(1, (_a = rule.interval) !== null && _a !== void 0 ? _a : 1)}`];
121
+ if (rule.count != null) {
122
+ parts.push(`COUNT=${rule.count}`);
123
+ }
124
+ else if (rule.end != null) {
125
+ // RFC 5545: UNTIL must match DTSTART value type (DATE vs DATE-TIME).
126
+ parts.push(`UNTIL=${isAllDay ? formatDateOnlyLocal(rule.end) : formatDateTimeUtc(rule.end)}`);
127
+ }
128
+ if (rule.byWeekDay != null && rule.byWeekDay.length > 0) {
129
+ const mapped = rule.byWeekDay.map(mapWeekday).filter((d) => d != null);
130
+ if (mapped.length > 0) {
131
+ parts.push(`BYDAY=${[...new Set(mapped)].join(',')}`);
132
+ }
133
+ }
134
+ if (rule.byMonthDay != null && rule.byMonthDay.length > 0) {
135
+ parts.push(`BYMONTHDAY=${rule.byMonthDay.join(',')}`);
136
+ }
137
+ if (rule.byMonth != null && rule.byMonth.length > 0) {
138
+ parts.push(`BYMONTH=${rule.byMonth.join(',')}`);
139
+ }
140
+ if (rule.weeksOfTheYear != null && rule.weeksOfTheYear.length > 0) {
141
+ parts.push(`BYWEEKNO=${rule.weeksOfTheYear.join(',')}`);
142
+ }
143
+ if (rule.daysOfTheYear != null && rule.daysOfTheYear.length > 0) {
144
+ parts.push(`BYYEARDAY=${rule.daysOfTheYear.join(',')}`);
145
+ }
146
+ return parts.join(';');
147
+ }
148
+ function mapWeekday(day) {
149
+ switch (day) {
150
+ case 1:
151
+ return 'MO';
152
+ case 2:
153
+ return 'TU';
154
+ case 3:
155
+ return 'WE';
156
+ case 4:
157
+ return 'TH';
158
+ case 5:
159
+ return 'FR';
160
+ case 6:
161
+ return 'SA';
162
+ case 7:
163
+ return 'SU';
164
+ default:
165
+ return null;
166
+ }
167
+ }
168
+ function buildAlarm(minutes) {
169
+ const trigger = minutes < 0 ? `-PT${Math.abs(minutes)}M` : `PT${minutes}M`;
170
+ return ['BEGIN:VALARM', 'ACTION:DISPLAY', 'DESCRIPTION:Reminder', `TRIGGER:${trigger}`, 'END:VALARM'];
171
+ }
172
+ function generateUid() {
173
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
174
+ return `${crypto.randomUUID()}@capacitor-calendar`;
175
+ }
176
+ return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}@capacitor-calendar`;
177
+ }
178
+ function formatDateTimeUtc(ms) {
179
+ const d = new Date(ms);
180
+ const y = d.getUTCFullYear();
181
+ const mo = pad(d.getUTCMonth() + 1);
182
+ const day = pad(d.getUTCDate());
183
+ const h = pad(d.getUTCHours());
184
+ const mi = pad(d.getUTCMinutes());
185
+ const s = pad(d.getUTCSeconds());
186
+ return `${y}${mo}${day}T${h}${mi}${s}Z`;
187
+ }
188
+ function formatDateOnlyLocal(ms) {
189
+ const d = new Date(ms);
190
+ return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}`;
191
+ }
192
+ function pad(n) {
193
+ return n < 10 ? `0${n}` : String(n);
194
+ }
195
+ /**
196
+ * Escapes TEXT values per RFC 5545 §3.3.11.
197
+ */
198
+ export function escapeText(value) {
199
+ return value
200
+ .replace(/\\/g, '\\\\')
201
+ .replace(/;/g, '\\;')
202
+ .replace(/,/g, '\\,')
203
+ .replace(/\r\n|\n|\r/g, '\\n');
204
+ }
205
+ /**
206
+ * Formats a property parameter value per RFC 5545 §3.2.
207
+ * Values with COMMA, SEMICOLON, or COLON are quoted; DQUOTE and line breaks are sanitized.
208
+ */
209
+ function formatParamValue(value) {
210
+ const sanitized = value.replace(/[\r\n]+/g, ' ').replace(/"/g, "'");
211
+ if (/[;:,]/.test(sanitized)) {
212
+ return `"${sanitized}"`;
213
+ }
214
+ return sanitized;
215
+ }
216
+ /**
217
+ * Folds a content line so each physical line is at most 75 octets (RFC 5545 §3.1).
218
+ */
219
+ export function foldLine(line) {
220
+ const max = 75;
221
+ if (byteLength(line) <= max) {
222
+ return line;
223
+ }
224
+ const chars = [...line];
225
+ let result = '';
226
+ let current = '';
227
+ for (const ch of chars) {
228
+ const next = current + ch;
229
+ if (byteLength(next) > max) {
230
+ result += result.length === 0 ? current : `${CRLF} ${current}`;
231
+ current = ch;
232
+ // Continuations are limited to 74 octets of content + leading space = 75
233
+ while (byteLength(current) > max - 1) {
234
+ // Extremely rare for a single code point; split by taking first unit as-is
235
+ result += `${CRLF} ${current}`;
236
+ current = '';
237
+ break;
238
+ }
239
+ }
240
+ else {
241
+ current = next;
242
+ }
243
+ }
244
+ if (current.length > 0) {
245
+ result += result.length === 0 ? current : `${CRLF} ${current}`;
246
+ }
247
+ return result;
248
+ }
249
+ function byteLength(s) {
250
+ return new TextEncoder().encode(s).length;
251
+ }
252
+ //# sourceMappingURL=ics.js.map
@@ -0,0 +1 @@
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;AAEpB;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,OAA2B;;IACvD,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,QAAQ,CAAC,CAAC;IAErE,MAAM,KAAK,GAAa;QACtB,iBAAiB;QACjB,aAAa;QACb,2CAA2C;QAC3C,oBAAoB;QACpB,gBAAgB;QAChB,cAAc;QACd,OAAO,WAAW,EAAE,EAAE;QACtB,WAAW,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE;KAC3C,CAAC;IAEF,IAAI,QAAQ,EAAE,CAAC;QACb,KAAK,CAAC,IAAI,CAAC,sBAAsB,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QACnE,KAAK,CAAC,IAAI,CAAC,oBAAoB,mBAAmB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACjE,CAAC;SAAM,CAAC;QACN,K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,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 * When `startDate` is omitted, uses the current time. When `endDate` is omitted, uses\n * one hour after the start (or the next day for all-day events).\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, 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\nfunction resolveEndDate(startDate: number, endDate: number | undefined, isAllDay: boolean): number {\n if (!isAllDay) {\n return endDate ?? startDate + HOUR_MS;\n }\n if (endDate == null) {\n return startDate + DAY_MS;\n }\n // ICS all-day DTEND is exclusive; same local date as DTSTART is zero-length.\n if (formatDateOnlyLocal(endDate) <= formatDateOnlyLocal(startDate)) {\n return startDate + DAY_MS;\n }\n return endDate;\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 d = new Date(ms);\n const y = d.getUTCFullYear();\n const mo = pad(d.getUTCMonth() + 1);\n const day = pad(d.getUTCDate());\n const h = pad(d.getUTCHours());\n const mi = pad(d.getUTCMinutes());\n const s = pad(d.getUTCSeconds());\n return `${y}${mo}${day}T${h}${mi}${s}Z`;\n}\n\nfunction formatDateOnlyLocal(ms: number): string {\n const d = new Date(ms);\n return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}`;\n}\n\nfunction pad(n: number): string {\n return n < 10 ? `0${n}` : String(n);\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"]}
package/dist/esm/web.d.ts CHANGED
@@ -8,7 +8,9 @@ import type { CheckPermissionOptions } from './schemas/interfaces/check-permissi
8
8
  import type { CreateCalendarOptions } from './schemas/interfaces/create-calendar-options';
9
9
  import type { CreateCalendarResult } from './schemas/interfaces/create-calendar-result';
10
10
  import type { CreateEventOptions } from './schemas/interfaces/create-event-options';
11
+ import type { CreateEventResult } from './schemas/interfaces/create-event-result';
11
12
  import type { CreateEventWithPromptOptions } from './schemas/interfaces/create-event-with-prompt-options';
13
+ import type { CreateEventWithPromptResult } from './schemas/interfaces/create-event-with-prompt-result';
12
14
  import type { CreateReminderOptions } from './schemas/interfaces/create-reminder-options';
13
15
  import type { CreateRemindersListOptions } from './schemas/interfaces/create-reminders-list-options';
14
16
  import type { CreateRemindersListResult } from './schemas/interfaces/create-reminders-list-result';
@@ -69,15 +71,11 @@ export declare class CapacitorCalendarWeb extends WebPlugin implements Capacitor
69
71
  requestFullRemindersAccess(): Promise<{
70
72
  result: PermissionState;
71
73
  }>;
72
- createEventWithPrompt(_options: CreateEventWithPromptOptions): Promise<{
73
- id: string | null;
74
- }>;
74
+ createEventWithPrompt(_options: CreateEventWithPromptOptions): Promise<CreateEventWithPromptResult>;
75
75
  modifyEventWithPrompt(_options: ModifyEventWithPromptOptions): Promise<{
76
76
  result: EventEditAction | null;
77
77
  }>;
78
- createEvent(_options: CreateEventOptions): Promise<{
79
- id: string;
80
- }>;
78
+ createEvent(options: CreateEventOptions): Promise<CreateEventResult>;
81
79
  commit(): Promise<void>;
82
80
  modifyEvent(_options: ModifyEventOptions): Promise<void>;
83
81
  selectCalendarsWithPrompt(_options?: SelectCalendarsWithPromptOptions): Promise<SelectCalendarsWithPromptResult>;
package/dist/esm/web.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
+ import { buildEventIcs, resolveIcsFileName } from './web/ics';
2
3
  export class CapacitorCalendarWeb extends WebPlugin {
3
4
  checkPermission(_options) {
4
5
  return this.throwUnimplemented(this.checkPermission.name);
@@ -36,8 +37,18 @@ export class CapacitorCalendarWeb extends WebPlugin {
36
37
  modifyEventWithPrompt(_options) {
37
38
  return this.throwUnimplemented(this.modifyEventWithPrompt.name);
38
39
  }
39
- createEvent(_options) {
40
- return this.throwUnimplemented(this.createEvent.name);
40
+ createEvent(options) {
41
+ try {
42
+ const content = buildEventIcs(options);
43
+ const ics = new File([content], resolveIcsFileName(options), {
44
+ type: 'text/calendar;charset=utf-8',
45
+ });
46
+ return Promise.resolve({ id: null, ics });
47
+ }
48
+ catch (error) {
49
+ const message = error instanceof Error ? error.message : String(error);
50
+ return Promise.reject(new Error(message));
51
+ }
41
52
  }
42
53
  commit() {
43
54
  return this.throwUnimplemented(this.commit.name);