@air-jam/sdk 0.1.4 → 0.9.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 (348) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +627 -57
  3. package/dist/agent-tooling-BSMGBix9.d.cts +123 -0
  4. package/dist/agent-tooling-BSMGBix9.d.ts +123 -0
  5. package/dist/agent-tooling.cjs +83 -0
  6. package/dist/agent-tooling.cjs.map +1 -0
  7. package/dist/agent-tooling.d.cts +2 -0
  8. package/dist/agent-tooling.d.ts +2 -0
  9. package/dist/agent-tooling.js +17 -0
  10. package/dist/agent-tooling.js.map +1 -0
  11. package/dist/arcade/bridge/controller.cjs +749 -0
  12. package/dist/arcade/bridge/controller.cjs.map +1 -0
  13. package/dist/arcade/bridge/controller.d.cts +85 -0
  14. package/dist/arcade/bridge/controller.d.ts +85 -0
  15. package/dist/arcade/bridge/controller.js +33 -0
  16. package/dist/arcade/bridge/controller.js.map +1 -0
  17. package/dist/arcade/bridge/host.cjs +421 -0
  18. package/dist/arcade/bridge/host.cjs.map +1 -0
  19. package/dist/arcade/bridge/host.d.cts +73 -0
  20. package/dist/arcade/bridge/host.d.ts +73 -0
  21. package/dist/arcade/bridge/host.js +25 -0
  22. package/dist/arcade/bridge/host.js.map +1 -0
  23. package/dist/arcade/bridge/iframe.cjs +453 -0
  24. package/dist/arcade/bridge/iframe.cjs.map +1 -0
  25. package/dist/arcade/bridge/iframe.d.cts +80 -0
  26. package/dist/arcade/bridge/iframe.d.ts +80 -0
  27. package/dist/arcade/bridge/iframe.js +28 -0
  28. package/dist/arcade/bridge/iframe.js.map +1 -0
  29. package/dist/arcade/bridge.cjs +1067 -0
  30. package/dist/arcade/bridge.cjs.map +1 -0
  31. package/dist/arcade/bridge.d.cts +11 -0
  32. package/dist/arcade/bridge.d.ts +11 -0
  33. package/dist/arcade/bridge.js +76 -0
  34. package/dist/arcade/bridge.js.map +1 -0
  35. package/dist/arcade/host.cjs +488 -0
  36. package/dist/arcade/host.cjs.map +1 -0
  37. package/dist/arcade/host.d.cts +19 -0
  38. package/dist/arcade/host.d.ts +19 -0
  39. package/dist/arcade/host.js +13 -0
  40. package/dist/arcade/host.js.map +1 -0
  41. package/dist/arcade/surface.cjs +113 -0
  42. package/dist/arcade/surface.cjs.map +1 -0
  43. package/dist/arcade/surface.d.cts +14 -0
  44. package/dist/arcade/surface.d.ts +14 -0
  45. package/dist/arcade/surface.js +27 -0
  46. package/dist/arcade/surface.js.map +1 -0
  47. package/dist/arcade/url.cjs +363 -0
  48. package/dist/arcade/url.cjs.map +1 -0
  49. package/dist/arcade/url.d.cts +68 -0
  50. package/dist/arcade/url.d.ts +68 -0
  51. package/dist/arcade/url.js +28 -0
  52. package/dist/arcade/url.js.map +1 -0
  53. package/dist/arcade-runtime-url-BW-MUAOY.d.cts +28 -0
  54. package/dist/arcade-runtime-url-l8qj01Pg.d.ts +28 -0
  55. package/dist/arcade-surface-identity-CQxDpn_w.d.cts +16 -0
  56. package/dist/arcade-surface-identity-CQxDpn_w.d.ts +16 -0
  57. package/dist/arcade.cjs +1565 -0
  58. package/dist/arcade.cjs.map +1 -0
  59. package/dist/arcade.d.cts +18 -0
  60. package/dist/arcade.d.ts +18 -0
  61. package/dist/arcade.js +122 -0
  62. package/dist/arcade.js.map +1 -0
  63. package/dist/capabilities.cjs +39 -0
  64. package/dist/capabilities.cjs.map +1 -0
  65. package/dist/capabilities.d.cts +31 -0
  66. package/dist/capabilities.d.ts +31 -0
  67. package/dist/capabilities.js +12 -0
  68. package/dist/capabilities.js.map +1 -0
  69. package/dist/chunk-2432OL7L.js +193 -0
  70. package/dist/chunk-2432OL7L.js.map +1 -0
  71. package/dist/chunk-2J65FXEP.js +41 -0
  72. package/dist/chunk-2J65FXEP.js.map +1 -0
  73. package/dist/chunk-32NYL7XI.js +539 -0
  74. package/dist/chunk-32NYL7XI.js.map +1 -0
  75. package/dist/chunk-3USU7GY2.js +54 -0
  76. package/dist/chunk-3USU7GY2.js.map +1 -0
  77. package/dist/chunk-BE6Z4SIT.js +65 -0
  78. package/dist/chunk-BE6Z4SIT.js.map +1 -0
  79. package/dist/chunk-CQUG24WX.js +249 -0
  80. package/dist/chunk-CQUG24WX.js.map +1 -0
  81. package/dist/chunk-D3X4MN4U.js +288 -0
  82. package/dist/chunk-D3X4MN4U.js.map +1 -0
  83. package/dist/chunk-EVZJA6RN.js +140 -0
  84. package/dist/chunk-EVZJA6RN.js.map +1 -0
  85. package/dist/chunk-HFWRZVZ3.js +1438 -0
  86. package/dist/chunk-HFWRZVZ3.js.map +1 -0
  87. package/dist/chunk-IKKDONQL.js +1 -0
  88. package/dist/chunk-IKKDONQL.js.map +1 -0
  89. package/dist/chunk-JTF47B56.js +1 -0
  90. package/dist/chunk-JTF47B56.js.map +1 -0
  91. package/dist/chunk-LIXPF4P6.js +22 -0
  92. package/dist/chunk-LIXPF4P6.js.map +1 -0
  93. package/dist/chunk-MKBASO6X.js +216 -0
  94. package/dist/chunk-MKBASO6X.js.map +1 -0
  95. package/dist/chunk-MPDMJIX5.js +1 -0
  96. package/dist/chunk-MPDMJIX5.js.map +1 -0
  97. package/dist/chunk-NCL6WJCL.js +91 -0
  98. package/dist/chunk-NCL6WJCL.js.map +1 -0
  99. package/dist/chunk-NU5W6VAV.js +126 -0
  100. package/dist/chunk-NU5W6VAV.js.map +1 -0
  101. package/dist/chunk-TGRTEWYV.js +195 -0
  102. package/dist/chunk-TGRTEWYV.js.map +1 -0
  103. package/dist/chunk-VDRNNGHX.js +184 -0
  104. package/dist/chunk-VDRNNGHX.js.map +1 -0
  105. package/dist/chunk-VN5LDWVN.js +32 -0
  106. package/dist/chunk-VN5LDWVN.js.map +1 -0
  107. package/dist/chunk-W2VK36RO.js +11 -0
  108. package/dist/chunk-W2VK36RO.js.map +1 -0
  109. package/dist/chunk-X24K52DG.js +12 -0
  110. package/dist/chunk-X24K52DG.js.map +1 -0
  111. package/dist/chunk-XLUWV45V.js +25 -0
  112. package/dist/chunk-XLUWV45V.js.map +1 -0
  113. package/dist/chunk-Y4RAPKKB.js +238 -0
  114. package/dist/chunk-Y4RAPKKB.js.map +1 -0
  115. package/dist/chunk-YXHH3MQT.js +230 -0
  116. package/dist/chunk-YXHH3MQT.js.map +1 -0
  117. package/dist/chunk-ZLPL2R3R.js +183 -0
  118. package/dist/chunk-ZLPL2R3R.js.map +1 -0
  119. package/dist/chunk-ZTQ5SP4H.js +9 -0
  120. package/dist/chunk-ZTQ5SP4H.js.map +1 -0
  121. package/dist/controller-Bod8YYr1.d.cts +172 -0
  122. package/dist/controller-DxVchfiA.d.ts +172 -0
  123. package/dist/dev-log-events-CVAM29hx.d.cts +123 -0
  124. package/dist/dev-log-events-CVAM29hx.d.ts +123 -0
  125. package/dist/handshake-CC_LrK5g.d.cts +31 -0
  126. package/dist/handshake-CC_LrK5g.d.ts +31 -0
  127. package/dist/host-8hmq_Sgc.d.cts +109 -0
  128. package/dist/host-Cw-N6e-5.d.ts +109 -0
  129. package/dist/index.cjs +8507 -3523
  130. package/dist/index.cjs.map +1 -1
  131. package/dist/index.d.cts +676 -1070
  132. package/dist/index.d.ts +676 -1070
  133. package/dist/index.js +4890 -3196
  134. package/dist/index.js.map +1 -1
  135. package/dist/metadata.cjs +114 -0
  136. package/dist/metadata.cjs.map +1 -0
  137. package/dist/metadata.d.cts +95 -0
  138. package/dist/metadata.d.ts +95 -0
  139. package/dist/metadata.js +83 -0
  140. package/dist/metadata.js.map +1 -0
  141. package/dist/notices-CnGaaS8B.d.ts +38 -0
  142. package/dist/notices-NyDM5Mtz.d.cts +38 -0
  143. package/dist/platform-machine.cjs +425 -0
  144. package/dist/platform-machine.cjs.map +1 -0
  145. package/dist/platform-machine.d.cts +1183 -0
  146. package/dist/platform-machine.d.ts +1183 -0
  147. package/dist/platform-machine.js +309 -0
  148. package/dist/platform-machine.js.map +1 -0
  149. package/dist/platform-settings-cuor3i11.d.cts +48 -0
  150. package/dist/platform-settings-cuor3i11.d.ts +48 -0
  151. package/dist/prefabs.cjs +36 -0
  152. package/dist/prefabs.cjs.map +1 -0
  153. package/dist/prefabs.d.cts +49 -0
  154. package/dist/prefabs.d.ts +49 -0
  155. package/dist/prefabs.js +8 -0
  156. package/dist/prefabs.js.map +1 -0
  157. package/dist/preview.cjs +2609 -0
  158. package/dist/preview.cjs.map +1 -0
  159. package/dist/preview.d.cts +155 -0
  160. package/dist/preview.d.ts +155 -0
  161. package/dist/preview.js +1671 -0
  162. package/dist/preview.js.map +1 -0
  163. package/dist/protocol.cjs +621 -54
  164. package/dist/protocol.cjs.map +1 -1
  165. package/dist/protocol.d.cts +76 -240
  166. package/dist/protocol.d.ts +76 -240
  167. package/dist/protocol.js +100 -2
  168. package/dist/protocol.js.map +1 -1
  169. package/dist/realtime-client-Cu8yVJFw.d.cts +15 -0
  170. package/dist/realtime-client-Cu8yVJFw.d.ts +15 -0
  171. package/dist/release.cjs +143 -0
  172. package/dist/release.cjs.map +1 -0
  173. package/dist/release.d.cts +64 -0
  174. package/dist/release.d.ts +64 -0
  175. package/dist/release.js +43 -0
  176. package/dist/release.js.map +1 -0
  177. package/dist/standard-match-phase-BucA5dYo.d.ts +44 -0
  178. package/dist/standard-match-phase-U2ra8J-0.d.cts +44 -0
  179. package/dist/sync-B6QsNrXz.d.cts +125 -0
  180. package/dist/sync-B6QsNrXz.d.ts +125 -0
  181. package/dist/ui.cjs +2827 -0
  182. package/dist/ui.cjs.map +1 -0
  183. package/dist/ui.d.cts +320 -0
  184. package/dist/ui.d.ts +320 -0
  185. package/dist/ui.js +1718 -0
  186. package/dist/ui.js.map +1 -0
  187. package/dist/url-policy-C89zxgw9.d.cts +9 -0
  188. package/dist/url-policy-C89zxgw9.d.ts +9 -0
  189. package/package.json +149 -11
  190. package/src/agent/agent-action.ts +304 -0
  191. package/src/agent/agent-contract.ts +180 -0
  192. package/src/agent-tooling.ts +20 -0
  193. package/src/arcade/bridge/controller.ts +15 -0
  194. package/src/arcade/bridge/host.ts +12 -0
  195. package/src/arcade/bridge/iframe.ts +61 -0
  196. package/src/arcade/bridge.ts +3 -0
  197. package/src/arcade/host.ts +1 -0
  198. package/src/arcade/surface.ts +4 -0
  199. package/src/arcade/url.ts +60 -0
  200. package/src/arcade.ts +4 -0
  201. package/src/audio/audio-manager.ts +162 -171
  202. package/src/audio/hooks.tsx +218 -97
  203. package/src/audio/index.ts +1 -1
  204. package/src/audio/music.tsx +139 -0
  205. package/src/capabilities/manifest.ts +71 -0
  206. package/src/capabilities.ts +12 -0
  207. package/src/components/connection-status-pill.tsx +55 -0
  208. package/src/components/controller-player-name-field.tsx +119 -0
  209. package/src/components/controller-primary-action.tsx +58 -0
  210. package/src/components/host-mute-button.tsx +49 -0
  211. package/src/components/join-qr-overlay.tsx +133 -0
  212. package/src/components/join-url-action-buttons.tsx +95 -0
  213. package/src/components/join-url-controls.tsx +58 -0
  214. package/src/components/join-url-field.tsx +52 -0
  215. package/src/components/lifecycle-action-group.tsx +129 -0
  216. package/src/components/player-avatar-strip.tsx +65 -0
  217. package/src/components/player-avatar.tsx +42 -13
  218. package/src/components/room-qr-code.tsx +125 -0
  219. package/src/components/runtime-shell-header.tsx +37 -0
  220. package/src/components/shell-classes.ts +19 -0
  221. package/src/components/surface-orientation-layout.ts +60 -0
  222. package/src/components/surface-viewport-layout.ts +268 -0
  223. package/src/components/surface-viewport.tsx +314 -0
  224. package/src/components/ui/button.tsx +4 -6
  225. package/src/components/ui/slider.tsx +1 -1
  226. package/src/components/volume-controls.tsx +65 -6
  227. package/src/context/air-jam-context.tsx +209 -161
  228. package/src/context/index.ts +2 -2
  229. package/src/context/session-providers.tsx +77 -0
  230. package/src/context/session-scope.ts +64 -0
  231. package/src/context/socket-manager.ts +6 -24
  232. package/src/contracts/v2/bridge.ts +261 -0
  233. package/src/contracts/v2/handshake.ts +40 -0
  234. package/src/contracts/v2/index.ts +2 -0
  235. package/src/dev/browser-log-sink.ts +912 -0
  236. package/src/diagnostics.ts +128 -0
  237. package/src/events.ts +7 -34
  238. package/src/hooks/internal/use-controller-runtime-api.ts +875 -0
  239. package/src/hooks/internal/use-host-runtime-api.ts +1051 -0
  240. package/src/hooks/internal/use-runtime-control-contract.ts +15 -0
  241. package/src/hooks/internal/use-runtime-inspection-contract.ts +16 -0
  242. package/src/hooks/internal/use-runtime-observability-contract.ts +24 -0
  243. package/src/hooks/use-air-jam-controller.ts +155 -475
  244. package/src/hooks/use-air-jam-host.ts +156 -485
  245. package/src/hooks/use-connection-status.ts +8 -0
  246. package/src/hooks/use-controller-lifecycle-intents.ts +27 -0
  247. package/src/hooks/use-controller-lifecycle-permissions.ts +36 -0
  248. package/src/hooks/use-controller-shell-status.ts +40 -0
  249. package/src/hooks/use-controller-tick.ts +65 -0
  250. package/src/hooks/use-controller-toasts.ts +116 -0
  251. package/src/hooks/use-get-input.ts +8 -5
  252. package/src/hooks/use-host-arcade-restore.ts +30 -0
  253. package/src/hooks/use-host-join-controls.ts +152 -0
  254. package/src/hooks/use-host-tick.ts +171 -0
  255. package/src/hooks/use-input-writer.ts +83 -0
  256. package/src/hooks/use-lifecycle-action-group-model.ts +98 -0
  257. package/src/hooks/use-players.ts +12 -0
  258. package/src/hooks/use-room.ts +22 -0
  259. package/src/hooks/use-send-signal.ts +6 -2
  260. package/src/index.ts +205 -31
  261. package/src/internal/input-manager.ts +195 -215
  262. package/src/lifecycle/index.ts +9 -0
  263. package/src/lifecycle/standard-match-phase.ts +32 -0
  264. package/src/metadata/manifest.ts +152 -0
  265. package/src/metadata.ts +12 -0
  266. package/src/platform-machine.ts +475 -0
  267. package/src/prefabs/types.ts +82 -0
  268. package/src/prefabs.ts +12 -0
  269. package/src/preview/host-workspace.tsx +59 -0
  270. package/src/preview/identity.ts +66 -0
  271. package/src/preview/layout.ts +223 -0
  272. package/src/preview/manager.ts +577 -0
  273. package/src/preview/messages.ts +26 -0
  274. package/src/preview/ownership.ts +81 -0
  275. package/src/preview/url.ts +117 -0
  276. package/src/preview/window.tsx +490 -0
  277. package/src/preview/workspace.tsx +678 -0
  278. package/src/preview.ts +42 -0
  279. package/src/protocol/arcade-platform-actions.ts +29 -0
  280. package/src/protocol/controller.ts +187 -0
  281. package/src/protocol/core.ts +23 -0
  282. package/src/protocol/dev-log-events.ts +222 -0
  283. package/src/protocol/errors.ts +21 -0
  284. package/src/protocol/host-grant.ts +185 -0
  285. package/src/protocol/host.ts +138 -0
  286. package/src/protocol/notices.ts +43 -0
  287. package/src/protocol/signals.ts +38 -0
  288. package/src/protocol/socket-events.ts +154 -0
  289. package/src/protocol/sync.ts +121 -0
  290. package/src/protocol/url-policy.ts +63 -0
  291. package/src/protocol.ts +12 -386
  292. package/src/qrcode.d.ts +16 -0
  293. package/src/release.ts +99 -0
  294. package/src/runtime/air-jam-config.ts +287 -0
  295. package/src/runtime/air-jam-error-boundary.tsx +672 -0
  296. package/src/runtime/arcade-bridge-request-surface.ts +15 -0
  297. package/src/runtime/arcade-runtime-url.ts +95 -0
  298. package/src/runtime/arcade-surface-identity.ts +16 -0
  299. package/src/runtime/contracts/control.ts +68 -0
  300. package/src/runtime/contracts/inspection.ts +165 -0
  301. package/src/runtime/contracts/observability.ts +94 -0
  302. package/src/runtime/controller-bridge.ts +451 -0
  303. package/src/runtime/controller-identity.ts +132 -0
  304. package/src/runtime/controller-presentation.ts +24 -0
  305. package/src/runtime/controller-realtime-client.ts +591 -0
  306. package/src/runtime/create-air-jam-app.tsx +260 -0
  307. package/src/runtime/dev-runtime-events.ts +36 -0
  308. package/src/runtime/embedded-runtime-adapters.ts +68 -0
  309. package/src/runtime/host-bridge.ts +388 -0
  310. package/src/runtime/host-realtime-client.ts +550 -0
  311. package/src/runtime/iframe-bridge.ts +135 -0
  312. package/src/runtime/realtime-client.ts +20 -0
  313. package/src/runtime/router-basename.ts +25 -0
  314. package/src/runtime/runtime-owner-contexts.tsx +4 -0
  315. package/src/runtime/runtime-session-params.ts +169 -0
  316. package/src/runtime/sdk-version.ts +6 -0
  317. package/src/runtime/session-runtimes.tsx +188 -0
  318. package/src/runtime/validate-arcade-bridge-attach.ts +14 -0
  319. package/src/runtime-control.ts +10 -0
  320. package/src/runtime-inspection.ts +14 -0
  321. package/src/runtime-observability.ts +9 -0
  322. package/src/settings/platform-settings-bridge.ts +336 -0
  323. package/src/settings/platform-settings-runtime.tsx +387 -0
  324. package/src/settings/platform-settings.ts +288 -0
  325. package/src/state/connection-store.ts +80 -12
  326. package/src/store/air-jam-store-domain-constants.ts +4 -0
  327. package/src/store/create-air-jam-store.ts +1094 -227
  328. package/src/styles.css +4 -38
  329. package/src/ui.ts +29 -0
  330. package/src/utils/is-rpc-serializable.ts +56 -0
  331. package/src/utils/player-avatar-url.ts +48 -0
  332. package/src/utils/url-builder.ts +7 -0
  333. package/dist/.tsbuildinfo +0 -1
  334. package/dist/chunk-B5DURUWT.js +0 -80
  335. package/dist/chunk-B5DURUWT.js.map +0 -1
  336. package/src/AirJamClient.ts +0 -224
  337. package/src/audio/volume-store.ts +0 -124
  338. package/src/components/controller-shell.tsx +0 -346
  339. package/src/components/host-shell.tsx +0 -520
  340. package/src/components/qr-scanner-dialog.tsx +0 -373
  341. package/src/components/ui/alert.tsx +0 -66
  342. package/src/components/ui/avatar.tsx +0 -46
  343. package/src/components/ui/badge.tsx +0 -47
  344. package/src/components/ui/card.tsx +0 -92
  345. package/src/components/ui/dialog.tsx +0 -122
  346. package/src/components/ui/tabs.tsx +0 -64
  347. package/src/hooks/use-air-jam-shell.ts +0 -379
  348. package/src/hooks/use-fullscreen.ts +0 -108
