@thi.ng/color 5.6.45 → 5.6.47
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/CHANGELOG.md +18 -1
- package/README.md +29 -25
- package/analog.d.ts +7 -3
- package/analog.js +24 -24
- package/api.d.ts +5 -1
- package/color-range.js +11 -11
- package/convert.d.ts +2 -2
- package/defcolor.js +4 -4
- package/distance.js +5 -5
- package/gradients.d.ts +0 -1
- package/gradients.js +3 -3
- package/int/int.js +5 -5
- package/internal/css.js +3 -2
- package/is-black.d.ts +2 -3
- package/is-black.js +7 -7
- package/is-gray.d.ts +2 -3
- package/is-gray.js +7 -7
- package/is-white.d.ts +2 -3
- package/is-white.js +7 -7
- package/lab/lab-xyz.js +4 -4
- package/package.json +19 -19
- package/sort.d.ts +2 -2
- package/transform.d.ts +3 -3
- package/transform.js +1 -1
- package/xyz/wavelength-xyz.js +4 -4
- package/xyz/xyz-lab.js +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-29T09:28:35Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,23 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [5.6.47](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.6.47) (2024-06-29)
|
|
13
|
+
|
|
14
|
+
#### 🩹 Bug fixes
|
|
15
|
+
|
|
16
|
+
- update color ctor handling for single ARGB int args ([8ab6083](https://github.com/thi-ng/umbrella/commit/8ab6083))
|
|
17
|
+
- interpret sole int arg as sRGB, **not** as linear RGB
|
|
18
|
+
- add tests
|
|
19
|
+
|
|
20
|
+
### [5.6.46](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.6.46) (2024-06-21)
|
|
21
|
+
|
|
22
|
+
#### ♻️ Refactoring
|
|
23
|
+
|
|
24
|
+
- rename various rest args to be more semantically meaningful ([8088a56](https://github.com/thi-ng/umbrella/commit/8088a56))
|
|
25
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
26
|
+
- dedupe types for isBlack/Gray/White() fns ([a00705d](https://github.com/thi-ng/umbrella/commit/a00705d))
|
|
27
|
+
- minor dedupe lab/lch CSS serialization ([19df487](https://github.com/thi-ng/umbrella/commit/19df487))
|
|
28
|
+
|
|
12
29
|
### [5.6.42](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.6.42) (2024-04-20)
|
|
13
30
|
|
|
14
31
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 189 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -676,7 +676,7 @@ For Node.js REPL:
|
|
|
676
676
|
const color = await import("@thi.ng/color");
|
|
677
677
|
```
|
|
678
678
|
|
|
679
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 15.
|
|
679
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 15.67 KB
|
|
680
680
|
|
|
681
681
|
## Dependencies
|
|
682
682
|
|
|
@@ -700,29 +700,33 @@ Several projects in this repo's
|
|
|
700
700
|
[/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
|
|
701
701
|
directory are using this package:
|
|
702
702
|
|
|
703
|
-
| Screenshot | Description
|
|
704
|
-
|
|
705
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/boid-basics.png" width="240"/> | Basic 2D boid simulation and spatial indexing neighbor lookups
|
|
706
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/color-themes.png" width="240"/> | Probabilistic color theme generator
|
|
707
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/commit-heatmap.png" width="240"/> | Heatmap visualization of this mono-repo's commits
|
|
708
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/dominant-colors.png" width="240"/> | Color palette generation via dominant color extraction from uploaded images
|
|
709
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/fiber-basics.png" width="240"/> | Fiber-based cooperative multitasking basics
|
|
710
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-complex-poly.png" width="240"/> | Shape conversions & operations using polygons with holes
|
|
711
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
712
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/
|
|
713
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
714
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
715
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
716
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/
|
|
717
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
718
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
719
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
720
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
721
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
722
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
723
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
724
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
725
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
703
|
+
| Screenshot | Description | Live demo | Source |
|
|
704
|
+
|:-------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------|:-------------------------------------------------------------|:------------------------------------------------------------------------------------------|
|
|
705
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/boid-basics.png" width="240"/> | Basic 2D boid simulation and spatial indexing neighbor lookups | [Demo](https://demo.thi.ng/umbrella/boid-basics/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/boid-basics) |
|
|
706
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/color-themes.png" width="240"/> | Probabilistic color theme generator | [Demo](https://demo.thi.ng/umbrella/color-themes/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/color-themes) |
|
|
707
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/commit-heatmap.png" width="240"/> | Heatmap visualization of this mono-repo's commits | | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/commit-heatmap) |
|
|
708
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/dominant-colors.png" width="240"/> | Color palette generation via dominant color extraction from uploaded images | [Demo](https://demo.thi.ng/umbrella/dominant-colors/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/dominant-colors) |
|
|
709
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/fiber-basics.png" width="240"/> | Fiber-based cooperative multitasking basics | [Demo](https://demo.thi.ng/umbrella/fiber-basics/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/fiber-basics) |
|
|
710
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-complex-poly.png" width="240"/> | Shape conversions & operations using polygons with holes | [Demo](https://demo.thi.ng/umbrella/geom-complex-poly/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-complex-poly) |
|
|
711
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-csv-piechart.png" width="240"/> | Piechart visualization of CSV data | [Demo](https://demo.thi.ng/umbrella/geom-csv-piechart/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-csv-piechart) |
|
|
712
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-unique-edges.png" width="240"/> | Iterating the unique edges of a tessellation | [Demo](https://demo.thi.ng/umbrella/geom-unique-edges/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-unique-edges) |
|
|
713
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-webgl-attrib-pool.jpg" width="240"/> | Augmenting thi.ng/geom shapes for WebGL, using instancing & attribute buffers | [Demo](https://demo.thi.ng/umbrella/geom-webgl-attrib-pool/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-webgl-attrib-pool) |
|
|
714
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-webgl-basics.jpg" width="240"/> | Converting thi.ng/geom shape types for WebGL | [Demo](https://demo.thi.ng/umbrella/geom-webgl-basics/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-webgl-basics) |
|
|
715
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/grid-iterators.png" width="240"/> | Visualization of different grid iterator strategies | [Demo](https://demo.thi.ng/umbrella/grid-iterators/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/grid-iterators) |
|
|
716
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/hdom-canvas/hdom-canvas-shapes-results.png" width="240"/> | Various hdom-canvas shape drawing examples & SVG conversion / export | [Demo](https://demo.thi.ng/umbrella/hdom-canvas-shapes/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/hdom-canvas-shapes) |
|
|
717
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/hiccup-canvas-basics.png" width="240"/> | Basic hiccup-based canvas drawing | [Demo](https://demo.thi.ng/umbrella/hiccup-canvas-basics/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/hiccup-canvas-basics) |
|
|
718
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/kmeans-viz.jpg" width="240"/> | k-means clustering visualization | [Demo](https://demo.thi.ng/umbrella/kmeans-viz/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/kmeans-viz) |
|
|
719
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-colormatrix.jpg" width="240"/> | Matrix-based image color adjustments | [Demo](https://demo.thi.ng/umbrella/pixel-colormatrix/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pixel-colormatrix) |
|
|
720
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-gradients.jpg" width="240"/> | Randomized 4-point 2D color gradient image generator | [Demo](https://demo.thi.ng/umbrella/pixel-gradients/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pixel-gradients) |
|
|
721
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-indexed.jpg" width="240"/> | Image dithering and remapping using indexed palettes | [Demo](https://demo.thi.ng/umbrella/pixel-indexed/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pixel-indexed) |
|
|
722
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-sorting.png" width="240"/> | Interactive pixel sorting tool using thi.ng/color & thi.ng/pixel | [Demo](https://demo.thi.ng/umbrella/pixel-sorting/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pixel-sorting) |
|
|
723
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/poly-subdiv.jpg" width="240"/> | Animated, iterative polygon subdivisions & visualization | [Demo](https://demo.thi.ng/umbrella/poly-subdiv/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/poly-subdiv) |
|
|
724
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-reactive-svg.jpg" width="240"/> | Animated SVG elements with reactive attributes | [Demo](https://demo.thi.ng/umbrella/rdom-reactive-svg/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-reactive-svg) |
|
|
725
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-workers.jpg" width="240"/> | Fork-join worker-based raymarch renderer (JS/CPU only) | [Demo](https://demo.thi.ng/umbrella/shader-ast-workers/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-workers) |
|
|
726
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/simd-plot.png" width="240"/> | Fitting, transforming & plotting 10k data points per frame using SIMD | [Demo](https://demo.thi.ng/umbrella/simd-plot/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/simd-plot) |
|
|
727
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/stacked-layout.png" width="240"/> | Responsive & reactively computed stacked column layout | [Demo](https://demo.thi.ng/umbrella/stacked-layout/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/stacked-layout) |
|
|
728
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/trace-bitmap.jpg" width="240"/> | Multi-layer vectorization & dithering of bitmap images | [Demo](https://demo.thi.ng/umbrella/trace-bitmap/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/trace-bitmap) |
|
|
729
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-texture-paint.jpg" width="240"/> | Interactively drawing to & reading from a WebGL offscreen render texture | [Demo](https://demo.thi.ng/umbrella/webgl-texture-paint/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-texture-paint) |
|
|
726
730
|
|
|
727
731
|
## API
|
|
728
732
|
|
package/analog.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type { Fn3,
|
|
1
|
+
import type { Fn3, FnU3 } from "@thi.ng/api";
|
|
2
|
+
import type { MultiFn3O } from "@thi.ng/defmulti";
|
|
2
3
|
import type { IRandom } from "@thi.ng/random";
|
|
3
4
|
import type { Color, ReadonlyColor, TypedColor } from "./api.js";
|
|
4
|
-
export
|
|
5
|
+
export type AnalogFn = {
|
|
6
|
+
(out: Color | null, src: TypedColor<any>, delta: number, rnd?: IRandom): Color;
|
|
7
|
+
} & MultiFn3O<Color | null, TypedColor<any>, number, IRandom, Color>;
|
|
8
|
+
export declare const defAnalog: FnU3<Fn3<number, number, IRandom, number>, (out: Color | null, src: TypedColor<any>, delta: number, rnd?: IRandom) => Color>;
|
|
5
9
|
/**
|
|
6
10
|
* Returns a random analog color based on given `src` color and variance
|
|
7
11
|
* `delta`. Each channel will be randomized by +/- `delta`, optionally using
|
|
@@ -13,7 +17,7 @@ export declare const defAnalog: FnU3<Fn3<number, number, IRandom, number>, Fn4<C
|
|
|
13
17
|
* If `out` is null, the resulting color will be written back into `src`.
|
|
14
18
|
*
|
|
15
19
|
*/
|
|
16
|
-
export declare const analog:
|
|
20
|
+
export declare const analog: AnalogFn;
|
|
17
21
|
/**
|
|
18
22
|
* Similar to {@link analogRgb}. Returns an analog color based on given HSVA
|
|
19
23
|
* color, with each channel randomly varied by given channel-specific delta
|
package/analog.js
CHANGED
|
@@ -5,10 +5,10 @@ import { SYSTEM } from "@thi.ng/random/system";
|
|
|
5
5
|
import { setC4 } from "@thi.ng/vectors/setc";
|
|
6
6
|
import { __dispatch1 } from "./internal/dispatch.js";
|
|
7
7
|
import { __ensureAlpha } from "./internal/ensure.js";
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
8
|
+
const __analogU = (x, delta, rnd) => delta !== 0 ? x + rnd.norm(delta) : x;
|
|
9
|
+
const __analogN = (x, delta, rnd, post = clamp01) => delta !== 0 ? post(x + rnd.norm(delta)) : x;
|
|
10
|
+
const __analogH = (x, delta, rnd) => __analogN(x, delta, rnd, fract);
|
|
11
|
+
const __analogA = (a, delta, rnd) => delta !== 0 ? clamp01((a !== void 0 ? a : 1) + rnd.norm(delta)) : __ensureAlpha(a);
|
|
12
12
|
const defAnalog = (x, y, z) => (out, src, delta, rnd = SYSTEM) => setC4(
|
|
13
13
|
out || src,
|
|
14
14
|
x(src[0], delta, rnd),
|
|
@@ -16,37 +16,37 @@ const defAnalog = (x, y, z) => (out, src, delta, rnd = SYSTEM) => setC4(
|
|
|
16
16
|
z(src[2], delta, rnd),
|
|
17
17
|
__ensureAlpha(src[3])
|
|
18
18
|
);
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
19
|
+
const __analogHNN = defAnalog(__analogH, __analogN, __analogN);
|
|
20
|
+
const __analogNNN = defAnalog(__analogN, __analogN, __analogN);
|
|
21
|
+
const __analogNUU = defAnalog(__analogN, __analogU, __analogU);
|
|
22
22
|
const analog = defmulti(
|
|
23
23
|
__dispatch1,
|
|
24
24
|
{ oklab: "lab50", oklch: "lch" },
|
|
25
25
|
{
|
|
26
|
-
hcy:
|
|
27
|
-
hsi:
|
|
28
|
-
hsl:
|
|
29
|
-
hsv:
|
|
30
|
-
lab50:
|
|
31
|
-
lab65:
|
|
32
|
-
lch: defAnalog(
|
|
33
|
-
ycc:
|
|
34
|
-
[DEFAULT]:
|
|
26
|
+
hcy: __analogHNN,
|
|
27
|
+
hsi: __analogHNN,
|
|
28
|
+
hsl: __analogHNN,
|
|
29
|
+
hsv: __analogHNN,
|
|
30
|
+
lab50: __analogNUU,
|
|
31
|
+
lab65: __analogNUU,
|
|
32
|
+
lch: defAnalog(__analogN, __analogN, __analogH),
|
|
33
|
+
ycc: __analogNUU,
|
|
34
|
+
[DEFAULT]: __analogNNN
|
|
35
35
|
}
|
|
36
36
|
);
|
|
37
37
|
const analogHsv = (out, src, deltaH, deltaS = 0, deltaV = 0, deltaA = 0, rnd = SYSTEM) => setC4(
|
|
38
38
|
out || src,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
__analogN(src[0], deltaH, rnd, fract),
|
|
40
|
+
__analogN(src[1], deltaS, rnd),
|
|
41
|
+
__analogN(src[2], deltaV, rnd),
|
|
42
|
+
__analogA(src[3], deltaA, rnd)
|
|
43
43
|
);
|
|
44
44
|
const analogRgb = (out, src, deltaR, deltaG = deltaR, deltaB = deltaR, deltaA = 0, rnd = SYSTEM) => setC4(
|
|
45
45
|
out || src,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
__analogN(src[0], deltaR, rnd),
|
|
47
|
+
__analogN(src[1], deltaG, rnd),
|
|
48
|
+
__analogN(src[2], deltaB, rnd),
|
|
49
|
+
__analogA(src[3], deltaA, rnd)
|
|
50
50
|
);
|
|
51
51
|
export {
|
|
52
52
|
analog,
|
package/api.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FnU2, IDeref, IEqualsDelta, NumericArray, Range, Tuple } from "@thi.ng/api";
|
|
2
|
+
import type { MultiFn1O } from "@thi.ng/defmulti";
|
|
2
3
|
import type { IRandom } from "@thi.ng/random";
|
|
3
4
|
import type { IVector, ReadonlyVec, Vec } from "@thi.ng/vectors";
|
|
4
5
|
export type Color = Vec;
|
|
@@ -82,7 +83,7 @@ export type Conversions = Partial<Record<ColorMode, ColorOp>> & {
|
|
|
82
83
|
export interface ColorFactory<T extends TypedColor<any>> {
|
|
83
84
|
(col: MaybeColor, buf?: NumericArray, idx?: number, stride?: number): T;
|
|
84
85
|
(col?: Vec, idx?: number, stride?: number): T;
|
|
85
|
-
(a: number, b: number, c: number, ...
|
|
86
|
+
(a: number, b: number, c: number, ...args: number[]): T;
|
|
86
87
|
readonly class: TypedColorConstructor<T>;
|
|
87
88
|
/**
|
|
88
89
|
* Returns a new random color, optionally backed by given memory. I.e. if
|
|
@@ -196,4 +197,7 @@ export declare class ParsedColor implements IParsedColor {
|
|
|
196
197
|
export type ColorMatrix = Tuple<number, 20>;
|
|
197
198
|
export type ColorDistance<T = ReadonlyColor> = FnU2<T, number>;
|
|
198
199
|
export type ColorMixFn<T = ReadonlyColor> = (out: Color | null, a: T, b: T, t: number) => Color;
|
|
200
|
+
export type IsGrayFn = {
|
|
201
|
+
(col: TypedColor<any>, eps?: number): boolean;
|
|
202
|
+
} & MultiFn1O<TypedColor<any>, number, boolean>;
|
|
199
203
|
//# sourceMappingURL=api.d.ts.map
|
package/color-range.js
CHANGED
|
@@ -136,12 +136,12 @@ function* colorsFromRange(range, opts = {}) {
|
|
|
136
136
|
let num = opts.num != void 0 ? opts.num : Infinity;
|
|
137
137
|
while (num-- > 0) yield colorFromRange(range, opts);
|
|
138
138
|
}
|
|
139
|
-
const
|
|
139
|
+
const __compileThemePart = (part, opts) => {
|
|
140
140
|
let spec;
|
|
141
141
|
if (isArray(part)) {
|
|
142
|
-
spec =
|
|
142
|
+
spec = __themePartFromTuple(part);
|
|
143
143
|
} else if (isString(part)) {
|
|
144
|
-
spec =
|
|
144
|
+
spec = __themePartFromString(part);
|
|
145
145
|
} else {
|
|
146
146
|
spec = { ...part };
|
|
147
147
|
spec.weight == null && (spec.weight = 1);
|
|
@@ -153,21 +153,21 @@ const compileThemePart = (part, opts) => {
|
|
|
153
153
|
}
|
|
154
154
|
return { spec, opts };
|
|
155
155
|
};
|
|
156
|
-
const
|
|
156
|
+
const __themePartFromTuple = (part) => {
|
|
157
157
|
let weight;
|
|
158
|
-
const [range, ...
|
|
159
|
-
if (isNumber(peek(
|
|
160
|
-
weight = peek(
|
|
161
|
-
|
|
158
|
+
const [range, ...args] = part;
|
|
159
|
+
if (isNumber(peek(args))) {
|
|
160
|
+
weight = peek(args);
|
|
161
|
+
args.pop();
|
|
162
162
|
} else {
|
|
163
163
|
weight = 1;
|
|
164
164
|
}
|
|
165
|
-
return
|
|
165
|
+
return args.length === 1 ? { range, base: args[0], weight } : args.length === 0 ? COLOR_RANGES[range] ? { range, weight } : { base: range, weight } : illegalArgs(`invalid theme part: "${part}"`);
|
|
166
166
|
};
|
|
167
|
-
const
|
|
167
|
+
const __themePartFromString = (part) => COLOR_RANGES[part] ? { range: part, weight: 1 } : { base: part, weight: 1 };
|
|
168
168
|
function* colorsFromTheme(parts, opts = {}) {
|
|
169
169
|
let { num, variance, rnd } = { ...DEFAULT_OPTS, ...opts };
|
|
170
|
-
const theme = parts.map((p) =>
|
|
170
|
+
const theme = parts.map((p) => __compileThemePart(p, opts));
|
|
171
171
|
const choice = weightedRandom(
|
|
172
172
|
theme,
|
|
173
173
|
theme.map((x) => x.spec.weight),
|
package/convert.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ColorMode, ColorSpec, Conversions, ReadonlyColor } from "./api.js";
|
|
1
|
+
import type { Color, ColorMode, ColorSpec, Conversions, ReadonlyColor } from "./api.js";
|
|
2
2
|
export declare const CONVERSIONS: Partial<Record<ColorMode, Conversions>>;
|
|
3
3
|
/**
|
|
4
4
|
* Registers conversions for given {@link ColorSpec}. Called by
|
|
@@ -18,5 +18,5 @@ export declare const defConversions: (mode: ColorMode, spec: ColorSpec<any, any>
|
|
|
18
18
|
* @param destMode
|
|
19
19
|
* @param srcMode
|
|
20
20
|
*/
|
|
21
|
-
export declare const convert: <T extends
|
|
21
|
+
export declare const convert: <T extends Color>(res: T | null, src: ReadonlyColor, destMode: ColorMode, srcMode: ColorMode) => T;
|
|
22
22
|
//# sourceMappingURL=convert.d.ts.map
|
package/defcolor.js
CHANGED
|
@@ -15,7 +15,7 @@ import { randMinMax } from "@thi.ng/vectors/rand-minmax";
|
|
|
15
15
|
import { set4 } from "@thi.ng/vectors/set";
|
|
16
16
|
import { convert, defConversions } from "./convert.js";
|
|
17
17
|
import { parseCss } from "./css/parse-css.js";
|
|
18
|
-
import {
|
|
18
|
+
import { intArgb32Srgb } from "./int/int-srgb.js";
|
|
19
19
|
import { __ensureArgs } from "./internal/ensure.js";
|
|
20
20
|
const defColor = (spec) => {
|
|
21
21
|
const channels = spec.channels || {};
|
|
@@ -102,11 +102,11 @@ const defColor = (spec) => {
|
|
|
102
102
|
declareIndices($Color.prototype, order);
|
|
103
103
|
defConversions(spec.mode, spec.from);
|
|
104
104
|
defConversions("rgb", { [spec.mode]: spec.toRgb });
|
|
105
|
-
const fromColor = (src, mode,
|
|
106
|
-
const res = new $Color(...
|
|
105
|
+
const fromColor = (src, mode, args) => {
|
|
106
|
+
const res = new $Color(...args);
|
|
107
107
|
return mode !== spec.mode ? convert(res, src, spec.mode, mode) : res.set(src);
|
|
108
108
|
};
|
|
109
|
-
const factory = (src, ...
|
|
109
|
+
const factory = (src, ...args) => src == null ? new $Color() : isString(src) ? factory(parseCss(src), ...args) : isArrayLike(src) ? isString(src.mode) ? fromColor(src, src.mode, args) : new $Color(src, ...args) : implementsFunction(src, "deref") ? fromColor(src.deref(), src.mode, args) : isNumber(src) ? args.length && args.every(isNumber) ? new $Color(...__ensureArgs([src, ...args])) : fromColor(intArgb32Srgb([], src), "srgb", args) : illegalArgs(`can't create a ${spec.mode} color from: ${src}`);
|
|
110
110
|
factory.class = $Color;
|
|
111
111
|
factory.range = [min, max];
|
|
112
112
|
factory.random = (rnd, buf, idx, stride) => new $Color(buf, idx, stride).randomize(rnd);
|
package/distance.js
CHANGED
|
@@ -40,15 +40,15 @@ const distCIEDE2000 = (weights = ONE3) => (a, b) => {
|
|
|
40
40
|
const c1ab = hypot(a1, b1);
|
|
41
41
|
const c2ab = hypot(a2, b2);
|
|
42
42
|
const cab = (c1ab + c2ab) * 0.5;
|
|
43
|
-
const g = 1 + 0.5 * (1 -
|
|
43
|
+
const g = 1 + 0.5 * (1 - __c7Coeff(cab));
|
|
44
44
|
a1 *= g;
|
|
45
45
|
a2 *= g;
|
|
46
46
|
const c1 = hypot(a1, b1);
|
|
47
47
|
const c2 = hypot(a2, b2);
|
|
48
48
|
const cmean = (c1 + c2) * 0.5;
|
|
49
|
-
const { deltaH, H } =
|
|
49
|
+
const { deltaH, H } = __computeDeltaH(a1, b1, a2, b2, c1, c2);
|
|
50
50
|
const T = 1 - 0.17 * cos(H - SIXTH_PI) + 0.24 * cos(2 * H) + 0.32 * cos(3 * H + H6) - 0.2 * cos(4 * H - H63);
|
|
51
|
-
const Rt = -2 *
|
|
51
|
+
const Rt = -2 * __c7Coeff(cmean) * sin(THIRD_PI * Math.exp(-(((H - H275) / H25) ** 2)));
|
|
52
52
|
const L50 = ((l1 + l2) * 0.5 - 50) ** 2;
|
|
53
53
|
const Sl = 1 + 0.015 * L50 / sqrt(20 + L50);
|
|
54
54
|
const Sc = 1 + 0.045 * cmean;
|
|
@@ -58,11 +58,11 @@ const distCIEDE2000 = (weights = ONE3) => (a, b) => {
|
|
|
58
58
|
const termH = deltaH / (weights[2] * Sh);
|
|
59
59
|
return sqrt(termL ** 2 + termC ** 2 + termH ** 2 + Rt * termC * termH);
|
|
60
60
|
};
|
|
61
|
-
const
|
|
61
|
+
const __c7Coeff = (c) => {
|
|
62
62
|
c = c ** 7;
|
|
63
63
|
return sqrt(c / (c + 25 ** 7));
|
|
64
64
|
};
|
|
65
|
-
const
|
|
65
|
+
const __computeDeltaH = (a1, b1, a2, b2, c1, c2, eps = 1e-3) => {
|
|
66
66
|
const h1 = atan2Abs(b1, a1);
|
|
67
67
|
const h2 = atan2Abs(b2, a2);
|
|
68
68
|
if (c1 <= eps || c2 <= eps) return { deltaH: 0, H: h1 + h2 };
|
package/gradients.d.ts
CHANGED
|
@@ -47,7 +47,6 @@ import type { GradientOpts } from "./api/gradients.js";
|
|
|
47
47
|
* ```
|
|
48
48
|
*
|
|
49
49
|
* @param opts -
|
|
50
|
-
* @param isABGR -
|
|
51
50
|
*/
|
|
52
51
|
export declare function multiColorGradient<T extends TypedColor<any>>(opts: GradientOpts<T>): T[];
|
|
53
52
|
export declare function multiColorGradient<T extends TypedColor<any>>(opts: GradientOpts<T>, isABGR: boolean): number[];
|
package/gradients.js
CHANGED
|
@@ -4,19 +4,19 @@ import { intArgb32Abgr32 } from "./int/int-int.js";
|
|
|
4
4
|
import { argb32 } from "./int/int.js";
|
|
5
5
|
import { mix as $mix } from "./mix.js";
|
|
6
6
|
function multiColorGradient(opts, isABGR) {
|
|
7
|
-
const cols = [...
|
|
7
|
+
const cols = [...__gradient(opts)];
|
|
8
8
|
if (isABGR === void 0) return cols;
|
|
9
9
|
const rgba = cols.map((x) => argb32(x)[0]);
|
|
10
10
|
return isABGR ? rgba.map(intArgb32Abgr32) : rgba;
|
|
11
11
|
}
|
|
12
12
|
const multiColorGradientBuffer = (opts, buffer = [], offset = 0, cstride = 1, estride = 4) => {
|
|
13
|
-
for (let col of
|
|
13
|
+
for (let col of __gradient(opts)) {
|
|
14
14
|
setS4(buffer, col, offset, 0, cstride);
|
|
15
15
|
offset += estride;
|
|
16
16
|
}
|
|
17
17
|
return buffer;
|
|
18
18
|
};
|
|
19
|
-
const
|
|
19
|
+
const __gradient = ({
|
|
20
20
|
num,
|
|
21
21
|
stops,
|
|
22
22
|
easing,
|
package/int/int.js
CHANGED
|
@@ -9,8 +9,8 @@ import { declareIndex } from "@thi.ng/vectors/compile/accessors";
|
|
|
9
9
|
import { eqDelta4 } from "@thi.ng/vectors/eqdelta";
|
|
10
10
|
import { parseCss } from "../css/parse-css.js";
|
|
11
11
|
import { __scale8bit } from "../internal/scale.js";
|
|
12
|
-
import { srgb } from "../srgb/srgb.js";
|
|
13
12
|
import { srgbIntAbgr32, srgbIntArgb32 } from "../srgb/srgb-int.js";
|
|
13
|
+
import { srgb } from "../srgb/srgb.js";
|
|
14
14
|
import { intArgb32Srgb } from "./int-srgb.js";
|
|
15
15
|
class Int32 {
|
|
16
16
|
constructor(buf, offset = 0, stride = 1) {
|
|
@@ -136,8 +136,8 @@ class ABGR extends Int32 {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
declareIndex(ABGR.prototype, "value", 0);
|
|
139
|
-
const
|
|
140
|
-
const factory = (src, ...
|
|
139
|
+
const __defInt = (ctor, fromSrgb) => {
|
|
140
|
+
const factory = (src, ...args) => src == null ? new ctor() : isNumber(src) ? args.length && args.every(isNumber) ? new ctor([srgbIntArgb32([src, ...args])]) : new ctor([src], ...args) : isString(src) ? factory(parseCss(src)) : isArrayLike(src) ? isString(src.mode) ? new ctor([fromSrgb(srgb(src))], ...args) : new ctor(src, ...args) : implementsFunction(src, "deref") ? new ctor([fromSrgb(srgb(src))], ...args) : illegalArgs(`can't create a ARGB32 color from: ${src}`);
|
|
141
141
|
factory.class = ctor;
|
|
142
142
|
factory.range = [[0], [4294967295]];
|
|
143
143
|
factory.random = (rnd = SYSTEM, buf, idx, stride) => new ctor(buf, idx, stride).set([
|
|
@@ -146,8 +146,8 @@ const defInt = (ctor, fromSrgb) => {
|
|
|
146
146
|
factory.mapBuffer = (buf, num = buf.length, start = 0, cstride = 1, estride = 1) => mapStridedBuffer(ctor, buf, num, start, cstride, estride);
|
|
147
147
|
return factory;
|
|
148
148
|
};
|
|
149
|
-
const argb32 =
|
|
150
|
-
const abgr32 =
|
|
149
|
+
const argb32 = __defInt(ARGB, srgbIntArgb32);
|
|
150
|
+
const abgr32 = __defInt(ABGR, srgbIntAbgr32);
|
|
151
151
|
export {
|
|
152
152
|
ABGR,
|
|
153
153
|
ARGB,
|
package/internal/css.js
CHANGED
|
@@ -7,15 +7,16 @@ const __labCss = (mode, src, scale) => {
|
|
|
7
7
|
const a = FF(src[1] * scale);
|
|
8
8
|
const b = FF(src[2] * scale);
|
|
9
9
|
const alpha = __ensureAlpha(src[3]);
|
|
10
|
-
return
|
|
10
|
+
return __css(mode, l, a, b, alpha);
|
|
11
11
|
};
|
|
12
12
|
const __lchCss = (mode, src, scaleC) => {
|
|
13
13
|
const l = PC(clamp0(src[0]));
|
|
14
14
|
const c = FF(clamp0(src[1]) * scaleC);
|
|
15
15
|
const h = FF(fract(src[2]) * 360);
|
|
16
16
|
const a = __ensureAlpha(src[3]);
|
|
17
|
-
return
|
|
17
|
+
return __css(mode, l, c, h, a);
|
|
18
18
|
};
|
|
19
|
+
const __css = (mode, x, y, z, a) => `${mode}(${x} ${y} ${z}` + (a < 1 ? `/${FF(a)})` : ")");
|
|
19
20
|
export {
|
|
20
21
|
__labCss,
|
|
21
22
|
__lchCss
|
package/is-black.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare const isBlack: import("@thi.ng/defmulti").MultiFn2<TypedColor<any>, Maybe<number>, boolean>;
|
|
1
|
+
import type { IsGrayFn } from "./api.js";
|
|
2
|
+
export declare const isBlack: IsGrayFn;
|
|
4
3
|
//# sourceMappingURL=is-black.d.ts.map
|
package/is-black.js
CHANGED
|
@@ -2,9 +2,9 @@ import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
|
|
|
2
2
|
import { EPS } from "./api/constants.js";
|
|
3
3
|
import { __dispatch0 } from "./internal/dispatch.js";
|
|
4
4
|
import { rgb } from "./rgb/rgb.js";
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const __isBlackHsv = (x, eps = EPS) => x[2] <= eps;
|
|
6
|
+
const __isBlackRgb = (x, eps = EPS) => x[0] <= eps && x[1] <= eps && x[2] <= eps;
|
|
7
|
+
const __isBlackLch = (x, eps = EPS) => x[0] <= eps;
|
|
8
8
|
const isBlack = defmulti(
|
|
9
9
|
__dispatch0,
|
|
10
10
|
{
|
|
@@ -17,10 +17,10 @@ const isBlack = defmulti(
|
|
|
17
17
|
ycc: "rgb"
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
[DEFAULT]: (x) => __isBlackRgb(rgb(x)),
|
|
21
|
+
hsv: __isBlackHsv,
|
|
22
|
+
lch: __isBlackLch,
|
|
23
|
+
rgb: __isBlackRgb
|
|
24
24
|
}
|
|
25
25
|
);
|
|
26
26
|
export {
|
package/is-gray.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare const isGray: import("@thi.ng/defmulti").MultiFn2<TypedColor<any>, Maybe<number>, boolean>;
|
|
1
|
+
import type { IsGrayFn } from "./api.js";
|
|
2
|
+
export declare const isGray: IsGrayFn;
|
|
4
3
|
//# sourceMappingURL=is-gray.d.ts.map
|
package/is-gray.js
CHANGED
|
@@ -3,9 +3,9 @@ import { eqDelta } from "@thi.ng/math/eqdelta";
|
|
|
3
3
|
import { EPS } from "./api/constants.js";
|
|
4
4
|
import { __dispatch0 } from "./internal/dispatch.js";
|
|
5
5
|
import { rgb } from "./rgb/rgb.js";
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
const __isGrayHsv = (x, eps = EPS) => x[1] <= eps;
|
|
7
|
+
const __isGrayRgb = (x, eps = EPS) => eqDelta(x[0], x[1], eps) && eqDelta(x[0], x[2], eps);
|
|
8
|
+
const __isGrayLab = (x, eps = EPS) => eqDelta(x[1], 0, eps) && eqDelta(x[2], 0, eps);
|
|
9
9
|
const isGray = defmulti(
|
|
10
10
|
__dispatch0,
|
|
11
11
|
{
|
|
@@ -18,10 +18,10 @@ const isGray = defmulti(
|
|
|
18
18
|
ycc: "labD50"
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
[DEFAULT]: (x) => __isGrayRgb(rgb(x)),
|
|
22
|
+
hsv: __isGrayHsv,
|
|
23
|
+
labD50: __isGrayLab,
|
|
24
|
+
rgb: __isGrayRgb
|
|
25
25
|
}
|
|
26
26
|
);
|
|
27
27
|
export {
|
package/is-white.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare const isWhite: import("@thi.ng/defmulti").MultiFn2<TypedColor<any>, Maybe<number>, boolean>;
|
|
1
|
+
import type { IsGrayFn } from "./api.js";
|
|
2
|
+
export declare const isWhite: IsGrayFn;
|
|
4
3
|
//# sourceMappingURL=is-white.d.ts.map
|
package/is-white.js
CHANGED
|
@@ -2,12 +2,12 @@ import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
|
|
|
2
2
|
import { EPS } from "./api/constants.js";
|
|
3
3
|
import { __dispatch0 } from "./internal/dispatch.js";
|
|
4
4
|
import { rgb } from "./rgb/rgb.js";
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const __isWhiteHsv = (x, eps = EPS) => x[1] <= eps && x[2] >= 1 - eps;
|
|
6
|
+
const __isWhiteRgb = (x, eps = EPS) => {
|
|
7
7
|
eps = 1 - eps;
|
|
8
8
|
return x[0] >= eps && x[1] >= eps && x[2] >= eps;
|
|
9
9
|
};
|
|
10
|
-
const
|
|
10
|
+
const __isWhiteLch = (x, eps = EPS) => x[1] <= eps && x[0] >= 1 - eps;
|
|
11
11
|
const isWhite = defmulti(
|
|
12
12
|
__dispatch0,
|
|
13
13
|
{
|
|
@@ -19,11 +19,11 @@ const isWhite = defmulti(
|
|
|
19
19
|
ycc: "lch"
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
|
+
[DEFAULT]: (x) => __isWhiteRgb(rgb(x)),
|
|
22
23
|
hcy: (x, eps = EPS) => x[1] <= eps && x[2] >= 1 - eps,
|
|
23
|
-
hsv:
|
|
24
|
-
lch:
|
|
25
|
-
rgb:
|
|
26
|
-
[DEFAULT]: (x) => isWhiteRgb(rgb(x))
|
|
24
|
+
hsv: __isWhiteHsv,
|
|
25
|
+
lch: __isWhiteLch,
|
|
26
|
+
rgb: __isWhiteRgb
|
|
27
27
|
}
|
|
28
28
|
);
|
|
29
29
|
export {
|
package/lab/lab-xyz.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setC4 } from "@thi.ng/vectors/setc";
|
|
2
2
|
import { D50, D65 } from "../api/constants.js";
|
|
3
3
|
import { __ensureAlpha } from "../internal/ensure.js";
|
|
4
|
-
const
|
|
4
|
+
const __transform = (x) => {
|
|
5
5
|
const y = x ** 3;
|
|
6
6
|
return y > 8856e-6 ? y : (x - 16 / 116) / 7.787;
|
|
7
7
|
};
|
|
@@ -9,9 +9,9 @@ const labXyz = (out, src, white = D50) => {
|
|
|
9
9
|
const y = (src[0] + 0.16) / 1.16;
|
|
10
10
|
return setC4(
|
|
11
11
|
out || src,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
__transform(src[1] / 5 + y) * white[0],
|
|
13
|
+
__transform(y) * white[1],
|
|
14
|
+
__transform(y - src[2] / 2) * white[2],
|
|
15
15
|
__ensureAlpha(src[3])
|
|
16
16
|
);
|
|
17
17
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/color",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.47",
|
|
4
4
|
"description": "Array-based color types, CSS parsing, conversions, transformations, declarative theme generation, gradients, presets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://thi.ng/color",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -40,25 +40,25 @@
|
|
|
40
40
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@thi.ng/api": "^8.11.
|
|
44
|
-
"@thi.ng/arrays": "^2.9.
|
|
45
|
-
"@thi.ng/binary": "^3.4.
|
|
46
|
-
"@thi.ng/checks": "^3.6.
|
|
47
|
-
"@thi.ng/compare": "^2.3.
|
|
48
|
-
"@thi.ng/compose": "^3.0.
|
|
49
|
-
"@thi.ng/defmulti": "^3.0.
|
|
50
|
-
"@thi.ng/errors": "^2.5.
|
|
51
|
-
"@thi.ng/math": "^5.
|
|
52
|
-
"@thi.ng/random": "^3.8.
|
|
53
|
-
"@thi.ng/strings": "^3.7.
|
|
54
|
-
"@thi.ng/transducers": "^9.0.
|
|
55
|
-
"@thi.ng/vectors": "^7.
|
|
43
|
+
"@thi.ng/api": "^8.11.4",
|
|
44
|
+
"@thi.ng/arrays": "^2.9.8",
|
|
45
|
+
"@thi.ng/binary": "^3.4.27",
|
|
46
|
+
"@thi.ng/checks": "^3.6.6",
|
|
47
|
+
"@thi.ng/compare": "^2.3.7",
|
|
48
|
+
"@thi.ng/compose": "^3.0.6",
|
|
49
|
+
"@thi.ng/defmulti": "^3.0.41",
|
|
50
|
+
"@thi.ng/errors": "^2.5.9",
|
|
51
|
+
"@thi.ng/math": "^5.11.1",
|
|
52
|
+
"@thi.ng/random": "^3.8.2",
|
|
53
|
+
"@thi.ng/strings": "^3.7.35",
|
|
54
|
+
"@thi.ng/transducers": "^9.0.7",
|
|
55
|
+
"@thi.ng/vectors": "^7.11.1"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@microsoft/api-extractor": "^7.
|
|
59
|
-
"esbuild": "^0.21.
|
|
58
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
59
|
+
"esbuild": "^0.21.5",
|
|
60
60
|
"typedoc": "^0.25.13",
|
|
61
|
-
"typescript": "^5.
|
|
61
|
+
"typescript": "^5.5.2"
|
|
62
62
|
},
|
|
63
63
|
"keywords": [
|
|
64
64
|
"color",
|
|
@@ -445,5 +445,5 @@
|
|
|
445
445
|
"vectors"
|
|
446
446
|
]
|
|
447
447
|
},
|
|
448
|
-
"gitHead": "
|
|
448
|
+
"gitHead": "7b950c112fba0b2e7c450765b15624c3382f1354\n"
|
|
449
449
|
}
|
package/sort.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare const proximity: (target: ReadonlyColor, dist?: ColorDistance) =>
|
|
|
21
21
|
* @param dist -
|
|
22
22
|
*/
|
|
23
23
|
export declare const proximityABGR32: (target: ReadonlyColor, dist?: ColorDistance) => (col: ReadonlyColor) => number;
|
|
24
|
-
export declare const sort: <T extends
|
|
24
|
+
export declare const sort: <T extends ReadonlyColor>(colors: T[], key: Fn<ReadonlyColor, number>, isReverse?: boolean) => T[];
|
|
25
25
|
/**
|
|
26
26
|
* Similar to {@link sort}, but only for memory mapped colors (e.g. mapping a
|
|
27
27
|
* pixel buffer). Does NOT change the order of elements in given `colors` array,
|
|
@@ -65,5 +65,5 @@ export declare const sort: <T extends import("@thi.ng/vectors").ReadonlyVec>(col
|
|
|
65
65
|
* @param isReverse -
|
|
66
66
|
*/
|
|
67
67
|
export declare const sortMapped: <T extends TypedColor<any>>(colors: T[], key: Fn<ReadonlyColor, number>, isReverse?: boolean) => T[];
|
|
68
|
-
export declare const mostSimilar: <T extends
|
|
68
|
+
export declare const mostSimilar: <T extends ReadonlyColor>(colors: T[], key: Fn<ReadonlyColor, number>) => T;
|
|
69
69
|
//# sourceMappingURL=sort.d.ts.map
|
package/transform.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { ColorMatrix, ReadonlyColor } from "./api.js";
|
|
|
10
10
|
* @param src - source color
|
|
11
11
|
* @param clampOut - true, if result should be clamped to [0..1]
|
|
12
12
|
*/
|
|
13
|
-
export declare const transform: (out: import("
|
|
13
|
+
export declare const transform: (out: import("./api.js").Color | null, mat: ColorMatrix, src: ReadonlyColor, clampOut?: boolean) => import("@thi.ng/vectors").Vec;
|
|
14
14
|
/**
|
|
15
15
|
* Concatenates given color matrices by pairwise multiplying them in
|
|
16
16
|
* left-right order. Returns combined result matrix to be used with
|
|
@@ -25,9 +25,9 @@ export declare const transform: (out: import("@thi.ng/vectors").Vec | null, mat:
|
|
|
25
25
|
* default, unless disabled).
|
|
26
26
|
*
|
|
27
27
|
* @param mat - first matrix
|
|
28
|
-
* @param
|
|
28
|
+
* @param rest - other matrices
|
|
29
29
|
*/
|
|
30
|
-
export declare const concat: (mat: ColorMatrix, ...
|
|
30
|
+
export declare const concat: (mat: ColorMatrix, ...rest: ColorMatrix[]) => ColorMatrix;
|
|
31
31
|
export declare const IDENTITY: ColorMatrix;
|
|
32
32
|
/**
|
|
33
33
|
* Returns a transformation matrix which subtracts user color from given
|
package/transform.js
CHANGED
package/xyz/wavelength-xyz.js
CHANGED
|
@@ -4,13 +4,13 @@ const wavelengthXyz = (out, lambda, alpha = 1) => {
|
|
|
4
4
|
lambda *= 10;
|
|
5
5
|
return setC4(
|
|
6
6
|
out || xyzD65(),
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
__gaussian(lambda, 1.056, 5998, 379, 310) + __gaussian(lambda, 0.362, 4420, 160, 267) + __gaussian(lambda, -0.065, 5011, 204, 262),
|
|
8
|
+
__gaussian(lambda, 0.821, 5688, 469, 405) + __gaussian(lambda, 0.286, 5309, 163, 311),
|
|
9
|
+
__gaussian(lambda, 1.217, 4370, 118, 360) + __gaussian(lambda, 0.681, 4590, 260, 138),
|
|
10
10
|
alpha
|
|
11
11
|
);
|
|
12
12
|
};
|
|
13
|
-
const
|
|
13
|
+
const __gaussian = (x, alpha, m, s1, s2) => {
|
|
14
14
|
const t = (x - m) / (x < m ? s1 : s2);
|
|
15
15
|
return alpha * Math.exp(-(t * t) / 2);
|
|
16
16
|
};
|
package/xyz/xyz-lab.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { setC4 } from "@thi.ng/vectors/setc";
|
|
2
2
|
import { D50, D65 } from "../api/constants.js";
|
|
3
3
|
import { __ensureAlpha } from "../internal/ensure.js";
|
|
4
|
-
const
|
|
4
|
+
const __transform = (x) => x > 885645e-8 ? Math.cbrt(x) : 7.787037 * x + 16 / 116;
|
|
5
5
|
const xyzLab = (out, src, white = D50) => {
|
|
6
|
-
const x =
|
|
7
|
-
const y =
|
|
8
|
-
const z =
|
|
6
|
+
const x = __transform(src[0] / white[0]);
|
|
7
|
+
const y = __transform(src[1] / white[1]);
|
|
8
|
+
const z = __transform(src[2] / white[2]);
|
|
9
9
|
return setC4(
|
|
10
10
|
out || src,
|
|
11
11
|
1.16 * y - 0.16,
|