var e=Object.defineProperty,t=Object.defineProperties,a=Object.getOwnPropertyDescriptors,r=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable,n=(t,a,r)=>a in t?e(t,a,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[a]=r,i=(e,t)=>{for(var a in t||(t={}))o.call(t,a)&&n(e,a,t[a]);if(r)for(var a of r(t))l.call(t,a)&&n(e,a,t[a]);return e},u=(e,r)=>t(e,a(r));import{e as s}from"./vendor-element-DupX9wXy.js";import{q as d,r as c,c as f,bM as p,R as m,S as v,b7 as y,t as g,v as h,A as w,H as b,D as k,K as x,E as C,M as O,J as W,F as B,x as U,y as P,u as _,c8 as L,L as H,a0 as j,bE as E}from"./vendor-core-Di0OO4oJ.js";const I={class:"cutter-container"},M={class:"cutter-component"},A={key:0,class:"title"},D={key:0,class:"preview-container"},R={class:"title"},T=["src"],F=E(d(u(i({},{name:"ArtCutterImg"}),{__name:"index",props:{isModal:{type:Boolean,default:!1},tool:{type:Boolean,default:!0},toolBgc:{default:"#fff"},title:{default:""},previewTitle:{default:""},showPreview:{type:Boolean,default:!0},boxWidth:{default:700},boxHeight:{default:458},cutWidth:{default:470},cutHeight:{default:270},sizeChange:{type:Boolean,default:!0},moveAble:{type:Boolean,default:!0},imgMove:{type:Boolean,default:!0},scaleAble:{type:Boolean,default:!0},originalGraph:{type:Boolean,default:!0},crossOrigin:{type:Boolean,default:!0},fileType:{default:"png"},quality:{default:.9},watermarkText:{default:""},watermarkFontSize:{default:20},watermarkColor:{default:"#ffffff"},saveCutPosition:{type:Boolean,default:!0},previewMode:{type:Boolean,default:!0},imgUrl:{},noCrop:{type:Boolean,default:!1}},emits:["update:imgUrl","error","imageLoadComplete","imageLoadError","cutDown"],setup(e,{emit:t}){const a=e,r=t,o=c(""),l=c(),n=c(null),{width:d}=p(),E=f(()=>d.value<768),F=f(()=>{const e=E.value?d.value:a.boxWidth;let t=a.cutWidth,r=a.cutHeight;if(E.value&&a.cutWidth){const o=.8*e;if(a.cutWidth>o){const e=o/a.cutWidth;t=Math.round(a.cutWidth*e),r=Math.round((a.cutHeight||a.cutWidth)*e)}}return u(i({},a),{boxWidth:e,boxHeight:E.value?400:a.boxHeight,cutWidth:t,cutHeight:r,WatermarkText:a.watermarkText,WatermarkFontSize:a.watermarkFontSize,WatermarkColor:a.watermarkColor})});function S(){return e=this,t=null,o=function*(){var e,t;if(a.imgUrl)try{yield(t=a.imgUrl,new Promise((e,a)=>{const r=new Image;r.crossOrigin="anonymous",r.onload=()=>e(),r.onerror=a,r.src=t})),null==(e=l.value)||e.handleOpen({name:"封面图片",src:a.imgUrl})}catch(o){r("error",o)}},new Promise((a,r)=>{var l=e=>{try{i(o.next(e))}catch(t){r(t)}},n=e=>{try{i(o.throw(e))}catch(t){r(t)}},i=e=>e.done?a(e.value):Promise.resolve(e.value).then(l,n);i((o=o.apply(e,t)).next())});var e,t,o}function z(e){o.value=e.dataURL}function $(e){r("update:imgUrl",e.dataURL),r("cutDown",e)}function q(e){r("imageLoadComplete",e)}function G(e){r("error",e),r("imageLoadError",e)}function J(){o.value=""}function K(){var e;null==(e=n.value)||e.click()}function N(e){var t;const a=e.target,o=null==(t=a.files)?void 0:t[0];if(!o)return;if(-1===o.type.indexOf("image"))return void r("error",new Error("请选择图片文件"));const l=new FileReader;l.onload=e=>{var t;const r=null==(t=e.target)?void 0:t.result;$({fileName:o.name,file:o,blob:new Blob([o],{type:o.type}),dataURL:r}),a&&(a.value="")},l.onerror=e=>{r("error",e)},l.readAsDataURL(o)}function Q(){const e=document.createElement("a");e.href=o.value,e.download="image.png",e.click()}return m(()=>{a.imgUrl&&(o.value=a.imgUrl,S())}),v(()=>a.imgUrl,e=>{e&&(o.value=e,S())}),(t,a)=>{const r=s,i=y("ripple");return h(),g("div",I,[w("div",M,[e.title?(h(),g("div",A,x(e.title),1)):b("",!0),e.noCrop?(h(),g(H,{key:2},[w("div",{onClick:K},[U(t.$slots,"default",{},()=>[B((h(),k(r,{type:"primary",plain:""},{default:C(()=>[...a[3]||(a[3]=[W("选择图片",-1)])]),_:1})),[[i]])],!0)]),w("input",{ref_key:"fileInput",ref:n,type:"file",class:"hidden",style:{display:"none"},onChange:N,accept:"image/*"},null,544)],64)):(h(),k(_(L),P({ref_key:"imgCutterModal",ref:l,key:_(E)?"mobile":"desktop",onCutDown:$,onOnPrintImg:z,onOnImageLoadComplete:q,onOnImageLoadError:G,onOnClearAll:J},_(F),{class:"img-cutter"}),{open:C(()=>[U(t.$slots,"default",{},()=>[B((h(),k(r,{type:"primary",plain:""},{default:C(()=>[...a[0]||(a[0]=[W("选择图片",-1)])]),_:1})),[[i]])],!0)]),cancel:C(()=>[B((h(),k(r,{type:"danger",plain:""},{default:C(()=>[...a[1]||(a[1]=[W("取消",-1)])]),_:1})),[[i]])]),confirm:C(()=>[O(r,{type:"primary",style:{"margin-left":"10px"}},{default:C(()=>[...a[2]||(a[2]=[W("确定",-1)])]),_:1})]),_:3},16))]),e.showPreview?(h(),g("div",D,[w("div",R,x(e.previewTitle),1),w("div",{class:"preview-box",style:j({width:`${_(F).cutWidth}px`,height:`${_(F).cutHeight}px`})},[_(o)?(h(),g("img",{key:0,class:"preview-img",src:_(o),alt:"预览图"},null,8,T)):b("",!0)],4),B((h(),k(r,{class:"download-btn",onClick:Q,disabled:!_(o)},{default:C(()=>[...a[4]||(a[4]=[W("下载图片",-1)])]),_:1},8,["disabled"])),[[i]])])):b("",!0)])}}})),[["__scopeId","data-v-00537a9d"]]);export{F as default};
