@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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { JSX } from "react";
|
|
2
|
+
import type { PlayerProfile } from "../protocol";
|
|
3
|
+
import { cn } from "../utils/cn";
|
|
4
|
+
import { PlayerAvatar } from "./player-avatar";
|
|
5
|
+
|
|
6
|
+
interface PlayerAvatarStripProps {
|
|
7
|
+
players: PlayerProfile[];
|
|
8
|
+
/** Avatars shown before a +N badge (default 4). */
|
|
9
|
+
maxVisible?: number;
|
|
10
|
+
size?: "sm" | "md" | "lg";
|
|
11
|
+
className?: string;
|
|
12
|
+
/** Extra classes on each `PlayerAvatar` (e.g. `ring-2 ring-black/90` on dark headers). */
|
|
13
|
+
avatarClassName?: string;
|
|
14
|
+
/** Extra classes on the +N overflow badge when present. */
|
|
15
|
+
overflowBadgeClassName?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const overflowSizeClasses: Record<
|
|
19
|
+
NonNullable<PlayerAvatarStripProps["size"]>,
|
|
20
|
+
string
|
|
21
|
+
> = {
|
|
22
|
+
sm: "h-9 w-9 min-h-9 min-w-9 text-[0.625rem]",
|
|
23
|
+
md: "h-12 w-12 min-h-12 min-w-12 text-[11px]",
|
|
24
|
+
lg: "h-16 w-16 min-h-16 min-w-16 text-xs",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Overlapping row of {@link PlayerAvatar} images, with an optional +N overflow badge.
|
|
29
|
+
*/
|
|
30
|
+
export const PlayerAvatarStrip = ({
|
|
31
|
+
players,
|
|
32
|
+
maxVisible = 4,
|
|
33
|
+
size = "sm",
|
|
34
|
+
className,
|
|
35
|
+
avatarClassName = "",
|
|
36
|
+
overflowBadgeClassName = "",
|
|
37
|
+
}: PlayerAvatarStripProps): JSX.Element => {
|
|
38
|
+
const visible = players.slice(0, maxVisible);
|
|
39
|
+
const overflow = Math.max(0, players.length - maxVisible);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div className={cn("flex items-center -space-x-2", className)}>
|
|
43
|
+
{visible.map((player) => (
|
|
44
|
+
<PlayerAvatar
|
|
45
|
+
key={player.id}
|
|
46
|
+
player={player}
|
|
47
|
+
size={size}
|
|
48
|
+
className={avatarClassName}
|
|
49
|
+
/>
|
|
50
|
+
))}
|
|
51
|
+
{overflow > 0 && (
|
|
52
|
+
<div
|
|
53
|
+
className={cn(
|
|
54
|
+
"bg-secondary/50 text-foreground flex shrink-0 items-center justify-center rounded-full border-2 border-[hsl(var(--border))] font-semibold tabular-nums shadow-sm",
|
|
55
|
+
overflowSizeClasses[size],
|
|
56
|
+
overflowBadgeClassName,
|
|
57
|
+
)}
|
|
58
|
+
aria-label={`${overflow} more players`}
|
|
59
|
+
>
|
|
60
|
+
+{overflow}
|
|
61
|
+
</div>
|
|
62
|
+
)}
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
+
import { Bot } from "lucide-react";
|
|
1
2
|
import type { JSX } from "react";
|
|
2
3
|
import type { PlayerProfile } from "../protocol";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const getPlayerAvatarUrl = (playerId: string): string => {
|
|
6
|
-
// Use DiceBear API with identicon style for GitHub-like avatars
|
|
7
|
-
// The seed ensures the same player ID always gets the same avatar
|
|
8
|
-
return `https://api.dicebear.com/9.x/adventurer-neutral/svg?seed=${encodeURIComponent(
|
|
9
|
-
playerId,
|
|
10
|
-
)}`;
|
|
11
|
-
};
|
|
4
|
+
import { cn } from "../utils/cn";
|
|
5
|
+
import { getPlayerAvatarImageUrl } from "../utils/player-avatar-url";
|
|
12
6
|
|
|
13
7
|
// Convert hex color to rgba with opacity
|
|
14
8
|
const hexToRgba = (hex: string, opacity: number): string => {
|
|
@@ -22,17 +16,20 @@ const hexToRgba = (hex: string, opacity: number): string => {
|
|
|
22
16
|
|
|
23
17
|
interface PlayerAvatarProps {
|
|
24
18
|
player: PlayerProfile;
|
|
19
|
+
isBot?: boolean;
|
|
25
20
|
size?: "sm" | "md" | "lg";
|
|
26
21
|
className?: string;
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
export const PlayerAvatar = ({
|
|
30
25
|
player,
|
|
26
|
+
isBot = false,
|
|
31
27
|
size = "md",
|
|
32
28
|
className = "",
|
|
33
29
|
}: PlayerAvatarProps): JSX.Element => {
|
|
30
|
+
const accentColor = player.color || "hsl(var(--border))";
|
|
34
31
|
const sizeClasses = {
|
|
35
|
-
sm: "h-
|
|
32
|
+
sm: "h-9 w-9 border-2",
|
|
36
33
|
md: "h-12 w-12 border-4",
|
|
37
34
|
lg: "h-16 w-16 border-4",
|
|
38
35
|
};
|
|
@@ -49,13 +46,45 @@ export const PlayerAvatar = ({
|
|
|
49
46
|
: "inset 0 0 12px rgba(0, 0, 0, 0.4), 0 0 24px hsl(var(--border) / 0.5)",
|
|
50
47
|
};
|
|
51
48
|
|
|
49
|
+
const iconSizeClasses = {
|
|
50
|
+
sm: "h-4 w-4",
|
|
51
|
+
md: "h-5 w-5",
|
|
52
|
+
lg: "h-6 w-6",
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const shellClassName = cn(
|
|
56
|
+
"shrink-0 rounded-full shadow-lg",
|
|
57
|
+
sizeClasses[size],
|
|
58
|
+
className,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
if (isBot) {
|
|
62
|
+
return (
|
|
63
|
+
<div
|
|
64
|
+
role="img"
|
|
65
|
+
aria-label={player.label}
|
|
66
|
+
className={cn(
|
|
67
|
+
"bg-secondary/40 flex items-center justify-center",
|
|
68
|
+
shellClassName,
|
|
69
|
+
)}
|
|
70
|
+
style={{
|
|
71
|
+
borderColor: accentColor,
|
|
72
|
+
color: accentColor,
|
|
73
|
+
boxShadow: shadowStyles[size],
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
76
|
+
<Bot aria-hidden="true" className={iconSizeClasses[size]} />
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
52
81
|
return (
|
|
53
82
|
<img
|
|
54
|
-
src={
|
|
83
|
+
src={getPlayerAvatarImageUrl(player)}
|
|
55
84
|
alt={player.label}
|
|
56
|
-
className={
|
|
85
|
+
className={cn("bg-secondary/30", shellClassName)}
|
|
57
86
|
style={{
|
|
58
|
-
borderColor:
|
|
87
|
+
borderColor: accentColor,
|
|
59
88
|
boxShadow: shadowStyles[size],
|
|
60
89
|
}}
|
|
61
90
|
/>
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { toDataURL } from "qrcode";
|
|
2
|
+
import { useEffect, useState, type CSSProperties, type JSX } from "react";
|
|
3
|
+
|
|
4
|
+
export interface RoomQrCodeProps {
|
|
5
|
+
value: string;
|
|
6
|
+
size?: number;
|
|
7
|
+
padding?: number;
|
|
8
|
+
foregroundColor?: string;
|
|
9
|
+
backgroundColor?: string;
|
|
10
|
+
errorCorrectionLevel?: "L" | "M" | "Q" | "H";
|
|
11
|
+
className?: string;
|
|
12
|
+
style?: CSSProperties;
|
|
13
|
+
alt?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const RoomQrCode = ({
|
|
17
|
+
value,
|
|
18
|
+
size = 180,
|
|
19
|
+
padding = 1,
|
|
20
|
+
foregroundColor = "#111111",
|
|
21
|
+
backgroundColor = "#ffffff",
|
|
22
|
+
errorCorrectionLevel = "M",
|
|
23
|
+
className = "",
|
|
24
|
+
style,
|
|
25
|
+
alt = "Room join QR code",
|
|
26
|
+
}: RoomQrCodeProps): JSX.Element => {
|
|
27
|
+
const trimmed = value.trim();
|
|
28
|
+
const qrKey = `${trimmed}\0${size}\0${padding}\0${foregroundColor}\0${backgroundColor}\0${errorCorrectionLevel}`;
|
|
29
|
+
const [qrState, setQrState] = useState<{
|
|
30
|
+
key: string | null;
|
|
31
|
+
dataUrl: string | null;
|
|
32
|
+
error: boolean;
|
|
33
|
+
}>({
|
|
34
|
+
key: null,
|
|
35
|
+
dataUrl: null,
|
|
36
|
+
error: false,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!trimmed) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let cancelled = false;
|
|
45
|
+
|
|
46
|
+
void toDataURL(trimmed, {
|
|
47
|
+
width: size,
|
|
48
|
+
margin: padding,
|
|
49
|
+
errorCorrectionLevel,
|
|
50
|
+
color: {
|
|
51
|
+
dark: foregroundColor,
|
|
52
|
+
light: backgroundColor,
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
.then((nextUrl: string) => {
|
|
56
|
+
if (!cancelled) {
|
|
57
|
+
setQrState({
|
|
58
|
+
key: qrKey,
|
|
59
|
+
dataUrl: nextUrl,
|
|
60
|
+
error: false,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
.catch(() => {
|
|
65
|
+
if (!cancelled) {
|
|
66
|
+
setQrState({
|
|
67
|
+
key: qrKey,
|
|
68
|
+
dataUrl: null,
|
|
69
|
+
error: true,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return () => {
|
|
75
|
+
cancelled = true;
|
|
76
|
+
};
|
|
77
|
+
}, [
|
|
78
|
+
backgroundColor,
|
|
79
|
+
errorCorrectionLevel,
|
|
80
|
+
foregroundColor,
|
|
81
|
+
padding,
|
|
82
|
+
size,
|
|
83
|
+
qrKey,
|
|
84
|
+
trimmed,
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
const imageSrc =
|
|
88
|
+
trimmed && qrState.key === qrKey && qrState.dataUrl
|
|
89
|
+
? qrState.dataUrl
|
|
90
|
+
: null;
|
|
91
|
+
const isLoading = !!trimmed && qrState.key !== qrKey;
|
|
92
|
+
const isUnavailable = !trimmed || (qrState.key === qrKey && qrState.error);
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<div
|
|
96
|
+
className={className}
|
|
97
|
+
style={{
|
|
98
|
+
width: size,
|
|
99
|
+
height: size,
|
|
100
|
+
...style,
|
|
101
|
+
}}
|
|
102
|
+
aria-live="polite"
|
|
103
|
+
aria-label={alt}
|
|
104
|
+
>
|
|
105
|
+
{imageSrc ? (
|
|
106
|
+
<img
|
|
107
|
+
src={imageSrc}
|
|
108
|
+
alt={alt}
|
|
109
|
+
width={size}
|
|
110
|
+
height={size}
|
|
111
|
+
className="h-full w-full rounded-md object-cover"
|
|
112
|
+
/>
|
|
113
|
+
) : isLoading ? (
|
|
114
|
+
<div className="flex h-full w-full flex-col items-center justify-center gap-2 rounded-md bg-black/15 text-xs text-white/70">
|
|
115
|
+
<span className="h-5 w-5 animate-spin rounded-full border-2 border-white/20 border-t-white/80" />
|
|
116
|
+
<span>Generating QR…</span>
|
|
117
|
+
</div>
|
|
118
|
+
) : (
|
|
119
|
+
<div className="flex h-full w-full items-center justify-center rounded-md bg-black/15 text-xs text-white/70">
|
|
120
|
+
{isUnavailable ? "QR unavailable" : "Generating QR…"}
|
|
121
|
+
</div>
|
|
122
|
+
)}
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { JSX, ReactNode } from "react";
|
|
2
|
+
import type { ConnectionStatus } from "../protocol";
|
|
3
|
+
import { cn } from "../utils/cn";
|
|
4
|
+
import { ConnectionStatusPill } from "./connection-status-pill";
|
|
5
|
+
import { shellHeaderClassName } from "./shell-classes";
|
|
6
|
+
|
|
7
|
+
export interface RuntimeShellHeaderProps {
|
|
8
|
+
connectionStatus: ConnectionStatus;
|
|
9
|
+
leftSlot: ReactNode;
|
|
10
|
+
rightSlot?: ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const RuntimeShellHeader = ({
|
|
15
|
+
connectionStatus,
|
|
16
|
+
leftSlot,
|
|
17
|
+
rightSlot,
|
|
18
|
+
className,
|
|
19
|
+
}: RuntimeShellHeaderProps): JSX.Element => {
|
|
20
|
+
return (
|
|
21
|
+
<header
|
|
22
|
+
className={cn(
|
|
23
|
+
"flex min-h-16 items-center gap-2.5 px-3 py-2.5 sm:px-4",
|
|
24
|
+
shellHeaderClassName,
|
|
25
|
+
className,
|
|
26
|
+
)}
|
|
27
|
+
>
|
|
28
|
+
<div className="min-w-0 flex-1">{leftSlot}</div>
|
|
29
|
+
<div className="flex shrink-0 items-center gap-2.5">
|
|
30
|
+
<ConnectionStatusPill status={connectionStatus} />
|
|
31
|
+
{rightSlot ? (
|
|
32
|
+
<div className="flex items-center justify-end">{rightSlot}</div>
|
|
33
|
+
) : null}
|
|
34
|
+
</div>
|
|
35
|
+
</header>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const shellHeaderClassName =
|
|
2
|
+
"border-b border-white/10 bg-black/28 backdrop-blur-sm";
|
|
3
|
+
|
|
4
|
+
export const shellLabelClassName =
|
|
5
|
+
"text-[0.6875rem] font-semibold tracking-[0.22em] text-white/52 uppercase";
|
|
6
|
+
|
|
7
|
+
export const shellHelperTextClassName = "text-sm leading-5 text-white/52";
|
|
8
|
+
|
|
9
|
+
export const shellFieldClassName =
|
|
10
|
+
"h-11 min-w-0 w-full rounded-2xl border border-white/10 bg-black/40 px-3.5 text-sm text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.03)] outline-none placeholder:text-white/35";
|
|
11
|
+
|
|
12
|
+
export const shellUtilityButtonClassName =
|
|
13
|
+
"rounded-2xl border-white/12 bg-white/[0.045] text-white/88 shadow-[inset_0_1px_0_rgba(255,255,255,0.03)] hover:bg-white/[0.085] hover:text-white disabled:border-white/8 disabled:bg-white/[0.03] disabled:text-white/35";
|
|
14
|
+
|
|
15
|
+
export const shellPanelClassName =
|
|
16
|
+
"rounded-[0.5rem] border border-white/10 bg-zinc-950/82 text-white shadow-[0_22px_70px_rgba(0,0,0,0.42)] backdrop-blur-md";
|
|
17
|
+
|
|
18
|
+
export const shellInsetPanelClassName =
|
|
19
|
+
"rounded-[1.25rem] border border-white/10 bg-white/[0.04] shadow-[inset_0_1px_0_rgba(255,255,255,0.03)]";
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
|
|
3
|
+
export type SurfaceOrientation = "portrait" | "landscape";
|
|
4
|
+
|
|
5
|
+
export const AIRJAM_SAFE_AREA_TOP = "env(safe-area-inset-top, 0px)";
|
|
6
|
+
export const AIRJAM_SAFE_AREA_RIGHT = "env(safe-area-inset-right, 0px)";
|
|
7
|
+
export const AIRJAM_SAFE_AREA_BOTTOM = "env(safe-area-inset-bottom, 0px)";
|
|
8
|
+
export const AIRJAM_SAFE_AREA_LEFT = "env(safe-area-inset-left, 0px)";
|
|
9
|
+
export const AIRJAM_SAFE_VIEWPORT_WIDTH = `calc(100dvw - ${AIRJAM_SAFE_AREA_LEFT} - ${AIRJAM_SAFE_AREA_RIGHT})`;
|
|
10
|
+
export const AIRJAM_SAFE_VIEWPORT_HEIGHT = `calc(100dvh - ${AIRJAM_SAFE_AREA_TOP} - ${AIRJAM_SAFE_AREA_BOTTOM})`;
|
|
11
|
+
|
|
12
|
+
export const createSurfaceViewportOuterStyle = (): CSSProperties =>
|
|
13
|
+
({
|
|
14
|
+
["--airjam-safe-area-top" as const]: AIRJAM_SAFE_AREA_TOP,
|
|
15
|
+
["--airjam-safe-area-right" as const]: AIRJAM_SAFE_AREA_RIGHT,
|
|
16
|
+
["--airjam-safe-area-bottom" as const]: AIRJAM_SAFE_AREA_BOTTOM,
|
|
17
|
+
["--airjam-safe-area-left" as const]: AIRJAM_SAFE_AREA_LEFT,
|
|
18
|
+
["--airjam-safe-viewport-width" as const]: AIRJAM_SAFE_VIEWPORT_WIDTH,
|
|
19
|
+
["--airjam-safe-viewport-height" as const]: AIRJAM_SAFE_VIEWPORT_HEIGHT,
|
|
20
|
+
}) as CSSProperties;
|
|
21
|
+
|
|
22
|
+
export const resolveForcedOrientationFrameStyle = (
|
|
23
|
+
desired: SurfaceOrientation,
|
|
24
|
+
needsRotation: boolean,
|
|
25
|
+
): CSSProperties => {
|
|
26
|
+
if (!needsRotation) {
|
|
27
|
+
return {
|
|
28
|
+
position: "absolute",
|
|
29
|
+
top: AIRJAM_SAFE_AREA_TOP,
|
|
30
|
+
left: AIRJAM_SAFE_AREA_LEFT,
|
|
31
|
+
width: AIRJAM_SAFE_VIEWPORT_WIDTH,
|
|
32
|
+
height: AIRJAM_SAFE_VIEWPORT_HEIGHT,
|
|
33
|
+
overflow: "hidden",
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (desired === "landscape") {
|
|
38
|
+
return {
|
|
39
|
+
position: "absolute",
|
|
40
|
+
top: AIRJAM_SAFE_AREA_TOP,
|
|
41
|
+
left: AIRJAM_SAFE_AREA_LEFT,
|
|
42
|
+
width: AIRJAM_SAFE_VIEWPORT_HEIGHT,
|
|
43
|
+
height: AIRJAM_SAFE_VIEWPORT_WIDTH,
|
|
44
|
+
overflow: "hidden",
|
|
45
|
+
transformOrigin: "top left",
|
|
46
|
+
transform: `translateX(${AIRJAM_SAFE_VIEWPORT_WIDTH}) rotate(90deg)`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
position: "absolute",
|
|
52
|
+
top: AIRJAM_SAFE_AREA_TOP,
|
|
53
|
+
left: AIRJAM_SAFE_AREA_LEFT,
|
|
54
|
+
width: AIRJAM_SAFE_VIEWPORT_HEIGHT,
|
|
55
|
+
height: AIRJAM_SAFE_VIEWPORT_WIDTH,
|
|
56
|
+
overflow: "hidden",
|
|
57
|
+
transformOrigin: "top left",
|
|
58
|
+
transform: `translateY(${AIRJAM_SAFE_VIEWPORT_HEIGHT}) rotate(-90deg)`,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
import type { SessionScope } from "../context/session-scope";
|
|
3
|
+
import type { SurfaceOrientation } from "./surface-orientation-layout";
|
|
4
|
+
|
|
5
|
+
interface SurfaceViewportReferenceDimensions {
|
|
6
|
+
portrait: {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
|
10
|
+
landscape: {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const CONTROLLER_REFERENCE_SIZE: SurfaceViewportReferenceDimensions = {
|
|
17
|
+
portrait: {
|
|
18
|
+
width: 412,
|
|
19
|
+
height: 915,
|
|
20
|
+
},
|
|
21
|
+
landscape: {
|
|
22
|
+
width: 915,
|
|
23
|
+
height: 412,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const HOST_REFERENCE_SIZE: SurfaceViewportReferenceDimensions = {
|
|
28
|
+
portrait: {
|
|
29
|
+
width: 900,
|
|
30
|
+
height: 1600,
|
|
31
|
+
},
|
|
32
|
+
landscape: {
|
|
33
|
+
width: 1600,
|
|
34
|
+
height: 900,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const resolveSurfaceViewportScopeReferenceSize = (
|
|
39
|
+
sessionScope: SessionScope,
|
|
40
|
+
): SurfaceViewportReferenceDimensions | null => {
|
|
41
|
+
if (sessionScope === "controller") {
|
|
42
|
+
return CONTROLLER_REFERENCE_SIZE;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (sessionScope === "host") {
|
|
46
|
+
return HOST_REFERENCE_SIZE;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const SURFACE_VIEWPORT_REFERENCE_SIZES = {
|
|
53
|
+
controller: CONTROLLER_REFERENCE_SIZE,
|
|
54
|
+
host: HOST_REFERENCE_SIZE,
|
|
55
|
+
} as const;
|
|
56
|
+
|
|
57
|
+
interface ResolveSurfaceViewportReferenceSizeOptions {
|
|
58
|
+
sessionScope: SessionScope;
|
|
59
|
+
designWidth?: number;
|
|
60
|
+
designHeight?: number;
|
|
61
|
+
orientation: SurfaceOrientation;
|
|
62
|
+
availableWidth: number;
|
|
63
|
+
availableHeight: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const resolveSurfaceViewportReferenceSize = ({
|
|
67
|
+
sessionScope,
|
|
68
|
+
designWidth,
|
|
69
|
+
designHeight,
|
|
70
|
+
orientation,
|
|
71
|
+
availableWidth,
|
|
72
|
+
availableHeight,
|
|
73
|
+
}: ResolveSurfaceViewportReferenceSizeOptions): {
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
} => {
|
|
77
|
+
if (
|
|
78
|
+
typeof designWidth === "number" &&
|
|
79
|
+
Number.isFinite(designWidth) &&
|
|
80
|
+
designWidth > 0 &&
|
|
81
|
+
typeof designHeight === "number" &&
|
|
82
|
+
Number.isFinite(designHeight) &&
|
|
83
|
+
designHeight > 0
|
|
84
|
+
) {
|
|
85
|
+
return {
|
|
86
|
+
width: designWidth,
|
|
87
|
+
height: designHeight,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const scopedReferenceSize =
|
|
92
|
+
resolveSurfaceViewportScopeReferenceSize(sessionScope);
|
|
93
|
+
if (scopedReferenceSize) {
|
|
94
|
+
return scopedReferenceSize[orientation];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
width: Math.max(availableWidth, 1),
|
|
99
|
+
height: Math.max(availableHeight, 1),
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const SURFACE_VIEWPORT_TEXT_SIZE_BASES = {
|
|
104
|
+
xs: "0.75rem",
|
|
105
|
+
sm: "0.875rem",
|
|
106
|
+
base: "1rem",
|
|
107
|
+
lg: "1.125rem",
|
|
108
|
+
xl: "1.25rem",
|
|
109
|
+
"2xl": "1.5rem",
|
|
110
|
+
"3xl": "1.875rem",
|
|
111
|
+
"4xl": "2.25rem",
|
|
112
|
+
"5xl": "3rem",
|
|
113
|
+
"6xl": "3.75rem",
|
|
114
|
+
"7xl": "4.5rem",
|
|
115
|
+
"8xl": "6rem",
|
|
116
|
+
"9xl": "8rem",
|
|
117
|
+
} as const;
|
|
118
|
+
|
|
119
|
+
const SURFACE_VIEWPORT_CONTAINER_BASES = {
|
|
120
|
+
"3xs": "16rem",
|
|
121
|
+
"2xs": "18rem",
|
|
122
|
+
xs: "20rem",
|
|
123
|
+
sm: "24rem",
|
|
124
|
+
md: "28rem",
|
|
125
|
+
lg: "32rem",
|
|
126
|
+
xl: "36rem",
|
|
127
|
+
"2xl": "42rem",
|
|
128
|
+
"3xl": "48rem",
|
|
129
|
+
"4xl": "56rem",
|
|
130
|
+
"5xl": "64rem",
|
|
131
|
+
"6xl": "72rem",
|
|
132
|
+
"7xl": "80rem",
|
|
133
|
+
} as const;
|
|
134
|
+
|
|
135
|
+
const SURFACE_VIEWPORT_RADIUS_BASES = {
|
|
136
|
+
xs: "0.125rem",
|
|
137
|
+
sm: "0.375rem",
|
|
138
|
+
md: "0.5rem",
|
|
139
|
+
lg: "0.625rem",
|
|
140
|
+
xl: "0.875rem",
|
|
141
|
+
"2xl": "1rem",
|
|
142
|
+
"3xl": "1.5rem",
|
|
143
|
+
"4xl": "2rem",
|
|
144
|
+
} as const;
|
|
145
|
+
|
|
146
|
+
export interface ResolveSurfaceViewportAvailableSizeOptions {
|
|
147
|
+
safeViewportWidth: number;
|
|
148
|
+
safeViewportHeight: number;
|
|
149
|
+
orientation?: SurfaceOrientation;
|
|
150
|
+
needsRotation: boolean;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export const resolveSurfaceViewportAvailableSize = ({
|
|
154
|
+
safeViewportWidth,
|
|
155
|
+
safeViewportHeight,
|
|
156
|
+
orientation,
|
|
157
|
+
needsRotation,
|
|
158
|
+
}: ResolveSurfaceViewportAvailableSizeOptions): {
|
|
159
|
+
width: number;
|
|
160
|
+
height: number;
|
|
161
|
+
} => {
|
|
162
|
+
if (!orientation || !needsRotation) {
|
|
163
|
+
return {
|
|
164
|
+
width: safeViewportWidth,
|
|
165
|
+
height: safeViewportHeight,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
width: safeViewportHeight,
|
|
171
|
+
height: safeViewportWidth,
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export interface ResolveSurfaceViewportScaleOptions {
|
|
176
|
+
availableWidth: number;
|
|
177
|
+
availableHeight: number;
|
|
178
|
+
referenceWidth: number;
|
|
179
|
+
referenceHeight: number;
|
|
180
|
+
scaleMode?: "fit" | "width" | "height";
|
|
181
|
+
uiScaleMultiplier?: number;
|
|
182
|
+
minScale?: number;
|
|
183
|
+
maxScale?: number;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export const resolveSurfaceViewportScale = ({
|
|
187
|
+
availableWidth,
|
|
188
|
+
availableHeight,
|
|
189
|
+
referenceWidth,
|
|
190
|
+
referenceHeight,
|
|
191
|
+
scaleMode = "fit",
|
|
192
|
+
uiScaleMultiplier = 1,
|
|
193
|
+
minScale,
|
|
194
|
+
maxScale,
|
|
195
|
+
}: ResolveSurfaceViewportScaleOptions): number => {
|
|
196
|
+
const safeAvailableWidth = Math.max(availableWidth, 1);
|
|
197
|
+
const safeAvailableHeight = Math.max(availableHeight, 1);
|
|
198
|
+
const safeReferenceWidth = Math.max(referenceWidth, 1);
|
|
199
|
+
const safeReferenceHeight = Math.max(referenceHeight, 1);
|
|
200
|
+
|
|
201
|
+
const widthScale = safeAvailableWidth / safeReferenceWidth;
|
|
202
|
+
const heightScale = safeAvailableHeight / safeReferenceHeight;
|
|
203
|
+
const baseScale =
|
|
204
|
+
scaleMode === "width"
|
|
205
|
+
? widthScale
|
|
206
|
+
: scaleMode === "height"
|
|
207
|
+
? heightScale
|
|
208
|
+
: Math.min(widthScale, heightScale);
|
|
209
|
+
|
|
210
|
+
let scale = baseScale * uiScaleMultiplier;
|
|
211
|
+
|
|
212
|
+
if (typeof minScale === "number" && Number.isFinite(minScale)) {
|
|
213
|
+
scale = Math.max(scale, minScale);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (typeof maxScale === "number" && Number.isFinite(maxScale)) {
|
|
217
|
+
scale = Math.min(scale, maxScale);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return scale;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const createScaledVariableValue = (baseValue: string): string =>
|
|
224
|
+
`calc(${baseValue} * var(--airjam-ui-scale))`;
|
|
225
|
+
|
|
226
|
+
export const createSurfaceViewportScaleStyle = ({
|
|
227
|
+
scale,
|
|
228
|
+
referenceWidth,
|
|
229
|
+
referenceHeight,
|
|
230
|
+
}: {
|
|
231
|
+
scale: number;
|
|
232
|
+
referenceWidth: number;
|
|
233
|
+
referenceHeight: number;
|
|
234
|
+
}): CSSProperties => {
|
|
235
|
+
const style: Record<string, string> = {
|
|
236
|
+
position: "relative",
|
|
237
|
+
width: "100%",
|
|
238
|
+
height: "100%",
|
|
239
|
+
overflow: "hidden",
|
|
240
|
+
fontSize: createScaledVariableValue("1rem"),
|
|
241
|
+
"--airjam-ui-scale": String(scale),
|
|
242
|
+
"--airjam-ui-rem": createScaledVariableValue("1rem"),
|
|
243
|
+
"--airjam-reference-width": `${referenceWidth}px`,
|
|
244
|
+
"--airjam-reference-height": `${referenceHeight}px`,
|
|
245
|
+
"--spacing": createScaledVariableValue("0.25rem"),
|
|
246
|
+
"--radius": createScaledVariableValue("0.625rem"),
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
for (const [name, baseValue] of Object.entries(
|
|
250
|
+
SURFACE_VIEWPORT_TEXT_SIZE_BASES,
|
|
251
|
+
)) {
|
|
252
|
+
style[`--text-${name}`] = createScaledVariableValue(baseValue);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
for (const [name, baseValue] of Object.entries(
|
|
256
|
+
SURFACE_VIEWPORT_CONTAINER_BASES,
|
|
257
|
+
)) {
|
|
258
|
+
style[`--container-${name}`] = createScaledVariableValue(baseValue);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
for (const [name, baseValue] of Object.entries(
|
|
262
|
+
SURFACE_VIEWPORT_RADIUS_BASES,
|
|
263
|
+
)) {
|
|
264
|
+
style[`--radius-${name}`] = createScaledVariableValue(baseValue);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return style as CSSProperties;
|
|
268
|
+
};
|