@inglorious/web 6.28.0 → 6.29.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 (36) hide show
  1. package/README.md +257 -200
  2. package/package.json +49 -37
  3. package/src/device/biometrics/index.js +86 -0
  4. package/src/device/compass/handlers.js +163 -0
  5. package/src/{sensors → device}/element-size/handlers.js +2 -2
  6. package/src/device/geolocation/index.js +120 -0
  7. package/src/device/local-notifications/index.js +133 -0
  8. package/src/{sensors → device}/media-query/handlers.js +2 -2
  9. package/src/{sensors → device}/network-status/handlers.js +1 -1
  10. package/src/{sensors → device}/page-visibility/handlers.js +1 -1
  11. package/src/{native → device}/share/index.js +1 -1
  12. package/src/device/storage/index.js +61 -0
  13. package/src/native/index.js +0 -32
  14. package/types/device/biometrics.d.ts +51 -0
  15. package/types/{sensors → device}/compass.d.ts +0 -2
  16. package/types/{sensors → device}/geolocation.d.ts +25 -7
  17. package/types/device/local-notifications.d.ts +76 -0
  18. package/types/device/storage.d.ts +30 -0
  19. package/types/native/index.d.ts +0 -19
  20. package/src/sensors/compass/handlers.js +0 -209
  21. package/src/sensors/geolocation/handlers.js +0 -168
  22. package/src/sensors/geolocation/index.js +0 -3
  23. /package/src/{sensors → device}/compass/index.js +0 -0
  24. /package/src/{sensors → device}/element-size/index.js +0 -0
  25. /package/src/{native → device}/haptics/index.js +0 -0
  26. /package/src/{keyboard → device/keyboard}/index.js +0 -0
  27. /package/src/{sensors → device}/media-query/index.js +0 -0
  28. /package/src/{sensors → device}/network-status/index.js +0 -0
  29. /package/src/{sensors → device}/page-visibility/index.js +0 -0
  30. /package/types/{sensors → device}/element-size.d.ts +0 -0
  31. /package/types/{native → device}/haptics.d.ts +0 -0
  32. /package/types/{keyboard.d.ts → device/keyboard.d.ts} +0 -0
  33. /package/types/{sensors → device}/media-query.d.ts +0 -0
  34. /package/types/{sensors → device}/network-status.d.ts +0 -0
  35. /package/types/{sensors → device}/page-visibility.d.ts +0 -0
  36. /package/types/{native → device}/share.d.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/web",
3
- "version": "6.28.0",
3
+ "version": "6.29.0",
4
4
  "description": "A new web framework that leverages the power of the Inglorious Store combined with the performance and simplicity of lit-html.",
5
5
  "author": "Matteo Antony Mistretta <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "contributors": [
@@ -53,18 +53,6 @@
53
53
  "types": "./types/native/system-bars.d.ts",
54
54
  "import": "./src/native/system-bars/index.js"
55
55
  },
56
- "./keyboard": {
57
- "types": "./types/keyboard.d.ts",
58
- "import": "./src/keyboard/index.js"
59
- },
60
- "./native/haptics": {
61
- "types": "./types/native/haptics.d.ts",
62
- "import": "./src/native/haptics/index.js"
63
- },
64
- "./native/share": {
65
- "types": "./types/native/share.d.ts",
66
- "import": "./src/native/share/index.js"
67
- },
68
56
  "./decorators/with-debounce": {
69
57
  "types": "./types/decorators/with-debounce.d.ts",
70
58
  "import": "./src/decorators/with-debounce/index.js"
@@ -81,6 +69,54 @@
81
69
  "types": "./types/decorators/with-throttle.d.ts",
82
70
  "import": "./src/decorators/with-throttle/index.js"
83
71
  },
