@aippy/runtime 0.2.6 โ†’ 0.2.7-dev.1

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.
Files changed (44) hide show
  1. package/README.md +34 -0
  2. package/dist/ai/config/bridge.d.ts +23 -0
  3. package/dist/ai/config/helper.d.ts +43 -0
  4. package/dist/ai/config/index.d.ts +11 -0
  5. package/dist/ai/config/parser.d.ts +60 -0
  6. package/dist/ai/config/types.d.ts +80 -0
  7. package/dist/ai/errors.d.ts +25 -0
  8. package/dist/ai/index.d.ts +46 -0
  9. package/dist/ai/index.js +25 -0
  10. package/dist/ai/openai/index.d.ts +11 -0
  11. package/dist/ai/openai/provider.d.ts +51 -0
  12. package/dist/ai/shared/config.d.ts +54 -0
  13. package/dist/ai/shared/fetch.d.ts +28 -0
  14. package/dist/ai/shared/index.d.ts +6 -0
  15. package/dist/ai/ui/config.d.ts +25 -0
  16. package/dist/ai/ui/endpoints.d.ts +12 -0
  17. package/dist/ai/ui/index.d.ts +13 -0
  18. package/dist/ai/ui/types.d.ts +21 -0
  19. package/dist/ai.d.ts +2 -0
  20. package/dist/bridge-D2d8hnO_.js +395 -0
  21. package/dist/container-message-DGrno17o.js +31 -0
  22. package/dist/core/container-message.d.ts +81 -0
  23. package/dist/core/index.d.ts +1 -0
  24. package/dist/core/index.js +21 -18
  25. package/dist/core/native-bridge.d.ts +9 -0
  26. package/dist/device/index.js +121 -129
  27. package/dist/device/sensors.d.ts +5 -1
  28. package/dist/errors-CDEBaBxB.js +26 -0
  29. package/dist/helper-CRGxnlsu.js +261 -0
  30. package/dist/index/index.js +113 -52
  31. package/dist/index.d.ts +2 -0
  32. package/dist/native-bridge-BnvipFJc.js +6 -0
  33. package/dist/{runtime-DjBdOttl.js โ†’ runtime-CmoG3v2m.js} +55 -76
  34. package/dist/user/api.d.ts +9 -0
  35. package/dist/user/bridge.d.ts +162 -0
  36. package/dist/user/config.d.ts +21 -0
  37. package/dist/user/hooks.d.ts +74 -0
  38. package/dist/user/index.d.ts +12 -0
  39. package/dist/user/index.js +38 -0
  40. package/dist/user/types.d.ts +113 -0
  41. package/dist/user/userSessionInfo.d.ts +6 -0
  42. package/dist/user.d.ts +2 -0
  43. package/dist/userSessionInfo-SbuNZ7JR.js +229 -0
  44. package/package.json +50 -36
