@coxwave/tap-sdk 0.0.5 → 0.0.7

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 CHANGED
@@ -14,7 +14,7 @@ npm install @coxwave/tap-sdk
14
14
  import TapSDK from "@coxwave/tap-sdk";
15
15
 
16
16
  const sdk = new TapSDK({
17
- pluginKey: "your-plugin-key",
17
+ apiKey: "your-plugin-key",
18
18
  isProd: true,
19
19
  });
20
20
 
@@ -50,7 +50,7 @@ new TapSDK(options);
50
50
 
51
51
  **Options:**
52
52
 
53
- - `pluginKey` (string) - Your unique plugin identifier
53
+ - `apiKey` (string) - Your unique plugin identifier
54
54
  - `isProd` (boolean) - Production mode flag (default: false)
55
55
  - `isLocal` (boolean) - Local development flag (default: false)
56
56
 
@@ -132,7 +132,7 @@ function ChatWidget({ userId, courseId }) {
132
132
  useEffect(() => {
133
133
  const initSDK = async () => {
134
134
  sdkRef.current = new TapSDK({
135
- pluginKey: process.env.REACT_APP_TAP_PLUGIN_KEY,
135
+ apiKey: process.env.REACT_APP_TAP_PLUGIN_KEY,
136
136
  isProd: process.env.NODE_ENV === "production",
137
137
  });
138
138
 
package/dist/index.d.cts CHANGED
@@ -30,15 +30,15 @@ type FromTapMessage = ChatInitiatedMessage | ChatOpenedMessage | ChatClosedMessa
30
30
  interface ChatInitConfig {
31
31
  chatApiParams: any;
32
32
  customStyles?: any;
33
- gaId?: string;
33
+ apiUrl?: string | undefined;
34
34
  }
35
35
  declare class TapIframeBridge extends Messenger<ToTapMessage, FromTapMessage> {
36
36
  protected hostClientUrl: string;
37
- protected pluginKey: string;
37
+ protected apiKey: string;
38
38
  protected iframe: HTMLIFrameElement | null;
39
- constructor({ hostClientUrl, pluginKey, }: {
39
+ constructor({ hostClientUrl, apiKey, }: {
40
40
  hostClientUrl: string;
41
- pluginKey: string;
41
+ apiKey: string;
42
42
  });
43
43
  protected isValidOrigin(_event: MessageEvent): boolean;
44
44
  protected getMessageTarget(): Window | null;
@@ -50,7 +50,7 @@ declare class TapIframeBridge extends Messenger<ToTapMessage, FromTapMessage> {
50
50
  }): Promise<HTMLIFrameElement>;
51
51
  hasIframe(): boolean;
52
52
  removeIframe(): void;
53
- get postToTap(): (() => void) | ((message: ToTapMessage) => boolean);
53
+ postToTap: (message: ToTapMessage) => boolean;
54
54
  listenToTap: <T extends "timeline:seek" | "chat:opened" | "chat:initiated" | "chat:closed" | "alarm:fadeIn" | "popUp:open" | "pdf:open" | "pdf:close">(messageType: T, callback: (data: Extract<TimelineSeekMessage, {
55
55
  type: T;
56
56
  }> | Extract<ChatInitiatedMessage, {
@@ -71,50 +71,31 @@ declare class TapIframeBridge extends Messenger<ToTapMessage, FromTapMessage> {
71
71
  performHandshake(config: ChatInitConfig, options?: HandshakeOptions): Promise<ChatInitiatedMessage>;
72
72
  }
73
73
 
74
- type TapSDKType = {
75
- pluginKey: string;
74
+ type TapSDKConfig = {
75
+ apiKey: string;
76
76
  isProd?: boolean;
77
77
  isLocal?: boolean;
78
78
  };
79
- type ChatApiParamsType = {
79
+ type Course = {
80
80
  userId: string;
81
81
  courseId: string | null;
82
- courseName: string;
83
- courseCategory: string;
84
- courseSubCategory: string;
85
82
  clipId: string | null;
86
- clipPlayHead: number | null;
87
83
  };
88
- type CustomStylesType = {
84
+ type CustomStyles = {
89
85
  floatingButton?: FloatingButtonType;
90
- chatBody?: ChatBodyType;
91
- theme?: ThemeType;
92
- };
93
- type ShortcutKeyType = {
94
- openChat: ShortcutKeyPropertiesType;
95
- sendChat: ShortcutKeyPropertiesType;
86
+ chatBody?: ChatBodyStyle;
96
87
  };
97
88
  type FloatingButtonType = {
98
89
  isInElement?: boolean;
99
90
  parentElementId?: string;
100
91
  style?: Partial<CSSStyleDeclaration>;
101
92
  };
102
- type ChatBodyType = {
93
+ type ChatBodyStyle = {
103
94
  position?: PositionType;
104
95
  width?: string;
105
96
  height?: string;
106
97
  borderRadius?: string;
107
98
  };
108
- type ThemeType = {
109
- iconColor?: string;
110
- chatBody?: colorsType;
111
- highlightBar?: colorsType;
112
- components?: colorsType;
113
- AIRecommendGradient?: {
114
- base: string;
115
- move: string;
116
- };
117
- };
118
99
  type PositionType = {
119
100
  top?: string;
120
101
  left?: string;
@@ -122,14 +103,6 @@ type PositionType = {
122
103
  bottom?: string;
123
104
  };
124
105
 
125
- type ShortcutKeyPropertiesType = {
126
- key: string;
127
- modifier: "ctrlKey" | "altKey" | "shiftKey" | "metaKey" | "";
128
- };
129
- type colorsType = {
130
- color?: string;
131
- backgroundColor?: string;
132
- };
133
106
  type SeekTimelineParamsType = {
134
107
  clipId: string;
135
108
  clipPlayHead: number;
@@ -150,25 +123,24 @@ declare class EventManager {
150
123
 
151
124
  declare class TapSDK {
152
125
  #private;
153
- private pluginKey;
126
+ private apiKey;
154
127
  private iframeBridge;
155
128
  events: EventManager;
156
129
  private chatBody;
157
130
  private chatBodyMaker;
158
131
  private floatingButtonMaker;
159
- private shortcutKey;
160
132
  private isProd;
161
133
  private isLocal;
162
134
  private isOpen;
163
135
  private isPdfOpen;
164
- constructor({ pluginKey, isProd, isLocal }: TapSDKType);
136
+ constructor({ apiKey, isProd, isLocal }: TapSDKConfig);
165
137
  private setIsOpen;
166
138
  private setIsPdfOpen;
139
+ private sendChatMessage;
167
140
  seekTimeline({ clipId, clipPlayHead }: SeekTimelineParamsType): void;
168
- initChat({ chatApiParams, customStyles, shortcutKey, }: {
169
- chatApiParams: ChatApiParamsType;
170
- customStyles?: CustomStylesType;
171
- shortcutKey?: ShortcutKeyType;
141
+ initChat({ course, customStyles, }: {
142
+ course: Course;
143
+ customStyles?: CustomStyles;
172
144
  }): Promise<void>;
173
145
  removeChat(): void;
174
146
  /**
package/dist/index.d.ts CHANGED
@@ -30,15 +30,15 @@ type FromTapMessage = ChatInitiatedMessage | ChatOpenedMessage | ChatClosedMessa
30
30
  interface ChatInitConfig {
31
31
  chatApiParams: any;
32
32
  customStyles?: any;
33
- gaId?: string;
33
+ apiUrl?: string | undefined;
34
34
  }
35
35
  declare class TapIframeBridge extends Messenger<ToTapMessage, FromTapMessage> {
36
36
  protected hostClientUrl: string;
37
- protected pluginKey: string;
37
+ protected apiKey: string;
38
38
  protected iframe: HTMLIFrameElement | null;
39
- constructor({ hostClientUrl, pluginKey, }: {
39
+ constructor({ hostClientUrl, apiKey, }: {
40
40
  hostClientUrl: string;
41
- pluginKey: string;
41
+ apiKey: string;
42
42
  });
43
43
  protected isValidOrigin(_event: MessageEvent): boolean;
44
44
  protected getMessageTarget(): Window | null;
@@ -50,7 +50,7 @@ declare class TapIframeBridge extends Messenger<ToTapMessage, FromTapMessage> {
50
50
  }): Promise<HTMLIFrameElement>;
51
51
  hasIframe(): boolean;
52
52
  removeIframe(): void;
53
- get postToTap(): (() => void) | ((message: ToTapMessage) => boolean);
53
+ postToTap: (message: ToTapMessage) => boolean;
54
54
  listenToTap: <T extends "timeline:seek" | "chat:opened" | "chat:initiated" | "chat:closed" | "alarm:fadeIn" | "popUp:open" | "pdf:open" | "pdf:close">(messageType: T, callback: (data: Extract<TimelineSeekMessage, {
55
55
  type: T;
56
56
  }> | Extract<ChatInitiatedMessage, {
@@ -71,50 +71,31 @@ declare class TapIframeBridge extends Messenger<ToTapMessage, FromTapMessage> {
71
71
  performHandshake(config: ChatInitConfig, options?: HandshakeOptions): Promise<ChatInitiatedMessage>;
72
72
  }
73
73
 
74
- type TapSDKType = {
75
- pluginKey: string;
74
+ type TapSDKConfig = {
75
+ apiKey: string;
76
76
  isProd?: boolean;
77
77
  isLocal?: boolean;
78
78
  };
79
- type ChatApiParamsType = {
79
+ type Course = {
80
80
  userId: string;
81
81
  courseId: string | null;
82
- courseName: string;
83
- courseCategory: string;
84
- courseSubCategory: string;
85
82
  clipId: string | null;
86
- clipPlayHead: number | null;
87
83
  };
88
- type CustomStylesType = {
84
+ type CustomStyles = {
89
85
  floatingButton?: FloatingButtonType;
90
- chatBody?: ChatBodyType;
91
- theme?: ThemeType;
92
- };
93
- type ShortcutKeyType = {
94
- openChat: ShortcutKeyPropertiesType;
95
- sendChat: ShortcutKeyPropertiesType;
86
+ chatBody?: ChatBodyStyle;
96
87
  };
97
88
  type FloatingButtonType = {
98
89
  isInElement?: boolean;
99
90
  parentElementId?: string;
100
91
  style?: Partial<CSSStyleDeclaration>;
101
92
  };
102
- type ChatBodyType = {
93
+ type ChatBodyStyle = {
103
94
  position?: PositionType;
104
95
  width?: string;
105
96
  height?: string;
106
97
  borderRadius?: string;
107
98
  };
108
- type ThemeType = {
109
- iconColor?: string;
110
- chatBody?: colorsType;
111
- highlightBar?: colorsType;
112
- components?: colorsType;
113
- AIRecommendGradient?: {
114
- base: string;
115
- move: string;
116
- };
117
- };
118
99
  type PositionType = {
119
100
  top?: string;
120
101
  left?: string;
@@ -122,14 +103,6 @@ type PositionType = {
122
103
  bottom?: string;
123
104
  };
124
105
 
125
- type ShortcutKeyPropertiesType = {
126
- key: string;
127
- modifier: "ctrlKey" | "altKey" | "shiftKey" | "metaKey" | "";
128
- };
129
- type colorsType = {
130
- color?: string;
131
- backgroundColor?: string;
132
- };
133
106
  type SeekTimelineParamsType = {
134
107
  clipId: string;
135
108
  clipPlayHead: number;
@@ -150,25 +123,24 @@ declare class EventManager {
150
123
 
151
124
  declare class TapSDK {
152
125
  #private;
153
- private pluginKey;
126
+ private apiKey;
154
127
  private iframeBridge;
155
128
  events: EventManager;
156
129
  private chatBody;
157
130
  private chatBodyMaker;
158
131
  private floatingButtonMaker;
159
- private shortcutKey;
160
132
  private isProd;
161
133
  private isLocal;
162
134
  private isOpen;
163
135
  private isPdfOpen;
164
- constructor({ pluginKey, isProd, isLocal }: TapSDKType);
136
+ constructor({ apiKey, isProd, isLocal }: TapSDKConfig);
165
137
  private setIsOpen;
166
138
  private setIsPdfOpen;
139
+ private sendChatMessage;
167
140
  seekTimeline({ clipId, clipPlayHead }: SeekTimelineParamsType): void;
168
- initChat({ chatApiParams, customStyles, shortcutKey, }: {
169
- chatApiParams: ChatApiParamsType;
170
- customStyles?: CustomStylesType;
171
- shortcutKey?: ShortcutKeyType;
141
+ initChat({ course, customStyles, }: {
142
+ course: Course;
143
+ customStyles?: CustomStyles;
172
144
  }): Promise<void>;
173
145
  removeChat(): void;
174
146
  /**
@@ -11,14 +11,10 @@
11
11
  }
12
12
  })();
13
13
 
14
- var MySDK=(function(){'use strict';var je=Object.defineProperty;var J=i=>{throw TypeError(i)};var Be=(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)=>Be(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 D="_1mlv4me3";var O=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:`
14
+ var MySDK=(function(){'use strict';var Ie=Object.defineProperty;var W=r=>{throw TypeError(r)};var Ce=(r,t,e)=>t in r?Ie(r,t,{enumerable:true,configurable:true,writable:true,value:e}):r[t]=e;var u=(r,t,e)=>Ce(r,typeof t!="symbol"?t+"":t,e),X=(r,t,e)=>t.has(r)||W("Cannot "+e);var K=(r,t,e)=>(X(r,t,"read from private field"),e?e.call(r):t.get(r)),k=(r,t,e)=>t.has(r)?W("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e);var d=(r,t,e)=>(X(r,t,"access private method"),e);var J="_1mlv4me2",w="_1mlv4me4";var $="_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=J,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(D,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?D: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=O;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,z=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=z;var _,R=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=R;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 Oe;function Pe(i){return Oe?.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 ze(i,t){return Object.hasOwn(i,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}var Re=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(ze(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 Re(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){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: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?super.postMessage:(console.warn("TapIframeBridge: iframe not found - ensure createIframeChat() was called first"),()=>{console.warn("TapIframeBridge: Cannot post message - no iframe available");})}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 B=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.id="wow",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
- window.dataLayer = window.dataLayer || [];
20
- function gtag(){dataLayer.push(arguments);}
21
- gtag('js', new Date());
22
- gtag('config', '${t}');
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 $,Ae,X=class{constructor({pluginKey:t,isProd:e=false,isLocal:n=false}){g(this,$);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 B(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,$,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);}};$=new WeakSet,Ae=function(){return typeof window<"u"&&typeof document<"u"};var Xt=X;return Xt;})();//# sourceMappingURL=index.global.js.map
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
+ return qt;})();//# sourceMappingURL=index.global.js.map
24
20
  //# sourceMappingURL=index.global.js.map