@bobthered/tailwindcss-palette-generator
Version:
Quickly generate tailwindcss color palettes from a base color or colors.
1 lines • 1.88 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var e=({hex:e,preserve:s,shades:t})=>{const n=(e=>{const s=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e)||[];try{let e=parseInt(s[1],16),t=parseInt(s[2],16),n=parseInt(s[3],16);e/=255,t/=255,n/=255;const r=Math.max(e,t,n),a=Math.min(e,t,n);let o,h=0,i=(r+a)/2;if(r==a)h=o=0;else{const s=r-a;switch(o=i>.5?s/(2-r-a):s/(r+a),r){case e:h=(t-n)/s+(t<n?6:0);break;case t:h=(n-e)/s+2;break;case n:h=(e-t)/s+4}h/=6}const c={h:0,s:0,l:0};return c.h=Math.round(360*h),c.s=Math.round(100*o),c.l=Math.round(100*i),c}catch(s){return console.log(e),{h:0,s:0,l:0}}})(e),r={},a=t.reduce(((e,{name:t,lightness:a})=>{const{h:o,s:h,l:i}=n,c=(({h:e,s:s,l:t})=>{t/=100;const n=s*Math.min(t,1-t)/100,r=s=>{const r=(s+e/30)%12,a=t-n*Math.max(Math.min(r-3,9-r,1),-1);return Math.round(255*a).toString(16).padStart(2,"0")};return`#${r(0)}${r(8)}${r(4)}`})({h:o,s:h,l:a});return e[t]=c,s&&(r[t]=Math.abs(i-a)),e}),{});if(s){const[s]=Object.keys(r).sort(((e,s)=>r[e]-r[s]));a[s]=e}return a},s=s=>{"string"==typeof s&&(s={colors:[s]}),"object"==typeof s&&Array.isArray(s)&&(s={colors:s}),s=Object.assign({colors:[],names:["primary","secondary","tertiary","quaternary","quinary","senary","septenary","octonary","nonary","denary"],preserve:!0,shades:[{name:"50",lightness:98},{name:"100",lightness:95},{name:"200",lightness:90},{name:"300",lightness:82},{name:"400",lightness:64},{name:"500",lightness:46},{name:"600",lightness:33},{name:"700",lightness:24},{name:"800",lightness:14},{name:"900",lightness:7},{name:"950",lightness:4}]},s);const{colors:t,names:n,preserve:r,shades:a}=s;if(void 0===t||void 0===n||void 0===r||void 0===a)return{};return t.reduce(((s,t,o)=>{const h=n[o],i=e({hex:t,preserve:r,shades:a});return s[h]=i,s}),{})};exports.default=s,exports.tailwindcssPaletteGenerator=s;//# sourceMappingURL=index.cjs.map