Skip to content

🎥 Make videos programmatically with React

Fix CRT effects and shutdown glow in client-side rendering

JonnyBurger47b9be16d15b
diff --git a/packages/web-renderer/src/compose.ts b/packages/web-renderer/src/compose.ts
index b5224cd9d7..730f73b80d 100644
--- a/packages/web-renderer/src/compose.ts
+++ b/packages/web-renderer/src/compose.ts
@@ -17,6 +17,12 @@ const getFilterFunction = (node: Node) => {
return NodeFilter.FILTER_REJECT;
}
+ // Canvas children are fallback/layout content. The canvas bitmap already
+ // contains their rendered output, including any <HtmlInCanvas> effects.
+ if (node.parentElement instanceof HTMLCanvasElement) {
+ return NodeFilter.FILTER_REJECT;
+ }
+
const computedStyle = getComputedStyle(node);
if (computedStyle.display === 'none') {
diff --git a/packages/web-renderer/src/drawing/get-background-fill.ts b/packages/web-renderer/src/drawing/get-background-fill.ts
index e589432782..9509f8d943 100644
--- a/packages/web-renderer/src/drawing/get-background-fill.ts
+++ b/packages/web-renderer/src/drawing/get-background-fill.ts
@@ -30,8 +30,62 @@ export const getBackgroundFill = ({
boundingRect: DOMRect;
offsetLeft: number;
offsetTop: number;
-}): CanvasGradient | string | null => {
+}): CanvasGradient | CanvasPattern | string | null => {
if (backgroundImage && backgroundImage !== 'none') {
+ const radialMatch = /^radial-gradient\((.*)\)$/.exec(backgroundImage);
+ if (radialMatch) {
+ const parts = radialMatch[1].split(/,(?![^(]*\))/);
+ const firstPart = parts[0].trim();
+ const hasShape = /^(ellipse|circle|farthest-corner|at)\b/.test(firstPart);
+ // Handle centered gradients with the default farthest-corner extent.
+ // Other positions and explicit radii need their own geometry.
+ if (
+ !hasShape ||
+ /^(?:(?:ellipse|circle)(?: farthest-corner)?|farthest-corner)?(?:\s*at (?:center|50% 50%))?$/.test(
+ firstPart,
+ )
+ ) {
+ const stops = parseLinearGradient(
+ `linear-gradient(${parts.slice(hasShape ? 1 : 0).join(',')})`,
+ );
+ if (stops) {
+ const rect = getBackgroundImageRect({
+ backgroundPosition,
+ backgroundSize,
+ positioningArea: boundingRect,
+ });
+ const circle = hasShape && firstPart.startsWith('circle');
+ const radiusX = circle
+ ? Math.hypot(rect.width / 2, rect.height / 2)
+ : (rect.width / 2) * Math.SQRT2;
+ const radiusY = circle ? radiusX : (rect.height / 2) * Math.SQRT2;
+ if (radiusX > 0 && radiusY > 0) {
+ const canvas = new OffscreenCanvas(
+ Math.ceil(rect.width),
+ Math.ceil(rect.height),
+ );
+ const ctx = canvas.getContext('2d');
+ if (!ctx) throw new Error('Could not get radial gradient context');
+ ctx.translate(rect.width / 2, rect.height / 2);
+ ctx.scale(radiusX, radiusY);
+ const gradient = ctx.createRadialGradient(0, 0, 0, 0, 0, 1);
+ for (const stop of stops.colorStops)
+ gradient.addColorStop(stop.position, stop.color);
+ ctx.fillStyle = gradient;
+ ctx.fillRect(-1, -1, 2, 2);
+ const pattern = contextToDraw.createPattern(canvas, 'no-repeat');
+ pattern?.setTransform(
+ new DOMMatrix().translate(
+ rect.left - offsetLeft,
+ rect.top - offsetTop,
+ ),
+ );
+ return pattern;
+ }
+ }
+ }
+ }
+
const gradientInfo = parseLinearGradient(backgroundImage);
if (gradientInfo) {
const backgroundImageRect = getBackgroundImageRect({