import type { ExpressionSource } from '@cloudpss/expression'; import type { ArgumentMap, Variable } from '@cloudpss/expression/definitions'; import type { Tagged } from 'type-fest'; /** 场景 ID */ export type SceneId = Tagged; /** 场景 key */ export type SceneKey = Tagged; /** 控件定义 ID */ export type ElementStencilId = Tagged; /** * 场景元素 */ export interface Widget { /** 元素 ID */ id: string; /** 元素 Key */ key: string; /** 定义 */ definition: ElementStencilId; /** 图形 */ shape: 'element'; /** 控件属性 */ properties: ArgumentMap; /** 事件 */ events: Record>; } /** 背景图像适应类型 */ export const BackgroundFit = Object.freeze(['fill', 'fit', 'stretch', 'tile', 'center'] as const); /** 背景图像适应类型 */ export type BackgroundFit = (typeof BackgroundFit)[number]; /** 背景 */ export interface Background { /** 背景颜色 */ color?: string; /** 背景图像 */ image?: string; /** 背景图像适应类型 */ imageFit?: BackgroundFit; } /** 主题 */ // eslint-disable-next-line @typescript-eslint/no-empty-object-type export interface SceneTheme {} /** 场景 */ export interface Scene { /** 场景 ID */ id: SceneId; /** 场景key */ key: SceneKey; /** 场景尺寸 */ size: { width: number; height: number; }; /** 场景背景 */ background: Background; /** 场景主题 */ theme: SceneTheme; /** 场景是否在主舞台显示 */ hidden?: boolean; /** 场景元素 */ cells: Record; /** 场景变量 */ variables?: Variable[]; } /** 检查是否为场景 */ export function isScene(value: unknown): value is Scene { if (!value || typeof value != 'object') return false; const item = value as Scene; return ( typeof item.id == 'string' && typeof item.key == 'string' && typeof item.cells == 'object' && typeof item.background == 'object' && typeof item.size == 'object' && (item.variables == null || Array.isArray(item.variables)) ); }