generated from gxc-solutions/gxc-template-repo
Added first files
This commit is contained in:
parent
8e1f2c6b8b
commit
37c748da0f
12 changed files with 93 additions and 3 deletions
|
|
@ -41,7 +41,7 @@ jobs:
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: gxc-math-${{ github.sha }}
|
name: gxc-colors-${{ github.sha }}
|
||||||
path: ./dist/
|
path: ./dist/
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
|
|
@ -53,7 +53,7 @@ jobs:
|
||||||
- name: Download artifact
|
- name: Download artifact
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: gxc-math-${{ github.sha }}
|
name: gxc-colors-${{ github.sha }}
|
||||||
path: ./artifact
|
path: ./artifact
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
export * from "./interfaces";
|
||||||
|
export * from "./models";
|
||||||
|
|
@ -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 {}
|
||||||
0
lib/src/models/hsb.ts
Normal file
0
lib/src/models/hsb.ts
Normal file
3
lib/src/models/index.ts
Normal file
3
lib/src/models/index.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
export * from "./rgb";
|
||||||
|
export * from "./swatch";
|
||||||
|
export * from "./palette";
|
||||||
0
lib/src/models/lab.ts
Normal file
0
lib/src/models/lab.ts
Normal file
1
lib/src/models/palette.ts
Normal file
1
lib/src/models/palette.ts
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
export class Palette {}
|
||||||
62
lib/src/models/rgb.ts
Normal file
62
lib/src/models/rgb.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
import { ColorSpace, 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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
0
lib/src/models/spot.ts
Normal file
0
lib/src/models/spot.ts
Normal file
6
lib/src/models/swatch.ts
Normal file
6
lib/src/models/swatch.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
import { IColor } from "../interfaces";
|
||||||
|
|
||||||
|
export class Swatch {
|
||||||
|
name: string;
|
||||||
|
color: IColor;
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "@gxc-solutions/lib",
|
"name": "@gxc-solutions/colors",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "GXC Solutions",
|
"author": "GXC Solutions",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Description
|
||||||
|
|
||||||
|
@gxc-solutions/colors - is a library with models, utils and services for work with colors
|
||||||
Loading…
Add table
Add a link
Reference in a new issue