export interface Constructor { new(...args: any[]): T; } export interface Properties { toCanvasValue(value: T): number | string | boolean | CanvasGradient | CanvasPattern | CanvasDirection | ImageSmoothingQuality; clone(value: T): T; } export function customStyles() { const styles = new Map, Properties<{}>>(); return class CustomStyles { static register(constructor: Constructor, properties: Properties) { styles.set(constructor, properties); return this; } static get(value: T) { return styles.get(value.constructor as Constructor) as Properties | undefined; } static toCanvasValue(value: T) { const properties = CustomStyles.get(value); if (properties === undefined) return value; return properties.toCanvasValue(value); } static clone(value: T) { const properties = CustomStyles.get(value); if (properties === undefined) return value; return properties.clone(value); } }; } export type CustomStyles = ReturnType;