@trycourier/courier-ui-toast 2.1.9 → 2.1.11

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.
@@ -20,6 +20,9 @@ export declare class CourierToastItem extends CourierBaseElement {
20
20
  private readonly _autoDismiss;
21
21
  /** The timeout before the toast item is auto-dismissed, applicable if _autoDismiss is true. */
22
22
  private readonly _autoDismissTimeoutMs;
23
+ private _autoDismissTimeout;
24
+ /** The progress bar element, paused/resumed alongside the countdown to stay in sync. */
25
+ private _autoDismissBar;
23
26
  private _onItemDismissedCallback;
24
27
  private _onToastItemClickCallback;
25
28
  private _onToastItemActionClickCallback;
@@ -65,6 +68,23 @@ export declare class CourierToastItem extends CourierBaseElement {
65
68
  * @param timeoutMs - the animation duration to fade out the toast item
66
69
  */
67
70
  dismiss(timeoutMs?: number): void;
71
+ /**
72
+ * Pause the auto-dismiss countdown, banking the time already elapsed and
73
+ * freezing the progress bar so the two stay in sync.
74
+ *
75
+ * Called by the containing {@link CourierToast} while the cursor is over the
76
+ * toast stack. No-op if this item doesn't auto-dismiss.
77
+ */
78
+ pauseAutoDismiss(): void;
79
+ /**
80
+ * Resume a paused auto-dismiss countdown from where it left off.
81
+ *
82
+ * Called by the containing {@link CourierToast} once the cursor leaves the
83
+ * toast stack. No-op if this item doesn't auto-dismiss.
84
+ */
85
+ resumeAutoDismiss(): void;
86
+ /** Freeze/unfreeze the progress bar to match the countdown. */
87
+ private syncAutoDismissBarPlayState;
68
88
  /** @override */
69
89
  protected onComponentMounted(): void;
70
90
  /** @override */
@@ -31,6 +31,20 @@ export declare class CourierToast extends CourierBaseElement {
31
31
  private _toastStyle?;
32
32
  private _authListener?;
33
33
  private _datastoreListener;
34
+ /**
35
+ * Whether the cursor is currently over the toast stack.
36
+ *
37
+ * Hover is tracked here — on the container — rather than per item, because
38
+ * the stacked items are one hover surface: moving between them (or a new
39
+ * toast arriving under the cursor) must not resume anyone's countdown.
40
+ */
41
+ private _isHovered;
42
+ /**
43
+ * Auto-dismiss countdowns for custom toast items set via
44
+ * {@link CourierToast.setToastItem}. {@link CourierToastItem}s own their own
45
+ * countdown, so they're not tracked here.
46
+ */
47
+ private _customItemAutoDismissTimeouts;
34
48
  private _autoDismiss;
35
49
  private _autoDismissTimeoutMs;
36
50
  private _dismissButtonOption;
@@ -136,6 +150,12 @@ export declare class CourierToast extends CourierBaseElement {
136
150
  * @override
137
151
  */
138
152
  protected onComponentUnmounted(): void;
153
+ private onMouseEnter;
154
+ private onMouseLeave;
155
+ /** Pause or resume the auto-dismiss countdown of every item in the stack. */
156
+ private setAutoDismissPaused;
157
+ /** Pause or resume a single item's auto-dismiss countdown. */
158
+ private setItemAutoDismissPaused;
139
159
  /**
140
160
  * Lifecycle callback invoked when an observed attribute changes.
141
161
  *
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@trycourier/courier-ui-core"),require("@trycourier/courier-js")):"function"==typeof define&&define.amd?define(["exports","@trycourier/courier-ui-core","@trycourier/courier-js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CourierUIToast={},e.CourierUICore,e.CourierJS)}(this,(function(e,t,s){"use strict";var i=Object.defineProperty,o=(e,t,s)=>((e,t,s)=>t in e?i(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s)(e,"symbol"!=typeof t?t+"":t,s);const n={item:{backgroundColor:t.CourierColors.white[500],hoverBackgroundColor:t.CourierColors.gray[200],activeBackgroundColor:t.CourierColors.gray[500],shadow:`0px 4px 8px -2px ${t.CourierColors.black[50020]}`,border:`1px solid ${t.CourierColors.gray[500]}`,borderRadius:"8px",title:{size:"11pt",weight:"400",color:t.CourierColors.black[500]},body:{size:"11pt",weight:"400",color:t.CourierColors.gray[600]},icon:{color:t.CourierColors.black[500],svg:t.CourierIconSVGs.inbox},dismissIcon:{color:t.CourierColors.black[500],svg:t.CourierIconSVGs.remove},autoDismissBarColor:t.CourierColors.blue[400],actions:{backgroundColor:"transparent",hoverBackgroundColor:t.CourierColors.gray[200],activeBackgroundColor:t.CourierColors.gray[500],border:`1px solid ${t.CourierColors.gray[500]}`,borderRadius:"4px",shadow:"0px 1px 2px 0px rgba(0, 0, 0, 0.06)",font:{color:t.CourierColors.black[500],size:"14px"}}}},r={item:{backgroundColor:t.CourierColors.black[500],hoverBackgroundColor:t.CourierColors.gray[800],activeBackgroundColor:t.CourierColors.gray[700],shadow:`0px 4px 8px -2px ${t.CourierColors.gray[400]}`,border:`1px solid ${t.CourierColors.gray[400]}`,borderRadius:"8px",title:{size:"11pt",weight:"400",color:t.CourierColors.white[500]},body:{size:"11pt",weight:"400",color:t.CourierColors.gray[500]},icon:{color:t.CourierColors.white[500],svg:t.CourierIconSVGs.inbox},dismissIcon:{color:t.CourierColors.white[500],svg:t.CourierIconSVGs.remove},autoDismissBarColor:t.CourierColors.blue[400],actions:{backgroundColor:t.CourierColors.black[400],hoverBackgroundColor:t.CourierColors.white[50010],activeBackgroundColor:t.CourierColors.white[50020],border:`1px solid ${t.CourierColors.gray[400]}`,borderRadius:"4px",shadow:`0px 1px 2px 0px ${t.CourierColors.white[50010]}`,font:{color:t.CourierColors.white[500],size:"14px"}}}},a=(e,t)=>{var s,i,o,a,l,d,h,c;const u="light"===e?n:r;return{item:{...u.item,...t.item,title:{...null==(s=u.item)?void 0:s.title,...null==(i=t.item)?void 0:i.title},body:{...null==(o=u.item)?void 0:o.body,...null==(a=t.item)?void 0:a.body},icon:{...null==(l=u.item)?void 0:l.icon,...null==(d=t.item)?void 0:d.icon},dismissIcon:{...null==(h=u.item)?void 0:h.dismissIcon,...null==(c=t.item)?void 0:c.dismissIcon}}}};class l extends t.CourierThemeManager{constructor(e){super(e),o(this,"THEME_CHANGE_EVENT","courier_toast_theme_change")}getDefaultLightTheme(){return n}getDefaultDarkTheme(){return r}mergeTheme(e,t){return a(e,t)}subscribe(e){return{...super.subscribe(e),manager:this}}}const d=class e extends t.CourierBaseElement{constructor(e){super(),o(this,"_themeManager"),o(this,"_themeSubscription"),o(this,"_message"),o(this,"_customToastItemContent"),o(this,"_autoDismiss"),o(this,"_autoDismissTimeoutMs"),o(this,"_onItemDismissedCallback",null),o(this,"_onToastItemClickCallback",null),o(this,"_onToastItemActionClickCallback",null),this._message=e.message,this._autoDismiss=e.autoDismiss,this._autoDismissTimeoutMs=e.autoDismissTimeoutMs,this._themeManager=e.themeManager,this._themeSubscription=this._themeManager.subscribe((e=>{this.render()}))}onItemDismissed(e){this._onItemDismissedCallback=e}onToastItemClick(e){this._onToastItemClickCallback=e,this.render()}onToastItemActionClick(e){this._onToastItemActionClickCallback=e,this.render()}setToastItemContent(e){this._customToastItemContent=e}dismiss(t=e.dismissAnimationTimeoutMs){this.classList.add("dismissing"),setTimeout((()=>{this.remove(),this._onItemDismissedCallback&&this._onItemDismissedCallback({message:this._message})}),t)}onComponentMounted(){this.render()}onComponentUnmounted(){this._themeSubscription.unsubscribe()}get theme(){return this._themeManager.getTheme()}static get id(){return"courier-toast-item"}static get observedAttributes(){return[]}render(){for(var e,s,i,o;this.firstChild;)this.removeChild(this.firstChild);this.removeEventListener("click",this.onClick);const n=document.createElement("div");if(n.classList.add("overflow-hidden-container"),this.appendChild(n),this._autoDismiss){const e=document.createElement("div");e.classList.add("auto-dismiss"),n.append(e)}this._customToastItemContent?n.appendChild(this._customToastItemContent({message:this._message,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs})):n.appendChild(this.createDefaultContent()),this._onToastItemClickCallback&&this.classList.add("clickable"),this.addEventListener("click",this.onClick);const r=new t.CourierIcon(null==(s=null==(e=this.theme.item)?void 0:e.dismissIcon)?void 0:s.color,null==(o=null==(i=this.theme.item)?void 0:i.dismissIcon)?void 0:o.svg);r.classList.add("dismiss"),r.addEventListener("click",(e=>{e.stopPropagation(),this.remove(),this._onItemDismissedCallback&&this._onItemDismissedCallback({message:this._message})})),this.appendChild(r)}createDefaultContent(){var e,s,i,o,n;const r=document.createElement("div");r.classList.add("content"),this.append(r);const a=new t.CourierIcon(null==(s=null==(e=this.theme.item)?void 0:e.icon)?void 0:s.color,null==(o=null==(i=this.theme.item)?void 0:i.icon)?void 0:o.svg);a.classList.add("icon"),r.appendChild(a);const l=document.createElement("div");l.classList.add("text-content"),r.appendChild(l);const d=document.createElement("p");d.classList.add("title"),d.textContent=this._message.title??"",l.appendChild(d);const h=document.createElement("p");if(h.classList.add("body"),h.textContent=this._message.preview??this._message.body??"",l.appendChild(h),this.messageHasActions){const e=document.createElement("div");e.classList.add("actions-container"),l.appendChild(e),null==(n=this._message.actions)||n.forEach((t=>{const s=this.createActionButton(t);e.appendChild(s)}))}return r}get messageHasActions(){return this._message.actions&&this._message.actions.length>0}createActionButton(e){var s,i,o,n,r;const a=null==(s=this._themeManager.getTheme().item)?void 0:s.actions;return new t.CourierButton({mode:this._themeManager.mode,text:e.content,variant:"secondary",backgroundColor:null==a?void 0:a.backgroundColor,hoverBackgroundColor:null==a?void 0:a.hoverBackgroundColor,activeBackgroundColor:null==a?void 0:a.activeBackgroundColor,border:null==a?void 0:a.border,borderRadius:null==a?void 0:a.borderRadius,shadow:null==a?void 0:a.shadow,fontFamily:null==(i=null==a?void 0:a.font)?void 0:i.family,fontSize:null==(o=null==a?void 0:a.font)?void 0:o.size,fontWeight:null==(n=null==a?void 0:a.font)?void 0:n.weight,textColor:null==(r=null==a?void 0:a.font)?void 0:r.color,onClick:()=>{this._onToastItemActionClickCallback&&this._onToastItemActionClickCallback({message:this._message,action:e})}})}onClick(e){e.stopPropagation(),this._onToastItemClickCallback&&this._onToastItemClickCallback({message:this._message})}};o(d,"dismissAnimationTimeoutMs",300);let h=d;t.registerElement(h);const c=class e{constructor(){o(this,"_dataset",[]),o(this,"_datastoreListeners",[]),o(this,"_removeMessageEventListener")}static get shared(){return e.instance||(e.instance=new e),e.instance}addDatastoreListener(e){this._datastoreListeners.push(e)}removeDatastoreListener(e){this._datastoreListeners=this._datastoreListeners.filter((t=>t!==e))}async listenForMessages(){var e,t,i,o,n,r,a;try{const a=null==(e=s.Courier.shared.client)?void 0:e.inbox.socket;if(!a)return void(null==(i=null==(t=s.Courier.shared.client)?void 0:t.options.logger)||i.info("CourierInbox socket not available"));if(this._removeMessageEventListener&&this._removeMessageEventListener(),this._removeMessageEventListener=a.addMessageEventListener((e=>{if(e.event===s.InboxMessageEvent.NewMessage){const t=e.data;this.addMessage(t)}})),a.isConnecting||a.isOpen)return void(null==(r=null==(o=s.Courier.shared.client)?void 0:o.options.logger)||r.info(`Inbox socket already connecting or open for client ID: [${null==(n=s.Courier.shared.client)?void 0:n.options.connectionId}]`));await a.connect()}catch(l){null==(a=s.Courier.shared.client)||a.options.logger.error("Error listening for messages:",l),this._datastoreListeners.forEach((e=>{var t,s;null==(s=(t=e.events).onError)||s.call(t,l)}))}}toastIndexOfMessage(e){const t=this._dataset.findIndex((t=>t.messageId===e.messageId));return t<0?t:this._dataset.length-t-1}addMessage(e){this._dataset.push(e),this._datastoreListeners.forEach((t=>{t.events.onMessageAdd&&t.events.onMessageAdd(e)}))}removeMessage(e){const t=this._dataset.findIndex((t=>t.messageId===e.messageId));t<0||(this._dataset.splice(t,1),this._datastoreListeners.forEach((t=>{t.events.onMessageRemove&&t.events.onMessageRemove(e)})))}};o(c,"instance");let u=c;class m{constructor(e){this.events=e}remove(){u.shared.removeDatastoreListener(this)}}const g=class e extends t.CourierBaseElement{constructor(e){super(),o(this,"_themeManager"),o(this,"_themeSubscription"),o(this,"_toastStyle"),o(this,"_authListener"),o(this,"_datastoreListener"),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}),this._themeManager=(null==e?void 0:e.themeManager)??new l(n),this._themeSubscription=this._themeManager.subscribe((e=>{this.refreshStyles()})),this._datastoreListener=new m({onMessageAdd:this.datastoreAddMessageListener.bind(this),onMessageRemove:this.datastoreRemoveMessageListener.bind(this)})}onToastItemClick(e){this._onItemClick=e}onToastItemActionClick(e){this._onItemActionClick=e}enableAutoDismiss(){this._autoDismiss=!0}disableAutoDismiss(){this._autoDismiss=!1}setAutoDismissTimeoutMs(e){this._autoDismissTimeoutMs=e}setLightTheme(e){this._themeManager.setLightTheme(e)}setDarkTheme(e){this._themeManager.setDarkTheme(e)}setDismissButton(e){this._dismissButtonOption=e,this.refreshStyles()}setMode(e){this._themeManager.setMode(e)}setToastItem(e){this._customToastItem=e}setToastItemContent(e){this._customToastItemContent=e}dismissToastForMessage(e){this.childNodes.forEach((t=>{t.dataset.courierMessageId===e.messageId&&(t instanceof h?t.dismiss():t.remove())}))}onComponentMounted(){this._toastStyle=t.injectGlobalStyle(e.id,this.getStyles(this.theme)),u.shared.addDatastoreListener(this._datastoreListener),s.Courier.shared.addAuthenticationListener(this.authChangedCallback.bind(this)),u.shared.listenForMessages()}onComponentUnmounted(){var e,t;this._datastoreListener.remove(),null==(e=this._authListener)||e.remove(),null==(t=this._toastStyle)||t.remove(),this._themeManager.cleanup(),this._themeSubscription.unsubscribe()}attributeChangedCallback(t,s,i){switch(t){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&&e.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(),u.shared.listenForMessages()}removeAllItems(){for(;this.firstChild;)this.removeChild(this.firstChild)}addToastItem(e){const t=this.createToastItem(e);return t.dataset.courierMessageId=e.messageId,this.appendChild(t),this.resizeContainerToHeight(this.topStackItemHeight),t}createToastItem(e){return this._customToastItem?this.createCustomToastItem(e):this.createDefaultToastItem(e)}createDefaultToastItem(e){const t=new h({message:e,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs,themeManager:this._themeManager});return t.onItemDismissed((e=>{this.resizeContainerToHeight(this.topStackItemHeight)})),this._customToastItemContent&&t.setToastItemContent(this._customToastItemContent),this._onItemClick&&t.onToastItemClick(this._onItemClick),this._onItemActionClick&&t.onToastItemActionClick(this._onItemActionClick),this._autoDismiss&&setTimeout(t.dismiss.bind(t),this._autoDismissTimeoutMs),t}createCustomToastItem(e){if(!this._customToastItem)throw Error("Attempted to create customToastItem, but none is set");const t=this._customToastItem({message:e,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs});return this._autoDismiss&&setTimeout((()=>{this.removeChild(t)}),this._autoDismissTimeoutMs),t.addEventListener("click",(()=>{this._onItemClick&&this._onItemClick({message:e})})),t}datastoreAddMessageListener(e){this.addToastItem(e)}datastoreRemoveMessageListener(e){this.dismissToastForMessage(e)}getStyles(t){var s,i,o,n,r,a;const l=t.item;return[`\n ${e.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 0.3s ease-in-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 @keyframes courier-toast-hide {\n 0% {\n opacity: 1;\n transform: scaleX(var(--scale, 1));\n }\n\n 100% {\n opacity: 0;\n transform: 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 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==(r=null==l?void 0:l.body)?void 0:r.size};\n line-height: 150%;\n color: ${null==(a=null==l?void 0:l.body)?void 0:a.color};\n }\n `,`\n ${h.id} > .overflow-hidden-container > .content > .text-content > .actions-container {\n display: flex;\n gap: 8px;\n margin-top: 12px;\n }\n `].join("")}get topStackItemHeight(){if(this.lastChild){return`${this.lastChild.getBoundingClientRect().height}px`}return"0px"}resizeContainerToHeight(e){this.style.height=e}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(e){return["visible","hidden","hover","auto"].includes(e)}};o(g,"observedAttributes",["auto-dismiss","auto-dismiss-timeout-ms","dismiss-button","light-theme","dark-theme","mode"]);let C=g;t.registerElement(C);s.Courier.shared.courierUserAgentName="courier-ui-toast",s.Courier.shared.courierUserAgentVersion="2.1.9",Object.defineProperty(e,"Courier",{enumerable:!0,get:()=>s.Courier}),Object.defineProperty(e,"DEFAULT_COURIER_API_URLS",{enumerable:!0,get:()=>s.DEFAULT_COURIER_API_URLS}),Object.defineProperty(e,"EU_COURIER_API_URLS",{enumerable:!0,get:()=>s.EU_COURIER_API_URLS}),Object.defineProperty(e,"getCourierApiUrls",{enumerable:!0,get:()=>s.getCourierApiUrls}),Object.defineProperty(e,"getCourierApiUrlsForRegion",{enumerable:!0,get:()=>s.getCourierApiUrlsForRegion}),e.CourierToast=C,e.CourierToastDatastore=u,e.CourierToastDatastoreEvents=class{onMessageAdd(e){}onMessageRemove(e){}onError(e){}},e.CourierToastDatastoreListener=m,e.CourierToastItem=h,e.CourierToastThemeManager=l,e.defaultDarkTheme=r,e.defaultLightTheme=n,e.mergeTheme=a,Object.defineProperty(e,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],actions:{backgroundColor:"transparent",hoverBackgroundColor:e.CourierColors.gray[200],activeBackgroundColor:e.CourierColors.gray[500],border:`1px solid ${e.CourierColors.gray[500]}`,borderRadius:"4px",shadow:"0px 1px 2px 0px rgba(0, 0, 0, 0.06)",font:{color:e.CourierColors.black[500],size:"14px"}}}},r={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],actions:{backgroundColor:e.CourierColors.black[400],hoverBackgroundColor:e.CourierColors.white[50010],activeBackgroundColor:e.CourierColors.white[50020],border:`1px solid ${e.CourierColors.gray[400]}`,borderRadius:"4px",shadow:`0px 1px 2px 0px ${e.CourierColors.white[50010]}`,font:{color:e.CourierColors.white[500],size:"14px"}}}},a=(t,e)=>{var s,i,o,a,l,d,u,h;const m="light"===t?n:r;return{item:{...m.item,...e.item,title:{...null==(s=m.item)?void 0:s.title,...null==(i=e.item)?void 0:i.title},body:{...null==(o=m.item)?void 0:o.body,...null==(a=e.item)?void 0:a.body},icon:{...null==(l=m.item)?void 0:l.icon,...null==(d=e.item)?void 0:d.icon},dismissIcon:{...null==(u=m.item)?void 0:u.dismissIcon,...null==(h=e.item)?void 0:h.dismissIcon}}}};class l extends e.CourierThemeManager{constructor(t){super(t),o(this,"THEME_CHANGE_EVENT","courier_toast_theme_change")}getDefaultLightTheme(){return n}getDefaultDarkTheme(){return r}mergeTheme(t,e){return a(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 r=document.createElement("div");if(r.classList.add("overflow-hidden-container"),this.appendChild(r),this._autoDismiss){const e=document.createElement("div");e.classList.add("auto-dismiss"),(null==(t=this._autoDismissTimeout)?void 0:t.isPaused)&&(e.style.animationPlayState="paused"),r.append(e),this._autoDismissBar=e}this._customToastItemContent?r.appendChild(this._customToastItemContent({message:this._message,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs})):r.appendChild(this.createDefaultContent()),this._onToastItemClickCallback&&this.classList.add("clickable"),this.addEventListener("click",this.onClick);const a=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);a.classList.add("dismiss"),a.addEventListener("click",(t=>{t.stopPropagation(),this.remove(),this._onItemDismissedCallback&&this._onItemDismissedCallback({message:this._message})})),this.appendChild(a)}createDefaultContent(){var t,s,i,o,n;const r=document.createElement("div");r.classList.add("content"),this.append(r);const a=new e.CourierIcon(null==(s=null==(t=this.theme.item)?void 0:t.icon)?void 0:s.color,null==(o=null==(i=this.theme.item)?void 0:i.icon)?void 0:o.svg);a.classList.add("icon"),r.appendChild(a);const l=document.createElement("div");l.classList.add("text-content"),r.appendChild(l);const d=document.createElement("p");d.classList.add("title"),d.textContent=this._message.title??"",l.appendChild(d);const u=document.createElement("p");if(u.classList.add("body"),u.textContent=this._message.preview??this._message.body??"",l.appendChild(u),this.messageHasActions){const t=document.createElement("div");t.classList.add("actions-container"),l.appendChild(t),null==(n=this._message.actions)||n.forEach((e=>{const s=this.createActionButton(e);t.appendChild(s)}))}return r}get messageHasActions(){return this._message.actions&&this._message.actions.length>0}createActionButton(t){var s,i,o,n,r;const a=null==(s=this._themeManager.getTheme().item)?void 0:s.actions;return new e.CourierButton({mode:this._themeManager.mode,text:t.content,variant:"secondary",backgroundColor:null==a?void 0:a.backgroundColor,hoverBackgroundColor:null==a?void 0:a.hoverBackgroundColor,activeBackgroundColor:null==a?void 0:a.activeBackgroundColor,border:null==a?void 0:a.border,borderRadius:null==a?void 0:a.borderRadius,shadow:null==a?void 0:a.shadow,fontFamily:null==(i=null==a?void 0:a.font)?void 0:i.family,fontSize:null==(o=null==a?void 0:a.font)?void 0:o.size,fontWeight:null==(n=null==a?void 0:a.font)?void 0:n.weight,textColor:null==(r=null==a?void 0:a.font)?void 0:r.color,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,r,a;try{const a=null==(t=s.Courier.shared.client)?void 0:t.inbox.socket;if(!a)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=a.addMessageEventListener((t=>{if(t.event===s.InboxMessageEvent.NewMessage){const e=t.data;this.addMessage(e)}})),a.isConnecting||a.isOpen)return void(null==(r=null==(o=s.Courier.shared.client)?void 0:o.options.logger)||r.info(`Inbox socket already connecting or open for client ID: [${null==(n=s.Courier.shared.client)?void 0:n.options.connectionId}]`));await a.connect()}catch(l){null==(a=s.Courier.shared.client)||a.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 C=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.setAutoDismissPaused(!0)})),o(this,"onMouseLeave",(()=>{this._isHovered=!1,this.setAutoDismissPaused(!1)})),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()))}))}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()}setAutoDismissPaused(t){Array.from(this.children).forEach((e=>this.setItemAutoDismissPaused(e,t)))}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._isHovered&&this.setItemAutoDismissPaused(e,!0),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._customToastItemContent&&e.setToastItemContent(this._customToastItemContent),this._onItemClick&&e.onToastItemClick(this._onItemClick),this._onItemActionClick&&e.onToastItemActionClick(this._onItemActionClick),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._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,r,a;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 0.3s ease-in-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 @keyframes courier-toast-hide {\n 0% {\n opacity: 1;\n transform: scaleX(var(--scale, 1));\n }\n\n 100% {\n opacity: 0;\n transform: 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 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==(r=null==l?void 0:l.body)?void 0:r.size};\n line-height: 150%;\n color: ${null==(a=null==l?void 0:l.body)?void 0:a.color};\n }\n `,`\n ${h.id} > .overflow-hidden-container > .content > .text-content > .actions-container {\n display: flex;\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(C,"observedAttributes",["auto-dismiss","auto-dismiss-timeout-ms","dismiss-button","light-theme","dark-theme","mode"]);let v=C;e.registerElement(v);s.Courier.shared.courierUserAgentName="courier-ui-toast",s.Courier.shared.courierUserAgentVersion="2.1.11",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=v,t.CourierToastDatastore=c,t.CourierToastDatastoreEvents=class{onMessageAdd(t){}onMessageRemove(t){}onError(t){}},t.CourierToastDatastoreListener=g,t.CourierToastItem=h,t.CourierToastThemeManager=l,t.defaultDarkTheme=r,t.defaultLightTheme=n,t.mergeTheme=a,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/types/courier-toast-theme.ts","../src/types/courier-toast-theme-manager.ts","../src/components/courier-toast-item.ts","../src/datastore/toast-datastore.ts","../src/datastore/toast-datastore-listener.ts","../src/components/courier-toast.ts","../src/index.ts","../src/datastore/toast-datastore-events.ts"],"sourcesContent":["import { CourierColors, CourierIconSVGs, SystemThemeMode, CourierFontTheme, CourierIconTheme } from \"@trycourier/courier-ui-core\";\r\n\r\n// Re-export common types from core for convenience\r\n\r\n/** @public */\r\nexport type CourierToastFontTheme = CourierFontTheme;\r\n\r\n/** @public */\r\nexport type CourierToastIconTheme = CourierIconTheme;\r\n\r\n/** @public */\r\nexport type CourierToastItemTheme = {\r\n backgroundColor?: string;\r\n hoverBackgroundColor?: string;\r\n activeBackgroundColor?: string;\r\n autoDismissBarColor?: string;\r\n title?: CourierToastFontTheme;\r\n body?: CourierToastFontTheme;\r\n icon?: CourierToastIconTheme;\r\n dismissIcon?: CourierToastIconTheme;\r\n shadow?: string;\r\n border?: string;\r\n borderRadius?: string;\r\n actions?: {\r\n backgroundColor?: string;\r\n hoverBackgroundColor?: string;\r\n activeBackgroundColor?: string;\r\n border?: string;\r\n borderRadius?: string;\r\n shadow?: string;\r\n font?: CourierToastFontTheme;\r\n }\r\n}\r\n\r\n/** @public */\r\nexport type CourierToastTheme = {\r\n item?: CourierToastItemTheme;\r\n};\r\n\r\n/** @public */\r\nexport const defaultLightTheme: CourierToastTheme = {\r\n item: {\r\n backgroundColor: CourierColors.white[500],\r\n hoverBackgroundColor: CourierColors.gray[200],\r\n activeBackgroundColor: CourierColors.gray[500],\r\n shadow: `0px 4px 8px -2px ${CourierColors.black[500_20]}`,\r\n border: `1px solid ${CourierColors.gray[500]}`,\r\n borderRadius: '8px',\r\n title: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.black[500],\r\n },\r\n body: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.gray[600],\r\n },\r\n icon: {\r\n color: CourierColors.black[500],\r\n svg: CourierIconSVGs.inbox,\r\n },\r\n dismissIcon: {\r\n color: CourierColors.black[500],\r\n svg: CourierIconSVGs.remove,\r\n },\r\n autoDismissBarColor: CourierColors.blue[400],\r\n actions: {\r\n backgroundColor: 'transparent',\r\n hoverBackgroundColor: CourierColors.gray[200],\r\n activeBackgroundColor: CourierColors.gray[500],\r\n border: `1px solid ${CourierColors.gray[500]}`,\r\n borderRadius: '4px',\r\n shadow: '0px 1px 2px 0px rgba(0, 0, 0, 0.06)',\r\n font: {\r\n color: CourierColors.black[500],\r\n size: '14px',\r\n }\r\n }\r\n }\r\n};\r\n\r\n/** @public */\r\nexport const defaultDarkTheme: CourierToastTheme = {\r\n item: {\r\n backgroundColor: CourierColors.black[500],\r\n hoverBackgroundColor: CourierColors.gray[800],\r\n activeBackgroundColor: CourierColors.gray[700],\r\n shadow: `0px 4px 8px -2px ${CourierColors.gray[400]}`,\r\n border: `1px solid ${CourierColors.gray[400]}`,\r\n borderRadius: '8px',\r\n title: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.white[500],\r\n },\r\n body: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.gray[500],\r\n },\r\n icon: {\r\n color: CourierColors.white[500],\r\n svg: CourierIconSVGs.inbox,\r\n },\r\n dismissIcon: {\r\n color: CourierColors.white[500],\r\n svg: CourierIconSVGs.remove,\r\n },\r\n autoDismissBarColor: CourierColors.blue[400],\r\n actions: {\r\n backgroundColor: CourierColors.black[400],\r\n hoverBackgroundColor: CourierColors.white[500_10],\r\n activeBackgroundColor: CourierColors.white[500_20],\r\n border: `1px solid ${CourierColors.gray[400]}`,\r\n borderRadius: '4px',\r\n shadow: `0px 1px 2px 0px ${CourierColors.white[500_10]}`,\r\n font: {\r\n color: CourierColors.white[500],\r\n size: '14px'\r\n }\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Deep merge themes, only overwriting non-optional properties.\r\n *\r\n * @public\r\n */\r\nexport const mergeTheme = (mode: SystemThemeMode, theme: CourierToastTheme): CourierToastTheme => {\r\n const defaultTheme = mode === 'light' ? defaultLightTheme : defaultDarkTheme;\r\n return {\r\n item: {\r\n ...defaultTheme.item,\r\n ...theme.item,\r\n title: {\r\n ...defaultTheme.item?.title,\r\n ...theme.item?.title\r\n },\r\n body: {\r\n ...defaultTheme.item?.body,\r\n ...theme.item?.body\r\n },\r\n icon: {\r\n ...defaultTheme.item?.icon,\r\n ...theme.item?.icon\r\n },\r\n dismissIcon: {\r\n ...defaultTheme.item?.dismissIcon,\r\n ...theme.item?.dismissIcon\r\n }\r\n }\r\n };\r\n};\r\n","import { CourierThemeManager, CourierThemeSubscription, SystemThemeMode } from \"@trycourier/courier-ui-core\";\r\nimport { CourierToastTheme, defaultDarkTheme, defaultLightTheme, mergeTheme } from \"./courier-toast-theme\";\r\n\r\n/**\r\n * @public\r\n */\r\nexport interface CourierToastThemeSubscription extends CourierThemeSubscription<CourierToastTheme> {\r\n manager: CourierToastThemeManager;\r\n}\r\n\r\n/**\r\n * Toast-specific theme manager that extends the abstract CourierThemeManager.\r\n * Provides toast theme management with light/dark mode support.\r\n *\r\n * @public\r\n */\r\nexport class CourierToastThemeManager extends CourierThemeManager<CourierToastTheme> {\r\n\r\n // Event ID for toast theme changes\r\n protected readonly THEME_CHANGE_EVENT: string = 'courier_toast_theme_change';\r\n\r\n constructor(initialTheme: CourierToastTheme) {\r\n super(initialTheme);\r\n }\r\n\r\n /**\r\n * Get the default light theme for toast\r\n */\r\n protected getDefaultLightTheme(): CourierToastTheme {\r\n return defaultLightTheme;\r\n }\r\n\r\n /**\r\n * Get the default dark theme for toast\r\n */\r\n protected getDefaultDarkTheme(): CourierToastTheme {\r\n return defaultDarkTheme;\r\n }\r\n\r\n /**\r\n * Merge the toast theme with defaults\r\n */\r\n protected mergeTheme(mode: SystemThemeMode, theme: CourierToastTheme): CourierToastTheme {\r\n return mergeTheme(mode, theme);\r\n }\r\n\r\n /**\r\n * Subscribe to toast theme changes\r\n * @param callback - Function to run when the theme changes\r\n * @returns Object with unsubscribe method to stop listening\r\n */\r\n public subscribe(callback: (theme: CourierToastTheme) => void): CourierToastThemeSubscription {\r\n const baseSubscription = super.subscribe(callback);\r\n return {\r\n ...baseSubscription,\r\n manager: this\r\n };\r\n }\r\n\r\n}\r\n","import { CourierBaseElement, CourierButton, CourierIcon, registerElement } from \"@trycourier/courier-ui-core\";\nimport { CourierToastThemeManager, CourierToastThemeSubscription } from \"../types/courier-toast-theme-manager\";\nimport { CourierToastTheme } from \"../types/courier-toast-theme\";\nimport { InboxAction, InboxMessage } from \"@trycourier/courier-js\";\nimport { CourierToastItemActionClickEvent, CourierToastItemClickEvent, CourierToastItemFactoryProps } from \"../types/toast\";\n\n/**\n * Default implementation of a Toast item.\n *\n * @see {@link CourierToast}\n * @public\n */\nexport class CourierToastItem extends CourierBaseElement {\n /** The animation duration to fade out a dismissed toast before its element is removed. */\n private static readonly dismissAnimationTimeoutMs = 300;\n\n private _themeManager: CourierToastThemeManager;\n private _themeSubscription: CourierToastThemeSubscription;\n private _message: InboxMessage;\n private _customToastItemContent?: (props: CourierToastItemFactoryProps) => HTMLElement;\n\n /** Whether this toast item is auto-dismissed. */\n private readonly _autoDismiss: boolean;\n\n /** The timeout before the toast item is auto-dismissed, applicable if _autoDismiss is true. */\n private readonly _autoDismissTimeoutMs: number;\n\n // Callbacks\n private _onItemDismissedCallback: ((props: { message: InboxMessage }) => void) | null = null;\n private _onToastItemClickCallback: ((props: CourierToastItemClickEvent) => void) | null = null;\n private _onToastItemActionClickCallback: ((props: CourierToastItemActionClickEvent) => void) | null = null;\n\n constructor(props: {\n message: InboxMessage,\n autoDismiss: boolean,\n autoDismissTimeoutMs: number,\n themeManager: CourierToastThemeManager,\n }) {\n\n super();\n this._message = props.message;\n this._autoDismiss = props.autoDismiss;\n this._autoDismissTimeoutMs = props.autoDismissTimeoutMs;\n\n this._themeManager = props.themeManager;\n this._themeSubscription = this._themeManager.subscribe((_: CourierToastTheme) => {\n this.render();\n });\n }\n\n /**\n * Registers a handler called when the item is dismissed.\n *\n * @param handler - A function to be called when the item is dismissed.\n */\n public onItemDismissed(handler: (props: { message: InboxMessage }) => void): void {\n this._onItemDismissedCallback = handler;\n }\n\n /**\n * Registers a handler for item click events.\n *\n * @param handler - A function to be called when the item is clicked.\n */\n public onToastItemClick(handler: (props: CourierToastItemClickEvent) => void): void {\n this._onToastItemClickCallback = handler;\n\n // Re-render to set/un-set the .clickable class\n this.render();\n }\n\n /**\n * Registers a handler for item click events.\n *\n * @param handler - A function to be called when the item is clicked.\n */\n public onToastItemActionClick(handler: (props: CourierToastItemActionClickEvent) => void): void {\n this._onToastItemActionClickCallback = handler;\n\n // Re-render to set/un-set the .clickable class\n this.render();\n }\n\n\n /**\n * Set a custom content element for the toast item, reusing the {@link CourierToastItem}\n * container, which provides styling, animations, and event handling.\n *\n * @param factory - Function that returns an `HTMLElement` to render as the content.\n */\n public setToastItemContent(factory?: (props: CourierToastItemFactoryProps) => HTMLElement) {\n this._customToastItemContent = factory;\n }\n\n /**\n * Dismiss the toast item.\n *\n * By default the toast fades out before it's removed. Set `timeoutMs` to\n * `0` to remove the item immediately.\n *\n * @param timeoutMs - the animation duration to fade out the toast item\n */\n public dismiss(timeoutMs: number = CourierToastItem.dismissAnimationTimeoutMs) {\n this.classList.add('dismissing');\n\n setTimeout(() => {\n this.remove();\n\n if (this._onItemDismissedCallback) {\n this._onItemDismissedCallback({ message: this._message });\n }\n }, timeoutMs);\n }\n\n /** @override */\n protected onComponentMounted(): void {\n this.render();\n }\n\n /** @override */\n protected onComponentUnmounted(): void {\n this._themeSubscription.unsubscribe();\n }\n\n get theme(): CourierToastTheme {\n return this._themeManager.getTheme();\n }\n\n /**\n * @override\n */\n static get id(): string {\n return 'courier-toast-item';\n }\n\n /**\n * @override\n */\n static get observedAttributes(): string[] {\n return [];\n }\n\n /**\n * Render a toast item, either with default content or custom content if\n * a content factory function is provided.\n *\n * Note: Styles for the toast item are set in {@link CourierToast} since\n * toasts are ephemeral by nature and we want to avoid adding/removing/duplicating\n * styles as {@link CourierToastItem}s enter/exit.\n */\n private render(): void {\n // Reset existing content and top-level listeners\n while (this.firstChild) {\n this.removeChild(this.firstChild);\n }\n this.removeEventListener('click', this.onClick);\n\n // Content and the auto-dismiss bar are wrapped in a container that hides overflow.\n // The standard dismiss button overflows the toast.\n const overflowHiddenContainer = document.createElement('div');\n overflowHiddenContainer.classList.add('overflow-hidden-container');\n this.appendChild(overflowHiddenContainer);\n\n // Auto-dismiss\n if (this._autoDismiss) {\n const autoDismiss = document.createElement('div');\n autoDismiss.classList.add('auto-dismiss');\n overflowHiddenContainer.append(autoDismiss);\n }\n\n // Content\n if (this._customToastItemContent) {\n overflowHiddenContainer.appendChild(this._customToastItemContent({ message: this._message, autoDismiss: this._autoDismiss, autoDismissTimeoutMs: this._autoDismissTimeoutMs }));\n } else {\n overflowHiddenContainer.appendChild(this.createDefaultContent());\n }\n\n // Click-ability\n if (this._onToastItemClickCallback) {\n this.classList.add('clickable');\n }\n\n this.addEventListener('click', this.onClick);\n\n // Dismiss button\n const dismiss = new CourierIcon(\n this.theme.item?.dismissIcon?.color,\n this.theme.item?.dismissIcon?.svg,\n );\n dismiss.classList.add('dismiss');\n dismiss.addEventListener('click', (event) => {\n event.stopPropagation();\n this.remove();\n\n if (this._onItemDismissedCallback) {\n this._onItemDismissedCallback({ message: this._message });\n }\n });\n this.appendChild(dismiss);\n }\n\n /** Create the default content for this item. */\n private createDefaultContent(): HTMLElement {\n const content = document.createElement('div');\n content.classList.add('content');\n this.append(content);\n\n const icon = new CourierIcon(\n this.theme.item?.icon?.color,\n this.theme.item?.icon?.svg,\n );\n icon.classList.add('icon');\n content.appendChild(icon);\n\n const textContent = document.createElement('div');\n textContent.classList.add('text-content');\n content.appendChild(textContent);\n\n const title = document.createElement('p');\n title.classList.add('title');\n title.textContent = this._message.title ?? '';\n textContent.appendChild(title);\n\n const body = document.createElement('p');\n body.classList.add('body');\n body.textContent = this._message.preview ?? this._message.body ?? '';\n textContent.appendChild(body);\n\n if (this.messageHasActions) {\n const actionsContainer = document.createElement('div');\n actionsContainer.classList.add('actions-container');\n textContent.appendChild(actionsContainer);\n\n this._message.actions?.forEach(action => {\n const button = this.createActionButton(action);\n actionsContainer.appendChild(button);\n });\n }\n\n return content;\n }\n\n private get messageHasActions() {\n return this._message.actions && this._message.actions.length > 0;\n }\n\n private createActionButton(action: InboxAction): CourierButton {\n const actionsTheme = this._themeManager.getTheme().item?.actions;\n\n return new CourierButton({\n mode: this._themeManager.mode,\n text: action.content,\n variant: 'secondary',\n backgroundColor: actionsTheme?.backgroundColor,\n hoverBackgroundColor: actionsTheme?.hoverBackgroundColor,\n activeBackgroundColor: actionsTheme?.activeBackgroundColor,\n border: actionsTheme?.border,\n borderRadius: actionsTheme?.borderRadius,\n shadow: actionsTheme?.shadow,\n fontFamily: actionsTheme?.font?.family,\n fontSize: actionsTheme?.font?.size,\n fontWeight: actionsTheme?.font?.weight,\n textColor: actionsTheme?.font?.color,\n onClick: () => {\n if (this._onToastItemActionClickCallback) {\n this._onToastItemActionClickCallback({ message: this._message, action });\n }\n }\n });\n\n\n }\n\n private onClick(event: Event) {\n event.stopPropagation();\n if (this._onToastItemClickCallback) {\n this._onToastItemClickCallback({ message: this._message });\n }\n }\n}\n\nregisterElement(CourierToastItem);\n","import { Courier, InboxMessage, InboxMessageEvent, InboxMessageEventEnvelope } from \"@trycourier/courier-js\";\nimport { CourierToastDatastoreListener } from \"./toast-datastore-listener\";\n\n/**\n * Shared datastore for Courier toasts.\n *\n * This datastore listens to and stores Courier Inbox messages.\n *\n * @public\n */\nexport class CourierToastDatastore {\n /** Shared instance. Access via {@link CourierToastDatastore.shared}. */\n private static instance: CourierToastDatastore;\n\n /** FIFO stack of toast messages. The end of the array is index 0 of the stack. */\n private _dataset: InboxMessage[] = [];\n\n /** Set of listeners whose handlers will be called when the datastore changes. */\n private _datastoreListeners: CourierToastDatastoreListener[] = [];\n\n /** Cleanup function to remove the message event listener. */\n private _removeMessageEventListener?: () => void;\n\n /** The shared instance of CourierToastDatastore, used to access all public methods. */\n public static get shared(): CourierToastDatastore {\n if (!CourierToastDatastore.instance) {\n CourierToastDatastore.instance = new CourierToastDatastore();\n }\n\n return CourierToastDatastore.instance;\n }\n\n /**\n * Add a listener whose handlers are called when there are changes to the datastore.\n *\n * @param listener - an implementation of {@link CourierToastDatastoreListener}\n */\n public addDatastoreListener(listener: CourierToastDatastoreListener) {\n this._datastoreListeners.push(listener);\n }\n\n /**\n * Remove a previously added listener.\n *\n * Note: the `listener` param is matched by object reference, so callers must pass\n * the same object previously passed to {@link CourierToastDatastore.addDatastoreListener}.\n *\n * See also: {@link CourierToastDatastoreListener.remove}\n *\n * @param listener - a previously added listener implementation\n */\n public removeDatastoreListener(listener: CourierToastDatastoreListener) {\n this._datastoreListeners = this._datastoreListeners.filter(l => l !== listener);\n }\n\n /**\n * Start listening for toast messages.\n *\n * Calling this method will open a WebSocket connection to the Courier backend if one\n * is not already open.\n *\n * See also: {@link @trycourier/courier-js#Courier.shared.signIn} and {@link @trycourier/courier-js#Courier.shared.signOut}\n */\n public async listenForMessages() {\n try {\n const socketClient = Courier.shared.client?.inbox.socket;\n\n if (!socketClient) {\n Courier.shared.client?.options.logger?.info('CourierInbox socket not available');\n return;\n }\n\n // Remove any existing listener before adding a new one\n // This prevents duplicates and handles socket changes\n if (this._removeMessageEventListener) {\n this._removeMessageEventListener();\n }\n\n // Register message event listener and store the cleanup function\n this._removeMessageEventListener = socketClient.addMessageEventListener((messageEvent: InboxMessageEventEnvelope) => {\n if (messageEvent.event === InboxMessageEvent.NewMessage) {\n const message: InboxMessage = messageEvent.data as InboxMessage;\n\n this.addMessage(message);\n }\n });\n\n // If the socket is already connecting or open, return early\n if (socketClient.isConnecting || socketClient.isOpen) {\n Courier.shared.client?.options.logger?.info(`Inbox socket already connecting or open for client ID: [${Courier.shared.client?.options.connectionId}]`);\n return;\n }\n\n await socketClient.connect();\n } catch (error: unknown) {\n Courier.shared.client?.options.logger.error('Error listening for messages:', error);\n this._datastoreListeners.forEach(listener => {\n listener.events.onError?.(error as Error);\n });\n }\n }\n\n /**\n * Find the position of an {@link @trycourier/courier-js#InboxMessage} in the toast stack.\n *\n * Notes:\n * - Since the stack is an array, with the last item being the \"top\" of the stack,\n * a toast's position in the underlying array is the inverse of its stack position.\n * - `message` is matched by {@link @trycourier/courier-js#InboxMessage.messageId}, not by object reference.\n *\n * @param message - the {@link @trycourier/courier-js#InboxMessage} to find in the stack\n */\n public toastIndexOfMessage(message: InboxMessage) {\n const position = this._dataset.findIndex(m => m.messageId === message.messageId);\n\n // Message not found\n if (position < 0) {\n return position;\n }\n\n // Return index from end of array (top of stack)\n return this._dataset.length - position - 1;\n }\n\n /**\n * Add an {@link @trycourier/courier-js#InboxMessage} toast item to the datastore.\n *\n * Calling this directly is useful to send test messages while developing with the Courier SDK.</p>\n *\n * @example\n * ```\n * CourierToastDatastore.shared.addMessage({\n * title: 'Lorem ipsum dolor sit',\n * body: 'Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet',\n * messageId: '1'\n * });\n * ```\n *\n * @param message - the message to add as a toast item.\n */\n public addMessage(message: InboxMessage) {\n this._dataset.push(message);\n\n this._datastoreListeners.forEach(listener => {\n if (listener.events.onMessageAdd) {\n listener.events.onMessageAdd(message);\n }\n });\n }\n\n /**\n * Remove an {@link @trycourier/courier-js#InboxMessage} from the datastore.\n *\n * Note: `message` is matched by {@link @trycourier/courier-js#InboxMessage.messageId}, not by object reference\n */\n public removeMessage(message: InboxMessage) {\n const index = this._dataset.findIndex(m => m.messageId === message.messageId);\n if (index < 0) {\n return;\n }\n\n this._dataset.splice(index, /* deleteCount */ 1);\n\n this._datastoreListeners.forEach(listener => {\n if (listener.events.onMessageRemove) {\n listener.events.onMessageRemove(message);\n }\n });\n }\n\n /** Access the shared instance with {@link CourierToastDatastore.shared}. */\n // Prevent instantiation via constructor.\n private constructor() {}\n}\n","import { CourierToastDatastore } from \"./toast-datastore\";\nimport { CourierToastDatastoreEvents } from \"./toast-datastore-events\";\n\n/**\n * Listener containing callbacks for {@link CourierToastDatastore} events.\n *\n * @public\n */\nexport class CourierToastDatastoreListener {\n constructor(readonly events: CourierToastDatastoreEvents) {}\n\n /** Remove this listener. Callbacks will no longer be invoked after remove is called. */\n remove() {\n CourierToastDatastore.shared.removeDatastoreListener(this);\n }\n}\n","import { CourierBaseElement, CourierComponentThemeMode, injectGlobalStyle, registerElement } from \"@trycourier/courier-ui-core\";\nimport { CourierToastThemeManager, CourierToastThemeSubscription } from \"../types/courier-toast-theme-manager\";\nimport { CourierToastTheme, defaultLightTheme } from \"../types/courier-toast-theme\";\nimport { AuthenticationListener, Courier, InboxMessage } from \"@trycourier/courier-js\";\nimport { CourierToastItem } from \"./courier-toast-item\";\nimport { CourierToastItemActionClickEvent, CourierToastItemClickEvent, CourierToastItemFactoryProps } from \"../types/toast\";\nimport { CourierToastDismissButtonOption } from \"../types/toast\";\nimport { CourierToastDatastoreListener } from \"../datastore/toast-datastore-listener\";\nimport { CourierToastDatastore } from \"../datastore/toast-datastore\";\n\n/** Default set of CSS properties used to layout CourierToast. */\ntype CourierToastLayoutProps = {\n position?: string;\n width?: string;\n top?: string;\n right?: string;\n zIndex?: number;\n}\n\n/**\n * An embeddable and customizable toast component, fed by data from Courier Inbox.\n *\n * @example\n *\n * Embedding the default toast component on a webpage.\n * ```\n * <html>\n * <body>\n * <courier-toast></courier-toast>\n *\n * <script type=\"module\">\n * import { Courier } from \"@trycourier/courier-ui-toast\";\n *\n * // Authenticate the user\n * Courier.shared.signIn({ userId, jwt });\n * </script>\n * </body>\n * </html>\n * ```\n *\n * @public\n */\nexport class CourierToast extends CourierBaseElement {\n\n // Internally-maintained state\n private _themeManager: CourierToastThemeManager;\n private _themeSubscription: CourierToastThemeSubscription;\n private _toastStyle?: HTMLStyleElement;\n private _authListener?: AuthenticationListener;\n private _datastoreListener: CourierToastDatastoreListener;\n\n // Consumer-provided options\n private _autoDismiss: boolean = false;\n private _autoDismissTimeoutMs: number = 5000;\n private _dismissButtonOption: CourierToastDismissButtonOption = 'auto';\n private _customToastItem?: (props: CourierToastItemFactoryProps) => HTMLElement;\n private _customToastItemContent?: (props: CourierToastItemFactoryProps) => HTMLElement;\n\n // Consumer-provided callbacks\n private _onItemClick?: ((props: CourierToastItemClickEvent) => void);\n private _onItemActionClick?: ((props: CourierToastItemActionClickEvent) => void);\n\n /** Default layout props. */\n private readonly _defaultLayoutProps: CourierToastLayoutProps = {\n position: 'fixed',\n width: '380px',\n top: '30px',\n right: '30px',\n zIndex: 999,\n };\n\n /**\n * The names of all attributes for which the web component needs change notifications.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes\n */\n static observedAttributes = [\n 'auto-dismiss',\n 'auto-dismiss-timeout-ms',\n 'dismiss-button',\n 'light-theme',\n 'dark-theme',\n 'mode',\n ];\n\n constructor(props: {\n themeManager?: CourierToastThemeManager\n }) {\n super();\n\n this._themeManager = props?.themeManager ?? new CourierToastThemeManager(defaultLightTheme);\n this._themeSubscription = this._themeManager.subscribe((_: CourierToastTheme) => {\n this.refreshStyles();\n });\n this._datastoreListener = new CourierToastDatastoreListener({\n onMessageAdd: this.datastoreAddMessageListener.bind(this),\n onMessageRemove: this.datastoreRemoveMessageListener.bind(this),\n });\n }\n\n /** Set the handler invoked when a toast item is clicked. */\n public onToastItemClick(handler?: (props: CourierToastItemClickEvent) => void): void {\n this._onItemClick = handler;\n }\n\n /** Set the handler invoked when a toast item action button is clicked. */\n public onToastItemActionClick(handler?: (props: CourierToastItemActionClickEvent) => void): void {\n this._onItemActionClick = handler;\n }\n\n /** Enable auto-dismiss for toast items. */\n public enableAutoDismiss() {\n this._autoDismiss = true;\n }\n\n /** Disable auto-dismiss for toast items. */\n public disableAutoDismiss() {\n this._autoDismiss = false;\n }\n\n /**\n * Set the timeout before auto-dismissing toasts.\n * Only applicable if auto-dismiss is enabled.\n * @param timeoutMs - The timeout in milliseconds before a toast is dismissed.\n */\n public setAutoDismissTimeoutMs(timeoutMs: number) {\n this._autoDismissTimeoutMs = timeoutMs;\n }\n\n /**\n * Set the light theme for the toast.\n * @param theme - The light theme object to set.\n */\n public setLightTheme(theme: CourierToastTheme) {\n this._themeManager.setLightTheme(theme);\n }\n\n /**\n * Set the dark theme for the toast.\n * @param theme - The dark theme object to set.\n */\n public setDarkTheme(theme: CourierToastTheme) {\n this._themeManager.setDarkTheme(theme);\n }\n\n /**\n * Set the dismiss button display option.\n *\n * @param option - a value of {@link CourierToastDismissButtonOption}\n */\n public setDismissButton(option: CourierToastDismissButtonOption) {\n this._dismissButtonOption = option;\n this.refreshStyles();\n }\n\n /**\n * Set the theme mode.\n *\n * @param mode - The theme mode, one of \"dark\", \"light\", or \"system\".\n */\n public setMode(mode: CourierComponentThemeMode) {\n this._themeManager.setMode(mode);\n }\n\n /**\n * Set a factory function that renders a toast item.\n *\n * See {@link CourierToast.setToastItemContent} to set the content while preserving the toast item's\n * container and stack styling.\n */\n public setToastItem(factory?: (props: CourierToastItemFactoryProps) => HTMLElement) {\n this._customToastItem = factory;\n }\n\n /**\n * Set a factory function that renders a toast item's content.\n *\n * The toast item's container, including the stack, auto-dismiss timer, and dismiss button\n * and all events are still present when custom content is set.\n *\n * See {@link CourierToast.setDismissButton} to customize the dismiss button's visibility and\n * {@link CourierToast.setToastItem} to customize the entire toast item, including\n * its container.\n */\n public setToastItemContent(factory?: (props: CourierToastItemFactoryProps) => HTMLElement) {\n this._customToastItemContent = factory;\n }\n\n /**\n * Dismiss the toast item(s) associated with a particular {@link @trycourier/courier-js#InboxMessage}.\n *\n * Toast items are matched to messages by the field {@link @trycourier/courier-js#InboxMessage.messageId}.\n * If the item is an instance of {@link CourierToastItem} it will be animated out\n * before removal, otherwise custom items are removed immediately.\n *\n * If there are multiple toast items matching the message, all items will be dismissed.\n *\n * @example\n * Using dismissToastForMessage with setToastItem to dismiss a custom element.\n * ```ts\n * // Get a reference to the toast component\n * const toast = document.getElementById(\"my-toast\");\n *\n * toast.setToastItem((props) => {\n * const el = document.createElement(\"div\");\n * el.addEventListener(\"click\", () => toast.dismissToastForMessage(props.message));\n * return el;\n * });\n * ```\n *\n * @param message - the {@link @trycourier/courier-js#InboxMessage} for which toast items should be dismissed\n */\n private dismissToastForMessage(message: InboxMessage) {\n this.childNodes.forEach(node => {\n const nodeMessageId = (node as HTMLElement).dataset.courierMessageId;\n\n if (nodeMessageId !== message.messageId) {\n return;\n }\n\n if (node instanceof CourierToastItem) {\n node.dismiss();\n } else {\n node.remove();\n }\n });\n }\n\n /**\n * @override\n */\n protected onComponentMounted(): void {\n this._toastStyle = injectGlobalStyle(CourierToast.id, this.getStyles(this.theme));\n\n CourierToastDatastore.shared.addDatastoreListener(this._datastoreListener);\n Courier.shared.addAuthenticationListener(this.authChangedCallback.bind(this));\n CourierToastDatastore.shared.listenForMessages();\n }\n\n /**\n * @override\n */\n protected onComponentUnmounted(): void {\n this._datastoreListener.remove();\n this._authListener?.remove();\n this._toastStyle?.remove();\n this._themeManager.cleanup();\n this._themeSubscription.unsubscribe();\n }\n\n /**\n * Lifecycle callback invoked when an observed attribute changes.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes\n */\n protected attributeChangedCallback(name: string, _: string, newValue: string) {\n switch (name) {\n case 'auto-dismiss':\n if (newValue === 'false') {\n this.disableAutoDismiss();\n } else {\n this.enableAutoDismiss();\n }\n break;\n case 'auto-dismiss-timeout-ms':\n this.setAutoDismissTimeoutMs(parseInt(newValue, /* base= */ 10));\n break;\n case 'dismiss-button':\n if (newValue && CourierToast.isDismissButtonOption(newValue)) {\n this.setDismissButton(newValue as CourierToastDismissButtonOption);\n } else {\n this.setDismissButton('auto');\n }\n break;\n case 'light-theme':\n if (newValue) {\n this.setLightTheme(JSON.parse(newValue));\n }\n break;\n case 'dark-theme':\n if (newValue) {\n this.setDarkTheme(JSON.parse(newValue));\n }\n break;\n case 'mode':\n this._themeManager.setMode(newValue as CourierComponentThemeMode);\n break;\n }\n }\n\n private get theme(): CourierToastTheme {\n return this._themeManager.getTheme();\n }\n\n /** Refresh the styles tag, if it exists, with the current theme. */\n private refreshStyles() {\n if (this._toastStyle) {\n this._toastStyle.textContent = this.getStyles(this.theme);\n }\n }\n\n private authChangedCallback() {\n this.removeAllItems();\n\n // If re-auth'ing logged the user out and closed the WebSocket connection,\n // we'll open a new connection. If one is already open, this is a no-op.\n CourierToastDatastore.shared.listenForMessages();\n }\n\n private removeAllItems(): void {\n while (this.firstChild) {\n this.removeChild(this.firstChild);\n }\n }\n\n private addToastItem(message: InboxMessage): CourierToastItem | HTMLElement {\n // Append the toast item and resize the toast container\n // so previous toast items can stack underneath at fixed offsets\n // from the top item.\n const toastItem = this.createToastItem(message);\n toastItem.dataset.courierMessageId = message.messageId;\n this.appendChild(toastItem);\n this.resizeContainerToHeight(this.topStackItemHeight);\n\n return toastItem;\n }\n\n private createToastItem(message: InboxMessage): CourierToastItem | HTMLElement {\n if (this._customToastItem) {\n return this.createCustomToastItem(message);\n }\n\n return this.createDefaultToastItem(message);\n }\n\n private createDefaultToastItem(message: InboxMessage) {\n const item = new CourierToastItem({\n message,\n autoDismiss: this._autoDismiss,\n autoDismissTimeoutMs: this._autoDismissTimeoutMs,\n themeManager: this._themeManager\n });\n\n item.onItemDismissed((_) => {\n this.resizeContainerToHeight(this.topStackItemHeight);\n });\n\n if (this._customToastItemContent) {\n item.setToastItemContent(this._customToastItemContent);\n }\n\n if (this._onItemClick) {\n item.onToastItemClick(this._onItemClick);\n }\n\n if (this._onItemActionClick) {\n item.onToastItemActionClick(this._onItemActionClick);\n }\n\n if (this._autoDismiss) {\n setTimeout(item.dismiss.bind(item), this._autoDismissTimeoutMs);\n }\n\n return item;\n }\n\n private createCustomToastItem(message: InboxMessage) {\n if (!this._customToastItem) {\n throw Error(\"Attempted to create customToastItem, but none is set\");\n }\n\n const customItem = this._customToastItem({\n message,\n autoDismiss: this._autoDismiss,\n autoDismissTimeoutMs: this._autoDismissTimeoutMs,\n });\n\n if (this._autoDismiss) {\n setTimeout(() => {\n this.removeChild(customItem);\n }, this._autoDismissTimeoutMs);\n }\n\n customItem.addEventListener('click', () => {\n if (this._onItemClick) {\n this._onItemClick({ message });\n }\n });\n\n return customItem;\n }\n\n private datastoreAddMessageListener(message: InboxMessage) {\n this.addToastItem(message);\n }\n\n private datastoreRemoveMessageListener(message: InboxMessage) {\n this.dismissToastForMessage(message);\n }\n\n private getStyles(theme: CourierToastTheme): string {\n const item = theme.item;\n\n // Styles for the top-level toast container.\n const toastStyles = `\n ${CourierToast.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\n // Stack the three most recently shown toast items and hide all others.\n // Content is transparent for all but the most recent (top) toast item\n // since it otherwise peeks out in the visible stack items.\n const toastStackStyles = `\n ${CourierToastItem.id}:last-child {\n top: 0;\n right: 0;\n }\n\n ${CourierToastItem.id}:nth-last-child(2) {\n top: 12px;\n bottom: -12px;\n --scale: 0.95\n }\n\n ${CourierToastItem.id}:nth-last-child(3) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n }\n\n ${CourierToastItem.id}:nth-last-child(n+4) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n visibility: hidden;\n }\n\n ${CourierToastItem.id}:nth-last-child(n+2) > .overflow-hidden-container {\n opacity: 0;\n }\n `;\n\n // Styles for the visible toast item.\n // `opacity` and `transform` are the initial states before\n // the keyframed `animation` show is applied.\n // The class `dismissing` is added to trigger the `animation` hide\n // before removing an item.\n // Only the top item is clickable.\n const toastItemStyles = `\n ${CourierToastItem.id} {\n position: absolute;\n box-sizing: border-box;\n width: 100%;\n background-color: ${item?.backgroundColor};\n box-shadow: ${item?.shadow};\n border: ${item?.border};\n border-radius: ${item?.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 ${CourierToastItem.id} > .overflow-hidden-container {\n height: 100%;\n width: 100%;\n border-radius: ${item?.borderRadius};\n overflow: hidden;\n }\n\n ${CourierToastItem.id}.dismissing {\n animation: courier-toast-hide 0.3s ease-in-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 @keyframes courier-toast-hide {\n 0% {\n opacity: 1;\n transform: scaleX(var(--scale, 1));\n }\n\n 100% {\n opacity: 0;\n transform: scaleX(var(--scale, 1));\n }\n }\n\n ${CourierToastItem.id}.clickable:last-child {\n cursor: pointer;\n }\n\n ${CourierToastItem.id}.clickable:last-child:hover {\n background-color: ${item?.hoverBackgroundColor};\n }\n\n ${CourierToastItem.id}.clickable:last-child:active {\n background-color: ${item?.activeBackgroundColor};\n }\n\n ${CourierToastItem.id}.clickable:nth-last-child(n+2) {\n pointer-events: none;\n }\n `;\n\n // A dismiss icon is visible when the top toast item is in the :hover state.\n // Auto-dismiss styles are added, but unused if the auto-dismiss progress\n // bar is not added in the courier-toast-item element\n // (i.e. when auto-dismiss is disabled).\n const dismissStyles = `\n ${CourierToastItem.id} > .dismiss {\n position: absolute;\n visibility: hidden;\n opacity: 0%;\n top: -10px;\n right: -10px;\n background-color: ${item?.backgroundColor};\n border: ${item?.border};\n padding: 3px;\n border-radius: 50%;\n font-size: 12pt;\n box-shadow: ${item?.shadow};\n cursor: pointer;\n transition: 0.2s ease-in-out;\n }\n\n ${CourierToastItem.id} > .dismiss:hover {\n background-color: ${item?.hoverBackgroundColor};\n }\n\n ${CourierToastItem.id} > .dismiss:active {\n background-color: ${item?.activeBackgroundColor};\n }\n\n ${CourierToastItem.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\n const autoDismissStyles = `\n ${CourierToastItem.id} > .overflow-hidden-container > .auto-dismiss {\n width: 100%;\n height: 5px;\n background-color: ${item?.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\n // Styles for the text and icon content.\n const contentStyles = `\n ${CourierToastItem.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 ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content {\n }\n\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .icon {\n }\n\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content > .title {\n margin: 0;\n font-weight: ${item?.title?.weight};\n font-size: ${item?.title?.size};\n color: ${item?.title?.color};\n }\n\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content > .body {\n margin: 8px 0 0 0;\n font-weight: ${item?.body?.weight};\n font-size: ${item?.body?.size};\n line-height: 150%;\n color: ${item?.body?.color};\n }\n `;\n\n const actionStyles = `\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content > .actions-container {\n display: flex;\n gap: 8px;\n margin-top: 12px;\n }\n `;\n\n return [\n toastStyles,\n toastStackStyles,\n toastItemStyles,\n dismissStyles,\n autoDismissStyles,\n contentStyles,\n actionStyles,\n ].join('');\n }\n\n /** Get the top item's (i.e. the fully visible item's) height. */\n private get topStackItemHeight(): string {\n if (this.lastChild) {\n const height = (this.lastChild as HTMLDivElement).getBoundingClientRect().height;\n return `${height}px`;\n }\n\n return '0px';\n }\n\n private resizeContainerToHeight(height: string) {\n this.style.height = height;\n }\n\n /** Whether the dismiss button should only be shown on hover. */\n private get showDismissOnHover(): boolean {\n // Auto-dismiss is enabled and button is using 'auto' behavior (show w/o auto-dismiss, show on hover w/ auto-dismiss).\n if (this._autoDismiss && this._dismissButtonOption === 'auto') {\n return true;\n }\n\n // Explicitly set to show on hover\n if (this._dismissButtonOption === 'hover') {\n return true;\n }\n\n return false;\n }\n\n /** Whether to show the dismiss button. The button is visible (either always or on hover) if not explicitly disabled. */\n private get showDismiss(): boolean {\n return this._dismissButtonOption !== 'hidden';\n }\n\n /** @override */\n static get id() {\n return 'courier-toast';\n }\n\n private static isDismissButtonOption(value: string): value is CourierToastDismissButtonOption {\n const validOptions: CourierToastDismissButtonOption[] = ['visible', 'hidden', 'hover', 'auto'];\n return validOptions.includes(value as CourierToastDismissButtonOption);\n }\n}\n\nregisterElement(CourierToast);\n","export * from './components/courier-toast';\r\nexport * from './components/courier-toast-item';\r\nexport * from './types/courier-toast-theme';\r\nexport * from './types/courier-toast-theme-manager';\r\nexport * from './types/toast';\r\nexport * from './datastore/toast-datastore';\r\nexport * from './datastore/toast-datastore-listener';\r\nexport * from './datastore/toast-datastore-events';\r\n\r\nimport { Courier } from \"@trycourier/courier-js\";\r\n\r\nCourier.shared.courierUserAgentName = \"courier-ui-toast\";\r\nCourier.shared.courierUserAgentVersion = __PACKAGE_VERSION__;\r\n\r\n// Re-export Courier from courier-js for direct import\r\nexport { Courier };\r\n\r\n// Re-export types from courier-js\r\nexport type {\n CourierProps,\n CourierClientOptions,\n CourierBrand,\n CourierApiRegion,\n CourierApiUrls,\n CourierUserPreferences,\r\n CourierUserPreferencesStatus,\r\n CourierUserPreferencesChannel,\r\n CourierUserPreferencesPaging,\r\n CourierUserPreferencesTopic,\r\n CourierUserPreferencesTopicResponse,\r\n CourierDevice,\r\n CourierToken,\r\n CourierGetInboxMessageResponse,\r\n CourierGetInboxMessagesResponse,\r\n InboxMessage,\r\n InboxAction,\r\n InboxMessageEventEnvelope,\n} from '@trycourier/courier-js';\n\nexport {\n DEFAULT_COURIER_API_URLS,\n EU_COURIER_API_URLS,\n getCourierApiUrls,\n getCourierApiUrlsForRegion\n} from '@trycourier/courier-js';\n\r\n// Re-export types from courier-ui-core\r\nexport type {\r\n CourierComponentThemeMode\r\n} from '@trycourier/courier-ui-core'\r\n","import { InboxMessage } from \"@trycourier/courier-js\";\n\n/**\n * The set of {@link CourierToastDatastore} events for which listeners can be added.\n *\n * @public\n */\nexport class CourierToastDatastoreEvents {\n public onMessageAdd?(_: InboxMessage): void { }\n public onMessageRemove?(_: InboxMessage): void { }\n public onError?(_: Error): void { }\n}\n"],"names":["defaultLightTheme","item","backgroundColor","CourierColors","white","hoverBackgroundColor","gray","activeBackgroundColor","shadow","black","border","borderRadius","title","size","weight","color","body","icon","svg","CourierIconSVGs","inbox","dismissIcon","remove","autoDismissBarColor","blue","actions","font","defaultDarkTheme","mergeTheme","mode","theme","defaultTheme","_a","_b","_c","_d","_e","_f","_g","_h","CourierToastThemeManager","CourierThemeManager","constructor","initialTheme","super","__publicField","this","getDefaultLightTheme","getDefaultDarkTheme","subscribe","callback","manager","_CourierToastItem","CourierBaseElement","props","_message","message","_autoDismiss","autoDismiss","_autoDismissTimeoutMs","autoDismissTimeoutMs","_themeManager","themeManager","_themeSubscription","_","render","onItemDismissed","handler","_onItemDismissedCallback","onToastItemClick","_onToastItemClickCallback","onToastItemActionClick","_onToastItemActionClickCallback","setToastItemContent","factory","_customToastItemContent","dismiss","timeoutMs","dismissAnimationTimeoutMs","classList","add","setTimeout","onComponentMounted","onComponentUnmounted","unsubscribe","getTheme","id","observedAttributes","firstChild","removeChild","removeEventListener","onClick","overflowHiddenContainer","document","createElement","appendChild","append","createDefaultContent","addEventListener","CourierIcon","event","stopPropagation","content","textContent","preview","messageHasActions","actionsContainer","forEach","action","button","createActionButton","length","actionsTheme","CourierButton","text","variant","fontFamily","family","fontSize","fontWeight","textColor","CourierToastItem","registerElement","_CourierToastDatastore","shared","instance","addDatastoreListener","listener","_datastoreListeners","push","removeDatastoreListener","filter","l","listenForMessages","socketClient","Courier","client","socket","options","logger","info","_removeMessageEventListener","addMessageEventListener","messageEvent","InboxMessageEvent","NewMessage","data","addMessage","isConnecting","isOpen","connectionId","connect","error","events","onError","call","toastIndexOfMessage","position","_dataset","findIndex","m","messageId","onMessageAdd","removeMessage","index","splice","onMessageRemove","CourierToastDatastore","CourierToastDatastoreListener","_CourierToast","width","top","right","zIndex","refreshStyles","_datastoreListener","datastoreAddMessageListener","bind","datastoreRemoveMessageListener","_onItemClick","_onItemActionClick","enableAutoDismiss","disableAutoDismiss","setAutoDismissTimeoutMs","setLightTheme","setDarkTheme","setDismissButton","option","_dismissButtonOption","setMode","setToastItem","_customToastItem","dismissToastForMessage","childNodes","node","dataset","courierMessageId","_toastStyle","injectGlobalStyle","getStyles","addAuthenticationListener","authChangedCallback","_authListener","cleanup","attributeChangedCallback","name","newValue","parseInt","isDismissButtonOption","JSON","parse","removeAllItems","addToastItem","toastItem","createToastItem","resizeContainerToHeight","topStackItemHeight","createCustomToastItem","createDefaultToastItem","Error","customItem","_defaultLayoutProps","showDismissOnHover","showDismiss","join","lastChild","getBoundingClientRect","height","style","value","includes","CourierToast","courierUserAgentName","courierUserAgentVersion"],"mappings":"gjBAwCO,MAAMA,EAAuC,CAClDC,KAAM,CACJC,gBAAiBC,EAAAA,cAAcC,MAAM,KACrCC,qBAAsBF,EAAAA,cAAcG,KAAK,KACzCC,sBAAuBJ,EAAAA,cAAcG,KAAK,KAC1CE,OAAQ,oBAAoBL,EAAAA,cAAcM,MAAM,SAChDC,OAAQ,aAAaP,EAAAA,cAAcG,KAAK,OACxCK,aAAc,MACdC,MAAO,CACLC,KAAM,OACNC,OAAQ,MACRC,MAAOZ,EAAAA,cAAcM,MAAM,MAE7BO,KAAM,CACJH,KAAM,OACNC,OAAQ,MACRC,MAAOZ,EAAAA,cAAcG,KAAK,MAE5BW,KAAM,CACJF,MAAOZ,EAAAA,cAAcM,MAAM,KAC3BS,IAAKC,EAAAA,gBAAgBC,OAEvBC,YAAa,CACXN,MAAOZ,EAAAA,cAAcM,MAAM,KAC3BS,IAAKC,EAAAA,gBAAgBG,QAEvBC,oBAAqBpB,EAAAA,cAAcqB,KAAK,KACxCC,QAAS,CACPvB,gBAAiB,cACjBG,qBAAsBF,EAAAA,cAAcG,KAAK,KACzCC,sBAAuBJ,EAAAA,cAAcG,KAAK,KAC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Me,WAAN,EAAAmB,EAAYrB,+BACd,OAAAsB,EAAA,MAAAnC,OAAA,EAAAA,EAAMe,WAAN,EAAAoB,EAAYvB,qDAEhB,OAAAwB,EAAA,MAAApC,OAAA,EAAAA,EAAMe,WAAN,EAAAqB,EAAYtB,wBAIJ,WACjB0G,EAAiBnC,0KAenB0I,KAAK,GACT,CAGA,sBAAYR,GACV,GAAI1K,KAAKmL,UAAW,CAElB,MAAO,GADSnL,KAAKmL,UAA6BC,wBAAwBC,UAE5E,CAEA,MAAO,KACT,CAEQ,uBAAAZ,CAAwBY,GAC9BrL,KAAKsL,MAAMD,OAASA,CACtB,CAGA,sBAAYL,GAEV,SAAIhL,KAAKW,cAA8C,SAA9BX,KAAK8I,uBAKI,UAA9B9I,KAAK8I,oBAKX,CAGA,eAAYmC,GACV,MAAqC,WAA9BjL,KAAK8I,oBACd,CAGA,aAAWtG,GACT,MAAO,eACT,CAEA,4BAAe0H,CAAsBqB,GAEnC,MADwD,CAAC,UAAW,SAAU,QAAS,QACnEC,SAASD,EAC/B,GA9kBAxL,EAlCW4H,EAkCJ,qBAAqB,CAC1B,eACA,0BACA,iBACA,cACA,aACA,SAxCG,IAAM8D,EAAN9D,EAmnBP/C,EAAAA,gBAAgB6G,GClpBhBhG,EAAAA,QAAQX,OAAO4G,qBAAuB,mBACtCjG,EAAAA,QAAQX,OAAO6G,wBAA0B,8hBCLlC,MACE,YAAAvE,CAAclG,GAAyB,CACvC,eAAAsG,CAAiBtG,GAAyB,CAC1C,OAAA0F,CAAS1F,GAAkB"}
1
+ {"version":3,"file":"index.js","sources":["../src/types/courier-toast-theme.ts","../src/types/courier-toast-theme-manager.ts","../src/utils/pausable-timeout.ts","../src/components/courier-toast-item.ts","../src/datastore/toast-datastore.ts","../src/datastore/toast-datastore-listener.ts","../src/components/courier-toast.ts","../src/index.ts","../src/datastore/toast-datastore-events.ts"],"sourcesContent":["import { CourierColors, CourierIconSVGs, SystemThemeMode, CourierFontTheme, CourierIconTheme } from \"@trycourier/courier-ui-core\";\r\n\r\n// Re-export common types from core for convenience\r\n\r\n/** @public */\r\nexport type CourierToastFontTheme = CourierFontTheme;\r\n\r\n/** @public */\r\nexport type CourierToastIconTheme = CourierIconTheme;\r\n\r\n/** @public */\r\nexport type CourierToastItemTheme = {\r\n backgroundColor?: string;\r\n hoverBackgroundColor?: string;\r\n activeBackgroundColor?: string;\r\n autoDismissBarColor?: string;\r\n title?: CourierToastFontTheme;\r\n body?: CourierToastFontTheme;\r\n icon?: CourierToastIconTheme;\r\n dismissIcon?: CourierToastIconTheme;\r\n shadow?: string;\r\n border?: string;\r\n borderRadius?: string;\r\n actions?: {\r\n backgroundColor?: string;\r\n hoverBackgroundColor?: string;\r\n activeBackgroundColor?: string;\r\n border?: string;\r\n borderRadius?: string;\r\n shadow?: string;\r\n font?: CourierToastFontTheme;\r\n }\r\n}\r\n\r\n/** @public */\r\nexport type CourierToastTheme = {\r\n item?: CourierToastItemTheme;\r\n};\r\n\r\n/** @public */\r\nexport const defaultLightTheme: CourierToastTheme = {\r\n item: {\r\n backgroundColor: CourierColors.white[500],\r\n hoverBackgroundColor: CourierColors.gray[200],\r\n activeBackgroundColor: CourierColors.gray[500],\r\n shadow: `0px 4px 8px -2px ${CourierColors.black[500_20]}`,\r\n border: `1px solid ${CourierColors.gray[500]}`,\r\n borderRadius: '8px',\r\n title: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.black[500],\r\n },\r\n body: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.gray[600],\r\n },\r\n icon: {\r\n color: CourierColors.black[500],\r\n svg: CourierIconSVGs.inbox,\r\n },\r\n dismissIcon: {\r\n color: CourierColors.black[500],\r\n svg: CourierIconSVGs.remove,\r\n },\r\n autoDismissBarColor: CourierColors.blue[400],\r\n actions: {\r\n backgroundColor: 'transparent',\r\n hoverBackgroundColor: CourierColors.gray[200],\r\n activeBackgroundColor: CourierColors.gray[500],\r\n border: `1px solid ${CourierColors.gray[500]}`,\r\n borderRadius: '4px',\r\n shadow: '0px 1px 2px 0px rgba(0, 0, 0, 0.06)',\r\n font: {\r\n color: CourierColors.black[500],\r\n size: '14px',\r\n }\r\n }\r\n }\r\n};\r\n\r\n/** @public */\r\nexport const defaultDarkTheme: CourierToastTheme = {\r\n item: {\r\n backgroundColor: CourierColors.black[500],\r\n hoverBackgroundColor: CourierColors.gray[800],\r\n activeBackgroundColor: CourierColors.gray[700],\r\n shadow: `0px 4px 8px -2px ${CourierColors.gray[400]}`,\r\n border: `1px solid ${CourierColors.gray[400]}`,\r\n borderRadius: '8px',\r\n title: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.white[500],\r\n },\r\n body: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.gray[500],\r\n },\r\n icon: {\r\n color: CourierColors.white[500],\r\n svg: CourierIconSVGs.inbox,\r\n },\r\n dismissIcon: {\r\n color: CourierColors.white[500],\r\n svg: CourierIconSVGs.remove,\r\n },\r\n autoDismissBarColor: CourierColors.blue[400],\r\n actions: {\r\n backgroundColor: CourierColors.black[400],\r\n hoverBackgroundColor: CourierColors.white[500_10],\r\n activeBackgroundColor: CourierColors.white[500_20],\r\n border: `1px solid ${CourierColors.gray[400]}`,\r\n borderRadius: '4px',\r\n shadow: `0px 1px 2px 0px ${CourierColors.white[500_10]}`,\r\n font: {\r\n color: CourierColors.white[500],\r\n size: '14px'\r\n }\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Deep merge themes, only overwriting non-optional properties.\r\n *\r\n * @public\r\n */\r\nexport const mergeTheme = (mode: SystemThemeMode, theme: CourierToastTheme): CourierToastTheme => {\r\n const defaultTheme = mode === 'light' ? defaultLightTheme : defaultDarkTheme;\r\n return {\r\n item: {\r\n ...defaultTheme.item,\r\n ...theme.item,\r\n title: {\r\n ...defaultTheme.item?.title,\r\n ...theme.item?.title\r\n },\r\n body: {\r\n ...defaultTheme.item?.body,\r\n ...theme.item?.body\r\n },\r\n icon: {\r\n ...defaultTheme.item?.icon,\r\n ...theme.item?.icon\r\n },\r\n dismissIcon: {\r\n ...defaultTheme.item?.dismissIcon,\r\n ...theme.item?.dismissIcon\r\n }\r\n }\r\n };\r\n};\r\n","import { CourierThemeManager, CourierThemeSubscription, SystemThemeMode } from \"@trycourier/courier-ui-core\";\r\nimport { CourierToastTheme, defaultDarkTheme, defaultLightTheme, mergeTheme } from \"./courier-toast-theme\";\r\n\r\n/**\r\n * @public\r\n */\r\nexport interface CourierToastThemeSubscription extends CourierThemeSubscription<CourierToastTheme> {\r\n manager: CourierToastThemeManager;\r\n}\r\n\r\n/**\r\n * Toast-specific theme manager that extends the abstract CourierThemeManager.\r\n * Provides toast theme management with light/dark mode support.\r\n *\r\n * @public\r\n */\r\nexport class CourierToastThemeManager extends CourierThemeManager<CourierToastTheme> {\r\n\r\n // Event ID for toast theme changes\r\n protected readonly THEME_CHANGE_EVENT: string = 'courier_toast_theme_change';\r\n\r\n constructor(initialTheme: CourierToastTheme) {\r\n super(initialTheme);\r\n }\r\n\r\n /**\r\n * Get the default light theme for toast\r\n */\r\n protected getDefaultLightTheme(): CourierToastTheme {\r\n return defaultLightTheme;\r\n }\r\n\r\n /**\r\n * Get the default dark theme for toast\r\n */\r\n protected getDefaultDarkTheme(): CourierToastTheme {\r\n return defaultDarkTheme;\r\n }\r\n\r\n /**\r\n * Merge the toast theme with defaults\r\n */\r\n protected mergeTheme(mode: SystemThemeMode, theme: CourierToastTheme): CourierToastTheme {\r\n return mergeTheme(mode, theme);\r\n }\r\n\r\n /**\r\n * Subscribe to toast theme changes\r\n * @param callback - Function to run when the theme changes\r\n * @returns Object with unsubscribe method to stop listening\r\n */\r\n public subscribe(callback: (theme: CourierToastTheme) => void): CourierToastThemeSubscription {\r\n const baseSubscription = super.subscribe(callback);\r\n return {\r\n ...baseSubscription,\r\n manager: this\r\n };\r\n }\r\n\r\n}\r\n","/**\n * A `setTimeout` that can be paused and resumed.\n *\n * Pausing banks the time that has already elapsed, so resuming fires the\n * callback after the *remaining* time rather than restarting the full delay.\n *\n * Used for the toast auto-dismiss countdown, which pauses while the cursor is\n * over the toast.\n */\nexport class PausableTimeout {\n private readonly _callback: () => void;\n\n /** Time left on the countdown, updated each time it's paused. */\n private _remainingMs: number;\n\n private _timerId: ReturnType<typeof setTimeout> | null = null;\n\n /** When the currently-running countdown was (re)started. */\n private _startedAt = 0;\n\n private _isPaused = false;\n\n /** Set once the callback has fired (or the countdown was cancelled). */\n private _isDone = false;\n\n constructor(callback: () => void, delayMs: number) {\n this._callback = callback;\n this._remainingMs = delayMs;\n }\n\n /** Whether the countdown is currently paused. */\n public get isPaused(): boolean {\n return this._isPaused;\n }\n\n /** Start the countdown for whatever time is left on it. */\n public start(): void {\n if (this._isDone) {\n return;\n }\n\n this.clear();\n this._isPaused = false;\n this._startedAt = Date.now();\n this._timerId = setTimeout(() => {\n this._timerId = null;\n this._isDone = true;\n this._callback();\n }, this._remainingMs);\n }\n\n /** Pause the countdown, banking the time that has already elapsed. */\n public pause(): void {\n if (this._isDone || this._isPaused || this._timerId === null) {\n return;\n }\n\n this._remainingMs = Math.max(0, this._remainingMs - (Date.now() - this._startedAt));\n this._isPaused = true;\n this.clear();\n }\n\n /** Resume a paused countdown from where it left off. */\n public resume(): void {\n if (this._isDone || !this._isPaused) {\n return;\n }\n\n this.start();\n }\n\n /** Cancel the countdown for good; it can't be started again. */\n public cancel(): void {\n this._isPaused = false;\n this._isDone = true;\n this.clear();\n }\n\n private clear(): void {\n if (this._timerId !== null) {\n clearTimeout(this._timerId);\n this._timerId = null;\n }\n }\n}\n","import { CourierBaseElement, CourierButton, CourierIcon, registerElement } from \"@trycourier/courier-ui-core\";\nimport { CourierToastThemeManager, CourierToastThemeSubscription } from \"../types/courier-toast-theme-manager\";\nimport { CourierToastTheme } from \"../types/courier-toast-theme\";\nimport { InboxAction, InboxMessage } from \"@trycourier/courier-js\";\nimport { CourierToastItemActionClickEvent, CourierToastItemClickEvent, CourierToastItemFactoryProps } from \"../types/toast\";\nimport { PausableTimeout } from \"../utils/pausable-timeout\";\n\n/**\n * Default implementation of a Toast item.\n *\n * @see {@link CourierToast}\n * @public\n */\nexport class CourierToastItem extends CourierBaseElement {\n /** The animation duration to fade out a dismissed toast before its element is removed. */\n private static readonly dismissAnimationTimeoutMs = 300;\n\n private _themeManager: CourierToastThemeManager;\n private _themeSubscription: CourierToastThemeSubscription;\n private _message: InboxMessage;\n private _customToastItemContent?: (props: CourierToastItemFactoryProps) => HTMLElement;\n\n /** Whether this toast item is auto-dismissed. */\n private readonly _autoDismiss: boolean;\n\n /** The timeout before the toast item is auto-dismissed, applicable if _autoDismiss is true. */\n private readonly _autoDismissTimeoutMs: number;\n\n // Auto-dismiss countdown state. The countdown is paused while the cursor is\n // over the toast and resumed (from where it left off) when the cursor leaves,\n // so a user reading the toast is never rushed. Hover is tracked by the\n // containing CourierToast, which pauses/resumes every item in the stack —\n // see CourierToast.setAutoDismissPaused.\n private _autoDismissTimeout: PausableTimeout | null = null;\n\n /** The progress bar element, paused/resumed alongside the countdown to stay in sync. */\n private _autoDismissBar: HTMLElement | null = null;\n\n // Callbacks\n private _onItemDismissedCallback: ((props: { message: InboxMessage }) => void) | null = null;\n private _onToastItemClickCallback: ((props: CourierToastItemClickEvent) => void) | null = null;\n private _onToastItemActionClickCallback: ((props: CourierToastItemActionClickEvent) => void) | null = null;\n\n constructor(props: {\n message: InboxMessage,\n autoDismiss: boolean,\n autoDismissTimeoutMs: number,\n themeManager: CourierToastThemeManager,\n }) {\n\n super();\n this._message = props.message;\n this._autoDismiss = props.autoDismiss;\n this._autoDismissTimeoutMs = props.autoDismissTimeoutMs;\n\n this._themeManager = props.themeManager;\n this._themeSubscription = this._themeManager.subscribe((_: CourierToastTheme) => {\n this.render();\n });\n }\n\n /**\n * Registers a handler called when the item is dismissed.\n *\n * @param handler - A function to be called when the item is dismissed.\n */\n public onItemDismissed(handler: (props: { message: InboxMessage }) => void): void {\n this._onItemDismissedCallback = handler;\n }\n\n /**\n * Registers a handler for item click events.\n *\n * @param handler - A function to be called when the item is clicked.\n */\n public onToastItemClick(handler: (props: CourierToastItemClickEvent) => void): void {\n this._onToastItemClickCallback = handler;\n\n // Re-render to set/un-set the .clickable class\n this.render();\n }\n\n /**\n * Registers a handler for item click events.\n *\n * @param handler - A function to be called when the item is clicked.\n */\n public onToastItemActionClick(handler: (props: CourierToastItemActionClickEvent) => void): void {\n this._onToastItemActionClickCallback = handler;\n\n // Re-render to set/un-set the .clickable class\n this.render();\n }\n\n\n /**\n * Set a custom content element for the toast item, reusing the {@link CourierToastItem}\n * container, which provides styling, animations, and event handling.\n *\n * @param factory - Function that returns an `HTMLElement` to render as the content.\n */\n public setToastItemContent(factory?: (props: CourierToastItemFactoryProps) => HTMLElement) {\n this._customToastItemContent = factory;\n }\n\n /**\n * Dismiss the toast item.\n *\n * By default the toast fades out before it's removed. Set `timeoutMs` to\n * `0` to remove the item immediately.\n *\n * @param timeoutMs - the animation duration to fade out the toast item\n */\n public dismiss(timeoutMs: number = CourierToastItem.dismissAnimationTimeoutMs) {\n // Stop the countdown so it can't fire again after we've started dismissing.\n this._autoDismissTimeout?.cancel();\n this.classList.add('dismissing');\n\n setTimeout(() => {\n this.remove();\n\n if (this._onItemDismissedCallback) {\n this._onItemDismissedCallback({ message: this._message });\n }\n }, timeoutMs);\n }\n\n /**\n * Pause the auto-dismiss countdown, banking the time already elapsed and\n * freezing the progress bar so the two stay in sync.\n *\n * Called by the containing {@link CourierToast} while the cursor is over the\n * toast stack. No-op if this item doesn't auto-dismiss.\n */\n public pauseAutoDismiss(): void {\n this._autoDismissTimeout?.pause();\n this.syncAutoDismissBarPlayState();\n }\n\n /**\n * Resume a paused auto-dismiss countdown from where it left off.\n *\n * Called by the containing {@link CourierToast} once the cursor leaves the\n * toast stack. No-op if this item doesn't auto-dismiss.\n */\n public resumeAutoDismiss(): void {\n this._autoDismissTimeout?.resume();\n this.syncAutoDismissBarPlayState();\n }\n\n /** Freeze/unfreeze the progress bar to match the countdown. */\n private syncAutoDismissBarPlayState(): void {\n if (!this._autoDismissBar) {\n return;\n }\n\n this._autoDismissBar.style.animationPlayState = this._autoDismissTimeout?.isPaused ? 'paused' : 'running';\n }\n\n /** @override */\n protected onComponentMounted(): void {\n this.render();\n\n if (this._autoDismiss) {\n this._autoDismissTimeout = new PausableTimeout(() => this.dismiss(), this._autoDismissTimeoutMs);\n this._autoDismissTimeout.start();\n }\n }\n\n /** @override */\n protected onComponentUnmounted(): void {\n this._themeSubscription.unsubscribe();\n this._autoDismissTimeout?.cancel();\n }\n\n get theme(): CourierToastTheme {\n return this._themeManager.getTheme();\n }\n\n /**\n * @override\n */\n static get id(): string {\n return 'courier-toast-item';\n }\n\n /**\n * @override\n */\n static get observedAttributes(): string[] {\n return [];\n }\n\n /**\n * Render a toast item, either with default content or custom content if\n * a content factory function is provided.\n *\n * Note: Styles for the toast item are set in {@link CourierToast} since\n * toasts are ephemeral by nature and we want to avoid adding/removing/duplicating\n * styles as {@link CourierToastItem}s enter/exit.\n */\n private render(): void {\n // Reset existing content and top-level listeners\n while (this.firstChild) {\n this.removeChild(this.firstChild);\n }\n this.removeEventListener('click', this.onClick);\n\n // Content and the auto-dismiss bar are wrapped in a container that hides overflow.\n // The standard dismiss button overflows the toast.\n const overflowHiddenContainer = document.createElement('div');\n overflowHiddenContainer.classList.add('overflow-hidden-container');\n this.appendChild(overflowHiddenContainer);\n\n // Auto-dismiss\n if (this._autoDismiss) {\n const autoDismiss = document.createElement('div');\n autoDismiss.classList.add('auto-dismiss');\n // Keep the bar frozen if we re-render (e.g. theme change) while paused.\n if (this._autoDismissTimeout?.isPaused) {\n autoDismiss.style.animationPlayState = 'paused';\n }\n overflowHiddenContainer.append(autoDismiss);\n this._autoDismissBar = autoDismiss;\n }\n\n // Content\n if (this._customToastItemContent) {\n overflowHiddenContainer.appendChild(this._customToastItemContent({ message: this._message, autoDismiss: this._autoDismiss, autoDismissTimeoutMs: this._autoDismissTimeoutMs }));\n } else {\n overflowHiddenContainer.appendChild(this.createDefaultContent());\n }\n\n // Click-ability\n if (this._onToastItemClickCallback) {\n this.classList.add('clickable');\n }\n\n this.addEventListener('click', this.onClick);\n\n // Dismiss button\n const dismiss = new CourierIcon(\n this.theme.item?.dismissIcon?.color,\n this.theme.item?.dismissIcon?.svg,\n );\n dismiss.classList.add('dismiss');\n dismiss.addEventListener('click', (event) => {\n event.stopPropagation();\n this.remove();\n\n if (this._onItemDismissedCallback) {\n this._onItemDismissedCallback({ message: this._message });\n }\n });\n this.appendChild(dismiss);\n }\n\n /** Create the default content for this item. */\n private createDefaultContent(): HTMLElement {\n const content = document.createElement('div');\n content.classList.add('content');\n this.append(content);\n\n const icon = new CourierIcon(\n this.theme.item?.icon?.color,\n this.theme.item?.icon?.svg,\n );\n icon.classList.add('icon');\n content.appendChild(icon);\n\n const textContent = document.createElement('div');\n textContent.classList.add('text-content');\n content.appendChild(textContent);\n\n const title = document.createElement('p');\n title.classList.add('title');\n title.textContent = this._message.title ?? '';\n textContent.appendChild(title);\n\n const body = document.createElement('p');\n body.classList.add('body');\n body.textContent = this._message.preview ?? this._message.body ?? '';\n textContent.appendChild(body);\n\n if (this.messageHasActions) {\n const actionsContainer = document.createElement('div');\n actionsContainer.classList.add('actions-container');\n textContent.appendChild(actionsContainer);\n\n this._message.actions?.forEach(action => {\n const button = this.createActionButton(action);\n actionsContainer.appendChild(button);\n });\n }\n\n return content;\n }\n\n private get messageHasActions() {\n return this._message.actions && this._message.actions.length > 0;\n }\n\n private createActionButton(action: InboxAction): CourierButton {\n const actionsTheme = this._themeManager.getTheme().item?.actions;\n\n return new CourierButton({\n mode: this._themeManager.mode,\n text: action.content,\n variant: 'secondary',\n backgroundColor: actionsTheme?.backgroundColor,\n hoverBackgroundColor: actionsTheme?.hoverBackgroundColor,\n activeBackgroundColor: actionsTheme?.activeBackgroundColor,\n border: actionsTheme?.border,\n borderRadius: actionsTheme?.borderRadius,\n shadow: actionsTheme?.shadow,\n fontFamily: actionsTheme?.font?.family,\n fontSize: actionsTheme?.font?.size,\n fontWeight: actionsTheme?.font?.weight,\n textColor: actionsTheme?.font?.color,\n onClick: () => {\n if (this._onToastItemActionClickCallback) {\n this._onToastItemActionClickCallback({ message: this._message, action });\n }\n }\n });\n\n\n }\n\n private onClick(event: Event) {\n event.stopPropagation();\n if (this._onToastItemClickCallback) {\n this._onToastItemClickCallback({ message: this._message });\n }\n }\n}\n\nregisterElement(CourierToastItem);\n","import { Courier, InboxMessage, InboxMessageEvent, InboxMessageEventEnvelope } from \"@trycourier/courier-js\";\nimport { CourierToastDatastoreListener } from \"./toast-datastore-listener\";\n\n/**\n * Shared datastore for Courier toasts.\n *\n * This datastore listens to and stores Courier Inbox messages.\n *\n * @public\n */\nexport class CourierToastDatastore {\n /** Shared instance. Access via {@link CourierToastDatastore.shared}. */\n private static instance: CourierToastDatastore;\n\n /** FIFO stack of toast messages. The end of the array is index 0 of the stack. */\n private _dataset: InboxMessage[] = [];\n\n /** Set of listeners whose handlers will be called when the datastore changes. */\n private _datastoreListeners: CourierToastDatastoreListener[] = [];\n\n /** Cleanup function to remove the message event listener. */\n private _removeMessageEventListener?: () => void;\n\n /** The shared instance of CourierToastDatastore, used to access all public methods. */\n public static get shared(): CourierToastDatastore {\n if (!CourierToastDatastore.instance) {\n CourierToastDatastore.instance = new CourierToastDatastore();\n }\n\n return CourierToastDatastore.instance;\n }\n\n /**\n * Add a listener whose handlers are called when there are changes to the datastore.\n *\n * @param listener - an implementation of {@link CourierToastDatastoreListener}\n */\n public addDatastoreListener(listener: CourierToastDatastoreListener) {\n this._datastoreListeners.push(listener);\n }\n\n /**\n * Remove a previously added listener.\n *\n * Note: the `listener` param is matched by object reference, so callers must pass\n * the same object previously passed to {@link CourierToastDatastore.addDatastoreListener}.\n *\n * See also: {@link CourierToastDatastoreListener.remove}\n *\n * @param listener - a previously added listener implementation\n */\n public removeDatastoreListener(listener: CourierToastDatastoreListener) {\n this._datastoreListeners = this._datastoreListeners.filter(l => l !== listener);\n }\n\n /**\n * Start listening for toast messages.\n *\n * Calling this method will open a WebSocket connection to the Courier backend if one\n * is not already open.\n *\n * See also: {@link @trycourier/courier-js#Courier.shared.signIn} and {@link @trycourier/courier-js#Courier.shared.signOut}\n */\n public async listenForMessages() {\n try {\n const socketClient = Courier.shared.client?.inbox.socket;\n\n if (!socketClient) {\n Courier.shared.client?.options.logger?.info('CourierInbox socket not available');\n return;\n }\n\n // Remove any existing listener before adding a new one\n // This prevents duplicates and handles socket changes\n if (this._removeMessageEventListener) {\n this._removeMessageEventListener();\n }\n\n // Register message event listener and store the cleanup function\n this._removeMessageEventListener = socketClient.addMessageEventListener((messageEvent: InboxMessageEventEnvelope) => {\n if (messageEvent.event === InboxMessageEvent.NewMessage) {\n const message: InboxMessage = messageEvent.data as InboxMessage;\n\n this.addMessage(message);\n }\n });\n\n // If the socket is already connecting or open, return early\n if (socketClient.isConnecting || socketClient.isOpen) {\n Courier.shared.client?.options.logger?.info(`Inbox socket already connecting or open for client ID: [${Courier.shared.client?.options.connectionId}]`);\n return;\n }\n\n await socketClient.connect();\n } catch (error: unknown) {\n Courier.shared.client?.options.logger.error('Error listening for messages:', error);\n this._datastoreListeners.forEach(listener => {\n listener.events.onError?.(error as Error);\n });\n }\n }\n\n /**\n * Find the position of an {@link @trycourier/courier-js#InboxMessage} in the toast stack.\n *\n * Notes:\n * - Since the stack is an array, with the last item being the \"top\" of the stack,\n * a toast's position in the underlying array is the inverse of its stack position.\n * - `message` is matched by {@link @trycourier/courier-js#InboxMessage.messageId}, not by object reference.\n *\n * @param message - the {@link @trycourier/courier-js#InboxMessage} to find in the stack\n */\n public toastIndexOfMessage(message: InboxMessage) {\n const position = this._dataset.findIndex(m => m.messageId === message.messageId);\n\n // Message not found\n if (position < 0) {\n return position;\n }\n\n // Return index from end of array (top of stack)\n return this._dataset.length - position - 1;\n }\n\n /**\n * Add an {@link @trycourier/courier-js#InboxMessage} toast item to the datastore.\n *\n * Calling this directly is useful to send test messages while developing with the Courier SDK.</p>\n *\n * @example\n * ```\n * CourierToastDatastore.shared.addMessage({\n * title: 'Lorem ipsum dolor sit',\n * body: 'Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet',\n * messageId: '1'\n * });\n * ```\n *\n * @param message - the message to add as a toast item.\n */\n public addMessage(message: InboxMessage) {\n this._dataset.push(message);\n\n this._datastoreListeners.forEach(listener => {\n if (listener.events.onMessageAdd) {\n listener.events.onMessageAdd(message);\n }\n });\n }\n\n /**\n * Remove an {@link @trycourier/courier-js#InboxMessage} from the datastore.\n *\n * Note: `message` is matched by {@link @trycourier/courier-js#InboxMessage.messageId}, not by object reference\n */\n public removeMessage(message: InboxMessage) {\n const index = this._dataset.findIndex(m => m.messageId === message.messageId);\n if (index < 0) {\n return;\n }\n\n this._dataset.splice(index, /* deleteCount */ 1);\n\n this._datastoreListeners.forEach(listener => {\n if (listener.events.onMessageRemove) {\n listener.events.onMessageRemove(message);\n }\n });\n }\n\n /** Access the shared instance with {@link CourierToastDatastore.shared}. */\n // Prevent instantiation via constructor.\n private constructor() {}\n}\n","import { CourierToastDatastore } from \"./toast-datastore\";\nimport { CourierToastDatastoreEvents } from \"./toast-datastore-events\";\n\n/**\n * Listener containing callbacks for {@link CourierToastDatastore} events.\n *\n * @public\n */\nexport class CourierToastDatastoreListener {\n constructor(readonly events: CourierToastDatastoreEvents) {}\n\n /** Remove this listener. Callbacks will no longer be invoked after remove is called. */\n remove() {\n CourierToastDatastore.shared.removeDatastoreListener(this);\n }\n}\n","import { CourierBaseElement, CourierComponentThemeMode, injectGlobalStyle, registerElement } from \"@trycourier/courier-ui-core\";\nimport { CourierToastThemeManager, CourierToastThemeSubscription } from \"../types/courier-toast-theme-manager\";\nimport { CourierToastTheme, defaultLightTheme } from \"../types/courier-toast-theme\";\nimport { AuthenticationListener, Courier, InboxMessage } from \"@trycourier/courier-js\";\nimport { CourierToastItem } from \"./courier-toast-item\";\nimport { CourierToastItemActionClickEvent, CourierToastItemClickEvent, CourierToastItemFactoryProps } from \"../types/toast\";\nimport { CourierToastDismissButtonOption } from \"../types/toast\";\nimport { CourierToastDatastoreListener } from \"../datastore/toast-datastore-listener\";\nimport { CourierToastDatastore } from \"../datastore/toast-datastore\";\nimport { PausableTimeout } from \"../utils/pausable-timeout\";\n\n/** Default set of CSS properties used to layout CourierToast. */\ntype CourierToastLayoutProps = {\n position?: string;\n width?: string;\n top?: string;\n right?: string;\n zIndex?: number;\n}\n\n/**\n * An embeddable and customizable toast component, fed by data from Courier Inbox.\n *\n * @example\n *\n * Embedding the default toast component on a webpage.\n * ```\n * <html>\n * <body>\n * <courier-toast></courier-toast>\n *\n * <script type=\"module\">\n * import { Courier } from \"@trycourier/courier-ui-toast\";\n *\n * // Authenticate the user\n * Courier.shared.signIn({ userId, jwt });\n * </script>\n * </body>\n * </html>\n * ```\n *\n * @public\n */\nexport class CourierToast extends CourierBaseElement {\n\n // Internally-maintained state\n private _themeManager: CourierToastThemeManager;\n private _themeSubscription: CourierToastThemeSubscription;\n private _toastStyle?: HTMLStyleElement;\n private _authListener?: AuthenticationListener;\n private _datastoreListener: CourierToastDatastoreListener;\n\n /**\n * Whether the cursor is currently over the toast stack.\n *\n * Hover is tracked here — on the container — rather than per item, because\n * the stacked items are one hover surface: moving between them (or a new\n * toast arriving under the cursor) must not resume anyone's countdown.\n */\n private _isHovered = false;\n\n /**\n * Auto-dismiss countdowns for custom toast items set via\n * {@link CourierToast.setToastItem}. {@link CourierToastItem}s own their own\n * countdown, so they're not tracked here.\n */\n private _customItemAutoDismissTimeouts = new WeakMap<HTMLElement, PausableTimeout>();\n\n // Consumer-provided options\n private _autoDismiss: boolean = false;\n private _autoDismissTimeoutMs: number = 5000;\n private _dismissButtonOption: CourierToastDismissButtonOption = 'auto';\n private _customToastItem?: (props: CourierToastItemFactoryProps) => HTMLElement;\n private _customToastItemContent?: (props: CourierToastItemFactoryProps) => HTMLElement;\n\n // Consumer-provided callbacks\n private _onItemClick?: ((props: CourierToastItemClickEvent) => void);\n private _onItemActionClick?: ((props: CourierToastItemActionClickEvent) => void);\n\n /** Default layout props. */\n private readonly _defaultLayoutProps: CourierToastLayoutProps = {\n position: 'fixed',\n width: '380px',\n top: '30px',\n right: '30px',\n zIndex: 999,\n };\n\n /**\n * The names of all attributes for which the web component needs change notifications.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes\n */\n static observedAttributes = [\n 'auto-dismiss',\n 'auto-dismiss-timeout-ms',\n 'dismiss-button',\n 'light-theme',\n 'dark-theme',\n 'mode',\n ];\n\n constructor(props: {\n themeManager?: CourierToastThemeManager\n }) {\n super();\n\n this._themeManager = props?.themeManager ?? new CourierToastThemeManager(defaultLightTheme);\n this._themeSubscription = this._themeManager.subscribe((_: CourierToastTheme) => {\n this.refreshStyles();\n });\n this._datastoreListener = new CourierToastDatastoreListener({\n onMessageAdd: this.datastoreAddMessageListener.bind(this),\n onMessageRemove: this.datastoreRemoveMessageListener.bind(this),\n });\n }\n\n /** Set the handler invoked when a toast item is clicked. */\n public onToastItemClick(handler?: (props: CourierToastItemClickEvent) => void): void {\n this._onItemClick = handler;\n }\n\n /** Set the handler invoked when a toast item action button is clicked. */\n public onToastItemActionClick(handler?: (props: CourierToastItemActionClickEvent) => void): void {\n this._onItemActionClick = handler;\n }\n\n /** Enable auto-dismiss for toast items. */\n public enableAutoDismiss() {\n this._autoDismiss = true;\n }\n\n /** Disable auto-dismiss for toast items. */\n public disableAutoDismiss() {\n this._autoDismiss = false;\n }\n\n /**\n * Set the timeout before auto-dismissing toasts.\n * Only applicable if auto-dismiss is enabled.\n * @param timeoutMs - The timeout in milliseconds before a toast is dismissed.\n */\n public setAutoDismissTimeoutMs(timeoutMs: number) {\n this._autoDismissTimeoutMs = timeoutMs;\n }\n\n /**\n * Set the light theme for the toast.\n * @param theme - The light theme object to set.\n */\n public setLightTheme(theme: CourierToastTheme) {\n this._themeManager.setLightTheme(theme);\n }\n\n /**\n * Set the dark theme for the toast.\n * @param theme - The dark theme object to set.\n */\n public setDarkTheme(theme: CourierToastTheme) {\n this._themeManager.setDarkTheme(theme);\n }\n\n /**\n * Set the dismiss button display option.\n *\n * @param option - a value of {@link CourierToastDismissButtonOption}\n */\n public setDismissButton(option: CourierToastDismissButtonOption) {\n this._dismissButtonOption = option;\n this.refreshStyles();\n }\n\n /**\n * Set the theme mode.\n *\n * @param mode - The theme mode, one of \"dark\", \"light\", or \"system\".\n */\n public setMode(mode: CourierComponentThemeMode) {\n this._themeManager.setMode(mode);\n }\n\n /**\n * Set a factory function that renders a toast item.\n *\n * See {@link CourierToast.setToastItemContent} to set the content while preserving the toast item's\n * container and stack styling.\n */\n public setToastItem(factory?: (props: CourierToastItemFactoryProps) => HTMLElement) {\n this._customToastItem = factory;\n }\n\n /**\n * Set a factory function that renders a toast item's content.\n *\n * The toast item's container, including the stack, auto-dismiss timer, and dismiss button\n * and all events are still present when custom content is set.\n *\n * See {@link CourierToast.setDismissButton} to customize the dismiss button's visibility and\n * {@link CourierToast.setToastItem} to customize the entire toast item, including\n * its container.\n */\n public setToastItemContent(factory?: (props: CourierToastItemFactoryProps) => HTMLElement) {\n this._customToastItemContent = factory;\n }\n\n /**\n * Dismiss the toast item(s) associated with a particular {@link @trycourier/courier-js#InboxMessage}.\n *\n * Toast items are matched to messages by the field {@link @trycourier/courier-js#InboxMessage.messageId}.\n * If the item is an instance of {@link CourierToastItem} it will be animated out\n * before removal, otherwise custom items are removed immediately.\n *\n * If there are multiple toast items matching the message, all items will be dismissed.\n *\n * @example\n * Using dismissToastForMessage with setToastItem to dismiss a custom element.\n * ```ts\n * // Get a reference to the toast component\n * const toast = document.getElementById(\"my-toast\");\n *\n * toast.setToastItem((props) => {\n * const el = document.createElement(\"div\");\n * el.addEventListener(\"click\", () => toast.dismissToastForMessage(props.message));\n * return el;\n * });\n * ```\n *\n * @param message - the {@link @trycourier/courier-js#InboxMessage} for which toast items should be dismissed\n */\n private dismissToastForMessage(message: InboxMessage) {\n this.childNodes.forEach(node => {\n const nodeMessageId = (node as HTMLElement).dataset.courierMessageId;\n\n if (nodeMessageId !== message.messageId) {\n return;\n }\n\n if (node instanceof CourierToastItem) {\n node.dismiss();\n } else {\n this._customItemAutoDismissTimeouts.get(node as HTMLElement)?.cancel();\n node.remove();\n }\n });\n }\n\n /**\n * @override\n */\n protected onComponentMounted(): void {\n this._toastStyle = injectGlobalStyle(CourierToast.id, this.getStyles(this.theme));\n\n // Pause every countdown in the stack while the cursor is over the toast, so\n // a user reading it is never rushed. mouseenter/mouseleave (not\n // mouseover/mouseout) fire once for the container's whole subtree, so moving\n // between toast items and their children doesn't resume the countdown.\n this.addEventListener('mouseenter', this.onMouseEnter);\n this.addEventListener('mouseleave', this.onMouseLeave);\n\n CourierToastDatastore.shared.addDatastoreListener(this._datastoreListener);\n Courier.shared.addAuthenticationListener(this.authChangedCallback.bind(this));\n CourierToastDatastore.shared.listenForMessages();\n }\n\n /**\n * @override\n */\n protected onComponentUnmounted(): void {\n this.removeEventListener('mouseenter', this.onMouseEnter);\n this.removeEventListener('mouseleave', this.onMouseLeave);\n\n this._datastoreListener.remove();\n this._authListener?.remove();\n this._toastStyle?.remove();\n this._themeManager.cleanup();\n this._themeSubscription.unsubscribe();\n }\n\n private onMouseEnter = (): void => {\n this._isHovered = true;\n this.setAutoDismissPaused(true);\n };\n\n private onMouseLeave = (): void => {\n this._isHovered = false;\n this.setAutoDismissPaused(false);\n };\n\n /** Pause or resume the auto-dismiss countdown of every item in the stack. */\n private setAutoDismissPaused(paused: boolean): void {\n Array.from(this.children).forEach(child => this.setItemAutoDismissPaused(child as HTMLElement, paused));\n }\n\n /** Pause or resume a single item's auto-dismiss countdown. */\n private setItemAutoDismissPaused(item: HTMLElement, paused: boolean): void {\n if (item instanceof CourierToastItem) {\n paused ? item.pauseAutoDismiss() : item.resumeAutoDismiss();\n return;\n }\n\n const customItemTimeout = this._customItemAutoDismissTimeouts.get(item);\n paused ? customItemTimeout?.pause() : customItemTimeout?.resume();\n }\n\n /**\n * Lifecycle callback invoked when an observed attribute changes.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes\n */\n protected attributeChangedCallback(name: string, _: string, newValue: string) {\n switch (name) {\n case 'auto-dismiss':\n if (newValue === 'false') {\n this.disableAutoDismiss();\n } else {\n this.enableAutoDismiss();\n }\n break;\n case 'auto-dismiss-timeout-ms':\n this.setAutoDismissTimeoutMs(parseInt(newValue, /* base= */ 10));\n break;\n case 'dismiss-button':\n if (newValue && CourierToast.isDismissButtonOption(newValue)) {\n this.setDismissButton(newValue as CourierToastDismissButtonOption);\n } else {\n this.setDismissButton('auto');\n }\n break;\n case 'light-theme':\n if (newValue) {\n this.setLightTheme(JSON.parse(newValue));\n }\n break;\n case 'dark-theme':\n if (newValue) {\n this.setDarkTheme(JSON.parse(newValue));\n }\n break;\n case 'mode':\n this._themeManager.setMode(newValue as CourierComponentThemeMode);\n break;\n }\n }\n\n private get theme(): CourierToastTheme {\n return this._themeManager.getTheme();\n }\n\n /** Refresh the styles tag, if it exists, with the current theme. */\n private refreshStyles() {\n if (this._toastStyle) {\n this._toastStyle.textContent = this.getStyles(this.theme);\n }\n }\n\n private authChangedCallback() {\n this.removeAllItems();\n\n // If re-auth'ing logged the user out and closed the WebSocket connection,\n // we'll open a new connection. If one is already open, this is a no-op.\n CourierToastDatastore.shared.listenForMessages();\n }\n\n private removeAllItems(): void {\n while (this.firstChild) {\n this._customItemAutoDismissTimeouts.get(this.firstChild as HTMLElement)?.cancel();\n this.removeChild(this.firstChild);\n }\n }\n\n private addToastItem(message: InboxMessage): CourierToastItem | HTMLElement {\n // Append the toast item and resize the toast container\n // so previous toast items can stack underneath at fixed offsets\n // from the top item.\n const toastItem = this.createToastItem(message);\n toastItem.dataset.courierMessageId = message.messageId;\n this.appendChild(toastItem);\n this.resizeContainerToHeight(this.topStackItemHeight);\n\n // A toast that arrives while the cursor is already over the stack starts out\n // paused — it just landed under the cursor, so it hasn't been read yet.\n if (this._isHovered) {\n this.setItemAutoDismissPaused(toastItem, /* paused= */ true);\n }\n\n return toastItem;\n }\n\n private createToastItem(message: InboxMessage): CourierToastItem | HTMLElement {\n if (this._customToastItem) {\n return this.createCustomToastItem(message);\n }\n\n return this.createDefaultToastItem(message);\n }\n\n private createDefaultToastItem(message: InboxMessage) {\n const item = new CourierToastItem({\n message,\n autoDismiss: this._autoDismiss,\n autoDismissTimeoutMs: this._autoDismissTimeoutMs,\n themeManager: this._themeManager\n });\n\n item.onItemDismissed((_) => {\n this.resizeContainerToHeight(this.topStackItemHeight);\n });\n\n if (this._customToastItemContent) {\n item.setToastItemContent(this._customToastItemContent);\n }\n\n if (this._onItemClick) {\n item.onToastItemClick(this._onItemClick);\n }\n\n if (this._onItemActionClick) {\n item.onToastItemActionClick(this._onItemActionClick);\n }\n\n // The auto-dismiss countdown (and its hover-to-pause behavior) is owned by\n // the CourierToastItem itself, started when it mounts — see\n // CourierToastItem.onComponentMounted.\n\n return item;\n }\n\n private createCustomToastItem(message: InboxMessage) {\n if (!this._customToastItem) {\n throw Error(\"Attempted to create customToastItem, but none is set\");\n }\n\n const customItem = this._customToastItem({\n message,\n autoDismiss: this._autoDismiss,\n autoDismissTimeoutMs: this._autoDismissTimeoutMs,\n });\n\n if (this._autoDismiss) {\n // Custom items have no countdown of their own, so the container owns it —\n // including pausing it while the cursor is over the toast.\n const autoDismissTimeout = new PausableTimeout(() => customItem.remove(), this._autoDismissTimeoutMs);\n this._customItemAutoDismissTimeouts.set(customItem, autoDismissTimeout);\n autoDismissTimeout.start();\n }\n\n customItem.addEventListener('click', () => {\n if (this._onItemClick) {\n this._onItemClick({ message });\n }\n });\n\n return customItem;\n }\n\n private datastoreAddMessageListener(message: InboxMessage) {\n this.addToastItem(message);\n }\n\n private datastoreRemoveMessageListener(message: InboxMessage) {\n this.dismissToastForMessage(message);\n }\n\n private getStyles(theme: CourierToastTheme): string {\n const item = theme.item;\n\n // Styles for the top-level toast container.\n const toastStyles = `\n ${CourierToast.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\n // Stack the three most recently shown toast items and hide all others.\n // Content is transparent for all but the most recent (top) toast item\n // since it otherwise peeks out in the visible stack items.\n const toastStackStyles = `\n ${CourierToastItem.id}:last-child {\n top: 0;\n right: 0;\n }\n\n ${CourierToastItem.id}:nth-last-child(2) {\n top: 12px;\n bottom: -12px;\n --scale: 0.95\n }\n\n ${CourierToastItem.id}:nth-last-child(3) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n }\n\n ${CourierToastItem.id}:nth-last-child(n+4) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n visibility: hidden;\n }\n\n ${CourierToastItem.id}:nth-last-child(n+2) > .overflow-hidden-container {\n opacity: 0;\n }\n `;\n\n // Styles for the visible toast item.\n // `opacity` and `transform` are the initial states before\n // the keyframed `animation` show is applied.\n // The class `dismissing` is added to trigger the `animation` hide\n // before removing an item.\n // Only the top item is clickable.\n const toastItemStyles = `\n ${CourierToastItem.id} {\n position: absolute;\n box-sizing: border-box;\n width: 100%;\n background-color: ${item?.backgroundColor};\n box-shadow: ${item?.shadow};\n border: ${item?.border};\n border-radius: ${item?.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 ${CourierToastItem.id} > .overflow-hidden-container {\n height: 100%;\n width: 100%;\n border-radius: ${item?.borderRadius};\n overflow: hidden;\n }\n\n ${CourierToastItem.id}.dismissing {\n animation: courier-toast-hide 0.3s ease-in-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 @keyframes courier-toast-hide {\n 0% {\n opacity: 1;\n transform: scaleX(var(--scale, 1));\n }\n\n 100% {\n opacity: 0;\n transform: scaleX(var(--scale, 1));\n }\n }\n\n ${CourierToastItem.id}.clickable:last-child {\n cursor: pointer;\n }\n\n ${CourierToastItem.id}.clickable:last-child:hover {\n background-color: ${item?.hoverBackgroundColor};\n }\n\n ${CourierToastItem.id}.clickable:last-child:active {\n background-color: ${item?.activeBackgroundColor};\n }\n\n ${CourierToastItem.id}.clickable:nth-last-child(n+2) {\n pointer-events: none;\n }\n `;\n\n // A dismiss icon is visible when the top toast item is in the :hover state.\n // Auto-dismiss styles are added, but unused if the auto-dismiss progress\n // bar is not added in the courier-toast-item element\n // (i.e. when auto-dismiss is disabled).\n const dismissStyles = `\n ${CourierToastItem.id} > .dismiss {\n position: absolute;\n visibility: hidden;\n opacity: 0%;\n top: -10px;\n right: -10px;\n background-color: ${item?.backgroundColor};\n border: ${item?.border};\n padding: 3px;\n border-radius: 50%;\n font-size: 12pt;\n box-shadow: ${item?.shadow};\n cursor: pointer;\n transition: 0.2s ease-in-out;\n }\n\n ${CourierToastItem.id} > .dismiss:hover {\n background-color: ${item?.hoverBackgroundColor};\n }\n\n ${CourierToastItem.id} > .dismiss:active {\n background-color: ${item?.activeBackgroundColor};\n }\n\n ${CourierToastItem.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\n const autoDismissStyles = `\n ${CourierToastItem.id} > .overflow-hidden-container > .auto-dismiss {\n width: 100%;\n height: 5px;\n background-color: ${item?.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\n // Styles for the text and icon content.\n const contentStyles = `\n ${CourierToastItem.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 ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content {\n }\n\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .icon {\n }\n\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content > .title {\n margin: 0;\n font-weight: ${item?.title?.weight};\n font-size: ${item?.title?.size};\n color: ${item?.title?.color};\n }\n\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content > .body {\n margin: 8px 0 0 0;\n font-weight: ${item?.body?.weight};\n font-size: ${item?.body?.size};\n line-height: 150%;\n color: ${item?.body?.color};\n }\n `;\n\n const actionStyles = `\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content > .actions-container {\n display: flex;\n gap: 8px;\n margin-top: 12px;\n }\n `;\n\n return [\n toastStyles,\n toastStackStyles,\n toastItemStyles,\n dismissStyles,\n autoDismissStyles,\n contentStyles,\n actionStyles,\n ].join('');\n }\n\n /** Get the top item's (i.e. the fully visible item's) height. */\n private get topStackItemHeight(): string {\n if (this.lastChild) {\n const height = (this.lastChild as HTMLDivElement).getBoundingClientRect().height;\n return `${height}px`;\n }\n\n return '0px';\n }\n\n private resizeContainerToHeight(height: string) {\n this.style.height = height;\n }\n\n /** Whether the dismiss button should only be shown on hover. */\n private get showDismissOnHover(): boolean {\n // Auto-dismiss is enabled and button is using 'auto' behavior (show w/o auto-dismiss, show on hover w/ auto-dismiss).\n if (this._autoDismiss && this._dismissButtonOption === 'auto') {\n return true;\n }\n\n // Explicitly set to show on hover\n if (this._dismissButtonOption === 'hover') {\n return true;\n }\n\n return false;\n }\n\n /** Whether to show the dismiss button. The button is visible (either always or on hover) if not explicitly disabled. */\n private get showDismiss(): boolean {\n return this._dismissButtonOption !== 'hidden';\n }\n\n /** @override */\n static get id() {\n return 'courier-toast';\n }\n\n private static isDismissButtonOption(value: string): value is CourierToastDismissButtonOption {\n const validOptions: CourierToastDismissButtonOption[] = ['visible', 'hidden', 'hover', 'auto'];\n return validOptions.includes(value as CourierToastDismissButtonOption);\n }\n}\n\nregisterElement(CourierToast);\n","export * from './components/courier-toast';\r\nexport * from './components/courier-toast-item';\r\nexport * from './types/courier-toast-theme';\r\nexport * from './types/courier-toast-theme-manager';\r\nexport * from './types/toast';\r\nexport * from './datastore/toast-datastore';\r\nexport * from './datastore/toast-datastore-listener';\r\nexport * from './datastore/toast-datastore-events';\r\n\r\nimport { Courier } from \"@trycourier/courier-js\";\r\n\r\nCourier.shared.courierUserAgentName = \"courier-ui-toast\";\r\nCourier.shared.courierUserAgentVersion = __PACKAGE_VERSION__;\r\n\r\n// Re-export Courier from courier-js for direct import\r\nexport { Courier };\r\n\r\n// Re-export types from courier-js\r\nexport type {\n CourierProps,\n CourierClientOptions,\n CourierBrand,\n CourierApiRegion,\n CourierApiUrls,\n CourierUserPreferences,\r\n CourierUserPreferencesStatus,\r\n CourierUserPreferencesChannel,\r\n CourierUserPreferencesPaging,\r\n CourierUserPreferencesTopic,\r\n CourierUserPreferencesTopicResponse,\r\n CourierDevice,\r\n CourierToken,\r\n CourierGetInboxMessageResponse,\r\n CourierGetInboxMessagesResponse,\r\n InboxMessage,\r\n InboxAction,\r\n InboxMessageEventEnvelope,\n} from '@trycourier/courier-js';\n\nexport {\n DEFAULT_COURIER_API_URLS,\n EU_COURIER_API_URLS,\n getCourierApiUrls,\n getCourierApiUrlsForRegion\n} from '@trycourier/courier-js';\n\r\n// Re-export types from courier-ui-core\r\nexport type {\r\n CourierComponentThemeMode\r\n} from '@trycourier/courier-ui-core'\r\n","import { InboxMessage } from \"@trycourier/courier-js\";\n\n/**\n * The set of {@link CourierToastDatastore} events for which listeners can be added.\n *\n * @public\n */\nexport class CourierToastDatastoreEvents {\n public onMessageAdd?(_: InboxMessage): void { }\n public onMessageRemove?(_: InboxMessage): void { }\n public onError?(_: Error): void { }\n}\n"],"names":["defaultLightTheme","item","backgroundColor","CourierColors","white","hoverBackgroundColor","gray","activeBackgroundColor","shadow","black","border","borderRadius","title","size","weight","color","body","icon","svg","CourierIconSVGs","inbox","dismissIcon","remove","autoDismissBarColor","blue","actions","font","defaultDarkTheme","mergeTheme","mode","theme","defaultTheme","_a","_b","_c","_d","_e","_f","_g","_h","CourierToastThemeManager","CourierThemeManager","constructor","initialTheme","super","__publicField","this","getDefaultLightTheme","getDefaultDarkTheme","subscribe","callback","manager","PausableTimeout","delayMs","_callback","_remainingMs","isPaused","_isPaused","start","_isDone","clear","_startedAt","Date","now","_timerId","setTimeout","pause","Math","max","resume","cancel","clearTimeout","_CourierToastItem","CourierBaseElement","props","_message","message","_autoDismiss","autoDismiss","_autoDismissTimeoutMs","autoDismissTimeoutMs","_themeManager","themeManager","_themeSubscription","_","render","onItemDismissed","handler","_onItemDismissedCallback","onToastItemClick","_onToastItemClickCallback","onToastItemActionClick","_onToastItemActionClickCallback","setToastItemContent","factory","_customToastItemContent","dismiss","timeoutMs","dismissAnimationTimeoutMs","_autoDismissTimeout","classList","add","pauseAutoDismiss","syncAutoDismissBarPlayState","resumeAutoDismiss","_autoDismissBar","style","animationPlayState","onComponentMounted","onComponentUnmounted","unsubscribe","getTheme","id","observedAttributes","firstChild","removeChild","removeEventListener","onClick","overflowHiddenContainer","document","createElement","appendChild","append","createDefaultContent","addEventListener","CourierIcon","event","stopPropagation","content","textContent","preview","messageHasActions","actionsContainer","forEach","action","button","createActionButton","length","actionsTheme","CourierButton","text","variant","fontFamily","family","fontSize","fontWeight","textColor","CourierToastItem","registerElement","_CourierToastDatastore","shared","instance","addDatastoreListener","listener","_datastoreListeners","push","removeDatastoreListener","filter","l","listenForMessages","socketClient","Courier","client","socket","options","logger","info","_removeMessageEventListener","addMessageEventListener","messageEvent","InboxMessageEvent","NewMessage","data","addMessage","isConnecting","isOpen","connectionId","connect","error","events","onError","call","toastIndexOfMessage","position","_dataset","findIndex","m","messageId","onMessageAdd","removeMessage","index","splice","onMessageRemove","CourierToastDatastore","CourierToastDatastoreListener","_CourierToast","WeakMap","width","top","right","zIndex","_isHovered","setAutoDismissPaused","refreshStyles","_datastoreListener","datastoreAddMessageListener","bind","datastoreRemoveMessageListener","_onItemClick","_onItemActionClick","enableAutoDismiss","disableAutoDismiss","setAutoDismissTimeoutMs","setLightTheme","setDarkTheme","setDismissButton","option","_dismissButtonOption","setMode","setToastItem","_customToastItem","dismissToastForMessage","childNodes","node","dataset","courierMessageId","_customItemAutoDismissTimeouts","get","_toastStyle","injectGlobalStyle","getStyles","onMouseEnter","onMouseLeave","addAuthenticationListener","authChangedCallback","_authListener","cleanup","paused","Array","from","children","setItemAutoDismissPaused","child","customItemTimeout","attributeChangedCallback","name","newValue","parseInt","isDismissButtonOption","JSON","parse","removeAllItems","addToastItem","toastItem","createToastItem","resizeContainerToHeight","topStackItemHeight","createCustomToastItem","createDefaultToastItem","Error","customItem","autoDismissTimeout","set","_defaultLayoutProps","showDismissOnHover","showDismiss","join","lastChild","getBoundingClientRect","height","value","includes","CourierToast","courierUserAgentName","courierUserAgentVersion"],"mappings":"gjBAwCO,MAAMA,EAAuC,CAClDC,KAAM,CACJC,gBAAiBC,EAAAA,cAAcC,MAAM,KACrCC,qBAAsBF,EAAAA,cAAcG,KAAK,KACzCC,sBAAuBJ,EAAAA,cAAcG,KAAK,KAC1CE,OAAQ,oBAAoBL,EAAAA,cAAcM,MAAM,SAChDC,OAAQ,aAAaP,EAAAA,cAAcG,KAAK,OACxCK,aAAc,MACdC,MAAO,CACLC,KAAM,OACNC,OAAQ,MACRC,MAAOZ,EAAAA,cAAcM,MAAM,MAE7BO,KAAM,CACJH,KAAM,OACNC,OAAQ,MACRC,MAAOZ,EAAAA,cAAcG,KAAK,MAE5BW,KAAM,CACJF,MAAOZ,EAAAA,cAAcM,MAAM,KAC3BS,IAAKC,EAAAA,gBAAgBC,OAEvBC,YAAa,CACXN,MAAOZ,EAAAA,cAAcM,MAAM,KAC3BS,IAAKC,EAAAA,gBAAgBG,QAEvBC,oBAAqBpB,EAAAA,cAAcqB,KAAK,KACxCC,QAAS,CACPvB,gBAAiB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1C,OAAAgG,CAAShG,GAAkB"}
package/dist/index.mjs CHANGED
@@ -149,6 +149,67 @@ class CourierToastThemeManager extends CourierThemeManager {
149
149
  };
150
150
  }
