@aippy/runtime 0.2.4-dev.6 → 0.2.4-dev.8

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.
@@ -1,4 +1,4 @@
1
- import { a as d, A as f, C as u, E as A, R as _, b as m, c as R, p as g } from "../runtime-DgUMQgA3.js";
1
+ import { a as d, A as f, 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.4-dev.6", a = {
25
+ const r = "0.2.4-dev.8", a = {
26
26
  version: r
27
27
  }, i = a.version, t = "@aippy/runtime";
28
28
  function p() {
@@ -39,18 +39,19 @@ export declare class AippyRuntime {
39
39
  receiveChannel: ReceiveChannel;
40
40
  private seq;
41
41
  private motionListeners;
42
+ private noListenersWarned;
42
43
  /**
43
44
  * Unified native data receiver - Routes to specific handlers based on message type
44
45
  * Called by native code via: window.aippyRuntime.receiveMessage(message)
45
46
  *
46
47
  * Supports two message formats:
47
- * 1. Motion: { endpoint: "0", payload: { motion: {...} } }
48
+ * 1. Motion: { command: "navigator.motion", endpoint: "0", data: { motion: {...} } }
48
49
  * 2. Tweaks: { "tweakKey": { value: ..., type: ... }, ... }
49
50
  */
50
51
  receiveMessage(message: any): Promise<void>;
51
52
  /**
52
53
  * Check if message is Motion format
53
- * Motion: { endpoint: string, payload: object }
54
+ * Motion: { command: "navigator.motion", endpoint: string, data: object }
54
55
  */
55
56
  private isMotionMessage;
56
57
  /**
@@ -60,16 +61,12 @@ export declare class AippyRuntime {
60
61
  private isTweaksMessage;
61
62
  /**
62
63
  * Create a subscription to native events
63
- * @param handler - WebKit message handler (e.g., deviceMotionHandler)
64
- * @param subscribePayload - Subscription parameters (e.g., { type: "motion" })
64
+ * @param handler - WebKit message handler (e.g., aippyListener)
65
+ * @param subscribePayload - Subscription parameters (e.g., { command: "navigator.motion", type: "motion" })
65
66
  * @param callback - Callback to handle received data
66
67
  * @returns Cancellable subscription
67
68
  */
68
69
  createSubscription(handler: any, subscribePayload: any, callback: (data: any) => void): Cancellable;
69
- /**
70
- * Make a subscription message with unique endpoint
71
- */
72
- private makeSubscriptionMessage;
73
70
  /**
74
71
  * Add motion listener (convenience method)
75
72
  * @param callback - Callback to handle motion data
@@ -1,7 +1,7 @@
1
1
  var v = Object.defineProperty;
2
2
  var E = (a, t, e) => t in a ? v(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
3
  var w = (a, t, e) => E(a, typeof t != "symbol" ? t + "" : t, e);
4
- import { c as s, b as f } from "../runtime-DgUMQgA3.js";
4
+ import { c as s, b as f } from "../runtime-DjBdOttl.js";
5
5
  class P {
6
6
  constructor() {
7
7
  w(this, "stream", null);
@@ -197,7 +197,8 @@ async function y() {
197
197
  return console.log("✅ [Aippy Sensors] No permission needed (granted by default)"), !0;
198
198
  }
199
199
  function S(a) {
200
- return f.addMotionListener((e) => {
200
+ console.log("🔧 [Aippy Sensors] watchMotionNative - Setting up native bridge listener");
201
+ const t = f.addMotionListener((e) => {
201
202
  const i = {
202
203
  gravity: {
203
204
  x: e.gravity?.x ?? 0,
@@ -223,6 +224,7 @@ function S(a) {
223
224
  };
224
225
  a(i);
225
226
  });
227
+ return console.log("✅ [Aippy Sensors] watchMotionNative - Listener setup complete"), t;
226
228
  }
227
229
  function N(a, t = !0) {
228
230
  if (!m())
@@ -286,11 +288,11 @@ function N(a, t = !0) {
286
288
  e = !1, window.removeEventListener("devicemotion", o), i && (i(), i = null);
287
289
  };
288
290
  }
289
- function L(a, t = !0) {
291
+ function M(a, t = !0) {
290
292
  const e = h();
291
293
  return console.log(`🎯 [Aippy Sensors] watchMotion - Using ${e ? "NATIVE BRIDGE" : "WEB API"} mode`), e ? (console.log("📱 [Aippy Sensors] Starting native bridge motion listener"), S(a)) : (console.log("🌐 [Aippy Sensors] Starting Web API motion listener (may require permission)"), N(a, t));
292
294
  }
293
- function M(a) {
295
+ function L(a) {
294
296
  if (!g())
295
297
  throw s("Device orientation API is not supported", "NOT_SUPPORTED");
296
298
  const t = (e) => {
@@ -306,7 +308,7 @@ function M(a) {
306
308
  window.removeEventListener("deviceorientation", t);
307
309
  };
308
310
  }
309
- class R {
311
+ class A {
310
312
  /**
311
313
  * Check if device orientation is supported
312
314
  */
@@ -404,8 +406,8 @@ class R {
404
406
  return y();
405
407
  }
406
408
  }
407
- const x = new R();
408
- class A {
409
+ const x = new A();
410
+ class R {
409
411
  /**
410
412
  * Check if file system access is supported
411
413
  */
@@ -505,7 +507,7 @@ class A {
505
507
  });
506
508
  }
507
509
  }
508
- const k = new A();
510
+ const k = new R();
509
511
  function T(a) {
510
512
  return new Promise((t) => {
511
513
  if ("vibrate" in navigator)
@@ -522,9 +524,9 @@ function T(a) {
522
524
  }
523
525
  export {
524
526
  P as CameraAPI,
525
- A as FileSystemAPI,
527
+ R as FileSystemAPI,
526
528
  O as GeolocationAPI,
527
- R as SensorsAPI,
529
+ A as SensorsAPI,
528
530
  D as camera,
529
531
  k as fileSystem,
530
532
  U as geolocation,
@@ -534,6 +536,6 @@ export {
534
536
  y as requestMotionPermission,
535
537
  x as sensors,
536
538
  T as vibrate,
537
- L as watchMotion,
538
- M as watchOrientation
539
+ M as watchMotion,
540
+ L as watchOrientation
539
541
  };
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_CONFIG as o, SDK_NAME as t, VERSION as r, getConfigFromEnv as i, getVersionInfo as s, mergeConfig as n } from "../core/index.js";
2
- import { a as m, A as c, C as d, E as f, R as u, b as l, c as A, p as S } from "../runtime-DgUMQgA3.js";
2
+ import { a as m, A as c, C as d, E as f, R as u, b as l, c as A, p as S } from "../runtime-DjBdOttl.js";
3
3
  import { CameraAPI as C, FileSystemAPI as R, GeolocationAPI as x, SensorsAPI as M, camera as P, fileSystem as I, geolocation as g, hasNativeBridge as y, isMotionSupported as O, isOrientationSupported as b, requestMotionPermission as v, sensors as D, vibrate as h, watchMotion as w, watchOrientation as F } from "../device/index.js";
4
4
  import { c as T, a as V, P as _, b as k, p as G, d as H } from "../pwa-8DGmPqLV.js";
5
5
  import { a as q, b as B } from "../useTweaks-QxMRmg7i.js";
@@ -1,27 +1,27 @@
1
- var p = Object.defineProperty;
2
- var u = (o, e, n) => e in o ? p(o, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : o[e] = n;
3
- var s = (o, e, n) => u(o, typeof e != "symbol" ? e + "" : e, n);
4
- class m extends Error {
5
- constructor(n, t = "AIPPY_ERROR", i) {
1
+ var u = Object.defineProperty;
2
+ var m = (o, e, n) => e in o ? u(o, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : o[e] = n;
3
+ var r = (o, e, n) => m(o, typeof e != "symbol" ? e + "" : e, n);
4
+ class d extends Error {
5
+ constructor(n, i = "AIPPY_ERROR", t) {
6
6
  super(n);
7
- s(this, "code");
8
- s(this, "context");
9
- this.name = "AippyRuntimeError", this.code = t, this.context = i;
7
+ r(this, "code");
8
+ r(this, "context");
9
+ this.name = "AippyRuntimeError", this.code = i, this.context = t;
10
10
  }
11
11
  }
12
- const d = {
12
+ const R = {
13
13
  NOT_SUPPORTED: "NOT_SUPPORTED",
14
14
  PERMISSION_DENIED: "PERMISSION_DENIED",
15
15
  INVALID_CONFIG: "INVALID_CONFIG",
16
16
  NETWORK_ERROR: "NETWORK_ERROR",
17
17
  UNKNOWN_ERROR: "UNKNOWN_ERROR"
18
18
  };
19
- function b(o, e = "UNKNOWN_ERROR", n) {
20
- return new m(o, d[e], n);
19
+ function g(o, e = "UNKNOWN_ERROR", n) {
20
+ return new d(o, R[e], n);
21
21
  }
22
- class l {
22
+ class a {
23
23
  constructor(e) {
24
- s(this, "cancelled", !1);
24
+ r(this, "cancelled", !1);
25
25
  this.cancelFn = e;
26
26
  }
27
27
  cancel() {
@@ -31,28 +31,28 @@ class l {
31
31
  return this.cancelled;
32
32
  }
33
33
  }
34
- class R {
34
+ class f {
35
35
  constructor() {
36
- s(this, "listeners", /* @__PURE__ */ new Map());
36
+ r(this, "listeners", /* @__PURE__ */ new Map());
37
37
  }
38
38
  addEventListener(e, n) {
39
39
  this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(n);
40
40
  }
41
41
  removeEventListener(e, n) {
42
- const t = this.listeners.get(e);
43
- if (t) {
44
- const i = t.indexOf(n);
45
- i > -1 && t.splice(i, 1);
42
+ const i = this.listeners.get(e);
43
+ if (i) {
44
+ const t = i.indexOf(n);
45
+ t > -1 && i.splice(t, 1);
46
46
  }
47
47
  }
48
48
  emit(e, n) {
49
- const t = this.listeners.get(e);
50
- t && t.forEach((i) => i(n));
49
+ const i = this.listeners.get(e);
50
+ i && i.forEach((t) => t(n));
51
51
  }
52
52
  }
53
53
  class y {
54
54
  constructor() {
55
- s(this, "emitter", new R());
55
+ r(this, "emitter", new f());
56
56
  }
57
57
  /**
58
58
  * Emit a message to subscribers
@@ -64,46 +64,50 @@ class y {
64
64
  * Subscribe to messages on a specific endpoint
65
65
  */
66
66
  subscribe(e, n) {
67
- const t = (i) => {
68
- n(i);
67
+ const i = (t) => {
68
+ n(t);
69
69
  };
70
- return this.emitter.addEventListener(e, t), new l(() => {
71
- this.emitter.removeEventListener(e, t);
70
+ return this.emitter.addEventListener(e, i), new a(() => {
71
+ this.emitter.removeEventListener(e, i);
72
72
  });
73
73
  }
74
74
  /**
75
75
  * Subscribe to a single message (auto-unsubscribe after first message)
76
76
  */
77
77
  once(e, n) {
78
- const t = this.subscribe(e, (i) => {
79
- t.cancel(), n(i);
78
+ const i = this.subscribe(e, (t) => {
79
+ i.cancel(), n(t);
80
80
  });
81
- return t;
81
+ return i;
82
82
  }
83
83
  }
84
- class f {
84
+ class h {
85
85
  constructor() {
86
- s(this, "receiveChannel", new y());
87
- s(this, "seq", 0);
88
- s(this, "motionListeners", []);
86
+ r(this, "receiveChannel", new y());
87
+ r(this, "seq", 0);
88
+ r(this, "motionListeners", []);
89
+ r(this, "noListenersWarned", !1);
89
90
  }
90
91
  /**
91
92
  * Unified native data receiver - Routes to specific handlers based on message type
92
93
  * Called by native code via: window.aippyRuntime.receiveMessage(message)
93
94
  *
94
95
  * Supports two message formats:
95
- * 1. Motion: { endpoint: "0", payload: { motion: {...} } }
96
+ * 1. Motion: { command: "navigator.motion", endpoint: "0", data: { motion: {...} } }
96
97
  * 2. Tweaks: { "tweakKey": { value: ..., type: ... }, ... }
97
98
  */
98
99
  receiveMessage(e) {
99
- return console.log("📩 [Aippy Runtime] receiveMessage called with:", e), !e || typeof e != "object" ? (console.warn("⚠️ [Aippy Runtime] Invalid message type:", typeof e), Promise.resolve()) : this.isMotionMessage(e) ? (console.log("✅ [Aippy Runtime] Detected MOTION message format, emitting to receive channel"), this.receiveChannel.emit(e), Promise.resolve()) : this.isTweaksMessage(e) ? (console.log("✅ [Aippy Runtime] Detected TWEAKS message format, calling processNativeData"), typeof window < "u" && window.processNativeData && window.processNativeData(e), Promise.resolve()) : (console.warn("⚠️ [Aippy Runtime] Unknown message format:", e), Promise.resolve());
100
+ return console.log("📩 [Aippy Runtime] receiveMessage called with:", e), !e || typeof e != "object" ? (console.warn("⚠️ [Aippy Runtime] Invalid message type:", typeof e), Promise.resolve()) : this.isMotionMessage(e) ? (console.log("✅ [Aippy Runtime] Detected MOTION message format, emitting to receive channel"), this.receiveChannel.emit({
101
+ endpoint: e.endpoint,
102
+ payload: e.data
103
+ }), Promise.resolve()) : this.isTweaksMessage(e) ? (console.log("✅ [Aippy Runtime] Detected TWEAKS message format, calling processNativeData"), typeof window < "u" && window.processNativeData && window.processNativeData(e), Promise.resolve()) : (console.warn("⚠️ [Aippy Runtime] Unknown message format:", e), Promise.resolve());
100
104
  }
101
105
  /**
102
106
  * Check if message is Motion format
103
- * Motion: { endpoint: string, payload: object }
107
+ * Motion: { command: "navigator.motion", endpoint: string, data: object }
104
108
  */
105
109
  isMotionMessage(e) {
106
- return typeof e == "object" && "endpoint" in e && typeof e.endpoint == "string" && "payload" in e && typeof e.payload == "object" && e.payload !== null;
110
+ return typeof e == "object" && "command" in e && e.command === "navigator.motion" && "endpoint" in e && typeof e.endpoint == "string" && "data" in e && typeof e.data == "object" && e.data !== null;
107
111
  }
108
112
  /**
109
113
  * Check if message is Tweaks format
@@ -113,56 +117,57 @@ class f {
113
117
  if (typeof e != "object" || e === null || "endpoint" in e || "payload" in e)
114
118
  return !1;
115
119
  const n = Object.keys(e);
116
- return n.length === 0 ? !1 : n.some((i) => {
117
- const c = e[i];
120
+ return n.length === 0 ? !1 : n.some((t) => {
121
+ const c = e[t];
118
122
  return typeof c == "object" && c !== null && "value" in c;
119
123
  });
120
124
  }
121
125
  /**
122
126
  * Create a subscription to native events
123
- * @param handler - WebKit message handler (e.g., deviceMotionHandler)
124
- * @param subscribePayload - Subscription parameters (e.g., { type: "motion" })
127
+ * @param handler - WebKit message handler (e.g., aippyListener)
128
+ * @param subscribePayload - Subscription parameters (e.g., { command: "navigator.motion", type: "motion" })
125
129
  * @param callback - Callback to handle received data
126
130
  * @returns Cancellable subscription
127
131
  */
128
- createSubscription(e, n, t) {
129
- const i = this.makeSubscriptionMessage(n);
130
- console.log("📨 [Aippy Runtime] Creating subscription with message:", JSON.stringify(i, null, 2));
131
- const c = this.receiveChannel.subscribe(i.endpoint, (r) => {
132
- if (console.log(`📬 [Aippy Runtime] Received data on endpoint ${i.endpoint}:`, r), r.error !== void 0) {
133
- console.warn("⚠️ [Aippy Runtime] Received error, skipping:", r.error);
132
+ createSubscription(e, n, i) {
133
+ const t = (this.seq++).toString(), c = {
134
+ command: n.command,
135
+ parameters: {
136
+ type: n.type,
137
+ action: "subscribe",
138
+ endpoint: t
139
+ }
140
+ };
141
+ console.log("📨 [Aippy Runtime] Creating subscription with message:", JSON.stringify(c, null, 2));
142
+ const l = this.receiveChannel.subscribe(t, (s) => {
143
+ if (console.log(`📬 [Aippy Runtime] Received data on endpoint ${t}:`, s), s.error !== void 0) {
144
+ console.warn("⚠️ [Aippy Runtime] Received error, skipping:", s.error);
134
145
  return;
135
146
  }
136
- t(r);
147
+ i(s);
137
148
  });
138
149
  try {
139
- console.log("📤 [Aippy Runtime] Sending postMessage to native iOS:", i), e.postMessage(i), console.log("✅ [Aippy Runtime] postMessage sent successfully");
140
- } catch (r) {
141
- console.error("❌ [Aippy Runtime] Failed to send postMessage:", r);
150
+ console.log("📤 [Aippy Runtime] Sending postMessage to native iOS:", c), e.postMessage(c), console.log("✅ [Aippy Runtime] postMessage sent successfully");
151
+ } catch (s) {
152
+ console.error("❌ [Aippy Runtime] Failed to send postMessage:", s);
142
153
  }
143
- return new l(() => {
144
- console.log(`🔌 [Aippy Runtime] Unsubscribing from endpoint ${i.endpoint}`), c.cancel();
154
+ return new a(() => {
155
+ console.log(`🔌 [Aippy Runtime] Unsubscribing from endpoint ${t}`), l.cancel();
145
156
  try {
146
- e.postMessage({
147
- endpoint: i.endpoint,
148
- payload: "unsubscribe"
149
- }), console.log("✅ [Aippy Runtime] Unsubscribe message sent");
150
- } catch (r) {
151
- console.error("❌ [Aippy Runtime] Failed to send unsubscribe message:", r);
157
+ const s = {
158
+ command: n.command,
159
+ parameters: {
160
+ type: n.type,
161
+ action: "unsubscribe",
162
+ endpoint: t
163
+ }
164
+ };
165
+ e.postMessage(s), console.log("✅ [Aippy Runtime] Unsubscribe message sent:", s);
166
+ } catch (s) {
167
+ console.error("❌ [Aippy Runtime] Failed to send unsubscribe message:", s);
152
168
  }
153
169
  });
154
170
  }
155
- /**
156
- * Make a subscription message with unique endpoint
157
- */
158
- makeSubscriptionMessage(e) {
159
- return {
160
- endpoint: (this.seq++).toString(),
161
- payload: {
162
- subscribe: e
163
- }
164
- };
165
- }
166
171
  /**
167
172
  * Add motion listener (convenience method)
168
173
  * @param callback - Callback to handle motion data
@@ -173,24 +178,24 @@ class f {
173
178
  const n = window.webkit?.messageHandlers?.aippyListener;
174
179
  if (!n)
175
180
  return console.warn("⚠️ [Aippy Runtime] No webkit message handler found, using fallback mode"), () => {
176
- const i = this.motionListeners.indexOf(e);
177
- i > -1 && this.motionListeners.splice(i, 1);
181
+ const t = this.motionListeners.indexOf(e);
182
+ t > -1 && this.motionListeners.splice(t, 1);
178
183
  };
179
184
  console.log("✅ [Aippy Runtime] Webkit handler found, creating subscription");
180
- const t = this.createSubscription(
185
+ const i = this.createSubscription(
181
186
  n,
182
187
  {
183
188
  command: "navigator.motion",
184
189
  type: "motion"
185
190
  },
186
- (i) => {
187
- console.log("📥 [Aippy Runtime] Received motion data from native:", i), i.motion && e(i.motion);
191
+ (t) => {
192
+ console.log("📥 [Aippy Runtime] Received motion data from native:", t), t.motion && e(t.motion);
188
193
  }
189
194
  );
190
195
  return () => {
191
- console.log("🧹 [Aippy Runtime] Cleaning up motion listener"), t.cancel();
192
- const i = this.motionListeners.indexOf(e);
193
- i > -1 && this.motionListeners.splice(i, 1);
196
+ console.log("🧹 [Aippy Runtime] Cleaning up motion listener"), i.cancel();
197
+ const t = this.motionListeners.indexOf(e);
198
+ t > -1 && this.motionListeners.splice(t, 1);
194
199
  };
195
200
  }
196
201
  /**
@@ -199,22 +204,22 @@ class f {
199
204
  * @param data - Motion data from iOS
200
205
  */
201
206
  broadcastMotionData(e) {
202
- if (console.log(`📢 [Aippy Runtime] broadcastMotionData called, listeners: ${this.motionListeners.length}`), this.motionListeners.length === 0) {
203
- console.warn("⚠️ [Aippy Runtime] No motion listeners to broadcast to");
207
+ if (this.motionListeners.length === 0) {
208
+ this.noListenersWarned || (console.warn("⚠️ [Aippy Runtime] No motion listeners to broadcast to"), this.noListenersWarned = !0);
204
209
  return;
205
210
  }
206
211
  const n = e.motion || e;
207
- console.log("📊 [Aippy Runtime] Broadcasting motion data:", n), this.motionListeners.forEach((t, i) => {
212
+ this.motionListeners.forEach((i) => {
208
213
  try {
209
- console.log(`📲 [Aippy Runtime] Calling listener #${i + 1}`), t(n);
210
- } catch (c) {
211
- console.error(`⚠️ [Aippy Runtime] Error in motion listener #${i + 1}:`, c);
214
+ i(n);
215
+ } catch (t) {
216
+ console.error("⚠️ [Aippy Runtime] Error in motion listener:", t);
212
217
  }
213
218
  });
214
219
  }
215
220
  }
216
- function h(o) {
217
- if (console.log("🎯 [Aippy Runtime] processMotionData called by iOS with data:", o), !o || typeof o != "object") {
221
+ function w(o) {
222
+ if (!o || typeof o != "object") {
218
223
  console.warn("⚠️ [Aippy Runtime] Invalid motion data type:", typeof o);
219
224
  return;
220
225
  }
@@ -222,17 +227,17 @@ function h(o) {
222
227
  console.warn("⚠️ [Aippy Runtime] Motion data missing valid motion field");
223
228
  return;
224
229
  }
225
- console.log("✅ [Aippy Runtime] Motion data validated, broadcasting to listeners"), a.broadcastMotionData(o);
230
+ p.broadcastMotionData(o);
226
231
  }
227
- const a = new f();
228
- typeof window < "u" && (window.aippyRuntime = a, window.processMotionData = h);
232
+ const p = new h();
233
+ typeof window < "u" && (window.aippyRuntime = p, window.processMotionData = w);
229
234
  export {
230
- m as A,
231
- l as C,
232
- d as E,
235
+ d as A,
236
+ a as C,
237
+ R as E,
233
238
  y as R,
234
- f as a,
235
- a as b,
236
- b as c,
237
- h as p
239
+ h as a,
240
+ p as b,
241
+ g as c,
242
+ w as p
238
243
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aippy/runtime",
3
- "version": "0.2.4-dev.6",
3
+ "version": "0.2.4-dev.8",
4
4
  "description": "Aippy Runtime SDK - Runtime SDK for Aippy projects",
5
5
  "private": false,
6
6
  "type": "module",