@revideo/vite-plugin 0.4.7-alpha.1027 → 0.4.7-five.1022

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.
@@ -1,26 +1,28 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : {default: mod};
6
+ };
7
+ Object.defineProperty(exports, '__esModule', {value: true});
6
8
  exports.scenesPlugin = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const utils_1 = require("../utils");
9
+ const path_1 = __importDefault(require('path'));
10
+ const utils_1 = require('../utils');
9
11
  const SCENE_QUERY_REGEX = /[?&]scene\b/;
10
12
  function scenesPlugin() {
11
- return {
12
- name: 'revideo:scene',
13
- async load(id) {
14
- if (!SCENE_QUERY_REGEX.test(id)) {
15
- return;
16
- }
17
- const [base] = id.split('?');
18
- const { name, dir } = path_1.default.posix.parse(base);
19
- const metaFile = `${name}.meta`;
20
- await (0, utils_1.createMeta)(path_1.default.join(dir, metaFile));
21
- const sceneFile = `${name}`;
22
- /* language=typescript */
23
- return `\
13
+ return {
14
+ name: 'revideo:scene',
15
+ async load(id) {
16
+ if (!SCENE_QUERY_REGEX.test(id)) {
17
+ return;
18
+ }
19
+ const [base] = id.split('?');
20
+ const {name, dir} = path_1.default.posix.parse(base);
21
+ const metaFile = `${name}.meta`;
22
+ await (0, utils_1.createMeta)(path_1.default.join(dir, metaFile));
23
+ const sceneFile = `${name}`;
24
+ /* language=typescript */
25
+ return `\
24
26
  import {ValueDispatcher} from '@revideo/core';
25
27
  import metaFile from './${metaFile}';
26
28
  import description from './${sceneFile}';
@@ -40,8 +42,8 @@ if (import.meta.hot) {
40
42
  }
41
43
  export default description;
42
44
  `;
43
- },
44
- };
45
+ },
46
+ };
45
47
  }
46
48
  exports.scenesPlugin = scenesPlugin;
47
- //# sourceMappingURL=scenes.js.map
49
+ //# sourceMappingURL=scenes.js.map
@@ -1,2 +1,2 @@
1
- import { Plugin } from 'vite';
1
+ import {Plugin} from 'vite';
2
2
  export declare function settingsPlugin(): Plugin;
@@ -1,66 +1,71 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : {default: mod};
6
+ };
7
+ Object.defineProperty(exports, '__esModule', {value: true});
6
8
  exports.settingsPlugin = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const os_1 = __importDefault(require("os"));
9
- const path_1 = __importDefault(require("path"));
9
+ const fs_1 = __importDefault(require('fs'));
10
+ const os_1 = __importDefault(require('os'));
11
+ const path_1 = __importDefault(require('path'));
10
12
  function settingsPlugin() {
11
- const settingsId = 'virtual:settings.meta';
12
- const resolvedSettingsId = '\0' + settingsId;
13
- const settingsPath = path_1.default.resolve(os_1.default.homedir(), '.revideo/settings.json');
14
- const outputDirectory = path_1.default.dirname(settingsPath);
15
- return {
16
- name: 'revideo:settings',
17
- resolveId(id) {
18
- if (id === settingsId) {
19
- return resolvedSettingsId;
20
- }
21
- },
22
- async load(id) {
23
- if (id === resolvedSettingsId) {
24
- let parsed = {};
25
- try {
26
- parsed = JSON.parse(await fs_1.default.promises.readFile(settingsPath, 'utf8'));
27
- }
28
- catch (_) {
29
- // Ignore an invalid settings file
30
- }
31
- return JSON.stringify(parsed);
32
- }
33
- },
34
- configureServer(server) {
35
- server.ws.on('revideo:meta', async ({ source, data }, client) => {
36
- if (source !== resolvedSettingsId) {
37
- return;
38
- }
39
- await fs_1.default.promises.mkdir(outputDirectory, { recursive: true });
40
- const newData = JSON.stringify(data, undefined, 2);
41
- let oldData = '';
42
- try {
43
- oldData = await fs_1.default.promises.readFile(settingsPath, 'utf8');
44
- }
45
- catch (_) {
46
- // Ignore an invalid settings file
47
- }
48
- if (oldData !== newData) {
49
- await Promise.all([
50
- fs_1.default.promises.writeFile(settingsPath, newData, 'utf8'),
51
- // Invalidate the module so that the settings are up-to-date next
52
- // time the browser is refreshed.
53
- server.moduleGraph.getModuleByUrl(source).then(module => {
54
- if (module) {
55
- server.moduleGraph.invalidateModule(module);
56
- }
57
- }),
58
- ]);
59
- }
60
- client.send('revideo:meta-ack', { source });
61
- });
62
- },
63
- };
13
+ const settingsId = 'virtual:settings.meta';
14
+ const resolvedSettingsId = '\0' + settingsId;
15
+ const settingsPath = path_1.default.resolve(
16
+ os_1.default.homedir(),
17
+ '.revideo/settings.json',
18
+ );
19
+ const outputDirectory = path_1.default.dirname(settingsPath);
20
+ return {
21
+ name: 'revideo:settings',
22
+ resolveId(id) {
23
+ if (id === settingsId) {
24
+ return resolvedSettingsId;
25
+ }
26
+ },
27
+ async load(id) {
28
+ if (id === resolvedSettingsId) {
29
+ let parsed = {};
30
+ try {
31
+ parsed = JSON.parse(
32
+ await fs_1.default.promises.readFile(settingsPath, 'utf8'),
33
+ );
34
+ } catch (_) {
35
+ // Ignore an invalid settings file
36
+ }
37
+ return JSON.stringify(parsed);
38
+ }
39
+ },
40
+ configureServer(server) {
41
+ server.ws.on('revideo:meta', async ({source, data}, client) => {
42
+ if (source !== resolvedSettingsId) {
43
+ return;
44
+ }
45
+ await fs_1.default.promises.mkdir(outputDirectory, {recursive: true});
46
+ const newData = JSON.stringify(data, undefined, 2);
47
+ let oldData = '';
48
+ try {
49
+ oldData = await fs_1.default.promises.readFile(settingsPath, 'utf8');
50
+ } catch (_) {
51
+ // Ignore an invalid settings file
52
+ }
53
+ if (oldData !== newData) {
54
+ await Promise.all([
55
+ fs_1.default.promises.writeFile(settingsPath, newData, 'utf8'),
56
+ // Invalidate the module so that the settings are up-to-date next
57
+ // time the browser is refreshed.
58
+ server.moduleGraph.getModuleByUrl(source).then(module => {
59
+ if (module) {
60
+ server.moduleGraph.invalidateModule(module);
61
+ }
62
+ }),
63
+ ]);
64
+ }
65
+ client.send('revideo:meta-ack', {source});
66
+ });
67
+ },
68
+ };
64
69
  }
65
70
  exports.settingsPlugin = settingsPlugin;
66
- //# sourceMappingURL=settings.js.map
71
+ //# sourceMappingURL=settings.js.map
@@ -1,10 +1,10 @@
1
- import { Plugin } from 'vite';
1
+ import {Plugin} from 'vite';
2
2
  declare module 'source-map' {
3
- interface SourceNode {
4
- add(value: string | SourceNode): void;
5
- }
6
- interface SourceMapGenerator {
7
- toJSON(): any;
8
- }
3
+ interface SourceNode {
4
+ add(value: string | SourceNode): void;
5
+ }
6
+ interface SourceMapGenerator {
7
+ toJSON(): any;
8
+ }
9
9
  }
10
10
  export declare function webglPlugin(): Plugin;
@@ -1,89 +1,97 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : {default: mod};
6
+ };
7
+ Object.defineProperty(exports, '__esModule', {value: true});
6
8
  exports.webglPlugin = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const source_map_1 = require("source-map");
10
- const vite_1 = require("vite");
9
+ const fs_1 = __importDefault(require('fs'));
10
+ const path_1 = __importDefault(require('path'));
11
+ const source_map_1 = require('source-map');
12
+ const vite_1 = require('vite');
11
13
  const GLSL_EXTENSION_REGEX = /\.glsl(?:$|\?)/;
12
14
  const INCLUDE_REGEX = /^#include "([^"]+)"/;
13
15
  function webglPlugin() {
14
- let config;
15
- return {
16
- name: 'revideo:webgl',
17
- configResolved(resolvedConfig) {
18
- config = resolvedConfig;
16
+ let config;
17
+ return {
18
+ name: 'revideo:webgl',
19
+ configResolved(resolvedConfig) {
20
+ config = resolvedConfig;
21
+ },
22
+ async transform(code, id) {
23
+ if (!GLSL_EXTENSION_REGEX.test(id)) {
24
+ return;
25
+ }
26
+ const [base, query] = id.split('?');
27
+ const {dir} = path_1.default.posix.parse(base);
28
+ const params = new URLSearchParams(query);
29
+ if (params.has('raw')) {
30
+ return;
31
+ }
32
+ const context = {
33
+ rootDir: dir,
34
+ fileStack: [],
35
+ includeMap: new Map(),
36
+ watchFile: file => this.addWatchFile(file),
37
+ resolve: async (source, importer) => {
38
+ const resolved = await this.resolve(source, importer);
39
+ return resolved?.id;
19
40
  },
20
- async transform(code, id) {
21
- if (!GLSL_EXTENSION_REGEX.test(id)) {
22
- return;
23
- }
24
- const [base, query] = id.split('?');
25
- const { dir } = path_1.default.posix.parse(base);
26
- const params = new URLSearchParams(query);
27
- if (params.has('raw')) {
28
- return;
29
- }
30
- const context = {
31
- rootDir: dir,
32
- fileStack: [],
33
- includeMap: new Map(),
34
- watchFile: file => this.addWatchFile(file),
35
- resolve: async (source, importer) => {
36
- const resolved = await this.resolve(source, importer);
37
- return resolved?.id;
38
- },
39
- };
40
- const glslSource = await resolveGlsl(context, id, code);
41
- const sourceUrl = (0, vite_1.normalizePath)(path_1.default.relative(config.root, base));
42
- const result = glslSource.toStringWithSourceMap();
43
- const map = result.map.toJSON();
44
- map.includeMap = Object.fromEntries(context.includeMap);
45
- return {
46
- map,
47
- code: `export default \`${result.code}\n//# sourceURL=${sourceUrl}\`;`,
48
- };
49
- },
50
- };
41
+ };
42
+ const glslSource = await resolveGlsl(context, id, code);
43
+ const sourceUrl = (0, vite_1.normalizePath)(
44
+ path_1.default.relative(config.root, base),
45
+ );
46
+ const result = glslSource.toStringWithSourceMap();
47
+ const map = result.map.toJSON();
48
+ map.includeMap = Object.fromEntries(context.includeMap);
49
+ return {
50
+ map,
51
+ code: `export default \`${result.code}\n//# sourceURL=${sourceUrl}\`;`,
52
+ };
53
+ },
54
+ };
51
55
  }
