@coxwave/tap-sdk 0.0.7 → 0.0.8
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/README.md +79 -107
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +63 -28
- package/dist/index.d.ts +63 -28
- package/dist/index.global.js +4 -4
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/index.ts +0 -323
package/dist/index.js
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
if (typeof document !== 'undefined') {
|
|
5
5
|
const style = document.createElement('style');
|
|
6
6
|
style.id = 'tap-sdk-styles';
|
|
7
|
-
style.textContent = "@keyframes _1mlv4me0{0%{opacity:0;transform:translateY(30px)}to{opacity:1;transform:translateY(0)}}@keyframes _1mlv4me1{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(30px);display:none}}._1mlv4me2{opacity:0;transform:translateY(30px);transition:opacity .4s ease,transform .4s ease;pointer-events:none;display:none}._1mlv4me3{animation:_1mlv4me0 .4s ease forwards;pointer-events:auto}._1mlv4me4{animation:_1mlv4me1 .4s ease forwards;pointer-events:none}._1mlv4me5{border:none!important}@keyframes
|
|
7
|
+
style.textContent = "@keyframes _1mlv4me0{0%{opacity:0;transform:translateY(30px)}to{opacity:1;transform:translateY(0)}}@keyframes _1mlv4me1{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(30px);display:none}}._1mlv4me2{opacity:0;transform:translateY(30px);transition:opacity .4s ease,transform .4s ease;pointer-events:none;display:none}._1mlv4me3{animation:_1mlv4me0 .4s ease forwards;pointer-events:auto}._1mlv4me4{animation:_1mlv4me1 .4s ease forwards;pointer-events:none}._1mlv4me5{border:none!important}@keyframes wtjce00{0%{opacity:1;pointer-events:auto}50%{opacity:1}to{opacity:0}}.wtjce01{pointer-events:none;opacity:0;display:flex;position:absolute;width:max-content;top:calc(100% + 5px);right:0;flex-direction:column;justify-content:center;align-items:flex-end;padding-top:2px;cursor:pointer;z-index:999;transition:opacity .3s ease}.wtjce02{pointer-events:auto;animation:wtjce00 18s forwards}.wtjce03{opacity:0;pointer-events:none;animation:none}.wtjce04{display:flex;justify-content:flex-end;border-radius:var(--Radius-radiusSM, 8px);width:max-content;gap:5px}.wtjce05{display:flex;padding:8px 12px 6px;justify-content:flex-end;align-items:center;border-radius:var(--Radius-radiusSM, 8px);max-width:340px}.wtjce06{background-color:#171b1f}.wtjce07{background-color:#fa6b4b}.wtjce08{color:#fff;text-align:right;font-family:Pretendard;font-size:14px;font-style:normal;font-weight:400;line-height:20px;white-space:pre-wrap;word-break:keep-all;overflow-wrap:break-word}.wtjce09{display:flex;padding:0 23px;align-items:flex-start;gap:10px}.wtjce0a{width:15px}.wtjce0b{color:#171b1f}.wtjce0c{color:#fa6b4b}.wtjce0d{cursor:pointer;justify-content:center;align-items:center;width:20px;height:20px;border-radius:100px;z-index:999;transition:all .2s ease}.wtjce0d:hover{width:63px;left:-72px}.wtjce04:hover .wtjce0d{display:flex}.wtjce0e,.wtjce0f{display:none;background-color:#171b1f}.wtjce0g{color:#fff}.wtjce0d:hover .wtjce0g{display:none}.wtjce0h{color:#fff;text-align:center;font-family:Pretendard;font-size:12px;font-style:normal;font-weight:400;line-height:20px;display:none}.wtjce0d:hover .wtjce0h{display:block}.wu2gm60{width:100%;min-width:max-content;table-layout:auto;border-collapse:separate;border-spacing:0;border:.4px solid rgba(118,118,128,.12);border-radius:8px;overflow:auto;background-color:#fff;cursor:pointer}.wu2gm61{border:.4px solid rgba(118,118,128,.12);padding:10px;background-color:#f2f2f2;text-align:left;font-family:Pretendard;color:#090909;font-size:12px;font-weight:500;white-space:normal;overflow-wrap:break-word;word-break:break-word}.wu2gm62{border:.4px solid rgba(118,118,128,.12);padding:10px;color:#090909;font-family:Pretendard;font-size:12px;font-weight:400;width:fit-content;max-width:400px;white-space:normal;overflow-wrap:break-word;word-break:break-word}.wu2gm63{position:relative;background-color:#fafafa;border-radius:8px;padding:8px;overflow-y:auto}.wu2gm64{display:flex;align-items:center;justify-content:space-between;padding-bottom:4px}.wu2gm65{color:#4a5568;padding:2px 6px;font-size:12px;border-radius:4px;z-index:10;font-family:Pretendard}.wu2gm66{z-index:10;cursor:pointer;display:flex;align-items:center;width:max-content;color:#4a5568;padding:2px 6px;font-size:12px;border:none;font-family:Pretendard}.wu2gm67{white-space:nowrap}.wu2gm68{display:flex;width:12px;height:12px;margin-bottom:4px;color:#4a5568;flex-shrink:0}\n/*# sourceMappingURL=index.css.map */";
|
|
8
8
|
if (!document.getElementById('tap-sdk-styles')) {
|
|
9
9
|
document.head.appendChild(style);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
})();
|
|
13
13
|
|
|
14
|
-
'use strict';var
|
|
14
|
+
'use strict';var Oe=Object.defineProperty;var Z=r=>{throw TypeError(r)};var je=(r,e,t)=>e in r?Oe(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var o=(r,e,t)=>je(r,typeof e!="symbol"?e+"":e,t),Y=(r,e,t)=>e.has(r)||Z("Cannot "+t);var Q=(r,e,t)=>(Y(r,e,"read from private field"),t?t.call(r):e.get(r)),v=(r,e,t)=>e.has(r)?Z("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t);var m=(r,e,t)=>(Y(r,e,"access private method"),t);var ee="_1mlv4me2",I="_1mlv4me4";var L="_1mlv4me3";var N=class{constructor(){o(this,"chatBody",null);this.chatBody=null;}createChatBody({customChatBody:e}){return this.chatBody?this.chatBody:(this.chatBody=document.createElement("div"),this.chatBody.id="cw-chat-body",this.chatBody.className=ee,this.chatBody.style.setProperty("z-index","10000001","important"),this.chatBody.style.setProperty("position","fixed","important"),Object.assign(this.chatBody.style,{top:e?.position?.top??"50px",right:e?.position?.right??"24px",left:e?.position?.left??"unset",bottom:e?.position?.bottom??"unset",width:e?.width??"340px",height:e?.height??"calc(100% - 116px)",overflow:"hidden",backgroundColor:"transparent",borderRadius:e?.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($,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?$:w);});}removeChatBody(){this.chatBody&&(this.chatBody.remove(),this.chatBody=null);}resizeChatBody(t,e){if(!this.chatBody)return;let n=e?.width??"340px",i=parseInt(n,10),o=i/3*10-i,s=t?`${i+o}px`:`${i}px`;this.chatBody.style.width=s;}},Z=D;var Y="_6j1ub51",O={default:"_6j1ub5b _6j1ub5a","call-to-action":"_6j1ub5c _6j1ub5a"},Q="_6j1ub5a",ee="_6j1ub59",P={default:"_6j1ub5e _6j1ub5d","call-to-action":"_6j1ub5f _6j1ub5d"},te="_6j1ub5d",ne="_6j1ub5h",re="_6j1ub5g",S="_6j1ub53",ie="_6j1ub58",L={default:"_6j1ub56 _6j1ub55","call-to-action":"_6j1ub57 _6j1ub55"},se="_6j1ub55",N="_6j1ub52",ue="_6j1ub54";var h,oe,ae,le,ce,pe,q=class{constructor(){k(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=Y,this.container.addEventListener("click",n=>{n.stopPropagation();}),t.appendChild(this.container),d(this,h,oe).call(this,this.container);let e=d(this,h,ae).call(this,this.container);d(this,h,ce).call(this,e),d(this,h,le).call(this,e);}fadeIn(t){t.type==="default"||t.type==="hourSpent"?(this.textContainer.className=L.default,this.alarmCornerSVG.setAttribute("class",O.default),this.circleElement.className=P.default):(this.textContainer.className=L["call-to-action"],this.alarmCornerSVG.setAttribute("class",O["call-to-action"]),this.circleElement.className=P["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(N,S),requestAnimationFrame(()=>{this.container?.classList.add(t?N:S);});}remove(){this.container&&this.toggleVisibility(false),this.alarmTimeout&&clearTimeout(this.alarmTimeout);}};h=new WeakSet,oe=function(t){let e=document.createElement("div");e.className=ee,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",Q);let i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d","M5.5 0L11.1292 8.25H-0.129165L5.5 0Z"),i.setAttribute("fill","currentColor"),n.appendChild(i),this.alarmCornerSVG=n,e.appendChild(n);},ae=function(t){let e=document.createElement("div");return e.className=ue,t.appendChild(e),e},le=function(t){this.textContainer=document.createElement("div"),this.textContainer.className=se,t.appendChild(this.textContainer),this.textInTextContainer=document.createElement("span"),this.textInTextContainer.className=ie,this.textContainer.appendChild(this.textInTextContainer);},ce=function(t){let e=document.createElement("div");e.className=te,t.appendChild(e),e.addEventListener("click",i=>{i.stopPropagation(),this.remove();});let n=document.createElement("span");n.className=ne,e.appendChild(n),n.textContent="\uC54C\uB9BC \uB044\uAE30",d(this,h,pe).call(this,e),this.circleElement=e;},pe=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",re);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 fe=q;var _,F=class{constructor(){u(this,"customFloatingButton");u(this,"floatingButton");u(this,"alarm");k(this,_,(t,e)=>t.key===e?true:t.code.startsWith("Key")?t.code.slice(3).toLowerCase()===e:false);this.alarm=new fe;}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=>{K(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 ye=F;var R;function he(r){return {lang:r?.lang??R?.lang,message:r?.message,abortEarly:r?.abortEarly??R?.abortEarly,abortPipeEarly:r?.abortPipeEarly??R?.abortPipeEarly}}var Be;function je(r){return Be?.get(r)}var $e;function De(r){return $e?.get(r)}var Oe;function Pe(r,t){return Oe?.get(r)?.get(t)}function me(r){let t=typeof r;return t==="string"?`"${r}"`:t==="number"||t==="bigint"||t==="boolean"?`${r}`:t==="object"||t==="function"?(r&&Object.getPrototypeOf(r)?.constructor?.name)??"null":t}function x(r,t,e,n,i){let o=i&&"input"in i?i.input:e.value,s=i?.expected??r.expects??null,c=i?.received??me(o),a={kind:r.kind,type:r.type,input:o,expected:s,received:c,message:`Invalid ${t}: ${s?`Expected ${s} but r`:"R"}eceived ${c}`,requirement:r.requirement,path:i?.path,issues:i?.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},p=r.kind==="schema",l=i?.message??r.message??Pe(r.reference,a.lang)??(p?De(a.lang):null)??n.message??je(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 E(r){return {version:1,vendor:"valibot",validate(t){return r["~run"]({value:t},he())}}}function Se(r,t){return Object.hasOwn(r,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}function Le(r,t,e){return typeof r.fallback=="function"?r.fallback(t,e):r.fallback}function Ne(r,t,e){return typeof r.default=="function"?r.default(t,e):r.default}function z(){return {kind:"schema",type:"any",reference:z,expects:"any",async:false,get"~standard"(){return E(this)},"~run"(r){return r.typed=true,r}}}function T(r,t){return {kind:"schema",type:"literal",reference:T,expects:me(r),async:false,literal:r,message:t,get"~standard"(){return E(this)},"~run"(e,n){return e.value===this.literal?e.typed=true:x(this,"type",e,n),e}}}function I(r,t){return {kind:"schema",type:"object",reference:I,expects:"Object",async:false,entries:r,message:t,get"~standard"(){return E(this)},"~run"(e,n){let i=e.value;if(i&&typeof i=="object"){e.typed=true,e.value={};for(let o in this.entries){let s=this.entries[o];if(o in i||(s.type==="exact_optional"||s.type==="optional"||s.type==="nullish")&&s.default!==void 0){let c=o in i?i[o]:Ne(s),a=s["~run"]({value:c},n);if(a.issues){let p={type:"object",origin:"value",input:i,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]=Le(s);else if(s.type!=="exact_optional"&&s.type!=="optional"&&s.type!=="nullish"&&(x(this,"key",e,n,{input:void 0,expected:`"${o}"`,path:[{type:"object",origin:"key",input:i,key:o,value:i[o]}]}),n.abortEarly))break}}else x(this,"type",e,n);return e}}}function H(r,t,e){return {kind:"schema",type:"record",reference:H,expects:"Object",async:false,key:r,value:t,message:e,get"~standard"(){return E(this)},"~run"(n,i){let o=n.value;if(o&&typeof o=="object"){n.typed=true,n.value={};for(let s in o)if(Se(o,s)){let c=o[s],a=this.key["~run"]({value:s},i);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),i.abortEarly){n.typed=false;break}}let p=this.value["~run"]({value:c},i);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),i.abortEarly){n.typed=false;break}}(!a.typed||!p.typed)&&(n.typed=false),a.typed&&(n.value[a.value]=p.value);}}else x(this,"type",n,i);return n}}}function C(r){return {kind:"schema",type:"string",reference:C,expects:"string",async:false,message:r,get"~standard"(){return E(this)},"~run"(t,e){return typeof t.value=="string"?t.typed=true:x(this,"type",t,e),t}}}function de(r,t,e){let n=r["~run"]({value:t},he(e));return {typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}var ge="chat:init",qe="chat:initiated";var be=I({type:T(qe),gaId:C()});I({type:T("GA_EVENT"),payload:H(C(),z())});var M=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);}},i=this.listeners.get(t)||[];return i.push(n),this.listeners.set(t,i),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,i){super(`Handshake failed: ${e}${n?` - ${n}`:""}`);this.reason=e;this.details=n;this.originalError=i;this.name="HandshakeError";}},A=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:i=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,Te=typeof b=="string"?JSON.parse(b):b,V=de(be,Te);if(V.success){l(),this.abortController=null,s(V.output);return}}catch{}},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(),b=this.getTargetOrigin();if(!y)throw new v("NO_TARGET_WINDOW","Target iframe window is not available");y.postMessage(t,b),a++,a<i&&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 B=class extends M{constructor({hostClientUrl:e,apiKey:n}){super();u(this,"hostClientUrl");u(this,"apiKey");u(this,"iframe");u(this,"postToTap",e=>this.iframe?super.postMessage(e):(console.error("TapIframeBridge: iframe not found - ensure createIframeChat() was called first"),console.error("Failed to send message:",e),(e.type==="chat:open"||e.type==="chat:close")&&console.error("Chat cannot be opened/closed - iframe is not initialized"),false));u(this,"listenToTap",super.on);this.hostClientUrl=e,this.apiKey=n;}isValidOrigin(e){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({chatBody:e,isProd:n,isLocal:i}){return new Promise(o=>{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"),i?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();}async performHandshake(e,n){if(!this.iframe)throw new Error("TapIframeBridge: iframe not available for handshake");let i=new A(()=>this.getMessageTarget(),()=>this.getTargetOrigin(),s=>this.isValidOrigin(s)),o={type:ge,hostClientUrl:this.hostClientUrl,apiKey:this.apiKey,chatApiParams:e.chatApiParams,apiUrl:e?.apiUrl||""};try{return await i.execute(o,n)}catch(s){throw s instanceof Error?new Error(`TapIframeBridge handshake failed: ${s.message}`):s}}};var j=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 ke="wu2gm66",xe="wu2gm67",Ee="wu2gm68";function Re({htmlString:r,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 i=document.createElement("div");i.id="wow",i.style.position="fixed",i.style.display="flex",i.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;i.style.top=e?.position?.top??"50px",i.style.right=`${s}px`,i.style.left=e?.position?.left??"unset",i.style.bottom=e?.position?.bottom??"unset",i.style.maxWidth="calc(100vw - 100px)",i.style.maxHeight=e?.height??"calc(100vh - 116px)",i.style.overflow="auto",i.style.background="#fff",i.style.padding="20px",i.style.border="1px solid #ccc",i.style.boxShadow="0 4px 20px rgba(0,0,0,0.2)",i.style.zIndex="10000003",i.style.borderRadius="8px";let c=document.createElement("div");c.innerHTML=r,n.addEventListener("click",()=>{document.body.removeChild(n),document.body.removeChild(i),t();}),i.addEventListener("click",m=>{m.stopPropagation();}),i.appendChild(c),document.body.appendChild(n),document.body.appendChild(i);let a=document.querySelector(`.${ke}`),p=document.querySelector(".cw-plugin-code-block"),l=document.querySelector(`.${Ee}`),f=document.querySelector(`.${xe}`);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 we=Re;var g,U,_e,G=class{constructor({apiKey:t,isProd:e=false,isLocal:n=false}){k(this,g);u(this,"apiKey");u(this,"iframeBridge");u(this,"events");u(this,"chatBody",null);u(this,"chatBodyMaker");u(this,"floatingButtonMaker");u(this,"isProd");u(this,"isLocal");u(this,"isOpen");u(this,"isPdfOpen");this.apiKey=t,this.iframeBridge=new B({hostClientUrl:window.location.origin,apiKey:this.apiKey}),this.events=new j(this.iframeBridge),this.floatingButtonMaker=new ye,this.chatBodyMaker=new Z,this.isProd=e,this.isLocal=n,this.isOpen=false,this.isPdfOpen=false;}setIsOpen(t){this.isOpen=t;}setIsPdfOpen(t){this.isPdfOpen=t;}sendChatMessage(){let t=this.isOpen?"chat:close":"chat:open";try{this.iframeBridge.postToTap({type:t})||console.error(`[TapSDK] Failed to send ${t} message`);}catch(e){console.error("[TapSDK] Error sending chat message:",e);}}seekTimeline({clipId:t,clipPlayHead:e}){this.iframeBridge.postToTap({type:"timeline:seek",clipId:t,clipPlayHead:e});}async initChat({course:t,customStyles:e}){if(!d(this,g,U).call(this))throw console.error("[TapSDK] Not running in client environment: window is not defined"),new Error("not client: window is not defined");if(!this.chatBody){let n=this.chatBodyMaker.createChatBody({...e?.chatBody&&{customChatBody:e.chatBody}});if(!n)throw console.error("[TapSDK] Failed to create chat body"),new Error("Failed to create chat body");this.chatBody=n;}this.iframeBridge.hasIframe()||await this.iframeBridge.renderIframe({chatBody:this.chatBody,isProd:this.isProd,isLocal:this.isLocal});try{let n=d(this,g,_e).call(this);await this.iframeBridge.performHandshake({chatApiParams:t,customStyles:e,apiUrl:n},{retryInterval:500,maxRetries:3,timeout:1e4});}catch(n){throw console.error("[TapSDK] Handshake failed:",n),new Error(`Chat initialization failed: ${n instanceof Error?n.message:"Unknown error"}`)}this.floatingButtonMaker.render({...e?.floatingButton&&{customFloatingButton:e.floatingButton}}),this.floatingButtonMaker.addClickEvent({callback:()=>{if(!this.iframeBridge.hasIframe()){this.iframeBridge.renderIframe({chatBody:this.chatBody,isProd:this.isProd,isLocal:this.isLocal}).then(()=>{this.sendChatMessage();}).catch(i=>{console.error("[TapSDK] Failed to recreate iframe:",i);});return}this.sendChatMessage();let n=this.isOpen?"chat:close":"chat:open";this.iframeBridge.postToTap({type:n});}}),this.floatingButtonMaker.addAlarmClickEvent({callback:n=>{this.iframeBridge.postToTap({type:"chat:open",isAlarm:true}),this.iframeBridge.postToTap({type:"alarm:click",messageInfo:n});}}),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",n=>{this.isOpen||this.floatingButtonMaker.alarmFadeIn(n.messageInfo);}),this.iframeBridge.listenToTap("popUp:open",n=>{we({htmlString:n.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",n=>{this.floatingButtonMaker.alarmFadeIn(n.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);}};g=new WeakSet,U=function(){return typeof window<"u"&&typeof document<"u"},_e=function(){if(d(this,g,U).call(this))try{let t=localStorage.getItem("tap-backend-url-storage");return t?JSON.parse(t)?.state?.apiUrl:void 0}catch{return}};var qt=G;
|
|
19
|
-
module.exports=
|
|
18
|
+
`,willChange:"transform, opacity, width, max-height, max-width"}),document.body.appendChild(this.chatBody),this.chatBody)}toggleVisibility(e){if(!this.chatBody)return;this.chatBody.classList.remove(L,I),this.chatBody.style.display="block";let t=()=>{this.chatBody&&(this.chatBody.classList.contains(I)&&(this.chatBody.style.display="none"),this.chatBody.removeEventListener("animationend",t));};this.chatBody.addEventListener("animationend",t),requestAnimationFrame(()=>{this.chatBody?.classList.add(e?L:I);});}removeChatBody(){this.chatBody&&(this.chatBody.remove(),this.chatBody=null);}resizeChatBody(e,t){if(!this.chatBody)return;let n=t?.width??"340px",i=parseInt(n,10),u=i/3*10-i,s=e?`${i+u}px`:`${i}px`;this.chatBody.style.width=s;}},te=N;var T,z=class{constructor(){o(this,"buttonElement");v(this,T,(e,t)=>e.key===t?true:e.code.startsWith("Key")?e.code.slice(3).toLowerCase()===t:false);}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);}onKeyboardShortcut({openChatShortcutKey:e,callback:t}){if(!this.buttonElement)throw new Error("not initialized");window.addEventListener("keydown",n=>{Q(this,T).call(this,n,e.key)&&(!e.modifier||n[e.modifier])&&t();});}getButtonElement(){return this.buttonElement}};T=new WeakMap;var ne=z;var re="wtjce01",q={default:"wtjce0b wtjce0a","call-to-action":"wtjce0c wtjce0a"},ie="wtjce0a",se="wtjce09",R={default:"wtjce0e wtjce0d","call-to-action":"wtjce0f wtjce0d"},ue="wtjce0d",oe="wtjce0h",ae="wtjce0g",H="wtjce03",le="wtjce08",F={default:"wtjce06 wtjce05","call-to-action":"wtjce07 wtjce05"},ce="wtjce05",V="wtjce02",pe="wtjce04";var h,fe,ye,he,me,de,G=class{constructor(){v(this,h);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=re,this.container.addEventListener("click",n=>{n.stopPropagation();}),e.appendChild(this.container),m(this,h,fe).call(this,this.container);let t=m(this,h,ye).call(this,this.container);m(this,h,me).call(this,t),m(this,h,he).call(this,t);}fadeIn(e){e.type==="default"||e.type==="hourSpent"?(this.textContainer.className=F.default,this.alarmCornerSVG.setAttribute("class",q.default),this.circleElement.className=R.default):(this.textContainer.className=F["call-to-action"],this.alarmCornerSVG.setAttribute("class",q["call-to-action"]),this.circleElement.className=R["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(V,H),requestAnimationFrame(()=>{this.container?.classList.add(e?V:H);});}remove(){this.container&&this.toggleVisibility(false),this.alarmTimeout&&clearTimeout(this.alarmTimeout);}};h=new WeakSet,fe=function(e){let t=document.createElement("div");t.className=se,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",ie);let i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d","M5.5 0L11.1292 8.25H-0.129165L5.5 0Z"),i.setAttribute("fill","currentColor"),n.appendChild(i),this.alarmCornerSVG=n,t.appendChild(n);},ye=function(e){let t=document.createElement("div");return t.className=pe,e.appendChild(t),t},he=function(e){this.textContainer=document.createElement("div"),this.textContainer.className=ce,e.appendChild(this.textContainer),this.textInTextContainer=document.createElement("span"),this.textInTextContainer.className=le,this.textContainer.appendChild(this.textInTextContainer);},me=function(e){let t=document.createElement("div");t.className=ue,e.appendChild(t),t.addEventListener("click",i=>{i.stopPropagation(),this.remove();});let n=document.createElement("span");n.className=oe,t.appendChild(n),n.textContent="\uC54C\uB9BC \uB044\uAE30",m(this,h,de).call(this,t),this.circleElement=t;},de=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",ae);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 ve=G;var U;function ge(r){return {lang:r?.lang??U?.lang,message:r?.message,abortEarly:r?.abortEarly??U?.abortEarly,abortPipeEarly:r?.abortPipeEarly??U?.abortPipeEarly}}var Se;function Le(r){return Se?.get(r)}var Ne;function ze(r){return Ne?.get(r)}var qe;function Re(r,e){return qe?.get(r)?.get(e)}function be(r){let e=typeof r;return e==="string"?`"${r}"`:e==="number"||e==="bigint"||e==="boolean"?`${r}`:e==="object"||e==="function"?(r&&Object.getPrototypeOf(r)?.constructor?.name)??"null":e}function w(r,e,t,n,i){let u=i&&"input"in i?i.input:t.value,s=i?.expected??r.expects??null,c=i?.received??be(u),a={kind:r.kind,type:r.type,input:u,expected:s,received:c,message:`Invalid ${e}: ${s?`Expected ${s} but r`:"R"}eceived ${c}`,requirement:r.requirement,path:i?.path,issues:i?.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},p=r.kind==="schema",l=i?.message??r.message??Re(r.reference,a.lang)??(p?ze(a.lang):null)??n.message??Le(a.lang);l!==void 0&&(a.message=typeof l=="function"?l(a):l),p&&(t.typed=false),t.issues?t.issues.push(a):t.issues=[a];}function E(r){return {version:1,vendor:"valibot",validate(e){return r["~run"]({value:e},ge())}}}function He(r,e){return Object.hasOwn(r,e)&&e!=="__proto__"&&e!=="prototype"&&e!=="constructor"}function Fe(r,e,t){return typeof r.fallback=="function"?r.fallback(e,t):r.fallback}function Ve(r,e,t){return typeof r.default=="function"?r.default(e,t):r.default}function K(){return {kind:"schema",type:"any",reference:K,expects:"any",async:false,get"~standard"(){return E(this)},"~run"(r){return r.typed=true,r}}}function _(r,e){return {kind:"schema",type:"literal",reference:_,expects:be(r),async:false,literal:r,message:e,get"~standard"(){return E(this)},"~run"(t,n){return t.value===this.literal?t.typed=true:w(this,"type",t,n),t}}}function C(r,e){return {kind:"schema",type:"object",reference:C,expects:"Object",async:false,entries:r,message:e,get"~standard"(){return E(this)},"~run"(t,n){let i=t.value;if(i&&typeof i=="object"){t.typed=true,t.value={};for(let u in this.entries){let s=this.entries[u];if(u in i||(s.type==="exact_optional"||s.type==="optional"||s.type==="nullish")&&s.default!==void 0){let c=u in i?i[u]:Ve(s),a=s["~run"]({value:c},n);if(a.issues){let p={type:"object",origin:"value",input:i,key:u,value:c};for(let l of a.issues)l.path?l.path.unshift(p):l.path=[p],t.issues?.push(l);if(t.issues||(t.issues=a.issues),n.abortEarly){t.typed=false;break}}a.typed||(t.typed=false),t.value[u]=a.value;}else if(s.fallback!==void 0)t.value[u]=Fe(s);else if(s.type!=="exact_optional"&&s.type!=="optional"&&s.type!=="nullish"&&(w(this,"key",t,n,{input:void 0,expected:`"${u}"`,path:[{type:"object",origin:"key",input:i,key:u,value:i[u]}]}),n.abortEarly))break}}else w(this,"type",t,n);return t}}}function W(r,e,t){return {kind:"schema",type:"record",reference:W,expects:"Object",async:false,key:r,value:e,message:t,get"~standard"(){return E(this)},"~run"(n,i){let u=n.value;if(u&&typeof u=="object"){n.typed=true,n.value={};for(let s in u)if(He(u,s)){let c=u[s],a=this.key["~run"]({value:s},i);if(a.issues){let l={type:"object",origin:"key",input:u,key:s,value:c};for(let f of a.issues)f.path=[l],n.issues?.push(f);if(n.issues||(n.issues=a.issues),i.abortEarly){n.typed=false;break}}let p=this.value["~run"]({value:c},i);if(p.issues){let l={type:"object",origin:"value",input:u,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),i.abortEarly){n.typed=false;break}}(!a.typed||!p.typed)&&(n.typed=false),a.typed&&(n.value[a.value]=p.value);}}else w(this,"type",n,i);return n}}}function A(r){return {kind:"schema",type:"string",reference:A,expects:"string",async:false,message:r,get"~standard"(){return E(this)},"~run"(e,t){return typeof e.value=="string"?e.typed=true:w(this,"type",e,t),e}}}function ke(r,e,t){let n=r["~run"]({value:e},ge(t));return {typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}var we="chat:init",Ge="chat:initiated";var Ee=C({type:_(Ge),gaId:A()});C({type:_("GA_EVENT"),payload:W(A(),K())});var M=class{constructor(){o(this,"listeners",new Map);o(this,"unifiedMessageHandler",null);}on(e,t){let n=u=>{if(this.isValidOrigin(u))try{let s=u.data,c=typeof s=="string"?JSON.parse(s):s,{type:a}=c;a===e&&t(c);}catch(s){console.warn("Messenger: Failed to parse message data",s);}},i=this.listeners.get(e)||[];return i.push(n),this.listeners.set(e,i),this.unifiedMessageHandler||(this.unifiedMessageHandler=u=>{this.listeners.forEach(s=>s.forEach(c=>c(u)));},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 g=class extends Error{constructor(t,n,i){super(`Handshake failed: ${t}${n?` - ${n}`:""}`);this.reason=t;this.details=n;this.originalError=i;this.name="HandshakeError";}},D=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:i=10,retryInterval:u=500}=t;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 g("TIMEOUT","Handshake was cancelled"));};this.abortController?.signal.addEventListener("abort",f),this.messageListener=y=>{if(this.isValidOrigin(y))try{let b=y.data,$e=typeof b=="string"?JSON.parse(b):b,J=ke(Ee,$e);if(J.success){l(),this.abortController=null,s(J.output);return}}catch{}},window.addEventListener("message",this.messageListener),p=setTimeout(()=>{l(),this.abortController=null,c(new g("TIMEOUT",`No valid response received within ${n}ms`));},n);let d=()=>{if(!this.abortController?.signal.aborted)try{let y=this.getTargetWindow(),b=this.getTargetOrigin();if(!y)throw new g("NO_TARGET_WINDOW","Target iframe window is not available");y.postMessage(e,b),a++,a<i&&setTimeout(()=>{this.abortController?.signal.aborted||d();},u);}catch(y){l(),this.abortController=null,y instanceof g?c(y):c(new g("MESSAGE_SEND_FAILED","Failed to send handshake message",y));}};d();})}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 k,Ie,Te,O=class O extends M{constructor({hostOrigin:t,apiKey:n}){super();v(this,k);o(this,"hostOrigin");o(this,"apiKey");o(this,"iframe");o(this,"postToTap",t=>this.iframe?super.postMessage(t):(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"),false));o(this,"listenToTap",super.on);this.hostOrigin=t,this.apiKey=n;}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,k,Ie).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=O.defaultHandshakeOptions){if(!this.iframe)throw new Error("TapIframeBridge: iframe not available for handshake");console.log("[TapIframeBridge] Starting handshake with iframe:",this.iframe.src),console.log("[TapIframeBridge] Target origin:",this.getTargetOrigin()),console.log("[TapIframeBridge] Message target available:",!!this.getMessageTarget());let i=new D(()=>this.getMessageTarget(),()=>this.getTargetOrigin(),s=>this.isValidOrigin(s)),u={type:we,hostOrigin:this.hostOrigin,apiKey:this.apiKey,chatApiParams:t.chatApiParams,apiUrl:t?.apiUrl??(m(this,k,Te).call(this)||"")};console.log("[TapIframeBridge] Sending handshake message:",{type:u.type,hostOrigin:u.hostOrigin,apiKey:u.apiKey?"***":"missing",chatApiParams:u.chatApiParams,apiUrl:u.apiUrl});try{let s=await i.execute(u,n);return console.log("[TapIframeBridge] Handshake successful:",s),s}catch(s){throw console.error("[TapIframeBridge] Handshake failed:",s),s instanceof Error?new Error(`TapIframeBridge handshake failed: ${s.message}`):s}}};k=new WeakSet,Ie=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);console.log("[TapIframeBridge] Stored tap-url-storage:",n);let i=n?.state?.tapUrl;if(i)return console.log("[TapIframeBridge] Using custom TAP URL:",i),`${i}/chat`}}catch{}return "https://edutap-ai.vercel.app/chat"},Te=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(O,"defaultHandshakeOptions",{retryInterval:500,maxRetries:3,timeout:3e4});var $=O;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 x=class{constructor(){}handle(e){typeof window.gtag=="function"&&window.gtag("event",e.action,{event_category:e.category,event_label:e.label,value:e.value,...e.customParams});}},B=class{constructor(e=false){this.enabled=e;}handle(e){this.enabled&&console.log("[TapSDK Event]",e);}},P=class{constructor(){o(this,"middlewares",[]);}addMiddleware(e){this.middlewares.push(e);}removeMiddleware(e){let t=this.middlewares.indexOf(e);t>-1&&this.middlewares.splice(t,1);}log(e){this.middlewares.forEach(t=>{try{t.handle(e);}catch(n){console.warn("[EventLogger] Middleware error:",n);}});}logChatAction(e,t){this.log({action:`chat_${e}`,category:"engagement",customParams:{timestamp:Date.now(),...t}});}logButtonClick(e,t,n){let i={action:`${e}_button_clicked`,category:"user_interaction",customParams:{timestamp:Date.now(),...n}};t!==void 0&&(i.label=t),this.log(i);}logSDKInitialization(e,t,n){let i=Date.now()-t,u={action:"sdk_initialization",category:"system",label:e?"success":"failure",value:i,customParams:{timestamp:Date.now(),...n&&{error:n}}};this.log(u);}};var _e="wu2gm66",Ce="wu2gm67",Ae="wu2gm68";function Ke({htmlString:r,callback:e,customStyles:t}){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 i=document.createElement("div");i.id="wow",i.style.position="fixed",i.style.display="flex",i.style.flexDirection="column";let s=15;if(t?.width){let d=parseFloat(t.width),y=t.width.match(/[a-zA-Z%]+/)?.[0];!isNaN(d)&&y==="px"&&(s+=d);}else s+=340;if(t?.position?.right){let d=parseFloat(t?.position?.right),y=t?.position?.right.match(/[a-zA-Z%]+/)?.[0];!isNaN(d)&&y==="px"&&(s+=d);}else s=s+24;i.style.top=t?.position?.top??"50px",i.style.right=`${s}px`,i.style.left=t?.position?.left??"unset",i.style.bottom=t?.position?.bottom??"unset",i.style.maxWidth="calc(100vw - 100px)",i.style.maxHeight=t?.height??"calc(100vh - 116px)",i.style.overflow="auto",i.style.background="#fff",i.style.padding="20px",i.style.border="1px solid #ccc",i.style.boxShadow="0 4px 20px rgba(0,0,0,0.2)",i.style.zIndex="10000003",i.style.borderRadius="8px";let c=document.createElement("div");c.innerHTML=r,n.addEventListener("click",()=>{document.body.removeChild(n),document.body.removeChild(i),e();}),i.addEventListener("click",d=>{d.stopPropagation();}),i.appendChild(c),document.body.appendChild(n),document.body.appendChild(i);let a=document.querySelector(`.${_e}`),p=document.querySelector(".cw-plugin-code-block"),l=document.querySelector(`.${Ae}`),f=document.querySelector(`.${Ce}`);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 Me=Ke;var S,De,X=class{constructor({apiKey:e}){v(this,S);o(this,"apiKey");o(this,"iframeBridge");o(this,"events");o(this,"eventLogger");o(this,"chatBody");o(this,"chatBodyMaker");o(this,"button");o(this,"alarm");o(this,"chatBodyVisible");o(this,"isPdfOpen");o(this,"_isInitialized",false);this.apiKey=e,this.iframeBridge=new $({hostOrigin:window.location.origin,apiKey:this.apiKey}),this.events=new j(this.iframeBridge),this.eventLogger=new P,m(this,S,De).call(this),this.button=new ne,this.alarm=new ve,this.chatBodyMaker=new te,this.chatBodyVisible="closed",this.isPdfOpen=false;}get isOpen(){return this.chatBodyVisible==="open"}get isInitialized(){return this._isInitialized}async init({buttonId:e,course:t,customStyles:n}){if(this._isInitialized){console.warn("[TapSDK] Already initialized, skipping initialization");return}let i=Date.now();try{await this.validateEnvironment(),await this.setupChatBody(n),await Promise.all([this.setupButton(e),this.iframeBridge.ensureIframe(this.chatBody)]),this.setupEventListeners(n),await this.iframeBridge.performHandshake({chatApiParams:t,customStyles:n}),this._isInitialized=!0,this.eventLogger.logSDKInitialization(!0,i);}catch(u){let s=u instanceof Error?u.message:"Unknown error";throw this.eventLogger.logSDKInitialization(false,i,s),u}}destroy(){if(!this._isInitialized){console.warn("[TapSDK] SDK not initialized, nothing to destroy");return}this.chatBodyMaker.removeChatBody(),this.alarm.remove(),this.iframeBridge.removeIframe(),this.chatBody=void 0,this.chatBodyVisible="closed",this._isInitialized=false;}isClient(){return typeof window<"u"&&typeof document<"u"}setChatBodyVisible(e){this.chatBodyVisible=e;}setIsPdfOpen(e){this.isPdfOpen=e;}toggleChatOpen(){let e=this.chatBodyVisible==="open"?"chat:close":"chat:open";try{this.iframeBridge.postToTap({type:e})||console.error(`[TapSDK] Failed to send ${e} message`);}catch(t){console.error("[TapSDK] Error sending chat message:",t);}}async validateEnvironment(){if(!this.isClient())throw new Error("Not running in client environment: window is not defined")}async setupChatBody(e){if(!this.chatBody){let t=this.chatBodyMaker.createChatBody({...e?.chatBody&&{customChatBody:e.chatBody}});if(!t)throw new Error("Failed to create chat body");this.chatBody=t;}}async setupButton(e){let t=this.button.create(e);this.button.onClick(async()=>{await this.iframeBridge.ensureIframe(this.chatBody),this.eventLogger.logButtonClick("toggle",this.chatBodyVisible==="open"?"open":"closed"),this.toggleChatOpen();}),this.alarm.render({rootElement:t}),this.alarm.onAlarmClick(n=>{this.eventLogger.logButtonClick("alarm"),this.iframeBridge.postToTap({type:"chat:open",isAlarm:true}),this.iframeBridge.postToTap({type:"alarm:click",messageInfo:n});});}setupEventListeners(e){this.iframeBridge.listenToTap("chat:opened",()=>{this.setChatBodyVisible("open"),this.chatBodyMaker.toggleVisibility(this.chatBodyVisible==="open"),this.alarm.remove(),this.eventLogger.logChatAction("opened");}),this.iframeBridge.listenToTap("chat:closed",()=>{this.setChatBodyVisible("closed"),this.chatBodyMaker.toggleVisibility(this.chatBodyVisible==="open"),this.eventLogger.logChatAction("closed");}),this.iframeBridge.listenToTap("alarm:fadeIn",t=>{this.chatBodyVisible!=="open"&&this.alarm.fadeIn(t.messageInfo);}),this.iframeBridge.listenToTap("popUp:open",t=>{Me({htmlString:t.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.listenToTap("pdf:close",()=>{this.setIsPdfOpen(false),this.chatBodyMaker.resizeChatBody(this.isPdfOpen,e?.chatBody);});}async initChat(e){return this.init(e)}postChatInfo({clipId:e,clipPlayHead:t}){this.events.seekTimeline({clipId:e,clipPlayHead:t});}getTimelineInfo({callback:e}){this.events.onTimelineSeek(e);}};S=new WeakSet,De=function(){if(typeof window>"u"||typeof localStorage>"u"){this.eventLogger.addMiddleware(new x);return}try{localStorage.getItem("tap-environment")==="local"?this.eventLogger.addMiddleware(new B(!0)):this.eventLogger.addMiddleware(new x);}catch{this.eventLogger.addMiddleware(new x);}};var Wt=X;
|
|
19
|
+
module.exports=Wt;//# sourceMappingURL=index.js.map
|
|
20
20
|
//# sourceMappingURL=index.js.map
|