From 009ba1eaa0f1c3638476129fe02af37802ced46b Mon Sep 17 00:00:00 2001 From: Omry Zobel Date: Wed, 19 Oct 2022 11:07:33 +0300 Subject: [PATCH] [semver:patch] Fix config is not init yet in setup --- dist/development/strigo.sdk.js | 5 ++--- dist/production/strigo.sdk.min.js | 4 ++-- src/strigo/index.ts | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/dist/development/strigo.sdk.js b/dist/development/strigo.sdk.js index 85cc5d7..6d938e3 100644 --- a/dist/development/strigo.sdk.js +++ b/dist/development/strigo.sdk.js @@ -12194,7 +12194,6 @@ ${JSON.stringify(parsedContext)}` : ""); break; } case "submit-assessment" /* SUBMIT_ASSESSMENT */: { - debugger; const recorderWindowId = window.sessionStorage.getItem(ASSESSMENT_RECORDER_ID_PARAM); const urlToSave = getURLWithoutStrigoRecorderParams(window.location.href); window.opener.postMessage({ @@ -13446,7 +13445,7 @@ ${JSON.stringify(parsedContext)}` : ""); const mainDiv = generatePageStructure(); const academyPanelFrame = appendIFrame({ parentElement: mainDiv, - url: generateStrigoIframeURL(config), + url: generateStrigoIframeURL(config, false), classNames: STRIGO_IFRAME_CLASSES, id: "strigo-exercises" }); @@ -13588,7 +13587,7 @@ ${JSON.stringify(parsedContext)}` : ""); openWidget: openWidget2 = true, dockingSide = "right" /* RIGHT */, isPreview - } = { ...config.user, ...config, ...data }; + } = { ...config?.user, ...config, ...data }; if (!email || !token) { throw new Error("Setup data is missing"); } diff --git a/dist/production/strigo.sdk.min.js b/dist/production/strigo.sdk.min.js index 467534a..93e7155 100644 --- a/dist/production/strigo.sdk.min.js +++ b/dist/production/strigo.sdk.min.js @@ -26,7 +26,7 @@ ${JSON.stringify(U)}`:"")}getDefaultContext(){let p=oe();if(!p)return{};let{user border: 2px dashed #696CBF; box-sizing: border-box; border-radius: 4px; - `),console.log("Appending overlay selector element."),h.body.appendChild(b),h.addEventListener("mouseover",this.mouseOverEvent),h.addEventListener("mouseout",this.removeClickListenerFromHoveredElement),window.focus(),h.body.focus(),window.addEventListener("keydown",this.onEscSelection,!0)},this.onEscSelection=b=>{b.key==="Escape"&&(console.log("Aborting element selection...",b.key),this.stopElementSelection())},this.stopElementSelection=()=>{this.removeOverlayElement(),window.removeEventListener("keydown",this.onEscSelection,!0),p.onElementSelectionCancel()},{startElementSelector:this.startElementSelector,stopElementSelection:this.stopElementSelection}}function Xg(h,p){let C=document.getElementById("strigo-assessment-recorder-iframe"),{nodeTree:E}=h,b=To(E);(0,Vl.default)(document.querySelector(b),{backgroundColor:"#c6c7e7"}).then(U=>{let K={imageData:U.toDataURL(),profile:h,querySelector:b};C.contentWindow.postMessage(JSON.stringify({messageType:"end-capture",payload:{elementType:p,selectedElement:K},windowName:window.name}),"*"),C.classList.replace("slide-from-opened-to-minimized","slide-from-minimized-to-opened")})}function Wg(h){L.info("Aborting element selection...");let p=document.getElementById("strigo-assessment-recorder-iframe");p.classList.replace("slide-from-opened-to-minimized","slide-from-minimized-to-opened"),p.contentWindow.postMessage(JSON.stringify({messageType:"end-capture",payload:{elementType:h,selectedElement:null},windowName:window.name}),"*")}function Xl(){if(document.getElementById("strigo-assessment-recorder-iframe"))return;let h=Bl();hr({parentElement:pr(),url:dl()});let p=xo({classNames:["strigo-assessment-recorder-iframe","opened"],id:"strigo-assessment-recorder-iframe",parentElement:window.document.body,url:h});window.addEventListener("message",C=>{if(!C||!C.data||C.origin!==h)return;let E;try{E=JSON.parse(C.data)}catch{return}let{messageType:b,payload:U}=E;switch(b){case"start-capture":{L.info("Start capturing message received"),p.classList.replace("opened","slide-from-opened-to-minimized")||p.classList.replace("slide-from-minimized-to-opened","slide-from-opened-to-minimized");let{elementType:X,rootElementSelector:oA}=U?.captureParams;window.Strigo.startElementSelector(yA=>Xg(yA,X),()=>Wg(X),oA);break}case"stop-capture":{L.info("Stop capturing message received"),p.classList.replace("slide-from-opened-to-minimized","slide-from-minimized-to-opened"),window.Strigo.stopElementSelector();break}case"submit-assessment":{debugger;let K=window.sessionStorage.getItem(Wi),X=ji(window.location.href);window.opener.postMessage({assessment:{...U.assessment,url:X},recorderWindowId:K},"*"),window.close();break}case"cancel-assessment":{window.close();break}default:break}},!1)}var Ye=typeof window!="undefined"?window:null,Xa=Ye===null,Oo=Xa?void 0:Ye.document,st="addEventListener",at="removeEventListener",Va="getBoundingClientRect",Lo="_a",ct="_b",Jt="_c",es="horizontal",lt=function(){return!1},Yg=Xa?"calc":["","-webkit-","-moz-","-o-"].filter(function(h){var p=Oo.createElement("div");return p.style.cssText="width:"+h+"calc(9px)",!!p.style.length}).shift()+"calc",Jl=function(h){return typeof h=="string"||h instanceof String},Wl=function(h){if(Jl(h)){var p=Oo.querySelector(h);if(!p)throw new Error("Selector "+h+" did not match a DOM element");return p}return h},Ce=function(h,p,C){var E=h[p];return E!==void 0?E:C},ts=function(h,p,C,E){if(p){if(E==="end")return 0;if(E==="center")return h/2}else if(C){if(E==="start")return 0;if(E==="center")return h/2}return h},jg=function(h,p){var C=Oo.createElement("div");return C.className="gutter gutter-"+p,C},zg=function(h,p,C){var E={};return Jl(p)?E[h]=p:E[h]=Yg+"("+p+"% - "+C+"px)",E},Zg=function(h,p){var C;return C={},C[h]=p+"px",C},qg=function(h,p){if(p===void 0&&(p={}),Xa)return{};var C=h,E,b,U,K,X,oA;Array.from&&(C=Array.from(C));var yA=Wl(C[0]),$=yA.parentNode,CA=getComputedStyle?getComputedStyle($):null,TA=CA?CA.flexDirection:null,BA=Ce(p,"sizes")||C.map(function(){return 100/C.length}),ce=Ce(p,"minSize",100),fA=Array.isArray(ce)?ce:C.map(function(){return ce}),NA=Ce(p,"maxSize",1/0),ue=Array.isArray(NA)?NA:C.map(function(){return NA}),Ut=Ce(p,"expandToMin",!1),GA=Ce(p,"gutterSize",10),OA=Ce(p,"gutterAlign","center"),Ue=Ce(p,"snapOffset",30),G=Array.isArray(Ue)?Ue:C.map(function(){return Ue}),zA=Ce(p,"dragInterval",1),WA=Ce(p,"direction",es),ye=Ce(p,"cursor",WA===es?"col-resize":"row-resize"),ut=Ce(p,"gutter",jg),yt=Ce(p,"elementStyle",zg),Yt=Ce(p,"gutterStyle",Zg);WA===es?(E="width",b="clientX",U="left",K="right",X="clientWidth"):WA==="vertical"&&(E="height",b="clientY",U="top",K="bottom",X="clientHeight");function AA(k,D,W,iA){var ZA=yt(E,D,W,iA);Object.keys(ZA).forEach(function(cA){k.style[cA]=ZA[cA]})}function HA(k,D,W){var iA=Yt(E,D,W);Object.keys(iA).forEach(function(ZA){k.style[ZA]=iA[ZA]})}function Re(){return oA.map(function(k){return k.size})}function _e(k){return"touches"in k?k.touches[0][b]:k[b]}function M(k){var D=oA[this.a],W=oA[this.b],iA=D.size+W.size;D.size=k/this.size*iA,W.size=iA-k/this.size*iA,AA(D.element,D.size,this[ct],D.i),AA(W.element,W.size,this[Jt],W.i)}function eA(k){var D,W=oA[this.a],iA=oA[this.b];!this.dragging||(D=_e(k)-this.start+(this[ct]-this.dragOffset),zA>1&&(D=Math.round(D/zA)*zA),D<=W.minSize+W.snapOffset+this[ct]?D=W.minSize+this[ct]:D>=this.size-(iA.minSize+iA.snapOffset+this[Jt])&&(D=this.size-(iA.minSize+this[Jt])),D>=W.maxSize-W.snapOffset+this[ct]?D=W.maxSize+this[ct]:D<=this.size-(iA.maxSize-iA.snapOffset+this[Jt])&&(D=this.size-(iA.maxSize+this[Jt])),M.call(this,D),Ce(p,"onDrag",lt)(Re()))}function Y(){var k=oA[this.a].element,D=oA[this.b].element,W=k[Va](),iA=D[Va]();this.size=W[E]+iA[E]+this[ct]+this[Jt],this.start=W[U],this.end=W[K]}function aA(k){if(!getComputedStyle)return null;var D=getComputedStyle(k);if(!D)return null;var W=k[X];return W===0?null:(WA===es?W-=parseFloat(D.paddingLeft)+parseFloat(D.paddingRight):W-=parseFloat(D.paddingTop)+parseFloat(D.paddingBottom),W)}function UA(k){var D=aA($);if(D===null||fA.reduce(function(cA,ie){return cA+ie},0)>D)return k;var W=0,iA=[],ZA=k.map(function(cA,ie){var He=D*cA/100,YA=ts(GA,ie===0,ie===k.length-1,OA),Pe=fA[ie]+YA;return He0&&iA[ie]-W>0){var YA=Math.min(W,iA[ie]-W);W-=YA,He=cA-YA}return He/D*100})}function V(){var k=this,D=oA[k.a].element,W=oA[k.b].element;k.dragging&&Ce(p,"onDragEnd",lt)(Re()),k.dragging=!1,Ye[at]("mouseup",k.stop),Ye[at]("touchend",k.stop),Ye[at]("touchcancel",k.stop),Ye[at]("mousemove",k.move),Ye[at]("touchmove",k.move),k.stop=null,k.move=null,D[at]("selectstart",lt),D[at]("dragstart",lt),W[at]("selectstart",lt),W[at]("dragstart",lt),D.style.userSelect="",D.style.webkitUserSelect="",D.style.MozUserSelect="",D.style.pointerEvents="",W.style.userSelect="",W.style.webkitUserSelect="",W.style.MozUserSelect="",W.style.pointerEvents="",k.gutter.style.cursor="",k.parent.style.cursor="",Oo.body.style.cursor=""}function FA(k){if(!("button"in k&&k.button!==0)){var D=this,W=oA[D.a].element,iA=oA[D.b].element;D.dragging||Ce(p,"onDragStart",lt)(Re()),k.preventDefault(),D.dragging=!0,D.move=eA.bind(D),D.stop=V.bind(D),Ye[st]("mouseup",D.stop),Ye[st]("touchend",D.stop),Ye[st]("touchcancel",D.stop),Ye[st]("mousemove",D.move),Ye[st]("touchmove",D.move),W[st]("selectstart",lt),W[st]("dragstart",lt),iA[st]("selectstart",lt),iA[st]("dragstart",lt),W.style.userSelect="none",W.style.webkitUserSelect="none",W.style.MozUserSelect="none",W.style.pointerEvents="none",iA.style.userSelect="none",iA.style.webkitUserSelect="none",iA.style.MozUserSelect="none",iA.style.pointerEvents="none",D.gutter.style.cursor=ye,D.parent.style.cursor=ye,Oo.body.style.cursor=ye,Y.call(D),D.dragOffset=_e(k)-D.end}}BA=UA(BA);var wA=[];oA=C.map(function(k,D){var W={element:Wl(k),size:BA[D],minSize:fA[D],maxSize:ue[D],snapOffset:G[D],i:D},iA;if(D>0&&(iA={a:D-1,b:D,dragging:!1,direction:WA,parent:$},iA[ct]=ts(GA,D-1===0,!1,OA),iA[Jt]=ts(GA,!1,D===C.length-1,OA),TA==="row-reverse"||TA==="column-reverse")){var ZA=iA.a;iA.a=iA.b,iA.b=ZA}if(D>0){var cA=ut(D,WA,W.element);HA(cA,GA,D),iA[Lo]=FA.bind(iA),cA[st]("mousedown",iA[Lo]),cA[st]("touchstart",iA[Lo]),$.insertBefore(cA,W.element),iA.gutter=cA}return AA(W.element,W.size,ts(GA,D===0,D===C.length-1,OA),D),D>0&&wA.push(iA),W});function JA(k){var D=k.i===wA.length,W=D?wA[k.i-1]:wA[k.i];Y.call(W);var iA=D?W.size-k.minSize-W[Jt]:k.minSize+W[ct];M.call(W,iA)}oA.forEach(function(k){var D=k.element[Va]()[E];D0){var ZA=wA[iA-1],cA=oA[ZA.a],ie=oA[ZA.b];cA.size=D[iA-1],ie.size=W,AA(cA.element,cA.size,ZA[ct],cA.i),AA(ie.element,ie.size,ZA[Jt],ie.i)}})}function VA(k,D){wA.forEach(function(W){if(D!==!0?W.parent.removeChild(W.gutter):(W.gutter[at]("mousedown",W[Lo]),W.gutter[at]("touchstart",W[Lo])),k!==!0){var iA=yt(E,W.a.size,W[ct]);Object.keys(iA).forEach(function(ZA){oA[W.a].element.style[ZA]="",oA[W.b].element.style[ZA]=""})}})}return{setSizes:vA,getSizes:Re,collapse:function(D){JA(oA[D])},destroy:VA,parent:$,pairs:wA}},Wa=qg;var $g=` + `),console.log("Appending overlay selector element."),h.body.appendChild(b),h.addEventListener("mouseover",this.mouseOverEvent),h.addEventListener("mouseout",this.removeClickListenerFromHoveredElement),window.focus(),h.body.focus(),window.addEventListener("keydown",this.onEscSelection,!0)},this.onEscSelection=b=>{b.key==="Escape"&&(console.log("Aborting element selection...",b.key),this.stopElementSelection())},this.stopElementSelection=()=>{this.removeOverlayElement(),window.removeEventListener("keydown",this.onEscSelection,!0),p.onElementSelectionCancel()},{startElementSelector:this.startElementSelector,stopElementSelection:this.stopElementSelection}}function Xg(h,p){let C=document.getElementById("strigo-assessment-recorder-iframe"),{nodeTree:E}=h,b=To(E);(0,Vl.default)(document.querySelector(b),{backgroundColor:"#c6c7e7"}).then(U=>{let K={imageData:U.toDataURL(),profile:h,querySelector:b};C.contentWindow.postMessage(JSON.stringify({messageType:"end-capture",payload:{elementType:p,selectedElement:K},windowName:window.name}),"*"),C.classList.replace("slide-from-opened-to-minimized","slide-from-minimized-to-opened")})}function Wg(h){L.info("Aborting element selection...");let p=document.getElementById("strigo-assessment-recorder-iframe");p.classList.replace("slide-from-opened-to-minimized","slide-from-minimized-to-opened"),p.contentWindow.postMessage(JSON.stringify({messageType:"end-capture",payload:{elementType:h,selectedElement:null},windowName:window.name}),"*")}function Xl(){if(document.getElementById("strigo-assessment-recorder-iframe"))return;let h=Bl();hr({parentElement:pr(),url:dl()});let p=xo({classNames:["strigo-assessment-recorder-iframe","opened"],id:"strigo-assessment-recorder-iframe",parentElement:window.document.body,url:h});window.addEventListener("message",C=>{if(!C||!C.data||C.origin!==h)return;let E;try{E=JSON.parse(C.data)}catch{return}let{messageType:b,payload:U}=E;switch(b){case"start-capture":{L.info("Start capturing message received"),p.classList.replace("opened","slide-from-opened-to-minimized")||p.classList.replace("slide-from-minimized-to-opened","slide-from-opened-to-minimized");let{elementType:X,rootElementSelector:oA}=U?.captureParams;window.Strigo.startElementSelector(yA=>Xg(yA,X),()=>Wg(X),oA);break}case"stop-capture":{L.info("Stop capturing message received"),p.classList.replace("slide-from-opened-to-minimized","slide-from-minimized-to-opened"),window.Strigo.stopElementSelector();break}case"submit-assessment":{let K=window.sessionStorage.getItem(Wi),X=ji(window.location.href);window.opener.postMessage({assessment:{...U.assessment,url:X},recorderWindowId:K},"*"),window.close();break}case"cancel-assessment":{window.close();break}default:break}},!1)}var Ye=typeof window!="undefined"?window:null,Xa=Ye===null,Oo=Xa?void 0:Ye.document,st="addEventListener",at="removeEventListener",Va="getBoundingClientRect",Lo="_a",ct="_b",Jt="_c",es="horizontal",lt=function(){return!1},Yg=Xa?"calc":["","-webkit-","-moz-","-o-"].filter(function(h){var p=Oo.createElement("div");return p.style.cssText="width:"+h+"calc(9px)",!!p.style.length}).shift()+"calc",Jl=function(h){return typeof h=="string"||h instanceof String},Wl=function(h){if(Jl(h)){var p=Oo.querySelector(h);if(!p)throw new Error("Selector "+h+" did not match a DOM element");return p}return h},Ce=function(h,p,C){var E=h[p];return E!==void 0?E:C},ts=function(h,p,C,E){if(p){if(E==="end")return 0;if(E==="center")return h/2}else if(C){if(E==="start")return 0;if(E==="center")return h/2}return h},jg=function(h,p){var C=Oo.createElement("div");return C.className="gutter gutter-"+p,C},zg=function(h,p,C){var E={};return Jl(p)?E[h]=p:E[h]=Yg+"("+p+"% - "+C+"px)",E},Zg=function(h,p){var C;return C={},C[h]=p+"px",C},qg=function(h,p){if(p===void 0&&(p={}),Xa)return{};var C=h,E,b,U,K,X,oA;Array.from&&(C=Array.from(C));var yA=Wl(C[0]),$=yA.parentNode,CA=getComputedStyle?getComputedStyle($):null,TA=CA?CA.flexDirection:null,BA=Ce(p,"sizes")||C.map(function(){return 100/C.length}),ce=Ce(p,"minSize",100),fA=Array.isArray(ce)?ce:C.map(function(){return ce}),NA=Ce(p,"maxSize",1/0),ue=Array.isArray(NA)?NA:C.map(function(){return NA}),Ut=Ce(p,"expandToMin",!1),GA=Ce(p,"gutterSize",10),OA=Ce(p,"gutterAlign","center"),Ue=Ce(p,"snapOffset",30),G=Array.isArray(Ue)?Ue:C.map(function(){return Ue}),zA=Ce(p,"dragInterval",1),WA=Ce(p,"direction",es),ye=Ce(p,"cursor",WA===es?"col-resize":"row-resize"),ut=Ce(p,"gutter",jg),yt=Ce(p,"elementStyle",zg),Yt=Ce(p,"gutterStyle",Zg);WA===es?(E="width",b="clientX",U="left",K="right",X="clientWidth"):WA==="vertical"&&(E="height",b="clientY",U="top",K="bottom",X="clientHeight");function AA(k,D,W,iA){var ZA=yt(E,D,W,iA);Object.keys(ZA).forEach(function(cA){k.style[cA]=ZA[cA]})}function HA(k,D,W){var iA=Yt(E,D,W);Object.keys(iA).forEach(function(ZA){k.style[ZA]=iA[ZA]})}function Re(){return oA.map(function(k){return k.size})}function _e(k){return"touches"in k?k.touches[0][b]:k[b]}function M(k){var D=oA[this.a],W=oA[this.b],iA=D.size+W.size;D.size=k/this.size*iA,W.size=iA-k/this.size*iA,AA(D.element,D.size,this[ct],D.i),AA(W.element,W.size,this[Jt],W.i)}function eA(k){var D,W=oA[this.a],iA=oA[this.b];!this.dragging||(D=_e(k)-this.start+(this[ct]-this.dragOffset),zA>1&&(D=Math.round(D/zA)*zA),D<=W.minSize+W.snapOffset+this[ct]?D=W.minSize+this[ct]:D>=this.size-(iA.minSize+iA.snapOffset+this[Jt])&&(D=this.size-(iA.minSize+this[Jt])),D>=W.maxSize-W.snapOffset+this[ct]?D=W.maxSize+this[ct]:D<=this.size-(iA.maxSize-iA.snapOffset+this[Jt])&&(D=this.size-(iA.maxSize+this[Jt])),M.call(this,D),Ce(p,"onDrag",lt)(Re()))}function Y(){var k=oA[this.a].element,D=oA[this.b].element,W=k[Va](),iA=D[Va]();this.size=W[E]+iA[E]+this[ct]+this[Jt],this.start=W[U],this.end=W[K]}function aA(k){if(!getComputedStyle)return null;var D=getComputedStyle(k);if(!D)return null;var W=k[X];return W===0?null:(WA===es?W-=parseFloat(D.paddingLeft)+parseFloat(D.paddingRight):W-=parseFloat(D.paddingTop)+parseFloat(D.paddingBottom),W)}function UA(k){var D=aA($);if(D===null||fA.reduce(function(cA,ie){return cA+ie},0)>D)return k;var W=0,iA=[],ZA=k.map(function(cA,ie){var He=D*cA/100,YA=ts(GA,ie===0,ie===k.length-1,OA),Pe=fA[ie]+YA;return He0&&iA[ie]-W>0){var YA=Math.min(W,iA[ie]-W);W-=YA,He=cA-YA}return He/D*100})}function V(){var k=this,D=oA[k.a].element,W=oA[k.b].element;k.dragging&&Ce(p,"onDragEnd",lt)(Re()),k.dragging=!1,Ye[at]("mouseup",k.stop),Ye[at]("touchend",k.stop),Ye[at]("touchcancel",k.stop),Ye[at]("mousemove",k.move),Ye[at]("touchmove",k.move),k.stop=null,k.move=null,D[at]("selectstart",lt),D[at]("dragstart",lt),W[at]("selectstart",lt),W[at]("dragstart",lt),D.style.userSelect="",D.style.webkitUserSelect="",D.style.MozUserSelect="",D.style.pointerEvents="",W.style.userSelect="",W.style.webkitUserSelect="",W.style.MozUserSelect="",W.style.pointerEvents="",k.gutter.style.cursor="",k.parent.style.cursor="",Oo.body.style.cursor=""}function FA(k){if(!("button"in k&&k.button!==0)){var D=this,W=oA[D.a].element,iA=oA[D.b].element;D.dragging||Ce(p,"onDragStart",lt)(Re()),k.preventDefault(),D.dragging=!0,D.move=eA.bind(D),D.stop=V.bind(D),Ye[st]("mouseup",D.stop),Ye[st]("touchend",D.stop),Ye[st]("touchcancel",D.stop),Ye[st]("mousemove",D.move),Ye[st]("touchmove",D.move),W[st]("selectstart",lt),W[st]("dragstart",lt),iA[st]("selectstart",lt),iA[st]("dragstart",lt),W.style.userSelect="none",W.style.webkitUserSelect="none",W.style.MozUserSelect="none",W.style.pointerEvents="none",iA.style.userSelect="none",iA.style.webkitUserSelect="none",iA.style.MozUserSelect="none",iA.style.pointerEvents="none",D.gutter.style.cursor=ye,D.parent.style.cursor=ye,Oo.body.style.cursor=ye,Y.call(D),D.dragOffset=_e(k)-D.end}}BA=UA(BA);var wA=[];oA=C.map(function(k,D){var W={element:Wl(k),size:BA[D],minSize:fA[D],maxSize:ue[D],snapOffset:G[D],i:D},iA;if(D>0&&(iA={a:D-1,b:D,dragging:!1,direction:WA,parent:$},iA[ct]=ts(GA,D-1===0,!1,OA),iA[Jt]=ts(GA,!1,D===C.length-1,OA),TA==="row-reverse"||TA==="column-reverse")){var ZA=iA.a;iA.a=iA.b,iA.b=ZA}if(D>0){var cA=ut(D,WA,W.element);HA(cA,GA,D),iA[Lo]=FA.bind(iA),cA[st]("mousedown",iA[Lo]),cA[st]("touchstart",iA[Lo]),$.insertBefore(cA,W.element),iA.gutter=cA}return AA(W.element,W.size,ts(GA,D===0,D===C.length-1,OA),D),D>0&&wA.push(iA),W});function JA(k){var D=k.i===wA.length,W=D?wA[k.i-1]:wA[k.i];Y.call(W);var iA=D?W.size-k.minSize-W[Jt]:k.minSize+W[ct];M.call(W,iA)}oA.forEach(function(k){var D=k.element[Va]()[E];D0){var ZA=wA[iA-1],cA=oA[ZA.a],ie=oA[ZA.b];cA.size=D[iA-1],ie.size=W,AA(cA.element,cA.size,ZA[ct],cA.i),AA(ie.element,ie.size,ZA[Jt],ie.i)}})}function VA(k,D){wA.forEach(function(W){if(D!==!0?W.parent.removeChild(W.gutter):(W.gutter[at]("mousedown",W[Lo]),W.gutter[at]("touchstart",W[Lo])),k!==!0){var iA=yt(E,W.a.size,W[ct]);Object.keys(iA).forEach(function(ZA){oA[W.a].element.style[ZA]="",oA[W.b].element.style[ZA]=""})}})}return{setSizes:vA,getSizes:Re,collapse:function(D){JA(oA[D])},destroy:VA,parent:$,pairs:wA}},Wa=qg;var $g=`
Expected text: ${C?.recordedAssessment?.expectedText}
Selector used: ${p}
- `,b.children[0].children[1].appendChild(K),L.info("*** Appending assessment debug context element.");let oA=window.document.querySelectorAll(`[data-${su}="${p}"]`)?.[0];oA?oA.appendChild(b):bd(h,p).appendChild(b)},cu=function(){L.info("*** Evaluating Assessments...",{bodyTextDuringAssessment:window.document.body.innerText.slice(0,50)}),uu.filter(({recordedAssessment:p})=>{let C=p?.locationElement?.profile?.recordedElementInfo?.url;if(!C)return!1;let E=window.location.href;return iu(C,E)}).forEach(p=>{let{recordedAssessment:C,challengeSuccessEvent:E,_id:b}=p,{actionType:U,expectedText:K}=C,X=C?.locationElement?.profile;if(!X){L.info("*** missing location element profile. Aborting...");return}if(Pn?.[b]?.status==="SUCCESS"){L.info('*** Assessment already in "success" status. Aborting...');return}$a(b,{status:"pending"});let oA;try{oA=Ed(b,X)}catch{L.info("*** Failed to find location element. Aborting assessment evaluation...");return}let yA=oe()?.isAcademyAssessmentDebug,{locationElement:$,locationElementSelector:CA}=oA;switch(yA&&Id($,CA,p),U){case"added-item":{let TA=Fd.bind({assessment:p,locationElement:$,window});if(Ct[b]?.observer&&$===Ct[b].element){Ct[b].element=$;try{TA([]),Ct[b].observer.observe($,Za),L.info("Same reference - no need to observe again"),L.info(" *** Same reference - no need to observe again",{locationElement:$})}catch(BA){L.error("*** Got an error in item count",{err:BA});break}break}if(Ct[b]?.observer){try{TA([]),Ct[b].observer.observe($,Za),L.info("DOM Reference have changed - observing again"),L.info(" *** DOM Reference have changed - observing again",{locationElement:$})}catch(BA){L.error("*** Got an error in item count",{err:BA});break}break}Ct[b]={element:$,observer:new MutationObserver(TA)};try{TA([]),Ct[b].observer.observe($,Za)}catch(BA){L.info("*** Got an error in item count",BA);break}break}case"text-change":{if(L.info("*** Assessing text changes in location element...",{locationElement:$,locationElementType:$ instanceof HTMLInputElement?"input":"non-input",innerTextValue:$ instanceof HTMLInputElement?$?.value:$?.innerText,expectedText:K}),$ instanceof HTMLInputElement&&$?.value?.includes(K)){qa(p,{locationElement:$});break}if($?.innerText?.includes(K)){qa(p,{locationElement:$});break}break}default:break}})},Sd=function(h){let p=h.some(E=>E.addedNodes?.length>0),C=h.some(E=>E.type=="characterData");if(L.info("#####",{isAddedNodes:p,isCharacterDataChanged:C}),!p&&!C){L.info("*** No added nodes and no character data change were detected after url change.",{previousLocation:Do||"",newLocation:document.location.href});return}Do===document.location.href?L.info("*** No URL change and no nodes were added."):(L.info("*** Detected URL change!",{previousLocation:Do||"",newLocation:document.location.href}),Do=document.location.href),Ac(window)},Ac=(0,lu.default)(h=>{if(L.info("*** Initializing document observer"),uu=_a().assessments.filter(({assessmentType:p})=>p==="recorded-flow"),!window?.strigoObserver?.observer){L.info("*** Adding Strigo observer to document body"),window.strigoObserver={observer:new MutationObserver(Sd),observedBodyElement:window.document.body},cu(),L.info("*** Starting to observe document body"),window?.strigoObserver?.observer?.observe(window.document,au);return}cu(),window.document.contains(window.strigoObserver.observedBodyElement)||(L.info('*** Detected a "body" element change. Re-initializing the document observer...'),window.strigoObserver.observedBodyElement=window.document.body,window.strigoObserver.observer.observe(window.document,au))},500);var Bu=Fo(za(),1);var gu={subtree:!0,childList:!0},ns;function pu(h){try{window["localStorage"].setItem("strigoUrlTriggers",JSON.stringify(h))}catch(p){return L.error("Url triggers setup error",{error:p}),null}}function xd(){try{let h=window["localStorage"].getItem("strigoUrlTriggers");if(h)return JSON.parse(h)}catch(h){return L.error("Get url triggers error",{error:h}),null}}function du(h){let p=document.getElementById("strigo-exercises"),C=h.document.location.href,E=xd();if(!!E)for(let b of E){let{publishmentId:U,urlTriggerMatchType:K,urlTriggerUrl:X}=b;switch(K){case"exact":{X.trim()===C.trim()&&(p.contentWindow.postMessage({selectedCourseId:U},"*"),zr());break}case"starts_with":{C.trim().startsWith(X.trim())&&(p.contentWindow.postMessage({selectedCourseId:U},"*"),zr());break}default:break}}}var Td=function(h){let p=h.some(C=>C.addedNodes?.length>0);if(L.info("#####",{isAddedNodes:p}),!p){L.info("*** No added nodes and no character data change were detected after url change.",{previousLocation:ns||"",newLocation:document.location.href});return}ns===document.location.href?L.info("*** No URL change and no nodes were added."):(L.info("*** Detected URL change!",{previousLocation:ns||"",newLocation:document.location.href}),ns=document.location.href),ec(window)},ec=(0,Bu.default)(h=>{if(L.info("*** Initializing url trigger observer"),!h?.strigoUrlTriggerObserver?.observer){L.info("*** Adding Strigo url trigger observer to document body"),h.strigoUrlTriggerObserver={observer:new MutationObserver(Td),observedBodyElement:h.document.body},du(h),L.info("*** Starting to observe document body - url trigger observer"),h?.strigoUrlTriggerObserver?.observer?.observe(h.document,gu);return}du(h),h.document.contains(h.strigoUrlTriggerObserver.observedBodyElement)||(L.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,gu))},500);var hu=342;function wu(){L.info("Posting dockable state to Strigo...");let h=Br("dockingSide");document.getElementById("strigo-exercises").contentWindow.postMessage({dockable:!0,dockingSide:h},"*")}function Od(){let[h]=As();(0,tc.default)("#strigo-widget").resizable({edges:{left:"#strigo-collapse-div",right:"#strigo-collapse-div.align-left",bottom:!1,top:!1},listeners:{move(p){let C=p.target;C.style.width=`${p.rect.widthh?h:p.rect.width}px`},start(){let p=document.getElementById("strigo-exercises");p.style.pointerEvents="none"},end(){let p=document.getElementById("strigo-exercises");p.style.pointerEvents="auto"}},modifiers:[tc.default.modifiers.restrictEdges({outer:"parent"})]})}var mu=class{init(){return L.info("overlay init called"),"OVERLAY"}setup({version:p}){L.info("overlay setup called"),hr({parentElement:pr(),url:gl(p)}),hr({parentElement:pr(),url:Yi(p)});let C=oe(),E=sessionStorage.getItem("strigoPreviewUserToken"),b=!!E,U=_l(Ji({...C,user:{token:{token:E||C.user.token.token,expiration:C.user.token.expiration},email:C.user.email}},b)),K=Ho();this.initEventListeners(K,U),L.info("adding assessment document observer"),Ac(K),ec(K),Pl(K),L.info("assessment document observer added"),Od()}shutdown(){L.info("overlay shutdown called");let p=Ho();this.removeEventListeners(p),p?.strigoObserver?.observer?.disconnect(),Ml(p)}collapse(){L.info("overlay collapse called"),Ga()}open(){zr(),wu()}move(){Kl()}initEventListeners(p,C){is(C,wu),os(p)}removeEventListeners(p){Qu()}},Ko=new mu;function Uu(h){if(!(!h||!h.data))switch(h.data){case"move":{L.info("Panel move message received"),So()==="overlay"&&Ko.move();break}case"close":{L.info("Shutdown message received - will collapse panel"),window.Strigo?.collapse();break}case"destroy":{L.info("Destroy message received"),window.Strigo?.destroy();break}case"challenge-success":{L.info("Challenge event success received"),So()==="overlay"&&Ko.open();break}default:break}}function os(h){h.addEventListener("message",Uu,!1)}function Qu(){window.removeEventListener("message",Uu)}function is(h,p){h.addEventListener("load",async()=>{yl("isLoading")&&(p&&await p(),$i("isLoading",!1))})}function yu(h){let p=Br("initSite")?.host;h.addEventListener("load",function(){try{this.contentWindow.location.host!==p&&window.Strigo.shutdown()}catch(C){L.error(C),window.Strigo.shutdown()}})}function Fu(){return Wa(["#strigo-exercises","#original-site"],{sizes:[25,75],maxSize:As(),minSize:Ol(),gutterSize:2})}async function Kd(){await jl(),document.getElementById("strigo-exercises").contentWindow.postMessage({dockable:!1},"*")}var Eu=class{init(){let p;return cl()?(L.info("Child SDK window"),p="CHILD",window.dispatchEvent(new Event("strigo-opened")),ll()):(L.info("Parent SDK window"),p="PARENT"),p}setup({version:p}){L.info("iframe setup started"),Hl(),hr({parentElement:pr(),url:fl(p)}),hr({parentElement:pr(),url:Yi(p)}),Yl();let C=oe(),E=xl(),b=xo({parentElement:E,url:Ji(C),classNames:Al,id:"strigo-exercises"}),U=xo({parentElement:E,url:al(C.initSite.href),classNames:el,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=Fu()};let X=document.createElement("div");X.className="strigo-academy-hat-icon",X.id="strigo-academy-hat-icon",X.innerHTML=Xi,K.appendChild(X),E.appendChild(K),this.splitInstance=Fu();let oA=Ho();this.initEventListeners(oA,b,U)}collapse(){this.splitInstance&&(this.splitInstance.destroy(),this.splitInstance=Wa(["#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(){L.info("iframe shutdown called"),Tl()}initEventListeners(p,C,E){is(C,Kd),yu(E),os(E.contentWindow)}},bu=new Eu;function Iu(h){return h&&h==="dynamic"?Dl()?"iframe":"overlay":h}function Mo(h){let p=null;switch(h){case"iframe":{p=bu;break}case"overlay":{p=Ko;break}default:throw L.error("Widget flavor is not supported",{widgetFlavor:h}),new Error(`Widget flavor ${h} is not supported`)}return p}var Su=class{constructor(){this.config={}}isDevelopment(){return!1}init(){try{if(L.info("Initializing SDK..."),this.config.initialized){L.info("SDK was already initialized");return}El();let{webApiKey:p,subDomain:C,selectedWidgetFlavor:E}=ul();if(!p||!C||!E)throw new Error("Init data is missing");let b=Iu(E);hl({webApiKey:p,subDomain:C,selectedWidgetFlavor:b});let U=Mo(b);if(this.config.sdkType=U.init(),this.config.initialized=!0,L.info("Initialized SDK."),this.config.sdkType!=="CHILD"&&_n()){let K=oe()?.user?.token,X=sessionStorage.getItem("strigoPreviewUserToken"),oA=X?{token:{token:X,expiration:`${Date.now()+1e3*60*60*24}`},isPreview:!0}:{token:K};this.setup(oA)}}catch(p){L.error("Could not initialize SDK",{err:p})}}async setup(p){try{L.info("Starting to setup SDK...");let C=document.getElementById("strigo-widget");if(this.config.isOpen&&C||this.config.sdkType==="CHILD"){L.info('panel is already opened. Aborting "setup" action...');return}if(!this.config.initialized)throw new Error("SDK was not initialized");let b=oe(),{email:U,token:K,version:X,openWidget:oA=!0,dockingSide:yA="right",isPreview:$}={...b.user,...b,...p};if(!U||!K)throw new Error("Setup data is missing");let CA=await Ql(K);if(!CA?.allowedAcademyDomains?.includes(window.location.host.replace(/^www\./i,""))){L.warn("Running on an unrelated domain. Aborting...",{allowedDomains:CA?.allowedAcademyDomains,currentHost:window.location.host});return}if(CA){let{loggingConfig:TA,userAssessments:BA}=CA;L.debug("Configuration fetched from Strigo"),L.setup(TA),bl(BA),CA.academyColors&&Nl(CA.academyColors),CA.urlTriggers&&pu(CA.urlTriggers)}$||wl({user:{email:U,token:K},initSite:sl(),version:X,loggingConfig:CA?.loggingConfig,assessmentThresholds:CA?.assessmentThresholds,isAcademyAssessmentDebug:CA?.isAcademyAssessmentDebug,dockingSide:yA}),this.config.configured=!0,L.info("Finished SDK setup."),oA&&this.open()}catch(C){L.error("Could not setup SDK",{err:C})}}open(){try{if(L.info("Opening academy panel..."),!this.config.configured)throw new Error("SDK was not set up");let p=document.getElementById("strigo-widget");if(this.config.isOpen&&p||this.config.sdkType==="CHILD"){L.info('Panel is already opened. Aborting "open" action...');return}let E=oe();Ul({currentUrl:E.initSite.href,shouldPanelBeOpen:_n(),isLoading:!0,widgetFlavor:E.selectedWidgetFlavor}),Mo(E.selectedWidgetFlavor).setup({version:E.version}),this.config.isOpen=!0,L.info("Opened academy panel.")}catch(p){L.error("Could not open academy panel",{err:p})}}collapse(){L.info("Collapsing academy panel");let{selectedWidgetFlavor:p}=oe();Mo(p).collapse()}shutdown(){try{if(L.info("Closing academy panel..."),this.config.sdkType==="CHILD"){window.parent.postMessage(JSON.stringify({messageType:"close"}),"*"),L.info("Notified parent frame to close academy panel.");return}if(!this.config.isOpen){L.info("Tried to close unopened academy panel");return}let p=Mo(So());Fl(),p.collapse(),p.shutdown(),this.config.isOpen=!1,L.info("Closed academy panel.")}catch(p){L.error("Could not close academy panel",{err:p})}}destroy(){try{if(L.info("Destroying SDK..."),this.config.sdkType==="CHILD"){window.parent.postMessage(JSON.stringify({messageType:"destroy"}),"*"),L.info("Notified parent frame to destroy SDK.");return}ml(),Il(),this.shutdown(),this.config={},L.info("Destroyed SDK.")}catch(p){L.error("Could not destroy SDK",{err:p})}}async sendEvent(p){let C=Br("user"),{token:E}=C;await Cl(E,p),L.debug("sendEvent called",{eventName:p})}startElementSelector(p,C,E){L.debug("startElementSelector called");let b=E?window.document.querySelector(E):window.document.body,{startElementSelector:U,stopElementSelection:K}=kl(window.document,{onElementProfileCreated:p,onElementSelectionCancel:C,zIndex:2147483645,rootElement:b});this.stopElementSelector=K,U()}stopElementSelector(){}assessmentRecorder(){Xl()}},Hu=new Su;window.Strigo=Hu;window.Strigo.init();})(); + `,b.children[0].children[1].appendChild(K),L.info("*** Appending assessment debug context element.");let oA=window.document.querySelectorAll(`[data-${su}="${p}"]`)?.[0];oA?oA.appendChild(b):bd(h,p).appendChild(b)},cu=function(){L.info("*** Evaluating Assessments...",{bodyTextDuringAssessment:window.document.body.innerText.slice(0,50)}),uu.filter(({recordedAssessment:p})=>{let C=p?.locationElement?.profile?.recordedElementInfo?.url;if(!C)return!1;let E=window.location.href;return iu(C,E)}).forEach(p=>{let{recordedAssessment:C,challengeSuccessEvent:E,_id:b}=p,{actionType:U,expectedText:K}=C,X=C?.locationElement?.profile;if(!X){L.info("*** missing location element profile. Aborting...");return}if(Pn?.[b]?.status==="SUCCESS"){L.info('*** Assessment already in "success" status. Aborting...');return}$a(b,{status:"pending"});let oA;try{oA=Ed(b,X)}catch{L.info("*** Failed to find location element. Aborting assessment evaluation...");return}let yA=oe()?.isAcademyAssessmentDebug,{locationElement:$,locationElementSelector:CA}=oA;switch(yA&&Id($,CA,p),U){case"added-item":{let TA=Fd.bind({assessment:p,locationElement:$,window});if(Ct[b]?.observer&&$===Ct[b].element){Ct[b].element=$;try{TA([]),Ct[b].observer.observe($,Za),L.info("Same reference - no need to observe again"),L.info(" *** Same reference - no need to observe again",{locationElement:$})}catch(BA){L.error("*** Got an error in item count",{err:BA});break}break}if(Ct[b]?.observer){try{TA([]),Ct[b].observer.observe($,Za),L.info("DOM Reference have changed - observing again"),L.info(" *** DOM Reference have changed - observing again",{locationElement:$})}catch(BA){L.error("*** Got an error in item count",{err:BA});break}break}Ct[b]={element:$,observer:new MutationObserver(TA)};try{TA([]),Ct[b].observer.observe($,Za)}catch(BA){L.info("*** Got an error in item count",BA);break}break}case"text-change":{if(L.info("*** Assessing text changes in location element...",{locationElement:$,locationElementType:$ instanceof HTMLInputElement?"input":"non-input",innerTextValue:$ instanceof HTMLInputElement?$?.value:$?.innerText,expectedText:K}),$ instanceof HTMLInputElement&&$?.value?.includes(K)){qa(p,{locationElement:$});break}if($?.innerText?.includes(K)){qa(p,{locationElement:$});break}break}default:break}})},Sd=function(h){let p=h.some(E=>E.addedNodes?.length>0),C=h.some(E=>E.type=="characterData");if(L.info("#####",{isAddedNodes:p,isCharacterDataChanged:C}),!p&&!C){L.info("*** No added nodes and no character data change were detected after url change.",{previousLocation:Do||"",newLocation:document.location.href});return}Do===document.location.href?L.info("*** No URL change and no nodes were added."):(L.info("*** Detected URL change!",{previousLocation:Do||"",newLocation:document.location.href}),Do=document.location.href),Ac(window)},Ac=(0,lu.default)(h=>{if(L.info("*** Initializing document observer"),uu=_a().assessments.filter(({assessmentType:p})=>p==="recorded-flow"),!window?.strigoObserver?.observer){L.info("*** Adding Strigo observer to document body"),window.strigoObserver={observer:new MutationObserver(Sd),observedBodyElement:window.document.body},cu(),L.info("*** Starting to observe document body"),window?.strigoObserver?.observer?.observe(window.document,au);return}cu(),window.document.contains(window.strigoObserver.observedBodyElement)||(L.info('*** Detected a "body" element change. Re-initializing the document observer...'),window.strigoObserver.observedBodyElement=window.document.body,window.strigoObserver.observer.observe(window.document,au))},500);var Bu=Fo(za(),1);var gu={subtree:!0,childList:!0},ns;function pu(h){try{window["localStorage"].setItem("strigoUrlTriggers",JSON.stringify(h))}catch(p){return L.error("Url triggers setup error",{error:p}),null}}function xd(){try{let h=window["localStorage"].getItem("strigoUrlTriggers");if(h)return JSON.parse(h)}catch(h){return L.error("Get url triggers error",{error:h}),null}}function du(h){let p=document.getElementById("strigo-exercises"),C=h.document.location.href,E=xd();if(!!E)for(let b of E){let{publishmentId:U,urlTriggerMatchType:K,urlTriggerUrl:X}=b;switch(K){case"exact":{X.trim()===C.trim()&&(p.contentWindow.postMessage({selectedCourseId:U},"*"),zr());break}case"starts_with":{C.trim().startsWith(X.trim())&&(p.contentWindow.postMessage({selectedCourseId:U},"*"),zr());break}default:break}}}var Td=function(h){let p=h.some(C=>C.addedNodes?.length>0);if(L.info("#####",{isAddedNodes:p}),!p){L.info("*** No added nodes and no character data change were detected after url change.",{previousLocation:ns||"",newLocation:document.location.href});return}ns===document.location.href?L.info("*** No URL change and no nodes were added."):(L.info("*** Detected URL change!",{previousLocation:ns||"",newLocation:document.location.href}),ns=document.location.href),ec(window)},ec=(0,Bu.default)(h=>{if(L.info("*** Initializing url trigger observer"),!h?.strigoUrlTriggerObserver?.observer){L.info("*** Adding Strigo url trigger observer to document body"),h.strigoUrlTriggerObserver={observer:new MutationObserver(Td),observedBodyElement:h.document.body},du(h),L.info("*** Starting to observe document body - url trigger observer"),h?.strigoUrlTriggerObserver?.observer?.observe(h.document,gu);return}du(h),h.document.contains(h.strigoUrlTriggerObserver.observedBodyElement)||(L.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,gu))},500);var hu=342;function wu(){L.info("Posting dockable state to Strigo...");let h=Br("dockingSide");document.getElementById("strigo-exercises").contentWindow.postMessage({dockable:!0,dockingSide:h},"*")}function Od(){let[h]=As();(0,tc.default)("#strigo-widget").resizable({edges:{left:"#strigo-collapse-div",right:"#strigo-collapse-div.align-left",bottom:!1,top:!1},listeners:{move(p){let C=p.target;C.style.width=`${p.rect.widthh?h:p.rect.width}px`},start(){let p=document.getElementById("strigo-exercises");p.style.pointerEvents="none"},end(){let p=document.getElementById("strigo-exercises");p.style.pointerEvents="auto"}},modifiers:[tc.default.modifiers.restrictEdges({outer:"parent"})]})}var mu=class{init(){return L.info("overlay init called"),"OVERLAY"}setup({version:p}){L.info("overlay setup called"),hr({parentElement:pr(),url:gl(p)}),hr({parentElement:pr(),url:Yi(p)});let C=oe(),E=sessionStorage.getItem("strigoPreviewUserToken"),b=!!E,U=_l(Ji({...C,user:{token:{token:E||C.user.token.token,expiration:C.user.token.expiration},email:C.user.email}},b)),K=Ho();this.initEventListeners(K,U),L.info("adding assessment document observer"),Ac(K),ec(K),Pl(K),L.info("assessment document observer added"),Od()}shutdown(){L.info("overlay shutdown called");let p=Ho();this.removeEventListeners(p),p?.strigoObserver?.observer?.disconnect(),Ml(p)}collapse(){L.info("overlay collapse called"),Ga()}open(){zr(),wu()}move(){Kl()}initEventListeners(p,C){is(C,wu),os(p)}removeEventListeners(p){Qu()}},Ko=new mu;function Uu(h){if(!(!h||!h.data))switch(h.data){case"move":{L.info("Panel move message received"),So()==="overlay"&&Ko.move();break}case"close":{L.info("Shutdown message received - will collapse panel"),window.Strigo?.collapse();break}case"destroy":{L.info("Destroy message received"),window.Strigo?.destroy();break}case"challenge-success":{L.info("Challenge event success received"),So()==="overlay"&&Ko.open();break}default:break}}function os(h){h.addEventListener("message",Uu,!1)}function Qu(){window.removeEventListener("message",Uu)}function is(h,p){h.addEventListener("load",async()=>{yl("isLoading")&&(p&&await p(),$i("isLoading",!1))})}function yu(h){let p=Br("initSite")?.host;h.addEventListener("load",function(){try{this.contentWindow.location.host!==p&&window.Strigo.shutdown()}catch(C){L.error(C),window.Strigo.shutdown()}})}function Fu(){return Wa(["#strigo-exercises","#original-site"],{sizes:[25,75],maxSize:As(),minSize:Ol(),gutterSize:2})}async function Kd(){await jl(),document.getElementById("strigo-exercises").contentWindow.postMessage({dockable:!1},"*")}var Eu=class{init(){let p;return cl()?(L.info("Child SDK window"),p="CHILD",window.dispatchEvent(new Event("strigo-opened")),ll()):(L.info("Parent SDK window"),p="PARENT"),p}setup({version:p}){L.info("iframe setup started"),Hl(),hr({parentElement:pr(),url:fl(p)}),hr({parentElement:pr(),url:Yi(p)}),Yl();let C=oe(),E=xl(),b=xo({parentElement:E,url:Ji(C,!1),classNames:Al,id:"strigo-exercises"}),U=xo({parentElement:E,url:al(C.initSite.href),classNames:el,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=Fu()};let X=document.createElement("div");X.className="strigo-academy-hat-icon",X.id="strigo-academy-hat-icon",X.innerHTML=Xi,K.appendChild(X),E.appendChild(K),this.splitInstance=Fu();let oA=Ho();this.initEventListeners(oA,b,U)}collapse(){this.splitInstance&&(this.splitInstance.destroy(),this.splitInstance=Wa(["#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(){L.info("iframe shutdown called"),Tl()}initEventListeners(p,C,E){is(C,Kd),yu(E),os(E.contentWindow)}},bu=new Eu;function Iu(h){return h&&h==="dynamic"?Dl()?"iframe":"overlay":h}function Mo(h){let p=null;switch(h){case"iframe":{p=bu;break}case"overlay":{p=Ko;break}default:throw L.error("Widget flavor is not supported",{widgetFlavor:h}),new Error(`Widget flavor ${h} is not supported`)}return p}var Su=class{constructor(){this.config={}}isDevelopment(){return!1}init(){try{if(L.info("Initializing SDK..."),this.config.initialized){L.info("SDK was already initialized");return}El();let{webApiKey:p,subDomain:C,selectedWidgetFlavor:E}=ul();if(!p||!C||!E)throw new Error("Init data is missing");let b=Iu(E);hl({webApiKey:p,subDomain:C,selectedWidgetFlavor:b});let U=Mo(b);if(this.config.sdkType=U.init(),this.config.initialized=!0,L.info("Initialized SDK."),this.config.sdkType!=="CHILD"&&_n()){let K=oe()?.user?.token,X=sessionStorage.getItem("strigoPreviewUserToken"),oA=X?{token:{token:X,expiration:`${Date.now()+1e3*60*60*24}`},isPreview:!0}:{token:K};this.setup(oA)}}catch(p){L.error("Could not initialize SDK",{err:p})}}async setup(p){try{L.info("Starting to setup SDK...");let C=document.getElementById("strigo-widget");if(this.config.isOpen&&C||this.config.sdkType==="CHILD"){L.info('panel is already opened. Aborting "setup" action...');return}if(!this.config.initialized)throw new Error("SDK was not initialized");let b=oe(),{email:U,token:K,version:X,openWidget:oA=!0,dockingSide:yA="right",isPreview:$}={...b?.user,...b,...p};if(!U||!K)throw new Error("Setup data is missing");let CA=await Ql(K);if(!CA?.allowedAcademyDomains?.includes(window.location.host.replace(/^www\./i,""))){L.warn("Running on an unrelated domain. Aborting...",{allowedDomains:CA?.allowedAcademyDomains,currentHost:window.location.host});return}if(CA){let{loggingConfig:TA,userAssessments:BA}=CA;L.debug("Configuration fetched from Strigo"),L.setup(TA),bl(BA),CA.academyColors&&Nl(CA.academyColors),CA.urlTriggers&&pu(CA.urlTriggers)}$||wl({user:{email:U,token:K},initSite:sl(),version:X,loggingConfig:CA?.loggingConfig,assessmentThresholds:CA?.assessmentThresholds,isAcademyAssessmentDebug:CA?.isAcademyAssessmentDebug,dockingSide:yA}),this.config.configured=!0,L.info("Finished SDK setup."),oA&&this.open()}catch(C){L.error("Could not setup SDK",{err:C})}}open(){try{if(L.info("Opening academy panel..."),!this.config.configured)throw new Error("SDK was not set up");let p=document.getElementById("strigo-widget");if(this.config.isOpen&&p||this.config.sdkType==="CHILD"){L.info('Panel is already opened. Aborting "open" action...');return}let E=oe();Ul({currentUrl:E.initSite.href,shouldPanelBeOpen:_n(),isLoading:!0,widgetFlavor:E.selectedWidgetFlavor}),Mo(E.selectedWidgetFlavor).setup({version:E.version}),this.config.isOpen=!0,L.info("Opened academy panel.")}catch(p){L.error("Could not open academy panel",{err:p})}}collapse(){L.info("Collapsing academy panel");let{selectedWidgetFlavor:p}=oe();Mo(p).collapse()}shutdown(){try{if(L.info("Closing academy panel..."),this.config.sdkType==="CHILD"){window.parent.postMessage(JSON.stringify({messageType:"close"}),"*"),L.info("Notified parent frame to close academy panel.");return}if(!this.config.isOpen){L.info("Tried to close unopened academy panel");return}let p=Mo(So());Fl(),p.collapse(),p.shutdown(),this.config.isOpen=!1,L.info("Closed academy panel.")}catch(p){L.error("Could not close academy panel",{err:p})}}destroy(){try{if(L.info("Destroying SDK..."),this.config.sdkType==="CHILD"){window.parent.postMessage(JSON.stringify({messageType:"destroy"}),"*"),L.info("Notified parent frame to destroy SDK.");return}ml(),Il(),this.shutdown(),this.config={},L.info("Destroyed SDK.")}catch(p){L.error("Could not destroy SDK",{err:p})}}async sendEvent(p){let C=Br("user"),{token:E}=C;await Cl(E,p),L.debug("sendEvent called",{eventName:p})}startElementSelector(p,C,E){L.debug("startElementSelector called");let b=E?window.document.querySelector(E):window.document.body,{startElementSelector:U,stopElementSelection:K}=kl(window.document,{onElementProfileCreated:p,onElementSelectionCancel:C,zIndex:2147483645,rootElement:b});this.stopElementSelector=K,U()}stopElementSelector(){}assessmentRecorder(){Xl()}},Hu=new Su;window.Strigo=Hu;window.Strigo.init();})(); /*! * html2canvas 1.4.1 * Copyright (c) 2022 Niklas von Hertzen diff --git a/src/strigo/index.ts b/src/strigo/index.ts index 55f10dd..16a442a 100644 --- a/src/strigo/index.ts +++ b/src/strigo/index.ts @@ -97,7 +97,7 @@ class StrigoSDK implements IStrigoSDK { openWidget = true, dockingSide = DockingSide.RIGHT, isPreview, - } = { ...config.user, ...config, ...data }; + } = { ...config?.user, ...config, ...data }; if (!email || !token) { throw new Error('Setup data is missing');