userflow.js-self-hosted 0.0.2000004 → 0.0.2000006

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 CHANGED
@@ -1 +1 @@
1
- import{r as e}from"./vendor.react.js";import{c as t,a as n,i as r}from"./flow-condition-types.js";import{b as l}from"./stylesheets.js";import{o}from"./vendor.obj-str.js";import{l as a,n as i,S as s,E as u,c,s as d,U as m,p as b,d as f}from"./userflow.js";import{S as h,a as p,V as w,b as g,c as v,T as E}from"./Icons.js";import{F as y}from"./vendor.fortawesome.react-fontawesome.js";import{f as k}from"./vendor.fortawesome.pro-solid-svg-icons.js";import{u as _}from"./vendor.react-i18next.js";import{u as x}from"./client-context.js";const j=e.createContext(null);function q(){const t=e.useContext(j);if(!t)throw new Error("useSession: Session was not set");return t}function N(n){const r=q(),[o,a]=e.useState(!1),i=l(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&&o}const S=({appearance:t,hidden:n,disabled:r,onMouseDown:l,onClick:a,text:i,active:s,children:u})=>e.createElement("button",{className:o({[ue(t)]:!0,"userflowjs-bubble-button--hidden":!!n,"userflowjs-bubble-button--active":!!s}),onMouseDown:l,onClick:a,disabled:r},u||e.createElement("div",{className:"userflowjs-bubble-button-text",role:"presentation"},i));async function C(e,t,l){const{steps:o}=t.version;switch(l.type){case a.CLOSE_FLOW:switch(t.kind){case"launcher":await e.dismissLauncher(t,{endReason:u.ACTION});break;case"flow":case"checklist":await e.endFlow(t,{endReason:u.ACTION})}return;case a.EVAL_JS:try{const e=r(l.code||"",t.data);new Function('"use strict";\n'+e)()}catch(b){console.error(`Userflow.js: Evaluate JavaScript action failed.\n\nError:\n${b.stack||b.message||b}\n\nCode:\n${l.code}`)}return;case a.GO_TO_STEP:{if("flow"!==t.kind)return;const n=o.find((({crossVersionId:e})=>e===l.stepCvid));if(!n)throw new m("Action points to unknown step: "+l.stepCvid);return void(await e.goToStep(t,n))}case a.NAVIGATE:{if(!l.url)return void console.warn("Userflow.js: NAVIGATE action is missing url property");const e=F(l.url,{lookupAttribute:n(t.data)});return void(l.navigateTarget===i.NEW_TAB?window.open(e):c.customNavigate?c.customNavigate(e):window.setTimeout((()=>{d(e)}),0))}case a.SNOOZE:return void("flow"===t.kind&&l.timeValue&&l.timeUnit&&(e.endFlow(t,{endReason:u.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 a.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?s.DRAFT:s.ACTION,replaceCurrent:!0}):console.warn("Userflow.js: START_FLOW action is missing other flow"))}}async function T(e,t,n){const r=[],l=[],o=[];for(const s of n)s.type===a.NAVIGATE?s.navigateTarget===i.NEW_TAB?r.push(s):o.push(s):l.push(s);for(const a of r)C(e,t,a);await Promise.all(l.map((n=>C(e,t,n))));for(const a of o)C(e,t,a)}const P=({button:t})=>{const n=x(),l=q(),o=N(t.disabledCondition),a=N(t.hiddenCondition);return e.createElement(S,{appearance:t.appearance,hidden:a,disabled:o,onClick:()=>T(n,l,t.actions),text:r(t.text,l.data)})},I=({type:t,required:n,buttonText:r,options:l,otherOption:a,multipleSelection:i,labelLeft:s,labelCenter:u,labelRight:c,minValue:d,maxValue:m,onSubmit:f,inert:w})=>{const{t:g}=_(),v=e.useRef(null),[E,x]=e.useState(""),[j,q]=e.useState(new Set),[N,S]=e.useState(),[C,T]=e.useState(),[P,I]=e.useState(!1),[A,$]=e.useState(!1),[M,R]=e.useState(null),F=e=>{if(!w&&f){if(n&&""===E&&[b.MULTILINE_TEXT,b.TEXT].includes(t))return R(g("question.requiredError")),void O();$(!0),R(null),f({...e,onCancel:()=>{$(!1)},onError:e=>{$(!1),R(e||"Sorry, something went wrong saving your answer. Please try again.")}})}},O=e.useCallback((()=>{!w&&v.current&&v.current.focus()}),[w]),[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:w?-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===b.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([b.SCALE,b.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===b.MULTIPLE_CHOICE&&(D=(l?l.length:0)+(a&&!P?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 b.MULTILINE_TEXT:G=e.createElement(e.Fragment,null,e.createElement("textarea",{ref:v,className:"userflowjs-textarea userflowjs-bubble-question__textarea",value:E,onChange:e=>x(e.target.value),onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&F({answer:{kind:"text",value:E}})},placeholder:g("question.placeholder"),readOnly:w||A,tabIndex:w?-1:void 0,rows:3,"aria-required":n?"true":void 0,"aria-invalid":null!=M?"true":void 0}),B);break;case b.MULTIPLE_CHOICE:{const t=()=>{E&&F({answer:{kind:"text",value:E},animationPromise:L()})},n=(l?.length||0)+(a?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));a&&P&&""!==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:o({"userflowjs-bubble-question__multiple-choice-hint":!0,"userflowjs-bubble-question__multiple-choice-hint--error":!!M})},g("question.multiple_selection_hint",{replace:{selected:j.size+(a&&P&&""!==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:o({"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":!!a&&P}),role:i?"group":"radiogroup",tabIndex:w||-1!==J?-1:0,onKeyDown:H},l?.map((({value:t,label:n},r)=>e.createElement("button",{key:r,className:o({"userflowjs-bubble-question__multiple-choice-option":!0,"userflowjs-bubble-question__multiple-choice-option--selected":i?j.has(r):A&&!P&&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 I(!1),x(t),F({answer:{kind:"text",value:t},animationPromise:L()})},disabled:A,tabIndex:w||r!==J?-1:0,role:i?"checkbox":"radio","aria-label":n||t,"aria-checked":!P&&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(y,{icon:k}))):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)))),a&&(P?e.createElement("div",{className:o({"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:()=>{x(""),I(!1)}},e.createElement("div",{className:"userflowjs-bubble-question__multiple-choice-checkbox-inner"},e.createElement(y,{icon:k}))):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=>x(e.target.value),onKeyDown:e=>{e.shiftKey||"Enter"!==e.key?"Escape"===e.key&&(e.stopPropagation(),x(""),I(!1)):i?c():t()},onBlur:()=>{""===E&&I(!1)},placeholder:g("question.placeholder"),readOnly:w||A,tabIndex:w?-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(p,null))):e.createElement("button",{className:"userflowjs-bubble-question__multiple-choice-option",onClick:A?void 0:()=>{R(null),I(!0),W(!0)},disabled:A,tabIndex:w||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(y,{icon:k}))):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:w?-1:void 0,disabled:A},e.createElement("div",{className:"userflowjs-bubble-button-text",role:"presentation"},r||g("question.submit")))));break}case b.NPS:case b.SCALE:G=e.createElement(e.Fragment,null,X,e.createElement("div",{className:"userflowjs-bubble-question__scale-options",role:"radiogroup",tabIndex:w||-1!==J?-1:0,onKeyDown:H},V?.map(((t,n)=>e.createElement("button",{className:o({"userflowjs-bubble-question__scale-option":!0,"userflowjs-bubble-question__scale-option--selected":A&&N==t}),key:t,tabIndex:w||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 b.STARS:G=e.createElement("div",{className:"userflowjs-bubble-question__stars-wrapper"},X,e.createElement("div",{className:"userflowjs-bubble-question__stars",role:"radiogroup",tabIndex:w||-1!==J?-1:0,onKeyDown:H},V?.map(((t,n)=>e.createElement("button",{className:o({"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:w||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 b.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=>x(e.target.value),onKeyDown:e=>{e.shiftKey||"Enter"!==e.key||F({answer:{kind:"text",value:E}})},placeholder:g("question.placeholder"),readOnly:w||A,tabIndex:w?-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:w?"none":void 0}},M&&!(t===b.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 A=({question:t})=>{const n=x(),r=function(){const e=q();if("flow"!==e.kind)throw new Error("useFlowSession: Wrong session kind");return e}();return e.createElement(I,{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]})}))}T(n,r,t.actions)}})},$=({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 M(e=""){return{type:"paragraph",children:[{text:e}]}}function R(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:[M(e)]}}()}function F(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(oe(e))e.text&&n.push(e.text);else switch(e.type){case"attribute":{const r=ne(e,t);r&&n.push(r);break}default:r(e.children)}}(e)))}return r(e.children),n.join("")}function O(e){let t=!0;if(!e)return!0;"string"==typeof e&&(e=R(e));const n=new Set(["attribute","button","image","question","video"]);return ae(e,(e=>{oe(e)?""!==e.text&&(t=!1):"type"in e&&n.has(e.type)&&(t=!1)})),t}const U=e.memo((({doc:t,...n})=>t?("string"==typeof t&&(t=R(t)),e.createElement(W,{parent:t,...n})):null)),W=({parent:t,...n})=>e.createElement(e.Fragment,null,t.children.map(((r,l)=>oe(r)?e.createElement(B,{key:l,node:r}):e.createElement(D,{key:l,node:r,parent:t,...n})))),B=({node:t})=>t.text?e.createElement(V,{node:t},e.createElement($,{text:t.text})):null,V=({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),D=({node:t,parent:n,...r})=>{const{lookupAttribute:l}=r,o=e.createElement(W,{parent:t,...r});switch(t.type){case"attribute":return e.createElement(z,{node:t,...r});case"button":return e.createElement(K,{node:t,...r});case"button-group":return e.createElement("div",{className:"userflowjs-bubble-buttons"},o);case"column":return e.createElement("div",{style:ee(t,n)},o);case"column-group":return e.createElement("div",{className:"p-like",style:Y(t)},o);case"container":return e.createElement("div",{className:"p-like"+(t.className?` ${t.className}`:""),style:te(t)},o);case"image":return e.createElement(H,{node:t,...r});case"link":return e.createElement("a",{href:F(t.href,{lookupAttribute:l}),target:"_blank",rel:"noopener noreferrer"},o);case"paragraph":return e.createElement("p",{className:Q(t)},o);case"heading1":return e.createElement("h1",{className:Q(t)},o);case"heading2":return e.createElement("h2",{className:Q(t)},o);case"question":return e.createElement(J,{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(G,{node:t,...r});default:return e.createElement("div",null,o)}},z=({node:t,lookupAttribute:n})=>{let r=ne(t,n);return e.createElement(V,{node:t},r)},K=({node:t,buttons:n})=>{const r=n?.find((e=>e.cvid===t.cvid));return r?e.createElement(P,{key:r.id,button:r}):null},J=({node:t,questions:n})=>{const r=n?.find((e=>e.cvid===t.cvid));return r?e.createElement(A,{key:r.id,question:r}):null},H=({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:f}=t;if("string"!=typeof r||!r)return null;const{wrapperStyle:h,blockStyle:p}=Z({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:{...p,objectFit:"contain"}});return b&&f&&(w=e.createElement("a",{href:F(f,{lookupAttribute:n}),target:"_blank",rel:"noopener noreferrer",style:p},w)),e.createElement("div",{className:"p-like"},e.createElement("div",{style:h},w))},G=({node:t})=>{const{url:n,widthMode:r,displayWidth:l,width:o,height:a,marginTop:i,marginRight:s,marginBottom:u,marginLeft:c,align:d}=t;if("string"!=typeof n||!n)return null;const{wrapperStyle:m,blockStyle:b}=Z({widthMode:r,displayWidth:l,width:o,height:a,marginTop:i,marginRight:s,marginBottom:u,marginLeft:c,align:d});return e.createElement("div",{className:"p-like"},e.createElement("div",{style:m},e.createElement("div",{style:b},e.createElement(X,{element:t,noFocus:!0}))))},X=({element:{embedType:t,url:n,src:r,autoPlay:l,controls:o,muted:a},noFocus:i,forceMuted:s})=>{if(!n)return null;const u={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:i?-1:void 0};if("video"===t)return e.createElement("video",{key:n+";"+String(l)+";"+String(o)+";"+String(a),src:n,style:{width:"100%",height:"100%",display:"block"},autoPlay:!!l,controls:!1!==o,muted:s||a});if(r){let t;try{t=new URL(r)}catch(f){return null}return s&&(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(),...u})}let c=function(e,{iframeFallback:t}={}){let n;try{n=new URL(e)}catch(f){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"===c.kind)return null;const{videoProvider:d,videoId:m,searchParams:b}=c;switch(l=l||b.has("autoplay")||b.has("autoPlay"),d){case"iframe":return e.createElement("iframe",{src:m,scrolling:b.get("scrolling")||void 0,...u});case"loom":return e.createElement("iframe",{src:`https://www.loom.com/embed/${m}?${b.toString()}`,...u});case"raw":return e.createElement("video",{src:m,controls:!0,style:{width:"100%",height:"100%",display:"block"},autoPlay:b.has("autoplay"),muted:s||b.has("muted")});case"youtube":return s&&l&&b.set("mute","1"),e.createElement("iframe",{src:`https://www.youtube.com/embed/${m}?${b.toString()}`,...u});case"vimeo":return s&&l&&b.set("muted","1"),e.createElement("iframe",{src:`https://player.vimeo.com/video/${m}?${b.toString()}`,...u});case"wistia":return b.set("videoFoam","true"),s&&l&&b.set("volume","0"),e.createElement(e.Fragment,null,e.createElement("iframe",{src:`https://fast.wistia.net/embed/iframe/${m}?${b.toString()}`,...u}))}};function Q(e){return"right"===e.align?"userflowjs-text-align-end":"center"===e.align?"userflowjs-text-align-center":""}function Z({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 Y(e){return{display:"flex",alignItems:"stretch",marginRight:`-${null==e.spacing?16:e.spacing}px`}}function ee(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 te(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 ne(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 re(e){return Array.isArray(e.children)&&void 0===e.addMark}function le(e,t,n="type"){return re(e)&&e[n]===t}function oe(e){return"string"==typeof e.text}function ae(e,t){function n(e){e&&e.forEach(((e,r)=>e&&function(e,r){t(e,r),re(e)&&n(e.children)}(e,r)))}n(Array.isArray(e)?e:e.children)}const ie=e.memo((({doc:t,lookupAttribute:n})=>t?e.createElement(e.Fragment,null,F(t,{lookupAttribute:n})):null));function se(e,{buttons:t,questions:n}){const r=new Set,l=new Set;if(ae(e,(e=>{le(e,"button")&&r.add(e.cvid),le(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 ue(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 ce=new URL("flow-host.css",import.meta.url).href,de=new URL("bubble-frame.css",import.meta.url).href;const me=({draftMode:t,muted:n,toggleMuted:r,close:l,minimize:o})=>{const{t:a}=_();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(w,null):e.createElement(g,null)),o&&e.createElement("button",{"data-testid":"minimize-button",className:"userflowjs-bubble-toolbar-button",onClick:o,"aria-label":"Minimize checklist"},e.createElement(v,null)),l&&e.createElement("button",{"data-testid":"close-button",className:"userflowjs-bubble-toolbar-button",onClick:l,"aria-label":a("menu.close")},e.createElement(E,null)))};export{me as B,U as R,j as S,ie as a,de as b,S as c,R as d,q as e,ce as f,ne as g,T as h,oe as i,se as m,O as r,F as s,N 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,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,muted:i},noFocus:s,forceMuted:u,lookupAttribute:c})=>{if(!n)return null;const d={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:s?-1:void 0};if("video"===t)return e.createElement("video",{key:n+";"+String(o)+";"+String(a)+";"+String(i),src:n,style:{width:"100%",height:"100%",display:"block"},autoPlay:!!o,controls:!1!==a,muted:u||i});if(r){let t;try{t=new URL(r)}catch(h){return null}return u&&(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(),...d})}let m=function(e,{iframeFallback:t}={}){let n;try{n=new URL(e)}catch(h){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"===m.kind)return null;const{videoProvider:b,videoId:p,searchParams:f}=m;switch(o=o||f.has("autoplay")||f.has("autoPlay"),b){case"iframe":return e.createElement("iframe",{src:l(p,(e=>encodeURIComponent(c(e)||""))),scrolling:f.get("scrolling")||void 0,...d});case"loom":return e.createElement("iframe",{src:`https://www.loom.com/embed/${p}?${f.toString()}`,...d});case"raw":return e.createElement("video",{src:p,controls:!0,style:{width:"100%",height:"100%",display:"block"},autoPlay:f.has("autoplay"),muted:u||f.has("muted")});case"youtube":return u&&o&&f.set("mute","1"),e.createElement("iframe",{src:`https://www.youtube.com/embed/${p}?${f.toString()}`,...d});case"vimeo":return u&&o&&f.set("muted","1"),e.createElement("iframe",{src:`https://player.vimeo.com/video/${p}?${f.toString()}`,...d});case"wistia":return f.set("videoFoam","true"),u&&o&&f.set("volume","0"),e.createElement(e.Fragment,null,e.createElement("iframe",{src:`https://fast.wistia.net/embed/iframe/${p}?${f.toString()}`,...d}))}};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 +1 @@
1
- import{r as e}from"./vendor.react.js";import{i as t}from"./vendor.is-hotkey.js";import{o as n}from"./vendor.obj-str.js";import{r as o,b as s,g as a,d as r,o as l,e as i,f as m,h as c,j as d,k as u,l as p}from"./flow-condition-types.js";import{a as v}from"./userflow.js";import{u as f}from"./client-context.js";import{u as g}from"./logomark.js";import{B as h}from"./BuilderBar.js";import"./vendor.object-assign.js";import"./vendor.date-fns.js";import"./vendor.phoenix.js";import"./vendor.uuid.js";import"./vendor.i18next.js";import"./vendor.react-i18next.js";import"./vendor.babel.runtime.js";import"./vendor.react-dom.js";import"./vendor.scheduler.js";import"./stylesheets.js";import"./vendor.fortawesome.pro-light-svg-icons.js";import"./DynamicIcon.js";import"./vendor.fortawesome.pro-regular-svg-icons.js";import"./vendor.fortawesome.pro-solid-svg-icons.js";const w=t("alt+s"),b=t("escape"),y=t("u"),E=({state:t})=>{const{mode:c,elementType:d}=t,E=f(),L=e.useRef(null),[S,N]=e.useState(!1),M=e.useRef(null),[k,R]=e.useState(null),[D,F]=e.useState((()=>x())),T=e.useCallback((async(e,t)=>{if(e&&t){const n=L.current?.getFrame();n&&M.current&&(M.current.classList.add("userflowjs-element-selection-box--no-transition"),n.style.display="none",n.offsetWidth),m(),E.setSessionStorageState((e=>({...e,elementSelection:{...e.elementSelection,mode:"done"}})));const l=o(e),i=0,c=0,d=Math.round(s()),u=Math.round(a()),p=await E.getTargetEnv().captureScreenshot(i,c,d,u),v=e=>Math.round(e/r(1));t={...t,screenshotDataUrl:p,targetX1:v(l.left),targetY1:v(l.top-c),targetX2:v(l.right),targetY2:v(l.bottom-c),screenshotWidth:d,screenshotHeight:u}}E.setSessionStorageState((e=>({...e,activeApp:null,elementSelection:null}))),E.getTargetEnv().postBuilderMessage({kind:"userflow:selectElementResult",selectorData:t})}),[E]),A=e.useCallback((e=>E.setSessionStorageState((t=>({...t,elementSelection:{...t.elementSelection,mode:e}})))),[E]);return e.useEffect((()=>{if(!S||!L.current)return;const e=L.current.getFrame(),t=L.current.getRootEl();let n=t&&t.ownerDocument&&t.ownerDocument.defaultView;n===window&&(n=null);let f=null,g=null,h=null,E=null;const x=document.getElementById("userflow-ui"),N={capture:!0},k=()=>{window.cancelAnimationFrame(F);let e=null,t=null,n=null;if(g&&!x.contains(g)){let o=null,s=g;for(;s;){{const e=s.getBoundingClientRect();if(0===e.width&&0===e.height){s=j(s);continue}}if(o=u(s,{elementType:d}),o)break;s=j(s)}o?(t=o.el,e=o.selector):n=d===v.INPUT?"No text input found here":"Sorry, we can't select that element (yet!)"}h=t,f=e,R(n),C()};let F;const B=()=>{window.cancelAnimationFrame(F),F=window.requestAnimationFrame(k)},C=()=>{window.cancelAnimationFrame($);const e=M.current;if(!e)return;m();const t=r(s()),n=r(a());let l=n/2,i=t/2,c=n/2,d=t/2;let u=2,v=2,f=2,g=2;if(h){const e=o(h),s=window.getComputedStyle(h);l=Math.max(0,e.top),i=Math.max(0,t-e.right),c=Math.max(0,n-e.bottom),d=Math.max(0,e.left),u=Math.max(2,p(s.borderTopLeftRadius)),v=Math.max(2,p(s.borderTopRightRadius)),f=Math.max(2,p(s.borderBottomLeftRadius)),g=Math.max(2,p(s.borderBottomRightRadius)),E=h}else if(E){const e=o(E);l=Math.max(0,e.top+e.height/2),i=Math.max(0,t-e.right+e.width/2),c=Math.max(0,n-e.bottom+e.height/2),d=Math.max(0,e.left+e.width/2)}e.style.top=`${l}px`,e.style.right=`${i}px`,e.style.bottom=`${c}px`,e.style.left=`${d}px`,e.style.borderTopLeftRadius=`${u}px`,e.style.borderTopRightRadius=`${v}px`,e.style.borderBottomLeftRadius=`${f}px`,e.style.borderBottomRightRadius=`${g}px`,h?document.body.classList.remove("userflowjs-body-with-element-selection--none"):document.body.classList.add("userflowjs-body-with-element-selection--none")};let $;const P=()=>{window.cancelAnimationFrame($),$=window.requestAnimationFrame(C)},I=e=>{if(w(e))return e.preventDefault(),void("select"===c?A("navigate"):"navigate"===c&&A("select"));if(b(e)&&"select"===c)return e.preventDefault(),void T(null,null);if(y(e)&&h){const t=j(h);if(t)return e.preventDefault(),g=t,void k()}},U=e=>{const t=e.composedPath()[0];t&&t!==h&&"BODY"!==t.tagName&&"HTML"!==t.tagName&&(g=t,B())},Y=()=>{g=null,B()};e&&e.addEventListener("mouseenter",Y);const V=e=>{e.preventDefault(),e.stopPropagation()},q=e=>{V(e)},H=e=>{V(e)},O=e=>{if(V(e),D){const t=e.target;if(!h||!h.contains(t))return void U(e)}f&&(T(h,f),X())};n&&n.addEventListener("keydown",I),"select"===c&&(document.body.addEventListener("mouseleave",Y),document.body.classList.add("userflowjs-body-with-element-selection"));const W=l((e=>{const t=e.ownerDocument.defaultView;t&&(t.addEventListener("keydown",I,N),"select"===c&&(t.addEventListener("scroll",P,N),e.addEventListener("mousemove",U,N),e.addEventListener("mousedown",q,N),e.addEventListener("focus",H,N),e.addEventListener("click",O,N)))}),(e=>{const t=e.ownerDocument.defaultView;t&&(t.removeEventListener("keydown",I,N),"select"===c&&(t.removeEventListener("scroll",P,N),i(e)||e.removeEventListener("mousemove",U,N),e.removeEventListener("mousedown",q,N),e.removeEventListener("focus",H,N),e.removeEventListener("click",O,N)))})),X=()=>{window.cancelAnimationFrame(F),window.cancelAnimationFrame($),document.body.removeEventListener("mouseleave",Y),n&&n.removeEventListener("keydown",I),e&&e.removeEventListener("mouseenter",Y),document.body.classList.remove("userflowjs-body-with-element-selection"),document.body.classList.remove("userflowjs-body-with-element-selection--none"),W()};return X}),[D,E,c,S,d,T,A]),g((()=>F(x()))),e.createElement(e.Fragment,null,e.createElement(h,{ref:L,onReadyChange:N,buttons:e.createElement(e.Fragment,null,"navigate"===c?e.createElement("button",{key:"select",className:"btn btn--default",onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),A("select")}},e.createElement("span",{className:"hidden-lg-up"},"Select here"),e.createElement("span",{className:"hidden-md-down"},"Select element here (Alt + S)")):"select"===c?e.createElement("button",{key:"navigate",className:"btn btn--default",onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),A("navigate")}},e.createElement("span",{className:"hidden-lg-up"},"Navigate"),e.createElement("span",{className:"hidden-md-down"},"Navigate to another page (Alt + S)")):null,("select"===c||"navigate"===c)&&e.createElement("button",{className:"btn btn--secondary-on-dark",onClick:()=>T(null,null)},"Cancel"))},"navigate"===c?e.createElement("div",{className:"status"},"Navigate to the page the element appears on"):k?e.createElement("div",{className:"error"},k):e.createElement("div",{className:"status"},D?e.createElement(e.Fragment,null,"Tap"," ",d===v.INPUT?"a text input":"an element"," ","to focus. Tap again to select."):e.createElement(e.Fragment,null,"Click"," ",d===v.INPUT?"a text input":"an element"," ","to select it"))),S&&("select"===c||"done"===c)&&e.createElement("div",{className:n({"userflowjs-element-selection-box":!0}),ref:M}))};function j(e){const t=e.parentNode;if(!t)return null;if(i(t))return t.host;if(!c(t))return null;if("BODY"===t.tagName){const e=d(t);return e||null}return t}function x(){return window.navigator.userAgent.includes("Mobile")}export default E;export{E as ElementSelectionApp};
1
+ import{r as e}from"./vendor.react.js";import{i as t}from"./vendor.is-hotkey.js";import{o as n}from"./vendor.obj-str.js";import{r as o,d as s,g as a,e as r,o as l,f as i,h as m,j as c,k as d,l as u,m as p}from"./flow-condition-types.js";import{a as v}from"./userflow.js";import{u as f}from"./client-context.js";import{u as g}from"./logomark.js";import{B as h}from"./BuilderBar.js";import"./vendor.object-assign.js";import"./vendor.date-fns.js";import"./vendor.phoenix.js";import"./vendor.uuid.js";import"./vendor.i18next.js";import"./vendor.react-i18next.js";import"./vendor.babel.runtime.js";import"./vendor.react-dom.js";import"./vendor.scheduler.js";import"./stylesheets.js";import"./vendor.fortawesome.pro-light-svg-icons.js";import"./DynamicIcon.js";import"./vendor.fortawesome.pro-regular-svg-icons.js";import"./vendor.fortawesome.pro-solid-svg-icons.js";const w=t("alt+s"),b=t("escape"),y=t("u"),E=({state:t})=>{const{mode:c,elementType:d}=t,E=f(),L=e.useRef(null),[S,N]=e.useState(!1),M=e.useRef(null),[k,R]=e.useState(null),[D,F]=e.useState((()=>x())),T=e.useCallback((async(e,t)=>{if(e&&t){const n=L.current?.getFrame();n&&M.current&&(M.current.classList.add("userflowjs-element-selection-box--no-transition"),n.style.display="none",n.offsetWidth),m(),E.setSessionStorageState((e=>({...e,elementSelection:{...e.elementSelection,mode:"done"}})));const l=o(e),i=0,c=0,d=Math.round(s()),u=Math.round(a()),p=await E.getTargetEnv().captureScreenshot(i,c,d,u),v=e=>Math.round(e/r(1));t={...t,screenshotDataUrl:p,targetX1:v(l.left),targetY1:v(l.top-c),targetX2:v(l.right),targetY2:v(l.bottom-c),screenshotWidth:d,screenshotHeight:u}}E.setSessionStorageState((e=>({...e,activeApp:null,elementSelection:null}))),E.getTargetEnv().postBuilderMessage({kind:"userflow:selectElementResult",selectorData:t})}),[E]),A=e.useCallback((e=>E.setSessionStorageState((t=>({...t,elementSelection:{...t.elementSelection,mode:e}})))),[E]);return e.useEffect((()=>{if(!S||!L.current)return;const e=L.current.getFrame(),t=L.current.getRootEl();let n=t&&t.ownerDocument&&t.ownerDocument.defaultView;n===window&&(n=null);let f=null,g=null,h=null,E=null;const x=document.getElementById("userflow-ui"),N={capture:!0},k=()=>{window.cancelAnimationFrame(F);let e=null,t=null,n=null;if(g&&!x.contains(g)){let o=null,s=g;for(;s;){{const e=s.getBoundingClientRect();if(0===e.width&&0===e.height){s=j(s);continue}}if(o=u(s,{elementType:d}),o)break;s=j(s)}o?(t=o.el,e=o.selector):n=d===v.INPUT?"No text input found here":"Sorry, we can't select that element (yet!)"}h=t,f=e,R(n),C()};let F;const B=()=>{window.cancelAnimationFrame(F),F=window.requestAnimationFrame(k)},C=()=>{window.cancelAnimationFrame($);const e=M.current;if(!e)return;m();const t=r(s()),n=r(a());let l=n/2,i=t/2,c=n/2,d=t/2;let u=2,v=2,f=2,g=2;if(h){const e=o(h),s=window.getComputedStyle(h);l=Math.max(0,e.top),i=Math.max(0,t-e.right),c=Math.max(0,n-e.bottom),d=Math.max(0,e.left),u=Math.max(2,p(s.borderTopLeftRadius)),v=Math.max(2,p(s.borderTopRightRadius)),f=Math.max(2,p(s.borderBottomLeftRadius)),g=Math.max(2,p(s.borderBottomRightRadius)),E=h}else if(E){const e=o(E);l=Math.max(0,e.top+e.height/2),i=Math.max(0,t-e.right+e.width/2),c=Math.max(0,n-e.bottom+e.height/2),d=Math.max(0,e.left+e.width/2)}e.style.top=`${l}px`,e.style.right=`${i}px`,e.style.bottom=`${c}px`,e.style.left=`${d}px`,e.style.borderTopLeftRadius=`${u}px`,e.style.borderTopRightRadius=`${v}px`,e.style.borderBottomLeftRadius=`${f}px`,e.style.borderBottomRightRadius=`${g}px`,h?document.body.classList.remove("userflowjs-body-with-element-selection--none"):document.body.classList.add("userflowjs-body-with-element-selection--none")};let $;const P=()=>{window.cancelAnimationFrame($),$=window.requestAnimationFrame(C)},I=e=>{if(w(e))return e.preventDefault(),void("select"===c?A("navigate"):"navigate"===c&&A("select"));if(b(e)&&"select"===c)return e.preventDefault(),void T(null,null);if(y(e)&&h){const t=j(h);if(t)return e.preventDefault(),g=t,void k()}},U=e=>{const t=e.composedPath()[0];t&&t!==h&&"BODY"!==t.tagName&&"HTML"!==t.tagName&&(g=t,B())},Y=()=>{g=null,B()};e&&e.addEventListener("mouseenter",Y);const V=e=>{e.preventDefault(),e.stopPropagation()},q=e=>{V(e)},H=e=>{V(e)},O=e=>{if(V(e),D){const t=e.target;if(!h||!h.contains(t))return void U(e)}f&&(T(h,f),X())};n&&n.addEventListener("keydown",I),"select"===c&&(document.body.addEventListener("mouseleave",Y),document.body.classList.add("userflowjs-body-with-element-selection"));const W=l((e=>{const t=e.ownerDocument.defaultView;t&&(t.addEventListener("keydown",I,N),"select"===c&&(t.addEventListener("scroll",P,N),e.addEventListener("mousemove",U,N),e.addEventListener("mousedown",q,N),e.addEventListener("focus",H,N),e.addEventListener("click",O,N)))}),(e=>{const t=e.ownerDocument.defaultView;t&&(t.removeEventListener("keydown",I,N),"select"===c&&(t.removeEventListener("scroll",P,N),i(e)||e.removeEventListener("mousemove",U,N),e.removeEventListener("mousedown",q,N),e.removeEventListener("focus",H,N),e.removeEventListener("click",O,N)))})),X=()=>{window.cancelAnimationFrame(F),window.cancelAnimationFrame($),document.body.removeEventListener("mouseleave",Y),n&&n.removeEventListener("keydown",I),e&&e.removeEventListener("mouseenter",Y),document.body.classList.remove("userflowjs-body-with-element-selection"),document.body.classList.remove("userflowjs-body-with-element-selection--none"),W()};return X}),[D,E,c,S,d,T,A]),g((()=>F(x()))),e.createElement(e.Fragment,null,e.createElement(h,{ref:L,onReadyChange:N,buttons:e.createElement(e.Fragment,null,"navigate"===c?e.createElement("button",{key:"select",className:"btn btn--default",onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),A("select")}},e.createElement("span",{className:"hidden-lg-up"},"Select here"),e.createElement("span",{className:"hidden-md-down"},"Select element here (Alt + S)")):"select"===c?e.createElement("button",{key:"navigate",className:"btn btn--default",onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),A("navigate")}},e.createElement("span",{className:"hidden-lg-up"},"Navigate"),e.createElement("span",{className:"hidden-md-down"},"Navigate to another page (Alt + S)")):null,("select"===c||"navigate"===c)&&e.createElement("button",{className:"btn btn--secondary-on-dark",onClick:()=>T(null,null)},"Cancel"))},"navigate"===c?e.createElement("div",{className:"status"},"Navigate to the page the element appears on"):k?e.createElement("div",{className:"error"},k):e.createElement("div",{className:"status"},D?e.createElement(e.Fragment,null,"Tap"," ",d===v.INPUT?"a text input":"an element"," ","to focus. Tap again to select."):e.createElement(e.Fragment,null,"Click"," ",d===v.INPUT?"a text input":"an element"," ","to select it"))),S&&("select"===c||"done"===c)&&e.createElement("div",{className:n({"userflowjs-element-selection-box":!0}),ref:M}))};function j(e){const t=e.parentNode;if(!t)return null;if(i(t))return t.host;if(!c(t))return null;if("BODY"===t.tagName){const e=d(t);return e||null}return t}function x(){return window.navigator.userAgent.includes("Mobile")}export default E;export{E as ElementSelectionApp};
package/FlowApp.js CHANGED
@@ -1 +1 @@
1
- import{r as e}from"./vendor.react.js";import{E as t,V as o,w as n,b as s,T as r,v as l,x as a,p as i,A as c,M as u,U as d}from"./userflow.js";import{m as p,d as m,R as f,B as b,i as h,g as w,u as g,c as E,h as v,S as k}from"./BubbleToolbar.js";import{a as y,z as j,g as T,m as R,r as S}from"./flow-condition-types.js";import{u as L,i as M}from"./client-context.js";import{u as x,r as F,F as C}from"./FlowChrome.js";import{e as N,f as I,g as B}from"./Icons.js";import{T as D}from"./Trigger.js";import{u as P}from"./vendor.react-i18next.js";import{u as q}from"./stylesheets.js";import"./vendor.object-assign.js";import"./vendor.phoenix.js";import"./vendor.uuid.js";import"./vendor.obj-str.js";import"./vendor.fortawesome.react-fontawesome.js";import"./vendor.fortawesome.fontawesome-svg-core.js";import"./vendor.prop-types.js";import"./vendor.fortawesome.pro-solid-svg-icons.js";import"./vendor.date-fns.js";import"./vendor.i18next.js";import"./logomark.js";import"./vendor.react-dom.js";import"./vendor.scheduler.js";import"./vendor.babel.runtime.js";const A=()=>{const{t:o}=P(),n=L(),{dispatch:s,restart:r}=re(),{session:l,step:a}=le(),i="userflowjs-bubble-button userflowjs-bubble-button--default userflowjs-bubble-menu__item";return e.createElement("div",{role:"dialog","aria-modal":oe(a)?"true":void 0,"aria-label":"Guide menu"},e.createElement("div",{className:"userflowjs-bubble-menu__title"},o("menu.title")),e.createElement("button",{className:i,onClick:()=>n.endFlow(l,{endReason:t.USER_CLOSED})},o("menu.close")),l.version.restartEnabled&&e.createElement("button",{className:i,onClick:r},o("menu.restart")),e.createElement("button",{className:i,onClick:()=>s({kind:"showFlow"})},o("menu.back")))},_=({progress:t})=>{const o={width:100*parseFloat(t||"0")+"%"};return e.createElement("div",{className:"userflowjs-bubble-progress"},e.createElement("div",{className:"userflowjs-bubble-progress__fill",style:o}))},O=()=>{const s=L(),{session:r,step:l,muted:a,shouldLabelDialog:i}=le(),{version:c}=r,u=l.theme||r.version.theme,{dispatch:d}=re(),h=c.steps[0],w=h&&h.id===l.id,g=w&&"1"===l.progress,E=e.useMemo((()=>l.content&&p(m(l.content),{buttons:l.buttons,questions:l.questions})),[l.content,l.buttons,l.questions]);return e.createElement("div",{key:l.id,role:"alertdialog","aria-modal":oe(l)?"true":void 0,"aria-label":i?"Guide":void 0},!g&&e.createElement(_,{progress:l.progress}),e.createElement("div",{id:"userflowjs-bubble-content",className:"userflowjs-bubble-content"},e.createElement(f,{doc:E,lookupAttribute:y(r.data),buttons:l.buttons,questions:l.questions})),e.createElement(b,{draftMode:r.draftMode,muted:a,toggleMuted:u.voiceType!==o.NONE?()=>d({kind:"toggleMuted"}):void 0,close:c.closeDisabled?void 0:()=>u.flowXButtonBehavior===n.DISMISS||w?s.endFlow(r,{endReason:t.USER_CLOSED}):d({kind:"showMenu"})}))};function U(e,t){if(!e)return"";"string"==typeof e&&(e=m(e));const o=[],n=/[.!?;,]$/;function s(){const e=(o[o.length-1]||"").trim();e&&!e.match(n)&&o.push(".")}function r(e){e.forEach((e=>function(e){if(h(e)){if(e.text&&!e.silent){const t=e.text.split("\n");t.forEach(((e,n)=>{o.push(e),n<t.length-1&&(s(),o.push("\n"))}))}}else switch(e.type){case"attribute":{const n=w(e,t);n&&o.push(n);break}default:r(e.children),["link"].includes(e.type)||(s(),o.push("\n\n"))}}(e)))}return r(e.children),o.join("").trim().replace(new RegExp(String.fromCharCode(160),"g")," ").replace(new RegExp(String.fromCharCode(8),"g"),"")}const V=({bubbleFrame:t,theme:n})=>{const s=L(),{dispatch:r}=re(),{muted:l,session:a,step:i}=le(),c=s.getAudio();e.useEffect((()=>{const e=()=>{r({kind:"speechPlaying"})},t=()=>{r({kind:"speechStopped"})};return c.addEventListener("playing",e),c.addEventListener("ended",t),c.addEventListener("pause",t),()=>{c.removeEventListener("playing",e),c.removeEventListener("ended",t),c.removeEventListener("pause",t),c.pause(),c.src="",r({kind:"speechStopped"})}}),[r,c]),e.useEffect((()=>{if(s.audioReady)return;const e=t&&"IFRAME"===t.tagName?t.contentWindow:null;const o=()=>{window.removeEventListener("mousedown",n),e&&e.removeEventListener("mousedown",n)},n=()=>{o(),s.playAudio(null)};return window.addEventListener("mousedown",n),e&&e.addEventListener("mousedown",n),o}),[t,s]);const u=e.useRef(a),d=e.useRef(n),p=e.useRef(i);return e.useEffect((()=>{u.current=a,d.current=n,p.current=i}),[a,n,i]),e.useEffect((()=>{if(!s.audioReady||l)return void s.pauseAudio();let e=!1;return async function(e,t,n,s){if(n.voiceType===o.SYNTHETIC&&"string"==typeof n.syntheticVoice&&s.content){e.ensureIdentified();const o=y(t.data),r=U(s.content,o);return e.getStepSpeech(n.syntheticVoice,r)}if(n.voiceType===o.MANUAL&&s.speechAsset)return s.speechAsset.assetUrl;return null}(s,u.current,d.current,p.current).then((t=>{t&&!e&&s.playAudio(t)})),()=>{e=!0}}),[l,s,i.id]),null};const Y=e.forwardRef(((t,o)=>{const n=N();return e.createElement("div",{ref:o,className:"userflowjs-out-of-viewport-pointer",style:{zIndex:n+2}},e.createElement(I,null))}));function z(e,t){const o=e.current;o&&(o.classList.toggle("userflowjs-out-of-viewport-pointer--visible",null!=t),t&&(o.style.left=t.left+"px",o.style.top=t.top+"px",o.classList.toggle("userflowjs-out-of-viewport-pointer--visible-up","up"===t.direction),o.classList.toggle("userflowjs-out-of-viewport-pointer--visible-down","down"===t.direction)))}const G=()=>{const{step:t}=le();return e.createElement(e.Fragment,null,t.beacons.map((t=>e.createElement(X,{key:t.id,beacon:t}))))},X=({beacon:t})=>{const{session:o}=le(),n=N(),s=e.useRef(null),r=e.useRef(null),l=g(t.hiddenCondition),a=e.useMemo((()=>R(t.selector,o.data)),[t.selector,o.data]),i=e.useCallback((({targetRect:e,clipEl:o,viewportClipRect:n})=>{const l=function({beacon:e,beaconRef:t,clipEl:o,viewportClipRect:n,targetRect:s}){if(!t.current)return null;if(0===s.width||0===s.height)return null;const r=16,l=16,a=S(o);let i=0,c=0;switch(e.placement){case"top-left":case"left":case"bottom-left":i=s.left;break;case"top":case"center":case"bottom":i=s.left+s.width/2;break;default:i=s.left+s.width}switch(e.placement){case"left":case"center":case"right":c=s.top+s.height/2;break;case"bottom-left":case"bottom":case"bottom-right":c=s.top+s.height;break;default:c=s.top}i-=r/2,c-=l/2,i+=e.offsetX,c+=e.offsetY,i=Math.max(i,a.left-(o===document.documentElement?0:o.scrollLeft)),c=Math.max(c,a.top-(o===document.documentElement?0:o.scrollTop));const u=i+r,d=c+l,p=Math.min(32,.5*l);let m;m=d<n.top+p?"up":c>n.bottom-p?"down":null;return{top:c,right:u,bottom:d,left:i,width:r,height:l,pointerSubjectPosition:{direction:m,left:i,width:r},visible:null==m}}({beacon:t,beaconRef:s,clipEl:o,viewportClipRect:n,targetRect:e}),a=l&&function({subjectPosition:e,pointerRef:t,viewportClipRect:o}){const n=t.current;if(!n)return null;const s=n.getBoundingClientRect(),r=j(T());let l,a,i=e.direction;return null==i?null:("down"===i&&o.bottom<s.height/2?i="up":"up"===i&&o.top>r&&(i="down"),l=e.left+e.width/2-s.width/2,a="down"===i?o.bottom-s.height:o.top,{direction:i,left:l,top:a})}({subjectPosition:l.pointerSubjectPosition,pointerRef:r,viewportClipRect:n});F((()=>{H(s,l),z(r,a)}))}),[t]),c=e.useCallback((()=>{H(s,null),z(r,null)}),[]);return x({selector:l?null:a,targetMoved:i,targetLost:c}),e.createElement(e.Fragment,null,e.createElement("div",{ref:s,className:"userflowjs-beacon userflowjs-beacon--pulse userflowjs-beacon--for-flow userflowjs-fixed-widget",style:{zIndex:n+2}},e.createElement("div",{className:"userflowjs-beacon__ring"}),e.createElement("div",{className:"userflowjs-beacon__ring"})),e.createElement(Y,{ref:r}))};function H(e,t){const o=e.current;o&&(o.classList.toggle("userflowjs-fixed-widget--visible",null!=t),t&&(o.style.transform=`translate3d(${t.left}px, ${t.top}px, 0)`,o.style.visibility=t.visible?"visible":"hidden"))}const W=()=>{const{t:o}=P(),n=L(),{restart:l}=re(),{session:a,step:i}=le(),c=i.theme||a.version.theme,u=i.selector,d=!u||u.type===s.AUTO&&!u.autoData,p=()=>n.endFlow(a,{endReason:t.USER_CLOSED});return e.createElement(e.Fragment,null,e.createElement(b,{draftMode:a.draftMode,close:p}),a.draftMode&&d?e.createElement("div",{className:"userflowjs-bubble-content"},e.createElement("div",{className:"userflowjs-bubble-alert p-like"},e.createElement("span",{className:"userflowjs-bubble-alert__label"},"Preview-only tip"),"No tooltip target selected yet. Please go back to the Builder and select a tooltip target in ",e.createElement("b",null,"Step ",i.idx+1)," of"," ",e.createElement("b",null,a.flow.name),".")):a.draftMode&&c.tooltipMissingBehavior===r.END?e.createElement("div",{className:"userflowjs-bubble-content"},e.createElement("div",{className:"userflowjs-bubble-alert p-like"},e.createElement("p",null,e.createElement("span",{className:"userflowjs-bubble-alert__label"},"Preview-only tip"),"The tooltip target element in ",e.createElement("b",null,"Step ",i.idx+1)," of"," ",e.createElement("b",null,a.flow.name)," was not found within"," ",c.tooltipMissingToleranceSeconds," ",1===parseFloat(c.tooltipMissingToleranceSeconds)?"second":"seconds","."),e.createElement("p",null,"For regular users, the flow will auto-dismiss when this happens."),e.createElement("p",null,"If you are on the right page, then try reselecting the element in the Builder."),e.createElement("p",null,"Read more in our"," ",e.createElement("a",{href:"https://userflow.com/docs/trouble/element-not-found",target:"_blank",rel:"noopener noreferrer"},"Element not found guide"),"."))):e.createElement(e.Fragment,null,e.createElement("div",{className:"userflowjs-bubble-content"},a.draftMode&&e.createElement("div",{className:"userflowjs-bubble-alert p-like"},e.createElement("span",{className:"userflowjs-bubble-alert__label"},"Preview-only tip"),"The tooltip target element in ",e.createElement("b",null,"Step ",i.idx+1)," of"," ",e.createElement("b",null,a.flow.name)," was not found on the page. If you are on the right page, then try reselecting the element in the Builder."),e.createElement("p",null,e.createElement("b",null,o("tooltipTargetMissing.line1"))),e.createElement("p",null,o("tooltipTargetMissing.line2"))),e.createElement("div",{className:"userflowjs-bubble-buttons"},e.createElement(E,{appearance:"primary",onClick:l,text:o("menu.restart")}),e.createElement(E,{appearance:"default",onClick:p,text:o("menu.close")}))))},$=({session:o,checklistSession:n,resourceCenterEmbedsChecklist:s})=>{const d=L(),[p,m]=e.useState(!1),[f,b]=e.useState(null),[h,w]=e.useReducer(Q,void 0,(()=>{const e=o,t=Z(e);return{...J,session:e,step:t,muted:!!l.getItem("flowsMuted"),autoFocusRequested:te(t)}})),{session:g,step:E,speechPlaying:y,contentType:j}=h,{version:T}=g,S=oe(E);let x=0;E.questions.some((e=>e.type===i.NPS))&&(x=420);const F=q(E.theme||T.theme),N=e.useMemo((()=>{let e=F.bubbleY;const t=n?.version.theme;return!s&&n&&t&&n.version.checklist?.launcherEnabled&&E.appearance===a.BUBBLE&&t.checklistLauncherPlacement===F.bubblePlacement&&(F.avatarType===c.NONE||t.checklistLauncherX<F.bubbleX+F.avatarSize)&&(e=Math.max(F.bubbleY,t.checklistLauncherY+t.checklistLauncherHeight+F.bubbleY)),{...F,bubbleWidth:Math.max(F.bubbleWidth,x),bubbleY:e}}),[s,n,E.appearance,F,x]);e.useEffect((()=>{g!==o&&w({kind:"updateSession",session:o});const e=e=>{e.session.id===g.id&&w({kind:"goToStep",stepId:e.step.id})};return d.on("gotostep",e),()=>{d.off("gotostep",e)}}),[d,g,o]);const I=e.useMemo((()=>({dispatch:w,restart:()=>{d.goToStep(g,ee(g)),w({kind:"showFlow"})}})),[d,w,g]),D=e.useMemo((()=>E.selector&&R(E.selector,g.data)),[E.selector,g.data]),P=e.useCallback((()=>{v(d,g,E.actions)}),[d,g,E.actions]);e.useEffect((()=>{h.muted?l.setItem("flowsMuted","true"):l.removeItem("flowsMuted")}),[h.muted]);const _=g.locale?g.locale.standardLocaleId:N.languageId;e.useEffect((()=>{M.changeLanguage(_)}),[_]);const[U,V]=e.useState(!1),Y=e.useCallback((e=>{V(e),e&&N.tooltipMissingBehavior===r.END&&!g.draftMode&&d.endFlow(g,{endReason:t.TOOLTIP_TARGET_MISSING})}),[d,g,N.tooltipMissingBehavior]);return e.useEffect((()=>{if(!p||!h.autoFocusRequested)return;d.originalActiveElement||d.originalActiveElement===f?.ownerDocument.defaultView?.frameElement||(d.originalActiveElement=document.activeElement);let e=f?.querySelector('button:not([tabindex="-1"]):not(.userflowjs-bubble-toolbar-button), [tabindex]:not([tabindex="-1"]):not(.userflowjs-bubble-toolbar-button), input, textarea');if(e&&e.matches(".userflowjs-bubble-buttons button:not(.userflowjs-bubble-button--primary)")){const t=f?.querySelector(".userflowjs-bubble-buttons .userflowjs-bubble-button--primary");t&&(e=t)}e&&"function"==typeof e.focus&&e.focus({preventScroll:!0}),w({kind:"autoFocused"})}),[d,f,p,h.autoFocusRequested]),e.useEffect((()=>{const e=f?.ownerDocument.defaultView;if(!e)return;const t=()=>{w({kind:"focusOut"}),delete d.originalActiveElement},o=()=>{w({kind:"focusIn"})};return window.addEventListener("focusin",t),e.addEventListener("focusin",o),()=>{window.removeEventListener("focusin",t),e.removeEventListener("focusin",o)}}),[f,d]),e.useEffect((()=>{if(!S||!f)return;const e=f.ownerDocument.defaultView,o=e?e.document:document,n=e=>{if("Escape"!==e.key||T.closeDisabled){if("Tab"===e.key){const t=f.querySelectorAll('button:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), input, textarea'),n=t[0],s=t[t.length-1],r=o.activeElement;e.shiftKey?r===n&&(e.preventDefault(),s.focus()):r===s&&(e.preventDefault(),n.focus())}}else d.endFlow(g,{endReason:t.USER_CLOSED})};return window.addEventListener("keydown",n),e?.addEventListener("keydown",n),()=>{window.removeEventListener("keydown",n),e?.removeEventListener("keydown",n)}}),[S,d,g,f,T.closeDisabled]),e.useEffect((()=>{if(h.scrollToTopRequested){if(f?.ownerDocument.defaultView?.frameElement){const e=f?.ownerDocument.body;e&&(e.scrollTop=0)}w({kind:"scrolledToTop"})}}),[h.scrollToTopRequested,f]),e.createElement(ne.Provider,{value:I},e.createElement(se.Provider,{value:h},e.createElement(k.Provider,{value:g},e.createElement(B,null,e.createElement(C,{company:g.flow.company,theme:N,position:"fixed",stepKey:E.crossVersionId,stepAppearance:E.appearance,width:E.width,backgroundImageUrl:"flow"===j&&!U&&E.backgroundAsset?E.backgroundAsset.assetUrl:null,tooltipSelector:D,tooltipPlacement:E.tooltipPlacement,backdrop:E.backdrop,tooltipTargetBlocked:E.tooltipTargetBlocked,backdropPadding:E.backdropPadding,onTooltipTargetClick:P,onTooltipTargetMissingChange:Y,onModalBackdropClick:E.appearance!==a.MODAL||N.modalBackdropOnclick!==u.DISMISS||T.closeDisabled?void 0:()=>d.endFlow(g,{endReason:t.USER_CLOSED}),speaking:y,minimizeOnAvatarClick:!0,autoHide3pEnabled:!0,onVisibleChange:m,bubbleFrameRootRef:b,rootChildren:t=>e.createElement(K,{...t,theme:N})},"menu"===j?e.createElement(A,null):U&&N.tooltipMissingBehavior!==r.BUBBLE?e.createElement(W,null):e.createElement(O,null))))))},K=({visible:t,bubbleFrame:o,theme:n})=>{const s=le(),{step:r}=s,l=s.session.currentStep&&s.session.currentStep.id,[a,i]=e.useState(!1),c=e.useRef(l);return e.useEffect((()=>{t?i(!0):c.current!==l&&i(!1),c.current=l}),[l,t]),e.createElement(e.Fragment,null,(t||a)&&"flow"===s.contentType&&e.createElement(e.Fragment,null,e.createElement(V,{bubbleFrame:o,theme:n}),e.createElement(G,null)),r.triggers.map((t=>e.createElement(D,{key:t.id,trigger:t}))))},J={muted:!1,speechPlaying:!1,contentType:"flow",autoFocusRequested:!1,hasFocus:!1,scrollToTopRequested:!1,shouldLabelDialog:!0};function Q(e,t){switch(t.kind){case"updateSession":{let o;return o=t.session.id===e.session.id&&t.session.version.steps.find((({crossVersionId:t})=>t===e.step.crossVersionId))||Z(t.session),{...e,session:t.session,step:o}}case"goToStep":{const o=e.session.version.steps.find((e=>e.id===t.stepId));return o?{...e,step:o,contentType:"flow",autoFocusRequested:e.hasFocus||te(o),scrollToTopRequested:!0,shouldLabelDialog:!e.hasFocus}:e}case"toggleMuted":return{...e,muted:!e.muted};case"speechPlaying":return{...e,speechPlaying:!0};case"speechStopped":return{...e,speechPlaying:!1};case"showFlow":return{...e,contentType:"flow",autoFocusRequested:!0,scrollToTopRequested:!0};case"showMenu":return{...e,contentType:"menu",autoFocusRequested:!0,scrollToTopRequested:!0};case"autoFocused":return{...e,autoFocusRequested:!1};case"focusIn":return{...e,hasFocus:!0};case"focusOut":return{...e,hasFocus:!1};case"scrolledToTop":return{...e,scrollToTopRequested:!1}}}function Z(e){const{currentStep:t}=e,{steps:o}=e.version;if(t){const e=o.find((({crossVersionId:e})=>e===t.crossVersionId));if(!e)throw new d("Session points to an unknown step: "+t.crossVersionId);return e}return ee(e)}function ee(e){const t=e.version.steps[0];if(!t)throw new d("Session has no current step and its version has no start step");return t}function te(e){return oe(e)}function oe(e){return e.appearance===a.MODAL||e.appearance===a.BUBBLE&&e.backdrop||e.appearance===a.TOOLTIP&&e.tooltipTargetBlocked}const ne=e.createContext(null),se=e.createContext(null);function re(){return e.useContext(ne)}function le(){return e.useContext(se)}export default $;export{$ as FlowApp,se as FlowStateContext,J as initialFlowState,oe as isStepModal,re as useFlowDispatch,le as useFlowState};
1
+ import{r as e}from"./vendor.react.js";import{E as t,V as o,w as n,b as s,T as r,v as l,x as a,p as i,A as c,M as u,U as d}from"./userflow.js";import{m as p,d as m,R as f,B as b,i as h,g as w,u as g,c as E,h as v,S as k}from"./BubbleToolbar.js";import{a as y,z as j,g as T,n as R,r as S}from"./flow-condition-types.js";import{u as L,i as M}from"./client-context.js";import{u as x,r as F,F as C}from"./FlowChrome.js";import{e as N,f as I,g as B}from"./Icons.js";import{T as D}from"./Trigger.js";import{u as P}from"./vendor.react-i18next.js";import{u as q}from"./stylesheets.js";import"./vendor.object-assign.js";import"./vendor.phoenix.js";import"./vendor.uuid.js";import"./vendor.obj-str.js";import"./vendor.fortawesome.react-fontawesome.js";import"./vendor.fortawesome.fontawesome-svg-core.js";import"./vendor.prop-types.js";import"./vendor.fortawesome.pro-solid-svg-icons.js";import"./vendor.date-fns.js";import"./vendor.i18next.js";import"./logomark.js";import"./vendor.react-dom.js";import"./vendor.scheduler.js";import"./vendor.babel.runtime.js";const A=()=>{const{t:o}=P(),n=L(),{dispatch:s,restart:r}=re(),{session:l,step:a}=le(),i="userflowjs-bubble-button userflowjs-bubble-button--default userflowjs-bubble-menu__item";return e.createElement("div",{role:"dialog","aria-modal":oe(a)?"true":void 0,"aria-label":"Guide menu"},e.createElement("div",{className:"userflowjs-bubble-menu__title"},o("menu.title")),e.createElement("button",{className:i,onClick:()=>n.endFlow(l,{endReason:t.USER_CLOSED})},o("menu.close")),l.version.restartEnabled&&e.createElement("button",{className:i,onClick:r},o("menu.restart")),e.createElement("button",{className:i,onClick:()=>s({kind:"showFlow"})},o("menu.back")))},_=({progress:t})=>{const o={width:100*parseFloat(t||"0")+"%"};return e.createElement("div",{className:"userflowjs-bubble-progress"},e.createElement("div",{className:"userflowjs-bubble-progress__fill",style:o}))},O=()=>{const s=L(),{session:r,step:l,muted:a,shouldLabelDialog:i}=le(),{version:c}=r,u=l.theme||r.version.theme,{dispatch:d}=re(),h=c.steps[0],w=h&&h.id===l.id,g=w&&"1"===l.progress,E=e.useMemo((()=>l.content&&p(m(l.content),{buttons:l.buttons,questions:l.questions})),[l.content,l.buttons,l.questions]);return e.createElement("div",{key:l.id,role:"alertdialog","aria-modal":oe(l)?"true":void 0,"aria-label":i?"Guide":void 0},!g&&e.createElement(_,{progress:l.progress}),e.createElement("div",{id:"userflowjs-bubble-content",className:"userflowjs-bubble-content"},e.createElement(f,{doc:E,lookupAttribute:y(r.data),buttons:l.buttons,questions:l.questions})),e.createElement(b,{draftMode:r.draftMode,muted:a,toggleMuted:u.voiceType!==o.NONE?()=>d({kind:"toggleMuted"}):void 0,close:c.closeDisabled?void 0:()=>u.flowXButtonBehavior===n.DISMISS||w?s.endFlow(r,{endReason:t.USER_CLOSED}):d({kind:"showMenu"})}))};function U(e,t){if(!e)return"";"string"==typeof e&&(e=m(e));const o=[],n=/[.!?;,]$/;function s(){const e=(o[o.length-1]||"").trim();e&&!e.match(n)&&o.push(".")}function r(e){e.forEach((e=>function(e){if(h(e)){if(e.text&&!e.silent){const t=e.text.split("\n");t.forEach(((e,n)=>{o.push(e),n<t.length-1&&(s(),o.push("\n"))}))}}else switch(e.type){case"attribute":{const n=w(e,t);n&&o.push(n);break}default:r(e.children),["link"].includes(e.type)||(s(),o.push("\n\n"))}}(e)))}return r(e.children),o.join("").trim().replace(new RegExp(String.fromCharCode(160),"g")," ").replace(new RegExp(String.fromCharCode(8),"g"),"")}const V=({bubbleFrame:t,theme:n})=>{const s=L(),{dispatch:r}=re(),{muted:l,session:a,step:i}=le(),c=s.getAudio();e.useEffect((()=>{const e=()=>{r({kind:"speechPlaying"})},t=()=>{r({kind:"speechStopped"})};return c.addEventListener("playing",e),c.addEventListener("ended",t),c.addEventListener("pause",t),()=>{c.removeEventListener("playing",e),c.removeEventListener("ended",t),c.removeEventListener("pause",t),c.pause(),c.src="",r({kind:"speechStopped"})}}),[r,c]),e.useEffect((()=>{if(s.audioReady)return;const e=t&&"IFRAME"===t.tagName?t.contentWindow:null;const o=()=>{window.removeEventListener("mousedown",n),e&&e.removeEventListener("mousedown",n)},n=()=>{o(),s.playAudio(null)};return window.addEventListener("mousedown",n),e&&e.addEventListener("mousedown",n),o}),[t,s]);const u=e.useRef(a),d=e.useRef(n),p=e.useRef(i);return e.useEffect((()=>{u.current=a,d.current=n,p.current=i}),[a,n,i]),e.useEffect((()=>{if(!s.audioReady||l)return void s.pauseAudio();let e=!1;return async function(e,t,n,s){if(n.voiceType===o.SYNTHETIC&&"string"==typeof n.syntheticVoice&&s.content){e.ensureIdentified();const o=y(t.data),r=U(s.content,o);return e.getStepSpeech(n.syntheticVoice,r)}if(n.voiceType===o.MANUAL&&s.speechAsset)return s.speechAsset.assetUrl;return null}(s,u.current,d.current,p.current).then((t=>{t&&!e&&s.playAudio(t)})),()=>{e=!0}}),[l,s,i.id]),null};const Y=e.forwardRef(((t,o)=>{const n=N();return e.createElement("div",{ref:o,className:"userflowjs-out-of-viewport-pointer",style:{zIndex:n+2}},e.createElement(I,null))}));function z(e,t){const o=e.current;o&&(o.classList.toggle("userflowjs-out-of-viewport-pointer--visible",null!=t),t&&(o.style.left=t.left+"px",o.style.top=t.top+"px",o.classList.toggle("userflowjs-out-of-viewport-pointer--visible-up","up"===t.direction),o.classList.toggle("userflowjs-out-of-viewport-pointer--visible-down","down"===t.direction)))}const G=()=>{const{step:t}=le();return e.createElement(e.Fragment,null,t.beacons.map((t=>e.createElement(X,{key:t.id,beacon:t}))))},X=({beacon:t})=>{const{session:o}=le(),n=N(),s=e.useRef(null),r=e.useRef(null),l=g(t.hiddenCondition),a=e.useMemo((()=>R(t.selector,o.data)),[t.selector,o.data]),i=e.useCallback((({targetRect:e,clipEl:o,viewportClipRect:n})=>{const l=function({beacon:e,beaconRef:t,clipEl:o,viewportClipRect:n,targetRect:s}){if(!t.current)return null;if(0===s.width||0===s.height)return null;const r=16,l=16,a=S(o);let i=0,c=0;switch(e.placement){case"top-left":case"left":case"bottom-left":i=s.left;break;case"top":case"center":case"bottom":i=s.left+s.width/2;break;default:i=s.left+s.width}switch(e.placement){case"left":case"center":case"right":c=s.top+s.height/2;break;case"bottom-left":case"bottom":case"bottom-right":c=s.top+s.height;break;default:c=s.top}i-=r/2,c-=l/2,i+=e.offsetX,c+=e.offsetY,i=Math.max(i,a.left-(o===document.documentElement?0:o.scrollLeft)),c=Math.max(c,a.top-(o===document.documentElement?0:o.scrollTop));const u=i+r,d=c+l,p=Math.min(32,.5*l);let m;m=d<n.top+p?"up":c>n.bottom-p?"down":null;return{top:c,right:u,bottom:d,left:i,width:r,height:l,pointerSubjectPosition:{direction:m,left:i,width:r},visible:null==m}}({beacon:t,beaconRef:s,clipEl:o,viewportClipRect:n,targetRect:e}),a=l&&function({subjectPosition:e,pointerRef:t,viewportClipRect:o}){const n=t.current;if(!n)return null;const s=n.getBoundingClientRect(),r=j(T());let l,a,i=e.direction;return null==i?null:("down"===i&&o.bottom<s.height/2?i="up":"up"===i&&o.top>r&&(i="down"),l=e.left+e.width/2-s.width/2,a="down"===i?o.bottom-s.height:o.top,{direction:i,left:l,top:a})}({subjectPosition:l.pointerSubjectPosition,pointerRef:r,viewportClipRect:n});F((()=>{H(s,l),z(r,a)}))}),[t]),c=e.useCallback((()=>{H(s,null),z(r,null)}),[]);return x({selector:l?null:a,targetMoved:i,targetLost:c}),e.createElement(e.Fragment,null,e.createElement("div",{ref:s,className:"userflowjs-beacon userflowjs-beacon--pulse userflowjs-beacon--for-flow userflowjs-fixed-widget",style:{zIndex:n+2}},e.createElement("div",{className:"userflowjs-beacon__ring"}),e.createElement("div",{className:"userflowjs-beacon__ring"})),e.createElement(Y,{ref:r}))};function H(e,t){const o=e.current;o&&(o.classList.toggle("userflowjs-fixed-widget--visible",null!=t),t&&(o.style.transform=`translate3d(${t.left}px, ${t.top}px, 0)`,o.style.visibility=t.visible?"visible":"hidden"))}const W=()=>{const{t:o}=P(),n=L(),{restart:l}=re(),{session:a,step:i}=le(),c=i.theme||a.version.theme,u=i.selector,d=!u||u.type===s.AUTO&&!u.autoData,p=()=>n.endFlow(a,{endReason:t.USER_CLOSED});return e.createElement(e.Fragment,null,e.createElement(b,{draftMode:a.draftMode,close:p}),a.draftMode&&d?e.createElement("div",{className:"userflowjs-bubble-content"},e.createElement("div",{className:"userflowjs-bubble-alert p-like"},e.createElement("span",{className:"userflowjs-bubble-alert__label"},"Preview-only tip"),"No tooltip target selected yet. Please go back to the Builder and select a tooltip target in ",e.createElement("b",null,"Step ",i.idx+1)," of"," ",e.createElement("b",null,a.flow.name),".")):a.draftMode&&c.tooltipMissingBehavior===r.END?e.createElement("div",{className:"userflowjs-bubble-content"},e.createElement("div",{className:"userflowjs-bubble-alert p-like"},e.createElement("p",null,e.createElement("span",{className:"userflowjs-bubble-alert__label"},"Preview-only tip"),"The tooltip target element in ",e.createElement("b",null,"Step ",i.idx+1)," of"," ",e.createElement("b",null,a.flow.name)," was not found within"," ",c.tooltipMissingToleranceSeconds," ",1===parseFloat(c.tooltipMissingToleranceSeconds)?"second":"seconds","."),e.createElement("p",null,"For regular users, the flow will auto-dismiss when this happens."),e.createElement("p",null,"If you are on the right page, then try reselecting the element in the Builder."),e.createElement("p",null,"Read more in our"," ",e.createElement("a",{href:"https://userflow.com/docs/trouble/element-not-found",target:"_blank",rel:"noopener noreferrer"},"Element not found guide"),"."))):e.createElement(e.Fragment,null,e.createElement("div",{className:"userflowjs-bubble-content"},a.draftMode&&e.createElement("div",{className:"userflowjs-bubble-alert p-like"},e.createElement("span",{className:"userflowjs-bubble-alert__label"},"Preview-only tip"),"The tooltip target element in ",e.createElement("b",null,"Step ",i.idx+1)," of"," ",e.createElement("b",null,a.flow.name)," was not found on the page. If you are on the right page, then try reselecting the element in the Builder."),e.createElement("p",null,e.createElement("b",null,o("tooltipTargetMissing.line1"))),e.createElement("p",null,o("tooltipTargetMissing.line2"))),e.createElement("div",{className:"userflowjs-bubble-buttons"},e.createElement(E,{appearance:"primary",onClick:l,text:o("menu.restart")}),e.createElement(E,{appearance:"default",onClick:p,text:o("menu.close")}))))},$=({session:o,checklistSession:n,resourceCenterEmbedsChecklist:s})=>{const d=L(),[p,m]=e.useState(!1),[f,b]=e.useState(null),[h,w]=e.useReducer(Q,void 0,(()=>{const e=o,t=Z(e);return{...J,session:e,step:t,muted:!!l.getItem("flowsMuted"),autoFocusRequested:te(t)}})),{session:g,step:E,speechPlaying:y,contentType:j}=h,{version:T}=g,S=oe(E);let x=0;E.questions.some((e=>e.type===i.NPS))&&(x=420);const F=q(E.theme||T.theme),N=e.useMemo((()=>{let e=F.bubbleY;const t=n?.version.theme;return!s&&n&&t&&n.version.checklist?.launcherEnabled&&E.appearance===a.BUBBLE&&t.checklistLauncherPlacement===F.bubblePlacement&&(F.avatarType===c.NONE||t.checklistLauncherX<F.bubbleX+F.avatarSize)&&(e=Math.max(F.bubbleY,t.checklistLauncherY+t.checklistLauncherHeight+F.bubbleY)),{...F,bubbleWidth:Math.max(F.bubbleWidth,x),bubbleY:e}}),[s,n,E.appearance,F,x]);e.useEffect((()=>{g!==o&&w({kind:"updateSession",session:o});const e=e=>{e.session.id===g.id&&w({kind:"goToStep",stepId:e.step.id})};return d.on("gotostep",e),()=>{d.off("gotostep",e)}}),[d,g,o]);const I=e.useMemo((()=>({dispatch:w,restart:()=>{d.goToStep(g,ee(g)),w({kind:"showFlow"})}})),[d,w,g]),D=e.useMemo((()=>E.selector&&R(E.selector,g.data)),[E.selector,g.data]),P=e.useCallback((()=>{v(d,g,E.actions)}),[d,g,E.actions]);e.useEffect((()=>{h.muted?l.setItem("flowsMuted","true"):l.removeItem("flowsMuted")}),[h.muted]);const _=g.locale?g.locale.standardLocaleId:N.languageId;e.useEffect((()=>{M.changeLanguage(_)}),[_]);const[U,V]=e.useState(!1),Y=e.useCallback((e=>{V(e),e&&N.tooltipMissingBehavior===r.END&&!g.draftMode&&d.endFlow(g,{endReason:t.TOOLTIP_TARGET_MISSING})}),[d,g,N.tooltipMissingBehavior]);return e.useEffect((()=>{if(!p||!h.autoFocusRequested)return;d.originalActiveElement||d.originalActiveElement===f?.ownerDocument.defaultView?.frameElement||(d.originalActiveElement=document.activeElement);let e=f?.querySelector('button:not([tabindex="-1"]):not(.userflowjs-bubble-toolbar-button), [tabindex]:not([tabindex="-1"]):not(.userflowjs-bubble-toolbar-button), input, textarea');if(e&&e.matches(".userflowjs-bubble-buttons button:not(.userflowjs-bubble-button--primary)")){const t=f?.querySelector(".userflowjs-bubble-buttons .userflowjs-bubble-button--primary");t&&(e=t)}e&&"function"==typeof e.focus&&e.focus({preventScroll:!0}),w({kind:"autoFocused"})}),[d,f,p,h.autoFocusRequested]),e.useEffect((()=>{const e=f?.ownerDocument.defaultView;if(!e)return;const t=()=>{w({kind:"focusOut"}),delete d.originalActiveElement},o=()=>{w({kind:"focusIn"})};return window.addEventListener("focusin",t),e.addEventListener("focusin",o),()=>{window.removeEventListener("focusin",t),e.removeEventListener("focusin",o)}}),[f,d]),e.useEffect((()=>{if(!S||!f)return;const e=f.ownerDocument.defaultView,o=e?e.document:document,n=e=>{if("Escape"!==e.key||T.closeDisabled){if("Tab"===e.key){const t=f.querySelectorAll('button:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), input, textarea'),n=t[0],s=t[t.length-1],r=o.activeElement;e.shiftKey?r===n&&(e.preventDefault(),s.focus()):r===s&&(e.preventDefault(),n.focus())}}else d.endFlow(g,{endReason:t.USER_CLOSED})};return window.addEventListener("keydown",n),e?.addEventListener("keydown",n),()=>{window.removeEventListener("keydown",n),e?.removeEventListener("keydown",n)}}),[S,d,g,f,T.closeDisabled]),e.useEffect((()=>{if(h.scrollToTopRequested){if(f?.ownerDocument.defaultView?.frameElement){const e=f?.ownerDocument.body;e&&(e.scrollTop=0)}w({kind:"scrolledToTop"})}}),[h.scrollToTopRequested,f]),e.createElement(ne.Provider,{value:I},e.createElement(se.Provider,{value:h},e.createElement(k.Provider,{value:g},e.createElement(B,null,e.createElement(C,{company:g.flow.company,theme:N,position:"fixed",stepKey:E.crossVersionId,stepAppearance:E.appearance,width:E.width,backgroundImageUrl:"flow"===j&&!U&&E.backgroundAsset?E.backgroundAsset.assetUrl:null,tooltipSelector:D,tooltipPlacement:E.tooltipPlacement,backdrop:E.backdrop,tooltipTargetBlocked:E.tooltipTargetBlocked,backdropPadding:E.backdropPadding,onTooltipTargetClick:P,onTooltipTargetMissingChange:Y,onModalBackdropClick:E.appearance!==a.MODAL||N.modalBackdropOnclick!==u.DISMISS||T.closeDisabled?void 0:()=>d.endFlow(g,{endReason:t.USER_CLOSED}),speaking:y,minimizeOnAvatarClick:!0,autoHide3pEnabled:!0,onVisibleChange:m,bubbleFrameRootRef:b,rootChildren:t=>e.createElement(K,{...t,theme:N})},"menu"===j?e.createElement(A,null):U&&N.tooltipMissingBehavior!==r.BUBBLE?e.createElement(W,null):e.createElement(O,null))))))},K=({visible:t,bubbleFrame:o,theme:n})=>{const s=le(),{step:r}=s,l=s.session.currentStep&&s.session.currentStep.id,[a,i]=e.useState(!1),c=e.useRef(l);return e.useEffect((()=>{t?i(!0):c.current!==l&&i(!1),c.current=l}),[l,t]),e.createElement(e.Fragment,null,(t||a)&&"flow"===s.contentType&&e.createElement(e.Fragment,null,e.createElement(V,{bubbleFrame:o,theme:n}),e.createElement(G,null)),r.triggers.map((t=>e.createElement(D,{key:t.id,trigger:t}))))},J={muted:!1,speechPlaying:!1,contentType:"flow",autoFocusRequested:!1,hasFocus:!1,scrollToTopRequested:!1,shouldLabelDialog:!0};function Q(e,t){switch(t.kind){case"updateSession":{let o;return o=t.session.id===e.session.id&&t.session.version.steps.find((({crossVersionId:t})=>t===e.step.crossVersionId))||Z(t.session),{...e,session:t.session,step:o}}case"goToStep":{const o=e.session.version.steps.find((e=>e.id===t.stepId));return o?{...e,step:o,contentType:"flow",autoFocusRequested:e.hasFocus||te(o),scrollToTopRequested:!0,shouldLabelDialog:!e.hasFocus}:e}case"toggleMuted":return{...e,muted:!e.muted};case"speechPlaying":return{...e,speechPlaying:!0};case"speechStopped":return{...e,speechPlaying:!1};case"showFlow":return{...e,contentType:"flow",autoFocusRequested:!0,scrollToTopRequested:!0};case"showMenu":return{...e,contentType:"menu",autoFocusRequested:!0,scrollToTopRequested:!0};case"autoFocused":return{...e,autoFocusRequested:!1};case"focusIn":return{...e,hasFocus:!0};case"focusOut":return{...e,hasFocus:!1};case"scrolledToTop":return{...e,scrollToTopRequested:!1}}}function Z(e){const{currentStep:t}=e,{steps:o}=e.version;if(t){const e=o.find((({crossVersionId:e})=>e===t.crossVersionId));if(!e)throw new d("Session points to an unknown step: "+t.crossVersionId);return e}return ee(e)}function ee(e){const t=e.version.steps[0];if(!t)throw new d("Session has no current step and its version has no start step");return t}function te(e){return oe(e)}function oe(e){return e.appearance===a.MODAL||e.appearance===a.BUBBLE&&e.backdrop||e.appearance===a.TOOLTIP&&e.tooltipTargetBlocked}const ne=e.createContext(null),se=e.createContext(null);function re(){return e.useContext(ne)}function le(){return e.useContext(se)}export default $;export{$ as FlowApp,se as FlowStateContext,J as initialFlowState,oe as isStepModal,re as useFlowDispatch,le as useFlowState};
package/FlowChrome.js CHANGED
@@ -1 +1 @@
1
- import{r as t}from"./vendor.react.js";import{u as e,F as o,S as a}from"./logomark.js";import{c as l,x as r,A as i,b as n,y as s,B as c,z as u}from"./userflow.js";import{f as d,b as p}from"./BubbleToolbar.js";import{o as m}from"./vendor.obj-str.js";import{n as f,h as b,p as h,q as g,r as w,f as T,d as E,g as v,b as M,s as L,M as y,l as k}from"./flow-condition-types.js";import{a as R,g as j}from"./stylesheets.js";import{e as B}from"./Icons.js";import{u as O}from"./vendor.react-i18next.js";var P=new URL("avatar-frame.css",import.meta.url).href;let x=!1;const I=[];let N,_=[];function H(t){_.push(t)}function C(){I.forEach((t=>t())),_.length>0&&(_.forEach((t=>t())),_=[]),S()}function S(){x&&(N=window.requestAnimationFrame(C))}function D(){}function U({selector:e,targetMoved:o,targetLost:a,onTargetClick:l,onTargetMouseEnter:r,onTargetMouseLeave:i}){const n=t.useRef(o),s=t.useRef(a),c=t.useRef(l),u=t.useRef(r),d=t.useRef(i);t.useLayoutEffect((()=>{n.current=o,s.current=a,c.current=l,u.current=r,d.current=i})),t.useLayoutEffect((()=>{let t=null,o=null,a=null,l=!1;const r=()=>{t=null,o=null,a=null,s.current()};if(!e)return void r();const i=()=>{if(!a||!t)return;const e=w(t);var l,i;o&&(i=e,(l=o).left===i.left&&l.top===i.top&&l.width===i.width&&l.height===i.height)||(o=e,0===e.width&&0===e.height?r():n.current({targetEl:t,targetRect:o,clipEl:a,viewportClipRect:F(a)}))};let p=!1;const m=()=>{var t;p||(p=!0,t=i,I.push(t),1===I.length&&(x=!0,S(),window.addEventListener("scroll",D)))},T=()=>{p&&(p=!1,function(t){const e=I.indexOf(t);e>=0&&(I.splice(e,1),0===I.length&&(x=!1,window.cancelAnimationFrame(N),window.removeEventListener("scroll",D)))}(i))},E=()=>{c.current&&c.current()},v=()=>{u.current&&u.current()},M=()=>{d.current&&d.current()},L=()=>{const o=t;t=b(e)?e:h(e),l&&t===o||(o&&(o.removeEventListener("click",E),o.removeEventListener("mouseenter",v),o.removeEventListener("mouseleave",M)),t?(m(),t.addEventListener("click",E),t.addEventListener("mouseenter",v),t.addEventListener("mouseleave",M),a=g(t)):(T(),r())),l=!0};L();const y=f(L);return()=>{y.disconnect(),T(),t&&(t.removeEventListener("click",E),t.removeEventListener("mouseenter",v),t.removeEventListener("mouseleave",M))}}),[e])}function F(t){T();const e=E(v()),o=E(M());if(t&&t!==document.documentElement){const a=w(t);return{top:Math.max(0,a.top),right:Math.min(o,a.right),bottom:Math.min(e,a.bottom),left:Math.max(0,a.left)}}return{top:0,right:o,bottom:e,left:0}}const A=({company:f,theme:h,position:w,absoluteWidth:x,absoluteHeight:I,stepKey:N,stepAppearance:_,width:H,backgroundImageUrl:C,tooltipSelector:S,allowMissingTooltipTarget:D,tooltipPlacement:F,backdrop:A,tooltipTargetBlocked:K,backdropPadding:q,zIndex:Y,onTooltipTargetClick:X,onTooltipTargetMissingChange:J,onModalBackdropClick:Q,onVisibleChange:Z,speaking:tt,noIframe:et,MadeWithUserflow:ot,minimizeOnAvatarClick:at,autoHide3pEnabled:lt,bubbleFrameRootRef:rt,frameWrapperHtmlAttributes:it,rootChildren:nt,children:st})=>{const ct=w||"absolute",ut=F||null,dt=q||"0",pt=ot||z,mt=B(),ft="fixed"===ct?null!=Y?Y:mt+1:1,bt=ft-1,{i18n:ht}=O(),gt=ht.dir(),wt=t.useRef(null),Tt=t.useRef(null),Et=t.useRef(null),[vt,Mt]=t.useState(null),Lt=t.useRef(null),yt=t.useRef(null),kt=t.useRef(null),Rt=t.useRef(null),jt=t.useRef(null),Bt=t.useRef(null),Ot=t.useRef(null),Pt=t.useRef(null),xt=t.useRef(null);t.useLayoutEffect((()=>{const t=wt.current.style;t.animation="none",t.visibility="hidden",t.position="absolute",t.top="-99999px",t.left="-99999px"}),[]);const{loaded:It}=R(window,d,h),[Nt,_t]=t.useState(!1),[Ht,Ct]=t.useState(!1),St=It&&Nt&&Ht;let[Dt,Ut]=t.useState(!1);_!==r.BUBBLE&&(at=!1,Dt=!1),t.useEffect((()=>{Ut(!1)}),[N]);const Ft=t.useRef({appearance:null,width:null,theme:h,bubbleFrameHeight:0,backdrop:!1,backdropPadding:"0",prevTooltipTargetParams:null,tooltipTargetParams:null,desiredTooltipPlacement:null,tooltipPlacement:null,lastReportedTooltipTargetMissing:!1,tooltipTargetMissing:!1,tooltipTargetMissingTimeout:void 0,stepKeyScrolledIntoView:void 0,targetScrolledIntoView:null}),[At,Wt]=t.useState(null),zt=null!=At&&St;t.useEffect((()=>{Z&&Z(zt)}),[Z,zt]);const Vt=t.useCallback((t=>{Ft.current.lastReportedTooltipTargetMissing!==t&&(Ft.current.lastReportedTooltipTargetMissing=t,J&&J(t))}),[J]),Gt=t.useCallback((({forceAppearanceLayout:t,forceUpdatePosition:e}={})=>{const o=wt.current,a=Tt.current,n=Et.current,d=yt.current,p=Lt.current,m=kt.current,f=Rt.current,b=jt.current,w=Bt.current,y=Ot.current,R=Pt.current,j=xt.current;if(!(o&&a&&n&&vt&&d&&p&&m&&f&&b&&w&&y&&R&&j))return;if(!St)return;const B=Ft.current,{tooltipTargetParams:O}=B;T();let P=_,C=!1;P!==r.TOOLTIP||D||O||(B.tooltipTargetMissing?(P=r.BUBBLE,C=!0):P=null);const S=P!==B.appearance,U=H!==B.width;if((t||S||U||h!==B.theme||A!=B.backdrop||dt!=B.backdropPadding||ut!==B.desiredTooltipPlacement)&&(B.appearance=P,B.width=H,B.theme=h,B.backdrop=A,B.backdropPadding=dt,B.desiredTooltipPlacement=ut,e=!0,function({layoutState:{appearance:t,theme:e,backdrop:o,tooltipTargetMissing:a},width:l,position:n,absoluteWidth:c,root:u,bubble:d,bubbleFrameRoot:p,avatar:m,avatarNotch:f,modalBackdrop:b,dir:h}){const g="absolute"===n?c||1024:E(M()),{avatarSize:w,bubblePlacement:T}=e;let v=e.bubbleWidth,L=null,y=null,k="userflowjs-bubble-frame-root",R="hidden",j=null,B=null,O=null,P=null,x="userflowjs-bubble__avatar-notch",I="hidden",N=null,_=null,H=null,C=null,S="userflowjs-modal-backdrop";(t===r.MODAL||!a&&t===r.BUBBLE&&o)&&(S+=" userflowjs-modal-backdrop--visible");switch(t){case r.BUBBLE:if(e.avatarType!==i.NONE){R="",I="",T===s.TOP_LEFT||T===s.TOP_CENTER||T===s.TOP_RIGHT?(L=w+20,j=0,N=-40,x+=" userflowjs-bubble__avatar-notch--top"):(y=w+20,O=0,H=-40,x+=" userflowjs-bubble__avatar-notch--bottom");const t=T===s.TOP_LEFT||T===s.TOP_CENTER||T===s.BOTTOM_LEFT||T===s.BOTTOM_CENTER||T===s.CENTER;"ltr"===h&&t||"rtl"===h&&!t?(P=0,C=w,x+=" userflowjs-bubble__avatar-notch--left"):(B=0,_=w,x+=" userflowjs-bubble__avatar-notch--right")}break;case r.MODAL:v=e.modalWidth,k+=" userflowjs-bubble-frame-root--appearance-modal",e.avatarType!==i.NONE&&(R="",P=`calc(50% - ${w/2}px)`,j=-w/2);break;case r.TOOLTIP:v=e.tooltipWidth}null!=l&&(v=l);v=Math.min(v,g),u.classList.toggle("userflowjs-flow-chrome--position-absolute","absolute"===n),u.classList.toggle("userflowjs-flow-chrome--position-relative","relative"===n),u.classList.toggle("userflowjs-flow-chrome--position-fixed","fixed"===n),u.classList.toggle("userflowjs-flow-chrome--appearance-modal",t===r.MODAL);const D=null!=t&&t!==r.HIDDEN;u.style.position="",u.style.top="",u.style.left="",u.style.visibility=D?"":"hidden",u.style.animation=D?"":"none",V(d,"width",E(v)),V(d,"padding-top",L),V(d,"padding-bottom",y),p.className=k,V(m,"width",E(e.avatarSize)),V(m,"height",E(e.avatarSize)),m.style.visibility=R,V(m,"top",j),V(m,"right",B),V(m,"bottom",O),V(m,"left",P),f.className=x,f.style.visibility=I,V(f,"top",N),V(f,"right",_),V(f,"bottom",H),V(f,"left",C),b.className=S}({layoutState:B,width:H,position:ct,absoluteWidth:x,root:o,bubble:a,bubbleFrameRoot:vt,avatar:d,avatarNotch:p,modalBackdrop:j,dir:gt})),!et){const t=vt.offsetHeight,o=v()-2*(M()<800?0:16)-(P===r.BUBBLE&&h.avatarType!==i.NONE?20+h.avatarSize:0),a=Math.min(t,o);if(P&&a!==B.bubbleFrameHeight){if(B.bubbleFrameHeight=a,V(n,"height",E(a)),L(n)&&n.contentDocument){n.contentDocument.documentElement.style.overflowY=t<=o?"hidden":"scroll"}e=!0}}if(e&&P){let t=S;if(P===r.TOOLTIP){(B.tooltipTargetParams&&B.tooltipTargetParams.targetEl)!==(B.prevTooltipTargetParams&&B.prevTooltipTargetParams.targetEl)&&(t=!0)}B.prevTooltipTargetParams=B.tooltipTargetParams,function({layoutState:t,animateIn:e,position:o,absoluteWidth:a,absoluteHeight:l,desiredTooltipPlacement:i,root:n,bubble:d,tooltipNotch:p,tooltipBackdrop:m,tooltipBlockTop:f,tooltipBlockRight:b,tooltipBlockBottom:h,tooltipBlockLeft:g,dir:w}){const{appearance:T,theme:L,tooltipTargetParams:y,backdrop:R,backdropPadding:j}=t,{bubblePlacement:B}=L,O=16,P=L.tooltipNotchSize,x=10,{width:I,height:N}=d.getBoundingClientRect(),_="absolute"===o?a||1024:E(M()),H="absolute"===o?l||768:E(v());let C=0,S=0,D="userflowjs-bubble__tooltip-notch",U="hidden",F=null,A=null,W=null,z=null,K="userflowjs-tooltip-backdrop",q=null,Y=null,X=null,J=null,Q=null,Z=null,tt=null,et=null,ot="userflowjs-tooltip-block userflowjs-tooltip-block--top",at=null,lt=null,rt="userflowjs-tooltip-block userflowjs-tooltip-block--right",it=null,nt=null,st="userflowjs-tooltip-block userflowjs-tooltip-block--bottom",ct=null,ut=null,dt="userflowjs-tooltip-block userflowjs-tooltip-block--left",pt=null,mt=null;switch(T){case r.BUBBLE:C=B===s.TOP_LEFT||B===s.BOTTOM_LEFT?L.bubbleX:B===s.TOP_CENTER||B===s.CENTER||B===s.BOTTOM_CENTER?(_-I)/2:_-I-L.bubbleX,S=B===s.TOP_LEFT||B===s.TOP_CENTER||B===s.TOP_RIGHT?L.bubbleY:B===s.CENTER?(H-N)/2:H-N-L.bubbleY,"rtl"===w&&(C=_-C-I),C=Math.max(0,Math.min(_-I,C)),S=Math.max(0,Math.min(H-N,S));break;case r.MODAL:C=O+(_-2*O-I)/2,S=O+(H-2*O-N)/2;break;case r.TOOLTIP:{let e;if(y){let{targetRect:a,viewportClipRect:l}=y;if("absolute"===o){const t=n.offsetParent.getBoundingClientRect();l={top:0,right:_,bottom:H,left:0},a={top:a.top-t.top,right:a.right-t.left,bottom:a.bottom-t.top,left:a.left-t.left,width:a.width,height:a.height}}let r=0;if(R){const{paddingTop:t,paddingRight:e,paddingBottom:o,paddingLeft:l}=function(t){if(!t||"0"===t)return{paddingTop:0,paddingRight:0,paddingBottom:0,paddingLeft:0};const e=t.trim().split(" ");if(1===e.length){const t=$(e[0]);return{paddingTop:t,paddingRight:t,paddingBottom:t,paddingLeft:t}}if(2===e.length){const t=$(e[0]),o=$(e[1]);return{paddingTop:t,paddingRight:o,paddingBottom:t,paddingLeft:o}}return{paddingTop:$(e[0]),paddingRight:$(e[1]),paddingBottom:$(e[2]),paddingLeft:$(e[3])}}(j);a={top:a.top-t,right:a.right+e,bottom:a.bottom+o,left:a.left-l,width:a.width+l+e,height:a.height+t+o},r=Math.min(t,e,o,l)}const s=a,d=L.backdropHighlightType==c.OUTSIDE?L.backdropHighlightSpread:0;if(R&&d&&(a={top:a.top-d,right:a.right+d,bottom:a.bottom+d,left:a.left-d,width:a.width+2*d,height:a.height+2*d}),e=function({targetRect:t,bubbleWidth:e,bubbleHeight:o,containerWidth:a,containerHeight:l,viewportClipRect:r,tooltipNotchSize:i,currentTooltipPlacement:n,desiredTooltipPlacement:s}){if(t.bottom<=r.top)return o+i<=l-r.top?u.BELOW:u.ABOVE;if(t.top>=r.bottom)return o+i<=r.bottom?u.ABOVE:u.BELOW;if(t.right<=r.left)return e+i<=a-r.left?u.RIGHT:u.LEFT;if(t.left>=r.right)return e+i<=r.right?u.LEFT:u.RIGHT;const c=n=>{const s=t.left+t.width/2,c=s>=r.left&&s<=r.right,d=t.top+t.height/2,p=d>=r.top&&d<=r.bottom;switch(n){case u.BELOW:return l-t.bottom>o+i&&c;case u.ABOVE:return t.top>o+i&&c;case u.RIGHT:return a-t.right>e+i&&p;case u.LEFT:return t.left>e+i&&p}};if(s&&c(s))return s;if(n&&c(n))return n;const d=[{placement:u.BELOW,dist:t.top},{placement:u.ABOVE,dist:l-t.bottom},{placement:u.RIGHT,dist:t.left},{placement:u.LEFT,dist:a-t.right}];d.sort(((t,e)=>t.dist-e.dist));for(const{placement:u}of d)if(c(u))return u;return u.BELOW}({targetRect:a,bubbleWidth:I,bubbleHeight:N,containerWidth:_,containerHeight:H,viewportClipRect:l,tooltipNotchSize:P,currentTooltipPlacement:t.tooltipPlacement,desiredTooltipPlacement:i}),e===u.BELOW||e===u.ABOVE?(C=a.left+a.width/2-I/2,C=Math.max(O,Math.min(_-I-O,C)),z=Math.max(x,Math.min(I-x-2*P,a.left+a.width/2-P-C)),e===u.BELOW?F=2*-P:W=2*-P):e===u.RIGHT?(C=a.right+P,C=Math.max(C,l.left+P),C=Math.min(C,l.right+P),C=Math.max(C,P),C=Math.min(C,_-I)):(C=a.left-P-I,C=Math.max(C,l.left-I-P),C=Math.min(C,l.right-I-P),C=Math.max(C,0),C=Math.min(C,_-I-P)),e===u.LEFT||e===u.RIGHT?(S=a.top+a.height/2-N/2,S=Math.max(O,Math.min(H-N-O,S)),F=Math.max(x,Math.min(N-x-2*P,a.top+a.height/2-P-S)),e===u.LEFT?A=2*-P:z=2*-P):e===u.BELOW?(S=a.bottom+P,S=Math.max(S,l.top+P),S=Math.min(S,l.bottom+P),S=Math.max(S,P),S=Math.min(S,H-N)):(S=a.top-P-N,S=Math.max(S,l.top-N-P),S=Math.min(S,l.bottom-N-P),S=Math.max(S,0),S=Math.min(S,H-N-P)),R){const t=window.getComputedStyle(y.targetEl);q=Math.max(0,s.top),Y=Math.max(0,_-s.right),X=Math.max(0,H-s.bottom),J=Math.max(0,s.left),Q=Math.max(0,k(t.borderTopLeftRadius)+r),Z=Math.max(0,k(t.borderTopRightRadius)+r),tt=Math.max(0,k(t.borderBottomRightRadius)+r),et=Math.max(0,k(t.borderBottomLeftRadius)+r),at=Math.max(0,s.right),lt=Math.max(0,s.top),it=Math.max(0,s.right),nt=Math.max(0,s.bottom),ct=Math.max(0,s.left),ut=Math.max(0,s.bottom),pt=Math.max(0,s.left),mt=Math.max(0,s.top)}}else e=i||u.BELOW,e!==u.BELOW&&e!==u.ABOVE||(z=I/2-P,e===u.BELOW?F=2*-P:W=2*-P),e!==u.LEFT&&e!==u.RIGHT||(F=N/2-P,e===u.LEFT?A=2*-P:z=2*-P);t.tooltipPlacement=e,D+=` userflowjs-bubble__tooltip-notch--${e.toLowerCase()}`,U="",R&&(K+=" userflowjs-tooltip-backdrop--visible",ot+=" userflowjs-tooltip-block--visible",rt+=" userflowjs-tooltip-block--visible",st+=" userflowjs-tooltip-block--visible",dt+=" userflowjs-tooltip-block--visible");break}}d.style.transition="";let ft=C,bt=S;if(e&&(d.style.opacity="0",T===r.TOOLTIP)){const e=24;switch(t.tooltipPlacement){case u.BELOW:S+=e;break;case u.ABOVE:S-=e;break;case u.RIGHT:C+=e;break;case u.LEFT:C-=e}}"relative"!==o&&G(d,C,S);if(p.className=D,p.style.visibility=U,V(p,"top",F),V(p,"right",A),V(p,"bottom",W),V(p,"left",z),m.className=K,V(m,"top",q),V(m,"right",Y),V(m,"bottom",X),V(m,"left",J),V(m,"border-top-left-radius",Q),V(m,"border-top-right-radius",Z),V(m,"border-bottom-right-radius",tt),V(m,"border-bottom-left-radius",et),f.className=ot,V(f,"width",at),V(f,"height",lt),b.className=rt,V(b,"left",it),V(b,"height",nt),h.className=st,V(h,"left",ct),V(h,"top",ut),g.className=dt,V(g,"width",pt),V(g,"top",mt),e){d.offsetWidth;const t="opacity 250ms linear";T===r.TOOLTIP?d.style.transition=`${t}, transform 500ms cubic-bezier(0.25, 0.8, 0.5, 1)`:d.style.transition=t,d.style.opacity="1","relative"!==o&&G(d,ft,bt)}}({layoutState:B,animateIn:t,position:ct,absoluteWidth:x,absoluteHeight:I,desiredTooltipPlacement:ut,root:o,bubble:a,tooltipNotch:m,tooltipBackdrop:f,tooltipBlockTop:b,tooltipBlockRight:w,tooltipBlockBottom:y,tooltipBlockLeft:R,dir:gt})}if(P===r.TOOLTIP){const t=O&&O.targetEl;t&&B.stepKeyScrolledIntoView!==N&&B.targetScrolledIntoView!==t&&(B.stepKeyScrolledIntoView=N,B.targetScrolledIntoView=t,function(t){if(l.customScrollIntoView)return void l.customScrollIntoView(t);const{scrollPadding:e}=l;if(e&&g(t)===document.scrollingElement){const o=e.top||0,a=e.right||0,l=e.bottom||0,r=e.left||0;let i=0,n=0;const s=t.getBoundingClientRect(),c=M(),u=v();if(s.top<o?i=s.top-o:s.bottom>u-l&&(i=s.bottom-u+l),s.left<r?n=s.left-r:s.right>c-a&&(n=s.right-c+a),0!=i||0!=n)return void window.scrollBy({top:i,left:n,behavior:"smooth"})}try{t.scrollIntoView({behavior:"smooth",block:"nearest"})}catch(o){console.warn("Userflow.js: scrollIntoView error (falling back to no options).",o),t.scrollIntoView()}}(t))}else B.stepKeyScrolledIntoView=void 0,B.targetScrolledIntoView=null;Vt(C),Wt(P)}),[St,vt,N,_,H,h,ct,x,I,D,ut,A,dt,et,Vt,gt]),$t=t.useRef(Gt);$t.current=Gt;const Kt=t.useRef(!1);t.useEffect((()=>{const t=()=>{Kt.current=!0};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)}),[]);const qt=()=>{window.clearTimeout(Ft.current.tooltipTargetMissingTimeout),Ft.current.tooltipTargetMissingTimeout=void 0};t.useEffect((()=>qt),[]);const Yt=t.useCallback((()=>{const t=Ft.current;if(t.tooltipTargetParams=null,D||(t.tooltipPlacement=null),_!==r.TOOLTIP)return qt(),void(t.tooltipTargetMissing=!1);if(!D&&!t.tooltipTargetMissingTimeout){t.tooltipTargetMissing=!1;const e=!S||b(S)||S.type!==n.AUTO||S.autoData?1e3*parseFloat(h.tooltipMissingToleranceSeconds):1;t.tooltipTargetMissingTimeout=window.setTimeout((()=>{if(!Kt.current){if(S&&!b(S)){let t=S.autoData;if(S.autoData)try{t=JSON.parse(S.autoData)}catch(e){}console.warn("Userflow.js: Tooltip target not found on page.\n",{type:S.type,autoData:t,excludeText:S.excludeText,precision:S.precision,text:S.text,css:S.css})}qt(),t.tooltipTargetMissing=!0,$t.current()}}),e)}$t.current()}),[_,D,S,h.tooltipMissingToleranceSeconds]),Xt=t.useCallback((t=>{const e=Ft.current;qt(),e.tooltipTargetParams&&e.tooltipTargetParams.targetEl!==t.targetEl&&(e.tooltipPlacement=null),e.tooltipTargetParams=t,Gt({forceUpdatePosition:!0})}),[Gt]);U({selector:_===r.TOOLTIP&&S||null,targetMoved:Xt,targetLost:Yt,onTargetClick:X});const Jt=t.useCallback((()=>Gt({forceAppearanceLayout:!0})),[Gt]);e(Jt),t.useEffect((()=>{if(!vt||et||"function"!=typeof y)return;let t;const e=new y((()=>{t||(t=window.requestAnimationFrame((()=>{t=void 0,$t.current()})))}));return e.observe(vt,{childList:!0,attributes:!0,subtree:!0}),()=>{e.disconnect(),t&&window.cancelAnimationFrame(t)}}),[vt,et]),t.useLayoutEffect((()=>{$t.current()})),t.useLayoutEffect((()=>{"absolute"===ct&&Gt({forceAppearanceLayout:!0})}),[ct,x,I]);const Qt=t=>{t.preventDefault(),t.stopPropagation()};return function(e,o){const a=window.Intercom;t.useEffect((()=>{if(o&&e.autoHideIntercom&&"function"==typeof a&&!l.autoHide3pDisabled){try{a("update",{hide_default_launcher:!0})}catch(t){console.warn("Userflow.js: Error when hiding Intercom launcher",t)}return()=>{if(!l.autoHide3pDisabled)try{a("update",{hide_default_launcher:!1})}catch(t){console.warn("Userflow.js: Error when unhiding Intercom launcher",t)}}}}),[a,e.autoHideIntercom,o]);const r=window.$crisp;t.useEffect((()=>{if(o&&e.autoHideCrisp&&r&&!l.autoHide3pDisabled){try{r.push(["do","chat:hide"])}catch(t){console.warn("Userflow.js: Error when hiding Crisp Chat",t)}return()=>{if(!l.autoHide3pDisabled)try{r.push(["do","chat:show"])}catch(t){console.warn("Userflow.js: Error when unhiding Crisp Chat",t)}}}}),[r,e.autoHideCrisp,o]);const i=window.HubSpotConversations;t.useEffect((()=>{if(o&&e.autoHideHubspot&&i&&!l.autoHide3pDisabled){try{i.widget.remove()}catch(t){console.warn("Userflow.js: Error when hiding HubSpot Chat",t)}return()=>{if(!l.autoHide3pDisabled)try{i.widget.load()}catch(t){console.warn("Userflow.js: Error when unhiding HubSpot Chat",t)}}}}),[i,e.autoHideHubspot,o]);const n=window.drift;t.useEffect((()=>{if(o&&e.autoHideDrift&&n&&!l.autoHide3pDisabled){try{n.api.widget.hide()}catch(t){console.warn("Userflow.js: Error when hiding Drift Chat",t)}return()=>{if(!l.autoHide3pDisabled)try{n.api.widget.show()}catch(t){console.warn("Userflow.js: Error when unhiding Drift Chat",t)}}}}),[n,e.autoHideDrift,o])}(h,!!lt&&At===r.BUBBLE),t.createElement("div",{ref:wt,"data-testid":"flow-chrome",className:"userflowjs-flow-chrome userflowjs-theme-root",style:j(h),dir:gt},t.createElement("div",{className:"userflowjs-bubble",ref:Tt,style:{zIndex:ft}},t.createElement("div",{className:m({"userflowjs-bubble-outline":!0,[`userflowjs-bubble-outline--bubble-placement-${(h.bubblePlacement||"").toLowerCase().replace(/_/,"-")}`]:!0,"userflowjs-bubble-outline--minimizable":!!at,"userflowjs-bubble-outline--minimized":Dt})},t.createElement("div",{className:"userflowjs-bubble__frame-wrapper",...it},t.createElement(o,{className:"userflowjs-bubble__frame",elRef:Et,stylesheetUrl:p,theme:h,onStylesheetsLoad:_t,noIframe:et},t.createElement("div",{className:"userflowjs-bubble-frame-root",dir:gt,ref:t=>{rt&&rt(t),Mt(t)},style:C?{backgroundImage:`url("${encodeURI(C)}")`}:void 0},st,f.flowBranding&&t.createElement("div",{className:"userflowjs-bubble-made-with-userflow"},t.createElement("div",{className:"userflowjs-bubble-made-with-userflow__absolute"},t.createElement(pt,{company:f},t.createElement(a,null),t.createElement("div",null,"Made with Userflow"))))))),t.createElement("div",{ref:Lt,className:"userflowjs-bubble__avatar-notch"})),t.createElement(o,{className:m({"userflowjs-bubble__avatar":!0,"userflowjs-bubble__avatar--minimizable":!!at,"userflowjs-bubble__avatar--speaking":!!tt}),elRef:yt,stylesheetUrl:P,theme:h,onStylesheetsLoad:Ct,noIframe:et,ariaHidden:!0},t.createElement("div",{className:m({"userflowjs-avatar-frame-root":!0,"userflowjs-avatar-frame-root--minimizable":!!at}),onClick:at?()=>Ut((t=>!t)):void 0},t.createElement(W,{theme:h}))),t.createElement("div",{ref:kt,className:"userflowjs-bubble__tooltip-notch"})),t.createElement("div",{ref:Rt,className:"userflowjs-tooltip-backdrop",onMouseDown:Qt,style:{zIndex:bt,pointerEvents:K?void 0:"none"}}),t.createElement("div",{ref:jt,className:"userflowjs-tooltip-block",onMouseDown:Qt,style:{zIndex:bt}}),t.createElement("div",{ref:Bt,className:"userflowjs-tooltip-block",onMouseDown:Qt,style:{zIndex:bt}}),t.createElement("div",{ref:Ot,className:"userflowjs-tooltip-block",onMouseDown:Qt,style:{zIndex:bt}}),t.createElement("div",{ref:Pt,className:"userflowjs-tooltip-block",onMouseDown:Qt,style:{zIndex:bt}}),t.createElement("div",{ref:xt,className:"userflowjs-modal-backdrop",onMouseDown:Qt,onClick:Q,style:{zIndex:bt}}),nt&&nt({visible:zt,bubbleFrame:Et.current}))},W=({theme:e})=>{const o="https://js.userflow.com/cartoon-avatars-no-bg/";let a;return a=e.avatarType===i.ASSET&&e.avatarAsset?e.avatarAsset.assetUrl:e.avatarType===i.CARTOON&&e.avatarName?o+e.avatarName+".svg?3":e.avatarType===i.URL&&e.avatarUrl?e.avatarUrl:o+"none.svg",t.createElement("img",{src:a,alt:""})},z=({company:e,children:o})=>t.createElement("a",{href:"https://userflow.com/?utm_source=made-with-userflow&utm_medium=link&utm_campaign=made-with-userflow-"+e.slug,target:"_blank",rel:"noopener noreferrer"},o);function V(t,e,o){null==o?t.style.removeProperty(e):t.style.setProperty(e,"number"==typeof o?o+"px":o,"important")}function G(t,e,o){e=Math.round(e),o=Math.round(o),t.style.transform=`translate3d(${e}px, ${o}px, 0px)`}function $(t){const e=parseInt(t,10);return isNaN(e)?0:e}export{A as F,H as r,U as u};
1
+ import{r as t}from"./vendor.react.js";import{u as e,F as o,S as a}from"./logomark.js";import{c as l,x as r,A as i,b as n,y as s,B as c,z as u}from"./userflow.js";import{f as d,b as p}from"./BubbleToolbar.js";import{o as m}from"./vendor.obj-str.js";import{p as f,j as b,q as h,s as g,r as w,h as T,e as E,g as v,d as M,t as L,M as y,m as k}from"./flow-condition-types.js";import{a as j,g as R}from"./stylesheets.js";import{e as B}from"./Icons.js";import{u as O}from"./vendor.react-i18next.js";var P=new URL("avatar-frame.css",import.meta.url).href;let x=!1;const I=[];let N,_=[];function H(t){_.push(t)}function C(){I.forEach((t=>t())),_.length>0&&(_.forEach((t=>t())),_=[]),S()}function S(){x&&(N=window.requestAnimationFrame(C))}function D(){}function U({selector:e,targetMoved:o,targetLost:a,onTargetClick:l,onTargetMouseEnter:r,onTargetMouseLeave:i}){const n=t.useRef(o),s=t.useRef(a),c=t.useRef(l),u=t.useRef(r),d=t.useRef(i);t.useLayoutEffect((()=>{n.current=o,s.current=a,c.current=l,u.current=r,d.current=i})),t.useLayoutEffect((()=>{let t=null,o=null,a=null,l=!1;const r=()=>{t=null,o=null,a=null,s.current()};if(!e)return void r();const i=()=>{if(!a||!t)return;const e=w(t);var l,i;o&&(i=e,(l=o).left===i.left&&l.top===i.top&&l.width===i.width&&l.height===i.height)||(o=e,0===e.width&&0===e.height?r():n.current({targetEl:t,targetRect:o,clipEl:a,viewportClipRect:F(a)}))};let p=!1;const m=()=>{var t;p||(p=!0,t=i,I.push(t),1===I.length&&(x=!0,S(),window.addEventListener("scroll",D)))},T=()=>{p&&(p=!1,function(t){const e=I.indexOf(t);e>=0&&(I.splice(e,1),0===I.length&&(x=!1,window.cancelAnimationFrame(N),window.removeEventListener("scroll",D)))}(i))},E=()=>{c.current&&c.current()},v=()=>{u.current&&u.current()},M=()=>{d.current&&d.current()},L=()=>{const o=t;t=b(e)?e:h(e),l&&t===o||(o&&(o.removeEventListener("click",E),o.removeEventListener("mouseenter",v),o.removeEventListener("mouseleave",M)),t?(m(),t.addEventListener("click",E),t.addEventListener("mouseenter",v),t.addEventListener("mouseleave",M),a=g(t)):(T(),r())),l=!0};L();const y=f(L);return()=>{y.disconnect(),T(),t&&(t.removeEventListener("click",E),t.removeEventListener("mouseenter",v),t.removeEventListener("mouseleave",M))}}),[e])}function F(t){T();const e=E(v()),o=E(M());if(t&&t!==document.documentElement){const a=w(t);return{top:Math.max(0,a.top),right:Math.min(o,a.right),bottom:Math.min(e,a.bottom),left:Math.max(0,a.left)}}return{top:0,right:o,bottom:e,left:0}}const A=({company:f,theme:h,position:w,absoluteWidth:x,absoluteHeight:I,stepKey:N,stepAppearance:_,width:H,backgroundImageUrl:C,tooltipSelector:S,allowMissingTooltipTarget:D,tooltipPlacement:F,backdrop:A,tooltipTargetBlocked:K,backdropPadding:q,zIndex:Y,onTooltipTargetClick:X,onTooltipTargetMissingChange:J,onModalBackdropClick:Q,onVisibleChange:Z,speaking:tt,noIframe:et,MadeWithUserflow:ot,minimizeOnAvatarClick:at,autoHide3pEnabled:lt,bubbleFrameRootRef:rt,frameWrapperHtmlAttributes:it,rootChildren:nt,children:st})=>{const ct=w||"absolute",ut=F||null,dt=q||"0",pt=ot||z,mt=B(),ft="fixed"===ct?null!=Y?Y:mt+1:1,bt=ft-1,{i18n:ht}=O(),gt=ht.dir(),wt=t.useRef(null),Tt=t.useRef(null),Et=t.useRef(null),[vt,Mt]=t.useState(null),Lt=t.useRef(null),yt=t.useRef(null),kt=t.useRef(null),jt=t.useRef(null),Rt=t.useRef(null),Bt=t.useRef(null),Ot=t.useRef(null),Pt=t.useRef(null),xt=t.useRef(null);t.useLayoutEffect((()=>{const t=wt.current.style;t.animation="none",t.visibility="hidden",t.position="absolute",t.top="-99999px",t.left="-99999px"}),[]);const{loaded:It}=j(window,d,h),[Nt,_t]=t.useState(!1),[Ht,Ct]=t.useState(!1),St=It&&Nt&&Ht;let[Dt,Ut]=t.useState(!1);_!==r.BUBBLE&&(at=!1,Dt=!1),t.useEffect((()=>{Ut(!1)}),[N]);const Ft=t.useRef({appearance:null,width:null,theme:h,bubbleFrameHeight:0,backdrop:!1,backdropPadding:"0",prevTooltipTargetParams:null,tooltipTargetParams:null,desiredTooltipPlacement:null,tooltipPlacement:null,lastReportedTooltipTargetMissing:!1,tooltipTargetMissing:!1,tooltipTargetMissingTimeout:void 0,stepKeyScrolledIntoView:void 0,targetScrolledIntoView:null}),[At,Wt]=t.useState(null),zt=null!=At&&St;t.useEffect((()=>{Z&&Z(zt)}),[Z,zt]);const Vt=t.useCallback((t=>{Ft.current.lastReportedTooltipTargetMissing!==t&&(Ft.current.lastReportedTooltipTargetMissing=t,J&&J(t))}),[J]),Gt=t.useCallback((({forceAppearanceLayout:t,forceUpdatePosition:e}={})=>{const o=wt.current,a=Tt.current,n=Et.current,d=yt.current,p=Lt.current,m=kt.current,f=jt.current,b=Rt.current,w=Bt.current,y=Ot.current,j=Pt.current,R=xt.current;if(!(o&&a&&n&&vt&&d&&p&&m&&f&&b&&w&&y&&j&&R))return;if(!St)return;const B=Ft.current,{tooltipTargetParams:O}=B;T();let P=_,C=!1;P!==r.TOOLTIP||D||O||(B.tooltipTargetMissing?(P=r.BUBBLE,C=!0):P=null);const S=P!==B.appearance,U=H!==B.width;if((t||S||U||h!==B.theme||A!=B.backdrop||dt!=B.backdropPadding||ut!==B.desiredTooltipPlacement)&&(B.appearance=P,B.width=H,B.theme=h,B.backdrop=A,B.backdropPadding=dt,B.desiredTooltipPlacement=ut,e=!0,function({layoutState:{appearance:t,theme:e,backdrop:o,tooltipTargetMissing:a},width:l,position:n,absoluteWidth:c,root:u,bubble:d,bubbleFrameRoot:p,avatar:m,avatarNotch:f,modalBackdrop:b,dir:h}){const g="absolute"===n?c||1024:E(M()),{avatarSize:w,bubblePlacement:T}=e;let v=e.bubbleWidth,L=null,y=null,k="userflowjs-bubble-frame-root",j="hidden",R=null,B=null,O=null,P=null,x="userflowjs-bubble__avatar-notch",I="hidden",N=null,_=null,H=null,C=null,S="userflowjs-modal-backdrop";(t===r.MODAL||!a&&t===r.BUBBLE&&o)&&(S+=" userflowjs-modal-backdrop--visible");switch(t){case r.BUBBLE:if(e.avatarType!==i.NONE){j="",I="",T===s.TOP_LEFT||T===s.TOP_CENTER||T===s.TOP_RIGHT?(L=w+20,R=0,N=-40,x+=" userflowjs-bubble__avatar-notch--top"):(y=w+20,O=0,H=-40,x+=" userflowjs-bubble__avatar-notch--bottom");const t=T===s.TOP_LEFT||T===s.TOP_CENTER||T===s.BOTTOM_LEFT||T===s.BOTTOM_CENTER||T===s.CENTER;"ltr"===h&&t||"rtl"===h&&!t?(P=0,C=w,x+=" userflowjs-bubble__avatar-notch--left"):(B=0,_=w,x+=" userflowjs-bubble__avatar-notch--right")}break;case r.MODAL:v=e.modalWidth,k+=" userflowjs-bubble-frame-root--appearance-modal",e.avatarType!==i.NONE&&(j="",P=`calc(50% - ${w/2}px)`,R=-w/2);break;case r.TOOLTIP:v=e.tooltipWidth}null!=l&&(v=l);v=Math.min(v,g),u.classList.toggle("userflowjs-flow-chrome--position-absolute","absolute"===n),u.classList.toggle("userflowjs-flow-chrome--position-relative","relative"===n),u.classList.toggle("userflowjs-flow-chrome--position-fixed","fixed"===n),u.classList.toggle("userflowjs-flow-chrome--appearance-modal",t===r.MODAL);const D=null!=t&&t!==r.HIDDEN;u.style.position="",u.style.top="",u.style.left="",u.style.visibility=D?"":"hidden",u.style.animation=D?"":"none",V(d,"width",E(v)),V(d,"padding-top",L),V(d,"padding-bottom",y),p.className=k,V(m,"width",E(e.avatarSize)),V(m,"height",E(e.avatarSize)),m.style.visibility=j,V(m,"top",R),V(m,"right",B),V(m,"bottom",O),V(m,"left",P),f.className=x,f.style.visibility=I,V(f,"top",N),V(f,"right",_),V(f,"bottom",H),V(f,"left",C),b.className=S}({layoutState:B,width:H,position:ct,absoluteWidth:x,root:o,bubble:a,bubbleFrameRoot:vt,avatar:d,avatarNotch:p,modalBackdrop:R,dir:gt})),!et){const t=vt.offsetHeight,o=v()-2*(M()<800?0:16)-(P===r.BUBBLE&&h.avatarType!==i.NONE?20+h.avatarSize:0),a=Math.min(t,o);if(P&&a!==B.bubbleFrameHeight){if(B.bubbleFrameHeight=a,V(n,"height",E(a)),L(n)&&n.contentDocument){n.contentDocument.documentElement.style.overflowY=t<=o?"hidden":"scroll"}e=!0}}if(e&&P){let t=S;if(P===r.TOOLTIP){(B.tooltipTargetParams&&B.tooltipTargetParams.targetEl)!==(B.prevTooltipTargetParams&&B.prevTooltipTargetParams.targetEl)&&(t=!0)}B.prevTooltipTargetParams=B.tooltipTargetParams,function({layoutState:t,animateIn:e,position:o,absoluteWidth:a,absoluteHeight:l,desiredTooltipPlacement:i,root:n,bubble:d,tooltipNotch:p,tooltipBackdrop:m,tooltipBlockTop:f,tooltipBlockRight:b,tooltipBlockBottom:h,tooltipBlockLeft:g,dir:w}){const{appearance:T,theme:L,tooltipTargetParams:y,backdrop:j,backdropPadding:R}=t,{bubblePlacement:B}=L,O=16,P=L.tooltipNotchSize,x=10,{width:I,height:N}=d.getBoundingClientRect(),_="absolute"===o?a||1024:E(M()),H="absolute"===o?l||768:E(v());let C=0,S=0,D="userflowjs-bubble__tooltip-notch",U="hidden",F=null,A=null,W=null,z=null,K="userflowjs-tooltip-backdrop",q=null,Y=null,X=null,J=null,Q=null,Z=null,tt=null,et=null,ot="userflowjs-tooltip-block userflowjs-tooltip-block--top",at=null,lt=null,rt="userflowjs-tooltip-block userflowjs-tooltip-block--right",it=null,nt=null,st="userflowjs-tooltip-block userflowjs-tooltip-block--bottom",ct=null,ut=null,dt="userflowjs-tooltip-block userflowjs-tooltip-block--left",pt=null,mt=null;switch(T){case r.BUBBLE:C=B===s.TOP_LEFT||B===s.BOTTOM_LEFT?L.bubbleX:B===s.TOP_CENTER||B===s.CENTER||B===s.BOTTOM_CENTER?(_-I)/2:_-I-L.bubbleX,S=B===s.TOP_LEFT||B===s.TOP_CENTER||B===s.TOP_RIGHT?L.bubbleY:B===s.CENTER?(H-N)/2:H-N-L.bubbleY,"rtl"===w&&(C=_-C-I),C=Math.max(0,Math.min(_-I,C)),S=Math.max(0,Math.min(H-N,S));break;case r.MODAL:C=O+(_-2*O-I)/2,S=O+(H-2*O-N)/2;break;case r.TOOLTIP:{let e;if(y){let{targetRect:a,viewportClipRect:l}=y;if("absolute"===o){const t=n.offsetParent.getBoundingClientRect();l={top:0,right:_,bottom:H,left:0},a={top:a.top-t.top,right:a.right-t.left,bottom:a.bottom-t.top,left:a.left-t.left,width:a.width,height:a.height}}let r=0;if(j){const{paddingTop:t,paddingRight:e,paddingBottom:o,paddingLeft:l}=function(t){if(!t||"0"===t)return{paddingTop:0,paddingRight:0,paddingBottom:0,paddingLeft:0};const e=t.trim().split(" ");if(1===e.length){const t=$(e[0]);return{paddingTop:t,paddingRight:t,paddingBottom:t,paddingLeft:t}}if(2===e.length){const t=$(e[0]),o=$(e[1]);return{paddingTop:t,paddingRight:o,paddingBottom:t,paddingLeft:o}}return{paddingTop:$(e[0]),paddingRight:$(e[1]),paddingBottom:$(e[2]),paddingLeft:$(e[3])}}(R);a={top:a.top-t,right:a.right+e,bottom:a.bottom+o,left:a.left-l,width:a.width+l+e,height:a.height+t+o},r=Math.min(t,e,o,l)}const s=a,d=L.backdropHighlightType==c.OUTSIDE?L.backdropHighlightSpread:0;if(j&&d&&(a={top:a.top-d,right:a.right+d,bottom:a.bottom+d,left:a.left-d,width:a.width+2*d,height:a.height+2*d}),e=function({targetRect:t,bubbleWidth:e,bubbleHeight:o,containerWidth:a,containerHeight:l,viewportClipRect:r,tooltipNotchSize:i,currentTooltipPlacement:n,desiredTooltipPlacement:s}){if(t.bottom<=r.top)return o+i<=l-r.top?u.BELOW:u.ABOVE;if(t.top>=r.bottom)return o+i<=r.bottom?u.ABOVE:u.BELOW;if(t.right<=r.left)return e+i<=a-r.left?u.RIGHT:u.LEFT;if(t.left>=r.right)return e+i<=r.right?u.LEFT:u.RIGHT;const c=n=>{const s=t.left+t.width/2,c=s>=r.left&&s<=r.right,d=t.top+t.height/2,p=d>=r.top&&d<=r.bottom;switch(n){case u.BELOW:return l-t.bottom>o+i&&c;case u.ABOVE:return t.top>o+i&&c;case u.RIGHT:return a-t.right>e+i&&p;case u.LEFT:return t.left>e+i&&p}};if(s&&c(s))return s;if(n&&c(n))return n;const d=[{placement:u.BELOW,dist:t.top},{placement:u.ABOVE,dist:l-t.bottom},{placement:u.RIGHT,dist:t.left},{placement:u.LEFT,dist:a-t.right}];d.sort(((t,e)=>t.dist-e.dist));for(const{placement:u}of d)if(c(u))return u;return u.BELOW}({targetRect:a,bubbleWidth:I,bubbleHeight:N,containerWidth:_,containerHeight:H,viewportClipRect:l,tooltipNotchSize:P,currentTooltipPlacement:t.tooltipPlacement,desiredTooltipPlacement:i}),e===u.BELOW||e===u.ABOVE?(C=a.left+a.width/2-I/2,C=Math.max(O,Math.min(_-I-O,C)),z=Math.max(x,Math.min(I-x-2*P,a.left+a.width/2-P-C)),e===u.BELOW?F=2*-P:W=2*-P):e===u.RIGHT?(C=a.right+P,C=Math.max(C,l.left+P),C=Math.min(C,l.right+P),C=Math.max(C,P),C=Math.min(C,_-I)):(C=a.left-P-I,C=Math.max(C,l.left-I-P),C=Math.min(C,l.right-I-P),C=Math.max(C,0),C=Math.min(C,_-I-P)),e===u.LEFT||e===u.RIGHT?(S=a.top+a.height/2-N/2,S=Math.max(O,Math.min(H-N-O,S)),F=Math.max(x,Math.min(N-x-2*P,a.top+a.height/2-P-S)),e===u.LEFT?A=2*-P:z=2*-P):e===u.BELOW?(S=a.bottom+P,S=Math.max(S,l.top+P),S=Math.min(S,l.bottom+P),S=Math.max(S,P),S=Math.min(S,H-N)):(S=a.top-P-N,S=Math.max(S,l.top-N-P),S=Math.min(S,l.bottom-N-P),S=Math.max(S,0),S=Math.min(S,H-N-P)),j){const t=window.getComputedStyle(y.targetEl);q=Math.max(0,s.top),Y=Math.max(0,_-s.right),X=Math.max(0,H-s.bottom),J=Math.max(0,s.left),Q=Math.max(0,k(t.borderTopLeftRadius)+r),Z=Math.max(0,k(t.borderTopRightRadius)+r),tt=Math.max(0,k(t.borderBottomRightRadius)+r),et=Math.max(0,k(t.borderBottomLeftRadius)+r),at=Math.max(0,s.right),lt=Math.max(0,s.top),it=Math.max(0,s.right),nt=Math.max(0,s.bottom),ct=Math.max(0,s.left),ut=Math.max(0,s.bottom),pt=Math.max(0,s.left),mt=Math.max(0,s.top)}}else e=i||u.BELOW,e!==u.BELOW&&e!==u.ABOVE||(z=I/2-P,e===u.BELOW?F=2*-P:W=2*-P),e!==u.LEFT&&e!==u.RIGHT||(F=N/2-P,e===u.LEFT?A=2*-P:z=2*-P);t.tooltipPlacement=e,D+=` userflowjs-bubble__tooltip-notch--${e.toLowerCase()}`,U="",j&&(K+=" userflowjs-tooltip-backdrop--visible",ot+=" userflowjs-tooltip-block--visible",rt+=" userflowjs-tooltip-block--visible",st+=" userflowjs-tooltip-block--visible",dt+=" userflowjs-tooltip-block--visible");break}}d.style.transition="";let ft=C,bt=S;if(e&&(d.style.opacity="0",T===r.TOOLTIP)){const e=24;switch(t.tooltipPlacement){case u.BELOW:S+=e;break;case u.ABOVE:S-=e;break;case u.RIGHT:C+=e;break;case u.LEFT:C-=e}}"relative"!==o&&G(d,C,S);if(p.className=D,p.style.visibility=U,V(p,"top",F),V(p,"right",A),V(p,"bottom",W),V(p,"left",z),m.className=K,V(m,"top",q),V(m,"right",Y),V(m,"bottom",X),V(m,"left",J),V(m,"border-top-left-radius",Q),V(m,"border-top-right-radius",Z),V(m,"border-bottom-right-radius",tt),V(m,"border-bottom-left-radius",et),f.className=ot,V(f,"width",at),V(f,"height",lt),b.className=rt,V(b,"left",it),V(b,"height",nt),h.className=st,V(h,"left",ct),V(h,"top",ut),g.className=dt,V(g,"width",pt),V(g,"top",mt),e){d.offsetWidth;const t="opacity 250ms linear";T===r.TOOLTIP?d.style.transition=`${t}, transform 500ms cubic-bezier(0.25, 0.8, 0.5, 1)`:d.style.transition=t,d.style.opacity="1","relative"!==o&&G(d,ft,bt)}}({layoutState:B,animateIn:t,position:ct,absoluteWidth:x,absoluteHeight:I,desiredTooltipPlacement:ut,root:o,bubble:a,tooltipNotch:m,tooltipBackdrop:f,tooltipBlockTop:b,tooltipBlockRight:w,tooltipBlockBottom:y,tooltipBlockLeft:j,dir:gt})}if(P===r.TOOLTIP){const t=O&&O.targetEl;t&&B.stepKeyScrolledIntoView!==N&&B.targetScrolledIntoView!==t&&(B.stepKeyScrolledIntoView=N,B.targetScrolledIntoView=t,function(t){if(l.customScrollIntoView)return void l.customScrollIntoView(t);const{scrollPadding:e}=l;if(e&&g(t)===document.scrollingElement){const o=e.top||0,a=e.right||0,l=e.bottom||0,r=e.left||0;let i=0,n=0;const s=t.getBoundingClientRect(),c=M(),u=v();if(s.top<o?i=s.top-o:s.bottom>u-l&&(i=s.bottom-u+l),s.left<r?n=s.left-r:s.right>c-a&&(n=s.right-c+a),0!=i||0!=n)return void window.scrollBy({top:i,left:n,behavior:"smooth"})}try{t.scrollIntoView({behavior:"smooth",block:"nearest"})}catch(o){console.warn("Userflow.js: scrollIntoView error (falling back to no options).",o),t.scrollIntoView()}}(t))}else B.stepKeyScrolledIntoView=void 0,B.targetScrolledIntoView=null;Vt(C),Wt(P)}),[St,vt,N,_,H,h,ct,x,I,D,ut,A,dt,et,Vt,gt]),$t=t.useRef(Gt);$t.current=Gt;const Kt=t.useRef(!1);t.useEffect((()=>{const t=()=>{Kt.current=!0};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)}),[]);const qt=()=>{window.clearTimeout(Ft.current.tooltipTargetMissingTimeout),Ft.current.tooltipTargetMissingTimeout=void 0};t.useEffect((()=>qt),[]);const Yt=t.useCallback((()=>{const t=Ft.current;if(t.tooltipTargetParams=null,D||(t.tooltipPlacement=null),_!==r.TOOLTIP)return qt(),void(t.tooltipTargetMissing=!1);if(!D&&!t.tooltipTargetMissingTimeout){t.tooltipTargetMissing=!1;const e=!S||b(S)||S.type!==n.AUTO||S.autoData?1e3*parseFloat(h.tooltipMissingToleranceSeconds):1;t.tooltipTargetMissingTimeout=window.setTimeout((()=>{if(!Kt.current){if(S&&!b(S)){let t=S.autoData;if(S.autoData)try{t=JSON.parse(S.autoData)}catch(e){}console.warn("Userflow.js: Tooltip target not found on page.\n",{type:S.type,autoData:t,excludeText:S.excludeText,precision:S.precision,text:S.text,css:S.css})}qt(),t.tooltipTargetMissing=!0,$t.current()}}),e)}$t.current()}),[_,D,S,h.tooltipMissingToleranceSeconds]),Xt=t.useCallback((t=>{const e=Ft.current;qt(),e.tooltipTargetParams&&e.tooltipTargetParams.targetEl!==t.targetEl&&(e.tooltipPlacement=null),e.tooltipTargetParams=t,Gt({forceUpdatePosition:!0})}),[Gt]);U({selector:_===r.TOOLTIP&&S||null,targetMoved:Xt,targetLost:Yt,onTargetClick:X});const Jt=t.useCallback((()=>Gt({forceAppearanceLayout:!0})),[Gt]);e(Jt),t.useEffect((()=>{if(!vt||et||"function"!=typeof y)return;let t;const e=new y((()=>{t||(t=window.requestAnimationFrame((()=>{t=void 0,$t.current()})))}));return e.observe(vt,{childList:!0,attributes:!0,subtree:!0}),()=>{e.disconnect(),t&&window.cancelAnimationFrame(t)}}),[vt,et]),t.useLayoutEffect((()=>{$t.current()})),t.useLayoutEffect((()=>{"absolute"===ct&&Gt({forceAppearanceLayout:!0})}),[ct,x,I]);const Qt=t=>{t.preventDefault(),t.stopPropagation()};return function(e,o){const a=window.Intercom;t.useEffect((()=>{if(o&&e.autoHideIntercom&&"function"==typeof a&&!l.autoHide3pDisabled){try{a("update",{hide_default_launcher:!0})}catch(t){console.warn("Userflow.js: Error when hiding Intercom launcher",t)}return()=>{if(!l.autoHide3pDisabled)try{a("update",{hide_default_launcher:!1})}catch(t){console.warn("Userflow.js: Error when unhiding Intercom launcher",t)}}}}),[a,e.autoHideIntercom,o]);const r=window.$crisp;t.useEffect((()=>{if(o&&e.autoHideCrisp&&r&&!l.autoHide3pDisabled){try{r.push(["do","chat:hide"])}catch(t){console.warn("Userflow.js: Error when hiding Crisp Chat",t)}return()=>{if(!l.autoHide3pDisabled)try{r.push(["do","chat:show"])}catch(t){console.warn("Userflow.js: Error when unhiding Crisp Chat",t)}}}}),[r,e.autoHideCrisp,o]);const i=window.HubSpotConversations;t.useEffect((()=>{if(o&&e.autoHideHubspot&&i&&!l.autoHide3pDisabled){try{i.widget.remove()}catch(t){console.warn("Userflow.js: Error when hiding HubSpot Chat",t)}return()=>{if(!l.autoHide3pDisabled)try{i.widget.load()}catch(t){console.warn("Userflow.js: Error when unhiding HubSpot Chat",t)}}}}),[i,e.autoHideHubspot,o]);const n=window.drift;t.useEffect((()=>{if(o&&e.autoHideDrift&&n&&!l.autoHide3pDisabled){try{n.api.widget.hide()}catch(t){console.warn("Userflow.js: Error when hiding Drift Chat",t)}return()=>{if(!l.autoHide3pDisabled)try{n.api.widget.show()}catch(t){console.warn("Userflow.js: Error when unhiding Drift Chat",t)}}}}),[n,e.autoHideDrift,o])}(h,!!lt&&At===r.BUBBLE),t.createElement("div",{ref:wt,"data-testid":"flow-chrome",className:"userflowjs-flow-chrome userflowjs-theme-root",style:R(h),dir:gt},t.createElement("div",{className:"userflowjs-bubble",ref:Tt,style:{zIndex:ft}},t.createElement("div",{className:m({"userflowjs-bubble-outline":!0,[`userflowjs-bubble-outline--bubble-placement-${(h.bubblePlacement||"").toLowerCase().replace(/_/,"-")}`]:!0,"userflowjs-bubble-outline--minimizable":!!at,"userflowjs-bubble-outline--minimized":Dt})},t.createElement("div",{className:"userflowjs-bubble__frame-wrapper",...it},t.createElement(o,{className:"userflowjs-bubble__frame",elRef:Et,stylesheetUrl:p,theme:h,onStylesheetsLoad:_t,noIframe:et},t.createElement("div",{className:"userflowjs-bubble-frame-root",dir:gt,ref:t=>{rt&&rt(t),Mt(t)},style:C?{backgroundImage:`url("${encodeURI(C)}")`}:void 0},st,f.flowBranding&&t.createElement("div",{className:"userflowjs-bubble-made-with-userflow"},t.createElement("div",{className:"userflowjs-bubble-made-with-userflow__absolute"},t.createElement(pt,{company:f},t.createElement(a,null),t.createElement("div",null,"Made with Userflow"))))))),t.createElement("div",{ref:Lt,className:"userflowjs-bubble__avatar-notch"})),t.createElement(o,{className:m({"userflowjs-bubble__avatar":!0,"userflowjs-bubble__avatar--minimizable":!!at,"userflowjs-bubble__avatar--speaking":!!tt}),elRef:yt,stylesheetUrl:P,theme:h,onStylesheetsLoad:Ct,noIframe:et,ariaHidden:!0},t.createElement("div",{className:m({"userflowjs-avatar-frame-root":!0,"userflowjs-avatar-frame-root--minimizable":!!at}),onClick:at?()=>Ut((t=>!t)):void 0},t.createElement(W,{theme:h}))),t.createElement("div",{ref:kt,className:"userflowjs-bubble__tooltip-notch"})),t.createElement("div",{ref:jt,className:"userflowjs-tooltip-backdrop",onMouseDown:Qt,style:{zIndex:bt,pointerEvents:K?void 0:"none"}}),t.createElement("div",{ref:Rt,className:"userflowjs-tooltip-block",onMouseDown:Qt,style:{zIndex:bt}}),t.createElement("div",{ref:Bt,className:"userflowjs-tooltip-block",onMouseDown:Qt,style:{zIndex:bt}}),t.createElement("div",{ref:Ot,className:"userflowjs-tooltip-block",onMouseDown:Qt,style:{zIndex:bt}}),t.createElement("div",{ref:Pt,className:"userflowjs-tooltip-block",onMouseDown:Qt,style:{zIndex:bt}}),t.createElement("div",{ref:xt,className:"userflowjs-modal-backdrop",onMouseDown:Qt,onClick:Q,style:{zIndex:bt}}),nt&&nt({visible:zt,bubbleFrame:Et.current}))},W=({theme:e})=>{const o="https://js.userflow.com/cartoon-avatars-no-bg/";let a;return a=e.avatarType===i.ASSET&&e.avatarAsset?e.avatarAsset.assetUrl:e.avatarType===i.CARTOON&&e.avatarName?o+e.avatarName+".svg?3":e.avatarType===i.URL&&e.avatarUrl?e.avatarUrl:o+"none.svg",t.createElement("img",{src:a,alt:""})},z=({company:e,children:o})=>t.createElement("a",{href:"https://userflow.com/?utm_source=made-with-userflow&utm_medium=link&utm_campaign=made-with-userflow-"+e.slug,target:"_blank",rel:"noopener noreferrer"},o);function V(t,e,o){null==o?t.style.removeProperty(e):t.style.setProperty(e,"number"==typeof o?o+"px":o,"important")}function G(t,e,o){e=Math.round(e),o=Math.round(o),t.style.transform=`translate3d(${e}px, ${o}px, 0px)`}function $(t){const e=parseInt(t,10);return isNaN(e)?0:e}export{A as F,H as r,U as u};
@@ -12,7 +12,7 @@
12
12
  background-color: var(--userflow-checklist-launcher-background-color);
