@unicom-cloud/utils 0.1.10 → 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.
- package/caseName.js +11 -0
- package/className.js +5 -0
- package/clipboardCopy.js +6 -0
- package/constant.js +4 -0
- package/contentDisposition.js +7 -0
- package/cookie.js +7 -0
- package/date/convertTime.js +61 -0
- package/date/index.js +22 -0
- package/date.js +9 -0
- package/decimal.js +5 -0
- package/eventEmitter.js +4 -0
- package/file.js +6 -0
- package/filesize.js +8 -0
- package/index.js +56 -46
- package/invariant.js +4 -0
- package/is.js +92 -0
- package/lunar/index.js +36 -0
- package/lunar/lib/Holiday.js +42 -0
- package/lunar/lib/HolidayUtil.js +128 -0
- package/lunar/lib/I18n.js +1005 -0
- package/lunar/lib/JieQi.js +40 -0
- package/lunar/lib/Lunar.js +1035 -0
- package/lunar/lib/LunarMonth.js +150 -0
- package/lunar/lib/LunarTime.js +138 -0
- package/lunar/lib/LunarUtil.js +1752 -0
- package/lunar/lib/LunarYear.js +616 -0
- package/lunar/lib/ShouXingUtil.js +6915 -0
- package/lunar/lib/Solar.js +311 -0
- package/lunar/lib/SolarHalfYear.js +45 -0
- package/lunar/lib/SolarMonth.js +55 -0
- package/lunar/lib/SolarSeason.js +42 -0
- package/lunar/lib/SolarUtil.js +256 -0
- package/lunar/lib/SolarWeek.js +153 -0
- package/lunar/lib/SolarYear.js +35 -0
- package/lunar/lib/index.js +35 -0
- package/lunar.js +36 -0
- package/math.js +9 -0
- package/md5.js +4 -0
- package/mock.js +8 -0
- package/normalizeWheel.js +6 -0
- package/number-to-chinese/index.js +72 -0
- package/numberToChinese.js +4 -0
- package/nzh.js +4 -0
- package/object-keys-sort/index.js +7 -0
- package/objectKeysSort.js +2 -5
- package/package.json +1 -1
- package/random.js +15 -0
- package/screenfull.js +4 -0
- package/snapdom/src/api/preCache.js +26 -36
- package/snapdom/src/api/snapdom.js +78 -61
- package/snapdom/src/core/capture.js +54 -54
- package/snapdom/src/core/prepare.js +46 -37
- package/snapdom/src/modules/fonts.js +90 -92
- package/snapdom/src/modules/iconFonts.js +28 -0
- package/snapdom/src/modules/images.js +6 -6
- package/snapdom/src/modules/pseudo.js +51 -49
- package/snapdom/src/modules/styles.js +27 -7
- package/snapdom/src/modules/svgDefs.js +26 -0
- package/snapdom/src/utils/helpers.js +150 -103
- package/snapdom.js +6 -0
- package/tinycolor/index.js +46 -0
- package/tinycolor/src/conversion.js +143 -0
- package/tinycolor/src/css-color-names.js +153 -0
- package/tinycolor/src/format-input.js +77 -0
- package/tinycolor/src/from-ratio.js +21 -0
- package/tinycolor/src/index.js +404 -0
- package/tinycolor/src/random.js +221 -0
- package/tinycolor/src/readability.js +37 -0
- package/tinycolor/src/to-ms-filter.js +15 -0
- package/tinycolor/src/util.js +32 -0
- package/tinycolor.js +46 -0
- package/tree/index.js +10 -8
- package/tree/searchTree.js +54 -0
- package/tree.js +13 -0
- package/turboStream.js +6 -0
- package/types/case-name/index.d.ts +11 -0
- package/types/class-name/index.d.ts +2 -0
- package/types/clipboard-copy/index.d.ts +2 -0
- package/types/constant/address.d.ts +14 -0
- package/types/constant/chineseCharacters.d.ts +2 -0
- package/types/constant/constellations.d.ts +2 -0
- package/types/constant/domain.d.ts +2 -0
- package/types/constant/identity.d.ts +2 -0
- package/types/constant/index.d.ts +1 -0
- package/types/constant/keyboardCode.d.ts +158 -0
- package/types/constant/licensePlate.d.ts +2 -0
- package/types/constant/name.d.ts +4 -0
- package/types/constant/platform.d.ts +11 -0
- package/types/constant/protocol.d.ts +2 -0
- package/types/constant/ui.d.ts +14 -0
- package/types/content-disposition/index.d.ts +10 -0
- package/types/cookie/index.d.ts +4 -0
- package/types/cookie/src/index.d.ts +114 -0
- package/types/date/convertTime.d.ts +32 -0
- package/types/date/index.d.ts +4 -0
- package/types/decimal/decimal.d.ts +4 -0
- package/types/decimal/index.d.ts +1 -0
- package/types/event-emitter/index.d.ts +17 -0
- package/types/file/fileToURL.d.ts +2 -0
- package/types/file/index.d.ts +3 -0
- package/types/file/saveAs.d.ts +2 -0
- package/types/filesize/index.d.ts +2 -0
- package/types/filesize/src/constants.d.ts +42 -0
- package/types/filesize/src/filesize.d.ts +47 -0
- package/types/index.d.ts +25 -0
- package/types/invariant/index.d.ts +2 -0
- package/types/is/index.d.ts +53 -0
- package/types/lunar/index.d.ts +3 -0
- package/types/lunar/lib/Holiday.d.ts +17 -0
- package/types/lunar/lib/HolidayUtil.d.ts +23 -0
- package/types/lunar/lib/I18n.d.ts +23 -0
- package/types/lunar/lib/JieQi.d.ts +15 -0
- package/types/lunar/lib/Lunar.d.ts +245 -0
- package/types/lunar/lib/LunarMonth.d.ts +35 -0
- package/types/lunar/lib/LunarTime.d.ts +40 -0
- package/types/lunar/lib/LunarUtil.d.ts +128 -0
- package/types/lunar/lib/LunarYear.d.ts +61 -0
- package/types/lunar/lib/ShouXingUtil.d.ts +38 -0
- package/types/lunar/lib/Solar.d.ts +51 -0
- package/types/lunar/lib/SolarHalfYear.d.ts +15 -0
- package/types/lunar/lib/SolarMonth.d.ts +16 -0
- package/types/lunar/lib/SolarSeason.d.ts +15 -0
- package/types/lunar/lib/SolarUtil.d.ts +20 -0
- package/types/lunar/lib/SolarWeek.d.ts +23 -0
- package/types/lunar/lib/SolarYear.d.ts +12 -0
- package/types/lunar/lib/index.d.ts +17 -0
- package/types/math/index.d.ts +11 -0
- package/types/md5/index.d.ts +2 -0
- package/types/mock/MockWebSocket.d.ts +17 -0
- package/types/mock/MockXMLHttpRequest.d.ts +17 -0
- package/types/mock/index.d.ts +2 -0
- package/types/normalize-wheel/ExecutionEnvironment.d.ts +9 -0
- package/types/normalize-wheel/UserAgent_DEPRECATED.d.ts +86 -0
- package/types/normalize-wheel/index.d.ts +115 -0
- package/types/normalize-wheel/isEventSupported.d.ts +16 -0
- package/types/number-to-chinese/index.d.ts +11 -0
- package/types/nzh/cn.d.ts +8 -0
- package/types/nzh/hk.d.ts +8 -0
- package/types/nzh/index.d.ts +1 -0
- package/types/nzh/nzh.d.ts +36 -0
- package/types/nzh/src/autoGet.d.ts +8 -0
- package/types/nzh/src/index.d.ts +34 -0
- package/types/nzh/src/langs/cn_b.d.ts +10 -0
- package/types/nzh/src/langs/cn_s.d.ts +7 -0
- package/types/nzh/src/langs/hk_b.d.ts +10 -0
- package/types/nzh/src/langs/hk_s.d.ts +7 -0
- package/types/nzh/src/utils.d.ts +65 -0
- package/types/object-keys-sort/index.d.ts +4 -0
- package/types/random/address.d.ts +8 -0
- package/types/random/constellation.d.ts +2 -0
- package/types/random/image.d.ts +5 -0
- package/types/random/index.d.ts +40 -0
- package/types/random/licensePlate.d.ts +2 -0
- package/types/random/name.d.ts +9 -0
- package/types/random/number.d.ts +6 -0
- package/types/random/text.d.ts +13 -0
- package/types/random/time.d.ts +2 -0
- package/types/random/web.d.ts +11 -0
- package/types/screenfull/index.d.ts +10 -0
- package/types/snapdom/index.d.ts +1 -0
- package/types/snapdom/src/api/preCache.d.ts +8 -0
- package/types/snapdom/src/api/snapdom.d.ts +26 -0
- package/types/snapdom/src/core/cache.d.ts +11 -0
- package/types/snapdom/src/core/capture.d.ts +17 -0
- package/types/snapdom/src/core/clone.d.ts +11 -0
- package/types/snapdom/src/core/prepare.d.ts +8 -0
- package/types/snapdom/src/index.browser.d.ts +1 -0
- package/types/snapdom/src/index.d.ts +2 -0
- package/types/snapdom/src/modules/background.d.ts +10 -0
- package/types/snapdom/src/modules/fonts.d.ts +23 -0
- package/types/snapdom/src/modules/iconFonts.d.ts +2 -0
- package/types/snapdom/src/modules/images.d.ts +8 -0
- package/types/snapdom/src/modules/pseudo.d.ts +12 -0
- package/types/snapdom/src/modules/styles.d.ts +1 -0
- package/types/snapdom/src/modules/svgDefs.d.ts +19 -0
- package/types/snapdom/src/utils/cssTools.d.ts +38 -0
- package/types/snapdom/src/utils/helpers.d.ts +71 -0
- package/types/tinycolor/index.d.ts +2 -0
- package/types/tinycolor/src/conversion.d.ts +79 -0
- package/types/tinycolor/src/css-color-names.d.ts +4 -0
- package/types/tinycolor/src/format-input.d.ts +38 -0
- package/types/tinycolor/src/from-ratio.d.ts +14 -0
- package/types/tinycolor/src/index.d.ts +214 -0
- package/types/tinycolor/src/interfaces.d.ts +57 -0
- package/types/tinycolor/src/public_api.d.ts +10 -0
- package/types/tinycolor/src/random.d.ts +24 -0
- package/types/tinycolor/src/readability.d.ts +46 -0
- package/types/tinycolor/src/to-ms-filter.d.ts +5 -0
- package/types/tinycolor/src/umd_api.d.ts +22 -0
- package/types/tinycolor/src/util.d.ts +36 -0
- package/types/tree/index.d.ts +9 -0
- package/types/tree/searchTree.d.ts +20 -0
- package/types/turbo-stream/index.d.ts +1 -0
- package/types/turbo-stream/src/decode.d.ts +7 -0
- package/types/turbo-stream/src/encode.d.ts +27 -0
- package/types/turbo-stream/src/shared.d.ts +107 -0
- package/types/turbo-stream/src/turbo-stream.d.ts +4 -0
- package/types/ui-color/compareColorByRange.d.ts +2 -0
- package/types/ui-color/index.d.ts +183 -0
- package/types/url-toolkit/index.d.ts +2 -0
- package/types/url-toolkit/src/url-toolkit.d.ts +18 -0
- package/ui-color/compareColorByRange.js +9 -0
- package/ui-color/index.js +155 -0
- package/uiColor.js +28 -0
- package/urlToolkit.js +8 -0
- package/dayjs/index.js +0 -15
|
@@ -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
|
+
};
|