sonner 2.0.0-beta.1 → 2.0.0-beta.2

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