Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zag-js/toast

Package Overview
Dependencies
Maintainers
1
Versions
1019
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/toast - npm Package Compare versions

Comparing version 0.0.0-dev-20220407084218 to 0.0.0-dev-20220408111010

2

dist/index.js

@@ -1,2 +0,2 @@

var E=Object.defineProperty,K=Object.defineProperties,W=Object.getOwnPropertyDescriptor,$=Object.getOwnPropertyDescriptors,Y=Object.getOwnPropertyNames,w=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var C=(t,e,n)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,f=(t,e)=>{for(var n in e||(e={}))T.call(e,n)&&C(t,n,e[n]);if(w)for(var n of w(e))I.call(e,n)&&C(t,n,e[n]);return t},g=(t,e)=>K(t,$(e)),X=t=>E(t,"__esModule",{value:!0});var O=(t,e)=>{var n={};for(var r in t)T.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&w)for(var r of w(t))e.indexOf(r)<0&&I.call(t,r)&&(n[r]=t[r]);return n};var Z=(t,e)=>{for(var n in e)E(t,n,{get:e[n],enumerable:!0})},J=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Y(e))!T.call(t,o)&&(n||o!=="default")&&E(t,o,{get:()=>e[o],enumerable:!(r=W(e,o))||r.enumerable});return t};var Q=(t=>(e,n)=>t&&t.get(e)||(n=J(X({}),e,1),t&&t.set(e,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var ft={};Z(ft,{api:()=>pt,connect:()=>q,createMachine:()=>P,group:()=>dt});var A=(t,...e)=>{let n=typeof t=="function"?t(...e):t;return n!=null?n:void 0};var gt=(()=>{let t=0;return()=>(t++,t.toString(36))})();var D=()=>typeof window!="undefined";function _(...t){let e=t.length===1?t[0]:t[1],n=t.length===2?t[0]:!0}var V=require("@zag-js/core");function tt(t){return{button:t,label:t,input:t,output:t,element:t}}var S=tt(t=>t);var d={getDoc:t=>{var e;return(e=t.doc)!=null?e:document},getGroupId:t=>`toast-group--${t}`,getContainerId:t=>`toast--${t.id}`,getTitleId:t=>`toast-title--${t.id}`,getCloseButtonId:t=>`toast-close-button--${t.id}`,getPortalId:t=>`toast-portal--${t.uid}`,getPortalEl:t=>d.getDoc(t).getElementById(d.getPortalId(t)),createPortalEl:t=>{let e=d.getPortalEl(t);if(e)return e;let n=d.getDoc(t).createElement("toast-portal");return n.id=d.getPortalId(t),n}};function R(t){let e={};for(let n of t){let r=n.state.context.placement;e[r]||(e[r]=[]),e[r].push(n)}return e}var et={info:5e3,error:5e3,success:2e3,loading:1/0,custom:5e3};function M(t,e){return t!=null?t:et[e]}function U(t,e){let n=t.offsets,r=typeof n=="string"?{left:n,right:n,bottom:n,top:n}:n,o=t.dir==="rtl",a=e.replace("-start",o?"-right":"-left").replace("-end",o?"-left":"-right"),l=a.includes("right"),m=a.includes("left"),c={position:"fixed",pointerEvents:t.count>0?void 0:"none",display:"flex",flexDirection:"column","--toast-gutter":t.gutter,zIndex:t.zIndex},i="center";if(l&&(i="flex-end"),m&&(i="flex-start"),c.alignItems=i,a.includes("top")){let s=r.top;c.top=`calc(env(safe-area-inset-top, 0px) + ${s})`}if(a.includes("bottom")){let s=r.bottom;c.bottom=`calc(env(safe-area-inset-bottom, 0px) + ${s})`}if(!a.includes("left")){let s=r.right;c.right=`calc(env(safe-area-inset-right, 0px) + ${s})`}if(!a.includes("right")){let s=r.left;c.left=`calc(env(safe-area-inset-left, 0px) + ${s})`}return c}var L={};function B(t,e,n=S){let r={count:t.context.count,toasts:t.context.toasts,toastsByPlacement:R(t.context.toasts),isVisible(o){return t.context.toasts.length?!!t.context.toasts.find(a=>a.id==o):!1},create(o){let a="toast-"+Math.random().toString(36).substring(2,9),l=o.id?o.id:a;if(!r.isVisible(l))return e({type:"ADD_TOAST",toast:g(f({},o),{id:l})}),l},upsert(o){let{id:a}=o;return(a?r.isVisible(a):!1)&&a!=null?r.update(a,o):r.create(o)},dismiss(o){o==null?e("DISMISS_ALL"):r.isVisible(o)&&e({type:"DISMISS_TOAST",id:o})},remove(o){o==null?e("REMOVE_ALL"):r.isVisible(o)&&e({type:"REMOVE_TOAST",id:o})},dismissByPlacement(o){let a=r.toastsByPlacement[o];a&&a.forEach(l=>r.dismiss(l.id))},update(o,a){if(!!r.isVisible(o))return e({type:"UPDATE_TOAST",id:o,toast:a}),o},loading(o){return o.type="loading",r.upsert(o)},success(o){return o.type="success",r.upsert(o)},error(o){return o.type="error",r.upsert(o)},promise(o,a,l={}){let m=r.loading(g(f(f({},l),l==null?void 0:l.loading),{type:"loading",title:a.loading}));return o.then(c=>{let i=A(a.loading,c);r.success(g(f(f({},l),l==null?void 0:l.success),{id:m,title:i}))}).catch(c=>{let i=A(a.error,c);r.error(g(f(f({},l),l==null?void 0:l.error),{id:m,title:i}))}),o},pause(o){o==null?e("PAUSE_ALL"):r.isVisible(o)&&e({type:"PAUSE_TOAST",id:o})},resume(o){o==null?e("RESUME_ALL"):r.isVisible(o)&&e({type:"RESUME_TOAST",id:o})},getGroupProps(o){let{placement:a,label:l="Notifications"}=o;return n.element({tabIndex:-1,"aria-label":l,id:d.getGroupId(a),"data-placement":a,"aria-live":"polite",role:"region",style:U(t.context,a)})},createPortal(){let o=d.getDoc(t.context),a=d.getPortalEl(t.context);if(a)return a;let l=d.createPortalEl(t.context);return o.body.appendChild(l),l},subscribe(o){return(0,V.subscribe)(t.context.toasts,()=>o(t.context.toasts))}};return t.matches("unknown")||Object.assign(L,r),r}var b=require("@zag-js/core");var N=t=>t?"":void 0;var nt=t=>t,ot=()=>{};var Lt=(()=>{let t=0;return()=>(t++,t.toString(36))})();var y=new Map,v=new Map;function rt(t,e,n,r){var o;if(!t)return ot;let a=JSON.stringify({type:e,options:r}),l=y.get(t);if(y.has(t))(l==null?void 0:l.has(a))?(o=l==null?void 0:l.get(a))==null||o.add(n):l==null||l.set(a,new Set([n]));else{let c=new Map([[a,new Set([n])]]);y.set(t,c)}function m(c){var i,s;function u(p){var h;let k=y.get(c);(h=k==null?void 0:k.get(a))==null||h.forEach(H=>H(p))}if(!(v==null?void 0:v.has(c))){v.set(c,new Map([[a,u]])),c.addEventListener(e,u,r);return}((i=v==null?void 0:v.get(c))==null?void 0:i.has(a))||((s=v.get(c))==null||s.set(a,u),c.addEventListener(e,u,r))}return m(t),function(){var c,i,s,u;if(!y.has(t))return;let p=y.get(t);if((c=p==null?void 0:p.get(a))==null||c.delete(n),((i=p==null?void 0:p.get(a))==null?void 0:i.size)===0){let h=(s=v.get(t))==null?void 0:s.get(a);t.removeEventListener(e,h,r),p==null||p.delete(a),(u=v.get(t))==null||u.delete(a),(p==null?void 0:p.size)===0&&(y.delete(t),v.delete(t))}}}var z=t=>Object.prototype.toString.call(t).slice(8,-1),it=t=>z(t)==="Object"&&"current"in t,at=t=>z(t)==="Function"?t():t;function st(t,e,n,r){let o=it(t)?t.current:at(t);return rt(o,e,n,r)}var F=2147483647;var kt=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","embed","iframe","object","a[href]","area[href]","[tabindex]","audio[controls]","video[controls]","*[tabindex]:not([aria-disabled])","[contenteditable]:not([contenteditable=false])","details > summary:first-of-type"].join(",");function G(t,e){let n=nt(t);return st(n,"visibilitychange",()=>{let r=n.hidden||n.msHidden||n.webkitHidden;e(!!r)})}var x=require("@zag-js/core");var{not:lt,and:ct,or:ut}=x.guards;function P(t={}){let c=t,{type:e="info",duration:n,id:r="toast",placement:o="bottom",removeDelay:a=500}=c,l=O(c,["type","duration","id","placement","removeDelay"]),m=M(n,e);return(0,x.createMachine)({id:r,entry:"invokeOnOpen",initial:e==="loading"?"persist":"active",context:f({id:r,type:e,remaining:m,duration:m,removeDelay:a,createdAt:Date.now(),placement:o},l),on:{UPDATE:[{guard:ct("hasTypeChanged","isChangingToLoading"),target:"persist",actions:["setContext","invokeOnUpdate"]},{guard:ut("hasDurationChanged","hasTypeChanged"),target:"active:temp",actions:["setContext","invokeOnUpdate"]},{actions:["setContext","invokeOnUpdate"]}]},states:{"active:temp":{tags:["visible","updating"],after:{0:"active"}},persist:{tags:["visible","paused"],activities:"trackDocumentVisibility",on:{RESUME:{guard:lt("isLoadingType"),target:"active",actions:["setCreatedAt"]},DISMISS:"dismissing"}},active:{tags:["visible"],activities:"trackDocumentVisibility",after:{VISIBLE_DURATION:"dismissing"},on:{DISMISS:"dismissing",PAUSE:{target:"persist",actions:"setRemainingDuration"}}},dismissing:{entry:"invokeOnClosing",after:{REMOVE_DELAY:{target:"inactive",actions:"notifyParentToRemove"}}},inactive:{entry:"invokeOnClose",type:"final"}}},{activities:{trackDocumentVisibility(i,s,{send:u}){if(!!i.pauseOnPageIdle)return G(d.getDoc(i),function(p){u(p?"PAUSE":"RESUME")})}},guards:{isChangingToLoading:(i,s)=>{var u;return((u=s.toast)==null?void 0:u.type)==="loading"},isLoadingType:i=>i.type==="loading",hasTypeChanged:(i,s)=>{var u;return((u=s.toast)==null?void 0:u.type)!==i.type},hasDurationChanged:(i,s)=>{var u;return((u=s.toast)==null?void 0:u.duration)!==i.duration}},delays:{VISIBLE_DURATION:i=>i.remaining,REMOVE_DELAY:i=>i.removeDelay},actions:{setRemainingDuration(i){i.remaining-=Date.now()-i.createdAt},setCreatedAt(i){i.createdAt=Date.now()},notifyParentToRemove(i,s,{self:u}){u.sendParent({type:"REMOVE_TOAST",id:u.id})},invokeOnClosing(i){var s;(s=i.onClosing)==null||s.call(i)},invokeOnClose(i){var s;(s=i.onClose)==null||s.call(i)},invokeOnOpen(i){var s;(s=i.onOpen)==null||s.call(i)},invokeOnUpdate(i){var s;(s=i.onUpdate)==null||s.call(i)},setContext(i,s){let{duration:u,type:p}=s.toast,h=M(u,p);Object.assign(i,g(f({},s.toast),{duration:h,remaining:h}))}}})}var j=(0,b.createMachine)({id:"toaster",initial:"active",context:{dir:"ltr",max:Number.MAX_SAFE_INTEGER,uid:"",toasts:[],gutter:"1rem",zIndex:F,pauseOnPageIdle:!1,pauseOnInteraction:!0,offsets:{left:"0px",right:"0px",top:"0px",bottom:"0px"}},computed:{count:t=>t.toasts.length},on:{SETUP:{actions:(t,e)=>{t.uid=e.id,e.doc&&(t.doc=(0,b.ref)(e.doc))}},PAUSE_TOAST:{actions:(t,e,{self:n})=>{n.sendChild("PAUSE",e.id)}},PAUSE_ALL:{actions:t=>{t.toasts.forEach(e=>e.send("PAUSE"))}},RESUME_TOAST:{actions:(t,e,{self:n})=>{n.sendChild("RESUME",e.id)}},RESUME_ALL:{actions:t=>{t.toasts.forEach(e=>e.send("RESUME"))}},ADD_TOAST:{guard:t=>t.toasts.length<t.max,actions:(t,e,{self:n})=>{var l;let r=g(f({},e.toast),{pauseOnPageIdle:t.pauseOnPageIdle,pauseOnInteraction:t.pauseOnInteraction,dir:t.dir,doc:(0,b.ref)((l=t.doc)!=null?l:document)}),o=P(r),a=n.spawn(o);t.toasts.push(a)}},UPDATE_TOAST:{actions:(t,e,{self:n})=>{n.sendChild({type:"UPDATE",toast:e.toast},e.id)}},DISMISS_TOAST:{actions:(t,e,{self:n})=>{n.sendChild("DISMISS",e.id)}},DISMISS_ALL:{actions:t=>{t.toasts.forEach(e=>e.send("DISMISS"))}},REMOVE_TOAST:{actions:(t,e,{self:n})=>{n.stopChild(e.id);let r=t.toasts.findIndex(o=>o.id===e.id);t.toasts.splice(r,1)}},REMOVE_ALL:{actions:(t,e,{self:n})=>{for(t.toasts.forEach(r=>n.stopChild(r.id));t.toasts.length;)t.toasts.pop()}}}});function q(t,e,n=S){let r=t.hasTag("visible"),o=t.hasTag("paused"),a=t.hasTag("updating"),l=t.context.dir==="rtl",m=t.context.type,c=t.context.pauseOnInteraction,i=t.context.placement;return{type:t.context.type,title:t.context.title,placement:i,isVisible:r,isPaused:o,pause(){e("PAUSE")},resume(){e("RESUME")},dismiss(){e("DISMISS")},rootProps:n.element({"data-part":"root",dir:t.context.dir,id:d.getContainerId(t.context),"data-open":N(r),"data-type":t.context.type,"data-placement":i,role:"status","aria-atomic":"true",tabIndex:0,style:{position:"relative",pointerEvents:"auto",margin:"calc(var(--toast-gutter) / 2)","--remove-delay":`${t.context.removeDelay}ms`,"--duration":`${t.context.duration}ms`},onKeyDown(s){s.key=="Escape"&&(e("DISMISS"),s.preventDefault(),s.stopPropagation())},onFocus(){c&&e("PAUSE")},onBlur(){c&&e("RESUME")},onPointerEnter(){c&&e("PAUSE")},onPointerLeave(){c&&e("RESUME")}}),progressbarProps:n.element({"data-part":"progressbar","data-type":t.context.type,style:{opacity:r?1:0,transformOrigin:l?"right":"left",animationName:a||m==="loading"?"none":void 0,animationPlayState:o?"paused":"running",animationDuration:`${t.context.duration}ms`,animationFillMode:a?void 0:"forwards"}}),titleProps:n.element({"data-part":"title",id:d.getTitleId(t.context)}),closeButtonProps:n.button({id:d.getCloseButtonId(t.context),"data-part":"close-button",type:"button","aria-label":"Dismiss notification",onClick(){e("DISMISS")}}),render(){var s,u;return(u=(s=t.context).render)==null?void 0:u.call(s,{id:t.context.id,type:t.context.type,duration:t.context.duration,title:t.context.title,placement:t.context.placement,description:t.context.description,dismiss(){e("DISMISS")}})}}}var dt={connect:B,machine:j};function pt(){if(!D())_("toast.api() is only available in the browser");else return L}module.exports=Q(ft);
var E=Object.defineProperty,W=Object.defineProperties,$=Object.getOwnPropertyDescriptor,K=Object.getOwnPropertyDescriptors,Y=Object.getOwnPropertyNames,w=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var C=(t,e,n)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,f=(t,e)=>{for(var n in e||(e={}))T.call(e,n)&&C(t,n,e[n]);if(w)for(var n of w(e))I.call(e,n)&&C(t,n,e[n]);return t},g=(t,e)=>W(t,K(e)),X=t=>E(t,"__esModule",{value:!0});var O=(t,e)=>{var n={};for(var r in t)T.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&w)for(var r of w(t))e.indexOf(r)<0&&I.call(t,r)&&(n[r]=t[r]);return n};var Z=(t,e)=>{for(var n in e)E(t,n,{get:e[n],enumerable:!0})},J=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Y(e))!T.call(t,o)&&(n||o!=="default")&&E(t,o,{get:()=>e[o],enumerable:!(r=$(e,o))||r.enumerable});return t};var Q=(t=>(e,n)=>t&&t.get(e)||(n=J(X({}),e,1),t&&t.set(e,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var ft={};Z(ft,{api:()=>pt,connect:()=>H,createMachine:()=>P,group:()=>dt});var A=(t,...e)=>{let n=typeof t=="function"?t(...e):t;return n!=null?n:void 0};var gt=(()=>{let t=0;return()=>(t++,t.toString(36))})();var D=()=>typeof window!="undefined";function _(...t){let e=t.length===1?t[0]:t[1],n=t.length===2?t[0]:!0}var V=require("@zag-js/core");function tt(t){return{button:t,label:t,input:t,output:t,element:t}}var S=tt(t=>t);var d={getDoc:t=>{var e;return(e=t.doc)!=null?e:document},getGroupId:t=>`toast-group--${t}`,getContainerId:t=>`toast--${t.id}`,getTitleId:t=>`toast-title--${t.id}`,getCloseButtonId:t=>`toast-close-button--${t.id}`,getPortalId:t=>`toast-portal--${t.uid}`,getPortalEl:t=>d.getDoc(t).getElementById(d.getPortalId(t)),createPortalEl:t=>{let e=d.getPortalEl(t);if(e)return e;let n=d.getDoc(t).createElement("toast-portal");return n.id=d.getPortalId(t),n}};function R(t){let e={};for(let n of t){let r=n.state.context.placement;e[r]||(e[r]=[]),e[r].push(n)}return e}var et={info:5e3,error:5e3,success:2e3,loading:1/0,custom:5e3};function M(t,e){return t!=null?t:et[e]}function U(t,e){let n=t.offsets,r=typeof n=="string"?{left:n,right:n,bottom:n,top:n}:n,o=t.dir==="rtl",a=e.replace("-start",o?"-right":"-left").replace("-end",o?"-left":"-right"),l=a.includes("right"),m=a.includes("left"),c={position:"fixed",pointerEvents:t.count>0?void 0:"none",display:"flex",flexDirection:"column","--toast-gutter":t.gutter,zIndex:t.zIndex},i="center";if(l&&(i="flex-end"),m&&(i="flex-start"),c.alignItems=i,a.includes("top")){let s=r.top;c.top=`calc(env(safe-area-inset-top, 0px) + ${s})`}if(a.includes("bottom")){let s=r.bottom;c.bottom=`calc(env(safe-area-inset-bottom, 0px) + ${s})`}if(!a.includes("left")){let s=r.right;c.right=`calc(env(safe-area-inset-right, 0px) + ${s})`}if(!a.includes("right")){let s=r.left;c.left=`calc(env(safe-area-inset-left, 0px) + ${s})`}return c}var L={};function F(t,e,n=S){let r={count:t.context.count,toasts:t.context.toasts,toastsByPlacement:R(t.context.toasts),isVisible(o){return t.context.toasts.length?!!t.context.toasts.find(a=>a.id==o):!1},create(o){let a="toast-"+Math.random().toString(36).substring(2,9),l=o.id?o.id:a;if(!r.isVisible(l))return e({type:"ADD_TOAST",toast:g(f({},o),{id:l})}),l},upsert(o){let{id:a}=o;return(a?r.isVisible(a):!1)&&a!=null?r.update(a,o):r.create(o)},dismiss(o){o==null?e("DISMISS_ALL"):r.isVisible(o)&&e({type:"DISMISS_TOAST",id:o})},remove(o){o==null?e("REMOVE_ALL"):r.isVisible(o)&&e({type:"REMOVE_TOAST",id:o})},dismissByPlacement(o){let a=r.toastsByPlacement[o];a&&a.forEach(l=>r.dismiss(l.id))},update(o,a){if(!!r.isVisible(o))return e({type:"UPDATE_TOAST",id:o,toast:a}),o},loading(o){return o.type="loading",r.upsert(o)},success(o){return o.type="success",r.upsert(o)},error(o){return o.type="error",r.upsert(o)},promise(o,a,l={}){let m=r.loading(g(f(f({},l),l==null?void 0:l.loading),{type:"loading",title:a.loading}));return o.then(c=>{let i=A(a.loading,c);r.success(g(f(f({},l),l==null?void 0:l.success),{id:m,title:i}))}).catch(c=>{let i=A(a.error,c);r.error(g(f(f({},l),l==null?void 0:l.error),{id:m,title:i}))}),o},pause(o){o==null?e("PAUSE_ALL"):r.isVisible(o)&&e({type:"PAUSE_TOAST",id:o})},resume(o){o==null?e("RESUME_ALL"):r.isVisible(o)&&e({type:"RESUME_TOAST",id:o})},getGroupProps(o){let{placement:a,label:l="Notifications"}=o;return n.element({tabIndex:-1,"aria-label":l,id:d.getGroupId(a),"data-placement":a,"aria-live":"polite",role:"region",style:U(t.context,a)})},createPortal(){let o=d.getDoc(t.context),a=d.getPortalEl(t.context);if(a)return a;let l=d.createPortalEl(t.context);return o.body.appendChild(l),l},subscribe(o){return(0,V.subscribe)(t.context.toasts,()=>o(t.context.toasts))}};return t.matches("unknown")||Object.assign(L,r),r}var b=require("@zag-js/core");var N=t=>t?"":void 0;var nt=t=>t,ot=()=>{};var Lt=(()=>{let t=0;return()=>(t++,t.toString(36))})();var y=new Map,v=new Map;function rt(t,e,n,r){var o;if(!t)return ot;let a=JSON.stringify({type:e,options:r}),l=y.get(t);if(y.has(t))(l==null?void 0:l.has(a))?(o=l==null?void 0:l.get(a))==null||o.add(n):l==null||l.set(a,new Set([n]));else{let c=new Map([[a,new Set([n])]]);y.set(t,c)}function m(c){var i,s;function u(p){var h;let k=y.get(c);(h=k==null?void 0:k.get(a))==null||h.forEach(q=>q(p))}if(!(v==null?void 0:v.has(c))){v.set(c,new Map([[a,u]])),c.addEventListener(e,u,r);return}((i=v==null?void 0:v.get(c))==null?void 0:i.has(a))||((s=v.get(c))==null||s.set(a,u),c.addEventListener(e,u,r))}return m(t),function(){var c,i,s,u;if(!y.has(t))return;let p=y.get(t);if((c=p==null?void 0:p.get(a))==null||c.delete(n),((i=p==null?void 0:p.get(a))==null?void 0:i.size)===0){let h=(s=v.get(t))==null?void 0:s.get(a);t.removeEventListener(e,h,r),p==null||p.delete(a),(u=v.get(t))==null||u.delete(a),(p==null?void 0:p.size)===0&&(y.delete(t),v.delete(t))}}}var B=t=>Object.prototype.toString.call(t).slice(8,-1),it=t=>B(t)==="Object"&&"current"in t,at=t=>B(t)==="Function"?t():t;function st(t,e,n,r){let o=it(t)?t.current:at(t);return rt(o,e,n,r)}var z=2147483647;var kt=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","embed","iframe","object","a[href]","area[href]","[tabindex]","audio[controls]","video[controls]","*[tabindex]:not([aria-disabled])","[contenteditable]:not([contenteditable=false])","details > summary:first-of-type"].join(",");function j(t,e){let n=nt(t);return st(n,"visibilitychange",()=>{let r=n.hidden||n.msHidden||n.webkitHidden;e(!!r)})}var x=require("@zag-js/core");var{not:lt,and:ct,or:ut}=x.guards;function P(t={}){let c=t,{type:e="info",duration:n,id:r="toast",placement:o="bottom",removeDelay:a=500}=c,l=O(c,["type","duration","id","placement","removeDelay"]),m=M(n,e);return(0,x.createMachine)({id:r,entry:"invokeOnOpen",initial:e==="loading"?"persist":"active",context:f({id:r,type:e,remaining:m,duration:m,removeDelay:a,createdAt:Date.now(),placement:o},l),on:{UPDATE:[{guard:ct("hasTypeChanged","isChangingToLoading"),target:"persist",actions:["setContext","invokeOnUpdate"]},{guard:ut("hasDurationChanged","hasTypeChanged"),target:"active:temp",actions:["setContext","invokeOnUpdate"]},{actions:["setContext","invokeOnUpdate"]}]},states:{"active:temp":{tags:["visible","updating"],after:{0:"active"}},persist:{tags:["visible","paused"],activities:"trackDocumentVisibility",on:{RESUME:{guard:lt("isLoadingType"),target:"active",actions:["setCreatedAt"]},DISMISS:"dismissing"}},active:{tags:["visible"],activities:"trackDocumentVisibility",after:{VISIBLE_DURATION:"dismissing"},on:{DISMISS:"dismissing",PAUSE:{target:"persist",actions:"setRemainingDuration"}}},dismissing:{entry:"invokeOnClosing",after:{REMOVE_DELAY:{target:"inactive",actions:"notifyParentToRemove"}}},inactive:{entry:"invokeOnClose",type:"final"}}},{activities:{trackDocumentVisibility(i,s,{send:u}){if(!!i.pauseOnPageIdle)return j(d.getDoc(i),function(p){u(p?"PAUSE":"RESUME")})}},guards:{isChangingToLoading:(i,s)=>{var u;return((u=s.toast)==null?void 0:u.type)==="loading"},isLoadingType:i=>i.type==="loading",hasTypeChanged:(i,s)=>{var u;return((u=s.toast)==null?void 0:u.type)!==i.type},hasDurationChanged:(i,s)=>{var u;return((u=s.toast)==null?void 0:u.duration)!==i.duration}},delays:{VISIBLE_DURATION:i=>i.remaining,REMOVE_DELAY:i=>i.removeDelay},actions:{setRemainingDuration(i){i.remaining-=Date.now()-i.createdAt},setCreatedAt(i){i.createdAt=Date.now()},notifyParentToRemove(i,s,{self:u}){u.sendParent({type:"REMOVE_TOAST",id:u.id})},invokeOnClosing(i){var s;(s=i.onClosing)==null||s.call(i)},invokeOnClose(i){var s;(s=i.onClose)==null||s.call(i)},invokeOnOpen(i){var s;(s=i.onOpen)==null||s.call(i)},invokeOnUpdate(i){var s;(s=i.onUpdate)==null||s.call(i)},setContext(i,s){let{duration:u,type:p}=s.toast,h=M(u,p);Object.assign(i,g(f({},s.toast),{duration:h,remaining:h}))}}})}var G=(0,b.createMachine)({id:"toaster",initial:"active",context:{dir:"ltr",max:Number.MAX_SAFE_INTEGER,uid:"",toasts:[],gutter:"1rem",zIndex:z,pauseOnPageIdle:!1,pauseOnInteraction:!0,offsets:{left:"0px",right:"0px",top:"0px",bottom:"0px"}},computed:{count:t=>t.toasts.length},on:{SETUP:{actions:(t,e)=>{t.uid=e.id,e.doc&&(t.doc=(0,b.ref)(e.doc))}},PAUSE_TOAST:{actions:(t,e,{self:n})=>{n.sendChild("PAUSE",e.id)}},PAUSE_ALL:{actions:t=>{t.toasts.forEach(e=>e.send("PAUSE"))}},RESUME_TOAST:{actions:(t,e,{self:n})=>{n.sendChild("RESUME",e.id)}},RESUME_ALL:{actions:t=>{t.toasts.forEach(e=>e.send("RESUME"))}},ADD_TOAST:{guard:t=>t.toasts.length<t.max,actions:(t,e,{self:n})=>{var l;let r=g(f({},e.toast),{pauseOnPageIdle:t.pauseOnPageIdle,pauseOnInteraction:t.pauseOnInteraction,dir:t.dir,doc:(0,b.ref)((l=t.doc)!=null?l:document)}),o=P(r),a=n.spawn(o);t.toasts.push(a)}},UPDATE_TOAST:{actions:(t,e,{self:n})=>{n.sendChild({type:"UPDATE",toast:e.toast},e.id)}},DISMISS_TOAST:{actions:(t,e,{self:n})=>{n.sendChild("DISMISS",e.id)}},DISMISS_ALL:{actions:t=>{t.toasts.forEach(e=>e.send("DISMISS"))}},REMOVE_TOAST:{actions:(t,e,{self:n})=>{n.stopChild(e.id);let r=t.toasts.findIndex(o=>o.id===e.id);t.toasts.splice(r,1)}},REMOVE_ALL:{actions:(t,e,{self:n})=>{for(t.toasts.forEach(r=>n.stopChild(r.id));t.toasts.length;)t.toasts.pop()}}}});function H(t,e,n=S){let r=t.hasTag("visible"),o=t.hasTag("paused"),a=t.hasTag("updating"),l=t.context.dir==="rtl",m=t.context.type,c=t.context.pauseOnInteraction,i=t.context.placement;return{type:t.context.type,title:t.context.title,placement:i,isVisible:r,isPaused:o,pause(){e("PAUSE")},resume(){e("RESUME")},dismiss(){e("DISMISS")},rootProps:n.element({"data-part":"root",dir:t.context.dir,id:d.getContainerId(t.context),"data-open":N(r),"data-type":t.context.type,"data-placement":i,role:"status","aria-atomic":"true",tabIndex:0,style:{position:"relative",pointerEvents:"auto",margin:"calc(var(--toast-gutter) / 2)","--remove-delay":`${t.context.removeDelay}ms`,"--duration":`${t.context.duration}ms`},onKeyDown(s){s.key=="Escape"&&(e("DISMISS"),s.preventDefault(),s.stopPropagation())},onFocus(){c&&e("PAUSE")},onBlur(){c&&e("RESUME")},onPointerEnter(){c&&e("PAUSE")},onPointerLeave(){c&&e("RESUME")}}),progressbarProps:n.element({"data-part":"progressbar","data-type":t.context.type,style:{opacity:r?1:0,transformOrigin:l?"right":"left",animationName:a||m==="loading"?"none":void 0,animationPlayState:o?"paused":"running",animationDuration:`${t.context.duration}ms`,animationFillMode:a?void 0:"forwards"}}),titleProps:n.element({"data-part":"title",id:d.getTitleId(t.context)}),closeButtonProps:n.button({id:d.getCloseButtonId(t.context),"data-part":"close-button",type:"button","aria-label":"Dismiss notification",onClick(){e("DISMISS")}}),render(){var s,u;return(u=(s=t.context).render)==null?void 0:u.call(s,{id:t.context.id,type:t.context.type,duration:t.context.duration,title:t.context.title,placement:t.context.placement,description:t.context.description,dismiss(){e("DISMISS")}})}}}var dt={connect:F,machine:G};function pt(){if(!D())_("toast.api() is only available in the browser");else return L}module.exports=Q(ft);
//# sourceMappingURL=index.js.map
{
"name": "@zag-js/toast",
"version": "0.0.0-dev-20220407084218",
"version": "0.0.0-dev-20220408111010",
"description": "Core logic for the toast widget implemented as a state machine",

@@ -32,7 +32,7 @@ "keywords": [

"dependencies": {
"@zag-js/core": "^0.0.0-dev-20220407084218",
"@zag-js/dom-utils": "^0.0.0-dev-20220407084218",
"@zag-js/types": "^0.0.0-dev-20220407084218",
"@zag-js/utils": "^0.0.0-dev-20220407084218"
"@zag-js/core": "^0.0.0-dev-20220408111010",
"@zag-js/dom-utils": "^0.0.0-dev-20220408111010",
"@zag-js/types": "^0.0.0-dev-20220408111010",
"@zag-js/utils": "^0.0.0-dev-20220408111010"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc