@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
@@ -1,209 +0,0 @@
1
- /**
2
- * @typedef {import("../../../types/sensors/compass.js").CompassEntity} CompassEntity
3
- * @typedef {import("../../../types/sensors/compass.js").CompassError} CompassError
4
- */
5
-
6
- const COMPASS_TIMEOUT = 3000
7
- const NO_TIMEOUT = null
8
-
9
- const FULL_CIRCLE = 360
10
- const DEFAULT_ORIENTATION = 0
11
- const DEFAULT_ERROR_CODE = 0
12
-
13
- export function create(entity) {
14
- entity.error ??= null
15
- entity.heading ??= null
16
- entity.isActive ??= false
17
- entity.isPermissionGranted ??= false
18
- entity.isLoading ??= false
19
- entity.isSupported = isCompassSupported()
20
- entity.manualOffset ??= 0
21
- entity._absoluteListener ??= null
22
- entity._cancelTimeout ??= null
23
- entity._orientationListener ??= null
24
- }
25
-
26
- export function destroy(entity) {
27
- compassUnwatch(entity)
28
- }
29
-
30
- export function compassUnwatch(entity) {
31
- const win = getWindow()
32
-
33
- if (entity._orientationListener && win) {
34
- win.removeEventListener("deviceorientation", entity._orientationListener)
35
- }
36
-
37
- if (entity._absoluteListener && win) {
38
- win.removeEventListener(
39
- "deviceorientationabsolute",
40
- entity._absoluteListener,
41
- )
42
- }
43
-
44
- if (entity._cancelTimeout) {
45
- entity._cancelTimeout()
46
- }
47
-
48
- entity.isLoading = false
49
- entity.isActive = false
50
- entity._orientationListener = null
51
- entity._absoluteListener = null
52
- entity._cancelTimeout = null
53
- }
54
-
55
- export function compassError(entity, error) {
56
- entity.error = normalizeError(error)
57
- entity.isLoading = false
58
- entity.isPermissionGranted = false
59
- }
60
-
61
- export async function compassPermissionsRequest(entity, _, api) {
62
- entity.isSupported = isCompassSupported()
63
- entity.error = null
64
-
65
- if (!entity.isSupported) {
66
- entity.isLoading = false
67
- api.notify("compassError", createUnsupportedError())
68
- return
69
- }
70
-
71
- entity.isLoading = true
72
-
73
- if (
74
- typeof DeviceOrientationEvent !== "undefined" &&
75
- typeof DeviceOrientationEvent.requestPermission === "function"
76
- ) {
77
- try {
78
- const permission = await DeviceOrientationEvent.requestPermission()
79
- if (permission === "granted") {
80
- api.notify("compassPermissionsGrant")
81
- } else {
82
- entity.isLoading = false
83
- api.notify("compassError", createPermissionDeniedError())
84
- }
85
- } catch (error) {
86
- entity.isLoading = false
87
- api.notify("compassError", normalizeError(error))
88
- }
89
- } else {
90
- api.notify("compassPermissionsGrant")
91
- }
92
- }
93
-
94
- export function compassPermissionsGrant(entity) {
95
- entity.isLoading = false
96
- entity.isPermissionGranted = true
97
- }
98
-
99
- export function compassWatch(entity, _, api) {
100
- // Snapshot values from the entity while the proxy is still live.
101
- // Closures must not access `entity` after this handler returns, as
102
- // Mutative revokes the draft proxy at that point.
103
- const manualOffset = entity.manualOffset
104
-
105
- let isUsingAbsolute = false
106
- let timeoutId = NO_TIMEOUT
107
-
108
- const cancelTimeout = () => {
109
- if (timeoutId !== NO_TIMEOUT) {
110
- clearTimeout(timeoutId)
111
- timeoutId = NO_TIMEOUT
112
- }
113
- }
114
-
115
- const orientationListener = createOrientationChangeListener(
116
- cancelTimeout,
117
- manualOffset,
118
- api,
119
- )
120
-
121
- const absoluteListener = (event) => {
122
- if (!isUsingAbsolute) {
123
- isUsingAbsolute = true
124
- getWindow()?.removeEventListener("deviceorientation", orientationListener)
125
- }
126
-
127
- orientationListener(event)
128
- }
129
-
130
- entity._orientationListener = orientationListener
131
- entity._absoluteListener = absoluteListener
132
- entity._cancelTimeout = cancelTimeout
133
-
134
- const win = getWindow()
135
- win?.addEventListener("deviceorientationabsolute", absoluteListener)
136
- win?.addEventListener("deviceorientation", orientationListener)
137
-
138
- timeoutId = globalThis.setTimeout(() => {
139
- timeoutId = NO_TIMEOUT
140
- api.notify("compassActiveChange", false)
141
- }, COMPASS_TIMEOUT)
142
- }
143
-
144
- export function compassActiveChange(entity, value) {
145
- entity.isActive = value
146
- }
147
-
148
- export function compassHeadingChange(entity, value) {
149
- entity.isLoading = false
150
- entity.heading = value
151
- }
152
-
153
- function createOrientationChangeListener(cancelTimeout, manualOffset, api) {
154
- return (event) => {
155
- const heading = event?.alpha
156
- if (typeof heading !== "number") {
157
- return
158
- }
159
-
160
- cancelTimeout()
161
-
162
- const screenAngle = getScreenAngle()
163
- const adjustedHeading =
164
- (((heading - screenAngle + manualOffset) % FULL_CIRCLE) + FULL_CIRCLE) %
165
- FULL_CIRCLE
166
-
167
- api.notify("compassActiveChange", true)
168
- api.notify("compassHeadingChange", Math.round(adjustedHeading))
169
- }
170
- }
171
-
172
- function getWindow() {
173
- return typeof window !== "undefined" ? window : null
174
- }
175
-
176
- function getScreenAngle() {
177
- const win = getWindow()
178
- return (
179
- win?.screen?.orientation?.angle ?? win?.orientation ?? DEFAULT_ORIENTATION
180
- )
181
- }
182
-
183
- function isCompassSupported() {
184
- return (
185
- typeof DeviceOrientationEvent !== "undefined" &&
186
- Boolean(getWindow()?.addEventListener)
187
- )
188
- }
189
-
190
- function createUnsupportedError() {
191
- return {
192
- code: 0,
193
- message: "Compass is not supported by this environment.",
194
- }
195
- }
196
-
197
- function createPermissionDeniedError() {
198
- return {
199
- code: 1,
200
- message: "Compass permission denied.",
201
- }
202
- }
203
-
204
- function normalizeError(error) {
205
- return {
206
- code: error?.code ?? DEFAULT_ERROR_CODE,
207
- message: error?.message ?? String(error),
208
- }
209
- }
@@ -1,168 +0,0 @@
1
- /**
2
- * @typedef {import("../../../types/sensors/geolocation.js").GeolocationEntity} GeolocationEntity
3
- * @typedef {import("../../../types/sensors/geolocation.js").GeolocationOptions} GeolocationOptions
4
- * @typedef {import("../../../types/sensors/geolocation.js").GeolocationPosition} GeolocationPosition
5
- */
6
-
7
- const NO_WATCH_ID = null
8
-
9
- /**
10
- * Initializes the geolocation entity with default state.
11
- * @param {GeolocationEntity} entity - The geolocation entity.
12
- */
13
- export function create(entity) {
14
- entity.error ??= null
15
- entity.isLoading ??= false
16
- entity.isSupported = Boolean(getGeolocation())
17
- entity.isWatching ??= false
18
- entity.position ??= null
19
- entity.watchId ??= NO_WATCH_ID
20
- }
21
-
22
- /**
23
- * Clears the geolocation watch before the entity is destroyed.
24
- * @param {GeolocationEntity} entity - The geolocation entity.
25
- */
26
- export function destroy(entity) {
27
- geolocationUnwatch(entity)
28
- }
29
-
30
- /**
31
- * Stores a normalized geolocation error.
32
- * @param {GeolocationEntity} entity - The geolocation entity.
33
- * @param {GeolocationPositionError} error - The geolocation error.
34
- */
35
- export function geolocationError(entity, error) {
36
- entity.error = normalizeError(error)
37
- entity.isLoading = false
38
- }
39
-
40
- /**
41
- * Requests the current geolocation position.
42
- * @param {GeolocationEntity} entity - The geolocation entity.
43
- * @param {GeolocationOptions} options - Position options.
44
- * @param {{ notify: Function }} api - The store API.
45
- */
46
- export function geolocationRequest(entity, options = {}, api) {
47
- const geolocation = getGeolocation()
48
-
49
- entity.isSupported = Boolean(geolocation)
50
- entity.error = null
51
-
52
- if (!geolocation) {
53
- entity.isLoading = false
54
- api.notify("geolocationError", createUnsupportedError())
55
- return
56
- }
57
-
58
- entity.isLoading = true
59
-
60
- geolocation.getCurrentPosition(
61
- (position) => {
62
- api.notify("geolocationSuccess", normalizePosition(position))
63
- },
64
- (error) => {
65
- api.notify("geolocationError", error)
66
- },
67
- options,
68
- )
69
- }
70
-
71
- /**
72
- * Stores a normalized geolocation position.
73
- * @param {GeolocationEntity} entity - The geolocation entity.
74
- * @param {GeolocationPosition} position - The geolocation position.
75
- */
76
- export function geolocationSuccess(entity, position) {
77
- entity.error = null
78
- entity.isLoading = false
79
- entity.position = position
80
- }
81
-
82
- /**
83
- * Stops an active geolocation watch.
84
- * @param {GeolocationEntity} entity - The geolocation entity.
85
- */
86
- export function geolocationUnwatch(entity) {
87
- const geolocation = getGeolocation()
88
-
89
- if (entity.watchId !== NO_WATCH_ID && geolocation) {
90
- geolocation.clearWatch(entity.watchId)
91
- }
92
-
93
- entity.isLoading = false
94
- entity.isWatching = false
95
- entity.watchId = NO_WATCH_ID
96
- }
97
-
98
- /**
99
- * Starts watching geolocation changes.
100
- * @param {GeolocationEntity} entity - The geolocation entity.
101
- * @param {GeolocationOptions} options - Watch options.
102
- * @param {{ notify: Function }} api - The store API.
103
- */
104
- export function geolocationWatch(entity, options = {}, api) {
105
- const geolocation = getGeolocation()
106
-
107
- entity.isSupported = Boolean(geolocation)
108
- entity.error = null
109
-
110
- if (!geolocation) {
111
- entity.isLoading = false
112
- api.notify("geolocationError", createUnsupportedError())
113
- return
114
- }
115
-
116
- if (entity.watchId !== NO_WATCH_ID) {
117
- return
118
- }
119
-
120
- entity.isLoading = true
121
- entity.isWatching = true
122
- entity.watchId = geolocation.watchPosition(
123
- (position) => {
124
- api.notify("geolocationSuccess", normalizePosition(position))
125
- },
126
- (error) => {
127
- api.notify("geolocationError", error)
128
- },
129
- options,
130
- )
131
- }
132
-
133
- function createUnsupportedError() {
134
- return {
135
- code: 0,
136
- message: "Geolocation is not supported by this environment.",
137
- }
138
- }
139
-
140
- function getGeolocation() {
141
- return globalThis.navigator?.geolocation
142
- }
143
-
144
- function normalizeCoords(coords) {
145
- return {
146
- accuracy: coords.accuracy,
147
- altitude: coords.altitude,
148
- altitudeAccuracy: coords.altitudeAccuracy,
149
- heading: coords.heading,
150
- latitude: coords.latitude,
151
- longitude: coords.longitude,
152
- speed: coords.speed,
153
- }
154
- }
155
-
156
- function normalizeError(error) {
157
- return {
158
- code: error.code,
159
- message: error.message,
160
- }
161
- }
162
-
163
- function normalizePosition(position) {
164
- return {
165
- coords: normalizeCoords(position.coords),
166
- timestamp: position.timestamp,
167
- }
168
- }
@@ -1,3 +0,0 @@
1
- import * as handlers from "./handlers.js"
2
-
3
- export const Geolocation = { ...handlers }
@@ -1,8 +0,0 @@
1
- /**
2
- * Sets `--iw-keyboard-height` on `<html>` to the height the on-screen keyboard
3
- * covers, and the `iw-keyboard-open` class while it is up, so what sits at the
4
- * bottom of the screen can move above it or step aside. Where the page shrinks
5
- * for the keyboard, the class is set and the height stays 0.
6
- * @returns A function that stops following.
7
- */
8
- export declare function watchKeyboard(): () => void
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes