@air-jam/sdk 0.1.4 → 0.9.1
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 +481 -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 +14 -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 +544 -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 +29 -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 +1737 -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 +123 -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-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-7UXSWCZZ.js +32 -0
- package/dist/chunk-7UXSWCZZ.js.map +1 -0
- package/dist/chunk-BE6Z4SIT.js +65 -0
- package/dist/chunk-BE6Z4SIT.js.map +1 -0
- package/dist/chunk-CABEUV65.js +184 -0
- package/dist/chunk-CABEUV65.js.map +1 -0
- package/dist/chunk-CEJ5RFSG.js +288 -0
- package/dist/chunk-CEJ5RFSG.js.map +1 -0
- package/dist/chunk-EDRQIOCV.js +25 -0
- package/dist/chunk-EDRQIOCV.js.map +1 -0
- package/dist/chunk-EVZJA6RN.js +140 -0
- package/dist/chunk-EVZJA6RN.js.map +1 -0
- package/dist/chunk-FAT2KJ3K.js +238 -0
- package/dist/chunk-FAT2KJ3K.js.map +1 -0
- package/dist/chunk-IKKDONQL.js +1 -0
- package/dist/chunk-IKKDONQL.js.map +1 -0
- package/dist/chunk-JEHV5C2X.js +249 -0
- package/dist/chunk-JEHV5C2X.js.map +1 -0
- package/dist/chunk-JO2HR5PV.js +43 -0
- package/dist/chunk-JO2HR5PV.js.map +1 -0
- package/dist/chunk-JTF47B56.js +1 -0
- package/dist/chunk-JTF47B56.js.map +1 -0
- package/dist/chunk-KXAFI5OP.js +193 -0
- package/dist/chunk-KXAFI5OP.js.map +1 -0
- package/dist/chunk-LIXPF4P6.js +22 -0
- package/dist/chunk-LIXPF4P6.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-NUJBMV3O.js +1435 -0
- package/dist/chunk-NUJBMV3O.js.map +1 -0
- package/dist/chunk-TGRTEWYV.js +195 -0
- package/dist/chunk-TGRTEWYV.js.map +1 -0
- package/dist/chunk-UWJOIVON.js +369 -0
- package/dist/chunk-UWJOIVON.js.map +1 -0
- package/dist/chunk-VKBMZHMQ.js +216 -0
- package/dist/chunk-VKBMZHMQ.js.map +1 -0
- package/dist/chunk-W2VK36RO.js +11 -0
- package/dist/chunk-W2VK36RO.js.map +1 -0
- package/dist/chunk-W3YA5BWR.js +126 -0
- package/dist/chunk-W3YA5BWR.js.map +1 -0
- package/dist/chunk-X24K52DG.js +12 -0
- package/dist/chunk-X24K52DG.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 +8730 -3426
- 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 -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 +2620 -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/runtime-topology.cjs +405 -0
- package/dist/runtime-topology.cjs.map +1 -0
- package/dist/runtime-topology.d.cts +59 -0
- package/dist/runtime-topology.d.ts +59 -0
- package/dist/runtime-topology.js +31 -0
- package/dist/runtime-topology.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 +3061 -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 +1719 -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 +155 -10
- 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/runtime-topology.ts +569 -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,82 @@
|
|
|
1
|
+
import type { ZodType } from "zod";
|
|
2
|
+
|
|
3
|
+
export type PrefabRenderFn<TProps, TRenderOutput = unknown> = (
|
|
4
|
+
props: TProps,
|
|
5
|
+
) => TRenderOutput;
|
|
6
|
+
|
|
7
|
+
export interface PrefabPreviewDescriptor {
|
|
8
|
+
summary: string;
|
|
9
|
+
accentColor?: string;
|
|
10
|
+
dimensions?: Record<string, number>;
|
|
11
|
+
defaultVariant?: string;
|
|
12
|
+
camera?: {
|
|
13
|
+
position: readonly [number, number, number];
|
|
14
|
+
target: readonly [number, number, number];
|
|
15
|
+
fov?: number;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface PrefabBoundsDescriptor {
|
|
20
|
+
width?: number;
|
|
21
|
+
height?: number;
|
|
22
|
+
depth?: number;
|
|
23
|
+
radius?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface PrefabFootprintDescriptor {
|
|
27
|
+
kind: "box" | "circle" | "custom";
|
|
28
|
+
width?: number;
|
|
29
|
+
depth?: number;
|
|
30
|
+
radius?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type PrefabPlacementOrigin = "center" | "ground" | "base" | "custom";
|
|
34
|
+
|
|
35
|
+
export interface PrefabPlacementDescriptor {
|
|
36
|
+
origin: PrefabPlacementOrigin;
|
|
37
|
+
bounds?: PrefabBoundsDescriptor;
|
|
38
|
+
footprint?: PrefabFootprintDescriptor;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface PrefabDefinition<
|
|
42
|
+
TProps,
|
|
43
|
+
// Existential wildcard for prefab render contracts that may take additional renderer-specific arguments.
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
TRenderContract extends (...args: any[]) => unknown = PrefabRenderFn<TProps>,
|
|
46
|
+
> {
|
|
47
|
+
id: string;
|
|
48
|
+
label: string;
|
|
49
|
+
category: string;
|
|
50
|
+
description: string;
|
|
51
|
+
tags: readonly string[];
|
|
52
|
+
defaultProps: TProps;
|
|
53
|
+
configSchema: ZodType<TProps>;
|
|
54
|
+
render: TRenderContract;
|
|
55
|
+
preview?: PrefabPreviewDescriptor;
|
|
56
|
+
placement?: PrefabPlacementDescriptor;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type PrefabCatalog = readonly PrefabDefinition<
|
|
60
|
+
unknown,
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
|
+
(...args: any[]) => unknown
|
|
63
|
+
>[];
|
|
64
|
+
|
|
65
|
+
export const definePrefab = <
|
|
66
|
+
TProps,
|
|
67
|
+
// Existential wildcard for prefab render contracts that may take additional renderer-specific arguments.
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
TRenderContract extends (...args: any[]) => unknown = PrefabRenderFn<TProps>,
|
|
70
|
+
>(
|
|
71
|
+
definition: PrefabDefinition<TProps, TRenderContract>,
|
|
72
|
+
): PrefabDefinition<TProps, TRenderContract> => definition;
|
|
73
|
+
|
|
74
|
+
export const createPrefabCatalog = <
|
|
75
|
+
const TPrefabs extends readonly PrefabDefinition<
|
|
76
|
+
unknown,
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
+
(...args: any[]) => unknown
|
|
79
|
+
>[],
|
|
80
|
+
>(
|
|
81
|
+
prefabs: TPrefabs,
|
|
82
|
+
): TPrefabs => prefabs;
|
package/src/prefabs.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createPrefabCatalog,
|
|
3
|
+
definePrefab,
|
|
4
|
+
type PrefabBoundsDescriptor,
|
|
5
|
+
type PrefabCatalog,
|
|
6
|
+
type PrefabDefinition,
|
|
7
|
+
type PrefabFootprintDescriptor,
|
|
8
|
+
type PrefabPlacementDescriptor,
|
|
9
|
+
type PrefabPlacementOrigin,
|
|
10
|
+
type PrefabPreviewDescriptor,
|
|
11
|
+
type PrefabRenderFn,
|
|
12
|
+
} from "./prefabs/types";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useAirJamConfig } from "../context/air-jam-context";
|
|
2
|
+
import { useAirJamHost } from "../hooks/use-air-jam-host";
|
|
3
|
+
import { useOptionalPlatformSettingsOwnerApi } from "../settings/platform-settings-runtime";
|
|
4
|
+
import { cn } from "../utils/cn";
|
|
5
|
+
import {
|
|
6
|
+
resolveHostPreviewControllerWorkspaceEnabled,
|
|
7
|
+
type HostPreviewControllerWorkspaceEnabled,
|
|
8
|
+
} from "./ownership";
|
|
9
|
+
import {
|
|
10
|
+
PreviewControllerWorkspace,
|
|
11
|
+
type PreviewControllerWorkspaceProps,
|
|
12
|
+
} from "./workspace";
|
|
13
|
+
|
|
14
|
+
export type HostPreviewControllerWorkspaceProps = Omit<
|
|
15
|
+
PreviewControllerWorkspaceProps,
|
|
16
|
+
"enabled" | "joinUrl"
|
|
17
|
+
> & {
|
|
18
|
+
enabled?: HostPreviewControllerWorkspaceEnabled;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const HostPreviewControllerWorkspace = ({
|
|
22
|
+
enabled = "auto",
|
|
23
|
+
className,
|
|
24
|
+
...props
|
|
25
|
+
}: HostPreviewControllerWorkspaceProps) => {
|
|
26
|
+
const host = useAirJamHost();
|
|
27
|
+
const config = useAirJamConfig();
|
|
28
|
+
const platformSettingsOwner = useOptionalPlatformSettingsOwnerApi();
|
|
29
|
+
const resolvedEnabled = resolveHostPreviewControllerWorkspaceEnabled({
|
|
30
|
+
enabled,
|
|
31
|
+
topology: config.topology,
|
|
32
|
+
});
|
|
33
|
+
const joinUrl =
|
|
34
|
+
host.joinUrlStatus === "ready" && host.joinUrl ? host.joinUrl : null;
|
|
35
|
+
const handleResetRoom = async () => {
|
|
36
|
+
const ack = await host.resetRoom();
|
|
37
|
+
if (!ack.ok || typeof window === "undefined") {
|
|
38
|
+
return ack;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
window.location.reload();
|
|
42
|
+
return ack;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<PreviewControllerWorkspace
|
|
47
|
+
enabled={resolvedEnabled}
|
|
48
|
+
joinUrl={joinUrl}
|
|
49
|
+
controllers={host.controllers}
|
|
50
|
+
onRemoveController={host.removeController}
|
|
51
|
+
onResetRoom={handleResetRoom}
|
|
52
|
+
onActiveOpacityChange={(activeOpacity) =>
|
|
53
|
+
platformSettingsOwner?.updatePreviewControllers({ activeOpacity })
|
|
54
|
+
}
|
|
55
|
+
className={cn("right-4 bottom-4 z-60 sm:right-6 sm:bottom-6", className)}
|
|
56
|
+
{...props}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { generateControllerId } from "../utils/ids";
|
|
2
|
+
|
|
3
|
+
export const AIR_JAM_PREVIEW_FLAG_QUERY_PARAM = "aj_preview";
|
|
4
|
+
export const AIR_JAM_PREVIEW_DEVICE_QUERY_PARAM = "aj_preview_device";
|
|
5
|
+
|
|
6
|
+
export interface PreviewControllerIdentity {
|
|
7
|
+
controllerId: string;
|
|
8
|
+
deviceId: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const generatePreviewDeviceId = (): string => {
|
|
12
|
+
if (
|
|
13
|
+
typeof crypto !== "undefined" &&
|
|
14
|
+
typeof crypto.randomUUID === "function"
|
|
15
|
+
) {
|
|
16
|
+
return `pd_${crypto.randomUUID()}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return `pd_${generateControllerId()}_${Date.now().toString(36)}`;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const createPreviewControllerIdentity =
|
|
23
|
+
(): PreviewControllerIdentity => ({
|
|
24
|
+
controllerId: generateControllerId(),
|
|
25
|
+
deviceId: generatePreviewDeviceId(),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const normalizePreviewDeviceId = (
|
|
29
|
+
value: string | null | undefined,
|
|
30
|
+
): string | null => {
|
|
31
|
+
if (!value) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const normalized = value.trim();
|
|
36
|
+
return normalized.length >= 8 ? normalized : null;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const isPreviewControllerSearchParams = (
|
|
40
|
+
params: URLSearchParams,
|
|
41
|
+
): boolean => {
|
|
42
|
+
const flag = params.get(AIR_JAM_PREVIEW_FLAG_QUERY_PARAM);
|
|
43
|
+
return flag === "1" || flag === "true";
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const readPreviewControllerDeviceIdFromSearchParams = (
|
|
47
|
+
params: URLSearchParams,
|
|
48
|
+
): string | null => {
|
|
49
|
+
if (!isPreviewControllerSearchParams(params)) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return normalizePreviewDeviceId(
|
|
54
|
+
params.get(AIR_JAM_PREVIEW_DEVICE_QUERY_PARAM),
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const readPreviewControllerDeviceIdFromLocation = (): string | null => {
|
|
59
|
+
if (typeof window === "undefined") {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return readPreviewControllerDeviceIdFromSearchParams(
|
|
64
|
+
new URLSearchParams(window.location.search),
|
|
65
|
+
);
|
|
66
|
+
};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import type { ControllerOrientation } from "../protocol/controller";
|
|
2
|
+
|
|
3
|
+
export const PREVIEW_WORKSPACE_Z_INDEX = 2_147_483_000;
|
|
4
|
+
export const PREVIEW_WINDOW_TITLEBAR_HEIGHT = 38;
|
|
5
|
+
export const PREVIEW_WINDOW_RESIZE_EDGE_HIT_SIZE = 12;
|
|
6
|
+
export const PREVIEW_WINDOW_RESIZE_CORNER_HIT_SIZE = 20;
|
|
7
|
+
|
|
8
|
+
export interface PreviewControllerDeviceProfile {
|
|
9
|
+
id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
portrait: { width: number; height: number };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const IPHONE_16_PREVIEW_DEVICE: PreviewControllerDeviceProfile = {
|
|
15
|
+
id: "iphone-16",
|
|
16
|
+
label: "iPhone 16 browser",
|
|
17
|
+
portrait: {
|
|
18
|
+
width: 393,
|
|
19
|
+
height: 740,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const DEFAULT_PREVIEW_CONTROLLER_DEVICE = IPHONE_16_PREVIEW_DEVICE;
|
|
24
|
+
export const DEFAULT_PREVIEW_CONTROLLER_SCALE = 0.8;
|
|
25
|
+
export const PREVIEW_CONTROLLER_MIN_SCALE = 0.55;
|
|
26
|
+
export const PREVIEW_CONTROLLER_MAX_SCALE = 1.12;
|
|
27
|
+
|
|
28
|
+
export const getPreviewControllerViewportSize = (
|
|
29
|
+
orientation: ControllerOrientation,
|
|
30
|
+
device: PreviewControllerDeviceProfile = DEFAULT_PREVIEW_CONTROLLER_DEVICE,
|
|
31
|
+
) =>
|
|
32
|
+
orientation === "portrait"
|
|
33
|
+
? device.portrait
|
|
34
|
+
: {
|
|
35
|
+
width: device.portrait.height,
|
|
36
|
+
height: device.portrait.width,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const getPreviewControllerScaleConstraints = () => ({
|
|
40
|
+
min: PREVIEW_CONTROLLER_MIN_SCALE,
|
|
41
|
+
max: PREVIEW_CONTROLLER_MAX_SCALE,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const getPreviewWindowBoundsForScale = (
|
|
45
|
+
orientation: ControllerOrientation,
|
|
46
|
+
scale: number,
|
|
47
|
+
device: PreviewControllerDeviceProfile = DEFAULT_PREVIEW_CONTROLLER_DEVICE,
|
|
48
|
+
) => {
|
|
49
|
+
const viewport = getPreviewControllerViewportSize(orientation, device);
|
|
50
|
+
return {
|
|
51
|
+
width: viewport.width * scale,
|
|
52
|
+
height: PREVIEW_WINDOW_TITLEBAR_HEIGHT + viewport.height * scale,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const getPreviewControllerScaleForBounds = (
|
|
57
|
+
orientation: ControllerOrientation,
|
|
58
|
+
bounds: { width: number; height: number },
|
|
59
|
+
mode: "grow" | "shrink" | "fit" = "fit",
|
|
60
|
+
device: PreviewControllerDeviceProfile = DEFAULT_PREVIEW_CONTROLLER_DEVICE,
|
|
61
|
+
): number => {
|
|
62
|
+
const viewport = getPreviewControllerViewportSize(orientation, device);
|
|
63
|
+
const widthScale = bounds.width / viewport.width;
|
|
64
|
+
const heightScale =
|
|
65
|
+
(bounds.height - PREVIEW_WINDOW_TITLEBAR_HEIGHT) / viewport.height;
|
|
66
|
+
const rawScale =
|
|
67
|
+
mode === "grow"
|
|
68
|
+
? Math.max(widthScale, heightScale)
|
|
69
|
+
: mode === "shrink"
|
|
70
|
+
? Math.min(widthScale, heightScale)
|
|
71
|
+
: Math.min(widthScale, heightScale);
|
|
72
|
+
const constraints = getPreviewControllerScaleConstraints();
|
|
73
|
+
|
|
74
|
+
return Math.min(Math.max(rawScale, constraints.min), constraints.max);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const getPreviewControllerScaleForResize = ({
|
|
78
|
+
orientation,
|
|
79
|
+
bounds,
|
|
80
|
+
originBounds,
|
|
81
|
+
handle,
|
|
82
|
+
device = DEFAULT_PREVIEW_CONTROLLER_DEVICE,
|
|
83
|
+
}: {
|
|
84
|
+
orientation: ControllerOrientation;
|
|
85
|
+
bounds: { width: number; height: number };
|
|
86
|
+
originBounds: { width: number; height: number };
|
|
87
|
+
handle: PreviewControllerResizeHandle;
|
|
88
|
+
device?: PreviewControllerDeviceProfile;
|
|
89
|
+
}): number => {
|
|
90
|
+
const viewport = getPreviewControllerViewportSize(orientation, device);
|
|
91
|
+
const widthScale = bounds.width / viewport.width;
|
|
92
|
+
const heightScale =
|
|
93
|
+
(bounds.height - PREVIEW_WINDOW_TITLEBAR_HEIGHT) / viewport.height;
|
|
94
|
+
|
|
95
|
+
if (handle === "e" || handle === "w") {
|
|
96
|
+
const constraints = getPreviewControllerScaleConstraints();
|
|
97
|
+
return Math.min(Math.max(widthScale, constraints.min), constraints.max);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (handle === "n" || handle === "s") {
|
|
101
|
+
const constraints = getPreviewControllerScaleConstraints();
|
|
102
|
+
return Math.min(Math.max(heightScale, constraints.min), constraints.max);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const widthDelta = Math.abs(bounds.width - originBounds.width);
|
|
106
|
+
const heightDelta = Math.abs(bounds.height - originBounds.height);
|
|
107
|
+
const rawScale =
|
|
108
|
+
widthDelta / viewport.width >= heightDelta / viewport.height
|
|
109
|
+
? widthScale
|
|
110
|
+
: heightScale;
|
|
111
|
+
const constraints = getPreviewControllerScaleConstraints();
|
|
112
|
+
|
|
113
|
+
return Math.min(Math.max(rawScale, constraints.min), constraints.max);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const PREVIEW_WINDOW_DEFAULT_BOUNDS: Record<
|
|
117
|
+
ControllerOrientation,
|
|
118
|
+
{ width: number; height: number }
|
|
119
|
+
> = {
|
|
120
|
+
portrait: getPreviewWindowBoundsForScale(
|
|
121
|
+
"portrait",
|
|
122
|
+
DEFAULT_PREVIEW_CONTROLLER_SCALE,
|
|
123
|
+
),
|
|
124
|
+
landscape: getPreviewWindowBoundsForScale(
|
|
125
|
+
"landscape",
|
|
126
|
+
DEFAULT_PREVIEW_CONTROLLER_SCALE,
|
|
127
|
+
),
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const PREVIEW_WINDOW_SIZE_CONSTRAINTS: Record<
|
|
131
|
+
ControllerOrientation,
|
|
132
|
+
{
|
|
133
|
+
minWidth: number;
|
|
134
|
+
minHeight: number;
|
|
135
|
+
maxWidth: number;
|
|
136
|
+
maxHeight: number;
|
|
137
|
+
}
|
|
138
|
+
> = {
|
|
139
|
+
portrait: {
|
|
140
|
+
minWidth: getPreviewWindowBoundsForScale(
|
|
141
|
+
"portrait",
|
|
142
|
+
PREVIEW_CONTROLLER_MIN_SCALE,
|
|
143
|
+
).width,
|
|
144
|
+
minHeight: getPreviewWindowBoundsForScale(
|
|
145
|
+
"portrait",
|
|
146
|
+
PREVIEW_CONTROLLER_MIN_SCALE,
|
|
147
|
+
).height,
|
|
148
|
+
maxWidth: getPreviewWindowBoundsForScale(
|
|
149
|
+
"portrait",
|
|
150
|
+
PREVIEW_CONTROLLER_MAX_SCALE,
|
|
151
|
+
).width,
|
|
152
|
+
maxHeight: getPreviewWindowBoundsForScale(
|
|
153
|
+
"portrait",
|
|
154
|
+
PREVIEW_CONTROLLER_MAX_SCALE,
|
|
155
|
+
).height,
|
|
156
|
+
},
|
|
157
|
+
landscape: {
|
|
158
|
+
minWidth: getPreviewWindowBoundsForScale(
|
|
159
|
+
"landscape",
|
|
160
|
+
PREVIEW_CONTROLLER_MIN_SCALE,
|
|
161
|
+
).width,
|
|
162
|
+
minHeight: getPreviewWindowBoundsForScale(
|
|
163
|
+
"landscape",
|
|
164
|
+
PREVIEW_CONTROLLER_MIN_SCALE,
|
|
165
|
+
).height,
|
|
166
|
+
maxWidth: getPreviewWindowBoundsForScale(
|
|
167
|
+
"landscape",
|
|
168
|
+
PREVIEW_CONTROLLER_MAX_SCALE,
|
|
169
|
+
).width,
|
|
170
|
+
maxHeight: getPreviewWindowBoundsForScale(
|
|
171
|
+
"landscape",
|
|
172
|
+
PREVIEW_CONTROLLER_MAX_SCALE,
|
|
173
|
+
).height,
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export type PreviewControllerResizeHandle =
|
|
178
|
+
| "n"
|
|
179
|
+
| "s"
|
|
180
|
+
| "e"
|
|
181
|
+
| "w"
|
|
182
|
+
| "ne"
|
|
183
|
+
| "nw"
|
|
184
|
+
| "se"
|
|
185
|
+
| "sw";
|
|
186
|
+
|
|
187
|
+
export interface PreviewControllerBounds {
|
|
188
|
+
x: number;
|
|
189
|
+
y: number;
|
|
190
|
+
width: number;
|
|
191
|
+
height: number;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export const getDefaultPreviewWindowBounds = (
|
|
195
|
+
orientation: ControllerOrientation,
|
|
196
|
+
) => PREVIEW_WINDOW_DEFAULT_BOUNDS[orientation];
|
|
197
|
+
|
|
198
|
+
export const getPreviewWindowSizeConstraints = (
|
|
199
|
+
orientation: ControllerOrientation,
|
|
200
|
+
) => PREVIEW_WINDOW_SIZE_CONSTRAINTS[orientation];
|
|
201
|
+
|
|
202
|
+
export const getResizedPreviewBounds = (
|
|
203
|
+
bounds: PreviewControllerBounds,
|
|
204
|
+
handle: PreviewControllerResizeHandle,
|
|
205
|
+
deltaX: number,
|
|
206
|
+
deltaY: number,
|
|
207
|
+
): PreviewControllerBounds => {
|
|
208
|
+
const resizingWest = handle.includes("w");
|
|
209
|
+
const resizingEast = handle.includes("e");
|
|
210
|
+
const resizingNorth = handle.includes("n");
|
|
211
|
+
const resizingSouth = handle.includes("s");
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
x: resizingWest ? bounds.x + deltaX : bounds.x,
|
|
215
|
+
y: resizingNorth ? bounds.y + deltaY : bounds.y,
|
|
216
|
+
width:
|
|
217
|
+
bounds.width + (resizingEast ? deltaX : 0) - (resizingWest ? deltaX : 0),
|
|
218
|
+
height:
|
|
219
|
+
bounds.height +
|
|
220
|
+
(resizingSouth ? deltaY : 0) -
|
|
221
|
+
(resizingNorth ? deltaY : 0),
|
|
222
|
+
};
|
|
223
|
+
};
|