@aippy/runtime 0.2.3 → 0.2.4-dev.3

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,54 @@
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 r, VERSION as t, 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 } from "../runtime-DOnodF_1.js";
3
+ import { CameraAPI as E, FileSystemAPI as C, GeolocationAPI as R, SensorsAPI as x, camera as P, fileSystem as I, geolocation as M, hasNativeBridge as g, isMotionSupported as y, isOrientationSupported as O, requestMotionPermission as b, sensors as v, vibrate as h, watchMotion as w, watchOrientation as D } from "../device/index.js";
4
+ import { c as N, a as T, P as V, b as _, p as k, d as G } from "../pwa-8DGmPqLV.js";
5
+ import { a as U, b as q } from "../useTweaks-QxMRmg7i.js";
6
+ import { c as K, a as L, b as W, i as j, p as z, u as J } from "../useAudioContext-CNQQSTab.js";
7
+ import { reportScore as X, sendEvent as Y, updateScore as Z } 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,
9
+ m as AippyRuntime,
10
+ c as AippyRuntimeError,
11
+ E as CameraAPI,
12
+ d as Cancellable,
13
+ o as DEFAULT_CONFIG,
14
+ f as ERROR_CODES,
15
+ C as FileSystemAPI,
16
+ R as GeolocationAPI,
17
+ N as PWAUtils,
18
+ T as PerformanceMonitor,
19
+ V as PlatformDetector,
20
+ u as ReceiveChannel,
21
+ r as SDK_NAME,
22
+ x as SensorsAPI,
20
23
  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,
24
+ l as aippyRuntime,
25
+ U as aippyTweaks,
26
+ q as aippyTweaksRuntime,
27
+ P as camera,
28
+ A as createError,
29
+ K as createHiddenMediaElement,
30
+ L as createHiddenVideoElement,
31
+ I as fileSystem,
32
+ M as geolocation,
33
+ i as getConfigFromEnv,
34
+ s as getVersionInfo,
35
+ g as hasNativeBridge,
36
+ W as isIOSDevice,
37
+ j as isMediaStreamAudioSupported,
38
+ y as isMotionSupported,
39
+ O 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
+ z as patchAudioContext,
42
+ _ as performanceMonitor,
43
+ k as platform,
44
+ G as pwa,
45
+ X as reportScore,
46
+ b as requestMotionPermission,
47
+ Y as sendEvent,
48
+ v as sensors,
49
+ Z as updateScore,
50
+ J as useAudioContext,
51
+ h as vibrate,
52
+ w as watchMotion,
53
+ D as watchOrientation
44
54
  };
@@ -0,0 +1,165 @@
1
+ var l = Object.defineProperty;
2
+ var p = (i, e, t) => e in i ? l(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var r = (i, e, t) => p(i, typeof e != "symbol" ? e + "" : e, t);
4
+ class u extends Error {
5
+ constructor(t, s = "AIPPY_ERROR", n) {
6
+ super(t);
7
+ r(this, "code");
8
+ r(this, "context");
9
+ this.name = "AippyRuntimeError", this.code = s, this.context = n;
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 O(i, e = "UNKNOWN_ERROR", t) {
20
+ return new u(i, R[e], t);
21
+ }
22
+ class o {
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 d {
35
+ constructor() {
36
+ r(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 s = this.listeners.get(e);
43
+ if (s) {
44
+ const n = s.indexOf(t);
45
+ n > -1 && s.splice(n, 1);
46
+ }
47
+ }
48
+ emit(e, t) {
49
+ const s = this.listeners.get(e);
50
+ s && s.forEach((n) => n(t));
51
+ }
52
+ }
53
+ class h {
54
+ constructor() {
55
+ r(this, "emitter", new d());
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 s = (n) => {
68
+ t(n);
69
+ };
70
+ return this.emitter.addEventListener(e, s), new o(() => {
71
+ this.emitter.removeEventListener(e, s);
72
+ });
73
+ }
74
+ /**
75
+ * Subscribe to a single message (auto-unsubscribe after first message)
76
+ */
77
+ once(e, t) {
78
+ const s = this.subscribe(e, (n) => {
79
+ s.cancel(), t(n);
80
+ });
81
+ return s;
82
+ }
83
+ }
84
+ class E {
85
+ constructor() {
86
+ r(this, "receiveChannel", new h());
87
+ r(this, "seq", 0);
88
+ }
89
+ /**
90
+ * Receive message from native layer
91
+ * Called by native code via: window.aippyRuntime.receiveMessage(message)
92
+ */
93
+ receiveMessage(e) {
94
+ return this.receiveChannel.emit(e), Promise.resolve();
95
+ }
96
+ /**
97
+ * Create a subscription to native events
98
+ * @param handler - WebKit message handler (e.g., deviceMotionHandler)
99
+ * @param subscribePayload - Subscription parameters (e.g., { type: "motion" })
100
+ * @param callback - Callback to handle received data
101
+ * @returns Cancellable subscription
102
+ */
103
+ createSubscription(e, t, s) {
104
+ const n = this.makeSubscriptionMessage(t), a = this.receiveChannel.subscribe(n.endpoint, (c) => {
105
+ c.error === void 0 && s(c);
106
+ });
107
+ try {
108
+ e.postMessage(n);
109
+ } catch {
110
+ }
111
+ return new o(() => {
112
+ a.cancel();
113
+ try {
114
+ e.postMessage({
115
+ endpoint: n.endpoint,
116
+ payload: "unsubscribe"
117
+ });
118
+ } catch {
119
+ }
120
+ });
121
+ }
122
+ /**
123
+ * Make a subscription message with unique endpoint
124
+ */
125
+ makeSubscriptionMessage(e) {
126
+ return {
127
+ endpoint: (this.seq++).toString(),
128
+ payload: {
129
+ subscribe: e
130
+ }
131
+ };
132
+ }
133
+ /**
134
+ * Add motion listener (convenience method)
135
+ * @param callback - Callback to handle motion data
136
+ * @returns Cleanup function
137
+ */
138
+ addMotionListener(e) {
139
+ const t = window.webkit?.messageHandlers?.deviceMotionHandler;
140
+ if (!t)
141
+ return () => {
142
+ };
143
+ const s = this.createSubscription(
144
+ t,
145
+ { type: "motion" },
146
+ (n) => {
147
+ n.motion && e(n.motion);
148
+ }
149
+ );
150
+ return () => {
151
+ s.cancel();
152
+ };
153
+ }
154
+ }
155
+ const m = new E();
156
+ typeof window < "u" && (window.aippyRuntime = m);
157
+ export {
158
+ u as A,
159
+ o as C,
160
+ R as E,
161
+ h as R,
162
+ E as a,
163
+ m as b,
164
+ O as c
165
+ };
@@ -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.3",
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
- };