diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml index 6bdf090..6a45dfa 100644 --- a/.forgejo/workflows/release.yml +++ b/.forgejo/workflows/release.yml @@ -41,7 +41,7 @@ jobs: - name: Upload artifact uses: actions/upload-artifact@v3 with: - name: gxc-math-${{ github.sha }} + name: gxc-colors-${{ github.sha }} path: ./dist/ deploy: @@ -53,7 +53,7 @@ jobs: - name: Download artifact uses: actions/download-artifact@v3 with: - name: gxc-math-${{ github.sha }} + name: gxc-colors-${{ github.sha }} path: ./artifact - name: Setup Node.js diff --git a/lib/src/index.ts b/lib/src/index.ts index e69de29..ed7bb26 100644 --- a/lib/src/index.ts +++ b/lib/src/index.ts @@ -0,0 +1,2 @@ +export * from "./interfaces"; +export * from "./models" \ No newline at end of file diff --git a/lib/src/interfaces/index.ts b/lib/src/interfaces/index.ts index e69de29..783e892 100644 --- a/lib/src/interfaces/index.ts +++ b/lib/src/interfaces/index.ts @@ -0,0 +1,13 @@ +export type ColorSpace = "rgb" | "cmyk"; +export type ColorType = "rgb" | "cmyk" | "grayscale" | "spot"; + +export interface IColor { + readonly colorSpace: ColorSpace; + isTransparent: boolean; + equals(color: IColor): boolean; + clone(): IColor; + toString(): string; + toJSON(): object; +} + +export interface IProcessColor {} \ No newline at end of file diff --git a/lib/src/models/hsb.ts b/lib/src/models/hsb.ts new file mode 100644 index 0000000..e69de29 diff --git a/lib/src/models/index.ts b/lib/src/models/index.ts new file mode 100644 index 0000000..a864fb9 --- /dev/null +++ b/lib/src/models/index.ts @@ -0,0 +1,3 @@ +export * from "./rgb"; +export * from "./swatch"; +export * from "./palette"; \ No newline at end of file diff --git a/lib/src/models/lab.ts b/lib/src/models/lab.ts new file mode 100644 index 0000000..e69de29 diff --git a/lib/src/models/palette.ts b/lib/src/models/palette.ts new file mode 100644 index 0000000..017b14b --- /dev/null +++ b/lib/src/models/palette.ts @@ -0,0 +1,3 @@ +export class Palette { + +} \ No newline at end of file diff --git a/lib/src/models/rgb.ts b/lib/src/models/rgb.ts new file mode 100644 index 0000000..b6ca226 --- /dev/null +++ b/lib/src/models/rgb.ts @@ -0,0 +1,57 @@ +import { ColorSpace, ColorType, IColor } from "../interfaces"; + +export class RgbColor implements IColor { + readonly colorSpace: ColorSpace = "rgb"; + + get isTransparent() { + return this.a === 0; + } + + constructor(readonly r = 255, readonly g = 255, readonly b = 255, readonly a = 255) {} + + static fromHex(hex: string): RgbColor { + const normalized = hex.replace(/^#/, ""); + const bigint = parseInt(normalized, 16); + const r = (bigint >> 16) & 255; + const g = (bigint >> 8) & 255; + const b = bigint & 255; + return new RgbColor(r, g, b); + } + + toString() { + return `rgba(${this.r}, ${this.g}, ${this.b}, ${this.a})`; + } + + equals(color: IColor) { + if (color instanceof RgbColor) { + return color.r === this.r && color.g === this.g && color.b === this.b && color.a === this.a; + } + return false; + } + + clone() { + const a = this.a / 255; + return new RgbColor(this.r, this.g, this.b, a); + } + + toHex() { + const r = Number(this.r).toString(16).padStart(2, "0"); + const g = Number(this.g).toString(16).padStart(2, "0"); + const b = Number(this.b).toString(16).padStart(2, "0"); + return `#${r}${g}${b}`; + } + + withoutAlpha() { + return new RgbColor(this.r, this.g, this.b, 255); + } + + toJSON(): object { + return { + colorSpace: this.colorSpace, + r: this.r, + g: this.b, + b: this.b, + a: this.a, + }; + } +} diff --git a/lib/src/models/spot.ts b/lib/src/models/spot.ts new file mode 100644 index 0000000..e69de29 diff --git a/lib/src/models/swatch.ts b/lib/src/models/swatch.ts new file mode 100644 index 0000000..3d2e586 --- /dev/null +++ b/lib/src/models/swatch.ts @@ -0,0 +1,6 @@ +import { IColor } from "../interfaces"; + +export class Swatch { + name: string; + color: IColor +} \ No newline at end of file diff --git a/lib/src/package.json b/lib/src/package.json index f576691..78213ac 100644 --- a/lib/src/package.json +++ b/lib/src/package.json @@ -1,5 +1,5 @@ { - "name": "@gxc-solutions/lib", + "name": "@gxc-solutions/colors", "version": "0.0.1", "main": "index.js", "author": "GXC Solutions", diff --git a/lib/src/readme.md b/lib/src/readme.md index e69de29..4a6b9ac 100644 --- a/lib/src/readme.md +++ b/lib/src/readme.md @@ -0,0 +1,3 @@ +# Description + +@gxc-solutions/colors - is a library with models, utils and services for work with colors