π₯ Make videos programmatically with React
cool
Jonny Burger343dfb2de3f5
diff --git a/packages/studio-server/src/preview-server/routes/apply-visual-control-change.ts b/packages/studio-server/src/preview-server/routes/apply-visual-control-change.tsindex e67ea4b486..b8ad5fb513 100644--- a/packages/studio-server/src/preview-server/routes/apply-visual-control-change.ts+++ b/packages/studio-server/src/preview-server/routes/apply-visual-control-change.ts@@ -70,13 +70,10 @@ export const applyVisualControlHandler: ApiHandler<// Prettier not available, use unformatted output}- pushToUndoStack(- absolutePath,- fileContents,- logLevel,- remotionRoot,- 'visual control change',- );+ pushToUndoStack(absolutePath, fileContents, logLevel, remotionRoot, {+ undoMessage: 'Undid visual control change',+ redoMessage: 'Redid visual control change',+ });suppressUndoStackInvalidation(absolutePath);suppressHmrForFile(absolutePath);writeFileAndNotifyFileWatchers(absolutePath, output);diff --git a/packages/studio-server/src/preview-server/routes/log-update.ts b/packages/studio-server/src/preview-server/routes/log-update.tsindex 927272b781..615b0933eb 100644--- a/packages/studio-server/src/preview-server/routes/log-update.ts+++ b/packages/studio-server/src/preview-server/routes/log-update.ts@@ -18,7 +18,7 @@ export const warnAboutPrettierOnce = (logLevel: LogLevel) => {);};-const normalizeQuotes = (str: string): string => {+export const normalizeQuotes = (str: string): string => {if (str.length >= 2 &&((str.startsWith("'") && str.endsWith("'")) ||@@ -30,29 +30,55 @@ const normalizeQuotes = (str: string): string => {return str;};-const formatValueChange = ({- oldValueString,- newValueString,- defaultValueString,-}: {- oldValueString: string;- newValueString: string;- defaultValueString: string | null;-}) => {- // Changed to default value (prop gets deleted) β show only old value in red- if (defaultValueString !== null && newValueString === defaultValueString) {- return RenderInternals.chalk.red(oldValueString);+// 24-bit ANSI helpers+const fg = (r: number, g: number, b: number, str: string) =>+ `\u001b[38;2;${r};${g};${b}m${str}\u001b[39m`;+const bg = (r: number, g: number, b: number, str: string) =>+ `\u001b[48;2;${r};${g};${b}m${str}\u001b[49m`;++// Monokai-inspired syntax colors+const attrName = (str: string) => fg(166, 226, 46, str);+const equals = (str: string) => fg(249, 38, 114, str);+const punctuation = (str: string) => fg(248, 248, 242, str);+const stringValue = (str: string) => fg(230, 219, 116, str);+const numberValue = (str: string) => fg(174, 129, 255, str);++const colorValue = (str: string) => {+ if (+ (str.startsWith("'") && str.endsWith("'")) ||+ (str.startsWith('"') && str.endsWith('"'))+ ) {+ return stringValue(str);}- // Changed from default value (prop gets added) β show only new value in green- if (defaultValueString !== null && oldValueString === defaultValueString) {- return RenderInternals.chalk.green(newValueString);+ if (/^-?\d+(\.\d+)?$/.test(str)) {+ return numberValue(str);}- return `${RenderInternals.chalk.red(oldValueString)} \u2192 ${RenderInternals.chalk.green(newValueString)}`;+ return punctuation(str);};-const formatPropChange = ({+// Subtle background tints+const removedBg = (str: string) => bg(80, 20, 20, str);+const addedBg = (str: string) => bg(30, 80, 30, str);++const colorEnabled = () => RenderInternals.chalk.enabled();++// Format key={value} with Monokai syntax highlighting+const formatSimpleProp = (key: string, value: string) => {+ return `${attrName(key)}${equals('=')}${punctuation('{')}${colorValue(value)}${punctuation('}')}`;+};++// Format parentKey={{childKey: value}} with Monokai syntax highlighting+const formatNestedProp = (+ parentKey: string,+ childKey: string,+ value: string,+) => {+ return `${attrName(parentKey)}${equals('=')}${punctuation('{{')}${punctuation(childKey)}${punctuation(':')} ${colorValue(value)}${punctuation('}}')}`;+};++export const formatPropChange = ({key,oldValueString,newValueString,@@ -63,42 +89,47 @@ const formatPropChange = ({newValueString: string;defaultValueString: string | null;}) => {+ if (!colorEnabled()) {+ const dotIndex = key.indexOf('.');+ if (dotIndex === -1) {+ return `${key}={${oldValueString}} \u2192 ${key}={${newValueString}}`;+ }++ const parentKey = key.slice(0, dotIndex);+ const childKey = key.slice(dotIndex + 1);+ return `${parentKey}={{${childKey}: ${oldValueString}}} \u2192 ${parentKey}={{${childKey}: ${newValueString}}}`;+ }+const isResetToDefault =defaultValueString !== null && newValueString === defaultValueString;const isChangeFromDefault =defaultValueString !== null && oldValueString === defaultValueString;- const valueChange = formatValueChange({- oldValueString,- newValueString,- defaultValueString,- });-const dotIndex = key.indexOf('.');if (dotIndex === -1) {if (isResetToDefault) {- return RenderInternals.chalk.red(`${key}={${oldValueString}}`);+ return removedBg(formatSimpleProp(key, oldValueString));}if (isChangeFromDefault) {- return RenderInternals.chalk.green(`${key}={${newValueString}}`);+ return addedBg(formatSimpleProp(key, newValueString));}- return `${key}={${valueChange}}`;+ return `${removedBg(formatSimpleProp(key, oldValueString))} \u2192 ${addedBg(formatSimpleProp(key, newValueString))}`;}const parentKey = key.slice(0, dotIndex);const childKey = key.slice(dotIndex + 1);if (isResetToDefault) {- return `${parentKey}={{${RenderInternals.chalk.red(`${childKey}: ${oldValueString}`)}}}`;+ return removedBg(formatNestedProp(parentKey, childKey, oldValueString));}if (isChangeFromDefault) {- return `${parentKey}={{${RenderInternals.chalk.green(`${childKey}: ${newValueString}`)}}}`;+ return addedBg(formatNestedProp(parentKey, childKey, newValueString));}- return `${parentKey}={{${childKey}: ${valueChange}}}`;+ return `${removedBg(formatNestedProp(parentKey, childKey, oldValueString))} \u2192 ${addedBg(formatNestedProp(parentKey, childKey, newValueString))}`;};export const logUpdate = ({diff --git a/packages/studio-server/src/preview-server/routes/save-sequence-props.ts b/packages/studio-server/src/preview-server/routes/save-sequence-props.tsindex 480b19b9d1..b2af56e9ae 100644--- a/packages/studio-server/src/preview-server/routes/save-sequence-props.ts+++ b/packages/studio-server/src/preview-server/routes/save-sequence-props.ts@@ -14,7 +14,7 @@ import {suppressUndoStackInvalidation,} from '../undo-stack';import {computeSequencePropsStatus} from './can-update-sequence-props';-import {logUpdate} from './log-update';+import {formatPropChange, logUpdate, normalizeQuotes} from './log-update';export const saveSequencePropsHandler: ApiHandler<SaveSequencePropsRequest,@@ -41,28 +41,45 @@ export const saveSequencePropsHandler: ApiHandler<defaultValue: defaultValue !== null ? JSON.parse(defaultValue) : null,});- pushToUndoStack(- absolutePath,- fileContents,- logLevel,- remotionRoot,- 'sequence props update',- );+ const newValueString = JSON.stringify(JSON.parse(value));+ const parsedDefault =+ defaultValue !== null ? JSON.parse(defaultValue) : null;+ const defaultValueString =+ parsedDefault !== null ? JSON.stringify(parsedDefault) : null;++ const normalizedOld = normalizeQuotes(oldValueString);+ const normalizedNew = normalizeQuotes(newValueString);+ const normalizedDefault =+ defaultValueString !== null ? normalizeQuotes(defaultValueString) : null;++ const undoPropChange = formatPropChange({+ key,+ oldValueString: normalizedNew,+ newValueString: normalizedOld,+ defaultValueString: normalizedDefault,+ });+ const redoPropChange = formatPropChange({+ key,+ oldValueString: normalizedOld,+ newValueString: normalizedNew,+ defaultValueString: normalizedDefault,+ });++ pushToUndoStack(absolutePath, fileContents, logLevel, remotionRoot, {+ undoMessage: `Undid ${undoPropChange}`,+ redoMessage: `Redid ${redoPropChange}`,+ });suppressUndoStackInvalidation(absolutePath);suppressHmrForFile(absolutePath);writeFileAndNotifyFileWatchers(absolutePath, output);- const newValueString = JSON.stringify(JSON.parse(value));- const parsedDefault =- defaultValue !== null ? JSON.parse(defaultValue) : null;logUpdate({absolutePath,fileRelativeToRoot,key,oldValueString,newValueString,- defaultValueString:- parsedDefault !== null ? JSON.stringify(parsedDefault) : null,+ defaultValueString,formatted,logLevel,});diff --git a/packages/studio-server/src/preview-server/routes/update-default-props.ts b/packages/studio-server/src/preview-server/routes/update-default-props.tsindex f2946b9d2f..0433d2e9c5 100644--- a/packages/studio-server/src/preview-server/routes/update-default-props.ts+++ b/packages/studio-server/src/preview-server/routes/update-default-props.ts@@ -50,7 +50,10 @@ export const updateDefaultPropsHandler: ApiHandler<fileContents,logLevel,remotionRoot,- 'default props update',+ {+ undoMessage: `Undid default props update for "${compositionId}"`,+ redoMessage: `Redid default props update for "${compositionId}"`,+ },);suppressUndoStackInvalidation(projectInfo.rootFile);suppressHmrForFile(projectInfo.rootFile);diff --git a/packages/studio-server/src/preview-server/undo-stack.ts b/packages/studio-server/src/preview-server/undo-stack.tsindex 1d126ec2cf..ceaa31f57e 100644--- a/packages/studio-server/src/preview-server/undo-stack.ts+++ b/packages/studio-server/src/preview-server/undo-stack.ts@@ -11,10 +11,15 @@ import {suppressHmrForFile} from './hmr-suppression';import {waitForLiveEventsListener} from './live-events';import {suppressBundlerUpdateForFile} from './watch-ignore-next-change';+export interface UndoEntryDescription {+ undoMessage: string;+ redoMessage: string;+}+interface UndoEntry {filePath: string;oldContents: string;- description: string;+ description: UndoEntryDescription;}const MAX_ENTRIES = 100;@@ -46,7 +51,7 @@ export function pushToUndoStack(oldContents: string,logLevel: LogLevel,remotionRoot: string,- description: string,+ description: UndoEntryDescription,) {storedLogLevel = logLevel;storedRemotionRoot = remotionRoot;@@ -82,7 +87,7 @@ export function printUndoHint(logLevel: LogLevel) {export function pushToRedoStack(filePath: string,oldContents: string,- description: string,+ description: UndoEntryDescription,) {redoStack.push({filePath, oldContents, description});if (redoStack.length > MAX_ENTRIES) {@@ -232,7 +237,7 @@ export function popUndo(): {success: true} | {success: false; reason: string} {`Undo: restored ${entry.filePath} (undo: ${undoStack.length}, redo: ${redoStack.length})`,),);- logFileAction(`Undid ${entry.description}`, entry.filePath);+ logFileAction(entry.description.undoMessage, entry.filePath);ensureWatching(entry.filePath);broadcastState();@@ -263,7 +268,7 @@ export function popRedo(): {success: true} | {success: false; reason: string} {`Redo: restored ${entry.filePath} (undo: ${undoStack.length}, redo: ${redoStack.length})`,),);- logFileAction(`Redid ${entry.description}`, entry.filePath);+ logFileAction(entry.description.redoMessage, entry.filePath);ensureWatching(entry.filePath);broadcastState();