customerio-gist-web 3.21.7 → 3.21.8

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.
Files changed (2) hide show
  1. package/dist/gist.min.js +1 -1
  2. package/package.json +1 -1
package/dist/gist.min.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Gist=t():e.Gist=t()}(this,()=>(()=>{"use strict";var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>en});class n{constructor(){this.callbacks={}}on(e,t){const n=this.callbacks[e];n?n.push(t):this.callbacks[e]=[t]}off(e,t){const n=this.callbacks[e];if(!n)return;if(!t)return void delete this.callbacks[e];const i=n.indexOf(t);-1!==i&&n.splice(i,1),0===n.length&&delete this.callbacks[e]}dispatch(e,t){const n=this.callbacks[e];n&&n.forEach(e=>e(t))}}function i(e){en.config&&en.config.logging&&console.log(`Gist: ${e}`)}const o="gist.web.isPersistingSession";function s(e,t,n=null){let i=n;i||(i=new Date,i.setDate(i.getDate()+365));const o={value:t,expiry:i};c().setItem(e,JSON.stringify(o))}function a(e){return d(e)}function r(e){c().removeItem(e)}function l(){const e=sessionStorage.getItem(o);return null===e?(sessionStorage.setItem(o,"true"),!0):"true"===e}function c(){return l()?localStorage:sessionStorage}function d(e){if(!e)return null;try{const t=c().getItem(e);if(!t)return null;const n=JSON.parse(t);if(!n.expiry)return n.value;const i=new Date,o=new Date(n.expiry),s=e.startsWith("gist.web.message.broadcasts")&&!e.endsWith("shouldShow")&&!e.endsWith("numberOfTimesShown")||e.startsWith("gist.web.message.user")&&!e.endsWith("seen")&&!e.endsWith("state"),a=new Date(i.getTime()+366e4);return s&&o.getTime()>a.getTime()||i.getTime()>o.getTime()?(r(e),null):n.value}catch(t){i(`Error checking key ${e} for expiry: ${t}`)}return null}var p,u=new Uint8Array(16);function g(){if(!p&&!(p="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return p(u)}const m=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var f=[],h=0;h<256;++h)f.push((h+256).toString(16).substr(1));const w=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(f[e[t+0]]+f[e[t+1]]+f[e[t+2]]+f[e[t+3]]+"-"+f[e[t+4]]+f[e[t+5]]+"-"+f[e[t+6]]+f[e[t+7]]+"-"+f[e[t+8]]+f[e[t+9]]+"-"+f[e[t+10]]+f[e[t+11]]+f[e[t+12]]+f[e[t+13]]+f[e[t+14]]+f[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&m.test(e)}(n))throw TypeError("Stringified UUID is invalid");return n},y=function(e,t,n){var i=(e=e||{}).random||(e.rng||g)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=i[o];return t}return w(i)},b="gist.web.userQueueUseSSE",v="gist.web.activeSSEConnection";let x,S=30;const I={RENDERER_HOST:"https://code.gist.build",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://api.local.gist.build:86"},GIST_QUEUE_REALTIME_API_ENDPOINT:{prod:"https://realtime.cloud.gist.build",dev:"https://realtime.cloud.dev.gist.build",local:"http://api.local.gist.build:3000"},GIST_VIEW_ENDPOINT:{prod:"https://renderer.gist.build/3.0",dev:"https://renderer.gist.build/3.0",local:"http://app.local.gist.build:8080/web"},getSdkId:()=>(x||(x=y()),x),useSSE:()=>a(b)??!1,setUseSSEFlag(e){s(b,e,new Date((new Date).getTime()+6e4)),i(`Set user uses SSE to "${e}"`)},removeActiveSSEConnection(){r(v)},setActiveSSEConnection(){s(v,I.getSdkId(),new Date((new Date).getTime()+I.getSSEHeartbeat()))},hasActiveSSEConnection:()=>a(v)??!1,isSSEConnectionManagedBySDK:()=>a(v)===I.getSdkId(),getSSEHeartbeat:()=>1e3*(S+5),setSSEHeartbeat(e){e&&e>0&&(S=e)}};function $(e){return null!==e&&"object"==typeof e&&"response"in e}function E(e){return $(e)?e.response:void 0}function C(){const e=I.GIST_QUEUE_API_ENDPOINT[en.config.env??"prod"],t={"X-CIO-Site-Id":en.config.siteId,"X-CIO-Client-Platform":"web"},n=B();async function i(n,i={}){const o=e+n,s=new AbortController,a=setTimeout(()=>s.abort(),5e3);try{const e=await fetch(o,{method:i.method||"GET",headers:{...t,...i.headers||{}},body:i.method&&"GET"!==i.method.toUpperCase()?i.body:void 0,signal:s.signal});clearTimeout(a);const n=e.headers.get("content-type")?.includes("application/json"),r=n?await e.json():await e.text(),l=Object.fromEntries(e.headers.entries());if(e.status<200||e.status>=400)throw function(e){return Object.assign(new Error,{response:e})}({status:e.status,data:r,headers:l});return{status:e.status,headers:l,data:r}}catch(e){if(clearTimeout(a),$(e))throw e;if(e instanceof Error)throw Object.assign(e,{response:{status:0,data:e.message||"Unknown error",headers:{}}});throw e}}return null!=n&&(t["X-Gist-Encoded-User-Token"]=n),i.post=(e,t={},n={})=>i(e,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json",...n.headers||{}}}),i}const k="gist.web.userLocale";function P(){const e=a(k);return null!==e?e:navigator.language}let L=600,T=!1;const M="gist.web.userQueueNextPullCheck",N="gist.web.sessionId";function D(){let e=a(N);return e||(e=y()),s(N,e,new Date((new Date).getTime()+18e5)),String(e)}const q="gist.web.userToken",A="gist.web.usingGuestUserToken",R="gist.web.guestUserToken";function W(){return null!==a(A)}function O(){return a(q)}function U(){if(null===O()){let e=a(R);null==e&&(e=y(),s(R,e),i(`Set guest user token "${e}" with expiry date set to 1 year from today`)),s(q,e),s(A,!0),i(`Using anonymous session with token: "${e}"`)}}async function z(){const e=O();return null===e?null:await async function(e){const t=(new TextEncoder).encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,"0")).join("")}(e)}function B(){const e=O();return null===e?null:btoa(e)}function F(){r(q),i("Cleared user token")}async function H(e){try{return await C().post(`/api/v1/logs/queue/${e}`)}catch(e){return E(e)}}function j(e){try{return(document.getElementById(e)??document.querySelector(e))||null}catch{return null}}const _={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 G(e){const t=_,n=e?.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:n.tooltipArrowColor||t.tooltipArrowColor,shouldScale:!!n.scale,campaignId:n.campaignId??null,messageWidth:null!=n.messageWidth&&n.messageWidth>0?n.messageWidth:t.messageWidth,hasCustomWidth:(n.messageWidth??0)>0,overlayColor:n.overlayColor||t.overlayColor,persistent:!!n.persistent,exitClick:!!n.exitClick}:t}const V=["x-gist-top","x-gist-floating-top","x-gist-bottom","x-gist-floating-bottom","x-gist-floating-bottom-left","x-gist-floating-bottom-right","x-gist-floating-top-left","x-gist-floating-top-right"];function X(e){if(document.getElementById(e))return;const t=document.createElement("div");t.id=e,"x-gist-top"===e?document.body.insertBefore(t,document.body.firstChild):document.body.insertAdjacentElement("beforeend",t),i("Top & bottom elements injected into page")}const J=["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"];function Y(e){return en.currentMessages.find(t=>t.instanceId===e)}function Q(e){return!!e&&en.currentMessages.some(t=>t.queueId===e)}function K(e){return e?en.currentMessages.find(t=>t.elementId===e)??null:null}function Z(e){en.currentMessages=en.currentMessages.filter(t=>t.instanceId!==e)}function ee(e,t){Z(e),en.currentMessages.push(t)}function te(e){const t={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"};return e&&t[e]?t[e]:(i(`Invalid overlay position "${e}", defaulting to "topCenter"`),t.topCenter)}function ne(e){return e.tooltipPosition?"tooltip":e.overlay?"modal":e.elementId&&V.includes(e.elementId)?"overlay":e.elementId?"inline":"modal"}function ie(e,t){const n=ne(e),i=t.displayType;if(void 0===i)return!1;if(n!==i)return!0;const o=G(e);switch(i){case"modal":{if((e.position||"center")!==(t.modalPosition||"center"))return!0;const n=t.dismissOutsideClick??_.exitClick;if(o.exitClick!==n)return!0;const i=t.overlayColor??_.overlayColor;if(o.overlayColor!==i)return!0;break}case"overlay":{const n=te(t.overlayPosition);if(e.elementId!==n)return!0;break}case"inline":if(e.elementId!==t.elementSelector)return!0;break;case"tooltip":if(e.tooltipPosition!==t.tooltipPosition)return!0;if(e.elementId!==t.elementSelector)return!0;if(void 0!==t.tooltipArrowColor&&o.tooltipArrowColor!==t.tooltipArrowColor)return!0}if("overlay"!==i||!J.includes(te(t.overlayPosition))){const e=t.maxWidth??_.messageWidth;if(o.messageWidth!==e)return!0}return!1}function oe(e,t){if(e.properties||(e.properties={}),e.properties.gist||(e.properties.gist={}),"modal"===t.displayType)e.overlay=!0,e.elementId=null,e.properties.gist.elementId=null,e.position=t.modalPosition||"center",e.properties.gist.position=t.modalPosition||"center",e.tooltipPosition=void 0,e.properties.gist.tooltipPosition=void 0,e.properties.gist.tooltipArrowColor=void 0;else if("overlay"===t.displayType){e.overlay=!1;const n=te(t.overlayPosition);e.elementId=n,e.properties.gist.elementId=n,e.position=null,e.properties.gist.position=null,e.tooltipPosition=void 0,e.properties.gist.tooltipPosition=void 0,e.properties.gist.tooltipArrowColor=void 0}else"inline"===t.displayType?(e.overlay=!1,e.elementId=t.elementSelector,e.properties.gist.elementId=t.elementSelector,e.position=null,e.properties.gist.position=null,e.tooltipPosition=void 0,e.properties.gist.tooltipPosition=void 0,e.properties.gist.tooltipArrowColor=void 0):"tooltip"===t.displayType&&(e.overlay=!1,e.elementId=t.elementSelector,e.properties.gist.elementId=t.elementSelector,e.tooltipPosition=t.tooltipPosition,e.properties.gist.tooltipPosition=t.tooltipPosition,e.position=null,e.properties.gist.position=null,void 0!==t.tooltipArrowColor&&(e.properties.gist.tooltipArrowColor=t.tooltipArrowColor));e.elementId&&J.includes(e.elementId)?delete e.properties.gist.messageWidth:void 0!==t.maxWidth&&t.maxWidth>0?e.properties.gist.messageWidth=t.maxWidth:delete e.properties.gist.messageWidth,void 0!==t.overlayColor?e.properties.gist.overlayColor=t.overlayColor:delete e.properties.gist.overlayColor,void 0!==t.dismissOutsideClick?e.properties.gist.exitClick=t.dismissOutsideClick:delete e.properties.gist.exitClick}const se={top:["bottom","left","right"],bottom:["top","left","right"],left:["right","top","bottom"],right:["left","top","bottom"]},ae=/auto|scroll/,re={top:"gist-arrow-bottom",bottom:"gist-arrow-top",left:"gist-arrow-right",right:"gist-arrow-left"};function le(e){const t=j(e);return t||i(`Tooltip target element not found for selector: ${e}`),t}function ce(e,t){if(e.bottom<=0||e.top>=window.innerHeight||e.right<=0||e.left>=window.innerWidth)return!1;for(const n of t){const t=n.getBoundingClientRect();if(e.bottom<=t.top||e.top>=t.bottom||e.right<=t.left||e.left>=t.right)return!1}return!0}function de(e,t,n){const i=function(e,t,n){switch(n){case"top":return{top:t.top-e.height-16,left:t.left+(t.width-e.width)/2};case"bottom":return{top:t.bottom+16,left:t.left+(t.width-e.width)/2};case"left":return{top:t.top+(t.height-e.height)/2,left:t.left-e.width-16};case"right":return{top:t.top+(t.height-e.height)/2,left:t.right+16}}}(e,t,n);return function(e,t,n){return"top"===n||"bottom"===n?e.top>=0&&e.top+t.height<=window.innerHeight:e.left>=0&&e.left+t.width<=window.innerWidth}(i,e,n)&&function(e,t){return"top"===t||"bottom"===t?e.width+8<=window.innerWidth:e.height+8<=window.innerHeight}(e,n)?function(e,t,n){let{top:i,left:o}=e,s=null;if("top"===n||"bottom"===n){const e=4,n=window.innerWidth-t.width-4;n>=e&&(o<e?(s=o-e,o=e):o>n&&(s=o-n,o=n))}else{const e=4,n=window.innerHeight-t.height-4;n>=e&&(i<e?(s=i-e,i=e):i>n&&(s=i-n,i=n))}if(null!==s){const e=("top"===n||"bottom"===n?t.width/2:t.height/2)-16-4;Math.abs(s)>e&&(s=s>0?e:-e)}return{top:i,left:o,position:n,arrowOffset:s}}(i,e,n):null}function pe(e,t,n){const i=de(e,t,n);if(i)return i;for(const i of se[n]){const n=de(e,t,i);if(n)return n}return null}function ue(e){const t=[];let n=e.parentElement;for(;n;){const e=getComputedStyle(n),i=e.overflow+e.overflowX+e.overflowY;ae.test(i)&&t.push(n),n=n.parentElement}return t}function ge(e){const t=j(e);t&&(t.classList.remove("gist-visible"),Array.from(t.classList).filter(e=>e.startsWith("gist-")).forEach(e=>t.classList.remove(e)),t.style.removeProperty("height"),t.style.removeProperty("width"),t.innerHTML="")}function me(e){const t=j(e);if(t)return!(!t.style||!t.style.height||"0px"===t.style.height)}function fe(e,t,n=null){const i=document.getElementById(e);i&&(i.onload=()=>{!function(e,t,n=null){const i=document.getElementById(e);if(i?.contentWindow){const e={options:t,capabilities:he};n&&(t.stepId=n),i.contentWindow.postMessage(e,"*")}}(e,t,n)})}const he=["MultiStepDisplayTypes"];function we(e){if(!e.displaySettings)return;const t=Se(e.instanceId??""),n=document.getElementById(t);n?.contentWindow&&n.contentWindow.postMessage({action:"updateDisplaySettings",displaySettings:e.displaySettings},"*")}async function ye(){const e=document.querySelector(".gist-message");e&&(e.classList.remove("gist-visible"),await new Promise(e=>setTimeout(e,300))),be()}function be(){const e=document.querySelector("#gist-embed-message");e&&e.parentNode?.removeChild(e)}const ve=new Map;function xe(e){const t=e.instanceId??"",n=ve.get(t);n&&(n.cleanup(),ve.delete(t));const i=j(`gist-tooltip-${t}`);i&&i.parentNode?.removeChild(i)}function Se(e){return`gist-${e}`}function Ie(){const e=document.querySelector(".gist-message");e&&e.classList.add("gist-visible")}const $e="gist.web.customAttributes";let Ee=new Map;function Ce(){const e=Array.from(Ee.entries()),t=new Date;t.setDate(t.getDate()+30),s($e,e,t),i(`Saved ${Ee.size} custom attributes to storage with TTL of 30 days`)}async function ke(e){const t=await Me();if(!t)return;const n=new Date;n.setMinutes(n.getMinutes()+60),s(t,e.filter(Le),n)}async function Pe(e,t){const n=a(e);return n?.find(e=>e.queueId===t)}function Le(e){return!(!e.properties?.gist||!e.properties.gist.broadcast)}function Te(e){if(!Le(e))return!1;const t=e.properties.gist.broadcast;return 0===t.frequency.delay&&0===t.frequency.count}async function Me(){const e=await z();return e?`gist.web.message.broadcasts.${e}`:null}function Ne(e,t){return`${e}.${t}.numberOfTimesShown`}function De(e,t){return`${e}.${t}.shouldShow`}!function(){const e=a($e);if(e)try{Ee=new Map(e)}catch{Ee=new Map}else Ee=new Map}();const qe="gist.web.message.user";async function Ae(e){const t=await Re();if(!t)return;const n=e.filter(e=>!(e.properties&&e.properties.gist&&e.properties.gist.broadcast)),i=new Date;i.setMinutes(i.getMinutes()+60),s(t,n,i)}async function Re(){const e=await z();return e?`${qe}.${e}`:null}async function We(){const e=await z();return e?`${qe}.${e}.seen`:null}async function Oe(e){const t=await z();return t?`${qe}.${t}.message.${e}.loading`:null}async function Ue(e){const t=await z();return t?`${qe}.${t}.message.${e}.state`:null}async function ze(e){const t=await Ue(e);t&&(r(t),i(`Cleared message state for queueId: ${e}`))}function Be(e){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="${e}"/></svg>`}const Fe=`\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(Be("#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 {\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-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 He="cioPreviewId",je="cioPreviewSettings";const _e="gist.previewBar.collapsed",Ge="gist-pb-styles",Ve="gist-preview-bar",Xe={topLeft:"Top Left",topCenter:"Top Center",topRight:"Top Right",bottomLeft:"Bottom Left",bottomCenter:"Bottom Center",bottomRight:"Bottom Right"};let Je=null,Ye=[],Qe={},Ke=null,Ze=!1,et=!1,tt=5,nt=null,it=!1,ot=null,st=null,at=null;const rt=new Map;function lt(e,t={}){const n=document.createElement(e);for(const[e,i]of Object.entries(t))n[e]=i;return n}function ct(e,t){const n=lt("div",{className:"gist-pb-label-group"});return n.appendChild(lt("span",{className:"gist-pb-label",textContent:e})),n.appendChild(t),n}function dt(e,t){const n=lt("select",{className:"gist-pb-select"});for(const i of e){const e=lt("option",{value:i.value,textContent:i.label});i.value===t&&(e.selected=!0),n.appendChild(e)}return n}function pt(e,t,n){const i=lt("input",{className:"gist-pb-input",type:e,value:String(t)});return n&&(i.style.width=n),i}function ut(e,t){const n=Math.round(Math.min(100,Math.max(0,t))/100*255);return"#"+e.replace("#","").toUpperCase()+n.toString(16).padStart(2,"0").toUpperCase()}function gt(e){return!!("inline"!==e.displayType&&"tooltip"!==e.displayType||e.elementSelector?.trim())}function mt(e){if("overlay"===e.displayType&&J.includes(te(e.overlayPosition))){const{maxWidth:t,...n}=e;e=n}if(Qe=e,Ke){const t=Ye.findIndex(e=>e.stepName===Ke);-1!==t&&(Ye[t]={...Ye[t],displaySettings:{...e}})}if(!Je)return;const t=en.currentMessages.find(e=>e.instanceId===Je);t&&gt(e)&&(we(t),ie(t,e)&&Ut(t,Ke,e)),function(){const e=new URLSearchParams(window.location.search).get(He);e&&async function(e,t){try{return await C()(`/api/v1/preview/${e}`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}})}catch(e){return E(e)}}(e,Ye).then(e=>{e&&404===e.status&&Je&&en.dismissMessage(Je)}).catch(()=>i("Failed to persist preview display settings"))}()}function ft(e){const t=e.value.trim();t&&!j(t)?e.classList.add("gist-pb-input--invalid"):e.classList.remove("gist-pb-input--invalid")}function ht(e,t){const n=pt("text",e.elementSelector||"","260px");n.placeholder="Element ID or selector",ft(n),n.addEventListener("change",()=>{const e=n.value.trim(),t=Qe.elementSelector;e&&wt(e),mt({...Qe,elementSelector:e}),t&&t!==e&&yt(t),ft(n)});const i=lt("button",{type:"button",className:"gist-pb-select-elem-btn",textContent:"Select Element"});i.addEventListener("click",()=>bt(n));const o=lt("div",{className:"gist-pb-inline-row"});o.appendChild(n),o.appendChild(i),t.appendChild(ct("Element Selector",o))}function wt(e){if(!e||rt.has(e))return;const t=j(e);t&&rt.set(e,t.innerHTML)}function yt(e){const t=rt.get(e);if(void 0===t)return;const n=j(e);n&&(n.innerHTML=t)}function bt(e){if(it)return;it=!0;const t={...Qe},n=en.currentMessages.find(e=>e.instanceId===Je)??null;n&&Ot(n),Qe.elementSelector&&yt(Qe.elementSelector);const o=lt("div",{className:"gist-pb-picker-overlay"});let s=null;const a=e=>{o.style.pointerEvents="none";const t=document.elementFromPoint(e.clientX,e.clientY);o.style.pointerEvents="all",t&&t!==s&&t!==o&&(s?.classList.remove("gist-pb-pick-highlight"),s=t,s.classList.add("gist-pb-pick-highlight"))},r=e=>{if("Escape"===e.key){if(c(),Qe=t,Ke){const e=Ye.findIndex(e=>e.stepName===Ke);-1!==e&&(Ye[e]={...Ye[e],displaySettings:{...t}})}n&&gt(t)&&Ut(n,Ke,t),vt()}},l=t=>{t.preventDefault(),t.stopPropagation(),o.style.pointerEvents="none";const s=document.elementFromPoint(t.clientX,t.clientY);if(o.style.pointerEvents="all",s&&s!==o){s.classList.remove("gist-pb-pick-highlight");const t=document.getElementById(Ve),o=t?.contains(s)?null:function(e){if(e.id){const t=CSS.escape(e.id);if(1===document.querySelectorAll(`#${t}`).length)return e.id}const t=[];let n=e;for(;n&&"BODY"!==n.tagName&&"HTML"!==n.tagName;){if(n.id){const e=CSS.escape(n.id);if(1===document.querySelectorAll(`#${e}`).length){t.unshift(`#${e}`);break}}let e=n.tagName.toLowerCase();n.className&&"string"==typeof n.className&&(e+=n.className.trim().split(/\s+/).filter(Boolean).map(e=>`.${CSS.escape(e)}`).join(""));const i=n.parentElement;i&&(e+=`:nth-of-type(${Array.from(i.children).filter(e=>e.tagName===n.tagName).indexOf(n)+1})`),t.unshift(e);try{if(1===document.querySelectorAll(t.join(" > ")).length)break}catch{}n=n.parentElement}const o=t.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}(s);if(null===o)return s.classList.add("gist-pb-pick-error"),void setTimeout(()=>{s.classList.remove("gist-pb-pick-error"),s.classList.add("gist-pb-pick-highlight")},800);e.value=o,wt(o);const a=Qe.elementSelector,r={...Qe,elementSelector:o},l=null!=n&&gt(r)&&ie(n,r);mt(r),a&&a!==o&&yt(a),n&&!l&&Ut(n,Ke,r)}c()},c=()=>{s?.classList.remove("gist-pb-pick-highlight"),o.removeEventListener("mousemove",a),o.removeEventListener("click",l),document.removeEventListener("keydown",r),document.body.removeChild(o),it=!1,ot=null};ot=c,o.addEventListener("mousemove",a),o.addEventListener("click",l),document.addEventListener("keydown",r),document.body.appendChild(o)}function vt(){const e=document.getElementById(Ve);if(!e)return;if(e.classList.toggle("gist-pb-hidden",!Je&&!et),e.innerHTML="",!Je){if(et){const t=lt("div",{className:"gist-pb-controls-row gist-pb-ended-row"}),n=lt("span",{className:"gist-pb-ended-icon",textContent:"✓"}),i=lt("p",{className:"gist-pb-ended-text"});i.innerHTML=`<strong>Preview session ended.</strong> Close this tab and navigate back to the message editor. Refreshing in ${tt}s…`,t.appendChild(n),t.appendChild(i),e.appendChild(t)}return}const t=lt("div",{className:"gist-pb-toggle-row"+(Ze?" gist-pb-toggle-row--collapsed":"")}),n=lt("button",{type:"button",className:"gist-pb-toggle-btn"}),i=Ze?"transform:rotate(180deg);display:inline-flex;":"display:inline-flex;";if(n.innerHTML=`${Ze?"Expand":"Collapse"}<span style="${i}">${Be("white")}</span>`,n.addEventListener("click",xt),t.appendChild(n),e.appendChild(t),Ze)return;const o=lt("div",{className:"gist-pb-controls-row"});if(Ye.length>0){const e=Ke??Ye[0].stepName,t=dt(Ye.map(e=>({value:e.stepName,label:e.stepName})),e);t.addEventListener("change",()=>{const e=Ye.find(e=>e.stepName===t.value);if(e){Ke=e.stepName,Qe={...e.displaySettings};const t=en.currentMessages.find(e=>e.instanceId===Je);t&&gt(e.displaySettings)&&Ut(t,e.stepName,e.displaySettings),vt()}}),o.appendChild(ct("Step",t))}const s=dt([{value:"modal",label:"Modal"},{value:"overlay",label:"Overlay"},{value:"inline",label:"Inline"},{value:"tooltip",label:"Tooltip"}],Qe.displayType||"modal");s.addEventListener("change",()=>{const e=s.value,t=Qe.displayType,n=Qe.elementSelector,i={...Qe,displayType:e};"modal"===e?(i.modalPosition=i.modalPosition||"center",i.maxWidth=i.maxWidth??414,delete i.overlayPosition,delete i.elementSelector,delete i.tooltipPosition):"overlay"===e?(i.overlayPosition=i.overlayPosition||"topCenter",i.maxWidth=i.maxWidth??414,delete i.modalPosition,delete i.elementSelector,delete i.tooltipPosition):"inline"===e?(delete i.modalPosition,delete i.overlayPosition,delete i.tooltipPosition):"tooltip"===e&&(i.tooltipPosition=i.tooltipPosition||"top",delete i.modalPosition,delete i.overlayPosition,delete i.overlayColor,delete i.dismissOutsideClick),Qe=i,mt(Qe),"inline"!==t&&"tooltip"!==t||!n||"inline"===e||"tooltip"===e||yt(n),vt()}),o.appendChild(ct("Display Type",s));const a=Qe.displayType||"modal";"modal"===a?function(e,t){const n=dt([{value:"top",label:"Top"},{value:"center",label:"Center"},{value:"bottom",label:"Bottom"}],e.modalPosition||"center");n.addEventListener("change",()=>mt({...Qe,modalPosition:n.value})),t.appendChild(ct("Position",n));const i=pt("number",e.maxWidth??414,"80px");i.addEventListener("change",()=>mt({...Qe,maxWidth:parseInt(i.value)||414})),t.appendChild(ct("Max Width",i)),t.appendChild(function(e){const{color:t,opacity:n}=function(e){const t=e.replace("#","");return 8===t.length?{color:"#"+t.slice(0,6).toUpperCase(),opacity:Math.round(parseInt(t.slice(6),16)/255*100)}:6===t.length?{color:"#"+t.toUpperCase(),opacity:100}:{color:"#000000",opacity:20}}(e.overlayColor||"#00000033"),i=lt("div",{className:"gist-pb-color-control"}),o=lt("input",{className:"gist-pb-color-input",type:"color",value:t}),s=lt("div",{className:"gist-pb-color-swatch"});s.style.background=t,s.appendChild(o),s.addEventListener("click",()=>o.click());const a=lt("input",{className:"gist-pb-color-hex",type:"text",maxLength:6,value:t.replace("#","")}),r=lt("input",{className:"gist-pb-color-opacity",type:"number",min:"0",max:"100",value:String(n)}),l=lt("span",{className:"gist-pb-color-pct",textContent:"%"}),c=()=>{const e="#"+a.value.replace("#",""),t=parseInt(r.value)||0;s.style.background=e,o.value=e,mt({...Qe,overlayColor:ut(e,t)})};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),ct("Overlay Color",i)}(e));const o=lt("div",{className:"gist-pb-checkbox-row"}),s=lt("input",{className:"gist-pb-checkbox",type:"checkbox"});s.checked=e.dismissOutsideClick??!1;const a=lt("label",{className:"gist-pb-checkbox-label",textContent:"Dismiss on click outside"});s.addEventListener("change",()=>mt({...Qe,dismissOutsideClick:s.checked})),a.addEventListener("click",()=>{s.checked=!s.checked,mt({...Qe,dismissOutsideClick:s.checked})}),o.appendChild(s),o.appendChild(a);const r=ct(" ",o);r.classList.add("gist-pb-label-group--grow"),r.firstChild.classList.add("gist-pb-label--spacer"),t.appendChild(r)}(Qe,o):"overlay"===a?function(e,t){const n=dt(Object.entries(Xe).map(([e,t])=>({value:e,label:t})),e.overlayPosition||"topCenter");if(n.addEventListener("change",()=>mt({...Qe,overlayPosition:n.value})),t.appendChild(ct("Position",n)),!J.includes(te(e.overlayPosition))){const n=pt("number",e.maxWidth??414,"80px");n.addEventListener("change",()=>mt({...Qe,maxWidth:parseInt(n.value)||414})),t.appendChild(ct("Max Width",n))}}(Qe,o):"inline"===a?function(e,t){ht(e,t)}(Qe,o):"tooltip"===a&&function(e,t){ht(e,t);const n=dt([{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"left",label:"Left"},{value:"right",label:"Right"}],e.tooltipPosition||"top");n.addEventListener("change",()=>mt({...Qe,tooltipPosition:n.value})),t.appendChild(ct("Position",n))}(Qe,o),o.appendChild(lt("div",{className:"gist-pb-spacer"}));const r=lt("button",{type:"button",className:"gist-pb-save-btn",textContent:"End session"});r.addEventListener("click",async()=>{Je&&await en.dismissMessage(Je)}),o.appendChild(r),e.appendChild(o)}function xt(){Ze=!Ze;try{sessionStorage.setItem(_e,String(Ze))}catch{}vt()}function St(e){if(et)return;Je=e.instanceId??null;const t=e.displaySettings;if(Array.isArray(t)&&t.length>0?(Ye=t,Ke||(Ke=Ye[0].stepName,Qe={...Ye[0].displaySettings})):t&&"object"==typeof t&&!Array.isArray(t)&&(Qe={...t}),st||at){const e=!!st,t=!!at,n=st,o=at;if(st=null,at=null,e){const e=Ye.find(e=>e.stepName===n);if(!e)return i(`Preview bar: step "${n}" not found, ignoring initial step/display override`),void vt();Ke=e.stepName,Qe={...e.displaySettings}}if(t){if(!e)return i(`Preview bar: display type "${o}" provided without a step, ignoring`),void vt();Qe={...Qe,displayType:o}}vt();const s=en.currentMessages.find(e=>e.instanceId===Je);return void(s&&gt(Qe)?Ut(s,Ke,Qe):function(){const e=Qe.displayType;if("inline"!==e&&"tooltip"!==e)return;const t=document.querySelector("#gist-preview-bar .gist-pb-input[type='text']");t&&bt(t)}())}vt()}function It(){(function(){for(const e of rt.keys())yt(e);rt.clear()})(),Je=null,Ye=[],Qe={},Ke=null,et=!0,tt=5;const e=new URLSearchParams(window.location.search).get(He);e&&async function(e){try{return await C()(`/api/v1/preview/${e}`,{method:"DELETE"})}catch(e){return E(e)}}(e).catch(()=>i("Failed to delete preview session")),vt(),nt&&clearInterval(nt),nt=setInterval(()=>{tt-=1,tt<=0?(clearInterval(nt),nt=null,F(),function(){try{sessionStorage.removeItem(o)}catch{}}(),window.location.reload()):vt()},1e3)}async function $t(e){if(!en.isDocumentVisible)return i("Document hidden, not showing message now."),null;if(Q(e.queueId))return i(`Message with queueId ${e.queueId} is already showing.`),null;const t=G(e);return!e.tooltipPosition&&t.hasTooltipPosition&&(e.tooltipPosition=t.tooltipPosition),e.tooltipPosition?function(e,t){const n=t.elementId||e.elementId;if(!n)return i(`No target selector specified for tooltip message ${e.messageId}`),en.messageError(e),null;if(!j(n)){if(!en.config.isPreviewSession||!e.properties?.gist?.livePreview)return i(`Tooltip target element "${n}" not found for message ${e.messageId}, skipping display`),en.messageError(e),null;i(`Preview: tooltip target "${n}" not found, loading message for preview bar`)}const o=en.currentMessages.find(e=>e.tooltipPosition&&e.elementId===n);o&&(i(`Tooltip already showing on target "${n}" (instance ${o.instanceId}), dismissing it first`),en.messageDismissed(o),xe(o),o.instanceId&&Z(o.instanceId)),e.instanceId=y(),e.overlay=!1,e.firstLoad=!0,e.shouldResizeHeight=!1,e.shouldScale=!1,e.renderStartTime=(new Date).getTime(),e.elementId=n,en.currentMessages.push(e);return Dt(e,null,e.savedStepName||null)}(e,t):en.overlayInstanceId?(i(`Message ${en.overlayInstanceId} already showing.`),null):(e.instanceId=y(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),en.overlayInstanceId=e.instanceId,en.currentMessages.push(e),Dt(e,null,e.savedStepName||null))}function Et(e,t){return en.isDocumentVisible?Q(e.queueId)?(i(`Message with queueId ${e.queueId} is already showing.`),null):K(t)?(i(`Message with elementId ${t} already has a message.`),null):(e.instanceId=y(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!me(t),e.renderStartTime=(new Date).getTime(),en.currentMessages.push(e),Dt(e,t,e.savedStepName||null)):(i("Document hidden, not showing message now."),null)}async function Ct(e){e?(en.messageDismissed(e),await kt(e)):i("Message not found")}async function kt(e){"tooltip"===ne(e)?Tt(e):e.overlay?await Mt(!0,e):Lt(e)}async function Pt(e){e?G(e).persistent&&(i("Persistent message dismissed, logging view"),await zt(e),await qt(e),await ze(e.queueId??"")):i("Message not found")}function Lt(e){e.instanceId&&Z(e.instanceId),e.elementId&&ge(e.elementId),en.config.isPreviewSession&&(It(),Nt())}function Tt(e){xe(e),e.instanceId&&Z(e.instanceId),0===en.currentMessages.length&&(window.removeEventListener("message",Rt),window.removeEventListener("touchstart",At)),en.config.isPreviewSession&&(It(),Nt())}async function Mt(e,t){e?await ye():be(),0===en.currentMessages.length&&(window.removeEventListener("message",Rt),window.removeEventListener("touchstart",At)),t.instanceId&&Z(t.instanceId),en.overlayInstanceId=null,en.config.isPreviewSession&&(It(),Nt())}function Nt(){const e=new URL(window.location.href);e.searchParams.delete(He),e.searchParams.delete(je),history.replaceState(null,"",e.toString())}function Dt(e,t=null,n=null){const o=en.config.env,s={endpoint:I.ENGINE_API_ENDPOINT[o],siteId:en.config.siteId,dataCenter:en.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId??"",livePreview:!1,properties:e.properties,customAttributes:Object.fromEntries(new Map(Ee))},a=`${I.GIST_VIEW_ENDPOINT[o]}/index.html`;return window.addEventListener("message",Rt),window.addEventListener("touchstart",At),"tooltip"===ne(e)?function(e,t,n,i=null){const o=t.instanceId??"",s=Se(o),a=G(t),r=ve.get(o);r&&(r.cleanup(),ve.delete(o)),document.querySelectorAll(`#gist-tooltip-${o}`).forEach(e=>{e.parentNode?.removeChild(e)});const l=`gist-tooltip-${o}`,c=document.createElement("div");c.id=l,c.innerHTML=function(e,t,n,i=""){let o=600;t.messageWidth>o&&(o=t.messageWidth);const s=t.tooltipArrowColor,a=function(e){switch(e){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"}}(t.tooltipPosition),r=i?`#${i} `:"";return`\n <div class="gist-tooltip-outer">\n <style>\n ${r}.gist-tooltip-outer {\n position: absolute;\n }\n ${r}.gist-tooltip-container {\n position: relative;\n z-index: 9999999;\n opacity: 0;\n transition: opacity 0.3s ease-in-out;\n }\n ${r}.gist-tooltip-container.gist-visible {\n opacity: 1;\n }\n ${r}.gist-tooltip-frame-clip {\n overflow: hidden;\n }\n ${r}.gist-tooltip-frame {\n display: block;\n width: ${t.messageWidth}px;\n border: none;\n transition: height 0.1s ease-in-out;\n }\n ${r}.gist-tooltip-arrow {\n width: 0;\n height: 0;\n position: absolute;\n z-index: 1;\n }\n ${r}.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 ${s};\n }\n ${r}.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 ${s};\n }\n ${r}.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 ${s};\n }\n ${r}.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 ${s};\n }\n @media (max-width: ${o}px) {\n ${r}.gist-tooltip-frame {\n max-width: 100%;\n }\n }\n </style>\n <div class="gist-tooltip-container">\n <div class="gist-tooltip-arrow ${a}"></div>\n <div class="gist-tooltip-frame-clip">\n <iframe id="${e}" class="gist-tooltip-frame" src="${n}"></iframe>\n </div>\n </div>\n </div>`}(s,a,e,l),document.body.appendChild(c),fe(s,n,i)}(a,e,s,n):t?(V.includes(t)&&X(t),function(e,t,n,o,s=null){const a=j(e);if(a){const i=Se(n.instanceId??"");a.classList.add(i);const r=G(n);let l=r.messageWidth+"px";J.includes(e)&&!r.hasCustomWidth&&(l="100%"),V.includes(e)&&(a.style.width=l),me(e)||(a.style.height="0px"),a.innerHTML=function(e,t,n){return function(e,t,n){let i=800;return t.messageWidth>i&&(i=t.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 }\n #x-gist-top.${e},\n #x-gist-bottom.${e},\n #x-gist-floating-top.${e},\n #x-gist-floating-bottom.${e},\n #x-gist-floating-top-left.${e},\n #x-gist-floating-top-right.${e},\n #x-gist-floating-bottom-left.${e},\n #x-gist-floating-bottom-right.${e} {\n transition: height 0.1s ease-in-out;\n }\n @media (max-width: ${i}px) {\n #x-gist-top.${e},\n #x-gist-bottom.${e},\n #x-gist-floating-top.${e},\n #x-gist-floating-bottom.${e},\n #x-gist-floating-top-left.${e},\n #x-gist-floating-top-right.${e},\n #x-gist-floating-bottom-left.${e},\n #x-gist-floating-bottom-right.${e} {\n width: 100% !important;\n }\n }\n </style>\n <div id="gist-embed-container">\n <iframe id="${e}" class="gist-frame" src="${n}"></iframe>\n </div>\n </div>`}(Se(t.instanceId??""),n,e)}(t,n,r),fe(i,o,s)}else i(`Message could not be embedded, elementId ${e} not found.`)}(t,a,e,s,n)):function(e,t,n,i=null){document.querySelectorAll("#gist-embed-message").forEach(e=>{e.parentNode?.removeChild(e)}),document.body.insertAdjacentHTML("afterbegin",function(e,t){const n=G(t);return function(e,t,n){let i=600;return t.messageWidth>i&&(i=t.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: ${t.overlayColor};\n visibility: hidden;\n }\n #gist-overlay.gist-background.gist-visible {\n visibility: visible;\n }\n .gist-message {\n width: ${t.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 }\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: ${i}px) {\n .gist-message {\n width: 100%;\n }\n }\n </style>\n <div id="gist-overlay" class="gist-background">\n <iframe id="${e}" class="gist-message" src="${n}"></iframe>\n </div>\n </div>`}(Se(t.instanceId??""),n,e)}(e,t)),fe(Se(t.instanceId??""),n,i)}(a,e,s,n),e}async function qt(e){let t;i(`Message shown, logging view for: ${e.messageId}`),null!=e.queueId?(await zt(e),t=await H(e.queueId)):t=await async function(e){try{return await C().post(`/api/v1/logs/message/${e}`)}catch(e){return E(e)}}(e.messageId),i(200===t?.status?"Message view logged":`Problem logging message: ${t?.status}`)}function At(){}async function Rt(e){const t=e.data;if(t.gist&&e.origin===I.RENDERER_HOST){const e=t.gist.instanceId,n=Y(e);if(!n)return;const o=G(n);switch(t.gist.method){case"routeLoaded":{const s=.001*((new Date).getTime()-(n.renderStartTime??0));if(i(`Engine render for message: ${n.messageId} timer elapsed in ${s.toFixed(3)} seconds`),async function(e){const t=await Oe(e);t&&r(t)}(n.queueId??""),n.currentRoute=t.gist.parameters.route,t.gist.parameters.fullDisplaySettings&&!n.displaySettings?n.displaySettings=t.gist.parameters.fullDisplaySettings:n.displaySettings&&(i("SDK already has display settings state, sending it to iframe"),we(n)),en.config.isPreviewSession&&n.properties?.gist?.livePreview&&St(n),n.firstLoad||n.isDisplayChange){if("tooltip"===ne(n)){const e=n.properties?.gist?.elementId||n.elementId||void 0;if(!e||!j(e)){if(en.config.isPreviewSession&&n.properties?.gist?.livePreview){i(`Preview: tooltip target "${e}" not found, preview bar will show element picker`),n.firstLoad=!1,n.isDisplayChange=!1;break}i(`Tooltip target not found for "${e}", emitting error and skipping display`),en.messageError(n),n.firstLoad=!1,n.isDisplayChange=!1,Tt(n);break}const t=await async function(e){const t=e.instanceId??"",n=G(e),o=`gist-tooltip-${t}`,s=j(o);if(!s)return i(`Tooltip wrapper not found for instance ${t}`),!1;const a=e.properties?.gist?.elementId||e.elementId||void 0;if(!a)return i(`No target selector for tooltip ${t}`),!1;const r=ve.get(t);r&&(r.cleanup(),ve.delete(t));const l=s.querySelector(".gist-tooltip-outer");if(!l)return i(`Tooltip inner element not found for instance ${t}`),!1;const c=n.tooltipPosition||"bottom";if(!await async function(e,t,n){const o=le(t);if(!o)return!1;let s=[];try{s=ue(o)}catch{}if(ce(o.getBoundingClientRect(),s))return!0;if(!function(e,t,n){const i=le(t);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 e.style.display="",null!==pe(e.getBoundingClientRect(),r,n)}(e,t,n))return i(`Preflight failed: tooltip would not fit after scrolling target "${t}" into view`),!1;o.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),await function(e){return new Promise(t=>{let n=e.getBoundingClientRect(),i=0;const o=Date.now();setTimeout(function s(){const a=e.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?t():setTimeout(s,50)},50)})}(o);const a=o.getBoundingClientRect();let r=[];try{r=ue(o)}catch{}return ce(a,r)}(l,a,c))return i(`Tooltip for instance ${t} skipped: target "${a}" is off-screen and cannot be scrolled into a valid position`),!1;const d=function(e,t,n,o){const s=le(t);if(!s)return null;let a=null,r=null,l=!1,c=[],d=null;try{c=ue(s)}catch{}function p(){if(l)return;if(!s||!document.contains(s)||!document.contains(e))return i("Tooltip or target element removed from DOM, cleaning up listeners"),g(),void o?.onDetach?.();const t=s.getBoundingClientRect();if(!ce(t,c))return void(e.style.display="none");e.style.display="";const a=pe(e.getBoundingClientRect(),t,n);a?(function(e,t){e.style.position="absolute",e.style.top=`${t.top+window.scrollY}px`,e.style.left=`${t.left+window.scrollX}px`}(e,a),function(e,t){const n=e.querySelector(".gist-tooltip-arrow");n&&(n.classList.remove("gist-arrow-top","gist-arrow-bottom","gist-arrow-left","gist-arrow-right"),n.classList.add(re[t.position]),null!==t.arrowOffset?"top"===t.position||"bottom"===t.position?(n.style.left=`calc(50% + ${t.arrowOffset}px)`,n.style.removeProperty("top")):(n.style.top=`calc(50% + ${t.arrowOffset}px)`,n.style.removeProperty("left")):"top"===t.position||"bottom"===t.position?(n.style.left="50%",n.style.removeProperty("top")):(n.style.top="50%",n.style.removeProperty("left")))}(e,a)):e.style.display="none"}function u(){null===a&&(a=requestAnimationFrame(()=>{a=null,p()}))}function g(){if(!l){l=!0,d&&(d.disconnect(),d=null),window.removeEventListener("scroll",u),window.removeEventListener("resize",u);for(const e of c)e.removeEventListener("scroll",u);null!==a&&(cancelAnimationFrame(a),a=null),null!==r&&(cancelAnimationFrame(r),r=null)}}if(p(),l)return null;window.addEventListener("scroll",u,{passive:!0}),window.addEventListener("resize",u,{passive:!0});for(const e of c)e.addEventListener("scroll",u,{passive:!0});try{d=new MutationObserver(()=>{null===r&&(r=requestAnimationFrame(()=>{r=null,document.contains(s)||p()}))}),d.observe(document.body,{childList:!0,subtree:!0})}catch{}return{cleanup:g,reposition:p}}(l,a,c,{onDetach:()=>{ve.delete(t);const e=j(o);e&&e.parentNode?.removeChild(e)}});if(d){if("none"!==l.style.display){const e=s.querySelector(".gist-tooltip-container");return e?(ve.set(t,d),e.classList.add("gist-visible"),!0):(d.cleanup(),i(`Tooltip container not found for instance ${t}`),!1)}return d.cleanup(),i(`Tooltip for instance ${t} could not be positioned within the viewport, target "${a}" may be off-screen`),!1}return i(`Failed to position tooltip for instance ${t}, target "${a}" may not exist or no position fits the viewport`),!1}(n);if(!t){if(en.config.isPreviewSession&&n.properties?.gist?.livePreview){i(`Preview: tooltip positioning failed for "${e}", preview bar will remain active`),n.firstLoad=!1,n.isDisplayChange=!1;break}i(`Tooltip positioning failed for "${e}", emitting error and cleaning up`),en.messageError(n),n.firstLoad=!1,n.isDisplayChange=!1,Tt(n);break}}else n.overlay?function(e){const t=G(e),n=document.querySelector("#gist-overlay");if(n){n.classList.add("gist-visible");const i=document.querySelector(".gist-message");i&&(e.position?i.classList.add("gist-"+e.position):i.classList.add("gist-center")),setTimeout(Ie,100),t.exitClick&&setTimeout(()=>function(e){const t=document.querySelector("#gist-overlay");t&&t.addEventListener("click",()=>{en.dismissMessage(e)})}(e.instanceId??""),1e3)}else be()}(n):function(e){const t=j(e);t&&t.classList.add("gist-visible")}(n.elementId);n.firstLoad&&!n.isDisplayChange&&(en.messageShown(n),o.persistent?i("Persistent message shown, skipping logging view"):await qt(n)),n.firstLoad=!1,n.isDisplayChange=!1}ee(e,n);break}case"tap":{const e=t.gist.parameters.action,i=t.gist.parameters.name;if(en.messageAction(n,e,i),t.gist.parameters.system&&!o.persistent){await Ct(n);break}try{const t=new URL(e);if(t&&"gist:"===t.protocol)switch(t.href.replace("gist://","").split("?")[0]){case"close":await Pt(n),await Bt(n),await Ct(n),await Yt();break;case"showMessage":{const e=t.searchParams.get("messageId"),n=t.searchParams.get("properties");if(e){const t=n?JSON.parse(atob(n)):void 0;await en.showMessage({messageId:e,properties:t})}break}case"loadPage":{const e=t.href.substring(t.href.indexOf("?url=")+5);e&&(e.startsWith("mailto:")||e.startsWith("https://")||e.startsWith("http://")||e.startsWith("/")?window.location.href=e:window.location.href=window.location+e);break}}}catch{}break}case"changeMessageStep":{const e=t.gist.parameters.displaySettings,r=t.gist.parameters.messageStepName;en.config.isPreviewSession&&r&&n.properties?.gist?.livePreview&&function(e,t){if(et)return;Ke=e;const n=Ye.find(t=>t.stepName===e);n?Qe={...n.displaySettings}:t&&(Qe={...t}),vt()}(r,e),(o.persistent||Te(n))&&await async function(e,t,n){const o=await Ue(e);if(!o)return;const r=a(o)||{},l={stepName:void 0!==t?t: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: ${e}`)}(n.queueId??"",r,e),e&&ie(n,e)&&(i("Display settings changed, reloading message"),await Ot(n),oe(n,e),await Wt(n,r??null));break}case"routeChanged":n.currentRoute=t.gist.parameters.route,n.renderStartTime=(new Date).getTime(),ee(e,n),i(`Route changed to: ${n.currentRoute}`);break;case"sizeChanged":i(`Size Changed Width: ${t.gist.parameters.width} - Height: ${t.gist.parameters.height}`),"tooltip"===ne(n)?function(e,t){const n=e.instanceId??"",i=Se(n),o=document.getElementById(i);if(o&&t.height>0){o.style.height=`${t.height}px`;const e=ve.get(n);e&&e.reposition()}}(n,t.gist.parameters):n.elementId&&!n.shouldResizeHeight||function(e,t){const n=j(e.elementId?e.elementId:Se(e.instanceId??""));if(n){const i=n.style;if(t.height>0)if(t.height>window.innerHeight){const n=1-(t.height/window.innerHeight-1);e.shouldScale&&n>=.4?(i.height=`${t.height}px`,i.transform=`translateX(-50%) translateY(-50%) scale(${n})`):i.height=`${window.innerHeight}px`}else i.height=`${t.height}px`}}(n,t.gist.parameters);break;case"titleChanged":i(`Overlay title changed to: ${t.gist.parameters.title}`),function(e,t){const n=j(Se(e));n&&(n.title=t)}(e,t.gist.parameters.title);break;case"eventDispatched":en.events.dispatch("eventDispatched",{name:t.gist.parameters.name,payload:t.gist.parameters.payload});break;case"error":case"routeError":en.messageError(n),"tooltip"===ne(n)?Tt(n):en.overlayInstanceId?await Mt(!1,n):Lt(n)}}}async function Wt(e,t){e.isDisplayChange=!0,e.renderStartTime=(new Date).getTime();const n=ne(e),o=e.elementId||null;if("tooltip"===n)return en.overlayInstanceId===e.instanceId&&(en.overlayInstanceId=null),e.shouldScale=!1,e.shouldResizeHeight=!1,void Dt(e,null,t);if(o){const t=K(o);t&&t.instanceId!==e.instanceId&&(i(`Dismissing existing message at ${o} to make room for multi-step message`),await Ct(t))}if(e.overlay){en.overlayInstanceId=e.instanceId??null;const t=G(e);e.shouldScale=t.shouldScale,e.shouldResizeHeight=!0}else en.overlayInstanceId=null,e.shouldScale=!1,e.shouldResizeHeight=!me(o??"");o&&V.includes(o)&&X(o),Dt(e,o,t)}async function Ot(e){"tooltip"===ne(e)?xe(e):e.overlay?await ye():e.elementId&&ge(e.elementId)}async function Ut(e,t,n){n&&ie(e,n)&&(await Ot(e),oe(e,n)),await Wt(e,t??null)}async function zt(e){i(`Logging user message view locally for: ${e.queueId}`),Le(e)?await async function(e){i(`Marking broadcast ${e} as seen.`);const t=await Me();if(!t)return;const n=await Pe(t,e);if(!n)return;const o=n.properties.gist.broadcast,{frequency:r}=o,l=Ne(t,e),c=De(t,e),d=a(l)||0;if(s(l,d+1),1===r.count)s(c,!1),i(`Marked broadcast ${e} as seen.`);else{const t=new Date;t.setSeconds(t.getSeconds()+r.delay),s(c,!1,t),i(`Marked broadcast ${e} as seen, broadcast was seen ${d+1} times, next show date is ${t}.`)}}(e.queueId??""):await async function(e){const t=await We();if(!t)return;const n=a(t)??[];n.push(e),s(t,n)}(e.queueId??"")}async function Bt(e){Le(e)&&(i(`Logging broadcast dismissed locally for: ${e.queueId}`),await async function(e){i(`Marking broadcast ${e} as dismissed.`);const t=await Me();if(!t)return;const n=await Pe(t,e);n&&(!0!==n.properties.gist.broadcast.frequency.ignoreDismiss?(s(De(t,e),!1),i(`Marked broadcast ${e} as dismissed and will not show again.`)):i(`Broadcast ${e} is set to ignore dismiss.`))}(e.queueId??""),await ze(e.queueId??""))}const Ft="messageInboxUpdated";async function Ht(e){const t=await _t();if(!t)return;const n=new Date;n.setMinutes(n.getMinutes()+60),s(t,e,n),en.events.dispatch(Ft,e)}async function jt(){const e=await _t();if(!e)return[];const t=a(e)??[],n=new Date;return t.filter(e=>!e.expiry||new Date(e.expiry)>n)}async function _t(){const e=await z();return e?`gist.web.inbox.messages.${e}`:null}const Gt=(e,t)=>e().then((e=>new Promise(t=>setTimeout(t,e)))(t).then(()=>Gt(e,t)));let Vt=!1,Xt=null;async function Jt(){Vt?await Yt():O()?(i("Queue watcher started"),Vt=!0,Gt(()=>new Promise(()=>{!async function(){if(I.hasActiveSSEConnection())return!I.isSSEConnectionManagedBySDK()&&Xt&&(i("Not the main instance, closing our SSE connection."),Zt()),void await Yt();Xt&&(i("SSE connection not active, closing it."),Zt()),!I.useSSE()||W()?await Kt():await async function(){Zt();const e=function(){const e=B();return null===e?(i("No user token available for SSE endpoint."),null):I.GIST_QUEUE_REALTIME_API_ENDPOINT[en.config.env??"prod"]+`/api/v3/sse?userToken=${e}&siteId=${en.config.siteId}&sessionId=${D()}`}();if(null===e)return i("SSE endpoint not available, falling back to polling."),void await Kt();i(`Starting SSE queue listener on ${e}`),Xt=new EventSource(e),I.setActiveSSEConnection(),Xt.addEventListener("connected",async e=>{try{i("SSE connection received"),I.setUseSSEFlag(!0);const t=JSON.parse(e.data);t.heartbeat&&(I.setSSEHeartbeat(t.heartbeat),i(`SSE heartbeat set to ${t.heartbeat} seconds`)),I.setActiveSSEConnection()}catch(e){i(`Failed to parse SSE settings: ${e}`)}r(M),await Kt()}),Xt.addEventListener("messages",async e=>{try{const t=JSON.parse(e.data);i("SSE message received"),await Ae(t),await ke(t),await Yt()}catch(e){i(`Failed to parse SSE message: ${e}`),Zt()}}),Xt.addEventListener("inbox_messages",async e=>{try{const t=JSON.parse(e.data);i("SSE inbox messages received"),await Ht(t)}catch(e){i(`Failed to parse SSE inbox messages: ${e}`)}}),Xt.addEventListener("error",async()=>{i("SSE error received"),Zt()}),Xt.addEventListener("heartbeat",async()=>{i("SSE heartbeat received"),I.setActiveSSEConnection(),I.setUseSSEFlag(!0)})}()}()}),1e3)):i("User token not setup, queue not started.")}async function Yt(){const e=await async function(){const e=await Me();return e?(a(e)??[]).filter(t=>{const n=t.properties.gist.broadcast,{frequency:i}=n,o=a(De(e,t.queueId))??!0,s=a(Ne(e,t.queueId))||0,r=0===i.count;return o&&(r||s<i.count)}):[]}(),t=await async function(){const e=await Re();if(!e)return[];const t=a(e)??[],n=await async function(){const e=await We();return e?a(e)??[]:[]}();return t.filter(e=>!n.includes(e.queueId??""))}(),n=e.concat(t);i(`Messages in local queue: ${n.length}`);const o=n.sort((e,t)=>e.priority-t.priority);for(const e of o)await Qt(e)}async function Qt(e){let t=G(e);if(t.hasRouteRule){let e=en.currentRoute;null==e&&(e=new URL(window.location.href).pathname);const n=t.routeRule;if(i(`Verifying route ${e} against rule: ${n}`),!new RegExp(n).test(e))return i(`Route ${e} does not match rule.`),!1}if(t.hasPosition&&(e.position=t.position),t.hasTooltipPosition&&(e.tooltipPosition=t.tooltipPosition),t.persistent||Te(e)){const n=await async function(e){const t=await Ue(e);return t?a(t):null}(e.queueId??"");n&&(i(`Restoring saved state for queueId ${e.queueId}`),n.displaySettings&&(oe(e,n.displaySettings),t=G(e)),e.savedStepName=n.stepName??null)}if(t.persistent||Te(e)||!await async function(e){const t=await Oe(e);return!!t&&null!==a(t)}(e.queueId??"")){let n=null;return t.isEmbedded?en.config.isPreviewSession&&e.properties?.gist?.livePreview&&!j(t.elementId)?(i(`Preview: element "${t.elementId}" not found, showing as overlay so placement can be changed`),n=await $t(e)):n=Et(e,t.elementId):n=await $t(e),n&&async function(e){const t=await Oe(e);t&&s(t,!0,new Date(Date.now()+5e3))}(e.queueId??""),null!==n}return i(`Not showing message with queueId ${e.queueId} because its already loading.`),!1}async function Kt(){if(O())if(en.isDocumentVisible)if(null===a(M)){const e=await async function(){const e=O();let t;try{if(!T){T=!0;const e={"X-Gist-User-Anonymous":String(W()),"Content-Language":String(P())};t=await C().post(`/api/v4/users?sessionId=${D()}`,{},{headers:e})}}catch(e){const n=E(e);n?t=n:i(`Error getting user queue: ${e}`)}finally{T=!1}return e!==O()?(i("User token changed, clearing queue next pull check."),void r(M)):(function(e){if(e?.headers){const t=e.headers["x-gist-queue-polling-interval"];t&&Number(t)>0&&(L=Number(t))}const t=new Date((new Date).getTime()+1e3*L);s(M,L,t)}(t),function(e){const t="true"===e?.headers?.["x-cio-use-sse"]?.toLowerCase();I.setUseSSEFlag(t)}(t),t)}();if(e){if(200===e.status||204===e.status){i("200 response, updating local store.");const t=e.data,n=t?.inAppMessages??[],o=t?.inboxMessages??[];Ae(n),ke(n),Ht(o)}else 304===e.status&&i("304 response, using local store.");await Yt()}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 Zt(e=!1){e&&I.removeActiveSSEConnection(),(e||I.isSSEConnectionManagedBySDK())&&I.setUseSSEFlag(!1),Xt&&(i("Stopping SSE queue listener..."),Xt.close(),Xt=null)}class en{static async setup(e){this.initialized?i("Gist SDK already initialized, skipping setup."):(this.initialized=!0,this.events=new n,this.config={useAnonymousSession:e.useAnonymousSession??!1,siteId:e.siteId,dataCenter:e.dataCenter,env:e.env??"prod",logging:e.logging??!1,experiments:e.experiments??!1},this.currentMessages=[],ve.forEach(e=>e.cleanup()),ve.clear(),document.querySelectorAll('[id^="gist-tooltip-"]').forEach(e=>{e.parentNode?.removeChild(e)}),this.overlayInstanceId=null,this.currentRoute=null,this.isDocumentVisible=!0,this.config.isPreviewSession=function(){const e=new URLSearchParams(window.location.search),t=e.get(He);if(t){sessionStorage.setItem(o,String(!1)),en.setUserToken(t),i(`Preview mode enabled with user token: ${t}`),function(){if(document.getElementById(Ve))return;!function(){if(document.getElementById(Ge))return;const e=document.createElement("style");e.id=Ge,e.textContent=Fe,document.head.appendChild(e)}();try{Ze="true"===sessionStorage.getItem(_e)}catch{Ze=!1}const e=lt("div",{id:Ve});document.body.appendChild(e),vt()}();const n=e.get(je);if(n)try{const e=JSON.parse(atob(n)),t=e.stepName||null,i=e.displayType||null;(t||i)&&function(e,t){st=e,at=t}(t,i)}catch{i("Preview bar: failed to parse cioPreviewSettings")}}return!l()}(),function(){const e=c();for(let t=e.length-1;t>=0;t--)d(e.key(t))}(),i(`Setup complete on ${this.config.env} environment.`),this.config.isPreviewSession||!this.config.useAnonymousSession||new URLSearchParams(location.search).has("ajs_uid")||U(),await Jt(),document.addEventListener("visibilitychange",async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await Yt())},!1))}static async setCurrentRoute(e){this.currentRoute=e,i(`Current route set to: ${e}`),await async function(){if(0!==en.currentMessages.length)for(const e of[...en.currentMessages])null==document.querySelector(`#gist-${e.instanceId}`)&&(i(`Removing active message ${e.instanceId} that no longer exists after route change`),await kt(e))}(),await Yt()}static async setUserToken(e,t){this.config.isPreviewSession||(function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),s(q,e,t),W()&&(r(M),r(A)),i(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),Zt(!0),await Jt())}static setUserLocale(e){var t;s(k,t=e),i(`Set user locate to "${t}"`)}static setCustomAttribute(e,t){return function(e,t){return e&&"string"==typeof e?(Ee.set(e,t),Ce(),i(`Set custom attribute "${e}" to "${t}"`),!0):(i(`Invalid key for custom attribute: ${e}`),!1)}(e,t)}static clearCustomAttributes(){Ee.clear(),r($e),i("Cleared all custom attributes")}static removeCustomAttribute(e){return function(e){if(!e||"string"!=typeof e)return i(`Invalid key for custom attribute: ${e}`),!1;const t=Ee.has(e);return Ee.delete(e),Ee.size>0?Ce():r($e),i(`Removed custom attribute "${e}"`),t}(e)}static async clearUserToken(){this.config.isPreviewSession||(F(),this.config.useAnonymousSession&&U(),Zt(!0),await Jt())}static async dismissMessage(e){const t=Y(e);t&&(await Pt(t),await Bt(t),await Ct(t),await Yt())}static async embedMessage(e,t){const n=Et(e,t);return n?.instanceId??null}static async showMessage(e){const t=await $t(e);return t?.instanceId??null}static updateMessageDisplaySettings(e,t){const n=Y(e);return!!n&&(n.displaySettings=t,we(n),!0)}static messageShown(e){i(`Message shown: ${e.messageId}`),this.events.dispatch("messageShown",e)}static messageDismissed(e){null!==e&&(i(`Message dismissed: ${e.messageId}`),this.events.dispatch("messageDismissed",e))}static messageError(e){i(`Message error: ${e.messageId}`),this.events.dispatch("messageError",e)}static messageAction(e,t,n){i(`Message action: ${e.currentRoute}, ${t} with name ${n} on ${e.instanceId}`),this.events.dispatch("messageAction",{message:e,action:t,name:n})}static async getInboxUnopenedCount(){return(await jt()).filter(e=>!e.opened).length}static async getInboxMessages(){return await jt()}static async updateInboxMessageOpenState(e,t){return await async function(e,t){const n=await _t();if(!n)return;const o=await async function(e,t){try{return await C()(`/api/v1/messages/${e}`,{method:"PATCH",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}})}catch(e){return E(e)}}(e,{opened:t});if(!o||o.status<200||o.status>=300){const e=`Failed to mark inbox message opened: ${o?.status??"unknown error"}`;throw i(e),new Error(e)}const a=await jt();let r=null;const l=a.map(n=>{if(n.queueId===e){const e={...n,opened:t};return r=e,e}return n}),c=new Date;if(c.setMinutes(c.getMinutes()+60),s(n,l,c),r){const e=t?"opened":"unopened";en.events.dispatch("inboxMessageAction",{message:r,action:e})}en.events.dispatch(Ft,await jt())}(e,t)}static async removeInboxMessage(e){return await async function(e){const t=await _t();if(!t)return;const n=await H(e);if(!n||n.status<200||n.status>=300){const e=`Failed to remove inbox message: ${n?.status??"unknown error"}`;throw i(e),new Error(e)}const o=(await jt()).filter(t=>t.queueId!==e),a=new Date;a.setMinutes(a.getMinutes()+60),s(t,o,a),en.events.dispatch(Ft,await jt())}(e)}}return t.default})());
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Gist=t():e.Gist=t()}(this,()=>(()=>{"use strict";var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>en});class n{constructor(){this.callbacks={}}on(e,t){const n=this.callbacks[e];n?n.push(t):this.callbacks[e]=[t]}off(e,t){const n=this.callbacks[e];if(!n)return;if(!t)return void delete this.callbacks[e];const i=n.indexOf(t);-1!==i&&n.splice(i,1),0===n.length&&delete this.callbacks[e]}dispatch(e,t){const n=this.callbacks[e];n&&n.forEach(e=>e(t))}}function i(e){en.config&&en.config.logging&&console.log(`Gist: ${e}`)}const o="gist.web.isPersistingSession";function s(e,t,n=null){let i=n;i||(i=new Date,i.setDate(i.getDate()+365));const o={value:t,expiry:i};c().setItem(e,JSON.stringify(o))}function a(e){return d(e)}function r(e){c().removeItem(e)}function l(){const e=sessionStorage.getItem(o);return null===e?(sessionStorage.setItem(o,"true"),!0):"true"===e}function c(){return l()?localStorage:sessionStorage}function d(e){if(!e)return null;try{const t=c().getItem(e);if(!t)return null;const n=JSON.parse(t);if(!n.expiry)return n.value;const i=new Date,o=new Date(n.expiry),s=e.startsWith("gist.web.message.broadcasts")&&!e.endsWith("shouldShow")&&!e.endsWith("numberOfTimesShown")||e.startsWith("gist.web.message.user")&&!e.endsWith("seen")&&!e.endsWith("state"),a=new Date(i.getTime()+366e4);return s&&o.getTime()>a.getTime()||i.getTime()>o.getTime()?(r(e),null):n.value}catch(t){i(`Error checking key ${e} for expiry: ${t}`)}return null}var p,u=new Uint8Array(16);function g(){if(!p&&!(p="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return p(u)}const m=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var f=[],h=0;h<256;++h)f.push((h+256).toString(16).substr(1));const w=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(f[e[t+0]]+f[e[t+1]]+f[e[t+2]]+f[e[t+3]]+"-"+f[e[t+4]]+f[e[t+5]]+"-"+f[e[t+6]]+f[e[t+7]]+"-"+f[e[t+8]]+f[e[t+9]]+"-"+f[e[t+10]]+f[e[t+11]]+f[e[t+12]]+f[e[t+13]]+f[e[t+14]]+f[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&m.test(e)}(n))throw TypeError("Stringified UUID is invalid");return n},y=function(e,t,n){var i=(e=e||{}).random||(e.rng||g)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=i[o];return t}return w(i)},b="gist.web.userQueueUseSSE",v="gist.web.activeSSEConnection";let x,S=30;const I={RENDERER_HOST:"https://code.gist.build",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://api.local.gist.build:86"},GIST_QUEUE_REALTIME_API_ENDPOINT:{prod:"https://realtime.cloud.gist.build",dev:"https://realtime.cloud.dev.gist.build",local:"http://api.local.gist.build:3000"},GIST_VIEW_ENDPOINT:{prod:"https://renderer.gist.build/3.0",dev:"https://renderer.gist.build/3.0",local:"http://app.local.gist.build:8080/web"},getSdkId:()=>(x||(x=y()),x),useSSE:()=>a(b)??!1,setUseSSEFlag(e){s(b,e,new Date((new Date).getTime()+6e4)),i(`Set user uses SSE to "${e}"`)},removeActiveSSEConnection(){r(v)},setActiveSSEConnection(){s(v,I.getSdkId(),new Date((new Date).getTime()+I.getSSEHeartbeat()))},hasActiveSSEConnection:()=>a(v)??!1,isSSEConnectionManagedBySDK:()=>a(v)===I.getSdkId(),getSSEHeartbeat:()=>1e3*(S+5),setSSEHeartbeat(e){e&&e>0&&(S=e)}};function $(e){return null!==e&&"object"==typeof e&&"response"in e}function E(e){return $(e)?e.response:void 0}function C(){const e=I.GIST_QUEUE_API_ENDPOINT[en.config.env??"prod"],t={"X-CIO-Site-Id":en.config.siteId,"X-CIO-Client-Platform":"web"},n=B();async function i(n,i={}){const o=e+n,s=new AbortController,a=setTimeout(()=>s.abort(),5e3);try{const e=await fetch(o,{method:i.method||"GET",headers:{...t,...i.headers||{}},body:i.method&&"GET"!==i.method.toUpperCase()?i.body:void 0,signal:s.signal});clearTimeout(a);const n=e.headers.get("content-type")?.includes("application/json"),r=n?await e.json():await e.text(),l=Object.fromEntries(e.headers.entries());if(e.status<200||e.status>=400)throw function(e){return Object.assign(new Error,{response:e})}({status:e.status,data:r,headers:l});return{status:e.status,headers:l,data:r}}catch(e){if(clearTimeout(a),$(e))throw e;if(e instanceof Error)throw Object.assign(e,{response:{status:0,data:e.message||"Unknown error",headers:{}}});throw e}}return null!=n&&(t["X-Gist-Encoded-User-Token"]=n),i.post=(e,t={},n={})=>i(e,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json",...n.headers||{}}}),i}const k="gist.web.userLocale";function P(){const e=a(k);return null!==e?e:navigator.language}let L=600,T=!1;const M="gist.web.userQueueNextPullCheck",N="gist.web.sessionId";function D(){let e=a(N);return e||(e=y()),s(N,e,new Date((new Date).getTime()+18e5)),String(e)}const q="gist.web.userToken",A="gist.web.usingGuestUserToken",R="gist.web.guestUserToken";function W(){return null!==a(A)}function O(){return a(q)}function U(){if(null===O()){let e=a(R);null==e&&(e=y(),s(R,e),i(`Set guest user token "${e}" with expiry date set to 1 year from today`)),s(q,e),s(A,!0),i(`Using anonymous session with token: "${e}"`)}}async function z(){const e=O();return null===e?null:await async function(e){const t=(new TextEncoder).encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,"0")).join("")}(e)}function B(){const e=O();return null===e?null:btoa(e)}function F(){r(q),i("Cleared user token")}async function H(e){try{return await C().post(`/api/v1/logs/queue/${e}`)}catch(e){return E(e)}}function j(e){try{return(document.getElementById(e)??document.querySelector(e))||null}catch{return null}}const _={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 G(e){const t=_,n=e?.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:n.tooltipArrowColor||t.tooltipArrowColor,shouldScale:!!n.scale,campaignId:n.campaignId??null,messageWidth:null!=n.messageWidth&&n.messageWidth>0?n.messageWidth:t.messageWidth,hasCustomWidth:(n.messageWidth??0)>0,overlayColor:n.overlayColor||t.overlayColor,persistent:!!n.persistent,exitClick:!!n.exitClick}:t}const V=["x-gist-top","x-gist-floating-top","x-gist-bottom","x-gist-floating-bottom","x-gist-floating-bottom-left","x-gist-floating-bottom-right","x-gist-floating-top-left","x-gist-floating-top-right"];function X(e){if(document.getElementById(e))return;const t=document.createElement("div");t.id=e,"x-gist-top"===e?document.body.insertBefore(t,document.body.firstChild):document.body.insertAdjacentElement("beforeend",t),i("Top & bottom elements injected into page")}const J=["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"];function Y(e){return en.currentMessages.find(t=>t.instanceId===e)}function Q(e){return!!e&&en.currentMessages.some(t=>t.queueId===e)}function K(e){return e?en.currentMessages.find(t=>t.elementId===e)??null:null}function Z(e){en.currentMessages=en.currentMessages.filter(t=>t.instanceId!==e)}function ee(e,t){Z(e),en.currentMessages.push(t)}function te(e){const t={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"};return e&&t[e]?t[e]:(i(`Invalid overlay position "${e}", defaulting to "topCenter"`),t.topCenter)}function ne(e){return e.tooltipPosition?"tooltip":e.overlay?"modal":e.elementId&&V.includes(e.elementId)?"overlay":e.elementId?"inline":"modal"}function ie(e,t){const n=ne(e),i=t.displayType;if(void 0===i)return!1;if(n!==i)return!0;const o=G(e);switch(i){case"modal":{if((e.position||"center")!==(t.modalPosition||"center"))return!0;const n=t.dismissOutsideClick??_.exitClick;if(o.exitClick!==n)return!0;const i=t.overlayColor??_.overlayColor;if(o.overlayColor!==i)return!0;break}case"overlay":{const n=te(t.overlayPosition);if(e.elementId!==n)return!0;break}case"inline":if(e.elementId!==t.elementSelector)return!0;break;case"tooltip":if(e.tooltipPosition!==t.tooltipPosition)return!0;if(e.elementId!==t.elementSelector)return!0;if(void 0!==t.tooltipArrowColor&&o.tooltipArrowColor!==t.tooltipArrowColor)return!0}if("overlay"!==i||!J.includes(te(t.overlayPosition))){const e=t.maxWidth??_.messageWidth;if(o.messageWidth!==e)return!0}return!1}function oe(e,t){if(e.properties||(e.properties={}),e.properties.gist||(e.properties.gist={}),"modal"===t.displayType)e.overlay=!0,e.elementId=null,e.properties.gist.elementId=null,e.position=t.modalPosition||"center",e.properties.gist.position=t.modalPosition||"center",e.tooltipPosition=void 0,e.properties.gist.tooltipPosition=void 0,e.properties.gist.tooltipArrowColor=void 0;else if("overlay"===t.displayType){e.overlay=!1;const n=te(t.overlayPosition);e.elementId=n,e.properties.gist.elementId=n,e.position=null,e.properties.gist.position=null,e.tooltipPosition=void 0,e.properties.gist.tooltipPosition=void 0,e.properties.gist.tooltipArrowColor=void 0}else"inline"===t.displayType?(e.overlay=!1,e.elementId=t.elementSelector,e.properties.gist.elementId=t.elementSelector,e.position=null,e.properties.gist.position=null,e.tooltipPosition=void 0,e.properties.gist.tooltipPosition=void 0,e.properties.gist.tooltipArrowColor=void 0):"tooltip"===t.displayType&&(e.overlay=!1,e.elementId=t.elementSelector,e.properties.gist.elementId=t.elementSelector,e.tooltipPosition=t.tooltipPosition,e.properties.gist.tooltipPosition=t.tooltipPosition,e.position=null,e.properties.gist.position=null,void 0!==t.tooltipArrowColor&&(e.properties.gist.tooltipArrowColor=t.tooltipArrowColor));e.elementId&&J.includes(e.elementId)?delete e.properties.gist.messageWidth:void 0!==t.maxWidth&&t.maxWidth>0?e.properties.gist.messageWidth=t.maxWidth:delete e.properties.gist.messageWidth,void 0!==t.overlayColor?e.properties.gist.overlayColor=t.overlayColor:delete e.properties.gist.overlayColor,void 0!==t.dismissOutsideClick?e.properties.gist.exitClick=t.dismissOutsideClick:delete e.properties.gist.exitClick}const se={top:["bottom","left","right"],bottom:["top","left","right"],left:["right","top","bottom"],right:["left","top","bottom"]},ae=/auto|scroll/,re={top:"gist-arrow-bottom",bottom:"gist-arrow-top",left:"gist-arrow-right",right:"gist-arrow-left"};function le(e){const t=j(e);return t||i(`Tooltip target element not found for selector: ${e}`),t}function ce(e,t){if(e.bottom<=0||e.top>=window.innerHeight||e.right<=0||e.left>=window.innerWidth)return!1;for(const n of t){const t=n.getBoundingClientRect();if(e.bottom<=t.top||e.top>=t.bottom||e.right<=t.left||e.left>=t.right)return!1}return!0}function de(e,t,n){const i=function(e,t,n){switch(n){case"top":return{top:t.top-e.height-16,left:t.left+(t.width-e.width)/2};case"bottom":return{top:t.bottom+16,left:t.left+(t.width-e.width)/2};case"left":return{top:t.top+(t.height-e.height)/2,left:t.left-e.width-16};case"right":return{top:t.top+(t.height-e.height)/2,left:t.right+16}}}(e,t,n);return function(e,t,n){return"top"===n||"bottom"===n?e.top>=0&&e.top+t.height<=window.innerHeight:e.left>=0&&e.left+t.width<=window.innerWidth}(i,e,n)&&function(e,t){return"top"===t||"bottom"===t?e.width+8<=window.innerWidth:e.height+8<=window.innerHeight}(e,n)?function(e,t,n){let{top:i,left:o}=e,s=null;if("top"===n||"bottom"===n){const e=4,n=window.innerWidth-t.width-4;n>=e&&(o<e?(s=o-e,o=e):o>n&&(s=o-n,o=n))}else{const e=4,n=window.innerHeight-t.height-4;n>=e&&(i<e?(s=i-e,i=e):i>n&&(s=i-n,i=n))}if(null!==s){const e=("top"===n||"bottom"===n?t.width/2:t.height/2)-16-4;Math.abs(s)>e&&(s=s>0?e:-e)}return{top:i,left:o,position:n,arrowOffset:s}}(i,e,n):null}function pe(e,t,n){const i=de(e,t,n);if(i)return i;for(const i of se[n]){const n=de(e,t,i);if(n)return n}return null}function ue(e){const t=[];let n=e.parentElement;for(;n;){const e=getComputedStyle(n),i=e.overflow+e.overflowX+e.overflowY;ae.test(i)&&t.push(n),n=n.parentElement}return t}function ge(e){const t=j(e);t&&(t.classList.remove("gist-visible"),Array.from(t.classList).filter(e=>e.startsWith("gist-")).forEach(e=>t.classList.remove(e)),t.style.removeProperty("height"),t.style.removeProperty("width"),t.innerHTML="")}function me(e){const t=j(e);if(t)return!(!t.style||!t.style.height||"0px"===t.style.height)}function fe(e,t,n=null){const i=document.getElementById(e);i&&(i.onload=()=>{!function(e,t,n=null){const i=document.getElementById(e);if(i?.contentWindow){const e={options:t,capabilities:he};n&&(t.stepId=n),i.contentWindow.postMessage(e,"*")}}(e,t,n)})}const he=["MultiStepDisplayTypes"];function we(e){if(!e.displaySettings)return;const t=Se(e.instanceId??""),n=document.getElementById(t);n?.contentWindow&&n.contentWindow.postMessage({action:"updateDisplaySettings",displaySettings:e.displaySettings},"*")}async function ye(){const e=document.querySelector(".gist-message");e&&(e.classList.remove("gist-visible"),await new Promise(e=>setTimeout(e,300))),be()}function be(){const e=document.querySelector("#gist-embed-message");e&&e.parentNode?.removeChild(e)}const ve=new Map;function xe(e){const t=e.instanceId??"",n=ve.get(t);n&&(n.cleanup(),ve.delete(t));const i=j(`gist-tooltip-${t}`);i&&i.parentNode?.removeChild(i)}function Se(e){return`gist-${e}`}function Ie(){const e=document.querySelector(".gist-message");e&&e.classList.add("gist-visible")}const $e="gist.web.customAttributes";let Ee=new Map;function Ce(){const e=Array.from(Ee.entries()),t=new Date;t.setDate(t.getDate()+30),s($e,e,t),i(`Saved ${Ee.size} custom attributes to storage with TTL of 30 days`)}async function ke(e){const t=await Me();if(!t)return;const n=new Date;n.setMinutes(n.getMinutes()+60),s(t,e.filter(Le),n)}async function Pe(e,t){const n=a(e);return n?.find(e=>e.queueId===t)}function Le(e){return!(!e.properties?.gist||!e.properties.gist.broadcast)}function Te(e){if(!Le(e))return!1;const t=e.properties.gist.broadcast;return 0===t.frequency.delay&&0===t.frequency.count}async function Me(){const e=await z();return e?`gist.web.message.broadcasts.${e}`:null}function Ne(e,t){return`${e}.${t}.numberOfTimesShown`}function De(e,t){return`${e}.${t}.shouldShow`}!function(){const e=a($e);if(e)try{Ee=new Map(e)}catch{Ee=new Map}else Ee=new Map}();const qe="gist.web.message.user";async function Ae(e){const t=await Re();if(!t)return;const n=e.filter(e=>!(e.properties&&e.properties.gist&&e.properties.gist.broadcast)),i=new Date;i.setMinutes(i.getMinutes()+60),s(t,n,i)}async function Re(){const e=await z();return e?`${qe}.${e}`:null}async function We(){const e=await z();return e?`${qe}.${e}.seen`:null}async function Oe(e){const t=await z();return t?`${qe}.${t}.message.${e}.loading`:null}async function Ue(e){const t=await z();return t?`${qe}.${t}.message.${e}.state`:null}async function ze(e){const t=await Ue(e);t&&(r(t),i(`Cleared message state for queueId: ${e}`))}function Be(e){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="${e}"/></svg>`}const Fe=`\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(Be("#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 {\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-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 He="cioPreviewId",je="cioPreviewSettings";const _e="gist.previewBar.collapsed",Ge="gist-pb-styles",Ve="gist-preview-bar",Xe={topLeft:"Top Left",topCenter:"Top Center",topRight:"Top Right",bottomLeft:"Bottom Left",bottomCenter:"Bottom Center",bottomRight:"Bottom Right"};let Je=null,Ye=[],Qe={},Ke=null,Ze=!1,et=!1,tt=5,nt=null,it=!1,ot=null,st=null,at=null;const rt=new Map;function lt(e,t={}){const n=document.createElement(e);for(const[e,i]of Object.entries(t))n[e]=i;return n}function ct(e,t){const n=lt("div",{className:"gist-pb-label-group"});return n.appendChild(lt("span",{className:"gist-pb-label",textContent:e})),n.appendChild(t),n}function dt(e,t){const n=lt("select",{className:"gist-pb-select"});for(const i of e){const e=lt("option",{value:i.value,textContent:i.label});i.value===t&&(e.selected=!0),n.appendChild(e)}return n}function pt(e,t,n){const i=lt("input",{className:"gist-pb-input",type:e,value:String(t)});return n&&(i.style.width=n),i}function ut(e,t){const n=Math.round(Math.min(100,Math.max(0,t))/100*255);return"#"+e.replace("#","").toUpperCase()+n.toString(16).padStart(2,"0").toUpperCase()}function gt(e){return!!("inline"!==e.displayType&&"tooltip"!==e.displayType||e.elementSelector?.trim())}function mt(e){if("overlay"===e.displayType&&J.includes(te(e.overlayPosition))){const{maxWidth:t,...n}=e;e=n}if(Qe=e,Ke){const t=Ye.findIndex(e=>e.stepName===Ke);-1!==t&&(Ye[t]={...Ye[t],displaySettings:{...e}})}if(!Je)return;const t=en.currentMessages.find(e=>e.instanceId===Je);t&&gt(e)&&(we(t),ie(t,e)&&Ut(t,Ke,e)),function(){const e=new URLSearchParams(window.location.search).get(He);e&&async function(e,t){try{return await C()(`/api/v1/preview/${e}`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}})}catch(e){return E(e)}}(e,Ye).then(e=>{e&&404===e.status&&Je&&en.dismissMessage(Je)}).catch(()=>i("Failed to persist preview display settings"))}()}function ft(e){const t=e.value.trim();t&&!j(t)?e.classList.add("gist-pb-input--invalid"):e.classList.remove("gist-pb-input--invalid")}function ht(e,t){const n=pt("text",e.elementSelector||"","260px");n.placeholder="Element ID or selector",ft(n),n.addEventListener("change",()=>{const e=n.value.trim(),t=Qe.elementSelector;e&&wt(e),mt({...Qe,elementSelector:e}),t&&t!==e&&yt(t),ft(n)});const i=lt("button",{type:"button",className:"gist-pb-select-elem-btn",textContent:"Select Element"});i.addEventListener("click",()=>bt(n));const o=lt("div",{className:"gist-pb-inline-row"});o.appendChild(n),o.appendChild(i),t.appendChild(ct("Element Selector",o))}function wt(e){if(!e||rt.has(e))return;const t=j(e);t&&rt.set(e,t.innerHTML)}function yt(e){const t=rt.get(e);if(void 0===t)return;const n=j(e);n&&(n.innerHTML=t)}function bt(e){if(it)return;it=!0;const t={...Qe},n=en.currentMessages.find(e=>e.instanceId===Je)??null;n&&Ot(n),Qe.elementSelector&&yt(Qe.elementSelector);const o=lt("div",{className:"gist-pb-picker-overlay"});let s=null;const a=e=>{o.style.pointerEvents="none";const t=document.elementFromPoint(e.clientX,e.clientY);o.style.pointerEvents="all",t&&t!==s&&t!==o&&(s?.classList.remove("gist-pb-pick-highlight"),s=t,s.classList.add("gist-pb-pick-highlight"))},r=e=>{if("Escape"===e.key){if(c(),Qe=t,Ke){const e=Ye.findIndex(e=>e.stepName===Ke);-1!==e&&(Ye[e]={...Ye[e],displaySettings:{...t}})}n&&gt(t)&&Ut(n,Ke,t),vt()}},l=t=>{t.preventDefault(),t.stopPropagation(),o.style.pointerEvents="none";const s=document.elementFromPoint(t.clientX,t.clientY);if(o.style.pointerEvents="all",s&&s!==o){s.classList.remove("gist-pb-pick-highlight");const t=document.getElementById(Ve),o=t?.contains(s)?null:function(e){if(e.id){const t=CSS.escape(e.id);if(1===document.querySelectorAll(`#${t}`).length)return e.id}const t=[];let n=e;for(;n&&"BODY"!==n.tagName&&"HTML"!==n.tagName;){if(n.id){const e=CSS.escape(n.id);if(1===document.querySelectorAll(`#${e}`).length){t.unshift(`#${e}`);break}}let e=n.tagName.toLowerCase();n.className&&"string"==typeof n.className&&(e+=n.className.trim().split(/\s+/).filter(Boolean).map(e=>`.${CSS.escape(e)}`).join(""));const i=n.parentElement;i&&(e+=`:nth-of-type(${Array.from(i.children).filter(e=>e.tagName===n.tagName).indexOf(n)+1})`),t.unshift(e);try{if(1===document.querySelectorAll(t.join(" > ")).length)break}catch{}n=n.parentElement}const o=t.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}(s);if(null===o)return s.classList.add("gist-pb-pick-error"),void setTimeout(()=>{s.classList.remove("gist-pb-pick-error"),s.classList.add("gist-pb-pick-highlight")},800);e.value=o,wt(o);const a=Qe.elementSelector,r={...Qe,elementSelector:o},l=null!=n&&gt(r)&&ie(n,r);mt(r),a&&a!==o&&yt(a),n&&!l&&Ut(n,Ke,r)}c()},c=()=>{s?.classList.remove("gist-pb-pick-highlight"),o.removeEventListener("mousemove",a),o.removeEventListener("click",l),document.removeEventListener("keydown",r),document.body.removeChild(o),it=!1,ot=null};ot=c,o.addEventListener("mousemove",a),o.addEventListener("click",l),document.addEventListener("keydown",r),document.body.appendChild(o)}function vt(){const e=document.getElementById(Ve);if(!e)return;if(e.classList.toggle("gist-pb-hidden",!Je&&!et),e.innerHTML="",!Je){if(et){const t=lt("div",{className:"gist-pb-controls-row gist-pb-ended-row"}),n=lt("span",{className:"gist-pb-ended-icon",textContent:"✓"}),i=lt("p",{className:"gist-pb-ended-text"});i.innerHTML=`<strong>Preview session ended.</strong> Close this tab and navigate back to the message editor. Refreshing in ${tt}s…`,t.appendChild(n),t.appendChild(i),e.appendChild(t)}return}const t=lt("div",{className:"gist-pb-toggle-row"+(Ze?" gist-pb-toggle-row--collapsed":"")}),n=lt("button",{type:"button",className:"gist-pb-toggle-btn"}),i=Ze?"transform:rotate(180deg);display:inline-flex;":"display:inline-flex;";if(n.innerHTML=`${Ze?"Expand":"Collapse"}<span style="${i}">${Be("white")}</span>`,n.addEventListener("click",xt),t.appendChild(n),e.appendChild(t),Ze)return;const o=lt("div",{className:"gist-pb-controls-row"});if(Ye.length>0){const e=Ke??Ye[0].stepName,t=dt(Ye.map(e=>({value:e.stepName,label:e.stepName})),e);t.addEventListener("change",()=>{const e=Ye.find(e=>e.stepName===t.value);if(e){Ke=e.stepName,Qe={...e.displaySettings};const t=en.currentMessages.find(e=>e.instanceId===Je);t&&gt(e.displaySettings)&&Ut(t,e.stepName,e.displaySettings),vt()}}),o.appendChild(ct("Step",t))}const s=dt([{value:"modal",label:"Modal"},{value:"overlay",label:"Overlay"},{value:"inline",label:"Inline"},{value:"tooltip",label:"Tooltip"}],Qe.displayType||"modal");s.addEventListener("change",()=>{const e=s.value,t=Qe.displayType,n=Qe.elementSelector,i={...Qe,displayType:e};"modal"===e?(i.modalPosition=i.modalPosition||"center",i.maxWidth=i.maxWidth??414,delete i.overlayPosition,delete i.elementSelector,delete i.tooltipPosition):"overlay"===e?(i.overlayPosition=i.overlayPosition||"topCenter",i.maxWidth=i.maxWidth??414,delete i.modalPosition,delete i.elementSelector,delete i.tooltipPosition):"inline"===e?(delete i.modalPosition,delete i.overlayPosition,delete i.tooltipPosition):"tooltip"===e&&(i.tooltipPosition=i.tooltipPosition||"top",delete i.modalPosition,delete i.overlayPosition,delete i.overlayColor,delete i.dismissOutsideClick),Qe=i,mt(Qe),"inline"!==t&&"tooltip"!==t||!n||"inline"===e||"tooltip"===e||yt(n),vt()}),o.appendChild(ct("Display Type",s));const a=Qe.displayType||"modal";"modal"===a?function(e,t){const n=dt([{value:"top",label:"Top"},{value:"center",label:"Center"},{value:"bottom",label:"Bottom"}],e.modalPosition||"center");n.addEventListener("change",()=>mt({...Qe,modalPosition:n.value})),t.appendChild(ct("Position",n));const i=pt("number",e.maxWidth??414,"80px");i.addEventListener("change",()=>mt({...Qe,maxWidth:parseInt(i.value)||414})),t.appendChild(ct("Max Width",i)),t.appendChild(function(e){const{color:t,opacity:n}=function(e){const t=e.replace("#","");return 8===t.length?{color:"#"+t.slice(0,6).toUpperCase(),opacity:Math.round(parseInt(t.slice(6),16)/255*100)}:6===t.length?{color:"#"+t.toUpperCase(),opacity:100}:{color:"#000000",opacity:20}}(e.overlayColor||"#00000033"),i=lt("div",{className:"gist-pb-color-control"}),o=lt("input",{className:"gist-pb-color-input",type:"color",value:t}),s=lt("div",{className:"gist-pb-color-swatch"});s.style.background=t,s.appendChild(o),s.addEventListener("click",()=>o.click());const a=lt("input",{className:"gist-pb-color-hex",type:"text",maxLength:6,value:t.replace("#","")}),r=lt("input",{className:"gist-pb-color-opacity",type:"number",min:"0",max:"100",value:String(n)}),l=lt("span",{className:"gist-pb-color-pct",textContent:"%"}),c=()=>{const e="#"+a.value.replace("#",""),t=parseInt(r.value)||0;s.style.background=e,o.value=e,mt({...Qe,overlayColor:ut(e,t)})};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),ct("Overlay Color",i)}(e));const o=lt("div",{className:"gist-pb-checkbox-row"}),s=lt("input",{className:"gist-pb-checkbox",type:"checkbox"});s.checked=e.dismissOutsideClick??!1;const a=lt("label",{className:"gist-pb-checkbox-label",textContent:"Dismiss on click outside"});s.addEventListener("change",()=>mt({...Qe,dismissOutsideClick:s.checked})),a.addEventListener("click",()=>{s.checked=!s.checked,mt({...Qe,dismissOutsideClick:s.checked})}),o.appendChild(s),o.appendChild(a);const r=ct(" ",o);r.classList.add("gist-pb-label-group--grow"),r.firstChild.classList.add("gist-pb-label--spacer"),t.appendChild(r)}(Qe,o):"overlay"===a?function(e,t){const n=dt(Object.entries(Xe).map(([e,t])=>({value:e,label:t})),e.overlayPosition||"topCenter");if(n.addEventListener("change",()=>mt({...Qe,overlayPosition:n.value})),t.appendChild(ct("Position",n)),!J.includes(te(e.overlayPosition))){const n=pt("number",e.maxWidth??414,"80px");n.addEventListener("change",()=>mt({...Qe,maxWidth:parseInt(n.value)||414})),t.appendChild(ct("Max Width",n))}}(Qe,o):"inline"===a?function(e,t){ht(e,t)}(Qe,o):"tooltip"===a&&function(e,t){const n=dt([{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"left",label:"Left"},{value:"right",label:"Right"}],e.tooltipPosition||"top");n.addEventListener("change",()=>mt({...Qe,tooltipPosition:n.value})),t.appendChild(ct("Position",n)),ht(e,t)}(Qe,o),o.appendChild(lt("div",{className:"gist-pb-spacer"}));const r=lt("button",{type:"button",className:"gist-pb-save-btn",textContent:"End session"});r.addEventListener("click",async()=>{Je&&await en.dismissMessage(Je)}),o.appendChild(r),e.appendChild(o)}function xt(){Ze=!Ze;try{sessionStorage.setItem(_e,String(Ze))}catch{}vt()}function St(e){if(et)return;Je=e.instanceId??null;const t=e.displaySettings;if(Array.isArray(t)&&t.length>0?(Ye=t,Ke||(Ke=Ye[0].stepName,Qe={...Ye[0].displaySettings})):t&&"object"==typeof t&&!Array.isArray(t)&&(Qe={...t}),st||at){const e=!!st,t=!!at,n=st,o=at;if(st=null,at=null,e){const e=Ye.find(e=>e.stepName===n);if(!e)return i(`Preview bar: step "${n}" not found, ignoring initial step/display override`),void vt();Ke=e.stepName,Qe={...e.displaySettings}}if(t){if(!e)return i(`Preview bar: display type "${o}" provided without a step, ignoring`),void vt();Qe={...Qe,displayType:o}}vt();const s=en.currentMessages.find(e=>e.instanceId===Je);return void(s&&gt(Qe)?Ut(s,Ke,Qe):function(){const e=Qe.displayType;if("inline"!==e&&"tooltip"!==e)return;const t=document.querySelector("#gist-preview-bar .gist-pb-input[type='text']");t&&bt(t)}())}vt()}function It(){(function(){for(const e of rt.keys())yt(e);rt.clear()})(),Je=null,Ye=[],Qe={},Ke=null,et=!0,tt=5;const e=new URLSearchParams(window.location.search).get(He);e&&async function(e){try{return await C()(`/api/v1/preview/${e}`,{method:"DELETE"})}catch(e){return E(e)}}(e).catch(()=>i("Failed to delete preview session")),vt(),nt&&clearInterval(nt),nt=setInterval(()=>{tt-=1,tt<=0?(clearInterval(nt),nt=null,F(),function(){try{sessionStorage.removeItem(o)}catch{}}(),window.location.reload()):vt()},1e3)}async function $t(e){if(!en.isDocumentVisible)return i("Document hidden, not showing message now."),null;if(Q(e.queueId))return i(`Message with queueId ${e.queueId} is already showing.`),null;const t=G(e);return!e.tooltipPosition&&t.hasTooltipPosition&&(e.tooltipPosition=t.tooltipPosition),e.tooltipPosition?function(e,t){const n=t.elementId||e.elementId;if(!n)return i(`No target selector specified for tooltip message ${e.messageId}`),en.messageError(e),null;if(!j(n)){if(!en.config.isPreviewSession||!e.properties?.gist?.livePreview)return i(`Tooltip target element "${n}" not found for message ${e.messageId}, skipping display`),en.messageError(e),null;i(`Preview: tooltip target "${n}" not found, loading message for preview bar`)}const o=en.currentMessages.find(e=>e.tooltipPosition&&e.elementId===n);o&&(i(`Tooltip already showing on target "${n}" (instance ${o.instanceId}), dismissing it first`),en.messageDismissed(o),xe(o),o.instanceId&&Z(o.instanceId)),e.instanceId=y(),e.overlay=!1,e.firstLoad=!0,e.shouldResizeHeight=!1,e.shouldScale=!1,e.renderStartTime=(new Date).getTime(),e.elementId=n,en.currentMessages.push(e);return Dt(e,null,e.savedStepName||null)}(e,t):en.overlayInstanceId?(i(`Message ${en.overlayInstanceId} already showing.`),null):(e.instanceId=y(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),en.overlayInstanceId=e.instanceId,en.currentMessages.push(e),Dt(e,null,e.savedStepName||null))}function Et(e,t){return en.isDocumentVisible?Q(e.queueId)?(i(`Message with queueId ${e.queueId} is already showing.`),null):K(t)?(i(`Message with elementId ${t} already has a message.`),null):(e.instanceId=y(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!me(t),e.renderStartTime=(new Date).getTime(),en.currentMessages.push(e),Dt(e,t,e.savedStepName||null)):(i("Document hidden, not showing message now."),null)}async function Ct(e){e?(en.messageDismissed(e),await kt(e)):i("Message not found")}async function kt(e){"tooltip"===ne(e)?Tt(e):e.overlay?await Mt(!0,e):Lt(e)}async function Pt(e){e?G(e).persistent&&(i("Persistent message dismissed, logging view"),await zt(e),await qt(e),await ze(e.queueId??"")):i("Message not found")}function Lt(e){e.instanceId&&Z(e.instanceId),e.elementId&&ge(e.elementId),en.config.isPreviewSession&&(It(),Nt())}function Tt(e){xe(e),e.instanceId&&Z(e.instanceId),0===en.currentMessages.length&&(window.removeEventListener("message",Rt),window.removeEventListener("touchstart",At)),en.config.isPreviewSession&&(It(),Nt())}async function Mt(e,t){e?await ye():be(),0===en.currentMessages.length&&(window.removeEventListener("message",Rt),window.removeEventListener("touchstart",At)),t.instanceId&&Z(t.instanceId),en.overlayInstanceId=null,en.config.isPreviewSession&&(It(),Nt())}function Nt(){const e=new URL(window.location.href);e.searchParams.delete(He),e.searchParams.delete(je),history.replaceState(null,"",e.toString())}function Dt(e,t=null,n=null){const o=en.config.env,s={endpoint:I.ENGINE_API_ENDPOINT[o],siteId:en.config.siteId,dataCenter:en.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId??"",livePreview:!1,properties:e.properties,customAttributes:Object.fromEntries(new Map(Ee))},a=`${I.GIST_VIEW_ENDPOINT[o]}/index.html`;return window.addEventListener("message",Rt),window.addEventListener("touchstart",At),"tooltip"===ne(e)?function(e,t,n,i=null){const o=t.instanceId??"",s=Se(o),a=G(t),r=ve.get(o);r&&(r.cleanup(),ve.delete(o)),document.querySelectorAll(`#gist-tooltip-${o}`).forEach(e=>{e.parentNode?.removeChild(e)});const l=`gist-tooltip-${o}`,c=document.createElement("div");c.id=l,c.innerHTML=function(e,t,n,i=""){let o=600;t.messageWidth>o&&(o=t.messageWidth);const s=t.tooltipArrowColor,a=function(e){switch(e){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"}}(t.tooltipPosition),r=i?`#${i} `:"";return`\n <div class="gist-tooltip-outer">\n <style>\n ${r}.gist-tooltip-outer {\n position: absolute;\n }\n ${r}.gist-tooltip-container {\n position: relative;\n z-index: 9999999;\n opacity: 0;\n transition: opacity 0.3s ease-in-out;\n }\n ${r}.gist-tooltip-container.gist-visible {\n opacity: 1;\n }\n ${r}.gist-tooltip-frame-clip {\n overflow: hidden;\n }\n ${r}.gist-tooltip-frame {\n display: block;\n width: ${t.messageWidth}px;\n border: none;\n transition: height 0.1s ease-in-out;\n }\n ${r}.gist-tooltip-arrow {\n width: 0;\n height: 0;\n position: absolute;\n z-index: 1;\n }\n ${r}.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 ${s};\n }\n ${r}.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 ${s};\n }\n ${r}.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 ${s};\n }\n ${r}.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 ${s};\n }\n @media (max-width: ${o}px) {\n ${r}.gist-tooltip-frame {\n max-width: 100%;\n }\n }\n </style>\n <div class="gist-tooltip-container">\n <div class="gist-tooltip-arrow ${a}"></div>\n <div class="gist-tooltip-frame-clip">\n <iframe id="${e}" class="gist-tooltip-frame" src="${n}"></iframe>\n </div>\n </div>\n </div>`}(s,a,e,l),document.body.appendChild(c),fe(s,n,i)}(a,e,s,n):t?(V.includes(t)&&X(t),function(e,t,n,o,s=null){const a=j(e);if(a){const i=Se(n.instanceId??"");a.classList.add(i);const r=G(n);let l=r.messageWidth+"px";J.includes(e)&&!r.hasCustomWidth&&(l="100%"),V.includes(e)&&(a.style.width=l),me(e)||(a.style.height="0px"),a.innerHTML=function(e,t,n){return function(e,t,n){let i=800;return t.messageWidth>i&&(i=t.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 }\n #x-gist-top.${e},\n #x-gist-bottom.${e},\n #x-gist-floating-top.${e},\n #x-gist-floating-bottom.${e},\n #x-gist-floating-top-left.${e},\n #x-gist-floating-top-right.${e},\n #x-gist-floating-bottom-left.${e},\n #x-gist-floating-bottom-right.${e} {\n transition: height 0.1s ease-in-out;\n }\n @media (max-width: ${i}px) {\n #x-gist-top.${e},\n #x-gist-bottom.${e},\n #x-gist-floating-top.${e},\n #x-gist-floating-bottom.${e},\n #x-gist-floating-top-left.${e},\n #x-gist-floating-top-right.${e},\n #x-gist-floating-bottom-left.${e},\n #x-gist-floating-bottom-right.${e} {\n width: 100% !important;\n }\n }\n </style>\n <div id="gist-embed-container">\n <iframe id="${e}" class="gist-frame" src="${n}"></iframe>\n </div>\n </div>`}(Se(t.instanceId??""),n,e)}(t,n,r),fe(i,o,s)}else i(`Message could not be embedded, elementId ${e} not found.`)}(t,a,e,s,n)):function(e,t,n,i=null){document.querySelectorAll("#gist-embed-message").forEach(e=>{e.parentNode?.removeChild(e)}),document.body.insertAdjacentHTML("afterbegin",function(e,t){const n=G(t);return function(e,t,n){let i=600;return t.messageWidth>i&&(i=t.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: ${t.overlayColor};\n visibility: hidden;\n }\n #gist-overlay.gist-background.gist-visible {\n visibility: visible;\n }\n .gist-message {\n width: ${t.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 }\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: ${i}px) {\n .gist-message {\n width: 100%;\n }\n }\n </style>\n <div id="gist-overlay" class="gist-background">\n <iframe id="${e}" class="gist-message" src="${n}"></iframe>\n </div>\n </div>`}(Se(t.instanceId??""),n,e)}(e,t)),fe(Se(t.instanceId??""),n,i)}(a,e,s,n),e}async function qt(e){let t;i(`Message shown, logging view for: ${e.messageId}`),null!=e.queueId?(await zt(e),t=await H(e.queueId)):t=await async function(e){try{return await C().post(`/api/v1/logs/message/${e}`)}catch(e){return E(e)}}(e.messageId),i(200===t?.status?"Message view logged":`Problem logging message: ${t?.status}`)}function At(){}async function Rt(e){const t=e.data;if(t.gist&&e.origin===I.RENDERER_HOST){const e=t.gist.instanceId,n=Y(e);if(!n)return;const o=G(n);switch(t.gist.method){case"routeLoaded":{const s=.001*((new Date).getTime()-(n.renderStartTime??0));if(i(`Engine render for message: ${n.messageId} timer elapsed in ${s.toFixed(3)} seconds`),async function(e){const t=await Oe(e);t&&r(t)}(n.queueId??""),n.currentRoute=t.gist.parameters.route,t.gist.parameters.fullDisplaySettings&&!n.displaySettings?n.displaySettings=t.gist.parameters.fullDisplaySettings:n.displaySettings&&(i("SDK already has display settings state, sending it to iframe"),we(n)),en.config.isPreviewSession&&n.properties?.gist?.livePreview&&St(n),n.firstLoad||n.isDisplayChange){if("tooltip"===ne(n)){const e=n.properties?.gist?.elementId||n.elementId||void 0;if(!e||!j(e)){if(en.config.isPreviewSession&&n.properties?.gist?.livePreview){i(`Preview: tooltip target "${e}" not found, preview bar will show element picker`),n.firstLoad=!1,n.isDisplayChange=!1;break}i(`Tooltip target not found for "${e}", emitting error and skipping display`),en.messageError(n),n.firstLoad=!1,n.isDisplayChange=!1,Tt(n);break}const t=await async function(e){const t=e.instanceId??"",n=G(e),o=`gist-tooltip-${t}`,s=j(o);if(!s)return i(`Tooltip wrapper not found for instance ${t}`),!1;const a=e.properties?.gist?.elementId||e.elementId||void 0;if(!a)return i(`No target selector for tooltip ${t}`),!1;const r=ve.get(t);r&&(r.cleanup(),ve.delete(t));const l=s.querySelector(".gist-tooltip-outer");if(!l)return i(`Tooltip inner element not found for instance ${t}`),!1;const c=n.tooltipPosition||"bottom";if(!await async function(e,t,n){const o=le(t);if(!o)return!1;let s=[];try{s=ue(o)}catch{}if(ce(o.getBoundingClientRect(),s))return!0;if(!function(e,t,n){const i=le(t);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 e.style.display="",null!==pe(e.getBoundingClientRect(),r,n)}(e,t,n))return i(`Preflight failed: tooltip would not fit after scrolling target "${t}" into view`),!1;o.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),await function(e){return new Promise(t=>{let n=e.getBoundingClientRect(),i=0;const o=Date.now();setTimeout(function s(){const a=e.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?t():setTimeout(s,50)},50)})}(o);const a=o.getBoundingClientRect();let r=[];try{r=ue(o)}catch{}return ce(a,r)}(l,a,c))return i(`Tooltip for instance ${t} skipped: target "${a}" is off-screen and cannot be scrolled into a valid position`),!1;const d=function(e,t,n,o){const s=le(t);if(!s)return null;let a=null,r=null,l=!1,c=[],d=null;try{c=ue(s)}catch{}function p(){if(l)return;if(!s||!document.contains(s)||!document.contains(e))return i("Tooltip or target element removed from DOM, cleaning up listeners"),g(),void o?.onDetach?.();const t=s.getBoundingClientRect();if(!ce(t,c))return void(e.style.display="none");e.style.display="";const a=pe(e.getBoundingClientRect(),t,n);a?(function(e,t){e.style.position="absolute",e.style.top=`${t.top+window.scrollY}px`,e.style.left=`${t.left+window.scrollX}px`}(e,a),function(e,t){const n=e.querySelector(".gist-tooltip-arrow");n&&(n.classList.remove("gist-arrow-top","gist-arrow-bottom","gist-arrow-left","gist-arrow-right"),n.classList.add(re[t.position]),null!==t.arrowOffset?"top"===t.position||"bottom"===t.position?(n.style.left=`calc(50% + ${t.arrowOffset}px)`,n.style.removeProperty("top")):(n.style.top=`calc(50% + ${t.arrowOffset}px)`,n.style.removeProperty("left")):"top"===t.position||"bottom"===t.position?(n.style.left="50%",n.style.removeProperty("top")):(n.style.top="50%",n.style.removeProperty("left")))}(e,a)):e.style.display="none"}function u(){null===a&&(a=requestAnimationFrame(()=>{a=null,p()}))}function g(){if(!l){l=!0,d&&(d.disconnect(),d=null),window.removeEventListener("scroll",u),window.removeEventListener("resize",u);for(const e of c)e.removeEventListener("scroll",u);null!==a&&(cancelAnimationFrame(a),a=null),null!==r&&(cancelAnimationFrame(r),r=null)}}if(p(),l)return null;window.addEventListener("scroll",u,{passive:!0}),window.addEventListener("resize",u,{passive:!0});for(const e of c)e.addEventListener("scroll",u,{passive:!0});try{d=new MutationObserver(()=>{null===r&&(r=requestAnimationFrame(()=>{r=null,document.contains(s)||p()}))}),d.observe(document.body,{childList:!0,subtree:!0})}catch{}return{cleanup:g,reposition:p}}(l,a,c,{onDetach:()=>{ve.delete(t);const e=j(o);e&&e.parentNode?.removeChild(e)}});if(d){if("none"!==l.style.display){const e=s.querySelector(".gist-tooltip-container");return e?(ve.set(t,d),e.classList.add("gist-visible"),!0):(d.cleanup(),i(`Tooltip container not found for instance ${t}`),!1)}return d.cleanup(),i(`Tooltip for instance ${t} could not be positioned within the viewport, target "${a}" may be off-screen`),!1}return i(`Failed to position tooltip for instance ${t}, target "${a}" may not exist or no position fits the viewport`),!1}(n);if(!t){if(en.config.isPreviewSession&&n.properties?.gist?.livePreview){i(`Preview: tooltip positioning failed for "${e}", preview bar will remain active`),n.firstLoad=!1,n.isDisplayChange=!1;break}i(`Tooltip positioning failed for "${e}", emitting error and cleaning up`),en.messageError(n),n.firstLoad=!1,n.isDisplayChange=!1,Tt(n);break}}else n.overlay?function(e){const t=G(e),n=document.querySelector("#gist-overlay");if(n){n.classList.add("gist-visible");const i=document.querySelector(".gist-message");i&&(e.position?i.classList.add("gist-"+e.position):i.classList.add("gist-center")),setTimeout(Ie,100),t.exitClick&&setTimeout(()=>function(e){const t=document.querySelector("#gist-overlay");t&&t.addEventListener("click",()=>{en.dismissMessage(e)})}(e.instanceId??""),1e3)}else be()}(n):function(e){const t=j(e);t&&t.classList.add("gist-visible")}(n.elementId);n.firstLoad&&!n.isDisplayChange&&(en.messageShown(n),o.persistent?i("Persistent message shown, skipping logging view"):await qt(n)),n.firstLoad=!1,n.isDisplayChange=!1}ee(e,n);break}case"tap":{const e=t.gist.parameters.action,i=t.gist.parameters.name;if(en.messageAction(n,e,i),t.gist.parameters.system&&!o.persistent){await Ct(n);break}try{const t=new URL(e);if(t&&"gist:"===t.protocol)switch(t.href.replace("gist://","").split("?")[0]){case"close":await Pt(n),await Bt(n),await Ct(n),await Yt();break;case"showMessage":{const e=t.searchParams.get("messageId"),n=t.searchParams.get("properties");if(e){const t=n?JSON.parse(atob(n)):void 0;await en.showMessage({messageId:e,properties:t})}break}case"loadPage":{const e=t.href.substring(t.href.indexOf("?url=")+5);e&&(e.startsWith("mailto:")||e.startsWith("https://")||e.startsWith("http://")||e.startsWith("/")?window.location.href=e:window.location.href=window.location+e);break}}}catch{}break}case"changeMessageStep":{const e=t.gist.parameters.displaySettings,r=t.gist.parameters.messageStepName;en.config.isPreviewSession&&r&&n.properties?.gist?.livePreview&&function(e,t){if(et)return;Ke=e;const n=Ye.find(t=>t.stepName===e);n?Qe={...n.displaySettings}:t&&(Qe={...t}),vt()}(r,e),(o.persistent||Te(n))&&await async function(e,t,n){const o=await Ue(e);if(!o)return;const r=a(o)||{},l={stepName:void 0!==t?t: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: ${e}`)}(n.queueId??"",r,e),e&&ie(n,e)&&(i("Display settings changed, reloading message"),await Ot(n),oe(n,e),await Wt(n,r??null));break}case"routeChanged":n.currentRoute=t.gist.parameters.route,n.renderStartTime=(new Date).getTime(),ee(e,n),i(`Route changed to: ${n.currentRoute}`);break;case"sizeChanged":i(`Size Changed Width: ${t.gist.parameters.width} - Height: ${t.gist.parameters.height}`),"tooltip"===ne(n)?function(e,t){const n=e.instanceId??"",i=Se(n),o=document.getElementById(i);if(o&&t.height>0){o.style.height=`${t.height}px`;const e=ve.get(n);e&&e.reposition()}}(n,t.gist.parameters):n.elementId&&!n.shouldResizeHeight||function(e,t){const n=j(e.elementId?e.elementId:Se(e.instanceId??""));if(n){const i=n.style;if(t.height>0)if(t.height>window.innerHeight){const n=1-(t.height/window.innerHeight-1);e.shouldScale&&n>=.4?(i.height=`${t.height}px`,i.transform=`translateX(-50%) translateY(-50%) scale(${n})`):i.height=`${window.innerHeight}px`}else i.height=`${t.height}px`}}(n,t.gist.parameters);break;case"titleChanged":i(`Overlay title changed to: ${t.gist.parameters.title}`),function(e,t){const n=j(Se(e));n&&(n.title=t)}(e,t.gist.parameters.title);break;case"eventDispatched":en.events.dispatch("eventDispatched",{name:t.gist.parameters.name,payload:t.gist.parameters.payload});break;case"error":case"routeError":en.messageError(n),"tooltip"===ne(n)?Tt(n):en.overlayInstanceId?await Mt(!1,n):Lt(n)}}}async function Wt(e,t){e.isDisplayChange=!0,e.renderStartTime=(new Date).getTime();const n=ne(e),o=e.elementId||null;if("tooltip"===n)return en.overlayInstanceId===e.instanceId&&(en.overlayInstanceId=null),e.shouldScale=!1,e.shouldResizeHeight=!1,void Dt(e,null,t);if(o){const t=K(o);t&&t.instanceId!==e.instanceId&&(i(`Dismissing existing message at ${o} to make room for multi-step message`),await Ct(t))}if(e.overlay){en.overlayInstanceId=e.instanceId??null;const t=G(e);e.shouldScale=t.shouldScale,e.shouldResizeHeight=!0}else en.overlayInstanceId=null,e.shouldScale=!1,e.shouldResizeHeight=!me(o??"");o&&V.includes(o)&&X(o),Dt(e,o,t)}async function Ot(e){"tooltip"===ne(e)?xe(e):e.overlay?await ye():e.elementId&&ge(e.elementId)}async function Ut(e,t,n){n&&ie(e,n)&&(await Ot(e),oe(e,n)),await Wt(e,t??null)}async function zt(e){i(`Logging user message view locally for: ${e.queueId}`),Le(e)?await async function(e){i(`Marking broadcast ${e} as seen.`);const t=await Me();if(!t)return;const n=await Pe(t,e);if(!n)return;const o=n.properties.gist.broadcast,{frequency:r}=o,l=Ne(t,e),c=De(t,e),d=a(l)||0;if(s(l,d+1),1===r.count)s(c,!1),i(`Marked broadcast ${e} as seen.`);else{const t=new Date;t.setSeconds(t.getSeconds()+r.delay),s(c,!1,t),i(`Marked broadcast ${e} as seen, broadcast was seen ${d+1} times, next show date is ${t}.`)}}(e.queueId??""):await async function(e){const t=await We();if(!t)return;const n=a(t)??[];n.push(e),s(t,n)}(e.queueId??"")}async function Bt(e){Le(e)&&(i(`Logging broadcast dismissed locally for: ${e.queueId}`),await async function(e){i(`Marking broadcast ${e} as dismissed.`);const t=await Me();if(!t)return;const n=await Pe(t,e);n&&(!0!==n.properties.gist.broadcast.frequency.ignoreDismiss?(s(De(t,e),!1),i(`Marked broadcast ${e} as dismissed and will not show again.`)):i(`Broadcast ${e} is set to ignore dismiss.`))}(e.queueId??""),await ze(e.queueId??""))}const Ft="messageInboxUpdated";async function Ht(e){const t=await _t();if(!t)return;const n=new Date;n.setMinutes(n.getMinutes()+60),s(t,e,n),en.events.dispatch(Ft,e)}async function jt(){const e=await _t();if(!e)return[];const t=a(e)??[],n=new Date;return t.filter(e=>!e.expiry||new Date(e.expiry)>n)}async function _t(){const e=await z();return e?`gist.web.inbox.messages.${e}`:null}const Gt=(e,t)=>e().then((e=>new Promise(t=>setTimeout(t,e)))(t).then(()=>Gt(e,t)));let Vt=!1,Xt=null;async function Jt(){Vt?await Yt():O()?(i("Queue watcher started"),Vt=!0,Gt(()=>new Promise(()=>{!async function(){if(I.hasActiveSSEConnection())return!I.isSSEConnectionManagedBySDK()&&Xt&&(i("Not the main instance, closing our SSE connection."),Zt()),void await Yt();Xt&&(i("SSE connection not active, closing it."),Zt()),!I.useSSE()||W()?await Kt():await async function(){Zt();const e=function(){const e=B();return null===e?(i("No user token available for SSE endpoint."),null):I.GIST_QUEUE_REALTIME_API_ENDPOINT[en.config.env??"prod"]+`/api/v3/sse?userToken=${e}&siteId=${en.config.siteId}&sessionId=${D()}`}();if(null===e)return i("SSE endpoint not available, falling back to polling."),void await Kt();i(`Starting SSE queue listener on ${e}`),Xt=new EventSource(e),I.setActiveSSEConnection(),Xt.addEventListener("connected",async e=>{try{i("SSE connection received"),I.setUseSSEFlag(!0);const t=JSON.parse(e.data);t.heartbeat&&(I.setSSEHeartbeat(t.heartbeat),i(`SSE heartbeat set to ${t.heartbeat} seconds`)),I.setActiveSSEConnection()}catch(e){i(`Failed to parse SSE settings: ${e}`)}r(M),await Kt()}),Xt.addEventListener("messages",async e=>{try{const t=JSON.parse(e.data);i("SSE message received"),await Ae(t),await ke(t),await Yt()}catch(e){i(`Failed to parse SSE message: ${e}`),Zt()}}),Xt.addEventListener("inbox_messages",async e=>{try{const t=JSON.parse(e.data);i("SSE inbox messages received"),await Ht(t)}catch(e){i(`Failed to parse SSE inbox messages: ${e}`)}}),Xt.addEventListener("error",async()=>{i("SSE error received"),Zt()}),Xt.addEventListener("heartbeat",async()=>{i("SSE heartbeat received"),I.setActiveSSEConnection(),I.setUseSSEFlag(!0)})}()}()}),1e3)):i("User token not setup, queue not started.")}async function Yt(){const e=await async function(){const e=await Me();return e?(a(e)??[]).filter(t=>{const n=t.properties.gist.broadcast,{frequency:i}=n,o=a(De(e,t.queueId))??!0,s=a(Ne(e,t.queueId))||0,r=0===i.count;return o&&(r||s<i.count)}):[]}(),t=await async function(){const e=await Re();if(!e)return[];const t=a(e)??[],n=await async function(){const e=await We();return e?a(e)??[]:[]}();return t.filter(e=>!n.includes(e.queueId??""))}(),n=e.concat(t);i(`Messages in local queue: ${n.length}`);const o=n.sort((e,t)=>e.priority-t.priority);for(const e of o)await Qt(e)}async function Qt(e){let t=G(e);if(t.hasRouteRule){let e=en.currentRoute;null==e&&(e=new URL(window.location.href).pathname);const n=t.routeRule;if(i(`Verifying route ${e} against rule: ${n}`),!new RegExp(n).test(e))return i(`Route ${e} does not match rule.`),!1}if(t.hasPosition&&(e.position=t.position),t.hasTooltipPosition&&(e.tooltipPosition=t.tooltipPosition),t.persistent||Te(e)){const n=await async function(e){const t=await Ue(e);return t?a(t):null}(e.queueId??"");n&&(i(`Restoring saved state for queueId ${e.queueId}`),n.displaySettings&&(oe(e,n.displaySettings),t=G(e)),e.savedStepName=n.stepName??null)}if(t.persistent||Te(e)||!await async function(e){const t=await Oe(e);return!!t&&null!==a(t)}(e.queueId??"")){let n=null;return t.isEmbedded?en.config.isPreviewSession&&e.properties?.gist?.livePreview&&!j(t.elementId)?(i(`Preview: element "${t.elementId}" not found, showing as overlay so placement can be changed`),n=await $t(e)):n=Et(e,t.elementId):n=await $t(e),n&&async function(e){const t=await Oe(e);t&&s(t,!0,new Date(Date.now()+5e3))}(e.queueId??""),null!==n}return i(`Not showing message with queueId ${e.queueId} because its already loading.`),!1}async function Kt(){if(O())if(en.isDocumentVisible)if(null===a(M)){const e=await async function(){const e=O();let t;try{if(!T){T=!0;const e={"X-Gist-User-Anonymous":String(W()),"Content-Language":String(P())};t=await C().post(`/api/v4/users?sessionId=${D()}`,{},{headers:e})}}catch(e){const n=E(e);n?t=n:i(`Error getting user queue: ${e}`)}finally{T=!1}return e!==O()?(i("User token changed, clearing queue next pull check."),void r(M)):(function(e){if(e?.headers){const t=e.headers["x-gist-queue-polling-interval"];t&&Number(t)>0&&(L=Number(t))}const t=new Date((new Date).getTime()+1e3*L);s(M,L,t)}(t),function(e){const t="true"===e?.headers?.["x-cio-use-sse"]?.toLowerCase();I.setUseSSEFlag(t)}(t),t)}();if(e){if(200===e.status||204===e.status){i("200 response, updating local store.");const t=e.data,n=t?.inAppMessages??[],o=t?.inboxMessages??[];Ae(n),ke(n),Ht(o)}else 304===e.status&&i("304 response, using local store.");await Yt()}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 Zt(e=!1){e&&I.removeActiveSSEConnection(),(e||I.isSSEConnectionManagedBySDK())&&I.setUseSSEFlag(!1),Xt&&(i("Stopping SSE queue listener..."),Xt.close(),Xt=null)}class en{static async setup(e){this.initialized?i("Gist SDK already initialized, skipping setup."):(this.initialized=!0,this.events=new n,this.config={useAnonymousSession:e.useAnonymousSession??!1,siteId:e.siteId,dataCenter:e.dataCenter,env:e.env??"prod",logging:e.logging??!1,experiments:e.experiments??!1},this.currentMessages=[],ve.forEach(e=>e.cleanup()),ve.clear(),document.querySelectorAll('[id^="gist-tooltip-"]').forEach(e=>{e.parentNode?.removeChild(e)}),this.overlayInstanceId=null,this.currentRoute=null,this.isDocumentVisible=!0,this.config.isPreviewSession=function(){const e=new URLSearchParams(window.location.search),t=e.get(He);if(t){sessionStorage.setItem(o,String(!1)),en.setUserToken(t),i(`Preview mode enabled with user token: ${t}`),function(){if(document.getElementById(Ve))return;!function(){if(document.getElementById(Ge))return;const e=document.createElement("style");e.id=Ge,e.textContent=Fe,document.head.appendChild(e)}();try{Ze="true"===sessionStorage.getItem(_e)}catch{Ze=!1}const e=lt("div",{id:Ve});document.body.appendChild(e),vt()}();const n=e.get(je);if(n)try{const e=JSON.parse(atob(n)),t=e.stepName||null,i=e.displayType||null;(t||i)&&function(e,t){st=e,at=t}(t,i)}catch{i("Preview bar: failed to parse cioPreviewSettings")}}return!l()}(),function(){const e=c();for(let t=e.length-1;t>=0;t--)d(e.key(t))}(),i(`Setup complete on ${this.config.env} environment.`),this.config.isPreviewSession||!this.config.useAnonymousSession||new URLSearchParams(location.search).has("ajs_uid")||U(),await Jt(),document.addEventListener("visibilitychange",async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await Yt())},!1))}static async setCurrentRoute(e){this.currentRoute=e,i(`Current route set to: ${e}`),await async function(){if(0!==en.currentMessages.length)for(const e of[...en.currentMessages])null==document.querySelector(`#gist-${e.instanceId}`)&&(i(`Removing active message ${e.instanceId} that no longer exists after route change`),await kt(e))}(),await Yt()}static async setUserToken(e,t){this.config.isPreviewSession||(function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),s(q,e,t),W()&&(r(M),r(A)),i(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),Zt(!0),await Jt())}static setUserLocale(e){var t;s(k,t=e),i(`Set user locate to "${t}"`)}static setCustomAttribute(e,t){return function(e,t){return e&&"string"==typeof e?(Ee.set(e,t),Ce(),i(`Set custom attribute "${e}" to "${t}"`),!0):(i(`Invalid key for custom attribute: ${e}`),!1)}(e,t)}static clearCustomAttributes(){Ee.clear(),r($e),i("Cleared all custom attributes")}static removeCustomAttribute(e){return function(e){if(!e||"string"!=typeof e)return i(`Invalid key for custom attribute: ${e}`),!1;const t=Ee.has(e);return Ee.delete(e),Ee.size>0?Ce():r($e),i(`Removed custom attribute "${e}"`),t}(e)}static async clearUserToken(){this.config.isPreviewSession||(F(),this.config.useAnonymousSession&&U(),Zt(!0),await Jt())}static async dismissMessage(e){const t=Y(e);t&&(await Pt(t),await Bt(t),await Ct(t),await Yt())}static async embedMessage(e,t){const n=Et(e,t);return n?.instanceId??null}static async showMessage(e){const t=await $t(e);return t?.instanceId??null}static updateMessageDisplaySettings(e,t){const n=Y(e);return!!n&&(n.displaySettings=t,we(n),!0)}static messageShown(e){i(`Message shown: ${e.messageId}`),this.events.dispatch("messageShown",e)}static messageDismissed(e){null!==e&&(i(`Message dismissed: ${e.messageId}`),this.events.dispatch("messageDismissed",e))}static messageError(e){i(`Message error: ${e.messageId}`),this.events.dispatch("messageError",e)}static messageAction(e,t,n){i(`Message action: ${e.currentRoute}, ${t} with name ${n} on ${e.instanceId}`),this.events.dispatch("messageAction",{message:e,action:t,name:n})}static async getInboxUnopenedCount(){return(await jt()).filter(e=>!e.opened).length}static async getInboxMessages(){return await jt()}static async updateInboxMessageOpenState(e,t){return await async function(e,t){const n=await _t();if(!n)return;const o=await async function(e,t){try{return await C()(`/api/v1/messages/${e}`,{method:"PATCH",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}})}catch(e){return E(e)}}(e,{opened:t});if(!o||o.status<200||o.status>=300){const e=`Failed to mark inbox message opened: ${o?.status??"unknown error"}`;throw i(e),new Error(e)}const a=await jt();let r=null;const l=a.map(n=>{if(n.queueId===e){const e={...n,opened:t};return r=e,e}return n}),c=new Date;if(c.setMinutes(c.getMinutes()+60),s(n,l,c),r){const e=t?"opened":"unopened";en.events.dispatch("inboxMessageAction",{message:r,action:e})}en.events.dispatch(Ft,await jt())}(e,t)}static async removeInboxMessage(e){return await async function(e){const t=await _t();if(!t)return;const n=await H(e);if(!n||n.status<200||n.status>=300){const e=`Failed to remove inbox message: ${n?.status??"unknown error"}`;throw i(e),new Error(e)}const o=(await jt()).filter(t=>t.queueId!==e),a=new Date;a.setMinutes(a.getMinutes()+60),s(t,o,a),en.events.dispatch(Ft,await jt())}(e)}}return t.default})());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "customerio-gist-web",
3
- "version": "3.21.7",
3
+ "version": "3.21.8",
4
4
  "description": "Build beautiful in-app flows with no code and deliver them instantly to your app. http://customer.io",
5
5
  "private": false,
6
6
  "files": [