sonner 2.0.0-beta.1 → 2.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,1165 @@
1
- "use client";var ne=Object.create;var pt=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var de=(s,e)=>{for(var t in e)pt(s,t,{get:e[t],enumerable:!0})},$t=(s,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of ie(e))!ce.call(s,l)&&l!==t&&pt(s,l,{get:()=>e[l],enumerable:!(a=re(e,l))||a.enumerable});return s};var et=(s,e,t)=>(t=s!=null?ne(le(s)):{},$t(e||!s||!s.__esModule?pt(t,"default",{value:s,enumerable:!0}):t,s)),ue=s=>$t(pt({},"__esModule",{value:!0}),s);var He={};de(He,{Toaster:()=>Me,toast:()=>Kt,useSonner:()=>Ie});module.exports=ue(He);var o=et(require("react")),mt=et(require("react-dom"));var S=et(require("react")),Ft=s=>{switch(s){case"success":return pe;case"info":return ge;case"warning":return me;case"error":return he;default:return null}},fe=Array(12).fill(0),Wt=({visible:s,className:e})=>S.default.createElement("div",{className:["sonner-loading-wrapper",e].filter(Boolean).join(" "),"data-visible":s},S.default.createElement("div",{className:"sonner-spinner"},fe.map((t,a)=>S.default.createElement("div",{className:"sonner-loading-bar",key:`spinner-bar-${a}`})))),pe=S.default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},S.default.createElement("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",clipRule:"evenodd"})),me=S.default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",height:"20",width:"20"},S.default.createElement("path",{fillRule:"evenodd",d:"M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z",clipRule:"evenodd"})),ge=S.default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},S.default.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",clipRule:"evenodd"})),he=S.default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},S.default.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"})),_t=S.default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},S.default.createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),S.default.createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"}));var Tt=et(require("react")),Vt=()=>{let[s,e]=Tt.default.useState(document.hidden);return Tt.default.useEffect(()=>{let t=()=>{e(document.hidden)};return document.addEventListener("visibilitychange",t),()=>window.removeEventListener("visibilitychange",t)},[]),s};var Ut=et(require("react")),wt=1,St=class{constructor(){this.subscribe=e=>(this.subscribers.push(e),()=>{let t=this.subscribers.indexOf(e);this.subscribers.splice(t,1)});this.publish=e=>{this.subscribers.forEach(t=>t(e))};this.addToast=e=>{this.publish(e),this.toasts=[...this.toasts,e]};this.create=e=>{var R;let{message:t,...a}=e,l=typeof(e==null?void 0:e.id)=="number"||((R=e.id)==null?void 0:R.length)>0?e.id:wt++,f=this.toasts.find(g=>g.id===l),x=e.dismissible===void 0?!0:e.dismissible;return this.dismissedToasts.has(l)&&this.dismissedToasts.delete(l),f?this.toasts=this.toasts.map(g=>g.id===l?(this.publish({...g,...e,id:l,title:t}),{...g,...e,id:l,dismissible:x,title:t}):g):this.addToast({title:t,...a,dismissible:x,id:l}),l};this.dismiss=e=>(this.dismissedToasts.add(e),e||this.toasts.forEach(t=>{this.subscribers.forEach(a=>a({id:t.id,dismiss:!0}))}),requestAnimationFrame(()=>this.subscribers.forEach(t=>t({id:e,dismiss:!0}))),e);this.message=(e,t)=>this.create({...t,message:e});this.error=(e,t)=>this.create({...t,message:e,type:"error"});this.success=(e,t)=>this.create({...t,type:"success",message:e});this.info=(e,t)=>this.create({...t,type:"info",message:e});this.warning=(e,t)=>this.create({...t,type:"warning",message:e});this.loading=(e,t)=>this.create({...t,type:"loading",message:e});this.promise=(e,t)=>{if(!t)return;let a;t.loading!==void 0&&(a=this.create({...t,promise:e,type:"loading",message:t.loading,description:typeof t.description!="function"?t.description:void 0}));let l=Promise.resolve(e instanceof Function?e():e),f=a!==void 0,x,R=l.then(async i=>{if(x=["resolve",i],Ut.default.isValidElement(i))f=!1,this.create({id:a,type:"default",message:i});else if(ye(i)&&!i.ok){f=!1;let w=typeof t.error=="function"?await t.error(`HTTP error! status: ${i.status}`):t.error,F=typeof t.description=="function"?await t.description(`HTTP error! status: ${i.status}`):t.description;this.create({id:a,type:"error",message:w,description:F})}else if(t.success!==void 0){f=!1;let w=typeof t.success=="function"?await t.success(i):t.success,F=typeof t.description=="function"?await t.description(i):t.description;this.create({id:a,type:"success",message:w,description:F})}}).catch(async i=>{if(x=["reject",i],t.error!==void 0){f=!1;let D=typeof t.error=="function"?await t.error(i):t.error,w=typeof t.description=="function"?await t.description(i):t.description;this.create({id:a,type:"error",message:D,description:w})}}).finally(()=>{var i;f&&(this.dismiss(a),a=void 0),(i=t.finally)==null||i.call(t)}),g=()=>new Promise((i,D)=>R.then(()=>x[0]==="reject"?D(x[1]):i(x[1])).catch(D));return typeof a!="string"&&typeof a!="number"?{unwrap:g}:Object.assign(a,{unwrap:g})};this.custom=(e,t)=>{let a=(t==null?void 0:t.id)||wt++;return this.create({jsx:e(a),id:a,...t}),a};this.getActiveToasts=()=>this.toasts.filter(e=>!this.dismissedToasts.has(e.id));this.subscribers=[],this.toasts=[],this.dismissedToasts=new Set}},T=new St,be=(s,e)=>{let t=(e==null?void 0:e.id)||wt++;return T.addToast({title:s,...e,id:t}),t},ye=s=>s&&typeof s=="object"&&"ok"in s&&typeof s.ok=="boolean"&&"status"in s&&typeof s.status=="number",xe=be,ve=()=>T.toasts,Te=()=>T.getActiveToasts(),Kt=Object.assign(xe,{success:T.success,info:T.info,warning:T.warning,error:T.error,custom:T.custom,message:T.message,promise:T.promise,dismiss:T.dismiss,loading:T.loading},{getHistory:ve,getToasts:Te});function Rt(s,{insertAt:e}={}){if(!s||typeof document=="undefined")return;let t=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css",e==="top"&&t.firstChild?t.insertBefore(a,t.firstChild):t.appendChild(a),a.styleSheet?a.styleSheet.cssText=s:a.appendChild(document.createTextNode(s))}Rt(`html[dir=ltr],[data-sonner-toaster][dir=ltr]{--toast-icon-margin-start: -3px;--toast-icon-margin-end: 4px;--toast-svg-margin-start: -1px;--toast-svg-margin-end: 0px;--toast-button-margin-start: auto;--toast-button-margin-end: 0;--toast-close-button-start: 0;--toast-close-button-end: unset;--toast-close-button-transform: translate(-35%, -35%)}html[dir=rtl],[data-sonner-toaster][dir=rtl]{--toast-icon-margin-start: 4px;--toast-icon-margin-end: -3px;--toast-svg-margin-start: 0px;--toast-svg-margin-end: -1px;--toast-button-margin-start: 0;--toast-button-margin-end: auto;--toast-close-button-start: unset;--toast-close-button-end: 0;--toast-close-button-transform: translate(35%, -35%)}[data-sonner-toaster]{position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1: hsl(0, 0%, 99%);--gray2: hsl(0, 0%, 97.3%);--gray3: hsl(0, 0%, 95.1%);--gray4: hsl(0, 0%, 93%);--gray5: hsl(0, 0%, 90.9%);--gray6: hsl(0, 0%, 88.7%);--gray7: hsl(0, 0%, 85.8%);--gray8: hsl(0, 0%, 78%);--gray9: hsl(0, 0%, 56.1%);--gray10: hsl(0, 0%, 52.3%);--gray11: hsl(0, 0%, 43.5%);--gray12: hsl(0, 0%, 9%);--border-radius: 8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:999999999;transition:transform .4s ease}[data-sonner-toaster][data-x-position=right]{right:var(--offset-right)}[data-sonner-toaster][data-x-position=left]{left:var(--offset-left)}[data-sonner-toaster][data-x-position=center]{left:50%;transform:translate(-50%)}[data-sonner-toaster][data-y-position=top]{top:var(--offset-top)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--offset-bottom)}[data-sonner-toast]{--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);filter:blur(0);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none;overflow-wrap:anywhere}[data-sonner-toast][data-styled=true]{padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}[data-sonner-toast]:focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}[data-sonner-toast][data-y-position=top]{top:0;--y: translateY(-100%);--lift: 1;--lift-amount: calc(1 * var(--gap))}[data-sonner-toast][data-y-position=bottom]{bottom:0;--y: translateY(100%);--lift: -1;--lift-amount: calc(var(--lift) * var(--gap))}[data-sonner-toast] [data-description]{font-weight:400;line-height:1.4;color:#3f3f3f}[data-sonner-toaster][data-sonner-theme=dark] [data-description]{color:#e8e8e8}[data-sonner-toast] [data-title]{font-weight:500;line-height:1.5;color:inherit}[data-sonner-toast] [data-icon]{display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}[data-sonner-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}[data-sonner-toast] [data-icon]>*{flex-shrink:0}[data-sonner-toast] [data-icon] svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}[data-sonner-toast] [data-content]{display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;font-weight:500;cursor:pointer;outline:none;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}[data-sonner-toast] [data-button]:focus-visible{box-shadow:0 0 0 2px #0006}[data-sonner-toast] [data-button]:first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}[data-sonner-toast] [data-cancel]{color:var(--normal-text);background:rgba(0,0,0,.08)}[data-sonner-toaster][data-sonner-theme=dark] [data-cancel]{background:rgba(255,255,255,.3)}[data-sonner-toast] [data-close-button]{position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast] [data-close-button]:focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}[data-sonner-toast] [data-disabled=true]{cursor:not-allowed}[data-sonner-toast]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-sonner-toast][data-swiping=true]:before{content:"";position:absolute;left:-100%;right:-100%;height:100%;z-index:-1}[data-sonner-toast][data-y-position=top][data-swiping=true]:before{bottom:50%;transform:scaleY(3) translateY(50%)}[data-sonner-toast][data-y-position=bottom][data-swiping=true]:before{top:50%;transform:scaleY(3) translateY(-50%)}[data-sonner-toast][data-swiping=false][data-removed=true]:before{content:"";position:absolute;inset:0;transform:scaleY(2)}[data-sonner-toast]:after{content:"";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-sonner-toast][data-mounted=true]{--y: translateY(0);opacity:1}[data-sonner-toast][data-expanded=false][data-front=false]{--scale: var(--toasts-before) * .05 + 1;--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-sonner-toast]>*{transition:opacity .4s}[data-sonner-toast][data-x-position=right]{right:0}[data-sonner-toast][data-x-position=left]{left:0}[data-sonner-toast][data-expanded=false][data-front=false][data-styled=true]>*{opacity:0}[data-sonner-toast][data-visible=false]{opacity:0;pointer-events:none}[data-sonner-toast][data-mounted=true][data-expanded=true]{--y: translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y: translateY(calc(var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]{--y: translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]{--y: translateY(40%);opacity:0;transition:transform .5s,opacity .2s}[data-sonner-toast][data-removed=true][data-front=false]:before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y, 0px)) translate(var(--swipe-amount-x, 0px));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width: 600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-sonner-theme=light]{--normal-bg: #fff;--normal-border: var(--gray4);--normal-text: var(--gray12);--success-bg: hsl(143, 85%, 96%);--success-border: hsl(145, 92%, 87%);--success-text: hsl(140, 100%, 27%);--info-bg: hsl(208, 100%, 97%);--info-border: hsl(221, 91%, 93%);--info-text: hsl(210, 92%, 45%);--warning-bg: hsl(49, 100%, 97%);--warning-border: hsl(49, 91%, 84%);--warning-text: hsl(31, 92%, 45%);--error-bg: hsl(359, 100%, 97%);--error-border: hsl(359, 100%, 94%);--error-text: hsl(360, 100%, 45%)}[data-sonner-toaster][data-sonner-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg: #fff;--normal-border: var(--gray3);--normal-text: var(--gray12)}[data-sonner-toaster][data-sonner-theme=dark]{--normal-bg: #000;--normal-bg-hover: hsl(0, 0%, 12%);--normal-border: hsl(0, 0%, 20%);--normal-border-hover: hsl(0, 0%, 25%);--normal-text: var(--gray1);--success-bg: hsl(150, 100%, 6%);--success-border: hsl(147, 100%, 12%);--success-text: hsl(150, 86%, 65%);--info-bg: hsl(215, 100%, 6%);--info-border: hsl(223, 43%, 17%);--info-text: hsl(216, 87%, 65%);--warning-bg: hsl(64, 100%, 6%);--warning-border: hsl(60, 100%, 9%);--warning-text: hsl(46, 87%, 65%);--error-bg: hsl(358, 76%, 10%);--error-border: hsl(357, 89%, 16%);--error-text: hsl(358, 100%, 81%)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success],[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info],[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning],[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error],[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size: 16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:nth-child(1){animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}to{opacity:.15}}@media (prefers-reduced-motion){[data-sonner-toast],[data-sonner-toast]>*,.sonner-loading-bar{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)}
2
- `);function ot(s){return s.label!==void 0}var we=3,Se="24px",Re="16px",Xt=5e3,Ee=356,De=14,Pe=20,Ne=200;function M(...s){return s.filter(Boolean).join(" ")}function Be(s){let[e,t]=s.split("-"),a=[];return e&&a.push(e),t&&a.push(t),a}var Ce=s=>{var Bt,Ct,kt,It,Mt,Ht,At,Lt,zt,jt,Yt;let{invert:e,toast:t,unstyled:a,interacting:l,setHeights:f,visibleToasts:x,heights:R,index:g,toasts:i,expanded:D,removeToast:w,defaultRichColors:F,closeButton:at,style:gt,cancelButtonStyle:ht,actionButtonStyle:c,className:st="",descriptionClassName:nt="",duration:X,position:rt,gap:bt,loadingIcon:it,expandByDefault:P,classNames:n,icons:B,closeButtonAriaLabel:lt="Close toast",pauseWhenPageIsHidden:ct}=s,[Y,k]=o.default.useState(null),[dt,J]=o.default.useState(null),[W,H]=o.default.useState(!1),[A,yt]=o.default.useState(!1),[L,z]=o.default.useState(!1),[ut,u]=o.default.useState(!1),[h,y]=o.default.useState(!1),[E,j]=o.default.useState(0),[p,_]=o.default.useState(0),O=o.default.useRef(t.duration||X||Xt),q=o.default.useRef(null),N=o.default.useRef(null),qt=g===0,Gt=g+1<=x,C=t.type,V=t.dismissible!==!1,Qt=t.className||"",Zt=t.descriptionClassName||"",ft=o.default.useMemo(()=>R.findIndex(r=>r.toastId===t.id)||0,[R,t.id]),te=o.default.useMemo(()=>{var r;return(r=t.closeButton)!=null?r:at},[t.closeButton,at]),Et=o.default.useMemo(()=>t.duration||X||Xt,[t.duration,X]),xt=o.default.useRef(0),U=o.default.useRef(0),Dt=o.default.useRef(0),K=o.default.useRef(null),[ee,oe]=rt.split("-"),Pt=o.default.useMemo(()=>R.reduce((r,m,d)=>d>=ft?r:r+m.height,0),[R,ft]),Nt=Vt(),ae=t.invert||e,vt=C==="loading";U.current=o.default.useMemo(()=>ft*bt+Pt,[ft,Pt]),o.default.useEffect(()=>{O.current=Et},[Et]),o.default.useEffect(()=>{H(!0)},[]),o.default.useEffect(()=>{let r=N.current;if(r){let m=r.getBoundingClientRect().height;return _(m),f(d=>[{toastId:t.id,height:m,position:t.position},...d]),()=>f(d=>d.filter(b=>b.toastId!==t.id))}},[f,t.id]),o.default.useLayoutEffect(()=>{if(!W)return;let r=N.current,m=r.style.height;r.style.height="auto";let d=r.getBoundingClientRect().height;r.style.height=m,_(d),f(b=>b.find(v=>v.toastId===t.id)?b.map(v=>v.toastId===t.id?{...v,height:d}:v):[{toastId:t.id,height:d,position:t.position},...b])},[W,t.title,t.description,f,t.id]);let $=o.default.useCallback(()=>{yt(!0),j(U.current),f(r=>r.filter(m=>m.toastId!==t.id)),setTimeout(()=>{w(t)},Ne)},[t,w,f,U]);o.default.useEffect(()=>{if(t.promise&&C==="loading"||t.duration===1/0||t.type==="loading")return;let r;return D||l||ct&&Nt?(()=>{if(Dt.current<xt.current){let b=new Date().getTime()-xt.current;O.current=O.current-b}Dt.current=new Date().getTime()})():(()=>{O.current!==1/0&&(xt.current=new Date().getTime(),r=setTimeout(()=>{var b;(b=t.onAutoClose)==null||b.call(t,t),$()},O.current))})(),()=>clearTimeout(r)},[D,l,t,C,ct,Nt,$]),o.default.useEffect(()=>{t.delete&&$()},[$,t.delete]);function se(){var r,m,d;return B!=null&&B.loading?o.default.createElement("div",{className:M(n==null?void 0:n.loader,(r=t==null?void 0:t.classNames)==null?void 0:r.loader,"sonner-loader"),"data-visible":C==="loading"},B.loading):it?o.default.createElement("div",{className:M(n==null?void 0:n.loader,(m=t==null?void 0:t.classNames)==null?void 0:m.loader,"sonner-loader"),"data-visible":C==="loading"},it):o.default.createElement(Wt,{className:M(n==null?void 0:n.loader,(d=t==null?void 0:t.classNames)==null?void 0:d.loader),visible:C==="loading"})}return o.default.createElement("li",{tabIndex:0,ref:N,className:M(st,Qt,n==null?void 0:n.toast,(Bt=t==null?void 0:t.classNames)==null?void 0:Bt.toast,n==null?void 0:n.default,n==null?void 0:n[C],(Ct=t==null?void 0:t.classNames)==null?void 0:Ct[C]),"data-sonner-toast":"","data-rich-colors":(kt=t.richColors)!=null?kt:F,"data-styled":!(t.jsx||t.unstyled||a),"data-mounted":W,"data-promise":!!t.promise,"data-swiped":h,"data-removed":A,"data-visible":Gt,"data-y-position":ee,"data-x-position":oe,"data-index":g,"data-front":qt,"data-swiping":L,"data-dismissible":V,"data-type":C,"data-invert":ae,"data-swipe-out":ut,"data-swipe-direction":dt,"data-expanded":!!(D||P&&W),style:{"--index":g,"--toasts-before":g,"--z-index":i.length-g,"--offset":`${A?E:U.current}px`,"--initial-height":P?"auto":`${p}px`,...gt,...t.style},onDragEnd:()=>{z(!1),k(null),K.current=null},onPointerDown:r=>{vt||!V||(q.current=new Date,j(U.current),r.target.setPointerCapture(r.pointerId),r.target.tagName!=="BUTTON"&&(z(!0),K.current={x:r.clientX,y:r.clientY}))},onPointerUp:()=>{var v,G,Q,Z,tt,Ot;if(ut||!V)return;K.current=null;let r=Number(((v=N.current)==null?void 0:v.style.getPropertyValue("--swipe-amount-x").replace("px",""))||0),m=Number(((G=N.current)==null?void 0:G.style.getPropertyValue("--swipe-amount-y").replace("px",""))||0),d=new Date().getTime()-((Q=q.current)==null?void 0:Q.getTime()),b=Y==="x"?r:m,I=Math.abs(b)/d;if(Math.abs(b)>=Pe||I>.11){j(U.current),(Z=t.onDismiss)==null||Z.call(t,t),J(Y==="x"?r>0?"right":"left":m>0?"down":"up"),$(),u(!0),y(!1);return}else(tt=N.current)==null||tt.style.setProperty("--swipe-amount-x","0px"),(Ot=N.current)==null||Ot.style.setProperty("--swipe-amount-y","0px");z(!1),k(null)},onPointerMove:r=>{var G,Q,Z,tt;if(!K.current||!V||((G=window.getSelection())==null?void 0:G.toString().length)>0)return;let d=r.clientY-K.current.y,b=r.clientX-K.current.x,I=(Q=s.swipeDirections)!=null?Q:Be(rt);!Y&&(Math.abs(b)>1||Math.abs(d)>1)&&k(Math.abs(b)>Math.abs(d)?"x":"y");let v={x:0,y:0};Y==="y"?(I.includes("top")||I.includes("bottom"))&&(I.includes("top")&&d<0||I.includes("bottom")&&d>0)&&(v.y=d):Y==="x"&&(I.includes("left")||I.includes("right"))&&(I.includes("left")&&b<0||I.includes("right")&&b>0)&&(v.x=b),(Math.abs(v.x)>0||Math.abs(v.y)>0)&&y(!0),(Z=N.current)==null||Z.style.setProperty("--swipe-amount-x",`${v.x}px`),(tt=N.current)==null||tt.style.setProperty("--swipe-amount-y",`${v.y}px`)}},te&&!t.jsx?o.default.createElement("button",{"aria-label":lt,"data-disabled":vt,"data-close-button":!0,onClick:vt||!V?()=>{}:()=>{var r;$(),(r=t.onDismiss)==null||r.call(t,t)},className:M(n==null?void 0:n.closeButton,(It=t==null?void 0:t.classNames)==null?void 0:It.closeButton)},(Mt=B==null?void 0:B.close)!=null?Mt:_t):null,C||t.icon||t.promise?o.default.createElement("div",{"data-icon":"",className:M(n==null?void 0:n.icon,(Ht=t==null?void 0:t.classNames)==null?void 0:Ht.icon)},t.promise||t.type==="loading"&&!t.icon?t.icon||se():null,t.type!=="loading"?t.icon||(B==null?void 0:B[C])||Ft(C):null):null,o.default.createElement("div",{"data-content":"",className:M(n==null?void 0:n.content,(At=t==null?void 0:t.classNames)==null?void 0:At.content)},o.default.createElement("div",{"data-title":"",className:M(n==null?void 0:n.title,(Lt=t==null?void 0:t.classNames)==null?void 0:Lt.title)},t.jsx?t.jsx:typeof t.title=="function"?t.title():t.title),t.description?o.default.createElement("div",{"data-description":"",className:M(nt,Zt,n==null?void 0:n.description,(zt=t==null?void 0:t.classNames)==null?void 0:zt.description)},typeof t.description=="function"?t.description():t.description):null),(0,o.isValidElement)(t.cancel)?t.cancel:t.cancel&&ot(t.cancel)?o.default.createElement("button",{"data-button":!0,"data-cancel":!0,style:t.cancelButtonStyle||ht,onClick:r=>{var m,d;ot(t.cancel)&&V&&((d=(m=t.cancel).onClick)==null||d.call(m,r),$())},className:M(n==null?void 0:n.cancelButton,(jt=t==null?void 0:t.classNames)==null?void 0:jt.cancelButton)},t.cancel.label):null,(0,o.isValidElement)(t.action)?t.action:t.action&&ot(t.action)?o.default.createElement("button",{"data-button":!0,"data-action":!0,style:t.actionButtonStyle||c,onClick:r=>{var m,d;ot(t.action)&&((d=(m=t.action).onClick)==null||d.call(m,r),!r.defaultPrevented&&$())},className:M(n==null?void 0:n.actionButton,(Yt=t==null?void 0:t.classNames)==null?void 0:Yt.actionButton)},t.action.label):null)};function Jt(){if(typeof window=="undefined"||typeof document=="undefined")return"ltr";let s=document.documentElement.getAttribute("dir");return s==="auto"||!s?window.getComputedStyle(document.documentElement).direction:s}function ke(s,e){let t={};return[s,e].forEach((a,l)=>{let f=l===1,x=f?"--mobile-offset":"--offset",R=f?Re:Se;function g(i){["top","right","bottom","left"].forEach(D=>{t[`${x}-${D}`]=typeof i=="number"?`${i}px`:i})}typeof a=="number"||typeof a=="string"?g(a):typeof a=="object"?["top","right","bottom","left"].forEach(i=>{a[i]===void 0?t[`${x}-${i}`]=R:t[`${x}-${i}`]=typeof a[i]=="number"?`${a[i]}px`:a[i]}):g(R)}),t}function Ie(){let[s,e]=o.default.useState([]);return o.default.useEffect(()=>T.subscribe(t=>{if(t.dismiss){setTimeout(()=>{mt.default.flushSync(()=>{e(a=>a.filter(l=>l.id!==t.id))})});return}setTimeout(()=>{mt.default.flushSync(()=>{e(a=>{let l=a.findIndex(f=>f.id===t.id);return l!==-1?[...a.slice(0,l),{...a[l],...t},...a.slice(l+1)]:[t,...a]})})})}),[]),{toasts:s}}var Me=(0,o.forwardRef)(function(e,t){let{invert:a,position:l="bottom-right",hotkey:f=["altKey","KeyT"],expand:x,closeButton:R,className:g,offset:i,mobileOffset:D,theme:w="light",richColors:F,duration:at,style:gt,visibleToasts:ht=we,toastOptions:c,dir:st=Jt(),gap:nt=De,loadingIcon:X,icons:rt,containerAriaLabel:bt="Notifications",pauseWhenPageIsHidden:it}=e,[P,n]=o.default.useState([]),B=o.default.useMemo(()=>Array.from(new Set([l].concat(P.filter(u=>u.position).map(u=>u.position)))),[P,l]),[lt,ct]=o.default.useState([]),[Y,k]=o.default.useState(!1),[dt,J]=o.default.useState(!1),[W,H]=o.default.useState(w!=="system"?w:typeof window!="undefined"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),A=o.default.useRef(null),yt=f.join("+").replace(/Key/g,"").replace(/Digit/g,""),L=o.default.useRef(null),z=o.default.useRef(!1),ut=o.default.useCallback(u=>{n(h=>{var y;return(y=h.find(E=>E.id===u.id))!=null&&y.delete||T.dismiss(u.id),h.filter(({id:E})=>E!==u.id)})},[]);return o.default.useEffect(()=>T.subscribe(u=>{if(u.dismiss){let h=P.map(y=>y.id===u.id?{...y,delete:!0}:y);n(h);return}setTimeout(()=>{mt.default.flushSync(()=>{n(h=>{let y=h.findIndex(E=>E.id===u.id);return y!==-1?[...h.slice(0,y),{...h[y],...u},...h.slice(y+1)]:[u,...h]})})})}),[P]),o.default.useEffect(()=>{if(w!=="system"){H(w);return}if(w==="system"&&(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?H("dark"):H("light")),typeof window=="undefined")return;let u=window.matchMedia("(prefers-color-scheme: dark)");try{u.addEventListener("change",({matches:h})=>{H(h?"dark":"light")})}catch(h){u.addListener(({matches:y})=>{try{H(y?"dark":"light")}catch(E){console.error(E)}})}},[w]),o.default.useEffect(()=>{P.length<=1&&k(!1)},[P]),o.default.useEffect(()=>{let u=h=>{var E,j;f.every(p=>h[p]||h.code===p)&&(k(!0),(E=A.current)==null||E.focus()),h.code==="Escape"&&(document.activeElement===A.current||(j=A.current)!=null&&j.contains(document.activeElement))&&k(!1)};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[f]),o.default.useEffect(()=>{if(A.current)return()=>{L.current&&(L.current.focus({preventScroll:!0}),L.current=null,z.current=!1)}},[A.current]),o.default.createElement("section",{ref:t,"aria-label":`${bt} ${yt}`,tabIndex:-1,"aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false",suppressHydrationWarning:!0},B.map((u,h)=>{var j;let[y,E]=u.split("-");return P.length?o.default.createElement("ol",{key:u,dir:st==="auto"?Jt():st,tabIndex:-1,ref:A,className:g,"data-sonner-toaster":!0,"data-sonner-theme":W,"data-y-position":y,"data-lifted":Y&&P.length>1&&!x,"data-x-position":E,style:{"--front-toast-height":`${((j=lt[0])==null?void 0:j.height)||0}px`,"--width":`${Ee}px`,"--gap":`${nt}px`,...gt,...ke(i,D)},onBlur:p=>{z.current&&!p.currentTarget.contains(p.relatedTarget)&&(z.current=!1,L.current&&(L.current.focus({preventScroll:!0}),L.current=null))},onFocus:p=>{p.target instanceof HTMLElement&&p.target.dataset.dismissible==="false"||z.current||(z.current=!0,L.current=p.relatedTarget)},onMouseEnter:()=>k(!0),onMouseMove:()=>k(!0),onMouseLeave:()=>{dt||k(!1)},onDragEnd:()=>k(!1),onPointerDown:p=>{p.target instanceof HTMLElement&&p.target.dataset.dismissible==="false"||J(!0)},onPointerUp:()=>J(!1)},P.filter(p=>!p.position&&h===0||p.position===u).map((p,_)=>{var O,q;return o.default.createElement(Ce,{key:p.id,icons:rt,index:_,toast:p,defaultRichColors:F,duration:(O=c==null?void 0:c.duration)!=null?O:at,className:c==null?void 0:c.className,descriptionClassName:c==null?void 0:c.descriptionClassName,invert:a,visibleToasts:ht,closeButton:(q=c==null?void 0:c.closeButton)!=null?q:R,interacting:dt,position:u,style:c==null?void 0:c.style,unstyled:c==null?void 0:c.unstyled,classNames:c==null?void 0:c.classNames,cancelButtonStyle:c==null?void 0:c.cancelButtonStyle,actionButtonStyle:c==null?void 0:c.actionButtonStyle,removeToast:ut,toasts:P.filter(N=>N.position==p.position),heights:lt.filter(N=>N.position==p.position),setHeights:ct,expandByDefault:x,gap:nt,loadingIcon:X,expanded:Y,pauseWhenPageIsHidden:it,swipeDirections:e.swipeDirections})})):null}))});0&&(module.exports={Toaster,toast,useSonner});
3
- //# sourceMappingURL=index.js.map
1
+ 'use client';
2
+ function __insertCSS(code) {
3
+ if (!code || typeof document == 'undefined') return
4
+ let head = document.head || document.getElementsByTagName('head')[0]
5
+ let style = document.createElement('style')
6
+ style.type = 'text/css'
7
+ head.appendChild(style)
8
+ ;style.styleSheet ? (style.styleSheet.cssText = code) : style.appendChild(document.createTextNode(code))
9
+ }
10
+
11
+ Object.defineProperty(exports, '__esModule', { value: true });
12
+
13
+ var React = require('react');
14
+ var ReactDOM = require('react-dom');
15
+
16
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
17
+
18
+ var React__default = /*#__PURE__*/_interopDefault(React);
19
+ var ReactDOM__default = /*#__PURE__*/_interopDefault(ReactDOM);
20
+
21
+ const getAsset = (type)=>{
22
+ switch(type){
23
+ case 'success':
24
+ return SuccessIcon;
25
+ case 'info':
26
+ return InfoIcon;
27
+ case 'warning':
28
+ return WarningIcon;
29
+ case 'error':
30
+ return ErrorIcon;
31
+ default:
32
+ return null;
33
+ }
34
+ };
35
+ const bars = Array(12).fill(0);
36
+ const Loader = ({ visible, className })=>{
37
+ return /*#__PURE__*/ React__default.default.createElement("div", {
38
+ className: [
39
+ 'sonner-loading-wrapper',
40
+ className
41
+ ].filter(Boolean).join(' '),
42
+ "data-visible": visible
43
+ }, /*#__PURE__*/ React__default.default.createElement("div", {
44
+ className: "sonner-spinner"
45
+ }, bars.map((_, i)=>/*#__PURE__*/ React__default.default.createElement("div", {
46
+ className: "sonner-loading-bar",
47
+ key: `spinner-bar-${i}`
48
+ }))));
49
+ };
50
+ const SuccessIcon = /*#__PURE__*/ React__default.default.createElement("svg", {
51
+ xmlns: "http://www.w3.org/2000/svg",
52
+ viewBox: "0 0 20 20",
53
+ fill: "currentColor",
54
+ height: "20",
55
+ width: "20"
56
+ }, /*#__PURE__*/ React__default.default.createElement("path", {
57
+ fillRule: "evenodd",
58
+ d: "M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",
59
+ clipRule: "evenodd"
60
+ }));
61
+ const WarningIcon = /*#__PURE__*/ React__default.default.createElement("svg", {
62
+ xmlns: "http://www.w3.org/2000/svg",
63
+ viewBox: "0 0 24 24",
64
+ fill: "currentColor",
65
+ height: "20",
66
+ width: "20"
67
+ }, /*#__PURE__*/ React__default.default.createElement("path", {
68
+ fillRule: "evenodd",
69
+ d: "M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z",
70
+ clipRule: "evenodd"
71
+ }));
72
+ const InfoIcon = /*#__PURE__*/ React__default.default.createElement("svg", {
73
+ xmlns: "http://www.w3.org/2000/svg",
74
+ viewBox: "0 0 20 20",
75
+ fill: "currentColor",
76
+ height: "20",
77
+ width: "20"
78
+ }, /*#__PURE__*/ React__default.default.createElement("path", {
79
+ fillRule: "evenodd",
80
+ d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",
81
+ clipRule: "evenodd"
82
+ }));
83
+ const ErrorIcon = /*#__PURE__*/ React__default.default.createElement("svg", {
84
+ xmlns: "http://www.w3.org/2000/svg",
85
+ viewBox: "0 0 20 20",
86
+ fill: "currentColor",
87
+ height: "20",
88
+ width: "20"
89
+ }, /*#__PURE__*/ React__default.default.createElement("path", {
90
+ fillRule: "evenodd",
91
+ d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",
92
+ clipRule: "evenodd"
93
+ }));
94
+ const CloseIcon = /*#__PURE__*/ React__default.default.createElement("svg", {
95
+ xmlns: "http://www.w3.org/2000/svg",
96
+ width: "12",
97
+ height: "12",
98
+ viewBox: "0 0 24 24",
99
+ fill: "none",
100
+ stroke: "currentColor",
101
+ strokeWidth: "1.5",
102
+ strokeLinecap: "round",
103
+ strokeLinejoin: "round"
104
+ }, /*#__PURE__*/ React__default.default.createElement("line", {
105
+ x1: "18",
106
+ y1: "6",
107
+ x2: "6",
108
+ y2: "18"
109
+ }), /*#__PURE__*/ React__default.default.createElement("line", {
110
+ x1: "6",
111
+ y1: "6",
112
+ x2: "18",
113
+ y2: "18"
114
+ }));
115
+
116
+ const useIsDocumentHidden = ()=>{
117
+ const [isDocumentHidden, setIsDocumentHidden] = React__default.default.useState(document.hidden);
118
+ React__default.default.useEffect(()=>{
119
+ const callback = ()=>{
120
+ setIsDocumentHidden(document.hidden);
121
+ };
122
+ document.addEventListener('visibilitychange', callback);
123
+ return ()=>window.removeEventListener('visibilitychange', callback);
124
+ }, []);
125
+ return isDocumentHidden;
126
+ };
127
+
128
+ let toastsCounter = 1;
129
+ class Observer {
130
+ constructor(){
131
+ // We use arrow functions to maintain the correct `this` reference
132
+ this.subscribe = (subscriber)=>{
133
+ this.subscribers.push(subscriber);
134
+ return ()=>{
135
+ const index = this.subscribers.indexOf(subscriber);
136
+ this.subscribers.splice(index, 1);
137
+ };
138
+ };
139
+ this.publish = (data)=>{
140
+ this.subscribers.forEach((subscriber)=>subscriber(data));
141
+ };
142
+ this.addToast = (data)=>{
143
+ this.publish(data);
144
+ this.toasts = [
145
+ ...this.toasts,
146
+ data
147
+ ];
148
+ };
149
+ this.create = (data)=>{
150
+ var _data_id;
151
+ const { message, ...rest } = data;
152
+ const id = typeof (data == null ? void 0 : data.id) === 'number' || ((_data_id = data.id) == null ? void 0 : _data_id.length) > 0 ? data.id : toastsCounter++;
153
+ const alreadyExists = this.toasts.find((toast)=>{
154
+ return toast.id === id;
155
+ });
156
+ const dismissible = data.dismissible === undefined ? true : data.dismissible;
157
+ if (this.dismissedToasts.has(id)) {
158
+ this.dismissedToasts.delete(id);
159
+ }
160
+ if (alreadyExists) {
161
+ this.toasts = this.toasts.map((toast)=>{
162
+ if (toast.id === id) {
163
+ this.publish({
164
+ ...toast,
165
+ ...data,
166
+ id,
167
+ title: message
168
+ });
169
+ return {
170
+ ...toast,
171
+ ...data,
172
+ id,
173
+ dismissible,
174
+ title: message
175
+ };
176
+ }
177
+ return toast;
178
+ });
179
+ } else {
180
+ this.addToast({
181
+ title: message,
182
+ ...rest,
183
+ dismissible,
184
+ id
185
+ });
186
+ }
187
+ return id;
188
+ };
189
+ this.dismiss = (id)=>{
190
+ this.dismissedToasts.add(id);
191
+ if (!id) {
192
+ this.toasts.forEach((toast)=>{
193
+ this.subscribers.forEach((subscriber)=>subscriber({
194
+ id: toast.id,
195
+ dismiss: true
196
+ }));
197
+ });
198
+ }
199
+ requestAnimationFrame(()=>this.subscribers.forEach((subscriber)=>subscriber({
200
+ id,
201
+ dismiss: true
202
+ })));
203
+ return id;
204
+ };
205
+ this.message = (message, data)=>{
206
+ return this.create({
207
+ ...data,
208
+ message
209
+ });
210
+ };
211
+ this.error = (message, data)=>{
212
+ return this.create({
213
+ ...data,
214
+ message,
215
+ type: 'error'
216
+ });
217
+ };
218
+ this.success = (message, data)=>{
219
+ return this.create({
220
+ ...data,
221
+ type: 'success',
222
+ message
223
+ });
224
+ };
225
+ this.info = (message, data)=>{
226
+ return this.create({
227
+ ...data,
228
+ type: 'info',
229
+ message
230
+ });
231
+ };
232
+ this.warning = (message, data)=>{
233
+ return this.create({
234
+ ...data,
235
+ type: 'warning',
236
+ message
237
+ });
238
+ };
239
+ this.loading = (message, data)=>{
240
+ return this.create({
241
+ ...data,
242
+ type: 'loading',
243
+ message
244
+ });
245
+ };
246
+ this.promise = (promise, data)=>{
247
+ if (!data) {
248
+ // Nothing to show
249
+ return;
250
+ }
251
+ let id = undefined;
252
+ if (data.loading !== undefined) {
253
+ id = this.create({
254
+ ...data,
255
+ promise,
256
+ type: 'loading',
257
+ message: data.loading,
258
+ description: typeof data.description !== 'function' ? data.description : undefined
259
+ });
260
+ }
261
+ const p = Promise.resolve(promise instanceof Function ? promise() : promise);
262
+ let shouldDismiss = id !== undefined;
263
+ let result;
264
+ const originalPromise = p.then(async (response)=>{
265
+ result = [
266
+ 'resolve',
267
+ response
268
+ ];
269
+ const isReactElementResponse = React__default.default.isValidElement(response);
270
+ if (isReactElementResponse) {
271
+ shouldDismiss = false;
272
+ this.create({
273
+ id,
274
+ type: 'default',
275
+ message: response
276
+ });
277
+ } else if (isHttpResponse(response) && !response.ok) {
278
+ shouldDismiss = false;
279
+ const promiseData = typeof data.error === 'function' ? await data.error(`HTTP error! status: ${response.status}`) : data.error;
280
+ const description = typeof data.description === 'function' ? await data.description(`HTTP error! status: ${response.status}`) : data.description;
281
+ const toastSettings = typeof promiseData === 'object' ? promiseData : {
282
+ message: promiseData
283
+ };
284
+ this.create({
285
+ id,
286
+ type: 'error',
287
+ description,
288
+ ...toastSettings
289
+ });
290
+ } else if (response instanceof Error) {
291
+ shouldDismiss = false;
292
+ const promiseData = typeof data.error === 'function' ? await data.error(response) : data.error;
293
+ const description = typeof data.description === 'function' ? await data.description(response) : data.description;
294
+ const toastSettings = typeof promiseData === 'object' ? promiseData : {
295
+ message: promiseData
296
+ };
297
+ this.create({
298
+ id,
299
+ type: 'error',
300
+ description,
301
+ ...toastSettings
302
+ });
303
+ } else if (data.success !== undefined) {
304
+ shouldDismiss = false;
305
+ const promiseData = typeof data.success === 'function' ? await data.success(response) : data.success;
306
+ const description = typeof data.description === 'function' ? await data.description(response) : data.description;
307
+ const toastSettings = typeof promiseData === 'object' ? promiseData : {
308
+ message: promiseData
309
+ };
310
+ this.create({
311
+ id,
312
+ type: 'success',
313
+ description,
314
+ ...toastSettings
315
+ });
316
+ }
317
+ }).catch(async (error)=>{
318
+ result = [
319
+ 'reject',
320
+ error
321
+ ];
322
+ if (data.error !== undefined) {
323
+ shouldDismiss = false;
324
+ const promiseData = typeof data.error === 'function' ? await data.error(error) : data.error;
325
+ const description = typeof data.description === 'function' ? await data.description(error) : data.description;
326
+ const toastSettings = typeof promiseData === 'object' ? promiseData : {
327
+ message: promiseData
328
+ };
329
+ this.create({
330
+ id,
331
+ type: 'error',
332
+ description,
333
+ ...toastSettings
334
+ });
335
+ }
336
+ }).finally(()=>{
337
+ if (shouldDismiss) {
338
+ // Toast is still in load state (and will be indefinitely — dismiss it)
339
+ this.dismiss(id);
340
+ id = undefined;
341
+ }
342
+ data.finally == null ? void 0 : data.finally.call(data);
343
+ });
344
+ const unwrap = ()=>new Promise((resolve, reject)=>originalPromise.then(()=>result[0] === 'reject' ? reject(result[1]) : resolve(result[1])).catch(reject));
345
+ if (typeof id !== 'string' && typeof id !== 'number') {
346
+ // cannot Object.assign on undefined
347
+ return {
348
+ unwrap
349
+ };
350
+ } else {
351
+ return Object.assign(id, {
352
+ unwrap
353
+ });
354
+ }
355
+ };
356
+ this.custom = (jsx, data)=>{
357
+ const id = (data == null ? void 0 : data.id) || toastsCounter++;
358
+ this.create({
359
+ jsx: jsx(id),
360
+ id,
361
+ ...data
362
+ });
363
+ return id;
364
+ };
365
+ this.getActiveToasts = ()=>{
366
+ return this.toasts.filter((toast)=>!this.dismissedToasts.has(toast.id));
367
+ };
368
+ this.subscribers = [];
369
+ this.toasts = [];
370
+ this.dismissedToasts = new Set();
371
+ }
372
+ }
373
+ const ToastState = new Observer();
374
+ // bind this to the toast function
375
+ const toastFunction = (message, data)=>{
376
+ const id = (data == null ? void 0 : data.id) || toastsCounter++;
377
+ ToastState.addToast({
378
+ title: message,
379
+ ...data,
380
+ id
381
+ });
382
+ return id;
383
+ };
384
+ const isHttpResponse = (data)=>{
385
+ return data && typeof data === 'object' && 'ok' in data && typeof data.ok === 'boolean' && 'status' in data && typeof data.status === 'number';
386
+ };
387
+ const basicToast = toastFunction;
388
+ const getHistory = ()=>ToastState.toasts;
389
+ const getToasts = ()=>ToastState.getActiveToasts();
390
+ // We use `Object.assign` to maintain the correct types as we would lose them otherwise
391
+ const toast = Object.assign(basicToast, {
392
+ success: ToastState.success,
393
+ info: ToastState.info,
394
+ warning: ToastState.warning,
395
+ error: ToastState.error,
396
+ custom: ToastState.custom,
397
+ message: ToastState.message,
398
+ promise: ToastState.promise,
399
+ dismiss: ToastState.dismiss,
400
+ loading: ToastState.loading
401
+ }, {
402
+ getHistory,
403
+ getToasts
404
+ });
405
+
406
+ __insertCSS("[data-sonner-toaster][dir=ltr],html[dir=ltr]{--toast-icon-margin-start:-3px;--toast-icon-margin-end:4px;--toast-svg-margin-start:-1px;--toast-svg-margin-end:0px;--toast-button-margin-start:auto;--toast-button-margin-end:0;--toast-close-button-start:0;--toast-close-button-end:unset;--toast-close-button-transform:translate(-35%, -35%)}[data-sonner-toaster][dir=rtl],html[dir=rtl]{--toast-icon-margin-start:4px;--toast-icon-margin-end:-3px;--toast-svg-margin-start:0px;--toast-svg-margin-end:-1px;--toast-button-margin-start:0;--toast-button-margin-end:auto;--toast-close-button-start:unset;--toast-close-button-end:0;--toast-close-button-transform:translate(35%, -35%)}[data-sonner-toaster]{position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1:hsl(0, 0%, 99%);--gray2:hsl(0, 0%, 97.3%);--gray3:hsl(0, 0%, 95.1%);--gray4:hsl(0, 0%, 93%);--gray5:hsl(0, 0%, 90.9%);--gray6:hsl(0, 0%, 88.7%);--gray7:hsl(0, 0%, 85.8%);--gray8:hsl(0, 0%, 78%);--gray9:hsl(0, 0%, 56.1%);--gray10:hsl(0, 0%, 52.3%);--gray11:hsl(0, 0%, 43.5%);--gray12:hsl(0, 0%, 9%);--border-radius:8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:0;z-index:999999999;transition:transform .4s ease}[data-sonner-toaster][data-lifted=true]{transform:translateY(-8px)}@media (hover:none) and (pointer:coarse){[data-sonner-toaster][data-lifted=true]{transform:none}}[data-sonner-toaster][data-x-position=right]{right:var(--offset-right)}[data-sonner-toaster][data-x-position=left]{left:var(--offset-left)}[data-sonner-toaster][data-x-position=center]{left:50%;transform:translateX(-50%)}[data-sonner-toaster][data-y-position=top]{top:var(--offset-top)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--offset-bottom)}[data-sonner-toast]{--y:translateY(100%);--lift-amount:calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:0;overflow-wrap:anywhere}[data-sonner-toast][data-styled=true]{padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px rgba(0,0,0,.1);width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}[data-sonner-toast]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-y-position=top]{top:0;--y:translateY(-100%);--lift:1;--lift-amount:calc(1 * var(--gap))}[data-sonner-toast][data-y-position=bottom]{bottom:0;--y:translateY(100%);--lift:-1;--lift-amount:calc(var(--lift) * var(--gap))}[data-sonner-toast][data-styled=true] [data-description]{font-weight:400;line-height:1.4;color:#3f3f3f}[data-sonner-toaster][data-sonner-theme=dark] [data-description]{color:#e8e8e8}[data-sonner-toast][data-styled=true] [data-title]{font-weight:500;line-height:1.5;color:inherit}[data-sonner-toast][data-styled=true] [data-icon]{display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}[data-sonner-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}[data-sonner-toast][data-styled=true] [data-icon]>*{flex-shrink:0}[data-sonner-toast][data-styled=true] [data-icon] svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}[data-sonner-toast][data-styled=true] [data-content]{display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;font-weight:500;cursor:pointer;outline:0;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}[data-sonner-toast][data-styled=true] [data-button]:focus-visible{box-shadow:0 0 0 2px rgba(0,0,0,.4)}[data-sonner-toast][data-styled=true] [data-button]:first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}[data-sonner-toast][data-styled=true] [data-cancel]{color:var(--normal-text);background:rgba(0,0,0,.08)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-styled=true] [data-cancel]{background:rgba(255,255,255,.3)}[data-sonner-toast][data-styled=true] [data-close-button]{position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);background:var(--normal-bg);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast][data-styled=true] [data-close-button]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-styled=true] [data-disabled=true]{cursor:not-allowed}[data-sonner-toast][data-styled=true]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-sonner-toast][data-swiping=true]::before{content:'';position:absolute;left:-100%;right:-100%;height:100%;z-index:-1}[data-sonner-toast][data-y-position=top][data-swiping=true]::before{bottom:50%;transform:scaleY(3) translateY(50%)}[data-sonner-toast][data-y-position=bottom][data-swiping=true]::before{top:50%;transform:scaleY(3) translateY(-50%)}[data-sonner-toast][data-swiping=false][data-removed=true]::before{content:'';position:absolute;inset:0;transform:scaleY(2)}[data-sonner-toast]::after{content:'';position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-sonner-toast][data-mounted=true]{--y:translateY(0);opacity:1}[data-sonner-toast][data-expanded=false][data-front=false]{--scale:var(--toasts-before) * 0.05 + 1;--y:translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-sonner-toast]>*{transition:opacity .4s}[data-sonner-toast][data-x-position=right]{right:0}[data-sonner-toast][data-x-position=left]{left:0}[data-sonner-toast][data-expanded=false][data-front=false][data-styled=true]>*{opacity:0}[data-sonner-toast][data-visible=false]{opacity:0;pointer-events:none}[data-sonner-toast][data-mounted=true][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y:translateY(calc(var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]{--y:translateY(40%);opacity:0;transition:transform .5s,opacity .2s}[data-sonner-toast][data-removed=true][data-front=false]::before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y,0)) translateX(var(--swipe-amount-x,0));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width:600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-sonner-theme=light]{--normal-bg:#fff;--normal-border:var(--gray4);--normal-text:var(--gray12);--success-bg:hsl(143, 85%, 96%);--success-border:hsl(145, 92%, 87%);--success-text:hsl(140, 100%, 27%);--info-bg:hsl(208, 100%, 97%);--info-border:hsl(221, 91%, 93%);--info-text:hsl(210, 92%, 45%);--warning-bg:hsl(49, 100%, 97%);--warning-border:hsl(49, 91%, 84%);--warning-text:hsl(31, 92%, 45%);--error-bg:hsl(359, 100%, 97%);--error-border:hsl(359, 100%, 94%);--error-text:hsl(360, 100%, 45%)}[data-sonner-toaster][data-sonner-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg:#000;--normal-border:hsl(0, 0%, 20%);--normal-text:var(--gray1)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg:#fff;--normal-border:var(--gray3);--normal-text:var(--gray12)}[data-sonner-toaster][data-sonner-theme=dark]{--normal-bg:#000;--normal-bg-hover:hsl(0, 0%, 12%);--normal-border:hsl(0, 0%, 20%);--normal-border-hover:hsl(0, 0%, 25%);--normal-text:var(--gray1);--success-bg:hsl(150, 100%, 6%);--success-border:hsl(147, 100%, 12%);--success-text:hsl(150, 86%, 65%);--info-bg:hsl(215, 100%, 6%);--info-border:hsl(223, 43%, 17%);--info-text:hsl(216, 87%, 65%);--warning-bg:hsl(64, 100%, 6%);--warning-border:hsl(60, 100%, 9%);--warning-text:hsl(46, 87%, 65%);--error-bg:hsl(358, 76%, 10%);--error-border:hsl(357, 89%, 16%);--error-text:hsl(358, 100%, 81%)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size:16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:first-child{animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}100%{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}100%{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}100%{opacity:.15}}@media (prefers-reduced-motion){.sonner-loading-bar,[data-sonner-toast],[data-sonner-toast]>*{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)}");
407
+
408
+ function isAction(action) {
409
+ return action.label !== undefined;
410
+ }
411
+
412
+ // Visible toasts amount
413
+ const VISIBLE_TOASTS_AMOUNT = 3;
414
+ // Viewport padding
415
+ const VIEWPORT_OFFSET = '24px';
416
+ // Mobile viewport padding
417
+ const MOBILE_VIEWPORT_OFFSET = '16px';
418
+ // Default lifetime of a toasts (in ms)
419
+ const TOAST_LIFETIME = 4000;
420
+ // Default toast width
421
+ const TOAST_WIDTH = 356;
422
+ // Default gap between toasts
423
+ const GAP = 14;
424
+ // Threshold to dismiss a toast
425
+ const SWIPE_THRESHOLD = 45;
426
+ // Equal to exit animation duration
427
+ const TIME_BEFORE_UNMOUNT = 200;
428
+ function cn(...classes) {
429
+ return classes.filter(Boolean).join(' ');
430
+ }
431
+ function getDefaultSwipeDirections(position) {
432
+ const [y, x] = position.split('-');
433
+ const directions = [];
434
+ if (y) {
435
+ directions.push(y);
436
+ }
437
+ if (x) {
438
+ directions.push(x);
439
+ }
440
+ return directions;
441
+ }
442
+ const Toast = (props)=>{
443
+ var _toast_classNames, _toast_classNames1, _toast_classNames2, _toast_classNames3, _toast_classNames4, _toast_classNames5, _toast_classNames6, _toast_classNames7, _toast_classNames8;
444
+ const { invert: ToasterInvert, toast, unstyled, interacting, setHeights, visibleToasts, heights, index, toasts, expanded, removeToast, defaultRichColors, closeButton: closeButtonFromToaster, style, cancelButtonStyle, actionButtonStyle, className = '', descriptionClassName = '', duration: durationFromToaster, position, gap, expandByDefault, classNames, icons, closeButtonAriaLabel = 'Close toast' } = props;
445
+ const [swipeDirection, setSwipeDirection] = React__default.default.useState(null);
446
+ const [swipeOutDirection, setSwipeOutDirection] = React__default.default.useState(null);
447
+ const [mounted, setMounted] = React__default.default.useState(false);
448
+ const [removed, setRemoved] = React__default.default.useState(false);
449
+ const [swiping, setSwiping] = React__default.default.useState(false);
450
+ const [swipeOut, setSwipeOut] = React__default.default.useState(false);
451
+ const [isSwiped, setIsSwiped] = React__default.default.useState(false);
452
+ const [offsetBeforeRemove, setOffsetBeforeRemove] = React__default.default.useState(0);
453
+ const [initialHeight, setInitialHeight] = React__default.default.useState(0);
454
+ const remainingTime = React__default.default.useRef(toast.duration || durationFromToaster || TOAST_LIFETIME);
455
+ const dragStartTime = React__default.default.useRef(null);
456
+ const toastRef = React__default.default.useRef(null);
457
+ const isFront = index === 0;
458
+ const isVisible = index + 1 <= visibleToasts;
459
+ const toastType = toast.type;
460
+ const dismissible = toast.dismissible !== false;
461
+ const toastClassname = toast.className || '';
462
+ const toastDescriptionClassname = toast.descriptionClassName || '';
463
+ // Height index is used to calculate the offset as it gets updated before the toast array, which means we can calculate the new layout faster.
464
+ const heightIndex = React__default.default.useMemo(()=>heights.findIndex((height)=>height.toastId === toast.id) || 0, [
465
+ heights,
466
+ toast.id
467
+ ]);
468
+ const closeButton = React__default.default.useMemo(()=>{
469
+ var _toast_closeButton;
470
+ return (_toast_closeButton = toast.closeButton) != null ? _toast_closeButton : closeButtonFromToaster;
471
+ }, [
472
+ toast.closeButton,
473
+ closeButtonFromToaster
474
+ ]);
475
+ const duration = React__default.default.useMemo(()=>toast.duration || durationFromToaster || TOAST_LIFETIME, [
476
+ toast.duration,
477
+ durationFromToaster
478
+ ]);
479
+ const closeTimerStartTimeRef = React__default.default.useRef(0);
480
+ const offset = React__default.default.useRef(0);
481
+ const lastCloseTimerStartTimeRef = React__default.default.useRef(0);
482
+ const pointerStartRef = React__default.default.useRef(null);
483
+ const [y, x] = position.split('-');
484
+ const toastsHeightBefore = React__default.default.useMemo(()=>{
485
+ return heights.reduce((prev, curr, reducerIndex)=>{
486
+ // Calculate offset up until current toast
487
+ if (reducerIndex >= heightIndex) {
488
+ return prev;
489
+ }
490
+ return prev + curr.height;
491
+ }, 0);
492
+ }, [
493
+ heights,
494
+ heightIndex
495
+ ]);
496
+ const isDocumentHidden = useIsDocumentHidden();
497
+ const invert = toast.invert || ToasterInvert;
498
+ const disabled = toastType === 'loading';
499
+ offset.current = React__default.default.useMemo(()=>heightIndex * gap + toastsHeightBefore, [
500
+ heightIndex,
501
+ toastsHeightBefore
502
+ ]);
503
+ React__default.default.useEffect(()=>{
504
+ remainingTime.current = duration;
505
+ }, [
506
+ duration
507
+ ]);
508
+ React__default.default.useEffect(()=>{
509
+ // Trigger enter animation without using CSS animation
510
+ setMounted(true);
511
+ }, []);
512
+ React__default.default.useEffect(()=>{
513
+ const toastNode = toastRef.current;
514
+ if (toastNode) {
515
+ const height = toastNode.getBoundingClientRect().height;
516
+ // Add toast height to heights array after the toast is mounted
517
+ setInitialHeight(height);
518
+ setHeights((h)=>[
519
+ {
520
+ toastId: toast.id,
521
+ height,
522
+ position: toast.position
523
+ },
524
+ ...h
525
+ ]);
526
+ return ()=>setHeights((h)=>h.filter((height)=>height.toastId !== toast.id));
527
+ }
528
+ }, [
529
+ setHeights,
530
+ toast.id
531
+ ]);
532
+ React__default.default.useLayoutEffect(()=>{
533
+ if (!mounted) return;
534
+ const toastNode = toastRef.current;
535
+ const originalHeight = toastNode.style.height;
536
+ toastNode.style.height = 'auto';
537
+ const newHeight = toastNode.getBoundingClientRect().height;
538
+ toastNode.style.height = originalHeight;
539
+ setInitialHeight(newHeight);
540
+ setHeights((heights)=>{
541
+ const alreadyExists = heights.find((height)=>height.toastId === toast.id);
542
+ if (!alreadyExists) {
543
+ return [
544
+ {
545
+ toastId: toast.id,
546
+ height: newHeight,
547
+ position: toast.position
548
+ },
549
+ ...heights
550
+ ];
551
+ } else {
552
+ return heights.map((height)=>height.toastId === toast.id ? {
553
+ ...height,
554
+ height: newHeight
555
+ } : height);
556
+ }
557
+ });
558
+ }, [
559
+ mounted,
560
+ toast.title,
561
+ toast.description,
562
+ setHeights,
563
+ toast.id
564
+ ]);
565
+ const deleteToast = React__default.default.useCallback(()=>{
566
+ // Save the offset for the exit swipe animation
567
+ setRemoved(true);
568
+ setOffsetBeforeRemove(offset.current);
569
+ setHeights((h)=>h.filter((height)=>height.toastId !== toast.id));
570
+ setTimeout(()=>{
571
+ removeToast(toast);
572
+ }, TIME_BEFORE_UNMOUNT);
573
+ }, [
574
+ toast,
575
+ removeToast,
576
+ setHeights,
577
+ offset
578
+ ]);
579
+ React__default.default.useEffect(()=>{
580
+ if (toast.promise && toastType === 'loading' || toast.duration === Infinity || toast.type === 'loading') return;
581
+ let timeoutId;
582
+ // Pause the timer on each hover
583
+ const pauseTimer = ()=>{
584
+ if (lastCloseTimerStartTimeRef.current < closeTimerStartTimeRef.current) {
585
+ // Get the elapsed time since the timer started
586
+ const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.current;
587
+ remainingTime.current = remainingTime.current - elapsedTime;
588
+ }
589
+ lastCloseTimerStartTimeRef.current = new Date().getTime();
590
+ };
591
+ const startTimer = ()=>{
592
+ // setTimeout(, Infinity) behaves as if the delay is 0.
593
+ // As a result, the toast would be closed immediately, giving the appearance that it was never rendered.
594
+ // See: https://github.com/denysdovhan/wtfjs?tab=readme-ov-file#an-infinite-timeout
595
+ if (remainingTime.current === Infinity) return;
596
+ closeTimerStartTimeRef.current = new Date().getTime();
597
+ // Let the toast know it has started
598
+ timeoutId = setTimeout(()=>{
599
+ toast.onAutoClose == null ? void 0 : toast.onAutoClose.call(toast, toast);
600
+ deleteToast();
601
+ }, remainingTime.current);
602
+ };
603
+ if (expanded || interacting || isDocumentHidden) {
604
+ pauseTimer();
605
+ } else {
606
+ startTimer();
607
+ }
608
+ return ()=>clearTimeout(timeoutId);
609
+ }, [
610
+ expanded,
611
+ interacting,
612
+ toast,
613
+ toastType,
614
+ isDocumentHidden,
615
+ deleteToast
616
+ ]);
617
+ React__default.default.useEffect(()=>{
618
+ if (toast.delete) {
619
+ deleteToast();
620
+ }
621
+ }, [
622
+ deleteToast,
623
+ toast.delete
624
+ ]);
625
+ function getLoadingIcon() {
626
+ var _toast_classNames;
627
+ if (icons == null ? void 0 : icons.loading) {
628
+ var _toast_classNames1;
629
+ return /*#__PURE__*/ React__default.default.createElement("div", {
630
+ className: cn(classNames == null ? void 0 : classNames.loader, toast == null ? void 0 : (_toast_classNames1 = toast.classNames) == null ? void 0 : _toast_classNames1.loader, 'sonner-loader'),
631
+ "data-visible": toastType === 'loading'
632
+ }, icons.loading);
633
+ }
634
+ return /*#__PURE__*/ React__default.default.createElement(Loader, {
635
+ className: cn(classNames == null ? void 0 : classNames.loader, toast == null ? void 0 : (_toast_classNames = toast.classNames) == null ? void 0 : _toast_classNames.loader),
636
+ visible: toastType === 'loading'
637
+ });
638
+ }
639
+ var _toast_richColors, _icons_close;
640
+ return /*#__PURE__*/ React__default.default.createElement("li", {
641
+ tabIndex: 0,
642
+ ref: toastRef,
643
+ className: cn(className, toastClassname, classNames == null ? void 0 : classNames.toast, toast == null ? void 0 : (_toast_classNames = toast.classNames) == null ? void 0 : _toast_classNames.toast, classNames == null ? void 0 : classNames.default, classNames == null ? void 0 : classNames[toastType], toast == null ? void 0 : (_toast_classNames1 = toast.classNames) == null ? void 0 : _toast_classNames1[toastType]),
644
+ "data-sonner-toast": "",
645
+ "data-rich-colors": (_toast_richColors = toast.richColors) != null ? _toast_richColors : defaultRichColors,
646
+ "data-styled": !Boolean(toast.jsx || toast.unstyled || unstyled),
647
+ "data-mounted": mounted,
648
+ "data-promise": Boolean(toast.promise),
649
+ "data-swiped": isSwiped,
650
+ "data-removed": removed,
651
+ "data-visible": isVisible,
652
+ "data-y-position": y,
653
+ "data-x-position": x,
654
+ "data-index": index,
655
+ "data-front": isFront,
656
+ "data-swiping": swiping,
657
+ "data-dismissible": dismissible,
658
+ "data-type": toastType,
659
+ "data-invert": invert,
660
+ "data-swipe-out": swipeOut,
661
+ "data-swipe-direction": swipeOutDirection,
662
+ "data-expanded": Boolean(expanded || expandByDefault && mounted),
663
+ style: {
664
+ '--index': index,
665
+ '--toasts-before': index,
666
+ '--z-index': toasts.length - index,
667
+ '--offset': `${removed ? offsetBeforeRemove : offset.current}px`,
668
+ '--initial-height': expandByDefault ? 'auto' : `${initialHeight}px`,
669
+ ...style,
670
+ ...toast.style
671
+ },
672
+ onDragEnd: ()=>{
673
+ setSwiping(false);
674
+ setSwipeDirection(null);
675
+ pointerStartRef.current = null;
676
+ },
677
+ onPointerDown: (event)=>{
678
+ if (disabled || !dismissible) return;
679
+ dragStartTime.current = new Date();
680
+ setOffsetBeforeRemove(offset.current);
681
+ // Ensure we maintain correct pointer capture even when going outside of the toast (e.g. when swiping)
682
+ event.target.setPointerCapture(event.pointerId);
683
+ if (event.target.tagName === 'BUTTON') return;
684
+ setSwiping(true);
685
+ pointerStartRef.current = {
686
+ x: event.clientX,
687
+ y: event.clientY
688
+ };
689
+ },
690
+ onPointerUp: ()=>{
691
+ var _toastRef_current, _toastRef_current1, _dragStartTime_current;
692
+ if (swipeOut || !dismissible) return;
693
+ pointerStartRef.current = null;
694
+ const swipeAmountX = Number(((_toastRef_current = toastRef.current) == null ? void 0 : _toastRef_current.style.getPropertyValue('--swipe-amount-x').replace('px', '')) || 0);
695
+ const swipeAmountY = Number(((_toastRef_current1 = toastRef.current) == null ? void 0 : _toastRef_current1.style.getPropertyValue('--swipe-amount-y').replace('px', '')) || 0);
696
+ const timeTaken = new Date().getTime() - ((_dragStartTime_current = dragStartTime.current) == null ? void 0 : _dragStartTime_current.getTime());
697
+ const swipeAmount = swipeDirection === 'x' ? swipeAmountX : swipeAmountY;
698
+ const velocity = Math.abs(swipeAmount) / timeTaken;
699
+ if (Math.abs(swipeAmount) >= SWIPE_THRESHOLD || velocity > 0.11) {
700
+ setOffsetBeforeRemove(offset.current);
701
+ toast.onDismiss == null ? void 0 : toast.onDismiss.call(toast, toast);
702
+ if (swipeDirection === 'x') {
703
+ setSwipeOutDirection(swipeAmountX > 0 ? 'right' : 'left');
704
+ } else {
705
+ setSwipeOutDirection(swipeAmountY > 0 ? 'down' : 'up');
706
+ }
707
+ deleteToast();
708
+ setSwipeOut(true);
709
+ setIsSwiped(false);
710
+ return;
711
+ } else {
712
+ var _toastRef_current2, _toastRef_current3;
713
+ (_toastRef_current2 = toastRef.current) == null ? void 0 : _toastRef_current2.style.setProperty('--swipe-amount-x', `0px`);
714
+ (_toastRef_current3 = toastRef.current) == null ? void 0 : _toastRef_current3.style.setProperty('--swipe-amount-y', `0px`);
715
+ }
716
+ setSwiping(false);
717
+ setSwipeDirection(null);
718
+ },
719
+ onPointerMove: (event)=>{
720
+ var _window_getSelection, // Apply transform using both x and y values
721
+ _toastRef_current, _toastRef_current1;
722
+ if (!pointerStartRef.current || !dismissible) return;
723
+ const isHighlighted = ((_window_getSelection = window.getSelection()) == null ? void 0 : _window_getSelection.toString().length) > 0;
724
+ if (isHighlighted) return;
725
+ const yDelta = event.clientY - pointerStartRef.current.y;
726
+ const xDelta = event.clientX - pointerStartRef.current.x;
727
+ var _props_swipeDirections;
728
+ const swipeDirections = (_props_swipeDirections = props.swipeDirections) != null ? _props_swipeDirections : getDefaultSwipeDirections(position);
729
+ // Determine swipe direction if not already locked
730
+ if (!swipeDirection && (Math.abs(xDelta) > 1 || Math.abs(yDelta) > 1)) {
731
+ setSwipeDirection(Math.abs(xDelta) > Math.abs(yDelta) ? 'x' : 'y');
732
+ }
733
+ let swipeAmount = {
734
+ x: 0,
735
+ y: 0
736
+ };
737
+ const getDampening = (delta)=>{
738
+ const factor = Math.abs(delta) / 20;
739
+ return 1 / (1.5 + factor);
740
+ };
741
+ // Only apply swipe in the locked direction
742
+ if (swipeDirection === 'y') {
743
+ // Handle vertical swipes
744
+ if (swipeDirections.includes('top') || swipeDirections.includes('bottom')) {
745
+ if (swipeDirections.includes('top') && yDelta < 0 || swipeDirections.includes('bottom') && yDelta > 0) {
746
+ swipeAmount.y = yDelta;
747
+ } else {
748
+ // Smoothly transition to dampened movement
749
+ const dampenedDelta = yDelta * getDampening(yDelta);
750
+ // Ensure we don't jump when transitioning to dampened movement
751
+ swipeAmount.y = Math.abs(dampenedDelta) < Math.abs(yDelta) ? dampenedDelta : yDelta;
752
+ }
753
+ }
754
+ } else if (swipeDirection === 'x') {
755
+ // Handle horizontal swipes
756
+ if (swipeDirections.includes('left') || swipeDirections.includes('right')) {
757
+ if (swipeDirections.includes('left') && xDelta < 0 || swipeDirections.includes('right') && xDelta > 0) {
758
+ swipeAmount.x = xDelta;
759
+ } else {
760
+ // Smoothly transition to dampened movement
761
+ const dampenedDelta = xDelta * getDampening(xDelta);
762
+ // Ensure we don't jump when transitioning to dampened movement
763
+ swipeAmount.x = Math.abs(dampenedDelta) < Math.abs(xDelta) ? dampenedDelta : xDelta;
764
+ }
765
+ }
766
+ }
767
+ if (Math.abs(swipeAmount.x) > 0 || Math.abs(swipeAmount.y) > 0) {
768
+ setIsSwiped(true);
769
+ }
770
+ (_toastRef_current = toastRef.current) == null ? void 0 : _toastRef_current.style.setProperty('--swipe-amount-x', `${swipeAmount.x}px`);
771
+ (_toastRef_current1 = toastRef.current) == null ? void 0 : _toastRef_current1.style.setProperty('--swipe-amount-y', `${swipeAmount.y}px`);
772
+ }
773
+ }, closeButton && !toast.jsx && toastType !== 'loading' ? /*#__PURE__*/ React__default.default.createElement("button", {
774
+ "aria-label": closeButtonAriaLabel,
775
+ "data-disabled": disabled,
776
+ "data-close-button": true,
777
+ onClick: disabled || !dismissible ? ()=>{} : ()=>{
778
+ deleteToast();
779
+ toast.onDismiss == null ? void 0 : toast.onDismiss.call(toast, toast);
780
+ },
781
+ className: cn(classNames == null ? void 0 : classNames.closeButton, toast == null ? void 0 : (_toast_classNames2 = toast.classNames) == null ? void 0 : _toast_classNames2.closeButton)
782
+ }, (_icons_close = icons == null ? void 0 : icons.close) != null ? _icons_close : CloseIcon) : null, toastType || toast.icon || toast.promise ? /*#__PURE__*/ React__default.default.createElement("div", {
783
+ "data-icon": "",
784
+ className: cn(classNames == null ? void 0 : classNames.icon, toast == null ? void 0 : (_toast_classNames3 = toast.classNames) == null ? void 0 : _toast_classNames3.icon)
785
+ }, toast.promise || toast.type === 'loading' && !toast.icon ? toast.icon || getLoadingIcon() : null, toast.type !== 'loading' ? toast.icon || (icons == null ? void 0 : icons[toastType]) || getAsset(toastType) : null) : null, /*#__PURE__*/ React__default.default.createElement("div", {
786
+ "data-content": "",
787
+ className: cn(classNames == null ? void 0 : classNames.content, toast == null ? void 0 : (_toast_classNames4 = toast.classNames) == null ? void 0 : _toast_classNames4.content)
788
+ }, /*#__PURE__*/ React__default.default.createElement("div", {
789
+ "data-title": "",
790
+ className: cn(classNames == null ? void 0 : classNames.title, toast == null ? void 0 : (_toast_classNames5 = toast.classNames) == null ? void 0 : _toast_classNames5.title)
791
+ }, toast.jsx ? toast.jsx : typeof toast.title === 'function' ? toast.title() : toast.title), toast.description ? /*#__PURE__*/ React__default.default.createElement("div", {
792
+ "data-description": "",
793
+ className: cn(descriptionClassName, toastDescriptionClassname, classNames == null ? void 0 : classNames.description, toast == null ? void 0 : (_toast_classNames6 = toast.classNames) == null ? void 0 : _toast_classNames6.description)
794
+ }, typeof toast.description === 'function' ? toast.description() : toast.description) : null), /*#__PURE__*/ React__default.default.isValidElement(toast.cancel) ? toast.cancel : toast.cancel && isAction(toast.cancel) ? /*#__PURE__*/ React__default.default.createElement("button", {
795
+ "data-button": true,
796
+ "data-cancel": true,
797
+ style: toast.cancelButtonStyle || cancelButtonStyle,
798
+ onClick: (event)=>{
799
+ // We need to check twice because typescript
800
+ if (!isAction(toast.cancel)) return;
801
+ if (!dismissible) return;
802
+ toast.cancel.onClick == null ? void 0 : toast.cancel.onClick.call(toast.cancel, event);
803
+ deleteToast();
804
+ },
805
+ className: cn(classNames == null ? void 0 : classNames.cancelButton, toast == null ? void 0 : (_toast_classNames7 = toast.classNames) == null ? void 0 : _toast_classNames7.cancelButton)
806
+ }, toast.cancel.label) : null, /*#__PURE__*/ React__default.default.isValidElement(toast.action) ? toast.action : toast.action && isAction(toast.action) ? /*#__PURE__*/ React__default.default.createElement("button", {
807
+ "data-button": true,
808
+ "data-action": true,
809
+ style: toast.actionButtonStyle || actionButtonStyle,
810
+ onClick: (event)=>{
811
+ // We need to check twice because typescript
812
+ if (!isAction(toast.action)) return;
813
+ toast.action.onClick == null ? void 0 : toast.action.onClick.call(toast.action, event);
814
+ if (event.defaultPrevented) return;
815
+ deleteToast();
816
+ },
817
+ className: cn(classNames == null ? void 0 : classNames.actionButton, toast == null ? void 0 : (_toast_classNames8 = toast.classNames) == null ? void 0 : _toast_classNames8.actionButton)
818
+ }, toast.action.label) : null);
819
+ };
820
+ function getDocumentDirection() {
821
+ if (typeof window === 'undefined') return 'ltr';
822
+ if (typeof document === 'undefined') return 'ltr'; // For Fresh purpose
823
+ const dirAttribute = document.documentElement.getAttribute('dir');
824
+ if (dirAttribute === 'auto' || !dirAttribute) {
825
+ return window.getComputedStyle(document.documentElement).direction;
826
+ }
827
+ return dirAttribute;
828
+ }
829
+ function assignOffset(defaultOffset, mobileOffset) {
830
+ const styles = {};
831
+ [
832
+ defaultOffset,
833
+ mobileOffset
834
+ ].forEach((offset, index)=>{
835
+ const isMobile = index === 1;
836
+ const prefix = isMobile ? '--mobile-offset' : '--offset';
837
+ const defaultValue = isMobile ? MOBILE_VIEWPORT_OFFSET : VIEWPORT_OFFSET;
838
+ function assignAll(offset) {
839
+ [
840
+ 'top',
841
+ 'right',
842
+ 'bottom',
843
+ 'left'
844
+ ].forEach((key)=>{
845
+ styles[`${prefix}-${key}`] = typeof offset === 'number' ? `${offset}px` : offset;
846
+ });
847
+ }
848
+ if (typeof offset === 'number' || typeof offset === 'string') {
849
+ assignAll(offset);
850
+ } else if (typeof offset === 'object') {
851
+ [
852
+ 'top',
853
+ 'right',
854
+ 'bottom',
855
+ 'left'
856
+ ].forEach((key)=>{
857
+ if (offset[key] === undefined) {
858
+ styles[`${prefix}-${key}`] = defaultValue;
859
+ } else {
860
+ styles[`${prefix}-${key}`] = typeof offset[key] === 'number' ? `${offset[key]}px` : offset[key];
861
+ }
862
+ });
863
+ } else {
864
+ assignAll(defaultValue);
865
+ }
866
+ });
867
+ return styles;
868
+ }
869
+ function useSonner() {
870
+ const [activeToasts, setActiveToasts] = React__default.default.useState([]);
871
+ React__default.default.useEffect(()=>{
872
+ return ToastState.subscribe((toast)=>{
873
+ if (toast.dismiss) {
874
+ setTimeout(()=>{
875
+ ReactDOM__default.default.flushSync(()=>{
876
+ setActiveToasts((toasts)=>toasts.filter((t)=>t.id !== toast.id));
877
+ });
878
+ });
879
+ return;
880
+ }
881
+ // Prevent batching, temp solution.
882
+ setTimeout(()=>{
883
+ ReactDOM__default.default.flushSync(()=>{
884
+ setActiveToasts((toasts)=>{
885
+ const indexOfExistingToast = toasts.findIndex((t)=>t.id === toast.id);
886
+ // Update the toast if it already exists
887
+ if (indexOfExistingToast !== -1) {
888
+ return [
889
+ ...toasts.slice(0, indexOfExistingToast),
890
+ {
891
+ ...toasts[indexOfExistingToast],
892
+ ...toast
893
+ },
894
+ ...toasts.slice(indexOfExistingToast + 1)
895
+ ];
896
+ }
897
+ return [
898
+ toast,
899
+ ...toasts
900
+ ];
901
+ });
902
+ });
903
+ });
904
+ });
905
+ }, []);
906
+ return {
907
+ toasts: activeToasts
908
+ };
909
+ }
910
+ const Toaster = /*#__PURE__*/ React__default.default.forwardRef(function Toaster(props, ref) {
911
+ const { invert, position = 'bottom-right', hotkey = [
912
+ 'altKey',
913
+ 'KeyT'
914
+ ], expand, closeButton, className, offset, mobileOffset, theme = 'light', richColors, duration, style, visibleToasts = VISIBLE_TOASTS_AMOUNT, toastOptions, dir = getDocumentDirection(), gap = GAP, icons, containerAriaLabel = 'Notifications' } = props;
915
+ const [toasts, setToasts] = React__default.default.useState([]);
916
+ const possiblePositions = React__default.default.useMemo(()=>{
917
+ return Array.from(new Set([
918
+ position
919
+ ].concat(toasts.filter((toast)=>toast.position).map((toast)=>toast.position))));
920
+ }, [
921
+ toasts,
922
+ position
923
+ ]);
924
+ const [heights, setHeights] = React__default.default.useState([]);
925
+ const [expanded, setExpanded] = React__default.default.useState(false);
926
+ const [interacting, setInteracting] = React__default.default.useState(false);
927
+ const [actualTheme, setActualTheme] = React__default.default.useState(theme !== 'system' ? theme : typeof window !== 'undefined' ? window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' : 'light');
928
+ const listRef = React__default.default.useRef(null);
929
+ const hotkeyLabel = hotkey.join('+').replace(/Key/g, '').replace(/Digit/g, '');
930
+ const lastFocusedElementRef = React__default.default.useRef(null);
931
+ const isFocusWithinRef = React__default.default.useRef(false);
932
+ const removeToast = React__default.default.useCallback((toastToRemove)=>{
933
+ setToasts((toasts)=>{
934
+ var _toasts_find;
935
+ if (!((_toasts_find = toasts.find((toast)=>toast.id === toastToRemove.id)) == null ? void 0 : _toasts_find.delete)) {
936
+ ToastState.dismiss(toastToRemove.id);
937
+ }
938
+ return toasts.filter(({ id })=>id !== toastToRemove.id);
939
+ });
940
+ }, []);
941
+ React__default.default.useEffect(()=>{
942
+ return ToastState.subscribe((toast)=>{
943
+ if (toast.dismiss) {
944
+ const map = toasts.map((t)=>t.id === toast.id ? {
945
+ ...t,
946
+ delete: true
947
+ } : t);
948
+ // Prevent batching of other state updates
949
+ requestAnimationFrame(()=>{
950
+ setToasts(map);
951
+ });
952
+ return;
953
+ }
954
+ // Prevent batching, temp solution.
955
+ ReactDOM__default.default.flushSync(()=>{
956
+ setToasts((toasts)=>{
957
+ const indexOfExistingToast = toasts.findIndex((t)=>t.id === toast.id);
958
+ // Update the toast if it already exists
959
+ if (indexOfExistingToast !== -1) {
960
+ return [
961
+ ...toasts.slice(0, indexOfExistingToast),
962
+ {
963
+ ...toasts[indexOfExistingToast],
964
+ ...toast
965
+ },
966
+ ...toasts.slice(indexOfExistingToast + 1)
967
+ ];
968
+ }
969
+ return [
970
+ toast,
971
+ ...toasts
972
+ ];
973
+ });
974
+ });
975
+ });
976
+ }, [
977
+ toasts
978
+ ]);
979
+ React__default.default.useEffect(()=>{
980
+ if (theme !== 'system') {
981
+ setActualTheme(theme);
982
+ return;
983
+ }
984
+ if (theme === 'system') {
985
+ // check if current preference is dark
986
+ if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
987
+ // it's currently dark
988
+ setActualTheme('dark');
989
+ } else {
990
+ // it's not dark
991
+ setActualTheme('light');
992
+ }
993
+ }
994
+ if (typeof window === 'undefined') return;
995
+ const darkMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
996
+ try {
997
+ // Chrome & Firefox
998
+ darkMediaQuery.addEventListener('change', ({ matches })=>{
999
+ if (matches) {
1000
+ setActualTheme('dark');
1001
+ } else {
1002
+ setActualTheme('light');
1003
+ }
1004
+ });
1005
+ } catch (error) {
1006
+ // Safari < 14
1007
+ darkMediaQuery.addListener(({ matches })=>{
1008
+ try {
1009
+ if (matches) {
1010
+ setActualTheme('dark');
1011
+ } else {
1012
+ setActualTheme('light');
1013
+ }
1014
+ } catch (e) {
1015
+ console.error(e);
1016
+ }
1017
+ });
1018
+ }
1019
+ }, [
1020
+ theme
1021
+ ]);
1022
+ React__default.default.useEffect(()=>{
1023
+ // Ensure expanded is always false when no toasts are present / only one left
1024
+ if (toasts.length <= 1) {
1025
+ setExpanded(false);
1026
+ }
1027
+ }, [
1028
+ toasts
1029
+ ]);
1030
+ React__default.default.useEffect(()=>{
1031
+ const handleKeyDown = (event)=>{
1032
+ var _listRef_current;
1033
+ const isHotkeyPressed = hotkey.every((key)=>event[key] || event.code === key);
1034
+ if (isHotkeyPressed) {
1035
+ var _listRef_current1;
1036
+ setExpanded(true);
1037
+ (_listRef_current1 = listRef.current) == null ? void 0 : _listRef_current1.focus();
1038
+ }
1039
+ if (event.code === 'Escape' && (document.activeElement === listRef.current || ((_listRef_current = listRef.current) == null ? void 0 : _listRef_current.contains(document.activeElement)))) {
1040
+ setExpanded(false);
1041
+ }
1042
+ };
1043
+ document.addEventListener('keydown', handleKeyDown);
1044
+ return ()=>document.removeEventListener('keydown', handleKeyDown);
1045
+ }, [
1046
+ hotkey
1047
+ ]);
1048
+ React__default.default.useEffect(()=>{
1049
+ if (listRef.current) {
1050
+ return ()=>{
1051
+ if (lastFocusedElementRef.current) {
1052
+ lastFocusedElementRef.current.focus({
1053
+ preventScroll: true
1054
+ });
1055
+ lastFocusedElementRef.current = null;
1056
+ isFocusWithinRef.current = false;
1057
+ }
1058
+ };
1059
+ }
1060
+ }, [
1061
+ listRef.current
1062
+ ]);
1063
+ return(// Remove item from normal navigation flow, only available via hotkey
1064
+ /*#__PURE__*/ React__default.default.createElement("section", {
1065
+ ref: ref,
1066
+ "aria-label": `${containerAriaLabel} ${hotkeyLabel}`,
1067
+ tabIndex: -1,
1068
+ "aria-live": "polite",
1069
+ "aria-relevant": "additions text",
1070
+ "aria-atomic": "false",
1071
+ suppressHydrationWarning: true
1072
+ }, possiblePositions.map((position, index)=>{
1073
+ var _heights_;
1074
+ const [y, x] = position.split('-');
1075
+ if (!toasts.length) return null;
1076
+ return /*#__PURE__*/ React__default.default.createElement("ol", {
1077
+ key: position,
1078
+ dir: dir === 'auto' ? getDocumentDirection() : dir,
1079
+ tabIndex: -1,
1080
+ ref: listRef,
1081
+ className: className,
1082
+ "data-sonner-toaster": true,
1083
+ "data-sonner-theme": actualTheme,
1084
+ "data-y-position": y,
1085
+ "data-lifted": expanded && toasts.length > 1 && !expand,
1086
+ "data-x-position": x,
1087
+ style: {
1088
+ '--front-toast-height': `${((_heights_ = heights[0]) == null ? void 0 : _heights_.height) || 0}px`,
1089
+ '--width': `${TOAST_WIDTH}px`,
1090
+ '--gap': `${gap}px`,
1091
+ ...style,
1092
+ ...assignOffset(offset, mobileOffset)
1093
+ },
1094
+ onBlur: (event)=>{
1095
+ if (isFocusWithinRef.current && !event.currentTarget.contains(event.relatedTarget)) {
1096
+ isFocusWithinRef.current = false;
1097
+ if (lastFocusedElementRef.current) {
1098
+ lastFocusedElementRef.current.focus({
1099
+ preventScroll: true
1100
+ });
1101
+ lastFocusedElementRef.current = null;
1102
+ }
1103
+ }
1104
+ },
1105
+ onFocus: (event)=>{
1106
+ const isNotDismissible = event.target instanceof HTMLElement && event.target.dataset.dismissible === 'false';
1107
+ if (isNotDismissible) return;
1108
+ if (!isFocusWithinRef.current) {
1109
+ isFocusWithinRef.current = true;
1110
+ lastFocusedElementRef.current = event.relatedTarget;
1111
+ }
1112
+ },
1113
+ onMouseEnter: ()=>setExpanded(true),
1114
+ onMouseMove: ()=>setExpanded(true),
1115
+ onMouseLeave: ()=>{
1116
+ // Avoid setting expanded to false when interacting with a toast, e.g. swiping
1117
+ if (!interacting) {
1118
+ setExpanded(false);
1119
+ }
1120
+ },
1121
+ onDragEnd: ()=>setExpanded(false),
1122
+ onPointerDown: (event)=>{
1123
+ const isNotDismissible = event.target instanceof HTMLElement && event.target.dataset.dismissible === 'false';
1124
+ if (isNotDismissible) return;
1125
+ setInteracting(true);
1126
+ },
1127
+ onPointerUp: ()=>setInteracting(false)
1128
+ }, toasts.filter((toast)=>!toast.position && index === 0 || toast.position === position).map((toast, index)=>{
1129
+ var _toastOptions_duration, _toastOptions_closeButton;
1130
+ return /*#__PURE__*/ React__default.default.createElement(Toast, {
1131
+ key: toast.id,
1132
+ icons: icons,
1133
+ index: index,
1134
+ toast: toast,
1135
+ defaultRichColors: richColors,
1136
+ duration: (_toastOptions_duration = toastOptions == null ? void 0 : toastOptions.duration) != null ? _toastOptions_duration : duration,
1137
+ className: toastOptions == null ? void 0 : toastOptions.className,
1138
+ descriptionClassName: toastOptions == null ? void 0 : toastOptions.descriptionClassName,
1139
+ invert: invert,
1140
+ visibleToasts: visibleToasts,
1141
+ closeButton: (_toastOptions_closeButton = toastOptions == null ? void 0 : toastOptions.closeButton) != null ? _toastOptions_closeButton : closeButton,
1142
+ interacting: interacting,
1143
+ position: position,
1144
+ style: toastOptions == null ? void 0 : toastOptions.style,
1145
+ unstyled: toastOptions == null ? void 0 : toastOptions.unstyled,
1146
+ classNames: toastOptions == null ? void 0 : toastOptions.classNames,
1147
+ cancelButtonStyle: toastOptions == null ? void 0 : toastOptions.cancelButtonStyle,
1148
+ actionButtonStyle: toastOptions == null ? void 0 : toastOptions.actionButtonStyle,
1149
+ closeButtonAriaLabel: toastOptions == null ? void 0 : toastOptions.closeButtonAriaLabel,
1150
+ removeToast: removeToast,
1151
+ toasts: toasts.filter((t)=>t.position == toast.position),
1152
+ heights: heights.filter((h)=>h.position == toast.position),
1153
+ setHeights: setHeights,
1154
+ expandByDefault: expand,
1155
+ gap: gap,
1156
+ expanded: expanded,
1157
+ swipeDirections: props.swipeDirections
1158
+ });
1159
+ }));
1160
+ })));
1161
+ });
1162
+
1163
+ exports.Toaster = Toaster;
1164
+ exports.toast = toast;
1165
+ exports.useSonner = useSonner;