@texel/color 1.1.9 → 1.1.11

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.
@@ -0,0 +1,14 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(npm ls:*)",
5
+ "Bash(wc:*)",
6
+ "Bash(npm audit:*)",
7
+ "Bash(npm test:*)",
8
+ "Bash(cat:*)",
9
+ "Bash(ls:*)",
10
+ "Bash(node --version:*)",
11
+ "Bash(npm:*)"
12
+ ]
13
+ }
14
+ }
package/LICENSE.md CHANGED
@@ -1,5 +1,5 @@
1
1
  The MIT License (MIT)
2
- Copyright (c) 2024 Matt DesLauriers
2
+ Copyright (c) Matt DesLauriers
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -342,7 +342,7 @@ The library currently only exposes `{ lerp, lerpAngle }` functions. To interpola
342
342
 
343
343
  ## Custom Color Spaces
344
344
 
345
- You can build custom color space objects to extend this library, such as adding support for CIELab and HSL. See [test/spaces/lab.js](./test/spaces/lab.js) and [test/spaces/hsl.js](./test/spaces/hsl.js) for examples of this. Some of these spaces may be added to the library at a later point, although the current focus is on "modern" spaces (such as OKLab that has largely made CIELab and HSL obsolete). Documentaiton on custom color spaces is WIP.
345
+ You can build custom color space objects to extend this library, such as adding support for CIELab and HSL. See [test/spaces/lab.js](./test/spaces/lab.js) and [test/spaces/hsl.js](./test/spaces/hsl.js) for examples of this. Some of these spaces may be added to the library at a later point, although the current focus is on "modern" spaces (such as OKLab that has largely made CIELab and HSL obsolete). Documentation on custom color spaces is WIP.
346
346
 
347
347
  ## Notes
348
348
 
@@ -350,9 +350,9 @@ You can build custom color space objects to extend this library, such as adding
350
350
 
