@soybeanjs/colord 0.0.7 → 0.0.8

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.
Files changed (43) hide show
  1. package/dist/{colord-CLzIbIN2.js → colord-CiL21DdP.js} +12 -6
  2. package/dist/{colord-Dc09uNcG.d.ts → colord-DjohCNUk.d.ts} +4 -67
  3. package/dist/colord.d.ts +1 -1
  4. package/dist/colord.js +8 -8
  5. package/dist/extend-Cjbo01n8.js +15 -0
  6. package/dist/{extend-D_jQFvDk.d.ts → extend-DmcZT4-q.d.ts} +2 -1
  7. package/dist/{get-SLuYLSG9.js → get-DjkEJgax.js} +1 -1
  8. package/dist/{hsv-OOAVcaRH.js → hsv-6f-Avk00.js} +1 -1
  9. package/dist/index.d.ts +3 -2
  10. package/dist/index.js +9 -20
  11. package/dist/lab-BXLaTQvQ.js +27 -0
  12. package/dist/{lab-9NsKpGel.js → lab-DklZwOkG.js} +3 -3
  13. package/dist/{manipulate-DCHNBCkU.js → manipulate-DJ-cBonL.js} +3 -3
  14. package/dist/oklch-sYjVoJRG.js +186 -0
  15. package/dist/palette/index.d.ts +30 -0
  16. package/dist/palette/index.js +518 -0
  17. package/dist/plugins/a11y.d.ts +2 -2
  18. package/dist/plugins/a11y.js +3 -3
  19. package/dist/plugins/cmyk.d.ts +2 -2
  20. package/dist/plugins/cmyk.js +1 -1
  21. package/dist/plugins/harmonies.d.ts +1 -1
  22. package/dist/plugins/hwb.d.ts +2 -2
  23. package/dist/plugins/hwb.js +2 -2
  24. package/dist/plugins/lab.d.ts +2 -2
  25. package/dist/plugins/lab.js +6 -27
  26. package/dist/plugins/lch.d.ts +2 -2
  27. package/dist/plugins/lch.js +4 -4
  28. package/dist/plugins/minify.d.ts +1 -1
  29. package/dist/plugins/minify.js +1 -1
  30. package/dist/plugins/mix.d.ts +2 -2
  31. package/dist/plugins/mix.js +6 -6
  32. package/dist/plugins/names.d.ts +1 -1
  33. package/dist/plugins/oklab.d.ts +2 -2
  34. package/dist/plugins/oklab.js +2 -2
  35. package/dist/plugins/oklch.d.ts +2 -2
  36. package/dist/plugins/oklch.js +3 -184
  37. package/dist/plugins/xyz.d.ts +2 -2
  38. package/dist/plugins/xyz.js +3 -3
  39. package/dist/{rgb-BVkoWOmR.js → rgb-BIWjP3hJ.js} +2 -2
  40. package/dist/types-B93dJkfp.d.ts +112 -0
  41. package/dist/{xyz-DsYRwYO_.js → xyz-Czd8MTub.js} +2 -2
  42. package/package.json +6 -1
  43. /package/dist/{utils-CshL9w1R.js → utils-BhDL0kto.js} +0 -0
@@ -1,9 +1,9 @@
1
- import "../utils-CshL9w1R.js";
2
- import "../rgb-BVkoWOmR.js";
3
- import "../hsv-OOAVcaRH.js";
4
- import { i as mix } from "../manipulate-DCHNBCkU.js";
5
- import "../xyz-DsYRwYO_.js";
6
- import "../lab-9NsKpGel.js";
1
+ import "../utils-BhDL0kto.js";
2
+ import "../rgb-BIWjP3hJ.js";
3
+ import "../hsv-6f-Avk00.js";
4
+ import { i as mix } from "../manipulate-DJ-cBonL.js";
5
+ import "../xyz-Czd8MTub.js";
6
+ import "../lab-DklZwOkG.js";
7
7
 
