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