import { isToolcraftBuiltInControlType, type ToolcraftBuiltInControlType } from "../contracts/component-contracts"; import type { ToolcraftCanvasAspectRatioValue } from "../state/canvas-state"; import type { ToolcraftCollectionControlFields } from "./control-schema-collections"; import type { DistributiveOmit, StrictControlUnion, ToolcraftControlSchemaBase } from "./control-schema-common"; import type { ToolcraftCompoundControlFields } from "./control-schema-compounds"; import type { ToolcraftInputControlFields } from "./control-schema-inputs"; import type { ToolcraftCustomControlType } from "./custom-control-type"; import type { ToolcraftActionSchema, ToolcraftMediaAssetKind, ToolcraftModelFormat, ToolcraftModelImportLimits, ToolcraftModelTopologyProfile, ToolcraftResolvedControlApplicabilitySchema } from "./types"; type ActionFields = { actions?: readonly (ToolcraftActionSchema | string)[]; /** Legacy empty authoring placeholder; actions never own a state value. */ defaultValue?: readonly never[] | null; }; type BuiltInFields = Omit & ToolcraftCompoundControlFields & ToolcraftCollectionControlFields & { text: ToolcraftInputControlFields["text"] | (Omit & { defaultValue?: number; target: "canvas.size.width" | "canvas.size.height"; }); actions: ActionFields; panelActions: ActionFields; settingsTransfer: Record; aspectRatio: { defaultValue?: string | ToolcraftCanvasAspectRatioValue }; }; /** Indexing every registry key makes omitted built-ins a compiler error. */ type BuiltInBranches = { [K in ToolcraftBuiltInControlType]: ToolcraftControlSchemaBase & BuiltInFields[K] & { type: K }; }[ToolcraftBuiltInControlType]; type CustomBranch = ToolcraftControlSchemaBase & { assetKind?: ToolcraftMediaAssetKind; defaultValue?: unknown; /** Optional numeric workload domain used by existing performance contracts. */ max?: number; min?: number; multiple?: boolean; type: ToolcraftCustomControlType; }; export type ToolcraftControlSchema = StrictControlUnion; export type ToolcraftBuiltInControlSchema = Extract; export type ToolcraftCustomControlSchema = Extract; export type ToolcraftModelFileDropSchema = Extract; export type ToolcraftNonModelControlSchema = Exclude; type ResolvedApplicability = DistributiveOmit & { applicability: ToolcraftResolvedControlApplicabilitySchema; }; export type ResolvedToolcraftNonModelControlSchema = ResolvedApplicability; export type ResolvedToolcraftModelFileDropSchema = ResolvedApplicability> & { modelFormats: readonly ToolcraftModelFormat[]; modelLimits: ToolcraftModelImportLimits; multiple: false; topologyProfile: ToolcraftModelTopologyProfile; }; export type ResolvedToolcraftControlSchema = ResolvedToolcraftNonModelControlSchema | ResolvedToolcraftModelFileDropSchema; /** Nominal custom strings cannot be narrowed by string equality alone in TypeScript. */ export function isToolcraftBuiltInControlSchema( control: T, ): control is Extract { return isToolcraftBuiltInControlType(control.type); }