generated from gxc-solutions/gxc-template-repo
Added color parse and color interfaces
This commit is contained in:
parent
7742cc7a83
commit
5d1acba69c
7 changed files with 35 additions and 6 deletions
|
|
@ -1,13 +1,16 @@
|
|||
import { _switch } from "@gxc-solutions/lett-js";
|
||||
import {
|
||||
ColorType,
|
||||
FillType,
|
||||
GradientType,
|
||||
IBaseFill,
|
||||
IColor,
|
||||
IEllipseModel,
|
||||
IImageModel,
|
||||
IModel,
|
||||
IRectangle,
|
||||
IRectangleModel,
|
||||
IRgbColor,
|
||||
ISolidFill,
|
||||
IStroke,
|
||||
ITransform,
|
||||
|
|
@ -19,6 +22,7 @@ import { Stroke } from "./models/stroke";
|
|||
import { SolidFill } from "./models/solid-fill";
|
||||
import { Ellipse, Rectangle, Transform } from "@gxc-solutions/math";
|
||||
import { RectangleItem } from "./models/objects/rectangle";
|
||||
import { RgbColor } from "@gxc-solutions/colors";
|
||||
|
||||
export class Parser {
|
||||
constructor() {}
|
||||
|
|
@ -74,14 +78,25 @@ export class Parser {
|
|||
}
|
||||
|
||||
parseStroke(strokeObj: IStroke) {
|
||||
return new Stroke(strokeObj.width, strokeObj.color, strokeObj.dash);
|
||||
const color = this.parseColor(strokeObj.color);
|
||||
return new Stroke(strokeObj.width, color, strokeObj.dash);
|
||||
}
|
||||
|
||||
parseFill(fillObj: IBaseFill) {
|
||||
return _switch<GradientType | FillType, SolidFill>(fillObj.type)
|
||||
.case("solid", () => {
|
||||
const solidFillObj = fillObj as ISolidFill;
|
||||
return new SolidFill(solidFillObj.color);
|
||||
const color = this.parseColor(solidFillObj.color);
|
||||
return new SolidFill(color);
|
||||
})
|
||||
.result();
|
||||
}
|
||||
|
||||
parseColor(colorObj: IColor) {
|
||||
return _switch<ColorType, RgbColor>(colorObj.type)
|
||||
.case("rgb", () => {
|
||||
const { a, b, g, r } = colorObj as IRgbColor;
|
||||
return new RgbColor(r, g, b, a);
|
||||
})
|
||||
.result();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue