@unicom-cloud/utils 0.1.11 → 0.1.12

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.
Files changed (107) hide show
  1. package/date/index.js +22 -0
  2. package/date.js +9 -0
  3. package/index.js +56 -54
  4. package/lunar/index.js +36 -0
  5. package/lunar/lib/Holiday.js +42 -0
  6. package/lunar/lib/HolidayUtil.js +128 -0
  7. package/lunar/lib/I18n.js +1005 -0
  8. package/lunar/lib/JieQi.js +40 -0
  9. package/lunar/lib/Lunar.js +1035 -0
  10. package/lunar/lib/LunarMonth.js +150 -0
  11. package/lunar/lib/LunarTime.js +138 -0
  12. package/lunar/lib/LunarUtil.js +1752 -0
  13. package/lunar/lib/LunarYear.js +616 -0
  14. package/lunar/lib/ShouXingUtil.js +6915 -0
  15. package/lunar/lib/Solar.js +311 -0
  16. package/lunar/lib/SolarHalfYear.js +45 -0
  17. package/lunar/lib/SolarMonth.js +55 -0
  18. package/lunar/lib/SolarSeason.js +42 -0
  19. package/lunar/lib/SolarUtil.js +256 -0
  20. package/lunar/lib/SolarWeek.js +153 -0
  21. package/lunar/lib/SolarYear.js +35 -0
  22. package/lunar/lib/index.js +35 -0
  23. package/lunar.js +36 -0
  24. package/package.json +1 -1
  25. package/snapdom/src/api/preCache.js +26 -36
  26. package/snapdom/src/api/snapdom.js +78 -61
  27. package/snapdom/src/core/capture.js +54 -54
  28. package/snapdom/src/core/prepare.js +46 -37
  29. package/snapdom/src/modules/fonts.js +90 -92
  30. package/snapdom/src/modules/iconFonts.js +28 -0
  31. package/snapdom/src/modules/images.js +6 -6
  32. package/snapdom/src/modules/pseudo.js +51 -49
  33. package/snapdom/src/modules/styles.js +27 -7
  34. package/snapdom/src/modules/svgDefs.js +26 -0
  35. package/snapdom/src/utils/helpers.js +150 -103
  36. package/tinycolor/index.js +46 -0
  37. package/tinycolor/src/conversion.js +143 -0
  38. package/tinycolor/src/css-color-names.js +153 -0
  39. package/tinycolor/src/format-input.js +77 -0
  40. package/tinycolor/src/from-ratio.js +21 -0
  41. package/tinycolor/src/index.js +404 -0
  42. package/tinycolor/src/random.js +221 -0
  43. package/tinycolor/src/readability.js +37 -0
  44. package/tinycolor/src/to-ms-filter.js +15 -0
  45. package/tinycolor/src/util.js +32 -0
  46. package/tinycolor.js +46 -0
  47. package/tree/index.js +10 -8
  48. package/tree.js +9 -7
  49. package/types/date/index.d.ts +4 -0
  50. package/types/index.d.ts +4 -3
  51. package/types/lunar/index.d.ts +3 -0
  52. package/types/lunar/lib/Holiday.d.ts +17 -0
  53. package/types/lunar/lib/HolidayUtil.d.ts +23 -0
  54. package/types/lunar/lib/I18n.d.ts +23 -0
  55. package/types/lunar/lib/JieQi.d.ts +15 -0
  56. package/types/lunar/lib/Lunar.d.ts +245 -0
  57. package/types/lunar/lib/LunarMonth.d.ts +35 -0
  58. package/types/lunar/lib/LunarTime.d.ts +40 -0
  59. package/types/lunar/lib/LunarUtil.d.ts +128 -0
  60. package/types/lunar/lib/LunarYear.d.ts +61 -0
  61. package/types/lunar/lib/ShouXingUtil.d.ts +38 -0
  62. package/types/lunar/lib/Solar.d.ts +51 -0
  63. package/types/lunar/lib/SolarHalfYear.d.ts +15 -0
  64. package/types/lunar/lib/SolarMonth.d.ts +16 -0
  65. package/types/lunar/lib/SolarSeason.d.ts +15 -0
  66. package/types/lunar/lib/SolarUtil.d.ts +20 -0
  67. package/types/lunar/lib/SolarWeek.d.ts +23 -0
  68. package/types/lunar/lib/SolarYear.d.ts +12 -0
  69. package/types/lunar/lib/index.d.ts +17 -0
  70. package/types/snapdom/src/core/prepare.d.ts +1 -1
  71. package/types/snapdom/src/modules/fonts.d.ts +1 -3
  72. package/types/snapdom/src/modules/iconFonts.d.ts +2 -0
  73. package/types/snapdom/src/modules/pseudo.d.ts +1 -1
  74. package/types/snapdom/src/modules/styles.d.ts +1 -10
  75. package/types/snapdom/src/modules/svgDefs.d.ts +19 -0
  76. package/types/snapdom/src/utils/helpers.d.ts +1 -1
  77. package/types/tinycolor/index.d.ts +2 -0
  78. package/types/tinycolor/src/conversion.d.ts +79 -0
  79. package/types/tinycolor/src/css-color-names.d.ts +4 -0
  80. package/types/tinycolor/src/format-input.d.ts +38 -0
  81. package/types/tinycolor/src/from-ratio.d.ts +14 -0
  82. package/types/tinycolor/src/index.d.ts +214 -0
  83. package/types/tinycolor/src/interfaces.d.ts +57 -0
  84. package/types/tinycolor/src/public_api.d.ts +10 -0
  85. package/types/tinycolor/src/random.d.ts +24 -0
  86. package/types/tinycolor/src/readability.d.ts +46 -0
  87. package/types/tinycolor/src/to-ms-filter.d.ts +5 -0
  88. package/types/tinycolor/src/umd_api.d.ts +22 -0
  89. package/types/tinycolor/src/util.d.ts +36 -0
  90. package/types/tree/index.d.ts +1 -0
  91. package/types/ui-color/compareColorByRange.d.ts +2 -0
  92. package/types/ui-color/index.d.ts +183 -0
  93. package/ui-color/compareColorByRange.js +9 -0
  94. package/ui-color/index.js +155 -0
  95. package/uiColor.js +28 -0
  96. package/convertTime.js +0 -4
  97. package/dayjs/index.js +0 -15
  98. package/dayjs.js +0 -5
  99. package/lunar-converter/index.js +0 -641
  100. package/lunarConverter.js +0 -4
  101. package/searchTree.js +0 -4
  102. package/types/dayjs/index.d.ts +0 -1
  103. package/types/lunar-converter/index.d.ts +0 -113
  104. /package/{convert-time/index.js → date/convertTime.js} +0 -0
  105. /package/{search-tree/index.js → tree/searchTree.js} +0 -0
  106. /package/types/{convert-time/index.d.ts → date/convertTime.d.ts} +0 -0
  107. /package/types/{search-tree/index.d.ts → tree/searchTree.d.ts} +0 -0
