@air-jam/sdk 0.1.3 → 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 +8512 -3518
- 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 +4892 -3188
- 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 +154 -13
- 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 -14
- 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 -141
- 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 -25
- 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 -521
- 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
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import type { CSSProperties, JSX, ReactNode } from "react";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { useSessionScope } from "../context/session-scope";
|
|
4
|
+
import { publishEmbeddedControllerPresentation } from "../runtime/controller-presentation";
|
|
5
|
+
import { cn } from "../utils/cn";
|
|
6
|
+
import {
|
|
7
|
+
createSurfaceViewportOuterStyle,
|
|
8
|
+
resolveForcedOrientationFrameStyle,
|
|
9
|
+
type SurfaceOrientation,
|
|
10
|
+
} from "./surface-orientation-layout";
|
|
11
|
+
import {
|
|
12
|
+
createSurfaceViewportScaleStyle,
|
|
13
|
+
resolveSurfaceViewportAvailableSize,
|
|
14
|
+
resolveSurfaceViewportReferenceSize,
|
|
15
|
+
resolveSurfaceViewportScale,
|
|
16
|
+
} from "./surface-viewport-layout";
|
|
17
|
+
|
|
18
|
+
type ScreenOrientationWithLock = ScreenOrientation & {
|
|
19
|
+
lock?: (orientation: SurfaceOrientation) => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
interface ViewportSize {
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const readLayoutViewportSize = (): ViewportSize => {
|
|
28
|
+
if (typeof window === "undefined") {
|
|
29
|
+
return { width: 0, height: 0 };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
width: window.innerWidth,
|
|
34
|
+
height: window.innerHeight,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const isTextEntryElement = (element: Element | null): boolean => {
|
|
39
|
+
if (!element) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (element instanceof HTMLTextAreaElement) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (element instanceof HTMLInputElement) {
|
|
48
|
+
return ![
|
|
49
|
+
"button",
|
|
50
|
+
"checkbox",
|
|
51
|
+
"color",
|
|
52
|
+
"file",
|
|
53
|
+
"hidden",
|
|
54
|
+
"image",
|
|
55
|
+
"radio",
|
|
56
|
+
"range",
|
|
57
|
+
"reset",
|
|
58
|
+
"submit",
|
|
59
|
+
].includes(element.type);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return element instanceof HTMLElement && element.isContentEditable;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const isKeyboardResize = (
|
|
66
|
+
previous: ViewportSize | null,
|
|
67
|
+
next: ViewportSize,
|
|
68
|
+
): boolean => {
|
|
69
|
+
if (!previous || typeof document === "undefined") {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!isTextEntryElement(document.activeElement)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const sameWidth = Math.abs(previous.width - next.width) <= 2;
|
|
78
|
+
const heightShrank = next.height < previous.height;
|
|
79
|
+
|
|
80
|
+
return sameWidth && heightShrank;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const getOrientation = ({
|
|
84
|
+
width,
|
|
85
|
+
height,
|
|
86
|
+
}: ViewportSize): SurfaceOrientation => {
|
|
87
|
+
if (typeof window !== "undefined") {
|
|
88
|
+
if (window.matchMedia) {
|
|
89
|
+
if (window.matchMedia("(orientation: portrait)").matches) {
|
|
90
|
+
return "portrait";
|
|
91
|
+
}
|
|
92
|
+
if (window.matchMedia("(orientation: landscape)").matches) {
|
|
93
|
+
return "landscape";
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (window.screen?.orientation?.type) {
|
|
98
|
+
if (window.screen.orientation.type.startsWith("portrait")) {
|
|
99
|
+
return "portrait";
|
|
100
|
+
}
|
|
101
|
+
if (window.screen.orientation.type.startsWith("landscape")) {
|
|
102
|
+
return "landscape";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (width > 0 && height > 0) {
|
|
108
|
+
return width >= height ? "landscape" : "portrait";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return width >= height ? "landscape" : "portrait";
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export interface SurfaceViewportProps {
|
|
115
|
+
children: ReactNode;
|
|
116
|
+
orientation?: SurfaceOrientation;
|
|
117
|
+
lockOnGesture?: boolean;
|
|
118
|
+
className?: string;
|
|
119
|
+
contentClassName?: string;
|
|
120
|
+
style?: CSSProperties;
|
|
121
|
+
designWidth?: number;
|
|
122
|
+
designHeight?: number;
|
|
123
|
+
uiScaleMultiplier?: number;
|
|
124
|
+
minScale?: number;
|
|
125
|
+
maxScale?: number;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export const SurfaceViewport = ({
|
|
129
|
+
children,
|
|
130
|
+
orientation,
|
|
131
|
+
lockOnGesture = true,
|
|
132
|
+
className,
|
|
133
|
+
contentClassName,
|
|
134
|
+
style,
|
|
135
|
+
designWidth,
|
|
136
|
+
designHeight,
|
|
137
|
+
uiScaleMultiplier,
|
|
138
|
+
minScale,
|
|
139
|
+
maxScale,
|
|
140
|
+
}: SurfaceViewportProps): JSX.Element => {
|
|
141
|
+
const [viewport, setViewport] = useState<ViewportSize | null>(null);
|
|
142
|
+
const viewportRef = useRef<ViewportSize | null>(null);
|
|
143
|
+
const sessionScope = useSessionScope();
|
|
144
|
+
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (typeof window === "undefined") {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const updateViewport = () => {
|
|
151
|
+
const nextViewport = readLayoutViewportSize();
|
|
152
|
+
if (isKeyboardResize(viewportRef.current, nextViewport)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
viewportRef.current = nextViewport;
|
|
157
|
+
setViewport(nextViewport);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
updateViewport();
|
|
161
|
+
window.addEventListener("resize", updateViewport);
|
|
162
|
+
window.visualViewport?.addEventListener("resize", updateViewport);
|
|
163
|
+
window.addEventListener("orientationchange", updateViewport);
|
|
164
|
+
|
|
165
|
+
return () => {
|
|
166
|
+
window.removeEventListener("resize", updateViewport);
|
|
167
|
+
window.visualViewport?.removeEventListener("resize", updateViewport);
|
|
168
|
+
window.removeEventListener("orientationchange", updateViewport);
|
|
169
|
+
};
|
|
170
|
+
}, []);
|
|
171
|
+
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (typeof window === "undefined" || !orientation || !lockOnGesture) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const tryLock = () => {
|
|
178
|
+
if (!("orientation" in screen)) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const screenOrientation = screen.orientation as ScreenOrientationWithLock;
|
|
183
|
+
if (!screenOrientation?.lock) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
void screenOrientation.lock(orientation).catch(() => {
|
|
188
|
+
// Best-effort only. Some browsers reject lock outside fullscreen.
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const onFirstGesture = () => {
|
|
193
|
+
tryLock();
|
|
194
|
+
window.removeEventListener("pointerdown", onFirstGesture, true);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
window.addEventListener("pointerdown", onFirstGesture, true);
|
|
198
|
+
|
|
199
|
+
return () => {
|
|
200
|
+
window.removeEventListener("pointerdown", onFirstGesture, true);
|
|
201
|
+
};
|
|
202
|
+
}, [orientation, lockOnGesture]);
|
|
203
|
+
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
if (!orientation || sessionScope !== "controller") {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
publishEmbeddedControllerPresentation(orientation);
|
|
210
|
+
}, [orientation, sessionScope]);
|
|
211
|
+
|
|
212
|
+
const currentOrientation = viewport ? getOrientation(viewport) : "portrait";
|
|
213
|
+
const effectiveOrientation = orientation ?? currentOrientation;
|
|
214
|
+
const needsRotation = orientation
|
|
215
|
+
? currentOrientation !== orientation
|
|
216
|
+
: false;
|
|
217
|
+
|
|
218
|
+
const shellStyle = useMemo<CSSProperties>(
|
|
219
|
+
() =>
|
|
220
|
+
orientation
|
|
221
|
+
? resolveForcedOrientationFrameStyle(orientation, needsRotation)
|
|
222
|
+
: resolveForcedOrientationFrameStyle(effectiveOrientation, false),
|
|
223
|
+
[effectiveOrientation, needsRotation, orientation],
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const availableSize = useMemo(
|
|
227
|
+
() =>
|
|
228
|
+
resolveSurfaceViewportAvailableSize({
|
|
229
|
+
safeViewportWidth: viewport?.width ?? 0,
|
|
230
|
+
safeViewportHeight: viewport?.height ?? 0,
|
|
231
|
+
orientation,
|
|
232
|
+
needsRotation,
|
|
233
|
+
}),
|
|
234
|
+
[needsRotation, orientation, viewport],
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const referenceSize = useMemo(
|
|
238
|
+
() =>
|
|
239
|
+
resolveSurfaceViewportReferenceSize({
|
|
240
|
+
sessionScope,
|
|
241
|
+
designWidth,
|
|
242
|
+
designHeight,
|
|
243
|
+
orientation: effectiveOrientation,
|
|
244
|
+
availableWidth: availableSize.width,
|
|
245
|
+
availableHeight: availableSize.height,
|
|
246
|
+
}),
|
|
247
|
+
[
|
|
248
|
+
availableSize.height,
|
|
249
|
+
availableSize.width,
|
|
250
|
+
designHeight,
|
|
251
|
+
designWidth,
|
|
252
|
+
effectiveOrientation,
|
|
253
|
+
sessionScope,
|
|
254
|
+
],
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
const scale = useMemo(() => {
|
|
258
|
+
const scaleMode =
|
|
259
|
+
sessionScope === "controller"
|
|
260
|
+
? effectiveOrientation === "portrait"
|
|
261
|
+
? "width"
|
|
262
|
+
: "height"
|
|
263
|
+
: "fit";
|
|
264
|
+
|
|
265
|
+
return resolveSurfaceViewportScale({
|
|
266
|
+
availableWidth: availableSize.width,
|
|
267
|
+
availableHeight: availableSize.height,
|
|
268
|
+
referenceWidth: referenceSize.width,
|
|
269
|
+
referenceHeight: referenceSize.height,
|
|
270
|
+
scaleMode,
|
|
271
|
+
uiScaleMultiplier,
|
|
272
|
+
minScale,
|
|
273
|
+
maxScale,
|
|
274
|
+
});
|
|
275
|
+
}, [
|
|
276
|
+
availableSize.height,
|
|
277
|
+
availableSize.width,
|
|
278
|
+
effectiveOrientation,
|
|
279
|
+
maxScale,
|
|
280
|
+
minScale,
|
|
281
|
+
referenceSize.height,
|
|
282
|
+
referenceSize.width,
|
|
283
|
+
sessionScope,
|
|
284
|
+
uiScaleMultiplier,
|
|
285
|
+
]);
|
|
286
|
+
|
|
287
|
+
return (
|
|
288
|
+
<div
|
|
289
|
+
className={cn("fixed inset-0 overflow-hidden", className)}
|
|
290
|
+
style={{
|
|
291
|
+
...createSurfaceViewportOuterStyle(),
|
|
292
|
+
...style,
|
|
293
|
+
}}
|
|
294
|
+
>
|
|
295
|
+
<div style={shellStyle}>
|
|
296
|
+
<div
|
|
297
|
+
className={cn("h-full w-full overflow-hidden", contentClassName)}
|
|
298
|
+
data-airjam-surface-viewport="true"
|
|
299
|
+
style={createSurfaceViewportScaleStyle({
|
|
300
|
+
scale,
|
|
301
|
+
referenceWidth: referenceSize.width,
|
|
302
|
+
referenceHeight: referenceSize.height,
|
|
303
|
+
})}
|
|
304
|
+
>
|
|
305
|
+
<div className="h-full w-full" data-airjam-surface-root="true">
|
|
306
|
+
{children}
|
|
307
|
+
</div>
|
|
308
|
+
</div>
|
|
309
|
+
</div>
|
|
310
|
+
</div>
|
|
311
|
+
);
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
export type { SurfaceOrientation };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable react-refresh/only-export-components */
|
|
2
1
|
import { Slot } from "@radix-ui/react-slot";
|
|
3
2
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
4
3
|
import * as React from "react";
|
|
@@ -6,19 +5,18 @@ import * as React from "react";
|
|
|
6
5
|
import { cn } from "../../utils/cn";
|
|
7
6
|
|
|
8
7
|
const buttonVariants = cva(
|
|
9
|
-
"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
|
|
8
|
+
"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",
|
|
10
9
|
{
|
|
11
10
|
variants: {
|
|
12
11
|
variant: {
|
|
13
12
|
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
14
13
|
destructive:
|
|
15
|
-
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20
|
|
14
|
+
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20",
|
|
16
15
|
outline:
|
|
17
|
-
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground
|
|
16
|
+
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground",
|
|
18
17
|
secondary:
|
|
19
18
|
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
20
|
-
ghost:
|
|
21
|
-
"text-foreground hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
19
|
+
ghost: "text-foreground hover:bg-accent hover:text-accent-foreground",
|
|
22
20
|
link: "text-primary underline-offset-4 hover:underline",
|
|
23
21
|
},
|
|
24
22
|
size: {
|
|
@@ -51,7 +51,7 @@ function Slider({
|
|
|
51
51
|
<SliderPrimitive.Thumb
|
|
52
52
|
data-slot="slider-thumb"
|
|
53
53
|
key={index}
|
|
54
|
-
className="border-primary ring-ring/50 block size-
|
|
54
|
+
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"
|
|
55
55
|
/>
|
|
56
56
|
))}
|
|
57
57
|
</SliderPrimitive.Root>
|
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
import { Headphones, Music, Volume2 } from "lucide-react";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
usePlatformAudioSettings,
|
|
4
|
+
type PlatformAudioSettingsApi,
|
|
5
|
+
} from "../settings/platform-settings-runtime";
|
|
3
6
|
import { cn } from "../utils/cn";
|
|
4
7
|
import { Slider } from "./ui/slider";
|
|
5
8
|
|
|
6
9
|
interface VolumeControlsProps {
|
|
7
10
|
className?: string;
|
|
8
11
|
compact?: boolean;
|
|
12
|
+
values?: Pick<
|
|
13
|
+
PlatformAudioSettingsApi,
|
|
14
|
+
"masterVolume" | "musicVolume" | "sfxVolume"
|
|
15
|
+
>;
|
|
16
|
+
readOnly?: boolean;
|
|
17
|
+
onMasterVolumeChange?: (volume: number) => void;
|
|
18
|
+
onMusicVolumeChange?: (volume: number) => void;
|
|
19
|
+
onSfxVolumeChange?: (volume: number) => void;
|
|
9
20
|
}
|
|
10
21
|
|
|
11
|
-
export function VolumeControls(
|
|
22
|
+
export function VolumeControls(props: VolumeControlsProps) {
|
|
23
|
+
if (props.values) {
|
|
24
|
+
return <ControlledVolumeControls {...props} />;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return <OwnedVolumeControls {...props} />;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function OwnedVolumeControls({ className, compact }: VolumeControlsProps) {
|
|
12
31
|
const {
|
|
13
32
|
masterVolume,
|
|
14
33
|
musicVolume,
|
|
@@ -16,7 +35,35 @@ export function VolumeControls({ className, compact }: VolumeControlsProps) {
|
|
|
16
35
|
setMasterVolume,
|
|
17
36
|
setMusicVolume,
|
|
18
37
|
setSfxVolume,
|
|
19
|
-
} =
|
|
38
|
+
} = usePlatformAudioSettings();
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<ControlledVolumeControls
|
|
42
|
+
className={className}
|
|
43
|
+
compact={compact}
|
|
44
|
+
values={{ masterVolume, musicVolume, sfxVolume }}
|
|
45
|
+
onMasterVolumeChange={setMasterVolume}
|
|
46
|
+
onMusicVolumeChange={setMusicVolume}
|
|
47
|
+
onSfxVolumeChange={setSfxVolume}
|
|
48
|
+
readOnly={false}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function ControlledVolumeControls({
|
|
54
|
+
className,
|
|
55
|
+
compact,
|
|
56
|
+
values,
|
|
57
|
+
readOnly = false,
|
|
58
|
+
onMasterVolumeChange,
|
|
59
|
+
onMusicVolumeChange,
|
|
60
|
+
onSfxVolumeChange,
|
|
61
|
+
}: VolumeControlsProps) {
|
|
62
|
+
if (!values) {
|
|
63
|
+
throw new Error("ControlledVolumeControls requires values");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const { masterVolume, musicVolume, sfxVolume } = values;
|
|
20
67
|
|
|
21
68
|
return (
|
|
22
69
|
<div className={cn("flex flex-col gap-3", compact && "gap-1", className)}>
|
|
@@ -35,13 +82,17 @@ export function VolumeControls({ className, compact }: VolumeControlsProps) {
|
|
|
35
82
|
</span>
|
|
36
83
|
</div>
|
|
37
84
|
<Slider
|
|
85
|
+
data-testid="platform-settings-master-volume"
|
|
38
86
|
value={[masterVolume * 100]}
|
|
39
|
-
onValueChange={(
|
|
87
|
+
onValueChange={(sliderValues) =>
|
|
88
|
+
onMasterVolumeChange?.(sliderValues[0] / 100)
|
|
89
|
+
}
|
|
40
90
|
min={0}
|
|
41
91
|
max={100}
|
|
42
92
|
step={1}
|
|
43
93
|
className="w-full"
|
|
44
94
|
aria-label="Master volume"
|
|
95
|
+
disabled={readOnly}
|
|
45
96
|
/>
|
|
46
97
|
</div>
|
|
47
98
|
|
|
@@ -57,13 +108,17 @@ export function VolumeControls({ className, compact }: VolumeControlsProps) {
|
|
|
57
108
|
</span>
|
|
58
109
|
</div>
|
|
59
110
|
<Slider
|
|
111
|
+
data-testid="platform-settings-music-volume"
|
|
60
112
|
value={[musicVolume * 100]}
|
|
61
|
-
onValueChange={(
|
|
113
|
+
onValueChange={(sliderValues) =>
|
|
114
|
+
onMusicVolumeChange?.(sliderValues[0] / 100)
|
|
115
|
+
}
|
|
62
116
|
min={0}
|
|
63
117
|
max={100}
|
|
64
118
|
step={1}
|
|
65
119
|
className="w-full"
|
|
66
120
|
aria-label="Music volume"
|
|
121
|
+
disabled={readOnly}
|
|
67
122
|
/>
|
|
68
123
|
</div>
|
|
69
124
|
|
|
@@ -79,13 +134,17 @@ export function VolumeControls({ className, compact }: VolumeControlsProps) {
|
|
|
79
134
|
</span>
|
|
80
135
|
</div>
|
|
81
136
|
<Slider
|
|
137
|
+
data-testid="platform-settings-sfx-volume"
|
|
82
138
|
value={[sfxVolume * 100]}
|
|
83
|
-
onValueChange={(
|
|
139
|
+
onValueChange={(sliderValues) =>
|
|
140
|
+
onSfxVolumeChange?.(sliderValues[0] / 100)
|
|
141
|
+
}
|
|
84
142
|
min={0}
|
|
85
143
|
max={100}
|
|
86
144
|
step={1}
|
|
87
145
|
className="w-full"
|
|
88
146
|
aria-label="SFX volume"
|
|
147
|
+
disabled={readOnly}
|
|
89
148
|
/>
|
|
90
149
|
</div>
|
|
91
150
|
</div>
|