mosha-vue-toastify
Advanced tools
Comparing version 1.0.21 to 1.0.22
@@ -1,1 +0,1 @@ | ||
var e=Object.defineProperty,t=Object.prototype.hasOwnProperty,o=Object.getOwnPropertySymbols,n=Object.prototype.propertyIsEnumerable,s=(t,o,n)=>o in t?e(t,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[o]=n,i=(e,i)=>{for(var r in i||(i={}))t.call(i,r)&&s(e,r,i[r]);if(o)for(var r of o(i))n.call(i,r)&&s(e,r,i[r]);return e};import{ref as r,onMounted as l,onUnmounted as a,computed as u,createVNode as p,defineComponent as c,openBlock as h,createBlock as d,watchEffect as v,resolveComponent as m,Transition as f,withCtx as g,createCommentVNode as _,toDisplayString as w,renderSlot as y,render as b}from"vue";const I={type:"default",timeout:5e3,showCloseButton:!0,position:"top-right",transition:"bounce",hideProgressBar:!1,swipeClose:!0};var T,x;(x=T||(T={}))[x.TITLE_ONLY=0]="TITLE_ONLY",x[x.TITLE_DESCRIPTION=1]="TITLE_DESCRIPTION",x[x.COMPONENT=2]="COMPONENT",x[x.VNODE=3]="VNODE";const C={"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"}},M=(e,t)=>p(e,t),E=(e,t=300)=>{let o;return(...n)=>{o&&(clearTimeout(o),o=void 0),o=setTimeout((()=>e(...n)),t)}},z=(e,t,o)=>{const n=r(),s=r(void 0),l=r(),u=e=>e instanceof MouseEvent,p=r=>{!1!==o&&n.value&&(u(r)?s.value=n.value.clientX-r.clientX:s.value=n.value.touches[0].clientX-r.touches[0].clientX,l.value=i(i({},l.value),{transition:"none"}),e.endsWith("left")?l.value.left=-s.value+"px !important":e.endsWith("right")?l.value.right=`${s.value}px !important`:s.value>0?l.value.left=-s.value+"px !important":l.value.right=`${s.value}px !important`,Math.abs(s.value)>200&&t())},c=e=>{!1!==o&&(n.value&&(n.value=void 0),s.value&&(s.value=void 0),removeEventListener(e,p))};return a((()=>{!1!==o&&(c("mousemove"),c("touchmove"))})),{swipedDiff:s,swipeStart:n,swipeStyle:l,swipeHandler:p,startSwipeHandler:t=>{if(!1===o)return;n.value=t;const r=u(t)?"mousemove":"touchmove",a=u(t)?"mouseup":"touchend";addEventListener(r,p),addEventListener(a,(()=>(t=>{const o={transition:"left .3s ease-out",left:0},r={transition:"right .3s ease-out",right:0},a={transition:"all .3s ease-out",left:0,right:0};e.endsWith("left")?l.value=i(i({},l.value),o):e.endsWith("right")?l.value=i(i({},l.value),r):l.value=i(i({},l.value),a),n.value=void 0,s.value=void 0,removeEventListener(t,p)})(r)))},cleanUpMove:c}};var S=c({props:{type:{type:String,default:"default"}}});const L={class:"mosha__icon"},N={key:0,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},O=p("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),B={key:1,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},P=p("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),H={key:2,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},D=p("path",{d:"M0 0h24v24H0V0z",fill:"none"},null,-1),k=p("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),V={key:3,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#616161"},R=p("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),$=p("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),W={key:4,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},j=p("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),q=p("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);S.render=function(e,t,o,n,s,i){return h(),d("span",L,["warning"===e.type?(h(),d("svg",N,[O])):"danger"===e.type?(h(),d("svg",B,[P])):"success"===e.type?(h(),d("svg",H,[D,k])):"default"===e.type?(h(),d("svg",V,[R,$])):(h(),d("svg",W,[j,q]))])};var U=c({name:"MToast",components:{MIcon:S},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(e,t){const o=r(),{width:n}=(()=>{const e=r(-1),t=r(-1),o=o=>{null!==o&&null!==o.currentTarget&&(e.value=o.currentTarget.innerWidth,t.value=o.currentTarget.innerHeight)};return l((()=>{window.innerWidth>0&&(e.value=window.innerWidth,t.value=window.innerHeight),window.addEventListener("resize",E(o))})),a((()=>{window.removeEventListener("resize",E(o))})),{width:e,height:t}})(),{swipedDiff:s,startSwipeHandler:i,swipeStyle:p,cleanUpMove:c}=z(e.position,e.onCloseHandler,e.swipeClose),{transitionType:h}=(d=e.position,m=e.transition,f=s,{transitionType:u((()=>f.value>200?"mosha__fadeOutLeft":f.value<-200?"mosha__fadeOutRight":C[d][m]))});var d,m,f;const{start:g,stop:_,progress:w}=((e,t)=>{const o=r(),n=r(0),s=r(t),i=r(),u=r(100),p=()=>{clearInterval(i.value),clearTimeout(o.value)};return l((()=>{})),a((()=>{p()})),{start:()=>{n.value=Date.now(),clearTimeout(o.value),i.value=setInterval((()=>{u.value--}),t/100-5),o.value=setTimeout(e,s.value)},stop:()=>{clearInterval(i.value),clearTimeout(o.value),s.value-=Date.now()-n.value},clear:p,progress:u}})((()=>{e.onCloseHandler()}),e.timeout),y=u((()=>t.slots.default)),b=u((()=>/<\/?[a-z][\s\S]*>/i.test(e.description))),I=()=>{e.timeout>0&&g()};return v((()=>{const{customStyle:t}=((e,t,o)=>{const n=u((()=>{switch(e){case"top-left":return{left:"0",top:`${t}px`};case"bottom-left":return{left:"0",bottom:`${t}px`};case"bottom-right":return{right:"0",bottom:`${t}px`};case"top-center":return{top:`${t}px`,left:"0",right:"0",marginRight:"auto",marginLeft:"auto"};case"bottom-center":return{bottom:`${t}px`,left:"0",right:"0",marginRight:"auto",marginLeft:"auto"};default:return{right:"0",top:`${t}px`}}}));return o.length>0&&(n.value.backgroundColor=o),{customStyle:n}})(e.position,e.offset,e.toastBackgroundColor);o.value=t.value})),l((()=>{I()})),{style:o,transitionType:h,startTimer:I,progress:w,onTouchStart:e=>{i(e)},onMouseLeave:()=>{c("mousemove"),I()},onMouseDown:e=>{i(e)},swipeStyle:p,isSlotPassed:y,isDescriptionHtml:b,onMouseEnter:()=>{e.timeout>0&&n.value>425&&_()}}}});const X={class:"mosha__toast__content-wrapper"},F={class:"mosha__toast__content"},Y={class:"mosha__toast__content__text"},A={key:1,class:"mosha__toast__content__description"},G={key:0,class:"mosha__toast__slot-wrapper"};U.render=function(e,t,o,n,s,i){const r=m("MIcon");return h(),d(f,{name:e.transitionType,type:"animation"},{default:g((()=>[e.visible?(h(),d("div",{key:0,class:["mosha__toast",e.toastBackgroundColor?null:e.type],style:[e.style,e.swipeStyle],onMouseenter:t[2]||(t[2]=(...t)=>e.onMouseEnter&&e.onMouseEnter(...t)),onMouseleave:t[3]||(t[3]=(...t)=>e.onMouseLeave&&e.onMouseLeave(...t)),onTouchstartPassive:t[4]||(t[4]=(...t)=>e.onTouchStart&&e.onTouchStart(...t)),onMousedown:t[5]||(t[5]=(...t)=>e.onMouseDown&&e.onMouseDown(...t))},[p("div",X,[e.showIcon?(h(),d(r,{key:0,type:e.type},null,8,["type"])):_("",!0),p("div",F,[p("div",Y,w(e.text),1),e.description.length>0&&e.isDescriptionHtml?(h(),d("div",{key:0,class:"mosha__toast__content__description",innerHTML:e.description},null,8,["innerHTML"])):_("",!0),e.description.length>0&&!e.isDescriptionHtml?(h(),d("div",A,w(e.description),1)):_("",!0)])]),e.isSlotPassed?(h(),d("div",G,[y(e.$slots,"default")])):_("",!0),e.showCloseButton?(h(),d("div",{key:1,class:"mosha__toast__close-icon",onClick:t[1]||(t[1]=(...t)=>e.onCloseHandler&&e.onCloseHandler(...t))})):_("",!0),e.hideProgressBar?_("",!0):(h(),d("div",{key:2,class:"mosha__toast__progress",style:{width:`${e.progress}%`}},null,4))],38)):_("",!0)])),_:3},8,["name"])};const J={"top-left":[],"top-right":[],"bottom-left":[],"bottom-right":[],"top-center":[],"bottom-center":[]};let K=0;const Q=(e,t)=>{const o=t?te(t):I;if(e.__v_isVNode){return{close:Z(T.VNODE,o,e)}}if(e.hasOwnProperty("render")){return{close:Z(T.COMPONENT,o,e)}}const n=oe(e);return{close:Z(T.TITLE_DESCRIPTION,o,n)}},Z=(e,t,o)=>{const n=ne(t,J,12),s=K++,i=document.createElement("div");let r;return document.body.appendChild(i),r=e===T.VNODE?p(U,ee(t,s,n,se),(()=>[o])):e===T.TITLE_DESCRIPTION?p(U,ee(t,s,n,se,o)):p(U,ee(t,s,n,se),(()=>[p(o)])),b(r,i),J[t.position].push({toastVNode:r,container:i}),r.component&&(r.component.props.visible=!0),()=>se(s,t.position)},ee=(e,t,o,n,s)=>i(i(i({},e),s),{id:t,offset:o,visible:!1,onCloseHandler:()=>{n(t,e.position?e.position:"top-right")}}),te=e=>{const t=i(i({},e),{type:e.type||I.type,timeout:e.timeout||I.timeout,showCloseButton:e.showCloseButton,position:e.position||I.position,showIcon:e.showIcon,swipeClose:e.swipeClose,transition:e.transition||I.transition});return t.hideProgressBar=void 0!==t.timeout&&t.timeout<=0,void 0!==e.hideProgressBar&&(t.hideProgressBar=e.hideProgressBar),t},oe=e=>({text:"string"==typeof e?e:e.title,description:"string"==typeof e?void 0:e.description}),ne=(e,t,o)=>{let n=o;if(!e.position)throw new Error("no position");return t[e.position].forEach((({toastVNode:e})=>{const t=e.el.offsetHeight+o;n+=t||0})),n},se=(e,t)=>{const o=J[t],n=o.findIndex((({toastVNode:t})=>t.props&&e===t.props.id));if(-1===n)return;const{container:s,toastVNode:i}=o[n];if(!i.el)return;const r=i.el.offsetHeight;J[t].splice(n,1),((e,t,o,n)=>{for(let s=e;s<t.length;s++){const{toastVNode:e}=t[s];if(!e.el)return;const i=o.split("-")[0]||"top",r=parseInt(e.el.style[i],10)-n-12;if(!e.component)return;e.component.props.offset=r}})(n,o,t,r),i.component&&(i.component.props.visible=!1,i.component.props.onClose&&i.component.props.onClose(),setTimeout((()=>{b(null,s),document.body.removeChild(s)}),1e3))},ie=()=>{Object.entries(J).forEach((([e,t])=>{if(t.length>0){t.map((e=>e.toastVNode.props.id)).forEach((t=>{se(t,e)}))}}))};var re={install:e=>{e.config.globalProperties.$moshaToast=Q,e.provide("moshaToast",Q)}};export default re;export{T as ToastContentType,ie as clearToasts,Q as createToast,M as withProps}; | ||
var e=Object.defineProperty,t=Object.defineProperties,o=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,r=(t,o,n)=>o in t?e(t,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[o]=n,l=(e,t)=>{for(var o in t||(t={}))s.call(t,o)&&r(e,o,t[o]);if(n)for(var o of n(t))i.call(t,o)&&r(e,o,t[o]);return e},a=(e,n)=>t(e,o(n));import{ref as u,onMounted as p,onUnmounted as c,computed as h,createVNode as d,defineComponent as v,openBlock as m,createBlock as f,watchEffect as g,resolveComponent as _,Transition as w,withCtx as y,createCommentVNode as b,toDisplayString as I,renderSlot as T,render as x}from"vue";const C={type:"default",timeout:5e3,showCloseButton:!0,position:"top-right",transition:"bounce",hideProgressBar:!1,swipeClose:!0};var M,E;(E=M||(M={}))[E.TITLE_ONLY=0]="TITLE_ONLY",E[E.TITLE_DESCRIPTION=1]="TITLE_DESCRIPTION",E[E.COMPONENT=2]="COMPONENT",E[E.VNODE=3]="VNODE";const z={"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"}},S=(e,t)=>d(e,t),L=(e,t=300)=>{let o;return(...n)=>{o&&(clearTimeout(o),o=void 0),o=setTimeout((()=>e(...n)),t)}},O=(e,t,o)=>{const n=u(),s=u(void 0),i=u(),r=e=>e instanceof MouseEvent,p=u=>{!1!==o&&n.value&&(r(u)?s.value=n.value.clientX-u.clientX:s.value=n.value.touches[0].clientX-u.touches[0].clientX,i.value=a(l({},i.value),{transition:"none"}),e.endsWith("left")?i.value.left=-s.value+"px !important":e.endsWith("right")?i.value.right=`${s.value}px !important`:s.value>0?i.value.left=-s.value+"px !important":i.value.right=`${s.value}px !important`,Math.abs(s.value)>200&&t())},h=e=>{!1!==o&&(n.value&&(n.value=void 0),s.value&&(s.value=void 0),removeEventListener(e,p))};return c((()=>{!1!==o&&(h("mousemove"),h("touchmove"))})),{swipedDiff:s,swipeStart:n,swipeStyle:i,swipeHandler:p,startSwipeHandler:t=>{if(!1===o)return;n.value=t;const a=r(t)?"mousemove":"touchmove",u=r(t)?"mouseup":"touchend";addEventListener(a,p),addEventListener(u,(()=>(t=>{const o={transition:"left .3s ease-out",left:0},r={transition:"right .3s ease-out",right:0},a={transition:"all .3s ease-out",left:0,right:0};e.endsWith("left")?i.value=l(l({},i.value),o):e.endsWith("right")?i.value=l(l({},i.value),r):i.value=l(l({},i.value),a),n.value=void 0,s.value=void 0,removeEventListener(t,p)})(a)))},cleanUpMove:h}};var N=v({props:{type:{type:String,default:"default"}}});const B={class:"mosha__icon"},P={key:0,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},D=d("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),H={key:1,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},k=d("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),V={key:2,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},R=d("path",{d:"M0 0h24v24H0V0z",fill:"none"},null,-1),$=d("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),j={key:3,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#616161"},W=d("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),q=d("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),U={key:4,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},X=d("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),F=d("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);N.render=function(e,t,o,n,s,i){return m(),f("span",B,["warning"===e.type?(m(),f("svg",P,[D])):"danger"===e.type?(m(),f("svg",H,[k])):"success"===e.type?(m(),f("svg",V,[R,$])):"default"===e.type?(m(),f("svg",j,[W,q])):(m(),f("svg",U,[X,F]))])};var Y=v({name:"MToast",components:{MIcon:N},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(e,t){const o=u(),{width:n}=(()=>{const e=u(-1),t=u(-1),o=o=>{null!==o&&null!==o.currentTarget&&(e.value=o.currentTarget.innerWidth,t.value=o.currentTarget.innerHeight)};return p((()=>{window.innerWidth>0&&(e.value=window.innerWidth,t.value=window.innerHeight),window.addEventListener("resize",L(o))})),c((()=>{window.removeEventListener("resize",L(o))})),{width:e,height:t}})(),{swipedDiff:s,startSwipeHandler:i,swipeStyle:r,cleanUpMove:l}=O(e.position,e.onCloseHandler,e.swipeClose),{transitionType:a}=(d=e.position,v=e.transition,m=s,{transitionType:h((()=>m.value>200?"mosha__fadeOutLeft":m.value<-200?"mosha__fadeOutRight":z[d][v]))});var d,v,m;const{start:f,stop:_,progress:w}=((e,t)=>{const o=u(),n=u(0),s=u(t),i=u(),r=u(100),l=()=>{clearInterval(i.value),clearTimeout(o.value)};return p((()=>{})),c((()=>{l()})),{start:()=>{n.value=Date.now(),clearTimeout(o.value),i.value=setInterval((()=>{r.value--}),t/100-5),o.value=setTimeout(e,s.value)},stop:()=>{clearInterval(i.value),clearTimeout(o.value),s.value-=Date.now()-n.value},clear:l,progress:r}})((()=>{e.onCloseHandler()}),e.timeout),y=h((()=>t.slots.default)),b=h((()=>/<\/?[a-z][\s\S]*>/i.test(e.description))),I=()=>{e.timeout>0&&f()};return g((()=>{const{customStyle:t}=((e,t,o)=>{const n=h((()=>{switch(e){case"top-left":return{left:"0",top:`${t}px`};case"bottom-left":return{left:"0",bottom:`${t}px`};case"bottom-right":return{right:"0",bottom:`${t}px`};case"top-center":return{top:`${t}px`,left:"0",right:"0",marginRight:"auto",marginLeft:"auto"};case"bottom-center":return{bottom:`${t}px`,left:"0",right:"0",marginRight:"auto",marginLeft:"auto"};default:return{right:"0",top:`${t}px`}}}));return o.length>0&&(n.value.backgroundColor=o),{customStyle:n}})(e.position,e.offset,e.toastBackgroundColor);o.value=t.value})),p((()=>{I()})),{style:o,transitionType:a,startTimer:I,progress:w,onTouchStart:e=>{i(e)},onMouseLeave:()=>{l("mousemove"),I()},onMouseDown:e=>{i(e)},swipeStyle:r,isSlotPassed:y,isDescriptionHtml:b,onMouseEnter:()=>{e.timeout>0&&n.value>425&&_()}}}});const A={class:"mosha__toast__content-wrapper"},G={class:"mosha__toast__content"},J={class:"mosha__toast__content__text"},K={key:1,class:"mosha__toast__content__description"},Q={key:0,class:"mosha__toast__slot-wrapper"};Y.render=function(e,t,o,n,s,i){const r=_("MIcon");return m(),f(w,{name:e.transitionType,type:"animation"},{default:y((()=>[e.visible?(m(),f("div",{key:0,class:["mosha__toast",e.toastBackgroundColor?null:e.type],style:[e.style,e.swipeStyle],onMouseenter:t[2]||(t[2]=(...t)=>e.onMouseEnter&&e.onMouseEnter(...t)),onMouseleave:t[3]||(t[3]=(...t)=>e.onMouseLeave&&e.onMouseLeave(...t)),onTouchstartPassive:t[4]||(t[4]=(...t)=>e.onTouchStart&&e.onTouchStart(...t)),onMousedown:t[5]||(t[5]=(...t)=>e.onMouseDown&&e.onMouseDown(...t))},[d("div",A,[e.showIcon?(m(),f(r,{key:0,type:e.type},null,8,["type"])):b("",!0),d("div",G,[d("div",J,I(e.text),1),e.description.length>0&&e.isDescriptionHtml?(m(),f("div",{key:0,class:"mosha__toast__content__description",innerHTML:e.description},null,8,["innerHTML"])):b("",!0),e.description.length>0&&!e.isDescriptionHtml?(m(),f("div",K,I(e.description),1)):b("",!0)])]),e.isSlotPassed?(m(),f("div",Q,[T(e.$slots,"default")])):b("",!0),e.showCloseButton?(m(),f("div",{key:1,class:"mosha__toast__close-icon",onClick:t[1]||(t[1]=(...t)=>e.onCloseHandler&&e.onCloseHandler(...t))})):b("",!0),e.hideProgressBar?b("",!0):(m(),f("div",{key:2,class:"mosha__toast__progress",style:{width:`${e.progress}%`}},null,4))],38)):b("",!0)])),_:3},8,["name"])};const Z={"top-left":[],"top-right":[],"bottom-left":[],"bottom-right":[],"top-center":[],"bottom-center":[]};let ee=0;const te=(e,t)=>{const o=t?se(t):C;if(e.__v_isVNode){return{close:oe(M.VNODE,o,e)}}if(e.hasOwnProperty("render")){return{close:oe(M.COMPONENT,o,e)}}const n=ie(e);return{close:oe(M.TITLE_DESCRIPTION,o,n)}},oe=(e,t,o)=>{const n=re(t,Z,12),s=ee++,i=document.createElement("div");let r;return document.body.appendChild(i),r=e===M.VNODE?d(Y,ne(t,s,n,le),(()=>[o])):e===M.TITLE_DESCRIPTION?d(Y,ne(t,s,n,le,o)):d(Y,ne(t,s,n,le),(()=>[d(o)])),x(r,i),Z[t.position].push({toastVNode:r,container:i}),r.component&&(r.component.props.visible=!0),()=>le(s,t.position)},ne=(e,t,o,n,s)=>a(l(l({},e),s),{id:t,offset:o,visible:!1,onCloseHandler:()=>{n(t,e.position?e.position:"top-right")}}),se=e=>{const t=a(l({},e),{type:e.type||C.type,timeout:e.timeout||C.timeout,showCloseButton:e.showCloseButton,position:e.position||C.position,showIcon:e.showIcon,swipeClose:e.swipeClose,transition:e.transition||C.transition});return t.hideProgressBar=void 0!==t.timeout&&t.timeout<=0,void 0!==e.hideProgressBar&&(t.hideProgressBar=e.hideProgressBar),t},ie=e=>({text:"string"==typeof e?e:e.title,description:"string"==typeof e?void 0:e.description}),re=(e,t,o)=>{let n=o;if(!e.position)throw new Error("no position");return t[e.position].forEach((({toastVNode:e})=>{const t=e.el.offsetHeight+o;n+=t||0})),n},le=(e,t)=>{const o=Z[t],n=o.findIndex((({toastVNode:t})=>t.props&&e===t.props.id));if(-1===n)return;const{container:s,toastVNode:i}=o[n];if(!i.el)return;const r=i.el.offsetHeight;Z[t].splice(n,1),((e,t,o,n)=>{for(let s=e;s<t.length;s++){const{toastVNode:e}=t[s];if(!e.el)return;const i=o.split("-")[0]||"top",r=parseInt(e.el.style[i],10)-n-12;if(!e.component)return;e.component.props.offset=r}})(n,o,t,r),i.component&&(i.component.props.visible=!1,i.component.props.onClose&&i.component.props.onClose(),setTimeout((()=>{x(null,s),document.body.removeChild(s)}),1e3))},ae=()=>{Object.entries(Z).forEach((([e,t])=>{if(t.length>0){t.map((e=>e.toastVNode.props.id)).forEach((t=>{le(t,e)}))}}))};var ue={install:e=>{e.config.globalProperties.$moshaToast=te,e.provide("moshaToast",te)}};export default ue;export{M as ToastContentType,ae as clearToasts,te as createToast,S as withProps}; |
@@ -1,1 +0,1 @@ | ||
var __defProp=Object.defineProperty,__hasOwnProp=Object.prototype.hasOwnProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,o)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,__assign=(e,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(e,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(e,o,t[o]);return e};!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["mosha-vue-toastify"]={},e.Vue)}(this,(function(e,t){"use strict";const o={type:"default",timeout:5e3,showCloseButton:!0,position:"top-right",transition:"bounce",hideProgressBar:!1,swipeClose:!0};var n;e.ToastContentType=void 0,(n=e.ToastContentType||(e.ToastContentType={}))[n.TITLE_ONLY=0]="TITLE_ONLY",n[n.TITLE_DESCRIPTION=1]="TITLE_DESCRIPTION",n[n.COMPONENT=2]="COMPONENT",n[n.VNODE=3]="VNODE";const s={"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"}},r=(e,t=300)=>{let o;return(...n)=>{o&&(clearTimeout(o),o=void 0),o=setTimeout((()=>e(...n)),t)}},i=(e,o,n)=>{const s=t.ref(),r=t.ref(void 0),i=t.ref(),a=e=>e instanceof MouseEvent,l=t=>{!1!==n&&s.value&&(a(t)?r.value=s.value.clientX-t.clientX:r.value=s.value.touches[0].clientX-t.touches[0].clientX,i.value=__assign(__assign({},i.value),{transition:"none"}),e.endsWith("left")?i.value.left=-r.value+"px !important":e.endsWith("right")?i.value.right=`${r.value}px !important`:r.value>0?i.value.left=-r.value+"px !important":i.value.right=`${r.value}px !important`,Math.abs(r.value)>200&&o())},p=e=>{!1!==n&&(s.value&&(s.value=void 0),r.value&&(r.value=void 0),removeEventListener(e,l))};return t.onUnmounted((()=>{!1!==n&&(p("mousemove"),p("touchmove"))})),{swipedDiff:r,swipeStart:s,swipeStyle:i,swipeHandler:l,startSwipeHandler:t=>{if(!1===n)return;s.value=t;const o=a(t)?"mousemove":"touchmove",p=a(t)?"mouseup":"touchend";addEventListener(o,l),addEventListener(p,(()=>(t=>{const o={transition:"left .3s ease-out",left:0},n={transition:"right .3s ease-out",right:0},a={transition:"all .3s ease-out",left:0,right:0};e.endsWith("left")?i.value=__assign(__assign({},i.value),o):e.endsWith("right")?i.value=__assign(__assign({},i.value),n):i.value=__assign(__assign({},i.value),a),s.value=void 0,r.value=void 0,removeEventListener(t,l)})(o)))},cleanUpMove:p}};var a=t.defineComponent({props:{type:{type:String,default:"default"}}});const l={class:"mosha__icon"},p={key:0,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},c=t.createVNode("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),u={key:1,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},d=t.createVNode("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),m={key:2,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},h=t.createVNode("path",{d:"M0 0h24v24H0V0z",fill:"none"},null,-1),f=t.createVNode("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),v={key:3,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#616161"},_=t.createVNode("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),g=t.createVNode("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),w={key:4,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},y=t.createVNode("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),T=t.createVNode("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);a.render=function(e,o,n,s,r,i){return t.openBlock(),t.createBlock("span",l,["warning"===e.type?(t.openBlock(),t.createBlock("svg",p,[c])):"danger"===e.type?(t.openBlock(),t.createBlock("svg",u,[d])):"success"===e.type?(t.openBlock(),t.createBlock("svg",m,[h,f])):"default"===e.type?(t.openBlock(),t.createBlock("svg",v,[_,g])):(t.openBlock(),t.createBlock("svg",w,[y,T]))])};var b=t.defineComponent({name:"MToast",components:{MIcon:a},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(e,o){const n=t.ref(),{width:a}=(()=>{const e=t.ref(-1),o=t.ref(-1),n=t=>{null!==t&&null!==t.currentTarget&&(e.value=t.currentTarget.innerWidth,o.value=t.currentTarget.innerHeight)};return t.onMounted((()=>{window.innerWidth>0&&(e.value=window.innerWidth,o.value=window.innerHeight),window.addEventListener("resize",r(n))})),t.onUnmounted((()=>{window.removeEventListener("resize",r(n))})),{width:e,height:o}})(),{swipedDiff:l,startSwipeHandler:p,swipeStyle:c,cleanUpMove:u}=i(e.position,e.onCloseHandler,e.swipeClose),{transitionType:d}=(m=e.position,h=e.transition,f=l,{transitionType:t.computed((()=>f.value>200?"mosha__fadeOutLeft":f.value<-200?"mosha__fadeOutRight":s[m][h]))});var m,h,f;const{start:v,stop:_,progress:g}=((e,o)=>{const n=t.ref(),s=t.ref(0),r=t.ref(o),i=t.ref(),a=t.ref(100),l=()=>{clearInterval(i.value),clearTimeout(n.value)};return t.onMounted((()=>{})),t.onUnmounted((()=>{l()})),{start:()=>{s.value=Date.now(),clearTimeout(n.value),i.value=setInterval((()=>{a.value--}),o/100-5),n.value=setTimeout(e,r.value)},stop:()=>{clearInterval(i.value),clearTimeout(n.value),r.value-=Date.now()-s.value},clear:l,progress:a}})((()=>{e.onCloseHandler()}),e.timeout),w=t.computed((()=>o.slots.default)),y=t.computed((()=>/<\/?[a-z][\s\S]*>/i.test(e.description))),T=()=>{e.timeout>0&&v()};return t.watchEffect((()=>{const{customStyle:o}=((e,o,n)=>{const s=t.computed((()=>{switch(e){case"top-left":return{left:"0",top:`${o}px`};case"bottom-left":return{left:"0",bottom:`${o}px`};case"bottom-right":return{right:"0",bottom:`${o}px`};case"top-center":return{top:`${o}px`,left:"0",right:"0",marginRight:"auto",marginLeft:"auto"};case"bottom-center":return{bottom:`${o}px`,left:"0",right:"0",marginRight:"auto",marginLeft:"auto"};default:return{right:"0",top:`${o}px`}}}));return n.length>0&&(s.value.backgroundColor=n),{customStyle:s}})(e.position,e.offset,e.toastBackgroundColor);n.value=o.value})),t.onMounted((()=>{T()})),{style:n,transitionType:d,startTimer:T,progress:g,onTouchStart:e=>{p(e)},onMouseLeave:()=>{u("mousemove"),T()},onMouseDown:e=>{p(e)},swipeStyle:c,isSlotPassed:w,isDescriptionHtml:y,onMouseEnter:()=>{e.timeout>0&&a.value>425&&_()}}}});const C={class:"mosha__toast__content-wrapper"},B={class:"mosha__toast__content"},N={class:"mosha__toast__content__text"},I={key:1,class:"mosha__toast__content__description"},k={key:0,class:"mosha__toast__slot-wrapper"};b.render=function(e,o,n,s,r,i){const a=t.resolveComponent("MIcon");return t.openBlock(),t.createBlock(t.Transition,{name:e.transitionType,type:"animation"},{default:t.withCtx((()=>[e.visible?(t.openBlock(),t.createBlock("div",{key:0,class:["mosha__toast",e.toastBackgroundColor?null:e.type],style:[e.style,e.swipeStyle],onMouseenter:o[2]||(o[2]=(...t)=>e.onMouseEnter&&e.onMouseEnter(...t)),onMouseleave:o[3]||(o[3]=(...t)=>e.onMouseLeave&&e.onMouseLeave(...t)),onTouchstartPassive:o[4]||(o[4]=(...t)=>e.onTouchStart&&e.onTouchStart(...t)),onMousedown:o[5]||(o[5]=(...t)=>e.onMouseDown&&e.onMouseDown(...t))},[t.createVNode("div",C,[e.showIcon?(t.openBlock(),t.createBlock(a,{key:0,type:e.type},null,8,["type"])):t.createCommentVNode("",!0),t.createVNode("div",B,[t.createVNode("div",N,t.toDisplayString(e.text),1),e.description.length>0&&e.isDescriptionHtml?(t.openBlock(),t.createBlock("div",{key:0,class:"mosha__toast__content__description",innerHTML:e.description},null,8,["innerHTML"])):t.createCommentVNode("",!0),e.description.length>0&&!e.isDescriptionHtml?(t.openBlock(),t.createBlock("div",I,t.toDisplayString(e.description),1)):t.createCommentVNode("",!0)])]),e.isSlotPassed?(t.openBlock(),t.createBlock("div",k,[t.renderSlot(e.$slots,"default")])):t.createCommentVNode("",!0),e.showCloseButton?(t.openBlock(),t.createBlock("div",{key:1,class:"mosha__toast__close-icon",onClick:o[1]||(o[1]=(...t)=>e.onCloseHandler&&e.onCloseHandler(...t))})):t.createCommentVNode("",!0),e.hideProgressBar?t.createCommentVNode("",!0):(t.openBlock(),t.createBlock("div",{key:2,class:"mosha__toast__progress",style:{width:`${e.progress}%`}},null,4))],38)):t.createCommentVNode("",!0)])),_:3},8,["name"])};const x={"top-left":[],"top-right":[],"bottom-left":[],"bottom-right":[],"top-center":[],"bottom-center":[]};let M=0;const S=(t,n)=>{const s=n?P(n):o;if(t.__v_isVNode){return{close:V(e.ToastContentType.VNODE,s,t)}}if(t.hasOwnProperty("render")){return{close:V(e.ToastContentType.COMPONENT,s,t)}}const r=z(t);return{close:V(e.ToastContentType.TITLE_DESCRIPTION,s,r)}},V=(o,n,s)=>{const r=O(n,x,12),i=M++,a=document.createElement("div");let l;return document.body.appendChild(a),l=o===e.ToastContentType.VNODE?t.createVNode(b,E(n,i,r,L),(()=>[s])):o===e.ToastContentType.TITLE_DESCRIPTION?t.createVNode(b,E(n,i,r,L,s)):t.createVNode(b,E(n,i,r,L),(()=>[t.createVNode(s)])),t.render(l,a),x[n.position].push({toastVNode:l,container:a}),l.component&&(l.component.props.visible=!0),()=>L(i,n.position)},E=(e,t,o,n,s)=>__assign(__assign(__assign({},e),s),{id:t,offset:o,visible:!1,onCloseHandler:()=>{n(t,e.position?e.position:"top-right")}}),P=e=>{const t=__assign(__assign({},e),{type:e.type||o.type,timeout:e.timeout||o.timeout,showCloseButton:e.showCloseButton,position:e.position||o.position,showIcon:e.showIcon,swipeClose:e.swipeClose,transition:e.transition||o.transition});return t.hideProgressBar=void 0!==t.timeout&&t.timeout<=0,void 0!==e.hideProgressBar&&(t.hideProgressBar=e.hideProgressBar),t},z=e=>({text:"string"==typeof e?e:e.title,description:"string"==typeof e?void 0:e.description}),O=(e,t,o)=>{let n=o;if(!e.position)throw new Error("no position");return t[e.position].forEach((({toastVNode:e})=>{const t=e.el.offsetHeight+o;n+=t||0})),n},L=(e,o)=>{const n=x[o],s=n.findIndex((({toastVNode:t})=>t.props&&e===t.props.id));if(-1===s)return;const{container:r,toastVNode:i}=n[s];if(!i.el)return;const a=i.el.offsetHeight;x[o].splice(s,1),((e,t,o,n)=>{for(let s=e;s<t.length;s++){const{toastVNode:e}=t[s];if(!e.el)return;const r=o.split("-")[0]||"top",i=parseInt(e.el.style[r],10)-n-12;if(!e.component)return;e.component.props.offset=i}})(s,n,o,a),i.component&&(i.component.props.visible=!1,i.component.props.onClose&&i.component.props.onClose(),setTimeout((()=>{t.render(null,r),document.body.removeChild(r)}),1e3))};var D={install:e=>{e.config.globalProperties.$moshaToast=S,e.provide("moshaToast",S)}};e.clearToasts=()=>{Object.entries(x).forEach((([e,t])=>{if(t.length>0){t.map((e=>e.toastVNode.props.id)).forEach((t=>{L(t,e)}))}}))},e.createToast=S,e.default=D,e.withProps=(e,o)=>t.createVNode(e,o),Object.defineProperty(e,"__esModule",{value:!0}),e[Symbol.toStringTag]="Module"})); | ||
var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,o)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,__spreadValues=(e,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(e,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(e,o,t[o]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["mosha-vue-toastify"]={},e.Vue)}(this,(function(e,t){"use strict";const o={type:"default",timeout:5e3,showCloseButton:!0,position:"top-right",transition:"bounce",hideProgressBar:!1,swipeClose:!0};var n;e.ToastContentType=void 0,(n=e.ToastContentType||(e.ToastContentType={}))[n.TITLE_ONLY=0]="TITLE_ONLY",n[n.TITLE_DESCRIPTION=1]="TITLE_DESCRIPTION",n[n.COMPONENT=2]="COMPONENT",n[n.VNODE=3]="VNODE";const s={"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"}},r=(e,t=300)=>{let o;return(...n)=>{o&&(clearTimeout(o),o=void 0),o=setTimeout((()=>e(...n)),t)}},a=(e,o,n)=>{const s=t.ref(),r=t.ref(void 0),a=t.ref(),i=e=>e instanceof MouseEvent,l=t=>{!1!==n&&s.value&&(i(t)?r.value=s.value.clientX-t.clientX:r.value=s.value.touches[0].clientX-t.touches[0].clientX,a.value=__spreadProps(__spreadValues({},a.value),{transition:"none"}),e.endsWith("left")?a.value.left=-r.value+"px !important":e.endsWith("right")?a.value.right=`${r.value}px !important`:r.value>0?a.value.left=-r.value+"px !important":a.value.right=`${r.value}px !important`,Math.abs(r.value)>200&&o())},p=e=>{!1!==n&&(s.value&&(s.value=void 0),r.value&&(r.value=void 0),removeEventListener(e,l))};return t.onUnmounted((()=>{!1!==n&&(p("mousemove"),p("touchmove"))})),{swipedDiff:r,swipeStart:s,swipeStyle:a,swipeHandler:l,startSwipeHandler:t=>{if(!1===n)return;s.value=t;const o=i(t)?"mousemove":"touchmove",p=i(t)?"mouseup":"touchend";addEventListener(o,l),addEventListener(p,(()=>(t=>{const o={transition:"left .3s ease-out",left:0},n={transition:"right .3s ease-out",right:0},i={transition:"all .3s ease-out",left:0,right:0};e.endsWith("left")?a.value=__spreadValues(__spreadValues({},a.value),o):e.endsWith("right")?a.value=__spreadValues(__spreadValues({},a.value),n):a.value=__spreadValues(__spreadValues({},a.value),i),s.value=void 0,r.value=void 0,removeEventListener(t,l)})(o)))},cleanUpMove:p}};var i=t.defineComponent({props:{type:{type:String,default:"default"}}});const l={class:"mosha__icon"},p={key:0,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},c=t.createVNode("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),u={key:1,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},d=t.createVNode("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),m={key:2,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},h=t.createVNode("path",{d:"M0 0h24v24H0V0z",fill:"none"},null,-1),f=t.createVNode("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),_={key:3,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#616161"},v=t.createVNode("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),g=t.createVNode("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),w={key:4,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},y=t.createVNode("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),T=t.createVNode("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);i.render=function(e,o,n,s,r,a){return t.openBlock(),t.createBlock("span",l,["warning"===e.type?(t.openBlock(),t.createBlock("svg",p,[c])):"danger"===e.type?(t.openBlock(),t.createBlock("svg",u,[d])):"success"===e.type?(t.openBlock(),t.createBlock("svg",m,[h,f])):"default"===e.type?(t.openBlock(),t.createBlock("svg",_,[v,g])):(t.openBlock(),t.createBlock("svg",w,[y,T]))])};var b=t.defineComponent({name:"MToast",components:{MIcon:i},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(e,o){const n=t.ref(),{width:i}=(()=>{const e=t.ref(-1),o=t.ref(-1),n=t=>{null!==t&&null!==t.currentTarget&&(e.value=t.currentTarget.innerWidth,o.value=t.currentTarget.innerHeight)};return t.onMounted((()=>{window.innerWidth>0&&(e.value=window.innerWidth,o.value=window.innerHeight),window.addEventListener("resize",r(n))})),t.onUnmounted((()=>{window.removeEventListener("resize",r(n))})),{width:e,height:o}})(),{swipedDiff:l,startSwipeHandler:p,swipeStyle:c,cleanUpMove:u}=a(e.position,e.onCloseHandler,e.swipeClose),{transitionType:d}=(m=e.position,h=e.transition,f=l,{transitionType:t.computed((()=>f.value>200?"mosha__fadeOutLeft":f.value<-200?"mosha__fadeOutRight":s[m][h]))});var m,h,f;const{start:_,stop:v,progress:g}=((e,o)=>{const n=t.ref(),s=t.ref(0),r=t.ref(o),a=t.ref(),i=t.ref(100),l=()=>{clearInterval(a.value),clearTimeout(n.value)};return t.onMounted((()=>{})),t.onUnmounted((()=>{l()})),{start:()=>{s.value=Date.now(),clearTimeout(n.value),a.value=setInterval((()=>{i.value--}),o/100-5),n.value=setTimeout(e,r.value)},stop:()=>{clearInterval(a.value),clearTimeout(n.value),r.value-=Date.now()-s.value},clear:l,progress:i}})((()=>{e.onCloseHandler()}),e.timeout),w=t.computed((()=>o.slots.default)),y=t.computed((()=>/<\/?[a-z][\s\S]*>/i.test(e.description))),T=()=>{e.timeout>0&&_()};return t.watchEffect((()=>{const{customStyle:o}=((e,o,n)=>{const s=t.computed((()=>{switch(e){case"top-left":return{left:"0",top:`${o}px`};case"bottom-left":return{left:"0",bottom:`${o}px`};case"bottom-right":return{right:"0",bottom:`${o}px`};case"top-center":return{top:`${o}px`,left:"0",right:"0",marginRight:"auto",marginLeft:"auto"};case"bottom-center":return{bottom:`${o}px`,left:"0",right:"0",marginRight:"auto",marginLeft:"auto"};default:return{right:"0",top:`${o}px`}}}));return n.length>0&&(s.value.backgroundColor=n),{customStyle:s}})(e.position,e.offset,e.toastBackgroundColor);n.value=o.value})),t.onMounted((()=>{T()})),{style:n,transitionType:d,startTimer:T,progress:g,onTouchStart:e=>{p(e)},onMouseLeave:()=>{u("mousemove"),T()},onMouseDown:e=>{p(e)},swipeStyle:c,isSlotPassed:w,isDescriptionHtml:y,onMouseEnter:()=>{e.timeout>0&&i.value>425&&v()}}}});const C={class:"mosha__toast__content-wrapper"},B={class:"mosha__toast__content"},N={class:"mosha__toast__content__text"},V={key:1,class:"mosha__toast__content__description"},I={key:0,class:"mosha__toast__slot-wrapper"};b.render=function(e,o,n,s,r,a){const i=t.resolveComponent("MIcon");return t.openBlock(),t.createBlock(t.Transition,{name:e.transitionType,type:"animation"},{default:t.withCtx((()=>[e.visible?(t.openBlock(),t.createBlock("div",{key:0,class:["mosha__toast",e.toastBackgroundColor?null:e.type],style:[e.style,e.swipeStyle],onMouseenter:o[2]||(o[2]=(...t)=>e.onMouseEnter&&e.onMouseEnter(...t)),onMouseleave:o[3]||(o[3]=(...t)=>e.onMouseLeave&&e.onMouseLeave(...t)),onTouchstartPassive:o[4]||(o[4]=(...t)=>e.onTouchStart&&e.onTouchStart(...t)),onMousedown:o[5]||(o[5]=(...t)=>e.onMouseDown&&e.onMouseDown(...t))},[t.createVNode("div",C,[e.showIcon?(t.openBlock(),t.createBlock(i,{key:0,type:e.type},null,8,["type"])):t.createCommentVNode("",!0),t.createVNode("div",B,[t.createVNode("div",N,t.toDisplayString(e.text),1),e.description.length>0&&e.isDescriptionHtml?(t.openBlock(),t.createBlock("div",{key:0,class:"mosha__toast__content__description",innerHTML:e.description},null,8,["innerHTML"])):t.createCommentVNode("",!0),e.description.length>0&&!e.isDescriptionHtml?(t.openBlock(),t.createBlock("div",V,t.toDisplayString(e.description),1)):t.createCommentVNode("",!0)])]),e.isSlotPassed?(t.openBlock(),t.createBlock("div",I,[t.renderSlot(e.$slots,"default")])):t.createCommentVNode("",!0),e.showCloseButton?(t.openBlock(),t.createBlock("div",{key:1,class:"mosha__toast__close-icon",onClick:o[1]||(o[1]=(...t)=>e.onCloseHandler&&e.onCloseHandler(...t))})):t.createCommentVNode("",!0),e.hideProgressBar?t.createCommentVNode("",!0):(t.openBlock(),t.createBlock("div",{key:2,class:"mosha__toast__progress",style:{width:`${e.progress}%`}},null,4))],38)):t.createCommentVNode("",!0)])),_:3},8,["name"])};const k={"top-left":[],"top-right":[],"bottom-left":[],"bottom-right":[],"top-center":[],"bottom-center":[]};let P=0;const x=(t,n)=>{const s=n?O(n):o;if(t.__v_isVNode){return{close:M(e.ToastContentType.VNODE,s,t)}}if(t.hasOwnProperty("render")){return{close:M(e.ToastContentType.COMPONENT,s,t)}}const r=E(t);return{close:M(e.ToastContentType.TITLE_DESCRIPTION,s,r)}},M=(o,n,s)=>{const r=z(n,k,12),a=P++,i=document.createElement("div");let l;return document.body.appendChild(i),l=o===e.ToastContentType.VNODE?t.createVNode(b,S(n,a,r,L),(()=>[s])):o===e.ToastContentType.TITLE_DESCRIPTION?t.createVNode(b,S(n,a,r,L,s)):t.createVNode(b,S(n,a,r,L),(()=>[t.createVNode(s)])),t.render(l,i),k[n.position].push({toastVNode:l,container:i}),l.component&&(l.component.props.visible=!0),()=>L(a,n.position)},S=(e,t,o,n,s)=>__spreadProps(__spreadValues(__spreadValues({},e),s),{id:t,offset:o,visible:!1,onCloseHandler:()=>{n(t,e.position?e.position:"top-right")}}),O=e=>{const t=__spreadProps(__spreadValues({},e),{type:e.type||o.type,timeout:e.timeout||o.timeout,showCloseButton:e.showCloseButton,position:e.position||o.position,showIcon:e.showIcon,swipeClose:e.swipeClose,transition:e.transition||o.transition});return t.hideProgressBar=void 0!==t.timeout&&t.timeout<=0,void 0!==e.hideProgressBar&&(t.hideProgressBar=e.hideProgressBar),t},E=e=>({text:"string"==typeof e?e:e.title,description:"string"==typeof e?void 0:e.description}),z=(e,t,o)=>{let n=o;if(!e.position)throw new Error("no position");return t[e.position].forEach((({toastVNode:e})=>{const t=e.el.offsetHeight+o;n+=t||0})),n},L=(e,o)=>{const n=k[o],s=n.findIndex((({toastVNode:t})=>t.props&&e===t.props.id));if(-1===s)return;const{container:r,toastVNode:a}=n[s];if(!a.el)return;const i=a.el.offsetHeight;k[o].splice(s,1),((e,t,o,n)=>{for(let s=e;s<t.length;s++){const{toastVNode:e}=t[s];if(!e.el)return;const r=o.split("-")[0]||"top",a=parseInt(e.el.style[r],10)-n-12;if(!e.component)return;e.component.props.offset=a}})(s,n,o,i),a.component&&(a.component.props.visible=!1,a.component.props.onClose&&a.component.props.onClose(),setTimeout((()=>{t.render(null,r),document.body.removeChild(r)}),1e3))};var D={install:e=>{e.config.globalProperties.$moshaToast=x,e.provide("moshaToast",x)}};e.clearToasts=()=>{Object.entries(k).forEach((([e,t])=>{if(t.length>0){t.map((e=>e.toastVNode.props.id)).forEach((t=>{L(t,e)}))}}))},e.createToast=x,e.default=D,e.withProps=(e,o)=>t.createVNode(e,o),Object.defineProperty(e,"__esModule",{value:!0}),e[Symbol.toStringTag]="Module"})); |
{ | ||
"name": "mosha-vue-toastify", | ||
"version": "1.0.21", | ||
"version": "1.0.22", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A light weight and fun Vue 3 toast or notification or snack bar or however you wanna call it library.", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52807
223
1