akanjs 2.2.1-rc.1 → 2.2.1-rc.2

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.
Files changed (2) hide show
  1. package/client/capacitor.ts +48 -27
  2. package/package.json +1 -1
@@ -145,6 +145,7 @@ type CapacitorModuleMap = {
145
145
  type CapacitorImportCache = Partial<{
146
146
  [K in keyof CapacitorModuleMap]: Promise<CapacitorModuleMap[keyof CapacitorModuleMap]>;
147
147
  }>;
148
+ type CapacitorPluginRegistry = Record<string, unknown>;
148
149
 
149
150
  declare global {
150
151
 
@@ -169,58 +170,78 @@ const loadCapacitorModule = <K extends keyof CapacitorModuleMap>(
169
170
  return loaded;
170
171
  };
171
172
 
172
- const importNativeModule = <T>(specifier: string) => import(specifier) as Promise<T>;
173
-
174
- const capacitorPackage = (name: string) => `@capacitor/${name}`;
175
-
176
- const capacitorCommunityPackage = (name: string) => `@capacitor-community/${name}`;
173
+ const getCapacitorPlugin = <Plugin>(name: string): Plugin => {
174
+ const capacitor = (globalThis as typeof globalThis & { Capacitor?: { Plugins?: CapacitorPluginRegistry } }).Capacitor;
175
+ const plugin = capacitor?.Plugins?.[name];
176
+ if (!plugin) throw new Error(`Capacitor plugin "${name}" is not available.`);
177
+ return plugin as Plugin;
178
+ };
177
179
 
178
180
  export const loadCapacitorApp = () =>
179
- loadCapacitorModule("app", () => importNativeModule<CapacitorAppModule>(capacitorPackage("app")));
181
+ loadCapacitorModule("app", async () => ({ App: getCapacitorPlugin<CapacitorAppModule["App"]>("App") }));
180
182
 
181
183
  export const loadCapacitorBrowser = () =>
182
- loadCapacitorModule("browser", () => importNativeModule<CapacitorBrowserModule>(capacitorPackage("browser")));
184
+ loadCapacitorModule("browser", async () => ({
185
+ Browser: getCapacitorPlugin<CapacitorBrowserModule["Browser"]>("Browser"),
186
+ }));
183
187
 
184
188
  export const loadCapacitorCamera = () =>
185
- loadCapacitorModule("camera", () => importNativeModule<CapacitorCameraModule>(capacitorPackage("camera")));
189
+ loadCapacitorModule("camera", async () => ({
190
+ Camera: getCapacitorPlugin<CapacitorCameraModule["Camera"]>("Camera"),
191
+ CameraResultType: { DataUrl: "dataUrl" },
192
+ CameraSource: { Prompt: "PROMPT", Camera: "CAMERA", Photos: "PHOTOS" },
193
+ }));
186
194
 
187
195
  export const loadCapacitorContacts = () =>
188
- loadCapacitorModule("contacts", () =>
189
- importNativeModule<CapacitorContactsModule>(capacitorCommunityPackage("contacts")),
190
- );
196
+ loadCapacitorModule("contacts", async () => ({
197
+ Contacts: getCapacitorPlugin<CapacitorContactsModule["Contacts"]>("Contacts"),
198
+ }));
191
199
 
192
200
  export const loadCapacitorCore = () =>
193
- loadCapacitorModule("core", () => importNativeModule<CapacitorCoreModule>(capacitorPackage("core")));
201
+ loadCapacitorModule("core", async () => ({
202
+ CapacitorCookies: getCapacitorPlugin<CapacitorCoreModule["CapacitorCookies"]>("CapacitorCookies"),
203
+ }));
194
204
 
195
205
  export const loadCapacitorDevice = () =>
196
- loadCapacitorModule("device", () => importNativeModule<CapacitorDeviceModule>(capacitorPackage("device")));
206
+ loadCapacitorModule("device", async () => ({
207
+ Device: getCapacitorPlugin<CapacitorDeviceModule["Device"]>("Device"),
208
+ }));
197
209
 
198
210
  export const loadCapacitorFcm = () =>
199
- loadCapacitorModule("fcm", () => importNativeModule<CapacitorFcmModule>(capacitorCommunityPackage("fcm")));
211
+ loadCapacitorModule("fcm", async () => ({ FCM: getCapacitorPlugin<CapacitorFcmModule["FCM"]>("FCM") }));
200
212
 
201
213
  export const loadCapacitorGeolocation = () =>
202
- loadCapacitorModule("geolocation", () =>
203
- importNativeModule<CapacitorGeolocationModule>(capacitorPackage("geolocation")),
204
- );
214
+ loadCapacitorModule("geolocation", async () => ({
215
+ Geolocation: getCapacitorPlugin<CapacitorGeolocationModule["Geolocation"]>("Geolocation"),
216
+ }));
205
217
 
206
218
  export const loadCapacitorHaptics = () =>
207
- loadCapacitorModule("haptics", () => importNativeModule<CapacitorHapticsModule>(capacitorPackage("haptics")));
219
+ loadCapacitorModule("haptics", async () => ({
220
+ Haptics: getCapacitorPlugin<CapacitorHapticsModule["Haptics"]>("Haptics"),
221
+ ImpactStyle: { Light: "LIGHT", Medium: "MEDIUM", Heavy: "HEAVY" },
222
+ }));
208
223
 
209
224
  export const loadCapacitorKeyboard = () =>
210
- loadCapacitorModule("keyboard", () => importNativeModule<CapacitorKeyboardModule>(capacitorPackage("keyboard")));
225
+ loadCapacitorModule("keyboard", async () => ({
226
+ Keyboard: getCapacitorPlugin<CapacitorKeyboardModule["Keyboard"]>("Keyboard"),
227
+ }));
211
228
 
212
229
  export const loadCapacitorPreferences = () =>
213
- loadCapacitorModule("preferences", () =>
214
- importNativeModule<CapacitorPreferencesModule>(capacitorPackage("preferences")),
215
- );
230
+ loadCapacitorModule("preferences", async () => ({
231
+ Preferences: getCapacitorPlugin<CapacitorPreferencesModule["Preferences"]>("Preferences"),
232
+ }));
216
233
 
217
234
  export const loadCapacitorPushNotifications = () =>
218
- loadCapacitorModule("pushNotifications", () =>
219
- importNativeModule<CapacitorPushNotificationsModule>(capacitorPackage("push-notifications")),
220
- );
235
+ loadCapacitorModule("pushNotifications", async () => ({
236
+ PushNotifications: getCapacitorPlugin<CapacitorPushNotificationsModule["PushNotifications"]>("PushNotifications"),
237
+ }));
221
238
 
222
239
  export const loadCapacitorSafeArea = () =>
223
- loadCapacitorModule("safeArea", () => importNativeModule<CapacitorSafeAreaModule>("capacitor-plugin-safe-area"));
240
+ loadCapacitorModule("safeArea", async () => ({
241
+ SafeArea: getCapacitorPlugin<CapacitorSafeAreaModule["SafeArea"]>("SafeArea"),
242
+ }));
224
243
 
225
244
  export const loadCapacitorUpdater = () =>
226
- loadCapacitorModule("updater", () => importNativeModule<CapacitorUpdaterModule>("@capgo/capacitor-updater"));
245
+ loadCapacitorModule("updater", async () => ({
246
+ CapacitorUpdater: getCapacitorPlugin<CapacitorUpdaterModule["CapacitorUpdater"]>("CapacitorUpdater"),
247
+ }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "2.2.1-rc.1",
3
+ "version": "2.2.1-rc.2",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {