@aippy/runtime 0.2.3 → 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.
@@ -58,6 +58,44 @@ export interface SensorData {
58
58
  /** Timestamp */
59
59
  timestamp: number;
60
60
  }
61
+ export interface MotionData {
62
+ /** Gravity vector (normalized, -1 to 1) */
63
+ gravity: {
64
+ x: number;
65
+ y: number;
66
+ z: number;
67
+ };
68
+ /** Linear acceleration (m/s²) */
69
+ acceleration: {
70
+ x: number;
71
+ y: number;
72
+ z: number;
73
+ };
74
+ /** Acceleration including gravity (m/s²) */
75
+ accelerationIncludingGravity: {
76
+ x: number;
77
+ y: number;
78
+ z: number;
79
+ };
80
+ /** Rotation rate (deg/s) */
81
+ rotation: {
82
+ alpha: number;
83
+ beta: number;
84
+ gamma: number;
85
+ };
86
+ /** Timestamp */
87
+ timestamp: number;
88
+ }
89
+ export interface OrientationData {
90
+ /** Rotation around Z axis (0-360°) */
91
+ alpha: number;
92
+ /** Rotation around X axis (-180 to 180°) */
93
+ beta: number;
94
+ /** Rotation around Y axis (-90 to 90°) */
95
+ gamma: number;
96
+ /** Timestamp */
97
+ timestamp: number;
98
+ }
61
99
  export interface FileSystemOptions {
62
100
  /** File types to accept */
63
101
  accept?: string[];
@@ -1,44 +1,55 @@
1
- import { DEFAULT_CONFIG as r, SDK_NAME as a, VERSION as t, getConfigFromEnv as s, getVersionInfo as i, mergeConfig as n } from "../core/index.js";
2
- import { A as m, E as c, c as f } from "../errors-CDEBaBxB.js";
3
- import { CameraAPI as A, FileSystemAPI as E, GeolocationAPI as S, SensorsAPI as l, camera as u, fileSystem as x, geolocation as I, sensors as P, vibrate as C } from "../device/index.js";
4
- import { c as R, a as y, P as D, b as M, p as O, d as b } from "../pwa-8DGmPqLV.js";
5
- import { a as F, b as w } from "../useTweaks-QxMRmg7i.js";
6
- import { c as T, a as V, i as _, b as k, p as G, u as H } from "../useAudioContext-BKgy28A1.js";
7
- import { reportScore as h, sendEvent as K, updateScore as L } from "../leaderboard/index.js";
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-DjBdOttl.js";
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
+ import { c as T, a as V, P as _, b as k, p as G, d as H } from "../pwa-8DGmPqLV.js";
5
+ import { a as q, b as B } from "../useTweaks-QxMRmg7i.js";
6
+ import { c as L, a as W, b as j, i as z, p as J, u as Q } from "../useAudioContext-CNQQSTab.js";
7
+ import { reportScore as Y, sendEvent as Z, updateScore as $ } from "../leaderboard/index.js";
8
8
  export {
9
- m as AippyRuntimeError,
10
- A as CameraAPI,
11
- r as DEFAULT_CONFIG,
12
- c as ERROR_CODES,
13
- E as FileSystemAPI,
14
- S as GeolocationAPI,
15
- R as PWAUtils,
16
- y as PerformanceMonitor,
17
- D as PlatformDetector,
18
- a as SDK_NAME,
19
- l as SensorsAPI,
20
- t as VERSION,
21
- F as aippyTweaks,
22
- w as aippyTweaksRuntime,
23
- u as camera,
24
- f as createError,
25
- T as createHiddenMediaElement,
26
- V as createHiddenVideoElement,
27
- x as fileSystem,
28
- I as geolocation,
29
- s as getConfigFromEnv,
30
- i as getVersionInfo,
31
- _ as isIOSDevice,
32
- k as isMediaStreamAudioSupported,
9
+ m as AippyRuntime,
10
+ c as AippyRuntimeError,
11
+ C as CameraAPI,
12
+ d as Cancellable,
13
+ o as DEFAULT_CONFIG,
14
+ f as ERROR_CODES,
15
+ R as FileSystemAPI,
16
+ x as GeolocationAPI,
17
+ T as PWAUtils,
18
+ V as PerformanceMonitor,
19
+ _ as PlatformDetector,
20
+ u as ReceiveChannel,
21
+ t as SDK_NAME,
22
+ M as SensorsAPI,
23
+ r as VERSION,
24
+ l as aippyRuntime,
25
+ q as aippyTweaks,
26
+ B as aippyTweaksRuntime,
27
+ P as camera,
28
+ A as createError,
29
+ L as createHiddenMediaElement,
30
+ W as createHiddenVideoElement,
31
+ I as fileSystem,
32
+ g as geolocation,
33
+ i as getConfigFromEnv,
34
+ s as getVersionInfo,
35
+ y as hasNativeBridge,
36
+ j as isIOSDevice,
37
+ z as isMediaStreamAudioSupported,
38
+ O as isMotionSupported,
39
+ b as isOrientationSupported,
33
40
  n as mergeConfig,
34
- G as patchAudioContext,
35
- M as performanceMonitor,
36
- O as platform,
37
- b as pwa,
38
- h as reportScore,
39
- K as sendEvent,
40
- P as sensors,
41
- L as updateScore,
42
- H as useAudioContext,
43
- C as vibrate
41
+ J as patchAudioContext,
42
+ k as performanceMonitor,
43
+ G as platform,
44
+ S as processMotionData,
45
+ H as pwa,
46
+ Y as reportScore,
47
+ v as requestMotionPermission,
48
+ Z as sendEvent,
49
+ D as sensors,
50
+ $ as updateScore,
51
+ Q as useAudioContext,
52
+ h as vibrate,
53
+ w as watchMotion,
54
+ F as watchOrientation
44
55
  };
@@ -0,0 +1,243 @@
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
+ super(n);
7
+ r(this, "code");
8
+ r(this, "context");
9
+ this.name = "AippyRuntimeError", this.code = i, this.context = t;
10
+ }
11
+ }
12
+ const R = {
13
+ NOT_SUPPORTED: "NOT_SUPPORTED",
14
+ PERMISSION_DENIED: "PERMISSION_DENIED",
15
+ INVALID_CONFIG: "INVALID_CONFIG",
16
+ NETWORK_ERROR: "NETWORK_ERROR",
17
+ UNKNOWN_ERROR: "UNKNOWN_ERROR"
18
+ };
19
+ function g(o, e = "UNKNOWN_ERROR", n) {
20
+ return new d(o, R[e], n);
21
+ }
22
+ class a {
23
+ constructor(e) {
24
+ r(this, "cancelled", !1);
25
+ this.cancelFn = e;
26
+ }
27
+ cancel() {
28
+ this.cancelled || (this.cancelled = !0, this.cancelFn?.());
29
+ }
30
+ get isCancelled() {
31
+ return this.cancelled;
32
+ }
33
+ }
34
+ class f {
35
+ constructor() {
36
+ r(this, "listeners", /* @__PURE__ */ new Map());
37
+ }
38
+ addEventListener(e, n) {
39
+ this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(n);
40
+ }
41
+ removeEventListener(e, n) {
42
+ const i = this.listeners.get(e);
43
+ if (i) {
44
+ const t = i.indexOf(n);
45
+ t > -1 && i.splice(t, 1);
46
+ }
47
+ }
48
+ emit(e, n) {
49
+ const i = this.listeners.get(e);
50
+ i && i.forEach((t) => t(n));
51
+ }
52
+ }
53
+ class y {
54
+ constructor() {
55
+ r(this, "emitter", new f());
56
+ }
57
+ /**
58
+ * Emit a message to subscribers
59
+ */
60
+ emit(e) {
61
+ this.emitter.emit(e.endpoint, e.payload);
62
+ }
63
+ /**
64
+ * Subscribe to messages on a specific endpoint
65
+ */
66
+ subscribe(e, n) {
67
+ const i = (t) => {
68
+ n(t);
69
+ };
70
+ return this.emitter.addEventListener(e, i), new a(() => {
71
+ this.emitter.removeEventListener(e, i);
72
+ });
73
+ }
74
+ /**
75
+ * Subscribe to a single message (auto-unsubscribe after first message)
76
+ */
77
+ once(e, n) {
78
+ const i = this.subscribe(e, (t) => {
79
+ i.cancel(), n(t);
80
+ });
81
+ return i;
82
+ }
83
+ }
84
+ class h {
85
+ constructor() {
86
+ r(this, "receiveChannel", new y());
87
+ r(this, "seq", 0);
88
+ r(this, "motionListeners", []);
89
+ r(this, "noListenersWarned", !1);
90
+ }
91
+ /**
92
+ * Unified native data receiver - Routes to specific handlers based on message type
93
+ * Called by native code via: window.aippyRuntime.receiveMessage(message)
94
+ *
95
+ * Supports two message formats:
96
+ * 1. Motion: { command: "navigator.motion", endpoint: "0", data: { motion: {...} } }
97
+ * 2. Tweaks: { "tweakKey": { value: ..., type: ... }, ... }
98
+ */
99
+ receiveMessage(e) {
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());
104
+ }
105
+ /**
106
+ * Check if message is Motion format
107
+ * Motion: { command: "navigator.motion", endpoint: string, data: object }
108
+ */
109
+ isMotionMessage(e) {
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;
111
+ }
112
+ /**
113
+ * Check if message is Tweaks format
114
+ * Tweaks: { "key": { value: any, type?: string, ... }, ... }
115
+ */
116
+ isTweaksMessage(e) {
117
+ if (typeof e != "object" || e === null || "endpoint" in e || "payload" in e)
118
+ return !1;
119
+ const n = Object.keys(e);
120
+ return n.length === 0 ? !1 : n.some((t) => {
121
+ const c = e[t];
122
+ return typeof c == "object" && c !== null && "value" in c;
123
+ });
124
+ }
125
+ /**
126
+ * Create a subscription to native events
127
+ * @param handler - WebKit message handler (e.g., aippyListener)
128
+ * @param subscribePayload - Subscription parameters (e.g., { command: "navigator.motion", type: "motion" })
129
+ * @param callback - Callback to handle received data
130
+ * @returns Cancellable subscription
131
+ */
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);
145
+ return;
146
+ }
147
+ i(s);
148
+ });
149
+ try {
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);
153
+ }
154
+ return new a(() => {
155
+ console.log(`🔌 [Aippy Runtime] Unsubscribing from endpoint ${t}`), l.cancel();
156
+ try {
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);
168
+ }
169
+ });
170
+ }
171
+ /**
172
+ * Add motion listener (convenience method)
173
+ * @param callback - Callback to handle motion data
174
+ * @returns Cleanup function
175
+ */
176
+ addMotionListener(e) {
177
+ console.log("🎬 [Aippy Runtime] addMotionListener called"), this.motionListeners.push(e), console.log(`📝 [Aippy Runtime] Total motion listeners: ${this.motionListeners.length}`);
178
+ const n = window.webkit?.messageHandlers?.aippyListener;
179
+ if (!n)
180
+ return console.warn("⚠️ [Aippy Runtime] No webkit message handler found, using fallback mode"), () => {
181
+ const t = this.motionListeners.indexOf(e);
182
+ t > -1 && this.motionListeners.splice(t, 1);
183
+ };
184
+ console.log("✅ [Aippy Runtime] Webkit handler found, creating subscription");
185
+ const i = this.createSubscription(
186
+ n,
187
+ {
188
+ command: "navigator.motion",
189
+ type: "motion"
190
+ },
191
+ (t) => {
192
+ console.log("📥 [Aippy Runtime] Received motion data from native:", t), t.motion && e(t.motion);
193
+ }
194
+ );
195
+ return () => {
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);
199
+ };
200
+ }
201
+ /**
202
+ * Broadcast motion data to all registered listeners
203
+ * Called by processMotionData when iOS sends data directly
204
+ * @param data - Motion data from iOS
205
+ */
206
+ broadcastMotionData(e) {
207
+ if (this.motionListeners.length === 0) {
208
+ this.noListenersWarned || (console.warn("⚠️ [Aippy Runtime] No motion listeners to broadcast to"), this.noListenersWarned = !0);
209
+ return;
210
+ }
211
+ const n = e.motion || e;
212
+ this.motionListeners.forEach((i) => {
213
+ try {
214
+ i(n);
215
+ } catch (t) {
216
+ console.error("⚠️ [Aippy Runtime] Error in motion listener:", t);
217
+ }
218
+ });
219
+ }
220
+ }
221
+ function w(o) {
222
+ if (!o || typeof o != "object") {
223
+ console.warn("⚠️ [Aippy Runtime] Invalid motion data type:", typeof o);
224
+ return;
225
+ }
226
+ if (!("motion" in o) || typeof o.motion != "object") {
227
+ console.warn("⚠️ [Aippy Runtime] Motion data missing valid motion field");
228
+ return;
229
+ }
230
+ p.broadcastMotionData(o);
231
+ }
232
+ const p = new h();
233
+ typeof window < "u" && (window.aippyRuntime = p, window.processMotionData = w);
234
+ export {
235
+ d as A,
236
+ a as C,
237
+ R as E,
238
+ y as R,
239
+ h as a,
240
+ p as b,
241
+ g as c,
242
+ w as p
243
+ };
@@ -215,9 +215,9 @@ function O(e = {}) {
215
215
  }
