@fluixi/utils 1.0.0-alpha.82 → 1.0.0-alpha.84

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 (129) hide show
  1. package/dist/index.cjs +2858 -1
  2. package/dist/index.mjs +2838 -1
  3. package/dist/lib/array/advanced.cjs +2227 -1
  4. package/dist/lib/array/advanced.mjs +2204 -1
  5. package/dist/lib/array/array.cjs +57 -1
  6. package/dist/lib/array/array.mjs +36 -1
  7. package/dist/lib/array/index.cjs +2344 -1
  8. package/dist/lib/array/index.mjs +2322 -1
  9. package/dist/lib/array/utils.cjs +103 -1
  10. package/dist/lib/array/utils.mjs +82 -1
  11. package/dist/lib/color/color.cjs +2190 -1
  12. package/dist/lib/color/color.mjs +2167 -1
  13. package/dist/lib/color/constants.cjs +380 -1
  14. package/dist/lib/color/constants.mjs +359 -1
  15. package/dist/lib/color/conversions.cjs +629 -1
  16. package/dist/lib/color/conversions.mjs +608 -1
  17. package/dist/lib/color/helpers.cjs +2534 -1
  18. package/dist/lib/color/helpers.mjs +2511 -1
  19. package/dist/lib/color/index.cjs +2641 -1
  20. package/dist/lib/color/index.mjs +2619 -1
  21. package/dist/lib/color/types.cjs +18 -1
  22. package/dist/lib/color/utils.cjs +962 -1
  23. package/dist/lib/color/utils.mjs +939 -1
  24. package/dist/lib/compare/comparators.cjs +171 -1
  25. package/dist/lib/compare/comparators.mjs +150 -1
  26. package/dist/lib/compare/index.cjs +172 -1
  27. package/dist/lib/compare/index.mjs +152 -1
  28. package/dist/lib/crypto/hash.cjs +83 -1
  29. package/dist/lib/crypto/hash.mjs +62 -1
  30. package/dist/lib/crypto/index.cjs +85 -1
  31. package/dist/lib/crypto/index.mjs +62 -1
  32. package/dist/lib/dom/events.cjs +40 -1
  33. package/dist/lib/dom/events.mjs +19 -1
  34. package/dist/lib/dom/index.cjs +78 -1
  35. package/dist/lib/dom/index.mjs +56 -1
  36. package/dist/lib/dom/utils.cjs +57 -1
  37. package/dist/lib/dom/utils.mjs +36 -1
  38. package/dist/lib/functions/functions.cjs +366 -1
  39. package/dist/lib/functions/functions.mjs +345 -1
  40. package/dist/lib/functions/index.cjs +369 -1
  41. package/dist/lib/functions/index.mjs +347 -1
  42. package/dist/lib/functions/types.cjs +18 -1
  43. package/dist/lib/helpers.cjs +78 -1
  44. package/dist/lib/helpers.mjs +59 -1
  45. package/dist/lib/index.cjs +2857 -1
  46. package/dist/lib/index.mjs +2836 -1
  47. package/dist/lib/maths/constants.cjs +70 -1
  48. package/dist/lib/maths/constants.mjs +50 -1
  49. package/dist/lib/maths/fn/advanced.cjs +231 -1
  50. package/dist/lib/maths/fn/advanced.mjs +208 -1
  51. package/dist/lib/maths/fn/basic.cjs +212 -1
  52. package/dist/lib/maths/fn/basic.mjs +191 -1
  53. package/dist/lib/maths/fn/complex.cjs +268 -1
  54. package/dist/lib/maths/fn/complex.mjs +247 -1
  55. package/dist/lib/maths/fn/index.cjs +877 -1
  56. package/dist/lib/maths/fn/index.mjs +855 -1
  57. package/dist/lib/maths/fn/trigo.cjs +179 -1
  58. package/dist/lib/maths/fn/trigo.mjs +156 -1
  59. package/dist/lib/maths/fn/vector.cjs +728 -1
  60. package/dist/lib/maths/fn/vector.mjs +707 -1
  61. package/dist/lib/maths/formatter.cjs +61 -1
  62. package/dist/lib/maths/formatter.mjs +40 -1
  63. package/dist/lib/maths/guards.cjs +164 -1
  64. package/dist/lib/maths/guards.mjs +144 -1
  65. package/dist/lib/maths/index.cjs +1152 -1
  66. package/dist/lib/maths/index.mjs +1130 -1
  67. package/dist/lib/maths/parser.cjs +75 -1
  68. package/dist/lib/maths/parser.mjs +54 -1
  69. package/dist/lib/maths/random.cjs +49 -1
  70. package/dist/lib/maths/random.mjs +28 -1
  71. package/dist/lib/maths/types/advanced.cjs +18 -1
  72. package/dist/lib/maths/types/basic.cjs +18 -1
  73. package/dist/lib/maths/types/index.cjs +19 -1
  74. package/dist/lib/maths/types/index.mjs +1 -0
  75. package/dist/lib/maths/types/negative.cjs +18 -1
  76. package/dist/lib/maths/types/operations.cjs +18 -1
  77. package/dist/lib/object/clone.cjs +88 -1
  78. package/dist/lib/object/clone.mjs +65 -1
  79. package/dist/lib/object/diff.cjs +573 -1
  80. package/dist/lib/object/diff.mjs +550 -1
  81. package/dist/lib/object/getter-setter.cjs +2351 -1
  82. package/dist/lib/object/getter-setter.mjs +2330 -1
  83. package/dist/lib/object/index.cjs +3956 -6
  84. package/dist/lib/object/index.mjs +3936 -6
  85. package/dist/lib/object/merge.cjs +1029 -1
  86. package/dist/lib/object/merge.mjs +1006 -1
  87. package/dist/lib/object/object.cjs +280 -1
  88. package/dist/lib/object/object.mjs +257 -1
  89. package/dist/lib/object/omit.cjs +2022 -1
  90. package/dist/lib/object/omit.mjs +1999 -1
  91. package/dist/lib/object/reconcile.cjs +126 -1
  92. package/dist/lib/object/reconcile.mjs +105 -1
  93. package/dist/lib/object/selector.cjs +303 -1
  94. package/dist/lib/object/selector.mjs +282 -1
  95. package/dist/lib/object/sort.cjs +209 -1
  96. package/dist/lib/object/sort.mjs +186 -1
  97. package/dist/lib/object/transform.cjs +2211 -1
  98. package/dist/lib/object/transform.mjs +2190 -1
  99. package/dist/lib/object/types.cjs +18 -1
  100. package/dist/lib/object/utils.cjs +326 -6
  101. package/dist/lib/object/utils.mjs +305 -6
  102. package/dist/lib/primitive/boolean/boolean.cjs +407 -1
  103. package/dist/lib/primitive/boolean/boolean.mjs +386 -1
  104. package/dist/lib/primitive/boolean/index.cjs +382 -1
  105. package/dist/lib/primitive/boolean/index.mjs +359 -1
  106. package/dist/lib/primitive/boolean/types.cjs +18 -1
  107. package/dist/lib/primitive/date/date.cjs +1126 -1
  108. package/dist/lib/primitive/date/date.mjs +1105 -1
  109. package/dist/lib/primitive/date/index.cjs +1128 -1
  110. package/dist/lib/primitive/date/index.mjs +1105 -1
  111. package/dist/lib/primitive/date/types.cjs +18 -1
  112. package/dist/lib/primitive/index.cjs +2338 -5
  113. package/dist/lib/primitive/index.mjs +2316 -5
  114. package/dist/lib/primitive/string/index.cjs +875 -5
  115. package/dist/lib/primitive/string/index.mjs +852 -5
  116. package/dist/lib/primitive/string/parser-2.cjs +543 -8
  117. package/dist/lib/primitive/string/parser-2.mjs +522 -8
  118. package/dist/lib/primitive/string/parser.cjs +236 -3
  119. package/dist/lib/primitive/string/parser.mjs +215 -3
  120. package/dist/lib/primitive/string/string.cjs +926 -5
  121. package/dist/lib/primitive/string/string.mjs +903 -5
  122. package/dist/lib/primitive/string/types.cjs +18 -1
  123. package/dist/lib/primitive/types.cjs +18 -1
  124. package/dist/lib/url/index.cjs +327 -1
  125. package/dist/lib/url/index.mjs +304 -1
  126. package/dist/lib/url/parser.cjs +325 -1
  127. package/dist/lib/url/parser.mjs +304 -1
  128. package/dist/lib/url/types.cjs +18 -1
  129. package/package.json +5 -5
