@hairy/palette 0.2.0 → 0.3.1

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,5 +1,17 @@
1
1
  # @hairy/palette
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: change alpha value error
8
+
9
+ ## 0.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - feat(alpha|palette): add palette and change alpha func
14
+
3
15
  ## 0.2.0
4
16
 
5
17
  ### Minor Changes
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019-PRESENT Anthony Fu<https://github.com/TuiMao233>
3
+ Copyright (c) 2019-PRESENT Mr Mao<https://github.com/TuiMao233>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/index.cjs.js CHANGED
@@ -20,8 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var util_color_exports = {};
21
21
  __export(util_color_exports, {
22
22
  blend: () => blend,
23
+ blendAlpha: () => blendAlpha,
23
24
  brightness: () => brightness,
24
25
  changeAlpha: () => changeAlpha,
26
+ colorPalette: () => colorPalette,
25
27
  hexToRgb: () => hexToRgb,
26
28
  hsvToRgb: () => hsvToRgb,
27
29
  lighten: () => lighten,
@@ -31,7 +33,7 @@ __export(util_color_exports, {
31
33
  textToRgb: () => textToRgb
32
34
  });
33
35
  module.exports = __toCommonJS(util_color_exports);
34
- var reRGBA = /^rgb(a)?\((\d{1,3}),(\d{1,3}),(\d{1,3}),?([01]?\.?\d*?)?\)$/;
36
+ var RE_RGBA = /^rgb(a)?\((\d{1,3}),(\d{1,3}),(\d{1,3}),?([01]?\.?\d*?)?\)$/;
35
37
  function rgbToHex({ r, g, b, a }) {
36
38
  const alpha = a !== void 0;
37
39
  r = Math.round(r);
@@ -127,7 +129,7 @@ function rgbToHsv({ r, g, b, a }) {
127
129
  h: Math.round(h * 360),
128
130
  s: Math.round(s * 100),
129
131
  v: Math.round(v * 100),
130
- a
132
+ a: a || 1
131
133
  };
132
134
  }
133
135
  function textToRgb(str) {
@@ -135,7 +137,7 @@ function textToRgb(str) {
135
137
  throw new TypeError("Expected a string");
136
138
  }
137
139
  const color = str.replace(/ /g, "");
138
- const m = reRGBA.exec(color);
140
+ const m = RE_RGBA.exec(color);
139
141
  if (m === null) {
140
142
  return hexToRgb(color);
141
143
  }
@@ -185,7 +187,7 @@ function blend(fgColor, bgColor) {
185
187
  const ret = { r, g, b, a: Math.round(a * 100) };
186
188
  return typeof fgColor === "string" ? rgbToHex(ret) : ret;
187
189
  }
188
- function changeAlpha(color, offset) {
190
+ function blendAlpha(color, offset) {
189
191
  if (typeof color !== "string") {
190
192
  throw new TypeError("Expected a string as color");
191
193
  }
@@ -201,11 +203,85 @@ function changeAlpha(color, offset) {
201
203
  a: Math.round(Math.min(1, Math.max(0, alpha + offset)) * 100)
202
204
  });
203
205
  }
206
+ function changeAlpha(color, alpha) {
207
+ if (typeof color !== "string") {
208
+ throw new TypeError("Expected a string as color");
209
+ }
210
+ if (alpha === void 0 || alpha < 0 || alpha > 100) {
211
+ throw new TypeError("Expected alpha to be between 0 and 1");
212
+ }
213
+ const rgba = textToRgb(color);
214
+ rgba.a = alpha;
215
+ return rgbToHex(rgba);
216
+ }
217
+ var hueStep = 2;
218
+ var saturationStep = 16;
219
+ var saturationStep2 = 5;
220
+ var brightnessStep1 = 5;
221
+ var brightnessStep2 = 15;
222
+ var lightColorCount = 5;
223
+ var darkColorCount = 4;
224
+ function colorPalette(color, index) {
225
+ if (typeof color !== "string" && (!color || color.r === void 0)) {
226
+ throw new TypeError("Expected a string or a {r, g, b} object as color");
227
+ }
228
+ const rgb = typeof color === "string" ? textToRgb(color) : color;
229
+ const oldHsv = rgbToHsv(rgb);
230
+ if (index === 6)
231
+ return rgbToHex(rgb);
232
+ const light = index < 6;
233
+ const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1;
234
+ const newHsv = {
235
+ h: hue(oldHsv, i, light),
236
+ s: saturation(oldHsv, i, light),
237
+ v: value(oldHsv, i, light),
238
+ a: oldHsv.a
239
+ };
240
+ return rgbToHex(hsvToRgb(newHsv));
241
+ }
242
+ function hue(hsv, i, isLight) {
243
+ let hue2;
244
+ if (hsv.h >= 60 && hsv.h <= 240) {
245
+ hue2 = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i;
246
+ } else {
247
+ hue2 = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i;
248
+ }
249
+ if (hue2 < 0)
250
+ hue2 += 360;
251
+ else if (hue2 >= 360)
252
+ hue2 -= 360;
253
+ return hue2;
254
+ }
255
+ function saturation(hsv, i, isLight) {
256
+ let saturation2;
257
+ if (isLight)
258
+ saturation2 = hsv.s - saturationStep * i;
259
+ else if (i === darkColorCount)
260
+ saturation2 = hsv.s + saturationStep;
261
+ else
262
+ saturation2 = hsv.s + saturationStep2 * i;
263
+ if (saturation2 > 100)
264
+ saturation2 = 100;
265
+ if (isLight && i === lightColorCount && saturation2 > 10)
266
+ saturation2 = 10;
267
+ if (saturation2 < 6)
268
+ saturation2 = 6;
269
+ return saturation2;
270
+ }
271
+ function value(hsv, i, isLight) {
272
+ let value2;
273
+ value2 = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i;
274
+ if (value2 > 100)
275
+ value2 = 100;
276
+ return value2;
277
+ }
204
278
  // Annotate the CommonJS export names for ESM import in node:
205
279
  0 && (module.exports = {
206
280
  blend,
281
+ blendAlpha,
207
282
  brightness,
208
283
  changeAlpha,
284
+ colorPalette,
209
285
  hexToRgb,
210
286
  hsvToRgb,
211
287
  lighten,
package/index.cjs.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../index.ts"],
4
- "sourcesContent": ["export type RGBA = Record<'r' | 'g' | 'b' | 'a', number>\r\nexport type RGB = Record<'r' | 'g' | 'b', number> & { a?: number }\r\nexport type HEX = string\r\nexport type HSVA = Record<'h' | 's' | 'v' | 'a', number>\r\n\r\nexport type RGBA_TEXT = string\r\nexport type HEX_TEXT = string\r\nexport type HSVA_TEXT = string\r\nexport type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT\r\n\r\nconst reRGBA = /^rgb(a)?\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3}),?([01]?\\.?\\d*?)?\\)$/\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HEX/A representation as a\r\n *\r\n * String (`#RRGGBB<AA>`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHex({ r, g, b, a }: RGBA): HEX {\r\n const alpha = a !== void 0\r\n\r\n r = Math.round(r)\r\n g = Math.round(g)\r\n b = Math.round(b)\r\n\r\n if (r > 255 || g > 255 || b > 255 || (alpha && a > 100)) {\r\n throw new TypeError('Expected 3 numbers below 256 (and optionally one below 100)')\r\n }\r\n\r\n if (alpha) {\r\n a = Number((Math.round((255 * a) / 100) | (1 << 8)).toString(16).slice(1))\r\n }\r\n\r\n return '#' + (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1) + a\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hexToRgb(hex: HEX): RGB {\r\n if (typeof hex !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n hex = hex.replace(/^#/, '')\r\n\r\n if (hex.length === 3) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]\r\n } else if (hex.length === 4) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3]\r\n }\r\n\r\n const num = parseInt(hex, 16)\r\n\r\n return hex.length > 6\r\n ? { r: (num >> 24) & 255, g: (num >> 16) & 255, b: (num >> 8) & 255, a: Math.round((num & 255) / 2.55) }\r\n : { r: num >> 16, g: (num >> 8) & 255, b: num & 255 }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hsvToRgb({ h, s, v, a }: HSVA): RGBA {\r\n let r: any, g: any, b: any\r\n s = s / 100\r\n v = v / 100\r\n\r\n h = h / 360\r\n const i = Math.floor(h * 6),\r\n f = h * 6 - i,\r\n p = v * (1 - s),\r\n q = v * (1 - f * s),\r\n t = v * (1 - (1 - f) * s)\r\n\r\n switch (i % 6) {\r\n case 0:\r\n r = v\r\n g = t\r\n b = p\r\n break\r\n case 1:\r\n r = q\r\n g = v\r\n b = p\r\n break\r\n case 2:\r\n r = p\r\n g = v\r\n b = t\r\n break\r\n case 3:\r\n r = p\r\n g = q\r\n b = v\r\n break\r\n case 4:\r\n r = t\r\n g = p\r\n b = v\r\n break\r\n case 5:\r\n r = v\r\n g = p\r\n b = q\r\n break\r\n }\r\n\r\n return {\r\n r: Math.round(r * 255),\r\n g: Math.round(g * 255),\r\n b: Math.round(b * 255),\r\n a\r\n }\r\n}\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HSV/A representation as an\r\n *\r\n * Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-100]}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHsv({ r, g, b, a }: RGBA): HSVA {\r\n const max = Math.max(r, g, b),\r\n min = Math.min(r, g, b),\r\n d = max - min,\r\n s = max === 0 ? 0 : d / max,\r\n v = max / 255\r\n let h: any\r\n\r\n switch (max) {\r\n case min:\r\n h = 0\r\n break\r\n case r:\r\n h = g - b + d * (g < b ? 6 : 0)\r\n h /= 6 * d\r\n break\r\n case g:\r\n h = b - r + d * 2\r\n h /= 6 * d\r\n break\r\n case b:\r\n h = r - g + d * 4\r\n h /= 6 * d\r\n break\r\n }\r\n\r\n return {\r\n h: Math.round(h * 360),\r\n s: Math.round(s * 100),\r\n v: Math.round(v * 100),\r\n a\r\n }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function textToRgb(str: COLOR): RGB {\r\n if (typeof str !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n const color = str.replace(/ /g, '')\r\n\r\n const m = reRGBA.exec(color)\r\n\r\n if (m === null) {\r\n return hexToRgb(color)\r\n }\r\n\r\n const rgb: RGB = {\r\n r: Math.min(255, parseInt(m[2], 10)),\r\n g: Math.min(255, parseInt(m[3], 10)),\r\n b: Math.min(255, parseInt(m[4], 10))\r\n }\r\n\r\n if (m[1]) {\r\n const alpha = parseFloat(m[5])\r\n rgb.a = Math.min(1, isNaN(alpha) === true ? 1 : alpha) * 100\r\n }\r\n\r\n return rgb\r\n}\r\n\r\n/**\r\n * Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).\r\n *\r\n * Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 100 or -100 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.\r\n */\r\nexport function lighten(color: COLOR, percent: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n if (typeof percent !== 'number') {\r\n throw new TypeError('Expected a numeric percent')\r\n }\r\n\r\n const rgb = textToRgb(color),\r\n t = percent < 0 ? 0 : 255,\r\n p = Math.abs(percent) / 100,\r\n R = rgb.r,\r\n G = rgb.g,\r\n B = rgb.b\r\n\r\n return (\r\n '#' +\r\n (\r\n 0x1_00_00_00 +\r\n (Math.round((t - R) * p) + R) * 0x1_00_00 +\r\n (Math.round((t - G) * p) + G) * 0x1_00 +\r\n (Math.round((t - B) * p) + B)\r\n )\r\n .toString(16)\r\n .slice(1)\r\n )\r\n}\r\n/**\r\n * Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function luminosity(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color,\r\n r = rgb.r / 255,\r\n g = rgb.g / 255,\r\n b = rgb.b / 255,\r\n R = r <= 0.039_28 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4),\r\n G = g <= 0.039_28 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4),\r\n B = b <= 0.039_28 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4)\r\n return 0.2126 * R + 0.7152 * G + 0.0722 * B\r\n}\r\n/**\r\n * Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function brightness(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n\r\n return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000\r\n}\r\n\r\n/**\r\n * Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.\r\n *\r\n * 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.\r\n */\r\nexport function blend(fgColor: COLOR | RGB, bgColor: COLOR | RGB) {\r\n if (typeof fgColor !== 'string' && (!fgColor || fgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as fgColor')\r\n }\r\n\r\n if (typeof bgColor !== 'string' && (!bgColor || bgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as bgColor')\r\n }\r\n\r\n const rgb1 = typeof fgColor === 'string' ? textToRgb(fgColor) : fgColor,\r\n r1 = rgb1.r / 255,\r\n g1 = rgb1.g / 255,\r\n b1 = rgb1.b / 255,\r\n a1 = rgb1.a !== void 0 ? rgb1.a / 100 : 1,\r\n rgb2 = typeof bgColor === 'string' ? textToRgb(bgColor) : bgColor,\r\n r2 = rgb2.r / 255,\r\n g2 = rgb2.g / 255,\r\n b2 = rgb2.b / 255,\r\n a2 = rgb2.a !== void 0 ? rgb2.a / 100 : 1,\r\n a = a1 + a2 * (1 - a1),\r\n r = Math.round(((r1 * a1 + r2 * a2 * (1 - a1)) / a) * 255),\r\n g = Math.round(((g1 * a1 + g2 * a2 * (1 - a1)) / a) * 255),\r\n b = Math.round(((b1 * a1 + b2 * a2 * (1 - a1)) / a) * 255)\r\n\r\n const ret = { r, g, b, a: Math.round(a * 100) }\r\n return typeof fgColor === 'string' ? rgbToHex(ret) : ret\r\n}\r\n\r\n/**\r\n * Increments or decrements the alpha of a string color.\r\n *\r\n * Accepts a HEX/A String as color and a number between -1 and 1 (including edges) as offset. Use a negative value to decrement and a positive number to increment (ex: changeAlpha('#ff0000', -0.1) to decrement alpha by 10%). Returns HEX/A String.\r\n */\r\nexport function changeAlpha(color: COLOR, offset: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n\r\n if (offset === void 0 || offset < -1 || offset > 1) {\r\n throw new TypeError('Expected offset to be between -1 and 1')\r\n }\r\n\r\n const { r, g, b, a } = textToRgb(color)\r\n const alpha = a !== void 0 ? a / 100 : 0\r\n\r\n return rgbToHex({\r\n r,\r\n g,\r\n b,\r\n a: Math.round(Math.min(1, Math.max(0, alpha + offset)) * 100)\r\n })\r\n}\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,IAAM,SAAS;AAaR,kBAAkB,EAAE,GAAG,GAAG,GAAG,KAAgB;AAClD,QAAM,QAAQ,MAAM;AAEpB,MAAI,KAAK,MAAM,CAAC;AAChB,MAAI,KAAK,MAAM,CAAC;AAChB,MAAI,KAAK,MAAM,CAAC;AAEhB,MAAI,IAAI,OAAO,IAAI,OAAO,IAAI,OAAQ,SAAS,IAAI,KAAM;AACvD,UAAM,IAAI,UAAU,6DAA6D;AAAA,EACnF;AAEA,MAAI,OAAO;AACT,QAAI,OAAQ,MAAK,MAAO,MAAM,IAAK,GAAG,IAAK,KAAK,GAAI,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AAAA,EAC3E;AAEA,SAAO,MAAO,KAAK,KAAK,IAAM,KAAK,KAAO,KAAK,IAAK,SAAS,EAAE,EAAE,MAAM,CAAC,IAAI;AAC9E;AAaO,kBAAkB,KAAe;AACtC,MAAI,OAAO,QAAQ,UAAU;AAC3B,UAAM,IAAI,UAAU,mBAAmB;AAAA,EACzC;AAEA,QAAM,IAA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AU,UAAU;AAC7B,UAAM,IAAI,UAAU,4BAA4B;AAAA,EAClD;AAEA,MAAI,WAAW,UAAU,SAAS,MAAM,SAAS,GAAG;AAClD,UAAM,IAAI,UAAU,wCAAwC;AAAA,EAC9D;AAEA,QAAM,EAAE,GAAG,GAAG,GAAG,MAAM,UAAU,KAAK;AACtC,QAAM,QAAQ,MAAM,SAAS,IAAI,MAAM;AAEvC,SAAO,SAAS;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG,KAAK,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,MAAM,CAAC,IAAI,GAAG;AAAA,EAC9D,CAAC;AACH;",
4
+ "sourcesContent": ["export type RGBA = Record<'r' | 'g' | 'b' | 'a', number>\r\nexport type RGB = Record<'r' | 'g' | 'b', number> & { a?: number }\r\nexport type HEX = string\r\nexport type HSVA = Record<'h' | 's' | 'v' | 'a', number>\r\n\r\nexport type RGBA_TEXT = string\r\nexport type HEX_TEXT = string\r\nexport type HSVA_TEXT = string\r\nexport type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT\r\nexport type PALETTE_INDEXES = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10\r\n\r\nconst RE_RGBA = /^rgb(a)?\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3}),?([01]?\\.?\\d*?)?\\)$/\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HEX/A representation as a\r\n *\r\n * String (`#RRGGBB<AA>`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHex({ r, g, b, a }: RGB): HEX {\r\n const alpha = a !== void 0\r\n\r\n r = Math.round(r)\r\n g = Math.round(g)\r\n b = Math.round(b)\r\n\r\n if (r > 255 || g > 255 || b > 255 || (alpha && a! > 100)) {\r\n throw new TypeError('Expected 3 numbers below 256 (and optionally one below 100)')\r\n }\r\n\r\n if (alpha) {\r\n a = Number((Math.round((255 * a!) / 100) | (1 << 8)).toString(16).slice(1))\r\n }\r\n\r\n return '#' + (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1) + a\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hexToRgb(hex: HEX): RGB {\r\n if (typeof hex !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n hex = hex.replace(/^#/, '')\r\n\r\n if (hex.length === 3) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]\r\n } else if (hex.length === 4) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3]\r\n }\r\n\r\n const num = parseInt(hex, 16)\r\n\r\n return hex.length > 6\r\n ? { r: (num >> 24) & 255, g: (num >> 16) & 255, b: (num >> 8) & 255, a: Math.round((num & 255) / 2.55) }\r\n : { r: num >> 16, g: (num >> 8) & 255, b: num & 255 }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hsvToRgb({ h, s, v, a }: HSVA): RGBA {\r\n let r: any, g: any, b: any\r\n s = s / 100\r\n v = v / 100\r\n\r\n h = h / 360\r\n const i = Math.floor(h * 6),\r\n f = h * 6 - i,\r\n p = v * (1 - s),\r\n q = v * (1 - f * s),\r\n t = v * (1 - (1 - f) * s)\r\n\r\n switch (i % 6) {\r\n case 0:\r\n r = v\r\n g = t\r\n b = p\r\n break\r\n case 1:\r\n r = q\r\n g = v\r\n b = p\r\n break\r\n case 2:\r\n r = p\r\n g = v\r\n b = t\r\n break\r\n case 3:\r\n r = p\r\n g = q\r\n b = v\r\n break\r\n case 4:\r\n r = t\r\n g = p\r\n b = v\r\n break\r\n case 5:\r\n r = v\r\n g = p\r\n b = q\r\n break\r\n }\r\n\r\n return {\r\n r: Math.round(r * 255),\r\n g: Math.round(g * 255),\r\n b: Math.round(b * 255),\r\n a\r\n }\r\n}\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HSV/A representation as an\r\n *\r\n * Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-100]}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHsv({ r, g, b, a }: RGB): HSVA {\r\n const max = Math.max(r, g, b),\r\n min = Math.min(r, g, b),\r\n d = max - min,\r\n s = max === 0 ? 0 : d / max,\r\n v = max / 255\r\n let h: any\r\n\r\n switch (max) {\r\n case min:\r\n h = 0\r\n break\r\n case r:\r\n h = g - b + d * (g < b ? 6 : 0)\r\n h /= 6 * d\r\n break\r\n case g:\r\n h = b - r + d * 2\r\n h /= 6 * d\r\n break\r\n case b:\r\n h = r - g + d * 4\r\n h /= 6 * d\r\n break\r\n }\r\n\r\n return {\r\n h: Math.round(h * 360),\r\n s: Math.round(s * 100),\r\n v: Math.round(v * 100),\r\n a: a || 1\r\n }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function textToRgb(str: COLOR): RGB {\r\n if (typeof str !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n const color = str.replace(/ /g, '')\r\n\r\n const m = RE_RGBA.exec(color)\r\n\r\n if (m === null) {\r\n return hexToRgb(color)\r\n }\r\n\r\n const rgb: RGB = {\r\n r: Math.min(255, parseInt(m[2], 10)),\r\n g: Math.min(255, parseInt(m[3], 10)),\r\n b: Math.min(255, parseInt(m[4], 10))\r\n }\r\n\r\n if (m[1]) {\r\n const alpha = parseFloat(m[5])\r\n rgb.a = Math.min(1, isNaN(alpha) === true ? 1 : alpha) * 100\r\n }\r\n\r\n return rgb\r\n}\r\n\r\n/**\r\n * Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).\r\n *\r\n * Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 100 or -100 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.\r\n */\r\nexport function lighten(color: COLOR, percent: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n if (typeof percent !== 'number') {\r\n throw new TypeError('Expected a numeric percent')\r\n }\r\n\r\n const rgb = textToRgb(color),\r\n t = percent < 0 ? 0 : 255,\r\n p = Math.abs(percent) / 100,\r\n R = rgb.r,\r\n G = rgb.g,\r\n B = rgb.b\r\n\r\n return (\r\n '#' +\r\n (\r\n 0x1_00_00_00 +\r\n (Math.round((t - R) * p) + R) * 0x1_00_00 +\r\n (Math.round((t - G) * p) + G) * 0x1_00 +\r\n (Math.round((t - B) * p) + B)\r\n )\r\n .toString(16)\r\n .slice(1)\r\n )\r\n}\r\n/**\r\n * Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function luminosity(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color,\r\n r = rgb.r / 255,\r\n g = rgb.g / 255,\r\n b = rgb.b / 255,\r\n R = r <= 0.039_28 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4),\r\n G = g <= 0.039_28 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4),\r\n B = b <= 0.039_28 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4)\r\n return 0.2126 * R + 0.7152 * G + 0.0722 * B\r\n}\r\n/**\r\n * Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function brightness(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n\r\n return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000\r\n}\r\n\r\n/**\r\n * Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.\r\n *\r\n * 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.\r\n */\r\nexport function blend(fgColor: COLOR | RGB, bgColor: COLOR | RGB) {\r\n if (typeof fgColor !== 'string' && (!fgColor || fgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as fgColor')\r\n }\r\n\r\n if (typeof bgColor !== 'string' && (!bgColor || bgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as bgColor')\r\n }\r\n\r\n const rgb1 = typeof fgColor === 'string' ? textToRgb(fgColor) : fgColor,\r\n r1 = rgb1.r / 255,\r\n g1 = rgb1.g / 255,\r\n b1 = rgb1.b / 255,\r\n a1 = rgb1.a !== void 0 ? rgb1.a / 100 : 1,\r\n rgb2 = typeof bgColor === 'string' ? textToRgb(bgColor) : bgColor,\r\n r2 = rgb2.r / 255,\r\n g2 = rgb2.g / 255,\r\n b2 = rgb2.b / 255,\r\n a2 = rgb2.a !== void 0 ? rgb2.a / 100 : 1,\r\n a = a1 + a2 * (1 - a1),\r\n r = Math.round(((r1 * a1 + r2 * a2 * (1 - a1)) / a) * 255),\r\n g = Math.round(((g1 * a1 + g2 * a2 * (1 - a1)) / a) * 255),\r\n b = Math.round(((b1 * a1 + b2 * a2 * (1 - a1)) / a) * 255)\r\n\r\n const ret = { r, g, b, a: Math.round(a * 100) }\r\n return typeof fgColor === 'string' ? rgbToHex(ret) : ret\r\n}\r\n\r\n/**\r\n * Increments or decrements the alpha of a string color.\r\n *\r\n * Accepts a HEX/A String as color and a number between -1 and 1 (including edges) as offset. Use a negative value to decrement and a positive number to increment (ex: blendAlpha('#ff0000', -0.1) to decrement alpha by 10%). Returns HEX/A String.\r\n */\r\nexport function blendAlpha(color: COLOR, offset: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n\r\n if (offset === void 0 || offset < -1 || offset > 1) {\r\n throw new TypeError('Expected offset to be between -1 and 1')\r\n }\r\n\r\n const { r, g, b, a } = textToRgb(color)\r\n const alpha = a !== void 0 ? a / 100 : 0\r\n\r\n return rgbToHex({\r\n r,\r\n g,\r\n b,\r\n a: Math.round(Math.min(1, Math.max(0, alpha + offset)) * 100)\r\n })\r\n}\r\n\r\n/**\r\n * Change color transparency\r\n */\r\nexport function changeAlpha(color: COLOR, alpha: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n if (alpha === void 0 || alpha < 0 || alpha > 100) {\r\n throw new TypeError('Expected alpha to be between 0 and 1')\r\n }\r\n const rgba = textToRgb(color)\r\n rgba.a = alpha\r\n\r\n return rgbToHex(rgba)\r\n}\r\n\r\nconst hueStep = 2\r\nconst saturationStep = 16\r\nconst saturationStep2 = 5\r\nconst brightnessStep1 = 5\r\nconst brightnessStep2 = 15\r\nconst lightColorCount = 5\r\nconst darkColorCount = 4\r\n\r\n/**\r\n * \u6839\u636E\u989C\u8272\u83B7\u53D6\u8C03\u8272\u677F\u989C\u8272(\u4ECE\u5DE6\u81F3\u53F3\u989C\u8272\u4ECE\u6D45\u5230\u6DF1\uFF0C6\u4E3A\u4E3B\u8272\u53F7)\r\n * @param color - \u989C\u8272\r\n * @param index - \u8C03\u8272\u677F\u7684\u5BF9\u5E94\u7684\u8272\u53F7(6\u4E3A\u4E3B\u8272\u53F7)\r\n * @description \u7B97\u6CD5\u5B9E\u73B0\u4ECEant-design\u8C03\u8272\u677F\u7B97\u6CD5\u4E2D\u501F\u9274 https://github.com/ant-design/ant-design/blob/master/components/style/color/colorPalette.less\r\n */\r\nexport function colorPalette(color: COLOR | RGB, index: PALETTE_INDEXES) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n const oldHsv = rgbToHsv(rgb)\r\n\r\n if (index === 6) return rgbToHex(rgb)\r\n\r\n const light = index < 6\r\n const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1\r\n const newHsv: HSVA = {\r\n h: hue(oldHsv, i, light),\r\n s: saturation(oldHsv, i, light),\r\n v: value(oldHsv, i, light),\r\n a: oldHsv.a\r\n }\r\n\r\n return rgbToHex(hsvToRgb(newHsv))\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u8272\u76F8\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction hue(hsv: HSVA, i: number, isLight: boolean) {\r\n let hue: number\r\n if (hsv.h >= 60 && hsv.h <= 240) {\r\n // \u51B7\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i\r\n } else {\r\n // \u6696\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i\r\n }\r\n if (hue < 0) hue += 360\r\n else if (hue >= 360) hue -= 360\r\n\r\n return hue\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u9971\u548C\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction saturation(hsv: HSVA, i: number, isLight: boolean) {\r\n let saturation: number\r\n if (isLight) saturation = hsv.s - saturationStep * i\r\n else if (i === darkColorCount) saturation = hsv.s + saturationStep\r\n else saturation = hsv.s + saturationStep2 * i\r\n\r\n if (saturation > 100) saturation = 100\r\n\r\n if (isLight && i === lightColorCount && saturation > 10) saturation = 10\r\n\r\n if (saturation < 6) saturation = 6\r\n\r\n return saturation\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u660E\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction value(hsv: HSVA, i: number, isLight: boolean) {\r\n let value: number\r\n value = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i\r\n\r\n if (value > 100) value = 100\r\n\r\n return value\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,IAAM,UAAU;AAaT,kBAAkB,EAAE,GAAG,GAAG,GAAG,KAAe;AACjD,QAAM,QAAQ,MAAM;AAEpB,MAAI,KAAK,MAAM,CAAC;AAChB,MAAI,KAAK,MAAM,CAAC;AAChB,MAAI,KAAK,MAAM,CAAC;AAEhB,MAAI,IAAI,OAAO,IAAI,OAAO,IAAI,OAAQ,SAAS,IAAK,KAAM;AACxD,UAAM,IAAI,UAAU,6DAA6D;AAAA,EACnF;AAEA,MAAI,OAAO;AACT,QAAI,OAAQ,MAAK,MAAO,MAAM,IAAM,GAAG,IAAK,KAAK,GAAI,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AAAA,EAC5E;AAEA,SAAO,MAAO,KAAK,KAAK,IAAM,KAAK,KAAO,KAAK,IAAK,SAAS,EAAE,EAAE,MAAM,CAAC,IAAI;AAC9E;AAaO,kBAAkB,KAAe;AACtC,MAAI,OAAO,QAAQ,UAAU;AAC3B,UAAM,IAAI,UAAU,mBAAmB;AAAA,EACzC;AAEA,QAAM,IAAI,QAAQ,MAAM,EAAE;AAE1B,MAAI,IAAI,WAAW,GAAG;AACpB,UAAM,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI;AAAA,EACzD,WAAW,IAAI,WAAW,GAAG;AAC3B,UAAM,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK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,IAAI,KAAK,MAAM,IAAI,KAAK,KAAK;AAI/B,WAAM,UAAU,IAAI,IAAI,UAAU,IAAI,IAAI,IAAI,UAAU;AAAA,EAC1D,OAAO;AAIL,WAAM,UAAU,IAAI,IAAI,UAAU,IAAI,IAAI,IAAI,UAAU;AAAA,EAC1D;AACA,MAAI,OAAM;AAAG,YAAO;AAAA,WACX,QAAO;AAAK,YAAO;AAE5B,SAAO;AACT;AAQA,oBAAoB,KAAW,GAAW,SAAkB;AAC1D,MAAI;AACJ,MAAI;AAAS,kBAAa,IAAI,IAAI,iBAAiB;AAAA,WAC1C,MAAM;AAAgB,kBAAa,IAAI,IAAI;AAAA;AAC/C,kBAAa,IAAI,IAAI,kBAAkB;AAE5C,MAAI,cAAa;AAAK,kBAAa;AAEnC,MAAI,WAAW,MAAM,mBAAmB,cAAa;AAAI,kBAAa;AAEtE,MAAI,cAAa;AAAG,kBAAa;AAEjC,SAAO;AACT;AAQA,eAAe,KAAW,GAAW,SAAkB;AACrD,MAAI;AACJ,WAAQ,UAAU,IAAI,IAAI,kBAAkB,IAAI,IAAI,IAAI,kBAAkB;AAE1E,MAAI,SAAQ;AAAK,aAAQ;AAEzB,SAAO;AACT;",
6
6
  "names": []
7
7
  }
package/index.d.ts CHANGED
@@ -8,6 +8,7 @@ declare type RGBA_TEXT = string;
8
8
  declare type HEX_TEXT = string;
9
9
  declare type HSVA_TEXT = string;
10
10
  declare type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT;
11
+ declare type PALETTE_INDEXES = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
11
12
  /**
12
13
  * Converts a RGB/A color
13
14
  *
@@ -19,7 +20,7 @@ declare type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT;
19
20
  *
20
21
  * If Alpha channel is present in the original object it will be present also in the output.
21
22
  */
22
- declare function rgbToHex({ r, g, b, a }: RGBA): HEX;
23
+ declare function rgbToHex({ r, g, b, a }: RGB): HEX;
23
24
  /**
24
25
  * Converts a HEX/A color
25
26
  *
@@ -55,7 +56,7 @@ declare function hsvToRgb({ h, s, v, a }: HSVA): RGBA;
55
56
  *
56
57
  * If Alpha channel is present in the original object it will be present also in the output.
57
58
  */
58
- declare function rgbToHsv({ r, g, b, a }: RGBA): HSVA;
59
+ declare function rgbToHsv({ r, g, b, a }: RGB): HSVA;
59
60
  /**
60
61
  * Converts a HEX/A color
61
62
  *
@@ -100,8 +101,19 @@ declare function blend(fgColor: COLOR | RGB, bgColor: COLOR | RGB): string | {
100
101
  /**
101
102
  * Increments or decrements the alpha of a string color.
102
103
  *
103
- * Accepts a HEX/A String as color and a number between -1 and 1 (including edges) as offset. Use a negative value to decrement and a positive number to increment (ex: changeAlpha('#ff0000', -0.1) to decrement alpha by 10%). Returns HEX/A String.
104
+ * Accepts a HEX/A String as color and a number between -1 and 1 (including edges) as offset. Use a negative value to decrement and a positive number to increment (ex: blendAlpha('#ff0000', -0.1) to decrement alpha by 10%). Returns HEX/A String.
104
105
  */
105
- declare function changeAlpha(color: COLOR, offset: number): string;
106
+ declare function blendAlpha(color: COLOR, offset: number): string;
107
+ /**
108
+ * Change color transparency
109
+ */
110
+ declare function changeAlpha(color: COLOR, alpha: number): string;
111
+ /**
112
+ * 根据颜色获取调色板颜色(从左至右颜色从浅到深,6为主色号)
113
+ * @param color - 颜色
114
+ * @param index - 调色板的对应的色号(6为主色号)
115
+ * @description 算法实现从ant-design调色板算法中借鉴 https://github.com/ant-design/ant-design/blob/master/components/style/color/colorPalette.less
116
+ */
117
+ declare function colorPalette(color: COLOR | RGB, index: PALETTE_INDEXES): string;
106
118
 
107
- export { COLOR, HEX, HEX_TEXT, HSVA, HSVA_TEXT, RGB, RGBA, RGBA_TEXT, blend, brightness, changeAlpha, hexToRgb, hsvToRgb, lighten, luminosity, rgbToHex, rgbToHsv, textToRgb };
119
+ export { COLOR, HEX, HEX_TEXT, HSVA, HSVA_TEXT, PALETTE_INDEXES, RGB, RGBA, RGBA_TEXT, blend, blendAlpha, brightness, changeAlpha, colorPalette, hexToRgb, hsvToRgb, lighten, luminosity, rgbToHex, rgbToHsv, textToRgb };
package/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // index.ts
2
- var reRGBA = /^rgb(a)?\((\d{1,3}),(\d{1,3}),(\d{1,3}),?([01]?\.?\d*?)?\)$/;
2
+ var RE_RGBA = /^rgb(a)?\((\d{1,3}),(\d{1,3}),(\d{1,3}),?([01]?\.?\d*?)?\)$/;
3
3
  function rgbToHex({ r, g, b, a }) {
4
4
  const alpha = a !== void 0;
5
5
  r = Math.round(r);
@@ -95,7 +95,7 @@ function rgbToHsv({ r, g, b, a }) {
95
95
  h: Math.round(h * 360),
96
96
  s: Math.round(s * 100),
97
97
  v: Math.round(v * 100),
98
- a
98
+ a: a || 1
99
99
  };
100
100
  }
101
101
  function textToRgb(str) {
@@ -103,7 +103,7 @@ function textToRgb(str) {
103
103
  throw new TypeError("Expected a string");
104
104
  }
105
105
  const color = str.replace(/ /g, "");
106
- const m = reRGBA.exec(color);
106
+ const m = RE_RGBA.exec(color);
107
107
  if (m === null) {
108
108
  return hexToRgb(color);
109
109
  }
@@ -153,7 +153,7 @@ function blend(fgColor, bgColor) {
153
153
  const ret = { r, g, b, a: Math.round(a * 100) };
154
154
  return typeof fgColor === "string" ? rgbToHex(ret) : ret;
155
155
  }
156
- function changeAlpha(color, offset) {
156
+ function blendAlpha(color, offset) {
157
157
  if (typeof color !== "string") {
158
158
  throw new TypeError("Expected a string as color");
159
159
  }
@@ -169,10 +169,84 @@ function changeAlpha(color, offset) {
169
169
  a: Math.round(Math.min(1, Math.max(0, alpha + offset)) * 100)
170
170
  });
171
171
  }
172
+ function changeAlpha(color, alpha) {
173
+ if (typeof color !== "string") {
174
+ throw new TypeError("Expected a string as color");
175
+ }
176
+ if (alpha === void 0 || alpha < 0 || alpha > 100) {
177
+ throw new TypeError("Expected alpha to be between 0 and 1");
178
+ }
179
+ const rgba = textToRgb(color);
180
+ rgba.a = alpha;
181
+ return rgbToHex(rgba);
182
+ }
183
+ var hueStep = 2;
184
+ var saturationStep = 16;
185
+ var saturationStep2 = 5;
186
+ var brightnessStep1 = 5;
187
+ var brightnessStep2 = 15;
188
+ var lightColorCount = 5;
189
+ var darkColorCount = 4;
190
+ function colorPalette(color, index) {
191
+ if (typeof color !== "string" && (!color || color.r === void 0)) {
192
+ throw new TypeError("Expected a string or a {r, g, b} object as color");
193
+ }
194
+ const rgb = typeof color === "string" ? textToRgb(color) : color;
195
+ const oldHsv = rgbToHsv(rgb);
196
+ if (index === 6)
197
+ return rgbToHex(rgb);
198
+ const light = index < 6;
199
+ const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1;
200
+ const newHsv = {
201
+ h: hue(oldHsv, i, light),
202
+ s: saturation(oldHsv, i, light),
203
+ v: value(oldHsv, i, light),
204
+ a: oldHsv.a
205
+ };
206
+ return rgbToHex(hsvToRgb(newHsv));
207
+ }
208
+ function hue(hsv, i, isLight) {
209
+ let hue2;
210
+ if (hsv.h >= 60 && hsv.h <= 240) {
211
+ hue2 = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i;
212
+ } else {
213
+ hue2 = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i;
214
+ }
215
+ if (hue2 < 0)
216
+ hue2 += 360;
217
+ else if (hue2 >= 360)
218
+ hue2 -= 360;
219
+ return hue2;
220
+ }
221
+ function saturation(hsv, i, isLight) {
222
+ let saturation2;
223
+ if (isLight)
224
+ saturation2 = hsv.s - saturationStep * i;
225
+ else if (i === darkColorCount)
226
+ saturation2 = hsv.s + saturationStep;
227
+ else
228
+ saturation2 = hsv.s + saturationStep2 * i;
229
+ if (saturation2 > 100)
230
+ saturation2 = 100;
231
+ if (isLight && i === lightColorCount && saturation2 > 10)
232
+ saturation2 = 10;
233
+ if (saturation2 < 6)
234
+ saturation2 = 6;
235
+ return saturation2;
236
+ }
237
+ function value(hsv, i, isLight) {
238
+ let value2;
239
+ value2 = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i;
240
+ if (value2 > 100)
241
+ value2 = 100;
242
+ return value2;
243
+ }
172
244
  export {
173
245
  blend,
246
+ blendAlpha,
174
247
  brightness,
175
248
  changeAlpha,
249
+ colorPalette,
176
250
  hexToRgb,
177
251
  hsvToRgb,
178
252
  lighten,
package/index.esm.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../index.ts"],
4
- "sourcesContent": ["export type RGBA = Record<'r' | 'g' | 'b' | 'a', number>\r\nexport type RGB = Record<'r' | 'g' | 'b', number> & { a?: number }\r\nexport type HEX = string\r\nexport type HSVA = Record<'h' | 's' | 'v' | 'a', number>\r\n\r\nexport type RGBA_TEXT = string\r\nexport type HEX_TEXT = string\r\nexport type HSVA_TEXT = string\r\nexport type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT\r\n\r\nconst reRGBA = /^rgb(a)?\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3}),?([01]?\\.?\\d*?)?\\)$/\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HEX/A representation as a\r\n *\r\n * String (`#RRGGBB<AA>`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHex({ r, g, b, a }: RGBA): HEX {\r\n const alpha = a !== void 0\r\n\r\n r = Math.round(r)\r\n g = Math.round(g)\r\n b = Math.round(b)\r\n\r\n if (r > 255 || g > 255 || b > 255 || (alpha && a > 100)) {\r\n throw new TypeError('Expected 3 numbers below 256 (and optionally one below 100)')\r\n }\r\n\r\n if (alpha) {\r\n a = Number((Math.round((255 * a) / 100) | (1 << 8)).toString(16).slice(1))\r\n }\r\n\r\n return '#' + (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1) + a\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hexToRgb(hex: HEX): RGB {\r\n if (typeof hex !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n hex = hex.replace(/^#/, '')\r\n\r\n if (hex.length === 3) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]\r\n } else if (hex.length === 4) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3]\r\n }\r\n\r\n const num = parseInt(hex, 16)\r\n\r\n return hex.length > 6\r\n ? { r: (num >> 24) & 255, g: (num >> 16) & 255, b: (num >> 8) & 255, a: Math.round((num & 255) / 2.55) }\r\n : { r: num >> 16, g: (num >> 8) & 255, b: num & 255 }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hsvToRgb({ h, s, v, a }: HSVA): RGBA {\r\n let r: any, g: any, b: any\r\n s = s / 100\r\n v = v / 100\r\n\r\n h = h / 360\r\n const i = Math.floor(h * 6),\r\n f = h * 6 - i,\r\n p = v * (1 - s),\r\n q = v * (1 - f * s),\r\n t = v * (1 - (1 - f) * s)\r\n\r\n switch (i % 6) {\r\n case 0:\r\n r = v\r\n g = t\r\n b = p\r\n break\r\n case 1:\r\n r = q\r\n g = v\r\n b = p\r\n break\r\n case 2:\r\n r = p\r\n g = v\r\n b = t\r\n break\r\n case 3:\r\n r = p\r\n g = q\r\n b = v\r\n break\r\n case 4:\r\n r = t\r\n g = p\r\n b = v\r\n break\r\n case 5:\r\n r = v\r\n g = p\r\n b = q\r\n break\r\n }\r\n\r\n return {\r\n r: Math.round(r * 255),\r\n g: Math.round(g * 255),\r\n b: Math.round(b * 255),\r\n a\r\n }\r\n}\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HSV/A representation as an\r\n *\r\n * Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-100]}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHsv({ r, g, b, a }: RGBA): HSVA {\r\n const max = Math.max(r, g, b),\r\n min = Math.min(r, g, b),\r\n d = max - min,\r\n s = max === 0 ? 0 : d / max,\r\n v = max / 255\r\n let h: any\r\n\r\n switch (max) {\r\n case min:\r\n h = 0\r\n break\r\n case r:\r\n h = g - b + d * (g < b ? 6 : 0)\r\n h /= 6 * d\r\n break\r\n case g:\r\n h = b - r + d * 2\r\n h /= 6 * d\r\n break\r\n case b:\r\n h = r - g + d * 4\r\n h /= 6 * d\r\n break\r\n }\r\n\r\n return {\r\n h: Math.round(h * 360),\r\n s: Math.round(s * 100),\r\n v: Math.round(v * 100),\r\n a\r\n }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function textToRgb(str: COLOR): RGB {\r\n if (typeof str !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n const color = str.replace(/ /g, '')\r\n\r\n const m = reRGBA.exec(color)\r\n\r\n if (m === null) {\r\n return hexToRgb(color)\r\n }\r\n\r\n const rgb: RGB = {\r\n r: Math.min(255, parseInt(m[2], 10)),\r\n g: Math.min(255, parseInt(m[3], 10)),\r\n b: Math.min(255, parseInt(m[4], 10))\r\n }\r\n\r\n if (m[1]) {\r\n const alpha = parseFloat(m[5])\r\n rgb.a = Math.min(1, isNaN(alpha) === true ? 1 : alpha) * 100\r\n }\r\n\r\n return rgb\r\n}\r\n\r\n/**\r\n * Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).\r\n *\r\n * Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 100 or -100 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.\r\n */\r\nexport function lighten(color: COLOR, percent: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n if (typeof percent !== 'number') {\r\n throw new TypeError('Expected a numeric percent')\r\n }\r\n\r\n const rgb = textToRgb(color),\r\n t = percent < 0 ? 0 : 255,\r\n p = Math.abs(percent) / 100,\r\n R = rgb.r,\r\n G = rgb.g,\r\n B = rgb.b\r\n\r\n return (\r\n '#' +\r\n (\r\n 0x1_00_00_00 +\r\n (Math.round((t - R) * p) + R) * 0x1_00_00 +\r\n (Math.round((t - G) * p) + G) * 0x1_00 +\r\n (Math.round((t - B) * p) + B)\r\n )\r\n .toString(16)\r\n .slice(1)\r\n )\r\n}\r\n/**\r\n * Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function luminosity(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color,\r\n r = rgb.r / 255,\r\n g = rgb.g / 255,\r\n b = rgb.b / 255,\r\n R = r <= 0.039_28 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4),\r\n G = g <= 0.039_28 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4),\r\n B = b <= 0.039_28 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4)\r\n return 0.2126 * R + 0.7152 * G + 0.0722 * B\r\n}\r\n/**\r\n * Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function brightness(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n\r\n return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000\r\n}\r\n\r\n/**\r\n * Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.\r\n *\r\n * 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.\r\n */\r\nexport function blend(fgColor: COLOR | RGB, bgColor: COLOR | RGB) {\r\n if (typeof fgColor !== 'string' && (!fgColor || fgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as fgColor')\r\n }\r\n\r\n if (typeof bgColor !== 'string' && (!bgColor || bgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as bgColor')\r\n }\r\n\r\n const rgb1 = typeof fgColor === 'string' ? textToRgb(fgColor) : fgColor,\r\n r1 = rgb1.r / 255,\r\n g1 = rgb1.g / 255,\r\n b1 = rgb1.b / 255,\r\n a1 = rgb1.a !== void 0 ? rgb1.a / 100 : 1,\r\n rgb2 = typeof bgColor === 'string' ? textToRgb(bgColor) : bgColor,\r\n r2 = rgb2.r / 255,\r\n g2 = rgb2.g / 255,\r\n b2 = rgb2.b / 255,\r\n a2 = rgb2.a !== void 0 ? rgb2.a / 100 : 1,\r\n a = a1 + a2 * (1 - a1),\r\n r = Math.round(((r1 * a1 + r2 * a2 * (1 - a1)) / a) * 255),\r\n g = Math.round(((g1 * a1 + g2 * a2 * (1 - a1)) / a) * 255),\r\n b = Math.round(((b1 * a1 + b2 * a2 * (1 - a1)) / a) * 255)\r\n\r\n const ret = { r, g, b, a: Math.round(a * 100) }\r\n return typeof fgColor === 'string' ? rgbToHex(ret) : ret\r\n}\r\n\r\n/**\r\n * Increments or decrements the alpha of a string color.\r\n *\r\n * Accepts a HEX/A String as color and a number between -1 and 1 (including edges) as offset. Use a negative value to decrement and a positive number to increment (ex: changeAlpha('#ff0000', -0.1) to decrement alpha by 10%). Returns HEX/A String.\r\n */\r\nexport function changeAlpha(color: COLOR, offset: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n\r\n if (offset === void 0 || offset < -1 || offset > 1) {\r\n throw new TypeError('Expected offset to be between -1 and 1')\r\n }\r\n\r\n const { r, g, b, a } = textToRgb(color)\r\n const alpha = a !== void 0 ? a / 100 : 0\r\n\r\n return rgbToHex({\r\n r,\r\n g,\r\n b,\r\n a: Math.round(Math.min(1, Math.max(0, alpha + offset)) * 100)\r\n })\r\n}\r\n"],
5
- "mappings": ";AAUA,IAAM,SAAS;AAaR,kBAAkB,EAAE,GAAG,GAAG,GAAG,KAAgB;AAClD,QAAM,QAAQ,MAAM;AAEpB,MAAI,KAAK,MAAM,CAAC;AAChB,MAAI,KAAK,MAAM,CAAC;AAChB,MAAI,KAAK,MAAM,CAAC;AAEhB,MAAI,IAAI,OAAO,IAAI,OAAO,IAAI,OAAQ,SAAS,IAAI,KAAM;AACvD,UAAM,IAAI,UAAU,6DAA6D;AAAA,EACnF;AAEA,MAAI,OAAO;AACT,QAAI,OAAQ,MAAK,MAAO,MAAM,IAAK,GAAG,IAAK,KAAK,GAAI,SAAS,EAAE,EAAE,MAAM,CAAC,CA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,MAAK,KAAK,KAAK,KAAM,KAAI,OAAO,IAAK,GAAG;AAE3D,QAAM,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,KAAK,MAAM,IAAI,GAAG,EAAE;AAC9C,SAAO,OAAO,YAAY,WAAW,SAAS,GAAG,IAAI;AACvD;AAOO,qBAAqB,OAAc,QAAgB;AACxD,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAM,IAAI,UAAU,4BAA4B;AAAA,EAClD;AAEA,MAAI,WAAW,UAAU,SAAS,MAAM,SAAS,GAAG;AAClD,UAAM,IAAI,UAAU,wCAAwC;AAAA,EAC9D;AAEA,QAAM,EAAE,GAAG,GAAG,GAAG,MAAM,UAAU,KAAK;AACtC,QAAM,QAAQ,MAAM,SAAS,IAAI,MAAM;AAEvC,SAAO,SAAS;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG,KAAK,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,MAAM,CAAC,IAAI,GAAG;AAAA,EAC9D,CAAC;AACH;",
4
+ "sourcesContent": ["export type RGBA = Record<'r' | 'g' | 'b' | 'a', number>\r\nexport type RGB = Record<'r' | 'g' | 'b', number> & { a?: number }\r\nexport type HEX = string\r\nexport type HSVA = Record<'h' | 's' | 'v' | 'a', number>\r\n\r\nexport type RGBA_TEXT = string\r\nexport type HEX_TEXT = string\r\nexport type HSVA_TEXT = string\r\nexport type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT\r\nexport type PALETTE_INDEXES = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10\r\n\r\nconst RE_RGBA = /^rgb(a)?\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3}),?([01]?\\.?\\d*?)?\\)$/\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HEX/A representation as a\r\n *\r\n * String (`#RRGGBB<AA>`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHex({ r, g, b, a }: RGB): HEX {\r\n const alpha = a !== void 0\r\n\r\n r = Math.round(r)\r\n g = Math.round(g)\r\n b = Math.round(b)\r\n\r\n if (r > 255 || g > 255 || b > 255 || (alpha && a! > 100)) {\r\n throw new TypeError('Expected 3 numbers below 256 (and optionally one below 100)')\r\n }\r\n\r\n if (alpha) {\r\n a = Number((Math.round((255 * a!) / 100) | (1 << 8)).toString(16).slice(1))\r\n }\r\n\r\n return '#' + (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1) + a\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hexToRgb(hex: HEX): RGB {\r\n if (typeof hex !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n hex = hex.replace(/^#/, '')\r\n\r\n if (hex.length === 3) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]\r\n } else if (hex.length === 4) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3]\r\n }\r\n\r\n const num = parseInt(hex, 16)\r\n\r\n return hex.length > 6\r\n ? { r: (num >> 24) & 255, g: (num >> 16) & 255, b: (num >> 8) & 255, a: Math.round((num & 255) / 2.55) }\r\n : { r: num >> 16, g: (num >> 8) & 255, b: num & 255 }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hsvToRgb({ h, s, v, a }: HSVA): RGBA {\r\n let r: any, g: any, b: any\r\n s = s / 100\r\n v = v / 100\r\n\r\n h = h / 360\r\n const i = Math.floor(h * 6),\r\n f = h * 6 - i,\r\n p = v * (1 - s),\r\n q = v * (1 - f * s),\r\n t = v * (1 - (1 - f) * s)\r\n\r\n switch (i % 6) {\r\n case 0:\r\n r = v\r\n g = t\r\n b = p\r\n break\r\n case 1:\r\n r = q\r\n g = v\r\n b = p\r\n break\r\n case 2:\r\n r = p\r\n g = v\r\n b = t\r\n break\r\n case 3:\r\n r = p\r\n g = q\r\n b = v\r\n break\r\n case 4:\r\n r = t\r\n g = p\r\n b = v\r\n break\r\n case 5:\r\n r = v\r\n g = p\r\n b = q\r\n break\r\n }\r\n\r\n return {\r\n r: Math.round(r * 255),\r\n g: Math.round(g * 255),\r\n b: Math.round(b * 255),\r\n a\r\n }\r\n}\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HSV/A representation as an\r\n *\r\n * Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-100]}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHsv({ r, g, b, a }: RGB): HSVA {\r\n const max = Math.max(r, g, b),\r\n min = Math.min(r, g, b),\r\n d = max - min,\r\n s = max === 0 ? 0 : d / max,\r\n v = max / 255\r\n let h: any\r\n\r\n switch (max) {\r\n case min:\r\n h = 0\r\n break\r\n case r:\r\n h = g - b + d * (g < b ? 6 : 0)\r\n h /= 6 * d\r\n break\r\n case g:\r\n h = b - r + d * 2\r\n h /= 6 * d\r\n break\r\n case b:\r\n h = r - g + d * 4\r\n h /= 6 * d\r\n break\r\n }\r\n\r\n return {\r\n h: Math.round(h * 360),\r\n s: Math.round(s * 100),\r\n v: Math.round(v * 100),\r\n a: a || 1\r\n }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function textToRgb(str: COLOR): RGB {\r\n if (typeof str !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n const color = str.replace(/ /g, '')\r\n\r\n const m = RE_RGBA.exec(color)\r\n\r\n if (m === null) {\r\n return hexToRgb(color)\r\n }\r\n\r\n const rgb: RGB = {\r\n r: Math.min(255, parseInt(m[2], 10)),\r\n g: Math.min(255, parseInt(m[3], 10)),\r\n b: Math.min(255, parseInt(m[4], 10))\r\n }\r\n\r\n if (m[1]) {\r\n const alpha = parseFloat(m[5])\r\n rgb.a = Math.min(1, isNaN(alpha) === true ? 1 : alpha) * 100\r\n }\r\n\r\n return rgb\r\n}\r\n\r\n/**\r\n * Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).\r\n *\r\n * Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 100 or -100 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.\r\n */\r\nexport function lighten(color: COLOR, percent: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n if (typeof percent !== 'number') {\r\n throw new TypeError('Expected a numeric percent')\r\n }\r\n\r\n const rgb = textToRgb(color),\r\n t = percent < 0 ? 0 : 255,\r\n p = Math.abs(percent) / 100,\r\n R = rgb.r,\r\n G = rgb.g,\r\n B = rgb.b\r\n\r\n return (\r\n '#' +\r\n (\r\n 0x1_00_00_00 +\r\n (Math.round((t - R) * p) + R) * 0x1_00_00 +\r\n (Math.round((t - G) * p) + G) * 0x1_00 +\r\n (Math.round((t - B) * p) + B)\r\n )\r\n .toString(16)\r\n .slice(1)\r\n )\r\n}\r\n/**\r\n * Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function luminosity(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color,\r\n r = rgb.r / 255,\r\n g = rgb.g / 255,\r\n b = rgb.b / 255,\r\n R = r <= 0.039_28 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4),\r\n G = g <= 0.039_28 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4),\r\n B = b <= 0.039_28 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4)\r\n return 0.2126 * R + 0.7152 * G + 0.0722 * B\r\n}\r\n/**\r\n * Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function brightness(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n\r\n return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000\r\n}\r\n\r\n/**\r\n * Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.\r\n *\r\n * 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.\r\n */\r\nexport function blend(fgColor: COLOR | RGB, bgColor: COLOR | RGB) {\r\n if (typeof fgColor !== 'string' && (!fgColor || fgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as fgColor')\r\n }\r\n\r\n if (typeof bgColor !== 'string' && (!bgColor || bgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as bgColor')\r\n }\r\n\r\n const rgb1 = typeof fgColor === 'string' ? textToRgb(fgColor) : fgColor,\r\n r1 = rgb1.r / 255,\r\n g1 = rgb1.g / 255,\r\n b1 = rgb1.b / 255,\r\n a1 = rgb1.a !== void 0 ? rgb1.a / 100 : 1,\r\n rgb2 = typeof bgColor === 'string' ? textToRgb(bgColor) : bgColor,\r\n r2 = rgb2.r / 255,\r\n g2 = rgb2.g / 255,\r\n b2 = rgb2.b / 255,\r\n a2 = rgb2.a !== void 0 ? rgb2.a / 100 : 1,\r\n a = a1 + a2 * (1 - a1),\r\n r = Math.round(((r1 * a1 + r2 * a2 * (1 - a1)) / a) * 255),\r\n g = Math.round(((g1 * a1 + g2 * a2 * (1 - a1)) / a) * 255),\r\n b = Math.round(((b1 * a1 + b2 * a2 * (1 - a1)) / a) * 255)\r\n\r\n const ret = { r, g, b, a: Math.round(a * 100) }\r\n return typeof fgColor === 'string' ? rgbToHex(ret) : ret\r\n}\r\n\r\n/**\r\n * Increments or decrements the alpha of a string color.\r\n *\r\n * Accepts a HEX/A String as color and a number between -1 and 1 (including edges) as offset. Use a negative value to decrement and a positive number to increment (ex: blendAlpha('#ff0000', -0.1) to decrement alpha by 10%). Returns HEX/A String.\r\n */\r\nexport function blendAlpha(color: COLOR, offset: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n\r\n if (offset === void 0 || offset < -1 || offset > 1) {\r\n throw new TypeError('Expected offset to be between -1 and 1')\r\n }\r\n\r\n const { r, g, b, a } = textToRgb(color)\r\n const alpha = a !== void 0 ? a / 100 : 0\r\n\r\n return rgbToHex({\r\n r,\r\n g,\r\n b,\r\n a: Math.round(Math.min(1, Math.max(0, alpha + offset)) * 100)\r\n })\r\n}\r\n\r\n/**\r\n * Change color transparency\r\n */\r\nexport function changeAlpha(color: COLOR, alpha: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n if (alpha === void 0 || alpha < 0 || alpha > 100) {\r\n throw new TypeError('Expected alpha to be between 0 and 1')\r\n }\r\n const rgba = textToRgb(color)\r\n rgba.a = alpha\r\n\r\n return rgbToHex(rgba)\r\n}\r\n\r\nconst hueStep = 2\r\nconst saturationStep = 16\r\nconst saturationStep2 = 5\r\nconst brightnessStep1 = 5\r\nconst brightnessStep2 = 15\r\nconst lightColorCount = 5\r\nconst darkColorCount = 4\r\n\r\n/**\r\n * \u6839\u636E\u989C\u8272\u83B7\u53D6\u8C03\u8272\u677F\u989C\u8272(\u4ECE\u5DE6\u81F3\u53F3\u989C\u8272\u4ECE\u6D45\u5230\u6DF1\uFF0C6\u4E3A\u4E3B\u8272\u53F7)\r\n * @param color - \u989C\u8272\r\n * @param index - \u8C03\u8272\u677F\u7684\u5BF9\u5E94\u7684\u8272\u53F7(6\u4E3A\u4E3B\u8272\u53F7)\r\n * @description \u7B97\u6CD5\u5B9E\u73B0\u4ECEant-design\u8C03\u8272\u677F\u7B97\u6CD5\u4E2D\u501F\u9274 https://github.com/ant-design/ant-design/blob/master/components/style/color/colorPalette.less\r\n */\r\nexport function colorPalette(color: COLOR | RGB, index: PALETTE_INDEXES) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n const oldHsv = rgbToHsv(rgb)\r\n\r\n if (index === 6) return rgbToHex(rgb)\r\n\r\n const light = index < 6\r\n const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1\r\n const newHsv: HSVA = {\r\n h: hue(oldHsv, i, light),\r\n s: saturation(oldHsv, i, light),\r\n v: value(oldHsv, i, light),\r\n a: oldHsv.a\r\n }\r\n\r\n return rgbToHex(hsvToRgb(newHsv))\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u8272\u76F8\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction hue(hsv: HSVA, i: number, isLight: boolean) {\r\n let hue: number\r\n if (hsv.h >= 60 && hsv.h <= 240) {\r\n // \u51B7\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i\r\n } else {\r\n // \u6696\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i\r\n }\r\n if (hue < 0) hue += 360\r\n else if (hue >= 360) hue -= 360\r\n\r\n return hue\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u9971\u548C\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction saturation(hsv: HSVA, i: number, isLight: boolean) {\r\n let saturation: number\r\n if (isLight) saturation = hsv.s - saturationStep * i\r\n else if (i === darkColorCount) saturation = hsv.s + saturationStep\r\n else saturation = hsv.s + saturationStep2 * i\r\n\r\n if (saturation > 100) saturation = 100\r\n\r\n if (isLight && i === lightColorCount && saturation > 10) saturation = 10\r\n\r\n if (saturation < 6) saturation = 6\r\n\r\n return saturation\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u660E\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction value(hsv: HSVA, i: number, isLight: boolean) {\r\n let value: number\r\n value = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i\r\n\r\n if (value > 100) value = 100\r\n\r\n return value\r\n}\r\n"],
5
+ "mappings": ";AAWA,IAAM,UAAU;AAaT,kBAAkB,EAAE,GAAG,GAAG,GAAG,KAAe;AACjD,QAAM,QAAQ,MAAM;AAEpB,MAAI,KAAK,MAAM,CAAC;AAChB,MAAI,KAAK,MAAM,CAAC;AAChB,MAAI,KAAK,MAAM,CAAC;AAEhB,MAAI,IAAI,OAAO,IAAI,OAAO,IAAI,OAAQ,SAAS,IAAK,KAAM;AACxD,UAAM,IAAI,UAAU,6DAA6D;AAAA,EACnF;AAEA,MAAI,OAAO;AACT,QAAI,OAAQ,MAAK,MAAO,MAAM,IAAM,GAAG,IAAK,KAAK,GAAI,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AAAA,EAC5E;AAEA,SAAO,MAAO,KAAK,KAAK,IAAM,KAAK,KAAO,KAAK,IAAK,SAAS,EAAE,EAAE,MAAM,CAAC,IAAI;AAC9E;AAaO,kBAAkB,KAAe;AACtC,MAAI,OAAO,QAAQ,UAAU;AAC3B,UAAM,IAAI,UAAU,mBAAmB;AAAA,EACzC;AAEA,QAAM,IAAI,QAAQ,MAAM,EAAE;AAE1B,MAAI,IAAI,WAAW,GAAG;AACpB,UAAM,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI;AAAA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,OAAO;AAAA,EACZ;AAEA,SAAO,SAAS,SAAS,MAAM,CAAC;AAClC;AAQA,aAAa,KAAW,GAAW,SAAkB;AACnD,MAAI;AACJ,MAAI,IAAI,KAAK,MAAM,IAAI,KAAK,KAAK;AAI/B,WAAM,UAAU,IAAI,IAAI,UAAU,IAAI,IAAI,IAAI,UAAU;AAAA,EAC1D,OAAO;AAIL,WAAM,UAAU,IAAI,IAAI,UAAU,IAAI,IAAI,IAAI,UAAU;AAAA,EAC1D;AACA,MAAI,OAAM;AAAG,YAAO;AAAA,WACX,QAAO;AAAK,YAAO;AAE5B,SAAO;AACT;AAQA,oBAAoB,KAAW,GAAW,SAAkB;AAC1D,MAAI;AACJ,MAAI;AAAS,kBAAa,IAAI,IAAI,iBAAiB;AAAA,WAC1C,MAAM;AAAgB,kBAAa,IAAI,IAAI;AAAA;AAC/C,kBAAa,IAAI,IAAI,kBAAkB;AAE5C,MAAI,cAAa;AAAK,kBAAa;AAEnC,MAAI,WAAW,MAAM,mBAAmB,cAAa;AAAI,kBAAa;AAEtE,MAAI,cAAa;AAAG,kBAAa;AAEjC,SAAO;AACT;AAQA,eAAe,KAAW,GAAW,SAAkB;AACrD,MAAI;AACJ,WAAQ,UAAU,IAAI,IAAI,kBAAkB,IAAI,IAAI,IAAI,kBAAkB;AAE1E,MAAI,SAAQ;AAAK,aAAQ;AAEzB,SAAO;AACT;",
6
6
  "names": []
7
7
  }
package/index.iife.js CHANGED
@@ -21,8 +21,10 @@ var HairyPalette = (() => {
21
21
  var util_color_exports = {};
22
22
  __export(util_color_exports, {
23
23
  blend: () => blend,
24
+ blendAlpha: () => blendAlpha,
24
25
  brightness: () => brightness,
25
26
  changeAlpha: () => changeAlpha,
27
+ colorPalette: () => colorPalette,
26
28
  hexToRgb: () => hexToRgb,
27
29
  hsvToRgb: () => hsvToRgb,
28
30
  lighten: () => lighten,
@@ -31,7 +33,7 @@ var HairyPalette = (() => {
31
33
  rgbToHsv: () => rgbToHsv,
32
34
  textToRgb: () => textToRgb
33
35
  });
34
- var reRGBA = /^rgb(a)?\((\d{1,3}),(\d{1,3}),(\d{1,3}),?([01]?\.?\d*?)?\)$/;
36
+ var RE_RGBA = /^rgb(a)?\((\d{1,3}),(\d{1,3}),(\d{1,3}),?([01]?\.?\d*?)?\)$/;
35
37
  function rgbToHex({ r, g, b, a }) {
36
38
  const alpha = a !== void 0;
37
39
  r = Math.round(r);
@@ -127,7 +129,7 @@ var HairyPalette = (() => {
127
129
  h: Math.round(h * 360),
128
130
  s: Math.round(s * 100),
129
131
  v: Math.round(v * 100),
130
- a
132
+ a: a || 1
131
133
  };
132
134
  }
133
135
  function textToRgb(str) {
@@ -135,7 +137,7 @@ var HairyPalette = (() => {
135
137
  throw new TypeError("Expected a string");
136
138
  }
137
139
  const color = str.replace(/ /g, "");
138
- const m = reRGBA.exec(color);
140
+ const m = RE_RGBA.exec(color);
139
141
  if (m === null) {
140
142
  return hexToRgb(color);
141
143
  }
@@ -185,7 +187,7 @@ var HairyPalette = (() => {
185
187
  const ret = { r, g, b, a: Math.round(a * 100) };
186
188
  return typeof fgColor === "string" ? rgbToHex(ret) : ret;
187
189
  }
188
- function changeAlpha(color, offset) {
190
+ function blendAlpha(color, offset) {
189
191
  if (typeof color !== "string") {
190
192
  throw new TypeError("Expected a string as color");
191
193
  }
@@ -201,6 +203,78 @@ var HairyPalette = (() => {
201
203
  a: Math.round(Math.min(1, Math.max(0, alpha + offset)) * 100)
202
204
  });
203
205
  }
206
+ function changeAlpha(color, alpha) {
207
+ if (typeof color !== "string") {
208
+ throw new TypeError("Expected a string as color");
209
+ }
210
+ if (alpha === void 0 || alpha < 0 || alpha > 100) {
211
+ throw new TypeError("Expected alpha to be between 0 and 1");
212
+ }
213
+ const rgba = textToRgb(color);
214
+ rgba.a = alpha;
215
+ return rgbToHex(rgba);
216
+ }
217
+ var hueStep = 2;
218
+ var saturationStep = 16;
219
+ var saturationStep2 = 5;
220
+ var brightnessStep1 = 5;
221
+ var brightnessStep2 = 15;
222
+ var lightColorCount = 5;
223
+ var darkColorCount = 4;
224
+ function colorPalette(color, index) {
225
+ if (typeof color !== "string" && (!color || color.r === void 0)) {
226
+ throw new TypeError("Expected a string or a {r, g, b} object as color");
227
+ }
228
+ const rgb = typeof color === "string" ? textToRgb(color) : color;
229
+ const oldHsv = rgbToHsv(rgb);
230
+ if (index === 6)
231
+ return rgbToHex(rgb);
232
+ const light = index < 6;
233
+ const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1;
234
+ const newHsv = {
235
+ h: hue(oldHsv, i, light),
236
+ s: saturation(oldHsv, i, light),
237
+ v: value(oldHsv, i, light),
238
+ a: oldHsv.a
239
+ };
240
+ return rgbToHex(hsvToRgb(newHsv));
241
+ }
242
+ function hue(hsv, i, isLight) {
243
+ let hue2;
244
+ if (hsv.h >= 60 && hsv.h <= 240) {
245
+ hue2 = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i;
246
+ } else {
247
+ hue2 = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i;
248
+ }
249
+ if (hue2 < 0)
250
+ hue2 += 360;
251
+ else if (hue2 >= 360)
252
+ hue2 -= 360;
253
+ return hue2;
254
+ }
255
+ function saturation(hsv, i, isLight) {
256
+ let saturation2;
257
+ if (isLight)
258
+ saturation2 = hsv.s - saturationStep * i;
259
+ else if (i === darkColorCount)
260
+ saturation2 = hsv.s + saturationStep;
261
+ else
262
+ saturation2 = hsv.s + saturationStep2 * i;
263
+ if (saturation2 > 100)
264
+ saturation2 = 100;
265
+ if (isLight && i === lightColorCount && saturation2 > 10)
266
+ saturation2 = 10;
267
+ if (saturation2 < 6)
268
+ saturation2 = 6;
269
+ return saturation2;
270
+ }
271
+ function value(hsv, i, isLight) {
272
+ let value2;
273
+ value2 = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i;
274
+ if (value2 > 100)
275
+ value2 = 100;
276
+ return value2;
277
+ }
204
278
  return __toCommonJS(util_color_exports);
205
279
  })();
206
280
  //# sourceMappingURL=index.iife.js.map
package/index.iife.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../index.ts"],
4
- "sourcesContent": ["export type RGBA = Record<'r' | 'g' | 'b' | 'a', number>\r\nexport type RGB = Record<'r' | 'g' | 'b', number> & { a?: number }\r\nexport type HEX = string\r\nexport type HSVA = Record<'h' | 's' | 'v' | 'a', number>\r\n\r\nexport type RGBA_TEXT = string\r\nexport type HEX_TEXT = string\r\nexport type HSVA_TEXT = string\r\nexport type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT\r\n\r\nconst reRGBA = /^rgb(a)?\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3}),?([01]?\\.?\\d*?)?\\)$/\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HEX/A representation as a\r\n *\r\n * String (`#RRGGBB<AA>`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHex({ r, g, b, a }: RGBA): HEX {\r\n const alpha = a !== void 0\r\n\r\n r = Math.round(r)\r\n g = Math.round(g)\r\n b = Math.round(b)\r\n\r\n if (r > 255 || g > 255 || b > 255 || (alpha && a > 100)) {\r\n throw new TypeError('Expected 3 numbers below 256 (and optionally one below 100)')\r\n }\r\n\r\n if (alpha) {\r\n a = Number((Math.round((255 * a) / 100) | (1 << 8)).toString(16).slice(1))\r\n }\r\n\r\n return '#' + (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1) + a\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hexToRgb(hex: HEX): RGB {\r\n if (typeof hex !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n hex = hex.replace(/^#/, '')\r\n\r\n if (hex.length === 3) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]\r\n } else if (hex.length === 4) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3]\r\n }\r\n\r\n const num = parseInt(hex, 16)\r\n\r\n return hex.length > 6\r\n ? { r: (num >> 24) & 255, g: (num >> 16) & 255, b: (num >> 8) & 255, a: Math.round((num & 255) / 2.55) }\r\n : { r: num >> 16, g: (num >> 8) & 255, b: num & 255 }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hsvToRgb({ h, s, v, a }: HSVA): RGBA {\r\n let r: any, g: any, b: any\r\n s = s / 100\r\n v = v / 100\r\n\r\n h = h / 360\r\n const i = Math.floor(h * 6),\r\n f = h * 6 - i,\r\n p = v * (1 - s),\r\n q = v * (1 - f * s),\r\n t = v * (1 - (1 - f) * s)\r\n\r\n switch (i % 6) {\r\n case 0:\r\n r = v\r\n g = t\r\n b = p\r\n break\r\n case 1:\r\n r = q\r\n g = v\r\n b = p\r\n break\r\n case 2:\r\n r = p\r\n g = v\r\n b = t\r\n break\r\n case 3:\r\n r = p\r\n g = q\r\n b = v\r\n break\r\n case 4:\r\n r = t\r\n g = p\r\n b = v\r\n break\r\n case 5:\r\n r = v\r\n g = p\r\n b = q\r\n break\r\n }\r\n\r\n return {\r\n r: Math.round(r * 255),\r\n g: Math.round(g * 255),\r\n b: Math.round(b * 255),\r\n a\r\n }\r\n}\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HSV/A representation as an\r\n *\r\n * Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-100]}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHsv({ r, g, b, a }: RGBA): HSVA {\r\n const max = Math.max(r, g, b),\r\n min = Math.min(r, g, b),\r\n d = max - min,\r\n s = max === 0 ? 0 : d / max,\r\n v = max / 255\r\n let h: any\r\n\r\n switch (max) {\r\n case min:\r\n h = 0\r\n break\r\n case r:\r\n h = g - b + d * (g < b ? 6 : 0)\r\n h /= 6 * d\r\n break\r\n case g:\r\n h = b - r + d * 2\r\n h /= 6 * d\r\n break\r\n case b:\r\n h = r - g + d * 4\r\n h /= 6 * d\r\n break\r\n }\r\n\r\n return {\r\n h: Math.round(h * 360),\r\n s: Math.round(s * 100),\r\n v: Math.round(v * 100),\r\n a\r\n }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function textToRgb(str: COLOR): RGB {\r\n if (typeof str !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n const color = str.replace(/ /g, '')\r\n\r\n const m = reRGBA.exec(color)\r\n\r\n if (m === null) {\r\n return hexToRgb(color)\r\n }\r\n\r\n const rgb: RGB = {\r\n r: Math.min(255, parseInt(m[2], 10)),\r\n g: Math.min(255, parseInt(m[3], 10)),\r\n b: Math.min(255, parseInt(m[4], 10))\r\n }\r\n\r\n if (m[1]) {\r\n const alpha = parseFloat(m[5])\r\n rgb.a = Math.min(1, isNaN(alpha) === true ? 1 : alpha) * 100\r\n }\r\n\r\n return rgb\r\n}\r\n\r\n/**\r\n * Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).\r\n *\r\n * Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 100 or -100 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.\r\n */\r\nexport function lighten(color: COLOR, percent: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n if (typeof percent !== 'number') {\r\n throw new TypeError('Expected a numeric percent')\r\n }\r\n\r\n const rgb = textToRgb(color),\r\n t = percent < 0 ? 0 : 255,\r\n p = Math.abs(percent) / 100,\r\n R = rgb.r,\r\n G = rgb.g,\r\n B = rgb.b\r\n\r\n return (\r\n '#' +\r\n (\r\n 0x1_00_00_00 +\r\n (Math.round((t - R) * p) + R) * 0x1_00_00 +\r\n (Math.round((t - G) * p) + G) * 0x1_00 +\r\n (Math.round((t - B) * p) + B)\r\n )\r\n .toString(16)\r\n .slice(1)\r\n )\r\n}\r\n/**\r\n * Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function luminosity(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color,\r\n r = rgb.r / 255,\r\n g = rgb.g / 255,\r\n b = rgb.b / 255,\r\n R = r <= 0.039_28 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4),\r\n G = g <= 0.039_28 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4),\r\n B = b <= 0.039_28 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4)\r\n return 0.2126 * R + 0.7152 * G + 0.0722 * B\r\n}\r\n/**\r\n * Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function brightness(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n\r\n return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000\r\n}\r\n\r\n/**\r\n * Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.\r\n *\r\n * 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.\r\n */\r\nexport function blend(fgColor: COLOR | RGB, bgColor: COLOR | RGB) {\r\n if (typeof fgColor !== 'string' && (!fgColor || fgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as fgColor')\r\n }\r\n\r\n if (typeof bgColor !== 'string' && (!bgColor || bgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as bgColor')\r\n }\r\n\r\n const rgb1 = typeof fgColor === 'string' ? textToRgb(fgColor) : fgColor,\r\n r1 = rgb1.r / 255,\r\n g1 = rgb1.g / 255,\r\n b1 = rgb1.b / 255,\r\n a1 = rgb1.a !== void 0 ? rgb1.a / 100 : 1,\r\n rgb2 = typeof bgColor === 'string' ? textToRgb(bgColor) : bgColor,\r\n r2 = rgb2.r / 255,\r\n g2 = rgb2.g / 255,\r\n b2 = rgb2.b / 255,\r\n a2 = rgb2.a !== void 0 ? rgb2.a / 100 : 1,\r\n a = a1 + a2 * (1 - a1),\r\n r = Math.round(((r1 * a1 + r2 * a2 * (1 - a1)) / a) * 255),\r\n g = Math.round(((g1 * a1 + g2 * a2 * (1 - a1)) / a) * 255),\r\n b = Math.round(((b1 * a1 + b2 * a2 * (1 - a1)) / a) * 255)\r\n\r\n const ret = { r, g, b, a: Math.round(a * 100) }\r\n return typeof fgColor === 'string' ? rgbToHex(ret) : ret\r\n}\r\n\r\n/**\r\n * Increments or decrements the alpha of a string color.\r\n *\r\n * Accepts a HEX/A String as color and a number between -1 and 1 (including edges) as offset. Use a negative value to decrement and a positive number to increment (ex: changeAlpha('#ff0000', -0.1) to decrement alpha by 10%). Returns HEX/A String.\r\n */\r\nexport function changeAlpha(color: COLOR, offset: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n\r\n if (offset === void 0 || offset < -1 || offset > 1) {\r\n throw new TypeError('Expected offset to be between -1 and 1')\r\n }\r\n\r\n const { r, g, b, a } = textToRgb(color)\r\n const alpha = a !== void 0 ? a / 100 : 0\r\n\r\n return rgbToHex({\r\n r,\r\n g,\r\n b,\r\n a: Math.round(Math.min(1, Math.max(0, alpha + offset)) * 100)\r\n })\r\n}\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,MAAM,SAAS;AAaR,oBAAkB,EAAE,GAAG,GAAG,GAAG,KAAgB;AAClD,UAAM,QAAQ,MAAM;AAEpB,QAAI,KAAK,MAAM,CAAC;AAChB,QAAI,KAAK,MAAM,CAAC;AAChB,QAAI,KAAK,MAAM,CAAC;AAEhB,QAAI,IAAI,OAAO,IAAI,OAAO,IAAI,OAAQ,SAAS,IAAI,KAAM;AACvD,YAAM,IAAI,UAAU,6DAA6D;AAAA,IACnF;AAEA,QAAI,OAAO;AACT,UAAI,OAAQ,MAAK,MAAO,MAAM,IAAK,GAAG,IAAK,KAAK,GAAI,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AAAA,IAC3E;AAEA,WAAO,MAAO,KAAK,KAAK,IAAM,KAAK,KAAO,KAAK,IAAK,SAAS,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AAO,IAAK,GAAG;AAE3D,UAAM,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,KAAK,MAAM,IAAI,GAAG,EAAE;AAC9C,WAAO,OAAO,YAAY,WAAW,SAAS,GAAG,IAAI;AAAA,EACvD;AAOO,uBAAqB,OAAc,QAAgB;AACxD,QAAI,OAAO,UAAU,UAAU;AAC7B,YAAM,IAAI,UAAU,4BAA4B;AAAA,IAClD;AAEA,QAAI,WAAW,UAAU,SAAS,MAAM,SAAS,GAAG;AAClD,YAAM,IAAI,UAAU,wCAAwC;AAAA,IAC9D;AAEA,UAAM,EAAE,GAAG,GAAG,GAAG,MAAM,UAAU,KAAK;AACtC,UAAM,QAAQ,MAAM,SAAS,IAAI,MAAM;AAEvC,WAAO,SAAS;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG,KAAK,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,MAAM,CAAC,IAAI,GAAG;AAAA,IAC9D,CAAC;AAAA,EACH;",
4
+ "sourcesContent": ["export type RGBA = Record<'r' | 'g' | 'b' | 'a', number>\r\nexport type RGB = Record<'r' | 'g' | 'b', number> & { a?: number }\r\nexport type HEX = string\r\nexport type HSVA = Record<'h' | 's' | 'v' | 'a', number>\r\n\r\nexport type RGBA_TEXT = string\r\nexport type HEX_TEXT = string\r\nexport type HSVA_TEXT = string\r\nexport type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT\r\nexport type PALETTE_INDEXES = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10\r\n\r\nconst RE_RGBA = /^rgb(a)?\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3}),?([01]?\\.?\\d*?)?\\)$/\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HEX/A representation as a\r\n *\r\n * String (`#RRGGBB<AA>`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHex({ r, g, b, a }: RGB): HEX {\r\n const alpha = a !== void 0\r\n\r\n r = Math.round(r)\r\n g = Math.round(g)\r\n b = Math.round(b)\r\n\r\n if (r > 255 || g > 255 || b > 255 || (alpha && a! > 100)) {\r\n throw new TypeError('Expected 3 numbers below 256 (and optionally one below 100)')\r\n }\r\n\r\n if (alpha) {\r\n a = Number((Math.round((255 * a!) / 100) | (1 << 8)).toString(16).slice(1))\r\n }\r\n\r\n return '#' + (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1) + a\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hexToRgb(hex: HEX): RGB {\r\n if (typeof hex !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n hex = hex.replace(/^#/, '')\r\n\r\n if (hex.length === 3) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]\r\n } else if (hex.length === 4) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3]\r\n }\r\n\r\n const num = parseInt(hex, 16)\r\n\r\n return hex.length > 6\r\n ? { r: (num >> 24) & 255, g: (num >> 16) & 255, b: (num >> 8) & 255, a: Math.round((num & 255) / 2.55) }\r\n : { r: num >> 16, g: (num >> 8) & 255, b: num & 255 }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hsvToRgb({ h, s, v, a }: HSVA): RGBA {\r\n let r: any, g: any, b: any\r\n s = s / 100\r\n v = v / 100\r\n\r\n h = h / 360\r\n const i = Math.floor(h * 6),\r\n f = h * 6 - i,\r\n p = v * (1 - s),\r\n q = v * (1 - f * s),\r\n t = v * (1 - (1 - f) * s)\r\n\r\n switch (i % 6) {\r\n case 0:\r\n r = v\r\n g = t\r\n b = p\r\n break\r\n case 1:\r\n r = q\r\n g = v\r\n b = p\r\n break\r\n case 2:\r\n r = p\r\n g = v\r\n b = t\r\n break\r\n case 3:\r\n r = p\r\n g = q\r\n b = v\r\n break\r\n case 4:\r\n r = t\r\n g = p\r\n b = v\r\n break\r\n case 5:\r\n r = v\r\n g = p\r\n b = q\r\n break\r\n }\r\n\r\n return {\r\n r: Math.round(r * 255),\r\n g: Math.round(g * 255),\r\n b: Math.round(b * 255),\r\n a\r\n }\r\n}\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HSV/A representation as an\r\n *\r\n * Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-100]}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHsv({ r, g, b, a }: RGB): HSVA {\r\n const max = Math.max(r, g, b),\r\n min = Math.min(r, g, b),\r\n d = max - min,\r\n s = max === 0 ? 0 : d / max,\r\n v = max / 255\r\n let h: any\r\n\r\n switch (max) {\r\n case min:\r\n h = 0\r\n break\r\n case r:\r\n h = g - b + d * (g < b ? 6 : 0)\r\n h /= 6 * d\r\n break\r\n case g:\r\n h = b - r + d * 2\r\n h /= 6 * d\r\n break\r\n case b:\r\n h = r - g + d * 4\r\n h /= 6 * d\r\n break\r\n }\r\n\r\n return {\r\n h: Math.round(h * 360),\r\n s: Math.round(s * 100),\r\n v: Math.round(v * 100),\r\n a: a || 1\r\n }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function textToRgb(str: COLOR): RGB {\r\n if (typeof str !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n const color = str.replace(/ /g, '')\r\n\r\n const m = RE_RGBA.exec(color)\r\n\r\n if (m === null) {\r\n return hexToRgb(color)\r\n }\r\n\r\n const rgb: RGB = {\r\n r: Math.min(255, parseInt(m[2], 10)),\r\n g: Math.min(255, parseInt(m[3], 10)),\r\n b: Math.min(255, parseInt(m[4], 10))\r\n }\r\n\r\n if (m[1]) {\r\n const alpha = parseFloat(m[5])\r\n rgb.a = Math.min(1, isNaN(alpha) === true ? 1 : alpha) * 100\r\n }\r\n\r\n return rgb\r\n}\r\n\r\n/**\r\n * Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).\r\n *\r\n * Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 100 or -100 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.\r\n */\r\nexport function lighten(color: COLOR, percent: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n if (typeof percent !== 'number') {\r\n throw new TypeError('Expected a numeric percent')\r\n }\r\n\r\n const rgb = textToRgb(color),\r\n t = percent < 0 ? 0 : 255,\r\n p = Math.abs(percent) / 100,\r\n R = rgb.r,\r\n G = rgb.g,\r\n B = rgb.b\r\n\r\n return (\r\n '#' +\r\n (\r\n 0x1_00_00_00 +\r\n (Math.round((t - R) * p) + R) * 0x1_00_00 +\r\n (Math.round((t - G) * p) + G) * 0x1_00 +\r\n (Math.round((t - B) * p) + B)\r\n )\r\n .toString(16)\r\n .slice(1)\r\n )\r\n}\r\n/**\r\n * Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function luminosity(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color,\r\n r = rgb.r / 255,\r\n g = rgb.g / 255,\r\n b = rgb.b / 255,\r\n R = r <= 0.039_28 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4),\r\n G = g <= 0.039_28 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4),\r\n B = b <= 0.039_28 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4)\r\n return 0.2126 * R + 0.7152 * G + 0.0722 * B\r\n}\r\n/**\r\n * Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function brightness(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n\r\n return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000\r\n}\r\n\r\n/**\r\n * Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.\r\n *\r\n * 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.\r\n */\r\nexport function blend(fgColor: COLOR | RGB, bgColor: COLOR | RGB) {\r\n if (typeof fgColor !== 'string' && (!fgColor || fgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as fgColor')\r\n }\r\n\r\n if (typeof bgColor !== 'string' && (!bgColor || bgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as bgColor')\r\n }\r\n\r\n const rgb1 = typeof fgColor === 'string' ? textToRgb(fgColor) : fgColor,\r\n r1 = rgb1.r / 255,\r\n g1 = rgb1.g / 255,\r\n b1 = rgb1.b / 255,\r\n a1 = rgb1.a !== void 0 ? rgb1.a / 100 : 1,\r\n rgb2 = typeof bgColor === 'string' ? textToRgb(bgColor) : bgColor,\r\n r2 = rgb2.r / 255,\r\n g2 = rgb2.g / 255,\r\n b2 = rgb2.b / 255,\r\n a2 = rgb2.a !== void 0 ? rgb2.a / 100 : 1,\r\n a = a1 + a2 * (1 - a1),\r\n r = Math.round(((r1 * a1 + r2 * a2 * (1 - a1)) / a) * 255),\r\n g = Math.round(((g1 * a1 + g2 * a2 * (1 - a1)) / a) * 255),\r\n b = Math.round(((b1 * a1 + b2 * a2 * (1 - a1)) / a) * 255)\r\n\r\n const ret = { r, g, b, a: Math.round(a * 100) }\r\n return typeof fgColor === 'string' ? rgbToHex(ret) : ret\r\n}\r\n\r\n/**\r\n * Increments or decrements the alpha of a string color.\r\n *\r\n * Accepts a HEX/A String as color and a number between -1 and 1 (including edges) as offset. Use a negative value to decrement and a positive number to increment (ex: blendAlpha('#ff0000', -0.1) to decrement alpha by 10%). Returns HEX/A String.\r\n */\r\nexport function blendAlpha(color: COLOR, offset: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n\r\n if (offset === void 0 || offset < -1 || offset > 1) {\r\n throw new TypeError('Expected offset to be between -1 and 1')\r\n }\r\n\r\n const { r, g, b, a } = textToRgb(color)\r\n const alpha = a !== void 0 ? a / 100 : 0\r\n\r\n return rgbToHex({\r\n r,\r\n g,\r\n b,\r\n a: Math.round(Math.min(1, Math.max(0, alpha + offset)) * 100)\r\n })\r\n}\r\n\r\n/**\r\n * Change color transparency\r\n */\r\nexport function changeAlpha(color: COLOR, alpha: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n if (alpha === void 0 || alpha < 0 || alpha > 100) {\r\n throw new TypeError('Expected alpha to be between 0 and 1')\r\n }\r\n const rgba = textToRgb(color)\r\n rgba.a = alpha\r\n\r\n return rgbToHex(rgba)\r\n}\r\n\r\nconst hueStep = 2\r\nconst saturationStep = 16\r\nconst saturationStep2 = 5\r\nconst brightnessStep1 = 5\r\nconst brightnessStep2 = 15\r\nconst lightColorCount = 5\r\nconst darkColorCount = 4\r\n\r\n/**\r\n * \u6839\u636E\u989C\u8272\u83B7\u53D6\u8C03\u8272\u677F\u989C\u8272(\u4ECE\u5DE6\u81F3\u53F3\u989C\u8272\u4ECE\u6D45\u5230\u6DF1\uFF0C6\u4E3A\u4E3B\u8272\u53F7)\r\n * @param color - \u989C\u8272\r\n * @param index - \u8C03\u8272\u677F\u7684\u5BF9\u5E94\u7684\u8272\u53F7(6\u4E3A\u4E3B\u8272\u53F7)\r\n * @description \u7B97\u6CD5\u5B9E\u73B0\u4ECEant-design\u8C03\u8272\u677F\u7B97\u6CD5\u4E2D\u501F\u9274 https://github.com/ant-design/ant-design/blob/master/components/style/color/colorPalette.less\r\n */\r\nexport function colorPalette(color: COLOR | RGB, index: PALETTE_INDEXES) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n const oldHsv = rgbToHsv(rgb)\r\n\r\n if (index === 6) return rgbToHex(rgb)\r\n\r\n const light = index < 6\r\n const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1\r\n const newHsv: HSVA = {\r\n h: hue(oldHsv, i, light),\r\n s: saturation(oldHsv, i, light),\r\n v: value(oldHsv, i, light),\r\n a: oldHsv.a\r\n }\r\n\r\n return rgbToHex(hsvToRgb(newHsv))\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u8272\u76F8\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction hue(hsv: HSVA, i: number, isLight: boolean) {\r\n let hue: number\r\n if (hsv.h >= 60 && hsv.h <= 240) {\r\n // \u51B7\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i\r\n } else {\r\n // \u6696\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i\r\n }\r\n if (hue < 0) hue += 360\r\n else if (hue >= 360) hue -= 360\r\n\r\n return hue\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u9971\u548C\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction saturation(hsv: HSVA, i: number, isLight: boolean) {\r\n let saturation: number\r\n if (isLight) saturation = hsv.s - saturationStep * i\r\n else if (i === darkColorCount) saturation = hsv.s + saturationStep\r\n else saturation = hsv.s + saturationStep2 * i\r\n\r\n if (saturation > 100) saturation = 100\r\n\r\n if (isLight && i === lightColorCount && saturation > 10) saturation = 10\r\n\r\n if (saturation < 6) saturation = 6\r\n\r\n return saturation\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u660E\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction value(hsv: HSVA, i: number, isLight: boolean) {\r\n let value: number\r\n value = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i\r\n\r\n if (value > 100) value = 100\r\n\r\n return value\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,MAAM,UAAU;AAaT,oBAAkB,EAAE,GAAG,GAAG,GAAG,KAAe;AACjD,UAAM,QAAQ,MAAM;AAEpB,QAAI,KAAK,MAAM,CAAC;AAChB,QAAI,KAAK,MAAM,CAAC;AAChB,QAAI,KAAK,MAAM,CAAC;AAEhB,QAAI,IAAI,OAAO,IAAI,OAAO,IAAI,OAAQ,SAAS,IAAK,KAAM;AACxD,YAAM,IAAI,UAAU,6DAA6D;AAAA,IACnF;AAEA,QAAI,OAAO;AACT,UAAI,OAAQ,MAAK,MAAO,MAAM,IAAM,GAAG,IAAK,KAAK,GAAI,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AAAA,IAC5E;AAEA,WAAO,MAAO,KAAK,KAAK,IAAM,KAAK,KAAO,KAAK,IAAK,SAAS,EAAE,EAAE,MAAM,CAAC,IAAI;AAAA,EAC9E;AAaO,oBAAkB,KAAe;AACtC,QAAI,OAAO,QAAQ,UAAU;AAC3B,YAAM,IAAI,UAAU,mBAAmB;AAAA,IACzC;AAEA,UAAM,IAAI,QAAQ,MAAM,EAAE;AAE1B,QAAI,IAA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AAM,SAAe;AAAA,MACnB,GAAG,IAAI,QAAQ,GAAG,KAAK;AAAA,MACvB,GAAG,WAAW,QAAQ,GAAG,KAAK;AAAA,MAC9B,GAAG,MAAM,QAAQ,GAAG,KAAK;AAAA,MACzB,GAAG,OAAO;AAAA,IACZ;AAEA,WAAO,SAAS,SAAS,MAAM,CAAC;AAAA,EAClC;AAQA,eAAa,KAAW,GAAW,SAAkB;AACnD,QAAI;AACJ,QAAI,IAAI,KAAK,MAAM,IAAI,KAAK,KAAK;AAI/B,aAAM,UAAU,IAAI,IAAI,UAAU,IAAI,IAAI,IAAI,UAAU;AAAA,IAC1D,OAAO;AAIL,aAAM,UAAU,IAAI,IAAI,UAAU,IAAI,IAAI,IAAI,UAAU;AAAA,IAC1D;AACA,QAAI,OAAM;AAAG,cAAO;AAAA,aACX,QAAO;AAAK,cAAO;AAE5B,WAAO;AAAA,EACT;AAQA,sBAAoB,KAAW,GAAW,SAAkB;AAC1D,QAAI;AACJ,QAAI;AAAS,oBAAa,IAAI,IAAI,iBAAiB;AAAA,aAC1C,MAAM;AAAgB,oBAAa,IAAI,IAAI;AAAA;AAC/C,oBAAa,IAAI,IAAI,kBAAkB;AAE5C,QAAI,cAAa;AAAK,oBAAa;AAEnC,QAAI,WAAW,MAAM,mBAAmB,cAAa;AAAI,oBAAa;AAEtE,QAAI,cAAa;AAAG,oBAAa;AAEjC,WAAO;AAAA,EACT;AAQA,iBAAe,KAAW,GAAW,SAAkB;AACrD,QAAI;AACJ,aAAQ,UAAU,IAAI,IAAI,kBAAkB,IAAI,IAAI,IAAI,kBAAkB;AAE1E,QAAI,SAAQ;AAAK,eAAQ;AAEzB,WAAO;AAAA,EACT;",
6
6
  "names": []
7
7
  }
package/index.iife.min.js CHANGED
@@ -1,2 +1,2 @@
1
- var HairyPalette=(()=>{var y=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var B=(t,r)=>{for(var e in r)y(t,e,{get:r[e],enumerable:!0})},G=(t,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of m(r))!x.call(t,n)&&n!==e&&y(t,n,{get:()=>r[n],enumerable:!(o=T(r,n))||o.enumerable});return t};var O=t=>G(y({},"__esModule",{value:!0}),t);var V={};B(V,{blend:()=>L,brightness:()=>l,changeAlpha:()=>S,hexToRgb:()=>E,hsvToRgb:()=>A,lighten:()=>X,luminosity:()=>k,rgbToHex:()=>h,rgbToHsv:()=>H,textToRgb:()=>u});var _=/^rgb(a)?\((\d{1,3}),(\d{1,3}),(\d{1,3}),?([01]?\.?\d*?)?\)$/;function h({r:t,g:r,b:e,a:o}){let n=o!==void 0;if(t=Math.round(t),r=Math.round(r),e=Math.round(e),t>255||r>255||e>255||n&&o>100)throw new TypeError("Expected 3 numbers below 256 (and optionally one below 100)");return n&&(o=Number((Math.round(255*o/100)|1<<8).toString(16).slice(1))),"#"+(e|r<<8|t<<16|1<<24).toString(16).slice(1)+o}function E(t){if(typeof t!="string")throw new TypeError("Expected a string");t=t.replace(/^#/,""),t.length===3?t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]:t.length===4&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]);let r=parseInt(t,16);return t.length>6?{r:r>>24&255,g:r>>16&255,b:r>>8&255,a:Math.round((r&255)/2.55)}:{r:r>>16,g:r>>8&255,b:r&255}}function A({h:t,s:r,v:e,a:o}){let n,i,a;r=r/100,e=e/100,t=t/360;let s=Math.floor(t*6),b=t*6-s,p=e*(1-r),g=e*(1-b*r),c=e*(1-(1-b)*r);switch(s%6){case 0:n=e,i=c,a=p;break;case 1:n=g,i=e,a=p;break;case 2:n=p,i=e,a=c;break;case 3:n=p,i=g,a=e;break;case 4:n=c,i=p,a=e;break;case 5:n=e,i=p,a=g;break}return{r:Math.round(n*255),g:Math.round(i*255),b:Math.round(a*255),a:o}}function H({r:t,g:r,b:e,a:o}){let n=Math.max(t,r,e),i=Math.min(t,r,e),a=n-i,s=n===0?0:a/n,b=n/255,p;switch(n){case i:p=0;break;case t:p=r-e+a*(r<e?6:0),p/=6*a;break;case r:p=e-t+a*2,p/=6*a;break;case e:p=t-r+a*4,p/=6*a;break}return{h:Math.round(p*360),s:Math.round(s*100),v:Math.round(b*100),a:o}}function u(t){if(typeof t!="string")throw new TypeError("Expected a string");let r=t.replace(/ /g,""),e=_.exec(r);if(e===null)return E(r);let o={r:Math.min(255,parseInt(e[2],10)),g:Math.min(255,parseInt(e[3],10)),b:Math.min(255,parseInt(e[4],10))};if(e[1]){let n=parseFloat(e[5]);o.a=Math.min(1,isNaN(n)===!0?1:n)*100}return o}function X(t,r){if(typeof t!="string")throw new TypeError("Expected a string as color");if(typeof r!="number")throw new TypeError("Expected a numeric percent");let e=u(t),o=r<0?0:255,n=Math.abs(r)/100,i=e.r,a=e.g,s=e.b;return"#"+(16777216+(Math.round((o-i)*n)+i)*65536+(Math.round((o-a)*n)+a)*256+(Math.round((o-s)*n)+s)).toString(16).slice(1)}function k(t){if(typeof t!="string"&&(!t||t.r===void 0))throw new TypeError("Expected a string or a {r, g, b} object as color");let r=typeof t=="string"?u(t):t,e=r.r/255,o=r.g/255,n=r.b/255,i=e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4),a=o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4),s=n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4);return .2126*i+.7152*a+.0722*s}function l(t){if(typeof t!="string"&&(!t||t.r===void 0))throw new TypeError("Expected a string or a {r, g, b} object as color");let r=typeof t=="string"?u(t):t;return(r.r*299+r.g*587+r.b*114)/1e3}function L(t,r){if(typeof t!="string"&&(!t||t.r===void 0))throw new TypeError("Expected a string or a {r, g, b[, a]} object as fgColor");if(typeof r!="string"&&(!r||r.r===void 0))throw new TypeError("Expected a string or a {r, g, b[, a]} object as bgColor");let e=typeof t=="string"?u(t):t,o=e.r/255,n=e.g/255,i=e.b/255,a=e.a!==void 0?e.a/100:1,s=typeof r=="string"?u(r):r,b=s.r/255,p=s.g/255,g=s.b/255,c=s.a!==void 0?s.a/100:1,d=a+c*(1-a),M=Math.round((o*a+b*c*(1-a))/d*255),R=Math.round((n*a+p*c*(1-a))/d*255),w=Math.round((i*a+g*c*(1-a))/d*255),f={r:M,g:R,b:w,a:Math.round(d*100)};return typeof t=="string"?h(f):f}function S(t,r){if(typeof t!="string")throw new TypeError("Expected a string as color");if(r===void 0||r<-1||r>1)throw new TypeError("Expected offset to be between -1 and 1");let{r:e,g:o,b:n,a:i}=u(t),a=i!==void 0?i/100:0;return h({r:e,g:o,b:n,a:Math.round(Math.min(1,Math.max(0,a+r))*100)})}return O(V);})();
1
+ var HairyPalette=(()=>{var y=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var G=(t,r)=>{for(var e in r)y(t,e,{get:r[e],enumerable:!0})},H=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of A(r))!B.call(t,o)&&o!==e&&y(t,o,{get:()=>r[o],enumerable:!(n=S(r,o))||n.enumerable});return t};var _=t=>H(y({},"__esModule",{value:!0}),t);var J={};G(J,{blend:()=>I,blendAlpha:()=>j,brightness:()=>V,changeAlpha:()=>v,colorPalette:()=>q,hexToRgb:()=>T,hsvToRgb:()=>M,lighten:()=>k,luminosity:()=>L,rgbToHex:()=>g,rgbToHsv:()=>m,textToRgb:()=>u});var X=/^rgb(a)?\((\d{1,3}),(\d{1,3}),(\d{1,3}),?([01]?\.?\d*?)?\)$/;function g({r:t,g:r,b:e,a:n}){let o=n!==void 0;if(t=Math.round(t),r=Math.round(r),e=Math.round(e),t>255||r>255||e>255||o&&n>100)throw new TypeError("Expected 3 numbers below 256 (and optionally one below 100)");return o&&(n=Number((Math.round(255*n/100)|1<<8).toString(16).slice(1))),"#"+(e|r<<8|t<<16|1<<24).toString(16).slice(1)+n}function T(t){if(typeof t!="string")throw new TypeError("Expected a string");t=t.replace(/^#/,""),t.length===3?t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]:t.length===4&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]);let r=parseInt(t,16);return t.length>6?{r:r>>24&255,g:r>>16&255,b:r>>8&255,a:Math.round((r&255)/2.55)}:{r:r>>16,g:r>>8&255,b:r&255}}function M({h:t,s:r,v:e,a:n}){let o,i,a;r=r/100,e=e/100,t=t/360;let p=Math.floor(t*6),b=t*6-p,s=e*(1-r),d=e*(1-b*r),c=e*(1-(1-b)*r);switch(p%6){case 0:o=e,i=c,a=s;break;case 1:o=d,i=e,a=s;break;case 2:o=s,i=e,a=c;break;case 3:o=s,i=d,a=e;break;case 4:o=c,i=s,a=e;break;case 5:o=e,i=s,a=d;break}return{r:Math.round(o*255),g:Math.round(i*255),b:Math.round(a*255),a:n}}function m({r:t,g:r,b:e,a:n}){let o=Math.max(t,r,e),i=Math.min(t,r,e),a=o-i,p=o===0?0:a/o,b=o/255,s;switch(o){case i:s=0;break;case t:s=r-e+a*(r<e?6:0),s/=6*a;break;case r:s=e-t+a*2,s/=6*a;break;case e:s=t-r+a*4,s/=6*a;break}return{h:Math.round(s*360),s:Math.round(p*100),v:Math.round(b*100),a:n||1}}function u(t){if(typeof t!="string")throw new TypeError("Expected a string");let r=t.replace(/ /g,""),e=X.exec(r);if(e===null)return T(r);let n={r:Math.min(255,parseInt(e[2],10)),g:Math.min(255,parseInt(e[3],10)),b:Math.min(255,parseInt(e[4],10))};if(e[1]){let o=parseFloat(e[5]);n.a=Math.min(1,isNaN(o)===!0?1:o)*100}return n}function k(t,r){if(typeof t!="string")throw new TypeError("Expected a string as color");if(typeof r!="number")throw new TypeError("Expected a numeric percent");let e=u(t),n=r<0?0:255,o=Math.abs(r)/100,i=e.r,a=e.g,p=e.b;return"#"+(16777216+(Math.round((n-i)*o)+i)*65536+(Math.round((n-a)*o)+a)*256+(Math.round((n-p)*o)+p)).toString(16).slice(1)}function L(t){if(typeof t!="string"&&(!t||t.r===void 0))throw new TypeError("Expected a string or a {r, g, b} object as color");let r=typeof t=="string"?u(t):t,e=r.r/255,n=r.g/255,o=r.b/255,i=e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4),a=n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4),p=o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4);return .2126*i+.7152*a+.0722*p}function V(t){if(typeof t!="string"&&(!t||t.r===void 0))throw new TypeError("Expected a string or a {r, g, b} object as color");let r=typeof t=="string"?u(t):t;return(r.r*299+r.g*587+r.b*114)/1e3}function I(t,r){if(typeof t!="string"&&(!t||t.r===void 0))throw new TypeError("Expected a string or a {r, g, b[, a]} object as fgColor");if(typeof r!="string"&&(!r||r.r===void 0))throw new TypeError("Expected a string or a {r, g, b[, a]} object as bgColor");let e=typeof t=="string"?u(t):t,n=e.r/255,o=e.g/255,i=e.b/255,a=e.a!==void 0?e.a/100:1,p=typeof r=="string"?u(r):r,b=p.r/255,s=p.g/255,d=p.b/255,c=p.a!==void 0?p.a/100:1,f=a+c*(1-a),l=Math.round((n*a+b*c*(1-a))/f*255),x=Math.round((o*a+s*c*(1-a))/f*255),O=Math.round((i*a+d*c*(1-a))/f*255),w={r:l,g:x,b:O,a:Math.round(f*100)};return typeof t=="string"?g(w):w}function j(t,r){if(typeof t!="string")throw new TypeError("Expected a string as color");if(r===void 0||r<-1||r>1)throw new TypeError("Expected offset to be between -1 and 1");let{r:e,g:n,b:o,a:i}=u(t),a=i!==void 0?i/100:0;return g({r:e,g:n,b:o,a:Math.round(Math.min(1,Math.max(0,a+r))*100)})}function v(t,r){if(typeof t!="string")throw new TypeError("Expected a string as color");if(r===void 0||r<0||r>100)throw new TypeError("Expected alpha to be between 0 and 1");let e=u(t);return e.a=r,g(e)}var E=2,R=16,C=5,N=5,P=15,h=5,D=4;function q(t,r){if(typeof t!="string"&&(!t||t.r===void 0))throw new TypeError("Expected a string or a {r, g, b} object as color");let e=typeof t=="string"?u(t):t,n=m(e);if(r===6)return g(e);let o=r<6,i=o?h+1-r:r-h-1,a={h:F(n,i,o),s:$(n,i,o),v:z(n,i,o),a:n.a};return g(M(a))}function F(t,r,e){let n;return t.h>=60&&t.h<=240?n=e?t.h-E*r:t.h+E*r:n=e?t.h+E*r:t.h-E*r,n<0?n+=360:n>=360&&(n-=360),n}function $(t,r,e){let n;return e?n=t.s-R*r:r===D?n=t.s+R:n=t.s+C*r,n>100&&(n=100),e&&r===h&&n>10&&(n=10),n<6&&(n=6),n}function z(t,r,e){let n;return n=e?t.v+N*r:t.v-P*r,n>100&&(n=100),n}return _(J);})();
2
2
  //# sourceMappingURL=index.iife.min.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../index.ts"],
4
- "sourcesContent": ["export type RGBA = Record<'r' | 'g' | 'b' | 'a', number>\r\nexport type RGB = Record<'r' | 'g' | 'b', number> & { a?: number }\r\nexport type HEX = string\r\nexport type HSVA = Record<'h' | 's' | 'v' | 'a', number>\r\n\r\nexport type RGBA_TEXT = string\r\nexport type HEX_TEXT = string\r\nexport type HSVA_TEXT = string\r\nexport type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT\r\n\r\nconst reRGBA = /^rgb(a)?\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3}),?([01]?\\.?\\d*?)?\\)$/\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HEX/A representation as a\r\n *\r\n * String (`#RRGGBB<AA>`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHex({ r, g, b, a }: RGBA): HEX {\r\n const alpha = a !== void 0\r\n\r\n r = Math.round(r)\r\n g = Math.round(g)\r\n b = Math.round(b)\r\n\r\n if (r > 255 || g > 255 || b > 255 || (alpha && a > 100)) {\r\n throw new TypeError('Expected 3 numbers below 256 (and optionally one below 100)')\r\n }\r\n\r\n if (alpha) {\r\n a = Number((Math.round((255 * a) / 100) | (1 << 8)).toString(16).slice(1))\r\n }\r\n\r\n return '#' + (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1) + a\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hexToRgb(hex: HEX): RGB {\r\n if (typeof hex !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n hex = hex.replace(/^#/, '')\r\n\r\n if (hex.length === 3) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]\r\n } else if (hex.length === 4) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3]\r\n }\r\n\r\n const num = parseInt(hex, 16)\r\n\r\n return hex.length > 6\r\n ? { r: (num >> 24) & 255, g: (num >> 16) & 255, b: (num >> 8) & 255, a: Math.round((num & 255) / 2.55) }\r\n : { r: num >> 16, g: (num >> 8) & 255, b: num & 255 }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hsvToRgb({ h, s, v, a }: HSVA): RGBA {\r\n let r: any, g: any, b: any\r\n s = s / 100\r\n v = v / 100\r\n\r\n h = h / 360\r\n const i = Math.floor(h * 6),\r\n f = h * 6 - i,\r\n p = v * (1 - s),\r\n q = v * (1 - f * s),\r\n t = v * (1 - (1 - f) * s)\r\n\r\n switch (i % 6) {\r\n case 0:\r\n r = v\r\n g = t\r\n b = p\r\n break\r\n case 1:\r\n r = q\r\n g = v\r\n b = p\r\n break\r\n case 2:\r\n r = p\r\n g = v\r\n b = t\r\n break\r\n case 3:\r\n r = p\r\n g = q\r\n b = v\r\n break\r\n case 4:\r\n r = t\r\n g = p\r\n b = v\r\n break\r\n case 5:\r\n r = v\r\n g = p\r\n b = q\r\n break\r\n }\r\n\r\n return {\r\n r: Math.round(r * 255),\r\n g: Math.round(g * 255),\r\n b: Math.round(b * 255),\r\n a\r\n }\r\n}\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HSV/A representation as an\r\n *\r\n * Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-100]}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHsv({ r, g, b, a }: RGBA): HSVA {\r\n const max = Math.max(r, g, b),\r\n min = Math.min(r, g, b),\r\n d = max - min,\r\n s = max === 0 ? 0 : d / max,\r\n v = max / 255\r\n let h: any\r\n\r\n switch (max) {\r\n case min:\r\n h = 0\r\n break\r\n case r:\r\n h = g - b + d * (g < b ? 6 : 0)\r\n h /= 6 * d\r\n break\r\n case g:\r\n h = b - r + d * 2\r\n h /= 6 * d\r\n break\r\n case b:\r\n h = r - g + d * 4\r\n h /= 6 * d\r\n break\r\n }\r\n\r\n return {\r\n h: Math.round(h * 360),\r\n s: Math.round(s * 100),\r\n v: Math.round(v * 100),\r\n a\r\n }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function textToRgb(str: COLOR): RGB {\r\n if (typeof str !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n const color = str.replace(/ /g, '')\r\n\r\n const m = reRGBA.exec(color)\r\n\r\n if (m === null) {\r\n return hexToRgb(color)\r\n }\r\n\r\n const rgb: RGB = {\r\n r: Math.min(255, parseInt(m[2], 10)),\r\n g: Math.min(255, parseInt(m[3], 10)),\r\n b: Math.min(255, parseInt(m[4], 10))\r\n }\r\n\r\n if (m[1]) {\r\n const alpha = parseFloat(m[5])\r\n rgb.a = Math.min(1, isNaN(alpha) === true ? 1 : alpha) * 100\r\n }\r\n\r\n return rgb\r\n}\r\n\r\n/**\r\n * Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).\r\n *\r\n * Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 100 or -100 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.\r\n */\r\nexport function lighten(color: COLOR, percent: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n if (typeof percent !== 'number') {\r\n throw new TypeError('Expected a numeric percent')\r\n }\r\n\r\n const rgb = textToRgb(color),\r\n t = percent < 0 ? 0 : 255,\r\n p = Math.abs(percent) / 100,\r\n R = rgb.r,\r\n G = rgb.g,\r\n B = rgb.b\r\n\r\n return (\r\n '#' +\r\n (\r\n 0x1_00_00_00 +\r\n (Math.round((t - R) * p) + R) * 0x1_00_00 +\r\n (Math.round((t - G) * p) + G) * 0x1_00 +\r\n (Math.round((t - B) * p) + B)\r\n )\r\n .toString(16)\r\n .slice(1)\r\n )\r\n}\r\n/**\r\n * Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function luminosity(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color,\r\n r = rgb.r / 255,\r\n g = rgb.g / 255,\r\n b = rgb.b / 255,\r\n R = r <= 0.039_28 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4),\r\n G = g <= 0.039_28 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4),\r\n B = b <= 0.039_28 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4)\r\n return 0.2126 * R + 0.7152 * G + 0.0722 * B\r\n}\r\n/**\r\n * Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function brightness(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n\r\n return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000\r\n}\r\n\r\n/**\r\n * Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.\r\n *\r\n * 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.\r\n */\r\nexport function blend(fgColor: COLOR | RGB, bgColor: COLOR | RGB) {\r\n if (typeof fgColor !== 'string' && (!fgColor || fgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as fgColor')\r\n }\r\n\r\n if (typeof bgColor !== 'string' && (!bgColor || bgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as bgColor')\r\n }\r\n\r\n const rgb1 = typeof fgColor === 'string' ? textToRgb(fgColor) : fgColor,\r\n r1 = rgb1.r / 255,\r\n g1 = rgb1.g / 255,\r\n b1 = rgb1.b / 255,\r\n a1 = rgb1.a !== void 0 ? rgb1.a / 100 : 1,\r\n rgb2 = typeof bgColor === 'string' ? textToRgb(bgColor) : bgColor,\r\n r2 = rgb2.r / 255,\r\n g2 = rgb2.g / 255,\r\n b2 = rgb2.b / 255,\r\n a2 = rgb2.a !== void 0 ? rgb2.a / 100 : 1,\r\n a = a1 + a2 * (1 - a1),\r\n r = Math.round(((r1 * a1 + r2 * a2 * (1 - a1)) / a) * 255),\r\n g = Math.round(((g1 * a1 + g2 * a2 * (1 - a1)) / a) * 255),\r\n b = Math.round(((b1 * a1 + b2 * a2 * (1 - a1)) / a) * 255)\r\n\r\n const ret = { r, g, b, a: Math.round(a * 100) }\r\n return typeof fgColor === 'string' ? rgbToHex(ret) : ret\r\n}\r\n\r\n/**\r\n * Increments or decrements the alpha of a string color.\r\n *\r\n * Accepts a HEX/A String as color and a number between -1 and 1 (including edges) as offset. Use a negative value to decrement and a positive number to increment (ex: changeAlpha('#ff0000', -0.1) to decrement alpha by 10%). Returns HEX/A String.\r\n */\r\nexport function changeAlpha(color: COLOR, offset: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n\r\n if (offset === void 0 || offset < -1 || offset > 1) {\r\n throw new TypeError('Expected offset to be between -1 and 1')\r\n }\r\n\r\n const { r, g, b, a } = textToRgb(color)\r\n const alpha = a !== void 0 ? a / 100 : 0\r\n\r\n return rgbToHex({\r\n r,\r\n g,\r\n b,\r\n a: Math.round(Math.min(1, Math.max(0, alpha + offset)) * 100)\r\n })\r\n}\r\n"],
5
- "mappings": "mbAAA,0KAUA,GAAM,GAAS,8DAaR,WAAkB,CAAE,IAAG,IAAG,IAAG,KAAgB,CAClD,GAAM,GAAQ,IAAM,OAMpB,GAJA,EAAI,KAAK,MAAM,CAAC,EAChB,EAAI,KAAK,MAAM,CAAC,EAChB,EAAI,KAAK,MAAM,CAAC,EAEZ,EAAI,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D,GAAI,MAAO,IAAU,SACnB,KAAM,IAAI,WAAU,4BAA4B,EAGlD,GAAI,IAAW,QAAU,EAAS,IAAM,EAAS,EAC/C,KAAM,IAAI,WAAU,wCAAwC,EAG9D,GAAM,CAAE,IAAG,IAAG,IAAG,KAAM,EAAU,CAAK,EAChC,EAAQ,IAAM,OAAS,EAAI,IAAM,EAEvC,MAAO,GAAS,CACd,IACA,IACA,IACA,EAAG,KAAK,MAAM,KAAK,IAAI,EAAG,KAAK,IAAI,EAAG,EAAQ,CAAM,CAAC,EAAI,GAAG,CAC9D,CAAC,CACH",
4
+ "sourcesContent": ["export type RGBA = Record<'r' | 'g' | 'b' | 'a', number>\r\nexport type RGB = Record<'r' | 'g' | 'b', number> & { a?: number }\r\nexport type HEX = string\r\nexport type HSVA = Record<'h' | 's' | 'v' | 'a', number>\r\n\r\nexport type RGBA_TEXT = string\r\nexport type HEX_TEXT = string\r\nexport type HSVA_TEXT = string\r\nexport type COLOR = RGBA_TEXT | HEX_TEXT | HSVA_TEXT\r\nexport type PALETTE_INDEXES = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10\r\n\r\nconst RE_RGBA = /^rgb(a)?\\((\\d{1,3}),(\\d{1,3}),(\\d{1,3}),?([01]?\\.?\\d*?)?\\)$/\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HEX/A representation as a\r\n *\r\n * String (`#RRGGBB<AA>`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHex({ r, g, b, a }: RGB): HEX {\r\n const alpha = a !== void 0\r\n\r\n r = Math.round(r)\r\n g = Math.round(g)\r\n b = Math.round(b)\r\n\r\n if (r > 255 || g > 255 || b > 255 || (alpha && a! > 100)) {\r\n throw new TypeError('Expected 3 numbers below 256 (and optionally one below 100)')\r\n }\r\n\r\n if (alpha) {\r\n a = Number((Math.round((255 * a!) / 100) | (1 << 8)).toString(16).slice(1))\r\n }\r\n\r\n return '#' + (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1) + a\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hexToRgb(hex: HEX): RGB {\r\n if (typeof hex !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n hex = hex.replace(/^#/, '')\r\n\r\n if (hex.length === 3) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]\r\n } else if (hex.length === 4) {\r\n hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3]\r\n }\r\n\r\n const num = parseInt(hex, 16)\r\n\r\n return hex.length > 6\r\n ? { r: (num >> 24) & 255, g: (num >> 16) & 255, b: (num >> 8) & 255, a: Math.round((num & 255) / 2.55) }\r\n : { r: num >> 16, g: (num >> 8) & 255, b: num & 255 }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`) .\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function hsvToRgb({ h, s, v, a }: HSVA): RGBA {\r\n let r: any, g: any, b: any\r\n s = s / 100\r\n v = v / 100\r\n\r\n h = h / 360\r\n const i = Math.floor(h * 6),\r\n f = h * 6 - i,\r\n p = v * (1 - s),\r\n q = v * (1 - f * s),\r\n t = v * (1 - (1 - f) * s)\r\n\r\n switch (i % 6) {\r\n case 0:\r\n r = v\r\n g = t\r\n b = p\r\n break\r\n case 1:\r\n r = q\r\n g = v\r\n b = p\r\n break\r\n case 2:\r\n r = p\r\n g = v\r\n b = t\r\n break\r\n case 3:\r\n r = p\r\n g = q\r\n b = v\r\n break\r\n case 4:\r\n r = t\r\n g = p\r\n b = v\r\n break\r\n case 5:\r\n r = v\r\n g = p\r\n b = q\r\n break\r\n }\r\n\r\n return {\r\n r: Math.round(r * 255),\r\n g: Math.round(g * 255),\r\n b: Math.round(b * 255),\r\n a\r\n }\r\n}\r\n\r\n/**\r\n * Converts a RGB/A color\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`)\r\n *\r\n * to its HSV/A representation as an\r\n *\r\n * Object (`{ h: [0-360], s: [0-100], v: [0-100}, a: [0-100]}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function rgbToHsv({ r, g, b, a }: RGB): HSVA {\r\n const max = Math.max(r, g, b),\r\n min = Math.min(r, g, b),\r\n d = max - min,\r\n s = max === 0 ? 0 : d / max,\r\n v = max / 255\r\n let h: any\r\n\r\n switch (max) {\r\n case min:\r\n h = 0\r\n break\r\n case r:\r\n h = g - b + d * (g < b ? 6 : 0)\r\n h /= 6 * d\r\n break\r\n case g:\r\n h = b - r + d * 2\r\n h /= 6 * d\r\n break\r\n case b:\r\n h = r - g + d * 4\r\n h /= 6 * d\r\n break\r\n }\r\n\r\n return {\r\n h: Math.round(h * 360),\r\n s: Math.round(s * 100),\r\n v: Math.round(v * 100),\r\n a: a || 1\r\n }\r\n}\r\n\r\n/**\r\n * Converts a HEX/A color\r\n *\r\n * String (`#RRGGBB<AA>`) or a RGB/A color String(`rgb(R, G, B<, A>)`)\r\n *\r\n * to its RGB/A representation as an\r\n *\r\n * Object (`{ r: [0-255], g: [0-255], b: [0-255}<, a: [0-100]>}`).\r\n *\r\n * If Alpha channel is present in the original object it will be present also in the output.\r\n */\r\nexport function textToRgb(str: COLOR): RGB {\r\n if (typeof str !== 'string') {\r\n throw new TypeError('Expected a string')\r\n }\r\n\r\n const color = str.replace(/ /g, '')\r\n\r\n const m = RE_RGBA.exec(color)\r\n\r\n if (m === null) {\r\n return hexToRgb(color)\r\n }\r\n\r\n const rgb: RGB = {\r\n r: Math.min(255, parseInt(m[2], 10)),\r\n g: Math.min(255, parseInt(m[3], 10)),\r\n b: Math.min(255, parseInt(m[4], 10))\r\n }\r\n\r\n if (m[1]) {\r\n const alpha = parseFloat(m[5])\r\n rgb.a = Math.min(1, isNaN(alpha) === true ? 1 : alpha) * 100\r\n }\r\n\r\n return rgb\r\n}\r\n\r\n/**\r\n * Lighten the `color` (if `percent` is positive) or darken it (if `percent` is negative).\r\n *\r\n * Accepts a HEX/A String or a RGB/A String as color and a percent (0 to 100 or -100 to 0) of lighten/darken to be applied to the `color`. Returns a HEX String representation of the calculated `color`.\r\n */\r\nexport function lighten(color: COLOR, percent: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n if (typeof percent !== 'number') {\r\n throw new TypeError('Expected a numeric percent')\r\n }\r\n\r\n const rgb = textToRgb(color),\r\n t = percent < 0 ? 0 : 255,\r\n p = Math.abs(percent) / 100,\r\n R = rgb.r,\r\n G = rgb.g,\r\n B = rgb.b\r\n\r\n return (\r\n '#' +\r\n (\r\n 0x1_00_00_00 +\r\n (Math.round((t - R) * p) + R) * 0x1_00_00 +\r\n (Math.round((t - G) * p) + G) * 0x1_00 +\r\n (Math.round((t - B) * p) + B)\r\n )\r\n .toString(16)\r\n .slice(1)\r\n )\r\n}\r\n/**\r\n * Calculates the [relative luminance](https://www.w3.org/TR/WCAG20/#relativeluminancedef) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function luminosity(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color,\r\n r = rgb.r / 255,\r\n g = rgb.g / 255,\r\n b = rgb.b / 255,\r\n R = r <= 0.039_28 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4),\r\n G = g <= 0.039_28 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4),\r\n B = b <= 0.039_28 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4)\r\n return 0.2126 * R + 0.7152 * G + 0.0722 * B\r\n}\r\n/**\r\n * Calculates the [color contrast](https://www.w3.org/TR/AERT/#color-contrast) of the `color`.\r\n *\r\n * Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `color`. Returns a value between 0 and 1.\r\n */\r\nexport function brightness(color: COLOR | RGB) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n\r\n return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000\r\n}\r\n\r\n/**\r\n * Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors.\r\n *\r\n * 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.\r\n */\r\nexport function blend(fgColor: COLOR | RGB, bgColor: COLOR | RGB) {\r\n if (typeof fgColor !== 'string' && (!fgColor || fgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as fgColor')\r\n }\r\n\r\n if (typeof bgColor !== 'string' && (!bgColor || bgColor.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b[, a]} object as bgColor')\r\n }\r\n\r\n const rgb1 = typeof fgColor === 'string' ? textToRgb(fgColor) : fgColor,\r\n r1 = rgb1.r / 255,\r\n g1 = rgb1.g / 255,\r\n b1 = rgb1.b / 255,\r\n a1 = rgb1.a !== void 0 ? rgb1.a / 100 : 1,\r\n rgb2 = typeof bgColor === 'string' ? textToRgb(bgColor) : bgColor,\r\n r2 = rgb2.r / 255,\r\n g2 = rgb2.g / 255,\r\n b2 = rgb2.b / 255,\r\n a2 = rgb2.a !== void 0 ? rgb2.a / 100 : 1,\r\n a = a1 + a2 * (1 - a1),\r\n r = Math.round(((r1 * a1 + r2 * a2 * (1 - a1)) / a) * 255),\r\n g = Math.round(((g1 * a1 + g2 * a2 * (1 - a1)) / a) * 255),\r\n b = Math.round(((b1 * a1 + b2 * a2 * (1 - a1)) / a) * 255)\r\n\r\n const ret = { r, g, b, a: Math.round(a * 100) }\r\n return typeof fgColor === 'string' ? rgbToHex(ret) : ret\r\n}\r\n\r\n/**\r\n * Increments or decrements the alpha of a string color.\r\n *\r\n * Accepts a HEX/A String as color and a number between -1 and 1 (including edges) as offset. Use a negative value to decrement and a positive number to increment (ex: blendAlpha('#ff0000', -0.1) to decrement alpha by 10%). Returns HEX/A String.\r\n */\r\nexport function blendAlpha(color: COLOR, offset: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n\r\n if (offset === void 0 || offset < -1 || offset > 1) {\r\n throw new TypeError('Expected offset to be between -1 and 1')\r\n }\r\n\r\n const { r, g, b, a } = textToRgb(color)\r\n const alpha = a !== void 0 ? a / 100 : 0\r\n\r\n return rgbToHex({\r\n r,\r\n g,\r\n b,\r\n a: Math.round(Math.min(1, Math.max(0, alpha + offset)) * 100)\r\n })\r\n}\r\n\r\n/**\r\n * Change color transparency\r\n */\r\nexport function changeAlpha(color: COLOR, alpha: number) {\r\n if (typeof color !== 'string') {\r\n throw new TypeError('Expected a string as color')\r\n }\r\n if (alpha === void 0 || alpha < 0 || alpha > 100) {\r\n throw new TypeError('Expected alpha to be between 0 and 1')\r\n }\r\n const rgba = textToRgb(color)\r\n rgba.a = alpha\r\n\r\n return rgbToHex(rgba)\r\n}\r\n\r\nconst hueStep = 2\r\nconst saturationStep = 16\r\nconst saturationStep2 = 5\r\nconst brightnessStep1 = 5\r\nconst brightnessStep2 = 15\r\nconst lightColorCount = 5\r\nconst darkColorCount = 4\r\n\r\n/**\r\n * \u6839\u636E\u989C\u8272\u83B7\u53D6\u8C03\u8272\u677F\u989C\u8272(\u4ECE\u5DE6\u81F3\u53F3\u989C\u8272\u4ECE\u6D45\u5230\u6DF1\uFF0C6\u4E3A\u4E3B\u8272\u53F7)\r\n * @param color - \u989C\u8272\r\n * @param index - \u8C03\u8272\u677F\u7684\u5BF9\u5E94\u7684\u8272\u53F7(6\u4E3A\u4E3B\u8272\u53F7)\r\n * @description \u7B97\u6CD5\u5B9E\u73B0\u4ECEant-design\u8C03\u8272\u677F\u7B97\u6CD5\u4E2D\u501F\u9274 https://github.com/ant-design/ant-design/blob/master/components/style/color/colorPalette.less\r\n */\r\nexport function colorPalette(color: COLOR | RGB, index: PALETTE_INDEXES) {\r\n if (typeof color !== 'string' && (!color || color.r === void 0)) {\r\n throw new TypeError('Expected a string or a {r, g, b} object as color')\r\n }\r\n const rgb = typeof color === 'string' ? textToRgb(color) : color\r\n const oldHsv = rgbToHsv(rgb)\r\n\r\n if (index === 6) return rgbToHex(rgb)\r\n\r\n const light = index < 6\r\n const i = light ? lightColorCount + 1 - index : index - lightColorCount - 1\r\n const newHsv: HSVA = {\r\n h: hue(oldHsv, i, light),\r\n s: saturation(oldHsv, i, light),\r\n v: value(oldHsv, i, light),\r\n a: oldHsv.a\r\n }\r\n\r\n return rgbToHex(hsvToRgb(newHsv))\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u8272\u76F8\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction hue(hsv: HSVA, i: number, isLight: boolean) {\r\n let hue: number\r\n if (hsv.h >= 60 && hsv.h <= 240) {\r\n // \u51B7\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h - hueStep * i : hsv.h + hueStep * i\r\n } else {\r\n // \u6696\u8272\u8C03\r\n // \u51CF\u6DE1\u53D8\u4EAE \u8272\u76F8\u9006\u65F6\u9488\u65CB\u8F6C \u66F4\u6696\r\n // \u52A0\u6DF1\u53D8\u6697 \u8272\u76F8\u987A\u65F6\u9488\u65CB\u8F6C \u66F4\u51B7\r\n hue = isLight ? hsv.h + hueStep * i : hsv.h - hueStep * i\r\n }\r\n if (hue < 0) hue += 360\r\n else if (hue >= 360) hue -= 360\r\n\r\n return hue\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u9971\u548C\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction saturation(hsv: HSVA, i: number, isLight: boolean) {\r\n let saturation: number\r\n if (isLight) saturation = hsv.s - saturationStep * i\r\n else if (i === darkColorCount) saturation = hsv.s + saturationStep\r\n else saturation = hsv.s + saturationStep2 * i\r\n\r\n if (saturation > 100) saturation = 100\r\n\r\n if (isLight && i === lightColorCount && saturation > 10) saturation = 10\r\n\r\n if (saturation < 6) saturation = 6\r\n\r\n return saturation\r\n}\r\n\r\n/**\r\n * \u83B7\u53D6\u660E\u5EA6\u6E10\u53D8\r\n * @param hsv - hsv\u683C\u5F0F\u989C\u8272\u503C\r\n * @param i - \u4E0E6\u7684\u76F8\u5BF9\u8DDD\u79BB\r\n * @param isLight - \u662F\u5426\u662F\u4EAE\u989C\u8272\r\n */\r\nfunction value(hsv: HSVA, i: number, isLight: boolean) {\r\n let value: number\r\n value = isLight ? hsv.v + brightnessStep1 * i : hsv.v - brightnessStep2 * i\r\n\r\n if (value > 100) value = 100\r\n\r\n return value\r\n}\r\n"],
5
+ "mappings": "mbAAA,8MAWA,GAAM,GAAU,8DAaT,WAAkB,CAAE,IAAG,IAAG,IAAG,KAAe,CACjD,GAAM,GAAQ,IAAM,OAMpB,GAJA,EAAI,KAAK,MAAM,CAAC,EAChB,EAAI,KAAK,MAAM,CAAC,EAChB,EAAI,KAAK,MAAM,CAAC,EAEZ,EAAI,KAAO,EAAI,KAAO,EAAI,KAAQ,GAAS,EAAK,IAClD,KAAM,IAAI,WAAU,6DAA6D,EAGnF,MAAI,IACF,GAAI,OAAQ,MAAK,MAAO,IAAM,EAAM,GAAG,EAAK,GAAK,GAAI,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,GAGrE,IAAO,GAAK,GAAK,EAAM,GAAK,GAAO,GAAK,IAAK,SAAS,EAAE,EAAE,MAAM,CAAC,EAAI,CAC9E,CAaO,WAAkB,EAAe,CACtC,GAAI,MAAO,IAAQ,SACjB,KAAM,IAAI,WAAU,mBAAmB,EAGzC,EAAM,EAAI,QAAQ,KAAM,EAAE,EAE1B,AAAI,EAAI,SAAW,EACjB,EAAM,EAAI,GAAK,EAAI,GAAK,EAAI,GAAK,EAAI,GAAK,EAAI,GAAK,EAAI,GAC9C,EAAI,SAAW,GACxB,GAAM,EAAI,GAAK,EAAI,GAAK,EAAI,GAAK,EAAI,GAAK,EAAI,GAAK,EAAI,GAAK,EAAI,GAAK,EAAI,IAG3E,GAAM,GAAM,SAAS,EAAK,EAAE,EAE5B,MAAO,GAAI,OAAS,EAChB,CAAE,EAAI,GAAO,GAAM,IAAK,EAAI,GAAO,GAAM,IAAK,EAAI,GAAO,EAAK,IAAK,EAAG,KAAK,MAAO,GAAM,KAAO,IAAI,CAAE,EACrG,CAAE,EAAG,GAAO,GAAI,EAAI,GAAO,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AAU,CAAK,EAAI,EACrD,EAAS,EAAS,CAAG,EAE3B,GAAI,IAAU,EAAG,MAAO,GAAS,CAAG,EAEpC,GAAM,GAAQ,EAAQ,EAChB,EAAI,EAAQ,EAAkB,EAAI,EAAQ,EAAQ,EAAkB,EACpE,EAAe,CACnB,EAAG,EAAI,EAAQ,EAAG,CAAK,EACvB,EAAG,EAAW,EAAQ,EAAG,CAAK,EAC9B,EAAG,EAAM,EAAQ,EAAG,CAAK,EACzB,EAAG,EAAO,CACZ,EAEA,MAAO,GAAS,EAAS,CAAM,CAAC,CAClC,CAQA,WAAa,EAAW,EAAW,EAAkB,CACnD,GAAI,GACJ,MAAI,GAAI,GAAK,IAAM,EAAI,GAAK,IAI1B,EAAM,EAAU,EAAI,EAAI,EAAU,EAAI,EAAI,EAAI,EAAU,EAKxD,EAAM,EAAU,EAAI,EAAI,EAAU,EAAI,EAAI,EAAI,EAAU,EAE1D,AAAI,EAAM,EAAG,GAAO,IACX,GAAO,KAAK,IAAO,KAErB,CACT,CAQA,WAAoB,EAAW,EAAW,EAAkB,CAC1D,GAAI,GACJ,MAAI,GAAS,EAAa,EAAI,EAAI,EAAiB,EAC9C,AAAI,IAAM,EAAgB,EAAa,EAAI,EAAI,EAC/C,EAAa,EAAI,EAAI,EAAkB,EAExC,EAAa,KAAK,GAAa,KAE/B,GAAW,IAAM,GAAmB,EAAa,IAAI,GAAa,IAElE,EAAa,GAAG,GAAa,GAE1B,CACT,CAQA,WAAe,EAAW,EAAW,EAAkB,CACrD,GAAI,GACJ,SAAQ,EAAU,EAAI,EAAI,EAAkB,EAAI,EAAI,EAAI,EAAkB,EAEtE,EAAQ,KAAK,GAAQ,KAElB,CACT",
6
6
  "names": []
7
7
  }
package/index.md CHANGED
@@ -79,4 +79,6 @@ Accepts a HEX/A String or a RGB/A Object as `fgColor`/`bgColor`. If the alpha ch
79
79
  ### changeAlpha(color, offset)
80
80
  Increments or decrements the alpha of a string color.
81
81
 
82
- Accepts a HEX/A String as color and a number between -1 and 1 (including edges) as offset. Use a negative value to decrement and a positive number to increment (ex: changeAlpha('#ff0000', -0.1) to decrement alpha by 10%). Returns HEX/A String.
82
+ Accepts a HEX/A String as color and a number between -1 and 1 (including edges) as offset. Use a negative value to decrement and a positive number to increment (ex: changeAlpha('#ff0000', -0.1) to decrement alpha by 10%). Returns HEX/A String.
83
+
84
+ ###
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hairy/palette",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "main": "index.cjs.js",
5
5
  "publishConfig": {
6
6
  "jsdelivr": "./index.iife.min.js"