🎥 Make videos programmatically with React
@remotion/studio: Add HTML-in-canvas quick actions
JonnyBurgerd9591bec6c14
diff --git a/packages/studio/src/components/HtmlInCanvasUnavailableModal.tsx b/packages/studio/src/components/HtmlInCanvasUnavailableModal.tsxnew file mode 100644index 0000000000..948478917a--- /dev/null+++ b/packages/studio/src/components/HtmlInCanvasUnavailableModal.tsx@@ -0,0 +1,137 @@+import React, {useCallback, useContext} from 'react';+import {BLACK_ALPHA_30, LIGHT_TEXT, WHITE} from '../helpers/colors';+import {copyText} from '../helpers/copy-text';+import {useCopyFeedback} from '../helpers/use-copy-feedback';+import {CopyIcon} from '../icons/copy';+import type {ModalState} from '../state/modals';+import {SetSelectedModalContext} from '../state/modals';+import type {RenderInlineAction} from './InlineAction';+import {InlineAction} from './InlineAction';+import {Flex, Row} from './layout';+import {ModalButton} from './ModalButton';+import {getMaxModalWidth} from './ModalContainer';+import {ModalFooterContainer} from './ModalFooter';+import {ModalHeader} from './ModalHeader';+import {DismissableModal} from './NewComposition/DismissableModal';+import {showNotification} from './Notifications/NotificationCenter';++const chromeFlagUrl = 'chrome://flags/#canvas-draw-element';++const panelStyle: React.CSSProperties = {+ borderRadius: 6,+ display: 'flex',+ flexDirection: 'column',+ minWidth: 0,+ overflow: 'hidden',+ width: getMaxModalWidth(520),+};++const contentStyle: React.CSSProperties = {+ padding: 16,+};++const bodyTextStyle: React.CSSProperties = {+ color: LIGHT_TEXT,+ fontFamily: 'sans-serif',+ fontSize: 14,+ lineHeight: 1.5,+};++const urlFieldStyle: React.CSSProperties = {+ alignItems: 'center',+ background: BLACK_ALPHA_30,+ borderRadius: 6,+ display: 'flex',+ gap: 8,+ margin: '12px 0',+ padding: '8px 8px 8px 10px',+ width: '100%',+};++const urlStyle: React.CSSProperties = {+ color: WHITE,+ flex: 1,+ fontFamily: 'monospace',+ fontSize: 13,+ fontWeight: 'normal',+ lineHeight: 1.5,+ margin: 0,+ minWidth: 0,+ overflowWrap: 'anywhere',+ whiteSpace: 'pre-wrap',+};++const copyActionStyle: React.CSSProperties = {flexShrink: 0};+const copyIconStyle: React.CSSProperties = {height: 12, width: 12};+const footerStyle: React.CSSProperties = {minWidth: 0};+const buttonTextStyle: React.CSSProperties = {+ color: WHITE,+ fontFamily: 'sans-serif',+ fontSize: 14,+ lineHeight: 1.5,+};++type State = Extract<ModalState, {type: 'html-in-canvas-unavailable'}>;++export const HtmlInCanvasUnavailableModal: React.FC<{+ readonly state: State;+}> = ({state}) => {+ const {setSelectedModal} = useContext(SetSelectedModalContext);+ const {copied, markCopied} = useCopyFeedback();++ const onCopy = useCallback(() => {+ copyText(chromeFlagUrl)+ .then(markCopied)+ .catch((error) => {+ showNotification(`Could not copy: ${error.message}`, 2000);+ });+ }, [markCopied]);++ const renderCopy: RenderInlineAction = useCallback(+ (color) => <CopyIcon copied={copied} color={color} style={copyIconStyle} />,+ [copied],+ );++ const onClose = useCallback(() => {+ setSelectedModal(null);+ }, [setSelectedModal]);++ return (+ <DismissableModal panelStyle={panelStyle}>+ <ModalHeader title="Enable HTML-in-canvas in Chrome" />+ <div style={contentStyle}>+ <div style={bodyTextStyle}>+ {state.action === 'motion-blur'+ ? 'Enable HTML-in-canvas in Chrome to apply motion blur to this element.'+ : 'Enable HTML-in-canvas in Chrome to apply effects to this element.'}+ </div>+ <div style={urlFieldStyle}>+ <pre style={urlStyle}>{chromeFlagUrl}</pre>+ <InlineAction+ onClick={onCopy}+ renderAction={renderCopy}+ style={copyActionStyle}+ aria-label={copied ? 'Copied Chrome URL' : 'Copy Chrome URL'}+ variant={null}+ />+ </div>+ <div style={bodyTextStyle}>+ Set the HTML-in-Canvas flag to Enabled, then fully restart Chrome and+ reopen Remotion Studio.+ </div>+ </div>+ <ModalFooterContainer style={footerStyle}>+ <Row align="center">+ <Flex />+ <ModalButton+ onClick={onClose}+ autoFocus+ buttonContainerStyle={buttonTextStyle}+ >+ Got it+ </ModalButton>+ </Row>+ </ModalFooterContainer>+ </DismissableModal>+ );+};diff --git a/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx b/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsxindex 455833b026..34e59c0b4f 100644--- a/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx+++ b/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx@@ -354,12 +354,14 @@ const SequenceSourceQuickActions: React.FC<{>Duplicate</InspectorQuickAction>- <SequenceWrapAction- nodePathInfo={selection.nodePathInfo}- sequence={track.sequence}- sourceActionsDisabled={sourceActionsDisabled}- sourceLocation={validatedLocation}- />+ {track.sequence.type === 'video' ? null : (+ <SequenceWrapAction+ nodePathInfo={selection.nodePathInfo}+ sequence={track.sequence}+ sourceActionsDisabled={sourceActionsDisabled}+ sourceLocation={validatedLocation}+ />+ )}<SequencePrecomposeActiontargets={[{diff --git a/packages/studio/src/components/InspectorPanel/SequenceWrapAction.tsx b/packages/studio/src/components/InspectorPanel/SequenceWrapAction.tsxindex d87e98364c..5285079923 100644--- a/packages/studio/src/components/InspectorPanel/SequenceWrapAction.tsx+++ b/packages/studio/src/components/InspectorPanel/SequenceWrapAction.tsx@@ -1,67 +1,37 @@import type {NodeWrapper} from '@remotion/studio-shared';-import React, {useCallback, useContext, useMemo, useState} from 'react';-import {isHtmlInCanvasSupported, useVideoConfig} from 'remotion';-import {LIGHT_TEXT} from '../../helpers/colors';+import React, {+ useCallback,+ useContext,+ useEffect,+ useMemo,+ useState,+} from 'react';+import {Internals, isHtmlInCanvasSupported, useVideoConfig} from 'remotion';import type {SequenceNodePathInfo,TimelineTrackData,} from '../../helpers/get-timeline-sequence-sort-key';import {installRequiredPackages} from '../../helpers/install-required-package';-import {CaretDown} from '../../icons/caret';-import {WrapIcon} from '../../icons/wrap';+import {HtmlInCanvasIcon} from '../../icons/html-in-canvas';+import {MotionBlurIcon} from '../../icons/motion-blur';import {SetSelectedModalContext} from '../../state/modals';-import {INSPECTOR_PANEL_HORIZONTAL_PADDING} from '../InspectorPanelLayout';-import type {ComboboxValue} from '../NewComposition/ComboBox';import {showNotification} from '../Notifications/NotificationCenter';-import {SegmentedButton, type SegmentedButtonSegment} from '../SegmentedButton';import {wrapNode} from '../wrap-node-api';import {+ InspectorQuickAction,largeInspectorActionIconContainerStyle,largeInspectorActionIconStyle,} from './common';-const wrapperNames: NodeWrapper[] = [- 'AbsoluteFill',- 'Sequence',- 'HtmlInCanvas',- 'HtmlInCanvasMotionBlur',-];--const buttonStyle: React.CSSProperties = {- borderRadius: 4,- height: 28,- margin: '0 4px',- width: 'calc(100% - 8px)',-};--const segmentStyle: React.CSSProperties = {- fontSize: 13,- gap: 8,- justifyContent: 'flex-start',- padding: `0 ${INSPECTOR_PANEL_HORIZONTAL_PADDING - 4}px`,- width: '100%',-};--const labelStyle: React.CSSProperties = {- flex: 1,- fontFamily: 'sans-serif',- fontSize: 13,- lineHeight: '18px',- minWidth: 0,- overflow: 'hidden',- textAlign: 'left',- textOverflow: 'ellipsis',- userSelect: 'none',- WebkitUserSelect: 'none',- whiteSpace: 'nowrap',-};+type HtmlInCanvasWrapper = Extract<+ NodeWrapper,+ 'HtmlInCanvas' | 'HtmlInCanvasMotionBlur'+>;-const caretStyle: React.CSSProperties = {- display: 'flex',- flexShrink: 0,- height: 12,- width: 12,-};+const htmlInCanvasComponentIdentities = new Set([+ 'dev.remotion.remotion.HtmlInCanvas',+ 'dev.remotion.motionBlur.HtmlInCanvasMotionBlur',+]);export const SequenceWrapAction: React.FC<{readonly nodePathInfo: SequenceNodePathInfo;@@ -74,12 +44,115 @@ export const SequenceWrapAction: React.FC<{}> = ({nodePathInfo, sequence, sourceActionsDisabled, sourceLocation}) => {const {width, height} = useVideoConfig();const {setSelectedModal} = useContext(SetSelectedModalContext);+ const {sequences} = useContext(Internals.SequenceManager);const nodePathKey = JSON.stringify(nodePathInfo.sequenceSubscriptionKey);+ const sequenceStack = sequence.getStack();+ const eligibilityKey = JSON.stringify([nodePathKey, sequenceStack]);const [busy, setBusy] = useState(false);+ const [eligibleNodeKey, setEligibleNodeKey] = useState<string | null>(null);+ const wouldNestAtRuntime = useMemo(() => {+ const sequencesById = new Map(+ sequences.map((registeredSequence) => [+ registeredSequence.id,+ registeredSequence,+ ]),+ );+ let ancestorId: string | null = sequence.id;+ while (ancestorId !== null) {+ const ancestor = sequencesById.get(ancestorId);+ if (!ancestor) {+ break;+ }++ if (+ ancestor.controls?.componentIdentity &&+ htmlInCanvasComponentIdentities.has(ancestor.controls.componentIdentity)+ ) {+ return true;+ }++ ancestorId = ancestor.parent;+ }++ for (const registeredSequence of sequences) {+ if (+ !registeredSequence.controls?.componentIdentity ||+ !htmlInCanvasComponentIdentities.has(+ registeredSequence.controls.componentIdentity,+ )+ ) {+ continue;+ }++ let descendantParentId = registeredSequence.parent;+ while (descendantParentId !== null) {+ if (descendantParentId === sequence.id) {+ return true;+ }++ descendantParentId =+ sequencesById.get(descendantParentId)?.parent ?? null;+ }+ }++ return false;+ }, [sequence.id, sequences]);++ useEffect(() => {+ if (sourceActionsDisabled || wouldNestAtRuntime) {+ setEligibleNodeKey(null);+ return;+ }++ let cancelled = false;+ setEligibleNodeKey(null);+ const nodePath = JSON.parse(+ nodePathKey,+ ) as SequenceNodePathInfo['sequenceSubscriptionKey'];+ wrapNode({+ fileName: nodePath.absolutePath,+ nodePath: nodePath.nodePath,+ wrapper: null,+ width: null,+ height: null,+ })+ .then((eligibility) => {+ if (!cancelled) {+ setEligibleNodeKey(+ eligibility.success && eligibility.canWrapHtmlInCanvas+ ? eligibilityKey+ : null,+ );+ }+ })+ .catch(() => {+ if (!cancelled) {+ setEligibleNodeKey(null);+ }+ });++ return () => {+ cancelled = true;+ };+ }, [eligibilityKey, nodePathKey, sourceActionsDisabled, wouldNestAtRuntime]);const onWrap = useCallback(- async (wrapper: NodeWrapper) => {- if (busy || sourceActionsDisabled) {+ async (wrapper: HtmlInCanvasWrapper) => {+ if (+ busy ||+ sourceActionsDisabled ||+ wouldNestAtRuntime ||+ eligibleNodeKey !== eligibilityKey+ ) {+ return;+ }++ if (!isHtmlInCanvasSupported()) {+ setSelectedModal({+ type: 'html-in-canvas-unavailable',+ action:+ wrapper === 'HtmlInCanvasMotionBlur' ? 'motion-blur' : 'effects',+ });return;}@@ -100,12 +173,7 @@ export const SequenceWrapAction: React.FC<{return;}- if (- !eligibility.canWrap ||- ((wrapper === 'HtmlInCanvas' ||- wrapper === 'HtmlInCanvasMotionBlur') &&- !eligibility.canWrapHtmlInCanvas)- ) {+ if (!eligibility.canWrap) {setSelectedModal({type: 'wrap-refactor',displayName:@@ -116,6 +184,12 @@ export const SequenceWrapAction: React.FC<{return;}+ if (!eligibility.canWrapHtmlInCanvas) {+ showNotification('HTML-in-canvas components cannot be nested.', 4000);+ setEligibleNodeKey(null);+ return;+ }+if (wrapper === 'HtmlInCanvasMotionBlur') {await installRequiredPackages([{name: '@remotion/motion-blur', version: null},@@ -140,6 +214,8 @@ export const SequenceWrapAction: React.FC<{},[busy,+ eligibilityKey,+ eligibleNodeKey,height,nodePathKey,sequence.controls?.componentName,@@ -148,68 +224,44 @@ export const SequenceWrapAction: React.FC<{sourceActionsDisabled,sourceLocation,width,+ wouldNestAtRuntime,],);- const values = useMemo<ComboboxValue[]>(- () =>- wrapperNames.map((wrapper) => ({- type: 'item',- id: wrapper,- label: `<${wrapper}>`,- value: wrapper,- onClick: () => onWrap(wrapper),- keyHint: null,- leftItem: null,- subMenu: null,- quickSwitcherLabel: null,- disabled:- busy ||- ((wrapper === 'HtmlInCanvas' ||- wrapper === 'HtmlInCanvasMotionBlur') &&- !isHtmlInCanvasSupported()),- })),- [busy, onWrap],- );+ if (+ sourceActionsDisabled ||+ eligibleNodeKey !== eligibilityKey ||+ wouldNestAtRuntime+ ) {+ return null;+ }- const segments = useMemo<SegmentedButtonSegment[]>(- () => [- {- ariaLabel:- nodePathInfo.numberOfSequencesWithThisNodePath > 1- ? `Wrap all ${nodePathInfo.numberOfSequencesWithThisNodePath} instances of this JSX element`- : 'Wrap this JSX element',- buttonId: null,- disabled: busy || sourceActionsDisabled,- idleColor: LIGHT_TEXT,- leaveLeftSpace: false,- onOpenChange: null,- renderContent: (color) => (- <>- <span style={largeInspectorActionIconContainerStyle}>- <WrapIcon color={color} style={largeInspectorActionIconStyle} />- </span>- <span style={labelStyle}>Wrap</span>- <span style={caretStyle}>- <CaretDown color={color} />- </span>- </>- ),- segmentId: 'wrap',- selectedId: null,- style: segmentStyle,- tooltipLabel: null,- type: 'menu',- values,- },- ],- [- busy,- nodePathInfo.numberOfSequencesWithThisNodePath,- sourceActionsDisabled,- values,- ],+ return (+ <>+ <InspectorQuickAction+ disabled={busy || sourceActionsDisabled}+ iconContainerStyle={largeInspectorActionIconContainerStyle}+ onClick={() => onWrap('HtmlInCanvas')}+ renderIcon={(color) => (+ <HtmlInCanvasIcon+ color={color}+ style={largeInspectorActionIconStyle}+ viewBox="-64 -80 704 704"+ />+ )}+ >+ HTML-in-canvas+ </InspectorQuickAction>+ <InspectorQuickAction+ disabled={busy || sourceActionsDisabled}+ iconContainerStyle={largeInspectorActionIconContainerStyle}+ onClick={() => onWrap('HtmlInCanvasMotionBlur')}+ renderIcon={(color) => (+ <MotionBlurIcon color={color} style={largeInspectorActionIconStyle} />+ )}+ >+ Motion blur+ </InspectorQuickAction>+ </>);-- return <SegmentedButton segments={segments} style={buttonStyle} />;};diff --git a/packages/studio/src/components/Modals.tsx b/packages/studio/src/components/Modals.tsxindex 7a3cc414ce..987a76150d 100644--- a/packages/studio/src/components/Modals.tsx+++ b/packages/studio/src/components/Modals.tsx@@ -15,6 +15,7 @@ import {import {ElementLibraryModal} from './ElementLibraryModal';import {FixComputedValueModal} from './FixComputedValueModal';import {GenerateWithAgentModal} from './GenerateWithAgentModal';+import {HtmlInCanvasUnavailableModal} from './HtmlInCanvasUnavailableModal';import {DeleteComposition} from './NewComposition/DeleteComposition';import {DeleteFolder} from './NewComposition/DeleteFolder';import {DuplicateComposition} from './NewComposition/DuplicateComposition';@@ -293,6 +294,10 @@ export const Modals: React.FC<{{modalContextType && modalContextType.type === 'wrap-refactor' ? (<WrapRefactorModal state={modalContextType} />) : null}+ {modalContextType &&+ modalContextType.type === 'html-in-canvas-unavailable' ? (+ <HtmlInCanvasUnavailableModal state={modalContextType} />+ ) : null}{modalContextType && modalContextType.type === 'quick-switcher' && (<QuickSwitcherreadOnlyStudio={readOnlyStudio}diff --git a/packages/studio/src/icons/html-in-canvas.tsx b/packages/studio/src/icons/html-in-canvas.tsxnew file mode 100644index 0000000000..9d9155e4a6--- /dev/null+++ b/packages/studio/src/icons/html-in-canvas.tsx@@ -0,0 +1,16 @@+import type {SVGProps} from 'react';++// Font Awesome Pro v7.3.1, Copyright 2026 Fonticons, Inc.+// https://fontawesome.com/license (Commercial License)+export const HtmlInCanvasIcon: React.FC<+ SVGProps<SVGSVGElement> & {readonly color: string}+> = ({color, ...props}) => {+ return (+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" {...props}>+ <path+ fill={color}+ d="M90.6 89.1l-22.9 102.9 129.6 0 9.6-128-85.1 0c-15 0-28 10.4-31.2 25.1zM60.6 224L40.8 313.1C36.4 333 51.6 352 72 352l113.3 0 9.6-128-134.3 0zM217.4 352l141.5 0-9.6-128-122.3 0-9.6 128zM391 352l113.3 0c20.5 0 35.7-19 31.2-38.9l-19.8-89.1-134.3 0 9.6 128zM508.6 192L485.7 89.1C482.5 74.4 469.5 64 454.5 64l-85.1 0 9.6 128 129.6 0zM337.3 64l-98.3 0-9.6 128 117.5 0-9.6-128zM59.3 82.1C65.8 52.8 91.8 32 121.8 32l332.7 0c30 0 56 20.8 62.5 50.1l49.8 224c8.9 40-21.5 77.9-62.5 77.9l-200.1 0 0 96 96 0c8.8 0 16 7.2 16 16s-7.2 16-16 16l-224 0c-8.8 0-16-7.2-16-16s7.2-16 16-16l96 0 0-96-200.1 0C31.1 384 .7 346.1 9.6 306.1l49.8-224z"+ />+ </svg>+ );+};diff --git a/packages/studio/src/icons/motion-blur.tsx b/packages/studio/src/icons/motion-blur.tsxnew file mode 100644index 0000000000..ecc7c1df4c--- /dev/null+++ b/packages/studio/src/icons/motion-blur.tsx@@ -0,0 +1,25 @@+import type {SVGProps} from 'react';++export const MotionBlurIcon: React.FC<+ SVGProps<SVGSVGElement> & {readonly color: string}+> = ({color, ...props}) => {+ return (+ <svg {...props} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640">+ <circle+ cx={220}+ cy={320}+ fill="none"+ r={160}+ stroke={color}+ strokeWidth={28}+ />+ <path+ d="M420 160a160 160 0 0 1 0 320"+ fill="none"+ stroke={color}+ strokeLinecap="round"+ strokeWidth={28}+ />+ </svg>+ );+};diff --git a/packages/studio/src/state/modals.ts b/packages/studio/src/state/modals.tsindex 6e9c6bdfea..ab9a1fc52a 100644--- a/packages/studio/src/state/modals.ts+++ b/packages/studio/src/state/modals.ts@@ -311,6 +311,10 @@ export type ModalState =};wrapper: NodeWrapper;}+ | {+ type: 'html-in-canvas-unavailable';+ action: 'effects' | 'motion-blur';+ }| {type: 'quick-switcher';mode: QuickSwitcherMode;