@soybeanjs/colord 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ interface ReadabilityOptions {
6
6
  level?: 'AA' | 'AAA';
7
7
  size?: 'normal' | 'large';
8
8
  }
9
- declare module '../colord' {
9
+ declare module '@soybeanjs/colord' {
10
10
  interface Colord {
11
11
  /**
12
12
  * Returns the relative luminance of a color,
@@ -2,7 +2,7 @@ import { i as CmykColor } from "../colord-xpgrVWRV.js";
2
2
  import { t as Plugin } from "../extend-DrPfn2Q1.js";
3
3
 
4
4
  //#region src/plugins/cmyk.d.ts
5
- declare module '../colord' {
5
+ declare module '@soybeanjs/colord' {
6
6
  interface Colord {
7
7
  /**
8
8
  * Converts a color to CMYK color space and returns an object.
@@ -2,7 +2,7 @@ import { t as Plugin } from "../extend-DrPfn2Q1.js";
2
2
 
3
3
  //#region src/plugins/harmonies.d.ts
4
4
  type HarmonyType = 'analogous' | 'complementary' | 'double-split-complementary' | 'rectangle' | 'split-complementary' | 'tetradic' | 'triadic';
5
- declare module '../colord' {
5
+ declare module '@soybeanjs/colord' {
6
6
  interface Colord {
7
7
  /**
8
8
  * Returns an array of harmony colors as `Colord` instances.
@@ -2,7 +2,7 @@ import { c as HwbColor } from "../colord-xpgrVWRV.js";
2
2
  import { t as Plugin } from "../extend-DrPfn2Q1.js";
3
3
 
4
4
  //#region src/plugins/hwb.d.ts
5
- declare module '../colord' {
5
+ declare module '@soybeanjs/colord' {
6
6
  interface Colord {
7
7
  /**
8
8
  * Converts a color to HWB (Hue-Whiteness-Blackness) color space and returns an object.
@@ -2,7 +2,7 @@ import { r as AnyColor, u as LabColor } from "../colord-xpgrVWRV.js";
2
2
  import { t as Plugin } from "../extend-DrPfn2Q1.js";
3
3
 
4
4
  //#region src/plugins/lab.d.ts
5
- declare module '../colord' {
5
+ declare module '@soybeanjs/colord' {
6
6
  interface Colord {
7
7
  /**
8
8
  * Converts a color to CIELAB color space and returns an object.
@@ -2,7 +2,7 @@ import { d as LchColor } from "../colord-xpgrVWRV.js";
2
2
  import { t as Plugin } from "../extend-DrPfn2Q1.js";
3
3
 
4
4
  //#region src/plugins/lch.d.ts
5
- declare module '../colord' {
5
+ declare module '@soybeanjs/colord' {
6
6
  interface Colord {
7
7
  /**
8
8
  * Converts a color to CIELCH (Lightness-Chroma-Hue) color space and returns an object.
@@ -9,7 +9,7 @@ interface MinificationOptions {
9
9
  name?: boolean;
10
10
  transparent?: boolean;
11
11
  }
12
- declare module '../colord' {
12
+ declare module '@soybeanjs/colord' {
13
13
  interface Colord {
14
14
  /** Returns the shortest string representation of the color */
15
15
  minify(options?: MinificationOptions): string;
@@ -2,7 +2,7 @@ import { r as AnyColor } from "../colord-xpgrVWRV.js";
2
2
  import { t as Plugin } from "../extend-DrPfn2Q1.js";
3
3
 
4
4
  //#region src/plugins/mix.d.ts
5
- declare module '../colord' {
5
+ declare module '@soybeanjs/colord' {
6
6
  interface Colord {
7
7
  /**
8
8
  * Produces a mixture of two colors through CIE LAB color space and returns a new Colord instance.
@@ -4,7 +4,7 @@ import { t as Plugin } from "../extend-DrPfn2Q1.js";
4
4
  interface ConvertOptions {
5
5
  closest?: boolean;
6
6
  }
7
- declare module '../colord' {
7
+ declare module '@soybeanjs/colord' {
8
8
  interface Colord {
9
9
  /** Finds CSS color keyword that matches with the color value */
10
10
  toName(options?: ConvertOptions): string | undefined;
@@ -2,9 +2,10 @@ import { f as OklabColor } from "../colord-xpgrVWRV.js";
2
2
  import { t as Plugin } from "../extend-DrPfn2Q1.js";
3
3
 
4
4
  //#region src/plugins/oklab.d.ts
5
- declare module '../colord' {
5
+ declare module '@soybeanjs/colord' {
6
6
  interface Colord {
7
7
  toOklab(): OklabColor;
8
+ toOklabString(): string;
8
9
  }
9
10
  }
10
11
  /**
@@ -83,6 +83,10 @@ const parseOklabString = (input) => {
83
83
  alpha: parseAlpha(alpha)
84
84
  }));
85
85
  };
86
+ const rgbToOklabString = (rgb) => {
87
+ const { l, a, b, alpha } = roundOklab(rgbToOklab(rgb));
88
+ return alpha < 1 ? `oklab(${l}% ${a} ${b} / ${alpha})` : `oklab(${l}% ${a} ${b})`;
89
+ };
86
90
 
87
91
  //#endregion
88
92
  //#region src/plugins/oklab.ts
@@ -94,6 +98,9 @@ const oklabPlugin = (ColordClass, parsers) => {
94
98
  ColordClass.prototype.toOklab = function toOklab() {
95
99
  return roundOklab(rgbToOklab(this.rgb));
96
100
  };
101
+ ColordClass.prototype.toOklabString = function toOklabString() {
102
+ return rgbToOklabString(this.rgb);
103
+ };
97
104
  parsers.string.push([parseOklabString, "oklab"]);
98
105
  parsers.object.push([parseOklab, "oklab"]);
99
106
  };
@@ -2,9 +2,10 @@ import { p as OklchColor } from "../colord-xpgrVWRV.js";
2
2
  import { t as Plugin } from "../extend-DrPfn2Q1.js";
3
3
 
4
4
  //#region src/plugins/oklch.d.ts
5
- declare module '../colord' {
5
+ declare module '@soybeanjs/colord' {
6
6
  interface Colord {
7
7
  toOklch(): OklchColor;
8
+ toOklchString(): string;
8
9
  }
9
10
  }
10
11
  /**
@@ -92,6 +92,10 @@ const parseOklchString = (input) => {
92
92
  alpha: parseAlpha(alpha)
93
93
  }));
94
94
  };
95
+ const rgbToOklchString = (rgb) => {
96
+ const { l, c, h, alpha } = roundOklch(rgbToOklch(rgb));
97
+ return alpha < 1 ? `oklch(${l}% ${c} ${h} / ${alpha})` : `oklch(${l}% ${c} ${h})`;
98
+ };
95
99
 
96
100
  //#endregion
97
101
  //#region src/plugins/oklch.ts
@@ -103,6 +107,9 @@ const oklchPlugin = (ColordClass, parsers) => {
103
107
  ColordClass.prototype.toOklch = function toOklch() {
104
108
  return roundOklch(rgbToOklch(this.rgb));
105
109
  };
110
+ ColordClass.prototype.toOklchString = function toOklchString() {
111
+ return rgbToOklchString(this.rgb);
112
+ };
106
113
  parsers.string.push([parseOklchString, "oklch"]);
107
114
  parsers.object.push([parseOklch, "oklch"]);
108
115
  };
@@ -2,7 +2,7 @@ import { g as XyzColor } from "../colord-xpgrVWRV.js";
2
2
  import { t as Plugin } from "../extend-DrPfn2Q1.js";
3
3
 
4
4
  //#region src/plugins/xyz.d.ts
5
- declare module '../colord' {
5
+ declare module '@soybeanjs/colord' {
6
6
  interface Colord {
7
7
  toXyz(): XyzColor;
8
8
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soybeanjs/colord",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "description": "A tiny yet powerful tool for high-performance color manipulations and conversions",
6
6
  "author": {
7
7
  "name": "Soybean",