@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.mjs ADDED
@@ -0,0 +1,201 @@
1
+ import { colord, extend } from "colord";
2
+ import a11yPlugin from "colord/plugins/a11y";
3
+ import mixPlugin from "colord/plugins/mix";
4
+
5
+ //#region src/index.ts
6
+ extend([a11yPlugin, mixPlugin]);
7
+ /**
8
+ * Converts a RGB/A color
9
+ *
10
+ * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)
11
+ *
12
+ * to its HEX/A representation as a
13
+ *
14
+ * String (`#RRGGBB<AA>`).
15
+ *
16
+ * If Alpha channel is present in the original object it will be present also in the output.
17
+ */
18
+ function rgbToHex({ r, g, b, a }) {
19
+ return colord({
20
+ r,
21
+ g,
22
+ b,
23
+ a
24
+ }).toHex();
25
+ }
26
+ /**
27
+ * Converts a HEX/A color
28
+ *
29
+ * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)
30
+ *
31
+ * to its RGB/A representation as an
32
+ *
33
+ * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).
34
+ *
35
+ * If Alpha channel is present in the original object it will be present also in the output.
36
+ */
37
+ function hexToRgb(hex) {
38
+ return colord(hex).toRgb();
39
+ }
40
+ /**
41
+ * Converts a HEX/A color
42
+ *
43
+ * String (`#RRGGBB<AA>`)
44
+ *
45
+ * to its RGB/A representation as an
46
+ *
47
+ * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .
48
+ *
49
+ * If Alpha channel is present in the original object it will be present also in the output.
50
+ */
51
+ function hsvToRgb({ h, s, v, a }) {
52
+ return colord({
53
+ h,
54
+ s,
55
+ v,
56
+ a
57
+ }).toRgb();
58
+ }
59
+ /**
60
+ * Converts a RGB/A color
61
+ *
62
+ * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)
63
+ *
64
+ * to its HSV/A representation as an
65
+ *
66
+ * Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-1]}`).
67
+ *
68
+ * If Alpha channel is present in the original object it will be present also in the output.
69
+ */
70
+ function rgbToHsv({ r, g, b, a }) {
71
+ return colord({
72
+ r,
73
+ b,
74
+ g,
75
+ a
76
+ }).toHsv();
77
+ }
78
+ /**
79
+ * Converts a HEX/A color
80
+ *
81
+ * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)
82
+ *
83
+ * to its RGB/A representation as an
84
+ *
85
+ * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).
86
+ *
87
+ * If Alpha channel is present in the original object it will be present also in the output.
88
+ */
89
+ function textToRgb(str) {
90
+ return colord(str).toRgb();
91
+ }
92
+ /**
93
+ * Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).
94
+ *
95
+ * Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 1 or -1 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.
96
+ */
97
+ function lighten(color, percent) {
98
+ return colord(color).lighten(percent).toHex();
99
+ }
100
+ /**
101
+ * Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.
102
+ *
103
+ * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.
104
+ */
105
+ function luminance(color) {
106
+ return colord(color).luminance();
107
+ }
108
+ /**
109
+ * Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.
110
+ *
111
+ * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.
112
+ */
113
+ function brightness(color) {
114
+ return colord(color).brightness();
115
+ }
116
+ /**
117
+ * Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.
118
+ *
119
+ * Accepts a HEX/A String or a RGB/A Object as `fgColor`/`bgColor`. If the alpha channel of the `fgColor` is completely opaque, then the result will be the `fgColor`. If the alpha channel of the `bgColor` is completely opaque, then the resulting blended color will also be opaque. Returns the same type as input for fgColor.
120
+ */
121
+ function blend(fgColor, bgColor) {
122
+ return colord(fgColor).mix(bgColor);
123
+ }
124
+ /**
125
+ * Change color transparency
126
+ */
127
+ function changeAlpha(color, alpha) {
128
+ return colord(color).alpha(alpha).toHex();
129
+ }
130
+ const hueStep = 2;
131
+ const saturationStep = 16;
132
+ const saturationStep2 = 5;
133
+ const brightnessStep1 = 5;
134
+ const brightnessStep2 = 15;
135
+ const lightColorCount = 5;
136
+ const darkColorCount = 4;
137
+ /**
138
+ * Obtain palette colors based on color (from left to right, from light to dark, with 6 as the main color number)
139
+ * @param color - Color
140
+ * @param index - The corresponding color number of the color palette (6 as the main color number)
141
+ * @description algorithm implementation draws inspiration from ant design palette algorithm https://github.com/ant-design/ant-design/blob/master/components/style/color/colorPalette.less
142
+ */
143
+ function colorPalette(color, index) {
144
+ if (typeof color !== "string" && (!color || color.r === void 0)) throw new TypeError("Expected a string or a {r, g, b} object as color");
145
+ const rgb = typeof color === "string" ? textToRgb(color) : color;
146
+ const oldHsv = colord(rgb).toHsv();
147
+ if (index === 6) return rgbToHex(rgb);
148
+ const light = index < 6;
149
+ const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1;
150
+ return colord({
151
+ h: hue(oldHsv, i, light),
152
+ s: saturation(oldHsv, i, light),
153
+ v: value(oldHsv, i, light),
154
+ a: oldHsv.a
155
+ }).toHex();
156
+ }
157
+ /**
158
+ * Obtain color gradient
159
+ * @param hsv - Color values in HSV format
160
+ * @param i - relative distance to 6
161
+ * @param isLight - Is it a bright color
162
+ */
163
+ function hue(hsv, i, isLight) {
164
+ let hue;
165
+ if (hsv.h >= 60 && hsv.h <= 240) hue = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i;
166
+ else hue = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i;
167
+ if (hue < 0) hue += 360;
168
+ else if (hue >= 360) hue -= 360;
169
+ return hue;
170
+ }
171
+ /**
172
+ * Obtain saturation gradient
173
+ * @param hsv - Color values in HSV format
174
+ * @param i - relative distance to 6
175
+ * @param isLight - Is it a bright color
176
+ */
177
+ function saturation(hsv, i, isLight) {
178
+ let saturation;
179
+ if (isLight) saturation = hsv.s - saturationStep * i;
180
+ else if (i === darkColorCount) saturation = hsv.s + saturationStep;
181
+ else saturation = hsv.s + saturationStep2 * i;
182
+ if (saturation > 100) saturation = 100;
183
+ if (isLight && i === lightColorCount && saturation > 10) saturation = 10;
184
+ if (saturation < 6) saturation = 6;
185
+ return saturation;
186
+ }
187
+ /**
188
+ * Obtain brightness gradient
189
+ * @param hsv - Color values in HSV format
190
+ * @param i - relative distance to 6
191
+ * @param isLight - Is it a bright color
192
+ */
193
+ function value(hsv, i, isLight) {
194
+ let value;
195
+ value = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i;
196
+ if (value > 100) value = 100;
197
+ return value;
198
+ }
199
+
200
+ //#endregion
201
+ export { blend, brightness, changeAlpha, colorPalette, hexToRgb, hsvToRgb, lighten, luminance, rgbToHex, rgbToHsv, textToRgb };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hairy/palette",
3
3
  "type": "module",
