Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@atomik-color/core

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atomik-color/core - npm Package Compare versions

Comparing version 1.0.10 to 1.0.11

dist/color/str2Color.d.ts

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [1.0.11](https://github.com/deebov/color-picker/compare/@atomik-color/core@1.0.10...@atomik-color/core@1.0.11) (2020-10-02)
**Note:** Version bump only for package @atomik-color/core
## [1.0.10](https://github.com/deebov/color-picker/compare/@atomik-color/core@1.0.9...@atomik-color/core@1.0.10) (2020-10-02)

@@ -8,0 +16,0 @@

2

dist/color/index.d.ts
export * from "./converters";
export { getColorFromString as str2Color } from "./getColorFromString";
export * from "./str2Color";
export * from "./hooks";
export * from "./color/converters";
export * from "./color";

@@ -1,2 +0,2 @@

import{useState as r,useEffect as e,useRef as t}from"react";var a;!function(r){r.PageUp="PageUp",r.PageDown="PageDown",r.End="End",r.Home="Home",r.ArrowLeft="ArrowLeft",r.ArrowUp="ArrowUp",r.ArrowRight="ArrowRight",r.ArrowDown="ArrowDown",r.Tab="Tab"}(a||(a={}));var n=a;function o(r=0,e,t=0){return r<t?t:r>e?e:r}const s=(r,e,t,a)=>{let n=(r.clientX-e.left)/e.width;return n=o(Math.round(n*t),t,a),n},i=(r,e,t,a)=>{let n=(r.clientY-e.top)/e.height;return n=o(Math.round(n*t),t,a),n},l=r=>{var{ref:e,onStep:t,ariaLabel:a,ariaValueNow:o,ariaValueText:l,maxValue:c=100,minValue:u=0,step:b=1,bigStep:g=10}=r,h=function(r,e){var t={};for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&e.indexOf(a)<0&&(t[a]=r[a]);if(null!=r&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(a=Object.getOwnPropertySymbols(r);n<a.length;n++)e.indexOf(a[n])<0&&Object.prototype.propertyIsEnumerable.call(r,a[n])&&(t[a[n]]=r[a[n]])}return t}(r,["ref","onStep","ariaLabel","ariaValueNow","ariaValueText","maxValue","minValue","step","bigStep"]);const p=r=>{if(!e.current||"function"!=typeof h.onChange)return;r.preventDefault();const t=e.current.getBoundingClientRect();if("both"===h.direction){let e=s(r,t,c,u),a=i(r,t,c,u);return h.onChange({x:e,y:a})}if("horizontal"===h.direction){let e=s(r,t,c,u);return h.onChange(e)}if("vertical"===h.direction){let e=i(r,t,c,u);return h.onChange(e)}};return{sliderProps:{tabIndex:0,onPointerDown:r=>{var t;e.current&&(r.preventDefault(),e.current.focus(),document.body.style.touchAction="none",e.current.onpointermove=p,null===(t=e.current)||void 0===t||t.setPointerCapture(r.pointerId),p(r))},onPointerUp:r=>{e.current&&(e.current.onpointermove=null,e.current.releasePointerCapture(r.pointerId),document.body.style.touchAction="auto")},onKeyDown:r=>{var e,a;r.key!==n.Tab&&r.preventDefault();let o=r.shiftKey?g:b;switch(r.key){case n.ArrowLeft:case n.ArrowDown:null==t||t(-o);break;case n.ArrowRight:case n.ArrowUp:null==t||t(o);break;case n.Home:"vertical"!==h.direction&&"horizontal"!==h.direction||null===(e=h.onChange)||void 0===e||e.call(h,u);break;case n.End:"vertical"!==h.direction&&"horizontal"!==h.direction||null===(a=h.onChange)||void 0===a||a.call(h,c);break;default:return}},role:"slider","aria-valuemin":u,"aria-valuemax":c,"aria-label":a,"aria-valuenow":o,"aria-valuetext":l}}},c=({state:r,ref:e})=>{const{sliderProps:t}=l({ref:e,direction:"horizontal",onChange:e=>r.setA(e),onStep:e=>r.rotateA(e),maxValue:100,ariaLabel:"Alpha slider",ariaValueNow:r.color.a,ariaValueText:String(r.color.a)});return{sliderProps:t}},u=(r,e,t=0)=>(r=>"number"==typeof r&&!1===isNaN(r))(r)&&r>=t&&r<=e,b=r=>{const{h:e,s:t,v:a}=(({h:r,s:e,v:t})=>({h:o(r,359,0),s:o(e,100,0),v:o(t,100,0)}))(r);let n=a/100,s=t/100*n,i=e/60,l=s*(1-Math.abs(i%2-1)),c=n-s;return s=255*(s+c)|0,l=255*(l+c)|0,c=255*c|0,i>=0&&i<1?{r:s,g:l,b:c}:i>=1&&i<2?{r:l,g:s,b:c}:i>=2&&i<3?{r:c,g:s,b:l}:i>=3&&i<4?{r:c,g:l,b:s}:i>=4&&i<5?{r:l,g:c,b:s}:i>=5&&i<6?{r:s,g:c,b:l}:{r:0,g:0,b:0}},g=({h:r,s:e,v:t})=>{let{r:a,g:n,b:o}=b({h:r,s:e,v:t});return d({r:a,g:n,b:o})},h=r=>{const{r:e,g:t,b:a}=(({r:r,g:e,b:t})=>({r:o(r,255,0),g:o(e,255,0),b:o(t,255,0)}))(r);let n=e/255,s=t/255,i=a/255,l=Math.max(n,s,i),c=l-Math.min(n,s,i),u=0,b=0,g=0;return c&&(l===n&&(u=(s-i)/c),l===s&&(u=2+(i-n)/c),l===i&&(u=4+(n-s)/c),l&&(b=c/l)),u=60*u|0,u<0&&(u+=360),b=100*b|0,g=100*l|0,{h:u,s:b,v:g}},p=({r:r,g:e,b:t})=>{let a=r/255,n=e/255,o=t/255,s=Math.max(a,n,o),i=Math.min(a,n,o),l=s-i,c=0,u=0,b=(s+i)/2,g=1-Math.abs(2*b-1);return l&&(s===a&&(c=(n-o)/l),s===n&&(c=2+(o-a)/l),s===o&&(c=4+(a-n)/l),s&&(u=l/g)),c=60*c|0,c<0&&(c+=360),u=100*u|0,b=100*b|0,{h:c,s:u,l:b}},d=({r:r,g:e,b:t},a=!0)=>(a?"#":"")+((1<<24)+(r<<16)+(e<<8)+t).toString(16).slice(1),v=({r:r,g:e,b:t,a:a})=>"number"==typeof a&&!1===isNaN(a)?`rgba(${r}, ${e}, ${t}, ${o(a,100,0)/100})`:`rgb(${r}, ${e}, ${t})`,f=r=>r.a<100?v(r):d(r),w=({h:r,s:e,l:t})=>{let a=t/100,n=e/100*(1-Math.abs(2*a-1)),o=r/60,s=n*(1-Math.abs(o%2-1)),i=a-n/2;return n=255*(n+i)|0,s=255*(s+i)|0,i=255*i|0,o>=0&&o<1?{r:n,g:s,b:i}:o>=1&&o<2?{r:s,g:n,b:i}:o>=2&&o<3?{r:i,g:n,b:s}:o>=3&&o<4?{r:i,g:s,b:n}:o>=4&&o<5?{r:s,g:i,b:n}:o>=5&&o<6?{r:n,g:i,b:s}:{r:0,g:0,b:0}},y=(r,e=null)=>{if(!0!==(r=>/(^#{0,1}[0-9A-F]{6}$)|(^#{0,1}[0-9A-F]{3}$)/i.test(r))(r))return e;return"#"===r[0]&&(r=r.slice(1,r.length)),3===r.length&&(r=r.replace(/([0-9A-F])([0-9A-F])([0-9A-F])/i,"$1$1$2$2$3$3")),{r:parseInt(r.substr(0,2),16),g:parseInt(r.substr(2,2),16),b:parseInt(r.substr(4,2),16)}},m=r=>{const e=y(r)||{r:0,g:0,b:0};return h(e)},A={h:0,s:50,v:50,a:100,r:128,g:64,b:64,hex:"804040",str:"#804040"},x=(r,e,t)=>{(r=>u(r,255))(t)&&r(r=>{const{r:a,g:n,b:o,a:s}=Object.assign(Object.assign({},r),{[e]:t}),{h:i,s:l,v:c}=h({r:a,g:n,b:o});return{r:a,g:n,b:o,a:s,h:i,s:l,v:c,hex:d({r:a,g:n,b:o},!1),str:f({r:a,g:n,b:o,a:s})}})},V=(r,e,t,a=100)=>{u(t,a)&&r(r=>{const{h:a,s:n,v:o,a:s}=Object.assign(Object.assign({},r),{[e]:t}),{r:i,g:l,b:c}=b({h:a,s:n,v:o});return{h:a,s:n,v:o,r:i,g:l,b:c,a:s,hex:d({r:i,g:l,b:c},!1),str:f({r:i,g:l,b:c,a:s})}})},S=(r,e,t,a=100)=>{r(r=>{const{h:n,s:s,v:i,a:l}=Object.assign(Object.assign({},r),{[e]:o(r[e]+t,a,0)}),{r:c,g:u,b:g}=b({h:n,s:s,v:i});return{h:n,s:s,v:i,r:c,g:u,b:g,a:l,hex:d({r:c,g:u,b:g},!1),str:f({r:c,g:u,b:g,a:l})}})},O=t=>{const[a,n]=r(t.defaultValue||A);e(()=>{t.value&&n(t.value)},[t.value]);const s=r=>{if("function"==typeof t.onChange){if(void 0!==t.value)return void t.onChange("function"==typeof r?r(a):r);t.onChange("function"==typeof r?r(a):r)}n(r)};return{setH:r=>V(s,"h",r,359),setS:r=>V(s,"s",r),setV:r=>V(s,"v",r),setR:r=>x(s,"r",r),setG:r=>x(s,"g",r),setB:r=>x(s,"b",r),setA:r=>{u(r,100)&&s(e=>{const t=Object.assign(Object.assign({},e),{a:r});return t.str=f(t),t})},setSV:(r,e)=>{(u(r,100)||u(e,100))&&s(t=>{const{h:a,a:n}=t,{r:o,g:s,b:i}=b({h:a,s:r,v:e}),l=d({r:o,g:s,b:i},!1),c=f({r:o,g:s,b:i,a:n});return{h:a,s:r,v:e,r:o,g:s,b:i,a:n,hex:l,str:c}})},setHex:(r,e={r:a.r,g:a.g,b:a.b})=>{s(({a:t})=>{const{r:a,g:n,b:o}=y(r,e),{h:s,s:i,v:l}=h({r:a,g:n,b:o}),c=f({r:a,g:n,b:o,a:t});return{r:a,g:n,b:o,h:s,s:i,v:l,hex:r,a:t,str:c}})},rotateH:r=>S(s,"h",r,359),rotateS:r=>S(s,"s",r),rotateV:r=>S(s,"v",r),rotateA:r=>{s(e=>Object.assign(Object.assign({},e),{a:o(e.a+r,100,0)}))},color:a,getSolidColor:()=>g({h:a.h,s:100,v:100})}},P="Saturation and brightness",k="Saturation {0} brightness {1}",j="Use left and right arrow keys to set saturation. Use up and down arrow keys to set brightness.",C=({state:r,ref:e,ariaDescription:a=j,ariaLabel:o=P,ariaValueFormat:s=k})=>{const i=t(!1),c=r.color,u=s.replace("{0}",String(c.s)).replace("{1}",String(c.v)),{sliderProps:b}=l({ref:e,maxValue:100,direction:"both",ariaLabel:o,ariaValueText:u,ariaValueNow:i.current?c.s:c.v,onChange({x:e,y:t}){t=100-t,r.setSV(e,t)}});return{containerProps:Object.assign(Object.assign({},b),{onKeyDown:e=>{e.key!==n.Tab&&e.preventDefault();const t=e.shiftKey?10:1;switch(e.key){case n.ArrowUp:i.current=!1,r.rotateV(t);break;case n.ArrowDown:i.current=!1,r.rotateV(-t);break;case n.ArrowLeft:i.current=!0,r.rotateS(-t);break;case n.ArrowRight:i.current=!0,r.rotateS(t);break;case n.Home:i.current=!0,r.setS(0);break;case n.End:i.current=!0,r.setS(100);break;case n.PageUp:i.current=!1,r.setV(100);break;case n.PageDown:i.current=!1,r.setV(0)}},"aria-describedby":"color-picker-desc",id:"color-rectangle1"}),descriptionProps:{id:"color-picker-desc",children:a}}},D=({state:r,ref:e})=>{const{sliderProps:t}=l({ref:e,direction:"horizontal",onChange:e=>r.setH(e),onStep:e=>r.rotateH(e),maxValue:359,ariaLabel:"Hue slider",ariaValueNow:r.color.h,ariaValueText:String(r.color.h)});return{sliderProps:t}};export{m as hex2Hsv,y as hex2Rgb,w as hsl2Rgb,g as hsv2Hex,b as hsv2Rgb,d as rgb2Hex,p as rgb2Hsl,h as rgb2Hsv,v as rgba2RgbStr,f as rgba2Str,c as useAlpha,C as useColorRectangle,O as useColorState,D as useHue,l as useSlider};
import{useState as r,useEffect as e,useRef as t}from"react";var n;!function(r){r.PageUp="PageUp",r.PageDown="PageDown",r.End="End",r.Home="Home",r.ArrowLeft="ArrowLeft",r.ArrowUp="ArrowUp",r.ArrowRight="ArrowRight",r.ArrowDown="ArrowDown",r.Tab="Tab"}(n||(n={}));var a=n;function o(r=0,e,t=0){return r<t?t:r>e?e:r}const s=(r,e,t,n)=>{let a=(r.clientX-e.left)/e.width;return a=o(Math.round(a*t),t,n),a},i=(r,e,t,n)=>{let a=(r.clientY-e.top)/e.height;return a=o(Math.round(a*t),t,n),a},c=r=>{var{ref:e,onStep:t,ariaLabel:n,ariaValueNow:o,ariaValueText:c,maxValue:l=100,minValue:u=0,step:b=1,bigStep:g=10}=r,h=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(null!=r&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(r);a<n.length;a++)e.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(r,n[a])&&(t[n[a]]=r[n[a]])}return t}(r,["ref","onStep","ariaLabel","ariaValueNow","ariaValueText","maxValue","minValue","step","bigStep"]);const p=r=>{if(!e.current||"function"!=typeof h.onChange)return;r.preventDefault();const t=e.current.getBoundingClientRect();if("both"===h.direction){let e=s(r,t,l,u),n=i(r,t,l,u);return h.onChange({x:e,y:n})}if("horizontal"===h.direction){let e=s(r,t,l,u);return h.onChange(e)}if("vertical"===h.direction){let e=i(r,t,l,u);return h.onChange(e)}};return{sliderProps:{tabIndex:0,onPointerDown:r=>{var t;e.current&&(r.preventDefault(),e.current.focus(),document.body.style.touchAction="none",e.current.onpointermove=p,null===(t=e.current)||void 0===t||t.setPointerCapture(r.pointerId),p(r))},onPointerUp:r=>{e.current&&(e.current.onpointermove=null,e.current.releasePointerCapture(r.pointerId),document.body.style.touchAction="auto")},onKeyDown:r=>{var e,n;r.key!==a.Tab&&r.preventDefault();let o=r.shiftKey?g:b;switch(r.key){case a.ArrowLeft:case a.ArrowDown:null==t||t(-o);break;case a.ArrowRight:case a.ArrowUp:null==t||t(o);break;case a.Home:"vertical"!==h.direction&&"horizontal"!==h.direction||null===(e=h.onChange)||void 0===e||e.call(h,u);break;case a.End:"vertical"!==h.direction&&"horizontal"!==h.direction||null===(n=h.onChange)||void 0===n||n.call(h,l);break;default:return}},role:"slider","aria-valuemin":u,"aria-valuemax":l,"aria-label":n,"aria-valuenow":o,"aria-valuetext":c}}},l=({state:r,ref:e})=>{const{sliderProps:t}=c({ref:e,direction:"horizontal",onChange:e=>r.setA(e),onStep:e=>r.rotateA(e),maxValue:100,ariaLabel:"Alpha slider",ariaValueNow:r.color.a,ariaValueText:String(r.color.a)});return{sliderProps:t}},u=(r,e,t=0)=>(r=>"number"==typeof r&&!1===isNaN(r))(r)&&r>=t&&r<=e,b=r=>{const{h:e,s:t,v:n}=(({h:r,s:e,v:t})=>({h:o(r,359,0),s:o(e,100,0),v:o(t,100,0)}))(r);let a=n/100,s=t/100*a,i=e/60,c=s*(1-Math.abs(i%2-1)),l=a-s;return s=255*(s+l)|0,c=255*(c+l)|0,l=255*l|0,i>=0&&i<1?{r:s,g:c,b:l}:i>=1&&i<2?{r:c,g:s,b:l}:i>=2&&i<3?{r:l,g:s,b:c}:i>=3&&i<4?{r:l,g:c,b:s}:i>=4&&i<5?{r:c,g:l,b:s}:i>=5&&i<6?{r:s,g:l,b:c}:{r:0,g:0,b:0}},g=({h:r,s:e,v:t})=>{let{r:n,g:a,b:o}=b({h:r,s:e,v:t});return d({r:n,g:a,b:o})},h=r=>{const{r:e,g:t,b:n}=(({r:r,g:e,b:t})=>({r:o(r,255,0),g:o(e,255,0),b:o(t,255,0)}))(r);let a=e/255,s=t/255,i=n/255,c=Math.max(a,s,i),l=c-Math.min(a,s,i),u=0,b=0,g=0;return l&&(c===a&&(u=(s-i)/l),c===s&&(u=2+(i-a)/l),c===i&&(u=4+(a-s)/l),c&&(b=l/c)),u=60*u|0,u<0&&(u+=360),b=100*b|0,g=100*c|0,{h:u,s:b,v:g}},p=({r:r,g:e,b:t})=>{let n=r/255,a=e/255,o=t/255,s=Math.max(n,a,o),i=Math.min(n,a,o),c=s-i,l=0,u=0,b=(s+i)/2,g=1-Math.abs(2*b-1);return c&&(s===n&&(l=(a-o)/c),s===a&&(l=2+(o-n)/c),s===o&&(l=4+(n-a)/c),s&&(u=c/g)),l=60*l|0,l<0&&(l+=360),u=100*u|0,b=100*b|0,{h:l,s:u,l:b}},d=({r:r,g:e,b:t},n=!0)=>(n?"#":"")+((1<<24)+(r<<16)+(e<<8)+t).toString(16).slice(1),f=({r:r,g:e,b:t,a:n})=>"number"==typeof n&&!1===isNaN(n)?`rgba(${r}, ${e}, ${t}, ${o(n,100,0)/100})`:`rgb(${r}, ${e}, ${t})`,v=r=>r.a<100?f(r):d(r),m=({h:r,s:e,l:t})=>{let n=t/100,a=e/100*(1-Math.abs(2*n-1)),o=r/60,s=a*(1-Math.abs(o%2-1)),i=n-a/2;return a=255*(a+i)|0,s=255*(s+i)|0,i=255*i|0,o>=0&&o<1?{r:a,g:s,b:i}:o>=1&&o<2?{r:s,g:a,b:i}:o>=2&&o<3?{r:i,g:a,b:s}:o>=3&&o<4?{r:i,g:s,b:a}:o>=4&&o<5?{r:s,g:i,b:a}:o>=5&&o<6?{r:a,g:i,b:s}:{r:0,g:0,b:0}},w=(r,e=null)=>{if(!0!==(r=>/(^#{0,1}[0-9A-F]{6}$)|(^#{0,1}[0-9A-F]{3}$)/i.test(r))(r))return e;return"#"===r[0]&&(r=r.slice(1,r.length)),3===r.length&&(r=r.replace(/([0-9A-F])([0-9A-F])([0-9A-F])/i,"$1$1$2$2$3$3")),{r:parseInt(r.substr(0,2),16),g:parseInt(r.substr(2,2),16),b:parseInt(r.substr(4,2),16)}},y=r=>{const e=w(r)||{r:0,g:0,b:0};return h(e)},x={h:0,s:50,v:50,a:100,r:128,g:64,b:64,hex:"804040",str:"#804040"},A=(r,e,t)=>{(r=>u(r,255))(t)&&r(r=>{const{r:n,g:a,b:o,a:s}=Object.assign(Object.assign({},r),{[e]:t}),{h:i,s:c,v:l}=h({r:n,g:a,b:o});return{r:n,g:a,b:o,a:s,h:i,s:c,v:l,hex:d({r:n,g:a,b:o},!1),str:v({r:n,g:a,b:o,a:s})}})},V=(r,e,t,n=100)=>{u(t,n)&&r(r=>{const{h:n,s:a,v:o,a:s}=Object.assign(Object.assign({},r),{[e]:t}),{r:i,g:c,b:l}=b({h:n,s:a,v:o});return{h:n,s:a,v:o,r:i,g:c,b:l,a:s,hex:d({r:i,g:c,b:l},!1),str:v({r:i,g:c,b:l,a:s})}})},S=(r,e,t,n=100)=>{r(r=>{const{h:a,s:s,v:i,a:c}=Object.assign(Object.assign({},r),{[e]:o(r[e]+t,n,0)}),{r:l,g:u,b:g}=b({h:a,s:s,v:i});return{h:a,s:s,v:i,r:l,g:u,b:g,a:c,hex:d({r:l,g:u,b:g},!1),str:v({r:l,g:u,b:g,a:c})}})},O=t=>{const[n,a]=r(t.defaultValue||x);e(()=>{t.value&&a(t.value)},[t.value]);const s=r=>{if("function"==typeof t.onChange){if(void 0!==t.value)return void t.onChange("function"==typeof r?r(n):r);t.onChange("function"==typeof r?r(n):r)}a(r)};return{setH:r=>V(s,"h",r,359),setS:r=>V(s,"s",r),setV:r=>V(s,"v",r),setR:r=>A(s,"r",r),setG:r=>A(s,"g",r),setB:r=>A(s,"b",r),setA:r=>{u(r,100)&&s(e=>{const t=Object.assign(Object.assign({},e),{a:r});return t.str=v(t),t})},setSV:(r,e)=>{(u(r,100)||u(e,100))&&s(t=>{const{h:n,a:a}=t,{r:o,g:s,b:i}=b({h:n,s:r,v:e}),c=d({r:o,g:s,b:i},!1),l=v({r:o,g:s,b:i,a:a});return{h:n,s:r,v:e,r:o,g:s,b:i,a:a,hex:c,str:l}})},setHex:(r,e={r:n.r,g:n.g,b:n.b})=>{s(({a:t})=>{const{r:n,g:a,b:o}=w(r,e),{h:s,s:i,v:c}=h({r:n,g:a,b:o}),l=v({r:n,g:a,b:o,a:t});return{r:n,g:a,b:o,h:s,s:i,v:c,hex:r,a:t,str:l}})},rotateH:r=>S(s,"h",r,359),rotateS:r=>S(s,"s",r),rotateV:r=>S(s,"v",r),rotateA:r=>{s(e=>Object.assign(Object.assign({},e),{a:o(e.a+r,100,0)}))},color:n,getSolidColor:()=>g({h:n.h,s:100,v:100})}},k="Saturation and brightness",C="Saturation {0} brightness {1}",P="Use left and right arrow keys to set saturation. Use up and down arrow keys to set brightness.",$=({state:r,ref:e,ariaDescription:n=P,ariaLabel:o=k,ariaValueFormat:s=C})=>{const i=t(!1),l=r.color,u=s.replace("{0}",String(l.s)).replace("{1}",String(l.v)),{sliderProps:b}=c({ref:e,maxValue:100,direction:"both",ariaLabel:o,ariaValueText:u,ariaValueNow:i.current?l.s:l.v,onChange({x:e,y:t}){t=100-t,r.setSV(e,t)}});return{containerProps:Object.assign(Object.assign({},b),{onKeyDown:e=>{e.key!==a.Tab&&e.preventDefault();const t=e.shiftKey?10:1;switch(e.key){case a.ArrowUp:i.current=!1,r.rotateV(t);break;case a.ArrowDown:i.current=!1,r.rotateV(-t);break;case a.ArrowLeft:i.current=!0,r.rotateS(-t);break;case a.ArrowRight:i.current=!0,r.rotateS(t);break;case a.Home:i.current=!0,r.setS(0);break;case a.End:i.current=!0,r.setS(100);break;case a.PageUp:i.current=!1,r.setV(100);break;case a.PageDown:i.current=!1,r.setV(0)}},"aria-describedby":"color-picker-desc",id:"color-rectangle1"}),descriptionProps:{id:"color-picker-desc",children:n}}},j=({state:r,ref:e})=>{const{sliderProps:t}=c({ref:e,direction:"horizontal",onChange:e=>r.setH(e),onStep:e=>r.rotateH(e),maxValue:359,ariaLabel:"Hue slider",ariaValueNow:r.color.h,ariaValueText:String(r.color.h)});return{sliderProps:t}};function D(r){if(!r)return;const e=I(r)||function(r){if("#"===r[0]&&7===r.length&&/^#[\da-fA-F]{6}$/.test(r))return{r:parseInt(r.slice(1,3),16),g:parseInt(r.slice(3,5),16),b:parseInt(r.slice(5,7),16),a:100}}(r)||function(r){if("#"===r[0]&&4===r.length&&/^#[\da-fA-F]{3}$/.test(r))return{r:parseInt(r[1]+r[1],16),g:parseInt(r[2]+r[2],16),b:parseInt(r[3]+r[3],16),a:100}}(r)||function(r){const e=r.match(/^hsl(a?)\(([\d., ]+)\)$/);if(e){const r=!!e[1],t=r?4:3,n=e[2].split(/ *, */).map(Number);if(n.length===t){const e=m({h:n[0],s:n[1],l:n[2]});return e.a=r?100*n[3]:100,e}}}(r);return e||function(r){if("undefined"==typeof document)return;const e=document.createElement("div");e.style.backgroundColor=r,e.style.position="absolute",e.style.top="-9999px",e.style.left="-9999px",e.style.height="1px",e.style.width="1px",document.body.appendChild(e);const t=getComputedStyle(e),n=t&&t.backgroundColor;if(document.body.removeChild(e),"rgba(0, 0, 0, 0)"===n||"transparent"===n){switch(r.trim()){case"transparent":case"#0000":case"#00000000":return{r:0,g:0,b:0,a:0}}return}return I(n)}(r)}function I(r){if(!r)return;const e=r.match(/^rgb(a?)\(([\d., ]+)\)$/);if(e){const r=!!e[1],t=r?4:3,n=e[2].split(/ *, */).map(Number);if(n.length===t)return{r:n[0],g:n[1],b:n[2],a:r?100*n[3]:100}}}function N(r){const e=D(r);if(e)return Object.assign(Object.assign({},(({r:r,g:e,b:t,a:n})=>{const{h:a,s:o,v:s}=h({r:r,g:e,b:t});return{r:r,g:e,b:t,a:n,h:a,s:o,v:s,hex:d({r:r,g:e,b:t},!1),str:v({r:r,g:e,b:t,a:n})}})(e)),{str:r})}export{y as hex2Hsv,w as hex2Rgb,m as hsl2Rgb,g as hsv2Hex,b as hsv2Rgb,d as rgb2Hex,p as rgb2Hsl,h as rgb2Hsv,f as rgba2RgbStr,v as rgba2Str,N as str2Color,l as useAlpha,$ as useColorRectangle,O as useColorState,j as useHue,c as useSlider};
//# sourceMappingURL=index.esm.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");var r;!function(e){e.PageUp="PageUp",e.PageDown="PageDown",e.End="End",e.Home="Home",e.ArrowLeft="ArrowLeft",e.ArrowUp="ArrowUp",e.ArrowRight="ArrowRight",e.ArrowDown="ArrowDown",e.Tab="Tab"}(r||(r={}));var t=r;function a(e=0,r,t=0){return e<t?t:e>r?r:e}const n=(e,r,t,n)=>{let o=(e.clientX-r.left)/r.width;return o=a(Math.round(o*t),t,n),o},o=(e,r,t,n)=>{let o=(e.clientY-r.top)/r.height;return o=a(Math.round(o*t),t,n),o},s=e=>{var{ref:r,onStep:a,ariaLabel:s,ariaValueNow:i,ariaValueText:l,maxValue:c=100,minValue:u=0,step:b=1,bigStep:g=10}=e,h=function(e,r){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&r.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(a=Object.getOwnPropertySymbols(e);n<a.length;n++)r.indexOf(a[n])<0&&Object.prototype.propertyIsEnumerable.call(e,a[n])&&(t[a[n]]=e[a[n]])}return t}(e,["ref","onStep","ariaLabel","ariaValueNow","ariaValueText","maxValue","minValue","step","bigStep"]);const p=e=>{if(!r.current||"function"!=typeof h.onChange)return;e.preventDefault();const t=r.current.getBoundingClientRect();if("both"===h.direction){let r=n(e,t,c,u),a=o(e,t,c,u);return h.onChange({x:r,y:a})}if("horizontal"===h.direction){let r=n(e,t,c,u);return h.onChange(r)}if("vertical"===h.direction){let r=o(e,t,c,u);return h.onChange(r)}};return{sliderProps:{tabIndex:0,onPointerDown:e=>{var t;r.current&&(e.preventDefault(),r.current.focus(),document.body.style.touchAction="none",r.current.onpointermove=p,null===(t=r.current)||void 0===t||t.setPointerCapture(e.pointerId),p(e))},onPointerUp:e=>{r.current&&(r.current.onpointermove=null,r.current.releasePointerCapture(e.pointerId),document.body.style.touchAction="auto")},onKeyDown:e=>{var r,n;e.key!==t.Tab&&e.preventDefault();let o=e.shiftKey?g:b;switch(e.key){case t.ArrowLeft:case t.ArrowDown:null==a||a(-o);break;case t.ArrowRight:case t.ArrowUp:null==a||a(o);break;case t.Home:"vertical"!==h.direction&&"horizontal"!==h.direction||null===(r=h.onChange)||void 0===r||r.call(h,u);break;case t.End:"vertical"!==h.direction&&"horizontal"!==h.direction||null===(n=h.onChange)||void 0===n||n.call(h,c);break;default:return}},role:"slider","aria-valuemin":u,"aria-valuemax":c,"aria-label":s,"aria-valuenow":i,"aria-valuetext":l}}},i=(e,r,t=0)=>(e=>"number"==typeof e&&!1===isNaN(e))(e)&&e>=t&&e<=r,l=e=>{const{h:r,s:t,v:n}=(({h:e,s:r,v:t})=>({h:a(e,359,0),s:a(r,100,0),v:a(t,100,0)}))(e);let o=n/100,s=t/100*o,i=r/60,l=s*(1-Math.abs(i%2-1)),c=o-s;return s=255*(s+c)|0,l=255*(l+c)|0,c=255*c|0,i>=0&&i<1?{r:s,g:l,b:c}:i>=1&&i<2?{r:l,g:s,b:c}:i>=2&&i<3?{r:c,g:s,b:l}:i>=3&&i<4?{r:c,g:l,b:s}:i>=4&&i<5?{r:l,g:c,b:s}:i>=5&&i<6?{r:s,g:c,b:l}:{r:0,g:0,b:0}},c=({h:e,s:r,v:t})=>{let{r:a,g:n,b:o}=l({h:e,s:r,v:t});return b({r:a,g:n,b:o})},u=e=>{const{r:r,g:t,b:n}=(({r:e,g:r,b:t})=>({r:a(e,255,0),g:a(r,255,0),b:a(t,255,0)}))(e);let o=r/255,s=t/255,i=n/255,l=Math.max(o,s,i),c=l-Math.min(o,s,i),u=0,b=0,g=0;return c&&(l===o&&(u=(s-i)/c),l===s&&(u=2+(i-o)/c),l===i&&(u=4+(o-s)/c),l&&(b=c/l)),u=60*u|0,u<0&&(u+=360),b=100*b|0,g=100*l|0,{h:u,s:b,v:g}},b=({r:e,g:r,b:t},a=!0)=>(a?"#":"")+((1<<24)+(e<<16)+(r<<8)+t).toString(16).slice(1),g=({r:e,g:r,b:t,a:n})=>"number"==typeof n&&!1===isNaN(n)?`rgba(${e}, ${r}, ${t}, ${a(n,100,0)/100})`:`rgb(${e}, ${r}, ${t})`,h=e=>e.a<100?g(e):b(e),p=(e,r=null)=>{if(!0!==(e=>/(^#{0,1}[0-9A-F]{6}$)|(^#{0,1}[0-9A-F]{3}$)/i.test(e))(e))return r;return"#"===e[0]&&(e=e.slice(1,e.length)),3===e.length&&(e=e.replace(/([0-9A-F])([0-9A-F])([0-9A-F])/i,"$1$1$2$2$3$3")),{r:parseInt(e.substr(0,2),16),g:parseInt(e.substr(2,2),16),b:parseInt(e.substr(4,2),16)}},v={h:0,s:50,v:50,a:100,r:128,g:64,b:64,hex:"804040",str:"#804040"},d=(e,r,t)=>{(e=>i(e,255))(t)&&e(e=>{const{r:a,g:n,b:o,a:s}=Object.assign(Object.assign({},e),{[r]:t}),{h:i,s:l,v:c}=u({r:a,g:n,b:o});return{r:a,g:n,b:o,a:s,h:i,s:l,v:c,hex:b({r:a,g:n,b:o},!1),str:h({r:a,g:n,b:o,a:s})}})},f=(e,r,t,a=100)=>{i(t,a)&&e(e=>{const{h:a,s:n,v:o,a:s}=Object.assign(Object.assign({},e),{[r]:t}),{r:i,g:c,b:u}=l({h:a,s:n,v:o});return{h:a,s:n,v:o,r:i,g:c,b:u,a:s,hex:b({r:i,g:c,b:u},!1),str:h({r:i,g:c,b:u,a:s})}})},x=(e,r,t,n=100)=>{e(e=>{const{h:o,s:s,v:i,a:c}=Object.assign(Object.assign({},e),{[r]:a(e[r]+t,n,0)}),{r:u,g:g,b:p}=l({h:o,s:s,v:i});return{h:o,s:s,v:i,r:u,g:g,b:p,a:c,hex:b({r:u,g:g,b:p},!1),str:h({r:u,g:g,b:p,a:c})}})},w="Saturation and brightness",y="Saturation {0} brightness {1}",A="Use left and right arrow keys to set saturation. Use up and down arrow keys to set brightness.";exports.hex2Hsv=e=>{const r=p(e)||{r:0,g:0,b:0};return u(r)},exports.hex2Rgb=p,exports.hsl2Rgb=({h:e,s:r,l:t})=>{let a=t/100,n=r/100*(1-Math.abs(2*a-1)),o=e/60,s=n*(1-Math.abs(o%2-1)),i=a-n/2;return n=255*(n+i)|0,s=255*(s+i)|0,i=255*i|0,o>=0&&o<1?{r:n,g:s,b:i}:o>=1&&o<2?{r:s,g:n,b:i}:o>=2&&o<3?{r:i,g:n,b:s}:o>=3&&o<4?{r:i,g:s,b:n}:o>=4&&o<5?{r:s,g:i,b:n}:o>=5&&o<6?{r:n,g:i,b:s}:{r:0,g:0,b:0}},exports.hsv2Hex=c,exports.hsv2Rgb=l,exports.rgb2Hex=b,exports.rgb2Hsl=({r:e,g:r,b:t})=>{let a=e/255,n=r/255,o=t/255,s=Math.max(a,n,o),i=Math.min(a,n,o),l=s-i,c=0,u=0,b=(s+i)/2,g=1-Math.abs(2*b-1);return l&&(s===a&&(c=(n-o)/l),s===n&&(c=2+(o-a)/l),s===o&&(c=4+(a-n)/l),s&&(u=l/g)),c=60*c|0,c<0&&(c+=360),u=100*u|0,b=100*b|0,{h:c,s:u,l:b}},exports.rgb2Hsv=u,exports.rgba2RgbStr=g,exports.rgba2Str=h,exports.useAlpha=({state:e,ref:r})=>{const{sliderProps:t}=s({ref:r,direction:"horizontal",onChange:r=>e.setA(r),onStep:r=>e.rotateA(r),maxValue:100,ariaLabel:"Alpha slider",ariaValueNow:e.color.a,ariaValueText:String(e.color.a)});return{sliderProps:t}},exports.useColorRectangle=({state:r,ref:a,ariaDescription:n=A,ariaLabel:o=w,ariaValueFormat:i=y})=>{const l=e.useRef(!1),c=r.color,u=i.replace("{0}",String(c.s)).replace("{1}",String(c.v)),{sliderProps:b}=s({ref:a,maxValue:100,direction:"both",ariaLabel:o,ariaValueText:u,ariaValueNow:l.current?c.s:c.v,onChange({x:e,y:t}){t=100-t,r.setSV(e,t)}});return{containerProps:Object.assign(Object.assign({},b),{onKeyDown:e=>{e.key!==t.Tab&&e.preventDefault();const a=e.shiftKey?10:1;switch(e.key){case t.ArrowUp:l.current=!1,r.rotateV(a);break;case t.ArrowDown:l.current=!1,r.rotateV(-a);break;case t.ArrowLeft:l.current=!0,r.rotateS(-a);break;case t.ArrowRight:l.current=!0,r.rotateS(a);break;case t.Home:l.current=!0,r.setS(0);break;case t.End:l.current=!0,r.setS(100);break;case t.PageUp:l.current=!1,r.setV(100);break;case t.PageDown:l.current=!1,r.setV(0)}},"aria-describedby":"color-picker-desc",id:"color-rectangle1"}),descriptionProps:{id:"color-picker-desc",children:n}}},exports.useColorState=r=>{const[t,n]=e.useState(r.defaultValue||v);e.useEffect(()=>{r.value&&n(r.value)},[r.value]);const o=e=>{if("function"==typeof r.onChange){if(void 0!==r.value)return void r.onChange("function"==typeof e?e(t):e);r.onChange("function"==typeof e?e(t):e)}n(e)};return{setH:e=>f(o,"h",e,359),setS:e=>f(o,"s",e),setV:e=>f(o,"v",e),setR:e=>d(o,"r",e),setG:e=>d(o,"g",e),setB:e=>d(o,"b",e),setA:e=>{i(e,100)&&o(r=>{const t=Object.assign(Object.assign({},r),{a:e});return t.str=h(t),t})},setSV:(e,r)=>{(i(e,100)||i(r,100))&&o(t=>{const{h:a,a:n}=t,{r:o,g:s,b:i}=l({h:a,s:e,v:r}),c=b({r:o,g:s,b:i},!1),u=h({r:o,g:s,b:i,a:n});return{h:a,s:e,v:r,r:o,g:s,b:i,a:n,hex:c,str:u}})},setHex:(e,r={r:t.r,g:t.g,b:t.b})=>{o(({a:t})=>{const{r:a,g:n,b:o}=p(e,r),{h:s,s:i,v:l}=u({r:a,g:n,b:o}),c=h({r:a,g:n,b:o,a:t});return{r:a,g:n,b:o,h:s,s:i,v:l,hex:e,a:t,str:c}})},rotateH:e=>x(o,"h",e,359),rotateS:e=>x(o,"s",e),rotateV:e=>x(o,"v",e),rotateA:e=>{o(r=>Object.assign(Object.assign({},r),{a:a(r.a+e,100,0)}))},color:t,getSolidColor:()=>c({h:t.h,s:100,v:100})}},exports.useHue=({state:e,ref:r})=>{const{sliderProps:t}=s({ref:r,direction:"horizontal",onChange:r=>e.setH(r),onStep:r=>e.rotateH(r),maxValue:359,ariaLabel:"Hue slider",ariaValueNow:e.color.h,ariaValueText:String(e.color.h)});return{sliderProps:t}},exports.useSlider=s;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");var r;!function(e){e.PageUp="PageUp",e.PageDown="PageDown",e.End="End",e.Home="Home",e.ArrowLeft="ArrowLeft",e.ArrowUp="ArrowUp",e.ArrowRight="ArrowRight",e.ArrowDown="ArrowDown",e.Tab="Tab"}(r||(r={}));var t=r;function a(e=0,r,t=0){return e<t?t:e>r?r:e}const n=(e,r,t,n)=>{let o=(e.clientX-r.left)/r.width;return o=a(Math.round(o*t),t,n),o},o=(e,r,t,n)=>{let o=(e.clientY-r.top)/r.height;return o=a(Math.round(o*t),t,n),o},s=e=>{var{ref:r,onStep:a,ariaLabel:s,ariaValueNow:i,ariaValueText:c,maxValue:l=100,minValue:u=0,step:b=1,bigStep:g=10}=e,h=function(e,r){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&r.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(a=Object.getOwnPropertySymbols(e);n<a.length;n++)r.indexOf(a[n])<0&&Object.prototype.propertyIsEnumerable.call(e,a[n])&&(t[a[n]]=e[a[n]])}return t}(e,["ref","onStep","ariaLabel","ariaValueNow","ariaValueText","maxValue","minValue","step","bigStep"]);const p=e=>{if(!r.current||"function"!=typeof h.onChange)return;e.preventDefault();const t=r.current.getBoundingClientRect();if("both"===h.direction){let r=n(e,t,l,u),a=o(e,t,l,u);return h.onChange({x:r,y:a})}if("horizontal"===h.direction){let r=n(e,t,l,u);return h.onChange(r)}if("vertical"===h.direction){let r=o(e,t,l,u);return h.onChange(r)}};return{sliderProps:{tabIndex:0,onPointerDown:e=>{var t;r.current&&(e.preventDefault(),r.current.focus(),document.body.style.touchAction="none",r.current.onpointermove=p,null===(t=r.current)||void 0===t||t.setPointerCapture(e.pointerId),p(e))},onPointerUp:e=>{r.current&&(r.current.onpointermove=null,r.current.releasePointerCapture(e.pointerId),document.body.style.touchAction="auto")},onKeyDown:e=>{var r,n;e.key!==t.Tab&&e.preventDefault();let o=e.shiftKey?g:b;switch(e.key){case t.ArrowLeft:case t.ArrowDown:null==a||a(-o);break;case t.ArrowRight:case t.ArrowUp:null==a||a(o);break;case t.Home:"vertical"!==h.direction&&"horizontal"!==h.direction||null===(r=h.onChange)||void 0===r||r.call(h,u);break;case t.End:"vertical"!==h.direction&&"horizontal"!==h.direction||null===(n=h.onChange)||void 0===n||n.call(h,l);break;default:return}},role:"slider","aria-valuemin":u,"aria-valuemax":l,"aria-label":s,"aria-valuenow":i,"aria-valuetext":c}}},i=(e,r,t=0)=>(e=>"number"==typeof e&&!1===isNaN(e))(e)&&e>=t&&e<=r,c=e=>{const{h:r,s:t,v:n}=(({h:e,s:r,v:t})=>({h:a(e,359,0),s:a(r,100,0),v:a(t,100,0)}))(e);let o=n/100,s=t/100*o,i=r/60,c=s*(1-Math.abs(i%2-1)),l=o-s;return s=255*(s+l)|0,c=255*(c+l)|0,l=255*l|0,i>=0&&i<1?{r:s,g:c,b:l}:i>=1&&i<2?{r:c,g:s,b:l}:i>=2&&i<3?{r:l,g:s,b:c}:i>=3&&i<4?{r:l,g:c,b:s}:i>=4&&i<5?{r:c,g:l,b:s}:i>=5&&i<6?{r:s,g:l,b:c}:{r:0,g:0,b:0}},l=({h:e,s:r,v:t})=>{let{r:a,g:n,b:o}=c({h:e,s:r,v:t});return b({r:a,g:n,b:o})},u=e=>{const{r:r,g:t,b:n}=(({r:e,g:r,b:t})=>({r:a(e,255,0),g:a(r,255,0),b:a(t,255,0)}))(e);let o=r/255,s=t/255,i=n/255,c=Math.max(o,s,i),l=c-Math.min(o,s,i),u=0,b=0,g=0;return l&&(c===o&&(u=(s-i)/l),c===s&&(u=2+(i-o)/l),c===i&&(u=4+(o-s)/l),c&&(b=l/c)),u=60*u|0,u<0&&(u+=360),b=100*b|0,g=100*c|0,{h:u,s:b,v:g}},b=({r:e,g:r,b:t},a=!0)=>(a?"#":"")+((1<<24)+(e<<16)+(r<<8)+t).toString(16).slice(1),g=({r:e,g:r,b:t,a:n})=>"number"==typeof n&&!1===isNaN(n)?`rgba(${e}, ${r}, ${t}, ${a(n,100,0)/100})`:`rgb(${e}, ${r}, ${t})`,h=e=>e.a<100?g(e):b(e),p=({h:e,s:r,l:t})=>{let a=t/100,n=r/100*(1-Math.abs(2*a-1)),o=e/60,s=n*(1-Math.abs(o%2-1)),i=a-n/2;return n=255*(n+i)|0,s=255*(s+i)|0,i=255*i|0,o>=0&&o<1?{r:n,g:s,b:i}:o>=1&&o<2?{r:s,g:n,b:i}:o>=2&&o<3?{r:i,g:n,b:s}:o>=3&&o<4?{r:i,g:s,b:n}:o>=4&&o<5?{r:s,g:i,b:n}:o>=5&&o<6?{r:n,g:i,b:s}:{r:0,g:0,b:0}},d=(e,r=null)=>{if(!0!==(e=>/(^#{0,1}[0-9A-F]{6}$)|(^#{0,1}[0-9A-F]{3}$)/i.test(e))(e))return r;return"#"===e[0]&&(e=e.slice(1,e.length)),3===e.length&&(e=e.replace(/([0-9A-F])([0-9A-F])([0-9A-F])/i,"$1$1$2$2$3$3")),{r:parseInt(e.substr(0,2),16),g:parseInt(e.substr(2,2),16),b:parseInt(e.substr(4,2),16)}},f={h:0,s:50,v:50,a:100,r:128,g:64,b:64,hex:"804040",str:"#804040"},v=(e,r,t)=>{(e=>i(e,255))(t)&&e(e=>{const{r:a,g:n,b:o,a:s}=Object.assign(Object.assign({},e),{[r]:t}),{h:i,s:c,v:l}=u({r:a,g:n,b:o});return{r:a,g:n,b:o,a:s,h:i,s:c,v:l,hex:b({r:a,g:n,b:o},!1),str:h({r:a,g:n,b:o,a:s})}})},x=(e,r,t,a=100)=>{i(t,a)&&e(e=>{const{h:a,s:n,v:o,a:s}=Object.assign(Object.assign({},e),{[r]:t}),{r:i,g:l,b:u}=c({h:a,s:n,v:o});return{h:a,s:n,v:o,r:i,g:l,b:u,a:s,hex:b({r:i,g:l,b:u},!1),str:h({r:i,g:l,b:u,a:s})}})},w=(e,r,t,n=100)=>{e(e=>{const{h:o,s:s,v:i,a:l}=Object.assign(Object.assign({},e),{[r]:a(e[r]+t,n,0)}),{r:u,g:g,b:p}=c({h:o,s:s,v:i});return{h:o,s:s,v:i,r:u,g:g,b:p,a:l,hex:b({r:u,g:g,b:p},!1),str:h({r:u,g:g,b:p,a:l})}})},y="Saturation and brightness",m="Saturation {0} brightness {1}",A="Use left and right arrow keys to set saturation. Use up and down arrow keys to set brightness.";function S(e){if(!e)return;const r=V(e)||function(e){if("#"===e[0]&&7===e.length&&/^#[\da-fA-F]{6}$/.test(e))return{r:parseInt(e.slice(1,3),16),g:parseInt(e.slice(3,5),16),b:parseInt(e.slice(5,7),16),a:100}}(e)||function(e){if("#"===e[0]&&4===e.length&&/^#[\da-fA-F]{3}$/.test(e))return{r:parseInt(e[1]+e[1],16),g:parseInt(e[2]+e[2],16),b:parseInt(e[3]+e[3],16),a:100}}(e)||function(e){const r=e.match(/^hsl(a?)\(([\d., ]+)\)$/);if(r){const e=!!r[1],t=e?4:3,a=r[2].split(/ *, */).map(Number);if(a.length===t){const r=p({h:a[0],s:a[1],l:a[2]});return r.a=e?100*a[3]:100,r}}}(e);return r||function(e){if("undefined"==typeof document)return;const r=document.createElement("div");r.style.backgroundColor=e,r.style.position="absolute",r.style.top="-9999px",r.style.left="-9999px",r.style.height="1px",r.style.width="1px",document.body.appendChild(r);const t=getComputedStyle(r),a=t&&t.backgroundColor;if(document.body.removeChild(r),"rgba(0, 0, 0, 0)"===a||"transparent"===a){switch(e.trim()){case"transparent":case"#0000":case"#00000000":return{r:0,g:0,b:0,a:0}}return}return V(a)}(e)}function V(e){if(!e)return;const r=e.match(/^rgb(a?)\(([\d., ]+)\)$/);if(r){const e=!!r[1],t=e?4:3,a=r[2].split(/ *, */).map(Number);if(a.length===t)return{r:a[0],g:a[1],b:a[2],a:e?100*a[3]:100}}}exports.hex2Hsv=e=>{const r=d(e)||{r:0,g:0,b:0};return u(r)},exports.hex2Rgb=d,exports.hsl2Rgb=p,exports.hsv2Hex=l,exports.hsv2Rgb=c,exports.rgb2Hex=b,exports.rgb2Hsl=({r:e,g:r,b:t})=>{let a=e/255,n=r/255,o=t/255,s=Math.max(a,n,o),i=Math.min(a,n,o),c=s-i,l=0,u=0,b=(s+i)/2,g=1-Math.abs(2*b-1);return c&&(s===a&&(l=(n-o)/c),s===n&&(l=2+(o-a)/c),s===o&&(l=4+(a-n)/c),s&&(u=c/g)),l=60*l|0,l<0&&(l+=360),u=100*u|0,b=100*b|0,{h:l,s:u,l:b}},exports.rgb2Hsv=u,exports.rgba2RgbStr=g,exports.rgba2Str=h,exports.str2Color=function(e){const r=S(e);if(r)return Object.assign(Object.assign({},(({r:e,g:r,b:t,a:a})=>{const{h:n,s:o,v:s}=u({r:e,g:r,b:t});return{r:e,g:r,b:t,a:a,h:n,s:o,v:s,hex:b({r:e,g:r,b:t},!1),str:h({r:e,g:r,b:t,a:a})}})(r)),{str:e})},exports.useAlpha=({state:e,ref:r})=>{const{sliderProps:t}=s({ref:r,direction:"horizontal",onChange:r=>e.setA(r),onStep:r=>e.rotateA(r),maxValue:100,ariaLabel:"Alpha slider",ariaValueNow:e.color.a,ariaValueText:String(e.color.a)});return{sliderProps:t}},exports.useColorRectangle=({state:r,ref:a,ariaDescription:n=A,ariaLabel:o=y,ariaValueFormat:i=m})=>{const c=e.useRef(!1),l=r.color,u=i.replace("{0}",String(l.s)).replace("{1}",String(l.v)),{sliderProps:b}=s({ref:a,maxValue:100,direction:"both",ariaLabel:o,ariaValueText:u,ariaValueNow:c.current?l.s:l.v,onChange({x:e,y:t}){t=100-t,r.setSV(e,t)}});return{containerProps:Object.assign(Object.assign({},b),{onKeyDown:e=>{e.key!==t.Tab&&e.preventDefault();const a=e.shiftKey?10:1;switch(e.key){case t.ArrowUp:c.current=!1,r.rotateV(a);break;case t.ArrowDown:c.current=!1,r.rotateV(-a);break;case t.ArrowLeft:c.current=!0,r.rotateS(-a);break;case t.ArrowRight:c.current=!0,r.rotateS(a);break;case t.Home:c.current=!0,r.setS(0);break;case t.End:c.current=!0,r.setS(100);break;case t.PageUp:c.current=!1,r.setV(100);break;case t.PageDown:c.current=!1,r.setV(0)}},"aria-describedby":"color-picker-desc",id:"color-rectangle1"}),descriptionProps:{id:"color-picker-desc",children:n}}},exports.useColorState=r=>{const[t,n]=e.useState(r.defaultValue||f);e.useEffect(()=>{r.value&&n(r.value)},[r.value]);const o=e=>{if("function"==typeof r.onChange){if(void 0!==r.value)return void r.onChange("function"==typeof e?e(t):e);r.onChange("function"==typeof e?e(t):e)}n(e)};return{setH:e=>x(o,"h",e,359),setS:e=>x(o,"s",e),setV:e=>x(o,"v",e),setR:e=>v(o,"r",e),setG:e=>v(o,"g",e),setB:e=>v(o,"b",e),setA:e=>{i(e,100)&&o(r=>{const t=Object.assign(Object.assign({},r),{a:e});return t.str=h(t),t})},setSV:(e,r)=>{(i(e,100)||i(r,100))&&o(t=>{const{h:a,a:n}=t,{r:o,g:s,b:i}=c({h:a,s:e,v:r}),l=b({r:o,g:s,b:i},!1),u=h({r:o,g:s,b:i,a:n});return{h:a,s:e,v:r,r:o,g:s,b:i,a:n,hex:l,str:u}})},setHex:(e,r={r:t.r,g:t.g,b:t.b})=>{o(({a:t})=>{const{r:a,g:n,b:o}=d(e,r),{h:s,s:i,v:c}=u({r:a,g:n,b:o}),l=h({r:a,g:n,b:o,a:t});return{r:a,g:n,b:o,h:s,s:i,v:c,hex:e,a:t,str:l}})},rotateH:e=>w(o,"h",e,359),rotateS:e=>w(o,"s",e),rotateV:e=>w(o,"v",e),rotateA:e=>{o(r=>Object.assign(Object.assign({},r),{a:a(r.a+e,100,0)}))},color:t,getSolidColor:()=>l({h:t.h,s:100,v:100})}},exports.useHue=({state:e,ref:r})=>{const{sliderProps:t}=s({ref:r,direction:"horizontal",onChange:r=>e.setH(r),onStep:r=>e.rotateH(r),maxValue:359,ariaLabel:"Hue slider",ariaValueNow:e.color.h,ariaValueText:String(e.color.h)});return{sliderProps:t}},exports.useSlider=s;
//# sourceMappingURL=index.js.map
{
"name": "@atomik-color/core",
"version": "1.0.10",
"version": "1.0.11",
"license": "MIT",

@@ -39,3 +39,3 @@ "author": "Dilshod Turobov <deebov@yandex.com",

},
"gitHead": "dc6c10d2d60189141a2c7d595e51f5460d1cb7c6"
"gitHead": "5710fdfc37b16b4886793376d4f31563b5f7bf90"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc