@inglorious/web 6.28.0 → 6.30.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.
Files changed (58) hide show
  1. package/README.md +31 -2198
  2. package/package.json +50 -38
  3. package/src/auth/index.js +23 -21
  4. package/src/decorators/limit.js +67 -0
  5. package/src/decorators/with-debounce/index.js +6 -57
  6. package/src/decorators/with-throttle/index.js +12 -67
  7. package/src/device/biometrics/index.js +86 -0
  8. package/src/device/compass/handlers.js +163 -0
  9. package/src/{sensors → device}/element-size/handlers.js +2 -2
  10. package/src/device/geolocation/index.js +120 -0
  11. package/src/{keyboard → device/keyboard}/index.js +58 -21
  12. package/src/device/local-notifications/index.js +133 -0
  13. package/src/{sensors → device}/media-query/handlers.js +2 -2
  14. package/src/{sensors → device}/network-status/handlers.js +1 -1
  15. package/src/{sensors → device}/page-visibility/handlers.js +1 -1
  16. package/src/{native → device}/share/index.js +1 -1
  17. package/src/device/storage/index.js +61 -0
  18. package/src/mount.js +7 -4
  19. package/src/native/app-links/index.js +44 -30
  20. package/src/native/back-button/index.js +40 -21
  21. package/src/native/index.js +0 -32
  22. package/src/native/live-update/index.js +104 -92
  23. package/src/native/system-bars/index.js +63 -33
  24. package/src/native/update/index.js +37 -38
  25. package/src/pwa/index.js +67 -3
  26. package/src/pwa/update.js +10 -20
  27. package/types/auth.d.ts +1 -10
  28. package/types/device/biometrics.d.ts +51 -0
  29. package/types/{sensors → device}/compass.d.ts +0 -2
  30. package/types/{sensors → device}/geolocation.d.ts +25 -7
  31. package/types/device/keyboard.d.ts +28 -0
  32. package/types/device/local-notifications.d.ts +76 -0
  33. package/types/device/storage.d.ts +30 -0
  34. package/types/mount.d.ts +11 -5
  35. package/types/native/app-links.d.ts +22 -14
  36. package/types/native/back-button.d.ts +22 -12
  37. package/types/native/index.d.ts +0 -19
  38. package/types/native/live-update.d.ts +25 -32
  39. package/types/native/system-bars.d.ts +24 -8
  40. package/types/native/update.d.ts +12 -25
  41. package/types/pwa.d.ts +11 -20
  42. package/src/pwa/handlers.js +0 -17
  43. package/src/sensors/compass/handlers.js +0 -209
  44. package/src/sensors/geolocation/handlers.js +0 -168
  45. package/src/sensors/geolocation/index.js +0 -3
  46. package/types/keyboard.d.ts +0 -8
  47. /package/src/{sensors → device}/compass/index.js +0 -0
  48. /package/src/{sensors → device}/element-size/index.js +0 -0
  49. /package/src/{native → device}/haptics/index.js +0 -0
  50. /package/src/{sensors → device}/media-query/index.js +0 -0
  51. /package/src/{sensors → device}/network-status/index.js +0 -0
  52. /package/src/{sensors → device}/page-visibility/index.js +0 -0
  53. /package/types/{sensors → device}/element-size.d.ts +0 -0
  54. /package/types/{native → device}/haptics.d.ts +0 -0
  55. /package/types/{sensors → device}/media-query.d.ts +0 -0
  56. /package/types/{sensors → device}/network-status.d.ts +0 -0
  57. /package/types/{sensors → device}/page-visibility.d.ts +0 -0
  58. /package/types/{native → device}/share.d.ts +0 -0
