@aippy/runtime 0.2.3 → 0.2.4-dev.3
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/dist/audio/index.d.ts +2 -1
- package/dist/audio/index.js +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +24 -20
- package/dist/core/runtime.d.ts +71 -0
- package/dist/device/index.js +316 -183
- package/dist/device/sensors.d.ts +39 -3
- package/dist/device/types.d.ts +38 -0
- package/dist/index/index.js +50 -40
- package/dist/runtime-DOnodF_1.js +165 -0
- package/dist/{useAudioContext-BKgy28A1.js → useAudioContext-CNQQSTab.js} +2 -2
- package/package.json +25 -26
- package/dist/errors-CDEBaBxB.js +0 -26
package/dist/device/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { c as a } from "../
|
|
5
|
-
class
|
|
1
|
+
var v = Object.defineProperty;
|
|
2
|
+
var f = (c, t, e) => t in c ? v(c, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[t] = e;
|
|
3
|
+
var p = (c, t, e) => f(c, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { c as a, b as E } from "../runtime-DOnodF_1.js";
|
|
5
|
+
class P {
|
|
6
6
|
constructor() {
|
|
7
|
-
|
|
7
|
+
p(this, "stream", null);
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Check if camera is supported
|
|
@@ -15,21 +15,21 @@ class g {
|
|
|
15
15
|
/**
|
|
16
16
|
* Get camera stream
|
|
17
17
|
*/
|
|
18
|
-
async getStream(
|
|
18
|
+
async getStream(t = {}) {
|
|
19
19
|
if (!this.isSupported())
|
|
20
20
|
throw a("Camera API is not supported", "NOT_SUPPORTED");
|
|
21
21
|
try {
|
|
22
|
-
const
|
|
22
|
+
const e = {
|
|
23
23
|
video: {
|
|
24
|
-
width:
|
|
25
|
-
height:
|
|
26
|
-
facingMode:
|
|
24
|
+
width: t.width,
|
|
25
|
+
height: t.height,
|
|
26
|
+
facingMode: t.facingMode || "environment"
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
-
return this.stream = await navigator.mediaDevices.getUserMedia(
|
|
30
|
-
} catch (
|
|
29
|
+
return this.stream = await navigator.mediaDevices.getUserMedia(e), this.stream;
|
|
30
|
+
} catch (e) {
|
|
31
31
|
throw a(
|
|
32
|
-
`Failed to access camera: ${
|
|
32
|
+
`Failed to access camera: ${e instanceof Error ? e.message : "Unknown error"}`,
|
|
33
33
|
"PERMISSION_DENIED"
|
|
34
34
|
);
|
|
35
35
|
}
|
|
@@ -37,30 +37,30 @@ class g {
|
|
|
37
37
|
/**
|
|
38
38
|
* Capture photo from stream
|
|
39
39
|
*/
|
|
40
|
-
async capturePhoto(
|
|
40
|
+
async capturePhoto(t = {}) {
|
|
41
41
|
if (!this.stream)
|
|
42
42
|
throw a("No camera stream available", "NOT_SUPPORTED");
|
|
43
43
|
try {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
44
|
+
const e = document.createElement("video");
|
|
45
|
+
e.srcObject = this.stream, e.play();
|
|
46
|
+
const i = document.createElement("canvas"), o = i.getContext("2d");
|
|
47
|
+
if (!o)
|
|
48
48
|
throw a("Failed to get canvas context", "UNKNOWN_ERROR");
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}, `image/${
|
|
54
|
-
}),
|
|
49
|
+
i.width = t.width || e.videoWidth, i.height = t.height || e.videoHeight, o.drawImage(e, 0, 0, i.width, i.height);
|
|
50
|
+
const n = t.format || "jpeg", d = t.quality === "high" ? 0.9 : t.quality === "medium" ? 0.7 : 0.5, r = await new Promise((l, u) => {
|
|
51
|
+
i.toBlob((w) => {
|
|
52
|
+
w ? l(w) : u(new Error("Failed to create blob"));
|
|
53
|
+
}, `image/${n}`, d);
|
|
54
|
+
}), s = i.toDataURL(`image/${n}`, d);
|
|
55
55
|
return {
|
|
56
|
-
blob:
|
|
57
|
-
dataUrl:
|
|
58
|
-
width:
|
|
59
|
-
height:
|
|
56
|
+
blob: r,
|
|
57
|
+
dataUrl: s,
|
|
58
|
+
width: i.width,
|
|
59
|
+
height: i.height
|
|
60
60
|
};
|
|
61
|
-
} catch (
|
|
61
|
+
} catch (e) {
|
|
62
62
|
throw a(
|
|
63
|
-
`Failed to capture photo: ${
|
|
63
|
+
`Failed to capture photo: ${e instanceof Error ? e.message : "Unknown error"}`,
|
|
64
64
|
"UNKNOWN_ERROR"
|
|
65
65
|
);
|
|
66
66
|
}
|
|
@@ -69,11 +69,11 @@ class g {
|
|
|
69
69
|
* Stop camera stream
|
|
70
70
|
*/
|
|
71
71
|
stopStream() {
|
|
72
|
-
this.stream && (this.stream.getTracks().forEach((
|
|
72
|
+
this.stream && (this.stream.getTracks().forEach((t) => t.stop()), this.stream = null);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
const
|
|
76
|
-
class
|
|
75
|
+
const D = new P();
|
|
76
|
+
class O {
|
|
77
77
|
/**
|
|
78
78
|
* Check if geolocation is supported
|
|
79
79
|
*/
|
|
@@ -83,99 +83,230 @@ class v {
|
|
|
83
83
|
/**
|
|
84
84
|
* Get current position
|
|
85
85
|
*/
|
|
86
|
-
async getCurrentPosition(
|
|
86
|
+
async getCurrentPosition(t = {}) {
|
|
87
87
|
if (!this.isSupported())
|
|
88
88
|
throw a("Geolocation API is not supported", "NOT_SUPPORTED");
|
|
89
|
-
return new Promise((
|
|
90
|
-
const
|
|
91
|
-
enableHighAccuracy:
|
|
92
|
-
timeout:
|
|
93
|
-
maximumAge:
|
|
89
|
+
return new Promise((e, i) => {
|
|
90
|
+
const o = {
|
|
91
|
+
enableHighAccuracy: t.enableHighAccuracy ?? !0,
|
|
92
|
+
timeout: t.timeout ?? 1e4,
|
|
93
|
+
maximumAge: t.maximumAge ?? 6e4
|
|
94
94
|
};
|
|
95
95
|
navigator.geolocation.getCurrentPosition(
|
|
96
|
-
(
|
|
97
|
-
const
|
|
98
|
-
latitude:
|
|
99
|
-
longitude:
|
|
100
|
-
accuracy:
|
|
101
|
-
altitude:
|
|
102
|
-
altitudeAccuracy:
|
|
103
|
-
heading:
|
|
104
|
-
speed:
|
|
105
|
-
timestamp:
|
|
96
|
+
(n) => {
|
|
97
|
+
const d = {
|
|
98
|
+
latitude: n.coords.latitude,
|
|
99
|
+
longitude: n.coords.longitude,
|
|
100
|
+
accuracy: n.coords.accuracy,
|
|
101
|
+
altitude: n.coords.altitude ?? void 0,
|
|
102
|
+
altitudeAccuracy: n.coords.altitudeAccuracy ?? void 0,
|
|
103
|
+
heading: n.coords.heading ?? void 0,
|
|
104
|
+
speed: n.coords.speed ?? void 0,
|
|
105
|
+
timestamp: n.timestamp
|
|
106
106
|
};
|
|
107
|
-
|
|
107
|
+
e(d);
|
|
108
108
|
},
|
|
109
|
-
(
|
|
110
|
-
let
|
|
111
|
-
switch (
|
|
112
|
-
case
|
|
113
|
-
|
|
109
|
+
(n) => {
|
|
110
|
+
let d = "UNKNOWN_ERROR", r = "Unknown geolocation error";
|
|
111
|
+
switch (n.code) {
|
|
112
|
+
case n.PERMISSION_DENIED:
|
|
113
|
+
d = "PERMISSION_DENIED", r = "Geolocation permission denied";
|
|
114
114
|
break;
|
|
115
|
-
case
|
|
116
|
-
|
|
115
|
+
case n.POSITION_UNAVAILABLE:
|
|
116
|
+
r = "Position unavailable";
|
|
117
117
|
break;
|
|
118
|
-
case
|
|
119
|
-
|
|
118
|
+
case n.TIMEOUT:
|
|
119
|
+
r = "Geolocation timeout";
|
|
120
120
|
break;
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
i(a(r, d));
|
|
123
123
|
},
|
|
124
|
-
|
|
124
|
+
o
|
|
125
125
|
);
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
129
129
|
* Watch position changes
|
|
130
130
|
*/
|
|
131
|
-
watchPosition(
|
|
131
|
+
watchPosition(t, e = {}) {
|
|
132
132
|
if (!this.isSupported())
|
|
133
133
|
throw a("Geolocation API is not supported", "NOT_SUPPORTED");
|
|
134
|
-
const
|
|
135
|
-
enableHighAccuracy:
|
|
136
|
-
timeout:
|
|
137
|
-
maximumAge:
|
|
134
|
+
const i = {
|
|
135
|
+
enableHighAccuracy: e.enableHighAccuracy ?? !0,
|
|
136
|
+
timeout: e.timeout ?? 1e4,
|
|
137
|
+
maximumAge: e.maximumAge ?? 6e4
|
|
138
138
|
};
|
|
139
139
|
return navigator.geolocation.watchPosition(
|
|
140
|
-
(
|
|
141
|
-
const
|
|
142
|
-
latitude:
|
|
143
|
-
longitude:
|
|
144
|
-
accuracy:
|
|
145
|
-
altitude:
|
|
146
|
-
altitudeAccuracy:
|
|
147
|
-
heading:
|
|
148
|
-
speed:
|
|
149
|
-
timestamp:
|
|
140
|
+
(o) => {
|
|
141
|
+
const n = {
|
|
142
|
+
latitude: o.coords.latitude,
|
|
143
|
+
longitude: o.coords.longitude,
|
|
144
|
+
accuracy: o.coords.accuracy,
|
|
145
|
+
altitude: o.coords.altitude ?? void 0,
|
|
146
|
+
altitudeAccuracy: o.coords.altitudeAccuracy ?? void 0,
|
|
147
|
+
heading: o.coords.heading ?? void 0,
|
|
148
|
+
speed: o.coords.speed ?? void 0,
|
|
149
|
+
timestamp: o.timestamp
|
|
150
150
|
};
|
|
151
|
-
|
|
151
|
+
t(n);
|
|
152
152
|
},
|
|
153
|
-
(
|
|
154
|
-
console.error("Geolocation watch error:",
|
|
153
|
+
(o) => {
|
|
154
|
+
console.error("Geolocation watch error:", o);
|
|
155
155
|
},
|
|
156
|
-
|
|
156
|
+
i
|
|
157
157
|
);
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
160
160
|
* Clear position watch
|
|
161
161
|
*/
|
|
162
|
-
clearWatch(
|
|
163
|
-
navigator.geolocation.clearWatch(
|
|
162
|
+
clearWatch(t) {
|
|
163
|
+
navigator.geolocation.clearWatch(t);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
const
|
|
167
|
-
|
|
166
|
+
const A = new O();
|
|
167
|
+
function m() {
|
|
168
|
+
return "DeviceMotionEvent" in window;
|
|
169
|
+
}
|
|
170
|
+
function h() {
|
|
171
|
+
return "DeviceOrientationEvent" in window;
|
|
172
|
+
}
|
|
173
|
+
function g() {
|
|
174
|
+
return typeof window < "u" && !!window.webkit?.messageHandlers?.deviceMotionHandler;
|
|
175
|
+
}
|
|
176
|
+
async function y() {
|
|
177
|
+
if (g())
|
|
178
|
+
return !0;
|
|
179
|
+
if (!m())
|
|
180
|
+
return !1;
|
|
181
|
+
if (typeof DeviceMotionEvent < "u" && typeof DeviceMotionEvent.requestPermission == "function")
|
|
182
|
+
try {
|
|
183
|
+
return await DeviceMotionEvent.requestPermission() === "granted";
|
|
184
|
+
} catch {
|
|
185
|
+
return !1;
|
|
186
|
+
}
|
|
187
|
+
return !0;
|
|
188
|
+
}
|
|
189
|
+
function R(c) {
|
|
190
|
+
return E.addMotionListener((e) => {
|
|
191
|
+
const i = {
|
|
192
|
+
gravity: {
|
|
193
|
+
x: e.gravity?.x ?? 0,
|
|
194
|
+
y: e.gravity?.y ?? 0,
|
|
195
|
+
z: e.gravity?.z ?? 0
|
|
196
|
+
},
|
|
197
|
+
acceleration: {
|
|
198
|
+
x: e.acceleration?.x ?? 0,
|
|
199
|
+
y: e.acceleration?.y ?? 0,
|
|
200
|
+
z: e.acceleration?.z ?? 0
|
|
201
|
+
},
|
|
202
|
+
accelerationIncludingGravity: {
|
|
203
|
+
x: (e.gravity?.x ?? 0) + (e.acceleration?.x ?? 0),
|
|
204
|
+
y: (e.gravity?.y ?? 0) + (e.acceleration?.y ?? 0),
|
|
205
|
+
z: (e.gravity?.z ?? 0) + (e.acceleration?.z ?? 0)
|
|
206
|
+
},
|
|
207
|
+
rotation: {
|
|
208
|
+
alpha: e.rotation?.alpha ?? 0,
|
|
209
|
+
beta: e.rotation?.beta ?? 0,
|
|
210
|
+
gamma: e.rotation?.gamma ?? 0
|
|
211
|
+
},
|
|
212
|
+
timestamp: Date.now()
|
|
213
|
+
};
|
|
214
|
+
c(i);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function N(c, t = !0) {
|
|
218
|
+
if (!m())
|
|
219
|
+
throw a("Device motion API is not supported", "NOT_SUPPORTED");
|
|
220
|
+
let e = !1, i = null;
|
|
221
|
+
const o = (r) => {
|
|
222
|
+
if (!e) return;
|
|
223
|
+
const s = {
|
|
224
|
+
gravity: {
|
|
225
|
+
x: r.acceleration?.x ?? 0,
|
|
226
|
+
y: r.acceleration?.y ?? 0,
|
|
227
|
+
z: r.acceleration?.z ?? 0
|
|
228
|
+
},
|
|
229
|
+
acceleration: {
|
|
230
|
+
x: r.acceleration?.x ?? 0,
|
|
231
|
+
y: r.acceleration?.y ?? 0,
|
|
232
|
+
z: r.acceleration?.z ?? 0
|
|
233
|
+
},
|
|
234
|
+
accelerationIncludingGravity: {
|
|
235
|
+
x: r.accelerationIncludingGravity?.x ?? 0,
|
|
236
|
+
y: r.accelerationIncludingGravity?.y ?? 0,
|
|
237
|
+
z: r.accelerationIncludingGravity?.z ?? 0
|
|
238
|
+
},
|
|
239
|
+
rotation: {
|
|
240
|
+
alpha: r.rotationRate?.alpha ?? 0,
|
|
241
|
+
beta: r.rotationRate?.beta ?? 0,
|
|
242
|
+
gamma: r.rotationRate?.gamma ?? 0
|
|
243
|
+
},
|
|
244
|
+
timestamp: Date.now()
|
|
245
|
+
};
|
|
246
|
+
if (r.acceleration) {
|
|
247
|
+
const l = r.accelerationIncludingGravity, u = r.acceleration;
|
|
248
|
+
s.gravity = {
|
|
249
|
+
x: (l?.x ?? 0) - (u?.x ?? 0),
|
|
250
|
+
y: (l?.y ?? 0) - (u?.y ?? 0),
|
|
251
|
+
z: (l?.z ?? 0) - (u?.z ?? 0)
|
|
252
|
+
};
|
|
253
|
+
} else {
|
|
254
|
+
const l = r.accelerationIncludingGravity, u = 9.8;
|
|
255
|
+
s.gravity = {
|
|
256
|
+
x: (l?.x ?? 0) / u,
|
|
257
|
+
y: (l?.y ?? 0) / u,
|
|
258
|
+
z: (l?.z ?? 0) / u
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
c(s);
|
|
262
|
+
}, n = async () => {
|
|
263
|
+
t && !await y() || (e = !0, window.addEventListener("devicemotion", o));
|
|
264
|
+
};
|
|
265
|
+
return (async () => {
|
|
266
|
+
if (typeof DeviceMotionEvent < "u" && typeof DeviceMotionEvent.requestPermission == "function" && t) {
|
|
267
|
+
const s = async () => {
|
|
268
|
+
i = null, await n();
|
|
269
|
+
};
|
|
270
|
+
window.addEventListener("click", s, { once: !0 }), window.addEventListener("touchstart", s, { once: !0 }), i = () => {
|
|
271
|
+
window.removeEventListener("click", s), window.removeEventListener("touchstart", s);
|
|
272
|
+
};
|
|
273
|
+
} else
|
|
274
|
+
await n();
|
|
275
|
+
})(), () => {
|
|
276
|
+
e = !1, window.removeEventListener("devicemotion", o), i && (i(), i = null);
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function x(c, t = !0) {
|
|
280
|
+
return g() ? R(c) : N(c, t);
|
|
281
|
+
}
|
|
282
|
+
function L(c) {
|
|
283
|
+
if (!h())
|
|
284
|
+
throw a("Device orientation API is not supported", "NOT_SUPPORTED");
|
|
285
|
+
const t = (e) => {
|
|
286
|
+
const i = {
|
|
287
|
+
alpha: e.alpha ?? 0,
|
|
288
|
+
beta: e.beta ?? 0,
|
|
289
|
+
gamma: e.gamma ?? 0,
|
|
290
|
+
timestamp: Date.now()
|
|
291
|
+
};
|
|
292
|
+
c(i);
|
|
293
|
+
};
|
|
294
|
+
return window.addEventListener("deviceorientation", t), () => {
|
|
295
|
+
window.removeEventListener("deviceorientation", t);
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
class S {
|
|
168
299
|
/**
|
|
169
300
|
* Check if device orientation is supported
|
|
170
301
|
*/
|
|
171
302
|
isOrientationSupported() {
|
|
172
|
-
return
|
|
303
|
+
return h();
|
|
173
304
|
}
|
|
174
305
|
/**
|
|
175
306
|
* Check if device motion is supported
|
|
176
307
|
*/
|
|
177
308
|
isMotionSupported() {
|
|
178
|
-
return
|
|
309
|
+
return m();
|
|
179
310
|
}
|
|
180
311
|
/**
|
|
181
312
|
* Get device orientation data
|
|
@@ -183,36 +314,37 @@ class E {
|
|
|
183
314
|
async getOrientation() {
|
|
184
315
|
if (!this.isOrientationSupported())
|
|
185
316
|
throw a("Device orientation API is not supported", "NOT_SUPPORTED");
|
|
186
|
-
return new Promise((
|
|
187
|
-
const
|
|
188
|
-
window.removeEventListener("deviceorientation",
|
|
189
|
-
x:
|
|
190
|
-
y:
|
|
191
|
-
z:
|
|
317
|
+
return new Promise((t, e) => {
|
|
318
|
+
const i = (o) => {
|
|
319
|
+
window.removeEventListener("deviceorientation", i), t({
|
|
320
|
+
x: o.alpha ?? 0,
|
|
321
|
+
y: o.beta ?? 0,
|
|
322
|
+
z: o.gamma ?? 0,
|
|
192
323
|
timestamp: Date.now()
|
|
193
324
|
});
|
|
194
325
|
};
|
|
195
|
-
window.addEventListener("deviceorientation",
|
|
196
|
-
window.removeEventListener("deviceorientation",
|
|
326
|
+
window.addEventListener("deviceorientation", i), setTimeout(() => {
|
|
327
|
+
window.removeEventListener("deviceorientation", i), e(a("Device orientation timeout", "UNKNOWN_ERROR"));
|
|
197
328
|
}, 5e3);
|
|
198
329
|
});
|
|
199
330
|
}
|
|
200
331
|
/**
|
|
201
332
|
* Watch device orientation changes
|
|
333
|
+
* @deprecated Use watchOrientation() function instead
|
|
202
334
|
*/
|
|
203
|
-
watchOrientation(
|
|
335
|
+
watchOrientation(t) {
|
|
204
336
|
if (!this.isOrientationSupported())
|
|
205
337
|
throw a("Device orientation API is not supported", "NOT_SUPPORTED");
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
x:
|
|
209
|
-
y:
|
|
210
|
-
z:
|
|
338
|
+
const e = (i) => {
|
|
339
|
+
t({
|
|
340
|
+
x: i.alpha ?? 0,
|
|
341
|
+
y: i.beta ?? 0,
|
|
342
|
+
z: i.gamma ?? 0,
|
|
211
343
|
timestamp: Date.now()
|
|
212
344
|
});
|
|
213
345
|
};
|
|
214
|
-
return window.addEventListener("deviceorientation",
|
|
215
|
-
window.removeEventListener("deviceorientation",
|
|
346
|
+
return window.addEventListener("deviceorientation", e), () => {
|
|
347
|
+
window.removeEventListener("deviceorientation", e);
|
|
216
348
|
};
|
|
217
349
|
}
|
|
218
350
|
/**
|
|
@@ -221,53 +353,48 @@ class E {
|
|
|
221
353
|
async getMotion() {
|
|
222
354
|
if (!this.isMotionSupported())
|
|
223
355
|
throw a("Device motion API is not supported", "NOT_SUPPORTED");
|
|
224
|
-
return new Promise((
|
|
225
|
-
const
|
|
226
|
-
window.removeEventListener("devicemotion",
|
|
227
|
-
x:
|
|
228
|
-
y:
|
|
229
|
-
z:
|
|
356
|
+
return new Promise((t, e) => {
|
|
357
|
+
const i = (o) => {
|
|
358
|
+
window.removeEventListener("devicemotion", i), t({
|
|
359
|
+
x: o.acceleration?.x ?? 0,
|
|
360
|
+
y: o.acceleration?.y ?? 0,
|
|
361
|
+
z: o.acceleration?.z ?? 0,
|
|
230
362
|
timestamp: Date.now()
|
|
231
363
|
});
|
|
232
364
|
};
|
|
233
|
-
window.addEventListener("devicemotion",
|
|
234
|
-
window.removeEventListener("devicemotion",
|
|
365
|
+
window.addEventListener("devicemotion", i), setTimeout(() => {
|
|
366
|
+
window.removeEventListener("devicemotion", i), e(a("Device motion timeout", "UNKNOWN_ERROR"));
|
|
235
367
|
}, 5e3);
|
|
236
368
|
});
|
|
237
369
|
}
|
|
238
370
|
/**
|
|
239
371
|
* Watch device motion changes
|
|
372
|
+
* @deprecated Use watchMotion() function instead
|
|
240
373
|
*/
|
|
241
|
-
watchMotion(
|
|
374
|
+
watchMotion(t) {
|
|
242
375
|
if (!this.isMotionSupported())
|
|
243
376
|
throw a("Device motion API is not supported", "NOT_SUPPORTED");
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
x:
|
|
247
|
-
y:
|
|
248
|
-
z:
|
|
377
|
+
const e = (i) => {
|
|
378
|
+
t({
|
|
379
|
+
x: i.acceleration?.x ?? 0,
|
|
380
|
+
y: i.acceleration?.y ?? 0,
|
|
381
|
+
z: i.acceleration?.z ?? 0,
|
|
249
382
|
timestamp: Date.now()
|
|
250
383
|
});
|
|
251
384
|
};
|
|
252
|
-
return window.addEventListener("devicemotion",
|
|
253
|
-
window.removeEventListener("devicemotion",
|
|
385
|
+
return window.addEventListener("devicemotion", e), () => {
|
|
386
|
+
window.removeEventListener("devicemotion", e);
|
|
254
387
|
};
|
|
255
388
|
}
|
|
256
389
|
/**
|
|
257
390
|
* Request permission for motion sensors (iOS 13+)
|
|
258
391
|
*/
|
|
259
392
|
async requestPermission() {
|
|
260
|
-
|
|
261
|
-
return !1;
|
|
262
|
-
try {
|
|
263
|
-
return (await navigator.permissions?.query({ name: "accelerometer" }))?.state === "granted";
|
|
264
|
-
} catch {
|
|
265
|
-
return !1;
|
|
266
|
-
}
|
|
393
|
+
return y();
|
|
267
394
|
}
|
|
268
395
|
}
|
|
269
|
-
const
|
|
270
|
-
class
|
|
396
|
+
const M = new S();
|
|
397
|
+
class I {
|
|
271
398
|
/**
|
|
272
399
|
* Check if file system access is supported
|
|
273
400
|
*/
|
|
@@ -283,28 +410,28 @@ class O {
|
|
|
283
410
|
/**
|
|
284
411
|
* Open file picker (modern API)
|
|
285
412
|
*/
|
|
286
|
-
async openFilePicker(
|
|
413
|
+
async openFilePicker(t = {}) {
|
|
287
414
|
if (!this.isSupported())
|
|
288
415
|
throw a("File System Access API is not supported", "NOT_SUPPORTED");
|
|
289
416
|
try {
|
|
290
|
-
const
|
|
291
|
-
types:
|
|
417
|
+
const e = {
|
|
418
|
+
types: t.accept ? [{
|
|
292
419
|
description: "Files",
|
|
293
420
|
accept: Object.fromEntries(
|
|
294
|
-
|
|
421
|
+
t.accept.map((n) => [n, [n]])
|
|
295
422
|
)
|
|
296
423
|
}] : void 0,
|
|
297
|
-
multiple:
|
|
298
|
-
},
|
|
299
|
-
|
|
424
|
+
multiple: t.multiple ?? !1
|
|
425
|
+
}, i = await window.showOpenFilePicker(e), o = await Promise.all(
|
|
426
|
+
i.map(async (n) => n.getFile())
|
|
300
427
|
);
|
|
301
428
|
return {
|
|
302
|
-
files:
|
|
303
|
-
paths:
|
|
429
|
+
files: o,
|
|
430
|
+
paths: o.map((n) => n.name)
|
|
304
431
|
};
|
|
305
|
-
} catch (
|
|
306
|
-
throw
|
|
307
|
-
`Failed to open file picker: ${
|
|
432
|
+
} catch (e) {
|
|
433
|
+
throw e instanceof Error && e.name === "AbortError" ? a("File picker was cancelled", "PERMISSION_DENIED") : a(
|
|
434
|
+
`Failed to open file picker: ${e instanceof Error ? e.message : "Unknown error"}`,
|
|
308
435
|
"PERMISSION_DENIED"
|
|
309
436
|
);
|
|
310
437
|
}
|
|
@@ -312,38 +439,38 @@ class O {
|
|
|
312
439
|
/**
|
|
313
440
|
* Open file picker (legacy fallback)
|
|
314
441
|
*/
|
|
315
|
-
async openFilePickerLegacy(
|
|
442
|
+
async openFilePickerLegacy(t = {}) {
|
|
316
443
|
if (!this.isLegacySupported())
|
|
317
444
|
throw a("File input is not supported", "NOT_SUPPORTED");
|
|
318
|
-
return new Promise((
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
files:
|
|
324
|
-
paths:
|
|
445
|
+
return new Promise((e, i) => {
|
|
446
|
+
const o = document.createElement("input");
|
|
447
|
+
o.type = "file", o.multiple = t.multiple ?? !1, o.accept = t.accept?.join(",") ?? "", o.onchange = (n) => {
|
|
448
|
+
const d = n.target, r = Array.from(d.files || []);
|
|
449
|
+
e({
|
|
450
|
+
files: r,
|
|
451
|
+
paths: r.map((s) => s.name)
|
|
325
452
|
});
|
|
326
|
-
},
|
|
327
|
-
|
|
328
|
-
},
|
|
453
|
+
}, o.oncancel = () => {
|
|
454
|
+
i(a("File picker was cancelled", "PERMISSION_DENIED"));
|
|
455
|
+
}, o.click();
|
|
329
456
|
});
|
|
330
457
|
}
|
|
331
458
|
/**
|
|
332
459
|
* Open file picker with fallback
|
|
333
460
|
*/
|
|
334
|
-
async openFile(
|
|
335
|
-
return this.isSupported() ? await this.openFilePicker(
|
|
461
|
+
async openFile(t = {}) {
|
|
462
|
+
return this.isSupported() ? await this.openFilePicker(t) : await this.openFilePickerLegacy(t);
|
|
336
463
|
}
|
|
337
464
|
/**
|
|
338
465
|
* Save file
|
|
339
466
|
*/
|
|
340
|
-
async saveFile(
|
|
467
|
+
async saveFile(t, e) {
|
|
341
468
|
try {
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
} catch (
|
|
469
|
+
const i = URL.createObjectURL(t), o = document.createElement("a");
|
|
470
|
+
o.href = i, o.download = e, document.body.appendChild(o), o.click(), document.body.removeChild(o), URL.revokeObjectURL(i);
|
|
471
|
+
} catch (i) {
|
|
345
472
|
throw a(
|
|
346
|
-
`Failed to save file: ${
|
|
473
|
+
`Failed to save file: ${i instanceof Error ? i.message : "Unknown error"}`,
|
|
347
474
|
"UNKNOWN_ERROR"
|
|
348
475
|
);
|
|
349
476
|
}
|
|
@@ -351,45 +478,51 @@ class O {
|
|
|
351
478
|
/**
|
|
352
479
|
* Read file as text
|
|
353
480
|
*/
|
|
354
|
-
async readAsText(
|
|
355
|
-
return new Promise((
|
|
356
|
-
const
|
|
357
|
-
|
|
481
|
+
async readAsText(t) {
|
|
482
|
+
return new Promise((e, i) => {
|
|
483
|
+
const o = new FileReader();
|
|
484
|
+
o.onload = () => e(o.result), o.onerror = () => i(a("Failed to read file", "UNKNOWN_ERROR")), o.readAsText(t);
|
|
358
485
|
});
|
|
359
486
|
}
|
|
360
487
|
/**
|
|
361
488
|
* Read file as data URL
|
|
362
489
|
*/
|
|
363
|
-
async readAsDataURL(
|
|
364
|
-
return new Promise((
|
|
365
|
-
const
|
|
366
|
-
|
|
490
|
+
async readAsDataURL(t) {
|
|
491
|
+
return new Promise((e, i) => {
|
|
492
|
+
const o = new FileReader();
|
|
493
|
+
o.onload = () => e(o.result), o.onerror = () => i(a("Failed to read file", "UNKNOWN_ERROR")), o.readAsDataURL(t);
|
|
367
494
|
});
|
|
368
495
|
}
|
|
369
496
|
}
|
|
370
|
-
const
|
|
371
|
-
function
|
|
372
|
-
return new Promise((
|
|
497
|
+
const T = new I();
|
|
498
|
+
function k(c) {
|
|
499
|
+
return new Promise((t) => {
|
|
373
500
|
if ("vibrate" in navigator)
|
|
374
|
-
navigator.vibrate(
|
|
501
|
+
navigator.vibrate(c), t();
|
|
375
502
|
else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.aippyListener) {
|
|
376
|
-
const
|
|
503
|
+
const e = {
|
|
377
504
|
command: "navigator.vibrate",
|
|
378
|
-
parameters:
|
|
505
|
+
parameters: c
|
|
379
506
|
};
|
|
380
|
-
window.webkit.messageHandlers.aippyListener.postMessage(
|
|
507
|
+
window.webkit.messageHandlers.aippyListener.postMessage(e), t();
|
|
381
508
|
} else
|
|
382
|
-
console.warn("Vibration not supported in this environment"),
|
|
509
|
+
console.warn("Vibration not supported in this environment"), t();
|
|
383
510
|
});
|
|
384
511
|
}
|
|
385
512
|
export {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
513
|
+
P as CameraAPI,
|
|
514
|
+
I as FileSystemAPI,
|
|
515
|
+
O as GeolocationAPI,
|
|
516
|
+
S as SensorsAPI,
|
|
517
|
+
D as camera,
|
|
518
|
+
T as fileSystem,
|
|
519
|
+
A as geolocation,
|
|
520
|
+
g as hasNativeBridge,
|
|
521
|
+
m as isMotionSupported,
|
|
522
|
+
h as isOrientationSupported,
|
|
523
|
+
y as requestMotionPermission,
|
|
524
|
+
M as sensors,
|
|
525
|
+
k as vibrate,
|
|
526
|
+
x as watchMotion,
|
|
527
|
+
L as watchOrientation
|
|
395
528
|
};
|