@air-jam/sdk 0.1.0

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 (56) hide show
  1. package/README.md +87 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/chunk-XSXI3RIS.js +72 -0
  4. package/dist/chunk-XSXI3RIS.js.map +1 -0
  5. package/dist/index.cjs +3514 -0
  6. package/dist/index.cjs.map +1 -0
  7. package/dist/index.d.cts +1529 -0
  8. package/dist/index.d.ts +1529 -0
  9. package/dist/index.js +3366 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/protocol.cjs +85 -0
  12. package/dist/protocol.cjs.map +1 -0
  13. package/dist/protocol.d.cts +242 -0
  14. package/dist/protocol.d.ts +242 -0
  15. package/dist/protocol.js +3 -0
  16. package/dist/protocol.js.map +1 -0
  17. package/package.json +81 -0
  18. package/src/AirJamClient.ts +775 -0
  19. package/src/audio/audio-manager.ts +395 -0
  20. package/src/audio/hooks.tsx +140 -0
  21. package/src/audio/index.ts +3 -0
  22. package/src/audio/volume-store.ts +77 -0
  23. package/src/components/air-jam-overlay.tsx +456 -0
  24. package/src/components/controller-shell.tsx +329 -0
  25. package/src/components/qr-scanner-dialog.tsx +373 -0
  26. package/src/components/ui/alert.tsx +66 -0
  27. package/src/components/ui/avatar.tsx +46 -0
  28. package/src/components/ui/badge.tsx +47 -0
  29. package/src/components/ui/button.tsx +61 -0
  30. package/src/components/ui/card.tsx +92 -0
  31. package/src/components/ui/slider.tsx +61 -0
  32. package/src/components/ui/tabs.tsx +64 -0
  33. package/src/components/volume-controls.tsx +93 -0
  34. package/src/constants.ts +45 -0
  35. package/src/context/air-jam-context.tsx +478 -0
  36. package/src/context/index.ts +2 -0
  37. package/src/context/socket-manager.ts +98 -0
  38. package/src/events.ts +151 -0
  39. package/src/hooks/use-air-jam-controller.ts +608 -0
  40. package/src/hooks/use-air-jam-host.ts +624 -0
  41. package/src/hooks/use-air-jam-shell.ts +343 -0
  42. package/src/hooks/use-fullscreen.ts +108 -0
  43. package/src/hooks/use-get-input.ts +97 -0
  44. package/src/hooks/use-send-signal.ts +164 -0
  45. package/src/index.ts +33 -0
  46. package/src/internal/input-manager.ts +362 -0
  47. package/src/protocol.ts +331 -0
  48. package/src/state/connection-store.ts +84 -0
  49. package/src/styles.css +128 -0
  50. package/src/types/browser.ts +42 -0
  51. package/src/utils/cn.ts +4 -0
  52. package/src/utils/ids.ts +31 -0
  53. package/src/utils/index.ts +1 -0
  54. package/src/utils/mode.ts +13 -0
  55. package/src/utils/network-ip.ts +145 -0
  56. package/src/utils/url-builder.ts +170 -0
