@coxwave/tap-sdk 0.0.1

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.
@@ -0,0 +1,189 @@
1
+ import { ChatInitMessage, ChatOpenMessage, ChatCloseMessage, TimelineSeekMessage, AlarmClickMessage, PopUpCloseMessage, PdfEnlargedMessage, PdfShrinkedMessage, ChatInitiatedMessage, ChatOpenedMessage, ChatClosedMessage, AlarmFadeInMessage, PopUpOpenMessage, PdfOpenMessage, PdfCloseMessage, AlarmMessageInstanceType } from '@coxwave/tap-messages';
2
+
3
+ type Unsubscribe = () => void;
4
+ type Message = {
5
+ type: string;
6
+ [key: string]: any;
7
+ };
8
+ declare abstract class Messenger<TToTargetMessages extends Message = Message, TFromTargetMessage extends Message = Message> {
9
+ protected listeners: Map<TFromTargetMessage["type"], ((event: MessageEvent) => void)[]>;
10
+ protected unifiedMessageHandler: ((event: MessageEvent) => void) | null;
11
+ protected on<T extends TFromTargetMessage["type"]>(messageType: T, callback: (data: Extract<TFromTargetMessage, {
12
+ type: T;
13
+ }>) => void): Unsubscribe;
14
+ removeListener(messageType: TFromTargetMessage["type"]): void;
15
+ removeAllListeners(): void;
16
+ postMessage(message: TToTargetMessages): boolean;
17
+ protected abstract isValidOrigin(event: MessageEvent): boolean;
18
+ protected abstract getMessageTarget(): Window | null;
19
+ protected abstract getTargetOrigin(): string;
20
+ }
21
+
22
+ interface HandshakeOptions {
23
+ timeout?: number;
24
+ maxRetries?: number;
25
+ retryInterval?: number;
26
+ }
27
+
28
+ type ToTapMessage = ChatInitMessage | ChatOpenMessage | ChatCloseMessage | TimelineSeekMessage | AlarmClickMessage | PopUpCloseMessage | PdfEnlargedMessage | PdfShrinkedMessage;
29
+ type FromTapMessage = ChatInitiatedMessage | ChatOpenedMessage | ChatClosedMessage | AlarmFadeInMessage | PopUpOpenMessage | PdfOpenMessage | PdfCloseMessage | TimelineSeekMessage;
30
+ interface ChatInitConfig {
31
+ chatApiParams: any;
32
+ customStyles?: any;
33
+ gaId?: string;
34
+ }
35
+ declare class TapIframeBridge extends Messenger<ToTapMessage, FromTapMessage> {
36
+ protected hostClientUrl: string;
37
+ protected pluginKey: string;
38
+ protected iframe: HTMLIFrameElement | null;
39
+ constructor({ hostClientUrl, pluginKey, }: {
40
+ hostClientUrl: string;
41
+ pluginKey: string;
42
+ });
43
+ protected isValidOrigin(event: MessageEvent): boolean;
44
+ protected getMessageTarget(): Window | null;
45
+ protected getTargetOrigin(): string;
46
+ renderIframe({ chatBody, isProd, isLocal, }: {
47
+ chatBody: HTMLElement;
48
+ isProd: boolean;
49
+ isLocal?: boolean;
50
+ }): Promise<HTMLIFrameElement>;
51
+ hasIframe(): boolean;
52
+ removeIframe(): void;
53
+ get postToTap(): (message: ToTapMessage) => boolean;
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
+ type: T;
56
+ }> | Extract<ChatInitiatedMessage, {
57
+ type: T;
58
+ }> | Extract<ChatOpenedMessage, {
59
+ type: T;
60
+ }> | Extract<ChatClosedMessage, {
61
+ type: T;
62
+ }> | Extract<AlarmFadeInMessage, {
63
+ type: T;
64
+ }> | Extract<PopUpOpenMessage, {
65
+ type: T;
66
+ }> | Extract<PdfOpenMessage, {
67
+ type: T;
68
+ }> | Extract<PdfCloseMessage, {
69
+ type: T;
70
+ }>) => void) => () => void;
71
+ performHandshake(config: ChatInitConfig, options?: HandshakeOptions): Promise<ChatInitiatedMessage>;
72
+ }
73
+
74
+ type TapSDKType = {
75
+ pluginKey: string;
76
+ isProd?: boolean;
77
+ isLocal?: boolean;
78
+ };
79
+ type ChatApiParamsType = {
80
+ userId: string;
81
+ courseId: string | null;
82
+ courseName: string;
83
+ courseCategory: string;
84
+ courseSubCategory: string;
85
+ clipId: string | null;
86
+ clipPlayHead: number | null;
87
+ };
88
+ type CustomStylesType = {
89
+ floatingButton?: FloatingButtonType;
90
+ chatBody?: ChatBodyType;
91
+ theme?: ThemeType;
92
+ };
93
+ type ShortcutKeyType = {
94
+ openChat: ShortcutKeyPropertiesType;
95
+ sendChat: ShortcutKeyPropertiesType;
96
+ };
97
+ type FloatingButtonType = {
98
+ isInElement?: boolean;
99
+ parentElementId?: string;
100
+ style?: Partial<CSSStyleDeclaration>;
101
+ };
102
+ type ChatBodyType = {
103
+ position?: PositionType;
104
+ width?: string;
105
+ height?: string;
106
+ borderRadius?: string;
107
+ };
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
+ type PositionType = {
119
+ top?: string;
120
+ left?: string;
121
+ right?: string;
122
+ bottom?: string;
123
+ };
124
+
125
+ type ShortcutKeyPropertiesType = {
126
+ key: string;
127
+ modifier: "ctrlKey" | "altKey" | "shiftKey" | "metaKey" | "";
128
+ };
129
+ type colorsType = {
130
+ color?: string;
131
+ backgroundColor?: string;
132
+ };
133
+ type SeekTimelineParamsType = {
134
+ clipId: string;
135
+ clipPlayHead: number;
136
+ };
137
+
138
+ declare class EventManager {
139
+ private iframeBridge;
140
+ constructor(iframeBridge: TapIframeBridge);
141
+ onTimelineSeek(handler: (clipPlayHead: number, clipId: string) => void): void;
142
+ onChatOpened(handler: () => void): void;
143
+ onChatClosed(handler: () => void): void;
144
+ onChatInitiated(handler: () => void): void;
145
+ onAlarmFadeIn(handler: (messageInfo: AlarmMessageInstanceType) => void): void;
146
+ onPopUpOpen(handler: (popUpInfo: PopUpOpenMessage["popUpInfo"]) => void): void;
147
+ onPdfOpen(handler: () => void): void;
148
+ onPdfClose(handler: () => void): void;
149
+ }
150
+
151
+ declare class TapSDK {
152
+ #private;
153
+ private pluginKey;
154
+ private iframeBridge;
155
+ events: EventManager;
156
+ private chatBody;
157
+ private chatBodyMaker;
158
+ private floatingButtonMaker;
159
+ private shortcutKey;
160
+ private isProd;
161
+ private isLocal;
162
+ private isOpen;
163
+ private isPdfOpen;
164
+ constructor({ pluginKey, isProd, isLocal }: TapSDKType);
165
+ private setIsOpen;
166
+ private setIsPdfOpen;
167
+ seekTimeline({ clipId, clipPlayHead }: SeekTimelineParamsType): void;
168
+ initChat({ chatApiParams, customStyles, shortcutKey, }: {
169
+ chatApiParams: ChatApiParamsType;
170
+ customStyles?: CustomStylesType;
171
+ shortcutKey?: ShortcutKeyType;
172
+ }): Promise<void>;
173
+ removeChat(): void;
174
+ /**
175
+ * @deprecated use `seekTimeline` method. gotta be expired at v1.0.0
176
+ */
177
+ postChatInfo({ clipId, clipPlayHead, }: {
178
+ clipId: string;
179
+ clipPlayHead: number;
180
+ }): void;
181
+ /**
182
+ * @deprecated use `events.onTimelineSeek` method. gotta be expired at v1.0.0
183
+ */
184
+ getTimelineInfo({ callback, }: {
185
+ callback: (clipPlayHead: number, clipId: string) => void;
186
+ }): void;
187
+ }
188
+
189
+ export { TapSDK as default };
@@ -0,0 +1,24 @@
1
+
2
+ // Auto-injected CSS
3
+ (function() {
4
+ if (typeof document !== 'undefined') {
5
+ const style = document.createElement('style');
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 _6j1ub50{0%{opacity:1;pointer-events:auto}50%{opacity:1}to{opacity:0}}._6j1ub51{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}._6j1ub52{pointer-events:auto;animation:_6j1ub50 18s forwards}._6j1ub53{opacity:0;pointer-events:none;animation:none}._6j1ub54{display:flex;justify-content:flex-end;border-radius:var(--Radius-radiusSM, 8px);width:max-content;gap:5px}._6j1ub55{display:flex;padding:8px 12px 6px;justify-content:flex-end;align-items:center;border-radius:var(--Radius-radiusSM, 8px);max-width:340px}._6j1ub56{background-color:#171b1f}._6j1ub57{background-color:#fa6b4b}._6j1ub58{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}._6j1ub59{display:flex;padding:0 23px;align-items:flex-start;gap:10px}._6j1ub5a{width:15px}._6j1ub5b{color:#171b1f}._6j1ub5c{color:#fa6b4b}._6j1ub5d{cursor:pointer;justify-content:center;align-items:center;width:20px;height:20px;border-radius:100px;z-index:999;transition:all .2s ease}._6j1ub5d:hover{width:63px;left:-72px}._6j1ub54:hover ._6j1ub5d{display:flex}._6j1ub5e,._6j1ub5f{display:none;background-color:#171b1f}._6j1ub5g{color:#fff}._6j1ub5d:hover ._6j1ub5g{display:none}._6j1ub5h{color:#fff;text-align:center;font-family:Pretendard;font-size:12px;font-style:normal;font-weight:400;line-height:20px;display:none}._6j1ub5d:hover ._6j1ub5h{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
+ if (!document.getElementById('tap-sdk-styles')) {
9
+ document.head.appendChild(style);
10
+ }
11
+ }
12
+ })();
13
+
14
+ var MySDK=(function(){'use strict';var je=Object.defineProperty;var J=i=>{throw TypeError(i)};var $e=(i,t,e)=>t in i?je(i,t,{enumerable:true,configurable:true,writable:true,value:e}):i[t]=e;var u=(i,t,e)=>$e(i,typeof t!="symbol"?t+"":t,e),Z=(i,t,e)=>t.has(i)||J("Cannot "+e);var Y=(i,t,e)=>(Z(i,t,"read from private field"),e?e.call(i):t.get(i)),g=(i,t,e)=>t.has(i)?J("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e);var d=(i,t,e)=>(Z(i,t,"access private method"),e);var Q="_1mlv4me2",w="_1mlv4me4";var O="_1mlv4me3";var D=class{constructor(){u(this,"chatBody",null);this.chatBody=null;}createChatBody({customChatBody:t}){return this.chatBody?this.chatBody:(this.chatBody=document.createElement("div"),this.chatBody.id="cw-chat-body",this.chatBody.className=Q,this.chatBody.style.setProperty("z-index","10000001","important"),this.chatBody.style.setProperty("position","fixed","important"),Object.assign(this.chatBody.style,{top:t?.position?.top??"50px",right:t?.position?.right??"24px",left:t?.position?.left??"unset",bottom:t?.position?.bottom??"unset",width:t?.width??"340px",height:t?.height??"calc(100% - 116px)",overflow:"hidden",backgroundColor:"transparent",borderRadius:t?.borderRadius??"16px",boxShadow:`
15
+ rgba(255, 255, 255, 0.12) 0px 0px 2px 0px inset,
16
+ rgba(0, 0, 0, 0.05) 0px 0px 2px 1px,
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(O,w),this.chatBody.style.display="block";let e=()=>{this.chatBody&&(this.chatBody.classList.contains(w)&&(this.chatBody.style.display="none"),this.chatBody.removeEventListener("animationend",e));};this.chatBody.addEventListener("animationend",e),requestAnimationFrame(()=>{this.chatBody?.classList.add(t?O:w);});}removeChatBody(){this.chatBody&&(this.chatBody.remove(),this.chatBody=null);}resizeChatBody(t,e){if(!this.chatBody)return;let n=e?.width??"340px",r=parseInt(n,10),o=r/3*10-r,s=t?`${r+o}px`:`${r}px`;this.chatBody.style.width=s;}},ee=D;var te="_6j1ub51",P={default:"_6j1ub5b _6j1ub5a","call-to-action":"_6j1ub5c _6j1ub5a"},ne="_6j1ub5a",re="_6j1ub59",L={default:"_6j1ub5e _6j1ub5d","call-to-action":"_6j1ub5f _6j1ub5d"},ie="_6j1ub5d",se="_6j1ub5h",ue="_6j1ub5g",S="_6j1ub53",oe="_6j1ub58",N={default:"_6j1ub56 _6j1ub55","call-to-action":"_6j1ub57 _6j1ub55"},ae="_6j1ub55",q="_6j1ub52",le="_6j1ub54";var h,ce,pe,fe,ye,he,R=class{constructor(){g(this,h);u(this,"container");u(this,"alarmTimeout");u(this,"alarmCornerSVG");u(this,"textContainer");u(this,"circleElement");u(this,"textInTextContainer");u(this,"messageInfo");}render({rootElement:t}){this.container=document.createElement("div"),this.container.id="alarm-container",this.container.className=te,this.container.addEventListener("click",n=>{n.stopPropagation();}),t.appendChild(this.container),d(this,h,ce).call(this,this.container);let e=d(this,h,pe).call(this,this.container);d(this,h,ye).call(this,e),d(this,h,fe).call(this,e);}fadeIn(t){t.type==="default"||t.type==="hourSpent"?(this.textContainer.className=N.default,this.alarmCornerSVG.setAttribute("class",P.default),this.circleElement.className=L.default):(this.textContainer.className=N["call-to-action"],this.alarmCornerSVG.setAttribute("class",P["call-to-action"]),this.circleElement.className=L["call-to-action"]),this.messageInfo=t,this.textInTextContainer.textContent=t.message,this.toggleVisibility(true),this.alarmTimeout=setTimeout(()=>{this.toggleVisibility(false);},18*1e3);}addClickEvent({callback:t}){this.container.addEventListener("click",()=>{this.toggleVisibility(false),t(this.messageInfo);});}toggleVisibility(t){this.container.classList.remove(q,S),requestAnimationFrame(()=>{this.container?.classList.add(t?q:S);});}remove(){this.container&&this.toggleVisibility(false),this.alarmTimeout&&clearTimeout(this.alarmTimeout);}};h=new WeakSet,ce=function(t){let e=document.createElement("div");e.className=re,t.appendChild(e);let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","11"),n.setAttribute("height","8"),n.setAttribute("viewBox","0 0 11 8"),n.setAttribute("fill","currentColor"),n.setAttribute("class",ne);let r=document.createElementNS("http://www.w3.org/2000/svg","path");r.setAttribute("d","M5.5 0L11.1292 8.25H-0.129165L5.5 0Z"),r.setAttribute("fill","currentColor"),n.appendChild(r),this.alarmCornerSVG=n,e.appendChild(n);},pe=function(t){let e=document.createElement("div");return e.className=le,t.appendChild(e),e},fe=function(t){this.textContainer=document.createElement("div"),this.textContainer.className=ae,t.appendChild(this.textContainer),this.textInTextContainer=document.createElement("span"),this.textInTextContainer.className=oe,this.textContainer.appendChild(this.textInTextContainer);},ye=function(t){let e=document.createElement("div");e.className=ie,t.appendChild(e),e.addEventListener("click",r=>{r.stopPropagation(),this.remove();});let n=document.createElement("span");n.className=se,e.appendChild(n),n.textContent="\uC54C\uB9BC \uB044\uAE30",d(this,h,he).call(this,e),this.circleElement=e;},he=function(t){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("width","10"),e.setAttribute("height","10"),e.setAttribute("viewBox","0 0 14 14"),e.setAttribute("fill","none"),e.setAttribute("class",ue);let n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d","M1 1L13 13M13 1L1 13"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","2"),n.setAttribute("stroke-linecap","round"),e.appendChild(n),t.appendChild(e);};var me=R;var _,z=class{constructor(){u(this,"customFloatingButton");u(this,"floatingButton");u(this,"alarm");g(this,_,(t,e)=>t.key===e?true:t.code.startsWith("Key")?t.code.slice(3).toLowerCase()===e:false);this.alarm=new me;}render({customFloatingButton:t}){if(this.customFloatingButton=t,this.customFloatingButton?.isInElement&&this.customFloatingButton?.parentElementId){let e=document.getElementById(this.customFloatingButton.parentElementId);e?.style.setProperty("position","relative","important"),e?.style.setProperty("z-index","10000001","important"),this.floatingButton=e;}else {let e=document.getElementById("cw-plugin");e||(e=document.createElement("button"),e.id="cw-plugin",e.style.zIndex="10000001",e.style.setProperty("z-index","10000001","important"),e.style.setProperty("position","fixed","important"),e.style.width="50px",e.style.height="50px",e.style.borderRadius="50%",e.style.backgroundColor="#000",document.body.appendChild(e),this.floatingButton=e);}return this.alarm.render({rootElement:this.floatingButton}),this.floatingButton}addClickEvent({callback:t}){if(!this.floatingButton)throw new Error("not initialized");this.floatingButton.addEventListener("click",()=>{t();});}addAlarmClickEvent({callback:t}){this.alarm.addClickEvent({callback:t});}addShortCutEvent({openChatShortcutKey:t,callback:e}){if(!this.floatingButton)throw new Error("not initialized");window.addEventListener("keydown",n=>{Y(this,_).call(this,n,t.key)&&(!t.modifier||n[t.modifier])&&e();});}alarmFadeIn(t){this.alarm.fadeIn(t);}alarmRemove(){this.alarm.remove();}};_=new WeakMap;var de=z;var F;function H(i){return {lang:i?.lang??F?.lang,message:i?.message,abortEarly:i?.abortEarly??F?.abortEarly,abortPipeEarly:i?.abortPipeEarly??F?.abortPipeEarly}}var De;function Pe(i){return De?.get(i)}var Le;function Se(i){return Le?.get(i)}var Ne;function qe(i,t){return Ne?.get(i)?.get(t)}function ve(i){let t=typeof i;return t==="string"?`"${i}"`:t==="number"||t==="bigint"||t==="boolean"?`${i}`:t==="object"||t==="function"?(i&&Object.getPrototypeOf(i)?.constructor?.name)??"null":t}function k(i,t,e,n,r){let o=r&&"input"in r?r.input:e.value,s=r?.expected??i.expects??null,c=r?.received??ve(o),a={kind:i.kind,type:i.type,input:o,expected:s,received:c,message:`Invalid ${t}: ${s?`Expected ${s} but r`:"R"}eceived ${c}`,requirement:i.requirement,path:r?.path,issues:r?.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},p=i.kind==="schema",l=r?.message??i.message??qe(i.reference,a.lang)??(p?Se(a.lang):null)??n.message??Pe(a.lang);l!==void 0&&(a.message=typeof l=="function"?l(a):l),p&&(e.typed=false),e.issues?e.issues.push(a):e.issues=[a];}function x(i){return {version:1,vendor:"valibot",validate(t){return i["~run"]({value:t},H())}}}function Re(i,t){return Object.hasOwn(i,t)&&t!=="__proto__"&&t!=="prototype"&&t!=="constructor"}var ze=class extends Error{constructor(i){super(i[0].message),this.name="ValiError",this.issues=i;}};function Fe(i,t,e){return typeof i.fallback=="function"?i.fallback(t,e):i.fallback}function He(i,t,e){return typeof i.default=="function"?i.default(t,e):i.default}function G(){return {kind:"schema",type:"any",reference:G,expects:"any",async:false,get"~standard"(){return x(this)},"~run"(i){return i.typed=true,i}}}function T(i,t){return {kind:"schema",type:"literal",reference:T,expects:ve(i),async:false,literal:i,message:t,get"~standard"(){return x(this)},"~run"(e,n){return e.value===this.literal?e.typed=true:k(this,"type",e,n),e}}}function I(i,t){return {kind:"schema",type:"object",reference:I,expects:"Object",async:false,entries:i,message:t,get"~standard"(){return x(this)},"~run"(e,n){let r=e.value;if(r&&typeof r=="object"){e.typed=true,e.value={};for(let o in this.entries){let s=this.entries[o];if(o in r||(s.type==="exact_optional"||s.type==="optional"||s.type==="nullish")&&s.default!==void 0){let c=o in r?r[o]:He(s),a=s["~run"]({value:c},n);if(a.issues){let p={type:"object",origin:"value",input:r,key:o,value:c};for(let l of a.issues)l.path?l.path.unshift(p):l.path=[p],e.issues?.push(l);if(e.issues||(e.issues=a.issues),n.abortEarly){e.typed=false;break}}a.typed||(e.typed=false),e.value[o]=a.value;}else if(s.fallback!==void 0)e.value[o]=Fe(s);else if(s.type!=="exact_optional"&&s.type!=="optional"&&s.type!=="nullish"&&(k(this,"key",e,n,{input:void 0,expected:`"${o}"`,path:[{type:"object",origin:"key",input:r,key:o,value:r[o]}]}),n.abortEarly))break}}else k(this,"type",e,n);return e}}}function V(i,t,e){return {kind:"schema",type:"record",reference:V,expects:"Object",async:false,key:i,value:t,message:e,get"~standard"(){return x(this)},"~run"(n,r){let o=n.value;if(o&&typeof o=="object"){n.typed=true,n.value={};for(let s in o)if(Re(o,s)){let c=o[s],a=this.key["~run"]({value:s},r);if(a.issues){let l={type:"object",origin:"key",input:o,key:s,value:c};for(let f of a.issues)f.path=[l],n.issues?.push(f);if(n.issues||(n.issues=a.issues),r.abortEarly){n.typed=false;break}}let p=this.value["~run"]({value:c},r);if(p.issues){let l={type:"object",origin:"value",input:o,key:s,value:c};for(let f of p.issues)f.path?f.path.unshift(l):f.path=[l],n.issues?.push(f);if(n.issues||(n.issues=p.issues),r.abortEarly){n.typed=false;break}}(!a.typed||!p.typed)&&(n.typed=false),a.typed&&(n.value[a.value]=p.value);}}else k(this,"type",n,r);return n}}}function C(i){return {kind:"schema",type:"string",reference:C,expects:"string",async:false,message:i,get"~standard"(){return x(this)},"~run"(t,e){return typeof t.value=="string"?t.typed=true:k(this,"type",t,e),t}}}function ge(i,t,e){let n=i["~run"]({value:t},H(e));if(n.issues)throw new ze(n.issues);return n.value}function be(i,t,e){let n=i["~run"]({value:t},H(e));return {typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}var ke="chat:init",Ge="chat:initiated";var xe=I({type:T(Ge),gaId:C()}),Ee=I({type:T("GA_EVENT"),payload:V(C(),G())});var A=class{constructor(){u(this,"listeners",new Map);u(this,"unifiedMessageHandler",null);}on(t,e){let n=o=>{if(this.isValidOrigin(o))try{let s=o.data,c=typeof s=="string"?JSON.parse(s):s,{type:a}=c;a===t&&e(c);}catch(s){console.warn("Messenger: Failed to parse message data",s);}},r=this.listeners.get(t)||[];return r.push(n),this.listeners.set(t,r),this.unifiedMessageHandler||(this.unifiedMessageHandler=o=>{this.listeners.forEach(s=>s.forEach(c=>c(o)));},window.addEventListener("message",this.unifiedMessageHandler)),()=>{this.unifiedMessageHandler&&(window.removeEventListener("message",this.unifiedMessageHandler),this.unifiedMessageHandler=null);}}removeListener(t){this.listeners.delete(t);}removeAllListeners(){this.listeners.clear(),this.unifiedMessageHandler&&(window.removeEventListener("message",this.unifiedMessageHandler),this.unifiedMessageHandler=null);}postMessage(t){try{let e=this.getMessageTarget();return e?(e.postMessage(t,this.getTargetOrigin()),!0):(console.warn("Messenger: Message target not available"),!1)}catch(e){return console.error("Messenger: postMessage failed",e),false}}};var v=class extends Error{constructor(e,n,r){super(`Handshake failed: ${e}${n?` - ${n}`:""}`);this.reason=e;this.details=n;this.originalError=r;this.name="HandshakeError";}},M=class{constructor(t,e,n){this.getTargetWindow=t;this.getTargetOrigin=e;this.isValidOrigin=n;u(this,"abortController",null);u(this,"messageListener",null);}async execute(t,e={}){let{timeout:n=1e4,maxRetries:r=10,retryInterval:o=500}=e;return this.cancel(),this.abortController=new AbortController,new Promise((s,c)=>{let a=0,p,l=()=>{p&&clearTimeout(p),this.messageListener&&(window.removeEventListener("message",this.messageListener),this.messageListener=null);},f=()=>{l(),c(new v("TIMEOUT","Handshake was cancelled"));};this.abortController?.signal.addEventListener("abort",f),this.messageListener=y=>{if(this.isValidOrigin(y))try{let b=y.data,Me=typeof b=="string"?JSON.parse(b):b;try{let K=be(xe,Me);l(),this.abortController=null,s(K.output);return}catch{}}catch(b){console.warn("Failed to parse handshake message:",b);}},window.addEventListener("message",this.messageListener),p=setTimeout(()=>{l(),this.abortController=null,c(new v("TIMEOUT",`No valid response received within ${n}ms`));},n);let m=()=>{if(!this.abortController?.signal.aborted)try{let y=this.getTargetWindow();if(!y)throw new v("NO_TARGET_WINDOW","Target iframe window is not available");y.postMessage(t,this.getTargetOrigin()),a++,a<r&&setTimeout(()=>{this.abortController?.signal.aborted||m();},o);}catch(y){l(),this.abortController=null,y instanceof v?c(y):c(new v("MESSAGE_SEND_FAILED","Failed to send handshake message",y));}};m();})}cancel(){this.abortController&&(this.abortController.abort(),this.abortController=null),this.messageListener&&(window.removeEventListener("message",this.messageListener),this.messageListener=null);}isActive(){return this.abortController!==null&&!this.abortController.signal.aborted}};var j=class extends A{constructor({hostClientUrl:e,pluginKey:n}){super();u(this,"hostClientUrl");u(this,"pluginKey");u(this,"iframe");u(this,"listenToTap",super.on);this.hostClientUrl=e,this.pluginKey=n;}isValidOrigin(e){if(!this.iframe)return false;let n=e.origin,r=new URL(this.iframe.src).origin;return !!(n===r||n.includes("vercel.app")&&r.includes("vercel.app")||n.includes("localhost")&&r.includes("localhost"))}getMessageTarget(){return this.iframe?.contentWindow||null}getTargetOrigin(){if(!this.iframe?.src)return "*";try{return new URL(this.iframe.src).origin}catch{return "*"}}renderIframe({chatBody:e,isProd:n,isLocal:r}){return new Promise(o=>{this.iframe=document.createElement("iframe"),this.iframe.style.setProperty("display","flex","important"),this.iframe.style.setProperty("border","none","important"),r?this.iframe.src=`${this.hostClientUrl}/chat`:this.iframe.src="https://ax-tap-fe-staging.vercel.app/chat",this.iframe.style.width="100%",this.iframe.style.height="100%",this.iframe.onload=()=>o(this.iframe),e.appendChild(this.iframe);})}hasIframe(){return !!this.iframe}removeIframe(){this.iframe?.remove(),this.iframe=null,this.removeAllListeners();}get postToTap(){return this.iframe||console.warn("TapIframeBridge: iframe not found"),super.postMessage}async performHandshake(e,n){if(!this.iframe)throw new Error("TapIframeBridge: iframe not available for handshake");let r=new M(()=>this.getMessageTarget(),()=>this.getTargetOrigin(),s=>this.isValidOrigin(s)),o={type:ke,hostClientUrl:this.hostClientUrl,pluginKey:this.pluginKey,chatApiParams:e.chatApiParams,theme:e.customStyles};try{return await r.execute(o,n)}catch(s){throw s instanceof Error?new Error(`TapIframeBridge handshake failed: ${s.message}`):s}}};var $=class{constructor(t){this.iframeBridge=t;}onTimelineSeek(t){this.iframeBridge.listenToTap("timeline:seek",e=>t(e.clipPlayHead,e.clipId));}onChatOpened(t){this.iframeBridge.listenToTap("chat:opened",t);}onChatClosed(t){this.iframeBridge.listenToTap("chat:closed",t);}onChatInitiated(t){this.iframeBridge.listenToTap("chat:initiated",t);}onAlarmFadeIn(t){this.iframeBridge.listenToTap("alarm:fadeIn",e=>{t(e.messageInfo);});}onPopUpOpen(t){this.iframeBridge.listenToTap("popUp:open",e=>{t(e.popUpInfo);});}onPdfOpen(t){this.iframeBridge.listenToTap("pdf:open",t);}onPdfClose(t){this.iframeBridge.listenToTap("pdf:close",t);}};var we="wu2gm66",_e="wu2gm67",Te="wu2gm68";function Ue({htmlString:i,callback:t,customStyles:e}){let n=document.createElement("div");n.style.position="fixed",n.style.top="0",n.style.left="0",n.style.width="100vw",n.style.height="100vh",n.style.background="rgba(0, 0, 0, 0.4)",n.style.zIndex="10000002";let r=document.createElement("div");r.style.position="fixed",r.style.display="flex",r.style.flexDirection="column";let s=15;if(e?.width){let m=parseFloat(e.width),y=e.width.match(/[a-zA-Z%]+/)?.[0];!isNaN(m)&&y==="px"&&(s+=m);}else s+=340;if(e?.position?.right){let m=parseFloat(e?.position?.right),y=e?.position?.right.match(/[a-zA-Z%]+/)?.[0];!isNaN(m)&&y==="px"&&(s+=m);}else s=s+24;r.style.top=e?.position?.top??"50px",r.style.right=`${s}px`,r.style.left=e?.position?.left??"unset",r.style.bottom=e?.position?.bottom??"unset",r.style.maxWidth="calc(100vw - 100px)",r.style.maxHeight=e?.height??"calc(100vh - 116px)",r.style.overflow="auto",r.style.background="#fff",r.style.padding="20px",r.style.border="1px solid #ccc",r.style.boxShadow="0 4px 20px rgba(0,0,0,0.2)",r.style.zIndex="10000003",r.style.borderRadius="8px";let c=document.createElement("div");c.innerHTML=i,n.addEventListener("click",()=>{document.body.removeChild(n),document.body.removeChild(r),t();}),r.addEventListener("click",m=>{m.stopPropagation();}),r.appendChild(c),document.body.appendChild(n),document.body.appendChild(r);let a=document.querySelector(`.${we}`),p=document.querySelector(".cw-plugin-code-block"),l=document.querySelector(`.${Te}`),f=document.querySelector(`.${_e}`);a&&p&&l&&f&&a.addEventListener("click",()=>{navigator.clipboard.writeText(p.textContent??""),l.style.display="none",f.textContent="\uBCF5\uC0AC\uB428",setTimeout(()=>{f.textContent="\uBCF5\uC0AC",l.style.display="inline";},1e3);});}var Ie=Ue;var E=class E{constructor({gaId:t}){E.isInitialized||(this.init(t),E.isInitialized=true);}init(t){if(!document.querySelector(`script[src="https://www.googletagmanager.com/gtag/js?id=${t}"]`)){let e=document.createElement("script");e.async=true,e.src=`https://www.googletagmanager.com/gtag/js?id=${t}`,document.head.appendChild(e);}if(typeof window.gtag!="function"){let e=document.createElement("script");e.innerHTML=`
19
+ 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 B,Ae,X=class{constructor({pluginKey:t,isProd:e=false,isLocal:n=false}){g(this,B);u(this,"pluginKey");u(this,"iframeBridge");u(this,"events");u(this,"chatBody",null);u(this,"chatBodyMaker");u(this,"floatingButtonMaker");u(this,"shortcutKey",{openChat:{key:"/",modifier:""},sendChat:{key:"Enter",modifier:""}});u(this,"isProd");u(this,"isLocal");u(this,"isOpen");u(this,"isPdfOpen");this.pluginKey=t,this.iframeBridge=new j({hostClientUrl:window.location.origin,pluginKey:this.pluginKey}),this.events=new $(this.iframeBridge),this.floatingButtonMaker=new de,this.chatBodyMaker=new ee,this.isProd=e,this.isLocal=n,this.isOpen=false,this.isPdfOpen=false;}setIsOpen(t){this.isOpen=t;}setIsPdfOpen(t){this.isPdfOpen=t;}seekTimeline({clipId:t,clipPlayHead:e}){this.iframeBridge.postToTap({type:"timeline:seek",clipId:t,clipPlayHead:e});}async initChat({chatApiParams:t,customStyles:e,shortcutKey:n}){if(!d(this,B,Ae).call(this))throw new Error("not client");this.shortcutKey={openChat:n?.openChat??this.shortcutKey.openChat,sendChat:n?.sendChat??this.shortcutKey.sendChat},this.chatBody||(this.chatBody=this.chatBodyMaker.createChatBody({...e?.chatBody&&{customChatBody:e.chatBody}})),this.iframeBridge.hasIframe()||await this.iframeBridge.renderIframe({chatBody:this.chatBody,isProd:this.isProd,isLocal:this.isLocal});try{let r=await this.iframeBridge.performHandshake({chatApiParams:t,customStyles:e},{retryInterval:500,maxRetries:10,timeout:1e4});new Ce({gaId:r.gaId});}catch(r){throw console.error("Handshake failed:",r),new Error(`Chat initialization failed: ${r instanceof Error?r.message:"Unknown error"}`)}this.floatingButtonMaker.render({...e?.floatingButton&&{customFloatingButton:e.floatingButton}}),this.floatingButtonMaker.addClickEvent({callback:()=>{this.iframeBridge.postToTap({type:this.isOpen?"chat:close":"chat:open"});}}),this.floatingButtonMaker.addAlarmClickEvent({callback:r=>{this.iframeBridge.postToTap({type:"chat:open",isAlarm:true}),this.iframeBridge.postToTap({type:"alarm:click",messageInfo:r});}}),this.iframeBridge.listenToTap("chat:opened",()=>{this.setIsOpen(true),this.chatBodyMaker.toggleVisibility(this.isOpen),this.floatingButtonMaker.alarmRemove();}),this.iframeBridge.listenToTap("chat:closed",()=>{this.setIsOpen(false),this.chatBodyMaker.toggleVisibility(this.isOpen);}),this.iframeBridge.listenToTap("alarm:fadeIn",r=>{this.isOpen||this.floatingButtonMaker.alarmFadeIn(r.messageInfo);}),this.iframeBridge.listenToTap("popUp:open",r=>{Ie({htmlString:r.popUpInfo.html,callback:()=>this.iframeBridge.postToTap({type:"popUp:close"}),...e?.chatBody&&{customStyles:e.chatBody}});}),this.iframeBridge.listenToTap("pdf:open",()=>{this.setIsPdfOpen(true),this.chatBodyMaker.resizeChatBody(this.isPdfOpen,e?.chatBody),this.iframeBridge.postToTap({type:"pdf:enlarged"});}),this.iframeBridge.listenToTap("pdf:close",()=>{this.setIsPdfOpen(false),this.chatBodyMaker.resizeChatBody(this.isPdfOpen,e?.chatBody),this.iframeBridge.postToTap({type:"pdf:shrinked"});}),this.isLocal&&this.iframeBridge.listenToTap("alarm:fadeIn",r=>{this.floatingButtonMaker.alarmFadeIn(r.messageInfo);});}removeChat(){if(!this.chatBody)throw new Error("chatBody is not initialized");this.chatBodyMaker.removeChatBody(),this.floatingButtonMaker.alarmRemove(),this.iframeBridge.removeIframe(),this.chatBody=null,this.isOpen=false;}postChatInfo({clipId:t,clipPlayHead:e}){this.seekTimeline({clipId:t,clipPlayHead:e});}getTimelineInfo({callback:t}){this.events.onTimelineSeek(t);}};B=new WeakSet,Ae=function(){return typeof window<"u"&&typeof document<"u"};var Xt=X;return Xt;})();//# sourceMappingURL=index.global.js.map
24
+ //# sourceMappingURL=index.global.js.map