captions.js 0.1.0-alpha → 0.1.0
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 +5 -3
- package/dist/index.d.mts +234 -1
- package/dist/index.d.ts +234 -1
- package/dist/index.js +1817 -3
- package/dist/index.mjs +1797 -2
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
> [!WARNING]
|
|
2
2
|
> 🚧 **Captions.js is nearing its first public release**
|
|
3
|
-
> The library is under active development and a full-featured version is expected around **
|
|
3
|
+
> The library is under active development and a full-featured version is expected around **January 2026**.
|
|
4
4
|
|
|
5
5
|
💌 Want to know when Captions.js is released?
|
|
6
6
|
Star or watch the repo on GitHub to get updates!
|
|
7
7
|
|
|
8
8
|
# Captions.js
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Render styled animated captions on canvas — works both on client and server side using Node.js and FFmpeg.
|
|
11
11
|
|
|
12
12
|
[**Live Demo**](https://maskin25.github.io/captions.js/)
|
|
13
13
|
|
|
14
|
-
[
|
|
14
|
+
[**Docs & API Reference**](https://maskin25.github.io/captions.js/docs/)
|
|
15
|
+
|
|
16
|
+
<!-- [](https://main--68e681805917843931c33a87.chromatic.com/) -->
|
|
15
17
|
|
|
16
18
|
## Features
|
|
17
19
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,236 @@
|
|
|
1
|
+
import Konva from 'konva';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whitelisted Google Fonts that the renderer knows how to lazy-load.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Restricting the list keeps bundle size predictable across consumers.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
declare const googleFontsList: readonly ["Roboto", "Open Sans", "Lato", "Montserrat", "Nunito", "Poppins", "Ubuntu", "PT Sans", "Merriweather Sans", "Lobster", "Amatic SC", "Pacifico", "Raleway", "Cinzel", "Quicksand", "Zilla Slab", "Caveat", "Crimson Pro", "Bebas Neue", "Comfortaa", "Satisfy", "Permanent Marker", "Oswald", "Onset", "Bangers", "Kanit", "Work Sans", "Fira Sans", "Anton", "Playfair Display", "Rubik", "Alumni Sans", "Righteous", "Comico", "Excon", "Kalam", "Tanker", "Arsenal", "Balsamiq Sans", "Bona Nova SC"];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Full styling + animation configuration for a single captions track.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
interface CaptionsSettings {
|
|
19
|
+
style: {
|
|
20
|
+
name: string;
|
|
21
|
+
font: {
|
|
22
|
+
fontFamily: string;
|
|
23
|
+
fontSize: number;
|
|
24
|
+
fontWeight: "thin" | "light" | "regular" | "medium" | "bold" | "black";
|
|
25
|
+
fontColor: string;
|
|
26
|
+
fontCapitalize: boolean;
|
|
27
|
+
italic: boolean;
|
|
28
|
+
underline: boolean;
|
|
29
|
+
fontStrokeColor: string;
|
|
30
|
+
fontStrokeWidth: number;
|
|
31
|
+
shadow?: {
|
|
32
|
+
fontShadowColor: string;
|
|
33
|
+
fontShadowBlur: number;
|
|
34
|
+
fontShadowOffsetX: number;
|
|
35
|
+
fontShadowOffsetY: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
verticalCoverImg?: string;
|
|
39
|
+
aplifiedWordColor: string;
|
|
40
|
+
backgroundColor: string;
|
|
41
|
+
};
|
|
42
|
+
linesPerPage: number;
|
|
43
|
+
lineSpacing?: number | null;
|
|
44
|
+
position: "auto" | "top" | "middle" | "bottom";
|
|
45
|
+
positionTopOffset?: number;
|
|
46
|
+
animation: "none" | "bounce" | "underline" | "box" | "pop" | "scale" | "slide-left" | "slide-up" | "slide-down" | "box-word";
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Single timed word/segment that will be highlighted as audio plays.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
interface Caption {
|
|
54
|
+
word: string;
|
|
55
|
+
startTime: number;
|
|
56
|
+
endTime: number;
|
|
57
|
+
highlightColor?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Shared schema describing how a preset styles captions plus rough layout hints.
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
interface StylePreset {
|
|
66
|
+
id: number;
|
|
67
|
+
captionsSettings: CaptionsSettings;
|
|
68
|
+
layoutSettings: {
|
|
69
|
+
aspectRatio: string;
|
|
70
|
+
aIAutoLayout: string[];
|
|
71
|
+
fitLayoutAspectRatio: string;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Names of all available style presets.
|
|
76
|
+
*/
|
|
77
|
+
type StylePresetName = "Karaoke" | "Beasty" | "Safari" | "Acid" | "Popline" | "Desert" | "Hook" | "Sky" | "Flamingo" | "Deep Diver B&W" | "New" | "Banger" | "Catchy" | "Karaoke 2" | "Karaoke 3" | "From" | "Classic" | "Classic Big" | "Crazy" | "Acid 2" | "Marvel" | "Lovly" | "Old Money" | "Cinema" | "Marker";
|
|
78
|
+
/**
|
|
79
|
+
* Curated set of presets that ship with captions.js out of the box.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* Downstream apps can reference them directly or clone/extend as needed.
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
declare const stylePresets: StylePreset[];
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Server/worker-friendly helper that paints a text string onto a provided canvas.
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* Uses the same Konva pipeline as the video overlay renderer so the results
|
|
93
|
+
* match what users see in the browser.
|
|
94
|
+
*
|
|
95
|
+
* @param canvas - Destination canvas that should receive the rendered text.
|
|
96
|
+
* @param text - Arbitrary content that needs to be painted.
|
|
97
|
+
* @param options - Rendering options that include the style preset.
|
|
98
|
+
* @returns Resolves once the frame has been painted (always resolves to `true`).
|
|
99
|
+
*/
|
|
100
|
+
declare function renderString(canvas: HTMLCanvasElement, text: string, options: {
|
|
101
|
+
preset: StylePreset;
|
|
102
|
+
}): Promise<boolean>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Configuration passed to the captions runtime when binding to a video element.
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
type CaptionsOptions = {
|
|
110
|
+
/** Video element that should receive overlays. */
|
|
111
|
+
video: HTMLVideoElement;
|
|
112
|
+
/** Optional custom container to host the Konva stage. */
|
|
113
|
+
container?: HTMLDivElement;
|
|
114
|
+
/** Initial preset controlling font, colors, animations. */
|
|
115
|
+
preset: StylePreset;
|
|
116
|
+
/** Initial caption track. */
|
|
117
|
+
captions?: Caption[] | null;
|
|
118
|
+
/** When false, caller must invoke {@link Captions.enable} manually. */
|
|
119
|
+
autoEnable?: boolean;
|
|
120
|
+
/** Show debug bounding boxes around lines/blocks. */
|
|
121
|
+
debug?: boolean;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Imperative controller that owns the Konva stage lifecycle for a single video element.
|
|
125
|
+
*
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
declare class Captions {
|
|
129
|
+
private enabled;
|
|
130
|
+
private readonly video;
|
|
131
|
+
private readonly providedContainer?;
|
|
132
|
+
private presetState;
|
|
133
|
+
private captionsState;
|
|
134
|
+
private containerElement?;
|
|
135
|
+
private ownsContainer;
|
|
136
|
+
private stage;
|
|
137
|
+
private layer;
|
|
138
|
+
private resizeObserver?;
|
|
139
|
+
private animationFrameId;
|
|
140
|
+
private videoWidth;
|
|
141
|
+
private videoHeight;
|
|
142
|
+
private readonly debug;
|
|
143
|
+
private readonly handleResize;
|
|
144
|
+
private readonly handleMetadata;
|
|
145
|
+
private readonly animationLoop;
|
|
146
|
+
/**
|
|
147
|
+
* Create a controller bound to the provided video element and preset.
|
|
148
|
+
*
|
|
149
|
+
* @param options - Complete configuration for the controller.
|
|
150
|
+
*/
|
|
151
|
+
constructor(options: CaptionsOptions);
|
|
152
|
+
/**
|
|
153
|
+
* Mount caption overlays onto the configured video if they are not active yet.
|
|
154
|
+
*/
|
|
155
|
+
enable(): void;
|
|
156
|
+
/**
|
|
157
|
+
* Tear down overlays, observers and animation loops to free resources.
|
|
158
|
+
*/
|
|
159
|
+
disable(): void;
|
|
160
|
+
/**
|
|
161
|
+
* Alias for {@link Captions.disable | disable()} to match typical imperative controller APIs.
|
|
162
|
+
*/
|
|
163
|
+
destroy(): void;
|
|
164
|
+
/**
|
|
165
|
+
* Swap the active preset and re-render with updated typography/colors.
|
|
166
|
+
*
|
|
167
|
+
* @param nextPreset - Preset that becomes the new render baseline.
|
|
168
|
+
*/
|
|
169
|
+
preset(nextPreset: StylePreset): void;
|
|
170
|
+
/**
|
|
171
|
+
* Replace the current caption track and repaint without reloading fonts.
|
|
172
|
+
*
|
|
173
|
+
* @param nextCaptions - Timed words that should drive the overlay.
|
|
174
|
+
*/
|
|
175
|
+
captions(nextCaptions: Caption[] | null): void;
|
|
176
|
+
/**
|
|
177
|
+
* Whether the Konva overlay is currently attached to the video element.
|
|
178
|
+
*
|
|
179
|
+
* @returns `true` when the overlay is mounted on top of the video.
|
|
180
|
+
*/
|
|
181
|
+
isEnabled(): boolean;
|
|
182
|
+
private refreshFrame;
|
|
183
|
+
private loadFontForCurrentPreset;
|
|
184
|
+
private updateFrame;
|
|
185
|
+
private syncStageDimensions;
|
|
186
|
+
private createOverlay;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Convenience alias for the concrete controller class.
|
|
190
|
+
*
|
|
191
|
+
* @public
|
|
192
|
+
*/
|
|
193
|
+
type CaptionsInstance = Captions;
|
|
194
|
+
/**
|
|
195
|
+
* Factory mirroring the legacy default export for ergonomic imports.
|
|
196
|
+
*
|
|
197
|
+
* @param options - Same options accepted by the {@link Captions} constructor.
|
|
198
|
+
* @returns New controller instance.
|
|
199
|
+
*/
|
|
200
|
+
declare function captionsjs(options: CaptionsOptions): Captions;
|
|
201
|
+
|
|
202
|
+
declare enum LayoutType {
|
|
203
|
+
'Fill' = "fill",
|
|
204
|
+
'Fit' = "fit",
|
|
205
|
+
'Split' = "split",
|
|
206
|
+
'Three' = "three",
|
|
207
|
+
'Four' = "four",
|
|
208
|
+
'ScreenShare' = "screenShare"
|
|
209
|
+
}
|
|
210
|
+
type AspectRatioType = typeof aspectRatios[number];
|
|
211
|
+
interface LayoutSettings {
|
|
212
|
+
aspectRatio: AspectRatioType;
|
|
213
|
+
aIAutoLayout: LayoutType[];
|
|
214
|
+
fitLayoutCropAspectRatio: AspectRatioType;
|
|
215
|
+
}
|
|
216
|
+
declare const aspectRatios: readonly ["1:1", "9:16", "16:9"];
|
|
217
|
+
|
|
218
|
+
type RenderFrameFn = (captionsSettings: CaptionsSettings, layoutSettings: LayoutSettings, captions: Caption[], currentTime: number, targetSize: [number, number], layer: Konva.Layer, toCoef?: number, debug?: boolean) => void;
|
|
219
|
+
|
|
220
|
+
declare const renderFrame: RenderFrameFn;
|
|
221
|
+
declare const renderStylePreset: (stylePreset: StylePreset, size: [number, number], frames: number[], text?: string) => Promise<string[]>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Simple canvas demo renderer used only for the docs playground.
|
|
225
|
+
*
|
|
226
|
+
* @remarks
|
|
227
|
+
* Keeps a reference implementation of drawing raw text to a canvas so we can
|
|
228
|
+
* showcase caption styling without a video element.
|
|
229
|
+
*
|
|
230
|
+
* @param ctx - Target 2D context to draw on.
|
|
231
|
+
* @param text - Arbitrary string that should be painted on the canvas.
|
|
232
|
+
* @returns Always returns `true` to match the historical API surface.
|
|
233
|
+
*/
|
|
1
234
|
declare function renderCaptions(ctx: CanvasRenderingContext2D, text: string): boolean;
|
|
2
235
|
|
|
3
|
-
export { renderCaptions };
|
|
236
|
+
export { type Caption, Captions, type CaptionsInstance, type CaptionsOptions, type CaptionsSettings, type StylePreset, type StylePresetName, captionsjs, captionsjs as default, googleFontsList, renderCaptions, renderFrame, renderString, renderStylePreset, stylePresets };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,236 @@
|
|
|
1
|
+
import Konva from 'konva';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whitelisted Google Fonts that the renderer knows how to lazy-load.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Restricting the list keeps bundle size predictable across consumers.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
declare const googleFontsList: readonly ["Roboto", "Open Sans", "Lato", "Montserrat", "Nunito", "Poppins", "Ubuntu", "PT Sans", "Merriweather Sans", "Lobster", "Amatic SC", "Pacifico", "Raleway", "Cinzel", "Quicksand", "Zilla Slab", "Caveat", "Crimson Pro", "Bebas Neue", "Comfortaa", "Satisfy", "Permanent Marker", "Oswald", "Onset", "Bangers", "Kanit", "Work Sans", "Fira Sans", "Anton", "Playfair Display", "Rubik", "Alumni Sans", "Righteous", "Comico", "Excon", "Kalam", "Tanker", "Arsenal", "Balsamiq Sans", "Bona Nova SC"];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Full styling + animation configuration for a single captions track.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
interface CaptionsSettings {
|
|
19
|
+
style: {
|
|
20
|
+
name: string;
|
|
21
|
+
font: {
|
|
22
|
+
fontFamily: string;
|
|
23
|
+
fontSize: number;
|
|
24
|
+
fontWeight: "thin" | "light" | "regular" | "medium" | "bold" | "black";
|
|
25
|
+
fontColor: string;
|
|
26
|
+
fontCapitalize: boolean;
|
|
27
|
+
italic: boolean;
|
|
28
|
+
underline: boolean;
|
|
29
|
+
fontStrokeColor: string;
|
|
30
|
+
fontStrokeWidth: number;
|
|
31
|
+
shadow?: {
|
|
32
|
+
fontShadowColor: string;
|
|
33
|
+
fontShadowBlur: number;
|
|
34
|
+
fontShadowOffsetX: number;
|
|
35
|
+
fontShadowOffsetY: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
verticalCoverImg?: string;
|
|
39
|
+
aplifiedWordColor: string;
|
|
40
|
+
backgroundColor: string;
|
|
41
|
+
};
|
|
42
|
+
linesPerPage: number;
|
|
43
|
+
lineSpacing?: number | null;
|
|
44
|
+
position: "auto" | "top" | "middle" | "bottom";
|
|
45
|
+
positionTopOffset?: number;
|
|
46
|
+
animation: "none" | "bounce" | "underline" | "box" | "pop" | "scale" | "slide-left" | "slide-up" | "slide-down" | "box-word";
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Single timed word/segment that will be highlighted as audio plays.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
interface Caption {
|
|
54
|
+
word: string;
|
|
55
|
+
startTime: number;
|
|
56
|
+
endTime: number;
|
|
57
|
+
highlightColor?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Shared schema describing how a preset styles captions plus rough layout hints.
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
interface StylePreset {
|
|
66
|
+
id: number;
|
|
67
|
+
captionsSettings: CaptionsSettings;
|
|
68
|
+
layoutSettings: {
|
|
69
|
+
aspectRatio: string;
|
|
70
|
+
aIAutoLayout: string[];
|
|
71
|
+
fitLayoutAspectRatio: string;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Names of all available style presets.
|
|
76
|
+
*/
|
|
77
|
+
type StylePresetName = "Karaoke" | "Beasty" | "Safari" | "Acid" | "Popline" | "Desert" | "Hook" | "Sky" | "Flamingo" | "Deep Diver B&W" | "New" | "Banger" | "Catchy" | "Karaoke 2" | "Karaoke 3" | "From" | "Classic" | "Classic Big" | "Crazy" | "Acid 2" | "Marvel" | "Lovly" | "Old Money" | "Cinema" | "Marker";
|
|
78
|
+
/**
|
|
79
|
+
* Curated set of presets that ship with captions.js out of the box.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* Downstream apps can reference them directly or clone/extend as needed.
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
declare const stylePresets: StylePreset[];
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Server/worker-friendly helper that paints a text string onto a provided canvas.
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* Uses the same Konva pipeline as the video overlay renderer so the results
|
|
93
|
+
* match what users see in the browser.
|
|
94
|
+
*
|
|
95
|
+
* @param canvas - Destination canvas that should receive the rendered text.
|
|
96
|
+
* @param text - Arbitrary content that needs to be painted.
|
|
97
|
+
* @param options - Rendering options that include the style preset.
|
|
98
|
+
* @returns Resolves once the frame has been painted (always resolves to `true`).
|
|
99
|
+
*/
|
|
100
|
+
declare function renderString(canvas: HTMLCanvasElement, text: string, options: {
|
|
101
|
+
preset: StylePreset;
|
|
102
|
+
}): Promise<boolean>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Configuration passed to the captions runtime when binding to a video element.
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
type CaptionsOptions = {
|
|
110
|
+
/** Video element that should receive overlays. */
|
|
111
|
+
video: HTMLVideoElement;
|
|
112
|
+
/** Optional custom container to host the Konva stage. */
|
|
113
|
+
container?: HTMLDivElement;
|
|
114
|
+
/** Initial preset controlling font, colors, animations. */
|
|
115
|
+
preset: StylePreset;
|
|
116
|
+
/** Initial caption track. */
|
|
117
|
+
captions?: Caption[] | null;
|
|
118
|
+
/** When false, caller must invoke {@link Captions.enable} manually. */
|
|
119
|
+
autoEnable?: boolean;
|
|
120
|
+
/** Show debug bounding boxes around lines/blocks. */
|
|
121
|
+
debug?: boolean;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Imperative controller that owns the Konva stage lifecycle for a single video element.
|
|
125
|
+
*
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
declare class Captions {
|
|
129
|
+
private enabled;
|
|
130
|
+
private readonly video;
|
|
131
|
+
private readonly providedContainer?;
|
|
132
|
+
private presetState;
|
|
133
|
+
private captionsState;
|
|
134
|
+
private containerElement?;
|
|
135
|
+
private ownsContainer;
|
|
136
|
+
private stage;
|
|
137
|
+
private layer;
|
|
138
|
+
private resizeObserver?;
|
|
139
|
+
private animationFrameId;
|
|
140
|
+
private videoWidth;
|
|
141
|
+
private videoHeight;
|
|
142
|
+
private readonly debug;
|
|
143
|
+
private readonly handleResize;
|
|
144
|
+
private readonly handleMetadata;
|
|
145
|
+
private readonly animationLoop;
|
|
146
|
+
/**
|
|
147
|
+
* Create a controller bound to the provided video element and preset.
|
|
148
|
+
*
|
|
149
|
+
* @param options - Complete configuration for the controller.
|
|
150
|
+
*/
|
|
151
|
+
constructor(options: CaptionsOptions);
|
|
152
|
+
/**
|
|
153
|
+
* Mount caption overlays onto the configured video if they are not active yet.
|
|
154
|
+
*/
|
|
155
|
+
enable(): void;
|
|
156
|
+
/**
|
|
157
|
+
* Tear down overlays, observers and animation loops to free resources.
|
|
158
|
+
*/
|
|
159
|
+
disable(): void;
|
|
160
|
+
/**
|
|
161
|
+
* Alias for {@link Captions.disable | disable()} to match typical imperative controller APIs.
|
|
162
|
+
*/
|
|
163
|
+
destroy(): void;
|
|
164
|
+
/**
|
|
165
|
+
* Swap the active preset and re-render with updated typography/colors.
|
|
166
|
+
*
|
|
167
|
+
* @param nextPreset - Preset that becomes the new render baseline.
|
|
168
|
+
*/
|
|
169
|
+
preset(nextPreset: StylePreset): void;
|
|
170
|
+
/**
|
|
171
|
+
* Replace the current caption track and repaint without reloading fonts.
|
|
172
|
+
*
|
|
173
|
+
* @param nextCaptions - Timed words that should drive the overlay.
|
|
174
|
+
*/
|
|
175
|
+
captions(nextCaptions: Caption[] | null): void;
|
|
176
|
+
/**
|
|
177
|
+
* Whether the Konva overlay is currently attached to the video element.
|
|
178
|
+
*
|
|
179
|
+
* @returns `true` when the overlay is mounted on top of the video.
|
|
180
|
+
*/
|
|
181
|
+
isEnabled(): boolean;
|
|
182
|
+
private refreshFrame;
|
|
183
|
+
private loadFontForCurrentPreset;
|
|
184
|
+
private updateFrame;
|
|
185
|
+
private syncStageDimensions;
|
|
186
|
+
private createOverlay;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Convenience alias for the concrete controller class.
|
|
190
|
+
*
|
|
191
|
+
* @public
|
|
192
|
+
*/
|
|
193
|
+
type CaptionsInstance = Captions;
|
|
194
|
+
/**
|
|
195
|
+
* Factory mirroring the legacy default export for ergonomic imports.
|
|
196
|
+
*
|
|
197
|
+
* @param options - Same options accepted by the {@link Captions} constructor.
|
|
198
|
+
* @returns New controller instance.
|
|
199
|
+
*/
|
|
200
|
+
declare function captionsjs(options: CaptionsOptions): Captions;
|
|
201
|
+
|
|
202
|
+
declare enum LayoutType {
|
|
203
|
+
'Fill' = "fill",
|
|
204
|
+
'Fit' = "fit",
|
|
205
|
+
'Split' = "split",
|
|
206
|
+
'Three' = "three",
|
|
207
|
+
'Four' = "four",
|
|
208
|
+
'ScreenShare' = "screenShare"
|
|
209
|
+
}
|
|
210
|
+
type AspectRatioType = typeof aspectRatios[number];
|
|
211
|
+
interface LayoutSettings {
|
|
212
|
+
aspectRatio: AspectRatioType;
|
|
213
|
+
aIAutoLayout: LayoutType[];
|
|
214
|
+
fitLayoutCropAspectRatio: AspectRatioType;
|
|
215
|
+
}
|
|
216
|
+
declare const aspectRatios: readonly ["1:1", "9:16", "16:9"];
|
|
217
|
+
|
|
218
|
+
type RenderFrameFn = (captionsSettings: CaptionsSettings, layoutSettings: LayoutSettings, captions: Caption[], currentTime: number, targetSize: [number, number], layer: Konva.Layer, toCoef?: number, debug?: boolean) => void;
|
|
219
|
+
|
|
220
|
+
declare const renderFrame: RenderFrameFn;
|
|
221
|
+
declare const renderStylePreset: (stylePreset: StylePreset, size: [number, number], frames: number[], text?: string) => Promise<string[]>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Simple canvas demo renderer used only for the docs playground.
|
|
225
|
+
*
|
|
226
|
+
* @remarks
|
|
227
|
+
* Keeps a reference implementation of drawing raw text to a canvas so we can
|
|
228
|
+
* showcase caption styling without a video element.
|
|
229
|
+
*
|
|
230
|
+
* @param ctx - Target 2D context to draw on.
|
|
231
|
+
* @param text - Arbitrary string that should be painted on the canvas.
|
|
232
|
+
* @returns Always returns `true` to match the historical API surface.
|
|
233
|
+
*/
|
|
1
234
|
declare function renderCaptions(ctx: CanvasRenderingContext2D, text: string): boolean;
|
|
2
235
|
|
|
3
|
-
export { renderCaptions };
|
|
236
|
+
export { type Caption, Captions, type CaptionsInstance, type CaptionsOptions, type CaptionsSettings, type StylePreset, type StylePresetName, captionsjs, captionsjs as default, googleFontsList, renderCaptions, renderFrame, renderString, renderStylePreset, stylePresets };
|