package/dist/ui.cjs ADDED
@@ -0,0 +1,2827 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/ui.ts
31
+ var ui_exports = {};
32
+ __export(ui_exports, {
33
+ AIRJAM_DEFAULT_AVATAR_SEEDS: () => AIRJAM_DEFAULT_AVATAR_SEEDS,
34
+ Button: () => Button,
35
+ ConnectionStatusPill: () => ConnectionStatusPill,
36
+ ControllerPlayerNameField: () => ControllerPlayerNameField,
37
+ ControllerPrimaryAction: () => ControllerPrimaryAction,
38
+ HostMuteButton: () => HostMuteButton,
39
+ JoinQrOverlay: () => JoinQrOverlay,
40
+ JoinUrlActionButtons: () => JoinUrlActionButtons,
41
+ JoinUrlControls: () => JoinUrlControls,
42
+ JoinUrlField: () => JoinUrlField,
43
+ LifecycleActionGroup: () => LifecycleActionGroup,
44
+ PlayerAvatar: () => PlayerAvatar,
45
+ PlayerAvatarStrip: () => PlayerAvatarStrip,
46
+ RoomQrCode: () => RoomQrCode,
47
+ RuntimeShellHeader: () => RuntimeShellHeader,
48
+ Slider: () => Slider,
49
+ SurfaceViewport: () => SurfaceViewport,
50
+ VolumeControls: () => VolumeControls,
51
+ buttonVariants: () => buttonVariants,
52
+ getDiceBearAdventurerNeutralUrl: () => getDiceBearAdventurerNeutralUrl,
53
+ getPlayerAvatarImageUrl: () => getPlayerAvatarImageUrl,
54
+ resolvePlayerAvatarSeed: () => resolvePlayerAvatarSeed,
55
+ useControllerLifecycleIntents: () => useControllerLifecycleIntents,
56
+ useControllerLifecyclePermissions: () => useControllerLifecyclePermissions,
57
+ useControllerShellStatus: () => useControllerShellStatus,
58
+ useHostJoinControls: () => useHostJoinControls,
59
+ useLifecycleActionGroupModel: () => useLifecycleActionGroupModel
60
+ });
61
+ module.exports = __toCommonJS(ui_exports);
62
+
63
+ // src/utils/cn.ts
64
+ var import_clsx = require("clsx");
65
+ var import_tailwind_merge = require("tailwind-merge");
66
+ var cn = (...inputs) => (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
67
+
68
+ // src/components/connection-status-pill.tsx
69
+ var import_jsx_runtime = require("react/jsx-runtime");
70
+ var statusLabelByConnection = {
71
+ connected: "Live",
72
+ connecting: "Syncing",
73
+ reconnecting: "Syncing",
74
+ disconnected: "Offline",
75
+ idle: "Idle"
76
+ };
77
+ var statusToneByConnection = {
78
+ connected: "border-emerald-400/18 bg-emerald-400/8 text-emerald-50",
79
+ connecting: "border-amber-400/18 bg-amber-400/8 text-amber-50",
80
+ reconnecting: "border-amber-400/18 bg-amber-400/8 text-amber-50",
81
+ disconnected: "border-rose-400/18 bg-rose-400/8 text-rose-50",
82
+ idle: "border-white/10 bg-white/[0.05] text-white/78"
83
+ };
84
+ var statusDotToneByConnection = {
85
+ connected: "bg-emerald-300",
86
+ connecting: "bg-amber-300",
87
+ reconnecting: "bg-amber-300",
88
+ disconnected: "bg-rose-300",
89
+ idle: "bg-white/45"
90
+ };
91
+ var ConnectionStatusPill = ({
92
+ status,
93
+ className
94
+ }) => {
95
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
96
+ "span",
97
+ {
98
+ className: cn(
99
+ "inline-flex shrink-0 items-center gap-1.5 rounded-full border px-2.5 py-1 text-[0.625rem] font-semibold tracking-[0.16em] uppercase",
100
+ statusToneByConnection[status],
101
+ className
102
+ ),
103
+ children: [
104
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
105
+ "span",
106
+ {
107
+ className: cn(
108
+ "h-1.5 w-1.5 shrink-0 rounded-full",
109
+ statusDotToneByConnection[status]
110
+ ),
111
+ "aria-hidden": true
112
+ }
113
+ ),
114
+ statusLabelByConnection[status]
115
+ ]
116
+ }
117
+ );
118
+ };
119
+
120
+ // src/components/controller-player-name-field.tsx
121
+ var import_react5 = require("react");
122
+
123
+ // src/hooks/use-air-jam-controller.ts
124
+ var import_react4 = require("react");
125
+ var import_zustand3 = require("zustand");
126
+ var import_shallow2 = require("zustand/react/shallow");
127
+
128
+ // src/context/air-jam-context.tsx
129
+ var import_runtime_topology3 = require("@air-jam/runtime-topology");
130
+ var import_react = require("react");
131
+ var import_zustand2 = require("zustand");
132
+ var import_shallow = require("zustand/react/shallow");
133
+
134
+ // src/dev/browser-log-sink.ts
135
+ var import_runtime_topology = require("@air-jam/runtime-topology");
136
+
137
+ // src/diagnostics.ts
138
+ var listeners = /* @__PURE__ */ new Set();
139
+ var lastEmissionByKey = /* @__PURE__ */ new Map();
140
+ var DIAGNOSTIC_THROTTLE_MS = 1500;
141
+ var diagnosticsEnabledOverride = null;
142
+ var shouldEmitDiagnostics = () => {
143
+ if (diagnosticsEnabledOverride !== null) {
144
+ return diagnosticsEnabledOverride;
145
+ }
146
+ const nodeEnv = globalThis.process?.env?.NODE_ENV;
147
+ if (typeof nodeEnv === "string") {
148
+ return nodeEnv !== "production";
149
+ }
150
+ return true;
151
+ };
152
+ var toConsolePrefix = (code) => `[AirJam][${code}]`;
153
+ var emitAirJamDiagnostic = (input) => {
154
+ if (!shouldEmitDiagnostics()) {
155
+ return;
156
+ }
157
+ const now = Date.now();
158
+ const key = `${input.code}|${input.message}`;
159
+ const last = lastEmissionByKey.get(key);
160
+ if (last && now - last < DIAGNOSTIC_THROTTLE_MS) {
161
+ return;
162
+ }
163
+ lastEmissionByKey.set(key, now);
164
+ const diagnostic = {
165
+ ...input,
166
+ timestamp: now
167
+ };
168
+ for (const listener of listeners) {
169
+ listener(diagnostic);
170
+ }
171
+ const logger = input.severity === "error" ? console.error : console.warn;
172
+ if (input.details) {
173
+ logger(`${toConsolePrefix(input.code)} ${input.message}`, input.details);
174
+ return;
175
+ }
176
+ logger(`${toConsolePrefix(input.code)} ${input.message}`);
177
+ };
178
+ var createAirJamDiagnosticError = (code, message, details) => {
179
+ emitAirJamDiagnostic({
180
+ code,
181
+ severity: "error",
182
+ message,
183
+ details
184
+ });
185
+ const error = new Error(`${toConsolePrefix(code)} ${message}`);
186
+ Object.defineProperty(error, "code", {
187
+ value: code,
188
+ enumerable: true
189
+ });
190
+ return error;
191
+ };
192
+
193
+ // src/protocol/controller.ts
194
+ var import_zod2 = require("zod");
195
+
196
+ // src/protocol/core.ts
197
+ var import_zod = require("zod");
198
+ var roomCodeSchema = import_zod.z.string().trim().min(4).max(8).regex(/^[A-Z0-9]+$/, { message: "room code must contain only A-Z or 0-9" });
199
+
200
+ // src/protocol/controller.ts
201
+ var controllerInputSchema = import_zod2.z.object({
202
+ roomId: roomCodeSchema,
203
+ controllerId: import_zod2.z.string().min(3),
204
+ input: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.unknown())
205
+ });
206
+ var controllerOrientationSchema = import_zod2.z.enum(["portrait", "landscape"]);
207
+ var controllerSourceSchema = import_zod2.z.enum(["phone", "preview", "virtual"]);
208
+ var controllerStateSchema = import_zod2.z.object({
209
+ roomId: roomCodeSchema,
210
+ state: import_zod2.z.object({
211
+ orientation: controllerOrientationSchema.optional(),
212
+ message: import_zod2.z.string().optional(),
213
+ roomSettings: import_zod2.z.object({
214
+ audio: import_zod2.z.object({
215
+ masterVolume: import_zod2.z.number().min(0).max(1),
216
+ musicVolume: import_zod2.z.number().min(0).max(1),
217
+ sfxVolume: import_zod2.z.number().min(0).max(1)
218
+ }),
219
+ previewControllers: import_zod2.z.object({
220
+ activeOpacity: import_zod2.z.number().min(0).max(1)
221
+ })
222
+ }).optional(),
223
+ runtimeState: import_zod2.z.enum(["paused", "playing"]).optional(),
224
+ stateVersion: import_zod2.z.number().int().nonnegative().optional()
225
+ })
226
+ });
227
+ var controllerJoinSchema = import_zod2.z.object({
228
+ roomId: roomCodeSchema,
229
+ controllerId: import_zod2.z.string().min(3),
230
+ /**
231
+ * Stable local controller device identity used as a reconnect hint.
232
+ * Older clients may omit this and fall back to controllerId-only behavior.
233
+ */
234
+ deviceId: import_zod2.z.string().min(8).max(128).optional(),
235
+ nickname: import_zod2.z.string().trim().min(1).max(24).optional(),
236
+ /** Preset avatar key (platform-defined); optional at join. */
237
+ avatarId: import_zod2.z.string().trim().min(1).max(48).optional(),
238
+ capabilityToken: import_zod2.z.string().min(1).optional()
239
+ });
240
+ var controllerLeaveSchema = import_zod2.z.object({
241
+ roomId: roomCodeSchema,
242
+ controllerId: import_zod2.z.string().min(3)
243
+ });
244
+ var controllerSystemSchema = import_zod2.z.object({
245
+ roomId: roomCodeSchema,
246
+ command: import_zod2.z.enum(["exit", "pause", "resume"])
247
+ });
248
+ var playerProfilePatchSchema = import_zod2.z.object({
249
+ label: import_zod2.z.string().trim().min(1).max(24).optional(),
250
+ avatarId: import_zod2.z.string().trim().min(1).max(48).optional()
251
+ }).strict();
252
+ var controllerUpdatePlayerProfileSchema = import_zod2.z.object({
253
+ roomId: roomCodeSchema,
254
+ controllerId: import_zod2.z.string().min(3),
255
+ patch: playerProfilePatchSchema
256
+ }).refine(
257
+ (data) => data.patch.label !== void 0 || data.patch.avatarId !== void 0,
258
+ { message: "patch must include at least one field" }
259
+ );
260
+ var controllerPrivilegedGrantSchema = import_zod2.z.enum([
261
+ "system",
262
+ "play_sound",
263
+ "action_rpc"
264
+ ]);
265
+ var controllerPrivilegedCapabilitySchema = import_zod2.z.object({
266
+ token: import_zod2.z.string().min(1),
267
+ expiresAt: import_zod2.z.number().int().positive(),
268
+ grants: import_zod2.z.array(controllerPrivilegedGrantSchema).min(1)
269
+ });
270
+
271
+ // src/protocol/dev-log-events.ts
272
+ var AIRJAM_DEV_LOG_EVENTS = {
273
+ server: {
274
+ started: "server.started",
275
+ startupFailed: "server.startup.failed"
276
+ },
277
+ socket: {
278
+ connected: "socket.connected",
279
+ disconnected: "socket.disconnected"
280
+ },
281
+ auth: {
282
+ modeDisabled: "auth.mode.disabled",
283
+ modeMasterKey: "auth.mode.master_key",
284
+ modeDatabaseAndHostGrant: "auth.mode.database_and_host_grant",
285
+ modeDatabase: "auth.mode.database",
286
+ modeHostGrantOnly: "auth.mode.host_grant_only",
287
+ backendMissing: "auth.backend.missing",
288
+ appIdLastUsedAtUpdateFailed: "auth.app_id_last_used_at_update.failed",
289
+ appIdVerificationDatabaseError: "auth.app_id_verification.database_error"
290
+ },
291
+ browser: {
292
+ logSessionStarted: "browser.log_session.started",
293
+ logBatchReceived: "browser.log_batch.received",
294
+ console: "browser.console",
295
+ windowError: "browser.window_error",
296
+ unhandledRejection: "browser.unhandled_rejection",
297
+ diagnostic: "browser.diagnostic",
298
+ runtime: "browser.runtime"
299
+ },
300
+ runtime: {
301
+ providerMounted: "runtime.provider.mounted",
302
+ providerUnmounted: "runtime.provider.unmounted",
303
+ windowBeforeUnload: "runtime.window.beforeunload",
304
+ windowPageHide: "runtime.window.pagehide",
305
+ socketConnected: "runtime.socket.connected",
306
+ socketDisconnected: "runtime.socket.disconnected",
307
+ socketConnectError: "runtime.socket.connect_error",
308
+ hostCreateRoomRequested: "runtime.host.create_room.requested",
309
+ hostReconnectRequested: "runtime.host.reconnect.requested",
310
+ hostReconnectRetryScheduled: "runtime.host.reconnect.retry_scheduled",
311
+ hostResetRoomRequested: "runtime.host.reset_room.requested",
312
+ hostStateReceived: "runtime.host.state.received",
313
+ controllerJoinRequested: "runtime.controller.join.requested",
314
+ controllerStateReceived: "runtime.controller.state.received",
315
+ phaseTransition: "runtime.phase.transition",
316
+ stateVersionReceived: "runtime.state_version.received",
317
+ invariantViolation: "runtime.invariant.violation",
318
+ embeddedBridgeRequested: "runtime.embedded_bridge.requested",
319
+ embeddedBridgeAttached: "runtime.embedded_bridge.attached",
320
+ embeddedBridgeRejected: "runtime.embedded_bridge.rejected",
321
+ embeddedBridgeClosed: "runtime.embedded_bridge.closed",
322
+ browserLogSinkFailure: "runtime.browser_log_sink.failure"
323
+ },
324
+ host: {
325
+ lifecycleRejected: "host.lifecycle.rejected",
326
+ bootstrapVerified: "host.bootstrap.verified",
327
+ bootstrapRejected: "host.bootstrap.rejected",
328
+ disconnectPendingRoomClose: "host.disconnect.pending_room_close",
329
+ disconnectRoomClosed: "host.disconnect.room_closed",
330
+ registerSystemAccepted: "host.register_system.accepted",
331
+ registerSystemRejected: "host.register_system.rejected",
332
+ createRoomAccepted: "host.create_room.accepted",
333
+ createRoomRejected: "host.create_room.rejected",
334
+ reconnectAccepted: "host.reconnect.accepted",
335
+ reconnectRejected: "host.reconnect.rejected",
336
+ resetRoomAccepted: "host.reset_room.accepted",
337
+ resetRoomRejected: "host.reset_room.rejected",
338
+ systemAccepted: "host.system.accepted",
339
+ systemRejected: "host.system.rejected",
340
+ stateRejected: "host.state.rejected",
341
+ signalRejected: "host.signal.rejected",
342
+ playSoundRejected: "host.play_sound.rejected",
343
+ stateBroadcastSummary: "host.state_broadcast.summary",
344
+ reconnectStateReconcile: "host.reconnect.state_reconcile",
345
+ stateSyncSummary: "host.state_sync.summary",
346
+ stateSyncRejected: "host.state_sync.rejected"
347
+ },
348
+ controller: {
349
+ joinAccepted: "controller.join.accepted",
350
+ joinRejected: "controller.join.rejected",
351
+ resumeAccepted: "controller.resume.accepted",
352
+ disconnectPendingResume: "controller.disconnect.pending_resume",
353
+ disconnectLeaseExpired: "controller.disconnect.lease_expired",
354
+ disconnectApplied: "controller.disconnect.applied",
355
+ profileUpdateAccepted: "controller.profile_update.accepted",
356
+ profileUpdateRejected: "controller.profile_update.rejected",
357
+ leaveAccepted: "controller.leave.accepted",
358
+ leaveRejected: "controller.leave.rejected",
359
+ inputSummary: "controller.input.summary",
360
+ inputDroppedSummary: "controller.input_dropped.summary",
361
+ inputRejected: "controller.input.rejected",
362
+ systemAccepted: "controller.system.accepted",
363
+ systemRejected: "controller.system.rejected",
364
+ playSoundRejected: "controller.play_sound.rejected",
365
+ actionRpcSummary: "controller.action_rpc.summary",
366
+ actionRpcRejected: "controller.action_rpc.rejected"
367
+ },
368
+ system: {
369
+ launchGameAccepted: "system.launch_game.accepted",
370
+ launchGameRejected: "system.launch_game.rejected",
371
+ closeGameAccepted: "system.close_game.accepted",
372
+ closeGameRejected: "system.close_game.rejected"
373
+ },
374
+ childHost: {
375
+ joinAccepted: "child_host.join.accepted",
376
+ joinRejected: "child_host.join.rejected",
377
+ disconnectPendingSystemFocus: "child_host.disconnect.pending_system_focus",
378
+ disconnectSystemFocusRestored: "child_host.disconnect.system_focus_restored"
379
+ },
380
+ embeddedGame: {
381
+ activateAccepted: "embedded_game.activate.accepted",
382
+ activateRejected: "embedded_game.activate.rejected"
383
+ }
384
+ };
385
+ var AIRJAM_BROWSER_LOG_EVENT_BY_SOURCE = {
386
+ console: AIRJAM_DEV_LOG_EVENTS.browser.console,
387
+ "window-error": AIRJAM_DEV_LOG_EVENTS.browser.windowError,
388
+ unhandledrejection: AIRJAM_DEV_LOG_EVENTS.browser.unhandledRejection,
389
+ diagnostic: AIRJAM_DEV_LOG_EVENTS.browser.diagnostic,
390
+ runtime: AIRJAM_DEV_LOG_EVENTS.browser.runtime
391
+ };
392
+
393
+ // src/protocol/host.ts
394
+ var import_zod3 = require("zod");
395
+ var hostSessionKindSchema = import_zod3.z.enum(["game", "system"]);
396
+ var childHostCapabilitySchema = import_zod3.z.object({
397
+ token: import_zod3.z.string().min(1),
398
+ expiresAt: import_zod3.z.number().int().positive()
399
+ });
400
+ var hostBootstrapSchema = import_zod3.z.object({
401
+ appId: import_zod3.z.string().optional(),
402
+ hostGrant: import_zod3.z.string().min(1).optional(),
403
+ hostSessionKind: hostSessionKindSchema.default("system")
404
+ });
405
+ var hostRegisterSystemSchema = import_zod3.z.object({
406
+ roomId: roomCodeSchema
407
+ });
408
+ var systemLaunchGameSchema = import_zod3.z.object({
409
+ roomId: roomCodeSchema,
410
+ gameId: import_zod3.z.string()
411
+ });
412
+ var hostJoinAsChildSchema = import_zod3.z.object({
413
+ roomId: roomCodeSchema,
414
+ capabilityToken: import_zod3.z.string().min(1)
415
+ });
416
+ var hostActivateEmbeddedGameSchema = import_zod3.z.object({
417
+ roomId: roomCodeSchema,
418
+ capabilityToken: import_zod3.z.string().min(1)
419
+ });
420
+ var hostCreateRoomSchema = import_zod3.z.object({
421
+ maxPlayers: import_zod3.z.number().int().min(1).max(16).default(8)
422
+ });
423
+ var hostReconnectSchema = import_zod3.z.object({
424
+ roomId: roomCodeSchema
425
+ });
426
+ var hostResetRoomSchema = import_zod3.z.object({
427
+ roomId: roomCodeSchema
428
+ });
429
+ var hostRemoveControllerSchema = import_zod3.z.object({
430
+ roomId: roomCodeSchema,
431
+ controllerId: import_zod3.z.string().min(3)
432
+ });
433
+
434
+ // src/protocol/host-grant.ts
435
+ var import_zod4 = require("zod");
436
+ var hostGrantScopeSchema = import_zod4.z.literal("host:bootstrap");
437
+ var hostGrantClaimsSchema = import_zod4.z.object({
438
+ typ: import_zod4.z.literal("airjam.host_grant.v1"),
439
+ appId: import_zod4.z.string().min(1),
440
+ exp: import_zod4.z.number().int().positive(),
441
+ iat: import_zod4.z.number().int().positive().optional(),
442
+ scopes: import_zod4.z.array(hostGrantScopeSchema).min(1).default(["host:bootstrap"]),
443
+ origins: import_zod4.z.array(import_zod4.z.string().min(1)).optional()
444
+ });
445
+ var encoder = new TextEncoder();
446
+ var decoder = new TextDecoder();
447
+
448
+ // src/protocol/sync.ts
449
+ var import_zod5 = require("zod");
450
+ var stateSyncRequestIdSchema = import_zod5.z.string().trim().min(1).max(128);
451
+ var airJamActionPayloadSchema = import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown());
452
+ var controllerActionRpcSchema = import_zod5.z.object({
453
+ roomId: roomCodeSchema,
454
+ actionName: import_zod5.z.string().trim().min(1),
455
+ payload: import_zod5.z.union([airJamActionPayloadSchema, import_zod5.z.undefined()]).optional(),
456
+ storeDomain: import_zod5.z.string().trim().min(1).max(128)
457
+ }).strict();
458
+ var hostActionRpcSchema = import_zod5.z.object({
459
+ roomId: roomCodeSchema,
460
+ actionName: import_zod5.z.string().trim().min(1),
461
+ payload: import_zod5.z.union([airJamActionPayloadSchema, import_zod5.z.undefined()]).optional(),
462
+ storeDomain: import_zod5.z.string().trim().min(1).max(128)
463
+ }).strict();
464
+ var hostStateSyncSchema = import_zod5.z.object({
465
+ roomId: roomCodeSchema,
466
+ data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()),
467
+ storeDomain: import_zod5.z.string().trim().min(1).max(128),
468
+ revision: import_zod5.z.number().int().nonnegative(),
469
+ requestId: stateSyncRequestIdSchema.optional()
470
+ }).strict();
471
+ var controllerStateSyncRequestSchema = import_zod5.z.object({
472
+ roomId: roomCodeSchema,
473
+ storeDomain: import_zod5.z.string().trim().min(1).max(128),
474
+ requestId: stateSyncRequestIdSchema.optional()
475
+ }).strict();
476
+
477
+ // src/protocol/url-policy.ts
478
+ var import_zod6 = require("zod");
479
+ var ALLOWED_RUNTIME_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]);
480
+ var parseRuntimeUrl = (value) => {
481
+ try {
482
+ const parsed = new URL(value);
483
+ if (!ALLOWED_RUNTIME_PROTOCOLS.has(parsed.protocol)) {
484
+ return null;
485
+ }
486
+ if (parsed.username || parsed.password) {
487
+ return null;
488
+ }
489
+ return parsed;
490
+ } catch {
491
+ return null;
492
+ }
493
+ };
494
+ var runtimeUrlSchema = import_zod6.z.string().trim().min(1).refine((value) => parseRuntimeUrl(value) !== null, {
495
+ message: "URL must be a valid http(s) URL without embedded credentials."
496
+ });
497
+
498
+ // src/runtime/air-jam-config.ts
499
+ var import_runtime_topology2 = require("@air-jam/runtime-topology");
500
+
501
+ // src/state/connection-store.ts
502
+ var import_zustand = require("zustand");
503
+
504
+ // src/settings/platform-settings.ts
505
+ var DEFAULT_PLATFORM_SETTINGS = {
506
+ audio: {
507
+ masterVolume: 1,
508
+ musicVolume: 0.8,
509
+ sfxVolume: 1
510
+ },
511
+ accessibility: {
512
+ reducedMotion: false,
513
+ highContrast: false
514
+ },
515
+ feedback: {
516
+ hapticsEnabled: true
517
+ },
518
+ previewControllers: {
519
+ activeOpacity: 1
520
+ }
521
+ };
522
+ var DEFAULT_ROOM_PLATFORM_SETTINGS = {
523
+ audio: DEFAULT_PLATFORM_SETTINGS.audio,
524
+ previewControllers: DEFAULT_PLATFORM_SETTINGS.previewControllers
525
+ };
526
+ var clamp01 = (value) => Math.max(0, Math.min(1, value));
527
+ var getEffectiveAudioVolume = (settings, category) => {
528
+ const categoryVolume = category === "music" ? settings.musicVolume : settings.sfxVolume;
529
+ return clamp01(settings.masterVolume) * clamp01(categoryVolume);
530
+ };
531
+
532
+ // src/context/socket-manager.ts
533
+ var import_socket = require("socket.io-client");
534
+
535
+ // src/context/air-jam-context.tsx
536
+ var import_jsx_runtime2 = require("react/jsx-runtime");
537
+ var AirJamContext = (0, import_react.createContext)(null);
538
+ var useAirJamContext = () => {
539
+ const context = (0, import_react.useContext)(AirJamContext);
540
+ if (!context) {
541
+ throw createAirJamDiagnosticError(
542
+ "AJ_MISSING_SESSION_PROVIDER",
543
+ "useAirJamContext must be used within a session provider. Wrap your app or component tree with <HostSessionProvider> or <ControllerSessionProvider>."
544
+ );
545
+ }
546
+ return context;
547
+ };
548
+
549
+ // src/context/session-scope.ts
550
+ var import_react2 = require("react");
551
+ var SessionScopeContext = (0, import_react2.createContext)("unscoped");
552
+ var RuntimeOwnerRegistryContext = (0, import_react2.createContext)(null);
553
+ var useSessionScope = () => {
554
+ return (0, import_react2.useContext)(SessionScopeContext);
555
+ };
556
+ var useAssertSessionScope = (expectedScope, hookName) => {
557
+ const scope = useSessionScope();
558
+ if (scope === expectedScope) {
559
+ return;
560
+ }
561
+ const expectedProviderName = expectedScope === "host" ? "HostSessionProvider" : "ControllerSessionProvider";
562
+ throw createAirJamDiagnosticError(
563
+ "AJ_SCOPE_MISMATCH",
564
+ `${hookName} requires ${expectedProviderName} when using scoped providers. Received scope "${scope}".`,
565
+ {
566
+ hookName,
567
+ expectedScope,
568
+ receivedScope: scope
569
+ }
570
+ );
571
+ };
572
+
573
+ // src/runtime/runtime-owner-contexts.tsx
574
+ var import_react3 = require("react");
575
+ var hostRuntimeContext = (0, import_react3.createContext)(null);
576
+ var controllerRuntimeContext = (0, import_react3.createContext)(null);
577
+
578
+ // src/hooks/use-air-jam-controller.ts
579
+ var toControllerState = (state) => {
580
+ const selfPlayer = state.controllerId ? state.players.find((player) => player.id === state.controllerId) ?? null : null;
581
+ return {
582
+ roomId: state.roomId,
583
+ controllerId: state.controllerId,
584
+ connectionStatus: state.connectionStatus,
585
+ lastError: state.lastError,
586
+ runtimeState: state.runtimeState,
587
+ controllerOrientation: state.controllerOrientation,
588
+ stateMessage: state.stateMessage,
589
+ roomSettings: state.roomSettings,
590
+ players: state.players,
591
+ selfPlayer
592
+ };
593
+ };
594
+ function useAirJamController(selector) {
595
+ useAssertSessionScope("controller", "useAirJamController");
596
+ const { store } = useAirJamContext();
597
+ const selectedState = (0, import_zustand3.useStore)(
598
+ store,
599
+ (0, import_shallow2.useShallow)((state) => {
600
+ const controllerState = toControllerState(state);
601
+ return selector ? selector(controllerState) : controllerState;
602
+ })
603
+ );
604
+ const runtime = (0, import_react4.useContext)(
605
+ controllerRuntimeContext
606
+ );
607
+ if (!runtime) {
608
+ throw createAirJamDiagnosticError(
609
+ "AJ_SCOPE_MISMATCH",
610
+ "useAirJamController requires a mounted controller runtime boundary. Wrap the controller tree with <AirJamControllerRuntime> or <airjam.Controller> before reading controller state.",
611
+ {
612
+ hookName: "useAirJamController",
613
+ expectedScope: "controller",
614
+ receivedScope: "controller"
615
+ }
616
+ );
617
+ }
618
+ if (selector) {
619
+ return selectedState;
620
+ }
621
+ return {
622
+ ...selectedState,
623
+ ...runtime
624
+ };
625
+ }
626
+
627
+ // src/components/controller-player-name-field.tsx
628
+ var import_jsx_runtime3 = require("react/jsx-runtime");
629
+ var LABEL_MAX = 24;
630
+ var DEFAULT_DEBOUNCE_MS = 400;
631
+ var ControllerPlayerNameField = ({
632
+ fieldLabel = "Your name",
633
+ className,
634
+ labelClassName,
635
+ inputClassName,
636
+ debounceMs = DEFAULT_DEBOUNCE_MS
637
+ }) => {
638
+ const controller = useAirJamController();
639
+ const [local, setLocal] = (0, import_react5.useState)("");
640
+ const inputRef = (0, import_react5.useRef)(null);
641
+ const debounceTimerRef = (0, import_react5.useRef)(null);
642
+ const nextPlayerLabel = controller.selfPlayer?.label?.trim() ?? "";
643
+ (0, import_react5.useEffect)(() => {
644
+ if (inputRef.current === document.activeElement) {
645
+ return;
646
+ }
647
+ setLocal(nextPlayerLabel);
648
+ }, [controller.controllerId, nextPlayerLabel]);
649
+ (0, import_react5.useEffect)(
650
+ () => () => {
651
+ if (debounceTimerRef.current !== null) {
652
+ clearTimeout(debounceTimerRef.current);
653
+ }
654
+ },
655
+ []
656
+ );
657
+ const pushRoomName = (0, import_react5.useCallback)(
658
+ (raw) => {
659
+ const trimmed = raw.trim().slice(0, LABEL_MAX);
660
+ if (trimmed.length < 1) {
661
+ return;
662
+ }
663
+ controller.setNickname(trimmed);
664
+ void controller.updatePlayerProfile({ label: trimmed });
665
+ },
666
+ [controller]
667
+ );
668
+ const schedulePush = (0, import_react5.useCallback)(
669
+ (raw) => {
670
+ if (debounceTimerRef.current !== null) {
671
+ clearTimeout(debounceTimerRef.current);
672
+ }
673
+ debounceTimerRef.current = setTimeout(() => {
674
+ debounceTimerRef.current = null;
675
+ pushRoomName(raw);
676
+ }, debounceMs);
677
+ },
678
+ [debounceMs, pushRoomName]
679
+ );
680
+ const connected = controller.connectionStatus === "connected";
681
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: cn("min-w-0", className), children: [
682
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
683
+ "label",
684
+ {
685
+ className: cn("mb-1 block", labelClassName),
686
+ htmlFor: "airjam-controller-player-name",
687
+ children: fieldLabel
688
+ }
689
+ ),
690
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
691
+ "input",
692
+ {
693
+ ref: inputRef,
694
+ id: "airjam-controller-player-name",
695
+ type: "text",
696
+ name: "airjam-controller-player-name",
697
+ autoComplete: "nickname",
698
+ enterKeyHint: "done",
699
+ maxLength: LABEL_MAX,
700
+ disabled: !connected,
701
+ value: local,
702
+ placeholder: connected ? "Enter name" : "Connect to edit",
703
+ className: cn(inputClassName),
704
+ onChange: (event) => {
705
+ const next = event.target.value.slice(0, LABEL_MAX);
706
+ setLocal(next);
707
+ schedulePush(next);
708
+ },
709
+ onBlur: () => {
710
+ if (debounceTimerRef.current !== null) {
711
+ clearTimeout(debounceTimerRef.current);
712
+ debounceTimerRef.current = null;
713
+ }
714
+ const trimmed = local.trim();
715
+ if (trimmed.length < 1) {
716
+ setLocal(nextPlayerLabel);
717
+ return;
718
+ }
719
+ pushRoomName(local);
720
+ }
721
+ }
722
+ )
723
+ ] });
724
+ };
725
+
726
+ // src/components/ui/button.tsx
727
+ var import_react_slot = require("@radix-ui/react-slot");
728
+ var import_class_variance_authority = require("class-variance-authority");
729
+ var import_jsx_runtime4 = require("react/jsx-runtime");
730
+ var buttonVariants = (0, import_class_variance_authority.cva)(
731
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all cursor-pointer disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 aria-invalid:border-destructive",
732
+ {
733
+ variants: {
734
+ variant: {
735
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
736
+ destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20",
737
+ outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground",
738
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
739
+ ghost: "text-foreground hover:bg-accent hover:text-accent-foreground",
740
+ link: "text-primary underline-offset-4 hover:underline"
741
+ },
742
+ size: {
743
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
744
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
745
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
746
+ icon: "size-9",
747
+ "icon-sm": "size-8",
748
+ "icon-lg": "size-10"
749
+ }
750
+ },
751
+ defaultVariants: {
752
+ variant: "default",
753
+ size: "default"
754
+ }
755
+ }
756
+ );
757
+ function Button({
758
+ className,
759
+ variant,
760
+ size,
761
+ asChild = false,
762
+ ...props
763
+ }) {
764
+ const Comp = asChild ? import_react_slot.Slot : "button";
765
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
766
+ Comp,
767
+ {
768
+ "data-slot": "button",
769
+ className: cn(buttonVariants({ variant, size, className })),
770
+ ...props
771
+ }
772
+ );
773
+ }
774
+
775
+ // src/components/controller-primary-action.tsx
776
+ var import_jsx_runtime5 = require("react/jsx-runtime");
777
+ var ControllerPrimaryAction = ({
778
+ label,
779
+ helper,
780
+ icon,
781
+ disabled,
782
+ onPress,
783
+ testId,
784
+ className,
785
+ buttonClassName
786
+ }) => {
787
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: cn("mt-auto pt-3", className), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
788
+ Button,
789
+ {
790
+ type: "button",
791
+ onClick: onPress,
792
+ disabled,
793
+ "data-testid": testId,
794
+ "aria-label": label,
795
+ title: label,
796
+ className: cn(
797
+ "flex h-auto min-h-18 w-full items-center justify-between rounded-[1.5rem] border border-white/15 px-5 py-4 text-left shadow-lg",
798
+ buttonClassName
799
+ ),
800
+ children: [
801
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "min-w-0", children: [
802
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "truncate text-base font-black tracking-[0.12em] uppercase sm:text-lg", children: label }),
803
+ helper ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mt-1 text-sm/5 font-medium tracking-normal normal-case opacity-80", children: helper }) : null
804
+ ] }),
805
+ icon ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "ml-4 flex shrink-0 items-center justify-center", children: icon }) : null
806
+ ]
807
+ }
808
+ ) });
809
+ };
810
+
811
+ // src/components/host-mute-button.tsx
812
+ var import_lucide_react = require("lucide-react");
813
+ var import_jsx_runtime6 = require("react/jsx-runtime");
814
+ function HostMuteButton({
815
+ muted,
816
+ onToggle,
817
+ className,
818
+ labelClassName,
819
+ mutedLabel = "Unmute",
820
+ unmutedLabel = "Mute"
821
+ }) {
822
+ const label = muted ? mutedLabel : unmutedLabel;
823
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
824
+ Button,
825
+ {
826
+ type: "button",
827
+ variant: "ghost",
828
+ size: "sm",
829
+ onClick: onToggle,
830
+ "aria-pressed": muted,
831
+ "aria-label": label,
832
+ title: label,
833
+ className: cn(
834
+ "rounded-full border border-white/25 bg-black/35 px-3 text-white backdrop-blur-sm hover:bg-black/55",
835
+ className
836
+ ),
837
+ children: [
838
+ muted ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react.VolumeX, { className: "size-4" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react.Volume2, { className: "size-4" }),
839
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
840
+ "span",
841
+ {
842
+ className: cn(
843
+ "text-[11px] font-semibold tracking-[0.16em] uppercase",
844
+ labelClassName
845
+ ),
846
+ children: label
847
+ }
848
+ )
849
+ ]
850
+ }
851
+ );
852
+ }
853
+
854
+ // src/components/join-qr-overlay.tsx
855
+ var import_react7 = require("react");
856
+
857
+ // src/components/room-qr-code.tsx
858
+ var import_qrcode = require("qrcode");
859
+ var import_react6 = require("react");
860
+ var import_jsx_runtime7 = require("react/jsx-runtime");
861
+ var RoomQrCode = ({
862
+ value,
863
+ size = 180,
864
+ padding = 1,
865
+ foregroundColor = "#111111",
866
+ backgroundColor = "#ffffff",
867
+ errorCorrectionLevel = "M",
868
+ className = "",
869
+ style,
870
+ alt = "Room join QR code"
871
+ }) => {
872
+ const trimmed = value.trim();
873
+ const qrKey = `${trimmed}\0${size}\0${padding}\0${foregroundColor}\0${backgroundColor}\0${errorCorrectionLevel}`;
874
+ const [qrState, setQrState] = (0, import_react6.useState)({
875
+ key: null,
876
+ dataUrl: null,
877
+ error: false
878
+ });
879
+ (0, import_react6.useEffect)(() => {
880
+ if (!trimmed) {
881
+ return;
882
+ }
883
+ let cancelled = false;
884
+ void (0, import_qrcode.toDataURL)(trimmed, {
885
+ width: size,
886
+ margin: padding,
887
+ errorCorrectionLevel,
888
+ color: {
889
+ dark: foregroundColor,
890
+ light: backgroundColor
891
+ }
892
+ }).then((nextUrl) => {
893
+ if (!cancelled) {
894
+ setQrState({
895
+ key: qrKey,
896
+ dataUrl: nextUrl,
897
+ error: false
898
+ });
899
+ }
900
+ }).catch(() => {
901
+ if (!cancelled) {
902
+ setQrState({
903
+ key: qrKey,
904
+ dataUrl: null,
905
+ error: true
906
+ });
907
+ }
908
+ });
909
+ return () => {
910
+ cancelled = true;
911
+ };
912
+ }, [
913
+ backgroundColor,
914
+ errorCorrectionLevel,
915
+ foregroundColor,
916
+ padding,
917
+ size,
918
+ qrKey,
919
+ trimmed
920
+ ]);
921
+ const imageSrc = trimmed && qrState.key === qrKey && qrState.dataUrl ? qrState.dataUrl : null;
922
+ const isLoading = !!trimmed && qrState.key !== qrKey;
923
+ const isUnavailable = !trimmed || qrState.key === qrKey && qrState.error;
924
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
925
+ "div",
926
+ {
927
+ className,
928
+ style: {
929
+ width: size,
930
+ height: size,
931
+ ...style
932
+ },
933
+ "aria-live": "polite",
934
+ "aria-label": alt,
935
+ children: imageSrc ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
936
+ "img",
937
+ {
938
+ src: imageSrc,
939
+ alt,
940
+ width: size,
941
+ height: size,
942
+ className: "h-full w-full rounded-md object-cover"
943
+ }
944
+ ) : isLoading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex h-full w-full flex-col items-center justify-center gap-2 rounded-md bg-black/15 text-xs text-white/70", children: [
945
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "h-5 w-5 animate-spin rounded-full border-2 border-white/20 border-t-white/80" }),
946
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: "Generating QR\u2026" })
947
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex h-full w-full items-center justify-center rounded-md bg-black/15 text-xs text-white/70", children: isUnavailable ? "QR unavailable" : "Generating QR\u2026" })
948
+ }
949
+ );
950
+ };
951
+
952
+ // src/components/shell-classes.ts
953
+ var shellHeaderClassName = "border-b border-white/10 bg-black/28 backdrop-blur-sm";
954
+ var shellLabelClassName = "text-[0.6875rem] font-semibold tracking-[0.22em] text-white/52 uppercase";
955
+ var shellHelperTextClassName = "text-sm leading-5 text-white/52";
956
+ var shellFieldClassName = "h-11 min-w-0 w-full rounded-2xl border border-white/10 bg-black/40 px-3.5 text-sm text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.03)] outline-none placeholder:text-white/35";
957
+ var shellUtilityButtonClassName = "rounded-2xl border-white/12 bg-white/[0.045] text-white/88 shadow-[inset_0_1px_0_rgba(255,255,255,0.03)] hover:bg-white/[0.085] hover:text-white disabled:border-white/8 disabled:bg-white/[0.03] disabled:text-white/35";
958
+ var shellPanelClassName = "rounded-[0.5rem] border border-white/10 bg-zinc-950/82 text-white shadow-[0_22px_70px_rgba(0,0,0,0.42)] backdrop-blur-md";
959
+
960
+ // src/components/join-qr-overlay.tsx
961
+ var import_jsx_runtime8 = require("react/jsx-runtime");
962
+ var JoinQrOverlay = ({
963
+ open,
964
+ value,
965
+ roomId,
966
+ onClose,
967
+ title = "Scan to join",
968
+ description = "Scan with your phone to connect as a controller.",
969
+ className,
970
+ panelClassName,
971
+ qrClassName,
972
+ size = 440
973
+ }) => {
974
+ const joinUrlValue = value?.trim() ?? "";
975
+ const hasJoinUrl = joinUrlValue.length > 0;
976
+ (0, import_react7.useEffect)(() => {
977
+ if (!open || typeof window === "undefined") {
978
+ return;
979
+ }
980
+ const handleKeyDown = (event) => {
981
+ if (event.key === "Escape") {
982
+ onClose?.();
983
+ }
984
+ };
985
+ window.addEventListener("keydown", handleKeyDown);
986
+ return () => {
987
+ window.removeEventListener("keydown", handleKeyDown);
988
+ };
989
+ }, [onClose, open]);
990
+ if (!open) {
991
+ return null;
992
+ }
993
+ const handlePanelClick = (event) => {
994
+ event.stopPropagation();
995
+ };
996
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
997
+ "div",
998
+ {
999
+ role: "dialog",
1000
+ "aria-modal": "true",
1001
+ "aria-label": roomId ? `Join room ${roomId}` : title,
1002
+ className: cn(
1003
+ "absolute inset-0 z-50 flex items-center justify-center bg-black/82 px-6 py-8 backdrop-blur-md",
1004
+ className
1005
+ ),
1006
+ onClick: onClose,
1007
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1008
+ "div",
1009
+ {
1010
+ className: cn(
1011
+ "flex w-full max-w-xl flex-col items-center gap-6 px-6 py-7 text-center",
1012
+ shellPanelClassName,
1013
+ panelClassName
1014
+ ),
1015
+ onClick: handlePanelClick,
1016
+ children: [
1017
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "space-y-1", children: [
1018
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "text-[0.6875rem] font-semibold tracking-[0.22em] text-white/52 uppercase", children: title }),
1019
+ roomId ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "text-3xl font-semibold tracking-[0.12em] text-white uppercase tabular-nums", children: roomId }) : null
1020
+ ] }),
1021
+ hasJoinUrl ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1022
+ RoomQrCode,
1023
+ {
1024
+ value: joinUrlValue,
1025
+ size,
1026
+ padding: 2,
1027
+ foregroundColor: "#111827",
1028
+ backgroundColor: "#ffffff",
1029
+ className: cn("rounded-xl bg-white shadow-sm", qrClassName),
1030
+ style: {
1031
+ width: "min(72vw, 26rem)",
1032
+ height: "auto",
1033
+ aspectRatio: "1 / 1"
1034
+ },
1035
+ alt: roomId ? `QR code to join room ${roomId}` : "QR code to join as a controller"
1036
+ }
1037
+ ) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex w-full max-w-[26rem] items-center justify-center rounded-xl border border-white/12 bg-white/6 px-5 py-10 text-sm leading-6 text-white/68", children: "Join URL unavailable right now." }),
1038
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "max-w-md text-sm leading-6 text-white/68", children: description }),
1039
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1040
+ Button,
1041
+ {
1042
+ type: "button",
1043
+ variant: "outline",
1044
+ onClick: onClose,
1045
+ className: cn("rounded-2xl px-5", shellUtilityButtonClassName),
1046
+ children: "Close"
1047
+ }
1048
+ )
1049
+ ]
1050
+ }
1051
+ )
1052
+ }
1053
+ );
1054
+ };
1055
+
1056
+ // src/components/join-url-action-buttons.tsx
1057
+ var import_lucide_react2 = require("lucide-react");
1058
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1059
+ var JoinUrlActionButtons = ({
1060
+ hasValue,
1061
+ copied = false,
1062
+ onCopy,
1063
+ onOpen,
1064
+ qrVisible = false,
1065
+ onToggleQr,
1066
+ className,
1067
+ buttonClassName
1068
+ }) => {
1069
+ const showsQrButton = typeof onToggleQr === "function";
1070
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1071
+ "div",
1072
+ {
1073
+ className: cn(
1074
+ "grid w-full gap-2",
1075
+ showsQrButton ? "grid-cols-3" : "grid-cols-2",
1076
+ className
1077
+ ),
1078
+ children: [
1079
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1080
+ Button,
1081
+ {
1082
+ type: "button",
1083
+ variant: "outline",
1084
+ disabled: !hasValue || !onCopy,
1085
+ onClick: onCopy,
1086
+ "aria-label": copied ? "Copied join link" : "Copy join link",
1087
+ title: copied ? "Copied" : "Copy join link",
1088
+ className: cn(
1089
+ "h-11 min-w-0 justify-center rounded-2xl px-3 text-sm",
1090
+ shellUtilityButtonClassName,
1091
+ buttonClassName
1092
+ ),
1093
+ children: [
1094
+ copied ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react2.Check, { className: "h-4 w-4", "aria-hidden": true }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react2.Copy, { className: "h-4 w-4", "aria-hidden": true }),
1095
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "truncate", children: copied ? "Copied" : "Copy" })
1096
+ ]
1097
+ }
1098
+ ),
1099
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1100
+ Button,
1101
+ {
1102
+ type: "button",
1103
+ variant: "outline",
1104
+ disabled: !hasValue || !onOpen,
1105
+ onClick: onOpen,
1106
+ "aria-label": "Open join link",
1107
+ title: "Open join link",
1108
+ className: cn(
1109
+ "h-11 min-w-0 justify-center rounded-2xl px-3 text-sm",
1110
+ shellUtilityButtonClassName,
1111
+ buttonClassName
1112
+ ),
1113
+ children: [
1114
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react2.ExternalLink, { className: "h-4 w-4", "aria-hidden": true }),
1115
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "truncate", children: "New tab" })
1116
+ ]
1117
+ }
1118
+ ),
1119
+ showsQrButton ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1120
+ Button,
1121
+ {
1122
+ type: "button",
1123
+ variant: "outline",
1124
+ disabled: !hasValue,
1125
+ "aria-pressed": qrVisible,
1126
+ onClick: onToggleQr,
1127
+ "aria-label": qrVisible ? "Hide join QR" : "Show join QR",
1128
+ title: qrVisible ? "Hide join QR" : "Show join QR",
1129
+ className: cn(
1130
+ "h-11 min-w-0 justify-center rounded-2xl px-3 text-sm",
1131
+ shellUtilityButtonClassName,
1132
+ buttonClassName
1133
+ ),
1134
+ children: [
1135
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react2.QrCode, { className: "h-4 w-4", "aria-hidden": true }),
1136
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "truncate", children: qrVisible ? "Hide QR" : "QR code" })
1137
+ ]
1138
+ }
1139
+ ) : null
1140
+ ]
1141
+ }
1142
+ );
1143
+ };
1144
+
1145
+ // src/components/join-url-field.tsx
1146
+ var import_react8 = require("react");
1147
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1148
+ var JoinUrlField = ({
1149
+ value,
1150
+ label = "Controller link",
1151
+ helperText,
1152
+ className,
1153
+ inputClassName,
1154
+ inputId,
1155
+ inputName = "airjam-controller-link"
1156
+ }) => {
1157
+ const hasValue = Boolean(value && value.trim().length > 0);
1158
+ const generatedInputId = (0, import_react8.useId)();
1159
+ const resolvedInputId = inputId ?? generatedInputId;
1160
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: cn("space-y-2.5", className), children: [
1161
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("label", { className: shellLabelClassName, htmlFor: resolvedInputId, children: label }),
1162
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1163
+ "input",
1164
+ {
1165
+ id: resolvedInputId,
1166
+ name: inputName,
1167
+ type: "text",
1168
+ readOnly: true,
1169
+ value: value ?? "",
1170
+ placeholder: hasValue ? void 0 : "Generating join link...",
1171
+ "aria-label": typeof label === "string" ? label : "Controller join link",
1172
+ className: cn(shellFieldClassName, inputClassName)
1173
+ }
1174
+ ),
1175
+ helperText ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: shellHelperTextClassName, children: helperText }) : null
1176
+ ] });
1177
+ };
1178
+
1179
+ // src/components/join-url-controls.tsx
1180
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1181
+ var JoinUrlControls = ({
1182
+ value,
1183
+ label = "Controller link",
1184
+ helperText,
1185
+ copied = false,
1186
+ onCopy,
1187
+ onOpen,
1188
+ qrVisible = false,
1189
+ onToggleQr,
1190
+ className,
1191
+ inputClassName,
1192
+ buttonClassName
1193
+ }) => {
1194
+ const hasValue = Boolean(value && value.trim().length > 0);
1195
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: cn("w-full space-y-3", className), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex flex-col gap-3", children: [
1196
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1197
+ JoinUrlField,
1198
+ {
1199
+ value,
1200
+ label,
1201
+ helperText,
1202
+ className: "w-full min-w-0",
1203
+ inputClassName
1204
+ }
1205
+ ),
1206
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1207
+ JoinUrlActionButtons,
1208
+ {
1209
+ hasValue,
1210
+ copied,
1211
+ onCopy,
1212
+ onOpen,
1213
+ qrVisible,
1214
+ onToggleQr,
1215
+ className: "w-full",
1216
+ buttonClassName
1217
+ }
1218
+ )
1219
+ ] }) });
1220
+ };
1221
+
1222
+ // src/components/lifecycle-action-group.tsx
1223
+ var import_lucide_react3 = require("lucide-react");
1224
+
1225
+ // src/hooks/use-lifecycle-action-group-model.ts
1226
+ var useLifecycleActionGroupModel = ({
1227
+ phase,
1228
+ runtimeState,
1229
+ canInteract = true,
1230
+ onStart,
1231
+ onTogglePause,
1232
+ onBackToLobby,
1233
+ onRestart,
1234
+ startLabel = "Start",
1235
+ restartLabel = "Restart",
1236
+ backLabel = "Back to Lobby",
1237
+ pauseLabel = "Pause",
1238
+ resumeLabel = "Resume"
1239
+ }) => {
1240
+ const isPaused = runtimeState === "paused";
1241
+ const actions = [];
1242
+ if (phase === "lobby" && onStart) {
1243
+ actions.push({
1244
+ kind: "start",
1245
+ label: startLabel,
1246
+ disabled: !canInteract,
1247
+ tone: "primary",
1248
+ onPress: onStart
1249
+ });
1250
+ }
1251
+ if (phase === "playing" && onTogglePause) {
1252
+ actions.push({
1253
+ kind: "pause-toggle",
1254
+ label: isPaused ? resumeLabel : pauseLabel,
1255
+ disabled: !canInteract,
1256
+ tone: "secondary",
1257
+ onPress: onTogglePause
1258
+ });
1259
+ }
1260
+ if (phase === "ended" && (onRestart || onStart)) {
1261
+ actions.push({
1262
+ kind: "restart",
1263
+ label: restartLabel,
1264
+ disabled: !canInteract,
1265
+ tone: "primary",
1266
+ onPress: onRestart ?? onStart
1267
+ });
1268
+ }
1269
+ if (phase !== "lobby" && onBackToLobby) {
1270
+ actions.push({
1271
+ kind: "back-to-lobby",
1272
+ label: backLabel,
1273
+ disabled: !canInteract,
1274
+ tone: "secondary",
1275
+ onPress: onBackToLobby
1276
+ });
1277
+ }
1278
+ return { isPaused, actions };
1279
+ };
1280
+
1281
+ // src/components/lifecycle-action-group.tsx
1282
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1283
+ var LifecycleActionGroup = ({
1284
+ phase,
1285
+ runtimeState,
1286
+ canInteract = true,
1287
+ onStart,
1288
+ onTogglePause,
1289
+ onBackToLobby,
1290
+ onRestart,
1291
+ startLabel = "Start",
1292
+ restartLabel = "Restart",
1293
+ backLabel = "Back to Lobby",
1294
+ presentation = "pill",
1295
+ visibleKinds,
1296
+ className,
1297
+ buttonClassName
1298
+ }) => {
1299
+ const { actions: allActions } = useLifecycleActionGroupModel({
1300
+ phase,
1301
+ runtimeState,
1302
+ canInteract,
1303
+ onStart,
1304
+ onTogglePause,
1305
+ onBackToLobby,
1306
+ onRestart,
1307
+ startLabel,
1308
+ restartLabel,
1309
+ backLabel
1310
+ });
1311
+ const actions = visibleKinds ? allActions.filter((action) => visibleKinds.includes(action.kind)) : allActions;
1312
+ if (actions.length === 0) {
1313
+ return null;
1314
+ }
1315
+ const renderIcon = (kind, label) => {
1316
+ switch (kind) {
1317
+ case "start":
1318
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.Play, { "aria-hidden": true, className: "size-4.5" });
1319
+ case "pause-toggle":
1320
+ return label.toLowerCase() === "resume" ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.Play, { "aria-hidden": true, className: "size-4.5" }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.Pause, { "aria-hidden": true, className: "size-4.5" });
1321
+ case "restart":
1322
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.RotateCcw, { "aria-hidden": true, className: "size-4.5" });
1323
+ case "back-to-lobby":
1324
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.House, { "aria-hidden": true, className: "size-4.5" });
1325
+ }
1326
+ };
1327
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1328
+ "div",
1329
+ {
1330
+ className: cn(
1331
+ "flex min-w-0 flex-nowrap items-center justify-end gap-1.5 overflow-x-auto",
1332
+ className
1333
+ ),
1334
+ children: actions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1335
+ Button,
1336
+ {
1337
+ type: "button",
1338
+ variant: presentation === "icon" ? action.tone === "primary" ? "secondary" : "ghost" : action.tone === "primary" ? "default" : "outline",
1339
+ size: presentation === "icon" ? "icon-sm" : void 0,
1340
+ onClick: action.onPress,
1341
+ disabled: action.disabled,
1342
+ "aria-label": action.label,
1343
+ title: action.label,
1344
+ className: cn(
1345
+ presentation === "icon" ? action.tone === "primary" ? "size-9 shrink-0 rounded-full border border-white/20 bg-white text-black hover:bg-white/90 sm:size-10" : "size-9 shrink-0 rounded-full border border-white/12 bg-white/6 text-white hover:bg-white/12 sm:size-10" : action.tone === "primary" ? "h-8 shrink-0 rounded-full border border-white/15 bg-white px-3 py-0 text-[9px] font-semibold tracking-[0.12em] whitespace-nowrap text-black uppercase hover:bg-white/90 sm:h-9 sm:px-4 sm:text-[10px] sm:tracking-[0.16em]" : "h-8 shrink-0 rounded-full border-white/15 bg-white/5 px-3 py-0 text-[9px] font-semibold tracking-[0.12em] whitespace-nowrap text-white uppercase hover:bg-white/10 sm:h-9 sm:px-4 sm:text-[10px] sm:tracking-[0.16em]",
1346
+ buttonClassName
1347
+ ),
1348
+ children: presentation === "icon" ? renderIcon(action.kind, action.label) : action.label
1349
+ },
1350
+ action.kind
1351
+ ))
1352
+ }
1353
+ );
1354
+ };
1355
+
1356
+ // src/components/player-avatar.tsx
1357
+ var import_lucide_react4 = require("lucide-react");
1358
+
1359
+ // src/utils/player-avatar-url.ts
1360
+ var DIEBEAR_ADVENTURER_NEUTRAL_SVG_BASE = "https://api.dicebear.com/9.x/adventurer-neutral/svg";
1361
+ var AIRJAM_DEFAULT_AVATAR_SEEDS = [
1362
+ "Aiko",
1363
+ "Brayden",
1364
+ "Caleb",
1365
+ "Dylan",
1366
+ "Emery",
1367
+ "Finley",
1368
+ "Grayson",
1369
+ "Harper"
1370
+ ];
1371
+ var resolvePlayerAvatarSeed = (player) => {
1372
+ const raw = player.avatarId?.trim();
1373
+ if (!raw) {
1374
+ return player.id;
1375
+ }
1376
+ const match = /^aj-(\d+)$/.exec(raw);
1377
+ if (match) {
1378
+ const index = Number(match[1]) - 1;
1379
+ if (index >= 0 && index < AIRJAM_DEFAULT_AVATAR_SEEDS.length) {
1380
+ return AIRJAM_DEFAULT_AVATAR_SEEDS[index];
1381
+ }
1382
+ }
1383
+ return raw;
1384
+ };
1385
+ var getDiceBearAdventurerNeutralUrl = (seed) => `${DIEBEAR_ADVENTURER_NEUTRAL_SVG_BASE}?seed=${encodeURIComponent(seed)}`;
1386
+ var getPlayerAvatarImageUrl = (player) => getDiceBearAdventurerNeutralUrl(resolvePlayerAvatarSeed(player));
1387
+
1388
+ // src/components/player-avatar.tsx
1389
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1390
+ var hexToRgba = (hex, opacity) => {
1391
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
1392
+ if (!result) return `rgba(0, 0, 0, ${opacity})`;
1393
+ const r = parseInt(result[1], 16);
1394
+ const g = parseInt(result[2], 16);
1395
+ const b = parseInt(result[3], 16);
1396
+ return `rgba(${r}, ${g}, ${b}, ${opacity})`;
1397
+ };
1398
+ var PlayerAvatar = ({
1399
+ player,
1400
+ isBot = false,
1401
+ size = "md",
1402
+ className = ""
1403
+ }) => {
1404
+ const accentColor = player.color || "hsl(var(--border))";
1405
+ const sizeClasses = {
1406
+ sm: "h-9 w-9 border-2",
1407
+ md: "h-12 w-12 border-4",
1408
+ lg: "h-16 w-16 border-4"
1409
+ };
1410
+ const shadowStyles = {
1411
+ sm: player.color ? `inset 0 0 4px rgba(0, 0, 0, 0.2), 0 0 8px ${hexToRgba(player.color, 0.4)}` : "inset 0 0 4px rgba(0, 0, 0, 0.2)",
1412
+ md: player.color ? `inset 0 0 10px rgba(0, 0, 0, 0.4), 0 0 20px ${hexToRgba(player.color, 0.6)}, 0 0 10px ${hexToRgba(player.color, 0.8)}` : "inset 0 0 10px rgba(0, 0, 0, 0.4), 0 0 20px hsl(var(--border) / 0.5)",
1413
+ lg: player.color ? `inset 0 0 12px rgba(0, 0, 0, 0.4), 0 0 24px ${hexToRgba(player.color, 0.6)}, 0 0 12px ${hexToRgba(player.color, 0.8)}` : "inset 0 0 12px rgba(0, 0, 0, 0.4), 0 0 24px hsl(var(--border) / 0.5)"
1414
+ };
1415
+ const iconSizeClasses = {
1416
+ sm: "h-4 w-4",
1417
+ md: "h-5 w-5",
1418
+ lg: "h-6 w-6"
1419
+ };
1420
+ const shellClassName = cn(
1421
+ "shrink-0 rounded-full shadow-lg",
1422
+ sizeClasses[size],
1423
+ className
1424
+ );
1425
+ if (isBot) {
1426
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1427
+ "div",
1428
+ {
1429
+ role: "img",
1430
+ "aria-label": player.label,
1431
+ className: cn(
1432
+ "bg-secondary/40 flex items-center justify-center",
1433
+ shellClassName
1434
+ ),
1435
+ style: {
1436
+ borderColor: accentColor,
1437
+ color: accentColor,
1438
+ boxShadow: shadowStyles[size]
1439
+ },
1440
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_lucide_react4.Bot, { "aria-hidden": "true", className: iconSizeClasses[size] })
1441
+ }
1442
+ );
1443
+ }
1444
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1445
+ "img",
1446
+ {
1447
+ src: getPlayerAvatarImageUrl(player),
1448
+ alt: player.label,
1449
+ className: cn("bg-secondary/30", shellClassName),
1450
+ style: {
1451
+ borderColor: accentColor,
1452
+ boxShadow: shadowStyles[size]
1453
+ }
1454
+ }
1455
+ );
1456
+ };
1457
+
1458
+ // src/components/player-avatar-strip.tsx
1459
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1460
+ var overflowSizeClasses = {
1461
+ sm: "h-9 w-9 min-h-9 min-w-9 text-[0.625rem]",
1462
+ md: "h-12 w-12 min-h-12 min-w-12 text-[11px]",
1463
+ lg: "h-16 w-16 min-h-16 min-w-16 text-xs"
1464
+ };
1465
+ var PlayerAvatarStrip = ({
1466
+ players,
1467
+ maxVisible = 4,
1468
+ size = "sm",
1469
+ className,
1470
+ avatarClassName = "",
1471
+ overflowBadgeClassName = ""
1472
+ }) => {
1473
+ const visible = players.slice(0, maxVisible);
1474
+ const overflow = Math.max(0, players.length - maxVisible);
1475
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: cn("flex items-center -space-x-2", className), children: [
1476
+ visible.map((player) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1477
+ PlayerAvatar,
1478
+ {
1479
+ player,
1480
+ size,
1481
+ className: avatarClassName
1482
+ },
1483
+ player.id
1484
+ )),
1485
+ overflow > 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
1486
+ "div",
1487
+ {
1488
+ className: cn(
1489
+ "bg-secondary/50 text-foreground flex shrink-0 items-center justify-center rounded-full border-2 border-[hsl(var(--border))] font-semibold tabular-nums shadow-sm",
1490
+ overflowSizeClasses[size],
1491
+ overflowBadgeClassName
1492
+ ),
1493
+ "aria-label": `${overflow} more players`,
1494
+ children: [
1495
+ "+",
1496
+ overflow
1497
+ ]
1498
+ }
1499
+ )
1500
+ ] });
1501
+ };
1502
+
1503
+ // src/components/runtime-shell-header.tsx
1504
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1505
+ var RuntimeShellHeader = ({
1506
+ connectionStatus,
1507
+ leftSlot,
1508
+ rightSlot,
1509
+ className
1510
+ }) => {
1511
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
1512
+ "header",
1513
+ {
1514
+ className: cn(
1515
+ "flex min-h-16 items-center gap-2.5 px-3 py-2.5 sm:px-4",
1516
+ shellHeaderClassName,
1517
+ className
1518
+ ),
1519
+ children: [
1520
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "min-w-0 flex-1", children: leftSlot }),
1521
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "flex shrink-0 items-center gap-2.5", children: [
1522
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(ConnectionStatusPill, { status: connectionStatus }),
1523
+ rightSlot ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "flex items-center justify-end", children: rightSlot }) : null
1524
+ ] })
1525
+ ]
1526
+ }
1527
+ );
1528
+ };
1529
+
1530
+ // src/components/surface-viewport.tsx
1531
+ var import_react9 = require("react");
1532
+
1533
+ // src/runtime/controller-bridge.ts
1534
+ var import_zod11 = require("zod");
1535
+
1536
+ // src/contracts/v2/bridge.ts
1537
+ var import_zod7 = require("zod");
1538
+ var roomCodeSchema2 = import_zod7.z.string().trim().min(4).max(8).regex(/^[A-Z0-9]+$/, {
1539
+ message: "room code must contain only A-Z or 0-9"
1540
+ });
1541
+ var runtimeStateSchema = import_zod7.z.enum(["paused", "playing"]);
1542
+ var playerProfileSchema = import_zod7.z.object({
1543
+ id: import_zod7.z.string().min(1),
1544
+ label: import_zod7.z.string().min(1),
1545
+ color: import_zod7.z.string().optional(),
1546
+ avatarId: import_zod7.z.string().optional()
1547
+ }).strict();
1548
+ var inputFrameEntrySchema = import_zod7.z.object({
1549
+ controllerId: import_zod7.z.string().min(1),
1550
+ input: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.unknown())
1551
+ }).strict();
1552
+ var V2_BRIDGE_PARENT_TO_GAME_TYPES = [
1553
+ "BOOTSTRAP",
1554
+ "PLAYERS_UPDATE",
1555
+ "RUNTIME_STATE_UPDATE",
1556
+ "INPUT_FRAME",
1557
+ "PAUSE",
1558
+ "RESUME",
1559
+ "SHUTDOWN"
1560
+ ];
1561
+ var V2_BRIDGE_GAME_TO_PARENT_TYPES = [
1562
+ "READY",
1563
+ "STATE_PATCH",
1564
+ "SIGNAL",
1565
+ "ERROR",
1566
+ "METRICS"
1567
+ ];
1568
+ var allMessageTypes = [
1569
+ ...V2_BRIDGE_PARENT_TO_GAME_TYPES,
1570
+ ...V2_BRIDGE_GAME_TO_PARENT_TYPES
1571
+ ];
1572
+ var knownBridgeMessageTypeSet = new Set(allMessageTypes);
1573
+ var bootstrapMessageSchema = import_zod7.z.object({
1574
+ type: import_zod7.z.literal("BOOTSTRAP"),
1575
+ payload: import_zod7.z.object({
1576
+ roomId: roomCodeSchema2,
1577
+ players: import_zod7.z.array(playerProfileSchema),
1578
+ state: import_zod7.z.object({
1579
+ runtimeState: runtimeStateSchema,
1580
+ message: import_zod7.z.string().optional()
1581
+ }).strict(),
1582
+ capabilities: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.boolean()).default({})
1583
+ }).strict()
1584
+ }).strict();
1585
+ var playersUpdateMessageSchema = import_zod7.z.object({
1586
+ type: import_zod7.z.literal("PLAYERS_UPDATE"),
1587
+ payload: import_zod7.z.object({
1588
+ players: import_zod7.z.array(playerProfileSchema)
1589
+ }).strict()
1590
+ }).strict();
1591
+ var runtimeStateUpdateMessageSchema = import_zod7.z.object({
1592
+ type: import_zod7.z.literal("RUNTIME_STATE_UPDATE"),
1593
+ payload: import_zod7.z.object({
1594
+ runtimeState: runtimeStateSchema,
1595
+ message: import_zod7.z.string().optional()
1596
+ }).strict()
1597
+ }).strict();
1598
+ var inputFrameMessageSchema = import_zod7.z.object({
1599
+ type: import_zod7.z.literal("INPUT_FRAME"),
1600
+ payload: import_zod7.z.object({
1601
+ frameId: import_zod7.z.number().int().nonnegative(),
1602
+ inputs: import_zod7.z.array(inputFrameEntrySchema)
1603
+ }).strict()
1604
+ }).strict();
1605
+ var pauseMessageSchema = import_zod7.z.object({
1606
+ type: import_zod7.z.literal("PAUSE"),
1607
+ payload: import_zod7.z.object({
1608
+ reason: import_zod7.z.string().optional()
1609
+ }).strict()
1610
+ }).strict();
1611
+ var resumeMessageSchema = import_zod7.z.object({
1612
+ type: import_zod7.z.literal("RESUME"),
1613
+ payload: import_zod7.z.object({}).strict()
1614
+ }).strict();
1615
+ var shutdownMessageSchema = import_zod7.z.object({
1616
+ type: import_zod7.z.literal("SHUTDOWN"),
1617
+ payload: import_zod7.z.object({
1618
+ reason: import_zod7.z.string().min(1)
1619
+ }).strict()
1620
+ }).strict();
1621
+ var readyMessageSchema = import_zod7.z.object({
1622
+ type: import_zod7.z.literal("READY"),
1623
+ payload: import_zod7.z.object({
1624
+ readyAtMs: import_zod7.z.number().int().nonnegative()
1625
+ }).strict()
1626
+ }).strict();
1627
+ var statePatchMessageSchema = import_zod7.z.object({
1628
+ type: import_zod7.z.literal("STATE_PATCH"),
1629
+ payload: import_zod7.z.object({
1630
+ patch: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.unknown())
1631
+ }).strict()
1632
+ }).strict();
1633
+ var signalMessageSchema = import_zod7.z.object({
1634
+ type: import_zod7.z.literal("SIGNAL"),
1635
+ payload: import_zod7.z.object({
1636
+ signalType: import_zod7.z.string().min(1),
1637
+ targetId: import_zod7.z.string().min(1).optional(),
1638
+ data: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.unknown())
1639
+ }).strict()
1640
+ }).strict();
1641
+ var errorMessageSchema = import_zod7.z.object({
1642
+ type: import_zod7.z.literal("ERROR"),
1643
+ payload: import_zod7.z.object({
1644
+ code: import_zod7.z.string().min(1),
1645
+ message: import_zod7.z.string().min(1),
1646
+ details: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.unknown()).optional()
1647
+ }).strict()
1648
+ }).strict();
1649
+ var metricsMessageSchema = import_zod7.z.object({
1650
+ type: import_zod7.z.literal("METRICS"),
1651
+ payload: import_zod7.z.object({
1652
+ values: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.number())
1653
+ }).strict()
1654
+ }).strict();
1655
+ var v2BridgeParentToGameMessageSchema = import_zod7.z.union([
1656
+ bootstrapMessageSchema,
1657
+ playersUpdateMessageSchema,
1658
+ runtimeStateUpdateMessageSchema,
1659
+ inputFrameMessageSchema,
1660
+ pauseMessageSchema,
1661
+ resumeMessageSchema,
1662
+ shutdownMessageSchema
1663
+ ]);
1664
+ var v2BridgeGameToParentMessageSchema = import_zod7.z.union([
1665
+ readyMessageSchema,
1666
+ statePatchMessageSchema,
1667
+ signalMessageSchema,
1668
+ errorMessageSchema,
1669
+ metricsMessageSchema
1670
+ ]);
1671
+ var v2BridgeMessageSchema = import_zod7.z.union([
1672
+ v2BridgeParentToGameMessageSchema,
1673
+ v2BridgeGameToParentMessageSchema
1674
+ ]);
1675
+
1676
+ // src/contracts/v2/handshake.ts
1677
+ var import_zod8 = require("zod");
1678
+ var AIR_JAM_PROTOCOL_V2 = "2";
1679
+ var semanticVersionPattern = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
1680
+ var v2ProtocolVersionSchema = import_zod8.z.literal(AIR_JAM_PROTOCOL_V2);
1681
+ var runtimeKindSchema = import_zod8.z.enum([
1682
+ "standalone-host",
1683
+ "standalone-controller",
1684
+ "arcade-runtime",
1685
+ "arcade-game-iframe",
1686
+ "arcade-host-runtime",
1687
+ "arcade-host-iframe",
1688
+ "arcade-controller-runtime",
1689
+ "arcade-controller-iframe"
1690
+ ]);
1691
+ var capabilityFlagsSchema = import_zod8.z.record(import_zod8.z.string(), import_zod8.z.boolean());
1692
+ var sdkVersionSchema = import_zod8.z.string().regex(
1693
+ semanticVersionPattern,
1694
+ "sdkVersion must use semantic version format (for example 1.2.3)"
1695
+ );
1696
+ var v2HandshakeSchema = import_zod8.z.object({
1697
+ protocolVersion: v2ProtocolVersionSchema,
1698
+ sdkVersion: sdkVersionSchema,
1699
+ runtimeKind: runtimeKindSchema,
1700
+ capabilityFlags: capabilityFlagsSchema.default({})
1701
+ }).strict();
1702
+
1703
+ // src/runtime/arcade-surface-identity.ts
1704
+ var import_zod9 = require("zod");
1705
+ var arcadeSurfaceRuntimeIdentitySchema = import_zod9.z.object({
1706
+ epoch: import_zod9.z.number().int().nonnegative(),
1707
+ kind: import_zod9.z.enum(["browser", "game"]),
1708
+ gameId: import_zod9.z.string().nullable()
1709
+ }).strict();
1710
+
1711
+ // src/runtime/iframe-bridge.ts
1712
+ var import_zod10 = require("zod");
1713
+ var AIRJAM_BRIDGE_INIT = "AIRJAM_BRIDGE_INIT";
1714
+ var AIRJAM_SETTINGS_SYNC = "AIRJAM_SETTINGS_SYNC";
1715
+ var AIRJAM_SETTINGS_READY = "AIRJAM_SETTINGS_READY";
1716
+ var airJamSettingsSyncSchema = import_zod10.z.object({
1717
+ type: import_zod10.z.literal(AIRJAM_SETTINGS_SYNC),
1718
+ payload: import_zod10.z.object({
1719
+ settings: import_zod10.z.object({
1720
+ audio: import_zod10.z.object({
1721
+ masterVolume: import_zod10.z.number(),
1722
+ musicVolume: import_zod10.z.number(),
1723
+ sfxVolume: import_zod10.z.number()
1724
+ }).strict(),
1725
+ accessibility: import_zod10.z.object({
1726
+ reducedMotion: import_zod10.z.boolean(),
1727
+ highContrast: import_zod10.z.boolean()
1728
+ }).strict(),
1729
+ feedback: import_zod10.z.object({
1730
+ hapticsEnabled: import_zod10.z.boolean()
1731
+ }).strict(),
1732
+ previewControllers: import_zod10.z.object({
1733
+ activeOpacity: import_zod10.z.number()
1734
+ }).strict()
1735
+ }).strict()
1736
+ }).strict()
1737
+ }).strict();
1738
+ var airJamBridgeInitSchema = import_zod10.z.object({
1739
+ type: import_zod10.z.literal(AIRJAM_BRIDGE_INIT),
1740
+ payload: import_zod10.z.object({
1741
+ handshake: v2HandshakeSchema
1742
+ }).strict()
1743
+ }).strict();
1744
+ var airJamSettingsReadySchema = import_zod10.z.object({
1745
+ type: import_zod10.z.literal(AIRJAM_SETTINGS_READY),
1746
+ payload: import_zod10.z.object({
1747
+ ready: import_zod10.z.literal(true)
1748
+ }).strict()
1749
+ }).strict();
1750
+
1751
+ // src/runtime/controller-bridge.ts
1752
+ var AIRJAM_CONTROLLER_BRIDGE_REQUEST = "AIRJAM_CONTROLLER_BRIDGE_REQUEST";
1753
+ var AIRJAM_CONTROLLER_BRIDGE_ATTACH = "AIRJAM_CONTROLLER_BRIDGE_ATTACH";
1754
+ var AIRJAM_CONTROLLER_BRIDGE_EVENT = "AIRJAM_CONTROLLER_BRIDGE_EVENT";
1755
+ var AIRJAM_CONTROLLER_BRIDGE_EMIT = "AIRJAM_CONTROLLER_BRIDGE_EMIT";
1756
+ var AIRJAM_CONTROLLER_BRIDGE_CLOSE = "AIRJAM_CONTROLLER_BRIDGE_CLOSE";
1757
+ var AIRJAM_CONTROLLER_PRESENTATION_SYNC = "AIRJAM_CONTROLLER_PRESENTATION_SYNC";
1758
+ var AIRJAM_CONTROLLER_BRIDGE_RESPONSE = "AIRJAM_CONTROLLER_BRIDGE_RESPONSE";
1759
+ var controllerBridgeClientEvents = [
1760
+ "controller:input",
1761
+ "controller:action_rpc",
1762
+ "controller:state_sync_request",
1763
+ "controller:system",
1764
+ "controller:play_sound",
1765
+ "controller:updatePlayerProfile"
1766
+ ];
1767
+ var controllerBridgeServerEvents = [
1768
+ "connect",
1769
+ "disconnect",
1770
+ "server:welcome",
1771
+ "server:controllerJoined",
1772
+ "server:controllerLeft",
1773
+ "server:state",
1774
+ "server:hostLeft",
1775
+ "server:error",
1776
+ "server:signal",
1777
+ "server:playSound",
1778
+ "server:playerUpdated",
1779
+ "airjam:state_sync"
1780
+ ];
1781
+ var bridgeRequestSchema = import_zod11.z.object({
1782
+ type: import_zod11.z.literal(AIRJAM_CONTROLLER_BRIDGE_REQUEST),
1783
+ payload: import_zod11.z.object({
1784
+ handshake: v2HandshakeSchema,
1785
+ roomId: import_zod11.z.string().min(1),
1786
+ controllerId: import_zod11.z.string().min(1),
1787
+ arcadeSurface: arcadeSurfaceRuntimeIdentitySchema
1788
+ }).strict()
1789
+ }).strict();
1790
+ var bridgeAttachSchema = import_zod11.z.object({
1791
+ type: import_zod11.z.literal(AIRJAM_CONTROLLER_BRIDGE_ATTACH),
1792
+ payload: import_zod11.z.object({
1793
+ handshake: v2HandshakeSchema,
1794
+ snapshot: import_zod11.z.object({
1795
+ roomId: import_zod11.z.string().min(1),
1796
+ controllerId: import_zod11.z.string().min(1),
1797
+ connected: import_zod11.z.boolean(),
1798
+ socketId: import_zod11.z.string().optional(),
1799
+ player: import_zod11.z.unknown().optional(),
1800
+ players: import_zod11.z.array(import_zod11.z.unknown()).optional(),
1801
+ state: import_zod11.z.unknown().optional(),
1802
+ arcadeSurface: arcadeSurfaceRuntimeIdentitySchema
1803
+ }).strict()
1804
+ }).strict()
1805
+ }).strict();
1806
+ var bridgeEventSchema = import_zod11.z.object({
1807
+ type: import_zod11.z.literal(AIRJAM_CONTROLLER_BRIDGE_EVENT),
1808
+ payload: import_zod11.z.object({
1809
+ event: import_zod11.z.enum(controllerBridgeServerEvents),
1810
+ args: import_zod11.z.array(import_zod11.z.unknown()),
1811
+ requestId: import_zod11.z.string().min(1).optional()
1812
+ }).strict()
1813
+ }).strict();
1814
+ var bridgeEmitSchema = import_zod11.z.object({
1815
+ type: import_zod11.z.literal(AIRJAM_CONTROLLER_BRIDGE_EMIT),
1816
+ payload: import_zod11.z.object({
1817
+ event: import_zod11.z.enum(controllerBridgeClientEvents),
1818
+ args: import_zod11.z.array(import_zod11.z.unknown()),
1819
+ requestId: import_zod11.z.string().min(1).optional()
1820
+ }).strict()
1821
+ }).strict();
1822
+ var bridgeResponseSchema = import_zod11.z.object({
1823
+ type: import_zod11.z.literal(AIRJAM_CONTROLLER_BRIDGE_RESPONSE),
1824
+ payload: import_zod11.z.object({
1825
+ requestId: import_zod11.z.string().min(1),
1826
+ ack: import_zod11.z.unknown()
1827
+ }).strict()
1828
+ }).strict();
1829
+ var bridgeCloseSchema = import_zod11.z.object({
1830
+ type: import_zod11.z.literal(AIRJAM_CONTROLLER_BRIDGE_CLOSE),
1831
+ payload: import_zod11.z.object({
1832
+ reason: import_zod11.z.string().optional()
1833
+ }).strict()
1834
+ }).strict();
1835
+ var presentationSyncSchema = import_zod11.z.object({
1836
+ type: import_zod11.z.literal(AIRJAM_CONTROLLER_PRESENTATION_SYNC),
1837
+ payload: import_zod11.z.object({
1838
+ orientation: controllerOrientationSchema,
1839
+ arcadeSurface: arcadeSurfaceRuntimeIdentitySchema
1840
+ }).strict()
1841
+ }).strict();
1842
+ var createControllerPresentationSyncMessage = (payload) => ({
1843
+ type: AIRJAM_CONTROLLER_PRESENTATION_SYNC,
1844
+ payload
1845
+ });
1846
+
1847
+ // src/runtime/runtime-session-params.ts
1848
+ var import_runtime_topology4 = require("@air-jam/runtime-topology");
1849
+
1850
+ // src/runtime/arcade-runtime-url.ts
1851
+ var parseOptionalArcadeSurfaceFromSearchParams = (params) => {
1852
+ const epochStr = params.get("aj_arcade_epoch");
1853
+ const kind = params.get("aj_arcade_kind");
1854
+ if (epochStr === null || kind !== "browser" && kind !== "game") {
1855
+ return void 0;
1856
+ }
1857
+ const epoch = Number(epochStr);
1858
+ if (!Number.isFinite(epoch) || epoch < 0 || !Number.isInteger(epoch)) {
1859
+ return void 0;
1860
+ }
1861
+ const gameIdRaw = params.get("aj_arcade_game_id");
1862
+ const gameId = kind === "browser" ? null : gameIdRaw && gameIdRaw.length > 0 ? gameIdRaw : null;
1863
+ return { epoch, kind, gameId };
1864
+ };
1865
+
1866
+ // src/runtime/runtime-session-params.ts
1867
+ var parseOrigin = (value) => {
1868
+ if (!value) {
1869
+ return null;
1870
+ }
1871
+ try {
1872
+ return new URL(value).origin;
1873
+ } catch {
1874
+ return null;
1875
+ }
1876
+ };
1877
+ var resolveLegacyEmbeddedTopology = ({
1878
+ surfaceRole,
1879
+ joinUrl
1880
+ }) => {
1881
+ if (typeof window === "undefined") {
1882
+ return null;
1883
+ }
1884
+ const appOrigin = window.location.origin;
1885
+ const joinUrlOrigin = parseOrigin(joinUrl);
1886
+ const referrerOrigin = parseOrigin(document.referrer);
1887
+ const embedParentOrigin = joinUrlOrigin ?? referrerOrigin ?? appOrigin;
1888
+ const publicHost = joinUrlOrigin ?? appOrigin;
1889
+ const secureTransport = appOrigin.startsWith("https://") && publicHost.startsWith("https://") && embedParentOrigin.startsWith("https://");
1890
+ return (0, import_runtime_topology4.resolveRuntimeTopology)({
1891
+ runtimeMode: "arcade-live",
1892
+ surfaceRole,
1893
+ appOrigin,
1894
+ backendOrigin: appOrigin,
1895
+ socketOrigin: appOrigin,
1896
+ publicHost,
1897
+ assetBasePath: "/",
1898
+ secureTransport,
1899
+ embedded: true,
1900
+ embedParentOrigin,
1901
+ proxyStrategy: "none"
1902
+ });
1903
+ };
1904
+ var readEmbeddedControllerRuntimeParams = () => {
1905
+ if (typeof window === "undefined") {
1906
+ return null;
1907
+ }
1908
+ const params = new URLSearchParams(window.location.search);
1909
+ const room = params.get("aj_room");
1910
+ const controllerId = params.get("aj_controller_id");
1911
+ if (!room || !controllerId) {
1912
+ return null;
1913
+ }
1914
+ const topology = (0, import_runtime_topology4.parseRuntimeTopologyFromSearchParams)(params) ?? resolveLegacyEmbeddedTopology({
1915
+ surfaceRole: "controller"
1916
+ });
1917
+ if (!topology) {
1918
+ return null;
1919
+ }
1920
+ const arcadeSurface = parseOptionalArcadeSurfaceFromSearchParams(params);
1921
+ if (!arcadeSurface) {
1922
+ return null;
1923
+ }
1924
+ const rawLabel = params.get("aj_player_label")?.trim();
1925
+ const rawAvatarId = params.get("aj_player_avatar")?.trim();
1926
+ const playerProfile = rawLabel || rawAvatarId ? {
1927
+ ...rawLabel ? { label: rawLabel } : {},
1928
+ ...rawAvatarId ? { avatarId: rawAvatarId } : {}
1929
+ } : void 0;
1930
+ return {
1931
+ room,
1932
+ controllerId,
1933
+ topology,
1934
+ arcadeSurface,
1935
+ ...playerProfile ? { playerProfile } : {}
1936
+ };
1937
+ };
1938
+
1939
+ // src/runtime/controller-presentation.ts
1940
+ var publishEmbeddedControllerPresentation = (orientation) => {
1941
+ if (typeof window === "undefined" || window.parent === window) {
1942
+ return;
1943
+ }
1944
+ const runtimeParams = readEmbeddedControllerRuntimeParams();
1945
+ if (!runtimeParams) {
1946
+ return;
1947
+ }
1948
+ window.parent.postMessage(
1949
+ createControllerPresentationSyncMessage({
1950
+ orientation,
1951
+ arcadeSurface: runtimeParams.arcadeSurface
1952
+ }),
1953
+ runtimeParams.topology.embedParentOrigin ?? "*"
1954
+ );
1955
+ };
1956
+
1957
+ // src/components/surface-orientation-layout.ts
1958
+ var AIRJAM_SAFE_AREA_TOP = "env(safe-area-inset-top, 0px)";
1959
+ var AIRJAM_SAFE_AREA_RIGHT = "env(safe-area-inset-right, 0px)";
1960
+ var AIRJAM_SAFE_AREA_BOTTOM = "env(safe-area-inset-bottom, 0px)";
1961
+ var AIRJAM_SAFE_AREA_LEFT = "env(safe-area-inset-left, 0px)";
1962
+ var AIRJAM_SAFE_VIEWPORT_WIDTH = `calc(100dvw - ${AIRJAM_SAFE_AREA_LEFT} - ${AIRJAM_SAFE_AREA_RIGHT})`;
1963
+ var AIRJAM_SAFE_VIEWPORT_HEIGHT = `calc(100dvh - ${AIRJAM_SAFE_AREA_TOP} - ${AIRJAM_SAFE_AREA_BOTTOM})`;
1964
+ var createSurfaceViewportOuterStyle = () => ({
1965
+ ["--airjam-safe-area-top"]: AIRJAM_SAFE_AREA_TOP,
1966
+ ["--airjam-safe-area-right"]: AIRJAM_SAFE_AREA_RIGHT,
1967
+ ["--airjam-safe-area-bottom"]: AIRJAM_SAFE_AREA_BOTTOM,
1968
+ ["--airjam-safe-area-left"]: AIRJAM_SAFE_AREA_LEFT,
1969
+ ["--airjam-safe-viewport-width"]: AIRJAM_SAFE_VIEWPORT_WIDTH,
1970
+ ["--airjam-safe-viewport-height"]: AIRJAM_SAFE_VIEWPORT_HEIGHT
1971
+ });
1972
+ var resolveForcedOrientationFrameStyle = (desired, needsRotation) => {
1973
+ if (!needsRotation) {
1974
+ return {
1975
+ position: "absolute",
1976
+ top: AIRJAM_SAFE_AREA_TOP,
1977
+ left: AIRJAM_SAFE_AREA_LEFT,
1978
+ width: AIRJAM_SAFE_VIEWPORT_WIDTH,
1979
+ height: AIRJAM_SAFE_VIEWPORT_HEIGHT,
1980
+ overflow: "hidden"
1981
+ };
1982
+ }
1983
+ if (desired === "landscape") {
1984
+ return {
1985
+ position: "absolute",
1986
+ top: AIRJAM_SAFE_AREA_TOP,
1987
+ left: AIRJAM_SAFE_AREA_LEFT,
1988
+ width: AIRJAM_SAFE_VIEWPORT_HEIGHT,
1989
+ height: AIRJAM_SAFE_VIEWPORT_WIDTH,
1990
+ overflow: "hidden",
1991
+ transformOrigin: "top left",
1992
+ transform: `translateX(${AIRJAM_SAFE_VIEWPORT_WIDTH}) rotate(90deg)`
1993
+ };
1994
+ }
1995
+ return {
1996
+ position: "absolute",
1997
+ top: AIRJAM_SAFE_AREA_TOP,
1998
+ left: AIRJAM_SAFE_AREA_LEFT,
1999
+ width: AIRJAM_SAFE_VIEWPORT_HEIGHT,
2000
+ height: AIRJAM_SAFE_VIEWPORT_WIDTH,
2001
+ overflow: "hidden",
2002
+ transformOrigin: "top left",
2003
+ transform: `translateY(${AIRJAM_SAFE_VIEWPORT_HEIGHT}) rotate(-90deg)`
2004
+ };
2005
+ };
2006
+
2007
+ // src/components/surface-viewport-layout.ts
2008
+ var CONTROLLER_REFERENCE_SIZE = {
2009
+ portrait: {
2010
+ width: 412,
2011
+ height: 915
2012
+ },
2013
+ landscape: {
2014
+ width: 915,
2015
+ height: 412
2016
+ }
2017
+ };
2018
+ var HOST_REFERENCE_SIZE = {
2019
+ portrait: {
2020
+ width: 900,
2021
+ height: 1600
2022
+ },
2023
+ landscape: {
2024
+ width: 1600,
2025
+ height: 900
2026
+ }
2027
+ };
2028
+ var resolveSurfaceViewportScopeReferenceSize = (sessionScope) => {
2029
+ if (sessionScope === "controller") {
2030
+ return CONTROLLER_REFERENCE_SIZE;
2031
+ }
2032
+ if (sessionScope === "host") {
2033
+ return HOST_REFERENCE_SIZE;
2034
+ }
2035
+ return null;
2036
+ };
2037
+ var resolveSurfaceViewportReferenceSize = ({
2038
+ sessionScope,
2039
+ designWidth,
2040
+ designHeight,
2041
+ orientation,
2042
+ availableWidth,
2043
+ availableHeight
2044
+ }) => {
2045
+ if (typeof designWidth === "number" && Number.isFinite(designWidth) && designWidth > 0 && typeof designHeight === "number" && Number.isFinite(designHeight) && designHeight > 0) {
2046
+ return {
2047
+ width: designWidth,
2048
+ height: designHeight
2049
+ };
2050
+ }
2051
+ const scopedReferenceSize = resolveSurfaceViewportScopeReferenceSize(sessionScope);
2052
+ if (scopedReferenceSize) {
2053
+ return scopedReferenceSize[orientation];
2054
+ }
2055
+ return {
2056
+ width: Math.max(availableWidth, 1),
2057
+ height: Math.max(availableHeight, 1)
2058
+ };
2059
+ };
2060
+ var SURFACE_VIEWPORT_TEXT_SIZE_BASES = {
2061
+ xs: "0.75rem",
2062
+ sm: "0.875rem",
2063
+ base: "1rem",
2064
+ lg: "1.125rem",
2065
+ xl: "1.25rem",
2066
+ "2xl": "1.5rem",
2067
+ "3xl": "1.875rem",
2068
+ "4xl": "2.25rem",
2069
+ "5xl": "3rem",
2070
+ "6xl": "3.75rem",
2071
+ "7xl": "4.5rem",
2072
+ "8xl": "6rem",
2073
+ "9xl": "8rem"
2074
+ };
2075
+ var SURFACE_VIEWPORT_CONTAINER_BASES = {
2076
+ "3xs": "16rem",
2077
+ "2xs": "18rem",
2078
+ xs: "20rem",
2079
+ sm: "24rem",
2080
+ md: "28rem",
2081
+ lg: "32rem",
2082
+ xl: "36rem",
2083
+ "2xl": "42rem",
2084
+ "3xl": "48rem",
2085
+ "4xl": "56rem",
2086
+ "5xl": "64rem",
2087
+ "6xl": "72rem",
2088
+ "7xl": "80rem"
2089
+ };
2090
+ var SURFACE_VIEWPORT_RADIUS_BASES = {
2091
+ xs: "0.125rem",
2092
+ sm: "0.375rem",
2093
+ md: "0.5rem",
2094
+ lg: "0.625rem",
2095
+ xl: "0.875rem",
2096
+ "2xl": "1rem",
2097
+ "3xl": "1.5rem",
2098
+ "4xl": "2rem"
2099
+ };
2100
+ var resolveSurfaceViewportAvailableSize = ({
2101
+ safeViewportWidth,
2102
+ safeViewportHeight,
2103
+ orientation,
2104
+ needsRotation
2105
+ }) => {
2106
+ if (!orientation || !needsRotation) {
2107
+ return {
2108
+ width: safeViewportWidth,
2109
+ height: safeViewportHeight
2110
+ };
2111
+ }
2112
+ return {
2113
+ width: safeViewportHeight,
2114
+ height: safeViewportWidth
2115
+ };
2116
+ };
2117
+ var resolveSurfaceViewportScale = ({
2118
+ availableWidth,
2119
+ availableHeight,
2120
+ referenceWidth,
2121
+ referenceHeight,
2122
+ scaleMode = "fit",
2123
+ uiScaleMultiplier = 1,
2124
+ minScale,
2125
+ maxScale
2126
+ }) => {
2127
+ const safeAvailableWidth = Math.max(availableWidth, 1);
2128
+ const safeAvailableHeight = Math.max(availableHeight, 1);
2129
+ const safeReferenceWidth = Math.max(referenceWidth, 1);
2130
+ const safeReferenceHeight = Math.max(referenceHeight, 1);
2131
+ const widthScale = safeAvailableWidth / safeReferenceWidth;
2132
+ const heightScale = safeAvailableHeight / safeReferenceHeight;
2133
+ const baseScale = scaleMode === "width" ? widthScale : scaleMode === "height" ? heightScale : Math.min(widthScale, heightScale);
2134
+ let scale = baseScale * uiScaleMultiplier;
2135
+ if (typeof minScale === "number" && Number.isFinite(minScale)) {
2136
+ scale = Math.max(scale, minScale);
2137
+ }
2138
+ if (typeof maxScale === "number" && Number.isFinite(maxScale)) {
2139
+ scale = Math.min(scale, maxScale);
2140
+ }
2141
+ return scale;
2142
+ };
2143
+ var createScaledVariableValue = (baseValue) => `calc(${baseValue} * var(--airjam-ui-scale))`;
2144
+ var createSurfaceViewportScaleStyle = ({
2145
+ scale,
2146
+ referenceWidth,
2147
+ referenceHeight
2148
+ }) => {
2149
+ const style = {
2150
+ position: "relative",
2151
+ width: "100%",
2152
+ height: "100%",
2153
+ overflow: "hidden",
2154
+ fontSize: createScaledVariableValue("1rem"),
2155
+ "--airjam-ui-scale": String(scale),
2156
+ "--airjam-ui-rem": createScaledVariableValue("1rem"),
2157
+ "--airjam-reference-width": `${referenceWidth}px`,
2158
+ "--airjam-reference-height": `${referenceHeight}px`,
2159
+ "--spacing": createScaledVariableValue("0.25rem"),
2160
+ "--radius": createScaledVariableValue("0.625rem")
2161
+ };
2162
+ for (const [name, baseValue] of Object.entries(
2163
+ SURFACE_VIEWPORT_TEXT_SIZE_BASES
2164
+ )) {
2165
+ style[`--text-${name}`] = createScaledVariableValue(baseValue);
2166
+ }
2167
+ for (const [name, baseValue] of Object.entries(
2168
+ SURFACE_VIEWPORT_CONTAINER_BASES
2169
+ )) {
2170
+ style[`--container-${name}`] = createScaledVariableValue(baseValue);
2171
+ }
2172
+ for (const [name, baseValue] of Object.entries(
2173
+ SURFACE_VIEWPORT_RADIUS_BASES
2174
+ )) {
2175
+ style[`--radius-${name}`] = createScaledVariableValue(baseValue);
2176
+ }
2177
+ return style;
2178
+ };
2179
+
2180
+ // src/components/surface-viewport.tsx
2181
+ var import_jsx_runtime16 = require("react/jsx-runtime");
2182
+ var readLayoutViewportSize = () => {
2183
+ if (typeof window === "undefined") {
2184
+ return { width: 0, height: 0 };
2185
+ }
2186
+ return {
2187
+ width: window.innerWidth,
2188
+ height: window.innerHeight
2189
+ };
2190
+ };
2191
+ var isTextEntryElement = (element) => {
2192
+ if (!element) {
2193
+ return false;
2194
+ }
2195
+ if (element instanceof HTMLTextAreaElement) {
2196
+ return true;
2197
+ }
2198
+ if (element instanceof HTMLInputElement) {
2199
+ return ![
2200
+ "button",
2201
+ "checkbox",
2202
+ "color",
2203
+ "file",
2204
+ "hidden",
2205
+ "image",
2206
+ "radio",
2207
+ "range",
2208
+ "reset",
2209
+ "submit"
2210
+ ].includes(element.type);
2211
+ }
2212
+ return element instanceof HTMLElement && element.isContentEditable;
2213
+ };
2214
+ var isKeyboardResize = (previous, next) => {
2215
+ if (!previous || typeof document === "undefined") {
2216
+ return false;
2217
+ }
2218
+ if (!isTextEntryElement(document.activeElement)) {
2219
+ return false;
2220
+ }
2221
+ const sameWidth = Math.abs(previous.width - next.width) <= 2;
2222
+ const heightShrank = next.height < previous.height;
2223
+ return sameWidth && heightShrank;
2224
+ };
2225
+ var getOrientation = ({
2226
+ width,
2227
+ height
2228
+ }) => {
2229
+ if (typeof window !== "undefined") {
2230
+ if (window.matchMedia) {
2231
+ if (window.matchMedia("(orientation: portrait)").matches) {
2232
+ return "portrait";
2233
+ }
2234
+ if (window.matchMedia("(orientation: landscape)").matches) {
2235
+ return "landscape";
2236
+ }
2237
+ }
2238
+ if (window.screen?.orientation?.type) {
2239
+ if (window.screen.orientation.type.startsWith("portrait")) {
2240
+ return "portrait";
2241
+ }
2242
+ if (window.screen.orientation.type.startsWith("landscape")) {
2243
+ return "landscape";
2244
+ }
2245
+ }
2246
+ }
2247
+ if (width > 0 && height > 0) {
2248
+ return width >= height ? "landscape" : "portrait";
2249
+ }
2250
+ return width >= height ? "landscape" : "portrait";
2251
+ };
2252
+ var SurfaceViewport = ({
2253
+ children,
2254
+ orientation,
2255
+ lockOnGesture = true,
2256
+ className,
2257
+ contentClassName,
2258
+ style,
2259
+ designWidth,
2260
+ designHeight,
2261
+ uiScaleMultiplier,
2262
+ minScale,
2263
+ maxScale
2264
+ }) => {
2265
+ const [viewport, setViewport] = (0, import_react9.useState)(null);
2266
+ const viewportRef = (0, import_react9.useRef)(null);
2267
+ const sessionScope = useSessionScope();
2268
+ (0, import_react9.useEffect)(() => {
2269
+ if (typeof window === "undefined") {
2270
+ return;
2271
+ }
2272
+ const updateViewport = () => {
2273
+ const nextViewport = readLayoutViewportSize();
2274
+ if (isKeyboardResize(viewportRef.current, nextViewport)) {
2275
+ return;
2276
+ }
2277
+ viewportRef.current = nextViewport;
2278
+ setViewport(nextViewport);
2279
+ };
2280
+ updateViewport();
2281
+ window.addEventListener("resize", updateViewport);
2282
+ window.visualViewport?.addEventListener("resize", updateViewport);
2283
+ window.addEventListener("orientationchange", updateViewport);
2284
+ return () => {
2285
+ window.removeEventListener("resize", updateViewport);
2286
+ window.visualViewport?.removeEventListener("resize", updateViewport);
2287
+ window.removeEventListener("orientationchange", updateViewport);
2288
+ };
2289
+ }, []);
2290
+ (0, import_react9.useEffect)(() => {
2291
+ if (typeof window === "undefined" || !orientation || !lockOnGesture) {
2292
+ return;
2293
+ }
2294
+ const tryLock = () => {
2295
+ if (!("orientation" in screen)) {
2296
+ return;
2297
+ }
2298
+ const screenOrientation = screen.orientation;
2299
+ if (!screenOrientation?.lock) {
2300
+ return;
2301
+ }
2302
+ void screenOrientation.lock(orientation).catch(() => {
2303
+ });
2304
+ };
2305
+ const onFirstGesture = () => {
2306
+ tryLock();
2307
+ window.removeEventListener("pointerdown", onFirstGesture, true);
2308
+ };
2309
+ window.addEventListener("pointerdown", onFirstGesture, true);
2310
+ return () => {
2311
+ window.removeEventListener("pointerdown", onFirstGesture, true);
2312
+ };
2313
+ }, [orientation, lockOnGesture]);
2314
+ (0, import_react9.useEffect)(() => {
2315
+ if (!orientation || sessionScope !== "controller") {
2316
+ return;
2317
+ }
2318
+ publishEmbeddedControllerPresentation(orientation);
2319
+ }, [orientation, sessionScope]);
2320
+ const currentOrientation = viewport ? getOrientation(viewport) : "portrait";
2321
+ const effectiveOrientation = orientation ?? currentOrientation;
2322
+ const needsRotation = orientation ? currentOrientation !== orientation : false;
2323
+ const shellStyle = (0, import_react9.useMemo)(
2324
+ () => orientation ? resolveForcedOrientationFrameStyle(orientation, needsRotation) : resolveForcedOrientationFrameStyle(effectiveOrientation, false),
2325
+ [effectiveOrientation, needsRotation, orientation]
2326
+ );
2327
+ const availableSize = (0, import_react9.useMemo)(
2328
+ () => resolveSurfaceViewportAvailableSize({
2329
+ safeViewportWidth: viewport?.width ?? 0,
2330
+ safeViewportHeight: viewport?.height ?? 0,
2331
+ orientation,
2332
+ needsRotation
2333
+ }),
2334
+ [needsRotation, orientation, viewport]
2335
+ );
2336
+ const referenceSize = (0, import_react9.useMemo)(
2337
+ () => resolveSurfaceViewportReferenceSize({
2338
+ sessionScope,
2339
+ designWidth,
2340
+ designHeight,
2341
+ orientation: effectiveOrientation,
2342
+ availableWidth: availableSize.width,
2343
+ availableHeight: availableSize.height
2344
+ }),
2345
+ [
2346
+ availableSize.height,
2347
+ availableSize.width,
2348
+ designHeight,
2349
+ designWidth,
2350
+ effectiveOrientation,
2351
+ sessionScope
2352
+ ]
2353
+ );
2354
+ const scale = (0, import_react9.useMemo)(() => {
2355
+ const scaleMode = sessionScope === "controller" ? effectiveOrientation === "portrait" ? "width" : "height" : "fit";
2356
+ return resolveSurfaceViewportScale({
2357
+ availableWidth: availableSize.width,
2358
+ availableHeight: availableSize.height,
2359
+ referenceWidth: referenceSize.width,
2360
+ referenceHeight: referenceSize.height,
2361
+ scaleMode,
2362
+ uiScaleMultiplier,
2363
+ minScale,
2364
+ maxScale
2365
+ });
2366
+ }, [
2367
+ availableSize.height,
2368
+ availableSize.width,
2369
+ effectiveOrientation,
2370
+ maxScale,
2371
+ minScale,
2372
+ referenceSize.height,
2373
+ referenceSize.width,
2374
+ sessionScope,
2375
+ uiScaleMultiplier
2376
+ ]);
2377
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2378
+ "div",
2379
+ {
2380
+ className: cn("fixed inset-0 overflow-hidden", className),
2381
+ style: {
2382
+ ...createSurfaceViewportOuterStyle(),
2383
+ ...style
2384
+ },
2385
+ children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { style: shellStyle, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2386
+ "div",
2387
+ {
2388
+ className: cn("h-full w-full overflow-hidden", contentClassName),
2389
+ "data-airjam-surface-viewport": "true",
2390
+ style: createSurfaceViewportScaleStyle({
2391
+ scale,
2392
+ referenceWidth: referenceSize.width,
2393
+ referenceHeight: referenceSize.height
2394
+ }),
2395
+ children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "h-full w-full", "data-airjam-surface-root": "true", children })
2396
+ }
2397
+ ) })
2398
+ }
2399
+ );
2400
+ };
2401
+
2402
+ // src/components/ui/slider.tsx
2403
+ var SliderPrimitive = __toESM(require("@radix-ui/react-slider"), 1);
2404
+ var React = __toESM(require("react"), 1);
2405
+ var import_jsx_runtime17 = require("react/jsx-runtime");
2406
+ function Slider({
2407
+ className,
2408
+ defaultValue,
2409
+ value,
2410
+ min = 0,
2411
+ max = 100,
2412
+ ...props
2413
+ }) {
2414
+ const _values = React.useMemo(
2415
+ () => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
2416
+ [value, defaultValue, min, max]
2417
+ );
2418
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
2419
+ SliderPrimitive.Root,
2420
+ {
2421
+ "data-slot": "slider",
2422
+ defaultValue,
2423
+ value,
2424
+ min,
2425
+ max,
2426
+ className: cn(
2427
+ "relative flex w-full cursor-pointer touch-none items-center select-none data-disabled:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
2428
+ className
2429
+ ),
2430
+ ...props,
2431
+ children: [
2432
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2433
+ SliderPrimitive.Track,
2434
+ {
2435
+ "data-slot": "slider-track",
2436
+ className: cn(
2437
+ "bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"
2438
+ ),
2439
+ children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2440
+ SliderPrimitive.Range,
2441
+ {
2442
+ "data-slot": "slider-range",
2443
+ className: cn(
2444
+ "bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"
2445
+ )
2446
+ }
2447
+ )
2448
+ }
2449
+ ),
2450
+ Array.from({ length: _values.length }, (_, index) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2451
+ SliderPrimitive.Thumb,
2452
+ {
2453
+ "data-slot": "slider-thumb",
2454
+ className: "border-primary ring-ring/50 relative block size-5 shrink-0 cursor-pointer touch-none rounded-full border bg-white shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
2455
+ },
2456
+ index
2457
+ ))
2458
+ ]
2459
+ }
2460
+ );
2461
+ }
2462
+
2463
+ // src/components/volume-controls.tsx
2464
+ var import_lucide_react5 = require("lucide-react");
2465
+
2466
+ // src/settings/platform-settings-runtime.tsx
2467
+ var import_react10 = require("react");
2468
+ var import_jsx_runtime18 = require("react/jsx-runtime");
2469
+ var platformSettingsContext = (0, import_react10.createContext)(null);
2470
+ var createDefaultContextValue = () => ({
2471
+ mode: "default",
2472
+ status: "ready",
2473
+ settings: DEFAULT_PLATFORM_SETTINGS,
2474
+ setSettings: () => {
2475
+ throw new Error(
2476
+ 'Platform settings are read-only in this runtime. Mount <PlatformSettingsRuntime persistence="local"> in the platform shell to update shared settings.'
2477
+ );
2478
+ },
2479
+ updateSettings: () => {
2480
+ throw new Error(
2481
+ 'Platform settings are read-only in this runtime. Mount <PlatformSettingsRuntime persistence="local"> in the platform shell to update shared settings.'
2482
+ );
2483
+ }
2484
+ });
2485
+ function usePlatformAudioSettings() {
2486
+ const context = (0, import_react10.useContext)(platformSettingsContext) ?? createDefaultContextValue();
2487
+ const { audio } = context.settings;
2488
+ const isReadOnly = context.mode !== "owner";
2489
+ const setAudioSetting = (0, import_react10.useCallback)(
2490
+ (patch) => {
2491
+ if (context.mode !== "owner") {
2492
+ throw new Error(
2493
+ 'Platform audio settings are read-only in this runtime. Mount <PlatformSettingsRuntime persistence="local"> in the platform shell to update shared settings.'
2494
+ );
2495
+ }
2496
+ context.updateSettings({ audio: patch });
2497
+ },
2498
+ [context]
2499
+ );
2500
+ return {
2501
+ ...audio,
2502
+ isReadOnly,
2503
+ getEffectiveVolume: (category) => getEffectiveAudioVolume(audio, category),
2504
+ setMasterVolume: (volume) => setAudioSetting({ masterVolume: volume }),
2505
+ setMusicVolume: (volume) => setAudioSetting({ musicVolume: volume }),
2506
+ setSfxVolume: (volume) => setAudioSetting({ sfxVolume: volume })
2507
+ };
2508
+ }
2509
+
2510
+ // src/components/volume-controls.tsx
2511
+ var import_jsx_runtime19 = require("react/jsx-runtime");
2512
+ function VolumeControls(props) {
2513
+ if (props.values) {
2514
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ControlledVolumeControls, { ...props });
2515
+ }
2516
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(OwnedVolumeControls, { ...props });
2517
+ }
2518
+ function OwnedVolumeControls({ className, compact }) {
2519
+ const {
2520
+ masterVolume,
2521
+ musicVolume,
2522
+ sfxVolume,
2523
+ setMasterVolume,
2524
+ setMusicVolume,
2525
+ setSfxVolume
2526
+ } = usePlatformAudioSettings();
2527
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2528
+ ControlledVolumeControls,
2529
+ {
2530
+ className,
2531
+ compact,
2532
+ values: { masterVolume, musicVolume, sfxVolume },
2533
+ onMasterVolumeChange: setMasterVolume,
2534
+ onMusicVolumeChange: setMusicVolume,
2535
+ onSfxVolumeChange: setSfxVolume,
2536
+ readOnly: false
2537
+ }
2538
+ );
2539
+ }
2540
+ function ControlledVolumeControls({
2541
+ className,
2542
+ compact,
2543
+ values,
2544
+ readOnly = false,
2545
+ onMasterVolumeChange,
2546
+ onMusicVolumeChange,
2547
+ onSfxVolumeChange
2548
+ }) {
2549
+ if (!values) {
2550
+ throw new Error("ControlledVolumeControls requires values");
2551
+ }
2552
+ const { masterVolume, musicVolume, sfxVolume } = values;
2553
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: cn("flex flex-col gap-3", compact && "gap-1", className), children: [
2554
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-2", children: [
2555
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_lucide_react5.Volume2, { className: "text-muted-foreground h-4 w-4" }),
2556
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "text-sm font-medium", children: "Volume" })
2557
+ ] }),
2558
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "space-y-1.5", children: [
2559
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center justify-between", children: [
2560
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("label", { className: "text-muted-foreground text-xs", children: "Master" }),
2561
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: "text-muted-foreground font-mono text-xs", children: [
2562
+ Math.round(masterVolume * 100),
2563
+ "%"
2564
+ ] })
2565
+ ] }),
2566
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2567
+ Slider,
2568
+ {
2569
+ "data-testid": "platform-settings-master-volume",
2570
+ value: [masterVolume * 100],
2571
+ onValueChange: (sliderValues) => onMasterVolumeChange?.(sliderValues[0] / 100),
2572
+ min: 0,
2573
+ max: 100,
2574
+ step: 1,
2575
+ className: "w-full",
2576
+ "aria-label": "Master volume",
2577
+ disabled: readOnly
2578
+ }
2579
+ )
2580
+ ] }),
2581
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "space-y-1.5", children: [
2582
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center justify-between", children: [
2583
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-1.5", children: [
2584
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_lucide_react5.Music, { className: "text-muted-foreground h-3 w-3" }),
2585
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("label", { className: "text-muted-foreground text-xs", children: "Music" })
2586
+ ] }),
2587
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: "text-muted-foreground font-mono text-xs", children: [
2588
+ Math.round(musicVolume * 100),
2589
+ "%"
2590
+ ] })
2591
+ ] }),
2592
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2593
+ Slider,
2594
+ {
2595
+ "data-testid": "platform-settings-music-volume",
2596
+ value: [musicVolume * 100],
2597
+ onValueChange: (sliderValues) => onMusicVolumeChange?.(sliderValues[0] / 100),
2598
+ min: 0,
2599
+ max: 100,
2600
+ step: 1,
2601
+ className: "w-full",
2602
+ "aria-label": "Music volume",
2603
+ disabled: readOnly
2604
+ }
2605
+ )
2606
+ ] }),
2607
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "space-y-1.5", children: [
2608
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center justify-between", children: [
2609
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-1.5", children: [
2610
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_lucide_react5.Headphones, { className: "text-muted-foreground h-3 w-3" }),
2611
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("label", { className: "text-muted-foreground text-xs", children: "SFX" })
2612
+ ] }),
2613
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: "text-muted-foreground font-mono text-xs", children: [
2614
+ Math.round(sfxVolume * 100),
2615
+ "%"
2616
+ ] })
2617
+ ] }),
2618
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2619
+ Slider,
2620
+ {
2621
+ "data-testid": "platform-settings-sfx-volume",
2622
+ value: [sfxVolume * 100],
2623
+ onValueChange: (sliderValues) => onSfxVolumeChange?.(sliderValues[0] / 100),
2624
+ min: 0,
2625
+ max: 100,
2626
+ step: 1,
2627
+ className: "w-full",
2628
+ "aria-label": "SFX volume",
2629
+ disabled: readOnly
2630
+ }
2631
+ )
2632
+ ] })
2633
+ ] });
2634
+ }
2635
+
2636
+ // src/hooks/use-controller-lifecycle-intents.ts
2637
+ var useControllerLifecycleIntents = ({
2638
+ onStart,
2639
+ onTogglePause,
2640
+ onBackToLobby,
2641
+ onRestart
2642
+ }) => {
2643
+ return {
2644
+ onStart,
2645
+ onTogglePause,
2646
+ onBackToLobby,
2647
+ onRestart
2648
+ };
2649
+ };
2650
+
2651
+ // src/hooks/use-controller-lifecycle-permissions.ts
2652
+ var useControllerLifecyclePermissions = ({
2653
+ phase,
2654
+ canStartMatch = false,
2655
+ canSendSystemCommand = false
2656
+ }) => {
2657
+ const canStart = phase === "lobby" && canStartMatch;
2658
+ const canPauseToggle = phase === "playing" && canSendSystemCommand;
2659
+ const canRestart = phase === "ended" && canSendSystemCommand;
2660
+ const canBackToLobby = phase !== "lobby" && canSendSystemCommand;
2661
+ const canInteractForPhase = phase === "lobby" ? canStart : canSendSystemCommand;
2662
+ return {
2663
+ canStart,
2664
+ canPauseToggle,
2665
+ canRestart,
2666
+ canBackToLobby,
2667
+ canInteractForPhase
2668
+ };
2669
+ };
2670
+
2671
+ // src/hooks/use-controller-shell-status.ts
2672
+ var useControllerShellStatus = ({
2673
+ roomId,
2674
+ connectionStatus,
2675
+ playerLabel,
2676
+ fallbackLabel = "Controller",
2677
+ roomFallback = "----"
2678
+ }) => {
2679
+ const trimmedLabel = playerLabel?.trim() ?? "";
2680
+ const displayName = trimmedLabel || fallbackLabel;
2681
+ const roomDisplay = roomId ?? roomFallback;
2682
+ const identityInitial = displayName.charAt(0).toUpperCase() || "M";
2683
+ return {
2684
+ connectionStatus,
2685
+ displayName,
2686
+ roomDisplay,
2687
+ roomLine: `Room ${roomDisplay}`,
2688
+ hasIdentity: trimmedLabel.length > 0,
2689
+ identityInitial
2690
+ };
2691
+ };
2692
+
2693
+ // src/hooks/use-host-join-controls.ts
2694
+ var import_react11 = require("react");
2695
+ var copyTextToClipboard = async (text) => {
2696
+ if (!text) {
2697
+ return false;
2698
+ }
2699
+ try {
2700
+ if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
2701
+ await navigator.clipboard.writeText(text);
2702
+ return true;
2703
+ }
2704
+ } catch {
2705
+ }
2706
+ if (typeof document === "undefined") {
2707
+ return false;
2708
+ }
2709
+ const fallbackField = document.createElement("textarea");
2710
+ fallbackField.value = text;
2711
+ fallbackField.style.position = "fixed";
2712
+ fallbackField.style.opacity = "0";
2713
+ document.body.appendChild(fallbackField);
2714
+ fallbackField.select();
2715
+ try {
2716
+ return document.execCommand("copy");
2717
+ } catch {
2718
+ return false;
2719
+ } finally {
2720
+ document.body.removeChild(fallbackField);
2721
+ }
2722
+ };
2723
+ var useHostJoinControls = ({
2724
+ joinUrl,
2725
+ canStartMatch = false,
2726
+ onStartMatch,
2727
+ copiedDurationMs = 1800
2728
+ }) => {
2729
+ const [copied, setCopied] = (0, import_react11.useState)(false);
2730
+ const [joinQrVisible, setJoinQrVisible] = (0, import_react11.useState)(false);
2731
+ const resetTimerRef = (0, import_react11.useRef)(null);
2732
+ const joinUrlValue = (0, import_react11.useMemo)(() => joinUrl ?? "", [joinUrl]);
2733
+ const hasJoinUrl = joinUrlValue.length > 0;
2734
+ (0, import_react11.useEffect)(() => {
2735
+ if (!hasJoinUrl) {
2736
+ setJoinQrVisible(false);
2737
+ }
2738
+ }, [hasJoinUrl]);
2739
+ const handleCopy = (0, import_react11.useCallback)(async () => {
2740
+ if (!joinUrlValue) {
2741
+ return;
2742
+ }
2743
+ const copiedSuccessfully = await copyTextToClipboard(joinUrlValue);
2744
+ if (!copiedSuccessfully || typeof window === "undefined") {
2745
+ return;
2746
+ }
2747
+ setCopied(true);
2748
+ if (resetTimerRef.current !== null) {
2749
+ window.clearTimeout(resetTimerRef.current);
2750
+ }
2751
+ resetTimerRef.current = window.setTimeout(() => {
2752
+ setCopied(false);
2753
+ resetTimerRef.current = null;
2754
+ }, copiedDurationMs);
2755
+ }, [copiedDurationMs, joinUrlValue]);
2756
+ const handleOpen = (0, import_react11.useCallback)(() => {
2757
+ if (!joinUrlValue || typeof window === "undefined") {
2758
+ return;
2759
+ }
2760
+ window.open(joinUrlValue, "_blank", "noopener,noreferrer");
2761
+ }, [joinUrlValue]);
2762
+ const showJoinQr = (0, import_react11.useCallback)(() => {
2763
+ if (!hasJoinUrl) {
2764
+ return;
2765
+ }
2766
+ setJoinQrVisible(true);
2767
+ }, [hasJoinUrl]);
2768
+ const hideJoinQr = (0, import_react11.useCallback)(() => {
2769
+ setJoinQrVisible(false);
2770
+ }, []);
2771
+ const toggleJoinQr = (0, import_react11.useCallback)(() => {
2772
+ if (!hasJoinUrl) {
2773
+ return;
2774
+ }
2775
+ setJoinQrVisible((current) => !current);
2776
+ }, [hasJoinUrl]);
2777
+ const handleStart = (0, import_react11.useCallback)(() => {
2778
+ if (!canStartMatch) {
2779
+ return;
2780
+ }
2781
+ onStartMatch?.();
2782
+ }, [canStartMatch, onStartMatch]);
2783
+ return {
2784
+ joinUrlValue,
2785
+ hasJoinUrl,
2786
+ copied,
2787
+ joinQrVisible,
2788
+ canStartMatch,
2789
+ handleCopy,
2790
+ handleOpen,
2791
+ showJoinQr,
2792
+ hideJoinQr,
2793
+ toggleJoinQr,
2794
+ handleStart
2795
+ };
2796
+ };
2797
+ // Annotate the CommonJS export names for ESM import in node:
2798
+ 0 && (module.exports = {
2799
+ AIRJAM_DEFAULT_AVATAR_SEEDS,
2800
+ Button,
2801
+ ConnectionStatusPill,
2802
+ ControllerPlayerNameField,
2803
+ ControllerPrimaryAction,
2804
+ HostMuteButton,
2805
+ JoinQrOverlay,
2806
+ JoinUrlActionButtons,
2807
+ JoinUrlControls,
2808
+ JoinUrlField,
2809
+ LifecycleActionGroup,
2810
+ PlayerAvatar,
2811
+ PlayerAvatarStrip,
2812
+ RoomQrCode,
2813
+ RuntimeShellHeader,
2814
+ Slider,
2815
+ SurfaceViewport,
2816
+ VolumeControls,
2817
+ buttonVariants,
2818
+ getDiceBearAdventurerNeutralUrl,
2819
+ getPlayerAvatarImageUrl,
2820
+ resolvePlayerAvatarSeed,
2821
+ useControllerLifecycleIntents,
2822
+ useControllerLifecyclePermissions,
2823
+ useControllerShellStatus,
2824
+ useHostJoinControls,
2825
+ useLifecycleActionGroupModel
2826
+ });
2827
+ //# sourceMappingURL=ui.cjs.map