@coxwave/tap-kit-types 0.0.34 → 0.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,26 +2,66 @@ import { AlarmMessageInstanceType } from '@coxwave/tap-messages';
2
2
  export { AlarmMessageInstanceType, AlarmType } from '@coxwave/tap-messages';
3
3
 
4
4
  /**
5
- * @coxwave/tap-kit-types
6
- * Shared TypeScript types for TapKit SDK packages
7
- *
8
- * This package serves as the single source of truth for all TapKit types,
9
- * used by both @coxwave/tap-sdk (npm wrapper) and @coxwave/tap-kit-core (CDN implementation).
5
+ * Styling Types
6
+ */
7
+ type PositionType = {
8
+ top?: string;
9
+ left?: string;
10
+ right?: string;
11
+ bottom?: string;
12
+ };
13
+ /**
14
+ * Container Styling
10
15
  */
16
+ type ContainerStyle = {
17
+ position?: PositionType;
18
+ width?: string;
19
+ height?: string;
20
+ borderRadius?: string;
21
+ };
22
+ /**
23
+ * Flattened container styles (backward compatibility)
24
+ */
25
+ type CustomStyles = ContainerStyle;
11
26
 
12
27
  /**
13
- * SDK Configuration
28
+ * Core Configuration Types
29
+ */
30
+ /**
31
+ * SDK Configuration (Public API)
32
+ * Constructor only accepts apiKey for simplicity
33
+ *
34
+ * Default values:
35
+ * - tapUrl: https://edutap-ai.vercel.app
36
+ * - apiUrl: https://tapapi.coxwave.link
37
+ * - environment: local (console logging enabled)
14
38
  */
15
39
  type TapKitConfig = {
16
40
  apiKey: string;
17
41
  };
18
42
  /**
19
- * SDK Initialization Parameters
43
+ * Runtime Configuration Options (Internal API)
44
+ * Used by Symbol-based config() method for advanced configuration
45
+ *
46
+ * @internal This is not part of the public API
20
47
  */