8
8
  //#region src/plugins/mix.ts
9
9
  /**
@@ -1,4 +1,4 @@
1
- import { t as Plugin } from "../extend-D_jQFvDk.js";
1
+ import { t as Plugin } from "../extend-DmcZT4-q.js";
2
2
 
3
3
  //#region src/plugins/names.d.ts
4
4
  interface ConvertOptions {
@@ -1,5 +1,5 @@
1
- import { f as OklabColor } from "../colord-Dc09uNcG.js";
2
- import { t as Plugin } from "../extend-D_jQFvDk.js";
1
+ import { f as OklabColor } from "../types-B93dJkfp.js";
2
+ import { t as Plugin } from "../extend-DmcZT4-q.js";
3
3
 
4
4
  //#region src/plugins/oklab.d.ts
5
5
  declare module '@soybeanjs/colord' {
@@ -1,5 +1,5 @@
1
- import { _ as OKLAB_M2_INV, a as mul3x3, c as parseValueToDecimal, g as OKLAB_M2, h as OKLAB_M1_INV, i as isPresent, l as round, m as OKLAB_M1, o as parseAlpha, t as clamp, v as ALPHA_PRECISION } from "../utils-CshL9w1R.js";
2
- import { n as clampRgb, o as rgbToLinearRgb, r as linearRgbToRgb, t as clampLinearRgb } from "../rgb-BVkoWOmR.js";
1
+ import { _ as OKLAB_M2_INV, a as mul3x3, c as parseValueToDecimal, g as OKLAB_M2, h as OKLAB_M1_INV, i as isPresent, l as round, m as OKLAB_M1, o as parseAlpha, t as clamp, v as ALPHA_PRECISION } from "../utils-BhDL0kto.js";
2
+ import { n as clampRgb, o as rgbToLinearRgb, r as linearRgbToRgb, t as clampLinearRgb } from "../rgb-BIWjP3hJ.js";
3
3
 
4
4
  //#region src/models/oklab.ts
5
5
  const clampOklab = (oklab) => {
@@ -1,5 +1,5 @@
1
- import { p as OklchColor } from "../colord-Dc09uNcG.js";
2
- import { t as Plugin } from "../extend-D_jQFvDk.js";
1
+ import { p as OklchColor } from "../types-B93dJkfp.js";
2
+ import { t as Plugin } from "../extend-DmcZT4-q.js";
3
3
 
4
4
  //#region src/plugins/oklch.d.ts
5
5
  declare module '@soybeanjs/colord' {
@@ -1,186 +1,5 @@
1
- import { _ as OKLAB_M2_INV, a as mul3x3, c as parseValueToDecimal, g as OKLAB_M2, h as OKLAB_M1_INV, i as isPresent, l as round, m as OKLAB_M1, n as clampHue, o as parseAlpha, s as parseHue, t as clamp, v as ALPHA_PRECISION } from "../utils-CshL9w1R.js";
2
- import { n as clampRgb, o as rgbToLinearRgb, r as linearRgbToRgb, t as clampLinearRgb } from "../rgb-BVkoWOmR.js";
1
+ import "../utils-BhDL0kto.js";
2
+ import "../rgb-BIWjP3hJ.js";
3
+ import { n as oklch_default, t as oklchPlugin } from "../oklch-sYjVoJRG.js";
3
4
 
4
- //#region src/models/oklch.ts
5
- const clampOklch = (oklch) => {
6
- const { l, c, h, alpha } = oklch;
7
- return {
8
- l: clamp(l, 0, 1),
9
- c: clamp(c, 0, .37),
10
- h: clampHue(h),
11
- alpha: clamp(alpha)
12
- };
13
- };
14
- const roundOklch = (oklch) => {
15
- const { l, c, h, alpha } = oklch;
16
- return {
17
- l: round(l, 3),
18
- c: round(c, 3),
19
- h: round(h, 3),
20
- alpha: round(alpha, ALPHA_PRECISION)
21
- };
22
- };
23
- /**
24
- * Convert OKLCH to Linear RGB without gamut mapping
25
- */
26
- const oklchToLinearRgb = (oklch) => {
27
- const { l, c, h, alpha } = oklch;
28
- const hRad = h * Math.PI / 180;
29
- const [r, g, b] = mul3x3(OKLAB_M1_INV, mul3x3(OKLAB_M2_INV, [
30
- l,
31
- c * Math.cos(hRad),
32
- c * Math.sin(hRad)
33
- ]).map((v) => v * v * v));
34
- return {
35
- r,
36
- g,
37
- b,
38
- alpha
39
- };
40
- };
41
- /**
42
- * Check if a linear RGB color is within sRGB gamut
43
- */
44
- const isInGamut = (linearRgb, epsilon = 1e-6) => {
45
- return linearRgb.r >= -epsilon && linearRgb.r <= 1 + epsilon && linearRgb.g >= -epsilon && linearRgb.g <= 1 + epsilon && linearRgb.b >= -epsilon && linearRgb.b <= 1 + epsilon;
46
- };
47
- /**
48
- * Binary search to find maximum chroma that fits in sRGB gamut
49
- * @param l - Lightness (0-1)
50
- * @param h - Hue (0-360)
51
- * @param alpha - Alpha (0-1)
52
- * @returns Maximum chroma that fits in sRGB gamut
53
- */
54
- const findGamutChroma = (l, h, alpha) => {
55
- let min = 0;
56
- let max = .37;
57
- const epsilon = 1e-5;
58
- if (isInGamut(oklchToLinearRgb({
59
- l,
60
- c: max,
61
- h,
62
- alpha
63
- }), epsilon)) return max;
64
- while (max - min > epsilon) {
65
- const mid = (min + max) / 2;
66
- if (isInGamut(oklchToLinearRgb({
67
- l,
68
- c: mid,
69
- h,
70
- alpha
71
- }), epsilon)) min = mid;
72
- else max = mid;
73
- }
74
- return min;
75
- };
76
- const oklchToRgb = (oklch) => {
77
- const { l, h, alpha } = oklch;
78
- let linearRgb = oklchToLinearRgb(oklch);
79
- if (!isInGamut(linearRgb)) linearRgb = oklchToLinearRgb({
80
- l,
81
- c: findGamutChroma(l, h, alpha),
82
- h,
83
- alpha
84
- });
85
- linearRgb = clampLinearRgb(linearRgb);
86
- return clampRgb(linearRgbToRgb(linearRgb));
87
- };
88
- const rgbToOklch = (rgb) => {
89
- const lRgb = rgbToLinearRgb(rgb);
90
- const [l, a, b] = mul3x3(OKLAB_M2, mul3x3(OKLAB_M1, [
91
- lRgb.r,
92
- lRgb.g,
93
- lRgb.b
94
- ]).map((v) => Math.cbrt(v)));
95
- const chroma = Math.sqrt(a * a + b * b);
96
- let hue;
97
- if (chroma < 1e-4) hue = 0;
98
- else {
99
- hue = Math.atan2(b, a) * (180 / Math.PI);
100
- if (hue < 0) hue += 360;
101
- }
102
- return clampOklch({
103
- l,
104
- c: chroma,
105
- h: hue,
106
- alpha: rgb.alpha
107
- });
108
- };
109
- const parseOklch = ({ l, c, h, alpha = 1 }) => {
110
- if (!isPresent(l) || !isPresent(c) || !isPresent(h)) return null;
111
- return clampOklch({
112
- l: Number(l),
113
- c: Number(c),
114
- h: Number(h),
115
- alpha: Number(alpha)
116
- });
117
- };
118
- const parseOklchToRgb = (input) => {
119
- const oklch = parseOklch(input);
120
- if (!oklch) return null;
121
- return oklchToRgb(oklch);
122
- };
123
- /**
124
- * Parsing syntax: oklch(L c h [/ alpha])
125
- * - L: <number|percentage>
126
- * - c: <number>
127
- * - h: <number>
128
- * - alpha: <number|percentage>
129
- */
130
- const oklchMatcher = /^oklch\(\s*([+-]?[\d.]+)%?\s+([+-]?[\d.]+)\s+([+-]?[\d.]+)(deg|grad|rad|turn)?(?:\s*\/\s*([+-]?[\d.]+%?))?\s*\)$/i;
131
- const parseOklchString = (input) => {
132
- const match = oklchMatcher.exec(input);
133
- if (!match) return null;
134
- const [_, l, c, h, unit, alpha] = match;
135
- return clampOklch({
136
- l: parseValueToDecimal(l),
137
- c: Number.parseFloat(c),
138
- h: parseHue(h, unit),
139
- alpha: parseAlpha(alpha)
140
- });
141
- };
142
- const parseOklchStringToRgb = (input) => {
143
- const oklch = parseOklchString(input);
144
- if (!oklch) return null;
145
- return oklchToRgb(oklch);
146
- };
147
- const toOklchString = (oklch) => {
148
- const { l, c, h, alpha } = roundOklch(oklch);
149
- return alpha < 1 ? `oklch(${l} ${c} ${h} / ${alpha})` : `oklch(${l} ${c} ${h})`;
150
- };
151
- const rgbToOklchString = (rgb) => {
152
- return toOklchString(rgbToOklch(rgb));
153
- };
154
- const parseOklchBySource = (source) => {
155
- if (!source || source.format !== "oklch") return null;
156
- const { input } = source;
157
- if (typeof input === "string") return parseOklchString(input);
158
- if (typeof input === "object") return parseOklch(input);
159
- return null;
160
- };
161
- const toOklchStringBySource = (source) => {
162
- const oklch = parseOklchBySource(source);
163
- if (!oklch) return null;
164
- return toOklchString(oklch);
165
- };
166
-
167
- //#endregion
168
- //#region src/plugins/oklch.ts
169
- /**
170
- * A plugin adding support for OKLCH colorspace.
171
- * https://bottosson.github.io/posts/oklab/
172
- */
173
- const oklchPlugin = (ColordClass, parsers) => {
174
- ColordClass.prototype.toOklch = function toOklch() {
175
- return roundOklch(parseOklchBySource(this.getSource()) || rgbToOklch(this.rgb));
176
- };
177
- ColordClass.prototype.toOklchString = function toOklchString$1() {
178
- return toOklchStringBySource(this.getSource()) || rgbToOklchString(this.rgb);
179
- };
180
- parsers.string.push([parseOklchStringToRgb, "oklch"]);
181
- parsers.object.push([parseOklchToRgb, "oklch"]);
182
- };
183
- var oklch_default = oklchPlugin;
184
-
185
- //#endregion
186
5
  export { oklch_default as default, oklchPlugin };
