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.13 to 1.0.14-alpha.3

2

dist/index.esm.js

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

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

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

},
"gitHead": "8dc2d2eb0da256df0227611e92d391a9f681e52f"
"gitHead": "f8fdfc4b6b7c6190f5ecc1e6d6ca7b6654cfeafc"
}

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