K===B},{nodeTree:b,recordedElementInfo:U}=Q.getElementProfileNodeTree(h.target,y);return console.log("*** Just FYI - this is how it can generate css selector:",Q.generateSelectorFromNodeTree(b,y)),{nodeTree:b,recordedElementInfo:U}}function Do(h,B){let Q=Va(),b={...{allowDuplicates:!1,optimizedMinLength:10,threshold:1e3,attr:K=>K===dataAttribute,fallbackNodeTree:h},...B};return Q.generateSelectorFromNodeTree(h,b)}function Vl(h,B){this.removeOverlayElement=()=>{console.log("Removing mouse over event listener from the selected element."),h.removeEventListener("mouseover",this.mouseOverEvent);let b=h.getElementById("element-selector-overlay");b&&h?.body?.removeChild(b)},this.saveSelectedSelector=b=>{b.preventDefault(),b.stopPropagation(),this.removeOverlayElement();let U=Wg(b,{dataAttribute:"some-custom-strigo-attribute"});U=U||{},console.log("Selected element with elementProfile:",U),B.onElementProfileCreated(U)};function Q(b,U){for(let K in U)b.style[K]=U[K]}let y=(b,U,K=[])=>{if(U===b.target)return;let W=b.target;if(K.includes(W.id))return;let $=W.offsetWidth+2,yA=W.offsetHeight+2;function AA(BA){let ce=0,fA=0;for(;BA&&!isNaN(BA.offsetLeft)&&!isNaN(BA.offsetTop);)ce+=BA.offsetLeft-BA.scrollLeft,fA+=BA.offsetTop-BA.scrollTop,BA=BA.offsetParent;return{top:fA-window.scrollY,left:ce-window.scrollX}}let CA=AA(W),TA={top:CA.top-2+"px",left:CA.left-2+"px",width:$+"px",height:yA+"px"};Q(U,TA)};return this.mouseOverEvent=b=>{let U=window.document.getElementById("element-selector-overlay");y(b,U,["element-selector-overlay","strigo-assessment-recorder-iframe"]),b.target.addEventListener("click",this.saveSelectedSelector)},this.removeClickListenerFromHoveredElement=b=>{b.target.removeEventListener("click",this.saveSelectedSelector)},this.startElementSelector=()=>{let b=h.createElement("div");b.setAttribute("id","element-selector-overlay"),b.setAttribute("id","element-selector-overlay"),b.setAttribute("style",`
position: fixed;
top: 0;
left: 0;
@@ -65,7 +65,7 @@ ${JSON.stringify(U)}`:"")}getDefaultContext(){let B=te();if(!B)return{};let{user
Expected text: ${Q?.recordedAssessment?.expectedText}
Selector used: ${B}
- `,b.children[0].children[1].appendChild(K),T.info("*** Appending assessment debug context element.");let $=window.document.querySelectorAll(`[data-${au}="${B}"]`)?.[0];$?$.appendChild(b):Sd(h,B).appendChild(b)},lu=function(){T.info("*** Evaluating Assessments...",{bodyTextDuringAssessment:window.document.body.innerText.slice(0,50)}),fu.filter(({recordedAssessment:B})=>{let Q=B?.locationElement?.profile?.recordedElementInfo?.url;if(!Q)return!1;let y=window.location.href;return su(Q,y)}).forEach(B=>{let{recordedAssessment:Q,challengeSuccessEvent:y,_id:b}=B,{actionType:U,expectedText:K}=Q,W=Q?.locationElement?.profile;if(!W){T.info("*** missing location element profile. Aborting...");return}if(kn?.[b]?.status==="SUCCESS"){T.info('*** Assessment already in "success" status. Aborting...');return}Ac(b,{status:"pending"});let $;try{$=Id(b,W)}catch{T.info("*** Failed to find location element. Aborting assessment evaluation...");return}let yA=te()?.isAcademyAssessmentDebug,{locationElement:AA,locationElementSelector:CA}=$;switch(yA&&Hd(AA,CA,B),U){case"added-item":{let TA=bd.bind({assessment:B,locationElement:AA,window});if(Ct[b]?.observer&&AA===Ct[b].element){Ct[b].element=AA;try{TA([]),Ct[b].observer.observe(AA,qa),T.info("Same reference - no need to observe again"),T.info(" *** Same reference - no need to observe again",{locationElement:AA})}catch(BA){T.error("*** Got an error in item count",{err:BA});break}break}if(Ct[b]?.observer){try{TA([]),Ct[b].observer.observe(AA,qa),T.info("DOM Reference have changed - observing again"),T.info(" *** DOM Reference have changed - observing again",{locationElement:AA})}catch(BA){T.error("*** Got an error in item count",{err:BA});break}break}Ct[b]={element:AA,observer:new MutationObserver(TA)};try{TA([]),Ct[b].observer.observe(AA,qa)}catch(BA){T.info("*** Got an error in item count",BA);break}break}case"text-change":{if(T.info("*** Assessing text changes in location element...",{locationElement:AA,locationElementType:AA instanceof HTMLInputElement?"input":"non-input",innerTextValue:AA instanceof HTMLInputElement?AA?.value:AA?.innerText,expectedText:K}),AA instanceof HTMLInputElement&&AA?.value?.includes(K)){$a(B,{locationElement:AA});break}if(AA?.innerText?.includes(K)){$a(B,{locationElement:AA});break}break}default:break}})},xd=function(h){let B=h.some(y=>y.addedNodes?.length>0),Q=h.some(y=>y.type=="characterData");if(T.info("#####",{isAddedNodes:B,isCharacterDataChanged:Q}),!B&&!Q){T.info("*** No added nodes and no character data change were detected after url change.",{previousLocation:Ro||"",newLocation:document.location.href});return}Ro===document.location.href?T.info("*** No URL change and no nodes were added."):(T.info("*** Detected URL change!",{previousLocation:Ro||"",newLocation:document.location.href}),Ro=document.location.href),ec(window)},ec=(0,uu.default)(h=>{if(T.info("*** Initializing document observer"),fu=Pa().assessments.filter(({assessmentType:B})=>B==="recorded-flow"),!window?.strigoObserver?.observer){T.info("*** Adding Strigo observer to document body"),window.strigoObserver={observer:new MutationObserver(xd),observedBodyElement:window.document.body},lu(),T.info("*** Starting to observe document body"),window?.strigoObserver?.observer?.observe(window.document,cu);return}lu(),window.document.contains(window.strigoObserver.observedBodyElement)||(T.info('*** Detected a "body" element change. Re-initializing the document observer...'),window.strigoObserver.observedBodyElement=window.document.body,window.strigoObserver.observer.observe(window.document,cu))},500);var pu=So(Za(),1);var du={subtree:!0,childList:!0},is;function hu(h){try{window["localStorage"].setItem("strigoUrlTriggers",JSON.stringify(h))}catch(B){return T.error("Url triggers setup error",{error:B}),null}}function Ld(){try{let h=window["localStorage"].getItem("strigoUrlTriggers");if(h)return JSON.parse(h)}catch(h){return T.error("Get url triggers error",{error:h}),null}}function Bu(h){let B=document.getElementById("strigo-exercises"),Q=h.document.location.href,y=Ld();if(!y)return;let b=Zr("urlTriggeredCourses")||[];for(let U of y){let{publishmentId:K,urlTriggerMatchType:W,urlTriggerUrl:$}=U;if(T.info("Detect URL trigger invoked",{publishmentId:K,urlTriggeredCourses:b}),!K){T.info("URL trigger detected without course id");continue}if(b.includes(K)){T.info("Detected URL trigger for a course that was already opened, doing nothing");continue}switch(W){case"exact":{$.trim()===Q.trim()&&B.contentWindow.postMessage({selectedCourseId:K},"*");break}case"starts_with":{Q.trim().startsWith($.trim())&&B.contentWindow.postMessage({selectedCourseId:K},"*");break}default:break}}}var Od=function(h){let B=h.some(Q=>Q.addedNodes?.length>0);if(T.info("#####",{isAddedNodes:B}),!B){T.info("*** No added nodes and no character data change were detected after url change.",{previousLocation:is||"",newLocation:document.location.href});return}is===document.location.href?T.info("*** No URL change and no nodes were added."):(T.info("*** Detected URL change!",{previousLocation:is||"",newLocation:document.location.href}),is=document.location.href),tc(window)},tc=(0,pu.default)(h=>{if(T.info("*** Initializing url trigger observer"),!h?.strigoUrlTriggerObserver?.observer){T.info("*** Adding Strigo url trigger observer to document body"),h.strigoUrlTriggerObserver={observer:new MutationObserver(Od),observedBodyElement:h.document.body},Bu(h),T.info("*** Starting to observe document body - url trigger observer"),h?.strigoUrlTriggerObserver?.observer?.observe(h.document,du);return}Bu(h),h.document.contains(h.strigoUrlTriggerObserver.observedBodyElement)||(T.info('*** Detected a "body" element change. Re-initializing the document observer - url trigger observer...'),h.strigoUrlTriggerObserver.observedBodyElement=h.document.body,h.strigoUrlTriggerObserver.observer.observe(h.document,du))},500);var wu=342;function vu(){T.info("Posting dockable state to Strigo",{});let h=pr("dockingSide");document.getElementById("strigo-exercises").contentWindow.postMessage({dockable:!0,dockingSide:h},"*")}function Kd(){let[h]=ts();(0,rc.default)("#strigo-widget").resizable({edges:{left:"#strigo-collapse-div",right:"#strigo-collapse-div.align-left",bottom:!1,top:!1},listeners:{move(B){let Q=B.target;Q.style.width=`${B.rect.widthh?h:B.rect.width}px`},start(){let B=document.getElementById("strigo-exercises");B.style.pointerEvents="none"},end(){let B=document.getElementById("strigo-exercises");B.style.pointerEvents="auto"}},modifiers:[rc.default.modifiers.restrictEdges({outer:"parent"})]})}var Qu=class{init(){return T.info("overlay init called"),"OVERLAY"}setup({version:B}){T.info("overlay setup called"),wr({parentElement:hr(),url:dl(B)}),wr({parentElement:hr(),url:zi(B)});let Q=te(),y=sessionStorage.getItem("strigoPreviewUserToken"),b=!!y,U=Pl(ji({...Q,user:{token:{token:y||Q.user.token.token,expiration:Q.user.token.expiration},email:Q.user.email}},b)),K=Lo();this.initEventListeners(K,U),T.info("adding assessment document observer"),ec(K),tc(K),Nl(K),T.info("assessment document observer added"),Kd()}shutdown(){T.info("overlay shutdown called");let B=Lo();this.removeEventListeners(B),B?.strigoObserver?.observer?.disconnect(),Ml(B)}collapse(){T.info("overlay collapse called"),_l()}open(){Gn(),vu()}move(){Kl()}initEventListeners(B,Q){as(Q,vu),ss(B)}removeEventListeners(B){Cu()}},_o=new Qu;function yu(h){let B=h?.data;if(!!B){if(B.startsWith("url-triggered")){let Q=Zr("urlTriggeredCourses")||[],y=B.split("/")[1];if(T.info("URL trigger message received",{selectedCourseId:y,urlTriggeredCourses:Q}),!y){T.info("URL trigger message received without course id");return}if(Q.includes(y)){T.info("URL trigger message received for a course that was already opened, doing nothing");return}T.info("URL trigger message received for a new course, opening it"),Q.push(y),Jt("urlTriggeredCourses",Q),Nn()==="overlay"&&Gn();return}switch(h.data){case"move":{T.info("Panel move message received"),Nn()==="overlay"&&_o.move();break}case"close":{T.info("Shutdown message received - will collapse panel"),window.Strigo?.collapse();break}case"destroy":{T.info("Destroy message received"),window.Strigo?.destroy();break}case"challenge-success":{T.info("Challenge event success message received"),Nn()==="overlay"&&_o.open();break}case"rendered":{T.info("Panel rendered message received"),Jt("isRendered",!0),window.Strigo?.expandPanel();break}default:break}}}function ss(h){h.addEventListener("message",yu,!1)}function Cu(){window.removeEventListener("message",yu)}function as(h,B){h.addEventListener("load",async()=>{Zr("isLoading")&&(B&&await B(),Jt("isLoading",!1))})}function Fu(h){let B=pr("initSite")?.host;h.addEventListener("load",function(){try{this.contentWindow.location.host!==B&&window.Strigo.shutdown()}catch(Q){T.error(Q),window.Strigo.shutdown()}})}function Eu(){return Ja(["#strigo-exercises","#original-site"],{sizes:[25,75],maxSize:ts(),minSize:Ol(),gutterSize:2})}async function Rd(){await zl(),document.getElementById("strigo-exercises").contentWindow.postMessage({dockable:!1},"*")}var bu=class{init(){let B;return ll()?(T.info("Child SDK window"),B="CHILD",window.dispatchEvent(new Event("strigo-opened")),ul()):(T.info("Parent SDK window"),B="PARENT"),B}setup({version:B}){T.info("iframe setup started"),Hl(),wr({parentElement:hr(),url:gl(B)}),wr({parentElement:hr(),url:zi(B)}),jl();let Q=te(),y=xl(),b=Oo({parentElement:y,url:ji(Q,!1),classNames:el,id:"strigo-exercises"}),U=Oo({parentElement:y,url:cl(Q.initSite.href),classNames:tl,id:"original-site"}),K=document.createElement("div");K.className="strigo-academy-hat align-left",K.id="strigo-academy-hat",K.onclick=()=>{document.getElementById("strigo-academy-hat").classList.toggle("slide-in"),this.splitInstance=Eu()};let W=document.createElement("div");W.className="strigo-academy-hat-icon",W.id="strigo-academy-hat-icon",W.innerHTML=Ji,K.appendChild(W),y.appendChild(K),this.splitInstance=Eu();let $=Lo();this.initEventListeners($,b,U)}collapse(){this.splitInstance&&(this.splitInstance.destroy(),this.splitInstance=Ja(["#strigo-exercises","#original-site"],{sizes:[25,75],minSize:0,gutterSize:0}),this.splitInstance.collapse(0),document.getElementById("strigo-academy-hat").classList.toggle("slide-in"))}open(){}shutdown(){T.info("iframe shutdown called"),Tl()}initEventListeners(B,Q,y){as(Q,Rd),Fu(y),ss(y.contentWindow)}},Iu=new bu;function Su(h){return h&&h==="dynamic"?Dl()?"iframe":"overlay":h}function Vn(h){let B=null;switch(h){case"iframe":{B=Iu;break}case"overlay":{B=_o;break}default:throw T.error("Widget flavor is not supported",{widgetFlavor:h}),new Error(`Widget flavor ${h} is not supported`)}return B}var Hu=class{constructor(){this.config={}}isDevelopment(){return!1}init(){try{if(T.info("Initializing SDK..."),this.config.initialized){T.info("SDK was already initialized");return}El();let{webApiKey:B,subDomain:Q,selectedWidgetFlavor:y}=fl();if(!B||!Q||!y)throw new Error("Init data is missing");let b=Su(y);wl({webApiKey:B,subDomain:Q,selectedWidgetFlavor:b});let U=Vn(b);if(this.config.sdkType=U.init(),this.config.initialized=!0,T.info("Initialized SDK."),this.config.sdkType!=="CHILD"&&Pn()){let K=te()?.user?.token,W=sessionStorage.getItem("strigoPreviewUserToken"),$=W?{token:{token:W,expiration:`${Date.now()+1e3*60*60*24}`},isPreview:!0}:{token:K};this.setup($)}}catch(B){T.error("Could not initialize SDK",{err:B})}}async setup(B){try{T.info("Starting to setup SDK...");let Q=document.getElementById("strigo-widget");if(this.config.isOpen&&Q||this.config.sdkType==="CHILD"){T.info('panel is already opened. Aborting "setup" action...');return}if(!this.config.initialized)throw new Error("SDK was not initialized");let b=te(),{email:U,token:K,version:W,openWidget:$=!0,dockingSide:yA="right",isPreview:AA}={...b?.user,...b,...B};if(!U||!K)throw new Error("Setup data is missing");let CA=await Cl(K);if(!CA?.allowedAcademyDomains?.includes(window.location.host.replace(/^www\./i,""))){T.warn("Running on an unrelated domain. Aborting...",{allowedDomains:CA?.allowedAcademyDomains,currentHost:window.location.host});return}if(CA){let{loggingConfig:TA,userAssessments:BA}=CA;T.debug("Configuration fetched from Strigo"),T.setup(TA),bl(BA),CA.academyColors&&Gl(CA.academyColors),CA.urlTriggers&&hu(CA.urlTriggers)}AA||vl({user:{email:U,token:K},initSite:al(),version:W,loggingConfig:CA?.loggingConfig,assessmentThresholds:CA?.assessmentThresholds,isAcademyAssessmentDebug:CA?.isAcademyAssessmentDebug,dockingSide:yA}),this.config.configured=!0,T.info("Finished SDK setup."),$&&(this.open(),Jt("shouldPanelBeOpen",!1),this.collapse())}catch(Q){T.error("Could not setup SDK",{err:Q})}}open(){try{if(T.info("Opening academy panel..."),!this.config.configured)throw new Error("SDK was not set up");let B=document.getElementById("strigo-widget");if(this.config.isOpen&&B||this.config.sdkType==="CHILD"){T.info('Panel is already opened. Aborting "open" action...');return}let y=te();yl({currentUrl:y.initSite.href,shouldPanelBeOpen:Pn(),isLoading:!0,isRendered:!1,widgetFlavor:y.selectedWidgetFlavor}),Vn(y.selectedWidgetFlavor).setup({version:y.version}),this.config.isOpen=!0,T.info("Opened academy panel.")}catch(B){T.error("Could not open academy panel",{err:B})}}expandPanel(){T.info("Expanding academy panel");let B=te();Vn(B.selectedWidgetFlavor).open(),Zr("isRendered")&&Rl()}collapse(){T.info("Collapsing academy panel");let{selectedWidgetFlavor:B}=te();Vn(B).collapse()}shutdown(){try{if(T.info("Closing academy panel..."),this.config.sdkType==="CHILD"){window.parent.postMessage(JSON.stringify({messageType:"close"}),"*"),T.info("Notified parent frame to close academy panel.");return}if(!this.config.isOpen){T.info("Tried to close unopened academy panel");return}let B=Vn(Nn());Fl(),B.collapse(),B.shutdown(),this.config.isOpen=!1,T.info("Closed academy panel.")}catch(B){T.error("Could not close academy panel",{err:B})}}destroy(){try{if(T.info("Destroying SDK..."),this.config.sdkType==="CHILD"){window.parent.postMessage(JSON.stringify({messageType:"destroy"}),"*"),T.info("Notified parent frame to destroy SDK.");return}Ql(),Il(),this.shutdown(),this.config={},T.info("Destroyed SDK.")}catch(B){T.error("Could not destroy SDK",{err:B})}}async sendEvent(B){let Q=pr("user"),{token:y}=Q;await Ul(y,B),T.debug("sendEvent called",{eventName:B})}startElementSelector(B,Q,y){T.debug("startElementSelector called");let b=y?window.document.querySelector(y):window.document.body,{startElementSelector:U,stopElementSelection:K}=Vl(window.document,{onElementProfileCreated:B,onElementSelectionCancel:Q,zIndex:2147483645,rootElement:b});this.stopElementSelector=K,U()}stopElementSelector(){}assessmentRecorder(){Wl()}},xu=new Hu;window.Strigo=xu;window.Strigo.init();})();
+ `,b.children[0].children[1].appendChild(K),T.info("*** Appending assessment debug context element.");let $=window.document.querySelectorAll(`[data-${au}="${B}"]`)?.[0];$?$.appendChild(b):Sd(h,B).appendChild(b)},lu=function(){T.info("*** Evaluating Assessments...",{bodyTextDuringAssessment:window.document.body.innerText.slice(0,50)}),fu.filter(({recordedAssessment:B})=>{let Q=B?.locationElement?.profile?.recordedElementInfo?.url;if(!Q)return!1;let y=window.location.href;return su(Q,y)}).forEach(B=>{let{recordedAssessment:Q,challengeSuccessEvent:y,_id:b}=B,{actionType:U,expectedText:K}=Q,W=Q?.locationElement?.profile;if(!W){T.info("*** missing location element profile. Aborting...");return}if(kn?.[b]?.status==="SUCCESS"){T.info('*** Assessment already in "success" status. Aborting...');return}Ac(b,{status:"pending"});let $;try{$=Id(b,W)}catch{T.info("*** Failed to find location element. Aborting assessment evaluation...");return}let yA=te()?.isAcademyAssessmentDebug,{locationElement:AA,locationElementSelector:CA}=$;switch(yA&&Hd(AA,CA,B),U){case"added-item":{let TA=bd.bind({assessment:B,locationElement:AA,window});if(Ct[b]?.observer&&AA===Ct[b].element){Ct[b].element=AA;try{TA([]),Ct[b].observer.observe(AA,qa),T.info("Same reference - no need to observe again"),T.info(" *** Same reference - no need to observe again",{locationElement:AA})}catch(BA){T.error("*** Got an error in item count",{err:BA});break}break}if(Ct[b]?.observer){try{TA([]),Ct[b].observer.observe(AA,qa),T.info("DOM Reference have changed - observing again"),T.info(" *** DOM Reference have changed - observing again",{locationElement:AA})}catch(BA){T.error("*** Got an error in item count",{err:BA});break}break}Ct[b]={element:AA,observer:new MutationObserver(TA)};try{TA([]),Ct[b].observer.observe(AA,qa)}catch(BA){T.info("*** Got an error in item count",BA);break}break}case"text-change":{if(T.info("*** Assessing text changes in location element...",{locationElement:AA,locationElementType:AA instanceof HTMLInputElement?"input":"non-input",innerTextValue:AA instanceof HTMLInputElement?AA?.value:AA?.innerText,expectedText:K}),AA instanceof HTMLInputElement&&AA?.value?.includes(K)){$a(B,{locationElement:AA});break}if(AA?.innerText?.includes(K)){$a(B,{locationElement:AA});break}break}default:break}})},xd=function(h){let B=h.some(y=>y.addedNodes?.length>0),Q=h.some(y=>y.type=="characterData");if(T.info("#####",{isAddedNodes:B,isCharacterDataChanged:Q}),!B&&!Q){T.info("*** No added nodes and no character data change were detected after url change.",{previousLocation:Ro||"",newLocation:document.location.href});return}Ro===document.location.href?T.info("*** No URL change and no nodes were added."):(T.info("*** Detected URL change!",{previousLocation:Ro||"",newLocation:document.location.href}),Ro=document.location.href),ec(window)},ec=(0,uu.default)(h=>{if(T.info("*** Initializing document observer"),fu=Pa().assessments.filter(({assessmentType:B})=>B==="recorded-flow"),!window?.strigoObserver?.observer){T.info("*** Adding Strigo observer to document body"),window.strigoObserver={observer:new MutationObserver(xd),observedBodyElement:window.document.body},lu(),T.info("*** Starting to observe document body"),window?.strigoObserver?.observer?.observe(window.document,cu);return}lu(),window.document.contains(window.strigoObserver.observedBodyElement)||(T.info('*** Detected a "body" element change. Re-initializing the document observer...'),window.strigoObserver.observedBodyElement=window.document.body,window.strigoObserver.observer.observe(window.document,cu))},500);var pu=So(Za(),1);var du={subtree:!0,childList:!0},is;function hu(h){try{window["localStorage"].setItem("strigoUrlTriggers",JSON.stringify(h))}catch(B){return T.error("Url triggers setup error",{error:B}),null}}function Ld(){try{let h=window["localStorage"].getItem("strigoUrlTriggers");if(h)return JSON.parse(h)}catch(h){return T.error("Get url triggers error",{error:h}),null}}function Bu(h){let B=document.getElementById("strigo-exercises"),Q=h.document.location.href,y=Ld();if(!y)return;let b=Zr("urlTriggeredCourses")||[];for(let U of y){let{publishmentId:K,urlTriggerMatchType:W,urlTriggerUrl:$}=U;if(T.info("Detect URL trigger invoked",{publishmentId:K,urlTriggeredCourses:b}),!K){T.info("URL trigger detected without course id");continue}if(b.includes(K)){T.info("Detected URL trigger for a course that was already opened, doing nothing");continue}switch(W){case"exact":{$.trim()===Q.trim()&&B.contentWindow.postMessage({selectedCourseId:K},"*");break}case"starts_with":{Q.trim().startsWith($.trim())&&B.contentWindow.postMessage({selectedCourseId:K},"*");break}default:break}}}var Od=function(h){let B=h.some(Q=>Q.addedNodes?.length>0);if(T.info("#####",{isAddedNodes:B}),!B){T.info("*** No added nodes and no character data change were detected after url change.",{previousLocation:is||"",newLocation:document.location.href});return}is===document.location.href?T.info("*** No URL change and no nodes were added."):(T.info("*** Detected URL change!",{previousLocation:is||"",newLocation:document.location.href}),is=document.location.href),tc(window)},tc=(0,pu.default)(h=>{if(T.info("*** Initializing url trigger observer"),!h?.strigoUrlTriggerObserver?.observer){T.info("*** Adding Strigo url trigger observer to document body"),h.strigoUrlTriggerObserver={observer:new MutationObserver(Od),observedBodyElement:h.document.body},Bu(h),T.info("*** Starting to observe document body - url trigger observer"),h?.strigoUrlTriggerObserver?.observer?.observe(h.document,du);return}Bu(h),h.document.contains(h.strigoUrlTriggerObserver.observedBodyElement)||(T.info('*** Detected a "body" element change. Re-initializing the document observer - url trigger observer...'),h.strigoUrlTriggerObserver.observedBodyElement=h.document.body,h.strigoUrlTriggerObserver.observer.observe(h.document,du))},500);var wu=342;function vu(){T.info("Posting dockable state to Strigo",{});let h=pr("dockingSide");document.getElementById("strigo-exercises").contentWindow.postMessage({dockable:!0,dockingSide:h},"*")}function Kd(){let[h]=ts();(0,rc.default)("#strigo-widget").resizable({edges:{left:"#strigo-collapse-div",right:"#strigo-collapse-div.align-left",bottom:!1,top:!1},listeners:{move(B){let Q=B.target;Q.style.width=`${B.rect.widthh?h:B.rect.width}px`},start(){let B=document.getElementById("strigo-exercises");B.style.pointerEvents="none"},end(){let B=document.getElementById("strigo-exercises");B.style.pointerEvents="auto"}},modifiers:[rc.default.modifiers.restrictEdges({outer:"parent"})]})}var Qu=class{init(){return T.info("overlay init called"),"OVERLAY"}setup({version:B}){T.info("overlay setup called"),wr({parentElement:hr(),url:dl(B)}),wr({parentElement:hr(),url:zi(B)});let Q=te(),y=sessionStorage.getItem("strigoPreviewUserToken"),b=!!y,U=Pl(ji({...Q,user:{token:{token:y||Q.user.token.token,expiration:Q.user.token.expiration},email:Q.user.email}},b)),K=Lo();this.initEventListeners(K,U),T.info("adding assessment document observer"),ec(K),tc(K),Nl(K),T.info("assessment document observer added"),Kd()}shutdown(){T.info("overlay shutdown called");let B=Lo();this.removeEventListeners(B),B?.strigoObserver?.observer?.disconnect(),Ml(B)}collapse(){T.info("overlay collapse called"),_l()}open(){Gn(),vu()}move(){Kl()}initEventListeners(B,Q){as(Q,vu),ss(B)}removeEventListeners(B){Cu()}},_o=new Qu;function yu(h){let B=h?.data;if(!!B){if(B.startsWith?.("url-triggered")){let Q=Zr("urlTriggeredCourses")||[],y=B.split("/")[1];if(T.info("URL trigger message received",{selectedCourseId:y,urlTriggeredCourses:Q}),!y){T.info("URL trigger message received without course id");return}if(Q.includes(y)){T.info("URL trigger message received for a course that was already opened, doing nothing");return}T.info("URL trigger message received for a new course, opening it"),Q.push(y),Jt("urlTriggeredCourses",Q),Nn()==="overlay"&&Gn();return}switch(h.data){case"move":{T.info("Panel move message received"),Nn()==="overlay"&&_o.move();break}case"close":{T.info("Shutdown message received - will collapse panel"),window.Strigo?.collapse();break}case"destroy":{T.info("Destroy message received"),window.Strigo?.destroy();break}case"challenge-success":{T.info("Challenge event success message received"),Nn()==="overlay"&&_o.open();break}case"rendered":{T.info("Panel rendered message received"),Jt("isRendered",!0),window.Strigo?.expandPanel();break}default:break}}}function ss(h){h.addEventListener("message",yu,!1)}function Cu(){window.removeEventListener("message",yu)}function as(h,B){h.addEventListener("load",async()=>{Zr("isLoading")&&(B&&await B(),Jt("isLoading",!1))})}function Fu(h){let B=pr("initSite")?.host;h.addEventListener("load",function(){try{this.contentWindow.location.host!==B&&window.Strigo.shutdown()}catch(Q){T.error(Q),window.Strigo.shutdown()}})}function Eu(){return Ja(["#strigo-exercises","#original-site"],{sizes:[25,75],maxSize:ts(),minSize:Ol(),gutterSize:2})}async function Rd(){await zl(),document.getElementById("strigo-exercises").contentWindow.postMessage({dockable:!1},"*")}var bu=class{init(){let B;return ll()?(T.info("Child SDK window"),B="CHILD",window.dispatchEvent(new Event("strigo-opened")),ul()):(T.info("Parent SDK window"),B="PARENT"),B}setup({version:B}){T.info("iframe setup started"),Hl(),wr({parentElement:hr(),url:gl(B)}),wr({parentElement:hr(),url:zi(B)}),jl();let Q=te(),y=xl(),b=Oo({parentElement:y,url:ji(Q,!1),classNames:el,id:"strigo-exercises"}),U=Oo({parentElement:y,url:cl(Q.initSite.href),classNames:tl,id:"original-site"}),K=document.createElement("div");K.className="strigo-academy-hat align-left",K.id="strigo-academy-hat",K.onclick=()=>{document.getElementById("strigo-academy-hat").classList.toggle("slide-in"),this.splitInstance=Eu()};let W=document.createElement("div");W.className="strigo-academy-hat-icon",W.id="strigo-academy-hat-icon",W.innerHTML=Ji,K.appendChild(W),y.appendChild(K),this.splitInstance=Eu();let $=Lo();this.initEventListeners($,b,U)}collapse(){this.splitInstance&&(this.splitInstance.destroy(),this.splitInstance=Ja(["#strigo-exercises","#original-site"],{sizes:[25,75],minSize:0,gutterSize:0}),this.splitInstance.collapse(0),document.getElementById("strigo-academy-hat").classList.toggle("slide-in"))}open(){}shutdown(){T.info("iframe shutdown called"),Tl()}initEventListeners(B,Q,y){as(Q,Rd),Fu(y),ss(y.contentWindow)}},Iu=new bu;function Su(h){return h&&h==="dynamic"?Dl()?"iframe":"overlay":h}function Vn(h){let B=null;switch(h){case"iframe":{B=Iu;break}case"overlay":{B=_o;break}default:throw T.error("Widget flavor is not supported",{widgetFlavor:h}),new Error(`Widget flavor ${h} is not supported`)}return B}var Hu=class{constructor(){this.config={}}isDevelopment(){return!1}init(){try{if(T.info("Initializing SDK..."),this.config.initialized){T.info("SDK was already initialized");return}El();let{webApiKey:B,subDomain:Q,selectedWidgetFlavor:y}=fl();if(!B||!Q||!y)throw new Error("Init data is missing");let b=Su(y);wl({webApiKey:B,subDomain:Q,selectedWidgetFlavor:b});let U=Vn(b);if(this.config.sdkType=U.init(),this.config.initialized=!0,T.info("Initialized SDK."),this.config.sdkType!=="CHILD"&&Pn()){let K=te()?.user?.token,W=sessionStorage.getItem("strigoPreviewUserToken"),$=W?{token:{token:W,expiration:`${Date.now()+1e3*60*60*24}`},isPreview:!0}:{token:K};this.setup($)}}catch(B){T.error("Could not initialize SDK",{err:B})}}async setup(B){try{T.info("Starting to setup SDK...");let Q=document.getElementById("strigo-widget");if(this.config.isOpen&&Q||this.config.sdkType==="CHILD"){T.info('panel is already opened. Aborting "setup" action...');return}if(!this.config.initialized)throw new Error("SDK was not initialized");let b=te(),{email:U,token:K,version:W,openWidget:$=!0,dockingSide:yA="right",isPreview:AA}={...b?.user,...b,...B};if(!U||!K)throw new Error("Setup data is missing");let CA=await Cl(K);if(!CA?.allowedAcademyDomains?.includes(window.location.host.replace(/^www\./i,""))){T.warn("Running on an unrelated domain. Aborting...",{allowedDomains:CA?.allowedAcademyDomains,currentHost:window.location.host});return}if(CA){let{loggingConfig:TA,userAssessments:BA}=CA;T.debug("Configuration fetched from Strigo"),T.setup(TA),bl(BA),CA.academyColors&&Gl(CA.academyColors),CA.urlTriggers&&hu(CA.urlTriggers)}AA||vl({user:{email:U,token:K},initSite:al(),version:W,loggingConfig:CA?.loggingConfig,assessmentThresholds:CA?.assessmentThresholds,isAcademyAssessmentDebug:CA?.isAcademyAssessmentDebug,dockingSide:yA}),this.config.configured=!0,T.info("Finished SDK setup."),$&&(this.open(),Jt("shouldPanelBeOpen",!1),this.collapse())}catch(Q){T.error("Could not setup SDK",{err:Q})}}open(){try{if(T.info("Opening academy panel..."),!this.config.configured)throw new Error("SDK was not set up");let B=document.getElementById("strigo-widget");if(this.config.isOpen&&B||this.config.sdkType==="CHILD"){T.info('Panel is already opened. Aborting "open" action...');return}let y=te();yl({currentUrl:y.initSite.href,shouldPanelBeOpen:Pn(),isLoading:!0,isRendered:!1,widgetFlavor:y.selectedWidgetFlavor}),Vn(y.selectedWidgetFlavor).setup({version:y.version}),this.config.isOpen=!0,T.info("Opened academy panel.")}catch(B){T.error("Could not open academy panel",{err:B})}}expandPanel(){T.info("Expanding academy panel");let B=te();Vn(B.selectedWidgetFlavor).open(),Zr("isRendered")&&Rl()}collapse(){T.info("Collapsing academy panel");let{selectedWidgetFlavor:B}=te();Vn(B).collapse()}shutdown(){try{if(T.info("Closing academy panel..."),this.config.sdkType==="CHILD"){window.parent.postMessage(JSON.stringify({messageType:"close"}),"*"),T.info("Notified parent frame to close academy panel.");return}if(!this.config.isOpen){T.info("Tried to close unopened academy panel");return}let B=Vn(Nn());Fl(),B.collapse(),B.shutdown(),this.config.isOpen=!1,T.info("Closed academy panel.")}catch(B){T.error("Could not close academy panel",{err:B})}}destroy(){try{if(T.info("Destroying SDK..."),this.config.sdkType==="CHILD"){window.parent.postMessage(JSON.stringify({messageType:"destroy"}),"*"),T.info("Notified parent frame to destroy SDK.");return}Ql(),Il(),this.shutdown(),this.config={},T.info("Destroyed SDK.")}catch(B){T.error("Could not destroy SDK",{err:B})}}async sendEvent(B){let Q=pr("user"),{token:y}=Q;await Ul(y,B),T.debug("sendEvent called",{eventName:B})}startElementSelector(B,Q,y){T.debug("startElementSelector called");let b=y?window.document.querySelector(y):window.document.body,{startElementSelector:U,stopElementSelection:K}=Vl(window.document,{onElementProfileCreated:B,onElementSelectionCancel:Q,zIndex:2147483645,rootElement:b});this.stopElementSelector=K,U()}stopElementSelector(){}assessmentRecorder(){Wl()}},xu=new Hu;window.Strigo=xu;window.Strigo.init();})();
/*!
* html2canvas 1.4.1
* Copyright (c) 2022 Niklas von Hertzen
diff --git a/src/modules/document/document.ts b/src/modules/document/document.ts
index 44f94f4..5cc9263 100644
--- a/src/modules/document/document.ts
+++ b/src/modules/document/document.ts
@@ -117,10 +117,10 @@ export function removeWidget(hostingAppWindow: Window): void {
export function removeLoader(): void {
const loader = document.getElementById('loader');
- loader.remove();
+ loader?.remove();
const academyHatIcon = document.getElementById('strigo-academy-hat-icon');
- academyHatIcon.classList.remove('loader');
+ academyHatIcon?.classList.remove('loader');
}
export function openWidget(): void {
diff --git a/src/modules/listeners/listeners.ts b/src/modules/listeners/listeners.ts
index bddfed1..c5245f0 100644
--- a/src/modules/listeners/listeners.ts
+++ b/src/modules/listeners/listeners.ts
@@ -14,7 +14,7 @@ function onHostEventHandler(ev: MessageEvent): void {
return;
}
- if (message.startsWith(MessageTypes.URL_TRIGGERED)) {
+ if (message.startsWith?.(MessageTypes.URL_TRIGGERED)) {
const urlTriggeredCourses = (sessionManager.getSessionValue('urlTriggeredCourses') as string[]) || [];
const selectedCourseId = message.split('/')[1];