@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.
- package/README.md +257 -200
- package/package.json +49 -37
- package/src/device/biometrics/index.js +86 -0
- package/src/device/compass/handlers.js +163 -0
- package/src/{sensors → device}/element-size/handlers.js +2 -2
- package/src/device/geolocation/index.js +120 -0
- package/src/device/local-notifications/index.js +133 -0
- package/src/{sensors → device}/media-query/handlers.js +2 -2
- package/src/{sensors → device}/network-status/handlers.js +1 -1
- package/src/{sensors → device}/page-visibility/handlers.js +1 -1
- package/src/{native → device}/share/index.js +1 -1
- package/src/device/storage/index.js +61 -0
- package/src/native/index.js +0 -32
- package/types/device/biometrics.d.ts +51 -0
- package/types/{sensors → device}/compass.d.ts +0 -2
- package/types/{sensors → device}/geolocation.d.ts +25 -7
- package/types/device/local-notifications.d.ts +76 -0
- package/types/device/storage.d.ts +30 -0
- package/types/native/index.d.ts +0 -19
- package/src/sensors/compass/handlers.js +0 -209
- package/src/sensors/geolocation/handlers.js +0 -168
- package/src/sensors/geolocation/index.js +0 -3
- /package/src/{sensors → device}/compass/index.js +0 -0
- /package/src/{sensors → device}/element-size/index.js +0 -0
- /package/src/{native → device}/haptics/index.js +0 -0
- /package/src/{keyboard → device/keyboard}/index.js +0 -0
- /package/src/{sensors → device}/media-query/index.js +0 -0
- /package/src/{sensors → device}/network-status/index.js +0 -0
- /package/src/{sensors → device}/page-visibility/index.js +0 -0
- /package/types/{sensors → device}/element-size.d.ts +0 -0
- /package/types/{native → device}/haptics.d.ts +0 -0
- /package/types/{keyboard.d.ts → device/keyboard.d.ts} +0 -0
- /package/types/{sensors → device}/media-query.d.ts +0 -0
- /package/types/{sensors → device}/network-status.d.ts +0 -0
- /package/types/{sensors → device}/page-visibility.d.ts +0 -0
- /package/types/{native → device}/share.d.ts +0 -0
|
@@ -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
|
-
}
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|