@clypra-studio/engine 1.10.2 → 2.2.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/dist/captions/index.cjs +559 -0
- package/dist/captions/index.cjs.map +1 -0
- package/dist/captions/index.d.cts +184 -0
- package/dist/captions/index.d.ts +184 -0
- package/dist/captions/index.js +35 -0
- package/dist/captions/index.js.map +1 -0
- package/dist/{chunk-ZV3RQAUJ.js → chunk-3AVGIISI.js} +175 -11
- package/dist/chunk-3AVGIISI.js.map +1 -0
- package/dist/{chunk-YBOYDQU5.js → chunk-4AT7MAXU.js} +9 -3
- package/dist/chunk-4AT7MAXU.js.map +1 -0
- package/dist/chunk-5DNPTBGA.js +520 -0
- package/dist/chunk-5DNPTBGA.js.map +1 -0
- package/dist/{chunk-V5VSY64D.js → chunk-IZH6P7WL.js} +2 -2
- package/dist/{index-Qc3rcMrW.d.ts → index-BRT37RMX.d.ts} +21 -6
- package/dist/{index-9XU-qEO-.d.cts → index-Nn5el7W0.d.cts} +21 -6
- package/dist/index.cjs +717 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -48
- package/dist/index.d.ts +56 -48
- package/dist/index.js +55 -19
- package/dist/index.js.map +1 -1
- package/dist/rendering/index.cjs +179 -11
- package/dist/rendering/index.cjs.map +1 -1
- package/dist/rendering/index.d.cts +1 -1
- package/dist/rendering/index.d.ts +1 -1
- package/dist/rendering/index.js +2 -2
- package/dist/textEffects/index.cjs +8 -2
- package/dist/textEffects/index.cjs.map +1 -1
- package/dist/textEffects/index.js +2 -2
- package/package.json +6 -1
- package/dist/chunk-YBOYDQU5.js.map +0 -1
- package/dist/chunk-ZV3RQAUJ.js.map +0 -1
- /package/dist/{chunk-V5VSY64D.js.map → chunk-IZH6P7WL.js.map} +0 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caption Engine Types
|
|
3
|
+
*
|
|
4
|
+
* Canonical types for word-timed animated captions, shared identically
|
|
5
|
+
* between desktop (wgpu compositor, worker rasterizer, main-thread fallback)
|
|
6
|
+
* and @clypra-studio/engine.
|
|
7
|
+
*/
|
|
8
|
+
interface CaptionWord {
|
|
9
|
+
id: string;
|
|
10
|
+
text: string;
|
|
11
|
+
startMs: number;
|
|
12
|
+
endMs: number;
|
|
13
|
+
/** Gap in milliseconds to the start of the next word (or 0 if end-of-segment) */
|
|
14
|
+
gapToNextMs?: number;
|
|
15
|
+
}
|
|
16
|
+
interface CaptionCue {
|
|
17
|
+
id: string;
|
|
18
|
+
words: CaptionWord[];
|
|
19
|
+
text: string;
|
|
20
|
+
startMs: number;
|
|
21
|
+
endMs: number;
|
|
22
|
+
}
|
|
23
|
+
type CaptionPresetId = "classic-subtitle" | "karaoke-pop" | "bold-punch" | "clean-minimal" | "cinematic-gold" | "neon-glow";
|
|
24
|
+
interface CaptionPresetDefinition {
|
|
25
|
+
id: CaptionPresetId | string;
|
|
26
|
+
name: string;
|
|
27
|
+
fontFamily: string;
|
|
28
|
+
fontWeight: number;
|
|
29
|
+
fontStyle: "normal" | "italic";
|
|
30
|
+
fontSize: number;
|
|
31
|
+
letterSpacing: number;
|
|
32
|
+
lineHeight: number;
|
|
33
|
+
textTransform?: "none" | "uppercase" | "lowercase" | "capitalize";
|
|
34
|
+
textAlign: "left" | "center" | "right";
|
|
35
|
+
verticalAlign: "top" | "middle" | "bottom";
|
|
36
|
+
inactiveColor: string;
|
|
37
|
+
inactiveOpacity: number;
|
|
38
|
+
activeColor: string;
|
|
39
|
+
activeScale?: number;
|
|
40
|
+
activeWordAnim?: "none" | "pop" | "glow" | "bounce";
|
|
41
|
+
activeBackgroundColor?: string;
|
|
42
|
+
activeBackgroundPaddingX?: number;
|
|
43
|
+
activeBackgroundPaddingY?: number;
|
|
44
|
+
activeBackgroundBorderRadius?: number;
|
|
45
|
+
strokeEnabled: boolean;
|
|
46
|
+
strokeColor?: string;
|
|
47
|
+
strokeWidth?: number;
|
|
48
|
+
activeStrokeColor?: string;
|
|
49
|
+
activeStrokeWidth?: number;
|
|
50
|
+
shadowEnabled: boolean;
|
|
51
|
+
shadowColor?: string;
|
|
52
|
+
shadowBlur?: number;
|
|
53
|
+
shadowOffsetX?: number;
|
|
54
|
+
shadowOffsetY?: number;
|
|
55
|
+
backgroundEnabled: boolean;
|
|
56
|
+
backgroundColor?: string;
|
|
57
|
+
backgroundPaddingX?: number;
|
|
58
|
+
backgroundPaddingY?: number;
|
|
59
|
+
backgroundBorderRadius?: number;
|
|
60
|
+
glowEnabled?: boolean;
|
|
61
|
+
glowColor?: string;
|
|
62
|
+
glowBlur?: number;
|
|
63
|
+
}
|
|
64
|
+
interface CaptionBounds {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
}
|
|
70
|
+
interface CaptionWordBox {
|
|
71
|
+
wordIndex: number;
|
|
72
|
+
word: CaptionWord;
|
|
73
|
+
x: number;
|
|
74
|
+
y: number;
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
baselineY: number;
|
|
78
|
+
isActive: boolean;
|
|
79
|
+
}
|
|
80
|
+
interface CaptionLineLayout {
|
|
81
|
+
lineIndex: number;
|
|
82
|
+
text: string;
|
|
83
|
+
words: CaptionWordBox[];
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
x: number;
|
|
87
|
+
y: number;
|
|
88
|
+
}
|
|
89
|
+
interface CaptionRenderOptions {
|
|
90
|
+
cue: CaptionCue;
|
|
91
|
+
activeWordIndex: number;
|
|
92
|
+
preset: CaptionPresetDefinition;
|
|
93
|
+
canvasWidth: number;
|
|
94
|
+
canvasHeight: number;
|
|
95
|
+
scale?: number;
|
|
96
|
+
positionYRatio?: number;
|
|
97
|
+
}
|
|
98
|
+
interface CaptionRenderResult {
|
|
99
|
+
bounds: CaptionBounds;
|
|
100
|
+
wordBoxes: CaptionWordBox[];
|
|
101
|
+
lines: CaptionLineLayout[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Built-in Caption Presets (OFL Fonts Only)
|
|
106
|
+
*
|
|
107
|
+
* 6 production-grade typography presets for word-timed animated captions:
|
|
108
|
+
* 1. Classic Subtitle (Inter Variable, subtle stroke, bottom centered)
|
|
109
|
+
* 2. Karaoke Pop (Outfit Variable, active word highlight with scale 1.12x)
|
|
110
|
+
* 3. Bold Punch (Montserrat Variable, uppercase, thick stroke, drop shadow)
|
|
111
|
+
* 4. Clean Minimal (Inter Variable, rounded translucent pill box background)
|
|
112
|
+
* 5. Cinematic Gold (Outfit Variable, gold active fill #FBBF24, tracked letters)
|
|
113
|
+
* 6. Neon Glow (Montserrat Variable, vibrant cyan stroke #0891B2, glow blur)
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
declare const CAPTION_PRESET_CLASSIC_SUBTITLE: CaptionPresetDefinition;
|
|
117
|
+
declare const CAPTION_PRESET_KARAOKE_POP: CaptionPresetDefinition;
|
|
118
|
+
declare const CAPTION_PRESET_BOLD_PUNCH: CaptionPresetDefinition;
|
|
119
|
+
declare const CAPTION_PRESET_CLEAN_MINIMAL: CaptionPresetDefinition;
|
|
120
|
+
declare const CAPTION_PRESET_CINEMATIC_GOLD: CaptionPresetDefinition;
|
|
121
|
+
declare const CAPTION_PRESET_NEON_GLOW: CaptionPresetDefinition;
|
|
122
|
+
declare const BUILT_IN_CAPTION_PRESETS: Record<CaptionPresetId, CaptionPresetDefinition>;
|
|
123
|
+
declare function getCaptionPreset(idOrPreset: string | CaptionPresetDefinition | undefined): CaptionPresetDefinition;
|
|
124
|
+
/**
|
|
125
|
+
* Computes a fast deterministic 32-bit hash of a resolved CaptionPresetDefinition
|
|
126
|
+
* for use in sub-canvas bounding-box raster cache keys.
|
|
127
|
+
*/
|
|
128
|
+
declare function hashCaptionPreset(preset: CaptionPresetDefinition): string;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Caption Engine
|
|
132
|
+
*
|
|
133
|
+
* Handles layout geometry, pagination, word-timing evaluation, and
|
|
134
|
+
* cache key computation for word-timed animated captions.
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
declare const PAUSE_RELEASE_THRESHOLD_MS = 250;
|
|
138
|
+
declare const DEFAULT_MAX_WORDS_PER_LINE = 5;
|
|
139
|
+
declare const DEFAULT_MAX_LINES = 2;
|
|
140
|
+
declare const DEFAULT_PAUSE_BREAK_MS = 350;
|
|
141
|
+
interface CaptionPaginationConfig {
|
|
142
|
+
maxWordsPerLine?: number;
|
|
143
|
+
maxLines?: number;
|
|
144
|
+
pauseBreakMs?: number;
|
|
145
|
+
}
|
|
146
|
+
declare class CaptionEngine {
|
|
147
|
+
/**
|
|
148
|
+
* Paginates a flat stream of words into structured caption cues.
|
|
149
|
+
* Enforces max words per line, max lines, pause thresholds, and punctuation breaks.
|
|
150
|
+
*/
|
|
151
|
+
static paginateWords(words: CaptionWord[], config?: CaptionPaginationConfig): CaptionCue[];
|
|
152
|
+
/**
|
|
153
|
+
* Resolves the active word index within a cue for a given playback time in milliseconds.
|
|
154
|
+
* Returns -1 if no word is active or during the pause release window (> 250ms after speech ends).
|
|
155
|
+
*/
|
|
156
|
+
static resolveActiveWordIndex(cue: CaptionCue, currentTimeMs: number): number;
|
|
157
|
+
/**
|
|
158
|
+
* Builds the canonical raster cache key for a caption frame.
|
|
159
|
+
* Format: `caption:${clipId}:${segmentId}:${activeWordIndex}:${presetHash}:${fontLoaded}`
|
|
160
|
+
*/
|
|
161
|
+
static buildCacheKey(clipId: string, segmentId: string, activeWordIndex: number, preset: CaptionPresetDefinition, fontLoaded: boolean): string;
|
|
162
|
+
/**
|
|
163
|
+
* Computes multi-line word layout and bounding boxes for a cue.
|
|
164
|
+
*/
|
|
165
|
+
static computeLayout(ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, cue: CaptionCue, activeWordIndex: number, preset: CaptionPresetDefinition, canvasWidth: number, canvasHeight: number, scale?: number, positionYRatio?: number): {
|
|
166
|
+
bounds: CaptionBounds;
|
|
167
|
+
wordBoxes: CaptionWordBox[];
|
|
168
|
+
lines: CaptionLineLayout[];
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Caption Canvas Renderer
|
|
174
|
+
*
|
|
175
|
+
* Single source of truth for rendering word-timed animated captions.
|
|
176
|
+
* Consumed identically by:
|
|
177
|
+
* 1. Web Worker (templateRasterizer.worker.ts) for off-thread sub-canvas rasterization
|
|
178
|
+
* 2. Main-thread fallback (nativeTextPreview.ts) when Web Workers are unavailable or during export
|
|
179
|
+
* 3. @clypra-studio/engine in web and browser previews
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
declare function renderCaptionToCanvas(ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, options: CaptionRenderOptions): CaptionRenderResult;
|
|
183
|
+
|
|
184
|
+
export { BUILT_IN_CAPTION_PRESETS, CAPTION_PRESET_BOLD_PUNCH, CAPTION_PRESET_CINEMATIC_GOLD, CAPTION_PRESET_CLASSIC_SUBTITLE, CAPTION_PRESET_CLEAN_MINIMAL, CAPTION_PRESET_KARAOKE_POP, CAPTION_PRESET_NEON_GLOW, type CaptionBounds, type CaptionCue, CaptionEngine, type CaptionLineLayout, type CaptionPaginationConfig, type CaptionPresetDefinition, type CaptionPresetId, type CaptionRenderOptions, type CaptionRenderResult, type CaptionWord, type CaptionWordBox, DEFAULT_MAX_LINES, DEFAULT_MAX_WORDS_PER_LINE, DEFAULT_PAUSE_BREAK_MS, PAUSE_RELEASE_THRESHOLD_MS, getCaptionPreset, hashCaptionPreset, renderCaptionToCanvas };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caption Engine Types
|
|
3
|
+
*
|
|
4
|
+
* Canonical types for word-timed animated captions, shared identically
|
|
5
|
+
* between desktop (wgpu compositor, worker rasterizer, main-thread fallback)
|
|
6
|
+
* and @clypra-studio/engine.
|
|
7
|
+
*/
|
|
8
|
+
interface CaptionWord {
|
|
9
|
+
id: string;
|
|
10
|
+
text: string;
|
|
11
|
+
startMs: number;
|
|
12
|
+
endMs: number;
|
|
13
|
+
/** Gap in milliseconds to the start of the next word (or 0 if end-of-segment) */
|
|
14
|
+
gapToNextMs?: number;
|
|
15
|
+
}
|
|
16
|
+
interface CaptionCue {
|
|
17
|
+
id: string;
|
|
18
|
+
words: CaptionWord[];
|
|
19
|
+
text: string;
|
|
20
|
+
startMs: number;
|
|
21
|
+
endMs: number;
|
|
22
|
+
}
|
|
23
|
+
type CaptionPresetId = "classic-subtitle" | "karaoke-pop" | "bold-punch" | "clean-minimal" | "cinematic-gold" | "neon-glow";
|
|
24
|
+
interface CaptionPresetDefinition {
|
|
25
|
+
id: CaptionPresetId | string;
|
|
26
|
+
name: string;
|
|
27
|
+
fontFamily: string;
|
|
28
|
+
fontWeight: number;
|
|
29
|
+
fontStyle: "normal" | "italic";
|
|
30
|
+
fontSize: number;
|
|
31
|
+
letterSpacing: number;
|
|
32
|
+
lineHeight: number;
|
|
33
|
+
textTransform?: "none" | "uppercase" | "lowercase" | "capitalize";
|
|
34
|
+
textAlign: "left" | "center" | "right";
|
|
35
|
+
verticalAlign: "top" | "middle" | "bottom";
|
|
36
|
+
inactiveColor: string;
|
|
37
|
+
inactiveOpacity: number;
|
|
38
|
+
activeColor: string;
|
|
39
|
+
activeScale?: number;
|
|
40
|
+
activeWordAnim?: "none" | "pop" | "glow" | "bounce";
|
|
41
|
+
activeBackgroundColor?: string;
|
|
42
|
+
activeBackgroundPaddingX?: number;
|
|
43
|
+
activeBackgroundPaddingY?: number;
|
|
44
|
+
activeBackgroundBorderRadius?: number;
|
|
45
|
+
strokeEnabled: boolean;
|
|
46
|
+
strokeColor?: string;
|
|
47
|
+
strokeWidth?: number;
|
|
48
|
+
activeStrokeColor?: string;
|
|
49
|
+
activeStrokeWidth?: number;
|
|
50
|
+
shadowEnabled: boolean;
|
|
51
|
+
shadowColor?: string;
|
|
52
|
+
shadowBlur?: number;
|
|
53
|
+
shadowOffsetX?: number;
|
|
54
|
+
shadowOffsetY?: number;
|
|
55
|
+
backgroundEnabled: boolean;
|
|
56
|
+
backgroundColor?: string;
|
|
57
|
+
backgroundPaddingX?: number;
|
|
58
|
+
backgroundPaddingY?: number;
|
|
59
|
+
backgroundBorderRadius?: number;
|
|
60
|
+
glowEnabled?: boolean;
|
|
61
|
+
glowColor?: string;
|
|
62
|
+
glowBlur?: number;
|
|
63
|
+
}
|
|
64
|
+
interface CaptionBounds {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
}
|
|
70
|
+
interface CaptionWordBox {
|
|
71
|
+
wordIndex: number;
|
|
72
|
+
word: CaptionWord;
|
|
73
|
+
x: number;
|
|
74
|
+
y: number;
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
baselineY: number;
|
|
78
|
+
isActive: boolean;
|
|
79
|
+
}
|
|
80
|
+
interface CaptionLineLayout {
|
|
81
|
+
lineIndex: number;
|
|
82
|
+
text: string;
|
|
83
|
+
words: CaptionWordBox[];
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
x: number;
|
|
87
|
+
y: number;
|
|
88
|
+
}
|
|
89
|
+
interface CaptionRenderOptions {
|
|
90
|
+
cue: CaptionCue;
|
|
91
|
+
activeWordIndex: number;
|
|
92
|
+
preset: CaptionPresetDefinition;
|
|
93
|
+
canvasWidth: number;
|
|
94
|
+
canvasHeight: number;
|
|
95
|
+
scale?: number;
|
|
96
|
+
positionYRatio?: number;
|
|
97
|
+
}
|
|
98
|
+
interface CaptionRenderResult {
|
|
99
|
+
bounds: CaptionBounds;
|
|
100
|
+
wordBoxes: CaptionWordBox[];
|
|
101
|
+
lines: CaptionLineLayout[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Built-in Caption Presets (OFL Fonts Only)
|
|
106
|
+
*
|
|
107
|
+
* 6 production-grade typography presets for word-timed animated captions:
|
|
108
|
+
* 1. Classic Subtitle (Inter Variable, subtle stroke, bottom centered)
|
|
109
|
+
* 2. Karaoke Pop (Outfit Variable, active word highlight with scale 1.12x)
|
|
110
|
+
* 3. Bold Punch (Montserrat Variable, uppercase, thick stroke, drop shadow)
|
|
111
|
+
* 4. Clean Minimal (Inter Variable, rounded translucent pill box background)
|
|
112
|
+
* 5. Cinematic Gold (Outfit Variable, gold active fill #FBBF24, tracked letters)
|
|
113
|
+
* 6. Neon Glow (Montserrat Variable, vibrant cyan stroke #0891B2, glow blur)
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
declare const CAPTION_PRESET_CLASSIC_SUBTITLE: CaptionPresetDefinition;
|
|
117
|
+
declare const CAPTION_PRESET_KARAOKE_POP: CaptionPresetDefinition;
|
|
118
|
+
declare const CAPTION_PRESET_BOLD_PUNCH: CaptionPresetDefinition;
|
|
119
|
+
declare const CAPTION_PRESET_CLEAN_MINIMAL: CaptionPresetDefinition;
|
|
120
|
+
declare const CAPTION_PRESET_CINEMATIC_GOLD: CaptionPresetDefinition;
|
|
121
|
+
declare const CAPTION_PRESET_NEON_GLOW: CaptionPresetDefinition;
|
|
122
|
+
declare const BUILT_IN_CAPTION_PRESETS: Record<CaptionPresetId, CaptionPresetDefinition>;
|
|
123
|
+
declare function getCaptionPreset(idOrPreset: string | CaptionPresetDefinition | undefined): CaptionPresetDefinition;
|
|
124
|
+
/**
|
|
125
|
+
* Computes a fast deterministic 32-bit hash of a resolved CaptionPresetDefinition
|
|
126
|
+
* for use in sub-canvas bounding-box raster cache keys.
|
|
127
|
+
*/
|
|
128
|
+
declare function hashCaptionPreset(preset: CaptionPresetDefinition): string;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Caption Engine
|
|
132
|
+
*
|
|
133
|
+
* Handles layout geometry, pagination, word-timing evaluation, and
|
|
134
|
+
* cache key computation for word-timed animated captions.
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
declare const PAUSE_RELEASE_THRESHOLD_MS = 250;
|
|
138
|
+
declare const DEFAULT_MAX_WORDS_PER_LINE = 5;
|
|
139
|
+
declare const DEFAULT_MAX_LINES = 2;
|
|
140
|
+
declare const DEFAULT_PAUSE_BREAK_MS = 350;
|
|
141
|
+
interface CaptionPaginationConfig {
|
|
142
|
+
maxWordsPerLine?: number;
|
|
143
|
+
maxLines?: number;
|
|
144
|
+
pauseBreakMs?: number;
|
|
145
|
+
}
|
|
146
|
+
declare class CaptionEngine {
|
|
147
|
+
/**
|
|
148
|
+
* Paginates a flat stream of words into structured caption cues.
|
|
149
|
+
* Enforces max words per line, max lines, pause thresholds, and punctuation breaks.
|
|
150
|
+
*/
|
|
151
|
+
static paginateWords(words: CaptionWord[], config?: CaptionPaginationConfig): CaptionCue[];
|
|
152
|
+
/**
|
|
153
|
+
* Resolves the active word index within a cue for a given playback time in milliseconds.
|
|
154
|
+
* Returns -1 if no word is active or during the pause release window (> 250ms after speech ends).
|
|
155
|
+
*/
|
|
156
|
+
static resolveActiveWordIndex(cue: CaptionCue, currentTimeMs: number): number;
|
|
157
|
+
/**
|
|
158
|
+
* Builds the canonical raster cache key for a caption frame.
|
|
159
|
+
* Format: `caption:${clipId}:${segmentId}:${activeWordIndex}:${presetHash}:${fontLoaded}`
|
|
160
|
+
*/
|
|
161
|
+
static buildCacheKey(clipId: string, segmentId: string, activeWordIndex: number, preset: CaptionPresetDefinition, fontLoaded: boolean): string;
|
|
162
|
+
/**
|
|
163
|
+
* Computes multi-line word layout and bounding boxes for a cue.
|
|
164
|
+
*/
|
|
165
|
+
static computeLayout(ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, cue: CaptionCue, activeWordIndex: number, preset: CaptionPresetDefinition, canvasWidth: number, canvasHeight: number, scale?: number, positionYRatio?: number): {
|
|
166
|
+
bounds: CaptionBounds;
|
|
167
|
+
wordBoxes: CaptionWordBox[];
|
|
168
|
+
lines: CaptionLineLayout[];
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Caption Canvas Renderer
|
|
174
|
+
*
|
|
175
|
+
* Single source of truth for rendering word-timed animated captions.
|
|
176
|
+
* Consumed identically by:
|
|
177
|
+
* 1. Web Worker (templateRasterizer.worker.ts) for off-thread sub-canvas rasterization
|
|
178
|
+
* 2. Main-thread fallback (nativeTextPreview.ts) when Web Workers are unavailable or during export
|
|
179
|
+
* 3. @clypra-studio/engine in web and browser previews
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
declare function renderCaptionToCanvas(ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, options: CaptionRenderOptions): CaptionRenderResult;
|
|
183
|
+
|
|
184
|
+
export { BUILT_IN_CAPTION_PRESETS, CAPTION_PRESET_BOLD_PUNCH, CAPTION_PRESET_CINEMATIC_GOLD, CAPTION_PRESET_CLASSIC_SUBTITLE, CAPTION_PRESET_CLEAN_MINIMAL, CAPTION_PRESET_KARAOKE_POP, CAPTION_PRESET_NEON_GLOW, type CaptionBounds, type CaptionCue, CaptionEngine, type CaptionLineLayout, type CaptionPaginationConfig, type CaptionPresetDefinition, type CaptionPresetId, type CaptionRenderOptions, type CaptionRenderResult, type CaptionWord, type CaptionWordBox, DEFAULT_MAX_LINES, DEFAULT_MAX_WORDS_PER_LINE, DEFAULT_PAUSE_BREAK_MS, PAUSE_RELEASE_THRESHOLD_MS, getCaptionPreset, hashCaptionPreset, renderCaptionToCanvas };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BUILT_IN_CAPTION_PRESETS,
|
|
3
|
+
CAPTION_PRESET_BOLD_PUNCH,
|
|
4
|
+
CAPTION_PRESET_CINEMATIC_GOLD,
|
|
5
|
+
CAPTION_PRESET_CLASSIC_SUBTITLE,
|
|
6
|
+
CAPTION_PRESET_CLEAN_MINIMAL,
|
|
7
|
+
CAPTION_PRESET_KARAOKE_POP,
|
|
8
|
+
CAPTION_PRESET_NEON_GLOW,
|
|
9
|
+
CaptionEngine,
|
|
10
|
+
DEFAULT_MAX_LINES,
|
|
11
|
+
DEFAULT_MAX_WORDS_PER_LINE,
|
|
12
|
+
DEFAULT_PAUSE_BREAK_MS,
|
|
13
|
+
PAUSE_RELEASE_THRESHOLD_MS,
|
|
14
|
+
getCaptionPreset,
|
|
15
|
+
hashCaptionPreset,
|
|
16
|
+
renderCaptionToCanvas
|
|
17
|
+
} from "../chunk-5DNPTBGA.js";
|
|
18
|
+
export {
|
|
19
|
+
BUILT_IN_CAPTION_PRESETS,
|
|
20
|
+
CAPTION_PRESET_BOLD_PUNCH,
|
|
21
|
+
CAPTION_PRESET_CINEMATIC_GOLD,
|
|
22
|
+
CAPTION_PRESET_CLASSIC_SUBTITLE,
|
|
23
|
+
CAPTION_PRESET_CLEAN_MINIMAL,
|
|
24
|
+
CAPTION_PRESET_KARAOKE_POP,
|
|
25
|
+
CAPTION_PRESET_NEON_GLOW,
|
|
26
|
+
CaptionEngine,
|
|
27
|
+
DEFAULT_MAX_LINES,
|
|
28
|
+
DEFAULT_MAX_WORDS_PER_LINE,
|
|
29
|
+
DEFAULT_PAUSE_BREAK_MS,
|
|
30
|
+
PAUSE_RELEASE_THRESHOLD_MS,
|
|
31
|
+
getCaptionPreset,
|
|
32
|
+
hashCaptionPreset,
|
|
33
|
+
renderCaptionToCanvas
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
evaluateScene,
|
|
7
7
|
sceneToConfig,
|
|
8
8
|
textEffectConfigToScene
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-4AT7MAXU.js";
|
|
10
10
|
|
|
11
11
|
// src/templates/keyframes.ts
|
|
12
12
|
function cubicBezier(x1, y1, x2, y2) {
|
|
@@ -547,7 +547,7 @@ function getRenderCapabilities(plan, target) {
|
|
|
547
547
|
// src/textTemplates/contract.ts
|
|
548
548
|
var TEXT_TEMPLATE_KIND = "text-template";
|
|
549
549
|
var TEXT_TEMPLATE_SCHEMA_VERSION = 4;
|
|
550
|
-
var TEXT_TEMPLATE_RENDERER_VERSION = "1.
|
|
550
|
+
var TEXT_TEMPLATE_RENDERER_VERSION = "1.6.0";
|
|
551
551
|
|
|
552
552
|
// src/rendering/textEffectRenderer.ts
|
|
553
553
|
function isScene(value) {
|
|
@@ -582,7 +582,90 @@ function renderTextEffectToCanvas(ctx, input) {
|
|
|
582
582
|
// src/textTemplates/validator.ts
|
|
583
583
|
var MAX_NODES = 500;
|
|
584
584
|
var MAX_CONTROLS = 100;
|
|
585
|
-
|
|
585
|
+
var MAX_ADDITIONAL_TARGETS = 16;
|
|
586
|
+
var UNSAFE_PATH_PARTS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
587
|
+
function readPath(target, path) {
|
|
588
|
+
if (!path || path.split(".").some((part) => UNSAFE_PATH_PARTS.has(part))) return { exists: false };
|
|
589
|
+
let cursor = target;
|
|
590
|
+
for (const part of path.split(".")) {
|
|
591
|
+
if (!cursor || typeof cursor !== "object" || !Object.prototype.hasOwnProperty.call(cursor, part)) return { exists: false };
|
|
592
|
+
cursor = cursor[part];
|
|
593
|
+
}
|
|
594
|
+
return { exists: true, value: cursor };
|
|
595
|
+
}
|
|
596
|
+
function valueType(value) {
|
|
597
|
+
if (value === null) return "null";
|
|
598
|
+
if (typeof value === "string") return "string";
|
|
599
|
+
if (typeof value === "number") return "number";
|
|
600
|
+
if (typeof value === "boolean") return "boolean";
|
|
601
|
+
return "other";
|
|
602
|
+
}
|
|
603
|
+
function controlTypeMatches(control, value) {
|
|
604
|
+
switch (control.type) {
|
|
605
|
+
case "text":
|
|
606
|
+
case "color":
|
|
607
|
+
case "enum":
|
|
608
|
+
case "font":
|
|
609
|
+
case "media":
|
|
610
|
+
return typeof value === "string";
|
|
611
|
+
case "number":
|
|
612
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
613
|
+
case "boolean":
|
|
614
|
+
return typeof value === "boolean";
|
|
615
|
+
default:
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
function transformedDefaultValue(control, target) {
|
|
620
|
+
const transform = target.transform;
|
|
621
|
+
if (!transform) return control.defaultValue;
|
|
622
|
+
if (transform.kind === "linear" && typeof control.defaultValue === "number") {
|
|
623
|
+
return control.defaultValue * transform.scale + transform.offset;
|
|
624
|
+
}
|
|
625
|
+
if (transform.kind === "enumMap" && typeof control.defaultValue === "string" && Object.prototype.hasOwnProperty.call(transform.values, control.defaultValue)) {
|
|
626
|
+
return transform.values[control.defaultValue];
|
|
627
|
+
}
|
|
628
|
+
return void 0;
|
|
629
|
+
}
|
|
630
|
+
function validateTargetTransform(control, target, currentValue, diagnostics, path) {
|
|
631
|
+
const transform = target.transform;
|
|
632
|
+
if (!transform) {
|
|
633
|
+
if (!controlTypeMatches(control, currentValue)) {
|
|
634
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TARGET_TYPE", message: `Control ${control.id} value type does not match ${target.propertyPath}`, nodeId: target.nodeId });
|
|
635
|
+
}
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (transform.kind === "linear") {
|
|
639
|
+
if (control.type !== "number" || typeof currentValue !== "number" || !Number.isFinite(transform.scale) || !Number.isFinite(transform.offset)) {
|
|
640
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TRANSFORM", message: `Control ${control.id} linear transforms require a numeric control, numeric target, scale, and offset`, nodeId: target.nodeId });
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
if (transform.kind === "enumMap") {
|
|
646
|
+
const values = transform.values;
|
|
647
|
+
if (control.type !== "enum" || !values || typeof values !== "object" || Array.isArray(values)) {
|
|
648
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TRANSFORM", message: `Control ${control.id} enumMap transforms require an enum control and values object`, nodeId: target.nodeId });
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
const targetType = valueType(currentValue);
|
|
652
|
+
for (const mappedValue of Object.values(values)) {
|
|
653
|
+
if (valueType(mappedValue) !== targetType) {
|
|
654
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TRANSFORM", message: `Control ${control.id} enumMap values must match the target property type`, nodeId: target.nodeId });
|
|
655
|
+
break;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
if (control.constraints?.options?.some((option) => !Object.prototype.hasOwnProperty.call(values, option.value))) {
|
|
659
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TRANSFORM", message: `Control ${control.id} enumMap must cover every enum option`, nodeId: target.nodeId });
|
|
660
|
+
}
|
|
661
|
+
if (transformedDefaultValue(control, target) === void 0) {
|
|
662
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TRANSFORM", message: `Control ${control.id} enumMap must map its default value`, nodeId: target.nodeId });
|
|
663
|
+
}
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TRANSFORM", message: `Control ${control.id} has an unknown transform kind`, nodeId: target.nodeId });
|
|
667
|
+
}
|
|
668
|
+
function validateTextTemplateArtifact(artifact, options = {}) {
|
|
586
669
|
const diagnostics = [];
|
|
587
670
|
if (!artifact || artifact.kind !== "text-template") {
|
|
588
671
|
return [{ severity: "error", code: "TEMPLATE_KIND", message: "Artifact kind must be text-template" }];
|
|
@@ -642,16 +725,51 @@ function validateTextTemplateArtifact(artifact) {
|
|
|
642
725
|
diagnostics.push({ severity: "error", code: "CONTROL_LIMIT", message: `Template exceeds the ${MAX_CONTROLS}-control limit` });
|
|
643
726
|
}
|
|
644
727
|
const controlIds = /* @__PURE__ */ new Set();
|
|
728
|
+
const targetOwners = /* @__PURE__ */ new Map();
|
|
645
729
|
for (const control of controls || []) {
|
|
646
730
|
if (controlIds.has(control.id)) {
|
|
647
731
|
diagnostics.push({ severity: "error", code: "DUPLICATE_CONTROL_ID", message: `Duplicate control ID: ${control.id}` });
|
|
648
732
|
}
|
|
649
733
|
controlIds.add(control.id);
|
|
650
|
-
if (
|
|
651
|
-
diagnostics.push({ severity: "error", code: "
|
|
734
|
+
if (control.target.transform !== void 0) {
|
|
735
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TRANSFORM", message: `Control ${control.id} primary target cannot have a transform` });
|
|
736
|
+
}
|
|
737
|
+
if (control.additionalTargets !== void 0 && !Array.isArray(control.additionalTargets)) {
|
|
738
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TARGETS", message: `Control ${control.id} additionalTargets must be an array` });
|
|
739
|
+
continue;
|
|
652
740
|
}
|
|
653
|
-
|
|
654
|
-
|
|
741
|
+
const targets = [
|
|
742
|
+
{ target: control.target, primary: true },
|
|
743
|
+
...(control.additionalTargets || []).map((target) => ({ target, primary: false }))
|
|
744
|
+
];
|
|
745
|
+
if ((control.additionalTargets || []).length > MAX_ADDITIONAL_TARGETS) {
|
|
746
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TARGET_LIMIT", message: `Control ${control.id} exceeds the ${MAX_ADDITIONAL_TARGETS}-additional-target limit` });
|
|
747
|
+
}
|
|
748
|
+
for (const { target, primary } of targets) {
|
|
749
|
+
const targetPath = `${control.id}.${primary ? "target" : "additionalTargets"}`;
|
|
750
|
+
if (!ids.has(target.nodeId)) {
|
|
751
|
+
diagnostics.push({ severity: "error", code: primary ? "CONTROL_TARGET" : "CONTROL_ADDITIONAL_TARGET", message: `Control ${control.id} targets missing node ${target.nodeId}` });
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
if (!target.propertyPath || target.propertyPath.split(".").some((part) => UNSAFE_PATH_PARTS.has(part))) {
|
|
755
|
+
diagnostics.push({ severity: "error", code: "UNSAFE_TARGET", message: `Control ${control.id} has an unsafe target path` });
|
|
756
|
+
continue;
|
|
757
|
+
}
|
|
758
|
+
const key = `${target.nodeId}\0${target.propertyPath}`;
|
|
759
|
+
const owner = targetOwners.get(key);
|
|
760
|
+
if (owner) {
|
|
761
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TARGET_CONFLICT", message: `Controls ${owner} and ${control.id} write the same target ${target.nodeId}.${target.propertyPath}` });
|
|
762
|
+
} else {
|
|
763
|
+
targetOwners.set(key, control.id);
|
|
764
|
+
}
|
|
765
|
+
const node = (document.nodes || []).find((candidate) => candidate.id === target.nodeId);
|
|
766
|
+
const resolved = node ? readPath(node, target.propertyPath) : { exists: false };
|
|
767
|
+
if (primary && !options.strictControlTargets) continue;
|
|
768
|
+
if (!resolved.exists) {
|
|
769
|
+
diagnostics.push({ severity: "error", code: "CONTROL_PROPERTY_PATH", message: `Control ${control.id} targets a missing property ${target.propertyPath}`, nodeId: target.nodeId });
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
validateTargetTransform(control, target, resolved.value, diagnostics, targetPath);
|
|
655
773
|
}
|
|
656
774
|
}
|
|
657
775
|
const regions = [timing.intro, timing.outro, timing.loop].filter(Boolean);
|
|
@@ -662,8 +780,8 @@ function validateTextTemplateArtifact(artifact) {
|
|
|
662
780
|
});
|
|
663
781
|
return diagnostics;
|
|
664
782
|
}
|
|
665
|
-
function assertValidTextTemplateArtifact(artifact) {
|
|
666
|
-
const errors = validateTextTemplateArtifact(artifact).filter((diagnostic) => diagnostic.severity === "error");
|
|
783
|
+
function assertValidTextTemplateArtifact(artifact, options = {}) {
|
|
784
|
+
const errors = validateTextTemplateArtifact(artifact, options).filter((diagnostic) => diagnostic.severity === "error");
|
|
667
785
|
if (errors.length) {
|
|
668
786
|
throw new Error(errors.map((diagnostic) => diagnostic.message).join("; "));
|
|
669
787
|
}
|
|
@@ -1192,6 +1310,27 @@ function resolveTemplateControlValues(artifact, optionsOrCustomization, fallback
|
|
|
1192
1310
|
return values;
|
|
1193
1311
|
}
|
|
1194
1312
|
|
|
1313
|
+
// src/textTemplates/compatibility.ts
|
|
1314
|
+
function versionParts(version) {
|
|
1315
|
+
return version.split(".").map((part) => Number.parseInt(part, 10)).map((part) => Number.isFinite(part) ? part : 0);
|
|
1316
|
+
}
|
|
1317
|
+
function isTextTemplateRendererVersionNewer(required, current = TEXT_TEMPLATE_RENDERER_VERSION) {
|
|
1318
|
+
const requiredParts = versionParts(required);
|
|
1319
|
+
const currentParts = versionParts(current);
|
|
1320
|
+
for (let index = 0; index < Math.max(requiredParts.length, currentParts.length); index += 1) {
|
|
1321
|
+
const requiredPart = requiredParts[index] ?? 0;
|
|
1322
|
+
const currentPart = currentParts[index] ?? 0;
|
|
1323
|
+
if (requiredPart !== currentPart) return requiredPart > currentPart;
|
|
1324
|
+
}
|
|
1325
|
+
return false;
|
|
1326
|
+
}
|
|
1327
|
+
function assertCompatibleTextTemplateRenderer(artifact, current = TEXT_TEMPLATE_RENDERER_VERSION) {
|
|
1328
|
+
const required = artifact.revision?.rendererVersion;
|
|
1329
|
+
if (required && isTextTemplateRendererVersionNewer(required, current)) {
|
|
1330
|
+
throw new Error(`Text template requires renderer ${required}, but this engine supports ${current}`);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1195
1334
|
// src/textTemplates/compiler.ts
|
|
1196
1335
|
function clone3(value) {
|
|
1197
1336
|
return JSON.parse(JSON.stringify(value));
|
|
@@ -1215,6 +1354,20 @@ function setPath(target, path, value) {
|
|
|
1215
1354
|
}
|
|
1216
1355
|
cursor[parts[parts.length - 1]] = value;
|
|
1217
1356
|
}
|
|
1357
|
+
function transformTargetValue(value, target, fallback) {
|
|
1358
|
+
const transform = target.transform;
|
|
1359
|
+
if (!transform) return value;
|
|
1360
|
+
if (transform.kind === "linear") {
|
|
1361
|
+
return typeof value === "number" && Number.isFinite(value) ? value * transform.scale + transform.offset : value;
|
|
1362
|
+
}
|
|
1363
|
+
if (transform.kind === "enumMap" && typeof value === "string" && Object.prototype.hasOwnProperty.call(transform.values, value)) {
|
|
1364
|
+
return transform.values[value];
|
|
1365
|
+
}
|
|
1366
|
+
if (transform.kind === "enumMap" && typeof fallback === "string" && Object.prototype.hasOwnProperty.call(transform.values, fallback)) {
|
|
1367
|
+
return transform.values[fallback];
|
|
1368
|
+
}
|
|
1369
|
+
return value;
|
|
1370
|
+
}
|
|
1218
1371
|
function finite(value, fallback) {
|
|
1219
1372
|
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
1220
1373
|
}
|
|
@@ -1262,6 +1415,8 @@ function resolveControls(controls, values) {
|
|
|
1262
1415
|
) : control.defaultValue;
|
|
1263
1416
|
} else if (control.type === "boolean") {
|
|
1264
1417
|
resolved[control.id] = value === true;
|
|
1418
|
+
} else if (control.type === "enum" && control.constraints?.options && !control.constraints.options.some((option) => option.value === value)) {
|
|
1419
|
+
resolved[control.id] = control.defaultValue;
|
|
1265
1420
|
} else {
|
|
1266
1421
|
resolved[control.id] = value;
|
|
1267
1422
|
}
|
|
@@ -1393,11 +1548,18 @@ function evaluateNodeProperty(node, property, fallback, time, duration) {
|
|
|
1393
1548
|
}
|
|
1394
1549
|
function compileTextTemplate(artifact, context) {
|
|
1395
1550
|
assertValidTextTemplateArtifact(artifact);
|
|
1551
|
+
assertCompatibleTextTemplateRenderer(artifact);
|
|
1396
1552
|
const resolvedControls = resolveControls(artifact.controls, context.controlValues);
|
|
1397
1553
|
const document = clone3(artifact.document);
|
|
1398
1554
|
for (const control of artifact.controls || []) {
|
|
1399
1555
|
const node = findNode(document.nodes, control.target.nodeId);
|
|
1400
1556
|
if (node) setPath(node, control.target.propertyPath, resolvedControls[control.id]);
|
|
1557
|
+
for (const target of control.additionalTargets || []) {
|
|
1558
|
+
const additionalNode = findNode(document.nodes, target.nodeId);
|
|
1559
|
+
if (additionalNode) {
|
|
1560
|
+
setPath(additionalNode, target.propertyPath, transformTargetValue(resolvedControls[control.id], target, control.defaultValue));
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1401
1563
|
}
|
|
1402
1564
|
if (context.controlValues) {
|
|
1403
1565
|
for (const node of document.nodes || []) {
|
|
@@ -1508,7 +1670,7 @@ function compileTextTemplate(artifact, context) {
|
|
|
1508
1670
|
const measuredSize = node.type === "text" ? measureTextNode(node, context.runtime) : void 0;
|
|
1509
1671
|
const resolvedWidth = flexPos?.width ?? (node.width === "auto" ? measuredSize?.width ?? 1 : evaluateNodeProperty(node, "width", Number(node.width), time, artifact.timing.duration));
|
|
1510
1672
|
const resolvedHeight = flexPos?.height ?? (node.height === "auto" ? measuredSize?.height ?? 1 : evaluateNodeProperty(node, "height", Number(node.height), time, artifact.timing.duration));
|
|
1511
|
-
const baseOpacity = node.type === "
|
|
1673
|
+
const baseOpacity = node.type === "container" ? node.style?.opacity ?? 1 : 1;
|
|
1512
1674
|
return {
|
|
1513
1675
|
id: node.id,
|
|
1514
1676
|
type: node.type,
|
|
@@ -2714,6 +2876,8 @@ export {
|
|
|
2714
2876
|
resolveTemplateControlValues,
|
|
2715
2877
|
validateTextTemplateArtifact,
|
|
2716
2878
|
assertValidTextTemplateArtifact,
|
|
2879
|
+
isTextTemplateRendererVersionNewer,
|
|
2880
|
+
assertCompatibleTextTemplateRenderer,
|
|
2717
2881
|
compileTextTemplate,
|
|
2718
2882
|
renderTextEffectToCanvas,
|
|
2719
2883
|
resolveTextTemplateArtifact,
|
|
@@ -2738,4 +2902,4 @@ export {
|
|
|
2738
2902
|
validateBubbleAssetDefinition,
|
|
2739
2903
|
renderCanonicalToCanvas
|
|
2740
2904
|
};
|
|
2741
|
-
//# sourceMappingURL=chunk-
|
|
2905
|
+
//# sourceMappingURL=chunk-3AVGIISI.js.map
|