!function(){"use strict";const t=new Map,n=new Map;function r(t){if(t.size>500){Array.from(t.entries()).slice(0,Math.floor(100)).forEach(([n])=>t.delete(n))}}function e(n){const e="hexToRgb:".concat(n);if(t.has(e))return t.get(e);const o=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n),a=o?{r:parseInt(o[1],16),g:parseInt(o[2],16),b:parseInt(o[3],16)}:null;return t.set(e,a),r(t),a}function o(n,e,o){const a="rgbToHex:".concat(n,",").concat(e,",").concat(o);if(t.has(a))return t.get(a);const c=t=>{const n=t.toString(16);return 1===n.length?"0".concat(n):n},s="#".concat(c(n)).concat(c(e)).concat(c(o));return t.set(a,s),r(t),s}function a(n,e,o){const a="rgbToHsl:".concat(n,",").concat(e,",").concat(o);if(t.has(a))return t.get(a);const c=n/255,s=e/255,l=o/255,i=Math.max(c,s,l),h=Math.min(c,s,l),g=i-h;let u=0,d=0;const f=(i+h)/2;0!==g&&(d=f>.5?g/(2-i-h):g/(i+h),u=i===c?(s-l)/g+(s<l?6:0):i===s?(l-c)/g+2:(c-s)/g+4,u/=6);const b={h:360*u,s:100*d,l:100*f};return t.set(a,b),r(t),b}function c(n,e,o){const a="hslToRgb:".concat(n,",").concat(e,",").concat(o);if(t.has(a))return t.get(a);const c=n/360,s=e/100,l=o/100,i=(t,n,r)=>{let e=r;return e<0&&(e+=1),e>1&&(e-=1),e<1/6?t+6*(n-t)*e:e<.5?n:e<2/3?t+(n-t)*(2/3-e)*6:t};let h=0,g=0,u=0;if(0===s)h=l,g=l,u=l;else{const t=l<.5?l*(1+s):l+s-l*s,n=2*l-t;h=i(n,t,c+1/3),g=i(n,t,c),u=i(n,t,c-1/3)}const d={r:Math.round(255*h),g:Math.round(255*g),b:Math.round(255*u)};return t.set(a,d),r(t),d}function s(t){const{r:n,g:r,b:e}=t,o=t=>{const n=t/255;return n<=.03928?n/12.92:((n+.055)/1.055)**2.4};return.2126*o(n)+.7152*o(r)+.0722*o(e)}function l(t,s="light"){const l="standardColorScale:".concat(t,":").concat(s);if(n.has(l))return n.get(l);const i=e(t);if(!i)throw new Error("Invalid color format");const h=a(i.r,i.g,i.b),g={base:t,light3:"",light5:"",light7:"",light8:"",light9:"",dark2:""};if("light"===s){const t=c(h.h,h.s,Math.min(95,h.l+20)),n=c(h.h,.8*h.s,Math.min(95,h.l+30)),r=c(h.h,.6*h.s,Math.min(95,h.l+40)),e=c(h.h,.4*h.s,Math.min(95,h.l+50)),a=c(h.h,.2*h.s,Math.min(95,h.l+60)),s=c(h.h,h.s,Math.max(5,h.l-15));g.light3=o(t.r,t.g,t.b),g.light5=o(n.r,n.g,n.b),g.light7=o(r.r,r.g,r.b),g.light8=o(e.r,e.g,e.b),g.light9=o(a.r,a.g,a.b),g.dark2=o(s.r,s.g,s.b)}else{const t=c(h.h,h.s,Math.max(5,h.l-10)),n=c(h.h,.9*h.s,Math.max(5,h.l-20)),r=c(h.h,.7*h.s,Math.max(5,h.l-30)),e=c(h.h,.5*h.s,Math.max(5,h.l-40)),a=c(h.h,.3*h.s,Math.max(5,h.l-50)),s=c(h.h,Math.min(100,h.s+20),Math.min(95,h.l+25));g.light3=o(t.r,t.g,t.b),g.light5=o(n.r,n.g,n.b),g.light7=o(r.r,r.g,r.b),g.light8=o(e.r,e.g,e.b),g.light9=o(a.r,a.g,a.b),g.dark2=o(s.r,s.g,s.b)}return n.set(l,g),r(n),g}function i(t,o={}){const a="smartColorScale:".concat(t,":").concat(JSON.stringify(o));if(n.has(a))return n.get(a);const{mode:c="auto"}=o,i=l(t,"auto"===c?function(t){const n=e(t);return!!n&&s(n)>.5}(t)?"light":"dark":c);return n.set(a,i),r(n),i}onmessage=r=>{const h=function(r){try{switch(r.type){case"generateColorScale":{const{primaryColor:t,config:n}=r.payload,e="light"===(null==n?void 0:n.mode)||"dark"===(null==n?void 0:n.mode)?l(t,n.mode):i(t,n);return{id:r.id,type:r.type,success:!0,data:e}}case"convertColor":{const{color:t,from:n,to:s}=r.payload;let l=null;return"hex"===n&&"rgb"===s?l=e(t):"rgb"===n&&"hex"===s?l=o(t.r,t.g,t.b):"rgb"===n&&"hsl"===s?l=a(t.r,t.g,t.b):"hsl"===n&&"rgb"===s&&(l=c(t.h,t.s,t.l)),{id:r.id,type:r.type,success:!0,data:l}}case"analyzeColor":{const{color:t}=r.payload,n=e(t);if(!n)throw new Error("Invalid color");const o=s(n),c=o>.5;return{id:r.id,type:r.type,success:!0,data:{isLight:c,luminance:o,rgb:n,hsl:a(n.r,n.g,n.b)}}}case"clearCache":return t.clear(),n.clear(),{id:r.id,type:r.type,success:!0,data:{message:"Cache cleared"}};default:throw new Error("Unknown message type: ".concat(r.type))}}catch(h){return{id:r.id,type:r.type,success:!1,error:h instanceof Error?h.message:"Unknown error"}}}(r.data);postMessage(h)}}();
