@coxwave/tap-sdk 0.0.11 → 0.0.12
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/dist/index.global.js +1 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.global.js
CHANGED
|
@@ -15,7 +15,7 @@ var TapSDK=(function(){'use strict';var je=Object.defineProperty;var Y=i=>{throw
|
|
|
15
15
|
rgba(255, 255, 255, 0.12) 0px 0px 2px 0px inset,
|
|
16
16
|
rgba(0, 0, 0, 0.05) 0px 0px 2px 1px,
|
|
17
17
|
rgba(0, 0, 0, 0.3) 0px 12px 60px
|
|
18
|
-
`,willChange:"transform, opacity, width, max-height, max-width"};this.$container.style.cssText="",this.$container.style.setProperty("position","fixed","important"),this.$container.style.setProperty("z-index","10000001","important"),this.$container.style.setProperty("top",t.top,"important"),this.$container.style.setProperty("right",t.right,"important"),this.$container.style.setProperty("left",t.left,"important"),this.$container.style.setProperty("bottom",t.bottom,"important"),this.$container.style.setProperty("width",t.width,"important"),this.$container.style.setProperty("height",t.height,"important"),this.$container.style.setProperty("overflow",t.overflow,"important"),this.$container.style.setProperty("background-color",t.backgroundColor,"important"),this.$container.style.setProperty("border-radius",t.borderRadius,"important"),this.$container.style.setProperty("box-shadow",t.boxShadow,"important"),this.$container.style.setProperty("will-change",t.willChange,"important"),this.$container.offsetHeight;}getBoundingClientRect(){return this.$container?this.$container.getBoundingClientRect():null}getComputedStyles(){if(!this.$container)return null;let e=window.getComputedStyle(this.$container);console.log("[Container] Raw computed styles:",{width:e.width,height:e.height,borderRadius:e.borderRadius,top:e.top,right:e.right,left:e.left,bottom:e.bottom});let t=(r,s)=>r&&r!=="auto"?r:s,n={width:t(e.width,"340px"),height:"calc(100vh - 116px)",borderRadius:t(e.borderRadius,"16px"),position:{top:t(e.top,"50px"),right:t(e.right,"24px"),left:e.left==="auto"?"unset":e.left,bottom:e.bottom==="auto"?"unset":e.bottom}};return console.log("[Container] Processed computed styles:",n),n}toggleVisibility(e){if(!this.$container)return;this.$container.classList.remove(L,E),this.$container.style.display="block";let t=()=>{this.$container&&(this.$container.classList.contains(E)&&(this.$container.style.display="none"),this.$container.removeEventListener("animationend",t));};this.$container.addEventListener("animationend",t),requestAnimationFrame(()=>{this.$container?.classList.add(e?L:E);});}removeContainer(){this.forceRemove();}resizeContainer(e,t){if(!this.$container)return;let n=t?.width??"340px",r=parseInt(n,10),s=r/3*10-r,u=e?`${r+s}px`:`${r}px`;this.$container.style.width=u;}setDynamicSize(e,t){this.$container&&(this.$container.style.transition="width 0.3s ease, height 0.3s ease",this.$container.style.width=e,this.$container.style.height=t);}animateResize(e,t,n=300){this.$container&&(this.$container.style.transition=`width ${n}ms ease, height ${n}ms ease`,this.$container.style.width=e,this.$container.style.height=t);}setResponsiveMode(e){if(!this.$container)return;let t={compact:{width:"280px",height:"calc(100% - 200px)"},normal:{width:"340px",height:"calc(100% - 116px)"},expanded:{width:"480px",height:"calc(100% - 80px)"}},{width:n,height:r}=t[e];this.animateResize(n,r,400);}};o(d,"instance",null);var z=d,N=z;var R=class{constructor(){o(this,"buttonElement");}create(e){let t=document.getElementById(e);if(!t)throw new Error(`Element with id '${e}' not found`);return t.style.setProperty("position","relative","important"),t.style.setProperty("z-index","10000001","important"),this.buttonElement=t,this.buttonElement}onClick(e){if(!this.buttonElement)throw new Error("not initialized");this.buttonElement.addEventListener("click",e);}},ee=R;var te="wtjce01",q={default:"wtjce0b wtjce0a","call-to-action":"wtjce0c wtjce0a"},ne="wtjce0a",re="wtjce09",B={default:"wtjce0e wtjce0d","call-to-action":"wtjce0f wtjce0d"},ie="wtjce0d",se="wtjce0h",ue="wtjce0g",H="wtjce03",oe="wtjce08",G={default:"wtjce06 wtjce05","call-to-action":"wtjce07 wtjce05"},ae="wtjce05",F="wtjce02",le="wtjce04";var f,ce,pe,fe,he,ye,V=class{constructor(){w(this,f);o(this,"container");o(this,"alarmTimeout");o(this,"alarmCornerSVG");o(this,"textContainer");o(this,"circleElement");o(this,"textInTextContainer");o(this,"messageInfo");}render({rootElement:e}){this.container=document.createElement("div"),this.container.id="alarm-container",this.container.className=te,this.container.addEventListener("click",n=>{n.stopPropagation();}),e.appendChild(this.container),m(this,f,ce).call(this,this.container);let t=m(this,f,pe).call(this,this.container);m(this,f,he).call(this,t),m(this,f,fe).call(this,t);}fadeIn(e){e.type==="default"||e.type==="hourSpent"?(this.textContainer.className=G.default,this.alarmCornerSVG.setAttribute("class",q.default),this.circleElement.className=B.default):(this.textContainer.className=G["call-to-action"],this.alarmCornerSVG.setAttribute("class",q["call-to-action"]),this.circleElement.className=B["call-to-action"]),this.messageInfo=e,this.textInTextContainer.textContent=e.message,this.toggleVisibility(true),this.alarmTimeout=setTimeout(()=>{this.toggleVisibility(false);},18*1e3);}onAlarmClick(e){this.container.addEventListener("click",()=>{this.toggleVisibility(false),e(this.messageInfo);});}toggleVisibility(e){this.container.classList.remove(F,H),requestAnimationFrame(()=>{this.container?.classList.add(e?F:H);});}remove(){this.container&&this.toggleVisibility(false),this.alarmTimeout&&clearTimeout(this.alarmTimeout);}};f=new WeakSet,ce=function(e){let t=document.createElement("div");t.className=re,e.appendChild(t);let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","11"),n.setAttribute("height","8"),n.setAttribute("viewBox","0 0 11 8"),n.setAttribute("fill","currentColor"),n.setAttribute("class",ne);let r=document.createElementNS("http://www.w3.org/2000/svg","path");r.setAttribute("d","M5.5 0L11.1292 8.25H-0.129165L5.5 0Z"),r.setAttribute("fill","currentColor"),n.appendChild(r),this.alarmCornerSVG=n,t.appendChild(n);},pe=function(e){let t=document.createElement("div");return t.className=le,e.appendChild(t),t},fe=function(e){this.textContainer=document.createElement("div"),this.textContainer.className=ae,e.appendChild(this.textContainer),this.textInTextContainer=document.createElement("span"),this.textInTextContainer.className=oe,this.textContainer.appendChild(this.textInTextContainer);},he=function(e){let t=document.createElement("div");t.className=ie,e.appendChild(t),t.addEventListener("click",r=>{r.stopPropagation(),this.remove();});let n=document.createElement("span");n.className=se,t.appendChild(n),n.textContent="\uC54C\uB9BC \uB044\uAE30",m(this,f,ye).call(this,t),this.circleElement=t;},ye=function(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("width","10"),t.setAttribute("height","10"),t.setAttribute("viewBox","0 0 14 14"),t.setAttribute("fill","none"),t.setAttribute("class",ue);let n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d","M1 1L13 13M13 1L1 13"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","2"),n.setAttribute("stroke-linecap","round"),t.appendChild(n),e.appendChild(t);};var me=V;var U;function de(i){return {lang:i?.lang??U?.lang,message:i?.message,abortEarly:i?.abortEarly??U?.abortEarly,abortPipeEarly:i?.abortPipeEarly??U?.abortPipeEarly}}var Le;function ze(i){return Le?.get(i)}var Ne;function Re(i){return Ne?.get(i)}var qe;function Be(i,e){return qe?.get(i)?.get(e)}function ve(i){let e=typeof i;return e==="string"?`"${i}"`:e==="number"||e==="bigint"||e==="boolean"?`${i}`:e==="object"||e==="function"?(i&&Object.getPrototypeOf(i)?.constructor?.name)??"null":e}function k(i,e,t,n,r){let s=r&&"input"in r?r.input:t.value,u=r?.expected??i.expects??null,a=r?.received??ve(s),l={kind:i.kind,type:i.type,input:s,expected:u,received:a,message:`Invalid ${e}: ${u?`Expected ${u} but r`:"R"}eceived ${a}`,requirement:i.requirement,path:r?.path,issues:r?.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},p=i.kind==="schema",c=r?.message??i.message??Be(i.reference,l.lang)??(p?Re(l.lang):null)??n.message??ze(l.lang);c!==void 0&&(l.message=typeof c=="function"?c(l):c),p&&(t.typed=false),t.issues?t.issues.push(l):t.issues=[l];}function x(i){return {version:1,vendor:"valibot",validate(e){return i["~run"]({value:e},de())}}}function He(i,e){return Object.hasOwn(i,e)&&e!=="__proto__"&&e!=="prototype"&&e!=="constructor"}function Ge(i,e,t){return typeof i.fallback=="function"?i.fallback(e,t):i.fallback}function Fe(i,e,t){return typeof i.default=="function"?i.default(e,t):i.default}function X(){return {kind:"schema",type:"any",reference:X,expects:"any",async:false,get"~standard"(){return x(this)},"~run"(i){return i.typed=true,i}}}function _(i,e){return {kind:"schema",type:"literal",reference:_,expects:ve(i),async:false,literal:i,message:e,get"~standard"(){return x(this)},"~run"(t,n){return t.value===this.literal?t.typed=true:k(this,"type",t,n),t}}}function I(i,e){return {kind:"schema",type:"object",reference:I,expects:"Object",async:false,entries:i,message:e,get"~standard"(){return x(this)},"~run"(t,n){let r=t.value;if(r&&typeof r=="object"){t.typed=true,t.value={};for(let s in this.entries){let u=this.entries[s];if(s in r||(u.type==="exact_optional"||u.type==="optional"||u.type==="nullish")&&u.default!==void 0){let a=s in r?r[s]:Fe(u),l=u["~run"]({value:a},n);if(l.issues){let p={type:"object",origin:"value",input:r,key:s,value:a};for(let c of l.issues)c.path?c.path.unshift(p):c.path=[p],t.issues?.push(c);if(t.issues||(t.issues=l.issues),n.abortEarly){t.typed=false;break}}l.typed||(t.typed=false),t.value[s]=l.value;}else if(u.fallback!==void 0)t.value[s]=Ge(u);else if(u.type!=="exact_optional"&&u.type!=="optional"&&u.type!=="nullish"&&(k(this,"key",t,n,{input:void 0,expected:`"${s}"`,path:[{type:"object",origin:"key",input:r,key:s,value:r[s]}]}),n.abortEarly))break}}else k(this,"type",t,n);return t}}}function W(i,e,t){return {kind:"schema",type:"record",reference:W,expects:"Object",async:false,key:i,value:e,message:t,get"~standard"(){return x(this)},"~run"(n,r){let s=n.value;if(s&&typeof s=="object"){n.typed=true,n.value={};for(let u in s)if(He(s,u)){let a=s[u],l=this.key["~run"]({value:u},r);if(l.issues){let c={type:"object",origin:"key",input:s,key:u,value:a};for(let h of l.issues)h.path=[c],n.issues?.push(h);if(n.issues||(n.issues=l.issues),r.abortEarly){n.typed=false;break}}let p=this.value["~run"]({value:a},r);if(p.issues){let c={type:"object",origin:"value",input:s,key:u,value:a};for(let h of p.issues)h.path?h.path.unshift(c):h.path=[c],n.issues?.push(h);if(n.issues||(n.issues=p.issues),r.abortEarly){n.typed=false;break}}(!l.typed||!p.typed)&&(n.typed=false),l.typed&&(n.value[l.value]=p.value);}}else k(this,"type",n,r);return n}}}function C(i){return {kind:"schema",type:"string",reference:C,expects:"string",async:false,message:i,get"~standard"(){return x(this)},"~run"(e,t){return typeof e.value=="string"?e.typed=true:k(this,"type",e,t),e}}}function ge(i,e,t){let n=i["~run"]({value:e},de(t));return {typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}var ke="chat:init",Ve="chat:initiated";var xe=I({type:_(Ve),gaId:C()});I({type:_("GA_EVENT"),payload:W(C(),X())});var T=class{constructor(){o(this,"listeners",new Map);o(this,"unifiedMessageHandler",null);}on(e,t){let n=s=>{if(this.isValidOrigin(s))try{let u=s.data,a=typeof u=="string"?JSON.parse(u):u,{type:l}=a;l===e&&t(a);}catch(u){console.warn("Messenger: Failed to parse message data",u);}},r=this.listeners.get(e)||[];return r.push(n),this.listeners.set(e,r),this.unifiedMessageHandler||(this.unifiedMessageHandler=s=>{this.listeners.forEach(u=>u.forEach(a=>a(s)));},window.addEventListener("message",this.unifiedMessageHandler)),()=>{this.unifiedMessageHandler&&(window.removeEventListener("message",this.unifiedMessageHandler),this.unifiedMessageHandler=null);}}removeListener(e){this.listeners.delete(e);}removeAllListeners(){this.listeners.clear(),this.unifiedMessageHandler&&(window.removeEventListener("message",this.unifiedMessageHandler),this.unifiedMessageHandler=null);}postMessage(e){try{let t=this.getMessageTarget();return t?(t.postMessage(e,this.getTargetOrigin()),!0):(console.warn("Messenger: Message target not available"),!1)}catch(t){return console.error("Messenger: postMessage failed",t),false}}};var v=class extends Error{constructor(t,n,r){super(`Handshake failed: ${t}${n?` - ${n}`:""}`);this.reason=t;this.details=n;this.originalError=r;this.name="HandshakeError";}},$=class{constructor(e,t,n){this.getTargetWindow=e;this.getTargetOrigin=t;this.isValidOrigin=n;o(this,"abortController",null);o(this,"messageListener",null);}async execute(e,t={}){let{timeout:n=1e4,maxRetries:r=10,retryInterval:s=500}=t;return this.cancel(),this.abortController=new AbortController,new Promise((u,a)=>{let l=0,p,c=()=>{p&&clearTimeout(p),this.messageListener&&(window.removeEventListener("message",this.messageListener),this.messageListener=null);},h=()=>{c(),a(new v("TIMEOUT","Handshake was cancelled"));};this.abortController?.signal.addEventListener("abort",h),this.messageListener=y=>{if(this.isValidOrigin(y))try{let g=y.data,Me=typeof g=="string"?JSON.parse(g):g,Z=ge(xe,Me);if(Z.success){c(),this.abortController=null,u(Z.output);return}}catch{}},window.addEventListener("message",this.messageListener),p=setTimeout(()=>{c(),this.abortController=null,a(new v("TIMEOUT",`No valid response received within ${n}ms`));},n);let J=()=>{if(!this.abortController?.signal.aborted)try{let y=this.getTargetWindow(),g=this.getTargetOrigin();if(!y)throw new v("NO_TARGET_WINDOW","Target iframe window is not available");y.postMessage(e,g),l++,l<r&&setTimeout(()=>{this.abortController?.signal.aborted||J();},s);}catch(y){c(),this.abortController=null,y instanceof v?a(y):a(new v("MESSAGE_SEND_FAILED","Failed to send handshake message",y));}};J();})}cancel(){this.abortController&&(this.abortController.abort(),this.abortController=null),this.messageListener&&(window.removeEventListener("message",this.messageListener),this.messageListener=null);}isActive(){return this.abortController!==null&&!this.abortController.signal.aborted}};var b,we,Ee,M=class M extends T{constructor({hostOrigin:t,apiKey:n,eventLogger:r}){super();w(this,b);o(this,"hostOrigin");o(this,"apiKey");o(this,"iframe");o(this,"eventLogger");o(this,"postToTap",t=>{if(!this.iframe)return console.error("TapIframeBridge: iframe not found - ensure createIframeChat() was called first"),console.error("Failed to send message:",t),(t.type==="chat:open"||t.type==="chat:close")&&console.error("Chat cannot be opened/closed - iframe is not initialized"),this.eventLogger?.log({action:"iframe_message_failed",category:"error",label:t.type,customParams:{reason:"iframe_not_initialized"}}),false;let n=super.postMessage(t);return this.eventLogger?.log({action:"iframe_message_sent",category:"communication",label:t.type,customParams:{success:n}}),n});o(this,"listenToTap",super.on);this.hostOrigin=t,this.apiKey=n,this.eventLogger=r;}isValidOrigin(t){return true}getMessageTarget(){return this.iframe?.contentWindow||null}getTargetOrigin(){if(!this.iframe?.src)return "*";try{return new URL(this.iframe.src).origin}catch{return "*"}}renderIframe(t){return new Promise(n=>{this.iframe&&(this.iframe.remove(),this.iframe=null),this.iframe=document.createElement("iframe"),this.iframe.style.setProperty("display","flex","important"),this.iframe.style.setProperty("border","none","important"),this.iframe.src=m(this,b,we).call(this),this.iframe.style.width="100%",this.iframe.style.height="100%",this.iframe.onload=()=>{n(this.iframe);},t?.appendChild(this.iframe);})}hasIframe(){return this.iframe!==null&&this.iframe!==void 0}async ensureIframe(t){return this.hasIframe()?this.iframe:this.renderIframe(t)}removeIframe(){this.iframe?.remove(),this.iframe=null,this.removeAllListeners();}async performHandshake(t,n=M.defaultHandshakeOptions){if(!this.iframe)throw new Error("TapIframeBridge: iframe not available for handshake");this.eventLogger?.log({action:"handshake_started",category:"communication",customParams:{iframeSrc:this.iframe.src,targetOrigin:this.getTargetOrigin(),messageTargetAvailable:!!this.getMessageTarget()}});let r=new $(()=>this.getMessageTarget(),()=>this.getTargetOrigin(),a=>this.isValidOrigin(a)),s={type:ke,hostOrigin:this.hostOrigin,apiKey:this.apiKey,chatApiParams:{...t.course,clipPlayHead:t.course.clipPlayHead??0},apiUrl:m(this,b,Ee).call(this)||""};this.eventLogger?.log({action:"handshake_message_sending",category:"communication",customParams:{messageType:s.type,hostOrigin:s.hostOrigin,hasApiKey:!!s.apiKey,apiUrl:s.apiUrl,chatApiParams:s.chatApiParams}});let u=Date.now();try{let a=await r.execute(s,n);return this.eventLogger?.log({action:"iframe_handshake",category:"system",label:"success",value:Date.now()-u,customParams:{apiUrl:s.apiUrl,targetOrigin:this.getTargetOrigin()}}),a}catch(a){throw console.error("[TapIframeBridge] Handshake failed:",a),this.eventLogger?.log({action:"iframe_handshake",category:"error",label:"failed",value:Date.now()-u,customParams:{error:a instanceof Error?a.message:"Unknown error",apiUrl:s.apiUrl}}),a instanceof Error?new Error(`TapIframeBridge handshake failed: ${a.message}`):a}}};b=new WeakSet,we=function(){if(typeof window>"u"||typeof localStorage>"u")throw new Error("TapIframeBridge: window or localStorage is not defined");try{let t=localStorage.getItem("tap-url-storage");if(t){let n=JSON.parse(t);this.eventLogger?.log({action:"custom_tap_url_found",category:"configuration",customParams:{stored:n}});let r=n?.state?.tapUrl;if(r)return this.eventLogger?.log({action:"custom_tap_url_used",category:"configuration",customParams:{customTapUrl:r}}),`${r}/chat`}}catch{}return "https://edutap-ai.vercel.app/chat"},Ee=function(){if(!(typeof window>"u"||typeof localStorage>"u"))try{let t=localStorage.getItem("tap-api-url-storage");return t?JSON.parse(t)?.state?.apiUrl:void 0}catch{return}},o(M,"defaultHandshakeOptions",{retryInterval:500,maxRetries:3,timeout:3e4});var A=M;var j=class{constructor(e){this.iframeBridge=e;}seekTimeline({clipId:e,clipPlayHead:t}){this.iframeBridge.postToTap({type:"timeline:seek",clipId:e,clipPlayHead:t});}onTimelineSeek(e){this.iframeBridge.listenToTap("timeline:seek",t=>e(t.clipPlayHead,t.clipId));}onChatOpened(e){this.iframeBridge.listenToTap("chat:opened",e);}onChatClosed(e){this.iframeBridge.listenToTap("chat:closed",e);}onChatInitiated(e){this.iframeBridge.listenToTap("chat:initiated",e);}onAlarmFadeIn(e){this.iframeBridge.listenToTap("alarm:fadeIn",t=>{e(t.messageInfo);});}onPopUpOpen(e){this.iframeBridge.listenToTap("popUp:open",t=>{e(t.popUpInfo);});}onPdfOpen(e){this.iframeBridge.listenToTap("pdf:open",e);}onPdfClose(e){this.iframeBridge.listenToTap("pdf:close",e);}};var Ue="G-27C0E436HL",D=class{constructor(e=Ue){this.gaId=e;this.gaId&&typeof window<"u"&&this.initializeGA(this.gaId);}initializeGA(e){if(document.querySelector(`script[src*="googletagmanager.com/gtag/js?id=${e}"]`))return;let t=document.createElement("script");if(t.async=true,t.src=`https://www.googletagmanager.com/gtag/js?id=${e}`,document.head.appendChild(t),typeof window.gtag!="function"){let n=document.createElement("script");n.innerHTML=`
|
|
18
|
+
`,willChange:"transform, opacity, width, max-height, max-width"};this.$container.style.cssText="",this.$container.style.setProperty("position","fixed","important"),this.$container.style.setProperty("z-index","10000001","important"),this.$container.style.setProperty("top",t.top,"important"),this.$container.style.setProperty("right",t.right,"important"),this.$container.style.setProperty("left",t.left,"important"),this.$container.style.setProperty("bottom",t.bottom,"important"),this.$container.style.setProperty("width",t.width,"important"),this.$container.style.setProperty("height",t.height,"important"),this.$container.style.setProperty("overflow",t.overflow,"important"),this.$container.style.setProperty("background-color",t.backgroundColor,"important"),this.$container.style.setProperty("border-radius",t.borderRadius,"important"),this.$container.style.setProperty("box-shadow",t.boxShadow,"important"),this.$container.style.setProperty("will-change",t.willChange,"important"),this.$container.offsetHeight;}getBoundingClientRect(){return this.$container?this.$container.getBoundingClientRect():null}getComputedStyles(){if(!this.$container)return null;let e=window.getComputedStyle(this.$container);console.log("[Container] Raw computed styles:",{width:e.width,height:e.height,borderRadius:e.borderRadius,top:e.top,right:e.right,left:e.left,bottom:e.bottom});let t=(r,s)=>r&&r!=="auto"?r:s,n={width:t(e.width,"340px"),height:"calc(100vh - 116px)",borderRadius:t(e.borderRadius,"16px"),position:{top:t(e.top,"50px"),right:t(e.right,"24px"),left:e.left==="auto"?"unset":e.left,bottom:e.bottom==="auto"?"unset":e.bottom}};return console.log("[Container] Processed computed styles:",n),n}toggleVisibility(e){if(!this.$container)return;this.$container.classList.remove(L,E),this.$container.style.display="block";let t=()=>{this.$container&&(this.$container.classList.contains(E)&&(this.$container.style.display="none"),this.$container.removeEventListener("animationend",t));};this.$container.addEventListener("animationend",t),requestAnimationFrame(()=>{this.$container?.classList.add(e?L:E);});}removeContainer(){this.forceRemove();}resizeContainer(e,t){if(!this.$container)return;let n=t?.width??"340px",r=parseInt(n,10),s=r/3*10-r,u=e?`${r+s}px`:`${r}px`;this.$container.style.width=u;}setDynamicSize(e,t){this.$container&&(this.$container.style.transition="width 0.3s ease, height 0.3s ease",this.$container.style.width=e,this.$container.style.height=t);}animateResize(e,t,n=300){this.$container&&(this.$container.style.transition=`width ${n}ms ease, height ${n}ms ease`,this.$container.style.width=e,this.$container.style.height=t);}setResponsiveMode(e){if(!this.$container)return;let t={compact:{width:"280px",height:"calc(100% - 200px)"},normal:{width:"340px",height:"calc(100% - 116px)"},expanded:{width:"480px",height:"calc(100% - 80px)"}},{width:n,height:r}=t[e];this.animateResize(n,r,400);}};o(d,"instance",null);var z=d,N=z;var R=class{constructor(){o(this,"buttonElement");}create(e){let t=document.getElementById(e);if(!t)throw new Error(`Element with id '${e}' not found`);return t.style.setProperty("position","relative","important"),t.style.setProperty("z-index","10000001","important"),this.buttonElement=t,this.buttonElement}onClick(e){if(!this.buttonElement)throw new Error("not initialized");this.buttonElement.addEventListener("click",e);}},ee=R;var te="wtjce01",q={default:"wtjce0b wtjce0a","call-to-action":"wtjce0c wtjce0a"},ne="wtjce0a",re="wtjce09",B={default:"wtjce0e wtjce0d","call-to-action":"wtjce0f wtjce0d"},ie="wtjce0d",se="wtjce0h",ue="wtjce0g",H="wtjce03",oe="wtjce08",G={default:"wtjce06 wtjce05","call-to-action":"wtjce07 wtjce05"},ae="wtjce05",F="wtjce02",le="wtjce04";var f,ce,pe,fe,he,ye,V=class{constructor(){w(this,f);o(this,"container");o(this,"alarmTimeout");o(this,"alarmCornerSVG");o(this,"textContainer");o(this,"circleElement");o(this,"textInTextContainer");o(this,"messageInfo");}render({rootElement:e}){this.container=document.createElement("div"),this.container.id="alarm-container",this.container.className=te,this.container.addEventListener("click",n=>{n.stopPropagation();}),e.appendChild(this.container),m(this,f,ce).call(this,this.container);let t=m(this,f,pe).call(this,this.container);m(this,f,he).call(this,t),m(this,f,fe).call(this,t);}fadeIn(e){e.type==="default"||e.type==="hourSpent"?(this.textContainer.className=G.default,this.alarmCornerSVG.setAttribute("class",q.default),this.circleElement.className=B.default):(this.textContainer.className=G["call-to-action"],this.alarmCornerSVG.setAttribute("class",q["call-to-action"]),this.circleElement.className=B["call-to-action"]),this.messageInfo=e,this.textInTextContainer.textContent=e.message,this.toggleVisibility(true),this.alarmTimeout=setTimeout(()=>{this.toggleVisibility(false);},18*1e3);}onAlarmClick(e){this.container.addEventListener("click",()=>{this.toggleVisibility(false),e(this.messageInfo);});}toggleVisibility(e){this.container.classList.remove(F,H),requestAnimationFrame(()=>{this.container?.classList.add(e?F:H);});}remove(){this.container&&this.toggleVisibility(false),this.alarmTimeout&&clearTimeout(this.alarmTimeout);}};f=new WeakSet,ce=function(e){let t=document.createElement("div");t.className=re,e.appendChild(t);let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","11"),n.setAttribute("height","8"),n.setAttribute("viewBox","0 0 11 8"),n.setAttribute("fill","currentColor"),n.setAttribute("class",ne);let r=document.createElementNS("http://www.w3.org/2000/svg","path");r.setAttribute("d","M5.5 0L11.1292 8.25H-0.129165L5.5 0Z"),r.setAttribute("fill","currentColor"),n.appendChild(r),this.alarmCornerSVG=n,t.appendChild(n);},pe=function(e){let t=document.createElement("div");return t.className=le,e.appendChild(t),t},fe=function(e){this.textContainer=document.createElement("div"),this.textContainer.className=ae,e.appendChild(this.textContainer),this.textInTextContainer=document.createElement("span"),this.textInTextContainer.className=oe,this.textContainer.appendChild(this.textInTextContainer);},he=function(e){let t=document.createElement("div");t.className=ie,e.appendChild(t),t.addEventListener("click",r=>{r.stopPropagation(),this.remove();});let n=document.createElement("span");n.className=se,t.appendChild(n),n.textContent="\uC54C\uB9BC \uB044\uAE30",m(this,f,ye).call(this,t),this.circleElement=t;},ye=function(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("width","10"),t.setAttribute("height","10"),t.setAttribute("viewBox","0 0 14 14"),t.setAttribute("fill","none"),t.setAttribute("class",ue);let n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d","M1 1L13 13M13 1L1 13"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","2"),n.setAttribute("stroke-linecap","round"),t.appendChild(n),e.appendChild(t);};var me=V;var U;function de(i){return {lang:i?.lang??U?.lang,message:i?.message,abortEarly:i?.abortEarly??U?.abortEarly,abortPipeEarly:i?.abortPipeEarly??U?.abortPipeEarly}}var Le;function ze(i){return Le?.get(i)}var Ne;function Re(i){return Ne?.get(i)}var qe;function Be(i,e){return qe?.get(i)?.get(e)}function ve(i){let e=typeof i;return e==="string"?`"${i}"`:e==="number"||e==="bigint"||e==="boolean"?`${i}`:e==="object"||e==="function"?(i&&Object.getPrototypeOf(i)?.constructor?.name)??"null":e}function k(i,e,t,n,r){let s=r&&"input"in r?r.input:t.value,u=r?.expected??i.expects??null,a=r?.received??ve(s),l={kind:i.kind,type:i.type,input:s,expected:u,received:a,message:`Invalid ${e}: ${u?`Expected ${u} but r`:"R"}eceived ${a}`,requirement:i.requirement,path:r?.path,issues:r?.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},p=i.kind==="schema",c=r?.message??i.message??Be(i.reference,l.lang)??(p?Re(l.lang):null)??n.message??ze(l.lang);c!==void 0&&(l.message=typeof c=="function"?c(l):c),p&&(t.typed=false),t.issues?t.issues.push(l):t.issues=[l];}function x(i){return {version:1,vendor:"valibot",validate(e){return i["~run"]({value:e},de())}}}function He(i,e){return Object.hasOwn(i,e)&&e!=="__proto__"&&e!=="prototype"&&e!=="constructor"}function Ge(i,e,t){return typeof i.fallback=="function"?i.fallback(e,t):i.fallback}function Fe(i,e,t){return typeof i.default=="function"?i.default(e,t):i.default}function X(){return {kind:"schema",type:"any",reference:X,expects:"any",async:false,get"~standard"(){return x(this)},"~run"(i){return i.typed=true,i}}}function _(i,e){return {kind:"schema",type:"literal",reference:_,expects:ve(i),async:false,literal:i,message:e,get"~standard"(){return x(this)},"~run"(t,n){return t.value===this.literal?t.typed=true:k(this,"type",t,n),t}}}function I(i,e){return {kind:"schema",type:"object",reference:I,expects:"Object",async:false,entries:i,message:e,get"~standard"(){return x(this)},"~run"(t,n){let r=t.value;if(r&&typeof r=="object"){t.typed=true,t.value={};for(let s in this.entries){let u=this.entries[s];if(s in r||(u.type==="exact_optional"||u.type==="optional"||u.type==="nullish")&&u.default!==void 0){let a=s in r?r[s]:Fe(u),l=u["~run"]({value:a},n);if(l.issues){let p={type:"object",origin:"value",input:r,key:s,value:a};for(let c of l.issues)c.path?c.path.unshift(p):c.path=[p],t.issues?.push(c);if(t.issues||(t.issues=l.issues),n.abortEarly){t.typed=false;break}}l.typed||(t.typed=false),t.value[s]=l.value;}else if(u.fallback!==void 0)t.value[s]=Ge(u);else if(u.type!=="exact_optional"&&u.type!=="optional"&&u.type!=="nullish"&&(k(this,"key",t,n,{input:void 0,expected:`"${s}"`,path:[{type:"object",origin:"key",input:r,key:s,value:r[s]}]}),n.abortEarly))break}}else k(this,"type",t,n);return t}}}function W(i,e,t){return {kind:"schema",type:"record",reference:W,expects:"Object",async:false,key:i,value:e,message:t,get"~standard"(){return x(this)},"~run"(n,r){let s=n.value;if(s&&typeof s=="object"){n.typed=true,n.value={};for(let u in s)if(He(s,u)){let a=s[u],l=this.key["~run"]({value:u},r);if(l.issues){let c={type:"object",origin:"key",input:s,key:u,value:a};for(let h of l.issues)h.path=[c],n.issues?.push(h);if(n.issues||(n.issues=l.issues),r.abortEarly){n.typed=false;break}}let p=this.value["~run"]({value:a},r);if(p.issues){let c={type:"object",origin:"value",input:s,key:u,value:a};for(let h of p.issues)h.path?h.path.unshift(c):h.path=[c],n.issues?.push(h);if(n.issues||(n.issues=p.issues),r.abortEarly){n.typed=false;break}}(!l.typed||!p.typed)&&(n.typed=false),l.typed&&(n.value[l.value]=p.value);}}else k(this,"type",n,r);return n}}}function C(i){return {kind:"schema",type:"string",reference:C,expects:"string",async:false,message:i,get"~standard"(){return x(this)},"~run"(e,t){return typeof e.value=="string"?e.typed=true:k(this,"type",e,t),e}}}function ge(i,e,t){let n=i["~run"]({value:e},de(t));return {typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}var ke="chat:init",Ve="chat:initiated";var xe=I({type:_(Ve),gaId:C()});I({type:_("GA_EVENT"),payload:W(C(),X())});var T=class{constructor(){o(this,"listeners",new Map);o(this,"unifiedMessageHandler",null);}on(e,t){let n=s=>{if(this.isValidOrigin(s))try{let u=s.data,a=typeof u=="string"?JSON.parse(u):u,{type:l}=a;l===e&&t(a);}catch(u){console.warn("Messenger: Failed to parse message data",u);}},r=this.listeners.get(e)||[];return r.push(n),this.listeners.set(e,r),this.unifiedMessageHandler||(this.unifiedMessageHandler=s=>{this.listeners.forEach(u=>u.forEach(a=>a(s)));},window.addEventListener("message",this.unifiedMessageHandler)),()=>{this.unifiedMessageHandler&&(window.removeEventListener("message",this.unifiedMessageHandler),this.unifiedMessageHandler=null);}}removeListener(e){this.listeners.delete(e);}removeAllListeners(){this.listeners.clear(),this.unifiedMessageHandler&&(window.removeEventListener("message",this.unifiedMessageHandler),this.unifiedMessageHandler=null);}postMessage(e){try{let t=this.getMessageTarget();return t?(t.postMessage(e,this.getTargetOrigin()),!0):(console.warn("Messenger: Message target not available"),!1)}catch(t){return console.error("Messenger: postMessage failed",t),false}}};var v=class extends Error{constructor(t,n,r){super(`Handshake failed: ${t}${n?` - ${n}`:""}`);this.reason=t;this.details=n;this.originalError=r;this.name="HandshakeError";}},$=class{constructor(e,t,n){this.getTargetWindow=e;this.getTargetOrigin=t;this.isValidOrigin=n;o(this,"abortController",null);o(this,"messageListener",null);}async execute(e,t={}){let{timeout:n=1e4,maxRetries:r=10,retryInterval:s=500}=t;return this.cancel(),this.abortController=new AbortController,new Promise((u,a)=>{let l=0,p,c=()=>{p&&clearTimeout(p),this.messageListener&&(window.removeEventListener("message",this.messageListener),this.messageListener=null);},h=()=>{c(),a(new v("TIMEOUT","Handshake was cancelled"));};this.abortController?.signal.addEventListener("abort",h),this.messageListener=y=>{if(this.isValidOrigin(y))try{let g=y.data,Me=typeof g=="string"?JSON.parse(g):g,Z=ge(xe,Me);if(Z.success){c(),this.abortController=null,u(Z.output);return}}catch{}},window.addEventListener("message",this.messageListener),p=setTimeout(()=>{c(),this.abortController=null,a(new v("TIMEOUT",`No valid response received within ${n}ms`));},n);let J=()=>{if(!this.abortController?.signal.aborted)try{let y=this.getTargetWindow(),g=this.getTargetOrigin();if(!y)throw new v("NO_TARGET_WINDOW","Target iframe window is not available");y.postMessage(e,g),l++,l<r&&setTimeout(()=>{this.abortController?.signal.aborted||J();},s);}catch(y){c(),this.abortController=null,y instanceof v?a(y):a(new v("MESSAGE_SEND_FAILED","Failed to send handshake message",y));}};J();})}cancel(){this.abortController&&(this.abortController.abort(),this.abortController=null),this.messageListener&&(window.removeEventListener("message",this.messageListener),this.messageListener=null);}isActive(){return this.abortController!==null&&!this.abortController.signal.aborted}};var b,we,Ee,M=class M extends T{constructor({hostOrigin:t,apiKey:n,eventLogger:r}){super();w(this,b);o(this,"hostOrigin");o(this,"apiKey");o(this,"iframe");o(this,"eventLogger");o(this,"postToTap",t=>{if(!this.iframe)return console.error("TapIframeBridge: iframe not found - ensure createIframeChat() was called first"),console.error("Failed to send message:",t),(t.type==="chat:open"||t.type==="chat:close")&&console.error("Chat cannot be opened/closed - iframe is not initialized"),this.eventLogger?.log({action:"iframe_message_failed",category:"error",label:t.type,customParams:{reason:"iframe_not_initialized"}}),false;let n=super.postMessage(t);return this.eventLogger?.log({action:"iframe_message_sent",category:"communication",label:t.type,customParams:{success:n}}),n});o(this,"listenToTap",super.on);this.hostOrigin=t,this.apiKey=n,this.eventLogger=r;}isValidOrigin(t){return true}getMessageTarget(){return this.iframe?.contentWindow||null}getTargetOrigin(){if(!this.iframe?.src)return "*";try{return new URL(this.iframe.src).origin}catch{return "*"}}renderIframe(t){return new Promise(n=>{this.iframe&&(this.iframe.remove(),this.iframe=null),this.iframe=document.createElement("iframe"),this.iframe.style.setProperty("display","flex","important"),this.iframe.style.setProperty("border","none","important"),this.iframe.src=m(this,b,we).call(this),this.iframe.style.width="100%",this.iframe.style.height="100%",this.iframe.onload=()=>{n(this.iframe);},t?.appendChild(this.iframe);})}hasIframe(){return this.iframe!==null&&this.iframe!==void 0}async ensureIframe(t){return this.hasIframe()?this.iframe:this.renderIframe(t)}removeIframe(){this.iframe?.remove(),this.iframe=null,this.removeAllListeners();}async performHandshake(t,n=M.defaultHandshakeOptions){if(!this.iframe)throw new Error("TapIframeBridge: iframe not available for handshake");this.eventLogger?.log({action:"handshake_started",category:"communication",customParams:{iframeSrc:this.iframe.src,targetOrigin:this.getTargetOrigin(),messageTargetAvailable:!!this.getMessageTarget()}});let r=new $(()=>this.getMessageTarget(),()=>this.getTargetOrigin(),a=>this.isValidOrigin(a)),s={type:ke,hostOrigin:this.hostOrigin,apiKey:this.apiKey,chatApiParams:{...t.course,clipPlayHead:t.course.clipPlayHead??0},apiUrl:m(this,b,Ee).call(this)||""};this.eventLogger?.log({action:"handshake_message_sending",category:"communication",customParams:{messageType:s.type,hostOrigin:s.hostOrigin,hasApiKey:!!s.apiKey,apiUrl:s.apiUrl,chatApiParams:s.chatApiParams}});let u=Date.now();try{let a=await r.execute(s,n);return this.eventLogger?.log({action:"iframe_handshake",category:"system",label:"success",value:Date.now()-u,customParams:{apiUrl:s.apiUrl,targetOrigin:this.getTargetOrigin()}}),a}catch(a){throw console.error("[TapIframeBridge] Handshake failed:",a),this.eventLogger?.log({action:"iframe_handshake",category:"error",label:"failed",value:Date.now()-u,customParams:{error:a instanceof Error?a.message:"Unknown error",apiUrl:s.apiUrl}}),a instanceof Error?new Error(`TapIframeBridge handshake failed: ${a.message}`):a}}};b=new WeakSet,we=function(){if(typeof window>"u"||typeof localStorage>"u")throw new Error("TapIframeBridge: window or localStorage is not defined");try{let t=localStorage.getItem("tap-url-storage");if(t){let n=JSON.parse(t);this.eventLogger?.log({action:"custom_tap_url_found",category:"configuration",customParams:{stored:n}});let r=n?.state?.tapUrl;if(r)return this.eventLogger?.log({action:"custom_tap_url_used",category:"configuration",customParams:{customTapUrl:r}}),`${r}/chat`}}catch{}return "https://ax-tap-fe-edutap-poc.vercel.app/chat"},Ee=function(){if(!(typeof window>"u"||typeof localStorage>"u"))try{let t=localStorage.getItem("tap-api-url-storage");return t?JSON.parse(t)?.state?.apiUrl:void 0}catch{return}},o(M,"defaultHandshakeOptions",{retryInterval:500,maxRetries:3,timeout:3e4});var A=M;var j=class{constructor(e){this.iframeBridge=e;}seekTimeline({clipId:e,clipPlayHead:t}){this.iframeBridge.postToTap({type:"timeline:seek",clipId:e,clipPlayHead:t});}onTimelineSeek(e){this.iframeBridge.listenToTap("timeline:seek",t=>e(t.clipPlayHead,t.clipId));}onChatOpened(e){this.iframeBridge.listenToTap("chat:opened",e);}onChatClosed(e){this.iframeBridge.listenToTap("chat:closed",e);}onChatInitiated(e){this.iframeBridge.listenToTap("chat:initiated",e);}onAlarmFadeIn(e){this.iframeBridge.listenToTap("alarm:fadeIn",t=>{e(t.messageInfo);});}onPopUpOpen(e){this.iframeBridge.listenToTap("popUp:open",t=>{e(t.popUpInfo);});}onPdfOpen(e){this.iframeBridge.listenToTap("pdf:open",e);}onPdfClose(e){this.iframeBridge.listenToTap("pdf:close",e);}};var Ue="G-27C0E436HL",D=class{constructor(e=Ue){this.gaId=e;this.gaId&&typeof window<"u"&&this.initializeGA(this.gaId);}initializeGA(e){if(document.querySelector(`script[src*="googletagmanager.com/gtag/js?id=${e}"]`))return;let t=document.createElement("script");if(t.async=true,t.src=`https://www.googletagmanager.com/gtag/js?id=${e}`,document.head.appendChild(t),typeof window.gtag!="function"){let n=document.createElement("script");n.innerHTML=`
|
|
19
19
|
window.dataLayer = window.dataLayer || [];
|
|
20
20
|
function gtag(){dataLayer.push(arguments);}
|
|
21
21
|
gtag('js', new Date());
|