@aippy/runtime 0.2.3 → 0.2.4-dev.4

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,6 +1,39 @@
1
- import { SensorData } from './types';
1
+ import { SensorData, MotionData, OrientationData } from './types';
2
2
  /**
3
- * Device sensors functionality wrapper
3
+ * Check if device motion is supported
4
+ */
5
+ export declare function isMotionSupported(): boolean;
6
+ /**
7
+ * Check if device orientation is supported
8
+ */
9
+ export declare function isOrientationSupported(): boolean;
10
+ /**
11
+ * Check if native bridge is available
12
+ */
13
+ export declare function hasNativeBridge(): boolean;
14
+ /**
15
+ * Request permission for motion sensors (iOS 13+)
16
+ * @returns Promise<boolean> - true if permission granted
17
+ */
18
+ export declare function requestMotionPermission(): Promise<boolean>;
19
+ /**
20
+ * Watch device motion changes with full motion data
21
+ * Automatically uses native bridge if available, otherwise falls back to Web API
22
+ *
23
+ * @param callback - Function to call with motion data
24
+ * @param autoRequestPermission - Automatically request permission on iOS (default: true, only for Web API)
25
+ * @returns Cleanup function to stop watching
26
+ */
27
+ export declare function watchMotion(callback: (data: MotionData) => void, autoRequestPermission?: boolean): () => void;
28
+ /**
29
+ * Watch device orientation changes
30
+ * @param callback - Function to call with orientation data
31
+ * @returns Cleanup function to stop watching
32
+ */
33
+ export declare function watchOrientation(callback: (data: OrientationData) => void): () => void;
34
+ /**
35
+ * Legacy SensorsAPI class for backward compatibility
36
+ * @deprecated Use watchMotion() and watchOrientation() functions instead
4
37
  */
