@thi.ng/color 5.0.2 → 5.1.0

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**: 2022-04-07T14:17:30Z
3
+ - **Last updated**: 2022-06-09T16:14:01Z
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,14 @@ 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.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.1.0) (2022-06-09)
13
+
14
+ #### 🚀 Features
15
+
16
+ - update multiColorGradient() ([f47a59d](https://github.com/thi-ng/umbrella/commit/f47a59d))
17
+ - add support for automatic conversion to packed ARGB/ABGR ints
18
+ (for use with indexed color models in [@thi.ng/pixel](https://github.com/thi-ng/umbrella/tree/main/packages/pixel))
19
+
12
20
  # [5.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.0.0) (2022-03-11)
13
21
 
14
22
  #### 🛑 Breaking changes
package/color-range.d.ts CHANGED
@@ -26,7 +26,7 @@ export declare const COLOR_RANGES: Record<ColorRangePreset, ColorRange>;
26
26
  * @param range -
27
27
  * @param opts -
28
28
  */
29
- export declare const colorFromRange: (range: ColorRange | keyof typeof COLOR_RANGES, opts?: Partial<Pick<ColorRangeOpts, "variance" | "eps" | "rnd">> | undefined) => LCH;
29
+ export declare const colorFromRange: (range: ColorRange | keyof typeof COLOR_RANGES, opts?: Partial<Pick<ColorRangeOpts, "variance" | "eps" | "rnd">>) => LCH;
30
30
  /**
31
31
  * Generator version of {@link colorFromRange}, by default yielding an infinite
32
32
  * sequence of random colors based on given range, base color (optional) and
@@ -32,7 +32,7 @@ export declare const cosineColor: (spec: CosGradientSpec, t: number) => Color;
32
32
  * @param spec -
33
33
  * @param tx -
34
34
  */
35
- export declare const cosineGradient: (n: number, spec: CosGradientSpec, tx?: FnU<import("@thi.ng/vectors").Vec, import("@thi.ng/vectors").Vec> | undefined) => Color[];
35
+ export declare const cosineGradient: (n: number, spec: CosGradientSpec, tx?: FnU<Color>) => Color[];
36
36
  /**
37
37
  * Similar to {@link cosineGradient}, but writes results into `buffer` from
38
38
  * given `offset` and component/element strides. Returns buffer.
package/gradients.d.ts CHANGED
@@ -3,7 +3,10 @@ import type { TypedColor } from "./api.js";
3
3
  import type { GradientOpts } from "./api/gradients.js";
4
4
  /**
5
5
  * Similar to {@link multiCosineGradient}, but using any number of gradient
6
- * color stops and isn't limited to RGB, but for arbitrary color types.
6
+ * color stops and isn't limited to RGB, but for arbitrary color types. The
7
+ * optional `isABGR` boolean arg can be used to autoconvert resulting colors
8
+ * into packed ARGB (false) or ABGR (true) integers. If that arg is given, an
9
+ * array of numbers will be returned.
7
10
  *
8
11
  * @remarks
9
12
  * @see {@link @thi.ng/transducers#tween}
@@ -38,8 +41,10 @@ import type { GradientOpts } from "./api/gradients.js";
38
41
  * ```
39
42
  *
40
43
  * @param opts -
44
+ * @param isABGR -
41
45
  */
42
- export declare const multiColorGradient: <T extends TypedColor<any>>(opts: GradientOpts<T>) => T[];
46
+ export declare function multiColorGradient<T extends TypedColor<any>>(opts: GradientOpts<T>): T[];
47
+ export declare function multiColorGradient<T extends TypedColor<any>>(opts: GradientOpts<T>, isABGR: boolean): number[];
43
48
  /**
44
49
  * Similar to {@link multiColorGradient}, but writes results into `buffer` from
45
50
  * given `offset` and component/element strides. Returns buffer.
package/gradients.js CHANGED
@@ -1,45 +1,15 @@
1
1
  import { tween } from "@thi.ng/transducers/tween";
2
2
  import { setS4 } from "@thi.ng/vectors/sets";
3
+ import { intArgb32Abgr32 } from "./int/int-int.js";
4
+ import { argb32 } from "./int/int.js";
3
5
  import { mix as $mix } from "./mix.js";
4
- /**
5
- * Similar to {@link multiCosineGradient}, but using any number of gradient
6
- * color stops and isn't limited to RGB, but for arbitrary color types.
7
- *
8
- * @remarks
9
- * @see {@link @thi.ng/transducers#tween}
10
- *
11
- * @example
12
- * ```ts
13
- * gradient = multiColorGradient({
14
- * num: 100,
15
- * // LAB color stops
16
- * stops: [
17
- * // pink red
18
- * [0, lch(0.8, 0.8, 0)],
19
- * // green
20
- * [1 / 3, lch(0.8, 0.8, 1 / 3)],
21
- * // blue
22
- * [2 / 3, lch(0.8, 0.8, 2 / 3)],
23
- * // gray
24
- * [1, lch(0.8, 0, 1)],
25
- * ]
26
- * });
27
- *
28
- * // write gradient as SVG swatches
29
- * writeFileSync(
30
- * `export/lch-multigradient.svg`,
31
- * serialize(
32
- * svg(
33
- * { width: 500, height: 50, convert: true },
34
- * swatchesH(gradient, 5, 50)
35
- * )
36
- * )
37
- * );
38
- * ```
39
- *
40
- * @param opts -
41
- */
42
- export const multiColorGradient = (opts) => [...gradient(opts)];
6
+ export function multiColorGradient(opts, isABGR) {
7
+ const cols = [...gradient(opts)];
8
+ if (isABGR === undefined)
9
+ return cols;
10
+ const rgba = cols.map((x) => argb32(x)[0]);
11
+ return isABGR ? rgba.map(intArgb32Abgr32) : rgba;
12
+ }
43
13
  /**
44
14
  * Similar to {@link multiColorGradient}, but writes results into `buffer` from
45
15
  * given `offset` and component/element strides. Returns buffer.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/color",
3
- "version": "5.0.2",
3
+ "version": "5.1.0",
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",
@@ -36,27 +36,27 @@
36
36
  "tool:swatches": "tools:node-esm tools/index.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.3.5",
40
- "@thi.ng/arrays": "^2.2.1",
41
- "@thi.ng/binary": "^3.2.1",
42
- "@thi.ng/checks": "^3.1.5",
43
- "@thi.ng/compare": "^2.1.5",
44
- "@thi.ng/compose": "^2.1.5",
45
- "@thi.ng/defmulti": "^2.1.5",
46
- "@thi.ng/errors": "^2.1.5",
47
- "@thi.ng/math": "^5.3.1",
48
- "@thi.ng/random": "^3.2.5",
49
- "@thi.ng/strings": "^3.3.3",
50
- "@thi.ng/transducers": "^8.3.1",
51
- "@thi.ng/vectors": "^7.5.2"
39
+ "@thi.ng/api": "^8.3.7",
40
+ "@thi.ng/arrays": "^2.2.4",
41
+ "@thi.ng/binary": "^3.2.3",
42
+ "@thi.ng/checks": "^3.2.0",
43
+ "@thi.ng/compare": "^2.1.7",
44
+ "@thi.ng/compose": "^2.1.7",
45
+ "@thi.ng/defmulti": "^2.1.7",
46
+ "@thi.ng/errors": "^2.1.7",
47
+ "@thi.ng/math": "^5.3.3",
48
+ "@thi.ng/random": "^3.3.1",
49
+ "@thi.ng/strings": "^3.3.5",
50
+ "@thi.ng/transducers": "^8.3.4",
51
+ "@thi.ng/vectors": "^7.5.5"
52
52
  },
53
53
  "devDependencies": {
54
- "@microsoft/api-extractor": "^7.19.4",
55
- "@thi.ng/testament": "^0.2.5",
54
+ "@microsoft/api-extractor": "^7.25.0",
55
+ "@thi.ng/testament": "^0.2.8",
56
56
  "rimraf": "^3.0.2",
57
57
  "tools": "^0.0.1",
58
- "typedoc": "^0.22.13",
59
- "typescript": "^4.6.2"
58
+ "typedoc": "^0.22.17",
59
+ "typescript": "^4.7.3"
60
60
  },
61
61
  "keywords": [
62
62
  "color",
@@ -421,5 +421,5 @@
421
421
  "vectors"
422
422
  ]
423
423
  },
424
- "gitHead": "542bf14bd0c7a56b4e6297718189eea772a824b7\n"
424
+ "gitHead": "9e516d30a1a537e027a6b3d78bf9121bc5831d31\n"
425
425
  }
package/strategies.d.ts CHANGED
@@ -7,7 +7,7 @@ import { LCH } from "./lch/lch.js";
7
7
  * @param deltaL -
8
8
  * @param deltaC -
9
9
  */
10
- export declare const complementaryStrategy: (src: LCH, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
10
+ export declare const complementaryStrategy: (src: LCH, deltaL?: number, deltaC?: number) => LCH[];
11
11
  /**
12
12
  * Returns array of `src` color and 2 neighboring colors, each ±rotated by
13
13
  * normalized `theta` and possibly adjusted via optional `deltaL` and `deltaC`
@@ -18,7 +18,7 @@ export declare const complementaryStrategy: (src: LCH, deltaL?: number | undefin
18
18
  * @param deltaL -
19
19
  * @param deltaC -
20
20
  */
21
- export declare const analogStrategy: (src: LCH, theta?: number, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
21
+ export declare const analogStrategy: (src: LCH, theta?: number, deltaL?: number, deltaC?: number) => LCH[];
22
22
  /**
23
23
  * Similar to {@link splitComplementaryStrategy}. Returns array of `src` color,
24
24
  * its complementary color and 2 of that colors' neighbors, each ±rotated by
@@ -30,7 +30,7 @@ export declare const analogStrategy: (src: LCH, theta?: number, deltaL?: number
30
30
  * @param deltaL -
31
31
  * @param deltaC -
32
32
  */
33
- export declare const splitAnalogStrategy: (src: LCH, theta?: number, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
33
+ export declare const splitAnalogStrategy: (src: LCH, theta?: number, deltaL?: number, deltaC?: number) => LCH[];
34
34
  /**
35
35
  * Similar to {@link splitAnalogStrategy}. Returns array of `src` color and 2
36
36
  * neighbors of its complementary color, each ±rotated by normalized `theta`
@@ -42,7 +42,7 @@ export declare const splitAnalogStrategy: (src: LCH, theta?: number, deltaL?: nu
42
42
  * @param deltaL -
43
43
  * @param deltaC -
44
44
  */
45
- export declare const splitComplementaryStrategy: (src: LCH, theta?: number, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
45
+ export declare const splitComplementaryStrategy: (src: LCH, theta?: number, deltaL?: number, deltaC?: number) => LCH[];
46
46
  /**
47
47
  * Returns array of 5 colors all sharing same hue and chromacity of given `src`
48
48
  * color, but with these luminance settings: 0.0, 0.25, 0.5, 0.75, 1.0. Chroma
@@ -62,7 +62,7 @@ export declare const monochromeStrategy: (src: LCH, deltaC?: number) => LCH[];
62
62
  * @param deltaL -
63
63
  * @param deltaC -
64
64
  */
65
- export declare const triadicStrategy: (src: LCH, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
65
+ export declare const triadicStrategy: (src: LCH, deltaL?: number, deltaC?: number) => LCH[];
66
66
  /**
67
67
  * Returns array of `src` color and 3 other colors whose hues form a rectangle,
68
68
  * using `theta` to define the angular separation. The hues are at: `src`,
@@ -75,7 +75,7 @@ export declare const triadicStrategy: (src: LCH, deltaL?: number | undefined, de
75
75
  * @param deltaL -
76
76
  * @param deltaC -
77
77
  */
78
- export declare const tetradicStrategy: (src: LCH, theta?: number, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
78
+ export declare const tetradicStrategy: (src: LCH, theta?: number, deltaL?: number, deltaC?: number) => LCH[];
79
79
  /**
80
80
  * Version of {@link tetradicStrategy} with an hardcoded `theta` of 1/4 to
81
81
  * produce 4 colors with hues uniformly distributed on the color wheel (possibly
@@ -86,5 +86,5 @@ export declare const tetradicStrategy: (src: LCH, theta?: number, deltaL?: numbe
86
86
  * @param deltaL -
87
87
  * @param deltaC -
88
88
  */
89
- export declare const squareStrategy: (src: LCH, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
89
+ export declare const squareStrategy: (src: LCH, deltaL?: number, deltaC?: number) => LCH[];
90
90
  //# sourceMappingURL=strategies.d.ts.map
package/swatches.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { Fn2, IObjectOf } from "@thi.ng/api";
2
2
  import type { ReadonlyColor } from "./api.js";
3
3
  export declare const swatches: (cols: (ReadonlyColor | string)[], shapeFn: Fn2<ReadonlyColor | string, number, any[]>, attribs?: IObjectOf<any>) => (string | IObjectOf<any>)[];
4
- export declare const swatchesH: (cols: (ReadonlyColor | string)[], w?: number, h?: number, gap?: number, attribs?: IObjectOf<any> | undefined) => (string | IObjectOf<any>)[];
5
- export declare const dotsH: (cols: (ReadonlyColor | string)[], r?: number, gap?: number, attribs?: IObjectOf<any> | undefined) => (string | IObjectOf<any>)[];
4
+ export declare const swatchesH: (cols: (ReadonlyColor | string)[], w?: number, h?: number, gap?: number, attribs?: IObjectOf<any>) => (string | IObjectOf<any>)[];
5
+ export declare const dotsH: (cols: (ReadonlyColor | string)[], r?: number, gap?: number, attribs?: IObjectOf<any>) => (string | IObjectOf<any>)[];
6
6
  export declare const swatchesV: (cols: (ReadonlyColor | string)[], w?: number, h?: number, gap?: number, attribs?: IObjectOf<any>) => (string | IObjectOf<any>)[];
7
- export declare const dotsV: (cols: (ReadonlyColor | string)[], r?: number, gap?: number, attribs?: IObjectOf<any> | undefined) => (string | IObjectOf<any>)[];
7
+ export declare const dotsV: (cols: (ReadonlyColor | string)[], r?: number, gap?: number, attribs?: IObjectOf<any>) => (string | IObjectOf<any>)[];
8
8
  //# sourceMappingURL=swatches.d.ts.map