import Node from '../Node'; import Input from './Input'; import Output from './Output'; import AbstractIO from './AbstractIO'; type ImageType = HTMLCanvasElement | OffscreenCanvas | HTMLImageElement | HTMLVideoElement | ImageData | ImageBitmap; export interface NumberVar { type: 'Number', min?: number max?: number step?: number default?: VariableValueType } export interface StringVar { type: 'String', default?: VariableValueType enum?: string[] } export interface BooleanVar { type: 'Boolean', default?: VariableValueType } export interface ColorVar { type: 'Color', default?: VariableValueType } export interface FontVar { type: 'Font', default?: VariableValueType } export interface ImageVar { type: 'Image' default?: VariableValueType } export type Variable = NumberVar | StringVar | BooleanVar | ColorVar | FontVar | ImageVar export interface Variables { [key: string]: Variable } export type VariablesType = { [K in keyof V]: V[K] extends Variable ? V[K] : never }; export type VariableValueType = T extends NumberVar ? number : T extends BooleanVar ? boolean : T extends ImageVar ? ImageType : string export type IOProperties = { [K in keyof V]: AbstractIO } export type InputProperties = { [K in keyof V]: Input } export type OutputProperties = { [K in keyof V]: Output } export default class AbstractIOSet { __values: any __owner: Node variables: V constructor(variables: V, owner: Node) { this.__values = {}; this.__owner = owner; this.variables = variables; for (let name of Object.keys(this.variables)) { if (variables[name] === null) { delete this.variables[name]; continue; } this.__values[name] = this.__createProperty(name, variables[name]); Object.defineProperty(this, name, { get() { return this.__values[name]; }, }) } } get id() { return `${this.__owner.id}-set`; } *[Symbol.iterator]() { for (let name of Object.keys(this.variables)) { yield this.__values[name]; } } __createProperty(name, definition) { } update(changed) { } }