colorizr 3.0.2 → 3.0.4
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 +40 -21
- package/dist/index.d.mts +79 -14
- package/dist/index.d.ts +79 -14
- package/dist/index.js +76 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -51
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/colorizr.ts +5 -3
- package/src/format-css.ts +7 -3
- package/src/index.ts +7 -0
- package/src/modules/invariant.ts +0 -1
- package/src/palette.ts +34 -18
- package/src/scheme.ts +5 -0
- package/src/swatch.ts +93 -36
- package/src/text-color.ts +15 -5
- package/src/types/index.ts +4 -1
package/README.md
CHANGED
|
@@ -241,7 +241,7 @@ palette('#ff0044', { type: 'monochromatic' });
|
|
|
241
241
|
// ['#ff99b4', '#ff5582', '#ff1150', '#cc0036', '#880024', '#440012']
|
|
242
242
|
```
|
|
243
243
|
|
|
244
|
-
**scheme(input: string, type:
|
|
244
|
+
**scheme(input: string, type: SchemeOptions): string[]**
|
|
245
245
|
Get a color scheme.
|
|
246
246
|
|
|
247
247
|
```typescript
|
|
@@ -251,30 +251,49 @@ const complementary = scheme('rgb(255 0 68)'); // ['#ff0044', '#00ffbb']
|
|
|
251
251
|
const triadic = scheme('#ff0044', 'triadic'); // ['#ff0044', '#44ff00', '#0044ff']
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
-
**swatch(input: string,
|
|
255
|
-
Generate a color swatch with ten shades.
|
|
256
|
-
The `variant` can be used to generate a lighter or darker swatch.
|
|
254
|
+
**swatch(input: string, options?: SwatchOptions): Swatch**
|
|
255
|
+
Generate a color swatch with ten shades, from lightest (50) to darkest (900).
|
|
257
256
|
|
|
258
257
|
```typescript
|
|
259
258
|
import { swatch } from 'colorizr';
|
|
260
259
|
|
|
261
|
-
|
|
262
|
-
/*
|
|
263
|
-
|
|
264
|
-
"#
|
|
265
|
-
"#
|
|
266
|
-
"#
|
|
267
|
-
"#
|
|
268
|
-
"#
|
|
269
|
-
"#
|
|
270
|
-
"#
|
|
271
|
-
"#
|
|
272
|
-
"#
|
|
273
|
-
|
|
260
|
+
swatch('#ff0044');
|
|
261
|
+
/*
|
|
262
|
+
{
|
|
263
|
+
"50": "#ff9aa7",
|
|
264
|
+
"100": "#ff7a8a",
|
|
265
|
+
"200": "#ff586f",
|
|
266
|
+
"300": "#ff3053",
|
|
267
|
+
"400": "#ed0039",
|
|
268
|
+
"500": "#cd001b",
|
|
269
|
+
"600": "#b30000",
|
|
270
|
+
"700": "#970000",
|
|
271
|
+
"800": "#7a0000",
|
|
272
|
+
"900": "#5b0000",
|
|
273
|
+
}
|
|
274
|
+
*/
|
|
275
|
+
|
|
276
|
+
swatch('#ff0044', { mode: 'light' });
|
|
277
|
+
/*
|
|
278
|
+
{
|
|
279
|
+
"50": "#ffd0d8",
|
|
280
|
+
"100": "#ffa5b0",
|
|
281
|
+
"200": "#ff7a8a",
|
|
282
|
+
"300": "#ff4c65",
|
|
283
|
+
"400": "#f90041",
|
|
284
|
+
"500": "#cd001b",
|
|
285
|
+
"600": "#ba0000",
|
|
286
|
+
"700": "#a50000",
|
|
287
|
+
"800": "#900000",
|
|
288
|
+
"900": "#790000",
|
|
289
|
+
}
|
|
290
|
+
*/
|
|
274
291
|
```
|
|
275
292
|
|
|
276
293
|
### Converters
|
|
277
294
|
|
|
295
|
+
The default precision is 5.
|
|
296
|
+
|
|
278
297
|
**convert(input: string, format: ColorType): string**
|
|
279
298
|
Convert a color string to another format.
|
|
280
299
|
|
|
@@ -461,7 +480,7 @@ rgb2hsl({ r: 255, g: 0, b: 68 }); // { h: 344, s: 100, l: 50 }
|
|
|
461
480
|
rgb2hsl([255, 0, 68]); // { h: 344, s: 100, l: 50 }
|
|
462
481
|
```
|
|
463
482
|
|
|
464
|
-
**rgb2oklab(input: RGB | ColorTuple, precision
|
|
483
|
+
**rgb2oklab(input: RGB | ColorTuple, precision?: number): LAB**
|
|
465
484
|
Convert RGB to OKLAB.
|
|
466
485
|
|
|
467
486
|
```typescript
|
|
@@ -471,7 +490,7 @@ rgb2oklab({ r: 255, g: 0, b: 68 }); // { l: 0.63269, a: 0.23887, b: 0.08648 }
|
|
|
471
490
|
rgb2oklab([255, 0, 68]); // { l: 0.63269, a: 0.23887, b: 0.08648 }
|
|
472
491
|
```
|
|
473
492
|
|
|
474
|
-
**rgb2oklch(input: RGB | ColorTuple, precision
|
|
493
|
+
**rgb2oklch(input: RGB | ColorTuple, precision?: number): LCH**
|
|
475
494
|
Convert RGB to OKLCH.
|
|
476
495
|
|
|
477
496
|
```typescript
|
|
@@ -525,7 +544,7 @@ extractColorParts('rgb(255 0 68)') // { model: 'rgb', r: 255, g: 0, b: 68 }
|
|
|
525
544
|
extractColorParts('hsl(344 100% 50% / 90%)') // { alpha: 0.9, model: 'hsl', h: 344, g: 100, l: 50 }
|
|
526
545
|
```
|
|
527
546
|
|
|
528
|
-
**formatCSS(input: HSL | RGB, options?:
|
|
547
|
+
**formatCSS(input: HSL | RGB, options?: FormatCSSOptions): string**
|
|
529
548
|
Get a css string from a color object.
|
|
530
549
|
|
|
531
550
|
```typescript
|
|
@@ -595,7 +614,7 @@ import { removeAlphaFromHex } from 'colorizr';
|
|
|
595
614
|
removeAlphaFromHex('#ff0044cc'); // '#ff0044'
|
|
596
615
|
```
|
|
597
616
|
|
|
598
|
-
**textColor(input: string): string**
|
|
617
|
+
**textColor(input: string, options?: TextColorOptions): string**
|
|
599
618
|
Get a contrasting color (black or white) for the input color.
|
|
600
619
|
|
|
601
620
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ type ColorModelKey = 'hsl' | 'oklab' | 'oklch' | 'rgb';
|
|
|
4
4
|
type ColorModelKeys<TModel extends ColorModelKey> = TModel extends 'hsl' ? keyof Omit<HSL, 'alpha'> : TModel extends 'oklab' ? keyof Omit<LAB, 'alpha'> : TModel extends 'oklch' ? keyof Omit<LCH, 'alpha'> : TModel extends 'rgb' ? keyof Omit<RGB, 'alpha'> : never;
|
|
5
5
|
type ColorKeysTuple = [string, string, string];
|
|
6
6
|
type ColorTuple = [number, number, number];
|
|
7
|
-
type
|
|
7
|
+
type ColorTokens = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
8
8
|
interface Colors {
|
|
9
9
|
alpha: Alpha;
|
|
10
10
|
hex: HEX;
|
|
@@ -14,6 +14,7 @@ interface Colors {
|
|
|
14
14
|
rgb: RGB;
|
|
15
15
|
type: ColorType;
|
|
16
16
|
}
|
|
17
|
+
type ConverterParameters<TModel extends ColorModel> = TModel | ColorTuple;
|
|
17
18
|
type Alpha = number;
|
|
18
19
|
type Amount = number;
|
|
19
20
|
type Degrees = number;
|
|
@@ -54,9 +55,11 @@ interface Analysis {
|
|
|
54
55
|
}
|
|
55
56
|
type PlainObject<T = any> = Record<string, T>;
|
|
56
57
|
|
|
57
|
-
interface
|
|
58
|
+
interface ColorizrOptions {
|
|
58
59
|
/**
|
|
59
|
-
*
|
|
60
|
+
* Output color format.
|
|
61
|
+
*
|
|
62
|
+
* If not specified, the output will use the same format as the input color.
|
|
60
63
|
*/
|
|
61
64
|
format?: ColorType;
|
|
62
65
|
}
|
|
@@ -68,7 +71,7 @@ declare class Colorizr {
|
|
|
68
71
|
oklch: LCH;
|
|
69
72
|
rgb: RGB;
|
|
70
73
|
type: ColorType;
|
|
71
|
-
constructor(color: string | HSL | LAB | LCH | RGB, options?:
|
|
74
|
+
constructor(color: string | HSL | LAB | LCH | RGB, options?: ColorizrOptions);
|
|
72
75
|
/**
|
|
73
76
|
* Get css string
|
|
74
77
|
*/
|
|
@@ -203,10 +206,13 @@ type ExtractColorPartsReturn = {
|
|
|
203
206
|
*/
|
|
204
207
|
declare function extractColorParts(input: string): ExtractColorPartsReturn;
|
|
205
208
|
|
|
206
|
-
interface
|
|
209
|
+
interface FormatCSSOptions {
|
|
210
|
+
/**
|
|
211
|
+
* The alpha value of the color.
|
|
212
|
+
*/
|
|
207
213
|
alpha?: Alpha;
|
|
208
214
|
/**
|
|
209
|
-
*
|
|
215
|
+
* Output color format.
|
|
210
216
|
* @default 'hex'
|
|
211
217
|
*/
|
|
212
218
|
format?: ColorType;
|
|
@@ -217,12 +223,13 @@ interface FormatOptions {
|
|
|
217
223
|
precision?: number;
|
|
218
224
|
/**
|
|
219
225
|
* The separator between the values.
|
|
226
|
+
*
|
|
220
227
|
* oklab and oklch always use space as a separator.
|
|
221
228
|
* @default ' '
|
|
222
229
|
*/
|
|
223
230
|
separator?: string;
|
|
224
231
|
}
|
|
225
|
-
declare function formatCSS<T extends ColorModel | HEX>(input: T, options?:
|
|
232
|
+
declare function formatCSS<T extends ColorModel | HEX>(input: T, options?: FormatCSSOptions): string;
|
|
226
233
|
|
|
227
234
|
declare function formatHex(input: string): HEX;
|
|
228
235
|
|
|
@@ -245,14 +252,36 @@ declare function luminance(input: string): number;
|
|
|
245
252
|
declare function name(input: string): string;
|
|
246
253
|
|
|
247
254
|
interface PaletteOptions {
|
|
255
|
+
/**
|
|
256
|
+
* Output color format.
|
|
257
|
+
*
|
|
258
|
+
* If not specified, the output will use the same format as the input color.
|
|
259
|
+
*/
|
|
248
260
|
format?: ColorType;
|
|
261
|
+
/**
|
|
262
|
+
* Adjusts the lightness of the base color before generating the palette.
|
|
263
|
+
*
|
|
264
|
+
* Value should be between 0 and 100.
|
|
265
|
+
*/
|
|
249
266
|
lightness?: number;
|
|
267
|
+
/**
|
|
268
|
+
* Adjusts the saturation of the base color before generating the palette.
|
|
269
|
+
*
|
|
270
|
+
* Value should be between 0 and 100.
|
|
271
|
+
*/
|
|
250
272
|
saturation?: number;
|
|
251
273
|
/**
|
|
252
|
-
* The number of colors to generate
|
|
274
|
+
* The number of colors to generate in the palette.
|
|
275
|
+
*
|
|
276
|
+
* Minimum value is 2.
|
|
253
277
|
* @default 6
|
|
254
278
|
*/
|
|
255
279
|
size?: number;
|
|
280
|
+
/**
|
|
281
|
+
* Generate a monochromatic palette.
|
|
282
|
+
*
|
|
283
|
+
* For more options, use the `swatch` function.
|
|
284
|
+
*/
|
|
256
285
|
type?: 'monochromatic';
|
|
257
286
|
}
|
|
258
287
|
declare function palette(input: string, options?: PaletteOptions): string[];
|
|
@@ -296,6 +325,11 @@ declare function saturate(input: string, amount: number, format?: ColorType): st
|
|
|
296
325
|
|
|
297
326
|
type Scheme = 'analogous' | 'complementary' | 'rectangle' | 'split' | 'split-complementary' | 'square' | 'tetradic' | 'triadic';
|
|
298
327
|
interface SchemeOptions {
|
|
328
|
+
/**
|
|
329
|
+
* Output color format.
|
|
330
|
+
*
|
|
331
|
+
* If not specified, the output will use the same format as the input color.
|
|
332
|
+
*/
|
|
299
333
|
format?: ColorType;
|
|
300
334
|
/**
|
|
301
335
|
* The type of scheme to generate.
|
|
@@ -308,25 +342,55 @@ interface SchemeOptions {
|
|
|
308
342
|
*/
|
|
309
343
|
declare function scheme(input: string, typeOrOptions?: Scheme | SchemeOptions): string[];
|
|
310
344
|
|
|
311
|
-
type ColorTokens = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
312
345
|
type Swatch = {
|
|
313
346
|
[key in ColorTokens]: string;
|
|
314
347
|
};
|
|
348
|
+
type SwatchVariant = 'deep' | 'neutral' | 'pastel' | 'subtle' | 'vibrant';
|
|
315
349
|
interface SwatchOptions {
|
|
350
|
+
/**
|
|
351
|
+
* Output color format.
|
|
352
|
+
*
|
|
353
|
+
* If not specified, the output will use the same format as the input color.
|
|
354
|
+
*/
|
|
316
355
|
format?: ColorType;
|
|
317
356
|
/**
|
|
318
|
-
* The
|
|
319
|
-
*
|
|
357
|
+
* The mode of the swatch.
|
|
358
|
+
* - 'light': Focuses on lighter tones starting from a higher lightness.
|
|
359
|
+
* - 'dark': Focuses on darker tones starting from a lower lightness.
|
|
360
|
+
*
|
|
361
|
+
* If omitted, a balanced palette is generated.
|
|
362
|
+
*/
|
|
363
|
+
mode?: 'light' | 'dark';
|
|
364
|
+
/**
|
|
365
|
+
* Generate a monochromatic swatch.
|
|
366
|
+
*
|
|
367
|
+
* Disable chroma adjustments for all shades.
|
|
368
|
+
* @default false
|
|
369
|
+
*/
|
|
370
|
+
monochromatic?: boolean;
|
|
371
|
+
/**
|
|
372
|
+
* Determines the scale type for the swatch.
|
|
373
|
+
* - 'linear': Shades are distributed with equal lightness intervals.
|
|
374
|
+
* - 'dynamic': Shades are distributed adaptively based on the input color.
|
|
320
375
|
* @default 'dynamic'
|
|
321
376
|
*/
|
|
322
377
|
scale?: 'dynamic' | 'linear';
|
|
378
|
+
/**
|
|
379
|
+
* The variant of the swatch.
|
|
380
|
+
* - 'deep': Generates rich and bold tones with significantly reduced lightness.
|
|
381
|
+
* - 'neutral': Generates muted tones by reducing chroma.
|
|
382
|
+
* - 'pastel': Produces soft and airy tones with significant chroma reduction.
|
|
383
|
+
* - 'subtle': Creates extremely desaturated tones, close to grayscale.
|
|
384
|
+
* - 'vibrant': Enhances chroma for bold and striking tones.
|
|
385
|
+
*/
|
|
386
|
+
variant?: SwatchVariant;
|
|
323
387
|
}
|
|
324
388
|
/**
|
|
325
389
|
* Generate a palette of shades of a color
|
|
326
390
|
*/
|
|
327
391
|
declare function swatch(input: string, options?: SwatchOptions): Swatch;
|
|
328
392
|
|
|
329
|
-
interface
|
|
393
|
+
interface TextColorOptions {
|
|
330
394
|
/**
|
|
331
395
|
* The dark color to return if the input is light.
|
|
332
396
|
* @default '#000000'
|
|
@@ -339,6 +403,7 @@ interface Options {
|
|
|
339
403
|
lightColor?: string;
|
|
340
404
|
/**
|
|
341
405
|
* The threshold to determine if the color is light or dark.
|
|
406
|
+
*
|
|
342
407
|
* A number between 0 and 255.
|
|
343
408
|
* @default 128
|
|
344
409
|
*/
|
|
@@ -347,7 +412,7 @@ interface Options {
|
|
|
347
412
|
/**
|
|
348
413
|
* Get the contrasted color for a given hex.
|
|
349
414
|
*/
|
|
350
|
-
declare function textColor(input: string, options?:
|
|
415
|
+
declare function textColor(input: string, options?: TextColorOptions): string;
|
|
351
416
|
|
|
352
417
|
/**
|
|
353
418
|
* Increase the color transparency.
|
|
@@ -455,4 +520,4 @@ declare function isLCH(input: unknown): input is LCH;
|
|
|
455
520
|
*/
|
|
456
521
|
declare function isRGB(input: unknown): input is RGB;
|
|
457
522
|
|
|
458
|
-
export { type Alpha, type Amount, type Analysis, type ColorKeysTuple, type ColorModel, type ColorModelKey, type ColorModelKeys, type ColorTuple, type ColorType, type Colors, type ConverterParameters, type Degrees, type HEX, type HSL, type LAB, type LCH, type PlainObject, type RGB, addAlphaToHex, brightnessDifference, chroma, colorDifference, compare, contrast, convert, convertAlphaToHex, darken, Colorizr as default, desaturate, extractAlphaFromHex, extractColorParts, formatCSS, formatHex, getOkLCHMaxChroma, getP3Color, hex2hsl, hex2oklab, hex2oklch, hex2rgb, hexadecimalToNumber, hsl2hex, hsl2oklab, hsl2oklch, hsl2rgb, isHSL, isHex, isLAB, isLCH, isRGB, isValidColor, lighten, luminance, name, oklab2hex, oklab2hsl, oklab2oklch, oklab2rgb, oklch2hex, oklch2hsl, oklch2oklab, oklch2rgb, opacify, opacity, palette, parseCSS, random, removeAlphaFromHex, rgb2hex, rgb2hsl, rgb2oklab, rgb2oklch, rotate, saturate, scheme, swatch, textColor, transparentize };
|
|
523
|
+
export { type Alpha, type Amount, type Analysis, type ColorKeysTuple, type ColorModel, type ColorModelKey, type ColorModelKeys, type ColorTokens, type ColorTuple, type ColorType, type ColorizrOptions, type Colors, type ConverterParameters, type Degrees, type FormatCSSOptions, type HEX, type HSL, type LAB, type LCH, type PaletteOptions, type PlainObject, type RGB, type Scheme, type SchemeOptions, type Swatch, type SwatchOptions, type SwatchVariant, type TextColorOptions, addAlphaToHex, brightnessDifference, chroma, colorDifference, compare, contrast, convert, convertAlphaToHex, darken, Colorizr as default, desaturate, extractAlphaFromHex, extractColorParts, formatCSS, formatHex, getOkLCHMaxChroma, getP3Color, hex2hsl, hex2oklab, hex2oklch, hex2rgb, hexadecimalToNumber, hsl2hex, hsl2oklab, hsl2oklch, hsl2rgb, isHSL, isHex, isLAB, isLCH, isRGB, isValidColor, lighten, luminance, name, oklab2hex, oklab2hsl, oklab2oklch, oklab2rgb, oklch2hex, oklch2hsl, oklch2oklab, oklch2rgb, opacify, opacity, palette, parseCSS, random, removeAlphaFromHex, rgb2hex, rgb2hsl, rgb2oklab, rgb2oklch, rotate, saturate, scheme, swatch, textColor, transparentize };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ type ColorModelKey = 'hsl' | 'oklab' | 'oklch' | 'rgb';
|
|
|
4
4
|
type ColorModelKeys<TModel extends ColorModelKey> = TModel extends 'hsl' ? keyof Omit<HSL, 'alpha'> : TModel extends 'oklab' ? keyof Omit<LAB, 'alpha'> : TModel extends 'oklch' ? keyof Omit<LCH, 'alpha'> : TModel extends 'rgb' ? keyof Omit<RGB, 'alpha'> : never;
|
|
5
5
|
type ColorKeysTuple = [string, string, string];
|
|
6
6
|
type ColorTuple = [number, number, number];
|
|
7
|
-
type
|
|
7
|
+
type ColorTokens = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
8
8
|
interface Colors {
|
|
9
9
|
alpha: Alpha;
|
|
10
10
|
hex: HEX;
|
|
@@ -14,6 +14,7 @@ interface Colors {
|
|
|
14
14
|
rgb: RGB;
|
|
15
15
|
type: ColorType;
|
|
16
16
|
}
|
|
17
|
+
type ConverterParameters<TModel extends ColorModel> = TModel | ColorTuple;
|
|
17
18
|
type Alpha = number;
|
|
18
19
|
type Amount = number;
|
|
19
20
|
type Degrees = number;
|
|
@@ -54,9 +55,11 @@ interface Analysis {
|
|
|
54
55
|
}
|
|
55
56
|
type PlainObject<T = any> = Record<string, T>;
|
|
56
57
|
|
|
57
|
-
interface
|
|
58
|
+
interface ColorizrOptions {
|
|
58
59
|
/**
|
|
59
|
-
*
|
|
60
|
+
* Output color format.
|
|
61
|
+
*
|
|
62
|
+
* If not specified, the output will use the same format as the input color.
|
|
60
63
|
*/
|
|
61
64
|
format?: ColorType;
|
|
62
65
|
}
|
|
@@ -68,7 +71,7 @@ declare class Colorizr {
|
|
|
68
71
|
oklch: LCH;
|
|
69
72
|
rgb: RGB;
|
|
70
73
|
type: ColorType;
|
|
71
|
-
constructor(color: string | HSL | LAB | LCH | RGB, options?:
|
|
74
|
+
constructor(color: string | HSL | LAB | LCH | RGB, options?: ColorizrOptions);
|
|
72
75
|
/**
|
|
73
76
|
* Get css string
|
|
74
77
|
*/
|
|
@@ -203,10 +206,13 @@ type ExtractColorPartsReturn = {
|
|
|
203
206
|
*/
|
|
204
207
|
declare function extractColorParts(input: string): ExtractColorPartsReturn;
|
|
205
208
|
|
|
206
|
-
interface
|
|
209
|
+
interface FormatCSSOptions {
|
|
210
|
+
/**
|
|
211
|
+
* The alpha value of the color.
|
|
212
|
+
*/
|
|
207
213
|
alpha?: Alpha;
|
|
208
214
|
/**
|
|
209
|
-
*
|
|
215
|
+
* Output color format.
|
|
210
216
|
* @default 'hex'
|
|
211
217
|
*/
|
|
212
218
|
format?: ColorType;
|
|
@@ -217,12 +223,13 @@ interface FormatOptions {
|
|
|
217
223
|
precision?: number;
|
|
218
224
|
/**
|
|
219
225
|
* The separator between the values.
|
|
226
|
+
*
|
|
220
227
|
* oklab and oklch always use space as a separator.
|
|
221
228
|
* @default ' '
|
|
222
229
|
*/
|
|
223
230
|
separator?: string;
|
|
224
231
|
}
|
|
225
|
-
declare function formatCSS<T extends ColorModel | HEX>(input: T, options?:
|
|
232
|
+
declare function formatCSS<T extends ColorModel | HEX>(input: T, options?: FormatCSSOptions): string;
|
|
226
233
|
|
|
227
234
|
declare function formatHex(input: string): HEX;
|
|
228
235
|
|
|
@@ -245,14 +252,36 @@ declare function luminance(input: string): number;
|
|
|
245
252
|
declare function name(input: string): string;
|
|
246
253
|
|
|
247
254
|
interface PaletteOptions {
|
|
255
|
+
/**
|
|
256
|
+
* Output color format.
|
|
257
|
+
*
|
|
258
|
+
* If not specified, the output will use the same format as the input color.
|
|
259
|
+
*/
|
|
248
260
|
format?: ColorType;
|
|
261
|
+
/**
|
|
262
|
+
* Adjusts the lightness of the base color before generating the palette.
|
|
263
|
+
*
|
|
264
|
+
* Value should be between 0 and 100.
|
|
265
|
+
*/
|
|
249
266
|
lightness?: number;
|
|
267
|
+
/**
|
|
268
|
+
* Adjusts the saturation of the base color before generating the palette.
|
|
269
|
+
*
|
|
270
|
+
* Value should be between 0 and 100.
|
|
271
|
+
*/
|
|
250
272
|
saturation?: number;
|
|
251
273
|
/**
|
|
252
|
-
* The number of colors to generate
|
|
274
|
+
* The number of colors to generate in the palette.
|
|
275
|
+
*
|
|
276
|
+
* Minimum value is 2.
|
|
253
277
|
* @default 6
|
|
254
278
|
*/
|
|
255
279
|
size?: number;
|
|
280
|
+
/**
|
|
281
|
+
* Generate a monochromatic palette.
|
|
282
|
+
*
|
|
283
|
+
* For more options, use the `swatch` function.
|
|
284
|
+
*/
|
|
256
285
|
type?: 'monochromatic';
|
|
257
286
|
}
|
|
258
287
|
declare function palette(input: string, options?: PaletteOptions): string[];
|
|
@@ -296,6 +325,11 @@ declare function saturate(input: string, amount: number, format?: ColorType): st
|
|
|
296
325
|
|
|
297
326
|
type Scheme = 'analogous' | 'complementary' | 'rectangle' | 'split' | 'split-complementary' | 'square' | 'tetradic' | 'triadic';
|
|
298
327
|
interface SchemeOptions {
|
|
328
|
+
/**
|
|
329
|
+
* Output color format.
|
|
330
|
+
*
|
|
331
|
+
* If not specified, the output will use the same format as the input color.
|
|
332
|
+
*/
|
|
299
333
|
format?: ColorType;
|
|
300
334
|
/**
|
|
301
335
|
* The type of scheme to generate.
|
|
@@ -308,25 +342,55 @@ interface SchemeOptions {
|
|
|
308
342
|
*/
|
|
309
343
|
declare function scheme(input: string, typeOrOptions?: Scheme | SchemeOptions): string[];
|
|
310
344
|
|
|
311
|
-
type ColorTokens = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
312
345
|
type Swatch = {
|
|
313
346
|
[key in ColorTokens]: string;
|
|
314
347
|
};
|
|
348
|
+
type SwatchVariant = 'deep' | 'neutral' | 'pastel' | 'subtle' | 'vibrant';
|
|
315
349
|
interface SwatchOptions {
|
|
350
|
+
/**
|
|
351
|
+
* Output color format.
|
|
352
|
+
*
|
|
353
|
+
* If not specified, the output will use the same format as the input color.
|
|
354
|
+
*/
|
|
316
355
|
format?: ColorType;
|
|
317
356
|
/**
|
|
318
|
-
* The
|
|
319
|
-
*
|
|
357
|
+
* The mode of the swatch.
|
|
358
|
+
* - 'light': Focuses on lighter tones starting from a higher lightness.
|
|
359
|
+
* - 'dark': Focuses on darker tones starting from a lower lightness.
|
|
360
|
+
*
|
|
361
|
+
* If omitted, a balanced palette is generated.
|
|
362
|
+
*/
|
|
363
|
+
mode?: 'light' | 'dark';
|
|
364
|
+
/**
|
|
365
|
+
* Generate a monochromatic swatch.
|
|
366
|
+
*
|
|
367
|
+
* Disable chroma adjustments for all shades.
|
|
368
|
+
* @default false
|
|
369
|
+
*/
|
|
370
|
+
monochromatic?: boolean;
|
|
371
|
+
/**
|
|
372
|
+
* Determines the scale type for the swatch.
|
|
373
|
+
* - 'linear': Shades are distributed with equal lightness intervals.
|
|
374
|
+
* - 'dynamic': Shades are distributed adaptively based on the input color.
|
|
320
375
|
* @default 'dynamic'
|
|
321
376
|
*/
|
|
322
377
|
scale?: 'dynamic' | 'linear';
|
|
378
|
+
/**
|
|
379
|
+
* The variant of the swatch.
|
|
380
|
+
* - 'deep': Generates rich and bold tones with significantly reduced lightness.
|
|
381
|
+
* - 'neutral': Generates muted tones by reducing chroma.
|
|
382
|
+
* - 'pastel': Produces soft and airy tones with significant chroma reduction.
|
|
383
|
+
* - 'subtle': Creates extremely desaturated tones, close to grayscale.
|
|
384
|
+
* - 'vibrant': Enhances chroma for bold and striking tones.
|
|
385
|
+
*/
|
|
386
|
+
variant?: SwatchVariant;
|
|
323
387
|
}
|
|
324
388
|
/**
|
|
325
389
|
* Generate a palette of shades of a color
|
|
326
390
|
*/
|
|
327
391
|
declare function swatch(input: string, options?: SwatchOptions): Swatch;
|
|
328
392
|
|
|
329
|
-
interface
|
|
393
|
+
interface TextColorOptions {
|
|
330
394
|
/**
|
|
331
395
|
* The dark color to return if the input is light.
|
|
332
396
|
* @default '#000000'
|
|
@@ -339,6 +403,7 @@ interface Options {
|
|
|
339
403
|
lightColor?: string;
|
|
340
404
|
/**
|
|
341
405
|
* The threshold to determine if the color is light or dark.
|
|
406
|
+
*
|
|
342
407
|
* A number between 0 and 255.
|
|
343
408
|
* @default 128
|
|
344
409
|
*/
|
|
@@ -347,7 +412,7 @@ interface Options {
|
|
|
347
412
|
/**
|
|
348
413
|
* Get the contrasted color for a given hex.
|
|
349
414
|
*/
|
|
350
|
-
declare function textColor(input: string, options?:
|
|
415
|
+
declare function textColor(input: string, options?: TextColorOptions): string;
|
|
351
416
|
|
|
352
417
|
/**
|
|
353
418
|
* Increase the color transparency.
|
|
@@ -455,4 +520,4 @@ declare function isLCH(input: unknown): input is LCH;
|
|
|
455
520
|
*/
|
|
456
521
|
declare function isRGB(input: unknown): input is RGB;
|
|
457
522
|
|
|
458
|
-
export { type Alpha, type Amount, type Analysis, type ColorKeysTuple, type ColorModel, type ColorModelKey, type ColorModelKeys, type ColorTuple, type ColorType, type Colors, type ConverterParameters, type Degrees, type HEX, type HSL, type LAB, type LCH, type PlainObject, type RGB, addAlphaToHex, brightnessDifference, chroma, colorDifference, compare, contrast, convert, convertAlphaToHex, darken, Colorizr as default, desaturate, extractAlphaFromHex, extractColorParts, formatCSS, formatHex, getOkLCHMaxChroma, getP3Color, hex2hsl, hex2oklab, hex2oklch, hex2rgb, hexadecimalToNumber, hsl2hex, hsl2oklab, hsl2oklch, hsl2rgb, isHSL, isHex, isLAB, isLCH, isRGB, isValidColor, lighten, luminance, name, oklab2hex, oklab2hsl, oklab2oklch, oklab2rgb, oklch2hex, oklch2hsl, oklch2oklab, oklch2rgb, opacify, opacity, palette, parseCSS, random, removeAlphaFromHex, rgb2hex, rgb2hsl, rgb2oklab, rgb2oklch, rotate, saturate, scheme, swatch, textColor, transparentize };
|
|
523
|
+
export { type Alpha, type Amount, type Analysis, type ColorKeysTuple, type ColorModel, type ColorModelKey, type ColorModelKeys, type ColorTokens, type ColorTuple, type ColorType, type ColorizrOptions, type Colors, type ConverterParameters, type Degrees, type FormatCSSOptions, type HEX, type HSL, type LAB, type LCH, type PaletteOptions, type PlainObject, type RGB, type Scheme, type SchemeOptions, type Swatch, type SwatchOptions, type SwatchVariant, type TextColorOptions, addAlphaToHex, brightnessDifference, chroma, colorDifference, compare, contrast, convert, convertAlphaToHex, darken, Colorizr as default, desaturate, extractAlphaFromHex, extractColorParts, formatCSS, formatHex, getOkLCHMaxChroma, getP3Color, hex2hsl, hex2oklab, hex2oklch, hex2rgb, hexadecimalToNumber, hsl2hex, hsl2oklab, hsl2oklch, hsl2rgb, isHSL, isHex, isLAB, isLCH, isRGB, isValidColor, lighten, luminance, name, oklab2hex, oklab2hsl, oklab2oklch, oklab2rgb, oklch2hex, oklch2hsl, oklch2oklab, oklch2rgb, opacify, opacity, palette, parseCSS, random, removeAlphaFromHex, rgb2hex, rgb2hsl, rgb2oklab, rgb2oklch, rotate, saturate, scheme, swatch, textColor, transparentize };
|