@design-edito/tools 0.2.15 → 0.2.17
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/agnostic/arrays/index.js +8 -8
- package/agnostic/arrays/random-pick/index.js +4 -4
- package/agnostic/colors/channels/index.d.ts +5 -0
- package/agnostic/colors/channels/index.js +18 -0
- package/agnostic/colors/contrast/index.d.ts +2 -0
- package/agnostic/colors/contrast/index.js +13 -0
- package/agnostic/colors/convert/index.d.ts +20 -0
- package/agnostic/colors/convert/index.js +45 -0
- package/agnostic/colors/distance/index.d.ts +2 -0
- package/agnostic/colors/distance/index.js +12 -0
- package/agnostic/colors/grayscale/index.d.ts +2 -0
- package/agnostic/colors/grayscale/index.js +12 -0
- package/agnostic/colors/index.d.ts +14 -16
- package/agnostic/colors/index.js +95 -27
- package/agnostic/colors/invert/index.d.ts +2 -0
- package/agnostic/colors/invert/index.js +12 -0
- package/agnostic/colors/lerp/index.d.ts +2 -0
- package/agnostic/colors/lerp/index.js +12 -0
- package/agnostic/colors/luminance/index.d.ts +2 -0
- package/agnostic/colors/luminance/index.js +12 -0
- package/agnostic/colors/palette/index.d.ts +2 -0
- package/agnostic/colors/palette/index.js +14 -0
- package/agnostic/colors/rotate/index.d.ts +2 -0
- package/agnostic/colors/rotate/index.js +13 -0
- package/agnostic/colors/tidy/index.d.ts +2 -0
- package/agnostic/colors/tidy/index.js +11 -0
- package/agnostic/colors/typechecks/index.d.ts +11 -0
- package/agnostic/colors/typechecks/index.js +26 -0
- package/agnostic/colors/types.d.ts +82 -0
- package/agnostic/css/index.js +12 -12
- package/agnostic/css/styles-set/index.js +6 -6
- package/agnostic/html/hyper-json/cast/index.js +7 -7
- package/agnostic/html/hyper-json/index.js +8 -8
- package/agnostic/html/hyper-json/smart-tags/coalesced/add/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/addclass/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/and/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/append/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/at/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/call/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/clone/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/deleteproperties/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/equals/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/getattribute/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/getproperties/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/getproperty/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/if/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/initialize/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/join/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/length/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/map/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/negate/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/notrailing/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/or/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/pickrandom/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/populate/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/print/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/push/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/pusheach/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/recordtoarray/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/removeattribute/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/removeclass/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/renameproperty/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/replace/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/select/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/set/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/setattribute/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/setproperty/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/sorton/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/split/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/spread/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/toarray/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/toboolean/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/toelement/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/toggleclass/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/tonodelist/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/tonull/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/tonumber/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/torecord/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/toref/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/tostring/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/totext/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/transformselected/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/coalesced/trim/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/isolated/boolean/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/isolated/element/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/isolated/get/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/isolated/global/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/isolated/guess/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/isolated/nodelist/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/isolated/number/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/isolated/record/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/isolated/ref/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/isolated/string/index.js +7 -7
- package/agnostic/html/hyper-json/smart-tags/isolated/text/index.js +7 -7
- package/agnostic/html/hyper-json/tree/index.js +7 -7
- package/agnostic/html/hyper-json/utils/index.js +7 -7
- package/agnostic/html/index.js +21 -21
- package/agnostic/html/sanitize/index.js +4 -4
- package/agnostic/html/selector-to-element/index.js +4 -4
- package/agnostic/html/string-to-nodes/index.js +5 -5
- package/agnostic/index.d.ts +1 -1
- package/agnostic/misc/crossenv/index.js +2 -2
- package/agnostic/misc/index.js +27 -27
- package/agnostic/misc/logs/index.js +2 -2
- package/agnostic/misc/lorem-ipsum/index.js +11 -11
- package/agnostic/numbers/index.js +9 -9
- package/agnostic/objects/index.js +8 -8
- package/agnostic/random/index.js +2 -2
- package/agnostic/strings/index.js +7 -7
- package/agnostic/time/index.js +6 -6
- package/chunks/chunk-2EHYEUX4.js +21 -0
- package/chunks/chunk-5LK2YLTK.js +21 -0
- package/chunks/chunk-65NTXENV.js +157 -0
- package/chunks/chunk-ALMK24GK.js +0 -0
- package/chunks/{chunk-B446JIN3.js → chunk-AQBJ6HNB.js} +1 -1
- package/chunks/chunk-BKIF2ELV.js +47 -0
- package/chunks/chunk-D7SXHHU3.js +47 -0
- package/chunks/chunk-GUBFCOBT.js +98 -0
- package/chunks/{chunk-XDITZ5QN.js → chunk-HONCMQHQ.js} +2 -2
- package/chunks/{chunk-YIZODJC7.js → chunk-IAOZM4EN.js} +5 -5
- package/chunks/chunk-IDXUS2IO.js +296 -0
- package/chunks/chunk-ISUDTAMN.js +101 -0
- package/chunks/{chunk-GVQVGFAA.js → chunk-J4WGYUFY.js} +4 -4
- package/chunks/{chunk-Q6DUKZU6.js → chunk-JJ7DN7NN.js} +7 -7
- package/chunks/{chunk-EDJ3TVNV.js → chunk-KDOMQ4LM.js} +15 -6
- package/chunks/{chunk-TSZAQ3RQ.js → chunk-L5VJAZVW.js} +90 -91
- package/chunks/chunk-MN4FVOU2.js +28 -0
- package/chunks/{chunk-IOJTC6CN.js → chunk-O7VEAOGY.js} +22 -22
- package/chunks/{chunk-2M33FCDG.js → chunk-O7VFJHQX.js} +11 -5
- package/chunks/chunk-P4YT4RBG.js +51 -0
- package/chunks/{chunk-2UAVBQI5.js → chunk-QJXJT5JS.js} +4 -4
- package/chunks/{chunk-FQ4UTWMP.js → chunk-QTA7ZEVX.js} +3 -1
- package/chunks/chunk-QW34TQCS.js +48 -0
- package/chunks/{chunk-HMAK6VAF.js → chunk-RBCZWVQH.js} +11 -5
- package/chunks/{chunk-IWDIKDYR.js → chunk-RBH5MYJ7.js} +17 -17
- package/chunks/{chunk-AI6AGF4I.js → chunk-S7637BQZ.js} +8 -5
- package/chunks/{chunk-SA2IY5LN.js → chunk-SKBOSWM2.js} +1 -1
- package/chunks/{chunk-CYUEPBUN.js → chunk-STW5RKR7.js} +2 -2
- package/chunks/{chunk-CHUOCTRP.js → chunk-TIER4TF4.js} +1 -1
- package/chunks/chunk-UG5EMKGN.js +265 -0
- package/chunks/chunk-VA67YLZL.js +26 -0
- package/chunks/chunk-XAYMIITK.js +103 -0
- package/chunks/{chunk-JWF5EKM2.js → chunk-XB3EGDBI.js} +1 -1
- package/chunks/chunk-YZVZKBVJ.js +631 -0
- package/chunks/{chunk-36CTYZYA.js → chunk-ZBBU2P4D.js} +2 -2
- package/chunks/chunk-ZJ63OCMA.js +207 -0
- package/node/@aws-s3/index.js +9 -9
- package/node/@aws-s3/storage/directory/index.js +7 -7
- package/node/@aws-s3/storage/file/index.js +13 -13
- package/node/@aws-s3/storage/index.js +11 -11
- package/node/@google-cloud/index.js +14 -14
- package/node/@google-cloud/storage/bucket/index.js +4 -4
- package/node/@google-cloud/storage/directory/index.js +7 -7
- package/node/@google-cloud/storage/file/index.js +18 -18
- package/node/@google-cloud/storage/file/revoke-signed-urls/index.js +2 -2
- package/node/@google-cloud/storage/index.js +16 -16
- package/node/cloud-storage/index.js +41 -41
- package/node/cloud-storage/operations/copy-dir/index.js +2 -2
- package/node/cloud-storage/operations/copy-file/index.js +2 -2
- package/node/cloud-storage/operations/download-file/index.js +2 -2
- package/node/cloud-storage/operations/exists-file/index.js +2 -2
- package/node/cloud-storage/operations/index.js +53 -53
- package/node/cloud-storage/operations/list-dir/index.js +2 -2
- package/node/cloud-storage/operations/move-dir/index.js +2 -2
- package/node/cloud-storage/operations/move-file/index.js +2 -2
- package/node/cloud-storage/operations/remove-dir/index.js +2 -2
- package/node/cloud-storage/operations/remove-file/index.js +2 -2
- package/node/cloud-storage/operations/stat-file/index.js +2 -2
- package/node/cloud-storage/operations/upload-file/index.js +2 -2
- package/node/encryption/index.js +3 -3
- package/node/ftps/directory/index.js +7 -7
- package/node/ftps/file/index.js +13 -13
- package/node/ftps/index.js +10 -10
- package/node/images/create/index.d.ts +3 -0
- package/node/images/create/index.js +23 -0
- package/node/images/format/index.d.ts +17 -51
- package/node/images/format/index.js +30 -4
- package/node/images/index.d.ts +4 -2
- package/node/images/index.js +41 -21
- package/node/images/metadata/index.d.ts +3 -0
- package/node/images/metadata/index.js +23 -0
- package/node/images/transform/index.d.ts +2 -97
- package/node/images/transform/index.js +27 -16
- package/node/images/transform/operations/blur/index.d.ts +1 -3
- package/node/images/transform/operations/brighten/index.d.ts +1 -3
- package/node/images/transform/operations/extend/index.d.ts +1 -8
- package/node/images/transform/operations/extend/index.js +17 -2
- package/node/images/transform/operations/extract/index.d.ts +1 -6
- package/node/images/transform/operations/flatten/index.d.ts +1 -3
- package/node/images/transform/operations/flatten/index.js +17 -2
- package/node/images/transform/operations/hue/index.d.ts +1 -3
- package/node/images/transform/operations/level/index.d.ts +1 -4
- package/node/images/transform/operations/lighten/index.d.ts +1 -3
- package/node/images/transform/operations/normalize/index.d.ts +1 -4
- package/node/images/transform/operations/overlay/index.d.ts +5 -0
- package/node/images/transform/operations/overlay/index.js +27 -0
- package/node/images/transform/operations/resize/index.d.ts +1 -11
- package/node/images/transform/operations/resize/index.js +17 -2
- package/node/images/transform/operations/rotate/index.d.ts +1 -4
- package/node/images/transform/operations/rotate/index.js +17 -2
- package/node/images/transform/operations/saturate/index.d.ts +1 -3
- package/node/images/transform/operations/saturate/index.js +1 -1
- package/node/images/types.d.ts +252 -0
- package/node/images/utils/index.d.ts +7 -0
- package/node/images/utils/index.js +28 -0
- package/node/sftp/directory/index.js +7 -7
- package/node/sftp/file/index.js +13 -13
- package/node/sftp/index.js +10 -10
- package/package.json +1 -1
- package/agnostic/colors/complement-color/index.d.ts +0 -1
- package/agnostic/colors/complement-color/index.js +0 -7
- package/agnostic/colors/hex-to-rgb/index.d.ts +0 -1
- package/agnostic/colors/hex-to-rgb/index.js +0 -7
- package/agnostic/colors/hsl-to-rgb/index.d.ts +0 -1
- package/agnostic/colors/hsl-to-rgb/index.js +0 -7
- package/agnostic/colors/lighten-color/index.d.ts +0 -2
- package/agnostic/colors/lighten-color/index.js +0 -11
- package/agnostic/colors/rgb-to-hex/index.d.ts +0 -1
- package/agnostic/colors/rgb-to-hex/index.js +0 -7
- package/agnostic/colors/rgb-to-hsl/index.d.ts +0 -1
- package/agnostic/colors/rgb-to-hsl/index.js +0 -7
- package/agnostic/colors/saturate-color/index.d.ts +0 -2
- package/agnostic/colors/saturate-color/index.js +0 -11
- package/chunks/chunk-2POD3TAX.js +0 -11
- package/chunks/chunk-2TJCB6IM.js +0 -12
- package/chunks/chunk-7EDDWSWS.js +0 -123
- package/chunks/chunk-FAXNZG5C.js +0 -10
- package/chunks/chunk-IFQA5PWI.js +0 -112
- package/chunks/chunk-MB7HWF22.js +0 -23
- package/chunks/chunk-MFYNJMVM.js +0 -18
- package/chunks/chunk-NYVARFI7.js +0 -20
- package/chunks/chunk-QLC3A6PC.js +0 -17
- package/chunks/chunk-U57Q62IN.js +0 -23
- package/chunks/chunk-YVLJKJV2.js +0 -17
- package/node/images/get-metadata/index.d.ts +0 -4
- package/node/images/get-metadata/index.js +0 -7
- package/node/images/transform/operations/composite/index.d.ts +0 -7
- package/node/images/transform/operations/composite/index.js +0 -12
- package/node/images/transform/utils/index.d.ts +0 -2
- package/node/images/transform/utils/index.js +0 -8
- package/chunks/{chunk-LAVXHKKR.js → chunk-2DW5MV3U.js} +12 -12
- package/chunks/{chunk-QCMBG5LN.js → chunk-7SZXDQVJ.js} +16 -16
- package/chunks/{chunk-74CFPDKM.js → chunk-A7K5DUP7.js} +6 -6
- package/chunks/{chunk-DEQWCMAL.js → chunk-ASCJDM27.js} +12 -12
- package/chunks/{chunk-646R6BQZ.js → chunk-CGITTQIW.js} +3 -3
- package/chunks/{chunk-7KSMK42F.js → chunk-CNMP2GU4.js} +6 -6
- package/chunks/{chunk-EOTOFHUR.js → chunk-D7PZ7633.js} +3 -3
- package/chunks/{chunk-UFKH5WD2.js → chunk-FR5H2OCV.js} +3 -3
- package/chunks/{chunk-FS6LRTDK.js → chunk-HX5PHI2P.js} +3 -3
- package/chunks/{chunk-CA3UPHYO.js → chunk-JNQPNZTB.js} +3 -3
- package/chunks/{chunk-G5RRNREY.js → chunk-LSZVKXDZ.js} +3 -3
- package/chunks/{chunk-MJQF3YZO.js → chunk-QN3UAKIU.js} +3 -3
- package/chunks/{chunk-DPQRXSZH.js → chunk-RXBMGIPJ.js} +3 -3
- package/chunks/{chunk-OVG5RGI3.js → chunk-S32K7POB.js} +4 -4
- package/chunks/{chunk-Y4THX4AN.js → chunk-TFZOOTCF.js} +3 -3
- package/chunks/{chunk-UXEKCYL7.js → chunk-UEAMPAHK.js} +3 -3
- package/chunks/{chunk-24ZUWYIR.js → chunk-UX2O74SG.js} +3 -3
- package/chunks/{chunk-AIC5YAJU.js → chunk-X5F6XGEP.js} +6 -6
- package/chunks/{chunk-JSW6R3ZH.js → chunk-X5VXP4GS.js} +12 -12
- package/chunks/{chunk-OA7Y2A5T.js → chunk-XNWEMAIP.js} +3 -3
- package/chunks/{chunk-UK4HNSEJ.js → chunk-YVWQXQTE.js} +3 -3
- package/chunks/{chunk-4OK2UH4M.js → chunk-ZBAKY6DB.js} +6 -6
- package/chunks/{chunk-6NLNUGBI.js → chunk-ZQY2MR66.js} +3 -3
- package/chunks/{chunk-NOLQR5RW.js → chunk-ZUQEHFGL.js} +3 -3
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
import {
|
|
2
|
+
absoluteModulo
|
|
3
|
+
} from "./chunk-DNIOWD7K.js";
|
|
4
|
+
import {
|
|
5
|
+
clamp
|
|
6
|
+
} from "./chunk-OSAXBA7G.js";
|
|
7
|
+
import {
|
|
8
|
+
cssColors,
|
|
9
|
+
isCmyk,
|
|
10
|
+
isCssColor,
|
|
11
|
+
isHex,
|
|
12
|
+
isHsb,
|
|
13
|
+
isHsl,
|
|
14
|
+
isLab,
|
|
15
|
+
isLch,
|
|
16
|
+
isRgb,
|
|
17
|
+
isXyz
|
|
18
|
+
} from "./chunk-UG5EMKGN.js";
|
|
19
|
+
|
|
20
|
+
// src/agnostic/colors/convert/index.ts
|
|
21
|
+
function _hex2rgb(hex) {
|
|
22
|
+
if (!isHex(hex)) throw new Error(`invalid hex color ${hex}`);
|
|
23
|
+
let hexString = hex;
|
|
24
|
+
const inputHex = hexString;
|
|
25
|
+
const startsWithHash = hexString.startsWith("#");
|
|
26
|
+
if (!startsWithHash) throw new Error(`invalid hex color ${inputHex}`);
|
|
27
|
+
hexString = hexString.slice(1);
|
|
28
|
+
if (hexString.length === 3) {
|
|
29
|
+
hexString = hexString.split("").map((c) => c + c).join("") + "ff";
|
|
30
|
+
} else if (hexString.length === 4) {
|
|
31
|
+
hexString = hexString.split("").map((c) => c + c).join("");
|
|
32
|
+
} else if (hexString.length === 6) {
|
|
33
|
+
hexString = hexString + "ff";
|
|
34
|
+
} else if (hexString.length === 8) {
|
|
35
|
+
hexString = hexString;
|
|
36
|
+
} else throw new Error(`invalid hex color ${inputHex}`);
|
|
37
|
+
const r = parseInt(hexString.slice(0, 2), 16);
|
|
38
|
+
const g = parseInt(hexString.slice(2, 4), 16);
|
|
39
|
+
const b = parseInt(hexString.slice(4, 6), 16);
|
|
40
|
+
const a = parseInt(hexString.slice(6, 8), 16) / 255;
|
|
41
|
+
return { r, g, b, a };
|
|
42
|
+
}
|
|
43
|
+
function _rgb2hex(rgb) {
|
|
44
|
+
const { r, g, b, a = 1 } = rgb;
|
|
45
|
+
const rHex = Math.round(r).toString(16).padStart(2, "0");
|
|
46
|
+
const gHex = Math.round(g).toString(16).padStart(2, "0");
|
|
47
|
+
const bHex = Math.round(b).toString(16).padStart(2, "0");
|
|
48
|
+
const aHex = Math.round(a * 255).toString(16).padStart(2, "0");
|
|
49
|
+
const returned = `#${rHex}${gHex}${bHex}${aHex}`;
|
|
50
|
+
if (!isHex(returned)) {
|
|
51
|
+
throw new Error(`invalid hex color output ${returned}`);
|
|
52
|
+
}
|
|
53
|
+
return returned;
|
|
54
|
+
}
|
|
55
|
+
function _css2rgb(color) {
|
|
56
|
+
if (color in cssColors) return cssColors[color];
|
|
57
|
+
return void 0;
|
|
58
|
+
}
|
|
59
|
+
var cssColorsWithHex = Object.entries(cssColors).map(([cssColor, rgba]) => ({
|
|
60
|
+
name: cssColor,
|
|
61
|
+
hex: _rgb2hex(rgba),
|
|
62
|
+
rgba
|
|
63
|
+
}));
|
|
64
|
+
function _rgb2css(rgb) {
|
|
65
|
+
const hexTarget = _rgb2hex(rgb);
|
|
66
|
+
return cssColorsWithHex.find((c) => c.hex === hexTarget)?.name;
|
|
67
|
+
}
|
|
68
|
+
function _hsl2rgb(hsl) {
|
|
69
|
+
const { h, s, l, a = 1 } = hsl;
|
|
70
|
+
const H = absoluteModulo(h, 360) / 360;
|
|
71
|
+
const S = Math.max(0, Math.min(1, s / 100));
|
|
72
|
+
const L = Math.max(0, Math.min(1, l / 100));
|
|
73
|
+
const A = Math.max(0, Math.min(1, a));
|
|
74
|
+
const hue2rgb = (p, q, t) => {
|
|
75
|
+
if (t < 0) t += 1;
|
|
76
|
+
if (t > 1) t -= 1;
|
|
77
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
78
|
+
if (t < 1 / 2) return q;
|
|
79
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
80
|
+
return p;
|
|
81
|
+
};
|
|
82
|
+
let r;
|
|
83
|
+
let g;
|
|
84
|
+
let b;
|
|
85
|
+
if (S === 0) {
|
|
86
|
+
r = g = b = L;
|
|
87
|
+
} else {
|
|
88
|
+
const q = L < 0.5 ? L * (1 + S) : L + S - L * S;
|
|
89
|
+
const p = 2 * L - q;
|
|
90
|
+
r = hue2rgb(p, q, H + 1 / 3);
|
|
91
|
+
g = hue2rgb(p, q, H);
|
|
92
|
+
b = hue2rgb(p, q, H - 1 / 3);
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
r: Math.round(r * 255),
|
|
96
|
+
g: Math.round(g * 255),
|
|
97
|
+
b: Math.round(b * 255),
|
|
98
|
+
a: A
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function _rgb2hsl(rgb) {
|
|
102
|
+
const { r, g, b, a = 1 } = rgb;
|
|
103
|
+
const R = r / 255;
|
|
104
|
+
const G = g / 255;
|
|
105
|
+
const B = b / 255;
|
|
106
|
+
const max = Math.max(R, G, B);
|
|
107
|
+
const min = Math.min(R, G, B);
|
|
108
|
+
const delta = max - min;
|
|
109
|
+
let h = 0;
|
|
110
|
+
let s = 0;
|
|
111
|
+
const l = (max + min) / 2;
|
|
112
|
+
if (delta !== 0) {
|
|
113
|
+
s = l > 0.5 ? delta / (2 - max - min) : delta / (max + min);
|
|
114
|
+
if (max === R) {
|
|
115
|
+
h = ((G - B) / delta + (G < B ? 6 : 0)) / 6;
|
|
116
|
+
} else if (max === G) {
|
|
117
|
+
h = ((B - R) / delta + 2) / 6;
|
|
118
|
+
} else {
|
|
119
|
+
h = ((R - G) / delta + 4) / 6;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
h: Math.round(h * 360),
|
|
124
|
+
s: Math.round(s * 100),
|
|
125
|
+
l: Math.round(l * 100),
|
|
126
|
+
a
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function _hsb2rgb(hsb) {
|
|
130
|
+
const { h, s, b, a = 1 } = hsb;
|
|
131
|
+
const H = absoluteModulo(h, 360) / 360;
|
|
132
|
+
const S = Math.max(0, Math.min(1, s / 100));
|
|
133
|
+
const B = Math.max(0, Math.min(1, b / 100));
|
|
134
|
+
const A = Math.max(0, Math.min(1, a));
|
|
135
|
+
const i = Math.floor(H * 6);
|
|
136
|
+
const f = H * 6 - i;
|
|
137
|
+
const p = B * (1 - S);
|
|
138
|
+
const q = B * (1 - f * S);
|
|
139
|
+
const t = B * (1 - (1 - f) * S);
|
|
140
|
+
let r;
|
|
141
|
+
let g;
|
|
142
|
+
let blue;
|
|
143
|
+
switch (absoluteModulo(i, 6)) {
|
|
144
|
+
case 0:
|
|
145
|
+
r = B;
|
|
146
|
+
g = t;
|
|
147
|
+
blue = p;
|
|
148
|
+
break;
|
|
149
|
+
case 1:
|
|
150
|
+
r = q;
|
|
151
|
+
g = B;
|
|
152
|
+
blue = p;
|
|
153
|
+
break;
|
|
154
|
+
case 2:
|
|
155
|
+
r = p;
|
|
156
|
+
g = B;
|
|
157
|
+
blue = t;
|
|
158
|
+
break;
|
|
159
|
+
case 3:
|
|
160
|
+
r = p;
|
|
161
|
+
g = q;
|
|
162
|
+
blue = B;
|
|
163
|
+
break;
|
|
164
|
+
case 4:
|
|
165
|
+
r = t;
|
|
166
|
+
g = p;
|
|
167
|
+
blue = B;
|
|
168
|
+
break;
|
|
169
|
+
case 5:
|
|
170
|
+
r = B;
|
|
171
|
+
g = p;
|
|
172
|
+
blue = q;
|
|
173
|
+
break;
|
|
174
|
+
default:
|
|
175
|
+
r = g = blue = 0;
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
r: Math.round(r * 255),
|
|
179
|
+
g: Math.round(g * 255),
|
|
180
|
+
b: Math.round(blue * 255),
|
|
181
|
+
a: A
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function _rgb2hsb(rgb) {
|
|
185
|
+
const { r, g, b, a = 1 } = rgb;
|
|
186
|
+
const R = r / 255;
|
|
187
|
+
const G = g / 255;
|
|
188
|
+
const B = b / 255;
|
|
189
|
+
const max = Math.max(R, G, B);
|
|
190
|
+
const min = Math.min(R, G, B);
|
|
191
|
+
const delta = max - min;
|
|
192
|
+
let h = 0;
|
|
193
|
+
let s = 0;
|
|
194
|
+
const brightness = max;
|
|
195
|
+
if (max !== 0) {
|
|
196
|
+
s = delta / max;
|
|
197
|
+
}
|
|
198
|
+
if (delta !== 0) {
|
|
199
|
+
if (max === R) {
|
|
200
|
+
h = ((G - B) / delta + (G < B ? 6 : 0)) / 6;
|
|
201
|
+
} else if (max === G) {
|
|
202
|
+
h = ((B - R) / delta + 2) / 6;
|
|
203
|
+
} else {
|
|
204
|
+
h = ((R - G) / delta + 4) / 6;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
h: Math.round(h * 360),
|
|
209
|
+
s: Math.round(s * 100),
|
|
210
|
+
b: Math.round(brightness * 100),
|
|
211
|
+
a
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function _cmyk2rgb(cmyka) {
|
|
215
|
+
const { c, m, y, k, a = 1 } = cmyka;
|
|
216
|
+
const C = Math.max(0, Math.min(100, c)) / 100;
|
|
217
|
+
const M = Math.max(0, Math.min(100, m)) / 100;
|
|
218
|
+
const Y = Math.max(0, Math.min(100, y)) / 100;
|
|
219
|
+
const K = Math.max(0, Math.min(100, k)) / 100;
|
|
220
|
+
const A = Math.max(0, Math.min(1, a));
|
|
221
|
+
const R = 1 - Math.min(1, C * (1 - K) + K);
|
|
222
|
+
const G = 1 - Math.min(1, M * (1 - K) + K);
|
|
223
|
+
const B = 1 - Math.min(1, Y * (1 - K) + K);
|
|
224
|
+
return {
|
|
225
|
+
r: Math.round(R * 255),
|
|
226
|
+
g: Math.round(G * 255),
|
|
227
|
+
b: Math.round(B * 255),
|
|
228
|
+
a: A
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function _rgb2cmyk(rgb) {
|
|
232
|
+
const { r, g, b, a = 1 } = rgb;
|
|
233
|
+
const R = Math.max(0, Math.min(1, r / 255));
|
|
234
|
+
const G = Math.max(0, Math.min(1, g / 255));
|
|
235
|
+
const B = Math.max(0, Math.min(1, b / 255));
|
|
236
|
+
const A = Math.max(0, Math.min(1, a));
|
|
237
|
+
const K = 1 - Math.max(R, G, B);
|
|
238
|
+
const denom = 1 - K || 1;
|
|
239
|
+
const C = (1 - R - K) / denom;
|
|
240
|
+
const M = (1 - G - K) / denom;
|
|
241
|
+
const Y = (1 - B - K) / denom;
|
|
242
|
+
return {
|
|
243
|
+
c: Math.round(C * 100),
|
|
244
|
+
m: Math.round(M * 100),
|
|
245
|
+
y: Math.round(Y * 100),
|
|
246
|
+
k: Math.round(K * 100),
|
|
247
|
+
a: A
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function _xyz2rgb(xyza) {
|
|
251
|
+
const { x, y, z, a = 1 } = xyza;
|
|
252
|
+
const X = x / 100;
|
|
253
|
+
const Y = y / 100;
|
|
254
|
+
const Z = z / 100;
|
|
255
|
+
const A = Math.max(0, Math.min(1, a));
|
|
256
|
+
let R = X * 3.2404542 + Y * -1.5371385 + Z * -0.4985314;
|
|
257
|
+
let G = X * -0.969266 + Y * 1.8760108 + Z * 0.041556;
|
|
258
|
+
let B = X * 0.0556434 + Y * -0.2040259 + Z * 1.0572252;
|
|
259
|
+
const GAMMA_THRESHOLD = 31308e-7;
|
|
260
|
+
const GAMMA_EXPONENT = 1 / 2.4;
|
|
261
|
+
const GAMMA_MULT = 1.055;
|
|
262
|
+
const GAMMA_OFFSET = 0.055;
|
|
263
|
+
const LINEAR_DIVISOR = 12.92;
|
|
264
|
+
const gammaCorrect = (c) => c <= GAMMA_THRESHOLD ? c * LINEAR_DIVISOR : GAMMA_MULT * Math.pow(c, GAMMA_EXPONENT) - GAMMA_OFFSET;
|
|
265
|
+
R = gammaCorrect(R);
|
|
266
|
+
G = gammaCorrect(G);
|
|
267
|
+
B = gammaCorrect(B);
|
|
268
|
+
return {
|
|
269
|
+
r: Math.round(Math.max(0, Math.min(1, R)) * 255),
|
|
270
|
+
g: Math.round(Math.max(0, Math.min(1, G)) * 255),
|
|
271
|
+
b: Math.round(Math.max(0, Math.min(1, B)) * 255),
|
|
272
|
+
a: A
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function _rgb2xyz(rgb) {
|
|
276
|
+
const { r, g, b, a = 1 } = rgb;
|
|
277
|
+
let R = Math.max(0, Math.min(1, r / 255));
|
|
278
|
+
let G = Math.max(0, Math.min(1, g / 255));
|
|
279
|
+
let B = Math.max(0, Math.min(1, b / 255));
|
|
280
|
+
const A = Math.max(0, Math.min(1, a));
|
|
281
|
+
const SRGB_THRESHOLD = 0.04045;
|
|
282
|
+
const SRGB_OFFSET = 0.055;
|
|
283
|
+
const SRGB_DIVISOR = 1.055;
|
|
284
|
+
const SRGB_EXPONENT = 2.4;
|
|
285
|
+
const SRGB_LINEAR_DIVISOR = 12.92;
|
|
286
|
+
const linearize = (c) => c > SRGB_THRESHOLD ? Math.pow((c + SRGB_OFFSET) / SRGB_DIVISOR, SRGB_EXPONENT) : c / SRGB_LINEAR_DIVISOR;
|
|
287
|
+
R = linearize(R);
|
|
288
|
+
G = linearize(G);
|
|
289
|
+
B = linearize(B);
|
|
290
|
+
const X = R * 0.4124564 + G * 0.3575761 + B * 0.1804375;
|
|
291
|
+
const Y = R * 0.2126729 + G * 0.7151522 + B * 0.072175;
|
|
292
|
+
const Z = R * 0.0193339 + G * 0.119192 + B * 0.9503041;
|
|
293
|
+
return {
|
|
294
|
+
x: X * 100,
|
|
295
|
+
y: Y * 100,
|
|
296
|
+
z: Z * 100,
|
|
297
|
+
a: A
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function _lab2xyz(lab) {
|
|
301
|
+
const { l, a: A = 0, b: B = 0, al: alpha = 1 } = lab;
|
|
302
|
+
const REF_X = 95.047;
|
|
303
|
+
const REF_Y = 100;
|
|
304
|
+
const REF_Z = 108.883;
|
|
305
|
+
const fy = (l + 16) / 116;
|
|
306
|
+
const fx = fy + A / 500;
|
|
307
|
+
const fz = fy - B / 200;
|
|
308
|
+
const fx3 = Math.pow(fx, 3);
|
|
309
|
+
const fz3 = Math.pow(fz, 3);
|
|
310
|
+
const fy3 = Math.pow(fy, 3);
|
|
311
|
+
const epsilon = 8856e-6;
|
|
312
|
+
const kappa = 903.3;
|
|
313
|
+
const X = fx3 > epsilon ? fx3 : (116 * fx - 16) / kappa;
|
|
314
|
+
const Y = l > kappa * epsilon ? fy3 : l / kappa;
|
|
315
|
+
const Z = fz3 > epsilon ? fz3 : (116 * fz - 16) / kappa;
|
|
316
|
+
return {
|
|
317
|
+
x: X * REF_X,
|
|
318
|
+
y: Y * REF_Y,
|
|
319
|
+
z: Z * REF_Z,
|
|
320
|
+
a: Math.max(0, Math.min(1, alpha))
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function _xyz2lab(xyza) {
|
|
324
|
+
const { x, y, z, a: alpha = 1 } = xyza;
|
|
325
|
+
const REF_X = 95.047;
|
|
326
|
+
const REF_Y = 100;
|
|
327
|
+
const REF_Z = 108.883;
|
|
328
|
+
const X = x / REF_X;
|
|
329
|
+
const Y = y / REF_Y;
|
|
330
|
+
const Z = z / REF_Z;
|
|
331
|
+
const epsilon = 8856e-6;
|
|
332
|
+
const kappa = 903.3;
|
|
333
|
+
const fx = X > epsilon ? Math.cbrt(X) : (kappa * X + 16) / 116;
|
|
334
|
+
const fy = Y > epsilon ? Math.cbrt(Y) : (kappa * Y + 16) / 116;
|
|
335
|
+
const fz = Z > epsilon ? Math.cbrt(Z) : (kappa * Z + 16) / 116;
|
|
336
|
+
const L = 116 * fy - 16;
|
|
337
|
+
const A = 500 * (fx - fy);
|
|
338
|
+
const B = 200 * (fy - fz);
|
|
339
|
+
return {
|
|
340
|
+
l: L,
|
|
341
|
+
a: A,
|
|
342
|
+
b: B,
|
|
343
|
+
al: Math.max(0, Math.min(1, alpha))
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
function _lab2lch(lab) {
|
|
347
|
+
const { l, a, b, al = 1 } = lab;
|
|
348
|
+
const c = Math.sqrt(a * a + b * b);
|
|
349
|
+
let h = Math.atan2(b, a) * (180 / Math.PI);
|
|
350
|
+
if (h < 0) h += 360;
|
|
351
|
+
return { l, c, h, a: al };
|
|
352
|
+
}
|
|
353
|
+
function _lch2lab(lch) {
|
|
354
|
+
const { l, c, h, a = 1 } = lch;
|
|
355
|
+
const hRad = h * Math.PI / 180;
|
|
356
|
+
const A = c * Math.cos(hRad);
|
|
357
|
+
const B = c * Math.sin(hRad);
|
|
358
|
+
return { l, a: A, b: B, al: a };
|
|
359
|
+
}
|
|
360
|
+
function toRgb(color) {
|
|
361
|
+
if (isRgb(color)) return color;
|
|
362
|
+
if (isHsl(color)) return _hsl2rgb(color);
|
|
363
|
+
if (isHsb(color)) return _hsb2rgb(color);
|
|
364
|
+
if (isCmyk(color)) return _cmyk2rgb(color);
|
|
365
|
+
if (isCssColor(color)) return _css2rgb(color);
|
|
366
|
+
if (isHex(color)) return _hex2rgb(color);
|
|
367
|
+
if (isXyz(color)) return _xyz2rgb(color);
|
|
368
|
+
if (isLab(color)) return _xyz2rgb(_lab2xyz(color));
|
|
369
|
+
if (isLch(color)) return _xyz2rgb(_lab2xyz(_lch2lab(color)));
|
|
370
|
+
throw new Error(`Invalid color input: ${color}`);
|
|
371
|
+
}
|
|
372
|
+
function toXyz(color) {
|
|
373
|
+
if (isXyz(color)) return color;
|
|
374
|
+
if (isLab(color)) return _lab2xyz(color);
|
|
375
|
+
if (isLch(color)) return _lab2xyz(_lch2lab(color));
|
|
376
|
+
if (isRgb(color)) return _rgb2xyz(color);
|
|
377
|
+
if (isHsl(color)) return _rgb2xyz(_hsl2rgb(color));
|
|
378
|
+
if (isHsb(color)) return _rgb2xyz(_hsb2rgb(color));
|
|
379
|
+
if (isCmyk(color)) return _rgb2xyz(_cmyk2rgb(color));
|
|
380
|
+
if (isCssColor(color)) return _rgb2xyz(_css2rgb(color));
|
|
381
|
+
if (isHex(color)) return _rgb2xyz(_hex2rgb(color));
|
|
382
|
+
throw new Error(`Invalid color input: ${color}`);
|
|
383
|
+
}
|
|
384
|
+
function toLab(color) {
|
|
385
|
+
if (isLab(color)) return color;
|
|
386
|
+
if (isLch(color)) return _lch2lab(color);
|
|
387
|
+
const xyzColor = toXyz(color);
|
|
388
|
+
return _xyz2lab(xyzColor);
|
|
389
|
+
}
|
|
390
|
+
function toLch(color) {
|
|
391
|
+
if (isLch(color)) return color;
|
|
392
|
+
const labColor = toLab(color);
|
|
393
|
+
return _lab2lch(labColor);
|
|
394
|
+
}
|
|
395
|
+
function toHsl(color) {
|
|
396
|
+
if (isHsl(color)) return color;
|
|
397
|
+
const rgbColor = toRgb(color);
|
|
398
|
+
return _rgb2hsl(rgbColor);
|
|
399
|
+
}
|
|
400
|
+
function toHsb(color) {
|
|
401
|
+
if (isHsb(color)) return color;
|
|
402
|
+
const rgbColor = toRgb(color);
|
|
403
|
+
return _rgb2hsb(rgbColor);
|
|
404
|
+
}
|
|
405
|
+
function toCmyk(color) {
|
|
406
|
+
if (isCmyk(color)) return color;
|
|
407
|
+
const rgbColor = toRgb(color);
|
|
408
|
+
return _rgb2cmyk(rgbColor);
|
|
409
|
+
}
|
|
410
|
+
function toCss(color) {
|
|
411
|
+
if (isCssColor(color)) return color;
|
|
412
|
+
const rgbColor = toRgb(color);
|
|
413
|
+
return _rgb2css(rgbColor);
|
|
414
|
+
}
|
|
415
|
+
function toHex(color) {
|
|
416
|
+
if (isHex(color)) return color;
|
|
417
|
+
const rgbColor = toRgb(color);
|
|
418
|
+
return _rgb2hex(rgbColor);
|
|
419
|
+
}
|
|
420
|
+
function viaRgb(color, transformer) {
|
|
421
|
+
const _color = color;
|
|
422
|
+
const rgb = toRgb(_color);
|
|
423
|
+
const transformedRgb = transformer(rgb);
|
|
424
|
+
if (isRgb(_color)) return transformedRgb;
|
|
425
|
+
if (isHsl(_color)) return toHsl(transformedRgb);
|
|
426
|
+
if (isHsb(_color)) return toHsb(transformedRgb);
|
|
427
|
+
if (isCmyk(_color)) return toCmyk(transformedRgb);
|
|
428
|
+
if (isXyz(_color)) return toXyz(transformedRgb);
|
|
429
|
+
if (isLab(_color)) return toLab(transformedRgb);
|
|
430
|
+
if (isLch(_color)) return toLch(transformedRgb);
|
|
431
|
+
if (isHex(_color)) return toRgb(transformedRgb);
|
|
432
|
+
if (isCssColor(_color)) return transformedRgb;
|
|
433
|
+
const _typecheck = true;
|
|
434
|
+
throw new Error(`Invalid color input: ${_color}`);
|
|
435
|
+
}
|
|
436
|
+
function viaHsl(color, transformer) {
|
|
437
|
+
const _color = color;
|
|
438
|
+
const hsl = toHsl(_color);
|
|
439
|
+
const transformedHsl = transformer(hsl);
|
|
440
|
+
if (isHsl(_color)) return transformedHsl;
|
|
441
|
+
if (isRgb(_color)) return toRgb(transformedHsl);
|
|
442
|
+
if (isHsb(_color)) return toHsb(transformedHsl);
|
|
443
|
+
if (isCmyk(_color)) return toCmyk(transformedHsl);
|
|
444
|
+
if (isXyz(_color)) return toXyz(transformedHsl);
|
|
445
|
+
if (isLab(_color)) return toLab(transformedHsl);
|
|
446
|
+
if (isLch(_color)) return toLch(transformedHsl);
|
|
447
|
+
if (isHex(_color)) return toHex(transformedHsl);
|
|
448
|
+
if (isCssColor(_color)) return transformedHsl;
|
|
449
|
+
const _typecheck = true;
|
|
450
|
+
throw new Error(`Invalid color input: ${_color}`);
|
|
451
|
+
}
|
|
452
|
+
function viaHsb(color, transformer) {
|
|
453
|
+
const _color = color;
|
|
454
|
+
const hsb = toHsb(_color);
|
|
455
|
+
const transformedHsb = transformer(hsb);
|
|
456
|
+
if (isHsb(_color)) return transformedHsb;
|
|
457
|
+
if (isRgb(_color)) return toRgb(transformedHsb);
|
|
458
|
+
if (isHsl(_color)) return toHsl(transformedHsb);
|
|
459
|
+
if (isCmyk(_color)) return toCmyk(transformedHsb);
|
|
460
|
+
if (isXyz(_color)) return toXyz(transformedHsb);
|
|
461
|
+
if (isLab(_color)) return toLab(transformedHsb);
|
|
462
|
+
if (isLch(_color)) return toLch(transformedHsb);
|
|
463
|
+
if (isHex(_color)) return toHex(transformedHsb);
|
|
464
|
+
if (isCssColor(_color)) return transformedHsb;
|
|
465
|
+
const _typecheck = true;
|
|
466
|
+
throw new Error(`Invalid color input: ${_color}`);
|
|
467
|
+
}
|
|
468
|
+
function viaCmyk(color, transformer) {
|
|
469
|
+
const _color = color;
|
|
470
|
+
const cmyk = toCmyk(_color);
|
|
471
|
+
const transformedCmyk = transformer(cmyk);
|
|
472
|
+
if (isHsb(_color)) return transformedCmyk;
|
|
473
|
+
if (isRgb(_color)) return toRgb(transformedCmyk);
|
|
474
|
+
if (isHsl(_color)) return toHsl(transformedCmyk);
|
|
475
|
+
if (isCmyk(_color)) return toCmyk(transformedCmyk);
|
|
476
|
+
if (isXyz(_color)) return toXyz(transformedCmyk);
|
|
477
|
+
if (isLab(_color)) return toLab(transformedCmyk);
|
|
478
|
+
if (isLch(_color)) return toLch(transformedCmyk);
|
|
479
|
+
if (isHex(_color)) return toHex(transformedCmyk);
|
|
480
|
+
if (isCssColor(_color)) return transformedCmyk;
|
|
481
|
+
const _typecheck = true;
|
|
482
|
+
throw new Error(`Invalid color input: ${_color}`);
|
|
483
|
+
}
|
|
484
|
+
function viaXyz(color, transformer) {
|
|
485
|
+
const _color = color;
|
|
486
|
+
const xyz = toXyz(_color);
|
|
487
|
+
const transformedXyz = transformer(xyz);
|
|
488
|
+
if (isHsb(_color)) return transformedXyz;
|
|
489
|
+
if (isRgb(_color)) return toRgb(transformedXyz);
|
|
490
|
+
if (isHsl(_color)) return toHsl(transformedXyz);
|
|
491
|
+
if (isCmyk(_color)) return toCmyk(transformedXyz);
|
|
492
|
+
if (isXyz(_color)) return toXyz(transformedXyz);
|
|
493
|
+
if (isLab(_color)) return toLab(transformedXyz);
|
|
494
|
+
if (isLch(_color)) return toLch(transformedXyz);
|
|
495
|
+
if (isHex(_color)) return toHex(transformedXyz);
|
|
496
|
+
if (isCssColor(_color)) return transformedXyz;
|
|
497
|
+
const _typecheck = true;
|
|
498
|
+
throw new Error(`Invalid color input: ${_color}`);
|
|
499
|
+
}
|
|
500
|
+
function viaLab(color, transformer) {
|
|
501
|
+
const _color = color;
|
|
502
|
+
const lab = toLab(_color);
|
|
503
|
+
const transformedLab = transformer(lab);
|
|
504
|
+
if (isHsb(_color)) return transformedLab;
|
|
505
|
+
if (isRgb(_color)) return toRgb(transformedLab);
|
|
506
|
+
if (isHsl(_color)) return toHsl(transformedLab);
|
|
507
|
+
if (isCmyk(_color)) return toCmyk(transformedLab);
|
|
508
|
+
if (isXyz(_color)) return toXyz(transformedLab);
|
|
509
|
+
if (isLab(_color)) return toLab(transformedLab);
|
|
510
|
+
if (isLch(_color)) return toLch(transformedLab);
|
|
511
|
+
if (isHex(_color)) return toHex(transformedLab);
|
|
512
|
+
if (isCssColor(_color)) return transformedLab;
|
|
513
|
+
const _typecheck = true;
|
|
514
|
+
throw new Error(`Invalid color input: ${_color}`);
|
|
515
|
+
}
|
|
516
|
+
function viaLch(color, transformer) {
|
|
517
|
+
const _color = color;
|
|
518
|
+
const lch = toLch(_color);
|
|
519
|
+
const transformedLch = transformer(lch);
|
|
520
|
+
if (isHsb(_color)) return transformedLch;
|
|
521
|
+
if (isRgb(_color)) return toRgb(transformedLch);
|
|
522
|
+
if (isHsl(_color)) return toHsl(transformedLch);
|
|
523
|
+
if (isCmyk(_color)) return toCmyk(transformedLch);
|
|
524
|
+
if (isXyz(_color)) return toXyz(transformedLch);
|
|
525
|
+
if (isLab(_color)) return toLab(transformedLch);
|
|
526
|
+
if (isLch(_color)) return toLch(transformedLch);
|
|
527
|
+
if (isHex(_color)) return toHex(transformedLch);
|
|
528
|
+
if (isCssColor(_color)) return transformedLch;
|
|
529
|
+
const _typecheck = true;
|
|
530
|
+
throw new Error(`Invalid color input: ${_color}`);
|
|
531
|
+
}
|
|
532
|
+
function linearizeToSRgb(rgb) {
|
|
533
|
+
const cleanRgb = tidy(rgb);
|
|
534
|
+
const linearChannel = (v) => {
|
|
535
|
+
const n = v / 255;
|
|
536
|
+
if (n <= 0.04045) return n / 12.92;
|
|
537
|
+
else return Math.pow((n + 0.055) / 1.055, 2.4);
|
|
538
|
+
};
|
|
539
|
+
return {
|
|
540
|
+
linearR: linearChannel(cleanRgb.r),
|
|
541
|
+
linearG: linearChannel(cleanRgb.g),
|
|
542
|
+
linearB: linearChannel(cleanRgb.b),
|
|
543
|
+
a: cleanRgb.a
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
function delinearizeToRgb(srgb) {
|
|
547
|
+
const gammaChannel = (v) => {
|
|
548
|
+
if (v <= 31308e-7) return v * 12.92;
|
|
549
|
+
else return 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
|
|
550
|
+
};
|
|
551
|
+
return tidy({
|
|
552
|
+
r: gammaChannel(srgb.linearR) * 255,
|
|
553
|
+
g: gammaChannel(srgb.linearG) * 255,
|
|
554
|
+
b: gammaChannel(srgb.linearB) * 255,
|
|
555
|
+
a: srgb.a
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// src/agnostic/colors/tidy/index.ts
|
|
560
|
+
function tidy(color) {
|
|
561
|
+
const _color = color;
|
|
562
|
+
if (isRgb(_color)) return {
|
|
563
|
+
r: clamp(_color.r, 0, 255),
|
|
564
|
+
g: clamp(_color.g, 0, 255),
|
|
565
|
+
b: clamp(_color.b, 0, 255),
|
|
566
|
+
a: clamp(_color.a ?? 1, 0, 1)
|
|
567
|
+
};
|
|
568
|
+
if (isHsl(_color)) return {
|
|
569
|
+
h: absoluteModulo(_color.h, 360),
|
|
570
|
+
s: clamp(_color.s, 0, 100),
|
|
571
|
+
l: clamp(_color.l, 0, 100),
|
|
572
|
+
a: clamp(_color.a ?? 1, 0, 1)
|
|
573
|
+
};
|
|
574
|
+
if (isHsb(_color)) return {
|
|
575
|
+
h: absoluteModulo(_color.h, 360),
|
|
576
|
+
s: clamp(_color.s, 0, 100),
|
|
577
|
+
b: clamp(_color.b, 0, 100),
|
|
578
|
+
a: clamp(_color.a ?? 1, 0, 1)
|
|
579
|
+
};
|
|
580
|
+
if (isCmyk(_color)) return {
|
|
581
|
+
c: clamp(_color.c, 0, 100),
|
|
582
|
+
m: clamp(_color.m, 0, 100),
|
|
583
|
+
y: clamp(_color.y, 0, 100),
|
|
584
|
+
k: clamp(_color.k, 0, 100),
|
|
585
|
+
a: clamp(_color.a ?? 1, 0, 1)
|
|
586
|
+
};
|
|
587
|
+
if (isXyz(_color)) return {
|
|
588
|
+
x: _color.x,
|
|
589
|
+
y: _color.y,
|
|
590
|
+
z: _color.z,
|
|
591
|
+
a: clamp(_color.a ?? 1, 0, 1)
|
|
592
|
+
};
|
|
593
|
+
if (isLab(_color)) return {
|
|
594
|
+
l: clamp(_color.l, 0, 100),
|
|
595
|
+
a: _color.a,
|
|
596
|
+
b: _color.b,
|
|
597
|
+
al: clamp(_color.al ?? 1, 0, 1)
|
|
598
|
+
};
|
|
599
|
+
if (isLch(_color)) return {
|
|
600
|
+
l: clamp(_color.l, 0, 100),
|
|
601
|
+
c: Math.max(0, _color.c),
|
|
602
|
+
h: clamp(_color.h, 0, 360),
|
|
603
|
+
a: clamp(_color.a ?? 1, 0, 1)
|
|
604
|
+
};
|
|
605
|
+
if (isCssColor(_color)) return tidy(toRgb(_color));
|
|
606
|
+
if (isHex(_color)) return toHex(tidy(toRgb(_color)));
|
|
607
|
+
const _typecheck = true;
|
|
608
|
+
throw new Error(`Invalid color input: ${_color}`);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
export {
|
|
612
|
+
tidy,
|
|
613
|
+
toRgb,
|
|
614
|
+
toXyz,
|
|
615
|
+
toLab,
|
|
616
|
+
toLch,
|
|
617
|
+
toHsl,
|
|
618
|
+
toHsb,
|
|
619
|
+
toCmyk,
|
|
620
|
+
toCss,
|
|
621
|
+
toHex,
|
|
622
|
+
viaRgb,
|
|
623
|
+
viaHsl,
|
|
624
|
+
viaHsb,
|
|
625
|
+
viaCmyk,
|
|
626
|
+
viaXyz,
|
|
627
|
+
viaLab,
|
|
628
|
+
viaLch,
|
|
629
|
+
linearizeToSRgb,
|
|
630
|
+
delinearizeToRgb
|
|
631
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Sanitize
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XB3EGDBI.js";
|
|
4
4
|
import {
|
|
5
5
|
register
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TIER4TF4.js";
|
|
7
7
|
|
|
8
8
|
// src/agnostic/html/string-to-nodes/index.ts
|
|
9
9
|
function stringToNodes(dirtyStr, options) {
|