@thi.ng/color 5.6.54 → 5.7.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**: 2024-08-10T15:03:07Z
3
+ - **Last updated**: 2024-08-19T13:45:57Z
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.7.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.7.0) (2024-08-19)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add setDefaultCSSConversions(), update css() ([2d9e505](https://github.com/thi-ng/umbrella/commit/2d9e505))
17
+ - add setDefaultCSSConversions() to set default CSS color conversion rules
18
+ - update css() to use current configured default instead of CSS_LEVEL3
19
+ - add/update docs
20
+
12
21
  ### [5.6.47](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.6.47) (2024-06-29)
13
22
 
14
23
  #### 🩹 Bug fixes
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 198 standalone projects, maintained as part
10
+ > This is one of 199 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
  >
package/css/css.d.ts CHANGED
@@ -1,12 +1,37 @@
1
1
  import type { Fn } from "@thi.ng/api";
2
2
  import type { ColorMode, IParsedColor, MaybeColor } from "../api.js";
3
3
  export type CSSConversions = Partial<Record<ColorMode, Fn<any, string>>>;
4
+ /**
5
+ * CSS Color Module Level 3 compatible color conversion rules.
6
+ *
7
+ * @remarks
8
+ * Initial default setting for {@link css}. Also see
9
+ * {@link setDefaultCSSConversions} to change default.
10
+ *
11
+ * Reference:
12
+ * - https://www.w3.org/TR/css-color-3/
13
+ */
4
14
  export declare const CSS_LEVEL3: CSSConversions;
5
15
  /**
6
16
  * Extended set of direct CSS conversions for use with CSS Color Module Level 4.
7
- * Based on {@link CSS_LEVEL3}.
17
+ * Based on {@link CSS_LEVEL3} and used for {@link css}.
18
+ *
19
+ * @remarks
20
+ * Use {@link setDefaultCSSConversions} to use as default.
21
+ *
22
+ * Reference:
23
+ * - https://www.w3.org/TR/css-color-4/
8
24
  */
9
25
  export declare const CSS_LEVEL4: CSSConversions;
26
+ /**
27
+ * Sets the default set of {@link CSSConversions} functions used by {@link css}.
28
+ * The default is {@link CSS_LEVEL3}, but {@link CSS_LEVEL4} is also available
29
+ * and will provide better (direct) support for newer color spaces like
30
+ * {@link lch}, {@link oklab} or {@link oklch}.
31
+ *
32
+ * @param fns
33
+ */
34
+ export declare const setDefaultCSSConversions: (fns: CSSConversions) => Partial<Record<ColorMode, Fn<any, string>>>;
10
35
  /**
11
36
  * Takes a color in one of the following formats and tries to convert it to a
12
37
  * CSS string.
@@ -20,7 +45,8 @@ export declare const CSS_LEVEL4: CSSConversions;
20
45
  * - string (passthrough)
21
46
  *
22
47
  * If CSS Color Module Level 4 support is desired, pass {@link CSS_LEVEL4} as
23
- * 2nd argument.
48
+ * 2nd argument or call {@link setDefaultCSSConversions}. If no `cssTarget` is
49
+ * given, uses current configured default (initially {@link CSS_LEVEL3}).
24
50
  *
25
51
  * If no direct conversion route for a given source color mode exists, the color
26
52
  * will be first converted to sRGB and serialized as such.
package/css/css.js CHANGED
@@ -34,7 +34,9 @@ const CSS_LEVEL4 = {
34
34
  oklab: oklabCss,
35
35
  oklch: oklchCss
36
36
  };
37
- const css = (src, cssTarget = CSS_LEVEL3) => {
37
+ let CSS_DEFAULT = CSS_LEVEL3;
38
+ const setDefaultCSSConversions = (fns) => CSS_DEFAULT = fns;
39
+ const css = (src, cssTarget = CSS_DEFAULT) => {
38
40
  let asCss;
39
41
  return isString(src) ? src : isNumber(src) ? intArgb32Css(src) : src.mode ? (asCss = cssTarget[src.mode]) ? asCss(src) : cssTarget.rgb(
40
42
  convert([], src, "rgb", src.mode)
@@ -43,5 +45,6 @@ const css = (src, cssTarget = CSS_LEVEL3) => {
43
45
  export {
44
46
  CSS_LEVEL3,
45
47
  CSS_LEVEL4,
46
- css
48
+ css,
49
+ setDefaultCSSConversions
47
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/color",
3
- "version": "5.6.54",
3
+ "version": "5.7.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",
@@ -40,19 +40,19 @@
40
40
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@thi.ng/api": "^8.11.8",
44
- "@thi.ng/arrays": "^2.9.14",
45
- "@thi.ng/binary": "^3.4.31",
46
- "@thi.ng/checks": "^3.6.10",
47
- "@thi.ng/compare": "^2.4.0",
48
- "@thi.ng/compose": "^3.0.11",
49
- "@thi.ng/defmulti": "^3.0.46",
50
- "@thi.ng/errors": "^2.5.14",
51
- "@thi.ng/math": "^5.11.7",
52
- "@thi.ng/random": "^4.0.2",
53
- "@thi.ng/strings": "^3.8.3",
54
- "@thi.ng/transducers": "^9.1.0",
55
- "@thi.ng/vectors": "^7.11.8"
43
+ "@thi.ng/api": "^8.11.9",
44
+ "@thi.ng/arrays": "^2.10.0",
45
+ "@thi.ng/binary": "^3.4.32",
46
+ "@thi.ng/checks": "^3.6.11",
47
+ "@thi.ng/compare": "^2.4.1",
48
+ "@thi.ng/compose": "^3.0.12",
49
+ "@thi.ng/defmulti": "^3.0.47",
50
+ "@thi.ng/errors": "^2.5.15",
51
+ "@thi.ng/math": "^5.11.8",
52
+ "@thi.ng/random": "^4.0.3",
53
+ "@thi.ng/strings": "^3.8.4",
54
+ "@thi.ng/transducers": "^9.2.0",
55
+ "@thi.ng/vectors": "^7.11.10"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@microsoft/api-extractor": "^7.47.5",
@@ -444,5 +444,5 @@
444
444
  "vectors"
445
445
  ]
446
446
  },
447
- "gitHead": "e914ebbd81c56783c39cf746548c547cbacadc96\n"
447
+ "gitHead": "bfbc227cf5ca2d3c2984b3d4713eebd6225cbd54\n"
448
448
  }