4
- "version": "1.46.0",
4
+ "version": "1.49.0",
5
5
  "description": "Library for color palette",
6
6
  "author": "Hairyf <wwu710632@gmail.com>",
7
7
  "license": "MIT",
@@ -14,30 +14,29 @@
14
14
  "bugs": "https://github.com/hairyf/hairylib/issues",
15
15
  "keywords": [],
16
16
  "sideEffects": false,
17
- "main": "./dist/index.js",
18
- "publishConfig": {
19
- "jsdelivr": "./dist/index.global.js"
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.mjs",
20
+ "require": "./dist/index.cjs"
21
+ },
22
+ "./package.json": "./package.json"
20
23
  },
24
+ "main": "./dist/index.mjs",
25
+ "module": "./dist/index.mjs",
26
+ "types": "./dist/index.d.mts",
21
27
  "files": [
22
28
  "dist"
23
29
  ],
30
+ "publishConfig": {
31
+ "jsdelivr": "./dist/index.iife.js"
32
+ },
24
33
  "dependencies": {
25
34
  "colord": "^2.9.3"
26
35
  },
27
36
  "scripts": {
28
- "build": "tsup",
29
- "dev": "tsup --watch",
37
+ "build": "tsdown",
38
+ "dev": "tsdown --watch",
30
39
  "start": "tsx src/index.ts"
31
40
  },
