2022-03-04 03:39:48 +00:00
|
|
|
import BarComponent from "features/bars/Bar.vue";
|
2022-01-14 04:25:47 +00:00
|
|
|
import {
|
|
|
|
CoercableComponent,
|
|
|
|
Component,
|
2022-04-11 00:04:56 +00:00
|
|
|
OptionsFunc,
|
2022-02-27 19:49:34 +00:00
|
|
|
GatherProps,
|
2022-01-14 04:25:47 +00:00
|
|
|
getUniqueID,
|
|
|
|
Replace,
|
|
|
|
setDefault,
|
|
|
|
StyleValue,
|
|
|
|
Visibility
|
2022-03-04 03:39:48 +00:00
|
|
|
} from "features/feature";
|
2022-03-11 20:02:41 +00:00
|
|
|
import { DecimalSource } from "util/bignum";
|
2022-05-01 03:08:29 +00:00
|
|
|
import { Direction } from "util/common";
|
2022-01-14 04:25:47 +00:00
|
|
|
import {
|
|
|
|
Computable,
|
|
|
|
GetComputableType,
|
|
|
|
GetComputableTypeWithDefault,
|
|
|
|
processComputable,
|
|
|
|
ProcessedComputable
|
2022-03-04 03:39:48 +00:00
|
|
|
} from "util/computed";
|
|
|
|
import { createLazyProxy } from "util/proxies";
|
2022-03-13 22:09:09 +00:00
|
|
|
import { unref } from "vue";
|
2022-01-14 04:25:47 +00:00
|
|
|
|
|
|
|
export const BarType = Symbol("Bar");
|
|
|
|
|
|
|
|
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>;
|
|
|
|
}
|
|
|
|
|
2022-03-09 01:40:51 +00:00
|
|
|
export interface BaseBar {
|
2022-01-14 04:25:47 +00:00
|
|
|
id: string;
|
|
|
|
type: typeof BarType;
|
|
|
|
[Component]: typeof BarComponent;
|
2022-02-27 19:49:34 +00:00
|
|
|
[GatherProps]: () => Record<string, unknown>;
|
2022-01-14 04:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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>;
|
|
|
|
}
|
|
|
|
>;
|
|
|
|
|
2022-05-24 04:34:59 +00:00
|
|
|
export function createBar<T extends BarOptions>(optionsFunc: OptionsFunc<T, BaseBar>): Bar<T> {
|
2022-02-27 19:49:34 +00:00
|
|
|
return createLazyProxy(() => {
|
2022-04-11 00:04:56 +00:00
|
|
|
const bar = optionsFunc();
|
2022-02-27 19:49:34 +00:00
|
|
|
bar.id = getUniqueID("bar-");
|
|
|
|
bar.type = BarType;
|
|
|
|
bar[Component] = BarComponent;
|
2022-01-14 04:25:47 +00:00
|
|
|
|
2022-02-27 19:49:34 +00:00
|
|
|
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-14 04:25:47 +00:00
|
|
|
|
2022-02-27 19:49:34 +00:00
|
|
|
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,
|
2022-03-13 22:09:09 +00:00
|
|
|
style: unref(style),
|
2022-02-27 19:49:34 +00:00
|
|
|
classes,
|
|
|
|
borderStyle,
|
|
|
|
textStyle,
|
|
|
|
baseStyle,
|
|
|
|
fillStyle,
|
|
|
|
mark,
|
|
|
|
id
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
return bar as unknown as Bar<T>;
|
|
|
|
});
|
2022-01-14 04:25:47 +00:00
|
|
|
}
|