A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(editor): the screen list is the project's, and orientation stops lying
esengine75b5b3e21c9b
diff --git a/desktop/src/App.tsx b/desktop/src/App.tsxindex 3fcb252a3..4916411cd 100644--- a/desktop/src/App.tsx+++ b/desktop/src/App.tsx@@ -125,7 +125,7 @@ export function App() {useEffect(() => {const apply = () => {const { device, orientation } = useEditorMode.getState();- EngineHost.setUiPreviewAspect(uiPreviewAspect(device, orientation));+ EngineHost.setUiPreviewAspect(uiPreviewAspect(device, orientation, ProjectStore.getSnapshot()?.screenPresets));};apply();const unsubMode = useEditorMode.subscribe(apply);diff --git a/desktop/src/components/OverlayMenu.tsx b/desktop/src/components/OverlayMenu.tsxindex 63f2e83d9..3231eb565 100644--- a/desktop/src/components/OverlayMenu.tsx+++ b/desktop/src/components/OverlayMenu.tsx@@ -61,10 +61,27 @@ export function DdCheck({ on, label, onClick }: { on: boolean; label: string; on);}-/** Single-select menu row (tick mark, shown when active) — for the Snap menu. */-export function DdRadio({ on, label, onClick }: { on: boolean; label: string; onClick: () => void }) {+/**+ * Single-select menu row (tick mark, shown when active) — for the Snap menu.+ *+ * `disabled` is for a choice that exists but cannot act yet: it stays visible so+ * the menu's shape does not shift, and `title` should say what would enable it. A+ * row that looks clickable and does nothing is worse than a greyed one.+ */+export function DdRadio({+ on, label, onClick, disabled = false, title,+}: {+ on: boolean; label: string; onClick: () => void; disabled?: boolean; title?: string;+}) {return (- <div className={`ovmenu-item${on ? ' on' : ''}`} role="menuitemradio" aria-checked={on} onClick={onClick}>+ <div+ className={`ovmenu-item${on ? ' on' : ''}${disabled ? ' disabled' : ''}`}+ role="menuitemradio"+ aria-checked={on}+ aria-disabled={disabled || undefined}+ title={title}+ onClick={disabled ? undefined : onClick}+ ><span className="tk"><Check size={11} strokeWidth={3} /></span><span className="l">{label}</span></div>diff --git a/desktop/src/i18n/messages/viewport.ts b/desktop/src/i18n/messages/viewport.tsindex 0230e29f1..c1674c041 100644--- a/desktop/src/i18n/messages/viewport.ts+++ b/desktop/src/i18n/messages/viewport.ts@@ -113,6 +113,10 @@ export const viewportMessages = defineMessages({'vp.device': { en: 'Device', zh: '设备' },'vp.devDesign': { en: 'Design', zh: '设计' },'vp.orientation': { en: 'Orientation', zh: '方向' },+ 'vp.orientationNeedsDevice': {+ en: 'Pick a device to rotate — “Design” simulates no screen',+ zh: '选择设备后才能旋转——“设计”不模拟任何屏幕',+ },'vp.landscape': { en: 'Landscape', zh: '横屏' },'vp.portrait': { en: 'Portrait', zh: '竖屏' },'vp.overlay': { en: 'Overlay', zh: '叠加层' },diff --git a/desktop/src/mode/TargetScreen.tsx b/desktop/src/mode/TargetScreen.tsxindex 1ecc9f0fc..08b4e2386 100644--- a/desktop/src/mode/TargetScreen.tsx+++ b/desktop/src/mode/TargetScreen.tsx@@ -13,11 +13,19 @@** One selection now drives both. Editing previews it; play is constrained to it.*/+import { useSyncExternalStore } from 'react';import { Smartphone } from 'lucide-react';import { t } from '@/i18n';import { OvDropdown, DdCheck, DdRadio } from '@/components/OverlayMenu';import { useEditorMode } from '@/store/editorModeStore';-import { RESOLUTION_PRESETS, RESOLUTION_PRESET_BY_ID, deviceDims } from '@/mode/resolutionPresets';+import { screenPresets, screenPresetById, deviceDims } from '@/mode/resolutionPresets';+import { ProjectStore } from '@/project/ProjectStore';+import type { ScreenPreset as ProjectScreenPreset } from '@/project/format';++/** The open project's declared screens, reactively. */+export function useProjectScreenPresets(): ProjectScreenPreset[] | undefined {+ return useSyncExternalStore(ProjectStore.subscribe, ProjectStore.getSnapshot)?.screenPresets;+}/*** The dropdown: device presets, orientation, and (authoring only) the safe-area@@ -37,15 +45,19 @@ export function TargetScreenDropdown({const device = useEditorMode((s) => s.device);const orientation = useEditorMode((s) => s.orientation);const showSafeArea = useEditorMode((s) => s.showSafeArea);+ const presets = useProjectScreenPresets();+ // The `design` sentinel simulates no screen, so there is nothing for the+ // orientation to turn — deviceDims ignores it entirely for this case.+ const noDevice = !deviceDims(device, orientation, presets);return (<OvDropdownicon={Smartphone}- label={<span className="val">{RESOLUTION_PRESET_BY_ID[device].label}</span>}+ label={<span className="val">{screenPresetById(device, presets).label}</span>}title={t('vp.deviceTitle')}><div className="ovmenu-lbl">{t('vp.device')}</div>- {RESOLUTION_PRESETS.map((p) => (+ {screenPresets(presets).map((p) => (<DdRadiokey={p.id}on={device === p.id}@@ -63,17 +75,26 @@ export function TargetScreenDropdown({}}/>))}+ {/* Orientation rotates a DEVICE. With no device simulated there is nothing to+ rotate — the design resolution is the authored shape, not a screen being+ held one way or the other — so the rows are disabled rather than being+ clickable no-ops. */}<div className="ovmenu-lbl">{t('vp.orientation')}</div><DdRadioon={orientation === 'landscape'}label={t('vp.landscape')}+ disabled={noDevice}+ title={noDevice ? t('vp.orientationNeedsDevice') : undefined}onClick={() => orientation !== 'landscape' && useEditorMode.getState().toggleOrientation()}/><DdRadioon={orientation === 'portrait'}label={t('vp.portrait')}+ disabled={noDevice}+ title={noDevice ? t('vp.orientationNeedsDevice') : undefined}onClick={() => orientation !== 'portrait' && useEditorMode.getState().toggleOrientation()}/>+ {noDevice && <div className="ovmenu-note">{t('vp.orientationNeedsDevice')}</div>}{showSafeAreaToggle && (<><div className="ovmenu-lbl">{t('vp.overlay')}</div>@@ -98,14 +119,19 @@ export function TargetScreenDropdown({export function playHostAspectStyle(device: string,orientation: 'portrait' | 'landscape',+ presets?: readonly ProjectScreenPreset[],): React.CSSProperties | null {- const d = deviceDims(device as never, orientation);+ const d = deviceDims(device, orientation, presets);if (!d) return null;return { aspectRatio: `${d.w} / ${d.h}`, maxWidth: '100%', maxHeight: '100%', width: 'auto', height: '100%' };}/** Label for the status readout: the simulated screen's pixel size, or null. */-export function targetScreenLabel(device: string, orientation: 'portrait' | 'landscape'): string | null {- const d = deviceDims(device as never, orientation);+export function targetScreenLabel(+ device: string,+ orientation: 'portrait' | 'landscape',+ presets?: readonly ProjectScreenPreset[],+): string | null {+ const d = deviceDims(device, orientation, presets);return d ? `${d.w} × ${d.h}` : null;}diff --git a/desktop/src/mode/resolutionPresets.ts b/desktop/src/mode/resolutionPresets.tsindex 760b55314..4f04496b3 100644--- a/desktop/src/mode/resolutionPresets.ts+++ b/desktop/src/mode/resolutionPresets.ts@@ -9,7 +9,10 @@* orientation toggle swaps them at render time.*/import { t } from '@/i18n';+import type { ScreenPreset as ProjectScreenPreset } from '@/project/format';+/** The built-in ids. Not a closed set: a project may declare its own screens, so+ * anything holding a selection types it as `string`. */export type DevicePresetId = 'design' | 'iphone' | 'ipad' | '1080p' | '720p';export interface DeviceInsets {@@ -20,7 +23,7 @@ export interface DeviceInsets {}export interface DevicePreset {- id: DevicePresetId;+ id: string;label: string;/** Portrait pixel dimensions. The `design` sentinel (0×0) means "use the Canvas' own aspect" (no letterbox). */w: number;@@ -41,6 +44,35 @@ export const RESOLUTION_PRESET_BY_ID: Record<DevicePresetId, DevicePreset> = ObjRESOLUTION_PRESETS.map((p) => [p.id, p]),) as Record<DevicePresetId, DevicePreset>;+/**+ * Built-ins plus whatever the open project declares (`screenPresets` in the+ * manifest). Which handsets a team ships to is the project's business — a+ * built-in list is a guess, and one that cannot be corrected means everyone+ * tests on approximately the wrong screen.+ *+ * A project preset may take a built-in's id to REPLACE it (a studio that means+ * something specific by "iPhone"), so ids stay unique and a saved selection+ * still resolves. Everything downstream reads through here, so the dropdown, the+ * design-frame overlay and the play-host letterbox cannot disagree about what a+ * given id means.+ */+export function screenPresets(project?: readonly ProjectScreenPreset[]): DevicePreset[] {+ if (!project || project.length === 0) return RESOLUTION_PRESETS;+ const byId = new Map(RESOLUTION_PRESETS.map((p) => [p.id, p]));+ for (const p of project) {+ byId.set(p.id, { id: p.id, label: p.label, w: p.width, h: p.height, safe: p.safe });+ }+ return [...byId.values()];+}++/** Resolve one id against the built-ins + the project's. Unknown ⇒ the `design` sentinel. */+export function screenPresetById(+ id: string,+ project?: readonly ProjectScreenPreset[],+): DevicePreset {+ return screenPresets(project).find((p) => p.id === id) ?? RESOLUTION_PRESET_BY_ID.design;+}+export type Orientation = 'portrait' | 'landscape';/**@@ -49,8 +81,12 @@ export type Orientation = 'portrait' | 'landscape';* source of the device's oriented size — the design-frame overlay and the UI-layout-aspect* sync both read it, so the previewed frame and the actual UI layout can't drift apart.*/-export function deviceDims(device: DevicePresetId, orientation: Orientation): { w: number; h: number } | null {- const p = RESOLUTION_PRESET_BY_ID[device];+export function deviceDims(+ device: string,+ orientation: Orientation,+ presets?: readonly ProjectScreenPreset[],+): { w: number; h: number } | null {+ const p = screenPresetById(device, presets);if (p.w <= 0 || p.h <= 0) return null;return orientation === 'landscape' ? { w: p.h, h: p.w } : { w: p.w, h: p.h };}@@ -60,8 +96,12 @@ export function deviceDims(device: DevicePresetId, orientation: Orientation): {* aspect (previewing adaptation), or 0 for the `design` sentinel (WYSIWYG at the authored* resolution). Fed to EditorView.uiPreviewAspect → uiLayoutRect.*/-export function uiPreviewAspect(device: DevicePresetId, orientation: Orientation): number {- const d = deviceDims(device, orientation);+export function uiPreviewAspect(+ device: string,+ orientation: Orientation,+ presets?: readonly ProjectScreenPreset[],+): number {+ const d = deviceDims(device, orientation, presets);return d ? d.w / d.h : 0;}diff --git a/desktop/src/panels/GamePanel.tsx b/desktop/src/panels/GamePanel.tsxindex 1cc1e35b5..b30d97a89 100644--- a/desktop/src/panels/GamePanel.tsx+++ b/desktop/src/panels/GamePanel.tsx@@ -5,7 +5,7 @@ import { t } from '@/i18n';import { PlayRealm, PlayRealms } from '@/engine/PlayRealm';import { useEditorStore } from '@/store/editorStore';import { useEditorMode } from '@/store/editorModeStore';-import { TargetScreenDropdown, playHostAspectStyle, targetScreenLabel } from '@/mode/TargetScreen';+import { TargetScreenDropdown, playHostAspectStyle, targetScreenLabel, useProjectScreenPresets } from '@/mode/TargetScreen';// The "Game" dock panel: hosts the isolated play-realm iframe (the realm owns the// element + re-parents it here, so the realm survives panel remounts). The host@@ -31,6 +31,7 @@ export function GamePanel() {const playTarget = useEditorStore((s) => s.playTarget);const device = useEditorMode((s) => s.device);const orientation = useEditorMode((s) => s.orientation);+ const presets = useProjectScreenPresets();// Only host the realm iframe in 'window' mode — in 'viewport' mode the Viewport// owns it (one iframe, one mount). Guards against a stale Game tab stealing it.@@ -43,8 +44,8 @@ export function GamePanel() {}, [playTarget]);const overlay = overlayFor(snap);- const aspect = playHostAspectStyle(device, orientation);- const sizeLabel = targetScreenLabel(device, orientation);+ const aspect = playHostAspectStyle(device, orientation, presets);+ const sizeLabel = targetScreenLabel(device, orientation, presets);return (<div className="game-panel">diff --git a/desktop/src/panels/Viewport.tsx b/desktop/src/panels/Viewport.tsxindex a2d4d69c3..5a5cae93a 100644--- a/desktop/src/panels/Viewport.tsx+++ b/desktop/src/panels/Viewport.tsx@@ -16,7 +16,7 @@ import { useTilemapPaint, type PaintTool } from '@/store/tilemapPaintStore';import { exitTilePaint, isTilePaintMode, selectedTilemapCellSize } from '@/tools/tileMode';import { activeMode, activeModeOverlays } from '@/mode/activeMode';import { useEditorMode } from '@/store/editorModeStore';-import { RESOLUTION_PRESET_BY_ID, DESIGN_RESOLUTION_PRESETS, deviceDims } from '@/mode/resolutionPresets';+import { screenPresetById, DESIGN_RESOLUTION_PRESETS, deviceDims } from '@/mode/resolutionPresets';import { buildStampGhost } from '@/tools/tileStampGhost';import { alignSelection, distributeSelection } from '@/tools/alignTools';import { TilemapAPI, tileIdOf, isNonOrthogonal, isCollisionPaletteRef, buildCollisionPaletteModel, UINode, DimensionUnit, computeEffectiveOrthoSize, type TileCollisionPiece, type TilesetModel } from 'esengine';@@ -1109,12 +1109,12 @@ export function Viewport() {if (ci && des) {dsvg.style.opacity = '1';const ms = useEditorMode.getState();- const preset = RESOLUTION_PRESET_BY_ID[ms.device];+ const preset = screenPresetById(ms.device, ProjectStore.getSnapshot()?.screenPresets);// Device visible frame: the design resolution fit into the simulated device's// aspect per the Canvas scaleMode. `dd` is the oriented device size (null for the// 'design' sentinel) — the SAME source App.tsx feeds to uiLayoutRect, so this// frame and the actual UI layout share one aspect and can't drift.- const dd = deviceDims(ms.device, ms.orientation);+ const dd = deviceDims(ms.device, ms.orientation, ProjectStore.getSnapshot()?.screenPresets);let dev = des;if (dd) {const deviceAspect = dd.w / dd.h;@@ -2412,7 +2412,7 @@ export function Viewport() {<div className="viewport__play-stage"><divclassName="viewport__play-host"- style={playHostAspectStyle(device, orientation) ?? undefined}+ style={playHostAspectStyle(device, orientation, projectState?.screenPresets) ?? undefined}ref={playHostRef}/></div>diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.tsindex efb298663..0b9f47ac6 100644--- a/desktop/src/project/ProjectStore.ts+++ b/desktop/src/project/ProjectStore.ts@@ -36,7 +36,7 @@ import { t } from '@/i18n';import { assetTypeOf } from '@/project/assetMeta';import { ASSET_SLOTS, metaTypeToSlot } from '@/project/assetSlots';import type { AssetType } from '@/types';-import { resolveLayout, orientationFromDesignResolution, resolveOrientation, cameraScaleModeValue, WORKSPACE_DIR, PROJECT_MANIFEST_FILE, type OpenedProject, type ProjectFeatures, type ProjectLayout, type ProjectPackaging, type WorkspaceState, type DesignResolution, type ScreenOrientation, type CameraScaleMode, type ExportPlatform } from './format';+import { resolveLayout, orientationFromDesignResolution, resolveOrientation, cameraScaleModeValue, WORKSPACE_DIR, PROJECT_MANIFEST_FILE, type OpenedProject, type ProjectFeatures, type ProjectLayout, type ProjectPackaging, type WorkspaceState, type DesignResolution, type ScreenPreset, type ScreenOrientation, type CameraScaleMode, type ExportPlatform } from './format';import { useEditorMode } from '@/store/editorModeStore';import { PlayRealms } from '@/engine/PlayRealm';import { PlayInspect } from '@/engine/PlayInspect';@@ -126,6 +126,8 @@ interface ProjectState {packaging?: ProjectPackaging;/** Reference resolution new Canvas entities seed from; per-scene Canvas stays authoritative. */designResolution?: DesignResolution;+ /** Project-declared screens the target-screen dropdown offers beside the built-ins. */+ screenPresets?: ScreenPreset[];/** The scene currently loaded into the world (project-relative path). */currentScene: string | null;/** When editing a PREFAB asset in place (Prefab Mode) rather than a scene:@@ -431,6 +433,7 @@ class ProjectStoreImpl {features: opened.manifest.features,packaging: opened.manifest.packaging,designResolution: opened.manifest.designResolution,+ screenPresets: opened.manifest.screenPresets,currentScene: null,},});diff --git a/desktop/src/project/format.ts b/desktop/src/project/format.tsindex 5903de4ea..ffe8b9cc2 100644--- a/desktop/src/project/format.ts+++ b/desktop/src/project/format.ts@@ -45,6 +45,26 @@ export interface DesignResolution {height: number;}+/**+ * A screen the project cares about testing on, shown in the viewport/Game+ * target-screen dropdown alongside the built-in devices.+ *+ * Which handsets a team ships to is a property of the PROJECT, not of the+ * editor: a built-in list can only ever be a guess, and a guess that cannot be+ * corrected means everyone tests on approximately the wrong screen. Dimensions+ * are stored portrait (w ≤ h) like the built-ins, so the orientation toggle+ * means the same thing for both.+ */+export interface ScreenPreset {+ /** Stable id — what the editor's device selection persists. */+ id: string;+ label: string;+ width: number;+ height: number;+ /** Safe-area insets in device pixels (notch / home indicator), if any. */+ safe?: { top: number; bottom: number; left: number; right: number };+}+/*** Script entry points. Splitting declaration from* startup is what lets the editor extract a component schema WITHOUT executing@@ -244,6 +264,8 @@ export interface ProjectManifest {defaultScene?: string;/** Design resolution for the viewport / camera. */designResolution?: DesignResolution;+ /** Extra screens the target-screen dropdown offers, beside the built-in devices. */+ screenPresets?: ScreenPreset[];/** Spine runtime the project needs ('none' | '2.1' | '3.8' | '4.1' | '4.2' | '4.3' …). */spineVersion?: string;/** Per-path overrides of {@link DEFAULT_LAYOUT}. */@@ -346,6 +368,21 @@ export function parseManifest(raw: unknown): ProjectManifest {if (dr && typeof dr.width === 'number' && typeof dr.height === 'number') {manifest.designResolution = { width: dr.width, height: dr.height };}+ if (Array.isArray(o.screenPresets)) {+ // Hand-edited manifests are normal, so a malformed entry is dropped rather+ // than failing the load — a bad preset must not cost you the project.+ const presets = (o.screenPresets as unknown[]).flatMap((raw) => {+ const p = raw as Partial<ScreenPreset> | null;+ if (!p || typeof p.id !== 'string' || typeof p.label !== 'string') return [];+ if (typeof p.width !== 'number' || typeof p.height !== 'number') return [];+ if (!(p.width > 0) || !(p.height > 0)) return [];+ const out: ScreenPreset = { id: p.id, label: p.label, width: p.width, height: p.height };+ const s = p.safe;+ if (s && [s.top, s.bottom, s.left, s.right].every((n) => typeof n === 'number')) out.safe = s;+ return [out];+ });+ if (presets.length > 0) manifest.screenPresets = presets;+ }if (o.layout && typeof o.layout === 'object') {manifest.layout = o.layout as Partial<ProjectLayout>;}diff --git a/desktop/src/store/editorModeStore.ts b/desktop/src/store/editorModeStore.tsindex 7fd82af2a..232e950b1 100644--- a/desktop/src/store/editorModeStore.ts+++ b/desktop/src/store/editorModeStore.ts@@ -8,18 +8,18 @@*/import { create } from 'zustand';import type { EditorModeId } from '@/mode/editorModes';-import type { DevicePresetId } from '@/mode/resolutionPresets';interface EditorModeState {/** Explicit mode override; null ⇒ follow the selection-suggested mode. */pinned: EditorModeId | null;- /** Simulated target device for the design-resolution preview ('design' = no letterbox). */- device: DevicePresetId;+ /** Simulated target screen ('design' = no letterbox). A project may declare its+ * own presets, so this is any id the preset table resolves — not a closed set. */+ device: string;orientation: 'portrait' | 'landscape';showSafeArea: boolean;setMode(id: EditorModeId): void;clearPin(): void;- setDevice(id: DevicePresetId): void;+ setDevice(id: string): void;toggleOrientation(): void;toggleSafeArea(): void;}diff --git a/desktop/src/theme/viewport.css b/desktop/src/theme/viewport.cssindex ff1e5ce8d..b04293567 100644--- a/desktop/src/theme/viewport.css+++ b/desktop/src/theme/viewport.css@@ -160,6 +160,11 @@}.ovmenu-item.on .chk { background: var(--acc); border-color: var(--acc); color: var(--on-accent); }.ovmenu-item .l { flex: 1; }+/* A choice that exists but cannot act yet — kept in place (the menu must not+ reflow) and visibly inert, with a title saying what would enable it. */+.ovmenu-item.disabled { opacity: 0.38; cursor: default; }+.ovmenu-item.disabled:hover { color: var(--text-dim); background: none; }+.ovmenu-note { padding: 2px 8px 6px; color: var(--text-mute); font-size: var(--fs-2xs); line-height: 1.4; max-width: 210px; }/* UI resize gizmo: accent edge/corner handles laid over a selected UINode's screenrect. Container is inert; only the handles take pointer events. */diff --git a/desktop/tests/target-screen.test.ts b/desktop/tests/target-screen.test.tsindex e2ef000ed..6e2860773 100644--- a/desktop/tests/target-screen.test.ts+++ b/desktop/tests/target-screen.test.ts@@ -10,7 +10,8 @@*/import { describe, it, expect } from 'vitest';import { playHostAspectStyle, targetScreenLabel } from '@/mode/TargetScreen';-import { deviceDims } from '@/mode/resolutionPresets';+import { deviceDims, screenPresets, screenPresetById, RESOLUTION_PRESETS } from '@/mode/resolutionPresets';+import { parseManifest } from '@/project/format';describe('play host sizing', () => {it('leaves the host unconstrained for the `design` sentinel', () => {@@ -49,3 +50,73 @@ describe('play host sizing', () => {}});});++describe('project-declared screens', () => {+ const project = [+ { id: 'studio-tablet', label: 'Studio Tablet', width: 1200, height: 1920 },+ // Same id as a built-in: the project MEANS something specific by it.+ { id: 'iphone', label: 'iPhone 15 Pro', width: 1179, height: 2556 },+ ];++ it('offers the project screens beside the built-ins', () => {+ const ids = screenPresets(project).map((p) => p.id);+ expect(ids).toContain('studio-tablet');+ expect(ids).toContain('design');+ expect(ids).toContain('720p');+ });++ it('lets a project redefine a built-in id rather than duplicating it', () => {+ const ids = screenPresets(project).map((p) => p.id);+ expect(ids.filter((id) => id === 'iphone')).toHaveLength(1);+ expect(screenPresetById('iphone', project).label).toBe('iPhone 15 Pro');+ expect(deviceDims('iphone', 'portrait', project)).toEqual({ w: 1179, h: 2556 });+ });++ it('sizes the play host from a project screen', () => {+ expect(playHostAspectStyle('studio-tablet', 'portrait', project)?.aspectRatio).toBe('1200 / 1920');+ expect(targetScreenLabel('studio-tablet', 'landscape', project)).toBe('1920 × 1200');+ });++ it('falls back to the design sentinel for an id nothing declares', () => {+ // A selection persisted before a preset was deleted must not size the host+ // from a screen that no longer exists.+ expect(screenPresetById('deleted-device', project).id).toBe('design');+ expect(playHostAspectStyle('deleted-device', 'portrait', project)).toBeNull();+ });++ it('is untouched when the project declares none', () => {+ expect(screenPresets()).toBe(RESOLUTION_PRESETS);+ expect(screenPresets([])).toBe(RESOLUTION_PRESETS);+ });+});++describe('manifest parsing of screenPresets', () => {+ const parse = (presets: unknown): unknown =>+ parseManifest({ formatVersion: '1', name: 'p', screenPresets: presets }).screenPresets;++ it('keeps well-formed entries', () => {+ expect(parse([{ id: 'a', label: 'A', width: 800, height: 1200 }]))+ .toEqual([{ id: 'a', label: 'A', width: 800, height: 1200 }]);+ });++ it('drops malformed entries rather than failing the project load', () => {+ // Hand-edited manifests are normal; one bad preset must not cost the project.+ expect(parse([+ { id: 'ok', label: 'OK', width: 800, height: 1200 },+ { id: 'no-size', label: 'X' },+ { label: 'no-id', width: 1, height: 2 },+ { id: 'zero', label: 'Z', width: 0, height: 100 },+ null,+ ])).toEqual([{ id: 'ok', label: 'OK', width: 800, height: 1200 }]);+ });++ it('carries safe-area insets only when complete', () => {+ const safe = { top: 44, bottom: 34, left: 0, right: 0 };+ expect(parse([{ id: 'a', label: 'A', width: 8, height: 9, safe }])).toEqual([+ { id: 'a', label: 'A', width: 8, height: 9, safe },+ ]);+ expect(parse([{ id: 'a', label: 'A', width: 8, height: 9, safe: { top: 44 } }])).toEqual([+ { id: 'a', label: 'A', width: 8, height: 9 },+ ]);+ });+});