@hairy/palette 1.46.0 → 1.49.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/dist/index.js DELETED
@@ -1,107 +0,0 @@
1
- // src/index.ts
2
- import { colord, extend } from "colord";
3
- import a11yPlugin from "colord/plugins/a11y";
4
- import mixPlugin from "colord/plugins/mix";
5
- extend([a11yPlugin, mixPlugin]);
6
- function rgbToHex({ r, g, b, a }) {
7
- return colord({ r, g, b, a }).toHex();
8
- }
9
- function hexToRgb(hex) {
10
- return colord(hex).toRgb();
11
- }
12
- function hsvToRgb({ h, s, v, a }) {
13
- return colord({ h, s, v, a }).toRgb();
14
- }
15
- function rgbToHsv({ r, g, b, a }) {
16
- return colord({ r, b, g, a }).toHsv();
17
- }
18
- function textToRgb(str) {
19
- return colord(str).toRgb();
20
- }
21
- function lighten(color, percent) {
22
- return colord(color).lighten(percent).toHex();
23
- }
24
- function luminance(color) {
25
- return colord(color).luminance();
26
- }
27
- function brightness(color) {
28
- return colord(color).brightness();
29
- }
30
- function blend(fgColor, bgColor) {
31
- return colord(fgColor).mix(bgColor);
32
- }
33
- function changeAlpha(color, alpha) {
34
- return colord(color).alpha(alpha).toHex();
35
- }
36
- var hueStep = 2;
37
- var saturationStep = 16;
38
- var saturationStep2 = 5;
39
- var brightnessStep1 = 5;
40
- var brightnessStep2 = 15;
41
- var lightColorCount = 5;
42
- var darkColorCount = 4;
43
- function colorPalette(color, index) {
44
- if (typeof color !== "string" && (!color || color.r === void 0))
45
- throw new TypeError("Expected a string or a {r, g, b} object as color");
46
- const rgb = typeof color === "string" ? textToRgb(color) : color;
47
- const oldHsv = colord(rgb).toHsv();
48
- if (index === 6)
49
- return rgbToHex(rgb);
50
- const light = index < 6;
51
- const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1;
52
- const newHsv = {
53
- h: hue(oldHsv, i, light),
54
- s: saturation(oldHsv, i, light),
55
- v: value(oldHsv, i, light),
56
- a: oldHsv.a
57
- };
58
- return colord(newHsv).toHex();
59
- }
60
- function hue(hsv, i, isLight) {
61
- let hue2;
62
- if (hsv.h >= 60 && hsv.h <= 240) {
63
- hue2 = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i;
64
- } else {
65
- hue2 = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i;
66
- }
67
- if (hue2 < 0)
68
- hue2 += 360;
69
- else if (hue2 >= 360)
70
- hue2 -= 360;
71
- return hue2;
72
- }
73
- function saturation(hsv, i, isLight) {
74
- let saturation2;
75
- if (isLight)
76
- saturation2 = hsv.s - saturationStep * i;
77
- else if (i === darkColorCount)
78
- saturation2 = hsv.s + saturationStep;
79
- else saturation2 = hsv.s + saturationStep2 * i;
80
- if (saturation2 > 100)
81
- saturation2 = 100;
82
- if (isLight && i === lightColorCount && saturation2 > 10)
83
- saturation2 = 10;
84
- if (saturation2 < 6)
85
- saturation2 = 6;
86
- return saturation2;
87
- }
88
- function value(hsv, i, isLight) {
89
- let value2;
90
- value2 = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i;
91
- if (value2 > 100)
92
- value2 = 100;
93
- return value2;
94
- }
95
- export {
96
- blend,
97
- brightness,
98
- changeAlpha,
99
- colorPalette,
100
- hexToRgb,
101
- hsvToRgb,
102
- lighten,
103
- luminance,
104
- rgbToHex,
105
- rgbToHsv,
106
- textToRgb
107
- };