@@ -0,0 +1,51 @@
1
+ import type { AsyncEvents } from "@inglorious/store/async"
2
+
3
+ import { Api } from "../mount"
4
+
5
+ /** What `createBiometrics` needs of `NativeBiometric` from `@capgo/capacitor-native-biometric`. */
6
+ export interface BiometricsPlugin {
7
+ isAvailable(): Promise<{ isAvailable: boolean; biometryType: number }>
8
+ verifyIdentity(options?: BiometricsOptions): Promise<void>
9
+ }
10
+
11
+ /** What the system's prompt says. */
12
+ export interface BiometricsOptions {
13
+ reason?: string
14
+ title?: string
15
+ subtitle?: string
16
+ description?: string
17
+ }
18
+
19
+ export type BiometryType =
20
+ "face" | "fingerprint" | "iris" | "multiple" | "passcode"
21
+
22
+ export interface BiometricsEntity {
23
+ id?: string
24
+ type: string
25
+ isAvailable: boolean
26
+ biometryType: BiometryType | null
27
+ status: "idle" | "loading" | "success" | "error"
28
+ error: "unavailable" | "failed" | null
29
+ result: "verified" | "cancelled" | null
30
+ }
31
+
32
+ export type BiometricsType = {
33
+ create(entity: BiometricsEntity, payload: unknown, api: Api): void
34
+ biometricsAvailable(
35
+ entity: BiometricsEntity,
36
+ answer: { isAvailable: boolean; biometryType: number },
37
+ ): void
38
+ } & AsyncEvents<
39
+ "verify",
40
+ BiometricsEntity,
41
+ BiometricsOptions | undefined,
42
+ BiometricsEntity["result"]
43
+ >
44
+
45
+ /**
46
+ * The type behind "unlock with Face ID": the system's biometric prompt in a
47
+ * native app; never available in a browser.
48
+ */
49
+ export declare function createBiometrics(config?: {
50
+ plugin?: BiometricsPlugin
51
+ }): BiometricsType
@@ -10,8 +10,6 @@ export interface CompassEntity {
10
10
  isLoading: boolean
11
11
  isSupported: boolean
12
12
  manualOffset: number | null
13
- _absoluteListener: ((event: DeviceOrientationEvent) => void) | null
14
- _orientationListener: ((event: DeviceOrientationEvent) => void) | null
15
13
  _isUsingAbsolute: boolean
16
14
  compassTimeout: number | null
17
15
  }
@@ -18,7 +18,6 @@ export interface GeolocationEntity {
18
18
  isWatching: boolean
19
19
  position: GeolocationPosition | null
20
20
  type: string
21
- watchId: number | null
22
21
  }
23
22
 
