(function(a,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("cropperjs"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","cropperjs","@vueuse/core"],e):(a=typeof globalThis<"u"?globalThis:a||self,e(a.index={},a.Vue,a.Cropper,a.core))})(this,function(a,e,S,w){"use strict";const D="",C="g";function g(r,s,c){let o=r;return s&&(o+=`__${s}`),c&&(o+=`--${c}`),o}function O(r,s=!1){const c=s?`.${C}-${r}`:`${C}-${r}`;return{b:()=>g(c),e:t=>t?g(c,t):"",m:t=>t?g(c,"",t):"",em:(t,m)=>t&&m?g(c,t,m):""}}const R=["src","alt","crossorigin"],B={name:"GCropperImage"},u=e.defineComponent({...B,props:{src:{type:String,required:!0},alt:{type:String},circled:{type:Boolean,default:!1},realTimePreview:{type:Boolean,default:!0},height:{type:[String,Number],default:"360px"},crossorigin:{type:String,default:void 0},imageStyle:{type:Object,default:()=>({})},options:{type:Object,default:()=>({})}},emits:["cropend","ready","cropendError"],setup(r,{emit:s}){const c={aspectRatio:1,zoomable:!0,zoomOnTouch:!0,zoomOnWheel:!0,cropBoxMovable:!0,cropBoxResizable:!0,toggleDragModeOnDblclick:!0,autoCrop:!0,background:!0,highlight:!0,center:!0,responsive:!0,restore:!0,checkCrossOrigin:!0,checkOrientation:!0,scalable:!0,modal:!0,guides:!0,movable:!0,rotatable:!0},o=r,f=s,v=e.useAttrs(),h=e.ref(),t=e.ref(),m=e.ref(!1),b=O("cropper-image").b(),y=w.useDebounceFn(_,80),z=e.computed(()=>({height:o.height,maxWidth:"100%",...o.imageStyle})),T=e.computed(()=>[b,v.class,{[`${b}--circled`]:o.circled}]),$=e.computed(()=>({height:`${o.height}`.replace(/px/,"")+"px"}));e.onMounted(M),e.onUnmounted(()=>{var n;(n=t.value)==null||n.destroy()});async function M(){const n=e.unref(h);n&&(t.value=new S(n,{...c,ready:()=>{m.value=!0,_(),f("ready",t.value)},crop(){y()},zoom(){y()},cropmove(){y()},...o.options}))}function _(){o.realTimePreview&&j()}function j(){if(!t.value)return;let n=t.value.getData();(o.circled?k():t.value.getCroppedCanvas()).toBlob(i=>{if(!i)return;let l=new FileReader;l.readAsDataURL(i),l.onloadend=d=>{var x;f("cropend",{imgBase64:((x=d.target)==null?void 0:x.result)??"",imgInfo:n})},l.onerror=()=>{f("cropendError")}},"image/png")}function k(){const n=t.value.getCroppedCanvas(),p=document.createElement("canvas"),i=p.getContext("2d"),l=n.width,d=n.height;return p.width=l,p.height=d,i.imageSmoothingEnabled=!0,i.drawImage(n,0,0,l,d),i.globalCompositeOperation="destination-in",i.beginPath(),i.arc(l/2,d/2,Math.min(l,d)/2,0,2*Math.PI,!0),i.fill(),p}return(n,p)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(T.value),style:e.normalizeStyle($.value)},[e.withDirectives(e.createElementVNode("img",{ref_key:"imgElRef",ref:h,src:r.src,alt:r.alt,crossorigin:r.crossorigin,style:e.normalizeStyle(z.value)},null,12,R),[[e.vShow,m.value]])],6))}}),I="";u.install=function(r,s){r.component(s||u.name,u)};const E={title:"Cropper 图片裁剪",category:"高级组件",status:"100%",install(r){r.component(u.name,u)}};a.CropperImage=u,a.default=E,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
