UNPKG

customerio-gist-web

Version:

Build beautiful in-app flows with no code and deliver them instantly to your app. http://customer.io

1 lines 110 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Gist=e():t.Gist=e()}(this,()=>(()=>{"use strict";var t={d:(e,n)=>{for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{default:()=>ui});class n{constructor(){this.callbacks={}}on(t,e){const n=this.callbacks[t];n?n.push(e):this.callbacks[t]=[e]}off(t,e){const n=this.callbacks[t];if(!n)return;if(!e)return void delete this.callbacks[t];const i=n.indexOf(e);-1!==i&&n.splice(i,1),0===n.length&&delete this.callbacks[t]}dispatch(t,e){const n=this.callbacks[t];n&&[...n].forEach(n=>{try{n(e)}catch(e){console.warn(`[Gist] Error in "${t}" event listener:`,e)}})}}function i(t){ui.config&&ui.config.logging&&console.log(`Gist: ${t}`)}const o="gist.web.isPersistingSession";function s(t,e,n=null){let i=n;i||(i=new Date,i.setDate(i.getDate()+365));const o={value:e,expiry:i};c().setItem(t,JSON.stringify(o))}function a(t){return d(t)}function r(t){c().removeItem(t)}function l(){const t=sessionStorage.getItem(o);return null===t?(sessionStorage.setItem(o,"true"),!0):"true"===t}function c(){return l()?localStorage:sessionStorage}function d(t){if(!t)return null;try{const e=c().getItem(t);if(!e)return null;const n=JSON.parse(e);if(!n.expiry)return n.value;if(t.startsWith("gist.")){const e=new Date,i=new Date(n.expiry),o=t.startsWith("gist.web.message.broadcasts")&&!t.endsWith("shouldShow")&&!t.endsWith("numberOfTimesShown")||t.startsWith("gist.web.message.user")&&!t.endsWith("seen")&&!t.endsWith("state"),s=new Date(e.getTime()+366e4);if(o&&i.getTime()>s.getTime())return r(t),null;if(e.getTime()>i.getTime())return r(t),null}return n.value}catch(e){i(`Error checking key ${t} for expiry: ${e}`)}return null}const u=new Uint8Array(16),p=[];for(let t=0;t<256;++t)p.push((t+256).toString(16).slice(1));const g=function(t,e,n){return e||t||!crypto.randomUUID?function(t,e,n){const i=(t=t||{}).random??t.rng?.()??crypto.getRandomValues(u);if(i.length<16)throw new Error("Random bytes length must be >= 16");if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,e){if((n=n||0)<0||n+16>e.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let t=0;t<16;++t)e[n+t]=i[t];return e}return function(t,e=0){return(p[t[e+0]]+p[t[e+1]]+p[t[e+2]]+p[t[e+3]]+"-"+p[t[e+4]]+p[t[e+5]]+"-"+p[t[e+6]]+p[t[e+7]]+"-"+p[t[e+8]]+p[t[e+9]]+"-"+p[t[e+10]]+p[t[e+11]]+p[t[e+12]]+p[t[e+13]]+p[t[e+14]]+p[t[e+15]]).toLowerCase()}(i)}(t,e,n):crypto.randomUUID()},m="gist.web.inbox.enabled",h="gist.web.userQueueUseSSE",f="gist.web.activeSSEConnection";let b,y=30;const v={RENDERER_HOST:{prod:"https://code.gist.build",dev:"https://code.gist.build",local:"http://localhost:9998"},ENGINE_API_ENDPOINT:{prod:"https://engine.api.gist.build",dev:"https://engine.api.dev.gist.build",local:"http://engine.api.local.gist.build:82"},GIST_QUEUE_API_ENDPOINT:{prod:"https://consumer.cloud.gist.build",dev:"https://consumer.cloud.dev.gist.build",local:"http://localhost:3010"},GIST_QUEUE_REALTIME_API_ENDPOINT:{prod:"https://realtime.cloud.gist.build",dev:"https://realtime.cloud.dev.gist.build",local:"http://localhost:3009"},GIST_VIEW_ENDPOINT:{prod:"https://renderer.gist.build/3.0",dev:"https://renderer.gist.build/3.0",local:"http://localhost:9998"},getSdkId:()=>(b||(b=g()),b),useSSE:()=>a(h)??!1,setUseSSEFlag(t){s(h,t,new Date((new Date).getTime()+6e4)),i(`Set user uses SSE to "${t}"`)},removeActiveSSEConnection(){r(f)},setActiveSSEConnection(){s(f,v.getSdkId(),new Date((new Date).getTime()+v.getSSEHeartbeat()))},hasActiveSSEConnection:()=>a(f)??!1,isSSEConnectionManagedBySDK:()=>a(f)===v.getSdkId(),getSSEHeartbeat:()=>1e3*(y+5),setSSEHeartbeat(t){t&&t>0&&(y=t)},inboxEnabled:()=>a(m)??!1,setInboxEnabledFlag(t){s(m,t,new Date((new Date).getTime()+36e5)),i(`Set inbox enabled to "${t}"`)}};function w(t){return null!==t&&"object"==typeof t&&"response"in t}function x(t){return w(t)?t.response:void 0}function S(){const t=v.GIST_QUEUE_API_ENDPOINT[ui.config.env??"prod"],e={"X-CIO-Site-Id":ui.config.siteId,"X-CIO-Client-Platform":"web"},n=Le();async function i(n,i={}){const o=t+n,s=new AbortController,a=setTimeout(()=>s.abort(),5e3);try{const t=await fetch(o,{method:i.method||"GET",headers:{...e,...i.headers||{}},body:i.method&&"GET"!==i.method.toUpperCase()?i.body:void 0,signal:s.signal});clearTimeout(a);const n=t.headers.get("content-type")?.includes("application/json"),r=n?await t.json():await t.text(),l=Object.fromEntries(t.headers.entries());if(t.status<200||t.status>=400)throw function(t){return Object.assign(new Error,{response:t})}({status:t.status,data:r,headers:l});return{status:t.status,headers:l,data:r}}catch(t){if(clearTimeout(a),w(t))throw t;if(t instanceof Error)throw Object.assign(t,{response:{status:0,data:t.message||"Unknown error",headers:{}}});throw t}}return null!=n&&(e["X-Gist-Encoded-User-Token"]=n),i.post=(t,e={},n={})=>i(t,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json",...n.headers||{}}}),i}const I="gist.web.userLocale";function C(){const t=a(I);return null!==t?t:navigator.language}const $="gist.web.branding";async function k(){if(null!==a($))return void i("Branding already cached.");const t=await async function(){try{return await S()("/api/v1/branding")}catch(t){return x(t)}}();if(t&&t.status>=200&&t.status<300){const e=new Date;e.setMinutes(e.getMinutes()+10),s($,t.data,e),i("Branding fetched and cached.")}}function E(){return a($)}const j="gist.web.templates";async function L(){if(null!==a(j))return void i("Templates already cached.");const t=await async function(){try{return await S()("/api/v1/templates")}catch(t){return x(t)}}();if(t&&t.status>=200&&t.status<300){const e=new Date;e.setMinutes(e.getMinutes()+60),s(j,t.data,e),i("Templates fetched and cached.")}}function T(){return a(j)}function P(t){try{return(document.getElementById(t)??document.querySelector(t))||null}catch{return null}}function D(t,e={}){const n=document.createElement(t);for(const[t,i]of Object.entries(e))n[t]=i;return n}function N(t,e){if(document.getElementById(t))return;const n=document.createElement("style");n.id=t,n.textContent=e,document.head.appendChild(n)}function M(t){document.body?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>document.body.appendChild(t),{once:!0})}async function A(t){try{return await S().post(`/api/v1/logs/queue/${t}`)}catch(t){return x(t)}}const R="messageInboxUpdated",q="inboxMessageAction";async function z(t){const e=await B();if(!e)return;const n=new Date;n.setMinutes(n.getMinutes()+60),s(e,t,n),ui.events.dispatch(R,t)}async function W(){const t=await B();if(!t)return[];const e=a(t)??[],n=new Date;return e.filter(t=>!t.expiry||new Date(t.expiry)>n)}async function _(t,e){const n=await B();if(!n)return;const o=await async function(t,e){try{return await S()(`/api/v1/messages/${t}`,{method:"PATCH",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}})}catch(t){return x(t)}}(t,{opened:e});if(!o||o.status<200||o.status>=300){const t=`Failed to mark inbox message opened: ${o?.status??"unknown error"}`;throw i(t),new Error(t)}const a=await W();let r=null;const l=a.map(n=>{if(n.queueId===t){const t={...n,opened:e};return r=t,t}return n}),c=new Date;if(c.setMinutes(c.getMinutes()+60),s(n,l,c),r){const t=e?"opened":"unopened";ui.events.dispatch(q,{message:r,action:t})}ui.events.dispatch(R,await W())}async function O(t){const e=await B();if(!e)return;const n=await W(),o=n.find(e=>e.queueId===t)??null,a=n.filter(e=>e.queueId!==t),r=new Date;r.setMinutes(r.getMinutes()+60),s(e,a,r),o&&ui.events.dispatch(q,{message:o,action:"dismissed"}),ui.events.dispatch(R,await W());const l=await A(t);(!l||l.status<200||l.status>=300)&&i(`Failed to log inbox message view: ${l?.status??"unknown error"}`)}async function B(){const t=await je();return t?`gist.web.inbox.messages.${t}`:null}const U={isEmbedded:!1,elementId:"",hasRouteRule:!1,routeRule:"",position:"",hasPosition:!1,tooltipPosition:"",hasTooltipPosition:!1,tooltipArrowColor:"#fff",shouldScale:!1,campaignId:null,messageWidth:414,overlayColor:"#00000033",persistent:!1,exitClick:!1,hasCustomWidth:!1};function H(t){let e=U.tooltipArrowColor;if((t?.properties?.gist?.tooltipArrowColor?.length??0)>0)e=t.properties.gist.tooltipArrowColor;else{if(!Array.isArray(t?.displaySettings)||0===t.displaySettings.length)return e;let n=t.displaySettings[0];if(t.savedStepName){const e=t.displaySettings.find(e=>e?.stepName===t.savedStepName&&e.displaySettings);e&&(n=e)}n?.displaySettings?.tooltipArrowColor&&(e=n.displaySettings.tooltipArrowColor)}return e}function F(t){const e=U,n=t?.properties?.gist;return n?{isEmbedded:!!n.elementId&&!n.tooltipPosition,elementId:n.elementId||"",hasRouteRule:!!n.routeRuleWeb,routeRule:n.routeRuleWeb||"",position:n.position||"",hasPosition:!!n.position,tooltipPosition:n.tooltipPosition||"",hasTooltipPosition:!!n.tooltipPosition,tooltipArrowColor:H(t),shouldScale:!!n.scale,campaignId:n.campaignId??null,messageWidth:null!=n.messageWidth&&n.messageWidth>0?n.messageWidth:e.messageWidth,hasCustomWidth:(n.messageWidth??0)>0,overlayColor:n.overlayColor||e.overlayColor,persistent:!!n.persistent,exitClick:!!n.exitClick}:e}const V=["x-gist-top","x-gist-floating-top","x-gist-bottom","x-gist-floating-bottom","x-gist-floating-bottom-left","x-gist-floating-bottom-right","x-gist-floating-top-left","x-gist-floating-top-right"];function G(t){if(document.getElementById(t))return;const e=document.createElement("div");e.id=t,"x-gist-top"===t?document.body.insertBefore(e,document.body.firstChild):document.body.insertAdjacentElement("beforeend",e),i("Top & bottom elements injected into page")}const X=["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"];function J(t){return ui.currentMessages.find(e=>e.instanceId===t)}function Q(t){return!!t&&ui.currentMessages.some(e=>e.queueId===t)}function Y(t){return t?ui.currentMessages.find(e=>e.elementId===t)??null:null}function K(t){ui.currentMessages=ui.currentMessages.filter(e=>e.instanceId!==t)}function Z(t,e){K(t),ui.currentMessages.push(e)}const tt={topLeft:"x-gist-floating-top-left",topCenter:"x-gist-floating-top",topRight:"x-gist-floating-top-right",bottomLeft:"x-gist-floating-bottom-left",bottomCenter:"x-gist-floating-bottom",bottomRight:"x-gist-floating-bottom-right"},et=Object.fromEntries(Object.entries(tt).map(([t,e])=>[e,t]));function nt(t){return t&&tt[t]?tt[t]:(i(`Invalid overlay position "${t}", defaulting to "topCenter"`),tt.topCenter)}function it(t){try{const e=new RegExp(t),n=new URL(window.location.href).pathname,i=null!=ui.currentRoute&&e.test(ui.currentRoute),o=ui.currentRoute!==n&&e.test(n);return i||o}catch{return!1}}function ot(t){return t.tooltipPosition?"tooltip":t.overlay?"modal":t.elementId&&V.includes(t.elementId)?"overlay":t.elementId?"inline":"modal"}function st(t,e){const n=ot(t),i=e.displayType;if(void 0===i)return!1;if(n!==i)return!0;const o=F(t);switch(i){case"modal":{if((t.position||"center")!==(e.modalPosition||"center"))return!0;const n=e.dismissOutsideClick??U.exitClick;if(o.exitClick!==n)return!0;const i=e.overlayColor??U.overlayColor;if(o.overlayColor!==i)return!0;break}case"overlay":{const n=nt(e.overlayPosition);if(t.elementId!==n)return!0;break}case"inline":if(t.elementId!==e.elementSelector)return!0;break;case"tooltip":if(t.tooltipPosition!==e.tooltipPosition)return!0;if(t.elementId!==e.elementSelector)return!0;if(void 0!==e.tooltipArrowColor&&o.tooltipArrowColor!==e.tooltipArrowColor)return!0}if("overlay"!==i||!X.includes(nt(e.overlayPosition))){const t=e.maxWidth??U.messageWidth;if(o.messageWidth!==t)return!0}return!1}function at(t,e){if(t.properties||(t.properties={}),t.properties.gist||(t.properties.gist={}),"modal"===e.displayType)t.overlay=!0,t.elementId=null,t.properties.gist.elementId=null,t.position=e.modalPosition||"center",t.properties.gist.position=e.modalPosition||"center",t.tooltipPosition=void 0,t.properties.gist.tooltipPosition=void 0,t.properties.gist.tooltipArrowColor=void 0;else if("overlay"===e.displayType){t.overlay=!1;const n=nt(e.overlayPosition);t.elementId=n,t.properties.gist.elementId=n,t.position=null,t.properties.gist.position=null,t.tooltipPosition=void 0,t.properties.gist.tooltipPosition=void 0,t.properties.gist.tooltipArrowColor=void 0}else"inline"===e.displayType?(t.overlay=!1,t.elementId=e.elementSelector,t.properties.gist.elementId=e.elementSelector,t.position=null,t.properties.gist.position=null,t.tooltipPosition=void 0,t.properties.gist.tooltipPosition=void 0,t.properties.gist.tooltipArrowColor=void 0):"tooltip"===e.displayType&&(t.overlay=!1,t.elementId=e.elementSelector,t.properties.gist.elementId=e.elementSelector,t.tooltipPosition=e.tooltipPosition,t.properties.gist.tooltipPosition=e.tooltipPosition,t.position=null,t.properties.gist.position=null,void 0!==e.tooltipArrowColor&&(t.properties.gist.tooltipArrowColor=e.tooltipArrowColor));t.elementId&&X.includes(t.elementId)?delete t.properties.gist.messageWidth:void 0!==e.maxWidth&&e.maxWidth>0?t.properties.gist.messageWidth=e.maxWidth:delete t.properties.gist.messageWidth,void 0!==e.overlayColor?t.properties.gist.overlayColor=e.overlayColor:delete t.properties.gist.overlayColor,void 0!==e.dismissOutsideClick?t.properties.gist.exitClick=e.dismissOutsideClick:delete t.properties.gist.exitClick}const rt={top:["bottom","left","right"],bottom:["top","left","right"],left:["right","top","bottom"],right:["left","top","bottom"]},lt=/auto|scroll/,ct={top:"gist-arrow-bottom",bottom:"gist-arrow-top",left:"gist-arrow-right",right:"gist-arrow-left"};function dt(t){const e=P(t);return e||i(`Tooltip target element not found for selector: ${t}`),e}function ut(t,e){if(t.bottom<=0||t.top>=window.innerHeight||t.right<=0||t.left>=window.innerWidth)return!1;for(const n of e){const e=n.getBoundingClientRect();if(t.bottom<=e.top||t.top>=e.bottom||t.right<=e.left||t.left>=e.right)return!1}return!0}function pt(t,e,n){const i=function(t,e,n){switch(n){case"top":return{top:e.top-t.height-16,left:e.left+(e.width-t.width)/2};case"bottom":return{top:e.bottom+16,left:e.left+(e.width-t.width)/2};case"left":return{top:e.top+(e.height-t.height)/2,left:e.left-t.width-16};case"right":return{top:e.top+(e.height-t.height)/2,left:e.right+16}}}(t,e,n);return function(t,e,n){return"top"===n||"bottom"===n?t.top>=0&&t.top+e.height<=window.innerHeight:t.left>=0&&t.left+e.width<=window.innerWidth}(i,t,n)&&function(t,e){return"top"===e||"bottom"===e?t.width+8<=window.innerWidth:t.height+8<=window.innerHeight}(t,n)?function(t,e,n){let{top:i,left:o}=t,s=null;if("top"===n||"bottom"===n){const t=4,n=window.innerWidth-e.width-4;n>=t&&(o<t?(s=o-t,o=t):o>n&&(s=o-n,o=n))}else{const t=4,n=window.innerHeight-e.height-4;n>=t&&(i<t?(s=i-t,i=t):i>n&&(s=i-n,i=n))}if(null!==s){const t=("top"===n||"bottom"===n?e.width/2:e.height/2)-16-4;Math.abs(s)>t&&(s=s>0?t:-t)}return{top:i,left:o,position:n,arrowOffset:s}}(i,t,n):null}function gt(t,e,n){const i=pt(t,e,n);if(i)return i;for(const i of rt[n]){const n=pt(t,e,i);if(n)return n}return null}function mt(t){const e=[];let n=t.parentElement;for(;n;){const t=getComputedStyle(n),i=t.overflow+t.overflowX+t.overflowY;lt.test(i)&&e.push(n),n=n.parentElement}return e}function ht(t){return"system"===t||"auto"===t?"normal":"light only"}function ft(t){if(!t||"default"===t)return"light";if("system"===t)return;const e=function(){const t=getComputedStyle(document.documentElement).colorScheme;if(t&&"normal"!==t)return t;if(document.body){const t=getComputedStyle(document.body).colorScheme;if(t&&"normal"!==t)return t}}();return e?function(t){const e=t.includes("dark"),n=t.includes("light");if(!e||!n)return e?"dark":n?"light":void 0}(e):void 0}let bt,yt=null;function vt(){yt||(bt=ft(ui.config?.colorScheme),yt=new MutationObserver(()=>{const t=ft(ui.config?.colorScheme);t!==bt&&(bt=t,wt(t))}),yt.observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]}),document.body&&yt.observe(document.body,{attributes:!0,attributeFilter:["style","class"]}))}function wt(t){const e=t??"normal",n=ht(ui.config?.colorScheme);for(const t of ui.currentMessages??[]){const i=Dt(t.instanceId??""),o=document.getElementById(i);o&&(o.style.colorScheme=n,o.contentWindow&&o.contentWindow.postMessage({action:"updateColorScheme",colorScheme:e},"*"))}ui.events?.dispatch("colorSchemeChanged",t)}function xt(t){const e=P(t);e&&(e.classList.remove("gist-visible"),Array.from(e.classList).filter(t=>t.startsWith("gist-")).forEach(t=>e.classList.remove(t)),e.style.removeProperty("height"),e.style.removeProperty("width"),e.innerHTML="")}function St(t){const e=P(t);if(e)return!(!e.style||!e.style.height||"0px"===e.style.height)}function It(t,e,n=null){const i=document.getElementById(t);i&&(i.onload=()=>{!function(t,e,n=null){const i=document.getElementById(t);if(i?.contentWindow){n&&(e.stepId=n);const t=ft(ui.config?.colorScheme);t&&(e.colorScheme=t);const o={options:e,capabilities:Ct};i.contentWindow.postMessage(o,"*")}}(t,e,n)})}const Ct=["MultiStepDisplayTypes"];function $t(t){if(!t.displaySettings)return;const e=Dt(t.instanceId??""),n=document.getElementById(e);n?.contentWindow&&n.contentWindow.postMessage({action:"updateDisplaySettings",displaySettings:t.displaySettings},"*")}let kt=null;function Et(){kt&&(document.removeEventListener("keydown",kt),kt=null)}async function jt(){const t=document.querySelector(".gist-message");t&&(t.classList.remove("gist-visible"),await new Promise(t=>setTimeout(t,300))),Lt()}function Lt(){Et();const t=document.querySelector("#gist-embed-message");t&&t.parentNode?.removeChild(t)}const Tt=new Map;function Pt(t){const e=t.instanceId??"",n=Tt.get(e);n&&(n.cleanup(),Tt.delete(e));const i=P(`gist-tooltip-${e}`);i&&i.parentNode?.removeChild(i)}function Dt(t){return`gist-${t}`}function Nt(){const t=document.querySelector(".gist-message");t&&t.classList.add("gist-visible")}const Mt="jist",At={start:"flex-start",end:"flex-end",center:"center",stretch:"stretch",baseline:"baseline"},Rt={start:"flex-start",end:"flex-end",center:"center","space-between":"space-between","space-around":"space-around","space-evenly":"space-evenly"};function qt(t){return"number"==typeof t?`${t}px`:"fill"===t?"100%":t}function zt(t){try{return new Date(t).toLocaleDateString(navigator.language)}catch{return t}}class Wt{#t;#e;#n;#i=0;constructor({formatDate:t,onAction:e,templates:n}={}){this.#t=t||zt,this.#e=e||null,this.#n=n||{}}render(t,e){if(!t)return null;switch(t.type){case"layout":return this.#o(t,e);case"action":return this.#s(t,e);case"heading":return this.#a(t,e);case"text":return this.#r("p",t,e);case"date":return this.#l(t,e);case"button":return this.#c(t,e);case"image":return this.#d(t,e);case"dynamicLayout":return this.#u(t,e);case"template":return this.#p(t,e);default:return null}}#o(t,e){const n=document.createElement("div");n.style.display="flex",n.style.flexDirection="horizontal"===t.direction?"row":"column",t.gap&&(n.style.gap=qt(t.gap)),t.align&&(n.style.alignItems=At[t.align]||t.align),t.justify&&(n.style.justifyContent=Rt[t.justify]||t.justify),t.margin&&(t.margin.top&&(n.style.marginTop=qt(t.margin.top)),t.margin.right&&(n.style.marginRight=qt(t.margin.right)),t.margin.bottom&&(n.style.marginBottom=qt(t.margin.bottom)),t.margin.left&&(n.style.marginLeft=qt(t.margin.left)));const i="horizontal"===t.direction,o=i&&(!t.justify||"start"===t.justify),s=i||"center"!==t.align?i||"end"!==t.align?"":"right":"center";for(const i of t.children||[]){const t=this.render(i,e);t&&(o&&"layout"===i.type&&(t.style.flex="1",t.style.minWidth="0"),s&&(t.style.textAlign=s),n.appendChild(t))}return n}#s(t,e){const n=t.name||"action",i=document.createElement("div");this.#g(i,"action",n),i.setAttribute("role","button"),i.setAttribute("tabindex","0");for(const n of t.children||[]){const t=this.render(n,e);t&&i.appendChild(t)}const o=e[n],s=t.meta||null;if(this.#e){const t=this.#e,e=e=>{e.stopPropagation(),t({component:"action",name:n,data:o,meta:s,event:e})};i.addEventListener("click",e),i.addEventListener("keydown",t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),e(t))})}return i}#a(t,e){const n=t.variant||"h3";return this.#r(n,t,e,n)}#r(t,e,n,i){const o=e.name||e.type,s=document.createElement(t);return this.#g(s,e.type,o,i||e.variant),s.textContent=n[o]||"",s}#l(t,e){const n=t.name||"date",i=document.createElement("time");this.#g(i,"date",n,t.variant);const o=e[n];return i.textContent=o?this.#t(o,n):"",i}#c(t,e){const n=t.name||"button",i=e[n];if(!i)return null;const o=document.createElement("button");this.#g(o,"button",n,t.variant),o.textContent=i.label,i.disabled&&(o.disabled=!0);const s=t.meta||null;return o.addEventListener("click",t=>{t.stopPropagation(),this.#e&&this.#e({component:"button",name:n,data:i,meta:s,event:t})}),o}#d(t,e){const n=t.name||"image",i=e[n];if(!i)return null;const o=document.createElement("div");this.#g(o,"image",n,t.variant),o.style.overflow="hidden";const s=document.createElement("img");return s.src=i,s.alt=e.title||"",s.style.display="block",t.width&&(s.style.width=qt(t.width)),t.height&&(s.style.height=qt(t.height)),t.objectFit&&(s.style.objectFit=t.objectFit),t.borderRadius&&(s.style.borderRadius=qt(t.borderRadius)),o.appendChild(s),o}#u(t,e){const n=e[t.name];if(!Array.isArray(n))return null;const i=document.createElement("div"),o=t.direction||"vertical";i.style.display="flex",i.style.flexDirection="horizontal"===o?"row":"column",t.gap&&(i.style.gap=qt(t.gap)),t.align&&(i.style.alignItems=At[t.align]||t.align),t.justify&&(i.style.justifyContent=Rt[t.justify]||t.justify),t.margin&&(t.margin.top&&(i.style.marginTop=qt(t.margin.top)),t.margin.right&&(i.style.marginRight=qt(t.margin.right)),t.margin.bottom&&(i.style.marginBottom=qt(t.margin.bottom)),t.margin.left&&(i.style.marginLeft=qt(t.margin.left)));for(const e of n){const n="object"==typeof e&&null!==e?e:{},o=this.render(t.template,n);o&&i.appendChild(o)}return i}#p(t,e){const n=this.#n[t.name];if(!n||this.#i>=10)return null;this.#i++;const i=this.render(n.root,e);return this.#i--,i}#g(t,e,n,i){t.classList.add(`${Mt}__${e}`),i&&t.classList.add(`${Mt}__${e}--${i}`),n!==e&&t.classList.add(`${Mt}__${n}`)}}var _t;const Ot=new Set(["fontWeight","maxLines","lineHeight","opacity"]),Bt=new Set(["lineHeight","letterSpacing"]),Ut={"text-font-size":"font-size","text-font-weight":"font-weight","text-font-family":"font-family","text-color":"color","text-line-height":"line-height","text-letter-spacing":"letter-spacing","text-max-lines":"-webkit-line-clamp","background-color":"background-color","border-width":"border-width","border-color":"border-color","border-radius":"border-radius","padding-top":"padding-top","padding-right":"padding-right","padding-bottom":"padding-bottom","padding-left":"padding-left","margin-top":"margin-top","margin-right":"margin-right","margin-bottom":"margin-bottom","margin-left":"margin-left","min-width":"min-width","min-height":"min-height"},Ht=["shadow-offset-x","shadow-offset-y","shadow-blur","shadow-color"],Ft={"shadow-offset-x":"0","shadow-offset-y":"0","shadow-blur":"0","shadow-color":"transparent"},Vt={heading:new Set(["text","padding","margin"]),text:new Set(["text","padding","margin"]),date:new Set(["text","padding","margin"]),button:new Set(["text","background","border","shadow","padding","margin","minWidth","minHeight","states"]),image:new Set(["border","padding","margin"])},Gt=["hover","active","disabled"],Xt=[["background-color","background-color"],["color","text-color"]];class Jt extends HTMLElement{static observedAttributes=["template","data","theme","mode"];static#m=!1;static#h=null;static#f=0;static#b=new Map;static#y(){if(_t.#m)return;if(_t.#m=!0,document.querySelector("style[data-jist-base]"))return;const t=document.createElement("style");t.setAttribute("data-jist-base",""),t.textContent="/* ═══════════════════════════════════════════\n Jist Template Styles\n ═══════════════════════════════════════════ */\n\n/* ── Host Element ───────────────────────── */\n\njist-template {\n display: block;\n}\n\n/* ── Base Reset ─────────────────────────── */\n\n.jist__heading,\n.jist__text,\n.jist__date {\n margin: 0;\n padding: 0;\n}\n\n/* ── Heading ────────────────────────────── */\n\n.jist__heading {\n font-size: var(--jist-heading-text-font-size, 16px);\n font-weight: var(--jist-heading-text-font-weight, 600);\n color: var(--jist-heading-text-color, #000000);\n font-family: var(--jist-heading-text-font-family, inherit);\n line-height: var(--jist-heading-text-line-height, 1.3);\n letter-spacing: var(--jist-heading-text-letter-spacing, normal);\n padding-top: var(--jist-heading-padding-top, 0);\n padding-right: var(--jist-heading-padding-right, 0);\n padding-bottom: var(--jist-heading-padding-bottom, 0);\n padding-left: var(--jist-heading-padding-left, 0);\n margin-top: var(--jist-heading-margin-top, 0);\n margin-right: var(--jist-heading-margin-right, 0);\n margin-bottom: var(--jist-heading-margin-bottom, 0);\n margin-left: var(--jist-heading-margin-left, 0);\n /* Line clamping — active when --jist-heading-text-max-lines is set */\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: var(--jist-heading-text-max-lines, none);\n overflow: hidden;\n}\n\n/* ── Text ───────────────────────────────── */\n\n.jist__text {\n font-size: var(--jist-text-text-font-size, 14px);\n font-weight: var(--jist-text-text-font-weight, 400);\n color: var(--jist-text-text-color, #000000);\n font-family: var(--jist-text-text-font-family, inherit);\n line-height: var(--jist-text-text-line-height, 1.5);\n letter-spacing: var(--jist-text-text-letter-spacing, normal);\n padding-top: var(--jist-text-padding-top, 0);\n padding-right: var(--jist-text-padding-right, 0);\n padding-bottom: var(--jist-text-padding-bottom, 0);\n padding-left: var(--jist-text-padding-left, 0);\n margin-top: var(--jist-text-margin-top, 0);\n margin-right: var(--jist-text-margin-right, 0);\n margin-bottom: var(--jist-text-margin-bottom, 0);\n margin-left: var(--jist-text-margin-left, 0);\n /* Line clamping — active when --jist-text-text-max-lines is set */\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: var(--jist-text-text-max-lines, none);\n overflow: hidden;\n}\n\n/* ── Date ───────────────────────────────── */\n\n.jist__date {\n font-size: var(--jist-date-text-font-size, 12px);\n font-weight: var(--jist-date-text-font-weight, 400);\n color: var(--jist-date-text-color, #000000);\n font-family: var(--jist-date-text-font-family, inherit);\n line-height: var(--jist-date-text-line-height, 1.4);\n letter-spacing: var(--jist-date-text-letter-spacing, normal);\n padding-top: var(--jist-date-padding-top, 0);\n padding-right: var(--jist-date-padding-right, 0);\n padding-bottom: var(--jist-date-padding-bottom, 0);\n padding-left: var(--jist-date-padding-left, 0);\n margin-top: var(--jist-date-margin-top, 0);\n margin-right: var(--jist-date-margin-right, 0);\n margin-bottom: var(--jist-date-margin-bottom, 0);\n margin-left: var(--jist-date-margin-left, 0);\n}\n\n/* ── Button ─────────────────────────────── */\n\n.jist__button {\n appearance: none;\n -webkit-appearance: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n border: none;\n font-size: var(--jist-button-text-font-size, 14px);\n font-weight: var(--jist-button-text-font-weight, 500);\n color: var(--jist-button-text-color, #ffffff);\n font-family: var(--jist-button-text-font-family, inherit);\n line-height: var(--jist-button-text-line-height, 1);\n background-color: var(--jist-button-background-color, #4f46e5);\n border-width: var(--jist-button-border-width, 0);\n border-style: solid;\n border-color: var(--jist-button-border-color, transparent);\n border-radius: var(--jist-button-border-radius, 6px);\n box-shadow:\n var(--jist-button-shadow-offset-x, 0)\n var(--jist-button-shadow-offset-y, 0)\n var(--jist-button-shadow-blur, 0)\n var(--jist-button-shadow-color, transparent);\n padding-top: var(--jist-button-padding-top, 8px);\n padding-right: var(--jist-button-padding-right, 16px);\n padding-bottom: var(--jist-button-padding-bottom, 8px);\n padding-left: var(--jist-button-padding-left, 16px);\n margin-top: var(--jist-button-margin-top, 0);\n margin-right: var(--jist-button-margin-right, 0);\n margin-bottom: var(--jist-button-margin-bottom, 0);\n margin-left: var(--jist-button-margin-left, 0);\n min-width: var(--jist-button-min-width, 0);\n min-height: var(--jist-button-min-height, 0);\n transition: background-color 0.15s ease, color 0.15s ease,\n border-color 0.15s ease, box-shadow 0.15s ease;\n}\n\n.jist__button:hover {\n background-color: var(--jist-button-states-hover-background-color,\n var(--jist-button-background-color, #4338ca));\n color: var(--jist-button-states-hover-text-color,\n var(--jist-button-text-color, #ffffff));\n}\n\n.jist__button:active {\n background-color: var(--jist-button-states-active-background-color,\n var(--jist-button-background-color, #3730a3));\n color: var(--jist-button-states-active-text-color,\n var(--jist-button-text-color, #ffffff));\n}\n\n.jist__button:disabled {\n background-color: var(--jist-button-states-disabled-background-color,\n var(--jist-button-background-color, #c7d2fe));\n color: var(--jist-button-states-disabled-text-color,\n var(--jist-button-text-color, #a5b4fc));\n cursor: not-allowed;\n}\n\n/* ── Image ──────────────────────────────── */\n\n.jist__image {\n display: block;\n max-width: 100%;\n overflow: hidden;\n border-radius: var(--jist-image-border-radius, 0);\n padding-top: var(--jist-image-padding-top, 0);\n padding-right: var(--jist-image-padding-right, 0);\n padding-bottom: var(--jist-image-padding-bottom, 0);\n padding-left: var(--jist-image-padding-left, 0);\n margin-top: var(--jist-image-margin-top, 0);\n margin-right: var(--jist-image-margin-right, 0);\n margin-bottom: var(--jist-image-margin-bottom, 0);\n margin-left: var(--jist-image-margin-left, 0);\n}\n\n.jist__image img {\n border-radius: inherit;\n}\n\n/* ── Dark Mode Defaults ────────────────── */\n\n[data-jist-dark] .jist__heading { color: var(--jist-heading-text-color, #ffffff); }\n[data-jist-dark] .jist__text { color: var(--jist-text-text-color, #ffffff); }\n[data-jist-dark] .jist__date { color: var(--jist-date-text-color, #ffffff); }\n[data-jist-dark] .jist__button { color: var(--jist-button-text-color, #ffffff); }\n\n/* ── Action (clickable wrapper) ─────────── */\n\n.jist__action {\n cursor: pointer;\n -webkit-tap-highlight-color: transparent;\n}\n\n.jist__action:focus-visible {\n outline: 2px solid var(--jist-button-background-color, #4f46e5);\n outline-offset: 2px;\n border-radius: 4px;\n}\n",document.head.appendChild(t)}#v=null;#w=null;#x=null;#S=null;#I="auto";#t=null;#e=null;#n={};#C=null;#$=null;get template(){return this.#w}set template(t){this.#w=t,this.#k()}get data(){return this.#x}set data(t){this.#x="string"==typeof t?JSON.parse(t):t,this.#k()}get theme(){return this.#S}set theme(t){this.#S="string"==typeof t?JSON.parse(t):t,this.#E(),this.#k()}get mode(){return this.#I}set mode(t){this.#I=t||"auto",this.#E()}get formatDate(){return this.#t}set formatDate(t){this.#t=t,this.#k()}get onAction(){return this.#e}set onAction(t){this.#e=t}get templates(){return this.#n}set templates(t){const e="string"==typeof t?JSON.parse(t):t||{},n={};for(const[t,i]of Object.entries(e)){if(t.startsWith("$"))continue;if(!Array.isArray(i))continue;const e=i.find(t=>"1"===t.version);e&&(n[t]=e)}this.#n=n,this.#k()}connectedCallback(){_t.#y(),this.#C=window.matchMedia("(prefers-color-scheme: dark)"),this.#$=()=>{"auto"===this.#I&&(this.#E(),this.#k())},this.#C.addEventListener("change",this.#$),this.#E(),this.#k()}disconnectedCallback(){this.#C&&this.#$&&this.#C.removeEventListener("change",this.#$),this.#j(),_t.#L()}attributeChangedCallback(t,e,n){if(e!==n)switch(t){case"template":this.#w=n||null,this.#k();break;case"data":this.#x=n?JSON.parse(n):null,this.#k();break;case"theme":this.#S=n?JSON.parse(n):null,this.#E(),this.#k();break;case"mode":this.#I=n||"auto",this.#E(),this.#k()}}#T(){return"dark"===this.#I||"light"!==this.#I&&(this.#C?.matches??!1)}#E(){if(!this.isConnected)return void(this.#S||(this.#j(),_t.#L()));if(this.#T()?this.setAttribute("data-jist-dark",""):this.removeAttribute("data-jist-dark"),!this.#S)return this.#j(),void _t.#L();const t=[];for(let e=0;e<this.style.length;e++)this.style[e].startsWith("--jist-")&&t.push(this.style[e]);if(t.forEach(t=>this.style.removeProperty(t)),this.#P(this.#S,"--jist"),this.#T()){const t=this.#S.modes?.dark;t&&this.#P(t,"--jist")}this.#D()}#P(t,e){for(const[n,i]of Object.entries(t)){if("modes"===n||n.startsWith("$"))continue;const t=`${e}-${n.replace(/([A-Z])/g,"-$1").toLowerCase()}`;if(null===i||"object"!=typeof i||Array.isArray(i)){if(null!=i&&""!==i){const e=0===i&&Bt.has(n)?"normal":"number"!=typeof i||Ot.has(n)?String(i):`${i}px`;this.style.setProperty(t,e)}}else this.#P(i,t)}}#D(){const t=[],e=this.#S;if(!e)return;const n=e.modes?.dark;for(const i of Object.keys(Vt)){const o=e[i],s=n?.[i],a=Vt[i],r=new Set;for(const t of[o,s])if(t)for(const e of Object.keys(t))a.has(e)||e.startsWith("$")||r.add(e);for(const e of r){const n=o?.[e]??{},a=s?.[e]??{};t.push(this.#N(i,e,n,a))}}const i=t.join("\n");if(this.#j(),!i)return;let o=_t.#b.get(i);o||(o={id:_t.#f++,refs:0},_t.#b.set(i,o)),o.refs++,this.#v=i,this.setAttribute("data-jist-v",String(o.id)),_t.#L()}#j(){if(!this.#v)return;const t=_t.#b.get(this.#v);t&&(t.refs--,t.refs<=0&&_t.#b.delete(this.#v)),this.#v=null,this.removeAttribute("data-jist-v")}static#L(){if(0===_t.#b.size)return void(_t.#h&&(_t.#h.remove(),_t.#h=null));_t.#h||(_t.#h=document.createElement("style"),_t.#h.setAttribute("data-jist-variants",""),document.head.appendChild(_t.#h));const t=[];for(const[e,{id:n}]of _t.#b){const i=`[data-jist-v="${n}"]`;t.push(e.replace(/^(\.[a-z_-]+)/gm,`${i} $1`))}_t.#h.textContent=t.join("\n")}#N(t,e,n,i){const o=e.replace(/([A-Z])/g,"-$1").toLowerCase(),s=`.jist__${t}--${o}`,a=new Set,r=(t,e)=>{for(const[n,i]of Object.entries(t)){if("states"===n||n.startsWith("$"))continue;const t=n.replace(/([A-Z])/g,"-$1").toLowerCase(),o=e?`${e}-${t}`:t;null===i||"object"!=typeof i||Array.isArray(i)?a.add(o):r(i,o)}};r(n,""),r(i,"");const l=[];for(const e of a){const n=Ut[e];if(!n)continue;const i=`--jist-${t}-${o}-${e}`,s=`--jist-${t}-${e}`;l.push(` ${n}: var(${i}, var(${s}));`)}if("button"===t&&[...a].some(t=>t.startsWith("shadow-"))){const t=Ht.map(t=>`var(--jist-button-${o}-${t}, var(--jist-button-${t}, ${Ft[t]}))`);l.push(` box-shadow: ${t.join(" ")};`)}let c=`${s} {\n${l.join("\n")}\n}`;if("button"===t&&(n.states||i.states))for(const t of Gt){const e=n.states?.[t],a=i.states?.[t];if(!e&&!a)continue;const r=[];for(const[e,n]of Xt){const i=`--jist-button-${o}-states-${t}-${n}`,s=`--jist-button-states-${t}-${n}`,a=`--jist-button-${o}-${n}`,l=`--jist-button-${n}`;r.push(` ${e}: var(${i}, var(${s}, var(${a}, var(${l}))));`)}c+=`\n${s}${"disabled"===t?":disabled":`:${t}`} {\n${r.join("\n")}\n}`}return c}#k(){if(!this.#w||!this.#x)return;if(!this.isConnected)return;const t=this.#n[this.#w];if(!t)return void(this.innerHTML="");const e=new Wt({formatDate:this.#t||void 0,templates:this.#n,onAction:t=>{this.#e&&this.#e(t),this.dispatchEvent(new CustomEvent("jist-action",{bubbles:!0,detail:{component:t.component,name:t.name,data:t.data,meta:t.meta}}))}});this.innerHTML="";const n=e.render(t.root,this.#x);n&&this.appendChild(n)}}_t=Jt,customElements.define("jist-template",Jt);const Qt=Jt,Yt="gist-inbox-button",Kt="gist-inbox-badge",Zt="gist-inbox-panel",te="gist-inbox-messages";let ee=!1,ne=!1;const ie=new Set;let oe=null,se=null;function ae(t,e){const n={...t},i=e;for(const t of Object.keys(i)){const e=n[t],o=i[t];null==e||"object"!=typeof e||Array.isArray(e)||null==o||"object"!=typeof o||Array.isArray(o)?void 0!==o&&(n[t]=o):n[t]=ae(e,o)}return n}function re(t,e){const n=t?.patterns?.inbox;if(!n)return null;const i=t?.patterns?.modes?.dark?.inbox;return("dark"===e||null==e&&oe?.matches)&&i?ae(n,i):n}function le(){ee||(ee=!0,customElements.get("jist-template")||customElements.define("jist-template",Qt),N("gist-inbox-styles",'\n#gist-inbox-button {\n position: fixed;\n width: 56px;\n height: 56px;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n z-index: 9998;\n border: none;\n transition: background-color 0.2s ease,\n box-shadow 0.2s ease,\n transform 0.15s ease;\n}\n#gist-inbox-button:hover {\n transform: scale(1.05);\n}\n#gist-inbox-button:active {\n transform: scale(0.93);\n}\n#gist-inbox-button svg {\n width: 24px;\n height: 24px;\n}\n#gist-inbox-button svg [fill]:not([fill="none"]) {\n fill: currentColor;\n}\n#gist-inbox-badge {\n position: absolute;\n top: -4px;\n right: -4px;\n min-width: 20px;\n height: 20px;\n border-radius: 10px;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 0 6px;\n box-sizing: border-box;\n}\n#gist-inbox-panel {\n position: fixed;\n width: 400px;\n max-height: 600px;\n z-index: 9999;\n overflow: hidden;\n display: flex;\n flex-direction: column;\n user-select: none;\n -webkit-user-select: none;\n transform: translateY(8px) scale(0.96);\n opacity: 0;\n pointer-events: none;\n transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),\n opacity 0.2s ease;\n}\n#gist-inbox-panel.gist-inbox-panel--open {\n transform: translateY(0) scale(1);\n opacity: 1;\n pointer-events: auto;\n}\n#gist-inbox-messages {\n overflow-y: auto;\n flex: 1;\n}\n.gist-inbox-message-row {\n transition: background-color 0.15s ease;\n}\n@media (max-width: 424px) {\n #gist-inbox-panel {\n width: auto !important;\n left: 12px !important;\n right: 12px !important;\n }\n}\n'),ui.events.on("messageInboxUpdated",t=>{ce(t)}),ui.events.on("colorSchemeChanged",()=>{ce()}),oe=window.matchMedia("(prefers-color-scheme: dark)"),se=()=>{"system"===ui.config?.colorScheme&&ce()},oe.addEventListener("change",se),ce())}async function ce(t){t||(t=await W());const e=function(t){return t.filter(t=>t.topics?.some(t=>t.startsWith("cio_inbox"))).sort((t,e)=>{const n=(t.priority??Number.MAX_SAFE_INTEGER)-(e.priority??Number.MAX_SAFE_INTEGER);return 0!==n?n:new Date(e.sentAt??0).getTime()-new Date(t.sentAt??0).getTime()})}(t);if(0===e.length)return void de();let n=E();n||(await fe(),n=E());const o=ft(ui.config?.colorScheme),s=re(n,o);if(s){if(function(t,e){let n=document.getElementById(Yt);n||(n=D("div",{id:Yt}),n.addEventListener("click",()=>{ne?(ne=!1,document.getElementById(Zt)?.classList.remove("gist-inbox-panel--open")):(ne=!0,ce())}),M(n));const i=he(t.position);n.style.background=t.floatingIcon.background,n.style.color=t.floatingIcon.color,n.style.boxShadow="0 2px 8px rgba(0,0,0,0.15)",Object.assign(n.style,i),n.querySelector("svg")||n.insertAdjacentHTML("afterbegin",t.floatingIcon.svg);!function(t,e,n){let i=document.getElementById(Kt);if(0===n||!e.unreadIndicator.showAlert)return void i?.remove();i||(i=D("span",{id:Kt}),t.appendChild(i));const o=e.unreadIndicator;i.textContent=String(n),i.style.background=o.background,i.style.color=o.text.color,i.style.fontSize=`${o.text.fontSize}px`,i.style.fontWeight=String(o.text.fontWeight),i.style.fontFamily=o.text.fontFamily,i.style.lineHeight=String(o.text.lineHeight)}(n,t,e.filter(t=>!t.opened).length)}(s,e),ne){!function(t,e,n,o){let s=document.getElementById(Zt);const a=!s;a&&(s=D("div",{id:Zt}),M(s));const r=he(t.position,!0);s.style.background=t.background,s.style.borderRadius=`${t.cornerRadius}px`,s.style.border=`1px solid ${t.borderColor}`,s.style.boxShadow=`${t.shadow.offsetX}px ${t.shadow.offsetY}px ${t.shadow.blur}px ${t.shadow.color}`,Object.assign(s.style,r);let l=document.getElementById(te);l||(l=D("div",{id:te}),s.appendChild(l)),l.innerHTML="";const c=T();e.forEach((s,a)=>{const r=D("div",{className:"gist-inbox-message-row"});r.style.padding="12px 16px",r.style.cursor="pointer",r.addEventListener("mouseenter",()=>{r.style.background=t.hoverBackground}),r.addEventListener("mouseleave",()=>{r.style.background=""});const d=document.createElement("jist-template");r.appendChild(d),l.appendChild(r);const u=d;if(u.onAction=t=>{i(`Inbox action: ${t.name}`);const e=function(t){if(!t||"object"!=typeof t)return null;const e=t;return"string"==typeof e.behavior&&["openUrl","dismiss","openDeeplink","performAction"].includes(e.behavior)?{behavior:e.behavior,action:"string"==typeof e.action?e.action:void 0,name:"string"==typeof e.name?e.name:void 0,dismiss:"boolean"==typeof e.dismiss?e.dismiss:void 0,newTab:"boolean"==typeof e.newTab?e.newTab:void 0}:null}(t.data);e&&function(t,e){"openUrl"!==e.behavior&&"openDeeplink"!==e.behavior||!e.action||(function(t){try{return"javascript:"!==new URL(t,window.location.href).protocol}catch{return!1}}(e.action)?e.newTab?window.open(e.action,"_blank","noopener"):window.location.href=e.action:i(`Blocked unsafe URL: ${e.action}`)),("dismiss"===e.behavior||e.dismiss)&&t.queueId&&O(t.queueId),ui.events.dispatch("inboxMessageAction",{message:t,action:"clicked",actionConfig:e})}(s,e)},c&&(u.templates=c),n?.theme&&(u.theme=n.theme),u.mode=o,u.formatDate=me,u.data=s.properties??{},u.template=s.type??null,a<e.length-1){const e=D("div",{className:"gist-inbox-divider"});e.style.height="1px",e.style.background=t.dividerColor,e.style.margin="0",l.appendChild(e)}}),a?requestAnimationFrame(()=>{s.classList.add("gist-inbox-panel--open")}):s.classList.add("gist-inbox-panel--open")}(s,e,n,o??"auto");for(const t of e){const e=t.queueId;t.opened||!e||ie.has(e)||(ie.add(e),_(e,!0).finally(()=>{ie.delete(e)}))}}}else de()}function de(){document.getElementById(Yt)?.remove(),document.getElementById(Zt)?.remove(),ne=!1}const ue=[[60,"second",1],[3600,"minute",60],[86400,"hour",3600],[2592e3,"day",86400],[31536e3,"month",2592e3],[1/0,"year",31536e3]];let pe=null,ge=null;function me(t){const e=Math.round((Date.now()-new Date(t).getTime())/1e3);if(Number.isNaN(e))return t;const[,n,i]=ue.find(([t])=>Math.abs(e)<t);return function(){const t=C();return pe&&ge===t||(ge=t,pe=new Intl.RelativeTimeFormat(t,{numeric:"auto"})),pe}().format(-Math.round(e/i),n)}function he(t,e=!1){const n=e?"":"24px",i="96px";switch(t){case"bottom-left":return e?{bottom:i,left:"24px",right:"",top:""}:{bottom:n,left:n,right:"",top:""};case"top-right":return e?{top:i,right:"24px",bottom:"",left:""}:{top:n,right:n,bottom:"",left:""};case"top-left":return e?{top:i,left:"24px",bottom:"",right:""}:{top:n,left:n,bottom:"",right:""};default:return e?{bottom:i,right:"24px",left:"",top:""}:{bottom:n,right:n,left:"",top:""}}}async function fe(){await Promise.all([k(),L()])}let be=600,ye=!1;const ve="gist.web.userQueueNextPullCheck",we="gist.web.sessionId";function xe(){let t=a(we);return t||(t=g()),s(we,t,new Date((new Date).getTime()+18e5)),String(t)}const Se="gist.web.userToken",Ie="gist.web.usingGuestUserToken",Ce="gist.web.guestUserToken";function $e(){return null!==a(Ie)}function ke(){return a(Se)}function Ee(){if(null===ke()){let t=a(Ce);null==t&&(t=g(),s(Ce,t),i(`Set guest user token "${t}" with expiry date set to 1 year from today`)),s(Se,t),s(Ie,!0),i(`Using anonymous session with token: "${t}"`)}}async function je(){const t=ke();return null===t?null:await async function(t){const e=(new TextEncoder).encode(t),n=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(n)).map(t=>t.toString(16).padStart(2,"0")).join("")}(t)}function Le(){const t=ke();return null===t?null:btoa(t)}function Te(){r(Se),i("Cleared user token")}const Pe="gist.web.customAttributes";let De=new Map;function Ne(){const t=Array.from(De.entries()),e=new Date;e.setDate(e.getDate()+30),s(Pe,t,e),i(`Saved ${De.size} custom attributes to storage with TTL of 30 days`)}async function Me(t){const e=await We();if(!e)return;const n=new Date;n.setMinutes(n.getMinutes()+60),s(e,t.filter(qe),n)}async function Ae(){const t=await We();return t?(a(t)??[]).filter(e=>{const n=e.properties.gist.broadcast,{frequency:i}=n,o=a(Oe(t,e.queueId))??!0,s=a(_e(t,e.queueId))||0,r=0===i.count;return o&&(r||s<i.count)}):[]}async function Re(t,e){const n=a(t);return n?.find(t=>t.queueId===e)}function qe(t){return!(!t.properties?.gist||!t.properties.gist.broadcast)}function ze(t){if(!qe(t))return!1;const e=t.properties.gist.broadcast;return 0===e.frequency.delay&&0===e.frequency.count}async function We(){const t=await je();return t?`gist.web.message.broadcasts.${t}`:null}function _e(t,e){return`${t}.${e}.numberOfTimesShown`}function Oe(t,e){return`${t}.${e}.shouldShow`}!function(){const t=a(Pe);if(t)try{De=new Map(t)}catch{De=new Map}else De=new Map}();const Be="gist.web.message.user";async function Ue(t){const e=await Fe();if(!e)return;const n=t.filter(t=>!(t.properties&&t.properties.gist&&t.properties.gist.broadcast)),i=new Date;i.setMinutes(i.getMinutes()+60),s(e,n,i)}async function He(){const t=await Fe();if(!t)return[];const e=a(t)??[],n=await async function(){const t=await Ve();return t?a(t)??[]:[]}();return e.filter(t=>!n.includes(t.queueId??""))}async function Fe(){const t=await je();return t?`${Be}.${t}`:null}async function Ve(){const t=await je();return t?`${Be}.${t}.seen`:null}async function Ge(t){const e=await je();return e?`${Be}.${e}.message.${t}.loading`:null}async function Xe(t){const e=await je();return e?`${Be}.${e}.message.${t}.state`:null}async function Je(t){const e=await Xe(t);e&&(r(e),i(`Cleared message state for queueId: ${t}`))}function Qe(t){return`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.54223 5.33301L7.7089 9.33301L11.8756 5.33301L12.6121 6.04011L7.7089 10.7472L2.80566 6.04011L3.54223 5.33301Z" fill="${t}"/></svg>`}const Ye=`\n #gist-preview-bar {\n position: fixed; bottom: 0; left: 0; right: 0;\n z-index: 99999999999;\n font-family: system-ui, -apple-system, sans-serif;\n pointer-events: none;\n }\n .gist-pb-toggle-row {\n display: flex; justify-content: center;\n padding: 6px 16px;\n border-bottom: 1px solid #e5e7eb;\n }\n .gist-pb-toggle-row--collapsed { border-bottom: none; }\n .gist-pb-toggle-btn {\n background: #08272B; border: none;\n padding: 4px 14px;\n border-radius: 100px;\n font-size: 12px; font-weight: 500;\n font-family: system-ui, -apple-system, sans-serif;\n color: white; cursor: pointer;\n display: flex; align-items: center; gap: 6px;\n pointer-events: auto;\n height: auto; min-width: auto;\n box-sizing: border-box;\n line-height: normal;\n -webkit-appearance: none;\n appearance: none;\n }\n .gist-pb-controls-row {\n background: #F8F9F9;\n box-shadow: 1px 2px 2px #34344605, 3px 3px 8px #34344614;\n display: flex; flex-wrap: wrap; align-items: center;\n gap: 12px; padding: 10px 16px 12px;\n pointer-events: auto;\n }\n .gist-pb-label-group { display: flex; flex-direction: column; gap: 4px; }\n .gist-pb-label-group--grow { flex: 1; }\n .gist-pb-label {\n font-size: 10px; font-weight: 600; color: #3F4E50;\n letter-spacing: 0.05em; text-transform: uppercase;\n font-family: system-ui, -apple-system, sans-serif;\n }\n .gist-pb-select {\n height: 32px; padding: 0 32px 0 8px;\n border: 1px solid #d1d5db; border-radius: 6px;\n font-size: 13px; font-family: system-ui, -apple-system, sans-serif;\n background: white ${`url("data:image/svg+xml,${encodeURIComponent(Qe("#3F4E50"))}")`} no-repeat right 2px center;\n color: #3F4E50; cursor: pointer; outline: none;\n appearance: none; min-width: 120px;\n }\n .gist-pb-input {\n height: 32px; padding: 0 8px;\n border: 1px solid #d1d5db; border-radius: 6px;\n font-size: 13px; font-family: system-ui, -apple-system, sans-serif;\n color: #3F4E50; outline: none; box-sizing: border-box;\n }\n .gist-pb-checkbox-row { display: flex; align-items: center; gap: 6px; height: 32px; }\n .gist-pb-checkbox-label {\n font-size: 12px; font-family: system-ui, -apple-system, sans-serif;\n color: #3F4E50; cursor: pointer; user-select: none;\n }\n .gist-pb-color-control {\n display: flex; align-items: center;\n border: 1px solid #d1d5db; border-radius: 6px;\n overflow: hidden; height: 32px; background: white;\n }\n .gist-pb-color-swatch {\n width: 28px; height: 100%;\n cursor: pointer; flex-shrink: 0;\n border-right: 1px solid #d1d5db; position: relative;\n }\n .gist-pb-color-input {\n position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none;\n }\n .gist-pb-color-hex {\n flex: 1; border: none; outline: none; padding: 0 6px;\n font-size: 13px; font-family: monospace; color: #3F4E50;\n min-width: 0; background: transparent;\n }\n .gist-pb-color-opacity {\n width: 36px; border: none; border-left: 1px solid #d1d5db;\n outline: none; padding: 0 4px;\n font-size: 13px; font-family: system-ui, -apple-system, sans-serif;\n color: #3F4E50; background: transparent; text-align: right;\n }\n .gist-pb-color-pct {\n font-size: 12px; color: #3F4E50; padding: 0 6px 0 2px;\n font-family: system-ui, -apple-system, sans-serif; flex-shrink: 0;\n }\n .gist-pb-input--invalid { border-color: #941616; outline: 1px solid #941616; }\n .gist-pb-inline-row { display: flex; align-items: center; gap: 6px; }\n .gist-pb-select-elem-btn, .gist-pb-cancel-btn {\n height: 32px; padding: 0 12px;\n border: none; border-radius: 6px;\n font-size: 12px; font-weight: 500; font-family: system-ui, -apple-system, sans-serif;\n background: #08272B; color: white; cursor: pointer; whit