import{q as M,J0 as d,aq as P}from"./index.5dbe5867.js";import{_ as I}from"./DragVerify.vue_vue_type_style_index_0_lang.0c44209c.js";import{rotateProps as $}from"./props.2e9bdf22.js";import"./vendor-@yoyoboot.494652c9.js";import{f as C,r as O,j as b,w as E,e as p,c as n,u as l,aZ as F}from"./vendor-@vue.54cfd5db.js";var L=C({name:"ImgRotateDragVerify",inheritAttrs:!1,props:$,emits:["success","change","update:value"],setup(r,{emit:m,attrs:_,expose:v}){const u=O(null),e=b({showTip:!1,isPassing:!1,imgStyle:{},randomRotate:0,currentRotate:0,toOrigin:!1,startTime:0,endTime:0,draged:!1}),{l:c}=M.methods;E(()=>e.isPassing,t=>{if(t){const{startTime:a,endTime:s}=e,i=(s-a)/1e3;m("success",{isPassing:t,time:i.toFixed(1)}),m("change",t),m("update:value",t)}});const T=p(()=>{const{imgWrapStyle:t,imgWidth:a}=r;return{width:`${a}px`,height:`${a}px`,...t}}),R=p(()=>{const{minDegree:t,maxDegree:a}=r;return t===a?Math.floor(1+Math.random()*1)/10+1:1});function w(){e.startTime=new Date().getTime()}function y(t){e.draged=!0;const{imgWidth:a,height:s,maxDegree:i}=r,{moveX:g}=t,o=Math.ceil(g/(a-parseInt(s))*i*l(R));e.currentRotate=o,e.imgStyle=d("transform",`rotateZ(${e.randomRotate-o}deg)`)}function f(){const{minDegree:t,maxDegree:a}=r,s=Math.floor(t+Math.random()*(a-t));e.randomRotate=s,e.imgStyle=d("transform",`rotateZ(${s}deg)`)}function D(){const{randomRotate:t,currentRotate:a}=e,{diffDegree:s}=r;Math.abs(t-a)>=(s||20)?(e.imgStyle=d("transform",`rotateZ(${t}deg)`),e.toOrigin=!0,P(()=>{e.toOrigin=!1,e.showTip=!0},300)):S(),e.showTip=!0}function S(){e.isPassing=!0,e.endTime=new Date().getTime()}function h(){e.showTip=!1;const t=l(u);!t||(e.isPassing=!1,t.resume(),f())}return v({resume:h}),()=>{const{src:t}=r,{toOrigin:a,isPassing:s,startTime:i,endTime:g}=e,o=[];a&&o.push("to-origin");const x=(g-i)/1e3;return n("div",{class:"ir-dv"},[n("div",{class:"ir-dv-img__wrap",style:l(T)},[n("img",{src:t,onLoad:f,width:parseInt(r.width),class:o,style:e.imgStyle,onClick:()=>{h()},alt:"verify"},null),e.showTip&&n("span",{class:["ir-dv-img__tip",e.isPassing?"success":"error"]},[e.isPassing?c("Time",{time:x.toFixed(1)}):c("Error")]),!e.showTip&&!e.draged&&n("span",{class:["ir-dv-img__tip","normal"]},[c("RedoTip")])]),n(I,F({class:"ir-dv-drag__bar",onMove:y,onEnd:D,onStart:w,ref:u},{..._,...r},{value:s,isSlot:!0}),null)])}}});export{L as _};
