import{r as e}from"./rolldown-runtime-DCMCV6zW.js";import{G as t}from"./vendor-other-CyG3qq8S.js";function isTransparent(e){if(e===`transparent`)return!0;if(e[0]===`#`){if(e.length===5)return e[4]===`0`;if(e.length===9)return e.substring(7)===`00`}return!1}function rgbToHsl({r:e,g:t,b:n}){e/=255,t/=255,n/=255;let r=Math.max(e,t,n),i=Math.min(e,t,n),a=0,o=0,s=(r+i)/2;if(r!==i){let c=r-i;switch(o=s>.5?c/(2-r-i):c/(r+i),r){case e:a=(t-n)/c+(t<n?6:0);break;case t:a=(n-e)/c+2;break;case n:a=(e-t)/c+4;break}a/=6}return{h:a,s:o,l:s}}function hexToRgb(e){let t=0,n=0,r=0;return e.length==4?(t=parseInt(e[1]+e[1],16),n=parseInt(e[2]+e[2],16),r=parseInt(e[3]+e[3],16)):e.length==7&&(t=parseInt(e.slice(1,3),16),n=parseInt(e.slice(3,5),16),r=parseInt(e.slice(5,7),16)),{r:t,g:n,b:r}}function rgbToHex({r:e,g:t,b:n}){let toHex=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,`0`);return`#${toHex(e)}${toHex(t)}${toHex(n)}`}function hsbToRgb({h:e,s:t,b:n}){let r=(e%360+360)%360,i=Math.max(0,Math.min(100,t))/100,a=Math.max(0,Math.min(100,n))/100,o=a*i,s=o*(1-Math.abs(r/60%2-1)),c=a-o,l=0,u=0,d=0;return r<60?(l=o,u=s,d=0):r<120?(l=s,u=o,d=0):r<180?(l=0,u=o,d=s):r<240?(l=0,u=s,d=o):r<300?(l=s,u=0,d=o):(l=o,u=0,d=s),{r:Math.floor((l+c)*255),g:Math.floor((u+c)*255),b:Math.floor((d+c)*255)}}function parseToRgb(e){let t=identifyColorFormat(e);if(!t)return{r:0,g:0,b:0};let n=parseToHSLA(e,t);if(!isHSLA(n))return{r:0,g:0,b:0};let r=n.h/360,i=n.s/100,a=n.l/100,o=(1-Math.abs(2*a-1))*i,s=o*(1-Math.abs(r*6%2-1)),c=a-o/2,l=0,u=0,d=0;return r<1/6?(l=o,u=s,d=0):r<2/6?(l=s,u=o,d=0):r<3/6?(l=0,u=o,d=s):r<4/6?(l=0,u=s,d=o):r<5/6?(l=s,u=0,d=o):(l=o,u=0,d=s),{r:Math.round((l+c)*255),g:Math.round((u+c)*255),b:Math.round((d+c)*255)}}var identifyColorFormat=e=>e?e.startsWith(`#`)&&(e.length===4||e.length===7)?`hex`:/rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*/.test(e)?e.includes(`rgba`)?`rgba`:`rgb`:/hsla?\(\s*\d+(\.\d+)?\s*,\s*\d+(\.\d+)?%\s*,\s*\d+(\.\d+)?%/.test(e)?e.includes(`hsla`)?`hsla`:`hsl`:null:null,isHSLA=e=>typeof e!=`object`||!e?!1:[`h`,`s`,`l`,`a`].every(t=>typeof e[t]==`number`&&!isNaN(e[t]));function isColorFormat(e){return e===`hex`||e===`rgb`||e===`hsb`}function isHSBObject(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.h==`number`&&Number.isFinite(t.h)&&typeof t.s==`number`&&Number.isFinite(t.s)&&typeof t.b==`number`&&Number.isFinite(t.b)}function isHSVObject(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.h==`number`&&Number.isFinite(t.h)&&typeof t.s==`number`&&Number.isFinite(t.s)&&typeof t.v==`number`&&Number.isFinite(t.v)}function toHexFromFormat(e,t){if(t===`hex`&&typeof e==`string`){let t=e.trim().toLowerCase();return t?/^[0-9a-f]{3}$/.test(t)?`#${t}`:/^#[0-9a-f]{3}$/.test(t)?t:/^[0-9a-f]{6}$/.test(t)?`#${t}`:/^#[0-9a-f]{6}$/.test(t)?t:`#000000`:`#000000`}if(t===`rgb`&&typeof e==`string`)return rgbToHex(parseToRgb(e)).toLowerCase();if(t===`hsb`){if(isHSBObject(e))return rgbToHex(hsbToRgb(e)).toLowerCase();if(isHSVObject(e)){let{h:t,s:n,v:r}=e;return rgbToHex(hsbToRgb({h:t,s:n,b:r})).toLowerCase()}if(typeof e==`string`){let t=e.match(/\d+(?:\.\d+)?/g)?.map(Number)||[];if(t.length>=3)return rgbToHex(hsbToRgb({h:t[0],s:t[1],b:t[2]})).toLowerCase()}}return`#000000`}function parseToHSLA(e,t){let n;switch(t){case`hex`:{let t=rgbToHsl(hexToRgb(e));return{h:Math.round(t.h*360),s:+(t.s*100).toFixed(1),l:+(t.l*100).toFixed(1),a:1}}case`rgb`:case`rgba`:{if(n=e.match(/\d+(\.\d+)?/g),!n||n.length<3)return null;let[r,i,a]=n.map(Number),o=rgbToHsl({r,g:i,b:a}),s=t===`rgba`&&n[3]?parseFloat(n[3]):1;return{h:Math.round(o.h*360),s:+(o.s*100).toFixed(1),l:+(o.l*100).toFixed(1),a:s}}case`hsl`:case`hsla`:{if(n=e.match(/\d+(\.\d+)?/g),!n||n.length<3)return null;let[r,i,a]=n.map(Number);return{h:r,s:i,l:a,a:t===`hsla`&&n[3]?parseFloat(n[3]):1}}default:return null}}var applyColorAdjustments=(e,t)=>{if(!Object.keys(t).length)return e;let n=identifyColorFormat(e);if(!n)return console.warn(`Unsupported color format in color palette: ${e}`),e;let r=parseToHSLA(e,n);return isHSLA(r)?(t.lightness&&(r.l=Math.max(0,Math.min(100,r.l+t.lightness*100))),t.opacity&&(r.a=Math.max(0,Math.min(1,t.opacity))),`hsla(${r.h}, ${r.s}%, ${r.l}%, ${r.a})`):(console.warn(`Invalid color values in color palette: ${e}`),e)};const n=t(applyColorAdjustments,(e,t)=>`${e}-${JSON.stringify(t)}`);export{parseToRgb as a,isTransparent as i,hexToRgb as n,toHexFromFormat as o,isColorFormat as r,n as t};
//# sourceMappingURL=colorUtil-Cth7eqhK.js.map