🎥 Make videos programmatically with React
@remotion/studio-protocol: Add remotion.dev/new URL builder
Jonny Burger0281d7350763
diff --git a/packages/docs/docs/studio-protocol/build-open-in-remotion-dot-new-url.mdx b/packages/docs/docs/studio-protocol/build-open-in-remotion-dot-new-url.mdxnew file mode 100644index 0000000000..3154dbc99d--- /dev/null+++ b/packages/docs/docs/studio-protocol/build-open-in-remotion-dot-new-url.mdx@@ -0,0 +1,72 @@+---+image: /generated/articles-docs-studio-protocol-build-open-in-remotion-dot-new-url.png+title: 'buildOpenInRemotionDotNewUrl()'+crumb: '@remotion/studio-protocol'+---++# buildOpenInRemotionDotNewUrl()<AvailableFrom v="4.0.526" />++Builds a URL that opens an Element in the browser-based editor at [remotion.dev/new](https://www.remotion.dev/new).++## Example++```tsx twoslash title="OpenInRemotion.tsx"+import {+ buildOpenInRemotionDotNewUrl,+ createElementPayload,+} from '@remotion/studio-protocol';++const payload = createElementPayload({+ displayName: 'My Element',+ slug: 'my-element',+ sourceCode: `+export const MyElement = () => {+ return <div>Hello world</div>;+};+`,+ dependencies: [],+ dimensions: {width: 900, height: 260},+ durationInFrames: 90,+});++export const OpenInRemotion = () => {+ return (+ <a+ href={buildOpenInRemotionDotNewUrl({payload})}+ target="_blank"+ rel="noopener noreferrer"+ >+ Open in Remotion+ </a>+ );+};+```++## Arguments++Pass an object with the following property.++### payload++The value returned by [`createElementPayload()`](/docs/studio-protocol/create-element-payload).++## Return value++A URL string pointing to remotion.dev/new. The Element payload is encoded in the URL fragment.++The function throws a `TypeError` if the payload is invalid or too large.++## Security++The URL contains the Element source code. Do not log or share generated URLs.++URL fragments are not sent to remotion.dev as part of the HTTP request.++## Compatibility++<CompatibilityTable chrome firefox safari nodejs bun serverlessFunctions clientSideRendering serverSideRendering player studio />++## See also++- [`createElementPayload()`](/docs/studio-protocol/create-element-payload)+- [`installInStudio()`](/docs/studio-protocol/install-in-studio)diff --git a/packages/docs/docs/studio-protocol/create-element-payload.mdx b/packages/docs/docs/studio-protocol/create-element-payload.mdxindex 3aa721a39f..939e7f4b51 100644--- a/packages/docs/docs/studio-protocol/create-element-payload.mdx+++ b/packages/docs/docs/studio-protocol/create-element-payload.mdx@@ -6,7 +6,7 @@ crumb: '@remotion/studio-protocol'# createElementPayload()<AvailableFrom v="4.0.502" />-Creates a validated, versioned Element payload for [`setStudioDragData()`](/docs/studio-protocol/set-studio-drag-data) and [`installInStudio()`](/docs/studio-protocol/install-in-studio).+Creates a validated, versioned Element payload for [`buildOpenInRemotionDotNewUrl()`](/docs/studio-protocol/build-open-in-remotion-dot-new-url), [`setStudioDragData()`](/docs/studio-protocol/set-studio-drag-data), and [`installInStudio()`](/docs/studio-protocol/install-in-studio).## Example@@ -100,5 +100,6 @@ Invalid input throws a `TypeError`.## See also+- [`buildOpenInRemotionDotNewUrl()`](/docs/studio-protocol/build-open-in-remotion-dot-new-url)- [`setStudioDragData()`](/docs/studio-protocol/set-studio-drag-data)- [`installInStudio()`](/docs/studio-protocol/install-in-studio)diff --git a/packages/docs/docs/studio-protocol/index.mdx b/packages/docs/docs/studio-protocol/index.mdxindex c36722595c..c82273c0e8 100644--- a/packages/docs/docs/studio-protocol/index.mdx+++ b/packages/docs/docs/studio-protocol/index.mdx@@ -16,19 +16,20 @@ A versioned protocol for providing content to Remotion Studio.A Remotion Element is a reusable React component distributed as source code, together with the metadata and dependencies needed to add it to a composition. Because its source code becomes part of the project, it can be edited and remixed by the user.-Websites can provide Remotion Elements by drag-and-drop or request their installation into the active composition.+Websites can provide Remotion Elements by drag-and-drop, request their installation into the active composition, or open them in the browser-based editor at remotion.dev/new.<Step>1</Step> Create an Element payload with [`createElementPayload()`](/docs/studio-protocol/create-element-payload).<br />-<Step>2</Step> Provide the payload to Studio: put it on a drag event with [`setStudioDragData()`](/docs/studio-protocol/set-studio-drag-data), or request installation into the active composition with [`installInStudio()`](/docs/studio-protocol/install-in-studio).+<Step>2</Step> Provide the payload to Studio: build a link to remotion.dev/new with [`buildOpenInRemotionDotNewUrl()`](/docs/studio-protocol/build-open-in-remotion-dot-new-url), put it on a drag event with [`setStudioDragData()`](/docs/studio-protocol/set-studio-drag-data), or request installation into the active composition with [`installInStudio()`](/docs/studio-protocol/install-in-studio).-If you publish reusable components, see [Integrating a component library with Studio](/docs/studio-protocol/component-library-integration) for recommendations on Player previews, representing components as Elements, and both delivery methods.+If you publish reusable components, see [Integrating a component library with Studio](/docs/studio-protocol/component-library-integration) for recommendations on Player previews, representing components as Elements, and local Studio delivery methods.-Offer both delivery methods when possible. They use the same Element payload but suit different workflows.+The methods use the same Element payload but suit different workflows.-| Method | Benefits | Tradeoffs |-| --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |-| [Drag-and-drop](/docs/studio-protocol/set-studio-drag-data) | The user chooses the exact Studio tab, timeline position, and canvas position. | Drag data has no reliable website provenance, so Studio labels the source as [unverified](/docs/studio-protocol/security#confirmation-boundary). |-| [Installation request](/docs/studio-protocol/install-in-studio) | The requesting website is shown in Studio. On macOS, Studio attempts to bring the target tab to the foreground. | Local Studio ports are probed and the most recently focused compatible Studio is selected automatically. |+| Method | Benefits | Tradeoffs |+| --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |+| [remotion.dev/new link](/docs/studio-protocol/build-open-in-remotion-dot-new-url) | Works without a local Studio and can be used in a regular anchor element. | Opens a separate browser-based editor. The generated URL contains the Element source code. |+| [Drag-and-drop](/docs/studio-protocol/set-studio-drag-data) | The user chooses the exact Studio tab, timeline position, and canvas position. | Drag data has no reliable website provenance, so Studio labels the source as [unverified](/docs/studio-protocol/security#confirmation-boundary). |+| [Installation request](/docs/studio-protocol/install-in-studio) | The requesting website is shown in Studio. On macOS, Studio attempts to bring the target tab to the foreground. | Local Studio ports are probed and the most recently focused compatible Studio is selected automatically. |### Adding Element catalogsdiff --git a/packages/docs/docs/studio-protocol/table-of-contents.tsx b/packages/docs/docs/studio-protocol/table-of-contents.tsxindex 954e2c8eb9..84821f18be 100644--- a/packages/docs/docs/studio-protocol/table-of-contents.tsx+++ b/packages/docs/docs/studio-protocol/table-of-contents.tsx@@ -9,6 +9,10 @@ export const TableOfContents: React.FC = () => {<strong>createElementPayload()</strong><div>Create a versioned Element payload</div></TOCItem>+ <TOCItem link="/docs/studio-protocol/build-open-in-remotion-dot-new-url">+ <strong>buildOpenInRemotionDotNewUrl()</strong>+ <div>Build a URL that opens an Element on remotion.dev/new</div>+ </TOCItem><TOCItem link="/docs/studio-protocol/set-studio-drag-data"><strong>setStudioDragData()</strong><div>Put an Element payload on a drag event</div>diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex 1af7797646..463708a12b 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -828,6 +828,7 @@ const sidebars: SidebarsConfig = {items: ['studio-protocol/component-library-integration','studio-protocol/create-element-payload',+ 'studio-protocol/build-open-in-remotion-dot-new-url','studio-protocol/set-studio-drag-data','studio-protocol/install-in-studio','studio-protocol/add-element-library-to-studio',diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 65f089c886..92c898988e 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -7093,6 +7093,15 @@ export const articles = [noAi: false,slug: 'studio-protocol/add-element-library-to-studio',},+ {+ id: 'studio-protocol/build-open-in-remotion-dot-new-url',+ title: 'buildOpenInRemotionDotNewUrl()',+ relativePath: 'docs/studio-protocol/build-open-in-remotion-dot-new-url.mdx',+ compId: 'articles-docs-studio-protocol-build-open-in-remotion-dot-new-url',+ crumb: '@remotion/studio-protocol',+ noAi: false,+ slug: 'studio-protocol/build-open-in-remotion-dot-new-url',+ },{id: 'studio-protocol/component-library-integration',title: 'Integrating a component library with Studio',diff --git a/packages/docs/static/generated/articles-docs-studio-protocol-build-open-in-remotion-dot-new-url.png b/packages/docs/static/generated/articles-docs-studio-protocol-build-open-in-remotion-dot-new-url.pngnew file mode 100644index 0000000000..f54b71c2b8Binary files /dev/null and b/packages/docs/static/generated/articles-docs-studio-protocol-build-open-in-remotion-dot-new-url.png differdiff --git a/packages/studio-protocol/src/browser-studio-link.ts b/packages/studio-protocol/src/browser-studio-link.tsindex 459cfcec19..e995134725 100644--- a/packages/studio-protocol/src/browser-studio-link.ts+++ b/packages/studio-protocol/src/browser-studio-link.ts@@ -81,6 +81,14 @@ export const makeBrowserStudioUrl = ({return url.toString();};+export const buildOpenInRemotionDotNewUrl = ({+ payload,+}: {+ readonly payload: StudioElementPayload;+}) => {+ return makeBrowserStudioUrl({endpoint: null, payload});+};+export const parseBrowserStudioHash = (hash: string,): StudioElementPayload | null => {diff --git a/packages/studio-protocol/src/index.ts b/packages/studio-protocol/src/index.tsindex 1364ea73f0..dbd255e42c 100644--- a/packages/studio-protocol/src/index.ts+++ b/packages/studio-protocol/src/index.ts@@ -39,6 +39,7 @@ export {type AddElementLibraryToStudioResult,} from './add-element-library-to-studio';export type {AssetDragData} from './asset-drag-data';+export {buildOpenInRemotionDotNewUrl} from './browser-studio-link';export type {ComponentDimensions,ComponentDragData,diff --git a/packages/studio-protocol/src/test/browser-studio-link.test.ts b/packages/studio-protocol/src/test/browser-studio-link.test.tsindex 6d8ff84d3c..3f097dcafd 100644--- a/packages/studio-protocol/src/test/browser-studio-link.test.ts+++ b/packages/studio-protocol/src/test/browser-studio-link.test.ts@@ -1,5 +1,5 @@import {expect, test} from 'bun:test';-import {StudioProtocolInternals} from '..';+import {buildOpenInRemotionDotNewUrl, StudioProtocolInternals} from '..';import {createElementPayload} from '../element-payload';const payload = createElementPayload({@@ -13,10 +13,7 @@ const payload = createElementPayload({});test('round-trips a payload through the default Browser Studio URL', () => {- const url = StudioProtocolInternals.makeBrowserStudioUrl({- endpoint: null,- payload,- });+ const url = buildOpenInRemotionDotNewUrl({payload});const parsedUrl = new URL(url);expect(parsedUrl.origin).toBe('https://www.remotion.dev');