🎥 Make videos programmatically with React
Preserve font weight value types in Inspector
Jonny Burger12856a44f8d1
diff --git a/packages/core/src/interactivity-schema.ts b/packages/core/src/interactivity-schema.tsindex 8f31350f6c..247e2427e3 100644--- a/packages/core/src/interactivity-schema.ts+++ b/packages/core/src/interactivity-schema.ts@@ -112,6 +112,13 @@ export type FontFamilyFieldSchema = {keyframable?: false;};+export type FontWeightFieldSchema = {+ type: 'font-weight';+ default: number | string | undefined;+ description?: string;+ keyframable?: false;+};+export type AssetFieldSchema = {type: 'asset';default: string | undefined;@@ -211,6 +218,7 @@ export type VisibleFieldSchema =| ColorFieldSchema| TextContentFieldSchema| FontFamilyFieldSchema+ | FontWeightFieldSchema| AssetFieldSchema| ArrayFieldSchema| CaptionsFieldSchema@@ -301,22 +309,10 @@ export const textSchema = {hiddenFromList: false,},'style.fontWeight': {- type: 'enum',- default: '400',+ type: 'font-weight',+ default: 400,description: 'Font weight',- variants: {- '100': {},- '200': {},- '300': {},- '400': {},- '500': {},- '600': {},- '700': {},- '800': {},- '900': {},- normal: {},- bold: {},- },+ keyframable: false,},'style.fontStyle': {type: 'enum',diff --git a/packages/core/src/test/with-interactivity-schema-helpers.test.ts b/packages/core/src/test/with-interactivity-schema-helpers.test.tsindex ec292f391f..a73539e028 100644--- a/packages/core/src/test/with-interactivity-schema-helpers.test.ts+++ b/packages/core/src/test/with-interactivity-schema-helpers.test.ts@@ -358,19 +358,12 @@ test('textSchema exposes common text style fields', () => {step: 0.05,hiddenFromList: false,});- expect(Object.keys(textSchema['style.fontWeight'].variants)).toEqual([- '100',- '200',- '300',- '400',- '500',- '600',- '700',- '800',- '900',- 'normal',- 'bold',- ]);+ expect(textSchema['style.fontWeight']).toEqual({+ type: 'font-weight',+ default: 400,+ description: 'Font weight',+ keyframable: false,+ });expect(Object.keys(textSchema['style.fontStyle'].variants)).toEqual(['normal','italic',diff --git a/packages/docs/components/effects-demos/schema-control.tsx b/packages/docs/components/effects-demos/schema-control.tsxindex ced6eca87d..cedf4077fd 100644--- a/packages/docs/components/effects-demos/schema-control.tsx+++ b/packages/docs/components/effects-demos/schema-control.tsx@@ -401,6 +401,27 @@ const SchemaControlInput = ({);}+ if (field.type === 'font-weight') {+ const currentValue = value ?? getDefaultValueFromSchema(field);+ return (+ <input+ onChange={(e) => {+ setValue(+ typeof currentValue === 'number'+ ? Number(e.target.value)+ : e.target.value,+ );+ }}+ style={textInputStyle}+ type={typeof currentValue === 'number' ? 'number' : 'text'}+ value={getStringOrNumberValue(+ currentValue,+ getDefaultValueFromSchema(field),+ )}+ />+ );+ }+if (field.type === 'hidden') {return null;}diff --git a/packages/example/e2e/font-weight-controls.test.mts b/packages/example/e2e/font-weight-controls.test.mtsnew file mode 100644index 0000000000..9e1e075b9d--- /dev/null+++ b/packages/example/e2e/font-weight-controls.test.mts@@ -0,0 +1,74 @@+import fs from 'fs';+import path from 'path';+import {expect, test} from '@playwright/test';+import {EXPANDED_SIDEBAR_STATE, STUDIO_URL, exampleDir} from './constants.mts';+import {startStudio, stopStudio} from './studio-server.mts';++const compositionFile = path.join(+ exampleDir,+ 'src',+ 'VisualModeTests',+ 'FontWeightControls.tsx',+);++test.use({storageState: EXPANDED_SIDEBAR_STATE});++test.describe('font weight controls', () => {+ test.beforeEach(async () => {+ await startStudio();+ });++ test.afterEach(async () => {+ await stopStudio();+ });++ test('edits numeric, string, and keyword font weights without changing their types', async ({+ page,+ }) => {+ const originalSource = fs.readFileSync(compositionFile, 'utf-8');++ try {+ await page.goto(`${STUDIO_URL}/font-weight-controls`);+ await expect(page).toHaveURL(/font-weight-controls/, {timeout: 15_000});++ await page+ .locator('[data-timeline-marquee-item][title="Numeric font weight"]')+ .click();+ const numericControl = page.getByRole('button', {+ name: '650',+ exact: true,+ });+ await expect(numericControl).toBeVisible();+ await numericControl.click();+ await page.locator('input[value="650"]').fill('675');+ await page.keyboard.press('Enter');+ await expect+ .poll(() => fs.readFileSync(compositionFile, 'utf-8'))+ .toContain('fontWeight: 675');++ await page+ .locator('[data-timeline-marquee-item][title="String font weight"]')+ .click();+ const stringControl = page.locator('input[value="650"]');+ await expect(stringControl).toBeVisible();+ await stringControl.fill('675');+ await page.keyboard.press('Enter');+ await expect+ .poll(() => fs.readFileSync(compositionFile, 'utf-8'))+ .toContain("fontWeight: '675'");++ await page+ .locator('[data-timeline-marquee-item][title="Keyword font weight"]')+ .click();+ const keywordControl = page.getByTitle('style.fontWeight');+ await expect(keywordControl).toContainText('bold');+ await keywordControl.click();+ await page.getByText('normal', {exact: true}).last().click();+ await expect+ .poll(() => fs.readFileSync(compositionFile, 'utf-8'))+ .toContain("fontWeight: 'normal'");+ } finally {+ fs.writeFileSync(compositionFile, originalSource);+ }+ });+});diff --git a/packages/example/src/E2eTestRoot.tsx b/packages/example/src/E2eTestRoot.tsxindex 88f9ef52dd..1ce7d70c4e 100644--- a/packages/example/src/E2eTestRoot.tsx+++ b/packages/example/src/E2eTestRoot.tsx@@ -25,6 +25,7 @@ import {TimelineVirtualizationTestbed} from './TimelineVirtualizationTestbed';import {VisualControls} from './VisualControls';import {VisualMode3D} from './VisualMode3D';import {AffineFrameClock} from './VisualModeTests/AffineFrameClock';+import {FontWeightControls} from './VisualModeTests/FontWeightControls';import {OutlineSelectionCases} from './VisualModeTests/OutlineSelectionCases';import {SequenceShiftRepro} from './VisualModeTests/SequenceShiftRepro';@@ -206,6 +207,14 @@ export const E2eTestRoot: React.FC = () => {fps={30}durationInFrames={60}/>+ <Composition+ id="font-weight-controls"+ component={FontWeightControls}+ width={1280}+ height={720}+ fps={30}+ durationInFrames={90}+ /><Compositionid="outline-selection-cases"component={OutlineSelectionCases}diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsxindex 79622fe077..1820487223 100644--- a/packages/example/src/Root.tsx+++ b/packages/example/src/Root.tsx@@ -312,6 +312,7 @@ import {AffineFrameClock} from './VisualModeTests/AffineFrameClock';import {ConstantMultiplication} from './VisualModeTests/ConstantMultiplication';import {FastUpdates} from './VisualModeTests/FastUpdates';import {FastUpdatesNested} from './VisualModeTests/FastUpdatesNested';+import {FontWeightControls} from './VisualModeTests/FontWeightControls';import {InteractiveHtmlElements,InteractiveSvgElements,@@ -3060,6 +3061,14 @@ export const Index: React.FC = () => {fps={30}durationInFrames={90}/>+ <Composition+ id="font-weight-controls"+ component={FontWeightControls}+ width={1280}+ height={720}+ fps={30}+ durationInFrames={90}+ /><Compositionid="interactive-svg-elements"component={InteractiveSvgElements}diff --git a/packages/example/src/VisualModeTests/FontWeightControls.tsx b/packages/example/src/VisualModeTests/FontWeightControls.tsxnew file mode 100644index 0000000000..41febf1bd8--- /dev/null+++ b/packages/example/src/VisualModeTests/FontWeightControls.tsx@@ -0,0 +1,56 @@+import React from 'react';+import {AbsoluteFill, Interactive} from 'remotion';++const rowStyle: React.CSSProperties = {+ alignItems: 'center',+ borderRadius: 24,+ display: 'flex',+ flex: 1,+ fontFamily: 'sans-serif',+ fontSize: 64,+ justifyContent: 'center',+};++export const FontWeightControls: React.FC = () => {+ return (+ <AbsoluteFill+ style={{+ backgroundColor: '#0f172a',+ color: '#f8fafc',+ gap: 24,+ padding: 80,+ }}+ >+ <Interactive.Div+ name="Numeric font weight"+ style={{+ ...rowStyle,+ backgroundColor: '#1d4ed8',+ fontWeight: 650,+ }}+ >+ Numeric: 650+ </Interactive.Div>+ <Interactive.Div+ name="String font weight"+ style={{+ ...rowStyle,+ backgroundColor: '#6d28d9',+ fontWeight: '650',+ }}+ >+ String: '650'+ </Interactive.Div>+ <Interactive.Div+ name="Keyword font weight"+ style={{+ ...rowStyle,+ backgroundColor: '#be123c',+ fontWeight: 'bold',+ }}+ >+ Keyword: 'bold'+ </Interactive.Div>+ </AbsoluteFill>+ );+};diff --git a/packages/studio-shared/src/keyframe-clipboard-data.ts b/packages/studio-shared/src/keyframe-clipboard-data.tsindex 9fcccafc27..32a1a293a2 100644--- a/packages/studio-shared/src/keyframe-clipboard-data.ts+++ b/packages/studio-shared/src/keyframe-clipboard-data.ts@@ -15,6 +15,7 @@ const KEYFRAME_CLIPBOARD_FIELD_TYPE_SUPPORT = {color: true,enum: false,'font-family': false,+ 'font-weight': false,hidden: false,number: true,'rotation-css': true,diff --git a/packages/studio-shared/src/keyframe-interpolation-function.ts b/packages/studio-shared/src/keyframe-interpolation-function.tsindex e766553360..7d73a6139e 100644--- a/packages/studio-shared/src/keyframe-interpolation-function.ts+++ b/packages/studio-shared/src/keyframe-interpolation-function.ts@@ -18,6 +18,7 @@ const KEYFRAME_FIELD_TYPE_SUPPORT = {color: true,enum: true,'font-family': false,+ 'font-weight': false,hidden: true,number: true,'rotation-css': true,@@ -42,6 +43,7 @@ const KEYFRAME_FIELD_TYPE_INTERPOLATION = {color: 'interpolateColors',enum: 'interpolate','font-family': 'unsupported',+ 'font-weight': 'unsupported',hidden: 'infer',number: 'infer','rotation-css': 'interpolate',diff --git a/packages/studio-shared/src/schema-field-info.ts b/packages/studio-shared/src/schema-field-info.tsindex 4b97dbf36d..0fab987f25 100644--- a/packages/studio-shared/src/schema-field-info.ts+++ b/packages/studio-shared/src/schema-field-info.ts@@ -226,6 +226,7 @@ const TIMELINE_SCHEMA_FIELD_TYPE_SUPPORT = {color: true,enum: true,'font-family': true,+ 'font-weight': true,hidden: false,number: true,'rotation-css': true,diff --git a/packages/studio/src/components/Timeline/TimelineFontWeightField.tsx b/packages/studio/src/components/Timeline/TimelineFontWeightField.tsxnew file mode 100644index 0000000000..6e479e24b1--- /dev/null+++ b/packages/studio/src/components/Timeline/TimelineFontWeightField.tsx@@ -0,0 +1,128 @@+import React, {useCallback, useMemo} from 'react';+import type {CanUpdateSequencePropStatusStatic} from 'remotion';+import type {+ SchemaFieldInfo,+ TimelineFieldOnDragValueChange,+ TimelineFieldOnSave,+} from '../../helpers/timeline-layout';+import type {ComboboxValue} from '../NewComposition/ComboBox';+import {Combobox} from '../NewComposition/ComboBox';+import {RemotionInput} from '../NewComposition/RemInput';+import {draggerStyle} from './timeline-field-utils';+import {TimelineNumberField} from './TimelineNumberField';++const FONT_WEIGHT_KEYWORDS = ['normal', 'bold', 'bolder', 'lighter'] as const;++export const TimelineFontWeightField: React.FC<{+ readonly field: SchemaFieldInfo;+ readonly propStatus: CanUpdateSequencePropStatusStatic;+ readonly effectiveValue: unknown;+ readonly onSave: TimelineFieldOnSave;+ readonly onDragValueChange: TimelineFieldOnDragValueChange;+ readonly onDragEnd: () => void;+}> = ({+ field,+ propStatus,+ effectiveValue,+ onSave,+ onDragValueChange,+ onDragEnd,+}) => {+ const {fieldSchema} = field;+ if (fieldSchema.type !== 'font-weight') {+ throw new Error(+ 'TimelineFontWeightField rendered for non-font-weight field',+ );+ }++ const sourceValue = propStatus.codeValue ?? fieldSchema.default;+ const currentValue = effectiveValue ?? sourceValue;++ const onSelectKeyword = useCallback(+ (newValue: string) => {+ if (newValue === propStatus.codeValue) {+ return;+ }++ onDragValueChange(newValue);+ onSave(newValue).finally(onDragEnd);+ },+ [onDragEnd, onDragValueChange, onSave, propStatus.codeValue],+ );++ const keywordItems = useMemo<ComboboxValue[]>(() => {+ return FONT_WEIGHT_KEYWORDS.map((keyword) => ({+ type: 'item',+ id: keyword,+ value: keyword,+ label: keyword,+ onClick: () => onSelectKeyword(keyword),+ keyHint: null,+ leftItem: null,+ subMenu: null,+ quickSwitcherLabel: null,+ disabled: false,+ }));+ }, [onSelectKeyword]);++ if (typeof sourceValue === 'number') {+ return (+ <TimelineNumberField+ effectiveValue={currentValue}+ field={field}+ onDragEnd={onDragEnd}+ onDragValueChange={onDragValueChange}+ onSave={onSave}+ propStatus={propStatus}+ />+ );+ }++ if (+ FONT_WEIGHT_KEYWORDS.includes(+ sourceValue as (typeof FONT_WEIGHT_KEYWORDS)[number],+ )+ ) {+ return (+ <Combobox+ size="small"+ title={field.key}+ selectedId={String(currentValue)}+ values={keywordItems}+ />+ );+ }++ return (+ <RemotionInput+ key={String(sourceValue)}+ status="ok"+ rightAlign={false}+ small+ defaultValue={String(currentValue ?? '')}+ onBlur={(event) => {+ const newValue = event.currentTarget.value;+ if (newValue === propStatus.codeValue) {+ onDragEnd();+ return;+ }++ onSave(newValue).finally(onDragEnd);+ }}+ onChange={(event) => onDragValueChange(event.currentTarget.value)}+ onDoubleClick={(event) => event.stopPropagation()}+ onKeyDown={(event) => {+ if (event.key === 'Enter') {+ event.currentTarget.blur();+ }++ if (event.key === 'Escape') {+ event.currentTarget.value = String(propStatus.codeValue ?? '');+ onDragEnd();+ event.currentTarget.blur();+ }+ }}+ style={{...draggerStyle, boxSizing: 'border-box'}}+ />+ );+};diff --git a/packages/studio/src/components/Timeline/TimelineNumberField.tsx b/packages/studio/src/components/Timeline/TimelineNumberField.tsxindex 8a18fc2cb5..1a25e7fec6 100644--- a/packages/studio/src/components/Timeline/TimelineNumberField.tsx+++ b/packages/studio/src/components/Timeline/TimelineNumberField.tsx@@ -93,12 +93,16 @@ export const TimelineNumberField: React.FC<{min={field.fieldSchema.type === 'number'? (field.fieldSchema.min ?? -Infinity)- : -Infinity+ : field.fieldSchema.type === 'font-weight'+ ? 1+ : -Infinity}max={field.fieldSchema.type === 'number'? (field.fieldSchema.max ?? Infinity)- : Infinity+ : field.fieldSchema.type === 'font-weight'+ ? 1000+ : Infinity}step={step}formatter={formatter}diff --git a/packages/studio/src/components/Timeline/TimelinePrimitiveFieldValue.tsx b/packages/studio/src/components/Timeline/TimelinePrimitiveFieldValue.tsxindex bf8ccf17dd..bb95a44180 100644--- a/packages/studio/src/components/Timeline/TimelinePrimitiveFieldValue.tsx+++ b/packages/studio/src/components/Timeline/TimelinePrimitiveFieldValue.tsx@@ -15,6 +15,7 @@ import {TimelineBooleanField} from './TimelineBooleanField';import {TimelineColorField} from './TimelineColorField';import {TimelineEnumField} from './TimelineEnumField';import {TimelineFontFamilyField} from './TimelineFontFamilyField';+import {TimelineFontWeightField} from './TimelineFontWeightField';import {TimelineNumberField} from './TimelineNumberField';import {TimelineRotationField} from './TimelineRotationField';import {TimelineScaleField} from './TimelineScaleField';@@ -247,6 +248,21 @@ export const TimelinePrimitiveFieldValue: React.FC<{);}+ if (field.typeName === 'font-weight') {+ return (+ <span style={inlineWrapper}>+ <TimelineFontWeightField+ effectiveValue={effectiveValue}+ field={field}+ onDragEnd={onDragEnd}+ onDragValueChange={onDragValueChange}+ onSave={onSave}+ propStatus={propStatus}+ />+ </span>+ );+ }+if (field.typeName === 'asset') {return (<span style={assetInlineWrapper}>diff --git a/packages/studio/src/components/Timeline/timeline-field-display-utils.ts b/packages/studio/src/components/Timeline/timeline-field-display-utils.tsindex 284c5ea02a..62e78abaab 100644--- a/packages/studio/src/components/Timeline/timeline-field-display-utils.ts+++ b/packages/studio/src/components/Timeline/timeline-field-display-utils.ts@@ -397,6 +397,7 @@ export const formatTimelineFieldValueForDisplay = ({case 'color':case 'enum':case 'font-family':+ case 'font-weight':case 'hidden':return formatUnknownTimelineValueForDisplay(value);