From f106226e7024af6e0960bac9a14d241c14d1d785 Mon Sep 17 00:00:00 2001 From: Andrey Kernichniy Date: Sat, 7 Mar 2026 00:16:34 +0700 Subject: [PATCH] Release package version 0.0.3 Update types of scene, added utils for check fill type. --- .npmrc | 1 + lib/src/index.ts | 1 + lib/src/interfaces/color.ts | 5 +++++ lib/src/interfaces/fill.ts | 40 +++++++++++++++++++++++++++++++++ lib/src/interfaces/index.ts | 41 +++++----------------------------- lib/src/interfaces/objects.ts | 33 +++++++++++++++++++++++++++ lib/src/interfaces/renderer.ts | 9 ++++++++ lib/src/interfaces/scene.ts | 9 ++++++++ lib/src/package.json | 5 ++++- lib/src/utils/fill.ts | 7 ++++++ lib/src/utils/index.ts | 1 + package-lock.json | 8 +++++++ package.json | 4 +++- 13 files changed, 126 insertions(+), 38 deletions(-) create mode 100644 .npmrc create mode 100644 lib/src/interfaces/color.ts create mode 100644 lib/src/interfaces/fill.ts create mode 100644 lib/src/interfaces/objects.ts create mode 100644 lib/src/interfaces/renderer.ts create mode 100644 lib/src/interfaces/scene.ts create mode 100644 lib/src/utils/fill.ts create mode 100644 lib/src/utils/index.ts diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..80b9b9b --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +@gxc-solutions:registry=https://npm.gxc-solutions.ru/ \ No newline at end of file diff --git a/lib/src/index.ts b/lib/src/index.ts index a427c73..795622a 100644 --- a/lib/src/index.ts +++ b/lib/src/index.ts @@ -1 +1,2 @@ export * from "./interfaces"; +export * from "./utils"; diff --git a/lib/src/interfaces/color.ts b/lib/src/interfaces/color.ts new file mode 100644 index 0000000..b19c5db --- /dev/null +++ b/lib/src/interfaces/color.ts @@ -0,0 +1,5 @@ +export interface IRgbColor { + r: number; + g: number; + b: number; +} diff --git a/lib/src/interfaces/fill.ts b/lib/src/interfaces/fill.ts new file mode 100644 index 0000000..84457e0 --- /dev/null +++ b/lib/src/interfaces/fill.ts @@ -0,0 +1,40 @@ +import { IRgbColor } from "./color"; +import { IPoint } from "@gxc-solutions/math"; + +export type FillType = "solid" | "texture"; +export type GradientType = "liner" | "radial" | "conic"; + +export interface IBaseFill { + type: GradientType | FillType; +} + +export interface ISolidFill extends IBaseFill { + type: "solid"; + color: IRgbColor; +} + +export interface ITextureFill extends IBaseFill { + type: "texture"; + texture: HTMLImageElement; +} + +export interface IGradientStop { + offset: number; + color: IRgbColor; +} + +export interface ILinerGradient extends IBaseFill { + type: "liner"; + start: IPoint; + end: IPoint; + stops: IGradientStop[]; +} + +export interface IRadialGradient { + type: "radial"; +} + +export interface IConicGradient { + type: "conic"; +} + diff --git a/lib/src/interfaces/index.ts b/lib/src/interfaces/index.ts index fca68d0..5f54c0d 100644 --- a/lib/src/interfaces/index.ts +++ b/lib/src/interfaces/index.ts @@ -1,36 +1,5 @@ -export type TRendererType = "2d" | "webgl" | "webgl2" | "webgpu" | "html"; - -export type DrawObjectType = "rectangle-object" | "image-object" | "ellipse-object" | "text-object"; - -export interface IDrawObject extends IDrawBorderedRectangle { - readonly id: string; - readonly type: DrawObjectType; - color: string; -} - -export interface IDrawRectangle { - x: number; - y: number; - width: number; - height: number; - angle: number; -} - -export interface IDrawBorderedRectangle extends IDrawRectangle { - border: number; - borderColor: string; -} - -export interface IScene { - objects: IDrawObject[]; - selection?: IDrawRectangle; - spotlight: IDrawRectangle[]; - background: string; - static: IDrawObject[]; -} - -export interface IRenderer { - readonly type: TRendererType; - holder: HTMLElement; - render(scene: IScene): Promise; -} +export * from "./renderer"; +export * from "./scene"; +export * from "./objects"; +export * from "./fill"; +export * from "./color"; diff --git a/lib/src/interfaces/objects.ts b/lib/src/interfaces/objects.ts new file mode 100644 index 0000000..e038cd0 --- /dev/null +++ b/lib/src/interfaces/objects.ts @@ -0,0 +1,33 @@ +import { IRgbColor } from "./color"; +import { IBaseFill } from "./fill"; + +export interface IRectangle { + x: number; + y: number; + width: number; + height: number; + angle: number; +} + +export interface IStroke { + width: number; + color: IRgbColor; + dash: number[]; +} + +export type DrawObjectType = "rectangle-object" | "image-object" | "ellipse-object" | "text-object"; + +export interface IBaseDrawObject { + readonly id: string; + readonly type: DrawObjectType; + name: string; +} + +export interface IDrawObject extends IBaseDrawObject { + stroke: IStroke; + fill: IBaseFill; +} + +export interface IDrawNode extends IBaseDrawObject { + children: IDrawObject[]; +} diff --git a/lib/src/interfaces/renderer.ts b/lib/src/interfaces/renderer.ts new file mode 100644 index 0000000..f8e29b8 --- /dev/null +++ b/lib/src/interfaces/renderer.ts @@ -0,0 +1,9 @@ +import { IScene } from "./scene"; + +export type TRendererType = "2d" | "webgl" | "webgl2" | "webgpu" | "html"; + +export interface IRenderer { + readonly type: TRendererType; + holder: HTMLElement; + render(scene: IScene): Promise; +} diff --git a/lib/src/interfaces/scene.ts b/lib/src/interfaces/scene.ts new file mode 100644 index 0000000..83a5d36 --- /dev/null +++ b/lib/src/interfaces/scene.ts @@ -0,0 +1,9 @@ +import { IBaseDrawObject, IDrawNode, IRectangle } from "./objects"; + +export interface IScene { + nodes: IDrawNode[]; + selection?: IRectangle; + spotlight: IRectangle[]; + background: string; + static: IBaseDrawObject[]; +} diff --git a/lib/src/package.json b/lib/src/package.json index 9517949..320c1c8 100644 --- a/lib/src/package.json +++ b/lib/src/package.json @@ -1,10 +1,13 @@ { "name": "@gxc-solutions/renderer-base", - "version": "0.0.2", + "version": "0.0.3", "main": "index.js", "author": "GXC Solutions", "publishConfig": { "access": "public", "registry": "https://npm.gxc-solutions.ru" + }, + "peerDependencies": { + "@gxc-solutions/math": "^0.0.1" } } diff --git a/lib/src/utils/fill.ts b/lib/src/utils/fill.ts new file mode 100644 index 0000000..8738bc1 --- /dev/null +++ b/lib/src/utils/fill.ts @@ -0,0 +1,7 @@ +import { IBaseFill, IConicGradient, ILinerGradient, IRadialGradient, ISolidFill, ITextureFill } from "../interfaces/fill"; + +export const isSolidFill = (fill: IBaseFill): fill is ISolidFill => fill?.type === "solid"; +export const isTextureFill = (fill: IBaseFill): fill is ITextureFill => fill?.type === "texture"; +export const isLinerGradientFill = (fill: IBaseFill): fill is ILinerGradient => fill?.type === "liner"; +export const isRadialGradientFill = (fill: IBaseFill): fill is IRadialGradient => fill?.type === "radial"; +export const isConicGradientFill = (fill: IBaseFill): fill is IConicGradient => fill?.type === "conic"; diff --git a/lib/src/utils/index.ts b/lib/src/utils/index.ts new file mode 100644 index 0000000..7d586c6 --- /dev/null +++ b/lib/src/utils/index.ts @@ -0,0 +1 @@ +export * from "./fill"; diff --git a/package-lock.json b/package-lock.json index 98dff49..cdca1ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,11 +8,19 @@ "name": "gxc-renderer-base", "version": "0.0.0", "license": "ISC", + "dependencies": { + "@gxc-solutions/math": "^0.0.1" + }, "devDependencies": { "rimraf": "^6.0.1", "typescript": "^5.9.3" } }, + "node_modules/@gxc-solutions/math": { + "version": "0.0.1", + "resolved": "https://npm.gxc-solutions.ru/@gxc-solutions/math/-/math-0.0.1.tgz", + "integrity": "sha512-m6lxTkjXkyaUoI3+cJKpgt/AQlyApLSJ2p9D2EJ9+XzHCSjOWs29GzczPLgopYdLEWYN/YPr77V4CScGpR7qxw==" + }, "node_modules/balanced-match": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", diff --git a/package.json b/package.json index 3567241..fe997fb 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "author": "", "license": "ISC", "description": "", - "dependencies": {}, + "dependencies": { + "@gxc-solutions/math": "^0.0.1" + }, "devDependencies": { "rimraf": "^6.0.1", "typescript": "^5.9.3"