@ebarooni/capacitor-calendar 8.7.1 → 8.9.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 +202 -137
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +72 -25
- package/android/src/main/java/dev/barooni/capacitor/calendar/PluginError.kt +8 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/CreateEventWithPromptResult.kt +1 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/GetDefaultCalendarResult.kt +1 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/ListCalendarsResult.kt +1 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/utils/DeclarationCheck.kt +59 -0
- package/dist/docs.json +463 -81
- package/dist/esm/index.d.ts +7 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schemas/enums/calendar-permission-scope.d.ts +1 -1
- package/dist/esm/schemas/enums/calendar-permission-scope.js +1 -1
- package/dist/esm/schemas/enums/calendar-permission-scope.js.map +1 -1
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.d.ts +13 -0
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.js +15 -0
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.js.map +1 -0
- package/dist/esm/schemas/interfaces/calendar.d.ts +10 -2
- package/dist/esm/schemas/interfaces/calendar.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-calendar-options.d.ts +6 -4
- package/dist/esm/schemas/interfaces/create-calendar-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-event-options.d.ts +10 -1
- package/dist/esm/schemas/interfaces/create-event-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-event-result.d.ts +0 -2
- package/dist/esm/schemas/interfaces/create-event-result.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-event-with-prompt-options.d.ts +36 -10
- package/dist/esm/schemas/interfaces/create-event-with-prompt-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-event-with-prompt-result.d.ts +10 -1
- package/dist/esm/schemas/interfaces/create-event-with-prompt-result.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-reminder-options.d.ts +2 -0
- package/dist/esm/schemas/interfaces/create-reminder-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-reminders-list-options.d.ts +12 -7
- package/dist/esm/schemas/interfaces/create-reminders-list-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/delete-reminder-with-prompt-result.d.ts +12 -0
- package/dist/esm/schemas/interfaces/delete-reminder-with-prompt-result.js +2 -0
- package/dist/esm/schemas/interfaces/delete-reminder-with-prompt-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/event-recurrence-rule.d.ts +9 -9
- package/dist/esm/schemas/interfaces/event-recurrence-rule.js.map +1 -1
- package/dist/esm/schemas/interfaces/get-default-reminders-list-result.d.ts +13 -0
- package/dist/esm/schemas/interfaces/get-default-reminders-list-result.js +2 -0
- package/dist/esm/schemas/interfaces/get-default-reminders-list-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/get-reminders-lists-result.d.ts +13 -0
- package/dist/esm/schemas/interfaces/get-reminders-lists-result.js +2 -0
- package/dist/esm/schemas/interfaces/get-reminders-lists-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/modify-calendar-options.d.ts +6 -2
- package/dist/esm/schemas/interfaces/modify-calendar-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/modify-event-with-prompt-options.d.ts +77 -2
- package/dist/esm/schemas/interfaces/modify-event-with-prompt-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/modify-reminder-options.d.ts +3 -0
- package/dist/esm/schemas/interfaces/modify-reminder-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/reminder.d.ts +2 -0
- package/dist/esm/schemas/interfaces/reminder.js.map +1 -1
- package/dist/esm/schemas/interfaces/reminders-list.d.ts +6 -0
- package/dist/esm/schemas/interfaces/reminders-list.js.map +1 -1
- package/dist/esm/schemas/interfaces/update-reminders-list-options.d.ts +8 -5
- package/dist/esm/schemas/interfaces/update-reminders-list-options.js.map +1 -1
- package/dist/esm/schemas/types/system-color-name.d.ts +6 -0
- package/dist/esm/schemas/types/system-color-name.js +2 -0
- package/dist/esm/schemas/types/system-color-name.js.map +1 -0
- package/dist/esm/sub-definitions/event-operations.d.ts +7 -10
- package/dist/esm/sub-definitions/event-operations.js.map +1 -1
- package/dist/esm/sub-definitions/reminders-access.d.ts +1 -1
- package/dist/esm/sub-definitions/reminders-access.js.map +1 -1
- package/dist/esm/sub-definitions/reminders-operations.d.ts +41 -16
- package/dist/esm/sub-definitions/reminders-operations.js.map +1 -1
- package/dist/esm/web/ics.d.ts +8 -2
- package/dist/esm/web/ics.js +64 -22
- package/dist/esm/web/ics.js.map +1 -1
- package/dist/esm/web.d.ts +8 -15
- package/dist/esm/web.js +100 -5
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +180 -29
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +180 -29
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorCalendarPlugin.swift +68 -22
- package/ios/Plugin/Models/Inputs/CreateCalendarInput.swift +5 -2
- package/ios/Plugin/Models/Inputs/CreateRemindersListInput.swift +4 -18
- package/ios/Plugin/Models/Inputs/ModifyCalendarInput.swift +2 -2
- package/ios/Plugin/Models/Inputs/UpdateRemindersListInput.swift +4 -18
- package/ios/Plugin/Models/Results/CreateEventWithPromptResult.swift +1 -0
- package/ios/Plugin/PluginError.swift +13 -0
- package/ios/Plugin/Utils/DeclarationCheck.swift +63 -0
- package/ios/Plugin/Utils/ImplementationHelper.swift +44 -0
- package/ios/Plugin/Utils/UIColorFromHexExtension.swift +5 -0
- package/package.json +1 -1
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
import type { CalendarSource } from '../schemas/interfaces/calendar-source';
|
|
2
1
|
import type { CreateReminderOptions } from '../schemas/interfaces/create-reminder-options';
|
|
3
2
|
import type { CreateReminderResult } from '../schemas/interfaces/create-reminder-result';
|
|
4
3
|
import type { CreateRemindersListOptions } from '../schemas/interfaces/create-reminders-list-options';
|
|
5
4
|
import type { CreateRemindersListResult } from '../schemas/interfaces/create-reminders-list-result';
|
|
6
5
|
import type { DeleteReminderOptions } from '../schemas/interfaces/delete-reminder-options';
|
|
7
6
|
import type { DeleteReminderWithPromptOptions } from '../schemas/interfaces/delete-reminder-with-prompt-options';
|
|
7
|
+
import type { DeleteReminderWithPromptResult } from '../schemas/interfaces/delete-reminder-with-prompt-result';
|
|
8
8
|
import type { DeleteRemindersByIdOptions } from '../schemas/interfaces/delete-reminders-by-id-options';
|
|
9
9
|
import type { DeleteRemindersByIdResult } from '../schemas/interfaces/delete-reminders-by-id-result';
|
|
10
10
|
import type { DeleteRemindersListOptions } from '../schemas/interfaces/delete-reminders-list-options';
|
|
11
|
+
import type { FetchAllCalendarSourcesResult } from '../schemas/interfaces/fetch-all-calendar-sources-result';
|
|
12
|
+
import type { GetDefaultRemindersListResult } from '../schemas/interfaces/get-default-reminders-list-result';
|
|
11
13
|
import type { GetReminderByIdOptions } from '../schemas/interfaces/get-reminder-by-id-options';
|
|
12
14
|
import type { GetReminderByIdResult } from '../schemas/interfaces/get-reminder-by-id-result';
|
|
13
15
|
import type { GetRemindersFromListsOptions } from '../schemas/interfaces/get-reminders-from-lists-options';
|
|
14
16
|
import type { GetRemindersFromListsResult } from '../schemas/interfaces/get-reminders-from-lists-result';
|
|
17
|
+
import type { GetRemindersListsResult } from '../schemas/interfaces/get-reminders-lists-result';
|
|
15
18
|
import type { ModifyReminderOptions } from '../schemas/interfaces/modify-reminder-options';
|
|
16
|
-
import type { RemindersList } from '../schemas/interfaces/reminders-list';
|
|
17
19
|
import type { UpdateRemindersListOptions } from '../schemas/interfaces/update-reminders-list-options';
|
|
18
20
|
import type { UpdateRemindersListResult } from '../schemas/interfaces/update-reminders-list-result';
|
|
19
21
|
export interface RemindersOperations {
|
|
20
22
|
/**
|
|
21
23
|
* Creates a new reminders list.
|
|
22
24
|
*
|
|
25
|
+
* @throws {Error} `Title must be provided.` — when `title` is missing.
|
|
26
|
+
* @throws {Error} `Invalid color format.` — when `color` is present but invalid.
|
|
27
|
+
*
|
|
23
28
|
* @platform iOS
|
|
24
29
|
* @since 8.1.0
|
|
25
30
|
*/
|
|
@@ -27,6 +32,8 @@ export interface RemindersOperations {
|
|
|
27
32
|
/**
|
|
28
33
|
* Deletes a reminders list.
|
|
29
34
|
*
|
|
35
|
+
* @throws {Error} `List not found.` — when no list exists for `id`.
|
|
36
|
+
*
|
|
30
37
|
* @platform iOS
|
|
31
38
|
* @since 8.2.0
|
|
32
39
|
*/
|
|
@@ -38,12 +45,12 @@ export interface RemindersOperations {
|
|
|
38
45
|
* @platform iOS
|
|
39
46
|
* @since 6.6.0
|
|
40
47
|
*/
|
|
41
|
-
fetchAllRemindersSources(): Promise<
|
|
42
|
-
result: CalendarSource[];
|
|
43
|
-
}>;
|
|
48
|
+
fetchAllRemindersSources(): Promise<FetchAllCalendarSourcesResult>;
|
|
44
49
|
/**
|
|
45
50
|
* Opens the reminders app.
|
|
46
51
|
*
|
|
52
|
+
* @throws {Error} `Failed to launch reminders app.` — when the system cannot open Reminders.
|
|
53
|
+
*
|
|
47
54
|
* @platform iOS
|
|
48
55
|
* @since 7.1.0
|
|
49
56
|
*/
|
|
@@ -54,21 +61,23 @@ export interface RemindersOperations {
|
|
|
54
61
|
* @platform iOS
|
|
55
62
|
* @since 7.1.0
|
|
56
63
|
*/
|
|
57
|
-
getDefaultRemindersList(): Promise<
|
|
58
|
-
result: RemindersList | null;
|
|
59
|
-
}>;
|
|
64
|
+
getDefaultRemindersList(): Promise<GetDefaultRemindersListResult>;
|
|
60
65
|
/**
|
|
61
66
|
* Retrieves all available reminders lists.
|
|
62
67
|
*
|
|
63
68
|
* @platform iOS
|
|
64
69
|
* @since 7.1.0
|
|
65
70
|
*/
|
|
66
|
-
getRemindersLists(): Promise<
|
|
67
|
-
result: RemindersList[];
|
|
68
|
-
}>;
|
|
71
|
+
getRemindersLists(): Promise<GetRemindersListsResult>;
|
|
69
72
|
/**
|
|
70
73
|
* Creates a reminder.
|
|
71
74
|
*
|
|
75
|
+
* @throws {Error} `Title must be provided.` — when `title` is missing.
|
|
76
|
+
* @throws {Error} `List not found.` — when `listId` is set and no list matches.
|
|
77
|
+
* @throws {Error} `Invalid frequency.` — when `recurrence.frequency` is present but invalid.
|
|
78
|
+
* @throws {Error} `Frequency must be provided.` — when recurrence is set without `frequency`.
|
|
79
|
+
* @throws {Error} `Interval must be provided.` — when recurrence is set without `interval`.
|
|
80
|
+
*
|
|
72
81
|
* @platform iOS
|
|
73
82
|
* @since 0.5.0
|
|
74
83
|
*/
|
|
@@ -86,6 +95,8 @@ export interface RemindersOperations {
|
|
|
86
95
|
/**
|
|
87
96
|
* Deletes a reminder.
|
|
88
97
|
*
|
|
98
|
+
* @throws {Error} `Reminder not found.` — when no reminder exists for `id`.
|
|
99
|
+
*
|
|
89
100
|
* @platform iOS
|
|
90
101
|
* @since 7.1.0
|
|
91
102
|
*/
|
|
@@ -93,12 +104,18 @@ export interface RemindersOperations {
|
|
|
93
104
|
/**
|
|
94
105
|
* Modifies a reminder.
|
|
95
106
|
*
|
|
107
|
+
* @throws {Error} `Reminder not found.` — when no reminder exists for `id`.
|
|
108
|
+
* @throws {Error} `List not found.` — when `listId` is set and no list matches.
|
|
109
|
+
* @throws {Error} `Invalid frequency.` — when `recurrence.frequency` is present but invalid.
|
|
110
|
+
* @throws {Error} `Frequency must be provided.` — when recurrence is set without `frequency`.
|
|
111
|
+
* @throws {Error} `Interval must be provided.` — when recurrence is set without `interval`.
|
|
112
|
+
*
|
|
96
113
|
* @platform iOS
|
|
97
114
|
* @since 6.7.0
|
|
98
115
|
*/
|
|
99
116
|
modifyReminder(options: ModifyReminderOptions): Promise<void>;
|
|
100
117
|
/**
|
|
101
|
-
*
|
|
118
|
+
* Retrieves a reminder by id.
|
|
102
119
|
*
|
|
103
120
|
* @platform iOS
|
|
104
121
|
* @since 7.1.0
|
|
@@ -107,6 +124,8 @@ export interface RemindersOperations {
|
|
|
107
124
|
/**
|
|
108
125
|
* Retrieves reminders from multiple lists.
|
|
109
126
|
*
|
|
127
|
+
* @throws {Error} `List not found.` — when a requested list id does not exist.
|
|
128
|
+
*
|
|
110
129
|
* @platform iOS
|
|
111
130
|
* @since 5.3.0
|
|
112
131
|
*/
|
|
@@ -114,14 +133,20 @@ export interface RemindersOperations {
|
|
|
114
133
|
/**
|
|
115
134
|
* Opens a dialog to delete a reminder.
|
|
116
135
|
*
|
|
136
|
+
* @throws {Error} `Reminder not found.` — when no reminder exists for `id`.
|
|
137
|
+
* @throws {Error} `Missing view controller.` — when the plugin cannot present the dialog.
|
|
138
|
+
*
|
|
117
139
|
* @platform iOS
|
|
118
140
|
* @since 7.2.0
|
|
119
141
|
*/
|
|
120
|
-
deleteReminderWithPrompt(options: DeleteReminderWithPromptOptions): Promise<
|
|
121
|
-
deleted: boolean;
|
|
122
|
-
}>;
|
|
142
|
+
deleteReminderWithPrompt(options: DeleteReminderWithPromptOptions): Promise<DeleteReminderWithPromptResult>;
|
|
123
143
|
/**
|
|
124
|
-
*
|
|
144
|
+
* Updates a reminders list.
|
|
145
|
+
*
|
|
146
|
+
* @throws {Error} `Event ID must be provided.` — when `id` is missing.
|
|
147
|
+
* @throws {Error} `List not found.` — when no list exists for `id`.
|
|
148
|
+
* @throws {Error} `List is not modifiable.` — when the list does not allow edits.
|
|
149
|
+
* @throws {Error} `Invalid color format.` — when `color` is present but invalid.
|
|
125
150
|
*
|
|
126
151
|
* @platform iOS
|
|
127
152
|
* @since 8.2.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reminders-operations.js","sourceRoot":"","sources":["../../../src/sub-definitions/reminders-operations.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"reminders-operations.js","sourceRoot":"","sources":["../../../src/sub-definitions/reminders-operations.ts"],"names":[],"mappings":"","sourcesContent":["import type { CreateReminderOptions } from '../schemas/interfaces/create-reminder-options';\nimport type { CreateReminderResult } from '../schemas/interfaces/create-reminder-result';\nimport type { CreateRemindersListOptions } from '../schemas/interfaces/create-reminders-list-options';\nimport type { CreateRemindersListResult } from '../schemas/interfaces/create-reminders-list-result';\nimport type { DeleteReminderOptions } from '../schemas/interfaces/delete-reminder-options';\nimport type { DeleteReminderWithPromptOptions } from '../schemas/interfaces/delete-reminder-with-prompt-options';\nimport type { DeleteReminderWithPromptResult } from '../schemas/interfaces/delete-reminder-with-prompt-result';\nimport type { DeleteRemindersByIdOptions } from '../schemas/interfaces/delete-reminders-by-id-options';\nimport type { DeleteRemindersByIdResult } from '../schemas/interfaces/delete-reminders-by-id-result';\nimport type { DeleteRemindersListOptions } from '../schemas/interfaces/delete-reminders-list-options';\nimport type { FetchAllCalendarSourcesResult } from '../schemas/interfaces/fetch-all-calendar-sources-result';\nimport type { GetDefaultRemindersListResult } from '../schemas/interfaces/get-default-reminders-list-result';\nimport type { GetReminderByIdOptions } from '../schemas/interfaces/get-reminder-by-id-options';\nimport type { GetReminderByIdResult } from '../schemas/interfaces/get-reminder-by-id-result';\nimport type { GetRemindersFromListsOptions } from '../schemas/interfaces/get-reminders-from-lists-options';\nimport type { GetRemindersFromListsResult } from '../schemas/interfaces/get-reminders-from-lists-result';\nimport type { GetRemindersListsResult } from '../schemas/interfaces/get-reminders-lists-result';\nimport type { ModifyReminderOptions } from '../schemas/interfaces/modify-reminder-options';\nimport type { UpdateRemindersListOptions } from '../schemas/interfaces/update-reminders-list-options';\nimport type { UpdateRemindersListResult } from '../schemas/interfaces/update-reminders-list-result';\n\nexport interface RemindersOperations {\n /**\n * Creates a new reminders list.\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 *\n * @platform iOS\n * @since 8.1.0\n */\n createRemindersList(options: CreateRemindersListOptions): Promise<CreateRemindersListResult>;\n /**\n * Deletes a reminders list.\n *\n * @throws {Error} `List not found.` — when no list exists for `id`.\n *\n * @platform iOS\n * @since 8.2.0\n */\n deleteRemindersList(options: DeleteRemindersListOptions): Promise<void>;\n /**\n * Retrieves a list of calendar sources.\n *\n * @deprecated Duplicates {@link CalendarOperations#fetchAllCalendarSources}\n * @platform iOS\n * @since 6.6.0\n */\n fetchAllRemindersSources(): Promise<FetchAllCalendarSourcesResult>;\n /**\n * Opens the reminders app.\n *\n * @throws {Error} `Failed to launch reminders app.` — when the system cannot open Reminders.\n *\n * @platform iOS\n * @since 7.1.0\n */\n openReminders(): Promise<void>;\n /**\n * Retrieves the default reminders list.\n *\n * @platform iOS\n * @since 7.1.0\n */\n getDefaultRemindersList(): Promise<GetDefaultRemindersListResult>;\n /**\n * Retrieves all available reminders lists.\n *\n * @platform iOS\n * @since 7.1.0\n */\n getRemindersLists(): Promise<GetRemindersListsResult>;\n /**\n * Creates a reminder.\n *\n * @throws {Error} `Title must be provided.` — when `title` is missing.\n * @throws {Error} `List not found.` — when `listId` is set and no list matches.\n * @throws {Error} `Invalid frequency.` — when `recurrence.frequency` is present but invalid.\n * @throws {Error} `Frequency must be provided.` — when recurrence is set without `frequency`.\n * @throws {Error} `Interval must be provided.` — when recurrence is set without `interval`.\n *\n * @platform iOS\n * @since 0.5.0\n */\n createReminder(options: CreateReminderOptions): Promise<CreateReminderResult>;\n /**\n * Deletes multiple reminders.\n *\n * @deprecated Use `deleteReminder(...)`.\n * @platform iOS\n * @since 5.3.0\n */\n deleteRemindersById(options: DeleteRemindersByIdOptions): Promise<{ result: DeleteRemindersByIdResult }>;\n /**\n * Deletes a reminder.\n *\n * @throws {Error} `Reminder not found.` — when no reminder exists for `id`.\n *\n * @platform iOS\n * @since 7.1.0\n */\n deleteReminder(options: DeleteReminderOptions): Promise<void>;\n /**\n * Modifies a reminder.\n *\n * @throws {Error} `Reminder not found.` — when no reminder exists for `id`.\n * @throws {Error} `List not found.` — when `listId` is set and no list matches.\n * @throws {Error} `Invalid frequency.` — when `recurrence.frequency` is present but invalid.\n * @throws {Error} `Frequency must be provided.` — when recurrence is set without `frequency`.\n * @throws {Error} `Interval must be provided.` — when recurrence is set without `interval`.\n *\n * @platform iOS\n * @since 6.7.0\n */\n modifyReminder(options: ModifyReminderOptions): Promise<void>;\n /**\n * Retrieves a reminder by id.\n *\n * @platform iOS\n * @since 7.1.0\n */\n getReminderById(options: GetReminderByIdOptions): Promise<GetReminderByIdResult>;\n /**\n * Retrieves reminders from multiple lists.\n *\n * @throws {Error} `List not found.` — when a requested list id does not exist.\n *\n * @platform iOS\n * @since 5.3.0\n */\n getRemindersFromLists(options: GetRemindersFromListsOptions): Promise<GetRemindersFromListsResult>;\n /**\n * Opens a dialog to delete a reminder.\n *\n * @throws {Error} `Reminder not found.` — when no reminder exists for `id`.\n * @throws {Error} `Missing view controller.` — when the plugin cannot present the dialog.\n *\n * @platform iOS\n * @since 7.2.0\n */\n deleteReminderWithPrompt(options: DeleteReminderWithPromptOptions): Promise<DeleteReminderWithPromptResult>;\n /**\n * Updates a reminders list.\n *\n * @throws {Error} `Event ID must be provided.` — when `id` is missing.\n * @throws {Error} `List not found.` — when no list exists for `id`.\n * @throws {Error} `List is not modifiable.` — when the list does not allow edits.\n * @throws {Error} `Invalid color format.` — when `color` is present but invalid.\n *\n * @platform iOS\n * @since 8.2.0\n */\n updateRemindersList(options: UpdateRemindersListOptions): Promise<UpdateRemindersListResult>;\n}\n"]}
|
package/dist/esm/web/ics.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { CreateEventOptions } from '../schemas/interfaces/create-event-options';
|
|
2
2
|
/**
|
|
3
3
|
* Builds an RFC 5545 `VCALENDAR` document with one `VEVENT` from CreateEventOptions.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* End comes from `endDate`, else `duration` (RFC 2445), else one hour (or next day if all-day).
|
|
5
|
+
* All-day ends that fall on the start's local day bump to the next day (exclusive `DTEND`).
|
|
6
6
|
*/
|
|
7
7
|
export declare function buildEventIcs(options: CreateEventOptions): string;
|
|
8
8
|
/**
|
|
@@ -11,6 +11,12 @@ export declare function buildEventIcs(options: CreateEventOptions): string;
|
|
|
11
11
|
* Appends `.ics` when the chosen name has no such extension.
|
|
12
12
|
*/
|
|
13
13
|
export declare function resolveIcsFileName(options: Pick<CreateEventOptions, 'icsFileName' | 'title'>): string;
|
|
14
|
+
/**
|
|
15
|
+
* Resolves event end milliseconds the same way ICS export does.
|
|
16
|
+
* Prefers `endDate`, else `duration` (RFC 2445), else one hour (or next day if all-day).
|
|
17
|
+
* All-day ends that fall on the start's local day bump to the next day (exclusive `DTEND`).
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveEndDate(startDate: number, endDate: number | undefined, duration: string | undefined, isAllDay: boolean): number;
|
|
14
20
|
/**
|
|
15
21
|
* Escapes TEXT values per RFC 5545 §3.3.11.
|
|
16
22
|
*/
|
package/dist/esm/web/ics.js
CHANGED
|
@@ -4,14 +4,14 @@ const DAY_MS = 24 * HOUR_MS;
|
|
|
4
4
|
const CRLF = '\r\n';
|
|
5
5
|
/**
|
|
6
6
|
* Builds an RFC 5545 `VCALENDAR` document with one `VEVENT` from CreateEventOptions.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* End comes from `endDate`, else `duration` (RFC 2445), else one hour (or next day if all-day).
|
|
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
11
|
var _a;
|
|
12
12
|
const startDate = (_a = options.startDate) !== null && _a !== void 0 ? _a : Date.now();
|
|
13
13
|
const isAllDay = options.isAllDay === true;
|
|
14
|
-
const endDate = resolveEndDate(startDate, options.endDate, isAllDay);
|
|
14
|
+
const endDate = resolveEndDate(startDate, options.endDate, options.duration, isAllDay);
|
|
15
15
|
const lines = [
|
|
16
16
|
'BEGIN:VCALENDAR',
|
|
17
17
|
'VERSION:2.0',
|
|
@@ -90,18 +90,60 @@ function fileNameFromTitle(title) {
|
|
|
90
90
|
.slice(0, 64);
|
|
91
91
|
return `${base.length > 0 ? base : 'event'}.ics`;
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Resolves event end milliseconds the same way ICS export does.
|
|
95
|
+
* Prefers `endDate`, else `duration` (RFC 2445), else one hour (or next day if all-day).
|
|
96
|
+
* All-day ends that fall on the start's local day bump to the next day (exclusive `DTEND`).
|
|
97
|
+
*/
|
|
98
|
+
export function resolveEndDate(startDate, endDate, duration, isAllDay) {
|
|
99
|
+
let resolved;
|
|
100
|
+
if (endDate != null) {
|
|
101
|
+
resolved = endDate;
|
|
96
102
|
}
|
|
97
|
-
if (
|
|
98
|
-
|
|
103
|
+
else if (duration != null && duration.trim().length > 0) {
|
|
104
|
+
resolved = startDate + parseRfc2445DurationMs(duration.trim());
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
resolved = isAllDay ? startDate + DAY_MS : startDate + HOUR_MS;
|
|
108
|
+
}
|
|
109
|
+
if (!isAllDay) {
|
|
110
|
+
return resolved;
|
|
99
111
|
}
|
|
100
112
|
// ICS all-day DTEND is exclusive; same local date as DTSTART is zero-length.
|
|
101
|
-
|
|
113
|
+
// Also covers short durations (e.g. PT1H) on all-day events — treat as one whole day.
|
|
114
|
+
if (formatDateOnlyLocal(resolved) <= formatDateOnlyLocal(startDate)) {
|
|
102
115
|
return startDate + DAY_MS;
|
|
103
116
|
}
|
|
104
|
-
return
|
|
117
|
+
return resolved;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Parses an RFC 2445 / RFC 5545 duration string into milliseconds.
|
|
121
|
+
* Supports forms such as `PT1H`, `P1D`, `P3W`, `P2DT4H30M`.
|
|
122
|
+
*
|
|
123
|
+
* @throws If the string is empty, negative, zero-length, or not a valid duration.
|
|
124
|
+
*/
|
|
125
|
+
function parseRfc2445DurationMs(value) {
|
|
126
|
+
var _a, _b, _c, _d, _e;
|
|
127
|
+
const match = /^([+-])?P(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/i.exec(value);
|
|
128
|
+
if (match == null) {
|
|
129
|
+
throw new Error(`Invalid duration: ${value}`);
|
|
130
|
+
}
|
|
131
|
+
const sign = match[1] === '-' ? -1 : 1;
|
|
132
|
+
const weeks = Number((_a = match[2]) !== null && _a !== void 0 ? _a : 0);
|
|
133
|
+
const days = Number((_b = match[3]) !== null && _b !== void 0 ? _b : 0);
|
|
134
|
+
const hours = Number((_c = match[4]) !== null && _c !== void 0 ? _c : 0);
|
|
135
|
+
const minutes = Number((_d = match[5]) !== null && _d !== void 0 ? _d : 0);
|
|
136
|
+
const seconds = Number((_e = match[6]) !== null && _e !== void 0 ? _e : 0);
|
|
137
|
+
// Require at least one unit so bare "P" / "PT" are rejected.
|
|
138
|
+
if (weeks === 0 && days === 0 && hours === 0 && minutes === 0 && seconds === 0) {
|
|
139
|
+
throw new Error(`Invalid duration: ${value}`);
|
|
140
|
+
}
|
|
141
|
+
const ms = weeks * 7 * DAY_MS + days * DAY_MS + hours * HOUR_MS + minutes * 60 * 1000 + seconds * 1000;
|
|
142
|
+
const signed = sign * ms;
|
|
143
|
+
if (signed <= 0) {
|
|
144
|
+
throw new Error(`Invalid duration: ${value}`);
|
|
145
|
+
}
|
|
146
|
+
return signed;
|
|
105
147
|
}
|
|
106
148
|
function mapTransparency(availability) {
|
|
107
149
|
if (availability == null) {
|
|
@@ -176,21 +218,21 @@ function generateUid() {
|
|
|
176
218
|
return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}@capacitor-calendar`;
|
|
177
219
|
}
|
|
178
220
|
function formatDateTimeUtc(ms) {
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
const
|
|
186
|
-
return `${
|
|
221
|
+
const date = new Date(ms);
|
|
222
|
+
const fullYear = date.getUTCFullYear();
|
|
223
|
+
const month = padTwoDigits(date.getUTCMonth() + 1);
|
|
224
|
+
const dayOfMonth = padTwoDigits(date.getUTCDate());
|
|
225
|
+
const hours = padTwoDigits(date.getUTCHours());
|
|
226
|
+
const minutes = padTwoDigits(date.getUTCMinutes());
|
|
227
|
+
const seconds = padTwoDigits(date.getUTCSeconds());
|
|
228
|
+
return `${fullYear}${month}${dayOfMonth}T${hours}${minutes}${seconds}Z`;
|
|
187
229
|
}
|
|
188
230
|
function formatDateOnlyLocal(ms) {
|
|
189
|
-
const
|
|
190
|
-
return `${
|
|
231
|
+
const date = new Date(ms);
|
|
232
|
+
return `${date.getFullYear()}${padTwoDigits(date.getMonth() + 1)}${padTwoDigits(date.getDate())}`;
|
|
191
233
|
}
|
|
192
|
-
function
|
|
193
|
-
return
|
|
234
|
+
function padTwoDigits(value) {
|
|
235
|
+
return value < 10 ? `0${value}` : String(value);
|
|
194
236
|
}
|
|
195
237
|
/**
|
|
196
238
|
* Escapes TEXT values per RFC 5545 §3.3.11.
|
package/dist/esm/web/ics.js.map
CHANGED
|
@@ -1 +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,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AAC,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC;gBACrC,2EAA2E;gBAC3E,MAAM,IAAI,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC;gBAC/B,OAAO,GAAG,EAAE,CAAC;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 * 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"]}
|
|
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;IAC3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IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IACxB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,OAAO,GAAG,EAAE,CAAC;IAEjB,KAAK,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,OAAO,GAAG,EAAE,CAAC;QAC1B,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;YAC3B,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC;YAC/D,OAAO,GAAG,EAAE,CAAC;YACb,yEAAyE;YACzE,OAAO,UAAU,CAAC,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC;gBACrC,2EAA2E;gBAC3E,MAAM,IAAI,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC;gBAC/B,OAAO,GAAG,EAAE,CAAC;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"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { PermissionState } from '@capacitor/core';
|
|
|
2
2
|
import { WebPlugin } from '@capacitor/core';
|
|
3
3
|
import type { CapacitorCalendarPlugin } from './definitions';
|
|
4
4
|
import type { Calendar } from './schemas/interfaces/calendar';
|
|
5
|
-
import type { CalendarSource } from './schemas/interfaces/calendar-source';
|
|
6
5
|
import type { CheckPermissionOptions } from './schemas/interfaces/check-permission-options';
|
|
7
6
|
import type { CreateCalendarOptions } from './schemas/interfaces/create-calendar-options';
|
|
8
7
|
import type { CreateCalendarResult } from './schemas/interfaces/create-calendar-result';
|
|
@@ -20,15 +19,18 @@ import type { DeleteEventWithPromptOptions } from './schemas/interfaces/delete-e
|
|
|
20
19
|
import type { DeleteEventsByIdOptions } from './schemas/interfaces/delete-events-by-id-options';
|
|
21
20
|
import type { DeleteReminderOptions } from './schemas/interfaces/delete-reminder-options';
|
|
22
21
|
import type { DeleteReminderWithPromptOptions } from './schemas/interfaces/delete-reminder-with-prompt-options';
|
|
22
|
+
import type { DeleteReminderWithPromptResult } from './schemas/interfaces/delete-reminder-with-prompt-result';
|
|
23
23
|
import type { DeleteRemindersByIdOptions } from './schemas/interfaces/delete-reminders-by-id-options';
|
|
24
24
|
import type { DeleteRemindersByIdResult } from './schemas/interfaces/delete-reminders-by-id-result';
|
|
25
25
|
import type { DeleteRemindersListOptions } from './schemas/interfaces/delete-reminders-list-options';
|
|
26
26
|
import type { FetchAllCalendarSourcesResult } from './schemas/interfaces/fetch-all-calendar-sources-result';
|
|
27
27
|
import type { GetDefaultCalendarOptions } from './schemas/interfaces/get-default-calendar-options';
|
|
28
|
+
import type { GetDefaultRemindersListResult } from './schemas/interfaces/get-default-reminders-list-result';
|
|
28
29
|
import type { GetReminderByIdOptions } from './schemas/interfaces/get-reminder-by-id-options';
|
|
29
30
|
import type { GetReminderByIdResult } from './schemas/interfaces/get-reminder-by-id-result';
|
|
30
31
|
import type { GetRemindersFromListsOptions } from './schemas/interfaces/get-reminders-from-lists-options';
|
|
31
32
|
import type { GetRemindersFromListsResult } from './schemas/interfaces/get-reminders-from-lists-result';
|
|
33
|
+
import type { GetRemindersListsResult } from './schemas/interfaces/get-reminders-lists-result';
|
|
32
34
|
import type { ListCalendarsResult } from './schemas/interfaces/list-calendars-result';
|
|
33
35
|
import type { ListEventsInRangeOptions } from './schemas/interfaces/list-events-in-range-options';
|
|
34
36
|
import type { ListEventsInRangeResult } from './schemas/interfaces/list-events-in-range-result';
|
|
@@ -37,7 +39,6 @@ import type { ModifyEventOptions } from './schemas/interfaces/modify-event-optio
|
|
|
37
39
|
import type { ModifyEventWithPromptOptions } from './schemas/interfaces/modify-event-with-prompt-options';
|
|
38
40
|
import type { ModifyReminderOptions } from './schemas/interfaces/modify-reminder-options';
|
|
39
41
|
import type { OpenCalendarOptions } from './schemas/interfaces/open-calendar-options';
|
|
40
|
-
import type { RemindersList } from './schemas/interfaces/reminders-list';
|
|
41
42
|
import type { RequestPermissionOptions } from './schemas/interfaces/request-permission-options';
|
|
42
43
|
import type { SelectCalendarsWithPromptOptions } from './schemas/interfaces/select-calendars-with-prompt-options';
|
|
43
44
|
import type { SelectCalendarsWithPromptResult } from './schemas/interfaces/select-calendars-with-prompt-result';
|
|
@@ -73,7 +74,7 @@ export declare class CapacitorCalendarWeb extends WebPlugin implements Capacitor
|
|
|
73
74
|
requestFullRemindersAccess(): Promise<{
|
|
74
75
|
result: PermissionState;
|
|
75
76
|
}>;
|
|
76
|
-
createEventWithPrompt(
|
|
77
|
+
createEventWithPrompt(options?: CreateEventWithPromptOptions): Promise<CreateEventWithPromptResult>;
|
|
77
78
|
modifyEventWithPrompt(_options: ModifyEventWithPromptOptions): Promise<{
|
|
78
79
|
result: EventEditAction | null;
|
|
79
80
|
}>;
|
|
@@ -83,19 +84,13 @@ export declare class CapacitorCalendarWeb extends WebPlugin implements Capacitor
|
|
|
83
84
|
selectCalendarsWithPrompt(_options?: SelectCalendarsWithPromptOptions): Promise<SelectCalendarsWithPromptResult>;
|
|
84
85
|
fetchAllCalendarSources(): Promise<FetchAllCalendarSourcesResult>;
|
|
85
86
|
listCalendars(): Promise<ListCalendarsResult>;
|
|
86
|
-
fetchAllRemindersSources(): Promise<
|
|
87
|
-
result: CalendarSource[];
|
|
88
|
-
}>;
|
|
87
|
+
fetchAllRemindersSources(): Promise<FetchAllCalendarSourcesResult>;
|
|
89
88
|
getDefaultCalendar(_options?: GetDefaultCalendarOptions): Promise<{
|
|
90
89
|
result: Calendar | null;
|
|
91
90
|
}>;
|
|
92
|
-
getDefaultRemindersList(): Promise<
|
|
93
|
-
result: RemindersList | null;
|
|
94
|
-
}>;
|
|
91
|
+
getDefaultRemindersList(): Promise<GetDefaultRemindersListResult>;
|
|
95
92
|
openReminders(): Promise<void>;
|
|
96
|
-
getRemindersLists(): Promise<
|
|
97
|
-
result: RemindersList[];
|
|
98
|
-
}>;
|
|
93
|
+
getRemindersLists(): Promise<GetRemindersListsResult>;
|
|
99
94
|
openCalendar(_options?: OpenCalendarOptions): Promise<void>;
|
|
100
95
|
createCalendar(_options: CreateCalendarOptions): Promise<CreateCalendarResult>;
|
|
101
96
|
deleteCalendar(_options: DeleteCalendarOptions): Promise<void>;
|
|
@@ -116,9 +111,7 @@ export declare class CapacitorCalendarWeb extends WebPlugin implements Capacitor
|
|
|
116
111
|
}>;
|
|
117
112
|
listEventsInRange(_options: ListEventsInRangeOptions): Promise<ListEventsInRangeResult>;
|
|
118
113
|
modifyCalendar(_options: ModifyCalendarOptions): Promise<void>;
|
|
119
|
-
deleteReminderWithPrompt(_options: DeleteReminderWithPromptOptions): Promise<
|
|
120
|
-
deleted: boolean;
|
|
121
|
-
}>;
|
|
114
|
+
deleteReminderWithPrompt(_options: DeleteReminderWithPromptOptions): Promise<DeleteReminderWithPromptResult>;
|
|
122
115
|
updateRemindersList(_options: UpdateRemindersListOptions): Promise<UpdateRemindersListResult>;
|
|
123
116
|
private throwUnimplemented;
|
|
124
117
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import {
|
|
2
|
+
import { downloadIcsFile } from './web/download-ics-file';
|
|
3
|
+
import { buildEventIcs, resolveEndDate, resolveIcsFileName } from './web/ics';
|
|
4
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
3
5
|
export class CapacitorCalendarWeb extends WebPlugin {
|
|
4
6
|
checkPermission(_options) {
|
|
5
7
|
return this.throwUnimplemented(this.checkPermission.name);
|
|
@@ -31,19 +33,40 @@ export class CapacitorCalendarWeb extends WebPlugin {
|
|
|
31
33
|
requestFullRemindersAccess() {
|
|
32
34
|
return this.throwUnimplemented(this.requestFullRemindersAccess.name);
|
|
33
35
|
}
|
|
34
|
-
createEventWithPrompt(
|
|
35
|
-
|
|
36
|
+
async createEventWithPrompt(options = {}) {
|
|
37
|
+
try {
|
|
38
|
+
const confirmed = window.confirm(buildCreateEventConfirmMessage(options));
|
|
39
|
+
if (!confirmed) {
|
|
40
|
+
return { id: null, ics: null };
|
|
41
|
+
}
|
|
42
|
+
const createOptions = mapPromptOptionsToCreateEvent(options);
|
|
43
|
+
const content = buildEventIcs(createOptions);
|
|
44
|
+
const ics = new File([content], resolveIcsFileName(createOptions), {
|
|
45
|
+
type: 'text/calendar;charset=utf-8',
|
|
46
|
+
});
|
|
47
|
+
if (options.autoDownloadIcsFile !== false) {
|
|
48
|
+
await downloadIcsFile(ics);
|
|
49
|
+
}
|
|
50
|
+
return { id: null, ics };
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
54
|
+
return Promise.reject(new Error(message));
|
|
55
|
+
}
|
|
36
56
|
}
|
|
37
57
|
modifyEventWithPrompt(_options) {
|
|
38
58
|
return this.throwUnimplemented(this.modifyEventWithPrompt.name);
|
|
39
59
|
}
|
|
40
|
-
createEvent(options) {
|
|
60
|
+
async createEvent(options) {
|
|
41
61
|
try {
|
|
42
62
|
const content = buildEventIcs(options);
|
|
43
63
|
const ics = new File([content], resolveIcsFileName(options), {
|
|
44
64
|
type: 'text/calendar;charset=utf-8',
|
|
45
65
|
});
|
|
46
|
-
|
|
66
|
+
if (options.autoDownloadIcsFile === true) {
|
|
67
|
+
await downloadIcsFile(ics);
|
|
68
|
+
}
|
|
69
|
+
return { id: null, ics };
|
|
47
70
|
}
|
|
48
71
|
catch (error) {
|
|
49
72
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -132,4 +155,76 @@ export class CapacitorCalendarWeb extends WebPlugin {
|
|
|
132
155
|
return Promise.reject(this.unimplemented(`${methodName} is not implemented on the web.`));
|
|
133
156
|
}
|
|
134
157
|
}
|
|
158
|
+
function mapPromptOptionsToCreateEvent(options) {
|
|
159
|
+
var _a;
|
|
160
|
+
return {
|
|
161
|
+
alerts: options.alerts,
|
|
162
|
+
availability: options.availability,
|
|
163
|
+
description: options.description,
|
|
164
|
+
endDate: options.endDate,
|
|
165
|
+
icsFileName: options.icsFileName,
|
|
166
|
+
isAllDay: options.isAllDay,
|
|
167
|
+
location: options.location,
|
|
168
|
+
recurrence: options.recurrence,
|
|
169
|
+
startDate: options.startDate,
|
|
170
|
+
title: (_a = options.title) !== null && _a !== void 0 ? _a : '',
|
|
171
|
+
url: options.url,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function buildCreateEventConfirmMessage(options) {
|
|
175
|
+
var _a;
|
|
176
|
+
const custom = (_a = options.promptMessage) === null || _a === void 0 ? void 0 : _a.trim();
|
|
177
|
+
if (custom != null && custom.length > 0) {
|
|
178
|
+
return custom;
|
|
179
|
+
}
|
|
180
|
+
const title = normalizeConfirmTitle(options.title);
|
|
181
|
+
const timeSummary = formatEventTimeSummary(options);
|
|
182
|
+
return `Create event?\n\n${title}\n${timeSummary}`;
|
|
183
|
+
}
|
|
184
|
+
function normalizeConfirmTitle(title) {
|
|
185
|
+
const collapsed = (title !== null && title !== void 0 ? title : '')
|
|
186
|
+
.replace(/[\r\n]+/g, ' ')
|
|
187
|
+
.replace(/\s+/g, ' ')
|
|
188
|
+
.trim();
|
|
189
|
+
return collapsed.length > 0 ? collapsed : 'Untitled event';
|
|
190
|
+
}
|
|
191
|
+
function formatEventTimeSummary(options) {
|
|
192
|
+
var _a;
|
|
193
|
+
const startDate = (_a = options.startDate) !== null && _a !== void 0 ? _a : Date.now();
|
|
194
|
+
const isAllDay = options.isAllDay === true;
|
|
195
|
+
const endDate = resolveEndDate(startDate, options.endDate, undefined, isAllDay);
|
|
196
|
+
if (isAllDay) {
|
|
197
|
+
const startDay = formatLocalDate(startDate);
|
|
198
|
+
const lastInclusiveMs = endDate - DAY_MS;
|
|
199
|
+
const lastDay = formatLocalDate(lastInclusiveMs);
|
|
200
|
+
if (lastDay <= startDay) {
|
|
201
|
+
return `All day · ${formatDisplayDate(startDate)}`;
|
|
202
|
+
}
|
|
203
|
+
return `All day · ${formatDisplayDate(startDate)} – ${formatDisplayDate(lastInclusiveMs)}`;
|
|
204
|
+
}
|
|
205
|
+
return `${formatDisplayDateTime(startDate)} – ${formatDisplayDateTime(endDate)}`;
|
|
206
|
+
}
|
|
207
|
+
function formatLocalDate(ms) {
|
|
208
|
+
const date = new Date(ms);
|
|
209
|
+
const fullYear = date.getFullYear();
|
|
210
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
211
|
+
const dayOfMonth = String(date.getDate()).padStart(2, '0');
|
|
212
|
+
return `${fullYear}-${month}-${dayOfMonth}`;
|
|
213
|
+
}
|
|
214
|
+
function formatDisplayDate(ms) {
|
|
215
|
+
return new Date(ms).toLocaleDateString(undefined, {
|
|
216
|
+
year: 'numeric',
|
|
217
|
+
month: 'short',
|
|
218
|
+
day: 'numeric',
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
function formatDisplayDateTime(ms) {
|
|
222
|
+
return new Date(ms).toLocaleString(undefined, {
|
|
223
|
+
year: 'numeric',
|
|
224
|
+
month: 'short',
|
|
225
|
+
day: 'numeric',
|
|
226
|
+
hour: 'numeric',
|
|
227
|
+
minute: '2-digit',
|
|
228
|
+
});
|
|
229
|
+
}
|
|
135
230
|
//# sourceMappingURL=web.js.map
|