@soybeanjs/colord 0.0.4 → 0.0.6

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 (38) hide show
  1. package/dist/{colord-C3iU53g-.js → colord-CLzIbIN2.js} +20 -7
  2. package/dist/{colord-xpgrVWRV.d.ts → colord-Dc09uNcG.d.ts} +10 -0
  3. package/dist/colord.d.ts +1 -1
  4. package/dist/colord.js +8 -8
  5. package/dist/{extend-DrPfn2Q1.d.ts → extend-D_jQFvDk.d.ts} +1 -1
  6. package/dist/{get-D0jfz1WU.js → get-SLuYLSG9.js} +1 -1
  7. package/dist/{hsv-BKcGyyrD.js → hsv-OOAVcaRH.js} +1 -1
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.js +8 -8
  10. package/dist/lab-9NsKpGel.js +219 -0
  11. package/dist/{manipulate-C3CvrU4m.js → manipulate-DCHNBCkU.js} +3 -3
  12. package/dist/plugins/a11y.d.ts +2 -2
  13. package/dist/plugins/a11y.js +3 -3
  14. package/dist/plugins/cmyk.d.ts +2 -2
  15. package/dist/plugins/cmyk.js +1 -1
  16. package/dist/plugins/harmonies.d.ts +1 -1
  17. package/dist/plugins/hwb.d.ts +2 -2
  18. package/dist/plugins/hwb.js +2 -2
  19. package/dist/plugins/lab.d.ts +6 -2
  20. package/dist/plugins/lab.js +11 -8
  21. package/dist/plugins/lch.d.ts +2 -2
  22. package/dist/plugins/lch.js +99 -25
  23. package/dist/plugins/minify.d.ts +1 -1
  24. package/dist/plugins/minify.js +1 -1
  25. package/dist/plugins/mix.d.ts +2 -2
  26. package/dist/plugins/mix.js +6 -6
  27. package/dist/plugins/names.d.ts +1 -1
  28. package/dist/plugins/oklab.d.ts +2 -2
  29. package/dist/plugins/oklab.js +50 -17
  30. package/dist/plugins/oklch.d.ts +2 -2
  31. package/dist/plugins/oklch.js +93 -24
  32. package/dist/plugins/xyz.d.ts +2 -2
  33. package/dist/plugins/xyz.js +5 -5
  34. package/dist/{rgb-DNYno5F7.js → rgb-BVkoWOmR.js} +8 -9
  35. package/dist/{utils-DajWVr6Z.js → utils-CshL9w1R.js} +18 -1
  36. package/dist/{xyz-CXEZJhV8.js → xyz-DsYRwYO_.js} +22 -9
  37. package/package.json +1 -1
  38. package/dist/lab-B5wAd4fu.js +0 -128
@@ -1,16 +1,18 @@
1
- import { a as mul3x3, 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, y as D50 } from "./utils-DajWVr6Z.js";
2
- import { n as clampRgb, o as rgbToLinearRgb, r as linearRgbToRgb } from "./rgb-DNYno5F7.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-CshL9w1R.js";
2
+ import { n as clampRgb, o as rgbToLinearRgb, r as linearRgbToRgb } from "./rgb-BVkoWOmR.js";
3
3
 
4
4
  //#region src/models/xyz.ts
5
5
  /**
6
- * Limits XYZ axis values assuming XYZ is relative to D50.
6
+ * Limits XYZ axis values.
7
+ * Using D65 white point as upper bound since it's the standard for sRGB.
8
+ * Allow values slightly beyond D65 for wider gamut support.
7
9
  */
8
10
  const clampXyz = (xyz) => {
9
11
  const { x, y, z, alpha } = xyz;
10
12
  return {
11
- x: clamp(x, 1e-4, D50.x),
12
- y: clamp(y, 1e-4, D50.y),
13
- z: clamp(z, 1e-4, D50.z),
13
+ x: clamp(x, 0, D65.x * 1.2),
14
+ y: clamp(y, 0, D65.y * 1.2),
15
+ z: clamp(z, 0, D65.z * 1.2),
14
16
  alpha: clamp(alpha)
15
17
  };
16
18
  };
@@ -61,13 +63,24 @@ const rgbToXyz = (rgb) => {
61
63
  };
62
64
  const parseXyz = ({ x, y, z, alpha = 1 }) => {
63
65
  if (!isPresent(x) || !isPresent(y) || !isPresent(z)) return null;
64
- return xyzToRgb(clampXyz({
66
+ return clampXyz({
65
67
  x: Number(x),
66
68
  y: Number(y),
67
69
  z: Number(z),
68
70
  alpha: Number(alpha)
69
- }));
71
+ });
72
+ };
73
+ const parseXyzToRgb = (input) => {
74
+ const xyz = parseXyz(input);
75
+ if (!xyz) return null;
76
+ return xyzToRgb(xyz);
77
+ };
78
+ const parseXyzBySource = (source) => {
79
+ if (!source || source.format !== "xyz") return null;
80
+ const { input } = source;
81
+ if (typeof input === "object") return parseXyz(input);
82
+ return null;
70
83
  };
71
84
 
72
85
  //#endregion
