🎥 Make videos programmatically with React
cool
Jonny Burgeref67d1046c10
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 490fe2c7bd..bfa42a94d8 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,10 +1,7 @@-import {- colorEnabled,- formatSideProps,- type PropDelta,-} from './format-side-props';+import {formatSideProps, type PropDelta} from './format-side-props';import {attrName,+ colorEnabled,colorValue,equals,punctuation,@@ -40,18 +37,8 @@ export const formatPropChange = ({removedProps: PropDelta[];addedProps: PropDelta[];}) => {- const suffix = formatSideProps({removedProps, addedProps});-- if (!colorEnabled()) {- const dotIdx = key.indexOf('.');- if (dotIdx === -1) {- return `${key}={${oldValueString}} \u2192 ${key}={${newValueString}}${suffix}`;- }-- const parent = key.slice(0, dotIdx);- const child = key.slice(dotIdx + 1);- return `${parent}={{${child}: ${oldValueString}}} \u2192 ${parent}={{${child}: ${newValueString}}}${suffix}`;- }+ const color = colorEnabled();+ const suffix = formatSideProps({removedProps, addedProps, color});const dotIndex = key.indexOf('.');const formatProp = (value: string) =>@@ -64,12 +51,25 @@ export const formatPropChange = ({);if (defaultValueString !== null && newValueString === defaultValueString) {- return `${strikeThrough(formatProp(oldValueString))}${suffix}`;+ 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}`;+ return [formatProp(newValueString), suffix].filter(Boolean).join(', ');}- return `${formatProp(oldValueString)} \u2192 ${formatProp(newValueString)}${suffix}`;+ return [+ `${formatProp(oldValueString)} \u2192 ${formatProp(newValueString)}`,+ suffix,+ ]+ .filter(Boolean)+ .join(', ');};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 9d44136859..e77b08e8a8 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,4 +1,3 @@-import {RenderInternals} from '@remotion/renderer';import {attrName,colorValue,@@ -12,8 +11,6 @@ export type PropDelta = {valueString: string;};-export const colorEnabled = () => RenderInternals.chalk.enabled();-// Format key={value} with Monokai syntax highlightingconst formatSimpleProp = (key: string, value: string) => {return `${attrName(key)}${equals('=')}${punctuation('{')}${colorValue(value)}${punctuation('}')}`;@@ -28,8 +25,8 @@ const formatNestedProp = (return `${attrName(parentKey)}${equals('=')}${punctuation('{{')}${punctuation(childKey)}${punctuation(':')} ${colorValue(value)}${punctuation('}}')}`;};-const formatPropDelta = ({key, valueString}: PropDelta) => {- if (!colorEnabled()) {+const formatPropDelta = ({key, valueString}: PropDelta, color: boolean) => {+ if (!color) {const dotIndex = key.indexOf('.');if (dotIndex === -1) {return `${key}={${valueString}}`;@@ -55,24 +52,34 @@ const formatPropDelta = ({key, valueString}: PropDelta) => {export const formatSideProps = ({removedProps,addedProps,+ color,}: {removedProps: PropDelta[];addedProps: PropDelta[];+ color: boolean;}) => {const parts: string[] = [];for (const prop of removedProps) {- const formatted = formatPropDelta(prop);- parts.push(colorEnabled() ? strikeThrough(formatted) : formatted);+ const formatted = formatPropDelta(prop, color);+ if (color) {+ parts.push(strikeThrough(formatted));+ } else {+ parts.push('removed: ' + formatted);+ }}for (const prop of addedProps) {- parts.push(formatPropDelta(prop));+ if (color) {+ parts.push(formatPropDelta(prop, color));+ } else {+ parts.push('added: ' + formatPropDelta(prop, color));+ }}if (parts.length === 0) {- return '';+ return null;}- return `, ${parts.join(', ')}`;+ return parts.join(', ');};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 1398c2bd21..98862820a2 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@@ -1,3 +1,7 @@+import {RenderInternals} from '@remotion/renderer';++export const colorEnabled = () => RenderInternals.chalk.enabled();+export const colorValue = (str: string) => {if ((str.startsWith("'") && str.endsWith("'")) ||@@ -18,9 +22,9 @@ const stripAnsi = (str: string) => str.replace(/\u001b\[[0-9;]*m/g, '');// 24-bit ANSI helpersexport const fg = (r: number, g: number, b: number, str: string) =>- `\u001b[38;2;${r};${g};${b}m${str}\u001b[39m`;+ colorEnabled() ? `\u001b[38;2;${r};${g};${b}m${str}\u001b[39m` : str;export const bg = (r: number, g: number, b: number, str: string) =>- `\u001b[48;2;${r};${g};${b}m${str}\u001b[49m`;+ colorEnabled() ? `\u001b[48;2;${r};${g};${b}m${str}\u001b[49m` : str;// Monokai-inspired syntax colorsexport const attrName = (str: string) => fg(166, 226, 46, str);