@@ -0,0 +1,261 @@
1
+ import { createOpenAICompatible as l } from "@ai-sdk/openai-compatible";
2
+ import "react";
3
+ import { h as d } from "./bridge-D2d8hnO_.js";
4
+ import { DefaultChatTransport as y, AISDKError as i } from "ai";
5
+ import { s as u } from "./container-message-DGrno17o.js";
6
+ const m = "https://api.aippy.dev", h = `${m}/api/aisdk/v1/`, A = `${m}/api/aisdk/v1/ui/`, b = "gpt-5-nano", E = "";
7
+ function w(r = {}) {
8
+ return {
9
+ baseUrl: r.baseUrl ?? h
10
+ };
11
+ }
12
+ function I(r = {}) {
13
+ return {
14
+ baseUrl: r.baseUrl ?? A
15
+ };
16
+ }
17
+ function v(r, e) {
18
+ const n = r.endsWith("/") ? r : `${r}/`, t = e.startsWith("/") ? e.slice(1) : e;
19
+ return new URL(t, n).href;
20
+ }
21
+ function c() {
22
+ return async (r, e) => {
23
+ const n = await d(), t = new Headers(e?.headers);
24
+ return t.set("Authorization", `Bearer ${n}`), globalThis.fetch(r, { ...e, headers: t });
25
+ };
26
+ }
27
+ const _ = [
28
+ "gpt-image-1",
29
+ "gpt-image-1-mini",
30
+ "gpt-image-1.5"
31
+ ];
32
+ function C(r) {
33
+ try {
34
+ const e = JSON.parse(r);
35
+ if (e.model && _.some((n) => e.model.startsWith(n))) {
36
+ const { response_format: n, ...t } = e;
37
+ return JSON.stringify(t);
38
+ }
39
+ } catch {
40
+ }
41
+ return r;
42
+ }
43
+ function j(r = {}) {
44
+ const { baseUrl: e } = w(r), n = c();
45
+ return l({
46
+ name: "aippy",
47
+ baseURL: e,
48
+ fetch: async (a, s) => a.toString().includes("/images/generations") && s?.method?.toUpperCase() === "POST" && s?.body ? n(a, {
49
+ ...s,
50
+ body: C(s.body)
51
+ }) : n(a, s)
52
+ });
53
+ }
54
+ const S = "/chat";
55
+ function F(r = {}) {
56
+ const { baseUrl: e } = I(r), n = r.model ?? b, t = r.system ?? E, a = r.api ?? v(e, S), s = { model: n, system: t }, o = c();
57
+ return {
58
+ transport: new y({
59
+ api: a,
60
+ body: s,
61
+ // Ensure token is fetched fresh for every request
62
+ fetch: o
63
+ })
64
+ };
65
+ }
66
+ function L(r, e) {
67
+ const n = r.status;
68
+ if (e && typeof e == "object" && "error" in e) {
69
+ const t = e, a = t.error.code, s = a != null ? `AippyAIError_${a}` : `AippyAIError_${n}`, o = e;
70
+ return "appMessage" in o && o.appMessage !== void 0 ? u(o.appMessage) : "containerErrorData" in o && o.containerErrorData !== void 0 && u(o.containerErrorData), new i({
71
+ name: s,
72
+ message: t.error.message,
73
+ cause: {
74
+ type: t.error.type ?? void 0,
75
+ param: t.error.param ?? void 0,
76
+ status: n
77
+ }
78
+ });
79
+ }
80
+ if (e && typeof e == "object" && e !== null) {
81
+ const t = e;
82
+ "appMessage" in t && t.appMessage !== void 0 ? u(t.appMessage) : "containerErrorData" in t && t.containerErrorData !== void 0 && u(t.containerErrorData);
83
+ }
84
+ return new i({
85
+ name: `AippyAIError_${n}`,
86
+ message: `Request failed with status ${n}`,
87
+ cause: { status: n }
88
+ });
89
+ }
90
+ function x() {
91
+ return new i({
92
+ name: "AippyAIError_MISSING_TOKEN",
93
+ message: "User token is required. Ensure user credentials are available via initUserBridge()."
94
+ });
95
+ }
96
+ function k() {
97
+ return new i({
98
+ name: "AippyAIError_REQUEST_ABORTED",
99
+ message: "Request was aborted"
100
+ });
101
+ }
102
+ function B(r) {
103
+ const e = r instanceof Error ? r.message : "Network request failed";
104
+ return new i({
105
+ name: "AippyAIError_NETWORK_ERROR",
106
+ message: e,
107
+ cause: r instanceof Error ? r : String(r)
108
+ });
109
+ }
110
+ function P(r) {
111
+ return new i({
112
+ name: "AippyAIError_PARSE_ERROR",
113
+ message: `Failed to parse response: ${r}`
114
+ });
115
+ }
116
+ class f extends Error {
117
+ constructor(e, n) {
118
+ super(e), this.errors = n, this.name = "AIConfigValidationError";
119
+ }
120
+ }
121
+ function g(r) {
122
+ const e = [];
123
+ if (!r || typeof r != "object")
124
+ throw new f("AIConfig must be an object", []);
125
+ const n = r;
126
+ for (const [t, a] of Object.entries(n)) {
127
+ if (!a || typeof a != "object") {
128
+ e.push({ key: t, message: "Item must be an object" });
129
+ continue;
130
+ }
131
+ const s = a;
132
+ typeof s.index != "number" && e.push({ key: t, message: "index must be a number" }), typeof s.name != "string" && e.push({ key: t, message: "name must be a string" }), typeof s.description != "string" && e.push({ key: t, message: "description must be a string" });
133
+ const o = s.type;
134
+ if (!["number", "boolean", "text", "enum"].includes(o)) {
135
+ e.push({
136
+ key: t,
137
+ message: `type must be one of: number, boolean, text, enum (got: ${o})`
138
+ });
139
+ continue;
140
+ }
141
+ if (o === "number")
142
+ typeof s.value != "number" && e.push({ key: t, message: 'value must be a number for type "number"' }), s.min !== void 0 && typeof s.min != "number" && e.push({ key: t, message: "min must be a number" }), s.max !== void 0 && typeof s.max != "number" && e.push({ key: t, message: "max must be a number" }), s.step !== void 0 && typeof s.step != "number" && e.push({ key: t, message: "step must be a number" });
143
+ else if (o === "boolean")
144
+ typeof s.value != "boolean" && e.push({ key: t, message: 'value must be a boolean for type "boolean"' });
145
+ else if (o === "text")
146
+ typeof s.value != "string" && e.push({ key: t, message: 'value must be a string for type "text"' });
147
+ else if (o === "enum") {
148
+ if (!Array.isArray(s.options))
149
+ e.push({ key: t, message: 'options must be an array for type "enum"' });
150
+ else if (s.options.length === 0)
151
+ e.push({ key: t, message: 'options array cannot be empty for type "enum"' });
152
+ else
153
+ for (let p = 0; p < s.options.length; p++)
154
+ typeof s.options[p] != "string" && e.push({
155
+ key: t,
156
+ message: `options[${p}] must be a string`
157
+ });
158
+ typeof s.value != "string" ? e.push({ key: t, message: 'value must be a string for type "enum"' }) : Array.isArray(s.options) && !s.options.includes(s.value) && e.push({
159
+ key: t,
160
+ message: `value "${s.value}" is not in options: [${s.options.join(", ")}]`
161
+ });
162
+ }
163
+ s.group !== void 0 && typeof s.group != "string" && e.push({ key: t, message: "group must be a string" });
164
+ }
165
+ if (e.length > 0)
166
+ throw new f(
167
+ `AIConfig validation failed with ${e.length} error(s)`,
168
+ e
169
+ );
170
+ }
171
+ function J(r) {
172
+ let e;
173
+ try {
174
+ e = JSON.parse(r);
175
+ } catch (n) {
176
+ throw new f("Invalid JSON", [
177
+ {
178
+ key: "",
179
+ message: `JSON parse error: ${n instanceof Error ? n.message : String(n)}`
180
+ }
181
+ ]);
182
+ }
183
+ return g(e), e;
184
+ }
185
+ function O(r) {
186
+ return g(r), r;
187
+ }
188
+ function T(r, e) {
189
+ const n = r[e];
190
+ if (!n)
191
+ throw new Error(`AIConfig key "${e}" not found`);
192
+ return n.value;
193
+ }
194
+ function U(r) {
195
+ if (!(typeof window > "u"))
196
+ try {
197
+ const e = window.webkit?.messageHandlers?.aippyListener;
198
+ if (e)
199
+ try {
200
+ const n = {
201
+ command: "ai.initialize",
202
+ parameters: JSON.stringify(r)
203
+ };
204
+ e.postMessage(n);
205
+ } catch (n) {
206
+ console.warn("โŒ [Aippy AI Config] Failed to send config to iOS app:", n);
207
+ }
208
+ if (window.parent && window.parent !== window)
209
+ try {
210
+ const n = {
211
+ type: "ai.initialize",
212
+ config: JSON.stringify(r)
213
+ };
214
+ window.parent.postMessage(n, "*");
215
+ } catch (n) {
216
+ console.warn("โŒ [Aippy AI Config] Failed to send config to parent window:", n);
217
+ }
218
+ } catch (e) {
219
+ console.warn("โš ๏ธ [Aippy AI Config] Failed to send config:", e);
220
+ }
221
+ }
222
+ function z(r) {
223
+ const e = O(r);
224
+ return U(e), new Proxy({}, {
225
+ get(n, t) {
226
+ if (typeof t == "string")
227
+ try {
228
+ return T(e, t);
229
+ } catch {
230
+ return;
231
+ }
232
+ },
233
+ has(n, t) {
234
+ return typeof t != "string" ? !1 : t in e;
235
+ },
236
+ ownKeys(n) {
237
+ return Object.keys(e);
238
+ }
239
+ });
240
+ }
241
+ export {
242
+ f as A,
243
+ h as D,
244
+ S as U,
245
+ j as a,
246
+ F as b,
247
+ A as c,
248
+ b as d,
249
+ E as e,
250
+ k as f,
251
+ B as g,
252
+ J as h,
253
+ T as i,
254
+ z as j,
255
+ O as l,
256
+ x as m,
257
+ L as n,
258
+ P as p,
259
+ U as s,
260
+ g as v
261
+ };
@@ -1,55 +1,116 @@
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";
1
+ import { DEFAULT_CONFIG as a, SDK_NAME as s, VERSION as o, getConfigFromEnv as t, getVersionInfo as n, mergeConfig as i } from "../core/index.js";
2
+ import { A as p, E as d, c as m } from "../errors-CDEBaBxB.js";
3
+ import { s as C } from "../container-message-DGrno17o.js";
4
+ import { A as c, C as I, R as g, a as l, p as U } from "../runtime-CmoG3v2m.js";
5
+ import { CameraAPI as S, FileSystemAPI as h, GeolocationAPI as P, SensorsAPI as y, camera as T, fileSystem as x, geolocation as F, isMotionSupported as _, isOrientationSupported as D, requestMotionPermission as R, sensors as M, vibrate as k, watchMotion as O, watchOrientation as v } from "../device/index.js";
6
+ import { c as L, a as q, P as w, b as G, p as N, d as B } from "../pwa-8DGmPqLV.js";
7
+ import { a as V, b as j } from "../useTweaks-QxMRmg7i.js";
8
+ import { c as z, a as J, b as K, i as W, p as Y, u as X } from "../useAudioContext-CNQQSTab.js";
9
+ import { reportScore as $, sendEvent as ee, updateScore as re } from "../leaderboard/index.js";
10
+ import { A as se, D as oe, d as te, e as ne, c as ie, U as fe, f as pe, a as de, a as me, b as ue, j as Ce, i as Ae, l as ce, m as Ie, g as ge, n as le, h as Ue, p as Ee, s as Se, v as he } from "../helper-CRGxnlsu.js";
11
+ import { f as ye, q as Te, b as xe, h as Fe, l as _e, o as De, j as Re, n as Me, w as ke, g as Oe, k as ve, p as be, e as Le, i as qe, c as we, d as Ge, r as Ne, u as Be, m as He, s as Ve, a as je, t as Qe, v as ze } from "../bridge-D2d8hnO_.js";
12
+ import { i as Ke, f as We, h as Ye, g as Xe, a as Ze, u as $e, b as er, d as rr, c as ar, e as sr, j as or } from "../userSessionInfo-SbuNZ7JR.js";
13
+ import { hasNativeBridge as nr } from "../native-bridge-BnvipFJc.js";
8
14
  export {
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,
15
+ se as AIConfigValidationError,
16
+ c as AippyRuntime,
17
+ p as AippyRuntimeError,
18
+ S as CameraAPI,
19
+ I as Cancellable,
20
+ oe as DEFAULT_BASE_URL,
21
+ te as DEFAULT_CHAT_MODEL,
22
+ ne as DEFAULT_CHAT_SYSTEM,
23
+ a as DEFAULT_CONFIG,
24
+ ie as DEFAULT_UI_BASE_URL,
25
+ d as ERROR_CODES,
26
+ h as FileSystemAPI,
27
+ P as GeolocationAPI,
28
+ L as PWAUtils,
29
+ q as PerformanceMonitor,
30
+ w as PlatformDetector,
31
+ g as ReceiveChannel,
32
+ s as SDK_NAME,
33
+ y as SensorsAPI,
34
+ fe as UI_CHAT_ENDPOINT,
35
+ o as VERSION,
36
+ pe as abortedError,
37
+ de as aippy,
38
+ me as aippyAIProvider,
39
+ ue as aippyChatConfig,
24
40
  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,
40
- n as mergeConfig,
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
41
+ V as aippyTweaks,
42
+ j as aippyTweaksRuntime,
43
+ ye as autoRequestCredentials,
44
+ T as camera,
45
+ Te as clearCachedUserInfo,
46
+ Ke as clearProfileCache,
47
+ We as clearUserInfoCache,
48
+ Ce as createAIConfig,
49
+ m as createError,
50
+ z as createHiddenMediaElement,
51
+ J as createHiddenVideoElement,
52
+ Ye as fetchUserProfile,
53
+ x as fileSystem,
54
+ F as geolocation,
55
+ Ae as getAIConfigValue,
56
+ xe as getAuthToken,
57
+ Fe as getAuthTokenAsync,
58
+ _e as getCachedCredentials,
59
+ De as getCachedUserInfo,
60
+ t as getConfigFromEnv,
61
+ Xe as getCurrentUserId,
62
+ Re as getCurrentUserIdAsync,
63
+ Me as getUserInfoAsync,
64
+ ke as getUserInfoFromParent,
65
+ Oe as getUserSdkConfig,
66
+ n as getVersionInfo,
67
+ ve as hasCredentials,
68
+ nr as hasNativeBridge,
69
+ be as hasUserInfo,
70
+ Le as initUserBridge,
71
+ qe as initUserSdk,
72
+ K as isIOSDevice,
73
+ we as isInIframe,
74
+ W as isMediaStreamAudioSupported,
75
+ _ as isMotionSupported,
76
+ D as isOrientationSupported,
77
+ ce as loadAIConfig,
78
+ i as mergeConfig,
79
+ Ie as missingTokenError,
80
+ ge as networkError,
81
+ le as normalizeError,
82
+ Ue as parseAIConfig,
83
+ Ee as parseError,
84
+ Y as patchAudioContext,
85
+ G as performanceMonitor,
86
+ N as platform,
87
+ U as processMotionData,
88
+ B as pwa,
89
+ $ as reportScore,
90
+ Ge as requestCredentialsFromParent,
91
+ Ne as requestCredentialsFromiOS,
92
+ R as requestMotionPermission,
93
+ Be as requestUserInfoFromParent,
94
+ He as requestUserInfoFromiOS,
95
+ Se as sendAIConfigToContainer,
96
+ ee as sendEvent,
97
+ C as sendMessageToContainer,
98
+ M as sensors,
99
+ Ve as setAuthToken,
100
+ je as setCurrentUserId,
101
+ Qe as tryGetCredentialsFromParentStorage,
102
+ ze as tryGetUserInfoFromParentStorage,
103
+ re as updateScore,
104
+ X as useAudioContext,
105
+ Ze as useAuthToken,
106
+ $e as useCurrentUserId,
107
+ er as useGetCurrentUserProfileQuery,
108
+ rr as useGetJoinedUserProfilesQuery,
109
+ ar as useGetUserProfileByIdQuery,
110
+ sr as useUserInfo,
111
+ or as userSessionInfo,
112
+ he as validateAIConfig,
113
+ k as vibrate,
114
+ O as watchMotion,
115
+ v as watchOrientation
55
116
  };