351
351
  [Colorjs](https://colorjs.io/) is fantastic and perhaps the current leading standard in JavaScript, but it's not very practical for creative coding and real-time web applications, where the requirements are often (1) leaner codebases, (2) highly optimized, and (3) minimal GC thrashing.
352
352
 
353
- Colorjs, and simialrly, [Culori](https://culorijs.org/), are focused on matching CSS spec, which means it will very likely continue to grow in complexity over time, and performance will often be marred (for example, `@texel/color` cusp intersection gamut mapping is ~125 times faster than Colorjs and ~60 times faster than culori).
353
+ Colorjs, and similarly, [Culori](https://culorijs.org/), are focused on matching CSS spec, which means it will very likely continue to grow in complexity over time, and performance will often be marred (for example, `@texel/color` cusp intersection gamut mapping is ~125 times faster than Colorjs and ~60 times faster than culori).
354
354
 
355
- There are many other options such as [color-space](https://www.npmjs.com/package/color-space) or [color-convert](https://www.npmjs.com/package/color-convert), however, these do not support modern spacse such as OKLab and OKHSL, and/or have dubious levels of accuracy (many libraries, for example, do not distinguish between D50 and D65 whitepoints in XYZ).
355
+ There are many other options such as [color-space](https://www.npmjs.com/package/color-space) or [color-convert](https://www.npmjs.com/package/color-convert), however, these do not support modern spaces such as OKLab and OKHSL, and/or have dubious levels of accuracy (many libraries, for example, do not distinguish between D50 and D65 whitepoints in XYZ).
356
356
 
357
357
  ### Supported Spaces
358
358
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@texel/color",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "a minimal and modern color library",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -23,6 +23,7 @@
23
23
  "esbuild": "^0.23.0",
24
24
  "faucet": "^0.0.4",
25
25
  "jsdoc": "^4.0.4",
26
+ "jsdoc-memberof-namespace": "^2.2.0",
26
27
  "pako": "^2.1.0",
27
28
  "png-tools": "^1.0.4",
28
29
  "prettier": "^3.3.3",
@@ -34,7 +35,7 @@
34
35
  "visualize": "canvas-sketch-cli test/canvas-graph.js --open",
35
36
  "docs": "jsdoc src -r -t node_modules/better-docs -c tools/.jsdoc.json -d docs -R DOC.md",
36
37
  "types": "jsdoc src -r -t node_modules/tsd-jsdoc/dist -c tools/.jsdoc.types.json -d .",
37
- "test": "faucet test/test*.js",
38
+ "test": "node test/test.js | faucet",
38
39
  "bench": "node test/bench-colorjs.js",
39
40
  "bench:node": "NODE_ENV=production node --prof --no-logfile-per-isolate test/bench-node.js && node --prof-process v8.log",
40
41
  "bench:size": "esbuild test/bench-size.js --format=esm --bundle --minify --tree-shaking=true | wc -c",
package/src/core.js CHANGED
@@ -146,7 +146,7 @@ export const serialize = (input, inputSpace, outputSpace = inputSpace) => {
146
146
  convert(input, inputSpace, outputSpace, tmp3);
147
147
  }
148
148
  const id = outputSpace.id;
149
- if (id == "srgb") {
149
+ if (id === "srgb") {
150
150
  // uses the legacy rgb() format
151
151
  const r = floatToByte(tmp3[0]);
152
152
  const g = floatToByte(tmp3[1]);
@@ -155,7 +155,7 @@ export const serialize = (input, inputSpace, outputSpace = inputSpace) => {
155
155
  return alpha === 1 ? `rgb(${rgb})` : `rgba(${rgb}, ${alpha})`;
156
156
  } else {
157
157
  const alphaSuffix = alpha === 1 ? "" : ` / ${alpha}`;
158
- if (id == "oklab" || id == "oklch") {
158
+ if (id === "oklab" || id === "oklch") {
159
159
  // older versions of Safari don't support oklch with 0..1 L but do support %
160
160
  return `${id}(${tmp3[0] * 100}% ${tmp3[1]} ${tmp3[2]}${alphaSuffix})`;
161
161
  } else {
@@ -296,7 +296,7 @@ export const parse = (input, targetSpace, out = vec3()) => {
296
296
  // store alpha
297
297
  if (alpha !== 1) out[3] = alpha;
298
298
  // reduce to 3D
299
- if (alpha == 1 && out.length === 4) out.pop();
299
+ if (alpha === 1 && out.length === 4) out.pop();
300
300
  return out;
301
301
  };
302
302
 
@@ -318,7 +318,7 @@ export const convert = (input, fromSpace, toSpace, out = vec3()) => {
318
318
  if (!toSpace) throw new Error(`must specify a toSpace`);
319
319
 
320
320
  // special case: no conversion needed
321
- if (fromSpace == toSpace) {
321
+ if (fromSpace === toSpace) {
322
322
  return out;
323
323
  }
324
324
 
package/src/gamut.js CHANGED
@@ -345,7 +345,7 @@ export const gamutMapOKLCH = (
345
345
  const lmsToRgb = gamutSpaceBase.fromLMS_M;
346
346
  if (!lmsToRgb) {
347
347
  throw new Error(
348
- `color space ${outSpace.id} has no base with LMS to RGB matrix`
348
+ `color space ${gamutSpaceBase.id} has no base with LMS to RGB matrix`
349
349
  );
350
350
  }
351
351
 
@@ -406,7 +406,7 @@ export const gamutMapOKLCH = (
406
406
  // will be applied. The OKLCH result is _basically_ in gamut, but not exactly; you'll need to clip at final stage.
407
407
  // I've documented this behaviour in the readme.
408
408
  const targetSpaceBase = targetSpace.base ?? targetSpace;
409
- if (targetSpaceBase.id == "oklab") {
409
+ if (targetSpaceBase.id === "oklab") {
410
410
  return convert(out, OKLCH, targetSpace, out);
411
411
  }
412
412
 
package/src/okhsl.js CHANGED
@@ -371,7 +371,7 @@ export const OKLabToOKHSV = (lab, gamut = sRGBGamut, out = vec3()) => {
371
371
  s = ((s0 + tMax) * cv) / (tMax * s0 + tMax * k * cv);
372
372
  }
373
373
 
374
- // unlike colorjs.io, we are not worknig with none-types
374
+ // unlike colorjs.io, we are not working with none-types
375
375
  // if (Math.abs(s) < ε || v === 0.0) {
376
376
  // h = null;
377
377
  // }
package/src/util.js CHANGED
@@ -84,6 +84,8 @@ export const RGBToHex = (rgb) =>
84
84
  /**
85
85
  * @method
86
86
  * @deprecated Use RGBToHex instead.
87
+ * @param {Vector} rgb The RGB array.
88
+ * @returns {string} The hex color string.
87
89
  * @category rgb
88
90
  */
89
91
  export const RGBtoHex = RGBToHex;
@@ -92,11 +94,11 @@ export const RGBtoHex = RGBToHex;
92
94
  * Checks if an RGB color is within the gamut.
93
95
  * @method
94
96
  * @param {Vector} lrgb The linear RGB array.
95
- * @param {number} [ep=GAMUT_EPSILON] The epsilon value for comparison.
97
+ * @param {number} [ep=0] The epsilon value for comparison.
96
98
  * @returns {boolean} True if the color is within the gamut, false otherwise.
97
99
  * @category rgb
98
100
  */
99
- export const isRGBInGamut = (lrgb, ep = GAMUT_EPSILON) => {
101
+ export const isRGBInGamut = (lrgb, ep = 0) => {
100
102
  const r = lrgb[0];
101
103
  const g = lrgb[1];
102
104
  const b = lrgb[2];
package/types.d.ts CHANGED
@@ -386,11 +386,15 @@ declare module "@texel/color" {
386
386
  * @returns The hex color string.
387
387
  */
388
388
  function RGBToHex(rgb: Vector): string;
389
- function RGBtoHex(): void;
389
+ /**
390
+ * @param rgb - The RGB array.
391
+ * @returns The hex color string.
392
+ */
393
+ function RGBtoHex(rgb: Vector): string;
390
394
  /**
391
395
  * Checks if an RGB color is within the gamut.
392
396
  * @param lrgb - The linear RGB array.
393
- * @param [ep = GAMUT_EPSILON] - The epsilon value for comparison.
397
+ * @param [ep = 0] - The epsilon value for comparison.
394
398
  * @returns True if the color is within the gamut, false otherwise.
395
399
  */
396
400
  function isRGBInGamut(lrgb: Vector, ep?: number): boolean;