userflow.js-self-hosted 0.1.1002856 → 0.1.1002863

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.
@@ -1 +1 @@
1
- import{h as e,C as t,i as r,c as s,j as n,k as o,E as c,l as a,m as l,n as i,S as u,_ as d}from"./userflow.js";import{r as m}from"./vendor.react.js";import{u as f,i as w}from"./client-context.js";import{u as h,w as E,C as b}from"./Icons.js";import{b as k,h as p,s as v,B as g,R as C,a as j,n as S,f as y}from"./BubbleToolbar.js";import{M as N,g as _,a as I}from"./flow-condition-types.js";import{u as x,a as T,g as R}from"./stylesheets.js";import{u as A,F as B,S as L}from"./logomark.js";import{o as H}from"./vendor.obj-str.js";import{D as M}from"./DynamicIcon.js";import{f as F,C as P}from"./ChecklistUI.js";import{f as W,a as O,b as $,c as U,d as z,e as D,g as q,h as K,i as V,j as G}from"./vendor.fortawesome.pro-regular-svg-icons.js";import{F as Q}from"./vendor.fortawesome.react-fontawesome.js";import{u as Z}from"./vendor.react-i18next.js";function Y(t){return t!==e.ACTION&&t!==e.ASSISTANT&&t!==e.CONTACT&&t!==e.FLOWS&&t!==e.KNOWLEDGE_BASE&&t!==e.SUBPAGE}const J=window,X={[t.CRISP]:{configure:({onShow:e,onHide:t})=>{J.$crisp||(J.$crisp=[]),J.$crisp.push(["do","chat:hide"]);let r=!1,s=!1;const n=()=>{r||s?(J.$crisp.push(["do","chat:show"]),e()):(J.$crisp.push(["do","chat:hide"]),t())},o=()=>{r=!0,n()};J.$crisp.push(["on","chat:opened",o]);const c=()=>{r=!1,n()};J.$crisp.push(["on","chat:closed",c]);const a=()=>{s=!0,n()};J.$crisp.push(["on","message:received",a]);const l=window.setInterval((()=>{const e=(()=>{const e=document.getElementById("crisp-chatbox");if(!e||"block"!==window.getComputedStyle(e).display)return!1;const t=e.querySelector('[data-id="new_messages"]');return!(!t||"block"!==window.getComputedStyle(t).display)})();e!==s&&(s=e,n())}),200);return()=>{J.$crisp.push(["off","chat:opened",o]),J.$crisp.push(["off","chat:closed",c]),J.$crisp.push(["off","message:received",a]),window.clearInterval(l)}},show:()=>{J.$crisp.push(["do","chat:show"]),J.$crisp.push(["do","chat:open"])},hide:()=>{J.$crisp.push(["do","chat:hide"]),J.$crisp.push(["do","chat:close"])}},[t.CUSTOM]:{configure:()=>()=>{},show:({block:e})=>{try{new Function('"use strict";\n'+e.chatCode)()}catch(t){console.error(`Userflow.js: Showing custom chat provider failed. Code: ${e.chatCode}`,t)}},hide:()=>{}},[t.FRESHCHAT]:{configure:({onShow:e,onHide:t})=>{if(!J.fcWidget)throw new Error("Freshchat is not installed");let r=!1,s=!1;const n=()=>{r||s?e():t()},o=()=>{r=!0,n()};J.fcWidget.on("widget:opened",o);const c=()=>{r=!1,n()};J.fcWidget.on("widget:closed",c);const a=()=>{const e=!!document.querySelector("#fc_frame.h-open-notify");e!==s&&(s=e,n())},l=window.setInterval(a,200);return J.fcWidget.on("unreadCount:notify",a),()=>{J.fcWidget.off("widget:opened",o),J.fcWidget.off("widget:closed",c),J.fcWidget.off("unreadCount:notify",a),window.clearInterval(l)}},show:()=>{J.fcWidget.open()},hide:()=>{J.fcWidget.close()}},[t.HELPSCOUT]:{configure:({onShow:e,onHide:t})=>{if(!J.Beacon)throw new Error("Help Scout is not installed");te();let r=!1,s=!1;const n=()=>{r||s?(ee(),e()):(te(),t())},o=()=>{r=!0,n()};J.Beacon("on","open",o),J.Beacon("info")?.status.isOpened&&o();const c=()=>{r=!1,n()};J.Beacon("on","close",c);const a=window.setInterval((()=>{const e=!!document.querySelector(".BeaconNotificationsFrame");e!==s&&(s=e,n())}),200);return()=>{J.Beacon("off","open",o),J.Beacon("off","close",c),window.clearInterval(a)}},show:()=>{ee(),J.Beacon("open")},hide:()=>{te(),J.Beacon("close")}},[t.HUBSPOT]:{configure:({onShow:e,onHide:t})=>{const r=()=>{const r=document.getElementById("hubspot-messages-iframe-container");if(!J.HubSpotConversations||!r)return;window.clearInterval(n),re?se():ne();let o=!1,c=!1;const a=()=>{o||c?(se(),e()):(ne(),t())},l=()=>{const e=!!document.querySelector("#hubspot-messages-iframe-container .hs-shadow-container.active");e!==o&&(o=e,a())},i=new N(l);i.observe(r,{attributes:!0,subtree:!0,attributeFilter:["class"]}),l();const u=({unreadCount:e})=>{const t=e>0;t!==c&&(c=t,a())};J.HubSpotConversations.on("unreadConversationCountChanged",u),s=()=>{i.disconnect(),J.HubSpotConversations.off("unreadConversationCountChanged",u)}};let s=()=>{window.clearInterval(n)};const n=window.setInterval(r,100);return r(),()=>{s()}},show:()=>{se(),J.HubSpotConversations.widget.open()},hide:()=>{ne(),J.HubSpotConversations.widget.close()}},[t.INTERCOM]:{configure:({onShow:e,onHide:t})=>{if(!J.Intercom)throw new Error("Intercom is not installed");return ie(),function(){if(oe)return;oe=!0;let e=!1,t=!1;const r=()=>{le();for(const e of ce)e()},s=()=>{ie();for(const e of ae)e()},n=()=>{e||t?r():s()};J.Intercom("onShow",(()=>{e=!0,n()})),J.Intercom("onHide",(()=>{e=!1,n()}));const o=()=>{const e=!!document.querySelector('iframe[name="intercom-borderless-frame"], iframe[name="intercom-notifications-frame"]');t!==e&&(t=e,n())};J.Intercom("onUnreadCountChange",(()=>{o()})),window.setInterval(o,200)}(),ce.add(e),ae.add(t),()=>{ce.delete(e),ae.delete(t)}},show:()=>{le(),J.Intercom("show")},hide:()=>{ie(),J.Intercom("hide")}},[t.ZENDESK]:{configure:({onShow:e,onHide:t})=>{if(!J.zE)throw new Error("Zendesk is not installed");!function(){if(ue)return;ue=!0,J.zE("webWidget:on","open",(()=>{for(const e of de)e()})),J.zE("webWidget:on","close",(()=>{for(const e of me)e()})),J.zE("webWidget:on","chat:unreadMessages",(e=>{for(const t of fe)t(e)}))}(),J.zE("webWidget","hide"),J.zE("webWidget","close");let r=!1,s=!1;const n=()=>{r||s?(J.zE("webWidget","show"),e()):(J.zE("webWidget","hide"),t())},o=()=>{r=!0,s=!1,n()};de.add(o);const c=()=>{r=!1,s=!1,n()};me.add(c);const a=e=>{const t=e>0;t!==s&&(s=t,n())};return fe.add(a),()=>{de.delete(o),me.delete(c),fe.delete(a)}},show:()=>{J.zE("webWidget","show"),J.zE("webWidget","open")},hide:()=>{J.zE("webWidget","hide"),J.zE("webWidget","close")}},[t.ZENDESK_MESSENGER]:{configure:({onShow:e,onHide:t})=>{if(!J.zE)throw new Error("Zendesk is not installed");let r=!1;const s=window.setInterval((()=>{const s=(()=>{const e=document.querySelector('iframe[title="Messaging window"]');return!!e?.parentElement&&"0px"!==window.getComputedStyle(e.parentElement).height})();s!==r&&(r=s,r?e():t())}),200);return()=>{window.clearInterval(s)}},show:()=>{J.zE("messenger","open")},hide:()=>{J.zE("messenger","close")}}};function ee(){J.Beacon("config",{display:{style:"icon"}})}function te(){J.Beacon("config",{display:{style:"manual"}})}let re=!1;function se(){re=!0;document.getElementById("hubspot-messages-iframe-container")?.style.setProperty("visibility","visible","important")}function ne(){re=!1;document.getElementById("hubspot-messages-iframe-container")?.style.setProperty("visibility","hidden","important")}let oe=!1,ce=new Set,ae=new Set;function le(){J.Intercom("update",{hide_default_launcher:!1,vertical_padding:20})}function ie(){J.Intercom("update",{hide_default_launcher:!0,vertical_padding:100})}let ue=!1,de=new Set,me=new Set,fe=new Set;const we=e=>m.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 100 100"},e),m.createElement("path",{fill:"currentColor",d:"M24.049 79.74h36.003c8.185 0 15.985-6.621 17.43-14.814l6.091-34.556h3.997c8.149 0 13.645 6.63 12.2 14.815l-7.051 40C91.274 93.363 83.474 100 75.288 100h-40c-8.185 0-13.645-6.667-12.2-14.815l.96-5.444Z"}),m.createElement("path",{fill:"currentColor",fillRule:"evenodd",d:"M12.437 69.63h40c8.148 0 15.978-6.637 17.422-14.815l7.052-40C78.355 6.63 72.896 0 64.711 0h-40C16.533 0 8.726 6.63 7.281 14.815l-7.052 40C-1.215 62.963 4.252 69.63 12.437 69.63Zm33.628-33.798c3.756-2.064 8.725-4.795 9.907-11.844C57.385 15.458 50.065 8.983 42.168 9c-7.452 0-12.771 3.195-17.508 8.892-.858 1.034-.884 2.45-.053 3.212l3.472 3.196c.847.767 2.25.589 3.176-.406 2.842-3.068 4.869-4.83 8.51-4.83 2.864 0 6.077 1.934 5.59 4.847-.37 2.223-2.292 3.334-5.4 5.001l-.28.151c-3.582 1.92-8.134 4.362-9.124 10.247l-.16.956c-.055.28-.05.571.014.85.065.278.188.538.362.76.173.222.391.4.639.522.247.121.518.183.79.18h6.744a2.709 2.709 0 0 0 1.712-.688c.481-.426.81-1.01.934-1.657l.095-.556c.266-1.582 2.101-2.59 4.384-3.845ZM32.837 59c3.552 0 6.955-3.034 7.58-6.769.63-3.729-1.742-6.763-5.293-6.763-3.552 0-6.934 3.028-7.58 6.763C26.9 55.966 29.286 59 32.837 59Z"})),he=({center:e,fadeIn:t})=>{const r=12;return m.createElement("div",{className:H({"userflowjs-spinner":!0,"userflowjs-spinner--center":!!e,"userflowjs-spinner--fade-in":!!t})},m.createElement("svg",{viewBox:"0 0 24 24",version:"1.1",xmlns:"http://www.w3.org/2000/svg"},m.createElement("circle",{className:"userflowjs-spinner__bg",fill:"none",cx:r,cy:r,r:10,style:{strokeWidth:"4px"}}),m.createElement("circle",{className:"userflowjs-spinner__fill",fill:"none",cx:r,cy:r,r:10,transform:"translate(12, 12) rotate(-90) translate(-12, -12)",style:{strokeWidth:"4px",strokeDasharray:20*Math.PI*.25+"px, 1000"}})))};function Ee(e){const t=f(),[r,s]=m.useState(!0),[n,o]=m.useState(!1),[c,a]=m.useState(null),[l,i]=m.useState(null),[u,d]=m.useState(null),w=m.useRef(0),h=m.useRef(null),E=m.useRef((()=>{}));return m.useEffect((()=>{const r=JSON.stringify(e);if(r===h.current)return;h.current=r;const n=++w.current;let c,l;let u=!1;E.current=async(e,r)=>{if(!u){u=!0,o(!0);try{const s=e(c,l);l=s;const i=await t.send(s,{handlesRejection:!0});if(n!==w.current)return;c=r(c,i),a(c),d(null)}catch(s){if(n!==w.current)return;d(s)}finally{u=!1,o(!1)}}},(async()=>{s(!0);try{l=e;const r=await t.send(e,{handlesRejection:!0});if(n!==w.current)return;c=r,a(c),i(e),d(null)}catch(r){if(n!==w.current)return;d(r)}finally{s(!1)}})()}),[t,e]),{loading:r,loadingMore:n,data:c,messageForData:l,error:u,loadMore:E.current}}function be(e,t){const[r,s]=m.useState(e),n=m.useRef(void 0),o=m.useCallback((e=>{window.clearTimeout(n.current),s(e),t(e)}),[t]),c=m.useCallback((e=>{window.clearTimeout(n.current),s(e),n.current=window.setTimeout((()=>{t(e)}),200)}),[t]);return m.useEffect((()=>()=>{window.clearTimeout(n.current)}),[]),[r,c,o]}const ke=({textareaRef:e,value:t,onChange:r,onBlur:s,onKeyDown:n,placeholder:o,disabled:c,readOnly:a,className:l,mirrorClassName:i,textareaClassName:u,children:d})=>{let f=t||o||"";return(""===f||f.endsWith("\n"))&&(f+=" "),l=l||"growing-textarea",i=i||l+"__mirror",m.createElement("div",{className:l},m.createElement("div",{className:i+" "+(u||"")},f),m.createElement("textarea",{ref:e,value:t,onChange:e=>r&&r(e.target.value),onBlur:s,onKeyDown:n,placeholder:o,disabled:c,readOnly:a,className:u}),d)},pe=({textareaRef:e,value:t,onChange:r,onSubmit:s,placeholder:n,readOnly:o})=>{const c=()=>{s&&s()};return m.createElement("div",{className:"userflowjs-assistant-chat-input"},m.createElement(ke,{textareaRef:e,className:"userflowjs-growing-textarea",mirrorClassName:"userflowjs-growing-textarea__mirror",textareaClassName:"userflowjs-textarea userflowjs-assistant-chat-input__textarea",placeholder:n,readOnly:o,value:t||"",onChange:r,onKeyDown:e=>{e.shiftKey||"Enter"!==e.key||(e.preventDefault(),c())}}),m.createElement("button",{className:"userflowjs-assistant-chat-input__submit",onClick:()=>c()},m.createElement(Q,{icon:W})))},ve=async()=>(await d((()=>import("./ResourceCenterAssistantChat.js")),[new URL("ResourceCenterAssistantChat.js",import.meta.url).toString(),new URL("vendor.react.js",import.meta.url).toString(),new URL("vendor.object-assign.js",import.meta.url).toString(),new URL("client-context.js",import.meta.url).toString(),new URL("vendor.i18next.js",import.meta.url).toString(),new URL("vendor.react-i18next.js",import.meta.url).toString(),new URL("vendor.babel.runtime.js",import.meta.url).toString(),new URL("vendor.fortawesome.pro-regular-svg-icons.js",import.meta.url).toString(),new URL("vendor.fortawesome.react-fontawesome.js",import.meta.url).toString(),new URL("vendor.fortawesome.fontawesome-svg-core.js",import.meta.url).toString(),new URL("vendor.prop-types.js",import.meta.url).toString(),new URL("vendor.dompurify.js",import.meta.url).toString(),new URL("vendor.marked.js",import.meta.url).toString(),new URL("vendor.obj-str.js",import.meta.url).toString(),new URL("userflow.js",import.meta.url).toString(),new URL("vendor.phoenix.js",import.meta.url).toString(),new URL("vendor.uuid.js",import.meta.url).toString(),new URL("BubbleToolbar.js",import.meta.url).toString(),new URL("flow-condition-types.js",import.meta.url).toString(),new URL("vendor.date-fns.js",import.meta.url).toString(),new URL("stylesheets.js",import.meta.url).toString(),new URL("Icons.js",import.meta.url).toString(),new URL("vendor.fortawesome.pro-solid-svg-icons.js",import.meta.url).toString(),new URL("logomark.js",import.meta.url).toString(),new URL("vendor.react-dom.js",import.meta.url).toString(),new URL("vendor.scheduler.js",import.meta.url).toString(),new URL("DynamicIcon.js",import.meta.url).toString(),new URL("ChecklistUI.js",import.meta.url).toString()])).ResourceCenterAssistantChat,ge=({session:a,isOpen:l,flowSession:i,checklistSession:u})=>{const d=f(),{t:p}=Z(),{company:v}=a.flow,{version:g}=a,C=g.resourceCenter,j=x(g.theme),S=a.locale?a.locale.standardLocaleId:a.version.theme.languageId;m.useEffect((()=>{w.changeLanguage(S)}),[S]);const{loaded:I}=T(window,y,j),[P,W]=m.useState(!1),D=I&&P,[q,K]=m.useState(_()),V=m.useCallback((()=>{K(_())}),[]);A(V);const{zIndex:G,bringToFront:Q}=h(),J=m.useRef(null),[ee,te]=m.useState(null),[re,se]=m.useState(null),[ne,oe]=m.useState(null),ce=m.useRef(null),[ae,le]=m.useState(null),[ie,ue]=m.useState(null),[de,me]=m.useState(null),[fe,he]=m.useState(0),[Ee,be]=m.useState(0),ke=m.useCallback((()=>{re&&he(re.offsetWidth),be((ne?.offsetHeight||0)+(ae?.offsetHeight||0)+(ie?.offsetHeight||0)+(de?.offsetHeight||0))}),[re,ne,ae,ie,de]);m.useLayoutEffect((()=>{if(!ee||"function"!=typeof N)return;const e=new N((()=>{ke()}));return e.observe(ee,{childList:!0,attributes:!0,subtree:!0}),()=>{e.disconnect()}}),[ee,ke]),m.useLayoutEffect((()=>{ke()}));const[pe,ve]=m.useState(!1),ge=m.useRef(),Se=m.useCallback((()=>{ve(!0),window.clearTimeout(ge.current),ge.current=window.setTimeout((()=>{ve(!1)}),j.resourceCenterTransitionDuration)}),[j.resourceCenterTransitionDuration]);m.useEffect((()=>()=>{window.clearTimeout(ge.current)}),[]);const ye=m.useCallback((()=>{Q(),Se(),d.openResourceCenter()}),[Q,d,Se]),Te=m.useCallback((()=>{Se(),d.closeResourceCenter()}),[d,Se]),[Re,Be]=m.useState(!1);m.useEffect((()=>{if(Re){if(l){const e='button:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), input, textarea';let t=ae?.querySelector(e)||ne?.querySelector(e);if(t){const e=t.closest&&t.closest(".userflowjs-resource-center-checklist")||null;e?F(e):t.focus({preventScroll:!0})}}else re?.focus({preventScroll:!0});Be(!1)}}),[Re,l,ae,ne,re]),m.useEffect((()=>{const e=ee?.ownerDocument.defaultView;if(!l||!e)return;const t=e=>{"Escape"===e.key&&(Te(),Be(!0))};return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t)}),[l,ee,Be,Te]);const[Fe,Pe]=m.useState(null),We=m.useCallback(((e,t)=>{Pe(e),0===t?.detail&&Be(!0)}),[]);m.useEffect((()=>{l||We(null)}),[l,We]);const Oe=m.useMemo((()=>C.blocks.filter((t=>!(t.type===e.CHECKLIST&&!u)&&(!t.hiddenWhenFlowsActive||!t.hiddenWhenFlowsActive.some((e=>e===i?.flow.id||e===u?.flow.id)))))),[C,i,u]),$e=m.useMemo((()=>Ce(Oe)),[Oe]),Ue=m.useMemo((()=>u&&C.blocks.some((t=>t.type===e.CHECKLIST))?r(u):0),[C,u]),ze=m.useMemo((()=>C.blocks.find((t=>t.type===e.CONTACT&&t.chatEnabled&&t.chatProvider))),[C]),[De,qe]=m.useState(!1),Ke=m.useCallback((()=>{d.closeResourceCenter(),ze&&ze.chatProvider!==t.CUSTOM&&qe(!0)}),[d,ze]),Ve=m.useCallback((()=>{qe(!1)}),[]),Ge=m.useCallback((()=>{if(ze)try{X[ze.chatProvider].hide({block:ze}),Ve()}catch(e){console.error(`Userflow.js: Error when hiding ${ze.chatProvider}:`,e)}}),[ze,Ve]);m.useEffect((()=>{if(!ze)return;s.autoHide3pDisabled=!0;const e=X[ze.chatProvider];try{const t=e.configure({block:ze,onShow:Ke,onHide:Ve});return()=>{t()}}catch(t){return void console.error(`Userflow.js: Error when configuring ${ze.chatProvider}:`,t)}}),[ze,Ke,Ve]),m.useEffect((()=>{l&&Ge()}),[Ge,l]);const Qe=!!Fe&&("search"===Fe.kind||"flows"===Fe.kind||"knowledgeBase"===Fe.kind||"assistant"===Fe.kind),Ze={zIndex:null!=j.resourceCenterZIndex?j.resourceCenterZIndex:l?G:E(b),width:l?void 0:fe+"px",height:l?Math.min(Qe?540:Ee,q-2*j.resourceCenterPaddingY)+"px":void 0,position:D?void 0:"absolute",visibility:D&&!De?void 0:"hidden"},Ye=j.resourceCenterDisplayChecklistProgress&&u&&Ue>0?m.createElement("div",{"data-testid":"resource-center-launcher-badge",className:"userflowjs-resource-center-launcher-badge"},Ue,m.createElement("div",{className:"userflowjs-a11y-only"},"uncompleted tasks")):null;let Je="",Xe="";return j.resourceCenterLauncherTextMode===n.CHECKLIST_OVERRIDE&&u&&Ue>0?Je=u.version.checklist?.launcherText||"Get Started":j.resourceCenterLauncherTextMode!==n.NONE&&(Xe=C.buttonText),m.createElement("div",{"data-testid":"resource-center-app",className:"userflowjs-resource-center userflowjs-theme-root",style:R(j),dir:w.dir()},m.createElement(B,{elRef:J,className:H({"userflowjs-resource-center-frame":!0,"userflowjs-resource-center-frame--fixed":!0,[`userflowjs-resource-center-frame--placement-${j.resourceCenterPlacement.toLowerCase().replace(/_/g,"-")}`]:!0,"userflowjs-resource-center-frame--animating":pe,"userflowjs-resource-center-frame--open":l,"userflowjs-resource-center-frame--closed":!l}),style:{...Ze},stylesheet:k,theme:j,onStylesheetsLoad:W},D&&m.createElement(m.Fragment,null,m.createElement("div",{ref:te,className:H({"userflowjs-resource-center-frame-root":!0,[`userflowjs-resource-center-frame-root--placement-${j.resourceCenterPlacement.toLowerCase().replace(/_/g,"-")}`]:!0,"userflowjs-resource-center-frame-root--animating":pe,"userflowjs-resource-center-frame-root--open":l,"userflowjs-resource-center-frame-root--closed":!l}),role:l?"dialog":void 0,"aria-label":l?C.headerText:void 0},m.createElement("div",{className:"userflowjs-resource-center-launcher-container"},m.createElement("button",{ref:se,className:"userflowjs-resource-center-launcher-button",onClick:e=>{ye(),0===e.detail&&Be(!0)},"aria-label":`Open ${C.headerText}`},Ye,Je&&m.createElement("div",{"data-testid":"resource-center-launcher-text",className:"userflowjs-resource-center-launcher-text"},Je),(Ye||Je)&&m.createElement("div",{className:"userflowjs-resource-center-launcher-divider"}),Xe&&m.createElement("div",{"data-testid":"resource-center-launcher-text",className:"userflowjs-resource-center-launcher-text"},Xe),m.createElement("div",{className:"userflowjs-resource-center-launcher-icon"},j.resourceCenterLauncherIconType===o.PLAINTEXT?"?":m.createElement(we,null)))),m.createElement("div",{ref:ce,className:"userflowjs-resource-center-body"},m.createElement("div",{ref:le,className:H({"userflowjs-resource-center-body-content":!0,"userflowjs-resource-center-body-content--padding":"assistant"!==Fe?.kind,"userflowjs-resource-center-body-content--same-background":j.sameBackground,"userflowjs-resource-center-body-content--with-made-with-userflow":v.resourceCenterBranding})},l&&m.createElement(m.Fragment,null,Fe?"search"===Fe.kind?m.createElement(Ne,{session:a,navigate:We}):"email"===Fe.kind?m.createElement(_e,{block:Fe.block,session:a}):"phone"===Fe.kind?m.createElement(Ie,{block:Fe.block,session:a}):"flows"===Fe.kind?m.createElement(xe,{block:Fe.block,initialQ:Fe.initialQ,session:a,navigate:We}):"knowledgeBase"===Fe.kind?m.createElement(Ae,{block:Fe.block,initialQ:Fe.initialQ,session:a,bodyRef:ce}):"subpage"===Fe.kind?m.createElement(Le,{block:Fe.block,session:a}):"assistant"===Fe.kind?m.createElement(He,{block:Fe.block,initialUserContent:Fe.initialUserContent,session:a}):null:m.createElement(m.Fragment,null,Oe.map(((e,t)=>{const r=je[e.type],s=Oe[t+1];return r?m.createElement(m.Fragment,{key:e.id},m.createElement(r.View,{session:a,flowSession:i,checklistSession:u,block:e,navigate:We,onChatShow:Ke}),s&&(n=e.type,o=s.type,Y(n)||Y(o))&&m.createElement("div",{className:"userflowjs-resource-center-divider"})):null;var n,o})))))),v.resourceCenterBranding&&m.createElement("div",{className:"userflowjs-resource-center-made-with-userflow"},m.createElement("div",{className:"userflowjs-resource-center-made-with-userflow-content",ref:ue},m.createElement("a",{href:"https://userflow.com/?utm_source=made-with-userflow&utm_medium=link&utm_campaign=made-with-userflow-"+v.slug+"&utm_content=resource-center",target:"_blank",rel:"noopener noreferrer"},m.createElement(L,null),m.createElement("div",null,"Made with Userflow")))),a.draftMode&&m.createElement("div",{className:"userflowjs-resource-center-preview"},m.createElement("div",{ref:me,className:"userflowjs-resource-center-preview-content"},m.createElement("div",{className:"userflowjs-resource-center-preview-text"},"Preview"),m.createElement("button",{className:"userflowjs-resource-center-preview-button",onClick:()=>{d.endFlow(a,{endReason:c.USER_CLOSED})}},m.createElement(M,{icon:O})))),m.createElement("div",{className:"userflowjs-resource-center-header"},m.createElement("div",{ref:oe,className:"userflowjs-resource-center-header-content"},null==Fe?m.createElement("div",{className:"userflowjs-resource-center-header-text"},C.headerText):m.createElement("button",{className:"userflowjs-resource-center-icon-button",onClick:e=>We(null,e)},m.createElement("div",{className:"userflowjs-rtl-mirrored"},m.createElement(M,{icon:$})),m.createElement("div",{className:"userflowjs-resource-center-icon-button__text"},p("resource_center.back"))),m.createElement("div",{className:"flex-1"}),$e.length>0&&m.createElement("button",{className:"userflowjs-resource-center-icon-button",onClick:()=>{let e={kind:"search"};if(1===$e.length){const t=$e[0],r=je[t.type];r.routeTo&&(e=r.routeTo({block:t}))}"search"===Fe?.kind?We(null):(Me(d,a,null,"Search icon"),We(e))},"aria-label":"Search"},m.createElement(M,{icon:U})),m.createElement("button",{className:"userflowjs-resource-center-icon-button userflowjs-resource-center-close-button",onClick:e=>{Te(),0===e.detail&&Be(!0)},"aria-label":`Close ${C.headerText}`},m.createElement(M,{icon:z}))))))))};function Ce(e){return e.filter((e=>{const t=je[e.type];return t.isSearchable?t.isSearchable(e):!!t.search}))}const je={[e.ACTION]:{View:e=>{const{block:t,session:r,flowSession:s,checklistSession:n}=e,o=f(),[c,l]=m.useState(!1),i=s?.id,u=n?.id;return m.useEffect((()=>{l(!1)}),[i,u]),m.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:c?void 0:()=>{Me(o,r,t);const e=t.actions.find((e=>e.type===a.START_FLOW));if(e){e.otherFlow?.id!==n?.flow.id&&l(!0)}else o.closeResourceCenter();p(o,r,t.actions)},disabled:c},m.createElement(Se,{...e}),m.createElement(ye,{...e}),c&&m.createElement(he,null))}},[e.ASSISTANT]:{View:e=>{const{block:t,session:r,navigate:s}=e,n=f(),[o,c]=m.useState("");return t.assistantAppearance===l.INPUT?m.createElement("div",{className:"userflowjs-resource-center-assistant-block"},m.createElement(pe,{value:o,onChange:c,placeholder:v(t.name,{lookupAttribute:I(r.data)}),onSubmit:()=>{Me(n,r,t),s({kind:"assistant",block:t,initialUserContent:o})}})):m.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:()=>{Me(n,r,t),s({kind:"assistant",block:t,initialUserContent:""})}},m.createElement(Se,{...e}),m.createElement(ye,{...e}))}},[e.CHECKLIST]:{View:({checklistSession:e})=>m.createElement("div",{"data-testid":"resource-center-checklist",className:"userflowjs-resource-center-checklist"},m.createElement(P,{session:e}),m.createElement(g,{draftMode:!!e.draftMode&&"CHECKLIST PREVIEW"}))},[e.CONTACT]:{View:e=>{const{block:t,session:r,navigate:s,onChatShow:n}=e,o=f(),c=[];return t.emailEnabled&&c.push({icon:K,label:"Email",isRoute:!0,onClick:e=>{Me(o,r,t,"Email"),s({kind:"email",block:t},e)}}),t.phoneEnabled&&c.push({icon:V,label:"Phone",isRoute:!0,onClick:e=>{Me(o,r,t,"Phone"),s({kind:"phone",block:t},e)}}),t.chatEnabled&&c.push({icon:G,label:"Live-chat",isRoute:!1,onClick:()=>{if(Me(o,r,t,"Chat"),t.chatProvider){const r=X[t.chatProvider];try{r.show({block:t})}catch(e){console.error(`Userflow.js: Error when showing ${t.chatProvider}:`,e)}n()}else r.draftMode&&window.alert("You have not selected a chat provider. Go to the resource center builder in Userflow. Click the Contact block. Pick a chat provider in the side panel.")}}),m.createElement("div",{className:H({"userflowjs-resource-center-block":!0,"userflowjs-resource-center-block--clickable":1===c.length}),onClick:1===c.length?c[0].onClick:void 0},1===c.length&&m.createElement("div",{className:"userflowjs-resource-center-block-icon"},m.createElement(M,{icon:c[0].icon})),m.createElement(ye,{...e}),c.length>1&&c.map((({icon:e,label:t,onClick:r},s)=>m.createElement("button",{key:s,className:"userflowjs-resource-center-icon-button",onClick:r,"aria-label":t},m.createElement(M,{icon:e})))),1===c.length&&c[0].isRoute&&m.createElement("div",{className:"userflowjs-resource-center-block-nav-icon"},m.createElement(M,{icon:D})))}},[e.FLOWS]:{View:e=>{const{block:t,session:r,navigate:s}=e,n=f();return m.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:e=>{Me(n,r,t),s({kind:"flows",block:t},e)}},m.createElement(Se,{...e}),m.createElement(ye,{...e}),m.createElement("div",{className:"userflowjs-resource-center-block-nav-icon"},m.createElement(M,{icon:D})))},routeTo:({block:e,initialQ:t})=>({kind:"flows",block:e,initialQ:t}),isSearchable:e=>!!e.searchEnabled,search:async({client:e,session:t,block:r,q:s})=>{const{flows:n}=await e.send({kind:"ListResourceCenterBlockFlows",sessionId:t.id,blockCvid:r.cvid},{handlesRejection:!0}),o=Te(n,s),c=o.slice(0,5);return{block:r,truncated:c.length===o.length,results:c.map((e=>({kind:"flow",flow:e})))}}},[e.KNOWLEDGE_BASE]:{View:e=>{const{block:t,session:r,navigate:s}=e,n=f();return m.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:e=>{Me(n,r,t),s({kind:"knowledgeBase",block:t},e)}},m.createElement(Se,{...e}),m.createElement(ye,{...e}),m.createElement("div",{className:"userflowjs-resource-center-block-nav-icon"},m.createElement(M,{icon:D})))},routeTo:({block:e,initialQ:t})=>({kind:"knowledgeBase",block:e,initialQ:t}),search:async({client:e,session:t,block:r,q:s})=>{const{truncated:n,articles:o}=await e.send({kind:"SearchKnowledgeBase",sessionId:t.id,blockCvid:r.cvid,q:s,offset:0,limit:5},{handlesRejection:!0});return{block:r,truncated:n,results:o.map((e=>({kind:"article",article:e})))}}},[e.MESSAGE]:{View:({block:e,session:t})=>m.createElement("div",{className:"userflowjs-resource-center-block"},m.createElement("div",{className:"userflowjs-resource-center-block-text userflowjs-bubble-content"},m.createElement(C,{doc:e.content,lookupAttribute:I(t.data)})))},[e.SUBPAGE]:{View:e=>{const{block:t,session:r,navigate:s}=e,n=f();return m.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:e=>{Me(n,r,t),s({kind:"subpage",block:t},e)}},m.createElement(Se,{...e}),m.createElement(ye,{...e}),m.createElement("div",{className:"userflowjs-resource-center-block-nav-icon"},m.createElement(M,{icon:D})))}}},Se=({block:e})=>e.icon?m.createElement("div",{className:"userflowjs-resource-center-block-icon"},m.createElement(M,{icon:e.icon,size:16})):null,ye=({block:e,session:t})=>m.createElement("div",{className:"userflowjs-resource-center-block-text"},m.createElement(j,{doc:e.name,lookupAttribute:I(t.data)})),Ne=({session:e,navigate:t})=>{const r=f(),s=e.version.resourceCenter.blocks,n=Ce(s),{t:o}=Z(),c=m.useRef(null),[a,l]=m.useState(""),[i,u]=be(a,l),[d,w]=m.useState(null);return m.useEffect((()=>{if(""===a.trim())return void w(null);let t=!1;return(async()=>{w(null);const n=await Promise.all(s.map((async t=>{const{search:s}=je[t.type];if(!s)return null;try{return await s({client:r,session:e,block:t,q:a})}catch(n){return console.error(`Userflow.js: Global search failed for ${t.type} block=`,t,"error=",n),null}})));t||w(n.filter((e=>null!=e&&e.results.length>0)))})(),()=>{t=!0}}),[r,e,s,a]),m.useEffect((()=>{c.current?.focus({preventScroll:!0})}),[]),m.createElement(m.Fragment,null,m.createElement("div",{className:"userflowjs-resource-center-list-route-search"},m.createElement("input",{ref:c,className:"userflowjs-text-input",type:"text",value:i,onChange:e=>u(e.target.value),placeholder:o("resource_center.search_placeholder")})),""===a.trim()?m.createElement("div",{"data-testid":"resource-center-empty-query",className:"userflowjs-resource-center-list-route-error"},o("resource_center.search_in")," ",n.map(((t,r)=>m.createElement(m.Fragment,{key:t.cvid},r>0&&(r===n.length-1?` ${o("and")} `:", "),m.createElement("b",null,m.createElement(j,{doc:t.name,lookupAttribute:I(e.data)}))))),"."):d?0===d.length?m.createElement("div",{className:"userflowjs-resource-center-list-route-error"},o("resource_center.no_results_found")):d.map((({block:s,truncated:n,results:c},l)=>{const i=je[s.type],u=i.routeTo&&i.routeTo({block:s,initialQ:a});return m.createElement(m.Fragment,{key:s.cvid},l>0&&m.createElement("div",{className:"userflowjs-resource-center-divider"}),m.createElement("div",{className:"userflowjs-resource-center-label"},m.createElement(j,{doc:s.name,lookupAttribute:I(e.data)})),c.map(((r,n)=>"flow"===r.kind?m.createElement(Re,{key:r.flow.id,block:s,session:e,flow:r.flow,navigate:t}):"article"===r.kind?m.createElement(Be,{key:n,block:s,session:e,article:r.article}):null)),!n&&u&&m.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:n=>{Me(r,e,s),t(u,n)}},m.createElement("div",{className:"userflowjs-resource-center-block-text"},o("more"),":"," ",m.createElement(j,{doc:s.name,lookupAttribute:I(e.data)})),m.createElement("div",{className:"userflowjs-resource-center-block-nav-icon"},m.createElement(M,{icon:D}))))})):m.createElement("div",{className:"userflowjs-resource-center-list-route-spinner"},m.createElement(he,null)))},_e=({block:e,session:t})=>m.createElement("div",{className:"userflowjs-resource-center-content-route userflowjs-bubble-content"},m.createElement(C,{doc:e.emailContent,lookupAttribute:I(t.data)})),Ie=({block:e,session:t})=>m.createElement("div",{className:"userflowjs-resource-center-content-route userflowjs-bubble-content"},m.createElement(C,{doc:e.phoneContent,lookupAttribute:I(t.data)})),xe=({block:e,initialQ:t,session:r,navigate:s})=>{const{t:n}=Z(),o=m.useRef(null),[c,a]=m.useState(t||""),[l,i]=be(c,a),{data:u,error:d}=Ee({kind:"ListResourceCenterBlockFlows",sessionId:r.id,blockCvid:e.cvid}),f=u?.flows,w=m.useMemo((()=>f?Te(f,c):null),[f,c]);return m.useEffect((()=>{o.current?.focus({preventScroll:!0})}),[]),m.createElement(m.Fragment,null,m.createElement("div",{className:"userflowjs-resource-center-list-route-header"},m.createElement("div",{className:"userflowjs-resource-center-list-route-title"},m.createElement(j,{doc:e.name,lookupAttribute:I(r.data)}))),e.searchEnabled&&m.createElement("div",{className:"userflowjs-resource-center-list-route-search"},m.createElement("input",{ref:o,className:"userflowjs-text-input",type:"text",value:l,onChange:e=>i(e.target.value),placeholder:n("resource_center.search_placeholder")})),d?m.createElement("div",{className:"userflowjs-resource-center-list-route-error"},n("resource_center.generic_error")):w?0===w.length?m.createElement("div",{className:"userflowjs-resource-center-list-route-error"},n("resource_center.no_results_found")):w.map((t=>m.createElement(Re,{key:t.id,block:e,session:r,flow:t,navigate:s}))):m.createElement("div",{className:"userflowjs-resource-center-list-route-spinner"},m.createElement(he,{fadeIn:!0})))};function Te(e,t){const r=t.toLowerCase().trim();return""===r?e:e.filter((e=>e.name.toLowerCase().includes(r)))}const Re=({block:e,session:t,flow:r,navigate:s})=>{const n=f(),[o,c]=m.useState(!1);return m.useEffect((()=>{if(!o||r.type!==i.CHECKLIST)return;const e=()=>{n.checklistSession?.flow.id===r.id&&(t(),s(null))},t=()=>{n.off("checklistChanged",e)};return n.on("checklistChanged",e),t}),[n,o,r.type,r.id,s]),m.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:()=>{if(Me(n,t,e,r.name),n.checklistSession?.flow.id===r.id)return void s(null);n.startFlow({flowId:r.id,startReason:u.RESOURCE_CENTER,replaceCurrent:!0}),c(!0);const o=v(r.url,{lookupAttribute:I(t.data)});o&&S(o)},disabled:o},m.createElement("div",{className:"userflowjs-resource-center-block-icon"},m.createElement(M,{icon:r.type===i.CHECKLIST?"regular/tasks":"regular/shoe-prints",size:16})),m.createElement("div",{className:"userflowjs-resource-center-block-text"},r.name),o&&m.createElement(he,null))},Ae=({block:e,initialQ:t,session:r,bodyRef:s})=>{const{t:n}=Z(),o=m.useRef(null),[c,a]=m.useState(t||""),[l,i]=be(c,a),{loading:u,loadingMore:d,data:f,messageForData:w,error:h,loadMore:E}=Ee({kind:"SearchKnowledgeBase",sessionId:r.id,blockCvid:e.cvid,q:c,offset:0}),b=f?.truncated,k=m.useCallback((()=>{E(((e,t)=>({...t,offset:e.articles.length})),((e,t)=>({...t,articles:[...e.articles,...t.articles]})))}),[E]);m.useEffect((()=>{const e=s.current;if(!e||u||d||b)return;const t=()=>{e.scrollHeight-e.clientHeight-e.scrollTop>400||k()};return e.addEventListener("scroll",t),()=>{e.removeEventListener("scroll",t)}}),[s,u,d,b,k]),m.useEffect((()=>{o.current?.focus({preventScroll:!0})}),[]);let p=e.knowledgeBaseUrl||"";return p.match(/^https?:\/\//)||(p=`http://${p}`),m.createElement(m.Fragment,null,m.createElement("div",{className:"userflowjs-resource-center-list-route-header"},m.createElement("div",{className:"userflowjs-resource-center-list-route-title"},m.createElement(j,{doc:e.name,lookupAttribute:I(r.data)})),m.createElement("a",{className:"userflowjs-resource-center-icon-button",href:p,target:"_blank",rel:"noopener noreferrer"},m.createElement(M,{icon:q}))),m.createElement("div",{className:"userflowjs-resource-center-list-route-search"},m.createElement("input",{ref:o,className:"userflowjs-text-input",type:"text",value:l,onChange:e=>i(e.target.value),placeholder:n("resource_center.search_placeholder")})),h?m.createElement("div",{className:"userflowjs-resource-center-list-route-error"},"quota_exceeded"===h.code?"Sorry, this company has reached its max number of searches. Consider asking Userflow to be moved to a dedicated search engine for a higher quota.":n("resource_center.generic_error")):u||!f?m.createElement("div",{className:"userflowjs-resource-center-list-route-spinner"},m.createElement(he,null)):0===f.articles.length?""===w?.q?null:m.createElement("div",{className:"userflowjs-resource-center-list-route-error"},n("resource_center.no_results_found")):m.createElement(m.Fragment,null,""===w?.q&&m.createElement("div",{className:"userflowjs-resource-center-label"},n("resource_center.suggested_articles")),f.articles.map(((t,s)=>m.createElement(Be,{key:s,block:e,session:r,article:t}))),d&&m.createElement("div",{className:"userflowjs-resource-center-list-route-spinner"},m.createElement(he,null))))},Be=({block:e,article:t,session:r})=>{const s=f();return m.createElement("a",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:()=>{Me(s,r,e,t.title)},href:t.url,target:"_blank",rel:"noopener noreferrer"},m.createElement("div",{className:"userflowjs-resource-center-block-icon"},m.createElement(M,{icon:"regular/file-alt",size:16})),m.createElement("div",{className:"userflowjs-resource-center-block-text"},m.createElement("span",{dangerouslySetInnerHTML:{__html:t.htmlTitle}}),m.createElement("div",{className:"userflowjs-resource-center-block-subtext",dangerouslySetInnerHTML:{__html:t.htmlSnippet}})))},Le=({block:e,session:t})=>m.createElement("div",{className:"userflowjs-resource-center-content-route userflowjs-bubble-content"},m.createElement(C,{doc:e.content,lookupAttribute:I(t.data)})),He=({block:e,initialUserContent:t,session:r})=>{const s=e.assistantFlowId,n=f(),[o,c]=m.useState(null),[a,l]=m.useState(null),[i,u]=m.useState(null);return m.useEffect((()=>{let e=!1;return(async()=>{try{const[t,r]=await Promise.all([ve(),n.send({kind:"GetAssistant",assistantFlowId:s},{handlesRejection:!0})]);if(e)return;c((()=>t)),l(r.assistant)}catch(t){console.error("Resource center assistant route failed to load:",t),u(t.humanMessage||"Sorry, something went wrong. Please try again or contact my human friends.")}})(),()=>{e=!0}}),[n,s]),i?m.createElement("div",{className:"userflowjs-assistant-chat"},m.createElement("div",{className:"userflowjs-assistant-chat__content"},m.createElement("div",{className:"userflowjs-assistant-chat__error"},i))):o&&a?m.createElement(o,{block:e,session:r,assistant:a,initialUserContent:t}):m.createElement(he,{center:!0,fadeIn:!0})};function Me(e,t,r,s){e.send({kind:"ClickResourceCenter",sessionId:t.id,description:r?v(r.name,{lookupAttribute:I(t.data)})+(s?` - ${s}`:""):s},{batch:!0})}var Fe=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",ResourceCenterApp:ge,default:ge});export{pe as A,ke as G,Fe as R};
1
+ import{h as e,C as t,i as r,c as s,j as n,k as o,E as c,l as a,m as l,n as i,S as u,p as d,_ as m}from"./userflow.js";import{r as f}from"./vendor.react.js";import{u as w,i as h}from"./client-context.js";import{u as E,w as b,C as k}from"./Icons.js";import{b as p,h as v,s as g,B as C,R as j,a as S,n as y,f as N}from"./BubbleToolbar.js";import{M as _,g as I,a as x}from"./flow-condition-types.js";import{u as T,a as R,g as A}from"./stylesheets.js";import{u as B,F as L,S as H}from"./logomark.js";import{o as M}from"./vendor.obj-str.js";import{D as F}from"./DynamicIcon.js";import{f as P,C as W}from"./ChecklistUI.js";import{f as O,a as $,b as U,c as z,d as D,e as q,g as K,h as V,i as G,j as Q}from"./vendor.fortawesome.pro-regular-svg-icons.js";import{F as Z}from"./vendor.fortawesome.react-fontawesome.js";import{u as Y}from"./vendor.react-i18next.js";function J(t){return t!==e.ACTION&&t!==e.ASSISTANT&&t!==e.CONTACT&&t!==e.FLOWS&&t!==e.KNOWLEDGE_BASE&&t!==e.SUBPAGE}const X=window,ee={[t.CRISP]:{configure:({onShow:e,onHide:t})=>{X.$crisp||(X.$crisp=[]),X.$crisp.push(["do","chat:hide"]);let r=!1,s=!1;const n=()=>{r||s?(X.$crisp.push(["do","chat:show"]),e()):(X.$crisp.push(["do","chat:hide"]),t())},o=()=>{r=!0,n()};X.$crisp.push(["on","chat:opened",o]);const c=()=>{r=!1,n()};X.$crisp.push(["on","chat:closed",c]);const a=()=>{s=!0,n()};X.$crisp.push(["on","message:received",a]);const l=window.setInterval((()=>{const e=(()=>{const e=document.getElementById("crisp-chatbox");if(!e||"block"!==window.getComputedStyle(e).display)return!1;const t=e.querySelector('[data-id="new_messages"]');return!(!t||"block"!==window.getComputedStyle(t).display)})();e!==s&&(s=e,n())}),200);return()=>{X.$crisp.push(["off","chat:opened",o]),X.$crisp.push(["off","chat:closed",c]),X.$crisp.push(["off","message:received",a]),window.clearInterval(l)}},show:()=>{X.$crisp.push(["do","chat:show"]),X.$crisp.push(["do","chat:open"])},hide:()=>{X.$crisp.push(["do","chat:hide"]),X.$crisp.push(["do","chat:close"])}},[t.CUSTOM]:{configure:()=>()=>{},show:({block:e})=>{try{new Function('"use strict";\n'+e.chatCode)()}catch(t){console.error(`Userflow.js: Showing custom chat provider failed. Code: ${e.chatCode}`,t)}},hide:()=>{}},[t.FRESHCHAT]:{configure:({onShow:e,onHide:t})=>{if(!X.fcWidget)throw new Error("Freshchat is not installed");let r=!1,s=!1;const n=()=>{r||s?e():t()},o=()=>{r=!0,n()};X.fcWidget.on("widget:opened",o);const c=()=>{r=!1,n()};X.fcWidget.on("widget:closed",c);const a=()=>{const e=!!document.querySelector("#fc_frame.h-open-notify");e!==s&&(s=e,n())},l=window.setInterval(a,200);return X.fcWidget.on("unreadCount:notify",a),()=>{X.fcWidget.off("widget:opened",o),X.fcWidget.off("widget:closed",c),X.fcWidget.off("unreadCount:notify",a),window.clearInterval(l)}},show:()=>{X.fcWidget.open()},hide:()=>{X.fcWidget.close()}},[t.HELPSCOUT]:{configure:({onShow:e,onHide:t})=>{if(!X.Beacon)throw new Error("Help Scout is not installed");re();let r=!1,s=!1;const n=()=>{r||s?(te(),e()):(re(),t())},o=()=>{r=!0,n()};X.Beacon("on","open",o),X.Beacon("info")?.status.isOpened&&o();const c=()=>{r=!1,n()};X.Beacon("on","close",c);const a=window.setInterval((()=>{const e=!!document.querySelector(".BeaconNotificationsFrame");e!==s&&(s=e,n())}),200);return()=>{X.Beacon("off","open",o),X.Beacon("off","close",c),window.clearInterval(a)}},show:()=>{te(),X.Beacon("open")},hide:()=>{re(),X.Beacon("close")}},[t.HUBSPOT]:{configure:({onShow:e,onHide:t})=>{const r=()=>{const r=document.getElementById("hubspot-messages-iframe-container");if(!X.HubSpotConversations||!r)return;window.clearInterval(n),se?ne():oe();let o=!1,c=!1;const a=()=>{o||c?(ne(),e()):(oe(),t())},l=()=>{const e=!!document.querySelector("#hubspot-messages-iframe-container .hs-shadow-container.active");e!==o&&(o=e,a())},i=new _(l);i.observe(r,{attributes:!0,subtree:!0,attributeFilter:["class"]}),l();const u=({unreadCount:e})=>{const t=e>0;t!==c&&(c=t,a())};X.HubSpotConversations.on("unreadConversationCountChanged",u),s=()=>{i.disconnect(),X.HubSpotConversations.off("unreadConversationCountChanged",u)}};let s=()=>{window.clearInterval(n)};const n=window.setInterval(r,100);return r(),()=>{s()}},show:()=>{ne(),X.HubSpotConversations.widget.open()},hide:()=>{oe(),X.HubSpotConversations.widget.close()}},[t.INTERCOM]:{configure:({onShow:e,onHide:t})=>{if(!X.Intercom)throw new Error("Intercom is not installed");return ue(),function(){if(ce)return;ce=!0;let e=!1,t=!1;const r=()=>{ie();for(const e of ae)e()},s=()=>{ue();for(const e of le)e()},n=()=>{e||t?r():s()};X.Intercom("onShow",(()=>{e=!0,n()})),X.Intercom("onHide",(()=>{e=!1,n()}));const o=()=>{const e=!!document.querySelector('iframe[name="intercom-borderless-frame"], iframe[name="intercom-notifications-frame"]');t!==e&&(t=e,n())};X.Intercom("onUnreadCountChange",(()=>{o()})),window.setInterval(o,200)}(),ae.add(e),le.add(t),()=>{ae.delete(e),le.delete(t)}},show:()=>{ie(),X.Intercom("show")},hide:()=>{ue(),X.Intercom("hide")}},[t.ZENDESK]:{configure:({onShow:e,onHide:t})=>{if(!X.zE)throw new Error("Zendesk is not installed");!function(){if(de)return;de=!0,X.zE("webWidget:on","open",(()=>{for(const e of me)e()})),X.zE("webWidget:on","close",(()=>{for(const e of fe)e()})),X.zE("webWidget:on","chat:unreadMessages",(e=>{for(const t of we)t(e)}))}(),X.zE("webWidget","hide"),X.zE("webWidget","close");let r=!1,s=!1;const n=()=>{r||s?(X.zE("webWidget","show"),e()):(X.zE("webWidget","hide"),t())},o=()=>{r=!0,s=!1,n()};me.add(o);const c=()=>{r=!1,s=!1,n()};fe.add(c);const a=e=>{const t=e>0;t!==s&&(s=t,n())};return we.add(a),()=>{me.delete(o),fe.delete(c),we.delete(a)}},show:()=>{X.zE("webWidget","show"),X.zE("webWidget","open")},hide:()=>{X.zE("webWidget","hide"),X.zE("webWidget","close")}},[t.ZENDESK_MESSENGER]:{configure:({onShow:e,onHide:t})=>{if(!X.zE)throw new Error("Zendesk is not installed");let r=!1;const s=window.setInterval((()=>{const s=(()=>{const e=document.querySelector('iframe[title="Messaging window"]');return!!e?.parentElement&&"0px"!==window.getComputedStyle(e.parentElement).height})();s!==r&&(r=s,r?e():t())}),200);return()=>{window.clearInterval(s)}},show:()=>{X.zE("messenger","open")},hide:()=>{X.zE("messenger","close")}}};function te(){X.Beacon("config",{display:{style:"icon"}})}function re(){X.Beacon("config",{display:{style:"manual"}})}let se=!1;function ne(){se=!0;document.getElementById("hubspot-messages-iframe-container")?.style.setProperty("visibility","visible","important")}function oe(){se=!1;document.getElementById("hubspot-messages-iframe-container")?.style.setProperty("visibility","hidden","important")}let ce=!1,ae=new Set,le=new Set;function ie(){X.Intercom("update",{hide_default_launcher:!1,vertical_padding:20})}function ue(){X.Intercom("update",{hide_default_launcher:!0,vertical_padding:100})}let de=!1,me=new Set,fe=new Set,we=new Set;const he=e=>f.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 100 100"},e),f.createElement("path",{fill:"currentColor",d:"M24.049 79.74h36.003c8.185 0 15.985-6.621 17.43-14.814l6.091-34.556h3.997c8.149 0 13.645 6.63 12.2 14.815l-7.051 40C91.274 93.363 83.474 100 75.288 100h-40c-8.185 0-13.645-6.667-12.2-14.815l.96-5.444Z"}),f.createElement("path",{fill:"currentColor",fillRule:"evenodd",d:"M12.437 69.63h40c8.148 0 15.978-6.637 17.422-14.815l7.052-40C78.355 6.63 72.896 0 64.711 0h-40C16.533 0 8.726 6.63 7.281 14.815l-7.052 40C-1.215 62.963 4.252 69.63 12.437 69.63Zm33.628-33.798c3.756-2.064 8.725-4.795 9.907-11.844C57.385 15.458 50.065 8.983 42.168 9c-7.452 0-12.771 3.195-17.508 8.892-.858 1.034-.884 2.45-.053 3.212l3.472 3.196c.847.767 2.25.589 3.176-.406 2.842-3.068 4.869-4.83 8.51-4.83 2.864 0 6.077 1.934 5.59 4.847-.37 2.223-2.292 3.334-5.4 5.001l-.28.151c-3.582 1.92-8.134 4.362-9.124 10.247l-.16.956c-.055.28-.05.571.014.85.065.278.188.538.362.76.173.222.391.4.639.522.247.121.518.183.79.18h6.744a2.709 2.709 0 0 0 1.712-.688c.481-.426.81-1.01.934-1.657l.095-.556c.266-1.582 2.101-2.59 4.384-3.845ZM32.837 59c3.552 0 6.955-3.034 7.58-6.769.63-3.729-1.742-6.763-5.293-6.763-3.552 0-6.934 3.028-7.58 6.763C26.9 55.966 29.286 59 32.837 59Z"})),Ee=({center:e,fadeIn:t})=>{const r=12;return f.createElement("div",{className:M({"userflowjs-spinner":!0,"userflowjs-spinner--center":!!e,"userflowjs-spinner--fade-in":!!t})},f.createElement("svg",{viewBox:"0 0 24 24",version:"1.1",xmlns:"http://www.w3.org/2000/svg"},f.createElement("circle",{className:"userflowjs-spinner__bg",fill:"none",cx:r,cy:r,r:10,style:{strokeWidth:"4px"}}),f.createElement("circle",{className:"userflowjs-spinner__fill",fill:"none",cx:r,cy:r,r:10,transform:"translate(12, 12) rotate(-90) translate(-12, -12)",style:{strokeWidth:"4px",strokeDasharray:20*Math.PI*.25+"px, 1000"}})))};function be(e){const t=w(),[r,s]=f.useState(!0),[n,o]=f.useState(!1),[c,a]=f.useState(null),[l,i]=f.useState(null),[u,d]=f.useState(null),m=f.useRef(0),h=f.useRef(null),E=f.useRef((()=>{}));return f.useEffect((()=>{const r=JSON.stringify(e);if(r===h.current)return;h.current=r;const n=++m.current;let c,l;let u=!1;E.current=async(e,r)=>{if(!u){u=!0,o(!0);try{const s=e(c,l);l=s;const i=await t.send(s,{handlesRejection:!0});if(n!==m.current)return;c=r(c,i),a(c),d(null)}catch(s){if(n!==m.current)return;d(s)}finally{u=!1,o(!1)}}},(async()=>{s(!0);try{l=e;const r=await t.send(e,{handlesRejection:!0});if(n!==m.current)return;c=r,a(c),i(e),d(null)}catch(r){if(n!==m.current)return;d(r)}finally{s(!1)}})()}),[t,e]),{loading:r,loadingMore:n,data:c,messageForData:l,error:u,loadMore:E.current}}function ke(e,t){const[r,s]=f.useState(e),n=f.useRef(void 0),o=f.useCallback((e=>{window.clearTimeout(n.current),s(e),t(e)}),[t]),c=f.useCallback((e=>{window.clearTimeout(n.current),s(e),n.current=window.setTimeout((()=>{t(e)}),200)}),[t]);return f.useEffect((()=>()=>{window.clearTimeout(n.current)}),[]),[r,c,o]}const pe=({textareaRef:e,value:t,onChange:r,onBlur:s,onKeyDown:n,placeholder:o,disabled:c,readOnly:a,className:l,mirrorClassName:i,textareaClassName:u,children:d})=>{let m=t||o||"";return(""===m||m.endsWith("\n"))&&(m+=" "),l=l||"growing-textarea",i=i||l+"__mirror",f.createElement("div",{className:l},f.createElement("div",{className:i+" "+(u||"")},m),f.createElement("textarea",{ref:e,value:t,onChange:e=>r&&r(e.target.value),onBlur:s,onKeyDown:n,placeholder:o,disabled:c,readOnly:a,className:u}),d)},ve=({textareaRef:e,value:t,onChange:r,onSubmit:s,placeholder:n,readOnly:o})=>{const c=()=>{s&&s()};return f.createElement("div",{className:"userflowjs-assistant-chat-input"},f.createElement(pe,{textareaRef:e,className:"userflowjs-growing-textarea",mirrorClassName:"userflowjs-growing-textarea__mirror",textareaClassName:"userflowjs-textarea userflowjs-assistant-chat-input__textarea",placeholder:n,readOnly:o,value:t||"",onChange:r,onKeyDown:e=>{e.shiftKey||"Enter"!==e.key||(e.preventDefault(),c())}}),f.createElement("button",{className:"userflowjs-assistant-chat-input__submit",onClick:()=>c()},f.createElement(Z,{icon:O})))},ge=async()=>(await m((()=>import("./ResourceCenterAssistantChat.js")),[new URL("ResourceCenterAssistantChat.js",import.meta.url).toString(),new URL("vendor.react.js",import.meta.url).toString(),new URL("vendor.object-assign.js",import.meta.url).toString(),new URL("client-context.js",import.meta.url).toString(),new URL("vendor.i18next.js",import.meta.url).toString(),new URL("vendor.react-i18next.js",import.meta.url).toString(),new URL("vendor.babel.runtime.js",import.meta.url).toString(),new URL("vendor.fortawesome.pro-regular-svg-icons.js",import.meta.url).toString(),new URL("vendor.fortawesome.react-fontawesome.js",import.meta.url).toString(),new URL("vendor.fortawesome.fontawesome-svg-core.js",import.meta.url).toString(),new URL("vendor.prop-types.js",import.meta.url).toString(),new URL("vendor.dompurify.js",import.meta.url).toString(),new URL("vendor.marked.js",import.meta.url).toString(),new URL("vendor.obj-str.js",import.meta.url).toString(),new URL("userflow.js",import.meta.url).toString(),new URL("vendor.phoenix.js",import.meta.url).toString(),new URL("vendor.uuid.js",import.meta.url).toString(),new URL("BubbleToolbar.js",import.meta.url).toString(),new URL("flow-condition-types.js",import.meta.url).toString(),new URL("vendor.date-fns.js",import.meta.url).toString(),new URL("stylesheets.js",import.meta.url).toString(),new URL("Icons.js",import.meta.url).toString(),new URL("vendor.fortawesome.pro-solid-svg-icons.js",import.meta.url).toString(),new URL("logomark.js",import.meta.url).toString(),new URL("vendor.react-dom.js",import.meta.url).toString(),new URL("vendor.scheduler.js",import.meta.url).toString(),new URL("DynamicIcon.js",import.meta.url).toString(),new URL("ChecklistUI.js",import.meta.url).toString()])).ResourceCenterAssistantChat,Ce=({session:a,isOpen:l,flowSession:i,checklistSession:u})=>{const d=w(),{t:m}=Y(),{company:v}=a.flow,{version:g}=a,C=g.resourceCenter,j=T(g.theme),S=a.locale?a.locale.standardLocaleId:a.version.theme.languageId;f.useEffect((()=>{h.changeLanguage(S)}),[S]);const{loaded:y}=R(window,N,j),[x,W]=f.useState(!1),O=y&&x,[q,K]=f.useState(I()),V=f.useCallback((()=>{K(I())}),[]);B(V);const{zIndex:G,bringToFront:Q}=E(),Z=f.useRef(null),[X,te]=f.useState(null),[re,se]=f.useState(null),[ne,oe]=f.useState(null),ce=f.useRef(null),[ae,le]=f.useState(null),[ie,ue]=f.useState(null),[de,me]=f.useState(null),[fe,we]=f.useState(0),[Ee,be]=f.useState(0),ke=f.useCallback((()=>{re&&we(re.offsetWidth),be((ne?.offsetHeight||0)+(ae?.offsetHeight||0)+(ie?.offsetHeight||0)+(de?.offsetHeight||0))}),[re,ne,ae,ie,de]);f.useLayoutEffect((()=>{if(!X||"function"!=typeof _)return;const e=new _((()=>{ke()}));return e.observe(X,{childList:!0,attributes:!0,subtree:!0}),()=>{e.disconnect()}}),[X,ke]),f.useLayoutEffect((()=>{ke()}));const[pe,ve]=f.useState(!1),ge=f.useRef(),Ce=f.useCallback((()=>{ve(!0),window.clearTimeout(ge.current),ge.current=window.setTimeout((()=>{ve(!1)}),j.resourceCenterTransitionDuration)}),[j.resourceCenterTransitionDuration]);f.useEffect((()=>()=>{window.clearTimeout(ge.current)}),[]);const ye=f.useCallback((()=>{Q(),Ce(),d.openResourceCenter()}),[Q,d,Ce]),Ne=f.useCallback((()=>{Ce(),d.closeResourceCenter()}),[d,Ce]),[Re,Ae]=f.useState(!1);f.useEffect((()=>{if(Re){if(l){const e='button:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), input, textarea';let t=ae?.querySelector(e)||ne?.querySelector(e);if(t){const e=t.closest&&t.closest(".userflowjs-resource-center-checklist")||null;e?P(e):t.focus({preventScroll:!0})}}else re?.focus({preventScroll:!0});Ae(!1)}}),[Re,l,ae,ne,re]),f.useEffect((()=>{const e=X?.ownerDocument.defaultView;if(!l||!e)return;const t=e=>{"Escape"===e.key&&(Ne(),Ae(!0))};return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t)}),[l,X,Ae,Ne]);const[Le,Pe]=f.useState(null),We=f.useCallback(((e,t)=>{Pe(e),0===t?.detail&&Ae(!0)}),[]),Oe=f.useMemo((()=>C.blocks.filter((t=>!(t.type===e.CHECKLIST&&!u)&&(!t.hiddenWhenFlowsActive||!t.hiddenWhenFlowsActive.some((e=>e===i?.flow.id||e===u?.flow.id)))))),[C,i,u]),$e=f.useMemo((()=>je(Oe)),[Oe]),Ue=f.useMemo((()=>u&&C.blocks.some((t=>t.type===e.CHECKLIST))?r(u):0),[C,u]),ze=f.useMemo((()=>C.blocks.find((t=>t.type===e.CONTACT&&t.chatEnabled&&t.chatProvider))),[C]),[De,qe]=f.useState(!1),Ke=f.useCallback((()=>{d.closeResourceCenter(),ze&&ze.chatProvider!==t.CUSTOM&&qe(!0)}),[d,ze]),Ve=f.useCallback((()=>{qe(!1)}),[]),Ge=f.useCallback((()=>{if(ze)try{ee[ze.chatProvider].hide({block:ze}),Ve()}catch(e){console.error(`Userflow.js: Error when hiding ${ze.chatProvider}:`,e)}}),[ze,Ve]);f.useEffect((()=>{if(!ze)return;s.autoHide3pDisabled=!0;const e=ee[ze.chatProvider];try{const t=e.configure({block:ze,onShow:Ke,onHide:Ve});return()=>{t()}}catch(t){return void console.error(`Userflow.js: Error when configuring ${ze.chatProvider}:`,t)}}),[ze,Ke,Ve]),f.useEffect((()=>{l&&Ge()}),[Ge,l]);const Qe=!!Le&&("search"===Le.kind||"flows"===Le.kind||"knowledgeBase"===Le.kind||"assistant"===Le.kind),Ze={zIndex:null!=j.resourceCenterZIndex?j.resourceCenterZIndex:l?G:b(k),width:l?void 0:fe+"px",height:l?Math.min(Qe?540:Ee,q-2*j.resourceCenterPaddingY)+"px":void 0,position:O?void 0:"absolute",visibility:O&&!De?void 0:"hidden"},Ye=j.resourceCenterDisplayChecklistProgress&&u&&Ue>0?f.createElement("div",{"data-testid":"resource-center-launcher-badge",className:"userflowjs-resource-center-launcher-badge"},Ue,f.createElement("div",{className:"userflowjs-a11y-only"},"uncompleted tasks")):null;let Je="",Xe="";return j.resourceCenterLauncherTextMode===n.CHECKLIST_OVERRIDE&&u&&Ue>0?Je=u.version.checklist?.launcherText||"Get Started":j.resourceCenterLauncherTextMode!==n.NONE&&(Xe=C.buttonText),f.createElement("div",{"data-testid":"resource-center-app",className:"userflowjs-resource-center userflowjs-theme-root",style:A(j),dir:h.dir()},f.createElement(L,{elRef:Z,className:M({"userflowjs-resource-center-frame":!0,"userflowjs-resource-center-frame--fixed":!0,[`userflowjs-resource-center-frame--placement-${j.resourceCenterPlacement.toLowerCase().replace(/_/g,"-")}`]:!0,"userflowjs-resource-center-frame--animating":pe,"userflowjs-resource-center-frame--open":l,"userflowjs-resource-center-frame--closed":!l}),style:{...Ze},stylesheet:p,theme:j,onStylesheetsLoad:W},O&&f.createElement(f.Fragment,null,f.createElement("div",{ref:te,className:M({"userflowjs-resource-center-frame-root":!0,[`userflowjs-resource-center-frame-root--placement-${j.resourceCenterPlacement.toLowerCase().replace(/_/g,"-")}`]:!0,"userflowjs-resource-center-frame-root--animating":pe,"userflowjs-resource-center-frame-root--open":l,"userflowjs-resource-center-frame-root--closed":!l}),role:l?"dialog":void 0,"aria-label":l?C.headerText:void 0},f.createElement("div",{className:"userflowjs-resource-center-launcher-container"},f.createElement("button",{ref:se,className:"userflowjs-resource-center-launcher-button",onClick:e=>{ye(),0===e.detail&&Ae(!0)},"aria-label":`Open ${C.headerText}`},Ye,Je&&f.createElement("div",{"data-testid":"resource-center-launcher-text",className:"userflowjs-resource-center-launcher-text"},Je),(Ye||Je)&&f.createElement("div",{className:"userflowjs-resource-center-launcher-divider"}),Xe&&f.createElement("div",{"data-testid":"resource-center-launcher-text",className:"userflowjs-resource-center-launcher-text"},Xe),f.createElement("div",{className:"userflowjs-resource-center-launcher-icon"},j.resourceCenterLauncherIconType===o.PLAINTEXT?"?":f.createElement(he,null)))),f.createElement("div",{ref:ce,className:"userflowjs-resource-center-body"},f.createElement("div",{ref:le,className:M({"userflowjs-resource-center-body-content":!0,"userflowjs-resource-center-body-content--padding":"assistant"!==Le?.kind,"userflowjs-resource-center-body-content--same-background":j.sameBackground,"userflowjs-resource-center-body-content--with-made-with-userflow":v.resourceCenterBranding})},l&&f.createElement(f.Fragment,null,Le?"search"===Le.kind?f.createElement(_e,{session:a,navigate:We}):"email"===Le.kind?f.createElement(Ie,{block:Le.block,session:a}):"phone"===Le.kind?f.createElement(xe,{block:Le.block,session:a}):"flows"===Le.kind?f.createElement(Te,{block:Le.block,initialQ:Le.initialQ,session:a,navigate:We}):"knowledgeBase"===Le.kind?f.createElement(Be,{block:Le.block,initialQ:Le.initialQ,session:a,bodyRef:ce}):"subpage"===Le.kind?f.createElement(He,{block:Le.block,session:a}):"assistant"===Le.kind?f.createElement(Me,{block:Le.block,initialUserContent:Le.initialUserContent,session:a}):null:f.createElement(f.Fragment,null,Oe.map(((e,t)=>{const r=Se[e.type],s=Oe[t+1];return r?f.createElement(f.Fragment,{key:e.id},f.createElement(r.View,{session:a,flowSession:i,checklistSession:u,block:e,navigate:We,onChatShow:Ke}),s&&(n=e.type,o=s.type,J(n)||J(o))&&f.createElement("div",{className:"userflowjs-resource-center-divider"})):null;var n,o})))))),v.resourceCenterBranding&&f.createElement("div",{className:"userflowjs-resource-center-made-with-userflow"},f.createElement("div",{className:"userflowjs-resource-center-made-with-userflow-content",ref:ue},f.createElement("a",{href:"https://userflow.com/?utm_source=made-with-userflow&utm_medium=link&utm_campaign=made-with-userflow-"+v.slug+"&utm_content=resource-center",target:"_blank",rel:"noopener noreferrer"},f.createElement(H,null),f.createElement("div",null,"Made with Userflow")))),a.draftMode&&f.createElement("div",{className:"userflowjs-resource-center-preview"},f.createElement("div",{ref:me,className:"userflowjs-resource-center-preview-content"},f.createElement("div",{className:"userflowjs-resource-center-preview-text"},"Preview"),f.createElement("button",{className:"userflowjs-resource-center-preview-button",onClick:()=>{d.endFlow(a,{endReason:c.USER_CLOSED})}},f.createElement(F,{icon:$})))),f.createElement("div",{className:"userflowjs-resource-center-header"},f.createElement("div",{ref:oe,className:"userflowjs-resource-center-header-content"},null==Le?f.createElement("div",{className:"userflowjs-resource-center-header-text"},C.headerText):f.createElement("button",{className:"userflowjs-resource-center-icon-button",onClick:e=>We(null,e)},f.createElement("div",{className:"userflowjs-rtl-mirrored"},f.createElement(F,{icon:U})),f.createElement("div",{className:"userflowjs-resource-center-icon-button__text"},m("resource_center.back"))),f.createElement("div",{className:"flex-1"}),$e.length>0&&f.createElement("button",{className:"userflowjs-resource-center-icon-button",onClick:()=>{let e={kind:"search"};if(1===$e.length){const t=$e[0],r=Se[t.type];r.routeTo&&(e=r.routeTo({block:t}))}"search"===Le?.kind?We(null):(Fe(d,a,null,"Search icon"),We(e))},"aria-label":"Search"},f.createElement(F,{icon:z})),f.createElement("button",{className:"userflowjs-resource-center-icon-button userflowjs-resource-center-close-button",onClick:e=>{Ne(),0===e.detail&&Ae(!0)},"aria-label":`Close ${C.headerText}`},f.createElement(F,{icon:D}))))))))};function je(e){return e.filter((e=>{const t=Se[e.type];return t.isSearchable?t.isSearchable(e):!!t.search}))}const Se={[e.ACTION]:{View:e=>{const{block:t,session:r,flowSession:s,checklistSession:n}=e,o=w(),[c,l]=f.useState(!1),i=s?.id,u=n?.id;return f.useEffect((()=>{l(!1)}),[i,u]),f.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:c?void 0:()=>{Fe(o,r,t);const e=t.actions.find((e=>e.type===a.START_FLOW));if(e){e.otherFlow?.id!==n?.flow.id&&l(!0)}else o.closeResourceCenter();v(o,r,t.actions)},disabled:c},f.createElement(ye,{...e}),f.createElement(Ne,{...e}),c&&f.createElement(Ee,null))}},[e.ASSISTANT]:{View:e=>{const{block:t,session:r,navigate:s}=e,n=w(),[o,c]=f.useState("");return t.assistantAppearance===l.INPUT?f.createElement("div",{className:"userflowjs-resource-center-assistant-block"},f.createElement(ve,{value:o,onChange:c,placeholder:g(t.name,{lookupAttribute:x(r.data)}),onSubmit:()=>{Fe(n,r,t),s({kind:"assistant",block:t,initialUserContent:o})}})):f.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:()=>{Fe(n,r,t),s({kind:"assistant",block:t,initialUserContent:""})}},f.createElement(ye,{...e}),f.createElement(Ne,{...e}))}},[e.CHECKLIST]:{View:({checklistSession:e})=>f.createElement("div",{"data-testid":"resource-center-checklist",className:"userflowjs-resource-center-checklist"},f.createElement(W,{session:e}),f.createElement(C,{draftMode:!!e.draftMode&&"CHECKLIST PREVIEW"}))},[e.CONTACT]:{View:e=>{const{block:t,session:r,navigate:s,onChatShow:n}=e,o=w(),c=[];return t.emailEnabled&&c.push({icon:V,label:"Email",isRoute:!0,onClick:e=>{Fe(o,r,t,"Email"),s({kind:"email",block:t},e)}}),t.phoneEnabled&&c.push({icon:G,label:"Phone",isRoute:!0,onClick:e=>{Fe(o,r,t,"Phone"),s({kind:"phone",block:t},e)}}),t.chatEnabled&&c.push({icon:Q,label:"Live-chat",isRoute:!1,onClick:()=>{if(Fe(o,r,t,"Chat"),t.chatProvider){const r=ee[t.chatProvider];try{r.show({block:t})}catch(e){console.error(`Userflow.js: Error when showing ${t.chatProvider}:`,e)}n()}else r.draftMode&&window.alert("You have not selected a chat provider. Go to the resource center builder in Userflow. Click the Contact block. Pick a chat provider in the side panel.")}}),f.createElement("div",{className:M({"userflowjs-resource-center-block":!0,"userflowjs-resource-center-block--clickable":1===c.length}),onClick:1===c.length?c[0].onClick:void 0},1===c.length&&f.createElement("div",{className:"userflowjs-resource-center-block-icon"},f.createElement(F,{icon:c[0].icon})),f.createElement(Ne,{...e}),c.length>1&&c.map((({icon:e,label:t,onClick:r},s)=>f.createElement("button",{key:s,className:"userflowjs-resource-center-icon-button",onClick:r,"aria-label":t},f.createElement(F,{icon:e})))),1===c.length&&c[0].isRoute&&f.createElement("div",{className:"userflowjs-resource-center-block-nav-icon"},f.createElement(F,{icon:q})))}},[e.FLOWS]:{View:e=>{const{block:t,session:r,navigate:s}=e,n=w();return f.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:e=>{Fe(n,r,t),s({kind:"flows",block:t},e)}},f.createElement(ye,{...e}),f.createElement(Ne,{...e}),f.createElement("div",{className:"userflowjs-resource-center-block-nav-icon"},f.createElement(F,{icon:q})))},routeTo:({block:e,initialQ:t})=>({kind:"flows",block:e,initialQ:t}),isSearchable:e=>!!e.searchEnabled,search:async({client:e,session:t,block:r,q:s})=>{const{flows:n}=await e.send({kind:"ListResourceCenterBlockFlows",sessionId:t.id,blockCvid:r.cvid},{handlesRejection:!0}),o=Re(n,s),c=o.slice(0,5);return{block:r,truncated:c.length===o.length,results:c.map((e=>({kind:"flow",flow:e})))}}},[e.KNOWLEDGE_BASE]:{View:e=>{const{block:t,session:r,navigate:s}=e,n=w();return f.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:e=>{Fe(n,r,t),s({kind:"knowledgeBase",block:t},e)}},f.createElement(ye,{...e}),f.createElement(Ne,{...e}),f.createElement("div",{className:"userflowjs-resource-center-block-nav-icon"},f.createElement(F,{icon:q})))},routeTo:({block:e,initialQ:t})=>({kind:"knowledgeBase",block:e,initialQ:t}),search:async({client:e,session:t,block:r,q:s})=>{const{truncated:n,articles:o}=await e.send({kind:"SearchKnowledgeBase",sessionId:t.id,blockCvid:r.cvid,q:s,offset:0,limit:5},{handlesRejection:!0});return{block:r,truncated:n,results:o.map((e=>({kind:"article",article:e})))}}},[e.MESSAGE]:{View:({block:e,session:t})=>f.createElement("div",{className:"userflowjs-resource-center-block"},f.createElement("div",{className:"userflowjs-resource-center-block-text userflowjs-bubble-content"},f.createElement(j,{doc:e.content,lookupAttribute:x(t.data)})))},[e.SUBPAGE]:{View:e=>{const{block:t,session:r,navigate:s}=e,n=w();return f.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:e=>{Fe(n,r,t),s({kind:"subpage",block:t},e)}},f.createElement(ye,{...e}),f.createElement(Ne,{...e}),f.createElement("div",{className:"userflowjs-resource-center-block-nav-icon"},f.createElement(F,{icon:q})))}}},ye=({block:e})=>e.icon?f.createElement("div",{className:"userflowjs-resource-center-block-icon"},f.createElement(F,{icon:e.icon,size:16})):null,Ne=({block:e,session:t})=>f.createElement("div",{className:"userflowjs-resource-center-block-text"},f.createElement(S,{doc:e.name,lookupAttribute:x(t.data)})),_e=({session:e,navigate:t})=>{const r=w(),s=e.version.resourceCenter.blocks,n=je(s),{t:o}=Y(),c=f.useRef(null),[a,l]=f.useState(""),[i,u]=ke(a,l),[d,m]=f.useState(null);return f.useEffect((()=>{if(""===a.trim())return void m(null);let t=!1;return(async()=>{m(null);const n=await Promise.all(s.map((async t=>{const{search:s}=Se[t.type];if(!s)return null;try{return await s({client:r,session:e,block:t,q:a})}catch(n){return console.error(`Userflow.js: Global search failed for ${t.type} block=`,t,"error=",n),null}})));t||m(n.filter((e=>null!=e&&e.results.length>0)))})(),()=>{t=!0}}),[r,e,s,a]),f.useEffect((()=>{c.current?.focus({preventScroll:!0})}),[]),f.createElement(f.Fragment,null,f.createElement("div",{className:"userflowjs-resource-center-list-route-search"},f.createElement("input",{ref:c,className:"userflowjs-text-input",type:"text",value:i,onChange:e=>u(e.target.value),placeholder:o("resource_center.search_placeholder")})),""===a.trim()?f.createElement("div",{"data-testid":"resource-center-empty-query",className:"userflowjs-resource-center-list-route-error"},o("resource_center.search_in")," ",n.map(((t,r)=>f.createElement(f.Fragment,{key:t.cvid},r>0&&(r===n.length-1?` ${o("and")} `:", "),f.createElement("b",null,f.createElement(S,{doc:t.name,lookupAttribute:x(e.data)}))))),"."):d?0===d.length?f.createElement("div",{className:"userflowjs-resource-center-list-route-error"},o("resource_center.no_results_found")):d.map((({block:s,truncated:n,results:c},l)=>{const i=Se[s.type],u=i.routeTo&&i.routeTo({block:s,initialQ:a});return f.createElement(f.Fragment,{key:s.cvid},l>0&&f.createElement("div",{className:"userflowjs-resource-center-divider"}),f.createElement("div",{className:"userflowjs-resource-center-label"},f.createElement(S,{doc:s.name,lookupAttribute:x(e.data)})),c.map(((r,n)=>"flow"===r.kind?f.createElement(Ae,{key:r.flow.id,block:s,session:e,flow:r.flow,navigate:t}):"article"===r.kind?f.createElement(Le,{key:n,block:s,session:e,article:r.article}):null)),!n&&u&&f.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:n=>{Fe(r,e,s),t(u,n)}},f.createElement("div",{className:"userflowjs-resource-center-block-text"},o("more"),":"," ",f.createElement(S,{doc:s.name,lookupAttribute:x(e.data)})),f.createElement("div",{className:"userflowjs-resource-center-block-nav-icon"},f.createElement(F,{icon:q}))))})):f.createElement("div",{className:"userflowjs-resource-center-list-route-spinner"},f.createElement(Ee,null)))},Ie=({block:e,session:t})=>f.createElement("div",{className:"userflowjs-resource-center-content-route userflowjs-bubble-content"},f.createElement(j,{doc:e.emailContent,lookupAttribute:x(t.data)})),xe=({block:e,session:t})=>f.createElement("div",{className:"userflowjs-resource-center-content-route userflowjs-bubble-content"},f.createElement(j,{doc:e.phoneContent,lookupAttribute:x(t.data)})),Te=({block:e,initialQ:t,session:r,navigate:s})=>{const{t:n}=Y(),o=f.useRef(null),[c,a]=f.useState(t||""),[l,i]=ke(c,a),{data:u,error:d}=be({kind:"ListResourceCenterBlockFlows",sessionId:r.id,blockCvid:e.cvid}),m=u?.flows,w=f.useMemo((()=>m?Re(m,c):null),[m,c]);return f.useEffect((()=>{o.current?.focus({preventScroll:!0})}),[]),f.createElement(f.Fragment,null,f.createElement("div",{className:"userflowjs-resource-center-list-route-header"},f.createElement("div",{className:"userflowjs-resource-center-list-route-title"},f.createElement(S,{doc:e.name,lookupAttribute:x(r.data)}))),e.searchEnabled&&f.createElement("div",{className:"userflowjs-resource-center-list-route-search"},f.createElement("input",{ref:o,className:"userflowjs-text-input",type:"text",value:l,onChange:e=>i(e.target.value),placeholder:n("resource_center.search_placeholder")})),d?f.createElement("div",{className:"userflowjs-resource-center-list-route-error"},n("resource_center.generic_error")):w?0===w.length?f.createElement("div",{className:"userflowjs-resource-center-list-route-error"},n("resource_center.no_results_found")):w.map((t=>f.createElement(Ae,{key:t.id,block:e,session:r,flow:t,navigate:s}))):f.createElement("div",{className:"userflowjs-resource-center-list-route-spinner"},f.createElement(Ee,{fadeIn:!0})))};function Re(e,t){const r=t.toLowerCase().trim();return""===r?e:e.filter((e=>e.name.toLowerCase().includes(r)))}const Ae=({block:e,session:t,flow:r,navigate:s})=>{const n=w(),[o,c]=f.useState(!1);return f.useEffect((()=>{if(!o||r.type!==i.CHECKLIST)return;const e=()=>{n.checklistSession?.flow.id===r.id&&(t(),s(null))},t=()=>{n.off("checklistChanged",e)};return n.on("checklistChanged",e),t}),[n,o,r.type,r.id,s]),f.createElement("button",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:()=>{if(Fe(n,t,e,r.name),n.checklistSession?.flow.id===r.id)return void s(null);n.startFlow({flowId:r.id,startReason:u.RESOURCE_CENTER,replaceCurrent:!0}),c(!0);const o=g(r.url,{lookupAttribute:x(t.data)});o&&y(o)},disabled:o},f.createElement("div",{className:"userflowjs-resource-center-block-icon"},f.createElement(F,{icon:r.type===i.CHECKLIST?"regular/tasks":"regular/shoe-prints",size:16})),f.createElement("div",{className:"userflowjs-resource-center-block-text"},r.name),o&&f.createElement(Ee,null))},Be=({block:e,initialQ:t,session:r,bodyRef:s})=>{const{t:n}=Y(),o=f.useRef(null),[c,a]=f.useState(t||""),[l,i]=ke(c,a),{loading:u,loadingMore:d,data:m,messageForData:w,error:h,loadMore:E}=be({kind:"SearchKnowledgeBase",sessionId:r.id,blockCvid:e.cvid,q:c,offset:0}),b=m?.truncated,k=f.useCallback((()=>{E(((e,t)=>({...t,offset:e.articles.length})),((e,t)=>({...t,articles:[...e.articles,...t.articles]})))}),[E]);f.useEffect((()=>{const e=s.current;if(!e||u||d||b)return;const t=()=>{e.scrollHeight-e.clientHeight-e.scrollTop>400||k()};return e.addEventListener("scroll",t),()=>{e.removeEventListener("scroll",t)}}),[s,u,d,b,k]),f.useEffect((()=>{o.current?.focus({preventScroll:!0})}),[]);let p=e.knowledgeBaseUrl||"";return p.match(/^https?:\/\//)||(p=`http://${p}`),f.createElement(f.Fragment,null,f.createElement("div",{className:"userflowjs-resource-center-list-route-header"},f.createElement("div",{className:"userflowjs-resource-center-list-route-title"},f.createElement(S,{doc:e.name,lookupAttribute:x(r.data)})),f.createElement("a",{className:"userflowjs-resource-center-icon-button",href:p,target:"_blank",rel:"noopener noreferrer"},f.createElement(F,{icon:K}))),f.createElement("div",{className:"userflowjs-resource-center-list-route-search"},f.createElement("input",{ref:o,className:"userflowjs-text-input",type:"text",value:l,onChange:e=>i(e.target.value),placeholder:n("resource_center.search_placeholder")})),h?f.createElement("div",{className:"userflowjs-resource-center-list-route-error"},"quota_exceeded"===h.code?"Sorry, this company has reached its max number of searches. Consider asking Userflow to be moved to a dedicated search engine for a higher quota.":n("resource_center.generic_error")):u||!m?f.createElement("div",{className:"userflowjs-resource-center-list-route-spinner"},f.createElement(Ee,null)):0===m.articles.length?""===w?.q?null:f.createElement("div",{className:"userflowjs-resource-center-list-route-error"},n("resource_center.no_results_found")):f.createElement(f.Fragment,null,""===w?.q&&f.createElement("div",{className:"userflowjs-resource-center-label"},n("resource_center.suggested_articles")),m.articles.map(((t,s)=>f.createElement(Le,{key:s,block:e,session:r,article:t}))),d&&f.createElement("div",{className:"userflowjs-resource-center-list-route-spinner"},f.createElement(Ee,null))))},Le=({block:e,article:t,session:r})=>{const s=w();return f.createElement("a",{className:"userflowjs-resource-center-block userflowjs-resource-center-block--clickable",onClick:()=>{Fe(s,r,e,t.title)},href:t.url,target:"_blank",rel:"noopener noreferrer"},f.createElement("div",{className:"userflowjs-resource-center-block-icon"},f.createElement(F,{icon:"regular/file-alt",size:16})),f.createElement("div",{className:"userflowjs-resource-center-block-text"},f.createElement("span",{dangerouslySetInnerHTML:{__html:t.htmlTitle}}),f.createElement("div",{className:"userflowjs-resource-center-block-subtext",dangerouslySetInnerHTML:{__html:t.htmlSnippet}})))},He=({block:e,session:t})=>f.createElement("div",{className:"userflowjs-resource-center-content-route userflowjs-bubble-content"},f.createElement(j,{doc:e.content,lookupAttribute:x(t.data)})),Me=({block:e,initialUserContent:t,session:r})=>{const s=e.assistantFlowId,n=w(),[o,c]=f.useState(null),[a,l]=f.useState(null),[i,u]=f.useState(null);return f.useEffect((()=>{let e=!1;return(async()=>{try{const t=d.getItem("assistantConversationId:"+s),[r,o]=await Promise.all([ge(),n.send({kind:"GetAssistant",assistantFlowId:s,conversationId:t},{handlesRejection:!0})]);if(e)return;c((()=>r)),l(o)}catch(t){console.error("Resource center assistant route failed to load:",t),u(t.humanMessage||"Sorry, something went wrong. Please try again or contact my human friends.")}})(),()=>{e=!0}}),[n,s]),i?f.createElement("div",{className:"userflowjs-assistant-chat"},f.createElement("div",{className:"userflowjs-assistant-chat__content"},f.createElement("div",{className:"userflowjs-assistant-chat__error"},i))):o&&a?f.createElement(o,{block:e,session:r,assistantReply:a,initialUserContent:t}):f.createElement(Ee,{center:!0,fadeIn:!0})};function Fe(e,t,r,s){e.send({kind:"ClickResourceCenter",sessionId:t.id,description:r?g(r.name,{lookupAttribute:x(t.data)})+(s?` - ${s}`:""):s},{batch:!0})}var Pe=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",ResourceCenterApp:Ce,default:Ce});export{ve as A,pe as G,Pe as R};
@@ -1 +1 @@
1
- import{r as e}from"./vendor.react.js";import{u as t}from"./client-context.js";import{y as s,z as a,A as n}from"./vendor.fortawesome.pro-regular-svg-icons.js";import{F as r}from"./vendor.fortawesome.react-fontawesome.js";import{p as o}from"./vendor.dompurify.js";import{m as i}from"./vendor.marked.js";import{o as c}from"./vendor.obj-str.js";import{P as l}from"./userflow.js";import{A as u,G as m}from"./ResourceCenterApp.js";import{r as d,R as f}from"./BubbleToolbar.js";import{a as p}from"./flow-condition-types.js";import"./vendor.object-assign.js";import"./vendor.i18next.js";import"./vendor.react-i18next.js";import"./vendor.babel.runtime.js";import"./vendor.fortawesome.fontawesome-svg-core.js";import"./vendor.prop-types.js";import"./vendor.phoenix.js";import"./vendor.uuid.js";import"./Icons.js";import"./stylesheets.js";import"./logomark.js";import"./vendor.react-dom.js";import"./vendor.scheduler.js";import"./DynamicIcon.js";import"./vendor.fortawesome.pro-solid-svg-icons.js";import"./ChecklistUI.js";import"./vendor.date-fns.js";const b=[];const g=({assistant:t,lookupAttribute:s,history:a,setInput:n,contentElRef:r,userContent:o,setUserContent:i,onSubmitMessage:c,supportsFeedback:l,onSubmitRating:m,onSubmitFeedback:p,reset:b,onContentMouseWheel:g})=>e.createElement("div",{className:"userflowjs-assistant-chat"},e.createElement("div",{ref:r,className:"userflowjs-assistant-chat__header"},e.createElement("h2",{ref:r,className:"userflowjs-assistant-chat__title"},t.title),e.createElement("button",{className:"userflowjs-bubble-button userflowjs-bubble-button--default",onClick:b},t.resetText)),e.createElement("div",{ref:r,className:"userflowjs-assistant-chat__content",onWheel:g},!d(t.intro)&&e.createElement("div",{className:"userflowjs-assistant-chat__intro"},e.createElement(f,{doc:t.intro,lookupAttribute:s})),a.map(((s,a)=>e.createElement(h,{key:a,assistant:t,message:s,supportsFeedback:l,onSubmitRating:m,onSubmitFeedback:p})))),e.createElement("div",{className:"userflowjs-assistant-chat__prompt"},e.createElement(u,{textareaRef:n,placeholder:(0===a.length?t.promptEmptyPlaceholder:t.promptNonemptyPlaceholder)||"",value:o,onChange:i,onSubmit:()=>c(o)}))),h=({assistant:t,message:o,supportsFeedback:i,onSubmitRating:u,onSubmitFeedback:d})=>{const f=e.useRef(null),[p,b]=e.useState(""),g=()=>{o.id&&(d({messageId:o.id,feedback:p.trim()}),b(""))};return e.useEffect((()=>{o.rating&&f.current?.focus({preventScroll:!0})}),[o.rating]),e.createElement("div",null,e.createElement("div",{className:"userflowjs-assistant-chat__user-content"},e.createElement("div",{style:{whiteSpace:"pre-wrap"}},o.userContent)),e.createElement("div",{className:"userflowjs-assistant-chat__assistant-content"},e.createElement("div",{dangerouslySetInnerHTML:{__html:o.assistantHtml||""}}),o.error&&e.createElement("div",{className:"userflowjs-assistant-chat__error"},o.error)),o.sources&&o.sources.length>0&&e.createElement("div",{className:"userflowjs-assistant-chat__sources"},e.createElement("div",{className:"userflowjs-assistant-chat__sources-title"},t.sourcesText),o.sources.map(((t,s)=>e.createElement("a",{key:s,className:"userflowjs-assistant-chat__source",href:t.url,target:"_blank",rel:"noreferrer noopener"},t.title)))),i&&o.completed&&o.id&&e.createElement("div",{className:c({"userflowjs-assistant-chat__feedback":!0,"userflowjs-assistant-chat__feedback--with-textarea":!!o.rating&&!o.feedbackSubmitted})},o.feedbackSubmitted?e.createElement(e.Fragment,null,e.createElement("button",{className:"userflowjs-assistant-chat__rating",disabled:!0},e.createElement(r,{icon:o.rating==l.DISLIKE?s:a})),e.createElement("div",{className:"userflowjs-assistant-chat__feedback-thanks"},t.feedbackThanksText)):o.rating?e.createElement(m,{textareaRef:f,className:"userflowjs-growing-textarea userflowjs-assistant-chat__feedback-textarea",mirrorClassName:"userflowjs-growing-textarea__mirror",textareaClassName:"userflowjs-textarea",placeholder:(o.rating===l.LIKE?t.feedbackLikePlaceholder:t.feedbackDislikePlaceholder)||"",value:p,onChange:b,onKeyDown:e=>{e.shiftKey||"Enter"!==e.key||(e.preventDefault(),g())}},e.createElement("button",{className:"userflowjs-assistant-chat__rating",disabled:!0},e.createElement(r,{icon:o.rating==l.DISLIKE?s:a})),e.createElement("button",{className:"userflowjs-assistant-chat__feedback-submit",onClick:()=>g()},e.createElement(r,{icon:n}))):[l.LIKE,l.DISLIKE].map((t=>(!o.rating||o.rating===t)&&e.createElement("button",{key:t,className:"userflowjs-assistant-chat__rating",onClick:o.rating?void 0:()=>(e=>{o.id&&u({messageId:o.id,rating:e})})(t),disabled:!!o.rating},e.createElement(r,{icon:t==l.DISLIKE?s:a}))))))};function k(e){let t=e;const s=e=>e=(e=e.replace(/\s*[*_`]*$/,"")).replace(/(^|\n)\s*(\d+\.?|-|=)$/,"");t=s(t),t=t.replace(/\[[^\]\n]*(\](\([^)\n]*\)?)?)?$/,""),t=s(t);const a=Array.from(t.matchAll(/\n( *)```/g));if(a.length%2==1){t+="\n"+a[a.length-1][1]+"```"}else{let e=0;for(let r=t.length-1;r>=0;r--)if("\n"===t[r]&&"\n"===t[r-1]){e=r;break}const s=[];let a=!1;const n=e=>null==e||e.match(/\W/);for(let r=e;r<t.length;r++){const e=t[r],o=e+t[r+1],i=o+t[r+2];let c=null;(a||"***"!==i)&&(a||"___"!==i||!n(t[r-1])&&!n(t[r+3]))?(a||"**"!==o)&&(a||"__"!==o||!n(t[r-1])&&!n(t[r+2]))?(a||"*"!==e)&&(a||"_"!==e||!n(t[r-1])&&!n(t[r+1]))?"`"===e&&(c=e):c=e:c=o:c=i,null!=c&&(s[s.length-1]===c?("`"===c&&(a=!1),s.pop()):("`"===c&&(a=!0),s.push(c)),r+=c.length-1)}t+=s.reverse().join("")}return t}function j(e,t){e=e.trim(),!1!==t&&(e=e.replace(/(\n *```)?$/,"{{USERFLOWCHATBRAIN}}$1"));let s=o.sanitize(i.parse(e));if(!1!==t){let e="userflowjs-assistant-chat__brain";t&&(e+=` userflowjs-assistant-chat__brain--${t}`),s=s.replace("{{USERFLOWCHATBRAIN}}",`<span class="${e}"><span></span><span></span><span></span><span></span></span>`)}return s}const _=({block:s,session:a,assistant:n,initialUserContent:r})=>{const o=s.assistantFlowId,i=t(),c=function({assistant:t,lookupAttribute:s,initialUserContent:a,submitMessage:n,submitRating:r,submitFeedback:o}){const i=e.useRef(null),[c,l]=e.useState(null),[u,m]=e.useState(b),[d,f]=e.useState(""),p=e.useRef(null),g=e.useRef(null),h=e.useRef(!0),_=e.useCallback((()=>{c?.focus({preventScroll:!0})}),[c]);e.useEffect((()=>{_()}),[_]);const v=e.useCallback((()=>{const e=g.current;e&&(h.current=!0,e.scrollTo({top:Math.ceil(e.scrollHeight-e.clientHeight),behavior:"smooth"}))}),[]),E=e.useRef(0);e.useLayoutEffect((()=>{const e=g.current;e&&e.scrollHeight!==E.current&&(E.current=e.scrollHeight,h.current&&v())}),[u,v]);const w=e.useCallback((()=>{p.current&&p.current()}),[]);e.useEffect((()=>()=>{w()}),[w]);const C=(e,t)=>{m((s=>s.map((s=>{if(e===s.id){const e=t(s);return{...s,...e}}return s}))))},I=e=>{m((t=>t.map(((s,a)=>{if(a===t.length-1){const t=e(s);return{...s,...t}}return s}))))},S=e.useCallback((async e=>{if(""===(e=e.trim()))return;w(),m((t=>[...t,{userContent:e,assistantContent:"",assistantHtml:j("","enter")}])),f(""),v();let t=!1;const s=()=>{t=!0,p.current=null},a=n({conversationId:i.current,userContent:e,callback:e=>{if(t)console.log("Userflow.js AssistantChat got message after being done",e);else switch(e.kind){case"conversation_created":i.current=e.conversationId;break;case"message_created":I((()=>({id:e.messageId})));break;case"assistant_content_delta":I((t=>{const s=e.delta,a=t.assistantContent+s;return{assistantContent:a,assistantHtml:j(k(a))}}));break;case"done":s(),I((t=>({assistantHtml:j(t.assistantContent,"exit"),completed:!0,sources:e.sources})));break;case"error":s(),I((t=>({failed:!0,error:e.message,assistantHtml:j(k(t.assistantContent),!1)})));break;default:console.log("Userflow.js AssistantChat got unknown message",e)}}});p.current=()=>{s(),a.abort(),I((e=>({assistantHtml:j(k(e.assistantContent),!1)})))}}),[w,v,n]),y=e.useRef(!1);e.useEffect((()=>{y.current||(y.current=!0,a&&S(a))}),[S,a]);const N=e.useCallback((()=>{w(),i.current=null,m(b),_()}),[w,_]),R=e.useCallback((()=>{const e=g.current;e&&(h.current=Math.ceil(e.scrollHeight-e.clientHeight)==Math.ceil(e.scrollTop))}),[]);return{assistant:t,lookupAttribute:s,history:u,setInput:l,contentElRef:g,userContent:d,setUserContent:f,onSubmitMessage:S,supportsFeedback:!!r&&!!o,onSubmitRating:e=>{r&&(C(e.messageId,(()=>({rating:e.rating}))),r(e))},onSubmitFeedback:e=>{o&&(C(e.messageId,(()=>({feedbackSubmitted:!0}))),o(e))},reset:N,onContentMouseWheel:R}}(e.useMemo((()=>({assistant:n,lookupAttribute:p(a.data),initialUserContent:r,submitMessage:({conversationId:e,userContent:t,callback:s})=>{i.assistantMessageInProgress=!0,i.send({kind:"SubmitAssistantMessage",assistantFlowId:o,conversationId:e,userContent:t});const a=()=>{i.assistantMessageInProgress=void 0,i.off("private:assistantMessageEvent",n),i.off("private:disconnect",r)},n=({event:e})=>{s(e),"done"!=e.kind&&"error"!=e.kind||a()},r=()=>{s({kind:"error",message:"Sorry, my connection got disconnected. Please try again or contact my human friends."}),a()};return i.on("private:assistantMessageEvent",n),i.on("private:disconnect",r),{abort:()=>{i.send({kind:"AbortAssistantMessage"}),a()}}},submitRating:e=>{i.send({kind:"SubmitAssistantRating",messageId:e.messageId,rating:e.rating})},submitFeedback:e=>{i.send({kind:"SubmitAssistantFeedback",messageId:e.messageId,feedback:e.feedback})}})),[n,o,i,r,a.data]));return e.createElement(e.Fragment,null,e.createElement(g,{...c}))};export{_ as ResourceCenterAssistantChat};
1
+ import{r as e}from"./vendor.react.js";import{u as t}from"./client-context.js";import{y as s,z as a,A as n}from"./vendor.fortawesome.pro-regular-svg-icons.js";import{F as r}from"./vendor.fortawesome.react-fontawesome.js";import{p as o}from"./vendor.dompurify.js";import{m as i}from"./vendor.marked.js";import{o as l}from"./vendor.obj-str.js";import{Q as c,p as u}from"./userflow.js";import{A as m,G as d}from"./ResourceCenterApp.js";import{r as f,R as p}from"./BubbleToolbar.js";import{a as b}from"./flow-condition-types.js";import"./vendor.object-assign.js";import"./vendor.i18next.js";import"./vendor.react-i18next.js";import"./vendor.babel.runtime.js";import"./vendor.fortawesome.fontawesome-svg-core.js";import"./vendor.prop-types.js";import"./vendor.phoenix.js";import"./vendor.uuid.js";import"./Icons.js";import"./stylesheets.js";import"./logomark.js";import"./vendor.react-dom.js";import"./vendor.scheduler.js";import"./DynamicIcon.js";import"./vendor.fortawesome.pro-solid-svg-icons.js";import"./ChecklistUI.js";import"./vendor.date-fns.js";const g=[];const h=({assistant:t,lookupAttribute:s,history:a,setInput:n,contentElRef:r,scrolledToTop:o,userContent:i,setUserContent:c,onSubmitMessage:u,supportsFeedback:d,onSubmitRating:b,onSubmitFeedback:g,reset:h,onContentScroll:v,onContentWheel:j})=>e.createElement("div",{className:"userflowjs-assistant-chat"},e.createElement("div",{className:l({"userflowjs-assistant-chat__header":!0,"userflowjs-assistant-chat__header--content-scrolled":!o})},e.createElement("h2",{className:"userflowjs-assistant-chat__title"},t.title),e.createElement("button",{className:"userflowjs-bubble-button userflowjs-bubble-button--default",onClick:h},t.resetText)),e.createElement("div",{ref:r,className:"userflowjs-assistant-chat__content",onScroll:v,onWheel:j},!f(t.intro)&&e.createElement("div",{className:"userflowjs-assistant-chat__intro"},e.createElement(p,{doc:t.intro,lookupAttribute:s})),a.map(((s,a)=>e.createElement(k,{key:a,assistant:t,message:s,supportsFeedback:d,onSubmitRating:b,onSubmitFeedback:g})))),e.createElement("div",{className:"userflowjs-assistant-chat__prompt"},e.createElement(m,{textareaRef:n,placeholder:(0===a.length?t.promptEmptyPlaceholder:t.promptNonemptyPlaceholder)||"",value:i,onChange:c,onSubmit:()=>u(i)}))),k=({assistant:t,message:o,supportsFeedback:i,onSubmitRating:u,onSubmitFeedback:m})=>{const f=e.useRef(null),[p,b]=e.useState(""),g=()=>{o.id&&(m({messageId:o.id,feedback:p.trim()}),b(""))};return e.useEffect((()=>{o.rating&&f.current?.focus({preventScroll:!0})}),[o.rating]),e.createElement("div",null,e.createElement("div",{className:l({"userflowjs-assistant-chat__user-content":!0,"userflowjs-assistant-chat__user-content--enter":!!o.enterAnimation})},e.createElement("div",{style:{whiteSpace:"pre-wrap"}},o.userContent)),e.createElement("div",{className:"userflowjs-assistant-chat__assistant-content"},e.createElement("div",{dangerouslySetInnerHTML:{__html:o.assistantHtml||""}}),o.error&&e.createElement("div",{className:"userflowjs-assistant-chat__error"},o.error)),o.sources&&o.sources.length>0&&e.createElement("div",{className:"userflowjs-assistant-chat__sources"},e.createElement("div",{className:"userflowjs-assistant-chat__sources-title"},t.sourcesText),o.sources.map(((t,s)=>e.createElement("a",{key:s,className:"userflowjs-assistant-chat__source",href:t.url,target:"_blank",rel:"noreferrer noopener"},t.title)))),i&&o.completed&&o.id&&e.createElement("div",{className:l({"userflowjs-assistant-chat__feedback":!0,"userflowjs-assistant-chat__feedback--with-textarea":!!o.rating&&!o.feedbackSubmitted})},o.feedbackSubmitted?e.createElement(e.Fragment,null,e.createElement("button",{className:"userflowjs-assistant-chat__rating",disabled:!0},e.createElement(r,{icon:o.rating==c.DISLIKE?s:a})),e.createElement("div",{className:"userflowjs-assistant-chat__feedback-thanks"},t.feedbackThanksText)):o.rating?e.createElement(d,{textareaRef:f,className:"userflowjs-growing-textarea userflowjs-assistant-chat__feedback-textarea",mirrorClassName:"userflowjs-growing-textarea__mirror",textareaClassName:"userflowjs-textarea",placeholder:(o.rating===c.LIKE?t.feedbackLikePlaceholder:t.feedbackDislikePlaceholder)||"",value:p,onChange:b,onKeyDown:e=>{e.shiftKey||"Enter"!==e.key||(e.preventDefault(),g())}},e.createElement("button",{className:"userflowjs-assistant-chat__rating",disabled:!0},e.createElement(r,{icon:o.rating==c.DISLIKE?s:a})),e.createElement("button",{className:"userflowjs-assistant-chat__feedback-submit",onClick:()=>g()},e.createElement(r,{icon:n}))):[c.LIKE,c.DISLIKE].map((t=>(!o.rating||o.rating===t)&&e.createElement("button",{key:t,className:"userflowjs-assistant-chat__rating",onClick:o.rating?void 0:()=>(e=>{o.id&&u({messageId:o.id,rating:e})})(t),disabled:!!o.rating},e.createElement(r,{icon:t==c.DISLIKE?s:a}))))))};function v(e){let t=e;const s=e=>e=(e=e.replace(/\s*[*_`]*$/,"")).replace(/(^|\n)\s*(\d+\.?|-|=)$/,"");t=s(t),t=t.replace(/\[[^\]\n]*(\](\([^)\n]*\)?)?)?$/,""),t=s(t);const a=Array.from(t.matchAll(/\n( *)```/g));if(a.length%2==1){t+="\n"+a[a.length-1][1]+"```"}else{let e=0;for(let r=t.length-1;r>=0;r--)if("\n"===t[r]&&"\n"===t[r-1]){e=r;break}const s=[];let a=!1;const n=e=>null==e||e.match(/\W/);for(let r=e;r<t.length;r++){const e=t[r],o=e+t[r+1],i=o+t[r+2];let l=null;(a||"***"!==i)&&(a||"___"!==i||!n(t[r-1])&&!n(t[r+3]))?(a||"**"!==o)&&(a||"__"!==o||!n(t[r-1])&&!n(t[r+2]))?(a||"*"!==e)&&(a||"_"!==e||!n(t[r-1])&&!n(t[r+1]))?"`"===e&&(l=e):l=e:l=o:l=i,null!=l&&(s[s.length-1]===l?("`"===l&&(a=!1),s.pop()):("`"===l&&(a=!0),s.push(l)),r+=l.length-1)}t+=s.reverse().join("")}return t}function j(e,t){e=e.trim(),!1!==t&&(e=e.replace(/(\n *```)?$/,"{{USERFLOWCHATBRAIN}}$1"));let s=o.sanitize(i.parse(e));if(!1!==t){let e="userflowjs-assistant-chat__brain";t&&(e+=` userflowjs-assistant-chat__brain--${t}`),s=s.replace("{{USERFLOWCHATBRAIN}}",`<span class="${e}"><span></span><span></span><span></span><span></span></span>`)}return s}const _=({block:s,session:a,assistantReply:n,initialUserContent:r})=>{const o=s.assistantFlowId,i=t(),l=function({assistant:t,lookupAttribute:s,initialConversationId:a,initialHistory:n,initialUserContent:r,onConversationIdChange:o,submitMessage:i,submitRating:l,submitFeedback:c}){const[u,m]=e.useState(null),[d,f]=e.useState((()=>n?n.map((e=>({...e,assistantHtml:j(v(e.assistantContent),!1)}))):g)),[p,b]=e.useState(""),h=e.useRef(null),k=e.useRef(null),_=e.useRef(!0),E=e.useRef(a||null),C=e.useCallback((e=>{E.current=e,o&&o(e)}),[o]),w=e.useCallback((()=>{u?.focus({preventScroll:!0})}),[u]);e.useEffect((()=>{w()}),[w]),e.useLayoutEffect((()=>{const e=k.current;e&&(e.scrollTop=Math.ceil(e.scrollHeight-e.clientHeight))}),[]);const I=e.useCallback((()=>{const e=k.current;e&&(_.current=!0,e.scrollTo({top:Math.ceil(e.scrollHeight-e.clientHeight),behavior:"smooth"}))}),[]),S=e.useRef(0);e.useLayoutEffect((()=>{const e=k.current;e&&e.scrollHeight!==S.current&&(S.current=e.scrollHeight,_.current&&I())}),[d,I]);const y=e.useCallback((()=>{h.current&&h.current()}),[]);e.useEffect((()=>()=>{y()}),[y]);const N=(e,t)=>{f((s=>s.map((s=>{if(e===s.id){const e=t(s);return{...s,...e}}return s}))))},R=e=>{f((t=>t.map(((s,a)=>{if(a===t.length-1){const t=e(s);return{...s,...t}}return s}))))},A=e.useCallback((async e=>{if(""===(e=e.trim()))return;y(),f((t=>[...t,{id:null,userContent:e,assistantContent:"",assistantHtml:j("","enter"),enterAnimation:!0,sources:[],completed:!1,rating:null,feedbackSubmitted:!1}])),b(""),I();let t=!1;const s=()=>{t=!0,h.current=null},a=i({conversationId:E.current,userContent:e,callback:e=>{if(t)console.log("Userflow.js AssistantChat got message after being done",e);else switch(e.kind){case"conversation_created":C(e.conversationId);break;case"message_created":R((()=>({id:e.messageId})));break;case"assistant_content_delta":R((t=>{const s=e.delta,a=t.assistantContent+s;return{assistantContent:a,assistantHtml:j(v(a))}}));break;case"done":s(),R((t=>({assistantHtml:j(t.assistantContent,"exit"),completed:!0,sources:e.sources})));break;case"error":s(),R((t=>({failed:!0,error:e.message,assistantHtml:j(v(t.assistantContent),!1)})));break;default:console.log("Userflow.js AssistantChat got unknown message",e)}}});h.current=()=>{s(),a.abort(),R((e=>({assistantHtml:j(v(e.assistantContent),!1)})))}}),[y,I,i,C]),H=e.useRef(!1);e.useEffect((()=>{H.current||(H.current=!0,r&&A(r))}),[A,r]);const F=e.useCallback((()=>{y(),C(null),f(g),w()}),[y,w,C]),[x,M]=e.useState(!0),T=e.useCallback((()=>{const e=k.current;e&&M(0===e.scrollTop)}),[]),L=e.useCallback((()=>{const e=k.current;e&&(_.current=Math.ceil(e.scrollHeight-e.clientHeight)==Math.ceil(e.scrollTop))}),[]);return{assistant:t,lookupAttribute:s,history:d,setInput:m,contentElRef:k,scrolledToTop:x,userContent:p,setUserContent:b,onSubmitMessage:A,supportsFeedback:!!l&&!!c,onSubmitRating:e=>{l&&(N(e.messageId,(()=>({rating:e.rating}))),l(e))},onSubmitFeedback:e=>{c&&(N(e.messageId,(()=>({feedbackSubmitted:!0}))),c(e))},reset:F,onContentScroll:T,onContentWheel:L}}(e.useMemo((()=>({assistant:n.assistant,lookupAttribute:b(a.data),initialConversationId:n.conversationId,initialHistory:n.history,initialUserContent:r,onConversationIdChange:e=>{const t="assistantConversationId:"+o;e?u.setItem(t,e):u.removeItem(t)},submitMessage:({conversationId:e,userContent:t,callback:s})=>{i.assistantMessageInProgress=!0,i.send({kind:"SubmitAssistantMessage",assistantFlowId:o,conversationId:e,userContent:t});const a=()=>{i.assistantMessageInProgress=void 0,i.off("private:assistantMessageEvent",n),i.off("private:disconnect",r)},n=({event:e})=>{s(e),"done"!=e.kind&&"error"!=e.kind||a()},r=()=>{s({kind:"error",message:"Sorry, my connection got disconnected. Please try again or contact my human friends."}),a()};return i.on("private:assistantMessageEvent",n),i.on("private:disconnect",r),{abort:()=>{i.send({kind:"AbortAssistantMessage"}),a()}}},submitRating:e=>{i.send({kind:"SubmitAssistantRating",messageId:e.messageId,rating:e.rating})},submitFeedback:e=>{i.send({kind:"SubmitAssistantFeedback",messageId:e.messageId,feedback:e.feedback})}})),[n,o,i,r,a.data]));return e.createElement(e.Fragment,null,e.createElement(h,{...l}))};export{_ as ResourceCenterAssistantChat};
@@ -1 +1 @@
1
- import{r as e}from"./vendor.react.js";import{u as t}from"./client-context.js";import{B as r}from"./BuilderBar.js";import{c as o}from"./flow-condition-types.js";import{w as s}from"./userflow.js";import"./vendor.object-assign.js";import"./vendor.i18next.js";import"./vendor.react-i18next.js";import"./vendor.babel.runtime.js";import"./logomark.js";import"./vendor.react-dom.js";import"./vendor.scheduler.js";import"./stylesheets.js";import"./vendor.obj-str.js";import"./vendor.fortawesome.pro-light-svg-icons.js";import"./DynamicIcon.js";import"./vendor.fortawesome.pro-regular-svg-icons.js";import"./vendor.fortawesome.pro-solid-svg-icons.js";import"./vendor.date-fns.js";import"./vendor.phoenix.js";import"./vendor.uuid.js";const n=({state:n})=>{const i=t(),[a,c]=e.useState("notIdentified");e.useEffect((()=>{let e,t,r=!1;const a=async()=>{c("trackerLoading");const{tracker:e}=await i.send({kind:"GetTrackerForTesting",token:n.token});if(r)return;const{condition:a}=e,d=o[a.type];let l=!1;t=d.track({sessionData:new s(e.data),condition:a,flipBackEvents:!0,callback:e=>{const t=l;l=e,!t&&e&&i.setSessionStorageState((e=>({...e,trackerTesting:{...e.trackerTesting,events:e.trackerTesting.events+1}})))}}),c("trackerLoaded")};return e=()=>{i.off("private:identified",e),a()},i.isIdentified()?e():i.on("private:identified",e),()=>{r=!0,e&&i.off("private:identified",e),t&&t()}}),[i,n.token]);const d=e.useCallback((async()=>{i.setSessionStorageState((e=>({...e,activeApp:null,trackerTesting:null}))),i.getTargetEnv().postBuilderMessage({kind:"userflow:testTrackerClosed"})}),[i]);return e.createElement(r,{buttons:e.createElement("button",{className:"btn btn--default",onClick:()=>d()},"Back to Builder")},e.createElement("div",null,e.createElement("div",{className:"label"},"Testing tracker: ",n.trackerName),"notIdentified"===a?e.createElement("div",null,"Waiting for your app to identify user..."):"trackerLoading"===a?e.createElement("div",null,"Loading tracker..."):0===n.events?e.createElement("div",{className:"error"},"Not tracked yet"):e.createElement("div",{className:"success"},"Tracked ",n.events," time",1===n.events?"":"s")))};export default n;export{n as TrackerTestingApp};
1
+ import{r as e}from"./vendor.react.js";import{u as t}from"./client-context.js";import{B as r}from"./BuilderBar.js";import{c as o}from"./flow-condition-types.js";import{x as s}from"./userflow.js";import"./vendor.object-assign.js";import"./vendor.i18next.js";import"./vendor.react-i18next.js";import"./vendor.babel.runtime.js";import"./logomark.js";import"./vendor.react-dom.js";import"./vendor.scheduler.js";import"./stylesheets.js";import"./vendor.obj-str.js";import"./vendor.fortawesome.pro-light-svg-icons.js";import"./DynamicIcon.js";import"./vendor.fortawesome.pro-regular-svg-icons.js";import"./vendor.fortawesome.pro-solid-svg-icons.js";import"./vendor.date-fns.js";import"./vendor.phoenix.js";import"./vendor.uuid.js";const n=({state:n})=>{const i=t(),[a,c]=e.useState("notIdentified");e.useEffect((()=>{let e,t,r=!1;const a=async()=>{c("trackerLoading");const{tracker:e}=await i.send({kind:"GetTrackerForTesting",token:n.token});if(r)return;const{condition:a}=e,d=o[a.type];let l=!1;t=d.track({sessionData:new s(e.data),condition:a,flipBackEvents:!0,callback:e=>{const t=l;l=e,!t&&e&&i.setSessionStorageState((e=>({...e,trackerTesting:{...e.trackerTesting,events:e.trackerTesting.events+1}})))}}),c("trackerLoaded")};return e=()=>{i.off("private:identified",e),a()},i.isIdentified()?e():i.on("private:identified",e),()=>{r=!0,e&&i.off("private:identified",e),t&&t()}}),[i,n.token]);const d=e.useCallback((async()=>{i.setSessionStorageState((e=>({...e,activeApp:null,trackerTesting:null}))),i.getTargetEnv().postBuilderMessage({kind:"userflow:testTrackerClosed"})}),[i]);return e.createElement(r,{buttons:e.createElement("button",{className:"btn btn--default",onClick:()=>d()},"Back to Builder")},e.createElement("div",null,e.createElement("div",{className:"label"},"Testing tracker: ",n.trackerName),"notIdentified"===a?e.createElement("div",null,"Waiting for your app to identify user..."):"trackerLoading"===a?e.createElement("div",null,"Loading tracker..."):0===n.events?e.createElement("div",{className:"error"},"Not tracked yet"):e.createElement("div",{className:"success"},"Tracked ",n.events," time",1===n.events?"":"s")))};export default n;export{n as TrackerTestingApp};
package/bubble-frame.css CHANGED
@@ -1644,7 +1644,10 @@ a.userflowjs-resource-center-block--clickable:hover {
1644
1644
  display: flex;
1645
1645
  align-items: center;
1646
1646
  padding: 1rem;
1647
- padding-bottom: 0.5rem;
1647
+ border-bottom: 1px solid transparent;
1648
+ }
1649
+ .userflowjs-assistant-chat__header--content-scrolled {
1650
+ border-bottom-color: rgba(var(--userflow-main-foreground-color-rgb), 0.15);
1648
1651
  }