@@ -1 +1,608 @@
1
- var f={x:.95047,y:1,z:1.08883},g=.008856,b=903.3;function p(o,n,t){return Math.max(n,Math.min(t,o))}function G(o,n=2){let t=Math.pow(10,n);return Math.round(o*t)/t}function M(o){let n=o.r/255,t=o.g/255,r=o.b/255,e=Math.max(n,t,r),c=Math.min(n,t,r),s=e-c,a=0,l=0,u=(e+c)/2;if(s!==0)switch(l=u>.5?s/(2-e-c):s/(e+c),e){case n:a=((t-r)/s+(t<r?6:0))/6;break;case t:a=((r-n)/s+2)/6;break;case r:a=((n-t)/s+4)/6;break}return{h:a*360,s:l*100,l:u*100,a:o.a}}function x(o){let n=o.r/255,t=o.g/255,r=o.b/255,e=Math.max(n,t,r),c=Math.min(n,t,r),s=e-c,a=0,l=e===0?0:s/e,u=e;if(s!==0)switch(e){case n:a=((t-r)/s+(t<r?6:0))/6;break;case t:a=((r-n)/s+2)/6;break;case r:a=((n-t)/s+4)/6;break}return{h:a*360,s:l*100,v:u*100,a:o.a}}function d(o){let n=x(o),t=(100-n.s)*n.v/100,r=100-n.v;return{h:n.h,w:t,b:r,a:o.a}}function O(o){let n=o.r/255,t=o.g/255,r=o.b/255,e=1-Math.max(n,t,r),c=e===1?0:(1-n-e)/(1-e),s=e===1?0:(1-t-e)/(1-e),a=e===1?0:(1-r-e)/(1-e);return{c:c*100,m:s*100,y:a*100,k:e*100,a:o.a}}function y(o){let n=o.r/255,t=o.g/255,r=o.b/255;n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92,t=t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92,r=r>.04045?Math.pow((r+.055)/1.055,2.4):r/12.92;let e=n*.4124564+t*.3575761+r*.1804375,c=n*.2126729+t*.7151522+r*.072175,s=n*.0193339+t*.119192+r*.9503041;return{x:e*100,y:c*100,z:s*100,alpha:o.a}}function m(o){let n=y(o);return A(n)}function S(o){let n=m(o);return Y(n)}function T(o){let n=o.r/255,t=o.g/255,r=o.b/255,e=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92,c=t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92,s=r>.04045?Math.pow((r+.055)/1.055,2.4):r/12.92,a=.4122214708*e+.5363325363*c+.0514459929*s,l=.2119034982*e+.6806995451*c+.1073969566*s,u=.0883024619*e+.2817188376*c+.6299787005*s,i=Math.cbrt(a),h=Math.cbrt(l),C=Math.cbrt(u);return{l:.2104542553*i+.793617785*h-.0040720468*C,a:1.9779984951*i-2.428592205*h+.4505937099*C,b:.0259040371*i+.7827717662*h-.808675766*C,alpha:o.a}}function K(o){let n=T(o);return W(n)}function H(o){let n=o.h/360,t=o.s/100,r=o.l/100,e,c,s;if(t===0)e=c=s=r;else{let a=(i,h,C)=>(C<0&&(C+=1),C>1&&(C-=1),C<.16666666666666666?i+(h-i)*6*C:C<.5?h:C<.6666666666666666?i+(h-i)*(.6666666666666666-C)*6:i),l=r<.5?r*(1+t):r+t-r*t,u=2*r-l;e=a(u,l,n+1/3),c=a(u,l,n),s=a(u,l,n-1/3)}return{r:Math.round(e*255),g:Math.round(c*255),b:Math.round(s*255),a:o.a}}function q(o){let n=H(o);return x(n)}function D(o){let n=H(o);return d(n)}function L(o){let n=o.h/360,t=o.s/100,r=o.v/100,e=Math.floor(n*6),c=n*6-e,s=r*(1-t),a=r*(1-c*t),l=r*(1-(1-c)*t),u,i,h;switch(e%6){case 0:u=r,i=l,h=s;break;case 1:u=a,i=r,h=s;break;case 2:u=s,i=r,h=l;break;case 3:u=s,i=a,h=r;break;case 4:u=l,i=s,h=r;break;default:u=r,i=s,h=a;break}return{r:Math.round(u*255),g:Math.round(i*255),b:Math.round(h*255),a:o.a}}function F(o){let n=L(o);return M(n)}function N(o){let n=(100-o.s)*o.v/100,t=100-o.v;return{h:o.h,w:n,b:t,a:o.a}}function B(o){let n=o.h,t=o.w/100,r=o.b/100,e=t+r;e>1&&(t/=e,r/=e);let c=1-r,s=c===0?0:1-t/c;return L({h:n,s:s*100,v:c*100,a:o.a})}function U(o){let n=B(o);return M(n)}function J(o){let n=B(o);return x(n)}function w(o){let n=o.c/100,t=o.m/100,r=o.y/100,e=o.k/100,c=255*(1-n)*(1-e),s=255*(1-t)*(1-e),a=255*(1-r)*(1-e);return{r:Math.round(c),g:Math.round(s),b:Math.round(a),a:o.a}}function Q(o){let n=w(o);return M(n)}function $(o){let n=w(o);return x(n)}function k(o){let n=o.x/100,t=o.y/100,r=o.z/100,e=n*3.2404542+t*-1.5371385+r*-.4985314,c=n*-.969266+t*1.8760108+r*.041556,s=n*.0556434+t*-.2040259+r*1.0572252;return e=e>.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e,c=c>.0031308?1.055*Math.pow(c,1/2.4)-.055:12.92*c,s=s>.0031308?1.055*Math.pow(s,1/2.4)-.055:12.92*s,{r:Math.round(p(e*255,0,255)),g:Math.round(p(c*255,0,255)),b:Math.round(p(s*255,0,255)),a:o.alpha||1}}function A(o){let n=o.x/f.x/100,t=o.y/f.y/100,r=o.z/f.z/100,e=n>g?Math.cbrt(n):(b*n+16)/116,c=t>g?Math.cbrt(t):(b*t+16)/116,s=r>g?Math.cbrt(r):(b*r+16)/116,a=116*c-16,l=500*(e-c),u=200*(c-s);return{l:p(a,0,100),a:l,b:u,alpha:o.alpha}}function R(o){let n=(o.l+16)/116,t=o.a/500+n,r=n-o.b/200,e=t*t*t>g?t*t*t:(116*t-16)/b,c=o.l>b*g?Math.pow((o.l+16)/116,3):o.l/b,s=r*r*r>g?r*r*r:(116*r-16)/b;return{x:e*f.x*100,y:c*f.y*100,z:s*f.z*100,alpha:o.alpha}}function v(o){let n=R(o);return k(n)}function Y(o){let n=Math.sqrt(o.a*o.a+o.b*o.b),t=Math.atan2(o.b,o.a)*180/Math.PI;return t<0&&(t+=360),{l:o.l,c:n,h:t,alpha:o.alpha}}function z(o){let n=o.h*Math.PI/180,t=o.c*Math.cos(n),r=o.c*Math.sin(n);return{l:o.l,a:t,b:r,alpha:o.alpha}}function V(o){let n=z(o);return v(n)}function oo(o){let n=z(o);return R(n)}function X(o){let n=o.l+.3963377774*o.a+.2158037573*o.b,t=o.l-.1055613458*o.a-.0638541728*o.b,r=o.l-.0894841775*o.a-1.291485548*o.b,e=n*n*n,c=t*t*t,s=r*r*r,a=4.0767416621*e-3.3077115913*c+.2309699292*s,l=-1.2684380046*e+2.6097574011*c-.3413193965*s,u=-.0041960863*e-.7034186147*c+1.707614701*s;return a=a>.0031308?1.055*Math.pow(a,1/2.4)-.055:12.92*a,l=l>.0031308?1.055*Math.pow(l,1/2.4)-.055:12.92*l,u=u>.0031308?1.055*Math.pow(u,1/2.4)-.055:12.92*u,{r:Math.round(p(a*255,0,255)),g:Math.round(p(l*255,0,255)),b:Math.round(p(u*255,0,255)),a:o.alpha}}function W(o){let n=Math.sqrt(o.a*o.a+o.b*o.b),t=Math.atan2(o.b,o.a)*180/Math.PI;return t<0&&(t+=360),{l:o.l,c:n,h:t,alpha:o.alpha}}function P(o){let n=o.h*Math.PI/180,t=o.c*Math.cos(n),r=o.c*Math.sin(n);return{l:o.l,a:t,b:r,alpha:o.alpha}}function Z(o){let n=P(o);return X(n)}function _(o){if("r"in o&&"g"in o&&"b"in o)return o;if("h"in o&&"s"in o&&"l"in o)return H(o);if("h"in o&&"s"in o&&"v"in o)return L(o);if("h"in o&&"w"in o&&"b"in o)return B(o);if("c"in o&&"m"in o&&"y"in o&&"k"in o)return w(o);if("x"in o&&"y"in o&&"z"in o)return k(o);if("l"in o&&"a"in o&&"b"in o&&!("c"in o)&&!("h"in o))return v(o);if("l"in o&&"c"in o&&"h"in o){let n=o;return n.l<=1?Z(o):V(n)}throw new Error("Unknown color format")}function I(o,n,t={}){let{round:r=!0,precision:e=2,preserveAlpha:c=!0}=t,s=_(o),a;switch(n.toLowerCase()){case"rgb":a=s;break;case"hsl":a=M(s);break;case"hsv":a=x(s);break;case"hwb":a=d(s);break;case"cmyk":a=O(s);break;case"xyz":a=y(s);break;case"lab":a=m(s);break;case"lch":a=S(s);break;case"oklab":a=T(s);break;case"oklch":a=K(s);break;default:a=s}return r&&a&&Object.keys(a).forEach(l=>{typeof a[l]=="number"&&l!=="a"&&l!=="alpha"&&(a[l]=G(a[l],e))}),c||(delete a.a,delete a.alpha),a}function no(o,n,t={}){return o.map(r=>I(r,n,t))}function E(o,n){let t={rgb:["hsl","hsv","hwb","cmyk","xyz","lab","lch","oklab","oklch"],hsl:["rgb","hsv","hwb"],hsv:["rgb","hsl","hwb"],hwb:["rgb","hsl","hsv"],cmyk:["rgb","hsl","hsv"],xyz:["rgb","lab"],lab:["rgb","xyz","lch"],lch:["rgb","lab","xyz"],oklab:["rgb","oklch"],oklch:["rgb","oklab"]};return o=o.toLowerCase(),n=n.toLowerCase(),o===n?[o]:t[o]?.includes(n)?[o,n]:t[o]?.includes("rgb")&&t.rgb?.includes(n)?[o,"rgb",n]:["lab","lch"].includes(o)&&["lab","lch"].includes(n)&&o!==n?[o,"xyz",n]:["oklab","oklch"].includes(o)&&["oklab","oklch"].includes(n)&&o!==n?[o,"oklab",n]:t[o]&&t.rgb?.includes(n)?[o,"rgb",n]:null}function to(o,n){let t=E(o,n);return t!==null&&t.length<=2}function j(){return["rgb","hsl","hsv","hwb","cmyk","xyz","lab","lch","oklab","oklch"]}function ro(o){return j().includes(o.toLowerCase())}export{_ as anyToRgb,no as batchConvert,Q as cmykToHsl,$ as cmykToHsv,w as cmykToRgb,I as convertColor,E as getConversionPath,j as getSupportedFormats,to as hasDirectConversion,q as hslToHsv,D as hslToHwb,H as hslToRgb,F as hsvToHsl,N as hsvToHwb,L as hsvToRgb,U as hwbToHsl,J as hwbToHsv,B as hwbToRgb,ro as isValidFormat,Y as labToLch,v as labToRgb,R as labToXyz,z as lchToLab,V as lchToRgb,oo as lchToXyz,W as oklabToOklch,X as oklabToRgb,P as oklchToOklab,Z as oklchToRgb,O as rgbToCmyk,M as rgbToHsl,x as rgbToHsv,d as rgbToHwb,m as rgbToLab,S as rgbToLch,T as rgbToOklab,K as rgbToOklch,y as rgbToXyz,A as xyzToLab,k as xyzToRgb};
1
+ // src/lib/color/conversions.ts
2
+ var D65_WHITE = { x: 0.95047, y: 1, z: 1.08883 };
3
+ var EPSILON = 8856e-6;
4
+ var KAPPA = 903.3;
5
+ function clamp(value, min, max) {
6
+ return Math.max(min, Math.min(max, value));
7
+ }
8
+ function roundToPrecision(value, precision = 2) {
9
+ const multiplier = Math.pow(10, precision);
10
+ return Math.round(value * multiplier) / multiplier;
11
+ }
12
+ function rgbToHsl(rgb) {
13
+ const r = rgb.r / 255;
14
+ const g = rgb.g / 255;
15
+ const b = rgb.b / 255;
16
+ const max = Math.max(r, g, b);
17
+ const min = Math.min(r, g, b);
18
+ const delta = max - min;
19
+ let h = 0;
20
+ let s = 0;
21
+ const l = (max + min) / 2;
22
+ if (delta !== 0) {
23
+ s = l > 0.5 ? delta / (2 - max - min) : delta / (max + min);
24
+ switch (max) {
25
+ case r:
26
+ h = ((g - b) / delta + (g < b ? 6 : 0)) / 6;
27
+ break;
28
+ case g:
29
+ h = ((b - r) / delta + 2) / 6;
30
+ break;
31
+ case b:
32
+ h = ((r - g) / delta + 4) / 6;
33
+ break;
34
+ }
35
+ }
36
+ return {
37
+ h: h * 360,
38
+ s: s * 100,
39
+ l: l * 100,
40
+ a: rgb.a
41
+ };
42
+ }
43
+ function rgbToHsv(rgb) {
44
+ const r = rgb.r / 255;
45
+ const g = rgb.g / 255;
46
+ const b = rgb.b / 255;
47
+ const max = Math.max(r, g, b);
48
+ const min = Math.min(r, g, b);
49
+ const delta = max - min;
50
+ let h = 0;
51
+ const s = max === 0 ? 0 : delta / max;
52
+ const v = max;
53
+ if (delta !== 0) {
54
+ switch (max) {
55
+ case r:
56
+ h = ((g - b) / delta + (g < b ? 6 : 0)) / 6;
57
+ break;
58
+ case g:
59
+ h = ((b - r) / delta + 2) / 6;
60
+ break;
61
+ case b:
62
+ h = ((r - g) / delta + 4) / 6;
63
+ break;
64
+ }
65
+ }
66
+ return {
67
+ h: h * 360,
68
+ s: s * 100,
69
+ v: v * 100,
70
+ a: rgb.a
71
+ };
72
+ }
73
+ function rgbToHwb(rgb) {
74
+ const hsv = rgbToHsv(rgb);
75
+ const w = (100 - hsv.s) * hsv.v / 100;
76
+ const b = 100 - hsv.v;
77
+ return {
78
+ h: hsv.h,
79
+ w,
80
+ b,
81
+ a: rgb.a
82
+ };
83
+ }
84
+ function rgbToCmyk(rgb) {
85
+ const r = rgb.r / 255;
86
+ const g = rgb.g / 255;
87
+ const b = rgb.b / 255;
88
+ const k = 1 - Math.max(r, g, b);
89
+ const c = k === 1 ? 0 : (1 - r - k) / (1 - k);
90
+ const m = k === 1 ? 0 : (1 - g - k) / (1 - k);
91
+ const y = k === 1 ? 0 : (1 - b - k) / (1 - k);
92
+ return {
93
+ c: c * 100,
94
+ m: m * 100,
95
+ y: y * 100,
96
+ k: k * 100,
97
+ a: rgb.a
98
+ };
99
+ }
100
+ function rgbToXyz(rgb) {
101
+ let r = rgb.r / 255;
102
+ let g = rgb.g / 255;
103
+ let b = rgb.b / 255;
104
+ r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
105
+ g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
106
+ b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
107
+ const x = r * 0.4124564 + g * 0.3575761 + b * 0.1804375;
108
+ const y = r * 0.2126729 + g * 0.7151522 + b * 0.072175;
109
+ const z = r * 0.0193339 + g * 0.119192 + b * 0.9503041;
110
+ return {
111
+ x: x * 100,
112
+ y: y * 100,
113
+ z: z * 100,
114
+ alpha: rgb.a
115
+ };
116
+ }
117
+ function rgbToLab(rgb) {
118
+ const xyz = rgbToXyz(rgb);
119
+ return xyzToLab(xyz);
120
+ }
121
+ function rgbToLch(rgb) {
122
+ const lab = rgbToLab(rgb);
123
+ return labToLch(lab);
124
+ }
125
+ function rgbToOklab(rgb) {
126
+ const r = rgb.r / 255;
127
+ const g = rgb.g / 255;
128
+ const b = rgb.b / 255;
129
+ const lr = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
130
+ const lg = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
131
+ const lb = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
132
+ const l = 0.4122214708 * lr + 0.5363325363 * lg + 0.0514459929 * lb;
133
+ const m = 0.2119034982 * lr + 0.6806995451 * lg + 0.1073969566 * lb;
134
+ const s = 0.0883024619 * lr + 0.2817188376 * lg + 0.6299787005 * lb;
135
+ const l_ = Math.cbrt(l);
136
+ const m_ = Math.cbrt(m);
137
+ const s_ = Math.cbrt(s);
138
+ return {
139
+ l: 0.2104542553 * l_ + 0.793617785 * m_ - 0.0040720468 * s_,
140
+ a: 1.9779984951 * l_ - 2.428592205 * m_ + 0.4505937099 * s_,
141
+ b: 0.0259040371 * l_ + 0.7827717662 * m_ - 0.808675766 * s_,
142
+ alpha: rgb.a
143
+ };
144
+ }
145
+ function rgbToOklch(rgb) {
146
+ const oklab = rgbToOklab(rgb);
147
+ return oklabToOklch(oklab);
148
+ }
149
+ function hslToRgb(hsl) {
150
+ const h = hsl.h / 360;
151
+ const s = hsl.s / 100;
152
+ const l = hsl.l / 100;
153
+ let r, g, b;
154
+ if (s === 0) {
155
+ r = g = b = l;
156
+ } else {
157
+ const hue2rgb = (p2, q2, t) => {
158
+ if (t < 0) t += 1;
159
+ if (t > 1) t -= 1;
160
+ if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
161
+ if (t < 1 / 2) return q2;
162
+ if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
163
+ return p2;
164
+ };
165
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
166
+ const p = 2 * l - q;
167
+ r = hue2rgb(p, q, h + 1 / 3);
168
+ g = hue2rgb(p, q, h);
169
+ b = hue2rgb(p, q, h - 1 / 3);
170
+ }
171
+ return {
172
+ r: Math.round(r * 255),
173
+ g: Math.round(g * 255),
174
+ b: Math.round(b * 255),
175
+ a: hsl.a
176
+ };
177
+ }
178
+ function hslToHsv(hsl) {
179
+ const rgb = hslToRgb(hsl);
180
+ return rgbToHsv(rgb);
181
+ }
182
+ function hslToHwb(hsl) {
183
+ const rgb = hslToRgb(hsl);
184
+ return rgbToHwb(rgb);
185
+ }
186
+ function hsvToRgb(hsv) {
187
+ const h = hsv.h / 360;
188
+ const s = hsv.s / 100;
189
+ const v = hsv.v / 100;
190
+ const i = Math.floor(h * 6);
191
+ const f = h * 6 - i;
192
+ const p = v * (1 - s);
193
+ const q = v * (1 - f * s);
194
+ const t = v * (1 - (1 - f) * s);
195
+ let r, g, b;
196
+ switch (i % 6) {
197
+ case 0:
198
+ r = v;
199
+ g = t;
200
+ b = p;
201
+ break;
202
+ case 1:
203
+ r = q;
204
+ g = v;
205
+ b = p;
206
+ break;
207
+ case 2:
208
+ r = p;
209
+ g = v;
210
+ b = t;
211
+ break;
212
+ case 3:
213
+ r = p;
214
+ g = q;
215
+ b = v;
216
+ break;
217
+ case 4:
218
+ r = t;
219
+ g = p;
220
+ b = v;
221
+ break;
222
+ case 5:
223
+ default:
224
+ r = v;
225
+ g = p;
226
+ b = q;
227
+ break;
228
+ }
229
+ return {
230
+ r: Math.round(r * 255),
231
+ g: Math.round(g * 255),
232
+ b: Math.round(b * 255),
233
+ a: hsv.a
234
+ };
235
+ }
236
+ function hsvToHsl(hsv) {
237
+ const rgb = hsvToRgb(hsv);
238
+ return rgbToHsl(rgb);
239
+ }
240
+ function hsvToHwb(hsv) {
241
+ const w = (100 - hsv.s) * hsv.v / 100;
242
+ const b = 100 - hsv.v;
243
+ return {
244
+ h: hsv.h,
245
+ w,
246
+ b,
247
+ a: hsv.a
248
+ };
249
+ }
250
+ function hwbToRgb(hwb) {
251
+ const h = hwb.h;
252
+ let w = hwb.w / 100;
253
+ let b = hwb.b / 100;
254
+ const sum = w + b;
255
+ if (sum > 1) {
256
+ w /= sum;
257
+ b /= sum;
258
+ }
259
+ const v = 1 - b;
260
+ const s = v === 0 ? 0 : 1 - w / v;
261
+ return hsvToRgb({ h, s: s * 100, v: v * 100, a: hwb.a });
262
+ }
263
+ function hwbToHsl(hwb) {
264
+ const rgb = hwbToRgb(hwb);
265
+ return rgbToHsl(rgb);
266
+ }
267
+ function hwbToHsv(hwb) {
268
+ const rgb = hwbToRgb(hwb);
269
+ return rgbToHsv(rgb);
270
+ }
271
+ function cmykToRgb(cmyk) {
272
+ const c = cmyk.c / 100;
273
+ const m = cmyk.m / 100;
274
+ const y = cmyk.y / 100;
275
+ const k = cmyk.k / 100;
276
+ const r = 255 * (1 - c) * (1 - k);
277
+ const g = 255 * (1 - m) * (1 - k);
278
+ const b = 255 * (1 - y) * (1 - k);
279
+ return {
280
+ r: Math.round(r),
281
+ g: Math.round(g),
282
+ b: Math.round(b),
283
+ a: cmyk.a
284
+ };
285
+ }
286
+ function cmykToHsl(cmyk) {
287
+ const rgb = cmykToRgb(cmyk);
288
+ return rgbToHsl(rgb);
289
+ }
290
+ function cmykToHsv(cmyk) {
291
+ const rgb = cmykToRgb(cmyk);
292
+ return rgbToHsv(rgb);
293
+ }
294
+ function xyzToRgb(xyz) {
295
+ const x = xyz.x / 100;
296
+ const y = xyz.y / 100;
297
+ const z = xyz.z / 100;
298
+ let r = x * 3.2404542 + y * -1.5371385 + z * -0.4985314;
299
+ let g = x * -0.969266 + y * 1.8760108 + z * 0.041556;
300
+ let b = x * 0.0556434 + y * -0.2040259 + z * 1.0572252;
301
+ r = r > 31308e-7 ? 1.055 * Math.pow(r, 1 / 2.4) - 0.055 : 12.92 * r;
302
+ g = g > 31308e-7 ? 1.055 * Math.pow(g, 1 / 2.4) - 0.055 : 12.92 * g;
303
+ b = b > 31308e-7 ? 1.055 * Math.pow(b, 1 / 2.4) - 0.055 : 12.92 * b;
304
+ return {
305
+ r: Math.round(clamp(r * 255, 0, 255)),
306
+ g: Math.round(clamp(g * 255, 0, 255)),
307
+ b: Math.round(clamp(b * 255, 0, 255)),
308
+ a: xyz.alpha || 1
309
+ };
310
+ }
311
+ function xyzToLab(xyz) {
312
+ const xr = xyz.x / D65_WHITE.x / 100;
313
+ const yr = xyz.y / D65_WHITE.y / 100;
314
+ const zr = xyz.z / D65_WHITE.z / 100;
315
+ const fx = xr > EPSILON ? Math.cbrt(xr) : (KAPPA * xr + 16) / 116;
316
+ const fy = yr > EPSILON ? Math.cbrt(yr) : (KAPPA * yr + 16) / 116;
317
+ const fz = zr > EPSILON ? Math.cbrt(zr) : (KAPPA * zr + 16) / 116;
318
+ const l = 116 * fy - 16;
319
+ const a = 500 * (fx - fy);
320
+ const b = 200 * (fy - fz);
321
+ return {
322
+ l: clamp(l, 0, 100),
323
+ a,
324
+ b,
325
+ alpha: xyz.alpha
326
+ };
327
+ }
328
+ function labToXyz(lab) {
329
+ const fy = (lab.l + 16) / 116;
330
+ const fx = lab.a / 500 + fy;
331
+ const fz = fy - lab.b / 200;
332
+ const xr = fx * fx * fx > EPSILON ? fx * fx * fx : (116 * fx - 16) / KAPPA;
333
+ const yr = lab.l > KAPPA * EPSILON ? Math.pow((lab.l + 16) / 116, 3) : lab.l / KAPPA;
334
+ const zr = fz * fz * fz > EPSILON ? fz * fz * fz : (116 * fz - 16) / KAPPA;
335
+ return {
336
+ x: xr * D65_WHITE.x * 100,
337
+ y: yr * D65_WHITE.y * 100,
338
+ z: zr * D65_WHITE.z * 100,
339
+ alpha: lab.alpha
340
+ };
341
+ }
342
+ function labToRgb(lab) {
343
+ const xyz = labToXyz(lab);
344
+ return xyzToRgb(xyz);
345
+ }
346
+ function labToLch(lab) {
347
+ const c = Math.sqrt(lab.a * lab.a + lab.b * lab.b);
348
+ let h = Math.atan2(lab.b, lab.a) * 180 / Math.PI;
349
+ if (h < 0) {
350
+ h += 360;
351
+ }
352
+ return {
353
+ l: lab.l,
354
+ c,
355
+ h,
356
+ alpha: lab.alpha
357
+ };
358
+ }
359
+ function lchToLab(lch) {
360
+ const h = lch.h * Math.PI / 180;
361
+ const a = lch.c * Math.cos(h);
362
+ const b = lch.c * Math.sin(h);
363
+ return {
364
+ l: lch.l,
365
+ a,
366
+ b,
367
+ alpha: lch.alpha
368
+ };
369
+ }
370
+ function lchToRgb(lch) {
371
+ const lab = lchToLab(lch);
372
+ return labToRgb(lab);
373
+ }
374
+ function lchToXyz(lch) {
375
+ const lab = lchToLab(lch);
376
+ return labToXyz(lab);
377
+ }
378
+ function oklabToRgb(oklab) {
379
+ const l_ = oklab.l + 0.3963377774 * oklab.a + 0.2158037573 * oklab.b;
380
+ const m_ = oklab.l - 0.1055613458 * oklab.a - 0.0638541728 * oklab.b;
381
+ const s_ = oklab.l - 0.0894841775 * oklab.a - 1.291485548 * oklab.b;
382
+ const l = l_ * l_ * l_;
383
+ const m = m_ * m_ * m_;
384
+ const s = s_ * s_ * s_;
385
+ let lr = 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s;
386
+ let lg = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s;
387
+ let lb = -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s;
388
+ lr = lr > 31308e-7 ? 1.055 * Math.pow(lr, 1 / 2.4) - 0.055 : 12.92 * lr;
389
+ lg = lg > 31308e-7 ? 1.055 * Math.pow(lg, 1 / 2.4) - 0.055 : 12.92 * lg;
390
+ lb = lb > 31308e-7 ? 1.055 * Math.pow(lb, 1 / 2.4) - 0.055 : 12.92 * lb;
391
+ return {
392
+ r: Math.round(clamp(lr * 255, 0, 255)),
393
+ g: Math.round(clamp(lg * 255, 0, 255)),
394
+ b: Math.round(clamp(lb * 255, 0, 255)),
395
+ a: oklab.alpha
396
+ };
397
+ }
398
+ function oklabToOklch(oklab) {
399
+ const c = Math.sqrt(oklab.a * oklab.a + oklab.b * oklab.b);
400
+ let h = Math.atan2(oklab.b, oklab.a) * 180 / Math.PI;
401
+ if (h < 0) {
402
+ h += 360;
403
+ }
404
+ return {
405
+ l: oklab.l,
406
+ c,
407
+ h,
408
+ alpha: oklab.alpha
409
+ };
410
+ }
411
+ function oklchToOklab(oklch) {
412
+ const h = oklch.h * Math.PI / 180;
413
+ const a = oklch.c * Math.cos(h);
414
+ const b = oklch.c * Math.sin(h);
415
+ return {
416
+ l: oklch.l,
417
+ a,
418
+ b,
419
+ alpha: oklch.alpha
420
+ };
421
+ }
422
+ function oklchToRgb(oklch) {
423
+ const oklab = oklchToOklab(oklch);
424
+ return oklabToRgb(oklab);
425
+ }
426
+ function anyToRgb(color) {
427
+ if ("r" in color && "g" in color && "b" in color) {
428
+ return color;
429
+ }
430
+ if ("h" in color && "s" in color && "l" in color) {
431
+ return hslToRgb(color);
432
+ }
433
+ if ("h" in color && "s" in color && "v" in color) {
434
+ return hsvToRgb(color);
435
+ }
436
+ if ("h" in color && "w" in color && "b" in color) {
437
+ return hwbToRgb(color);
438
+ }
439
+ if ("c" in color && "m" in color && "y" in color && "k" in color) {
440
+ return cmykToRgb(color);
441
+ }
442
+ if ("x" in color && "y" in color && "z" in color) {
443
+ return xyzToRgb(color);
444
+ }
445
+ if ("l" in color && "a" in color && "b" in color && !("c" in color) && !("h" in color)) {
446
+ return labToRgb(color);
447
+ }
448
+ if ("l" in color && "c" in color && "h" in color) {
449
+ const lchColor = color;
450
+ if (lchColor.l <= 1) {
451
+ return oklchToRgb(color);
452
+ }
453
+ return lchToRgb(lchColor);
454
+ }
455
+ throw new Error("Unknown color format");
456
+ }
457
+ function convertColor(color, targetFormat, options = {}) {
458
+ const { round = true, precision = 2, preserveAlpha = true } = options;
459
+ const rgb = anyToRgb(color);
460
+ let result;
461
+ switch (targetFormat.toLowerCase()) {
462
+ case "rgb":
463
+ result = rgb;
464
+ break;
465
+ case "hsl":
466
+ result = rgbToHsl(rgb);
467
+ break;
468
+ case "hsv":
469
+ result = rgbToHsv(rgb);
470
+ break;
471
+ case "hwb":
472
+ result = rgbToHwb(rgb);
473
+ break;
474
+ case "cmyk":
475
+ result = rgbToCmyk(rgb);
476
+ break;
477
+ case "xyz":
478
+ result = rgbToXyz(rgb);
479
+ break;
480
+ case "lab":
481
+ result = rgbToLab(rgb);
482
+ break;
483
+ case "lch":
484
+ result = rgbToLch(rgb);
485
+ break;
486
+ case "oklab":
487
+ result = rgbToOklab(rgb);
488
+ break;
489
+ case "oklch":
490
+ result = rgbToOklch(rgb);
491
+ break;
492
+ default:
493
+ result = rgb;
494
+ }
495
+ if (round && result) {
496
+ Object.keys(result).forEach((key) => {
497
+ if (typeof result[key] === "number" && key !== "a" && key !== "alpha") {
498
+ result[key] = roundToPrecision(result[key], precision);
499
+ }
500
+ });
501
+ }
502
+ if (!preserveAlpha) {
503
+ delete result.a;
504
+ delete result.alpha;
505
+ }
506
+ return result;
507
+ }
508
+ function batchConvert(colors, targetFormat, options = {}) {
509
+ return colors.map((color) => convertColor(color, targetFormat, options));
510
+ }
511
+ function getConversionPath(from, to) {
512
+ const directConversions = {
513
+ rgb: ["hsl", "hsv", "hwb", "cmyk", "xyz", "lab", "lch", "oklab", "oklch"],
514
+ hsl: ["rgb", "hsv", "hwb"],
515
+ hsv: ["rgb", "hsl", "hwb"],
516
+ hwb: ["rgb", "hsl", "hsv"],
517
+ cmyk: ["rgb", "hsl", "hsv"],
518
+ xyz: ["rgb", "lab"],
519
+ lab: ["rgb", "xyz", "lch"],
520
+ lch: ["rgb", "lab", "xyz"],
521
+ oklab: ["rgb", "oklch"],
522
+ oklch: ["rgb", "oklab"]
523
+ };
524
+ from = from.toLowerCase();
525
+ to = to.toLowerCase();
526
+ if (from === to) {
527
+ return [from];
528
+ }
529
+ if (directConversions[from]?.includes(to)) {
530
+ return [from, to];
531
+ }
532
+ if (directConversions[from]?.includes("rgb") && directConversions["rgb"]?.includes(to)) {
533
+ return [from, "rgb", to];
534
+ }
535
+ if (["lab", "lch"].includes(from) && ["lab", "lch"].includes(to) && from !== to) {
536
+ return [from, "xyz", to];
537
+ }
538
+ if (["oklab", "oklch"].includes(from) && ["oklab", "oklch"].includes(to) && from !== to) {
539
+ return [from, "oklab", to];
540
+ }
541
+ if (directConversions[from] && directConversions["rgb"]?.includes(to)) {
542
+ return [from, "rgb", to];
543
+ }
544
+ return null;
545
+ }
546
+ function hasDirectConversion(from, to) {
547
+ const path = getConversionPath(from, to);
548
+ return path !== null && path.length <= 2;
549
+ }
550
+ function getSupportedFormats() {
551
+ return [
552
+ "rgb",
553
+ "hsl",
554
+ "hsv",
555
+ "hwb",
556
+ "cmyk",
557
+ "xyz",
558
+ "lab",
559
+ "lch",
560
+ "oklab",
561
+ "oklch"
562
+ ];
563
+ }
564
+ function isValidFormat(format) {
565
+ return getSupportedFormats().includes(format.toLowerCase());
566
+ }
567
+ export {
568
+ anyToRgb,
569
+ batchConvert,
570
+ cmykToHsl,
571
+ cmykToHsv,
572
+ cmykToRgb,
573
+ convertColor,
574
+ getConversionPath,
575
+ getSupportedFormats,
576
+ hasDirectConversion,
577
+ hslToHsv,
578
+ hslToHwb,
579
+ hslToRgb,
580
+ hsvToHsl,
581
+ hsvToHwb,
582
+ hsvToRgb,
583
+ hwbToHsl,
584
+ hwbToHsv,
585
+ hwbToRgb,
586
+ isValidFormat,
587
+ labToLch,
588
+ labToRgb,
589
+ labToXyz,
590
+ lchToLab,
591
+ lchToRgb,
592
+ lchToXyz,
593
+ oklabToOklch,
594
+ oklabToRgb,
595
+ oklchToOklab,
596
+ oklchToRgb,
597
+ rgbToCmyk,
598
+ rgbToHsl,
599
+ rgbToHsv,
600
+ rgbToHwb,
601
+ rgbToLab,
602
+ rgbToLch,
603
+ rgbToOklab,
604
+ rgbToOklch,
605
+ rgbToXyz,
606
+ xyzToLab,
607
+ xyzToRgb
608
+ };