mosha-vue-toastify
Advanced tools
Comparing version 1.0.11 to 1.0.12
import { ComputedRef, CSSProperties } from 'vue'; | ||
import { Position } from '../types'; | ||
declare const useCustomStyle: (position: Position, offset: string, bgColor: string) => { | ||
declare const useCustomStyle: (position: Position, offset: number, bgColor: string) => { | ||
customStyle: ComputedRef<CSSProperties>; | ||
}; | ||
export default useCustomStyle; |
import { App } from '@vue/runtime-core'; | ||
import './index.scss'; | ||
export * from './components/createToast'; | ||
export { createToast } from './createToast'; | ||
export * from './types'; | ||
declare const _default: { | ||
@@ -5,0 +6,0 @@ install: (app: App) => void; |
@@ -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 a in i||(i={}))t.call(i,a)&&s(e,a,i[a]);if(o)for(var a of o(i))n.call(i,a)&&s(e,a,i[a]);return e};import{ref as a,onMounted as l,onUnmounted as r,computed as u,defineComponent as p,openBlock as c,createBlock as h,createVNode as v,watchEffect as m,resolveComponent as d,Transition as f,withCtx as g,createCommentVNode as _,toDisplayString as w,render as y}from"vue";const b={type:"default",timeout:5e3,showCloseButton:!0,position:"top-right",transition:"bounce",hideProgressBar:!1,swipeClose:!0},x={"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"}},I=(e,t,o)=>{const n=a(),s=a(void 0),l=a(),u=e=>e instanceof MouseEvent,p=a=>{!1!==o&&n.value&&(u(a)?s.value=n.value.clientX-a.clientX:s.value=n.value.touches[0].clientX-a.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 r((()=>{!1!==o&&(c("mousemove"),c("touchmove"))})),{swipedDiff:s,swipeStart:n,swipeStyle:l,swipeHandler:p,startSwipeHandler:t=>{if(!1===o)return;n.value=t;const a=u(t)?"mousemove":"touchmove",r=u(t)?"mouseup":"touchend";addEventListener(a,p),addEventListener(r,(()=>(t=>{const o={transition:"left .3s ease-out",left:0},a={transition:"right .3s ease-out",right:0};e.endsWith("left")?l.value=i(i({},l.value),o):e.endsWith("right")?l.value=i(i({},l.value),a):s.value>0?l.value=i(i({},l.value),o):s.value&&s.value<0&&(l.value=i(i({},l.value),a)),n.value=void 0,s.value=void 0,removeEventListener(t,p)})(a)))},cleanUpMove:c}};var z=p({props:{type:{type:String,default:"default"}}});const C={class:"mosha__icon"},M={key:0,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},B=v("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),S={key:1,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},T=v("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),L={key:2,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},k=v("path",{d:"M0 0h24v24H0V0z",fill:"none"},null,-1),H=v("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),P={key:3,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#616161"},$=v("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),D=v("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),E={key:4,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},V=v("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),N=v("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);z.render=function(e,t,o,n,s,i){return c(),h("span",C,["warning"===e.type?(c(),h("svg",M,[B])):"danger"===e.type?(c(),h("svg",S,[T])):"success"===e.type?(c(),h("svg",L,[k,H])):"default"===e.type?(c(),h("svg",P,[$,D])):(c(),h("svg",E,[V,N]))])};var O=p({name:"MToast",components:{MIcon:z},props:{visible:Boolean,text:{type:String,default:""},description:{type:String,default:""},toastBackgroundColor:{type:String,default:""},type:{type:String,default:"default"},onCloseHandler:{type:Function,required:!0},offset:Number,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){const t=a(),{swipedDiff:o,startSwipeHandler:n,swipeStyle:s,cleanUpMove:i}=I(e.position,e.onCloseHandler,e.swipeClose),{transitionType:p}=(c=e.position,h=e.transition,v=o,{transitionType:u((()=>v.value>200?"mosha__fadeOutLeft":v.value<-200?"mosha__fadeOutRight":x[c][h]))});var c,h,v;const{start:d,stop:f,progress:g}=((e,t)=>{const o=a(),n=a(0),s=a(t),i=a(),u=a(100),p=()=>{clearInterval(i.value),clearTimeout(o.value)};return l((()=>{})),r((()=>{p()})),{start:()=>{n.value=Date.now(),clearTimeout(o.value),i.value=setInterval((()=>{u.value--}),t/100-2),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),_=()=>{e.timeout>0&&d()};return m((()=>{const{customStyle:o}=((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);t.value=o.value})),l((()=>{_()})),{style:t,transitionType:p,startTimer:_,stopTimer:()=>{e.timeout>0&&f()},progress:g,onTouchStart:e=>{n(e)},onMouseLeave:()=>{i("mousemove"),_()},onMouseDown:e=>{n(e)},swipeStyle:s}}});const R={class:"mosha__toast__content-wrapper"},j={class:"mosha__toast__content"},U={class:"mosha__toast__content__text"},W={key:0,class:"mosha__toast__content__description"};O.render=function(e,t,o,n,s,i){const a=d("MIcon");return c(),h(f,{name:e.transitionType,type:"animation"},{default:g((()=>[e.visible?(c(),h("div",{key:0,class:["mosha__toast",e.toastBackgroundColor?null:e.type],style:[e.style,e.swipeStyle],onMouseenter:t[2]||(t[2]=(...t)=>e.stopTimer&&e.stopTimer(...t)),onMouseleave:t[3]||(t[3]=(...t)=>e.onMouseLeave&&e.onMouseLeave(...t)),onTouchstart:t[4]||(t[4]=(...t)=>e.onTouchStart&&e.onTouchStart(...t)),onMousedown:t[5]||(t[5]=(...t)=>e.onMouseDown&&e.onMouseDown(...t))},[v("div",R,[e.showIcon?(c(),h(a,{key:0,type:e.type},null,8,["type"])):_("",!0),v("div",j,[v("div",U,w(e.text),1),e.description.length>0?(c(),h("div",W,w(e.description),1)):_("",!0)])]),e.showCloseButton?(c(),h("div",{key:0,class:"mosha__toast__close-icon",onClick:t[1]||(t[1]=(...t)=>e.onCloseHandler&&e.onCloseHandler(...t))})):_("",!0),e.hideProgressBar?_("",!0):(c(),h("div",{key:1,class:"mosha__toast__progress",style:{width:`${e.progress}%`}},null,4))],38)):_("",!0)])),_:1},8,["name"])};const X={"top-left":[],"top-right":[],"bottom-left":[],"bottom-right":[],"top-center":[],"bottom-center":[]};let q=0;const F=e=>{const t=i(i({},e),{type:e.type||b.type,timeout:e.timeout||b.timeout,showCloseButton:e.showCloseButton,position:e.position||b.position,showIcon:e.showIcon,swipeClose:e.swipeClose,transition:e.transition||b.transition});return t.hideProgressBar=void 0!==t.timeout&&t.timeout<=0,void 0!==e.hideProgressBar&&(t.hideProgressBar=e.hideProgressBar),t},A=e=>({text:"string"==typeof e?e:e.title,description:"string"==typeof e?void 0:e.description}),G=e=>{let t=12;if(!e.position)throw new Error("no position");return X[e.position].forEach((({toastVNode:e})=>{const o=e.el.offsetHeight+12;t+=o||0})),t},J=(e,t,o,n)=>i(i(i({},e),t),{id:o,offset:n,visible:!1,onCloseHandler:()=>{Y(o,e.position?e.position:"top-right")}}),K=(e,t)=>{const o=G(e),n=q++,s=document.createElement("div");document.body.appendChild(s);const i=v(O,J(e,t,n,o));y(i,s),e.position&&(X[e.position].push({toastVNode:i,container:s}),i.component&&(i.component.props.visible=!0))},Q=(e,t)=>{if(!e)return;const o=A(e),n=t?F(t):b;K(n,o)},Y=(e,t)=>{const o=X[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 a=i.el.offsetHeight;X[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",a=parseInt(e.el.style[i],10)-n-12;if(!e.component)return;e.component.props.offset=a}})(n,o,t,a),i.component&&(i.component.props.visible=!1,i.component.props.onClose&&i.component.props.onClose(),setTimeout((()=>{y(null,s),document.body.removeChild(s)}),1e3))};var Z={install:e=>{e.config.globalProperties.$moshaToast=Q,e.provide("moshaToast",Q)}};export default Z;export{Q as createToast,A as initializeContent,F as initializeOptions,G as moveToastsOnAdd,K as setupVNode,J as setupVNodeProps}; | ||
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 a,onUnmounted as l,computed as u,defineComponent as p,openBlock as c,createBlock as h,createVNode as d,watchEffect as m,resolveComponent as v,Transition as f,withCtx as g,createCommentVNode as w,toDisplayString as _,renderSlot as y,render as b}from"vue";const x={type:"default",timeout:5e3,showCloseButton:!0,position:"top-right",transition:"bounce",hideProgressBar:!1,swipeClose:!0},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"}},I=(e,t,o)=>{const n=r(),s=r(void 0),a=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,a.value=i(i({},a.value),{transition:"none"}),e.endsWith("left")?a.value.left=-s.value+"px !important":e.endsWith("right")?a.value.right=`${s.value}px !important`:s.value>0?a.value.left=-s.value+"px !important":a.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 l((()=>{!1!==o&&(c("mousemove"),c("touchmove"))})),{swipedDiff:s,swipeStart:n,swipeStyle:a,swipeHandler:p,startSwipeHandler:t=>{if(!1===o)return;n.value=t;const r=u(t)?"mousemove":"touchmove",l=u(t)?"mouseup":"touchend";addEventListener(r,p),addEventListener(l,(()=>(t=>{const o={transition:"left .3s ease-out",left:0},r={transition:"right .3s ease-out",right:0},l={transition:"all .3s ease-out",left:0,right:0};e.endsWith("left")?a.value=i(i({},a.value),o):e.endsWith("right")?a.value=i(i({},a.value),r):a.value=i(i({},a.value),l),n.value=void 0,s.value=void 0,removeEventListener(t,p)})(r)))},cleanUpMove:c}};var z=p({props:{type:{type:String,default:"default"}}});const M={class:"mosha__icon"},B={key:0,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},S=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),T={key:1,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},L=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),k={key:2,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},H=d("path",{d:"M0 0h24v24H0V0z",fill:"none"},null,-1),P=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),$={key:3,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#616161"},O=d("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),D=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),E={key:4,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},V=d("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),N=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);z.render=function(e,t,o,n,s,i){return c(),h("span",M,["warning"===e.type?(c(),h("svg",B,[S])):"danger"===e.type?(c(),h("svg",T,[L])):"success"===e.type?(c(),h("svg",k,[H,P])):"default"===e.type?(c(),h("svg",$,[O,D])):(c(),h("svg",E,[V,N]))])};var R=p({name:"MToast",components:{MIcon:z},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){const t=r(),{swipedDiff:o,startSwipeHandler:n,swipeStyle:s,cleanUpMove:i}=I(e.position,e.onCloseHandler,e.swipeClose),{transitionType:p}=(c=e.position,h=e.transition,d=o,{transitionType:u((()=>d.value>200?"mosha__fadeOutLeft":d.value<-200?"mosha__fadeOutRight":C[c][h]))});var c,h,d;const{start:v,stop:f,progress:g}=((e,t)=>{const o=r(),n=r(0),s=r(t),i=r(),u=r(100),p=()=>{clearInterval(i.value),clearTimeout(o.value)};return a((()=>{})),l((()=>{p()})),{start:()=>{n.value=Date.now(),clearTimeout(o.value),i.value=setInterval((()=>{u.value--}),t/100-2),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),w=()=>{e.timeout>0&&v()};return m((()=>{const{customStyle:o}=((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);t.value=o.value})),a((()=>{w()})),{style:t,transitionType:p,startTimer:w,stopTimer:()=>{e.timeout>0&&f()},progress:g,onTouchStart:e=>{n(e)},onMouseLeave:()=>{i("mousemove"),w()},onMouseDown:e=>{n(e)},swipeStyle:s}}});const j={class:"mosha__toast__content-wrapper"},q={class:"mosha__toast__content"},U={class:"mosha__toast__content__text"},W={key:0,class:"mosha__toast__content__description"};R.render=function(e,t,o,n,s,i){const r=v("MIcon");return c(),h(f,{name:e.transitionType,type:"animation"},{default:g((()=>[e.visible?(c(),h("div",{key:0,class:["mosha__toast",e.toastBackgroundColor?null:e.type],style:[e.style,e.swipeStyle],onMouseenter:t[2]||(t[2]=(...t)=>e.stopTimer&&e.stopTimer(...t)),onMouseleave:t[3]||(t[3]=(...t)=>e.onMouseLeave&&e.onMouseLeave(...t)),onTouchstart:t[4]||(t[4]=(...t)=>e.onTouchStart&&e.onTouchStart(...t)),onMousedown:t[5]||(t[5]=(...t)=>e.onMouseDown&&e.onMouseDown(...t))},[d("div",j,[e.showIcon?(c(),h(r,{key:0,type:e.type},null,8,["type"])):w("",!0),d("div",q,[d("div",U,_(e.text),1),e.description.length>0?(c(),h("div",W,_(e.description),1)):w("",!0)]),y(e.$slots,"default")]),e.showCloseButton?(c(),h("div",{key:0,class:"mosha__toast__close-icon",onClick:t[1]||(t[1]=(...t)=>e.onCloseHandler&&e.onCloseHandler(...t))})):w("",!0),e.hideProgressBar?w("",!0):(c(),h("div",{key:1,class:"mosha__toast__progress",style:{width:`${e.progress}%`}},null,4))],38)):w("",!0)])),_:3},8,["name"])};const X={"top-left":[],"top-right":[],"bottom-left":[],"bottom-right":[],"top-center":[],"bottom-center":[]};let F=0;const A=(e,t)=>{if(!e)return;const o=t?K(t):x;if(e.hasOwnProperty("render"))return void G(o,e);const n=Q(e);G(o,n)},G=(e,t)=>{const o=Y(e,X,12),n=F++,s=document.createElement("div");let i;document.body.appendChild(s),i=t.hasOwnProperty("render")?d(R,J(e,n,o,Z),(()=>[d(t)])):d(R,J(e,n,o,Z,t)),b(i,s),e.position&&(X[e.position].push({toastVNode:i,container:s}),i.component&&(i.component.props.visible=!0))},J=(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")}}),K=e=>{const t=i(i({},e),{type:e.type||x.type,timeout:e.timeout||x.timeout,showCloseButton:e.showCloseButton,position:e.position||x.position,showIcon:e.showIcon,swipeClose:e.swipeClose,transition:e.transition||x.transition});return t.hideProgressBar=void 0!==t.timeout&&t.timeout<=0,void 0!==e.hideProgressBar&&(t.hideProgressBar=e.hideProgressBar),t},Q=e=>({text:"string"==typeof e?e:e.title,description:"string"==typeof e?void 0:e.description}),Y=(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},Z=(e,t)=>{const o=X[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;X[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))};var ee={install:e=>{e.config.globalProperties.$moshaToast=A,e.provide("moshaToast",A)}};export default ee;export{A as createToast}; |
@@ -1,1 +0,1 @@ | ||
var __defProp=Object.defineProperty,__hasOwnProp=Object.prototype.hasOwnProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,o,t)=>o in e?__defProp(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,__assign=(e,o)=>{for(var t in o||(o={}))__hasOwnProp.call(o,t)&&__defNormalProp(e,t,o[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(o))__propIsEnum.call(o,t)&&__defNormalProp(e,t,o[t]);return e};!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self)["mosha-vue-toastify"]={},e.Vue)}(this,(function(e,o){"use strict";const t={type:"default",timeout:5e3,showCloseButton:!0,position:"top-right",transition:"bounce",hideProgressBar:!1,swipeClose:!0},n={"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,n)=>{const s=o.ref(),a=o.ref(void 0),i=o.ref(),r=e=>e instanceof MouseEvent,l=o=>{!1!==n&&s.value&&(r(o)?a.value=s.value.clientX-o.clientX:a.value=s.value.touches[0].clientX-o.touches[0].clientX,i.value=__assign(__assign({},i.value),{transition:"none"}),e.endsWith("left")?i.value.left=-a.value+"px !important":e.endsWith("right")?i.value.right=`${a.value}px !important`:a.value>0?i.value.left=-a.value+"px !important":i.value.right=`${a.value}px !important`,Math.abs(a.value)>200&&t())},p=e=>{!1!==n&&(s.value&&(s.value=void 0),a.value&&(a.value=void 0),removeEventListener(e,l))};return o.onUnmounted((()=>{!1!==n&&(p("mousemove"),p("touchmove"))})),{swipedDiff:a,swipeStart:s,swipeStyle:i,swipeHandler:l,startSwipeHandler:o=>{if(!1===n)return;s.value=o;const t=r(o)?"mousemove":"touchmove",p=r(o)?"mouseup":"touchend";addEventListener(t,l),addEventListener(p,(()=>(o=>{const t={transition:"left .3s ease-out",left:0},n={transition:"right .3s ease-out",right:0};e.endsWith("left")?i.value=__assign(__assign({},i.value),t):e.endsWith("right")?i.value=__assign(__assign({},i.value),n):a.value>0?i.value=__assign(__assign({},i.value),t):a.value&&a.value<0&&(i.value=__assign(__assign({},i.value),n)),s.value=void 0,a.value=void 0,removeEventListener(o,l)})(t)))},cleanUpMove:p}};var a=o.defineComponent({props:{type:{type:String,default:"default"}}});const i={class:"mosha__icon"},r={key:0,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},l=o.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),p={key:1,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},u=o.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),c={key:2,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},d=o.createVNode("path",{d:"M0 0h24v24H0V0z",fill:"none"},null,-1),m=o.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),h={key:3,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#616161"},f=o.createVNode("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),v=o.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),_={key:4,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},g=o.createVNode("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),w=o.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,t,n,s,a,y){return o.openBlock(),o.createBlock("span",i,["warning"===e.type?(o.openBlock(),o.createBlock("svg",r,[l])):"danger"===e.type?(o.openBlock(),o.createBlock("svg",p,[u])):"success"===e.type?(o.openBlock(),o.createBlock("svg",c,[d,m])):"default"===e.type?(o.openBlock(),o.createBlock("svg",h,[f,v])):(o.openBlock(),o.createBlock("svg",_,[g,w]))])};var y=o.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"},onCloseHandler:{type:Function,required:!0},offset:Number,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){const t=o.ref(),{swipedDiff:a,startSwipeHandler:i,swipeStyle:r,cleanUpMove:l}=s(e.position,e.onCloseHandler,e.swipeClose),{transitionType:p}=(u=e.position,c=e.transition,d=a,{transitionType:o.computed((()=>d.value>200?"mosha__fadeOutLeft":d.value<-200?"mosha__fadeOutRight":n[u][c]))});var u,c,d;const{start:m,stop:h,progress:f}=((e,t)=>{const n=o.ref(),s=o.ref(0),a=o.ref(t),i=o.ref(),r=o.ref(100),l=()=>{clearInterval(i.value),clearTimeout(n.value)};return o.onMounted((()=>{})),o.onUnmounted((()=>{l()})),{start:()=>{s.value=Date.now(),clearTimeout(n.value),i.value=setInterval((()=>{r.value--}),t/100-2),n.value=setTimeout(e,a.value)},stop:()=>{clearInterval(i.value),clearTimeout(n.value),a.value-=Date.now()-s.value},clear:l,progress:r}})((()=>{e.onCloseHandler()}),e.timeout),v=()=>{e.timeout>0&&m()};return o.watchEffect((()=>{const{customStyle:n}=((e,t,n)=>{const s=o.computed((()=>{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 n.length>0&&(s.value.backgroundColor=n),{customStyle:s}})(e.position,e.offset,e.toastBackgroundColor);t.value=n.value})),o.onMounted((()=>{v()})),{style:t,transitionType:p,startTimer:v,stopTimer:()=>{e.timeout>0&&h()},progress:f,onTouchStart:e=>{i(e)},onMouseLeave:()=>{l("mousemove"),v()},onMouseDown:e=>{i(e)},swipeStyle:r}}});const b={class:"mosha__toast__content-wrapper"},B={class:"mosha__toast__content"},k={class:"mosha__toast__content__text"},x={key:0,class:"mosha__toast__content__description"};y.render=function(e,t,n,s,a,i){const r=o.resolveComponent("MIcon");return o.openBlock(),o.createBlock(o.Transition,{name:e.transitionType,type:"animation"},{default:o.withCtx((()=>[e.visible?(o.openBlock(),o.createBlock("div",{key:0,class:["mosha__toast",e.toastBackgroundColor?null:e.type],style:[e.style,e.swipeStyle],onMouseenter:t[2]||(t[2]=(...o)=>e.stopTimer&&e.stopTimer(...o)),onMouseleave:t[3]||(t[3]=(...o)=>e.onMouseLeave&&e.onMouseLeave(...o)),onTouchstart:t[4]||(t[4]=(...o)=>e.onTouchStart&&e.onTouchStart(...o)),onMousedown:t[5]||(t[5]=(...o)=>e.onMouseDown&&e.onMouseDown(...o))},[o.createVNode("div",b,[e.showIcon?(o.openBlock(),o.createBlock(r,{key:0,type:e.type},null,8,["type"])):o.createCommentVNode("",!0),o.createVNode("div",B,[o.createVNode("div",k,o.toDisplayString(e.text),1),e.description.length>0?(o.openBlock(),o.createBlock("div",x,o.toDisplayString(e.description),1)):o.createCommentVNode("",!0)])]),e.showCloseButton?(o.openBlock(),o.createBlock("div",{key:0,class:"mosha__toast__close-icon",onClick:t[1]||(t[1]=(...o)=>e.onCloseHandler&&e.onCloseHandler(...o))})):o.createCommentVNode("",!0),e.hideProgressBar?o.createCommentVNode("",!0):(o.openBlock(),o.createBlock("div",{key:1,class:"mosha__toast__progress",style:{width:`${e.progress}%`}},null,4))],38)):o.createCommentVNode("",!0)])),_:1},8,["name"])};const C={"top-left":[],"top-right":[],"bottom-left":[],"bottom-right":[],"top-center":[],"bottom-center":[]};let I=0;const z=e=>{const o=__assign(__assign({},e),{type:e.type||t.type,timeout:e.timeout||t.timeout,showCloseButton:e.showCloseButton,position:e.position||t.position,showIcon:e.showIcon,swipeClose:e.swipeClose,transition:e.transition||t.transition});return o.hideProgressBar=void 0!==o.timeout&&o.timeout<=0,void 0!==e.hideProgressBar&&(o.hideProgressBar=e.hideProgressBar),o},S=e=>({text:"string"==typeof e?e:e.title,description:"string"==typeof e?void 0:e.description}),M=e=>{let o=12;if(!e.position)throw new Error("no position");return C[e.position].forEach((({toastVNode:e})=>{const t=e.el.offsetHeight+12;o+=t||0})),o},N=(e,o,t,n)=>__assign(__assign(__assign({},e),o),{id:t,offset:n,visible:!1,onCloseHandler:()=>{P(t,e.position?e.position:"top-right")}}),V=(e,t)=>{const n=M(e),s=I++,a=document.createElement("div");document.body.appendChild(a);const i=o.createVNode(y,N(e,t,s,n));o.render(i,a),e.position&&(C[e.position].push({toastVNode:i,container:a}),i.component&&(i.component.props.visible=!0))},T=(e,o)=>{if(!e)return;const n=S(e),s=o?z(o):t;V(s,n)},P=(e,t)=>{const n=C[t],s=n.findIndex((({toastVNode:o})=>o.props&&e===o.props.id));if(-1===s)return;const{container:a,toastVNode:i}=n[s];if(!i.el)return;const r=i.el.offsetHeight;C[t].splice(s,1),((e,o,t,n)=>{for(let s=e;s<o.length;s++){const{toastVNode:e}=o[s];if(!e.el)return;const a=t.split("-")[0]||"top",i=parseInt(e.el.style[a],10)-n-12;if(!e.component)return;e.component.props.offset=i}})(s,n,t,r),i.component&&(i.component.props.visible=!1,i.component.props.onClose&&i.component.props.onClose(),setTimeout((()=>{o.render(null,a),document.body.removeChild(a)}),1e3))};var L={install:e=>{e.config.globalProperties.$moshaToast=T,e.provide("moshaToast",T)}};e.createToast=T,e.default=L,e.initializeContent=S,e.initializeOptions=z,e.moveToastsOnAdd=M,e.setupVNode=V,e.setupVNodeProps=N,Object.defineProperty(e,"__esModule",{value:!0}),e[Symbol.toStringTag]="Module"})); | ||
var __defProp=Object.defineProperty,__hasOwnProp=Object.prototype.hasOwnProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,o,t)=>o in e?__defProp(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,__assign=(e,o)=>{for(var t in o||(o={}))__hasOwnProp.call(o,t)&&__defNormalProp(e,t,o[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(o))__propIsEnum.call(o,t)&&__defNormalProp(e,t,o[t]);return e};!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self)["mosha-vue-toastify"]={},e.Vue)}(this,(function(e,o){"use strict";const t={type:"default",timeout:5e3,showCloseButton:!0,position:"top-right",transition:"bounce",hideProgressBar:!1,swipeClose:!0},n={"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,n)=>{const s=o.ref(),r=o.ref(void 0),a=o.ref(),i=e=>e instanceof MouseEvent,l=o=>{!1!==n&&s.value&&(i(o)?r.value=s.value.clientX-o.clientX:r.value=s.value.touches[0].clientX-o.touches[0].clientX,a.value=__assign(__assign({},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&&t())},p=e=>{!1!==n&&(s.value&&(s.value=void 0),r.value&&(r.value=void 0),removeEventListener(e,l))};return o.onUnmounted((()=>{!1!==n&&(p("mousemove"),p("touchmove"))})),{swipedDiff:r,swipeStart:s,swipeStyle:a,swipeHandler:l,startSwipeHandler:o=>{if(!1===n)return;s.value=o;const t=i(o)?"mousemove":"touchmove",p=i(o)?"mouseup":"touchend";addEventListener(t,l),addEventListener(p,(()=>(o=>{const t={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=__assign(__assign({},a.value),t):e.endsWith("right")?a.value=__assign(__assign({},a.value),n):a.value=__assign(__assign({},a.value),i),s.value=void 0,r.value=void 0,removeEventListener(o,l)})(t)))},cleanUpMove:p}};var r=o.defineComponent({props:{type:{type:String,default:"default"}}});const a={class:"mosha__icon"},i={key:0,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},l=o.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),p={key:1,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},u=o.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),c={key:2,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},d=o.createVNode("path",{d:"M0 0h24v24H0V0z",fill:"none"},null,-1),m=o.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),h={key:3,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#616161"},f=o.createVNode("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),v=o.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),_={key:4,xmlns:"http://www.w3.org/2000/svg",height:"32px",viewBox:"0 0 24 24",width:"32px",fill:"#ffffff"},g=o.createVNode("path",{d:"M0 0h24v24H0z",fill:"none"},null,-1),y=o.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);r.render=function(e,t,n,s,r,w){return o.openBlock(),o.createBlock("span",a,["warning"===e.type?(o.openBlock(),o.createBlock("svg",i,[l])):"danger"===e.type?(o.openBlock(),o.createBlock("svg",p,[u])):"success"===e.type?(o.openBlock(),o.createBlock("svg",c,[d,m])):"default"===e.type?(o.openBlock(),o.createBlock("svg",h,[f,v])):(o.openBlock(),o.createBlock("svg",_,[g,y]))])};var w=o.defineComponent({name:"MToast",components:{MIcon:r},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){const t=o.ref(),{swipedDiff:r,startSwipeHandler:a,swipeStyle:i,cleanUpMove:l}=s(e.position,e.onCloseHandler,e.swipeClose),{transitionType:p}=(u=e.position,c=e.transition,d=r,{transitionType:o.computed((()=>d.value>200?"mosha__fadeOutLeft":d.value<-200?"mosha__fadeOutRight":n[u][c]))});var u,c,d;const{start:m,stop:h,progress:f}=((e,t)=>{const n=o.ref(),s=o.ref(0),r=o.ref(t),a=o.ref(),i=o.ref(100),l=()=>{clearInterval(a.value),clearTimeout(n.value)};return o.onMounted((()=>{})),o.onUnmounted((()=>{l()})),{start:()=>{s.value=Date.now(),clearTimeout(n.value),a.value=setInterval((()=>{i.value--}),t/100-2),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),v=()=>{e.timeout>0&&m()};return o.watchEffect((()=>{const{customStyle:n}=((e,t,n)=>{const s=o.computed((()=>{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 n.length>0&&(s.value.backgroundColor=n),{customStyle:s}})(e.position,e.offset,e.toastBackgroundColor);t.value=n.value})),o.onMounted((()=>{v()})),{style:t,transitionType:p,startTimer:v,stopTimer:()=>{e.timeout>0&&h()},progress:f,onTouchStart:e=>{a(e)},onMouseLeave:()=>{l("mousemove"),v()},onMouseDown:e=>{a(e)},swipeStyle:i}}});const b={class:"mosha__toast__content-wrapper"},B={class:"mosha__toast__content"},k={class:"mosha__toast__content__text"},x={key:0,class:"mosha__toast__content__description"};w.render=function(e,t,n,s,r,a){const i=o.resolveComponent("MIcon");return o.openBlock(),o.createBlock(o.Transition,{name:e.transitionType,type:"animation"},{default:o.withCtx((()=>[e.visible?(o.openBlock(),o.createBlock("div",{key:0,class:["mosha__toast",e.toastBackgroundColor?null:e.type],style:[e.style,e.swipeStyle],onMouseenter:t[2]||(t[2]=(...o)=>e.stopTimer&&e.stopTimer(...o)),onMouseleave:t[3]||(t[3]=(...o)=>e.onMouseLeave&&e.onMouseLeave(...o)),onTouchstart:t[4]||(t[4]=(...o)=>e.onTouchStart&&e.onTouchStart(...o)),onMousedown:t[5]||(t[5]=(...o)=>e.onMouseDown&&e.onMouseDown(...o))},[o.createVNode("div",b,[e.showIcon?(o.openBlock(),o.createBlock(i,{key:0,type:e.type},null,8,["type"])):o.createCommentVNode("",!0),o.createVNode("div",B,[o.createVNode("div",k,o.toDisplayString(e.text),1),e.description.length>0?(o.openBlock(),o.createBlock("div",x,o.toDisplayString(e.description),1)):o.createCommentVNode("",!0)]),o.renderSlot(e.$slots,"default")]),e.showCloseButton?(o.openBlock(),o.createBlock("div",{key:0,class:"mosha__toast__close-icon",onClick:t[1]||(t[1]=(...o)=>e.onCloseHandler&&e.onCloseHandler(...o))})):o.createCommentVNode("",!0),e.hideProgressBar?o.createCommentVNode("",!0):(o.openBlock(),o.createBlock("div",{key:1,class:"mosha__toast__progress",style:{width:`${e.progress}%`}},null,4))],38)):o.createCommentVNode("",!0)])),_:3},8,["name"])};const C={"top-left":[],"top-right":[],"bottom-left":[],"bottom-right":[],"top-center":[],"bottom-center":[]};let I=0;const S=(e,o)=>{if(!e)return;const n=o?z(o):t;if(e.hasOwnProperty("render"))return void M(n,e);const s=V(e);M(n,s)},M=(e,t)=>{const n=T(e,C,12),s=I++,r=document.createElement("div");let a;document.body.appendChild(r),a=t.hasOwnProperty("render")?o.createVNode(w,N(e,s,n,P),(()=>[o.createVNode(t)])):o.createVNode(w,N(e,s,n,P,t)),o.render(a,r),e.position&&(C[e.position].push({toastVNode:a,container:r}),a.component&&(a.component.props.visible=!0))},N=(e,o,t,n,s)=>__assign(__assign(__assign({},e),s),{id:o,offset:t,visible:!1,onCloseHandler:()=>{n(o,e.position?e.position:"top-right")}}),z=e=>{const o=__assign(__assign({},e),{type:e.type||t.type,timeout:e.timeout||t.timeout,showCloseButton:e.showCloseButton,position:e.position||t.position,showIcon:e.showIcon,swipeClose:e.swipeClose,transition:e.transition||t.transition});return o.hideProgressBar=void 0!==o.timeout&&o.timeout<=0,void 0!==e.hideProgressBar&&(o.hideProgressBar=e.hideProgressBar),o},V=e=>({text:"string"==typeof e?e:e.title,description:"string"==typeof e?void 0:e.description}),T=(e,o,t)=>{let n=t;if(!e.position)throw new Error("no position");return o[e.position].forEach((({toastVNode:e})=>{const o=e.el.offsetHeight+t;n+=o||0})),n},P=(e,t)=>{const n=C[t],s=n.findIndex((({toastVNode:o})=>o.props&&e===o.props.id));if(-1===s)return;const{container:r,toastVNode:a}=n[s];if(!a.el)return;const i=a.el.offsetHeight;C[t].splice(s,1),((e,o,t,n)=>{for(let s=e;s<o.length;s++){const{toastVNode:e}=o[s];if(!e.el)return;const r=t.split("-")[0]||"top",a=parseInt(e.el.style[r],10)-n-12;if(!e.component)return;e.component.props.offset=a}})(s,n,t,i),a.component&&(a.component.props.visible=!1,a.component.props.onClose&&a.component.props.onClose(),setTimeout((()=>{o.render(null,r),document.body.removeChild(r)}),1e3))};var L={install:e=>{e.config.globalProperties.$moshaToast=S,e.provide("moshaToast",S)}};e.createToast=S,e.default=L,Object.defineProperty(e,"__esModule",{value:!0}),e[Symbol.toStringTag]="Module"})); |
import { VNode } from '@vue/runtime-core'; | ||
import { Component } from 'vue'; | ||
export declare type ToastType = 'info' | 'danger' | 'warning' | 'success' | 'default'; | ||
export declare type Position = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'top-center' | 'bottom-center'; | ||
export declare type TransitionType = 'bounce' | 'zoom' | 'slide'; | ||
export declare type ToastContent = string | { | ||
export interface ContentObject { | ||
title: string; | ||
description?: string; | ||
}; | ||
} | ||
export interface DisplayContentObject { | ||
text: string; | ||
description?: string; | ||
} | ||
export declare type ToastContent = string | ContentObject | Component; | ||
export interface ToastObject { | ||
@@ -21,2 +27,3 @@ toastVNode: VNode; | ||
hideProgressBar?: boolean; | ||
useComponentContent?: boolean; | ||
toastBackgroundColor?: string; | ||
@@ -23,0 +30,0 @@ swipeClose?: boolean; |
{ | ||
"name": "mosha-vue-toastify", | ||
"version": "1.0.11", | ||
"version": "1.0.12", | ||
"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.", |
@@ -65,5 +65,21 @@ # Mosha Vue Toastify | ||
The `createToast` function accepts 2 arguments, the first argument can be just a string or a object like this `{ title: 'some title', description: 'some good description'}`, the second argument is an options object. | ||
The `createToast` function accepts 2 arguments: | ||
- **First argument**: | ||
- It can be just a string or a object like this: `{ title: 'some title', description: 'some good description'}` | ||
- It can also accept a Vue 3 component if you need more customization, e.g. | ||
```ts | ||
import CustomizedContent from "./CustomizedContent.vue"; | ||
export default defineComponent({ | ||
setup () { | ||
const toast = () => { | ||
createToast(CustomizedContent) | ||
} | ||
return { toast } | ||
} | ||
}) | ||
``` | ||
- **Second argument**: the second argument is an options object. | ||
Options: | ||
@@ -70,0 +86,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
42914
181
101
1