diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-03-02 15:08:21 +0100 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-03-02 15:08:21 +0100 |
| commit | 81e7a7fb32466633d38fa14bd5e14c2dca7bf658 (patch) | |
| tree | 60766b11ab738f855eaed04f77a875c22e5f0773 /apps/web/src/services/renderer | |
| parent | 887d1795dd1662985400af5e02c4b7215c830a7d (diff) | |
| download | opencut-81e7a7fb32466633d38fa14bd5e14c2dca7bf658.tar.gz | |
feat: implement keyframe support for more properties at the core (no ui yet)
Diffstat (limited to 'apps/web/src/services/renderer')
| -rw-r--r-- | apps/web/src/services/renderer/nodes/text-node.ts | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/apps/web/src/services/renderer/nodes/text-node.ts b/apps/web/src/services/renderer/nodes/text-node.ts index ffffc895..e929c2bc 100644 --- a/apps/web/src/services/renderer/nodes/text-node.ts +++ b/apps/web/src/services/renderer/nodes/text-node.ts @@ -17,6 +17,7 @@ import { } from "@/lib/text/layout"; import { getElementLocalTime, + resolveColorAtTime, resolveOpacityAtTime, resolveTransformAtTime, } from "@/lib/animation"; @@ -150,11 +151,24 @@ export class TextNode extends BaseNode<TextNodeParams> { const lineCount = lines.length; const block = measureTextBlock({ lineMetrics, lineHeightPx, fallbackFontSize: scaledFontSize }); + const textColor = resolveColorAtTime({ + baseColor: this.params.color, + animations: this.params.animations, + propertyPath: "color", + localTime, + }); + const backgroundColor = resolveColorAtTime({ + baseColor: this.params.background.color, + animations: this.params.animations, + propertyPath: "background.color", + localTime, + }); + const drawContent = (ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D) => { ctx.font = fontString; ctx.textAlign = this.params.textAlign; ctx.textBaseline = baseline; - ctx.fillStyle = this.params.color; + ctx.fillStyle = textColor; if ("letterSpacing" in ctx) { (ctx as CanvasRenderingContext2D & { letterSpacing: string }).letterSpacing = `${letterSpacing}px`; } @@ -165,7 +179,7 @@ export class TextNode extends BaseNode<TextNodeParams> { this.params.background.color !== "transparent" && lineCount > 0 ) { - const { color, cornerRadius = 0 } = this.params.background; + const { cornerRadius = 0 } = this.params.background; const backgroundRect = getTextBackgroundRect({ textAlign: this.params.textAlign, block, @@ -175,11 +189,11 @@ export class TextNode extends BaseNode<TextNodeParams> { if (backgroundRect) { const p = clamp({ value: cornerRadius, min: CORNER_RADIUS_MIN, max: CORNER_RADIUS_MAX }) / 100; const radius = Math.min(backgroundRect.width, backgroundRect.height) / 2 * p; - ctx.fillStyle = color; - ctx.beginPath(); - ctx.roundRect(backgroundRect.left, backgroundRect.top, backgroundRect.width, backgroundRect.height, radius); - ctx.fill(); - ctx.fillStyle = this.params.color; + ctx.fillStyle = backgroundColor; + ctx.beginPath(); + ctx.roundRect(backgroundRect.left, backgroundRect.top, backgroundRect.width, backgroundRect.height, radius); + ctx.fill(); + ctx.fillStyle = textColor; } } |