73
- export { xyzToRgb as i, rgbToXyz as n, roundXyz as r, parseXyz as t };
86
+ export { xyzToRgb as a, roundXyz as i, parseXyzToRgb as n, rgbToXyz as r, parseXyzBySource as t };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soybeanjs/colord",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "description": "A tiny yet powerful tool for high-performance color manipulations and conversions",
6
6
  "author": {
7
7
  "name": "Soybean",
@@ -1,128 +0,0 @@
1
- import { a as mul3x3, d as M_D65_TO_D50, i as isPresent, l as round, o as parseAlpha, t as clamp, u as M_D50_TO_D65, v as ALPHA_PRECISION, y as D50 } from "./utils-DajWVr6Z.js";
2
- import { i as xyzToRgb, n as rgbToXyz } from "./xyz-CXEZJhV8.js";
3
-
4
- //#region src/models/lab.ts
5
- const EPSILON = 216 / 24389;
6
- const KAPPA = 24389 / 27;
7
- /**
8
- * Clamps LAB axis values as defined in CSS Color Level 4 specs.
9
- * https://www.w3.org/TR/css-color-4/#specifying-lab-lch
10
- */
11
- const clampLab = (lab) => {
12
- const { l, a, b, alpha } = lab;
13
- return {
14
- l: clamp(l, 0, 100),
15
- a: clamp(a, -128, 127),
16
- b: clamp(b, -128, 127),
17
- alpha: clamp(alpha)
18
- };
19
- };
20
- const roundLab = (lab) => {
21
- const { l, a, b, alpha } = lab;
22
- return {
23
- l: round(l, 3),
24
- a: round(a, 3),
25
- b: round(b, 3),
26
- alpha: round(alpha, ALPHA_PRECISION)
27
- };
28
- };
29
- /**
30
- * Performs RGB → CIEXYZ → LAB color conversion
31
- * https://www.w3.org/TR/css-color-4/#color-conversion-code
32
- */
33
- const rgbToLab = (rgb) => {
34
- const xyzD65 = rgbToXyz(rgb);
35
- const { alpha } = xyzD65;
36
- const [x, y, z] = mul3x3(M_D65_TO_D50, [
37
- xyzD65.x,
38
- xyzD65.y,
39
- xyzD65.z
40
- ]);
41
- return xyzToLabRaw({
42
- x,
43
- y,
44
- z,
45
- alpha
46
- });
47
- };
48
- /**
49
- * Performs LAB → CIEXYZ → RGB color conversion
50
- * https://www.w3.org/TR/css-color-4/#color-conversion-code
51
- */
52
- const labToRgb = (lab) => {
53
- const xyzD50 = labToXyzRaw(lab);
54
- const [x, y, z] = mul3x3(M_D50_TO_D65, [
55
- xyzD50.x,
56
- xyzD50.y,
57
- xyzD50.z
58
- ]);
59
- return xyzToRgb({
60
- x,
61
- y,
62
- z,
63
- alpha: lab.alpha
64
- });
65
- };
66
- function xyzToLabRaw(xyz) {
67
- const { x, y, z, alpha } = xyz;
68
- const xr = x / D50.x;
69
- const yr = y / D50.y;
70
- const zr = z / D50.z;
71
- const f = (t) => t > EPSILON ? Math.cbrt(t) : (KAPPA * t + 16) / 116;
72
- const fx = f(xr);
73
- const fy = f(yr);
74
- const fz = f(zr);
75
- return {
76
- l: 116 * fy - 16,
77
- a: 500 * (fx - fy),
78
- b: 200 * (fy - fz),
79
- alpha
80
- };
81
- }
82
- function labToXyzRaw(lab) {
83
- const { l, a, b, alpha } = lab;
84
- const fy = (l + 16) / 116;
85
- const fx = a / 500 + fy;
86
- const fz = fy - b / 200;
87
- const f3 = (t) => t * t * t > EPSILON ? t * t * t : (116 * t - 16) / KAPPA;
88
- const xr = f3(fx);
89
- const yr = l > KAPPA * EPSILON ? ((l + 16) / 116) ** 3 : l / KAPPA;
90
- const zr = f3(fz);
91
- return {
92
- x: xr * D50.x,
93
- y: yr * D50.y,
94
- z: zr * D50.z,
95
- alpha
96
- };
97
- }
98
- const parseLab = ({ l, a, b, alpha = 1 }) => {
99
- if (!isPresent(l) || !isPresent(a) || !isPresent(b)) return null;
100
- return labToRgb(clampLab({
101
- l: Number(l),
102
- a: Number(a),
103
- b: Number(b),
104
- alpha: Number(alpha)
105
- }));
106
- };
107
- /**
108
- * Parsing syntax: oklab(L a b [/ alpha])
109
- * - L: <number|percentage> [0,100]
110
- * - a: <number> [-125,125]
111
- * - b: <number> [-125,125]
112
- * - alpha: <number|percentage> [0,1]
113
- */
114
- const labMatcher = /^lab\(\s*([+-]?[\d.]+)%?\s+([+-]?[\d.]+)\s+([+-]?[\d.]+)(?:\s*\/\s*([+-]?[\d.]+%?))?\s*\)$/i;
115
- const parseLabString = (input) => {
116
- const match = labMatcher.exec(input);
117
- if (!match) return null;
118
- const [_, l, a, b, alpha] = match;
119
- return labToRgb(clampLab({
120
- l: Number.parseFloat(l),
121
- a: Number.parseFloat(a),
122
- b: Number.parseFloat(b),
123
- alpha: parseAlpha(alpha)
124
- }));
125
- };
126
-
127
- //#endregion
128
- export { rgbToLab as a, parseLabString as i, labToRgb as n, roundLab as o, parseLab as r, clampLab as t };