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