@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,520 @@
|
|
|
1
|
+
// src/captions/presets.ts
|
|
2
|
+
var CAPTION_PRESET_CLASSIC_SUBTITLE = {
|
|
3
|
+
id: "classic-subtitle",
|
|
4
|
+
name: "Classic Subtitle",
|
|
5
|
+
fontFamily: "Inter Variable",
|
|
6
|
+
fontWeight: 600,
|
|
7
|
+
fontStyle: "normal",
|
|
8
|
+
fontSize: 48,
|
|
9
|
+
letterSpacing: 0,
|
|
10
|
+
lineHeight: 1.25,
|
|
11
|
+
textTransform: "none",
|
|
12
|
+
textAlign: "center",
|
|
13
|
+
verticalAlign: "bottom",
|
|
14
|
+
inactiveColor: "#FFFFFF",
|
|
15
|
+
inactiveOpacity: 0.95,
|
|
16
|
+
activeColor: "#FFFFFF",
|
|
17
|
+
activeScale: 1,
|
|
18
|
+
strokeEnabled: true,
|
|
19
|
+
strokeColor: "#000000",
|
|
20
|
+
strokeWidth: 4,
|
|
21
|
+
shadowEnabled: true,
|
|
22
|
+
shadowColor: "rgba(0, 0, 0, 0.75)",
|
|
23
|
+
shadowBlur: 6,
|
|
24
|
+
shadowOffsetX: 0,
|
|
25
|
+
shadowOffsetY: 2,
|
|
26
|
+
backgroundEnabled: false
|
|
27
|
+
};
|
|
28
|
+
var CAPTION_PRESET_KARAOKE_POP = {
|
|
29
|
+
id: "karaoke-pop",
|
|
30
|
+
name: "Karaoke Pop",
|
|
31
|
+
fontFamily: "Outfit Variable",
|
|
32
|
+
fontWeight: 700,
|
|
33
|
+
fontStyle: "normal",
|
|
34
|
+
fontSize: 54,
|
|
35
|
+
letterSpacing: 0.5,
|
|
36
|
+
lineHeight: 1.3,
|
|
37
|
+
textTransform: "none",
|
|
38
|
+
textAlign: "center",
|
|
39
|
+
verticalAlign: "bottom",
|
|
40
|
+
inactiveColor: "#FFFFFF",
|
|
41
|
+
inactiveOpacity: 0.55,
|
|
42
|
+
activeColor: "#38BDF8",
|
|
43
|
+
activeScale: 1.12,
|
|
44
|
+
activeWordAnim: "pop",
|
|
45
|
+
strokeEnabled: true,
|
|
46
|
+
strokeColor: "#000000",
|
|
47
|
+
strokeWidth: 5,
|
|
48
|
+
shadowEnabled: true,
|
|
49
|
+
shadowColor: "rgba(0, 0, 0, 0.8)",
|
|
50
|
+
shadowBlur: 8,
|
|
51
|
+
shadowOffsetX: 0,
|
|
52
|
+
shadowOffsetY: 3,
|
|
53
|
+
backgroundEnabled: false
|
|
54
|
+
};
|
|
55
|
+
var CAPTION_PRESET_BOLD_PUNCH = {
|
|
56
|
+
id: "bold-punch",
|
|
57
|
+
name: "Bold Punch",
|
|
58
|
+
fontFamily: "Montserrat Variable",
|
|
59
|
+
fontWeight: 900,
|
|
60
|
+
fontStyle: "normal",
|
|
61
|
+
fontSize: 56,
|
|
62
|
+
letterSpacing: 1,
|
|
63
|
+
lineHeight: 1.2,
|
|
64
|
+
textTransform: "uppercase",
|
|
65
|
+
textAlign: "center",
|
|
66
|
+
verticalAlign: "bottom",
|
|
67
|
+
inactiveColor: "#FFFFFF",
|
|
68
|
+
inactiveOpacity: 0.6,
|
|
69
|
+
activeColor: "#E11D48",
|
|
70
|
+
activeScale: 1.08,
|
|
71
|
+
activeWordAnim: "pop",
|
|
72
|
+
strokeEnabled: true,
|
|
73
|
+
strokeColor: "#000000",
|
|
74
|
+
strokeWidth: 6,
|
|
75
|
+
shadowEnabled: true,
|
|
76
|
+
shadowColor: "rgba(0, 0, 0, 0.9)",
|
|
77
|
+
shadowBlur: 10,
|
|
78
|
+
shadowOffsetX: 3,
|
|
79
|
+
shadowOffsetY: 4,
|
|
80
|
+
backgroundEnabled: false
|
|
81
|
+
};
|
|
82
|
+
var CAPTION_PRESET_CLEAN_MINIMAL = {
|
|
83
|
+
id: "clean-minimal",
|
|
84
|
+
name: "Clean Minimal",
|
|
85
|
+
fontFamily: "Inter Variable",
|
|
86
|
+
fontWeight: 500,
|
|
87
|
+
fontStyle: "normal",
|
|
88
|
+
fontSize: 42,
|
|
89
|
+
letterSpacing: 0,
|
|
90
|
+
lineHeight: 1.3,
|
|
91
|
+
textTransform: "none",
|
|
92
|
+
textAlign: "center",
|
|
93
|
+
verticalAlign: "bottom",
|
|
94
|
+
inactiveColor: "#E2E8F0",
|
|
95
|
+
inactiveOpacity: 0.7,
|
|
96
|
+
activeColor: "#FFFFFF",
|
|
97
|
+
activeScale: 1,
|
|
98
|
+
strokeEnabled: false,
|
|
99
|
+
shadowEnabled: false,
|
|
100
|
+
backgroundEnabled: true,
|
|
101
|
+
backgroundColor: "rgba(15, 23, 42, 0.75)",
|
|
102
|
+
backgroundPaddingX: 20,
|
|
103
|
+
backgroundPaddingY: 10,
|
|
104
|
+
backgroundBorderRadius: 14
|
|
105
|
+
};
|
|
106
|
+
var CAPTION_PRESET_CINEMATIC_GOLD = {
|
|
107
|
+
id: "cinematic-gold",
|
|
108
|
+
name: "Cinematic Gold",
|
|
109
|
+
fontFamily: "Outfit Variable",
|
|
110
|
+
fontWeight: 600,
|
|
111
|
+
fontStyle: "normal",
|
|
112
|
+
fontSize: 48,
|
|
113
|
+
letterSpacing: 2,
|
|
114
|
+
lineHeight: 1.35,
|
|
115
|
+
textTransform: "none",
|
|
116
|
+
textAlign: "center",
|
|
117
|
+
verticalAlign: "bottom",
|
|
118
|
+
inactiveColor: "#E2E8F0",
|
|
119
|
+
inactiveOpacity: 0.55,
|
|
120
|
+
activeColor: "#FBBF24",
|
|
121
|
+
activeScale: 1.05,
|
|
122
|
+
strokeEnabled: true,
|
|
123
|
+
strokeColor: "#000000",
|
|
124
|
+
strokeWidth: 3.5,
|
|
125
|
+
shadowEnabled: true,
|
|
126
|
+
shadowColor: "rgba(251, 191, 36, 0.35)",
|
|
127
|
+
shadowBlur: 14,
|
|
128
|
+
shadowOffsetX: 0,
|
|
129
|
+
shadowOffsetY: 2,
|
|
130
|
+
backgroundEnabled: false
|
|
131
|
+
};
|
|
132
|
+
var CAPTION_PRESET_NEON_GLOW = {
|
|
133
|
+
id: "neon-glow",
|
|
134
|
+
name: "Neon Glow",
|
|
135
|
+
fontFamily: "Montserrat Variable",
|
|
136
|
+
fontWeight: 800,
|
|
137
|
+
fontStyle: "normal",
|
|
138
|
+
fontSize: 52,
|
|
139
|
+
letterSpacing: 1,
|
|
140
|
+
lineHeight: 1.25,
|
|
141
|
+
textTransform: "none",
|
|
142
|
+
textAlign: "center",
|
|
143
|
+
verticalAlign: "bottom",
|
|
144
|
+
inactiveColor: "#94A3B8",
|
|
145
|
+
inactiveOpacity: 0.5,
|
|
146
|
+
activeColor: "#22D3EE",
|
|
147
|
+
activeScale: 1.06,
|
|
148
|
+
activeWordAnim: "glow",
|
|
149
|
+
strokeEnabled: true,
|
|
150
|
+
strokeColor: "#0891B2",
|
|
151
|
+
strokeWidth: 4,
|
|
152
|
+
glowEnabled: true,
|
|
153
|
+
glowColor: "#06B6D4",
|
|
154
|
+
glowBlur: 16,
|
|
155
|
+
shadowEnabled: true,
|
|
156
|
+
shadowColor: "rgba(0, 0, 0, 0.8)",
|
|
157
|
+
shadowBlur: 8,
|
|
158
|
+
shadowOffsetX: 0,
|
|
159
|
+
shadowOffsetY: 2,
|
|
160
|
+
backgroundEnabled: false
|
|
161
|
+
};
|
|
162
|
+
var BUILT_IN_CAPTION_PRESETS = {
|
|
163
|
+
"classic-subtitle": CAPTION_PRESET_CLASSIC_SUBTITLE,
|
|
164
|
+
"karaoke-pop": CAPTION_PRESET_KARAOKE_POP,
|
|
165
|
+
"bold-punch": CAPTION_PRESET_BOLD_PUNCH,
|
|
166
|
+
"clean-minimal": CAPTION_PRESET_CLEAN_MINIMAL,
|
|
167
|
+
"cinematic-gold": CAPTION_PRESET_CINEMATIC_GOLD,
|
|
168
|
+
"neon-glow": CAPTION_PRESET_NEON_GLOW
|
|
169
|
+
};
|
|
170
|
+
function getCaptionPreset(idOrPreset) {
|
|
171
|
+
if (!idOrPreset) return CAPTION_PRESET_CLASSIC_SUBTITLE;
|
|
172
|
+
if (typeof idOrPreset === "object") return idOrPreset;
|
|
173
|
+
const match = BUILT_IN_CAPTION_PRESETS[idOrPreset];
|
|
174
|
+
return match ?? CAPTION_PRESET_CLASSIC_SUBTITLE;
|
|
175
|
+
}
|
|
176
|
+
function hashCaptionPreset(preset) {
|
|
177
|
+
const str = `${preset.id}:${preset.fontFamily}:${preset.fontWeight}:${preset.fontSize}:${preset.activeColor}:${preset.inactiveColor}:${preset.activeScale ?? 1}:${preset.strokeEnabled ? preset.strokeWidth : 0}:${preset.shadowEnabled ? preset.shadowBlur : 0}:${preset.backgroundEnabled ? preset.backgroundColor : ""}:${preset.glowEnabled ? preset.glowBlur : 0}`;
|
|
178
|
+
let hash = 2166136261;
|
|
179
|
+
for (let i = 0; i < str.length; i++) {
|
|
180
|
+
hash ^= str.charCodeAt(i);
|
|
181
|
+
hash = Math.imul(hash, 16777619);
|
|
182
|
+
}
|
|
183
|
+
return (hash >>> 0).toString(16);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/captions/engine.ts
|
|
187
|
+
var PAUSE_RELEASE_THRESHOLD_MS = 250;
|
|
188
|
+
var DEFAULT_MAX_WORDS_PER_LINE = 5;
|
|
189
|
+
var DEFAULT_MAX_LINES = 2;
|
|
190
|
+
var DEFAULT_PAUSE_BREAK_MS = 350;
|
|
191
|
+
var CaptionEngine = class {
|
|
192
|
+
/**
|
|
193
|
+
* Paginates a flat stream of words into structured caption cues.
|
|
194
|
+
* Enforces max words per line, max lines, pause thresholds, and punctuation breaks.
|
|
195
|
+
*/
|
|
196
|
+
static paginateWords(words, config = {}) {
|
|
197
|
+
if (!words.length) return [];
|
|
198
|
+
const maxWordsPerLine = config.maxWordsPerLine ?? DEFAULT_MAX_WORDS_PER_LINE;
|
|
199
|
+
const maxLines = config.maxLines ?? DEFAULT_MAX_LINES;
|
|
200
|
+
const maxWordsPerCue = maxWordsPerLine * maxLines;
|
|
201
|
+
const pauseBreakMs = config.pauseBreakMs ?? DEFAULT_PAUSE_BREAK_MS;
|
|
202
|
+
const cues = [];
|
|
203
|
+
let currentCueWords = [];
|
|
204
|
+
for (let i = 0; i < words.length; i++) {
|
|
205
|
+
const currentWord = words[i];
|
|
206
|
+
const nextWord = words[i + 1];
|
|
207
|
+
currentCueWords.push(currentWord);
|
|
208
|
+
const hasReachedMaxWords = currentCueWords.length >= maxWordsPerCue;
|
|
209
|
+
const isTerminalPunctuation = /[.!?]$/.test(currentWord.text.trim());
|
|
210
|
+
const hasPauseBreak = nextWord && nextWord.startMs - currentWord.endMs >= pauseBreakMs;
|
|
211
|
+
const isLastWord = i === words.length - 1;
|
|
212
|
+
if (hasReachedMaxWords || isTerminalPunctuation || hasPauseBreak || isLastWord) {
|
|
213
|
+
const text = currentCueWords.map((w) => w.text).join(" ");
|
|
214
|
+
const startMs = currentCueWords[0].startMs;
|
|
215
|
+
const endMs = currentCueWords[currentCueWords.length - 1].endMs;
|
|
216
|
+
const id = `cue_${startMs}_${endMs}`;
|
|
217
|
+
cues.push({
|
|
218
|
+
id,
|
|
219
|
+
words: [...currentCueWords],
|
|
220
|
+
text,
|
|
221
|
+
startMs,
|
|
222
|
+
endMs
|
|
223
|
+
});
|
|
224
|
+
currentCueWords = [];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return cues;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Resolves the active word index within a cue for a given playback time in milliseconds.
|
|
231
|
+
* Returns -1 if no word is active or during the pause release window (> 250ms after speech ends).
|
|
232
|
+
*/
|
|
233
|
+
static resolveActiveWordIndex(cue, currentTimeMs) {
|
|
234
|
+
if (!cue.words.length) return -1;
|
|
235
|
+
if (currentTimeMs < cue.words[0].startMs) return -1;
|
|
236
|
+
for (let i = 0; i < cue.words.length; i++) {
|
|
237
|
+
const w = cue.words[i];
|
|
238
|
+
const nextWord = cue.words[i + 1];
|
|
239
|
+
if (currentTimeMs >= w.startMs && currentTimeMs < w.endMs) {
|
|
240
|
+
return i;
|
|
241
|
+
}
|
|
242
|
+
if (currentTimeMs >= w.endMs && nextWord && currentTimeMs < nextWord.startMs) {
|
|
243
|
+
const gap = nextWord.startMs - w.endMs;
|
|
244
|
+
if (gap <= PAUSE_RELEASE_THRESHOLD_MS) {
|
|
245
|
+
return i;
|
|
246
|
+
}
|
|
247
|
+
if (currentTimeMs < w.endMs + PAUSE_RELEASE_THRESHOLD_MS) {
|
|
248
|
+
return i;
|
|
249
|
+
}
|
|
250
|
+
return -1;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const lastWord = cue.words[cue.words.length - 1];
|
|
254
|
+
if (currentTimeMs >= lastWord.endMs) {
|
|
255
|
+
if (currentTimeMs < lastWord.endMs + PAUSE_RELEASE_THRESHOLD_MS) {
|
|
256
|
+
return cue.words.length - 1;
|
|
257
|
+
}
|
|
258
|
+
return -1;
|
|
259
|
+
}
|
|
260
|
+
return -1;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Builds the canonical raster cache key for a caption frame.
|
|
264
|
+
* Format: `caption:${clipId}:${segmentId}:${activeWordIndex}:${presetHash}:${fontLoaded}`
|
|
265
|
+
*/
|
|
266
|
+
static buildCacheKey(clipId, segmentId, activeWordIndex, preset, fontLoaded) {
|
|
267
|
+
const presetHash = hashCaptionPreset(preset);
|
|
268
|
+
return `caption:${clipId}:${segmentId}:${activeWordIndex}:${presetHash}:${fontLoaded ? 1 : 0}`;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Computes multi-line word layout and bounding boxes for a cue.
|
|
272
|
+
*/
|
|
273
|
+
static computeLayout(ctx, cue, activeWordIndex, preset, canvasWidth, canvasHeight, scale = 1, positionYRatio = 0.85) {
|
|
274
|
+
const fontSize = Math.round(preset.fontSize * scale);
|
|
275
|
+
const lineHeight = fontSize * preset.lineHeight;
|
|
276
|
+
const fontStr = `${preset.fontStyle} ${preset.fontWeight} ${fontSize}px "${preset.fontFamily}", sans-serif`;
|
|
277
|
+
ctx.font = fontStr;
|
|
278
|
+
const maxLineWidth = Math.max(200, canvasWidth * 0.85);
|
|
279
|
+
const spaceWidth = ctx.measureText(" ").width;
|
|
280
|
+
const lines = [];
|
|
281
|
+
let curLineWords = [];
|
|
282
|
+
let curLineIndices = [];
|
|
283
|
+
let curLineWidths = [];
|
|
284
|
+
let curLineWidth = 0;
|
|
285
|
+
for (let i = 0; i < cue.words.length; i++) {
|
|
286
|
+
const word = cue.words[i];
|
|
287
|
+
const displayText = preset.textTransform === "uppercase" ? word.text.toUpperCase() : preset.textTransform === "lowercase" ? word.text.toLowerCase() : word.text;
|
|
288
|
+
const wWidth = ctx.measureText(displayText).width;
|
|
289
|
+
const neededWidth = curLineWidth === 0 ? wWidth : curLineWidth + spaceWidth + wWidth;
|
|
290
|
+
if (curLineWords.length > 0 && (neededWidth > maxLineWidth || curLineWords.length >= DEFAULT_MAX_WORDS_PER_LINE)) {
|
|
291
|
+
lines.push({
|
|
292
|
+
words: curLineWords,
|
|
293
|
+
indices: curLineIndices,
|
|
294
|
+
widths: curLineWidths
|
|
295
|
+
});
|
|
296
|
+
curLineWords = [word];
|
|
297
|
+
curLineIndices = [i];
|
|
298
|
+
curLineWidths = [wWidth];
|
|
299
|
+
curLineWidth = wWidth;
|
|
300
|
+
} else {
|
|
301
|
+
curLineWords.push(word);
|
|
302
|
+
curLineIndices.push(i);
|
|
303
|
+
curLineWidths.push(wWidth);
|
|
304
|
+
curLineWidth = neededWidth;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (curLineWords.length > 0) {
|
|
308
|
+
lines.push({
|
|
309
|
+
words: curLineWords,
|
|
310
|
+
indices: curLineIndices,
|
|
311
|
+
widths: curLineWidths
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
const totalHeight = lines.length * lineHeight;
|
|
315
|
+
const anchorCenterY = canvasHeight * positionYRatio;
|
|
316
|
+
const startY = anchorCenterY - totalHeight / 2;
|
|
317
|
+
const allWordBoxes = [];
|
|
318
|
+
const lineLayouts = [];
|
|
319
|
+
let overallMinX = Infinity;
|
|
320
|
+
let overallMinY = Infinity;
|
|
321
|
+
let overallMaxX = -Infinity;
|
|
322
|
+
let overallMaxY = -Infinity;
|
|
323
|
+
for (let l = 0; l < lines.length; l++) {
|
|
324
|
+
const line = lines[l];
|
|
325
|
+
const lineWidth = line.widths.reduce((a, b) => a + b, 0) + (line.words.length - 1) * spaceWidth;
|
|
326
|
+
const lineY = startY + l * lineHeight;
|
|
327
|
+
const baselineY = lineY + fontSize * 0.82;
|
|
328
|
+
let startX = (canvasWidth - lineWidth) / 2;
|
|
329
|
+
if (preset.textAlign === "left") {
|
|
330
|
+
startX = canvasWidth * 0.08;
|
|
331
|
+
} else if (preset.textAlign === "right") {
|
|
332
|
+
startX = canvasWidth * 0.92 - lineWidth;
|
|
333
|
+
}
|
|
334
|
+
let curX = startX;
|
|
335
|
+
const lineBoxes = [];
|
|
336
|
+
for (let w = 0; w < line.words.length; w++) {
|
|
337
|
+
const word = line.words[w];
|
|
338
|
+
const wordIdx = line.indices[w];
|
|
339
|
+
const wWidth = line.widths[w];
|
|
340
|
+
const isActive = wordIdx === activeWordIndex;
|
|
341
|
+
const box = {
|
|
342
|
+
wordIndex: wordIdx,
|
|
343
|
+
word,
|
|
344
|
+
x: curX,
|
|
345
|
+
y: lineY,
|
|
346
|
+
width: wWidth,
|
|
347
|
+
height: lineHeight,
|
|
348
|
+
baselineY,
|
|
349
|
+
isActive
|
|
350
|
+
};
|
|
351
|
+
lineBoxes.push(box);
|
|
352
|
+
allWordBoxes.push(box);
|
|
353
|
+
overallMinX = Math.min(overallMinX, curX);
|
|
354
|
+
overallMinY = Math.min(overallMinY, lineY);
|
|
355
|
+
overallMaxX = Math.max(overallMaxX, curX + wWidth);
|
|
356
|
+
overallMaxY = Math.max(overallMaxY, lineY + lineHeight);
|
|
357
|
+
curX += wWidth + spaceWidth;
|
|
358
|
+
}
|
|
359
|
+
lineLayouts.push({
|
|
360
|
+
lineIndex: l,
|
|
361
|
+
text: line.words.map((w) => w.text).join(" "),
|
|
362
|
+
words: lineBoxes,
|
|
363
|
+
width: lineWidth,
|
|
364
|
+
height: lineHeight,
|
|
365
|
+
x: startX,
|
|
366
|
+
y: lineY
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
const strokeBleed = preset.strokeEnabled ? (preset.strokeWidth ?? 4) * scale : 0;
|
|
370
|
+
const shadowBleed = preset.shadowEnabled ? (preset.shadowBlur ?? 8) * scale : 0;
|
|
371
|
+
const glowBleed = preset.glowEnabled ? (preset.glowBlur ?? 16) * scale : 0;
|
|
372
|
+
const bgPadX = preset.backgroundEnabled ? (preset.backgroundPaddingX ?? 20) * scale : 0;
|
|
373
|
+
const bgPadY = preset.backgroundEnabled ? (preset.backgroundPaddingY ?? 10) * scale : 0;
|
|
374
|
+
const activeScaleBleed = fontSize * 0.25;
|
|
375
|
+
const padX = Math.ceil(Math.max(strokeBleed + shadowBleed + glowBleed + activeScaleBleed, bgPadX));
|
|
376
|
+
const padY = Math.ceil(Math.max(strokeBleed + shadowBleed + glowBleed + activeScaleBleed, bgPadY));
|
|
377
|
+
const bounds = {
|
|
378
|
+
x: Math.max(0, Math.floor(overallMinX - padX)),
|
|
379
|
+
y: Math.max(0, Math.floor(overallMinY - padY)),
|
|
380
|
+
width: Math.min(canvasWidth, Math.ceil(overallMaxX - overallMinX + padX * 2)),
|
|
381
|
+
height: Math.min(canvasHeight, Math.ceil(overallMaxY - overallMinY + padY * 2))
|
|
382
|
+
};
|
|
383
|
+
return { bounds, wordBoxes: allWordBoxes, lines: lineLayouts };
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
// src/captions/renderer.ts
|
|
388
|
+
function renderCaptionToCanvas(ctx, options) {
|
|
389
|
+
const {
|
|
390
|
+
cue,
|
|
391
|
+
activeWordIndex,
|
|
392
|
+
preset,
|
|
393
|
+
canvasWidth,
|
|
394
|
+
canvasHeight,
|
|
395
|
+
scale = 1,
|
|
396
|
+
positionYRatio = 0.85
|
|
397
|
+
} = options;
|
|
398
|
+
if (!cue.words || cue.words.length === 0) {
|
|
399
|
+
return {
|
|
400
|
+
bounds: { x: 0, y: 0, width: 0, height: 0 },
|
|
401
|
+
wordBoxes: [],
|
|
402
|
+
lines: []
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
const layout = CaptionEngine.computeLayout(
|
|
406
|
+
ctx,
|
|
407
|
+
cue,
|
|
408
|
+
activeWordIndex,
|
|
409
|
+
preset,
|
|
410
|
+
canvasWidth,
|
|
411
|
+
canvasHeight,
|
|
412
|
+
scale,
|
|
413
|
+
positionYRatio
|
|
414
|
+
);
|
|
415
|
+
const fontSize = Math.round(preset.fontSize * scale);
|
|
416
|
+
const fontStr = `${preset.fontStyle} ${preset.fontWeight} ${fontSize}px "${preset.fontFamily}", sans-serif`;
|
|
417
|
+
ctx.font = fontStr;
|
|
418
|
+
ctx.textBaseline = "alphabetic";
|
|
419
|
+
if (preset.backgroundEnabled && preset.backgroundColor) {
|
|
420
|
+
ctx.save();
|
|
421
|
+
ctx.fillStyle = preset.backgroundColor;
|
|
422
|
+
const padX = (preset.backgroundPaddingX ?? 18) * scale;
|
|
423
|
+
const padY = (preset.backgroundPaddingY ?? 8) * scale;
|
|
424
|
+
const radius = (preset.backgroundBorderRadius ?? 12) * scale;
|
|
425
|
+
for (const line of layout.lines) {
|
|
426
|
+
const bgX = line.x - padX;
|
|
427
|
+
const bgY = line.y - padY / 2;
|
|
428
|
+
const bgW = line.width + padX * 2;
|
|
429
|
+
const bgH = line.height + padY;
|
|
430
|
+
ctx.beginPath();
|
|
431
|
+
if (typeof ctx.roundRect === "function") {
|
|
432
|
+
ctx.roundRect(bgX, bgY, bgW, bgH, radius);
|
|
433
|
+
} else {
|
|
434
|
+
ctx.rect(bgX, bgY, bgW, bgH);
|
|
435
|
+
}
|
|
436
|
+
ctx.fill();
|
|
437
|
+
}
|
|
438
|
+
ctx.restore();
|
|
439
|
+
}
|
|
440
|
+
for (const box of layout.wordBoxes) {
|
|
441
|
+
ctx.save();
|
|
442
|
+
const displayText = preset.textTransform === "uppercase" ? box.word.text.toUpperCase() : preset.textTransform === "lowercase" ? box.word.text.toLowerCase() : box.word.text;
|
|
443
|
+
const isActive = box.isActive;
|
|
444
|
+
if (isActive && preset.activeBackgroundColor) {
|
|
445
|
+
ctx.save();
|
|
446
|
+
ctx.fillStyle = preset.activeBackgroundColor;
|
|
447
|
+
const padX = (preset.activeBackgroundPaddingX ?? 8) * scale;
|
|
448
|
+
const padY = (preset.activeBackgroundPaddingY ?? 4) * scale;
|
|
449
|
+
const radius = (preset.activeBackgroundBorderRadius ?? 5) * scale;
|
|
450
|
+
const bgX = box.x - padX;
|
|
451
|
+
const bgY = box.y - padY / 2;
|
|
452
|
+
const bgW = box.width + padX * 2;
|
|
453
|
+
const bgH = box.height + padY;
|
|
454
|
+
ctx.beginPath();
|
|
455
|
+
if (typeof ctx.roundRect === "function") ctx.roundRect(bgX, bgY, bgW, bgH, radius);
|
|
456
|
+
else ctx.rect(bgX, bgY, bgW, bgH);
|
|
457
|
+
ctx.fill();
|
|
458
|
+
ctx.restore();
|
|
459
|
+
}
|
|
460
|
+
if (isActive && preset.activeScale && preset.activeScale !== 1) {
|
|
461
|
+
const centerX = box.x + box.width / 2;
|
|
462
|
+
const centerY = box.y + box.height / 2;
|
|
463
|
+
ctx.translate(centerX, centerY);
|
|
464
|
+
ctx.scale(preset.activeScale, preset.activeScale);
|
|
465
|
+
ctx.translate(-centerX, -centerY);
|
|
466
|
+
}
|
|
467
|
+
if (isActive && preset.glowEnabled && preset.glowColor) {
|
|
468
|
+
ctx.shadowColor = preset.glowColor;
|
|
469
|
+
ctx.shadowBlur = (preset.glowBlur ?? 16) * scale;
|
|
470
|
+
ctx.shadowOffsetX = 0;
|
|
471
|
+
ctx.shadowOffsetY = 0;
|
|
472
|
+
} else if (preset.shadowEnabled && preset.shadowColor) {
|
|
473
|
+
ctx.shadowColor = preset.shadowColor;
|
|
474
|
+
ctx.shadowBlur = (preset.shadowBlur ?? 6) * scale;
|
|
475
|
+
ctx.shadowOffsetX = (preset.shadowOffsetX ?? 0) * scale;
|
|
476
|
+
ctx.shadowOffsetY = (preset.shadowOffsetY ?? 2) * scale;
|
|
477
|
+
} else {
|
|
478
|
+
ctx.shadowColor = "transparent";
|
|
479
|
+
ctx.shadowBlur = 0;
|
|
480
|
+
ctx.shadowOffsetX = 0;
|
|
481
|
+
ctx.shadowOffsetY = 0;
|
|
482
|
+
}
|
|
483
|
+
if (preset.strokeEnabled) {
|
|
484
|
+
ctx.lineWidth = (isActive && preset.activeStrokeWidth || preset.strokeWidth || 4) * scale;
|
|
485
|
+
ctx.strokeStyle = isActive && preset.activeStrokeColor || preset.strokeColor || "#000000";
|
|
486
|
+
ctx.lineJoin = "round";
|
|
487
|
+
ctx.miterLimit = 2;
|
|
488
|
+
ctx.strokeText(displayText, box.x, box.baselineY);
|
|
489
|
+
}
|
|
490
|
+
if (isActive) {
|
|
491
|
+
ctx.fillStyle = preset.activeColor;
|
|
492
|
+
ctx.globalAlpha = 1;
|
|
493
|
+
} else {
|
|
494
|
+
ctx.fillStyle = preset.inactiveColor;
|
|
495
|
+
ctx.globalAlpha = preset.inactiveOpacity;
|
|
496
|
+
}
|
|
497
|
+
ctx.fillText(displayText, box.x, box.baselineY);
|
|
498
|
+
ctx.restore();
|
|
499
|
+
}
|
|
500
|
+
return layout;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
export {
|
|
504
|
+
CAPTION_PRESET_CLASSIC_SUBTITLE,
|
|
505
|
+
CAPTION_PRESET_KARAOKE_POP,
|
|
506
|
+
CAPTION_PRESET_BOLD_PUNCH,
|
|
507
|
+
CAPTION_PRESET_CLEAN_MINIMAL,
|
|
508
|
+
CAPTION_PRESET_CINEMATIC_GOLD,
|
|
509
|
+
CAPTION_PRESET_NEON_GLOW,
|
|
510
|
+
BUILT_IN_CAPTION_PRESETS,
|
|
511
|
+
getCaptionPreset,
|
|
512
|
+
hashCaptionPreset,
|
|
513
|
+
PAUSE_RELEASE_THRESHOLD_MS,
|
|
514
|
+
DEFAULT_MAX_WORDS_PER_LINE,
|
|
515
|
+
DEFAULT_MAX_LINES,
|
|
516
|
+
DEFAULT_PAUSE_BREAK_MS,
|
|
517
|
+
CaptionEngine,
|
|
518
|
+
renderCaptionToCanvas
|
|
519
|
+
};
|
|
520
|
+
//# sourceMappingURL=chunk-5DNPTBGA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/captions/presets.ts","../src/captions/engine.ts","../src/captions/renderer.ts"],"sourcesContent":["/**\n * Built-in Caption Presets (OFL Fonts Only)\n *\n * 6 production-grade typography presets for word-timed animated captions:\n * 1. Classic Subtitle (Inter Variable, subtle stroke, bottom centered)\n * 2. Karaoke Pop (Outfit Variable, active word highlight with scale 1.12x)\n * 3. Bold Punch (Montserrat Variable, uppercase, thick stroke, drop shadow)\n * 4. Clean Minimal (Inter Variable, rounded translucent pill box background)\n * 5. Cinematic Gold (Outfit Variable, gold active fill #FBBF24, tracked letters)\n * 6. Neon Glow (Montserrat Variable, vibrant cyan stroke #0891B2, glow blur)\n */\n\nimport type { CaptionPresetDefinition, CaptionPresetId } from \"./types.js\";\n\nexport const CAPTION_PRESET_CLASSIC_SUBTITLE: CaptionPresetDefinition = {\n id: \"classic-subtitle\",\n name: \"Classic Subtitle\",\n fontFamily: \"Inter Variable\",\n fontWeight: 600,\n fontStyle: \"normal\",\n fontSize: 48,\n letterSpacing: 0,\n lineHeight: 1.25,\n textTransform: \"none\",\n textAlign: \"center\",\n verticalAlign: \"bottom\",\n inactiveColor: \"#FFFFFF\",\n inactiveOpacity: 0.95,\n activeColor: \"#FFFFFF\",\n activeScale: 1.0,\n strokeEnabled: true,\n strokeColor: \"#000000\",\n strokeWidth: 4,\n shadowEnabled: true,\n shadowColor: \"rgba(0, 0, 0, 0.75)\",\n shadowBlur: 6,\n shadowOffsetX: 0,\n shadowOffsetY: 2,\n backgroundEnabled: false,\n};\n\nexport const CAPTION_PRESET_KARAOKE_POP: CaptionPresetDefinition = {\n id: \"karaoke-pop\",\n name: \"Karaoke Pop\",\n fontFamily: \"Outfit Variable\",\n fontWeight: 700,\n fontStyle: \"normal\",\n fontSize: 54,\n letterSpacing: 0.5,\n lineHeight: 1.3,\n textTransform: \"none\",\n textAlign: \"center\",\n verticalAlign: \"bottom\",\n inactiveColor: \"#FFFFFF\",\n inactiveOpacity: 0.55,\n activeColor: \"#38BDF8\",\n activeScale: 1.12,\n activeWordAnim: \"pop\",\n strokeEnabled: true,\n strokeColor: \"#000000\",\n strokeWidth: 5,\n shadowEnabled: true,\n shadowColor: \"rgba(0, 0, 0, 0.8)\",\n shadowBlur: 8,\n shadowOffsetX: 0,\n shadowOffsetY: 3,\n backgroundEnabled: false,\n};\n\nexport const CAPTION_PRESET_BOLD_PUNCH: CaptionPresetDefinition = {\n id: \"bold-punch\",\n name: \"Bold Punch\",\n fontFamily: \"Montserrat Variable\",\n fontWeight: 900,\n fontStyle: \"normal\",\n fontSize: 56,\n letterSpacing: 1.0,\n lineHeight: 1.2,\n textTransform: \"uppercase\",\n textAlign: \"center\",\n verticalAlign: \"bottom\",\n inactiveColor: \"#FFFFFF\",\n inactiveOpacity: 0.6,\n activeColor: \"#E11D48\",\n activeScale: 1.08,\n activeWordAnim: \"pop\",\n strokeEnabled: true,\n strokeColor: \"#000000\",\n strokeWidth: 6,\n shadowEnabled: true,\n shadowColor: \"rgba(0, 0, 0, 0.9)\",\n shadowBlur: 10,\n shadowOffsetX: 3,\n shadowOffsetY: 4,\n backgroundEnabled: false,\n};\n\nexport const CAPTION_PRESET_CLEAN_MINIMAL: CaptionPresetDefinition = {\n id: \"clean-minimal\",\n name: \"Clean Minimal\",\n fontFamily: \"Inter Variable\",\n fontWeight: 500,\n fontStyle: \"normal\",\n fontSize: 42,\n letterSpacing: 0,\n lineHeight: 1.3,\n textTransform: \"none\",\n textAlign: \"center\",\n verticalAlign: \"bottom\",\n inactiveColor: \"#E2E8F0\",\n inactiveOpacity: 0.7,\n activeColor: \"#FFFFFF\",\n activeScale: 1.0,\n strokeEnabled: false,\n shadowEnabled: false,\n backgroundEnabled: true,\n backgroundColor: \"rgba(15, 23, 42, 0.75)\",\n backgroundPaddingX: 20,\n backgroundPaddingY: 10,\n backgroundBorderRadius: 14,\n};\n\nexport const CAPTION_PRESET_CINEMATIC_GOLD: CaptionPresetDefinition = {\n id: \"cinematic-gold\",\n name: \"Cinematic Gold\",\n fontFamily: \"Outfit Variable\",\n fontWeight: 600,\n fontStyle: \"normal\",\n fontSize: 48,\n letterSpacing: 2.0,\n lineHeight: 1.35,\n textTransform: \"none\",\n textAlign: \"center\",\n verticalAlign: \"bottom\",\n inactiveColor: \"#E2E8F0\",\n inactiveOpacity: 0.55,\n activeColor: \"#FBBF24\",\n activeScale: 1.05,\n strokeEnabled: true,\n strokeColor: \"#000000\",\n strokeWidth: 3.5,\n shadowEnabled: true,\n shadowColor: \"rgba(251, 191, 36, 0.35)\",\n shadowBlur: 14,\n shadowOffsetX: 0,\n shadowOffsetY: 2,\n backgroundEnabled: false,\n};\n\nexport const CAPTION_PRESET_NEON_GLOW: CaptionPresetDefinition = {\n id: \"neon-glow\",\n name: \"Neon Glow\",\n fontFamily: \"Montserrat Variable\",\n fontWeight: 800,\n fontStyle: \"normal\",\n fontSize: 52,\n letterSpacing: 1.0,\n lineHeight: 1.25,\n textTransform: \"none\",\n textAlign: \"center\",\n verticalAlign: \"bottom\",\n inactiveColor: \"#94A3B8\",\n inactiveOpacity: 0.5,\n activeColor: \"#22D3EE\",\n activeScale: 1.06,\n activeWordAnim: \"glow\",\n strokeEnabled: true,\n strokeColor: \"#0891B2\",\n strokeWidth: 4,\n glowEnabled: true,\n glowColor: \"#06B6D4\",\n glowBlur: 16,\n shadowEnabled: true,\n shadowColor: \"rgba(0, 0, 0, 0.8)\",\n shadowBlur: 8,\n shadowOffsetX: 0,\n shadowOffsetY: 2,\n backgroundEnabled: false,\n};\n\nexport const BUILT_IN_CAPTION_PRESETS: Record<CaptionPresetId, CaptionPresetDefinition> = {\n \"classic-subtitle\": CAPTION_PRESET_CLASSIC_SUBTITLE,\n \"karaoke-pop\": CAPTION_PRESET_KARAOKE_POP,\n \"bold-punch\": CAPTION_PRESET_BOLD_PUNCH,\n \"clean-minimal\": CAPTION_PRESET_CLEAN_MINIMAL,\n \"cinematic-gold\": CAPTION_PRESET_CINEMATIC_GOLD,\n \"neon-glow\": CAPTION_PRESET_NEON_GLOW,\n};\n\nexport function getCaptionPreset(idOrPreset: string | CaptionPresetDefinition | undefined): CaptionPresetDefinition {\n if (!idOrPreset) return CAPTION_PRESET_CLASSIC_SUBTITLE;\n if (typeof idOrPreset === \"object\") return idOrPreset;\n const match = BUILT_IN_CAPTION_PRESETS[idOrPreset as CaptionPresetId];\n return match ?? CAPTION_PRESET_CLASSIC_SUBTITLE;\n}\n\n/**\n * Computes a fast deterministic 32-bit hash of a resolved CaptionPresetDefinition\n * for use in sub-canvas bounding-box raster cache keys.\n */\nexport function hashCaptionPreset(preset: CaptionPresetDefinition): string {\n const str = `${preset.id}:${preset.fontFamily}:${preset.fontWeight}:${preset.fontSize}:${preset.activeColor}:${preset.inactiveColor}:${preset.activeScale ?? 1}:${preset.strokeEnabled ? preset.strokeWidth : 0}:${preset.shadowEnabled ? preset.shadowBlur : 0}:${preset.backgroundEnabled ? preset.backgroundColor : \"\"}:${preset.glowEnabled ? preset.glowBlur : 0}`;\n let hash = 0x811c9dc5;\n for (let i = 0; i < str.length; i++) {\n hash ^= str.charCodeAt(i);\n hash = Math.imul(hash, 0x01000193);\n }\n return (hash >>> 0).toString(16);\n}\n","/**\n * Caption Engine\n *\n * Handles layout geometry, pagination, word-timing evaluation, and\n * cache key computation for word-timed animated captions.\n */\n\nimport type {\n CaptionCue,\n CaptionWord,\n CaptionPresetDefinition,\n CaptionLineLayout,\n CaptionWordBox,\n CaptionBounds,\n} from \"./types.js\";\nimport { hashCaptionPreset } from \"./presets.js\";\n\nexport const PAUSE_RELEASE_THRESHOLD_MS = 250;\nexport const DEFAULT_MAX_WORDS_PER_LINE = 5;\nexport const DEFAULT_MAX_LINES = 2;\nexport const DEFAULT_PAUSE_BREAK_MS = 350;\n\nexport interface CaptionPaginationConfig {\n maxWordsPerLine?: number;\n maxLines?: number;\n pauseBreakMs?: number;\n}\n\nexport class CaptionEngine {\n /**\n * Paginates a flat stream of words into structured caption cues.\n * Enforces max words per line, max lines, pause thresholds, and punctuation breaks.\n */\n public static paginateWords(\n words: CaptionWord[],\n config: CaptionPaginationConfig = {},\n ): CaptionCue[] {\n if (!words.length) return [];\n\n const maxWordsPerLine = config.maxWordsPerLine ?? DEFAULT_MAX_WORDS_PER_LINE;\n const maxLines = config.maxLines ?? DEFAULT_MAX_LINES;\n const maxWordsPerCue = maxWordsPerLine * maxLines;\n const pauseBreakMs = config.pauseBreakMs ?? DEFAULT_PAUSE_BREAK_MS;\n\n const cues: CaptionCue[] = [];\n let currentCueWords: CaptionWord[] = [];\n\n for (let i = 0; i < words.length; i++) {\n const currentWord = words[i];\n const nextWord = words[i + 1];\n\n currentCueWords.push(currentWord);\n\n const hasReachedMaxWords = currentCueWords.length >= maxWordsPerCue;\n const isTerminalPunctuation = /[.!?]$/.test(currentWord.text.trim());\n const hasPauseBreak =\n nextWord && nextWord.startMs - currentWord.endMs >= pauseBreakMs;\n const isLastWord = i === words.length - 1;\n\n if (hasReachedMaxWords || isTerminalPunctuation || hasPauseBreak || isLastWord) {\n const text = currentCueWords.map((w) => w.text).join(\" \");\n const startMs = currentCueWords[0].startMs;\n const endMs = currentCueWords[currentCueWords.length - 1].endMs;\n const id = `cue_${startMs}_${endMs}`;\n\n cues.push({\n id,\n words: [...currentCueWords],\n text,\n startMs,\n endMs,\n });\n\n currentCueWords = [];\n }\n }\n\n return cues;\n }\n\n /**\n * Resolves the active word index within a cue for a given playback time in milliseconds.\n * Returns -1 if no word is active or during the pause release window (> 250ms after speech ends).\n */\n public static resolveActiveWordIndex(cue: CaptionCue, currentTimeMs: number): number {\n if (!cue.words.length) return -1;\n if (currentTimeMs < cue.words[0].startMs) return -1;\n\n for (let i = 0; i < cue.words.length; i++) {\n const w = cue.words[i];\n const nextWord = cue.words[i + 1];\n\n // Currently speaking inside word boundary\n if (currentTimeMs >= w.startMs && currentTimeMs < w.endMs) {\n return i;\n }\n\n // Inside pause between this word and next word\n if (currentTimeMs >= w.endMs && nextWord && currentTimeMs < nextWord.startMs) {\n const gap = nextWord.startMs - w.endMs;\n if (gap <= PAUSE_RELEASE_THRESHOLD_MS) {\n // Short gap (sub-250ms coarticulation): maintain highlight on finished word\n return i;\n }\n // Longer gap: release highlight during pause\n if (currentTimeMs < w.endMs + PAUSE_RELEASE_THRESHOLD_MS) {\n return i;\n }\n return -1;\n }\n }\n\n // After the last word in the cue\n const lastWord = cue.words[cue.words.length - 1];\n if (currentTimeMs >= lastWord.endMs) {\n if (currentTimeMs < lastWord.endMs + PAUSE_RELEASE_THRESHOLD_MS) {\n return cue.words.length - 1;\n }\n return -1;\n }\n\n return -1;\n }\n\n /**\n * Builds the canonical raster cache key for a caption frame.\n * Format: `caption:${clipId}:${segmentId}:${activeWordIndex}:${presetHash}:${fontLoaded}`\n */\n public static buildCacheKey(\n clipId: string,\n segmentId: string,\n activeWordIndex: number,\n preset: CaptionPresetDefinition,\n fontLoaded: boolean,\n ): string {\n const presetHash = hashCaptionPreset(preset);\n return `caption:${clipId}:${segmentId}:${activeWordIndex}:${presetHash}:${fontLoaded ? 1 : 0}`;\n }\n\n /**\n * Computes multi-line word layout and bounding boxes for a cue.\n */\n public static computeLayout(\n ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D,\n cue: CaptionCue,\n activeWordIndex: number,\n preset: CaptionPresetDefinition,\n canvasWidth: number,\n canvasHeight: number,\n scale: number = 1.0,\n positionYRatio: number = 0.85,\n ): { bounds: CaptionBounds; wordBoxes: CaptionWordBox[]; lines: CaptionLineLayout[] } {\n const fontSize = Math.round(preset.fontSize * scale);\n const lineHeight = fontSize * preset.lineHeight;\n const fontStr = `${preset.fontStyle} ${preset.fontWeight} ${fontSize}px \"${preset.fontFamily}\", sans-serif`;\n ctx.font = fontStr;\n\n // Split words into lines based on max canvas width (80% of canvas width)\n const maxLineWidth = Math.max(200, canvasWidth * 0.85);\n const spaceWidth = ctx.measureText(\" \").width;\n\n const lines: { words: CaptionWord[]; indices: number[]; widths: number[] }[] = [];\n let curLineWords: CaptionWord[] = [];\n let curLineIndices: number[] = [];\n let curLineWidths: number[] = [];\n let curLineWidth = 0;\n\n for (let i = 0; i < cue.words.length; i++) {\n const word = cue.words[i];\n const displayText =\n preset.textTransform === \"uppercase\"\n ? word.text.toUpperCase()\n : preset.textTransform === \"lowercase\"\n ? word.text.toLowerCase()\n : word.text;\n\n const wWidth = ctx.measureText(displayText).width;\n const neededWidth = curLineWidth === 0 ? wWidth : curLineWidth + spaceWidth + wWidth;\n\n if (curLineWords.length > 0 && (neededWidth > maxLineWidth || curLineWords.length >= DEFAULT_MAX_WORDS_PER_LINE)) {\n lines.push({\n words: curLineWords,\n indices: curLineIndices,\n widths: curLineWidths,\n });\n curLineWords = [word];\n curLineIndices = [i];\n curLineWidths = [wWidth];\n curLineWidth = wWidth;\n } else {\n curLineWords.push(word);\n curLineIndices.push(i);\n curLineWidths.push(wWidth);\n curLineWidth = neededWidth;\n }\n }\n\n if (curLineWords.length > 0) {\n lines.push({\n words: curLineWords,\n indices: curLineIndices,\n widths: curLineWidths,\n });\n }\n\n const totalHeight = lines.length * lineHeight;\n const anchorCenterY = canvasHeight * positionYRatio;\n const startY = anchorCenterY - totalHeight / 2;\n\n const allWordBoxes: CaptionWordBox[] = [];\n const lineLayouts: CaptionLineLayout[] = [];\n\n let overallMinX = Infinity;\n let overallMinY = Infinity;\n let overallMaxX = -Infinity;\n let overallMaxY = -Infinity;\n\n for (let l = 0; l < lines.length; l++) {\n const line = lines[l];\n const lineWidth =\n line.widths.reduce((a, b) => a + b, 0) + (line.words.length - 1) * spaceWidth;\n const lineY = startY + l * lineHeight;\n const baselineY = lineY + fontSize * 0.82;\n\n let startX = (canvasWidth - lineWidth) / 2;\n if (preset.textAlign === \"left\") {\n startX = canvasWidth * 0.08;\n } else if (preset.textAlign === \"right\") {\n startX = canvasWidth * 0.92 - lineWidth;\n }\n\n let curX = startX;\n const lineBoxes: CaptionWordBox[] = [];\n\n for (let w = 0; w < line.words.length; w++) {\n const word = line.words[w];\n const wordIdx = line.indices[w];\n const wWidth = line.widths[w];\n const isActive = wordIdx === activeWordIndex;\n\n const box: CaptionWordBox = {\n wordIndex: wordIdx,\n word,\n x: curX,\n y: lineY,\n width: wWidth,\n height: lineHeight,\n baselineY,\n isActive,\n };\n\n lineBoxes.push(box);\n allWordBoxes.push(box);\n\n overallMinX = Math.min(overallMinX, curX);\n overallMinY = Math.min(overallMinY, lineY);\n overallMaxX = Math.max(overallMaxX, curX + wWidth);\n overallMaxY = Math.max(overallMaxY, lineY + lineHeight);\n\n curX += wWidth + spaceWidth;\n }\n\n lineLayouts.push({\n lineIndex: l,\n text: line.words.map((w) => w.text).join(\" \"),\n words: lineBoxes,\n width: lineWidth,\n height: lineHeight,\n x: startX,\n y: lineY,\n });\n }\n\n // Add bleed padding for stroke, shadow, glow, and active-word scale\n const strokeBleed = preset.strokeEnabled ? (preset.strokeWidth ?? 4) * scale : 0;\n const shadowBleed = preset.shadowEnabled ? (preset.shadowBlur ?? 8) * scale : 0;\n const glowBleed = preset.glowEnabled ? (preset.glowBlur ?? 16) * scale : 0;\n const bgPadX = preset.backgroundEnabled ? (preset.backgroundPaddingX ?? 20) * scale : 0;\n const bgPadY = preset.backgroundEnabled ? (preset.backgroundPaddingY ?? 10) * scale : 0;\n const activeScaleBleed = fontSize * 0.25;\n\n const padX = Math.ceil(Math.max(strokeBleed + shadowBleed + glowBleed + activeScaleBleed, bgPadX));\n const padY = Math.ceil(Math.max(strokeBleed + shadowBleed + glowBleed + activeScaleBleed, bgPadY));\n\n const bounds: CaptionBounds = {\n x: Math.max(0, Math.floor(overallMinX - padX)),\n y: Math.max(0, Math.floor(overallMinY - padY)),\n width: Math.min(canvasWidth, Math.ceil(overallMaxX - overallMinX + padX * 2)),\n height: Math.min(canvasHeight, Math.ceil(overallMaxY - overallMinY + padY * 2)),\n };\n\n return { bounds, wordBoxes: allWordBoxes, lines: lineLayouts };\n }\n}\n","/**\n * Caption Canvas Renderer\n *\n * Single source of truth for rendering word-timed animated captions.\n * Consumed identically by:\n * 1. Web Worker (templateRasterizer.worker.ts) for off-thread sub-canvas rasterization\n * 2. Main-thread fallback (nativeTextPreview.ts) when Web Workers are unavailable or during export\n * 3. @clypra-studio/engine in web and browser previews\n */\n\nimport type {\n CaptionRenderOptions,\n CaptionRenderResult,\n CaptionPresetDefinition,\n} from \"./types.js\";\nimport { CaptionEngine } from \"./engine.js\";\n\nexport function renderCaptionToCanvas(\n ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D,\n options: CaptionRenderOptions,\n): CaptionRenderResult {\n const {\n cue,\n activeWordIndex,\n preset,\n canvasWidth,\n canvasHeight,\n scale = 1.0,\n positionYRatio = 0.85,\n } = options;\n\n if (!cue.words || cue.words.length === 0) {\n return {\n bounds: { x: 0, y: 0, width: 0, height: 0 },\n wordBoxes: [],\n lines: [],\n };\n }\n\n // 1. Compute multi-line layout and geometry bounds\n const layout = CaptionEngine.computeLayout(\n ctx,\n cue,\n activeWordIndex,\n preset,\n canvasWidth,\n canvasHeight,\n scale,\n positionYRatio,\n );\n\n const fontSize = Math.round(preset.fontSize * scale);\n const fontStr = `${preset.fontStyle} ${preset.fontWeight} ${fontSize}px \"${preset.fontFamily}\", sans-serif`;\n ctx.font = fontStr;\n ctx.textBaseline = \"alphabetic\";\n\n // 2. Render background box/pill if enabled\n if (preset.backgroundEnabled && preset.backgroundColor) {\n ctx.save();\n ctx.fillStyle = preset.backgroundColor;\n const padX = (preset.backgroundPaddingX ?? 18) * scale;\n const padY = (preset.backgroundPaddingY ?? 8) * scale;\n const radius = (preset.backgroundBorderRadius ?? 12) * scale;\n\n for (const line of layout.lines) {\n const bgX = line.x - padX;\n const bgY = line.y - padY / 2;\n const bgW = line.width + padX * 2;\n const bgH = line.height + padY;\n\n ctx.beginPath();\n if (typeof ctx.roundRect === \"function\") {\n ctx.roundRect(bgX, bgY, bgW, bgH, radius);\n } else {\n ctx.rect(bgX, bgY, bgW, bgH);\n }\n ctx.fill();\n }\n ctx.restore();\n }\n\n // 3. Render words\n for (const box of layout.wordBoxes) {\n ctx.save();\n\n const displayText =\n preset.textTransform === \"uppercase\"\n ? box.word.text.toUpperCase()\n : preset.textTransform === \"lowercase\"\n ? box.word.text.toLowerCase()\n : box.word.text;\n\n const isActive = box.isActive;\n\n if (isActive && preset.activeBackgroundColor) {\n ctx.save();\n ctx.fillStyle = preset.activeBackgroundColor;\n const padX = (preset.activeBackgroundPaddingX ?? 8) * scale;\n const padY = (preset.activeBackgroundPaddingY ?? 4) * scale;\n const radius = (preset.activeBackgroundBorderRadius ?? 5) * scale;\n const bgX = box.x - padX;\n const bgY = box.y - padY / 2;\n const bgW = box.width + padX * 2;\n const bgH = box.height + padY;\n ctx.beginPath();\n if (typeof ctx.roundRect === \"function\") ctx.roundRect(bgX, bgY, bgW, bgH, radius);\n else ctx.rect(bgX, bgY, bgW, bgH);\n ctx.fill();\n ctx.restore();\n }\n\n // Apply active-word scale animation (centered on word)\n if (isActive && preset.activeScale && preset.activeScale !== 1.0) {\n const centerX = box.x + box.width / 2;\n const centerY = box.y + box.height / 2;\n ctx.translate(centerX, centerY);\n ctx.scale(preset.activeScale, preset.activeScale);\n ctx.translate(-centerX, -centerY);\n }\n\n // Configure glow if active and enabled\n if (isActive && preset.glowEnabled && preset.glowColor) {\n ctx.shadowColor = preset.glowColor;\n ctx.shadowBlur = (preset.glowBlur ?? 16) * scale;\n ctx.shadowOffsetX = 0;\n ctx.shadowOffsetY = 0;\n } else if (preset.shadowEnabled && preset.shadowColor) {\n ctx.shadowColor = preset.shadowColor;\n ctx.shadowBlur = (preset.shadowBlur ?? 6) * scale;\n ctx.shadowOffsetX = (preset.shadowOffsetX ?? 0) * scale;\n ctx.shadowOffsetY = (preset.shadowOffsetY ?? 2) * scale;\n } else {\n ctx.shadowColor = \"transparent\";\n ctx.shadowBlur = 0;\n ctx.shadowOffsetX = 0;\n ctx.shadowOffsetY = 0;\n }\n\n // Configure stroke\n if (preset.strokeEnabled) {\n ctx.lineWidth = ((isActive && preset.activeStrokeWidth) || preset.strokeWidth || 4) * scale;\n ctx.strokeStyle = (isActive && preset.activeStrokeColor) || preset.strokeColor || \"#000000\";\n ctx.lineJoin = \"round\";\n ctx.miterLimit = 2;\n ctx.strokeText(displayText, box.x, box.baselineY);\n }\n\n // Configure fill\n if (isActive) {\n ctx.fillStyle = preset.activeColor;\n ctx.globalAlpha = 1.0;\n } else {\n ctx.fillStyle = preset.inactiveColor;\n ctx.globalAlpha = preset.inactiveOpacity;\n }\n\n ctx.fillText(displayText, box.x, box.baselineY);\n\n ctx.restore();\n }\n\n return layout;\n}\n"],"mappings":";AAcO,IAAM,kCAA2D;AAAA,EACtE,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,UAAU;AAAA,EACV,eAAe;AAAA,EACf,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,WAAW;AAAA,EACX,eAAe;AAAA,EACf,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,aAAa;AAAA,EACb,aAAa;AAAA,EACb,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,eAAe;AAAA,EACf,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,eAAe;AAAA,EACf,mBAAmB;AACrB;AAEO,IAAM,6BAAsD;AAAA,EACjE,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,UAAU;AAAA,EACV,eAAe;AAAA,EACf,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,WAAW;AAAA,EACX,eAAe;AAAA,EACf,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,aAAa;AAAA,EACb,aAAa;AAA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pB,UAAI,gBAAgB;AAAA,IACtB,WAAW,OAAO,iBAAiB,OAAO,aAAa;AACrD,UAAI,cAAc,OAAO;AACzB,UAAI,cAAc,OAAO,cAAc,KAAK;AAC5C,UAAI,iBAAiB,OAAO,iBAAiB,KAAK;AAClD,UAAI,iBAAiB,OAAO,iBAAiB,KAAK;AAAA,IACpD,OAAO;AACL,UAAI,cAAc;AAClB,UAAI,aAAa;AACjB,UAAI,gBAAgB;AACpB,UAAI,gBAAgB;AAAA,IACtB;AAGA,QAAI,OAAO,eAAe;AACxB,UAAI,aAAc,YAAY,OAAO,qBAAsB,OAAO,eAAe,KAAK;AACtF,UAAI,cAAe,YAAY,OAAO,qBAAsB,OAAO,eAAe;AAClF,UAAI,WAAW;AACf,UAAI,aAAa;AACjB,UAAI,WAAW,aAAa,IAAI,GAAG,IAAI,SAAS;AAAA,IAClD;AAGA,QAAI,UAAU;AACZ,UAAI,YAAY,OAAO;AACvB,UAAI,cAAc;AAAA,IACpB,OAAO;AACL,UAAI,YAAY,OAAO;AACvB,UAAI,cAAc,OAAO;AAAA,IAC3B;AAEA,QAAI,SAAS,aAAa,IAAI,GAAG,IAAI,SAAS;AAE9C,QAAI,QAAQ;AAAA,EACd;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveFontFamilyName
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4AT7MAXU.js";
|
|
4
4
|
|
|
5
5
|
// src/fontLoader.ts
|
|
6
6
|
var FONT_VARIANTS = [
|
|
@@ -297,4 +297,4 @@ export {
|
|
|
297
297
|
resetFontLoader,
|
|
298
298
|
ensureFontsLoaded
|
|
299
299
|
};
|
|
300
|
-
//# sourceMappingURL=chunk-
|
|
300
|
+
//# sourceMappingURL=chunk-IZH6P7WL.js.map
|
|
@@ -81,7 +81,7 @@ declare function getRenderCapabilities(plan: RenderPlan, target: RenderTarget):
|
|
|
81
81
|
|
|
82
82
|
declare const TEXT_TEMPLATE_KIND: "text-template";
|
|
83
83
|
declare const TEXT_TEMPLATE_SCHEMA_VERSION: 4;
|
|
84
|
-
declare const TEXT_TEMPLATE_RENDERER_VERSION: "1.
|
|
84
|
+
declare const TEXT_TEMPLATE_RENDERER_VERSION: "1.6.0";
|
|
85
85
|
type TemplateControlType = "text" | "color" | "number" | "boolean" | "enum" | "font" | "media";
|
|
86
86
|
interface TemplateControlOption {
|
|
87
87
|
value: string;
|
|
@@ -96,6 +96,21 @@ interface TemplateControlConstraints {
|
|
|
96
96
|
options?: TemplateControlOption[];
|
|
97
97
|
allowedMimeTypes?: string[];
|
|
98
98
|
}
|
|
99
|
+
interface TemplateControlLinearTransform {
|
|
100
|
+
kind: "linear";
|
|
101
|
+
scale: number;
|
|
102
|
+
offset: number;
|
|
103
|
+
}
|
|
104
|
+
interface TemplateControlEnumMapTransform {
|
|
105
|
+
kind: "enumMap";
|
|
106
|
+
values: Record<string, string | number | boolean | null>;
|
|
107
|
+
}
|
|
108
|
+
type TemplateControlTransform = TemplateControlLinearTransform | TemplateControlEnumMapTransform;
|
|
109
|
+
interface TemplateControlTarget {
|
|
110
|
+
nodeId: string;
|
|
111
|
+
propertyPath: string;
|
|
112
|
+
transform?: TemplateControlTransform;
|
|
113
|
+
}
|
|
99
114
|
interface TemplateControl {
|
|
100
115
|
id: string;
|
|
101
116
|
label: string;
|
|
@@ -105,10 +120,10 @@ interface TemplateControl {
|
|
|
105
120
|
required?: boolean;
|
|
106
121
|
defaultValue: string | number | boolean | null;
|
|
107
122
|
constraints?: TemplateControlConstraints;
|
|
108
|
-
target
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
123
|
+
/** Required primary target retained for compatibility with existing artifacts. */
|
|
124
|
+
target: Omit<TemplateControlTarget, "transform">;
|
|
125
|
+
/** Additional node targets are applied after the primary target, in order. */
|
|
126
|
+
additionalTargets?: TemplateControlTarget[];
|
|
112
127
|
}
|
|
113
128
|
interface TemplateProtectedRegion {
|
|
114
129
|
start: number;
|
|
@@ -780,4 +795,4 @@ type CanonicalRenderInput = {
|
|
|
780
795
|
/** Extensible capability registry for all package-owned render semantics. */
|
|
781
796
|
declare function renderCanonicalToCanvas(ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, input: CanonicalRenderInput): CanonicalRenderResult;
|
|
782
797
|
|
|
783
|
-
export { type
|
|
798
|
+
export { type TemplateImageNode as $, TEXT_TEMPLATE_KIND as A, type BubbleAppearance as B, type CompiledTextTemplate as C, TEXT_TEMPLATE_RENDERER_VERSION as D, type EvaluatedTemplateScene as E, type FreeformBubbleDefinition as F, TEXT_TEMPLATE_SCHEMA_VERSION as G, type TemplateAssetRef as H, type TemplateBackgroundPanel as I, type TemplateCapabilityReport as J, type TemplateContainerNode as K, type TemplateContainerNodeStyle as L, type TemplateControl as M, type TemplateControlConstraints as N, type TemplateControlEnumMapTransform as O, type ParametricBubbleDefinition as P, type TemplateControlLinearTransform as Q, type RenderPlan as R, type SceneDocumentV2 as S, type TextTemplateArtifact as T, type TemplateControlOption as U, type TemplateControlTarget as V, type TemplateControlTransform as W, type TemplateControlType as X, type TemplateDependencyManifest as Y, type TemplateDurationPolicy as Z, type TemplateFontRef as _, type ResolveTemplateControlValuesOptions as a, type TemplateLayerV2 as a0, type TemplateMetadata as a1, type TemplateNode as a2, type TemplateNodeAnimation as a3, type TemplatePreviewArtifacts as a4, type TemplatePropertyKeyframes as a5, type TemplateProtectedRegion as a6, type TemplateRenderTarget as a7, type TemplateRevision as a8, type TemplateShapeNode as a9, drawSpeechBubble as aA, drawThoughtCloud as aB, drawTornPaper as aC, evaluateTextEffect as aD, evaluateTextTemplate as aE, getRenderCapabilities as aF, getTextTemplateControls as aG, normalizeTextEffect as aH, normalizeTextTemplate as aI, pseudoNoise as aJ, renderBubbleAssetDefinition as aK, renderBubbleBackground as aL, renderBubblePresetBackground as aM, renderCanonicalToCanvas as aN, renderTextEffectToCanvas as aO, renderTextTemplateToCanvas as aP, resolveBubbleLayout as aQ, resolveTemplateFontFamily as aR, resolveTextTemplateArtifact as aS, validateBubbleAssetDefinition as aT, type TemplateShapeNodeStyle as aa, type TemplateStyleRef as ab, type TemplateTextNode as ac, type TemplateTextNodeStyle as ad, type TemplateTimelineMarker as ae, type TemplateTiming as af, type TextBubbleCategory as ag, type TextBubbleLayout as ah, type TextBubblePadding as ai, type TextBubblePreset as aj, type TextEffectRenderInput as ak, type TextTemplateCanvas as al, type TextTemplateClip as am, type TextTemplateDocument as an, type TextTemplateDocumentV2 as ao, type TextTemplateFlexLayout as ap, type TextTemplateRenderInput as aq, canonicalContentHash as ar, canonicalizeSceneDocument as as, compileBubblePath as at, compileBubbleSvg as au, createBubbleAssetDefinition as av, createFreeformBubbleAssetDefinition as aw, drawChalkSpeechBubble as ax, drawComicBurst as ay, drawRibbonBanner as az, type TemplateCustomization as b, type TemplateRenderContext as c, type BubbleAssetDefinition as d, type BubblePathCommand as e, type BubbleRenderMode as f, type BubbleRenderOptions as g, type BubbleShape as h, type BubbleTailPosition as i, type BubbleTailSide as j, type BubbleTexture as k, CANONICAL_RENDERER_VERSION as l, CANONICAL_SCHEMA_VERSION as m, type CanonicalRenderContext as n, type CanonicalRenderInput as o, type CanonicalRenderResult as p, type CapabilityReport as q, type CapabilityStatus as r, type CompiledTemplateRenderLayer as s, type PublishedRevision as t, type RenderCapability as u, type RenderDiagnostic as v, type RenderDiagnostics as w, type RenderEnvironment as x, type RenderIdentity as y, type RenderTarget as z };
|