32
- "module": "./dist/index.js",
33
- "types": "./dist/index.d.ts",
34
- "unpkg": "./dist/index.global.js",
35
- "exports": {
36
- ".": {
37
- "import": "./dist/index.js",
38
- "require": "./dist/index.cjs",
39
- "types": "./dist/index.d.ts"
40
- },
41
- "./*": "./*"
42
- }
41
+ "unpkg": "./dist/index.iife.js"
43
42
  }
@@ -1,338 +0,0 @@
1
- "use strict";
2
- (() => {
3
- // ../../node_modules/.pnpm/colord@2.9.3/node_modules/colord/index.mjs
4
- var r = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) };
5
- var t = function(r3) {
6
- return "string" == typeof r3 ? r3.length > 0 : "number" == typeof r3;
7
- };
8
- var n = function(r3, t4, n3) {
9
- return void 0 === t4 && (t4 = 0), void 0 === n3 && (n3 = Math.pow(10, t4)), Math.round(n3 * r3) / n3 + 0;
10
- };
11
- var e = function(r3, t4, n3) {
12
- return void 0 === t4 && (t4 = 0), void 0 === n3 && (n3 = 1), r3 > n3 ? n3 : r3 > t4 ? r3 : t4;
13
- };
14
- var u = function(r3) {
15
- return (r3 = isFinite(r3) ? r3 % 360 : 0) > 0 ? r3 : r3 + 360;
16
- };
17
- var a = function(r3) {
18
- return { r: e(r3.r, 0, 255), g: e(r3.g, 0, 255), b: e(r3.b, 0, 255), a: e(r3.a) };
19
- };
20
- var o = function(r3) {
21
- return { r: n(r3.r), g: n(r3.g), b: n(r3.b), a: n(r3.a, 3) };
22
- };
23
- var i = /^#([0-9a-f]{3,8})$/i;
24
- var s = function(r3) {
25
- var t4 = r3.toString(16);
26
- return t4.length < 2 ? "0" + t4 : t4;
27
- };
28
- var h = function(r3) {
29
- var t4 = r3.r, n3 = r3.g, e3 = r3.b, u3 = r3.a, a3 = Math.max(t4, n3, e3), o4 = a3 - Math.min(t4, n3, e3), i3 = o4 ? a3 === t4 ? (n3 - e3) / o4 : a3 === n3 ? 2 + (e3 - t4) / o4 : 4 + (t4 - n3) / o4 : 0;
30
- return { h: 60 * (i3 < 0 ? i3 + 6 : i3), s: a3 ? o4 / a3 * 100 : 0, v: a3 / 255 * 100, a: u3 };
31
- };
32
- var b = function(r3) {
33
- var t4 = r3.h, n3 = r3.s, e3 = r3.v, u3 = r3.a;
34
- t4 = t4 / 360 * 6, n3 /= 100, e3 /= 100;
35
- var a3 = Math.floor(t4), o4 = e3 * (1 - n3), i3 = e3 * (1 - (t4 - a3) * n3), s2 = e3 * (1 - (1 - t4 + a3) * n3), h3 = a3 % 6;
36
- return { r: 255 * [e3, i3, o4, o4, s2, e3][h3], g: 255 * [s2, e3, e3, i3, o4, o4][h3], b: 255 * [o4, o4, s2, e3, e3, i3][h3], a: u3 };
37
- };
38
- var g = function(r3) {
39
- return { h: u(r3.h), s: e(r3.s, 0, 100), l: e(r3.l, 0, 100), a: e(r3.a) };
40
- };
41
- var d = function(r3) {
42
- return { h: n(r3.h), s: n(r3.s), l: n(r3.l), a: n(r3.a, 3) };
43
- };
44
- var f = function(r3) {
45
- return b((n3 = (t4 = r3).s, { h: t4.h, s: (n3 *= ((e3 = t4.l) < 50 ? e3 : 100 - e3) / 100) > 0 ? 2 * n3 / (e3 + n3) * 100 : 0, v: e3 + n3, a: t4.a }));
46
- var t4, n3, e3;
47
- };
48
- var c = function(r3) {
49
- return { h: (t4 = h(r3)).h, s: (u3 = (200 - (n3 = t4.s)) * (e3 = t4.v) / 100) > 0 && u3 < 200 ? n3 * e3 / 100 / (u3 <= 100 ? u3 : 200 - u3) * 100 : 0, l: u3 / 2, a: t4.a };
50
- var t4, n3, e3, u3;
51
- };
52
- var l = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
53
- var p = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
54
- var v = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
55
- var m = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
56
- var y = { string: [[function(r3) {
57
- var t4 = i.exec(r3);
58
- return t4 ? (r3 = t4[1]).length <= 4 ? { r: parseInt(r3[0] + r3[0], 16), g: parseInt(r3[1] + r3[1], 16), b: parseInt(r3[2] + r3[2], 16), a: 4 === r3.length ? n(parseInt(r3[3] + r3[3], 16) / 255, 2) : 1 } : 6 === r3.length || 8 === r3.length ? { r: parseInt(r3.substr(0, 2), 16), g: parseInt(r3.substr(2, 2), 16), b: parseInt(r3.substr(4, 2), 16), a: 8 === r3.length ? n(parseInt(r3.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
59
- }, "hex"], [function(r3) {
60
- var t4 = v.exec(r3) || m.exec(r3);
61
- return t4 ? t4[2] !== t4[4] || t4[4] !== t4[6] ? null : a({ r: Number(t4[1]) / (t4[2] ? 100 / 255 : 1), g: Number(t4[3]) / (t4[4] ? 100 / 255 : 1), b: Number(t4[5]) / (t4[6] ? 100 / 255 : 1), a: void 0 === t4[7] ? 1 : Number(t4[7]) / (t4[8] ? 100 : 1) }) : null;
62
- }, "rgb"], [function(t4) {
63
- var n3 = l.exec(t4) || p.exec(t4);
64
- if (!n3) return null;
65
- var e3, u3, a3 = g({ h: (e3 = n3[1], u3 = n3[2], void 0 === u3 && (u3 = "deg"), Number(e3) * (r[u3] || 1)), s: Number(n3[3]), l: Number(n3[4]), a: void 0 === n3[5] ? 1 : Number(n3[5]) / (n3[6] ? 100 : 1) });
66
- return f(a3);
67
- }, "hsl"]], object: [[function(r3) {
68
- var n3 = r3.r, e3 = r3.g, u3 = r3.b, o4 = r3.a, i3 = void 0 === o4 ? 1 : o4;
69
- return t(n3) && t(e3) && t(u3) ? a({ r: Number(n3), g: Number(e3), b: Number(u3), a: Number(i3) }) : null;
70
- }, "rgb"], [function(r3) {
71
- var n3 = r3.h, e3 = r3.s, u3 = r3.l, a3 = r3.a, o4 = void 0 === a3 ? 1 : a3;
72
- if (!t(n3) || !t(e3) || !t(u3)) return null;
73
- var i3 = g({ h: Number(n3), s: Number(e3), l: Number(u3), a: Number(o4) });
74
- return f(i3);
75
- }, "hsl"], [function(r3) {
76
- var n3 = r3.h, a3 = r3.s, o4 = r3.v, i3 = r3.a, s2 = void 0 === i3 ? 1 : i3;
77
- if (!t(n3) || !t(a3) || !t(o4)) return null;
78
- var h3 = function(r4) {
79
- return { h: u(r4.h), s: e(r4.s, 0, 100), v: e(r4.v, 0, 100), a: e(r4.a) };
80
- }({ h: Number(n3), s: Number(a3), v: Number(o4), a: Number(s2) });
81
- return b(h3);
82
- }, "hsv"]] };
83
- var N = function(r3, t4) {
84
- for (var n3 = 0; n3 < t4.length; n3++) {
85
- var e3 = t4[n3][0](r3);
86
- if (e3) return [e3, t4[n3][1]];
87
- }
88
- return [null, void 0];
89
- };
90
- var x = function(r3) {
91
- return "string" == typeof r3 ? N(r3.trim(), y.string) : "object" == typeof r3 && null !== r3 ? N(r3, y.object) : [null, void 0];
92
- };
93
- var M = function(r3, t4) {
94
- var n3 = c(r3);
95
- return { h: n3.h, s: e(n3.s + 100 * t4, 0, 100), l: n3.l, a: n3.a };
96
- };
97
- var H = function(r3) {
98
- return (299 * r3.r + 587 * r3.g + 114 * r3.b) / 1e3 / 255;
99
- };
100
- var $ = function(r3, t4) {
101
- var n3 = c(r3);
102
- return { h: n3.h, s: n3.s, l: e(n3.l + 100 * t4, 0, 100), a: n3.a };
103
- };
104
- var j = function() {
105
- function r3(r4) {
106
- this.parsed = x(r4)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
107
- }
108
- return r3.prototype.isValid = function() {
109
- return null !== this.parsed;
110
- }, r3.prototype.brightness = function() {
111
- return n(H(this.rgba), 2);
112
- }, r3.prototype.isDark = function() {
113
- return H(this.rgba) < 0.5;
114
- }, r3.prototype.isLight = function() {
115
- return H(this.rgba) >= 0.5;
116
- }, r3.prototype.toHex = function() {
117
- return r4 = o(this.rgba), t4 = r4.r, e3 = r4.g, u3 = r4.b, i3 = (a3 = r4.a) < 1 ? s(n(255 * a3)) : "", "#" + s(t4) + s(e3) + s(u3) + i3;
118
- var r4, t4, e3, u3, a3, i3;
119
- }, r3.prototype.toRgb = function() {
120
- return o(this.rgba);
121
- }, r3.prototype.toRgbString = function() {
122
- return r4 = o(this.rgba), t4 = r4.r, n3 = r4.g, e3 = r4.b, (u3 = r4.a) < 1 ? "rgba(" + t4 + ", " + n3 + ", " + e3 + ", " + u3 + ")" : "rgb(" + t4 + ", " + n3 + ", " + e3 + ")";
123
- var r4, t4, n3, e3, u3;
124
- }, r3.prototype.toHsl = function() {
125
- return d(c(this.rgba));
126
- }, r3.prototype.toHslString = function() {
127
- return r4 = d(c(this.rgba)), t4 = r4.h, n3 = r4.s, e3 = r4.l, (u3 = r4.a) < 1 ? "hsla(" + t4 + ", " + n3 + "%, " + e3 + "%, " + u3 + ")" : "hsl(" + t4 + ", " + n3 + "%, " + e3 + "%)";
128
- var r4, t4, n3, e3, u3;
129
- }, r3.prototype.toHsv = function() {
130
- return r4 = h(this.rgba), { h: n(r4.h), s: n(r4.s), v: n(r4.v), a: n(r4.a, 3) };
131
- var r4;
132
- }, r3.prototype.invert = function() {
133
- return w({ r: 255 - (r4 = this.rgba).r, g: 255 - r4.g, b: 255 - r4.b, a: r4.a });
134
- var r4;
135
- }, r3.prototype.saturate = function(r4) {
136
- return void 0 === r4 && (r4 = 0.1), w(M(this.rgba, r4));
137
- }, r3.prototype.desaturate = function(r4) {
138
- return void 0 === r4 && (r4 = 0.1), w(M(this.rgba, -r4));
139
- }, r3.prototype.grayscale = function() {
140
- return w(M(this.rgba, -1));
141
- }, r3.prototype.lighten = function(r4) {
142
- return void 0 === r4 && (r4 = 0.1), w($(this.rgba, r4));
143
- }, r3.prototype.darken = function(r4) {
144
- return void 0 === r4 && (r4 = 0.1), w($(this.rgba, -r4));
145
- }, r3.prototype.rotate = function(r4) {
146
- return void 0 === r4 && (r4 = 15), this.hue(this.hue() + r4);
147
- }, r3.prototype.alpha = function(r4) {
148
- return "number" == typeof r4 ? w({ r: (t4 = this.rgba).r, g: t4.g, b: t4.b, a: r4 }) : n(this.rgba.a, 3);
149
- var t4;
150
- }, r3.prototype.hue = function(r4) {
151
- var t4 = c(this.rgba);
152
- return "number" == typeof r4 ? w({ h: r4, s: t4.s, l: t4.l, a: t4.a }) : n(t4.h);
153
- }, r3.prototype.isEqual = function(r4) {
154
- return this.toHex() === w(r4).toHex();
155
- }, r3;
156
- }();
157
- var w = function(r3) {
158
- return r3 instanceof j ? r3 : new j(r3);
159
- };
160
- var S = [];
161
- var k = function(r3) {
162
- r3.forEach(function(r4) {
163
- S.indexOf(r4) < 0 && (r4(j, y), S.push(r4));
164
- });
165
- };
166
-
167
- // ../../node_modules/.pnpm/colord@2.9.3/node_modules/colord/plugins/a11y.mjs
168
- var o2 = function(o4) {
169
- var t4 = o4 / 255;
170
- return t4 < 0.04045 ? t4 / 12.92 : Math.pow((t4 + 0.055) / 1.055, 2.4);
171
- };
172
- var t2 = function(t4) {
173
- return 0.2126 * o2(t4.r) + 0.7152 * o2(t4.g) + 0.0722 * o2(t4.b);
174
- };
175
- function a11y_default(o4) {
176
- o4.prototype.luminance = function() {
177
- return o5 = t2(this.rgba), void 0 === (r3 = 2) && (r3 = 0), void 0 === n3 && (n3 = Math.pow(10, r3)), Math.round(n3 * o5) / n3 + 0;
178
- var o5, r3, n3;
179
- }, o4.prototype.contrast = function(r3) {
180
- void 0 === r3 && (r3 = "#FFF");
181
- var n3, a3, i3, e3, v2, u3, d2, c3 = r3 instanceof o4 ? r3 : new o4(r3);
182
- return e3 = this.rgba, v2 = c3.toRgb(), u3 = t2(e3), d2 = t2(v2), n3 = u3 > d2 ? (u3 + 0.05) / (d2 + 0.05) : (d2 + 0.05) / (u3 + 0.05), void 0 === (a3 = 2) && (a3 = 0), void 0 === i3 && (i3 = Math.pow(10, a3)), Math.floor(i3 * n3) / i3 + 0;
183
- }, o4.prototype.isReadable = function(o5, t4) {
184
- return void 0 === o5 && (o5 = "#FFF"), void 0 === t4 && (t4 = {}), this.contrast(o5) >= (e3 = void 0 === (i3 = (r3 = t4).size) ? "normal" : i3, "AAA" === (a3 = void 0 === (n3 = r3.level) ? "AA" : n3) && "normal" === e3 ? 7 : "AA" === a3 && "large" === e3 ? 3 : 4.5);
185
- var r3, n3, a3, i3, e3;
186
- };
187
- }
188
-
189
- // ../../node_modules/.pnpm/colord@2.9.3/node_modules/colord/plugins/mix.mjs
190
- var t3 = function(t4, a3, n3) {
191
- return void 0 === a3 && (a3 = 0), void 0 === n3 && (n3 = 1), t4 > n3 ? n3 : t4 > a3 ? t4 : a3;
192
- };
193
- var a2 = function(t4) {
194
- var a3 = t4 / 255;
195
- return a3 < 0.04045 ? a3 / 12.92 : Math.pow((a3 + 0.055) / 1.055, 2.4);
196
- };
197
- var n2 = function(t4) {
198
- return 255 * (t4 > 31308e-7 ? 1.055 * Math.pow(t4, 1 / 2.4) - 0.055 : 12.92 * t4);
199
- };
200
- var r2 = 96.422;
201
- var o3 = 100;
202
- var u2 = 82.521;
203
- var e2 = function(a3) {
204
- var r3, o4, u3 = { x: 0.9555766 * (r3 = a3).x + -0.0230393 * r3.y + 0.0631636 * r3.z, y: -0.0282895 * r3.x + 1.0099416 * r3.y + 0.0210077 * r3.z, z: 0.0122982 * r3.x + -0.020483 * r3.y + 1.3299098 * r3.z };
205
- return o4 = { r: n2(0.032404542 * u3.x - 0.015371385 * u3.y - 4985314e-9 * u3.z), g: n2(-969266e-8 * u3.x + 0.018760108 * u3.y + 41556e-8 * u3.z), b: n2(556434e-9 * u3.x - 2040259e-9 * u3.y + 0.010572252 * u3.z), a: a3.a }, { r: t3(o4.r, 0, 255), g: t3(o4.g, 0, 255), b: t3(o4.b, 0, 255), a: t3(o4.a) };
206
- };
207
- var i2 = function(n3) {
208
- var e3 = a2(n3.r), i3 = a2(n3.g), p3 = a2(n3.b);
209
- return function(a3) {
210
- return { x: t3(a3.x, 0, r2), y: t3(a3.y, 0, o3), z: t3(a3.z, 0, u2), a: t3(a3.a) };
211
- }(function(t4) {
212
- return { x: 1.0478112 * t4.x + 0.0228866 * t4.y + -0.050127 * t4.z, y: 0.0295424 * t4.x + 0.9904844 * t4.y + -0.0170491 * t4.z, z: -92345e-7 * t4.x + 0.0150436 * t4.y + 0.7521316 * t4.z, a: t4.a };
213
- }({ x: 100 * (0.4124564 * e3 + 0.3575761 * i3 + 0.1804375 * p3), y: 100 * (0.2126729 * e3 + 0.7151522 * i3 + 0.072175 * p3), z: 100 * (0.0193339 * e3 + 0.119192 * i3 + 0.9503041 * p3), a: n3.a }));
214
- };
215
- var p2 = 216 / 24389;
216
- var h2 = 24389 / 27;
217
- var f2 = function(t4) {
218
- var a3 = i2(t4), n3 = a3.x / r2, e3 = a3.y / o3, f3 = a3.z / u2;
219
- return n3 = n3 > p2 ? Math.cbrt(n3) : (h2 * n3 + 16) / 116, { l: 116 * (e3 = e3 > p2 ? Math.cbrt(e3) : (h2 * e3 + 16) / 116) - 16, a: 500 * (n3 - e3), b: 200 * (e3 - (f3 = f3 > p2 ? Math.cbrt(f3) : (h2 * f3 + 16) / 116)), alpha: a3.a };
220
- };
221
- var c2 = function(a3, n3, i3) {
222
- var c3, y2 = f2(a3), x2 = f2(n3);
223
- return function(t4) {
224
- var a4 = (t4.l + 16) / 116, n4 = t4.a / 500 + a4, i4 = a4 - t4.b / 200;
225
- return e2({ x: (Math.pow(n4, 3) > p2 ? Math.pow(n4, 3) : (116 * n4 - 16) / h2) * r2, y: (t4.l > 8 ? Math.pow((t4.l + 16) / 116, 3) : t4.l / h2) * o3, z: (Math.pow(i4, 3) > p2 ? Math.pow(i4, 3) : (116 * i4 - 16) / h2) * u2, a: t4.alpha });
226
- }({ l: t3((c3 = { l: y2.l * (1 - i3) + x2.l * i3, a: y2.a * (1 - i3) + x2.a * i3, b: y2.b * (1 - i3) + x2.b * i3, alpha: y2.alpha * (1 - i3) + x2.alpha * i3 }).l, 0, 400), a: c3.a, b: c3.b, alpha: t3(c3.alpha) });
227
- };
228
- function mix_default(t4) {
229
- function a3(t5, a4, n3) {
230
- void 0 === n3 && (n3 = 5);
231
- for (var r3 = [], o4 = 1 / (n3 - 1), u3 = 0; u3 <= n3 - 1; u3++) r3.push(t5.mix(a4, o4 * u3));
232
- return r3;
233
- }
234
- t4.prototype.mix = function(a4, n3) {
235
- void 0 === n3 && (n3 = 0.5);
236
- var r3 = a4 instanceof t4 ? a4 : new t4(a4), o4 = c2(this.toRgb(), r3.toRgb(), n3);
237
- return new t4(o4);
238
- }, t4.prototype.tints = function(t5) {
239
- return a3(this, "#fff", t5);
240
- }, t4.prototype.shades = function(t5) {
241
- return a3(this, "#000", t5);
242
- }, t4.prototype.tones = function(t5) {
243
- return a3(this, "#808080", t5);
244
- };
245
- }
246
-
247
- // src/index.ts
248
- k([a11y_default, mix_default]);
249
- function rgbToHex({ r: r3, g: g2, b: b2, a: a3 }) {
250
- return w({ r: r3, g: g2, b: b2, a: a3 }).toHex();
251
- }
252
- function hexToRgb(hex) {
253
- return w(hex).toRgb();
254
- }
255
- function hsvToRgb({ h: h3, s: s2, v: v2, a: a3 }) {
256
- return w({ h: h3, s: s2, v: v2, a: a3 }).toRgb();
257
- }
258
- function rgbToHsv({ r: r3, g: g2, b: b2, a: a3 }) {
259
- return w({ r: r3, b: b2, g: g2, a: a3 }).toHsv();
260
- }
261
- function textToRgb(str) {
262
- return w(str).toRgb();
263
- }
264
- function lighten(color, percent) {
265
- return w(color).lighten(percent).toHex();
266
- }
267
- function luminance(color) {
268
- return w(color).luminance();
269
- }
270
- function brightness(color) {
271
- return w(color).brightness();
272
- }
273
- function blend(fgColor, bgColor) {
274
- return w(fgColor).mix(bgColor);
275
- }
276
- function changeAlpha(color, alpha) {
277
- return w(color).alpha(alpha).toHex();
278
- }
279
- var hueStep = 2;
280
- var saturationStep = 16;
281
- var saturationStep2 = 5;
282
- var brightnessStep1 = 5;
283
- var brightnessStep2 = 15;
284
- var lightColorCount = 5;
285
- var darkColorCount = 4;
286
- function colorPalette(color, index) {
287
- if (typeof color !== "string" && (!color || color.r === void 0))
288
- throw new TypeError("Expected a string or a {r, g, b} object as color");
289
- const rgb = typeof color === "string" ? textToRgb(color) : color;
290
- const oldHsv = w(rgb).toHsv();
291
- if (index === 6)
292
- return rgbToHex(rgb);
293
- const light = index < 6;
294
- const i3 = light ? lightColorCount + 1 - index : index - lightColorCount - 1;
295
- const newHsv = {
296
- h: hue(oldHsv, i3, light),
297
- s: saturation(oldHsv, i3, light),
298
- v: value(oldHsv, i3, light),
299
- a: oldHsv.a
300
- };
301
- return w(newHsv).toHex();
302
- }
303
- function hue(hsv, i3, isLight) {
304
- let hue2;
305
- if (hsv.h >= 60 && hsv.h <= 240) {
306
- hue2 = isLight ? hsv.h - hueStep * i3 : hsv.h + hueStep * i3;
307
- } else {
308
- hue2 = isLight ? hsv.h + hueStep * i3 : hsv.h - hueStep * i3;
309
- }
310
- if (hue2 < 0)
311
- hue2 += 360;
312
- else if (hue2 >= 360)
313
- hue2 -= 360;
314
- return hue2;
315
- }
316
- function saturation(hsv, i3, isLight) {
317
- let saturation2;
318
- if (isLight)
319
- saturation2 = hsv.s - saturationStep * i3;
320
- else if (i3 === darkColorCount)
321
- saturation2 = hsv.s + saturationStep;
322
- else saturation2 = hsv.s + saturationStep2 * i3;
323
- if (saturation2 > 100)
324
- saturation2 = 100;
325
- if (isLight && i3 === lightColorCount && saturation2 > 10)
326
- saturation2 = 10;
327
- if (saturation2 < 6)
328
- saturation2 = 6;
329
- return saturation2;
330
- }
331
- function value(hsv, i3, isLight) {
332
- let value2;
333
- value2 = isLight ? hsv.v + brightnessStep1 * i3 : hsv.v - brightnessStep2 * i3;
334
- if (value2 > 100)
335
- value2 = 100;
336
- return value2;
337
- }
338
- })();