@coxwave/tap-sdk 0.0.1 → 0.0.3
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.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
}
|
|
12
12
|
})();
|
|
13
13
|
|
|
14
|
-
'use strict';var
|
|
14
|
+
'use strict';var je=Object.defineProperty;var J=i=>{throw TypeError(i)};var $e=(i,t,e)=>t in i?je(i,t,{enumerable:true,configurable:true,writable:true,value:e}):i[t]=e;var u=(i,t,e)=>$e(i,typeof t!="symbol"?t+"":t,e),Z=(i,t,e)=>t.has(i)||J("Cannot "+e);var Y=(i,t,e)=>(Z(i,t,"read from private field"),e?e.call(i):t.get(i)),g=(i,t,e)=>t.has(i)?J("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e);var d=(i,t,e)=>(Z(i,t,"access private method"),e);var Q="_1mlv4me2",w="_1mlv4me4";var O="_1mlv4me3";var D=class{constructor(){u(this,"chatBody",null);this.chatBody=null;}createChatBody({customChatBody:t}){return this.chatBody?this.chatBody:(this.chatBody=document.createElement("div"),this.chatBody.id="cw-chat-body",this.chatBody.className=Q,this.chatBody.style.setProperty("z-index","10000001","important"),this.chatBody.style.setProperty("position","fixed","important"),Object.assign(this.chatBody.style,{top:t?.position?.top??"50px",right:t?.position?.right??"24px",left:t?.position?.left??"unset",bottom:t?.position?.bottom??"unset",width:t?.width??"340px",height:t?.height??"calc(100% - 116px)",overflow:"hidden",backgroundColor:"transparent",borderRadius:t?.borderRadius??"16px",boxShadow:`
|
|
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"}),document.body.appendChild(this.chatBody),this.chatBody)}toggleVisibility(t){if(!this.chatBody)return;this.chatBody.classList.remove(k,w),this.chatBody.style.display="block";let e=()=>{this.chatBody&&(this.chatBody.classList.contains(w)&&(this.chatBody.style.display="none"),this.chatBody.removeEventListener("animationend",e));};this.chatBody.addEventListener("animationend",e),requestAnimationFrame(()=>{this.chatBody?.classList.add(t?k:w);});}removeChatBody(){this.chatBody&&(this.chatBody.remove(),this.chatBody=null);}resizeChatBody(t,e){if(!this.chatBody)return;let i=e?.width??"340px",a=parseInt(i,10),o=a/3*10-a,n=t?`${a+o}px`:`${a}px`;this.chatBody.style.width=n;}},W=_;var V="_6j1ub51",L={default:"_6j1ub5b _6j1ub5a","call-to-action":"_6j1ub5c _6j1ub5a"},$="_6j1ub5a",G="_6j1ub59",A={default:"_6j1ub5e _6j1ub5d","call-to-action":"_6j1ub5f _6j1ub5d"},q="_6j1ub5d",Y="_6j1ub5h",X="_6j1ub5g",P="_6j1ub53",J="_6j1ub58",O={default:"_6j1ub56 _6j1ub55","call-to-action":"_6j1ub57 _6j1ub55"},Z="_6j1ub55",j="_6j1ub52",Q="_6j1ub54";var p,ee,te,ae,ie,re,H=class{constructor(){y(this,p);r(this,"container");r(this,"alarmTimeout");r(this,"alarmCornerSVG");r(this,"textContainer");r(this,"circleElement");r(this,"textInTextContainer");r(this,"messageInfo");}render({rootElement:t}){this.container=document.createElement("div"),this.container.id="alarm-container",this.container.className=V,this.container.addEventListener("click",i=>{i.stopPropagation();}),t.appendChild(this.container),m(this,p,ee).call(this,this.container);let e=m(this,p,te).call(this,this.container);m(this,p,ie).call(this,e),m(this,p,ae).call(this,e);}fadeIn(t){t.type==="default"||t.type==="hourSpent"?(this.textContainer.className=O.default,this.alarmCornerSVG.setAttribute("class",L.default),this.circleElement.className=A.default):(this.textContainer.className=O["call-to-action"],this.alarmCornerSVG.setAttribute("class",L["call-to-action"]),this.circleElement.className=A["call-to-action"]),this.messageInfo=t,this.textInTextContainer.textContent=t.message,this.toggleVisibility(true),this.alarmTimeout=setTimeout(()=>{this.toggleVisibility(false);},18*1e3);}addClickEvent({callback:t}){this.container.addEventListener("click",()=>{this.toggleVisibility(false),t(this.messageInfo);});}toggleVisibility(t){this.container.classList.remove(j,P),requestAnimationFrame(()=>{this.container?.classList.add(t?j:P);});}remove(){this.container&&this.toggleVisibility(false),this.alarmTimeout&&clearTimeout(this.alarmTimeout);}};p=new WeakSet,ee=function(t){let e=document.createElement("div");e.className=G,t.appendChild(e);let i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("width","11"),i.setAttribute("height","8"),i.setAttribute("viewBox","0 0 11 8"),i.setAttribute("fill","currentColor"),i.setAttribute("class",$);let a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d","M5.5 0L11.1292 8.25H-0.129165L5.5 0Z"),a.setAttribute("fill","currentColor"),i.appendChild(a),this.alarmCornerSVG=i,e.appendChild(i);},te=function(t){let e=document.createElement("div");return e.className=Q,t.appendChild(e),e},ae=function(t){this.textContainer=document.createElement("div"),this.textContainer.className=Z,t.appendChild(this.textContainer),this.textInTextContainer=document.createElement("span"),this.textInTextContainer.className=J,this.textContainer.appendChild(this.textInTextContainer);},ie=function(t){let e=document.createElement("div");e.className=q,t.appendChild(e),e.addEventListener("click",a=>{a.stopPropagation(),this.remove();});let i=document.createElement("span");i.className=Y,e.appendChild(i),i.textContent="\uC54C\uB9BC \uB044\uAE30",m(this,p,re).call(this,e),this.circleElement=e;},re=function(t){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("width","10"),e.setAttribute("height","10"),e.setAttribute("viewBox","0 0 14 14"),e.setAttribute("fill","none"),e.setAttribute("class",X);let i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d","M1 1L13 13M13 1L1 13"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),e.appendChild(i),t.appendChild(e);};var se=H;var T,S=class{constructor(){r(this,"customFloatingButton");r(this,"floatingButton");r(this,"alarm");y(this,T,(t,e)=>t.key===e?true:t.code.startsWith("Key")?t.code.slice(3).toLowerCase()===e:false);this.alarm=new se;}render({customFloatingButton:t}){if(this.customFloatingButton=t,this.customFloatingButton?.isInElement&&this.customFloatingButton?.parentElementId){let e=document.getElementById(this.customFloatingButton.parentElementId);e?.style.setProperty("position","relative","important"),e?.style.setProperty("z-index","10000001","important"),this.floatingButton=e;}else {let e=document.getElementById("cw-plugin");e||(e=document.createElement("button"),e.id="cw-plugin",e.style.zIndex="10000001",e.style.setProperty("z-index","10000001","important"),e.style.setProperty("position","fixed","important"),e.style.width="50px",e.style.height="50px",e.style.borderRadius="50%",e.style.backgroundColor="#000",document.body.appendChild(e),this.floatingButton=e);}return this.alarm.render({rootElement:this.floatingButton}),this.floatingButton}addClickEvent({callback:t}){if(!this.floatingButton)throw new Error("not initialized");this.floatingButton.addEventListener("click",()=>{t();});}addAlarmClickEvent({callback:t}){this.alarm.addClickEvent({callback:t});}addShortCutEvent({openChatShortcutKey:t,callback:e}){if(!this.floatingButton)throw new Error("not initialized");window.addEventListener("keydown",i=>{R(this,T).call(this,i,t.key)&&(!t.modifier||i[t.modifier])&&e();});}alarmFadeIn(t){this.alarm.fadeIn(t);}alarmRemove(){this.alarm.remove();}};T=new WeakMap;var ne=S;var C=class{constructor(){r(this,"listeners",new Map);r(this,"unifiedMessageHandler",null);}on(t,e){let i=o=>{if(this.isValidOrigin(o))try{let n=o.data,d=typeof n=="string"?JSON.parse(n):n,{type:g}=d;g===t&&e(d);}catch(n){console.warn("Messenger: Failed to parse message data",n);}},a=this.listeners.get(t)||[];return a.push(i),this.listeners.set(t,a),this.unifiedMessageHandler||(this.unifiedMessageHandler=o=>{this.listeners.forEach(n=>n.forEach(d=>d(o)));},window.addEventListener("message",this.unifiedMessageHandler)),()=>{this.unifiedMessageHandler&&(window.removeEventListener("message",this.unifiedMessageHandler),this.unifiedMessageHandler=null);}}removeListener(t){this.listeners.delete(t);}removeAllListeners(){this.listeners.clear(),this.unifiedMessageHandler&&(window.removeEventListener("message",this.unifiedMessageHandler),this.unifiedMessageHandler=null);}postMessage(t){try{let e=this.getMessageTarget();return e?(e.postMessage(t,this.getTargetOrigin()),!0):(console.warn("Messenger: Message target not available"),!1)}catch(e){return console.error("Messenger: postMessage failed",e),false}}};var u=class extends Error{constructor(e,i,a){super(`Handshake failed: ${e}${i?` - ${i}`:""}`);this.reason=e;this.details=i;this.originalError=a;this.name="HandshakeError";}},M=class{constructor(t,e,i){this.getTargetWindow=t;this.getTargetOrigin=e;this.isValidOrigin=i;r(this,"abortController",null);r(this,"messageListener",null);}async execute(t,e={}){let{timeout:i=1e4,maxRetries:a=10,retryInterval:o=500}=e;return this.cancel(),this.abortController=new AbortController,new Promise((n,d)=>{let g=0,f,h=()=>{f&&clearTimeout(f),this.messageListener&&(window.removeEventListener("message",this.messageListener),this.messageListener=null);},v=()=>{h(),d(new u("TIMEOUT","Handshake was cancelled"));};this.abortController?.signal.addEventListener("abort",v),this.messageListener=l=>{if(this.isValidOrigin(l))try{let b=l.data,ue=typeof b=="string"?JSON.parse(b):b;try{let U=oe__namespace.safeParse(tapMessages.ChatInitiatedSchema,ue);h(),this.abortController=null,n(U.output);return}catch{}}catch(b){console.warn("Failed to parse handshake message:",b);}},window.addEventListener("message",this.messageListener),f=setTimeout(()=>{h(),this.abortController=null,d(new u("TIMEOUT",`No valid response received within ${i}ms`));},i);let c=()=>{if(!this.abortController?.signal.aborted)try{let l=this.getTargetWindow();if(!l)throw new u("NO_TARGET_WINDOW","Target iframe window is not available");l.postMessage(t,this.getTargetOrigin()),g++,g<a&&setTimeout(()=>{this.abortController?.signal.aborted||c();},o);}catch(l){h(),this.abortController=null,l instanceof u?d(l):d(new u("MESSAGE_SEND_FAILED","Failed to send handshake message",l));}};c();})}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=class extends C{constructor({hostClientUrl:e,pluginKey:i}){super();r(this,"hostClientUrl");r(this,"pluginKey");r(this,"iframe");r(this,"listenToTap",super.on);this.hostClientUrl=e,this.pluginKey=i;}isValidOrigin(e){if(!this.iframe)return false;let i=e.origin,a=new URL(this.iframe.src).origin;return !!(i===a||i.includes("vercel.app")&&a.includes("vercel.app")||i.includes("localhost")&&a.includes("localhost"))}getMessageTarget(){return this.iframe?.contentWindow||null}getTargetOrigin(){if(!this.iframe?.src)return "*";try{return new URL(this.iframe.src).origin}catch{return "*"}}renderIframe({chatBody:e,isProd:i,isLocal:a}){return new Promise(o=>{this.iframe=document.createElement("iframe"),this.iframe.style.setProperty("display","flex","important"),this.iframe.style.setProperty("border","none","important"),a?this.iframe.src=`${this.hostClientUrl}/chat`:this.iframe.src="https://ax-tap-fe-staging.vercel.app/chat",this.iframe.style.width="100%",this.iframe.style.height="100%",this.iframe.onload=()=>o(this.iframe),e.appendChild(this.iframe);})}hasIframe(){return !!this.iframe}removeIframe(){this.iframe?.remove(),this.iframe=null,this.removeAllListeners();}get postToTap(){return this.iframe||console.warn("TapIframeBridge: iframe not found"),super.postMessage}async performHandshake(e,i){if(!this.iframe)throw new Error("TapIframeBridge: iframe not available for handshake");let a=new M(()=>this.getMessageTarget(),()=>this.getTargetOrigin(),n=>this.isValidOrigin(n)),o={type:tapMessages.CHAT_INIT,hostClientUrl:this.hostClientUrl,pluginKey:this.pluginKey,chatApiParams:e.chatApiParams,theme:e.customStyles};try{return await a.execute(o,i)}catch(n){throw n instanceof Error?new Error(`TapIframeBridge handshake failed: ${n.message}`):n}}};var E=class{constructor(t){this.iframeBridge=t;}onTimelineSeek(t){this.iframeBridge.listenToTap("timeline:seek",e=>t(e.clipPlayHead,e.clipId));}onChatOpened(t){this.iframeBridge.listenToTap("chat:opened",t);}onChatClosed(t){this.iframeBridge.listenToTap("chat:closed",t);}onChatInitiated(t){this.iframeBridge.listenToTap("chat:initiated",t);}onAlarmFadeIn(t){this.iframeBridge.listenToTap("alarm:fadeIn",e=>{t(e.messageInfo);});}onPopUpOpen(t){this.iframeBridge.listenToTap("popUp:open",e=>{t(e.popUpInfo);});}onPdfOpen(t){this.iframeBridge.listenToTap("pdf:open",t);}onPdfClose(t){this.iframeBridge.listenToTap("pdf:close",t);}};var le="wu2gm66",de="wu2gm67",pe="wu2gm68";function Ce({htmlString:s,callback:t,customStyles:e}){let i=document.createElement("div");i.style.position="fixed",i.style.top="0",i.style.left="0",i.style.width="100vw",i.style.height="100vh",i.style.background="rgba(0, 0, 0, 0.4)",i.style.zIndex="10000002";let a=document.createElement("div");a.style.position="fixed",a.style.display="flex",a.style.flexDirection="column";let n=15;if(e?.width){let c=parseFloat(e.width),l=e.width.match(/[a-zA-Z%]+/)?.[0];!isNaN(c)&&l==="px"&&(n+=c);}else n+=340;if(e?.position?.right){let c=parseFloat(e?.position?.right),l=e?.position?.right.match(/[a-zA-Z%]+/)?.[0];!isNaN(c)&&l==="px"&&(n+=c);}else n=n+24;a.style.top=e?.position?.top??"50px",a.style.right=`${n}px`,a.style.left=e?.position?.left??"unset",a.style.bottom=e?.position?.bottom??"unset",a.style.maxWidth="calc(100vw - 100px)",a.style.maxHeight=e?.height??"calc(100vh - 116px)",a.style.overflow="auto",a.style.background="#fff",a.style.padding="20px",a.style.border="1px solid #ccc",a.style.boxShadow="0 4px 20px rgba(0,0,0,0.2)",a.style.zIndex="10000003",a.style.borderRadius="8px";let d=document.createElement("div");d.innerHTML=s,i.addEventListener("click",()=>{document.body.removeChild(i),document.body.removeChild(a),t();}),a.addEventListener("click",c=>{c.stopPropagation();}),a.appendChild(d),document.body.appendChild(i),document.body.appendChild(a);let g=document.querySelector(`.${le}`),f=document.querySelector(".cw-plugin-code-block"),h=document.querySelector(`.${pe}`),v=document.querySelector(`.${de}`);g&&f&&h&&v&&g.addEventListener("click",()=>{navigator.clipboard.writeText(f.textContent??""),h.style.display="none",v.textContent="\uBCF5\uC0AC\uB428",setTimeout(()=>{v.textContent="\uBCF5\uC0AC",h.style.display="inline";},1e3);});}var ce=Ce;var x=class x{constructor({gaId:t}){x.isInitialized||(this.init(t),x.isInitialized=true);}init(t){if(!document.querySelector(`script[src="https://www.googletagmanager.com/gtag/js?id=${t}"]`)){let e=document.createElement("script");e.async=true,e.src=`https://www.googletagmanager.com/gtag/js?id=${t}`,document.head.appendChild(e);}if(typeof window.gtag!="function"){let e=document.createElement("script");e.innerHTML=`
|
|
18
|
+
`,willChange:"transform, opacity, width, max-height, max-width"}),document.body.appendChild(this.chatBody),this.chatBody)}toggleVisibility(t){if(!this.chatBody)return;this.chatBody.classList.remove(O,w),this.chatBody.style.display="block";let e=()=>{this.chatBody&&(this.chatBody.classList.contains(w)&&(this.chatBody.style.display="none"),this.chatBody.removeEventListener("animationend",e));};this.chatBody.addEventListener("animationend",e),requestAnimationFrame(()=>{this.chatBody?.classList.add(t?O:w);});}removeChatBody(){this.chatBody&&(this.chatBody.remove(),this.chatBody=null);}resizeChatBody(t,e){if(!this.chatBody)return;let n=e?.width??"340px",r=parseInt(n,10),o=r/3*10-r,s=t?`${r+o}px`:`${r}px`;this.chatBody.style.width=s;}},ee=D;var te="_6j1ub51",P={default:"_6j1ub5b _6j1ub5a","call-to-action":"_6j1ub5c _6j1ub5a"},ne="_6j1ub5a",re="_6j1ub59",L={default:"_6j1ub5e _6j1ub5d","call-to-action":"_6j1ub5f _6j1ub5d"},ie="_6j1ub5d",se="_6j1ub5h",ue="_6j1ub5g",S="_6j1ub53",oe="_6j1ub58",N={default:"_6j1ub56 _6j1ub55","call-to-action":"_6j1ub57 _6j1ub55"},ae="_6j1ub55",q="_6j1ub52",le="_6j1ub54";var h,ce,pe,fe,ye,he,R=class{constructor(){g(this,h);u(this,"container");u(this,"alarmTimeout");u(this,"alarmCornerSVG");u(this,"textContainer");u(this,"circleElement");u(this,"textInTextContainer");u(this,"messageInfo");}render({rootElement:t}){this.container=document.createElement("div"),this.container.id="alarm-container",this.container.className=te,this.container.addEventListener("click",n=>{n.stopPropagation();}),t.appendChild(this.container),d(this,h,ce).call(this,this.container);let e=d(this,h,pe).call(this,this.container);d(this,h,ye).call(this,e),d(this,h,fe).call(this,e);}fadeIn(t){t.type==="default"||t.type==="hourSpent"?(this.textContainer.className=N.default,this.alarmCornerSVG.setAttribute("class",P.default),this.circleElement.className=L.default):(this.textContainer.className=N["call-to-action"],this.alarmCornerSVG.setAttribute("class",P["call-to-action"]),this.circleElement.className=L["call-to-action"]),this.messageInfo=t,this.textInTextContainer.textContent=t.message,this.toggleVisibility(true),this.alarmTimeout=setTimeout(()=>{this.toggleVisibility(false);},18*1e3);}addClickEvent({callback:t}){this.container.addEventListener("click",()=>{this.toggleVisibility(false),t(this.messageInfo);});}toggleVisibility(t){this.container.classList.remove(q,S),requestAnimationFrame(()=>{this.container?.classList.add(t?q:S);});}remove(){this.container&&this.toggleVisibility(false),this.alarmTimeout&&clearTimeout(this.alarmTimeout);}};h=new WeakSet,ce=function(t){let e=document.createElement("div");e.className=re,t.appendChild(e);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,e.appendChild(n);},pe=function(t){let e=document.createElement("div");return e.className=le,t.appendChild(e),e},fe=function(t){this.textContainer=document.createElement("div"),this.textContainer.className=ae,t.appendChild(this.textContainer),this.textInTextContainer=document.createElement("span"),this.textInTextContainer.className=oe,this.textContainer.appendChild(this.textInTextContainer);},ye=function(t){let e=document.createElement("div");e.className=ie,t.appendChild(e),e.addEventListener("click",r=>{r.stopPropagation(),this.remove();});let n=document.createElement("span");n.className=se,e.appendChild(n),n.textContent="\uC54C\uB9BC \uB044\uAE30",d(this,h,he).call(this,e),this.circleElement=e;},he=function(t){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("width","10"),e.setAttribute("height","10"),e.setAttribute("viewBox","0 0 14 14"),e.setAttribute("fill","none"),e.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"),e.appendChild(n),t.appendChild(e);};var me=R;var _,z=class{constructor(){u(this,"customFloatingButton");u(this,"floatingButton");u(this,"alarm");g(this,_,(t,e)=>t.key===e?true:t.code.startsWith("Key")?t.code.slice(3).toLowerCase()===e:false);this.alarm=new me;}render({customFloatingButton:t}){if(this.customFloatingButton=t,this.customFloatingButton?.isInElement&&this.customFloatingButton?.parentElementId){let e=document.getElementById(this.customFloatingButton.parentElementId);e?.style.setProperty("position","relative","important"),e?.style.setProperty("z-index","10000001","important"),this.floatingButton=e;}else {let e=document.getElementById("cw-plugin");e||(e=document.createElement("button"),e.id="cw-plugin",e.style.zIndex="10000001",e.style.setProperty("z-index","10000001","important"),e.style.setProperty("position","fixed","important"),e.style.width="50px",e.style.height="50px",e.style.borderRadius="50%",e.style.backgroundColor="#000",document.body.appendChild(e),this.floatingButton=e);}return this.alarm.render({rootElement:this.floatingButton}),this.floatingButton}addClickEvent({callback:t}){if(!this.floatingButton)throw new Error("not initialized");this.floatingButton.addEventListener("click",()=>{t();});}addAlarmClickEvent({callback:t}){this.alarm.addClickEvent({callback:t});}addShortCutEvent({openChatShortcutKey:t,callback:e}){if(!this.floatingButton)throw new Error("not initialized");window.addEventListener("keydown",n=>{Y(this,_).call(this,n,t.key)&&(!t.modifier||n[t.modifier])&&e();});}alarmFadeIn(t){this.alarm.fadeIn(t);}alarmRemove(){this.alarm.remove();}};_=new WeakMap;var de=z;var F;function H(i){return {lang:i?.lang??F?.lang,message:i?.message,abortEarly:i?.abortEarly??F?.abortEarly,abortPipeEarly:i?.abortPipeEarly??F?.abortPipeEarly}}var De;function Pe(i){return De?.get(i)}var Le;function Se(i){return Le?.get(i)}var Ne;function qe(i,t){return Ne?.get(i)?.get(t)}function ve(i){let t=typeof i;return t==="string"?`"${i}"`:t==="number"||t==="bigint"||t==="boolean"?`${i}`:t==="object"||t==="function"?(i&&Object.getPrototypeOf(i)?.constructor?.name)??"null":t}function k(i,t,e,n,r){let o=r&&"input"in r?r.input:e.value,s=r?.expected??i.expects??null,c=r?.received??ve(o),a={kind:i.kind,type:i.type,input:o,expected:s,received:c,message:`Invalid ${t}: ${s?`Expected ${s} but r`:"R"}eceived ${c}`,requirement:i.requirement,path:r?.path,issues:r?.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},p=i.kind==="schema",l=r?.message??i.message??qe(i.reference,a.lang)??(p?Se(a.lang):null)??n.message??Pe(a.lang);l!==void 0&&(a.message=typeof l=="function"?l(a):l),p&&(e.typed=false),e.issues?e.issues.push(a):e.issues=[a];}function x(i){return {version:1,vendor:"valibot",validate(t){return i["~run"]({value:t},H())}}}function Re(i,t){return Object.hasOwn(i,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}var ze=class extends Error{constructor(i){super(i[0].message),this.name="ValiError",this.issues=i;}};function Fe(i,t,e){return typeof i.fallback=="function"?i.fallback(t,e):i.fallback}function He(i,t,e){return typeof i.default=="function"?i.default(t,e):i.default}function G(){return {kind:"schema",type:"any",reference:G,expects:"any",async:false,get"~standard"(){return x(this)},"~run"(i){return i.typed=true,i}}}function T(i,t){return {kind:"schema",type:"literal",reference:T,expects:ve(i),async:false,literal:i,message:t,get"~standard"(){return x(this)},"~run"(e,n){return e.value===this.literal?e.typed=true:k(this,"type",e,n),e}}}function I(i,t){return {kind:"schema",type:"object",reference:I,expects:"Object",async:false,entries:i,message:t,get"~standard"(){return x(this)},"~run"(e,n){let r=e.value;if(r&&typeof r=="object"){e.typed=true,e.value={};for(let o in this.entries){let s=this.entries[o];if(o in r||(s.type==="exact_optional"||s.type==="optional"||s.type==="nullish")&&s.default!==void 0){let c=o in r?r[o]:He(s),a=s["~run"]({value:c},n);if(a.issues){let p={type:"object",origin:"value",input:r,key:o,value:c};for(let l of a.issues)l.path?l.path.unshift(p):l.path=[p],e.issues?.push(l);if(e.issues||(e.issues=a.issues),n.abortEarly){e.typed=false;break}}a.typed||(e.typed=false),e.value[o]=a.value;}else if(s.fallback!==void 0)e.value[o]=Fe(s);else if(s.type!=="exact_optional"&&s.type!=="optional"&&s.type!=="nullish"&&(k(this,"key",e,n,{input:void 0,expected:`"${o}"`,path:[{type:"object",origin:"key",input:r,key:o,value:r[o]}]}),n.abortEarly))break}}else k(this,"type",e,n);return e}}}function V(i,t,e){return {kind:"schema",type:"record",reference:V,expects:"Object",async:false,key:i,value:t,message:e,get"~standard"(){return x(this)},"~run"(n,r){let o=n.value;if(o&&typeof o=="object"){n.typed=true,n.value={};for(let s in o)if(Re(o,s)){let c=o[s],a=this.key["~run"]({value:s},r);if(a.issues){let l={type:"object",origin:"key",input:o,key:s,value:c};for(let f of a.issues)f.path=[l],n.issues?.push(f);if(n.issues||(n.issues=a.issues),r.abortEarly){n.typed=false;break}}let p=this.value["~run"]({value:c},r);if(p.issues){let l={type:"object",origin:"value",input:o,key:s,value:c};for(let f of p.issues)f.path?f.path.unshift(l):f.path=[l],n.issues?.push(f);if(n.issues||(n.issues=p.issues),r.abortEarly){n.typed=false;break}}(!a.typed||!p.typed)&&(n.typed=false),a.typed&&(n.value[a.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"(t,e){return typeof t.value=="string"?t.typed=true:k(this,"type",t,e),t}}}function ge(i,t,e){let n=i["~run"]({value:t},H(e));if(n.issues)throw new ze(n.issues);return n.value}function be(i,t,e){let n=i["~run"]({value:t},H(e));return {typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}var ke="chat:init",Ge="chat:initiated";var xe=I({type:T(Ge),gaId:C()}),Ee=I({type:T("GA_EVENT"),payload:V(C(),G())});var A=class{constructor(){u(this,"listeners",new Map);u(this,"unifiedMessageHandler",null);}on(t,e){let n=o=>{if(this.isValidOrigin(o))try{let s=o.data,c=typeof s=="string"?JSON.parse(s):s,{type:a}=c;a===t&&e(c);}catch(s){console.warn("Messenger: Failed to parse message data",s);}},r=this.listeners.get(t)||[];return r.push(n),this.listeners.set(t,r),this.unifiedMessageHandler||(this.unifiedMessageHandler=o=>{this.listeners.forEach(s=>s.forEach(c=>c(o)));},window.addEventListener("message",this.unifiedMessageHandler)),()=>{this.unifiedMessageHandler&&(window.removeEventListener("message",this.unifiedMessageHandler),this.unifiedMessageHandler=null);}}removeListener(t){this.listeners.delete(t);}removeAllListeners(){this.listeners.clear(),this.unifiedMessageHandler&&(window.removeEventListener("message",this.unifiedMessageHandler),this.unifiedMessageHandler=null);}postMessage(t){try{let e=this.getMessageTarget();return e?(e.postMessage(t,this.getTargetOrigin()),!0):(console.warn("Messenger: Message target not available"),!1)}catch(e){return console.error("Messenger: postMessage failed",e),false}}};var v=class extends Error{constructor(e,n,r){super(`Handshake failed: ${e}${n?` - ${n}`:""}`);this.reason=e;this.details=n;this.originalError=r;this.name="HandshakeError";}},M=class{constructor(t,e,n){this.getTargetWindow=t;this.getTargetOrigin=e;this.isValidOrigin=n;u(this,"abortController",null);u(this,"messageListener",null);}async execute(t,e={}){let{timeout:n=1e4,maxRetries:r=10,retryInterval:o=500}=e;return this.cancel(),this.abortController=new AbortController,new Promise((s,c)=>{let a=0,p,l=()=>{p&&clearTimeout(p),this.messageListener&&(window.removeEventListener("message",this.messageListener),this.messageListener=null);},f=()=>{l(),c(new v("TIMEOUT","Handshake was cancelled"));};this.abortController?.signal.addEventListener("abort",f),this.messageListener=y=>{if(this.isValidOrigin(y))try{let b=y.data,Me=typeof b=="string"?JSON.parse(b):b;try{let K=be(xe,Me);l(),this.abortController=null,s(K.output);return}catch{}}catch(b){console.warn("Failed to parse handshake message:",b);}},window.addEventListener("message",this.messageListener),p=setTimeout(()=>{l(),this.abortController=null,c(new v("TIMEOUT",`No valid response received within ${n}ms`));},n);let m=()=>{if(!this.abortController?.signal.aborted)try{let y=this.getTargetWindow();if(!y)throw new v("NO_TARGET_WINDOW","Target iframe window is not available");y.postMessage(t,this.getTargetOrigin()),a++,a<r&&setTimeout(()=>{this.abortController?.signal.aborted||m();},o);}catch(y){l(),this.abortController=null,y instanceof v?c(y):c(new v("MESSAGE_SEND_FAILED","Failed to send handshake message",y));}};m();})}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 j=class extends A{constructor({hostClientUrl:e,pluginKey:n}){super();u(this,"hostClientUrl");u(this,"pluginKey");u(this,"iframe");u(this,"listenToTap",super.on);this.hostClientUrl=e,this.pluginKey=n;}isValidOrigin(e){if(!this.iframe)return false;let n=e.origin,r=new URL(this.iframe.src).origin;return !!(n===r||n.includes("vercel.app")&&r.includes("vercel.app")||n.includes("localhost")&&r.includes("localhost"))}getMessageTarget(){return this.iframe?.contentWindow||null}getTargetOrigin(){if(!this.iframe?.src)return "*";try{return new URL(this.iframe.src).origin}catch{return "*"}}renderIframe({chatBody:e,isProd:n,isLocal:r}){return new Promise(o=>{this.iframe=document.createElement("iframe"),this.iframe.style.setProperty("display","flex","important"),this.iframe.style.setProperty("border","none","important"),r?this.iframe.src=`${this.hostClientUrl}/chat`:this.iframe.src="https://ax-tap-fe-staging.vercel.app/chat",this.iframe.style.width="100%",this.iframe.style.height="100%",this.iframe.onload=()=>o(this.iframe),e.appendChild(this.iframe);})}hasIframe(){return !!this.iframe}removeIframe(){this.iframe?.remove(),this.iframe=null,this.removeAllListeners();}get postToTap(){return this.iframe||console.warn("TapIframeBridge: iframe not found"),super.postMessage}async performHandshake(e,n){if(!this.iframe)throw new Error("TapIframeBridge: iframe not available for handshake");let r=new M(()=>this.getMessageTarget(),()=>this.getTargetOrigin(),s=>this.isValidOrigin(s)),o={type:ke,hostClientUrl:this.hostClientUrl,pluginKey:this.pluginKey,chatApiParams:e.chatApiParams,theme:e.customStyles};try{return await r.execute(o,n)}catch(s){throw s instanceof Error?new Error(`TapIframeBridge handshake failed: ${s.message}`):s}}};var $=class{constructor(t){this.iframeBridge=t;}onTimelineSeek(t){this.iframeBridge.listenToTap("timeline:seek",e=>t(e.clipPlayHead,e.clipId));}onChatOpened(t){this.iframeBridge.listenToTap("chat:opened",t);}onChatClosed(t){this.iframeBridge.listenToTap("chat:closed",t);}onChatInitiated(t){this.iframeBridge.listenToTap("chat:initiated",t);}onAlarmFadeIn(t){this.iframeBridge.listenToTap("alarm:fadeIn",e=>{t(e.messageInfo);});}onPopUpOpen(t){this.iframeBridge.listenToTap("popUp:open",e=>{t(e.popUpInfo);});}onPdfOpen(t){this.iframeBridge.listenToTap("pdf:open",t);}onPdfClose(t){this.iframeBridge.listenToTap("pdf:close",t);}};var we="wu2gm66",_e="wu2gm67",Te="wu2gm68";function Ue({htmlString:i,callback:t,customStyles:e}){let n=document.createElement("div");n.style.position="fixed",n.style.top="0",n.style.left="0",n.style.width="100vw",n.style.height="100vh",n.style.background="rgba(0, 0, 0, 0.4)",n.style.zIndex="10000002";let r=document.createElement("div");r.style.position="fixed",r.style.display="flex",r.style.flexDirection="column";let s=15;if(e?.width){let m=parseFloat(e.width),y=e.width.match(/[a-zA-Z%]+/)?.[0];!isNaN(m)&&y==="px"&&(s+=m);}else s+=340;if(e?.position?.right){let m=parseFloat(e?.position?.right),y=e?.position?.right.match(/[a-zA-Z%]+/)?.[0];!isNaN(m)&&y==="px"&&(s+=m);}else s=s+24;r.style.top=e?.position?.top??"50px",r.style.right=`${s}px`,r.style.left=e?.position?.left??"unset",r.style.bottom=e?.position?.bottom??"unset",r.style.maxWidth="calc(100vw - 100px)",r.style.maxHeight=e?.height??"calc(100vh - 116px)",r.style.overflow="auto",r.style.background="#fff",r.style.padding="20px",r.style.border="1px solid #ccc",r.style.boxShadow="0 4px 20px rgba(0,0,0,0.2)",r.style.zIndex="10000003",r.style.borderRadius="8px";let c=document.createElement("div");c.innerHTML=i,n.addEventListener("click",()=>{document.body.removeChild(n),document.body.removeChild(r),t();}),r.addEventListener("click",m=>{m.stopPropagation();}),r.appendChild(c),document.body.appendChild(n),document.body.appendChild(r);let a=document.querySelector(`.${we}`),p=document.querySelector(".cw-plugin-code-block"),l=document.querySelector(`.${Te}`),f=document.querySelector(`.${_e}`);a&&p&&l&&f&&a.addEventListener("click",()=>{navigator.clipboard.writeText(p.textContent??""),l.style.display="none",f.textContent="\uBCF5\uC0AC\uB428",setTimeout(()=>{f.textContent="\uBCF5\uC0AC",l.style.display="inline";},1e3);});}var Ie=Ue;var E=class E{constructor({gaId:t}){E.isInitialized||(this.init(t),E.isInitialized=true);}init(t){if(!document.querySelector(`script[src="https://www.googletagmanager.com/gtag/js?id=${t}"]`)){let e=document.createElement("script");e.async=true,e.src=`https://www.googletagmanager.com/gtag/js?id=${t}`,document.head.appendChild(e);}if(typeof window.gtag!="function"){let e=document.createElement("script");e.innerHTML=`
|
|
19
19
|
window.dataLayer = window.dataLayer || [];
|
|
20
20
|
function gtag(){dataLayer.push(arguments);}
|
|
21
21
|
gtag('js', new Date());
|
|
22
22
|
gtag('config', '${t}');
|
|
23
|
-
`,document.head.appendChild(e);}window.addEventListener("message",e=>{try{let
|
|
23
|
+
`,document.head.appendChild(e);}window.addEventListener("message",e=>{try{let n=typeof e.data=="string"?JSON.parse(e.data):e.data,r=ge(Ee,n);typeof window.gtag=="function"&&window.gtag("event",r.payload.action??"click",{event_category:r.payload.category??"Default",event_label:r.payload.label,value:r.payload.value,fastCampus_user_id:r.payload.fastCampus_user_id,course_id:r.payload.course_id,...r.payload});}catch{}});}};u(E,"isInitialized",false);var W=E,Ce=W;var B,Ae,X=class{constructor({pluginKey:t,isProd:e=false,isLocal:n=false}){g(this,B);u(this,"pluginKey");u(this,"iframeBridge");u(this,"events");u(this,"chatBody",null);u(this,"chatBodyMaker");u(this,"floatingButtonMaker");u(this,"shortcutKey",{openChat:{key:"/",modifier:""},sendChat:{key:"Enter",modifier:""}});u(this,"isProd");u(this,"isLocal");u(this,"isOpen");u(this,"isPdfOpen");this.pluginKey=t,this.iframeBridge=new j({hostClientUrl:window.location.origin,pluginKey:this.pluginKey}),this.events=new $(this.iframeBridge),this.floatingButtonMaker=new de,this.chatBodyMaker=new ee,this.isProd=e,this.isLocal=n,this.isOpen=false,this.isPdfOpen=false;}setIsOpen(t){this.isOpen=t;}setIsPdfOpen(t){this.isPdfOpen=t;}seekTimeline({clipId:t,clipPlayHead:e}){this.iframeBridge.postToTap({type:"timeline:seek",clipId:t,clipPlayHead:e});}async initChat({chatApiParams:t,customStyles:e,shortcutKey:n}){if(!d(this,B,Ae).call(this))throw new Error("not client");this.shortcutKey={openChat:n?.openChat??this.shortcutKey.openChat,sendChat:n?.sendChat??this.shortcutKey.sendChat},this.chatBody||(this.chatBody=this.chatBodyMaker.createChatBody({...e?.chatBody&&{customChatBody:e.chatBody}})),this.iframeBridge.hasIframe()||await this.iframeBridge.renderIframe({chatBody:this.chatBody,isProd:this.isProd,isLocal:this.isLocal});try{let r=await this.iframeBridge.performHandshake({chatApiParams:t,customStyles:e},{retryInterval:500,maxRetries:10,timeout:1e4});new Ce({gaId:r.gaId});}catch(r){throw console.error("Handshake failed:",r),new Error(`Chat initialization failed: ${r instanceof Error?r.message:"Unknown error"}`)}this.floatingButtonMaker.render({...e?.floatingButton&&{customFloatingButton:e.floatingButton}}),this.floatingButtonMaker.addClickEvent({callback:()=>{this.iframeBridge.postToTap({type:this.isOpen?"chat:close":"chat:open"});}}),this.floatingButtonMaker.addAlarmClickEvent({callback:r=>{this.iframeBridge.postToTap({type:"chat:open",isAlarm:true}),this.iframeBridge.postToTap({type:"alarm:click",messageInfo:r});}}),this.iframeBridge.listenToTap("chat:opened",()=>{this.setIsOpen(true),this.chatBodyMaker.toggleVisibility(this.isOpen),this.floatingButtonMaker.alarmRemove();}),this.iframeBridge.listenToTap("chat:closed",()=>{this.setIsOpen(false),this.chatBodyMaker.toggleVisibility(this.isOpen);}),this.iframeBridge.listenToTap("alarm:fadeIn",r=>{this.isOpen||this.floatingButtonMaker.alarmFadeIn(r.messageInfo);}),this.iframeBridge.listenToTap("popUp:open",r=>{Ie({htmlString:r.popUpInfo.html,callback:()=>this.iframeBridge.postToTap({type:"popUp:close"}),...e?.chatBody&&{customStyles:e.chatBody}});}),this.iframeBridge.listenToTap("pdf:open",()=>{this.setIsPdfOpen(true),this.chatBodyMaker.resizeChatBody(this.isPdfOpen,e?.chatBody),this.iframeBridge.postToTap({type:"pdf:enlarged"});}),this.iframeBridge.listenToTap("pdf:close",()=>{this.setIsPdfOpen(false),this.chatBodyMaker.resizeChatBody(this.isPdfOpen,e?.chatBody),this.iframeBridge.postToTap({type:"pdf:shrinked"});}),this.isLocal&&this.iframeBridge.listenToTap("alarm:fadeIn",r=>{this.floatingButtonMaker.alarmFadeIn(r.messageInfo);});}removeChat(){if(!this.chatBody)throw new Error("chatBody is not initialized");this.chatBodyMaker.removeChatBody(),this.floatingButtonMaker.alarmRemove(),this.iframeBridge.removeIframe(),this.chatBody=null,this.isOpen=false;}postChatInfo({clipId:t,clipPlayHead:e}){this.seekTimeline({clipId:t,clipPlayHead:e});}getTimelineInfo({callback:t}){this.events.onTimelineSeek(t);}};B=new WeakSet,Ae=function(){return typeof window<"u"&&typeof document<"u"};var Xt=X;module.exports=Xt;//# sourceMappingURL=index.js.map
|
|
24
24
|
//# sourceMappingURL=index.js.map
|