24
23
  export interface GeolocationError {
@@ -38,21 +37,40 @@ export interface GeolocationPosition {
38
37
  }
39
38
 
40
39
  export type GeolocationType = {
41
- unwatch(entity: GeolocationEntity): void
42
40
  create(entity: GeolocationEntity): void
43
41
  destroy(entity: GeolocationEntity): void
44
- error(entity: GeolocationEntity, error: GeolocationError): void
45
- request(
42
+ geolocationRequest(
46
43
  entity: GeolocationEntity,
47
44
  options: GeolocationOptions | undefined,
48
45
  api: Api,
49
46
  ): void
50
- success(entity: GeolocationEntity, position: GeolocationPosition): void
51
- watch(
47
+ geolocationWatch(
52
48
  entity: GeolocationEntity,
53
49
  options: GeolocationOptions | undefined,
54
50
  api: Api,
55
51
  ): void
52
+ geolocationUnwatch(entity: GeolocationEntity): void
53
+ geolocationSuccess(
54
+ entity: GeolocationEntity,
55
+ position: GeolocationPosition,
56
+ ): void
57
+ geolocationError(entity: GeolocationEntity, error: GeolocationError): void
58
+ }
59
+
60
+ /** What `createGeolocation` needs of `Geolocation` from `@capacitor/geolocation`. */
61
+ export interface GeolocationPlugin {
62
+ getCurrentPosition(options?: GeolocationOptions): Promise<GeolocationPosition>
63
+ watchPosition(
64
+ options: GeolocationOptions,
65
+ callback: (position: GeolocationPosition | null, error?: unknown) => void,
66
+ ): Promise<string>
67
+ clearWatch(options: { id: string }): Promise<void>
56
68
  }
57
69
 
58
- export declare const Geolocation: GeolocationType
70
+ /**
71
+ * The type behind a position: `navigator.geolocation`, or the Capacitor
72
+ * plugin in a native app.
73
+ */
74
+ export declare function createGeolocation(config?: {
75
+ plugin?: GeolocationPlugin
76
+ }): GeolocationType
@@ -0,0 +1,28 @@
1
+ export interface KeyboardEntity {
2
+ id?: string
3
+ type: string
4
+ /** The page has a visual viewport to read the keyboard from. */
5
+ isSupported: boolean
6
+ /** The on-screen keyboard is up. */
7
+ isOpen: boolean
8
+ /** How much of the page the keyboard covers, in pixels: 0 where the page shrinks for it. */
9
+ height: number
10
+ }
11
+
12
+ export interface KeyboardChange {
13
+ isOpen: boolean
14
+ height: number
15
+ }
16
+
17
+ export type KeyboardType = {
18
+ create(entity: KeyboardEntity): void
19
+ destroy(entity: KeyboardEntity): void
20
+ keyboardChange(entity: KeyboardEntity, change: KeyboardChange): void
21
+ }
22
+
23
+ /**
24
+ * The type that knows when the on-screen keyboard is up and how much of the
25
+ * page it covers, setting `--iw-keyboard-height` on `<html>` and the
26
+ * `iw-keyboard-open` class so fixed elements can move above it.
27
+ */
28
+ export declare const Keyboard: KeyboardType
@@ -0,0 +1,76 @@
1
+ import { Api } from "../mount"
2
+
3
+ /** What `createLocalNotifications` needs of `LocalNotifications` from `@capacitor/local-notifications`. */
4
+ export interface LocalNotificationsPlugin {
5
+ checkPermissions(): Promise<{ display: string }>
6
+ requestPermissions(): Promise<{ display: string }>
7
+ schedule(options: {
8
+ notifications: {
9
+ id: number
10
+ title: string
11
+ body?: string
12
+ schedule: { at: Date }
13
+ extra?: { url?: string }
14
+ }[]
15
+ }): Promise<unknown>
16
+ cancel(options: { notifications: { id: number }[] }): Promise<void>
17
+ addListener(
18
+ event: "localNotificationActionPerformed",
19
+ listener: (action: { notification: { extra?: { url?: string } } }) => void,
20
+ ): unknown
21
+ }
22
+
23
+ /** A reminder to show at a given time. */
24
+ export interface LocalNotification {
25
+ /** A whole number, to cancel it by. */
26
+ id: number
27
+ title: string
28
+ body?: string
29
+ at: Date
30
+ /** Where a tap goes. */
31
+ url?: string
32
+ }
33
+
34
+ export type LocalNotificationsPermission =
35
+ "granted" | "denied" | "prompt" | "unsupported"
36
+
37
+ export interface LocalNotificationsEntity {
38
+ id?: string
39
+ type: string
40
+ /** `null` until the device says. */
41
+ permission: LocalNotificationsPermission | null
42
+ }
43
+
44
+ export type LocalNotificationsType = {
45
+ create(entity: LocalNotificationsEntity, payload: unknown, api: Api): void
46
+ localNotificationsAsk(
47
+ entity: LocalNotificationsEntity,
48
+ payload: unknown,
49
+ api: Api,
50
+ ): void
51
+ localNotificationsPermission(
52
+ entity: LocalNotificationsEntity,
53
+ permission: LocalNotificationsPermission,
54
+ ): void
55
+ localNotificationSchedule(
56
+ entity: LocalNotificationsEntity,
57
+ notification: LocalNotification,
58
+ ): void
59
+ localNotificationCancel(entity: LocalNotificationsEntity, id: number): void
60
+ localNotificationTap(
61
+ entity: LocalNotificationsEntity,
62
+ url: string | undefined,
63
+ api: Api,
64
+ ): void
65
+ }
66
+
67
+ /**
68
+ * Reminders the device shows at a given time: through the Capacitor plugin in
69
+ * a native app, even with the app closed; through the Notification API in a
70
+ * browser, while the page is open.
71
+ */
72
+ export declare function createLocalNotifications(config?: {
73
+ plugin?: LocalNotificationsPlugin
74
+ /** Where a tap goes. Defaults to `#router:navigate`. */
75
+ onTap?: (url: string, api: Api) => void
76
+ }): LocalNotificationsType
@@ -0,0 +1,30 @@
1
+ /** What `createNativeStorage` needs of `Preferences` from `@capacitor/preferences`. */
2
+ export interface PreferencesPlugin {
3
+ get(options: { key: string }): Promise<{ value: string | null }>
4
+ set(options: { key: string; value: string }): Promise<void>
5
+ remove(options: { key: string }): Promise<void>
6
+ }
7
+
8
+ /** A storage for `withStorage`: answering with promises in a native app. */
9
+ export interface NativeStorage {
10
+ getItem(key: string): string | null | Promise<string | null>
11
+ setItem(key: string, value: string): void | Promise<void>
12
+ removeItem(key: string): void | Promise<void>
13
+ }
14
+
15
+ /** Capacitor Preferences in a native app, `localStorage` in a browser. */
16
+ export declare function createNativeStorage(config?: {
17
+ plugin?: PreferencesPlugin
18
+ }): NativeStorage
19
+
20
+ /** What `createSecureStorage` needs of `NativeBiometric` from `@capgo/capacitor-native-biometric`. */
21
+ export interface SecureStoragePlugin {
22
+ getData(options: { key: string }): Promise<{ value: string }>
23
+ setData(options: { key: string; value: string }): Promise<void>
24
+ deleteData(options: { key: string }): Promise<void>
25
+ }
26
+
27
+ /** The Keychain or Keystore in a native app, `localStorage` in a browser. */
28
+ export declare function createSecureStorage(config?: {
29
+ plugin?: SecureStoragePlugin
30
+ }): NativeStorage
package/types/mount.d.ts CHANGED
@@ -42,7 +42,7 @@ declare module "@inglorious/store" {
42
42
  export type { Api }
43
43
 
44
44
  /**
45
- * Root error-boundary options for `mount`.
45
+ * Options for `mount`.
46
46
  */
47
47
  export interface MountOptions<
48
48
  TEntity extends BaseEntity = BaseEntity,
@@ -59,6 +59,11 @@ export interface MountOptions<
59
59
  error: unknown,
60
60
  api: Api<TEntity, TState>,
61
61
  ) => TemplateResult | null
62
+ /**
63
+ * Whether markup already in the element, as a server-rendered page has, is hydrated
64
+ * rather than replaced. Defaults to `true`.
65
+ */
66
+ hydrate?: boolean
62
67
  /**
63
68
  * Whether navigations are announced to screen readers and move focus to the top of the
64
69
  * new page. Only apps with the `Router` type navigate. Defaults to `true`.
@@ -72,12 +77,13 @@ export interface MountOptions<
72
77
  }
73
78
 
74
79
  /**
75
- * Mounts a lit-html template to the DOM and subscribes to a store for re-rendering.
80
+ * Mounts a lit-html template to the DOM and subscribes to a store for re-rendering,
81
+ * hydrating markup already in the element. Once mounted, it notifies `init`.
76
82
  * @param store The application state store.
77
83
  * @param renderFn The root render function that receives the API and returns a template.
78
84
  * @param element The DOM element to mount the template to.
79
- * @param options Root error-boundary options (`onError`, `fallback`).
80
- * @returns An unsubscribe function.
85
+ * @param options Error-boundary, hydration and navigation options.
86
+ * @returns An unsubscribe function, once mounted.
81
87
  */
82
88
  export function mount<
83
89
  TEntity extends BaseEntity = BaseEntity,
@@ -88,4 +94,4 @@ export function mount<
88
94
  renderFn: (api: Api<TEntity, TState, TEvents>) => TemplateResult | null,
89
95
  element: HTMLElement | DocumentFragment,
90
96
  options?: MountOptions<TEntity, TState>,
91
- ): () => void
97
+ ): Promise<() => void>
@@ -1,7 +1,5 @@
1
- import { Api } from "../mount"
2
-
3
- /** What `watchAppLinks` needs of `App` from `@capacitor/app`. */
4
- export interface AppLinksApp {
1
+ /** What `createAppLinks` needs of `App` from `@capacitor/app`. */
2
+ export interface AppLinksPlugin {
5
3
  getLaunchUrl(): Promise<{ url: string } | undefined>
6
4
  addListener(
7
5
  event: "appUrlOpen",
@@ -9,19 +7,29 @@ export interface AppLinksApp {
9
7
  ): Promise<{ remove(): Promise<void> }>
10
8
  }
11
9
 
12
- export interface WatchAppLinksOptions {
10
+ export interface AppLinksConfig {
11
+ plugin: AppLinksPlugin
13
12
  /** The router entity to notify. Defaults to `router`. */
13
+ router?: string
14
+ }
15
+
16
+ export interface AppLinksEntity {
14
17
  id?: string
18
+ type: string
19
+ /** The last link opened, or `null`. */
20
+ url: string | null
21
+ }
22
+
23
+ export type AppLinksType = {
24
+ create(entity: AppLinksEntity): void
25
+ destroy(entity: AppLinksEntity): void
26
+ /** Sends the router to the link's path. */
27
+ appLinkOpen(entity: AppLinksEntity, url: string): void
15
28
  }
16
29
 
17
30
  /**
18
- * Opens Universal Links and App Links in the router, both the link that
19
- * started the app and those that arrive while it runs, notifying
20
- * `#${id}:navigate`. Does nothing outside a native app.
21
- * @returns A function that stops listening.
31
+ * The type that opens Universal Links and App Links in the router, both the
32
+ * link that started the app and those that arrive while it runs. Does nothing
33
+ * outside a native app.
22
34
  */
23
- export declare function watchAppLinks(
24
- app: AppLinksApp,
25
- store: Pick<Api, "notify">,
26
- options?: WatchAppLinksOptions,
27
- ): () => Promise<void>
35
+ export declare function createAppLinks(config: AppLinksConfig): AppLinksType
@@ -1,5 +1,5 @@
1
- /** What `watchBackButton` needs of `App` from `@capacitor/app`. */
2
- export interface BackButtonApp {
1
+ /** What `createBackButton` needs of `App` from `@capacitor/app`. */
2
+ export interface BackButtonPlugin {
3
3
  exitApp(): Promise<void>
4
4
  addListener(
5
5
  event: "backButton",
@@ -7,18 +7,28 @@ export interface BackButtonApp {
7
7
  ): Promise<{ remove(): Promise<void> }>
8
8
  }
9
9
 
10
- export interface WatchBackButtonOptions {
10
+ export interface BackButtonConfig {
11
+ plugin: BackButtonPlugin
12
+ }
13
+
14
+ export interface BackButtonEntity {
15
+ id?: string
16
+ type: string
11
17
  /** The top-level paths, where back closes the app. Defaults to `["/"]`. */
12
- rootPaths?: string[]
18
+ rootPaths: string[]
19
+ }
20
+
21
+ export type BackButtonType = {
22
+ create(entity: BackButtonEntity): void
23
+ destroy(entity: BackButtonEntity): void
24
+ /** Back in history, or closes the app on a root path or with no history left. */
25
+ backButtonPress(entity: BackButtonEntity, event: { canGoBack: boolean }): void
13
26
  }
14
27
 
15
28
  /**
16
- * Android's back button and back gesture: back in history, or closes the app
17
- * on a root path or when there is no history left. Does nothing outside a
18
- * native app.
19
- * @returns A function that stops listening.
29
+ * The type behind Android's back button and back gesture. Does nothing outside
30
+ * a native app.
20
31
  */
21
- export declare function watchBackButton(
22
- app: BackButtonApp,
23
- options?: WatchBackButtonOptions,
24
- ): () => Promise<void>
32
+ export declare function createBackButton(
33
+ config: BackButtonConfig,
34
+ ): BackButtonType
@@ -1,20 +1 @@
1
1
  export declare function isNative(): boolean
2
-
3
- /** What `createNativeStorage` needs of `Preferences` from `@capacitor/preferences`. */
4
- export interface PreferencesPlugin {
5
- get(options: { key: string }): Promise<{ value: string | null }>
6
- set(options: { key: string; value: string }): Promise<void>
7
- remove(options: { key: string }): Promise<void>
8
- }
9
-
10
- /** A storage for `withStorage`: answering with promises in a native app. */
11
- export interface NativeStorage {
12
- getItem(key: string): string | null | Promise<string | null>
13
- setItem(key: string, value: string): void | Promise<void>
14
- removeItem(key: string): void | Promise<void>
15
- }
16
-
17
- /** Capacitor Preferences in a native app, `localStorage` in a browser. */
18
- export declare function createNativeStorage(config?: {
19
- plugin?: PreferencesPlugin
20
- }): NativeStorage
@@ -1,5 +1,3 @@
1
- import { Api } from "../mount"
2
-
3
1
  /** What a publisher puts at the manifest URL. */
4
2
  export interface LiveUpdateManifest {
5
3
  /** Grows with every bundle: newer than the running release means wanted. */
@@ -14,7 +12,7 @@ export interface LiveUpdateManifest {
14
12
  signature?: string
15
13
  }
16
14
 
17
- /** What the live update types need of `LiveUpdate` from `@capawesome/capacitor-live-update`. */
15
+ /** What `createLiveUpdate` needs of `LiveUpdate` from `@capawesome/capacitor-live-update`. */
18
16
  export interface LiveUpdatePlugin {
19
17
  ready(): Promise<unknown>
20
18
  reload(): Promise<void>
@@ -29,7 +27,7 @@ export interface LiveUpdatePlugin {
29
27
  setNextBundle(options: { bundleId: string | null }): Promise<void>
30
28
  }
31
29
 
32
- /** What `watchLiveUpdate` needs of `App` from `@capacitor/app`. */
30
+ /** What `createLiveUpdate` needs of `App` from `@capacitor/app`. */
33
31
  export interface LiveUpdateApp {
34
32
  getInfo(): Promise<{ build: string }>
35
33
  addListener(
@@ -38,50 +36,45 @@ export interface LiveUpdateApp {
38
36
  ): Promise<{ remove(): Promise<void> }>
39
37
  }
40
38
 
39
+ export interface LiveUpdateConfig {
40
+ plugin: LiveUpdatePlugin
41
+ /** Needed to check for bundles; without it the type only offers `liveUpdateApply`. */
42
+ app?: LiveUpdateApp
43
+ manifestUrl?: string
44
+ /** The release of the running web code. None for a development build. */
45
+ release?: number
46
+ /** How often to check for a new bundle. Defaults to one hour. */
47
+ checkEveryMs?: number
48
+ }
49
+
41
50
  export interface LiveUpdateEntity {
42
51
  id?: string
43
52
  type: string
44
53
  /** A bundle is downloaded and waits for the next trip to the background. */
45
54
  isUpdateReady: boolean
55
+ /** The release of the downloaded bundle, or `null`. */
56
+ pendingRelease: number | null
46
57
  }
47
58
 
48
59
  export type LiveUpdateType = {
49
60
  create(entity: LiveUpdateEntity): void
50
- liveUpdateReady(entity: LiveUpdateEntity): void
61
+ destroy(entity: LiveUpdateEntity): void
62
+ liveUpdateReady(entity: LiveUpdateEntity, release: number): void
51
63
  /** Moves over to the downloaded bundle now, reloading the app. */
52
64
  liveUpdateApply(): void
53
65
  }
54
66
 
55
- /** The type that offers a downloaded live update. */
56
- export declare function createLiveUpdate(config: {
57
- plugin: Pick<LiveUpdatePlugin, "reload">
58
- }): LiveUpdateType
67
+ /**
68
+ * The type that keeps a native app on its latest published web code, applying
69
+ * a downloaded bundle on the next trip to the background. Does nothing outside
70
+ * a native app.
71
+ */
72
+ export declare function createLiveUpdate(
73
+ config: LiveUpdateConfig,
74
+ ): LiveUpdateType
59
75
 
60
76
  /** Whether a published bundle should replace the running one. */
61
77
  export declare function isLiveUpdateWanted(
62
78
  manifest: Pick<LiveUpdateManifest, "release" | "minBuild"> | null,
63
79
  installed: { release: number; build: number },
64
80
  ): boolean
65
-
66
- export interface WatchLiveUpdateOptions {
67
- plugin: LiveUpdatePlugin
68
- app: LiveUpdateApp
69
- /** Where to announce a downloaded bundle. */
70
- store?: Pick<Api, "notify">
71
- manifestUrl: string
72
- /** The release of the running web code. */
73
- release: number
74
- /** The LiveUpdate entity to announce to. Defaults to `liveUpdate`. */
75
- id?: string
76
- /** How often to check for a new bundle. Defaults to one hour. */
77
- checkEveryMs?: number
78
- }
79
-
80
- /**
81
- * Keeps a native app on its latest published web code, applying a downloaded
82
- * bundle on the next trip to the background. Does nothing outside a native app.
83
- * @returns A function that stops watching.
84
- */
85
- export declare function watchLiveUpdate(
86
- options: WatchLiveUpdateOptions,
87
- ): () => Promise<void>
@@ -1,4 +1,4 @@
1
- /** What `watchSystemBars` needs of `SystemBars` from `@capacitor/core`. */
1
+ /** What `createSystemBars` needs of `SystemBars` from `@capacitor/core`. */
2
2
  export interface SystemBarsPlugin {
3
3
  setStyle(options: { style: SystemBarsStyle }): Promise<void>
4
4
  }
@@ -6,15 +6,31 @@ export interface SystemBarsPlugin {
6
6
  /** `SystemBarsStyle` from `@capacitor/core`: the colour of the background. */
7
7
  export type SystemBarsStyle = "DARK" | "LIGHT" | "DEFAULT"
8
8
 
9
+ export interface SystemBarsConfig {
10
+ plugin: SystemBarsPlugin
11
+ }
12
+
13
+ export interface SystemBarsEntity {
14
+ id?: string
15
+ type: string
16
+ /** The bars' current style, or `null` outside a native app. */
17
+ style: SystemBarsStyle | null
18
+ }
19
+
20
+ export type SystemBarsType = {
21
+ create(entity: SystemBarsEntity): void
22
+ destroy(entity: SystemBarsEntity): void
23
+ systemBarsStyleChange(entity: SystemBarsEntity, style: SystemBarsStyle): void
24
+ }
25
+
9
26
  /**
10
- * Keeps the status and navigation bars readable on the app's own colours, as
11
- * its `color-scheme` sets them, and follows theme changes. Does nothing
12
- * outside a native app.
13
- * @returns A function that stops following.
27
+ * The type that keeps the status and navigation bars readable on the app's own
28
+ * colours, as its `color-scheme` sets them, and follows theme changes. Does
29
+ * nothing outside a native app.
14
30
  */
15
- export declare function watchSystemBars(
16
- systemBars: SystemBarsPlugin,
17
- ): () => void
31
+ export declare function createSystemBars(
32
+ config: SystemBarsConfig,
33
+ ): SystemBarsType
18
34
 
19
35
  /**
20
36
  * The bars' style for a `color-scheme` value: `"DARK"` on a dark-only page,
@@ -17,8 +17,19 @@ export interface NativeUpdateAdapter {
17
17
  ): Promise<NativeUpdateRequirement | null>
18
18
  }
19
19
 
20
+ /** What `createNativeUpdate` needs of `App` from `@capacitor/app`. */
21
+ export interface NativeUpdatePlugin {
22
+ getInfo(): Promise<{ build: string }>
23
+ addListener(
24
+ event: "resume",
25
+ listener: () => void,
26
+ ): Promise<{ remove(): Promise<void> }>
27
+ }
28
+
20
29
  export interface NativeUpdateConfig {
21
30
  adapter: NativeUpdateAdapter
31
+ /** Checks the installed build at launch and on every resume, in a native app. */
32
+ plugin?: NativeUpdatePlugin
22
33
  }
23
34
 
24
35
  export interface NativeUpdateEntity {
@@ -36,6 +47,7 @@ export interface NativeUpdateCheckPayload {
36
47
 
37
48
  export type NativeUpdateType = {
38
49
  create(entity: NativeUpdateEntity): void
50
+ destroy(entity: NativeUpdateEntity): void
39
51
  /** Compares the installed build with the platform's minimum. */
40
52
  nativeUpdateCheck(
41
53
  entity: NativeUpdateEntity,
@@ -55,28 +67,3 @@ export type NativeUpdateType = {
55
67
  export declare function createNativeUpdate(
56
68
  config: NativeUpdateConfig,
57
69
  ): NativeUpdateType
58
-
59
- /** What `watchNativeUpdate` needs of `App` from `@capacitor/app`. */
60
- export interface NativeApp {
61
- getInfo(): Promise<{ build: string }>
62
- addListener(
63
- event: "resume",
64
- listener: () => void,
65
- ): Promise<{ remove(): Promise<void> }>
66
- }
67
-
68
- export interface WatchNativeUpdateOptions {
69
- /** The NativeUpdate entity to notify. Defaults to `nativeUpdate`. */
70
- id?: string
71
- }
72
-
73
- /**
74
- * Checks the installed build at launch and on every resume, notifying
75
- * `#${id}:nativeUpdateCheck`. Does nothing outside a native app.
76
- * @returns A function that stops watching.
77
- */
78
- export declare function watchNativeUpdate(
79
- app: NativeApp,
80
- store: Pick<Api, "notify">,
81
- options?: WatchNativeUpdateOptions,
82
- ): () => Promise<void>
package/types/pwa.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- import { Api } from "./mount"
1
+ export interface PwaUpdateConfig {
2
+ /** How often to check for a new version. Defaults to one hour. */
3
+ checkEveryMs?: number
4
+ }
2
5
 
3
6
  export interface PwaUpdateEntity {
4
7
  id?: string
@@ -9,31 +12,19 @@ export interface PwaUpdateEntity {
9
12
 
10
13
  export type PwaUpdateType = {
11
14
  create(entity: PwaUpdateEntity): void
15
+ destroy(entity: PwaUpdateEntity): void
16
+ pwaUpdateReady(entity: PwaUpdateEntity): void
12
17
  /** Moves over to the waiting version now, reloading the page. */
13
18
  pwaUpdateApply(): void
14
- pwaUpdateReady(entity: PwaUpdateEntity): void
15
- }
16
-
17
- export declare const PwaUpdate: PwaUpdateType
18
-
19
- export interface WatchPwaUpdateOptions {
20
- /** The PwaUpdate entity to announce to. Defaults to `pwaUpdate`. */
21
- id?: string
22
- /** How often to check for a new version. Defaults to one hour. */
23
- checkEveryMs?: number
24
19
  }
25
20
 
26
21
  /**
27
- * Keeps an installed PWA on its latest version, applying a downloaded one at
28
- * boot and on each trip to or from the background. A version that lands
29
- * mid-session is announced to `store` as `#${id}:pwaUpdateReady`.
30
- * @returns A function that stops watching.
22
+ * The type that keeps an installed PWA on its latest version, applying a
23
+ * downloaded one at boot and on each trip to or from the background, and
24
+ * setting `isUpdateReady` when a version lands mid-session. Does nothing in a
25
+ * native app or without a service worker.
31
26
  */
32
- export declare function watchPwaUpdate(
33
- registration: ServiceWorkerRegistration,
34
- store?: Pick<Api, "notify">,
35
- options?: WatchPwaUpdateOptions,
36
- ): () => void
27
+ export declare function createPwaUpdate(config?: PwaUpdateConfig): PwaUpdateType
37
28
 
38
29
  /** Moves the page over to the waiting version and reloads. */
39
30
  export declare function applyPwaUpdate(
@@ -1,17 +0,0 @@
1
- /**
2
- * @typedef {import("../../types/pwa.js").PwaUpdateEntity} PwaUpdateEntity
3
- */
4
-
5
- import { applyPwaUpdate } from "./update.js"
6
-
7
- export function create(entity) {
8
- entity.isUpdateReady ??= false
9
- }
10
-
11
- export function pwaUpdateApply() {
12
- applyPwaUpdate()
13
- }
14
-
15
- export function pwaUpdateReady(entity) {
16
- entity.isUpdateReady = true
17
- }