Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.
TypeScript agentic-aiaiai-agentsai-videocompilerdslffmpeggenerative-aillmmarkup-languagemonorepoplugin-systemprogramming-languagetext-to-videotypescriptvideovideo-automationvideo-clonevideo-editingvideo-generation
fix: preserve fine caption paint overflow
kashorina74e109ac2fd
diff --git a/docs/quickstart/tracks.md b/docs/quickstart/tracks.mdindex fd30226d..bedd77a3 100644--- a/docs/quickstart/tracks.md+++ b/docs/quickstart/tracks.md@@ -40,7 +40,7 @@ caption.primary {size: 58;line-height: 0.96; letter-spacing: -0.5; word-gap: 14;align: center; block-align: end; inline-size: fixed;- wrap: word; overflow: clip; max-lines: 2; max-words-per-line: 4;+ wrap: word; max-lines: 2; max-words-per-line: 4;direction: ltr;fill: #FFFFFF; opacity: 1;stroke-color: #09090B; stroke-width: 2;@@ -103,9 +103,10 @@ continuous on each real browser line. Thus trail-colored text with a current-onlRecipe—not a second renderer.With `wrap: word`, Fine wraps between complete Alignment Units and falls back inside a single-over-wide display unit so it cannot escape the Region. `max-lines` is accepted only with the explicit-`overflow: clip`; without that opt-in Fine does not silently discard author text. Cue boundaries come-from Script segments, turns, Style changes and authored `||`.+over-wide display unit so it cannot escape the Region. `max-words-per-line` constructs explicit rows;+when `max-lines` is present, a Cue that would construct more rows is rejected instead of having its+text or Paint clipped. Cue boundaries come from Script segments, turns, Style changes and authored+`||`.Fine is the uniform-flow family: every token follows the same Recipe and may differ only by time,index or play state. A Cue with authored internal roles—different font/layout groups, full-framediff --git a/docs/zh/quickstart/tracks.md b/docs/zh/quickstart/tracks.mdindex 658c682a..f9b919e3 100644--- a/docs/zh/quickstart/tracks.md+++ b/docs/zh/quickstart/tracks.md@@ -38,7 +38,7 @@ caption.primary {anchor-x: center; anchor-y: bottom;size: 58; line-height: 1;align: center; block-align: end; inline-size: fixed;- wrap: word; overflow: clip; max-lines: 2; max-words-per-line: 4;+ wrap: word; max-lines: 2; max-words-per-line: 4;fill: #FFFFFF; stroke-color: #09090B; stroke-width: 2;background: #00000000; padding: 0; radius: 0;karaoke: trail; karaoke-transition: wipe; active-fill: #FFD54A;@@ -69,7 +69,7 @@ Fine 不是一组互斥预设。基础/激活渐变、描边、阴影、长阴包在 Surface 声明中把参数分成 **Where / How / When**,Studio 直接消费这份作者协议,无需再维护字幕专用参数全集。`lead-frames`、`tail-frames` 先产生显式可见 Schedule;`handoff: cut` 负责相邻 Cue 的交接,`overlap` 则保留双方包络。二者都不会修改 Karaoke 使用的原始词帧。-`wrap: word` 优先在完整 Alignment Unit 之间换行;单个显示单元若比 Region 还宽,会继续在内部回退换行,不会逃出范围。只有显式同时写出 `max-lines` 与 `overflow: clip` 才允许裁掉超出的行;否则不会静默丢字。Cue 分界由 Script 的结构和 `||` 决定。+`wrap: word` 优先在完整 Alignment Unit 之间换行;单个显示单元若比 Region 还宽,会继续在内部回退换行,不会逃出范围。`max-words-per-line` 直接构造真实行;声明 `max-lines` 后,超过行数预算的 Cue 会被拒绝,不会裁掉文字、描边、阴影或外发光。Cue 分界由 Script 的结构和 `||` 决定。Fine 是“统一文字流”字幕:同一 Cue 的每个 token 遵守同一 Recipe,只允许时间、顺序和播放状态驱动差异。若 Cue 内存在不同字体/布局角色、全屏反色、撕裂或前后语块之间的合成关系,就应新建另一个 Caption 包,而不是给 Fine 塞隐藏例外。diff --git a/examples/talking-film-graph-check/recipes.svs b/examples/talking-film-graph-check/recipes.svsindex e9f6f1fb..07dd335c 100644--- a/examples/talking-film-graph-check/recipes.svs+++ b/examples/talking-film-graph-check/recipes.svs@@ -15,7 +15,7 @@stack-order: 70; x: 0.5; y: 0.88; width: 0.84; height: 0.22;anchor-x: center; anchor-y: bottom;size: 58; line-height: 1; align: center; block-align: end; inline-size: fixed;- wrap: word; overflow: clip; max-lines: 2; max-words-per-line: 4;+ wrap: word; max-lines: 2; max-words-per-line: 4;fill: #FFFFFF; stroke-color: #09090B; stroke-width: 2;shadow-color: #000000; shadow-opacity: 0.72; shadow-x: 0; shadow-y: 3; shadow-blur: 8;glow-color: #FFFFFF; glow-opacity: 0.12; glow-blur: 8;diff --git a/packages/caption-fine-studio/src/index.ts b/packages/caption-fine-studio/src/index.tsindex 6c996adb..1c4e4dd6 100644--- a/packages/caption-fine-studio/src/index.ts+++ b/packages/caption-fine-studio/src/index.ts@@ -40,7 +40,7 @@ function placeCaption(names: readonly string[], domain: "where" | "how" | "when"placeCaption(["stack-order", "x", "y", "width", "height", "anchor-x", "anchor-y"], "where", "placement", "region");placeCaption([- "align", "block-align", "inline-size", "wrap", "overflow", "max-lines", "max-words-per-line", "direction",+ "align", "block-align", "inline-size", "wrap", "max-lines", "max-words-per-line", "direction","line-height", "letter-spacing", "word-gap",], "where", "flow", "flow");placeCaption(["size", "kerning", "caps", "text-transform"], "how", "text", "typography");diff --git a/packages/caption-fine/README.md b/packages/caption-fine/README.mdindex 6a3ada39..7c3bd6a0 100644--- a/packages/caption-fine/README.md+++ b/packages/caption-fine/README.md@@ -37,7 +37,7 @@ caption.primary {x: 0.5; y: 0.9; width: 0.84; height: 0.22;anchor-x: center; anchor-y: bottom;align: center; block-align: end; inline-size: fixed;- wrap: word; overflow: clip; max-lines: 2; max-words-per-line: 4;+ wrap: word; max-lines: 2; max-words-per-line: 4;size: 58; line-height: 1; fill: #FFFFFF;background: #00000000; padding: 0; radius: 0;karaoke: current; active-fill: #FFD54A;diff --git a/packages/caption-fine/src/manifest.ts b/packages/caption-fine/src/manifest.tsindex 22bd91e4..075d2423 100644--- a/packages/caption-fine/src/manifest.ts+++ b/packages/caption-fine/src/manifest.ts@@ -59,10 +59,8 @@ export const captionFineMarkupSurfaces = [summary: "Chooses whether the Cue hugs its text up to the Region width or fills the Region width." },{ name: "wrap", required: false, values: ["word", "grapheme"], fallback: "word",summary: "Wraps at Word boundaries, falling back for an over-wide Word, or permits a break at any grapheme." },- { name: "overflow", required: false, values: ["visible", "clip"], fallback: "visible",- summary: "Keeps Paint overflow visible or clips the Cue to its declared line envelope." },{ name: "max-lines", required: false,- summary: "Caps the Cue's visible line boxes; it is accepted only together with overflow: clip." },+ summary: "Rejects a Cue whose explicitly constructed rows exceed this budget; it requires max-words-per-line and never clips Paint." },{ name: "max-words-per-line", required: false,summary: "Forces a new line after this many display Words while preserving authored Cue boundaries." },{ name: "direction", required: false, values: ["ltr", "rtl"], fallback: "ltr",diff --git a/packages/caption-fine/src/recipe.ts b/packages/caption-fine/src/recipe.tsindex 401586de..af30ab84 100644--- a/packages/caption-fine/src/recipe.ts+++ b/packages/caption-fine/src/recipe.ts@@ -49,7 +49,6 @@ const enums: Readonly<Record<string, readonly string[]>> = {"direction": ["ltr", "rtl"],"inline-size": ["hug", "fixed"],"wrap": ["word", "grapheme"],- "overflow": ["visible", "clip"],"kerning": ["auto", "normal", "none"],"caps": ["normal", "small-caps", "all-small-caps"],"text-transform": ["none", "uppercase", "lowercase", "capitalize"],@@ -91,7 +90,7 @@ export const fineCaptionOptionalRecipeProperties = ["cue-enter-frames", "cue-exit", "cue-exit-frames", "direction", "glow-blur", "glow-color","glow-opacity", "glow-spread", "gradient-angle", "gradient-from", "gradient-to", "height", "inline-size", "karaoke", "karaoke-transition", "kerning","handoff", "lead-frames", "letter-spacing", "long-shadow-angle", "long-shadow-color", "long-shadow-distance", "long-shadow-opacity",- "loop", "loop-intensity", "loop-period-frames", "loop-target", "max-lines", "max-words-per-line", "opacity", "overflow", "shadow-blur", "shadow-color",+ "loop", "loop-intensity", "loop-period-frames", "loop-target", "max-lines", "max-words-per-line", "opacity", "shadow-blur", "shadow-color","shadow-opacity", "shadow-spread", "shadow-x", "shadow-y", "slide-distance", "stroke-color", "stroke-width", "text-transform","tail-frames", "underline", "underline-color", "underline-offset", "underline-thickness", "word-gap", "wrap",] as const;diff --git a/packages/caption-fine/src/render.ts b/packages/caption-fine/src/render.tsindex 31e94f7a..ba46bfb9 100644--- a/packages/caption-fine/src/render.ts+++ b/packages/caption-fine/src/render.ts@@ -68,10 +68,9 @@ function underlineStyle(underline: FineCaptionUnderline | FineCaptionActiveUnder* The glyph body and its outline, as ordered Paint.** An outline belongs outside the letter. `-webkit-text-stroke` cannot put it there: it centres the- * stroke on the glyph edge, so half the width is always inside, and the only choice left is which- * half gets painted over. Declaring the Paint hands the placement to the renderer, which builds the- * ring by dilating the glyph and subtracting it from itself — wholly outside, at the width asked- * for rather than half of it.+ * stroke on the glyph edge, so half the width is always inside. Declaring the Paint hands placement+ * to the renderer, which keeps the authored width wholly outside while the body preserves the+ * original letterform.** A caption with no outline keeps its plain fill, which is one element and one paint rather than* two, and is what most captions are.@@ -282,6 +281,11 @@ function easeOutElastic(value: number): number {const neutralMotion: MotionSnapshot = { opacity: 1, transform: "none", filter: "none", clipPath: "inset(0% 0% 0% 0%)" };+/** A zero inset still clips Paint outside the box; only wipe motions need it. */+function wipes(kind: FineCaptionOneShotMotion): boolean {+ return kind === "wipe-left" || kind === "wipe-right" || kind === "wipe-up" || kind === "wipe-down";+}+function motionSnapshot(kind: FineCaptionOneShotMotion, progress: number, distancePx: number): MotionSnapshot {const value = clamp(progress, 0, 1);const eased = easeOut(value);@@ -319,12 +323,12 @@ function motionSnapshot(kind: FineCaptionOneShotMotion, progress: number, distanreturn state(eased, transform);}-function snapshotStyle(snapshot: MotionSnapshot): VisualStyleDeclaration[] {+function snapshotStyle(snapshot: MotionSnapshot, clipped = true): VisualStyleDeclaration[] {return [{ name: "opacity", value: snapshot.opacity },{ name: "transform", value: snapshot.transform },{ name: "filter", value: snapshot.filter },- { name: "clip-path", value: snapshot.clipPath },+ ...(clipped ? [{ name: "clip-path", value: snapshot.clipPath }] : []),];}@@ -343,12 +347,13 @@ function cueAnimation(parameters: FineCaptionParameters, durationFrames: number)...transitionOffsets(0, enterFrames, parameters.motion.cueEnter),...transitionOffsets(durationFrames - exitFrames, exitFrames, parameters.motion.cueExit),];+ const clipped = wipes(parameters.motion.cueEnter) || wipes(parameters.motion.cueExit);return animationFrom(durationFrames, offsets, (frame) => {const enterProgress = enterFrames === 0 ? 1 : clamp(frame / enterFrames, 0, 1);const exitProgress = exitFrames === 0 ? 1 : clamp((durationFrames - frame) / exitFrames, 0, 1);const enter = motionSnapshot(parameters.motion.cueEnter, enterProgress, parameters.motion.slideDistancePx);const exit = motionSnapshot(parameters.motion.cueExit, exitProgress, parameters.motion.slideDistancePx);- return snapshotStyle(enterProgress < 1 ? enter : exit);+ return snapshotStyle(enterProgress < 1 ? enter : exit, clipped);});}@@ -369,15 +374,16 @@ function atomLifecycleAnimation(...transitionOffsets(endFrame - exitFrames, exitFrames, parameters.motion.atomExit),...stepOffsets(endFrame),];+ const clipped = wipes(parameters.motion.atomEnter) || wipes(parameters.motion.atomExit);return animationFrom(durationFrames, offsets, (frame) => {- if (frame < startFrame) return shouldWait ? [{ name: "opacity", value: 0 }] : snapshotStyle(neutralMotion);+ if (frame < startFrame) return shouldWait ? [{ name: "opacity", value: 0 }] : snapshotStyle(neutralMotion, clipped);if (frame >= endFrame && parameters.motion.atomExit !== "none") {- return snapshotStyle(motionSnapshot(parameters.motion.atomExit, 0, parameters.motion.slideDistancePx));+ return snapshotStyle(motionSnapshot(parameters.motion.atomExit, 0, parameters.motion.slideDistancePx), clipped);}const enterProgress = enterFrames === 0 ? 1 : clamp((frame - startFrame) / enterFrames, 0, 1);const exitProgress = exitFrames === 0 ? 1 : clamp((endFrame - frame) / exitFrames, 0, 1);- if (enterProgress < 1) return snapshotStyle(motionSnapshot(parameters.motion.atomEnter, enterProgress, parameters.motion.slideDistancePx));- return snapshotStyle(motionSnapshot(parameters.motion.atomExit, exitProgress, parameters.motion.slideDistancePx));+ if (enterProgress < 1) return snapshotStyle(motionSnapshot(parameters.motion.atomEnter, enterProgress, parameters.motion.slideDistancePx), clipped);+ return snapshotStyle(motionSnapshot(parameters.motion.atomExit, exitProgress, parameters.motion.slideDistancePx), clipped);});}@@ -460,8 +466,9 @@ function activeResponseAnimation(});}const frames = Math.min(parameters.motion.activeResponseFrames, Math.max(1, endFrame - startFrame));+ const clipped = wipes(response);return animationFrom(durationFrames, transitionOffsets(startFrame, frames, response), (frame) => {- if (frame < startFrame || frame > startFrame + frames) return snapshotStyle(neutralMotion);+ if (frame < startFrame || frame > startFrame + frames) return snapshotStyle(neutralMotion, clipped);const progress = clamp((frame - startFrame) / frames, 0, 1);if (response === "pop" || response === "spring") {const amplitude = parameters.motion.activeScale - 1;@@ -470,7 +477,7 @@ function activeResponseAnimation(: 1 + amplitude * Math.exp(-4 * progress) * Math.sin(12 * progress);return [{ name: "transform", value: `scale(${compactNumber(responseScale)})` }];}- return snapshotStyle(motionSnapshot(response, progress, parameters.motion.slideDistancePx));+ return snapshotStyle(motionSnapshot(response, progress, parameters.motion.slideDistancePx), clipped);});}@@ -542,7 +549,8 @@ function activeBoxAnimation(const enterProgress = enterFrames === 0 ? 1 : clamp((frame - startFrame) / enterFrames, 0, 1);const exitProgress = exitFrames === 0 ? 1 : clamp((logicalEnd - frame) / exitFrames, 0, 1);const kind = enterProgress < 1 ? box.enter : box.exit;- return snapshotStyle(motionSnapshot(kind, Math.min(enterProgress, exitProgress), parameters.motion.slideDistancePx));+ return snapshotStyle(motionSnapshot(kind, Math.min(enterProgress, exitProgress), parameters.motion.slideDistancePx),+ wipes(box.enter) || wipes(box.exit));}) ?? { keyframes: [{ atFrame: 0, style: [{ name: "opacity", value: 1 }] },{ atFrame: durationFrames, style: [{ name: "opacity", value: 1 }] },@@ -555,6 +563,22 @@ function anchorTransform(parameters: FineCaptionParameters): string | undefinedreturn x === 0 && y === 0 ? undefined : `translate(${x}%,${y}%)`;}+function structuralRowCount(+ atoms: readonly CaptionAlignmentUnit[],+ maxWordsPerLine: number,+): number {+ let rows = atoms.length === 0 ? 0 : 1;+ let wordsOnRow = 0;+ for (const atom of atoms) {+ if (wordsOnRow > 0 && wordsOnRow + atom.wordIds.length > maxWordsPerLine) {+ rows += 1;+ wordsOnRow = 0;+ }+ wordsOnRow += atom.wordIds.length;+ }+ return rows;+}+function cueElements(atoms: readonly CaptionAlignmentUnit[],atomFrames: ReadonlyMap<string, { readonly start: number; readonly end: number }>,@@ -574,6 +598,12 @@ function cueElements(const cueMotion = cueAnimation(parameters, durationFrames);const cueLoop = parameters.motion.loopTarget === "cue" ? loopAnimation(parameters, durationFrames) : undefined;const fonts = parameters.typography.exactFonts;+ if (parameters.layout.maxLines !== undefined) {+ const rows = structuralRowCount(atoms, parameters.layout.maxWordsPerLine!);+ if (rows > parameters.layout.maxLines) {+ throw new Error(`Fine Caption Style ${styleId} constructs ${rows} rows for a Cue whose maximum is ${parameters.layout.maxLines}`);+ }+ }push({id: "placement",kind: "box",@@ -629,11 +659,7 @@ function cueElements({ name: "justify-content", value: parameters.layout.textAlign === "left" ? "flex-start": parameters.layout.textAlign === "right" ? "flex-end" : "center" },{ name: "max-width", value: "100%" },- ...(parameters.layout.maxLines === undefined ? [] : [{- name: "max-height",- value: `${compactNumber(parameters.typography.fontSizePx * parameters.layout.lineHeight * parameters.layout.maxLines + parameters.cueBox.paddingYPx * 2)}px`,- }] as const),- { name: "overflow", value: parameters.layout.overflow === "clip" ? "hidden" : "visible" },+ { name: "overflow", value: "visible" },{ name: "padding", value: `${compactNumber(parameters.cueBox.paddingYPx)}px ${compactNumber(parameters.cueBox.paddingXPx)}px` },{ name: "position", value: "relative" },{ name: "text-align", value: parameters.layout.textAlign },@@ -829,8 +855,6 @@ function cueElements({ name: "column-gap", value: `${compactNumber(parameters.layout.wordGapPx)}px` },{ name: "display", value: "inline-flex" },{ name: "inset", value: "0" },- ...(kind === "glyph" && parameters.karaoke.transition === "wipe"- ? [{ name: "overflow", value: "hidden" }] as const : []),{ name: "position", value: "absolute" },],animation: kind === "glyph" && parameters.karaoke.transition === "wipe"diff --git a/packages/caption-fine/src/style.ts b/packages/caption-fine/src/style.tsindex 754d6377..24119f4d 100644--- a/packages/caption-fine/src/style.ts+++ b/packages/caption-fine/src/style.ts@@ -198,7 +198,6 @@ export function fineCaptionParameters(direction: choice(recipe, "direction", ["ltr", "rtl"] as const, "ltr"),inlineSize: choice(recipe, "inline-size", ["hug", "fixed"] as const, "hug"),wrap: choice(recipe, "wrap", ["word", "grapheme"] as const, "word"),- overflow: choice(recipe, "overflow", ["visible", "clip"] as const, "visible"),...(Object.hasOwn(recipe.properties, "max-lines") ? { maxLines: integer(recipe, "max-lines") } : {}),...(Object.hasOwn(recipe.properties, "max-words-per-line")? { maxWordsPerLine: integer(recipe, "max-words-per-line") } : {}),@@ -330,8 +329,8 @@ export function assertFineCaptionParameters(value: FineCaptionParameters): voidif (faces.has(identity)) throw new Error("Fine Caption exact Font stack contains a duplicate face");faces.add(identity);}- if (value.layout.maxLines !== undefined && value.layout.overflow !== "clip") {- throw new Error("Fine Caption max-lines requires overflow: clip");+ if (value.layout.maxLines !== undefined && value.layout.maxWordsPerLine === undefined) {+ throw new Error("Fine Caption max-lines requires max-words-per-line so its rows are structural");}assertColor(value.cueBox.background, "Fine Caption background");assertColor(value.cueBox.borderColor, "Fine Caption border color");diff --git a/packages/caption-fine/src/types.ts b/packages/caption-fine/src/types.tsindex c1cd3104..4eb9c37a 100644--- a/packages/caption-fine/src/types.ts+++ b/packages/caption-fine/src/types.ts@@ -102,7 +102,6 @@ export type FineCaptionParameters = {readonly direction: "ltr" | "rtl";readonly inlineSize: "hug" | "fixed";readonly wrap: "word" | "grapheme";- readonly overflow: "visible" | "clip";readonly maxLines?: number;readonly maxWordsPerLine?: number;readonly lineHeight: number;diff --git a/packages/caption-fine/test/caption-fine.test.ts b/packages/caption-fine/test/caption-fine.test.tsindex 72deaf6f..fa64fb3f 100644--- a/packages/caption-fine/test/caption-fine.test.ts+++ b/packages/caption-fine/test/caption-fine.test.ts@@ -40,12 +40,12 @@ const recipe: SvsRecipe = {"block-align": "end","inline-size": "fixed",wrap: "word",- overflow: "clip","max-lines": 2,"max-words-per-line": 1,size: 56,"line-height": 1.05,fill: "#FFFFFF",+ "stroke-width": 2,"shadow-color": "#000000","shadow-opacity": 0.7,"shadow-blur": 8,@@ -132,11 +132,30 @@ test("Fine Caption schedules visibility outside semantic Word timing and cuts on{ startFrame: 36, endFrameExclusive: 62 },]);assert.ok(track.presents[0]?.elements.some((element) => element.id === "line-break-1"));+ const cue = track.presents[0]?.elements.find((element) => element.id === "cue");+ assert.equal(cue?.style.find((declaration) => declaration.name === "overflow")?.value, "visible");+ assert.equal(cue?.style.some((declaration) => declaration.name === "max-height"), false);const atom = track.presents[0]?.elements.find((element) => element.id === "atom-1");assert.equal(atom?.style.find((declaration) => declaration.name === "white-space")?.value, "normal");assert.equal(atom?.style.find((declaration) => declaration.name === "overflow-wrap")?.value, "anywhere");});+test("Fine Caption rejects a Cue that exceeds its structural row budget instead of clipping Paint", () => {+ const { document, program, projection } = fixture();+ const constrained = fineCaptionStyle("plain", {+ ...recipe,+ properties: { ...recipe.properties, "max-lines": 1 },+ }, [font]);+ const constrainedProgram: CaptionProgram = { ...program, styles: [constrained] };+ const schedule = scheduleFineCaption(projection, constrainedProgram, document);+ assert.throws(+ () => renderFineCaption(schedule, constrainedProgram, document,+ sealProgramSpace({ id: "test-space", narrativeId: "story", durationSec: 3,+ frameRate: { numerator: 30, denominator: 1 } })),+ /constructs 2 rows.+maximum is 1/u,+ );+});+test("Fine Caption applies authored mute before it schedules the visible envelope", () => {const { document, program, projection } = fixture();const muted: CaptionProgram = { ...program, mutedUnitIds: [projection.cues[0]!.units[0]!.unitId] };diff --git a/packages/hyperframes/src/text.ts b/packages/hyperframes/src/text.tsindex a7876a44..f1b0bf3f 100644--- a/packages/hyperframes/src/text.ts+++ b/packages/hyperframes/src/text.ts@@ -164,11 +164,17 @@ function mergedTypography(}type GlyphPaintLayer = Exclude<VisualTextPaintLayer, { readonly kind: "box" }>;+type FilterGlyphPaint = Extract<GlyphPaintLayer, { kind: "stroke" | "shadow" | "glow" }>;function glyphPaintLayers(paints: readonly VisualTextPaintLayer[]): GlyphPaintLayer[] {return paints.filter((paint): paint is GlyphPaintLayer => paint.kind !== "box");}+function usesGlyphFilter(paint: GlyphPaintLayer): paint is FilterGlyphPaint {+ return paint.kind === "shadow" || paint.kind === "glow"+ || (paint.kind === "stroke" && paint.placement !== "outside");+}+function inheritedGlyphColor(paints: readonly VisualTextPaintLayer[]): string[] {const fills = glyphPaintLayers(paints).filter((paint): paint is Extract<GlyphPaintLayer, { kind: "fill" }> => paint.kind === "fill");return fills.length === 1 && fills[0]!.paint.kind === "solid" ? [`color:${fills[0]!.paint.color}`] : [];@@ -231,7 +237,7 @@ function glyphFilterDefinitions(element: TerminalTextElement, context: TextRendeappend(paragraph.style?.paints);for (const inline of paragraph.inlines) if (inline.kind === "text") append(inline.style?.paints);}- const filtered = layers.filter((paint): paint is Extract<GlyphPaintLayer, { kind: "stroke" | "shadow" | "glow" }> => paint.kind !== "fill");+ const filtered = layers.filter(usesGlyphFilter);const definitions = [...new Map(filtered.map((paint) => [canonicalStringify(paint), paint])).values()].map((paint) => glyphFilterDefinition(paint, context)).join("");return definitions;@@ -259,6 +265,22 @@ function glyphLayerCss("-webkit-text-fill-color:transparent",];}+ if (paint.kind === "stroke" && paint.placement === "outside") {+ // CSS centres a stroke on the glyph edge. Doubling the requested width and drawing the body+ // again in the following fill layer covers the inner half, leaving exactly the authored width+ // outside without passing the descender through an SVG filter input box first.+ const color = solidPaint(paint.paint);+ if (color === undefined) {+ throw new Error("HyperFrames outside Text stroke requires solid color; materialize a gradient stroke as a Surface.");+ }+ return [+ ...common,+ `color:${color}`,+ `-webkit-text-fill-color:${color}`,+ `-webkit-text-stroke:${number(paint.widthPx * 2)}px ${color}`,+ "paint-order:stroke fill",+ ];+ }return [...common,"color:#ffffff",@@ -296,8 +318,7 @@ export function renderGlyphPaintedString(): string {const layers = glyphPaintLayers(paints);if (layers.length === 0) return context.escape(value);- const shaped = layers.filter((paint): paint is Extract<GlyphPaintLayer, { kind: "stroke" | "shadow" | "glow" }> =>- paint.kind !== "fill");+ const shaped = layers.filter(usesGlyphFilter);const written = context.emittedFilterIds;const definitions = [...new Map(shaped.map((paint) => [canonicalStringify(paint), paint])).values()].filter((paint) => {@@ -311,7 +332,8 @@ export function renderGlyphPaintedString(const defs = definitions.length === 0? "": `<svg aria-hidden="true" width="0" height="0" style="position:absolute;overflow:hidden"><defs>${definitions}</defs></svg>`;- // The layers occupy one grid cell each so they stack in the order they were declared.+ // Paint layers share one grid cell. The wrapper stacks them but does not absorb their ink into+ // layout: outline, shadow and glow remain visible overflow around the measured letterform.return `${defs}<span style="position:relative;display:inline-grid">${renderGlyphPaint(value, paints, context)}</span>`;}diff --git a/packages/hyperframes/test/document.test.ts b/packages/hyperframes/test/document.test.tsindex 8aeae4bf..01a813d9 100644--- a/packages/hyperframes/test/document.test.ts+++ b/packages/hyperframes/test/document.test.ts@@ -63,7 +63,13 @@ function fixture() {stacking: { order: 20, tieBreak: "upper" },elements: [{ id: "root", order: 0, kind: "box", style: [{ name: "position", value: "absolute" }] },- { id: "text", parent: "root", order: 1, kind: "text", text: "Hello <world>", fonts: [fixtureFont], style: [] },+ { id: "text", parent: "root", order: 1, kind: "text", text: "Hello <world>", fonts: [fixtureFont], style: [],+ paints: [+ { kind: "stroke", placement: "outside", widthPx: 2,+ paint: { kind: "solid", color: "#000000" } },+ { kind: "fill", paint: { kind: "solid", color: "#ffffff" } },+ ],+ },],}],});@@ -102,6 +108,10 @@ test("HyperFrames flattens generic peer visual Track Presents without absorbingassert.doesNotMatch(document.html, new RegExp(sound.digest, "u"));assert.doesNotMatch(document.html, /isolation:isolate|hypit-visual-track/u);assert.match(document.html, /Hello <world>/u);+ assert.match(document.html, /display:inline-grid/u);+ assert.doesNotMatch(document.html, /display:inline-grid;padding:/u);+ assert.match(document.html, /-webkit-text-stroke:4px #000000/u);+ assert.doesNotMatch(document.html, /<feMorphology/u);assert.doesNotMatch(document.html, /speech-visual-track|caption-track/u);});