@theaiplatform/miniapp-sdk 0.1.0-dev.5264044 → 0.1.0-dev.e198ea6

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.
package/dist/web.d.ts CHANGED
@@ -7,6 +7,8 @@ export declare const app: MiniAppPlatformApi;
7
7
 
8
8
  export declare function applyMiniAppTheme(theme: MiniAppTheme): void;
9
9
 
10
+ export declare function applyMiniAppUiScale(scale: MiniAppUiScale): void;
11
+
10
12
  declare type CreateChannelOptions = {
11
13
  workspaceId?: string;
12
14
  name: string;
@@ -61,6 +63,8 @@ declare type GetChannelTimelineResult = {
61
63
 
62
64
  export declare function getMiniAppThemeFromSearch(search?: string | URLSearchParams): MiniAppTheme;
63
65
 
66
+ export declare function getMiniAppUiScaleFromSearch(search?: string | URLSearchParams): MiniAppUiScale;
67
+
64
68
  /** Returns the public miniapp API proxy, which fails only when it is used. */
65
69
  export declare function getPlatform(): MiniAppPlatform;
66
70
 
@@ -73,6 +77,13 @@ declare type GetProjectResult = {
73
77
  project: MiniAppProject | null;
74
78
  };
75
79
 
80
+ /** Synchronizes both theme and UI scale from the exact parent miniapp host. */
81
+ export declare function installMiniAppAppearanceSync({ applyTheme, applyUiScale, search, }?: InstallMiniAppAppearanceSyncOptions): () => void;
82
+
83
+ export declare type InstallMiniAppAppearanceSyncOptions = InstallMiniAppThemeSyncOptions & {
84
+ applyUiScale?: (scale: MiniAppUiScale) => void;
85
+ };
86
+
76
87
  export declare function installMiniAppThemeSync({ applyTheme, search, }?: InstallMiniAppThemeSyncOptions): () => void;
77
88
 
78
89
  export declare type InstallMiniAppThemeSyncOptions = {
@@ -115,6 +126,12 @@ declare type ListWorkflowsResult = {
115
126
  workflows: MiniAppWorkflow[];
116
127
  };
117
128
 
129
+ export declare const MINIAPP_UI_SCALE_DEFAULT = 16;
130
+
131
+ export declare const MINIAPP_UI_SCALE_MAX = 20;
132
+
133
+ export declare const MINIAPP_UI_SCALE_MIN = 12;
134
+
118
135
  declare type MiniAppAuthApi = {
119
136
  getUserProfile(): MiniAppMaybePromise<MiniAppUserProfile | null>;
120
137
  };
@@ -258,6 +275,8 @@ export declare type MiniAppPlatformApi = {
258
275
  open(options: OpenNavigationOptions): void | Promise<void>;
259
276
  };
260
277
  chat: MiniAppChatApi;
278
+ storage: MiniAppStorageApi;
279
+ presence: MiniAppPresenceApi;
261
280
  /** Browser capabilities appear only when the selected target supports them. */
262
281
  auth?: MiniAppAuthApi;
263
282
  vfs?: MiniAppVfsApi;
@@ -266,6 +285,41 @@ export declare type MiniAppPlatformApi = {
266
285
  hasHostHttpRequest?: boolean;
267
286
  };
268
287
 
288
+ declare type MiniAppPresenceAddress = {
289
+ namespace: string;
290
+ room: string;
291
+ };
292
+
293
+ /**
294
+ * Ephemeral realtime presence scoped by the host to the active workspace and
295
+ * exact package. Participant identity is stamped by the host, not the app.
296
+ */
297
+ declare type MiniAppPresenceApi = {
298
+ join(options: MiniAppPresenceUpdateOptions): MiniAppMaybePromise<MiniAppPresenceSnapshot>;
299
+ update(options: MiniAppPresenceUpdateOptions): MiniAppMaybePromise<MiniAppPresenceSnapshot>;
300
+ leave(options: MiniAppPresenceAddress): MiniAppMaybePromise<void>;
301
+ subscribe(options: MiniAppPresenceAddress, listener: MiniAppPresenceListener): () => void;
302
+ };
303
+
304
+ declare type MiniAppPresenceListener = (snapshot: MiniAppPresenceSnapshot) => void;
305
+
306
+ declare type MiniAppPresenceParticipant = {
307
+ /** Host-derived, ephemeral participant identity. */
308
+ participantId: string;
309
+ displayName: string;
310
+ state: MiniAppJsonValue;
311
+ updatedAtMs: number;
312
+ };
313
+
314
+ declare type MiniAppPresenceSnapshot = MiniAppPresenceAddress & {
315
+ selfParticipantId: string;
316
+ participants: MiniAppPresenceParticipant[];
317
+ };
318
+
319
+ declare type MiniAppPresenceUpdateOptions = MiniAppPresenceAddress & {
320
+ state: MiniAppJsonValue;
321
+ };
322
+
269
323
  declare type MiniAppProject = {
270
324
  id: string;
271
325
  name: string;
@@ -365,8 +419,47 @@ declare type MiniAppSpecialistTurnResult = {
365
419
  };
366
420
  };
367
421
 
422
+ /** Caller-selected partition inside the host-derived workspace/package scope. */
423
+ declare type MiniAppStorageAddress = {
424
+ namespace: string;
425
+ key: string;
426
+ };
427
+
428
+ /**
429
+ * Durable, non-secret JSON storage. The host derives workspace and package
430
+ * identity from the authenticated frame; apps control only the namespace and
431
+ * key inside that scope.
432
+ */
433
+ declare type MiniAppStorageApi = {
434
+ get(options: MiniAppStorageAddress): MiniAppMaybePromise<MiniAppStorageEntry>;
435
+ set(options: MiniAppStorageSetOptions): MiniAppMaybePromise<MiniAppStorageMutationResult>;
436
+ delete(options: MiniAppStorageDeleteOptions): MiniAppMaybePromise<void>;
437
+ };
438
+
439
+ declare type MiniAppStorageDeleteOptions = MiniAppStorageAddress & {
440
+ expectedRevision: number;
441
+ };
442
+
443
+ declare type MiniAppStorageEntry = {
444
+ value: MiniAppJsonValue | null;
445
+ /** Null means that no value currently exists at this address. */
446
+ revision: number | null;
447
+ };
448
+
449
+ declare type MiniAppStorageMutationResult = {
450
+ revision: number;
451
+ };
452
+
453
+ declare type MiniAppStorageSetOptions = MiniAppStorageAddress & {
454
+ value: MiniAppJsonValue;
455
+ /** Optimistic concurrency token returned by `get`; null creates a missing key. */
456
+ expectedRevision: number | null;
457
+ };
458
+
368
459
  export declare type MiniAppTheme = 'light' | 'dark';
369
460
 
461
+ export declare type MiniAppUiScale = number;
462
+
370
463
  declare type MiniAppUserProfile = {
371
464
  sub: string;
372
465
  name?: string | null;
package/dist/web.js CHANGED
@@ -101,10 +101,14 @@ async function openEditorProject(options) {
101
101
  if ("u" < typeof window) throw new Error('The miniapp host is unavailable.');
102
102
  await requestHostAction(OPEN_EDITOR_PROJECT_ACTION, options);
103
103
  }
104
+ const MINIAPP_UI_SCALE_MIN = 12;
105
+ const MINIAPP_UI_SCALE_MAX = 20;
106
+ const MINIAPP_UI_SCALE_DEFAULT = 16;
104
107
  const MINIAPP_THEME_CHANGED_EVENTS = new Set([
105
108
  'zephyr-app-theme-changed',
106
109
  'tap-miniapp-theme-changed'
107
110
  ]);
111
+ const MINIAPP_UI_SCALE_CHANGED_EVENT = 'zephyr-app-ui-scale-changed';
108
112
  function isMiniAppTheme(value) {
109
113
  return 'light' === value || 'dark' === value;
110
114
  }
@@ -123,6 +127,21 @@ function applyMiniAppTheme(theme) {
123
127
  document.documentElement.classList.toggle('light', 'light' === theme);
124
128
  document.documentElement.style.colorScheme = theme;
125
129
  }
130
+ function isMiniAppUiScale(value) {
131
+ return 'number' == typeof value && Number.isInteger(value) && value >= MINIAPP_UI_SCALE_MIN && value <= MINIAPP_UI_SCALE_MAX;
132
+ }
133
+ function getMiniAppUiScaleFromSearch(search = "u" < typeof window ? '' : window.location.search) {
134
+ const params = 'string' == typeof search ? new URLSearchParams(search.startsWith('?') ? search.slice(1) : search) : search;
135
+ const rawScale = params.get('appUiScale');
136
+ if (null === rawScale || '' === rawScale.trim()) return MINIAPP_UI_SCALE_DEFAULT;
137
+ const scale = Number(rawScale);
138
+ return isMiniAppUiScale(scale) ? scale : MINIAPP_UI_SCALE_DEFAULT;
139
+ }
140
+ function applyMiniAppUiScale(scale) {
141
+ if ("u" < typeof document || !isMiniAppUiScale(scale)) return;
142
+ document.documentElement.dataset.uiScale = String(scale);
143
+ document.documentElement.style.setProperty('--app-font-size', `${scale}px`);
144
+ }
126
145
  function installMiniAppThemeSync({ applyTheme = applyMiniAppTheme, search } = {}) {
127
146
  applyTheme(getMiniAppThemeFromSearch(search));
128
147
  if ("u" < typeof window) return ()=>void 0;
@@ -142,5 +161,22 @@ function installMiniAppThemeSync({ applyTheme = applyMiniAppTheme, search } = {}
142
161
  window.removeEventListener('message', handleMessage);
143
162
  };
144
163
  }
164
+ function installMiniAppAppearanceSync({ applyTheme = applyMiniAppTheme, applyUiScale = applyMiniAppUiScale, search } = {}) {
165
+ applyTheme(getMiniAppThemeFromSearch(search));
166
+ applyUiScale(getMiniAppUiScaleFromSearch(search));
167
+ if ("u" < typeof window) return ()=>void 0;
168
+ const hostOrigin = getHostOrigin();
169
+ const parent = window.parent;
170
+ if (!hostOrigin || !parent || parent === window) return ()=>void 0;
171
+ const handleMessage = (event)=>{
172
+ if (event.source !== parent || event.origin !== hostOrigin) return;
173
+ if ('object' != typeof event.data || null === event.data) return;
174
+ const record = event.data;
175
+ if ('string' == typeof record.type && MINIAPP_THEME_CHANGED_EVENTS.has(record.type) && isMiniAppTheme(record.appTheme)) return void applyTheme(record.appTheme);
176
+ if (record.type === MINIAPP_UI_SCALE_CHANGED_EVENT && isMiniAppUiScale(record.appUiScale)) applyUiScale(record.appUiScale);
177
+ };
178
+ window.addEventListener('message', handleMessage);
179
+ return ()=>window.removeEventListener('message', handleMessage);
180
+ }
145
181
  export { sdk as app } from "./sdk.js";
146
- export { applyMiniAppTheme, getMiniAppThemeFromSearch, getPlatform, installMiniAppThemeSync, openEditorProject, platformSatisfiesApp };
182
+ export { MINIAPP_UI_SCALE_DEFAULT, MINIAPP_UI_SCALE_MAX, MINIAPP_UI_SCALE_MIN, applyMiniAppTheme, applyMiniAppUiScale, getMiniAppThemeFromSearch, getMiniAppUiScaleFromSearch, getPlatform, installMiniAppAppearanceSync, installMiniAppThemeSync, openEditorProject, platformSatisfiesApp };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theaiplatform/miniapp-sdk",
3
- "version": "0.1.0-dev.5264044",
3
+ "version": "0.1.0-dev.e198ea6",
4
4
  "description": "Public SDK for building portable miniapps that run in The AI Platform.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -27,6 +27,13 @@
27
27
  "types": "./dist/web.d.ts",
28
28
  "import": "./dist/web.js"
29
29
  },
30
+ "./ui": {
31
+ "types": "./dist/ui.d.ts",
32
+ "import": "./dist/ui.js"
33
+ },
34
+ "./ui/styles.css": "./dist/ui/styles.css",
35
+ "./ui/tailwind.css": "./dist/ui/tailwind.css",
36
+ "./ui-components.json": "./ui-components.json",
30
37
  "./surface": {
31
38
  "types": "./dist/surface.d.ts",
32
39
  "import": "./dist/surface.js"
@@ -46,13 +53,14 @@
46
53
  "files": [
47
54
  "dist",
48
55
  "config-schema.json",
56
+ "ui-components.json",
49
57
  "README.md",
50
58
  "LICENSE.md",
51
59
  "THIRD_PARTY_NOTICES.md"
52
60
  ],
53
61
  "scripts": {
54
62
  "prepack": "pnpm run build",
55
- "build": "rm -rf dist && rslib build && node scripts/copy-rspack-loaders.mjs",
63
+ "build": "rm -rf dist && rslib build && node scripts/copy-rspack-loaders.mjs && node scripts/build-ui-styles.mjs",
56
64
  "test": "rstest run",
57
65
  "typecheck": "tsc --noEmit"
58
66
  },
@@ -75,6 +83,13 @@
75
83
  "types": "./dist/web.d.ts",
76
84
  "import": "./dist/web.js"
77
85
  },
86
+ "./ui": {
87
+ "types": "./dist/ui.d.ts",
88
+ "import": "./dist/ui.js"
89
+ },
90
+ "./ui/styles.css": "./dist/ui/styles.css",
91
+ "./ui/tailwind.css": "./dist/ui/tailwind.css",
92
+ "./ui-components.json": "./ui-components.json",
78
93
  "./surface": {
79
94
  "types": "./dist/surface.d.ts",
80
95
  "import": "./dist/surface.js"
@@ -133,11 +148,37 @@
133
148
  "@rsbuild/core": "^2.1.4",
134
149
  "@rslib/core": "^0.23.2",
135
150
  "@rstest/core": "catalog:rstest",
151
+ "@tailwindcss/postcss": "^4.3.0",
136
152
  "@types/node": "catalog:node",
153
+ "postcss": "^8.5.6",
154
+ "tailwindcss": "^4.3.0",
155
+ "tw-animate-css": "^1.4.0",
137
156
  "typescript": "catalog:typescript"
138
157
  },
139
158
  "dependencies": {
159
+ "@radix-ui/react-alert-dialog": "^1.1.15",
160
+ "@radix-ui/react-checkbox": "^1.3.3",
161
+ "@radix-ui/react-compose-refs": "^1.1.2",
162
+ "@radix-ui/react-dialog": "^1.1.15",
163
+ "@radix-ui/react-label": "^2.1.8",
164
+ "@radix-ui/react-progress": "^1.1.8",
165
+ "@radix-ui/react-radio-group": "^1.3.8",
166
+ "@radix-ui/react-scroll-area": "^1.2.10",
167
+ "@radix-ui/react-select": "^2.2.6",
168
+ "@radix-ui/react-separator": "^1.1.8",
169
+ "@radix-ui/react-slider": "^1.3.6",
170
+ "@radix-ui/react-slot": "^1.2.4",
171
+ "@radix-ui/react-tabs": "^1.1.13",
172
+ "@radix-ui/react-toggle": "^1.1.10",
173
+ "@radix-ui/react-toggle-group": "^1.1.11",
174
+ "@radix-ui/react-tooltip": "^1.2.8",
140
175
  "ajv": "^8.20.0",
141
- "saxes": "^6.0.0"
176
+ "class-variance-authority": "^0.7.1",
177
+ "clsx": "^2.1.1",
178
+ "lucide-react": "^1.14.0",
179
+ "prism-react-renderer": "^2.4.1",
180
+ "react-resizable-panels": "^4.11.1",
181
+ "saxes": "^6.0.0",
182
+ "tailwind-merge": "^3.6.0"
142
183
  }
143
184
  }
@@ -0,0 +1,59 @@
1
+ {
2
+ "version": 1,
3
+ "package": "@theaiplatform/miniapp-sdk",
4
+ "import": "@theaiplatform/miniapp-sdk/ui",
5
+ "styles": {
6
+ "precompiled": "@theaiplatform/miniapp-sdk/ui/styles.css",
7
+ "tailwindV4": "@theaiplatform/miniapp-sdk/ui/tailwind.css"
8
+ },
9
+ "groups": {
10
+ "foundations": [
11
+ "Badge",
12
+ "Button",
13
+ "ButtonGroup",
14
+ "H1",
15
+ "H2",
16
+ "H3",
17
+ "H4",
18
+ "H5",
19
+ "H6",
20
+ "Icon",
21
+ "Progress",
22
+ "Separator",
23
+ "Skeleton"
24
+ ],
25
+ "layout": [
26
+ "Alert",
27
+ "Card",
28
+ "Empty",
29
+ "Item",
30
+ "ResizablePanelGroup",
31
+ "ScrollArea",
32
+ "Table",
33
+ "Tabs"
34
+ ],
35
+ "forms": [
36
+ "Checkbox",
37
+ "Field",
38
+ "Input",
39
+ "InputGroup",
40
+ "Label",
41
+ "NativeSelect",
42
+ "RadioCard",
43
+ "RadioGroup",
44
+ "Select",
45
+ "Slider",
46
+ "Textarea",
47
+ "Toggle",
48
+ "ToggleGroup"
49
+ ],
50
+ "overlays": ["AlertDialog", "Dialog", "Sheet", "Tooltip"],
51
+ "miniapp": [
52
+ "CodeBlock",
53
+ "MiniAppIconButton",
54
+ "MiniAppStatusBar",
55
+ "MiniAppToolbar"
56
+ ],
57
+ "utilities": ["cn"]
58
+ }
59
+ }