customerio-gist-web 3.23.6 → 3.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gist.min.js +1 -1
- package/dist/types/managers/message-component-manager.d.ts +6 -0
- package/dist/types/managers/message-manager.d.ts +9 -0
- package/dist/types/managers/message-user-queue-manager.d.ts +2 -0
- package/dist/types/managers/preview-bar-manager.d.ts +8 -0
- package/dist/types/types.d.ts +5 -0
- package/dist/types/utilities/dom.d.ts +7 -0
- package/dist/types/utilities/message-utils.d.ts +8 -0
- package/dist/types/utilities/preview-mode.d.ts +9 -0
- package/package.json +1 -1
package/dist/gist.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!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:()=>Di});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){Pi.config&&Pi.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[Pi.config.env??"prod"],e={"X-CIO-Site-Id":Pi.config.siteId,"X-CIO-Client-Platform":"web"},n=Pe();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 P(){return a(j)}function T(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),Pi.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";Pi.events.dispatch(q,{message:r,action:t})}Pi.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&&Pi.events.dispatch(q,{message:o,action:"dismissed"}),Pi.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 Le();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 G=["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 V(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 Pi.currentMessages.find(e=>e.instanceId===t)}function K(t){return!!t&&Pi.currentMessages.some(e=>e.queueId===t)}function Q(t){return t?Pi.currentMessages.find(e=>e.elementId===t)??null:null}function Y(t){Pi.currentMessages=Pi.currentMessages.filter(e=>e.instanceId!==t)}function Z(t,e){Y(t),Pi.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!=Pi.currentRoute&&e.test(Pi.currentRoute),o=Pi.currentRoute!==n&&e.test(n);return i||o}catch{return!1}}function ot(t){return t.tooltipPosition?"tooltip":t.overlay?"modal":t.elementId&&G.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=T(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(Pi.config?.colorScheme),yt=new MutationObserver(()=>{const t=ft(Pi.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(Pi.config?.colorScheme);for(const t of Pi.currentMessages??[]){const i=Dt(t.instanceId??""),o=document.getElementById(i);o&&(o.style.colorScheme=n,o.contentWindow&&o.contentWindow.postMessage({action:"updateColorScheme",colorScheme:e},"*"))}Pi.events?.dispatch("colorSchemeChanged",t)}function xt(t){const e=T(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=T(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(Pi.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 Pt=new Map;function Tt(t){const e=t.instanceId??"",n=Pt.get(e);n&&(n.cleanup(),Pt.delete(e));const i=T(`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="jist-template",Bt=["template","data","theme","mode","formatDate","onAction","templates"],Ut=new Set(["fontWeight","maxLines","lineHeight","opacity"]),Ht=new Set(["lineHeight","letterSpacing"]),Ft={"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"},Gt=["shadow-offset-x","shadow-offset-y","shadow-blur","shadow-color"],Vt={"shadow-offset-x":"0","shadow-offset-y":"0","shadow-blur":"0","shadow-color":"transparent"},Xt={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"])},Jt=["hover","active","disabled"],Kt=[["background-color","background-color"],["color","text-color"]];class Qt 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.#$);for(const t of Bt)this.#j(t);this.#E(),this.#k()}#j(t){if(!Object.prototype.hasOwnProperty.call(this,t))return;const e=this,n=e[t];delete e[t],e[t]=n}disconnectedCallback(){this.#C&&this.#$&&this.#C.removeEventListener("change",this.#$),this.#L(),_t.#P()}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.#L(),_t.#P()));if(this.#T()?this.setAttribute("data-jist-dark",""):this.removeAttribute("data-jist-dark"),!this.#S)return this.#L(),void _t.#P();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.#D(this.#S,"--jist"),this.#T()){const t=this.#S.modes?.dark;t&&this.#D(t,"--jist")}this.#N()}#D(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&&Ht.has(n)?"normal":"number"!=typeof i||Ut.has(n)?String(i):`${i}px`;this.style.setProperty(t,e)}}else this.#D(i,t)}}#N(){const t=[],e=this.#S;if(!e)return;const n=e.modes?.dark;for(const i of Object.keys(Xt)){const o=e[i],s=n?.[i],a=Xt[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.#M(i,e,n,a))}}const i=t.join("\n");if(this.#L(),!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.#P()}#L(){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#P(){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")}#M(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=Ft[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=Gt.map(t=>`var(--jist-button-${o}-${t}, var(--jist-button-${t}, ${Vt[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 Jt){const e=n.states?.[t],a=i.states?.[t];if(!e&&!a)continue;const r=[];for(const[e,n]of Kt){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=Qt;const Yt="gist-inbox-button",Zt="gist-inbox-badge",te="gist-inbox-panel",ee="gist-inbox-messages";let ne=!1,ie=!1;const oe=new Set;let se=null,ae=null;function re(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]=re(e,o)}return n}function le(t,e){const n=t?.patterns?.inbox;if(!n)return null;const i=t?.patterns?.modes?.dark?.inbox;return("dark"===e||null==e&&se?.matches)&&i?re(n,i):n}function ce(){ne||(ne=!0,function(){const t=customElements.get(Ot);t?t!==Qt&&console.warn("[jist] <jist-template> is already registered by another copy or version of the library; keeping the first registration."):customElements.define(Ot,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'),Pi.events.on("messageInboxUpdated",t=>{de(t)}),Pi.events.on("colorSchemeChanged",()=>{de()}),se=window.matchMedia("(prefers-color-scheme: dark)"),ae=()=>{"system"===Pi.config?.colorScheme&&de()},se.addEventListener("change",ae),de())}async function de(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 ue();let n=E();n||(await be(),n=E());const o=ft(Pi.config?.colorScheme),s=le(n,o);if(s){if(function(t,e){let n=document.getElementById(Yt);n||(n=D("div",{id:Yt}),n.addEventListener("click",()=>{ie?(ie=!1,document.getElementById(te)?.classList.remove("gist-inbox-panel--open")):(ie=!0,de())}),M(n));const i=fe(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(Zt);if(0===n||!e.unreadIndicator.showAlert)return void i?.remove();i||(i=D("span",{id:Zt}),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),ie){!function(t,e,n,o){let s=document.getElementById(te);const a=!s;a&&(s=D("div",{id:te}),M(s));const r=fe(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(ee);l||(l=D("div",{id:ee}),s.appendChild(l)),l.innerHTML="";const c=P();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),Pi.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=he,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||oe.has(e)||(oe.add(e),_(e,!0).finally(()=>{oe.delete(e)}))}}}else ue()}function ue(){document.getElementById(Yt)?.remove(),document.getElementById(te)?.remove(),ie=!1}const pe=[[60,"second",1],[3600,"minute",60],[86400,"hour",3600],[2592e3,"day",86400],[31536e3,"month",2592e3],[1/0,"year",31536e3]];let ge=null,me=null;function he(t){const e=Math.round((Date.now()-new Date(t).getTime())/1e3);if(Number.isNaN(e))return t;const[,n,i]=pe.find(([t])=>Math.abs(e)<t);return function(){const t=C();return ge&&me===t||(me=t,ge=new Intl.RelativeTimeFormat(t,{numeric:"auto"})),ge}().format(-Math.round(e/i),n)}function fe(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 be(){await Promise.all([k(),L()])}let ye=600,ve=!1;const we="gist.web.userQueueNextPullCheck",xe="gist.web.sessionId";function Se(){let t=a(xe);return t||(t=g()),s(xe,t,new Date((new Date).getTime()+18e5)),String(t)}const Ie="gist.web.userToken",Ce="gist.web.usingGuestUserToken",$e="gist.web.guestUserToken";function ke(){return null!==a(Ce)}function Ee(){return a(Ie)}function je(){if(null===Ee()){let t=a($e);null==t&&(t=g(),s($e,t),i(`Set guest user token "${t}" with expiry date set to 1 year from today`)),s(Ie,t),s(Ce,!0),i(`Using anonymous session with token: "${t}"`)}}async function Le(){const t=Ee();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 Pe(){const t=Ee();return null===t?null:btoa(t)}function Te(){r(Ie),i("Cleared user token")}const De="gist.web.customAttributes";let Ne=new Map;function Me(){const t=Array.from(Ne.entries()),e=new Date;e.setDate(e.getDate()+30),s(De,t,e),i(`Saved ${Ne.size} custom attributes to storage with TTL of 30 days`)}async function Ae(t){const e=await _e();if(!e)return;const n=new Date;n.setMinutes(n.getMinutes()+60),s(e,t.filter(ze),n)}async function Re(){const t=await _e();return t?(a(t)??[]).filter(e=>{const n=e.properties.gist.broadcast,{frequency:i}=n,o=a(Be(t,e.queueId))??!0,s=a(Oe(t,e.queueId))||0,r=0===i.count;return o&&(r||s<i.count)}):[]}async function qe(t,e){const n=a(t);return n?.find(t=>t.queueId===e)}function ze(t){return!(!t.properties?.gist||!t.properties.gist.broadcast)}function We(t){if(!ze(t))return!1;const e=t.properties.gist.broadcast;return 0===e.frequency.delay&&0===e.frequency.count}async function _e(){const t=await Le();return t?`gist.web.message.broadcasts.${t}`:null}function Oe(t,e){return`${t}.${e}.numberOfTimesShown`}function Be(t,e){return`${t}.${e}.shouldShow`}!function(){const t=a(De);if(t)try{Ne=new Map(t)}catch{Ne=new Map}else Ne=new Map}();const Ue="gist.web.message.user";async function He(t){const e=await Ge();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 Fe(){const t=await Ge();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 Ge(){const t=await Le();return t?`${Ue}.${t}`:null}async function Ve(){const t=await Le();return t?`${Ue}.${t}.seen`:null}async function Xe(t){const e=await Le();return e?`${Ue}.${e}.message.${t}.loading`:null}async function Je(t){const e=await Le();return e?`${Ue}.${e}.message.${t}.state`:null}async function Ke(t){const e=await Je(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; white-space: nowrap; flex-shrink: 0;\n min-width: auto; box-sizing: border-box;\n -webkit-appearance: none; appearance: none;\n }\n .gist-pb-select-elem-btn:disabled {\n opacity: 0.4; cursor: not-allowed;\n }\n .gist-pb-spacer { flex: 1; min-width: 0; }\n .gist-pb-save-btn {\n height: 36px; padding: 0 18px;\n background: #08272B; color: white;\n border: none; border-radius: 6px;\n font-size: 13px; font-weight: 600;\n font-family: system-ui, -apple-system, sans-serif;\n cursor: pointer; white-space: nowrap; align-self: center;\n min-width: auto; box-sizing: border-box;\n -webkit-appearance: none; appearance: none;\n }\n .gist-pb-save-btn:disabled {\n background: #CAD6D8; cursor: not-allowed;\n }\n .gist-pb-picker-overlay {\n position: fixed; inset: 0; z-index: 999999999998; cursor: crosshair;\n }\n .gist-pb-checkbox { cursor: pointer; width: 14px; height: 14px; }\n .gist-pb-pick-highlight { outline: 2px solid #006FF5 !important; }\n .gist-pb-pick-error { outline: 2px solid #941616 !important; }\n #gist-preview-bar.gist-pb-hidden { display: none; }\n .gist-pb-ended-row {\n justify-content: center; align-items: center; gap: 10px; padding: 12px 16px;\n flex-wrap: nowrap;\n }\n .gist-pb-ended-icon {\n display: flex; align-items: center; justify-content: center;\n width: 22px; height: 22px; border-radius: 50%;\n background: #08272B; color: white;\n font-size: 13px; font-weight: 700; flex-shrink: 0;\n }\n .gist-pb-ended-text {\n margin: 0; font-size: 13px; color: #3F4E50;\n font-family: system-ui, -apple-system, sans-serif;\n min-width: 0;\n }\n .gist-pb-ended-text strong { color: #08272B; }\n @media (max-width: 1024px) {\n .gist-pb-controls-row { gap: 8px; }\n .gist-pb-label-group { flex: 1 1 100%; }\n .gist-pb-label-group--grow { flex: 1 1 100%; }\n .gist-pb-select { width: 100%; min-width: unset; box-sizing: border-box; }\n .gist-pb-input { width: 100% !important; box-sizing: border-box; }\n .gist-pb-color-control { width: 100%; }\n .gist-pb-checkbox-row { width: 100%; }\n .gist-pb-inline-row { flex-direction: row; align-items: center; }\n .gist-pb-inline-row .gist-pb-input { flex: 1; min-width: 0; }\n .gist-pb-save-btn { width: 100%; box-sizing: border-box; }\n .gist-pb-label--spacer { display: none; }\n }\n`;const Ze="cioPreviewId",tn="cioPreviewSettings";const en="gist.previewBar.collapsed",nn="gist-pb-styles",on="gist-preview-bar",sn={topLeft:"Top Left",topCenter:"Top Center",topRight:"Top Right",bottomLeft:"Bottom Left",bottomCenter:"Bottom Center",bottomRight:"Bottom Right"};let an=null,rn=[],ln={},cn=null,dn=!1,un=!1,pn=5,gn=null,mn=!0,hn=!1,fn=!1,bn=null,yn=null,vn=null;const wn=new Map;function xn(t,e){const n=D("div",{className:"gist-pb-label-group"});return n.appendChild(D("span",{className:"gist-pb-label",textContent:t})),n.appendChild(e),n}function Sn(t,e){const n=D("select",{className:"gist-pb-select"});for(const i of t){const t=D("option",{value:i.value,textContent:i.label});i.value===e&&(t.selected=!0),n.appendChild(t)}return n}function In(t,e,n){const i=D("input",{className:"gist-pb-input",type:t,value:String(e)});return n&&(i.style.width=n),i}function Cn(t,e){const n=Math.round(Math.min(100,Math.max(0,e))/100*255);return"#"+t.replace("#","").toUpperCase()+n.toString(16).padStart(2,"0").toUpperCase()}function $n(t){return!!("inline"!==t.displayType&&"tooltip"!==t.displayType||t.elementSelector?.trim())}function kn(t){if("overlay"===t.displayType&&X.includes(nt(t.overlayPosition))){const{maxWidth:e,...n}=t;t=n}if(ln=t,cn){const e=rn.findIndex(t=>t.stepName===cn);-1!==e&&(rn[e]={...rn[e],displaySettings:{...t}})}if(!an)return;const e=Pi.currentMessages.find(t=>t.instanceId===an);e&&$n(t)&&($t(e),st(e,t)&&ei(e,cn,t)),function(){const t=new URLSearchParams(window.location.search).get(Ze);t&&async function(t,e){try{return await S()(`/api/v1/preview/${t}`,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}})}catch(t){return x(t)}}(t,rn).then(t=>{t&&404===t.status&&an&&Pi.dismissMessage(an)}).catch(()=>i("Failed to persist preview display settings"))}()}function En(t){const e=t.value.trim();e&&!T(e)?t.classList.add("gist-pb-input--invalid"):t.classList.remove("gist-pb-input--invalid")}function jn(t,e){const n=In("text",t.elementSelector||"","260px");n.placeholder="Element ID or selector",En(n),n.addEventListener("change",()=>{const t=n.value.trim(),e=ln.elementSelector;t&&Ln(t),kn({...ln,elementSelector:t}),e&&e!==t&&Pn(e),En(n)});const i=D("button",{type:"button",className:"gist-pb-select-elem-btn",textContent:"Select Element"});fn&&(i.disabled=!0),i.addEventListener("click",()=>Dn(n));const o=D("div",{className:"gist-pb-inline-row"});o.appendChild(n),o.appendChild(i),e.appendChild(xn("Element Selector",o))}function Ln(t){if(!t||wn.has(t))return;const e=T(t);e&&wn.set(t,e.innerHTML)}function Pn(t){const e=wn.get(t);if(void 0===e)return;const n=T(t);n&&(n.innerHTML=e)}function Tn(){for(const t of wn.keys())Pn(t);wn.clear()}function Dn(t){if(fn)return;fn=!0;const e=document.querySelector(`#${on} .gist-pb-select-elem-btn`);e&&(e.disabled=!0);const n={...ln},o=Pi.currentMessages.find(t=>t.instanceId===an)??null;o&&ti(o),ln.elementSelector&&Pn(ln.elementSelector);const s=D("div",{className:"gist-pb-picker-overlay"});let a=null;const r=t=>{s.style.pointerEvents="none";const e=document.elementFromPoint(t.clientX,t.clientY);s.style.pointerEvents="all",e&&e!==a&&e!==s&&(a?.classList.remove("gist-pb-pick-highlight"),a=e,a.classList.add("gist-pb-pick-highlight"))},l=t=>{if("Escape"===t.key){if(d(),ln=n,cn){const t=rn.findIndex(t=>t.stepName===cn);-1!==t&&(rn[t]={...rn[t],displaySettings:{...n}})}o&&$n(n)&&ei(o,cn,n),Nn()}},c=e=>{e.preventDefault(),e.stopPropagation(),s.style.pointerEvents="none";const n=document.elementFromPoint(e.clientX,e.clientY);if(s.style.pointerEvents="all",n&&n!==s){n.classList.remove("gist-pb-pick-highlight");const e=document.getElementById(on),s=e?.contains(n)?null:function(t){if(t.id){const e=CSS.escape(t.id);if(1===document.querySelectorAll(`#${e}`).length)return t.id}const e=[];let n=t;for(;n&&"BODY"!==n.tagName&&"HTML"!==n.tagName;){if(n.id){const t=CSS.escape(n.id);if(1===document.querySelectorAll(`#${t}`).length){e.unshift(`#${t}`);break}}let t=n.tagName.toLowerCase();n.className&&"string"==typeof n.className&&(t+=n.className.trim().split(/\s+/).filter(Boolean).map(t=>`.${CSS.escape(t)}`).join(""));const i=n.parentElement;i&&(t+=`:nth-of-type(${Array.from(i.children).filter(t=>t.tagName===n.tagName).indexOf(n)+1})`),e.unshift(t);try{if(1===document.querySelectorAll(e.join(" > ")).length)break}catch{}n=n.parentElement}const o=e.join(" > ");try{if(1!==document.querySelectorAll(o).length)return i("buildUniqueSelector: could not produce a unique selector for element"),null}catch{return null}return o}(n);if(null===s)return n.classList.add("gist-pb-pick-error"),void setTimeout(()=>{n.classList.remove("gist-pb-pick-error"),n.classList.add("gist-pb-pick-highlight")},800);t.value=s,Ln(s);const a=ln.elementSelector,r={...ln,elementSelector:s},l=null!=o&&$n(r)&&st(o,r);kn(r),a&&a!==s&&Pn(a),o&&!l&&ei(o,cn,r)}d(),Nn()},d=()=>{a?.classList.remove("gist-pb-pick-highlight"),s.removeEventListener("mousemove",r),s.removeEventListener("click",c),document.removeEventListener("keydown",l),document.body.removeChild(s),fn=!1,bn=null};bn=d,s.addEventListener("mousemove",r),s.addEventListener("click",c),document.addEventListener("keydown",l),document.body.appendChild(s)}function Nn(){const t=document.getElementById(on);if(!t)return;if(t.classList.toggle("gist-pb-hidden",!an&&!un),t.innerHTML="",!an){if(un){const e=D("div",{className:"gist-pb-controls-row gist-pb-ended-row"}),n=D("span",{className:"gist-pb-ended-icon",textContent:"✓"}),i=D("p",{className:"gist-pb-ended-text"});if(i.innerHTML=An(pn),e.appendChild(n),e.appendChild(i),mn){const t=D("button",{type:"button",className:"gist-pb-cancel-btn",textContent:"Cancel"});t.addEventListener("click",Rn),e.appendChild(t)}t.appendChild(e)}return}const e=D("div",{className:"gist-pb-toggle-row"+(dn?" gist-pb-toggle-row--collapsed":"")}),n=D("button",{type:"button",className:"gist-pb-toggle-btn"}),i=dn?"transform:rotate(180deg);display:inline-flex;":"display:inline-flex;";if(n.innerHTML=`${dn?"Expand":"Collapse"}<span style="${i}">${Qe("white")}</span>`,n.addEventListener("click",qn),e.appendChild(n),t.appendChild(e),dn)return;const o=D("div",{className:"gist-pb-controls-row"});if(rn.length>0){const t=cn??rn[0].stepName,e=Sn(rn.map(t=>({value:t.stepName,label:t.stepName})),t);e.addEventListener("change",()=>{const t=rn.find(t=>t.stepName===e.value);if(t){cn=t.stepName,ln={...t.displaySettings};const e=Pi.currentMessages.find(t=>t.instanceId===an);e&&$n(t.displaySettings)&&ei(e,t.stepName,t.displaySettings),Nn()}}),o.appendChild(xn("Step",e))}const s=Sn([{value:"modal",label:"Modal"},{value:"overlay",label:"Overlay"},{value:"inline",label:"Inline"},{value:"tooltip",label:"Tooltip"}],ln.displayType||"modal");s.addEventListener("change",()=>{const t=s.value,e=ln.displayType,n=ln.elementSelector,i={...ln,displayType:t};"modal"===t?(i.modalPosition=i.modalPosition||"center",i.maxWidth=i.maxWidth??414,delete i.overlayPosition,delete i.elementSelector,delete i.tooltipPosition):"overlay"===t?(i.overlayPosition=i.overlayPosition||"topCenter",i.maxWidth=i.maxWidth??414,delete i.modalPosition,delete i.elementSelector,delete i.tooltipPosition):"inline"===t?(delete i.modalPosition,delete i.overlayPosition,delete i.tooltipPosition):"tooltip"===t&&(i.tooltipPosition=i.tooltipPosition||"top",delete i.modalPosition,delete i.overlayPosition,delete i.overlayColor,delete i.dismissOutsideClick),ln=i,kn(ln),"inline"!==e&&"tooltip"!==e||!n||"inline"===t||"tooltip"===t||Pn(n),Nn()}),o.appendChild(xn("Display Type",s));const a=ln.displayType||"modal";"modal"===a?function(t,e){const n=Sn([{value:"top",label:"Top"},{value:"center",label:"Center"},{value:"bottom",label:"Bottom"}],t.modalPosition||"center");n.addEventListener("change",()=>kn({...ln,modalPosition:n.value})),e.appendChild(xn("Position",n));const i=In("number",t.maxWidth??414,"80px");i.addEventListener("change",()=>kn({...ln,maxWidth:parseInt(i.value)||414})),e.appendChild(xn("Max Width",i)),e.appendChild(function(t){const{color:e,opacity:n}=function(t){const e=t.replace("#","");return 8===e.length?{color:"#"+e.slice(0,6).toUpperCase(),opacity:Math.round(parseInt(e.slice(6),16)/255*100)}:6===e.length?{color:"#"+e.toUpperCase(),opacity:100}:{color:"#000000",opacity:20}}(t.overlayColor||"#00000033"),i=D("div",{className:"gist-pb-color-control"}),o=D("input",{className:"gist-pb-color-input",type:"color",value:e}),s=D("div",{className:"gist-pb-color-swatch"});s.style.background=e,s.appendChild(o),s.addEventListener("click",()=>o.click());const a=D("input",{className:"gist-pb-color-hex",type:"text",maxLength:6,value:e.replace("#","")}),r=D("input",{className:"gist-pb-color-opacity",type:"number",min:"0",max:"100",value:String(n)}),l=D("span",{className:"gist-pb-color-pct",textContent:"%"}),c=()=>{const t="#"+a.value.replace("#",""),e=parseInt(r.value)||0;s.style.background=t,o.value=t,kn({...ln,overlayColor:Cn(t,e)})};return o.addEventListener("input",()=>{a.value=o.value.replace("#","").toUpperCase(),s.style.background=o.value}),o.addEventListener("change",c),a.addEventListener("change",c),r.addEventListener("change",c),i.appendChild(s),i.appendChild(a),i.appendChild(r),i.appendChild(l),xn("Overlay Color",i)}(t));const o=D("div",{className:"gist-pb-checkbox-row"}),s=D("input",{className:"gist-pb-checkbox",type:"checkbox"});s.checked=t.dismissOutsideClick??!1;const a=D("label",{className:"gist-pb-checkbox-label",textContent:"Dismiss on click outside"});s.addEventListener("change",()=>kn({...ln,dismissOutsideClick:s.checked})),a.addEventListener("click",()=>{s.checked=!s.checked,kn({...ln,dismissOutsideClick:s.checked})}),o.appendChild(s),o.appendChild(a);const r=xn(" ",o);r.classList.add("gist-pb-label-group--grow"),r.firstChild.classList.add("gist-pb-label--spacer"),e.appendChild(r)}(ln,o):"overlay"===a?function(t,e){const n=Sn(Object.entries(sn).map(([t,e])=>({value:t,label:e})),t.overlayPosition||"topCenter");if(n.addEventListener("change",()=>kn({...ln,overlayPosition:n.value})),e.appendChild(xn("Position",n)),!X.includes(nt(t.overlayPosition))){const n=In("number",t.maxWidth??414,"80px");n.addEventListener("change",()=>kn({...ln,maxWidth:parseInt(n.value)||414})),e.appendChild(xn("Max Width",n))}}(ln,o):"inline"===a?function(t,e){jn(t,e)}(ln,o):"tooltip"===a&&function(t,e){const n=Sn([{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"left",label:"Left"},{value:"right",label:"Right"}],t.tooltipPosition||"top");n.addEventListener("change",()=>kn({...ln,tooltipPosition:n.value})),e.appendChild(xn("Position",n)),jn(t,e)}(ln,o),o.appendChild(D("div",{className:"gist-pb-spacer"}));const r=D("button",{type:"button",className:"gist-pb-save-btn",textContent:"End session"});r.addEventListener("click",async()=>{an&&await Pi.dismissMessage(an)}),o.appendChild(r),t.appendChild(o)}async function Mn(){if(!hn)if(hn=!0,Te(),function(){try{sessionStorage.removeItem(o)}catch{}}(),mn){try{window.close()}catch{}try{window.location.reload()}catch{}bn&&bn(),gn&&(clearInterval(gn),gn=null),Tn(),document.getElementById(on)?.remove(),document.getElementById(nn)?.remove(),an=null,rn=[],ln={},cn=null,un=!1,pn=5,mn=!0,hn=!1}else un=!1,hn=!1,Nn()}function An(t){return mn?`<strong>Preview session ended.</strong> This tab will close in ${t}s…`:`<strong>Preview session ended.</strong> Finishing session in ${t}s… This tab will stay open.`}function Rn(){un&&gn&&(mn=!1,Nn())}function qn(){dn=!dn;try{sessionStorage.setItem(en,String(dn))}catch{}Nn()}function zn(t){if(un)return;an=t.instanceId??null;const e=t.displaySettings;if(Array.isArray(e)&&e.length>0?(rn=e,cn||(cn=rn[0].stepName,ln={...rn[0].displaySettings})):e&&"object"==typeof e&&!Array.isArray(e)&&(ln={...e}),yn||vn){const t=!!yn,e=!!vn,n=yn,o=vn;if(yn=null,vn=null,t){const t=rn.find(t=>t.stepName===n);if(!t)return i(`Preview bar: step "${n}" not found, ignoring initial step/display override`),void Nn();cn=t.stepName,ln={...t.displaySettings}}if(e){if(!t)return i(`Preview bar: display type "${o}" provided without a step, ignoring`),void Nn();ln={...ln,displayType:o}}Nn();const s=Pi.currentMessages.find(t=>t.instanceId===an);return void(s&&$n(ln)?ei(s,cn,ln):function(){const t=ln.displayType;if("inline"!==t&&"tooltip"!==t)return;const e=document.querySelector("#gist-preview-bar .gist-pb-input[type='text']");e&&Dn(e)}())}Nn()}function Wn(){Tn(),an=null,rn=[],ln={},cn=null,un=!0,pn=5,mn=!0,hn=!1;const t=new URLSearchParams(window.location.search).get(Ze);t&&async function(t){try{return await S()(`/api/v1/preview/${t}`,{method:"DELETE"})}catch(t){return x(t)}}(t).catch(()=>i("Failed to delete preview session")),Nn(),gn&&clearInterval(gn),gn=setInterval(async()=>{if(pn-=1,pn<=0)clearInterval(gn),gn=null,await Mn();else{const t=document.querySelector(`#${on} .gist-pb-ended-text`);t?t.innerHTML=An(pn):Nn()}},1e3)}async function _n(t){if(!Pi.isDocumentVisible)return i("Document hidden, not showing message now."),null;if(K(t.queueId))return i(`Message with queueId ${t.queueId} is already showing.`),null;const e=F(t);return!t.tooltipPosition&&e.hasTooltipPosition&&(t.tooltipPosition=e.tooltipPosition),t.tooltipPosition?function(t,e){const n=e.elementId||t.elementId;if(!n)return i(`No target selector specified for tooltip message ${t.messageId}`),Pi.messageError(t),null;if(!T(n)){if(!Pi.config.isPreviewSession||!t.properties?.gist?.livePreview)return i(`Tooltip target element "${n}" not found for message ${t.messageId}, skipping display`),Pi.messageError(t),null;i(`Preview: tooltip target "${n}" not found, loading message for preview bar`)}const o=Pi.currentMessages.find(t=>t.tooltipPosition&&t.elementId===n);o&&(i(`Tooltip already showing on target "${n}" (instance ${o.instanceId}), dismissing it first`),Pi.messageDismissed(o),Tt(o),o.instanceId&&Y(o.instanceId)),t.instanceId=g(),t.overlay=!1,t.firstLoad=!0,t.shouldResizeHeight=!1,t.shouldScale=!1,t.renderStartTime=(new Date).getTime(),t.elementId=n,Pi.currentMessages.push(t);return Jn(t,null,t.savedStepName||null)}(t,e):Pi.overlayInstanceId?(i(`Message ${Pi.overlayInstanceId} already showing.`),null):(t.instanceId=g(),t.overlay=!0,t.firstLoad=!0,t.shouldResizeHeight=!0,t.shouldScale=e.shouldScale,t.renderStartTime=(new Date).getTime(),Pi.overlayInstanceId=t.instanceId,Pi.currentMessages.push(t),Jn(t,null,t.savedStepName||null))}function On(t,e){return Pi.isDocumentVisible?K(t.queueId)?(i(`Message with queueId ${t.queueId} is already showing.`),null):Q(e)?(i(`Message with elementId ${e} already has a message.`),null):(t.instanceId=g(),t.overlay=!1,t.firstLoad=!0,t.shouldScale=!1,t.elementId=e,t.shouldResizeHeight=!St(e),t.renderStartTime=(new Date).getTime(),Pi.currentMessages.push(t),Jn(t,e,t.savedStepName||null)):(i("Document hidden, not showing message now."),null)}async function Bn(t){t?(Pi.messageDismissed(t),await Un(t)):i("Message not found")}async function Un(t){"tooltip"===ot(t)?Gn(t):t.overlay?await Vn(!0,t):Fn(t)}async function Hn(t){t?F(t).persistent&&(i("Persistent message dismissed, logging view"),await ni(t),await Kn(t),await Ke(t.queueId??"")):i("Message not found")}function Fn(t){t.instanceId&&Y(t.instanceId),t.elementId&&xt(t.elementId),Pi.config.isPreviewSession&&(Wn(),Xn())}function Gn(t){Tt(t),t.instanceId&&Y(t.instanceId),0===Pi.currentMessages.length&&(window.removeEventListener("message",Yn),window.removeEventListener("touchstart",Qn)),Pi.config.isPreviewSession&&(Wn(),Xn())}async function Vn(t,e){t?await jt():Lt(),0===Pi.currentMessages.length&&(window.removeEventListener("message",Yn),window.removeEventListener("touchstart",Qn)),e.instanceId&&Y(e.instanceId),Pi.overlayInstanceId=null,Pi.config.isPreviewSession&&(Wn(),Xn())}function Xn(){const t=new URL(window.location.href);t.searchParams.delete(Ze),t.searchParams.delete(tn),history.replaceState(null,"",t.toString())}function Jn(t,e=null,n=null){const o=Pi.config.env,s={endpoint:v.ENGINE_API_ENDPOINT[o],siteId:Pi.config.siteId,dataCenter:Pi.config.dataCenter,messageId:t.messageId,instanceId:t.instanceId??"",livePreview:!1,properties:t.properties,customAttributes:Object.fromEntries(new Map(Ne))},a=`${v.GIST_VIEW_ENDPOINT[o]}/index.html`;return window.addEventListener("message",Yn),window.addEventListener("touchstart",Qn),"tooltip"===ot(t)?function(t,e,n,i=null){const o=e.instanceId??"",s=Dt(o),a=F(e),r=Pt.get(o);r&&(r.cleanup(),Pt.delete(o)),document.querySelectorAll(`#gist-tooltip-${o}`).forEach(t=>{t.parentNode?.removeChild(t)});const l=`gist-tooltip-${o}`,c=document.createElement("div");c.id=l;const d=ht(Pi.config?.colorScheme);c.innerHTML=function(t,e,n,i="",o="light only"){let s=600;e.messageWidth>s&&(s=e.messageWidth);const a=e.tooltipArrowColor,r=function(t){switch(t){case"top":default:return"gist-arrow-bottom";case"bottom":return"gist-arrow-top";case"left":return"gist-arrow-right";case"right":return"gist-arrow-left"}}(e.tooltipPosition),l=i?`#${i} `:"";return`\n <div class="gist-tooltip-outer">\n <style>\n ${l}.gist-tooltip-outer {\n position: absolute;\n }\n ${l}.gist-tooltip-container {\n position: relative;\n z-index: 9999999;\n opacity: 0;\n transition: opacity 0.3s ease-in-out;\n }\n ${l}.gist-tooltip-container.gist-visible {\n opacity: 1;\n }\n ${l}.gist-tooltip-frame-clip {\n overflow: hidden;\n }\n ${l}.gist-tooltip-frame {\n display: block;\n width: ${e.messageWidth}px;\n border: none;\n transition: height 0.1s ease-in-out;\n color-scheme: ${o};\n }\n ${l}.gist-tooltip-arrow {\n width: 0;\n height: 0;\n position: absolute;\n z-index: 1;\n }\n ${l}.gist-tooltip-arrow.gist-arrow-bottom {\n bottom: 0;\n left: 50%;\n transform: translateX(-50%) translateY(100%);\n border-left: 10px solid transparent;\n border-right: 10px solid transparent;\n border-top: 10px solid ${a};\n }\n ${l}.gist-tooltip-arrow.gist-arrow-top {\n top: 0;\n left: 50%;\n transform: translateX(-50%) translateY(-100%);\n border-left: 10px solid transparent;\n border-right: 10px solid transparent;\n border-bottom: 10px solid ${a};\n }\n ${l}.gist-tooltip-arrow.gist-arrow-right {\n right: 0;\n top: 50%;\n transform: translateY(-50%) translateX(100%);\n border-top: 10px solid transparent;\n border-bottom: 10px solid transparent;\n border-left: 10px solid ${a};\n }\n ${l}.gist-tooltip-arrow.gist-arrow-left {\n left: 0;\n top: 50%;\n transform: translateY(-50%) translateX(-100%);\n border-top: 10px solid transparent;\n border-bottom: 10px solid transparent;\n border-right: 10px solid ${a};\n }\n @media (max-width: ${s}px) {\n ${l}.gist-tooltip-frame {\n max-width: 100%;\n }\n }\n </style>\n <div class="gist-tooltip-container">\n <div class="gist-tooltip-arrow ${r}"></div>\n <div class="gist-tooltip-frame-clip">\n <iframe id="${t}" class="gist-tooltip-frame" src="${n}"></iframe>\n </div>\n </div>\n </div>`}(s,a,t,l,d),document.body.appendChild(c),It(s,n,i)}(a,t,s,n):e?(G.includes(e)&&V(e),function(t,e,n,o,s=null){const a=T(t);if(a){const i=Dt(n.instanceId??"");a.classList.add(i);const r=F(n);let l=r.messageWidth+"px";X.includes(t)&&!r.hasCustomWidth&&(l="100%"),G.includes(t)&&(a.style.width=l),St(t)||(a.style.height="0px"),a.innerHTML=function(t,e,n){const i=ht(Pi.config?.colorScheme);return function(t,e,n,i="light only"){let o=800;return e.messageWidth>o&&(o=e.messageWidth),`\n <div id="gist-embed">\n <style>\n #x-gist-floating-top, #x-gist-floating-top-left, #x-gist-floating-top-right {\n position: fixed;\n top: 0px;\n z-index: 1000000;\n }\n #x-gist-floating-bottom, #x-gist-floating-bottom-left, #x-gist-floating-bottom-right {\n position: fixed;\n bottom: 0px;\n z-index: 1000000;\n }\n #x-gist-bottom, #x-gist-top, #x-gist-floating-top, #x-gist-floating-bottom {\n left: 50%;\n transform: translate(-50%, 0%);\n }\n #x-gist-floating-top-right, #x-gist-floating-bottom-right {\n right: 0px;\n }\n #gist-embed {\n position: relative;\n height: 100%;\n width: 100%;\n }\n #gist-embed-container {\n position: relative;\n height: 100%;\n width: 100%;\n }\n #gist-embed-container .gist-frame {\n height: 100%;\n width: 100%;\n border: none;\n color-scheme: ${i};\n }\n #x-gist-top.${t},\n #x-gist-bottom.${t},\n #x-gist-floating-top.${t},\n #x-gist-floating-bottom.${t},\n #x-gist-floating-top-left.${t},\n #x-gist-floating-top-right.${t},\n #x-gist-floating-bottom-left.${t},\n #x-gist-floating-bottom-right.${t} {\n transition: height 0.1s ease-in-out;\n }\n @media (max-width: ${o}px) {\n #x-gist-top.${t},\n #x-gist-bottom.${t},\n #x-gist-floating-top.${t},\n #x-gist-floating-bottom.${t},\n #x-gist-floating-top-left.${t},\n #x-gist-floating-top-right.${t},\n #x-gist-floating-bottom-left.${t},\n #x-gist-floating-bottom-right.${t} {\n width: 100% !important;\n }\n }\n </style>\n <div id="gist-embed-container">\n <iframe id="${t}" class="gist-frame" src="${n}"></iframe>\n </div>\n </div>`}(Dt(e.instanceId??""),n,t,i)}(e,n,r),It(i,o,s)}else i(`Message could not be embedded, elementId ${t} not found.`)}(e,a,t,s,n)):function(t,e,n,i=null){Et(),document.querySelectorAll("#gist-embed-message").forEach(t=>{t.parentNode?.removeChild(t)}),document.body.insertAdjacentHTML("afterbegin",function(t,e){const n=F(e),i=ht(Pi.config?.colorScheme);return function(t,e,n,i="light only"){let o=600;return e.messageWidth>o&&(o=e.messageWidth),`\n <div id="gist-embed-message">\n <style>\n #gist-overlay.gist-background {\n position: fixed;\n z-index: 9999999998;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n background-color: ${e.overlayColor};\n visibility: hidden;\n }\n #gist-overlay.gist-background.gist-visible {\n visibility: visible;\n }\n .gist-message {\n width: ${e.messageWidth}px;\n position: absolute;\n border: none;\n opacity: 0;\n transition: opacity 0.3s ease-in-out, height 0.1s ease-in-out;\n z-index: 9999999999;\n left: 50%;\n transform: translateX(-50%);\n color-scheme: ${i};\n }\n .gist-message.gist-visible {\n opacity: 1;\n pointer-events: auto;\n }\n .gist-message.gist-center {\n transform: translate(-50%, -50%);\n top: 50%;\n }\n .gist-message.gist-bottom {\n bottom: 0;\n }\n .gist-message.gist-top {\n top: 0;\n }\n @media (max-width: ${o}px) {\n .gist-message {\n width: 100%;\n }\n }\n </style>\n <div id="gist-overlay" class="gist-background">\n <iframe id="${t}" class="gist-message" src="${n}"></iframe>\n </div>\n </div>`}(Dt(e.instanceId??""),n,t,i)}(t,e)),It(Dt(e.instanceId??""),n,i)}(a,t,s,n),t}async function Kn(t){let e;i(`Message shown, logging view for: ${t.messageId}`),null!=t.queueId?(await ni(t),e=await A(t.queueId)):e=await async function(t){try{return await S().post(`/api/v1/logs/message/${t}`)}catch(t){return x(t)}}(t.messageId),i(200===e?.status?"Message view logged":`Problem logging message: ${e?.status}`)}function Qn(){}async function Yn(t){const e=Pi.config.env,n=t.data;if(n.gist&&t.origin===v.RENDERER_HOST[e]){const t=n.gist.instanceId,e=J(t);if(!e)return;const o=F(e);switch(n.gist.method){case"routeLoaded":{const s=.001*((new Date).getTime()-(e.renderStartTime??0));if(i(`Engine render for message: ${e.messageId} timer elapsed in ${s.toFixed(3)} seconds`),async function(t){const e=await Xe(t);e&&r(e)}(e.queueId??""),e.currentRoute=n.gist.parameters.route,n.gist.parameters.fullDisplaySettings&&!e.displaySettings?e.displaySettings=n.gist.parameters.fullDisplaySettings:e.displaySettings&&(i("SDK already has display settings state, sending it to iframe"),$t(e)),Pi.config.isPreviewSession&&e.properties?.gist?.livePreview&&zn(e),e.firstLoad||e.isDisplayChange){if("tooltip"===ot(e)){const t=e.properties?.gist?.elementId||e.elementId||void 0;if(!t||!T(t)){if(Pi.config.isPreviewSession&&e.properties?.gist?.livePreview){i(`Preview: tooltip target "${t}" not found, preview bar will show element picker`),e.firstLoad=!1,e.isDisplayChange=!1;break}i(`Tooltip target not found for "${t}", emitting error and skipping display`),Pi.messageError(e),e.firstLoad=!1,e.isDisplayChange=!1,Gn(e);break}const n=await async function(t){const e=t.instanceId??"",n=F(t),o=`gist-tooltip-${e}`,s=T(o);if(!s)return i(`Tooltip wrapper not found for instance ${e}`),!1;const a=t.properties?.gist?.elementId||t.elementId||void 0;if(!a)return i(`No target selector for tooltip ${e}`),!1;const r=Pt.get(e);r&&(r.cleanup(),Pt.delete(e));const l=s.querySelector(".gist-tooltip-outer");if(!l)return i(`Tooltip inner element not found for instance ${e}`),!1;const c=n.tooltipPosition||"bottom";if(!await async function(t,e,n){const o=dt(e);if(!o)return!1;let s=[];try{s=mt(o)}catch{}if(ut(o.getBoundingClientRect(),s))return!0;if(!function(t,e,n){const i=dt(e);if(!i)return!1;const o=i.getBoundingClientRect(),s=window.innerWidth,a=window.innerHeight,r=new DOMRect(Math.max(0,(s-o.width)/2),Math.max(0,(a-o.height)/2),o.width,o.height);return t.style.display="",null!==gt(t.getBoundingClientRect(),r,n)}(t,e,n))return i(`Preflight failed: tooltip would not fit after scrolling target "${e}" into view`),!1;o.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),await function(t){return new Promise(e=>{let n=t.getBoundingClientRect(),i=0;const o=Date.now();setTimeout(function s(){const a=t.getBoundingClientRect();Math.abs(a.top-n.top)<1&&Math.abs(a.left-n.left)<1?i++:i=0,n=a,i>=2||Date.now()-o>1e3?e():setTimeout(s,50)},50)})}(o);const a=o.getBoundingClientRect();let r=[];try{r=mt(o)}catch{}return ut(a,r)}(l,a,c))return i(`Tooltip for instance ${e} skipped: target "${a}" is off-screen and cannot be scrolled into a valid position`),!1;const d=function(t,e,n,o){const s=dt(e);if(!s)return null;let a=null,r=null,l=!1,c=[],d=null;try{c=mt(s)}catch{}function u(){if(l)return;if(!s||!document.contains(s)||!document.contains(t))return i("Tooltip or target element removed from DOM, cleaning up listeners"),g(),void o?.onDetach?.();const e=s.getBoundingClientRect();if(!ut(e,c))return void(t.style.display="none");t.style.display="";const a=gt(t.getBoundingClientRect(),e,n);a?(function(t,e){t.style.position="absolute",t.style.top=`${e.top+window.scrollY}px`,t.style.left=`${e.left+window.scrollX}px`}(t,a),function(t,e){const n=t.querySelector(".gist-tooltip-arrow");n&&(n.classList.remove("gist-arrow-top","gist-arrow-bottom","gist-arrow-left","gist-arrow-right"),n.classList.add(ct[e.position]),null!==e.arrowOffset?"top"===e.position||"bottom"===e.position?(n.style.left=`calc(50% + ${e.arrowOffset}px)`,n.style.removeProperty("top")):(n.style.top=`calc(50% + ${e.arrowOffset}px)`,n.style.removeProperty("left")):"top"===e.position||"bottom"===e.position?(n.style.left="50%",n.style.removeProperty("top")):(n.style.top="50%",n.style.removeProperty("left")))}(t,a)):t.style.display="none"}function p(){null===a&&(a=requestAnimationFrame(()=>{a=null,u()}))}function g(){if(!l){l=!0,d&&(d.disconnect(),d=null),window.removeEventListener("scroll",p),window.removeEventListener("resize",p);for(const t of c)t.removeEventListener("scroll",p);null!==a&&(cancelAnimationFrame(a),a=null),null!==r&&(cancelAnimationFrame(r),r=null)}}if(u(),l)return null;window.addEventListener("scroll",p,{passive:!0}),window.addEventListener("resize",p,{passive:!0});for(const t of c)t.addEventListener("scroll",p,{passive:!0});try{d=new MutationObserver(()=>{null===r&&(r=requestAnimationFrame(()=>{r=null,document.contains(s)||u()}))}),d.observe(document.body,{childList:!0,subtree:!0})}catch{}return{cleanup:g,reposition:u}}(l,a,c,{onDetach:()=>{Pt.delete(e);const t=T(o);t&&t.parentNode?.removeChild(t)}});if(d){if("none"!==l.style.display){const t=s.querySelector(".gist-tooltip-container");return t?(Pt.set(e,d),t.classList.add("gist-visible"),!0):(d.cleanup(),i(`Tooltip container not found for instance ${e}`),!1)}return d.cleanup(),i(`Tooltip for instance ${e} could not be positioned within the viewport, target "${a}" may be off-screen`),!1}return i(`Failed to position tooltip for instance ${e}, target "${a}" may not exist or no position fits the viewport`),!1}(e);if(!n){if(Pi.config.isPreviewSession&&e.properties?.gist?.livePreview){i(`Preview: tooltip positioning failed for "${t}", preview bar will remain active`),e.firstLoad=!1,e.isDisplayChange=!1;break}i(`Tooltip positioning failed for "${t}", emitting error and cleaning up`),Pi.messageError(e),e.firstLoad=!1,e.isDisplayChange=!1,Gn(e);break}}else e.overlay?function(t){const e=F(t),n=document.querySelector("#gist-overlay");if(n){n.classList.add("gist-visible");const o=document.querySelector(".gist-message");o&&(t.position?o.classList.add("gist-"+t.position):o.classList.add("gist-center")),setTimeout(Nt,100),e.exitClick&&(i=t.instanceId??"",Et(),kt=t=>{"Escape"===t.key&&Pi.dismissMessage(i)},document.addEventListener("keydown",kt),setTimeout(()=>function(t){const e=document.querySelector("#gist-overlay");e&&e.addEventListener("click",()=>{Pi.dismissMessage(t)})}(t.instanceId??""),1e3))}else Lt();var i}(e):function(t){const e=T(t);e&&e.classList.add("gist-visible")}(e.elementId);e.firstLoad&&!e.isDisplayChange&&(Pi.messageShown(e),o.persistent?i("Persistent message shown, skipping logging view"):await Kn(e)),e.firstLoad=!1,e.isDisplayChange=!1}Z(t,e);break}case"tap":{const t=n.gist.parameters.action,i=n.gist.parameters.name;if(Pi.messageAction(e,t,i),n.gist.parameters.system&&!o.persistent){await Bn(e);break}try{const n=new URL(t);if(n&&"gist:"===n.protocol)switch(n.href.replace("gist://","").split("?")[0]){case"close":await Hn(e),await ii(e),await Bn(e),await li();break;case"showMessage":{const t=n.searchParams.get("messageId"),e=n.searchParams.get("properties");if(t){const n=e?JSON.parse(atob(e)):void 0;await Pi.showMessage({messageId:t,properties:n})}break}case"loadPage":{const t=n.href.substring(n.href.indexOf("?url=")+5);t&&(t.startsWith("mailto:")||t.startsWith("https://")||t.startsWith("http://")||t.startsWith("/")?window.location.href=t:window.location.href=window.location+t);break}}}catch{}break}case"changeMessageStep":{const t=n.gist.parameters.displaySettings,r=n.gist.parameters.messageStepName;Pi.config.isPreviewSession&&r&&e.properties?.gist?.livePreview&&function(t,e){if(un)return;cn=t;const n=rn.find(e=>e.stepName===t);n?ln={...n.displaySettings}:e&&(ln={...e}),Nn()}(r,t),(o.persistent||We(e))&&await async function(t,e,n){const o=await Je(t);if(!o)return;const r=a(o)||{},l={stepName:void 0!==e?e:r.stepName,displaySettings:void 0!==n?n:r.displaySettings},c=new Date;c.setDate(c.getDate()+30),s(o,l,c),i(`Saved message state for queueId: ${t}`)}(e.queueId??"",r,t),t&&st(e,t)&&(i("Display settings changed, reloading message"),await ti(e),at(e,t),await Zn(e,r??null));break}case"routeChanged":e.currentRoute=n.gist.parameters.route,e.renderStartTime=(new Date).getTime(),Z(t,e),i(`Route changed to: ${e.currentRoute}`);break;case"sizeChanged":i(`Size Changed Width: ${n.gist.parameters.width} - Height: ${n.gist.parameters.height}`),"tooltip"===ot(e)?function(t,e){const n=t.instanceId??"",i=Dt(n),o=document.getElementById(i);if(o&&e.height>0){o.style.height=`${e.height}px`;const t=Pt.get(n);t&&t.reposition()}}(e,n.gist.parameters):e.elementId&&!e.shouldResizeHeight||function(t,e){const n=T(t.elementId?t.elementId:Dt(t.instanceId??""));if(n){const i=n.style;if(e.height>0)if(e.height>window.innerHeight){const n=1-(e.height/window.innerHeight-1);t.shouldScale&&n>=.4?(i.height=`${e.height}px`,i.transform=`translateX(-50%) translateY(-50%) scale(${n})`):i.height=`${window.innerHeight}px`}else i.height=`${e.height}px`}}(e,n.gist.parameters);break;case"titleChanged":i(`Overlay title changed to: ${n.gist.parameters.title}`),function(t,e){const n=T(Dt(t));n&&(n.title=e)}(t,n.gist.parameters.title);break;case"eventDispatched":Pi.events.dispatch("eventDispatched",{name:n.gist.parameters.name,payload:n.gist.parameters.payload});break;case"error":case"routeError":Pi.messageError(e),"tooltip"===ot(e)?Gn(e):Pi.overlayInstanceId?await Vn(!1,e):Fn(e)}}}async function Zn(t,e){t.isDisplayChange=!0,t.renderStartTime=(new Date).getTime();const n=ot(t),o=t.elementId||null;if("tooltip"===n)return Pi.overlayInstanceId===t.instanceId&&(Pi.overlayInstanceId=null),t.shouldScale=!1,t.shouldResizeHeight=!1,void Jn(t,null,e);if(o){const e=Q(o);e&&e.instanceId!==t.instanceId&&(i(`Dismissing existing message at ${o} to make room for multi-step message`),await Bn(e))}if(t.overlay){Pi.overlayInstanceId=t.instanceId??null;const e=F(t);t.shouldScale=e.shouldScale,t.shouldResizeHeight=!0}else Pi.overlayInstanceId=null,t.shouldScale=!1,t.shouldResizeHeight=!St(o??"");o&&G.includes(o)&&V(o),Jn(t,o,e)}async function ti(t){"tooltip"===ot(t)?Tt(t):t.overlay?await jt():t.elementId&&xt(t.elementId)}async function ei(t,e,n){n&&st(t,n)&&(await ti(t),at(t,n)),await Zn(t,e??null)}async function ni(t){i(`Logging user message view locally for: ${t.queueId}`),ze(t)?await async function(t){i(`Marking broadcast ${t} as seen.`);const e=await _e();if(!e)return;const n=await qe(e,t);if(!n)return;const o=n.properties.gist.broadcast,{frequency:r}=o,l=Oe(e,t),c=Be(e,t),d=a(l)||0;if(s(l,d+1),1===r.count)s(c,!1),i(`Marked broadcast ${t} as seen.`);else{const e=new Date;e.setSeconds(e.getSeconds()+r.delay),s(c,!1,e),i(`Marked broadcast ${t} as seen, broadcast was seen ${d+1} times, next show date is ${e}.`)}}(t.queueId??""):await async function(t){const e=await Ve();if(!e)return;const n=a(e)??[];n.push(t),s(e,n)}(t.queueId??"")}async function ii(t){ze(t)&&(i(`Logging broadcast dismissed locally for: ${t.queueId}`),await async function(t){i(`Marking broadcast ${t} as dismissed.`);const e=await _e();if(!e)return;const n=await qe(e,t);n&&(!0!==n.properties.gist.broadcast.frequency.ignoreDismiss?(s(Be(e,t),!1),i(`Marked broadcast ${t} as dismissed and will not show again.`)):i(`Broadcast ${t} is set to ignore dismiss.`))}(t.queueId??""),await Ke(t.queueId??""))}const oi=(t,e)=>t().then((t=>new Promise(e=>setTimeout(e,t)))(e).then(()=>oi(t,e)));let si=!1,ai=null;async function ri(){si?await li():Ee()?(i("Queue watcher started"),si=!0,oi(()=>new Promise(()=>{!async function(){if(v.hasActiveSSEConnection())return!v.isSSEConnectionManagedBySDK()&&ai&&(i("Not the main instance, closing our SSE connection."),ui()),void await li();ai&&(i("SSE connection not active, closing it."),ui()),!v.useSSE()||ke()?await di():await async function(){ui();const t=function(){const t=Pe();return null===t?(i("No user token available for SSE endpoint."),null):v.GIST_QUEUE_REALTIME_API_ENDPOINT[Pi.config.env??"prod"]+`/api/v3/sse?userToken=${t}&siteId=${Pi.config.siteId}&sessionId=${Se()}`}();if(null===t)return i("SSE endpoint not available, falling back to polling."),void await di();i(`Starting SSE queue listener on ${t}`),ai=new EventSource(t),v.setActiveSSEConnection(),ai.addEventListener("connected",async t=>{try{i("SSE connection received"),v.setUseSSEFlag(!0);const e=JSON.parse(t.data);e.heartbeat&&(v.setSSEHeartbeat(e.heartbeat),i(`SSE heartbeat set to ${e.heartbeat} seconds`)),v.setActiveSSEConnection()}catch(t){i(`Failed to parse SSE settings: ${t}`)}r(we),await di()}),ai.addEventListener("messages",async t=>{try{const e=JSON.parse(t.data);i("SSE message received"),await He(e),await Ae(e),await li()}catch(t){i(`Failed to parse SSE message: ${t}`),ui()}}),ai.addEventListener("inbox_messages",async t=>{try{const e=JSON.parse(t.data);i("SSE inbox messages received"),await z(e)}catch(t){i(`Failed to parse SSE inbox messages: ${t}`)}}),ai.addEventListener("error",async()=>{i("SSE error received"),ui()}),ai.addEventListener("heartbeat",async()=>{i("SSE heartbeat received"),v.setActiveSSEConnection(),v.setUseSSEFlag(!0)})}()}()}),1e3)):i("User token not setup, queue not started.")}async function li(){const t=await Re(),e=await Fe(),n=t.concat(e);i(`Messages in local queue: ${n.length}`);const o=n.sort((t,e)=>t.priority-e.priority);for(const t of o)await ci(t)}async function ci(t){let e=F(t);if(e.hasRouteRule){if(null==Pi.currentRoute&&!Pi.routeInitialized)return i(`Deferring message ${t.queueId}, route not yet initialized`),!1;if(!it(e.routeRule))return i(`Route ${new URL(window.location.href).pathname} (currentRoute: ${Pi.currentRoute}) does not match rule: ${e.routeRule}`),!1}if(e.hasPosition&&(t.position=e.position),e.hasTooltipPosition&&(t.tooltipPosition=e.tooltipPosition),e.persistent||We(t)){const n=await async function(t){const e=await Je(t);return e?a(e):null}(t.queueId??"");n&&(i(`Restoring saved state for queueId ${t.queueId}`),n.displaySettings&&(at(t,n.displaySettings),e=F(t)),t.savedStepName=n.stepName??null)}if(e.persistent||We(t)||!await async function(t){const e=await Xe(t);return!!e&&null!==a(e)}(t.queueId??"")){let n=null;return e.isEmbedded?!Pi.config.isPreviewSession||!t.properties?.gist?.livePreview||T(e.elementId)||G.includes(e.elementId)?n=On(t,e.elementId):(i(`Preview: element "${e.elementId}" not found, showing as overlay so placement can be changed`),n=await _n(t)):n=await _n(t),n&&async function(t){const e=await Xe(t);e&&s(e,!0,new Date(Date.now()+5e3))}(t.queueId??""),null!==n}return i(`Not showing message with queueId ${t.queueId} because its already loading.`),!1}async function di(){if(Ee())if(Pi.isDocumentVisible)if(null===a(we)){const t=await async function(){if(ve)return;ve=!0;const t=Ee();let e;try{const t={"X-Gist-User-Anonymous":String(ke()),"Content-Language":String(C())};e=await S().post(`/api/v4/users?sessionId=${Se()}`,{},{headers:t})}catch(t){const n=x(t);n?e=n:i(`Error getting user queue: ${t}`)}finally{ve=!1}return t!==Ee()?(i("User token changed, clearing queue next pull check."),void r(we)):(function(t){const e=t?.headers?.["x-gist-queue-polling-interval"];ye=e&&Number(e)>0?Number(e):Math.min(2*ye,600);const n=new Date((new Date).getTime()+1e3*ye);s(we,ye,n)}(e),function(t){const e="true"===t?.headers?.["x-cio-use-sse"]?.toLowerCase();v.setUseSSEFlag(e)}(e),await async function(t){const e=t?.headers?.["x-cio-inbox-enabled"]?.toLowerCase();if(void 0===e)return;const n="true"===e;v.setInboxEnabledFlag(n),n&&(i("Inbox enabled, ensuring branding and templates are cached."),await be(),ce())}(e),e)}();if(t){if(200===t.status||204===t.status){i("200 response, updating local store.");const e=t.data,n=e?.inAppMessages??[],o=e?.inboxMessages??[];He(n),Ae(n),z(o)}else 304===t.status&&i("304 response, using local store.");await li()}else i("No response object returned while checking message queue.")}else i("Next queue pull scheduled for later.");else i("Document not visible, skipping queue check.");else i("User token reset, skipping queue check.")}function ui(t=!1){t&&v.removeActiveSSEConnection(),(t||v.isSSEConnectionManagedBySDK())&&v.setUseSSEFlag(!1),ai&&(i("Stopping SSE queue listener..."),ai.close(),ai=null)}const pi="gist-debug-overlay-styles";let gi=null,mi=!1,hi=!1,fi=null;function bi(t){const e=t.properties?.gist;return ot(e?{...t,tooltipPosition:e.tooltipPosition??t.tooltipPosition,elementId:null!=e.elementId?String(e.elementId):t.elementId}:t)}function yi(t,e,n=!1){const i=D("div",{className:"gist-debug-msg-row"});return i.appendChild(D("span",{className:"gist-debug-msg-key",textContent:t})),i.appendChild(D("span",{className:n?"gist-debug-msg-val gist-debug-val-error":"gist-debug-msg-val",textContent:e})),i}function vi(t,e,n=!1){t.replaceChildren(...e.map(([t,e])=>yi(t,e,n)))}function wi(t,e){const n=D("div",{className:"gist-debug-msg"}),i=D("div",{className:"gist-debug-msg-meta"});if(i.appendChild(D("span",{className:"gist-debug-msg-type",textContent:bi(t)})),i.appendChild(D("span",{className:`gist-debug-msg-state gist-debug-msg-state--${e}`,textContent:e})),t.instanceId){const e=D("button",{className:"gist-debug-msg-dismiss",textContent:"×"});e.addEventListener("click",()=>{Ii(),Pi.dismissMessage(t.instanceId).then(()=>{Ii(),Ci()})}),i.appendChild(e)}n.appendChild(i);const o=[];for(const[e,i]of function(t){const e=t.properties?.gist,n=[];e?.routeRuleWeb&&n.push(["Route Rule",String(e.routeRuleWeb)]);const i=e?.elementId??t.elementId,o=bi(t);if(i&&"overlay"===o){const t=function(t){if(t)return et[t]}(String(i));t&&n.push(["Position",t.replace(/([A-Z])/g," $1").toLowerCase()])}else i&&"modal"!==o&&n.push(["Target",String(i)]);const s=e?.position??t.position;s&&"overlay"!==o&&n.push(["Position",String(s)]);const a=e?.tooltipPosition??t.tooltipPosition;return a&&n.push(["Tooltip",String(a)]),n}(t)){let t=null,s=null;if("Route Rule"===e){const e=!it(i);t=e?"gist-debug-route-mismatch":"gist-debug-element-found",s=e?"✕":"✓",e&&o.push("Route rule does not match current route. If it should, verify the route is set correctly and that analytics.page() is called on route changes.")}else if("Target"===e){const e=!!T(i);t=e?"gist-debug-element-found":"gist-debug-route-mismatch",s=e?"✓":"✕",e||o.push("Target element not found on the page. If it should, verify the selector is correct.")}const a=yi(e,i);t&&s&&a.appendChild(D("span",{className:t,textContent:s})),n.appendChild(a)}if(o.length>0){const t=D("ul",{className:"gist-debug-msg-details"});for(const e of o)t.appendChild(D("li",{textContent:e}));n.appendChild(t)}return n}function xi(t){const e=D("div",{className:"gist-debug-expand-detail"}),n=D("ul",{className:"gist-debug-expand-list"});return n.appendChild(D("li",{textContent:t})),e.appendChild(n),e}function Si(){gi&&(gi.root.remove(),document.getElementById(pi)?.remove(),null!==fi&&(clearInterval(fi),fi=null),mi&&(Pi.events&&(Pi.events.off("messageShown",$i),Pi.events.off("messageDismissed",$i),Pi.events.off("messageInboxUpdated",ki),Pi.events.off("routeChanged",$i)),mi=!1),gi=null)}function Ii(){if(!gi)return;Pi.config?vi(gi.configRows,[["Site ID",Pi.config.siteId],["Connection",v.useSSE()?"SSE":`Polling ${ye}s`]]):vi(gi.configRows,[["Status","NOT INITIALIZED"]],!0),gi.configDetail.style.display=Pi.config?"none":"";const t=Ee();t?ke()?gi.userValue.textContent="(anonymous)":gi.userValue.textContent=t.length>32?`${t.slice(0,32)}…`:t:gi.userValue.textContent="(none)";const e=Pi.currentRoute;gi.routeValue.replaceChildren(D("span",{className:e?"gist-debug-msg-val":"gist-debug-msg-val gist-debug-val-error",textContent:e??"NONE"})),gi.routeDetail.style.display=e?"none":""}async function Ci(){if(!hi&&gi){hi=!0;try{const t=Pi.currentMessages??[],[e,n]=Pi.config?await Promise.all([Fe(),Re()]):[[],[]],i=new Set(t.map(t=>t.queueId??t.messageId)),o=new Set,s=[...n,...e].filter(t=>{const e=t.queueId??t.messageId;return!i.has(e)&&!o.has(e)&&(o.add(e),!0)});if(!gi)return;const a=t.length+s.length;gi.messagesLabel.textContent=`Messages (${a})`,gi.messagesList.replaceChildren(...t.map(t=>wi(t,"active")),...s.map(t=>wi(t,"queued")))}finally{hi=!1}}}function $i(){Ii(),Ci()}function ki(){Ci()}async function Ei(){mi||(!mi&&Pi.events&&(Pi.events.on("messageShown",$i),Pi.events.on("messageDismissed",$i),Pi.events.on("messageInboxUpdated",ki),Pi.events.on("routeChanged",$i),mi=!0),mi&&ji(5e3)),Ii(),await Ci()}function ji(t){null!==fi&&clearInterval(fi),fi=setInterval(()=>{Ei()},t)}function Li(){if("undefined"!=typeof window&&"true"===new URLSearchParams(window.location.search).get("cio_debug_session"))try{gi||null!==fi||(N(pi,"\n #gist-debug-overlay {\n position: fixed; bottom: 16px; right: 16px;\n z-index: 99999999999;\n background: #08272B; color: white;\n font-family: system-ui, -apple-system, sans-serif;\n font-size: 11px;\n border-radius: 8px;\n box-shadow: 0 4px 12px rgba(0,0,0,0.3);\n width: 300px;\n max-height: min(700px, calc(100vh - 32px));\n display: flex;\n flex-direction: column;\n pointer-events: auto;\n overflow: hidden;\n }\n .gist-debug-header {\n display: flex; align-items: center;\n padding: 8px 12px;\n border-bottom: 1px solid rgba(255,255,255,0.1);\n flex-shrink: 0;\n }\n .gist-debug-title {\n flex: 1;\n font-weight: 700;\n font-size: 12px;\n letter-spacing: 0.02em;\n }\n #gist-debug-overlay-close {\n background: none; border: none;\n color: white; cursor: pointer;\n padding: 0; font-size: 18px; line-height: 1;\n opacity: 0.6; flex-shrink: 0;\n font-family: system-ui, -apple-system, sans-serif;\n -webkit-appearance: none; appearance: none;\n }\n #gist-debug-overlay-close:hover { opacity: 1; }\n .gist-debug-section {\n padding: 0 12px 8px;\n border-bottom: 1px solid rgba(255,255,255,0.07);\n overflow-y: auto;\n max-height: 180px;\n }\n .gist-debug-section:last-child { border-bottom: none; }\n .gist-debug-label {\n position: sticky;\n top: 0;\n z-index: 1;\n background: #08272B;\n display: flex;\n align-items: center;\n gap: 4px;\n font-size: 10px;\n text-transform: uppercase;\n letter-spacing: 0.08em;\n color: rgba(255,255,255,0.45);\n padding: 8px 0 5px;\n font-weight: 600;\n }\n .gist-debug-value {\n font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;\n font-size: 11px;\n color: rgba(255,255,255,0.9);\n overflow-wrap: break-word;\n }\n .gist-debug-msg {\n background: rgba(255,255,255,0.06);\n border-radius: 4px;\n padding: 5px 7px;\n margin-bottom: 8px;\n }\n .gist-debug-msg:last-child { margin-bottom: 0; }\n .gist-debug-msg-row {\n display: flex;\n align-items: center;\n gap: 6px;\n margin-bottom: 2px;\n }\n .gist-debug-msg-row:last-child { margin-bottom: 0; }\n .gist-debug-msg-meta {\n display: flex;\n align-items: center;\n gap: 5px;\n margin-bottom: 4px;\n }\n .gist-debug-msg-state {\n font-size: 9px;\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.05em;\n border-radius: 3px;\n padding: 1px 4px;\n flex-shrink: 0;\n }\n .gist-debug-msg-state--active {\n color: #4caf82;\n background: rgba(76,175,130,0.12);\n }\n .gist-debug-msg-state--queued {\n color: rgba(255,200,100,0.9);\n background: rgba(255,200,100,0.1);\n }\n .gist-debug-msg-dismiss {\n margin-left: auto;\n background: none;\n border: none;\n color: rgba(255,255,255,0.3);\n cursor: pointer;\n padding: 0;\n font-size: 13px;\n line-height: 1;\n font-family: system-ui, -apple-system, sans-serif;\n -webkit-appearance: none;\n appearance: none;\n }\n .gist-debug-msg-dismiss:hover { color: rgba(255,255,255,0.7); }\n .gist-debug-element-found {\n color: #4caf82;\n font-size: 9px;\n font-weight: 700;\n flex-shrink: 0;\n }\n .gist-debug-route-mismatch {\n color: #ff6b6b;\n font-size: 9px;\n font-weight: 700;\n flex-shrink: 0;\n }\n .gist-debug-msg-type {\n font-size: 9px;\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.05em;\n color: rgba(255,255,255,0.45);\n background: rgba(255,255,255,0.08);\n border-radius: 3px;\n padding: 1px 4px;\n flex-shrink: 0;\n }\n .gist-debug-msg-key {\n color: rgba(255,255,255,0.45);\n font-size: 10px;\n line-height: 1.4;\n min-width: 64px;\n flex-shrink: 0;\n }\n .gist-debug-msg-val {\n font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;\n font-size: 10px;\n line-height: 1.4;\n color: rgba(255,255,255,0.9);\n overflow-wrap: break-word;\n }\n .gist-debug-val-error {\n color: #ff6b6b;\n font-weight: 600;\n }\n .gist-debug-expand-detail {\n background: rgba(255,107,107,0.08);\n border-left: 2px solid rgba(255,107,107,0.4);\n color: rgba(255,255,255,0.75);\n font-family: system-ui, -apple-system, sans-serif;\n font-size: 10px;\n padding: 4px 6px;\n margin-top: 4px;\n margin-bottom: 6px;\n border-radius: 0 3px 3px 0;\n }\n .gist-debug-expand-list {\n margin: 0;\n padding: 0 0 0 14px;\n list-style: disc;\n }\n .gist-debug-expand-list li {\n margin-bottom: 3px;\n line-height: 1.4;\n }\n .gist-debug-expand-list li:last-child { margin-bottom: 0; }\n .gist-debug-msg-details {\n margin: 5px 0 0;\n padding: 0 0 0 14px;\n list-style: disc;\n color: rgba(255,255,255,0.5);\n font-size: 10px;\n line-height: 1.4;\n font-family: system-ui, -apple-system, sans-serif;\n }\n .gist-debug-msg-details li { margin-bottom: 2px; }\n .gist-debug-msg-details li:last-child { margin-bottom: 0; }\n"),gi=function(){const t=D("div",{id:"gist-debug-overlay"}),e=D("div",{className:"gist-debug-header"});e.appendChild(D("span",{className:"gist-debug-title",textContent:"Customer.io In-App SDK Debugger"}));const n=D("button",{id:"gist-debug-overlay-close",ariaLabel:"Dismiss debug overlay",textContent:"×"});n.addEventListener("click",Si),e.appendChild(n),t.appendChild(e);const i=D("div",{className:"gist-debug-section"}),o=D("div",{className:"gist-debug-label"});o.appendChild(D("span",{textContent:"Config"})),i.appendChild(o);const s=D("div",{});i.appendChild(s);const a=xi("Verify your site ID and credentials are correct.");i.appendChild(a),t.appendChild(i);const r=D("div",{className:"gist-debug-section"}),l=D("div",{className:"gist-debug-label",textContent:"User"});r.appendChild(l);const c=D("div",{className:"gist-debug-value"});r.appendChild(c),t.appendChild(r);const d=D("div",{className:"gist-debug-section"}),u=D("div",{className:"gist-debug-label"});u.appendChild(D("span",{textContent:"Route"})),d.appendChild(u);const p=D("div",{className:"gist-debug-value"});d.appendChild(p);const g=xi("The current route is used to match against potential message page rules.");d.appendChild(g),t.appendChild(d);const m=D("div",{className:"gist-debug-section"}),h=D("div",{className:"gist-debug-label"});m.appendChild(h);const f=D("div",{});return m.appendChild(f),t.appendChild(m),{root:t,configRows:s,configDetail:a,userValue:c,routeValue:p,routeDetail:g,messagesLabel:h,messagesList:f}}(),M(gi.root),ji(2e3),Ei())}catch(t){i(`Failed to initialize debug overlay: ${t}`)}}class Pi{static async setup(t){this.initialized?i("Gist SDK already initialized, skipping setup."):(this.initialized=!0,this.events=new n,this.config={useAnonymousSession:t.useAnonymousSession??!1,siteId:t.siteId,dataCenter:t.dataCenter,env:t.env??"prod",logging:t.logging??!1,experiments:t.experiments??!1,colorScheme:t.colorScheme??"default"},this.currentMessages=[],Pt.forEach(t=>t.cleanup()),Pt.clear(),document.querySelectorAll('[id^="gist-tooltip-"]').forEach(t=>{t.parentNode?.removeChild(t)}),this.overlayInstanceId=null,this.currentRoute=null,this.routeInitialized=!1,this.isDocumentVisible=!0,this.config.isPreviewSession=function(){const t=new URLSearchParams(window.location.search),e=t.get(Ze);if(e){sessionStorage.setItem(o,String(!1)),Pi.setUserToken(e),i(`Preview mode enabled with user token: ${e}`),function(){if(document.getElementById(on))return;N(nn,Ye);try{dn="true"===sessionStorage.getItem(en)}catch{dn=!1}const t=D("div",{id:on});document.body.appendChild(t),Nn()}();const n=t.get(tn);if(n)try{const t=JSON.parse(atob(n)),e=t.stepName||null,i=t.displayType||null;(e||i)&&function(t,e){yn=t,vn=e}(e,i)}catch{i("Preview bar: failed to parse cioPreviewSettings")}}return!l()}(),Li(),function(){const t=c();for(let e=t.length-1;e>=0;e--){const n=t.key(e);n?.startsWith("gist.")&&d(n)}}(),async function(){v.inboxEnabled()&&(E()&&P()||(i("Inbox enabled but missing cached branding/templates, fetching."),await be()),ce())}(),"auto"===this.config.colorScheme&&vt(),i(`Setup complete on ${this.config.env} environment.`),this.config.isPreviewSession||!this.config.useAnonymousSession||new URLSearchParams(location.search).has("ajs_uid")||je(),await ri(),setTimeout(()=>{this.routeInitialized||(this.routeInitialized=!0,li())},2e3),document.addEventListener("visibilitychange",async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await li())},!1))}static setupDebugOverlay(){Li()}static async setCurrentRoute(t){this.routeInitialized=!0,this.currentRoute=t,i(`Current route set to: ${t}`),await async function(){if(0!==Pi.currentMessages.length)for(const t of[...Pi.currentMessages])null==document.querySelector(`#gist-${t.instanceId}`)&&(i(`Removing active message ${t.instanceId} that no longer exists after route change`),await Un(t))}(),await li(),this.events?.dispatch("routeChanged",t)}static async setUserToken(t,e){this.config.isPreviewSession||(function(t,e){void 0===e&&(e=new Date).setDate(e.getDate()+30),s(Ie,t,e),ke()&&(r(we),r(Ce)),i(`Set user token "${t}" with expiry date set to ${e}`)}(t,e),ui(!0),await ri())}static setUserLocale(t){var e;s(I,e=t),i(`Set user locate to "${e}"`)}static setColorScheme(t){this.config.colorScheme=t,function(){const t=Pi.config?.colorScheme;"auto"===t?vt():yt&&(yt.disconnect(),yt=null);const e=ft(t);bt=e,wt(e)}(),i(`Color scheme set to: ${t}`)}static setCustomAttribute(t,e){return function(t,e){return t&&"string"==typeof t?(Ne.set(t,e),Me(),i(`Set custom attribute "${t}" to "${e}"`),!0):(i(`Invalid key for custom attribute: ${t}`),!1)}(t,e)}static clearCustomAttributes(){Ne.clear(),r(De),i("Cleared all custom attributes")}static removeCustomAttribute(t){return function(t){if(!t||"string"!=typeof t)return i(`Invalid key for custom attribute: ${t}`),!1;const e=Ne.has(t);return Ne.delete(t),Ne.size>0?Me():r(De),i(`Removed custom attribute "${t}"`),e}(t)}static async clearUserToken(){this.config.isPreviewSession||(Te(),ue(),this.config.useAnonymousSession&&je(),ui(!0),await ri())}static async dismissMessage(t){const e=J(t);e&&(await Hn(e),await ii(e),await Bn(e),await li())}static async embedMessage(t,e){const n=On(t,e);return n?.instanceId??null}static async showMessage(t){const e=await _n(t);return e?.instanceId??null}static updateMessageDisplaySettings(t,e){const n=J(t);return!!n&&(n.displaySettings=e,$t(n),!0)}static messageShown(t){i(`Message shown: ${t.messageId}`),this.events.dispatch("messageShown",t)}static messageDismissed(t){null!==t&&(i(`Message dismissed: ${t.messageId}`),this.events.dispatch("messageDismissed",t))}static messageError(t){i(`Message error: ${t.messageId}`),this.events.dispatch("messageError",t)}static messageAction(t,e,n){i(`Message action: ${t.currentRoute}, ${e} with name ${n} on ${t.instanceId}`),this.events.dispatch("messageAction",{message:t,action:e,name:n})}static async getInboxUnopenedCount(){return(await W()).filter(t=>!t.opened).length}static async getInboxMessages(){return await W()}static async updateInboxMessageOpenState(t,e){return await _(t,e)}static async removeInboxMessage(t){return await O(t)}static isInboxEnabled(){return v.inboxEnabled()}}let Ti=Pi;if("undefined"!=typeof window){const t=window;t.__gistWebLoaded?(console.warn("Gist: the SDK has been loaded more than once on this page; check for duplicate snippets or bundles."),t.Gist&&(Ti=t.Gist)):(t.__gistWebLoaded=!0,Li())}const Di=Ti;return e.default})());
|
|
1
|
+
!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:()=>Fi});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")&&!t.endsWith("snoozed"),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 w={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,w.getSdkId(),new Date((new Date).getTime()+w.getSSEHeartbeat()))},hasActiveSSEConnection:()=>a(f)??!1,isSSEConnectionManagedBySDK:()=>a(f)===w.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 v(t){return null!==t&&"object"==typeof t&&"response"in t}function x(t){return v(t)?t.response:void 0}function S(){const t=w.GIST_QUEUE_API_ENDPOINT[Ui.config.env??"prod"],e={"X-CIO-Site-Id":Ui.config.siteId,"X-CIO-Client-Platform":"web"},n=Te();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),v(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 $(){const t=a(I);return null!==t?t:navigator.language}const C="gist.web.branding";async function k(){if(null!==a(C))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(C,t.data,e),i("Branding fetched and cached.")}}function E(){return a(C)}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 P(){return a(j)}function T(t){try{return(document.getElementById(t)??document.querySelector(t))||null}catch{return null}}function N(t,e={}){const n=document.createElement(t);for(const[t,i]of Object.entries(e))n[t]=i;return n}function D(t,e){if(document.getElementById(t))return;const n=document.createElement("style");n.id=t,n.textContent=e,document.head.appendChild(n)}function A(t){document.body?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>document.body.appendChild(t),{once:!0})}async function M(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 U();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 U();if(!t)return[];const e=a(t)??[],n=new Date;return e.filter(t=>!t.expiry||new Date(t.expiry)>n)}async function O(t,e){const n=await U();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 _(t){const e=await U();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 M(t);(!l||l.status<200||l.status>=300)&&i(`Failed to log inbox message view: ${l?.status??"unknown error"}`)}async function U(){const t=await Pe();return t?`gist.web.inbox.messages.${t}`:null}const B={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 F(t){let e=B.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 H(t){const e=B,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:F(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 G=["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 V(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 J=["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"];function X(t){return Ui.currentMessages.find(e=>e.instanceId===t)}function K(t){return!!t&&Ui.currentMessages.some(e=>e.queueId===t)}function Q(t){return t?Ui.currentMessages.find(e=>e.elementId===t)??null:null}function Y(t){Ui.currentMessages=Ui.currentMessages.filter(e=>e.instanceId!==t)}function Z(t,e){Y(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){try{return(new URL(t,window.location.href).pathname.replace(/\/+$/,"")||"/")===(new URL(window.location.href).pathname.replace(/\/+$/,"")||"/")}catch{return!0}}function st(t){return t.tooltipPosition?"tooltip":t.overlay?"modal":t.elementId&&G.includes(t.elementId)?"overlay":t.elementId?"inline":"modal"}function at(t,e){const n=st(t),i=e.displayType;if(void 0===i)return!1;if(n!==i)return!0;const o=H(t);switch(i){case"modal":{if((t.position||"center")!==(e.modalPosition||"center"))return!0;const n=e.dismissOutsideClick??B.exitClick;if(o.exitClick!==n)return!0;const i=e.overlayColor??B.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||!J.includes(nt(e.overlayPosition))){const t=e.maxWidth??B.messageWidth;if(o.messageWidth!==t)return!0}return!1}function rt(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&&J.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 lt={top:["bottom","left","right"],bottom:["top","left","right"],left:["right","top","bottom"],right:["left","top","bottom"]},ct=/auto|scroll/,dt={top:"gist-arrow-bottom",bottom:"gist-arrow-top",left:"gist-arrow-right",right:"gist-arrow-left"};function ut(t){const e=T(t);return e||i(`Tooltip target element not found for selector: ${t}`),e}function pt(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 gt(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 mt(t,e,n){const i=gt(t,e,n);if(i)return i;for(const i of lt[n]){const n=gt(t,e,i);if(n)return n}return null}function ht(t){const e=[];let n=t.parentElement;for(;n;){const t=getComputedStyle(n),i=t.overflow+t.overflowX+t.overflowY;ct.test(i)&&e.push(n),n=n.parentElement}return e}function ft(t){return"system"===t||"auto"===t?"normal":"light only"}function bt(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 yt,wt=null;function vt(){wt||(yt=bt(Ui.config?.colorScheme),wt=new MutationObserver(()=>{const t=bt(Ui.config?.colorScheme);t!==yt&&(yt=t,xt(t))}),wt.observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]}),document.body&&wt.observe(document.body,{attributes:!0,attributeFilter:["style","class"]}))}function xt(t){const e=t??"normal",n=ft(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 St(t){const e=T(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 It(t){const e=T(t);if(e)return!(!e.style||!e.style.height||"0px"===e.style.height)}function $t(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=bt(Ui.config?.colorScheme);t&&(e.colorScheme=t);const o={options:e,capabilities:Ct};i.contentWindow.postMessage(o,"*")}}(t,e,n)})}const Ct=["MultiStepDisplayTypes","CrossPageStepNavigation","Snooze"];function kt(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 Et=null;function jt(){Et&&(document.removeEventListener("keydown",Et),Et=null)}async function Lt(){const t=document.querySelector(".gist-message");t&&(t.classList.remove("gist-visible"),await new Promise(t=>setTimeout(t,300))),Pt()}function Pt(){jt();const t=document.querySelector("#gist-embed-message");t&&t.parentNode?.removeChild(t)}const Tt=new Map;function Nt(t){const e=t.instanceId??"",n=Tt.get(e);n&&(n.cleanup(),Tt.delete(e));const i=T(`gist-tooltip-${e}`);i&&i.parentNode?.removeChild(i)}function Dt(t){return`gist-${t}`}function At(){const t=document.querySelector(".gist-message");t&&t.classList.add("gist-visible")}const Mt="jist",Rt={start:"flex-start",end:"flex-end",center:"center",stretch:"stretch",baseline:"baseline"},qt={start:"flex-start",end:"flex-end",center:"center","space-between":"space-between","space-around":"space-around","space-evenly":"space-evenly"};function zt(t){return"number"==typeof t?`${t}px`:"fill"===t?"100%":t}function Wt(t){try{return new Date(t).toLocaleDateString(navigator.language)}catch{return t}}class Ot{#t;#e;#n;#i=0;constructor({formatDate:t,onAction:e,templates:n}={}){this.#t=t||Wt,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=zt(t.gap)),t.align&&(n.style.alignItems=Rt[t.align]||t.align),t.justify&&(n.style.justifyContent=qt[t.justify]||t.justify),t.margin&&(t.margin.top&&(n.style.marginTop=zt(t.margin.top)),t.margin.right&&(n.style.marginRight=zt(t.margin.right)),t.margin.bottom&&(n.style.marginBottom=zt(t.margin.bottom)),t.margin.left&&(n.style.marginLeft=zt(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=zt(t.width)),t.height&&(s.style.height=zt(t.height)),t.objectFit&&(s.style.objectFit=t.objectFit),t.borderRadius&&(s.style.borderRadius=zt(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=zt(t.gap)),t.align&&(i.style.alignItems=Rt[t.align]||t.align),t.justify&&(i.style.justifyContent=qt[t.justify]||t.justify),t.margin&&(t.margin.top&&(i.style.marginTop=zt(t.margin.top)),t.margin.right&&(i.style.marginRight=zt(t.margin.right)),t.margin.bottom&&(i.style.marginBottom=zt(t.margin.bottom)),t.margin.left&&(i.style.marginLeft=zt(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 Ut="jist-template",Bt=["template","data","theme","mode","formatDate","onAction","templates"],Ft=new Set(["fontWeight","maxLines","lineHeight","opacity"]),Ht=new Set(["lineHeight","letterSpacing"]),Gt={"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"},Vt=["shadow-offset-x","shadow-offset-y","shadow-blur","shadow-color"],Jt={"shadow-offset-x":"0","shadow-offset-y":"0","shadow-blur":"0","shadow-color":"transparent"},Xt={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"])},Kt=["hover","active","disabled"],Qt=[["background-color","background-color"],["color","text-color"]];class Yt 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)}#w=null;#v=null;#x=null;#S=null;#I="auto";#t=null;#e=null;#n={};#$=null;#C=null;get template(){return this.#v}set template(t){this.#v=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.#$=window.matchMedia("(prefers-color-scheme: dark)"),this.#C=()=>{"auto"===this.#I&&(this.#E(),this.#k())},this.#$.addEventListener("change",this.#C);for(const t of Bt)this.#j(t);this.#E(),this.#k()}#j(t){if(!Object.prototype.hasOwnProperty.call(this,t))return;const e=this,n=e[t];delete e[t],e[t]=n}disconnectedCallback(){this.#$&&this.#C&&this.#$.removeEventListener("change",this.#C),this.#L(),_t.#P()}attributeChangedCallback(t,e,n){if(e!==n)switch(t){case"template":this.#v=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.#$?.matches??!1)}#E(){if(!this.isConnected)return void(this.#S||(this.#L(),_t.#P()));if(this.#T()?this.setAttribute("data-jist-dark",""):this.removeAttribute("data-jist-dark"),!this.#S)return this.#L(),void _t.#P();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.#N(this.#S,"--jist"),this.#T()){const t=this.#S.modes?.dark;t&&this.#N(t,"--jist")}this.#D()}#N(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&&Ht.has(n)?"normal":"number"!=typeof i||Ft.has(n)?String(i):`${i}px`;this.style.setProperty(t,e)}}else this.#N(i,t)}}#D(){const t=[],e=this.#S;if(!e)return;const n=e.modes?.dark;for(const i of Object.keys(Xt)){const o=e[i],s=n?.[i],a=Xt[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.#A(i,e,n,a))}}const i=t.join("\n");if(this.#L(),!i)return;let o=_t.#b.get(i);o||(o={id:_t.#f++,refs:0},_t.#b.set(i,o)),o.refs++,this.#w=i,this.setAttribute("data-jist-v",String(o.id)),_t.#P()}#L(){if(!this.#w)return;const t=_t.#b.get(this.#w);t&&(t.refs--,t.refs<=0&&_t.#b.delete(this.#w)),this.#w=null,this.removeAttribute("data-jist-v")}static#P(){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")}#A(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=Gt[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=Vt.map(t=>`var(--jist-button-${o}-${t}, var(--jist-button-${t}, ${Jt[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 Kt){const e=n.states?.[t],a=i.states?.[t];if(!e&&!a)continue;const r=[];for(const[e,n]of Qt){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.#v||!this.#x)return;if(!this.isConnected)return;const t=this.#n[this.#v];if(!t)return void(this.innerHTML="");const e=new Ot({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=Yt;const Zt="gist-inbox-button",te="gist-inbox-badge",ee="gist-inbox-panel",ne="gist-inbox-messages";let ie=!1,oe=!1;const se=new Set;let ae=null,re=null;function le(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]=le(e,o)}return n}function ce(t,e){const n=t?.patterns?.inbox;if(!n)return null;const i=t?.patterns?.modes?.dark?.inbox;return("dark"===e||null==e&&ae?.matches)&&i?le(n,i):n}function de(){ie||(ie=!0,function(){const t=customElements.get(Ut);t?t!==Yt&&console.warn("[jist] <jist-template> is already registered by another copy or version of the library; keeping the first registration."):customElements.define(Ut,Yt)}(),D("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=>{ue(t)}),Ui.events.on("colorSchemeChanged",()=>{ue()}),ae=window.matchMedia("(prefers-color-scheme: dark)"),re=()=>{"system"===Ui.config?.colorScheme&&ue()},ae.addEventListener("change",re),ue())}async function ue(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 pe();let n=E();n||(await ye(),n=E());const o=bt(Ui.config?.colorScheme),s=ce(n,o);if(s){if(function(t,e){let n=document.getElementById(Zt);n||(n=N("div",{id:Zt}),n.addEventListener("click",()=>{oe?(oe=!1,document.getElementById(ee)?.classList.remove("gist-inbox-panel--open")):(oe=!0,ue())}),A(n));const i=be(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(te);if(0===n||!e.unreadIndicator.showAlert)return void i?.remove();i||(i=N("span",{id:te}),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),oe){!function(t,e,n,o){let s=document.getElementById(ee);const a=!s;a&&(s=N("div",{id:ee}),A(s));const r=be(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(ne);l||(l=N("div",{id:ne}),s.appendChild(l)),l.innerHTML="";const c=P();e.forEach((s,a)=>{const r=N("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&&_(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=fe,u.data=s.properties??{},u.template=s.type??null,a<e.length-1){const e=N("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||se.has(e)||(se.add(e),O(e,!0).finally(()=>{se.delete(e)}))}}}else pe()}function pe(){document.getElementById(Zt)?.remove(),document.getElementById(ee)?.remove(),oe=!1}const ge=[[60,"second",1],[3600,"minute",60],[86400,"hour",3600],[2592e3,"day",86400],[31536e3,"month",2592e3],[1/0,"year",31536e3]];let me=null,he=null;function fe(t){const e=Math.round((Date.now()-new Date(t).getTime())/1e3);if(Number.isNaN(e))return t;const[,n,i]=ge.find(([t])=>Math.abs(e)<t);return function(){const t=$();return me&&he===t||(he=t,me=new Intl.RelativeTimeFormat(t,{numeric:"auto"})),me}().format(-Math.round(e/i),n)}function be(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 ye(){await Promise.all([k(),L()])}let we=600,ve=!1;const xe="gist.web.userQueueNextPullCheck",Se="gist.web.sessionId";function Ie(){let t=a(Se);return t||(t=g()),s(Se,t,new Date((new Date).getTime()+18e5)),String(t)}const $e="gist.web.userToken",Ce="gist.web.usingGuestUserToken",ke="gist.web.guestUserToken";function Ee(){return null!==a(Ce)}function je(){return a($e)}function Le(){if(null===je()){let t=a(ke);null==t&&(t=g(),s(ke,t),i(`Set guest user token "${t}" with expiry date set to 1 year from today`)),s($e,t),s(Ce,!0),i(`Using anonymous session with token: "${t}"`)}}async function Pe(){const t=je();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 Te(){const t=je();return null===t?null:btoa(t)}function Ne(){r($e),i("Cleared user token")}const De="gist.web.customAttributes";let Ae=new Map;function Me(){const t=Array.from(Ae.entries()),e=new Date;e.setDate(e.getDate()+30),s(De,t,e),i(`Saved ${Ae.size} custom attributes to storage with TTL of 30 days`)}async function Re(t){const e=await _e();if(!e)return;const n=new Date;n.setMinutes(n.getMinutes()+60),s(e,t.filter(We),n)}async function qe(){const t=await _e();return t?(a(t)??[]).filter(e=>{const n=e.properties.gist.broadcast,{frequency:i}=n,o=a(Be(t,e.queueId))??!0,s=a(Ue(t,e.queueId))||0,r=0===i.count;return o&&(r||s<i.count)}):[]}async function ze(t,e){const n=a(t);return n?.find(t=>t.queueId===e)}function We(t){return!(!t.properties?.gist||!t.properties.gist.broadcast)}function Oe(t){if(!We(t))return!1;const e=t.properties.gist.broadcast;return 0===e.frequency.delay&&0===e.frequency.count}async function _e(){const t=await Pe();return t?`gist.web.message.broadcasts.${t}`:null}function Ue(t,e){return`${t}.${e}.numberOfTimesShown`}function Be(t,e){return`${t}.${e}.shouldShow`}!function(){const t=a(De);if(t)try{Ae=new Map(t)}catch{Ae=new Map}else Ae=new Map}();const Fe="gist.web.message.user";async function He(t){const e=await Ve();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 Ge(){const t=await Ve();if(!t)return[];const e=a(t)??[],n=await async function(){const t=await Je();return t?a(t)??[]:[]}();return e.filter(t=>!n.includes(t.queueId??""))}async function Ve(){const t=await Pe();return t?`${Fe}.${t}`:null}async function Je(){const t=await Pe();return t?`${Fe}.${t}.seen`:null}async function Xe(t){const e=await Pe();return e?`${Fe}.${e}.message.${t}.loading`:null}async function Ke(t){const e=await Pe();return e?`${Fe}.${e}.message.${t}.state`:null}async function Qe(t){const e=await Pe();return e?`${Fe}.${e}.message.${t}.snoozed`:null}async function Ye(t,e,n){const o=await Ke(t);if(!o)return;const r=a(o)||{},l={stepName:void 0!==e?e:r.stepName,displaySettings:void 0!==n?n:r.displaySettings},c=new Date;c.setDate(c.getDate()+30),s(o,l,c),i(`Saved message state for queueId: ${t}`)}async function Ze(t){const e=await Ke(t);e&&(r(e),i(`Cleared message state for queueId: ${t}`))}function tn(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 en=`\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(tn("#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; white-space: nowrap; flex-shrink: 0;\n min-width: auto; box-sizing: border-box;\n -webkit-appearance: none; appearance: none;\n }\n .gist-pb-select-elem-btn:disabled {\n opacity: 0.4; cursor: not-allowed;\n }\n .gist-pb-spacer { flex: 1; min-width: 0; }\n .gist-pb-save-btn {\n height: 36px; padding: 0 18px;\n background: #08272B; color: white;\n border: none; border-radius: 6px;\n font-size: 13px; font-weight: 600;\n font-family: system-ui, -apple-system, sans-serif;\n cursor: pointer; white-space: nowrap; align-self: center;\n min-width: auto; box-sizing: border-box;\n -webkit-appearance: none; appearance: none;\n }\n .gist-pb-save-btn:disabled {\n background: #CAD6D8; cursor: not-allowed;\n }\n .gist-pb-picker-overlay {\n position: fixed; inset: 0; z-index: 999999999998; cursor: crosshair;\n }\n .gist-pb-checkbox { cursor: pointer; width: 14px; height: 14px; }\n .gist-pb-pick-highlight { outline: 2px solid #006FF5 !important; }\n .gist-pb-pick-error { outline: 2px solid #941616 !important; }\n #gist-preview-bar.gist-pb-hidden { display: none; }\n .gist-pb-ended-row {\n justify-content: center; align-items: center; gap: 10px; padding: 12px 16px;\n flex-wrap: nowrap;\n }\n .gist-pb-ended-icon {\n display: flex; align-items: center; justify-content: center;\n width: 22px; height: 22px; border-radius: 50%;\n background: #08272B; color: white;\n font-size: 13px; font-weight: 700; flex-shrink: 0;\n }\n .gist-pb-ended-text {\n margin: 0; font-size: 13px; color: #3F4E50;\n font-family: system-ui, -apple-system, sans-serif;\n min-width: 0;\n }\n .gist-pb-ended-text strong { color: #08272B; }\n @media (max-width: 1024px) {\n .gist-pb-controls-row { gap: 8px; }\n .gist-pb-label-group { flex: 1 1 100%; }\n .gist-pb-label-group--grow { flex: 1 1 100%; }\n .gist-pb-select { width: 100%; min-width: unset; box-sizing: border-box; }\n .gist-pb-input { width: 100% !important; box-sizing: border-box; }\n .gist-pb-color-control { width: 100%; }\n .gist-pb-checkbox-row { width: 100%; }\n .gist-pb-inline-row { flex-direction: row; align-items: center; }\n .gist-pb-inline-row .gist-pb-input { flex: 1; min-width: 0; }\n .gist-pb-save-btn { width: 100%; box-sizing: border-box; }\n .gist-pb-label--spacer { display: none; }\n }\n`;async function nn(t,e){try{return await S()(`/api/v1/preview/${t}`,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}})}catch(t){return x(t)}}const on="cioPreviewId",sn="cioPreviewSettings";const an="gist.previewBar.collapsed",rn="gist.previewBar.steps",ln="gist-pb-styles",cn="gist-preview-bar",dn={topLeft:"Top Left",topCenter:"Top Center",topRight:"Top Right",bottomLeft:"Bottom Left",bottomCenter:"Bottom Center",bottomRight:"Bottom Right"};let un=null,pn=[],gn={},mn=null,hn=!1,fn=!1,bn=5,yn=null,wn=!0,vn=!1,xn=!1,Sn=null,In=null,$n=null;const Cn=new Map;function kn(t,e){const n=N("div",{className:"gist-pb-label-group"});return n.appendChild(N("span",{className:"gist-pb-label",textContent:t})),n.appendChild(e),n}function En(t,e){const n=N("select",{className:"gist-pb-select"});for(const i of t){const t=N("option",{value:i.value,textContent:i.label});i.value===e&&(t.selected=!0),n.appendChild(t)}return n}function jn(t,e,n){const i=N("input",{className:"gist-pb-input",type:t,value:String(e)});return n&&(i.style.width=n),i}function Ln(t,e){const n=Math.round(Math.min(100,Math.max(0,e))/100*255);return"#"+t.replace("#","").toUpperCase()+n.toString(16).padStart(2,"0").toUpperCase()}function Pn(t){return!!("inline"!==t.displayType&&"tooltip"!==t.displayType||t.elementSelector?.trim())}function Tn(t){if("overlay"===t.displayType&&J.includes(nt(t.overlayPosition))){const{maxWidth:e,...n}=t;t=n}if(gn=t,mn){const e=pn.findIndex(t=>t.stepName===mn);-1!==e&&(pn[e]={...pn[e],displaySettings:{...t}})}if(!un)return;const e=Ui.currentMessages.find(t=>t.instanceId===un);e&&Pn(t)&&(kt(e),at(e,t)&&di(e,mn,t)),function(){const t=new URLSearchParams(window.location.search).get(on);t&&(Nn(),nn(t,pn).then(t=>{t&&404===t.status&&un&&Ui.dismissMessage(un)}).catch(()=>i("Failed to persist preview display settings")))}()}function Nn(){try{sessionStorage.setItem(rn,JSON.stringify(pn))}catch{}}function Dn(t){const e=t.value.trim();e&&!T(e)?t.classList.add("gist-pb-input--invalid"):t.classList.remove("gist-pb-input--invalid")}function An(t,e){const n=jn("text",t.elementSelector||"","260px");n.placeholder="Element ID or selector",Dn(n),n.addEventListener("change",()=>{const t=n.value.trim(),e=gn.elementSelector;t&&Mn(t),Tn({...gn,elementSelector:t}),e&&e!==t&&Rn(e),Dn(n)});const i=N("button",{type:"button",className:"gist-pb-select-elem-btn",textContent:"Select Element"});xn&&(i.disabled=!0),i.addEventListener("click",()=>zn(n));const o=N("div",{className:"gist-pb-inline-row"});o.appendChild(n),o.appendChild(i),e.appendChild(kn("Element Selector",o))}function Mn(t){if(!t||Cn.has(t))return;const e=T(t);e&&Cn.set(t,e.innerHTML)}function Rn(t){const e=Cn.get(t);if(void 0===e)return;const n=T(t);n&&(n.innerHTML=e)}function qn(){for(const t of Cn.keys())Rn(t);Cn.clear()}function zn(t){if(xn)return;xn=!0;const e=document.querySelector(`#${cn} .gist-pb-select-elem-btn`);e&&(e.disabled=!0);const n={...gn},o=Ui.currentMessages.find(t=>t.instanceId===un)??null;o&&li(o),gn.elementSelector&&Rn(gn.elementSelector);const s=N("div",{className:"gist-pb-picker-overlay"});let a=null;const r=t=>{s.style.pointerEvents="none";const e=document.elementFromPoint(t.clientX,t.clientY);s.style.pointerEvents="all",e&&e!==a&&e!==s&&(a?.classList.remove("gist-pb-pick-highlight"),a=e,a.classList.add("gist-pb-pick-highlight"))},l=t=>{if("Escape"===t.key){if(d(),gn=n,mn){const t=pn.findIndex(t=>t.stepName===mn);-1!==t&&(pn[t]={...pn[t],displaySettings:{...n}})}o&&Pn(n)&&di(o,mn,n),Wn()}},c=e=>{e.preventDefault(),e.stopPropagation(),s.style.pointerEvents="none";const n=document.elementFromPoint(e.clientX,e.clientY);if(s.style.pointerEvents="all",n&&n!==s){n.classList.remove("gist-pb-pick-highlight");const e=document.getElementById(cn),s=e?.contains(n)?null:function(t){if(t.id){const e=CSS.escape(t.id);if(1===document.querySelectorAll(`#${e}`).length)return t.id}const e=[];let n=t;for(;n&&"BODY"!==n.tagName&&"HTML"!==n.tagName;){if(n.id){const t=CSS.escape(n.id);if(1===document.querySelectorAll(`#${t}`).length){e.unshift(`#${t}`);break}}let t=n.tagName.toLowerCase();n.className&&"string"==typeof n.className&&(t+=n.className.trim().split(/\s+/).filter(Boolean).map(t=>`.${CSS.escape(t)}`).join(""));const i=n.parentElement;i&&(t+=`:nth-of-type(${Array.from(i.children).filter(t=>t.tagName===n.tagName).indexOf(n)+1})`),e.unshift(t);try{if(1===document.querySelectorAll(e.join(" > ")).length)break}catch{}n=n.parentElement}const o=e.join(" > ");try{if(1!==document.querySelectorAll(o).length)return i("buildUniqueSelector: could not produce a unique selector for element"),null}catch{return null}return o}(n);if(null===s)return n.classList.add("gist-pb-pick-error"),void setTimeout(()=>{n.classList.remove("gist-pb-pick-error"),n.classList.add("gist-pb-pick-highlight")},800);t.value=s,Mn(s);const a=gn.elementSelector,r={...gn,elementSelector:s},l=null!=o&&Pn(r)&&at(o,r);Tn(r),a&&a!==s&&Rn(a),o&&!l&&di(o,mn,r)}d(),Wn()},d=()=>{a?.classList.remove("gist-pb-pick-highlight"),s.removeEventListener("mousemove",r),s.removeEventListener("click",c),document.removeEventListener("keydown",l),document.body.removeChild(s),xn=!1,Sn=null};Sn=d,s.addEventListener("mousemove",r),s.addEventListener("click",c),document.addEventListener("keydown",l),document.body.appendChild(s)}function Wn(){const t=document.getElementById(cn);if(!t)return;if(t.classList.toggle("gist-pb-hidden",!un&&!fn),t.innerHTML="",!un){if(fn){const e=N("div",{className:"gist-pb-controls-row gist-pb-ended-row"}),n=N("span",{className:"gist-pb-ended-icon",textContent:"✓"}),i=N("p",{className:"gist-pb-ended-text"});if(i.innerHTML=_n(bn),e.appendChild(n),e.appendChild(i),wn){const t=N("button",{type:"button",className:"gist-pb-cancel-btn",textContent:"Cancel"});t.addEventListener("click",Un),e.appendChild(t)}t.appendChild(e)}return}const e=N("div",{className:"gist-pb-toggle-row"+(hn?" gist-pb-toggle-row--collapsed":"")}),n=N("button",{type:"button",className:"gist-pb-toggle-btn"}),i=hn?"transform:rotate(180deg);display:inline-flex;":"display:inline-flex;";if(n.innerHTML=`${hn?"Expand":"Collapse"}<span style="${i}">${tn("white")}</span>`,n.addEventListener("click",Bn),e.appendChild(n),t.appendChild(e),hn)return;const o=N("div",{className:"gist-pb-controls-row"});if(pn.length>0){const t=mn??pn[0].stepName,e=En(pn.map(t=>({value:t.stepName,label:t.stepName})),t);e.addEventListener("change",()=>{const t=pn.find(t=>t.stepName===e.value);if(t){mn=t.stepName,gn={...t.displaySettings};const e=Ui.currentMessages.find(t=>t.instanceId===un);e&&ci(e,t.stepName,t.displaySettings).then(n=>{!n&&Pn(t.displaySettings)&&di(e,t.stepName,t.displaySettings)}),Wn()}}),o.appendChild(kn("Step",e))}const s=En([{value:"modal",label:"Modal"},{value:"overlay",label:"Overlay"},{value:"inline",label:"Inline"},{value:"tooltip",label:"Tooltip"}],gn.displayType||"modal");s.addEventListener("change",()=>{const t=s.value,e=gn.displayType,n=gn.elementSelector,i={...gn,displayType:t};"modal"===t?(i.modalPosition=i.modalPosition||"center",i.maxWidth=i.maxWidth??414,delete i.overlayPosition,delete i.elementSelector,delete i.tooltipPosition):"overlay"===t?(i.overlayPosition=i.overlayPosition||"topCenter",i.maxWidth=i.maxWidth??414,delete i.modalPosition,delete i.elementSelector,delete i.tooltipPosition):"inline"===t?(delete i.modalPosition,delete i.overlayPosition,delete i.tooltipPosition):"tooltip"===t&&(i.tooltipPosition=i.tooltipPosition||"top",delete i.modalPosition,delete i.overlayPosition,delete i.overlayColor,delete i.dismissOutsideClick),gn=i,Tn(gn),"inline"!==e&&"tooltip"!==e||!n||"inline"===t||"tooltip"===t||Rn(n),Wn()}),o.appendChild(kn("Display Type",s));const a=gn.displayType||"modal";"modal"===a?function(t,e){const n=En([{value:"top",label:"Top"},{value:"center",label:"Center"},{value:"bottom",label:"Bottom"}],t.modalPosition||"center");n.addEventListener("change",()=>Tn({...gn,modalPosition:n.value})),e.appendChild(kn("Position",n));const i=jn("number",t.maxWidth??414,"80px");i.addEventListener("change",()=>Tn({...gn,maxWidth:parseInt(i.value)||414})),e.appendChild(kn("Max Width",i)),e.appendChild(function(t){const{color:e,opacity:n}=function(t){const e=t.replace("#","");return 8===e.length?{color:"#"+e.slice(0,6).toUpperCase(),opacity:Math.round(parseInt(e.slice(6),16)/255*100)}:6===e.length?{color:"#"+e.toUpperCase(),opacity:100}:{color:"#000000",opacity:20}}(t.overlayColor||"#00000033"),i=N("div",{className:"gist-pb-color-control"}),o=N("input",{className:"gist-pb-color-input",type:"color",value:e}),s=N("div",{className:"gist-pb-color-swatch"});s.style.background=e,s.appendChild(o),s.addEventListener("click",()=>o.click());const a=N("input",{className:"gist-pb-color-hex",type:"text",maxLength:6,value:e.replace("#","")}),r=N("input",{className:"gist-pb-color-opacity",type:"number",min:"0",max:"100",value:String(n)}),l=N("span",{className:"gist-pb-color-pct",textContent:"%"}),c=()=>{const t="#"+a.value.replace("#",""),e=parseInt(r.value)||0;s.style.background=t,o.value=t,Tn({...gn,overlayColor:Ln(t,e)})};return o.addEventListener("input",()=>{a.value=o.value.replace("#","").toUpperCase(),s.style.background=o.value}),o.addEventListener("change",c),a.addEventListener("change",c),r.addEventListener("change",c),i.appendChild(s),i.appendChild(a),i.appendChild(r),i.appendChild(l),kn("Overlay Color",i)}(t));const o=N("div",{className:"gist-pb-checkbox-row"}),s=N("input",{className:"gist-pb-checkbox",type:"checkbox"});s.checked=t.dismissOutsideClick??!1;const a=N("label",{className:"gist-pb-checkbox-label",textContent:"Dismiss on click outside"});s.addEventListener("change",()=>Tn({...gn,dismissOutsideClick:s.checked})),a.addEventListener("click",()=>{s.checked=!s.checked,Tn({...gn,dismissOutsideClick:s.checked})}),o.appendChild(s),o.appendChild(a);const r=kn(" ",o);r.classList.add("gist-pb-label-group--grow"),r.firstChild.classList.add("gist-pb-label--spacer"),e.appendChild(r)}(gn,o):"overlay"===a?function(t,e){const n=En(Object.entries(dn).map(([t,e])=>({value:t,label:e})),t.overlayPosition||"topCenter");if(n.addEventListener("change",()=>Tn({...gn,overlayPosition:n.value})),e.appendChild(kn("Position",n)),!J.includes(nt(t.overlayPosition))){const n=jn("number",t.maxWidth??414,"80px");n.addEventListener("change",()=>Tn({...gn,maxWidth:parseInt(n.value)||414})),e.appendChild(kn("Max Width",n))}}(gn,o):"inline"===a?function(t,e){An(t,e)}(gn,o):"tooltip"===a&&function(t,e){const n=En([{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"left",label:"Left"},{value:"right",label:"Right"}],t.tooltipPosition||"top");n.addEventListener("change",()=>Tn({...gn,tooltipPosition:n.value})),e.appendChild(kn("Position",n)),An(t,e)}(gn,o),o.appendChild(N("div",{className:"gist-pb-spacer"}));const r=N("button",{type:"button",className:"gist-pb-save-btn",textContent:"End session"});r.addEventListener("click",async()=>{un&&await Ui.dismissMessage(un)}),o.appendChild(r),t.appendChild(o)}async function On(){if(!vn)if(vn=!0,function(){try{sessionStorage.removeItem(rn)}catch{}}(),Ne(),function(){try{sessionStorage.removeItem(o)}catch{}}(),wn){try{window.close()}catch{}try{window.location.reload()}catch{}Sn&&Sn(),yn&&(clearInterval(yn),yn=null),qn(),document.getElementById(cn)?.remove(),document.getElementById(ln)?.remove(),un=null,pn=[],gn={},mn=null,fn=!1,bn=5,wn=!0,vn=!1}else fn=!1,vn=!1,Wn()}function _n(t){return wn?`<strong>Preview session ended.</strong> This tab will close in ${t}s…`:`<strong>Preview session ended.</strong> Finishing session in ${t}s… This tab will stay open.`}function Un(){fn&&yn&&(wn=!1,Wn())}function Bn(){hn=!hn;try{sessionStorage.setItem(an,String(hn))}catch{}Wn()}function Fn(t){if(fn)return;un=t.instanceId??null;const e=t.displaySettings;if(Array.isArray(e)&&e.length>0?(pn=e,function(t){let e;try{const t=sessionStorage.getItem(rn);if(!t)return;e=JSON.parse(t)}catch{return}if(Array.isArray(e))for(const n of e){const e=t.findIndex(t=>t.stepName===n.stepName);-1!==e&&n.displaySettings&&(t[e]={...t[e],displaySettings:{...t[e].displaySettings,...n.displaySettings}})}}(pn),mn||(mn=pn[0].stepName,gn={...pn[0].displaySettings})):e&&"object"==typeof e&&!Array.isArray(e)&&(gn={...e}),In||$n){const t=!!In,e=!!$n,n=In,o=$n;if(In=null,$n=null,t){const t=pn.find(t=>t.stepName===n);if(!t)return i(`Preview bar: step "${n}" not found, ignoring initial step/display override`),void Wn();mn=t.stepName,gn={...t.displaySettings}}if(e){if(!t)return i(`Preview bar: display type "${o}" provided without a step, ignoring`),void Wn();gn={...gn,displayType:o}}Wn();const s=Ui.currentMessages.find(t=>t.instanceId===un);return void(s&&Pn(gn)?di(s,mn,gn):function(){const t=gn.displayType;if("inline"!==t&&"tooltip"!==t)return;const e=document.querySelector("#gist-preview-bar .gist-pb-input[type='text']");e&&zn(e)}())}Wn()}function Hn(){qn(),un=null,pn=[],gn={},mn=null,fn=!0,bn=5,wn=!0,vn=!1;const t=new URLSearchParams(window.location.search).get(on);t&&async function(t){try{return await S()(`/api/v1/preview/${t}`,{method:"DELETE"})}catch(t){return x(t)}}(t).catch(()=>i("Failed to delete preview session")),Wn(),yn&&clearInterval(yn),yn=setInterval(async()=>{if(bn-=1,bn<=0)clearInterval(yn),yn=null,await On();else{const t=document.querySelector(`#${cn} .gist-pb-ended-text`);t?t.innerHTML=_n(bn):Wn()}},1e3)}const Gn=60;async function Vn(t){if(!Ui.isDocumentVisible)return i("Document hidden, not showing message now."),null;if(K(t.queueId))return i(`Message with queueId ${t.queueId} is already showing.`),null;const e=H(t);return!t.tooltipPosition&&e.hasTooltipPosition&&(t.tooltipPosition=e.tooltipPosition),t.tooltipPosition?function(t,e){const n=e.elementId||t.elementId,o=Ui.config.isPreviewSession&&t.properties?.gist?.livePreview;if(n){if(!T(n)){if(!o)return i(`Tooltip target element "${n}" not found for message ${t.messageId}, skipping display`),Ui.messageError(t),null;i(`Preview: tooltip target "${n}" not found, loading message for preview bar`)}}else{if(!o)return i(`No target selector specified for tooltip message ${t.messageId}`),Ui.messageError(t),null;i("Preview: no tooltip target yet, loading message for preview bar")}const s=Ui.currentMessages.find(t=>t.tooltipPosition&&t.elementId===n);s&&(i(`Tooltip already showing on target "${n}" (instance ${s.instanceId}), dismissing it first`),Ui.messageDismissed(s),Nt(s),s.instanceId&&Y(s.instanceId)),t.instanceId=g(),t.overlay=!1,t.firstLoad=!0,t.shouldResizeHeight=!1,t.shouldScale=!1,t.renderStartTime=(new Date).getTime(),t.elementId=n,Ui.currentMessages.push(t);return ni(t,null,t.savedStepName||null)}(t,e):Ui.overlayInstanceId?(i(`Message ${Ui.overlayInstanceId} already showing.`),null):(t.instanceId=g(),t.overlay=!0,t.firstLoad=!0,t.shouldResizeHeight=!0,t.shouldScale=e.shouldScale,t.renderStartTime=(new Date).getTime(),Ui.overlayInstanceId=t.instanceId,Ui.currentMessages.push(t),ni(t,null,t.savedStepName||null))}function Jn(t,e){return Ui.isDocumentVisible?K(t.queueId)?(i(`Message with queueId ${t.queueId} is already showing.`),null):Q(e)?(i(`Message with elementId ${e} already has a message.`),null):(t.instanceId=g(),t.overlay=!1,t.firstLoad=!0,t.shouldScale=!1,t.elementId=e,t.shouldResizeHeight=!It(e),t.renderStartTime=(new Date).getTime(),Ui.currentMessages.push(t),ni(t,e,t.savedStepName||null)):(i("Document hidden, not showing message now."),null)}async function Xn(t){t?(Ui.messageDismissed(t),await Kn(t)):i("Message not found")}async function Kn(t){"tooltip"===st(t)?Zn(t):t.overlay?await ti(!0,t):Yn(t)}async function Qn(t){t?H(t).persistent&&(i("Persistent message dismissed, logging view"),await ui(t),await ii(t),await Ze(t.queueId??"")):i("Message not found")}function Yn(t){t.instanceId&&Y(t.instanceId),t.elementId&&St(t.elementId),Ui.config.isPreviewSession&&(Hn(),ei())}function Zn(t){Nt(t),t.instanceId&&Y(t.instanceId),0===Ui.currentMessages.length&&(window.removeEventListener("message",ai),window.removeEventListener("touchstart",oi)),Ui.config.isPreviewSession&&(Hn(),ei())}async function ti(t,e){t?await Lt():Pt(),0===Ui.currentMessages.length&&(window.removeEventListener("message",ai),window.removeEventListener("touchstart",oi)),e.instanceId&&Y(e.instanceId),Ui.overlayInstanceId=null,Ui.config.isPreviewSession&&(Hn(),ei())}function ei(){const t=new URL(window.location.href);t.searchParams.delete(on),t.searchParams.delete(sn),history.replaceState(null,"",t.toString())}function ni(t,e=null,n=null){const o=Ui.config.env,s={endpoint:w.ENGINE_API_ENDPOINT[o],siteId:Ui.config.siteId,dataCenter:Ui.config.dataCenter,messageId:t.messageId,instanceId:t.instanceId??"",livePreview:!1,properties:t.properties,customAttributes:Object.fromEntries(new Map(Ae))};let a=`${w.GIST_VIEW_ENDPOINT[o]}/index.html`;return"undefined"!=typeof window&&window.crossOriginIsolated&&(a=`${a}?coi=1`,i("Cross-origin-isolated page detected, requesting renderer with COEP headers")),window.addEventListener("message",ai),window.addEventListener("touchstart",oi),"tooltip"===st(t)?function(t,e,n,i=null){const o=e.instanceId??"",s=Dt(o),a=H(e),r=Tt.get(o);r&&(r.cleanup(),Tt.delete(o)),document.querySelectorAll(`#gist-tooltip-${o}`).forEach(t=>{t.parentNode?.removeChild(t)});const l=`gist-tooltip-${o}`,c=document.createElement("div");c.id=l;const d=ft(Ui.config?.colorScheme);c.innerHTML=function(t,e,n,i="",o="light only"){let s=600;e.messageWidth>s&&(s=e.messageWidth);const a=e.tooltipArrowColor,r=function(t){switch(t){case"top":default:return"gist-arrow-bottom";case"bottom":return"gist-arrow-top";case"left":return"gist-arrow-right";case"right":return"gist-arrow-left"}}(e.tooltipPosition),l=i?`#${i} `:"";return`\n <div class="gist-tooltip-outer">\n <style>\n ${l}.gist-tooltip-outer {\n position: absolute;\n }\n ${l}.gist-tooltip-container {\n position: relative;\n z-index: 9999999;\n opacity: 0;\n transition: opacity 0.3s ease-in-out;\n }\n ${l}.gist-tooltip-container.gist-visible {\n opacity: 1;\n }\n ${l}.gist-tooltip-frame-clip {\n overflow: hidden;\n }\n ${l}.gist-tooltip-frame {\n display: block;\n width: ${e.messageWidth}px;\n border: none;\n transition: height 0.1s ease-in-out;\n color-scheme: ${o};\n }\n ${l}.gist-tooltip-arrow {\n width: 0;\n height: 0;\n position: absolute;\n z-index: 1;\n }\n ${l}.gist-tooltip-arrow.gist-arrow-bottom {\n bottom: 0;\n left: 50%;\n transform: translateX(-50%) translateY(100%);\n border-left: 10px solid transparent;\n border-right: 10px solid transparent;\n border-top: 10px solid ${a};\n }\n ${l}.gist-tooltip-arrow.gist-arrow-top {\n top: 0;\n left: 50%;\n transform: translateX(-50%) translateY(-100%);\n border-left: 10px solid transparent;\n border-right: 10px solid transparent;\n border-bottom: 10px solid ${a};\n }\n ${l}.gist-tooltip-arrow.gist-arrow-right {\n right: 0;\n top: 50%;\n transform: translateY(-50%) translateX(100%);\n border-top: 10px solid transparent;\n border-bottom: 10px solid transparent;\n border-left: 10px solid ${a};\n }\n ${l}.gist-tooltip-arrow.gist-arrow-left {\n left: 0;\n top: 50%;\n transform: translateY(-50%) translateX(-100%);\n border-top: 10px solid transparent;\n border-bottom: 10px solid transparent;\n border-right: 10px solid ${a};\n }\n @media (max-width: ${s}px) {\n ${l}.gist-tooltip-frame {\n max-width: 100%;\n }\n }\n </style>\n <div class="gist-tooltip-container">\n <div class="gist-tooltip-arrow ${r}"></div>\n <div class="gist-tooltip-frame-clip">\n <iframe id="${t}" class="gist-tooltip-frame" src="${n}"></iframe>\n </div>\n </div>\n </div>`}(s,a,t,l,d),document.body.appendChild(c),$t(s,n,i)}(a,t,s,n):e?(G.includes(e)&&V(e),function(t,e,n,o,s=null){const a=T(t);if(a){const i=Dt(n.instanceId??"");a.classList.add(i);const r=H(n);let l=r.messageWidth+"px";J.includes(t)&&!r.hasCustomWidth&&(l="100%"),G.includes(t)&&(a.style.width=l),It(t)||(a.style.height="0px"),a.innerHTML=function(t,e,n){const i=ft(Ui.config?.colorScheme);return function(t,e,n,i="light only"){let o=800;return e.messageWidth>o&&(o=e.messageWidth),`\n <div id="gist-embed">\n <style>\n #x-gist-floating-top, #x-gist-floating-top-left, #x-gist-floating-top-right {\n position: fixed;\n top: 0px;\n z-index: 1000000;\n }\n #x-gist-floating-bottom, #x-gist-floating-bottom-left, #x-gist-floating-bottom-right {\n position: fixed;\n bottom: 0px;\n z-index: 1000000;\n }\n #x-gist-bottom, #x-gist-top, #x-gist-floating-top, #x-gist-floating-bottom {\n left: 50%;\n transform: translate(-50%, 0%);\n }\n #x-gist-floating-top-right, #x-gist-floating-bottom-right {\n right: 0px;\n }\n #gist-embed {\n position: relative;\n height: 100%;\n width: 100%;\n }\n #gist-embed-container {\n position: relative;\n height: 100%;\n width: 100%;\n }\n #gist-embed-container .gist-frame {\n height: 100%;\n width: 100%;\n border: none;\n color-scheme: ${i};\n }\n #x-gist-top.${t},\n #x-gist-bottom.${t},\n #x-gist-floating-top.${t},\n #x-gist-floating-bottom.${t},\n #x-gist-floating-top-left.${t},\n #x-gist-floating-top-right.${t},\n #x-gist-floating-bottom-left.${t},\n #x-gist-floating-bottom-right.${t} {\n transition: height 0.1s ease-in-out;\n }\n @media (max-width: ${o}px) {\n #x-gist-top.${t},\n #x-gist-bottom.${t},\n #x-gist-floating-top.${t},\n #x-gist-floating-bottom.${t},\n #x-gist-floating-top-left.${t},\n #x-gist-floating-top-right.${t},\n #x-gist-floating-bottom-left.${t},\n #x-gist-floating-bottom-right.${t} {\n width: 100% !important;\n }\n }\n </style>\n <div id="gist-embed-container">\n <iframe id="${t}" class="gist-frame" src="${n}"></iframe>\n </div>\n </div>`}(Dt(e.instanceId??""),n,t,i)}(e,n,r),$t(i,o,s)}else i(`Message could not be embedded, elementId ${t} not found.`)}(e,a,t,s,n)):function(t,e,n,i=null){jt(),document.querySelectorAll("#gist-embed-message").forEach(t=>{t.parentNode?.removeChild(t)}),document.body.insertAdjacentHTML("afterbegin",function(t,e){const n=H(e),i=ft(Ui.config?.colorScheme);return function(t,e,n,i="light only"){let o=600;return e.messageWidth>o&&(o=e.messageWidth),`\n <div id="gist-embed-message">\n <style>\n #gist-overlay.gist-background {\n position: fixed;\n z-index: 9999999998;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n background-color: ${e.overlayColor};\n visibility: hidden;\n }\n #gist-overlay.gist-background.gist-visible {\n visibility: visible;\n }\n .gist-message {\n width: ${e.messageWidth}px;\n position: absolute;\n border: none;\n opacity: 0;\n transition: opacity 0.3s ease-in-out, height 0.1s ease-in-out;\n z-index: 9999999999;\n left: 50%;\n transform: translateX(-50%);\n color-scheme: ${i};\n }\n .gist-message.gist-visible {\n opacity: 1;\n pointer-events: auto;\n }\n .gist-message.gist-center {\n transform: translate(-50%, -50%);\n top: 50%;\n }\n .gist-message.gist-bottom {\n bottom: 0;\n }\n .gist-message.gist-top {\n top: 0;\n }\n @media (max-width: ${o}px) {\n .gist-message {\n width: 100%;\n }\n }\n </style>\n <div id="gist-overlay" class="gist-background">\n <iframe id="${t}" class="gist-message" src="${n}"></iframe>\n </div>\n </div>`}(Dt(e.instanceId??""),n,t,i)}(t,e)),$t(Dt(e.instanceId??""),n,i)}(a,t,s,n),t}async function ii(t){let e;i(`Message shown, logging view for: ${t.messageId}`),null!=t.queueId?(await ui(t),e=await M(t.queueId)):e=await async function(t){try{return await S().post(`/api/v1/logs/message/${t}`)}catch(t){return x(t)}}(t.messageId),i(200===e?.status?"Message view logged":`Problem logging message: ${e?.status}`)}function oi(){}function si(t){if(t.startsWith("mailto:")||t.startsWith("https://")||t.startsWith("http://")||t.startsWith("/"))window.location.href=t;else try{const e=new URL(t,window.location.href);"https:"===e.protocol||"http:"===e.protocol?window.location.href=e.href:i(`Refusing to navigate to non-http(s) target: ${t}`)}catch{i(`Refusing to navigate to unparseable target: ${t}`)}}async function ai(t){const e=Ui.config.env,n=t.data;if(n.gist&&t.origin===w.RENDERER_HOST[e]){const t=n.gist.instanceId,e=X(t);if(!e)return;const o=H(e);switch(n.gist.method){case"routeLoaded":{const s=.001*((new Date).getTime()-(e.renderStartTime??0));if(i(`Engine render for message: ${e.messageId} timer elapsed in ${s.toFixed(3)} seconds`),async function(t){const e=await Xe(t);e&&r(e)}(e.queueId??""),e.currentRoute=n.gist.parameters.route,n.gist.parameters.fullDisplaySettings&&!e.displaySettings?e.displaySettings=n.gist.parameters.fullDisplaySettings:e.displaySettings&&(i("SDK already has display settings state, sending it to iframe"),kt(e)),Ui.config.isPreviewSession&&e.properties?.gist?.livePreview&&Fn(e),e.firstLoad||e.isDisplayChange){if("tooltip"===st(e)){const t=e.properties?.gist?.elementId||e.elementId||void 0;if(!t||!T(t)){if(Ui.config.isPreviewSession&&e.properties?.gist?.livePreview){i(`Preview: tooltip target "${t}" not found, preview bar will show element picker`),e.firstLoad=!1,e.isDisplayChange=!1;break}i(`Tooltip target not found for "${t}", emitting error and skipping display`),Ui.messageError(e),e.firstLoad=!1,e.isDisplayChange=!1,Zn(e);break}const n=await async function(t){const e=t.instanceId??"",n=H(t),o=`gist-tooltip-${e}`,s=T(o);if(!s)return i(`Tooltip wrapper not found for instance ${e}`),!1;const a=t.properties?.gist?.elementId||t.elementId||void 0;if(!a)return i(`No target selector for tooltip ${e}`),!1;const r=Tt.get(e);r&&(r.cleanup(),Tt.delete(e));const l=s.querySelector(".gist-tooltip-outer");if(!l)return i(`Tooltip inner element not found for instance ${e}`),!1;const c=n.tooltipPosition||"bottom";if(!await async function(t,e,n){const o=ut(e);if(!o)return!1;let s=[];try{s=ht(o)}catch{}if(pt(o.getBoundingClientRect(),s))return!0;if(!function(t,e,n){const i=ut(e);if(!i)return!1;const o=i.getBoundingClientRect(),s=window.innerWidth,a=window.innerHeight,r=new DOMRect(Math.max(0,(s-o.width)/2),Math.max(0,(a-o.height)/2),o.width,o.height);return t.style.display="",null!==mt(t.getBoundingClientRect(),r,n)}(t,e,n))return i(`Preflight failed: tooltip would not fit after scrolling target "${e}" into view`),!1;o.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),await function(t){return new Promise(e=>{let n=t.getBoundingClientRect(),i=0;const o=Date.now();setTimeout(function s(){const a=t.getBoundingClientRect();Math.abs(a.top-n.top)<1&&Math.abs(a.left-n.left)<1?i++:i=0,n=a,i>=2||Date.now()-o>1e3?e():setTimeout(s,50)},50)})}(o);const a=o.getBoundingClientRect();let r=[];try{r=ht(o)}catch{}return pt(a,r)}(l,a,c))return i(`Tooltip for instance ${e} skipped: target "${a}" is off-screen and cannot be scrolled into a valid position`),!1;const d=function(t,e,n,o){const s=ut(e);if(!s)return null;let a=null,r=null,l=!1,c=[],d=null;try{c=ht(s)}catch{}function u(){if(l)return;if(!s||!document.contains(s)||!document.contains(t))return i("Tooltip or target element removed from DOM, cleaning up listeners"),g(),void o?.onDetach?.();const e=s.getBoundingClientRect();if(!pt(e,c))return void(t.style.display="none");t.style.display="";const a=mt(t.getBoundingClientRect(),e,n);a?(function(t,e){t.style.position="absolute",t.style.top=`${e.top+window.scrollY}px`,t.style.left=`${e.left+window.scrollX}px`}(t,a),function(t,e){const n=t.querySelector(".gist-tooltip-arrow");n&&(n.classList.remove("gist-arrow-top","gist-arrow-bottom","gist-arrow-left","gist-arrow-right"),n.classList.add(dt[e.position]),null!==e.arrowOffset?"top"===e.position||"bottom"===e.position?(n.style.left=`calc(50% + ${e.arrowOffset}px)`,n.style.removeProperty("top")):(n.style.top=`calc(50% + ${e.arrowOffset}px)`,n.style.removeProperty("left")):"top"===e.position||"bottom"===e.position?(n.style.left="50%",n.style.removeProperty("top")):(n.style.top="50%",n.style.removeProperty("left")))}(t,a)):t.style.display="none"}function p(){null===a&&(a=requestAnimationFrame(()=>{a=null,u()}))}function g(){if(!l){l=!0,d&&(d.disconnect(),d=null),window.removeEventListener("scroll",p),window.removeEventListener("resize",p);for(const t of c)t.removeEventListener("scroll",p);null!==a&&(cancelAnimationFrame(a),a=null),null!==r&&(cancelAnimationFrame(r),r=null)}}if(u(),l)return null;window.addEventListener("scroll",p,{passive:!0}),window.addEventListener("resize",p,{passive:!0});for(const t of c)t.addEventListener("scroll",p,{passive:!0});try{d=new MutationObserver(()=>{null===r&&(r=requestAnimationFrame(()=>{r=null,document.contains(s)||u()}))}),d.observe(document.body,{childList:!0,subtree:!0})}catch{}return{cleanup:g,reposition:u}}(l,a,c,{onDetach:()=>{Tt.delete(e);const t=T(o);t&&t.parentNode?.removeChild(t)}});if(d){if("none"!==l.style.display){const t=s.querySelector(".gist-tooltip-container");return t?(Tt.set(e,d),t.classList.add("gist-visible"),!0):(d.cleanup(),i(`Tooltip container not found for instance ${e}`),!1)}return d.cleanup(),i(`Tooltip for instance ${e} could not be positioned within the viewport, target "${a}" may be off-screen`),!1}return i(`Failed to position tooltip for instance ${e}, target "${a}" may not exist or no position fits the viewport`),!1}(e);if(!n){if(Ui.config.isPreviewSession&&e.properties?.gist?.livePreview){i(`Preview: tooltip positioning failed for "${t}", preview bar will remain active`),e.firstLoad=!1,e.isDisplayChange=!1;break}i(`Tooltip positioning failed for "${t}", emitting error and cleaning up`),Ui.messageError(e),e.firstLoad=!1,e.isDisplayChange=!1,Zn(e);break}}else e.overlay?function(t){const e=H(t),n=document.querySelector("#gist-overlay");if(n){n.classList.add("gist-visible");const o=document.querySelector(".gist-message");o&&(t.position?o.classList.add("gist-"+t.position):o.classList.add("gist-center")),setTimeout(At,100),e.exitClick&&(i=t.instanceId??"",jt(),Et=t=>{"Escape"===t.key&&Ui.dismissMessage(i)},document.addEventListener("keydown",Et),setTimeout(()=>function(t){const e=document.querySelector("#gist-overlay");e&&e.addEventListener("click",()=>{Ui.dismissMessage(t)})}(t.instanceId??""),1e3))}else Pt();var i}(e):function(t){const e=T(t);e&&e.classList.add("gist-visible")}(e.elementId);e.firstLoad&&!e.isDisplayChange&&(Ui.messageShown(e),o.persistent?i("Persistent message shown, skipping logging view"):await ii(e)),e.firstLoad=!1,e.isDisplayChange=!1}Z(t,e);break}case"tap":{const t=n.gist.parameters.action,a=n.gist.parameters.name;if(Ui.messageAction(e,t,a),n.gist.parameters.system&&!o.persistent){await Xn(e);break}try{const n=new URL(t);if(n&&"gist:"===n.protocol)switch(n.href.replace("gist://","").split("?")[0]){case"close":await Qn(e),await pi(e),await Xn(e),await vi();break;case"snooze":{const t=Number.parseInt(n.searchParams.get("showIn")??"",10),a=Number.isFinite(t)&&t>0?t:Gn;o.persistent&&e.queueId?(await async function(t,e){const n=await Qe(t);if(!n)return;const o=Math.min(Math.max(Math.floor(e),1),43200);s(n,!0,new Date(Date.now()+60*o*1e3)),i(`Snoozed message ${t} for ${o} minutes`)}(e.queueId,a),function(t){const e=60*t*1e3;e>2**31-1||setTimeout(()=>{vi()},e)}(a)):(i("Snooze is only supported for persistent queue messages, closing instead"),await Qn(e),await pi(e)),await Xn(e),await vi();break}case"showMessage":{const t=n.searchParams.get("messageId"),e=n.searchParams.get("properties");if(t){const n=e?JSON.parse(atob(e)):void 0;await Ui.showMessage({messageId:t,properties:n})}break}case"loadPage":{const t=n.href.substring(n.href.indexOf("?url=")+5);t&&si(t);break}}}catch{}break}case"stepChangeRequested":{const t=n.gist.parameters.displaySettings,o=n.gist.parameters.messageStepName;if(!o){i(`stepChangeRequested for message ${e.messageId} arrived without a messageStepName; keeping the current step visible`);break}await ci(e,o,t,n.gist.parameters.name??"")||(i(`Step "${o}" stays on this page, instructing renderer to show it`),function(t,e,n){const i=Dt(t.instanceId??""),o=document.getElementById(i);o?.contentWindow?.postMessage({action:"showStep",stepId:e,requestId:n},"*")}(e,o,n.gist.parameters.requestId));break}case"changeMessageStep":{const t=n.gist.parameters.displaySettings,s=n.gist.parameters.messageStepName;Ui.config.isPreviewSession&&s&&e.properties?.gist?.livePreview&&function(t,e){if(fn)return;mn=t;const n=pn.find(e=>e.stepName===t);n?gn={...n.displaySettings}:e&&(gn={...e}),Wn()}(s,t),(o.persistent||Oe(e))&&await Ye(e.queueId??"",s,t),t&&at(e,t)&&(i("Display settings changed, reloading message"),await li(e),rt(e,t),await ri(e,s??null));break}case"routeChanged":e.currentRoute=n.gist.parameters.route,e.renderStartTime=(new Date).getTime(),Z(t,e),i(`Route changed to: ${e.currentRoute}`);break;case"sizeChanged":i(`Size Changed Width: ${n.gist.parameters.width} - Height: ${n.gist.parameters.height}`),"tooltip"===st(e)?function(t,e){const n=t.instanceId??"",i=Dt(n),o=document.getElementById(i);if(o&&e.height>0){o.style.height=`${e.height}px`;const t=Tt.get(n);t&&t.reposition()}}(e,n.gist.parameters):e.elementId&&!e.shouldResizeHeight||function(t,e){const n=T(t.elementId?t.elementId:Dt(t.instanceId??""));if(n){const i=n.style;if(e.height>0)if(e.height>window.innerHeight){const n=1-(e.height/window.innerHeight-1);t.shouldScale&&n>=.4?(i.height=`${e.height}px`,i.transform=`translateX(-50%) translateY(-50%) scale(${n})`):i.height=`${window.innerHeight}px`}else i.height=`${e.height}px`}}(e,n.gist.parameters);break;case"titleChanged":i(`Overlay title changed to: ${n.gist.parameters.title}`),function(t,e){const n=T(Dt(t));n&&(n.title=e)}(t,n.gist.parameters.title);break;case"eventDispatched":Ui.events.dispatch("eventDispatched",{name:n.gist.parameters.name,payload:n.gist.parameters.payload});break;case"error":case"routeError":Ui.messageError(e),"tooltip"===st(e)?Zn(e):Ui.overlayInstanceId?await ti(!1,e):Yn(e)}}}async function ri(t,e){t.isDisplayChange=!0,t.renderStartTime=(new Date).getTime();const n=st(t),o=t.elementId||null;if("tooltip"===n)return Ui.overlayInstanceId===t.instanceId&&(Ui.overlayInstanceId=null),t.shouldScale=!1,t.shouldResizeHeight=!1,void ni(t,null,e);if(o){const e=Q(o);e&&e.instanceId!==t.instanceId&&(i(`Dismissing existing message at ${o} to make room for multi-step message`),await Xn(e))}if(t.overlay){Ui.overlayInstanceId=t.instanceId??null;const e=H(t);t.shouldScale=e.shouldScale,t.shouldResizeHeight=!0}else Ui.overlayInstanceId=null,t.shouldScale=!1,t.shouldResizeHeight=!It(o??"");o&&G.includes(o)&&V(o),ni(t,o,e)}async function li(t){"tooltip"===st(t)?Nt(t):t.overlay?await Lt():t.elementId&&St(t.elementId)}async function ci(t,e,n,o=""){const s=n?.pageUrl;if(!s||ot(s))return!1;if(!function(t){try{const e=new URL(t,window.location.href).protocol;return"https:"===e||"http:"===e}catch{return!1}}(s))return i(`Step "${e}" page-url is not a navigable http(s) target (${s}); treating as a local step change`),!1;const a=H(t);if(Ui.messageAction(t,`gist://loadPage?url=${s}`,o),a.persistent||Oe(t)){i(`Saving step "${e}" before navigating to ${s}`);try{await Ye(t.queueId??"",e,n)}catch(t){i(`Failed to save step state before navigating: ${t}`)}}return Ui.config.isPreviewSession?(await async function(){const t=new URLSearchParams(window.location.search).get(on);if(t){Nn();try{await nn(t,pn)}catch{i("Failed to flush preview display settings before navigation")}}}(),function(t){try{const e=new URL(window.location.href);return new URL(t,window.location.href).origin===e.origin}catch{return!1}}(s)?window.location.href=function(t,e,n){try{const i=new URL(t,window.location.href),o=je();if(!o)return t;i.searchParams.set(on,o);try{i.searchParams.set(sn,btoa(JSON.stringify({stepName:e,displayType:n})))}catch{}return i.href}catch{return t}}(s,e,n?.displayType):(i(`Preview: step "${e}" targets a different origin (${s}); navigating without the preview session token`),si(s))):si(s),!0}async function di(t,e,n){n&&at(t,n)&&(await li(t),rt(t,n)),await ri(t,e??null)}async function ui(t){i(`Logging user message view locally for: ${t.queueId}`),We(t)?await async function(t){i(`Marking broadcast ${t} as seen.`);const e=await _e();if(!e)return;const n=await ze(e,t);if(!n)return;const o=n.properties.gist.broadcast,{frequency:r}=o,l=Ue(e,t),c=Be(e,t),d=a(l)||0;if(s(l,d+1),1===r.count)s(c,!1),i(`Marked broadcast ${t} as seen.`);else{const e=new Date;e.setSeconds(e.getSeconds()+r.delay),s(c,!1,e),i(`Marked broadcast ${t} as seen, broadcast was seen ${d+1} times, next show date is ${e}.`)}}(t.queueId??""):await async function(t){const e=await Je();if(!e)return;const n=a(e)??[];n.push(t),s(e,n)}(t.queueId??"")}async function pi(t){We(t)&&(i(`Logging broadcast dismissed locally for: ${t.queueId}`),await async function(t){i(`Marking broadcast ${t} as dismissed.`);const e=await _e();if(!e)return;const n=await ze(e,t);n&&(!0!==n.properties.gist.broadcast.frequency.ignoreDismiss?(s(Be(e,t),!1),i(`Marked broadcast ${t} as dismissed and will not show again.`)):i(`Broadcast ${t} is set to ignore dismiss.`))}(t.queueId??""),await Ze(t.queueId??""))}const gi=(t,e)=>t().then((t=>new Promise(e=>setTimeout(e,t)))(e).then(()=>gi(t,e)));let mi=!1,hi=null;const fi=1e4,bi=new Set,yi=new Map;async function wi(){mi?await vi():je()?(i("Queue watcher started"),mi=!0,gi(()=>new Promise(()=>{!async function(){if(w.hasActiveSSEConnection())return!w.isSSEConnectionManagedBySDK()&&hi&&(i("Not the main instance, closing our SSE connection."),Ii()),void await vi();hi&&(i("SSE connection not active, closing it."),Ii()),!w.useSSE()||Ee()?await Si():await async function(){Ii();const t=function(){const t=Te();return null===t?(i("No user token available for SSE endpoint."),null):w.GIST_QUEUE_REALTIME_API_ENDPOINT[Ui.config.env??"prod"]+`/api/v3/sse?userToken=${t}&siteId=${Ui.config.siteId}&sessionId=${Ie()}`}();if(null===t)return i("SSE endpoint not available, falling back to polling."),void await Si();i(`Starting SSE queue listener on ${t}`),hi=new EventSource(t),w.setActiveSSEConnection(),hi.addEventListener("connected",async t=>{try{i("SSE connection received"),w.setUseSSEFlag(!0);const e=JSON.parse(t.data);e.heartbeat&&(w.setSSEHeartbeat(e.heartbeat),i(`SSE heartbeat set to ${e.heartbeat} seconds`)),w.setActiveSSEConnection()}catch(t){i(`Failed to parse SSE settings: ${t}`)}r(xe),await Si()}),hi.addEventListener("messages",async t=>{try{const e=JSON.parse(t.data);i("SSE message received"),await He(e),await Re(e),await vi()}catch(t){i(`Failed to parse SSE message: ${t}`),Ii()}}),hi.addEventListener("inbox_messages",async t=>{try{const e=JSON.parse(t.data);i("SSE inbox messages received"),await z(e)}catch(t){i(`Failed to parse SSE inbox messages: ${t}`)}}),hi.addEventListener("error",async()=>{i("SSE error received"),Ii()}),hi.addEventListener("heartbeat",async()=>{i("SSE heartbeat received"),w.setActiveSSEConnection(),w.setUseSSEFlag(!0)})}()}()}),1e3)):i("User token not setup, queue not started.")}async function vi(){const t=await qe(),e=await Ge(),n=t.concat(e);i(`Messages in local queue: ${n.length}`);const o=n.sort((t,e)=>t.priority-e.priority);for(const t of o)await xi(t)}async function xi(t){if(t.queueId&&await async function(t){const e=await Qe(t);return!!e&&null!==a(e)}(t.queueId))return i(`Not showing message with queueId ${t.queueId} because it is snoozed.`),!1;let e=H(t);if(e.hasRouteRule){if(null==Ui.currentRoute&&!Ui.routeInitialized)return i(`Deferring message ${t.queueId}, route not yet initialized`),!1;if(!it(e.routeRule))return i(`Route ${new URL(window.location.href).pathname} (currentRoute: ${Ui.currentRoute}) does not match rule: ${e.routeRule}`),!1}if(e.hasPosition&&(t.position=e.position),e.hasTooltipPosition&&(t.tooltipPosition=e.tooltipPosition),e.persistent||Oe(t)){const n=await async function(t){const e=await Ke(t);return e?a(e):null}(t.queueId??"");if(n){const o=n.displaySettings?.pageUrl;if(o&&!ot(o))return i(`Saved step for queueId ${t.queueId} belongs to page ${o}, not showing on ${new URL(window.location.href).pathname}`),!1;i(`Restoring saved state for queueId ${t.queueId}`),n.displaySettings&&(rt(t,n.displaySettings),e=H(t)),t.savedStepName=n.stepName??null}}if(t.savedStepName){const n=function(t,e){let n=null;return e.hasTooltipPosition||t.tooltipPosition?n=e.elementId||t.elementId:e.isEmbedded&&(n=e.elementId),!n||G.includes(n)?null:n}(t,e);if(n&&!T(n)&&(!Ui.config.isPreviewSession||!t.properties?.gist?.livePreview))return function(t,e){const n=t.queueId??"",o=new URL(window.location.href).pathname;bi.has(n)||yi.get(n)!==o&&(bi.add(n),i(`Anchor "${e}" not present for saved step "${t.savedStepName}" of queueId ${n}, waiting up to ${fi}ms`),function(t,e){const n=T(t);return n?Promise.resolve(n):new Promise(n=>{const i=new MutationObserver(()=>{const e=T(t);e&&(clearTimeout(o),i.disconnect(),n(e))}),o=setTimeout(()=>{i.disconnect(),n(null)},e);i.observe(document.documentElement,{childList:!0,subtree:!0})})}(e,fi).then(async s=>{if(bi.delete(n),s)return yi.delete(n),i(`Anchor "${e}" appeared, re-checking message queue`),void await vi();const a=new URL(window.location.href).pathname;a===o?(yi.set(n,o),i(`Anchor "${e}" did not appear within ${fi}ms, tour step for queueId ${n} cannot continue on ${o}`),Ui.messageError(t)):i(`Anchor wait for "${e}" outlived ${o} (now on ${a}), ignoring`)}).catch(t=>{bi.delete(n),i(`Anchor wait for "${e}" failed: ${t}`)}))}(t,n),!1}if(e.persistent||Oe(t)||!await async function(t){const e=await Xe(t);return!!e&&null!==a(e)}(t.queueId??"")){let n=null;return e.isEmbedded?!Ui.config.isPreviewSession||!t.properties?.gist?.livePreview||T(e.elementId)||G.includes(e.elementId)?n=Jn(t,e.elementId):(i(`Preview: element "${e.elementId}" not found, showing as overlay so placement can be changed`),n=await Vn(t)):n=await Vn(t),n&&async function(t){const e=await Xe(t);e&&s(e,!0,new Date(Date.now()+5e3))}(t.queueId??""),null!==n}return i(`Not showing message with queueId ${t.queueId} because its already loading.`),!1}async function Si(){if(je())if(Ui.isDocumentVisible)if(null===a(xe)){const t=await async function(){if(ve)return;ve=!0;const t=je();let e;try{const t={"X-Gist-User-Anonymous":String(Ee()),"Content-Language":String($())};e=await S().post(`/api/v4/users?sessionId=${Ie()}`,{},{headers:t})}catch(t){const n=x(t);n?e=n:i(`Error getting user queue: ${t}`)}finally{ve=!1}return t!==je()?(i("User token changed, clearing queue next pull check."),void r(xe)):(function(t){const e=t?.headers?.["x-gist-queue-polling-interval"];we=e&&Number(e)>0?Number(e):Math.min(2*we,600);const n=new Date((new Date).getTime()+1e3*we);s(xe,we,n)}(e),function(t){const e="true"===t?.headers?.["x-cio-use-sse"]?.toLowerCase();w.setUseSSEFlag(e)}(e),await async function(t){const e=t?.headers?.["x-cio-inbox-enabled"]?.toLowerCase();if(void 0===e)return;const n="true"===e;w.setInboxEnabledFlag(n),n&&(i("Inbox enabled, ensuring branding and templates are cached."),await ye(),de())}(e),e)}();if(t){if(200===t.status||204===t.status){i("200 response, updating local store.");const e=t.data,n=e?.inAppMessages??[],o=e?.inboxMessages??[];He(n),Re(n),z(o)}else 304===t.status&&i("304 response, using local store.");await vi()}else i("No response object returned while checking message queue.")}else i("Next queue pull scheduled for later.");else i("Document not visible, skipping queue check.");else i("User token reset, skipping queue check.")}function Ii(t=!1){t&&w.removeActiveSSEConnection(),(t||w.isSSEConnectionManagedBySDK())&&w.setUseSSEFlag(!1),hi&&(i("Stopping SSE queue listener..."),hi.close(),hi=null)}const $i="gist-debug-overlay-styles";let Ci=null,ki=!1,Ei=!1,ji=null;function Li(t){const e=t.properties?.gist;return st(e?{...t,tooltipPosition:e.tooltipPosition??t.tooltipPosition,elementId:null!=e.elementId?String(e.elementId):t.elementId}:t)}function Pi(t,e,n=!1){const i=N("div",{className:"gist-debug-msg-row"});return i.appendChild(N("span",{className:"gist-debug-msg-key",textContent:t})),i.appendChild(N("span",{className:n?"gist-debug-msg-val gist-debug-val-error":"gist-debug-msg-val",textContent:e})),i}function Ti(t,e,n=!1){t.replaceChildren(...e.map(([t,e])=>Pi(t,e,n)))}function Ni(t,e){const n=N("div",{className:"gist-debug-msg"}),i=N("div",{className:"gist-debug-msg-meta"});if(i.appendChild(N("span",{className:"gist-debug-msg-type",textContent:Li(t)})),i.appendChild(N("span",{className:`gist-debug-msg-state gist-debug-msg-state--${e}`,textContent:e})),t.instanceId){const e=N("button",{className:"gist-debug-msg-dismiss",textContent:"×"});e.addEventListener("click",()=>{Mi(),Ui.dismissMessage(t.instanceId).then(()=>{Mi(),Ri()})}),i.appendChild(e)}n.appendChild(i);const o=[];for(const[e,i]of function(t){const e=t.properties?.gist,n=[];e?.routeRuleWeb&&n.push(["Route Rule",String(e.routeRuleWeb)]);const i=e?.elementId??t.elementId,o=Li(t);if(i&&"overlay"===o){const t=function(t){if(t)return et[t]}(String(i));t&&n.push(["Position",t.replace(/([A-Z])/g," $1").toLowerCase()])}else i&&"modal"!==o&&n.push(["Target",String(i)]);const s=e?.position??t.position;s&&"overlay"!==o&&n.push(["Position",String(s)]);const a=e?.tooltipPosition??t.tooltipPosition;return a&&n.push(["Tooltip",String(a)]),n}(t)){let t=null,s=null;if("Route Rule"===e){const e=!it(i);t=e?"gist-debug-route-mismatch":"gist-debug-element-found",s=e?"✕":"✓",e&&o.push("Route rule does not match current route. If it should, verify the route is set correctly and that analytics.page() is called on route changes.")}else if("Target"===e){const e=!!T(i);t=e?"gist-debug-element-found":"gist-debug-route-mismatch",s=e?"✓":"✕",e||o.push("Target element not found on the page. If it should, verify the selector is correct.")}const a=Pi(e,i);t&&s&&a.appendChild(N("span",{className:t,textContent:s})),n.appendChild(a)}if(o.length>0){const t=N("ul",{className:"gist-debug-msg-details"});for(const e of o)t.appendChild(N("li",{textContent:e}));n.appendChild(t)}return n}function Di(t){const e=N("div",{className:"gist-debug-expand-detail"}),n=N("ul",{className:"gist-debug-expand-list"});return n.appendChild(N("li",{textContent:t})),e.appendChild(n),e}function Ai(){Ci&&(Ci.root.remove(),document.getElementById($i)?.remove(),null!==ji&&(clearInterval(ji),ji=null),ki&&(Ui.events&&(Ui.events.off("messageShown",qi),Ui.events.off("messageDismissed",qi),Ui.events.off("messageInboxUpdated",zi),Ui.events.off("routeChanged",qi)),ki=!1),Ci=null)}function Mi(){if(!Ci)return;Ui.config?Ti(Ci.configRows,[["Site ID",Ui.config.siteId],["Connection",w.useSSE()?"SSE":`Polling ${we}s`]]):Ti(Ci.configRows,[["Status","NOT INITIALIZED"]],!0),Ci.configDetail.style.display=Ui.config?"none":"";const t=je();t?Ee()?Ci.userValue.textContent="(anonymous)":Ci.userValue.textContent=t.length>32?`${t.slice(0,32)}…`:t:Ci.userValue.textContent="(none)";const e=Ui.currentRoute;Ci.routeValue.replaceChildren(N("span",{className:e?"gist-debug-msg-val":"gist-debug-msg-val gist-debug-val-error",textContent:e??"NONE"})),Ci.routeDetail.style.display=e?"none":""}async function Ri(){if(!Ei&&Ci){Ei=!0;try{const t=Ui.currentMessages??[],[e,n]=Ui.config?await Promise.all([Ge(),qe()]):[[],[]],i=new Set(t.map(t=>t.queueId??t.messageId)),o=new Set,s=[...n,...e].filter(t=>{const e=t.queueId??t.messageId;return!i.has(e)&&!o.has(e)&&(o.add(e),!0)});if(!Ci)return;const a=t.length+s.length;Ci.messagesLabel.textContent=`Messages (${a})`,Ci.messagesList.replaceChildren(...t.map(t=>Ni(t,"active")),...s.map(t=>Ni(t,"queued")))}finally{Ei=!1}}}function qi(){Mi(),Ri()}function zi(){Ri()}async function Wi(){ki||(!ki&&Ui.events&&(Ui.events.on("messageShown",qi),Ui.events.on("messageDismissed",qi),Ui.events.on("messageInboxUpdated",zi),Ui.events.on("routeChanged",qi),ki=!0),ki&&Oi(5e3)),Mi(),await Ri()}function Oi(t){null!==ji&&clearInterval(ji),ji=setInterval(()=>{Wi()},t)}function _i(){if("undefined"!=typeof window&&"true"===new URLSearchParams(window.location.search).get("cio_debug_session"))try{Ci||null!==ji||(D($i,"\n #gist-debug-overlay {\n position: fixed; bottom: 16px; right: 16px;\n z-index: 99999999999;\n background: #08272B; color: white;\n font-family: system-ui, -apple-system, sans-serif;\n font-size: 11px;\n border-radius: 8px;\n box-shadow: 0 4px 12px rgba(0,0,0,0.3);\n width: 300px;\n max-height: min(700px, calc(100vh - 32px));\n display: flex;\n flex-direction: column;\n pointer-events: auto;\n overflow: hidden;\n }\n .gist-debug-header {\n display: flex; align-items: center;\n padding: 8px 12px;\n border-bottom: 1px solid rgba(255,255,255,0.1);\n flex-shrink: 0;\n }\n .gist-debug-title {\n flex: 1;\n font-weight: 700;\n font-size: 12px;\n letter-spacing: 0.02em;\n }\n #gist-debug-overlay-close {\n background: none; border: none;\n color: white; cursor: pointer;\n padding: 0; font-size: 18px; line-height: 1;\n opacity: 0.6; flex-shrink: 0;\n font-family: system-ui, -apple-system, sans-serif;\n -webkit-appearance: none; appearance: none;\n }\n #gist-debug-overlay-close:hover { opacity: 1; }\n .gist-debug-section {\n padding: 0 12px 8px;\n border-bottom: 1px solid rgba(255,255,255,0.07);\n overflow-y: auto;\n max-height: 180px;\n }\n .gist-debug-section:last-child { border-bottom: none; }\n .gist-debug-label {\n position: sticky;\n top: 0;\n z-index: 1;\n background: #08272B;\n display: flex;\n align-items: center;\n gap: 4px;\n font-size: 10px;\n text-transform: uppercase;\n letter-spacing: 0.08em;\n color: rgba(255,255,255,0.45);\n padding: 8px 0 5px;\n font-weight: 600;\n }\n .gist-debug-value {\n font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;\n font-size: 11px;\n color: rgba(255,255,255,0.9);\n overflow-wrap: break-word;\n }\n .gist-debug-msg {\n background: rgba(255,255,255,0.06);\n border-radius: 4px;\n padding: 5px 7px;\n margin-bottom: 8px;\n }\n .gist-debug-msg:last-child { margin-bottom: 0; }\n .gist-debug-msg-row {\n display: flex;\n align-items: center;\n gap: 6px;\n margin-bottom: 2px;\n }\n .gist-debug-msg-row:last-child { margin-bottom: 0; }\n .gist-debug-msg-meta {\n display: flex;\n align-items: center;\n gap: 5px;\n margin-bottom: 4px;\n }\n .gist-debug-msg-state {\n font-size: 9px;\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.05em;\n border-radius: 3px;\n padding: 1px 4px;\n flex-shrink: 0;\n }\n .gist-debug-msg-state--active {\n color: #4caf82;\n background: rgba(76,175,130,0.12);\n }\n .gist-debug-msg-state--queued {\n color: rgba(255,200,100,0.9);\n background: rgba(255,200,100,0.1);\n }\n .gist-debug-msg-dismiss {\n margin-left: auto;\n background: none;\n border: none;\n color: rgba(255,255,255,0.3);\n cursor: pointer;\n padding: 0;\n font-size: 13px;\n line-height: 1;\n font-family: system-ui, -apple-system, sans-serif;\n -webkit-appearance: none;\n appearance: none;\n }\n .gist-debug-msg-dismiss:hover { color: rgba(255,255,255,0.7); }\n .gist-debug-element-found {\n color: #4caf82;\n font-size: 9px;\n font-weight: 700;\n flex-shrink: 0;\n }\n .gist-debug-route-mismatch {\n color: #ff6b6b;\n font-size: 9px;\n font-weight: 700;\n flex-shrink: 0;\n }\n .gist-debug-msg-type {\n font-size: 9px;\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.05em;\n color: rgba(255,255,255,0.45);\n background: rgba(255,255,255,0.08);\n border-radius: 3px;\n padding: 1px 4px;\n flex-shrink: 0;\n }\n .gist-debug-msg-key {\n color: rgba(255,255,255,0.45);\n font-size: 10px;\n line-height: 1.4;\n min-width: 64px;\n flex-shrink: 0;\n }\n .gist-debug-msg-val {\n font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;\n font-size: 10px;\n line-height: 1.4;\n color: rgba(255,255,255,0.9);\n overflow-wrap: break-word;\n }\n .gist-debug-val-error {\n color: #ff6b6b;\n font-weight: 600;\n }\n .gist-debug-expand-detail {\n background: rgba(255,107,107,0.08);\n border-left: 2px solid rgba(255,107,107,0.4);\n color: rgba(255,255,255,0.75);\n font-family: system-ui, -apple-system, sans-serif;\n font-size: 10px;\n padding: 4px 6px;\n margin-top: 4px;\n margin-bottom: 6px;\n border-radius: 0 3px 3px 0;\n }\n .gist-debug-expand-list {\n margin: 0;\n padding: 0 0 0 14px;\n list-style: disc;\n }\n .gist-debug-expand-list li {\n margin-bottom: 3px;\n line-height: 1.4;\n }\n .gist-debug-expand-list li:last-child { margin-bottom: 0; }\n .gist-debug-msg-details {\n margin: 5px 0 0;\n padding: 0 0 0 14px;\n list-style: disc;\n color: rgba(255,255,255,0.5);\n font-size: 10px;\n line-height: 1.4;\n font-family: system-ui, -apple-system, sans-serif;\n }\n .gist-debug-msg-details li { margin-bottom: 2px; }\n .gist-debug-msg-details li:last-child { margin-bottom: 0; }\n"),Ci=function(){const t=N("div",{id:"gist-debug-overlay"}),e=N("div",{className:"gist-debug-header"});e.appendChild(N("span",{className:"gist-debug-title",textContent:"Customer.io In-App SDK Debugger"}));const n=N("button",{id:"gist-debug-overlay-close",ariaLabel:"Dismiss debug overlay",textContent:"×"});n.addEventListener("click",Ai),e.appendChild(n),t.appendChild(e);const i=N("div",{className:"gist-debug-section"}),o=N("div",{className:"gist-debug-label"});o.appendChild(N("span",{textContent:"Config"})),i.appendChild(o);const s=N("div",{});i.appendChild(s);const a=Di("Verify your site ID and credentials are correct.");i.appendChild(a),t.appendChild(i);const r=N("div",{className:"gist-debug-section"}),l=N("div",{className:"gist-debug-label",textContent:"User"});r.appendChild(l);const c=N("div",{className:"gist-debug-value"});r.appendChild(c),t.appendChild(r);const d=N("div",{className:"gist-debug-section"}),u=N("div",{className:"gist-debug-label"});u.appendChild(N("span",{textContent:"Route"})),d.appendChild(u);const p=N("div",{className:"gist-debug-value"});d.appendChild(p);const g=Di("The current route is used to match against potential message page rules.");d.appendChild(g),t.appendChild(d);const m=N("div",{className:"gist-debug-section"}),h=N("div",{className:"gist-debug-label"});m.appendChild(h);const f=N("div",{});return m.appendChild(f),t.appendChild(m),{root:t,configRows:s,configDetail:a,userValue:c,routeValue:p,routeDetail:g,messagesLabel:h,messagesList:f}}(),A(Ci.root),Oi(2e3),Wi())}catch(t){i(`Failed to initialize debug overlay: ${t}`)}}class Ui{static async setup(t){this.initialized?i("Gist SDK already initialized, skipping setup."):(this.initialized=!0,this.events=new n,this.config={useAnonymousSession:t.useAnonymousSession??!1,siteId:t.siteId,dataCenter:t.dataCenter,env:t.env??"prod",logging:t.logging??!1,experiments:t.experiments??!1,colorScheme:t.colorScheme??"default"},this.currentMessages=[],Tt.forEach(t=>t.cleanup()),Tt.clear(),document.querySelectorAll('[id^="gist-tooltip-"]').forEach(t=>{t.parentNode?.removeChild(t)}),this.overlayInstanceId=null,this.currentRoute=null,this.routeInitialized=!1,this.isDocumentVisible=!0,this.config.isPreviewSession=function(){const t=new URLSearchParams(window.location.search),e=t.get(on);if(e){sessionStorage.setItem(o,String(!1)),Ui.setUserToken(e),i(`Preview mode enabled with user token: ${e}`),function(){if(document.getElementById(cn))return;D(ln,en);try{hn="true"===sessionStorage.getItem(an)}catch{hn=!1}const t=N("div",{id:cn});document.body.appendChild(t),Wn()}();const n=t.get(sn);if(n)try{const t=JSON.parse(atob(n)),e=t.stepName||null,i=t.displayType||null;(e||i)&&function(t,e){In=t,$n=e}(e,i)}catch{i("Preview bar: failed to parse cioPreviewSettings")}}return!l()}(),_i(),function(){const t=c();for(let e=t.length-1;e>=0;e--){const n=t.key(e);n?.startsWith("gist.")&&d(n)}}(),async function(){w.inboxEnabled()&&(E()&&P()||(i("Inbox enabled but missing cached branding/templates, fetching."),await ye()),de())}(),"auto"===this.config.colorScheme&&vt(),i(`Setup complete on ${this.config.env} environment.`),this.config.isPreviewSession||!this.config.useAnonymousSession||new URLSearchParams(location.search).has("ajs_uid")||Le(),await wi(),setTimeout(()=>{this.routeInitialized||(this.routeInitialized=!0,vi())},2e3),document.addEventListener("visibilitychange",async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await vi())},!1))}static setupDebugOverlay(){_i()}static async setCurrentRoute(t){this.routeInitialized=!0,this.currentRoute=t,i(`Current route set to: ${t}`),await async function(){if(function(){const t=new URL(window.location.href).pathname;for(const[e,n]of yi)n!==t&&yi.delete(e)}(),0!==Ui.currentMessages.length)for(const t of[...Ui.currentMessages])null==document.querySelector(`#gist-${t.instanceId}`)&&(i(`Removing active message ${t.instanceId} that no longer exists after route change`),await Kn(t))}(),await vi(),this.events?.dispatch("routeChanged",t)}static async setUserToken(t,e){this.config.isPreviewSession||(function(t,e){void 0===e&&(e=new Date).setDate(e.getDate()+30),s($e,t,e),Ee()&&(r(xe),r(Ce)),i(`Set user token "${t}" with expiry date set to ${e}`)}(t,e),Ii(!0),await wi())}static setUserLocale(t){var e;s(I,e=t),i(`Set user locate to "${e}"`)}static setColorScheme(t){this.config.colorScheme=t,function(){const t=Ui.config?.colorScheme;"auto"===t?vt():wt&&(wt.disconnect(),wt=null);const e=bt(t);yt=e,xt(e)}(),i(`Color scheme set to: ${t}`)}static setCustomAttribute(t,e){return function(t,e){return t&&"string"==typeof t?(Ae.set(t,e),Me(),i(`Set custom attribute "${t}" to "${e}"`),!0):(i(`Invalid key for custom attribute: ${t}`),!1)}(t,e)}static clearCustomAttributes(){Ae.clear(),r(De),i("Cleared all custom attributes")}static removeCustomAttribute(t){return function(t){if(!t||"string"!=typeof t)return i(`Invalid key for custom attribute: ${t}`),!1;const e=Ae.has(t);return Ae.delete(t),Ae.size>0?Me():r(De),i(`Removed custom attribute "${t}"`),e}(t)}static async clearUserToken(){this.config.isPreviewSession||(Ne(),pe(),this.config.useAnonymousSession&&Le(),Ii(!0),await wi())}static async dismissMessage(t){const e=X(t);e&&(await Qn(e),await pi(e),await Xn(e),await vi())}static async embedMessage(t,e){const n=Jn(t,e);return n?.instanceId??null}static async showMessage(t){const e=await Vn(t);return e?.instanceId??null}static updateMessageDisplaySettings(t,e){const n=X(t);return!!n&&(n.displaySettings=e,kt(n),!0)}static messageShown(t){i(`Message shown: ${t.messageId}`),this.events.dispatch("messageShown",t)}static messageDismissed(t){null!==t&&(i(`Message dismissed: ${t.messageId}`),this.events.dispatch("messageDismissed",t))}static messageError(t){i(`Message error: ${t.messageId}`),this.events.dispatch("messageError",t)}static messageAction(t,e,n){i(`Message action: ${t.currentRoute}, ${e} with name ${n} on ${t.instanceId}`),this.events.dispatch("messageAction",{message:t,action:e,name:n})}static async getInboxUnopenedCount(){return(await W()).filter(t=>!t.opened).length}static async getInboxMessages(){return await W()}static async updateInboxMessageOpenState(t,e){return await O(t,e)}static async removeInboxMessage(t){return await _(t)}static isInboxEnabled(){return w.inboxEnabled()}}let Bi=Ui;if("undefined"!=typeof window){const t=window;t.__gistWebLoaded?(console.warn("Gist: the SDK has been loaded more than once on this page; check for duplicate snippets or bundles."),t.Gist&&(Bi=t.Gist)):(t.__gistWebLoaded=!0,_i())}const Fi=Bi;return e.default})());
|
|
@@ -24,6 +24,12 @@ export declare function resizeComponent(message: GistMessage, size: {
|
|
|
24
24
|
}): void;
|
|
25
25
|
export declare function loadOverlayComponent(url: string, message: GistMessage, options: MessageOptions, stepName?: string | null): void;
|
|
26
26
|
export declare function sendOptionsToIframe(iframeId: string, options: MessageOptions, stepName?: string | null): void;
|
|
27
|
+
/**
|
|
28
|
+
* Answers a stepChangeRequested bridge event with "stay on this page": the
|
|
29
|
+
* renderer withheld its local toggle pending our decision, so instruct it to
|
|
30
|
+
* show the step now (INAPP-14575).
|
|
31
|
+
*/
|
|
32
|
+
export declare function sendShowStepToIframe(message: GistMessage, stepName: string, requestId?: number): void;
|
|
27
33
|
export declare function sendDisplaySettingsToIframe(message: GistMessage): void;
|
|
28
34
|
export declare function showOverlayComponent(message: GistMessage): void;
|
|
29
35
|
export declare function hideOverlayComponent(): Promise<void>;
|
|
@@ -5,5 +5,14 @@ export declare function hideMessage(message: GistMessage): Promise<void>;
|
|
|
5
5
|
export declare function resetMessage(message: GistMessage): Promise<void>;
|
|
6
6
|
export declare function removePersistentMessage(message: GistMessage): Promise<void>;
|
|
7
7
|
export declare function hideMessageVisually(message: GistMessage): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Cross-page step routing (INAPP-14575), shared by the button-tap
|
|
10
|
+
* `stepChangeRequested` handler and the preview bar's step switcher. If the
|
|
11
|
+
* target step belongs to a different page, it persists the step and navigates
|
|
12
|
+
* (rehearsing the hop with the preview session in preview mode) and returns
|
|
13
|
+
* true. Otherwise it returns false and the caller performs its normal in-place
|
|
14
|
+
* step change.
|
|
15
|
+
*/
|
|
16
|
+
export declare function navigateForCrossPageStep(message: GistMessage, stepName: string, displaySettings: DisplaySettings | undefined, trackingName?: string): Promise<boolean>;
|
|
8
17
|
export declare function applyMessageStepChange(message: GistMessage, stepName: string | null | undefined, displaySettings: DisplaySettings | undefined): Promise<void>;
|
|
9
18
|
export declare function logBroadcastDismissedLocally(message: GistMessage): Promise<void>;
|
|
@@ -5,6 +5,8 @@ export declare function markUserQueueMessageAsSeen(queueId: string): Promise<voi
|
|
|
5
5
|
export declare function isMessageLoading(queueId: string): Promise<boolean>;
|
|
6
6
|
export declare function setMessageLoading(queueId: string): Promise<void>;
|
|
7
7
|
export declare function setMessageLoaded(queueId: string): Promise<void>;
|
|
8
|
+
export declare function setMessageSnoozed(queueId: string, showInMinutes: number): Promise<void>;
|
|
9
|
+
export declare function isMessageSnoozed(queueId: string): Promise<boolean>;
|
|
8
10
|
export declare function saveMessageState(queueId: string, stepName: string | undefined, displaySettings: DisplaySettings | undefined): Promise<void>;
|
|
9
11
|
export declare function getSavedMessageState(queueId: string): Promise<unknown>;
|
|
10
12
|
export declare function clearMessageState(queueId: string): Promise<void>;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { DisplaySettings, GistMessage } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Awaits the pending per-step settings save so edits aren't lost to an
|
|
4
|
+
* in-flight request when a cross-page step switch navigates the page. Unlike
|
|
5
|
+
* persistDisplaySettings (fire-and-forget on every keystroke), the caller can
|
|
6
|
+
* await this before assigning window.location (INAPP-14575). No-op outside a
|
|
7
|
+
* preview session.
|
|
8
|
+
*/
|
|
9
|
+
export declare function flushPreviewDisplaySettings(): Promise<void>;
|
|
2
10
|
export declare function initPreviewBar(): void;
|
|
3
11
|
export declare function updatePreviewBarMessage(message: GistMessage): void;
|
|
4
12
|
export declare function updatePreviewBarStep(stepName: string, displaySettings: DisplaySettings): void;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -38,6 +38,11 @@ export interface DisplaySettings {
|
|
|
38
38
|
maxWidth?: number;
|
|
39
39
|
overlayColor?: string;
|
|
40
40
|
dismissOutsideClick?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Page the step belongs to (product tours). Saved with the step state so a
|
|
43
|
+
* restored step is only re-shown on its own page (INAPP-14575).
|
|
44
|
+
*/
|
|
45
|
+
pageUrl?: string;
|
|
41
46
|
}
|
|
42
47
|
export interface StepDisplayConfig {
|
|
43
48
|
stepName: string;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export declare function findElement(selector: string): HTMLElement | null;
|
|
2
|
+
/**
|
|
3
|
+
* Resolves with the element once it appears in the DOM, or null after the
|
|
4
|
+
* timeout. Used for tour continuations: after a cross-page hop the queue check
|
|
5
|
+
* usually beats the app rendering a tooltip/inline anchor, so a one-shot
|
|
6
|
+
* lookup would fail on exactly the step that just navigated (INAPP-14575).
|
|
7
|
+
*/
|
|
8
|
+
export declare function waitForElement(selector: string, timeoutMs: number): Promise<HTMLElement | null>;
|
|
2
9
|
export declare function el<K extends keyof HTMLElementTagNameMap>(tag: K, attrs?: Partial<HTMLElementTagNameMap[K]> & {
|
|
3
10
|
[k: string]: unknown;
|
|
4
11
|
}): HTMLElementTagNameMap[K];
|
|
@@ -8,6 +8,14 @@ export declare function updateMessageByInstanceId(instanceId: string, message: G
|
|
|
8
8
|
export declare function mapOverlayPositionToElementId(overlayPosition: string | undefined): string;
|
|
9
9
|
export declare function mapElementIdToOverlayPosition(elementId: string | undefined | null): string | undefined;
|
|
10
10
|
export declare function matchesRouteRule(rule: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether a step's page-url refers to the page the visitor is currently on.
|
|
13
|
+
* Compared by pathname only: authored URLs stay environment-agnostic (staging
|
|
14
|
+
* and production hosts differ) and query/hash noise is ignored. Relative URLs
|
|
15
|
+
* resolve against the current location. Unparseable values fail open (treated
|
|
16
|
+
* as matching) so a bad authored URL can't strand a tour mid-way.
|
|
17
|
+
*/
|
|
18
|
+
export declare function matchesPageUrl(pageUrl: string): boolean;
|
|
11
19
|
export declare function getCurrentDisplayType(message: GistMessage): 'modal' | 'overlay' | 'inline' | 'tooltip';
|
|
12
20
|
export declare function hasDisplayChanged(currentMessage: GistMessage, displaySettings: DisplaySettings): boolean;
|
|
13
21
|
export declare function applyDisplaySettings(message: GistMessage, displaySettings: DisplaySettings): void;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
export declare const PREVIEW_PARAM_ID = "cioPreviewId";
|
|
2
2
|
export declare const PREVIEW_SETTINGS_PARAM = "cioPreviewSettings";
|
|
3
3
|
export declare function setupPreview(): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Rewrites a navigation target so the preview session survives the hop:
|
|
6
|
+
* setupPreview() on the destination page re-bootstraps the preview bar and the
|
|
7
|
+
* preview user token from these params. Without them a cross-page step change
|
|
8
|
+
* would strand the tab in a headless preview session — sessionStorage keeps the
|
|
9
|
+
* preview token alive, but the bar (and its exit affordance) only initializes
|
|
10
|
+
* from the URL (INAPP-14575).
|
|
11
|
+
*/
|
|
12
|
+
export declare function withPreviewSession(url: string, stepName?: string, displayType?: string): string;
|
|
4
13
|
export declare function teardownPreview(): void;
|