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