72
+ "./device/biometrics": {
73
+ "types": "./types/device/biometrics.d.ts",
74
+ "import": "./src/device/biometrics/index.js"
75
+ },
76
+ "./device/compass": {
77
+ "types": "./types/device/compass.d.ts",
78
+ "import": "./src/device/compass/index.js"
79
+ },
80
+ "./device/element-size": {
81
+ "types": "./types/device/element-size.d.ts",
82
+ "import": "./src/device/element-size/index.js"
83
+ },
84
+ "./device/geolocation": {
85
+ "types": "./types/device/geolocation.d.ts",
86
+ "import": "./src/device/geolocation/index.js"
87
+ },
88
+ "./device/haptics": {
89
+ "types": "./types/device/haptics.d.ts",
90
+ "import": "./src/device/haptics/index.js"
91
+ },
92
+ "./device/keyboard": {
93
+ "types": "./types/device/keyboard.d.ts",
94
+ "import": "./src/device/keyboard/index.js"
95
+ },
96
+ "./device/local-notifications": {
97
+ "types": "./types/device/local-notifications.d.ts",
98
+ "import": "./src/device/local-notifications/index.js"
99
+ },
100
+ "./device/media-query": {
101
+ "types": "./types/device/media-query.d.ts",
102
+ "import": "./src/device/media-query/index.js"
103
+ },
104
+ "./device/network-status": {
105
+ "types": "./types/device/network-status.d.ts",
106
+ "import": "./src/device/network-status/index.js"
107
+ },
108
+ "./device/page-visibility": {
109
+ "types": "./types/device/page-visibility.d.ts",
110
+ "import": "./src/device/page-visibility/index.js"
111
+ },
112
+ "./device/share": {
113
+ "types": "./types/device/share.d.ts",
114
+ "import": "./src/device/share/index.js"
115
+ },
116
+ "./device/storage": {
117
+ "types": "./types/device/storage.d.ts",
118
+ "import": "./src/device/storage/index.js"
119
+ },
84
120
  "./directives/*": {
85
121
  "types": "./types/directives/*.d.ts",
86
122
  "import": "./src/directives/*.js"
@@ -114,30 +150,6 @@
114
150
  "types": "./types/router.d.ts",
115
151
  "import": "./src/router/index.js"
116
152
  },
