From 5d1acba69cc954b37623ebd392e13ce32ed9e0d5 Mon Sep 17 00:00:00 2001 From: Andrey Kernichniy Date: Sat, 14 Mar 2026 17:26:04 +0700 Subject: [PATCH] Release package version 0.0.3 Added color parse and color interfaces --- lib/src/interfaces/color.ts | 13 +++++++++++++ lib/src/interfaces/fill.ts | 2 +- lib/src/interfaces/index.ts | 1 + lib/src/interfaces/models.ts | 2 +- lib/src/interfaces/stroke.ts | 2 +- lib/src/package.json | 2 +- lib/src/parser.ts | 19 +++++++++++++++++-- 7 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 lib/src/interfaces/color.ts diff --git a/lib/src/interfaces/color.ts b/lib/src/interfaces/color.ts new file mode 100644 index 0000000..36a9509 --- /dev/null +++ b/lib/src/interfaces/color.ts @@ -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; +} diff --git a/lib/src/interfaces/fill.ts b/lib/src/interfaces/fill.ts index 957b5fc..46a8ec8 100644 --- a/lib/src/interfaces/fill.ts +++ b/lib/src/interfaces/fill.ts @@ -1,4 +1,4 @@ -import { IColor } from "@gxc-solutions/colors"; +import { IColor } from "./color"; export type FillType = "solid" | "texture"; export type GradientType = "liner" | "radial" | "conic"; diff --git a/lib/src/interfaces/index.ts b/lib/src/interfaces/index.ts index 347be64..282919d 100644 --- a/lib/src/interfaces/index.ts +++ b/lib/src/interfaces/index.ts @@ -1,3 +1,4 @@ export * from "./fill"; export * from "./models"; export * from "./stroke"; +export * from "./color"; diff --git a/lib/src/interfaces/models.ts b/lib/src/interfaces/models.ts index 534d83a..818a713 100644 --- a/lib/src/interfaces/models.ts +++ b/lib/src/interfaces/models.ts @@ -1,7 +1,7 @@ import { UUID_V4 } from "@gxc-solutions/lett-js"; +import { IPoint } from "@gxc-solutions/math"; import { ISolidFill } from "./fill"; import { IStroke } from "./stroke"; -import { IPoint } from "@gxc-solutions/math"; export type ModelConstructor = new (...args: any[]) => IModel; diff --git a/lib/src/interfaces/stroke.ts b/lib/src/interfaces/stroke.ts index d6b8476..324fb9e 100644 --- a/lib/src/interfaces/stroke.ts +++ b/lib/src/interfaces/stroke.ts @@ -1,4 +1,4 @@ -import { IColor } from "@gxc-solutions/colors"; +import { IColor } from "./color"; export interface IStroke { width: number; diff --git a/lib/src/package.json b/lib/src/package.json index f664772..8fc3248 100644 --- a/lib/src/package.json +++ b/lib/src/package.json @@ -1,6 +1,6 @@ { "name": "@gxc-solutions/model-base", - "version": "0.0.2", + "version": "0.0.3", "main": "index.js", "author": "GXC Solutions", "publishConfig": { diff --git a/lib/src/parser.ts b/lib/src/parser.ts index ed0169b..366b39e 100644 --- a/lib/src/parser.ts +++ b/lib/src/parser.ts @@ -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(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(colorObj.type) + .case("rgb", () => { + const { a, b, g, r } = colorObj as IRgbColor; + return new RgbColor(r, g, b, a); }) .result(); }