151
151
  }
152
+ class PausableTimeout {
153
+ constructor(callback, delayMs) {
154
+ __publicField(this, "_callback");
155
+ /** Time left on the countdown, updated each time it's paused. */
156
+ __publicField(this, "_remainingMs");
157
+ __publicField(this, "_timerId", null);
158
+ /** When the currently-running countdown was (re)started. */
159
+ __publicField(this, "_startedAt", 0);
160
+ __publicField(this, "_isPaused", false);
161
+ /** Set once the callback has fired (or the countdown was cancelled). */
162
+ __publicField(this, "_isDone", false);
163
+ this._callback = callback;
164
+ this._remainingMs = delayMs;
165
+ }
166
+ /** Whether the countdown is currently paused. */
167
+ get isPaused() {
168
+ return this._isPaused;
169
+ }
170
+ /** Start the countdown for whatever time is left on it. */
171
+ start() {
172
+ if (this._isDone) {
173
+ return;
174
+ }
175
+ this.clear();
176
+ this._isPaused = false;
177
+ this._startedAt = Date.now();
178
+ this._timerId = setTimeout(() => {
179
+ this._timerId = null;
180
+ this._isDone = true;
181
+ this._callback();
182
+ }, this._remainingMs);
183
+ }
184
+ /** Pause the countdown, banking the time that has already elapsed. */
185
+ pause() {
186
+ if (this._isDone || this._isPaused || this._timerId === null) {
187
+ return;
188
+ }
189
+ this._remainingMs = Math.max(0, this._remainingMs - (Date.now() - this._startedAt));
190
+ this._isPaused = true;
191
+ this.clear();
192
+ }
193
+ /** Resume a paused countdown from where it left off. */
194
+ resume() {
195
+ if (this._isDone || !this._isPaused) {
196
+ return;
197
+ }
198
+ this.start();
199
+ }
200
+ /** Cancel the countdown for good; it can't be started again. */
201
+ cancel() {
202
+ this._isPaused = false;
203
+ this._isDone = true;
204
+ this.clear();
205
+ }
206
+ clear() {
207
+ if (this._timerId !== null) {
208
+ clearTimeout(this._timerId);
209
+ this._timerId = null;
210
+ }
211
+ }
212
+ }
152
213
  const _CourierToastItem = class _CourierToastItem extends CourierBaseElement {
153
214
  constructor(props) {
154
215
  super();
@@ -160,6 +221,14 @@ const _CourierToastItem = class _CourierToastItem extends CourierBaseElement {
160
221
  __publicField(this, "_autoDismiss");
161
222
  /** The timeout before the toast item is auto-dismissed, applicable if _autoDismiss is true. */
162
223
  __publicField(this, "_autoDismissTimeoutMs");
224
+ // Auto-dismiss countdown state. The countdown is paused while the cursor is
225
+ // over the toast and resumed (from where it left off) when the cursor leaves,
226
+ // so a user reading the toast is never rushed. Hover is tracked by the
227
+ // containing CourierToast, which pauses/resumes every item in the stack —
228
+ // see CourierToast.setAutoDismissPaused.
229
+ __publicField(this, "_autoDismissTimeout", null);
230
+ /** The progress bar element, paused/resumed alongside the countdown to stay in sync. */
231
+ __publicField(this, "_autoDismissBar", null);
163
232
  // Callbacks
164
233
  __publicField(this, "_onItemDismissedCallback", null);
165
234
  __publicField(this, "_onToastItemClickCallback", null);
@@ -216,6 +285,8 @@ const _CourierToastItem = class _CourierToastItem extends CourierBaseElement {
216
285
  * @param timeoutMs - the animation duration to fade out the toast item
217
286
  */
218
287
  dismiss(timeoutMs = _CourierToastItem.dismissAnimationTimeoutMs) {
288
+ var _a;
289
+ (_a = this._autoDismissTimeout) == null ? void 0 : _a.cancel();
219
290
  this.classList.add("dismissing");
220
291
  setTimeout(() => {
221
292
  this.remove();
@@ -224,13 +295,50 @@ const _CourierToastItem = class _CourierToastItem extends CourierBaseElement {
224
295
  }
225
296
  }, timeoutMs);
226
297
  }
298
+ /**
299
+ * Pause the auto-dismiss countdown, banking the time already elapsed and
300
+ * freezing the progress bar so the two stay in sync.
301
+ *
302
+ * Called by the containing {@link CourierToast} while the cursor is over the
303
+ * toast stack. No-op if this item doesn't auto-dismiss.
304
+ */
305
+ pauseAutoDismiss() {
306
+ var _a;
307
+ (_a = this._autoDismissTimeout) == null ? void 0 : _a.pause();
308
+ this.syncAutoDismissBarPlayState();
309
+ }
310
+ /**
311
+ * Resume a paused auto-dismiss countdown from where it left off.
312
+ *
313
+ * Called by the containing {@link CourierToast} once the cursor leaves the
314
+ * toast stack. No-op if this item doesn't auto-dismiss.
315
+ */
316
+ resumeAutoDismiss() {
317
+ var _a;
318
+ (_a = this._autoDismissTimeout) == null ? void 0 : _a.resume();
319
+ this.syncAutoDismissBarPlayState();
320
+ }
321
+ /** Freeze/unfreeze the progress bar to match the countdown. */
322
+ syncAutoDismissBarPlayState() {
323
+ var _a;
324
+ if (!this._autoDismissBar) {
325
+ return;
326
+ }
327
+ this._autoDismissBar.style.animationPlayState = ((_a = this._autoDismissTimeout) == null ? void 0 : _a.isPaused) ? "paused" : "running";
328
+ }
227
329
  /** @override */
228
330
  onComponentMounted() {
229
331
  this.render();
332
+ if (this._autoDismiss) {
333
+ this._autoDismissTimeout = new PausableTimeout(() => this.dismiss(), this._autoDismissTimeoutMs);
334
+ this._autoDismissTimeout.start();
335
+ }
230
336
  }
231
337
  /** @override */
232
338
  onComponentUnmounted() {
339
+ var _a;
233
340
  this._themeSubscription.unsubscribe();
341
+ (_a = this._autoDismissTimeout) == null ? void 0 : _a.cancel();
234
342
  }
235
343
  get theme() {
236
344
  return this._themeManager.getTheme();
@@ -256,7 +364,7 @@ const _CourierToastItem = class _CourierToastItem extends CourierBaseElement {
256
364
  * styles as {@link CourierToastItem}s enter/exit.
257
365
  */
258
366
  render() {
259
- var _a, _b, _c, _d;
367
+ var _a, _b, _c, _d, _e;
260
368
  while (this.firstChild) {
261
369
  this.removeChild(this.firstChild);
262
370
  }
@@ -267,7 +375,11 @@ const _CourierToastItem = class _CourierToastItem extends CourierBaseElement {
267
375
  if (this._autoDismiss) {
268
376
  const autoDismiss = document.createElement("div");
269
377
  autoDismiss.classList.add("auto-dismiss");
378
+ if ((_a = this._autoDismissTimeout) == null ? void 0 : _a.isPaused) {
379
+ autoDismiss.style.animationPlayState = "paused";
380
+ }
270
381
  overflowHiddenContainer.append(autoDismiss);
382
+ this._autoDismissBar = autoDismiss;
271
383
  }
272
384
  if (this._customToastItemContent) {
273
385
  overflowHiddenContainer.appendChild(this._customToastItemContent({ message: this._message, autoDismiss: this._autoDismiss, autoDismissTimeoutMs: this._autoDismissTimeoutMs }));
@@ -279,8 +391,8 @@ const _CourierToastItem = class _CourierToastItem extends CourierBaseElement {
279
391
  }
280
392
  this.addEventListener("click", this.onClick);
281
393
  const dismiss = new CourierIcon(
282
- (_b = (_a = this.theme.item) == null ? void 0 : _a.dismissIcon) == null ? void 0 : _b.color,
283
- (_d = (_c = this.theme.item) == null ? void 0 : _c.dismissIcon) == null ? void 0 : _d.svg
394
+ (_c = (_b = this.theme.item) == null ? void 0 : _b.dismissIcon) == null ? void 0 : _c.color,
395
+ (_e = (_d = this.theme.item) == null ? void 0 : _d.dismissIcon) == null ? void 0 : _e.svg
284
396
  );
285
397
  dismiss.classList.add("dismiss");
286
398
  dismiss.addEventListener("click", (event) => {
@@ -525,6 +637,20 @@ const _CourierToast = class _CourierToast extends CourierBaseElement {
525
637
  __publicField(this, "_toastStyle");
526
638
  __publicField(this, "_authListener");
527
639
  __publicField(this, "_datastoreListener");
640
+ /**
641
+ * Whether the cursor is currently over the toast stack.
642
+ *
643
+ * Hover is tracked here — on the container — rather than per item, because
644
+ * the stacked items are one hover surface: moving between them (or a new
645
+ * toast arriving under the cursor) must not resume anyone's countdown.
646
+ */
647
+ __publicField(this, "_isHovered", false);
648
+ /**
649
+ * Auto-dismiss countdowns for custom toast items set via
650
+ * {@link CourierToast.setToastItem}. {@link CourierToastItem}s own their own
651
+ * countdown, so they're not tracked here.
652
+ */
653
+ __publicField(this, "_customItemAutoDismissTimeouts", /* @__PURE__ */ new WeakMap());
528
654
  // Consumer-provided options
529
655
  __publicField(this, "_autoDismiss", false);
530
656
  __publicField(this, "_autoDismissTimeoutMs", 5e3);
@@ -542,6 +668,14 @@ const _CourierToast = class _CourierToast extends CourierBaseElement {
542
668
  right: "30px",
543
669
  zIndex: 999
544
670
  });
671
+ __publicField(this, "onMouseEnter", () => {
672
+ this._isHovered = true;
673
+ this.setAutoDismissPaused(true);
674
+ });
675
+ __publicField(this, "onMouseLeave", () => {
676
+ this._isHovered = false;
677
+ this.setAutoDismissPaused(false);
678
+ });
545
679
  this._themeManager = (props == null ? void 0 : props.themeManager) ?? new CourierToastThemeManager(defaultLightTheme);
546
680
  this._themeSubscription = this._themeManager.subscribe((_) => {
547
681
  this.refreshStyles();
@@ -654,6 +788,7 @@ const _CourierToast = class _CourierToast extends CourierBaseElement {
654
788
  */
655
789
  dismissToastForMessage(message) {
656
790
  this.childNodes.forEach((node) => {
791
+ var _a;
657
792
  const nodeMessageId = node.dataset.courierMessageId;
658
793
  if (nodeMessageId !== message.messageId) {
659
794
  return;
@@ -661,6 +796,7 @@ const _CourierToast = class _CourierToast extends CourierBaseElement {
661
796
  if (node instanceof CourierToastItem) {
662
797
  node.dismiss();
663
798
  } else {
799
+ (_a = this._customItemAutoDismissTimeouts.get(node)) == null ? void 0 : _a.cancel();
664
800
  node.remove();
665
801
  }
666
802
  });
@@ -670,6 +806,8 @@ const _CourierToast = class _CourierToast extends CourierBaseElement {
670
806
  */
671
807
  onComponentMounted() {
672
808
  this._toastStyle = injectGlobalStyle(_CourierToast.id, this.getStyles(this.theme));
809
+ this.addEventListener("mouseenter", this.onMouseEnter);
810
+ this.addEventListener("mouseleave", this.onMouseLeave);
673
811
  CourierToastDatastore.shared.addDatastoreListener(this._datastoreListener);
674
812
  Courier.shared.addAuthenticationListener(this.authChangedCallback.bind(this));
675
813
  CourierToastDatastore.shared.listenForMessages();
@@ -679,12 +817,27 @@ const _CourierToast = class _CourierToast extends CourierBaseElement {
679
817
  */
680
818
  onComponentUnmounted() {
681
819
  var _a, _b;
820
+ this.removeEventListener("mouseenter", this.onMouseEnter);
821
+ this.removeEventListener("mouseleave", this.onMouseLeave);
682
822
  this._datastoreListener.remove();
683
823
  (_a = this._authListener) == null ? void 0 : _a.remove();
684
824
  (_b = this._toastStyle) == null ? void 0 : _b.remove();
685
825
  this._themeManager.cleanup();
686
826
  this._themeSubscription.unsubscribe();
687
827
  }
828
+ /** Pause or resume the auto-dismiss countdown of every item in the stack. */
829
+ setAutoDismissPaused(paused) {
830
+ Array.from(this.children).forEach((child) => this.setItemAutoDismissPaused(child, paused));
831
+ }
832
+ /** Pause or resume a single item's auto-dismiss countdown. */
833
+ setItemAutoDismissPaused(item, paused) {
834
+ if (item instanceof CourierToastItem) {
835
+ paused ? item.pauseAutoDismiss() : item.resumeAutoDismiss();
836
+ return;
837
+ }
838
+ const customItemTimeout = this._customItemAutoDismissTimeouts.get(item);
839
+ paused ? customItemTimeout == null ? void 0 : customItemTimeout.pause() : customItemTimeout == null ? void 0 : customItemTimeout.resume();
840
+ }
688
841
  /**
689
842
  * Lifecycle callback invoked when an observed attribute changes.
690
843
  *
@@ -742,7 +895,9 @@ const _CourierToast = class _CourierToast extends CourierBaseElement {
742
895
  CourierToastDatastore.shared.listenForMessages();
743
896
  }
744
897
  removeAllItems() {
898
+ var _a;
745
899
  while (this.firstChild) {
900
+ (_a = this._customItemAutoDismissTimeouts.get(this.firstChild)) == null ? void 0 : _a.cancel();
746
901
  this.removeChild(this.firstChild);
747
902
  }
748
903
  }
@@ -751,6 +906,13 @@ const _CourierToast = class _CourierToast extends CourierBaseElement {
751
906
  toastItem.dataset.courierMessageId = message.messageId;
752
907
  this.appendChild(toastItem);
753
908
  this.resizeContainerToHeight(this.topStackItemHeight);
909
+ if (this._isHovered) {
910
+ this.setItemAutoDismissPaused(
911
+ toastItem,
912
+ /* paused= */
913
+ true
914
+ );
915
+ }
754
916
  return toastItem;
755
917
  }
756
918
  createToastItem(message) {
@@ -778,9 +940,6 @@ const _CourierToast = class _CourierToast extends CourierBaseElement {
778
940
  if (this._onItemActionClick) {
779
941
  item.onToastItemActionClick(this._onItemActionClick);
780
942
  }
781
- if (this._autoDismiss) {
782
- setTimeout(item.dismiss.bind(item), this._autoDismissTimeoutMs);
783
- }
784
943
  return item;
785
944
  }
786
945
  createCustomToastItem(message) {
@@ -793,9 +952,9 @@ const _CourierToast = class _CourierToast extends CourierBaseElement {
793
952
  autoDismissTimeoutMs: this._autoDismissTimeoutMs
794
953
  });
795
954
  if (this._autoDismiss) {
796
- setTimeout(() => {
797
- this.removeChild(customItem);
798
- }, this._autoDismissTimeoutMs);
955
+ const autoDismissTimeout = new PausableTimeout(() => customItem.remove(), this._autoDismissTimeoutMs);
956
+ this._customItemAutoDismissTimeouts.set(customItem, autoDismissTimeout);
957
+ autoDismissTimeout.start();
799
958
  }
800
959
  customItem.addEventListener("click", () => {
801
960
  if (this._onItemClick) {
@@ -1069,7 +1228,7 @@ class CourierToastDatastoreEvents {
1069
1228
  }
1070
1229
  }
1071
1230
  Courier.shared.courierUserAgentName = "courier-ui-toast";
1072
- Courier.shared.courierUserAgentVersion = "2.1.9";
1231
+ Courier.shared.courierUserAgentVersion = "2.1.11";
1073
1232
  export {
1074
1233
  Courier2 as Courier,
1075
1234
  CourierToast,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/types/courier-toast-theme.ts","../src/types/courier-toast-theme-manager.ts","../src/components/courier-toast-item.ts","../src/datastore/toast-datastore.ts","../src/datastore/toast-datastore-listener.ts","../src/components/courier-toast.ts","../src/datastore/toast-datastore-events.ts","../src/index.ts"],"sourcesContent":["import { CourierColors, CourierIconSVGs, SystemThemeMode, CourierFontTheme, CourierIconTheme } from \"@trycourier/courier-ui-core\";\r\n\r\n// Re-export common types from core for convenience\r\n\r\n/** @public */\r\nexport type CourierToastFontTheme = CourierFontTheme;\r\n\r\n/** @public */\r\nexport type CourierToastIconTheme = CourierIconTheme;\r\n\r\n/** @public */\r\nexport type CourierToastItemTheme = {\r\n backgroundColor?: string;\r\n hoverBackgroundColor?: string;\r\n activeBackgroundColor?: string;\r\n autoDismissBarColor?: string;\r\n title?: CourierToastFontTheme;\r\n body?: CourierToastFontTheme;\r\n icon?: CourierToastIconTheme;\r\n dismissIcon?: CourierToastIconTheme;\r\n shadow?: string;\r\n border?: string;\r\n borderRadius?: string;\r\n actions?: {\r\n backgroundColor?: string;\r\n hoverBackgroundColor?: string;\r\n activeBackgroundColor?: string;\r\n border?: string;\r\n borderRadius?: string;\r\n shadow?: string;\r\n font?: CourierToastFontTheme;\r\n }\r\n}\r\n\r\n/** @public */\r\nexport type CourierToastTheme = {\r\n item?: CourierToastItemTheme;\r\n};\r\n\r\n/** @public */\r\nexport const defaultLightTheme: CourierToastTheme = {\r\n item: {\r\n backgroundColor: CourierColors.white[500],\r\n hoverBackgroundColor: CourierColors.gray[200],\r\n activeBackgroundColor: CourierColors.gray[500],\r\n shadow: `0px 4px 8px -2px ${CourierColors.black[500_20]}`,\r\n border: `1px solid ${CourierColors.gray[500]}`,\r\n borderRadius: '8px',\r\n title: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.black[500],\r\n },\r\n body: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.gray[600],\r\n },\r\n icon: {\r\n color: CourierColors.black[500],\r\n svg: CourierIconSVGs.inbox,\r\n },\r\n dismissIcon: {\r\n color: CourierColors.black[500],\r\n svg: CourierIconSVGs.remove,\r\n },\r\n autoDismissBarColor: CourierColors.blue[400],\r\n actions: {\r\n backgroundColor: 'transparent',\r\n hoverBackgroundColor: CourierColors.gray[200],\r\n activeBackgroundColor: CourierColors.gray[500],\r\n border: `1px solid ${CourierColors.gray[500]}`,\r\n borderRadius: '4px',\r\n shadow: '0px 1px 2px 0px rgba(0, 0, 0, 0.06)',\r\n font: {\r\n color: CourierColors.black[500],\r\n size: '14px',\r\n }\r\n }\r\n }\r\n};\r\n\r\n/** @public */\r\nexport const defaultDarkTheme: CourierToastTheme = {\r\n item: {\r\n backgroundColor: CourierColors.black[500],\r\n hoverBackgroundColor: CourierColors.gray[800],\r\n activeBackgroundColor: CourierColors.gray[700],\r\n shadow: `0px 4px 8px -2px ${CourierColors.gray[400]}`,\r\n border: `1px solid ${CourierColors.gray[400]}`,\r\n borderRadius: '8px',\r\n title: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.white[500],\r\n },\r\n body: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.gray[500],\r\n },\r\n icon: {\r\n color: CourierColors.white[500],\r\n svg: CourierIconSVGs.inbox,\r\n },\r\n dismissIcon: {\r\n color: CourierColors.white[500],\r\n svg: CourierIconSVGs.remove,\r\n },\r\n autoDismissBarColor: CourierColors.blue[400],\r\n actions: {\r\n backgroundColor: CourierColors.black[400],\r\n hoverBackgroundColor: CourierColors.white[500_10],\r\n activeBackgroundColor: CourierColors.white[500_20],\r\n border: `1px solid ${CourierColors.gray[400]}`,\r\n borderRadius: '4px',\r\n shadow: `0px 1px 2px 0px ${CourierColors.white[500_10]}`,\r\n font: {\r\n color: CourierColors.white[500],\r\n size: '14px'\r\n }\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Deep merge themes, only overwriting non-optional properties.\r\n *\r\n * @public\r\n */\r\nexport const mergeTheme = (mode: SystemThemeMode, theme: CourierToastTheme): CourierToastTheme => {\r\n const defaultTheme = mode === 'light' ? defaultLightTheme : defaultDarkTheme;\r\n return {\r\n item: {\r\n ...defaultTheme.item,\r\n ...theme.item,\r\n title: {\r\n ...defaultTheme.item?.title,\r\n ...theme.item?.title\r\n },\r\n body: {\r\n ...defaultTheme.item?.body,\r\n ...theme.item?.body\r\n },\r\n icon: {\r\n ...defaultTheme.item?.icon,\r\n ...theme.item?.icon\r\n },\r\n dismissIcon: {\r\n ...defaultTheme.item?.dismissIcon,\r\n ...theme.item?.dismissIcon\r\n }\r\n }\r\n };\r\n};\r\n","import { CourierThemeManager, CourierThemeSubscription, SystemThemeMode } from \"@trycourier/courier-ui-core\";\r\nimport { CourierToastTheme, defaultDarkTheme, defaultLightTheme, mergeTheme } from \"./courier-toast-theme\";\r\n\r\n/**\r\n * @public\r\n */\r\nexport interface CourierToastThemeSubscription extends CourierThemeSubscription<CourierToastTheme> {\r\n manager: CourierToastThemeManager;\r\n}\r\n\r\n/**\r\n * Toast-specific theme manager that extends the abstract CourierThemeManager.\r\n * Provides toast theme management with light/dark mode support.\r\n *\r\n * @public\r\n */\r\nexport class CourierToastThemeManager extends CourierThemeManager<CourierToastTheme> {\r\n\r\n // Event ID for toast theme changes\r\n protected readonly THEME_CHANGE_EVENT: string = 'courier_toast_theme_change';\r\n\r\n constructor(initialTheme: CourierToastTheme) {\r\n super(initialTheme);\r\n }\r\n\r\n /**\r\n * Get the default light theme for toast\r\n */\r\n protected getDefaultLightTheme(): CourierToastTheme {\r\n return defaultLightTheme;\r\n }\r\n\r\n /**\r\n * Get the default dark theme for toast\r\n */\r\n protected getDefaultDarkTheme(): CourierToastTheme {\r\n return defaultDarkTheme;\r\n }\r\n\r\n /**\r\n * Merge the toast theme with defaults\r\n */\r\n protected mergeTheme(mode: SystemThemeMode, theme: CourierToastTheme): CourierToastTheme {\r\n return mergeTheme(mode, theme);\r\n }\r\n\r\n /**\r\n * Subscribe to toast theme changes\r\n * @param callback - Function to run when the theme changes\r\n * @returns Object with unsubscribe method to stop listening\r\n */\r\n public subscribe(callback: (theme: CourierToastTheme) => void): CourierToastThemeSubscription {\r\n const baseSubscription = super.subscribe(callback);\r\n return {\r\n ...baseSubscription,\r\n manager: this\r\n };\r\n }\r\n\r\n}\r\n","import { CourierBaseElement, CourierButton, CourierIcon, registerElement } from \"@trycourier/courier-ui-core\";\nimport { CourierToastThemeManager, CourierToastThemeSubscription } from \"../types/courier-toast-theme-manager\";\nimport { CourierToastTheme } from \"../types/courier-toast-theme\";\nimport { InboxAction, InboxMessage } from \"@trycourier/courier-js\";\nimport { CourierToastItemActionClickEvent, CourierToastItemClickEvent, CourierToastItemFactoryProps } from \"../types/toast\";\n\n/**\n * Default implementation of a Toast item.\n *\n * @see {@link CourierToast}\n * @public\n */\nexport class CourierToastItem extends CourierBaseElement {\n /** The animation duration to fade out a dismissed toast before its element is removed. */\n private static readonly dismissAnimationTimeoutMs = 300;\n\n private _themeManager: CourierToastThemeManager;\n private _themeSubscription: CourierToastThemeSubscription;\n private _message: InboxMessage;\n private _customToastItemContent?: (props: CourierToastItemFactoryProps) => HTMLElement;\n\n /** Whether this toast item is auto-dismissed. */\n private readonly _autoDismiss: boolean;\n\n /** The timeout before the toast item is auto-dismissed, applicable if _autoDismiss is true. */\n private readonly _autoDismissTimeoutMs: number;\n\n // Callbacks\n private _onItemDismissedCallback: ((props: { message: InboxMessage }) => void) | null = null;\n private _onToastItemClickCallback: ((props: CourierToastItemClickEvent) => void) | null = null;\n private _onToastItemActionClickCallback: ((props: CourierToastItemActionClickEvent) => void) | null = null;\n\n constructor(props: {\n message: InboxMessage,\n autoDismiss: boolean,\n autoDismissTimeoutMs: number,\n themeManager: CourierToastThemeManager,\n }) {\n\n super();\n this._message = props.message;\n this._autoDismiss = props.autoDismiss;\n this._autoDismissTimeoutMs = props.autoDismissTimeoutMs;\n\n this._themeManager = props.themeManager;\n this._themeSubscription = this._themeManager.subscribe((_: CourierToastTheme) => {\n this.render();\n });\n }\n\n /**\n * Registers a handler called when the item is dismissed.\n *\n * @param handler - A function to be called when the item is dismissed.\n */\n public onItemDismissed(handler: (props: { message: InboxMessage }) => void): void {\n this._onItemDismissedCallback = handler;\n }\n\n /**\n * Registers a handler for item click events.\n *\n * @param handler - A function to be called when the item is clicked.\n */\n public onToastItemClick(handler: (props: CourierToastItemClickEvent) => void): void {\n this._onToastItemClickCallback = handler;\n\n // Re-render to set/un-set the .clickable class\n this.render();\n }\n\n /**\n * Registers a handler for item click events.\n *\n * @param handler - A function to be called when the item is clicked.\n */\n public onToastItemActionClick(handler: (props: CourierToastItemActionClickEvent) => void): void {\n this._onToastItemActionClickCallback = handler;\n\n // Re-render to set/un-set the .clickable class\n this.render();\n }\n\n\n /**\n * Set a custom content element for the toast item, reusing the {@link CourierToastItem}\n * container, which provides styling, animations, and event handling.\n *\n * @param factory - Function that returns an `HTMLElement` to render as the content.\n */\n public setToastItemContent(factory?: (props: CourierToastItemFactoryProps) => HTMLElement) {\n this._customToastItemContent = factory;\n }\n\n /**\n * Dismiss the toast item.\n *\n * By default the toast fades out before it's removed. Set `timeoutMs` to\n * `0` to remove the item immediately.\n *\n * @param timeoutMs - the animation duration to fade out the toast item\n */\n public dismiss(timeoutMs: number = CourierToastItem.dismissAnimationTimeoutMs) {\n this.classList.add('dismissing');\n\n setTimeout(() => {\n this.remove();\n\n if (this._onItemDismissedCallback) {\n this._onItemDismissedCallback({ message: this._message });\n }\n }, timeoutMs);\n }\n\n /** @override */\n protected onComponentMounted(): void {\n this.render();\n }\n\n /** @override */\n protected onComponentUnmounted(): void {\n this._themeSubscription.unsubscribe();\n }\n\n get theme(): CourierToastTheme {\n return this._themeManager.getTheme();\n }\n\n /**\n * @override\n */\n static get id(): string {\n return 'courier-toast-item';\n }\n\n /**\n * @override\n */\n static get observedAttributes(): string[] {\n return [];\n }\n\n /**\n * Render a toast item, either with default content or custom content if\n * a content factory function is provided.\n *\n * Note: Styles for the toast item are set in {@link CourierToast} since\n * toasts are ephemeral by nature and we want to avoid adding/removing/duplicating\n * styles as {@link CourierToastItem}s enter/exit.\n */\n private render(): void {\n // Reset existing content and top-level listeners\n while (this.firstChild) {\n this.removeChild(this.firstChild);\n }\n this.removeEventListener('click', this.onClick);\n\n // Content and the auto-dismiss bar are wrapped in a container that hides overflow.\n // The standard dismiss button overflows the toast.\n const overflowHiddenContainer = document.createElement('div');\n overflowHiddenContainer.classList.add('overflow-hidden-container');\n this.appendChild(overflowHiddenContainer);\n\n // Auto-dismiss\n if (this._autoDismiss) {\n const autoDismiss = document.createElement('div');\n autoDismiss.classList.add('auto-dismiss');\n overflowHiddenContainer.append(autoDismiss);\n }\n\n // Content\n if (this._customToastItemContent) {\n overflowHiddenContainer.appendChild(this._customToastItemContent({ message: this._message, autoDismiss: this._autoDismiss, autoDismissTimeoutMs: this._autoDismissTimeoutMs }));\n } else {\n overflowHiddenContainer.appendChild(this.createDefaultContent());\n }\n\n // Click-ability\n if (this._onToastItemClickCallback) {\n this.classList.add('clickable');\n }\n\n this.addEventListener('click', this.onClick);\n\n // Dismiss button\n const dismiss = new CourierIcon(\n this.theme.item?.dismissIcon?.color,\n this.theme.item?.dismissIcon?.svg,\n );\n dismiss.classList.add('dismiss');\n dismiss.addEventListener('click', (event) => {\n event.stopPropagation();\n this.remove();\n\n if (this._onItemDismissedCallback) {\n this._onItemDismissedCallback({ message: this._message });\n }\n });\n this.appendChild(dismiss);\n }\n\n /** Create the default content for this item. */\n private createDefaultContent(): HTMLElement {\n const content = document.createElement('div');\n content.classList.add('content');\n this.append(content);\n\n const icon = new CourierIcon(\n this.theme.item?.icon?.color,\n this.theme.item?.icon?.svg,\n );\n icon.classList.add('icon');\n content.appendChild(icon);\n\n const textContent = document.createElement('div');\n textContent.classList.add('text-content');\n content.appendChild(textContent);\n\n const title = document.createElement('p');\n title.classList.add('title');\n title.textContent = this._message.title ?? '';\n textContent.appendChild(title);\n\n const body = document.createElement('p');\n body.classList.add('body');\n body.textContent = this._message.preview ?? this._message.body ?? '';\n textContent.appendChild(body);\n\n if (this.messageHasActions) {\n const actionsContainer = document.createElement('div');\n actionsContainer.classList.add('actions-container');\n textContent.appendChild(actionsContainer);\n\n this._message.actions?.forEach(action => {\n const button = this.createActionButton(action);\n actionsContainer.appendChild(button);\n });\n }\n\n return content;\n }\n\n private get messageHasActions() {\n return this._message.actions && this._message.actions.length > 0;\n }\n\n private createActionButton(action: InboxAction): CourierButton {\n const actionsTheme = this._themeManager.getTheme().item?.actions;\n\n return new CourierButton({\n mode: this._themeManager.mode,\n text: action.content,\n variant: 'secondary',\n backgroundColor: actionsTheme?.backgroundColor,\n hoverBackgroundColor: actionsTheme?.hoverBackgroundColor,\n activeBackgroundColor: actionsTheme?.activeBackgroundColor,\n border: actionsTheme?.border,\n borderRadius: actionsTheme?.borderRadius,\n shadow: actionsTheme?.shadow,\n fontFamily: actionsTheme?.font?.family,\n fontSize: actionsTheme?.font?.size,\n fontWeight: actionsTheme?.font?.weight,\n textColor: actionsTheme?.font?.color,\n onClick: () => {\n if (this._onToastItemActionClickCallback) {\n this._onToastItemActionClickCallback({ message: this._message, action });\n }\n }\n });\n\n\n }\n\n private onClick(event: Event) {\n event.stopPropagation();\n if (this._onToastItemClickCallback) {\n this._onToastItemClickCallback({ message: this._message });\n }\n }\n}\n\nregisterElement(CourierToastItem);\n","import { Courier, InboxMessage, InboxMessageEvent, InboxMessageEventEnvelope } from \"@trycourier/courier-js\";\nimport { CourierToastDatastoreListener } from \"./toast-datastore-listener\";\n\n/**\n * Shared datastore for Courier toasts.\n *\n * This datastore listens to and stores Courier Inbox messages.\n *\n * @public\n */\nexport class CourierToastDatastore {\n /** Shared instance. Access via {@link CourierToastDatastore.shared}. */\n private static instance: CourierToastDatastore;\n\n /** FIFO stack of toast messages. The end of the array is index 0 of the stack. */\n private _dataset: InboxMessage[] = [];\n\n /** Set of listeners whose handlers will be called when the datastore changes. */\n private _datastoreListeners: CourierToastDatastoreListener[] = [];\n\n /** Cleanup function to remove the message event listener. */\n private _removeMessageEventListener?: () => void;\n\n /** The shared instance of CourierToastDatastore, used to access all public methods. */\n public static get shared(): CourierToastDatastore {\n if (!CourierToastDatastore.instance) {\n CourierToastDatastore.instance = new CourierToastDatastore();\n }\n\n return CourierToastDatastore.instance;\n }\n\n /**\n * Add a listener whose handlers are called when there are changes to the datastore.\n *\n * @param listener - an implementation of {@link CourierToastDatastoreListener}\n */\n public addDatastoreListener(listener: CourierToastDatastoreListener) {\n this._datastoreListeners.push(listener);\n }\n\n /**\n * Remove a previously added listener.\n *\n * Note: the `listener` param is matched by object reference, so callers must pass\n * the same object previously passed to {@link CourierToastDatastore.addDatastoreListener}.\n *\n * See also: {@link CourierToastDatastoreListener.remove}\n *\n * @param listener - a previously added listener implementation\n */\n public removeDatastoreListener(listener: CourierToastDatastoreListener) {\n this._datastoreListeners = this._datastoreListeners.filter(l => l !== listener);\n }\n\n /**\n * Start listening for toast messages.\n *\n * Calling this method will open a WebSocket connection to the Courier backend if one\n * is not already open.\n *\n * See also: {@link @trycourier/courier-js#Courier.shared.signIn} and {@link @trycourier/courier-js#Courier.shared.signOut}\n */\n public async listenForMessages() {\n try {\n const socketClient = Courier.shared.client?.inbox.socket;\n\n if (!socketClient) {\n Courier.shared.client?.options.logger?.info('CourierInbox socket not available');\n return;\n }\n\n // Remove any existing listener before adding a new one\n // This prevents duplicates and handles socket changes\n if (this._removeMessageEventListener) {\n this._removeMessageEventListener();\n }\n\n // Register message event listener and store the cleanup function\n this._removeMessageEventListener = socketClient.addMessageEventListener((messageEvent: InboxMessageEventEnvelope) => {\n if (messageEvent.event === InboxMessageEvent.NewMessage) {\n const message: InboxMessage = messageEvent.data as InboxMessage;\n\n this.addMessage(message);\n }\n });\n\n // If the socket is already connecting or open, return early\n if (socketClient.isConnecting || socketClient.isOpen) {\n Courier.shared.client?.options.logger?.info(`Inbox socket already connecting or open for client ID: [${Courier.shared.client?.options.connectionId}]`);\n return;\n }\n\n await socketClient.connect();\n } catch (error: unknown) {\n Courier.shared.client?.options.logger.error('Error listening for messages:', error);\n this._datastoreListeners.forEach(listener => {\n listener.events.onError?.(error as Error);\n });\n }\n }\n\n /**\n * Find the position of an {@link @trycourier/courier-js#InboxMessage} in the toast stack.\n *\n * Notes:\n * - Since the stack is an array, with the last item being the \"top\" of the stack,\n * a toast's position in the underlying array is the inverse of its stack position.\n * - `message` is matched by {@link @trycourier/courier-js#InboxMessage.messageId}, not by object reference.\n *\n * @param message - the {@link @trycourier/courier-js#InboxMessage} to find in the stack\n */\n public toastIndexOfMessage(message: InboxMessage) {\n const position = this._dataset.findIndex(m => m.messageId === message.messageId);\n\n // Message not found\n if (position < 0) {\n return position;\n }\n\n // Return index from end of array (top of stack)\n return this._dataset.length - position - 1;\n }\n\n /**\n * Add an {@link @trycourier/courier-js#InboxMessage} toast item to the datastore.\n *\n * Calling this directly is useful to send test messages while developing with the Courier SDK.</p>\n *\n * @example\n * ```\n * CourierToastDatastore.shared.addMessage({\n * title: 'Lorem ipsum dolor sit',\n * body: 'Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet',\n * messageId: '1'\n * });\n * ```\n *\n * @param message - the message to add as a toast item.\n */\n public addMessage(message: InboxMessage) {\n this._dataset.push(message);\n\n this._datastoreListeners.forEach(listener => {\n if (listener.events.onMessageAdd) {\n listener.events.onMessageAdd(message);\n }\n });\n }\n\n /**\n * Remove an {@link @trycourier/courier-js#InboxMessage} from the datastore.\n *\n * Note: `message` is matched by {@link @trycourier/courier-js#InboxMessage.messageId}, not by object reference\n */\n public removeMessage(message: InboxMessage) {\n const index = this._dataset.findIndex(m => m.messageId === message.messageId);\n if (index < 0) {\n return;\n }\n\n this._dataset.splice(index, /* deleteCount */ 1);\n\n this._datastoreListeners.forEach(listener => {\n if (listener.events.onMessageRemove) {\n listener.events.onMessageRemove(message);\n }\n });\n }\n\n /** Access the shared instance with {@link CourierToastDatastore.shared}. */\n // Prevent instantiation via constructor.\n private constructor() {}\n}\n","import { CourierToastDatastore } from \"./toast-datastore\";\nimport { CourierToastDatastoreEvents } from \"./toast-datastore-events\";\n\n/**\n * Listener containing callbacks for {@link CourierToastDatastore} events.\n *\n * @public\n */\nexport class CourierToastDatastoreListener {\n constructor(readonly events: CourierToastDatastoreEvents) {}\n\n /** Remove this listener. Callbacks will no longer be invoked after remove is called. */\n remove() {\n CourierToastDatastore.shared.removeDatastoreListener(this);\n }\n}\n","import { CourierBaseElement, CourierComponentThemeMode, injectGlobalStyle, registerElement } from \"@trycourier/courier-ui-core\";\nimport { CourierToastThemeManager, CourierToastThemeSubscription } from \"../types/courier-toast-theme-manager\";\nimport { CourierToastTheme, defaultLightTheme } from \"../types/courier-toast-theme\";\nimport { AuthenticationListener, Courier, InboxMessage } from \"@trycourier/courier-js\";\nimport { CourierToastItem } from \"./courier-toast-item\";\nimport { CourierToastItemActionClickEvent, CourierToastItemClickEvent, CourierToastItemFactoryProps } from \"../types/toast\";\nimport { CourierToastDismissButtonOption } from \"../types/toast\";\nimport { CourierToastDatastoreListener } from \"../datastore/toast-datastore-listener\";\nimport { CourierToastDatastore } from \"../datastore/toast-datastore\";\n\n/** Default set of CSS properties used to layout CourierToast. */\ntype CourierToastLayoutProps = {\n position?: string;\n width?: string;\n top?: string;\n right?: string;\n zIndex?: number;\n}\n\n/**\n * An embeddable and customizable toast component, fed by data from Courier Inbox.\n *\n * @example\n *\n * Embedding the default toast component on a webpage.\n * ```\n * <html>\n * <body>\n * <courier-toast></courier-toast>\n *\n * <script type=\"module\">\n * import { Courier } from \"@trycourier/courier-ui-toast\";\n *\n * // Authenticate the user\n * Courier.shared.signIn({ userId, jwt });\n * </script>\n * </body>\n * </html>\n * ```\n *\n * @public\n */\nexport class CourierToast extends CourierBaseElement {\n\n // Internally-maintained state\n private _themeManager: CourierToastThemeManager;\n private _themeSubscription: CourierToastThemeSubscription;\n private _toastStyle?: HTMLStyleElement;\n private _authListener?: AuthenticationListener;\n private _datastoreListener: CourierToastDatastoreListener;\n\n // Consumer-provided options\n private _autoDismiss: boolean = false;\n private _autoDismissTimeoutMs: number = 5000;\n private _dismissButtonOption: CourierToastDismissButtonOption = 'auto';\n private _customToastItem?: (props: CourierToastItemFactoryProps) => HTMLElement;\n private _customToastItemContent?: (props: CourierToastItemFactoryProps) => HTMLElement;\n\n // Consumer-provided callbacks\n private _onItemClick?: ((props: CourierToastItemClickEvent) => void);\n private _onItemActionClick?: ((props: CourierToastItemActionClickEvent) => void);\n\n /** Default layout props. */\n private readonly _defaultLayoutProps: CourierToastLayoutProps = {\n position: 'fixed',\n width: '380px',\n top: '30px',\n right: '30px',\n zIndex: 999,\n };\n\n /**\n * The names of all attributes for which the web component needs change notifications.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes\n */\n static observedAttributes = [\n 'auto-dismiss',\n 'auto-dismiss-timeout-ms',\n 'dismiss-button',\n 'light-theme',\n 'dark-theme',\n 'mode',\n ];\n\n constructor(props: {\n themeManager?: CourierToastThemeManager\n }) {\n super();\n\n this._themeManager = props?.themeManager ?? new CourierToastThemeManager(defaultLightTheme);\n this._themeSubscription = this._themeManager.subscribe((_: CourierToastTheme) => {\n this.refreshStyles();\n });\n this._datastoreListener = new CourierToastDatastoreListener({\n onMessageAdd: this.datastoreAddMessageListener.bind(this),\n onMessageRemove: this.datastoreRemoveMessageListener.bind(this),\n });\n }\n\n /** Set the handler invoked when a toast item is clicked. */\n public onToastItemClick(handler?: (props: CourierToastItemClickEvent) => void): void {\n this._onItemClick = handler;\n }\n\n /** Set the handler invoked when a toast item action button is clicked. */\n public onToastItemActionClick(handler?: (props: CourierToastItemActionClickEvent) => void): void {\n this._onItemActionClick = handler;\n }\n\n /** Enable auto-dismiss for toast items. */\n public enableAutoDismiss() {\n this._autoDismiss = true;\n }\n\n /** Disable auto-dismiss for toast items. */\n public disableAutoDismiss() {\n this._autoDismiss = false;\n }\n\n /**\n * Set the timeout before auto-dismissing toasts.\n * Only applicable if auto-dismiss is enabled.\n * @param timeoutMs - The timeout in milliseconds before a toast is dismissed.\n */\n public setAutoDismissTimeoutMs(timeoutMs: number) {\n this._autoDismissTimeoutMs = timeoutMs;\n }\n\n /**\n * Set the light theme for the toast.\n * @param theme - The light theme object to set.\n */\n public setLightTheme(theme: CourierToastTheme) {\n this._themeManager.setLightTheme(theme);\n }\n\n /**\n * Set the dark theme for the toast.\n * @param theme - The dark theme object to set.\n */\n public setDarkTheme(theme: CourierToastTheme) {\n this._themeManager.setDarkTheme(theme);\n }\n\n /**\n * Set the dismiss button display option.\n *\n * @param option - a value of {@link CourierToastDismissButtonOption}\n */\n public setDismissButton(option: CourierToastDismissButtonOption) {\n this._dismissButtonOption = option;\n this.refreshStyles();\n }\n\n /**\n * Set the theme mode.\n *\n * @param mode - The theme mode, one of \"dark\", \"light\", or \"system\".\n */\n public setMode(mode: CourierComponentThemeMode) {\n this._themeManager.setMode(mode);\n }\n\n /**\n * Set a factory function that renders a toast item.\n *\n * See {@link CourierToast.setToastItemContent} to set the content while preserving the toast item's\n * container and stack styling.\n */\n public setToastItem(factory?: (props: CourierToastItemFactoryProps) => HTMLElement) {\n this._customToastItem = factory;\n }\n\n /**\n * Set a factory function that renders a toast item's content.\n *\n * The toast item's container, including the stack, auto-dismiss timer, and dismiss button\n * and all events are still present when custom content is set.\n *\n * See {@link CourierToast.setDismissButton} to customize the dismiss button's visibility and\n * {@link CourierToast.setToastItem} to customize the entire toast item, including\n * its container.\n */\n public setToastItemContent(factory?: (props: CourierToastItemFactoryProps) => HTMLElement) {\n this._customToastItemContent = factory;\n }\n\n /**\n * Dismiss the toast item(s) associated with a particular {@link @trycourier/courier-js#InboxMessage}.\n *\n * Toast items are matched to messages by the field {@link @trycourier/courier-js#InboxMessage.messageId}.\n * If the item is an instance of {@link CourierToastItem} it will be animated out\n * before removal, otherwise custom items are removed immediately.\n *\n * If there are multiple toast items matching the message, all items will be dismissed.\n *\n * @example\n * Using dismissToastForMessage with setToastItem to dismiss a custom element.\n * ```ts\n * // Get a reference to the toast component\n * const toast = document.getElementById(\"my-toast\");\n *\n * toast.setToastItem((props) => {\n * const el = document.createElement(\"div\");\n * el.addEventListener(\"click\", () => toast.dismissToastForMessage(props.message));\n * return el;\n * });\n * ```\n *\n * @param message - the {@link @trycourier/courier-js#InboxMessage} for which toast items should be dismissed\n */\n private dismissToastForMessage(message: InboxMessage) {\n this.childNodes.forEach(node => {\n const nodeMessageId = (node as HTMLElement).dataset.courierMessageId;\n\n if (nodeMessageId !== message.messageId) {\n return;\n }\n\n if (node instanceof CourierToastItem) {\n node.dismiss();\n } else {\n node.remove();\n }\n });\n }\n\n /**\n * @override\n */\n protected onComponentMounted(): void {\n this._toastStyle = injectGlobalStyle(CourierToast.id, this.getStyles(this.theme));\n\n CourierToastDatastore.shared.addDatastoreListener(this._datastoreListener);\n Courier.shared.addAuthenticationListener(this.authChangedCallback.bind(this));\n CourierToastDatastore.shared.listenForMessages();\n }\n\n /**\n * @override\n */\n protected onComponentUnmounted(): void {\n this._datastoreListener.remove();\n this._authListener?.remove();\n this._toastStyle?.remove();\n this._themeManager.cleanup();\n this._themeSubscription.unsubscribe();\n }\n\n /**\n * Lifecycle callback invoked when an observed attribute changes.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes\n */\n protected attributeChangedCallback(name: string, _: string, newValue: string) {\n switch (name) {\n case 'auto-dismiss':\n if (newValue === 'false') {\n this.disableAutoDismiss();\n } else {\n this.enableAutoDismiss();\n }\n break;\n case 'auto-dismiss-timeout-ms':\n this.setAutoDismissTimeoutMs(parseInt(newValue, /* base= */ 10));\n break;\n case 'dismiss-button':\n if (newValue && CourierToast.isDismissButtonOption(newValue)) {\n this.setDismissButton(newValue as CourierToastDismissButtonOption);\n } else {\n this.setDismissButton('auto');\n }\n break;\n case 'light-theme':\n if (newValue) {\n this.setLightTheme(JSON.parse(newValue));\n }\n break;\n case 'dark-theme':\n if (newValue) {\n this.setDarkTheme(JSON.parse(newValue));\n }\n break;\n case 'mode':\n this._themeManager.setMode(newValue as CourierComponentThemeMode);\n break;\n }\n }\n\n private get theme(): CourierToastTheme {\n return this._themeManager.getTheme();\n }\n\n /** Refresh the styles tag, if it exists, with the current theme. */\n private refreshStyles() {\n if (this._toastStyle) {\n this._toastStyle.textContent = this.getStyles(this.theme);\n }\n }\n\n private authChangedCallback() {\n this.removeAllItems();\n\n // If re-auth'ing logged the user out and closed the WebSocket connection,\n // we'll open a new connection. If one is already open, this is a no-op.\n CourierToastDatastore.shared.listenForMessages();\n }\n\n private removeAllItems(): void {\n while (this.firstChild) {\n this.removeChild(this.firstChild);\n }\n }\n\n private addToastItem(message: InboxMessage): CourierToastItem | HTMLElement {\n // Append the toast item and resize the toast container\n // so previous toast items can stack underneath at fixed offsets\n // from the top item.\n const toastItem = this.createToastItem(message);\n toastItem.dataset.courierMessageId = message.messageId;\n this.appendChild(toastItem);\n this.resizeContainerToHeight(this.topStackItemHeight);\n\n return toastItem;\n }\n\n private createToastItem(message: InboxMessage): CourierToastItem | HTMLElement {\n if (this._customToastItem) {\n return this.createCustomToastItem(message);\n }\n\n return this.createDefaultToastItem(message);\n }\n\n private createDefaultToastItem(message: InboxMessage) {\n const item = new CourierToastItem({\n message,\n autoDismiss: this._autoDismiss,\n autoDismissTimeoutMs: this._autoDismissTimeoutMs,\n themeManager: this._themeManager\n });\n\n item.onItemDismissed((_) => {\n this.resizeContainerToHeight(this.topStackItemHeight);\n });\n\n if (this._customToastItemContent) {\n item.setToastItemContent(this._customToastItemContent);\n }\n\n if (this._onItemClick) {\n item.onToastItemClick(this._onItemClick);\n }\n\n if (this._onItemActionClick) {\n item.onToastItemActionClick(this._onItemActionClick);\n }\n\n if (this._autoDismiss) {\n setTimeout(item.dismiss.bind(item), this._autoDismissTimeoutMs);\n }\n\n return item;\n }\n\n private createCustomToastItem(message: InboxMessage) {\n if (!this._customToastItem) {\n throw Error(\"Attempted to create customToastItem, but none is set\");\n }\n\n const customItem = this._customToastItem({\n message,\n autoDismiss: this._autoDismiss,\n autoDismissTimeoutMs: this._autoDismissTimeoutMs,\n });\n\n if (this._autoDismiss) {\n setTimeout(() => {\n this.removeChild(customItem);\n }, this._autoDismissTimeoutMs);\n }\n\n customItem.addEventListener('click', () => {\n if (this._onItemClick) {\n this._onItemClick({ message });\n }\n });\n\n return customItem;\n }\n\n private datastoreAddMessageListener(message: InboxMessage) {\n this.addToastItem(message);\n }\n\n private datastoreRemoveMessageListener(message: InboxMessage) {\n this.dismissToastForMessage(message);\n }\n\n private getStyles(theme: CourierToastTheme): string {\n const item = theme.item;\n\n // Styles for the top-level toast container.\n const toastStyles = `\n ${CourierToast.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\n // Stack the three most recently shown toast items and hide all others.\n // Content is transparent for all but the most recent (top) toast item\n // since it otherwise peeks out in the visible stack items.\n const toastStackStyles = `\n ${CourierToastItem.id}:last-child {\n top: 0;\n right: 0;\n }\n\n ${CourierToastItem.id}:nth-last-child(2) {\n top: 12px;\n bottom: -12px;\n --scale: 0.95\n }\n\n ${CourierToastItem.id}:nth-last-child(3) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n }\n\n ${CourierToastItem.id}:nth-last-child(n+4) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n visibility: hidden;\n }\n\n ${CourierToastItem.id}:nth-last-child(n+2) > .overflow-hidden-container {\n opacity: 0;\n }\n `;\n\n // Styles for the visible toast item.\n // `opacity` and `transform` are the initial states before\n // the keyframed `animation` show is applied.\n // The class `dismissing` is added to trigger the `animation` hide\n // before removing an item.\n // Only the top item is clickable.\n const toastItemStyles = `\n ${CourierToastItem.id} {\n position: absolute;\n box-sizing: border-box;\n width: 100%;\n background-color: ${item?.backgroundColor};\n box-shadow: ${item?.shadow};\n border: ${item?.border};\n border-radius: ${item?.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 ${CourierToastItem.id} > .overflow-hidden-container {\n height: 100%;\n width: 100%;\n border-radius: ${item?.borderRadius};\n overflow: hidden;\n }\n\n ${CourierToastItem.id}.dismissing {\n animation: courier-toast-hide 0.3s ease-in-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 @keyframes courier-toast-hide {\n 0% {\n opacity: 1;\n transform: scaleX(var(--scale, 1));\n }\n\n 100% {\n opacity: 0;\n transform: scaleX(var(--scale, 1));\n }\n }\n\n ${CourierToastItem.id}.clickable:last-child {\n cursor: pointer;\n }\n\n ${CourierToastItem.id}.clickable:last-child:hover {\n background-color: ${item?.hoverBackgroundColor};\n }\n\n ${CourierToastItem.id}.clickable:last-child:active {\n background-color: ${item?.activeBackgroundColor};\n }\n\n ${CourierToastItem.id}.clickable:nth-last-child(n+2) {\n pointer-events: none;\n }\n `;\n\n // A dismiss icon is visible when the top toast item is in the :hover state.\n // Auto-dismiss styles are added, but unused if the auto-dismiss progress\n // bar is not added in the courier-toast-item element\n // (i.e. when auto-dismiss is disabled).\n const dismissStyles = `\n ${CourierToastItem.id} > .dismiss {\n position: absolute;\n visibility: hidden;\n opacity: 0%;\n top: -10px;\n right: -10px;\n background-color: ${item?.backgroundColor};\n border: ${item?.border};\n padding: 3px;\n border-radius: 50%;\n font-size: 12pt;\n box-shadow: ${item?.shadow};\n cursor: pointer;\n transition: 0.2s ease-in-out;\n }\n\n ${CourierToastItem.id} > .dismiss:hover {\n background-color: ${item?.hoverBackgroundColor};\n }\n\n ${CourierToastItem.id} > .dismiss:active {\n background-color: ${item?.activeBackgroundColor};\n }\n\n ${CourierToastItem.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\n const autoDismissStyles = `\n ${CourierToastItem.id} > .overflow-hidden-container > .auto-dismiss {\n width: 100%;\n height: 5px;\n background-color: ${item?.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\n // Styles for the text and icon content.\n const contentStyles = `\n ${CourierToastItem.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 ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content {\n }\n\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .icon {\n }\n\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content > .title {\n margin: 0;\n font-weight: ${item?.title?.weight};\n font-size: ${item?.title?.size};\n color: ${item?.title?.color};\n }\n\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content > .body {\n margin: 8px 0 0 0;\n font-weight: ${item?.body?.weight};\n font-size: ${item?.body?.size};\n line-height: 150%;\n color: ${item?.body?.color};\n }\n `;\n\n const actionStyles = `\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content > .actions-container {\n display: flex;\n gap: 8px;\n margin-top: 12px;\n }\n `;\n\n return [\n toastStyles,\n toastStackStyles,\n toastItemStyles,\n dismissStyles,\n autoDismissStyles,\n contentStyles,\n actionStyles,\n ].join('');\n }\n\n /** Get the top item's (i.e. the fully visible item's) height. */\n private get topStackItemHeight(): string {\n if (this.lastChild) {\n const height = (this.lastChild as HTMLDivElement).getBoundingClientRect().height;\n return `${height}px`;\n }\n\n return '0px';\n }\n\n private resizeContainerToHeight(height: string) {\n this.style.height = height;\n }\n\n /** Whether the dismiss button should only be shown on hover. */\n private get showDismissOnHover(): boolean {\n // Auto-dismiss is enabled and button is using 'auto' behavior (show w/o auto-dismiss, show on hover w/ auto-dismiss).\n if (this._autoDismiss && this._dismissButtonOption === 'auto') {\n return true;\n }\n\n // Explicitly set to show on hover\n if (this._dismissButtonOption === 'hover') {\n return true;\n }\n\n return false;\n }\n\n /** Whether to show the dismiss button. The button is visible (either always or on hover) if not explicitly disabled. */\n private get showDismiss(): boolean {\n return this._dismissButtonOption !== 'hidden';\n }\n\n /** @override */\n static get id() {\n return 'courier-toast';\n }\n\n private static isDismissButtonOption(value: string): value is CourierToastDismissButtonOption {\n const validOptions: CourierToastDismissButtonOption[] = ['visible', 'hidden', 'hover', 'auto'];\n return validOptions.includes(value as CourierToastDismissButtonOption);\n }\n}\n\nregisterElement(CourierToast);\n","import { InboxMessage } from \"@trycourier/courier-js\";\n\n/**\n * The set of {@link CourierToastDatastore} events for which listeners can be added.\n *\n * @public\n */\nexport class CourierToastDatastoreEvents {\n public onMessageAdd?(_: InboxMessage): void { }\n public onMessageRemove?(_: InboxMessage): void { }\n public onError?(_: Error): void { }\n}\n","export * from './components/courier-toast';\r\nexport * from './components/courier-toast-item';\r\nexport * from './types/courier-toast-theme';\r\nexport * from './types/courier-toast-theme-manager';\r\nexport * from './types/toast';\r\nexport * from './datastore/toast-datastore';\r\nexport * from './datastore/toast-datastore-listener';\r\nexport * from './datastore/toast-datastore-events';\r\n\r\nimport { Courier } from \"@trycourier/courier-js\";\r\n\r\nCourier.shared.courierUserAgentName = \"courier-ui-toast\";\r\nCourier.shared.courierUserAgentVersion = __PACKAGE_VERSION__;\r\n\r\n// Re-export Courier from courier-js for direct import\r\nexport { Courier };\r\n\r\n// Re-export types from courier-js\r\nexport type {\n CourierProps,\n CourierClientOptions,\n CourierBrand,\n CourierApiRegion,\n CourierApiUrls,\n CourierUserPreferences,\r\n CourierUserPreferencesStatus,\r\n CourierUserPreferencesChannel,\r\n CourierUserPreferencesPaging,\r\n CourierUserPreferencesTopic,\r\n CourierUserPreferencesTopicResponse,\r\n CourierDevice,\r\n CourierToken,\r\n CourierGetInboxMessageResponse,\r\n CourierGetInboxMessagesResponse,\r\n InboxMessage,\r\n InboxAction,\r\n InboxMessageEventEnvelope,\n} from '@trycourier/courier-js';\n\nexport {\n DEFAULT_COURIER_API_URLS,\n EU_COURIER_API_URLS,\n getCourierApiUrls,\n getCourierApiUrlsForRegion\n} from '@trycourier/courier-js';\n\r\n// Re-export types from courier-ui-core\r\nexport type {\r\n CourierComponentThemeMode\r\n} from '@trycourier/courier-ui-core'\r\n"],"names":["_b","_a"],"mappings":";;;;;;AAwCO,MAAM,oBAAuC;AAAA,EAClD,MAAM;AAAA,IACJ,iBAAiB,cAAc,MAAM,GAAG;AAAA,IACxC,sBAAsB,cAAc,KAAK,GAAG;AAAA,IAC5C,uBAAuB,cAAc,KAAK,GAAG;AAAA,IAC7C,QAAQ,oBAAoB,cAAc,MAAM,KAAM,CAAC;AAAA,IACvD,QAAQ,aAAa,cAAc,KAAK,GAAG,CAAC;AAAA,IAC5C,cAAc;AAAA,IACd,OAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,OAAO,cAAc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A,EAChC,aAAc,GAAuB;AAAA,EAAE;AAAA,EACvC,gBAAiB,GAAuB;AAAA,EAAE;AAAA,EAC1C,QAAS,GAAgB;AAAA,EAAE;AACpC;ACAA,QAAQ,OAAO,uBAAuB;AACtC,QAAQ,OAAO,0BAA0B;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/types/courier-toast-theme.ts","../src/types/courier-toast-theme-manager.ts","../src/utils/pausable-timeout.ts","../src/components/courier-toast-item.ts","../src/datastore/toast-datastore.ts","../src/datastore/toast-datastore-listener.ts","../src/components/courier-toast.ts","../src/datastore/toast-datastore-events.ts","../src/index.ts"],"sourcesContent":["import { CourierColors, CourierIconSVGs, SystemThemeMode, CourierFontTheme, CourierIconTheme } from \"@trycourier/courier-ui-core\";\r\n\r\n// Re-export common types from core for convenience\r\n\r\n/** @public */\r\nexport type CourierToastFontTheme = CourierFontTheme;\r\n\r\n/** @public */\r\nexport type CourierToastIconTheme = CourierIconTheme;\r\n\r\n/** @public */\r\nexport type CourierToastItemTheme = {\r\n backgroundColor?: string;\r\n hoverBackgroundColor?: string;\r\n activeBackgroundColor?: string;\r\n autoDismissBarColor?: string;\r\n title?: CourierToastFontTheme;\r\n body?: CourierToastFontTheme;\r\n icon?: CourierToastIconTheme;\r\n dismissIcon?: CourierToastIconTheme;\r\n shadow?: string;\r\n border?: string;\r\n borderRadius?: string;\r\n actions?: {\r\n backgroundColor?: string;\r\n hoverBackgroundColor?: string;\r\n activeBackgroundColor?: string;\r\n border?: string;\r\n borderRadius?: string;\r\n shadow?: string;\r\n font?: CourierToastFontTheme;\r\n }\r\n}\r\n\r\n/** @public */\r\nexport type CourierToastTheme = {\r\n item?: CourierToastItemTheme;\r\n};\r\n\r\n/** @public */\r\nexport const defaultLightTheme: CourierToastTheme = {\r\n item: {\r\n backgroundColor: CourierColors.white[500],\r\n hoverBackgroundColor: CourierColors.gray[200],\r\n activeBackgroundColor: CourierColors.gray[500],\r\n shadow: `0px 4px 8px -2px ${CourierColors.black[500_20]}`,\r\n border: `1px solid ${CourierColors.gray[500]}`,\r\n borderRadius: '8px',\r\n title: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.black[500],\r\n },\r\n body: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.gray[600],\r\n },\r\n icon: {\r\n color: CourierColors.black[500],\r\n svg: CourierIconSVGs.inbox,\r\n },\r\n dismissIcon: {\r\n color: CourierColors.black[500],\r\n svg: CourierIconSVGs.remove,\r\n },\r\n autoDismissBarColor: CourierColors.blue[400],\r\n actions: {\r\n backgroundColor: 'transparent',\r\n hoverBackgroundColor: CourierColors.gray[200],\r\n activeBackgroundColor: CourierColors.gray[500],\r\n border: `1px solid ${CourierColors.gray[500]}`,\r\n borderRadius: '4px',\r\n shadow: '0px 1px 2px 0px rgba(0, 0, 0, 0.06)',\r\n font: {\r\n color: CourierColors.black[500],\r\n size: '14px',\r\n }\r\n }\r\n }\r\n};\r\n\r\n/** @public */\r\nexport const defaultDarkTheme: CourierToastTheme = {\r\n item: {\r\n backgroundColor: CourierColors.black[500],\r\n hoverBackgroundColor: CourierColors.gray[800],\r\n activeBackgroundColor: CourierColors.gray[700],\r\n shadow: `0px 4px 8px -2px ${CourierColors.gray[400]}`,\r\n border: `1px solid ${CourierColors.gray[400]}`,\r\n borderRadius: '8px',\r\n title: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.white[500],\r\n },\r\n body: {\r\n size: '11pt',\r\n weight: '400',\r\n color: CourierColors.gray[500],\r\n },\r\n icon: {\r\n color: CourierColors.white[500],\r\n svg: CourierIconSVGs.inbox,\r\n },\r\n dismissIcon: {\r\n color: CourierColors.white[500],\r\n svg: CourierIconSVGs.remove,\r\n },\r\n autoDismissBarColor: CourierColors.blue[400],\r\n actions: {\r\n backgroundColor: CourierColors.black[400],\r\n hoverBackgroundColor: CourierColors.white[500_10],\r\n activeBackgroundColor: CourierColors.white[500_20],\r\n border: `1px solid ${CourierColors.gray[400]}`,\r\n borderRadius: '4px',\r\n shadow: `0px 1px 2px 0px ${CourierColors.white[500_10]}`,\r\n font: {\r\n color: CourierColors.white[500],\r\n size: '14px'\r\n }\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Deep merge themes, only overwriting non-optional properties.\r\n *\r\n * @public\r\n */\r\nexport const mergeTheme = (mode: SystemThemeMode, theme: CourierToastTheme): CourierToastTheme => {\r\n const defaultTheme = mode === 'light' ? defaultLightTheme : defaultDarkTheme;\r\n return {\r\n item: {\r\n ...defaultTheme.item,\r\n ...theme.item,\r\n title: {\r\n ...defaultTheme.item?.title,\r\n ...theme.item?.title\r\n },\r\n body: {\r\n ...defaultTheme.item?.body,\r\n ...theme.item?.body\r\n },\r\n icon: {\r\n ...defaultTheme.item?.icon,\r\n ...theme.item?.icon\r\n },\r\n dismissIcon: {\r\n ...defaultTheme.item?.dismissIcon,\r\n ...theme.item?.dismissIcon\r\n }\r\n }\r\n };\r\n};\r\n","import { CourierThemeManager, CourierThemeSubscription, SystemThemeMode } from \"@trycourier/courier-ui-core\";\r\nimport { CourierToastTheme, defaultDarkTheme, defaultLightTheme, mergeTheme } from \"./courier-toast-theme\";\r\n\r\n/**\r\n * @public\r\n */\r\nexport interface CourierToastThemeSubscription extends CourierThemeSubscription<CourierToastTheme> {\r\n manager: CourierToastThemeManager;\r\n}\r\n\r\n/**\r\n * Toast-specific theme manager that extends the abstract CourierThemeManager.\r\n * Provides toast theme management with light/dark mode support.\r\n *\r\n * @public\r\n */\r\nexport class CourierToastThemeManager extends CourierThemeManager<CourierToastTheme> {\r\n\r\n // Event ID for toast theme changes\r\n protected readonly THEME_CHANGE_EVENT: string = 'courier_toast_theme_change';\r\n\r\n constructor(initialTheme: CourierToastTheme) {\r\n super(initialTheme);\r\n }\r\n\r\n /**\r\n * Get the default light theme for toast\r\n */\r\n protected getDefaultLightTheme(): CourierToastTheme {\r\n return defaultLightTheme;\r\n }\r\n\r\n /**\r\n * Get the default dark theme for toast\r\n */\r\n protected getDefaultDarkTheme(): CourierToastTheme {\r\n return defaultDarkTheme;\r\n }\r\n\r\n /**\r\n * Merge the toast theme with defaults\r\n */\r\n protected mergeTheme(mode: SystemThemeMode, theme: CourierToastTheme): CourierToastTheme {\r\n return mergeTheme(mode, theme);\r\n }\r\n\r\n /**\r\n * Subscribe to toast theme changes\r\n * @param callback - Function to run when the theme changes\r\n * @returns Object with unsubscribe method to stop listening\r\n */\r\n public subscribe(callback: (theme: CourierToastTheme) => void): CourierToastThemeSubscription {\r\n const baseSubscription = super.subscribe(callback);\r\n return {\r\n ...baseSubscription,\r\n manager: this\r\n };\r\n }\r\n\r\n}\r\n","/**\n * A `setTimeout` that can be paused and resumed.\n *\n * Pausing banks the time that has already elapsed, so resuming fires the\n * callback after the *remaining* time rather than restarting the full delay.\n *\n * Used for the toast auto-dismiss countdown, which pauses while the cursor is\n * over the toast.\n */\nexport class PausableTimeout {\n private readonly _callback: () => void;\n\n /** Time left on the countdown, updated each time it's paused. */\n private _remainingMs: number;\n\n private _timerId: ReturnType<typeof setTimeout> | null = null;\n\n /** When the currently-running countdown was (re)started. */\n private _startedAt = 0;\n\n private _isPaused = false;\n\n /** Set once the callback has fired (or the countdown was cancelled). */\n private _isDone = false;\n\n constructor(callback: () => void, delayMs: number) {\n this._callback = callback;\n this._remainingMs = delayMs;\n }\n\n /** Whether the countdown is currently paused. */\n public get isPaused(): boolean {\n return this._isPaused;\n }\n\n /** Start the countdown for whatever time is left on it. */\n public start(): void {\n if (this._isDone) {\n return;\n }\n\n this.clear();\n this._isPaused = false;\n this._startedAt = Date.now();\n this._timerId = setTimeout(() => {\n this._timerId = null;\n this._isDone = true;\n this._callback();\n }, this._remainingMs);\n }\n\n /** Pause the countdown, banking the time that has already elapsed. */\n public pause(): void {\n if (this._isDone || this._isPaused || this._timerId === null) {\n return;\n }\n\n this._remainingMs = Math.max(0, this._remainingMs - (Date.now() - this._startedAt));\n this._isPaused = true;\n this.clear();\n }\n\n /** Resume a paused countdown from where it left off. */\n public resume(): void {\n if (this._isDone || !this._isPaused) {\n return;\n }\n\n this.start();\n }\n\n /** Cancel the countdown for good; it can't be started again. */\n public cancel(): void {\n this._isPaused = false;\n this._isDone = true;\n this.clear();\n }\n\n private clear(): void {\n if (this._timerId !== null) {\n clearTimeout(this._timerId);\n this._timerId = null;\n }\n }\n}\n","import { CourierBaseElement, CourierButton, CourierIcon, registerElement } from \"@trycourier/courier-ui-core\";\nimport { CourierToastThemeManager, CourierToastThemeSubscription } from \"../types/courier-toast-theme-manager\";\nimport { CourierToastTheme } from \"../types/courier-toast-theme\";\nimport { InboxAction, InboxMessage } from \"@trycourier/courier-js\";\nimport { CourierToastItemActionClickEvent, CourierToastItemClickEvent, CourierToastItemFactoryProps } from \"../types/toast\";\nimport { PausableTimeout } from \"../utils/pausable-timeout\";\n\n/**\n * Default implementation of a Toast item.\n *\n * @see {@link CourierToast}\n * @public\n */\nexport class CourierToastItem extends CourierBaseElement {\n /** The animation duration to fade out a dismissed toast before its element is removed. */\n private static readonly dismissAnimationTimeoutMs = 300;\n\n private _themeManager: CourierToastThemeManager;\n private _themeSubscription: CourierToastThemeSubscription;\n private _message: InboxMessage;\n private _customToastItemContent?: (props: CourierToastItemFactoryProps) => HTMLElement;\n\n /** Whether this toast item is auto-dismissed. */\n private readonly _autoDismiss: boolean;\n\n /** The timeout before the toast item is auto-dismissed, applicable if _autoDismiss is true. */\n private readonly _autoDismissTimeoutMs: number;\n\n // Auto-dismiss countdown state. The countdown is paused while the cursor is\n // over the toast and resumed (from where it left off) when the cursor leaves,\n // so a user reading the toast is never rushed. Hover is tracked by the\n // containing CourierToast, which pauses/resumes every item in the stack —\n // see CourierToast.setAutoDismissPaused.\n private _autoDismissTimeout: PausableTimeout | null = null;\n\n /** The progress bar element, paused/resumed alongside the countdown to stay in sync. */\n private _autoDismissBar: HTMLElement | null = null;\n\n // Callbacks\n private _onItemDismissedCallback: ((props: { message: InboxMessage }) => void) | null = null;\n private _onToastItemClickCallback: ((props: CourierToastItemClickEvent) => void) | null = null;\n private _onToastItemActionClickCallback: ((props: CourierToastItemActionClickEvent) => void) | null = null;\n\n constructor(props: {\n message: InboxMessage,\n autoDismiss: boolean,\n autoDismissTimeoutMs: number,\n themeManager: CourierToastThemeManager,\n }) {\n\n super();\n this._message = props.message;\n this._autoDismiss = props.autoDismiss;\n this._autoDismissTimeoutMs = props.autoDismissTimeoutMs;\n\n this._themeManager = props.themeManager;\n this._themeSubscription = this._themeManager.subscribe((_: CourierToastTheme) => {\n this.render();\n });\n }\n\n /**\n * Registers a handler called when the item is dismissed.\n *\n * @param handler - A function to be called when the item is dismissed.\n */\n public onItemDismissed(handler: (props: { message: InboxMessage }) => void): void {\n this._onItemDismissedCallback = handler;\n }\n\n /**\n * Registers a handler for item click events.\n *\n * @param handler - A function to be called when the item is clicked.\n */\n public onToastItemClick(handler: (props: CourierToastItemClickEvent) => void): void {\n this._onToastItemClickCallback = handler;\n\n // Re-render to set/un-set the .clickable class\n this.render();\n }\n\n /**\n * Registers a handler for item click events.\n *\n * @param handler - A function to be called when the item is clicked.\n */\n public onToastItemActionClick(handler: (props: CourierToastItemActionClickEvent) => void): void {\n this._onToastItemActionClickCallback = handler;\n\n // Re-render to set/un-set the .clickable class\n this.render();\n }\n\n\n /**\n * Set a custom content element for the toast item, reusing the {@link CourierToastItem}\n * container, which provides styling, animations, and event handling.\n *\n * @param factory - Function that returns an `HTMLElement` to render as the content.\n */\n public setToastItemContent(factory?: (props: CourierToastItemFactoryProps) => HTMLElement) {\n this._customToastItemContent = factory;\n }\n\n /**\n * Dismiss the toast item.\n *\n * By default the toast fades out before it's removed. Set `timeoutMs` to\n * `0` to remove the item immediately.\n *\n * @param timeoutMs - the animation duration to fade out the toast item\n */\n public dismiss(timeoutMs: number = CourierToastItem.dismissAnimationTimeoutMs) {\n // Stop the countdown so it can't fire again after we've started dismissing.\n this._autoDismissTimeout?.cancel();\n this.classList.add('dismissing');\n\n setTimeout(() => {\n this.remove();\n\n if (this._onItemDismissedCallback) {\n this._onItemDismissedCallback({ message: this._message });\n }\n }, timeoutMs);\n }\n\n /**\n * Pause the auto-dismiss countdown, banking the time already elapsed and\n * freezing the progress bar so the two stay in sync.\n *\n * Called by the containing {@link CourierToast} while the cursor is over the\n * toast stack. No-op if this item doesn't auto-dismiss.\n */\n public pauseAutoDismiss(): void {\n this._autoDismissTimeout?.pause();\n this.syncAutoDismissBarPlayState();\n }\n\n /**\n * Resume a paused auto-dismiss countdown from where it left off.\n *\n * Called by the containing {@link CourierToast} once the cursor leaves the\n * toast stack. No-op if this item doesn't auto-dismiss.\n */\n public resumeAutoDismiss(): void {\n this._autoDismissTimeout?.resume();\n this.syncAutoDismissBarPlayState();\n }\n\n /** Freeze/unfreeze the progress bar to match the countdown. */\n private syncAutoDismissBarPlayState(): void {\n if (!this._autoDismissBar) {\n return;\n }\n\n this._autoDismissBar.style.animationPlayState = this._autoDismissTimeout?.isPaused ? 'paused' : 'running';\n }\n\n /** @override */\n protected onComponentMounted(): void {\n this.render();\n\n if (this._autoDismiss) {\n this._autoDismissTimeout = new PausableTimeout(() => this.dismiss(), this._autoDismissTimeoutMs);\n this._autoDismissTimeout.start();\n }\n }\n\n /** @override */\n protected onComponentUnmounted(): void {\n this._themeSubscription.unsubscribe();\n this._autoDismissTimeout?.cancel();\n }\n\n get theme(): CourierToastTheme {\n return this._themeManager.getTheme();\n }\n\n /**\n * @override\n */\n static get id(): string {\n return 'courier-toast-item';\n }\n\n /**\n * @override\n */\n static get observedAttributes(): string[] {\n return [];\n }\n\n /**\n * Render a toast item, either with default content or custom content if\n * a content factory function is provided.\n *\n * Note: Styles for the toast item are set in {@link CourierToast} since\n * toasts are ephemeral by nature and we want to avoid adding/removing/duplicating\n * styles as {@link CourierToastItem}s enter/exit.\n */\n private render(): void {\n // Reset existing content and top-level listeners\n while (this.firstChild) {\n this.removeChild(this.firstChild);\n }\n this.removeEventListener('click', this.onClick);\n\n // Content and the auto-dismiss bar are wrapped in a container that hides overflow.\n // The standard dismiss button overflows the toast.\n const overflowHiddenContainer = document.createElement('div');\n overflowHiddenContainer.classList.add('overflow-hidden-container');\n this.appendChild(overflowHiddenContainer);\n\n // Auto-dismiss\n if (this._autoDismiss) {\n const autoDismiss = document.createElement('div');\n autoDismiss.classList.add('auto-dismiss');\n // Keep the bar frozen if we re-render (e.g. theme change) while paused.\n if (this._autoDismissTimeout?.isPaused) {\n autoDismiss.style.animationPlayState = 'paused';\n }\n overflowHiddenContainer.append(autoDismiss);\n this._autoDismissBar = autoDismiss;\n }\n\n // Content\n if (this._customToastItemContent) {\n overflowHiddenContainer.appendChild(this._customToastItemContent({ message: this._message, autoDismiss: this._autoDismiss, autoDismissTimeoutMs: this._autoDismissTimeoutMs }));\n } else {\n overflowHiddenContainer.appendChild(this.createDefaultContent());\n }\n\n // Click-ability\n if (this._onToastItemClickCallback) {\n this.classList.add('clickable');\n }\n\n this.addEventListener('click', this.onClick);\n\n // Dismiss button\n const dismiss = new CourierIcon(\n this.theme.item?.dismissIcon?.color,\n this.theme.item?.dismissIcon?.svg,\n );\n dismiss.classList.add('dismiss');\n dismiss.addEventListener('click', (event) => {\n event.stopPropagation();\n this.remove();\n\n if (this._onItemDismissedCallback) {\n this._onItemDismissedCallback({ message: this._message });\n }\n });\n this.appendChild(dismiss);\n }\n\n /** Create the default content for this item. */\n private createDefaultContent(): HTMLElement {\n const content = document.createElement('div');\n content.classList.add('content');\n this.append(content);\n\n const icon = new CourierIcon(\n this.theme.item?.icon?.color,\n this.theme.item?.icon?.svg,\n );\n icon.classList.add('icon');\n content.appendChild(icon);\n\n const textContent = document.createElement('div');\n textContent.classList.add('text-content');\n content.appendChild(textContent);\n\n const title = document.createElement('p');\n title.classList.add('title');\n title.textContent = this._message.title ?? '';\n textContent.appendChild(title);\n\n const body = document.createElement('p');\n body.classList.add('body');\n body.textContent = this._message.preview ?? this._message.body ?? '';\n textContent.appendChild(body);\n\n if (this.messageHasActions) {\n const actionsContainer = document.createElement('div');\n actionsContainer.classList.add('actions-container');\n textContent.appendChild(actionsContainer);\n\n this._message.actions?.forEach(action => {\n const button = this.createActionButton(action);\n actionsContainer.appendChild(button);\n });\n }\n\n return content;\n }\n\n private get messageHasActions() {\n return this._message.actions && this._message.actions.length > 0;\n }\n\n private createActionButton(action: InboxAction): CourierButton {\n const actionsTheme = this._themeManager.getTheme().item?.actions;\n\n return new CourierButton({\n mode: this._themeManager.mode,\n text: action.content,\n variant: 'secondary',\n backgroundColor: actionsTheme?.backgroundColor,\n hoverBackgroundColor: actionsTheme?.hoverBackgroundColor,\n activeBackgroundColor: actionsTheme?.activeBackgroundColor,\n border: actionsTheme?.border,\n borderRadius: actionsTheme?.borderRadius,\n shadow: actionsTheme?.shadow,\n fontFamily: actionsTheme?.font?.family,\n fontSize: actionsTheme?.font?.size,\n fontWeight: actionsTheme?.font?.weight,\n textColor: actionsTheme?.font?.color,\n onClick: () => {\n if (this._onToastItemActionClickCallback) {\n this._onToastItemActionClickCallback({ message: this._message, action });\n }\n }\n });\n\n\n }\n\n private onClick(event: Event) {\n event.stopPropagation();\n if (this._onToastItemClickCallback) {\n this._onToastItemClickCallback({ message: this._message });\n }\n }\n}\n\nregisterElement(CourierToastItem);\n","import { Courier, InboxMessage, InboxMessageEvent, InboxMessageEventEnvelope } from \"@trycourier/courier-js\";\nimport { CourierToastDatastoreListener } from \"./toast-datastore-listener\";\n\n/**\n * Shared datastore for Courier toasts.\n *\n * This datastore listens to and stores Courier Inbox messages.\n *\n * @public\n */\nexport class CourierToastDatastore {\n /** Shared instance. Access via {@link CourierToastDatastore.shared}. */\n private static instance: CourierToastDatastore;\n\n /** FIFO stack of toast messages. The end of the array is index 0 of the stack. */\n private _dataset: InboxMessage[] = [];\n\n /** Set of listeners whose handlers will be called when the datastore changes. */\n private _datastoreListeners: CourierToastDatastoreListener[] = [];\n\n /** Cleanup function to remove the message event listener. */\n private _removeMessageEventListener?: () => void;\n\n /** The shared instance of CourierToastDatastore, used to access all public methods. */\n public static get shared(): CourierToastDatastore {\n if (!CourierToastDatastore.instance) {\n CourierToastDatastore.instance = new CourierToastDatastore();\n }\n\n return CourierToastDatastore.instance;\n }\n\n /**\n * Add a listener whose handlers are called when there are changes to the datastore.\n *\n * @param listener - an implementation of {@link CourierToastDatastoreListener}\n */\n public addDatastoreListener(listener: CourierToastDatastoreListener) {\n this._datastoreListeners.push(listener);\n }\n\n /**\n * Remove a previously added listener.\n *\n * Note: the `listener` param is matched by object reference, so callers must pass\n * the same object previously passed to {@link CourierToastDatastore.addDatastoreListener}.\n *\n * See also: {@link CourierToastDatastoreListener.remove}\n *\n * @param listener - a previously added listener implementation\n */\n public removeDatastoreListener(listener: CourierToastDatastoreListener) {\n this._datastoreListeners = this._datastoreListeners.filter(l => l !== listener);\n }\n\n /**\n * Start listening for toast messages.\n *\n * Calling this method will open a WebSocket connection to the Courier backend if one\n * is not already open.\n *\n * See also: {@link @trycourier/courier-js#Courier.shared.signIn} and {@link @trycourier/courier-js#Courier.shared.signOut}\n */\n public async listenForMessages() {\n try {\n const socketClient = Courier.shared.client?.inbox.socket;\n\n if (!socketClient) {\n Courier.shared.client?.options.logger?.info('CourierInbox socket not available');\n return;\n }\n\n // Remove any existing listener before adding a new one\n // This prevents duplicates and handles socket changes\n if (this._removeMessageEventListener) {\n this._removeMessageEventListener();\n }\n\n // Register message event listener and store the cleanup function\n this._removeMessageEventListener = socketClient.addMessageEventListener((messageEvent: InboxMessageEventEnvelope) => {\n if (messageEvent.event === InboxMessageEvent.NewMessage) {\n const message: InboxMessage = messageEvent.data as InboxMessage;\n\n this.addMessage(message);\n }\n });\n\n // If the socket is already connecting or open, return early\n if (socketClient.isConnecting || socketClient.isOpen) {\n Courier.shared.client?.options.logger?.info(`Inbox socket already connecting or open for client ID: [${Courier.shared.client?.options.connectionId}]`);\n return;\n }\n\n await socketClient.connect();\n } catch (error: unknown) {\n Courier.shared.client?.options.logger.error('Error listening for messages:', error);\n this._datastoreListeners.forEach(listener => {\n listener.events.onError?.(error as Error);\n });\n }\n }\n\n /**\n * Find the position of an {@link @trycourier/courier-js#InboxMessage} in the toast stack.\n *\n * Notes:\n * - Since the stack is an array, with the last item being the \"top\" of the stack,\n * a toast's position in the underlying array is the inverse of its stack position.\n * - `message` is matched by {@link @trycourier/courier-js#InboxMessage.messageId}, not by object reference.\n *\n * @param message - the {@link @trycourier/courier-js#InboxMessage} to find in the stack\n */\n public toastIndexOfMessage(message: InboxMessage) {\n const position = this._dataset.findIndex(m => m.messageId === message.messageId);\n\n // Message not found\n if (position < 0) {\n return position;\n }\n\n // Return index from end of array (top of stack)\n return this._dataset.length - position - 1;\n }\n\n /**\n * Add an {@link @trycourier/courier-js#InboxMessage} toast item to the datastore.\n *\n * Calling this directly is useful to send test messages while developing with the Courier SDK.</p>\n *\n * @example\n * ```\n * CourierToastDatastore.shared.addMessage({\n * title: 'Lorem ipsum dolor sit',\n * body: 'Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet',\n * messageId: '1'\n * });\n * ```\n *\n * @param message - the message to add as a toast item.\n */\n public addMessage(message: InboxMessage) {\n this._dataset.push(message);\n\n this._datastoreListeners.forEach(listener => {\n if (listener.events.onMessageAdd) {\n listener.events.onMessageAdd(message);\n }\n });\n }\n\n /**\n * Remove an {@link @trycourier/courier-js#InboxMessage} from the datastore.\n *\n * Note: `message` is matched by {@link @trycourier/courier-js#InboxMessage.messageId}, not by object reference\n */\n public removeMessage(message: InboxMessage) {\n const index = this._dataset.findIndex(m => m.messageId === message.messageId);\n if (index < 0) {\n return;\n }\n\n this._dataset.splice(index, /* deleteCount */ 1);\n\n this._datastoreListeners.forEach(listener => {\n if (listener.events.onMessageRemove) {\n listener.events.onMessageRemove(message);\n }\n });\n }\n\n /** Access the shared instance with {@link CourierToastDatastore.shared}. */\n // Prevent instantiation via constructor.\n private constructor() {}\n}\n","import { CourierToastDatastore } from \"./toast-datastore\";\nimport { CourierToastDatastoreEvents } from \"./toast-datastore-events\";\n\n/**\n * Listener containing callbacks for {@link CourierToastDatastore} events.\n *\n * @public\n */\nexport class CourierToastDatastoreListener {\n constructor(readonly events: CourierToastDatastoreEvents) {}\n\n /** Remove this listener. Callbacks will no longer be invoked after remove is called. */\n remove() {\n CourierToastDatastore.shared.removeDatastoreListener(this);\n }\n}\n","import { CourierBaseElement, CourierComponentThemeMode, injectGlobalStyle, registerElement } from \"@trycourier/courier-ui-core\";\nimport { CourierToastThemeManager, CourierToastThemeSubscription } from \"../types/courier-toast-theme-manager\";\nimport { CourierToastTheme, defaultLightTheme } from \"../types/courier-toast-theme\";\nimport { AuthenticationListener, Courier, InboxMessage } from \"@trycourier/courier-js\";\nimport { CourierToastItem } from \"./courier-toast-item\";\nimport { CourierToastItemActionClickEvent, CourierToastItemClickEvent, CourierToastItemFactoryProps } from \"../types/toast\";\nimport { CourierToastDismissButtonOption } from \"../types/toast\";\nimport { CourierToastDatastoreListener } from \"../datastore/toast-datastore-listener\";\nimport { CourierToastDatastore } from \"../datastore/toast-datastore\";\nimport { PausableTimeout } from \"../utils/pausable-timeout\";\n\n/** Default set of CSS properties used to layout CourierToast. */\ntype CourierToastLayoutProps = {\n position?: string;\n width?: string;\n top?: string;\n right?: string;\n zIndex?: number;\n}\n\n/**\n * An embeddable and customizable toast component, fed by data from Courier Inbox.\n *\n * @example\n *\n * Embedding the default toast component on a webpage.\n * ```\n * <html>\n * <body>\n * <courier-toast></courier-toast>\n *\n * <script type=\"module\">\n * import { Courier } from \"@trycourier/courier-ui-toast\";\n *\n * // Authenticate the user\n * Courier.shared.signIn({ userId, jwt });\n * </script>\n * </body>\n * </html>\n * ```\n *\n * @public\n */\nexport class CourierToast extends CourierBaseElement {\n\n // Internally-maintained state\n private _themeManager: CourierToastThemeManager;\n private _themeSubscription: CourierToastThemeSubscription;\n private _toastStyle?: HTMLStyleElement;\n private _authListener?: AuthenticationListener;\n private _datastoreListener: CourierToastDatastoreListener;\n\n /**\n * Whether the cursor is currently over the toast stack.\n *\n * Hover is tracked here — on the container — rather than per item, because\n * the stacked items are one hover surface: moving between them (or a new\n * toast arriving under the cursor) must not resume anyone's countdown.\n */\n private _isHovered = false;\n\n /**\n * Auto-dismiss countdowns for custom toast items set via\n * {@link CourierToast.setToastItem}. {@link CourierToastItem}s own their own\n * countdown, so they're not tracked here.\n */\n private _customItemAutoDismissTimeouts = new WeakMap<HTMLElement, PausableTimeout>();\n\n // Consumer-provided options\n private _autoDismiss: boolean = false;\n private _autoDismissTimeoutMs: number = 5000;\n private _dismissButtonOption: CourierToastDismissButtonOption = 'auto';\n private _customToastItem?: (props: CourierToastItemFactoryProps) => HTMLElement;\n private _customToastItemContent?: (props: CourierToastItemFactoryProps) => HTMLElement;\n\n // Consumer-provided callbacks\n private _onItemClick?: ((props: CourierToastItemClickEvent) => void);\n private _onItemActionClick?: ((props: CourierToastItemActionClickEvent) => void);\n\n /** Default layout props. */\n private readonly _defaultLayoutProps: CourierToastLayoutProps = {\n position: 'fixed',\n width: '380px',\n top: '30px',\n right: '30px',\n zIndex: 999,\n };\n\n /**\n * The names of all attributes for which the web component needs change notifications.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes\n */\n static observedAttributes = [\n 'auto-dismiss',\n 'auto-dismiss-timeout-ms',\n 'dismiss-button',\n 'light-theme',\n 'dark-theme',\n 'mode',\n ];\n\n constructor(props: {\n themeManager?: CourierToastThemeManager\n }) {\n super();\n\n this._themeManager = props?.themeManager ?? new CourierToastThemeManager(defaultLightTheme);\n this._themeSubscription = this._themeManager.subscribe((_: CourierToastTheme) => {\n this.refreshStyles();\n });\n this._datastoreListener = new CourierToastDatastoreListener({\n onMessageAdd: this.datastoreAddMessageListener.bind(this),\n onMessageRemove: this.datastoreRemoveMessageListener.bind(this),\n });\n }\n\n /** Set the handler invoked when a toast item is clicked. */\n public onToastItemClick(handler?: (props: CourierToastItemClickEvent) => void): void {\n this._onItemClick = handler;\n }\n\n /** Set the handler invoked when a toast item action button is clicked. */\n public onToastItemActionClick(handler?: (props: CourierToastItemActionClickEvent) => void): void {\n this._onItemActionClick = handler;\n }\n\n /** Enable auto-dismiss for toast items. */\n public enableAutoDismiss() {\n this._autoDismiss = true;\n }\n\n /** Disable auto-dismiss for toast items. */\n public disableAutoDismiss() {\n this._autoDismiss = false;\n }\n\n /**\n * Set the timeout before auto-dismissing toasts.\n * Only applicable if auto-dismiss is enabled.\n * @param timeoutMs - The timeout in milliseconds before a toast is dismissed.\n */\n public setAutoDismissTimeoutMs(timeoutMs: number) {\n this._autoDismissTimeoutMs = timeoutMs;\n }\n\n /**\n * Set the light theme for the toast.\n * @param theme - The light theme object to set.\n */\n public setLightTheme(theme: CourierToastTheme) {\n this._themeManager.setLightTheme(theme);\n }\n\n /**\n * Set the dark theme for the toast.\n * @param theme - The dark theme object to set.\n */\n public setDarkTheme(theme: CourierToastTheme) {\n this._themeManager.setDarkTheme(theme);\n }\n\n /**\n * Set the dismiss button display option.\n *\n * @param option - a value of {@link CourierToastDismissButtonOption}\n */\n public setDismissButton(option: CourierToastDismissButtonOption) {\n this._dismissButtonOption = option;\n this.refreshStyles();\n }\n\n /**\n * Set the theme mode.\n *\n * @param mode - The theme mode, one of \"dark\", \"light\", or \"system\".\n */\n public setMode(mode: CourierComponentThemeMode) {\n this._themeManager.setMode(mode);\n }\n\n /**\n * Set a factory function that renders a toast item.\n *\n * See {@link CourierToast.setToastItemContent} to set the content while preserving the toast item's\n * container and stack styling.\n */\n public setToastItem(factory?: (props: CourierToastItemFactoryProps) => HTMLElement) {\n this._customToastItem = factory;\n }\n\n /**\n * Set a factory function that renders a toast item's content.\n *\n * The toast item's container, including the stack, auto-dismiss timer, and dismiss button\n * and all events are still present when custom content is set.\n *\n * See {@link CourierToast.setDismissButton} to customize the dismiss button's visibility and\n * {@link CourierToast.setToastItem} to customize the entire toast item, including\n * its container.\n */\n public setToastItemContent(factory?: (props: CourierToastItemFactoryProps) => HTMLElement) {\n this._customToastItemContent = factory;\n }\n\n /**\n * Dismiss the toast item(s) associated with a particular {@link @trycourier/courier-js#InboxMessage}.\n *\n * Toast items are matched to messages by the field {@link @trycourier/courier-js#InboxMessage.messageId}.\n * If the item is an instance of {@link CourierToastItem} it will be animated out\n * before removal, otherwise custom items are removed immediately.\n *\n * If there are multiple toast items matching the message, all items will be dismissed.\n *\n * @example\n * Using dismissToastForMessage with setToastItem to dismiss a custom element.\n * ```ts\n * // Get a reference to the toast component\n * const toast = document.getElementById(\"my-toast\");\n *\n * toast.setToastItem((props) => {\n * const el = document.createElement(\"div\");\n * el.addEventListener(\"click\", () => toast.dismissToastForMessage(props.message));\n * return el;\n * });\n * ```\n *\n * @param message - the {@link @trycourier/courier-js#InboxMessage} for which toast items should be dismissed\n */\n private dismissToastForMessage(message: InboxMessage) {\n this.childNodes.forEach(node => {\n const nodeMessageId = (node as HTMLElement).dataset.courierMessageId;\n\n if (nodeMessageId !== message.messageId) {\n return;\n }\n\n if (node instanceof CourierToastItem) {\n node.dismiss();\n } else {\n this._customItemAutoDismissTimeouts.get(node as HTMLElement)?.cancel();\n node.remove();\n }\n });\n }\n\n /**\n * @override\n */\n protected onComponentMounted(): void {\n this._toastStyle = injectGlobalStyle(CourierToast.id, this.getStyles(this.theme));\n\n // Pause every countdown in the stack while the cursor is over the toast, so\n // a user reading it is never rushed. mouseenter/mouseleave (not\n // mouseover/mouseout) fire once for the container's whole subtree, so moving\n // between toast items and their children doesn't resume the countdown.\n this.addEventListener('mouseenter', this.onMouseEnter);\n this.addEventListener('mouseleave', this.onMouseLeave);\n\n CourierToastDatastore.shared.addDatastoreListener(this._datastoreListener);\n Courier.shared.addAuthenticationListener(this.authChangedCallback.bind(this));\n CourierToastDatastore.shared.listenForMessages();\n }\n\n /**\n * @override\n */\n protected onComponentUnmounted(): void {\n this.removeEventListener('mouseenter', this.onMouseEnter);\n this.removeEventListener('mouseleave', this.onMouseLeave);\n\n this._datastoreListener.remove();\n this._authListener?.remove();\n this._toastStyle?.remove();\n this._themeManager.cleanup();\n this._themeSubscription.unsubscribe();\n }\n\n private onMouseEnter = (): void => {\n this._isHovered = true;\n this.setAutoDismissPaused(true);\n };\n\n private onMouseLeave = (): void => {\n this._isHovered = false;\n this.setAutoDismissPaused(false);\n };\n\n /** Pause or resume the auto-dismiss countdown of every item in the stack. */\n private setAutoDismissPaused(paused: boolean): void {\n Array.from(this.children).forEach(child => this.setItemAutoDismissPaused(child as HTMLElement, paused));\n }\n\n /** Pause or resume a single item's auto-dismiss countdown. */\n private setItemAutoDismissPaused(item: HTMLElement, paused: boolean): void {\n if (item instanceof CourierToastItem) {\n paused ? item.pauseAutoDismiss() : item.resumeAutoDismiss();\n return;\n }\n\n const customItemTimeout = this._customItemAutoDismissTimeouts.get(item);\n paused ? customItemTimeout?.pause() : customItemTimeout?.resume();\n }\n\n /**\n * Lifecycle callback invoked when an observed attribute changes.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes\n */\n protected attributeChangedCallback(name: string, _: string, newValue: string) {\n switch (name) {\n case 'auto-dismiss':\n if (newValue === 'false') {\n this.disableAutoDismiss();\n } else {\n this.enableAutoDismiss();\n }\n break;\n case 'auto-dismiss-timeout-ms':\n this.setAutoDismissTimeoutMs(parseInt(newValue, /* base= */ 10));\n break;\n case 'dismiss-button':\n if (newValue && CourierToast.isDismissButtonOption(newValue)) {\n this.setDismissButton(newValue as CourierToastDismissButtonOption);\n } else {\n this.setDismissButton('auto');\n }\n break;\n case 'light-theme':\n if (newValue) {\n this.setLightTheme(JSON.parse(newValue));\n }\n break;\n case 'dark-theme':\n if (newValue) {\n this.setDarkTheme(JSON.parse(newValue));\n }\n break;\n case 'mode':\n this._themeManager.setMode(newValue as CourierComponentThemeMode);\n break;\n }\n }\n\n private get theme(): CourierToastTheme {\n return this._themeManager.getTheme();\n }\n\n /** Refresh the styles tag, if it exists, with the current theme. */\n private refreshStyles() {\n if (this._toastStyle) {\n this._toastStyle.textContent = this.getStyles(this.theme);\n }\n }\n\n private authChangedCallback() {\n this.removeAllItems();\n\n // If re-auth'ing logged the user out and closed the WebSocket connection,\n // we'll open a new connection. If one is already open, this is a no-op.\n CourierToastDatastore.shared.listenForMessages();\n }\n\n private removeAllItems(): void {\n while (this.firstChild) {\n this._customItemAutoDismissTimeouts.get(this.firstChild as HTMLElement)?.cancel();\n this.removeChild(this.firstChild);\n }\n }\n\n private addToastItem(message: InboxMessage): CourierToastItem | HTMLElement {\n // Append the toast item and resize the toast container\n // so previous toast items can stack underneath at fixed offsets\n // from the top item.\n const toastItem = this.createToastItem(message);\n toastItem.dataset.courierMessageId = message.messageId;\n this.appendChild(toastItem);\n this.resizeContainerToHeight(this.topStackItemHeight);\n\n // A toast that arrives while the cursor is already over the stack starts out\n // paused — it just landed under the cursor, so it hasn't been read yet.\n if (this._isHovered) {\n this.setItemAutoDismissPaused(toastItem, /* paused= */ true);\n }\n\n return toastItem;\n }\n\n private createToastItem(message: InboxMessage): CourierToastItem | HTMLElement {\n if (this._customToastItem) {\n return this.createCustomToastItem(message);\n }\n\n return this.createDefaultToastItem(message);\n }\n\n private createDefaultToastItem(message: InboxMessage) {\n const item = new CourierToastItem({\n message,\n autoDismiss: this._autoDismiss,\n autoDismissTimeoutMs: this._autoDismissTimeoutMs,\n themeManager: this._themeManager\n });\n\n item.onItemDismissed((_) => {\n this.resizeContainerToHeight(this.topStackItemHeight);\n });\n\n if (this._customToastItemContent) {\n item.setToastItemContent(this._customToastItemContent);\n }\n\n if (this._onItemClick) {\n item.onToastItemClick(this._onItemClick);\n }\n\n if (this._onItemActionClick) {\n item.onToastItemActionClick(this._onItemActionClick);\n }\n\n // The auto-dismiss countdown (and its hover-to-pause behavior) is owned by\n // the CourierToastItem itself, started when it mounts — see\n // CourierToastItem.onComponentMounted.\n\n return item;\n }\n\n private createCustomToastItem(message: InboxMessage) {\n if (!this._customToastItem) {\n throw Error(\"Attempted to create customToastItem, but none is set\");\n }\n\n const customItem = this._customToastItem({\n message,\n autoDismiss: this._autoDismiss,\n autoDismissTimeoutMs: this._autoDismissTimeoutMs,\n });\n\n if (this._autoDismiss) {\n // Custom items have no countdown of their own, so the container owns it —\n // including pausing it while the cursor is over the toast.\n const autoDismissTimeout = new PausableTimeout(() => customItem.remove(), this._autoDismissTimeoutMs);\n this._customItemAutoDismissTimeouts.set(customItem, autoDismissTimeout);\n autoDismissTimeout.start();\n }\n\n customItem.addEventListener('click', () => {\n if (this._onItemClick) {\n this._onItemClick({ message });\n }\n });\n\n return customItem;\n }\n\n private datastoreAddMessageListener(message: InboxMessage) {\n this.addToastItem(message);\n }\n\n private datastoreRemoveMessageListener(message: InboxMessage) {\n this.dismissToastForMessage(message);\n }\n\n private getStyles(theme: CourierToastTheme): string {\n const item = theme.item;\n\n // Styles for the top-level toast container.\n const toastStyles = `\n ${CourierToast.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\n // Stack the three most recently shown toast items and hide all others.\n // Content is transparent for all but the most recent (top) toast item\n // since it otherwise peeks out in the visible stack items.\n const toastStackStyles = `\n ${CourierToastItem.id}:last-child {\n top: 0;\n right: 0;\n }\n\n ${CourierToastItem.id}:nth-last-child(2) {\n top: 12px;\n bottom: -12px;\n --scale: 0.95\n }\n\n ${CourierToastItem.id}:nth-last-child(3) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n }\n\n ${CourierToastItem.id}:nth-last-child(n+4) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n visibility: hidden;\n }\n\n ${CourierToastItem.id}:nth-last-child(n+2) > .overflow-hidden-container {\n opacity: 0;\n }\n `;\n\n // Styles for the visible toast item.\n // `opacity` and `transform` are the initial states before\n // the keyframed `animation` show is applied.\n // The class `dismissing` is added to trigger the `animation` hide\n // before removing an item.\n // Only the top item is clickable.\n const toastItemStyles = `\n ${CourierToastItem.id} {\n position: absolute;\n box-sizing: border-box;\n width: 100%;\n background-color: ${item?.backgroundColor};\n box-shadow: ${item?.shadow};\n border: ${item?.border};\n border-radius: ${item?.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 ${CourierToastItem.id} > .overflow-hidden-container {\n height: 100%;\n width: 100%;\n border-radius: ${item?.borderRadius};\n overflow: hidden;\n }\n\n ${CourierToastItem.id}.dismissing {\n animation: courier-toast-hide 0.3s ease-in-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 @keyframes courier-toast-hide {\n 0% {\n opacity: 1;\n transform: scaleX(var(--scale, 1));\n }\n\n 100% {\n opacity: 0;\n transform: scaleX(var(--scale, 1));\n }\n }\n\n ${CourierToastItem.id}.clickable:last-child {\n cursor: pointer;\n }\n\n ${CourierToastItem.id}.clickable:last-child:hover {\n background-color: ${item?.hoverBackgroundColor};\n }\n\n ${CourierToastItem.id}.clickable:last-child:active {\n background-color: ${item?.activeBackgroundColor};\n }\n\n ${CourierToastItem.id}.clickable:nth-last-child(n+2) {\n pointer-events: none;\n }\n `;\n\n // A dismiss icon is visible when the top toast item is in the :hover state.\n // Auto-dismiss styles are added, but unused if the auto-dismiss progress\n // bar is not added in the courier-toast-item element\n // (i.e. when auto-dismiss is disabled).\n const dismissStyles = `\n ${CourierToastItem.id} > .dismiss {\n position: absolute;\n visibility: hidden;\n opacity: 0%;\n top: -10px;\n right: -10px;\n background-color: ${item?.backgroundColor};\n border: ${item?.border};\n padding: 3px;\n border-radius: 50%;\n font-size: 12pt;\n box-shadow: ${item?.shadow};\n cursor: pointer;\n transition: 0.2s ease-in-out;\n }\n\n ${CourierToastItem.id} > .dismiss:hover {\n background-color: ${item?.hoverBackgroundColor};\n }\n\n ${CourierToastItem.id} > .dismiss:active {\n background-color: ${item?.activeBackgroundColor};\n }\n\n ${CourierToastItem.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\n const autoDismissStyles = `\n ${CourierToastItem.id} > .overflow-hidden-container > .auto-dismiss {\n width: 100%;\n height: 5px;\n background-color: ${item?.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\n // Styles for the text and icon content.\n const contentStyles = `\n ${CourierToastItem.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 ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content {\n }\n\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .icon {\n }\n\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content > .title {\n margin: 0;\n font-weight: ${item?.title?.weight};\n font-size: ${item?.title?.size};\n color: ${item?.title?.color};\n }\n\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content > .body {\n margin: 8px 0 0 0;\n font-weight: ${item?.body?.weight};\n font-size: ${item?.body?.size};\n line-height: 150%;\n color: ${item?.body?.color};\n }\n `;\n\n const actionStyles = `\n ${CourierToastItem.id} > .overflow-hidden-container > .content > .text-content > .actions-container {\n display: flex;\n gap: 8px;\n margin-top: 12px;\n }\n `;\n\n return [\n toastStyles,\n toastStackStyles,\n toastItemStyles,\n dismissStyles,\n autoDismissStyles,\n contentStyles,\n actionStyles,\n ].join('');\n }\n\n /** Get the top item's (i.e. the fully visible item's) height. */\n private get topStackItemHeight(): string {\n if (this.lastChild) {\n const height = (this.lastChild as HTMLDivElement).getBoundingClientRect().height;\n return `${height}px`;\n }\n\n return '0px';\n }\n\n private resizeContainerToHeight(height: string) {\n this.style.height = height;\n }\n\n /** Whether the dismiss button should only be shown on hover. */\n private get showDismissOnHover(): boolean {\n // Auto-dismiss is enabled and button is using 'auto' behavior (show w/o auto-dismiss, show on hover w/ auto-dismiss).\n if (this._autoDismiss && this._dismissButtonOption === 'auto') {\n return true;\n }\n\n // Explicitly set to show on hover\n if (this._dismissButtonOption === 'hover') {\n return true;\n }\n\n return false;\n }\n\n /** Whether to show the dismiss button. The button is visible (either always or on hover) if not explicitly disabled. */\n private get showDismiss(): boolean {\n return this._dismissButtonOption !== 'hidden';\n }\n\n /** @override */\n static get id() {\n return 'courier-toast';\n }\n\n private static isDismissButtonOption(value: string): value is CourierToastDismissButtonOption {\n const validOptions: CourierToastDismissButtonOption[] = ['visible', 'hidden', 'hover', 'auto'];\n return validOptions.includes(value as CourierToastDismissButtonOption);\n }\n}\n\nregisterElement(CourierToast);\n","import { InboxMessage } from \"@trycourier/courier-js\";\n\n/**\n * The set of {@link CourierToastDatastore} events for which listeners can be added.\n *\n * @public\n */\nexport class CourierToastDatastoreEvents {\n public onMessageAdd?(_: InboxMessage): void { }\n public onMessageRemove?(_: InboxMessage): void { }\n public onError?(_: Error): void { }\n}\n","export * from './components/courier-toast';\r\nexport * from './components/courier-toast-item';\r\nexport * from './types/courier-toast-theme';\r\nexport * from './types/courier-toast-theme-manager';\r\nexport * from './types/toast';\r\nexport * from './datastore/toast-datastore';\r\nexport * from './datastore/toast-datastore-listener';\r\nexport * from './datastore/toast-datastore-events';\r\n\r\nimport { Courier } from \"@trycourier/courier-js\";\r\n\r\nCourier.shared.courierUserAgentName = \"courier-ui-toast\";\r\nCourier.shared.courierUserAgentVersion = __PACKAGE_VERSION__;\r\n\r\n// Re-export Courier from courier-js for direct import\r\nexport { Courier };\r\n\r\n// Re-export types from courier-js\r\nexport type {\n CourierProps,\n CourierClientOptions,\n CourierBrand,\n CourierApiRegion,\n CourierApiUrls,\n CourierUserPreferences,\r\n CourierUserPreferencesStatus,\r\n CourierUserPreferencesChannel,\r\n CourierUserPreferencesPaging,\r\n CourierUserPreferencesTopic,\r\n CourierUserPreferencesTopicResponse,\r\n CourierDevice,\r\n CourierToken,\r\n CourierGetInboxMessageResponse,\r\n CourierGetInboxMessagesResponse,\r\n InboxMessage,\r\n InboxAction,\r\n InboxMessageEventEnvelope,\n} from '@trycourier/courier-js';\n\nexport {\n DEFAULT_COURIER_API_URLS,\n EU_COURIER_API_URLS,\n getCourierApiUrls,\n getCourierApiUrlsForRegion\n} from '@trycourier/courier-js';\n\r\n// Re-export types from courier-ui-core\r\nexport type {\r\n CourierComponentThemeMode\r\n} from '@trycourier/courier-ui-core'\r\n"],"names":["_b","_a"],"mappings":";;;;;;AAwCO,MAAM,oBAAuC;AAAA,EAClD,MAAM;AAAA,IACJ,iBAAiB,cAAc,MAAM,GAAG;AAAA,IACxC,sBAAsB,cAAc,KAAK,GAAG;AAAA,IAC5C,uBAAuB,cAAc,KAAK,GAAG;AAAA,IAC7C,QAAQ,oBAAoB,cAAc,MAAM,KAAM,CAAC;AAAA,IACvD,QAAQ,aAAa,cAAc,KAAK,GAAG,CAAC;AAAA,IAC5C,cAAc;AAAA,IACd,OAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,OAAO,cAAc,MAAM,GAAG;AAAA,IAAA;AAAA,IAEhC,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,OAAO,cAAc,KAAK,GAAG;AAAA,IAAA;AAAA,IAE/B,MAAM;AAAA,MACJ,OAAO,cAAc,MAAM,GAAG;AAAA,MAC9B,KAAK,gBAAgB;AAAA,IAAA;AAAA,IAEvB,aAAa;AAAA,MACX,OAAO,cAAc,MAAM,GAAG;AAAA,MAC9B,KAAK,gBAAgB;AAAA,IAAA;AAAA,IAEvB,qBAAqB,cAAc,KAAK,GAAG;AAAA,IAC3C,SAAS;AAAA,MACP,iBAAiB;AAAA,MACjB,sBAAsB,cAAc,KAAK,GAAG;AAAA,MAC5C,uBAAuB,cAAc,KAAK,GAAG;AAAA,MAC7C,QAAQ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/**
2
+ * A `setTimeout` that can be paused and resumed.
3
+ *
4
+ * Pausing banks the time that has already elapsed, so resuming fires the
5
+ * callback after the *remaining* time rather than restarting the full delay.
6
+ *
7
+ * Used for the toast auto-dismiss countdown, which pauses while the cursor is
8
+ * over the toast.
9
+ */
10
+ export declare class PausableTimeout {
11
+ private readonly _callback;
12
+ /** Time left on the countdown, updated each time it's paused. */
13
+ private _remainingMs;
14
+ private _timerId;
15
+ /** When the currently-running countdown was (re)started. */
16
+ private _startedAt;
17
+ private _isPaused;
18
+ /** Set once the callback has fired (or the countdown was cancelled). */
19
+ private _isDone;
20
+ constructor(callback: () => void, delayMs: number);
21
+ /** Whether the countdown is currently paused. */
22
+ get isPaused(): boolean;
23
+ /** Start the countdown for whatever time is left on it. */
24
+ start(): void;
25
+ /** Pause the countdown, banking the time that has already elapsed. */
26
+ pause(): void;
27
+ /** Resume a paused countdown from where it left off. */
28
+ resume(): void;
29
+ /** Cancel the countdown for good; it can't be started again. */
30
+ cancel(): void;
31
+ private clear;
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier-ui-toast",
3
- "version": "2.1.9",
3
+ "version": "2.1.11",
4
4
  "description": "Toast components for the Courier web UI",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -11,7 +11,6 @@
11
11
  "build:ci": "yarn build && yarn generate-api-doc",
12
12
  "watch": "vite build --watch",
13
13
  "preview": "vite preview",
14
- "prepare": "npm run build",
15
14
  "test": "jest",
16
15
  "generate-api-doc": "api-extractor run"
17
16
  },