2022-01-14 04:25:47 +00:00
|
|
|
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<Visibility>;
|
|
|
|
width: Computable<number>;
|
|
|
|
height: Computable<number>;
|
|
|
|
direction: Computable<Direction>;
|
|
|
|
style?: Computable<StyleValue>;
|
|
|
|
classes?: Computable<Record<string, boolean>>;
|
|
|
|
borderStyle?: Computable<StyleValue>;
|
|
|
|
baseStyle?: Computable<StyleValue>;
|
|
|
|
textStyle?: Computable<StyleValue>;
|
|
|
|
fillStyle?: Computable<StyleValue>;
|
|
|
|
progress: Computable<DecimalSource>;
|
|
|
|
display?: Computable<CoercableComponent>;
|
|
|
|
mark?: Computable<boolean | string>;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface BaseBar {
|
|
|
|
id: string;
|
|
|
|
type: typeof BarType;
|
|
|
|
[Component]: typeof BarComponent;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type Bar<T extends BarOptions> = Replace<
|
|
|
|
T & BaseBar,
|
|
|
|
{
|
|
|
|
visibility: GetComputableTypeWithDefault<T["visibility"], Visibility.Visible>;
|
|
|
|
width: GetComputableType<T["width"]>;
|
|
|
|
height: GetComputableType<T["height"]>;
|
|
|
|
direction: GetComputableType<T["direction"]>;
|
|
|
|
style: GetComputableType<T["style"]>;
|
|
|
|
classes: GetComputableType<T["classes"]>;
|
|
|
|
borderStyle: GetComputableType<T["borderStyle"]>;
|
|
|
|
baseStyle: GetComputableType<T["baseStyle"]>;
|
|
|
|
textStyle: GetComputableType<T["textStyle"]>;
|
|
|
|
fillStyle: GetComputableType<T["fillStyle"]>;
|
|
|
|
progress: GetComputableType<T["progress"]>;
|
|
|
|
display: GetComputableType<T["display"]>;
|
|
|
|
mark: GetComputableType<T["mark"]>;
|
|
|
|
}
|
|
|
|
>;
|
|
|
|
|
|
|
|
export type GenericBar = Replace<
|
|
|
|
Bar<BarOptions>,
|
|
|
|
{
|
|
|
|
visibility: ProcessedComputable<Visibility>;
|
|
|
|
}
|
|
|
|
>;
|
|
|
|
|
|
|
|
export function createBar<T extends BarOptions>(options: T & ThisType<Bar<T>>): Bar<T> {
|
|
|
|
const bar: T & Partial<BaseBar> = 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");
|
|
|
|
|
2022-01-25 04:23:30 +00:00
|
|
|
const proxy = createProxy(bar as unknown as Bar<T>);
|
2022-01-14 04:25:47 +00:00
|
|
|
return proxy;
|
|
|
|
}
|