userflow.js-self-hosted 0.1.1002482 → 0.1.1002497
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BubbleToolbar.js +1 -1
- package/hash.txt +1 -1
- package/package.json +1 -1
- package/userflow.js +1 -1
package/BubbleToolbar.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./vendor.react.js";import{c as t,a as n,i as r,b as l}from"./flow-condition-types.js";import{b as o}from"./stylesheets.js";import{o as a}from"./vendor.obj-str.js";import{l as i,n as s,S as u,E as c,c as d,s as m,U as b,p,d as f}from"./userflow.js";import{S as h,a as w,V as g,b as v,c as E,T as y}from"./Icons.js";import{F as k}from"./vendor.fortawesome.react-fontawesome.js";import{f as _}from"./vendor.fortawesome.pro-solid-svg-icons.js";import{u as x}from"./vendor.react-i18next.js";import{u as j}from"./client-context.js";const q=e.createContext(null);function N(){const t=e.useContext(q);if(!t)throw new Error("useSession: Session was not set");return t}function S(n){const r=N(),[l,a]=e.useState(!1),i=o(r.data),s=function(t){const n=e.useRef(t),r=e.useRef(t);return t!==r.current&&JSON.stringify(t)!==JSON.stringify(r.current)&&(n.current=t),r.current=t,n.current}(n);return e.useLayoutEffect((()=>{if(s){return t[s.type].track({sessionData:i,condition:s,callback:e=>{a(e)}})}}),[i,s]),null!=s&&l}const C=({appearance:t,hidden:n,disabled:r,onMouseDown:l,onClick:o,text:i,active:s,children:u})=>e.createElement("button",{className:a({[ce(t)]:!0,"userflowjs-bubble-button--hidden":!!n,"userflowjs-bubble-button--active":!!s}),onMouseDown:l,onClick:o,disabled:r},u||e.createElement("div",{className:"userflowjs-bubble-button-text",role:"presentation"},i));async function T(e,t,l){const{steps:o}=t.version;switch(l.type){case i.CLOSE_FLOW:switch(t.kind){case"launcher":await e.dismissLauncher(t,{endReason:c.ACTION});break;case"flow":case"checklist":await e.endFlow(t,{endReason:c.ACTION})}return;case i.EVAL_JS:try{const e=r(l.code||"",t.data);new Function('"use strict";\n'+e)()}catch(a){console.error(`Userflow.js: Evaluate JavaScript action failed.\n\nError:\n${a.stack||a.message||a}\n\nCode:\n${l.code}`)}return;case i.GO_TO_STEP:{if("flow"!==t.kind)return;const n=o.find((({crossVersionId:e})=>e===l.stepCvid));if(!n)throw new b("Action points to unknown step: "+l.stepCvid);return void(await e.goToStep(t,n))}case i.NAVIGATE:{if(!l.url)return void console.warn("Userflow.js: NAVIGATE action is missing url property");const e=O(l.url,{lookupAttribute:n(t.data)});return void(l.navigateTarget===s.NEW_TAB?window.open(e):d.customNavigate?d.customNavigate(e):window.setTimeout((()=>{m(e)}),0))}case i.SNOOZE:return void("flow"===t.kind&&l.timeValue&&l.timeUnit&&(e.endFlow(t,{endReason:c.SNOOZED,batch:!0}),t.draftMode?window.alert(`In preview mode, flows can't be snoozed.\n\nBut if this flow was running in published mode, the flow would now be snoozed for ${l.timeValue} ${l.timeUnit.toLowerCase()+(1===l.timeValue?"":"s")}.`):e.send({kind:"Snooze",flowId:t.flow.id,timeValue:l.timeValue,timeUnit:l.timeUnit},{batch:!0})));case i.START_FLOW:return"launcher"===t.kind&&e.deactivateLauncher(t),void(l.otherFlow?await e.startFlow({flowId:l.otherFlow.id,stepCvid:l.otherFlowStepCvid,startReason:t.draftMode?u.DRAFT:u.ACTION,replaceCurrent:!0}):console.warn("Userflow.js: START_FLOW action is missing other flow"))}}async function I(e,t,n){const r=[],l=[],o=[];for(const a of n)a.type===i.NAVIGATE?a.navigateTarget===s.NEW_TAB?r.push(a):o.push(a):l.push(a);for(const a of r)T(e,t,a);await Promise.all(l.map((n=>T(e,t,n))));for(const a of o)T(e,t,a)}const P=({button:t})=>{const n=j(),l=N(),o=S(t.disabledCondition),a=S(t.hiddenCondition);return e.createElement(C,{appearance:t.appearance,hidden:a,disabled:o,onClick:()=>I(n,l,t.actions),text:r(t.text,l.data)})},A=({type:t,required:n,buttonText:r,options:l,otherOption:o,multipleSelection:i,labelLeft:s,labelCenter:u,labelRight:c,minValue:d,maxValue:m,onSubmit:b,inert:f})=>{const{t:g}=x(),v=e.useRef(null),[E,y]=e.useState(""),[j,q]=e.useState(new Set),[N,S]=e.useState(),[C,T]=e.useState(),[I,P]=e.useState(!1),[A,$]=e.useState(!1),[M,R]=e.useState(null),F=e=>{if(!f&&b){if(n&&""===E&&[p.MULTILINE_TEXT,p.TEXT].includes(t))return R(g("question.requiredError")),void O();$(!0),R(null),b({...e,onCancel:()=>{$(!1)},onError:e=>{$(!1),R(e||"Sorry, something went wrong saving your answer. Please try again.")}})}},O=e.useCallback((()=>{!f&&v.current&&v.current.focus()}),[f]),[U,W]=e.useState(!1);e.useEffect((()=>{U&&(O(),W(!1))}),[O,U]);const B=e.createElement("div",{className:"userflowjs-bubble-question__button-row userflowjs-bubble-question__button-row--end"},e.createElement("button",{className:"userflowjs-bubble-button userflowjs-bubble-button--primary",onClick:()=>F({answer:{kind:"text",value:E}}),tabIndex:f?-1:void 0,disabled:A},e.createElement("div",{className:"userflowjs-bubble-button-text",role:"presentation"},r||g("question.submit"))));let V=null,D=0;if(t===p.NPS)s=s||g("question.npsLabelLeft"),c=c||g("question.npsLabelRight"),V=[0,1,2,3,4,5,6,7,8,9,10],D=V.length;else if([p.SCALE,p.STARS].includes(t)){m=null!=m?m:5,V=[];for(let e=d=null!=d?d:1;e<=m;e++)V.push(e);D=V.length}else t===p.MULTIPLE_CHOICE&&(D=(l?l.length:0)+(o&&!I?1:0));const[z,K]=e.useState(-1),J=-1===z?-1:Math.min(z,D-1),H=e=>{if(!e.target.closest('[role="radio"], [role="checkbox"], [role="radiogroup"], [role="group"]'))return;let t=null;if("ArrowRight"===e.key||"ArrowDown"===e.key?t=1:"ArrowLeft"!==e.key&&"ArrowUp"!==e.key||(t=-1),null!=t){e.preventDefault();const n=e.currentTarget.querySelectorAll('[role="radio"], [role="checkbox"]');let r=J+t;r<0?r=n.length-1:r>n.length-1&&(r=0),K(r),n[r].focus()}};let G,X=null,Q=null;if(V&&(s||u||c)){const t=[];s&&t.push(V[0],s),c&&t.push(V[V.length-1],c),X=e.createElement("div",{id:"a11y-scale-labels",className:"userflowjs-a11y-only"},t.join(", ")),Q=e.createElement("div",{id:"userflowjs-bubble-question-labels",className:"userflowjs-bubble-question__scale-labels","aria-hidden":"true"},e.createElement("div",{className:"userflowjs-bubble-question__scale-label"},s),u&&e.createElement("div",{className:"userflowjs-bubble-question__scale-label userflowjs-bubble-question__scale-label--center"},u),e.createElement("div",{className:"userflowjs-bubble-question__scale-label userflowjs-bubble-question__scale-label--right"},c))}switch(t){case p.MULTILINE_TEXT:G=e.createElement(e.Fragment,null,e.createElement("textarea",{ref:v,className:"userflowjs-textarea userflowjs-bubble-question__textarea",value:E,onChange:e=>y(e.target.value),onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&F({answer:{kind:"text",value:E}})},placeholder:g("question.placeholder"),readOnly:f||A,tabIndex:f?-1:void 0,rows:3,"aria-required":n?"true":void 0,"aria-invalid":null!=M?"true":void 0}),B);break;case p.MULTIPLE_CHOICE:{const t=()=>{E&&F({answer:{kind:"text",value:E},animationPromise:L()})},n=(l?.length||0)+(o?1:0),s=Math.max(0,Math.min(n,null==d?1:d)),u=Math.max(0,Math.min(n,null==m?n:m)),c=()=>{const e=(l||[]).filter(((e,t)=>j.has(t))).map((e=>e.value));o&&I&&""!==E&&e.push(E),s!==u||e.length===s?e.length<s?R(g("question.multiple_selection_too_few",{count:s})):e.length>u?R(g("question.multiple_selection_too_many",{count:u})):F({answer:{kind:"list",values:e}}):R(g("question.multiple_selection_wrong",{count:s}))};G=e.createElement(e.Fragment,null,i&&e.createElement("div",{className:a({"userflowjs-bubble-question__multiple-choice-hint":!0,"userflowjs-bubble-question__multiple-choice-hint--error":!!M})},g("question.multiple_selection_hint",{replace:{selected:j.size+(o&&I&&""!==E?1:0),range:s===u?s:`${s}-${u}`}}),M&&e.createElement(e.Fragment,null,". ",e.createElement("span",{role:"alert"},M))),e.createElement("div",{className:a({"userflowjs-bubble-question__multiple-choice":!0,"userflowjs-bubble-question__multiple-choice--single-selection":!i,"userflowjs-bubble-question__multiple-choice--multiple-selection":!!i,"userflowjs-bubble-question__multiple-choice--other-option-active":!!o&&I}),role:i?"group":"radiogroup",tabIndex:f||-1!==J?-1:0,onKeyDown:H},l?.map((({value:t,label:n},r)=>e.createElement("button",{key:r,className:a({"userflowjs-bubble-question__multiple-choice-option":!0,"userflowjs-bubble-question__multiple-choice-option--selected":i?j.has(r):A&&!I&&E==t}),onClick:A?void 0:()=>{if(i){R(null);const e=new Set(j);j.has(r)?e.delete(r):e.add(r),q(e)}else P(!1),y(t),F({answer:{kind:"text",value:t},animationPromise:L()})},disabled:A,tabIndex:f||r!==J?-1:0,role:i?"checkbox":"radio","aria-label":n||t,"aria-checked":!I&&E==t},i?e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-checkbox"},e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-checkbox-inner"},e.createElement(k,{icon:_}))):e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-radio"},e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-radio-inner"})),e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-option-text","aria-hidden":"true"},n||t)))),o&&(I?e.createElement("div",{className:a({"userflowjs-bubble-question__multiple-choice-option":!0,"userflowjs-bubble-question__multiple-choice-option--other":!0,"userflowjs-bubble-question__multiple-choice-option--selected":i?""!=E:A})},i?e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-checkbox",onClick:()=>{y(""),P(!1)}},e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-checkbox-inner"},e.createElement(k,{icon:_}))):e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-radio"},e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-radio-inner"})),e.createElement("input",{ref:v,className:"userflowjs-bubble-question__multiple-choice-option-input",value:E,onChange:e=>y(e.target.value),onKeyDown:e=>{e.shiftKey||"Enter"!==e.key?"Escape"===e.key&&(e.stopPropagation(),y(""),P(!1)):i?c():t()},onBlur:()=>{""===E&&P(!1)},placeholder:g("question.placeholder"),readOnly:f||A,tabIndex:f?-1:void 0}),!i&&e.createElement("button",{"data-testid":"multiple-choice-other-submit",className:"userflowjs-bubble-question__multiple-choice-option-submit",onClick:()=>t(),disabled:A,"aria-label":g("question.submit")},e.createElement(w,null))):e.createElement("button",{className:"userflowjs-bubble-question__multiple-choice-option",onClick:A?void 0:()=>{R(null),P(!0),W(!0)},disabled:A,tabIndex:f||l?.length!==J?-1:0,role:"radio","aria-label":g("question.other"),"aria-checked":"false"},i?e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-checkbox"},e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-checkbox-inner"},e.createElement(k,{icon:_}))):e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-radio"},e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-radio-inner"})),e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-option-text","aria-hidden":"true"},g("question.other"))))),i&&e.createElement("div",{className:"userflowjs-bubble-question__button-row"},e.createElement("button",{className:"userflowjs-bubble-button userflowjs-bubble-button--primary",onClick:c,tabIndex:f?-1:void 0,disabled:A},e.createElement("div",{className:"userflowjs-bubble-button-text",role:"presentation"},r||g("question.submit")))));break}case p.NPS:case p.SCALE:G=e.createElement(e.Fragment,null,X,e.createElement("div",{className:"userflowjs-bubble-question__scale-options",role:"radiogroup",tabIndex:f||-1!==J?-1:0,onKeyDown:H},V?.map(((t,n)=>e.createElement("button",{className:a({"userflowjs-bubble-question__scale-option":!0,"userflowjs-bubble-question__scale-option--selected":A&&N==t}),key:t,tabIndex:f||n!==J?-1:0,onClick:()=>{S(t),F({answer:{kind:"number",value:t},animationPromise:L()})},disabled:A,role:"radio","aria-checked":N==t},t)))),Q);break;case p.STARS:G=e.createElement("div",{className:"userflowjs-bubble-question__stars-wrapper"},X,e.createElement("div",{className:"userflowjs-bubble-question__stars",role:"radiogroup",tabIndex:f||-1!==J?-1:0,onKeyDown:H},V?.map(((t,n)=>e.createElement("button",{className:a({"userflowjs-bubble-question__star":!0,"userflowjs-bubble-question__star--hovered":!A&&null!=C&&C>=t,"userflowjs-bubble-question__star--selected":A&&null!=N&&N>=t,"userflowjs-bubble-question__star--not-selected":A&&null!=N&&N<t}),key:t,tabIndex:f||n!==J?-1:0,onClick:()=>{S(t),F({answer:{kind:"number",value:t},animationPromise:L()})},onMouseOver:()=>T(t),onMouseLeave:()=>T(null),disabled:A,role:"radio","aria-checked":N==t,"aria-label":String(t)},e.createElement("div",{className:"userflowjs-bubble-question__star-icon","aria-hidden":"true"},e.createElement(h,null)),e.createElement("div",{className:"userflowjs-bubble-question__star-value","aria-hidden":"true"},t))))),Q);break;case p.TEXT:G=e.createElement(e.Fragment,null,e.createElement("input",{ref:v,className:"userflowjs-text-input userflowjs-bubble-question__text-input",value:E,onChange:e=>y(e.target.value),onKeyDown:e=>{e.shiftKey||"Enter"!==e.key||F({answer:{kind:"text",value:E}})},placeholder:g("question.placeholder"),readOnly:f||A,tabIndex:f?-1:void 0,"aria-required":n?"true":void 0,"aria-invalid":null!=M?"true":void 0}),B)}return e.createElement("div",{className:"userflowjs-bubble-question",style:{pointerEvents:f?"none":void 0}},M&&!(t===p.MULTIPLE_CHOICE&&i)&&e.createElement("div",{className:"userflowjs-bubble-question__error",role:"alert"},M),G)};function L(){return new Promise((e=>window.setTimeout(e,250)))}const $=({question:t})=>{const n=j(),r=function(){const e=N();if("flow"!==e.kind)throw new Error("useFlowSession: Wrong session kind");return e}();return e.createElement(A,{type:t.type,required:!!t.required,buttonText:t.buttonText||"",options:t.options,otherOption:t.otherOption,multipleSelection:t.multipleSelection,labelLeft:t.labelLeft||"",labelCenter:t.labelCenter||"",labelRight:t.labelRight||"",minValue:t.minValue,maxValue:t.maxValue,onSubmit:async e=>{f("answerQuestion",r.id,t.cvid,e);const{answer:l}=e;try{await Promise.all([await n.send({kind:"AnswerQuestion",sessionId:r.id,questionName:t.name,questionCvid:t.cvid,textAnswer:"text"==l.kind?l.value:null,numberAnswer:"number"==l.kind?String(l.value):null,listAnswer:"list"==l.kind?l.values:null}),e.animationPromise])}catch(a){return console.log("Userflow.js: Error when answering question:",a),void e.onError()}const{bindAttributeFqn:o}=t;if(o&&n.flowSession?.id===r.id){let e;switch(l.kind){case"text":e={name:o,value:l.value};break;case"number":e={name:o,value:String(l.value)};break;case"list":e={name:o,value:l.values}}n.optimisticClockUIUpdate((()=>{n.setFlowSession({...r,data:[...r.data.filter((e=>e.name!==o)),e]})}))}I(n,r,t.actions)}})},M=({text:t})=>{if(!t)return null;const n=t.split(/\n/);return 1===n.length?e.createElement(e.Fragment,null,n[0]):e.createElement(e.Fragment,null,n.map(((t,n)=>e.createElement(e.Fragment,{key:n},n>0&&e.createElement("br",null),t))))};function R(e=""){return{type:"paragraph",children:[{text:e}]}}function F(e){if(e){let n;try{n=JSON.parse(e)}catch(t){throw new Error("Could not JSON.parse rich content doc: "+e)}if("rich2"===n.type)return n;throw new Error("Could not recognize rich content doc: "+e)}return function(e=""){return{type:"rich2",children:[R(e)]}}()}function O(e,{lookupAttribute:t}){if(!e)return"";"string"==typeof e&&(e=function(e){if(e){let n;try{n=JSON.parse(e)}catch(t){throw new Error("Could not JSON.parse plaintext doc: "+e)}if("plaintext2"===n.type)return n;throw new Error("Could not recognize plaintext doc: "+e)}return function(e=""){return{type:"plaintext2",children:[{type:"plaintext",children:[{text:e}]}]}}()}(e));const n=[];function r(e){e&&e.forEach((e=>e&&function(e){if(ae(e))e.text&&n.push(e.text);else switch(e.type){case"attribute":{const r=re(e,t);r&&n.push(r);break}default:r(e.children)}}(e)))}return r(e.children),n.join("")}function U(e){let t=!0;if(!e)return!0;"string"==typeof e&&(e=F(e));const n=new Set(["attribute","button","image","question","video"]);return ie(e,(e=>{ae(e)?""!==e.text&&(t=!1):"type"in e&&n.has(e.type)&&(t=!1)})),t}const W=e.memo((({doc:t,...n})=>t?("string"==typeof t&&(t=F(t)),e.createElement(B,{parent:t,...n})):null)),B=({parent:t,...n})=>e.createElement(e.Fragment,null,t.children.map(((r,l)=>ae(r)?e.createElement(V,{key:l,node:r}):e.createElement(z,{key:l,node:r,parent:t,...n})))),V=({node:t})=>t.text?e.createElement(D,{node:t},e.createElement(M,{text:t.text})):null,D=({node:t,children:n})=>(t.color&&"string"==typeof t.color&&(n=e.createElement("span",{style:{color:t.color}},n)),t.bold&&(n=e.createElement("b",null,n)),t.italic&&(n=e.createElement("i",null,n)),t.underline&&(n=e.createElement("u",null,n)),t.strikeThrough&&(n=e.createElement("s",null,n)),t.code&&(n=e.createElement("code",null,n)),t.sup&&(n=e.createElement("sup",null,n)),n),z=({node:t,parent:n,...r})=>{const{lookupAttribute:l}=r,o=e.createElement(B,{parent:t,...r});switch(t.type){case"attribute":return e.createElement(K,{node:t,...r});case"button":return e.createElement(J,{node:t,...r});case"button-group":return e.createElement("div",{className:"userflowjs-bubble-buttons"},o);case"column":return e.createElement("div",{style:te(t,n)},o);case"column-group":return e.createElement("div",{className:"p-like",style:ee(t)},o);case"container":return e.createElement("div",{className:"p-like"+(t.className?` ${t.className}`:""),style:ne(t)},o);case"image":return e.createElement(G,{node:t,...r});case"link":return e.createElement("a",{href:O(t.href,{lookupAttribute:l}),target:"_blank",rel:"noopener noreferrer"},o);case"paragraph":return e.createElement("p",{className:Z(t)},o);case"heading1":return e.createElement("h1",{className:Z(t)},o);case"heading2":return e.createElement("h2",{className:Z(t)},o);case"question":return e.createElement(H,{node:t,...r});case"quote":return e.createElement("blockquote",null,o);case"code-block":return e.createElement("pre",null,e.createElement("code",null,o));case"ordered-list":return e.createElement("ol",null,o);case"unordered-list":return e.createElement("ul",null,o);case"list-item":return e.createElement("li",null,o);case"video":return e.createElement(X,{node:t,...r});default:return e.createElement("div",null,o)}},K=({node:t,lookupAttribute:n})=>{let r=re(t,n);return e.createElement(D,{node:t},r)},J=({node:t,buttons:n})=>{const r=n?.find((e=>e.cvid===t.cvid));return r?e.createElement(P,{key:r.id,button:r}):null},H=({node:t,questions:n})=>{const r=n?.find((e=>e.cvid===t.cvid));return r?e.createElement($,{key:r.id,question:r}):null},G=({node:t,lookupAttribute:n})=>{const{src:r,widthMode:l,displayWidth:o,width:a,height:i,marginTop:s,marginRight:u,marginBottom:c,marginLeft:d,align:m,hasLink:b,href:p}=t;if("string"!=typeof r||!r)return null;const{wrapperStyle:f,blockStyle:h}=Y({widthMode:l,displayWidth:o,width:a,height:i,marginTop:s,marginRight:u,marginBottom:c,marginLeft:d,align:m});let w=e.createElement("img",{src:r,style:{...h,objectFit:"contain"}});return b&&p&&(w=e.createElement("a",{href:O(p,{lookupAttribute:n}),target:"_blank",rel:"noopener noreferrer",style:h},w)),e.createElement("div",{className:"p-like"},e.createElement("div",{style:f},w))},X=({node:t,lookupAttribute:n})=>{const{url:r,widthMode:l,displayWidth:o,width:a,height:i,marginTop:s,marginRight:u,marginBottom:c,marginLeft:d,align:m}=t;if("string"!=typeof r||!r)return null;const{wrapperStyle:b,blockStyle:p}=Y({widthMode:l,displayWidth:o,width:a,height:i,marginTop:s,marginRight:u,marginBottom:c,marginLeft:d,align:m});return e.createElement("div",{className:"p-like"},e.createElement("div",{style:b},e.createElement("div",{style:p},e.createElement(Q,{element:t,noFocus:!0,lookupAttribute:n}))))},Q=({element:{embedType:t,url:n,src:r,autoPlay:o,controls:a,loop:i,muted:s},noFocus:u,forceMuted:c,lookupAttribute:d})=>{if(!n)return null;const m={width:"100%",height:"100%",frameBorder:"0",allow:"accelerometer; autoplay; fullscreen; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0,allowtransparency:"true",mozallowfullscreen:"true",webkitallowfullscreen:"true",oallowfullscreen:"true",msallowfullscreen:"true",style:{display:"block"},tabIndex:u?-1:void 0};if("video"===t)return e.createElement("video",{key:n+";"+String(o)+";"+String(a)+";"+String(i)+";"+String(s),src:n,style:{width:"100%",height:"100%",display:"block"},autoPlay:!!o,controls:!1!==a,loop:i,muted:c||s});if(r){let t;try{t=new URL(r)}catch(w){return null}return c&&(t.searchParams.has("autoplay")||t.searchParams.has("autoPlay"))&&(t.searchParams.set("mute","1"),t.searchParams.set("muted","1"),t.searchParams.set("volume","0")),e.createElement("iframe",{src:t.toString(),...m})}let b=function(e,{iframeFallback:t}={}){let n;try{n=new URL(e)}catch(w){return{kind:"invalid"}}const{hostname:r,pathname:l,searchParams:o}=n;if(r.match(/^(www\.)?(use)?loom\.com$/)){const e=l.match(/^\/share\/([a-z0-9]+)$/i);if(e){const[,t]=e;return{kind:"ok",videoProvider:"loom",videoId:t,searchParams:o}}}if(e.startsWith("raw:")){return{kind:"ok",videoProvider:"raw",videoId:e.replace(/^raw:/,""),searchParams:o}}if(e.startsWith("iframe:")){return{kind:"ok",videoProvider:"iframe",videoId:e.replace(/^iframe:/,""),searchParams:o}}if(["youtube.com","www.youtube.com"].includes(r)){const e=o.get("v");if(e)return o.delete("v"),{kind:"ok",videoProvider:"youtube",videoId:e,searchParams:o}}if("youtu.be"===r){const e=l.match(/^\/([^/]+)$/);if(e){const[,t]=e;return{kind:"ok",videoProvider:"youtube",videoId:t,searchParams:o}}}if("vimeo.com"===r){const e=l.match(/^\/(\d+)$/);if(e){const[,t]=e;return{kind:"ok",videoProvider:"vimeo",videoId:t,searchParams:o}}}if("player.vimeo.com"===r){const e=l.match(/^\/video\/([^/]+)$/);if(e){const[,t]=e;return{kind:"ok",videoProvider:"vimeo",videoId:t,searchParams:o}}}if(r.match(/^[^.]+\.wistia.com$/)){const e=l.match(/^\/medias\/([^/]+)$/);if(e){const[,t]=e;return{kind:"ok",videoProvider:"wistia",videoId:t,searchParams:o}}}return t?{kind:"ok",videoProvider:"iframe",videoId:e,searchParams:o}:{kind:"invalid"}}(n,{iframeFallback:!0});if("invalid"===b.kind)return null;const{videoProvider:p,videoId:f,searchParams:h}=b;switch(o=o||h.has("autoplay")||h.has("autoPlay"),p){case"iframe":return e.createElement("iframe",{src:l(f,(e=>encodeURIComponent(d(e)||""))),scrolling:h.get("scrolling")||void 0,...m});case"loom":return e.createElement("iframe",{src:`https://www.loom.com/embed/${f}?${h.toString()}`,...m});case"raw":return e.createElement("video",{src:f,controls:!0,style:{width:"100%",height:"100%",display:"block"},autoPlay:h.has("autoplay"),muted:c||h.has("muted")});case"youtube":return c&&o&&h.set("mute","1"),e.createElement("iframe",{src:`https://www.youtube.com/embed/${f}?${h.toString()}`,...m});case"vimeo":return c&&o&&h.set("muted","1"),e.createElement("iframe",{src:`https://player.vimeo.com/video/${f}?${h.toString()}`,...m});case"wistia":return h.set("videoFoam","true"),c&&o&&h.set("volume","0"),e.createElement(e.Fragment,null,e.createElement("iframe",{src:`https://fast.wistia.net/embed/iframe/${f}?${h.toString()}`,...m}))}};function Z(e){return"right"===e.align?"userflowjs-text-align-end":"center"===e.align?"userflowjs-text-align-center":""}function Y({widthMode:e,displayWidth:t,width:n,height:r,marginTop:l,marginRight:o,marginBottom:a,marginLeft:i,align:s}){const u={position:"relative"};"number"!=typeof t&&(t=100,e="percent"),"center"===s?(u.marginLeft="auto",u.marginRight="auto"):"right"===s&&(u.marginLeft="auto");let c=0;if(null!=l&&"number"==typeof l&&(u.marginTop=`${l}px`),null!=o&&"number"==typeof o&&(u.marginRight=`${o}px`,c+=o),null!=a&&"number"==typeof a&&(u.marginBottom=`${a}px`),null!=i&&"number"==typeof i&&(u.marginLeft=`${i}px`,c+=i),"number"!=typeof t||"number"!=typeof n||"number"!=typeof r)u.width="100px",u.height="100px";else if("px"===e){const e=10,l=Math.max(e,t);u.width=`${l}px`,u.height=l/(n/r)+"px"}else{const e=Math.max(0,Math.min(100,t));u.width=`calc(${e}% - ${c}px)`,u.height="0",u.paddingBottom=`calc((${e}% - ${c}px) / (${n} / ${r})`}return{wrapperStyle:u,blockStyle:{position:"absolute",top:"0",left:"0",display:"block",width:"100%",height:"100%"}}}function ee(e){return{display:"flex",alignItems:"stretch",marginRight:`-${null==e.spacing?16:e.spacing}px`}}function te(e,t){const n="fill"===e.widthMode||null==e.displayWidth;return{display:"flex",flexDirection:"column",justifyContent:e.justifyContent,width:n?void 0:"px"===e.widthMode?`${e.displayWidth||50}px`:"percent"===e.widthMode?`${e.displayWidth||50}%`:void 0,flex:n?"1 0 0":void 0,marginRight:`${null==t.spacing?16:t.spacing}px`,marginBottom:"0"}}function ne(e){return{display:"flex",flexDirection:"column",justifyContent:e.justifyContent,width:"px"===e.widthMode&&null!=e.displayWidth?`${e.displayWidth}px`:"percent"===e.widthMode&&null!=e.displayWidth?`${e.displayWidth}%`:void 0,minHeight:"px"===e.heightMode?`${e.displayHeight||50}px`:void 0,flex:"fill"===e.heightMode?"1 0 0":void 0,marginTop:null!=e.marginTop?`${e.marginTop}px`:void 0,marginRight:null!=e.marginRight?`${e.marginRight}px`:"fill"!==e.widthMode&&"center"===e.align?"auto":void 0,marginBottom:null!=e.marginBottom?`${e.marginBottom}px`:void 0,marginLeft:null!=e.marginLeft?`${e.marginLeft}px`:"fill"===e.widthMode||"center"!==e.align&&"right"!==e.align?void 0:"auto"}}function re(e,t){const n=e.attributeName;if("string"==typeof n){const r=t(n)||e.fallback;if("string"==typeof r)return r}return null}function le(e){return Array.isArray(e.children)&&void 0===e.addMark}function oe(e,t,n="type"){return le(e)&&e[n]===t}function ae(e){return"string"==typeof e.text}function ie(e,t){function n(e){e&&e.forEach(((e,r)=>e&&function(e,r){t(e,r),le(e)&&n(e.children)}(e,r)))}n(Array.isArray(e)?e:e.children)}const se=e.memo((({doc:t,lookupAttribute:n})=>t?e.createElement(e.Fragment,null,O(t,{lookupAttribute:n})):null));function ue(e,{buttons:t,questions:n}){const r=new Set,l=new Set;if(ie(e,(e=>{oe(e,"button")&&r.add(e.cvid),oe(e,"question")&&l.add(e.cvid)})),n){const t=n.filter((e=>!l.has(e.cvid)));t.length>0&&(e={...e,children:[...e.children,...t.map((e=>({type:"question",cvid:e.cvid,children:[{text:""}]})))]})}if(t){const n=t.filter((e=>!r.has(e.cvid)));n.length>0&&(e={...e,children:[...e.children,{type:"button-group",children:n.map((e=>({type:"button",cvid:e.cvid,children:[{text:""}]})))}]})}return e}function ce(e){return"userflowjs-bubble-button "+("primary"===(e=e||"default")||"PRIMARY"===e?"userflowjs-bubble-button--primary":"default"===e||"DEFAULT"===e?"userflowjs-bubble-button--default":e)}var de=new URL("flow-host.css",import.meta.url).href,me=new URL("bubble-frame.css",import.meta.url).href;const be=({draftMode:t,muted:n,toggleMuted:r,close:l,minimize:o})=>{const{t:a}=x();return e.createElement("div",{className:"userflowjs-bubble-toolbar"},t&&e.createElement("div",{className:"userflowjs-bubble-draft"},"string"==typeof t?t:"Preview"),r&&e.createElement("button",{className:"userflowjs-bubble-toolbar-button",onClick:r,"aria-label":n?"Unmute":"Mute"},n?e.createElement(g,null):e.createElement(v,null)),o&&e.createElement("button",{"data-testid":"minimize-button",className:"userflowjs-bubble-toolbar-button",onClick:o,"aria-label":"Minimize checklist"},e.createElement(E,null)),l&&e.createElement("button",{"data-testid":"close-button",className:"userflowjs-bubble-toolbar-button",onClick:l,"aria-label":a("menu.close")},e.createElement(y,null)))};export{be as B,W as R,q as S,se as a,me as b,C as c,F as d,N as e,de as f,re as g,I as h,ae as i,ue as m,U as r,O as s,S as u};
|
|
1
|
+
import{r as e}from"./vendor.react.js";import{c as t,a as n,i as r,b as l}from"./flow-condition-types.js";import{b as o}from"./stylesheets.js";import{o as a}from"./vendor.obj-str.js";import{l as i,n as s,S as u,E as c,c as d,s as m,U as b,p,d as f}from"./userflow.js";import{S as h,a as w,V as g,b as v,c as E,T as y}from"./Icons.js";import{F as k}from"./vendor.fortawesome.react-fontawesome.js";import{f as _}from"./vendor.fortawesome.pro-solid-svg-icons.js";import{u as x}from"./vendor.react-i18next.js";import{u as j}from"./client-context.js";const q=e.createContext(null);function N(){const t=e.useContext(q);if(!t)throw new Error("useSession: Session was not set");return t}function S(n){const r=N(),[l,a]=e.useState(!1),i=o(r.data),s=function(t){const n=e.useRef(t),r=e.useRef(t);return t!==r.current&&JSON.stringify(t)!==JSON.stringify(r.current)&&(n.current=t),r.current=t,n.current}(n);return e.useLayoutEffect((()=>{if(s){return t[s.type].track({sessionData:i,condition:s,callback:e=>{a(e)}})}}),[i,s]),null!=s&&l}const C=({appearance:t,hidden:n,disabled:r,onMouseDown:l,onClick:o,text:i,active:s,children:u})=>e.createElement("button",{className:a({[ce(t)]:!0,"userflowjs-bubble-button--hidden":!!n,"userflowjs-bubble-button--active":!!s}),onMouseDown:l,onClick:o,disabled:r},u||e.createElement("div",{className:"userflowjs-bubble-button-text",role:"presentation"},i));async function T(e,t,l){const{steps:o}=t.version;switch(l.type){case i.CLOSE_FLOW:switch(t.kind){case"launcher":await e.dismissLauncher(t,{endReason:c.ACTION});break;case"flow":case"checklist":await e.endFlow(t,{endReason:c.ACTION})}return;case i.EVAL_JS:try{const e=r(l.code||"",t.data);new Function('"use strict";\n'+e)()}catch(a){console.error(`Userflow.js: Evaluate JavaScript action failed.\n\nError:\n${a.stack||a.message||a}\n\nCode:\n${l.code}`)}return;case i.GO_TO_STEP:{if("flow"!==t.kind)return;const n=o.find((({crossVersionId:e})=>e===l.stepCvid));if(!n)throw new b("Action points to unknown step: "+l.stepCvid);return void(await e.goToStep(t,n))}case i.NAVIGATE:{if(!l.url)return void console.warn("Userflow.js: NAVIGATE action is missing url property");const e=O(l.url,{lookupAttribute:n(t.data)});return void(l.navigateTarget===s.NEW_TAB?window.open(e):d.customNavigate?d.customNavigate(e):window.setTimeout((()=>{m(e)}),0))}case i.SNOOZE:return void("flow"===t.kind&&l.timeValue&&l.timeUnit&&(e.endFlow(t,{endReason:c.SNOOZED,batch:!0}),t.draftMode?window.alert(`In preview mode, flows can't be snoozed.\n\nBut if this flow was running in published mode, the flow would now be snoozed for ${l.timeValue} ${l.timeUnit.toLowerCase()+(1===l.timeValue?"":"s")}.`):e.send({kind:"Snooze",flowId:t.flow.id,timeValue:l.timeValue,timeUnit:l.timeUnit},{batch:!0})));case i.START_FLOW:return"launcher"===t.kind&&e.deactivateLauncher(t),void(l.otherFlow?await e.startFlow({flowId:l.otherFlow.id,stepCvid:l.otherFlowStepCvid,startReason:t.draftMode?u.DRAFT:u.ACTION,replaceCurrent:!0}):console.warn("Userflow.js: START_FLOW action is missing other flow"))}}async function I(e,t,n){const r=[],l=[],o=[];for(const a of n)a.type===i.NAVIGATE?a.navigateTarget===s.NEW_TAB?r.push(a):o.push(a):l.push(a);for(const a of r)T(e,t,a);await Promise.all(l.map((n=>T(e,t,n))));for(const a of o)T(e,t,a)}const P=({button:t})=>{const n=j(),l=N(),o=S(t.disabledCondition),a=S(t.hiddenCondition);return e.createElement(C,{appearance:t.appearance,hidden:a,disabled:o,onClick:()=>I(n,l,t.actions),text:r(t.text,l.data)})},A=({type:t,required:n,buttonText:r,options:l,otherOption:o,multipleSelection:i,shuffleOptions:s,labelLeft:u,labelCenter:c,labelRight:d,minValue:m,maxValue:b,onSubmit:f,inert:g})=>{const{t:v}=x(),E=e.useRef(null),[y,j]=e.useState(""),[q,N]=e.useState(new Set),[S,C]=e.useState(),[T,I]=e.useState(),[P,A]=e.useState(!1),[$,M]=e.useState(!1),[R,F]=e.useState(null),O=e.useMemo((()=>l&&(s?[...l].sort((()=>Math.random()-.5)):l)),[l,s]),U=e=>{if(!g&&f){if(n&&""===y&&[p.MULTILINE_TEXT,p.TEXT].includes(t))return F(v("question.requiredError")),void W();M(!0),F(null),f({...e,onCancel:()=>{M(!1)},onError:e=>{M(!1),F(e||"Sorry, something went wrong saving your answer. Please try again.")}})}},W=e.useCallback((()=>{!g&&E.current&&E.current.focus()}),[g]),[B,V]=e.useState(!1);e.useEffect((()=>{B&&(W(),V(!1))}),[W,B]);const D=e.createElement("div",{className:"userflowjs-bubble-question__button-row userflowjs-bubble-question__button-row--end"},e.createElement("button",{className:"userflowjs-bubble-button userflowjs-bubble-button--primary",onClick:()=>U({answer:{kind:"text",value:y}}),tabIndex:g?-1:void 0,disabled:$},e.createElement("div",{className:"userflowjs-bubble-button-text",role:"presentation"},r||v("question.submit"))));let z=null,K=0;if(t===p.NPS)u=u||v("question.npsLabelLeft"),d=d||v("question.npsLabelRight"),z=[0,1,2,3,4,5,6,7,8,9,10],K=z.length;else if([p.SCALE,p.STARS].includes(t)){b=null!=b?b:5,z=[];for(let e=m=null!=m?m:1;e<=b;e++)z.push(e);K=z.length}else t===p.MULTIPLE_CHOICE&&(K=(O?O.length:0)+(o&&!P?1:0));const[J,H]=e.useState(-1),G=-1===J?-1:Math.min(J,K-1),X=e=>{if(!e.target.closest('[role="radio"], [role="checkbox"], [role="radiogroup"], [role="group"]'))return;let t=null;if("ArrowRight"===e.key||"ArrowDown"===e.key?t=1:"ArrowLeft"!==e.key&&"ArrowUp"!==e.key||(t=-1),null!=t){e.preventDefault();const n=e.currentTarget.querySelectorAll('[role="radio"], [role="checkbox"]');let r=G+t;r<0?r=n.length-1:r>n.length-1&&(r=0),H(r),n[r].focus()}};let Q,Z=null,Y=null;if(z&&(u||c||d)){const t=[];u&&t.push(z[0],u),d&&t.push(z[z.length-1],d),Z=e.createElement("div",{id:"a11y-scale-labels",className:"userflowjs-a11y-only"},t.join(", ")),Y=e.createElement("div",{id:"userflowjs-bubble-question-labels",className:"userflowjs-bubble-question__scale-labels","aria-hidden":"true"},e.createElement("div",{className:"userflowjs-bubble-question__scale-label"},u),c&&e.createElement("div",{className:"userflowjs-bubble-question__scale-label userflowjs-bubble-question__scale-label--center"},c),e.createElement("div",{className:"userflowjs-bubble-question__scale-label userflowjs-bubble-question__scale-label--right"},d))}switch(t){case p.MULTILINE_TEXT:Q=e.createElement(e.Fragment,null,e.createElement("textarea",{ref:E,className:"userflowjs-textarea userflowjs-bubble-question__textarea",value:y,onChange:e=>j(e.target.value),onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&U({answer:{kind:"text",value:y}})},placeholder:v("question.placeholder"),readOnly:g||$,tabIndex:g?-1:void 0,rows:3,"aria-required":n?"true":void 0,"aria-invalid":null!=R?"true":void 0}),D);break;case p.MULTIPLE_CHOICE:{const t=()=>{y&&U({answer:{kind:"text",value:y},animationPromise:L()})},n=(O?.length||0)+(o?1:0),l=Math.max(0,Math.min(n,null==m?1:m)),s=Math.max(0,Math.min(n,null==b?n:b)),u=()=>{const e=(O||[]).filter(((e,t)=>q.has(t))).map((e=>e.value));o&&P&&""!==y&&e.push(y),l!==s||e.length===l?e.length<l?F(v("question.multiple_selection_too_few",{count:l})):e.length>s?F(v("question.multiple_selection_too_many",{count:s})):U({answer:{kind:"list",values:e}}):F(v("question.multiple_selection_wrong",{count:l}))};Q=e.createElement(e.Fragment,null,i&&e.createElement("div",{className:a({"userflowjs-bubble-question__multiple-choice-hint":!0,"userflowjs-bubble-question__multiple-choice-hint--error":!!R})},v("question.multiple_selection_hint",{replace:{selected:q.size+(o&&P&&""!==y?1:0),range:l===s?l:`${l}-${s}`}}),R&&e.createElement(e.Fragment,null,". ",e.createElement("span",{role:"alert"},R))),e.createElement("div",{className:a({"userflowjs-bubble-question__multiple-choice":!0,"userflowjs-bubble-question__multiple-choice--single-selection":!i,"userflowjs-bubble-question__multiple-choice--multiple-selection":!!i,"userflowjs-bubble-question__multiple-choice--other-option-active":!!o&&P}),role:i?"group":"radiogroup",tabIndex:g||-1!==G?-1:0,onKeyDown:X},O?.map((({value:t,label:n},r)=>e.createElement("button",{key:r,className:a({"userflowjs-bubble-question__multiple-choice-option":!0,"userflowjs-bubble-question__multiple-choice-option--selected":i?q.has(r):$&&!P&&y==t}),onClick:$?void 0:()=>{if(i){F(null);const e=new Set(q);q.has(r)?e.delete(r):e.add(r),N(e)}else A(!1),j(t),U({answer:{kind:"text",value:t},animationPromise:L()})},disabled:$,tabIndex:g||r!==G?-1:0,role:i?"checkbox":"radio","aria-label":n||t,"aria-checked":!P&&y==t},i?e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-checkbox"},e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-checkbox-inner"},e.createElement(k,{icon:_}))):e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-radio"},e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-radio-inner"})),e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-option-text","aria-hidden":"true"},n||t)))),o&&(P?e.createElement("div",{className:a({"userflowjs-bubble-question__multiple-choice-option":!0,"userflowjs-bubble-question__multiple-choice-option--other":!0,"userflowjs-bubble-question__multiple-choice-option--selected":i?""!=y:$})},i?e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-checkbox",onClick:()=>{j(""),A(!1)}},e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-checkbox-inner"},e.createElement(k,{icon:_}))):e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-radio"},e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-radio-inner"})),e.createElement("input",{ref:E,className:"userflowjs-bubble-question__multiple-choice-option-input",value:y,onChange:e=>j(e.target.value),onKeyDown:e=>{e.shiftKey||"Enter"!==e.key?"Escape"===e.key&&(e.stopPropagation(),j(""),A(!1)):i?u():t()},onBlur:()=>{""===y&&A(!1)},placeholder:v("question.placeholder"),readOnly:g||$,tabIndex:g?-1:void 0}),!i&&e.createElement("button",{"data-testid":"multiple-choice-other-submit",className:"userflowjs-bubble-question__multiple-choice-option-submit",onClick:()=>t(),disabled:$,"aria-label":v("question.submit")},e.createElement(w,null))):e.createElement("button",{className:"userflowjs-bubble-question__multiple-choice-option",onClick:$?void 0:()=>{F(null),A(!0),V(!0)},disabled:$,tabIndex:g||O?.length!==G?-1:0,role:"radio","aria-label":v("question.other"),"aria-checked":"false"},i?e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-checkbox"},e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-checkbox-inner"},e.createElement(k,{icon:_}))):e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-radio"},e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-radio-inner"})),e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-option-text","aria-hidden":"true"},v("question.other"))))),i&&e.createElement("div",{className:"userflowjs-bubble-question__button-row"},e.createElement("button",{className:"userflowjs-bubble-button userflowjs-bubble-button--primary",onClick:u,tabIndex:g?-1:void 0,disabled:$},e.createElement("div",{className:"userflowjs-bubble-button-text",role:"presentation"},r||v("question.submit")))));break}case p.NPS:case p.SCALE:Q=e.createElement(e.Fragment,null,Z,e.createElement("div",{className:"userflowjs-bubble-question__scale-options",role:"radiogroup",tabIndex:g||-1!==G?-1:0,onKeyDown:X},z?.map(((t,n)=>e.createElement("button",{className:a({"userflowjs-bubble-question__scale-option":!0,"userflowjs-bubble-question__scale-option--selected":$&&S==t}),key:t,tabIndex:g||n!==G?-1:0,onClick:()=>{C(t),U({answer:{kind:"number",value:t},animationPromise:L()})},disabled:$,role:"radio","aria-checked":S==t},t)))),Y);break;case p.STARS:Q=e.createElement("div",{className:"userflowjs-bubble-question__stars-wrapper"},Z,e.createElement("div",{className:"userflowjs-bubble-question__stars",role:"radiogroup",tabIndex:g||-1!==G?-1:0,onKeyDown:X},z?.map(((t,n)=>e.createElement("button",{className:a({"userflowjs-bubble-question__star":!0,"userflowjs-bubble-question__star--hovered":!$&&null!=T&&T>=t,"userflowjs-bubble-question__star--selected":$&&null!=S&&S>=t,"userflowjs-bubble-question__star--not-selected":$&&null!=S&&S<t}),key:t,tabIndex:g||n!==G?-1:0,onClick:()=>{C(t),U({answer:{kind:"number",value:t},animationPromise:L()})},onMouseOver:()=>I(t),onMouseLeave:()=>I(null),disabled:$,role:"radio","aria-checked":S==t,"aria-label":String(t)},e.createElement("div",{className:"userflowjs-bubble-question__star-icon","aria-hidden":"true"},e.createElement(h,null)),e.createElement("div",{className:"userflowjs-bubble-question__star-value","aria-hidden":"true"},t))))),Y);break;case p.TEXT:Q=e.createElement(e.Fragment,null,e.createElement("input",{ref:E,className:"userflowjs-text-input userflowjs-bubble-question__text-input",value:y,onChange:e=>j(e.target.value),onKeyDown:e=>{e.shiftKey||"Enter"!==e.key||U({answer:{kind:"text",value:y}})},placeholder:v("question.placeholder"),readOnly:g||$,tabIndex:g?-1:void 0,"aria-required":n?"true":void 0,"aria-invalid":null!=R?"true":void 0}),D)}return e.createElement("div",{className:"userflowjs-bubble-question",style:{pointerEvents:g?"none":void 0}},R&&!(t===p.MULTIPLE_CHOICE&&i)&&e.createElement("div",{className:"userflowjs-bubble-question__error",role:"alert"},R),Q)};function L(){return new Promise((e=>window.setTimeout(e,250)))}const $=({question:t})=>{const n=j(),r=function(){const e=N();if("flow"!==e.kind)throw new Error("useFlowSession: Wrong session kind");return e}();return e.createElement(A,{type:t.type,required:!!t.required,buttonText:t.buttonText||"",options:t.options,otherOption:t.otherOption,multipleSelection:t.multipleSelection,shuffleOptions:t.shuffleOptions,labelLeft:t.labelLeft||"",labelCenter:t.labelCenter||"",labelRight:t.labelRight||"",minValue:t.minValue,maxValue:t.maxValue,onSubmit:async e=>{f("answerQuestion",r.id,t.cvid,e);const{answer:l}=e;try{await Promise.all([await n.send({kind:"AnswerQuestion",sessionId:r.id,questionName:t.name,questionCvid:t.cvid,textAnswer:"text"==l.kind?l.value:null,numberAnswer:"number"==l.kind?String(l.value):null,listAnswer:"list"==l.kind?l.values:null}),e.animationPromise])}catch(a){return console.log("Userflow.js: Error when answering question:",a),void e.onError()}const{bindAttributeFqn:o}=t;if(o&&n.flowSession?.id===r.id){let e;switch(l.kind){case"text":e={name:o,value:l.value};break;case"number":e={name:o,value:String(l.value)};break;case"list":e={name:o,value:l.values}}n.optimisticClockUIUpdate((()=>{n.setFlowSession({...r,data:[...r.data.filter((e=>e.name!==o)),e]})}))}I(n,r,t.actions)}})},M=({text:t})=>{if(!t)return null;const n=t.split(/\n/);return 1===n.length?e.createElement(e.Fragment,null,n[0]):e.createElement(e.Fragment,null,n.map(((t,n)=>e.createElement(e.Fragment,{key:n},n>0&&e.createElement("br",null),t))))};function R(e=""){return{type:"paragraph",children:[{text:e}]}}function F(e){if(e){let n;try{n=JSON.parse(e)}catch(t){throw new Error("Could not JSON.parse rich content doc: "+e)}if("rich2"===n.type)return n;throw new Error("Could not recognize rich content doc: "+e)}return function(e=""){return{type:"rich2",children:[R(e)]}}()}function O(e,{lookupAttribute:t}){if(!e)return"";"string"==typeof e&&(e=function(e){if(e){let n;try{n=JSON.parse(e)}catch(t){throw new Error("Could not JSON.parse plaintext doc: "+e)}if("plaintext2"===n.type)return n;throw new Error("Could not recognize plaintext doc: "+e)}return function(e=""){return{type:"plaintext2",children:[{type:"plaintext",children:[{text:e}]}]}}()}(e));const n=[];function r(e){e&&e.forEach((e=>e&&function(e){if(ae(e))e.text&&n.push(e.text);else switch(e.type){case"attribute":{const r=re(e,t);r&&n.push(r);break}default:r(e.children)}}(e)))}return r(e.children),n.join("")}function U(e){let t=!0;if(!e)return!0;"string"==typeof e&&(e=F(e));const n=new Set(["attribute","button","image","question","video"]);return ie(e,(e=>{ae(e)?""!==e.text&&(t=!1):"type"in e&&n.has(e.type)&&(t=!1)})),t}const W=e.memo((({doc:t,...n})=>t?("string"==typeof t&&(t=F(t)),e.createElement(B,{parent:t,...n})):null)),B=({parent:t,...n})=>e.createElement(e.Fragment,null,t.children.map(((r,l)=>ae(r)?e.createElement(V,{key:l,node:r}):e.createElement(z,{key:l,node:r,parent:t,...n})))),V=({node:t})=>t.text?e.createElement(D,{node:t},e.createElement(M,{text:t.text})):null,D=({node:t,children:n})=>(t.color&&"string"==typeof t.color&&(n=e.createElement("span",{style:{color:t.color}},n)),t.bold&&(n=e.createElement("b",null,n)),t.italic&&(n=e.createElement("i",null,n)),t.underline&&(n=e.createElement("u",null,n)),t.strikeThrough&&(n=e.createElement("s",null,n)),t.code&&(n=e.createElement("code",null,n)),t.sup&&(n=e.createElement("sup",null,n)),n),z=({node:t,parent:n,...r})=>{const{lookupAttribute:l}=r,o=e.createElement(B,{parent:t,...r});switch(t.type){case"attribute":return e.createElement(K,{node:t,...r});case"button":return e.createElement(J,{node:t,...r});case"button-group":return e.createElement("div",{className:"userflowjs-bubble-buttons"},o);case"column":return e.createElement("div",{style:te(t,n)},o);case"column-group":return e.createElement("div",{className:"p-like",style:ee(t)},o);case"container":return e.createElement("div",{className:"p-like"+(t.className?` ${t.className}`:""),style:ne(t)},o);case"image":return e.createElement(G,{node:t,...r});case"link":return e.createElement("a",{href:O(t.href,{lookupAttribute:l}),target:"_blank",rel:"noopener noreferrer"},o);case"paragraph":return e.createElement("p",{className:Z(t)},o);case"heading1":return e.createElement("h1",{className:Z(t)},o);case"heading2":return e.createElement("h2",{className:Z(t)},o);case"question":return e.createElement(H,{node:t,...r});case"quote":return e.createElement("blockquote",null,o);case"code-block":return e.createElement("pre",null,e.createElement("code",null,o));case"ordered-list":return e.createElement("ol",null,o);case"unordered-list":return e.createElement("ul",null,o);case"list-item":return e.createElement("li",null,o);case"video":return e.createElement(X,{node:t,...r});default:return e.createElement("div",null,o)}},K=({node:t,lookupAttribute:n})=>{let r=re(t,n);return e.createElement(D,{node:t},r)},J=({node:t,buttons:n})=>{const r=n?.find((e=>e.cvid===t.cvid));return r?e.createElement(P,{key:r.id,button:r}):null},H=({node:t,questions:n})=>{const r=n?.find((e=>e.cvid===t.cvid));return r?e.createElement($,{key:r.id,question:r}):null},G=({node:t,lookupAttribute:n})=>{const{src:r,widthMode:l,displayWidth:o,width:a,height:i,marginTop:s,marginRight:u,marginBottom:c,marginLeft:d,align:m,hasLink:b,href:p}=t;if("string"!=typeof r||!r)return null;const{wrapperStyle:f,blockStyle:h}=Y({widthMode:l,displayWidth:o,width:a,height:i,marginTop:s,marginRight:u,marginBottom:c,marginLeft:d,align:m});let w=e.createElement("img",{src:r,style:{...h,objectFit:"contain"}});return b&&p&&(w=e.createElement("a",{href:O(p,{lookupAttribute:n}),target:"_blank",rel:"noopener noreferrer",style:h},w)),e.createElement("div",{className:"p-like"},e.createElement("div",{style:f},w))},X=({node:t,lookupAttribute:n})=>{const{url:r,widthMode:l,displayWidth:o,width:a,height:i,marginTop:s,marginRight:u,marginBottom:c,marginLeft:d,align:m}=t;if("string"!=typeof r||!r)return null;const{wrapperStyle:b,blockStyle:p}=Y({widthMode:l,displayWidth:o,width:a,height:i,marginTop:s,marginRight:u,marginBottom:c,marginLeft:d,align:m});return e.createElement("div",{className:"p-like"},e.createElement("div",{style:b},e.createElement("div",{style:p},e.createElement(Q,{element:t,noFocus:!0,lookupAttribute:n}))))},Q=({element:{embedType:t,url:n,src:r,autoPlay:o,controls:a,loop:i,muted:s},noFocus:u,forceMuted:c,lookupAttribute:d})=>{if(!n)return null;const m={width:"100%",height:"100%",frameBorder:"0",allow:"accelerometer; autoplay; fullscreen; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0,allowtransparency:"true",mozallowfullscreen:"true",webkitallowfullscreen:"true",oallowfullscreen:"true",msallowfullscreen:"true",style:{display:"block"},tabIndex:u?-1:void 0};if("video"===t)return e.createElement("video",{key:n+";"+String(o)+";"+String(a)+";"+String(i)+";"+String(s),src:n,style:{width:"100%",height:"100%",display:"block"},autoPlay:!!o,controls:!1!==a,loop:i,muted:c||s});if(r){let t;try{t=new URL(r)}catch(w){return null}return c&&(t.searchParams.has("autoplay")||t.searchParams.has("autoPlay"))&&(t.searchParams.set("mute","1"),t.searchParams.set("muted","1"),t.searchParams.set("volume","0")),e.createElement("iframe",{src:t.toString(),...m})}let b=function(e,{iframeFallback:t}={}){let n;try{n=new URL(e)}catch(w){return{kind:"invalid"}}const{hostname:r,pathname:l,searchParams:o}=n;if(r.match(/^(www\.)?(use)?loom\.com$/)){const e=l.match(/^\/share\/([a-z0-9]+)$/i);if(e){const[,t]=e;return{kind:"ok",videoProvider:"loom",videoId:t,searchParams:o}}}if(e.startsWith("raw:")){return{kind:"ok",videoProvider:"raw",videoId:e.replace(/^raw:/,""),searchParams:o}}if(e.startsWith("iframe:")){return{kind:"ok",videoProvider:"iframe",videoId:e.replace(/^iframe:/,""),searchParams:o}}if(["youtube.com","www.youtube.com"].includes(r)){const e=o.get("v");if(e)return o.delete("v"),{kind:"ok",videoProvider:"youtube",videoId:e,searchParams:o}}if("youtu.be"===r){const e=l.match(/^\/([^/]+)$/);if(e){const[,t]=e;return{kind:"ok",videoProvider:"youtube",videoId:t,searchParams:o}}}if("vimeo.com"===r){const e=l.match(/^\/(\d+)$/);if(e){const[,t]=e;return{kind:"ok",videoProvider:"vimeo",videoId:t,searchParams:o}}}if("player.vimeo.com"===r){const e=l.match(/^\/video\/([^/]+)$/);if(e){const[,t]=e;return{kind:"ok",videoProvider:"vimeo",videoId:t,searchParams:o}}}if(r.match(/^[^.]+\.wistia.com$/)){const e=l.match(/^\/medias\/([^/]+)$/);if(e){const[,t]=e;return{kind:"ok",videoProvider:"wistia",videoId:t,searchParams:o}}}return t?{kind:"ok",videoProvider:"iframe",videoId:e,searchParams:o}:{kind:"invalid"}}(n,{iframeFallback:!0});if("invalid"===b.kind)return null;const{videoProvider:p,videoId:f,searchParams:h}=b;switch(o=o||h.has("autoplay")||h.has("autoPlay"),p){case"iframe":return e.createElement("iframe",{src:l(f,(e=>encodeURIComponent(d(e)||""))),scrolling:h.get("scrolling")||void 0,...m});case"loom":return e.createElement("iframe",{src:`https://www.loom.com/embed/${f}?${h.toString()}`,...m});case"raw":return e.createElement("video",{src:f,controls:!0,style:{width:"100%",height:"100%",display:"block"},autoPlay:h.has("autoplay"),muted:c||h.has("muted")});case"youtube":return c&&o&&h.set("mute","1"),e.createElement("iframe",{src:`https://www.youtube.com/embed/${f}?${h.toString()}`,...m});case"vimeo":return c&&o&&h.set("muted","1"),e.createElement("iframe",{src:`https://player.vimeo.com/video/${f}?${h.toString()}`,...m});case"wistia":return h.set("videoFoam","true"),c&&o&&h.set("volume","0"),e.createElement(e.Fragment,null,e.createElement("iframe",{src:`https://fast.wistia.net/embed/iframe/${f}?${h.toString()}`,...m}))}};function Z(e){return"right"===e.align?"userflowjs-text-align-end":"center"===e.align?"userflowjs-text-align-center":""}function Y({widthMode:e,displayWidth:t,width:n,height:r,marginTop:l,marginRight:o,marginBottom:a,marginLeft:i,align:s}){const u={position:"relative"};"number"!=typeof t&&(t=100,e="percent"),"center"===s?(u.marginLeft="auto",u.marginRight="auto"):"right"===s&&(u.marginLeft="auto");let c=0;if(null!=l&&"number"==typeof l&&(u.marginTop=`${l}px`),null!=o&&"number"==typeof o&&(u.marginRight=`${o}px`,c+=o),null!=a&&"number"==typeof a&&(u.marginBottom=`${a}px`),null!=i&&"number"==typeof i&&(u.marginLeft=`${i}px`,c+=i),"number"!=typeof t||"number"!=typeof n||"number"!=typeof r)u.width="100px",u.height="100px";else if("px"===e){const e=10,l=Math.max(e,t);u.width=`${l}px`,u.height=l/(n/r)+"px"}else{const e=Math.max(0,Math.min(100,t));u.width=`calc(${e}% - ${c}px)`,u.height="0",u.paddingBottom=`calc((${e}% - ${c}px) / (${n} / ${r})`}return{wrapperStyle:u,blockStyle:{position:"absolute",top:"0",left:"0",display:"block",width:"100%",height:"100%"}}}function ee(e){return{display:"flex",alignItems:"stretch",marginRight:`-${null==e.spacing?16:e.spacing}px`}}function te(e,t){const n="fill"===e.widthMode||null==e.displayWidth;return{display:"flex",flexDirection:"column",justifyContent:e.justifyContent,width:n?void 0:"px"===e.widthMode?`${e.displayWidth||50}px`:"percent"===e.widthMode?`${e.displayWidth||50}%`:void 0,flex:n?"1 0 0":void 0,marginRight:`${null==t.spacing?16:t.spacing}px`,marginBottom:"0"}}function ne(e){return{display:"flex",flexDirection:"column",justifyContent:e.justifyContent,width:"px"===e.widthMode&&null!=e.displayWidth?`${e.displayWidth}px`:"percent"===e.widthMode&&null!=e.displayWidth?`${e.displayWidth}%`:void 0,minHeight:"px"===e.heightMode?`${e.displayHeight||50}px`:void 0,flex:"fill"===e.heightMode?"1 0 0":void 0,marginTop:null!=e.marginTop?`${e.marginTop}px`:void 0,marginRight:null!=e.marginRight?`${e.marginRight}px`:"fill"!==e.widthMode&&"center"===e.align?"auto":void 0,marginBottom:null!=e.marginBottom?`${e.marginBottom}px`:void 0,marginLeft:null!=e.marginLeft?`${e.marginLeft}px`:"fill"===e.widthMode||"center"!==e.align&&"right"!==e.align?void 0:"auto"}}function re(e,t){const n=e.attributeName;if("string"==typeof n){const r=t(n)||e.fallback;if("string"==typeof r)return r}return null}function le(e){return Array.isArray(e.children)&&void 0===e.addMark}function oe(e,t,n="type"){return le(e)&&e[n]===t}function ae(e){return"string"==typeof e.text}function ie(e,t){function n(e){e&&e.forEach(((e,r)=>e&&function(e,r){t(e,r),le(e)&&n(e.children)}(e,r)))}n(Array.isArray(e)?e:e.children)}const se=e.memo((({doc:t,lookupAttribute:n})=>t?e.createElement(e.Fragment,null,O(t,{lookupAttribute:n})):null));function ue(e,{buttons:t,questions:n}){const r=new Set,l=new Set;if(ie(e,(e=>{oe(e,"button")&&r.add(e.cvid),oe(e,"question")&&l.add(e.cvid)})),n){const t=n.filter((e=>!l.has(e.cvid)));t.length>0&&(e={...e,children:[...e.children,...t.map((e=>({type:"question",cvid:e.cvid,children:[{text:""}]})))]})}if(t){const n=t.filter((e=>!r.has(e.cvid)));n.length>0&&(e={...e,children:[...e.children,{type:"button-group",children:n.map((e=>({type:"button",cvid:e.cvid,children:[{text:""}]})))}]})}return e}function ce(e){return"userflowjs-bubble-button "+("primary"===(e=e||"default")||"PRIMARY"===e?"userflowjs-bubble-button--primary":"default"===e||"DEFAULT"===e?"userflowjs-bubble-button--default":e)}var de=new URL("flow-host.css",import.meta.url).href,me=new URL("bubble-frame.css",import.meta.url).href;const be=({draftMode:t,muted:n,toggleMuted:r,close:l,minimize:o})=>{const{t:a}=x();return e.createElement("div",{className:"userflowjs-bubble-toolbar"},t&&e.createElement("div",{className:"userflowjs-bubble-draft"},"string"==typeof t?t:"Preview"),r&&e.createElement("button",{className:"userflowjs-bubble-toolbar-button",onClick:r,"aria-label":n?"Unmute":"Mute"},n?e.createElement(g,null):e.createElement(v,null)),o&&e.createElement("button",{"data-testid":"minimize-button",className:"userflowjs-bubble-toolbar-button",onClick:o,"aria-label":"Minimize checklist"},e.createElement(E,null)),l&&e.createElement("button",{"data-testid":"close-button",className:"userflowjs-bubble-toolbar-button",onClick:l,"aria-label":a("menu.close")},e.createElement(y,null)))};export{be as B,W as R,q as S,se as a,me as b,C as c,F as d,N as e,de as f,re as g,I as h,ae as i,ue as m,U as r,O as s,S as u};
|
package/hash.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
80241ffbf593379fee93565682f73ab084495edf
|
package/package.json
CHANGED
package/userflow.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e}from"./vendor.phoenix.js";import{v as t}from"./vendor.uuid.js";let s;const i={},n=function(e,t){if(!t)return e();if(void 0===s){const e=document.createElement("link").relList;s=e&&e.supports&&e.supports("modulepreload")?"modulepreload":"preload"}return Promise.all(t.map((e=>{if(e in i)return;i[e]=!0;const t=e.endsWith(".css"),n=t?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${e}"]${n}`))return;const o=document.createElement("link");return o.rel=t?"stylesheet":s,t||(o.as="script",o.crossOrigin=""),o.href=e,document.head.appendChild(o),t?new Promise(((e,t)=>{o.addEventListener("load",e),o.addEventListener("error",t)})):void 0}))).then((()=>e()))};class o extends Error{constructor(e,t){super(e),Object.setPrototypeOf(this,o.prototype),this.name="UserflowError",this.code=t}}class r{constructor(e){this.type=e,this.testState={}}formatKey(e){return`userflow:${e}`}getItem(e){return e=this.formatKey(e),"undefined"==typeof window?null:window[this.type].getItem(e)}setItem(e,t){e=this.formatKey(e),"undefined"!=typeof window&&window[this.type].setItem(e,t)}removeItem(e){if(e=this.formatKey(e),"undefined"!=typeof window)return window[this.type].removeItem(e)}clear(){if("undefined"!=typeof window)return window[this.type].clear()}}const a=new r("localStorage"),c=new r("sessionStorage");function l(e){window.location.href=e}function d(){return window.location.href}var h,u,f;function E(e,t,{toOrigin:s}={}){e.postMessage(t,s||"*")}function T(e,{fromWindow:t,fromOrigin:s}={}){const i=i=>{if(!i.isTrusted)return;if(t&&t!==i.source)return;if(s&&i.origin!==s)return;const o=i.data;o&&"object"==typeof o&&"string"==typeof o.kind&&o.kind.startsWith("userflow:")&&!0===e(o)&&n()};window.addEventListener("message",i);const n=()=>window.removeEventListener("message",i);return n}(h||(h={})).INPUT="INPUT",(f=u||(u={})).AUTO="AUTO",f.MANUAL="MANUAL";const w=new Set;let p=!1;function S(e){return function(){if(p)return;p=!0;const{history:e}=window,t=t=>{const s=e[t];e[t]=(...t)=>{s.apply(e,t),C()}};t("pushState"),t("replaceState"),window.addEventListener("popstate",(()=>{C()}))}(),w.add(e),()=>{g(e)}}function g(e){w.delete(e)}function C(){w.forEach((e=>e()))}class m{destroy(){this.unregisterOnMessage&&this.unregisterOnMessage()}postBuilderMessage(e){E(window.opener,e,{toOrigin:"https://userflow.com"})}onBuilderMessage(e){return this.unregisterOnMessage=T(e,{fromOrigin:"https://userflow.com"}),!1}async captureScreenshot(e,t,s,i){E(window,{kind:"userflow:crxScreenshot",x:e,y:t,width:s,height:i,devicePixelRatio:window.devicePixelRatio});var n;return(await(n=e=>"userflow:crxScreenshotResult"===e.kind?e:null,new Promise((e=>{T((t=>{const s=n(t);return!!s&&(e(s),!0)}))})))).imageDataUrl}}var I,k,U,A,L,y,R,O,v,N,_,b,D,F,M,P,B,x,H,G,W,$,V,j,K,z,Y,J,X,Q,Z,q,ee,te,se,ie,ne,oe,re,ae,ce,le,de,he,ue,fe,Ee,Te,we,pe,Se,ge,Ce,me,Ie,ke,Ue,Ae,Le,ye,Re,Oe,ve,Ne,_e,be,De,Fe,Me,Pe;(k=I||(I={})).ACTION="ACTION",k.LAUNCHER_DEACTIVATED="LAUNCHER_DEACTIVATED",k.REPLACED="REPLACED",k.SNOOZED="SNOOZED",k.TOOLTIP_TARGET_MISSING="TOOLTIP_TARGET_MISSING",k.USERFLOWJS="USERFLOWJS",k.USER_CLOSED="USER_CLOSED",(A=U||(U={})).SECOND="SECOND",A.MINUTE="MINUTE",A.HOUR="HOUR",A.DAY="DAY",(y=L||(L={})).ACTION="ACTION",y.DRAFT="DRAFT",y.LINK="LINK",y.LAUNCHER_SEEN="LAUNCHER_SEEN",y.RESOURCE_CENTER="RESOURCE_CENTER",y.USERFLOWJS="USERFLOWJS",(O=R||(R={})).STRING="STRING",O.BOOLEAN="BOOLEAN",O.NUMBER="NUMBER",O.DATETIME="DATETIME",O.LIST="LIST",(N=v||(v={})).FLOW="FLOW",N.CHECKLIST="CHECKLIST",N.LAUNCHER="LAUNCHER",N.RESOURCE_CENTER="RESOURCE_CENTER",(b=_||(_={})).ALWAYS_TRUE="ALWAYS_TRUE",b.ATTRIBUTE="ATTRIBUTE",b.CLAUSE="CLAUSE",b.ELEMENT="ELEMENT",b.FILLED_IN_INPUT="FILLED_IN_INPUT",b.FLOW="FLOW",b.INPUT_VALUE="INPUT_VALUE",b.PAGE="PAGE",b.TIME="TIME",function(e){e.AUTO="AUTO",e.MANUAL="MANUAL"}(D||(D={})),(F||(F={})).INPUT="INPUT",(P=M||(M={})).ABSOLUTE_EQ="ABSOLUTE_EQ",P.ABSOLUTE_GT="ABSOLUTE_GT",P.ABSOLUTE_LT="ABSOLUTE_LT",P.AND="AND",P.CONTAINS="CONTAINS",P.EMPTY="EMPTY",P.ENDS_WITH="ENDS_WITH",P.EQ="EQ",P.EXCLUDES_ALL="EXCLUDES_ALL",P.EXCLUDES_ANY="EXCLUDES_ANY",P.FALSE="FALSE",P.GT="GT",P.INCLUDES_ALL="INCLUDES_ALL",P.INCLUDES_ANY="INCLUDES_ANY",P.LT="LT",P.NE="NE",P.NOT_CONTAINS="NOT_CONTAINS",P.NOT_EMPTY="NOT_EMPTY",P.NOT_REGEX="NOT_REGEX",P.OR="OR",P.REGEX="REGEX",P.RELATIVE_EQ="RELATIVE_EQ",P.RELATIVE_GT="RELATIVE_GT",P.RELATIVE_LT="RELATIVE_LT",P.STARTS_WITH="STARTS_WITH",P.TRUE="TRUE",P.URL="URL",(x=B||(B={})).CLICK="CLICK",x.DISABLED="DISABLED",x.MOUSEDOWN="MOUSEDOWN",x.NOT_CLICK="NOT_CLICK",x.NOT_DISABLED="NOT_DISABLED",x.NOT_PRESENT="NOT_PRESENT",x.PRESENT="PRESENT",(G=H||(H={})).ASSET="ASSET",G.CARTOON="CARTOON",G.NONE="NONE",G.URL="URL",($=W||(W={})).INSIDE="INSIDE",$.OUTSIDE="OUTSIDE",(j=V||(V={})).TOP_LEFT="TOP_LEFT",j.TOP_CENTER="TOP_CENTER",j.TOP_RIGHT="TOP_RIGHT",j.BOTTOM_RIGHT="BOTTOM_RIGHT",j.BOTTOM_CENTER="BOTTOM_CENTER",j.BOTTOM_LEFT="BOTTOM_LEFT",j.CENTER="CENTER",(z=K||(K={})).GOOGLE="GOOGLE",z.STANDARD="STANDARD",(J=Y||(Y={})).DISMISS_FIRST_MENU_AFTER="DISMISS_FIRST_MENU_AFTER",J.DISMISS="DISMISS",(Q=X||(X={})).DISMISS="DISMISS",Q.NONE="NONE",(q=Z||(Z={})).DEFAULT="DEFAULT",q.PLAINTEXT="PLAINTEXT",(te=ee||(ee={})).CHECKLIST_OVERRIDE="CHECKLIST_OVERRIDE",te.RESOURCE_CENTER_ONLY="RESOURCE_CENTER_ONLY",te.NONE="NONE",(ie=se||(se={})).BUBBLE="BUBBLE",ie.END="END",ie.ERROR="ERROR",ie.FLAG="FLAG",(oe=ne||(ne={})).MANUAL="MANUAL",oe.NONE="NONE",oe.SYNTHETIC="SYNTHETIC",(ae=re||(re={})).BUBBLE="BUBBLE",ae.HIDDEN="HIDDEN",ae.MODAL="MODAL",ae.TOOLTIP="TOOLTIP",(le=ce||(ce={})).ABOVE="ABOVE",le.BELOW="BELOW",le.LEFT="LEFT",le.RIGHT="RIGHT",(he=de||(de={})).CLOSE_FLOW="CLOSE_FLOW",he.EVAL_JS="EVAL_JS",he.GO_TO_STEP="GO_TO_STEP",he.NAVIGATE="NAVIGATE",he.SNOOZE="SNOOZE",he.START_FLOW="START_FLOW",(fe=ue||(ue={})).NEW_TAB="NEW_TAB",fe.SAME_TAB="SAME_TAB",(Te=Ee||(Ee={})).MULTILINE_TEXT="MULTILINE_TEXT",Te.MULTIPLE_CHOICE="MULTIPLE_CHOICE",Te.NPS="NPS",Te.SCALE="SCALE",Te.STARS="STARS",Te.TEXT="TEXT",(pe=we||(we={})).ACTION="ACTION",pe.CHECKLIST="CHECKLIST",pe.CONTACT="CONTACT",pe.FLOWS="FLOWS",pe.KNOWLEDGE_BASE="KNOWLEDGE_BASE",pe.MESSAGE="MESSAGE",pe.SUBPAGE="SUBPAGE",(ge=Se||(Se={})).CRISP="CRISP",ge.CUSTOM="CUSTOM",ge.FRESHCHAT="FRESHCHAT",ge.HELPSCOUT="HELPSCOUT",ge.HUBSPOT="HUBSPOT",ge.INTERCOM="INTERCOM",ge.ZENDESK="ZENDESK",ge.ZENDESK_MESSENGER="ZENDESK_MESSENGER",(me=Ce||(Ce={})).LAUNCHER_CLICK="LAUNCHER_CLICK",me.LAUNCHER_HOVER="LAUNCHER_HOVER",me.TARGET_CLICK="TARGET_CLICK",me.TARGET_HOVER="TARGET_HOVER",me.LAUNCHER_TARGET_CLICK="LAUNCHER_TARGET_CLICK",me.LAUNCHER_TARGET_HOVER="LAUNCHER_TARGET_HOVER",(ke=Ie||(Ie={})).ACTIVATE="ACTIVATE",ke.DEACTIVATE="DEACTIVATE",ke.NEVER="NEVER",(Ae=Ue||(Ue={})).AUTO="AUTO",Ae.TOP="TOP",Ae.RIGHT="RIGHT",Ae.BOTTOM="BOTTOM",Ae.LEFT="LEFT",(ye=Le||(Le={})).START="START",ye.CENTER="CENTER",ye.END="END",(Oe=Re||(Re={})).PERCENT="PERCENT",Oe.PX="PX",(Ne=ve||(ve={})).BEACON="BEACON",Ne.BUTTON="BUTTON",Ne.HIDDEN="HIDDEN",Ne.ICON="ICON",(be=_e||(_e={})).LAUNCHER="LAUNCHER",be.TARGET="TARGET",(Fe=De||(De={})).ACTIVE="ACTIVE",Fe.COMPLETED="COMPLETED",Fe.ENDED="ENDED",Fe.NOT_SEEN="NOT_SEEN",(Pe=Me||(Me={})).HIGHLIGHT="HIGHLIGHT",Pe.MODAL="MODAL",Pe.HIGHLIGHT_MODAL="HIGHLIGHT_MODAL";const Be={customInputs:[],customNavigate:null,urlFilter:null,customScrollIntoView:null,scrollPadding:null,inferenceAttributeNames:["data-for","data-id","data-testid","data-test-id","for","id","name","placeholder","role"],inferenceAttributeFilters:{id:[e=>!e.match(/\d$/)],"data-id":[e=>!e.match(/\d$/)]},inferenceClassNameFilters:[e=>!e.startsWith("css-")]};function xe(e){return Array.isArray(e)||(e=e?[e]:[]),e=e.map((e=>"string"==typeof e?new RegExp(e):e))}function He(e,t){return e.every((e=>"function"==typeof e?e(t):!(e instanceof RegExp)||e.test(t)))}function Ge(){let e=d();if(Be.urlFilter){if(e=Be.urlFilter(e),"string"!=typeof e)throw new o("Userflow.js: URL filter returned non-string value. Please check your userflow.setUrlFilter() implementation.");try{new URL(e)}catch(t){throw new o("Userflow.js: URL filter returned an invalid URL. Please check your userflow.setUrlFilter() implementation.\nReturned URL: "+e+"\nError message: "+t.message)}}return e}const We=(localStorage.getItem("debug")||"").split(",").some((e=>"*"===e||e.startsWith("userflow:*"))),$e=je("log");let Ve;function je(e){return function(t,...s){if(We){const i=performance.now(),n=Ve?Math.round(i-Ve):0;Ve=i,console[e](`%cuserflow %c${t} %c+${n}ms`,"color:#4579E4;","","color:#4579E4;",...s)}}}$e.group=je("group"),$e.groupCollapsed=je("groupCollapsed"),$e.groupEnd=function(){We&&console.groupEnd()};const Ke=()=>n((()=>import("./ResourceCenterApp.js")),[new URL("ResourceCenterApp.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("Icons.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("vendor.obj-str.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.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("vendor.fortawesome.pro-regular-svg-icons.js",import.meta.url).toString(),new URL("ChecklistUI.js",import.meta.url).toString(),new URL("vendor.phoenix.js",import.meta.url).toString(),new URL("vendor.uuid.js",import.meta.url).toString()]);function ze(e){const t=e.version.checklist.tasks.length;return Math.max(0,t-e.taskCompletions.length)}class Ye{constructor(e){this.observers=new Set,this._value=e}get value(){return this._value}update(e){if(e!==this._value){this._value=e;for(const e of this.observers)e()}}observe(e){return this.observers.add(e),()=>this.observers.delete(e)}}const Je=import.meta.url;class Xe{constructor(){this.clientToken=null,this.externalId=null,this.signature=null,this.groupId=null,this.groupSignature=null,this._socketStatus="disconnected",this.socket=null,this.channel=null,this.featureFlags=new Set,this.logrocketAppId=null,this.debounceInactiveDisconnectTimeout=void 0,this.inBatch=!1,this.endBatchTimeout=void 0,this.pushRateLimitMinute=0,this.pushRateLimitMinuteExpires=0,this.clientClock=1,this.serverClock=1,this.flowSession=null,this.flowSessionClock=0,this.checklistSession=null,this.checklistExpanded=!1,this.checklistExpandPending=!1,this.checklistSessionClock=0,this.resourceCenterSession=null,this.resourceCenterOpen=!1,this.resourceCenterLauncherHidden=!1,this.launcherSessions=[],this.activeLauncherFlowId=null,this.notifications=[],this.notificationIdCounter=0,this.sessionStorageState=null,this.clientContext=null,this.flushUrlChangeTimeout=void 0,this.onFirstIdentifyRun=!1,this.onFirstIdentifyTimeout=void 0,this.firstIdentifyCallback=null,this.ui=null,this.unackedTasks=new Set,this.clientConditions=new Map,this.trackers=new Map,this.conditionWaitTimers=new Map,this.listeners=new Map,this.targetEnv=null,this.idempotencyKeysSeen=new Set,this.testUserIdentified=!1,this.cspIssueReported=!1,this.uiDisabled=!1,this.audio=null,this.audioReady=!1,this.pageTrackingDisabled=!1,this.onBuilderMessage=e=>(this.handleBuilderMessage(e),!1),this.handleBuilderMessage=async e=>{$e(`builder ${e.kind} message received`,e);const t="idempotencyKey"in e&&"string"==typeof e.idempotencyKey?e.idempotencyKey:null;if(t&&this.idempotencyKeysSeen.has(t))return;const s=()=>{t&&this.idempotencyKeysSeen.add(t)};switch(e.kind){case"userflow:selectElement":return s(),this.getTargetEnv().postBuilderMessage({kind:"userflow:selectElementAck",idempotencyKey:e.idempotencyKey}),void this.setSessionStorageState((t=>({...t,activeApp:"elementSelection",elementSelection:{mode:"select",elementType:e.elementType}})));case"userflow:selectElementCancel":return void this.setSessionStorageState((e=>({...e,activeApp:null,elementSelection:null})));case"userflow:startFlowWithToken":return s(),this.getTargetEnv().postBuilderMessage({kind:"userflow:startFlowWithTokenAck",idempotencyKey:e.idempotencyKey}),e.testUser?this.identifyTestUser(e.testUser):this.resetTestUser(),void this.onceIdentified((()=>{if(this.startFlowWithToken(e.token),e.isResourceCenter){const t=()=>{const s=this.resourceCenterSession;s&&s.draftMode&&s.flow.id===e.flowId&&(this.openResourceCenter(),this.off("resourceCenterChanged",t))};this.on("resourceCenterChanged",t),t()}}));case"userflow:testTracker":return s(),this.getTargetEnv().postBuilderMessage({kind:"userflow:testTrackerAck",idempotencyKey:e.idempotencyKey}),e.testUser?this.identifyTestUser(e.testUser):this.resetTestUser(),void this.setSessionStorageState((t=>({...t,activeApp:"trackerTesting",trackerTesting:{trackerName:e.trackerName,token:e.token,events:0}})));case"userflow:testTrackerCancel":return void this.setSessionStorageState((e=>({...e,activeApp:null,trackerTesting:null})))}},this.onUrlChange=()=>{this.externalId&&(window.clearTimeout(this.flushUrlChangeTimeout),this.flushUrlChangeTimeout=window.setTimeout((()=>this.flushUrlChange()),50))},this.onUserActivity=()=>this.ensureConnected(),$e("constructor, build=1002482"),S(this.onUrlChange),this.setTargetEnv(new m),this.checkTestUserAtBoot(),this.toggleUI()}get socketStatus(){return this._socketStatus}destroy(){$e("destroy"),this.reset(),g(this.onUrlChange),this.destroyTargetEnv()}setTargetEnv(e){this.destroyTargetEnv(),this.targetEnv=e,e.onBuilderMessage(this.onBuilderMessage)}destroyTargetEnv(){this.targetEnv&&(this.targetEnv.destroy(),this.targetEnv=null)}getTargetEnv(){if(!this.targetEnv)throw new o("Userflow.js: Cannot call getTargetEnv when protocol is not set");return this.targetEnv}setSessionStorageState(e){const t=e(this.getSessionStorageState());c.setItem("userflowClientState",JSON.stringify(t)),this.sessionStorageState=t,this.toggleUI()}getSessionStorageState(){let e=this.sessionStorageState;if(!e){const s=c.getItem("userflowClientState");if(s)try{e=JSON.parse(s)}catch(t){console.error("Userflow.js: Parse ElementSelectionState error:",t)}e||(e={testUser:null,activeApp:null,elementSelection:null,trackerTesting:null})}return e}checkTestUserAtBoot(){const e=this.getSessionStorageState().testUser;e&&($e("checkTestUserAtBoot identifying test user"),this.identifyTestUser(e))}async identifyTestUser(e){this.setSessionStorageState((t=>({...t,testUser:e}))),this.reset(),this.init(e.clientToken),this.testUserIdentified=!0,this.externalId=e.id;const t=[this.identify(e.id,{name:e.name,email:e.email,signed_up_at:{set_once:(new Date).toISOString(),data_type:"datetime"}},{signature:e.signature})],{group:s}=e;s&&(this.groupId=s.id,t.push(this.group(s.id,{name:s.name},{signature:s.signature}))),await Promise.all(t)}resetTestUser(){this.setSessionStorageState((e=>({...e,testUser:null})))}init(e){if($e("init",e),!e)throw new o("userflow.init() was called but missing Userflow.js Token");this.clientToken!==e&&(this.testUserIdentified?$e("init() ignoring new token since a test user has been identified"):(this.clientToken&&($e("init() resetting due to new client token"),this.reset()),this.clientToken=e))}ensureInit(){if(!this.clientToken)throw new o("You must call userflow.init() first")}ensureIdentified(){if(this.ensureInit(),!this.externalId)throw new o("You must call userflow.identify() first");return this.externalId}ensureGroup(){if(this.ensureIdentified(),!this.groupId)throw new o("You must call userflow.group() first");return this.groupId}ensureConnected(){if(!this.clientToken||!this.externalId)return;if(this.debounceInactiveDisconnect(),this.socket)return;this._socketStatus="connecting",$e("connecting to socket");let t="e.userflow.com";"js.getuserflow.com"===new URL(Je).hostname&&"e.userflow.com"===t&&(t="e.getuserflow.com");const s="wss://"+t+"/end-users/"+this.clientToken+"/socket";this.socket=new e(s,{reconnectAfterMs:e=>[100,500,1e3,5e3][e-1]||1e4,timeout:2e4}),this.socket.connect(),this.socket.onOpen((()=>{$e("socket opened")})),this.socket.onError((e=>{console.log("Userflow.js socket error",e),this.reportCspIssue()})),this.channel=this.socket.channel(`end_users:${this.externalId}`,(()=>this.makeChannelJoinPayload())),this.channel.join().receive("ok",(e=>{this.logrocketAppId=e.logrocketAppId,this.featureFlags=new Set(e.featureFlags),$e("channel joined"),"connected"!==this._socketStatus&&(this._socketStatus="connected")})).receive("error",(e=>{["company_closed","invalid_client_token","invalid_user_external_id","incorrect_user_signature","rate_limit_exceeded","user_signature_required"].includes(e.code)?(console.error(`Userflow.js resetting due to: [${e.code}] ${e.message}`),this.reset(),this.clientToken=null):"invalid_protocol_version"===e.code?(console.error(`Userflow.js destroying due to: [${e.code}] ${e.message}`),this.destroy()):console.log("Userflow.js channel join error",e)})),this.channel.on("server_message",(e=>this.handleServerMessage(e))),this.channel.on("server_error",(e=>{console.log(`Userflow.js server error (${e.code}): ${e.message}`+(e.details&&e.details.length>0?"\nDetails:\n"+e.details.map((e=>(e.path?`${e.path}: `:"")+e.message)):""))}))}makeChannelJoinPayload(){const e=this.buildClientContext();this.clientContext=e;const t={protocolVersion:2,userflowClientBuild:"1002482",signature:this.signature,groupExternalId:this.groupId,groupSignature:this.groupSignature,flowSessionId:this.flowSession?.id||null,checklistSessionId:this.checklistSession?.id||null,resourceCenterSessionId:this.resourceCenterSession?.id||null,launchers:this.launcherSessions.map((e=>({flowId:e.flow.id}))),trackers:Array.from(this.trackers.values()).map((e=>({flowId:e.tracker.flowId}))),hasDraftSession:this.hasDraftSession(),clientConditions:Array.from(this.clientConditions.values()).map((e=>({conditionId:e.condition.id,isTrue:e.isTrue}))),clientContext:e};return $e("channel join payload",t),t}disconnect(){window.clearTimeout(this.debounceInactiveDisconnectTimeout),this.socket&&this.socket.disconnect(),this._socketStatus="disconnected",this.socket=null,this.channel=null}debounceInactiveDisconnect(){window.clearTimeout(this.debounceInactiveDisconnectTimeout),this.debounceInactiveDisconnectTimeout=window.setTimeout((()=>{this.hasDraftSession()?this.debounceInactiveDisconnect():($e("disconnecting from socket due to inactivity"),this.disconnect())}),3e5)}hasDraftSession(){return!!this.flowSession?.draftMode||!!this.checklistSession?.draftMode||!!this.resourceCenterSession?.draftMode||this.launcherSessions.some((e=>e.draftMode))}async send(e,{batch:t,handlesRejection:s}={}){return this.inBatch&&["ToggleClientCondition","UpdateClientContext"].includes(e.kind)||this.checkPushRateLimit(),this.ensureConnected(),t&&!this.inBatch&&(this.inBatch=!0,this.sendRaw({kind:"BeginBatch"})),this.inBatch&&(window.clearTimeout(this.endBatchTimeout),this.endBatchTimeout=window.setTimeout((()=>{this.inBatch=!1,this.sendRaw({kind:"EndBatch"})}),50)),this.sendRaw(e,{handlesRejection:s})}async sendRaw(e,{handlesRejection:t}={}){return new Promise(((s,i)=>{if(!this.channel)throw Error("Userflow.js: send() should not be called if channel is not set");$e(`push ${e.kind} message`,e);const n=this.clientClock,r=()=>{this.serverClock=n,this.channel?.off("phx_error",a)},a=this.channel.on("phx_error",(s=>{r();const n="Userflow.js send got phx_error";console.log(n,"\nClient message:",e,"\nError:",s),t&&i(new o(n))}));this.channel.push("client_message",e).receive("ok",(e=>{r(),s(e)})).receive("error",(t=>{r();const s=`Userflow.js error reply (${t.code}): ${t.message}`;console.log(s,"\nClient message:",e,"\nError:",t),i(new o(s,t.code))}))}))}checkPushRateLimit(){const e=Date.now();if(this.pushRateLimitMinuteExpires<e&&(this.pushRateLimitMinute=0,this.pushRateLimitMinuteExpires=e+6e4),this.pushRateLimitMinute>=100)throw new o("This Userflow.js client has reached a maximum of 100 operations in the last 1 minute. This is usually due to one of the following:\n\n - Excessive calls to Userflow.js. Check if any of userflow.track(), userflow.identify(), userflow.updateUser() or similar are called repeatedly.\n - The URL changing too frequently. Look into https://userflow.com/docs/userflow-js#seturlfilter and filter out the changing part of the URL.\n - The user legitimately being very active, in which case you can just ignore this error.\n \n If in doubt, reach out to us at support@userflow.com.");this.pushRateLimitMinute++}handleServerMessage(e){$e(`received ${e.kind} message`,e);const{serverClock:t,flowSession:s,flowSessionClock:i,checklistSession:n,checklistSessionClock:o,resourceCenterSession:r}=this;switch(e.kind){case"CheckSessionsAck":case"ServerDebug":return;case"AddLauncher":{const{session:t}=e,s=this.launcherSessions.findIndex((e=>e.flow.id===t.flow.id));return this.launcherSessions=-1===s?[...this.launcherSessions,t]:[...this.launcherSessions.slice(0,s),t,...this.launcherSessions.slice(s+1)],void this.toggleUI()}case"AddTracker":return void this.addTracker(e.tracker);case"CancelConditionWaitTimer":return window.clearTimeout(this.conditionWaitTimers.get(e.conditionId)),void this.conditionWaitTimers.delete(e.conditionId);case"ChecklistTaskCompleted":return void this.unackedTasks.add(e.taskCvid);case"ForceGoToStep":return i>t?void $e(`ignoring ${e.kind} message due to stale clock flowSessionClock=${i} > serverClock=${t}`):void(s?.id===e.sessionId&&this.emit("gotostep",{session:s,step:{id:e.stepId}}));case"RemoveLauncher":return void(this.removeLauncher(e.flowId)&&this.toggleUI());case"RemoveTracker":return void this.removeTracker(e.flowId);case"SetChecklistSession":return void(o<=t||n?.id===e.session.id?(this.setChecklistSession(e.session,t),this.toggleUI()):$e(`ignoring ${e.kind} message due to stale clock checklistSessionClock=${o} > serverClock=${t}`));case"SetFlowSession":return void(i<=t||s?.id===e.session.id?(this.setFlowSession(e.session,t),this.toggleUI()):$e(`ignoring ${e.kind} message due to stale clock flowSessionClock=${i} > serverClock=${t}`));case"SetResourceCenterSession":return this.setResourceCenterSession(e.session),void this.toggleUI();case"StartConditionWaitTimer":if(!this.conditionWaitTimers.has(e.conditionId)){const t=window.setTimeout((()=>{this.conditionWaitTimers.delete(e.conditionId),this.send({kind:"FireConditionWaitTimer",conditionId:e.conditionId},{batch:!0})}),1e3*parseFloat(e.waitTime));this.conditionWaitTimers.set(e.conditionId,t)}return;case"TrackClientCondition":return void this.trackClientCondition(e.condition);case"UnsetChecklistSession":return o>t?void $e(`ignoring ${e.kind} message due to stale clock checklistSessionClock=${o} > serverClock=${t}`):void(n?.id===e.sessionId&&(this.setChecklistSession(null,t),this.toggleUI()));case"UnsetFlowSession":return i>t?void $e(`ignoring ${e.kind} message due to stale clock flowSessionClock=${i} > serverClock=${t}`):void(s?.id===e.sessionId&&(this.setFlowSession(null,t),this.toggleUI()));case"UnsetResourceCenterSession":return void(r?.id===e.sessionId&&(this.setResourceCenterSession(null),this.toggleUI()));case"UntrackClientCondition":return void this.untrackClientCondition(e.conditionId);default:return void console.warn("Userflow.js: Received unknown message",e)}}async identify(e,t={},{signature:s}={}){if($e("identify",e),this.ensureInit(),this.testUserIdentified&&e!==this.externalId)$e("identify() ignored since a test user has been identified");else{if("number"==typeof e)e=String(e);else if(!e||"string"!=typeof e)throw new o(`userflow.identify: First argument must be a non-empty string representing the user's ID in your database. Value received: ${JSON.stringify(e)}`);this.externalId&&e!==this.externalId&&($e("identify resetting due to new externalId"),this.reset()),this.externalId=e,this.signature=s||null,this.observeUserActivity(),await Promise.all([this.send({kind:"UpsertUser",attributes:this.normalizeAttributes(t)},{batch:!0}),this.onFirstIdentify()]),this.emit("private:identified")}}async identifyAnonymous(e={},s={}){const i="anonymousId";let n=a.getItem(i);n||(n="anon-"+t(),a.setItem(i,n)),await this.identify(n,e,s)}async updateUser(e={},t={}){$e("updateUser"),this.ensureIdentified(),await this.send({kind:"UpsertUser",attributes:this.normalizeAttributes(e)},{batch:!0})}async group(e,t={},{signature:s,membership:i}={}){if($e("group",e),this.ensureIdentified(),this.testUserIdentified&&e!==this.groupId)$e("group() ignored since a test user has been identified");else{if("number"==typeof e)e=String(e);else if(!e||"string"!=typeof e)throw new o(`userflow.group: First argument must be a non-empty string representing the group's ID in your database. Value received: ${JSON.stringify(e)}`);this.groupId=e,this.groupSignature=s||null,await this.send({kind:"UpsertGroup",groupExternalId:e,groupSignature:this.groupSignature,groupAttributes:this.normalizeAttributes(t),membershipAttributes:this.normalizeAttributes(i)},{batch:!0})}}async updateGroup(e={},t={}){$e("updateGroup");const s=this.ensureGroup();await this.send({kind:"UpsertGroup",groupExternalId:s,groupSignature:this.groupSignature,membershipAttributes:this.normalizeAttributes(t.membership),groupAttributes:this.normalizeAttributes(e)},{batch:!0})}normalizeAttributes(e){if(null==e)return{};if("object"!=typeof e)throw new o("Userflow: 'attributes' must be an object.");const t={};for(const s in e){if(!e.hasOwnProperty(s))continue;if("traits"===s){const i=e[s];Object.assign(t,this.extractLegacyTraits(i));continue}let i=e[s];if("string"==typeof i||"number"==typeof i||"boolean"==typeof i||null==i||Array.isArray(i))t[s]=this.normalizeAttributeLiteralOrList(s,i);else{if("object"!=typeof i||null==i)throw new o(`Userflow: Invalid value for '${s}' attribute.`);if("set"in i)t[s]={set:this.normalizeAttributeLiteralOrList(s,i.set),dataType:this.normalizeDataType(s,i.data_type||i.dataType)};else if("set_once"in i||"setOnce"in i)t[s]={setOnce:this.normalizeAttributeLiteralOrList(s,i.set_once||i.setOnce),dataType:this.normalizeDataType(s,i.data_type||i.dataType)};else if("add"in i){const e=i.add;if("string"!=typeof e&&"number"!=typeof e)throw new o(`Userflow: Invalid 'add' value for '${s}' attribute. Must be a number or string.`);t[s]={add:e}}else if("subtract"in i){const e=i.subtract;if("string"!=typeof e&&"number"!=typeof e)throw new o(`Userflow: Invalid 'subtract' value for '${s}' attribute. Must be a number or string.`);t[s]={subtract:e}}else if("append"in i)t[s]={append:this.normalizeAttributeLiteralOrList(s,i.append)};else if("prepend"in i)t[s]={prepend:this.normalizeAttributeLiteralOrList(s,i.prepend)};else{if(!("remove"in i))throw new o(`Userflow: Invalid value for '${s}' attribute.`);t[s]={remove:this.normalizeAttributeLiteralOrList(s,i.remove)}}}}return t}normalizeAttributeLiteralOrList(e,t){return Array.isArray(t)?t.map((t=>this.normalizeAttributeLiteral(e,t))):this.normalizeAttributeLiteral(e,t)}normalizeAttributeLiteral(e,t){if(null==t)return null;if("string"==typeof t||"number"==typeof t||"boolean"==typeof t)return t;throw new o(`Userflow: Invalid value for '${e}' attribute.`)}normalizeDataType(e,t){if(!t)return null;switch(t){case"string":return R.STRING;case"number":return R.NUMBER;case"boolean":return R.BOOLEAN;case"datetime":return R.DATETIME}throw new o(`Userflow: Invalid data_type for '${e}' attribute.`)}extractLegacyTraits(e){if(!e)return{};if(!Array.isArray(e)){const t=[];for(const s in e)e.hasOwnProperty(s)&&t.push({name:s,value:e[s]});e=t}return e.reduce(((e,{name:t,value:s,dataType:i})=>{if("string"!=typeof t||t.length>100||!t.match(/^[a-z0-9_]+$/))return this.warn("Userflow.identify: Invalid trait name (must be string, no more than 100 characters, and only consist of a-z, 0-9 and underscores). The trait will be ignored. Name was:",t),e;if("string"==typeof s);else if("boolean"==typeof s)i||(i="boolean"),s=s?"true":"false";else{if("number"!=typeof s)return this.warn(`userflow.identify: The value of trait '${t}' is invalid (must be a string, a boolean or a number). The trait will be ignored. Value was:`,s),e;i||(i=Number.isInteger(s)?"integer":"decimal"),s=String(s)}let n=null;if(i)switch(i){case"string":n=R.STRING;break;case"boolean":n=R.BOOLEAN;break;case"integer":case"decimal":n=R.NUMBER;break;case"datetime":n=R.DATETIME;break;default:return this.warn(`userflow.identify: The data type of trait '${t}' is invalid (must be a 'string', 'boolean', 'integer', 'decimal' or 'datetime'). The trait will be ignored. Data type was:`,i),e}return e[t]={set:s,dataType:n},e}),{})}async track(e,t={},{userOnly:s}={}){$e(`track '${e}'`,t),this.ensureIdentified(),await this.send({kind:"TrackEvent",userOnly:!!s,name:e,attributes:this.normalizeEventAttributes(t)},{batch:!0})}normalizeEventAttributes(e){const t=this.normalizeAttributes(e);for(const s in t){if(!t.hasOwnProperty(s))continue;const e=t[s];if(null!=e&&"string"!=typeof e&&"boolean"!=typeof e&&"number"!=typeof e&&!Array.isArray(e)&&!("set"in e))throw new o(`Userflow: Invalid value for '${s}' attribute. Event attributes only support literal values, list values and 'set' changes.`)}return t}onFirstIdentify(){this.onFirstIdentifyRun||(this.onFirstIdentifyRun=!0,this.onFirstIdentifyTimeout=window.setTimeout((()=>{this.trackPageViewed(),this.firstIdentifyCallback?(this.firstIdentifyCallback(),this.firstIdentifyCallback=null):this.checkUrlForStartFlow()}),0))}onceIdentified(e){this.isIdentified()?e():this.firstIdentifyCallback=e}checkUrlForStartFlow(){const e=new URL(d()),t=e.searchParams.get("userflow")||e.searchParams.get("studio1_flow")||e.searchParams.get("studio1_walkthrough");t&&($e(`url contained flow ${t}`),this.startFlow({flowId:t,startReason:L.LINK,batch:!0}),e.searchParams.delete("userflow"),e.searchParams.delete("studio1_flow"),e.searchParams.delete("studio1_walkthrough"),window.history.replaceState({},"",e.toString()),this.clientContext=this.buildClientContext(),this.pushUpdateClientContext())}flushUrlChange(){const e=this.buildClientContext();this.clientContext&&e.pageUrl===this.clientContext.pageUrl||(this.clientContext=e,this.pushUpdateClientContext(),this.trackPageViewed(),this.checkUrlForStartFlow())}async trackPageViewed(){this.pageTrackingDisabled||this.track("page_viewed",{})}buildClientContext(){return{pageUrl:Ge(),viewportWidth:window.innerWidth,viewportHeight:window.innerHeight}}pushUpdateClientContext(){this.send({kind:"UpdateClientContext",clientContext:this.clientContext},{batch:!0})}ackCompletedTask(e){this.unackedTasks.delete(e)}taskIsUnacked(e){return this.unackedTasks.has(e)}isIdentified(){return null!=this.externalId}on(e,t){let s=this.listeners.get(e);s||(s=new Set,this.listeners.set(e,s)),s.add(t)}off(e,t){const s=this.listeners.get(e);s&&s.delete(t)}emit(e,...t){const s=this.listeners.get(e);if(s){Array.from(s).forEach((e=>e(...t)))}}observeUserActivity(){document.addEventListener("mouseover",this.onUserActivity),document.addEventListener("pointerdown",this.onUserActivity),document.addEventListener("keydown",this.onUserActivity)}unobserveUserActivity(){document.removeEventListener("mouseover",this.onUserActivity),document.removeEventListener("pointerdown",this.onUserActivity),document.removeEventListener("keydown",this.onUserActivity)}reset(){$e("reset"),this.externalId=null,this.groupId=null,this.sessionStorageState=null,this.setFlowSession(null,0),this.setChecklistSession(null,0),this.setResourceCenterSession(null),this.launcherSessions=[],this.activeLauncherFlowId=null,this.notifications=[],this.unackedTasks=new Set,this.onFirstIdentifyRun=!1,window.clearTimeout(this.onFirstIdentifyTimeout),this.onFirstIdentifyTimeout=void 0,this.clientContext=null,this.unobserveUserActivity(),window.clearTimeout(this.flushUrlChangeTimeout),this.flushUrlChangeTimeout=void 0,this.clientConditions.forEach(((e,t)=>{this.untrackClientCondition(t)})),this.firstIdentifyCallback=null,this.testUserIdentified=!1,a.removeItem("anonymousId"),this.unmountUI(),this.disconnect(),this.inBatch=!1,window.clearTimeout(this.endBatchTimeout),this.endBatchTimeout=void 0,this.clientClock=1,this.serverClock=1}async startFlow({flowId:e,stepCvid:t,startReason:s,once:i,batch:n,replaceCurrent:o}){if(this.ensureIdentified(),o&&this.flowSession&&this.endFlow(this.flowSession,{endReason:I.REPLACED,batch:!0}),$e(`startFlow ${e}`,{startReason:s}),this.checklistSession?.flow.id===e)return $e("startFlow matches current checklist, so showing it instead"),void this.showChecklist();const r={kind:"StartFlow",flowId:e,stepCvid:t,startReason:s,once:!!i};await this.send(r,{batch:n})}async startFlowWithToken(e){this.ensureIdentified(),$e("startFlowWithToken",{token:e}),await this.send({kind:"StartFlowWithToken",token:e},{batch:!0})}optimisticClockUIUpdate(e){this.clientClock++,e(),this.toggleUI()}async showChecklist(){this.resourceCenterEmbedsChecklist()?this.openResourceCenter():(this.unmarkExpandPending(),this.checklistSession&&!this.checklistExpanded&&(this.ensureIdentified(),this.checklistExpanded=!0,this.toggleUI(),c.setItem(`checklistExpanded:${this.checklistSession.id}`,"1"),await this.send({kind:"ShowChecklist",sessionId:this.checklistSession.id},{batch:!0})))}async hideChecklist(){this.resourceCenterEmbedsChecklist()?this.closeResourceCenter():this.checklistSession&&this.checklistExpanded&&(this.ensureIdentified(),this.checklistExpanded=!1,this.toggleUI(),c.removeItem(`checklistExpanded:${this.checklistSession.id}`),await this.send({kind:"HideChecklist",sessionId:this.checklistSession.id},{batch:!0}))}async unmarkExpandPending(){this.checklistSession&&this.checklistExpandPending&&(this.checklistExpandPending=!1,await this.send({kind:"UnmarkExpandPending",sessionId:this.checklistSession.id},{batch:!0}))}async openResourceCenter(){this.resourceCenterEmbedsChecklist()&&this.unmarkExpandPending(),this.resourceCenterSession&&!this.resourceCenterOpen&&(this.ensureIdentified(),this.resourceCenterOpen=!0,this.toggleUI(),this.emit("resourceCenterChanged"),c.setItem(`resourceCenterOpen:${this.resourceCenterSession.id}`,"1"),await this.send({kind:"OpenResourceCenter",sessionId:this.resourceCenterSession.id},{batch:!0}))}async closeResourceCenter(){this.resourceCenterSession&&this.resourceCenterOpen&&(this.ensureIdentified(),this.resourceCenterOpen=!1,this.toggleUI(),this.emit("resourceCenterChanged"),c.removeItem(`resourceCenterOpen:${this.resourceCenterSession.id}`),await this.send({kind:"CloseResourceCenter",sessionId:this.resourceCenterSession.id},{batch:!0}))}toggleResourceCenter(){this.resourceCenterOpen?this.closeResourceCenter():this.openResourceCenter()}setResourceCenterLauncherHidden(e){this.resourceCenterLauncherHidden=e,this.toggleUI()}getResourceCenterState(){if(!this.resourceCenterSession)return null;const e=this.resourceCenterEmbedsChecklist(),{checklistSession:t}=this;return{isOpen:this.resourceCenterOpen,hasChecklist:e,uncompletedChecklistTaskCount:e&&t?ze(t):0}}resourceCenterEmbedsChecklist(){const e=this.resourceCenterSession;return!!e&&!!e.version.resourceCenter?.blocks.some((e=>e.type===we.CHECKLIST))}async endFlow(e,{endReason:t,batch:s}){this.ensureIdentified(),this.optimisticClockUIUpdate((()=>{const{clientClock:t}=this;this.flowSession?.id===e.id&&this.setFlowSession(null,t),this.checklistSession?.id===e.id&&this.setChecklistSession(null,t),this.resourceCenterSession?.id===e.id&&this.setResourceCenterSession(null)}));const{flow:i}=e,n={id:i.id,type:i.type.toLowerCase()};i.type===v.CHECKLIST?this.emit("checklistEnded",{checklist:n,endReason:t}):i.type===v.FLOW&&this.emit("flowEnded",{flow:n,endReason:t});const o={kind:"EndFlow",sessionId:e.id,endReason:t};await this.send(o,{batch:s})}async goToStep(e,t){$e("goToStep",e.id,t.name||t.id),this.ensureIdentified();const s=this.send({kind:"GoToStep",sessionId:e.id,stepId:t.id});e.currentStep=t,this.emit("gotostep",{session:e,step:t}),await s}async endAllFlows(){$e("endAllFlows"),this.optimisticClockUIUpdate((()=>{const{clientClock:e}=this;this.setFlowSession(null,e),this.setChecklistSession(null,e)})),await this.send({kind:"EndAllFlows"})}async endChecklist(){$e("endChecklist");const e=this.checklistSession||this.flowSession;e?.flow.type===v.CHECKLIST&&this.endFlow(e,{endReason:I.USERFLOWJS})}setFlowSession(e,t=this.clientClock){const s=this.flowSession;this.flowSession=e,this.flowSessionClock=t,e&&!s&&(this.hideChecklist(),this.closeResourceCenter()),null==e&&this.originalActiveElement&&("function"==typeof this.originalActiveElement.focus&&this.originalActiveElement.focus(),this.originalActiveElement=void 0)}setChecklistSession(e,t=this.clientClock){const s=this.checklistSession;this.checklistSession=e,this.checklistSessionClock=t,null===e&&(this.checklistExpanded=!1,this.checklistExpandPending=!1),e&&e.id!==s?.id&&(this.checklistExpanded=!!c.getItem(`checklistExpanded:${e.id}`),e.expandPending&&(this.checklistExpandPending=!0)),this.emit("checklistChanged"),this.emit("resourceCenterChanged")}setResourceCenterSession(e){const t=this.resourceCenterSession;this.resourceCenterSession=e,null===e&&(this.resourceCenterOpen=!1),t&&t.id!==e?.id&&c.removeItem(`resourceCenterOpen:${t.id}`),e&&e.id!==t?.id&&(this.resourceCenterOpen=!!c.getItem(`resourceCenterOpen:${e.id}`)),this.emit("resourceCenterChanged")}launcherSeen(e){this.send({kind:"StartFlow",flowId:e,startReason:L.LAUNCHER_SEEN,once:!1})}activateLauncher(e){const t=this.activeLauncherFlowId&&this.launcherSessions.find((e=>e.flow.id===this.activeLauncherFlowId));t&&this.deactivateLauncher(t),this.activeLauncherFlowId=e.flow.id,this.toggleUI(),this.send({kind:"ActivateLauncher",flowId:e.flow.id})}deactivateLauncher(e){const{launcher:t}=e.version;e.flow.id===this.activeLauncherFlowId&&(t?.dismissOn===Ie.DEACTIVATE?this.dismissLauncher(e,{endReason:I.LAUNCHER_DEACTIVATED}):(this.activeLauncherFlowId=null,this.toggleUI()))}dismissLauncher(e,{endReason:t}){const s=e.flow.id;this.removeLauncher(s),this.toggleUI(),this.send({kind:"DismissLauncher",flowId:s,endReason:t})}removeLauncher(e){const t=this.launcherSessions.findIndex((t=>t.flow.id===e));return-1!==t&&(this.launcherSessions=[...this.launcherSessions.slice(0,t),...this.launcherSessions.slice(t+1)],e===this.activeLauncherFlowId&&(this.activeLauncherFlowId=null),!0)}async toggleUI(){this.flowSession||!this.checklistExpandPending&&!this.checklistSession?.version.checklist?.tasks.some((e=>this.taskIsUnacked(e.cvid)))||this.showChecklist(),this.emit("uistatechange"),this.shouldBeMounted()?await this.mountUI():this.unmountUI()}shouldBeMounted(){if(this.uiDisabled)return!1;return!!this.getSessionStorageState().activeApp||!!this.flowSession||!!this.checklistSession&&(this.checklistExpanded||!!this.checklistSession?.version.checklist?.launcherEnabled)||!!this.resourceCenterSession&&(this.resourceCenterOpen||!this.resourceCenterLauncherHidden)||this.launcherSessions.length>0||this.notifications.length>0}async mountUI(){if(!this.ui){const e=await this.createUI();this.shouldBeMounted()&&!this.ui&&($e("mount UI"),this.ui=e,this.ui.mount())}}unmountUI(){this.ui&&($e("unmount UI"),this.ui.unmount(),this.ui=null)}remount(){this.unmountUI(),this.toggleUI()}async createUI(){try{const e=n((()=>import("./ui.js")),[new URL("ui.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("vendor.react-dom.js",import.meta.url).toString(),new URL("vendor.scheduler.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.phoenix.js",import.meta.url).toString(),new URL("vendor.uuid.js",import.meta.url).toString()]);this.resourceCenterSession&&Ke();const{RealUI:t}=await e;return new t(this)}catch(e){throw this.reportCspIssue(),e}}async trackClientCondition(e){if(this.clientConditions.has(e.id))return;$e("track client condition",e),this.clientConditions.set(e.id,{condition:e,isTrue:null});const{conditionTypes:t}=await n((()=>import("./flow-condition-types.js").then((function(e){return e.u}))),[new URL("flow-condition-types.js",import.meta.url).toString(),new URL("vendor.date-fns.js",import.meta.url).toString()]),s=t[e.type],i=this.clientConditions.get(e.id);i&&(i.untrack=s.track({sessionData:new Ye([]),condition:e,callback:t=>{i.isTrue!==t&&($e("client condition truthiness changed",t,i.condition),i.isTrue=t,this.send({kind:"ToggleClientCondition",conditionId:e.id,isTrue:t},{batch:!0}))}}))}untrackClientCondition(e){const t=this.clientConditions.get(e);t&&($e("untrack client condition",t.condition),t.untrack&&t.untrack(),this.clientConditions.delete(e))}async addTracker(e){let t=this.trackers.get(e.flowId);t?t.tracker=e:this.trackers.set(e.flowId,{tracker:e,isTrue:!1});const{conditionTypes:s}=await n((()=>import("./flow-condition-types.js").then((function(e){return e.u}))),[new URL("flow-condition-types.js",import.meta.url).toString(),new URL("vendor.date-fns.js",import.meta.url).toString()]),i=this.trackers.get(e.flowId);if(!i)return;const{tracker:o}=i,{condition:r}=o,a=s[r.type];i.untrack&&i.untrack(),i.untrack=a.track({sessionData:new Ye(o.data),condition:r,flipBackEvents:!0,callback:e=>{const t=i.isTrue;i.isTrue=e,!t&&e&&this.send({kind:"TrackTrackerEvent",token:o.token},{batch:!0})}}),this.emit("private:trackerStarted")}removeTracker(e){const t=this.trackers.get(e);t&&(t.untrack&&t.untrack(),this.trackers.delete(e),this.emit("private:trackerStopped"))}reportCspIssue(){const e=this.getSessionStorageState();!this.testUserIdentified&&!e.activeApp||this.cspIssueReported||(this.cspIssueReported=!0,$e("csp issue detected"),E(window,{kind:"userflow:crxCspIssueDetected"}))}getAudio(){return this.audio||(this.audio=new Audio),this.audio}playAudio(e){if(document.hidden)return;const t=this.getAudio();e&&(t.src=e);const s=t.play();this.audioReady=!0,s&&s.catch((e=>{e.name}))}pauseAudio(){const e=this.audio;e&&!e.paused&&e.pause()}async getStepSpeech(e,t){return(await this.send({kind:"GetStepSpeechV2",syntheticVoice:e,text:t})).url}featureFlagEnabled(e){return this.featureFlags.has(e)}showNotification(e,t,s){const i={id:++this.notificationIdCounter,label:e,message:t,type:s};this.notifications=[...this.notifications,i],this.toggleUI()}dismissNotification(e){this.notifications=this.notifications.filter((t=>t.id!==e)),this.toggleUI()}warn(...e){console.warn(...e)}}if(void 0===window.userflow||window.userflow._stubbed){const e=Object.assign(window.userflow||{},function(){const e=new Xe;return{_stubbed:!1,init(t){e.init(t)},identify:(t,s={},i={})=>e.identify(t,s,i),identifyAnonymous:(t={},s={})=>e.identifyAnonymous(t,s),isIdentified:()=>e.isIdentified(),updateUser:(t,s={})=>e.updateUser(t,s),group:(t,s={},i={})=>e.group(t,s,i),updateGroup:(t,s={})=>e.updateGroup(t,s),track:(t,s={},i={})=>e.track(t,s,i),start:(t,{once:s}={})=>e.startFlow({flowId:t,startReason:L.USERFLOWJS,once:s}),startFlow:e=>(console.warn("Userflow.js: userflow.startFlow() has been deprecated. Use userflow.start() instead."),window.userflow.start(e)),startWalk:e=>(console.warn("Userflow.js: userflow.startWalk() has been deprecated. Use userflow.start() instead."),window.userflow.start(e)),endAll:()=>e.endAllFlows(),endChecklist:()=>e.endChecklist(),endAllFlows:()=>window.userflow.endAll(),async endFlow(){console.warn("Userflow.js: userflow.endFlow() has been deprecated and no longer has any effect.")},async endWalk(){console.warn("Userflow.js: userflow.endWalk() has been deprecated and no longer has any effect.")},openResourceCenter(){e.openResourceCenter()},closeResourceCenter(){e.closeResourceCenter()},toggleResourceCenter(){e.toggleResourceCenter()},setResourceCenterLauncherHidden(t){e.setResourceCenterLauncherHidden(t)},getResourceCenterState:()=>e.getResourceCenterState(),setWalkPosition(){console.warn("Userflow.js: userflow.setWalkPosition() has been deprecated and no longer has any effect.")},reset(){e.reset()},remount(){e.remount()},on(t,s){e.on(t,s)},off(t,s){e.off(t,s)},setCustomInputSelector(e){console.warn("Userflow.js: userflow.setCustomInputSelector() has been deprecated. Use userflow.registerCustomInput() instead. See docs: https://userflow.com/docs/userflow-js"),e&&Be.customInputs.push({cssSelector:e})},registerCustomInput(e,t){Be.customInputs.push({cssSelector:e,getValue:t})},setCustomNavigate(e){Be.customNavigate=e},setUrlFilter(e){Be.urlFilter=e},setInferenceAttributeNames(e){Be.inferenceAttributeNames=e},setInferenceAttributeFilter(e,t){Be.inferenceAttributeFilters[e]=xe(t)},setInferenceClassNameFilter(e){Be.inferenceClassNameFilters=xe(e)},setScrollPadding(e){Be.scrollPadding=e},setCustomScrollIntoView(e){Be.customScrollIntoView=e},prepareAudio(){e.playAudio(null)},setShadowDomEnabled(e){console.warn("Userflow.js: userflow.setShadowDomEnabled() has been deprecated. Please remove this call from your Userflow.js snippet. Shadow DOM is supported by default now.")},setPageTrackingDisabled(t){e.pageTrackingDisabled=t},_setTargetEnv(t){e.setTargetEnv(t)}}}());window.userflow=e,window.studio1=e,function(){const e=window.userflow,t=window.USERFLOWJS_QUEUE;if(delete window.USERFLOWJS_QUEUE,!t||0===t.length)return;$e(`processing ${t.length} items in the queue`);for(const[s,i,n]of t){if("function"!=typeof e[s]){console.error(`Userflow.js: Invalid method '${s}' in queue`);continue}const t=e[s](...n);i&&t&&"function"==typeof t.then&&t.then(i.resolve,i.reject)}$e("queue processed")}()}export{H as A,W as B,Se as C,Ce as D,I as E,M as F,Ue as G,_e as H,Le as I,Re as J,ve as L,X as M,Ke as R,L as S,se as T,o as U,ne as V,n as _,F as a,D as b,Be as c,$e as d,_ as e,B as f,Ge as g,we as h,ze as i,ee as j,Z as k,de as l,v as m,ue as n,S as o,Ee as p,Ye as q,K as r,l as s,He as t,g as u,a as v,Y as w,re as x,V as y,ce as z};export default window.userflow;
|
|
1
|
+
import{S as e}from"./vendor.phoenix.js";import{v as t}from"./vendor.uuid.js";let s;const i={},n=function(e,t){if(!t)return e();if(void 0===s){const e=document.createElement("link").relList;s=e&&e.supports&&e.supports("modulepreload")?"modulepreload":"preload"}return Promise.all(t.map((e=>{if(e in i)return;i[e]=!0;const t=e.endsWith(".css"),n=t?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${e}"]${n}`))return;const o=document.createElement("link");return o.rel=t?"stylesheet":s,t||(o.as="script",o.crossOrigin=""),o.href=e,document.head.appendChild(o),t?new Promise(((e,t)=>{o.addEventListener("load",e),o.addEventListener("error",t)})):void 0}))).then((()=>e()))};class o extends Error{constructor(e,t){super(e),Object.setPrototypeOf(this,o.prototype),this.name="UserflowError",this.code=t}}class r{constructor(e){this.type=e,this.testState={}}formatKey(e){return`userflow:${e}`}getItem(e){return e=this.formatKey(e),"undefined"==typeof window?null:window[this.type].getItem(e)}setItem(e,t){e=this.formatKey(e),"undefined"!=typeof window&&window[this.type].setItem(e,t)}removeItem(e){if(e=this.formatKey(e),"undefined"!=typeof window)return window[this.type].removeItem(e)}clear(){if("undefined"!=typeof window)return window[this.type].clear()}}const a=new r("localStorage"),c=new r("sessionStorage");function l(e){window.location.href=e}function d(){return window.location.href}var h,u,f;function E(e,t,{toOrigin:s}={}){e.postMessage(t,s||"*")}function w(e,{fromWindow:t,fromOrigin:s}={}){const i=i=>{if(!i.isTrusted)return;if(t&&t!==i.source)return;if(s&&i.origin!==s)return;const o=i.data;o&&"object"==typeof o&&"string"==typeof o.kind&&o.kind.startsWith("userflow:")&&!0===e(o)&&n()};window.addEventListener("message",i);const n=()=>window.removeEventListener("message",i);return n}(h||(h={})).INPUT="INPUT",(f=u||(u={})).AUTO="AUTO",f.MANUAL="MANUAL";const T=new Set;let p=!1;function S(e){return function(){if(p)return;p=!0;const{history:e}=window,t=t=>{const s=e[t];e[t]=(...t)=>{s.apply(e,t),C()}};t("pushState"),t("replaceState"),window.addEventListener("popstate",(()=>{C()}))}(),T.add(e),()=>{g(e)}}function g(e){T.delete(e)}function C(){T.forEach((e=>e()))}class I{destroy(){this.unregisterOnMessage&&this.unregisterOnMessage()}postBuilderMessage(e){E(window.opener,e,{toOrigin:"https://userflow.com"})}onBuilderMessage(e){return this.unregisterOnMessage=w(e,{fromOrigin:"https://userflow.com"}),!1}async captureScreenshot(e,t,s,i){E(window,{kind:"userflow:crxScreenshot",x:e,y:t,width:s,height:i,devicePixelRatio:window.devicePixelRatio});var n;return(await(n=e=>"userflow:crxScreenshotResult"===e.kind?e:null,new Promise((e=>{w((t=>{const s=n(t);return!!s&&(e(s),!0)}))})))).imageDataUrl}}var m,k,U,A,L,y,R,O,v,N,_,b,D,F,M,P,B,x,H,G,W,$,V,j,K,z,Y,J,X,Q,Z,q,ee,te,se,ie,ne,oe,re,ae,ce,le,de,he,ue,fe,Ee,we,Te,pe,Se,ge,Ce,Ie,me,ke,Ue,Ae,Le,ye,Re,Oe,ve,Ne,_e,be,De,Fe,Me,Pe;(k=m||(m={})).ACTION="ACTION",k.LAUNCHER_DEACTIVATED="LAUNCHER_DEACTIVATED",k.REPLACED="REPLACED",k.SNOOZED="SNOOZED",k.TOOLTIP_TARGET_MISSING="TOOLTIP_TARGET_MISSING",k.USERFLOWJS="USERFLOWJS",k.USER_CLOSED="USER_CLOSED",(A=U||(U={})).SECOND="SECOND",A.MINUTE="MINUTE",A.HOUR="HOUR",A.DAY="DAY",(y=L||(L={})).ACTION="ACTION",y.DRAFT="DRAFT",y.LINK="LINK",y.LAUNCHER_SEEN="LAUNCHER_SEEN",y.RESOURCE_CENTER="RESOURCE_CENTER",y.USERFLOWJS="USERFLOWJS",(O=R||(R={})).STRING="STRING",O.BOOLEAN="BOOLEAN",O.NUMBER="NUMBER",O.DATETIME="DATETIME",O.LIST="LIST",(N=v||(v={})).FLOW="FLOW",N.CHECKLIST="CHECKLIST",N.LAUNCHER="LAUNCHER",N.RESOURCE_CENTER="RESOURCE_CENTER",(b=_||(_={})).ALWAYS_TRUE="ALWAYS_TRUE",b.ATTRIBUTE="ATTRIBUTE",b.CLAUSE="CLAUSE",b.ELEMENT="ELEMENT",b.FILLED_IN_INPUT="FILLED_IN_INPUT",b.FLOW="FLOW",b.INPUT_VALUE="INPUT_VALUE",b.PAGE="PAGE",b.TIME="TIME",function(e){e.AUTO="AUTO",e.MANUAL="MANUAL"}(D||(D={})),(F||(F={})).INPUT="INPUT",(P=M||(M={})).ABSOLUTE_EQ="ABSOLUTE_EQ",P.ABSOLUTE_GT="ABSOLUTE_GT",P.ABSOLUTE_LT="ABSOLUTE_LT",P.AND="AND",P.CONTAINS="CONTAINS",P.EMPTY="EMPTY",P.ENDS_WITH="ENDS_WITH",P.EQ="EQ",P.EXCLUDES_ALL="EXCLUDES_ALL",P.EXCLUDES_ANY="EXCLUDES_ANY",P.FALSE="FALSE",P.GT="GT",P.INCLUDES_ALL="INCLUDES_ALL",P.INCLUDES_ANY="INCLUDES_ANY",P.LT="LT",P.NE="NE",P.NOT_CONTAINS="NOT_CONTAINS",P.NOT_EMPTY="NOT_EMPTY",P.NOT_REGEX="NOT_REGEX",P.OR="OR",P.REGEX="REGEX",P.RELATIVE_EQ="RELATIVE_EQ",P.RELATIVE_GT="RELATIVE_GT",P.RELATIVE_LT="RELATIVE_LT",P.STARTS_WITH="STARTS_WITH",P.TRUE="TRUE",P.URL="URL",(x=B||(B={})).CLICK="CLICK",x.DISABLED="DISABLED",x.MOUSEDOWN="MOUSEDOWN",x.NOT_CLICK="NOT_CLICK",x.NOT_DISABLED="NOT_DISABLED",x.NOT_PRESENT="NOT_PRESENT",x.PRESENT="PRESENT",(G=H||(H={})).ASSET="ASSET",G.CARTOON="CARTOON",G.NONE="NONE",G.URL="URL",($=W||(W={})).INSIDE="INSIDE",$.OUTSIDE="OUTSIDE",(j=V||(V={})).TOP_LEFT="TOP_LEFT",j.TOP_CENTER="TOP_CENTER",j.TOP_RIGHT="TOP_RIGHT",j.BOTTOM_RIGHT="BOTTOM_RIGHT",j.BOTTOM_CENTER="BOTTOM_CENTER",j.BOTTOM_LEFT="BOTTOM_LEFT",j.CENTER="CENTER",(z=K||(K={})).GOOGLE="GOOGLE",z.STANDARD="STANDARD",(J=Y||(Y={})).DISMISS_FIRST_MENU_AFTER="DISMISS_FIRST_MENU_AFTER",J.DISMISS="DISMISS",(Q=X||(X={})).DISMISS="DISMISS",Q.NONE="NONE",(q=Z||(Z={})).DEFAULT="DEFAULT",q.PLAINTEXT="PLAINTEXT",(te=ee||(ee={})).CHECKLIST_OVERRIDE="CHECKLIST_OVERRIDE",te.RESOURCE_CENTER_ONLY="RESOURCE_CENTER_ONLY",te.NONE="NONE",(ie=se||(se={})).BUBBLE="BUBBLE",ie.END="END",ie.ERROR="ERROR",ie.FLAG="FLAG",(oe=ne||(ne={})).MANUAL="MANUAL",oe.NONE="NONE",oe.SYNTHETIC="SYNTHETIC",(ae=re||(re={})).BUBBLE="BUBBLE",ae.HIDDEN="HIDDEN",ae.MODAL="MODAL",ae.TOOLTIP="TOOLTIP",(le=ce||(ce={})).ABOVE="ABOVE",le.BELOW="BELOW",le.LEFT="LEFT",le.RIGHT="RIGHT",(he=de||(de={})).CLOSE_FLOW="CLOSE_FLOW",he.EVAL_JS="EVAL_JS",he.GO_TO_STEP="GO_TO_STEP",he.NAVIGATE="NAVIGATE",he.SNOOZE="SNOOZE",he.START_FLOW="START_FLOW",(fe=ue||(ue={})).NEW_TAB="NEW_TAB",fe.SAME_TAB="SAME_TAB",(we=Ee||(Ee={})).MULTILINE_TEXT="MULTILINE_TEXT",we.MULTIPLE_CHOICE="MULTIPLE_CHOICE",we.NPS="NPS",we.SCALE="SCALE",we.STARS="STARS",we.TEXT="TEXT",(pe=Te||(Te={})).ACTION="ACTION",pe.CHECKLIST="CHECKLIST",pe.CONTACT="CONTACT",pe.FLOWS="FLOWS",pe.KNOWLEDGE_BASE="KNOWLEDGE_BASE",pe.MESSAGE="MESSAGE",pe.SUBPAGE="SUBPAGE",(ge=Se||(Se={})).CRISP="CRISP",ge.CUSTOM="CUSTOM",ge.FRESHCHAT="FRESHCHAT",ge.HELPSCOUT="HELPSCOUT",ge.HUBSPOT="HUBSPOT",ge.INTERCOM="INTERCOM",ge.ZENDESK="ZENDESK",ge.ZENDESK_MESSENGER="ZENDESK_MESSENGER",(Ie=Ce||(Ce={})).LAUNCHER_CLICK="LAUNCHER_CLICK",Ie.LAUNCHER_HOVER="LAUNCHER_HOVER",Ie.TARGET_CLICK="TARGET_CLICK",Ie.TARGET_HOVER="TARGET_HOVER",Ie.LAUNCHER_TARGET_CLICK="LAUNCHER_TARGET_CLICK",Ie.LAUNCHER_TARGET_HOVER="LAUNCHER_TARGET_HOVER",(ke=me||(me={})).ACTIVATE="ACTIVATE",ke.DEACTIVATE="DEACTIVATE",ke.NEVER="NEVER",(Ae=Ue||(Ue={})).AUTO="AUTO",Ae.TOP="TOP",Ae.RIGHT="RIGHT",Ae.BOTTOM="BOTTOM",Ae.LEFT="LEFT",(ye=Le||(Le={})).START="START",ye.CENTER="CENTER",ye.END="END",(Oe=Re||(Re={})).PERCENT="PERCENT",Oe.PX="PX",(Ne=ve||(ve={})).BEACON="BEACON",Ne.BUTTON="BUTTON",Ne.HIDDEN="HIDDEN",Ne.ICON="ICON",(be=_e||(_e={})).LAUNCHER="LAUNCHER",be.TARGET="TARGET",(Fe=De||(De={})).ACTIVE="ACTIVE",Fe.COMPLETED="COMPLETED",Fe.ENDED="ENDED",Fe.NOT_SEEN="NOT_SEEN",(Pe=Me||(Me={})).HIGHLIGHT="HIGHLIGHT",Pe.MODAL="MODAL",Pe.HIGHLIGHT_MODAL="HIGHLIGHT_MODAL";const Be={customInputs:[],customNavigate:null,urlFilter:null,customScrollIntoView:null,scrollPadding:null,inferenceAttributeNames:["data-for","data-id","data-testid","data-test-id","for","id","name","placeholder","role"],inferenceAttributeFilters:{id:[e=>!e.match(/\d$/)],"data-id":[e=>!e.match(/\d$/)]},inferenceClassNameFilters:[e=>!e.startsWith("css-")]};function xe(e){return Array.isArray(e)||(e=e?[e]:[]),e=e.map((e=>"string"==typeof e?new RegExp(e):e))}function He(e,t){return e.every((e=>"function"==typeof e?e(t):!(e instanceof RegExp)||e.test(t)))}function Ge(){let e=d();if(Be.urlFilter){if(e=Be.urlFilter(e),"string"!=typeof e)throw new o("Userflow.js: URL filter returned non-string value. Please check your userflow.setUrlFilter() implementation.");try{new URL(e)}catch(t){throw new o("Userflow.js: URL filter returned an invalid URL. Please check your userflow.setUrlFilter() implementation.\nReturned URL: "+e+"\nError message: "+t.message)}}return e}const We=(localStorage.getItem("debug")||"").split(",").some((e=>"*"===e||e.startsWith("userflow:*"))),$e=je("log");let Ve;function je(e){return function(t,...s){if(We){const i=performance.now(),n=Ve?Math.round(i-Ve):0;Ve=i,console[e](`%cuserflow %c${t} %c+${n}ms`,"color:#4579E4;","","color:#4579E4;",...s)}}}$e.group=je("group"),$e.groupCollapsed=je("groupCollapsed"),$e.groupEnd=function(){We&&console.groupEnd()};const Ke=()=>n((()=>import("./ResourceCenterApp.js")),[new URL("ResourceCenterApp.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("Icons.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("vendor.obj-str.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.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("vendor.fortawesome.pro-regular-svg-icons.js",import.meta.url).toString(),new URL("ChecklistUI.js",import.meta.url).toString(),new URL("vendor.phoenix.js",import.meta.url).toString(),new URL("vendor.uuid.js",import.meta.url).toString()]);function ze(e){const t=e.version.checklist.tasks.length;return Math.max(0,t-e.taskCompletions.length)}class Ye{constructor(e){this.observers=new Set,this._value=e}get value(){return this._value}update(e){if(e!==this._value){this._value=e;for(const e of this.observers)e()}}observe(e){return this.observers.add(e),()=>this.observers.delete(e)}}const Je=import.meta.url;class Xe{constructor(){this.clientToken=null,this.externalId=null,this.signature=null,this.groupId=null,this.groupSignature=null,this._socketStatus="disconnected",this.socket=null,this.channel=null,this.featureFlags=new Set,this.logrocketAppId=null,this.debounceInactiveDisconnectTimeout=void 0,this.inBatch=!1,this.endBatchTimeout=void 0,this.pushRateLimitMinute=0,this.pushRateLimitMinuteExpires=0,this.clientClock=1,this.serverClock=1,this.flowSession=null,this.flowSessionClock=0,this.checklistSession=null,this.checklistExpanded=!1,this.checklistExpandPending=!1,this.checklistSessionClock=0,this.resourceCenterSession=null,this.resourceCenterOpen=!1,this.resourceCenterLauncherHidden=!1,this.launcherSessions=[],this.activeLauncherFlowId=null,this.notifications=[],this.notificationIdCounter=0,this.sessionStorageState=null,this.clientContext=null,this.flushUrlChangeTimeout=void 0,this.onFirstIdentifyRun=!1,this.onFirstIdentifyTimeout=void 0,this.firstIdentifyCallback=null,this.ui=null,this.unackedTasks=new Set,this.clientConditions=new Map,this.trackers=new Map,this.conditionWaitTimers=new Map,this.listeners=new Map,this.targetEnv=null,this.idempotencyKeysSeen=new Set,this.testUserIdentified=!1,this.cspIssueReported=!1,this.uiDisabled=!1,this.audio=null,this.audioReady=!1,this.pageTrackingDisabled=!1,this.onBuilderMessage=e=>(this.handleBuilderMessage(e),!1),this.handleBuilderMessage=async e=>{$e(`builder ${e.kind} message received`,e);const t="idempotencyKey"in e&&"string"==typeof e.idempotencyKey?e.idempotencyKey:null;if(t&&this.idempotencyKeysSeen.has(t))return;const s=()=>{t&&this.idempotencyKeysSeen.add(t)};switch(e.kind){case"userflow:selectElement":return s(),this.getTargetEnv().postBuilderMessage({kind:"userflow:selectElementAck",idempotencyKey:e.idempotencyKey}),void this.setSessionStorageState((t=>({...t,activeApp:"elementSelection",elementSelection:{mode:"select",elementType:e.elementType}})));case"userflow:selectElementCancel":return void this.setSessionStorageState((e=>({...e,activeApp:null,elementSelection:null})));case"userflow:startFlowWithToken":return s(),this.getTargetEnv().postBuilderMessage({kind:"userflow:startFlowWithTokenAck",idempotencyKey:e.idempotencyKey}),c.setItem("previewFlowId",e.flowId),e.testUser?this.identifyTestUser(e.testUser):this.resetTestUser(),void this.onceIdentified((()=>{if(this.startFlowWithToken(e.token),e.isResourceCenter){const t=()=>{const s=this.resourceCenterSession;s&&s.draftMode&&s.flow.id===e.flowId&&(this.openResourceCenter(),this.off("resourceCenterChanged",t))};this.on("resourceCenterChanged",t),t()}}));case"userflow:testTracker":return s(),this.getTargetEnv().postBuilderMessage({kind:"userflow:testTrackerAck",idempotencyKey:e.idempotencyKey}),e.testUser?this.identifyTestUser(e.testUser):this.resetTestUser(),void this.setSessionStorageState((t=>({...t,activeApp:"trackerTesting",trackerTesting:{trackerName:e.trackerName,token:e.token,events:0}})));case"userflow:testTrackerCancel":return void this.setSessionStorageState((e=>({...e,activeApp:null,trackerTesting:null})))}},this.onUrlChange=()=>{this.externalId&&(window.clearTimeout(this.flushUrlChangeTimeout),this.flushUrlChangeTimeout=window.setTimeout((()=>this.flushUrlChange()),50))},this.onUserActivity=()=>this.ensureConnected(),$e("constructor, build=1002497"),S(this.onUrlChange),this.setTargetEnv(new I),this.checkTestUserAtBoot(),this.toggleUI()}get socketStatus(){return this._socketStatus}destroy(){$e("destroy"),this.reset(),g(this.onUrlChange),this.destroyTargetEnv()}setTargetEnv(e){this.destroyTargetEnv(),this.targetEnv=e,e.onBuilderMessage(this.onBuilderMessage)}destroyTargetEnv(){this.targetEnv&&(this.targetEnv.destroy(),this.targetEnv=null)}getTargetEnv(){if(!this.targetEnv)throw new o("Userflow.js: Cannot call getTargetEnv when protocol is not set");return this.targetEnv}setSessionStorageState(e){const t=e(this.getSessionStorageState());c.setItem("userflowClientState",JSON.stringify(t)),this.sessionStorageState=t,this.toggleUI()}getSessionStorageState(){let e=this.sessionStorageState;if(!e){const s=c.getItem("userflowClientState");if(s)try{e=JSON.parse(s)}catch(t){console.error("Userflow.js: Parse ElementSelectionState error:",t)}e||(e={testUser:null,activeApp:null,elementSelection:null,trackerTesting:null})}return e}checkTestUserAtBoot(){const e=this.getSessionStorageState().testUser;e&&($e("checkTestUserAtBoot identifying test user"),this.identifyTestUser(e))}async identifyTestUser(e){this.setSessionStorageState((t=>({...t,testUser:e}))),this.reset(),this.init(e.clientToken),this.testUserIdentified=!0,this.externalId=e.id;const t=[this.identify(e.id,{name:e.name,email:e.email,signed_up_at:{set_once:(new Date).toISOString(),data_type:"datetime"}},{signature:e.signature})],{group:s}=e;s&&(this.groupId=s.id,t.push(this.group(s.id,{name:s.name},{signature:s.signature}))),await Promise.all(t)}resetTestUser(){this.setSessionStorageState((e=>({...e,testUser:null})))}init(e){if($e("init",e),!e)throw new o("userflow.init() was called but missing Userflow.js Token");this.clientToken!==e&&(this.testUserIdentified?$e("init() ignoring new token since a test user has been identified"):(this.clientToken&&($e("init() resetting due to new client token"),this.reset()),this.clientToken=e))}ensureInit(){if(!this.clientToken)throw new o("You must call userflow.init() first")}ensureIdentified(){if(this.ensureInit(),!this.externalId)throw new o("You must call userflow.identify() first");return this.externalId}ensureGroup(){if(this.ensureIdentified(),!this.groupId)throw new o("You must call userflow.group() first");return this.groupId}ensureConnected(){if(!this.clientToken||!this.externalId)return;if(this.debounceInactiveDisconnect(),this.socket)return;this._socketStatus="connecting",$e("connecting to socket");let t="e.userflow.com";"js.getuserflow.com"===new URL(Je).hostname&&"e.userflow.com"===t&&(t="e.getuserflow.com");const s="wss://"+t+"/end-users/"+this.clientToken+"/socket";this.socket=new e(s,{reconnectAfterMs:e=>[100,500,1e3,5e3][e-1]||1e4,timeout:2e4}),this.socket.connect(),this.socket.onOpen((()=>{$e("socket opened")})),this.socket.onError((e=>{console.log("Userflow.js socket error",e),this.reportCspIssue()})),this.channel=this.socket.channel(`end_users:${this.externalId}`,(()=>this.makeChannelJoinPayload())),this.channel.join().receive("ok",(e=>{this.logrocketAppId=e.logrocketAppId,this.featureFlags=new Set(e.featureFlags),$e("channel joined"),"connected"!==this._socketStatus&&(this._socketStatus="connected")})).receive("error",(e=>{["company_closed","invalid_client_token","invalid_user_external_id","incorrect_user_signature","rate_limit_exceeded","user_signature_required"].includes(e.code)?(console.error(`Userflow.js resetting due to: [${e.code}] ${e.message}`),this.reset(),this.clientToken=null):"invalid_protocol_version"===e.code?(console.error(`Userflow.js destroying due to: [${e.code}] ${e.message}`),this.destroy()):console.log("Userflow.js channel join error",e)})),this.channel.on("server_message",(e=>this.handleServerMessage(e))),this.channel.on("server_error",(e=>{console.log(`Userflow.js server error (${e.code}): ${e.message}`+(e.details&&e.details.length>0?"\nDetails:\n"+e.details.map((e=>(e.path?`${e.path}: `:"")+e.message)):""))}))}makeChannelJoinPayload(){const e=this.buildClientContext();this.clientContext=e;const t={protocolVersion:2,userflowClientBuild:"1002497",signature:this.signature,groupExternalId:this.groupId,groupSignature:this.groupSignature,flowSessionId:this.flowSession?.id||null,checklistSessionId:this.checklistSession?.id||null,resourceCenterSessionId:this.resourceCenterSession?.id||null,launchers:this.launcherSessions.map((e=>({flowId:e.flow.id}))),trackers:Array.from(this.trackers.values()).map((e=>({flowId:e.tracker.flowId}))),hasDraftSession:this.hasDraftSession(),clientConditions:Array.from(this.clientConditions.values()).map((e=>({conditionId:e.condition.id,isTrue:e.isTrue}))),previewFlowId:c.getItem("previewFlowId"),clientContext:e};return $e("channel join payload",t),t}disconnect(){window.clearTimeout(this.debounceInactiveDisconnectTimeout),this.socket&&this.socket.disconnect(),this._socketStatus="disconnected",this.socket=null,this.channel=null}debounceInactiveDisconnect(){window.clearTimeout(this.debounceInactiveDisconnectTimeout),this.debounceInactiveDisconnectTimeout=window.setTimeout((()=>{this.hasDraftSession()?this.debounceInactiveDisconnect():($e("disconnecting from socket due to inactivity"),this.disconnect())}),3e5)}hasDraftSession(){return!!this.flowSession?.draftMode||!!this.checklistSession?.draftMode||!!this.resourceCenterSession?.draftMode||this.launcherSessions.some((e=>e.draftMode))}async send(e,{batch:t,handlesRejection:s}={}){return this.inBatch&&["ToggleClientCondition","UpdateClientContext"].includes(e.kind)||this.checkPushRateLimit(),this.ensureConnected(),t&&!this.inBatch&&(this.inBatch=!0,this.sendRaw({kind:"BeginBatch"})),this.inBatch&&(window.clearTimeout(this.endBatchTimeout),this.endBatchTimeout=window.setTimeout((()=>{this.inBatch=!1,this.sendRaw({kind:"EndBatch"})}),50)),this.sendRaw(e,{handlesRejection:s})}async sendRaw(e,{handlesRejection:t}={}){return new Promise(((s,i)=>{if(!this.channel)throw Error("Userflow.js: send() should not be called if channel is not set");$e(`push ${e.kind} message`,e);const n=this.clientClock,r=()=>{this.serverClock=n,this.channel?.off("phx_error",a)},a=this.channel.on("phx_error",(s=>{r();const n="Userflow.js send got phx_error";console.log(n,"\nClient message:",e,"\nError:",s),t&&i(new o(n))}));this.channel.push("client_message",e).receive("ok",(e=>{r(),s(e)})).receive("error",(t=>{r();const s=`Userflow.js error reply (${t.code}): ${t.message}`;console.log(s,"\nClient message:",e,"\nError:",t),i(new o(s,t.code))}))}))}checkPushRateLimit(){const e=Date.now();if(this.pushRateLimitMinuteExpires<e&&(this.pushRateLimitMinute=0,this.pushRateLimitMinuteExpires=e+6e4),this.pushRateLimitMinute>=100)throw new o("This Userflow.js client has reached a maximum of 100 operations in the last 1 minute. This is usually due to one of the following:\n\n - Excessive calls to Userflow.js. Check if any of userflow.track(), userflow.identify(), userflow.updateUser() or similar are called repeatedly.\n - The URL changing too frequently. Look into https://userflow.com/docs/userflow-js#seturlfilter and filter out the changing part of the URL.\n - The user legitimately being very active, in which case you can just ignore this error.\n \n If in doubt, reach out to us at support@userflow.com.");this.pushRateLimitMinute++}handleServerMessage(e){$e(`received ${e.kind} message`,e);const{serverClock:t,flowSession:s,flowSessionClock:i,checklistSession:n,checklistSessionClock:o,resourceCenterSession:r}=this;switch(e.kind){case"CheckSessionsAck":case"ServerDebug":return;case"AddLauncher":{const{session:t}=e,s=this.launcherSessions.findIndex((e=>e.flow.id===t.flow.id));return this.launcherSessions=-1===s?[...this.launcherSessions,t]:[...this.launcherSessions.slice(0,s),t,...this.launcherSessions.slice(s+1)],void this.toggleUI()}case"AddTracker":return void this.addTracker(e.tracker);case"CancelConditionWaitTimer":return window.clearTimeout(this.conditionWaitTimers.get(e.conditionId)),void this.conditionWaitTimers.delete(e.conditionId);case"ChecklistTaskCompleted":return void this.unackedTasks.add(e.taskCvid);case"ForceGoToStep":return i>t?void $e(`ignoring ${e.kind} message due to stale clock flowSessionClock=${i} > serverClock=${t}`):void(s?.id===e.sessionId&&this.emit("gotostep",{session:s,step:{id:e.stepId}}));case"RemoveLauncher":return void(this.removeLauncher(e.flowId)&&this.toggleUI());case"RemoveTracker":return void this.removeTracker(e.flowId);case"SetChecklistSession":return void(o<=t||n?.id===e.session.id?(this.setChecklistSession(e.session,t),this.toggleUI()):$e(`ignoring ${e.kind} message due to stale clock checklistSessionClock=${o} > serverClock=${t}`));case"SetFlowSession":return void(i<=t||s?.id===e.session.id?(this.setFlowSession(e.session,t),this.toggleUI()):$e(`ignoring ${e.kind} message due to stale clock flowSessionClock=${i} > serverClock=${t}`));case"SetResourceCenterSession":return this.setResourceCenterSession(e.session),void this.toggleUI();case"StartConditionWaitTimer":if(!this.conditionWaitTimers.has(e.conditionId)){const t=window.setTimeout((()=>{this.conditionWaitTimers.delete(e.conditionId),this.send({kind:"FireConditionWaitTimer",conditionId:e.conditionId},{batch:!0})}),1e3*parseFloat(e.waitTime));this.conditionWaitTimers.set(e.conditionId,t)}return;case"TrackClientCondition":return void this.trackClientCondition(e.condition);case"UnsetChecklistSession":return o>t?void $e(`ignoring ${e.kind} message due to stale clock checklistSessionClock=${o} > serverClock=${t}`):void(n?.id===e.sessionId&&(this.setChecklistSession(null,t),this.toggleUI()));case"UnsetFlowSession":return i>t?void $e(`ignoring ${e.kind} message due to stale clock flowSessionClock=${i} > serverClock=${t}`):void(s?.id===e.sessionId&&(this.setFlowSession(null,t),this.toggleUI()));case"UnsetResourceCenterSession":return void(r?.id===e.sessionId&&(this.setResourceCenterSession(null),this.toggleUI()));case"UntrackClientCondition":return void this.untrackClientCondition(e.conditionId);default:return void console.warn("Userflow.js: Received unknown message",e)}}async identify(e,t={},{signature:s}={}){if($e("identify",e),this.ensureInit(),this.testUserIdentified&&e!==this.externalId)$e("identify() ignored since a test user has been identified");else{if("number"==typeof e)e=String(e);else if(!e||"string"!=typeof e)throw new o(`userflow.identify: First argument must be a non-empty string representing the user's ID in your database. Value received: ${JSON.stringify(e)}`);this.externalId&&e!==this.externalId&&($e("identify resetting due to new externalId"),this.reset()),this.externalId=e,this.signature=s||null,this.observeUserActivity(),await Promise.all([this.send({kind:"UpsertUser",attributes:this.normalizeAttributes(t)},{batch:!0}),this.onFirstIdentify()]),this.emit("private:identified")}}async identifyAnonymous(e={},s={}){const i="anonymousId";let n=a.getItem(i);n||(n="anon-"+t(),a.setItem(i,n)),await this.identify(n,e,s)}async updateUser(e={},t={}){$e("updateUser"),this.ensureIdentified(),await this.send({kind:"UpsertUser",attributes:this.normalizeAttributes(e)},{batch:!0})}async group(e,t={},{signature:s,membership:i}={}){if($e("group",e),this.ensureIdentified(),this.testUserIdentified&&e!==this.groupId)$e("group() ignored since a test user has been identified");else{if("number"==typeof e)e=String(e);else if(!e||"string"!=typeof e)throw new o(`userflow.group: First argument must be a non-empty string representing the group's ID in your database. Value received: ${JSON.stringify(e)}`);this.groupId=e,this.groupSignature=s||null,await this.send({kind:"UpsertGroup",groupExternalId:e,groupSignature:this.groupSignature,groupAttributes:this.normalizeAttributes(t),membershipAttributes:this.normalizeAttributes(i)},{batch:!0})}}async updateGroup(e={},t={}){$e("updateGroup");const s=this.ensureGroup();await this.send({kind:"UpsertGroup",groupExternalId:s,groupSignature:this.groupSignature,membershipAttributes:this.normalizeAttributes(t.membership),groupAttributes:this.normalizeAttributes(e)},{batch:!0})}normalizeAttributes(e){if(null==e)return{};if("object"!=typeof e)throw new o("Userflow: 'attributes' must be an object.");const t={};for(const s in e){if(!e.hasOwnProperty(s))continue;if("traits"===s){const i=e[s];Object.assign(t,this.extractLegacyTraits(i));continue}let i=e[s];if("string"==typeof i||"number"==typeof i||"boolean"==typeof i||null==i||Array.isArray(i))t[s]=this.normalizeAttributeLiteralOrList(s,i);else{if("object"!=typeof i||null==i)throw new o(`Userflow: Invalid value for '${s}' attribute.`);if("set"in i)t[s]={set:this.normalizeAttributeLiteralOrList(s,i.set),dataType:this.normalizeDataType(s,i.data_type||i.dataType)};else if("set_once"in i||"setOnce"in i)t[s]={setOnce:this.normalizeAttributeLiteralOrList(s,i.set_once||i.setOnce),dataType:this.normalizeDataType(s,i.data_type||i.dataType)};else if("add"in i){const e=i.add;if("string"!=typeof e&&"number"!=typeof e)throw new o(`Userflow: Invalid 'add' value for '${s}' attribute. Must be a number or string.`);t[s]={add:e}}else if("subtract"in i){const e=i.subtract;if("string"!=typeof e&&"number"!=typeof e)throw new o(`Userflow: Invalid 'subtract' value for '${s}' attribute. Must be a number or string.`);t[s]={subtract:e}}else if("append"in i)t[s]={append:this.normalizeAttributeLiteralOrList(s,i.append)};else if("prepend"in i)t[s]={prepend:this.normalizeAttributeLiteralOrList(s,i.prepend)};else{if(!("remove"in i))throw new o(`Userflow: Invalid value for '${s}' attribute.`);t[s]={remove:this.normalizeAttributeLiteralOrList(s,i.remove)}}}}return t}normalizeAttributeLiteralOrList(e,t){return Array.isArray(t)?t.map((t=>this.normalizeAttributeLiteral(e,t))):this.normalizeAttributeLiteral(e,t)}normalizeAttributeLiteral(e,t){if(null==t)return null;if("string"==typeof t||"number"==typeof t||"boolean"==typeof t)return t;throw new o(`Userflow: Invalid value for '${e}' attribute.`)}normalizeDataType(e,t){if(!t)return null;switch(t){case"string":return R.STRING;case"number":return R.NUMBER;case"boolean":return R.BOOLEAN;case"datetime":return R.DATETIME}throw new o(`Userflow: Invalid data_type for '${e}' attribute.`)}extractLegacyTraits(e){if(!e)return{};if(!Array.isArray(e)){const t=[];for(const s in e)e.hasOwnProperty(s)&&t.push({name:s,value:e[s]});e=t}return e.reduce(((e,{name:t,value:s,dataType:i})=>{if("string"!=typeof t||t.length>100||!t.match(/^[a-z0-9_]+$/))return this.warn("Userflow.identify: Invalid trait name (must be string, no more than 100 characters, and only consist of a-z, 0-9 and underscores). The trait will be ignored. Name was:",t),e;if("string"==typeof s);else if("boolean"==typeof s)i||(i="boolean"),s=s?"true":"false";else{if("number"!=typeof s)return this.warn(`userflow.identify: The value of trait '${t}' is invalid (must be a string, a boolean or a number). The trait will be ignored. Value was:`,s),e;i||(i=Number.isInteger(s)?"integer":"decimal"),s=String(s)}let n=null;if(i)switch(i){case"string":n=R.STRING;break;case"boolean":n=R.BOOLEAN;break;case"integer":case"decimal":n=R.NUMBER;break;case"datetime":n=R.DATETIME;break;default:return this.warn(`userflow.identify: The data type of trait '${t}' is invalid (must be a 'string', 'boolean', 'integer', 'decimal' or 'datetime'). The trait will be ignored. Data type was:`,i),e}return e[t]={set:s,dataType:n},e}),{})}async track(e,t={},{userOnly:s}={}){$e(`track '${e}'`,t),this.ensureIdentified(),await this.send({kind:"TrackEvent",userOnly:!!s,name:e,attributes:this.normalizeEventAttributes(t)},{batch:!0})}normalizeEventAttributes(e){const t=this.normalizeAttributes(e);for(const s in t){if(!t.hasOwnProperty(s))continue;const e=t[s];if(null!=e&&"string"!=typeof e&&"boolean"!=typeof e&&"number"!=typeof e&&!Array.isArray(e)&&!("set"in e))throw new o(`Userflow: Invalid value for '${s}' attribute. Event attributes only support literal values, list values and 'set' changes.`)}return t}onFirstIdentify(){this.onFirstIdentifyRun||(this.onFirstIdentifyRun=!0,this.onFirstIdentifyTimeout=window.setTimeout((()=>{this.trackPageViewed(),this.firstIdentifyCallback?(this.firstIdentifyCallback(),this.firstIdentifyCallback=null):this.checkUrlForStartFlow()}),0))}onceIdentified(e){this.isIdentified()?e():this.firstIdentifyCallback=e}checkUrlForStartFlow(){const e=new URL(d()),t=e.searchParams.get("userflow")||e.searchParams.get("studio1_flow")||e.searchParams.get("studio1_walkthrough");t&&($e(`url contained flow ${t}`),this.startFlow({flowId:t,startReason:L.LINK,batch:!0}),e.searchParams.delete("userflow"),e.searchParams.delete("studio1_flow"),e.searchParams.delete("studio1_walkthrough"),window.history.replaceState({},"",e.toString()),this.clientContext=this.buildClientContext(),this.pushUpdateClientContext())}flushUrlChange(){const e=this.buildClientContext();this.clientContext&&e.pageUrl===this.clientContext.pageUrl||(this.clientContext=e,this.pushUpdateClientContext(),this.trackPageViewed(),this.checkUrlForStartFlow())}async trackPageViewed(){this.pageTrackingDisabled||this.track("page_viewed",{})}buildClientContext(){return{pageUrl:Ge(),viewportWidth:window.innerWidth,viewportHeight:window.innerHeight}}pushUpdateClientContext(){this.send({kind:"UpdateClientContext",clientContext:this.clientContext},{batch:!0})}ackCompletedTask(e){this.unackedTasks.delete(e)}taskIsUnacked(e){return this.unackedTasks.has(e)}isIdentified(){return null!=this.externalId}on(e,t){let s=this.listeners.get(e);s||(s=new Set,this.listeners.set(e,s)),s.add(t)}off(e,t){const s=this.listeners.get(e);s&&s.delete(t)}emit(e,...t){const s=this.listeners.get(e);if(s){Array.from(s).forEach((e=>e(...t)))}}observeUserActivity(){document.addEventListener("mouseover",this.onUserActivity),document.addEventListener("pointerdown",this.onUserActivity),document.addEventListener("keydown",this.onUserActivity)}unobserveUserActivity(){document.removeEventListener("mouseover",this.onUserActivity),document.removeEventListener("pointerdown",this.onUserActivity),document.removeEventListener("keydown",this.onUserActivity)}reset(){$e("reset"),this.externalId=null,this.groupId=null,this.sessionStorageState=null,this.setFlowSession(null,0),this.setChecklistSession(null,0),this.setResourceCenterSession(null),this.launcherSessions=[],this.activeLauncherFlowId=null,this.notifications=[],this.unackedTasks=new Set,this.onFirstIdentifyRun=!1,window.clearTimeout(this.onFirstIdentifyTimeout),this.onFirstIdentifyTimeout=void 0,this.clientContext=null,this.unobserveUserActivity(),window.clearTimeout(this.flushUrlChangeTimeout),this.flushUrlChangeTimeout=void 0,this.clientConditions.forEach(((e,t)=>{this.untrackClientCondition(t)})),this.firstIdentifyCallback=null,this.testUserIdentified=!1,a.removeItem("anonymousId"),this.unmountUI(),this.disconnect(),this.inBatch=!1,window.clearTimeout(this.endBatchTimeout),this.endBatchTimeout=void 0,this.clientClock=1,this.serverClock=1}async startFlow({flowId:e,stepCvid:t,startReason:s,once:i,batch:n,replaceCurrent:o}){if(this.ensureIdentified(),o&&this.flowSession&&this.endFlow(this.flowSession,{endReason:m.REPLACED,batch:!0}),$e(`startFlow ${e}`,{startReason:s}),this.checklistSession?.flow.id===e)return $e("startFlow matches current checklist, so showing it instead"),void this.showChecklist();const r={kind:"StartFlow",flowId:e,stepCvid:t,startReason:s,once:!!i};await this.send(r,{batch:n})}async startFlowWithToken(e){this.ensureIdentified(),$e("startFlowWithToken",{token:e}),await this.send({kind:"StartFlowWithToken",token:e},{batch:!0})}optimisticClockUIUpdate(e){this.clientClock++,e(),this.toggleUI()}async showChecklist(){this.resourceCenterEmbedsChecklist()?this.openResourceCenter():(this.unmarkExpandPending(),this.checklistSession&&!this.checklistExpanded&&(this.ensureIdentified(),this.checklistExpanded=!0,this.toggleUI(),c.setItem(`checklistExpanded:${this.checklistSession.id}`,"1"),await this.send({kind:"ShowChecklist",sessionId:this.checklistSession.id},{batch:!0})))}async hideChecklist(){this.resourceCenterEmbedsChecklist()?this.closeResourceCenter():this.checklistSession&&this.checklistExpanded&&(this.ensureIdentified(),this.checklistExpanded=!1,this.toggleUI(),c.removeItem(`checklistExpanded:${this.checklistSession.id}`),await this.send({kind:"HideChecklist",sessionId:this.checklistSession.id},{batch:!0}))}async unmarkExpandPending(){this.checklistSession&&this.checklistExpandPending&&(this.checklistExpandPending=!1,await this.send({kind:"UnmarkExpandPending",sessionId:this.checklistSession.id},{batch:!0}))}async openResourceCenter(){this.resourceCenterEmbedsChecklist()&&this.unmarkExpandPending(),this.resourceCenterSession&&!this.resourceCenterOpen&&(this.ensureIdentified(),this.resourceCenterOpen=!0,this.toggleUI(),this.emit("resourceCenterChanged"),c.setItem(`resourceCenterOpen:${this.resourceCenterSession.id}`,"1"),await this.send({kind:"OpenResourceCenter",sessionId:this.resourceCenterSession.id},{batch:!0}))}async closeResourceCenter(){this.resourceCenterSession&&this.resourceCenterOpen&&(this.ensureIdentified(),this.resourceCenterOpen=!1,this.toggleUI(),this.emit("resourceCenterChanged"),c.removeItem(`resourceCenterOpen:${this.resourceCenterSession.id}`),await this.send({kind:"CloseResourceCenter",sessionId:this.resourceCenterSession.id},{batch:!0}))}toggleResourceCenter(){this.resourceCenterOpen?this.closeResourceCenter():this.openResourceCenter()}setResourceCenterLauncherHidden(e){this.resourceCenterLauncherHidden=e,this.toggleUI()}getResourceCenterState(){if(!this.resourceCenterSession)return null;const e=this.resourceCenterEmbedsChecklist(),{checklistSession:t}=this;return{isOpen:this.resourceCenterOpen,hasChecklist:e,uncompletedChecklistTaskCount:e&&t?ze(t):0}}resourceCenterEmbedsChecklist(){const e=this.resourceCenterSession;return!!e&&!!e.version.resourceCenter?.blocks.some((e=>e.type===Te.CHECKLIST))}async endFlow(e,{endReason:t,batch:s}){this.ensureIdentified(),this.optimisticClockUIUpdate((()=>{const{clientClock:t}=this;this.flowSession?.id===e.id&&this.setFlowSession(null,t),this.checklistSession?.id===e.id&&this.setChecklistSession(null,t),this.resourceCenterSession?.id===e.id&&this.setResourceCenterSession(null)}));const{flow:i}=e,n={id:i.id,type:i.type.toLowerCase()};i.type===v.CHECKLIST?this.emit("checklistEnded",{checklist:n,endReason:t}):i.type===v.FLOW&&this.emit("flowEnded",{flow:n,endReason:t});const o={kind:"EndFlow",sessionId:e.id,endReason:t};await this.send(o,{batch:s})}async goToStep(e,t){$e("goToStep",e.id,t.name||t.id),this.ensureIdentified();const s=this.send({kind:"GoToStep",sessionId:e.id,stepId:t.id});e.currentStep=t,this.emit("gotostep",{session:e,step:t}),await s}async endAllFlows(){$e("endAllFlows"),this.optimisticClockUIUpdate((()=>{const{clientClock:e}=this;this.setFlowSession(null,e),this.setChecklistSession(null,e)})),await this.send({kind:"EndAllFlows"})}async endChecklist(){$e("endChecklist");const e=this.checklistSession||this.flowSession;e?.flow.type===v.CHECKLIST&&this.endFlow(e,{endReason:m.USERFLOWJS})}setFlowSession(e,t=this.clientClock){const s=this.flowSession;this.flowSession=e,this.flowSessionClock=t,e&&!s&&(this.hideChecklist(),this.closeResourceCenter()),null==e&&this.originalActiveElement&&("function"==typeof this.originalActiveElement.focus&&this.originalActiveElement.focus(),this.originalActiveElement=void 0)}setChecklistSession(e,t=this.clientClock){const s=this.checklistSession;this.checklistSession=e,this.checklistSessionClock=t,null===e&&(this.checklistExpanded=!1,this.checklistExpandPending=!1),e&&e.id!==s?.id&&(this.checklistExpanded=!!c.getItem(`checklistExpanded:${e.id}`),e.expandPending&&(this.checklistExpandPending=!0)),this.emit("checklistChanged"),this.emit("resourceCenterChanged")}setResourceCenterSession(e){const t=this.resourceCenterSession;this.resourceCenterSession=e,null===e&&(this.resourceCenterOpen=!1),t&&t.id!==e?.id&&c.removeItem(`resourceCenterOpen:${t.id}`),e&&e.id!==t?.id&&(this.resourceCenterOpen=!!c.getItem(`resourceCenterOpen:${e.id}`)),this.emit("resourceCenterChanged")}launcherSeen(e){this.send({kind:"StartFlow",flowId:e,startReason:L.LAUNCHER_SEEN,once:!1})}activateLauncher(e){const t=this.activeLauncherFlowId&&this.launcherSessions.find((e=>e.flow.id===this.activeLauncherFlowId));t&&this.deactivateLauncher(t),this.activeLauncherFlowId=e.flow.id,this.toggleUI(),this.send({kind:"ActivateLauncher",flowId:e.flow.id})}deactivateLauncher(e){const{launcher:t}=e.version;e.flow.id===this.activeLauncherFlowId&&(t?.dismissOn===me.DEACTIVATE?this.dismissLauncher(e,{endReason:m.LAUNCHER_DEACTIVATED}):(this.activeLauncherFlowId=null,this.toggleUI()))}dismissLauncher(e,{endReason:t}){const s=e.flow.id;this.removeLauncher(s),this.toggleUI(),this.send({kind:"DismissLauncher",flowId:s,endReason:t})}removeLauncher(e){const t=this.launcherSessions.findIndex((t=>t.flow.id===e));return-1!==t&&(this.launcherSessions=[...this.launcherSessions.slice(0,t),...this.launcherSessions.slice(t+1)],e===this.activeLauncherFlowId&&(this.activeLauncherFlowId=null),!0)}async toggleUI(){this.flowSession||!this.checklistExpandPending&&!this.checklistSession?.version.checklist?.tasks.some((e=>this.taskIsUnacked(e.cvid)))||this.showChecklist(),this.emit("uistatechange"),this.shouldBeMounted()?await this.mountUI():this.unmountUI()}shouldBeMounted(){if(this.uiDisabled)return!1;return!!this.getSessionStorageState().activeApp||!!this.flowSession||!!this.checklistSession&&(this.checklistExpanded||!!this.checklistSession?.version.checklist?.launcherEnabled)||!!this.resourceCenterSession&&(this.resourceCenterOpen||!this.resourceCenterLauncherHidden)||this.launcherSessions.length>0||this.notifications.length>0}async mountUI(){if(!this.ui){const e=await this.createUI();this.shouldBeMounted()&&!this.ui&&($e("mount UI"),this.ui=e,this.ui.mount())}}unmountUI(){this.ui&&($e("unmount UI"),this.ui.unmount(),this.ui=null)}remount(){this.unmountUI(),this.toggleUI()}async createUI(){try{const e=n((()=>import("./ui.js")),[new URL("ui.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("vendor.react-dom.js",import.meta.url).toString(),new URL("vendor.scheduler.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.phoenix.js",import.meta.url).toString(),new URL("vendor.uuid.js",import.meta.url).toString()]);this.resourceCenterSession&&Ke();const{RealUI:t}=await e;return new t(this)}catch(e){throw this.reportCspIssue(),e}}async trackClientCondition(e){if(this.clientConditions.has(e.id))return;$e("track client condition",e),this.clientConditions.set(e.id,{condition:e,isTrue:null});const{conditionTypes:t}=await n((()=>import("./flow-condition-types.js").then((function(e){return e.u}))),[new URL("flow-condition-types.js",import.meta.url).toString(),new URL("vendor.date-fns.js",import.meta.url).toString()]),s=t[e.type],i=this.clientConditions.get(e.id);i&&(i.untrack=s.track({sessionData:new Ye([]),condition:e,callback:t=>{i.isTrue!==t&&($e("client condition truthiness changed",t,i.condition),i.isTrue=t,this.send({kind:"ToggleClientCondition",conditionId:e.id,isTrue:t},{batch:!0}))}}))}untrackClientCondition(e){const t=this.clientConditions.get(e);t&&($e("untrack client condition",t.condition),t.untrack&&t.untrack(),this.clientConditions.delete(e))}async addTracker(e){let t=this.trackers.get(e.flowId);t?t.tracker=e:this.trackers.set(e.flowId,{tracker:e,isTrue:!1});const{conditionTypes:s}=await n((()=>import("./flow-condition-types.js").then((function(e){return e.u}))),[new URL("flow-condition-types.js",import.meta.url).toString(),new URL("vendor.date-fns.js",import.meta.url).toString()]),i=this.trackers.get(e.flowId);if(!i)return;const{tracker:o}=i,{condition:r}=o,a=s[r.type];i.untrack&&i.untrack(),i.untrack=a.track({sessionData:new Ye(o.data),condition:r,flipBackEvents:!0,callback:e=>{const t=i.isTrue;i.isTrue=e,!t&&e&&this.send({kind:"TrackTrackerEvent",token:o.token},{batch:!0})}}),this.emit("private:trackerStarted")}removeTracker(e){const t=this.trackers.get(e);t&&(t.untrack&&t.untrack(),this.trackers.delete(e),this.emit("private:trackerStopped"))}reportCspIssue(){const e=this.getSessionStorageState();!this.testUserIdentified&&!e.activeApp||this.cspIssueReported||(this.cspIssueReported=!0,$e("csp issue detected"),E(window,{kind:"userflow:crxCspIssueDetected"}))}getAudio(){return this.audio||(this.audio=new Audio),this.audio}playAudio(e){if(document.hidden)return;const t=this.getAudio();e&&(t.src=e);const s=t.play();this.audioReady=!0,s&&s.catch((e=>{e.name}))}pauseAudio(){const e=this.audio;e&&!e.paused&&e.pause()}async getStepSpeech(e,t){return(await this.send({kind:"GetStepSpeechV2",syntheticVoice:e,text:t})).url}featureFlagEnabled(e){return this.featureFlags.has(e)}showNotification(e,t,s){const i={id:++this.notificationIdCounter,label:e,message:t,type:s};this.notifications=[...this.notifications,i],this.toggleUI()}dismissNotification(e){this.notifications=this.notifications.filter((t=>t.id!==e)),this.toggleUI()}warn(...e){console.warn(...e)}}if(void 0===window.userflow||window.userflow._stubbed){const e=Object.assign(window.userflow||{},function(){const e=new Xe;return{_stubbed:!1,init(t){e.init(t)},identify:(t,s={},i={})=>e.identify(t,s,i),identifyAnonymous:(t={},s={})=>e.identifyAnonymous(t,s),isIdentified:()=>e.isIdentified(),updateUser:(t,s={})=>e.updateUser(t,s),group:(t,s={},i={})=>e.group(t,s,i),updateGroup:(t,s={})=>e.updateGroup(t,s),track:(t,s={},i={})=>e.track(t,s,i),start:(t,{once:s}={})=>e.startFlow({flowId:t,startReason:L.USERFLOWJS,once:s}),startFlow:e=>(console.warn("Userflow.js: userflow.startFlow() has been deprecated. Use userflow.start() instead."),window.userflow.start(e)),startWalk:e=>(console.warn("Userflow.js: userflow.startWalk() has been deprecated. Use userflow.start() instead."),window.userflow.start(e)),endAll:()=>e.endAllFlows(),endChecklist:()=>e.endChecklist(),endAllFlows:()=>window.userflow.endAll(),async endFlow(){console.warn("Userflow.js: userflow.endFlow() has been deprecated and no longer has any effect.")},async endWalk(){console.warn("Userflow.js: userflow.endWalk() has been deprecated and no longer has any effect.")},openResourceCenter(){e.openResourceCenter()},closeResourceCenter(){e.closeResourceCenter()},toggleResourceCenter(){e.toggleResourceCenter()},setResourceCenterLauncherHidden(t){e.setResourceCenterLauncherHidden(t)},getResourceCenterState:()=>e.getResourceCenterState(),setWalkPosition(){console.warn("Userflow.js: userflow.setWalkPosition() has been deprecated and no longer has any effect.")},reset(){e.reset()},remount(){e.remount()},on(t,s){e.on(t,s)},off(t,s){e.off(t,s)},setCustomInputSelector(e){console.warn("Userflow.js: userflow.setCustomInputSelector() has been deprecated. Use userflow.registerCustomInput() instead. See docs: https://userflow.com/docs/userflow-js"),e&&Be.customInputs.push({cssSelector:e})},registerCustomInput(e,t){Be.customInputs.push({cssSelector:e,getValue:t})},setCustomNavigate(e){Be.customNavigate=e},setUrlFilter(e){Be.urlFilter=e},setInferenceAttributeNames(e){Be.inferenceAttributeNames=e},setInferenceAttributeFilter(e,t){Be.inferenceAttributeFilters[e]=xe(t)},setInferenceClassNameFilter(e){Be.inferenceClassNameFilters=xe(e)},setScrollPadding(e){Be.scrollPadding=e},setCustomScrollIntoView(e){Be.customScrollIntoView=e},prepareAudio(){e.playAudio(null)},setShadowDomEnabled(e){console.warn("Userflow.js: userflow.setShadowDomEnabled() has been deprecated. Please remove this call from your Userflow.js snippet. Shadow DOM is supported by default now.")},setPageTrackingDisabled(t){e.pageTrackingDisabled=t},_setTargetEnv(t){e.setTargetEnv(t)}}}());window.userflow=e,window.studio1=e,function(){const e=window.userflow,t=window.USERFLOWJS_QUEUE;if(delete window.USERFLOWJS_QUEUE,!t||0===t.length)return;$e(`processing ${t.length} items in the queue`);for(const[s,i,n]of t){if("function"!=typeof e[s]){console.error(`Userflow.js: Invalid method '${s}' in queue`);continue}const t=e[s](...n);i&&t&&"function"==typeof t.then&&t.then(i.resolve,i.reject)}$e("queue processed")}()}export{H as A,W as B,Se as C,Ce as D,m as E,M as F,Ue as G,_e as H,Le as I,Re as J,ve as L,X as M,Ke as R,L as S,se as T,o as U,ne as V,n as _,F as a,D as b,Be as c,$e as d,_ as e,B as f,Ge as g,Te as h,ze as i,ee as j,Z as k,de as l,v as m,ue as n,S as o,Ee as p,Ye as q,K as r,l as s,He as t,g as u,a as v,Y as w,re as x,V as y,ce as z};export default window.userflow;
|