@aippy/runtime 0.2.3 → 0.2.4-dev.2
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 +23 -18
- package/dist/core/runtime.d.ts +94 -0
- package/dist/device/index.js +284 -123
- package/dist/device/sensors.d.ts +39 -3
- package/dist/device/types.d.ts +38 -0
- package/dist/index/index.js +52 -41
- package/dist/runtime-DjBdOttl.js +243 -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
|
|
5
|
-
class
|
|
1
|
+
var U = Object.defineProperty;
|
|
2
|
+
var M = (n, e, t) => e in n ? U(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var A = (n, e, t) => M(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { c as s, b as L } from "../runtime-DjBdOttl.js";
|
|
5
|
+
class k {
|
|
6
6
|
constructor() {
|
|
7
|
-
|
|
7
|
+
A(this, "stream", null);
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Check if camera is supported
|
|
@@ -17,7 +17,7 @@ class g {
|
|
|
17
17
|
*/
|
|
18
18
|
async getStream(e = {}) {
|
|
19
19
|
if (!this.isSupported())
|
|
20
|
-
throw
|
|
20
|
+
throw s("Camera API is not supported", "NOT_SUPPORTED");
|
|
21
21
|
try {
|
|
22
22
|
const t = {
|
|
23
23
|
video: {
|
|
@@ -28,7 +28,7 @@ class g {
|
|
|
28
28
|
};
|
|
29
29
|
return this.stream = await navigator.mediaDevices.getUserMedia(t), this.stream;
|
|
30
30
|
} catch (t) {
|
|
31
|
-
throw
|
|
31
|
+
throw s(
|
|
32
32
|
`Failed to access camera: ${t instanceof Error ? t.message : "Unknown error"}`,
|
|
33
33
|
"PERMISSION_DENIED"
|
|
34
34
|
);
|
|
@@ -39,27 +39,27 @@ class g {
|
|
|
39
39
|
*/
|
|
40
40
|
async capturePhoto(e = {}) {
|
|
41
41
|
if (!this.stream)
|
|
42
|
-
throw
|
|
42
|
+
throw s("No camera stream available", "NOT_SUPPORTED");
|
|
43
43
|
try {
|
|
44
44
|
const t = document.createElement("video");
|
|
45
45
|
t.srcObject = this.stream, t.play();
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
48
|
-
throw
|
|
49
|
-
|
|
50
|
-
const r = e.format || "jpeg", c = e.quality === "high" ? 0.9 : e.quality === "medium" ? 0.7 : 0.5,
|
|
51
|
-
|
|
52
|
-
l ? u(l) :
|
|
46
|
+
const i = document.createElement("canvas"), o = i.getContext("2d");
|
|
47
|
+
if (!o)
|
|
48
|
+
throw s("Failed to get canvas context", "UNKNOWN_ERROR");
|
|
49
|
+
i.width = e.width || t.videoWidth, i.height = e.height || t.videoHeight, o.drawImage(t, 0, 0, i.width, i.height);
|
|
50
|
+
const r = e.format || "jpeg", c = e.quality === "high" ? 0.9 : e.quality === "medium" ? 0.7 : 0.5, a = await new Promise((u, m) => {
|
|
51
|
+
i.toBlob((l) => {
|
|
52
|
+
l ? u(l) : m(new Error("Failed to create blob"));
|
|
53
53
|
}, `image/${r}`, c);
|
|
54
|
-
}), d =
|
|
54
|
+
}), d = i.toDataURL(`image/${r}`, c);
|
|
55
55
|
return {
|
|
56
|
-
blob:
|
|
56
|
+
blob: a,
|
|
57
57
|
dataUrl: d,
|
|
58
|
-
width:
|
|
59
|
-
height:
|
|
58
|
+
width: i.width,
|
|
59
|
+
height: i.height
|
|
60
60
|
};
|
|
61
61
|
} catch (t) {
|
|
62
|
-
throw
|
|
62
|
+
throw s(
|
|
63
63
|
`Failed to capture photo: ${t instanceof Error ? t.message : "Unknown error"}`,
|
|
64
64
|
"UNKNOWN_ERROR"
|
|
65
65
|
);
|
|
@@ -72,8 +72,8 @@ class g {
|
|
|
72
72
|
this.stream && (this.stream.getTracks().forEach((e) => e.stop()), this.stream = null);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
const
|
|
76
|
-
class
|
|
75
|
+
const H = new k();
|
|
76
|
+
class T {
|
|
77
77
|
/**
|
|
78
78
|
* Check if geolocation is supported
|
|
79
79
|
*/
|
|
@@ -85,9 +85,9 @@ class v {
|
|
|
85
85
|
*/
|
|
86
86
|
async getCurrentPosition(e = {}) {
|
|
87
87
|
if (!this.isSupported())
|
|
88
|
-
throw
|
|
89
|
-
return new Promise((t,
|
|
90
|
-
const
|
|
88
|
+
throw s("Geolocation API is not supported", "NOT_SUPPORTED");
|
|
89
|
+
return new Promise((t, i) => {
|
|
90
|
+
const o = {
|
|
91
91
|
enableHighAccuracy: e.enableHighAccuracy ?? !0,
|
|
92
92
|
timeout: e.timeout ?? 1e4,
|
|
93
93
|
maximumAge: e.maximumAge ?? 6e4
|
|
@@ -107,21 +107,21 @@ class v {
|
|
|
107
107
|
t(c);
|
|
108
108
|
},
|
|
109
109
|
(r) => {
|
|
110
|
-
let c = "UNKNOWN_ERROR",
|
|
110
|
+
let c = "UNKNOWN_ERROR", a = "Unknown geolocation error";
|
|
111
111
|
switch (r.code) {
|
|
112
112
|
case r.PERMISSION_DENIED:
|
|
113
|
-
c = "PERMISSION_DENIED",
|
|
113
|
+
c = "PERMISSION_DENIED", a = "Geolocation permission denied";
|
|
114
114
|
break;
|
|
115
115
|
case r.POSITION_UNAVAILABLE:
|
|
116
|
-
|
|
116
|
+
a = "Position unavailable";
|
|
117
117
|
break;
|
|
118
118
|
case r.TIMEOUT:
|
|
119
|
-
|
|
119
|
+
a = "Geolocation timeout";
|
|
120
120
|
break;
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
i(s(a, c));
|
|
123
123
|
},
|
|
124
|
-
|
|
124
|
+
o
|
|
125
125
|
);
|
|
126
126
|
});
|
|
127
127
|
}
|
|
@@ -130,30 +130,30 @@ class v {
|
|
|
130
130
|
*/
|
|
131
131
|
watchPosition(e, t = {}) {
|
|
132
132
|
if (!this.isSupported())
|
|
133
|
-
throw
|
|
134
|
-
const
|
|
133
|
+
throw s("Geolocation API is not supported", "NOT_SUPPORTED");
|
|
134
|
+
const i = {
|
|
135
135
|
enableHighAccuracy: t.enableHighAccuracy ?? !0,
|
|
136
136
|
timeout: t.timeout ?? 1e4,
|
|
137
137
|
maximumAge: t.maximumAge ?? 6e4
|
|
138
138
|
};
|
|
139
139
|
return navigator.geolocation.watchPosition(
|
|
140
|
-
(
|
|
140
|
+
(o) => {
|
|
141
141
|
const r = {
|
|
142
|
-
latitude:
|
|
143
|
-
longitude:
|
|
144
|
-
accuracy:
|
|
145
|
-
altitude:
|
|
146
|
-
altitudeAccuracy:
|
|
147
|
-
heading:
|
|
148
|
-
speed:
|
|
149
|
-
timestamp:
|
|
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
|
e(r);
|
|
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
|
/**
|
|
@@ -163,51 +163,211 @@ class v {
|
|
|
163
163
|
navigator.geolocation.clearWatch(e);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
const
|
|
167
|
-
|
|
166
|
+
const q = new T();
|
|
167
|
+
function f() {
|
|
168
|
+
return "DeviceMotionEvent" in window;
|
|
169
|
+
}
|
|
170
|
+
function N() {
|
|
171
|
+
return "DeviceOrientationEvent" in window;
|
|
172
|
+
}
|
|
173
|
+
function R() {
|
|
174
|
+
const n = typeof window < "u", e = n && !!window.webkit, t = e && !!window.webkit?.messageHandlers, i = t && !!window.webkit?.messageHandlers?.aippyListener;
|
|
175
|
+
return console.log("🔍 [Aippy Sensors] hasNativeBridge check:", {
|
|
176
|
+
hasWindow: n,
|
|
177
|
+
hasWebkit: e,
|
|
178
|
+
hasMessageHandlers: t,
|
|
179
|
+
hasAippyListener: i,
|
|
180
|
+
result: i
|
|
181
|
+
}), i;
|
|
182
|
+
}
|
|
183
|
+
function I() {
|
|
184
|
+
return typeof window < "u" && typeof window.orientation < "u" ? window.orientation : typeof window < "u" && window.screen?.orientation?.angle !== void 0 ? window.screen.orientation.angle : 0;
|
|
185
|
+
}
|
|
186
|
+
function y(n, e, t) {
|
|
187
|
+
switch (t) {
|
|
188
|
+
case 0:
|
|
189
|
+
return [n, e];
|
|
190
|
+
case 180:
|
|
191
|
+
return [-n, -e];
|
|
192
|
+
case 90:
|
|
193
|
+
return [-e, n];
|
|
194
|
+
case -90:
|
|
195
|
+
return [e, -n];
|
|
196
|
+
default:
|
|
197
|
+
return [n, e];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async function b() {
|
|
201
|
+
if (console.log("🔐 [Aippy Sensors] requestMotionPermission called"), R())
|
|
202
|
+
return console.log("✅ [Aippy Sensors] Native bridge available, skipping permission request"), !0;
|
|
203
|
+
if (!f())
|
|
204
|
+
return console.warn("❌ [Aippy Sensors] Device motion not supported"), !1;
|
|
205
|
+
const n = typeof DeviceMotionEvent < "u" && typeof DeviceMotionEvent.requestPermission == "function";
|
|
206
|
+
if (console.log("🔍 [Aippy Sensors] Permission API available:", n), n)
|
|
207
|
+
try {
|
|
208
|
+
console.log("🙏 [Aippy Sensors] Requesting device motion permission...");
|
|
209
|
+
const e = await DeviceMotionEvent.requestPermission();
|
|
210
|
+
return console.log("📋 [Aippy Sensors] Permission result:", e), e === "granted";
|
|
211
|
+
} catch (e) {
|
|
212
|
+
return console.warn("❌ [Aippy Sensors] Permission request failed:", e), !1;
|
|
213
|
+
}
|
|
214
|
+
return console.log("✅ [Aippy Sensors] No permission needed (granted by default)"), !0;
|
|
215
|
+
}
|
|
216
|
+
function _(n) {
|
|
217
|
+
console.log("🔧 [Aippy Sensors] watchMotionNative - Setting up native bridge listener");
|
|
218
|
+
const e = L.addMotionListener((t) => {
|
|
219
|
+
const i = I(), o = t.gravity?.x ?? 0, r = t.gravity?.y ?? 0, c = t.gravity?.z ?? 0, a = t.acceleration?.x ?? 0, d = t.acceleration?.y ?? 0, u = t.acceleration?.z ?? 0, [m, l] = y(o, r, i), [g, h] = y(a, d, i), v = {
|
|
220
|
+
gravity: {
|
|
221
|
+
x: m,
|
|
222
|
+
y: l,
|
|
223
|
+
z: c
|
|
224
|
+
// Z轴不受屏幕旋转影响
|
|
225
|
+
},
|
|
226
|
+
acceleration: {
|
|
227
|
+
x: g,
|
|
228
|
+
y: h,
|
|
229
|
+
z: u
|
|
230
|
+
// Z轴不受屏幕旋转影响
|
|
231
|
+
},
|
|
232
|
+
accelerationIncludingGravity: {
|
|
233
|
+
x: m + g,
|
|
234
|
+
y: l + h,
|
|
235
|
+
z: c + u
|
|
236
|
+
},
|
|
237
|
+
rotation: {
|
|
238
|
+
alpha: t.rotation?.alpha ?? 0,
|
|
239
|
+
beta: t.rotation?.beta ?? 0,
|
|
240
|
+
gamma: t.rotation?.gamma ?? 0
|
|
241
|
+
},
|
|
242
|
+
timestamp: Date.now()
|
|
243
|
+
};
|
|
244
|
+
n(v);
|
|
245
|
+
});
|
|
246
|
+
return console.log("✅ [Aippy Sensors] watchMotionNative - Listener setup complete"), e;
|
|
247
|
+
}
|
|
248
|
+
function F(n, e = !0) {
|
|
249
|
+
if (!f())
|
|
250
|
+
throw s("Device motion API is not supported", "NOT_SUPPORTED");
|
|
251
|
+
let t = !1, i = null;
|
|
252
|
+
const o = (a) => {
|
|
253
|
+
if (!t) return;
|
|
254
|
+
const d = I();
|
|
255
|
+
let u, m, l;
|
|
256
|
+
if (a.acceleration) {
|
|
257
|
+
const w = a.accelerationIncludingGravity, p = a.acceleration;
|
|
258
|
+
u = (w?.x ?? 0) - (p?.x ?? 0), m = (w?.y ?? 0) - (p?.y ?? 0), l = (w?.z ?? 0) - (p?.z ?? 0);
|
|
259
|
+
} else {
|
|
260
|
+
const w = a.accelerationIncludingGravity, p = 9.8;
|
|
261
|
+
u = (w?.x ?? 0) / p, m = (w?.y ?? 0) / p, l = (w?.z ?? 0) / p;
|
|
262
|
+
}
|
|
263
|
+
const g = a.acceleration?.x ?? 0, h = a.acceleration?.y ?? 0, v = a.acceleration?.z ?? 0, [E, P] = y(u, m, d), [O, S] = y(g, h, d), D = {
|
|
264
|
+
gravity: {
|
|
265
|
+
x: E,
|
|
266
|
+
y: P,
|
|
267
|
+
z: l
|
|
268
|
+
// Z轴不受屏幕旋转影响
|
|
269
|
+
},
|
|
270
|
+
acceleration: {
|
|
271
|
+
x: O,
|
|
272
|
+
y: S,
|
|
273
|
+
z: v
|
|
274
|
+
// Z轴不受屏幕旋转影响
|
|
275
|
+
},
|
|
276
|
+
accelerationIncludingGravity: {
|
|
277
|
+
x: E + O,
|
|
278
|
+
y: P + S,
|
|
279
|
+
z: l + v
|
|
280
|
+
},
|
|
281
|
+
rotation: {
|
|
282
|
+
alpha: a.rotationRate?.alpha ?? 0,
|
|
283
|
+
beta: a.rotationRate?.beta ?? 0,
|
|
284
|
+
gamma: a.rotationRate?.gamma ?? 0
|
|
285
|
+
},
|
|
286
|
+
timestamp: Date.now()
|
|
287
|
+
};
|
|
288
|
+
n(D);
|
|
289
|
+
}, r = async () => {
|
|
290
|
+
e && !await b() || (t = !0, window.addEventListener("devicemotion", o));
|
|
291
|
+
};
|
|
292
|
+
return (async () => {
|
|
293
|
+
if (typeof DeviceMotionEvent < "u" && typeof DeviceMotionEvent.requestPermission == "function" && e) {
|
|
294
|
+
const d = async () => {
|
|
295
|
+
i = null, await r();
|
|
296
|
+
};
|
|
297
|
+
window.addEventListener("click", d, { once: !0 }), window.addEventListener("touchstart", d, { once: !0 }), i = () => {
|
|
298
|
+
window.removeEventListener("click", d), window.removeEventListener("touchstart", d);
|
|
299
|
+
};
|
|
300
|
+
} else
|
|
301
|
+
await r();
|
|
302
|
+
})(), () => {
|
|
303
|
+
t = !1, window.removeEventListener("devicemotion", o), i && (i(), i = null);
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
function C(n, e = !0) {
|
|
307
|
+
const t = R();
|
|
308
|
+
return console.log(`🎯 [Aippy Sensors] watchMotion - Using ${t ? "NATIVE BRIDGE" : "WEB API"} mode`), t ? (console.log("📱 [Aippy Sensors] Starting native bridge motion listener"), _(n)) : (console.log("🌐 [Aippy Sensors] Starting Web API motion listener (may require permission)"), F(n, e));
|
|
309
|
+
}
|
|
310
|
+
function B(n) {
|
|
311
|
+
if (!N())
|
|
312
|
+
throw s("Device orientation API is not supported", "NOT_SUPPORTED");
|
|
313
|
+
const e = (t) => {
|
|
314
|
+
const i = {
|
|
315
|
+
alpha: t.alpha ?? 0,
|
|
316
|
+
beta: t.beta ?? 0,
|
|
317
|
+
gamma: t.gamma ?? 0,
|
|
318
|
+
timestamp: Date.now()
|
|
319
|
+
};
|
|
320
|
+
n(i);
|
|
321
|
+
};
|
|
322
|
+
return window.addEventListener("deviceorientation", e), () => {
|
|
323
|
+
window.removeEventListener("deviceorientation", e);
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
class x {
|
|
168
327
|
/**
|
|
169
328
|
* Check if device orientation is supported
|
|
170
329
|
*/
|
|
171
330
|
isOrientationSupported() {
|
|
172
|
-
return
|
|
331
|
+
return N();
|
|
173
332
|
}
|
|
174
333
|
/**
|
|
175
334
|
* Check if device motion is supported
|
|
176
335
|
*/
|
|
177
336
|
isMotionSupported() {
|
|
178
|
-
return
|
|
337
|
+
return f();
|
|
179
338
|
}
|
|
180
339
|
/**
|
|
181
340
|
* Get device orientation data
|
|
182
341
|
*/
|
|
183
342
|
async getOrientation() {
|
|
184
343
|
if (!this.isOrientationSupported())
|
|
185
|
-
throw
|
|
344
|
+
throw s("Device orientation API is not supported", "NOT_SUPPORTED");
|
|
186
345
|
return new Promise((e, t) => {
|
|
187
|
-
const
|
|
188
|
-
window.removeEventListener("deviceorientation",
|
|
189
|
-
x:
|
|
190
|
-
y:
|
|
191
|
-
z:
|
|
346
|
+
const i = (o) => {
|
|
347
|
+
window.removeEventListener("deviceorientation", i), e({
|
|
348
|
+
x: o.alpha ?? 0,
|
|
349
|
+
y: o.beta ?? 0,
|
|
350
|
+
z: o.gamma ?? 0,
|
|
192
351
|
timestamp: Date.now()
|
|
193
352
|
});
|
|
194
353
|
};
|
|
195
|
-
window.addEventListener("deviceorientation",
|
|
196
|
-
window.removeEventListener("deviceorientation",
|
|
354
|
+
window.addEventListener("deviceorientation", i), setTimeout(() => {
|
|
355
|
+
window.removeEventListener("deviceorientation", i), t(s("Device orientation timeout", "UNKNOWN_ERROR"));
|
|
197
356
|
}, 5e3);
|
|
198
357
|
});
|
|
199
358
|
}
|
|
200
359
|
/**
|
|
201
360
|
* Watch device orientation changes
|
|
361
|
+
* @deprecated Use watchOrientation() function instead
|
|
202
362
|
*/
|
|
203
363
|
watchOrientation(e) {
|
|
204
364
|
if (!this.isOrientationSupported())
|
|
205
|
-
throw
|
|
206
|
-
const t = (
|
|
365
|
+
throw s("Device orientation API is not supported", "NOT_SUPPORTED");
|
|
366
|
+
const t = (i) => {
|
|
207
367
|
e({
|
|
208
|
-
x:
|
|
209
|
-
y:
|
|
210
|
-
z:
|
|
368
|
+
x: i.alpha ?? 0,
|
|
369
|
+
y: i.beta ?? 0,
|
|
370
|
+
z: i.gamma ?? 0,
|
|
211
371
|
timestamp: Date.now()
|
|
212
372
|
});
|
|
213
373
|
};
|
|
@@ -220,32 +380,33 @@ class E {
|
|
|
220
380
|
*/
|
|
221
381
|
async getMotion() {
|
|
222
382
|
if (!this.isMotionSupported())
|
|
223
|
-
throw
|
|
383
|
+
throw s("Device motion API is not supported", "NOT_SUPPORTED");
|
|
224
384
|
return new Promise((e, t) => {
|
|
225
|
-
const
|
|
226
|
-
window.removeEventListener("devicemotion",
|
|
227
|
-
x:
|
|
228
|
-
y:
|
|
229
|
-
z:
|
|
385
|
+
const i = (o) => {
|
|
386
|
+
window.removeEventListener("devicemotion", i), e({
|
|
387
|
+
x: o.acceleration?.x ?? 0,
|
|
388
|
+
y: o.acceleration?.y ?? 0,
|
|
389
|
+
z: o.acceleration?.z ?? 0,
|
|
230
390
|
timestamp: Date.now()
|
|
231
391
|
});
|
|
232
392
|
};
|
|
233
|
-
window.addEventListener("devicemotion",
|
|
234
|
-
window.removeEventListener("devicemotion",
|
|
393
|
+
window.addEventListener("devicemotion", i), setTimeout(() => {
|
|
394
|
+
window.removeEventListener("devicemotion", i), t(s("Device motion timeout", "UNKNOWN_ERROR"));
|
|
235
395
|
}, 5e3);
|
|
236
396
|
});
|
|
237
397
|
}
|
|
238
398
|
/**
|
|
239
399
|
* Watch device motion changes
|
|
400
|
+
* @deprecated Use watchMotion() function instead
|
|
240
401
|
*/
|
|
241
402
|
watchMotion(e) {
|
|
242
403
|
if (!this.isMotionSupported())
|
|
243
|
-
throw
|
|
244
|
-
const t = (
|
|
404
|
+
throw s("Device motion API is not supported", "NOT_SUPPORTED");
|
|
405
|
+
const t = (i) => {
|
|
245
406
|
e({
|
|
246
|
-
x:
|
|
247
|
-
y:
|
|
248
|
-
z:
|
|
407
|
+
x: i.acceleration?.x ?? 0,
|
|
408
|
+
y: i.acceleration?.y ?? 0,
|
|
409
|
+
z: i.acceleration?.z ?? 0,
|
|
249
410
|
timestamp: Date.now()
|
|
250
411
|
});
|
|
251
412
|
};
|
|
@@ -257,17 +418,11 @@ class E {
|
|
|
257
418
|
* Request permission for motion sensors (iOS 13+)
|
|
258
419
|
*/
|
|
259
420
|
async requestPermission() {
|
|
260
|
-
|
|
261
|
-
return !1;
|
|
262
|
-
try {
|
|
263
|
-
return (await navigator.permissions?.query({ name: "accelerometer" }))?.state === "granted";
|
|
264
|
-
} catch {
|
|
265
|
-
return !1;
|
|
266
|
-
}
|
|
421
|
+
return b();
|
|
267
422
|
}
|
|
268
423
|
}
|
|
269
|
-
const
|
|
270
|
-
class
|
|
424
|
+
const K = new x();
|
|
425
|
+
class G {
|
|
271
426
|
/**
|
|
272
427
|
* Check if file system access is supported
|
|
273
428
|
*/
|
|
@@ -285,7 +440,7 @@ class O {
|
|
|
285
440
|
*/
|
|
286
441
|
async openFilePicker(e = {}) {
|
|
287
442
|
if (!this.isSupported())
|
|
288
|
-
throw
|
|
443
|
+
throw s("File System Access API is not supported", "NOT_SUPPORTED");
|
|
289
444
|
try {
|
|
290
445
|
const t = {
|
|
291
446
|
types: e.accept ? [{
|
|
@@ -295,15 +450,15 @@ class O {
|
|
|
295
450
|
)
|
|
296
451
|
}] : void 0,
|
|
297
452
|
multiple: e.multiple ?? !1
|
|
298
|
-
},
|
|
299
|
-
|
|
453
|
+
}, i = await window.showOpenFilePicker(t), o = await Promise.all(
|
|
454
|
+
i.map(async (r) => r.getFile())
|
|
300
455
|
);
|
|
301
456
|
return {
|
|
302
|
-
files:
|
|
303
|
-
paths:
|
|
457
|
+
files: o,
|
|
458
|
+
paths: o.map((r) => r.name)
|
|
304
459
|
};
|
|
305
460
|
} catch (t) {
|
|
306
|
-
throw t instanceof Error && t.name === "AbortError" ?
|
|
461
|
+
throw t instanceof Error && t.name === "AbortError" ? s("File picker was cancelled", "PERMISSION_DENIED") : s(
|
|
307
462
|
`Failed to open file picker: ${t instanceof Error ? t.message : "Unknown error"}`,
|
|
308
463
|
"PERMISSION_DENIED"
|
|
309
464
|
);
|
|
@@ -314,18 +469,18 @@ class O {
|
|
|
314
469
|
*/
|
|
315
470
|
async openFilePickerLegacy(e = {}) {
|
|
316
471
|
if (!this.isLegacySupported())
|
|
317
|
-
throw
|
|
318
|
-
return new Promise((t,
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
const c = r.target,
|
|
472
|
+
throw s("File input is not supported", "NOT_SUPPORTED");
|
|
473
|
+
return new Promise((t, i) => {
|
|
474
|
+
const o = document.createElement("input");
|
|
475
|
+
o.type = "file", o.multiple = e.multiple ?? !1, o.accept = e.accept?.join(",") ?? "", o.onchange = (r) => {
|
|
476
|
+
const c = r.target, a = Array.from(c.files || []);
|
|
322
477
|
t({
|
|
323
|
-
files:
|
|
324
|
-
paths:
|
|
478
|
+
files: a,
|
|
479
|
+
paths: a.map((d) => d.name)
|
|
325
480
|
});
|
|
326
|
-
},
|
|
327
|
-
|
|
328
|
-
},
|
|
481
|
+
}, o.oncancel = () => {
|
|
482
|
+
i(s("File picker was cancelled", "PERMISSION_DENIED"));
|
|
483
|
+
}, o.click();
|
|
329
484
|
});
|
|
330
485
|
}
|
|
331
486
|
/**
|
|
@@ -339,11 +494,11 @@ class O {
|
|
|
339
494
|
*/
|
|
340
495
|
async saveFile(e, t) {
|
|
341
496
|
try {
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
} catch (
|
|
345
|
-
throw
|
|
346
|
-
`Failed to save file: ${
|
|
497
|
+
const i = URL.createObjectURL(e), o = document.createElement("a");
|
|
498
|
+
o.href = i, o.download = t, document.body.appendChild(o), o.click(), document.body.removeChild(o), URL.revokeObjectURL(i);
|
|
499
|
+
} catch (i) {
|
|
500
|
+
throw s(
|
|
501
|
+
`Failed to save file: ${i instanceof Error ? i.message : "Unknown error"}`,
|
|
347
502
|
"UNKNOWN_ERROR"
|
|
348
503
|
);
|
|
349
504
|
}
|
|
@@ -352,23 +507,23 @@ class O {
|
|
|
352
507
|
* Read file as text
|
|
353
508
|
*/
|
|
354
509
|
async readAsText(e) {
|
|
355
|
-
return new Promise((t,
|
|
356
|
-
const
|
|
357
|
-
|
|
510
|
+
return new Promise((t, i) => {
|
|
511
|
+
const o = new FileReader();
|
|
512
|
+
o.onload = () => t(o.result), o.onerror = () => i(s("Failed to read file", "UNKNOWN_ERROR")), o.readAsText(e);
|
|
358
513
|
});
|
|
359
514
|
}
|
|
360
515
|
/**
|
|
361
516
|
* Read file as data URL
|
|
362
517
|
*/
|
|
363
518
|
async readAsDataURL(e) {
|
|
364
|
-
return new Promise((t,
|
|
365
|
-
const
|
|
366
|
-
|
|
519
|
+
return new Promise((t, i) => {
|
|
520
|
+
const o = new FileReader();
|
|
521
|
+
o.onload = () => t(o.result), o.onerror = () => i(s("Failed to read file", "UNKNOWN_ERROR")), o.readAsDataURL(e);
|
|
367
522
|
});
|
|
368
523
|
}
|
|
369
524
|
}
|
|
370
|
-
const
|
|
371
|
-
function
|
|
525
|
+
const X = new G();
|
|
526
|
+
function Y(n) {
|
|
372
527
|
return new Promise((e) => {
|
|
373
528
|
if ("vibrate" in navigator)
|
|
374
529
|
navigator.vibrate(n), e();
|
|
@@ -383,13 +538,19 @@ function D(n) {
|
|
|
383
538
|
});
|
|
384
539
|
}
|
|
385
540
|
export {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
R as
|
|
394
|
-
|
|
541
|
+
k as CameraAPI,
|
|
542
|
+
G as FileSystemAPI,
|
|
543
|
+
T as GeolocationAPI,
|
|
544
|
+
x as SensorsAPI,
|
|
545
|
+
H as camera,
|
|
546
|
+
X as fileSystem,
|
|
547
|
+
q as geolocation,
|
|
548
|
+
R as hasNativeBridge,
|
|
549
|
+
f as isMotionSupported,
|
|
550
|
+
N as isOrientationSupported,
|
|
551
|
+
b as requestMotionPermission,
|
|
552
|
+
K as sensors,
|
|
553
|
+
Y as vibrate,
|
|
554
|
+
C as watchMotion,
|
|
555
|
+
B as watchOrientation
|
|
395
556
|
};
|
package/dist/device/sensors.d.ts
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
|
-
import { SensorData } from './types';
|
|
1
|
+
import { SensorData, MotionData, OrientationData } from './types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Check if device motion is supported
|
|
4
|
+
*/
|
|
5
|
+
export declare function isMotionSupported(): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Check if device orientation is supported
|
|
8
|
+
*/
|
|
9
|
+
export declare function isOrientationSupported(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Check if native bridge is available
|
|
12
|
+
*/
|
|
13
|
+
export declare function hasNativeBridge(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Request permission for motion sensors (iOS 13+)
|
|
16
|
+
* @returns Promise<boolean> - true if permission granted
|
|
17
|
+
*/
|
|
18
|
+
export declare function requestMotionPermission(): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Watch device motion changes with full motion data
|
|
21
|
+
* Automatically uses native bridge if available, otherwise falls back to Web API
|
|
22
|
+
*
|
|
23
|
+
* @param callback - Function to call with motion data
|
|
24
|
+
* @param autoRequestPermission - Automatically request permission on iOS (default: true, only for Web API)
|
|
25
|
+
* @returns Cleanup function to stop watching
|
|
26
|
+
*/
|
|
27
|
+
export declare function watchMotion(callback: (data: MotionData) => void, autoRequestPermission?: boolean): () => void;
|
|
28
|
+
/**
|
|
29
|
+
* Watch device orientation changes
|
|
30
|
+
* @param callback - Function to call with orientation data
|
|
31
|
+
* @returns Cleanup function to stop watching
|
|
32
|
+
*/
|
|
33
|
+
export declare function watchOrientation(callback: (data: OrientationData) => void): () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Legacy SensorsAPI class for backward compatibility
|
|
36
|
+
* @deprecated Use watchMotion() and watchOrientation() functions instead
|
|
4
37
|
*/
|
|
5
38
|
export declare class SensorsAPI {
|
|
6
39
|
/**
|
|
@@ -17,6 +50,7 @@ export declare class SensorsAPI {
|
|
|
17
50
|
getOrientation(): Promise<SensorData>;
|
|
18
51
|
/**
|
|
19
52
|
* Watch device orientation changes
|
|
53
|
+
* @deprecated Use watchOrientation() function instead
|
|
20
54
|
*/
|
|
21
55
|
watchOrientation(callback: (data: SensorData) => void): () => void;
|
|
22
56
|
/**
|
|
@@ -25,6 +59,7 @@ export declare class SensorsAPI {
|
|
|
25
59
|
getMotion(): Promise<SensorData>;
|
|
26
60
|
/**
|
|
27
61
|
* Watch device motion changes
|
|
62
|
+
* @deprecated Use watchMotion() function instead
|
|
28
63
|
*/
|
|
29
64
|
watchMotion(callback: (data: SensorData) => void): () => void;
|
|
30
65
|
/**
|
|
@@ -33,6 +68,7 @@ export declare class SensorsAPI {
|
|
|
33
68
|
requestPermission(): Promise<boolean>;
|
|
34
69
|
}
|
|
35
70
|
/**
|
|
36
|
-
* Sensors API instance
|
|
71
|
+
* Sensors API instance (for backward compatibility)
|
|
72
|
+
* @deprecated Use watchMotion() and watchOrientation() functions instead
|
|
37
73
|
*/
|
|
38
74
|
export declare const sensors: SensorsAPI;
|