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
13
lib/src/interfaces/color.ts
Normal file
13
lib/src/interfaces/color.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
export type ColorType = "rgb";
|
||||||
|
|
||||||
|
export interface IColor {
|
||||||
|
type: ColorType;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IRgbColor extends IColor {
|
||||||
|
type: "rgb";
|
||||||
|
r: number;
|
||||||
|
g: number;
|
||||||
|
b: number;
|
||||||
|
a: number;
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { IColor } from "@gxc-solutions/colors";
|
import { IColor } from "./color";
|
||||||
|
|
||||||
export type FillType = "solid" | "texture";
|
export type FillType = "solid" | "texture";
|
||||||
export type GradientType = "liner" | "radial" | "conic";
|
export type GradientType = "liner" | "radial" | "conic";
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
export * from "./fill";
|
export * from "./fill";
|
||||||
export * from "./models";
|
export * from "./models";
|
||||||
export * from "./stroke";
|
export * from "./stroke";
|
||||||
|
export * from "./color";
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { UUID_V4 } from "@gxc-solutions/lett-js";
|
import { UUID_V4 } from "@gxc-solutions/lett-js";
|
||||||
|
import { IPoint } from "@gxc-solutions/math";
|
||||||
import { ISolidFill } from "./fill";
|
import { ISolidFill } from "./fill";
|
||||||
import { IStroke } from "./stroke";
|
import { IStroke } from "./stroke";
|
||||||
import { IPoint } from "@gxc-solutions/math";
|
|
||||||
|
|
||||||
export type ModelConstructor = new (...args: any[]) => IModel;
|
export type ModelConstructor = new (...args: any[]) => IModel;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { IColor } from "@gxc-solutions/colors";
|
import { IColor } from "./color";
|
||||||
|
|
||||||
export interface IStroke {
|
export interface IStroke {
|
||||||
width: number;
|
width: number;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@gxc-solutions/model-base",
|
"name": "@gxc-solutions/model-base",
|
||||||
"version": "0.0.2",
|
"version": "0.0.3",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "GXC Solutions",
|
"author": "GXC Solutions",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
import { _switch } from "@gxc-solutions/lett-js";
|
import { _switch } from "@gxc-solutions/lett-js";
|
||||||
import {
|
import {
|
||||||
|
ColorType,
|
||||||
FillType,
|
FillType,
|
||||||
GradientType,
|
GradientType,
|
||||||
IBaseFill,
|
IBaseFill,
|
||||||
|
IColor,
|
||||||
IEllipseModel,
|
IEllipseModel,
|
||||||
IImageModel,
|
IImageModel,
|
||||||
IModel,
|
IModel,
|
||||||
IRectangle,
|
IRectangle,
|
||||||
IRectangleModel,
|
IRectangleModel,
|
||||||
|
IRgbColor,
|
||||||
ISolidFill,
|
ISolidFill,
|
||||||
IStroke,
|
IStroke,
|
||||||
ITransform,
|
ITransform,
|
||||||
|
|
@ -19,6 +22,7 @@ import { Stroke } from "./models/stroke";
|
||||||
import { SolidFill } from "./models/solid-fill";
|
import { SolidFill } from "./models/solid-fill";
|
||||||
import { Ellipse, Rectangle, Transform } from "@gxc-solutions/math";
|
import { Ellipse, Rectangle, Transform } from "@gxc-solutions/math";
|
||||||
import { RectangleItem } from "./models/objects/rectangle";
|
import { RectangleItem } from "./models/objects/rectangle";
|
||||||
|
import { RgbColor } from "@gxc-solutions/colors";
|
||||||
|
|
||||||
export class Parser {
|
export class Parser {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
@ -74,14 +78,25 @@ export class Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
parseStroke(strokeObj: IStroke) {
|
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) {
|
parseFill(fillObj: IBaseFill) {
|
||||||
return _switch<GradientType | FillType, SolidFill>(fillObj.type)
|
return _switch<GradientType | FillType, SolidFill>(fillObj.type)
|
||||||
.case("solid", () => {
|
.case("solid", () => {
|
||||||
const solidFillObj = fillObj as ISolidFill;
|
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();
|
.result();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue