@meframe/core 0.5.9 → 0.5.10
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/orchestrator/CompositionPlanner.d.ts.map +1 -1
- package/dist/orchestrator/CompositionPlanner.js +6 -1
- package/dist/orchestrator/CompositionPlanner.js.map +1 -1
- package/dist/stages/compose/text-renderers/basic-text-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/basic-text-renderer.js +6 -18
- package/dist/stages/compose/text-renderers/basic-text-renderer.js.map +1 -1
- package/dist/stages/compose/text-renderers/caption-stagger-entrance-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/caption-stagger-entrance-renderer.js +6 -18
- package/dist/stages/compose/text-renderers/caption-stagger-entrance-renderer.js.map +1 -1
- package/dist/stages/compose/text-renderers/character-ktv-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/character-ktv-renderer.js +6 -18
- package/dist/stages/compose/text-renderers/character-ktv-renderer.js.map +1 -1
- package/dist/stages/compose/text-renderers/word-by-word-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/word-by-word-renderer.js +6 -18
- package/dist/stages/compose/text-renderers/word-by-word-renderer.js.map +1 -1
- package/dist/stages/compose/text-renderers/word-fancy-renderer.d.ts.map +1 -1
- package/dist/stages/compose/text-renderers/word-fancy-renderer.js +6 -18
- package/dist/stages/compose/text-renderers/word-fancy-renderer.js.map +1 -1
- package/dist/stages/compose/text-utils/caption-position.d.ts +12 -0
- package/dist/stages/compose/text-utils/caption-position.d.ts.map +1 -0
- package/dist/stages/compose/text-utils/caption-position.js +21 -0
- package/dist/stages/compose/text-utils/caption-position.js.map +1 -0
- package/dist/workers/stages/export/{export.worker.CWPrx2Nf.js → export.worker.XX9XDu3o.js} +43 -91
- package/dist/workers/stages/export/export.worker.XX9XDu3o.js.map +1 -0
- package/dist/workers/worker-manifest.json +1 -1
- package/package.json +1 -1
- package/dist/workers/stages/export/export.worker.CWPrx2Nf.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"word-fancy-renderer.js","sources":["../../../../src/stages/compose/text-renderers/word-fancy-renderer.ts"],"sourcesContent":["import type { TextLayer } from '../types';\nimport { formEvenLinesWithWords } from '../text-utils/text-wrapper';\nimport { getLetterCaseText, measureTextWidth } from '../text-utils/text-metrics';\nimport { springEasing, interpolate } from './animation-utils';\nimport { needsSpaceBetweenWords } from '../text-utils/locale-detector';\n\ninterface WordPosition {\n text: string;\n x: number;\n y: number;\n width: number;\n lineIndex: number;\n wordIndex: number;\n timing?: { startFrame: number; endFrame: number };\n}\n\nfunction usToFrame(us: number, fps: number): number {\n return Math.floor(us / (1000000 / fps));\n}\n\
|
|
1
|
+
{"version":3,"file":"word-fancy-renderer.js","sources":["../../../../src/stages/compose/text-renderers/word-fancy-renderer.ts"],"sourcesContent":["import type { TextLayer } from '../types';\nimport { formEvenLinesWithWords } from '../text-utils/text-wrapper';\nimport { getLetterCaseText, measureTextWidth } from '../text-utils/text-metrics';\nimport { springEasing, interpolate } from './animation-utils';\nimport { needsSpaceBetweenWords } from '../text-utils/locale-detector';\nimport { calculateCaptionStartY } from '../text-utils/caption-position';\n\ninterface WordPosition {\n text: string;\n x: number;\n y: number;\n width: number;\n lineIndex: number;\n wordIndex: number;\n timing?: { startFrame: number; endFrame: number };\n}\n\nfunction usToFrame(us: number, fps: number): number {\n return Math.floor(us / (1000000 / fps));\n}\n\nexport function renderWordByWordFancy(\n ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D,\n layer: TextLayer,\n canvasWidth: number,\n canvasHeight: number,\n relativeFrame: number,\n fps: number = 30\n): void {\n const fontConfig = layer.fontConfig?.textStyle;\n if (!fontConfig) return;\n\n const fontSize = fontConfig.fontSize;\n const fontFamily = fontConfig.fontFamily;\n const fontWeight = fontConfig.fontWeight;\n const fill = fontConfig.fill;\n const strokeColor = fontConfig.strokeColor;\n const strokeWidth = fontConfig.strokeWidth || 0;\n const lineHeight = fontConfig.lineHeight || 1.2;\n\n const highlightBackgroundColor = layer.animation?.highlightColor || 'rgb(255, 215, 0)';\n\n const maxWidth = canvasWidth * 0.64;\n const text = getLetterCaseText(layer.text, layer.letterCase);\n const needsSpace = needsSpaceBetweenWords(layer.localeCode || 'en-US', text);\n const words = text.split(needsSpace ? /\\s+/ : '');\n const lines = formEvenLinesWithWords(\n ctx,\n words,\n maxWidth,\n fontSize,\n needsSpace,\n fontFamily,\n fontWeight\n );\n\n const wordPositions: WordPosition[] = [];\n let wordIndex = 0;\n\n const totalHeight = lines.length * fontSize * lineHeight;\n const startY = calculateCaptionStartY(\n canvasHeight,\n totalHeight,\n layer.fontConfig?.globalPosition\n );\n\n for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {\n const line = lines[lineIndex]!;\n const lineWords = line.split(needsSpace ? /\\s+/ : '');\n const y = startY + lineIndex * fontSize * lineHeight + fontSize / 2;\n\n const lineWidth = measureTextWidth(ctx, line, fontSize, fontFamily, fontWeight);\n let currentX = canvasWidth / 2 - lineWidth / 2;\n\n for (const word of lineWords) {\n const wordWidth = measureTextWidth(ctx, word, fontSize, fontFamily, fontWeight);\n const wordTimingUs = layer.wordTimings?.[wordIndex];\n\n const wordTiming = wordTimingUs\n ? {\n startFrame: usToFrame(wordTimingUs.startUs, fps),\n endFrame: usToFrame(wordTimingUs.endUs, fps),\n }\n : undefined;\n\n wordPositions.push({\n text: word,\n x: currentX + wordWidth / 2,\n y,\n width: wordWidth,\n lineIndex,\n wordIndex,\n timing: wordTiming,\n });\n\n currentX +=\n wordWidth + (needsSpace ? measureTextWidth(ctx, ' ', fontSize, fontFamily, fontWeight) : 0);\n wordIndex++;\n }\n }\n\n ctx.save();\n ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`;\n ctx.textAlign = 'center';\n ctx.textBaseline = 'middle';\n ctx.lineJoin = 'round';\n ctx.lineCap = 'round';\n\n for (const wordPos of wordPositions) {\n let backgroundOpacity = 0;\n let backgroundScale = 0.8;\n\n if (wordPos.timing) {\n const { startFrame, endFrame } = wordPos.timing;\n const preStartFrames = 3;\n const isActive = relativeFrame >= startFrame && relativeFrame <= endFrame;\n\n if (isActive) {\n const scaleSpringIn = springEasing(relativeFrame - (startFrame - preStartFrames), {\n damping: 6,\n mass: 0.35,\n stiffness: 200,\n overshootClamping: false,\n });\n\n const inProgress = interpolate(relativeFrame, [startFrame, startFrame + 1], [0, 1], {\n extrapolateLeft: 'clamp',\n extrapolateRight: 'clamp',\n });\n\n backgroundOpacity = 0.9 * inProgress;\n backgroundScale = 0.8 + scaleSpringIn * 0.45;\n } else if (relativeFrame > endFrame) {\n backgroundOpacity = 0;\n backgroundScale = 0.8;\n }\n\n if (backgroundOpacity > 0) {\n const padding = 8;\n const bgWidth = (wordPos.width + padding * 2) * backgroundScale;\n const bgHeight = (fontSize + padding) * backgroundScale;\n\n ctx.save();\n ctx.globalAlpha = backgroundOpacity;\n ctx.fillStyle = highlightBackgroundColor;\n ctx.beginPath();\n ctx.roundRect(wordPos.x - bgWidth / 2, wordPos.y - bgHeight / 2, bgWidth, bgHeight, 8);\n ctx.fill();\n ctx.restore();\n }\n }\n\n if (strokeColor && strokeWidth > 0) {\n ctx.strokeStyle = strokeColor;\n ctx.lineWidth = strokeWidth;\n ctx.strokeText(wordPos.text, wordPos.x, wordPos.y);\n }\n ctx.fillStyle = fill;\n ctx.fillText(wordPos.text, wordPos.x, wordPos.y);\n }\n\n ctx.restore();\n}\n"],"names":[],"mappings":";;;;;AAiBA,SAAS,UAAU,IAAY,KAAqB;AAClD,SAAO,KAAK,MAAM,MAAM,MAAU,IAAI;AACxC;AAEO,SAAS,sBACd,KACA,OACA,aACA,cACA,eACA,MAAc,IACR;AACN,QAAM,aAAa,MAAM,YAAY;AACrC,MAAI,CAAC,WAAY;AAEjB,QAAM,WAAW,WAAW;AAC5B,QAAM,aAAa,WAAW;AAC9B,QAAM,aAAa,WAAW;AAC9B,QAAM,OAAO,WAAW;AACxB,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c,GAAG;AAClC,UAAI,cAAc;AAClB,UAAI,YAAY;AAChB,UAAI,WAAW,QAAQ,MAAM,QAAQ,GAAG,QAAQ,CAAC;AAAA,IACnD;AACA,QAAI,YAAY;AAChB,QAAI,SAAS,QAAQ,MAAM,QAAQ,GAAG,QAAQ,CAAC;AAAA,EACjD;AAEA,MAAI,QAAA;AACN;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GlobalPositionStyle } from '../font-system/types';
|
|
2
|
+
|
|
3
|
+
export type CaptionGlobalPosition = Pick<GlobalPositionStyle, 'position' | 'top' | 'bottom' | 'left' | 'right' | 'display' | 'alignItems' | 'justifyContent'>;
|
|
4
|
+
/**
|
|
5
|
+
* Resolve vertical start Y (top edge of the text block) from globalPosition.
|
|
6
|
+
*
|
|
7
|
+
* - `top: 'N%'` — vertical center of the caption block at N% of canvas height
|
|
8
|
+
* (matches medeo-web CaptionCover preview `positionY` semantics).
|
|
9
|
+
* - `bottom: 'N%'` — bottom edge of the block sits N% above the canvas bottom.
|
|
10
|
+
*/
|
|
11
|
+
export declare function calculateCaptionStartY(canvasHeight: number, totalHeight: number, globalPosition?: Partial<CaptionGlobalPosition>): number;
|
|
12
|
+
//# sourceMappingURL=caption-position.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caption-position.d.ts","sourceRoot":"","sources":["../../../../src/stages/compose/text-utils/caption-position.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,MAAM,MAAM,qBAAqB,GAAG,IAAI,CACtC,mBAAmB,EACnB,UAAU,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,YAAY,GAAG,gBAAgB,CAC/F,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,cAAc,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAC9C,MAAM,CAoBR"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function calculateCaptionStartY(canvasHeight, totalHeight, globalPosition) {
|
|
2
|
+
if (!globalPosition) {
|
|
3
|
+
return canvasHeight / 2 - totalHeight / 2;
|
|
4
|
+
}
|
|
5
|
+
if (globalPosition.top) {
|
|
6
|
+
const centerPercent = parseFloat(globalPosition.top) / 100;
|
|
7
|
+
return canvasHeight * centerPercent - totalHeight / 2;
|
|
8
|
+
}
|
|
9
|
+
if (globalPosition.bottom) {
|
|
10
|
+
const bottomPercent = parseFloat(globalPosition.bottom) / 100;
|
|
11
|
+
return canvasHeight * (1 - bottomPercent) - totalHeight;
|
|
12
|
+
}
|
|
13
|
+
if (globalPosition.justifyContent === "center" || globalPosition.alignItems === "center") {
|
|
14
|
+
return canvasHeight / 2 - totalHeight / 2;
|
|
15
|
+
}
|
|
16
|
+
return canvasHeight / 2 - totalHeight / 2;
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
calculateCaptionStartY
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=caption-position.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caption-position.js","sources":["../../../../src/stages/compose/text-utils/caption-position.ts"],"sourcesContent":["import type { GlobalPositionStyle } from '../font-system/types';\n\nexport type CaptionGlobalPosition = Pick<\n GlobalPositionStyle,\n 'position' | 'top' | 'bottom' | 'left' | 'right' | 'display' | 'alignItems' | 'justifyContent'\n>;\n\n/**\n * Resolve vertical start Y (top edge of the text block) from globalPosition.\n *\n * - `top: 'N%'` — vertical center of the caption block at N% of canvas height\n * (matches medeo-web CaptionCover preview `positionY` semantics).\n * - `bottom: 'N%'` — bottom edge of the block sits N% above the canvas bottom.\n */\nexport function calculateCaptionStartY(\n canvasHeight: number,\n totalHeight: number,\n globalPosition?: Partial<CaptionGlobalPosition>\n): number {\n if (!globalPosition) {\n return canvasHeight / 2 - totalHeight / 2;\n }\n\n if (globalPosition.top) {\n const centerPercent = parseFloat(globalPosition.top) / 100;\n return canvasHeight * centerPercent - totalHeight / 2;\n }\n\n if (globalPosition.bottom) {\n const bottomPercent = parseFloat(globalPosition.bottom) / 100;\n return canvasHeight * (1 - bottomPercent) - totalHeight;\n }\n\n if (globalPosition.justifyContent === 'center' || globalPosition.alignItems === 'center') {\n return canvasHeight / 2 - totalHeight / 2;\n }\n\n return canvasHeight / 2 - totalHeight / 2;\n}\n"],"names":[],"mappings":"AAcO,SAAS,uBACd,cACA,aACA,gBACQ;AACR,MAAI,CAAC,gBAAgB;AACnB,WAAO,eAAe,IAAI,cAAc;AAAA,EAC1C;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,gBAAgB,WAAW,eAAe,GAAG,IAAI;AACvD,WAAO,eAAe,gBAAgB,cAAc;AAAA,EACtD;AAEA,MAAI,eAAe,QAAQ;AACzB,UAAM,gBAAgB,WAAW,eAAe,MAAM,IAAI;AAC1D,WAAO,gBAAgB,IAAI,iBAAiB;AAAA,EAC9C;AAEA,MAAI,eAAe,mBAAmB,YAAY,eAAe,eAAe,UAAU;AACxF,WAAO,eAAe,IAAI,cAAc;AAAA,EAC1C;AAEA,SAAO,eAAe,IAAI,cAAc;AAC1C;"}
|
|
@@ -525,6 +525,23 @@ function textAnimationFrameForTextLayer(layer, fallbackFrame, fps) {
|
|
|
525
525
|
}
|
|
526
526
|
return fallbackFrame;
|
|
527
527
|
}
|
|
528
|
+
function calculateCaptionStartY(canvasHeight, totalHeight, globalPosition) {
|
|
529
|
+
if (!globalPosition) {
|
|
530
|
+
return canvasHeight / 2 - totalHeight / 2;
|
|
531
|
+
}
|
|
532
|
+
if (globalPosition.top) {
|
|
533
|
+
const centerPercent = parseFloat(globalPosition.top) / 100;
|
|
534
|
+
return canvasHeight * centerPercent - totalHeight / 2;
|
|
535
|
+
}
|
|
536
|
+
if (globalPosition.bottom) {
|
|
537
|
+
const bottomPercent = parseFloat(globalPosition.bottom) / 100;
|
|
538
|
+
return canvasHeight * (1 - bottomPercent) - totalHeight;
|
|
539
|
+
}
|
|
540
|
+
if (globalPosition.justifyContent === "center" || globalPosition.alignItems === "center") {
|
|
541
|
+
return canvasHeight / 2 - totalHeight / 2;
|
|
542
|
+
}
|
|
543
|
+
return canvasHeight / 2 - totalHeight / 2;
|
|
544
|
+
}
|
|
528
545
|
function measureTextWidth(ctx, text, fontSize, fontFamily, fontWeight = 400) {
|
|
529
546
|
ctx.save();
|
|
530
547
|
ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
@@ -847,23 +864,6 @@ function needsSpaceBetweenWords(locale, text) {
|
|
|
847
864
|
}
|
|
848
865
|
return !["zh-CN", "ja-JP", "ko-KR"].includes(locale);
|
|
849
866
|
}
|
|
850
|
-
function calculateYPosition$4(canvasHeight, totalHeight, globalPosition) {
|
|
851
|
-
if (!globalPosition) {
|
|
852
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
853
|
-
}
|
|
854
|
-
if (globalPosition.top) {
|
|
855
|
-
const topPercent = parseFloat(globalPosition.top) / 100;
|
|
856
|
-
return canvasHeight * topPercent;
|
|
857
|
-
}
|
|
858
|
-
if (globalPosition.bottom) {
|
|
859
|
-
const bottomPercent = parseFloat(globalPosition.bottom) / 100;
|
|
860
|
-
return canvasHeight * (1 - bottomPercent) - totalHeight;
|
|
861
|
-
}
|
|
862
|
-
if (globalPosition.justifyContent === "center" || globalPosition.alignItems === "center") {
|
|
863
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
864
|
-
}
|
|
865
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
866
|
-
}
|
|
867
867
|
function drawBasicTextLines(ctx, layer, canvasWidth, canvasHeight, lines) {
|
|
868
868
|
const fontConfig = layer.fontConfig?.textStyle;
|
|
869
869
|
if (!fontConfig) return;
|
|
@@ -881,7 +881,11 @@ function drawBasicTextLines(ctx, layer, canvasWidth, canvasHeight, lines) {
|
|
|
881
881
|
ctx.lineJoin = "round";
|
|
882
882
|
ctx.lineCap = "round";
|
|
883
883
|
const totalHeight = lines.length * fontSize * lineHeight;
|
|
884
|
-
const startY =
|
|
884
|
+
const startY = calculateCaptionStartY(
|
|
885
|
+
canvasHeight,
|
|
886
|
+
totalHeight,
|
|
887
|
+
layer.fontConfig?.globalPosition
|
|
888
|
+
);
|
|
885
889
|
for (let i = 0; i < lines.length; i++) {
|
|
886
890
|
const line = lines[i];
|
|
887
891
|
const y = startY + i * fontSize * lineHeight + fontSize / 2;
|
|
@@ -949,23 +953,6 @@ function easeOutExpo(t) {
|
|
|
949
953
|
if (t >= 1) return 1;
|
|
950
954
|
return 1 - Math.pow(2, -10 * t);
|
|
951
955
|
}
|
|
952
|
-
function calculateYPosition$3(canvasHeight, totalHeight, globalPosition) {
|
|
953
|
-
if (!globalPosition) {
|
|
954
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
955
|
-
}
|
|
956
|
-
if (globalPosition.top) {
|
|
957
|
-
const topPercent = parseFloat(globalPosition.top) / 100;
|
|
958
|
-
return canvasHeight * topPercent;
|
|
959
|
-
}
|
|
960
|
-
if (globalPosition.bottom) {
|
|
961
|
-
const bottomPercent = parseFloat(globalPosition.bottom) / 100;
|
|
962
|
-
return canvasHeight * (1 - bottomPercent) - totalHeight;
|
|
963
|
-
}
|
|
964
|
-
if (globalPosition.justifyContent === "center" || globalPosition.alignItems === "center") {
|
|
965
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
966
|
-
}
|
|
967
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
968
|
-
}
|
|
969
956
|
function charProgress(relativeFrame, fps, charIndex, staggerMs, durationMs) {
|
|
970
957
|
const tMs = relativeFrame / fps * 1e3;
|
|
971
958
|
const startMs = charIndex * staggerMs;
|
|
@@ -1030,7 +1017,11 @@ function buildCharSlots(ctx, layer, canvasWidth, canvasHeight) {
|
|
|
1030
1017
|
lines = getCachedWrapText(ctx, text, maxWidth, fontSize, fontFamily, fontWeight);
|
|
1031
1018
|
}
|
|
1032
1019
|
const totalHeight = lines.length * fontSize * lineHeight;
|
|
1033
|
-
const startY =
|
|
1020
|
+
const startY = calculateCaptionStartY(
|
|
1021
|
+
canvasHeight,
|
|
1022
|
+
totalHeight,
|
|
1023
|
+
layer.fontConfig?.globalPosition
|
|
1024
|
+
);
|
|
1034
1025
|
ctx.save();
|
|
1035
1026
|
ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
1036
1027
|
const slots = [];
|
|
@@ -1193,23 +1184,6 @@ function renderCaptionStaggerEntrance(ctx, layer, canvasWidth, canvasHeight, rel
|
|
|
1193
1184
|
function usToFrame$2(us, fps) {
|
|
1194
1185
|
return Math.floor(us / (1e6 / fps));
|
|
1195
1186
|
}
|
|
1196
|
-
function calculateYPosition$2(canvasHeight, totalHeight, globalPosition) {
|
|
1197
|
-
if (!globalPosition) {
|
|
1198
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
1199
|
-
}
|
|
1200
|
-
if (globalPosition.top) {
|
|
1201
|
-
const topPercent = parseFloat(globalPosition.top) / 100;
|
|
1202
|
-
return canvasHeight * topPercent;
|
|
1203
|
-
}
|
|
1204
|
-
if (globalPosition.bottom) {
|
|
1205
|
-
const bottomPercent = parseFloat(globalPosition.bottom) / 100;
|
|
1206
|
-
return canvasHeight * (1 - bottomPercent) - totalHeight;
|
|
1207
|
-
}
|
|
1208
|
-
if (globalPosition.justifyContent === "center" || globalPosition.alignItems === "center") {
|
|
1209
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
1210
|
-
}
|
|
1211
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
1212
|
-
}
|
|
1213
1187
|
function renderWordByWord(ctx, layer, canvasWidth, canvasHeight, relativeFrame, fps = 30) {
|
|
1214
1188
|
const fontConfig = layer.fontConfig?.textStyle;
|
|
1215
1189
|
if (!fontConfig) return;
|
|
@@ -1238,7 +1212,11 @@ function renderWordByWord(ctx, layer, canvasWidth, canvasHeight, relativeFrame,
|
|
|
1238
1212
|
const wordPositions = [];
|
|
1239
1213
|
let wordIndex = 0;
|
|
1240
1214
|
const totalHeight = lines.length * fontSize * lineHeight;
|
|
1241
|
-
const startY =
|
|
1215
|
+
const startY = calculateCaptionStartY(
|
|
1216
|
+
canvasHeight,
|
|
1217
|
+
totalHeight,
|
|
1218
|
+
layer.fontConfig?.globalPosition
|
|
1219
|
+
);
|
|
1242
1220
|
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
1243
1221
|
const line = lines[lineIndex];
|
|
1244
1222
|
const lineWords = line.split(needsSpace ? /\s+/ : "");
|
|
@@ -1313,23 +1291,6 @@ function renderWordByWord(ctx, layer, canvasWidth, canvasHeight, relativeFrame,
|
|
|
1313
1291
|
function usToFrame$1(us, fps) {
|
|
1314
1292
|
return Math.floor(us / (1e6 / fps));
|
|
1315
1293
|
}
|
|
1316
|
-
function calculateYPosition$1(canvasHeight, totalHeight, globalPosition) {
|
|
1317
|
-
if (!globalPosition) {
|
|
1318
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
1319
|
-
}
|
|
1320
|
-
if (globalPosition.top) {
|
|
1321
|
-
const topPercent = parseFloat(globalPosition.top) / 100;
|
|
1322
|
-
return canvasHeight * topPercent;
|
|
1323
|
-
}
|
|
1324
|
-
if (globalPosition.bottom) {
|
|
1325
|
-
const bottomPercent = parseFloat(globalPosition.bottom) / 100;
|
|
1326
|
-
return canvasHeight * (1 - bottomPercent) - totalHeight;
|
|
1327
|
-
}
|
|
1328
|
-
if (globalPosition.justifyContent === "center" || globalPosition.alignItems === "center") {
|
|
1329
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
1330
|
-
}
|
|
1331
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
1332
|
-
}
|
|
1333
1294
|
function renderCharacterKTV(ctx, layer, canvasWidth, canvasHeight, relativeFrame, fps = 30) {
|
|
1334
1295
|
const fontConfig = layer.fontConfig?.textStyle;
|
|
1335
1296
|
if (!fontConfig) return;
|
|
@@ -1401,7 +1362,11 @@ function renderCharacterKTV(ctx, layer, canvasWidth, canvasHeight, relativeFrame
|
|
|
1401
1362
|
ctx.lineJoin = "round";
|
|
1402
1363
|
ctx.lineCap = "round";
|
|
1403
1364
|
const totalHeight = fullTextLines.length * fontSize * lineHeight;
|
|
1404
|
-
const startY =
|
|
1365
|
+
const startY = calculateCaptionStartY(
|
|
1366
|
+
canvasHeight,
|
|
1367
|
+
totalHeight,
|
|
1368
|
+
layer.fontConfig?.globalPosition
|
|
1369
|
+
);
|
|
1405
1370
|
let charIndexInText = 0;
|
|
1406
1371
|
for (let lineIndex = 0; lineIndex < fullTextLines.length; lineIndex++) {
|
|
1407
1372
|
const line = fullTextLines[lineIndex];
|
|
@@ -1438,23 +1403,6 @@ function renderCharacterKTV(ctx, layer, canvasWidth, canvasHeight, relativeFrame
|
|
|
1438
1403
|
function usToFrame(us, fps) {
|
|
1439
1404
|
return Math.floor(us / (1e6 / fps));
|
|
1440
1405
|
}
|
|
1441
|
-
function calculateYPosition(canvasHeight, totalHeight, globalPosition) {
|
|
1442
|
-
if (!globalPosition) {
|
|
1443
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
1444
|
-
}
|
|
1445
|
-
if (globalPosition.top) {
|
|
1446
|
-
const topPercent = parseFloat(globalPosition.top) / 100;
|
|
1447
|
-
return canvasHeight * topPercent;
|
|
1448
|
-
}
|
|
1449
|
-
if (globalPosition.bottom) {
|
|
1450
|
-
const bottomPercent = parseFloat(globalPosition.bottom) / 100;
|
|
1451
|
-
return canvasHeight * (1 - bottomPercent) - totalHeight;
|
|
1452
|
-
}
|
|
1453
|
-
if (globalPosition.justifyContent === "center" || globalPosition.alignItems === "center") {
|
|
1454
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
1455
|
-
}
|
|
1456
|
-
return canvasHeight / 2 - totalHeight / 2;
|
|
1457
|
-
}
|
|
1458
1406
|
function renderWordByWordFancy(ctx, layer, canvasWidth, canvasHeight, relativeFrame, fps = 30) {
|
|
1459
1407
|
const fontConfig = layer.fontConfig?.textStyle;
|
|
1460
1408
|
if (!fontConfig) return;
|
|
@@ -1482,7 +1430,11 @@ function renderWordByWordFancy(ctx, layer, canvasWidth, canvasHeight, relativeFr
|
|
|
1482
1430
|
const wordPositions = [];
|
|
1483
1431
|
let wordIndex = 0;
|
|
1484
1432
|
const totalHeight = lines.length * fontSize * lineHeight;
|
|
1485
|
-
const startY =
|
|
1433
|
+
const startY = calculateCaptionStartY(
|
|
1434
|
+
canvasHeight,
|
|
1435
|
+
totalHeight,
|
|
1436
|
+
layer.fontConfig?.globalPosition
|
|
1437
|
+
);
|
|
1486
1438
|
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
1487
1439
|
const line = lines[lineIndex];
|
|
1488
1440
|
const lineWords = line.split(needsSpace ? /\s+/ : "");
|
|
@@ -3548,4 +3500,4 @@ const export_worker = null;
|
|
|
3548
3500
|
export {
|
|
3549
3501
|
export_worker as default
|
|
3550
3502
|
};
|
|
3551
|
-
//# sourceMappingURL=export.worker.
|
|
3503
|
+
//# sourceMappingURL=export.worker.XX9XDu3o.js.map
|