@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
package/dist/index.cjs
CHANGED
|
@@ -37,11 +37,19 @@ __export(index_exports, {
|
|
|
37
37
|
AnimationValidator: () => AnimationValidator,
|
|
38
38
|
AssetRegistry: () => AssetRegistry,
|
|
39
39
|
BUILTIN_CANVAS_TEMPLATES: () => BUILTIN_CANVAS_TEMPLATES,
|
|
40
|
+
BUILT_IN_CAPTION_PRESETS: () => BUILT_IN_CAPTION_PRESETS,
|
|
40
41
|
BoundingBoxSchema: () => BoundingBoxSchema,
|
|
41
42
|
CANONICAL_RENDERER_VERSION: () => CANONICAL_RENDERER_VERSION,
|
|
42
43
|
CANONICAL_SCHEMA_VERSION: () => CANONICAL_SCHEMA_VERSION,
|
|
44
|
+
CAPTION_PRESET_BOLD_PUNCH: () => CAPTION_PRESET_BOLD_PUNCH,
|
|
45
|
+
CAPTION_PRESET_CINEMATIC_GOLD: () => CAPTION_PRESET_CINEMATIC_GOLD,
|
|
46
|
+
CAPTION_PRESET_CLASSIC_SUBTITLE: () => CAPTION_PRESET_CLASSIC_SUBTITLE,
|
|
47
|
+
CAPTION_PRESET_CLEAN_MINIMAL: () => CAPTION_PRESET_CLEAN_MINIMAL,
|
|
48
|
+
CAPTION_PRESET_KARAOKE_POP: () => CAPTION_PRESET_KARAOKE_POP,
|
|
49
|
+
CAPTION_PRESET_NEON_GLOW: () => CAPTION_PRESET_NEON_GLOW,
|
|
43
50
|
COMPOSITION_PRESETS: () => COMPOSITION_PRESETS,
|
|
44
51
|
CanvasDevice: () => CanvasDevice,
|
|
52
|
+
CaptionEngine: () => CaptionEngine,
|
|
45
53
|
CommandBufferBuilder: () => CommandBufferBuilder,
|
|
46
54
|
CommandExecutor: () => CommandExecutor,
|
|
47
55
|
CommandHistory: () => CommandHistory,
|
|
@@ -50,6 +58,9 @@ __export(index_exports, {
|
|
|
50
58
|
DEFAULT_DURATION: () => DEFAULT_DURATION,
|
|
51
59
|
DEFAULT_FONT_SIZE: () => DEFAULT_FONT_SIZE,
|
|
52
60
|
DEFAULT_FPS: () => DEFAULT_FPS,
|
|
61
|
+
DEFAULT_MAX_LINES: () => DEFAULT_MAX_LINES,
|
|
62
|
+
DEFAULT_MAX_WORDS_PER_LINE: () => DEFAULT_MAX_WORDS_PER_LINE,
|
|
63
|
+
DEFAULT_PAUSE_BREAK_MS: () => DEFAULT_PAUSE_BREAK_MS,
|
|
53
64
|
DEFAULT_TEXT_STYLE: () => DEFAULT_TEXT_STYLE,
|
|
54
65
|
DataBindingAuthoringEngine: () => DataBindingAuthoringEngine,
|
|
55
66
|
DataBindingEngine: () => DataBindingEngine,
|
|
@@ -102,6 +113,7 @@ __export(index_exports, {
|
|
|
102
113
|
Mp4VideoEncoder: () => Mp4VideoEncoder,
|
|
103
114
|
NodeRegistry: () => NodeRegistry,
|
|
104
115
|
NullBackend: () => NullBackend,
|
|
116
|
+
PAUSE_RELEASE_THRESHOLD_MS: () => PAUSE_RELEASE_THRESHOLD_MS,
|
|
105
117
|
PngSequenceEncoder: () => PngSequenceEncoder,
|
|
106
118
|
PrimitiveRegistry: () => PrimitiveRegistry,
|
|
107
119
|
ProResVideoEncoder: () => ProResVideoEncoder,
|
|
@@ -167,6 +179,7 @@ __export(index_exports, {
|
|
|
167
179
|
applyStyleToLottie: () => applyStyleToLottie,
|
|
168
180
|
applyStyleToLottieLayer: () => applyStyleToLottieLayer,
|
|
169
181
|
applyTimelineAtTime: () => applyTimelineAtTime,
|
|
182
|
+
assertCompatibleTextTemplateRenderer: () => assertCompatibleTextTemplateRenderer,
|
|
170
183
|
assertValidTextTemplateArtifact: () => assertValidTextTemplateArtifact,
|
|
171
184
|
assetRegistry: () => assetRegistry,
|
|
172
185
|
bakeAnimationIntoLayer: () => bakeAnimationIntoLayer,
|
|
@@ -271,6 +284,7 @@ __export(index_exports, {
|
|
|
271
284
|
getAnimatableParamsForLayer: () => getAnimatableParamsForLayer,
|
|
272
285
|
getCanvasTemplatePreset: () => getCanvasTemplatePreset,
|
|
273
286
|
getCanvasTemplatesByCategory: () => getCanvasTemplatesByCategory,
|
|
287
|
+
getCaptionPreset: () => getCaptionPreset,
|
|
274
288
|
getClipLayout: () => getClipLayout,
|
|
275
289
|
getDefaultText: () => getDefaultText,
|
|
276
290
|
getEffectByIdForApi: () => getEffectByIdForApi,
|
|
@@ -299,9 +313,10 @@ __export(index_exports, {
|
|
|
299
313
|
getTransitionsByCategory: () => getTransitionsByCategory,
|
|
300
314
|
getTransitionsByTags: () => getTransitionsByTags,
|
|
301
315
|
getWebMFrameCount: () => getWebMFrameCount,
|
|
316
|
+
hashCaptionPreset: () => hashCaptionPreset,
|
|
302
317
|
hexToLottieColor: () => hexToLottieColor,
|
|
303
318
|
hexToLottieRgb: () => hexToLottieRgb,
|
|
304
|
-
hexToRgba: () =>
|
|
319
|
+
hexToRgba: () => hexToRgba2,
|
|
305
320
|
hitTestTransformHandles: () => hitTestTransformHandles,
|
|
306
321
|
initializeFontSystem: () => initializeFontSystem,
|
|
307
322
|
injectBatch: () => injectBatch,
|
|
@@ -317,6 +332,7 @@ __export(index_exports, {
|
|
|
317
332
|
interpolateValue: () => interpolateValue,
|
|
318
333
|
isKeyframed: () => isKeyframed,
|
|
319
334
|
isMp4ExportSupported: () => isMp4ExportSupported,
|
|
335
|
+
isTextTemplateRendererVersionNewer: () => isTextTemplateRendererVersionNewer,
|
|
320
336
|
isWebMExportSupported: () => isWebMExportSupported,
|
|
321
337
|
layerToTextEffectConfig: () => layerToTextEffectConfig,
|
|
322
338
|
layoutEngine: () => layoutEngine,
|
|
@@ -356,6 +372,7 @@ __export(index_exports, {
|
|
|
356
372
|
renderBubbleBackground: () => renderBubbleBackground,
|
|
357
373
|
renderBubblePresetBackground: () => renderBubblePresetBackground,
|
|
358
374
|
renderCanonicalToCanvas: () => renderCanonicalToCanvas,
|
|
375
|
+
renderCaptionToCanvas: () => renderCaptionToCanvas,
|
|
359
376
|
renderEvaluatedSceneToCanvas: () => renderEvaluatedSceneToCanvas,
|
|
360
377
|
renderPngSequence: () => renderPngSequence,
|
|
361
378
|
renderSceneWebM: () => renderSceneWebM,
|
|
@@ -1204,6 +1221,10 @@ function hexToRgb(hex) {
|
|
|
1204
1221
|
b: parseInt(result[3], 16)
|
|
1205
1222
|
} : { r: 255, g: 255, b: 255 };
|
|
1206
1223
|
}
|
|
1224
|
+
function hexToRgba(hex, alpha2) {
|
|
1225
|
+
const rgb = hexToRgb(hex);
|
|
1226
|
+
return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${alpha2})`;
|
|
1227
|
+
}
|
|
1207
1228
|
|
|
1208
1229
|
// src/renderer.ts
|
|
1209
1230
|
function getCanvas2DContext(canvas) {
|
|
@@ -1360,9 +1381,11 @@ function renderTextEffectCore(ctx, cfg) {
|
|
|
1360
1381
|
};
|
|
1361
1382
|
const renderWithShadowTrick = (mode, sColor, sBlur, sOffsetX, sOffsetY, opacity, overrideStyle = "#000", spread = 0) => {
|
|
1362
1383
|
ctx.save();
|
|
1363
|
-
|
|
1384
|
+
const normalizedOpacity = Math.max(0, Math.min(100, opacity)) / 100;
|
|
1385
|
+
const shadowColor2 = /^#(?:[\da-f]{3}|[\da-f]{6})$/i.test(sColor) ? hexToRgba(sColor, normalizedOpacity) : sColor;
|
|
1386
|
+
ctx.globalAlpha = /^#(?:[\da-f]{3}|[\da-f]{6})$/i.test(sColor) ? 1 : normalizedOpacity;
|
|
1364
1387
|
const shiftX = 1e4;
|
|
1365
|
-
ctx.shadowColor =
|
|
1388
|
+
ctx.shadowColor = shadowColor2;
|
|
1366
1389
|
ctx.shadowBlur = sBlur;
|
|
1367
1390
|
ctx.shadowOffsetX = shiftX + sOffsetX;
|
|
1368
1391
|
ctx.shadowOffsetY = sOffsetY;
|
|
@@ -8688,7 +8711,7 @@ var EffectEngine = class {
|
|
|
8688
8711
|
};
|
|
8689
8712
|
|
|
8690
8713
|
// src/videoEffects/utils/colorUtils.ts
|
|
8691
|
-
function
|
|
8714
|
+
function hexToRgba2(hex, alpha2) {
|
|
8692
8715
|
hex = hex.replace("#", "");
|
|
8693
8716
|
const r = parseInt(hex.substring(0, 2), 16);
|
|
8694
8717
|
const g = parseInt(hex.substring(2, 4), 16);
|
|
@@ -12475,7 +12498,7 @@ function getCanvasTemplatesByCategory(category) {
|
|
|
12475
12498
|
// src/textTemplates/contract.ts
|
|
12476
12499
|
var TEXT_TEMPLATE_KIND = "text-template";
|
|
12477
12500
|
var TEXT_TEMPLATE_SCHEMA_VERSION = 4;
|
|
12478
|
-
var TEXT_TEMPLATE_RENDERER_VERSION = "1.
|
|
12501
|
+
var TEXT_TEMPLATE_RENDERER_VERSION = "1.6.0";
|
|
12479
12502
|
|
|
12480
12503
|
// src/textTemplates/normalize.ts
|
|
12481
12504
|
function clone2(value) {
|
|
@@ -13003,7 +13026,90 @@ function resolveTemplateControlValues(artifact, optionsOrCustomization, fallback
|
|
|
13003
13026
|
// src/textTemplates/validator.ts
|
|
13004
13027
|
var MAX_NODES = 500;
|
|
13005
13028
|
var MAX_CONTROLS = 100;
|
|
13006
|
-
|
|
13029
|
+
var MAX_ADDITIONAL_TARGETS = 16;
|
|
13030
|
+
var UNSAFE_PATH_PARTS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
13031
|
+
function readPath(target, path) {
|
|
13032
|
+
if (!path || path.split(".").some((part) => UNSAFE_PATH_PARTS.has(part))) return { exists: false };
|
|
13033
|
+
let cursor = target;
|
|
13034
|
+
for (const part of path.split(".")) {
|
|
13035
|
+
if (!cursor || typeof cursor !== "object" || !Object.prototype.hasOwnProperty.call(cursor, part)) return { exists: false };
|
|
13036
|
+
cursor = cursor[part];
|
|
13037
|
+
}
|
|
13038
|
+
return { exists: true, value: cursor };
|
|
13039
|
+
}
|
|
13040
|
+
function valueType(value) {
|
|
13041
|
+
if (value === null) return "null";
|
|
13042
|
+
if (typeof value === "string") return "string";
|
|
13043
|
+
if (typeof value === "number") return "number";
|
|
13044
|
+
if (typeof value === "boolean") return "boolean";
|
|
13045
|
+
return "other";
|
|
13046
|
+
}
|
|
13047
|
+
function controlTypeMatches(control, value) {
|
|
13048
|
+
switch (control.type) {
|
|
13049
|
+
case "text":
|
|
13050
|
+
case "color":
|
|
13051
|
+
case "enum":
|
|
13052
|
+
case "font":
|
|
13053
|
+
case "media":
|
|
13054
|
+
return typeof value === "string";
|
|
13055
|
+
case "number":
|
|
13056
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
13057
|
+
case "boolean":
|
|
13058
|
+
return typeof value === "boolean";
|
|
13059
|
+
default:
|
|
13060
|
+
return false;
|
|
13061
|
+
}
|
|
13062
|
+
}
|
|
13063
|
+
function transformedDefaultValue(control, target) {
|
|
13064
|
+
const transform = target.transform;
|
|
13065
|
+
if (!transform) return control.defaultValue;
|
|
13066
|
+
if (transform.kind === "linear" && typeof control.defaultValue === "number") {
|
|
13067
|
+
return control.defaultValue * transform.scale + transform.offset;
|
|
13068
|
+
}
|
|
13069
|
+
if (transform.kind === "enumMap" && typeof control.defaultValue === "string" && Object.prototype.hasOwnProperty.call(transform.values, control.defaultValue)) {
|
|
13070
|
+
return transform.values[control.defaultValue];
|
|
13071
|
+
}
|
|
13072
|
+
return void 0;
|
|
13073
|
+
}
|
|
13074
|
+
function validateTargetTransform(control, target, currentValue, diagnostics, path) {
|
|
13075
|
+
const transform = target.transform;
|
|
13076
|
+
if (!transform) {
|
|
13077
|
+
if (!controlTypeMatches(control, currentValue)) {
|
|
13078
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TARGET_TYPE", message: `Control ${control.id} value type does not match ${target.propertyPath}`, nodeId: target.nodeId });
|
|
13079
|
+
}
|
|
13080
|
+
return;
|
|
13081
|
+
}
|
|
13082
|
+
if (transform.kind === "linear") {
|
|
13083
|
+
if (control.type !== "number" || typeof currentValue !== "number" || !Number.isFinite(transform.scale) || !Number.isFinite(transform.offset)) {
|
|
13084
|
+
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 });
|
|
13085
|
+
return;
|
|
13086
|
+
}
|
|
13087
|
+
return;
|
|
13088
|
+
}
|
|
13089
|
+
if (transform.kind === "enumMap") {
|
|
13090
|
+
const values = transform.values;
|
|
13091
|
+
if (control.type !== "enum" || !values || typeof values !== "object" || Array.isArray(values)) {
|
|
13092
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TRANSFORM", message: `Control ${control.id} enumMap transforms require an enum control and values object`, nodeId: target.nodeId });
|
|
13093
|
+
return;
|
|
13094
|
+
}
|
|
13095
|
+
const targetType = valueType(currentValue);
|
|
13096
|
+
for (const mappedValue of Object.values(values)) {
|
|
13097
|
+
if (valueType(mappedValue) !== targetType) {
|
|
13098
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TRANSFORM", message: `Control ${control.id} enumMap values must match the target property type`, nodeId: target.nodeId });
|
|
13099
|
+
break;
|
|
13100
|
+
}
|
|
13101
|
+
}
|
|
13102
|
+
if (control.constraints?.options?.some((option) => !Object.prototype.hasOwnProperty.call(values, option.value))) {
|
|
13103
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TRANSFORM", message: `Control ${control.id} enumMap must cover every enum option`, nodeId: target.nodeId });
|
|
13104
|
+
}
|
|
13105
|
+
if (transformedDefaultValue(control, target) === void 0) {
|
|
13106
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TRANSFORM", message: `Control ${control.id} enumMap must map its default value`, nodeId: target.nodeId });
|
|
13107
|
+
}
|
|
13108
|
+
return;
|
|
13109
|
+
}
|
|
13110
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TRANSFORM", message: `Control ${control.id} has an unknown transform kind`, nodeId: target.nodeId });
|
|
13111
|
+
}
|
|
13112
|
+
function validateTextTemplateArtifact(artifact, options = {}) {
|
|
13007
13113
|
const diagnostics = [];
|
|
13008
13114
|
if (!artifact || artifact.kind !== "text-template") {
|
|
13009
13115
|
return [{ severity: "error", code: "TEMPLATE_KIND", message: "Artifact kind must be text-template" }];
|
|
@@ -13063,16 +13169,51 @@ function validateTextTemplateArtifact(artifact) {
|
|
|
13063
13169
|
diagnostics.push({ severity: "error", code: "CONTROL_LIMIT", message: `Template exceeds the ${MAX_CONTROLS}-control limit` });
|
|
13064
13170
|
}
|
|
13065
13171
|
const controlIds = /* @__PURE__ */ new Set();
|
|
13172
|
+
const targetOwners = /* @__PURE__ */ new Map();
|
|
13066
13173
|
for (const control of controls || []) {
|
|
13067
13174
|
if (controlIds.has(control.id)) {
|
|
13068
13175
|
diagnostics.push({ severity: "error", code: "DUPLICATE_CONTROL_ID", message: `Duplicate control ID: ${control.id}` });
|
|
13069
13176
|
}
|
|
13070
13177
|
controlIds.add(control.id);
|
|
13071
|
-
if (
|
|
13072
|
-
diagnostics.push({ severity: "error", code: "
|
|
13178
|
+
if (control.target.transform !== void 0) {
|
|
13179
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TRANSFORM", message: `Control ${control.id} primary target cannot have a transform` });
|
|
13180
|
+
}
|
|
13181
|
+
if (control.additionalTargets !== void 0 && !Array.isArray(control.additionalTargets)) {
|
|
13182
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TARGETS", message: `Control ${control.id} additionalTargets must be an array` });
|
|
13183
|
+
continue;
|
|
13073
13184
|
}
|
|
13074
|
-
|
|
13075
|
-
|
|
13185
|
+
const targets = [
|
|
13186
|
+
{ target: control.target, primary: true },
|
|
13187
|
+
...(control.additionalTargets || []).map((target) => ({ target, primary: false }))
|
|
13188
|
+
];
|
|
13189
|
+
if ((control.additionalTargets || []).length > MAX_ADDITIONAL_TARGETS) {
|
|
13190
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TARGET_LIMIT", message: `Control ${control.id} exceeds the ${MAX_ADDITIONAL_TARGETS}-additional-target limit` });
|
|
13191
|
+
}
|
|
13192
|
+
for (const { target, primary } of targets) {
|
|
13193
|
+
const targetPath = `${control.id}.${primary ? "target" : "additionalTargets"}`;
|
|
13194
|
+
if (!ids.has(target.nodeId)) {
|
|
13195
|
+
diagnostics.push({ severity: "error", code: primary ? "CONTROL_TARGET" : "CONTROL_ADDITIONAL_TARGET", message: `Control ${control.id} targets missing node ${target.nodeId}` });
|
|
13196
|
+
continue;
|
|
13197
|
+
}
|
|
13198
|
+
if (!target.propertyPath || target.propertyPath.split(".").some((part) => UNSAFE_PATH_PARTS.has(part))) {
|
|
13199
|
+
diagnostics.push({ severity: "error", code: "UNSAFE_TARGET", message: `Control ${control.id} has an unsafe target path` });
|
|
13200
|
+
continue;
|
|
13201
|
+
}
|
|
13202
|
+
const key = `${target.nodeId}\0${target.propertyPath}`;
|
|
13203
|
+
const owner = targetOwners.get(key);
|
|
13204
|
+
if (owner) {
|
|
13205
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TARGET_CONFLICT", message: `Controls ${owner} and ${control.id} write the same target ${target.nodeId}.${target.propertyPath}` });
|
|
13206
|
+
} else {
|
|
13207
|
+
targetOwners.set(key, control.id);
|
|
13208
|
+
}
|
|
13209
|
+
const node = (document2.nodes || []).find((candidate) => candidate.id === target.nodeId);
|
|
13210
|
+
const resolved = node ? readPath(node, target.propertyPath) : { exists: false };
|
|
13211
|
+
if (primary && !options.strictControlTargets) continue;
|
|
13212
|
+
if (!resolved.exists) {
|
|
13213
|
+
diagnostics.push({ severity: "error", code: "CONTROL_PROPERTY_PATH", message: `Control ${control.id} targets a missing property ${target.propertyPath}`, nodeId: target.nodeId });
|
|
13214
|
+
continue;
|
|
13215
|
+
}
|
|
13216
|
+
validateTargetTransform(control, target, resolved.value, diagnostics, targetPath);
|
|
13076
13217
|
}
|
|
13077
13218
|
}
|
|
13078
13219
|
const regions = [timing.intro, timing.outro, timing.loop].filter(Boolean);
|
|
@@ -13083,13 +13224,34 @@ function validateTextTemplateArtifact(artifact) {
|
|
|
13083
13224
|
});
|
|
13084
13225
|
return diagnostics;
|
|
13085
13226
|
}
|
|
13086
|
-
function assertValidTextTemplateArtifact(artifact) {
|
|
13087
|
-
const errors = validateTextTemplateArtifact(artifact).filter((diagnostic) => diagnostic.severity === "error");
|
|
13227
|
+
function assertValidTextTemplateArtifact(artifact, options = {}) {
|
|
13228
|
+
const errors = validateTextTemplateArtifact(artifact, options).filter((diagnostic) => diagnostic.severity === "error");
|
|
13088
13229
|
if (errors.length) {
|
|
13089
13230
|
throw new Error(errors.map((diagnostic) => diagnostic.message).join("; "));
|
|
13090
13231
|
}
|
|
13091
13232
|
}
|
|
13092
13233
|
|
|
13234
|
+
// src/textTemplates/compatibility.ts
|
|
13235
|
+
function versionParts(version) {
|
|
13236
|
+
return version.split(".").map((part) => Number.parseInt(part, 10)).map((part) => Number.isFinite(part) ? part : 0);
|
|
13237
|
+
}
|
|
13238
|
+
function isTextTemplateRendererVersionNewer(required, current = TEXT_TEMPLATE_RENDERER_VERSION) {
|
|
13239
|
+
const requiredParts = versionParts(required);
|
|
13240
|
+
const currentParts = versionParts(current);
|
|
13241
|
+
for (let index = 0; index < Math.max(requiredParts.length, currentParts.length); index += 1) {
|
|
13242
|
+
const requiredPart = requiredParts[index] ?? 0;
|
|
13243
|
+
const currentPart = currentParts[index] ?? 0;
|
|
13244
|
+
if (requiredPart !== currentPart) return requiredPart > currentPart;
|
|
13245
|
+
}
|
|
13246
|
+
return false;
|
|
13247
|
+
}
|
|
13248
|
+
function assertCompatibleTextTemplateRenderer(artifact, current = TEXT_TEMPLATE_RENDERER_VERSION) {
|
|
13249
|
+
const required = artifact.revision?.rendererVersion;
|
|
13250
|
+
if (required && isTextTemplateRendererVersionNewer(required, current)) {
|
|
13251
|
+
throw new Error(`Text template requires renderer ${required}, but this engine supports ${current}`);
|
|
13252
|
+
}
|
|
13253
|
+
}
|
|
13254
|
+
|
|
13093
13255
|
// src/textTemplates/compiler.ts
|
|
13094
13256
|
function clone3(value) {
|
|
13095
13257
|
return JSON.parse(JSON.stringify(value));
|
|
@@ -13113,6 +13275,20 @@ function setPath(target, path, value) {
|
|
|
13113
13275
|
}
|
|
13114
13276
|
cursor[parts[parts.length - 1]] = value;
|
|
13115
13277
|
}
|
|
13278
|
+
function transformTargetValue(value, target, fallback) {
|
|
13279
|
+
const transform = target.transform;
|
|
13280
|
+
if (!transform) return value;
|
|
13281
|
+
if (transform.kind === "linear") {
|
|
13282
|
+
return typeof value === "number" && Number.isFinite(value) ? value * transform.scale + transform.offset : value;
|
|
13283
|
+
}
|
|
13284
|
+
if (transform.kind === "enumMap" && typeof value === "string" && Object.prototype.hasOwnProperty.call(transform.values, value)) {
|
|
13285
|
+
return transform.values[value];
|
|
13286
|
+
}
|
|
13287
|
+
if (transform.kind === "enumMap" && typeof fallback === "string" && Object.prototype.hasOwnProperty.call(transform.values, fallback)) {
|
|
13288
|
+
return transform.values[fallback];
|
|
13289
|
+
}
|
|
13290
|
+
return value;
|
|
13291
|
+
}
|
|
13116
13292
|
function finite(value, fallback) {
|
|
13117
13293
|
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
13118
13294
|
}
|
|
@@ -13160,6 +13336,8 @@ function resolveControls(controls, values) {
|
|
|
13160
13336
|
) : control.defaultValue;
|
|
13161
13337
|
} else if (control.type === "boolean") {
|
|
13162
13338
|
resolved[control.id] = value === true;
|
|
13339
|
+
} else if (control.type === "enum" && control.constraints?.options && !control.constraints.options.some((option) => option.value === value)) {
|
|
13340
|
+
resolved[control.id] = control.defaultValue;
|
|
13163
13341
|
} else {
|
|
13164
13342
|
resolved[control.id] = value;
|
|
13165
13343
|
}
|
|
@@ -13291,11 +13469,18 @@ function evaluateNodeProperty(node, property, fallback, time, duration) {
|
|
|
13291
13469
|
}
|
|
13292
13470
|
function compileTextTemplate(artifact, context) {
|
|
13293
13471
|
assertValidTextTemplateArtifact(artifact);
|
|
13472
|
+
assertCompatibleTextTemplateRenderer(artifact);
|
|
13294
13473
|
const resolvedControls = resolveControls(artifact.controls, context.controlValues);
|
|
13295
13474
|
const document2 = clone3(artifact.document);
|
|
13296
13475
|
for (const control of artifact.controls || []) {
|
|
13297
13476
|
const node = findNode(document2.nodes, control.target.nodeId);
|
|
13298
13477
|
if (node) setPath(node, control.target.propertyPath, resolvedControls[control.id]);
|
|
13478
|
+
for (const target of control.additionalTargets || []) {
|
|
13479
|
+
const additionalNode = findNode(document2.nodes, target.nodeId);
|
|
13480
|
+
if (additionalNode) {
|
|
13481
|
+
setPath(additionalNode, target.propertyPath, transformTargetValue(resolvedControls[control.id], target, control.defaultValue));
|
|
13482
|
+
}
|
|
13483
|
+
}
|
|
13299
13484
|
}
|
|
13300
13485
|
if (context.controlValues) {
|
|
13301
13486
|
for (const node of document2.nodes || []) {
|
|
@@ -13406,7 +13591,7 @@ function compileTextTemplate(artifact, context) {
|
|
|
13406
13591
|
const measuredSize = node.type === "text" ? measureTextNode(node, context.runtime) : void 0;
|
|
13407
13592
|
const resolvedWidth = flexPos?.width ?? (node.width === "auto" ? measuredSize?.width ?? 1 : evaluateNodeProperty(node, "width", Number(node.width), time, artifact.timing.duration));
|
|
13408
13593
|
const resolvedHeight = flexPos?.height ?? (node.height === "auto" ? measuredSize?.height ?? 1 : evaluateNodeProperty(node, "height", Number(node.height), time, artifact.timing.duration));
|
|
13409
|
-
const baseOpacity = node.type === "
|
|
13594
|
+
const baseOpacity = node.type === "container" ? node.style?.opacity ?? 1 : 1;
|
|
13410
13595
|
return {
|
|
13411
13596
|
id: node.id,
|
|
13412
13597
|
type: node.type,
|
|
@@ -25283,6 +25468,508 @@ async function calculateSha256(data) {
|
|
|
25283
25468
|
}
|
|
25284
25469
|
}
|
|
25285
25470
|
|
|
25471
|
+
// src/captions/presets.ts
|
|
25472
|
+
var CAPTION_PRESET_CLASSIC_SUBTITLE = {
|
|
25473
|
+
id: "classic-subtitle",
|
|
25474
|
+
name: "Classic Subtitle",
|
|
25475
|
+
fontFamily: "Inter Variable",
|
|
25476
|
+
fontWeight: 600,
|
|
25477
|
+
fontStyle: "normal",
|
|
25478
|
+
fontSize: 48,
|
|
25479
|
+
letterSpacing: 0,
|
|
25480
|
+
lineHeight: 1.25,
|
|
25481
|
+
textTransform: "none",
|
|
25482
|
+
textAlign: "center",
|
|
25483
|
+
verticalAlign: "bottom",
|
|
25484
|
+
inactiveColor: "#FFFFFF",
|
|
25485
|
+
inactiveOpacity: 0.95,
|
|
25486
|
+
activeColor: "#FFFFFF",
|
|
25487
|
+
activeScale: 1,
|
|
25488
|
+
strokeEnabled: true,
|
|
25489
|
+
strokeColor: "#000000",
|
|
25490
|
+
strokeWidth: 4,
|
|
25491
|
+
shadowEnabled: true,
|
|
25492
|
+
shadowColor: "rgba(0, 0, 0, 0.75)",
|
|
25493
|
+
shadowBlur: 6,
|
|
25494
|
+
shadowOffsetX: 0,
|
|
25495
|
+
shadowOffsetY: 2,
|
|
25496
|
+
backgroundEnabled: false
|
|
25497
|
+
};
|
|
25498
|
+
var CAPTION_PRESET_KARAOKE_POP = {
|
|
25499
|
+
id: "karaoke-pop",
|
|
25500
|
+
name: "Karaoke Pop",
|
|
25501
|
+
fontFamily: "Outfit Variable",
|
|
25502
|
+
fontWeight: 700,
|
|
25503
|
+
fontStyle: "normal",
|
|
25504
|
+
fontSize: 54,
|
|
25505
|
+
letterSpacing: 0.5,
|
|
25506
|
+
lineHeight: 1.3,
|
|
25507
|
+
textTransform: "none",
|
|
25508
|
+
textAlign: "center",
|
|
25509
|
+
verticalAlign: "bottom",
|
|
25510
|
+
inactiveColor: "#FFFFFF",
|
|
25511
|
+
inactiveOpacity: 0.55,
|
|
25512
|
+
activeColor: "#38BDF8",
|
|
25513
|
+
activeScale: 1.12,
|
|
25514
|
+
activeWordAnim: "pop",
|
|
25515
|
+
strokeEnabled: true,
|
|
25516
|
+
strokeColor: "#000000",
|
|
25517
|
+
strokeWidth: 5,
|
|
25518
|
+
shadowEnabled: true,
|
|
25519
|
+
shadowColor: "rgba(0, 0, 0, 0.8)",
|
|
25520
|
+
shadowBlur: 8,
|
|
25521
|
+
shadowOffsetX: 0,
|
|
25522
|
+
shadowOffsetY: 3,
|
|
25523
|
+
backgroundEnabled: false
|
|
25524
|
+
};
|
|
25525
|
+
var CAPTION_PRESET_BOLD_PUNCH = {
|
|
25526
|
+
id: "bold-punch",
|
|
25527
|
+
name: "Bold Punch",
|
|
25528
|
+
fontFamily: "Montserrat Variable",
|
|
25529
|
+
fontWeight: 900,
|
|
25530
|
+
fontStyle: "normal",
|
|
25531
|
+
fontSize: 56,
|
|
25532
|
+
letterSpacing: 1,
|
|
25533
|
+
lineHeight: 1.2,
|
|
25534
|
+
textTransform: "uppercase",
|
|
25535
|
+
textAlign: "center",
|
|
25536
|
+
verticalAlign: "bottom",
|
|
25537
|
+
inactiveColor: "#FFFFFF",
|
|
25538
|
+
inactiveOpacity: 0.6,
|
|
25539
|
+
activeColor: "#E11D48",
|
|
25540
|
+
activeScale: 1.08,
|
|
25541
|
+
activeWordAnim: "pop",
|
|
25542
|
+
strokeEnabled: true,
|
|
25543
|
+
strokeColor: "#000000",
|
|
25544
|
+
strokeWidth: 6,
|
|
25545
|
+
shadowEnabled: true,
|
|
25546
|
+
shadowColor: "rgba(0, 0, 0, 0.9)",
|
|
25547
|
+
shadowBlur: 10,
|
|
25548
|
+
shadowOffsetX: 3,
|
|
25549
|
+
shadowOffsetY: 4,
|
|
25550
|
+
backgroundEnabled: false
|
|
25551
|
+
};
|
|
25552
|
+
var CAPTION_PRESET_CLEAN_MINIMAL = {
|
|
25553
|
+
id: "clean-minimal",
|
|
25554
|
+
name: "Clean Minimal",
|
|
25555
|
+
fontFamily: "Inter Variable",
|
|
25556
|
+
fontWeight: 500,
|
|
25557
|
+
fontStyle: "normal",
|
|
25558
|
+
fontSize: 42,
|
|
25559
|
+
letterSpacing: 0,
|
|
25560
|
+
lineHeight: 1.3,
|
|
25561
|
+
textTransform: "none",
|
|
25562
|
+
textAlign: "center",
|
|
25563
|
+
verticalAlign: "bottom",
|
|
25564
|
+
inactiveColor: "#E2E8F0",
|
|
25565
|
+
inactiveOpacity: 0.7,
|
|
25566
|
+
activeColor: "#FFFFFF",
|
|
25567
|
+
activeScale: 1,
|
|
25568
|
+
strokeEnabled: false,
|
|
25569
|
+
shadowEnabled: false,
|
|
25570
|
+
backgroundEnabled: true,
|
|
25571
|
+
backgroundColor: "rgba(15, 23, 42, 0.75)",
|
|
25572
|
+
backgroundPaddingX: 20,
|
|
25573
|
+
backgroundPaddingY: 10,
|
|
25574
|
+
backgroundBorderRadius: 14
|
|
25575
|
+
};
|
|
25576
|
+
var CAPTION_PRESET_CINEMATIC_GOLD = {
|
|
25577
|
+
id: "cinematic-gold",
|
|
25578
|
+
name: "Cinematic Gold",
|
|
25579
|
+
fontFamily: "Outfit Variable",
|
|
25580
|
+
fontWeight: 600,
|
|
25581
|
+
fontStyle: "normal",
|
|
25582
|
+
fontSize: 48,
|
|
25583
|
+
letterSpacing: 2,
|
|
25584
|
+
lineHeight: 1.35,
|
|
25585
|
+
textTransform: "none",
|
|
25586
|
+
textAlign: "center",
|
|
25587
|
+
verticalAlign: "bottom",
|
|
25588
|
+
inactiveColor: "#E2E8F0",
|
|
25589
|
+
inactiveOpacity: 0.55,
|
|
25590
|
+
activeColor: "#FBBF24",
|
|
25591
|
+
activeScale: 1.05,
|
|
25592
|
+
strokeEnabled: true,
|
|
25593
|
+
strokeColor: "#000000",
|
|
25594
|
+
strokeWidth: 3.5,
|
|
25595
|
+
shadowEnabled: true,
|
|
25596
|
+
shadowColor: "rgba(251, 191, 36, 0.35)",
|
|
25597
|
+
shadowBlur: 14,
|
|
25598
|
+
shadowOffsetX: 0,
|
|
25599
|
+
shadowOffsetY: 2,
|
|
25600
|
+
backgroundEnabled: false
|
|
25601
|
+
};
|
|
25602
|
+
var CAPTION_PRESET_NEON_GLOW = {
|
|
25603
|
+
id: "neon-glow",
|
|
25604
|
+
name: "Neon Glow",
|
|
25605
|
+
fontFamily: "Montserrat Variable",
|
|
25606
|
+
fontWeight: 800,
|
|
25607
|
+
fontStyle: "normal",
|
|
25608
|
+
fontSize: 52,
|
|
25609
|
+
letterSpacing: 1,
|
|
25610
|
+
lineHeight: 1.25,
|
|
25611
|
+
textTransform: "none",
|
|
25612
|
+
textAlign: "center",
|
|
25613
|
+
verticalAlign: "bottom",
|
|
25614
|
+
inactiveColor: "#94A3B8",
|
|
25615
|
+
inactiveOpacity: 0.5,
|
|
25616
|
+
activeColor: "#22D3EE",
|
|
25617
|
+
activeScale: 1.06,
|
|
25618
|
+
activeWordAnim: "glow",
|
|
25619
|
+
strokeEnabled: true,
|
|
25620
|
+
strokeColor: "#0891B2",
|
|
25621
|
+
strokeWidth: 4,
|
|
25622
|
+
glowEnabled: true,
|
|
25623
|
+
glowColor: "#06B6D4",
|
|
25624
|
+
glowBlur: 16,
|
|
25625
|
+
shadowEnabled: true,
|
|
25626
|
+
shadowColor: "rgba(0, 0, 0, 0.8)",
|
|
25627
|
+
shadowBlur: 8,
|
|
25628
|
+
shadowOffsetX: 0,
|
|
25629
|
+
shadowOffsetY: 2,
|
|
25630
|
+
backgroundEnabled: false
|
|
25631
|
+
};
|
|
25632
|
+
var BUILT_IN_CAPTION_PRESETS = {
|
|
25633
|
+
"classic-subtitle": CAPTION_PRESET_CLASSIC_SUBTITLE,
|
|
25634
|
+
"karaoke-pop": CAPTION_PRESET_KARAOKE_POP,
|
|
25635
|
+
"bold-punch": CAPTION_PRESET_BOLD_PUNCH,
|
|
25636
|
+
"clean-minimal": CAPTION_PRESET_CLEAN_MINIMAL,
|
|
25637
|
+
"cinematic-gold": CAPTION_PRESET_CINEMATIC_GOLD,
|
|
25638
|
+
"neon-glow": CAPTION_PRESET_NEON_GLOW
|
|
25639
|
+
};
|
|
25640
|
+
function getCaptionPreset(idOrPreset) {
|
|
25641
|
+
if (!idOrPreset) return CAPTION_PRESET_CLASSIC_SUBTITLE;
|
|
25642
|
+
if (typeof idOrPreset === "object") return idOrPreset;
|
|
25643
|
+
const match = BUILT_IN_CAPTION_PRESETS[idOrPreset];
|
|
25644
|
+
return match ?? CAPTION_PRESET_CLASSIC_SUBTITLE;
|
|
25645
|
+
}
|
|
25646
|
+
function hashCaptionPreset(preset) {
|
|
25647
|
+
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}`;
|
|
25648
|
+
let hash = 2166136261;
|
|
25649
|
+
for (let i = 0; i < str.length; i++) {
|
|
25650
|
+
hash ^= str.charCodeAt(i);
|
|
25651
|
+
hash = Math.imul(hash, 16777619);
|
|
25652
|
+
}
|
|
25653
|
+
return (hash >>> 0).toString(16);
|
|
25654
|
+
}
|
|
25655
|
+
|
|
25656
|
+
// src/captions/engine.ts
|
|
25657
|
+
var PAUSE_RELEASE_THRESHOLD_MS = 250;
|
|
25658
|
+
var DEFAULT_MAX_WORDS_PER_LINE = 5;
|
|
25659
|
+
var DEFAULT_MAX_LINES = 2;
|
|
25660
|
+
var DEFAULT_PAUSE_BREAK_MS = 350;
|
|
25661
|
+
var CaptionEngine = class {
|
|
25662
|
+
/**
|
|
25663
|
+
* Paginates a flat stream of words into structured caption cues.
|
|
25664
|
+
* Enforces max words per line, max lines, pause thresholds, and punctuation breaks.
|
|
25665
|
+
*/
|
|
25666
|
+
static paginateWords(words, config = {}) {
|
|
25667
|
+
if (!words.length) return [];
|
|
25668
|
+
const maxWordsPerLine = config.maxWordsPerLine ?? DEFAULT_MAX_WORDS_PER_LINE;
|
|
25669
|
+
const maxLines = config.maxLines ?? DEFAULT_MAX_LINES;
|
|
25670
|
+
const maxWordsPerCue = maxWordsPerLine * maxLines;
|
|
25671
|
+
const pauseBreakMs = config.pauseBreakMs ?? DEFAULT_PAUSE_BREAK_MS;
|
|
25672
|
+
const cues = [];
|
|
25673
|
+
let currentCueWords = [];
|
|
25674
|
+
for (let i = 0; i < words.length; i++) {
|
|
25675
|
+
const currentWord = words[i];
|
|
25676
|
+
const nextWord = words[i + 1];
|
|
25677
|
+
currentCueWords.push(currentWord);
|
|
25678
|
+
const hasReachedMaxWords = currentCueWords.length >= maxWordsPerCue;
|
|
25679
|
+
const isTerminalPunctuation = /[.!?]$/.test(currentWord.text.trim());
|
|
25680
|
+
const hasPauseBreak = nextWord && nextWord.startMs - currentWord.endMs >= pauseBreakMs;
|
|
25681
|
+
const isLastWord = i === words.length - 1;
|
|
25682
|
+
if (hasReachedMaxWords || isTerminalPunctuation || hasPauseBreak || isLastWord) {
|
|
25683
|
+
const text = currentCueWords.map((w) => w.text).join(" ");
|
|
25684
|
+
const startMs = currentCueWords[0].startMs;
|
|
25685
|
+
const endMs = currentCueWords[currentCueWords.length - 1].endMs;
|
|
25686
|
+
const id = `cue_${startMs}_${endMs}`;
|
|
25687
|
+
cues.push({
|
|
25688
|
+
id,
|
|
25689
|
+
words: [...currentCueWords],
|
|
25690
|
+
text,
|
|
25691
|
+
startMs,
|
|
25692
|
+
endMs
|
|
25693
|
+
});
|
|
25694
|
+
currentCueWords = [];
|
|
25695
|
+
}
|
|
25696
|
+
}
|
|
25697
|
+
return cues;
|
|
25698
|
+
}
|
|
25699
|
+
/**
|
|
25700
|
+
* Resolves the active word index within a cue for a given playback time in milliseconds.
|
|
25701
|
+
* Returns -1 if no word is active or during the pause release window (> 250ms after speech ends).
|
|
25702
|
+
*/
|
|
25703
|
+
static resolveActiveWordIndex(cue, currentTimeMs) {
|
|
25704
|
+
if (!cue.words.length) return -1;
|
|
25705
|
+
if (currentTimeMs < cue.words[0].startMs) return -1;
|
|
25706
|
+
for (let i = 0; i < cue.words.length; i++) {
|
|
25707
|
+
const w = cue.words[i];
|
|
25708
|
+
const nextWord = cue.words[i + 1];
|
|
25709
|
+
if (currentTimeMs >= w.startMs && currentTimeMs < w.endMs) {
|
|
25710
|
+
return i;
|
|
25711
|
+
}
|
|
25712
|
+
if (currentTimeMs >= w.endMs && nextWord && currentTimeMs < nextWord.startMs) {
|
|
25713
|
+
const gap = nextWord.startMs - w.endMs;
|
|
25714
|
+
if (gap <= PAUSE_RELEASE_THRESHOLD_MS) {
|
|
25715
|
+
return i;
|
|
25716
|
+
}
|
|
25717
|
+
if (currentTimeMs < w.endMs + PAUSE_RELEASE_THRESHOLD_MS) {
|
|
25718
|
+
return i;
|
|
25719
|
+
}
|
|
25720
|
+
return -1;
|
|
25721
|
+
}
|
|
25722
|
+
}
|
|
25723
|
+
const lastWord = cue.words[cue.words.length - 1];
|
|
25724
|
+
if (currentTimeMs >= lastWord.endMs) {
|
|
25725
|
+
if (currentTimeMs < lastWord.endMs + PAUSE_RELEASE_THRESHOLD_MS) {
|
|
25726
|
+
return cue.words.length - 1;
|
|
25727
|
+
}
|
|
25728
|
+
return -1;
|
|
25729
|
+
}
|
|
25730
|
+
return -1;
|
|
25731
|
+
}
|
|
25732
|
+
/**
|
|
25733
|
+
* Builds the canonical raster cache key for a caption frame.
|
|
25734
|
+
* Format: `caption:${clipId}:${segmentId}:${activeWordIndex}:${presetHash}:${fontLoaded}`
|
|
25735
|
+
*/
|
|
25736
|
+
static buildCacheKey(clipId, segmentId, activeWordIndex, preset, fontLoaded) {
|
|
25737
|
+
const presetHash = hashCaptionPreset(preset);
|
|
25738
|
+
return `caption:${clipId}:${segmentId}:${activeWordIndex}:${presetHash}:${fontLoaded ? 1 : 0}`;
|
|
25739
|
+
}
|
|
25740
|
+
/**
|
|
25741
|
+
* Computes multi-line word layout and bounding boxes for a cue.
|
|
25742
|
+
*/
|
|
25743
|
+
static computeLayout(ctx, cue, activeWordIndex, preset, canvasWidth, canvasHeight, scale = 1, positionYRatio = 0.85) {
|
|
25744
|
+
const fontSize = Math.round(preset.fontSize * scale);
|
|
25745
|
+
const lineHeight = fontSize * preset.lineHeight;
|
|
25746
|
+
const fontStr = `${preset.fontStyle} ${preset.fontWeight} ${fontSize}px "${preset.fontFamily}", sans-serif`;
|
|
25747
|
+
ctx.font = fontStr;
|
|
25748
|
+
const maxLineWidth = Math.max(200, canvasWidth * 0.85);
|
|
25749
|
+
const spaceWidth = ctx.measureText(" ").width;
|
|
25750
|
+
const lines = [];
|
|
25751
|
+
let curLineWords = [];
|
|
25752
|
+
let curLineIndices = [];
|
|
25753
|
+
let curLineWidths = [];
|
|
25754
|
+
let curLineWidth = 0;
|
|
25755
|
+
for (let i = 0; i < cue.words.length; i++) {
|
|
25756
|
+
const word = cue.words[i];
|
|
25757
|
+
const displayText = preset.textTransform === "uppercase" ? word.text.toUpperCase() : preset.textTransform === "lowercase" ? word.text.toLowerCase() : word.text;
|
|
25758
|
+
const wWidth = ctx.measureText(displayText).width;
|
|
25759
|
+
const neededWidth = curLineWidth === 0 ? wWidth : curLineWidth + spaceWidth + wWidth;
|
|
25760
|
+
if (curLineWords.length > 0 && (neededWidth > maxLineWidth || curLineWords.length >= DEFAULT_MAX_WORDS_PER_LINE)) {
|
|
25761
|
+
lines.push({
|
|
25762
|
+
words: curLineWords,
|
|
25763
|
+
indices: curLineIndices,
|
|
25764
|
+
widths: curLineWidths
|
|
25765
|
+
});
|
|
25766
|
+
curLineWords = [word];
|
|
25767
|
+
curLineIndices = [i];
|
|
25768
|
+
curLineWidths = [wWidth];
|
|
25769
|
+
curLineWidth = wWidth;
|
|
25770
|
+
} else {
|
|
25771
|
+
curLineWords.push(word);
|
|
25772
|
+
curLineIndices.push(i);
|
|
25773
|
+
curLineWidths.push(wWidth);
|
|
25774
|
+
curLineWidth = neededWidth;
|
|
25775
|
+
}
|
|
25776
|
+
}
|
|
25777
|
+
if (curLineWords.length > 0) {
|
|
25778
|
+
lines.push({
|
|
25779
|
+
words: curLineWords,
|
|
25780
|
+
indices: curLineIndices,
|
|
25781
|
+
widths: curLineWidths
|
|
25782
|
+
});
|
|
25783
|
+
}
|
|
25784
|
+
const totalHeight = lines.length * lineHeight;
|
|
25785
|
+
const anchorCenterY = canvasHeight * positionYRatio;
|
|
25786
|
+
const startY = anchorCenterY - totalHeight / 2;
|
|
25787
|
+
const allWordBoxes = [];
|
|
25788
|
+
const lineLayouts = [];
|
|
25789
|
+
let overallMinX = Infinity;
|
|
25790
|
+
let overallMinY = Infinity;
|
|
25791
|
+
let overallMaxX = -Infinity;
|
|
25792
|
+
let overallMaxY = -Infinity;
|
|
25793
|
+
for (let l = 0; l < lines.length; l++) {
|
|
25794
|
+
const line = lines[l];
|
|
25795
|
+
const lineWidth = line.widths.reduce((a, b) => a + b, 0) + (line.words.length - 1) * spaceWidth;
|
|
25796
|
+
const lineY = startY + l * lineHeight;
|
|
25797
|
+
const baselineY = lineY + fontSize * 0.82;
|
|
25798
|
+
let startX = (canvasWidth - lineWidth) / 2;
|
|
25799
|
+
if (preset.textAlign === "left") {
|
|
25800
|
+
startX = canvasWidth * 0.08;
|
|
25801
|
+
} else if (preset.textAlign === "right") {
|
|
25802
|
+
startX = canvasWidth * 0.92 - lineWidth;
|
|
25803
|
+
}
|
|
25804
|
+
let curX = startX;
|
|
25805
|
+
const lineBoxes = [];
|
|
25806
|
+
for (let w = 0; w < line.words.length; w++) {
|
|
25807
|
+
const word = line.words[w];
|
|
25808
|
+
const wordIdx = line.indices[w];
|
|
25809
|
+
const wWidth = line.widths[w];
|
|
25810
|
+
const isActive = wordIdx === activeWordIndex;
|
|
25811
|
+
const box = {
|
|
25812
|
+
wordIndex: wordIdx,
|
|
25813
|
+
word,
|
|
25814
|
+
x: curX,
|
|
25815
|
+
y: lineY,
|
|
25816
|
+
width: wWidth,
|
|
25817
|
+
height: lineHeight,
|
|
25818
|
+
baselineY,
|
|
25819
|
+
isActive
|
|
25820
|
+
};
|
|
25821
|
+
lineBoxes.push(box);
|
|
25822
|
+
allWordBoxes.push(box);
|
|
25823
|
+
overallMinX = Math.min(overallMinX, curX);
|
|
25824
|
+
overallMinY = Math.min(overallMinY, lineY);
|
|
25825
|
+
overallMaxX = Math.max(overallMaxX, curX + wWidth);
|
|
25826
|
+
overallMaxY = Math.max(overallMaxY, lineY + lineHeight);
|
|
25827
|
+
curX += wWidth + spaceWidth;
|
|
25828
|
+
}
|
|
25829
|
+
lineLayouts.push({
|
|
25830
|
+
lineIndex: l,
|
|
25831
|
+
text: line.words.map((w) => w.text).join(" "),
|
|
25832
|
+
words: lineBoxes,
|
|
25833
|
+
width: lineWidth,
|
|
25834
|
+
height: lineHeight,
|
|
25835
|
+
x: startX,
|
|
25836
|
+
y: lineY
|
|
25837
|
+
});
|
|
25838
|
+
}
|
|
25839
|
+
const strokeBleed = preset.strokeEnabled ? (preset.strokeWidth ?? 4) * scale : 0;
|
|
25840
|
+
const shadowBleed = preset.shadowEnabled ? (preset.shadowBlur ?? 8) * scale : 0;
|
|
25841
|
+
const glowBleed = preset.glowEnabled ? (preset.glowBlur ?? 16) * scale : 0;
|
|
25842
|
+
const bgPadX = preset.backgroundEnabled ? (preset.backgroundPaddingX ?? 20) * scale : 0;
|
|
25843
|
+
const bgPadY = preset.backgroundEnabled ? (preset.backgroundPaddingY ?? 10) * scale : 0;
|
|
25844
|
+
const activeScaleBleed = fontSize * 0.25;
|
|
25845
|
+
const padX = Math.ceil(Math.max(strokeBleed + shadowBleed + glowBleed + activeScaleBleed, bgPadX));
|
|
25846
|
+
const padY = Math.ceil(Math.max(strokeBleed + shadowBleed + glowBleed + activeScaleBleed, bgPadY));
|
|
25847
|
+
const bounds = {
|
|
25848
|
+
x: Math.max(0, Math.floor(overallMinX - padX)),
|
|
25849
|
+
y: Math.max(0, Math.floor(overallMinY - padY)),
|
|
25850
|
+
width: Math.min(canvasWidth, Math.ceil(overallMaxX - overallMinX + padX * 2)),
|
|
25851
|
+
height: Math.min(canvasHeight, Math.ceil(overallMaxY - overallMinY + padY * 2))
|
|
25852
|
+
};
|
|
25853
|
+
return { bounds, wordBoxes: allWordBoxes, lines: lineLayouts };
|
|
25854
|
+
}
|
|
25855
|
+
};
|
|
25856
|
+
|
|
25857
|
+
// src/captions/renderer.ts
|
|
25858
|
+
function renderCaptionToCanvas(ctx, options) {
|
|
25859
|
+
const {
|
|
25860
|
+
cue,
|
|
25861
|
+
activeWordIndex,
|
|
25862
|
+
preset,
|
|
25863
|
+
canvasWidth,
|
|
25864
|
+
canvasHeight,
|
|
25865
|
+
scale = 1,
|
|
25866
|
+
positionYRatio = 0.85
|
|
25867
|
+
} = options;
|
|
25868
|
+
if (!cue.words || cue.words.length === 0) {
|
|
25869
|
+
return {
|
|
25870
|
+
bounds: { x: 0, y: 0, width: 0, height: 0 },
|
|
25871
|
+
wordBoxes: [],
|
|
25872
|
+
lines: []
|
|
25873
|
+
};
|
|
25874
|
+
}
|
|
25875
|
+
const layout = CaptionEngine.computeLayout(
|
|
25876
|
+
ctx,
|
|
25877
|
+
cue,
|
|
25878
|
+
activeWordIndex,
|
|
25879
|
+
preset,
|
|
25880
|
+
canvasWidth,
|
|
25881
|
+
canvasHeight,
|
|
25882
|
+
scale,
|
|
25883
|
+
positionYRatio
|
|
25884
|
+
);
|
|
25885
|
+
const fontSize = Math.round(preset.fontSize * scale);
|
|
25886
|
+
const fontStr = `${preset.fontStyle} ${preset.fontWeight} ${fontSize}px "${preset.fontFamily}", sans-serif`;
|
|
25887
|
+
ctx.font = fontStr;
|
|
25888
|
+
ctx.textBaseline = "alphabetic";
|
|
25889
|
+
if (preset.backgroundEnabled && preset.backgroundColor) {
|
|
25890
|
+
ctx.save();
|
|
25891
|
+
ctx.fillStyle = preset.backgroundColor;
|
|
25892
|
+
const padX = (preset.backgroundPaddingX ?? 18) * scale;
|
|
25893
|
+
const padY = (preset.backgroundPaddingY ?? 8) * scale;
|
|
25894
|
+
const radius = (preset.backgroundBorderRadius ?? 12) * scale;
|
|
25895
|
+
for (const line of layout.lines) {
|
|
25896
|
+
const bgX = line.x - padX;
|
|
25897
|
+
const bgY = line.y - padY / 2;
|
|
25898
|
+
const bgW = line.width + padX * 2;
|
|
25899
|
+
const bgH = line.height + padY;
|
|
25900
|
+
ctx.beginPath();
|
|
25901
|
+
if (typeof ctx.roundRect === "function") {
|
|
25902
|
+
ctx.roundRect(bgX, bgY, bgW, bgH, radius);
|
|
25903
|
+
} else {
|
|
25904
|
+
ctx.rect(bgX, bgY, bgW, bgH);
|
|
25905
|
+
}
|
|
25906
|
+
ctx.fill();
|
|
25907
|
+
}
|
|
25908
|
+
ctx.restore();
|
|
25909
|
+
}
|
|
25910
|
+
for (const box of layout.wordBoxes) {
|
|
25911
|
+
ctx.save();
|
|
25912
|
+
const displayText = preset.textTransform === "uppercase" ? box.word.text.toUpperCase() : preset.textTransform === "lowercase" ? box.word.text.toLowerCase() : box.word.text;
|
|
25913
|
+
const isActive = box.isActive;
|
|
25914
|
+
if (isActive && preset.activeBackgroundColor) {
|
|
25915
|
+
ctx.save();
|
|
25916
|
+
ctx.fillStyle = preset.activeBackgroundColor;
|
|
25917
|
+
const padX = (preset.activeBackgroundPaddingX ?? 8) * scale;
|
|
25918
|
+
const padY = (preset.activeBackgroundPaddingY ?? 4) * scale;
|
|
25919
|
+
const radius = (preset.activeBackgroundBorderRadius ?? 5) * scale;
|
|
25920
|
+
const bgX = box.x - padX;
|
|
25921
|
+
const bgY = box.y - padY / 2;
|
|
25922
|
+
const bgW = box.width + padX * 2;
|
|
25923
|
+
const bgH = box.height + padY;
|
|
25924
|
+
ctx.beginPath();
|
|
25925
|
+
if (typeof ctx.roundRect === "function") ctx.roundRect(bgX, bgY, bgW, bgH, radius);
|
|
25926
|
+
else ctx.rect(bgX, bgY, bgW, bgH);
|
|
25927
|
+
ctx.fill();
|
|
25928
|
+
ctx.restore();
|
|
25929
|
+
}
|
|
25930
|
+
if (isActive && preset.activeScale && preset.activeScale !== 1) {
|
|
25931
|
+
const centerX = box.x + box.width / 2;
|
|
25932
|
+
const centerY = box.y + box.height / 2;
|
|
25933
|
+
ctx.translate(centerX, centerY);
|
|
25934
|
+
ctx.scale(preset.activeScale, preset.activeScale);
|
|
25935
|
+
ctx.translate(-centerX, -centerY);
|
|
25936
|
+
}
|
|
25937
|
+
if (isActive && preset.glowEnabled && preset.glowColor) {
|
|
25938
|
+
ctx.shadowColor = preset.glowColor;
|
|
25939
|
+
ctx.shadowBlur = (preset.glowBlur ?? 16) * scale;
|
|
25940
|
+
ctx.shadowOffsetX = 0;
|
|
25941
|
+
ctx.shadowOffsetY = 0;
|
|
25942
|
+
} else if (preset.shadowEnabled && preset.shadowColor) {
|
|
25943
|
+
ctx.shadowColor = preset.shadowColor;
|
|
25944
|
+
ctx.shadowBlur = (preset.shadowBlur ?? 6) * scale;
|
|
25945
|
+
ctx.shadowOffsetX = (preset.shadowOffsetX ?? 0) * scale;
|
|
25946
|
+
ctx.shadowOffsetY = (preset.shadowOffsetY ?? 2) * scale;
|
|
25947
|
+
} else {
|
|
25948
|
+
ctx.shadowColor = "transparent";
|
|
25949
|
+
ctx.shadowBlur = 0;
|
|
25950
|
+
ctx.shadowOffsetX = 0;
|
|
25951
|
+
ctx.shadowOffsetY = 0;
|
|
25952
|
+
}
|
|
25953
|
+
if (preset.strokeEnabled) {
|
|
25954
|
+
ctx.lineWidth = (isActive && preset.activeStrokeWidth || preset.strokeWidth || 4) * scale;
|
|
25955
|
+
ctx.strokeStyle = isActive && preset.activeStrokeColor || preset.strokeColor || "#000000";
|
|
25956
|
+
ctx.lineJoin = "round";
|
|
25957
|
+
ctx.miterLimit = 2;
|
|
25958
|
+
ctx.strokeText(displayText, box.x, box.baselineY);
|
|
25959
|
+
}
|
|
25960
|
+
if (isActive) {
|
|
25961
|
+
ctx.fillStyle = preset.activeColor;
|
|
25962
|
+
ctx.globalAlpha = 1;
|
|
25963
|
+
} else {
|
|
25964
|
+
ctx.fillStyle = preset.inactiveColor;
|
|
25965
|
+
ctx.globalAlpha = preset.inactiveOpacity;
|
|
25966
|
+
}
|
|
25967
|
+
ctx.fillText(displayText, box.x, box.baselineY);
|
|
25968
|
+
ctx.restore();
|
|
25969
|
+
}
|
|
25970
|
+
return layout;
|
|
25971
|
+
}
|
|
25972
|
+
|
|
25286
25973
|
// src/index.ts
|
|
25287
25974
|
var VERSION = "1.4.0";
|
|
25288
25975
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -25295,11 +25982,19 @@ var VERSION = "1.4.0";
|
|
|
25295
25982
|
AnimationValidator,
|
|
25296
25983
|
AssetRegistry,
|
|
25297
25984
|
BUILTIN_CANVAS_TEMPLATES,
|
|
25985
|
+
BUILT_IN_CAPTION_PRESETS,
|
|
25298
25986
|
BoundingBoxSchema,
|
|
25299
25987
|
CANONICAL_RENDERER_VERSION,
|
|
25300
25988
|
CANONICAL_SCHEMA_VERSION,
|
|
25989
|
+
CAPTION_PRESET_BOLD_PUNCH,
|
|
25990
|
+
CAPTION_PRESET_CINEMATIC_GOLD,
|
|
25991
|
+
CAPTION_PRESET_CLASSIC_SUBTITLE,
|
|
25992
|
+
CAPTION_PRESET_CLEAN_MINIMAL,
|
|
25993
|
+
CAPTION_PRESET_KARAOKE_POP,
|
|
25994
|
+
CAPTION_PRESET_NEON_GLOW,
|
|
25301
25995
|
COMPOSITION_PRESETS,
|
|
25302
25996
|
CanvasDevice,
|
|
25997
|
+
CaptionEngine,
|
|
25303
25998
|
CommandBufferBuilder,
|
|
25304
25999
|
CommandExecutor,
|
|
25305
26000
|
CommandHistory,
|
|
@@ -25308,6 +26003,9 @@ var VERSION = "1.4.0";
|
|
|
25308
26003
|
DEFAULT_DURATION,
|
|
25309
26004
|
DEFAULT_FONT_SIZE,
|
|
25310
26005
|
DEFAULT_FPS,
|
|
26006
|
+
DEFAULT_MAX_LINES,
|
|
26007
|
+
DEFAULT_MAX_WORDS_PER_LINE,
|
|
26008
|
+
DEFAULT_PAUSE_BREAK_MS,
|
|
25311
26009
|
DEFAULT_TEXT_STYLE,
|
|
25312
26010
|
DataBindingAuthoringEngine,
|
|
25313
26011
|
DataBindingEngine,
|
|
@@ -25360,6 +26058,7 @@ var VERSION = "1.4.0";
|
|
|
25360
26058
|
Mp4VideoEncoder,
|
|
25361
26059
|
NodeRegistry,
|
|
25362
26060
|
NullBackend,
|
|
26061
|
+
PAUSE_RELEASE_THRESHOLD_MS,
|
|
25363
26062
|
PngSequenceEncoder,
|
|
25364
26063
|
PrimitiveRegistry,
|
|
25365
26064
|
ProResVideoEncoder,
|
|
@@ -25425,6 +26124,7 @@ var VERSION = "1.4.0";
|
|
|
25425
26124
|
applyStyleToLottie,
|
|
25426
26125
|
applyStyleToLottieLayer,
|
|
25427
26126
|
applyTimelineAtTime,
|
|
26127
|
+
assertCompatibleTextTemplateRenderer,
|
|
25428
26128
|
assertValidTextTemplateArtifact,
|
|
25429
26129
|
assetRegistry,
|
|
25430
26130
|
bakeAnimationIntoLayer,
|
|
@@ -25529,6 +26229,7 @@ var VERSION = "1.4.0";
|
|
|
25529
26229
|
getAnimatableParamsForLayer,
|
|
25530
26230
|
getCanvasTemplatePreset,
|
|
25531
26231
|
getCanvasTemplatesByCategory,
|
|
26232
|
+
getCaptionPreset,
|
|
25532
26233
|
getClipLayout,
|
|
25533
26234
|
getDefaultText,
|
|
25534
26235
|
getEffectByIdForApi,
|
|
@@ -25557,6 +26258,7 @@ var VERSION = "1.4.0";
|
|
|
25557
26258
|
getTransitionsByCategory,
|
|
25558
26259
|
getTransitionsByTags,
|
|
25559
26260
|
getWebMFrameCount,
|
|
26261
|
+
hashCaptionPreset,
|
|
25560
26262
|
hexToLottieColor,
|
|
25561
26263
|
hexToLottieRgb,
|
|
25562
26264
|
hexToRgba,
|
|
@@ -25575,6 +26277,7 @@ var VERSION = "1.4.0";
|
|
|
25575
26277
|
interpolateValue,
|
|
25576
26278
|
isKeyframed,
|
|
25577
26279
|
isMp4ExportSupported,
|
|
26280
|
+
isTextTemplateRendererVersionNewer,
|
|
25578
26281
|
isWebMExportSupported,
|
|
25579
26282
|
layerToTextEffectConfig,
|
|
25580
26283
|
layoutEngine,
|
|
@@ -25614,6 +26317,7 @@ var VERSION = "1.4.0";
|
|
|
25614
26317
|
renderBubbleBackground,
|
|
25615
26318
|
renderBubblePresetBackground,
|
|
25616
26319
|
renderCanonicalToCanvas,
|
|
26320
|
+
renderCaptionToCanvas,
|
|
25617
26321
|
renderEvaluatedSceneToCanvas,
|
|
25618
26322
|
renderPngSequence,
|
|
25619
26323
|
renderSceneWebM,
|