21
- type TapKitInitParams = {
22
- buttonId: string;
23
- course: Course;
24
- container?: ContainerStyle;
48
+ type TapKitConfigOptions = {
49
+ /**
50
+ * Custom TAP iframe URL
51
+ * Default: https://edutap-ai.vercel.app
52
+ */
53
+ tapUrl?: string;
54
+ /**
55
+ * Custom API URL
56
+ * Default: https://tapapi.coxwave.link
57
+ */
58
+ apiUrl?: string;
59
+ /**
60
+ * Environment mode
61
+ * - 'dev': Console logging enabled (default)
62
+ * - 'prod': Google Analytics logging
63
+ */
64
+ environment?: 'dev' | 'prod';
25
65
  };
26
66
  /**
27
67
  * Course Information
@@ -33,24 +73,17 @@ type Course = {
33
73
  clipPlayHead?: number;
34
74
  };
35
75
  /**
36
- * Container Styling
76
+ * SDK Initialization Parameters
37
77
  */
38
- type ContainerStyle = {
39
- position?: PositionType;
40
- width?: string;
41
- height?: string;
42
- borderRadius?: string;
43
- };
44
- type PositionType = {
45
- top?: string;
46
- left?: string;
47
- right?: string;
48
- bottom?: string;
78
+ type TapKitInitParams = {
79
+ buttonId: string;
80
+ course: Course;
81
+ container?: ContainerStyle;
49
82
  };
83
+
50
84
  /**
51
- * Flattened container styles (backward compatibility)
85
+ * Event Types
52
86
  */
53
- type CustomStyles = ContainerStyle;
54
87
  /**
55
88
  * Timeline seek parameters
56
89
  */
@@ -69,56 +102,32 @@ type ShortcutKeyPropertiesType = {
69
102
  * Container Visibility State
70
103
  */
71
104
  type ContainerVisibility = "open" | "closed";
72
- /**
73
- * Pop-up information passed to onPopUpOpen event handler
74
- */
75
- interface PopUpInfo {
76
- html: string;
77
- [key: string]: unknown;
78
- }
79
- /**
80
- * Base TapKit instance interface
81
- * Shared properties and methods between core and wrapper
82
- */
83
- interface TapKitBaseInstance {
105
+
106
+ /** @internal Symbol for internal configuration method */
107
+ declare const TAPKIT_CONFIG_SYMBOL: unique symbol;
108
+ /** TapKit instance interface - shared by tap-kit-core and tap-sdk */
109
+ interface TapKitInstance {
84
110
  events: {
85
111
  seekTimeline: (params: SeekTimelineParamsType) => Promise<void>;
86
112
  onTimelineSeek: (callback: (clipPlayHead: number, clipId: string) => void) => () => void;
87
- onChatInitiated: (handler: () => void) => () => void;
88
113
  onChatOpened: (handler: () => void) => () => void;
89
114
  onChatClosed: (handler: () => void) => () => void;
90
115
  onAlarmFadeIn: (handler: (messageInfo: AlarmMessageInstanceType) => void) => () => void;
91
- onPopUpOpen: (handler: (popUpInfo: PopUpInfo) => void) => () => void;
92
- onPdfOpen: (handler: () => void) => () => void;
93
- onPdfClose: (handler: () => void) => () => void;
94
116
  };
95
117
  isOpen: boolean;
96
118
  isInitialized: boolean;
97
119
  ready: Promise<void>;
98
120
  init(params: TapKitInitParams): Promise<void>;
99
121
  destroy(): void;
122
+ /** @internal Advanced configuration API */
123
+ [TAPKIT_CONFIG_SYMBOL](options: TapKitConfigOptions): void;
100
124
  }
125
+ /** TapKit constructor type */
126
+ type TapKitConstructor = new (config: TapKitConfig) => TapKitInstance;
127
+
101
128
  /**
102
- * TapKit instance type from tap-kit-core
103
- * This matches the actual TapKit class exported from @coxwave/tap-kit-core
104
- * Exported for advanced use cases (e.g., when using window.TapKit directly)
105
- *
106
- * Currently identical to TapKitBaseInstance, but kept as separate type
107
- * for future extensibility and semantic clarity
108
- */
109
- interface TapKitCoreInstance extends TapKitBaseInstance {
110
- }
111
- /**
112
- * Public TapKit instance interface
113
- * This is what users interact with when using the SDK
114
- */
115
- interface TapKitInstance extends TapKitBaseInstance {
116
- getVersion(): string;
117
- }
118
- /**
119
- * TapKit constructor type
129
+ * Error Classes
120
130
  */
121
- type TapKitConstructor = new (config: TapKitConfig) => TapKitCoreInstance;
122
131
  declare const TAP_ERROR_MARKER = "__tap_sdk_error__";
123
132
  interface TapErrorOptions {
124
133
  code?: string;
@@ -173,4 +182,34 @@ declare class TapKitIframeError extends TapKitError {
173
182
  static fromPossibleFrameSafeError(error: any): TapKitIframeError | null;
174
183
  }
175
184
 
176
- export { type ContainerStyle, type ContainerVisibility, type Course, type CustomStyles, TapKitInitializationError as InitializationError, type PopUpInfo, type PositionType, type SeekTimelineParamsType, type ShortcutKeyPropertiesType, TAP_ERROR_MARKER, type TapErrorOptions, type TapKitBaseInstance, type TapKitConfig, TapKitConfigurationError, type TapKitConstructor, type TapKitCoreInstance, TapKitError, TapKitIframeError, type TapKitInitParams, TapKitInitializationError, type TapKitInstance, TapKitLoaderError, TapKitMessageError };
185
+ /**
186
+ * Global type definitions for browser environment
187
+ */
188
+
189
+
190
+
191
+ declare global {
192
+ interface Window {
193
+ TapKit?: TapKitConstructor;
194
+ __TAP_KIT_LOADER_LOADED__?: boolean;
195
+ __TAP_KIT_LOADER_LOADING__?: Promise<void>;
196
+ __TAP_KIT_LOADER_URL__?: string; // Override CDN loader URL for local testing
197
+ __TAP_KIT_CORE_URL__?: string; // Override to load local IIFE directly (bypass loader)
198
+ TapKitLoaded?: boolean; // Set by loader.js when real SDK is loaded
199
+ }
200
+
201
+ // requestIdleCallback types (not included in TypeScript by default)
202
+ interface IdleDeadline {
203
+ readonly didTimeout: boolean;
204
+ timeRemaining(): number;
205
+ }
206
+
207
+ function requestIdleCallback(
208
+ callback: (deadline: IdleDeadline) => void,
209
+ options?: { timeout: number },
210
+ ): number;
211
+
212
+ function cancelIdleCallback(handle: number): void;
213
+ }
214
+
215
+ export { type ContainerStyle, type ContainerVisibility, type Course, type CustomStyles, TapKitInitializationError as InitializationError, type PositionType, type SeekTimelineParamsType, type ShortcutKeyPropertiesType, TAPKIT_CONFIG_SYMBOL, TAP_ERROR_MARKER, type TapErrorOptions, type TapKitConfig, type TapKitConfigOptions, TapKitConfigurationError, type TapKitConstructor, TapKitError, TapKitIframeError, type TapKitInitParams, TapKitInitializationError, type TapKitInstance, TapKitLoaderError, TapKitMessageError };
package/dist/index.js CHANGED
@@ -2,7 +2,10 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
 
5
- // index.ts
5
+ // src/instance.ts
6
+ var TAPKIT_CONFIG_SYMBOL = Symbol.for("tapkit.config");
7
+
8
+ // src/errors.ts
6
9
  var TAP_ERROR_MARKER = "__tap_sdk_error__";
7
10
  var TapKitError = class _TapKitError extends Error {
8
11
  constructor(message, options) {
@@ -131,6 +134,6 @@ var TapKitIframeError = class _TapKitIframeError extends TapKitError {
131
134
  }
132
135
  };
133
136
 
134
- export { TapKitInitializationError as InitializationError, TAP_ERROR_MARKER, TapKitConfigurationError, TapKitError, TapKitIframeError, TapKitInitializationError, TapKitLoaderError, TapKitMessageError };
137
+ export { TapKitInitializationError as InitializationError, TAPKIT_CONFIG_SYMBOL, TAP_ERROR_MARKER, TapKitConfigurationError, TapKitError, TapKitIframeError, TapKitInitializationError, TapKitLoaderError, TapKitMessageError };
135
138
  //# sourceMappingURL=index.js.map
136
139
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts"],"names":[],"mappings":";;;;;AA4JO,IAAM,gBAAA,GAAmB;AAWzB,IAAM,WAAA,GAAN,MAAM,YAAA,SAAoB,KAAA,CAAM;AAAA,EAIrC,WAAA,CAAY,SAAiB,OAAA,EAA2B;AACtD,IAAA,KAAA,CAAM,OAAO,CAAA;AAJf,IAAA,aAAA,CAAA,IAAA,EAAS,OAAA,CAAA;AACT,IAAA,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAIE,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AACZ,IAAA,IAAA,CAAK,OAAO,OAAA,EAAS,IAAA;AACrB,IAAA,IAAA,CAAK,QAAQ,OAAA,EAAS,KAAA;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,2BAA2B,KAAA,EAAgC;AAChE,IAAA,IAAI,iBAAiB,YAAA,EAAa;AAChC,MAAA,OAAO,KAAA;AAAA,IACT;AACA,IAAA,IACE,KAAA,IACA,OAAO,KAAA,KAAU,QAAA,IACjB,oBAAoB,KAAA,IACpB,KAAA,CAAM,gBAAgB,CAAA,KAAM,aAAA,EAC5B;AACA,MAAA,MAAM,GAAA,GAAM,IAAI,Y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,GAAA,GAAM,IAAI,kBAAA,CAAkB,KAAA,CAAM,OAAA,EAAS;AAAA,QAC/C,MAAM,KAAA,CAAM;AAAA,OACb,CAAA;AACD,MAAA,GAAA,CAAI,QAAQ,KAAA,CAAM,KAAA;AAClB,MAAA,OAAO,GAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAA;AAAA,EACT;AACF","file":"index.js","sourcesContent":["/**\n * @coxwave/tap-kit-types\n * Shared TypeScript types for TapKit SDK packages\n *\n * This package serves as the single source of truth for all TapKit types,\n * used by both @coxwave/tap-sdk (npm wrapper) and @coxwave/tap-kit-core (CDN implementation).\n */\n\n// ==================== Re-exports from tap-messages ====================\nimport type {\n AlarmMessageInstanceType,\n AlarmType,\n} from \"@coxwave/tap-messages\";\n\nexport type { AlarmMessageInstanceType, AlarmType };\n\n// ==================== Core Configuration Types ====================\n\n/**\n * SDK Configuration\n */\nexport type TapKitConfig = {\n apiKey: string;\n};\n\n/**\n * SDK Initialization Parameters\n */\nexport type TapKitInitParams = {\n buttonId: string;\n course: Course;\n container?: ContainerStyle;\n};\n\n/**\n * Course Information\n */\nexport type Course = {\n userId: string;\n courseId: string;\n clipId: string;\n clipPlayHead?: number;\n};\n\n// ==================== Styling Types ====================\n\n/**\n * Container Styling\n */\nexport type ContainerStyle = {\n position?: PositionType;\n width?: string;\n height?: string;\n borderRadius?: string;\n};\n\nexport type PositionType = {\n top?: string;\n left?: string;\n right?: string;\n bottom?: string;\n};\n\n/**\n * Flattened container styles (backward compatibility)\n */\nexport type CustomStyles = ContainerStyle;\n\n// ==================== Event Types ====================\n\n/**\n * Timeline seek parameters\n */\nexport type SeekTimelineParamsType = {\n clipId: string;\n clipPlayHead: number;\n};\n\n/**\n * Shortcut Key Configuration\n */\nexport type ShortcutKeyPropertiesType = {\n key: string;\n modifier: \"ctrlKey\" | \"altKey\" | \"shiftKey\" | \"metaKey\" | \"\";\n};\n\n/**\n * Container Visibility State\n */\nexport type ContainerVisibility = \"open\" | \"closed\";\n\n// ==================== SDK Instance Interfaces ====================\n\n/**\n * Pop-up information passed to onPopUpOpen event handler\n */\nexport interface PopUpInfo {\n html: string;\n [key: string]: unknown;\n}\n\n/**\n * Base TapKit instance interface\n * Shared properties and methods between core and wrapper\n */\nexport interface TapKitBaseInstance {\n events: {\n seekTimeline: (params: SeekTimelineParamsType) => Promise<void>;\n onTimelineSeek: (\n callback: (clipPlayHead: number, clipId: string) => void,\n ) => () => void;\n onChatInitiated: (handler: () => void) => () => void;\n onChatOpened: (handler: () => void) => () => void;\n onChatClosed: (handler: () => void) => () => void;\n onAlarmFadeIn: (\n handler: (messageInfo: AlarmMessageInstanceType) => void,\n ) => () => void;\n onPopUpOpen: (handler: (popUpInfo: PopUpInfo) => void) => () => void;\n onPdfOpen: (handler: () => void) => () => void;\n onPdfClose: (handler: () => void) => () => void;\n };\n isOpen: boolean;\n isInitialized: boolean;\n ready: Promise<void>;\n init(params: TapKitInitParams): Promise<void>;\n destroy(): void;\n}\n\n/**\n * TapKit instance type from tap-kit-core\n * This matches the actual TapKit class exported from @coxwave/tap-kit-core\n * Exported for advanced use cases (e.g., when using window.TapKit directly)\n *\n * Currently identical to TapKitBaseInstance, but kept as separate type\n * for future extensibility and semantic clarity\n */\nexport interface TapKitCoreInstance extends TapKitBaseInstance {}\n\n/**\n * Public TapKit instance interface\n * This is what users interact with when using the SDK\n */\nexport interface TapKitInstance extends TapKitBaseInstance {\n // Wrapper-specific method\n getVersion(): string;\n}\n\n/**\n * TapKit constructor type\n */\nexport type TapKitConstructor = new (\n config: TapKitConfig,\n) => TapKitCoreInstance;\n\n// ==================== Error Classes ====================\n\nexport const TAP_ERROR_MARKER = \"__tap_sdk_error__\";\n\nexport interface TapErrorOptions {\n code?: string;\n cause?: Error;\n}\n\n/**\n * Base error class for all TapKit errors\n * Supports serialization across iframe boundaries\n */\nexport class TapKitError extends Error {\n override cause: Error | undefined;\n code: string | undefined;\n\n constructor(message: string, options?: TapErrorOptions) {\n super(message);\n this.name = \"TapKitError\";\n this.code = options?.code;\n this.cause = options?.cause;\n }\n\n /**\n * Restore error from postMessage serialization\n */\n static fromPossibleFrameSafeError(error: any): TapKitError | null {\n if (error instanceof TapKitError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitError\"\n ) {\n const err = new TapKitError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when SDK initialization fails\n */\nexport class TapKitInitializationError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitInitializationError\";\n this.code = options?.code ?? \"ERR_INITIALIZATION\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitInitializationError | null {\n if (error instanceof TapKitInitializationError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitInitializationError\"\n ) {\n const err = new TapKitInitializationError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when message communication fails\n */\nexport class TapKitMessageError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitMessageError\";\n this.code = options?.code ?? \"ERR_MESSAGE\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitMessageError | null {\n if (error instanceof TapKitMessageError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitMessageError\"\n ) {\n const err = new TapKitMessageError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when configuration is invalid\n */\nexport class TapKitConfigurationError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitConfigurationError\";\n this.code = options?.code ?? \"ERR_CONFIGURATION\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitConfigurationError | null {\n if (error instanceof TapKitConfigurationError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitConfigurationError\"\n ) {\n const err = new TapKitConfigurationError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when loader fails to fetch or load resources\n */\nexport class TapKitLoaderError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitLoaderError\";\n this.code = options?.code ?? \"ERR_LOADER\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitLoaderError | null {\n if (error instanceof TapKitLoaderError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitLoaderError\"\n ) {\n const err = new TapKitLoaderError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when iframe operations fail\n */\nexport class TapKitIframeError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitIframeError\";\n this.code = options?.code ?? \"ERR_IFRAME\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitIframeError | null {\n if (error instanceof TapKitIframeError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitIframeError\"\n ) {\n const err = new TapKitIframeError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n// Backward compatibility alias\nexport { TapKitInitializationError as InitializationError };\n"]}
1
+ {"version":3,"sources":["../src/instance.ts","../src/errors.ts"],"names":[],"mappings":";;;;;AAKO,IAAM,oBAAA,GAAsC,MAAA,C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I,kBAAA,CAAkB,KAAA,CAAM,OAAA,EAAS;AAAA,QAC/C,MAAM,KAAA,CAAM;AAAA,OACb,CAAA;AACD,MAAA,GAAA,CAAI,QAAQ,KAAA,CAAM,KAAA;AAClB,MAAA,OAAO,GAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAKO,IAAM,iBAAA,GAAN,MAAM,kBAAA,SAA0B,WAAA,CAAY;AAAA,EACjD,WAAA,CAAY,SAAiB,OAAA,EAA2B;AACtD,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,SAAS,IAAA,IAAQ,YAAA;AAAA,EAC/B;AAAA,EAEA,OAAgB,2BACd,KAAA,EAC0B;AAC1B,IAAA,IAAI,iBAAiB,kBAAA,EAAmB;AACtC,MAAA,OAAO,KAAA;AAAA,IACT;AACA,IAAA,IACE,KAAA,IACA,OAAO,KAAA,KAAU,QAAA,IACjB,oBAAoB,KAAA,IACpB,KAAA,CAAM,gBAAgB,CAAA,KAAM,mBAAA,EAC5B;AACA,MAAA,MAAM,GAAA,GAAM,IAAI,kBAAA,CAAkB,KAAA,CAAM,OAAA,EAAS;AAAA,QAC/C,MAAM,KAAA,CAAM;AAAA,OACb,CAAA;AACD,MAAA,GAAA,CAAI,QAAQ,KAAA,CAAM,KAAA;AAClB,MAAA,OAAO,GAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAA;AAAA,EACT;AACF","file":"index.js","sourcesContent":["import type { AlarmMessageInstanceType } from \"@coxwave/tap-messages\";\nimport type { SeekTimelineParamsType } from \"./events\";\nimport type { TapKitConfig, TapKitConfigOptions, TapKitInitParams } from \"./config.js\";\n\n/** @internal Symbol for internal configuration method */\nexport const TAPKIT_CONFIG_SYMBOL: unique symbol = Symbol.for(\"tapkit.config\") as any;\n\n/** TapKit instance interface - shared by tap-kit-core and tap-sdk */\nexport interface TapKitInstance {\n events: {\n seekTimeline: (params: SeekTimelineParamsType) => Promise<void>;\n onTimelineSeek: (callback: (clipPlayHead: number, clipId: string) => void) => () => void;\n onChatOpened: (handler: () => void) => () => void;\n onChatClosed: (handler: () => void) => () => void;\n onAlarmFadeIn: (handler: (messageInfo: AlarmMessageInstanceType) => void) => () => void;\n };\n isOpen: boolean;\n isInitialized: boolean;\n ready: Promise<void>;\n init(params: TapKitInitParams): Promise<void>;\n destroy(): void;\n /** @internal Advanced configuration API */\n [TAPKIT_CONFIG_SYMBOL](options: TapKitConfigOptions): void;\n}\n\n/** TapKit constructor type */\nexport type TapKitConstructor = new (config: TapKitConfig) => TapKitInstance;\n","/**\n * Error Classes\n */\n\nexport const TAP_ERROR_MARKER = \"__tap_sdk_error__\";\n\nexport interface TapErrorOptions {\n code?: string;\n cause?: Error;\n}\n\n/**\n * Base error class for all TapKit errors\n * Supports serialization across iframe boundaries\n */\nexport class TapKitError extends Error {\n override cause: Error | undefined;\n code: string | undefined;\n\n constructor(message: string, options?: TapErrorOptions) {\n super(message);\n this.name = \"TapKitError\";\n this.code = options?.code;\n this.cause = options?.cause;\n }\n\n /**\n * Restore error from postMessage serialization\n */\n static fromPossibleFrameSafeError(error: any): TapKitError | null {\n if (error instanceof TapKitError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitError\"\n ) {\n const err = new TapKitError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when SDK initialization fails\n */\nexport class TapKitInitializationError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitInitializationError\";\n this.code = options?.code ?? \"ERR_INITIALIZATION\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitInitializationError | null {\n if (error instanceof TapKitInitializationError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitInitializationError\"\n ) {\n const err = new TapKitInitializationError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when message communication fails\n */\nexport class TapKitMessageError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitMessageError\";\n this.code = options?.code ?? \"ERR_MESSAGE\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitMessageError | null {\n if (error instanceof TapKitMessageError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitMessageError\"\n ) {\n const err = new TapKitMessageError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when configuration is invalid\n */\nexport class TapKitConfigurationError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitConfigurationError\";\n this.code = options?.code ?? \"ERR_CONFIGURATION\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitConfigurationError | null {\n if (error instanceof TapKitConfigurationError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitConfigurationError\"\n ) {\n const err = new TapKitConfigurationError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when loader fails to fetch or load resources\n */\nexport class TapKitLoaderError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitLoaderError\";\n this.code = options?.code ?? \"ERR_LOADER\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitLoaderError | null {\n if (error instanceof TapKitLoaderError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitLoaderError\"\n ) {\n const err = new TapKitLoaderError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when iframe operations fail\n */\nexport class TapKitIframeError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitIframeError\";\n this.code = options?.code ?? \"ERR_IFRAME\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitIframeError | null {\n if (error instanceof TapKitIframeError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitIframeError\"\n ) {\n const err = new TapKitIframeError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n// Backward compatibility alias\nexport { TapKitInitializationError as InitializationError };\n"]}
package/index.ts CHANGED
@@ -6,358 +6,36 @@
6
6
  * used by both @coxwave/tap-sdk (npm wrapper) and @coxwave/tap-kit-core (CDN implementation).
7
7
  */
8
8
 
9
- // ==================== Re-exports from tap-messages ====================
10
- import type {
11
- AlarmMessageInstanceType,
12
- AlarmType,
13
- } from "@coxwave/tap-messages";
9
+ // Re-exports from tap-messages
10
+ export type { AlarmMessageInstanceType, AlarmType } from "@coxwave/tap-messages";
14
11
 
15
- export type { AlarmMessageInstanceType, AlarmType };
12
+ // Configuration types
13
+ export type { TapKitConfig, TapKitConfigOptions, TapKitInitParams, Course } from "./src/config.js";
16
14
 
17
- // ==================== Core Configuration Types ====================
15
+ // Styling types
16
+ export type { ContainerStyle, PositionType, CustomStyles } from "./src/styles.js";
18
17
 
19
- /**
20
- * SDK Configuration
21
- */
22
- export type TapKitConfig = {
23
- apiKey: string;
24
- };
25
-
26
- /**
27
- * SDK Initialization Parameters
28
- */
29
- export type TapKitInitParams = {
30
- buttonId: string;
31
- course: Course;
32
- container?: ContainerStyle;
33
- };
34
-
35
- /**
36
- * Course Information
37
- */
38
- export type Course = {
39
- userId: string;
40
- courseId: string;
41
- clipId: string;
42
- clipPlayHead?: number;
43
- };
44
-
45
- // ==================== Styling Types ====================
46
-
47
- /**
48
- * Container Styling
49
- */
50
- export type ContainerStyle = {
51
- position?: PositionType;
52
- width?: string;
53
- height?: string;
54
- borderRadius?: string;
55
- };
56
-
57
- export type PositionType = {
58
- top?: string;
59
- left?: string;
60
- right?: string;
61
- bottom?: string;
62
- };
63
-
64
- /**
65
- * Flattened container styles (backward compatibility)
66
- */
67
- export type CustomStyles = ContainerStyle;
68
-
69
- // ==================== Event Types ====================
18
+ // Event types
19
+ export type { SeekTimelineParamsType, ShortcutKeyPropertiesType, ContainerVisibility } from "./src/events.js";
70
20
 
71
- /**
72
- * Timeline seek parameters
73
- */
74
- export type SeekTimelineParamsType = {
75
- clipId: string;
76
- clipPlayHead: number;
77
- };
21
+ // Instance types
22
+ export type { TapKitInstance, TapKitConstructor } from "./src/instance.js";
78
23
 
79
- /**
80
- * Shortcut Key Configuration
81
- */
82
- export type ShortcutKeyPropertiesType = {
83
- key: string;
84
- modifier: "ctrlKey" | "altKey" | "shiftKey" | "metaKey" | "";
85
- };
24
+ export { TAPKIT_CONFIG_SYMBOL } from "./src/instance.js";
86
25
 
87
- /**
88
- * Container Visibility State
89
- */
90
- export type ContainerVisibility = "open" | "closed";
91
-
92
- // ==================== SDK Instance Interfaces ====================
93
-
94
- /**
95
- * Pop-up information passed to onPopUpOpen event handler
96
- */
97
- export interface PopUpInfo {
98
- html: string;
99
- [key: string]: unknown;
100
- }
101
-
102
- /**
103
- * Base TapKit instance interface
104
- * Shared properties and methods between core and wrapper
105
- */
106
- export interface TapKitBaseInstance {
107
- events: {
108
- seekTimeline: (params: SeekTimelineParamsType) => Promise<void>;
109
- onTimelineSeek: (
110
- callback: (clipPlayHead: number, clipId: string) => void,
111
- ) => () => void;
112
- onChatInitiated: (handler: () => void) => () => void;
113
- onChatOpened: (handler: () => void) => () => void;
114
- onChatClosed: (handler: () => void) => () => void;
115
- onAlarmFadeIn: (
116
- handler: (messageInfo: AlarmMessageInstanceType) => void,
117
- ) => () => void;
118
- onPopUpOpen: (handler: (popUpInfo: PopUpInfo) => void) => () => void;
119
- onPdfOpen: (handler: () => void) => () => void;
120
- onPdfClose: (handler: () => void) => () => void;
121
- };
122
- isOpen: boolean;
123
- isInitialized: boolean;
124
- ready: Promise<void>;
125
- init(params: TapKitInitParams): Promise<void>;
126
- destroy(): void;
127
- }
128
-
129
- /**
130
- * TapKit instance type from tap-kit-core
131
- * This matches the actual TapKit class exported from @coxwave/tap-kit-core
132
- * Exported for advanced use cases (e.g., when using window.TapKit directly)
133
- *
134
- * Currently identical to TapKitBaseInstance, but kept as separate type
135
- * for future extensibility and semantic clarity
136
- */
137
- export interface TapKitCoreInstance extends TapKitBaseInstance {}
138
-
139
- /**
140
- * Public TapKit instance interface
141
- * This is what users interact with when using the SDK
142
- */
143
- export interface TapKitInstance extends TapKitBaseInstance {
144
- // Wrapper-specific method
145
- getVersion(): string;
146
- }
147
-
148
- /**
149
- * TapKit constructor type
150
- */
151
- export type TapKitConstructor = new (
152
- config: TapKitConfig,
153
- ) => TapKitCoreInstance;
154
-
155
- // ==================== Error Classes ====================
156
-
157
- export const TAP_ERROR_MARKER = "__tap_sdk_error__";
158
-
159
- export interface TapErrorOptions {
160
- code?: string;
161
- cause?: Error;
162
- }
163
-
164
- /**
165
- * Base error class for all TapKit errors
166
- * Supports serialization across iframe boundaries
167
- */
168
- export class TapKitError extends Error {
169
- override cause: Error | undefined;
170
- code: string | undefined;
171
-
172
- constructor(message: string, options?: TapErrorOptions) {
173
- super(message);
174
- this.name = "TapKitError";
175
- this.code = options?.code;
176
- this.cause = options?.cause;
177
- }
178
-
179
- /**
180
- * Restore error from postMessage serialization
181
- */
182
- static fromPossibleFrameSafeError(error: any): TapKitError | null {
183
- if (error instanceof TapKitError) {
184
- return error;
185
- }
186
- if (
187
- error &&
188
- typeof error === "object" &&
189
- TAP_ERROR_MARKER in error &&
190
- error[TAP_ERROR_MARKER] === "TapKitError"
191
- ) {
192
- const err = new TapKitError(error.message, {
193
- code: error.code,
194
- });
195
- err.stack = error.stack;
196
- return err;
197
- }
198
- return null;
199
- }
200
- }
201
-
202
- /**
203
- * Error thrown when SDK initialization fails
204
- */
205
- export class TapKitInitializationError extends TapKitError {
206
- constructor(message: string, options?: TapErrorOptions) {
207
- super(message, options);
208
- this.name = "TapKitInitializationError";
209
- this.code = options?.code ?? "ERR_INITIALIZATION";
210
- }
211
-
212
- static override fromPossibleFrameSafeError(
213
- error: any
214
- ): TapKitInitializationError | null {
215
- if (error instanceof TapKitInitializationError) {
216
- return error;
217
- }
218
- if (
219
- error &&
220
- typeof error === "object" &&
221
- TAP_ERROR_MARKER in error &&
222
- error[TAP_ERROR_MARKER] === "TapKitInitializationError"
223
- ) {
224
- const err = new TapKitInitializationError(error.message, {
225
- code: error.code,
226
- });
227
- err.stack = error.stack;
228
- return err;
229
- }
230
- return null;
231
- }
232
- }
233
-
234
- /**
235
- * Error thrown when message communication fails
236
- */
237
- export class TapKitMessageError extends TapKitError {
238
- constructor(message: string, options?: TapErrorOptions) {
239
- super(message, options);
240
- this.name = "TapKitMessageError";
241
- this.code = options?.code ?? "ERR_MESSAGE";
242
- }
243
-
244
- static override fromPossibleFrameSafeError(
245
- error: any
246
- ): TapKitMessageError | null {
247
- if (error instanceof TapKitMessageError) {
248
- return error;
249
- }
250
- if (
251
- error &&
252
- typeof error === "object" &&
253
- TAP_ERROR_MARKER in error &&
254
- error[TAP_ERROR_MARKER] === "TapKitMessageError"
255
- ) {
256
- const err = new TapKitMessageError(error.message, {
257
- code: error.code,
258
- });
259
- err.stack = error.stack;
260
- return err;
261
- }
262
- return null;
263
- }
264
- }
265
-
266
- /**
267
- * Error thrown when configuration is invalid
268
- */
269
- export class TapKitConfigurationError extends TapKitError {
270
- constructor(message: string, options?: TapErrorOptions) {
271
- super(message, options);
272
- this.name = "TapKitConfigurationError";
273
- this.code = options?.code ?? "ERR_CONFIGURATION";
274
- }
275
-
276
- static override fromPossibleFrameSafeError(
277
- error: any
278
- ): TapKitConfigurationError | null {
279
- if (error instanceof TapKitConfigurationError) {
280
- return error;
281
- }
282
- if (
283
- error &&
284
- typeof error === "object" &&
285
- TAP_ERROR_MARKER in error &&
286
- error[TAP_ERROR_MARKER] === "TapKitConfigurationError"
287
- ) {
288
- const err = new TapKitConfigurationError(error.message, {
289
- code: error.code,
290
- });
291
- err.stack = error.stack;
292
- return err;
293
- }
294
- return null;
295
- }
296
- }
297
-
298
- /**
299
- * Error thrown when loader fails to fetch or load resources
300
- */
301
- export class TapKitLoaderError extends TapKitError {
302
- constructor(message: string, options?: TapErrorOptions) {
303
- super(message, options);
304
- this.name = "TapKitLoaderError";
305
- this.code = options?.code ?? "ERR_LOADER";
306
- }
307
-
308
- static override fromPossibleFrameSafeError(
309
- error: any
310
- ): TapKitLoaderError | null {
311
- if (error instanceof TapKitLoaderError) {
312
- return error;
313
- }
314
- if (
315
- error &&
316
- typeof error === "object" &&
317
- TAP_ERROR_MARKER in error &&
318
- error[TAP_ERROR_MARKER] === "TapKitLoaderError"
319
- ) {
320
- const err = new TapKitLoaderError(error.message, {
321
- code: error.code,
322
- });
323
- err.stack = error.stack;
324
- return err;
325
- }
326
- return null;
327
- }
328
- }
329
-
330
- /**
331
- * Error thrown when iframe operations fail
332
- */
333
- export class TapKitIframeError extends TapKitError {
334
- constructor(message: string, options?: TapErrorOptions) {
335
- super(message, options);
336
- this.name = "TapKitIframeError";
337
- this.code = options?.code ?? "ERR_IFRAME";
338
- }
26
+ // Error types and classes
27
+ export type { TapErrorOptions } from "./src/errors.js";
339
28
 
340
- static override fromPossibleFrameSafeError(
341
- error: any
342
- ): TapKitIframeError | null {
343
- if (error instanceof TapKitIframeError) {
344
- return error;
345
- }
346
- if (
347
- error &&
348
- typeof error === "object" &&
349
- TAP_ERROR_MARKER in error &&
350
- error[TAP_ERROR_MARKER] === "TapKitIframeError"
351
- ) {
352
- const err = new TapKitIframeError(error.message, {
353
- code: error.code,
354
- });
355
- err.stack = error.stack;
356
- return err;
357
- }
358
- return null;
359
- }
360
- }
29
+ export {
30
+ TAP_ERROR_MARKER,
31
+ TapKitError,
32
+ TapKitInitializationError,
33
+ TapKitMessageError,
34
+ TapKitConfigurationError,
35
+ TapKitLoaderError,
36
+ TapKitIframeError,
37
+ InitializationError,
38
+ } from "./src/errors.js";
361
39
 
362
- // Backward compatibility alias
363
- export { TapKitInitializationError as InitializationError };
40
+ // Global type definitions (Window, requestIdleCallback)
41
+ import "./src/global.d.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coxwave/tap-kit-types",
3
- "version": "0.0.34",
3
+ "version": "0.0.37",
4
4
  "type": "module",
5
5
  "description": "Shared TypeScript types for TapKit SDK packages",
6
6
  "main": "dist/index.js",