1649
1652
  .userflowjs-assistant-chat__title {
1650
1653
  min-width: 0;
@@ -1656,7 +1659,7 @@ a.userflowjs-resource-center-block--clickable:hover {
1656
1659
  min-width: 0;
1657
1660
  flex: 1 1 0%;
1658
1661
  padding: 1rem;
1659
- padding-top: 0.5rem;
1662
+ padding-top: 0;
1660
1663
  overflow-y: auto;
1661
1664
  }
1662
1665
  .userflowjs-assistant-chat__content > *:not(:last-child) {
@@ -1681,6 +1684,8 @@ a.userflowjs-resource-center-block--clickable:hover {
1681
1684
  padding: 0.5rem 1rem;
1682
1685
  margin-left: 2rem;
1683
1686
  margin-bottom: 1rem;
1687
+ }
1688
+ .userflowjs-assistant-chat__user-content--enter {
1684
1689
  animation: userflowjs-assistant-chat-user-content-enter 300ms cubic-bezier(0.25, 0.8, 0.5, 1) both;
1685
1690
  }
1686
1691
  .userflowjs-assistant-chat__assistant-content {
package/hash.txt CHANGED
@@ -1 +1 @@
1
- 17338f0505acc126f02b0c712fbda458b19fa0d9
1
+ f44f3f44306490e44d197164ac5058db190b7732
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "userflow.js-self-hosted",
3
- "version": "0.1.1002856",
3
+ "version": "0.1.1002863",
4
4
  "description": "Self-hosted version of Userflow.js",
5
5
  "main": "userflow.js"
6
6
  }
package/stylesheets.js CHANGED
@@ -1 +1 @@
1
- import{r as o}from"./vendor.react.js";import{w as r,B as t,A as e,x as n}from"./userflow.js";import{c as u}from"./flow-condition-types.js";import{a as l}from"./client-context.js";function a(t){const[e]=o.useState((()=>new r(t)));return e.update(t),e}function c(o){return o?o.match(/^#[0-9a-f]{6}$/i)?[parseInt(o.substring(1,3),16),parseInt(o.substring(3,5),16),parseInt(o.substring(5,7),16)]:o.match(/^#[0-9a-f]{3}$/i)?[parseInt(o.substring(1,2).repeat(2),16),parseInt(o.substring(2,3).repeat(2),16),parseInt(o.substring(3,4).repeat(2),16)]:[0,0,0]:[0,0,0]}function i([o,r,t]){return"#"+o.toString(16).padStart(2,"0")+r.toString(16).padStart(2,"0")+t.toString(16).padStart(2,"0")}function d(o){const r=c(o);return r?r.join(", "):"0, 0, 0"}function s(o){return i(c(o))}function f(o,r,t){return[Math.max(0,Math.min(255,Math.round(o[0]+(r[0]-o[0])*t))),Math.max(0,Math.min(255,Math.round(o[1]+(r[1]-o[1])*t))),Math.max(0,Math.min(255,Math.round(o[2]+(r[2]-o[2])*t)))]}function h(o,r,t){const e=c(o),n=c(r);return e&&n?i(f(e,n,t)):o}function g([o,r,t]){o/=255,r/=255,t/=255;const e=Math.max(o,r,t),n=Math.min(o,r,t);let u,l,a=(e+n)/2;if(e==n)u=l=0;else{const c=e-n;switch(l=a>.5?c/(2-e-n):c/(e+n),e){case o:u=(r-t)/c+(r<t?6:0);break;case r:u=(t-o)/c+2;break;default:u=(o-r)/c+4}u/=6}return[u,l,a]}function B([o,r,t]){let e=r/255,n=t/255;function u(o){let r=0;return r=o<=.04045?o/12.92:Math.pow((o+.055)/1.055,2.4),r}let l=.2126*u(o/255)+.7152*u(e)+.0722*u(n);return Math.round(10*function(o){let r=0;return r=o<=216/24389?o*(24389/27):116*Math.pow(o,1/3)-16,r}(l))/1e3}function C(o,r){const t=B(o),e=B(r);let n=.13*((1-(e-t))/2)+.05,u=1-Math.abs(e-t),l=n+Math.pow((1-n)*u,4);return Math.round(1e3*l)/1e3}function b(o,r){const t=c(o),e=g(t);let n=null,u=null;for(const i of r){const o=c(i),r=g(o);let t=!1;if(n&&u){const o=.3;Math.abs(r[2]-e[2])>o?r[1]>u[1]&&(t=!0):Math.abs(e[2]-r[2])>Math.abs(e[2]-u[2])&&(t=!0)}else t=!0;t&&(n=o,u=r)}let l=n,a=n,d=C(l,t),s=2*d;return e[2]>.2&&e[2]<.8&&(a=function([o,r,t]){return[Math.round(255-o),Math.round(255-r),Math.round(255-t)]}(a),s=C(a,t)),[i(f(t,l,d)),i(f(t,a,s))]}function k(o){const[r,t,e,n,u,l,a,i]=function(o,r,t,e){const[n,u]=b(o,[r]);let l,a;if(o===t)l=n,a=u;else{const n=b(t,[o,r,e]);l=n[0],a=n[1]}const i=c(o),d=c(t);let s,f,h,g;if(Math.abs(i[0]-d[0])<20&&Math.abs(i[1]-d[1])<20&&Math.abs(i[2]-d[2])<20){s=r,f=o;const t=b(s,[f]);h=t[0],g=t[1]}else s=o,f=r,h=n,g=u;return[n,u,l,a,s,f,h,g]}(o.brandBackgroundColor,o.brandForegroundColor,o.mainBackgroundColor,o.mainForegroundColor),d={...o,widgetBackgroundColor:u,widgetForegroundColor:l,widgetHoverBackgroundColor:a,widgetActiveBackgroundColor:i,sameBackground:s(o.mainBackgroundColor)==s(o.brandBackgroundColor)};if(d.brandHoverBackgroundColor&&(d.widgetHoverBackgroundColor=d.brandHoverBackgroundColor),d.brandActiveBackgroundColor&&(d.widgetActiveBackgroundColor=d.brandActiveBackgroundColor),d.brandHoverBackgroundColor||(d.brandHoverBackgroundColor=r),d.brandActiveBackgroundColor||(d.brandActiveBackgroundColor=t),d.mainHoverBackgroundColor||(d.mainHoverBackgroundColor=e),d.mainActiveBackgroundColor||(d.mainActiveBackgroundColor=n),d.bubbleBorderColor||(d.bubbleBorderColor=d.mainForegroundColor),d.checklistLauncherActiveBackgroundColor||(d.checklistLauncherActiveBackgroundColor=d.brandActiveBackgroundColor),d.checklistLauncherBackgroundColor||(d.checklistLauncherBackgroundColor=d.brandBackgroundColor),d.checklistLauncherCounterBackgroundColor||(d.checklistLauncherCounterBackgroundColor=d.brandForegroundColor),d.checklistLauncherCounterFontColor||(d.checklistLauncherCounterFontColor=d.brandBackgroundColor),d.checklistLauncherFontColor||(d.checklistLauncherFontColor=d.brandForegroundColor),d.checklistLauncherHoverBackgroundColor||(d.checklistLauncherHoverBackgroundColor=d.brandHoverBackgroundColor),d.focusColor||(d.focusColor=d.mainActiveBackgroundColor),d.launcherIconActiveColor||(d.launcherIconActiveColor=d.brandActiveBackgroundColor),d.launcherIconColor||(d.launcherIconColor=d.brandBackgroundColor),d.launcherIconHoverColor||(d.launcherIconHoverColor=d.brandHoverBackgroundColor),d.linkColor||(d.linkColor=d.widgetBackgroundColor),d.progressBarColor||(d.progressBarColor=d.widgetBackgroundColor),d.questionColor||(d.questionColor=d.widgetBackgroundColor),d.toolbarForegroundColor||(d.toolbarForegroundColor=d.mainForegroundColor),d.primaryButtonBackgroundColor||(d.primaryButtonBackgroundColor=d.widgetBackgroundColor),d.primaryButtonFontColor||(d.primaryButtonFontColor=d.widgetForegroundColor),d.primaryButtonHoverFontColor||(d.primaryButtonHoverFontColor=d.primaryButtonFontColor),d.primaryButtonActiveFontColor||(d.primaryButtonActiveFontColor=d.primaryButtonFontColor),!d.primaryButtonHoverBackgroundColor||!d.primaryButtonActiveBackgroundColor){const[o,r]=b(d.primaryButtonBackgroundColor,[d.primaryButtonFontColor]);d.primaryButtonHoverBackgroundColor||(d.primaryButtonHoverBackgroundColor=o),d.primaryButtonActiveBackgroundColor||(d.primaryButtonActiveBackgroundColor=r)}if(d.primaryButtonBorderColor||(d.primaryButtonBorderColor=d.widgetBackgroundColor),d.primaryButtonHoverBorderColor||(d.primaryButtonHoverBorderColor=d.primaryButtonHoverBackgroundColor),d.primaryButtonActiveBorderColor||(d.primaryButtonActiveBorderColor=d.primaryButtonActiveBackgroundColor),d.defaultButtonBackgroundColor||(d.defaultButtonBackgroundColor=d.mainBackgroundColor),d.defaultButtonFontColor||(d.defaultButtonFontColor=u),d.defaultButtonHoverFontColor||(d.defaultButtonHoverFontColor=d.defaultButtonFontColor),d.defaultButtonActiveFontColor||(d.defaultButtonActiveFontColor=d.defaultButtonFontColor),!d.defaultButtonHoverBackgroundColor||!d.defaultButtonActiveBackgroundColor){const[o,r]=b(d.defaultButtonBackgroundColor,[d.defaultButtonFontColor]);d.defaultButtonHoverBackgroundColor||(d.defaultButtonHoverBackgroundColor=o),d.defaultButtonActiveBackgroundColor||(d.defaultButtonActiveBackgroundColor=r)}return d.defaultButtonBorderColor||(d.defaultButtonBorderColor=d.defaultButtonFontColor),d.defaultButtonHoverBorderColor||(d.defaultButtonHoverBorderColor=d.defaultButtonBorderColor),d.defaultButtonActiveBorderColor||(d.defaultButtonActiveBorderColor=d.defaultButtonBorderColor),d.launcherButtonBackgroundColor||(d.launcherButtonBackgroundColor=d.brandBackgroundColor),d.launcherButtonBorderColor||(d.launcherButtonBorderColor=d.brandBackgroundColor),d.launcherButtonFontColor||(d.launcherButtonFontColor=d.brandForegroundColor),d.launcherButtonHoverBackgroundColor||(d.launcherButtonHoverBackgroundColor=d.brandHoverBackgroundColor),d.launcherButtonHoverBorderColor||(d.launcherButtonHoverBorderColor=d.launcherButtonHoverBackgroundColor),d.launcherButtonHoverFontColor||(d.launcherButtonHoverFontColor=d.launcherButtonFontColor),d.launcherButtonActiveBackgroundColor||(d.launcherButtonActiveBackgroundColor=d.brandActiveBackgroundColor),d.launcherButtonActiveBorderColor||(d.launcherButtonActiveBorderColor=d.launcherButtonActiveBackgroundColor),d.launcherButtonActiveFontColor||(d.launcherButtonActiveFontColor=d.launcherButtonFontColor),d}function w(o){const{questionColor:r}=o;return{"--userflow-backdrop-highlight-color-rgb":d(o.backdropHighlightColor),"--userflow-backdrop-highlight-inset":o.backdropHighlightType===t.INSIDE?"inset":"","--userflow-backdrop-highlight-opacity":o.backdropHighlightOpacity,"--userflow-backdrop-highlight-radius":o.backdropHighlightRadius+"px","--userflow-backdrop-highlight-spread":o.backdropHighlightSpread+"px","--userflow-backdrop-opacity":o.backdropOpacity,"--userflow-beacon-color":o.beaconColor,"--userflow-brand-active-background-color":o.brandActiveBackgroundColor,"--userflow-brand-background-color":o.brandBackgroundColor,"--userflow-brand-foreground-color":o.brandForegroundColor,"--userflow-brand-foreground-color-rgb":d(o.brandForegroundColor),"--userflow-brand-hover-background-color":o.brandHoverBackgroundColor,"--userflow-bubble-border-color":o.bubbleBorderColor,"--userflow-bubble-border-radius":o.bubbleBorderRadius+"px","--userflow-bubble-border-width":o.bubbleBorderWidth+"px","--userflow-button-border-radius":o.buttonBorderRadius+"px","--userflow-button-height":o.buttonHeight+"px","--userflow-button-min-width":o.buttonMinWidth+"px","--userflow-button-text-align":0===o.buttonMinWidth?"start":"center","--userflow-buttons-justify-content":"left"===o.buttonHorizontalAlign?"flex-start":"center"===o.buttonHorizontalAlign?"center":"flex-end","--userflow-buttons-modal-justify-content":"left"===o.buttonHorizontalAlign?"flex-start":"right"===o.buttonHorizontalAlign?"flex-end":"center","--userflow-checklist-launcher-active-background-color":o.checklistLauncherActiveBackgroundColor,"--userflow-checklist-launcher-background-color":o.checklistLauncherBackgroundColor,"--userflow-checklist-launcher-border-radius":o.checklistLauncherBorderRadius+"px","--userflow-checklist-launcher-counter-background-color":o.checklistLauncherCounterBackgroundColor,"--userflow-checklist-launcher-counter-font-color":o.checklistLauncherCounterFontColor,"--userflow-checklist-launcher-font-color-rgb":d(o.checklistLauncherFontColor),"--userflow-checklist-launcher-font-color":o.checklistLauncherFontColor,"--userflow-checklist-launcher-font-weight":String(o.checklistLauncherFontWeight),"--userflow-checklist-launcher-height":o.checklistLauncherHeight+"px","--userflow-checklist-launcher-hover-background-color":o.checklistLauncherHoverBackgroundColor,"--userflow-checkmark-background-color":o.checkmarkBackgroundColor,"--userflow-completed-task-text-decoration":o.completedTaskTextDecoration,"--userflow-default-button-active-background-color":o.defaultButtonActiveBackgroundColor,"--userflow-default-button-active-border-color":o.defaultButtonActiveBorderColor,"--userflow-default-button-active-font-color":o.defaultButtonActiveFontColor,"--userflow-default-button-background-color":o.defaultButtonBackgroundColor,"--userflow-default-button-border-color":o.defaultButtonBorderColor,"--userflow-default-button-border-width":o.defaultButtonBorderWidth+"px","--userflow-default-button-font-color":o.defaultButtonFontColor,"--userflow-default-button-font-weight":String(o.defaultButtonFontWeight),"--userflow-default-button-hover-background-color":o.defaultButtonHoverBackgroundColor,"--userflow-default-button-hover-border-color":o.defaultButtonHoverBorderColor,"--userflow-default-button-hover-font-color":o.defaultButtonHoverFontColor,"--userflow-focus-color":`rgba(${d(o.focusColor)}, ${o.focusOpacity})`,"--userflow-font-family":o.builtinFontFamily?o.builtinFontFamily.name+(o.builtinFontFamily.fallback?", "+o.builtinFontFamily.fallback:""):o.fontFamily?o.fontFamily:"sans-serif","--userflow-font-size":o.fontSize+"px","--userflow-font-weight-bold":String(o.fontWeightBold),"--userflow-font-weight-normal":String(o.fontWeightNormal),"--userflow-h1-font-size":o.h1FontSize+"px","--userflow-h2-font-size":o.h2FontSize+"px","--userflow-launcher-button-active-background-color":o.launcherButtonActiveBackgroundColor,"--userflow-launcher-button-active-border-color":o.launcherButtonActiveBorderColor,"--userflow-launcher-button-active-font-color":o.launcherButtonActiveFontColor,"--userflow-launcher-button-background-color":o.launcherButtonBackgroundColor,"--userflow-launcher-button-border-color":o.launcherButtonBorderColor,"--userflow-launcher-button-border-radius":o.launcherButtonBorderRadius+"px","--userflow-launcher-button-border-width":o.launcherButtonBorderWidth+"px","--userflow-launcher-button-font-color":o.launcherButtonFontColor,"--userflow-launcher-button-font-weight":String(o.launcherButtonFontWeight),"--userflow-launcher-button-height":o.launcherButtonHeight+"px","--userflow-launcher-button-horizontal-padding":o.launcherButtonHorizontalPadding+"px","--userflow-launcher-button-hover-background-color":o.launcherButtonHoverBackgroundColor,"--userflow-launcher-button-hover-border-color":o.launcherButtonHoverBorderColor,"--userflow-launcher-button-hover-font-color":o.launcherButtonHoverFontColor,"--userflow-launcher-button-width":o.launcherButtonWidth?o.launcherButtonWidth+"px":"auto","--userflow-launcher-icon-active-color":o.launcherIconActiveColor,"--userflow-launcher-icon-color":o.launcherIconColor,"--userflow-launcher-icon-hover-color":o.launcherIconHoverColor,"--userflow-launcher-icon-opacity":o.launcherIconOpacity,"--userflow-launcher-icon-size":o.launcherIconSize+"px","--userflow-line-height":o.lineHeight+"px","--userflow-link-color":o.linkColor,"--userflow-main-active-background-color":o.mainActiveBackgroundColor,"--userflow-main-background-color":o.mainBackgroundColor,"--userflow-main-background-color-rgb":d(o.mainBackgroundColor),"--userflow-main-foreground-color":o.mainForegroundColor,"--userflow-main-foreground-color-rgb":d(o.mainForegroundColor),"--userflow-main-hover-background-color":o.mainHoverBackgroundColor,"--userflow-modal-padding":o.modalPadding+"px","--userflow-modal-padding-top":(o.avatarType===e.NONE?o.modalPadding:o.modalPadding+Math.max((o.avatarSize-o.modalPadding)/2,0))+"px","--userflow-backdrop-color-rgb":d(o.backdropColor),"--userflow-notch-color":o.bubbleBorderWidth>0&&o.bubbleBorderColor||o.mainBackgroundColor,"--userflow-primary-button-active-background-color":o.primaryButtonActiveBackgroundColor,"--userflow-primary-button-active-border-color":o.primaryButtonActiveBorderColor,"--userflow-primary-button-active-font-color":o.primaryButtonActiveFontColor,"--userflow-primary-button-background-color":o.primaryButtonBackgroundColor,"--userflow-primary-button-border-color":o.primaryButtonBorderColor,"--userflow-primary-button-border-width":o.primaryButtonBorderWidth+"px","--userflow-primary-button-font-color":o.primaryButtonFontColor,"--userflow-primary-button-font-weight":String(o.primaryButtonFontWeight),"--userflow-primary-button-hover-background-color":o.primaryButtonHoverBackgroundColor,"--userflow-primary-button-hover-border-color":o.primaryButtonHoverBorderColor,"--userflow-primary-button-hover-font-color":o.primaryButtonHoverFontColor,"--userflow-progress-bar-color":o.progressBarColor,"--userflow-progress-bar-height":o.progressBarHeight+"px","--userflow-resource-center-collapsed-height":o.resourceCenterCollapsedHeight+"px","--userflow-resource-center-launcher-border-radius":(null!=o.resourceCenterLauncherBorderRadius?o.resourceCenterLauncherBorderRadius:o.resourceCenterCollapsedHeight/2)+"px","--userflow-resource-center-padding-x":o.resourceCenterPaddingX+"px","--userflow-resource-center-padding-y":o.resourceCenterPaddingY+"px","--userflow-resource-center-transition-duration":o.resourceCenterTransitionDuration+"ms","--userflow-resource-center-width":o.resourceCenterWidth+"px","--userflow-question-color-light":h(r,o.mainBackgroundColor,.5),"--userflow-question-color-lighter":h(r,o.mainBackgroundColor,.75),"--userflow-question-color-lightest":h(r,o.mainBackgroundColor,.9),"--userflow-question-color-medium-light":h(r,o.mainBackgroundColor,.15),"--userflow-question-color":r,"--userflow-toolbar-foreground-color":o.toolbarForegroundColor,"--userflow-toolbar-foreground-color-rgb":d(o.toolbarForegroundColor),"--userflow-tooltip-notch-size":o.tooltipNotchSize+"px","--userflow-widget-active-background-color":o.widgetActiveBackgroundColor,"--userflow-widget-background-color":o.widgetBackgroundColor,"--userflow-widget-foreground-color":o.widgetForegroundColor,"--userflow-widget-hover-background-color":o.widgetHoverBackgroundColor}}const p=[];function m(r){let[t,e]=o.useState(r);const n=a(r.sessionData||p);return o.useLayoutEffect((()=>{const{variations:o}=r;if(!o)return;const t=[],l=[],a=()=>{let n=r,u=!1;for(const[r,e]of o.entries())if(t[r]){u||(u=!0,n={...n});for(const o of e.overriddenKeys)n[o]=e[o]}e(n)};for(const[r,e]of o.entries()){t[r]=!1;const{condition:o}=e;if(o&&e.overriddenKeys&&e.overriddenKeys.length>0){const e=u[o.type].track({sessionData:n,condition:o,callback:o=>{t[r]=o,a()}});l[r]=e}else l[r]=()=>{}}return a(),()=>{for(const o of l)o()}}),[r,n]),o.useMemo((()=>k(t)),[t])}const v=new Map;function y(o){let r=v.get(o);return r||(r={stylesheets:new Map},v.set(o,r)),r}function F(r,t,e){const n=l(),[u,a]=o.useState(!t);return o.useLayoutEffect((()=>{if(!r||!t)return;let o,u=!1;const l=async t=>{await x(n,r,t),o&&function(o,r){const t=y(o),e=t.stylesheets.get(r);if(!e)return;o.document.head.removeChild(e.link),t.stylesheets.delete(r)}(r,o),o=t};(async()=>{let o="string"==typeof t?t:t.get();if(window.MSInputMethodContext&&document.documentMode&&e){let r=await function(o){return new Promise(((r,t)=>{let e=H.get(o);if(e)return void r(e);const n=new XMLHttpRequest;n.addEventListener("load",(()=>{if(200!==n.status)return void t(new Error("Userflow.js could not fetch stylesheet: "+o));const e=n.responseText;H.set(o,e),r(e)})),n.addEventListener("error",(()=>{t(new Error("Userflow.js could not fetch stylesheet: "+o))})),n.open("GET",o),n.send()}))}(o);if(u)return;r=function(o,r){for(const t in r)if(r.hasOwnProperty(t)){const e=r[t];e&&(o=o.replace(new RegExp(`var\\(${t}.*?\\)`,"g"),e))}return o=o.replace(/var\(--[a-z0-9-]+(,\s*(.*?))?\)/g,"$2")}(r,w(e)),o="data:text/css;base64,"+btoa(r)}await l(o),u||a(!0)})();let c=null;return"string"!=typeof t&&(c=t.onUpdate((async()=>{l(t.get())}))),()=>{u=!0,c&&c()}}),[n,r,t,e]),{loaded:u}}const H=new Map;function A(r,t){const e=t&&function(o){if(!o.builtinFontFamily)return o.fontCssUrl?{url:o.fontCssUrl,fontFamily:o.fontFamily}:null;switch(o.builtinFontFamily.provider){case n.GOOGLE:{const r=Array.from(new Set(["0,400","1,400",`0,${o.fontWeightBold}`,`0,${o.defaultButtonFontWeight}`,`0,${o.primaryButtonFontWeight}`,`0,${o.checklistLauncherFontWeight}`,`0,${o.launcherButtonFontWeight}`])).sort().join(";");return{url:`https://fonts.googleapis.com/css2?family=${encodeURIComponent(o.builtinFontFamily.name)}:ital,wght@${r}`,fontFamily:o.builtinFontFamily.name}}case n.STANDARD:return null}}(t),u=e?.url,l=e?.fontFamily,[a,c]=o.useState(!u||!l);return o.useLayoutEffect((()=>{if(!r||!u||!l)return;let o=!1;return x(null,r,u),function(o,r,t){if(!o.document.fonts)return t(),()=>{};let e=!1;const n=()=>{const u=o.document.fonts.load(`100px ${r}`,"BESbswy");if(!u)return l(),void t();u.then((o=>{e||(o.length>=1?(l(),t()):window.setTimeout(n,25))}),(o=>{console.log("Userflow.js: observeFont error:"),console.log(o),t()}))};n();const u=window.setTimeout((()=>{console.warn(`Userflow.js: Timed out waiting for font family ${r} to load. Will continue anyway.`),t()}),2e3),l=()=>{e=!0,window.clearTimeout(void 0),window.clearTimeout(u)}}(r,l,(()=>{o||c(!0)})),()=>{o=!0}}),[r,u,l]),{loaded:a}}function x(o,r,t){const e=y(r),n=e.stylesheets.get(t);if(n)return n.loadPromise;const u=r.document.createElement("link"),l=new Promise(((e,n)=>{u.dataset.userflowStylesheet="true",u.rel="stylesheet",u.href=t,u.onload=()=>{e()},u.onerror=r=>{console.log(`Userflow.js: Error installing Stylesheet ${t}:`,r),o&&o.reportCspIssue(),n()},r.document.head.appendChild(u)}));return e.stylesheets.set(t,{link:u,loadPromise:l}),l}export{F as a,a as b,A as c,w as g,m as u};
1
+ import{r as o}from"./vendor.react.js";import{x as r,B as t,A as e,y as n}from"./userflow.js";import{c as u}from"./flow-condition-types.js";import{a as l}from"./client-context.js";function a(t){const[e]=o.useState((()=>new r(t)));return e.update(t),e}function c(o){return o?o.match(/^#[0-9a-f]{6}$/i)?[parseInt(o.substring(1,3),16),parseInt(o.substring(3,5),16),parseInt(o.substring(5,7),16)]:o.match(/^#[0-9a-f]{3}$/i)?[parseInt(o.substring(1,2).repeat(2),16),parseInt(o.substring(2,3).repeat(2),16),parseInt(o.substring(3,4).repeat(2),16)]:[0,0,0]:[0,0,0]}function i([o,r,t]){return"#"+o.toString(16).padStart(2,"0")+r.toString(16).padStart(2,"0")+t.toString(16).padStart(2,"0")}function d(o){const r=c(o);return r?r.join(", "):"0, 0, 0"}function s(o){return i(c(o))}function f(o,r,t){return[Math.max(0,Math.min(255,Math.round(o[0]+(r[0]-o[0])*t))),Math.max(0,Math.min(255,Math.round(o[1]+(r[1]-o[1])*t))),Math.max(0,Math.min(255,Math.round(o[2]+(r[2]-o[2])*t)))]}function h(o,r,t){const e=c(o),n=c(r);return e&&n?i(f(e,n,t)):o}function g([o,r,t]){o/=255,r/=255,t/=255;const e=Math.max(o,r,t),n=Math.min(o,r,t);let u,l,a=(e+n)/2;if(e==n)u=l=0;else{const c=e-n;switch(l=a>.5?c/(2-e-n):c/(e+n),e){case o:u=(r-t)/c+(r<t?6:0);break;case r:u=(t-o)/c+2;break;default:u=(o-r)/c+4}u/=6}return[u,l,a]}function B([o,r,t]){let e=r/255,n=t/255;function u(o){let r=0;return r=o<=.04045?o/12.92:Math.pow((o+.055)/1.055,2.4),r}let l=.2126*u(o/255)+.7152*u(e)+.0722*u(n);return Math.round(10*function(o){let r=0;return r=o<=216/24389?o*(24389/27):116*Math.pow(o,1/3)-16,r}(l))/1e3}function C(o,r){const t=B(o),e=B(r);let n=.13*((1-(e-t))/2)+.05,u=1-Math.abs(e-t),l=n+Math.pow((1-n)*u,4);return Math.round(1e3*l)/1e3}function b(o,r){const t=c(o),e=g(t);let n=null,u=null;for(const i of r){const o=c(i),r=g(o);let t=!1;if(n&&u){const o=.3;Math.abs(r[2]-e[2])>o?r[1]>u[1]&&(t=!0):Math.abs(e[2]-r[2])>Math.abs(e[2]-u[2])&&(t=!0)}else t=!0;t&&(n=o,u=r)}let l=n,a=n,d=C(l,t),s=2*d;return e[2]>.2&&e[2]<.8&&(a=function([o,r,t]){return[Math.round(255-o),Math.round(255-r),Math.round(255-t)]}(a),s=C(a,t)),[i(f(t,l,d)),i(f(t,a,s))]}function k(o){const[r,t,e,n,u,l,a,i]=function(o,r,t,e){const[n,u]=b(o,[r]);let l,a;if(o===t)l=n,a=u;else{const n=b(t,[o,r,e]);l=n[0],a=n[1]}const i=c(o),d=c(t);let s,f,h,g;if(Math.abs(i[0]-d[0])<20&&Math.abs(i[1]-d[1])<20&&Math.abs(i[2]-d[2])<20){s=r,f=o;const t=b(s,[f]);h=t[0],g=t[1]}else s=o,f=r,h=n,g=u;return[n,u,l,a,s,f,h,g]}(o.brandBackgroundColor,o.brandForegroundColor,o.mainBackgroundColor,o.mainForegroundColor),d={...o,widgetBackgroundColor:u,widgetForegroundColor:l,widgetHoverBackgroundColor:a,widgetActiveBackgroundColor:i,sameBackground:s(o.mainBackgroundColor)==s(o.brandBackgroundColor)};if(d.brandHoverBackgroundColor&&(d.widgetHoverBackgroundColor=d.brandHoverBackgroundColor),d.brandActiveBackgroundColor&&(d.widgetActiveBackgroundColor=d.brandActiveBackgroundColor),d.brandHoverBackgroundColor||(d.brandHoverBackgroundColor=r),d.brandActiveBackgroundColor||(d.brandActiveBackgroundColor=t),d.mainHoverBackgroundColor||(d.mainHoverBackgroundColor=e),d.mainActiveBackgroundColor||(d.mainActiveBackgroundColor=n),d.bubbleBorderColor||(d.bubbleBorderColor=d.mainForegroundColor),d.checklistLauncherActiveBackgroundColor||(d.checklistLauncherActiveBackgroundColor=d.brandActiveBackgroundColor),d.checklistLauncherBackgroundColor||(d.checklistLauncherBackgroundColor=d.brandBackgroundColor),d.checklistLauncherCounterBackgroundColor||(d.checklistLauncherCounterBackgroundColor=d.brandForegroundColor),d.checklistLauncherCounterFontColor||(d.checklistLauncherCounterFontColor=d.brandBackgroundColor),d.checklistLauncherFontColor||(d.checklistLauncherFontColor=d.brandForegroundColor),d.checklistLauncherHoverBackgroundColor||(d.checklistLauncherHoverBackgroundColor=d.brandHoverBackgroundColor),d.focusColor||(d.focusColor=d.mainActiveBackgroundColor),d.launcherIconActiveColor||(d.launcherIconActiveColor=d.brandActiveBackgroundColor),d.launcherIconColor||(d.launcherIconColor=d.brandBackgroundColor),d.launcherIconHoverColor||(d.launcherIconHoverColor=d.brandHoverBackgroundColor),d.linkColor||(d.linkColor=d.widgetBackgroundColor),d.progressBarColor||(d.progressBarColor=d.widgetBackgroundColor),d.questionColor||(d.questionColor=d.widgetBackgroundColor),d.toolbarForegroundColor||(d.toolbarForegroundColor=d.mainForegroundColor),d.primaryButtonBackgroundColor||(d.primaryButtonBackgroundColor=d.widgetBackgroundColor),d.primaryButtonFontColor||(d.primaryButtonFontColor=d.widgetForegroundColor),d.primaryButtonHoverFontColor||(d.primaryButtonHoverFontColor=d.primaryButtonFontColor),d.primaryButtonActiveFontColor||(d.primaryButtonActiveFontColor=d.primaryButtonFontColor),!d.primaryButtonHoverBackgroundColor||!d.primaryButtonActiveBackgroundColor){const[o,r]=b(d.primaryButtonBackgroundColor,[d.primaryButtonFontColor]);d.primaryButtonHoverBackgroundColor||(d.primaryButtonHoverBackgroundColor=o),d.primaryButtonActiveBackgroundColor||(d.primaryButtonActiveBackgroundColor=r)}if(d.primaryButtonBorderColor||(d.primaryButtonBorderColor=d.widgetBackgroundColor),d.primaryButtonHoverBorderColor||(d.primaryButtonHoverBorderColor=d.primaryButtonHoverBackgroundColor),d.primaryButtonActiveBorderColor||(d.primaryButtonActiveBorderColor=d.primaryButtonActiveBackgroundColor),d.defaultButtonBackgroundColor||(d.defaultButtonBackgroundColor=d.mainBackgroundColor),d.defaultButtonFontColor||(d.defaultButtonFontColor=u),d.defaultButtonHoverFontColor||(d.defaultButtonHoverFontColor=d.defaultButtonFontColor),d.defaultButtonActiveFontColor||(d.defaultButtonActiveFontColor=d.defaultButtonFontColor),!d.defaultButtonHoverBackgroundColor||!d.defaultButtonActiveBackgroundColor){const[o,r]=b(d.defaultButtonBackgroundColor,[d.defaultButtonFontColor]);d.defaultButtonHoverBackgroundColor||(d.defaultButtonHoverBackgroundColor=o),d.defaultButtonActiveBackgroundColor||(d.defaultButtonActiveBackgroundColor=r)}return d.defaultButtonBorderColor||(d.defaultButtonBorderColor=d.defaultButtonFontColor),d.defaultButtonHoverBorderColor||(d.defaultButtonHoverBorderColor=d.defaultButtonBorderColor),d.defaultButtonActiveBorderColor||(d.defaultButtonActiveBorderColor=d.defaultButtonBorderColor),d.launcherButtonBackgroundColor||(d.launcherButtonBackgroundColor=d.brandBackgroundColor),d.launcherButtonBorderColor||(d.launcherButtonBorderColor=d.brandBackgroundColor),d.launcherButtonFontColor||(d.launcherButtonFontColor=d.brandForegroundColor),d.launcherButtonHoverBackgroundColor||(d.launcherButtonHoverBackgroundColor=d.brandHoverBackgroundColor),d.launcherButtonHoverBorderColor||(d.launcherButtonHoverBorderColor=d.launcherButtonHoverBackgroundColor),d.launcherButtonHoverFontColor||(d.launcherButtonHoverFontColor=d.launcherButtonFontColor),d.launcherButtonActiveBackgroundColor||(d.launcherButtonActiveBackgroundColor=d.brandActiveBackgroundColor),d.launcherButtonActiveBorderColor||(d.launcherButtonActiveBorderColor=d.launcherButtonActiveBackgroundColor),d.launcherButtonActiveFontColor||(d.launcherButtonActiveFontColor=d.launcherButtonFontColor),d}function w(o){const{questionColor:r}=o;return{"--userflow-backdrop-highlight-color-rgb":d(o.backdropHighlightColor),"--userflow-backdrop-highlight-inset":o.backdropHighlightType===t.INSIDE?"inset":"","--userflow-backdrop-highlight-opacity":o.backdropHighlightOpacity,"--userflow-backdrop-highlight-radius":o.backdropHighlightRadius+"px","--userflow-backdrop-highlight-spread":o.backdropHighlightSpread+"px","--userflow-backdrop-opacity":o.backdropOpacity,"--userflow-beacon-color":o.beaconColor,"--userflow-brand-active-background-color":o.brandActiveBackgroundColor,"--userflow-brand-background-color":o.brandBackgroundColor,"--userflow-brand-foreground-color":o.brandForegroundColor,"--userflow-brand-foreground-color-rgb":d(o.brandForegroundColor),"--userflow-brand-hover-background-color":o.brandHoverBackgroundColor,"--userflow-bubble-border-color":o.bubbleBorderColor,"--userflow-bubble-border-radius":o.bubbleBorderRadius+"px","--userflow-bubble-border-width":o.bubbleBorderWidth+"px","--userflow-button-border-radius":o.buttonBorderRadius+"px","--userflow-button-height":o.buttonHeight+"px","--userflow-button-min-width":o.buttonMinWidth+"px","--userflow-button-text-align":0===o.buttonMinWidth?"start":"center","--userflow-buttons-justify-content":"left"===o.buttonHorizontalAlign?"flex-start":"center"===o.buttonHorizontalAlign?"center":"flex-end","--userflow-buttons-modal-justify-content":"left"===o.buttonHorizontalAlign?"flex-start":"right"===o.buttonHorizontalAlign?"flex-end":"center","--userflow-checklist-launcher-active-background-color":o.checklistLauncherActiveBackgroundColor,"--userflow-checklist-launcher-background-color":o.checklistLauncherBackgroundColor,"--userflow-checklist-launcher-border-radius":o.checklistLauncherBorderRadius+"px","--userflow-checklist-launcher-counter-background-color":o.checklistLauncherCounterBackgroundColor,"--userflow-checklist-launcher-counter-font-color":o.checklistLauncherCounterFontColor,"--userflow-checklist-launcher-font-color-rgb":d(o.checklistLauncherFontColor),"--userflow-checklist-launcher-font-color":o.checklistLauncherFontColor,"--userflow-checklist-launcher-font-weight":String(o.checklistLauncherFontWeight),"--userflow-checklist-launcher-height":o.checklistLauncherHeight+"px","--userflow-checklist-launcher-hover-background-color":o.checklistLauncherHoverBackgroundColor,"--userflow-checkmark-background-color":o.checkmarkBackgroundColor,"--userflow-completed-task-text-decoration":o.completedTaskTextDecoration,"--userflow-default-button-active-background-color":o.defaultButtonActiveBackgroundColor,"--userflow-default-button-active-border-color":o.defaultButtonActiveBorderColor,"--userflow-default-button-active-font-color":o.defaultButtonActiveFontColor,"--userflow-default-button-background-color":o.defaultButtonBackgroundColor,"--userflow-default-button-border-color":o.defaultButtonBorderColor,"--userflow-default-button-border-width":o.defaultButtonBorderWidth+"px","--userflow-default-button-font-color":o.defaultButtonFontColor,"--userflow-default-button-font-weight":String(o.defaultButtonFontWeight),"--userflow-default-button-hover-background-color":o.defaultButtonHoverBackgroundColor,"--userflow-default-button-hover-border-color":o.defaultButtonHoverBorderColor,"--userflow-default-button-hover-font-color":o.defaultButtonHoverFontColor,"--userflow-focus-color":`rgba(${d(o.focusColor)}, ${o.focusOpacity})`,"--userflow-font-family":o.builtinFontFamily?o.builtinFontFamily.name+(o.builtinFontFamily.fallback?", "+o.builtinFontFamily.fallback:""):o.fontFamily?o.fontFamily:"sans-serif","--userflow-font-size":o.fontSize+"px","--userflow-font-weight-bold":String(o.fontWeightBold),"--userflow-font-weight-normal":String(o.fontWeightNormal),"--userflow-h1-font-size":o.h1FontSize+"px","--userflow-h2-font-size":o.h2FontSize+"px","--userflow-launcher-button-active-background-color":o.launcherButtonActiveBackgroundColor,"--userflow-launcher-button-active-border-color":o.launcherButtonActiveBorderColor,"--userflow-launcher-button-active-font-color":o.launcherButtonActiveFontColor,"--userflow-launcher-button-background-color":o.launcherButtonBackgroundColor,"--userflow-launcher-button-border-color":o.launcherButtonBorderColor,"--userflow-launcher-button-border-radius":o.launcherButtonBorderRadius+"px","--userflow-launcher-button-border-width":o.launcherButtonBorderWidth+"px","--userflow-launcher-button-font-color":o.launcherButtonFontColor,"--userflow-launcher-button-font-weight":String(o.launcherButtonFontWeight),"--userflow-launcher-button-height":o.launcherButtonHeight+"px","--userflow-launcher-button-horizontal-padding":o.launcherButtonHorizontalPadding+"px","--userflow-launcher-button-hover-background-color":o.launcherButtonHoverBackgroundColor,"--userflow-launcher-button-hover-border-color":o.launcherButtonHoverBorderColor,"--userflow-launcher-button-hover-font-color":o.launcherButtonHoverFontColor,"--userflow-launcher-button-width":o.launcherButtonWidth?o.launcherButtonWidth+"px":"auto","--userflow-launcher-icon-active-color":o.launcherIconActiveColor,"--userflow-launcher-icon-color":o.launcherIconColor,"--userflow-launcher-icon-hover-color":o.launcherIconHoverColor,"--userflow-launcher-icon-opacity":o.launcherIconOpacity,"--userflow-launcher-icon-size":o.launcherIconSize+"px","--userflow-line-height":o.lineHeight+"px","--userflow-link-color":o.linkColor,"--userflow-main-active-background-color":o.mainActiveBackgroundColor,"--userflow-main-background-color":o.mainBackgroundColor,"--userflow-main-background-color-rgb":d(o.mainBackgroundColor),"--userflow-main-foreground-color":o.mainForegroundColor,"--userflow-main-foreground-color-rgb":d(o.mainForegroundColor),"--userflow-main-hover-background-color":o.mainHoverBackgroundColor,"--userflow-modal-padding":o.modalPadding+"px","--userflow-modal-padding-top":(o.avatarType===e.NONE?o.modalPadding:o.modalPadding+Math.max((o.avatarSize-o.modalPadding)/2,0))+"px","--userflow-backdrop-color-rgb":d(o.backdropColor),"--userflow-notch-color":o.bubbleBorderWidth>0&&o.bubbleBorderColor||o.mainBackgroundColor,"--userflow-primary-button-active-background-color":o.primaryButtonActiveBackgroundColor,"--userflow-primary-button-active-border-color":o.primaryButtonActiveBorderColor,"--userflow-primary-button-active-font-color":o.primaryButtonActiveFontColor,"--userflow-primary-button-background-color":o.primaryButtonBackgroundColor,"--userflow-primary-button-border-color":o.primaryButtonBorderColor,"--userflow-primary-button-border-width":o.primaryButtonBorderWidth+"px","--userflow-primary-button-font-color":o.primaryButtonFontColor,"--userflow-primary-button-font-weight":String(o.primaryButtonFontWeight),"--userflow-primary-button-hover-background-color":o.primaryButtonHoverBackgroundColor,"--userflow-primary-button-hover-border-color":o.primaryButtonHoverBorderColor,"--userflow-primary-button-hover-font-color":o.primaryButtonHoverFontColor,"--userflow-progress-bar-color":o.progressBarColor,"--userflow-progress-bar-height":o.progressBarHeight+"px","--userflow-resource-center-collapsed-height":o.resourceCenterCollapsedHeight+"px","--userflow-resource-center-launcher-border-radius":(null!=o.resourceCenterLauncherBorderRadius?o.resourceCenterLauncherBorderRadius:o.resourceCenterCollapsedHeight/2)+"px","--userflow-resource-center-padding-x":o.resourceCenterPaddingX+"px","--userflow-resource-center-padding-y":o.resourceCenterPaddingY+"px","--userflow-resource-center-transition-duration":o.resourceCenterTransitionDuration+"ms","--userflow-resource-center-width":o.resourceCenterWidth+"px","--userflow-question-color-light":h(r,o.mainBackgroundColor,.5),"--userflow-question-color-lighter":h(r,o.mainBackgroundColor,.75),"--userflow-question-color-lightest":h(r,o.mainBackgroundColor,.9),"--userflow-question-color-medium-light":h(r,o.mainBackgroundColor,.15),"--userflow-question-color":r,"--userflow-toolbar-foreground-color":o.toolbarForegroundColor,"--userflow-toolbar-foreground-color-rgb":d(o.toolbarForegroundColor),"--userflow-tooltip-notch-size":o.tooltipNotchSize+"px","--userflow-widget-active-background-color":o.widgetActiveBackgroundColor,"--userflow-widget-background-color":o.widgetBackgroundColor,"--userflow-widget-foreground-color":o.widgetForegroundColor,"--userflow-widget-hover-background-color":o.widgetHoverBackgroundColor}}const p=[];function m(r){let[t,e]=o.useState(r);const n=a(r.sessionData||p);return o.useLayoutEffect((()=>{const{variations:o}=r;if(!o)return;const t=[],l=[],a=()=>{let n=r,u=!1;for(const[r,e]of o.entries())if(t[r]){u||(u=!0,n={...n});for(const o of e.overriddenKeys)n[o]=e[o]}e(n)};for(const[r,e]of o.entries()){t[r]=!1;const{condition:o}=e;if(o&&e.overriddenKeys&&e.overriddenKeys.length>0){const e=u[o.type].track({sessionData:n,condition:o,callback:o=>{t[r]=o,a()}});l[r]=e}else l[r]=()=>{}}return a(),()=>{for(const o of l)o()}}),[r,n]),o.useMemo((()=>k(t)),[t])}const v=new Map;function y(o){let r=v.get(o);return r||(r={stylesheets:new Map},v.set(o,r)),r}function F(r,t,e){const n=l(),[u,a]=o.useState(!t);return o.useLayoutEffect((()=>{if(!r||!t)return;let o,u=!1;const l=async t=>{await x(n,r,t),o&&function(o,r){const t=y(o),e=t.stylesheets.get(r);if(!e)return;o.document.head.removeChild(e.link),t.stylesheets.delete(r)}(r,o),o=t};(async()=>{let o="string"==typeof t?t:t.get();if(window.MSInputMethodContext&&document.documentMode&&e){let r=await function(o){return new Promise(((r,t)=>{let e=H.get(o);if(e)return void r(e);const n=new XMLHttpRequest;n.addEventListener("load",(()=>{if(200!==n.status)return void t(new Error("Userflow.js could not fetch stylesheet: "+o));const e=n.responseText;H.set(o,e),r(e)})),n.addEventListener("error",(()=>{t(new Error("Userflow.js could not fetch stylesheet: "+o))})),n.open("GET",o),n.send()}))}(o);if(u)return;r=function(o,r){for(const t in r)if(r.hasOwnProperty(t)){const e=r[t];e&&(o=o.replace(new RegExp(`var\\(${t}.*?\\)`,"g"),e))}return o=o.replace(/var\(--[a-z0-9-]+(,\s*(.*?))?\)/g,"$2")}(r,w(e)),o="data:text/css;base64,"+btoa(r)}await l(o),u||a(!0)})();let c=null;return"string"!=typeof t&&(c=t.onUpdate((async()=>{l(t.get())}))),()=>{u=!0,c&&c()}}),[n,r,t,e]),{loaded:u}}const H=new Map;function A(r,t){const e=t&&function(o){if(!o.builtinFontFamily)return o.fontCssUrl?{url:o.fontCssUrl,fontFamily:o.fontFamily}:null;switch(o.builtinFontFamily.provider){case n.GOOGLE:{const r=Array.from(new Set(["0,400","1,400",`0,${o.fontWeightBold}`,`0,${o.defaultButtonFontWeight}`,`0,${o.primaryButtonFontWeight}`,`0,${o.checklistLauncherFontWeight}`,`0,${o.launcherButtonFontWeight}`])).sort().join(";");return{url:`https://fonts.googleapis.com/css2?family=${encodeURIComponent(o.builtinFontFamily.name)}:ital,wght@${r}`,fontFamily:o.builtinFontFamily.name}}case n.STANDARD:return null}}(t),u=e?.url,l=e?.fontFamily,[a,c]=o.useState(!u||!l);return o.useLayoutEffect((()=>{if(!r||!u||!l)return;let o=!1;return x(null,r,u),function(o,r,t){if(!o.document.fonts)return t(),()=>{};let e=!1;const n=()=>{const u=o.document.fonts.load(`100px ${r}`,"BESbswy");if(!u)return l(),void t();u.then((o=>{e||(o.length>=1?(l(),t()):window.setTimeout(n,25))}),(o=>{console.log("Userflow.js: observeFont error:"),console.log(o),t()}))};n();const u=window.setTimeout((()=>{console.warn(`Userflow.js: Timed out waiting for font family ${r} to load. Will continue anyway.`),t()}),2e3),l=()=>{e=!0,window.clearTimeout(void 0),window.clearTimeout(u)}}(r,l,(()=>{o||c(!0)})),()=>{o=!0}}),[r,u,l]),{loaded:a}}function x(o,r,t){const e=y(r),n=e.stylesheets.get(t);if(n)return n.loadPromise;const u=r.document.createElement("link"),l=new Promise(((e,n)=>{u.dataset.userflowStylesheet="true",u.rel="stylesheet",u.href=t,u.onload=()=>{e()},u.onerror=r=>{console.log(`Userflow.js: Error installing Stylesheet ${t}:`,r),o&&o.reportCspIssue(),n()},r.document.head.appendChild(u)}));return e.stylesheets.set(t,{link:u,loadPromise:l}),l}export{F as a,a as b,A as c,w as g,m as u};