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