13
13
  color: var(--userflow-checklist-launcher-font-color);
14
14
  font-weight: var(--userflow-checklist-launcher-font-weight);
15
- line-height: var(--userflow-line-height, 24px);
15
+ line-height: 24px;
16
16
  border: 1px solid var(--userflow-checklist-launcher-border-color);
17
17
  border-radius: var(--userflow-checklist-launcher-border-radius);
18
18
  }
@@ -1 +1 @@
1
- import{F as e,d as t,c as n,t as o,a as r,b as s,e as i,g as l,o as c,u as a,f as u}from"./userflow.js";import{i as f,a as d,b as m,p,c as h,s as w}from"./vendor.date-fns.js";class v extends Error{constructor(e,t){const n=`Unreachable case: ${e}`;super(t=t?`${t} (${n})`:n)}}const E=/(\\*)\{\{([a-zA-Z0-9_.]+)\}\}/g;function g(e){let t=null;return n=>(t||(t=new Map,e.forEach((({name:e,value:n})=>t.set(e,Array.isArray(n)?n[0]:n)))),t.get(n)||null)}function y(e,t){const n=g(t);return function(e,t){return(e||"").replace(E,((e,n,o)=>{const r=n.length;return r%2==0?"\\".repeat(r/2)+(t(o)||""):"\\".repeat((r-1)/2)+"{{"+o+"}}"}))}(e,(e=>n(e)))}function b(e,t){const n=T(e,t),o=e.nearSelector&&T(e.nearSelector,t);return e===n&&e.nearSelector===o?e:e.nearSelector===o?n:{...n,nearSelector:o}}function T(e,t){if(!e.text)return e;const n=y(e.text,t);return n===e.text?e:{...e,text:n}}function S(e){const t=function(e){const t=e.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);if(!t)return null;const[,,n,o,r,,s,i]=t;return{scheme:n||"",domain:o||"",path:r||"",query:s||"",fragment:i||""}}(e);if(!t)return console.error("Userflow: Invalid URL pattern:",e),null;const{scheme:n,domain:o,path:r,query:s,fragment:i}=t;let l,c;l=n?N(n):"[a-z\\d]+",c=o?A(o,"[^/]","."):"[^/]*";let a,u,f;a=r?A(r,"[^?#]","/"):"/[^?#]*",s?(u="",new URLSearchParams(s).forEach(((e,t)=>{let n;n=""===e?"=?":"*"===e?"(=[^&#]*)?":"="+A(e,"[^#]"),u+="(?=.*[?&]"+N(t)+n+"([&#]|$))"})),u+="\\?[^#]*"):u="(\\?[^#]*)?",f=i?A(i,".","/"):"(#.*)?";return new RegExp("^"+l+"://"+c+"(:\\d+)?"+a+u+f+"$")}function A(e,t,n){return e=(e=N(e)).replace(/\\\*/g,t+"*"),n&&(e=e.replace(/:[a-zA-Z0-9_]+/g,"[^"+n+"]+")),e}function N(e){return e.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}const L={[e.ABSOLUTE_EQ]:{compare:({condition:e,value:t})=>{const n=k(t),o=C(e.value,"00:00:00.000"),r=C(e.value,"23:59:59.999");return null!=n&&null!=o&&null!=r&&!f(n,o)&&!d(n,r)}},[e.ABSOLUTE_GT]:{compare:({condition:e,value:t})=>{const n=k(t),o=C(e.value,"23:59:59.999");return null!=n&&null!=o&&d(n,o)}},[e.ABSOLUTE_LT]:{compare:({condition:e,value:t})=>{const n=k(t),o=C(e.value,"00:00:00.000");return null!=n&&null!=o&&f(n,o)}},[e.AND]:{compare:()=>x("AND.compare")},[e.CONTAINS]:{compare:({sessionData:e,condition:t,value:n})=>!!n&&_(n).toLowerCase().includes(y(t.value||"",e).toLowerCase())},[e.EMPTY]:{compare:({value:e})=>null==e||""===e},[e.ENDS_WITH]:{compare:({sessionData:e,condition:t,value:n})=>!!n&&_(n).toLowerCase().endsWith(y(t.value||"",e).toLowerCase())},[e.EQ]:{compare:({sessionData:e,condition:t,value:n})=>y(t.value||"",e)===_(n)},[e.EXCLUDES_ALL]:{compare:({condition:e,value:t})=>{const n=new Set(I(t));return!(e.values||[]).some((e=>n.has(e)))}},[e.EXCLUDES_ANY]:{compare:({condition:e,value:t})=>{const n=new Set(I(t));return!(e.values||[]).every((e=>n.has(e)))}},[e.FALSE]:{compare:({value:e})=>"false"===_(e).toLowerCase()},[e.GT]:{compare:({condition:e,value:t})=>!!t&&!!e.value&&parseFloat(_(t))>parseFloat(e.value)},[e.INCLUDES_ALL]:{compare:({condition:e,value:t})=>{const n=new Set(I(t));return(e.values||[]).every((e=>n.has(e)))}},[e.INCLUDES_ANY]:{compare:({condition:e,value:t})=>{const n=new Set(I(t));return(e.values||[]).some((e=>n.has(e)))}},[e.LT]:{compare:({condition:e,value:t})=>!!t&&!!e.value&&parseFloat(_(t))<parseFloat(e.value)},[e.NE]:{compare:({sessionData:e,condition:t,value:n})=>y(t.value||"",e)!==_(n)},[e.NOT_CONTAINS]:{compare:({sessionData:e,condition:t,value:n})=>!n||!_(n).toLowerCase().includes(y(t.value||"",e).toLowerCase())},[e.NOT_EMPTY]:{compare:({value:e})=>null!=e&&""!==e},[e.NOT_REGEX]:{compare:({condition:e,value:t})=>!M(e,t)},[e.OR]:{compare:()=>x("OR.compare")},[e.REGEX]:{compare:({condition:e,value:t})=>M(e,t)},[e.RELATIVE_EQ]:{compare:({condition:e,value:t})=>{const n=k(t),o=D(e.value);return null!=n&&null!=o&&(!f(n,o)&&f(n,m(o,1)))}},[e.RELATIVE_GT]:{compare:({condition:e,value:t})=>{const n=k(t),o=D(e.value);return null!=n&&null!=o&&d(n,o)}},[e.RELATIVE_LT]:{compare:({condition:e,value:t})=>{const n=k(t),o=D(e.value);return null!=n&&null!=o&&f(n,o)}},[e.STARTS_WITH]:{compare:({sessionData:e,condition:t,value:n})=>!!n&&_(n).toLowerCase().startsWith(y(t.value||"",e).toLowerCase())},[e.TRUE]:{compare:({value:e})=>"true"===_(e).toLowerCase()},[e.URL]:{compare:({condition:e,value:t})=>{return!(!e.urlPattern||null==t)&&(n=e.urlPattern,o=_(t),(0!==n.includes.length||0!==n.excludes.length)&&(0===n.includes.length||n.includes.some((e=>{const t=S(e);return t&&o.match(t)})))&&!n.excludes.some((e=>{const t=S(e);return t&&o.match(t)})));var n,o}}};function x(e){throw new Error(`conditionOperators.${e} is not supported`)}function k(e){if(Array.isArray(e)&&(e=e[0]),!e)return null;e.match(/(Z|((\+|-)\d\d:\d\d))$/i)||(e+="Z");const t=p(e);return h(t)?t:null}function C(e,t){if(!e)return null;const n=p(e+="T"+t+"Z");return h(n)?n:null}function D(e){if(!e)return null;const t=parseInt(e,10);return isNaN(t)?null:w(Date.now(),t)}function M(e,t){if(!e.value)return!1;return new RegExp(e.value).test(_(t))}function _(e){return Array.isArray(e)?e[0]:null==e?"":e}function I(e){return Array.isArray(e)?e:""===e||null==e?[]:[e]}let U=window.MutationObserver;const R=window;if(R.Zone&&"function"==typeof R.Zone.__symbol__){const e=R.Zone.__symbol__("MutationObserver");e&&"string"==typeof e&&R.hasOwnProperty(e)&&"function"==typeof R[e]&&(U=R[e])}function O(e,t){const n=e.left,o=e.top,r=n+e.width,s=o+e.height,i=t.left,l=t.top;return function(e,t,n,o,r,s,i,l){const c=i<e,a=n<r,u=l<t,f=o<s;return f&&c?$(e,o,i,s):c&&u?$(e,t,i,l):u&&a?$(n,t,r,l):a&&f?$(n,o,r,s):c?e-i:a?r-n:u?t-l:f?s-o:0}(n,o,r,s,i,l,i+t.width,l+t.height)}function $(e,t,n,o){return Math.sqrt(Math.pow(n-e,2)+Math.pow(o-t,2))}function V(e){window.performance.mark&&window.performance.mark(e)}function F(e,t,n){window.performance.measure&&window.performance.measure(e,t,n)}function B(e){return q(),j(e)}let P;function j(e){return null==P&&(P=function(){const e=window.getComputedStyle(window.document.body);if(e.zoom&&"1"!==e.zoom){const t=parseFloat(e.zoom);if(!isNaN(t))return t}return 1}()),1==P?e:e/P}function q(){P=null}function W(){return("BackCompat"==document.compatMode?document.body:document.documentElement).clientWidth||window.innerWidth}function Y(){return("BackCompat"==document.compatMode?document.body:document.documentElement).clientHeight||window.innerHeight}function z(e){return e?parseFloat(e.replace(/px$/,"")):0}const G=new Set(["left","start","justify","justify-all"]);class Z{constructor(e){this.ctx=e,this.rectCache=new Map,this.isLabelLikeCache=new Map,this.hasPlaceholderCache=new Map}calcScore(e,t){const n=this.getRect(e),o=this.getRect(t),r=this.distBetween(e,t),s=Ee(t)?100:50;if(r>s)return 0;const i=this.isLabelLike(e),l=this.isCloserToOtherInput(e,t),c=window.getComputedStyle(e).textAlign||"",a=n.top+n.height<=o.top,u=Math.abs(n.left-o.left)<25&&(!c||G.has(c)),f=n.left+n.width<=o.left,d=Math.abs(n.top-o.top)<25,m=a&&u||f&&d,p=n.height>=Y()/2,h=ye(t);if(h&&n.top>=o.top+o.height)return 0;let w=1;const v=e.htmlFor;return v&&v===t.id&&(w+=Math.pow(1e3,4)),!h||p||l||(i&&m?w+=Math.pow(1e3,3):t===e&&this.hasPlaceholder(t)?w+=Math.pow(1e3,2):!i&&m&&(w+=Math.pow(1e3,1))),w+=s-r,w}getRect(e){let t=this.rectCache.get(e);return t||(t=Ne(e),this.rectCache.set(e,t)),t}isLabelLike(e){let t=this.isLabelLikeCache.get(e);if(void 0===t){const n="a, button, h1, h2, h3, h4, h5, h6, input";t=!e.closest(n)&&!e.querySelector(n),this.isLabelLikeCache.set(e,t)}return t}hasPlaceholder(e){let t=this.hasPlaceholderCache.get(e);return void 0===t&&(t=!!ue(e),this.hasPlaceholderCache.set(e,t)),t}getAllInputs(){return this.allInputs||(this.allInputs=Array.from(document.querySelectorAll(pe())).filter((e=>be(e,this.ctx)))),this.allInputs}distBetween(e,t){return Math.round(O(this.getRect(e),this.getRect(t)))}isCloserToOtherInput(e,t){let n=this.distBetween(e,t);for(let o of this.getAllInputs()){if(o===t)continue;if(this.distBetween(e,o)<n)return!0}return!1}}function X(e,n={}){const o=performance.now();let i;V("userflow:inferSelector:start"),t.groupCollapsed("inferSelector for",e,n);try{i=function(e,{elementType:n}={}){const o={minorVersion:J};let i=ye(e);const l=function(e){let t=e.parentNode;for(;t&&"BODY"!==t.tagName&&!ke(t);){if(ge(t))return t;t=t.parentNode}return null}(e);if(n!==r.INPUT||i)l&&(e=l,i=!0);else{if(!l)return t("not an input"),null;e=l,i=!0,t("use custom input parent",l)}const c=function(e){let t=[],n=e;for(;n;){let e=n.getRootNode();if(ke(e)){const{host:o}=e;t.unshift(o.tagName.toLowerCase()),n=o;continue}const o=xe(n);if(!o)break;{let e=o.tagName.toLowerCase();const r=o.getAttribute("name");r?e+=`[name="${r}"]`:o.id&&!o.id.match(/\d$/)&&(e+="#"+o.id),t.unshift(e),n=o}}if(0===t.length)return;return t}(e);let a=null;i||(a=ae(e),a&&a.length>250&&(a=null));t("text is:"+a);let u=new Map,f=new Map;const d=new Map,m=new Q(c,null,o),p=new Q(c,a,o),h=(e,n,o,r,s)=>{if(r<0)return;let i=e.get(n);i||(i=[],e.set(n,i)),i.push({css:o,offset:r,complexity:s}),t(`use css=${o}, cardinality=${n}, offset=${r}`)},w=function(e){const t=new Map;t.set(null,0);let n=e.parentNode;for(;n&&"BODY"!==n.tagName&&!ke(n);){for(const e of H(n)){if(t.has(e))continue;const n=re(document.body,e);if(n){const o=n.length;t.set(e,o)}}n=n.parentNode}const o=20;return Array.from(t.entries()).sort((([,e],[,t])=>e-t)).slice(0,o).map((([e])=>e))}(e),v=[e.tagName.toLowerCase(),...H(e)];t("shadowRootSelectors:",c),t("ancestorCssSelectors:",w),t("ownCssSelectors:",v);for(const r of v)for(const n of w){const o=n?`${n} ${r}`:r,s=n?2:1,i=m.query(o),l=Array.from(i),c=l.length;if(c>100){t(`cardinality too high css=${o}, cardinality=${c}`);continue}d.set(o,c);if(h(u,c,o,l.indexOf(e),s),a){const t=p.query(o),n=Array.from(t),r=n.indexOf(e);h(f,n.length,o,r,s)}}if(u.size>0||f.size>0){const r=e=>Array.from(e.entries()).map((([e,t])=>({cardinality:e,cssSelectors:t.sort(((e,t)=>{const n=d.get(e.css),o=d.get(t.css);return n!==o?n?o?n-o:-1:1:e.complexity!==t.complexity?t.complexity-e.complexity:e.css.localeCompare(t.css)})).map((({css:e,offset:t})=>({css:e,offset:t})))}))).sort(((e,t)=>e.cardinality-t.cardinality)),i={version:"v1",minorVersion:o.minorVersion,shadowRootSelectors:c,notextGroups:r(u),textGroups:r(f)},l={el:e,selector:{type:s.AUTO,autoData:JSON.stringify(i),text:a,elementType:n}};return t("inference result",l),l}return t("no selector inferred "),null}(e,n)}catch(l){console.error("Userflow findElement error:",l),i=null}return t("time",performance.now()-o),t.groupEnd(),V("userflow:inferSelector:end"),F("userflow:inferSelector","userflow:inferSelector:start","userflow:inferSelector:end"),i}function H(e){const t=[],r=e.tagName.toLowerCase();return n.inferenceAttributeNames.forEach((s=>{const i=e.getAttribute(s);if(!i)return;const l=n.inferenceAttributeFilters[s];if(!l||o(l,i))if("id"===s)t.push(`#${e.id}`);else{const e="name"===s||"placeholder"===s?r:"";t.push(`${e}[${s}="${i}"]`)}})),e.classList.forEach((e=>{o(n.inferenceClassNameFilters,e)&&t.push(`.${e.trim()}`)})),t}(window.userflow||{}).__inferSelector=X;class Q{constructor(e,t,n){this.shadowRootSelectors=e,this.text=t,this.ctx=n,this.isVisibleCache=new Map,this.textCache=new Map}*query(e){const n=re(document.body,e,this.shadowRootSelectors);if(t("found",n),!n)return;const{text:o}=this;for(let r=0;r<n.length;r++){const e=n[r];if(o){let n=this.textCache.get(e);if(null==n&&(n=fe(e,o),this.textCache.set(e,n)),!n){t("skip, text mismatch",e);continue}}let s=this.isVisibleCache.get(e);null==s&&(s=be(e,this.ctx),this.isVisibleCache.set(e,s)),s?(t("yield",e),yield e):t("skip, not visible",e)}}}const J=4,K=window.userflow||{};function ee(e){const n=performance.now();let o;V("userflow:findAllElements:start"),t.groupCollapsed("findAllElements",e);try{if(e.type===s.MANUAL)o=function(e){const n={minorVersion:null==e.minorVersion?1:e.minorVersion};let{css:o,text:s,elementType:i,offset:l}=e;s=s&&de(s);const c="nearSelector"in e?e.nearSelector:null;t("findAllElementsManual",e),null!=l&&null!=c&&console.warn("Userflow.js: Both selector.offset and selector.nearSelector was set; ignoring nearSelector.");let a;if(s&&!o){if(a=[],n.minorVersion>=2)for(const e of Ue())oe(e,s,a);else oe(document.body,s,a);t("els after traverseElementForText",a)}else if(o){if(n.minorVersion>=2){a=[];for(const e of Ue()){const t=re(e,o);t&&t.length>0&&a.push(...t)}}else a=Array.from(re(document.body,o)||[]);t("els after safeQueryAll",a),s&&(a=function(e,t){const n=[];for(let o=e.length-1;o>=0;o--){const r=e[o];n.some((e=>e.contains(r)))||fe(r,t)&&n.push(r)}return n.reverse()}(a,s),t("els after filterElementsByText",a))}else console.warn("Userflow.js: findAllElements() requires least one of `css` and `text` to be set."),a=[];a.length>0&&(a=a.filter((e=>be(e,n))),t("els after isVisible",a));a.length>0&&i===r.INPUT&&(a=function(e,n){const o=new Set,r=new Z(n),s=pe();for(const i of e){if(i.matches(s)){o.add(i);continue}let e=null,n=null;r.getAllInputs().forEach((o=>{const s=r.calcScore(i,o);t("input",s,o),0!==s&&(e&&n&&s<=n||(t("input is best so far"),e=o,n=s))})),e&&(t("best input was",e),o.add(e))}return Array.from(o)}(a,n),t("els after mapElementsToInputs",a));a.length>0&&(a.sort(((e,t)=>{const n=Ne(e),o=Ne(t);return n.top<o.top?-1:n.top>o.top?1:n.left-o.left})),t("els after sort",a));if(a.length>0)if(null!=l)a=a[l]?[a[l]]:[],t("els after offset",a);else if(null!=c){const e=ee(c);let n=null,o=0;for(const t of a)for(const r of e){const e=O(Ne(t),Ne(r));(!n||e<o)&&(n=t,o=e)}a=n?[n]:[],t("els after nearSelector",a)}return a}(e);else if(e.autoData){const n=JSON.parse(e.autoData);let r;if("v1"!==n.version)throw new v(n.version,"Unknown autoData version: "+n.version);r=function(e,n){const{text:o,excludeText:r,precision:s}=e,i={minorVersion:n.minorVersion||0},l=null!=o&&!r,c=l?n.textGroups:n.notextGroups,a=Math.max(1,Math.min(c.length,Math.ceil((1-parseFloat(s||"1"))*c.length))),u=new Q(n.shadowRootSelectors,l&&o||null,i);t("findElementAutoV1",{text:o,excludeText:r,precision:s,groups:c,groupCount:a});for(let f=0;f<a;f++){const e=c[f];let n=new Map,o=0,r=null;t.group(`group cardinality=${e.cardinality}`,e);try{for(let s=0;s<e.cssSelectors.length;s++){const{css:i,offset:l}=e.cssSelectors[s];t(`css=${i}, offset=${l}`);let c=u.query(i),a=null;for(let e=0;e<=l;e++){const e=c.next();if(e.done)break;a=e.value}if(!a)continue;const f=(n.get(a)||0)+1;if(n.set(a,f),t(`el with frequency=${f}`+(f>o&&a!==r?" NEW BEST":""),a),f>o&&(o=f,r=a,f>=Math.ceil(e.cssSelectors.length/2)))return t("early winner",r),r}}finally{t.groupEnd()}if(r)return t("winner",r),r}return t("element not found"),null}(e,n),o=r?[r]:[]}else o=[]}catch(i){console.error("Userflow findElement error:",i),o=[]}return t("time",performance.now()-n),t.groupEnd(),V("userflow:findAllElements:end"),F("userflow:findAllElements","userflow:findAllElements:start","userflow:findAllElements:end"),o}function te(e){return ee(e)[0]||null}function ne(e,n){const o=performance.now();let r;V("userflow:elementMatchesSelector:start"),t.groupCollapsed("elementMatchesSelector",e,n);try{if(n.type===s.MANUAL)r=function(e,t){null!=t.offset&&console.warn("Userflow.js: selector.offset is not supported for elementMatchesSelector yet");"nearSelector"in t&&null!=t.nearSelector&&console.warn("Userflow.js: selector.nearSelector is not supported for elementMatchesSelector yet");let{css:n,text:o}=t;o=o&&de(o);let r=!1,s=e;for(;s&&"BODY"!==s.tagName;){if((!n||s.matches(n))&&(!o||fe(s,o))){r=!0;break}s=s.parentElement}return r}(e,n);else{const t=te(n);r=null!=t&&t.contains(e)}}catch(i){console.error("Userflow findElement error:",i),r=!1}return t(r?"match":"not match"),t("time",performance.now()-o),t.groupEnd(),V("userflow:elementMatchesSelector:end"),F("userflow:elementMatchesSelector","userflow:elementMatchesSelector:start","userflow:elementMatchesSelector:end"),r}function oe(e,t,n){if(Ce(e)){const{tagName:t}=e;if("SCRIPT"===t||"STYLE"===t)return!1}let o=!1;for(let r=0;r<e.children.length;r++)oe(e.children[r],t,n)&&(o=!0);return!o&&Ce(e)&&fe(e,t)&&(n.push(e),o=!0),o}function re(e,t,n){try{if(null==n)return e.querySelectorAll(t);return se(t,n,0,e)}catch(o){return console.warn("Userflow.js: Invalid CSS selector: ",t),null}}function se(e,t,n,o){if(n>=t.length)return Array.from(o.querySelectorAll(e));const r=t[n],s=o.querySelectorAll(r),i=[];return s.forEach((o=>{let r;if(o.shadowRoot)r=o.shadowRoot;else{if(!De(o))return;let e=null;try{e=o.contentDocument}catch(s){}if(!e)return;r=e.body}i.push(...se(e,t,n+1,r))})),i}const ie={email:!0,number:!0,password:!0,search:!0,tel:!0,text:!0,url:!0},le={date:!0,"datetime-local":!0,month:!0,time:!0,week:!0},ce={button:!0,email:!0,reset:!0,search:!0,submit:!0,tel:!0,text:!0,url:!0};function ae(e){let t=e.innerText;return void 0===t&&"SELECT"!==e.tagName&&(t=e.textContent),t=de(t),t||null}function ue(e){if(he(e)||we(e)){const t=de(e.getAttribute("placeholder")),n=e.value||"";if(t&&!n)return t;const o=de(n);if(o&&function(e){if(we(e))return!0;const t=(e.getAttribute("type")||"").toLowerCase();return ce[t]}(e))return o}if(ve(e)&&e.selectedIndex>=0){const t=de(e.options[e.selectedIndex].text);if(t)return t}return ae(e)}function fe(e,t){const n=ue(e);return!!n&&function(e,t){const n=e.toLowerCase();if(t.toLowerCase()===n)return!0;return!1}(t,n)}function de(e){return e?e.length>250?null:e.replace(/^[\s\uFEFF\xA0*]+|[\s\uFEFF\xA0*]+$/g,"").replace(/\s+/g," "):null}function me(e){for(const{cssSelector:o,getValue:r}of n.customInputs)if(e.matches(o)){if(!r)return ue(e)||"";try{return(r(e)||"").trim()}catch(t){return console.error(`Userflow.js: getValue function for custom input '${o}' failed:`,t),""}}return ve(e)?-1==e.selectedIndex?"":e.options[e.selectedIndex].text:Ee(e)?ue(e)||"":e.value}function pe(){return"input, select, textarea, [contenteditable]"+n.customInputs.map((({cssSelector:e})=>`, ${e}`)).join("")}function he(e){if("INPUT"!==e.tagName)return!1;const t=e.getAttribute("type");return null==t||!0===ie[(t||"").toLowerCase()]}function we(e){return"TEXTAREA"===e.tagName}function ve(e){return"SELECT"===e.tagName}function Ee(e){return"hasAttribute"in e&&e.hasAttribute("contenteditable")}function ge(e){return!!Ee(e)||!!n.customInputs.some((({cssSelector:t})=>e.matches(t)))}function ye(e){return he(e)||function(e){if("INPUT"!==e.tagName)return!1;const t=(e.getAttribute("type")||"").toLowerCase();return!0===le[t]}(e)||we(e)||ve(e)||ge(e)}function be(e,n){const o=Ne(e);let r=e,s=!0,i=!1,l=!1,c=!1,a=!1;for(;r;){const u=r===document.body,f="BODY"===r.tagName,d=window.getComputedStyle(r);let m=null;if(s){if(d.visibility&&"visible"!==d.visibility)return t("not visible because visibility is",d.visibility,e,{cur:r}),!1;s=!1}if("none"===d.display)return t("not visible because display is",d.display,e,{cur:r}),!1;if(null!=d.opacity&&parseFloat(d.opacity)<.01)return t("not visible because opacity is",d.opacity,e,{cur:r}),!1;if("absolute"===d.position?c=!0:"relative"!==d.position&&"fixed"!==d.position&&"sticky"!==d.position||(c=!1),n.minorVersion>=4&&!i&&!f&&(!a||"static"!==d.position)&&(Te(d.overflowX)||Te(d.overflowY))&&(m=m||Ne(r),0===m.width||0===m.height))return t("not visible because width/height (v1.4 check) is",m.width,m.height,e,{cur:r}),!1;if(!l&&Se(d.display)&&(n.minorVersion<1||f||"static"!==d.position)){const n=f||Te(d.overflow),s=n||Te(d.overflowX),i=n||Te(d.overflowY),{scrollLeft:a,scrollTop:u}=f?r.ownerDocument.documentElement:r,p=!f&&!c;if(s){if(m=m||Ne(r),p&&0===m.width)return t("not visible because width is",m.width,e,{cur:r}),!1;const n=Math.round(m.left-a);if(Math.round(o.left)<n)return t("not visible because it's clipped left",e,{left:n,cur:r}),!1}if(i){if(m=m||Ne(r),p&&0===m.height)return t("not visible because height is",m.height,e,{cur:r}),!1;const n=Math.round(m.top-u);if(Math.round(o.top)<n)return t("not visible because it's clipped top",e,{top:n,cur:r}),!1}(s||i)&&(l=!0)}if("fixed"===d.position&&(i=!0,l=!0),n.minorVersion>=3&&(r.scrollTop>0||r.scrollLeft>0)&&(l=!0),u)break;f?(r=xe(r),s=!0):r=r.parentElement,a=c}return!0}function Te(e){return"hidden"===e||"clip"===e||"scroll"===e||"auto"===e}function Se(e){return!e||!e.includes("inline")&&"contents"!==e}function Ae(e){let t=e.parentNode,n=!1;for(;t&&"BODY"!==t.tagName;){ke(t)&&(t=t.host);const o=window.getComputedStyle(t);if("absolute"===o.position?n=!0:"relative"!==o.position&&"fixed"!==o.position&&"sticky"!==o.position||(n=!1),!n&&Se(o.display)&&(Te(o.overflow)||Te(o.overflowY)))return t;if("fixed"===o.position)return e.ownerDocument.documentElement;t=t.parentNode}return e.ownerDocument.documentElement}function Ne(e){if("HTML"===e.tagName){const t=xe(e);if(t)return Ne(t)}let t=e.getBoundingClientRect(),n=e;for(;n&&(n=xe(n),n);){const e=n.getBoundingClientRect();t={width:t.width,height:t.height,left:t.left+e.left,right:t.right+e.left,top:t.top+e.top,bottom:t.bottom+e.top}}return t}const Le=new WeakSet;function xe(e){const t=e.ownerDocument?.defaultView;if(!t)return null;if(Le.has(t))return null;{const e=t.frameElement;return e||Le.add(t),e}}function ke(e){return"object"==typeof e&&null!=e&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e&&"mode"in e}function Ce(e){return"object"==typeof e&&null!=e&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function De(e){return Ce(e)&&"IFRAME"===e.tagName}K.__findElement=te,K.__findAllElements=ee,K.__elementMatchesSelector=ne,K.__getElementText=ue,K.__getInputValue=me;const Me=new Set,_e=new Map,Ie=new Set;function Ue(){return $e(),Me}function Re(e,t){$e();for(const o of Me)e(o);const n={setup:e,teardown:t};return Ie.add(n),()=>{Ie.delete(n);for(const e of Me)t(e)}}let Oe=!1;function $e(){Ve(),Oe||(t("roots started"),Oe=!0,Be(document.body),window.setInterval(Ve,1e4))}function Ve(){for(const e of Me)ke(e)&&(Fe(e)||(t("roots clean before removeRoot",e),Pe(e)));t("roots clean finished, remaining=",Me.size)}function Fe(e){if(!e.ownerDocument.defaultView)return!1;let t=e.host;for(;t;){if(ke(t)&&(t=t.host),Ce(t)&&"BODY"===t.tagName)return!0;t=t.parentNode}return!1}function Be(e){if(!Me.has(e)){t("roots addRoot",e),Me.add(e),function(e){let t;const n=()=>{je(e)},o=new U((()=>{window.cancelAnimationFrame(t),t=window.requestAnimationFrame(n)}));o.observe(e,{childList:!0,subtree:!0}),_e.set(e,o)}(e),je(e),function(e){const n=e.ownerDocument.defaultView;if(n.__userflowAttachShadowInstalled)return;n.__userflowAttachShadowInstalled=!0;const o=n.Element.prototype.attachShadow;null!=o&&(n.Element.prototype.attachShadow=function(e){const n=o.call(this,e);return this.shadowRoot&&(t("roots monitorShadowDom before addRoot",this,this.shadowRoot),Be(this.shadowRoot)),n})}(e),function(e){const n=e=>{e.childNodes.forEach((e=>{Ce(e)&&e.shadowRoot&&(t("roots queryShadowDom before addRoot",e,e.shadowRoot),Be(e.shadowRoot)),n(e)}))};n(e)}(e);for(const{setup:t}of Ie)t(e)}}function Pe(e){if(Me.has(e)){t("roots removeRoot",e),_e.get(e)?.disconnect(),_e.delete(e),Me.delete(e);for(const{teardown:t}of Ie)t(e)}}function je(e){const t=Ce(e)?e.ownerDocument.getElementsByTagName("iframe"):e.querySelectorAll("iframe");for(const n of t)We(n)}const qe=new WeakSet;function We(e){if(qe.has(e))return;if(e.closest("#userflow-ui"))return;e.addEventListener("load",Ye);const n=e.contentWindow,o=e.contentDocument;if(!n||!o)return void qe.add(e);const r=o.body;r&&(n.addEventListener("unload",ze),t("roots setupFrame before addRoot",e,o,r),Be(r))}function Ye(e){const t=e.target;t&&De(t)&&We(t)}function ze(e){const n=e.currentTarget.document.body;t("roots onFrameUnload before removeRoot",n),Pe(n)}function Ge(e,t={}){let n,o;const r=()=>{o=void 0,e()},s=()=>{if(window.clearTimeout(n),null==o)o=Date.now();else if(Date.now()-o>1e3)return void r();n=window.setTimeout(r,50)},i=e=>{const t=e.target;if(!t||!Ze(t))return;const n=document.getElementById("userflow-ui");n&&n.contains(t)||s()},l=new U((e=>{(function(e){const t=document.getElementById("userflow-ui");for(const n of e){const{target:e}=n;if(Ze(e)&&(t&&t.contains(e)))return!0}return!1})(e)||s()})),c=Re((e=>{l.observe(e,{attributes:!0,subtree:!0,childList:!0,characterData:!0}),e.addEventListener("animationend",i),e.addEventListener("transitionend",i),t.observeInput&&(e.addEventListener("input",s),e.addEventListener("change",s))}),(e=>{e.removeEventListener("animationend",i),e.removeEventListener("transitionend",i),t.observeInput&&(e.removeEventListener("input",s),e.removeEventListener("change",s))}));return{disconnect:()=>{window.clearTimeout(n),l.disconnect(),c()}}}function Ze(e){return e.nodeType===Node.ELEMENT_NODE}const Xe={[i.ALWAYS_TRUE]:{track:({callback:e})=>(e(!0),()=>{})},[i.ATTRIBUTE]:{track:({sessionData:e,condition:t,callback:n})=>{const o=()=>{let o=!1;if(e&&t.operator){const n=e.value.find((e=>e.name===t.attributeName)),r=n?n.value:null;o=L[t.operator].compare({sessionData:e.value,condition:t,value:r})}n(o)};o();const r=e.observe(o);return()=>{r()}}},[i.CLAUSE]:{isExpensive:e=>{for(const t of e.conditions){const e=Xe[t.type];if(e.isExpensive&&e.isExpensive(t))return!0}return!1},track:({sessionData:t,condition:n,flipBackEvents:o,callback:r})=>{let s,i,l=null;const c=n.conditions.map((e=>{const t=Xe[e.type];return{condition:e,typeDef:t,expensive:!!t.isExpensive&&t.isExpensive(e),active:!1,isTrue:null}})),a=e=>{for(const n of c){const r=!o||!n.expensive||e;r&&!n.active?(n.active=!0,n.isTrue=!1,n.untrack=n.typeDef.track({sessionData:t,condition:n.condition,flipBackEvents:o,callback:(e,t={})=>{n.isTrue=e,window.clearTimeout(s),t.immediate?u({immediate:!0}):s=window.setTimeout(u,0)}})):!r&&n.active&&(n.untrack&&n.untrack(),n.active=!1,n.isTrue=null,n.untrack=void 0)}},u=(t={})=>{if(0===c.length)return void f(!1,t);let o,r;if(n.operator===e.AND){o=!0,r=!0;for(const e of c)!1===e.isTrue?(o=!1,e.expensive||(r=!1)):!1!==o&&null===e.isTrue&&(o=null)}else{o=!1,r=!0;for(const e of c)!0===e.isTrue?(o=!0,e.expensive||(r=!1)):!0!==o&&null===e.isTrue&&(o=null)}null!==o&&o!==l&&(l=o,f(o,t)),a(r)},f=(e,t)=>{if(e&&null!=n.waitTime&&"0"!=n.waitTime){if(!i){const e=1e3*parseFloat(n.waitTime);i=window.setTimeout((()=>{r(!0,{})}),e)}}else window.clearTimeout(i),i=void 0,r(e,t)};return a(!1),u(),()=>{window.clearTimeout(s),window.clearTimeout(i);for(const e of c)e.untrack&&e.untrack()}}},[i.ELEMENT]:{isExpensive:()=>!0,track:e=>{const{elementState:t}=e.condition;if(!t)return()=>{};const n=function(e){switch(e){case u.CLICK:return{kind:"event",eventName:"click",valueWhenOccurred:!0};case u.DISABLED:return{kind:"observer",checkElement:e=>!!e&&e.disabled};case u.MOUSEDOWN:return{kind:"event",eventName:"mousedown",valueWhenOccurred:!0};case u.NOT_CLICK:return{kind:"event",eventName:"click",valueWhenOccurred:!1};case u.NOT_DISABLED:return{kind:"observer",checkElement:e=>!!e&&!e.disabled};case u.NOT_PRESENT:return{kind:"observer",checkElement:e=>!e};case u.PRESENT:return{kind:"observer",checkElement:e=>!!e}}}(t);switch(n.kind){case"observer":return function({sessionData:e,condition:t,callback:n},o){const r=()=>{if(!t.elementState)return void console.warn("Userflow.js: ELEMENT_STATE condition missing elementState",t);if(!t.selector)return void console.warn("Userflow.js: ELEMENT_STATE condition missing selector",t);let r=!1;const s=ee(b(t.selector,e.value));if(s.length>0){for(const e of s)if(o(e)){r=!0;break}}else o(null)&&(r=!0);n(r)};r();const s=e.observe(r),{disconnect:i}=Ge(r);return()=>{s(),i()}}(e,n.checkElement);case"event":return function({condition:e,flipBackEvents:t,callback:n},o,r){const{selector:s}=e;if(!s)return()=>{};let i;n(!r);const l=e=>{const o=e.target;o&&ne(o,s)&&(t?(n(r,{immediate:!0}),n(!r,{immediate:!0})):n(r))},c={capture:!0},a=Re((e=>e.addEventListener(o,l,c)),(e=>e.removeEventListener(o,l,c)));return()=>{a(),window.clearTimeout(i)}}(e,n.eventName,n.valueWhenOccurred)}}},[i.FILLED_IN_INPUT]:{isExpensive:()=>!0,track:({sessionData:e,condition:t,callback:n})=>{let o,r=null;const s=()=>{if(!t.selector)return void console.warn("Userflow.js: INPUT_VALUE condition missing selector",t);const s=ee(b(t.selector,e.value));let i=null;for(const e of s){const t=me(e);if(t){i=t;break}}i?i!=r&&(window.clearTimeout(o),o=window.setTimeout((()=>{n(!0)}),1e3)):(n(!1),window.clearTimeout(o)),r=i};s();const i=e.observe(s),{disconnect:l}=Ge(s,{observeInput:!0});return()=>{i(),l(),window.clearTimeout(o)}}},[i.FLOW]:{track:()=>(console.warn("Userflow.js: Flow conditions do not work client-side"),()=>{})},[i.INPUT_VALUE]:{isExpensive:()=>!0,track:({sessionData:e,condition:t,callback:n})=>{const o=()=>{if(!t.operator)return void console.warn("Userflow.js: INPUT_VALUE condition missing operator",t);if(!t.selector)return void console.warn("Userflow.js: INPUT_VALUE condition missing selector",t);let o=!1;const r=L[t.operator],s=ee(b(t.selector,e.value));if(s.length>0)for(const n of s){const s=me(n);if(r.compare({sessionData:e.value,condition:t,value:s})){o=!0;break}}else r.compare({sessionData:e.value,condition:t,value:""})&&(o=!0);n(o)};o();const r=e.observe(o),{disconnect:s}=Ge(o,{observeInput:!0});return()=>{r(),s()}}},[i.PAGE]:{track:({sessionData:e,condition:t,callback:n})=>{const o=()=>{let o=!1;if(t.operator){const n=l();o=L[t.operator].compare({sessionData:e.value,condition:t,value:n})}n(o)};let r=l();const s=()=>{const e=l();e!==r&&(r=e,o())};c(s),o();const i=e.observe(o);return()=>{i(),a(s)}}},[i.TIME]:{track:({condition:e,callback:t})=>{let n=null;const o=e.value?new Date(e.value):null,r=e.value2?new Date(e.value2):null,s=()=>{let e=!0;(o&&!isNaN(o.valueOf())&&Date.now()<o.valueOf()||r&&!isNaN(r.valueOf())&&Date.now()>=r.valueOf())&&(e=!1),e!==n&&(n=e,t(e))};s();const i=window.setInterval(s,1e4);return()=>{window.clearInterval(i)}}}};var He=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",conditionTypes:Xe});export{U as M,g as a,W as b,Xe as c,j as d,ke as e,q as f,Y as g,Ce as h,y as i,xe as j,X as k,z as l,b as m,Ge as n,Re as o,te as p,Ae as q,Ne as r,De as s,He as t,B as z};
1
+ import{F as e,d as t,c as n,t as o,a as r,b as s,e as i,g as l,o as c,u as a,f as u}from"./userflow.js";import{i as f,a as d,b as m,p,c as h,s as w}from"./vendor.date-fns.js";class v extends Error{constructor(e,t){const n=`Unreachable case: ${e}`;super(t=t?`${t} (${n})`:n)}}const E=/(\\*)\{\{([a-zA-Z0-9_.]+)\}\}/g;function g(e,t){return(e||"").replace(E,((e,n,o)=>{const r=n.length;return r%2==0?"\\".repeat(r/2)+(t(o)||""):"\\".repeat((r-1)/2)+"{{"+o+"}}"}))}function y(e){let t=null;return n=>(t||(t=new Map,e.forEach((({name:e,value:n})=>t.set(e,Array.isArray(n)?n[0]:n)))),t.get(n)||null)}function b(e,t){const n=y(t);return g(e,(e=>n(e)))}function T(e,t){const n=S(e,t),o=e.nearSelector&&S(e.nearSelector,t);return e===n&&e.nearSelector===o?e:e.nearSelector===o?n:{...n,nearSelector:o}}function S(e,t){if(!e.text)return e;const n=b(e.text,t);return n===e.text?e:{...e,text:n}}function A(e){const t=function(e){const t=e.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);if(!t)return null;const[,,n,o,r,,s,i]=t;return{scheme:n||"",domain:o||"",path:r||"",query:s||"",fragment:i||""}}(e);if(!t)return console.error("Userflow: Invalid URL pattern:",e),null;const{scheme:n,domain:o,path:r,query:s,fragment:i}=t;let l,c;l=n?L(n):"[a-z\\d]+",c=o?N(o,"[^/]","."):"[^/]*";let a,u,f;a=r?N(r,"[^?#]","/"):"/[^?#]*",s?(u="",new URLSearchParams(s).forEach(((e,t)=>{let n;n=""===e?"=?":"*"===e?"(=[^&#]*)?":"="+N(e,"[^#]"),u+="(?=.*[?&]"+L(t)+n+"([&#]|$))"})),u+="\\?[^#]*"):u="(\\?[^#]*)?",f=i?N(i,".","/"):"(#.*)?";return new RegExp("^"+l+"://"+c+"(:\\d+)?"+a+u+f+"$")}function N(e,t,n){return e=(e=L(e)).replace(/\\\*/g,t+"*"),n&&(e=e.replace(/:[a-zA-Z0-9_]+/g,"[^"+n+"]+")),e}function L(e){return e.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}const x={[e.ABSOLUTE_EQ]:{compare:({condition:e,value:t})=>{const n=C(t),o=D(e.value,"00:00:00.000"),r=D(e.value,"23:59:59.999");return null!=n&&null!=o&&null!=r&&!f(n,o)&&!d(n,r)}},[e.ABSOLUTE_GT]:{compare:({condition:e,value:t})=>{const n=C(t),o=D(e.value,"23:59:59.999");return null!=n&&null!=o&&d(n,o)}},[e.ABSOLUTE_LT]:{compare:({condition:e,value:t})=>{const n=C(t),o=D(e.value,"00:00:00.000");return null!=n&&null!=o&&f(n,o)}},[e.AND]:{compare:()=>k("AND.compare")},[e.CONTAINS]:{compare:({sessionData:e,condition:t,value:n})=>!!n&&I(n).toLowerCase().includes(b(t.value||"",e).toLowerCase())},[e.EMPTY]:{compare:({value:e})=>null==e||""===e},[e.ENDS_WITH]:{compare:({sessionData:e,condition:t,value:n})=>!!n&&I(n).toLowerCase().endsWith(b(t.value||"",e).toLowerCase())},[e.EQ]:{compare:({sessionData:e,condition:t,value:n})=>b(t.value||"",e)===I(n)},[e.EXCLUDES_ALL]:{compare:({condition:e,value:t})=>{const n=new Set(U(t));return!(e.values||[]).some((e=>n.has(e)))}},[e.EXCLUDES_ANY]:{compare:({condition:e,value:t})=>{const n=new Set(U(t));return!(e.values||[]).every((e=>n.has(e)))}},[e.FALSE]:{compare:({value:e})=>"false"===I(e).toLowerCase()},[e.GT]:{compare:({condition:e,value:t})=>!!t&&!!e.value&&parseFloat(I(t))>parseFloat(e.value)},[e.INCLUDES_ALL]:{compare:({condition:e,value:t})=>{const n=new Set(U(t));return(e.values||[]).every((e=>n.has(e)))}},[e.INCLUDES_ANY]:{compare:({condition:e,value:t})=>{const n=new Set(U(t));return(e.values||[]).some((e=>n.has(e)))}},[e.LT]:{compare:({condition:e,value:t})=>!!t&&!!e.value&&parseFloat(I(t))<parseFloat(e.value)},[e.NE]:{compare:({sessionData:e,condition:t,value:n})=>b(t.value||"",e)!==I(n)},[e.NOT_CONTAINS]:{compare:({sessionData:e,condition:t,value:n})=>!n||!I(n).toLowerCase().includes(b(t.value||"",e).toLowerCase())},[e.NOT_EMPTY]:{compare:({value:e})=>null!=e&&""!==e},[e.NOT_REGEX]:{compare:({condition:e,value:t})=>!_(e,t)},[e.OR]:{compare:()=>k("OR.compare")},[e.REGEX]:{compare:({condition:e,value:t})=>_(e,t)},[e.RELATIVE_EQ]:{compare:({condition:e,value:t})=>{const n=C(t),o=M(e.value);return null!=n&&null!=o&&(!f(n,o)&&f(n,m(o,1)))}},[e.RELATIVE_GT]:{compare:({condition:e,value:t})=>{const n=C(t),o=M(e.value);return null!=n&&null!=o&&d(n,o)}},[e.RELATIVE_LT]:{compare:({condition:e,value:t})=>{const n=C(t),o=M(e.value);return null!=n&&null!=o&&f(n,o)}},[e.STARTS_WITH]:{compare:({sessionData:e,condition:t,value:n})=>!!n&&I(n).toLowerCase().startsWith(b(t.value||"",e).toLowerCase())},[e.TRUE]:{compare:({value:e})=>"true"===I(e).toLowerCase()},[e.URL]:{compare:({condition:e,value:t})=>{return!(!e.urlPattern||null==t)&&(n=e.urlPattern,o=I(t),(0!==n.includes.length||0!==n.excludes.length)&&(0===n.includes.length||n.includes.some((e=>{const t=A(e);return t&&o.match(t)})))&&!n.excludes.some((e=>{const t=A(e);return t&&o.match(t)})));var n,o}}};function k(e){throw new Error(`conditionOperators.${e} is not supported`)}function C(e){if(Array.isArray(e)&&(e=e[0]),!e)return null;e.match(/(Z|((\+|-)\d\d:\d\d))$/i)||(e+="Z");const t=p(e);return h(t)?t:null}function D(e,t){if(!e)return null;const n=p(e+="T"+t+"Z");return h(n)?n:null}function M(e){if(!e)return null;const t=parseInt(e,10);return isNaN(t)?null:w(Date.now(),t)}function _(e,t){if(!e.value)return!1;return new RegExp(e.value).test(I(t))}function I(e){return Array.isArray(e)?e[0]:null==e?"":e}function U(e){return Array.isArray(e)?e:""===e||null==e?[]:[e]}let R=window.MutationObserver;const O=window;if(O.Zone&&"function"==typeof O.Zone.__symbol__){const e=O.Zone.__symbol__("MutationObserver");e&&"string"==typeof e&&O.hasOwnProperty(e)&&"function"==typeof O[e]&&(R=O[e])}function $(e,t){const n=e.left,o=e.top,r=n+e.width,s=o+e.height,i=t.left,l=t.top;return function(e,t,n,o,r,s,i,l){const c=i<e,a=n<r,u=l<t,f=o<s;return f&&c?V(e,o,i,s):c&&u?V(e,t,i,l):u&&a?V(n,t,r,l):a&&f?V(n,o,r,s):c?e-i:a?r-n:u?t-l:f?s-o:0}(n,o,r,s,i,l,i+t.width,l+t.height)}function V(e,t,n,o){return Math.sqrt(Math.pow(n-e,2)+Math.pow(o-t,2))}function F(e){window.performance.mark&&window.performance.mark(e)}function B(e,t,n){window.performance.measure&&window.performance.measure(e,t,n)}function P(e){return W(),q(e)}let j;function q(e){return null==j&&(j=function(){const e=window.getComputedStyle(window.document.body);if(e.zoom&&"1"!==e.zoom){const t=parseFloat(e.zoom);if(!isNaN(t))return t}return 1}()),1==j?e:e/j}function W(){j=null}function Y(){return("BackCompat"==document.compatMode?document.body:document.documentElement).clientWidth||window.innerWidth}function z(){return("BackCompat"==document.compatMode?document.body:document.documentElement).clientHeight||window.innerHeight}function G(e){return e?parseFloat(e.replace(/px$/,"")):0}const Z=new Set(["left","start","justify","justify-all"]);class X{constructor(e){this.ctx=e,this.rectCache=new Map,this.isLabelLikeCache=new Map,this.hasPlaceholderCache=new Map}calcScore(e,t){const n=this.getRect(e),o=this.getRect(t),r=this.distBetween(e,t),s=ge(t)?100:50;if(r>s)return 0;const i=this.isLabelLike(e),l=this.isCloserToOtherInput(e,t),c=window.getComputedStyle(e).textAlign||"",a=n.top+n.height<=o.top,u=Math.abs(n.left-o.left)<25&&(!c||Z.has(c)),f=n.left+n.width<=o.left,d=Math.abs(n.top-o.top)<25,m=a&&u||f&&d,p=n.height>=z()/2,h=be(t);if(h&&n.top>=o.top+o.height)return 0;let w=1;const v=e.htmlFor;return v&&v===t.id&&(w+=Math.pow(1e3,4)),!h||p||l||(i&&m?w+=Math.pow(1e3,3):t===e&&this.hasPlaceholder(t)?w+=Math.pow(1e3,2):!i&&m&&(w+=Math.pow(1e3,1))),w+=s-r,w}getRect(e){let t=this.rectCache.get(e);return t||(t=Le(e),this.rectCache.set(e,t)),t}isLabelLike(e){let t=this.isLabelLikeCache.get(e);if(void 0===t){const n="a, button, h1, h2, h3, h4, h5, h6, input";t=!e.closest(n)&&!e.querySelector(n),this.isLabelLikeCache.set(e,t)}return t}hasPlaceholder(e){let t=this.hasPlaceholderCache.get(e);return void 0===t&&(t=!!fe(e),this.hasPlaceholderCache.set(e,t)),t}getAllInputs(){return this.allInputs||(this.allInputs=Array.from(document.querySelectorAll(he())).filter((e=>Te(e,this.ctx)))),this.allInputs}distBetween(e,t){return Math.round($(this.getRect(e),this.getRect(t)))}isCloserToOtherInput(e,t){let n=this.distBetween(e,t);for(let o of this.getAllInputs()){if(o===t)continue;if(this.distBetween(e,o)<n)return!0}return!1}}function H(e,n={}){const o=performance.now();let i;F("userflow:inferSelector:start"),t.groupCollapsed("inferSelector for",e,n);try{i=function(e,{elementType:n}={}){const o={minorVersion:K};let i=be(e);const l=function(e){let t=e.parentNode;for(;t&&"BODY"!==t.tagName&&!Ce(t);){if(ye(t))return t;t=t.parentNode}return null}(e);if(n!==r.INPUT||i)l&&(e=l,i=!0);else{if(!l)return t("not an input"),null;e=l,i=!0,t("use custom input parent",l)}const c=function(e){let t=[],n=e;for(;n;){let e=n.getRootNode();if(Ce(e)){const{host:o}=e;t.unshift(o.tagName.toLowerCase()),n=o;continue}const o=ke(n);if(!o)break;{let e=o.tagName.toLowerCase();const r=o.getAttribute("name");r?e+=`[name="${r}"]`:o.id&&!o.id.match(/\d$/)&&(e+="#"+o.id),t.unshift(e),n=o}}if(0===t.length)return;return t}(e);let a=null;i||(a=ue(e),a&&a.length>250&&(a=null));t("text is:"+a);let u=new Map,f=new Map;const d=new Map,m=new J(c,null,o),p=new J(c,a,o),h=(e,n,o,r,s)=>{if(r<0)return;let i=e.get(n);i||(i=[],e.set(n,i)),i.push({css:o,offset:r,complexity:s}),t(`use css=${o}, cardinality=${n}, offset=${r}`)},w=function(e){const t=new Map;t.set(null,0);let n=e.parentNode;for(;n&&"BODY"!==n.tagName&&!Ce(n);){for(const e of Q(n)){if(t.has(e))continue;const n=se(document.body,e);if(n){const o=n.length;t.set(e,o)}}n=n.parentNode}const o=20;return Array.from(t.entries()).sort((([,e],[,t])=>e-t)).slice(0,o).map((([e])=>e))}(e),v=[e.tagName.toLowerCase(),...Q(e)];t("shadowRootSelectors:",c),t("ancestorCssSelectors:",w),t("ownCssSelectors:",v);for(const r of v)for(const n of w){const o=n?`${n} ${r}`:r,s=n?2:1,i=m.query(o),l=Array.from(i),c=l.length;if(c>100){t(`cardinality too high css=${o}, cardinality=${c}`);continue}d.set(o,c);if(h(u,c,o,l.indexOf(e),s),a){const t=p.query(o),n=Array.from(t),r=n.indexOf(e);h(f,n.length,o,r,s)}}if(u.size>0||f.size>0){const r=e=>Array.from(e.entries()).map((([e,t])=>({cardinality:e,cssSelectors:t.sort(((e,t)=>{const n=d.get(e.css),o=d.get(t.css);return n!==o?n?o?n-o:-1:1:e.complexity!==t.complexity?t.complexity-e.complexity:e.css.localeCompare(t.css)})).map((({css:e,offset:t})=>({css:e,offset:t})))}))).sort(((e,t)=>e.cardinality-t.cardinality)),i={version:"v1",minorVersion:o.minorVersion,shadowRootSelectors:c,notextGroups:r(u),textGroups:r(f)},l={el:e,selector:{type:s.AUTO,autoData:JSON.stringify(i),text:a,elementType:n}};return t("inference result",l),l}return t("no selector inferred "),null}(e,n)}catch(l){console.error("Userflow findElement error:",l),i=null}return t("time",performance.now()-o),t.groupEnd(),F("userflow:inferSelector:end"),B("userflow:inferSelector","userflow:inferSelector:start","userflow:inferSelector:end"),i}function Q(e){const t=[],r=e.tagName.toLowerCase();return n.inferenceAttributeNames.forEach((s=>{const i=e.getAttribute(s);if(!i)return;const l=n.inferenceAttributeFilters[s];if(!l||o(l,i))if("id"===s)t.push(`#${e.id}`);else{const e="name"===s||"placeholder"===s?r:"";t.push(`${e}[${s}="${i}"]`)}})),e.classList.forEach((e=>{o(n.inferenceClassNameFilters,e)&&t.push(`.${e.trim()}`)})),t}(window.userflow||{}).__inferSelector=H;class J{constructor(e,t,n){this.shadowRootSelectors=e,this.text=t,this.ctx=n,this.isVisibleCache=new Map,this.textCache=new Map}*query(e){const n=se(document.body,e,this.shadowRootSelectors);if(t("found",n),!n)return;const{text:o}=this;for(let r=0;r<n.length;r++){const e=n[r];if(o){let n=this.textCache.get(e);if(null==n&&(n=de(e,o),this.textCache.set(e,n)),!n){t("skip, text mismatch",e);continue}}let s=this.isVisibleCache.get(e);null==s&&(s=Te(e,this.ctx),this.isVisibleCache.set(e,s)),s?(t("yield",e),yield e):t("skip, not visible",e)}}}const K=4,ee=window.userflow||{};function te(e){const n=performance.now();let o;F("userflow:findAllElements:start"),t.groupCollapsed("findAllElements",e);try{if(e.type===s.MANUAL)o=function(e){const n={minorVersion:null==e.minorVersion?1:e.minorVersion};let{css:o,text:s,elementType:i,offset:l}=e;s=s&&me(s);const c="nearSelector"in e?e.nearSelector:null;t("findAllElementsManual",e),null!=l&&null!=c&&console.warn("Userflow.js: Both selector.offset and selector.nearSelector was set; ignoring nearSelector.");let a;if(s&&!o){if(a=[],n.minorVersion>=2)for(const e of Re())re(e,s,a);else re(document.body,s,a);t("els after traverseElementForText",a)}else if(o){if(n.minorVersion>=2){a=[];for(const e of Re()){const t=se(e,o);t&&t.length>0&&a.push(...t)}}else a=Array.from(se(document.body,o)||[]);t("els after safeQueryAll",a),s&&(a=function(e,t){const n=[];for(let o=e.length-1;o>=0;o--){const r=e[o];n.some((e=>e.contains(r)))||de(r,t)&&n.push(r)}return n.reverse()}(a,s),t("els after filterElementsByText",a))}else console.warn("Userflow.js: findAllElements() requires least one of `css` and `text` to be set."),a=[];a.length>0&&(a=a.filter((e=>Te(e,n))),t("els after isVisible",a));a.length>0&&i===r.INPUT&&(a=function(e,n){const o=new Set,r=new X(n),s=he();for(const i of e){if(i.matches(s)){o.add(i);continue}let e=null,n=null;r.getAllInputs().forEach((o=>{const s=r.calcScore(i,o);t("input",s,o),0!==s&&(e&&n&&s<=n||(t("input is best so far"),e=o,n=s))})),e&&(t("best input was",e),o.add(e))}return Array.from(o)}(a,n),t("els after mapElementsToInputs",a));a.length>0&&(a.sort(((e,t)=>{const n=Le(e),o=Le(t);return n.top<o.top?-1:n.top>o.top?1:n.left-o.left})),t("els after sort",a));if(a.length>0)if(null!=l)a=a[l]?[a[l]]:[],t("els after offset",a);else if(null!=c){const e=te(c);let n=null,o=0;for(const t of a)for(const r of e){const e=$(Le(t),Le(r));(!n||e<o)&&(n=t,o=e)}a=n?[n]:[],t("els after nearSelector",a)}return a}(e);else if(e.autoData){const n=JSON.parse(e.autoData);let r;if("v1"!==n.version)throw new v(n.version,"Unknown autoData version: "+n.version);r=function(e,n){const{text:o,excludeText:r,precision:s}=e,i={minorVersion:n.minorVersion||0},l=null!=o&&!r,c=l?n.textGroups:n.notextGroups,a=Math.max(1,Math.min(c.length,Math.ceil((1-parseFloat(s||"1"))*c.length))),u=new J(n.shadowRootSelectors,l&&o||null,i);t("findElementAutoV1",{text:o,excludeText:r,precision:s,groups:c,groupCount:a});for(let f=0;f<a;f++){const e=c[f];let n=new Map,o=0,r=null;t.group(`group cardinality=${e.cardinality}`,e);try{for(let s=0;s<e.cssSelectors.length;s++){const{css:i,offset:l}=e.cssSelectors[s];t(`css=${i}, offset=${l}`);let c=u.query(i),a=null;for(let e=0;e<=l;e++){const e=c.next();if(e.done)break;a=e.value}if(!a)continue;const f=(n.get(a)||0)+1;if(n.set(a,f),t(`el with frequency=${f}`+(f>o&&a!==r?" NEW BEST":""),a),f>o&&(o=f,r=a,f>=Math.ceil(e.cssSelectors.length/2)))return t("early winner",r),r}}finally{t.groupEnd()}if(r)return t("winner",r),r}return t("element not found"),null}(e,n),o=r?[r]:[]}else o=[]}catch(i){console.error("Userflow findElement error:",i),o=[]}return t("time",performance.now()-n),t.groupEnd(),F("userflow:findAllElements:end"),B("userflow:findAllElements","userflow:findAllElements:start","userflow:findAllElements:end"),o}function ne(e){return te(e)[0]||null}function oe(e,n){const o=performance.now();let r;F("userflow:elementMatchesSelector:start"),t.groupCollapsed("elementMatchesSelector",e,n);try{if(n.type===s.MANUAL)r=function(e,t){null!=t.offset&&console.warn("Userflow.js: selector.offset is not supported for elementMatchesSelector yet");"nearSelector"in t&&null!=t.nearSelector&&console.warn("Userflow.js: selector.nearSelector is not supported for elementMatchesSelector yet");let{css:n,text:o}=t;o=o&&me(o);let r=!1,s=e;for(;s&&"BODY"!==s.tagName;){if((!n||s.matches(n))&&(!o||de(s,o))){r=!0;break}s=s.parentElement}return r}(e,n);else{const t=ne(n);r=null!=t&&t.contains(e)}}catch(i){console.error("Userflow findElement error:",i),r=!1}return t(r?"match":"not match"),t("time",performance.now()-o),t.groupEnd(),F("userflow:elementMatchesSelector:end"),B("userflow:elementMatchesSelector","userflow:elementMatchesSelector:start","userflow:elementMatchesSelector:end"),r}function re(e,t,n){if(De(e)){const{tagName:t}=e;if("SCRIPT"===t||"STYLE"===t)return!1}let o=!1;for(let r=0;r<e.children.length;r++)re(e.children[r],t,n)&&(o=!0);return!o&&De(e)&&de(e,t)&&(n.push(e),o=!0),o}function se(e,t,n){try{if(null==n)return e.querySelectorAll(t);return ie(t,n,0,e)}catch(o){return console.warn("Userflow.js: Invalid CSS selector: ",t),null}}function ie(e,t,n,o){if(n>=t.length)return Array.from(o.querySelectorAll(e));const r=t[n],s=o.querySelectorAll(r),i=[];return s.forEach((o=>{let r;if(o.shadowRoot)r=o.shadowRoot;else{if(!Me(o))return;let e=null;try{e=o.contentDocument}catch(s){}if(!e)return;r=e.body}i.push(...ie(e,t,n+1,r))})),i}const le={email:!0,number:!0,password:!0,search:!0,tel:!0,text:!0,url:!0},ce={date:!0,"datetime-local":!0,month:!0,time:!0,week:!0},ae={button:!0,email:!0,reset:!0,search:!0,submit:!0,tel:!0,text:!0,url:!0};function ue(e){let t=e.innerText;return void 0===t&&"SELECT"!==e.tagName&&(t=e.textContent),t=me(t),t||null}function fe(e){if(we(e)||ve(e)){const t=me(e.getAttribute("placeholder")),n=e.value||"";if(t&&!n)return t;const o=me(n);if(o&&function(e){if(ve(e))return!0;const t=(e.getAttribute("type")||"").toLowerCase();return ae[t]}(e))return o}if(Ee(e)&&e.selectedIndex>=0){const t=me(e.options[e.selectedIndex].text);if(t)return t}return ue(e)}function de(e,t){const n=fe(e);return!!n&&function(e,t){const n=e.toLowerCase();if(t.toLowerCase()===n)return!0;return!1}(t,n)}function me(e){return e?e.length>250?null:e.replace(/^[\s\uFEFF\xA0*]+|[\s\uFEFF\xA0*]+$/g,"").replace(/\s+/g," "):null}function pe(e){for(const{cssSelector:o,getValue:r}of n.customInputs)if(e.matches(o)){if(!r)return fe(e)||"";try{return(r(e)||"").trim()}catch(t){return console.error(`Userflow.js: getValue function for custom input '${o}' failed:`,t),""}}return Ee(e)?-1==e.selectedIndex?"":e.options[e.selectedIndex].text:ge(e)?fe(e)||"":e.value}function he(){return"input, select, textarea, [contenteditable]"+n.customInputs.map((({cssSelector:e})=>`, ${e}`)).join("")}function we(e){if("INPUT"!==e.tagName)return!1;const t=e.getAttribute("type");return null==t||!0===le[(t||"").toLowerCase()]}function ve(e){return"TEXTAREA"===e.tagName}function Ee(e){return"SELECT"===e.tagName}function ge(e){return"hasAttribute"in e&&e.hasAttribute("contenteditable")}function ye(e){return!!ge(e)||!!n.customInputs.some((({cssSelector:t})=>e.matches(t)))}function be(e){return we(e)||function(e){if("INPUT"!==e.tagName)return!1;const t=(e.getAttribute("type")||"").toLowerCase();return!0===ce[t]}(e)||ve(e)||Ee(e)||ye(e)}function Te(e,n){const o=Le(e);let r=e,s=!0,i=!1,l=!1,c=!1,a=!1;for(;r;){const u=r===document.body,f="BODY"===r.tagName,d=window.getComputedStyle(r);let m=null;if(s){if(d.visibility&&"visible"!==d.visibility)return t("not visible because visibility is",d.visibility,e,{cur:r}),!1;s=!1}if("none"===d.display)return t("not visible because display is",d.display,e,{cur:r}),!1;if(null!=d.opacity&&parseFloat(d.opacity)<.01)return t("not visible because opacity is",d.opacity,e,{cur:r}),!1;if("absolute"===d.position?c=!0:"relative"!==d.position&&"fixed"!==d.position&&"sticky"!==d.position||(c=!1),n.minorVersion>=4&&!i&&!f&&(!a||"static"!==d.position)&&(Se(d.overflowX)||Se(d.overflowY))&&(m=m||Le(r),0===m.width||0===m.height))return t("not visible because width/height (v1.4 check) is",m.width,m.height,e,{cur:r}),!1;if(!l&&Ae(d.display)&&(n.minorVersion<1||f||"static"!==d.position)){const n=f||Se(d.overflow),s=n||Se(d.overflowX),i=n||Se(d.overflowY),{scrollLeft:a,scrollTop:u}=f?r.ownerDocument.documentElement:r,p=!f&&!c;if(s){if(m=m||Le(r),p&&0===m.width)return t("not visible because width is",m.width,e,{cur:r}),!1;const n=Math.round(m.left-a);if(Math.round(o.left)<n)return t("not visible because it's clipped left",e,{left:n,cur:r}),!1}if(i){if(m=m||Le(r),p&&0===m.height)return t("not visible because height is",m.height,e,{cur:r}),!1;const n=Math.round(m.top-u);if(Math.round(o.top)<n)return t("not visible because it's clipped top",e,{top:n,cur:r}),!1}(s||i)&&(l=!0)}if("fixed"===d.position&&(i=!0,l=!0),n.minorVersion>=3&&(r.scrollTop>0||r.scrollLeft>0)&&(l=!0),u)break;f?(r=ke(r),s=!0):r=r.parentElement,a=c}return!0}function Se(e){return"hidden"===e||"clip"===e||"scroll"===e||"auto"===e}function Ae(e){return!e||!e.includes("inline")&&"contents"!==e}function Ne(e){let t=e.parentNode,n=!1;for(;t&&"BODY"!==t.tagName;){Ce(t)&&(t=t.host);const o=window.getComputedStyle(t);if("absolute"===o.position?n=!0:"relative"!==o.position&&"fixed"!==o.position&&"sticky"!==o.position||(n=!1),!n&&Ae(o.display)&&(Se(o.overflow)||Se(o.overflowY)))return t;if("fixed"===o.position)return e.ownerDocument.documentElement;t=t.parentNode}return e.ownerDocument.documentElement}function Le(e){if("HTML"===e.tagName){const t=ke(e);if(t)return Le(t)}let t=e.getBoundingClientRect(),n=e;for(;n&&(n=ke(n),n);){const e=n.getBoundingClientRect();t={width:t.width,height:t.height,left:t.left+e.left,right:t.right+e.left,top:t.top+e.top,bottom:t.bottom+e.top}}return t}const xe=new WeakSet;function ke(e){const t=e.ownerDocument?.defaultView;if(!t)return null;if(xe.has(t))return null;{const e=t.frameElement;return e||xe.add(t),e}}function Ce(e){return"object"==typeof e&&null!=e&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e&&"mode"in e}function De(e){return"object"==typeof e&&null!=e&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function Me(e){return De(e)&&"IFRAME"===e.tagName}ee.__findElement=ne,ee.__findAllElements=te,ee.__elementMatchesSelector=oe,ee.__getElementText=fe,ee.__getInputValue=pe;const _e=new Set,Ie=new Map,Ue=new Set;function Re(){return Ve(),_e}function Oe(e,t){Ve();for(const o of _e)e(o);const n={setup:e,teardown:t};return Ue.add(n),()=>{Ue.delete(n);for(const e of _e)t(e)}}let $e=!1;function Ve(){Fe(),$e||(t("roots started"),$e=!0,Pe(document.body),window.setInterval(Fe,1e4))}function Fe(){for(const e of _e)Ce(e)&&(Be(e)||(t("roots clean before removeRoot",e),je(e)));t("roots clean finished, remaining=",_e.size)}function Be(e){if(!e.ownerDocument.defaultView)return!1;let t=e.host;for(;t;){if(Ce(t)&&(t=t.host),De(t)&&"BODY"===t.tagName)return!0;t=t.parentNode}return!1}function Pe(e){if(!_e.has(e)){t("roots addRoot",e),_e.add(e),function(e){let t;const n=()=>{qe(e)},o=new R((()=>{window.cancelAnimationFrame(t),t=window.requestAnimationFrame(n)}));o.observe(e,{childList:!0,subtree:!0}),Ie.set(e,o)}(e),qe(e),function(e){const n=e.ownerDocument.defaultView;if(n.__userflowAttachShadowInstalled)return;n.__userflowAttachShadowInstalled=!0;const o=n.Element.prototype.attachShadow;null!=o&&(n.Element.prototype.attachShadow=function(e){const n=o.call(this,e);return this.shadowRoot&&(t("roots monitorShadowDom before addRoot",this,this.shadowRoot),Pe(this.shadowRoot)),n})}(e),function(e){const n=e=>{e.childNodes.forEach((e=>{De(e)&&e.shadowRoot&&(t("roots queryShadowDom before addRoot",e,e.shadowRoot),Pe(e.shadowRoot)),n(e)}))};n(e)}(e);for(const{setup:t}of Ue)t(e)}}function je(e){if(_e.has(e)){t("roots removeRoot",e),Ie.get(e)?.disconnect(),Ie.delete(e),_e.delete(e);for(const{teardown:t}of Ue)t(e)}}function qe(e){const t=De(e)?e.ownerDocument.getElementsByTagName("iframe"):e.querySelectorAll("iframe");for(const n of t)Ye(n)}const We=new WeakSet;function Ye(e){if(We.has(e))return;if(e.closest("#userflow-ui"))return;e.addEventListener("load",ze);const n=e.contentWindow,o=e.contentDocument;if(!n||!o)return void We.add(e);const r=o.body;r&&(n.addEventListener("unload",Ge),t("roots setupFrame before addRoot",e,o,r),Pe(r))}function ze(e){const t=e.target;t&&Me(t)&&Ye(t)}function Ge(e){const n=e.currentTarget.document.body;t("roots onFrameUnload before removeRoot",n),je(n)}function Ze(e,t={}){let n,o;const r=()=>{o=void 0,e()},s=()=>{if(window.clearTimeout(n),null==o)o=Date.now();else if(Date.now()-o>1e3)return void r();n=window.setTimeout(r,50)},i=e=>{const t=e.target;if(!t||!Xe(t))return;const n=document.getElementById("userflow-ui");n&&n.contains(t)||s()},l=new R((e=>{(function(e){const t=document.getElementById("userflow-ui");for(const n of e){const{target:e}=n;if(Xe(e)&&(t&&t.contains(e)))return!0}return!1})(e)||s()})),c=Oe((e=>{l.observe(e,{attributes:!0,subtree:!0,childList:!0,characterData:!0}),e.addEventListener("animationend",i),e.addEventListener("transitionend",i),t.observeInput&&(e.addEventListener("input",s),e.addEventListener("change",s))}),(e=>{e.removeEventListener("animationend",i),e.removeEventListener("transitionend",i),t.observeInput&&(e.removeEventListener("input",s),e.removeEventListener("change",s))}));return{disconnect:()=>{window.clearTimeout(n),l.disconnect(),c()}}}function Xe(e){return e.nodeType===Node.ELEMENT_NODE}const He={[i.ALWAYS_TRUE]:{track:({callback:e})=>(e(!0),()=>{})},[i.ATTRIBUTE]:{track:({sessionData:e,condition:t,callback:n})=>{const o=()=>{let o=!1;if(e&&t.operator){const n=e.value.find((e=>e.name===t.attributeName)),r=n?n.value:null;o=x[t.operator].compare({sessionData:e.value,condition:t,value:r})}n(o)};o();const r=e.observe(o);return()=>{r()}}},[i.CLAUSE]:{isExpensive:e=>{for(const t of e.conditions){const e=He[t.type];if(e.isExpensive&&e.isExpensive(t))return!0}return!1},track:({sessionData:t,condition:n,flipBackEvents:o,callback:r})=>{let s,i,l=null;const c=n.conditions.map((e=>{const t=He[e.type];return{condition:e,typeDef:t,expensive:!!t.isExpensive&&t.isExpensive(e),active:!1,isTrue:null}})),a=e=>{for(const n of c){const r=!o||!n.expensive||e;r&&!n.active?(n.active=!0,n.isTrue=!1,n.untrack=n.typeDef.track({sessionData:t,condition:n.condition,flipBackEvents:o,callback:(e,t={})=>{n.isTrue=e,window.clearTimeout(s),t.immediate?u({immediate:!0}):s=window.setTimeout(u,0)}})):!r&&n.active&&(n.untrack&&n.untrack(),n.active=!1,n.isTrue=null,n.untrack=void 0)}},u=(t={})=>{if(0===c.length)return void f(!1,t);let o,r;if(n.operator===e.AND){o=!0,r=!0;for(const e of c)!1===e.isTrue?(o=!1,e.expensive||(r=!1)):!1!==o&&null===e.isTrue&&(o=null)}else{o=!1,r=!0;for(const e of c)!0===e.isTrue?(o=!0,e.expensive||(r=!1)):!0!==o&&null===e.isTrue&&(o=null)}null!==o&&o!==l&&(l=o,f(o,t)),a(r)},f=(e,t)=>{if(e&&null!=n.waitTime&&"0"!=n.waitTime){if(!i){const e=1e3*parseFloat(n.waitTime);i=window.setTimeout((()=>{r(!0,{})}),e)}}else window.clearTimeout(i),i=void 0,r(e,t)};return a(!1),u(),()=>{window.clearTimeout(s),window.clearTimeout(i);for(const e of c)e.untrack&&e.untrack()}}},[i.ELEMENT]:{isExpensive:()=>!0,track:e=>{const{elementState:t}=e.condition;if(!t)return()=>{};const n=function(e){switch(e){case u.CLICK:return{kind:"event",eventName:"click",valueWhenOccurred:!0};case u.DISABLED:return{kind:"observer",checkElement:e=>!!e&&e.disabled};case u.MOUSEDOWN:return{kind:"event",eventName:"mousedown",valueWhenOccurred:!0};case u.NOT_CLICK:return{kind:"event",eventName:"click",valueWhenOccurred:!1};case u.NOT_DISABLED:return{kind:"observer",checkElement:e=>!!e&&!e.disabled};case u.NOT_PRESENT:return{kind:"observer",checkElement:e=>!e};case u.PRESENT:return{kind:"observer",checkElement:e=>!!e}}}(t);switch(n.kind){case"observer":return function({sessionData:e,condition:t,callback:n},o){const r=()=>{if(!t.elementState)return void console.warn("Userflow.js: ELEMENT_STATE condition missing elementState",t);if(!t.selector)return void console.warn("Userflow.js: ELEMENT_STATE condition missing selector",t);let r=!1;const s=te(T(t.selector,e.value));if(s.length>0){for(const e of s)if(o(e)){r=!0;break}}else o(null)&&(r=!0);n(r)};r();const s=e.observe(r),{disconnect:i}=Ze(r);return()=>{s(),i()}}(e,n.checkElement);case"event":return function({condition:e,flipBackEvents:t,callback:n},o,r){const{selector:s}=e;if(!s)return()=>{};let i;n(!r);const l=e=>{const o=e.target;o&&oe(o,s)&&(t?(n(r,{immediate:!0}),n(!r,{immediate:!0})):n(r))},c={capture:!0},a=Oe((e=>e.addEventListener(o,l,c)),(e=>e.removeEventListener(o,l,c)));return()=>{a(),window.clearTimeout(i)}}(e,n.eventName,n.valueWhenOccurred)}}},[i.FILLED_IN_INPUT]:{isExpensive:()=>!0,track:({sessionData:e,condition:t,callback:n})=>{let o,r=null;const s=()=>{if(!t.selector)return void console.warn("Userflow.js: INPUT_VALUE condition missing selector",t);const s=te(T(t.selector,e.value));let i=null;for(const e of s){const t=pe(e);if(t){i=t;break}}i?i!=r&&(window.clearTimeout(o),o=window.setTimeout((()=>{n(!0)}),1e3)):(n(!1),window.clearTimeout(o)),r=i};s();const i=e.observe(s),{disconnect:l}=Ze(s,{observeInput:!0});return()=>{i(),l(),window.clearTimeout(o)}}},[i.FLOW]:{track:()=>(console.warn("Userflow.js: Flow conditions do not work client-side"),()=>{})},[i.INPUT_VALUE]:{isExpensive:()=>!0,track:({sessionData:e,condition:t,callback:n})=>{const o=()=>{if(!t.operator)return void console.warn("Userflow.js: INPUT_VALUE condition missing operator",t);if(!t.selector)return void console.warn("Userflow.js: INPUT_VALUE condition missing selector",t);let o=!1;const r=x[t.operator],s=te(T(t.selector,e.value));if(s.length>0)for(const n of s){const s=pe(n);if(r.compare({sessionData:e.value,condition:t,value:s})){o=!0;break}}else r.compare({sessionData:e.value,condition:t,value:""})&&(o=!0);n(o)};o();const r=e.observe(o),{disconnect:s}=Ze(o,{observeInput:!0});return()=>{r(),s()}}},[i.PAGE]:{track:({sessionData:e,condition:t,callback:n})=>{const o=()=>{let o=!1;if(t.operator){const n=l();o=x[t.operator].compare({sessionData:e.value,condition:t,value:n})}n(o)};let r=l();const s=()=>{const e=l();e!==r&&(r=e,o())};c(s),o();const i=e.observe(o);return()=>{i(),a(s)}}},[i.TIME]:{track:({condition:e,callback:t})=>{let n=null;const o=e.value?new Date(e.value):null,r=e.value2?new Date(e.value2):null,s=()=>{let e=!0;(o&&!isNaN(o.valueOf())&&Date.now()<o.valueOf()||r&&!isNaN(r.valueOf())&&Date.now()>=r.valueOf())&&(e=!1),e!==n&&(n=e,t(e))};s();const i=window.setInterval(s,1e4);return()=>{window.clearInterval(i)}}}};var Qe=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",conditionTypes:He});export{R as M,y as a,g as b,He as c,Y as d,q as e,Ce as f,z as g,W as h,b as i,De as j,ke as k,H as l,G as m,T as n,Oe as o,Ze as p,ne as q,Le as r,Ne as s,Me as t,Qe as u,P as z};
package/hash.txt CHANGED
@@ -1 +1 @@
1
- 84f55fcf4be48f69de86a7d785e964e3889e7be9
1
+ ad9fc7b0986bd3e9c81e855f3ad7aad547174d76
package/hashes.txt ADDED
@@ -0,0 +1,51 @@
1
+ 19ee23d40a69e8ba1e95e2a6375b09f7a22f8ba0 dist/userflowjs-self-hosted/BubbleToolbar.js
2
+ a9012a4ea3d0d2efe18695136ebbdacf9cf31e6a dist/userflowjs-self-hosted/BuilderBar.js
3
+ 5783ba0de73830792e7aabc2145b83b047a67d64 dist/userflowjs-self-hosted/ChecklistApp.js
4
+ ede3e27abb0e015147a79d44743e638d9eccc5c3 dist/userflowjs-self-hosted/ChecklistUI.js
5
+ b87c452042204f79066abc6c104eba0912a6ae21 dist/userflowjs-self-hosted/DynamicIcon.js
6
+ 3976c8f72cb6653de8d40e8229ffcc467cf541d7 dist/userflowjs-self-hosted/ElementSelectionApp.js
7
+ 0654409768bfa0c606edb614296d052052c9ae3b dist/userflowjs-self-hosted/FlowApp.js
8
+ 016d8447b8a36098acdcd0a13232d595cb54a188 dist/userflowjs-self-hosted/FlowChrome.js
9
+ f756a55ac672f45a2e98e4afc136fe5af900fb75 dist/userflowjs-self-hosted/Icons.js
10
+ 9adffc885e2a4a2ae11ce005a2f604876b1c6945 dist/userflowjs-self-hosted/LauncherApp.js
11
+ ec9657621fa66d20c891c42262961189e054091e dist/userflowjs-self-hosted/NotificationsApp.js
12
+ a4382a6155e7404919a1cf3efc274ff0841452bc dist/userflowjs-self-hosted/README.md
13
+ b000d4407594962083a82a721515112af3c5d039 dist/userflowjs-self-hosted/ResourceCenterApp.js
14
+ f2f9ae8b0d4d8ecebee874b28d10081e1b2b12fe dist/userflowjs-self-hosted/TrackerTestingApp.js
15
+ 87d6a4db2026413c0db572ea370a22debfe6b22c dist/userflowjs-self-hosted/Trigger.js
16
+ ffa4f3e47ee465281b6d88bef7068d16df45a395 dist/userflowjs-self-hosted/avatar-frame.css
17
+ 8087ae6efaef4b7cb169bca1c81174cbf663d892 dist/userflowjs-self-hosted/bubble-frame.css
18
+ 00701ec4a95522ec7e7dfc92d830d2458968ddcc dist/userflowjs-self-hosted/builder-ui-frame.css
19
+ d0c751e740079e6ce2f93341d24f75412ab27b3d dist/userflowjs-self-hosted/builder-ui-host.css
20
+ a0f1d89b03c50ad03b7a51318eec79db3bc1370a dist/userflowjs-self-hosted/checklist-launcher-frame.css
21
+ c3b02f9a428a270af699e5d324f273f2d0d405ef dist/userflowjs-self-hosted/client-context.js
22
+ c31d969a5e5a5ae163bc75adb71da690d82f7e86 dist/userflowjs-self-hosted/flow-condition-types.js
23
+ 7ea6318a04427bc31755de29974d03d3e8ff7022 dist/userflowjs-self-hosted/flow-host.css
24
+ 6f15ae1cddbe9cbc77b72dea7beda62a0cde018e dist/userflowjs-self-hosted/hashes.txt
25
+ 15d6595a692999cef5e65c07e60097ab482980c3 dist/userflowjs-self-hosted/iframe-reset.css
26
+ 15684726bbb8ca0463d20e70eea4af49862253d2 dist/userflowjs-self-hosted/logomark.js
27
+ 47146b05a95ac942833904128a312caacc891f20 dist/userflowjs-self-hosted/notifications-host.css
28
+ 7b1f6cd3307f69d8ba61295606ce19186166764e dist/userflowjs-self-hosted/package.json
29
+ 701cf35077f179dbec9d294ad7a3bbc18980b30f dist/userflowjs-self-hosted/stylesheets.js
30
+ df7affd329b0c2f2a77802ab016ae91af464def5 dist/userflowjs-self-hosted/ui.js
31
+ 64ad037c466edec4bd92482b954b5c32c9078b28 dist/userflowjs-self-hosted/userflow.js
32
+ 3cecb99cc5b176bd49887bd749b5e895f25216c4 dist/userflowjs-self-hosted/vendor.babel.runtime.js
33
+ 85bfdb3b8504620272dcbb487e363e4e79e60638 dist/userflowjs-self-hosted/vendor.date-fns.js
34
+ 2314b61feb70c5605445ca9fd3120fb3fd8b6301 dist/userflowjs-self-hosted/vendor.fortawesome.fontawesome-svg-core.js
35
+ c3e1189d3d60e69828113b417c1b59b1c9718abe dist/userflowjs-self-hosted/vendor.fortawesome.pro-light-svg-icons.js
36
+ a1d2be457d1340c877dca6b064d7a300fa2fc4ca dist/userflowjs-self-hosted/vendor.fortawesome.pro-regular-svg-icons.js
37
+ ec1014db455d6b90c3ad88acca64a7d30a0d4ed4 dist/userflowjs-self-hosted/vendor.fortawesome.pro-solid-svg-icons.js
38
+ 82c5495868375f0e50c670400be3aa5145137122 dist/userflowjs-self-hosted/vendor.fortawesome.react-fontawesome.js
39
+ adc83b19e793491b1c6ea0fd8b46cd9f32e592fc dist/userflowjs-self-hosted/vendor.html-parse-stringify2.js
40
+ 4f7fdc300e72ec4abfa17547b89e07610e92fa33 dist/userflowjs-self-hosted/vendor.i18next.js
41
+ 0f5d0479cce3e4557dd20e49238f8ecbe6ba1e14 dist/userflowjs-self-hosted/vendor.is-hotkey.js
42
+ 47360427df50a62b482767158985bac5e62e7f39 dist/userflowjs-self-hosted/vendor.obj-str.js
43
+ 407822567b860689496bd8a88c24f859356f9618 dist/userflowjs-self-hosted/vendor.object-assign.js
44
+ d32ade49c7fdc819f3dba17efc31f7a3312eb22b dist/userflowjs-self-hosted/vendor.phoenix.js
45
+ eb08d2c956436337007847fb7fa4407786622f38 dist/userflowjs-self-hosted/vendor.prop-types.js
46
+ 61724f383240f3c6b09492e3d8405b00de55ea63 dist/userflowjs-self-hosted/vendor.react-dom.js
47
+ b7696df1c1a9182ac0d8c2c5edf0606baa2603e1 dist/userflowjs-self-hosted/vendor.react-i18next.js
48
+ 4d1f9a29eca96342130fa38bda783c88c6797572 dist/userflowjs-self-hosted/vendor.react.js
49
+ 8d11c8a6fbdaea3428f0a04ebed94ad5dd69c42c dist/userflowjs-self-hosted/vendor.scheduler.js
50
+ f4491b9e58f7f0de5b8a5123a63c5892b9b614ca dist/userflowjs-self-hosted/vendor.uuid.js
51
+ adc83b19e793491b1c6ea0fd8b46cd9f32e592fc dist/userflowjs-self-hosted/vendor.void-elements.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "userflow.js-self-hosted",
3
- "version": "0.0.2000004",
3
+ "version": "0.0.2000006",
4
4
  "description": "Self-hosted version of Userflow.js",
5
5
  "main": "userflow.js"
6
6
  }
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 S=!1;function p(e){return function(){if(S)return;S=!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,Se,pe,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",(Se=we||(we={})).ACTION="ACTION",Se.CHECKLIST="CHECKLIST",Se.CONTACT="CONTACT",Se.FLOWS="FLOWS",Se.KNOWLEDGE_BASE="KNOWLEDGE_BASE",Se.MESSAGE="MESSAGE",Se.SUBPAGE="SUBPAGE",(ge=pe||(pe={})).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.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=2000004"),p(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.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:"2000004",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});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.t}))),[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.t}))),[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,pe 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,p 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 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 S=!1;function p(e){return function(){if(S)return;S=!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,Se,pe,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",(Se=we||(we={})).ACTION="ACTION",Se.CHECKLIST="CHECKLIST",Se.CONTACT="CONTACT",Se.FLOWS="FLOWS",Se.KNOWLEDGE_BASE="KNOWLEDGE_BASE",Se.MESSAGE="MESSAGE",Se.SUBPAGE="SUBPAGE",(ge=pe||(pe={})).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.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=2000006"),p(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.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:"2000006",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});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,pe 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,p 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;