2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
import{H as Y,a as u,o as c,I as d,r as G,w as Q,T as Z,J as v,K as H,L as R,M as L,N as tt,i as T,t as U,O as et,P as J}from"./index-9a3ecfe5.js";var ot=Object.defineProperty,nt=Object.defineProperties,st=Object.getOwnPropertyDescriptors,q=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,X=(t,e,o)=>e in t?ot(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,f=(t,e)=>{for(var o in e||(e={}))it.call(e,o)&&X(t,o,e[o]);if(q)for(var o of q(e))rt.call(e,o)&&X(t,o,e[o]);return t},$=(t,e)=>nt(t,st(e));const S={type:"default",timeout:5e3,showCloseButton:!0,position:"top-right",transition:"bounce",hideProgressBar:!1,swipeClose:!0};var C,b;(b=C||(C={}))[b.TITLE_ONLY=0]="TITLE_ONLY",b[b.TITLE_DESCRIPTION=1]="TITLE_DESCRIPTION",b[b.COMPONENT=2]="COMPONENT",b[b.VNODE=3]="VNODE";const at={"top-left":{bounce:"mosha__bounceInLeft",zoom:"mosha__zoomIn",slide:"mosha__slideInLeft"},"top-right":{bounce:"mosha__bounceInRight",zoom:"mosha__zoomIn",slide:"mosha__slideInRight"},"top-center":{bounce:"mosha__bounceInDown",zoom:"mosha__zoomIn",slide:"mosha__slideInDown"},"bottom-center":{bounce:"mosha__bounceInUp",zoom:"mosha__zoomIn",slide:"mosha__slideInUp"},"bottom-right":{bounce:"mosha__bounceInRight",zoom:"mosha__zoomIn",slide:"mosha__slideInRight"},"bottom-left":{bounce:"mosha__bounceInLeft",zoom:"mosha__zoomIn",slide:"mosha__slideInLeft"}},F=(t,e=300)=>{let o;return(...n)=>{o&&(clearTimeout(o),o=void 0),o=setTimeout(()=>t(...n),e)}},lt=(t,e,o)=>{const n=v(),i=v(void 0),s=v(),l=a=>a instanceof MouseEvent,r=a=>{o!==!1&&n.value&&(l(a)?i.value=n.value.clientX-a.clientX:i.value=n.value.touches[0].clientX-a.touches[0].clientX,s.value=$(f({},s.value),{transition:"none"}),t.endsWith("left")?s.value.left=-i.value+"px !important":t.endsWith("right")?s.value.right=`${i.value}px !important`:i.value>0?s.value.left=-i.value+"px !important":s.value.right=`${i.value}px !important`,Math.abs(i.value)>200&&e())},g=a=>{o!==!1&&(n.value&&(n.value=void 0),i.value&&(i.value=void 0),removeEventListener(a,r))};return R(()=>{o!==!1&&(g("mousemove"),g("touchmove"))}),{swipedDiff:i,swipeStart:n,swipeStyle:s,swipeHandler:r,startSwipeHandler:a=>{if(o===!1)return;n.value=a;const I=l(a)?"mousemove":"touchmove",_=l(a)?"mouseup":"touchend";addEventListener(I,r),addEventListener(_,()=>(w=>{const M={transition:"left .3s ease-out",left:0},z={transition:"right .3s ease-out",right:0},B={transition:"all .3s ease-out",left:0,right:0};t.endsWith("left")?s.value=f(f({},s.value),M):t.endsWith("right")?s.value=f(f({},s.value),z):s.value=f(f({},s.value),B),n.value=void 0,i.value=void 0,removeEventListener(w,r)})(I))},cleanUpMove:g}};var K=Y({props:{type:{type:String,default:"default"}}});const ut={class:"mosha__icon"},pt={key:0,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},ct=u("path",{d:"M4.47 21h15.06c1.54 0 2.5-1.67 1.73-3L13.73 4.99c-.77-1.33-2.69-1.33-3.46 0L2.74 18c-.77 1.33.19 3 1.73 3zM12 14c-.55 0-1-.45-1-1v-2c0-.55.45-1 1-1s1 .45 1 1v2c0 .55-.45 1-1 1zm1 4h-2v-2h2v2z"},null,-1),dt={key:1,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},ht=u("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 11c-.55 0-1-.45-1-1V8c0-.55.45-1 1-1s1 .45 1 1v4c0 .55-.45 1-1 1zm1 4h-2v-2h2v2z"},null,-1),vt={key:2,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},mt=u("path",{d:"M0 0h24v24H0V0z",fill:"none"},null,-1),ft=u("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zM9.29 16.29L5.7 12.7c-.39-.39-.39-1.02 0-1.41.39-.39 1.02-.39 1.41 0L10 14.17l6.88-6.88c.39-.39 1.02-.39 1.41 0 .39.39.39 1.02 0 1.41l-7.59 7.59c-.38.39-1.02.39-1.41 0z"},null,-1),_t={key:3,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#616161"},gt=u("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),wt=u("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"},null,-1),yt={key:4,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},bt=u("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),It=u("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"},null,-1);K.render=function(t,e,o,n,i,s){return c(),d("span",ut,[t.type==="warning"?(c(),d("svg",pt,[ct])):t.type==="danger"?(c(),d("svg",dt,[ht])):t.type==="success"?(c(),d("svg",vt,[mt,ft])):t.type==="default"?(c(),d("svg",_t,[gt,wt])):(c(),d("svg",yt,[bt,It]))])};var O=Y({name:"MToast",components:{MIcon:K},props:{visible:Boolean,text:{type:String,default:""},description:{type:String,default:""},toastBackgroundColor:{type:String,default:""},type:{type:String,default:"default"},onClose:{type:Function,default:()=>null},onCloseHandler:{type:Function,required:!0},offset:{type:Number,required:!0},id:{type:Number,required:!0},timeout:{type:Number,default:5e3},position:{type:String,required:!0},showCloseButton:{type:Boolean,default:!0},swipeClose:{type:Boolean,default:!0},hideProgressBar:{type:Boolean,default:!1},showIcon:{type:Boolean,default:!1},transition:{type:String,default:"bounce"}},setup(t,e){const o=v(),{width:n}=(()=>{const h=v(-1),y=v(-1),p=m=>{m!==null&&m.currentTarget!==null&&(h.value=m.currentTarget.innerWidth,y.value=m.currentTarget.innerHeight)};return H(()=>{window.innerWidth>0&&(h.value=window.innerWidth,y.value=window.innerHeight),window.addEventListener("resize",F(p))}),R(()=>{window.removeEventListener("resize",F(p))}),{width:h,height:y}})(),{swipedDiff:i,startSwipeHandler:s,swipeStyle:l,cleanUpMove:r}=lt(t.position,t.onCloseHandler,t.swipeClose),{transitionType:g}=(a=t.position,I=t.transition,_=i,{transitionType:L(()=>_.value>200?"mosha__fadeOutLeft":_.value<-200?"mosha__fadeOutRight":at[a][I])});var a,I,_;const{start:w,stop:M,progress:z}=((h,y)=>{const p=v(),m=v(0),E=v(y),D=v(),W=v(100),j=()=>{clearInterval(D.value),clearTimeout(p.value)};return H(()=>{}),R(()=>{j()}),{start:()=>{m.value=Date.now(),clearTimeout(p.value),D.value=setInterval(()=>{W.value--},y/100-5),p.value=setTimeout(h,E.value)},stop:()=>{clearInterval(D.value),clearTimeout(p.value),E.value-=Date.now()-m.value},clear:j,progress:W}})(()=>{t.onCloseHandler()},t.timeout),B=L(()=>e.slots.default),A=L(()=>/<\/?[a-z][\s\S]*>/i.test(t.description)),P=()=>{t.timeout>0&&w()};return tt(()=>{const{customStyle:h}=((y,p,m)=>{const E=L(()=>{switch(y){case"top-left":return{left:"0",top:`${p}px`};case"bottom-left":return{left:"0",bottom:`${p}px`};case"bottom-right":return{right:"0",bottom:`${p}px`};case"top-center":return{top:`${p}px`,left:"0",right:"0",marginRight:"auto",marginLeft:"auto"};case"bottom-center":return{bottom:`${p}px`,left:"0",right:"0",marginRight:"auto",marginLeft:"auto"};default:return{right:"0",top:`${p}px`}}});return m.length>0&&(E.value.backgroundColor=m),{customStyle:E}})(t.position,t.offset,t.toastBackgroundColor);o.value=h.value}),H(()=>{P()}),{style:o,transitionType:g,startTimer:P,progress:z,onTouchStart:h=>{s(h)},onMouseLeave:()=>{r("mousemove"),P()},onMouseDown:h=>{s(h)},swipeStyle:l,isSlotPassed:B,isDescriptionHtml:A,onMouseEnter:()=>{t.timeout>0&&n.value>425&&M()}}}});const Tt={class:"mosha__toast__content-wrapper"},Ct={class:"mosha__toast__content"},xt={class:"mosha__toast__content__text"},Mt={key:1,class:"mosha__toast__content__description"},zt={key:0,class:"mosha__toast__slot-wrapper"};O.render=function(t,e,o,n,i,s){const l=G("MIcon");return c(),d(Z,{name:t.transitionType,type:"animation"},{default:Q(()=>[t.visible?(c(),d("div",{key:0,class:["mosha__toast",t.toastBackgroundColor?null:t.type],style:[t.style,t.swipeStyle],onMouseenter:e[2]||(e[2]=(...r)=>t.onMouseEnter&&t.onMouseEnter(...r)),onMouseleave:e[3]||(e[3]=(...r)=>t.onMouseLeave&&t.onMouseLeave(...r)),onTouchstartPassive:e[4]||(e[4]=(...r)=>t.onTouchStart&&t.onTouchStart(...r)),onMousedown:e[5]||(e[5]=(...r)=>t.onMouseDown&&t.onMouseDown(...r))},[u("div",Tt,[t.showIcon?(c(),d(l,{key:0,type:t.type},null,8,["type"])):T("",!0),u("div",Ct,[u("div",xt,U(t.text),1),t.description.length>0&&t.isDescriptionHtml?(c(),d("div",{key:0,class:"mosha__toast__content__description",innerHTML:t.description},null,8,["innerHTML"])):T("",!0),t.description.length>0&&!t.isDescriptionHtml?(c(),d("div",Mt,U(t.description),1)):T("",!0)])]),t.isSlotPassed?(c(),d("div",zt,[et(t.$slots,"default")])):T("",!0),t.showCloseButton?(c(),d("div",{key:1,class:"mosha__toast__close-icon",onClick:e[1]||(e[1]=(...r)=>t.onCloseHandler&&t.onCloseHandler(...r))})):T("",!0),t.hideProgressBar?T("",!0):(c(),d("div",{key:2,class:"mosha__toast__progress",style:{width:`${t.progress}%`}},null,4))],38)):T("",!0)]),_:3},8,["name"])};const N={"top-left":[],"top-right":[],"bottom-left":[],"bottom-right":[],"top-center":[],"bottom-center":[]};let Et=0;const Bt=(t,e)=>{const o=Et++,n=e?St(e):S;if(t.__v_isVNode)return k(o,C.VNODE,n,t),{close:()=>x(o,n.position)};if(t.hasOwnProperty("render"))return k(o,C.COMPONENT,n,t),{close:()=>x(o,n.position)};const i=Lt(t);return k(o,C.TITLE_DESCRIPTION,n,i),{close:()=>x(o,n.position)}},k=(t,e,o,n)=>{setTimeout(()=>{const i=Ot(o,N,12),s=document.createElement("div");let l;document.body.appendChild(s),l=e===C.VNODE?u(O,V(o,t,i,x),()=>[n]):e===C.TITLE_DESCRIPTION?u(O,V(o,t,i,x,n)):u(O,V(o,t,i,x),()=>[u(n)]),J(l,s),N[o.position].push({toastVNode:l,container:s}),l.component&&(l.component.props.visible=!0)},1)},V=(t,e,o,n,i)=>$(f(f({},t),i),{id:e,offset:o,visible:!1,onCloseHandler:()=>{n(e,t.position?t.position:"top-right")}}),St=t=>{const e=$(f({},t),{type:t.type||S.type,timeout:t.timeout||S.timeout,showCloseButton:t.showCloseButton,position:t.position||S.position,showIcon:t.showIcon,swipeClose:t.swipeClose,transition:t.transition||S.transition});return e.hideProgressBar=e.timeout!==void 0&&e.timeout<=0,t.hideProgressBar!==void 0&&(e.hideProgressBar=t.hideProgressBar),e},Lt=t=>({text:typeof t=="string"?t:t.title,description:typeof t=="string"?void 0:t.description}),Ot=(t,e,o)=>{let n=o;if(!t.position)throw new Error("no position");return e[t.position].forEach(({toastVNode:i})=>{const s=i.el.offsetHeight+o;n+=s||0}),n},x=(t,e)=>{const o=N[e],n=o.findIndex(({toastVNode:r})=>r.props&&t===r.props.id);if(n===-1)return;const{container:i,toastVNode:s}=o[n];if(!s.el)return;const l=s.el.offsetHeight;N[e].splice(n,1),((r,g,a,I)=>{for(let _=r;_<g.length;_++){const{toastVNode:w}=g[_];if(!w.el)return;const M=a.split("-")[0]||"top",z=parseInt(w.el.style[M],10)-I-12;if(!w.component)return;w.component.props.offset=z}})(n,o,e,l),s.component&&(s.component.props.visible=!1,s.component.props.onClose&&s.component.props.onClose(),setTimeout(()=>{J(null,i),document.body.removeChild(i)},1e3))};export{Bt as t};
|