@@ -0,0 +1,331 @@
1
+ import { z } from "zod";
2
+
3
+ export type RoomCode = string;
4
+
5
+ export type ConnectionRole = "host" | "controller";
6
+
7
+ export type ConnectionStatus =
8
+ | "idle"
9
+ | "connecting"
10
+ | "connected"
11
+ | "disconnected"
12
+ | "reconnecting";
13
+
14
+ export type RunMode = "standalone" | "platform";
15
+
16
+ export type GameState = "paused" | "playing";
17
+
18
+ export const roomCodeSchema = z
19
+ .string()
20
+ .trim()
21
+ .min(4)
22
+ .max(8)
23
+ .regex(/^[A-Z0-9]+$/, { message: "room code must contain only A-Z or 0-9" });
24
+
25
+ export const controllerInputSchema = z.object({
26
+ roomId: roomCodeSchema,
27
+ controllerId: z.string().min(3),
28
+ input: z.record(z.string(), z.unknown()), // Arbitrary JSON object - developers define their own structure
29
+ });
30
+
31
+ export type ControllerInputPayload = Record<string, unknown>;
32
+
33
+ export interface ControllerInputEvent {
34
+ roomId: RoomCode;
35
+ controllerId: string;
36
+ input: ControllerInputPayload;
37
+ }
38
+
39
+ export const controllerStateSchema = z.object({
40
+ roomId: roomCodeSchema,
41
+ state: z.object({
42
+ orientation: z.enum(["portrait", "landscape"]).optional(),
43
+ message: z.string().optional(),
44
+ gameState: z.enum(["paused", "playing"]).optional(),
45
+ }),
46
+ });
47
+
48
+ export type ControllerStateMessage = z.infer<typeof controllerStateSchema>;
49
+
50
+ export type ControllerStatePayload = z.infer<
51
+ typeof controllerStateSchema
52
+ >["state"];
53
+
54
+ export const hostRegistrationSchema = z.object({
55
+ roomId: roomCodeSchema,
56
+ maxPlayers: z.number().int().min(1).max(16).default(8),
57
+ apiKey: z.string().optional(),
58
+ mode: z.enum(["master", "child"]).default("child"),
59
+ controllerUrl: z.string().url().optional(),
60
+ });
61
+
62
+ export type HostRegistrationPayload = z.infer<typeof hostRegistrationSchema>;
63
+
64
+ export const controllerJoinSchema = z.object({
65
+ roomId: roomCodeSchema,
66
+ controllerId: z.string().min(3),
67
+ nickname: z.string().trim().min(1).max(24).optional(),
68
+ });
69
+
70
+ export type ControllerJoinPayload = z.infer<typeof controllerJoinSchema>;
71
+
72
+ export const controllerLeaveSchema = z.object({
73
+ roomId: roomCodeSchema,
74
+ controllerId: z.string().min(3),
75
+ });
76
+
77
+ export type ControllerLeavePayload = z.infer<typeof controllerLeaveSchema>;
78
+
79
+ export interface PlayerProfile {
80
+ id: string;
81
+ label: string;
82
+ color?: string;
83
+ }
84
+
85
+ export interface HostRegistrationAck {
86
+ ok: boolean;
87
+ roomId?: RoomCode;
88
+ message?: string;
89
+ code?: ErrorCode | string;
90
+ }
91
+
92
+ export interface ControllerJoinAck {
93
+ ok: boolean;
94
+ controllerId?: string;
95
+ roomId?: RoomCode;
96
+ message?: string;
97
+ code?: ErrorCode | string;
98
+ }
99
+
100
+ export const controllerSystemSchema = z.object({
101
+ roomId: roomCodeSchema,
102
+ command: z.enum(["exit", "ready", "toggle_pause"]),
103
+ });
104
+
105
+ export type ControllerSystemPayload = z.infer<typeof controllerSystemSchema>;
106
+
107
+ /**
108
+ * Standard error codes for Air Jam
109
+ */
110
+ export enum ErrorCode {
111
+ // Room errors
112
+ ROOM_NOT_FOUND = "ROOM_NOT_FOUND",
113
+ ROOM_FULL = "ROOM_FULL",
114
+
115
+ // Auth errors
116
+ INVALID_API_KEY = "INVALID_API_KEY",
117
+ UNAUTHORIZED = "UNAUTHORIZED",
118
+
119
+ // Token errors
120
+ INVALID_TOKEN = "INVALID_TOKEN",
121
+ TOKEN_EXPIRED = "TOKEN_EXPIRED",
122
+
123
+ // Connection errors
124
+ CONNECTION_FAILED = "CONNECTION_FAILED",
125
+ ALREADY_CONNECTED = "ALREADY_CONNECTED",
126
+
127
+ // Validation errors
128
+ INVALID_PAYLOAD = "INVALID_PAYLOAD",
129
+ INVALID_ROOM_CODE = "INVALID_ROOM_CODE",
130
+
131
+ // Server errors
132
+ INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR",
133
+ SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
134
+
135
+ // Generic
136
+ UNKNOWN_ERROR = "UNKNOWN_ERROR",
137
+ }
138
+
139
+ /**
140
+ * Standardized error payload
141
+ */
142
+ export interface ServerErrorPayload {
143
+ code: ErrorCode | string; // Allow custom codes
144
+ message: string;
145
+ details?: unknown;
146
+ }
147
+
148
+ export interface ControllerWelcomePayload {
149
+ controllerId: string;
150
+ roomId: RoomCode;
151
+ player?: PlayerProfile;
152
+ }
153
+
154
+ export interface ControllerJoinedNotice {
155
+ controllerId: string;
156
+ nickname?: string;
157
+ player?: PlayerProfile;
158
+ }
159
+
160
+ export interface ControllerLeftNotice {
161
+ controllerId: string;
162
+ }
163
+
164
+ export interface RoomReadyNotice {
165
+ roomId: RoomCode;
166
+ }
167
+
168
+ export interface HostLeftNotice {
169
+ roomId: RoomCode;
170
+ reason: string;
171
+ }
172
+
173
+ export type SignalType = "HAPTIC" | "TOAST";
174
+
175
+ export interface HapticSignalPayload {
176
+ pattern: "light" | "medium" | "heavy" | "success" | "failure" | "custom";
177
+ sequence?: number | number[];
178
+ }
179
+
180
+ export interface ToastSignalPayload {
181
+ message: string;
182
+ color?: string;
183
+ duration?: number;
184
+ }
185
+
186
+ export type SignalPayload =
187
+ | {
188
+ targetId?: string;
189
+ type: "HAPTIC";
190
+ payload: HapticSignalPayload;
191
+ }
192
+ | {
193
+ targetId?: string;
194
+ type: "TOAST";
195
+ payload: ToastSignalPayload;
196
+ };
197
+
198
+ export interface PlaySoundEventPayload {
199
+ roomId: string;
200
+ targetControllerId?: string; // If null, broadcast to all
201
+ soundId: string;
202
+ volume?: number;
203
+ loop?: boolean;
204
+ }
205
+
206
+ export const hostRegisterSystemSchema = z.object({
207
+ roomId: roomCodeSchema,
208
+ apiKey: z.string().optional(),
209
+ });
210
+
211
+ export type HostRegisterSystemPayload = z.infer<
212
+ typeof hostRegisterSystemSchema
213
+ >;
214
+
215
+ export const systemLaunchGameSchema = z.object({
216
+ roomId: roomCodeSchema,
217
+ gameId: z.string(),
218
+ gameUrl: z.string().url(),
219
+ });
220
+
221
+ export type SystemLaunchGamePayload = z.infer<typeof systemLaunchGameSchema>;
222
+
223
+ export const hostJoinAsChildSchema = z.object({
224
+ roomId: roomCodeSchema,
225
+ joinToken: z.string(),
226
+ });
227
+
228
+ export type HostJoinAsChildPayload = z.infer<typeof hostJoinAsChildSchema>;
229
+
230
+ export interface SystemLaunchGameAck {
231
+ ok: boolean;
232
+ joinToken?: string;
233
+ message?: string;
234
+ code?: ErrorCode | string;
235
+ }
236
+
237
+ export interface ClientLoadUiPayload {
238
+ url: string;
239
+ }
240
+
241
+ export interface ClientToServerEvents {
242
+ "host:register": (
243
+ payload: z.infer<typeof hostRegistrationSchema>,
244
+ callback: (ack: HostRegistrationAck) => void,
245
+ ) => void;
246
+ "host:registerSystem": (
247
+ payload: HostRegisterSystemPayload,
248
+ callback: (ack: HostRegistrationAck) => void,
249
+ ) => void;
250
+ "system:launchGame": (
251
+ payload: SystemLaunchGamePayload,
252
+ callback: (ack: SystemLaunchGameAck) => void,
253
+ ) => void;
254
+ "host:joinAsChild": (
255
+ payload: HostJoinAsChildPayload,
256
+ callback: (ack: HostRegistrationAck) => void,
257
+ ) => void;
258
+ "system:closeGame": (payload: { roomId: string }) => void;
259
+ "host:state": (payload: z.infer<typeof controllerStateSchema>) => void;
260
+ "controller:join": (
261
+ payload: z.infer<typeof controllerJoinSchema>,
262
+ callback: (ack: ControllerJoinAck) => void,
263
+ ) => void;
264
+ "controller:leave": (payload: z.infer<typeof controllerLeaveSchema>) => void;
265
+ "controller:input": (payload: z.infer<typeof controllerInputSchema>) => void;
266
+ "controller:system": (
267
+ payload: z.infer<typeof controllerSystemSchema>,
268
+ ) => void;
269
+ "host:system": (payload: z.infer<typeof controllerSystemSchema>) => void;
270
+ "host:signal": (payload: SignalPayload) => void;
271
+ "host:play_sound": (payload: PlaySoundEventPayload) => void;
272
+ "controller:play_sound": (payload: PlaySoundEventPayload) => void;
273
+ }
274
+
275
+ export interface PlaySoundPayload {
276
+ id: string;
277
+ volume?: number;
278
+ loop?: boolean;
279
+ }
280
+
281
+ export interface ServerToClientEvents {
282
+ "server:roomReady": (payload: RoomReadyNotice) => void;
283
+ "server:controllerJoined": (payload: ControllerJoinedNotice) => void;
284
+ "server:controllerLeft": (payload: ControllerLeftNotice) => void;
285
+ "server:input": (payload: ControllerInputEvent) => void;
286
+ "server:error": (payload: ServerErrorPayload) => void;
287
+ "server:state": (payload: z.infer<typeof controllerStateSchema>) => void;
288
+ "server:welcome": (payload: ControllerWelcomePayload) => void;
289
+ "server:hostLeft": (payload: HostLeftNotice) => void;
290
+ "server:signal": (payload: SignalPayload) => void;
291
+ "server:playSound": (payload: PlaySoundPayload) => void;
292
+ "server:redirect": (url: string) => void;
293
+ "server:closeChild": () => void;
294
+ "client:loadUi": (payload: ClientLoadUiPayload) => void;
295
+ "client:unloadUi": () => void;
296
+ }
297
+
298
+ export interface InterServerEvents {
299
+ ping: () => void;
300
+ }
301
+
302
+ export type SocketData = Record<string, unknown>;
303
+
304
+ // --- Proxy Protocol (iframe <-> parent) ---
305
+ // Note: Proxy protocol is largely deprecated in favor of Direct Connect (airjam_force_connect=true),
306
+ // but might still be used for UI coordination (e.g. hiding headers).
307
+
308
+ export const AIRJAM_PROXY_PREFIX = "AIRJAM_";
309
+
310
+ export interface ProxyMessageBase {
311
+ type: string;
312
+ }
313
+
314
+ export interface ProxyReadyMessage extends ProxyMessageBase {
315
+ type: "AIRJAM_READY";
316
+ }
317
+
318
+ export interface ProxyInputMessage extends ProxyMessageBase {
319
+ type: "AIRJAM_INPUT";
320
+ payload: ControllerInputPayload;
321
+ }
322
+
323
+ export interface ProxyStateMessage extends ProxyMessageBase {
324
+ type: "AIRJAM_STATE";
325
+ payload: ControllerStatePayload;
326
+ }
327
+
328
+ export type AirJamProxyMessage =
329
+ | ProxyReadyMessage
330
+ | ProxyInputMessage
331
+ | ProxyStateMessage;
@@ -0,0 +1,84 @@
1
+ import { create, type StoreApi } from "zustand";
2
+ import type {
3
+ ConnectionRole,
4
+ ConnectionStatus,
5
+ GameState,
6
+ PlayerProfile,
7
+ RunMode,
8
+ } from "../protocol";
9
+
10
+ export interface AirJamStore {
11
+ role: ConnectionRole | null;
12
+ roomId: string | null;
13
+ controllerId: string | null;
14
+ connectionStatus: ConnectionStatus;
15
+ mode: RunMode;
16
+ gameState: GameState;
17
+ stateMessage?: string;
18
+ players: PlayerProfile[];
19
+ lastError?: string;
20
+ registeredRoomId: string | null;
21
+ setRole: (role: ConnectionRole | null) => void;
22
+ setRoomId: (roomId: string | null) => void;
23
+ setControllerId: (controllerId: string | null) => void;
24
+ setStatus: (status: ConnectionStatus) => void;
25
+ setMode: (mode: RunMode) => void;
26
+ setGameState: (state: GameState) => void;
27
+ setStateMessage: (message?: string) => void;
28
+ toggleGameState: () => void;
29
+ setError: (message?: string) => void;
30
+ upsertPlayer: (player: PlayerProfile) => void;
31
+ removePlayer: (playerId: string) => void;
32
+ resetPlayers: () => void;
33
+ resetGameState: () => void;
34
+ setRegisteredRoomId: (roomId: string | null) => void;
35
+ }
36
+
37
+ /**
38
+ * Factory function to create a new AirJamStore instance.
39
+ * Each AirJamProvider creates its own store for multi-instance support.
40
+ */
41
+ export const createAirJamStore = (): StoreApi<AirJamStore> =>
42
+ create<AirJamStore>((set) => ({
43
+ role: null,
44
+ roomId: null,
45
+ controllerId: null,
46
+ connectionStatus: "idle",
47
+ mode: "standalone",
48
+ gameState: "paused",
49
+ stateMessage: undefined,
50
+ players: [],
51
+ lastError: undefined,
52
+ registeredRoomId: null,
53
+ setRole: (role) => set({ role }),
54
+ setRoomId: (roomId) => set({ roomId }),
55
+ setControllerId: (controllerId) => set({ controllerId }),
56
+ setStatus: (connectionStatus) => set({ connectionStatus }),
57
+ setMode: (mode) => set({ mode }),
58
+ setGameState: (gameState) => set({ gameState }),
59
+ setStateMessage: (stateMessage) => set({ stateMessage }),
60
+ toggleGameState: () =>
61
+ set((state) => ({
62
+ gameState: state.gameState === "paused" ? "playing" : "paused",
63
+ })),
64
+ setError: (message) => set({ lastError: message }),
65
+ upsertPlayer: (player) =>
66
+ set((state) => {
67
+ const existingIndex = state.players.findIndex(
68
+ (entry) => entry.id === player.id,
69
+ );
70
+ if (existingIndex >= 0) {
71
+ const nextPlayers = [...state.players];
72
+ nextPlayers[existingIndex] = player;
73
+ return { players: nextPlayers };
74
+ }
75
+ return { players: [...state.players, player] };
76
+ }),
77
+ removePlayer: (playerId) =>
78
+ set((state) => ({
79
+ players: state.players.filter((player) => player.id !== playerId),
80
+ })),
81
+ resetPlayers: () => set({ players: [] }),
82
+ resetGameState: () => set({ gameState: "paused", stateMessage: undefined }),
83
+ setRegisteredRoomId: (roomId) => set({ registeredRoomId: roomId }),
84
+ }));
package/src/styles.css ADDED
@@ -0,0 +1,128 @@
1
+ @import "tailwindcss";
2
+
3
+ /* Tell Tailwind to scan this package's source files for classes */
4
+ @source "./components/**/*.{ts,tsx}";
5
+ @source "./hooks/**/*.{ts,tsx}";
6
+ @source "./utils/**/*.{ts,tsx}";
7
+ @source "./state/**/*.{ts,tsx}";
8
+
9
+ @custom-variant dark (&:is(.dark *));
10
+
11
+ :root {
12
+ --background: oklch(1 0 0);
13
+ --foreground: oklch(0.145 0 0);
14
+ --card: oklch(1 0 0);
15
+ --card-foreground: oklch(0.145 0 0);
16
+ --popover: oklch(1 0 0);
17
+ --popover-foreground: oklch(0.145 0 0);
18
+ --primary: oklch(0.205 0 0);
19
+ --primary-foreground: oklch(0.985 0 0);
20
+ --secondary: oklch(0.97 0 0);
21
+ --secondary-foreground: oklch(0.205 0 0);
22
+ --muted: oklch(0.97 0 0);
23
+ --muted-foreground: oklch(0.556 0 0);
24
+ --accent: oklch(0.97 0 0);
25
+ --accent-foreground: oklch(0.205 0 0);
26
+ --destructive: oklch(0.577 0.245 27.325);
27
+ --destructive-foreground: oklch(0.577 0.245 27.325);
28
+ --border: oklch(0.922 0 0);
29
+ --input: oklch(0.922 0 0);
30
+ --ring: oklch(0.708 0 0);
31
+ --chart-1: oklch(0.646 0.222 41.116);
32
+ --chart-2: oklch(0.6 0.118 184.704);
33
+ --chart-3: oklch(0.398 0.07 227.392);
34
+ --chart-4: oklch(0.828 0.189 84.429);
35
+ --chart-5: oklch(0.769 0.188 70.08);
36
+ --radius: 0.625rem;
37
+ --sidebar: oklch(0.985 0 0);
38
+ --sidebar-foreground: oklch(0.145 0 0);
39
+ --sidebar-primary: oklch(0.205 0 0);
40
+ --sidebar-primary-foreground: oklch(0.985 0 0);
41
+ --sidebar-accent: oklch(0.97 0 0);
42
+ --sidebar-accent-foreground: oklch(0.205 0 0);
43
+ --sidebar-border: oklch(0.922 0 0);
44
+ --sidebar-ring: oklch(0.708 0 0);
45
+ }
46
+
47
+ .dark {
48
+ --background: oklch(0.145 0 0);
49
+ --foreground: oklch(0.985 0 0);
50
+ --card: oklch(0.145 0 0);
51
+ --card-foreground: oklch(0.985 0 0);
52
+ --popover: oklch(0.145 0 0);
53
+ --popover-foreground: oklch(0.985 0 0);
54
+ --primary: oklch(0.985 0 0);
55
+ --primary-foreground: oklch(0.205 0 0);
56
+ --secondary: oklch(0.269 0 0);
57
+ --secondary-foreground: oklch(0.985 0 0);
58
+ --muted: oklch(0.269 0 0);
59
+ --muted-foreground: oklch(0.708 0 0);
60
+ --accent: oklch(0.269 0 0);
61
+ --accent-foreground: oklch(0.985 0 0);
62
+ --destructive: oklch(0.396 0.141 25.723);
63
+ --destructive-foreground: oklch(0.637 0.237 25.331);
64
+ --border: oklch(0.269 0 0);
65
+ --input: oklch(0.269 0 0);
66
+ --ring: oklch(0.439 0 0);
67
+ --chart-1: oklch(0.488 0.243 264.376);
68
+ --chart-2: oklch(0.696 0.17 162.48);
69
+ --chart-3: oklch(0.769 0.188 70.08);
70
+ --chart-4: oklch(0.627 0.265 303.9);
71
+ --chart-5: oklch(0.645 0.246 16.439);
72
+ --sidebar: oklch(0.205 0 0);
73
+ --sidebar-foreground: oklch(0.985 0 0);
74
+ --sidebar-primary: oklch(0.488 0.243 264.376);
75
+ --sidebar-primary-foreground: oklch(0.985 0 0);
76
+ --sidebar-accent: oklch(0.269 0 0);
77
+ --sidebar-accent-foreground: oklch(0.985 0 0);
78
+ --sidebar-border: oklch(0.269 0 0);
79
+ --sidebar-ring: oklch(0.439 0 0);
80
+ }
81
+
82
+ @theme inline {
83
+ --color-background: var(--background);
84
+ --color-foreground: var(--foreground);
85
+ --color-card: var(--card);
86
+ --color-card-foreground: var(--card-foreground);
87
+ --color-popover: var(--popover);
88
+ --color-popover-foreground: var(--popover-foreground);
89
+ --color-primary: var(--primary);
90
+ --color-primary-foreground: var(--primary-foreground);
91
+ --color-secondary: var(--secondary);
92
+ --color-secondary-foreground: var(--secondary-foreground);
93
+ --color-muted: var(--muted);
94
+ --color-muted-foreground: var(--muted-foreground);
95
+ --color-accent: var(--accent);
96
+ --color-accent-foreground: var(--accent-foreground);
97
+ --color-destructive: var(--destructive);
98
+ --color-destructive-foreground: var(--destructive-foreground);
99
+ --color-border: var(--border);
100
+ --color-input: var(--input);
101
+ --color-ring: var(--ring);
102
+ --color-chart-1: var(--chart-1);
103
+ --color-chart-2: var(--chart-2);
104
+ --color-chart-3: var(--chart-3);
105
+ --color-chart-4: var(--chart-4);
106
+ --color-chart-5: var(--chart-5);
107
+ --radius-sm: calc(var(--radius) - 4px);
108
+ --radius-md: calc(var(--radius) - 2px);
109
+ --radius-lg: var(--radius);
110
+ --radius-xl: calc(var(--radius) + 4px);
111
+ --color-sidebar: var(--sidebar);
112
+ --color-sidebar-foreground: var(--sidebar-foreground);
113
+ --color-sidebar-primary: var(--sidebar-primary);
114
+ --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
115
+ --color-sidebar-accent: var(--sidebar-accent);
116
+ --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
117
+ --color-sidebar-border: var(--sidebar-border);
118
+ --color-sidebar-ring: var(--sidebar-ring);
119
+ }
120
+
121
+ @layer base {
122
+ * {
123
+ @apply border-border outline-ring/50;
124
+ }
125
+ body {
126
+ @apply bg-background text-foreground;
127
+ }
128
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Browser API type definitions for vendor-prefixed features
3
+ * These extend standard DOM types to include vendor-specific APIs
4
+ */
5
+
6
+ /**
7
+ * Document interface extended with vendor-prefixed fullscreen APIs
8
+ */
9
+ export interface DocumentWithFullscreen extends Document {
10
+ /** Webkit fullscreen element */
11
+ webkitFullscreenElement?: Element;
12
+ /** Mozilla fullscreen element */
13
+ mozFullScreenElement?: Element;
14
+ /** Microsoft fullscreen element */
15
+ msFullscreenElement?: Element;
16
+ /** Webkit exit fullscreen method */
17
+ webkitExitFullscreen?: () => Promise<void>;
18
+ /** Mozilla exit fullscreen method */
19
+ mozCancelFullScreen?: () => Promise<void>;
20
+ /** Microsoft exit fullscreen method */
21
+ msExitFullscreen?: () => Promise<void>;
22
+ }
23
+
24
+ /**
25
+ * HTMLElement interface extended with vendor-prefixed fullscreen request APIs
26
+ */
27
+ export interface ElementWithFullscreen extends HTMLElement {
28
+ /** Webkit request fullscreen method */
29
+ webkitRequestFullscreen?: () => Promise<void>;
30
+ /** Mozilla request fullscreen method */
31
+ mozRequestFullScreen?: () => Promise<void>;
32
+ /** Microsoft request fullscreen method */
33
+ msRequestFullscreen?: () => Promise<void>;
34
+ }
35
+
36
+ /**
37
+ * Window interface extended with vendor-prefixed Audio Context
38
+ */
39
+ export interface WindowWithAudio extends Window {
40
+ /** Webkit AudioContext constructor */
41
+ webkitAudioContext?: typeof AudioContext;
42
+ }
@@ -0,0 +1,4 @@
1
+ import { clsx, type ClassValue } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+
4
+ export const cn = (...inputs: ClassValue[]): string => twMerge(clsx(inputs));
@@ -0,0 +1,31 @@
1
+ import { roomCodeSchema } from "../protocol";
2
+
3
+ const alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
4
+
5
+ export const generateRoomCode = (): string => {
6
+ const array = new Uint32Array(4);
7
+ if (
8
+ typeof crypto !== "undefined" &&
9
+ typeof crypto.getRandomValues === "function"
10
+ ) {
11
+ crypto.getRandomValues(array);
12
+ } else {
13
+ for (let i = 0; i < array.length; i += 1) {
14
+ array[i] = Math.floor(Math.random() * alphabet.length);
15
+ }
16
+ }
17
+
18
+ const code = Array.from(
19
+ array,
20
+ (value) => alphabet[value % alphabet.length],
21
+ ).join("");
22
+ return roomCodeSchema.parse(code);
23
+ };
24
+
25
+ export const generateControllerId = (): string => {
26
+ const stamp = Math.floor(Date.now() % 100000)
27
+ .toString()
28
+ .padStart(5, "0");
29
+ const random = alphabet[Math.floor(Math.random() * alphabet.length)];
30
+ return `C${random}${stamp}`;
31
+ };
@@ -0,0 +1 @@
1
+ export { cn } from "./cn";
@@ -0,0 +1,13 @@
1
+ import type { RunMode } from "../protocol";
2
+
3
+ export const detectRunMode = (): RunMode => {
4
+ if (typeof window === "undefined") {
5
+ return "standalone";
6
+ }
7
+
8
+ try {
9
+ return window.self !== window.top ? "platform" : "standalone";
10
+ } catch {
11
+ return "platform";
12
+ }
13
+ };