🎥 Make videos programmatically with React
Elements: Render cylinder text with HtmlInCanvas in absolute-fill mode
Jonny Burger19993c2bb737
diff --git a/packages/docs/components/demos/CylinderTextDemo.tsx b/packages/docs/components/demos/CylinderTextDemo.tsxindex a30e173619..0a27f0b10a 100644--- a/packages/docs/components/demos/CylinderTextDemo.tsx+++ b/packages/docs/components/demos/CylinderTextDemo.tsx@@ -1,8 +1,11 @@+import {Video} from '@remotion/media';import React from 'react';import {AbsoluteFill} from 'remotion';import {CylinderText} from '../../elements/text/cylinder-text/cylinder-text';+import {useHtmlInCanvasDocsDemoBranch} from './useHtmlInCanvasDocsDemoBranch';export const CylinderTextDemo: React.FC = () => {+ const branch = useHtmlInCanvasDocsDemoBranch('webgpu');return (<AbsoluteFillstyle={{@@ -11,7 +14,15 @@ export const CylinderTextDemo: React.FC = () => {backgroundColor: '#eef1f4',}}>- <CylinderText />+ {branch === 'live' ? (+ <CylinderText />+ ) : branch === 'fallback' ? (+ <Video+ muted+ src="https://remotion.media/elements/text-cylinder-text-preview-97956be8-ce8a-4d79-a9aa-f631bbe6dba9.mp4"+ style={{width: '100%', height: '100%'}}+ />+ ) : null}</AbsoluteFill>);};diff --git a/packages/docs/elements/text/cylinder-text/cylinder-text.tsx b/packages/docs/elements/text/cylinder-text/cylinder-text.tsxindex 0aa6aac0e7..358d15c16e 100644--- a/packages/docs/elements/text/cylinder-text/cylinder-text.tsx+++ b/packages/docs/elements/text/cylinder-text/cylinder-text.tsx@@ -1,15 +1,14 @@import {cylinder} from '@remotion/effects/cylinder';import React from 'react';import {- CanvasImage,+ HtmlInCanvas,Interactive,useCurrentFrame,useVideoConfig,- type InteractiveTransformProps,type InteractivitySchema,} from 'remotion';-type CylinderTextProps = InteractiveTransformProps & {+type CylinderTextProps = {readonly text?: string;readonly color?: string;readonly speed?: number;@@ -46,45 +45,49 @@ const CylinderTextInner: React.FC<CylinderTextProps> = ({color = '#182033',speed = 1 / 6,tilt = 52,- style,}) => {const frame = useCurrentFrame();- const {fps} = useVideoConfig();- const [escapedText, escapedColor] = [text, color].map((value) =>- value- .replaceAll('&', '&')- .replaceAll('"', '"')- .replaceAll('<', '<')- .replaceAll('>', '>'),- );- const src = `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="800" height="680" viewBox="0 0 800 680"><text x="0" y="340" dominant-baseline="central" fill="${escapedColor}" font-family="Arial, Helvetica, sans-serif" font-size="90" font-weight="700" textLength="800" lengthAdjust="spacingAndGlyphs" xml:space="preserve">${escapedText}</text></svg>`)}`;+ const {fps, width, height} = useVideoConfig();return (- <div style={{width: 800, height: 680, ...style}}>- <CanvasImage- src={src}- width={800}- height={680}- fit="cover"- showInTimeline={false}- style={{width: '100%', height: '100%'}}- effects={[- cylinder({- radius: 320,- rotation: (frame / fps) * speed * 360,- rotationX: tilt,- rotationZ: -18,- shading: 0.35,- }),- ]}- />- </div>+ <HtmlInCanvas+ width={width}+ height={height}+ name="Cylinder"+ effects={[+ cylinder({+ radius: Math.min(width, height) * 0.42,+ rotation: (frame / fps) * speed * 360,+ rotationX: tilt,+ rotationZ: -18,+ shading: 0.35,+ }),+ ]}+ >+ <div+ style={{+ alignItems: 'center',+ color,+ display: 'flex',+ fontFamily: 'Arial, Helvetica, sans-serif',+ fontSize: width / 22,+ fontWeight: 700,+ height: '100%',+ justifyContent: 'center',+ lineHeight: 1,+ whiteSpace: 'nowrap',+ width: '100%',+ }}+ >+ {text}+ </div>+ </HtmlInCanvas>);};export const CylinderText = Interactive.create({Component: CylinderTextInner,componentName: '<CylinderText>',- layout: 'none',+ layout: 'absolute-fill',schema: cylinderTextSchema,});diff --git a/packages/docs/elements/text/cylinder-text/index.mdx b/packages/docs/elements/text/cylinder-text/index.mdxindex 2ff28fdeee..c876bc5a54 100644--- a/packages/docs/elements/text/cylinder-text/index.mdx+++ b/packages/docs/elements/text/cylinder-text/index.mdx@@ -1,7 +1,7 @@---title: Cylinder Textdescription: Editable text spinning around a tilted cylinder using WebGPU.-image: https://remotion.media/elements/text-cylinder-text-preview-cc13b180-71e3-4c4b-9d87-bbad72173b0d.png+image: https://remotion.media/elements/text-cylinder-text-preview-97956be8-ce8a-4d79-a9aa-f631bbe6dba9.png---import {getElementDefinition} from '@site/src/components/Elements/element-utils';@@ -11,4 +11,4 @@ import {ElementPage} from '@site/src/components/Elements/ElementPage';<ElementPage definition={getElementDefinition('text/cylinder-text')} sourceFile="./cylinder-text.tsx" />-Requires WebGPU. Change the text, color, rotation speed, and tilt in the Inspector. Negative speed reverses the rotation.+Requires WebGPU and [HTML-in-canvas](/docs/html-in-canvas). Change the text, color, rotation speed, and tilt in the Inspector. Negative speed reverses the rotation.diff --git a/packages/docs/src/components/Elements/element-definitions.ts b/packages/docs/src/components/Elements/element-definitions.tsindex c036d8425f..f35b303d8d 100644--- a/packages/docs/src/components/Elements/element-definitions.ts+++ b/packages/docs/src/components/Elements/element-definitions.ts@@ -1169,20 +1169,20 @@ const elementImplementations = ['Editable text spinning around a tilted cylinder using WebGPU.',dependencies: [{name: '@remotion/effects', version: null}],durationInFrames: 180,- elementHeight: 680,- elementWidth: 800,+ elementHeight: null,+ elementWidth: null,fps: 30,height: 1080,posterFrame: 30,preview: {previewLayout: 'composition',posterUrl:- 'https://remotion.media/elements/text-cylinder-text-preview-cc13b180-71e3-4c4b-9d87-bbad72173b0d.png',+ 'https://remotion.media/elements/text-cylinder-text-preview-97956be8-ce8a-4d79-a9aa-f631bbe6dba9.png',backgroundTheme: 'light',videoUrl:- 'https://remotion.media/elements/text-cylinder-text-preview-cc13b180-71e3-4c4b-9d87-bbad72173b0d.mp4',+ 'https://remotion.media/elements/text-cylinder-text-preview-97956be8-ce8a-4d79-a9aa-f631bbe6dba9.mp4',},- safeArea: 120,+ safeArea: 0,initialProps: null,installationMode: 'component-owned-sequence',width: 1920,@@ -1384,6 +1384,7 @@ const elementImplementations = [const htmlInCanvasElementSlugs = new Set<ElementSlug>(['commerce/shine','commerce/tear',+ 'text/cylinder-text',]);export const elementDefinitions = elementImplementations.map((definition) => ({