colorizr 3.0.2 → 3.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "colorizr",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "Manipulate colors like a boss",
5
5
  "author": "Gil Barbara <gilbarbara@gmail.com>",
6
6
  "keywords": [
@@ -32,13 +32,13 @@
32
32
  "types": "dist/index.d.ts",
33
33
  "sideEffects": false,
34
34
  "devDependencies": {
35
- "@arethetypeswrong/cli": "^0.17.0",
35
+ "@arethetypeswrong/cli": "^0.17.2",
36
36
  "@gilbarbara/eslint-config": "^0.8.2",
37
37
  "@gilbarbara/prettier-config": "^1.0.0",
38
38
  "@gilbarbara/tsconfig": "^0.2.3",
39
39
  "@size-limit/preset-small-lib": "^11.1.6",
40
- "@types/node": "^22.10.1",
41
- "@vitest/coverage-v8": "^2.1.6",
40
+ "@types/node": "^22.10.2",
41
+ "@vitest/coverage-v8": "^2.1.8",
42
42
  "del-cli": "^6.0.0",
43
43
  "husky": "^9.1.7",
44
44
  "is-ci-cli": "^2.2.0",
@@ -46,9 +46,9 @@
46
46
  "size-limit": "^11.1.6",
47
47
  "ts-node": "^10.9.2",
48
48
  "tsup": "^8.3.5",
49
- "typescript": "^5.7.2",
50
- "vite-tsconfig-paths": "^5.1.3",
51
- "vitest": "^2.1.6",
49
+ "typescript": "^5.6.3",
50
+ "vite-tsconfig-paths": "^5.1.4",
51
+ "vitest": "^2.1.8",
52
52
  "watch-run": "^1.2.5"
53
53
  },
54
54
  "scripts": {
package/src/swatch.ts CHANGED
@@ -19,12 +19,17 @@ type Swatch = {
19
19
 
20
20
  export interface SwatchOptions {
21
21
  format?: ColorType;
22
+ /**
23
+ * Generate a monochromatic swatch.
24
+ * @default false
25
+ */
26
+ monochromatic?: boolean;
22
27
  /**
23
28
  * The scale of the swatch.
24
29
  * Linear scale will have equal distance between each shade.
25
30
  * @default 'dynamic'
26
31
  */
27
- scale?: 'dynamic' | 'linear';
32
+ scale?: 'dynamic' | 'linear' | 'monochromatic';
28
33
  }
29
34
 
30
35
  const MIN_LIGHTNESS = 21;
@@ -57,7 +62,7 @@ function shadeColor(input: LCH, lightness: number, chromaTuningFactor = 0): HEX
57
62
  */
58
63
  export default function swatch(input: string, options: SwatchOptions = {}): Swatch {
59
64
  invariant(isString(input), MESSAGES.inputString);
60
- const { format, scale = 'dynamic' } = options;
65
+ const { format, monochromatic = false, scale = 'dynamic' } = options;
61
66
 
62
67
  const lch = parseCSS(input, 'oklch');
63
68
 
@@ -74,28 +79,28 @@ export default function swatch(input: string, options: SwatchOptions = {}): Swat
74
79
  const output: Swatch =
75
80
  scale === 'linear'
76
81
  ? {
77
- 50: shadeColor(lch, 95, -0.00375),
78
- 100: shadeColor(lch, 90, -0.00375),
79
- 200: shadeColor(lch, 80, -0.00375),
80
- 300: shadeColor(lch, 70, -0.00375),
81
- 400: shadeColor(lch, 60, -0.00375),
82
- 500: shadeColor(lch, 50),
83
- 600: shadeColor(lch, 40, 0.025),
84
- 700: shadeColor(lch, 30, 0.05),
85
- 800: shadeColor(lch, 20, 0.075),
86
- 900: shadeColor(lch, 10, 0.1),
82
+ 50: shadeColor(lch, 95, monochromatic ? 0 : -0.00375),
83
+ 100: shadeColor(lch, 90, monochromatic ? 0 : -0.00375),
84
+ 200: shadeColor(lch, 80, monochromatic ? 0 : -0.00375),
85
+ 300: shadeColor(lch, 70, monochromatic ? 0 : -0.00375),
86
+ 400: shadeColor(lch, 60, monochromatic ? 0 : -0.00375),
87
+ 500: shadeColor(lch, 50, 0),
88
+ 600: shadeColor(lch, 40, monochromatic ? 0 : 0.025),
89
+ 700: shadeColor(lch, 30, monochromatic ? 0 : 0.05),
90
+ 800: shadeColor(lch, 20, monochromatic ? 0 : 0.075),
91
+ 900: shadeColor(lch, 10, monochromatic ? 0 : 0.1),
87
92
  }
88
93
  : {
89
- 50: shadeColorDynamic(lch, 5 * lightBase, -0.00375),
90
- 100: shadeColorDynamic(lch, 4 * lightBase, -0.00375),
91
- 200: shadeColorDynamic(lch, 3 * lightBase, -0.00375),
92
- 300: shadeColorDynamic(lch, 2 * lightBase, -0.00375),
93
- 400: shadeColorDynamic(lch, lightBase, -0.00375),
94
+ 50: shadeColorDynamic(lch, 5 * lightBase, monochromatic ? 0 : -0.00375),
95
+ 100: shadeColorDynamic(lch, 4 * lightBase, monochromatic ? 0 : -0.00375),
96
+ 200: shadeColorDynamic(lch, 3 * lightBase, monochromatic ? 0 : -0.00375),
97
+ 300: shadeColorDynamic(lch, 2 * lightBase, monochromatic ? 0 : -0.00375),
98
+ 400: shadeColorDynamic(lch, lightBase, monochromatic ? 0 : -0.00375),
94
99
  500: shadeColorDynamic(lch, 0),
95
- 600: shadeColorDynamic(lch, 1.6 * darkBase, 0.025),
96
- 700: shadeColorDynamic(lch, 1.875 * 2 * darkBase, 0.05),
97
- 800: shadeColorDynamic(lch, 3 * 2 * darkBase, 0.075),
98
- 900: shadeColorDynamic(lch, 4 * 2 * darkBase, 0.1),
100
+ 600: shadeColorDynamic(lch, 1.6 * darkBase, monochromatic ? 0 : 0.025),
101
+ 700: shadeColorDynamic(lch, 1.875 * 2 * darkBase, monochromatic ? 0 : 0.05),
102
+ 800: shadeColorDynamic(lch, 3 * 2 * darkBase, monochromatic ? 0 : 0.075),
103
+ 900: shadeColorDynamic(lch, 4 * 2 * darkBase, monochromatic ? 0 : 0.1),
99
104
  };
100
105
 
101
106
  return Object.entries(output).reduce((acc, [key, value]) => {