UNPKG

react-toast-plus

Version:

React Toast Plus: A flexible, customizable, and modern toast notification library for React.

161 lines (156 loc) 23.6 kB
(function(v,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react/jsx-runtime"),require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-dom"],g):(v=typeof globalThis<"u"?globalThis:v||self,g(v["react-toast-plus"]={},v["react/jsx-runtime"],v.React,v.ReactDOM))})(this,function(v,g,m,Te){"use strict";const k=(...t)=>t.flatMap(e=>typeof e=="string"?e:typeof e=="object"&&e!==null?Object.keys(e).filter(o=>e[o]):[]).filter(Boolean).join(" ").trim();let be={data:""},ve=t=>typeof window=="object"?((t?t.querySelector("#_goober"):window._goober)||Object.assign((t||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:t||be,Ce=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,we=/\/\*[^]*?\*\/| +/g,G=/\n+/g,E=(t,e)=>{let o="",c="",l="";for(let r in t){let i=t[r];r[0]=="@"?r[1]=="i"?o=r+" "+i+";":c+=r[1]=="f"?E(i,r):r+"{"+E(i,r[1]=="k"?"":e)+"}":typeof i=="object"?c+=E(i,e?e.replace(/([^,])+/g,n=>r.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g,a=>/&/.test(a)?a.replace(/&/g,n):n?n+" "+a:a)):r):i!=null&&(r=/^--/.test(r)?r:r.replace(/[A-Z]/g,"-$&").toLowerCase(),l+=E.p?E.p(r,i):r+":"+i+";")}return o+(e&&l?e+"{"+l+"}":l)+c},S={},Y=t=>{if(typeof t=="object"){let e="";for(let o in t)e+=o+Y(t[o]);return e}return t},Oe=(t,e,o,c,l)=>{let r=Y(t),i=S[r]||(S[r]=(a=>{let d=0,f=11;for(;d<a.length;)f=101*f+a.charCodeAt(d++)>>>0;return"go"+f})(r));if(!S[i]){let a=r!==t?t:(d=>{let f,u,p=[{}];for(;f=Ce.exec(d.replace(we,""));)f[4]?p.shift():f[3]?(u=f[3].replace(G," ").trim(),p.unshift(p[0][u]=p[0][u]||{})):p[0][f[1]]=f[2].replace(G," ").trim();return p[0]})(t);S[i]=E(l?{["@keyframes "+i]:a}:a,o?"":"."+i)}let n=o&&S.g?S.g:null;return o&&(S.g=S[i]),((a,d,f,u)=>{u?d.data=d.data.replace(u,a):d.data.indexOf(a)===-1&&(d.data=f?a+d.data:d.data+a)})(S[i],e,c,n),i},Se=(t,e,o)=>t.reduce((c,l,r)=>{let i=e[r];if(i&&i.call){let n=i(o),a=n&&n.props&&n.props.className||/^go/.test(n)&&n;i=a?"."+a:n&&typeof n=="object"?n.props?"":E(n,""):n===!1?"":n}return c+l+(i??"")},"");function I(t){let e=this||{},o=t.call?t(e.p):t;return Oe(o.unshift?o.raw?Se(o,[].slice.call(arguments,1),e.p):o.reduce((c,l)=>Object.assign(c,l&&l.call?l(e.p):l),{}):o,ve(e.target),e.g,e.o,e.k)}let R,W,z,xe=I.bind({g:1}),M=I.bind({k:1});function Ee(t,e,o,c){E.p=e,R=t,W=o,z=c}function L(t,e){let o=this||{};return function(){let c=arguments;function l(r,i){let n=Object.assign({},r),a=n.className||l.className;o.p=Object.assign({theme:W&&W()},n),o.o=/ *go\d+/.test(a),n.className=I.apply(o,c)+(a?" "+a:"");let d=t;return t[0]&&(d=n.as||t,delete n.as),z&&d[0]&&z(n),R(d,n)}return e?e(l):l}}const Le=5e3,Z="top-right",J=300,K="bounce",De=!0,$e={lifetime:Le,autoClose:!0,progressBar:{visible:!0},closeButton:{visible:!0},iconProps:{visible:!0},pauseOnHover:!0,pauseOnFocusLoss:!0,closeOnClick:!1,draggableClose:!0,transitionDuration:J,placement:Z,transition:K},Ae={lifetime:0,autoClose:!1,progressBar:{visible:!1},closeButton:{visible:!1},pauseOnHover:!1,pauseOnFocusLoss:!1,closeOnClick:!1,draggableClose:!1},ke=6,Me={toastMaxWidth:"320px",toastMinWidth:"150px",toastMinHeight:"48px",toastBgColor:"#FFF",toastTextColor:"#5C5C5C",toastEmptyColor:"#5C5C5C",toastSuccessColor:"#17c964",toastInfoColor:"#007bff",toastWarningColor:"#ffcc00",toastErrorColor:"#ff4d4f",toastLoaderColor:"gray",toastLoaderAreaColor:"rgba(0,0,0,0.1)",toastBoxShadow:"0 3px 10px rgba(0, 0, 0, 0.1), 0 3px 3px rgba(0, 0, 0, 0.05)",toastPadding:"10px",toastRadius:"4px",toastFontFamily:"Verdana, sans-serif"},_e=t=>{const e={...Me,...t};return xe` :root { --toast-max-width: ${e.toastMaxWidth}; --toast-min-width: ${e.toastMinWidth}; --toast-min-height: ${e.toastMinHeight}; --toast-font-family: ${e.toastFontFamily}; --toast-bg-color: ${e.toastBgColor}; --toast-text-color: ${e.toastTextColor}; --toast-empty-color: ${e.toastEmptyColor}; --toast-success-color: ${e.toastSuccessColor}; --toast-info-color: ${e.toastInfoColor}; --toast-warning-color: ${e.toastWarningColor}; --toast-error-color: ${e.toastErrorColor}; --toast-loader-color: ${e.toastLoaderColor}; --toast-loader-area-color: ${e.toastLoaderAreaColor}; --toast-radius: ${e.toastRadius}; --toast-padding: ${e.toastPadding}; --toast-shadow: ${e.toastBoxShadow}; } `},Q={success:"var(--toast-success-color)",info:"var(--toast-info-color)",warning:"var(--toast-warning-color)",error:"var(--toast-error-color)",loading:"var(--toast-loading-color)",empty:"var(--toast-empty-color)"},ee=L("div")` position: fixed; z-index: 9999; inset: 5px; pointer-events: none; `,Be=I` display: flex; position: absolute; box-sizing: border-box; > * { pointer-events: auto; } `,te=L("div")` display: flex; justify-content: space-between; align-items: center; position: relative; background: var(--toast-bg-color); color: var(--toast-text-color); will-change: transform; box-shadow: var(--toast-shadow); max-width: var(--toast-max-width); min-width: var(--toast-min-width); max-height: var(--toast-max-height); border-radius: var(--toast-radius); font-family: var(--toast-font-family); overflow: hidden; padding: var(--toast-padding); gap: 10px; `,se=L("div")` flex: 1 1 auto; display: flex; align-items: center; margin: 5px 0; white-space: pre-line; `,Ie=M` 0% { transform: scaleX(1); } 100% { transform: scaleX(0); } `,oe=L("div")` position: absolute; bottom: 0; left: 0; height: 4px; width: 100%; transform-origin: left; background-color:${t=>Q[t.type]}; animation: ${Ie} linear 1 forwards; animation-duration: ${t=>t.duration}ms; animation-play-state: ${t=>t.state}; `,re=L("button")` border: none; background: none; cursor: pointer; color: inherit; text-transform: none; padding: 0; margin: 0; align-self: center; transition: opacity 0.3s; opacity: 0.5; flex: 0 0 auto; :hover{ opacity: 1; color:var(--toast-error-color); } height: 1rem; width: 1rem; >svg{ transition: color 0.3s; fill:currentColor; } `,Ne=L("div")` flex: 0 0 auto; width: 20px; height: 20px; `,je=M` 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } `,Fe=M` 0% { stroke-dashoffset: 100%; } 100% { stroke-dashoffset: 0; } `,ne=M` 0% { r: 0; } `,Pe=M` 50% { opacity: 0.11; } 100% { r: 100; opacity: 0; } `,ae=L("span")` width: 100%; height: 100%; border: 2px solid var(--toast-loader-area-color); border-bottom-color: var(--toast-loader-color); border-radius: 50%; display: inline-block; box-sizing: border-box; animation: ${je} 1s linear infinite;`,Xe=L("svg")` display: block; width: 100%; height: 100%; color: ${t=>Q[t.type]}; & circle:nth-of-type(1) { fill: currentColor; opacity: 0.15; animation: ${ne} 0.45s cubic-bezier(0.66, 0.23, 0.51, 1.23) backwards, ${Pe} 0.9s linear 1.1s forwards; } & circle:nth-of-type(2) { fill: currentColor; opacity: 0.8; animation: ${ne} 0.5s cubic-bezier(0.66, 0.23, 0.51, 1.23) 0.25s backwards; } & polyline , & line ,& path ,& path { stroke: var(--toast-bg-color); stroke-width: 20; stroke-dasharray: 100%, 100%; stroke-dashoffset: 0; animation: ${Fe} 0.5s cubic-bezier(0.55, 0.2, 0.71, -0.04) 0.7s backwards; } `,We=({children:t,className:e,style:o})=>g.jsx(ee,{className:k("react-toast-plus",e),style:{...o},children:t});var O=(t=>(t.ADD_TOAST="ADD_TOAST",t.REMOVE_TOAST="REMOVE_TOAST",t.UPDATE_TOAST="UPDATE_TOAST",t.REMOVE_ALL_TOASTS="REMOVE_ALL_TOASTS",t))(O||{});const ze=(t,e)=>{switch(e.type){case O.ADD_TOAST:return{...t,toasts:[e.toast,...t.toasts]};case O.REMOVE_TOAST:return t.toasts.some(o=>o.id===e.id)?{...t,toasts:t.toasts.filter(o=>o.id!==e.id)}:t;case O.UPDATE_TOAST:return{...t,toasts:t.toasts.map(o=>{var c,l,r,i,n,a;return o.id===e.toast.id?{...o,...e.toast,options:{...o.options,...e.toast.options,closeButton:{...(c=o.options)==null?void 0:c.closeButton,...(l=e.toast.options)==null?void 0:l.closeButton},progressBar:{...(r=o.options)==null?void 0:r.progressBar,...(i=e.toast.options)==null?void 0:i.progressBar},iconProps:{...(n=o.options)==null?void 0:n.iconProps,...(a=e.toast.options)==null?void 0:a.iconProps}}}:o})};case O.REMOVE_ALL_TOASTS:return{...t,toasts:[]};default:return console.error(`Unhandled action type: ${e.type}`),t}},N=({children:t,type:e,svgOptions:o,circleOptions:c,gOptions:l})=>g.jsx(Xe,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 214 214",preserveAspectRatio:"xMidYMid meet",...o,type:e,children:g.jsxs("g",{fill:"none",stroke:"currentColor",strokeWidth:"2",...l,children:[g.jsx("circle",{cx:"107",cy:"107",r:"107",...c}),g.jsx("circle",{cx:"107",cy:"107",r:"107",...c}),t]})}),ie=()=>g.jsxs(N,{type:"error",children:[g.jsx("line",{x1:"70",y1:"70",x2:"144",y2:"144"}),g.jsx("line",{x1:"144",y1:"70",x2:"70",y2:"144"})]}),le=()=>g.jsx(N,{type:"success",children:g.jsx("polyline",{points:"55 110 95 150 172.9 72.1"})}),ce=()=>g.jsxs(N,{type:"warning",children:[g.jsx("path",{d:"M107 50 L107 130"}),g.jsx("path",{d:"M 107 165.37 L 107 166.42"})]}),de=()=>g.jsxs(N,{type:"info",svgOptions:{viewBox:"142.9996 143.0003 214 214",fill:"none",baseProfile:"tiny",version:"1.2",strokeWidth:"0",width:"24",height:"24"},circleOptions:{cx:"-777.249",cy:"104.68",r:"107"},gOptions:{transform:"matrix(1, 0, 0, 1, 1027.2486572265625, 145.3203125)"},children:[g.jsx("path",{d:"M -753.273 166.428 C -753.336 166.449 -759.001 168.335 -763.921 168.335 C -766.639 168.335 -767.736 167.771 -768.083 167.525 C -769.805 166.324 -773.003 164.081 -767.529 153.177 L -757.279 132.739 C -751.204 120.603 -750.302 108.867 -754.769 99.683 C -758.419 92.171 -765.42 87.017 -774.449 85.17 C -777.698 84.505 -780.999 84.177 -784.266 84.177 C -803.221 84.177 -815.98 95.247 -816.514 95.717 C -818.348 97.337 -818.779 100.021 -817.56 102.135 C -816.33 104.245 -813.796 105.209 -811.46 104.409 C -811.408 104.389 -805.73 102.493 -800.81 102.493 C -798.116 102.493 -797.029 103.055 -796.69 103.291 C -794.957 104.501 -791.75 106.776 -797.214 117.662 L -807.464 138.108 C -813.55 150.254 -814.442 161.992 -809.975 171.162 C -806.324 178.676 -799.334 183.833 -790.283 185.676 C -787.067 186.324 -783.766 186.671 -780.507 186.671 C -761.543 186.671 -748.774 175.603 -748.241 175.128 C -746.407 173.522 -745.975 170.826 -747.193 168.716 C -748.423 166.613 -750.977 165.668 -753.273 166.428 Z",style:{strokeDasharray:"none",strokeWidth:"unset",fill:"var(--toast-bg-color)",stroke:"var(--toast-bg-color)"}}),g.jsx("circle",{cx:"-761.871",cy:"48.312",r:"25.623",style:{strokeDasharray:"none",strokeWidth:"unset",fill:"var(--toast-bg-color)",stroke:"var(--toast-bg-color)"}})]}),ue=()=>g.jsx("svg",{fillRule:"evenodd",viewBox:"0 0 24 24",children:g.jsx("path",{d:"M 4.7070312 3.2929688 L 3.2929688 4.7070312 L 10.585938 12 L 3.2929688 19.292969 L 4.7070312 20.707031 L 12 13.414062 L 19.292969 20.707031 L 20.707031 19.292969 L 13.414062 12 L 20.707031 4.7070312 L 19.292969 3.2929688 L 12 10.585938 L 4.7070312 3.2929688 z"})}),fe={success:g.jsx(le,{}),error:g.jsx(ie,{}),warning:g.jsx(ce,{}),info:g.jsx(de,{}),loading:g.jsx(ae,{}),empty:null},He=t=>{const{id:e,type:o="empty",content:c,onClose:l,options:r={},isRunning:i}=t,{className:n,style:a,lifetime:d,autoClose:f,progressBar:u,closeButton:p,icon:y,iconProps:h}=r,T=()=>typeof c=="string"||m.isValidElement(c)?c:typeof c=="function"?c(t):null;return g.jsxs(te,{className:n,style:a,children:[(h==null?void 0:h.visible)&&(fe[o]||y)&&g.jsx(Ne,{className:h==null?void 0:h.className,style:h==null?void 0:h.style,children:y??fe[o]}),g.jsx(se,{children:T()}),(p==null?void 0:p.visible)&&g.jsx(re,{className:p.className,style:p.style,onClick:()=>l(e),children:g.jsx(ue,{})}),f&&(u==null?void 0:u.visible)&&g.jsx(oe,{type:o||"empty",state:i?"running":"paused",duration:d??0,className:u.className,style:u.style},`${e}-progress-bar`)]})},Ue=(...t)=>{var o,c,l,r,i,n,a,d,f,u,p,y,h,T,w,C;const e=[...t].reverse();return{className:k(...t.map(s=>s==null?void 0:s.className).filter(Boolean)),style:Object.assign({},...t.map(s=>s==null?void 0:s.style)),lifetime:(o=e.find(s=>(s==null?void 0:s.lifetime)!==void 0))==null?void 0:o.lifetime,autoClose:(c=e.find(s=>(s==null?void 0:s.autoClose)!==void 0))==null?void 0:c.autoClose,pauseOnHover:(l=e.find(s=>(s==null?void 0:s.pauseOnHover)!==void 0))==null?void 0:l.pauseOnHover,draggableClose:(r=e.find(s=>(s==null?void 0:s.draggableClose)!==void 0))==null?void 0:r.draggableClose,pauseOnFocusLoss:(i=e.find(s=>(s==null?void 0:s.pauseOnFocusLoss)!==void 0))==null?void 0:i.pauseOnFocusLoss,closeOnClick:(n=e.find(s=>(s==null?void 0:s.closeOnClick)!==void 0))==null?void 0:n.closeOnClick,progressBar:{visible:(d=(a=e.find(s=>{var b;return((b=s==null?void 0:s.progressBar)==null?void 0:b.visible)!==void 0}))==null?void 0:a.progressBar)==null?void 0:d.visible,className:k(...t.map(s=>{var b;return(b=s==null?void 0:s.progressBar)==null?void 0:b.className}).filter(Boolean)),style:Object.assign({},...t.map(s=>{var b;return(b=s==null?void 0:s.progressBar)==null?void 0:b.style}))},closeButton:{visible:(u=(f=e.find(s=>{var b;return((b=s==null?void 0:s.closeButton)==null?void 0:b.visible)!==void 0}))==null?void 0:f.closeButton)==null?void 0:u.visible,className:k(...t.map(s=>{var b;return(b=s==null?void 0:s.closeButton)==null?void 0:b.className}).filter(Boolean)),style:Object.assign({},...t.map(s=>{var b;return(b=s==null?void 0:s.closeButton)==null?void 0:b.style}))},transition:(p=e.find(s=>(s==null?void 0:s.transition)!==void 0))==null?void 0:p.transition,transitionDuration:(y=e.find(s=>(s==null?void 0:s.transitionDuration)!==void 0))==null?void 0:y.transitionDuration,placement:(h=e.find(s=>(s==null?void 0:s.placement)!==void 0))==null?void 0:h.placement,icon:(T=e.find(s=>(s==null?void 0:s.icon)!==void 0))==null?void 0:T.icon,iconProps:{visible:(C=(w=e.find(s=>{var b;return((b=s==null?void 0:s.iconProps)==null?void 0:b.visible)!==void 0}))==null?void 0:w.iconProps)==null?void 0:C.visible,className:k(...t.map(s=>{var b;return(b=s==null?void 0:s.iconProps)==null?void 0:b.className}).filter(Boolean)),style:Object.assign({},...t.map(s=>{var b;return(b=s==null?void 0:s.iconProps)==null?void 0:b.style}))}}},Ve=(t,e,o)=>{const[c,l]=m.useState(null),[r,i]=m.useState(!1),[n,a]=m.useState(!1),[d,f]=m.useState(0),u=m.useRef(null),p=m.useCallback(C=>{if(!t)return;const s=Date.now()+C;l(s),f(C),i(!0),a(!1),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{i(!1),f(0),t&&e(t)},C)},[t]),y=m.useCallback(()=>{if(r&&c){const C=Date.now(),s=c-C;f(s),i(!1),a(!0),u.current&&clearTimeout(u.current)}},[r,c]),h=m.useCallback(()=>{if(!r&&n&&d>0){const C=Date.now()+d;l(C),i(!0),a(!1),u.current=setTimeout(()=>{i(!1),f(0),t&&e(t)},d)}},[r,n,d]),T=m.useCallback(()=>{u.current&&(clearTimeout(u.current),u.current=null),i(!1),a(!1),f(0),l(null)},[]),w=m.useCallback(()=>r&&c?Math.max(0,c-Date.now()):d,[r,c,d]);return m.useEffect(()=>{if(o)return document.hasFocus()||y(),window.addEventListener("blur",y),window.addEventListener("focus",h),()=>{window.removeEventListener("blur",y),window.removeEventListener("focus",h)}},[o,y,h]),{start:p,pause:y,resume:h,clear:T,remainingTime:w,isRunning:r,isPaused:n}},H=()=>{const t=m.useContext(U);if(!t)throw new Error("useToast must be used within a ToastProvider");const{dispatch:e,state:o}=t;return{toasts:o.toasts,dispatch:e}},qe=()=>{const{toasts:t,dispatch:e}=H(),o=(l,r)=>{e({type:O.UPDATE_TOAST,toast:{id:l,element:r}})},c=m.useCallback((l,r)=>{var f,u;const i=(u=(f=l.options)==null?void 0:f.placement)==null?void 0:u.includes("bottom"),n=t.filter(p=>{var y,h;return((y=p.options)==null?void 0:y.placement)===((h=l.options)==null?void 0:h.placement)}),a=n.findIndex(p=>p.id===l.id),d=i?r.newestFirst?[a+1]:[0,a]:r.newestFirst?[0,a]:[a+1];return n.slice(...d).reduce((p,y)=>{var T;const h=((T=y.element)==null?void 0:T.height)??0;return p+r.gutter+h},0)},[t]);return{updateToastElement:o,calcToastOffset:c}},ge=()=>`${Date.now()}-${Math.random().toString(36).slice(2,11)}`,me=()=>{const{dispatch:t,toasts:e}=H(),o=(n,a="empty",d)=>{const f=ge();return t({type:O.ADD_TOAST,toast:{id:f,content:n,type:a,onClose:l,options:d}}),{id:f}},c=n=>(a,d)=>o(a,n,d);o.success=c("success"),o.error=c("error"),o.warning=c("warning"),o.info=c("info"),o.empty=c("empty"),o.loading=c("loading"),o.promise=(n,a,d)=>{const{success:f,error:u,...p}=d||{},y=o(a.pending,"loading",p).id;return(typeof n=="function"?n():n).then(T=>{const w=typeof a.success=="function"?a.success(T):a.success;i({id:y,content:w,type:"success",options:f})}).catch(T=>{const w=typeof a.error=="function"?a.error(T):a.error;i({id:y,content:w,type:"error",options:u})}),{id:y}},o.custom=(n,a)=>{const d=ge();return t({type:O.ADD_TOAST,toast:{id:d,content:"",onClose:l,renderCustomToast:n,options:a}}),{id:d}};const l=n=>{t({type:O.REMOVE_TOAST,id:n})};l.byIndex=n=>{var d;const a=(d=e[n])==null?void 0:d.id;a?l(a):console.error("Invalid index")};const r=()=>{t({type:O.REMOVE_ALL_TOASTS})},i=n=>{t({type:O.UPDATE_TOAST,toast:n})};return{addToast:o,removeToast:l,removeAllToasts:r,updateToast:i}},Ge=(t,e,o,c)=>{var d;const l=c.includes("right")?1:-1,r=c.includes("bottom")?1:-1,i=c.includes("center"),n={fade:{transition:`all ${o}ms cubic-bezier(0.2, 0, 0, 1)`},slide:{},zoom:{},bounce:{transition:`all ${o}ms cubic-bezier(0.68, -0.55, 0.25, 1.35)`}},a={fade:{unmounted:{transform:`translate3d(0, ${r*120}%, 0) scale(0.4)`},entering:{transform:"translate3d(0, 0, 0) scale(1)"},entered:{transform:"translate3d(0, 0, 0) scale(1)"},exiting:{transform:`translate3d(0, ${r*60}%, 0) scale(0.4)`,opacity:0},exited:{transform:`translate3d(0, ${r*60}%, 0) scale(0.4)`,opacity:0}},zoom:{unmounted:{transform:"scale(0)"},entering:{transform:"scale(1)"},entered:{transform:"scale(1)"},exiting:{transform:"scale(0)"},exited:{transform:"scale(0)"}},slide:{unmounted:{transform:`translateX(${l*(i?50:100)}%)`,opacity:i?0:1},entering:{transform:"translateX(0)",opacity:1},entered:{transform:"translateX(0)",opacity:1},exiting:{transform:`translateX(${l*(i?50:100)}%)`,opacity:i?0:1},exited:{transform:`translateX(${l*(i?50:100)}%)`,opacity:i?0:1}},bounce:{unmounted:{transform:`translate3d(${i?`0 , ${r*50}%`:`${l*100}% , 0`}, 0) scale(0.8)`,opacity:i?0:1},entering:{transform:"translate3d(0, 0, 0) scale(1)",opacity:1},entered:{transform:"translate3d(0, 0, 0) scale(1)",opacity:1},exiting:{transform:`translate3d(${i?`0 , ${r*50}%`:`${l*100}% , 0`}, 0) scale(0.8)`,opacity:i?0:1},exited:{transform:`translate3d(${i?`0 , ${r*50}%`:`${l*100}% , 0`}, 0) scale(0.8)`,opacity:i?0:1}}};return Object.assign({transition:`all ${o}ms ease-in-out`},n[e],(d=a[e])==null?void 0:d[t])||{}},Ye=t=>{switch(t){case"top-left":case"bottom-left":return{justifyContent:"flex-start",left:0};case"top-center":case"bottom-center":return{justifyContent:"center",left:0,right:0};case"top-right":case"bottom-right":return{justifyContent:"flex-end",right:0};default:return{justifyContent:"flex-end",right:0}}},Re=(t,e,o)=>{const[c,l]=m.useState(0),[r,i]=m.useState(!1),[n,a]=m.useState(1),d=m.useRef(0),f=m.useRef(0),u=m.useRef(!1),p=m.useCallback(T=>{if(!r)return;const C=("touches"in T?T.touches[0].clientX:T.clientX)-d.current;f.current=C-c,requestAnimationFrame(()=>{l(C);const s=Math.max(1-Math.abs(C)/150,0);a(s)}),Math.abs(C)>10&&(u.current=!0)},[r,c]),y=T=>{i(!0),d.current="touches"in T?T.touches[0].clientX:T.clientX,f.current=0,u.current=!1},h=m.useCallback(()=>{i(!1),Math.abs(c)>100||Math.abs(f.current)>30?e(t):(l(0),a(1))},[c,e,t]);return m.useEffect(()=>{if(o)return;const T=()=>{r&&h()};return window.addEventListener("mouseup",T),window.addEventListener("touchend",T),()=>{window.removeEventListener("mouseup",T),window.removeEventListener("touchend",T)}},[r,h]),{dragDistance:c,opacity:n,handleDragStart:y,handleDragMove:p,handleDragEnd:h,isDragging:r,wasDragged:u.current}},Ze=({children:t,toastContextProps:e,gutter:o,newestFirst:c=De})=>{var he;const[l,r]=m.useState("unmounted"),{updateToast:i}=me(),{updateToastElement:n,calcToastOffset:a}=qe(),{autoClose:d,lifetime:f,placement:u=Z,transition:p=K,transitionDuration:y=J,draggableClose:h,pauseOnHover:T,pauseOnFocusLoss:w,closeOnClick:C}=e.options||{},{dragDistance:s,opacity:b,handleDragStart:j,handleDragMove:F,handleDragEnd:P,isDragging:$,wasDragged:A}=Re(e.id,e.onClose,h),_=m.useCallback(x=>{r("exiting"),setTimeout(()=>{e.onClose(x)},y)},[y]),D=Ve(e.id,_,w);m.useEffect(()=>{i({id:e.id,options:{placement:u}})},[u]),m.useEffect(()=>{if(l==="unmounted"&&r("entering"),l==="entering"){const x=setTimeout(()=>r("entered"),y);return()=>clearTimeout(x)}else if(l==="exiting"){const x=setTimeout(()=>r("exited"),y);return()=>clearTimeout(x)}},[l,y]);const B=m.useRef({height:0}),V=m.useCallback(x=>{if(x){const pe=()=>{var ye;const X=x.clientHeight;B.current&&((ye=B.current)==null?void 0:ye.height)!==X&&X>0&&(B.current.height=X,n(e.id,{height:X}))};pe(),new ResizeObserver(pe).observe(x,{box:"border-box"})}},[e.id,n]);m.useEffect(()=>{if(d&&f)return D.start(f),()=>{D.clear()}},[d,f]),m.useEffect(()=>{$&&D.pause()},[$]);const q=m.useCallback(()=>{A||_(e.id)},[A]),Ke=a(e,{gutter:o,newestFirst:c}),Qe={...e,options:{...e.options,style:{...(he=e.options)==null?void 0:he.style,...Ge(l,p,y,u)}}};return g.jsx("div",{ref:V,className:Be,...T&&{onMouseEnter:D.pause,onMouseLeave:D.resume},...h&&{onMouseDown:j,onMouseMove:F,onMouseUp:P,onTouchStart:j,onTouchMove:F,onTouchEnd:P},...C&&{onClick:q},style:{transform:`translateY(${Ke*(u.includes("top")?1:-1)}px) translateX(${s}px)`,opacity:b,cursor:h?"pointer":"default",transition:$?"none":"all 300ms ease",...Ye(u),[u.includes("top")?"top":"bottom"]:0},children:g.jsx(t,{...Qe,...D,onClose:_},e.id)})};Ee(m.createElement);const U=m.createContext(void 0),Je=({children:t,containerOptions:e={},toastOptions:o={},gutter:c=ke,newestFirst:l,toastStyles:r,portalActive:i})=>{const[n,a]=m.useReducer(ze,{toasts:[]}),{portalSelector:d=typeof document<"u"?document.body:null,component:f=We,...u}=e,{component:p=He,successOptions:y={},errorOptions:h={},warningOptions:T={},infoOptions:w={},emptyOptions:C={},loadingOptions:s=Ae,...b}=o,j={success:y,error:h,warning:T,info:w,empty:C,loading:s};m.useEffect(()=>{_e(r)},[r]);const F=typeof window<"u"&&"__NEXT_DATA__"in window,P=i??!F,$=g.jsx(f,{...u,children:n.toasts.map(A=>{const{options:_,renderCustomToast:D,...B}=A,V=j[A.type]||{},q=Ue($e,b,V,_);return g.jsx(Ze,{gutter:c,toastContextProps:{...B,options:q},newestFirst:l,children:D||p},`Controller_${A.id}`)})});return g.jsxs(U.Provider,{value:{state:n,dispatch:a},children:[t,P&&d?Te.createPortal($,d):$]})};v.ActionTypes=O,v.CloseIcon=ue,v.ErrorIcon=ie,v.InfoIcon=de,v.StyledCloseButton=re,v.StyledLoadingIcon=ae,v.StyledProgressBar=oe,v.StyledToastContainer=ee,v.StyledToaster=te,v.StyledToasterContent=se,v.SuccessIcon=le,v.ToastContext=U,v.ToastProvider=Je,v.WarningIcon=ce,v.useToast=me,v.useToastStore=H,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});