5
38
  export declare class SensorsAPI {
6
39
  /**
@@ -17,6 +50,7 @@ export declare class SensorsAPI {
17
50
  getOrientation(): Promise<SensorData>;
18
51
  /**
19
52
  * Watch device orientation changes
53
+ * @deprecated Use watchOrientation() function instead
20
54
  */
21
55
  watchOrientation(callback: (data: SensorData) => void): () => void;
22
56
  /**
@@ -25,6 +59,7 @@ export declare class SensorsAPI {
25
59
  getMotion(): Promise<SensorData>;
26
60
  /**
27
61
  * Watch device motion changes
62
+ * @deprecated Use watchMotion() function instead
28
63
  */
29
64
  watchMotion(callback: (data: SensorData) => void): () => void;
30
65
  /**
@@ -33,6 +68,7 @@ export declare class SensorsAPI {
33
68
  requestPermission(): Promise<boolean>;
34
69
  }
35
70
  /**
36
- * Sensors API instance
71
+ * Sensors API instance (for backward compatibility)
72
+ * @deprecated Use watchMotion() and watchOrientation() functions instead
37
73
  */
38
74
  export declare const sensors: SensorsAPI;
@@ -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-Boz38wSz.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,227 @@
1
+ var l = Object.defineProperty;
2
+ var u = (o, e, t) => e in o ? l(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var s = (o, e, t) => u(o, typeof e != "symbol" ? e + "" : e, t);
4
+ class d extends Error {
5
+ constructor(t, n = "AIPPY_ERROR", i) {
6
+ super(t);
7
+ s(this, "code");
8
+ s(this, "context");
9
+ this.name = "AippyRuntimeError", this.code = n, this.context = i;
10
+ }
11
+ }
12
+ const f = {
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 E(o, e = "UNKNOWN_ERROR", t) {
20
+ return new d(o, f[e], t);
21
+ }
22
+ class a {
23
+ constructor(e) {
24
+ s(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 h {
35
+ constructor() {
36
+ s(this, "listeners", /* @__PURE__ */ new Map());
37
+ }
38
+ addEventListener(e, t) {
39
+ this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(t);
40
+ }
41
+ removeEventListener(e, t) {
42
+ const n = this.listeners.get(e);
43
+ if (n) {
44
+ const i = n.indexOf(t);
45
+ i > -1 && n.splice(i, 1);
46
+ }
47
+ }
48
+ emit(e, t) {
49
+ const n = this.listeners.get(e);
50
+ n && n.forEach((i) => i(t));
51
+ }
52
+ }
53
+ class m {
54
+ constructor() {
55
+ s(this, "emitter", new h());
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, t) {
67
+ const n = (i) => {
68
+ t(i);
69
+ };
70
+ return this.emitter.addEventListener(e, n), new a(() => {
71
+ this.emitter.removeEventListener(e, n);
72
+ });
73
+ }
74
+ /**
75
+ * Subscribe to a single message (auto-unsubscribe after first message)
76
+ */
77
+ once(e, t) {
78
+ const n = this.subscribe(e, (i) => {
79
+ n.cancel(), t(i);
80
+ });
81
+ return n;
82
+ }
83
+ }
84
+ class R {
85
+ constructor() {
86
+ s(this, "receiveChannel", new m());
87
+ s(this, "seq", 0);
88
+ s(this, "motionListeners", []);
89
+ }
90
+ /**
91
+ * Unified native data receiver - Routes to specific handlers based on message type
92
+ * Called by native code via: window.aippyRuntime.receiveMessage(message)
93
+ *
94
+ * Supports two message formats:
95
+ * 1. Motion: { endpoint: "0", payload: { motion: {...} } }
96
+ * 2. Tweaks: { "tweakKey": { value: ..., type: ... }, ... }
97
+ */
98
+ receiveMessage(e) {
99
+ return !e || typeof e != "object" ? (console.warn("⚠️ [Aippy Runtime] Invalid message type:", typeof e), Promise.resolve()) : this.isMotionMessage(e) ? (this.receiveChannel.emit(e), Promise.resolve()) : this.isTweaksMessage(e) ? (typeof window < "u" && window.processNativeData && window.processNativeData(e), Promise.resolve()) : (console.warn("⚠️ [Aippy Runtime] Unknown message format:", e), Promise.resolve());
100
+ }
101
+ /**
102
+ * Check if message is Motion format
103
+ * Motion: { endpoint: string, payload: object }
104
+ */
105
+ isMotionMessage(e) {
106
+ return typeof e == "object" && "endpoint" in e && typeof e.endpoint == "string" && "payload" in e && typeof e.payload == "object" && e.payload !== null;
107
+ }
108
+ /**
109
+ * Check if message is Tweaks format
110
+ * Tweaks: { "key": { value: any, type?: string, ... }, ... }
111
+ */
112
+ isTweaksMessage(e) {
113
+ if (typeof e != "object" || e === null || "endpoint" in e || "payload" in e)
114
+ return !1;
115
+ const t = Object.keys(e);
116
+ return t.length === 0 ? !1 : t.some((i) => {
117
+ const r = e[i];
118
+ return typeof r == "object" && r !== null && "value" in r;
119
+ });
120
+ }
121
+ /**
122
+ * Create a subscription to native events
123
+ * @param handler - WebKit message handler (e.g., deviceMotionHandler)
124
+ * @param subscribePayload - Subscription parameters (e.g., { type: "motion" })
125
+ * @param callback - Callback to handle received data
126
+ * @returns Cancellable subscription
127
+ */
128
+ createSubscription(e, t, n) {
129
+ const i = this.makeSubscriptionMessage(t), r = this.receiveChannel.subscribe(i.endpoint, (c) => {
130
+ c.error === void 0 && n(c);
131
+ });
132
+ try {
133
+ e.postMessage(i);
134
+ } catch {
135
+ }
136
+ return new a(() => {
137
+ r.cancel();
138
+ try {
139
+ e.postMessage({
140
+ endpoint: i.endpoint,
141
+ payload: "unsubscribe"
142
+ });
143
+ } catch {
144
+ }
145
+ });
146
+ }
147
+ /**
148
+ * Make a subscription message with unique endpoint
149
+ */
150
+ makeSubscriptionMessage(e) {
151
+ return {
152
+ endpoint: (this.seq++).toString(),
153
+ payload: {
154
+ subscribe: e
155
+ }
156
+ };
157
+ }
158
+ /**
159
+ * Add motion listener (convenience method)
160
+ * @param callback - Callback to handle motion data
161
+ * @returns Cleanup function
162
+ */
163
+ addMotionListener(e) {
164
+ this.motionListeners.push(e);
165
+ const t = window.webkit?.messageHandlers?.aippyListener;
166
+ if (!t)
167
+ return () => {
168
+ const i = this.motionListeners.indexOf(e);
169
+ i > -1 && this.motionListeners.splice(i, 1);
170
+ };
171
+ const n = this.createSubscription(
172
+ t,
173
+ {
174
+ command: "navigator.motion",
175
+ type: "motion"
176
+ },
177
+ (i) => {
178
+ i.motion && e(i.motion);
179
+ }
180
+ );
181
+ return () => {
182
+ n.cancel();
183
+ const i = this.motionListeners.indexOf(e);
184
+ i > -1 && this.motionListeners.splice(i, 1);
185
+ };
186
+ }
187
+ /**
188
+ * Broadcast motion data to all registered listeners
189
+ * Called by processMotionData when iOS sends data directly
190
+ * @param data - Motion data from iOS
191
+ */
192
+ broadcastMotionData(e) {
193
+ if (this.motionListeners.length === 0)
194
+ return;
195
+ const t = e.motion || e;
196
+ this.motionListeners.forEach((n) => {
197
+ try {
198
+ n(t);
199
+ } catch (i) {
200
+ console.error("⚠️ [Aippy Runtime] Error in motion listener:", i);
201
+ }
202
+ });
203
+ }
204
+ }
205
+ function y(o) {
206
+ if (!o || typeof o != "object") {
207
+ console.warn("⚠️ [Aippy Runtime] Invalid motion data type:", typeof o);
208
+ return;
209
+ }
210
+ if (!("motion" in o) || typeof o.motion != "object") {
211
+ console.warn("⚠️ [Aippy Runtime] Motion data missing valid motion field");
212
+ return;
213
+ }
214
+ p.broadcastMotionData(o);
215
+ }
216
+ const p = new R();
217
+ typeof window < "u" && (window.aippyRuntime = p, window.processMotionData = y);
218
+ export {
219
+ d as A,
220
+ a as C,
221
+ f as E,
222
+ m as R,
223
+ R as a,
224
+ p as b,
225
+ E as c,
226
+ y as p
227
+ };
@@ -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.4",
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
- };