@texel/color 1.1.7 → 1.1.9

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.
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@texel/color",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "a minimal and modern color library",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
7
+ "types": "./types.d.ts",
7
8
  "exports": {
8
- "import": "./src/index.js"
9
+ "import": "./src/index.js",
10
+ "types": "./types.d.ts"
9
11
  },
10
12
  "license": "MIT",
11
13
  "author": {
@@ -30,8 +32,8 @@
30
32
  },
31
33
  "scripts": {
32
34
  "visualize": "canvas-sketch-cli test/canvas-graph.js --open",
33
- "docs": "jsdoc src -t node_modules/better-docs -c tools/.jsdoc.json -d docs -R DOC.md",
34
- "types": "jsdoc src -t node_modules/tsd-jsdoc/dist -c tools/.jsdoc.types.json -d .",
35
+ "docs": "jsdoc src -r -t node_modules/better-docs -c tools/.jsdoc.json -d docs -R DOC.md",
36
+ "types": "jsdoc src -r -t node_modules/tsd-jsdoc/dist -c tools/.jsdoc.types.json -d .",
35
37
  "test": "faucet test/test*.js",
36
38
  "bench": "node test/bench-colorjs.js",
37
39
  "bench:node": "NODE_ENV=production node --prof --no-logfile-per-isolate test/bench-node.js && node --prof-process v8.log",
package/src/core.js CHANGED
@@ -20,6 +20,10 @@ import { listColorSpaces, sRGB, XYZ } from "./spaces.js";
20
20
  * const vec = [ x, y, z ];
21
21
  */
22
22
 
23
+ /**
24
+ * @typedef {number[][][]} ColorGamutCoefficients
25
+ */
26
+
23
27
  /**
24
28
  * @typedef {Object} ChromaticAdaptation
25
29
  * @property {Matrix3x3} from the matrix to convert from the source whitepoint to the destination whitepoint
@@ -42,6 +46,7 @@ import { listColorSpaces, sRGB, XYZ } from "./spaces.js";
42
46
  /**
43
47
  * @typedef {Object} ColorGamut
44
48
  * @property {ColorSpace} space the color space associated with this color gamut
49
+ * @property {ColorGamutCoefficients} [coefficients] the coefficients used during gamut mapping from OKLab
45
50
  */
46
51
 
47
52
  const tmp3 = vec3();
package/src/gamut.js CHANGED
@@ -92,8 +92,8 @@ const setYZ = (v, a, b) => {
92
92
  * the RGB gamut, using the given coefficients.
93
93
  * @param {number} a The normalized a component of the hue.
94
94
  * @param {number} b The normalized b component of the hue.
95
- * @param {number[][]} lmsToRgb The LMS to RGB conversion matrix.
96
- * @param {number[][][]} okCoeff The OKLab coefficients.
95
+ * @param {Matrix3x3} lmsToRgb The LMS to RGB conversion matrix.
96
+ * @param {ColorGamutCoefficients} okCoeff The OKLab coefficients.
97
97
  * @returns {number} The maximum saturation.
98
98
  * @method
99
99
  * @category mapping
package/types.d.ts CHANGED
@@ -15,6 +15,7 @@ declare module "@texel/color" {
15
15
  * const vec = [ x, y, z ];
16
16
  */
17
17
  type Vector = number[];
18
+ type ColorGamutCoefficients = number[][][];
18
19
  /**
19
20
  * @property from - the matrix to convert from the source whitepoint to the destination whitepoint
20
21
  * @property to - the matrix to convert from the destination whitepoint to the source whitepoint
@@ -47,9 +48,11 @@ declare module "@texel/color" {
47
48
  };
48
49
  /**
49
50
  * @property space - the color space associated with this color gamut
51
+ * @property [coefficients] - the coefficients used during gamut mapping from OKLab
50
52
  */
51
53
  type ColorGamut = {
52
54
  space: ColorSpace;
55
+ coefficients?: ColorGamutCoefficients;
53
56
  };
54
57
  /**
55
58
  * Converts OKLab color to another color space.
@@ -156,7 +159,7 @@ declare module "@texel/color" {
156
159
  * @param okCoeff - The OKLab coefficients.
157
160
  * @returns The maximum saturation.
158
161
  */
159
- function computeMaxSaturationOKLC(a: number, b: number, lmsToRgb: number[][], okCoeff: number[][][]): number;
162
+ function computeMaxSaturationOKLC(a: number, b: number, lmsToRgb: Matrix3x3, okCoeff: ColorGamutCoefficients): number;
160
163
  /**
161
164
  * Retrieves the LMS to RGB conversion matrix from the given gamut.
162
165
  * @param gamut - The gamut object.
@@ -216,6 +219,116 @@ declare module "@texel/color" {
216
219
  * @returns The OKHSV color as an array [h, s, v].
217
220
  */
218
221
  function OKLabToOKHSV(lab: Vector, gamut?: ColorGamut, out?: Vector): Vector;
222
+ /**
223
+ * The Adobe RGB (1998) color space in linear form, without a transfer function, aliased as <code>"a98-rgb-linear"</code>.
224
+ */
225
+ const A98RGBLinear: ColorSpace;
226
+ /**
227
+ * The Adobe RGB (1998) color space, with a transfer function, aliased as <code>"a98-rgb"</code>. Inherits from the {@link A98RGBLinear} color space.
228
+ */
229
+ const A98RGB: ColorSpace;
230
+ /**
231
+ * A color gamut for the {@link A98RGB}, or Adobe RGB (1998), color space.
232
+ */
233
+ const A98RGBGamut: ColorGamut;
234
+ /**
235
+ * The Display-P3 color space in linear form, without a transfer function, aliased as <code>"display-p3-linear"</code>.
236
+ */
237
+ const DisplayP3Linear: ColorSpace;
238
+ /**
239
+ * The Display-P3 color space, with a transfer function, aliased as <code>"display-p3"</code>. Inherits from the {@link DisplayP3Linear} color space.
240
+ */
241
+ const DisplayP3: ColorSpace;
242
+ /**
243
+ * A color gamut for the {@link DisplayP3} color space.
244
+ */
245
+ const DisplayP3Gamut: ColorGamut;
246
+ /**
247
+ * The OKLab color space.
248
+ */
249
+ const OKLab: ColorSpace;
250
+ /**
251
+ * The OKLCH color space, with Lightness, Chroma, and Hue components. This is the cylindrical form of the {@link OKLab} color space.
252
+ */
253
+ const OKLCH: ColorSpace;
254
+ /**
255
+ * An implementation of the OKHSL color space, fixed to the {@link sRGBGamut}. This is useful for color pickers and other applications where
256
+ * you wish to work with components in a well-defined and enclosed cylindrical form. If you wish to use OKHSL with a different gamut, you'll
257
+ * need to use the {@link OKHSLToOKLab} and {@link OKLabToOKHSL} methods directly, passing your desired gamut.
258
+ */
259
+ const OKHSL: ColorSpace;
260
+ /**
261
+ * An implementation of the OKHSV color space, fixed to the {@link sRGBGamut}. This is useful for color pickers and other applications where
262
+ * you wish to work with components in a well-defined and enclosed cylindrical form. If you wish to use OKHSL with a different gamut, you'll
263
+ * need to use the {@link OKHSLToOKLab} and {@link OKLabToOKHSL} methods directly, passing your desired gamut.
264
+ */
265
+ const OKHSV: ColorSpace;
266
+ /**
267
+ * The ProPhotoRGB color space in linear form, without a transfer function, aliased as <code>"prophoto-rgb-linear"</code>.
268
+ */
269
+ const ProPhotoRGBLinear: ColorSpace;
270
+ /**
271
+ * The ProPhotoRGB color space, with a transfer function, aliased as <code>"prophoto-rgb"</code>. Inherits from the {@link ProPhotoRGBLinear} color space.
272
+ */
273
+ const ProPhotoRGB: ColorSpace;
274
+ /**
275
+ * The Rec2020 color space in linear form, without a transfer function, aliased as <code>"rec2020-linear"</code>.
276
+ */
277
+ const Rec2020Linear: ColorSpace;
278
+ /**
279
+ * The Rec2020 color space, with a transfer function, aliased as <code>"rec2020"</code>. Inherits from the {@link Rec2020Linear} color space.
280
+ */
281
+ const Rec2020: ColorSpace;
282
+ /**
283
+ * A color gamut for the {@link Rec2020} color space.
284
+ */
285
+ const Rec2020Gamut: ColorGamut;
286
+ /**
287
+ * The sRGB color space in linear form, without a transfer function, aliased as <code>"srgb-linear"</code>.
288
+ */
289
+ const sRGBLinear: ColorSpace;
290
+ /**
291
+ * The sRGB color space, with a transfer function, aliased as <code>"srgb"</code>. Inherits from the {@link sRGBLinear} color space.
292
+ */
293
+ const sRGB: ColorSpace;
294
+ /**
295
+ * A color gamut for the {@link sRGB} color space.
296
+ */
297
+ const sRGBGamut: ColorGamut;
298
+ /**
299
+ * Converts a single sRGB gamma-corrected channel value to linear light (un-companded) form.
300
+ * @param val - The sRGB gamma-corrected channel value in the range [0, 1].
301
+ * @returns The linear light channel value.
302
+ */
303
+ function sRGBGammaToLinear(val: number): number;
304
+ /**
305
+ * Converts a single linear-light channel value to sRGB gamma-corrected form.
306
+ * @param val - The linear-light channel value in the range [0, 1].
307
+ * @returns The sRGB gamma-corrected channel value.
308
+ */
309
+ function sRGBLinearToGamma(val: number): number;
310
+ /**
311
+ * Converts a color from XYZ with D65 whitepoint to XYZ with D50 whitepoint.
312
+ * @param XYZ - The input color in XYZ with D65 whitepoint.
313
+ * @param [out = vec3()] - The output color in XYZ with D50 whitepoint.
314
+ * @returns The converted color in XYZ with D50 whitepoint.
315
+ */
316
+ function XYZD65ToD50(XYZ: Vector, out?: Vector): Vector;
317
+ /**
318
+ * Converts a color from XYZ with D50 whitepoint to XYZ with D65 whitepoint.
319
+ * @param XYZ - The input color in XYZ with D50 whitepoint.
320
+ * @param [out = vec3()] - The output color in XYZ with D65 whitepoint.
321
+ * @returns The converted color in XYZ with D65 whitepoint.
322
+ */
323
+ function XYZD50ToD65(XYZ: Vector, out?: Vector): Vector;
324
+ /**
325
+ * XYZ color space with D65 whitepoint, aliased as <code>"xyz"</code>.
326
+ */
327
+ const XYZ: ColorSpace;
328
+ /**
329
+ * XYZ color space with D50 whitepoint, aliased as <code>"xyz-d50"</code>.
330
+ */
331
+ const XYZD50: ColorSpace;
219
332
  /**
220
333
  * Returns a list of color spaces.
221
334
  * @returns An array of color space objects.