import BarComponent from "features/bars/Bar.vue"; import { CoercableComponent, Component, OptionsFunc, GatherProps, getUniqueID, Replace, setDefault, StyleValue, Visibility } from "features/feature"; import { DecimalSource } from "util/bignum"; import { Direction } from "util/common"; import { Computable, GetComputableType, GetComputableTypeWithDefault, processComputable, ProcessedComputable } from "util/computed"; import { createLazyProxy } from "util/proxies"; import { unref } from "vue"; export const BarType = Symbol("Bar"); export interface BarOptions { visibility?: Computable; width: Computable; height: Computable; direction: Computable; style?: Computable; classes?: Computable>; borderStyle?: Computable; baseStyle?: Computable; textStyle?: Computable; fillStyle?: Computable; progress: Computable; display?: Computable; mark?: Computable; } export interface BaseBar { id: string; type: typeof BarType; [Component]: typeof BarComponent; [GatherProps]: () => Record; } export type Bar = Replace< T & BaseBar, { visibility: GetComputableTypeWithDefault; width: GetComputableType; height: GetComputableType; direction: GetComputableType; style: GetComputableType; classes: GetComputableType; borderStyle: GetComputableType; baseStyle: GetComputableType; textStyle: GetComputableType; fillStyle: GetComputableType; progress: GetComputableType; display: GetComputableType; mark: GetComputableType; } >; export type GenericBar = Replace< Bar, { visibility: ProcessedComputable; } >; export function createBar(optionsFunc: OptionsFunc): Bar { return createLazyProxy(() => { const bar = optionsFunc(); bar.id = getUniqueID("bar-"); bar.type = BarType; bar[Component] = BarComponent; processComputable(bar as T, "visibility"); setDefault(bar, "visibility", Visibility.Visible); processComputable(bar as T, "width"); processComputable(bar as T, "height"); processComputable(bar as T, "direction"); processComputable(bar as T, "style"); processComputable(bar as T, "classes"); processComputable(bar as T, "borderStyle"); processComputable(bar as T, "baseStyle"); processComputable(bar as T, "textStyle"); processComputable(bar as T, "fillStyle"); processComputable(bar as T, "progress"); processComputable(bar as T, "display"); processComputable(bar as T, "mark"); bar[GatherProps] = function (this: GenericBar) { const { progress, width, height, direction, display, visibility, style, classes, borderStyle, textStyle, baseStyle, fillStyle, mark, id } = this; return { progress, width, height, direction, display, visibility, style: unref(style), classes, borderStyle, textStyle, baseStyle, fillStyle, mark, id }; }; return bar as unknown as Bar; }); }