@thi.ng/color 5.6.44 → 5.6.46
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 +10 -1
- package/README.md +29 -23
- package/analog.d.ts +7 -3
- package/analog.js +24 -24
- package/api.d.ts +5 -1
- package/color-range.js +12 -13
- package/convert.d.ts +2 -2
- package/defcolor.js +3 -3
- package/distance.js +6 -7
- package/gradients.d.ts +0 -1
- package/gradients.js +4 -5
- 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/max-chroma.js +1 -2
- package/package.json +20 -20
- package/sort.d.ts +2 -2
- package/sort.js +1 -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-21T19:34:38Z
|
|
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,15 @@ 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.46](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.6.46) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- rename various rest args to be more semantically meaningful ([8088a56](https://github.com/thi-ng/umbrella/commit/8088a56))
|
|
17
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
18
|
+
- dedupe types for isBlack/Gray/White() fns ([a00705d](https://github.com/thi-ng/umbrella/commit/a00705d))
|
|
19
|
+
- minor dedupe lab/lch CSS serialization ([19df487](https://github.com/thi-ng/umbrella/commit/19df487))
|
|
20
|
+
|
|
12
21
|
### [5.6.42](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.6.42) (2024-04-20)
|
|
13
22
|
|
|
14
23
|
#### ♻️ 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 193 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,27 +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/
|
|
711
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/
|
|
712
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/
|
|
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/
|
|
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) |
|
|
724
730
|
|
|
725
731
|
## API
|
|
726
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
|
@@ -134,15 +134,14 @@ const colorFromRange = (range, opts) => {
|
|
|
134
134
|
};
|
|
135
135
|
function* colorsFromRange(range, opts = {}) {
|
|
136
136
|
let num = opts.num != void 0 ? opts.num : Infinity;
|
|
137
|
-
while (num-- > 0)
|
|
138
|
-
yield colorFromRange(range, opts);
|
|
137
|
+
while (num-- > 0) yield colorFromRange(range, opts);
|
|
139
138
|
}
|
|
140
|
-
const
|
|
139
|
+
const __compileThemePart = (part, opts) => {
|
|
141
140
|
let spec;
|
|
142
141
|
if (isArray(part)) {
|
|
143
|
-
spec =
|
|
142
|
+
spec = __themePartFromTuple(part);
|
|
144
143
|
} else if (isString(part)) {
|
|
145
|
-
spec =
|
|
144
|
+
spec = __themePartFromString(part);
|
|
146
145
|
} else {
|
|
147
146
|
spec = { ...part };
|
|
148
147
|
spec.weight == null && (spec.weight = 1);
|
|
@@ -154,21 +153,21 @@ const compileThemePart = (part, opts) => {
|
|
|
154
153
|
}
|
|
155
154
|
return { spec, opts };
|
|
156
155
|
};
|
|
157
|
-
const
|
|
156
|
+
const __themePartFromTuple = (part) => {
|
|
158
157
|
let weight;
|
|
159
|
-
const [range, ...
|
|
160
|
-
if (isNumber(peek(
|
|
161
|
-
weight = peek(
|
|
162
|
-
|
|
158
|
+
const [range, ...args] = part;
|
|
159
|
+
if (isNumber(peek(args))) {
|
|
160
|
+
weight = peek(args);
|
|
161
|
+
args.pop();
|
|
163
162
|
} else {
|
|
164
163
|
weight = 1;
|
|
165
164
|
}
|
|
166
|
-
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}"`);
|
|
167
166
|
};
|
|
168
|
-
const
|
|
167
|
+
const __themePartFromString = (part) => COLOR_RANGES[part] ? { range: part, weight: 1 } : { base: part, weight: 1 };
|
|
169
168
|
function* colorsFromTheme(parts, opts = {}) {
|
|
170
169
|
let { num, variance, rnd } = { ...DEFAULT_OPTS, ...opts };
|
|
171
|
-
const theme = parts.map((p) =>
|
|
170
|
+
const theme = parts.map((p) => __compileThemePart(p, opts));
|
|
172
171
|
const choice = weightedRandom(
|
|
173
172
|
theme,
|
|
174
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
|
@@ -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(intArgb32Rgb([], src), "rgb", 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,15 +58,14 @@ 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
|
-
if (c1 <= eps || c2 <= eps)
|
|
69
|
-
return { deltaH: 0, H: h1 + h2 };
|
|
68
|
+
if (c1 <= eps || c2 <= eps) return { deltaH: 0, H: h1 + h2 };
|
|
70
69
|
let dh = h2 - h1;
|
|
71
70
|
const sumH = h1 + h2;
|
|
72
71
|
const absH = abs(dh);
|
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,20 +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 = [...
|
|
8
|
-
if (isABGR === void 0)
|
|
9
|
-
return cols;
|
|
7
|
+
const cols = [...__gradient(opts)];
|
|
8
|
+
if (isABGR === void 0) return cols;
|
|
10
9
|
const rgba = cols.map((x) => argb32(x)[0]);
|
|
11
10
|
return isABGR ? rgba.map(intArgb32Abgr32) : rgba;
|
|
12
11
|
}
|
|
13
12
|
const multiColorGradientBuffer = (opts, buffer = [], offset = 0, cstride = 1, estride = 4) => {
|
|
14
|
-
for (let col of
|
|
13
|
+
for (let col of __gradient(opts)) {
|
|
15
14
|
setS4(buffer, col, offset, 0, cstride);
|
|
16
15
|
offset += estride;
|
|
17
16
|
}
|
|
18
17
|
return buffer;
|
|
19
18
|
};
|
|
20
|
-
const
|
|
19
|
+
const __gradient = ({
|
|
21
20
|
num,
|
|
22
21
|
stops,
|
|
23
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/max-chroma.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/color",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.46",
|
|
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.
|
|
53
|
-
"@thi.ng/strings": "^3.7.
|
|
54
|
-
"@thi.ng/transducers": "^9.0.
|
|
55
|
-
"@thi.ng/vectors": "^7.
|
|
43
|
+
"@thi.ng/api": "^8.11.3",
|
|
44
|
+
"@thi.ng/arrays": "^2.9.7",
|
|
45
|
+
"@thi.ng/binary": "^3.4.26",
|
|
46
|
+
"@thi.ng/checks": "^3.6.5",
|
|
47
|
+
"@thi.ng/compare": "^2.3.6",
|
|
48
|
+
"@thi.ng/compose": "^3.0.5",
|
|
49
|
+
"@thi.ng/defmulti": "^3.0.40",
|
|
50
|
+
"@thi.ng/errors": "^2.5.8",
|
|
51
|
+
"@thi.ng/math": "^5.11.0",
|
|
52
|
+
"@thi.ng/random": "^3.8.1",
|
|
53
|
+
"@thi.ng/strings": "^3.7.34",
|
|
54
|
+
"@thi.ng/transducers": "^9.0.6",
|
|
55
|
+
"@thi.ng/vectors": "^7.11.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@microsoft/api-extractor": "^7.
|
|
59
|
-
"esbuild": "^0.
|
|
60
|
-
"typedoc": "^0.25.
|
|
61
|
-
"typescript": "^5.
|
|
58
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
59
|
+
"esbuild": "^0.21.5",
|
|
60
|
+
"typedoc": "^0.25.13",
|
|
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": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\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/sort.js
CHANGED
|
@@ -10,8 +10,7 @@ const proximity = (target, dist = distEucledian3) => (col) => dist(target, col);
|
|
|
10
10
|
const proximityABGR32 = (target, dist = distEucledian3) => (col) => dist(target, intAbgr32Srgb([], col[0]));
|
|
11
11
|
const sort = (colors, key, isReverse = false) => sortByCachedKey(colors, key, isReverse ? compareNumDesc : compareNumAsc);
|
|
12
12
|
const sortMapped = (colors, key, isReverse = false) => {
|
|
13
|
-
if (!colors.length)
|
|
14
|
-
return colors;
|
|
13
|
+
if (!colors.length) return colors;
|
|
15
14
|
const keys = colors.map(key);
|
|
16
15
|
const tmp = typedArray(typedArrayType(colors[0].buf), colors[0].length);
|
|
17
16
|
quickSort(keys, isReverse ? compareNumDesc : compareNumAsc, (_, x, y) => {
|
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,
|