@thi.ng/color 5.4.7 → 5.5.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-04-08T11:09:50Z
3
+ - **Last updated**: 2023-04-19T09:28:07Z
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,13 @@ 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.5.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.5.0) (2023-04-19)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add TypedColor.xyz 3-channel accessor, update all impls ([c62e0ee](https://github.com/thi-ng/umbrella/commit/c62e0ee))
17
+ - add mostSimilar() ([8cfc36d](https://github.com/thi-ng/umbrella/commit/8cfc36d))
18
+
12
19
  ## [5.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.4.0) (2023-03-02)
13
20
 
14
21
  #### 🚀 Features
package/README.md CHANGED
@@ -601,7 +601,7 @@ For Node.js REPL:
601
601
  const color = await import("@thi.ng/color");
602
602
  ```
603
603
 
604
- Package sizes (brotli'd, pre-treeshake): ESM: 15.51 KB
604
+ Package sizes (brotli'd, pre-treeshake): ESM: 15.58 KB
605
605
 
606
606
  ## Dependencies
607
607
 
package/api.d.ts CHANGED
@@ -145,6 +145,11 @@ export interface TypedColor<T> extends IColor, IDeref<Color>, IEqualsDelta<T>, I
145
145
  * colors into the color space used by this type.
146
146
  */
147
147
  readonly range: [ReadonlyColor, ReadonlyColor];
148
+ /**
149
+ * Returns first 3 color components as tuple/vector. Not to be confused with
150
+ * {@link XYZD50} or {@link XYZD65} color modes.
151
+ */
152
+ readonly xyz: [number, number, number];
148
153
  /**
149
154
  * Clamps all color channels so that colors is inside RGB gamut.
150
155
  *
package/defcolor.js CHANGED
@@ -55,6 +55,9 @@ export const defColor = (spec) => {
55
55
  get [Symbol.toStringTag]() {
56
56
  return spec.mode;
57
57
  }
58
+ get xyz() {
59
+ return [this[0], this[1], this[2]];
60
+ }
58
61
  [Symbol.iterator]() {
59
62
  return stridedValues(this.buf, this.length, this.offset, this.stride);
60
63
  }
package/hcy/hcy.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class HCY implements TypedColor<HCY> {
13
13
  readonly mode: "hcy";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): HCY;
package/hsi/hsi.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class HSI implements TypedColor<HSI> {
13
13
  readonly mode: "hsi";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): HSI;
package/hsl/hsl.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class HSL implements TypedColor<HSL> {
13
13
  readonly mode: "hsl";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): HSL;
package/hsv/hsv.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class HSV implements TypedColor<HSV> {
13
13
  readonly mode: "hsv";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): HSV;
package/int/int.d.ts CHANGED
@@ -17,6 +17,7 @@ export declare abstract class Int32<T extends TypedColor<T>> implements TypedCol
17
17
  get range(): [ReadonlyColor, ReadonlyColor];
18
18
  get alpha(): number;
19
19
  set alpha(x: number);
20
+ get xyz(): [number, number, number];
20
21
  [Symbol.iterator](): Generator<number, void, unknown>;
21
22
  deref(): number[];
22
23
  randomize(rnd?: IRandom): this;
package/int/int.js CHANGED
@@ -35,6 +35,14 @@ export class Int32 {
35
35
  set alpha(x) {
36
36
  this[0] = (this[0] & 0xffffff) | __scale8bit(x, 24);
37
37
  }
38
+ get xyz() {
39
+ const val = this[0];
40
+ return [
41
+ ((val >> 16) & 0xff) / 0xff,
42
+ ((val >> 8) & 0xff) / 0xff,
43
+ (val & 0xff) / 0xff,
44
+ ];
45
+ }
38
46
  *[Symbol.iterator]() {
39
47
  yield this[0];
40
48
  }
package/lab/lab50.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class LabD50 implements TypedColor<LabD50> {
13
13
  readonly mode: "lab50";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): LabD50;
package/lab/lab65.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class LabD65 implements TypedColor<LabD65> {
13
13
  readonly mode: "lab65";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): LabD65;
package/lch/lch.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class LCH implements TypedColor<LCH> {
13
13
  readonly mode: "lch";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): LCH;
package/oklab/oklab.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class Oklab implements TypedColor<Oklab> {
13
13
  readonly mode: "oklab";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): Oklab;
package/oklch/oklch.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class Oklch implements TypedColor<Oklch> {
13
13
  readonly mode: "oklch";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): Oklch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/color",
3
- "version": "5.4.7",
3
+ "version": "5.5.1",
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",
@@ -38,19 +38,19 @@
38
38
  "tool:swatches": "tools:node-esm tools/index.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@thi.ng/api": "^8.7.6",
42
- "@thi.ng/arrays": "^2.5.10",
43
- "@thi.ng/binary": "^3.3.23",
41
+ "@thi.ng/api": "^8.8.0",
42
+ "@thi.ng/arrays": "^2.5.11",
43
+ "@thi.ng/binary": "^3.3.24",
44
44
  "@thi.ng/checks": "^3.3.12",
45
- "@thi.ng/compare": "^2.1.29",
46
- "@thi.ng/compose": "^2.1.31",
47
- "@thi.ng/defmulti": "^2.1.35",
45
+ "@thi.ng/compare": "^2.1.30",
46
+ "@thi.ng/compose": "^2.1.32",
47
+ "@thi.ng/defmulti": "^2.1.36",
48
48
  "@thi.ng/errors": "^2.2.15",
49
- "@thi.ng/math": "^5.4.7",
50
- "@thi.ng/random": "^3.3.29",
51
- "@thi.ng/strings": "^3.4.4",
52
- "@thi.ng/transducers": "^8.4.2",
53
- "@thi.ng/vectors": "^7.6.11"
49
+ "@thi.ng/math": "^5.4.9",
50
+ "@thi.ng/random": "^3.4.0",
51
+ "@thi.ng/strings": "^3.4.5",
52
+ "@thi.ng/transducers": "^8.4.4",
53
+ "@thi.ng/vectors": "^7.6.13"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@microsoft/api-extractor": "^7.34.4",
@@ -445,5 +445,5 @@
445
445
  "vectors"
446
446
  ]
447
447
  },
448
- "gitHead": "abcedd9e4e06a4b631f363610eec572f79b571c1\n"
448
+ "gitHead": "ca22f02a137c0a4e3a38ef81e82e2bc7e3c43849\n"
449
449
  }
package/rgb/rgb.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class RGB implements TypedColor<RGB> {
13
13
  readonly mode: "rgb";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): RGB;
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: (colors: ReadonlyColor[], key: Fn<ReadonlyColor, number>, isReverse?: boolean) => import("@thi.ng/vectors").ReadonlyVec[];
24
+ export declare const sort: <T extends import("@thi.ng/vectors").ReadonlyVec>(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,
@@ -61,4 +61,5 @@ export declare const sort: (colors: ReadonlyColor[], key: Fn<ReadonlyColor, numb
61
61
  * @param isReverse -
62
62
  */
63
63
  export declare const sortMapped: <T extends TypedColor<any>>(colors: T[], key: Fn<ReadonlyColor, number>, isReverse?: boolean) => T[];
64
+ export declare const mostSimilar: <T extends import("@thi.ng/vectors").ReadonlyVec>(colors: T[], key: Fn<ReadonlyColor, number>) => T;
64
65
  //# sourceMappingURL=sort.d.ts.map
package/sort.js CHANGED
@@ -78,3 +78,4 @@ export const sortMapped = (colors, key, isReverse = false) => {
78
78
  });
79
79
  return colors;
80
80
  };
81
+ export const mostSimilar = (colors, key) => sort(colors.slice(), key)[0];
package/srgb/srgb.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class SRGB implements TypedColor<SRGB> {
13
13
  readonly mode: "srgb";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): SRGB;
package/xyy/xyy.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class XYY implements TypedColor<XYY> {
13
13
  readonly mode: "xyy";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): XYY;
package/xyz/xyz50.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class XYZD50 implements TypedColor<XYZD50> {
13
13
  readonly mode: "xyz50";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): XYZD50;
package/xyz/xyz65.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class XYZD65 implements TypedColor<XYZD65> {
13
13
  readonly mode: "xyz65";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): XYZD65;
package/ycc/ycc.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class YCC implements TypedColor<YCC> {
13
13
  readonly mode: "ycc";
14
14
  readonly length: 4;
15
15
  readonly range: [ReadonlyColor, ReadonlyColor];
16
+ readonly xyz: [number, number, number];
16
17
  [Symbol.iterator](): Iterator<number, any, undefined>;
17
18
  clamp(): this;
18
19
  copy(): YCC;