🎥 Make videos programmatically with React
make studio a package
Jonny Burger2db8a9d841f4
diff --git a/packages/core/src/default-css.ts b/packages/core/src/default-css.tsindex 805791a96c..533f732455 100644--- a/packages/core/src/default-css.ts+++ b/packages/core/src/default-css.ts@@ -21,7 +21,7 @@ export const injectCSS = (css: string) => {export const OFFTHREAD_VIDEO_CLASS_NAME = '__remotion_offthreadvideo';-export const makeDefaultCSS = (+export const makeDefaultPreviewCSS = (scope: string | null,backgroundColor: string,) => {diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsxindex 1db63a5b93..1703d55634 100644--- a/packages/player/src/Player.tsx+++ b/packages/player/src/Player.tsx@@ -321,7 +321,10 @@ const PlayerFn = <Schema extends AnyZodObject, Props>(useLayoutEffect(() => {// Inject CSS only on client, and also only after the Player has hydratedInternals.CSSUtils.injectCSS(- Internals.CSSUtils.makeDefaultCSS(`.${PLAYER_CSS_CLASSNAME}`, '#fff'),+ Internals.CSSUtils.makeDefaultPreviewCSS(+ `.${PLAYER_CSS_CLASSNAME}`,+ '#fff',+ ),);}, []);}diff --git a/packages/studio/bundle.ts b/packages/studio/bundle.tsnew file mode 100644index 0000000000..fe7f504d9d--- /dev/null+++ b/packages/studio/bundle.ts@@ -0,0 +1,26 @@+import {build} from 'bun';++const mainModule = await build({+ entrypoints: ['src/index.ts'],+ naming: '[name].mjs',+ external: ['react', 'remotion', 'remotion/no-react', 'react/jsx-runtime'],+});++const [file] = mainModule.outputs;+const text = (await file.text())+ .replace(/jsxDEV/g, 'jsx')+ .replace(/react\/jsx-dev-runtime/g, 'react/jsx-runtime');++await Bun.write('dist/esm/index.mjs', text);++const internalsModule = await build({+ entrypoints: ['src/internals.ts'],+ naming: 'internals.mjs',+ external: ['react', 'remotion', 'remotion/no-react', 'react/jsx-runtime'],+});+const [enableFile] = internalsModule.outputs;+const skiaEnable = await enableFile.text();++await Bun.write('dist/esm/internals.mjs', skiaEnable);++export {};diff --git a/packages/studio/package.json b/packages/studio/package.jsonindex 3935668322..a7df5e4217 100644--- a/packages/studio/package.json+++ b/packages/studio/package.json@@ -53,11 +53,18 @@},"exports": {".": {- "import": "./dist/index.js",- "require": "./dist/index.js",- "types": "./dist/index.d.js"+ "types": "./dist/cjs/index.d.ts",+ "module": "./dist/esm/index.mjs",+ "import": "./dist/esm/index.mjs",+ "require": "./dist/cjs/index.js"},"./package.json": "./package.json",- "./entry": "./dist/previewEntry.js"+ "./entry": "./dist/previewEntry.js",+ "./internals": {+ "types": "./dist/cjs/internals.d.ts",+ "module": "./dist/esm/internals.mjs",+ "import": "./dist/esm/internals.mjs",+ "require": "./dist/cjs/internals.js"+ }}}diff --git a/packages/studio/src/Studio.tsx b/packages/studio/src/Studio.tsxindex 5f25e2d68c..058b743acc 100644--- a/packages/studio/src/Studio.tsx+++ b/packages/studio/src/Studio.tsx@@ -1,23 +1,26 @@import React, {useLayoutEffect} from 'react';import {createPortal} from 'react-dom';import {Internals} from 'remotion';-import '../styles.css';import {Editor} from './components/Editor';import {EditorContexts} from './components/EditorContexts';import {ServerDisconnected} from './components/Notifications/ServerDisconnected';+import {injectCSS} from './helpers/inject-css';const getServerDisconnectedDomElement = () => {return document.getElementById('server-disconnected-overlay');};export const Studio: React.FC<{- rootComponent: React.FC;- readOnly: boolean;+ readonly rootComponent: React.FC;+ readonly readOnly: boolean;}> = ({rootComponent, readOnly}) => {useLayoutEffect(() => {window.remotion_isStudio = true;Internals.enableSequenceStackTraces();}, []);+ useLayoutEffect(() => {+ injectCSS();+ }, []);return (<Internals.RemotionRootnumberOfAudioTags={window.remotion_numberOfAudioTags}diff --git a/packages/studio/src/helpers/inject-css.ts b/packages/studio/src/helpers/inject-css.tsnew file mode 100644index 0000000000..13c33715cd--- /dev/null+++ b/packages/studio/src/helpers/inject-css.ts@@ -0,0 +1,140 @@+import {Internals} from 'remotion';++const makeDefaultGlobalCSS = () => {+ return `+ html {+ --remotion-cli-internals-blue: #0b84f3;+ }++ body {+ overscroll-behavior-y: none;+ overscroll-behavior-x: none;+ /* Override Chakra UI position: relative on body */+ position: static !important;+ }++ .remotion-splitter {+ user-select: none;+ }++ .remotion-splitter-horizontal {+ transform: scaleY(2);+ background: linear-gradient(+ to bottom,+ transparent 25%,+ black 25%,+ black 75%,+ transparent+ );+ }++ .remotion-splitter-horizontal:hover,+ .remotion-splitter-horizontal.remotion-splitter-active {+ background: linear-gradient(+ to bottom,+ var(--remotion-cli-internals-blue),+ var(--remotion-cli-internals-blue)+ );+ }++ .remotion-splitter-vertical {+ transform: scaleX(2);+ background: linear-gradient(+ to right,+ transparent 25%,+ black 25%,+ black 75%,+ transparent+ );+ }++ .remotion-splitter-vertical:hover,+ .remotion-splitter-vertical.remotion-splitter-active {+ background: linear-gradient(+ to right,+ var(--remotion-cli-internals-blue),+ var(--remotion-cli-internals-blue)+ );+ }++ input::-webkit-outer-spin-button,+ input::-webkit-inner-spin-button {+ -webkit-appearance: none;+ margin: 0;+ }++ input:focus,+ textarea:focus,+ button:focus,+ a:focus {+ outline: none;+ box-shadow:+ inset 1px 1px #555,+ inset -1px -1px #555,+ inset 1px -1px #555,+ inset -1px 1px #555;+ border-radius: 0 !important;+ }++ input[type='color'].__remotion_color_picker::-webkit-color-swatch-wrapper {+ padding: 0;+ }+ input[type='color'].__remotion_color_picker::-webkit-color-swatch {+ border: none;+ }++ .__remotion_thumb,+ .__remotion_thumb::-webkit-slider-thumb {+ -webkit-appearance: none;+ -webkit-tap-highlight-color: transparent;+ }++ .__remotion_thumb {+ pointer-events: none;+ position: absolute;+ height: 0;+ outline: none;+ top: 15.5px;+ width: 221px;+ margin-left: -2px;+ z-index: 2;+ }++ /* For Firefox browsers */+ .__remotion_thumb::-moz-range-thumb {+ border: 1px solid black;+ border-radius: 2px;+ cursor: pointer;+ height: 37px;+ width: 10px;+ pointer-events: all;+ border-color: black;+ background-color: white;+ position: relative;+ }++ /* For Chrome browsers */+ .__remotion_thumb::-webkit-slider-thumb {+ border: 1px solid black;+ border-radius: 2px;+ cursor: pointer;+ height: 39px;+ width: 10px;+ pointer-events: all;+ border-color: black;+ background-color: white;+ position: relative;+ }+ `.trim();+};++let injected = false;++export const injectCSS = () => {+ if (injected) {+ return;+ }++ Internals.CSSUtils.injectCSS(makeDefaultGlobalCSS());+ injected = true;+};diff --git a/packages/studio/src/index.ts b/packages/studio/src/index.tsindex 576c9b0dfa..aad33d9e1f 100644--- a/packages/studio/src/index.ts+++ b/packages/studio/src/index.ts@@ -1,10 +1,4 @@-import {Studio} from './Studio';-export type {GitSource, RenderDefaults} from '@remotion/studio-shared';-export const StudioInternals = {- Studio,-};-export {StaticFile, getStaticFiles} from './api/get-static-files';export {watchStaticFile} from './api/watch-static-file';diff --git a/packages/studio/src/internals.ts b/packages/studio/src/internals.tsnew file mode 100644index 0000000000..9b4040aae3--- /dev/null+++ b/packages/studio/src/internals.ts@@ -0,0 +1,4 @@+import {Studio} from './Studio';+export const StudioInternals = {+ Studio,+};diff --git a/packages/studio/src/previewEntry.tsx b/packages/studio/src/previewEntry.tsxindex edd17186e0..294a64796a 100644--- a/packages/studio/src/previewEntry.tsx+++ b/packages/studio/src/previewEntry.tsx@@ -9,7 +9,7 @@ import {startErrorOverlay} from './error-overlay/entry-basic';import {enableHotMiddleware} from './hot-middleware-client/client';Internals.CSSUtils.injectCSS(- Internals.CSSUtils.makeDefaultCSS(null, '#1f2428'),+ Internals.CSSUtils.makeDefaultPreviewCSS(null, '#1f2428'),);let root: ReturnType<typeof ReactDOM.createRoot> | null = null;diff --git a/packages/studio/styles.css b/packages/studio/styles.cssdeleted file mode 100644index c784eb176d..0000000000--- a/packages/studio/styles.css+++ /dev/null@@ -1,123 +0,0 @@-html {- --remotion-cli-internals-blue: #0b84f3;-}--body {- overscroll-behavior-y: none;- overscroll-behavior-x: none;- /* Override Chakra UI position: relative on body */- position: static !important;-}--.remotion-splitter {- user-select: none;-}--.remotion-splitter-horizontal {- transform: scaleY(2);- background: linear-gradient(- to bottom,- transparent 25%,- black 25%,- black 75%,- transparent- );-}--.remotion-splitter-horizontal:hover,-.remotion-splitter-horizontal.remotion-splitter-active {- background: linear-gradient(- to bottom,- var(--remotion-cli-internals-blue),- var(--remotion-cli-internals-blue)- );-}--.remotion-splitter-vertical {- transform: scaleX(2);- background: linear-gradient(- to right,- transparent 25%,- black 25%,- black 75%,- transparent- );-}--.remotion-splitter-vertical:hover,-.remotion-splitter-vertical.remotion-splitter-active {- background: linear-gradient(- to right,- var(--remotion-cli-internals-blue),- var(--remotion-cli-internals-blue)- );-}--input::-webkit-outer-spin-button,-input::-webkit-inner-spin-button {- -webkit-appearance: none;- margin: 0;-}--input:focus,-textarea:focus,-button:focus,-a:focus {- outline: none;- box-shadow:- inset 1px 1px #555,- inset -1px -1px #555,- inset 1px -1px #555,- inset -1px 1px #555;- border-radius: 0 !important;-}--input[type='color'].__remotion_color_picker::-webkit-color-swatch-wrapper {- padding: 0;-}-input[type='color'].__remotion_color_picker::-webkit-color-swatch {- border: none;-}--.__remotion_thumb,-.__remotion_thumb::-webkit-slider-thumb {- -webkit-appearance: none;- -webkit-tap-highlight-color: transparent;-}--.__remotion_thumb {- pointer-events: none;- position: absolute;- height: 0;- outline: none;- top: 15.5px;- width: 221px;- margin-left: -2px;- z-index: 2;-}--/* For Firefox browsers */-.__remotion_thumb::-moz-range-thumb {- border: 1px solid black;- border-radius: 2px;- cursor: pointer;- height: 37px;- width: 10px;- pointer-events: all;- border-color: black;- background-color: white;- position: relative;-}--/* For Chrome browsers */-.__remotion_thumb::-webkit-slider-thumb {- border: 1px solid black;- border-radius: 2px;- cursor: pointer;- height: 39px;- width: 10px;- pointer-events: all;- border-color: black;- background-color: white;- position: relative;-}