@thi.ng/color 5.7.62 → 5.8.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/README.md +90 -1
- package/css/css.d.ts +8 -0
- package/css/css.js +3 -0
- package/package.json +449 -449
- package/strategies.d.ts +12 -10
- package/strategies.js +40 -26
- package/CHANGELOG.md +0 -194
package/README.md
CHANGED
|
@@ -21,6 +21,14 @@ For the Clojure version, please visit: [thi.ng/color-clj](https://thi.ng/color-c
|
|
|
21
21
|
- [Color creation / conversion](#color-creation--conversion)
|
|
22
22
|
- [Storage & memory mapping](#storage--memory-mapping)
|
|
23
23
|
- [Color theme generation](#color-theme-generation)
|
|
24
|
+
- [Color theme strategies](#color-theme-strategies)
|
|
25
|
+
- [Analog colors](#analog-colors)
|
|
26
|
+
- [Split-analog colors](#split-analog-colors)
|
|
27
|
+
- [Complementary colors](#complementary-colors)
|
|
28
|
+
- [Split-complementary colors](#split-complementary-colors)
|
|
29
|
+
- [Monochrome colors](#monochrome-colors)
|
|
30
|
+
- [Triadic colors](#triadic-colors)
|
|
31
|
+
- [Tetradic colors](#tetradic-colors)
|
|
24
32
|
- [Color sorting & distance](#color-sorting--distance)
|
|
25
33
|
- [Sorting memory-mapped colors](#sorting-memory-mapped-colors)
|
|
26
34
|
- [Gradients](#gradients)
|
|
@@ -372,6 +380,87 @@ writeFileSync("swatches-ex01.svg", serialize(doc));
|
|
|
372
380
|
|
|
373
381
|

|
|
374
382
|
|
|
383
|
+
### Color theme strategies
|
|
384
|
+
|
|
385
|
+
In addition to the above approaches to create color themes, the package also provides these more standard strategies to derive a color theme from a given base color:
|
|
386
|
+
|
|
387
|
+
#### Analog colors
|
|
388
|
+
|
|
389
|
+
[Documentation](https://docs.thi.ng/umbrella/color/functions/analogStrategy.html)
|
|
390
|
+
|
|
391
|
+
```ts tangle:export/analog-strategy.ts
|
|
392
|
+
import { analogStrategy, cssColors } from "@thi.ng/color";
|
|
393
|
+
|
|
394
|
+
console.log(cssColors(analogStrategy("#f90")));
|
|
395
|
+
//
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
#### Split-analog colors
|
|
399
|
+
|
|
400
|
+
[Documentation](https://docs.thi.ng/umbrella/color/functions/splitAnalogStrategy.html)
|
|
401
|
+
|
|
402
|
+
```ts tangle:export/split-analog-strategy.ts
|
|
403
|
+
import { splitAnalogStrategy, cssColors } from "@thi.ng/color";
|
|
404
|
+
|
|
405
|
+
console.log(cssColors(splitAnalogStrategy("#f90")));
|
|
406
|
+
//
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
#### Complementary colors
|
|
410
|
+
|
|
411
|
+
[Documentation](https://docs.thi.ng/umbrella/color/functions/complementaryStrategy.html)
|
|
412
|
+
|
|
413
|
+
```ts tangle:export/complementary-strategy.ts
|
|
414
|
+
import { complementaryStrategy, cssColors } from "@thi.ng/color";
|
|
415
|
+
|
|
416
|
+
console.log(cssColors(complementaryStrategy("#f90")));
|
|
417
|
+
//
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
#### Split-complementary colors
|
|
421
|
+
|
|
422
|
+
[Documentation](https://docs.thi.ng/umbrella/color/functions/splitComplementaryStrategy.html)
|
|
423
|
+
|
|
424
|
+
```ts tangle:export/split-complementary-strategy.ts
|
|
425
|
+
import { splitComplementaryStrategy, cssColors } from "@thi.ng/color";
|
|
426
|
+
|
|
427
|
+
console.log(cssColors(splitComplementaryStrategy("#f90")));
|
|
428
|
+
//
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
#### Monochrome colors
|
|
432
|
+
|
|
433
|
+
[Documentation](https://docs.thi.ng/umbrella/color/functions/monochromeStrategy.html)
|
|
434
|
+
|
|
435
|
+
```ts tangle:export/monochrome-strategy.ts
|
|
436
|
+
import { monochromeStrategy, cssColors } from "@thi.ng/color";
|
|
437
|
+
|
|
438
|
+
console.log(cssColors(monochromeStrategy("#f90")));
|
|
439
|
+
//
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
#### Triadic colors
|
|
443
|
+
|
|
444
|
+
[Documentation](https://docs.thi.ng/umbrella/color/functions/triadicStrategy.html)
|
|
445
|
+
|
|
446
|
+
```ts tangle:export/triadic-strategy.ts
|
|
447
|
+
import { triadicStrategy, cssColors } from "@thi.ng/color";
|
|
448
|
+
|
|
449
|
+
console.log(cssColors(triadicStrategy("#f90")));
|
|
450
|
+
//
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
#### Tetradic colors
|
|
454
|
+
|
|
455
|
+
[Documentation](https://docs.thi.ng/umbrella/color/functions/tetradicStrategy.html)
|
|
456
|
+
|
|
457
|
+
```ts tangle:export/tetradic-strategy.ts
|
|
458
|
+
import { tetradicStrategy, cssColors } from "@thi.ng/color";
|
|
459
|
+
|
|
460
|
+
console.log(cssColors(tetradicStrategy("#f90")));
|
|
461
|
+
//
|
|
462
|
+
```
|
|
463
|
+
|
|
375
464
|
### Color sorting & distance
|
|
376
465
|
|
|
377
466
|
The package provides several functions to compute full or channel-wise distances
|
|
@@ -693,7 +782,7 @@ For Node.js REPL:
|
|
|
693
782
|
const color = await import("@thi.ng/color");
|
|
694
783
|
```
|
|
695
784
|
|
|
696
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 15.
|
|
785
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 15.80 KB
|
|
697
786
|
|
|
698
787
|
## Dependencies
|
|
699
788
|
|
package/css/css.d.ts
CHANGED
|
@@ -55,4 +55,12 @@ export declare const setDefaultCSSConversions: (fns: CSSConversions) => Partial<
|
|
|
55
55
|
* @param cssTarget - CSS conversions
|
|
56
56
|
*/
|
|
57
57
|
export declare const css: (src: Exclude<MaybeColor, IParsedColor>, cssTarget?: CSSConversions) => string;
|
|
58
|
+
/**
|
|
59
|
+
* Convenience helper to convert an iterable of colors into an array of CSS
|
|
60
|
+
* strings (using {@link css}).
|
|
61
|
+
*
|
|
62
|
+
* @param colors
|
|
63
|
+
* @param cssTarget
|
|
64
|
+
*/
|
|
65
|
+
export declare const cssColors: (colors: Iterable<Exclude<MaybeColor, IParsedColor>>, cssTarget?: CSSConversions) => string[];
|
|
58
66
|
//# sourceMappingURL=css.d.ts.map
|
package/css/css.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ensureArray } from "@thi.ng/arrays/ensure-array";
|
|
1
2
|
import { isNumber } from "@thi.ng/checks/is-number";
|
|
2
3
|
import { isString } from "@thi.ng/checks/is-string";
|
|
3
4
|
import { convert } from "../convert.js";
|
|
@@ -42,9 +43,11 @@ const css = (src, cssTarget = CSS_DEFAULT) => {
|
|
|
42
43
|
convert([], src, "rgb", src.mode)
|
|
43
44
|
) : srgbCss(src);
|
|
44
45
|
};
|
|
46
|
+
const cssColors = (colors, cssTarget = CSS_DEFAULT) => ensureArray(colors).map((x) => css(x, cssTarget));
|
|
45
47
|
export {
|
|
46
48
|
CSS_LEVEL3,
|
|
47
49
|
CSS_LEVEL4,
|
|
48
50
|
css,
|
|
51
|
+
cssColors,
|
|
49
52
|
setDefaultCSSConversions
|
|
50
53
|
};
|