@revideo/vite-plugin 0.4.7-test.1023 → 0.4.7

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,97 +1,89 @@
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});
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 });
8
6
  exports.webglPlugin = void 0;
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');
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");
13
11
  const GLSL_EXTENSION_REGEX = /\.glsl(?:$|\?)/;
14
12
  const INCLUDE_REGEX = /^#include "([^"]+)"/;
15
13
  function webglPlugin() {
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;
14
+ let config;
15
+ return {
16
+ name: 'revideo:webgl',
17
+ configResolved(resolvedConfig) {
18
+ config = resolvedConfig;
40
19
  },
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
- };
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
+ };
55
51
  }
56
52
  exports.webglPlugin = webglPlugin;
57
53
  async function resolveGlsl(context, id, code) {
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'));
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
+ }
92
85
  }
93
- }
94
- context.fileStack.pop();
95
- return source;
86
+ context.fileStack.pop();
87
+ return source;
96
88
  }
97
- //# sourceMappingURL=webgl.js.map
89
+ //# 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