@aippy/runtime 0.2.4-dev.11 → 0.2.4-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,7 +22,7 @@ function c(e) {
22
22
  }
23
23
  };
24
24
  }
25
- const r = "0.2.4-dev.11", a = {
25
+ const r = "0.2.4-dev.2", a = {
26
26
  version: r
27
27
  }, i = a.version, t = "@aippy/runtime";
28
28
  function p() {
@@ -1,10 +1,10 @@
1
- var O = Object.defineProperty;
2
- var S = (n, e, t) => e in n ? O(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var h = (n, e, t) => S(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { c as s, b as A } from "../runtime-DjBdOttl.js";
5
- class N {
1
+ var U = Object.defineProperty;
2
+ var M = (n, e, t) => e in n ? U(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var A = (n, e, t) => M(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { c as s, b as L } from "../runtime-DjBdOttl.js";
5
+ class k {
6
6
  constructor() {
7
- h(this, "stream", null);
7
+ A(this, "stream", null);
8
8
  }
9
9
  /**
10
10
  * Check if camera is supported
@@ -47,14 +47,14 @@ class N {
47
47
  if (!o)
48
48
  throw s("Failed to get canvas context", "UNKNOWN_ERROR");
49
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", d = e.quality === "high" ? 0.9 : e.quality === "medium" ? 0.7 : 0.5, a = await new Promise((l, u) => {
51
- i.toBlob((m) => {
52
- m ? l(m) : u(new Error("Failed to create blob"));
53
- }, `image/${r}`, d);
54
- }), c = i.toDataURL(`image/${r}`, d);
50
+ const r = e.format || "jpeg", c = e.quality === "high" ? 0.9 : e.quality === "medium" ? 0.7 : 0.5, a = await new Promise((u, m) => {
51
+ i.toBlob((l) => {
52
+ l ? u(l) : m(new Error("Failed to create blob"));
53
+ }, `image/${r}`, c);
54
+ }), d = i.toDataURL(`image/${r}`, c);
55
55
  return {
56
56
  blob: a,
57
- dataUrl: c,
57
+ dataUrl: d,
58
58
  width: i.width,
59
59
  height: i.height
60
60
  };
@@ -72,8 +72,8 @@ class N {
72
72
  this.stream && (this.stream.getTracks().forEach((e) => e.stop()), this.stream = null);
73
73
  }
74
74
  }
75
- const T = new N();
76
- class R {
75
+ const H = new k();
76
+ class T {
77
77
  /**
78
78
  * Check if geolocation is supported
79
79
  */
@@ -94,7 +94,7 @@ class R {
94
94
  };
95
95
  navigator.geolocation.getCurrentPosition(
96
96
  (r) => {
97
- const d = {
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 R {
104
104
  speed: r.coords.speed ?? void 0,
105
105
  timestamp: r.timestamp
106
106
  };
107
- t(d);
107
+ t(c);
108
108
  },
109
109
  (r) => {
110
- let d = "UNKNOWN_ERROR", a = "Unknown geolocation error";
110
+ let c = "UNKNOWN_ERROR", a = "Unknown geolocation error";
111
111
  switch (r.code) {
112
112
  case r.PERMISSION_DENIED:
113
- d = "PERMISSION_DENIED", a = "Geolocation permission denied";
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 R {
119
119
  a = "Geolocation timeout";
120
120
  break;
121
121
  }
122
- i(s(a, d));
122
+ i(s(a, c));
123
123
  },
124
124
  o
125
125
  );
@@ -163,14 +163,14 @@ class R {
163
163
  navigator.geolocation.clearWatch(e);
164
164
  }
165
165
  }
166
- const x = new R();
167
- function w() {
166
+ const q = new T();
167
+ function f() {
168
168
  return "DeviceMotionEvent" in window;
169
169
  }
170
- function v() {
170
+ function N() {
171
171
  return "DeviceOrientationEvent" in window;
172
172
  }
173
- function f() {
173
+ function R() {
174
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,
@@ -197,10 +197,10 @@ function y(n, e, t) {
197
197
  return [n, e];
198
198
  }
199
199
  }
200
- async function E() {
201
- if (console.log("🔐 [Aippy Sensors] requestMotionPermission called"), f())
200
+ async function b() {
201
+ if (console.log("🔐 [Aippy Sensors] requestMotionPermission called"), R())
202
202
  return console.log("✅ [Aippy Sensors] Native bridge available, skipping permission request"), !0;
203
- if (!w())
203
+ if (!f())
204
204
  return console.warn("❌ [Aippy Sensors] Device motion not supported"), !1;
205
205
  const n = typeof DeviceMotionEvent < "u" && typeof DeviceMotionEvent.requestPermission == "function";
206
206
  if (console.log("🔍 [Aippy Sensors] Permission API available:", n), n)
@@ -213,26 +213,26 @@ async function E() {
213
213
  }
214
214
  return console.log("✅ [Aippy Sensors] No permission needed (granted by default)"), !0;
215
215
  }
216
- function b(n) {
216
+ function _(n) {
217
217
  console.log("🔧 [Aippy Sensors] watchMotionNative - Setting up native bridge listener");
218
- const e = A.addMotionListener((t) => {
219
- const i = I(), o = t.gravity?.x ?? 0, r = t.gravity?.y ?? 0, d = t.gravity?.z ?? 0, a = t.acceleration?.x ?? 0, c = t.acceleration?.y ?? 0, l = t.acceleration?.z ?? 0, [u, m] = y(o, r, i), [p, g] = y(a, c, i), P = {
218
+ const e = L.addMotionListener((t) => {
219
+ const i = I(), o = t.gravity?.x ?? 0, r = t.gravity?.y ?? 0, c = t.gravity?.z ?? 0, a = t.acceleration?.x ?? 0, d = t.acceleration?.y ?? 0, u = t.acceleration?.z ?? 0, [m, l] = y(o, r, i), [g, h] = y(a, d, i), v = {
220
220
  gravity: {
221
- x: u,
222
- y: m,
223
- z: d
221
+ x: m,
222
+ y: l,
223
+ z: c
224
224
  // Z轴不受屏幕旋转影响
225
225
  },
226
226
  acceleration: {
227
- x: p,
228
- y: g,
229
- z: l
227
+ x: g,
228
+ y: h,
229
+ z: u
230
230
  // Z轴不受屏幕旋转影响
231
231
  },
232
232
  accelerationIncludingGravity: {
233
- x: u + p,
234
- y: m + g,
235
- z: d + l
233
+ x: m + g,
234
+ y: l + h,
235
+ z: c + u
236
236
  },
237
237
  rotation: {
238
238
  alpha: t.rotation?.alpha ?? 0,
@@ -241,31 +241,42 @@ function b(n) {
241
241
  },
242
242
  timestamp: Date.now()
243
243
  };
244
- n(P);
244
+ n(v);
245
245
  });
246
246
  return console.log("✅ [Aippy Sensors] watchMotionNative - Listener setup complete"), e;
247
247
  }
248
- function D(n, e = !0) {
249
- if (!w())
248
+ function F(n, e = !0) {
249
+ if (!f())
250
250
  throw s("Device motion API is not supported", "NOT_SUPPORTED");
251
251
  let t = !1, i = null;
252
252
  const o = (a) => {
253
253
  if (!t) return;
254
- const c = {
254
+ const d = I();
255
+ let u, m, l;
256
+ if (a.acceleration) {
257
+ const w = a.accelerationIncludingGravity, p = a.acceleration;
258
+ u = (w?.x ?? 0) - (p?.x ?? 0), m = (w?.y ?? 0) - (p?.y ?? 0), l = (w?.z ?? 0) - (p?.z ?? 0);
259
+ } else {
260
+ const w = a.accelerationIncludingGravity, p = 9.8;
261
+ u = (w?.x ?? 0) / p, m = (w?.y ?? 0) / p, l = (w?.z ?? 0) / p;
262
+ }
263
+ const g = a.acceleration?.x ?? 0, h = a.acceleration?.y ?? 0, v = a.acceleration?.z ?? 0, [E, P] = y(u, m, d), [O, S] = y(g, h, d), D = {
255
264
  gravity: {
256
- x: a.acceleration?.x ?? 0,
257
- y: a.acceleration?.y ?? 0,
258
- z: a.acceleration?.z ?? 0
265
+ x: E,
266
+ y: P,
267
+ z: l
268
+ // Z轴不受屏幕旋转影响
259
269
  },
260
270
  acceleration: {
261
- x: a.acceleration?.x ?? 0,
262
- y: a.acceleration?.y ?? 0,
263
- z: a.acceleration?.z ?? 0
271
+ x: O,
272
+ y: S,
273
+ z: v
274
+ // Z轴不受屏幕旋转影响
264
275
  },
265
276
  accelerationIncludingGravity: {
266
- x: a.accelerationIncludingGravity?.x ?? 0,
267
- y: a.accelerationIncludingGravity?.y ?? 0,
268
- z: a.accelerationIncludingGravity?.z ?? 0
277
+ x: E + O,
278
+ y: P + S,
279
+ z: l + v
269
280
  },
270
281
  rotation: {
271
282
  alpha: a.rotationRate?.alpha ?? 0,
@@ -274,32 +285,17 @@ function D(n, e = !0) {
274
285
  },
275
286
  timestamp: Date.now()
276
287
  };
277
- if (a.acceleration) {
278
- const l = a.accelerationIncludingGravity, u = a.acceleration;
279
- c.gravity = {
280
- x: (l?.x ?? 0) - (u?.x ?? 0),
281
- y: (l?.y ?? 0) - (u?.y ?? 0),
282
- z: (l?.z ?? 0) - (u?.z ?? 0)
283
- };
284
- } else {
285
- const l = a.accelerationIncludingGravity, u = 9.8;
286
- c.gravity = {
287
- x: (l?.x ?? 0) / u,
288
- y: (l?.y ?? 0) / u,
289
- z: (l?.z ?? 0) / u
290
- };
291
- }
292
- n(c);
288
+ n(D);
293
289
  }, r = async () => {
294
- e && !await E() || (t = !0, window.addEventListener("devicemotion", o));
290
+ e && !await b() || (t = !0, window.addEventListener("devicemotion", o));
295
291
  };
296
292
  return (async () => {
297
293
  if (typeof DeviceMotionEvent < "u" && typeof DeviceMotionEvent.requestPermission == "function" && e) {
298
- const c = async () => {
294
+ const d = async () => {
299
295
  i = null, await r();
300
296
  };
301
- window.addEventListener("click", c, { once: !0 }), window.addEventListener("touchstart", c, { once: !0 }), i = () => {
302
- window.removeEventListener("click", c), window.removeEventListener("touchstart", c);
297
+ window.addEventListener("click", d, { once: !0 }), window.addEventListener("touchstart", d, { once: !0 }), i = () => {
298
+ window.removeEventListener("click", d), window.removeEventListener("touchstart", d);
303
299
  };
304
300
  } else
305
301
  await r();
@@ -307,12 +303,12 @@ function D(n, e = !0) {
307
303
  t = !1, window.removeEventListener("devicemotion", o), i && (i(), i = null);
308
304
  };
309
305
  }
310
- function _(n, e = !0) {
311
- const t = f();
312
- return console.log(`🎯 [Aippy Sensors] watchMotion - Using ${t ? "NATIVE BRIDGE" : "WEB API"} mode`), t ? (console.log("📱 [Aippy Sensors] Starting native bridge motion listener"), b(n)) : (console.log("🌐 [Aippy Sensors] Starting Web API motion listener (may require permission)"), D(n, e));
306
+ function C(n, e = !0) {
307
+ const t = R();
308
+ return console.log(`🎯 [Aippy Sensors] watchMotion - Using ${t ? "NATIVE BRIDGE" : "WEB API"} mode`), t ? (console.log("📱 [Aippy Sensors] Starting native bridge motion listener"), _(n)) : (console.log("🌐 [Aippy Sensors] Starting Web API motion listener (may require permission)"), F(n, e));
313
309
  }
314
- function F(n) {
315
- if (!v())
310
+ function B(n) {
311
+ if (!N())
316
312
  throw s("Device orientation API is not supported", "NOT_SUPPORTED");
317
313
  const e = (t) => {
318
314
  const i = {
@@ -327,18 +323,18 @@ function F(n) {
327
323
  window.removeEventListener("deviceorientation", e);
328
324
  };
329
325
  }
330
- class U {
326
+ class x {
331
327
  /**
332
328
  * Check if device orientation is supported
333
329
  */
334
330
  isOrientationSupported() {
335
- return v();
331
+ return N();
336
332
  }
337
333
  /**
338
334
  * Check if device motion is supported
339
335
  */
340
336
  isMotionSupported() {
341
- return w();
337
+ return f();
342
338
  }
343
339
  /**
344
340
  * Get device orientation data
@@ -422,11 +418,11 @@ class U {
422
418
  * Request permission for motion sensors (iOS 13+)
423
419
  */
424
420
  async requestPermission() {
425
- return E();
421
+ return b();
426
422
  }
427
423
  }
428
- const z = new U();
429
- class M {
424
+ const K = new x();
425
+ class G {
430
426
  /**
431
427
  * Check if file system access is supported
432
428
  */
@@ -477,10 +473,10 @@ class M {
477
473
  return new Promise((t, i) => {
478
474
  const o = document.createElement("input");
479
475
  o.type = "file", o.multiple = e.multiple ?? !1, o.accept = e.accept?.join(",") ?? "", o.onchange = (r) => {
480
- const d = r.target, a = Array.from(d.files || []);
476
+ const c = r.target, a = Array.from(c.files || []);
481
477
  t({
482
478
  files: a,
483
- paths: a.map((c) => c.name)
479
+ paths: a.map((d) => d.name)
484
480
  });
485
481
  }, o.oncancel = () => {
486
482
  i(s("File picker was cancelled", "PERMISSION_DENIED"));
@@ -526,8 +522,8 @@ class M {
526
522
  });
527
523
  }
528
524
  }
529
- const G = new M();
530
- function W(n) {
525
+ const X = new G();
526
+ function Y(n) {
531
527
  return new Promise((e) => {
532
528
  if ("vibrate" in navigator)
533
529
  navigator.vibrate(n), e();
@@ -542,19 +538,19 @@ function W(n) {
542
538
  });
543
539
  }
544
540
  export {
545
- N as CameraAPI,
546
- M as FileSystemAPI,
547
- R as GeolocationAPI,
548
- U as SensorsAPI,
549
- T as camera,
550
- G as fileSystem,
551
- x as geolocation,
552
- f as hasNativeBridge,
553
- w as isMotionSupported,
554
- v as isOrientationSupported,
555
- E as requestMotionPermission,
556
- z as sensors,
557
- W as vibrate,
558
- _ as watchMotion,
559
- F as watchOrientation
541
+ k as CameraAPI,
542
+ G as FileSystemAPI,
543
+ T as GeolocationAPI,
544
+ x as SensorsAPI,
545
+ H as camera,
546
+ X as fileSystem,
547
+ q as geolocation,
548
+ R as hasNativeBridge,
549
+ f as isMotionSupported,
550
+ N as isOrientationSupported,
551
+ b as requestMotionPermission,
552
+ K as sensors,
553
+ Y as vibrate,
554
+ C as watchMotion,
555
+ B as watchOrientation
560
556
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aippy/runtime",
3
- "version": "0.2.4-dev.11",
3
+ "version": "0.2.4-dev.2",
4
4
  "description": "Aippy Runtime SDK - Runtime SDK for Aippy projects",
5
5
  "private": false,
6
6
  "type": "module",