52
56
  exports.webglPlugin = webglPlugin;
53
57
  async function resolveGlsl(context, id, code) {
54
- const lines = code.split(/\r?\n/);
55
- const source = new source_map_1.SourceNode(1, 0, '', '');
56
- if (context.fileStack.includes(id)) {
57
- throw new Error(`Circular dependency detected: ${context.fileStack.join(' -> ')}`);
58
- }
59
- context.fileStack.push(id);
60
- const sourceMapId = path_1.default.posix.relative(context.rootDir, id);
61
- for (let i = 0; i < lines.length; i++) {
62
- const line = lines[i];
63
- const match = line.match(INCLUDE_REGEX);
64
- if (match) {
65
- const childId = await context.resolve(match[1], id);
66
- if (!childId) {
67
- continue;
68
- }
69
- const childSourceMapId = path_1.default.posix.relative(context.rootDir, childId);
70
- if (context.includeMap.has(childSourceMapId)) {
71
- continue;
72
- }
73
- context.includeMap.set(childSourceMapId, [sourceMapId, i + 1]);
74
- context.watchFile(childId);
75
- const childCode = await fs_1.default.promises.readFile(childId, 'utf-8');
76
- source.add(await resolveGlsl(context, childId, childCode));
77
- }
78
- else {
79
- let j = 0;
80
- for (; j < line.length; j++) {
81
- source.add(new source_map_1.SourceNode(i + 1, j, sourceMapId, line[j]));
82
- }
83
- source.add(new source_map_1.SourceNode(i + 1, j, sourceMapId, '\n'));
84
- }
58
+ const lines = code.split(/\r?\n/);
59
+ const source = new source_map_1.SourceNode(1, 0, '', '');
60
+ if (context.fileStack.includes(id)) {
61
+ throw new Error(
62
+ `Circular dependency detected: ${context.fileStack.join(' -> ')}`,
63
+ );
64
+ }
65
+ context.fileStack.push(id);
66
+ const sourceMapId = path_1.default.posix.relative(context.rootDir, id);
67
+ for (let i = 0; i < lines.length; i++) {
68
+ const line = lines[i];
69
+ const match = line.match(INCLUDE_REGEX);
70
+ if (match) {
71
+ const childId = await context.resolve(match[1], id);
72
+ if (!childId) {
73
+ continue;
74
+ }
75
+ const childSourceMapId = path_1.default.posix.relative(
76
+ context.rootDir,
77
+ childId,
78
+ );
79
+ if (context.includeMap.has(childSourceMapId)) {
80
+ continue;
81
+ }
82
+ context.includeMap.set(childSourceMapId, [sourceMapId, i + 1]);
83
+ context.watchFile(childId);
84
+ const childCode = await fs_1.default.promises.readFile(childId, 'utf-8');
85
+ source.add(await resolveGlsl(context, childId, childCode));
86
+ } else {
87
+ let j = 0;
88
+ for (; j < line.length; j++) {
89
+ source.add(new source_map_1.SourceNode(i + 1, j, sourceMapId, line[j]));
90
+ }
91
+ source.add(new source_map_1.SourceNode(i + 1, j, sourceMapId, '\n'));
85
92
  }
86
- context.fileStack.pop();
87
- return source;
93
+ }
94
+ context.fileStack.pop();
95
+ return source;
88
96
  }
89
- //# sourceMappingURL=webgl.js.map
97
+ //# sourceMappingURL=webgl.js.map
package/lib/plugins.d.ts CHANGED
@@ -1,87 +1,87 @@
1
- import { Plugin as VitePlugin } from 'vite';
1
+ import {Plugin as VitePlugin} from 'vite';
2
2
  /**
3
3
  * Represents a Motion Canvas project configured in the Vite plugin.
4
4
  */
5
5
  export interface ProjectData {
6
- /**
7
- * The name of the project.
8
- */
9
- name: string;
10
- /**
11
- * The file name containing the project.
12
- */
13
- fileName: string;
14
- /**
15
- * The path to the project relative to the Vite configuration file.
16
- */
17
- url: string;
6
+ /**
7
+ * The name of the project.
8
+ */
9
+ name: string;
10
+ /**
11
+ * The file name containing the project.
12
+ */
13
+ fileName: string;
14
+ /**
15
+ * The path to the project relative to the Vite configuration file.
16
+ */
17
+ url: string;
18
18
  }
19
19
  /**
20
20
  * The Motion Canvas configuration passed to each plugin.
21
21
  */
22
22
  export interface PluginConfig {
23
- /**
24
- * The projects configured in the Vite plugin.
25
- */
26
- projects: ProjectData[];
27
- /**
28
- * The output path relative to the Vite configuration file.
29
- */
30
- output: string;
23
+ /**
24
+ * The projects configured in the Vite plugin.
25
+ */
26
+ projects: ProjectData[];
27
+ /**
28
+ * The output path relative to the Vite configuration file.
29
+ */
30
+ output: string;
31
31
  }
32
32
  export declare const PLUGIN_OPTIONS: unique symbol;
33
33
  export interface PluginOptions {
34
- /**
35
- * An entry point of the runtime plugin.
36
- *
37
- * @remarks
38
- * While the Vite plugin can extend the backend functionality, this entry
39
- * point lets you include custom runtime code that will be loaded by the
40
- * browser.
41
- *
42
- * It should be a valid module specifier from which the plugin will be
43
- * imported. The module should contain a default export of a runtime plugin.
44
- */
45
- entryPoint: string;
46
- /**
47
- * The configuration hook of the plugin.
48
- *
49
- * @remarks
50
- * Invoked during `configResolved` hook of Vite, contains the Motion Canvas
51
- * specific configuration.
52
- *
53
- * @param config - The configuration passed to the plugin.
54
- */
55
- config?(config: PluginConfig): Promise<void>;
56
- /**
57
- * Get custom configuration that will be passed to the runtime plugin.
58
- *
59
- * @remarks
60
- * The config will be passed as the first argument to the default export of
61
- * the runtime plugin. When provided as a string, it will be injected to the
62
- * code as is, letting you define non-serializable values such as functions.
63
- *
64
- * If the returned value is an object, it will be converted to a JavaScript
65
- * object using JSON serialization.
66
- *
67
- * @example
68
- * Returning an object:
69
- * ```ts
70
- * {
71
- * runtimeConfig: () => ({
72
- * myText: 'Hello!',
73
- * myNumber: 42,
74
- * })
75
- * }
76
- * ```
77
- * Returning a string:
78
- * ```ts
79
- * {
80
- * runtimeConfig: () => `{myRegex: /\\.wav$/}`
81
- * }
82
- * ```
83
- */
84
- runtimeConfig?(): Promise<any>;
34
+ /**
35
+ * An entry point of the runtime plugin.
36
+ *
37
+ * @remarks
38
+ * While the Vite plugin can extend the backend functionality, this entry
39
+ * point lets you include custom runtime code that will be loaded by the
40
+ * browser.
41
+ *
42
+ * It should be a valid module specifier from which the plugin will be
43
+ * imported. The module should contain a default export of a runtime plugin.
44
+ */
45
+ entryPoint: string;
46
+ /**
47
+ * The configuration hook of the plugin.
48
+ *
49
+ * @remarks
50
+ * Invoked during `configResolved` hook of Vite, contains the Motion Canvas
51
+ * specific configuration.
52
+ *
53
+ * @param config - The configuration passed to the plugin.
54
+ */
55
+ config?(config: PluginConfig): Promise<void>;
56
+ /**
57
+ * Get custom configuration that will be passed to the runtime plugin.
58
+ *
59
+ * @remarks
60
+ * The config will be passed as the first argument to the default export of
61
+ * the runtime plugin. When provided as a string, it will be injected to the
62
+ * code as is, letting you define non-serializable values such as functions.
63
+ *
64
+ * If the returned value is an object, it will be converted to a JavaScript
65
+ * object using JSON serialization.
66
+ *
67
+ * @example
68
+ * Returning an object:
69
+ * ```ts
70
+ * {
71
+ * runtimeConfig: () => ({
72
+ * myText: 'Hello!',
73
+ * myNumber: 42,
74
+ * })
75
+ * }
76
+ * ```
77
+ * Returning a string:
78
+ * ```ts
79
+ * {
80
+ * runtimeConfig: () => `{myRegex: /\\.wav$/}`
81
+ * }
82
+ * ```
83
+ */
84
+ runtimeConfig?(): Promise<any>;
85
85
  }
86
86
  /**
87
87
  * Represents a Motion Canvas plugin.
@@ -91,9 +91,9 @@ export interface PluginOptions {
91
91
  * to Motion Canvas.
92
92
  */
93
93
  export type Plugin = VitePlugin & {
94
- /**
95
- * The configuration specific to Motion Canvas.
96
- */
97
- [PLUGIN_OPTIONS]: PluginOptions;
94
+ /**
95
+ * The configuration specific to Motion Canvas.
96
+ */
97
+ [PLUGIN_OPTIONS]: PluginOptions;
98
98
  };
99
99
  export declare function isPlugin(value: any): value is Plugin;
package/lib/plugins.js CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', {value: true});
3
3
  exports.isPlugin = exports.PLUGIN_OPTIONS = void 0;
4
4
  exports.PLUGIN_OPTIONS = Symbol.for('@revideo/vite-plugin/PLUGIN_OPTIONS');
5
5
  function isPlugin(value) {
6
- return value && typeof value === 'object' && exports.PLUGIN_OPTIONS in value;
6
+ return value && typeof value === 'object' && exports.PLUGIN_OPTIONS in value;
7
7
  }
8
8
  exports.isPlugin = isPlugin;
9
- //# sourceMappingURL=plugins.js.map
9
+ //# sourceMappingURL=plugins.js.map