@@ -0,0 +1,77 @@
1
+ import { rgbToRgb as S, hsvToRgb as v, hslToRgb as E, cmykToRgb as F, convertHexToDecimal as A, parseIntFromHex as s } from "./conversion.js";
2
+ import { names as R } from "./css-color-names.js";
3
+ import { convertToPercentage as g, boundAlpha as T } from "./util.js";
4
+ function N(t) {
5
+ let a = { r: 0, g: 0, b: 0 }, e = 1, m = null, b = null, p = null, r = !1, i = !1;
6
+ return typeof t == "string" && (t = w(t)), typeof t == "object" && (n(t.r) && n(t.g) && n(t.b) ? (a = S(t.r, t.g, t.b), r = !0, i = String(t.r).slice(-1) === "%" ? "prgb" : "rgb") : n(t.h) && n(t.s) && n(t.v) ? (m = g(t.s), b = g(t.v), a = v(t.h, m, b), r = !0, i = "hsv") : n(t.h) && n(t.s) && n(t.l) ? (m = g(t.s), p = g(t.l), a = E(t.h, m, p), r = !0, i = "hsl") : n(t.c) && n(t.m) && n(t.y) && n(t.k) && (a = F(t.c, t.m, t.y, t.k), r = !0, i = "cmyk"), Object.prototype.hasOwnProperty.call(t, "a") && (e = t.a)), e = T(e), {
7
+ ok: r,
8
+ format: t.format || i,
9
+ r: Math.min(255, Math.max(a.r, 0)),
10
+ g: Math.min(255, Math.max(a.g, 0)),
11
+ b: Math.min(255, Math.max(a.b, 0)),
12
+ a: e
13
+ };
14
+ }
15
+ const y = "[-\\+]?\\d+%?", M = "[-\\+]?\\d*\\.\\d+%?", h = "(?:" + M + ")|(?:" + y + ")", u = "[\\s|\\(]+(" + h + ")[,|\\s]+(" + h + ")[,|\\s]+(" + h + ")\\s*\\)?", x = (
16
+ // eslint-disable-next-line prettier/prettier
17
+ "[\\s|\\(]+(" + h + ")[,|\\s]+(" + h + ")[,|\\s]+(" + h + ")[,|\\s]+(" + h + ")\\s*\\)?"
18
+ ), f = {
19
+ CSS_UNIT: new RegExp(h),
20
+ rgb: new RegExp("rgb" + u),
21
+ rgba: new RegExp("rgba" + x),
22
+ hsl: new RegExp("hsl" + u),
23
+ hsla: new RegExp("hsla" + x),
24
+ hsv: new RegExp("hsv" + u),
25
+ hsva: new RegExp("hsva" + x),
26
+ cmyk: new RegExp("cmyk" + x),
27
+ hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
28
+ hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
29
+ hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
30
+ hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
31
+ };
32
+ function w(t) {
33
+ if (t = t.trim().toLowerCase(), t.length === 0)
34
+ return !1;
35
+ let a = !1;
36
+ if (R[t])
37
+ t = R[t], a = !0;
38
+ else if (t === "transparent")
39
+ return { r: 0, g: 0, b: 0, a: 0, format: "name" };
40
+ let e = f.rgb.exec(t);
41
+ return e ? { r: e[1], g: e[2], b: e[3] } : (e = f.rgba.exec(t), e ? { r: e[1], g: e[2], b: e[3], a: e[4] } : (e = f.hsl.exec(t), e ? { h: e[1], s: e[2], l: e[3] } : (e = f.hsla.exec(t), e ? { h: e[1], s: e[2], l: e[3], a: e[4] } : (e = f.hsv.exec(t), e ? { h: e[1], s: e[2], v: e[3] } : (e = f.hsva.exec(t), e ? { h: e[1], s: e[2], v: e[3], a: e[4] } : (e = f.cmyk.exec(t), e ? {
42
+ c: e[1],
43
+ m: e[2],
44
+ y: e[3],
45
+ k: e[4]
46
+ } : (e = f.hex8.exec(t), e ? {
47
+ r: s(e[1]),
48
+ g: s(e[2]),
49
+ b: s(e[3]),
50
+ a: A(e[4]),
51
+ format: a ? "name" : "hex8"
52
+ } : (e = f.hex6.exec(t), e ? {
53
+ r: s(e[1]),
54
+ g: s(e[2]),
55
+ b: s(e[3]),
56
+ format: a ? "name" : "hex"
57
+ } : (e = f.hex4.exec(t), e ? {
58
+ r: s(e[1] + e[1]),
59
+ g: s(e[2] + e[2]),
60
+ b: s(e[3] + e[3]),
61
+ a: A(e[4] + e[4]),
62
+ format: a ? "name" : "hex8"
63
+ } : (e = f.hex3.exec(t), e ? {
64
+ r: s(e[1] + e[1]),
65
+ g: s(e[2] + e[2]),
66
+ b: s(e[3] + e[3]),
67
+ format: a ? "name" : "hex"
68
+ } : !1))))))))));
69
+ }
70
+ function n(t) {
71
+ return typeof t == "number" ? !Number.isNaN(t) : f.CSS_UNIT.test(t);
72
+ }
73
+ export {
74
+ N as inputToRGB,
75
+ n as isValidCSSUnit,
76
+ w as stringInputToObject
77
+ };
@@ -0,0 +1,21 @@
1
+ import { TinyColor as e } from "./index.js";
2
+ import { convertToPercentage as o } from "./util.js";
3
+ function c(n, m) {
4
+ const r = {
5
+ r: o(n.r),
6
+ g: o(n.g),
7
+ b: o(n.b)
8
+ };
9
+ return n.a !== void 0 && (r.a = Number(n.a)), new e(r, m);
10
+ }
11
+ function f() {
12
+ return new e({
13
+ r: Math.random(),
14
+ g: Math.random(),
15
+ b: Math.random()
16
+ });
17
+ }
18
+ export {
19
+ c as fromRatio,
20
+ f as legacyRandom
21
+ };
@@ -0,0 +1,404 @@
1
+ import { numberInputToObject as d, rgbToHsv as g, rgbToHsl as u, rgbToHex as b, rgbaToHex as m, rgbToCmyk as c } from "./conversion.js";
2
+ import { names as $ } from "./css-color-names.js";
3
+ import { inputToRGB as f } from "./format-input.js";
4
+ import { boundAlpha as p, clamp01 as a, bound01 as l } from "./util.js";
5
+ class n {
6
+ /** red */
7
+ r;
8
+ /** green */
9
+ g;
10
+ /** blue */
11
+ b;
12
+ /** alpha */
13
+ a;
14
+ /** the format used to create the tinycolor instance */
15
+ format;
16
+ /** input passed into the constructer used to create the tinycolor instance */
17
+ originalInput;
18
+ /** the color was successfully parsed */
19
+ isValid;
20
+ gradientType;
21
+ /** rounded alpha */
22
+ roundA;
23
+ constructor(t = "", s = {}) {
24
+ if (t instanceof n)
25
+ return t;
26
+ typeof t == "number" && (t = d(t)), this.originalInput = t;
27
+ const r = f(t);
28
+ this.originalInput = t, this.r = r.r, this.g = r.g, this.b = r.b, this.a = r.a, this.roundA = Math.round(100 * this.a) / 100, this.format = s.format ?? r.format, this.gradientType = s.gradientType, this.r < 1 && (this.r = Math.round(this.r)), this.g < 1 && (this.g = Math.round(this.g)), this.b < 1 && (this.b = Math.round(this.b)), this.isValid = r.ok;
29
+ }
30
+ get ok() {
31
+ return this.isValid;
32
+ }
33
+ isDark() {
34
+ return this.getBrightness() < 128;
35
+ }
36
+ isLight() {
37
+ return !this.isDark();
38
+ }
39
+ /**
40
+ * Returns the perceived brightness of the color, from 0-255.
41
+ */
42
+ getBrightness() {
43
+ const t = this.toRgb();
44
+ return (t.r * 299 + t.g * 587 + t.b * 114) / 1e3;
45
+ }
46
+ /**
47
+ * Returns the perceived luminance of a color, from 0-1.
48
+ */
49
+ getLuminance() {
50
+ const t = this.toRgb();
51
+ let s, r, h;
52
+ const i = t.r / 255, e = t.g / 255, o = t.b / 255;
53
+ return i <= 0.03928 ? s = i / 12.92 : s = Math.pow((i + 0.055) / 1.055, 2.4), e <= 0.03928 ? r = e / 12.92 : r = Math.pow((e + 0.055) / 1.055, 2.4), o <= 0.03928 ? h = o / 12.92 : h = Math.pow((o + 0.055) / 1.055, 2.4), 0.2126 * s + 0.7152 * r + 0.0722 * h;
54
+ }
55
+ /**
56
+ * Returns the alpha value of a color, from 0-1.
57
+ */
58
+ getAlpha() {
59
+ return this.a;
60
+ }
61
+ /**
62
+ * Sets the alpha value on the current color.
63
+ *
64
+ * @param alpha - The new alpha value. The accepted range is 0-1.
65
+ */
66
+ setAlpha(t) {
67
+ return this.a = p(t), this.roundA = Math.round(100 * this.a) / 100, this;
68
+ }
69
+ /**
70
+ * Returns whether the color is monochrome.
71
+ */
72
+ isMonochrome() {
73
+ const { s: t } = this.toHsl();
74
+ return t === 0;
75
+ }
76
+ /**
77
+ * Returns the object as a HSVA object.
78
+ */
79
+ toHsv() {
80
+ const t = g(this.r, this.g, this.b);
81
+ return { h: t.h * 360, s: t.s, v: t.v, a: this.a };
82
+ }
83
+ toHsv_() {
84
+ const t = g(this.r, this.g, this.b);
85
+ return { h: t.h, s: t.s, v: t.v, a: this.a };
86
+ }
87
+ /**
88
+ * Returns the hsva values interpolated into a string with the following format:
89
+ * "hsva(xxx, xxx, xxx, xx)".
90
+ */
91
+ toHsvString() {
92
+ const t = g(this.r, this.g, this.b), s = Math.round(t.h * 360), r = Math.round(t.s * 100), h = Math.round(t.v * 100);
93
+ return this.a === 1 ? `hsv(${s}, ${r}%, ${h}%)` : `hsva(${s}, ${r}%, ${h}%, ${this.roundA})`;
94
+ }
95
+ /**
96
+ * Returns the object as a HSLA object.
97
+ */
98
+ toHsl() {
99
+ const t = u(this.r, this.g, this.b);
100
+ return { h: t.h * 360, s: t.s, l: t.l, a: this.a };
101
+ }
102
+ /**
103
+ * Returns the hsla values interpolated into a string with the following format:
104
+ * "hsla(xxx, xxx, xxx, xx)".
105
+ */
106
+ toHslString() {
107
+ const t = u(this.r, this.g, this.b), s = Math.round(t.h * 360), r = Math.round(t.s * 100), h = Math.round(t.l * 100);
108
+ return this.a === 1 ? `hsl(${s}, ${r}%, ${h}%)` : `hsla(${s}, ${r}%, ${h}%, ${this.roundA})`;
109
+ }
110
+ /**
111
+ * Returns the hex value of the color.
112
+ * @param allow3Char will shorten hex value to 3 char if possible
113
+ */
114
+ toHex(t = !1) {
115
+ return b(this.r, this.g, this.b, t);
116
+ }
117
+ /**
118
+ * Returns the hex value of the color -with a # prefixed.
119
+ * @param allow3Char will shorten hex value to 3 char if possible
120
+ */
121
+ toHexString(t = !1) {
122
+ return `#${this.toHex(t)}`;
123
+ }
124
+ /**
125
+ * Returns the hex 8 value of the color.
126
+ * @param allow4Char will shorten hex value to 4 char if possible
127
+ */
128
+ toHex8(t = !1) {
129
+ return m(this.r, this.g, this.b, this.a, t);
130
+ }
131
+ /**
132
+ * Returns the hex 8 value of the color -with a # prefixed.
133
+ * @param allow4Char will shorten hex value to 4 char if possible
134
+ */
135
+ toHex8String(t = !1) {
136
+ return `#${this.toHex8(t)}`;
137
+ }
138
+ /**
139
+ * Returns the shorter hex value of the color depends on its alpha -with a # prefixed.
140
+ * @param allowShortChar will shorten hex value to 3 or 4 char if possible
141
+ */
142
+ toHexShortString(t = !1) {
143
+ return this.a === 1 ? this.toHexString(t) : this.toHex8String(t);
144
+ }
145
+ /**
146
+ * Returns the object as a RGBA object.
147
+ */
148
+ toRgb() {
149
+ return {
150
+ r: Math.round(this.r),
151
+ g: Math.round(this.g),
152
+ b: Math.round(this.b),
153
+ a: this.a
154
+ };
155
+ }
156
+ toRgba() {
157
+ return this.toRgb();
158
+ }
159
+ toRgbArray() {
160
+ const t = this.toRgb();
161
+ return [t.r, t.g, t.b];
162
+ }
163
+ toRgbArrayString() {
164
+ const t = this.toRgb();
165
+ return `${t.r},${t.g},${t.b}`;
166
+ }
167
+ /**
168
+ * Returns the RGBA values interpolated into a string with the following format:
169
+ * "RGBA(xxx, xxx, xxx, xx)".
170
+ */
171
+ toRgbString() {
172
+ const t = Math.round(this.r), s = Math.round(this.g), r = Math.round(this.b);
173
+ return this.a === 1 ? `rgb(${t}, ${s}, ${r})` : `rgba(${t}, ${s}, ${r}, ${this.roundA})`;
174
+ }
175
+ toRgbaString() {
176
+ const t = Math.round(this.r), s = Math.round(this.g), r = Math.round(this.b);
177
+ return `rgba(${t}, ${s}, ${r}, ${this.roundA})`;
178
+ }
179
+ /**
180
+ * Returns the object as a RGBA object.
181
+ */
182
+ toPercentageRgb() {
183
+ const t = (s) => `${Math.round(l(s, 255) * 100)}%`;
184
+ return {
185
+ r: t(this.r),
186
+ g: t(this.g),
187
+ b: t(this.b),
188
+ a: this.a
189
+ };
190
+ }
191
+ /**
192
+ * Returns the RGBA relative values interpolated into a string
193
+ */
194
+ toPercentageRgbString() {
195
+ const t = (s) => Math.round(l(s, 255) * 100);
196
+ return this.a === 1 ? `rgb(${t(this.r)}%, ${t(this.g)}%, ${t(this.b)}%)` : `rgba(${t(this.r)}%, ${t(this.g)}%, ${t(this.b)}%, ${this.roundA})`;
197
+ }
198
+ toCmyk() {
199
+ return {
200
+ ...c(this.r, this.g, this.b)
201
+ };
202
+ }
203
+ toCmykString() {
204
+ const { c: t, m: s, y: r, k: h } = c(this.r, this.g, this.b);
205
+ return `cmyk(${t}, ${s}, ${r}, ${h})`;
206
+ }
207
+ /**
208
+ * The 'real' name of the color -if there is one.
209
+ */
210
+ toName() {
211
+ if (this.a === 0)
212
+ return "transparent";
213
+ if (this.a < 1)
214
+ return !1;
215
+ const t = `#${b(this.r, this.g, this.b, !1)}`;
216
+ for (const [s, r] of Object.entries($))
217
+ if (t === r)
218
+ return s;
219
+ return !1;
220
+ }
221
+ toString(t) {
222
+ const s = !!t;
223
+ t = t ?? this.format;
224
+ let r = !1;
225
+ const h = this.a < 1 && this.a >= 0;
226
+ return !s && h && (t.startsWith("hex") || t === "name") ? t === "name" && this.a === 0 ? this.toName() : this.toRgbString() : (t === "rgb" && (r = this.toRgbString()), t === "prgb" && (r = this.toPercentageRgbString()), (t === "hex" || t === "hex6") && (r = this.toHexString()), t === "hex3" && (r = this.toHexString(!0)), t === "hex4" && (r = this.toHex8String(!0)), t === "hex8" && (r = this.toHex8String()), t === "name" && (r = this.toName()), t === "hsl" && (r = this.toHslString()), t === "hsv" && (r = this.toHsvString()), t === "cmyk" && (r = this.toCmykString()), r || this.toHexString());
227
+ }
228
+ toNumber() {
229
+ return (Math.round(this.r) << 16) + (Math.round(this.g) << 8) + Math.round(this.b);
230
+ }
231
+ clone() {
232
+ return new n(this.toString());
233
+ }
234
+ /**
235
+ * Lighten the color a given amount. Providing 100 will always return white.
236
+ * @param amount - valid between 1-100
237
+ */
238
+ lighten(t = 10) {
239
+ const s = this.toHsl();
240
+ return s.l += t / 100, s.l = a(s.l), new n(s);
241
+ }
242
+ /**
243
+ * Brighten the color a given amount, from 0 to 100.
244
+ * @param amount - valid between 1-100
245
+ */
246
+ brighten(t = 10) {
247
+ const s = this.toRgb();
248
+ return s.r = Math.max(
249
+ 0,
250
+ Math.min(255, s.r - Math.round(255 * -(t / 100)))
251
+ ), s.g = Math.max(
252
+ 0,
253
+ Math.min(255, s.g - Math.round(255 * -(t / 100)))
254
+ ), s.b = Math.max(
255
+ 0,
256
+ Math.min(255, s.b - Math.round(255 * -(t / 100)))
257
+ ), new n(s);
258
+ }
259
+ /**
260
+ * Darken the color a given amount, from 0 to 100.
261
+ * Providing 100 will always return black.
262
+ * @param amount - valid between 1-100
263
+ */
264
+ darken(t = 10) {
265
+ const s = this.toHsl();
266
+ return s.l -= t / 100, s.l = a(s.l), new n(s);
267
+ }
268
+ /**
269
+ * Mix the color with pure white, from 0 to 100.
270
+ * Providing 0 will do nothing, providing 100 will always return white.
271
+ * @param amount - valid between 1-100
272
+ */
273
+ tint(t = 10) {
274
+ return this.mix("white", t);
275
+ }
276
+ /**
277
+ * Mix the color with pure black, from 0 to 100.
278
+ * Providing 0 will do nothing, providing 100 will always return black.
279
+ * @param amount - valid between 1-100
280
+ */
281
+ shade(t = 10) {
282
+ return this.mix("black", t);
283
+ }
284
+ /**
285
+ * Desaturate the color a given amount, from 0 to 100.
286
+ * Providing 100 will is the same as calling greyscale
287
+ * @param amount - valid between 1-100
288
+ */
289
+ desaturate(t = 10) {
290
+ const s = this.toHsl();
291
+ return s.s -= t / 100, s.s = a(s.s), new n(s);
292
+ }
293
+ /**
294
+ * Saturate the color a given amount, from 0 to 100.
295
+ * @param amount - valid between 1-100
296
+ */
297
+ saturate(t = 10) {
298
+ const s = this.toHsl();
299
+ return s.s += t / 100, s.s = a(s.s), new n(s);
300
+ }
301
+ /**
302
+ * Completely desaturates a color into greyscale.
303
+ * Same as calling `desaturate(100)`
304
+ */
305
+ greyscale() {
306
+ return this.desaturate(100);
307
+ }
308
+ /**
309
+ * Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
310
+ * Values outside of this range will be wrapped into this range.
311
+ */
312
+ spin(t) {
313
+ const s = this.toHsl(), r = (s.h + t) % 360;
314
+ return s.h = r < 0 ? 360 + r : r, new n(s);
315
+ }
316
+ /**
317
+ * Mix the current color a given amount with another color, from 0 to 100.
318
+ * 0 means no mixing (return current color).
319
+ */
320
+ mix(t, s = 50) {
321
+ const r = this.toRgb(), h = new n(t).toRgb(), i = s / 100, e = {
322
+ r: (h.r - r.r) * i + r.r,
323
+ g: (h.g - r.g) * i + r.g,
324
+ b: (h.b - r.b) * i + r.b,
325
+ a: (h.a - r.a) * i + r.a
326
+ };
327
+ return new n(e);
328
+ }
329
+ analogous(t = 6, s = 30) {
330
+ const r = this.toHsl(), h = 360 / s, i = [this];
331
+ for (r.h = (r.h - (h * t >> 1) + 720) % 360; --t; )
332
+ r.h = (r.h + h) % 360, i.push(new n(r));
333
+ return i;
334
+ }
335
+ /**
336
+ * taken from https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js
337
+ */
338
+ complement() {
339
+ const t = this.toHsl();
340
+ return t.h = (t.h + 180) % 360, new n(t);
341
+ }
342
+ monochromatic(t = 6) {
343
+ const s = this.toHsv(), { h: r } = s, { s: h } = s;
344
+ let { v: i } = s;
345
+ const e = [], o = 1 / t;
346
+ for (; t--; )
347
+ e.push(new n({ h: r, s: h, v: i })), i = (i + o) % 1;
348
+ return e;
349
+ }
350
+ splitcomplement() {
351
+ const t = this.toHsl(), { h: s } = t;
352
+ return [
353
+ this,
354
+ new n({ h: (s + 72) % 360, s: t.s, l: t.l }),
355
+ new n({ h: (s + 216) % 360, s: t.s, l: t.l })
356
+ ];
357
+ }
358
+ /**
359
+ * Compute how the color would appear on a background
360
+ */
361
+ onBackground(t) {
362
+ const s = this.toRgb(), r = new n(t).toRgb(), h = s.a + r.a * (1 - s.a);
363
+ return new n({
364
+ r: (s.r * s.a + r.r * r.a * (1 - s.a)) / h,
365
+ g: (s.g * s.a + r.g * r.a * (1 - s.a)) / h,
366
+ b: (s.b * s.a + r.b * r.a * (1 - s.a)) / h,
367
+ a: h
368
+ });
369
+ }
370
+ /**
371
+ * Alias for `polyad(3)`
372
+ */
373
+ triad() {
374
+ return this.polyad(3);
375
+ }
376
+ /**
377
+ * Alias for `polyad(4)`
378
+ */
379
+ tetrad() {
380
+ return this.polyad(4);
381
+ }
382
+ /**
383
+ * Get polyad colors, like (for 1, 2, 3, 4, 5, 6, 7, 8, etc...)
384
+ * monad, dyad, triad, tetrad, pentad, hexad, heptad, octad, etc...
385
+ */
386
+ polyad(t) {
387
+ const s = this.toHsl(), { h: r } = s, h = [this], i = 360 / t;
388
+ for (let e = 1; e < t; e++)
389
+ h.push(
390
+ new n({ h: (r + e * i) % 360, s: s.s, l: s.l })
391
+ );
392
+ return h;
393
+ }
394
+ /**
395
+ * compare color vs current color
396
+ */
397
+ equals(t) {
398
+ const s = new n(t);
399
+ return this.format === "cmyk" || s.format === "cmyk" ? this.toCmykString() === s.toCmykString() : this.toRgbString() === s.toRgbString();
400
+ }
401
+ }
402
+ export {
403
+ n as TinyColor
404
+ };