@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.
- package/LICENSE +21 -0
- package/README.md +627 -57
- package/dist/agent-tooling-BSMGBix9.d.cts +123 -0
- package/dist/agent-tooling-BSMGBix9.d.ts +123 -0
- package/dist/agent-tooling.cjs +83 -0
- package/dist/agent-tooling.cjs.map +1 -0
- package/dist/agent-tooling.d.cts +2 -0
- package/dist/agent-tooling.d.ts +2 -0
- package/dist/agent-tooling.js +17 -0
- package/dist/agent-tooling.js.map +1 -0
- package/dist/arcade/bridge/controller.cjs +749 -0
- package/dist/arcade/bridge/controller.cjs.map +1 -0
- package/dist/arcade/bridge/controller.d.cts +85 -0
- package/dist/arcade/bridge/controller.d.ts +85 -0
- package/dist/arcade/bridge/controller.js +33 -0
- package/dist/arcade/bridge/controller.js.map +1 -0
- package/dist/arcade/bridge/host.cjs +421 -0
- package/dist/arcade/bridge/host.cjs.map +1 -0
- package/dist/arcade/bridge/host.d.cts +73 -0
- package/dist/arcade/bridge/host.d.ts +73 -0
- package/dist/arcade/bridge/host.js +25 -0
- package/dist/arcade/bridge/host.js.map +1 -0
- package/dist/arcade/bridge/iframe.cjs +453 -0
- package/dist/arcade/bridge/iframe.cjs.map +1 -0
- package/dist/arcade/bridge/iframe.d.cts +80 -0
- package/dist/arcade/bridge/iframe.d.ts +80 -0
- package/dist/arcade/bridge/iframe.js +28 -0
- package/dist/arcade/bridge/iframe.js.map +1 -0
- package/dist/arcade/bridge.cjs +1067 -0
- package/dist/arcade/bridge.cjs.map +1 -0
- package/dist/arcade/bridge.d.cts +11 -0
- package/dist/arcade/bridge.d.ts +11 -0
- package/dist/arcade/bridge.js +76 -0
- package/dist/arcade/bridge.js.map +1 -0
- package/dist/arcade/host.cjs +488 -0
- package/dist/arcade/host.cjs.map +1 -0
- package/dist/arcade/host.d.cts +19 -0
- package/dist/arcade/host.d.ts +19 -0
- package/dist/arcade/host.js +13 -0
- package/dist/arcade/host.js.map +1 -0
- package/dist/arcade/surface.cjs +113 -0
- package/dist/arcade/surface.cjs.map +1 -0
- package/dist/arcade/surface.d.cts +14 -0
- package/dist/arcade/surface.d.ts +14 -0
- package/dist/arcade/surface.js +27 -0
- package/dist/arcade/surface.js.map +1 -0
- package/dist/arcade/url.cjs +363 -0
- package/dist/arcade/url.cjs.map +1 -0
- package/dist/arcade/url.d.cts +68 -0
- package/dist/arcade/url.d.ts +68 -0
- package/dist/arcade/url.js +28 -0
- package/dist/arcade/url.js.map +1 -0
- package/dist/arcade-runtime-url-BW-MUAOY.d.cts +28 -0
- package/dist/arcade-runtime-url-l8qj01Pg.d.ts +28 -0
- package/dist/arcade-surface-identity-CQxDpn_w.d.cts +16 -0
- package/dist/arcade-surface-identity-CQxDpn_w.d.ts +16 -0
- package/dist/arcade.cjs +1565 -0
- package/dist/arcade.cjs.map +1 -0
- package/dist/arcade.d.cts +18 -0
- package/dist/arcade.d.ts +18 -0
- package/dist/arcade.js +122 -0
- package/dist/arcade.js.map +1 -0
- package/dist/capabilities.cjs +39 -0
- package/dist/capabilities.cjs.map +1 -0
- package/dist/capabilities.d.cts +31 -0
- package/dist/capabilities.d.ts +31 -0
- package/dist/capabilities.js +12 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/chunk-2432OL7L.js +193 -0
- package/dist/chunk-2432OL7L.js.map +1 -0
- package/dist/chunk-2J65FXEP.js +41 -0
- package/dist/chunk-2J65FXEP.js.map +1 -0
- package/dist/chunk-32NYL7XI.js +539 -0
- package/dist/chunk-32NYL7XI.js.map +1 -0
- package/dist/chunk-3USU7GY2.js +54 -0
- package/dist/chunk-3USU7GY2.js.map +1 -0
- package/dist/chunk-BE6Z4SIT.js +65 -0
- package/dist/chunk-BE6Z4SIT.js.map +1 -0
- package/dist/chunk-CQUG24WX.js +249 -0
- package/dist/chunk-CQUG24WX.js.map +1 -0
- package/dist/chunk-D3X4MN4U.js +288 -0
- package/dist/chunk-D3X4MN4U.js.map +1 -0
- package/dist/chunk-EVZJA6RN.js +140 -0
- package/dist/chunk-EVZJA6RN.js.map +1 -0
- package/dist/chunk-HFWRZVZ3.js +1438 -0
- package/dist/chunk-HFWRZVZ3.js.map +1 -0
- package/dist/chunk-IKKDONQL.js +1 -0
- package/dist/chunk-IKKDONQL.js.map +1 -0
- package/dist/chunk-JTF47B56.js +1 -0
- package/dist/chunk-JTF47B56.js.map +1 -0
- package/dist/chunk-LIXPF4P6.js +22 -0
- package/dist/chunk-LIXPF4P6.js.map +1 -0
- package/dist/chunk-MKBASO6X.js +216 -0
- package/dist/chunk-MKBASO6X.js.map +1 -0
- package/dist/chunk-MPDMJIX5.js +1 -0
- package/dist/chunk-MPDMJIX5.js.map +1 -0
- package/dist/chunk-NCL6WJCL.js +91 -0
- package/dist/chunk-NCL6WJCL.js.map +1 -0
- package/dist/chunk-NU5W6VAV.js +126 -0
- package/dist/chunk-NU5W6VAV.js.map +1 -0
- package/dist/chunk-TGRTEWYV.js +195 -0
- package/dist/chunk-TGRTEWYV.js.map +1 -0
- package/dist/chunk-VDRNNGHX.js +184 -0
- package/dist/chunk-VDRNNGHX.js.map +1 -0
- package/dist/chunk-VN5LDWVN.js +32 -0
- package/dist/chunk-VN5LDWVN.js.map +1 -0
- package/dist/chunk-W2VK36RO.js +11 -0
- package/dist/chunk-W2VK36RO.js.map +1 -0
- package/dist/chunk-X24K52DG.js +12 -0
- package/dist/chunk-X24K52DG.js.map +1 -0
- package/dist/chunk-XLUWV45V.js +25 -0
- package/dist/chunk-XLUWV45V.js.map +1 -0
- package/dist/chunk-Y4RAPKKB.js +238 -0
- package/dist/chunk-Y4RAPKKB.js.map +1 -0
- package/dist/chunk-YXHH3MQT.js +230 -0
- package/dist/chunk-YXHH3MQT.js.map +1 -0
- package/dist/chunk-ZLPL2R3R.js +183 -0
- package/dist/chunk-ZLPL2R3R.js.map +1 -0
- package/dist/chunk-ZTQ5SP4H.js +9 -0
- package/dist/chunk-ZTQ5SP4H.js.map +1 -0
- package/dist/controller-Bod8YYr1.d.cts +172 -0
- package/dist/controller-DxVchfiA.d.ts +172 -0
- package/dist/dev-log-events-CVAM29hx.d.cts +123 -0
- package/dist/dev-log-events-CVAM29hx.d.ts +123 -0
- package/dist/handshake-CC_LrK5g.d.cts +31 -0
- package/dist/handshake-CC_LrK5g.d.ts +31 -0
- package/dist/host-8hmq_Sgc.d.cts +109 -0
- package/dist/host-Cw-N6e-5.d.ts +109 -0
- package/dist/index.cjs +8507 -3523
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +676 -1070
- package/dist/index.d.ts +676 -1070
- package/dist/index.js +4890 -3196
- package/dist/index.js.map +1 -1
- package/dist/metadata.cjs +114 -0
- package/dist/metadata.cjs.map +1 -0
- package/dist/metadata.d.cts +95 -0
- package/dist/metadata.d.ts +95 -0
- package/dist/metadata.js +83 -0
- package/dist/metadata.js.map +1 -0
- package/dist/notices-CnGaaS8B.d.ts +38 -0
- package/dist/notices-NyDM5Mtz.d.cts +38 -0
- package/dist/platform-machine.cjs +425 -0
- package/dist/platform-machine.cjs.map +1 -0
- package/dist/platform-machine.d.cts +1183 -0
- package/dist/platform-machine.d.ts +1183 -0
- package/dist/platform-machine.js +309 -0
- package/dist/platform-machine.js.map +1 -0
- package/dist/platform-settings-cuor3i11.d.cts +48 -0
- package/dist/platform-settings-cuor3i11.d.ts +48 -0
- package/dist/prefabs.cjs +36 -0
- package/dist/prefabs.cjs.map +1 -0
- package/dist/prefabs.d.cts +49 -0
- package/dist/prefabs.d.ts +49 -0
- package/dist/prefabs.js +8 -0
- package/dist/prefabs.js.map +1 -0
- package/dist/preview.cjs +2609 -0
- package/dist/preview.cjs.map +1 -0
- package/dist/preview.d.cts +155 -0
- package/dist/preview.d.ts +155 -0
- package/dist/preview.js +1671 -0
- package/dist/preview.js.map +1 -0
- package/dist/protocol.cjs +621 -54
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +76 -240
- package/dist/protocol.d.ts +76 -240
- package/dist/protocol.js +100 -2
- package/dist/protocol.js.map +1 -1
- package/dist/realtime-client-Cu8yVJFw.d.cts +15 -0
- package/dist/realtime-client-Cu8yVJFw.d.ts +15 -0
- package/dist/release.cjs +143 -0
- package/dist/release.cjs.map +1 -0
- package/dist/release.d.cts +64 -0
- package/dist/release.d.ts +64 -0
- package/dist/release.js +43 -0
- package/dist/release.js.map +1 -0
- package/dist/standard-match-phase-BucA5dYo.d.ts +44 -0
- package/dist/standard-match-phase-U2ra8J-0.d.cts +44 -0
- package/dist/sync-B6QsNrXz.d.cts +125 -0
- package/dist/sync-B6QsNrXz.d.ts +125 -0
- package/dist/ui.cjs +2827 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.cts +320 -0
- package/dist/ui.d.ts +320 -0
- package/dist/ui.js +1718 -0
- package/dist/ui.js.map +1 -0
- package/dist/url-policy-C89zxgw9.d.cts +9 -0
- package/dist/url-policy-C89zxgw9.d.ts +9 -0
- package/package.json +149 -11
- package/src/agent/agent-action.ts +304 -0
- package/src/agent/agent-contract.ts +180 -0
- package/src/agent-tooling.ts +20 -0
- package/src/arcade/bridge/controller.ts +15 -0
- package/src/arcade/bridge/host.ts +12 -0
- package/src/arcade/bridge/iframe.ts +61 -0
- package/src/arcade/bridge.ts +3 -0
- package/src/arcade/host.ts +1 -0
- package/src/arcade/surface.ts +4 -0
- package/src/arcade/url.ts +60 -0
- package/src/arcade.ts +4 -0
- package/src/audio/audio-manager.ts +162 -171
- package/src/audio/hooks.tsx +218 -97
- package/src/audio/index.ts +1 -1
- package/src/audio/music.tsx +139 -0
- package/src/capabilities/manifest.ts +71 -0
- package/src/capabilities.ts +12 -0
- package/src/components/connection-status-pill.tsx +55 -0
- package/src/components/controller-player-name-field.tsx +119 -0
- package/src/components/controller-primary-action.tsx +58 -0
- package/src/components/host-mute-button.tsx +49 -0
- package/src/components/join-qr-overlay.tsx +133 -0
- package/src/components/join-url-action-buttons.tsx +95 -0
- package/src/components/join-url-controls.tsx +58 -0
- package/src/components/join-url-field.tsx +52 -0
- package/src/components/lifecycle-action-group.tsx +129 -0
- package/src/components/player-avatar-strip.tsx +65 -0
- package/src/components/player-avatar.tsx +42 -13
- package/src/components/room-qr-code.tsx +125 -0
- package/src/components/runtime-shell-header.tsx +37 -0
- package/src/components/shell-classes.ts +19 -0
- package/src/components/surface-orientation-layout.ts +60 -0
- package/src/components/surface-viewport-layout.ts +268 -0
- package/src/components/surface-viewport.tsx +314 -0
- package/src/components/ui/button.tsx +4 -6
- package/src/components/ui/slider.tsx +1 -1
- package/src/components/volume-controls.tsx +65 -6
- package/src/context/air-jam-context.tsx +209 -161
- package/src/context/index.ts +2 -2
- package/src/context/session-providers.tsx +77 -0
- package/src/context/session-scope.ts +64 -0
- package/src/context/socket-manager.ts +6 -24
- package/src/contracts/v2/bridge.ts +261 -0
- package/src/contracts/v2/handshake.ts +40 -0
- package/src/contracts/v2/index.ts +2 -0
- package/src/dev/browser-log-sink.ts +912 -0
- package/src/diagnostics.ts +128 -0
- package/src/events.ts +7 -34
- package/src/hooks/internal/use-controller-runtime-api.ts +875 -0
- package/src/hooks/internal/use-host-runtime-api.ts +1051 -0
- package/src/hooks/internal/use-runtime-control-contract.ts +15 -0
- package/src/hooks/internal/use-runtime-inspection-contract.ts +16 -0
- package/src/hooks/internal/use-runtime-observability-contract.ts +24 -0
- package/src/hooks/use-air-jam-controller.ts +155 -475
- package/src/hooks/use-air-jam-host.ts +156 -485
- package/src/hooks/use-connection-status.ts +8 -0
- package/src/hooks/use-controller-lifecycle-intents.ts +27 -0
- package/src/hooks/use-controller-lifecycle-permissions.ts +36 -0
- package/src/hooks/use-controller-shell-status.ts +40 -0
- package/src/hooks/use-controller-tick.ts +65 -0
- package/src/hooks/use-controller-toasts.ts +116 -0
- package/src/hooks/use-get-input.ts +8 -5
- package/src/hooks/use-host-arcade-restore.ts +30 -0
- package/src/hooks/use-host-join-controls.ts +152 -0
- package/src/hooks/use-host-tick.ts +171 -0
- package/src/hooks/use-input-writer.ts +83 -0
- package/src/hooks/use-lifecycle-action-group-model.ts +98 -0
- package/src/hooks/use-players.ts +12 -0
- package/src/hooks/use-room.ts +22 -0
- package/src/hooks/use-send-signal.ts +6 -2
- package/src/index.ts +205 -31
- package/src/internal/input-manager.ts +195 -215
- package/src/lifecycle/index.ts +9 -0
- package/src/lifecycle/standard-match-phase.ts +32 -0
- package/src/metadata/manifest.ts +152 -0
- package/src/metadata.ts +12 -0
- package/src/platform-machine.ts +475 -0
- package/src/prefabs/types.ts +82 -0
- package/src/prefabs.ts +12 -0
- package/src/preview/host-workspace.tsx +59 -0
- package/src/preview/identity.ts +66 -0
- package/src/preview/layout.ts +223 -0
- package/src/preview/manager.ts +577 -0
- package/src/preview/messages.ts +26 -0
- package/src/preview/ownership.ts +81 -0
- package/src/preview/url.ts +117 -0
- package/src/preview/window.tsx +490 -0
- package/src/preview/workspace.tsx +678 -0
- package/src/preview.ts +42 -0
- package/src/protocol/arcade-platform-actions.ts +29 -0
- package/src/protocol/controller.ts +187 -0
- package/src/protocol/core.ts +23 -0
- package/src/protocol/dev-log-events.ts +222 -0
- package/src/protocol/errors.ts +21 -0
- package/src/protocol/host-grant.ts +185 -0
- package/src/protocol/host.ts +138 -0
- package/src/protocol/notices.ts +43 -0
- package/src/protocol/signals.ts +38 -0
- package/src/protocol/socket-events.ts +154 -0
- package/src/protocol/sync.ts +121 -0
- package/src/protocol/url-policy.ts +63 -0
- package/src/protocol.ts +12 -386
- package/src/qrcode.d.ts +16 -0
- package/src/release.ts +99 -0
- package/src/runtime/air-jam-config.ts +287 -0
- package/src/runtime/air-jam-error-boundary.tsx +672 -0
- package/src/runtime/arcade-bridge-request-surface.ts +15 -0
- package/src/runtime/arcade-runtime-url.ts +95 -0
- package/src/runtime/arcade-surface-identity.ts +16 -0
- package/src/runtime/contracts/control.ts +68 -0
- package/src/runtime/contracts/inspection.ts +165 -0
- package/src/runtime/contracts/observability.ts +94 -0
- package/src/runtime/controller-bridge.ts +451 -0
- package/src/runtime/controller-identity.ts +132 -0
- package/src/runtime/controller-presentation.ts +24 -0
- package/src/runtime/controller-realtime-client.ts +591 -0
- package/src/runtime/create-air-jam-app.tsx +260 -0
- package/src/runtime/dev-runtime-events.ts +36 -0
- package/src/runtime/embedded-runtime-adapters.ts +68 -0
- package/src/runtime/host-bridge.ts +388 -0
- package/src/runtime/host-realtime-client.ts +550 -0
- package/src/runtime/iframe-bridge.ts +135 -0
- package/src/runtime/realtime-client.ts +20 -0
- package/src/runtime/router-basename.ts +25 -0
- package/src/runtime/runtime-owner-contexts.tsx +4 -0
- package/src/runtime/runtime-session-params.ts +169 -0
- package/src/runtime/sdk-version.ts +6 -0
- package/src/runtime/session-runtimes.tsx +188 -0
- package/src/runtime/validate-arcade-bridge-attach.ts +14 -0
- package/src/runtime-control.ts +10 -0
- package/src/runtime-inspection.ts +14 -0
- package/src/runtime-observability.ts +9 -0
- package/src/settings/platform-settings-bridge.ts +336 -0
- package/src/settings/platform-settings-runtime.tsx +387 -0
- package/src/settings/platform-settings.ts +288 -0
- package/src/state/connection-store.ts +80 -12
- package/src/store/air-jam-store-domain-constants.ts +4 -0
- package/src/store/create-air-jam-store.ts +1094 -227
- package/src/styles.css +4 -38
- package/src/ui.ts +29 -0
- package/src/utils/is-rpc-serializable.ts +56 -0
- package/src/utils/player-avatar-url.ts +48 -0
- package/src/utils/url-builder.ts +7 -0
- package/dist/.tsbuildinfo +0 -1
- package/dist/chunk-B5DURUWT.js +0 -80
- package/dist/chunk-B5DURUWT.js.map +0 -1
- package/src/AirJamClient.ts +0 -224
- package/src/audio/volume-store.ts +0 -124
- package/src/components/controller-shell.tsx +0 -346
- package/src/components/host-shell.tsx +0 -520
- package/src/components/qr-scanner-dialog.tsx +0 -373
- package/src/components/ui/alert.tsx +0 -66
- package/src/components/ui/avatar.tsx +0 -46
- package/src/components/ui/badge.tsx +0 -47
- package/src/components/ui/card.tsx +0 -92
- package/src/components/ui/dialog.tsx +0 -122
- package/src/components/ui/tabs.tsx +0 -64
- package/src/hooks/use-air-jam-shell.ts +0 -379
- package/src/hooks/use-fullscreen.ts +0 -108
package/dist/preview.js
ADDED
|
@@ -0,0 +1,1671 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
Slider,
|
|
4
|
+
cn,
|
|
5
|
+
shellInsetPanelClassName,
|
|
6
|
+
shellPanelClassName,
|
|
7
|
+
shellUtilityButtonClassName
|
|
8
|
+
} from "./chunk-EVZJA6RN.js";
|
|
9
|
+
import {
|
|
10
|
+
AIR_JAM_PREVIEW_CLOSE_REQUEST,
|
|
11
|
+
AIR_JAM_PREVIEW_DEVICE_QUERY_PARAM,
|
|
12
|
+
AIR_JAM_PREVIEW_FLAG_QUERY_PARAM,
|
|
13
|
+
createPreviewControllerIdentity,
|
|
14
|
+
isPreviewCloseResultMessage,
|
|
15
|
+
isPreviewControllerSearchParams,
|
|
16
|
+
normalizePreviewDeviceId,
|
|
17
|
+
readPreviewControllerDeviceIdFromLocation,
|
|
18
|
+
readPreviewControllerDeviceIdFromSearchParams,
|
|
19
|
+
useAirJamHost
|
|
20
|
+
} from "./chunk-NU5W6VAV.js";
|
|
21
|
+
import {
|
|
22
|
+
useOptionalPlatformSettingsOwnerApi,
|
|
23
|
+
useResolvedPlatformSettingsSnapshot
|
|
24
|
+
} from "./chunk-D3X4MN4U.js";
|
|
25
|
+
import "./chunk-Y4RAPKKB.js";
|
|
26
|
+
import {
|
|
27
|
+
useAirJamConfig
|
|
28
|
+
} from "./chunk-HFWRZVZ3.js";
|
|
29
|
+
import "./chunk-LIXPF4P6.js";
|
|
30
|
+
import "./chunk-W2VK36RO.js";
|
|
31
|
+
import {
|
|
32
|
+
parseOptionalArcadeSurfaceFromSearchParams
|
|
33
|
+
} from "./chunk-BE6Z4SIT.js";
|
|
34
|
+
import "./chunk-CQUG24WX.js";
|
|
35
|
+
import "./chunk-ZLPL2R3R.js";
|
|
36
|
+
import "./chunk-32NYL7XI.js";
|
|
37
|
+
import {
|
|
38
|
+
appendRuntimeQueryParams,
|
|
39
|
+
getRuntimeUrlOrigin,
|
|
40
|
+
normalizeRuntimeUrl
|
|
41
|
+
} from "./chunk-3USU7GY2.js";
|
|
42
|
+
|
|
43
|
+
// src/preview/ownership.ts
|
|
44
|
+
import {
|
|
45
|
+
isLocalDevControlSurfaceRuntimeMode
|
|
46
|
+
} from "@air-jam/runtime-topology";
|
|
47
|
+
var readDevelopmentRuntime = () => {
|
|
48
|
+
try {
|
|
49
|
+
const meta = import.meta;
|
|
50
|
+
const env = meta.env;
|
|
51
|
+
if (typeof env?.DEV === "boolean") {
|
|
52
|
+
return env.DEV;
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
const processLike = globalThis.process;
|
|
57
|
+
return processLike?.env?.NODE_ENV !== "production";
|
|
58
|
+
};
|
|
59
|
+
var readWindowSearchParams = () => {
|
|
60
|
+
if (typeof window === "undefined") {
|
|
61
|
+
return new URLSearchParams();
|
|
62
|
+
}
|
|
63
|
+
return new URLSearchParams(window.location.search);
|
|
64
|
+
};
|
|
65
|
+
var toSearchParams = (value) => {
|
|
66
|
+
if (typeof value === "string") {
|
|
67
|
+
return new URLSearchParams(value);
|
|
68
|
+
}
|
|
69
|
+
return value ?? readWindowSearchParams();
|
|
70
|
+
};
|
|
71
|
+
var isEmbeddedArcadeRuntimeSearchParams = (searchParams) => parseOptionalArcadeSurfaceFromSearchParams(toSearchParams(searchParams)) != null;
|
|
72
|
+
var resolveHostPreviewControllerWorkspaceEnabled = ({
|
|
73
|
+
enabled = "auto",
|
|
74
|
+
topology,
|
|
75
|
+
isDevelopmentRuntime = readDevelopmentRuntime(),
|
|
76
|
+
searchParams
|
|
77
|
+
} = {}) => {
|
|
78
|
+
if (typeof enabled === "boolean") {
|
|
79
|
+
return enabled;
|
|
80
|
+
}
|
|
81
|
+
const localDevControlSurfacesEnabled = topology != null ? isLocalDevControlSurfaceRuntimeMode(topology.runtimeMode) : isDevelopmentRuntime;
|
|
82
|
+
return localDevControlSurfacesEnabled && !isEmbeddedArcadeRuntimeSearchParams(searchParams);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// src/preview/workspace.tsx
|
|
86
|
+
import {
|
|
87
|
+
Bot,
|
|
88
|
+
ChevronDown,
|
|
89
|
+
ChevronUp,
|
|
90
|
+
MonitorSmartphone as MonitorSmartphone2,
|
|
91
|
+
Plus,
|
|
92
|
+
Smartphone,
|
|
93
|
+
X as X2
|
|
94
|
+
} from "lucide-react";
|
|
95
|
+
import { useEffect as useEffect2, useMemo, useRef as useRef3, useState as useState3 } from "react";
|
|
96
|
+
import { createPortal } from "react-dom";
|
|
97
|
+
|
|
98
|
+
// src/preview/layout.ts
|
|
99
|
+
var PREVIEW_WORKSPACE_Z_INDEX = 2147483e3;
|
|
100
|
+
var PREVIEW_WINDOW_TITLEBAR_HEIGHT = 38;
|
|
101
|
+
var PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE = 12;
|
|
102
|
+
var PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE = 20;
|
|
103
|
+
var IPHONE_16_PREVIEW_DEVICE = {
|
|
104
|
+
id: "iphone-16",
|
|
105
|
+
label: "iPhone 16 browser",
|
|
106
|
+
portrait: {
|
|
107
|
+
width: 393,
|
|
108
|
+
height: 740
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
var DEFAULT_PREVIEW_CONTROLLER_DEVICE = IPHONE_16_PREVIEW_DEVICE;
|
|
112
|
+
var DEFAULT_PREVIEW_CONTROLLER_SCALE = 0.8;
|
|
113
|
+
var PREVIEW_CONTROLLER_MIN_SCALE = 0.55;
|
|
114
|
+
var PREVIEW_CONTROLLER_MAX_SCALE = 1.12;
|
|
115
|
+
var getPreviewControllerViewportSize = (orientation, device = DEFAULT_PREVIEW_CONTROLLER_DEVICE) => orientation === "portrait" ? device.portrait : {
|
|
116
|
+
width: device.portrait.height,
|
|
117
|
+
height: device.portrait.width
|
|
118
|
+
};
|
|
119
|
+
var getPreviewControllerScaleConstraints = () => ({
|
|
120
|
+
min: PREVIEW_CONTROLLER_MIN_SCALE,
|
|
121
|
+
max: PREVIEW_CONTROLLER_MAX_SCALE
|
|
122
|
+
});
|
|
123
|
+
var getPreviewWindowBoundsForScale = (orientation, scale, device = DEFAULT_PREVIEW_CONTROLLER_DEVICE) => {
|
|
124
|
+
const viewport = getPreviewControllerViewportSize(orientation, device);
|
|
125
|
+
return {
|
|
126
|
+
width: viewport.width * scale,
|
|
127
|
+
height: PREVIEW_WINDOW_TITLEBAR_HEIGHT + viewport.height * scale
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
var getPreviewControllerScaleForBounds = (orientation, bounds, mode = "fit", device = DEFAULT_PREVIEW_CONTROLLER_DEVICE) => {
|
|
131
|
+
const viewport = getPreviewControllerViewportSize(orientation, device);
|
|
132
|
+
const widthScale = bounds.width / viewport.width;
|
|
133
|
+
const heightScale = (bounds.height - PREVIEW_WINDOW_TITLEBAR_HEIGHT) / viewport.height;
|
|
134
|
+
const rawScale = mode === "grow" ? Math.max(widthScale, heightScale) : mode === "shrink" ? Math.min(widthScale, heightScale) : Math.min(widthScale, heightScale);
|
|
135
|
+
const constraints = getPreviewControllerScaleConstraints();
|
|
136
|
+
return Math.min(Math.max(rawScale, constraints.min), constraints.max);
|
|
137
|
+
};
|
|
138
|
+
var getPreviewControllerScaleForResize = ({
|
|
139
|
+
orientation,
|
|
140
|
+
bounds,
|
|
141
|
+
originBounds,
|
|
142
|
+
handle,
|
|
143
|
+
device = DEFAULT_PREVIEW_CONTROLLER_DEVICE
|
|
144
|
+
}) => {
|
|
145
|
+
const viewport = getPreviewControllerViewportSize(orientation, device);
|
|
146
|
+
const widthScale = bounds.width / viewport.width;
|
|
147
|
+
const heightScale = (bounds.height - PREVIEW_WINDOW_TITLEBAR_HEIGHT) / viewport.height;
|
|
148
|
+
if (handle === "e" || handle === "w") {
|
|
149
|
+
const constraints2 = getPreviewControllerScaleConstraints();
|
|
150
|
+
return Math.min(Math.max(widthScale, constraints2.min), constraints2.max);
|
|
151
|
+
}
|
|
152
|
+
if (handle === "n" || handle === "s") {
|
|
153
|
+
const constraints2 = getPreviewControllerScaleConstraints();
|
|
154
|
+
return Math.min(Math.max(heightScale, constraints2.min), constraints2.max);
|
|
155
|
+
}
|
|
156
|
+
const widthDelta = Math.abs(bounds.width - originBounds.width);
|
|
157
|
+
const heightDelta = Math.abs(bounds.height - originBounds.height);
|
|
158
|
+
const rawScale = widthDelta / viewport.width >= heightDelta / viewport.height ? widthScale : heightScale;
|
|
159
|
+
const constraints = getPreviewControllerScaleConstraints();
|
|
160
|
+
return Math.min(Math.max(rawScale, constraints.min), constraints.max);
|
|
161
|
+
};
|
|
162
|
+
var PREVIEW_WINDOW_DEFAULT_BOUNDS = {
|
|
163
|
+
portrait: getPreviewWindowBoundsForScale(
|
|
164
|
+
"portrait",
|
|
165
|
+
DEFAULT_PREVIEW_CONTROLLER_SCALE
|
|
166
|
+
),
|
|
167
|
+
landscape: getPreviewWindowBoundsForScale(
|
|
168
|
+
"landscape",
|
|
169
|
+
DEFAULT_PREVIEW_CONTROLLER_SCALE
|
|
170
|
+
)
|
|
171
|
+
};
|
|
172
|
+
var PREVIEW_WINDOW_SIZE_CONSTRAINTS = {
|
|
173
|
+
portrait: {
|
|
174
|
+
minWidth: getPreviewWindowBoundsForScale(
|
|
175
|
+
"portrait",
|
|
176
|
+
PREVIEW_CONTROLLER_MIN_SCALE
|
|
177
|
+
).width,
|
|
178
|
+
minHeight: getPreviewWindowBoundsForScale(
|
|
179
|
+
"portrait",
|
|
180
|
+
PREVIEW_CONTROLLER_MIN_SCALE
|
|
181
|
+
).height,
|
|
182
|
+
maxWidth: getPreviewWindowBoundsForScale(
|
|
183
|
+
"portrait",
|
|
184
|
+
PREVIEW_CONTROLLER_MAX_SCALE
|
|
185
|
+
).width,
|
|
186
|
+
maxHeight: getPreviewWindowBoundsForScale(
|
|
187
|
+
"portrait",
|
|
188
|
+
PREVIEW_CONTROLLER_MAX_SCALE
|
|
189
|
+
).height
|
|
190
|
+
},
|
|
191
|
+
landscape: {
|
|
192
|
+
minWidth: getPreviewWindowBoundsForScale(
|
|
193
|
+
"landscape",
|
|
194
|
+
PREVIEW_CONTROLLER_MIN_SCALE
|
|
195
|
+
).width,
|
|
196
|
+
minHeight: getPreviewWindowBoundsForScale(
|
|
197
|
+
"landscape",
|
|
198
|
+
PREVIEW_CONTROLLER_MIN_SCALE
|
|
199
|
+
).height,
|
|
200
|
+
maxWidth: getPreviewWindowBoundsForScale(
|
|
201
|
+
"landscape",
|
|
202
|
+
PREVIEW_CONTROLLER_MAX_SCALE
|
|
203
|
+
).width,
|
|
204
|
+
maxHeight: getPreviewWindowBoundsForScale(
|
|
205
|
+
"landscape",
|
|
206
|
+
PREVIEW_CONTROLLER_MAX_SCALE
|
|
207
|
+
).height
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
var getDefaultPreviewWindowBounds = (orientation) => PREVIEW_WINDOW_DEFAULT_BOUNDS[orientation];
|
|
211
|
+
var getPreviewWindowSizeConstraints = (orientation) => PREVIEW_WINDOW_SIZE_CONSTRAINTS[orientation];
|
|
212
|
+
var getResizedPreviewBounds = (bounds, handle, deltaX, deltaY) => {
|
|
213
|
+
const resizingWest = handle.includes("w");
|
|
214
|
+
const resizingEast = handle.includes("e");
|
|
215
|
+
const resizingNorth = handle.includes("n");
|
|
216
|
+
const resizingSouth = handle.includes("s");
|
|
217
|
+
return {
|
|
218
|
+
x: resizingWest ? bounds.x + deltaX : bounds.x,
|
|
219
|
+
y: resizingNorth ? bounds.y + deltaY : bounds.y,
|
|
220
|
+
width: bounds.width + (resizingEast ? deltaX : 0) - (resizingWest ? deltaX : 0),
|
|
221
|
+
height: bounds.height + (resizingSouth ? deltaY : 0) - (resizingNorth ? deltaY : 0)
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// src/preview/manager.ts
|
|
226
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
227
|
+
|
|
228
|
+
// src/preview/url.ts
|
|
229
|
+
var normalizeAllowedOrigins = (allowedOrigins) => {
|
|
230
|
+
if (!allowedOrigins || allowedOrigins.length === 0) {
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
return allowedOrigins.map((origin) => getRuntimeUrlOrigin(origin)).filter((origin) => origin !== null);
|
|
234
|
+
};
|
|
235
|
+
var buildPreviewControllerUrl = ({
|
|
236
|
+
joinUrl,
|
|
237
|
+
controllerId,
|
|
238
|
+
previewDeviceId,
|
|
239
|
+
allowedOrigins,
|
|
240
|
+
embedOrigin
|
|
241
|
+
}) => {
|
|
242
|
+
const normalizedJoinUrl = normalizeRuntimeUrl(joinUrl);
|
|
243
|
+
if (!normalizedJoinUrl) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
const joinOrigin = getRuntimeUrlOrigin(normalizedJoinUrl);
|
|
247
|
+
const normalizedAllowedOrigins = normalizeAllowedOrigins(allowedOrigins);
|
|
248
|
+
if (normalizedAllowedOrigins.length > 0 && (!joinOrigin || !normalizedAllowedOrigins.includes(joinOrigin))) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
const previewBaseUrl = (() => {
|
|
252
|
+
if (!embedOrigin) {
|
|
253
|
+
return normalizedJoinUrl;
|
|
254
|
+
}
|
|
255
|
+
const normalizedEmbedOrigin = getRuntimeUrlOrigin(embedOrigin);
|
|
256
|
+
if (!normalizedEmbedOrigin) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
const nextUrl = new URL(normalizedJoinUrl);
|
|
260
|
+
const nextOrigin = new URL(normalizedEmbedOrigin);
|
|
261
|
+
nextUrl.protocol = nextOrigin.protocol;
|
|
262
|
+
nextUrl.host = nextOrigin.host;
|
|
263
|
+
return nextUrl.toString();
|
|
264
|
+
})();
|
|
265
|
+
if (!previewBaseUrl) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
return appendRuntimeQueryParams(previewBaseUrl, {
|
|
269
|
+
controllerId,
|
|
270
|
+
[AIR_JAM_PREVIEW_FLAG_QUERY_PARAM]: "1",
|
|
271
|
+
[AIR_JAM_PREVIEW_DEVICE_QUERY_PARAM]: previewDeviceId
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
var createPreviewControllerLaunch = ({
|
|
275
|
+
joinUrl,
|
|
276
|
+
allowedOrigins,
|
|
277
|
+
embedOrigin
|
|
278
|
+
}) => {
|
|
279
|
+
const identity = createPreviewControllerIdentity();
|
|
280
|
+
const url = buildPreviewControllerUrl({
|
|
281
|
+
joinUrl,
|
|
282
|
+
controllerId: identity.controllerId,
|
|
283
|
+
previewDeviceId: identity.deviceId,
|
|
284
|
+
allowedOrigins,
|
|
285
|
+
embedOrigin
|
|
286
|
+
});
|
|
287
|
+
if (!url) {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
...identity,
|
|
292
|
+
url
|
|
293
|
+
};
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// src/preview/manager.ts
|
|
297
|
+
var DEFAULT_VIEWPORT_WIDTH = 1440;
|
|
298
|
+
var DEFAULT_VIEWPORT_HEIGHT = 900;
|
|
299
|
+
var PREVIEW_WINDOW_MARGIN = 24;
|
|
300
|
+
var PREVIEW_WINDOW_CASCADE_OFFSET = 28;
|
|
301
|
+
var DEFAULT_PREVIEW_CONTROLLER_ORIENTATION = "portrait";
|
|
302
|
+
var getViewportSize = () => {
|
|
303
|
+
if (typeof window === "undefined") {
|
|
304
|
+
return {
|
|
305
|
+
width: DEFAULT_VIEWPORT_WIDTH,
|
|
306
|
+
height: DEFAULT_VIEWPORT_HEIGHT
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
width: window.innerWidth,
|
|
311
|
+
height: window.innerHeight
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
var getJoinRoomIdentity = (joinUrl) => {
|
|
315
|
+
if (!joinUrl) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
try {
|
|
319
|
+
const normalizedJoinUrl = normalizeRuntimeUrl(joinUrl) ?? joinUrl;
|
|
320
|
+
const roomId = new URL(normalizedJoinUrl).searchParams.get("room");
|
|
321
|
+
return roomId && roomId.trim().length > 0 ? roomId : normalizedJoinUrl;
|
|
322
|
+
} catch {
|
|
323
|
+
return joinUrl;
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
var clampSize = (orientation, width, height) => {
|
|
327
|
+
const viewport = getViewportSize();
|
|
328
|
+
const constraints = getPreviewWindowSizeConstraints(orientation);
|
|
329
|
+
const maxWidth = Math.max(
|
|
330
|
+
constraints.minWidth,
|
|
331
|
+
Math.min(constraints.maxWidth, viewport.width - PREVIEW_WINDOW_MARGIN * 2)
|
|
332
|
+
);
|
|
333
|
+
const maxHeight = Math.max(
|
|
334
|
+
constraints.minHeight,
|
|
335
|
+
Math.min(
|
|
336
|
+
constraints.maxHeight,
|
|
337
|
+
viewport.height - PREVIEW_WINDOW_MARGIN * 2
|
|
338
|
+
)
|
|
339
|
+
);
|
|
340
|
+
return {
|
|
341
|
+
width: Math.min(Math.max(constraints.minWidth, width), maxWidth),
|
|
342
|
+
height: Math.min(Math.max(constraints.minHeight, height), maxHeight)
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
var clampScaleForViewport = (orientation, scale) => {
|
|
346
|
+
const viewport = getViewportSize();
|
|
347
|
+
const deviceViewport = getPreviewControllerViewportSize(orientation);
|
|
348
|
+
const constraints = getPreviewControllerScaleConstraints();
|
|
349
|
+
const maxByViewport = Math.min(
|
|
350
|
+
(viewport.width - PREVIEW_WINDOW_MARGIN * 2) / deviceViewport.width,
|
|
351
|
+
(viewport.height - PREVIEW_WINDOW_MARGIN * 2 - PREVIEW_WINDOW_TITLEBAR_HEIGHT) / deviceViewport.height
|
|
352
|
+
);
|
|
353
|
+
return Math.min(
|
|
354
|
+
Math.max(scale, constraints.min),
|
|
355
|
+
Math.max(constraints.min, Math.min(constraints.max, maxByViewport))
|
|
356
|
+
);
|
|
357
|
+
};
|
|
358
|
+
var getPreviewWindowBounds = (orientation, scale) => {
|
|
359
|
+
const displayScale = clampScaleForViewport(orientation, scale);
|
|
360
|
+
const viewport = getPreviewControllerViewportSize(orientation);
|
|
361
|
+
const bounds = getPreviewWindowBoundsForScale(orientation, displayScale);
|
|
362
|
+
return {
|
|
363
|
+
...bounds,
|
|
364
|
+
viewportWidth: viewport.width,
|
|
365
|
+
viewportHeight: viewport.height,
|
|
366
|
+
displayScale
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
var clampPosition = (orientation, x, y, width = getDefaultPreviewWindowBounds(DEFAULT_PREVIEW_CONTROLLER_ORIENTATION).width, height = getDefaultPreviewWindowBounds(DEFAULT_PREVIEW_CONTROLLER_ORIENTATION).height) => {
|
|
370
|
+
const viewport = getViewportSize();
|
|
371
|
+
const nextSize = clampSize(orientation, width, height);
|
|
372
|
+
const maxX = Math.max(
|
|
373
|
+
PREVIEW_WINDOW_MARGIN,
|
|
374
|
+
viewport.width - nextSize.width - PREVIEW_WINDOW_MARGIN
|
|
375
|
+
);
|
|
376
|
+
const maxY = Math.max(
|
|
377
|
+
PREVIEW_WINDOW_MARGIN,
|
|
378
|
+
viewport.height - nextSize.height - PREVIEW_WINDOW_MARGIN
|
|
379
|
+
);
|
|
380
|
+
return {
|
|
381
|
+
x: Math.min(Math.max(PREVIEW_WINDOW_MARGIN, x), maxX),
|
|
382
|
+
y: Math.min(Math.max(PREVIEW_WINDOW_MARGIN, y), maxY)
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
var clampBounds = (orientation, bounds, options = {}, currentBounds) => {
|
|
386
|
+
const right = bounds.x + bounds.width;
|
|
387
|
+
const bottom = bounds.y + bounds.height;
|
|
388
|
+
const resizeMode = currentBounds && (bounds.width < currentBounds.width || bounds.height < currentBounds.height) ? "shrink" : "grow";
|
|
389
|
+
const scale = options.resizeHandle && options.originBounds ? getPreviewControllerScaleForResize({
|
|
390
|
+
orientation,
|
|
391
|
+
bounds,
|
|
392
|
+
originBounds: options.originBounds,
|
|
393
|
+
handle: options.resizeHandle
|
|
394
|
+
}) : getPreviewControllerScaleForBounds(orientation, bounds, resizeMode);
|
|
395
|
+
const nextWindowBounds = getPreviewWindowBounds(orientation, scale);
|
|
396
|
+
const { width, height } = nextWindowBounds;
|
|
397
|
+
const x = options.preserveRight ? right - width : bounds.x;
|
|
398
|
+
const y = options.preserveBottom ? bottom - height : bounds.y;
|
|
399
|
+
const position = clampPosition(orientation, x, y, width, height);
|
|
400
|
+
return {
|
|
401
|
+
x: position.x,
|
|
402
|
+
y: position.y,
|
|
403
|
+
width,
|
|
404
|
+
height
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
var getInitialWindowPosition = (sessions, orientation) => {
|
|
408
|
+
const viewport = getViewportSize();
|
|
409
|
+
const defaultBounds = getPreviewWindowBounds(
|
|
410
|
+
orientation,
|
|
411
|
+
DEFAULT_PREVIEW_CONTROLLER_SCALE
|
|
412
|
+
);
|
|
413
|
+
const cascadeCount = Math.min(sessions.length, 3);
|
|
414
|
+
const offset = cascadeCount * PREVIEW_WINDOW_CASCADE_OFFSET;
|
|
415
|
+
const defaultX = (viewport.width - defaultBounds.width) / 2 + offset;
|
|
416
|
+
const defaultY = (viewport.height - defaultBounds.height) / 2 + offset;
|
|
417
|
+
const anchored = clampPosition(
|
|
418
|
+
orientation,
|
|
419
|
+
defaultX,
|
|
420
|
+
defaultY,
|
|
421
|
+
defaultBounds.width,
|
|
422
|
+
defaultBounds.height
|
|
423
|
+
);
|
|
424
|
+
return {
|
|
425
|
+
x: anchored.x,
|
|
426
|
+
y: anchored.y
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
var getNextTopSessionId = (sessions) => sessions.filter((session) => !session.minimized).sort((left, right) => right.zIndex - left.zIndex)[0]?.id ?? null;
|
|
430
|
+
var activateSession = (sessions, id, nextZIndex) => sessions.map(
|
|
431
|
+
(session) => session.id === id ? {
|
|
432
|
+
...session,
|
|
433
|
+
active: true,
|
|
434
|
+
minimized: false,
|
|
435
|
+
zIndex: nextZIndex
|
|
436
|
+
} : { ...session, active: false }
|
|
437
|
+
);
|
|
438
|
+
var normalizeActiveSession = (sessions) => {
|
|
439
|
+
const nextActiveId = getNextTopSessionId(sessions);
|
|
440
|
+
return sessions.map((session) => ({
|
|
441
|
+
...session,
|
|
442
|
+
active: nextActiveId !== null && session.id === nextActiveId
|
|
443
|
+
}));
|
|
444
|
+
};
|
|
445
|
+
var mapSessionsAndNormalizeActive = (sessions, mapSession) => normalizeActiveSession(sessions.map(mapSession));
|
|
446
|
+
var usePreviewControllerManager = ({
|
|
447
|
+
joinUrl,
|
|
448
|
+
enabled = true,
|
|
449
|
+
maxControllers = 2,
|
|
450
|
+
allowedOrigins,
|
|
451
|
+
embedOrigin
|
|
452
|
+
}) => {
|
|
453
|
+
const [sessions, setSessions] = useState([]);
|
|
454
|
+
const nextSessionIdRef = useRef(1);
|
|
455
|
+
const nextOrdinalRef = useRef(1);
|
|
456
|
+
const nextZIndexRef = useRef(1);
|
|
457
|
+
const previousJoinRoomRef = useRef(
|
|
458
|
+
getJoinRoomIdentity(joinUrl)
|
|
459
|
+
);
|
|
460
|
+
useEffect(() => {
|
|
461
|
+
const nextJoinRoom = getJoinRoomIdentity(joinUrl);
|
|
462
|
+
const previousJoinRoom = previousJoinRoomRef.current;
|
|
463
|
+
if (!enabled || previousJoinRoom !== null && nextJoinRoom !== null && previousJoinRoom !== nextJoinRoom) {
|
|
464
|
+
setSessions([]);
|
|
465
|
+
nextSessionIdRef.current = 1;
|
|
466
|
+
nextOrdinalRef.current = 1;
|
|
467
|
+
nextZIndexRef.current = 1;
|
|
468
|
+
}
|
|
469
|
+
previousJoinRoomRef.current = nextJoinRoom;
|
|
470
|
+
}, [enabled, joinUrl]);
|
|
471
|
+
const canSpawn = enabled && typeof joinUrl === "string" && joinUrl.trim().length > 0 && sessions.length < maxControllers;
|
|
472
|
+
const spawnPreviewController = useCallback(() => {
|
|
473
|
+
if (!enabled || !joinUrl) {
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
476
|
+
let nextSession = null;
|
|
477
|
+
setSessions((current) => {
|
|
478
|
+
if (current.length >= maxControllers) {
|
|
479
|
+
return current;
|
|
480
|
+
}
|
|
481
|
+
const launch = createPreviewControllerLaunch({
|
|
482
|
+
joinUrl,
|
|
483
|
+
allowedOrigins,
|
|
484
|
+
embedOrigin
|
|
485
|
+
});
|
|
486
|
+
if (!launch) {
|
|
487
|
+
return current;
|
|
488
|
+
}
|
|
489
|
+
const ordinal = nextOrdinalRef.current++;
|
|
490
|
+
const zIndex = nextZIndexRef.current++;
|
|
491
|
+
const sessionId = `preview_session_${nextSessionIdRef.current++}`;
|
|
492
|
+
const orientation = DEFAULT_PREVIEW_CONTROLLER_ORIENTATION;
|
|
493
|
+
const defaultBounds = getPreviewWindowBounds(
|
|
494
|
+
orientation,
|
|
495
|
+
DEFAULT_PREVIEW_CONTROLLER_SCALE
|
|
496
|
+
);
|
|
497
|
+
const position = getInitialWindowPosition(current, orientation);
|
|
498
|
+
nextSession = {
|
|
499
|
+
id: sessionId,
|
|
500
|
+
ordinal,
|
|
501
|
+
label: `Preview ${ordinal}`,
|
|
502
|
+
controllerId: launch.controllerId,
|
|
503
|
+
deviceId: launch.deviceId,
|
|
504
|
+
url: launch.url,
|
|
505
|
+
surfaceState: "loading",
|
|
506
|
+
orientation,
|
|
507
|
+
minimized: false,
|
|
508
|
+
active: true,
|
|
509
|
+
x: position.x,
|
|
510
|
+
y: position.y,
|
|
511
|
+
width: defaultBounds.width,
|
|
512
|
+
height: defaultBounds.height,
|
|
513
|
+
viewportWidth: defaultBounds.viewportWidth,
|
|
514
|
+
viewportHeight: defaultBounds.viewportHeight,
|
|
515
|
+
displayScale: defaultBounds.displayScale,
|
|
516
|
+
zIndex
|
|
517
|
+
};
|
|
518
|
+
return [
|
|
519
|
+
...current.map((session) => ({ ...session, active: false })),
|
|
520
|
+
nextSession
|
|
521
|
+
];
|
|
522
|
+
});
|
|
523
|
+
return nextSession;
|
|
524
|
+
}, [allowedOrigins, embedOrigin, enabled, joinUrl, maxControllers]);
|
|
525
|
+
const removePreviewController = useCallback((id) => {
|
|
526
|
+
setSessions(
|
|
527
|
+
(current) => normalizeActiveSession(current.filter((session) => session.id !== id))
|
|
528
|
+
);
|
|
529
|
+
}, []);
|
|
530
|
+
const clearPreviewControllers = useCallback(() => {
|
|
531
|
+
setSessions([]);
|
|
532
|
+
nextSessionIdRef.current = 1;
|
|
533
|
+
nextOrdinalRef.current = 1;
|
|
534
|
+
nextZIndexRef.current = 1;
|
|
535
|
+
}, []);
|
|
536
|
+
const minimizePreviewController = useCallback((id) => {
|
|
537
|
+
setSessions(
|
|
538
|
+
(current) => normalizeActiveSession(
|
|
539
|
+
current.map(
|
|
540
|
+
(session) => session.id === id ? { ...session, minimized: true, active: false } : session
|
|
541
|
+
)
|
|
542
|
+
)
|
|
543
|
+
);
|
|
544
|
+
}, []);
|
|
545
|
+
const focusPreviewController = useCallback((id) => {
|
|
546
|
+
const nextZIndex = nextZIndexRef.current++;
|
|
547
|
+
setSessions((current) => activateSession(current, id, nextZIndex));
|
|
548
|
+
}, []);
|
|
549
|
+
const restorePreviewController = useCallback((id) => {
|
|
550
|
+
const nextZIndex = nextZIndexRef.current++;
|
|
551
|
+
setSessions((current) => activateSession(current, id, nextZIndex));
|
|
552
|
+
}, []);
|
|
553
|
+
const setPreviewControllerPosition = useCallback(
|
|
554
|
+
(id, x, y) => {
|
|
555
|
+
setSessions(
|
|
556
|
+
(current) => mapSessionsAndNormalizeActive(current, (session) => {
|
|
557
|
+
if (session.id !== id) {
|
|
558
|
+
return session;
|
|
559
|
+
}
|
|
560
|
+
const nextPosition = clampPosition(
|
|
561
|
+
session.orientation,
|
|
562
|
+
x,
|
|
563
|
+
y,
|
|
564
|
+
session.width,
|
|
565
|
+
session.height
|
|
566
|
+
);
|
|
567
|
+
return {
|
|
568
|
+
...session,
|
|
569
|
+
x: nextPosition.x,
|
|
570
|
+
y: nextPosition.y
|
|
571
|
+
};
|
|
572
|
+
})
|
|
573
|
+
);
|
|
574
|
+
},
|
|
575
|
+
[]
|
|
576
|
+
);
|
|
577
|
+
const setPreviewControllerBounds = useCallback(
|
|
578
|
+
(id, bounds, options = {}) => {
|
|
579
|
+
setSessions(
|
|
580
|
+
(current) => mapSessionsAndNormalizeActive(current, (session) => {
|
|
581
|
+
if (session.id !== id) {
|
|
582
|
+
return session;
|
|
583
|
+
}
|
|
584
|
+
const nextBounds = clampBounds(session.orientation, bounds, options, {
|
|
585
|
+
x: session.x,
|
|
586
|
+
y: session.y,
|
|
587
|
+
width: session.width,
|
|
588
|
+
height: session.height
|
|
589
|
+
});
|
|
590
|
+
const nextWindowBounds = getPreviewWindowBounds(
|
|
591
|
+
session.orientation,
|
|
592
|
+
getPreviewControllerScaleForBounds(session.orientation, nextBounds)
|
|
593
|
+
);
|
|
594
|
+
return {
|
|
595
|
+
...session,
|
|
596
|
+
width: nextWindowBounds.width,
|
|
597
|
+
height: nextWindowBounds.height,
|
|
598
|
+
viewportWidth: nextWindowBounds.viewportWidth,
|
|
599
|
+
viewportHeight: nextWindowBounds.viewportHeight,
|
|
600
|
+
displayScale: nextWindowBounds.displayScale,
|
|
601
|
+
x: nextBounds.x,
|
|
602
|
+
y: nextBounds.y
|
|
603
|
+
};
|
|
604
|
+
})
|
|
605
|
+
);
|
|
606
|
+
},
|
|
607
|
+
[]
|
|
608
|
+
);
|
|
609
|
+
const rotatePreviewController = useCallback((id) => {
|
|
610
|
+
setSessions(
|
|
611
|
+
(current) => mapSessionsAndNormalizeActive(current, (session) => {
|
|
612
|
+
if (session.id !== id) {
|
|
613
|
+
return session;
|
|
614
|
+
}
|
|
615
|
+
const nextOrientation = session.orientation === "portrait" ? "landscape" : "portrait";
|
|
616
|
+
const centerX = session.x + session.width / 2;
|
|
617
|
+
const centerY = session.y + session.height / 2;
|
|
618
|
+
const nextWindowBounds = getPreviewWindowBounds(
|
|
619
|
+
nextOrientation,
|
|
620
|
+
session.displayScale
|
|
621
|
+
);
|
|
622
|
+
const nextBounds = clampBounds(
|
|
623
|
+
nextOrientation,
|
|
624
|
+
{
|
|
625
|
+
x: centerX - nextWindowBounds.width / 2,
|
|
626
|
+
y: centerY - nextWindowBounds.height / 2,
|
|
627
|
+
width: nextWindowBounds.width,
|
|
628
|
+
height: nextWindowBounds.height
|
|
629
|
+
},
|
|
630
|
+
{}
|
|
631
|
+
);
|
|
632
|
+
const clampedWindowBounds = getPreviewWindowBounds(
|
|
633
|
+
nextOrientation,
|
|
634
|
+
getPreviewControllerScaleForBounds(nextOrientation, nextBounds)
|
|
635
|
+
);
|
|
636
|
+
return {
|
|
637
|
+
...session,
|
|
638
|
+
orientation: nextOrientation,
|
|
639
|
+
x: nextBounds.x,
|
|
640
|
+
y: nextBounds.y,
|
|
641
|
+
width: clampedWindowBounds.width,
|
|
642
|
+
height: clampedWindowBounds.height,
|
|
643
|
+
viewportWidth: clampedWindowBounds.viewportWidth,
|
|
644
|
+
viewportHeight: clampedWindowBounds.viewportHeight,
|
|
645
|
+
displayScale: clampedWindowBounds.displayScale
|
|
646
|
+
};
|
|
647
|
+
})
|
|
648
|
+
);
|
|
649
|
+
}, []);
|
|
650
|
+
const markPreviewControllerReady = useCallback((id) => {
|
|
651
|
+
setSessions(
|
|
652
|
+
(current) => mapSessionsAndNormalizeActive(
|
|
653
|
+
current,
|
|
654
|
+
(session) => session.id === id ? { ...session, surfaceState: "ready" } : session
|
|
655
|
+
)
|
|
656
|
+
);
|
|
657
|
+
}, []);
|
|
658
|
+
const markPreviewControllerFailed = useCallback((id) => {
|
|
659
|
+
setSessions(
|
|
660
|
+
(current) => mapSessionsAndNormalizeActive(
|
|
661
|
+
current,
|
|
662
|
+
(session) => session.id === id ? { ...session, surfaceState: "failed" } : session
|
|
663
|
+
)
|
|
664
|
+
);
|
|
665
|
+
}, []);
|
|
666
|
+
return {
|
|
667
|
+
sessions,
|
|
668
|
+
canSpawn,
|
|
669
|
+
spawnPreviewController,
|
|
670
|
+
removePreviewController,
|
|
671
|
+
minimizePreviewController,
|
|
672
|
+
restorePreviewController,
|
|
673
|
+
focusPreviewController,
|
|
674
|
+
setPreviewControllerPosition,
|
|
675
|
+
setPreviewControllerBounds,
|
|
676
|
+
rotatePreviewController,
|
|
677
|
+
markPreviewControllerReady,
|
|
678
|
+
markPreviewControllerFailed,
|
|
679
|
+
clearPreviewControllers
|
|
680
|
+
};
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
// src/preview/window.tsx
|
|
684
|
+
import {
|
|
685
|
+
Loader2,
|
|
686
|
+
Minus,
|
|
687
|
+
MonitorSmartphone,
|
|
688
|
+
SlidersHorizontal,
|
|
689
|
+
TabletSmartphone,
|
|
690
|
+
TriangleAlert,
|
|
691
|
+
X
|
|
692
|
+
} from "lucide-react";
|
|
693
|
+
import { useRef as useRef2, useState as useState2 } from "react";
|
|
694
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
695
|
+
var PREVIEW_WINDOW_SETTINGS_SHELF_HEIGHT = 52;
|
|
696
|
+
var PREVIEW_CLOSE_TIMEOUT_MS = 1e3;
|
|
697
|
+
var requestPreviewControllerClose = async (iframe, sessionUrl) => {
|
|
698
|
+
const frameWindow = iframe?.contentWindow;
|
|
699
|
+
if (!frameWindow) {
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
const targetOrigin = new URL(sessionUrl).origin;
|
|
703
|
+
await new Promise((resolve) => {
|
|
704
|
+
let settled = false;
|
|
705
|
+
const timeout = window.setTimeout(() => {
|
|
706
|
+
cleanup();
|
|
707
|
+
resolve();
|
|
708
|
+
}, PREVIEW_CLOSE_TIMEOUT_MS);
|
|
709
|
+
const handleMessage = (event) => {
|
|
710
|
+
if (event.source !== frameWindow || event.origin !== targetOrigin) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
if (!isPreviewCloseResultMessage(event.data)) {
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
cleanup();
|
|
717
|
+
resolve();
|
|
718
|
+
};
|
|
719
|
+
const cleanup = () => {
|
|
720
|
+
if (settled) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
settled = true;
|
|
724
|
+
window.clearTimeout(timeout);
|
|
725
|
+
window.removeEventListener("message", handleMessage);
|
|
726
|
+
};
|
|
727
|
+
window.addEventListener("message", handleMessage);
|
|
728
|
+
frameWindow.postMessage(
|
|
729
|
+
{
|
|
730
|
+
type: AIR_JAM_PREVIEW_CLOSE_REQUEST
|
|
731
|
+
},
|
|
732
|
+
targetOrigin
|
|
733
|
+
);
|
|
734
|
+
});
|
|
735
|
+
};
|
|
736
|
+
var previewControllerWindowStateLabel = {
|
|
737
|
+
loading: "Loading",
|
|
738
|
+
ready: "Ready",
|
|
739
|
+
failed: "Blocked"
|
|
740
|
+
};
|
|
741
|
+
var RESIZE_HANDLES = [
|
|
742
|
+
{
|
|
743
|
+
handle: "n",
|
|
744
|
+
cursor: "ns-resize",
|
|
745
|
+
style: {
|
|
746
|
+
top: -(PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE / 2),
|
|
747
|
+
left: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE,
|
|
748
|
+
right: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE,
|
|
749
|
+
height: PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE
|
|
750
|
+
}
|
|
751
|
+
},
|
|
752
|
+
{
|
|
753
|
+
handle: "s",
|
|
754
|
+
cursor: "ns-resize",
|
|
755
|
+
style: {
|
|
756
|
+
bottom: -(PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE / 2),
|
|
757
|
+
left: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE,
|
|
758
|
+
right: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE,
|
|
759
|
+
height: PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE
|
|
760
|
+
}
|
|
761
|
+
},
|
|
762
|
+
{
|
|
763
|
+
handle: "e",
|
|
764
|
+
cursor: "ew-resize",
|
|
765
|
+
style: {
|
|
766
|
+
top: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE,
|
|
767
|
+
right: -(PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE / 2),
|
|
768
|
+
bottom: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE,
|
|
769
|
+
width: PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE
|
|
770
|
+
}
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
handle: "w",
|
|
774
|
+
cursor: "ew-resize",
|
|
775
|
+
style: {
|
|
776
|
+
top: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE,
|
|
777
|
+
left: -(PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE / 2),
|
|
778
|
+
bottom: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE,
|
|
779
|
+
width: PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE
|
|
780
|
+
}
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
handle: "ne",
|
|
784
|
+
cursor: "nesw-resize",
|
|
785
|
+
style: {
|
|
786
|
+
top: -(PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE / 2),
|
|
787
|
+
right: -(PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE / 2),
|
|
788
|
+
width: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE,
|
|
789
|
+
height: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE
|
|
790
|
+
}
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
handle: "nw",
|
|
794
|
+
cursor: "nwse-resize",
|
|
795
|
+
style: {
|
|
796
|
+
top: -(PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE / 2),
|
|
797
|
+
left: -(PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE / 2),
|
|
798
|
+
width: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE,
|
|
799
|
+
height: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE
|
|
800
|
+
}
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
handle: "se",
|
|
804
|
+
cursor: "nwse-resize",
|
|
805
|
+
style: {
|
|
806
|
+
right: -(PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE / 2),
|
|
807
|
+
bottom: -(PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE / 2),
|
|
808
|
+
width: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE,
|
|
809
|
+
height: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE
|
|
810
|
+
}
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
handle: "sw",
|
|
814
|
+
cursor: "nesw-resize",
|
|
815
|
+
style: {
|
|
816
|
+
left: -(PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE / 2),
|
|
817
|
+
bottom: -(PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE / 2),
|
|
818
|
+
width: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE,
|
|
819
|
+
height: PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
];
|
|
823
|
+
var PreviewControllerWindow = ({
|
|
824
|
+
session,
|
|
825
|
+
activeOpacity,
|
|
826
|
+
highContrast = false,
|
|
827
|
+
dragging = false,
|
|
828
|
+
onFocus,
|
|
829
|
+
onMinimize,
|
|
830
|
+
onRemove,
|
|
831
|
+
onRotate,
|
|
832
|
+
onActiveOpacityChange,
|
|
833
|
+
onReady,
|
|
834
|
+
onFailed,
|
|
835
|
+
onTitlePointerDown,
|
|
836
|
+
onTitlePointerMove,
|
|
837
|
+
onTitlePointerUp,
|
|
838
|
+
onTitlePointerCancel,
|
|
839
|
+
onResizePointerDown,
|
|
840
|
+
onResizePointerMove,
|
|
841
|
+
onResizePointerUp,
|
|
842
|
+
onResizePointerCancel,
|
|
843
|
+
resizing = false
|
|
844
|
+
}) => {
|
|
845
|
+
const [windowHovered, setWindowHovered] = useState2(false);
|
|
846
|
+
const [settingsOpen, setSettingsOpen] = useState2(false);
|
|
847
|
+
const iframeRef = useRef2(null);
|
|
848
|
+
const isVisible = dragging || resizing || windowHovered;
|
|
849
|
+
const windowOpacity = isVisible ? activeOpacity : Math.min(activeOpacity, 0.62);
|
|
850
|
+
const settingsShelfHeight = settingsOpen && onActiveOpacityChange ? PREVIEW_WINDOW_SETTINGS_SHELF_HEIGHT : 0;
|
|
851
|
+
const contentHeight = Math.max(
|
|
852
|
+
session.height - PREVIEW_WINDOW_TITLEBAR_HEIGHT,
|
|
853
|
+
0
|
|
854
|
+
);
|
|
855
|
+
const nextOrientationLabel = session.orientation === "portrait" ? "landscape" : "portrait";
|
|
856
|
+
const statusToneClassName = session.surfaceState === "failed" ? "bg-amber-300" : session.surfaceState === "ready" ? "bg-emerald-300" : "bg-white/45";
|
|
857
|
+
return /* @__PURE__ */ jsxs(
|
|
858
|
+
"div",
|
|
859
|
+
{
|
|
860
|
+
className: "absolute",
|
|
861
|
+
style: {
|
|
862
|
+
left: session.x,
|
|
863
|
+
top: session.y,
|
|
864
|
+
width: session.width,
|
|
865
|
+
height: session.height + settingsShelfHeight,
|
|
866
|
+
zIndex: session.zIndex,
|
|
867
|
+
pointerEvents: "none"
|
|
868
|
+
},
|
|
869
|
+
onPointerEnter: () => setWindowHovered(true),
|
|
870
|
+
onPointerLeave: () => setWindowHovered(false),
|
|
871
|
+
children: [
|
|
872
|
+
/* @__PURE__ */ jsxs(
|
|
873
|
+
"section",
|
|
874
|
+
{
|
|
875
|
+
className: cn(
|
|
876
|
+
"relative overflow-hidden border-white/10 transition-opacity duration-150",
|
|
877
|
+
shellPanelClassName,
|
|
878
|
+
highContrast && "border-white/30",
|
|
879
|
+
dragging && "shadow-[0_28px_90px_rgba(0,0,0,0.55)]"
|
|
880
|
+
),
|
|
881
|
+
style: {
|
|
882
|
+
width: "100%",
|
|
883
|
+
height: "100%",
|
|
884
|
+
opacity: windowOpacity,
|
|
885
|
+
pointerEvents: "auto"
|
|
886
|
+
},
|
|
887
|
+
children: [
|
|
888
|
+
/* @__PURE__ */ jsxs(
|
|
889
|
+
"div",
|
|
890
|
+
{
|
|
891
|
+
className: "flex h-9 items-center gap-2 border-b border-white/8 px-2.5",
|
|
892
|
+
style: {
|
|
893
|
+
cursor: dragging ? "grabbing" : "grab",
|
|
894
|
+
touchAction: "none",
|
|
895
|
+
userSelect: "none"
|
|
896
|
+
},
|
|
897
|
+
onPointerDown: onTitlePointerDown,
|
|
898
|
+
onPointerMove: onTitlePointerMove,
|
|
899
|
+
onPointerUp: onTitlePointerUp,
|
|
900
|
+
onPointerCancel: onTitlePointerCancel,
|
|
901
|
+
children: [
|
|
902
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-2", children: [
|
|
903
|
+
/* @__PURE__ */ jsx("div", { className: "flex h-5 w-5 items-center justify-center rounded-full border border-white/10 bg-white/[0.05]", children: /* @__PURE__ */ jsx(MonitorSmartphone, { className: "h-3 w-3 text-white/80" }) }),
|
|
904
|
+
/* @__PURE__ */ jsx("div", { className: "min-w-0", children: /* @__PURE__ */ jsx("div", { className: "truncate text-[12px] leading-none font-semibold text-white/92", children: session.label }) }),
|
|
905
|
+
/* @__PURE__ */ jsx(
|
|
906
|
+
"span",
|
|
907
|
+
{
|
|
908
|
+
className: cn(
|
|
909
|
+
"ml-1 h-1.5 w-1.5 rounded-full",
|
|
910
|
+
statusToneClassName
|
|
911
|
+
),
|
|
912
|
+
title: previewControllerWindowStateLabel[session.surfaceState]
|
|
913
|
+
}
|
|
914
|
+
)
|
|
915
|
+
] }),
|
|
916
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
917
|
+
/* @__PURE__ */ jsx(
|
|
918
|
+
Button,
|
|
919
|
+
{
|
|
920
|
+
type: "button",
|
|
921
|
+
variant: "ghost",
|
|
922
|
+
size: "icon-sm",
|
|
923
|
+
className: "h-6 w-6 rounded-full text-white/70 hover:bg-white/[0.08] hover:text-white",
|
|
924
|
+
style: { pointerEvents: "auto" },
|
|
925
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
926
|
+
onClick: onRotate,
|
|
927
|
+
"aria-label": `Rotate ${session.label} to ${nextOrientationLabel}`,
|
|
928
|
+
title: `Rotate to ${nextOrientationLabel}`,
|
|
929
|
+
children: /* @__PURE__ */ jsx(TabletSmartphone, { className: "h-3.5 w-3.5" })
|
|
930
|
+
}
|
|
931
|
+
),
|
|
932
|
+
onActiveOpacityChange ? /* @__PURE__ */ jsx(
|
|
933
|
+
Button,
|
|
934
|
+
{
|
|
935
|
+
type: "button",
|
|
936
|
+
variant: "ghost",
|
|
937
|
+
size: "icon-sm",
|
|
938
|
+
className: cn(
|
|
939
|
+
"h-6 w-6 rounded-full text-white/70 hover:bg-white/[0.08] hover:text-white",
|
|
940
|
+
settingsOpen && "bg-white/[0.08] text-white"
|
|
941
|
+
),
|
|
942
|
+
style: { pointerEvents: "auto" },
|
|
943
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
944
|
+
onClick: () => setSettingsOpen((current) => !current),
|
|
945
|
+
"aria-label": `Adjust ${session.label} opacity`,
|
|
946
|
+
title: `Adjust opacity (${Math.round(activeOpacity * 100)}%)`,
|
|
947
|
+
children: /* @__PURE__ */ jsx(SlidersHorizontal, { className: "h-3.5 w-3.5" })
|
|
948
|
+
}
|
|
949
|
+
) : null,
|
|
950
|
+
/* @__PURE__ */ jsx(
|
|
951
|
+
Button,
|
|
952
|
+
{
|
|
953
|
+
type: "button",
|
|
954
|
+
variant: "ghost",
|
|
955
|
+
size: "icon-sm",
|
|
956
|
+
className: "h-6 w-6 rounded-full text-white/70 hover:bg-white/[0.08] hover:text-white",
|
|
957
|
+
style: { pointerEvents: "auto" },
|
|
958
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
959
|
+
onClick: onMinimize,
|
|
960
|
+
"aria-label": `Minimize ${session.label}`,
|
|
961
|
+
title: "Minimize controller",
|
|
962
|
+
children: /* @__PURE__ */ jsx(Minus, { className: "h-3.5 w-3.5" })
|
|
963
|
+
}
|
|
964
|
+
),
|
|
965
|
+
/* @__PURE__ */ jsx(
|
|
966
|
+
Button,
|
|
967
|
+
{
|
|
968
|
+
type: "button",
|
|
969
|
+
variant: "ghost",
|
|
970
|
+
size: "icon-sm",
|
|
971
|
+
className: "h-6 w-6 rounded-full text-white/70 hover:bg-white/[0.08] hover:text-white",
|
|
972
|
+
style: { pointerEvents: "auto" },
|
|
973
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
974
|
+
onClick: () => {
|
|
975
|
+
void requestPreviewControllerClose(
|
|
976
|
+
iframeRef.current,
|
|
977
|
+
session.url
|
|
978
|
+
).catch(() => void 0).finally(() => onRemove());
|
|
979
|
+
},
|
|
980
|
+
"aria-label": `Close ${session.label}`,
|
|
981
|
+
title: "Close controller",
|
|
982
|
+
children: /* @__PURE__ */ jsx(X, { className: "h-3.5 w-3.5" })
|
|
983
|
+
}
|
|
984
|
+
)
|
|
985
|
+
] })
|
|
986
|
+
]
|
|
987
|
+
}
|
|
988
|
+
),
|
|
989
|
+
settingsOpen && onActiveOpacityChange ? /* @__PURE__ */ jsxs(
|
|
990
|
+
"div",
|
|
991
|
+
{
|
|
992
|
+
className: "border-b border-white/8 bg-black/72 px-3 py-2.5 backdrop-blur-sm",
|
|
993
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
994
|
+
children: [
|
|
995
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-center justify-between gap-3", children: [
|
|
996
|
+
/* @__PURE__ */ jsx("p", { className: "text-[11px] font-semibold tracking-[0.16em] text-slate-300 uppercase", children: "Opacity" }),
|
|
997
|
+
/* @__PURE__ */ jsxs("span", { className: "font-mono text-[11px] text-slate-400", children: [
|
|
998
|
+
Math.round(activeOpacity * 100),
|
|
999
|
+
"%"
|
|
1000
|
+
] })
|
|
1001
|
+
] }),
|
|
1002
|
+
/* @__PURE__ */ jsx(
|
|
1003
|
+
Slider,
|
|
1004
|
+
{
|
|
1005
|
+
value: [activeOpacity * 100],
|
|
1006
|
+
onValueChange: (values) => onActiveOpacityChange(values[0] / 100),
|
|
1007
|
+
min: 35,
|
|
1008
|
+
max: 100,
|
|
1009
|
+
step: 1,
|
|
1010
|
+
"aria-label": "Preview controller opacity"
|
|
1011
|
+
}
|
|
1012
|
+
)
|
|
1013
|
+
]
|
|
1014
|
+
}
|
|
1015
|
+
) : null,
|
|
1016
|
+
/* @__PURE__ */ jsx(
|
|
1017
|
+
"div",
|
|
1018
|
+
{
|
|
1019
|
+
className: "relative",
|
|
1020
|
+
onPointerDownCapture: () => {
|
|
1021
|
+
if (!session.active) {
|
|
1022
|
+
onFocus();
|
|
1023
|
+
}
|
|
1024
|
+
},
|
|
1025
|
+
children: /* @__PURE__ */ jsxs(
|
|
1026
|
+
"div",
|
|
1027
|
+
{
|
|
1028
|
+
className: "relative overflow-hidden bg-black",
|
|
1029
|
+
style: {
|
|
1030
|
+
width: session.width,
|
|
1031
|
+
height: contentHeight
|
|
1032
|
+
},
|
|
1033
|
+
children: [
|
|
1034
|
+
/* @__PURE__ */ jsx(
|
|
1035
|
+
"div",
|
|
1036
|
+
{
|
|
1037
|
+
className: "origin-top-left",
|
|
1038
|
+
style: {
|
|
1039
|
+
width: session.viewportWidth,
|
|
1040
|
+
height: session.viewportHeight,
|
|
1041
|
+
transform: `scale(${session.displayScale})`,
|
|
1042
|
+
transformOrigin: "top left"
|
|
1043
|
+
},
|
|
1044
|
+
children: /* @__PURE__ */ jsx(
|
|
1045
|
+
"iframe",
|
|
1046
|
+
{
|
|
1047
|
+
ref: iframeRef,
|
|
1048
|
+
src: session.url,
|
|
1049
|
+
title: `${session.label} controller`,
|
|
1050
|
+
"data-testid": `preview-controller-frame-${session.ordinal}`,
|
|
1051
|
+
className: "border-none bg-black",
|
|
1052
|
+
style: {
|
|
1053
|
+
width: session.viewportWidth,
|
|
1054
|
+
height: session.viewportHeight
|
|
1055
|
+
},
|
|
1056
|
+
allow: "vibrate; gyroscope; accelerometer; autoplay; fullscreen",
|
|
1057
|
+
sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox allow-modals",
|
|
1058
|
+
onLoad: onReady,
|
|
1059
|
+
onError: onFailed
|
|
1060
|
+
}
|
|
1061
|
+
)
|
|
1062
|
+
}
|
|
1063
|
+
),
|
|
1064
|
+
session.surfaceState === "loading" ? /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-0 flex items-center justify-center bg-black/34 backdrop-blur-[1px]", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 rounded-full border border-white/10 bg-black/70 px-3 py-1.5 text-[11px] text-slate-200 shadow-lg", children: [
|
|
1065
|
+
/* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin" }),
|
|
1066
|
+
"Loading"
|
|
1067
|
+
] }) }) : null,
|
|
1068
|
+
session.surfaceState === "failed" ? /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-black/84 px-5 text-center backdrop-blur-[2px]", children: /* @__PURE__ */ jsxs("div", { className: "max-w-[14rem] space-y-2.5", children: [
|
|
1069
|
+
/* @__PURE__ */ jsx("div", { className: "mx-auto flex h-8 w-8 items-center justify-center rounded-full border border-amber-400/22 bg-amber-400/8 text-amber-200", children: /* @__PURE__ */ jsx(TriangleAlert, { className: "h-3.5 w-3.5" }) }),
|
|
1070
|
+
/* @__PURE__ */ jsx("div", { className: "text-sm font-semibold text-white", children: "Controller did not load" }),
|
|
1071
|
+
/* @__PURE__ */ jsx("p", { className: "text-[11px] leading-5 text-slate-300", children: "Close it and open a fresh controller once the route is ready again." })
|
|
1072
|
+
] }) }) : null
|
|
1073
|
+
]
|
|
1074
|
+
}
|
|
1075
|
+
)
|
|
1076
|
+
}
|
|
1077
|
+
)
|
|
1078
|
+
]
|
|
1079
|
+
}
|
|
1080
|
+
),
|
|
1081
|
+
RESIZE_HANDLES.map(({ handle, cursor, style }) => /* @__PURE__ */ jsx(
|
|
1082
|
+
"div",
|
|
1083
|
+
{
|
|
1084
|
+
"data-testid": `preview-controller-resize-${handle}-${session.ordinal}`,
|
|
1085
|
+
className: "absolute",
|
|
1086
|
+
style: {
|
|
1087
|
+
...style,
|
|
1088
|
+
cursor,
|
|
1089
|
+
pointerEvents: "auto",
|
|
1090
|
+
touchAction: "none"
|
|
1091
|
+
},
|
|
1092
|
+
onPointerDown: (event) => onResizePointerDown(handle, event),
|
|
1093
|
+
onPointerMove: onResizePointerMove,
|
|
1094
|
+
onPointerUp: onResizePointerUp,
|
|
1095
|
+
onPointerCancel: onResizePointerCancel,
|
|
1096
|
+
title: "Resize controller"
|
|
1097
|
+
},
|
|
1098
|
+
handle
|
|
1099
|
+
))
|
|
1100
|
+
]
|
|
1101
|
+
}
|
|
1102
|
+
);
|
|
1103
|
+
};
|
|
1104
|
+
|
|
1105
|
+
// src/preview/workspace.tsx
|
|
1106
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1107
|
+
var getControllerSourceLabel = (source) => {
|
|
1108
|
+
if (source === "virtual") {
|
|
1109
|
+
return "Agent";
|
|
1110
|
+
}
|
|
1111
|
+
return source === "preview" ? "Preview" : "Phone";
|
|
1112
|
+
};
|
|
1113
|
+
var getControllerSourceIcon = (source) => {
|
|
1114
|
+
if (source === "virtual") {
|
|
1115
|
+
return Bot;
|
|
1116
|
+
}
|
|
1117
|
+
if (source === "preview") {
|
|
1118
|
+
return MonitorSmartphone2;
|
|
1119
|
+
}
|
|
1120
|
+
return Smartphone;
|
|
1121
|
+
};
|
|
1122
|
+
var PreviewControllerWorkspace = ({
|
|
1123
|
+
joinUrl,
|
|
1124
|
+
embedOrigin,
|
|
1125
|
+
controllers = [],
|
|
1126
|
+
onRemoveController,
|
|
1127
|
+
onResetRoom,
|
|
1128
|
+
enabled = false,
|
|
1129
|
+
highContrast = false,
|
|
1130
|
+
onActiveOpacityChange,
|
|
1131
|
+
className,
|
|
1132
|
+
dockAccessory,
|
|
1133
|
+
maxControllers = 2,
|
|
1134
|
+
launcherLabel = "Controllers",
|
|
1135
|
+
waitingLabel = "Waiting for room"
|
|
1136
|
+
}) => {
|
|
1137
|
+
const [mounted, setMounted] = useState3(false);
|
|
1138
|
+
const [dragState, setDragState] = useState3(null);
|
|
1139
|
+
const [resizeState, setResizeState] = useState3(null);
|
|
1140
|
+
const [launcherOpen, setLauncherOpen] = useState3(false);
|
|
1141
|
+
const [removingControllerId, setRemovingControllerId] = useState3(null);
|
|
1142
|
+
const [resettingRoom, setResettingRoom] = useState3(false);
|
|
1143
|
+
const dockRef = useRef3(null);
|
|
1144
|
+
const resolvedEmbedOrigin = embedOrigin ?? (typeof window !== "undefined" ? window.location.origin : null);
|
|
1145
|
+
const {
|
|
1146
|
+
sessions,
|
|
1147
|
+
canSpawn,
|
|
1148
|
+
spawnPreviewController,
|
|
1149
|
+
clearPreviewControllers,
|
|
1150
|
+
removePreviewController,
|
|
1151
|
+
minimizePreviewController,
|
|
1152
|
+
restorePreviewController,
|
|
1153
|
+
focusPreviewController,
|
|
1154
|
+
setPreviewControllerPosition,
|
|
1155
|
+
setPreviewControllerBounds,
|
|
1156
|
+
rotatePreviewController,
|
|
1157
|
+
markPreviewControllerReady,
|
|
1158
|
+
markPreviewControllerFailed
|
|
1159
|
+
} = usePreviewControllerManager({
|
|
1160
|
+
joinUrl,
|
|
1161
|
+
embedOrigin: resolvedEmbedOrigin,
|
|
1162
|
+
enabled,
|
|
1163
|
+
maxControllers
|
|
1164
|
+
});
|
|
1165
|
+
const platformSettings = useResolvedPlatformSettingsSnapshot();
|
|
1166
|
+
const activeOpacity = platformSettings.previewControllers.activeOpacity;
|
|
1167
|
+
const sortedSessions = useMemo(
|
|
1168
|
+
() => [...sessions].sort((left, right) => left.ordinal - right.ordinal),
|
|
1169
|
+
[sessions]
|
|
1170
|
+
);
|
|
1171
|
+
useEffect2(() => {
|
|
1172
|
+
setMounted(true);
|
|
1173
|
+
return () => setMounted(false);
|
|
1174
|
+
}, []);
|
|
1175
|
+
useEffect2(() => {
|
|
1176
|
+
if (!launcherOpen || typeof document === "undefined") {
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
const handlePointerDown = (event) => {
|
|
1180
|
+
const target = event.target;
|
|
1181
|
+
if (!(target instanceof Node)) {
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
if (dockRef.current?.contains(target)) {
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
setLauncherOpen(false);
|
|
1188
|
+
};
|
|
1189
|
+
const handleKeyDown = (event) => {
|
|
1190
|
+
if (event.key === "Escape") {
|
|
1191
|
+
setLauncherOpen(false);
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
document.addEventListener("pointerdown", handlePointerDown);
|
|
1195
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
1196
|
+
return () => {
|
|
1197
|
+
document.removeEventListener("pointerdown", handlePointerDown);
|
|
1198
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
1199
|
+
};
|
|
1200
|
+
}, [launcherOpen]);
|
|
1201
|
+
const minimizedSessions = useMemo(
|
|
1202
|
+
() => sessions.filter((session) => session.minimized).sort((left, right) => left.ordinal - right.ordinal),
|
|
1203
|
+
[sessions]
|
|
1204
|
+
);
|
|
1205
|
+
const openSessions = useMemo(
|
|
1206
|
+
() => sessions.filter((session) => !session.minimized),
|
|
1207
|
+
[sessions]
|
|
1208
|
+
);
|
|
1209
|
+
const sortedControllers = useMemo(
|
|
1210
|
+
() => [...controllers].sort(
|
|
1211
|
+
(left, right) => left.controllerId.localeCompare(right.controllerId)
|
|
1212
|
+
),
|
|
1213
|
+
[controllers]
|
|
1214
|
+
);
|
|
1215
|
+
const controllerRoster = useMemo(() => {
|
|
1216
|
+
const sessionsByControllerId = new Map(
|
|
1217
|
+
sortedSessions.map((session) => [session.controllerId, session])
|
|
1218
|
+
);
|
|
1219
|
+
const controllerItems = sortedControllers.map((controller) => {
|
|
1220
|
+
const session = sessionsByControllerId.get(controller.controllerId) ?? null;
|
|
1221
|
+
return {
|
|
1222
|
+
id: controller.controllerId,
|
|
1223
|
+
controllerId: controller.controllerId,
|
|
1224
|
+
label: controller.player?.label ?? controller.nickname ?? controller.controllerId,
|
|
1225
|
+
source: controller.source,
|
|
1226
|
+
connected: controller.connected,
|
|
1227
|
+
resumable: Boolean(controller.resumeLeaseExpiresAt),
|
|
1228
|
+
session,
|
|
1229
|
+
controller
|
|
1230
|
+
};
|
|
1231
|
+
});
|
|
1232
|
+
const connectedControllerIds = new Set(
|
|
1233
|
+
sortedControllers.map((controller) => controller.controllerId)
|
|
1234
|
+
);
|
|
1235
|
+
const pendingPreviewItems = sortedSessions.filter((session) => !connectedControllerIds.has(session.controllerId)).map((session) => ({
|
|
1236
|
+
id: session.id,
|
|
1237
|
+
controllerId: session.controllerId,
|
|
1238
|
+
label: session.label,
|
|
1239
|
+
source: "preview",
|
|
1240
|
+
connected: session.surfaceState === "ready",
|
|
1241
|
+
resumable: false,
|
|
1242
|
+
session,
|
|
1243
|
+
controller: null
|
|
1244
|
+
}));
|
|
1245
|
+
return [...controllerItems, ...pendingPreviewItems].sort((left, right) => {
|
|
1246
|
+
if (left.source !== right.source) {
|
|
1247
|
+
const weight = {
|
|
1248
|
+
phone: 0,
|
|
1249
|
+
preview: 1,
|
|
1250
|
+
virtual: 2
|
|
1251
|
+
};
|
|
1252
|
+
return weight[left.source] - weight[right.source];
|
|
1253
|
+
}
|
|
1254
|
+
return left.label.localeCompare(right.label);
|
|
1255
|
+
});
|
|
1256
|
+
}, [sortedControllers, sortedSessions]);
|
|
1257
|
+
if (!enabled || !mounted || typeof document === "undefined") {
|
|
1258
|
+
return null;
|
|
1259
|
+
}
|
|
1260
|
+
return createPortal(
|
|
1261
|
+
/* @__PURE__ */ jsxs2(
|
|
1262
|
+
"div",
|
|
1263
|
+
{
|
|
1264
|
+
className: "fixed inset-0",
|
|
1265
|
+
style: { zIndex: PREVIEW_WORKSPACE_Z_INDEX, pointerEvents: "none" },
|
|
1266
|
+
children: [
|
|
1267
|
+
openSessions.map((session) => /* @__PURE__ */ jsx2(
|
|
1268
|
+
PreviewControllerWindow,
|
|
1269
|
+
{
|
|
1270
|
+
session,
|
|
1271
|
+
activeOpacity,
|
|
1272
|
+
highContrast,
|
|
1273
|
+
dragging: dragState?.id === session.id,
|
|
1274
|
+
resizing: resizeState?.id === session.id,
|
|
1275
|
+
onFocus: () => focusPreviewController(session.id),
|
|
1276
|
+
onMinimize: () => minimizePreviewController(session.id),
|
|
1277
|
+
onRemove: () => removePreviewController(session.id),
|
|
1278
|
+
onRotate: () => rotatePreviewController(session.id),
|
|
1279
|
+
onActiveOpacityChange,
|
|
1280
|
+
onReady: () => markPreviewControllerReady(session.id),
|
|
1281
|
+
onFailed: () => markPreviewControllerFailed(session.id),
|
|
1282
|
+
onTitlePointerDown: (event) => {
|
|
1283
|
+
if (event.button !== 0) {
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
1287
|
+
focusPreviewController(session.id);
|
|
1288
|
+
setDragState({
|
|
1289
|
+
id: session.id,
|
|
1290
|
+
originX: session.x,
|
|
1291
|
+
originY: session.y,
|
|
1292
|
+
startClientX: event.clientX,
|
|
1293
|
+
startClientY: event.clientY,
|
|
1294
|
+
pointerId: event.pointerId
|
|
1295
|
+
});
|
|
1296
|
+
event.preventDefault();
|
|
1297
|
+
},
|
|
1298
|
+
onTitlePointerMove: (event) => {
|
|
1299
|
+
if (resizeState || !dragState || dragState.id !== session.id || dragState.pointerId !== event.pointerId) {
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
setPreviewControllerPosition(
|
|
1303
|
+
dragState.id,
|
|
1304
|
+
dragState.originX + (event.clientX - dragState.startClientX),
|
|
1305
|
+
dragState.originY + (event.clientY - dragState.startClientY)
|
|
1306
|
+
);
|
|
1307
|
+
},
|
|
1308
|
+
onTitlePointerUp: (event) => {
|
|
1309
|
+
if (dragState?.pointerId !== event.pointerId) {
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
1313
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
1314
|
+
}
|
|
1315
|
+
setDragState(null);
|
|
1316
|
+
},
|
|
1317
|
+
onTitlePointerCancel: (event) => {
|
|
1318
|
+
if (dragState?.pointerId !== event.pointerId) {
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
1322
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
1323
|
+
}
|
|
1324
|
+
setDragState(null);
|
|
1325
|
+
},
|
|
1326
|
+
onResizePointerDown: (handle, event) => {
|
|
1327
|
+
if (event.button !== 0) {
|
|
1328
|
+
return;
|
|
1329
|
+
}
|
|
1330
|
+
event.stopPropagation();
|
|
1331
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
1332
|
+
focusPreviewController(session.id);
|
|
1333
|
+
setResizeState({
|
|
1334
|
+
id: session.id,
|
|
1335
|
+
handle,
|
|
1336
|
+
originBounds: {
|
|
1337
|
+
x: session.x,
|
|
1338
|
+
y: session.y,
|
|
1339
|
+
width: session.width,
|
|
1340
|
+
height: session.height
|
|
1341
|
+
},
|
|
1342
|
+
startClientX: event.clientX,
|
|
1343
|
+
startClientY: event.clientY,
|
|
1344
|
+
pointerId: event.pointerId
|
|
1345
|
+
});
|
|
1346
|
+
event.preventDefault();
|
|
1347
|
+
},
|
|
1348
|
+
onResizePointerMove: (event) => {
|
|
1349
|
+
if (!resizeState || resizeState.id !== session.id || resizeState.pointerId !== event.pointerId) {
|
|
1350
|
+
return;
|
|
1351
|
+
}
|
|
1352
|
+
setPreviewControllerBounds(
|
|
1353
|
+
resizeState.id,
|
|
1354
|
+
getResizedPreviewBounds(
|
|
1355
|
+
resizeState.originBounds,
|
|
1356
|
+
resizeState.handle,
|
|
1357
|
+
event.clientX - resizeState.startClientX,
|
|
1358
|
+
event.clientY - resizeState.startClientY
|
|
1359
|
+
),
|
|
1360
|
+
{
|
|
1361
|
+
preserveRight: resizeState.handle.includes("w"),
|
|
1362
|
+
preserveBottom: resizeState.handle.includes("n"),
|
|
1363
|
+
resizeHandle: resizeState.handle,
|
|
1364
|
+
originBounds: resizeState.originBounds
|
|
1365
|
+
}
|
|
1366
|
+
);
|
|
1367
|
+
},
|
|
1368
|
+
onResizePointerUp: (event) => {
|
|
1369
|
+
if (resizeState?.pointerId !== event.pointerId) {
|
|
1370
|
+
return;
|
|
1371
|
+
}
|
|
1372
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
1373
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
1374
|
+
}
|
|
1375
|
+
setResizeState(null);
|
|
1376
|
+
},
|
|
1377
|
+
onResizePointerCancel: (event) => {
|
|
1378
|
+
if (resizeState?.pointerId !== event.pointerId) {
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
1382
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
1383
|
+
}
|
|
1384
|
+
setResizeState(null);
|
|
1385
|
+
}
|
|
1386
|
+
},
|
|
1387
|
+
session.id
|
|
1388
|
+
)),
|
|
1389
|
+
/* @__PURE__ */ jsxs2(
|
|
1390
|
+
"div",
|
|
1391
|
+
{
|
|
1392
|
+
ref: dockRef,
|
|
1393
|
+
className: cn(
|
|
1394
|
+
"fixed flex max-w-[calc(100vw-2rem)] flex-col items-end gap-2",
|
|
1395
|
+
className ?? "right-4 bottom-4 sm:right-6 sm:bottom-6"
|
|
1396
|
+
),
|
|
1397
|
+
style: { pointerEvents: "none" },
|
|
1398
|
+
children: [
|
|
1399
|
+
/* @__PURE__ */ jsxs2(
|
|
1400
|
+
"div",
|
|
1401
|
+
{
|
|
1402
|
+
className: "flex items-start justify-end gap-2",
|
|
1403
|
+
style: { pointerEvents: "auto" },
|
|
1404
|
+
children: [
|
|
1405
|
+
dockAccessory,
|
|
1406
|
+
/* @__PURE__ */ jsxs2(
|
|
1407
|
+
Button,
|
|
1408
|
+
{
|
|
1409
|
+
type: "button",
|
|
1410
|
+
variant: "ghost",
|
|
1411
|
+
size: "sm",
|
|
1412
|
+
className: cn(
|
|
1413
|
+
"rounded-full border border-white/25 bg-black/35 px-3 text-white backdrop-blur-sm hover:bg-black/55 disabled:border-white/10 disabled:bg-black/25 disabled:text-white/40"
|
|
1414
|
+
),
|
|
1415
|
+
"aria-expanded": launcherOpen,
|
|
1416
|
+
"aria-label": launcherOpen ? "Hide preview controllers" : "Show preview controllers",
|
|
1417
|
+
title: !joinUrl ? waitingLabel : launcherLabel,
|
|
1418
|
+
onClick: () => setLauncherOpen((current) => !current),
|
|
1419
|
+
children: [
|
|
1420
|
+
/* @__PURE__ */ jsx2(MonitorSmartphone2, { className: "h-4 w-4" }),
|
|
1421
|
+
/* @__PURE__ */ jsx2("span", { className: "text-[11px] font-semibold tracking-[0.16em] uppercase", children: launcherLabel }),
|
|
1422
|
+
/* @__PURE__ */ jsx2("span", { className: "rounded-full border border-white/12 bg-white/6 px-1.5 py-0.5 text-[10px] leading-none font-semibold text-white/88", children: sessions.length }),
|
|
1423
|
+
launcherOpen ? /* @__PURE__ */ jsx2(ChevronUp, { className: "h-4 w-4 text-white/60" }) : /* @__PURE__ */ jsx2(ChevronDown, { className: "h-4 w-4 text-white/60" })
|
|
1424
|
+
]
|
|
1425
|
+
}
|
|
1426
|
+
)
|
|
1427
|
+
]
|
|
1428
|
+
}
|
|
1429
|
+
),
|
|
1430
|
+
launcherOpen ? /* @__PURE__ */ jsx2(
|
|
1431
|
+
"section",
|
|
1432
|
+
{
|
|
1433
|
+
className: cn(
|
|
1434
|
+
"w-88 max-w-[calc(100vw-2rem)] overflow-hidden p-4",
|
|
1435
|
+
shellPanelClassName,
|
|
1436
|
+
highContrast && "border-white/30"
|
|
1437
|
+
),
|
|
1438
|
+
style: { pointerEvents: "auto" },
|
|
1439
|
+
children: /* @__PURE__ */ jsx2("div", { className: "space-y-4", children: /* @__PURE__ */ jsxs2("div", { className: "space-y-4", children: [
|
|
1440
|
+
controllerRoster.length > 0 || onResetRoom ? /* @__PURE__ */ jsxs2("div", { className: "space-y-3", children: [
|
|
1441
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex items-start justify-between gap-3", children: [
|
|
1442
|
+
/* @__PURE__ */ jsxs2("div", { className: "min-w-0", children: [
|
|
1443
|
+
/* @__PURE__ */ jsx2("p", { className: "text-[11px] font-semibold tracking-[0.18em] text-white/54 uppercase", children: "Controllers" }),
|
|
1444
|
+
/* @__PURE__ */ jsx2("p", { className: "mt-2 text-sm text-white/86", children: controllerRoster.length === 0 ? "No controllers yet" : `${controllerRoster.length} controller${controllerRoster.length === 1 ? "" : "s"} connected` })
|
|
1445
|
+
] }),
|
|
1446
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex shrink-0 items-center gap-1.5", children: [
|
|
1447
|
+
onResetRoom ? /* @__PURE__ */ jsx2(
|
|
1448
|
+
Button,
|
|
1449
|
+
{
|
|
1450
|
+
type: "button",
|
|
1451
|
+
variant: "ghost",
|
|
1452
|
+
size: "sm",
|
|
1453
|
+
className: "h-7 rounded-full px-3 text-[10px] text-amber-100 hover:bg-amber-400/10 hover:text-amber-50 disabled:text-white/35",
|
|
1454
|
+
disabled: resettingRoom,
|
|
1455
|
+
onClick: async () => {
|
|
1456
|
+
try {
|
|
1457
|
+
setResettingRoom(true);
|
|
1458
|
+
await onResetRoom();
|
|
1459
|
+
} finally {
|
|
1460
|
+
setResettingRoom(false);
|
|
1461
|
+
}
|
|
1462
|
+
},
|
|
1463
|
+
children: "Reset room"
|
|
1464
|
+
}
|
|
1465
|
+
) : null,
|
|
1466
|
+
sessions.length > 0 ? /* @__PURE__ */ jsx2(
|
|
1467
|
+
Button,
|
|
1468
|
+
{
|
|
1469
|
+
type: "button",
|
|
1470
|
+
variant: "ghost",
|
|
1471
|
+
size: "icon-sm",
|
|
1472
|
+
className: "h-7 w-7 rounded-full text-white/72 hover:bg-white/8 hover:text-white",
|
|
1473
|
+
onClick: () => clearPreviewControllers(),
|
|
1474
|
+
title: "Close all preview controllers",
|
|
1475
|
+
children: /* @__PURE__ */ jsx2(X2, { className: "h-4 w-4" })
|
|
1476
|
+
}
|
|
1477
|
+
) : null
|
|
1478
|
+
] })
|
|
1479
|
+
] }),
|
|
1480
|
+
/* @__PURE__ */ jsx2("div", { className: "space-y-2", children: controllerRoster.map((item) => {
|
|
1481
|
+
const SourceIcon = getControllerSourceIcon(item.source);
|
|
1482
|
+
const previewSession = item.session;
|
|
1483
|
+
return /* @__PURE__ */ jsxs2(
|
|
1484
|
+
"div",
|
|
1485
|
+
{
|
|
1486
|
+
"data-airjam-controller-row": true,
|
|
1487
|
+
"data-controller-id": item.controllerId,
|
|
1488
|
+
"data-controller-source": item.source,
|
|
1489
|
+
className: cn(
|
|
1490
|
+
"flex items-center gap-2.5 rounded-2xl px-3 py-2.5",
|
|
1491
|
+
shellInsetPanelClassName
|
|
1492
|
+
),
|
|
1493
|
+
children: [
|
|
1494
|
+
/* @__PURE__ */ jsx2("div", { className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-white/10 bg-white/5 text-white/70", children: /* @__PURE__ */ jsx2(SourceIcon, { className: "h-4 w-4" }) }),
|
|
1495
|
+
/* @__PURE__ */ jsx2("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-2", children: [
|
|
1496
|
+
/* @__PURE__ */ jsx2("span", { className: "truncate text-sm font-semibold text-white/92", children: item.label }),
|
|
1497
|
+
/* @__PURE__ */ jsx2(
|
|
1498
|
+
"span",
|
|
1499
|
+
{
|
|
1500
|
+
"data-airjam-controller-source-badge": true,
|
|
1501
|
+
className: "rounded-full border border-white/12 bg-white/6 px-1.5 py-0.5 text-[9px] leading-none font-semibold tracking-[0.12em] text-white/70 uppercase",
|
|
1502
|
+
children: getControllerSourceLabel(item.source)
|
|
1503
|
+
}
|
|
1504
|
+
),
|
|
1505
|
+
/* @__PURE__ */ jsx2(
|
|
1506
|
+
"span",
|
|
1507
|
+
{
|
|
1508
|
+
className: cn(
|
|
1509
|
+
"h-1.5 w-1.5 rounded-full",
|
|
1510
|
+
item.session?.surfaceState === "failed" ? "bg-amber-300" : item.connected ? "bg-emerald-300" : "bg-white/45"
|
|
1511
|
+
),
|
|
1512
|
+
title: item.session?.minimized ? "Minimized" : item.session ? item.session.surfaceState === "ready" ? "Visible" : previewControllerWindowStateLabel[item.session.surfaceState] : item.connected ? "Connected" : "Disconnected"
|
|
1513
|
+
}
|
|
1514
|
+
),
|
|
1515
|
+
item.resumable ? /* @__PURE__ */ jsx2("span", { className: "rounded-full border border-white/10 bg-white/5 px-1.5 py-0.5 text-[9px] leading-none font-semibold tracking-[0.12em] text-white/55 uppercase", children: "Resume" }) : null
|
|
1516
|
+
] }) }),
|
|
1517
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-2", children: [
|
|
1518
|
+
previewSession?.minimized ? /* @__PURE__ */ jsx2(
|
|
1519
|
+
Button,
|
|
1520
|
+
{
|
|
1521
|
+
type: "button",
|
|
1522
|
+
variant: "outline",
|
|
1523
|
+
size: "sm",
|
|
1524
|
+
className: cn(
|
|
1525
|
+
"h-7 rounded-full px-3 text-[10px]",
|
|
1526
|
+
shellUtilityButtonClassName
|
|
1527
|
+
),
|
|
1528
|
+
onClick: () => restorePreviewController(previewSession.id),
|
|
1529
|
+
children: "Restore"
|
|
1530
|
+
}
|
|
1531
|
+
) : null,
|
|
1532
|
+
item.controller && onRemoveController ? /* @__PURE__ */ jsx2(
|
|
1533
|
+
Button,
|
|
1534
|
+
{
|
|
1535
|
+
type: "button",
|
|
1536
|
+
variant: "ghost",
|
|
1537
|
+
size: "sm",
|
|
1538
|
+
className: "h-7 rounded-full px-3 text-[10px] text-rose-200 hover:bg-rose-400/10 hover:text-rose-100 disabled:text-white/35",
|
|
1539
|
+
disabled: removingControllerId === item.controller.controllerId,
|
|
1540
|
+
onClick: async () => {
|
|
1541
|
+
if (!item.controller) {
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
try {
|
|
1545
|
+
setRemovingControllerId(
|
|
1546
|
+
item.controller.controllerId
|
|
1547
|
+
);
|
|
1548
|
+
await onRemoveController(
|
|
1549
|
+
item.controller.controllerId
|
|
1550
|
+
);
|
|
1551
|
+
} finally {
|
|
1552
|
+
setRemovingControllerId(
|
|
1553
|
+
(current) => current === item.controller?.controllerId ? null : current
|
|
1554
|
+
);
|
|
1555
|
+
}
|
|
1556
|
+
},
|
|
1557
|
+
children: "Kick"
|
|
1558
|
+
}
|
|
1559
|
+
) : null,
|
|
1560
|
+
previewSession ? /* @__PURE__ */ jsx2(
|
|
1561
|
+
Button,
|
|
1562
|
+
{
|
|
1563
|
+
type: "button",
|
|
1564
|
+
variant: "ghost",
|
|
1565
|
+
size: "icon-sm",
|
|
1566
|
+
className: "h-7 w-7 rounded-full text-white/68 hover:bg-white/8 hover:text-white",
|
|
1567
|
+
onClick: () => removePreviewController(previewSession.id),
|
|
1568
|
+
title: `Close ${item.label}`,
|
|
1569
|
+
children: /* @__PURE__ */ jsx2(X2, { className: "h-4 w-4" })
|
|
1570
|
+
}
|
|
1571
|
+
) : null
|
|
1572
|
+
] })
|
|
1573
|
+
]
|
|
1574
|
+
},
|
|
1575
|
+
item.id
|
|
1576
|
+
);
|
|
1577
|
+
}) }),
|
|
1578
|
+
/* @__PURE__ */ jsx2("div", { className: "h-px bg-white/10" })
|
|
1579
|
+
] }) : /* @__PURE__ */ jsx2("div", { className: cn("px-4 py-4", shellInsetPanelClassName), children: /* @__PURE__ */ jsx2("p", { className: "text-sm leading-6 text-white/58", children: "Open a controller preview here to test the host flow without using a phone." }) }),
|
|
1580
|
+
minimizedSessions.length > 0 ? /* @__PURE__ */ jsxs2("p", { className: "text-[11px] tracking-[0.14em] text-white/46 uppercase", children: [
|
|
1581
|
+
minimizedSessions.length,
|
|
1582
|
+
" minimized"
|
|
1583
|
+
] }) : null,
|
|
1584
|
+
/* @__PURE__ */ jsxs2(
|
|
1585
|
+
Button,
|
|
1586
|
+
{
|
|
1587
|
+
type: "button",
|
|
1588
|
+
variant: "outline",
|
|
1589
|
+
className: cn(
|
|
1590
|
+
"h-10 w-full rounded-2xl",
|
|
1591
|
+
shellUtilityButtonClassName
|
|
1592
|
+
),
|
|
1593
|
+
disabled: !canSpawn,
|
|
1594
|
+
onClick: () => {
|
|
1595
|
+
spawnPreviewController();
|
|
1596
|
+
},
|
|
1597
|
+
children: [
|
|
1598
|
+
/* @__PURE__ */ jsx2(Plus, { className: "h-4 w-4" }),
|
|
1599
|
+
!joinUrl ? waitingLabel : "Add controller"
|
|
1600
|
+
]
|
|
1601
|
+
}
|
|
1602
|
+
)
|
|
1603
|
+
] }) })
|
|
1604
|
+
}
|
|
1605
|
+
) : null
|
|
1606
|
+
]
|
|
1607
|
+
}
|
|
1608
|
+
)
|
|
1609
|
+
]
|
|
1610
|
+
}
|
|
1611
|
+
),
|
|
1612
|
+
document.body
|
|
1613
|
+
);
|
|
1614
|
+
};
|
|
1615
|
+
|
|
1616
|
+
// src/preview/host-workspace.tsx
|
|
1617
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
1618
|
+
var HostPreviewControllerWorkspace = ({
|
|
1619
|
+
enabled = "auto",
|
|
1620
|
+
className,
|
|
1621
|
+
...props
|
|
1622
|
+
}) => {
|
|
1623
|
+
const host = useAirJamHost();
|
|
1624
|
+
const config = useAirJamConfig();
|
|
1625
|
+
const platformSettingsOwner = useOptionalPlatformSettingsOwnerApi();
|
|
1626
|
+
const resolvedEnabled = resolveHostPreviewControllerWorkspaceEnabled({
|
|
1627
|
+
enabled,
|
|
1628
|
+
topology: config.topology
|
|
1629
|
+
});
|
|
1630
|
+
const joinUrl = host.joinUrlStatus === "ready" && host.joinUrl ? host.joinUrl : null;
|
|
1631
|
+
const handleResetRoom = async () => {
|
|
1632
|
+
const ack = await host.resetRoom();
|
|
1633
|
+
if (!ack.ok || typeof window === "undefined") {
|
|
1634
|
+
return ack;
|
|
1635
|
+
}
|
|
1636
|
+
window.location.reload();
|
|
1637
|
+
return ack;
|
|
1638
|
+
};
|
|
1639
|
+
return /* @__PURE__ */ jsx3(
|
|
1640
|
+
PreviewControllerWorkspace,
|
|
1641
|
+
{
|
|
1642
|
+
enabled: resolvedEnabled,
|
|
1643
|
+
joinUrl,
|
|
1644
|
+
controllers: host.controllers,
|
|
1645
|
+
onRemoveController: host.removeController,
|
|
1646
|
+
onResetRoom: handleResetRoom,
|
|
1647
|
+
onActiveOpacityChange: (activeOpacity) => platformSettingsOwner?.updatePreviewControllers({ activeOpacity }),
|
|
1648
|
+
className: cn("right-4 bottom-4 z-60 sm:right-6 sm:bottom-6", className),
|
|
1649
|
+
...props
|
|
1650
|
+
}
|
|
1651
|
+
);
|
|
1652
|
+
};
|
|
1653
|
+
export {
|
|
1654
|
+
AIR_JAM_PREVIEW_DEVICE_QUERY_PARAM,
|
|
1655
|
+
AIR_JAM_PREVIEW_FLAG_QUERY_PARAM,
|
|
1656
|
+
HostPreviewControllerWorkspace,
|
|
1657
|
+
PreviewControllerWindow,
|
|
1658
|
+
PreviewControllerWorkspace,
|
|
1659
|
+
buildPreviewControllerUrl,
|
|
1660
|
+
createPreviewControllerIdentity,
|
|
1661
|
+
createPreviewControllerLaunch,
|
|
1662
|
+
isEmbeddedArcadeRuntimeSearchParams,
|
|
1663
|
+
isPreviewControllerSearchParams,
|
|
1664
|
+
normalizePreviewDeviceId,
|
|
1665
|
+
previewControllerWindowStateLabel,
|
|
1666
|
+
readPreviewControllerDeviceIdFromLocation,
|
|
1667
|
+
readPreviewControllerDeviceIdFromSearchParams,
|
|
1668
|
+
resolveHostPreviewControllerWorkspaceEnabled,
|
|
1669
|
+
usePreviewControllerManager
|
|
1670
|
+
};
|
|
1671
|
+
//# sourceMappingURL=preview.js.map
|