package/dist/index.d.ts CHANGED
@@ -4,3 +4,5 @@ export * from './utils';
4
4
  export * from './tweaks';
5
5
  export * from './audio';
6
6
  export * from './leaderboard';
7
+ export * from './ai';
8
+ export * from './user';
@@ -0,0 +1,6 @@
1
+ function a() {
2
+ return typeof window < "u" && !!window.webkit && !!window.webkit?.messageHandlers && !!window.webkit?.messageHandlers?.aippyListener;
3
+ }
4
+ export {
5
+ a as hasNativeBridge
6
+ };
@@ -1,24 +1,6 @@
1
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
- }
2
+ var m = (o, e, t) => e in o ? u(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var r = (o, e, t) => m(o, typeof e != "symbol" ? e + "" : e, t);
22
4
  class a {
23
5
  constructor(e) {
24
6
  r(this, "cancelled", !1);
@@ -31,28 +13,28 @@ class a {
31
13
  return this.cancelled;
32
14
  }
33
15
  }
34
- class f {
16
+ class d {
35
17
  constructor() {
36
18
  r(this, "listeners", /* @__PURE__ */ new Map());
37
19
  }
38
- addEventListener(e, n) {
39
- this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(n);
20
+ addEventListener(e, t) {
21
+ this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(t);
40
22
  }
41
- removeEventListener(e, n) {
23
+ removeEventListener(e, t) {
42
24
  const i = this.listeners.get(e);
43
25
  if (i) {
44
- const t = i.indexOf(n);
45
- t > -1 && i.splice(t, 1);
26
+ const n = i.indexOf(t);
27
+ n > -1 && i.splice(n, 1);
46
28
  }
47
29
  }
48
- emit(e, n) {
30
+ emit(e, t) {
49
31
  const i = this.listeners.get(e);
50
- i && i.forEach((t) => t(n));
32
+ i && i.forEach((n) => n(t));
51
33
  }
52
34
  }
53
- class y {
35
+ class f {
54
36
  constructor() {
55
- r(this, "emitter", new f());
37
+ r(this, "emitter", new d());
56
38
  }
57
39
  /**
58
40
  * Emit a message to subscribers
@@ -63,9 +45,9 @@ class y {
63
45
  /**
64
46
  * Subscribe to messages on a specific endpoint
65
47
  */
66
- subscribe(e, n) {
67
- const i = (t) => {
68
- n(t);
48
+ subscribe(e, t) {
49
+ const i = (n) => {
50
+ t(n);
69
51
  };
70
52
  return this.emitter.addEventListener(e, i), new a(() => {
71
53
  this.emitter.removeEventListener(e, i);
@@ -74,16 +56,16 @@ class y {
74
56
  /**
75
57
  * Subscribe to a single message (auto-unsubscribe after first message)
76
58
  */
77
- once(e, n) {
78
- const i = this.subscribe(e, (t) => {
79
- i.cancel(), n(t);
59
+ once(e, t) {
60
+ const i = this.subscribe(e, (n) => {
61
+ i.cancel(), t(n);
80
62
  });
81
63
  return i;
82
64
  }
83
65
  }
84
- class h {
66
+ class y {
85
67
  constructor() {
86
- r(this, "receiveChannel", new y());
68
+ r(this, "receiveChannel", new f());
87
69
  r(this, "seq", 0);
88
70
  r(this, "motionListeners", []);
89
71
  r(this, "noListenersWarned", !1);
@@ -116,9 +98,9 @@ class h {
116
98
  isTweaksMessage(e) {
117
99
  if (typeof e != "object" || e === null || "endpoint" in e || "payload" in e)
118
100
  return !1;
119
- const n = Object.keys(e);
120
- return n.length === 0 ? !1 : n.some((t) => {
121
- const c = e[t];
101
+ const t = Object.keys(e);
102
+ return t.length === 0 ? !1 : t.some((n) => {
103
+ const c = e[n];
122
104
  return typeof c == "object" && c !== null && "value" in c;
123
105
  });
124
106
  }
@@ -129,18 +111,18 @@ class h {
129
111
  * @param callback - Callback to handle received data
130
112
  * @returns Cancellable subscription
131
113
  */
132
- createSubscription(e, n, i) {
133
- const t = (this.seq++).toString(), c = {
134
- command: n.command,
114
+ createSubscription(e, t, i) {
115
+ const n = (this.seq++).toString(), c = {
116
+ command: t.command,
135
117
  parameters: {
136
- type: n.type,
118
+ type: t.type,
137
119
  action: "subscribe",
138
- endpoint: t
120
+ endpoint: n
139
121
  }
140
122
  };
141
123
  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) {
124
+ const p = this.receiveChannel.subscribe(n, (s) => {
125
+ if (console.log(`๐Ÿ“ฌ [Aippy Runtime] Received data on endpoint ${n}:`, s), s.error !== void 0) {
144
126
  console.warn("โš ๏ธ [Aippy Runtime] Received error, skipping:", s.error);
145
127
  return;
146
128
  }
@@ -152,14 +134,14 @@ class h {
152
134
  console.error("โŒ [Aippy Runtime] Failed to send postMessage:", s);
153
135
  }
154
136
  return new a(() => {
155
- console.log(`๐Ÿ”Œ [Aippy Runtime] Unsubscribing from endpoint ${t}`), l.cancel();
137
+ console.log(`๐Ÿ”Œ [Aippy Runtime] Unsubscribing from endpoint ${n}`), p.cancel();
156
138
  try {
157
139
  const s = {
158
- command: n.command,
140
+ command: t.command,
159
141
  parameters: {
160
- type: n.type,
142
+ type: t.type,
161
143
  action: "unsubscribe",
162
- endpoint: t
144
+ endpoint: n
163
145
  }
164
146
  };
165
147
  e.postMessage(s), console.log("โœ… [Aippy Runtime] Unsubscribe message sent:", s);
@@ -175,27 +157,27 @@ class h {
175
157
  */
176
158
  addMotionListener(e) {
177
159
  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)
160
+ const t = window.webkit?.messageHandlers?.aippyListener;
161
+ if (!t)
180
162
  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);
163
+ const n = this.motionListeners.indexOf(e);
164
+ n > -1 && this.motionListeners.splice(n, 1);
183
165
  };
184
166
  console.log("โœ… [Aippy Runtime] Webkit handler found, creating subscription");
185
167
  const i = this.createSubscription(
186
- n,
168
+ t,
187
169
  {
188
170
  command: "navigator.motion",
189
171
  type: "motion"
190
172
  },
191
- (t) => {
192
- console.log("๐Ÿ“ฅ [Aippy Runtime] Received motion data from native:", t), t.motion && e(t.motion);
173
+ (n) => {
174
+ console.log("๐Ÿ“ฅ [Aippy Runtime] Received motion data from native:", n), n.motion && e(n.motion);
193
175
  }
194
176
  );
195
177
  return () => {
196
178
  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);
179
+ const n = this.motionListeners.indexOf(e);
180
+ n > -1 && this.motionListeners.splice(n, 1);
199
181
  };
200
182
  }
201
183
  /**
@@ -208,17 +190,17 @@ class h {
208
190
  this.noListenersWarned || (console.warn("โš ๏ธ [Aippy Runtime] No motion listeners to broadcast to"), this.noListenersWarned = !0);
209
191
  return;
210
192
  }
211
- const n = e.motion || e;
193
+ const t = e.motion || e;
212
194
  this.motionListeners.forEach((i) => {
213
195
  try {
214
- i(n);
215
- } catch (t) {
216
- console.error("โš ๏ธ [Aippy Runtime] Error in motion listener:", t);
196
+ i(t);
197
+ } catch (n) {
198
+ console.error("โš ๏ธ [Aippy Runtime] Error in motion listener:", n);
217
199
  }
218
200
  });
219
201
  }
220
202
  }
221
- function w(o) {
203
+ function h(o) {
222
204
  if (!o || typeof o != "object") {
223
205
  console.warn("โš ๏ธ [Aippy Runtime] Invalid motion data type:", typeof o);
224
206
  return;
@@ -227,17 +209,14 @@ function w(o) {
227
209
  console.warn("โš ๏ธ [Aippy Runtime] Motion data missing valid motion field");
228
210
  return;
229
211
  }
230
- p.broadcastMotionData(o);
212
+ l.broadcastMotionData(o);
231
213
  }
232
- const p = new h();
233
- typeof window < "u" && (window.aippyRuntime = p, window.processMotionData = w);
214
+ const l = new y();
215
+ typeof window < "u" && (window.aippyRuntime = l, window.processMotionData = h);
234
216
  export {
235
- d as A,
217
+ y as A,
236
218
  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
219
+ f as R,
220
+ l as a,
221
+ h as p
243
222
  };