customerio-gist-web 3.21.4 → 3.21.6

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