UNPKG

miharakinu-go-captcha-vue

Version:

GoCaptcha of Vue, which implements click mode, slider mode, drag-drop mode and rotation mode.

40 lines (39 loc) 32 kB
(function(F,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(F=typeof globalThis<"u"?globalThis:F||self,e(F["go-captcha-vue"]={},F.Vue))})(this,function(F,e){"use strict";const at="",ne=()=>({width:300,height:220,thumbWidth:150,thumbHeight:40,verticalPadding:16,horizontalPadding:12,showTheme:!0,title:"请在下图依次点击",buttonText:"确认",iconSize:22,dotSize:24}),de=[e.createElementVNode("path",{d:`M100.1,189.9C100.1,189.9,100,189.9,100.1,189.9c-49.7,0-90-40.4-90-89.9c0-49.6,40.4-89.9,89.9-89.9 c49.6,0,89.9,40.4,89.9,89.9c0,18.2-5.4,35.7-15.6,50.7c-1.5,2.1-3.6,3.4-6.1,3.9c-2.5,0.4-5-0.1-7-1.6c-4.2-3-5.3-8.6-2.4-12.9 c8.1-11.9,12.4-25.7,12.4-40.1c0-39.2-31.9-71.1-71.1-71.1c-39.2,0-71.1,31.9-71.1,71.1c0,39.2,31.9,71.1,71.1,71.1 c7.7,0,15.3-1.2,22.6-3.6c2.4-0.8,4.9-0.6,7.2,0.5c2.2,1.1,3.9,3.1,4.7,5.5c1.6,4.9-1,10.2-5.9,11.9 C119.3,188.4,109.8,189.9,100.1,189.9z M73,136.4C73,136.4,73,136.4,73,136.4c-2.5,0-4.9-1-6.7-2.8c-3.7-3.7-3.7-9.6,0-13.3 L86.7,100L66.4,79.7c-3.7-3.7-3.7-9.6,0-13.3c3.7-3.7,9.6-3.7,13.3,0L100,86.7l20.3-20.3c1.8-1.8,4.1-2.8,6.7-2.8c0,0,0,0,0,0 c2.5,0,4.9,1,6.7,2.8c1.8,1.8,2.8,4.1,2.8,6.7c0,2.5-1,4.9-2.8,6.7L113.3,100l20.3,20.3c3.7,3.7,3.7,9.6,0,13.3 c-3.7,3.7-9.6,3.7-13.3,0L100,113.3l-20.3,20.3C77.9,135.4,75.5,136.4,73,136.4z`},null,-1)],Q=e.defineComponent({__name:"close-icon",emits:["click"],setup(c,{emit:n}){const o=n;function h(i){o("click",i)}return(i,g)=>(e.openBlock(),e.createElementBlock("svg",e.mergeProps({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 200 200",width:"20",height:"20"},i.$attrs,{onClick:h}),de,16))}}),he=[e.createElementVNode("path",{d:`M135,149.9c-10.7,7.6-23.2,11.4-36,11.2c-1.7,0-3.4-0.1-5-0.3c-0.7-0.1-1.4-0.2-2-0.3c-1.3-0.2-2.6-0.4-3.9-0.6 c-0.8-0.2-1.6-0.4-2.3-0.5c-1.2-0.3-2.5-0.6-3.7-1c-0.6-0.2-1.2-0.4-1.7-0.6c-1.4-0.5-2.8-1-4.2-1.5c-0.3-0.1-0.6-0.3-0.9-0.4 c-1.6-0.7-3.2-1.4-4.7-2.3c-0.1,0-0.1-0.1-0.2-0.1c-5.1-2.9-9.8-6.4-14-10.6c-0.1-0.1-0.1-0.1-0.2-0.2c-1.3-1.3-2.5-2.7-3.7-4.1 c-0.2-0.3-0.5-0.6-0.7-0.9c-8.4-10.6-13.5-24.1-13.5-38.8h14.3c0.4,0,0.7-0.2,0.9-0.5c0.2-0.3,0.2-0.8,0-1.1L29.5,60.9 c-0.2-0.3-0.5-0.5-0.9-0.5c-0.4,0-0.7,0.2-0.9,0.5L3.8,97.3c-0.2,0.3-0.2,0.7,0,1.1c0.2,0.3,0.5,0.5,0.9,0.5h14.3 c0,17.2,5.3,33.2,14.3,46.4c0.1,0.2,0.2,0.4,0.3,0.6c0.9,1.4,2,2.6,3,3.9c0.4,0.5,0.7,1,1.1,1.5c1.5,1.8,3,3.5,4.6,5.2 c0.2,0.2,0.3,0.3,0.5,0.5c5.4,5.5,11.5,10.1,18.2,13.8c0.2,0.1,0.3,0.2,0.5,0.3c1.9,1,3.9,2,5.9,2.9c0.5,0.2,1,0.5,1.5,0.7 c1.7,0.7,3.5,1.3,5.2,1.9c0.8,0.3,1.7,0.6,2.5,0.8c1.5,0.5,3.1,0.8,4.7,1.2c1.1,0.2,2.1,0.5,3.2,0.7c0.4,0.1,0.9,0.2,1.3,0.3 c1.5,0.3,3,0.4,4.5,0.6c0.5,0.1,1.1,0.2,1.6,0.2c2.7,0.3,5.4,0.4,8.1,0.4c16.4,0,32.5-5.1,46.2-14.8c4.4-3.1,5.5-9.2,2.4-13.7 C145.5,147.8,139.4,146.7,135,149.9 M180.6,98.9c0-17.2-5.3-33.1-14.2-46.3c-0.1-0.2-0.2-0.5-0.4-0.7c-1.1-1.6-2.3-3.1-3.5-4.6 c-0.1-0.2-0.3-0.4-0.4-0.6c-8.2-10.1-18.5-17.9-30.2-23c-0.3-0.1-0.6-0.3-1-0.4c-1.9-0.8-3.8-1.5-5.7-2.1c-0.7-0.2-1.4-0.5-2.1-0.7 c-1.7-0.5-3.4-0.9-5.1-1.3c-0.9-0.2-1.9-0.5-2.8-0.7c-0.5-0.1-0.9-0.2-1.4-0.3c-1.3-0.2-2.6-0.3-3.8-0.5c-0.9-0.1-1.8-0.3-2.6-0.3 c-2.1-0.2-4.3-0.3-6.4-0.3c-0.4,0-0.8-0.1-1.2-0.1c-0.1,0-0.1,0-0.2,0c-16.4,0-32.4,5-46.2,14.8C49,35,48,41.1,51,45.6 c3.1,4.4,9.1,5.5,13.5,2.4c10.6-7.5,23-11.3,35.7-11.2c1.8,0,3.6,0.1,5.4,0.3c0.6,0.1,1.1,0.1,1.6,0.2c1.5,0.2,2.9,0.4,4.3,0.7 c0.6,0.1,1.3,0.3,1.9,0.4c1.4,0.3,2.8,0.7,4.2,1.1c0.4,0.1,0.9,0.3,1.3,0.4c1.6,0.5,3.1,1.1,4.6,1.7c0.2,0.1,0.3,0.1,0.5,0.2 c9,3.9,17,10,23.2,17.6c0,0,0.1,0.1,0.1,0.2c8.7,10.7,14,24.5,14,39.4H147c-0.4,0-0.7,0.2-0.9,0.5c-0.2,0.3-0.2,0.8,0,1.1l24,36.4 c0.2,0.3,0.5,0.5,0.9,0.5c0.4,0,0.7-0.2,0.9-0.5l23.9-36.4c0.2-0.3,0.2-0.7,0-1.1c-0.2-0.3-0.5-0.5-0.9-0.5L180.6,98.9L180.6,98.9 L180.6,98.9z`},null,-1)],Z=e.defineComponent({__name:"refresh-icon",emits:["click"],setup(c,{emit:n}){const o=n;function h(i){o("click",i)}return(i,g)=>(e.openBlock(),e.createElementBlock("svg",e.mergeProps({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 200 200",width:"20",height:"20"},i.$attrs,{onClick:h}),he,16))}}),me=[e.createElementVNode("circle",{cx:"50",cy:"36.8101",r:"10"},[e.createElementVNode("animate",{attributeName:"cy",dur:"1s",repeatCount:"indefinite",calcMode:"spline",keySplines:"0.45 0 0.9 0.55;0 0.45 0.55 0.9",keyTimes:"0;0.5;1",values:"23;77;23"})],-1)],ee=e.defineComponent({__name:"loading-icon",emits:["click"],setup(c,{emit:n}){const o=n;function h(i){o("click",i)}return(i,g)=>(e.openBlock(),e.createElementBlock("svg",e.mergeProps({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 100 100",preserveAspectRatio:"xMidYMid",width:"84",height:"84"},i.$attrs,{onClick:h}),me,16))}});function fe(c){let n=0,o=0;if(c.getBoundingClientRect){const h=c.getBoundingClientRect(),i=document.documentElement;n=h.left+Math.max(i.scrollLeft,document.body.scrollLeft)-i.clientLeft,o=h.top+Math.max(i.scrollTop,document.body.scrollTop)-i.clientTop}else for(;c!==document.body;)n+=c.offsetLeft,o+=c.offsetTop,c=c.offsetParent;return{domX:n,domY:o}}function I(c,n){let o=n.relatedTarget;try{for(;o&&o!==c;)o=o.parentNode}catch(h){console.warn(h)}return o!==c}function ge(c,n,o){const h=e.reactive({list:[]}),i=l=>{const p=l.currentTarget,D=fe(p),a=l.pageX||l.clientX,E=l.pageY||l.clientY,m=D.domX,C=D.domY,v=a-m,w=E-C,f=parseInt(v.toString()),b=parseInt(w.toString()),u=new Date,k=h.list.length;return h.list.push({key:u.getTime(),index:k+1,x:f,y:b}),n.click&&n.click(f,b),l.cancelBubble=!0,l.preventDefault(),!1},g=l=>(n.confirm&&n.confirm(e.toRaw(h.list),()=>{y()}),l.cancelBubble=!0,l.preventDefault(),!1),r=l=>(t(),l.cancelBubble=!0,l.preventDefault(),!1),s=l=>(d(),l.cancelBubble=!0,l.preventDefault(),!1),t=()=>{n.close&&n.close(),y()},d=()=>{n.refresh&&n.refresh(),y()},y=()=>{h.list=[]};return{dots:h,clickEvent:i,confirmEvent:g,closeEvent:r,refreshEvent:s,resetData:y,clearData:()=>{y(),o&&o()},refresh:d,close:t}}const pe={class:"gc-header"},ue=["src"],_e={class:"gc-loading"},Ee=["src"],we={class:"gc-dots"},be={class:"gc-footer"},ye={class:"gc-icon-block gc-icon-block2"},ke={class:"gc-button-block"},U=e.defineComponent({__name:"index",props:{config:{default:ne},events:{default:()=>({})},data:{default:()=>({})}},setup(c,{expose:n}){const o=c,{data:h,events:i,config:g}=o,r=e.reactive({...e.toRaw(h)}),s=e.reactive({...e.toRaw(i)}),t=e.reactive({...ne(),...e.toRaw(g)});e.watch(()=>o.data,(a,E)=>{Object.assign(r,a)},{deep:!0}),e.watch(()=>o.events,(a,E)=>{Object.assign(s,a)},{deep:!0}),e.watch(()=>o.config,(a,E)=>{Object.assign(t,a)},{deep:!0});const d=ge(r,s,()=>{r.thumb="",r.image=""}),y=e.computed(()=>{const a=t.horizontalPadding||0,E=t.verticalPadding||0;return{width:(t.width||0)+a*2+(t.showTheme?2:0)+"px",paddingLeft:a+"px",paddingRight:a+"px",paddingTop:E+"px",paddingBottom:E+"px"}}),_=e.computed(()=>({width:t.thumbWidth+"px",height:t.thumbHeight+"px"})),l=e.computed(()=>({width:t.width+"px",height:t.height+"px"})),p=e.computed(()=>r.image&&r.image.length>0||r.thumb&&r.thumb.length>0),D=e.computed(()=>(t.width||0)>0||(t.height||0)>0);return n({reset:d.resetData,clear:d.clearData,refresh:d.refresh,close:d.close}),(a,E)=>e.withDirectives((e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(`go-captcha gc-wrapper ${t.showTheme&&"gc-theme"}`),style:e.normalizeStyle(y.value)},[e.createElementVNode("div",pe,[e.createElementVNode("span",null,e.toDisplayString(t.title),1),e.withDirectives(e.createElementVNode("img",{style:e.normalizeStyle(_.value),src:r.thumb,alt:""},null,12,ue),[[e.vShow,p.value]])]),e.createElementVNode("div",{class:"gc-body",style:e.normalizeStyle(l.value)},[e.createElementVNode("div",_e,[e.createVNode(ee)]),e.withDirectives(e.createElementVNode("img",{style:e.normalizeStyle(l.value),class:"gc-picture",src:r.image,onClick:E[0]||(E[0]=(...m)=>e.unref(d).clickEvent&&e.unref(d).clickEvent(...m)),alt:""},null,12,Ee),[[e.vShow,p.value]]),e.createElementVNode("div",we,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(d).dots.list,m=>(e.openBlock(),e.createElementBlock("div",{class:"gc-dot",key:`${m.key+"-"+m.index}`,style:e.normalizeStyle({width:t.dotSize+"px",height:t.dotSize+"px",borderRadius:t.dotSize+"px",top:m.y-(t.dotSize||1)/2-1+"px",left:m.x-(t.dotSize||1)/2-1+"px"})},e.toDisplayString(m.index),5))),128))])],4),e.createElementVNode("div",be,[e.createElementVNode("div",ye,[e.createVNode(Q,{width:t.iconSize,height:t.iconSize,onClick:e.unref(d).closeEvent},null,8,["width","height","onClick"]),e.createVNode(Z,{width:t.iconSize,height:t.iconSize,onClick:e.unref(d).refreshEvent},null,8,["width","height","onClick"])]),e.createElementVNode("div",ke,[e.createElementVNode("button",{class:e.normalizeClass(!p.value&&"disabled"),onClick:E[1]||(E[1]=(...m)=>e.unref(d).confirmEvent&&e.unref(d).confirmEvent(...m))},e.toDisplayString(t.buttonText),3)])])],6)),[[e.vShow,D.value]])}}),dt="";U.name="gocaptcha-click",U.install=function(c){c.component("gocaptcha-click",U)};const ce=()=>({width:300,height:220,thumbWidth:150,thumbHeight:40,verticalPadding:16,horizontalPadding:12,showTheme:!0,title:"请拖动滑块完成拼图",iconSize:22,scope:!0}),xe=[e.createElementVNode("path",{d:`M131.6,116.3c0,0-75.6,0-109.7,0c-9.1,0-16.2-7.4-16.2-16.2c0-9.1,7.4-16.2,16.2-16.2c28.7,0,109.7,0,109.7,0 s-5.4-5.4-30.4-30.7c-6.4-6.4-6.4-16.7,0-23.1s16.7-6.4,23.1,0l58.4,58.4c6.4,6.4,6.4,16.7,0,23.1c0,0-32.9,32.9-57.9,57.9 c-6.4,6.4-16.7,6.4-23.1,0c-6.4-6.4-6.4-16.7,0-23.1C121.8,126.2,131.6,116.3,131.6,116.3z`},null,-1)],oe=e.defineComponent({__name:"arrows-icon",emits:["click"],setup(c,{emit:n}){const o=n;function h(i){o("click",i)}return(i,g)=>(e.openBlock(),e.createElementBlock("svg",e.mergeProps({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 200 200",width:"20",height:"20"},i.$attrs,{onClick:h}),xe,16))}}),se=()=>({thumbX:0,thumbY:0,thumbWidth:0,thumbHeight:0,image:"",thumb:""});function Le(c,n,o,h,i,g,r,s,t){const d=e.reactive({dragLeft:0,thumbLeft:c.thumbX||0,isFreeze:!1});e.watch(()=>c,(m,C)=>{d.isFreeze||(d.thumbLeft=m.thumbX||0)},{deep:!0});const y=m=>{if(!I(s.value,m))return;const C=m.touches&&m.touches[0],v=r.value.offsetLeft,w=i.value.offsetWidth,f=r.value.offsetWidth,b=w-f,u=g.value.offsetWidth,k=g.value.offsetLeft,S=w-u,Y=(w-(u+k))/b;let M=!1,$=null,O=0,P=0;C?O=C.pageX-v:O=m.clientX-v;const T=V=>{M=!0;const H=V.touches&&V.touches[0];let B=0;H?B=H.pageX-O:B=V.clientX-O;let st=k+B*Y;if(B>=b){d.dragLeft=b,d.thumbLeft=P=S;return}if(B<=0){d.dragLeft=0,d.thumbLeft=P=k;return}d.dragLeft=B,d.thumbLeft=P=st,n.move&&n.move(P,c.thumbY||0),V.cancelBubble=!0,V.preventDefault()},W=V=>{I(s.value,V)&&(N(),M&&(M=!1,!(P<0)&&(n.confirm&&n.confirm({x:parseInt(P.toString()),y:c.thumbY||0},()=>{a()}),V.cancelBubble=!0,V.preventDefault())))},R=V=>{$=V},X=()=>{$=null},A=V=>{$&&(W($),N())},x=o.scope,L=x?h.value:s.value,z=x?h.value:document.body,N=()=>{z.removeEventListener("mousemove",T,!1),z.removeEventListener("touchmove",T,{passive:!1}),L.removeEventListener("mouseup",W,!1),L.removeEventListener("mouseenter",X,!1),L.removeEventListener("mouseleave",R,!1),L.removeEventListener("touchend",W,!1),z.removeEventListener("mouseleave",W,!1),z.removeEventListener("mouseup",A,!1),d.isFreeze=!1};d.isFreeze=!0,z.addEventListener("mousemove",T,!1),z.addEventListener("touchmove",T,{passive:!1}),L.addEventListener("mouseup",W,!1),L.addEventListener("mouseenter",X,!1),L.addEventListener("mouseleave",R,!1),L.addEventListener("touchend",W,!1),z.addEventListener("mouseleave",W,!1),z.addEventListener("mouseup",A,!1)},_=m=>(p(),m.cancelBubble=!0,m.preventDefault(),!1),l=m=>(D(),m.cancelBubble=!0,m.preventDefault(),!1),p=()=>{n&&n.close&&n.close(),a()},D=()=>{n&&n.refresh&&n.refresh(),a()},a=()=>{d.dragLeft=0,d.thumbLeft=c.thumbX||0};return{state:d,dragEvent:y,closeEvent:_,refreshEvent:l,resetData:a,clearData:()=>{t&&t(),a()},refresh:D,close:p}}const mt="",Se={__name:"Tips",props:{show:{type:Boolean,default:!1},content:{type:String,default:""},type:{type:String,default:"SUCCESS",validator:c=>["SUCCESS","WARNING","ERROR"].includes(c)},duration:{type:Number,default:1500}},emits:["update:show"],setup(c,{emit:n}){const o=c,h=n,i=e.ref(null),g=e.ref(!1);let r=null;const s=e.computed(()=>`notification-${o.type.toLowerCase()}`);e.watch(()=>o.show,y=>{y?t():d()}),e.onMounted(()=>{o.show&&t()});function t(){clearTimeout(r),g.value=!0,o.duration>0&&(r=setTimeout(()=>{d()},o.duration))}function d(){g.value=!1,h("update:show",!1)}return(y,_)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"notification",ref:i,class:e.normalizeClass(["notification",[s.value,{show:g.value}]])},e.toDisplayString(c.content),3))}},ze={class:"gc-header"},Ce={class:"gc-icon-block"},De={class:"gc-loading"},ve=["src"],$e=["src"],Ne={class:"gc-footer"},Ve=e.createElementVNode("div",{class:"gc-drag-line"},null,-1),q=e.defineComponent({__name:"index",props:{config:{default:ce},events:{default:()=>({})},data:{default:se}},setup(c,{expose:n}){const o=e.reactive({show:!1,content:"",type:"SUCCESS"}),h=c,{data:i,events:g,config:r}=h,s=e.reactive({...se(),...e.toRaw(i)}),t=e.reactive({...e.toRaw(g)}),d=e.reactive({...ce(),...e.toRaw(r)});e.watch(()=>h.data,(u,k)=>{Object.assign(s,u)},{deep:!0}),e.watch(()=>h.events,(u,k)=>{Object.assign(t,u)},{deep:!0}),e.watch(()=>h.config,(u,k)=>{Object.assign(d,u)},{deep:!0});const y=e.ref(null),_=e.ref(null),l=e.ref(null),p=e.ref(null),D=e.ref(null),a=Le(s,t,d,y,l,D,p,_,()=>{s.thumb="",s.image="",s.thumbX=0,s.thumbY=0,s.thumbWidth=0,s.thumbHeight=0}),E=e.computed(()=>{const u=d.horizontalPadding||0,k=d.verticalPadding||0;return{width:(d.width||0)+u*2+(d.showTheme?2:0)+"px",paddingLeft:u+"px",paddingRight:u+"px",paddingTop:k+"px",paddingBottom:k+"px"}}),m=e.computed(()=>({width:s.thumbWidth+"px",height:s.thumbHeight+"px",top:s.thumbY+"px",left:a.state.thumbLeft+"px"})),C=e.computed(()=>({width:d.width+"px",height:d.height+"px"})),v=e.computed(()=>s.image&&s.image.length>0),w=e.computed(()=>s.thumb&&s.thumb.length>0),f=e.computed(()=>(d.width||0)>0||(d.height||0)>0),b=u=>u.preventDefault();return e.onMounted(async()=>{await e.nextTick(),p.value&&p.value.addEventListener("dragstart",b)}),e.onUnmounted(()=>{p.value&&p.value.removeEventListener("dragstart",b)}),n({reset:a.resetData,clear:a.clearData,refresh:a.refresh,close:a.close,setTips:(u,k,S)=>{o.show=u,o.content=k,o.type=S}}),(u,k)=>e.withDirectives((e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(`go-captcha gc-wrapper ${d.showTheme&&"gc-theme"}`),style:e.normalizeStyle(E.value),ref_key:"rootRef",ref:y},[e.createElementVNode("div",ze,[e.createElementVNode("span",null,e.toDisplayString(d.title),1),e.createElementVNode("div",Ce,[e.createVNode(Q,{width:d.iconSize,height:d.iconSize,onClick:e.unref(a).closeEvent},null,8,["width","height","onClick"]),e.createVNode(Z,{width:d.iconSize,height:d.iconSize,onClick:e.unref(a).refreshEvent},null,8,["width","height","onClick"])])]),e.createElementVNode("div",{class:e.normalizeClass(`gc-body ${o.type=="SUCCESS"&&o.show?"shine-effect-tr-bl":""}`),ref_key:"containerRef",ref:l,style:e.normalizeStyle(C.value)},[e.createElementVNode("div",De,[e.createVNode(ee)]),e.withDirectives(e.createElementVNode("img",{class:"gc-picture",style:e.normalizeStyle(C.value),src:s.image,alt:""},null,12,ve),[[e.vShow,v.value]]),e.createVNode(Se,{show:o.show,"onUpdate:show":k[0]||(k[0]=S=>o.show=S),content:o.content,type:o.type},null,8,["show","content","type"]),e.createElementVNode("div",{class:"gc-tile",ref_key:"tileRef",ref:D,style:e.normalizeStyle(m.value)},[e.withDirectives(e.createElementVNode("img",{src:s.thumb,alt:""},null,8,$e),[[e.vShow,w.value]])],4)],6),e.createElementVNode("div",Ne,[e.createElementVNode("div",{class:"gc-drag-slide-bar",ref_key:"dragBarRef",ref:_},[Ve,e.createElementVNode("div",{class:e.normalizeClass(["gc-drag-block",!v.value&&"disabled"]),ref_key:"dragBlockRef",ref:p,onMousedown:k[2]||(k[2]=(...S)=>e.unref(a).dragEvent&&e.unref(a).dragEvent(...S)),style:e.normalizeStyle({left:e.unref(a).state.dragLeft+"px"})},[e.createElementVNode("div",{class:"gc-drag-block-inline",onTouchstart:k[1]||(k[1]=(...S)=>e.unref(a).dragEvent&&e.unref(a).dragEvent(...S))},[e.createVNode(oe)],32)],38)],512)])],6)),[[e.vShow,f.value]])}}),ft="";q.name="gocaptcha-slide",q.install=function(c){c.component("gocaptcha-slide",q)};const ae=()=>({width:300,height:220,verticalPadding:16,horizontalPadding:12,showTheme:!0,title:"请拖拽贴图完成拼图",iconSize:22,scope:!0}),le=()=>({thumbX:0,thumbY:0,thumbWidth:0,thumbHeight:0,image:"",thumb:""});function Be(c,n,o,h,i,g,r){const s=e.reactive({x:c.thumbX||0,y:c.thumbY||0,isFreeze:!1});e.watch(()=>c,(a,E)=>{s.isFreeze||(s.x=a.thumbX||0,s.y=a.thumbY||0)},{deep:!0});const t=a=>{if(!I(i.value,a))return;const E=a.touches&&a.touches[0],m=g.value.offsetLeft,C=g.value.offsetTop,v=i.value.offsetWidth,w=i.value.offsetHeight,f=g.value.offsetWidth,b=g.value.offsetHeight,u=v-f,k=w-b;let S=!1,j=null,Y=0,M=0,$=0,O=0;E?(Y=E.pageX-m,M=E.pageY-C):(Y=a.clientX-m,M=a.clientY-C);const P=N=>{S=!0;const V=N.touches&&N.touches[0];let H=0,B=0;V?(H=V.pageX-Y,B=V.pageY-M):(H=N.clientX-Y,B=N.clientY-M),H<=0&&(H=0),B<=0&&(B=0),H>=u&&(H=u),B>=k&&(B=k),s.x=H,s.y=B,$=H,O=B,n.move&&n.move(H,B),N.cancelBubble=!0,N.preventDefault()},T=N=>{I(i.value,N)&&(z(),S&&(S=!1,!($<0||O<0)&&(n.confirm&&n.confirm({x:$,y:O},()=>{p()}),N.cancelBubble=!0,N.preventDefault())))},W=N=>{j=N},R=()=>{j=null},X=N=>{j&&(T(j),z())},A=o.scope,x=A?h.value:i.value,L=A?h.value:document.body,z=()=>{L.removeEventListener("mousemove",P,!1),L.removeEventListener("touchmove",P,{passive:!1}),x.removeEventListener("mouseup",T,!1),x.removeEventListener("mouseenter",R,!1),x.removeEventListener("mouseleave",W,!1),x.removeEventListener("touchend",T,!1),L.removeEventListener("mouseleave",T,!1),L.removeEventListener("mouseup",X,!1),s.isFreeze=!1};s.isFreeze=!0,L.addEventListener("mousemove",P,!1),L.addEventListener("touchmove",P,{passive:!1}),x.addEventListener("mouseup",T,!1),x.addEventListener("mouseenter",R,!1),x.addEventListener("mouseleave",W,!1),x.addEventListener("touchend",T,!1),L.addEventListener("mouseleave",T,!1),L.addEventListener("mouseup",X,!1)},d=a=>(_(),a.cancelBubble=!0,a.preventDefault(),!1),y=a=>(l(),a.cancelBubble=!0,a.preventDefault(),!1),_=()=>{n&&n.close&&n.close(),p()},l=()=>{n&&n.refresh&&n.refresh(),p()},p=()=>{s.x=c.thumbX||0,s.y=c.thumbY||0};return{state:s,dragEvent:t,closeEvent:d,refreshEvent:y,resetData:p,clearData:()=>{r&&r(),p()},refresh:l,close:_}}const Te={class:"gc-header gc-header2"},Pe={class:"gc-loading"},Re=["src"],Xe=["src"],Me={class:"gc-footer"},We={class:"gc-icon-block"},G=e.defineComponent({__name:"index",props:{config:{default:ae},events:{default:()=>({})},data:{default:le}},setup(c,{expose:n}){const o=c,{data:h,events:i,config:g}=o,r=e.reactive({...le(),...e.toRaw(h)}),s=e.reactive({...e.toRaw(i)}),t=e.reactive({...ae(),...e.toRaw(g)});e.watch(()=>o.data,(w,f)=>{Object.assign(r,w)},{deep:!0}),e.watch(()=>o.events,(w,f)=>{Object.assign(s,w)},{deep:!0}),e.watch(()=>o.config,(w,f)=>{Object.assign(t,w)},{deep:!0});const d=e.ref(null),y=e.ref(null),_=e.ref(null),l=Be(r,s,t,d,y,_,()=>{r.thumb="",r.image="",r.thumbX=0,r.thumbY=0,r.thumbWidth=0,r.thumbHeight=0}),p=e.computed(()=>{const w=t.horizontalPadding||0,f=t.verticalPadding||0;return{width:(t.width||0)+w*2+(t.showTheme?2:0)+"px",paddingLeft:w+"px",paddingRight:w+"px",paddingTop:f+"px",paddingBottom:f+"px"}}),D=e.computed(()=>({width:r.thumbWidth+"px",height:r.thumbHeight+"px",top:l.state.y+"px",left:l.state.x+"px"})),a=e.computed(()=>({width:t.width+"px",height:t.height+"px"})),E=e.computed(()=>r.image&&r.image.length>0),m=e.computed(()=>r.thumb&&r.thumb.length>0),C=e.computed(()=>(t.width||0)>0||(t.height||0)>0),v=w=>w.preventDefault();return e.onMounted(async()=>{await e.nextTick(),_.value&&_.value.addEventListener("dragstart",v)}),e.onUnmounted(()=>{_.value&&_.value.removeEventListener("dragstart",v)}),n({reset:l.resetData,clear:l.clearData,refresh:l.refresh,close:l.close}),(w,f)=>e.withDirectives((e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(`go-captcha gc-wrapper ${t.showTheme&&"gc-theme"}`),style:e.normalizeStyle(p.value),ref_key:"rootRef",ref:d},[e.createElementVNode("div",Te,[e.createElementVNode("span",null,e.toDisplayString(t.title),1)]),e.createElementVNode("div",{class:"gc-body",ref_key:"containerRef",ref:y,style:e.normalizeStyle(a.value)},[e.createElementVNode("div",Pe,[e.createVNode(ee)]),e.withDirectives(e.createElementVNode("img",{class:"gc-picture",style:e.normalizeStyle(a.value),src:r.image,alt:""},null,12,Re),[[e.vShow,E.value]]),e.createElementVNode("div",{class:"gc-tile",ref_key:"tileRef",ref:_,style:e.normalizeStyle(D.value),onMousedown:f[0]||(f[0]=(...b)=>e.unref(l).dragEvent&&e.unref(l).dragEvent(...b)),onTouchstart:f[1]||(f[1]=(...b)=>e.unref(l).dragEvent&&e.unref(l).dragEvent(...b))},[e.withDirectives(e.createElementVNode("img",{src:r.thumb,alt:""},null,8,Xe),[[e.vShow,m.value]])],36)],4),e.createElementVNode("div",Me,[e.createElementVNode("div",We,[e.createVNode(Q,{width:t.iconSize,height:t.iconSize,onClick:e.unref(l).closeEvent},null,8,["width","height","onClick"]),e.createVNode(Z,{width:t.iconSize,height:t.iconSize,onClick:e.unref(l).refreshEvent},null,8,["width","height","onClick"])])])],6)),[[e.vShow,C.value]])}}),gt="";G.name="gocaptcha-slide-region",G.install=function(c){c.component("gocaptcha-slide-region",G)};const te=()=>({width:300,height:220,size:220,verticalPadding:16,horizontalPadding:12,showTheme:!0,title:"请拖动滑块完成拼图",iconSize:22,scope:!0}),ie=()=>({angle:0,image:"",thumb:"",thumbSize:0});function Fe(c,n,o,h,i,g,r){const s=e.reactive({dragLeft:0,thumbAngle:c.angle||0,isFreeze:!1});e.watch(()=>c,(a,E)=>{s.isFreeze||(s.thumbAngle=a.angle||0)},{deep:!0});const t=a=>{if(!I(g.value,a))return;const E=a.touches&&a.touches[0],m=i.value.offsetLeft,C=g.value.offsetWidth,v=i.value.offsetWidth,w=C-v,f=360,b=(f-c.angle)/w;let u=0,k=!1,S=null,j=0,Y=0;E?j=E.pageX-m:j=a.clientX-m;const M=x=>{k=!0;const L=x.touches&&x.touches[0];let z=0;if(L?z=L.pageX-j:z=x.clientX-j,u=c.angle+z*b,z>=w){s.dragLeft=w,s.thumbAngle=Y=f;return}if(z<=0){s.dragLeft=0,s.thumbAngle=Y=c.angle;return}s.dragLeft=z,s.thumbAngle=Y=u,n.rotate&&n.rotate(u),x.cancelBubble=!0,x.preventDefault()},$=x=>{I(g.value,x)&&(A(),k&&(k=!1,!(Y<0)&&(n.confirm&&n.confirm(parseInt(Y.toString()),()=>{p()}),x.cancelBubble=!0,x.preventDefault())))},O=x=>{S=x},P=()=>{S=null},T=x=>{S&&($(S),A())},W=o.scope,R=W?h.value:g.value,X=W?h.value:document.body,A=()=>{X.removeEventListener("mousemove",M,!1),X.removeEventListener("touchmove",M,{passive:!1}),R.removeEventListener("mouseup",$,!1),R.removeEventListener("mouseenter",P,!1),R.removeEventListener("mouseleave",O,!1),R.removeEventListener("touchend",$,!1),X.removeEventListener("mouseleave",$,!1),X.removeEventListener("mouseup",T,!1),s.isFreeze=!1};s.isFreeze=!0,X.addEventListener("mousemove",M,!1),X.addEventListener("touchmove",M,{passive:!1}),R.addEventListener("mouseup",$,!1),R.addEventListener("mouseenter",P,!1),R.addEventListener("mouseleave",O,!1),R.addEventListener("touchend",$,!1),X.addEventListener("mouseleave",$,!1),X.addEventListener("mouseup",T,!1)},d=a=>(_(),a.cancelBubble=!0,a.preventDefault(),!1),y=a=>(l(),a.cancelBubble=!0,a.preventDefault(),!1),_=()=>{n&&n.close&&n.close(),p()},l=()=>{n&&n.refresh&&n.refresh(),p()},p=()=>{s.dragLeft=0,s.thumbAngle=c.angle};return{state:s,dragEvent:t,closeEvent:d,refreshEvent:y,resetData:p,clearData:()=>{r&&r(),p()},refresh:l,close:_}}const Ye={class:"gc-header"},He={class:"gc-icon-block"},Oe={class:"gc-loading"},je=["src"],Ae=e.createElementVNode("div",{class:"gc-round"},null,-1),Ie={class:"gc-thumb gc-rotate-thumb"},Ue=["src"],qe={class:"gc-footer"},Ge=e.createElementVNode("div",{class:"gc-drag-line"},null,-1),J=e.defineComponent({__name:"index",props:{config:{default:te},events:{default:()=>({})},data:{default:ie}},setup(c,{expose:n}){const o=c,{data:h,events:i,config:g}=o,r=e.reactive({...ie(),...e.toRaw(h)}),s=e.reactive({...e.toRaw(i)}),t=e.reactive({...te(),...e.toRaw(g)});e.watch(()=>o.data,(f,b)=>{Object.assign(r,f)},{deep:!0}),e.watch(()=>o.events,(f,b)=>{Object.assign(s,f)},{deep:!0}),e.watch(()=>o.config,(f,b)=>{Object.assign(t,f)},{deep:!0});const d=e.ref(null),y=e.ref(null),_=e.ref(null),l=Fe(r,s,t,d,_,y,()=>{r.thumb="",r.image="",r.angle=0}),p=e.computed(()=>{const f=t.horizontalPadding||0,b=t.verticalPadding||0;return{width:(t.width||0)+f*2+(t.showTheme?2:0)+"px",paddingLeft:f+"px",paddingRight:f+"px",paddingTop:b+"px",paddingBottom:b+"px"}}),D=e.computed(()=>({transform:`rotate(${l.state.thumbAngle}deg)`,...r.thumbSize>0?{width:r.thumbSize+"px",height:r.thumbSize+"px"}:{}})),a=e.computed(()=>({width:t.width+"px",height:t.height+"px"})),E=e.computed(()=>{const f=(t.size||0)>0?t.size:te().size;return{width:f+"px",height:f+"px"}}),m=e.computed(()=>r.image&&r.image.length>0),C=e.computed(()=>r.thumb&&r.thumb.length>0),v=e.computed(()=>(t.width||0)>0||(t.height||0)>0),w=f=>f.preventDefault();return e.onMounted(async()=>{await e.nextTick(),_.value&&_.value.addEventListener("dragstart",w)}),e.onUnmounted(()=>{_.value&&_.value.removeEventListener("dragstart",w)}),n({reset:l.resetData,clear:l.clearData,refresh:l.refresh,close:l.close}),(f,b)=>e.withDirectives((e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(`go-captcha gc-wrapper ${t.showTheme&&"gc-theme"}`),style:e.normalizeStyle(p.value),ref_key:"rootRef",ref:d},[e.createElementVNode("div",Ye,[e.createElementVNode("span",null,e.toDisplayString(t.title),1),e.createElementVNode("div",He,[e.createVNode(Q,{width:t.iconSize,height:t.iconSize,onClick:e.unref(l).closeEvent},null,8,["width","height","onClick"]),e.createVNode(Z,{width:t.iconSize,height:t.iconSize,onClick:e.unref(l).refreshEvent},null,8,["width","height","onClick"])])]),e.createElementVNode("div",{class:"gc-body gc-rotate-body",ref:"containerRef",style:e.normalizeStyle(a.value)},[e.createElementVNode("div",{class:"gc-body-inner",style:e.normalizeStyle(E.value)},[e.createElementVNode("div",Oe,[e.createVNode(ee)]),e.createElementVNode("div",{class:"gc-picture gc-rotate-picture",style:e.normalizeStyle(E.value)},[e.withDirectives(e.createElementVNode("img",{src:r.image,alt:""},null,8,je),[[e.vShow,m.value]]),Ae],4),e.createElementVNode("div",Ie,[e.createElementVNode("div",{class:"gc-rotate-thumb-block",style:e.normalizeStyle(D.value)},[e.withDirectives(e.createElementVNode("img",{src:r.thumb,alt:""},null,8,Ue),[[e.vShow,C.value]])],4)])],4)],4),e.createElementVNode("div",qe,[e.createElementVNode("div",{class:"gc-drag-slide-bar",ref_key:"dragBarRef",ref:y},[Ge,e.createElementVNode("div",{class:e.normalizeClass(["gc-drag-block",!m.value&&"disabled"]),ref_key:"dragBlockRef",ref:_,onMousedown:b[1]||(b[1]=(...u)=>e.unref(l).dragEvent&&e.unref(l).dragEvent(...u)),style:e.normalizeStyle({left:e.unref(l).state.dragLeft+"px"})},[e.createElementVNode("div",{class:"gc-drag-block-inline",onTouchstart:b[0]||(b[0]=(...u)=>e.unref(l).dragEvent&&e.unref(l).dragEvent(...u))},[e.createVNode(oe)],32)],38)],512)])],6)),[[e.vShow,v.value]])}}),pt="";J.name="gocaptcha-rotate",J.install=function(c){c.component("gocaptcha-rotate",J)};const Je=[e.createElementVNode("circle",{fill:"#3E7CFF",cx:"100",cy:"100",r:"96.3"},null,-1),e.createElementVNode("path",{fill:"#FFFFFF",d:`M140.8,64.4l-39.6-11.9h-2.4L59.2,64.4c-1.6,0.8-2.8,2.4-2.8,4v24.1c0,25.3,15.8,45.9,42.3,54.6 c0.4,0,0.8,0.4,1.2,0.4c0.4,0,0.8,0,1.2-0.4c26.5-8.7,42.3-28.9,42.3-54.6V68.3C143.5,66.8,142.3,65.2,140.8,64.4z`},null,-1)],Ke=e.defineComponent({__name:"btn-default-icon",emits:["click"],setup(c,{emit:n}){const o=n;function h(i){o("click",i)}return(i,g)=>(e.openBlock(),e.createElementBlock("svg",e.mergeProps({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 200 200",width:"20",height:"20"},i.$attrs,{onClick:h}),Je,16))}}),Qe=[e.createElementVNode("path",{fill:"#FFA000",d:`M184,26.6L102.4,2.1h-4.9L16,26.6c-3.3,1.6-5.7,4.9-5.7,8.2v49.8c0,52.2,32.6,94.7,87.3,112.6 c0.8,0,1.6,0.8,2.4,0.8s1.6,0,2.4-0.8c54.7-18,87.3-59.6,87.3-112.6V34.7C189.8,31.5,187.3,28.2,184,26.6z M107.3,109.1 c-0.5,5.4-3.9,7.9-7.3,7.9c-2.5,0,0,0,0,0c-3.2-0.6-5.7-2-6.8-7.4l-4.4-50.9c0-5.1,6.2-9.7,11.5-9.7c5.3,0,11,4.7,11,9.9 L107.3,109.1z M109.3,133.3c0,5.1-4.2,9.3-9.3,9.3c-5.1,0-9.3-4.2-9.3-9.3c0-5.1,4.2-9.3,9.3-9.3C105.1,124,109.3,128.1,109.3,133.3 z`},null,-1)],Ze=e.defineComponent({__name:"btn-warn-icon",emits:["click"],setup(c,{emit:n}){const o=n;function h(i){o("click",i)}return(i,g)=>(e.openBlock(),e.createElementBlock("svg",e.mergeProps({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 200 200",width:"20",height:"20"},i.$attrs,{onClick:h}),Qe,16))}}),et=[e.createElementVNode("path",{fill:"#ED4630",d:`M184,26.6L102.4,2.1h-4.9L16,26.6c-3.3,1.6-5.7,4.9-5.7,8.2v49.8c0,52.2,32.6,94.7,87.3,112.6 c0.8,0,1.6,0.8,2.4,0.8s1.6,0,2.4-0.8c54.7-18,87.3-59.6,87.3-112.6V34.7C189.8,31.5,187.3,28.2,184,26.6z M134.5,123.1 c3.1,3.1,3.1,8.2,0,11.3c-1.6,1.6-3.6,2.3-5.7,2.3s-4.1-0.8-5.7-2.3L100,111.3l-23.1,23.1c-1.6,1.6-3.6,2.3-5.7,2.3 c-2,0-4.1-0.8-5.7-2.3c-3.1-3.1-3.1-8.2,0-11.3L88.7,100L65.5,76.9c-3.1-3.1-3.1-8.2,0-11.3c3.1-3.1,8.2-3.1,11.3,0L100,88.7 l23.1-23.1c3.1-3.1,8.2-3.1,11.3,0c3.1,3.1,3.1,8.2,0,11.3L111.3,100L134.5,123.1z`},null,-1)],tt=e.defineComponent({__name:"btn-error-icon",emits:["click"],setup(c,{emit:n}){const o=n;function h(i){o("click",i)}return(i,g)=>(e.openBlock(),e.createElementBlock("svg",e.mergeProps({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 200 200",width:"20",height:"20"},i.$attrs,{onClick:h}),et,16))}}),nt=[e.createElementVNode("path",{fill:"#5EAA2F",d:`M183.3,27.2L102.4,2.9h-4.9L16.7,27.2C13.4,28.8,11,32,11,35.3v49.4c0,51.8,32.4,93.9,86.6,111.7 c0.8,0,1.6,0.8,2.4,0.8c0.8,0,1.6,0,2.4-0.8c54.2-17.8,86.6-59.1,86.6-111.7V35.3C189,32,186.6,28.8,183.3,27.2z M146.1,81.4 l-48.5,48.5c-1.6,1.6-3.2,2.4-5.7,2.4c-2.4,0-4-0.8-5.7-2.4L62,105.7c-3.2-3.2-3.2-8.1,0-11.3c3.2-3.2,8.1-3.2,11.3,0l18.6,18.6 l42.9-42.9c3.2-3.2,8.1-3.2,11.3,0C149.4,73.3,149.4,78.2,146.1,81.4L146.1,81.4z`},null,-1)],ct=e.defineComponent({__name:"btn-success-icon",emits:["click"],setup(c,{emit:n}){const o=n;function h(i){o("click",i)}return(i,g)=>(e.openBlock(),e.createElementBlock("svg",e.mergeProps({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 200 200",width:"20",height:"20"},i.$attrs,{onClick:h}),nt,16))}}),re=()=>({width:330,height:44,verticalPadding:12,horizontalPadding:16}),K=e.defineComponent({__name:"index",props:{config:{default:re},clickEvent:{},disabled:{type:Boolean,default:!1},type:{default:"default"},title:{default:"点击按键进行验证"}},emits:["click-event"],setup(c,{emit:n}){const o=c,{type:h,title:i,disabled:g,config:r}=e.toRefs(o),s=e.reactive({...re(),...e.toRaw(r)});e.watch(()=>o.config,(l,p)=>{Object.assign(s,l)},{deep:!0});const t=e.computed(()=>["go-captcha","gc-btn-block",`gc-${h.value}`,g.value?"gc-disabled":""]),d=e.computed(()=>({width:s.width+"px",height:s.height+"px",paddingLeft:s.horizontalPadding+"px",paddingRight:s.horizontalPadding+"px",paddingTop:s.verticalPadding+"px",paddingBottom:s.verticalPadding+"px"})),y=n;function _(l){y("click-event",l)}return(l,p)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(t.value),style:e.normalizeStyle(d.value),onClick:_},[e.createElementVNode("div",{class:e.normalizeClass(e.unref(h)==="default"?"gc-ripple":"")},[e.unref(h)==="default"?(e.openBlock(),e.createBlock(Ke,{key:0})):e.unref(h)==="warn"?(e.openBlock(),e.createBlock(Ze,{key:1})):e.unref(h)==="error"?(e.openBlock(),e.createBlock(tt,{key:2})):e.unref(h)==="success"?(e.openBlock(),e.createBlock(ct,{key:3})):e.createCommentVNode("",!0)],2),e.createElementVNode("span",null,e.toDisplayString(e.unref(i)),1)],6))}}),yt="";K.name="gocaptcha-button",K.install=function(c){c.component("gocaptcha-button",K)};const ot={install(c){U.install(c),q.install(c),G.install(c),J.install(c),K.install(c)}};F.Button=K,F.Click=U,F.Rotate=J,F.Slide=q,F.SlideRegion=G,F.default=ot,Object.defineProperties(F,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});