import{t as _}from"./debounce-Xd493GvO.js";import{u as y}from"./useOnEvent-Cta5e-FG.js";import{r as c,c as v,w as h,j as C,B as V,z as D,D as N}from"./vue-BJk78QHK.js";import"./index-M_JNBppB.js";import"./element-3_pOinej.js";import"./utils-YI6ye1sf.js";import"./threejs-BafxXW5-.js";import"./vxe-Dx3zSILm.js";const R={style:{overflow:"hidden"}},F=Object.assign({name:"DecorationPicture"},{__name:"DecorationPicture",props:{propValue:{type:Object,required:!0,default:()=>({})},element:{type:Object,default:()=>({})}},setup(b){const a=b,p=c(null),u=c(null),n=c(null),d=c(!0),w=v(()=>{const e=a.element.style.width,t=a.element.style.height;return{width:e,height:t}});h(w,_(()=>{f()},500),{deep:!0}),h(()=>a.propValue.flip.vertical,()=>{m()}),h(()=>a.propValue.flip.horizontal,()=>{m()}),h(()=>a.propValue.newColor,e=>{if(e){let t;e.includes("#")?(t=g(e),i(t)):(t=e.replace("rgba(","").replace(")",""),i(t.split(",")))}else f()},{deep:!0}),y(v(()=>a.linkage),c(a.element)),C(()=>{u.value=document.createElement("img"),n.value=p.value.getContext("2d"),f(),setTimeout(()=>{const e=a.propValue.newColor;if(e){let t;e.includes("#")?(t=g(e),i(t)):(t=e.replace("rgba(","").replace(")",""),i(t.split(",")))}},200)});function f(){const{width:e,height:t}=a.element.style;if(p.value.width=e,p.value.height=t,d.value?(d.value=!1,u.value.src=a.propValue.url||new URL("/assets/logo-CIrJpTeR.png",import.meta.url).href,u.value.setAttribute("crossOrigin","Anonymous"),u.value.onload=()=>{n.value.drawImage(u.value,0,0,e,t),m()}):m(),a.propValue.newColor){const r=a.propValue.newColor;let l;r.includes("#")?(l=g(r),i(l)):(l=r.replace("rgba(","").replace(")",""),i(l.split(",")))}}function m(){const{vertical:e,horizontal:t}=a.propValue.flip,{width:r,height:l}=a.element.style,s=t?-1:1,o=e?-1:1;n.value.clearRect(0,0,r,l),n.value.translate(r/2-r*s/2,l/2-l*o/2),n.value.scale(s,o),n.value.drawImage(u.value,0,0,r,l),n.value.setTransform(1,0,0,1,0,0)}function I(e){const{width:t,height:r}=a.element.style,l=n.value.getImageData(0,0,t,r),s=l.data;for(let o=0;o<s.length;o+=4)s[o]=Number.parseInt(e[0]),s[o+1]=Number.parseInt(e[1]),s[o+2]=Number.parseInt(e[2]);n.value.putImageData(l,0,0)}function i(e){I(e)}function g(e){const t=[];return t.push(Number.parseInt(e.substring(1,3),16)),t.push(Number.parseInt(e.substring(3,5),16)),t.push(Number.parseInt(e.substring(5),16)),t}return(e,t)=>(D(),V("div",R,[N("canvas",{ref_key:"canvasRef",ref:p},null,512)]))}});export{F as default};