@@ -1,5 +1,5 @@
1
- import { g as XyzColor } from "../colord-Dc09uNcG.js";
2
- import { t as Plugin } from "../extend-D_jQFvDk.js";
1
+ import { b as XyzColor } from "../types-B93dJkfp.js";
2
+ import { t as Plugin } from "../extend-DmcZT4-q.js";
3
3
 
4
4
  //#region src/plugins/xyz.d.ts
5
5
  declare module '@soybeanjs/colord' {
@@ -1,6 +1,6 @@
1
- import "../utils-CshL9w1R.js";
2
- import "../rgb-BVkoWOmR.js";
3
- import { i as roundXyz, n as parseXyzToRgb, r as rgbToXyz, t as parseXyzBySource } from "../xyz-DsYRwYO_.js";
1
+ import "../utils-BhDL0kto.js";
2
+ import "../rgb-BIWjP3hJ.js";
3
+ import { i as roundXyz, n as parseXyzToRgb, r as rgbToXyz, t as parseXyzBySource } from "../xyz-Czd8MTub.js";
4
4
 
5
5
  //#region src/plugins/xyz.ts
6
6
  /**
@@ -1,4 +1,4 @@
1
- import { i as isPresent, l as round, o as parseAlpha, t as clamp, v as ALPHA_PRECISION } from "./utils-CshL9w1R.js";
1
+ import { i as isPresent, l as round, o as parseAlpha, t as clamp, v as ALPHA_PRECISION } from "./utils-BhDL0kto.js";
2
2
 
3
3
  //#region src/models/rgb.ts
4
4
  const clampRgb = (rgb) => {
@@ -140,7 +140,7 @@ function parseValue(str) {
140
140
  }
141
141
  const rgbToRgbString = (rgb) => {
142
142
  const { r, g, b, alpha } = roundRgb(rgb);
143
- return alpha < 1 ? `rgb(${r}, ${g}, ${b}, ${alpha})` : `rgb(${r}, ${g}, ${b})`;
143
+ return alpha < 1 ? `rgb(${r}, ${g}, ${b} / ${alpha})` : `rgb(${r}, ${g}, ${b})`;
144
144
  };
145
145
 
146
146
  //#endregion
@@ -0,0 +1,112 @@
1
+ //#region src/types.d.ts
2
+ type WithAlpha<O> = O & {
3
+ alpha: number;
4
+ };
5
+ type RgbColor = WithAlpha<{
6
+ r: number;
7
+ g: number;
8
+ b: number;
9
+ }>;
10
+ type HslColor = WithAlpha<{
11
+ h: number;
12
+ s: number;
13
+ l: number;
14
+ }>;
15
+ type HsvColor = WithAlpha<{
16
+ h: number;
17
+ s: number;
18
+ v: number;
19
+ }>;
20
+ type HwbColor = WithAlpha<{
21
+ h: number;
22
+ w: number;
23
+ b: number;
24
+ }>;
25
+ type XyzColor = WithAlpha<{
26
+ x: number;
27
+ y: number;
28
+ z: number;
29
+ }>;
30
+ type LabColor = WithAlpha<{
31
+ l: number;
32
+ a: number;
33
+ b: number;
34
+ }>;
35
+ type LchColor = WithAlpha<{
36
+ l: number;
37
+ c: number;
38
+ h: number;
39
+ }>;
40
+ type CmykColor = WithAlpha<{
41
+ c: number;
42
+ m: number;
43
+ y: number;
44
+ k: number;
45
+ }>;
46
+ type OklabColor = WithAlpha<{
47
+ l: number;
48
+ a: number;
49
+ b: number;
50
+ }>;
51
+ type OklchColor = WithAlpha<{
52
+ l: number;
53
+ c: number;
54
+ h: number;
55
+ }>;
56
+ type PartialAlpha<O> = Omit<O, 'alpha'> & {
57
+ alpha?: number;
58
+ };
59
+ type ObjectColor = PartialAlpha<RgbColor> | PartialAlpha<HslColor> | PartialAlpha<HsvColor> | PartialAlpha<HwbColor> | PartialAlpha<XyzColor> | PartialAlpha<LabColor> | PartialAlpha<LchColor> | PartialAlpha<CmykColor> | PartialAlpha<OklabColor> | PartialAlpha<OklchColor>;
60
+ type AnyColor = string | ObjectColor;
61
+ type InputObject = Record<string, unknown>;
62
+ type Format = 'name' | 'hex' | 'rgb' | 'lrgb' | 'hsl' | 'hsv' | 'hwb' | 'xyz' | 'lab' | 'lch' | 'cmyk' | 'oklab' | 'oklch';
63
+ type Input = string | InputObject;
64
+ interface InputSource {
65
+ format: Format;
66
+ input: Input;
67
+ }
68
+ type ParseFunction<I extends Input> = (input: I) => RgbColor | null;
69
+ type Parser<I extends Input> = [ParseFunction<I>, Format];
70
+ type Parsers = {
71
+ string: Array<Parser<string>>;
72
+ object: Array<Parser<InputObject>>;
73
+ };
74
+ /**
75
+ * the palette color level
76
+ *
77
+ * the main color level is 500
78
+ */
79
+ type PaletteColorLevel = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
80
+ type TailwindPaletteColorKey = 'slate' | 'gray' | 'zinc' | 'neutral' | 'stone' | 'red' | 'orange' | 'amber' | 'yellow' | 'lime' | 'green' | 'emerald' | 'teal' | 'cyan' | 'sky' | 'blue' | 'indigo' | 'violet' | 'purple' | 'fuchsia' | 'pink' | 'rose';
81
+ /**
82
+ * the tailwind palette color
83
+ *
84
+ * the color format is `oklch` string
85
+ */
86
+ type TailwindPaletteColor = { [K in TailwindPaletteColorKey]: { [L in PaletteColorLevel]: string } };
87
+ type OutputColorMap = {
88
+ hex: string;
89
+ rgb: RgbColor;
90
+ rgbString: string;
91
+ oklch: OklchColor;
92
+ oklchString: string;
93
+ hsl: HslColor;
94
+ hslString: string;
95
+ };
96
+ type OutputFormat = keyof OutputColorMap;
97
+ interface NearestPalette<F extends OutputFormat> {
98
+ /** current color */
99
+ current: OutputColorMap[F];
100
+ /** palette color key */
101
+ paletteKey: TailwindPaletteColorKey;
102
+ /** palette level */
103
+ level: PaletteColorLevel;
104
+ /** palette color */
105
+ color: OutputColorMap[F];
106
+ /** the color delta value */
107
+ delta: number;
108
+ /** palette colors */
109
+ palette: Record<PaletteColorLevel, OutputColorMap[F]>;
110
+ }
111
+ //#endregion
112
+ export { Parsers as _, HsvColor as a, XyzColor as b, InputSource as c, NearestPalette as d, OklabColor as f, PaletteColorLevel as g, OutputFormat as h, HslColor as i, LabColor as l, OutputColorMap as m, CmykColor as n, HwbColor as o, OklchColor as p, Format as r, Input as s, AnyColor as t, LchColor as u, RgbColor as v, TailwindPaletteColor as y };
@@ -1,5 +1,5 @@
1
- import { a as mul3x3, b as D65, f as M_SRGB_TO_XYZ_D65, i as isPresent, l as round, p as M_XYZ_D65_TO_SRGB, t as clamp, v as ALPHA_PRECISION } from "./utils-CshL9w1R.js";
2
- import { n as clampRgb, o as rgbToLinearRgb, r as linearRgbToRgb } from "./rgb-BVkoWOmR.js";
1
+ import { a as mul3x3, b as D65, f as M_SRGB_TO_XYZ_D65, i as isPresent, l as round, p as M_XYZ_D65_TO_SRGB, t as clamp, v as ALPHA_PRECISION } from "./utils-BhDL0kto.js";
2
+ import { n as clampRgb, o as rgbToLinearRgb, r as linearRgbToRgb } from "./rgb-BIWjP3hJ.js";
3
3
 
4
4
  //#region src/models/xyz.ts
5
5
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soybeanjs/colord",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.8",
5
5
  "description": "A tiny yet powerful tool for high-performance color manipulations and conversions",
6
6
  "author": {
7
7
  "name": "Soybean",
@@ -25,6 +25,11 @@
25
25
  "import": "./dist/index.js",
26
26
  "require": "./dist/index.js"
27
27
  },
28
+ "./palette": {
29
+ "types": "./dist/palette/index.d.ts",
30
+ "import": "./dist/palette/index.js",
31
+ "require": "./dist/palette/index.js"
32
+ },
28
33
  "./plugins/*": {
29
34
  "types": "./dist/plugins/*.d.ts",
30
35
  "import": "./dist/plugins/*.js",
File without changes