🎥 Make videos programmatically with React
new logic
Jonny Burger0ef7846bf9b5
diff --git a/packages/studio-server/src/preview-server/routes/log-updates/format-prop-change.ts b/packages/studio-server/src/preview-server/routes/log-updates/format-prop-change.tsindex bfa42a94d8..0a80cbce88 100644--- a/packages/studio-server/src/preview-server/routes/log-updates/format-prop-change.ts+++ b/packages/studio-server/src/preview-server/routes/log-updates/format-prop-change.ts@@ -1,25 +1,32 @@-import {formatSideProps, type PropDelta} from './format-side-props';+import {formatSideProps} from './format-side-props';import {- attrName,colorEnabled,- colorValue,- equals,- punctuation,- strikeThrough,+ formatAddition,+ formatDeletion,+ formatPropDelta,+ type PropDelta,} from './formatting';-// Format key={value} with Monokai syntax highlighting-const formatSimpleProp = (key: string, value: string) => {- return `${attrName(key)}${equals('=')}${punctuation('{')}${colorValue(value)}${punctuation('}')}`;-};+const formatInnerPropChange = ({+ key,+ oldValueString,+ newValueString,+ defaultValueString,+}: {+ key: string;+ oldValueString: string;+ newValueString: string;+ defaultValueString: string | null;+}) => {+ if (defaultValueString !== null && newValueString === defaultValueString) {+ return formatDeletion({valueString: oldValueString, key});+ }++ if (defaultValueString !== null && oldValueString === defaultValueString) {+ return formatAddition({valueString: newValueString, key});+ }-// 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('}}')}`;+ return `${formatPropDelta({valueString: oldValueString, key})} \u2192 ${formatPropDelta({valueString: newValueString, key})}`;};export const formatPropChange = ({@@ -40,34 +47,13 @@ export const formatPropChange = ({const color = colorEnabled();const suffix = formatSideProps({removedProps, addedProps, color});- const dotIndex = key.indexOf('.');- const formatProp = (value: string) =>- dotIndex === -1- ? formatSimpleProp(key, value)- : formatNestedProp(- key.slice(0, dotIndex),- key.slice(dotIndex + 1),- value,- );-- if (defaultValueString !== null && newValueString === defaultValueString) {- if (!color) {- return ['removed: ' + formatProp(oldValueString), suffix]- .filter(Boolean)- .join(', ');- }-- return [strikeThrough(formatProp(oldValueString)), suffix]- .filter(Boolean)- .join(', ');- }-- if (defaultValueString !== null && oldValueString === defaultValueString) {- return [formatProp(newValueString), suffix].filter(Boolean).join(', ');- }-return [- `${formatProp(oldValueString)} \u2192 ${formatProp(newValueString)}`,+ formatInnerPropChange({+ key,+ oldValueString,+ newValueString,+ defaultValueString,+ }),suffix,].filter(Boolean)diff --git a/packages/studio-server/src/preview-server/routes/log-updates/format-side-props.ts b/packages/studio-server/src/preview-server/routes/log-updates/format-side-props.tsindex e77b08e8a8..976d7044f8 100644--- a/packages/studio-server/src/preview-server/routes/log-updates/format-side-props.ts+++ b/packages/studio-server/src/preview-server/routes/log-updates/format-side-props.ts@@ -1,53 +1,4 @@-import {- attrName,- colorValue,- equals,- punctuation,- strikeThrough,-} from './formatting';--export type PropDelta = {- key: string;- valueString: string;-};--// 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('}}')}`;-};--const formatPropDelta = ({key, valueString}: PropDelta, color: boolean) => {- if (!color) {- const dotIndex = key.indexOf('.');- if (dotIndex === -1) {- return `${key}={${valueString}}`;- }-- const parent = key.slice(0, dotIndex);- const child = key.slice(dotIndex + 1);- return `${parent}={{${child}: ${valueString}}}`;- }-- const dotIdx = key.indexOf('.');- if (dotIdx === -1) {- return formatSimpleProp(key, valueString);- }-- return formatNestedProp(- key.slice(0, dotIdx),- key.slice(dotIdx + 1),- valueString,- );-};+import {formatAddition, formatDeletion, type PropDelta} from './formatting';export const formatSideProps = ({removedProps,@@ -61,19 +12,12 @@ export const formatSideProps = ({const parts: string[] = [];for (const prop of removedProps) {- const formatted = formatPropDelta(prop, color);- if (color) {- parts.push(strikeThrough(formatted));- } else {- parts.push('removed: ' + formatted);- }+ parts.push(formatDeletion(prop));}for (const prop of addedProps) {if (color) {- parts.push(formatPropDelta(prop, color));- } else {- parts.push('added: ' + formatPropDelta(prop, color));+ parts.push(formatAddition(prop));}}diff --git a/packages/studio-server/src/preview-server/routes/log-updates/formatting.ts b/packages/studio-server/src/preview-server/routes/log-updates/formatting.tsindex 98862820a2..50e84316d1 100644--- a/packages/studio-server/src/preview-server/routes/log-updates/formatting.ts+++ b/packages/studio-server/src/preview-server/routes/log-updates/formatting.ts@@ -34,3 +34,49 @@ export const stringValue = (str: string) => fg(230, 219, 116, str);export const numberValue = (str: string) => fg(174, 129, 255, str);export const strikeThrough = (str: string) =>`\u001b[9m\u001b[38;2;255;85;85m${stripAnsi(str)}\u001b[39m\u001b[29m`;+export const strikeThroughOrRemovedPrefix = (str: string) =>+ colorEnabled() ? strikeThrough(str) : 'removed: ' + str;+export const addedPrefixIfNoColor = (str: string) =>+ colorEnabled() ? 'added: ' + stripAnsi(str) : str;++export type PropDelta = {+ key: string;+ valueString: string;+};++// 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 formatPropDelta = ({key, valueString}: PropDelta) => {+ const dotIdx = key.indexOf('.');+ if (dotIdx === -1) {+ return formatSimpleProp(key, valueString);+ }++ return formatNestedProp(+ key.slice(0, dotIdx),+ key.slice(dotIdx + 1),+ valueString,+ );+};++export const formatDeletion = (prop: PropDelta) => {+ const formatted = formatPropDelta(prop);+ return strikeThroughOrRemovedPrefix(formatted);+};++export const formatAddition = (prop: PropDelta) => {+ const formatted = formatPropDelta(prop);+ return addedPrefixIfNoColor(formatted);+};diff --git a/packages/studio-server/src/preview-server/routes/log-updates/log-update.ts b/packages/studio-server/src/preview-server/routes/log-updates/log-update.tsindex 8ff516d54d..6064f04d25 100644--- a/packages/studio-server/src/preview-server/routes/log-updates/log-update.ts+++ b/packages/studio-server/src/preview-server/routes/log-updates/log-update.ts@@ -1,7 +1,7 @@import {RenderInternals} from '@remotion/renderer';import type {LogLevel} from '@remotion/renderer';import {formatPropChange} from './format-prop-change';-import {type PropDelta} from './format-side-props';+import type {PropDelta} from './formatting';let warnedAboutPrettier = false;