216
216
  export {
217
217
  C as a,
218
- P as b,
218
+ E as b,
219
219
  v as c,
220
- E as i,
220
+ P as i,
221
221
  S as p,
222
222
  O as u
223
223
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aippy/runtime",
3
- "version": "0.2.3",
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",
@@ -44,30 +44,6 @@
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
- },
71
47
  "keywords": [
72
48
  "aippy",
73
49
  "runtime",
@@ -106,5 +82,28 @@
106
82
  "engines": {
107
83
  "node": ">=20.0.0",
108
84
  "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')\""
109
108
  }
110
- }
109
+ }
@@ -1,26 +0,0 @@
1
- var e = Object.defineProperty;
2
- var o = (E, R, N) => R in E ? e(E, R, { enumerable: !0, configurable: !0, writable: !0, value: N }) : E[R] = N;
3
- var O = (E, R, N) => o(E, typeof R != "symbol" ? R + "" : R, N);
4
- class I extends Error {
5
- constructor(N, r = "AIPPY_ERROR", t) {
6
- super(N);
7
- O(this, "code");
8
- O(this, "context");
9
- this.name = "AippyRuntimeError", this.code = r, this.context = t;
10
- }
11
- }
12
- const _ = {
13
- NOT_SUPPORTED: "NOT_SUPPORTED",
14
- PERMISSION_DENIED: "PERMISSION_DENIED",
15
- INVALID_CONFIG: "INVALID_CONFIG",
16
- NETWORK_ERROR: "NETWORK_ERROR",
17
- UNKNOWN_ERROR: "UNKNOWN_ERROR"
18
- };
19
- function s(E, R = "UNKNOWN_ERROR", N) {
20
- return new I(E, _[R], N);
21
- }
22
- export {
23
- I as A,
24
- _ as E,
25
- s as c
26
- };