import BarComponent from "@/components/features/Bar.vue"; import { CoercableComponent, Component, getUniqueID, Replace, setDefault, StyleValue, Visibility } from "@/features/feature"; import { DecimalSource } from "@/lib/break_eternity"; import { Computable, GetComputableType, GetComputableTypeWithDefault, processComputable, ProcessedComputable } from "@/util/computed"; import { createProxy } from "@/util/proxies"; export const BarType = Symbol("Bar"); export enum Direction { Up = "Up", Down = "Down", Left = "Left", Right = "Right", Default = "Up" } 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; } interface BaseBar { id: string; type: typeof BarType; [Component]: typeof BarComponent; } 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(options: T & ThisType>): Bar { const bar: T & Partial = options; 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"); const proxy = createProxy(bar as unknown as Bar); return proxy; }