@trycourier/courier-ui-toast 2.4.1 → 2.4.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.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@trycourier/courier-ui-core"),require("@trycourier/courier-js")):"function"==typeof define&&define.amd?define(["exports","@trycourier/courier-ui-core","@trycourier/courier-js"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CourierUIToast={},t.CourierUICore,t.CourierJS)}(this,(function(t,e,s){"use strict";var i=Object.defineProperty,o=(t,e,s)=>((t,e,s)=>e in t?i(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s)(t,"symbol"!=typeof e?e+"":e,s);const n={item:{backgroundColor:e.CourierColors.white[500],hoverBackgroundColor:e.CourierColors.gray[200],activeBackgroundColor:e.CourierColors.gray[500],shadow:`0px 4px 8px -2px ${e.CourierColors.black[50020]}`,border:`1px solid ${e.CourierColors.gray[500]}`,borderRadius:"8px",title:{size:"11pt",weight:"400",color:e.CourierColors.black[500]},body:{size:"11pt",weight:"400",color:e.CourierColors.gray[600]},icon:{color:e.CourierColors.black[500],svg:e.CourierIconSVGs.inbox},dismissIcon:{color:e.CourierColors.black[500],svg:e.CourierIconSVGs.remove},autoDismissBarColor:e.CourierColors.blue[400]}},a={item:{backgroundColor:e.CourierColors.black[500],hoverBackgroundColor:e.CourierColors.gray[800],activeBackgroundColor:e.CourierColors.gray[700],shadow:`0px 4px 8px -2px ${e.CourierColors.gray[400]}`,border:`1px solid ${e.CourierColors.gray[400]}`,borderRadius:"8px",title:{size:"11pt",weight:"400",color:e.CourierColors.white[500]},body:{size:"11pt",weight:"400",color:e.CourierColors.gray[500]},icon:{color:e.CourierColors.white[500],svg:e.CourierIconSVGs.inbox},dismissIcon:{color:e.CourierColors.white[500],svg:e.CourierIconSVGs.remove},autoDismissBarColor:e.CourierColors.blue[400]}},r=(t,e)=>{var s,i,o,r,l,d,u,h,m,c,g,v,_,C,p,b,f,I,k,D,T,y,M,w,x,A,L,$,E,S,P,B,R,O,U,z,H,j,F,N,G,V,X,J,q,K,W,Y,Q,Z,tt,et,st,it;const ot="light"===t?n:a;return{item:{...ot.item,...e.item,title:{...null==(s=ot.item)?void 0:s.title,...null==(i=e.item)?void 0:i.title},body:{...null==(o=ot.item)?void 0:o.body,...null==(r=e.item)?void 0:r.body},icon:{...null==(l=ot.item)?void 0:l.icon,...null==(d=e.item)?void 0:d.icon},dismissIcon:{...null==(u=ot.item)?void 0:u.dismissIcon,...null==(h=e.item)?void 0:h.dismissIcon},actions:{...null==(m=ot.item)?void 0:m.actions,...null==(c=e.item)?void 0:c.actions,font:{...null==(v=null==(g=ot.item)?void 0:g.actions)?void 0:v.font,...null==(C=null==(_=e.item)?void 0:_.actions)?void 0:C.font},button:{...null==(b=null==(p=ot.item)?void 0:p.actions)?void 0:b.button,...null==(I=null==(f=e.item)?void 0:f.actions)?void 0:I.button,font:{...null==(T=null==(D=null==(k=ot.item)?void 0:k.actions)?void 0:D.button)?void 0:T.font,...null==(w=null==(M=null==(y=e.item)?void 0:y.actions)?void 0:M.button)?void 0:w.font}},secondary:{...null==(A=null==(x=ot.item)?void 0:x.actions)?void 0:A.secondary,...null==($=null==(L=e.item)?void 0:L.actions)?void 0:$.secondary,font:{...null==(P=null==(S=null==(E=ot.item)?void 0:E.actions)?void 0:S.secondary)?void 0:P.font,...null==(O=null==(R=null==(B=e.item)?void 0:B.actions)?void 0:R.secondary)?void 0:O.font}},tertiary:{...null==(z=null==(U=ot.item)?void 0:U.actions)?void 0:z.tertiary,...null==(j=null==(H=e.item)?void 0:H.actions)?void 0:j.tertiary,font:{...null==(G=null==(N=null==(F=ot.item)?void 0:F.actions)?void 0:N.tertiary)?void 0:G.font,...null==(J=null==(X=null==(V=e.item)?void 0:V.actions)?void 0:X.tertiary)?void 0:J.font}},link:{...null==(K=null==(q=ot.item)?void 0:q.actions)?void 0:K.link,...null==(Y=null==(W=e.item)?void 0:W.actions)?void 0:Y.link,font:{...null==(tt=null==(Z=null==(Q=ot.item)?void 0:Q.actions)?void 0:Z.link)?void 0:tt.font,...null==(it=null==(st=null==(et=e.item)?void 0:et.actions)?void 0:st.link)?void 0:it.font}}}}}};class l extends e.CourierThemeManager{constructor(t){super(t),o(this,"THEME_CHANGE_EVENT","courier_toast_theme_change")}getDefaultLightTheme(){return n}getDefaultDarkTheme(){return a}mergeTheme(t,e){return r(t,e)}subscribe(t){return{...super.subscribe(t),manager:this}}}class d{constructor(t,e){o(this,"_callback"),o(this,"_remainingMs"),o(this,"_timerId",null),o(this,"_startedAt",0),o(this,"_isPaused",!1),o(this,"_isDone",!1),this._callback=t,this._remainingMs=e}get isPaused(){return this._isPaused}start(){this._isDone||(this.clear(),this._isPaused=!1,this._startedAt=Date.now(),this._timerId=setTimeout((()=>{this._timerId=null,this._isDone=!0,this._callback()}),this._remainingMs))}pause(){this._isDone||this._isPaused||null===this._timerId||(this._remainingMs=Math.max(0,this._remainingMs-(Date.now()-this._startedAt)),this._isPaused=!0,this.clear())}resume(){!this._isDone&&this._isPaused&&this.start()}cancel(){this._isPaused=!1,this._isDone=!0,this.clear()}clear(){null!==this._timerId&&(clearTimeout(this._timerId),this._timerId=null)}}const u=class t extends e.CourierBaseElement{constructor(t){super(),o(this,"_themeManager"),o(this,"_themeSubscription"),o(this,"_message"),o(this,"_customToastItemContent"),o(this,"_autoDismiss"),o(this,"_autoDismissTimeoutMs"),o(this,"_autoDismissTimeout",null),o(this,"_autoDismissBar",null),o(this,"_onItemDismissedCallback",null),o(this,"_onToastItemClickCallback",null),o(this,"_onToastItemActionClickCallback",null),this._message=t.message,this._autoDismiss=t.autoDismiss,this._autoDismissTimeoutMs=t.autoDismissTimeoutMs,this._themeManager=t.themeManager,this._themeSubscription=this._themeManager.subscribe((t=>{this.render()}))}onItemDismissed(t){this._onItemDismissedCallback=t}onToastItemClick(t){this._onToastItemClickCallback=t,this.render()}onToastItemActionClick(t){this._onToastItemActionClickCallback=t,this.render()}setToastItemContent(t){this._customToastItemContent=t}dismiss(e=t.dismissAnimationTimeoutMs){var s;null==(s=this._autoDismissTimeout)||s.cancel(),this.classList.add("dismissing"),setTimeout((()=>{this.remove(),this._onItemDismissedCallback&&this._onItemDismissedCallback({message:this._message})}),e)}pauseAutoDismiss(){var t;null==(t=this._autoDismissTimeout)||t.pause(),this.syncAutoDismissBarPlayState()}resumeAutoDismiss(){var t;null==(t=this._autoDismissTimeout)||t.resume(),this.syncAutoDismissBarPlayState()}syncAutoDismissBarPlayState(){var t;this._autoDismissBar&&(this._autoDismissBar.style.animationPlayState=(null==(t=this._autoDismissTimeout)?void 0:t.isPaused)?"paused":"running")}onComponentMounted(){this.render(),this._autoDismiss&&(this._autoDismissTimeout=new d((()=>this.dismiss()),this._autoDismissTimeoutMs),this._autoDismissTimeout.start())}onComponentUnmounted(){var t;this._themeSubscription.unsubscribe(),null==(t=this._autoDismissTimeout)||t.cancel()}get theme(){return this._themeManager.getTheme()}static get id(){return"courier-toast-item"}static get observedAttributes(){return[]}render(){for(var t,s,i,o,n;this.firstChild;)this.removeChild(this.firstChild);this.removeEventListener("click",this.onClick);const a=document.createElement("div");if(a.classList.add("overflow-hidden-container"),this.appendChild(a),this._autoDismiss){const e=document.createElement("div");e.classList.add("auto-dismiss"),(null==(t=this._autoDismissTimeout)?void 0:t.isPaused)&&(e.style.animationPlayState="paused"),a.append(e),this._autoDismissBar=e}this._customToastItemContent?a.appendChild(this._customToastItemContent({message:this._message,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs})):a.appendChild(this.createDefaultContent()),this._onToastItemClickCallback&&this.classList.add("clickable"),this.addEventListener("click",this.onClick);const r=new e.CourierIcon(null==(i=null==(s=this.theme.item)?void 0:s.dismissIcon)?void 0:i.color,null==(n=null==(o=this.theme.item)?void 0:o.dismissIcon)?void 0:n.svg);r.classList.add("dismiss"),r.addEventListener("click",(t=>{t.stopPropagation(),this.remove(),this._onItemDismissedCallback&&this._onItemDismissedCallback({message:this._message})})),this.appendChild(r)}createDefaultContent(){var t,s;const i=document.createElement("div");i.classList.add("content"),this.append(i);const o=null==(t=this.theme.item)?void 0:t.icon;if(!1!==(null==o?void 0:o.visible)){const t=new e.CourierIcon(null==o?void 0:o.color,null==o?void 0:o.svg);t.classList.add("icon"),i.appendChild(t)}const n=document.createElement("div");n.classList.add("text-content"),i.appendChild(n);const a=document.createElement("p");a.classList.add("title"),a.textContent=this._message.title??"",n.appendChild(a);const r=document.createElement("p");if(r.classList.add("body"),r.textContent=this._message.preview??this._message.body??"",n.appendChild(r),this.messageHasActions){const t=document.createElement("div");t.classList.add("actions-container"),n.appendChild(t),null==(s=this._message.actions)||s.forEach((e=>{const s=this.createActionButton(e);t.appendChild(s)}))}return i}get messageHasActions(){return this._message.actions&&this._message.actions.length>0}createActionButton(t){var s;const i=null==(s=this._themeManager.getTheme().item)?void 0:s.actions;return new e.CourierButton({mode:this._themeManager.mode,text:t.content,...e.courierActionButtonProps(t,i),onClick:()=>{this._onToastItemActionClickCallback&&this._onToastItemActionClickCallback({message:this._message,action:t})}})}onClick(t){t.stopPropagation(),this._onToastItemClickCallback&&this._onToastItemClickCallback({message:this._message})}};o(u,"dismissAnimationTimeoutMs",300);let h=u;e.registerElement(h);const m=class t{constructor(){o(this,"_dataset",[]),o(this,"_datastoreListeners",[]),o(this,"_removeMessageEventListener")}static get shared(){return t.instance||(t.instance=new t),t.instance}addDatastoreListener(t){this._datastoreListeners.push(t)}removeDatastoreListener(t){this._datastoreListeners=this._datastoreListeners.filter((e=>e!==t))}async listenForMessages(){var t,e,i,o,n,a,r;try{const r=null==(t=s.Courier.shared.client)?void 0:t.inbox.socket;if(!r)return void(null==(i=null==(e=s.Courier.shared.client)?void 0:e.options.logger)||i.info("CourierInbox socket not available"));if(this._removeMessageEventListener&&this._removeMessageEventListener(),this._removeMessageEventListener=r.addMessageEventListener((t=>{if(t.event===s.InboxMessageEvent.NewMessage){const e=t.data;this.addMessage(e)}})),r.isConnecting||r.isOpen)return void(null==(a=null==(o=s.Courier.shared.client)?void 0:o.options.logger)||a.info(`Inbox socket already connecting or open for client ID: [${null==(n=s.Courier.shared.client)?void 0:n.options.connectionId}]`));await r.connect()}catch(l){null==(r=s.Courier.shared.client)||r.options.logger.error("Error listening for messages:",l),this._datastoreListeners.forEach((t=>{var e,s;null==(s=(e=t.events).onError)||s.call(e,l)}))}}toastIndexOfMessage(t){const e=this._dataset.findIndex((e=>e.messageId===t.messageId));return e<0?e:this._dataset.length-e-1}addMessage(t){this._dataset.push(t),this._datastoreListeners.forEach((e=>{e.events.onMessageAdd&&e.events.onMessageAdd(t)}))}removeMessage(t){const e=this._dataset.findIndex((e=>e.messageId===t.messageId));e<0||(this._dataset.splice(e,1),this._datastoreListeners.forEach((e=>{e.events.onMessageRemove&&e.events.onMessageRemove(t)})))}};o(m,"instance");let c=m;class g{constructor(t){this.events=t}remove(){c.shared.removeDatastoreListener(this)}}const v=class t extends e.CourierBaseElement{constructor(t){super(),o(this,"_themeManager"),o(this,"_themeSubscription"),o(this,"_toastStyle"),o(this,"_authListener"),o(this,"_datastoreListener"),o(this,"_isHovered",!1),o(this,"_customItemAutoDismissTimeouts",new WeakMap),o(this,"_autoDismiss",!1),o(this,"_autoDismissTimeoutMs",5e3),o(this,"_dismissButtonOption","auto"),o(this,"_customToastItem"),o(this,"_customToastItemContent"),o(this,"_onItemClick"),o(this,"_onItemActionClick"),o(this,"_defaultLayoutProps",{position:"fixed",width:"380px",top:"30px",right:"30px",zIndex:999}),o(this,"onMouseEnter",(()=>{this._isHovered=!0,this.refreshAutoDismissCountdowns()})),o(this,"onMouseLeave",(()=>{this._isHovered=!1,this.refreshAutoDismissCountdowns()})),this._themeManager=(null==t?void 0:t.themeManager)??new l(n),this._themeSubscription=this._themeManager.subscribe((t=>{this.refreshStyles()})),this._datastoreListener=new g({onMessageAdd:this.datastoreAddMessageListener.bind(this),onMessageRemove:this.datastoreRemoveMessageListener.bind(this)})}onToastItemClick(t){this._onItemClick=t}onToastItemActionClick(t){this._onItemActionClick=t}enableAutoDismiss(){this._autoDismiss=!0}disableAutoDismiss(){this._autoDismiss=!1}setAutoDismissTimeoutMs(t){this._autoDismissTimeoutMs=t}setLightTheme(t){this._themeManager.setLightTheme(t)}setDarkTheme(t){this._themeManager.setDarkTheme(t)}setDismissButton(t){this._dismissButtonOption=t,this.refreshStyles()}setMode(t){this._themeManager.setMode(t)}setToastItem(t){this._customToastItem=t}setToastItemContent(t){this._customToastItemContent=t}dismissToastForMessage(t){this.childNodes.forEach((e=>{var s;e.dataset.courierMessageId===t.messageId&&(e instanceof h?e.dismiss():(null==(s=this._customItemAutoDismissTimeouts.get(e))||s.cancel(),e.remove(),this.refreshAutoDismissCountdowns()))}))}onComponentMounted(){this._toastStyle=e.injectGlobalStyle(t.id,this.getStyles(this.theme)),this.addEventListener("mouseenter",this.onMouseEnter),this.addEventListener("mouseleave",this.onMouseLeave),c.shared.addDatastoreListener(this._datastoreListener),s.Courier.shared.addAuthenticationListener(this.authChangedCallback.bind(this)),c.shared.listenForMessages()}onComponentUnmounted(){var t,e;this.removeEventListener("mouseenter",this.onMouseEnter),this.removeEventListener("mouseleave",this.onMouseLeave),this._datastoreListener.remove(),null==(t=this._authListener)||t.remove(),null==(e=this._toastStyle)||e.remove(),this._themeManager.cleanup(),this._themeSubscription.unsubscribe()}refreshAutoDismissCountdowns(){const t=Array.from(this.children),e=t[t.length-1];t.forEach((t=>{this.setItemAutoDismissPaused(t,this._isHovered||t!==e)}))}setItemAutoDismissPaused(t,e){if(t instanceof h)return void(e?t.pauseAutoDismiss():t.resumeAutoDismiss());const s=this._customItemAutoDismissTimeouts.get(t);e?null==s||s.pause():null==s||s.resume()}attributeChangedCallback(e,s,i){switch(e){case"auto-dismiss":"false"===i?this.disableAutoDismiss():this.enableAutoDismiss();break;case"auto-dismiss-timeout-ms":this.setAutoDismissTimeoutMs(parseInt(i,10));break;case"dismiss-button":i&&t.isDismissButtonOption(i)?this.setDismissButton(i):this.setDismissButton("auto");break;case"light-theme":i&&this.setLightTheme(JSON.parse(i));break;case"dark-theme":i&&this.setDarkTheme(JSON.parse(i));break;case"mode":this._themeManager.setMode(i)}}get theme(){return this._themeManager.getTheme()}refreshStyles(){this._toastStyle&&(this._toastStyle.textContent=this.getStyles(this.theme))}authChangedCallback(){this.removeAllItems(),c.shared.listenForMessages()}removeAllItems(){for(var t;this.firstChild;)null==(t=this._customItemAutoDismissTimeouts.get(this.firstChild))||t.cancel(),this.removeChild(this.firstChild)}addToastItem(t){const e=this.createToastItem(t);return e.dataset.courierMessageId=t.messageId,this.appendChild(e),this.resizeContainerToHeight(this.topStackItemHeight),this.refreshAutoDismissCountdowns(),e}createToastItem(t){return this._customToastItem?this.createCustomToastItem(t):this.createDefaultToastItem(t)}createDefaultToastItem(t){const e=new h({message:t,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs,themeManager:this._themeManager});return e.onItemDismissed((t=>{this.resizeContainerToHeight(this.topStackItemHeight),this.refreshAutoDismissCountdowns()})),this._customToastItemContent&&e.setToastItemContent(this._customToastItemContent),this._onItemClick&&e.onToastItemClick(this._onItemClick),e.onToastItemActionClick((t=>{var e,i,o;const n=null==(e=t.action.data)?void 0:e.trackingId;"string"==typeof n&&n&&(null==(i=s.Courier.shared.client)||i.inbox.click({messageId:t.message.messageId,trackingId:n}).catch((t=>{var e,i;return null==(i=null==(e=s.Courier.shared.client)?void 0:e.options.logger)?void 0:i.error("Error clicking toast action:",t)}))),null==(o=this._onItemActionClick)||o.call(this,t)})),e}createCustomToastItem(t){if(!this._customToastItem)throw Error("Attempted to create customToastItem, but none is set");const e=this._customToastItem({message:t,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs});if(this._autoDismiss){const t=new d((()=>{e.remove(),this.refreshAutoDismissCountdowns()}),this._autoDismissTimeoutMs);this._customItemAutoDismissTimeouts.set(e,t),t.start()}return e.addEventListener("click",(()=>{this._onItemClick&&this._onItemClick({message:t})})),e}datastoreAddMessageListener(t){this.addToastItem(t)}datastoreRemoveMessageListener(t){this.dismissToastForMessage(t)}getStyles(e){var s,i,o,n,a,r;const l=e.item;return[`\n ${t.id} {\n position: ${this._defaultLayoutProps.position};\n z-index: ${this._defaultLayoutProps.zIndex};\n top: ${this._defaultLayoutProps.top};\n right: ${this._defaultLayoutProps.right};\n width: ${this._defaultLayoutProps.width};\n }\n `,`\n ${h.id}:last-child {\n top: 0;\n right: 0;\n }\n\n ${h.id}:nth-last-child(2) {\n top: 12px;\n bottom: -12px;\n --scale: 0.95\n }\n\n ${h.id}:nth-last-child(3) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n }\n\n ${h.id}:nth-last-child(n+4) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n visibility: hidden;\n }\n\n ${h.id}:nth-last-child(n+2) > .overflow-hidden-container {\n opacity: 0;\n }\n `,`\n ${h.id} {\n position: absolute;\n box-sizing: border-box;\n width: 100%;\n background-color: ${null==l?void 0:l.backgroundColor};\n box-shadow: ${null==l?void 0:l.shadow};\n border: ${null==l?void 0:l.border};\n border-radius: ${null==l?void 0:l.borderRadius};\n transition: 0.2s ease-in-out;\n cursor: default;\n\n opacity: 0;\n transform: translate(0, -10px) scaleX(var(--scale, 1));\n animation: courier-toast-show 0.3s ease-in-out forwards;\n }\n\n ${h.id} > .overflow-hidden-container {\n height: 100%;\n width: 100%;\n border-radius: ${null==l?void 0:l.borderRadius};\n overflow: hidden;\n }\n\n ${h.id}.dismissing {\n animation: courier-toast-hide 300ms ease-out forwards;\n }\n\n @keyframes courier-toast-show {\n 0% {\n opacity: 0;\n }\n\n 100% {\n opacity: 1;\n transform: scaleX(var(--scale, 1));\n }\n }\n\n /* Lift the toast back out the way it came in rather than blinking it out\n in place, which reads as the toast leaving instead of vanishing. The\n toast is anchored to the top of the viewport, so "out" is up: a full\n translateY of its own height, eased so most of the travel happens\n early and the tail is imperceptible. */\n /* Shrink the toast slightly as it fades so it reads as receding rather\n than blinking out, but keep it where it sits — moving it competes with\n the toast underneath sliding up to take its place. The stack's own\n horizontal scale is preserved so a toast dismissed from behind the top\n one doesn't jump to full width on its way out. */\n @keyframes courier-toast-hide {\n 0% {\n opacity: 1;\n transform: scale(1) scaleX(var(--scale, 1));\n }\n\n 100% {\n opacity: 0;\n transform: scale(0.92) scaleX(var(--scale, 1));\n }\n }\n\n ${h.id}.clickable:last-child {\n cursor: pointer;\n }\n\n ${h.id}.clickable:last-child:hover {\n background-color: ${null==l?void 0:l.hoverBackgroundColor};\n }\n\n ${h.id}.clickable:last-child:active {\n background-color: ${null==l?void 0:l.activeBackgroundColor};\n }\n\n ${h.id}.clickable:nth-last-child(n+2) {\n pointer-events: none;\n }\n `,`\n ${h.id} > .dismiss {\n position: absolute;\n visibility: hidden;\n opacity: 0%;\n top: -10px;\n right: -10px;\n background-color: ${null==l?void 0:l.backgroundColor};\n border: ${null==l?void 0:l.border};\n padding: 3px;\n border-radius: 50%;\n font-size: 12pt;\n box-shadow: ${null==l?void 0:l.shadow};\n cursor: pointer;\n transition: 0.2s ease-in-out;\n }\n\n ${h.id} > .dismiss:hover {\n background-color: ${null==l?void 0:l.hoverBackgroundColor};\n }\n\n ${h.id} > .dismiss:active {\n background-color: ${null==l?void 0:l.activeBackgroundColor};\n }\n\n ${h.id}:last-child${this.showDismissOnHover?":hover":""} > .dismiss {\n visibility: ${this.showDismiss?"visible":"hidden"};\n opacity: 100%;\n transition: 0.2s ease-in-out;\n }\n `,`\n ${h.id} > .overflow-hidden-container > .auto-dismiss {\n width: 100%;\n height: 5px;\n background-color: ${null==l?void 0:l.autoDismissBarColor};\n animation: courier-toast-auto-dismiss ${this._autoDismissTimeoutMs}ms linear forwards;\n }\n\n @keyframes courier-toast-auto-dismiss {\n 100% {\n width: 0px;\n }\n }\n `,`\n ${h.id} > .overflow-hidden-container > .content {\n display: flex;\n gap: 12px;\n align-items: center;\n align-self: stretch;\n box-sizing: border-box;\n padding: 12px;\n }\n\n ${h.id} > .overflow-hidden-container > .content > .text-content {\n }\n\n ${h.id} > .overflow-hidden-container > .content > .icon {\n }\n\n ${h.id} > .overflow-hidden-container > .content > .text-content > .title {\n margin: 0;\n /* Keep room for the dismiss button, which overhangs this corner. */\n padding-right: 16px;\n font-weight: ${null==(s=null==l?void 0:l.title)?void 0:s.weight};\n font-size: ${null==(i=null==l?void 0:l.title)?void 0:i.size};\n color: ${null==(o=null==l?void 0:l.title)?void 0:o.color};\n }\n\n ${h.id} > .overflow-hidden-container > .content > .text-content > .body {\n margin: 8px 0 0 0;\n font-weight: ${null==(n=null==l?void 0:l.body)?void 0:n.weight};\n font-size: ${null==(a=null==l?void 0:l.body)?void 0:a.size};\n line-height: 150%;\n color: ${null==(r=null==l?void 0:l.body)?void 0:r.color};\n }\n `,`\n ${h.id} > .overflow-hidden-container > .content > .text-content > .actions-container {\n display: flex;\n /* Stretch rather than center so actions with different border widths still line up. */\n align-items: stretch;\n gap: 8px;\n margin-top: 12px;\n }\n `].join("")}get topStackItemHeight(){if(this.lastChild){return`${this.lastChild.getBoundingClientRect().height}px`}return"0px"}resizeContainerToHeight(t){this.style.height=t}get showDismissOnHover(){return!(!this._autoDismiss||"auto"!==this._dismissButtonOption)||"hover"===this._dismissButtonOption}get showDismiss(){return"hidden"!==this._dismissButtonOption}static get id(){return"courier-toast"}static isDismissButtonOption(t){return["visible","hidden","hover","auto"].includes(t)}};o(v,"observedAttributes",["auto-dismiss","auto-dismiss-timeout-ms","dismiss-button","light-theme","dark-theme","mode"]);let _=v;e.registerElement(_);s.Courier.shared.courierUserAgentName="courier-ui-toast",s.Courier.shared.courierUserAgentVersion="2.4.1",Object.defineProperty(t,"Courier",{enumerable:!0,get:()=>s.Courier}),Object.defineProperty(t,"DEFAULT_COURIER_API_URLS",{enumerable:!0,get:()=>s.DEFAULT_COURIER_API_URLS}),Object.defineProperty(t,"EU_COURIER_API_URLS",{enumerable:!0,get:()=>s.EU_COURIER_API_URLS}),Object.defineProperty(t,"getCourierApiUrls",{enumerable:!0,get:()=>s.getCourierApiUrls}),Object.defineProperty(t,"getCourierApiUrlsForRegion",{enumerable:!0,get:()=>s.getCourierApiUrlsForRegion}),t.CourierToast=_,t.CourierToastDatastore=c,t.CourierToastDatastoreEvents=class{onMessageAdd(t){}onMessageRemove(t){}onError(t){}},t.CourierToastDatastoreListener=g,t.CourierToastItem=h,t.CourierToastThemeManager=l,t.defaultDarkTheme=a,t.defaultLightTheme=n,t.mergeTheme=r,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@trycourier/courier-ui-core"),require("@trycourier/courier-js")):"function"==typeof define&&define.amd?define(["exports","@trycourier/courier-ui-core","@trycourier/courier-js"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CourierUIToast={},t.CourierUICore,t.CourierJS)}(this,(function(t,e,s){"use strict";var i=Object.defineProperty,o=(t,e,s)=>((t,e,s)=>e in t?i(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s)(t,"symbol"!=typeof e?e+"":e,s);const n={item:{backgroundColor:e.CourierColors.white[500],hoverBackgroundColor:e.CourierColors.gray[200],activeBackgroundColor:e.CourierColors.gray[500],shadow:`0px 4px 8px -2px ${e.CourierColors.black[50020]}`,border:`1px solid ${e.CourierColors.gray[500]}`,borderRadius:"8px",title:{size:"11pt",weight:"400",color:e.CourierColors.black[500]},body:{size:"11pt",weight:"400",color:e.CourierColors.gray[600]},icon:{color:e.CourierColors.black[500],svg:e.CourierIconSVGs.inbox},dismissIcon:{color:e.CourierColors.black[500],svg:e.CourierIconSVGs.remove},autoDismissBarColor:e.CourierColors.blue[400]}},a={item:{backgroundColor:e.CourierColors.black[500],hoverBackgroundColor:e.CourierColors.gray[800],activeBackgroundColor:e.CourierColors.gray[700],shadow:`0px 4px 8px -2px ${e.CourierColors.gray[400]}`,border:`1px solid ${e.CourierColors.gray[400]}`,borderRadius:"8px",title:{size:"11pt",weight:"400",color:e.CourierColors.white[500]},body:{size:"11pt",weight:"400",color:e.CourierColors.gray[500]},icon:{color:e.CourierColors.white[500],svg:e.CourierIconSVGs.inbox},dismissIcon:{color:e.CourierColors.white[500],svg:e.CourierIconSVGs.remove},autoDismissBarColor:e.CourierColors.blue[400]}},r=(t,e)=>{var s,i,o,r,l,d,u,h,m,c,g,v,_,C,p,b,f,I,k,D,T,y,M,w,x,A,L,$,E,S,P,B,R,O,U,z,H,j,F,N,G,V,X,J,q,K,W,Y,Q,Z,tt,et,st,it;const ot="light"===t?n:a;return{item:{...ot.item,...e.item,title:{...null==(s=ot.item)?void 0:s.title,...null==(i=e.item)?void 0:i.title},body:{...null==(o=ot.item)?void 0:o.body,...null==(r=e.item)?void 0:r.body},icon:{...null==(l=ot.item)?void 0:l.icon,...null==(d=e.item)?void 0:d.icon},dismissIcon:{...null==(u=ot.item)?void 0:u.dismissIcon,...null==(h=e.item)?void 0:h.dismissIcon},actions:{...null==(m=ot.item)?void 0:m.actions,...null==(c=e.item)?void 0:c.actions,font:{...null==(v=null==(g=ot.item)?void 0:g.actions)?void 0:v.font,...null==(C=null==(_=e.item)?void 0:_.actions)?void 0:C.font},button:{...null==(b=null==(p=ot.item)?void 0:p.actions)?void 0:b.button,...null==(I=null==(f=e.item)?void 0:f.actions)?void 0:I.button,font:{...null==(T=null==(D=null==(k=ot.item)?void 0:k.actions)?void 0:D.button)?void 0:T.font,...null==(w=null==(M=null==(y=e.item)?void 0:y.actions)?void 0:M.button)?void 0:w.font}},secondary:{...null==(A=null==(x=ot.item)?void 0:x.actions)?void 0:A.secondary,...null==($=null==(L=e.item)?void 0:L.actions)?void 0:$.secondary,font:{...null==(P=null==(S=null==(E=ot.item)?void 0:E.actions)?void 0:S.secondary)?void 0:P.font,...null==(O=null==(R=null==(B=e.item)?void 0:B.actions)?void 0:R.secondary)?void 0:O.font}},tertiary:{...null==(z=null==(U=ot.item)?void 0:U.actions)?void 0:z.tertiary,...null==(j=null==(H=e.item)?void 0:H.actions)?void 0:j.tertiary,font:{...null==(G=null==(N=null==(F=ot.item)?void 0:F.actions)?void 0:N.tertiary)?void 0:G.font,...null==(J=null==(X=null==(V=e.item)?void 0:V.actions)?void 0:X.tertiary)?void 0:J.font}},link:{...null==(K=null==(q=ot.item)?void 0:q.actions)?void 0:K.link,...null==(Y=null==(W=e.item)?void 0:W.actions)?void 0:Y.link,font:{...null==(tt=null==(Z=null==(Q=ot.item)?void 0:Q.actions)?void 0:Z.link)?void 0:tt.font,...null==(it=null==(st=null==(et=e.item)?void 0:et.actions)?void 0:st.link)?void 0:it.font}}}}}};class l extends e.CourierThemeManager{constructor(t){super(t),o(this,"THEME_CHANGE_EVENT","courier_toast_theme_change")}getDefaultLightTheme(){return n}getDefaultDarkTheme(){return a}mergeTheme(t,e){return r(t,e)}subscribe(t){return{...super.subscribe(t),manager:this}}}class d{constructor(t,e){o(this,"_callback"),o(this,"_remainingMs"),o(this,"_timerId",null),o(this,"_startedAt",0),o(this,"_isPaused",!1),o(this,"_isDone",!1),this._callback=t,this._remainingMs=e}get isPaused(){return this._isPaused}start(){this._isDone||(this.clear(),this._isPaused=!1,this._startedAt=Date.now(),this._timerId=setTimeout((()=>{this._timerId=null,this._isDone=!0,this._callback()}),this._remainingMs))}pause(){this._isDone||this._isPaused||null===this._timerId||(this._remainingMs=Math.max(0,this._remainingMs-(Date.now()-this._startedAt)),this._isPaused=!0,this.clear())}resume(){!this._isDone&&this._isPaused&&this.start()}cancel(){this._isPaused=!1,this._isDone=!0,this.clear()}clear(){null!==this._timerId&&(clearTimeout(this._timerId),this._timerId=null)}}const u=class t extends e.CourierBaseElement{constructor(t){super(),o(this,"_themeManager"),o(this,"_themeSubscription"),o(this,"_message"),o(this,"_customToastItemContent"),o(this,"_autoDismiss"),o(this,"_autoDismissTimeoutMs"),o(this,"_autoDismissTimeout",null),o(this,"_autoDismissBar",null),o(this,"_onItemDismissedCallback",null),o(this,"_onToastItemClickCallback",null),o(this,"_onToastItemActionClickCallback",null),this._message=t.message,this._autoDismiss=t.autoDismiss,this._autoDismissTimeoutMs=t.autoDismissTimeoutMs,this._themeManager=t.themeManager,this._themeSubscription=this._themeManager.subscribe((t=>{this.render()}))}onItemDismissed(t){this._onItemDismissedCallback=t}onToastItemClick(t){this._onToastItemClickCallback=t,this.render()}onToastItemActionClick(t){this._onToastItemActionClickCallback=t,this.render()}setToastItemContent(t){this._customToastItemContent=t}dismiss(e=t.dismissAnimationTimeoutMs){var s;null==(s=this._autoDismissTimeout)||s.cancel(),this.classList.add("dismissing"),setTimeout((()=>{this.remove(),this._onItemDismissedCallback&&this._onItemDismissedCallback({message:this._message})}),e)}pauseAutoDismiss(){var t;null==(t=this._autoDismissTimeout)||t.pause(),this.syncAutoDismissBarPlayState()}resumeAutoDismiss(){var t;null==(t=this._autoDismissTimeout)||t.resume(),this.syncAutoDismissBarPlayState()}syncAutoDismissBarPlayState(){var t;this._autoDismissBar&&(this._autoDismissBar.style.animationPlayState=(null==(t=this._autoDismissTimeout)?void 0:t.isPaused)?"paused":"running")}onComponentMounted(){this.render(),this._autoDismiss&&(this._autoDismissTimeout=new d((()=>this.dismiss()),this._autoDismissTimeoutMs),this._autoDismissTimeout.start())}onComponentUnmounted(){var t;this._themeSubscription.unsubscribe(),null==(t=this._autoDismissTimeout)||t.cancel()}get theme(){return this._themeManager.getTheme()}static get id(){return"courier-toast-item"}static get observedAttributes(){return[]}render(){for(var t,s,i,o,n;this.firstChild;)this.removeChild(this.firstChild);this.removeEventListener("click",this.onClick);const a=document.createElement("div");if(a.classList.add("overflow-hidden-container"),this.appendChild(a),this._autoDismiss){const e=document.createElement("div");e.classList.add("auto-dismiss"),(null==(t=this._autoDismissTimeout)?void 0:t.isPaused)&&(e.style.animationPlayState="paused"),a.append(e),this._autoDismissBar=e}this._customToastItemContent?a.appendChild(this._customToastItemContent({message:this._message,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs})):a.appendChild(this.createDefaultContent()),this._onToastItemClickCallback&&this.classList.add("clickable"),this.addEventListener("click",this.onClick);const r=new e.CourierIcon(null==(i=null==(s=this.theme.item)?void 0:s.dismissIcon)?void 0:i.color,null==(n=null==(o=this.theme.item)?void 0:o.dismissIcon)?void 0:n.svg);r.classList.add("dismiss"),r.addEventListener("click",(t=>{t.stopPropagation(),this.remove(),this._onItemDismissedCallback&&this._onItemDismissedCallback({message:this._message})})),this.appendChild(r)}createDefaultContent(){var t,s;const i=document.createElement("div");i.classList.add("content"),this.append(i);const o=null==(t=this.theme.item)?void 0:t.icon;if(!1!==(null==o?void 0:o.visible)){const t=new e.CourierIcon(null==o?void 0:o.color,null==o?void 0:o.svg);t.classList.add("icon"),i.appendChild(t)}const n=document.createElement("div");n.classList.add("text-content"),i.appendChild(n);const a=document.createElement("p");a.classList.add("title"),a.textContent=this._message.title??"",n.appendChild(a);const r=document.createElement("p");if(r.classList.add("body"),r.textContent=this._message.preview??this._message.body??"",n.appendChild(r),this.messageHasActions){const t=document.createElement("div");t.classList.add("actions-container"),n.appendChild(t),null==(s=this._message.actions)||s.forEach((e=>{const s=this.createActionButton(e);t.appendChild(s)}))}return i}get messageHasActions(){return this._message.actions&&this._message.actions.length>0}createActionButton(t){var s;const i=null==(s=this._themeManager.getTheme().item)?void 0:s.actions;return new e.CourierButton({mode:this._themeManager.mode,text:t.content,...e.courierActionButtonProps(t,i),onClick:()=>{this._onToastItemActionClickCallback&&this._onToastItemActionClickCallback({message:this._message,action:t})}})}onClick(t){t.stopPropagation(),this._onToastItemClickCallback&&this._onToastItemClickCallback({message:this._message})}};o(u,"dismissAnimationTimeoutMs",300);let h=u;e.registerElement(h);const m=class t{constructor(){o(this,"_dataset",[]),o(this,"_datastoreListeners",[]),o(this,"_removeMessageEventListener")}static get shared(){return t.instance||(t.instance=new t),t.instance}addDatastoreListener(t){this._datastoreListeners.push(t)}removeDatastoreListener(t){this._datastoreListeners=this._datastoreListeners.filter((e=>e!==t))}async listenForMessages(){var t,e,i,o,n,a,r;try{const r=null==(t=s.Courier.shared.client)?void 0:t.inbox.socket;if(!r)return void(null==(i=null==(e=s.Courier.shared.client)?void 0:e.options.logger)||i.info("CourierInbox socket not available"));if(this._removeMessageEventListener&&this._removeMessageEventListener(),this._removeMessageEventListener=r.addMessageEventListener((t=>{if(t.event===s.InboxMessageEvent.NewMessage){const e=t.data;this.addMessage(e)}})),r.isConnecting||r.isOpen)return void(null==(a=null==(o=s.Courier.shared.client)?void 0:o.options.logger)||a.info(`Inbox socket already connecting or open for client ID: [${null==(n=s.Courier.shared.client)?void 0:n.options.connectionId}]`));await r.connect()}catch(l){null==(r=s.Courier.shared.client)||r.options.logger.error("Error listening for messages:",l),this._datastoreListeners.forEach((t=>{var e,s;null==(s=(e=t.events).onError)||s.call(e,l)}))}}toastIndexOfMessage(t){const e=this._dataset.findIndex((e=>e.messageId===t.messageId));return e<0?e:this._dataset.length-e-1}addMessage(t){this._dataset.push(t),this._datastoreListeners.forEach((e=>{e.events.onMessageAdd&&e.events.onMessageAdd(t)}))}removeMessage(t){const e=this._dataset.findIndex((e=>e.messageId===t.messageId));e<0||(this._dataset.splice(e,1),this._datastoreListeners.forEach((e=>{e.events.onMessageRemove&&e.events.onMessageRemove(t)})))}};o(m,"instance");let c=m;class g{constructor(t){this.events=t}remove(){c.shared.removeDatastoreListener(this)}}const v=class t extends e.CourierBaseElement{constructor(t){super(),o(this,"_themeManager"),o(this,"_themeSubscription"),o(this,"_toastStyle"),o(this,"_authListener"),o(this,"_datastoreListener"),o(this,"_isHovered",!1),o(this,"_customItemAutoDismissTimeouts",new WeakMap),o(this,"_autoDismiss",!1),o(this,"_autoDismissTimeoutMs",5e3),o(this,"_dismissButtonOption","auto"),o(this,"_customToastItem"),o(this,"_customToastItemContent"),o(this,"_onItemClick"),o(this,"_onItemActionClick"),o(this,"_defaultLayoutProps",{position:"fixed",width:"380px",top:"30px",right:"30px",zIndex:999}),o(this,"onMouseEnter",(()=>{this._isHovered=!0,this.refreshAutoDismissCountdowns()})),o(this,"onMouseLeave",(()=>{this._isHovered=!1,this.refreshAutoDismissCountdowns()})),this._themeManager=(null==t?void 0:t.themeManager)??new l(n),this._themeSubscription=this._themeManager.subscribe((t=>{this.refreshStyles()})),this._datastoreListener=new g({onMessageAdd:this.datastoreAddMessageListener.bind(this),onMessageRemove:this.datastoreRemoveMessageListener.bind(this)})}onToastItemClick(t){this._onItemClick=t}onToastItemActionClick(t){this._onItemActionClick=t}enableAutoDismiss(){this._autoDismiss=!0}disableAutoDismiss(){this._autoDismiss=!1}setAutoDismissTimeoutMs(t){this._autoDismissTimeoutMs=t}setLightTheme(t){this._themeManager.setLightTheme(t)}setDarkTheme(t){this._themeManager.setDarkTheme(t)}setDismissButton(t){this._dismissButtonOption=t,this.refreshStyles()}setMode(t){this._themeManager.setMode(t)}setToastItem(t){this._customToastItem=t}setToastItemContent(t){this._customToastItemContent=t}dismissToastForMessage(t){this.childNodes.forEach((e=>{var s;e.dataset.courierMessageId===t.messageId&&(e instanceof h?e.dismiss():(null==(s=this._customItemAutoDismissTimeouts.get(e))||s.cancel(),e.remove(),this.refreshAutoDismissCountdowns()))}))}onComponentMounted(){this._toastStyle=e.injectGlobalStyle(t.id,this.getStyles(this.theme)),this.addEventListener("mouseenter",this.onMouseEnter),this.addEventListener("mouseleave",this.onMouseLeave),c.shared.addDatastoreListener(this._datastoreListener),s.Courier.shared.addAuthenticationListener(this.authChangedCallback.bind(this)),c.shared.listenForMessages()}onComponentUnmounted(){var t,e;this.removeEventListener("mouseenter",this.onMouseEnter),this.removeEventListener("mouseleave",this.onMouseLeave),this._datastoreListener.remove(),null==(t=this._authListener)||t.remove(),null==(e=this._toastStyle)||e.remove(),this._themeManager.cleanup(),this._themeSubscription.unsubscribe()}refreshAutoDismissCountdowns(){const t=Array.from(this.children),e=t[t.length-1];t.forEach((t=>{this.setItemAutoDismissPaused(t,this._isHovered||t!==e)}))}setItemAutoDismissPaused(t,e){if(t instanceof h)return void(e?t.pauseAutoDismiss():t.resumeAutoDismiss());const s=this._customItemAutoDismissTimeouts.get(t);e?null==s||s.pause():null==s||s.resume()}attributeChangedCallback(e,s,i){switch(e){case"auto-dismiss":"false"===i?this.disableAutoDismiss():this.enableAutoDismiss();break;case"auto-dismiss-timeout-ms":this.setAutoDismissTimeoutMs(parseInt(i,10));break;case"dismiss-button":i&&t.isDismissButtonOption(i)?this.setDismissButton(i):this.setDismissButton("auto");break;case"light-theme":i&&this.setLightTheme(JSON.parse(i));break;case"dark-theme":i&&this.setDarkTheme(JSON.parse(i));break;case"mode":this._themeManager.setMode(i)}}get theme(){return this._themeManager.getTheme()}refreshStyles(){this._toastStyle&&(this._toastStyle.textContent=this.getStyles(this.theme))}authChangedCallback(){this.removeAllItems(),c.shared.listenForMessages()}removeAllItems(){for(var t;this.firstChild;)null==(t=this._customItemAutoDismissTimeouts.get(this.firstChild))||t.cancel(),this.removeChild(this.firstChild)}addToastItem(t){const e=this.createToastItem(t);return e.dataset.courierMessageId=t.messageId,this.appendChild(e),this.resizeContainerToHeight(this.topStackItemHeight),this.refreshAutoDismissCountdowns(),e}createToastItem(t){return this._customToastItem?this.createCustomToastItem(t):this.createDefaultToastItem(t)}createDefaultToastItem(t){const e=new h({message:t,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs,themeManager:this._themeManager});return e.onItemDismissed((t=>{this.resizeContainerToHeight(this.topStackItemHeight),this.refreshAutoDismissCountdowns()})),this._customToastItemContent&&e.setToastItemContent(this._customToastItemContent),this._onItemClick&&e.onToastItemClick(this._onItemClick),e.onToastItemActionClick((t=>{var e,i,o;const n=null==(e=t.action.data)?void 0:e.trackingId;"string"==typeof n&&n&&(null==(i=s.Courier.shared.client)||i.inbox.click({messageId:t.message.messageId,trackingId:n}).catch((t=>{var e,i;return null==(i=null==(e=s.Courier.shared.client)?void 0:e.options.logger)?void 0:i.error("Error clicking toast action:",t)}))),null==(o=this._onItemActionClick)||o.call(this,t)})),e}createCustomToastItem(t){if(!this._customToastItem)throw Error("Attempted to create customToastItem, but none is set");const e=this._customToastItem({message:t,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs});if(this._autoDismiss){const t=new d((()=>{e.remove(),this.refreshAutoDismissCountdowns()}),this._autoDismissTimeoutMs);this._customItemAutoDismissTimeouts.set(e,t),t.start()}return e.addEventListener("click",(()=>{this._onItemClick&&this._onItemClick({message:t})})),e}datastoreAddMessageListener(t){this.addToastItem(t)}datastoreRemoveMessageListener(t){this.dismissToastForMessage(t)}getStyles(e){var s,i,o,n,a,r;const l=e.item;return[`\n ${t.id} {\n position: ${this._defaultLayoutProps.position};\n z-index: ${this._defaultLayoutProps.zIndex};\n top: ${this._defaultLayoutProps.top};\n right: ${this._defaultLayoutProps.right};\n width: ${this._defaultLayoutProps.width};\n }\n `,`\n ${h.id}:last-child {\n top: 0;\n right: 0;\n }\n\n ${h.id}:nth-last-child(2) {\n top: 12px;\n bottom: -12px;\n --scale: 0.95\n }\n\n ${h.id}:nth-last-child(3) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n }\n\n ${h.id}:nth-last-child(n+4) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n visibility: hidden;\n }\n\n ${h.id}:nth-last-child(n+2) > .overflow-hidden-container {\n opacity: 0;\n }\n `,`\n ${h.id} {\n position: absolute;\n box-sizing: border-box;\n width: 100%;\n background-color: ${null==l?void 0:l.backgroundColor};\n box-shadow: ${null==l?void 0:l.shadow};\n border: ${null==l?void 0:l.border};\n border-radius: ${null==l?void 0:l.borderRadius};\n transition: 0.2s ease-in-out;\n cursor: default;\n\n opacity: 0;\n transform: translate(0, -10px) scaleX(var(--scale, 1));\n animation: courier-toast-show 0.3s ease-in-out forwards;\n }\n\n ${h.id} > .overflow-hidden-container {\n height: 100%;\n width: 100%;\n border-radius: ${null==l?void 0:l.borderRadius};\n overflow: hidden;\n }\n\n ${h.id}.dismissing {\n animation: courier-toast-hide 300ms ease-out forwards;\n }\n\n @keyframes courier-toast-show {\n 0% {\n opacity: 0;\n }\n\n 100% {\n opacity: 1;\n transform: scaleX(var(--scale, 1));\n }\n }\n\n /* Lift the toast back out the way it came in rather than blinking it out\n in place, which reads as the toast leaving instead of vanishing. The\n toast is anchored to the top of the viewport, so "out" is up: a full\n translateY of its own height, eased so most of the travel happens\n early and the tail is imperceptible. */\n /* Shrink the toast slightly as it fades so it reads as receding rather\n than blinking out, but keep it where it sits — moving it competes with\n the toast underneath sliding up to take its place. The stack's own\n horizontal scale is preserved so a toast dismissed from behind the top\n one doesn't jump to full width on its way out. */\n @keyframes courier-toast-hide {\n 0% {\n opacity: 1;\n transform: scale(1) scaleX(var(--scale, 1));\n }\n\n 100% {\n opacity: 0;\n transform: scale(0.92) scaleX(var(--scale, 1));\n }\n }\n\n ${h.id}.clickable:last-child {\n cursor: pointer;\n }\n\n ${h.id}.clickable:last-child:hover {\n background-color: ${null==l?void 0:l.hoverBackgroundColor};\n }\n\n ${h.id}.clickable:last-child:active {\n background-color: ${null==l?void 0:l.activeBackgroundColor};\n }\n\n ${h.id}.clickable:nth-last-child(n+2) {\n pointer-events: none;\n }\n `,`\n ${h.id} > .dismiss {\n position: absolute;\n visibility: hidden;\n opacity: 0%;\n top: -10px;\n right: -10px;\n background-color: ${null==l?void 0:l.backgroundColor};\n border: ${null==l?void 0:l.border};\n padding: 3px;\n border-radius: 50%;\n font-size: 12pt;\n box-shadow: ${null==l?void 0:l.shadow};\n cursor: pointer;\n transition: 0.2s ease-in-out;\n }\n\n ${h.id} > .dismiss:hover {\n background-color: ${null==l?void 0:l.hoverBackgroundColor};\n }\n\n ${h.id} > .dismiss:active {\n background-color: ${null==l?void 0:l.activeBackgroundColor};\n }\n\n ${h.id}:last-child${this.showDismissOnHover?":hover":""} > .dismiss {\n visibility: ${this.showDismiss?"visible":"hidden"};\n opacity: 100%;\n transition: 0.2s ease-in-out;\n }\n `,`\n ${h.id} > .overflow-hidden-container > .auto-dismiss {\n width: 100%;\n height: 5px;\n background-color: ${null==l?void 0:l.autoDismissBarColor};\n animation: courier-toast-auto-dismiss ${this._autoDismissTimeoutMs}ms linear forwards;\n }\n\n @keyframes courier-toast-auto-dismiss {\n 100% {\n width: 0px;\n }\n }\n `,`\n ${h.id} > .overflow-hidden-container > .content {\n display: flex;\n gap: 12px;\n align-items: center;\n align-self: stretch;\n box-sizing: border-box;\n padding: 12px;\n }\n\n ${h.id} > .overflow-hidden-container > .content > .text-content {\n }\n\n ${h.id} > .overflow-hidden-container > .content > .icon {\n }\n\n ${h.id} > .overflow-hidden-container > .content > .text-content > .title {\n margin: 0;\n /* Keep room for the dismiss button, which overhangs this corner. */\n padding-right: 16px;\n font-weight: ${null==(s=null==l?void 0:l.title)?void 0:s.weight};\n font-size: ${null==(i=null==l?void 0:l.title)?void 0:i.size};\n color: ${null==(o=null==l?void 0:l.title)?void 0:o.color};\n }\n\n ${h.id} > .overflow-hidden-container > .content > .text-content > .body {\n margin: 8px 0 0 0;\n font-weight: ${null==(n=null==l?void 0:l.body)?void 0:n.weight};\n font-size: ${null==(a=null==l?void 0:l.body)?void 0:a.size};\n line-height: 150%;\n color: ${null==(r=null==l?void 0:l.body)?void 0:r.color};\n }\n `,`\n ${h.id} > .overflow-hidden-container > .content > .text-content > .actions-container {\n display: flex;\n /* Stretch rather than center so actions with different border widths still line up. */\n align-items: stretch;\n gap: 8px;\n margin-top: 12px;\n }\n `].join("")}get topStackItemHeight(){if(this.lastChild){return`${this.lastChild.getBoundingClientRect().height}px`}return"0px"}resizeContainerToHeight(t){this.style.height=t}get showDismissOnHover(){return!(!this._autoDismiss||"auto"!==this._dismissButtonOption)||"hover"===this._dismissButtonOption}get showDismiss(){return"hidden"!==this._dismissButtonOption}static get id(){return"courier-toast"}static isDismissButtonOption(t){return["visible","hidden","hover","auto"].includes(t)}};o(v,"observedAttributes",["auto-dismiss","auto-dismiss-timeout-ms","dismiss-button","light-theme","dark-theme","mode"]);let _=v;e.registerElement(_);s.Courier.shared.courierUserAgentName="courier-ui-toast",s.Courier.shared.courierUserAgentVersion="2.4.2",Object.defineProperty(t,"Courier",{enumerable:!0,get:()=>s.Courier}),Object.defineProperty(t,"DEFAULT_COURIER_API_URLS",{enumerable:!0,get:()=>s.DEFAULT_COURIER_API_URLS}),Object.defineProperty(t,"EU_COURIER_API_URLS",{enumerable:!0,get:()=>s.EU_COURIER_API_URLS}),Object.defineProperty(t,"getCourierApiUrls",{enumerable:!0,get:()=>s.getCourierApiUrls}),Object.defineProperty(t,"getCourierApiUrlsForRegion",{enumerable:!0,get:()=>s.getCourierApiUrlsForRegion}),t.CourierToast=_,t.CourierToastDatastore=c,t.CourierToastDatastoreEvents=class{onMessageAdd(t){}onMessageRemove(t){}onError(t){}},t.CourierToastDatastoreListener=g,t.CourierToastItem=h,t.CourierToastThemeManager=l,t.defaultDarkTheme=a,t.defaultLightTheme=n,t.mergeTheme=r,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -1278,7 +1278,7 @@ class CourierToastDatastoreEvents {
|
|
|
1278
1278
|
}
|
|
1279
1279
|
}
|
|
1280
1280
|
Courier.shared.courierUserAgentName = "courier-ui-toast";
|
|
1281
|
-
Courier.shared.courierUserAgentVersion = "2.4.
|
|
1281
|
+
Courier.shared.courierUserAgentVersion = "2.4.2";
|
|
1282
1282
|
export {
|
|
1283
1283
|
Courier2 as Courier,
|
|
1284
1284
|
CourierToast,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trycourier/courier-ui-toast",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.2",
|
|
4
4
|
"description": "Toast components for the Courier web UI",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"dist"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@trycourier/courier-js": "3.7.
|
|
45
|
-
"@trycourier/courier-ui-core": "2.5.
|
|
44
|
+
"@trycourier/courier-js": "3.7.1",
|
|
45
|
+
"@trycourier/courier-ui-core": "2.5.2"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/jest": "29.5.14",
|