@remotion/browser-bundler 4.0.527

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ import type { FC } from 'react';
2
+ import type { BrowserBundle } from './types';
3
+ export type BrowserBundleRuntime = {
4
+ applyBundle: (bundle: BrowserBundle) => Promise<FC>;
5
+ dispose: () => void;
6
+ };
7
+ export declare const createBrowserBundleRuntime: () => BrowserBundleRuntime;
@@ -0,0 +1,2 @@
1
+ import type { BrowserBundler, BrowserBundlerOptions } from './types';
2
+ export declare const createBrowserBundler: (options?: BrowserBundlerOptions) => BrowserBundler;
@@ -0,0 +1,27 @@
1
+ import type * as RspackBrowser from '@rspack/browser';
2
+ import type { BrowserBundlerProgress, VirtualProject } from './types';
3
+ export type BrowserCompilerProject = VirtualProject & {
4
+ rootDir: string;
5
+ };
6
+ export type BrowserCompilerResult = {
7
+ bundle: string | null;
8
+ assets: {
9
+ name: string;
10
+ content: string;
11
+ }[];
12
+ errors: string[];
13
+ warnings: string[];
14
+ hash: string | undefined;
15
+ modules: Record<string, string>;
16
+ time: number | undefined;
17
+ };
18
+ export type BrowserCompiler = {
19
+ compile: (project: BrowserCompilerProject) => Promise<BrowserCompilerResult>;
20
+ dispose: () => Promise<void>;
21
+ };
22
+ export declare const createBrowserCompiler: ({ project, virtualFiles, configure, onProgress, }: {
23
+ project: BrowserCompilerProject;
24
+ virtualFiles: Record<string, string>;
25
+ configure: (rspack: typeof RspackBrowser) => RspackBrowser.RspackOptions;
26
+ onProgress: ((progress: BrowserBundlerProgress) => void) | null;
27
+ }) => Promise<BrowserCompiler>;
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import type { BrowserComposition } from './get-browser-composition';
3
+ export type BrowserCompositionSelection = {
4
+ readonly root: React.FC;
5
+ readonly compositionId: string;
6
+ readonly inputProps: Record<string, unknown>;
7
+ };
8
+ export type BrowserCompositionObserver = {
9
+ update: (selection: BrowserCompositionSelection) => void;
10
+ dispose: () => void;
11
+ };
12
+ export declare const createBrowserCompositionObserver: ({ onChange, onError, }: {
13
+ onChange: (composition: BrowserComposition) => void;
14
+ onError: (error: Error) => void;
15
+ }) => BrowserCompositionObserver;
@@ -0,0 +1,9 @@
1
+ import type * as RspackBrowser from '@rspack/browser';
2
+ export declare const createBrowserDependencyPlugin: ({ rspack, resolvedUrls, resolvedVersions, resolvePackage, external, development, }: {
3
+ rspack: typeof RspackBrowser;
4
+ resolvedUrls: Record<string, string>;
5
+ resolvedVersions: Record<string, string>;
6
+ resolvePackage: ((request: string) => string | null) | null;
7
+ external: string[];
8
+ development: boolean;
9
+ }) => RspackBrowser.BrowserHttpImportEsmPlugin;
@@ -0,0 +1,6 @@
1
+ import type { SerializedCompilerError } from './types';
2
+ export declare class BrowserBundlerError extends Error {
3
+ readonly diagnostics: string[];
4
+ constructor(message: string, diagnostics: string[]);
5
+ }
6
+ export declare const serializeCompilerError: (error: unknown) => SerializedCompilerError;
@@ -0,0 +1,8 @@
1
+ export declare const browserBundleHmrBridgeName = "remotion_browserBundlerHmr";
2
+ export declare const browserBundleHotUpdateName = "remotion_browserBundlerHotUpdate";
3
+ export type BrowserBundleHotRuntime = {
4
+ check: () => Promise<(string | number)[] | null>;
5
+ apply: () => Promise<(string | number)[]>;
6
+ getHash: () => string;
7
+ status: () => string;
8
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import type { AnyComposition, VideoConfig } from 'remotion';
3
+ export type BrowserComposition = VideoConfig & {
4
+ component: AnyComposition['component'];
5
+ };
6
+ /**
7
+ * Mounts a registered Root to select a Composition and resolve its metadata.
8
+ * Input props override default props. Root providers are used for registration
9
+ * only; they are not included around the component returned for the Player.
10
+ * Pass an AbortSignal to cancel pending lazy roots or calculateMetadata().
11
+ */
12
+ export declare const getBrowserComposition: ({ root: RegisteredRoot, compositionId, inputProps, signal, }: {
13
+ root: React.FC<{}>;
14
+ compositionId: string;
15
+ inputProps: Record<string, unknown>;
16
+ signal?: AbortSignal | undefined;
17
+ }) => Promise<BrowserComposition>;
@@ -0,0 +1,16 @@
1
+ export type BrowserHmrAsset = {
2
+ name: string;
3
+ content: string;
4
+ };
5
+ export type BrowserHmrBridge = {
6
+ getManifest: (name: string) => Promise<object | undefined>;
7
+ resolveScriptUrl: (name: string) => string;
8
+ };
9
+ export declare const createBrowserHmrAssetManager: ({ createObjectUrl, revokeObjectUrl, }: {
10
+ createObjectUrl: (blob: Blob) => string;
11
+ revokeObjectUrl: (url: string) => void;
12
+ }) => {
13
+ bridge: BrowserHmrBridge;
14
+ dispose: () => void;
15
+ updateAssets: (newAssets: BrowserHmrAsset[]) => void;
16
+ };
@@ -0,0 +1,10 @@
1
+ import type * as RspackBrowser from '@rspack/browser';
2
+ export declare const createBrowserReactRefreshPlugin: ({ rspack, refreshRuntime, refreshUtils, }: {
3
+ rspack: typeof RspackBrowser;
4
+ refreshRuntime: string;
5
+ refreshUtils: string;
6
+ }) => RspackBrowser.RspackPluginInstance;
7
+ export declare const createBrowserHmrRuntimePlugin: ({ rspack, bridgeName, }: {
8
+ rspack: typeof RspackBrowser;
9
+ bridgeName: string;
10
+ }) => RspackBrowser.RspackPluginInstance;
@@ -0,0 +1,9 @@
1
+ type BrowserHttpResponse = {
2
+ body: Buffer;
3
+ headers: Record<string, string>;
4
+ status: number;
5
+ };
6
+ export declare const makeBrowserHttpClient: ({ fetchImplementation, }: {
7
+ fetchImplementation: (input: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
8
+ }) => (url: string, headers: Record<string, string>) => Promise<BrowserHttpResponse>;
9
+ export {};
@@ -0,0 +1,3 @@
1
+ export { createBrowserBundler } from './create-browser-bundler';
2
+ export { BrowserBundlerError } from './errors';
3
+ export type { BrowserBundle, BrowserBundler, BrowserBundlerOptions, BrowserBundlerProgress, VirtualFileSystem, VirtualProject, } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,115 @@
1
+ var __create = Object.create;
2
+ var __getProtoOf = Object.getPrototypeOf;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __toESM = (mod, isNodeMode, target) => {
7
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
8
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
9
+ for (let key of __getOwnPropNames(mod))
10
+ if (!__hasOwnProp.call(to, key))
11
+ __defProp(to, key, {
12
+ get: () => mod[key],
13
+ enumerable: true
14
+ });
15
+ return to;
16
+ };
17
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
18
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
19
+ }) : x)(function(x) {
20
+ if (typeof require !== "undefined")
21
+ return require.apply(this, arguments);
22
+ throw Error('Dynamic require of "' + x + '" is not supported');
23
+ });
24
+
25
+ // src/errors.ts
26
+ class BrowserBundlerError extends Error {
27
+ diagnostics;
28
+ constructor(message, diagnostics) {
29
+ super(message);
30
+ this.name = "BrowserBundlerError";
31
+ this.diagnostics = diagnostics;
32
+ }
33
+ }
34
+
35
+ // src/create-browser-bundler.ts
36
+ var createBrowserBundler = (options = {}) => {
37
+ if (typeof Worker === "undefined") {
38
+ throw new Error("createBrowserBundler() must be called in a browser.");
39
+ }
40
+ if (!globalThis.crossOriginIsolated) {
41
+ throw new Error("The browser bundler requires cross-origin isolation. Serve the page with Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp.");
42
+ }
43
+ const worker = options.workerUrl ? new Worker(options.workerUrl, { type: "module" }) : new Worker(new URL("./browser-bundler-worker.js", import.meta.url), {
44
+ type: "module"
45
+ });
46
+ const dependencyVersions = { ...options.dependencyVersions };
47
+ const enableFastRefresh = options.enableFastRefresh ?? false;
48
+ const pending = new Map;
49
+ let nextId = 0;
50
+ let terminalError = null;
51
+ const stop = (error) => {
52
+ terminalError = error;
53
+ worker.terminate();
54
+ for (const request of pending.values()) {
55
+ request.reject(error);
56
+ }
57
+ pending.clear();
58
+ };
59
+ worker.onmessage = (event) => {
60
+ const response = event.data;
61
+ if (response.type === "progress") {
62
+ options.onProgress?.(response);
63
+ return;
64
+ }
65
+ const request = pending.get(response.id);
66
+ if (!request) {
67
+ return;
68
+ }
69
+ pending.delete(response.id);
70
+ if (response.type === "error") {
71
+ const error = new BrowserBundlerError(response.error.message, response.error.diagnostics);
72
+ if (response.error.stack) {
73
+ error.stack = response.error.stack;
74
+ }
75
+ request.reject(error);
76
+ return;
77
+ }
78
+ request.resolve(response.bundle);
79
+ };
80
+ worker.onerror = (event) => {
81
+ stop(new Error(event.message || "The browser compiler worker failed."));
82
+ };
83
+ worker.onmessageerror = () => {
84
+ stop(new Error("Could not read the browser compiler worker response."));
85
+ };
86
+ return {
87
+ bundle: ({ project }) => {
88
+ if (terminalError) {
89
+ return Promise.reject(terminalError);
90
+ }
91
+ const id = nextId++;
92
+ return new Promise((resolve, reject) => {
93
+ pending.set(id, { resolve, reject });
94
+ try {
95
+ worker.postMessage({
96
+ id,
97
+ project,
98
+ dependencyVersions,
99
+ enableFastRefresh
100
+ });
101
+ } catch (error) {
102
+ pending.delete(id);
103
+ reject(error);
104
+ }
105
+ });
106
+ },
107
+ dispose: () => {
108
+ stop(new Error("The browser bundler has been disposed."));
109
+ }
110
+ };
111
+ };
112
+ export {
113
+ createBrowserBundler,
114
+ BrowserBundlerError
115
+ };
@@ -0,0 +1,19 @@
1
+ /*!
2
+ * The buffer module from node.js, for the browser.
3
+ *
4
+ * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
5
+ * @license MIT
6
+ */
7
+
8
+ /*!
9
+ * The buffer module from node.js, for the browser.
10
+ *
11
+ * @author Feross Aboukhadijeh <https://feross.org>
12
+ * @license MIT
13
+ */
14
+
15
+ /*! https://mths.be/punycode v1.4.1 by @mathias */
16
+
17
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
18
+
19
+ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
@@ -0,0 +1,10 @@
1
+ import type { FC } from 'react';
2
+ import type { BrowserBundle } from './types.js';
3
+ /**
4
+ * Executes a browser bundle and returns its registerRoot() component.
5
+ * Only execute code you trust: this uses Function(), not a sandbox, and the
6
+ * bundle has access to the page. React and Remotion are shared with the host.
7
+ */
8
+ export declare const loadBrowserBundle: ({ bundle }: {
9
+ bundle: BrowserBundle;
10
+ }) => FC;
@@ -0,0 +1,3 @@
1
+ import type * as RspackBrowser from '@rspack/browser';
2
+ import type { BrowserBundlerProgress } from './types';
3
+ export declare const loadRspackBrowser: (onProgress: ((progress: BrowserBundlerProgress) => void) | null) => Promise<typeof RspackBrowser>;
@@ -0,0 +1,5 @@
1
+ export declare const getBrowserReactRefreshVirtualFiles: ({ entry, runtime, utils, }: {
2
+ entry: string;
3
+ runtime: string;
4
+ utils: string;
5
+ }) => Record<string, string>;
Binary file
@@ -0,0 +1,5 @@
1
+ export { createBrowserBundleRuntime, type BrowserBundleRuntime, } from './create-browser-bundle-runtime';
2
+ export { createBrowserCompositionObserver, type BrowserCompositionObserver, type BrowserCompositionSelection, } from './create-browser-composition-observer';
3
+ export { getBrowserComposition } from './get-browser-composition.js';
4
+ export type { BrowserComposition } from './get-browser-composition.js';
5
+ export { loadBrowserBundle } from './load-browser-bundle.js';