117
- "./sensors/compass": {
118
- "types": "./types/sensors/compass.d.ts",
119
- "import": "./src/sensors/compass/index.js"
120
- },
121
- "./sensors/element-size": {
122
- "types": "./types/sensors/element-size.d.ts",
123
- "import": "./src/sensors/element-size/index.js"
124
- },
125
- "./sensors/geolocation": {
126
- "types": "./types/sensors/geolocation.d.ts",
127
- "import": "./src/sensors/geolocation/index.js"
128
- },
129
- "./sensors/media-query": {
130
- "types": "./types/sensors/media-query.d.ts",
131
- "import": "./src/sensors/media-query/index.js"
132
- },
133
- "./sensors/network-status": {
134
- "types": "./types/sensors/network-status.d.ts",
135
- "import": "./src/sensors/network-status/index.js"
136
- },
137
- "./sensors/page-visibility": {
138
- "types": "./types/sensors/page-visibility.d.ts",
139
- "import": "./src/sensors/page-visibility/index.js"
140
- },
141
153
  "./static": {
142
154
  "types": "./types/static.d.ts",
143
155
  "import": "./src/static.js"
@@ -0,0 +1,86 @@
1
+ import { handleRequest } from "@inglorious/store/async"
2
+
3
+ import { isNative } from "../../native/index.js"
4
+
5
+ const UNAVAILABLE = "unavailable"
6
+ const FAILED = "failed"
7
+ const USER_CANCEL = 16
8
+ const TYPES = {
9
+ 1: "fingerprint",
10
+ 2: "face",
11
+ 3: "fingerprint",
12
+ 4: "face",
13
+ 5: "iris",
14
+ 6: "multiple",
15
+ 7: "passcode",
16
+ }
17
+
18
+ /**
19
+ * The type behind "unlock with Face ID": `verify` shows the system's
20
+ * biometric prompt through `NativeBiometric` from
21
+ * `@capgo/capacitor-native-biometric`, given as `plugin`, in a native app.
22
+ *
23
+ * `isAvailable` says whether the device can verify, to hide the button
24
+ * otherwise, and `biometryType` (`"face"`, `"fingerprint"`, `"iris"`,
25
+ * `"multiple"` or `"passcode"`) to name it. `result` is `"verified"` or
26
+ * `"cancelled"`: closing the prompt is not an error. `status` and `error`
27
+ * (`"unavailable"` or `"failed"`) are those of `handleRequest`. A browser has
28
+ * no equivalent: there it is never available.
29
+ *
30
+ * @param {{ plugin?: object }} [config]
31
+ *
32
+ * @example
33
+ * import { NativeBiometric } from "@capgo/capacitor-native-biometric"
34
+ * const types = { Biometrics: createBiometrics({ plugin: NativeBiometric }) }
35
+ * api.notify("#biometrics:verify", { reason: "Unlock your account" })
36
+ */
37
+ export function createBiometrics({ plugin } = {}) {
38
+ const device = plugin && isNative() ? plugin : null
39
+
40
+ return {
41
+ create(entity, _, api) {
42
+ const { id } = entity
43
+ entity.isAvailable ??= false
44
+ entity.biometryType ??= null
45
+ entity.status ??= "idle"
46
+ entity.error ??= null
47
+ entity.result ??= null
48
+ device
49
+ ?.isAvailable()
50
+ .then((answer) => api.notify(`#${id}:biometricsAvailable`, answer))
51
+ },
52
+
53
+ biometricsAvailable(entity, { isAvailable, biometryType }) {
54
+ entity.isAvailable = isAvailable
55
+ entity.biometryType = TYPES[biometryType] ?? null
56
+ },
57
+
58
+ ...handleRequest(
59
+ "verify",
60
+ {
61
+ start(entity) {
62
+ entity.result = null
63
+ },
64
+ run: (options) => verify(device, options),
65
+ success(entity, result) {
66
+ entity.result = result
67
+ },
68
+ },
69
+ {
70
+ toError: (error) =>
71
+ error?.message === UNAVAILABLE ? UNAVAILABLE : FAILED,
72
+ },
73
+ ),
74
+ }
75
+ }
76
+
77
+ async function verify(device, options = {}) {
78
+ if (!device) throw new Error(UNAVAILABLE)
79
+ try {
80
+ await device.verifyIdentity(options)
81
+ return "verified"
82
+ } catch (error) {
83
+ if (Number(error?.code) === USER_CANCEL) return "cancelled"
84
+ throw error
85
+ }
86
+ }
@@ -0,0 +1,163 @@
1
+ /**
2
+ * @typedef {import("../../../types/device/compass.js").CompassEntity} CompassEntity
3
+ * @typedef {import("../../../types/device/compass.js").CompassError} CompassError
4
+ */
5
+
6
+ const COMPASS_TIMEOUT = 3000
7
+
8
+ const FULL_CIRCLE = 360
9
+ const DEFAULT_ORIENTATION = 0
10
+ const DEFAULT_ERROR_CODE = 0
11
+
12
+ const watches = new Map()
13
+
14
+ export function create(entity) {
15
+ entity.error ??= null
16
+ entity.heading ??= null
17
+ entity.isActive ??= false
18
+ entity.isPermissionGranted ??= false
19
+ entity.isLoading ??= false
20
+ entity.isSupported = isCompassSupported()
21
+ entity.manualOffset ??= 0
22
+ }
23
+
24
+ export function destroy(entity) {
25
+ compassUnwatch(entity)
26
+ }
27
+
28
+ export function compassUnwatch(entity) {
29
+ watches.get(entity.id)?.()
30
+ watches.delete(entity.id)
31
+ entity.isLoading = false
32
+ entity.isActive = false
33
+ }
34
+
35
+ export function compassError(entity, error) {
36
+ entity.error = normalizeError(error)
37
+ entity.isLoading = false
38
+ entity.isPermissionGranted = false
39
+ }
40
+
41
+ export function compassPermissionsRequest(entity, _, api) {
42
+ const { id } = entity
43
+ entity.isSupported = isCompassSupported()
44
+ entity.error = null
45
+
46
+ if (!entity.isSupported) {
47
+ api.notify(`#${id}:compassError`, createUnsupportedError())
48
+ return
49
+ }
50
+
51
+ entity.isLoading = true
52
+ requestPermission().then(
53
+ (permission) =>
54
+ permission === "granted"
55
+ ? api.notify(`#${id}:compassPermissionsGrant`)
56
+ : api.notify(`#${id}:compassError`, createPermissionDeniedError()),
57
+ (error) => api.notify(`#${id}:compassError`, error),
58
+ )
59
+ }
60
+
61
+ export function compassPermissionsGrant(entity) {
62
+ entity.isLoading = false
63
+ entity.isPermissionGranted = true
64
+ }
65
+
66
+ export function compassWatch(entity, _, api) {
67
+ const { id, manualOffset } = entity
68
+ const win = getWindow()
69
+ if (!win || watches.has(id)) return
70
+
71
+ const timeoutId = setTimeout(
72
+ () => api.notify(`#${id}:compassActiveChange`, false),
73
+ COMPASS_TIMEOUT,
74
+ )
75
+
76
+ const onOrientation = (event) => {
77
+ if (typeof event?.alpha !== "number") return
78
+ clearTimeout(timeoutId)
79
+ api.notify(`#${id}:compassActiveChange`, true)
80
+ api.notify(
81
+ `#${id}:compassHeadingChange`,
82
+ heading(event.alpha, manualOffset),
83
+ )
84
+ }
85
+
86
+ let isUsingAbsolute = false
87
+ const onAbsolute = (event) => {
88
+ if (!isUsingAbsolute) {
89
+ isUsingAbsolute = true
90
+ win.removeEventListener("deviceorientation", onOrientation)
91
+ }
92
+ onOrientation(event)
93
+ }
94
+
95
+ win.addEventListener("deviceorientationabsolute", onAbsolute)
96
+ win.addEventListener("deviceorientation", onOrientation)
97
+
98
+ watches.set(id, () => {
99
+ clearTimeout(timeoutId)
100
+ win.removeEventListener("deviceorientation", onOrientation)
101
+ win.removeEventListener("deviceorientationabsolute", onAbsolute)
102
+ })
103
+ }
104
+
105
+ export function compassActiveChange(entity, value) {
106
+ entity.isActive = value
107
+ }
108
+
109
+ export function compassHeadingChange(entity, value) {
110
+ entity.isLoading = false
111
+ entity.heading = value
112
+ }
113
+
114
+ function heading(alpha, manualOffset) {
115
+ const degrees = alpha - getScreenAngle() + manualOffset
116
+ return Math.round(((degrees % FULL_CIRCLE) + FULL_CIRCLE) % FULL_CIRCLE)
117
+ }
118
+
119
+ function requestPermission() {
120
+ return (
121
+ globalThis.DeviceOrientationEvent?.requestPermission?.() ??
122
+ Promise.resolve("granted")
123
+ )
124
+ }
125
+
126
+ function getWindow() {
127
+ return typeof window !== "undefined" ? window : null
128
+ }
129
+
130
+ function getScreenAngle() {
131
+ const win = getWindow()
132
+ return (
133
+ win?.screen?.orientation?.angle ?? win?.orientation ?? DEFAULT_ORIENTATION
134
+ )
135
+ }
136
+
137
+ function isCompassSupported() {
138
+ return (
139
+ typeof DeviceOrientationEvent !== "undefined" &&
140
+ Boolean(getWindow()?.addEventListener)
141
+ )
142
+ }
143
+
144
+ function createUnsupportedError() {
145
+ return {
146
+ code: 0,
147
+ message: "Compass is not supported by this environment.",
148
+ }
149
+ }
150
+
151
+ function createPermissionDeniedError() {
152
+ return {
153
+ code: 1,
154
+ message: "Compass permission denied.",
155
+ }
156
+ }
157
+
158
+ function normalizeError(error) {
159
+ return {
160
+ code: error?.code ?? DEFAULT_ERROR_CODE,
161
+ message: error?.message ?? String(error),
162
+ }
163
+ }
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @typedef {import("../../../types/sensors/element-size.js").ElementSizeEntity} ElementSizeEntity
3
- * @typedef {import("../../../types/sensors/element-size.js").ElementSizeSize} ElementSizeSize
2
+ * @typedef {import("../../../types/device/element-size.js").ElementSizeEntity} ElementSizeEntity
3
+ * @typedef {import("../../../types/device/element-size.js").ElementSizeSize} ElementSizeSize
4
4
  */
5
5
 
6
6
  const listeners = new Map()
@@ -0,0 +1,120 @@
1
+ import { isNative } from "../../native/index.js"
2
+
3
+ const UNSUPPORTED = {
4
+ code: 0,
5
+ message: "Geolocation is not supported by this environment.",
6
+ }
7
+
8
+ const watches = new Map()
9
+
10
+ /**
11
+ * The type behind a position: `geolocationRequest` reads it once,
12
+ * `geolocationWatch` follows it until `geolocationUnwatch`. In a native app it
13
+ * uses `Geolocation` from `@capacitor/geolocation` when given as `plugin`, so
14
+ * iOS asks once, for the app; elsewhere `navigator.geolocation`.
15
+ *
16
+ * @param {{ plugin?: object }} [config]
17
+ *
18
+ * @example
19
+ * import { Geolocation } from "@capacitor/geolocation"
20
+ * const types = { Geolocation: createGeolocation({ plugin: Geolocation }) }
21
+ * api.notify("#geolocation:geolocationRequest", { enableHighAccuracy: true })
22
+ */
23
+ export function createGeolocation({ plugin } = {}) {
24
+ const source = () =>
25
+ plugin && isNative()
26
+ ? fromPlugin(plugin)
27
+ : globalThis.navigator?.geolocation
28
+
29
+ return {
30
+ create(entity) {
31
+ entity.error ??= null
32
+ entity.isLoading ??= false
33
+ entity.isSupported = Boolean(source())
34
+ entity.isWatching ??= false
35
+ entity.position ??= null
36
+ },
37
+
38
+ destroy(entity) {
39
+ unwatch(entity)
40
+ },
41
+
42
+ geolocationRequest(entity, options = {}, api) {
43
+ const geolocation = start(entity, api)
44
+ geolocation?.getCurrentPosition(...answers(entity.id, api), options)
45
+ },
46
+
47
+ geolocationWatch(entity, options = {}, api) {
48
+ if (watches.has(entity.id)) return
49
+ const geolocation = start(entity, api)
50
+ if (!geolocation) return
51
+
52
+ entity.isWatching = true
53
+ watches.set(entity.id, {
54
+ geolocation,
55
+ watch: geolocation.watchPosition(...answers(entity.id, api), options),
56
+ })
57
+ },
58
+
59
+ geolocationUnwatch: unwatch,
60
+
61
+ geolocationSuccess(entity, position) {
62
+ entity.error = null
63
+ entity.isLoading = false
64
+ entity.position = {
65
+ coords: {
66
+ accuracy: position.coords.accuracy,
67
+ altitude: position.coords.altitude,
68
+ altitudeAccuracy: position.coords.altitudeAccuracy,
69
+ heading: position.coords.heading,
70
+ latitude: position.coords.latitude,
71
+ longitude: position.coords.longitude,
72
+ speed: position.coords.speed,
73
+ },
74
+ timestamp: position.timestamp,
75
+ }
76
+ },
77
+
78
+ geolocationError(entity, error) {
79
+ entity.error = { code: error.code, message: error.message }
80
+ entity.isLoading = false
81
+ },
82
+ }
83
+
84
+ function start(entity, api) {
85
+ const geolocation = source()
86
+ entity.isSupported = Boolean(geolocation)
87
+ entity.error = null
88
+ entity.isLoading = Boolean(geolocation)
89
+ if (!geolocation) api.notify(`#${entity.id}:geolocationError`, UNSUPPORTED)
90
+ return geolocation
91
+ }
92
+ }
93
+
94
+ function unwatch(entity) {
95
+ const active = watches.get(entity.id)
96
+ active?.geolocation.clearWatch(active.watch)
97
+ watches.delete(entity.id)
98
+ entity.isLoading = false
99
+ entity.isWatching = false
100
+ }
101
+
102
+ function answers(id, api) {
103
+ return [
104
+ (position) => api.notify(`#${id}:geolocationSuccess`, position),
105
+ (error) => api.notify(`#${id}:geolocationError`, error),
106
+ ]
107
+ }
108
+
109
+ function fromPlugin(plugin) {
110
+ return {
111
+ getCurrentPosition: (onSuccess, onError, options) =>
112
+ plugin.getCurrentPosition(options).then(onSuccess, onError),
113
+ watchPosition: (onSuccess, onError, options) =>
114
+ plugin.watchPosition(options, (position, error) =>
115
+ position ? onSuccess(position) : onError(error),
116
+ ),
117
+ clearWatch: (watch) =>
118
+ Promise.resolve(watch).then((id) => plugin.clearWatch({ id })),
119
+ }
120
+ }
@@ -0,0 +1,133 @@
1
+ import { isNative } from "../../native/index.js"
2
+
3
+ /**
4
+ * The type behind reminders the device shows on its own, such as "your job
5
+ * starts in an hour". In a native app they go through `LocalNotifications`
6
+ * from `@capacitor/local-notifications`, given as `plugin`, and show even with
7
+ * the app closed. In a browser they show only while the page is open, through
8
+ * the Notification API.
9
+ *
10
+ * `permission` is `"granted"`, `"denied"`, `"prompt"` or `"unsupported"`.
11
+ * `localNotificationsAsk` brings up the system's dialog: send it from a tap,
12
+ * which a browser requires. `localNotificationSchedule({ id, title, body, at,
13
+ * url })` schedules one, `id` being a whole number to cancel it by with
14
+ * `localNotificationCancel(id)`. A tap on one with a `url` navigates there,
15
+ * through `onTap(url, api)`, by default `#router:navigate`.
16
+ *
17
+ * @param {{ plugin?: object, onTap?: (url: string, api: object) => void }} [config]
18
+ *
19
+ * @example
20
+ * import { LocalNotifications } from "@capacitor/local-notifications"
21
+ * const types = {
22
+ * Reminders: createLocalNotifications({ plugin: LocalNotifications }),
23
+ * }
24
+ * api.notify("#reminders:localNotificationSchedule", {
25
+ * id: 1,
26
+ * title: "Wedding in an hour",
27
+ * at: new Date(start - HOUR),
28
+ * url: "/jobs/1",
29
+ * })
30
+ */
31
+ export function createLocalNotifications({
32
+ plugin,
33
+ onTap = (url, api) => api.notify("#router:navigate", url),
34
+ } = {}) {
35
+ const device = plugin && isNative() ? fromPlugin(plugin) : fromBrowser()
36
+
37
+ return {
38
+ create(entity, _, api) {
39
+ const { id } = entity
40
+ entity.permission ??= null
41
+ device.onTap((url) => api.notify(`#${id}:localNotificationTap`, url))
42
+ device
43
+ .permission()
44
+ .then((permission) =>
45
+ api.notify(`#${id}:localNotificationsPermission`, permission),
46
+ )
47
+ },
48
+
49
+ localNotificationsAsk(entity, _, api) {
50
+ const { id } = entity
51
+ device
52
+ .request()
53
+ .then((permission) =>
54
+ api.notify(`#${id}:localNotificationsPermission`, permission),
55
+ )
56
+ },
57
+
58
+ localNotificationsPermission(entity, permission) {
59
+ entity.permission = permission
60
+ },
61
+
62
+ localNotificationSchedule(entity, notification) {
63
+ device.schedule(notification)
64
+ },
65
+
66
+ localNotificationCancel(entity, notificationId) {
67
+ device.cancel(notificationId)
68
+ },
69
+
70
+ localNotificationTap(entity, url, api) {
71
+ if (url) onTap(url, api)
72
+ },
73
+ }
74
+ }
75
+
76
+ function fromPlugin(plugin) {
77
+ return {
78
+ permission: () => plugin.checkPermissions().then(toPermission),
79
+ request: () => plugin.requestPermissions().then(toPermission),
80
+ schedule: ({ id, title, body, at, url }) =>
81
+ plugin.schedule({
82
+ notifications: [{ id, title, body, schedule: { at }, extra: { url } }],
83
+ }),
84
+ cancel: (id) => plugin.cancel({ notifications: [{ id }] }),
85
+ onTap: (listener) =>
86
+ plugin.addListener(
87
+ "localNotificationActionPerformed",
88
+ ({ notification }) => listener(notification.extra?.url),
89
+ ),
90
+ }
91
+ }
92
+
93
+ function fromBrowser() {
94
+ const Notification = globalThis.Notification
95
+ const timers = new Map()
96
+ let tapListener = () => {}
97
+
98
+ return {
99
+ permission: async () =>
100
+ Notification ? toPermission(Notification.permission) : "unsupported",
101
+ request: async () =>
102
+ Notification
103
+ ? toPermission(await Notification.requestPermission())
104
+ : "unsupported",
105
+ schedule: ({ id, title, body, at, url }) => {
106
+ if (!Notification) return
107
+ clearTimeout(timers.get(id))
108
+ const delay = new Date(at).getTime() - Date.now()
109
+ const show = () => {
110
+ timers.delete(id)
111
+ const notification = new Notification(title, { body })
112
+ notification.onclick = () => {
113
+ globalThis.focus?.()
114
+ tapListener(url)
115
+ }
116
+ }
117
+ timers.set(id, setTimeout(show, delay))
118
+ },
119
+ cancel: (id) => {
120
+ clearTimeout(timers.get(id))
121
+ timers.delete(id)
122
+ },
123
+ onTap: (listener) => {
124
+ tapListener = listener
125
+ },
126
+ }
127
+ }
128
+
129
+ function toPermission(result) {
130
+ const value = typeof result === "string" ? result : result.display
131
+ if (value === "granted" || value === "denied") return value
132
+ return "prompt"
133
+ }
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @typedef {import("../../../types/sensors/media-query.js").MediaQueryEntity} MediaQueryEntity
3
- * @typedef {import("../../../types/sensors/media-query.js").MediaQueryMatchEvent} MediaQueryMatchEvent
2
+ * @typedef {import("../../../types/device/media-query.js").MediaQueryEntity} MediaQueryEntity
3
+ * @typedef {import("../../../types/device/media-query.js").MediaQueryMatchEvent} MediaQueryMatchEvent
4
4
  */
5
5
 
6
6
  const listeners = new Map()
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @typedef {import("../../../types/sensors/network-status.js").NetworkStatusEntity} NetworkStatusEntity
2
+ * @typedef {import("../../../types/device/network-status.js").NetworkStatusEntity} NetworkStatusEntity
3
3
  */
4
4
 
5
5
  const ONLINE_EVENT = "online"
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @typedef {import("../../../types/sensors/page-visibility.js").PageVisibilityEntity} PageVisibilityEntity
2
+ * @typedef {import("../../../types/device/page-visibility.js").PageVisibilityEntity} PageVisibilityEntity
3
3
  */
4
4
 
5
5
  const VISIBILITY_EVENT = "visibilitychange"
@@ -1,6 +1,6 @@
1
1
  import { handleRequest } from "@inglorious/store/async"
2
2
 
3
- import { isNative } from "../index.js"
3
+ import { isNative } from "../../native/index.js"
4
4
 
5
5
  const UNSUPPORTED = "unsupported"
6
6
  const FAILED = "failed"