Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: clamp hook word slam scale so it stays inside its text zone (#10789)

[._.]/ Adam Eivyc541c3abbde9
diff --git a/server/services/musicVideo/documentTemplates/shared/lyricType.js b/server/services/musicVideo/documentTemplates/shared/lyricType.js
index 86dc24c32d..c196d883c4 100644
--- a/server/services/musicVideo/documentTemplates/shared/lyricType.js
+++ b/server/services/musicVideo/documentTemplates/shared/lyricType.js
@@ -362,10 +362,14 @@ export function createLyricType(mv = globalThis.PORTOS_MV, options = {}) {
const placed = [];
rows.forEach((row, r) => {
const widths = row.map((item) => measure(`${item.text} `, fontFor(line.role, px)));
- const rowW = widths.reduce((a, b) => a + b, 0) - measure(' ', fontFor(line.role, px));
+ const spaceW = measure(' ', fontFor(line.role, px));
+ const rowW = widths.reduce((a, b) => a + b, 0) - spaceW;
let x = rect.align === 'left' ? rect.x : rect.align === 'right' ? rect.x + rect.w - rowW : rect.x + (rect.w - rowW) / 2;
row.forEach((item, k) => {
- placed.push({ index: item.index, text: item.text, x, y: top + r * lineH, w: widths[k] });
+ // Words scale about their own centre, so a slam may grow only until it meets the nearer zone edge.
+ const ink = widths[k] - spaceW;
+ const room = 2 * Math.min(x + ink / 2 - rect.x, rect.x + rect.w - (x + ink / 2));
+ placed.push({ index: item.index, text: item.text, x, y: top + r * lineH, w: widths[k], maxScale: ink > 0 ? Math.max(1, room / ink) : 1 });
x += widths[k];
});
});
@@ -403,7 +407,8 @@ export function createLyricType(mv = globalThis.PORTOS_MV, options = {}) {
ctx.globalAlpha = clamp(s.alpha * exit.alpha);
ctx.translate(cx + bx, word.y + (s.dy + exit.dy) * unit + by);
if (s.tilt) ctx.rotate((s.tilt * Math.PI) / 180);
- if (s.scale !== 1) ctx.scale(s.scale, s.scale);
+ const scale = Math.min(s.scale, word.maxScale);
+ if (scale !== 1) ctx.scale(scale, scale);
const text = line.role === 'data' ? rollNumbers(word.text, (t - s.startSec) / T.dataRollSec) : word.text;
const x0 = -(word.w - measure(' ', font)) / 2;
if (line.role === 'data') {
diff --git a/server/services/musicVideo/documentTemplates/shared/lyricType.test.js b/server/services/musicVideo/documentTemplates/shared/lyricType.test.js
index 2cf961233c..e52e12a99c 100644
--- a/server/services/musicVideo/documentTemplates/shared/lyricType.test.js
+++ b/server/services/musicVideo/documentTemplates/shared/lyricType.test.js
@@ -169,6 +169,24 @@ describe('lyricType text zones', () => {
}
});
+ it('keeps a slamming hook word inside its zone on the first frame', () => {
+ for (const zone of ['upper-right', 'lower-left', 'center']) {
+ // One word that fills the whole zone width at the base size (0.5em per char).
+ const type = createLyricType({}, { lines: [{ text: 'UNIVERSEWORDS', role: 'hook', zone, startSec: 1, endSec: 3, words: [{ text: 'UNIVERSEWORDS', startSec: 1, endSec: 2 }] }] });
+ const hook = type.lines[0];
+ const placed = type.layout(hook, 1920, 1080, (str, font) => str.length * Number(/(\d+)px/.exec(font)[1]) * 0.5);
+ const [word] = placed.words;
+ const [state] = type.wordStates(hook, 1);
+ expect(state.scale).toBeGreaterThan(1);
+ const space = placed.px * 0.5;
+ const ink = word.w - space;
+ const scaled = ink * Math.min(state.scale, word.maxScale);
+ const centre = word.x + ink / 2;
+ expect(centre - scaled / 2).toBeGreaterThanOrEqual(placed.rect.x - 1e-6);
+ expect(centre + scaled / 2).toBeLessThanOrEqual(placed.rect.x + placed.rect.w + 1e-6);
+ }
+ });
+
it('reframes zones for a portrait frame', () => {
const rect = zoneRect('lower-left', 1080, 1920);
expect(rect.x + rect.w).toBeCloseTo(1080 - rect.x, 6);