@efxlab/motion-canvas-vite-plugin 4.0.0

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.
Files changed (49) hide show
  1. package/lib/index.d.ts +3 -0
  2. package/lib/index.js +23 -0
  3. package/lib/index.js.map +1 -0
  4. package/lib/main.d.ts +82 -0
  5. package/lib/main.js +42 -0
  6. package/lib/main.js.map +1 -0
  7. package/lib/openInExplorer.d.ts +1 -0
  8. package/lib/openInExplorer.js +44 -0
  9. package/lib/openInExplorer.js.map +1 -0
  10. package/lib/partials/assets.d.ts +6 -0
  11. package/lib/partials/assets.js +50 -0
  12. package/lib/partials/assets.js.map +1 -0
  13. package/lib/partials/corsProxy.d.ts +43 -0
  14. package/lib/partials/corsProxy.js +218 -0
  15. package/lib/partials/corsProxy.js.map +1 -0
  16. package/lib/partials/editor.d.ts +8 -0
  17. package/lib/partials/editor.js +75 -0
  18. package/lib/partials/editor.js.map +1 -0
  19. package/lib/partials/exporter.d.ts +6 -0
  20. package/lib/partials/exporter.js +48 -0
  21. package/lib/partials/exporter.js.map +1 -0
  22. package/lib/partials/index.d.ts +9 -0
  23. package/lib/partials/index.js +26 -0
  24. package/lib/partials/index.js.map +1 -0
  25. package/lib/partials/meta.d.ts +2 -0
  26. package/lib/partials/meta.js +66 -0
  27. package/lib/partials/meta.js.map +1 -0
  28. package/lib/partials/projects.d.ts +9 -0
  29. package/lib/partials/projects.js +88 -0
  30. package/lib/partials/projects.js.map +1 -0
  31. package/lib/partials/scenes.d.ts +2 -0
  32. package/lib/partials/scenes.js +46 -0
  33. package/lib/partials/scenes.js.map +1 -0
  34. package/lib/partials/settings.d.ts +2 -0
  35. package/lib/partials/settings.js +65 -0
  36. package/lib/partials/settings.js.map +1 -0
  37. package/lib/partials/webgl.d.ts +10 -0
  38. package/lib/partials/webgl.js +88 -0
  39. package/lib/partials/webgl.js.map +1 -0
  40. package/lib/plugins.d.ts +104 -0
  41. package/lib/plugins.js +9 -0
  42. package/lib/plugins.js.map +1 -0
  43. package/lib/utils.d.ts +3 -0
  44. package/lib/utils.js +54 -0
  45. package/lib/utils.js.map +1 -0
  46. package/lib/versions.d.ts +6 -0
  47. package/lib/versions.js +28 -0
  48. package/lib/versions.js.map +1 -0
  49. package/package.json +39 -0
@@ -0,0 +1,48 @@
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 });
6
+ exports.exporterPlugin = exporterPlugin;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const mime_types_1 = __importDefault(require("mime-types"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const openInExplorer_1 = require("../openInExplorer");
11
+ function exporterPlugin({ outputPath }) {
12
+ return {
13
+ name: 'motion-canvas:exporter',
14
+ configureServer(server) {
15
+ server.middlewares.use((req, res, next) => {
16
+ if (req.url === '/__open-output-path') {
17
+ if (!fs_1.default.existsSync(outputPath)) {
18
+ fs_1.default.mkdirSync(outputPath, { recursive: true });
19
+ }
20
+ (0, openInExplorer_1.openInExplorer)(outputPath);
21
+ res.end();
22
+ return;
23
+ }
24
+ next();
25
+ });
26
+ server.ws.on('motion-canvas:export', async ({ data, frame, name, subDirectories, mimeType }, client) => {
27
+ const extension = mime_types_1.default.extension(mimeType);
28
+ const outputFilePath = path_1.default.join(outputPath, ...subDirectories, `${name}.${extension}`);
29
+ const outputDirectory = path_1.default.dirname(outputFilePath);
30
+ if (!fs_1.default.existsSync(outputDirectory)) {
31
+ fs_1.default.mkdirSync(outputDirectory, { recursive: true });
32
+ }
33
+ const base64Data = data.slice(data.indexOf(',') + 1);
34
+ await writeBase64(outputFilePath, base64Data);
35
+ client.send('motion-canvas:export-ack', { frame });
36
+ });
37
+ },
38
+ };
39
+ }
40
+ function writeBase64(filePath, base64) {
41
+ return new Promise((resolve, reject) => {
42
+ fs_1.default.createWriteStream(filePath)
43
+ .on('finish', resolve)
44
+ .on('error', reject)
45
+ .end(Buffer.from(base64, 'base64'));
46
+ });
47
+ }
48
+ //# sourceMappingURL=exporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exporter.js","sourceRoot":"","sources":["../../src/partials/exporter.ts"],"names":[],"mappings":";;;;;AAUA,wCAwCC;AAlDD,4CAAoB;AACpB,4DAA8B;AAC9B,gDAAwB;AAExB,sDAAiD;AAMjD,SAAgB,cAAc,CAAC,EAAC,UAAU,EAAuB;IAC/D,OAAO;QACL,IAAI,EAAE,wBAAwB;QAE9B,eAAe,CAAC,MAAM;YACpB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;gBACxC,IAAI,GAAG,CAAC,GAAG,KAAK,qBAAqB,EAAE,CAAC;oBACtC,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;wBAC/B,YAAE,CAAC,SAAS,CAAC,UAAU,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;oBAC9C,CAAC;oBACD,IAAA,+BAAc,EAAC,UAAU,CAAC,CAAC;oBAC3B,GAAG,CAAC,GAAG,EAAE,CAAC;oBACV,OAAO;gBACT,CAAC;gBAED,IAAI,EAAE,CAAC;YACT,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,EAAE,CAAC,EAAE,CACV,sBAAsB,EACtB,KAAK,EAAE,EAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAC,EAAE,MAAM,EAAE,EAAE;gBAC9D,MAAM,SAAS,GAAG,oBAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBAC3C,MAAM,cAAc,GAAG,cAAI,CAAC,IAAI,CAC9B,UAAU,EACV,GAAG,cAAc,EACjB,GAAG,IAAI,IAAI,SAAS,EAAE,CACvB,CAAC;gBACF,MAAM,eAAe,GAAG,cAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;gBAErD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;oBACpC,YAAE,CAAC,SAAS,CAAC,eAAe,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;gBACnD,CAAC;gBAED,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;gBACrD,MAAM,WAAW,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;gBAC9C,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAC,KAAK,EAAC,CAAC,CAAC;YACnD,CAAC,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,QAAgB,EAAE,MAAc;IACnD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,YAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC;aAC3B,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC;aACrB,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;aACnB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,9 @@
1
+ export * from './assets';
2
+ export * from './corsProxy';
3
+ export * from './editor';
4
+ export * from './exporter';
5
+ export * from './meta';
6
+ export * from './projects';
7
+ export * from './scenes';
8
+ export * from './settings';
9
+ export * from './webgl';
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./assets"), exports);
18
+ __exportStar(require("./corsProxy"), exports);
19
+ __exportStar(require("./editor"), exports);
20
+ __exportStar(require("./exporter"), exports);
21
+ __exportStar(require("./meta"), exports);
22
+ __exportStar(require("./projects"), exports);
23
+ __exportStar(require("./scenes"), exports);
24
+ __exportStar(require("./settings"), exports);
25
+ __exportStar(require("./webgl"), exports);
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/partials/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB;AACzB,6CAA2B;AAC3B,yCAAuB;AACvB,6CAA2B;AAC3B,2CAAyB;AACzB,6CAA2B;AAC3B,0CAAwB"}
@@ -0,0 +1,2 @@
1
+ import { Plugin } from 'vite';
2
+ export declare function metaPlugin(): Plugin;
@@ -0,0 +1,66 @@
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 });
6
+ exports.metaPlugin = metaPlugin;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ function metaPlugin() {
10
+ const timeStamps = {};
11
+ let config;
12
+ return {
13
+ name: 'motion-canvas:meta',
14
+ configResolved(resolvedConfig) {
15
+ config = resolvedConfig;
16
+ },
17
+ async transform(code, id) {
18
+ const [base] = id.split('?');
19
+ const { name, ext } = path_1.default.posix.parse(base);
20
+ if (ext !== '.meta') {
21
+ return;
22
+ }
23
+ const sourceFile = config.command === 'build' ? false : JSON.stringify(id);
24
+ /* language=typescript */
25
+ return `\
26
+ import {MetaFile} from '@efxlab/motion-canvas-core';
27
+ let meta;
28
+ if (import.meta.hot) {
29
+ meta = import.meta.hot.data.meta;
30
+ }
31
+ meta ??= new MetaFile('${name}', ${sourceFile});
32
+ if (import.meta.hot) {
33
+ import.meta.hot.accept();
34
+ import.meta.hot.data.meta = meta;
35
+ }
36
+ meta.loadData(${code});
37
+ export default meta;
38
+ `;
39
+ },
40
+ configureServer(server) {
41
+ server.ws.on('motion-canvas:meta', async ({ source, data }, client) => {
42
+ // Ignore virtual meta files.
43
+ if (source.startsWith('\0')) {
44
+ return;
45
+ }
46
+ timeStamps[source] = Date.now();
47
+ await fs_1.default.promises.writeFile(source, JSON.stringify(data, undefined, 2), 'utf8');
48
+ client.send('motion-canvas:meta-ack', { source });
49
+ });
50
+ },
51
+ handleHotUpdate(ctx) {
52
+ const now = Date.now();
53
+ const modules = [];
54
+ for (const module of ctx.modules) {
55
+ if (module.file !== null &&
56
+ timeStamps[module.file] &&
57
+ timeStamps[module.file] + 1000 > now) {
58
+ continue;
59
+ }
60
+ modules.push(module);
61
+ }
62
+ return modules;
63
+ },
64
+ };
65
+ }
66
+ //# sourceMappingURL=meta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.js","sourceRoot":"","sources":["../../src/partials/meta.ts"],"names":[],"mappings":";;;;;AAIA,gCAyEC;AA7ED,4CAAoB;AACpB,gDAAwB;AAGxB,SAAgB,UAAU;IACxB,MAAM,UAAU,GAA2B,EAAE,CAAC;IAC9C,IAAI,MAAsB,CAAC;IAC3B,OAAO;QACL,IAAI,EAAE,oBAAoB;QAE1B,cAAc,CAAC,cAAc;YAC3B,MAAM,GAAG,cAAc,CAAC;QAC1B,CAAC;QAED,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE;YACtB,MAAM,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,MAAM,CAAC,IAAI,KAAK,IAAI;oBACpB,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC;oBACvB,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,GAAG,EACpC,CAAC;oBACD,SAAS;gBACX,CAAC;gBAED,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Plugin } from 'vite';
2
+ import { PluginOptions, ProjectData } from '../plugins';
3
+ interface ProjectPluginConfig {
4
+ buildForEditor?: boolean;
5
+ plugins: PluginOptions[];
6
+ projects: ProjectData[];
7
+ }
8
+ export declare function projectsPlugin({ buildForEditor, plugins, projects, }: ProjectPluginConfig): Plugin;
9
+ export {};
@@ -0,0 +1,88 @@
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 });
6
+ exports.projectsPlugin = projectsPlugin;
7
+ const path_1 = __importDefault(require("path"));
8
+ const utils_1 = require("../utils");
9
+ const versions_1 = require("../versions");
10
+ const PROJECT_QUERY_REGEX = /[?&]project\b/;
11
+ function projectsPlugin({ buildForEditor, plugins, projects, }) {
12
+ const versions = JSON.stringify((0, versions_1.getVersions)());
13
+ let config;
14
+ return {
15
+ name: 'motion-canvas:project',
16
+ configResolved(resolvedConfig) {
17
+ config = resolvedConfig;
18
+ },
19
+ async load(id) {
20
+ if (!PROJECT_QUERY_REGEX.test(id)) {
21
+ return;
22
+ }
23
+ const [base] = id.split('?');
24
+ const { name, dir } = path_1.default.posix.parse(base);
25
+ const runsInEditor = buildForEditor || config.command === 'serve';
26
+ const metaFile = `${name}.meta`;
27
+ await (0, utils_1.createMeta)(path_1.default.join(dir, metaFile));
28
+ const imports = [];
29
+ const pluginNames = [];
30
+ let index = 0;
31
+ for (const plugin of plugins) {
32
+ if (plugin.entryPoint) {
33
+ const pluginName = `plugin${index}`;
34
+ let options = (await plugin.runtimeConfig?.()) ?? '';
35
+ if (typeof options !== 'string') {
36
+ options = JSON.stringify(options);
37
+ }
38
+ imports.push(`import ${pluginName} from '${plugin.entryPoint}'`);
39
+ pluginNames.push(`${pluginName}(${options})`);
40
+ index++;
41
+ }
42
+ }
43
+ /* language=typescript */
44
+ return `\
45
+ ${imports.join('\n')}
46
+ import {${runsInEditor ? 'editorBootstrap' : 'bootstrap'}} from '@efxlab/motion-canvas-core';
47
+ import {MetaFile} from '@efxlab/motion-canvas-core';
48
+ import metaFile from './${metaFile}';
49
+ import config from './${name}';
50
+ import settings from 'virtual:settings.meta';
51
+ export default ${runsInEditor ? 'await editorBootstrap' : 'bootstrap'}(
52
+ '${name}',
53
+ ${versions},
54
+ [${pluginNames.join(', ')}],
55
+ config,
56
+ metaFile,
57
+ settings,
58
+ );`;
59
+ },
60
+ config(config) {
61
+ return {
62
+ build: {
63
+ target: buildForEditor ? 'esnext' : 'modules',
64
+ assetsDir: './',
65
+ rollupOptions: {
66
+ preserveEntrySignatures: 'strict',
67
+ input: Object.fromEntries(projects.map(project => [
68
+ project.name,
69
+ project.filePath + '?project',
70
+ ])),
71
+ },
72
+ },
73
+ server: {
74
+ port: config?.server?.port ?? 9000,
75
+ },
76
+ esbuild: {
77
+ jsx: 'automatic',
78
+ jsxImportSource: '@efxlab/motion-canvas-2d/lib',
79
+ },
80
+ optimizeDeps: {
81
+ entries: projects.map(project => project.filePath),
82
+ exclude: ['preact', 'preact/*', '@preact/signals'],
83
+ },
84
+ };
85
+ },
86
+ };
87
+ }
88
+ //# sourceMappingURL=projects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/partials/projects.ts"],"names":[],"mappings":";;;;;AAcA,wCA4FC;AA1GD,gDAAwB;AAGxB,oCAAoC;AACpC,0CAAwC;AAExC,MAAM,mBA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C,QAAQ,CAAC;oBAClD,OAAO,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,iBAAiB,CAAC;iBACnD;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Plugin } from 'vite';
2
+ export declare function scenesPlugin(): Plugin;
@@ -0,0 +1,46 @@
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 });
6
+ exports.scenesPlugin = scenesPlugin;
7
+ const path_1 = __importDefault(require("path"));
8
+ const utils_1 = require("../utils");
9
+ const SCENE_QUERY_REGEX = /[?&]scene\b/;
10
+ function scenesPlugin() {
11
+ return {
12
+ name: 'motion-canvas: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 `\
24
+ import {ValueDispatcher} from '@efxlab/motion-canvas-core';
25
+ import metaFile from './${metaFile}';
26
+ import description from './${sceneFile}';
27
+ description.name = '${name}';
28
+ metaFile.attach(description.meta);
29
+ if (import.meta.hot) {
30
+ description.onReplaced = import.meta.hot.data.onReplaced;
31
+ }
32
+ description.onReplaced ??= new ValueDispatcher(description.config);
33
+ if (import.meta.hot) {
34
+ import.meta.hot.accept();
35
+ if (import.meta.hot.data.onReplaced) {
36
+ description.onReplaced.current = description;
37
+ } else {
38
+ import.meta.hot.data.onReplaced = description.onReplaced;
39
+ }
40
+ }
41
+ export default description;
42
+ `;
43
+ },
44
+ };
45
+ }
46
+ //# sourceMappingURL=scenes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scenes.js","sourceRoot":"","sources":["../../src/partials/scenes.ts"],"names":[],"mappings":";;;;;AAMA,oCAsCC;AA5CD,gDAAwB;AAExB,oCAAoC;AAEpC,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAExC,SAAgB,YAAY;IAC1B,OAAO;QACL,IAAI,EAAE,qBAAqB;QAE3B,KAAK,CAAC,IAAI,CAAC,EAAE;YACX,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;gBAChC,OAAO;YACT,CAAC;YAED,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC7B,MAAM,EAAC,IAAI,EAAE,GAAG,EAAC,GAAG,cAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC3C,MAAM,QAAQ,GAAG,GAAG,IAAI,OAAO,CAAC;YAChC,MAAM,IAAA,kBAAU,EAAC,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;YAC3C,MAAM,SAAS,GAAG,GAAG,IAAI,EAAE,CAAC;YAE5B,yBAAyB;YACzB,OAAO;;0BAEa,QAAQ;6BACL,SAAS;sBAChB,IAAI;;;;;;;;;;;;;;;CAezB,CAAC;QACE,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Plugin } from 'vite';
2
+ export declare function settingsPlugin(): Plugin;
@@ -0,0 +1,65 @@
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 });
6
+ exports.settingsPlugin = settingsPlugin;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const os_1 = __importDefault(require("os"));
9
+ const path_1 = __importDefault(require("path"));
10
+ function settingsPlugin() {
11
+ const settingsId = 'virtual:settings.meta';
12
+ const resolvedSettingsId = '\0' + settingsId;
13
+ const settingsPath = path_1.default.resolve(os_1.default.homedir(), '.motion-canvas/settings.json');
14
+ const outputDirectory = path_1.default.dirname(settingsPath);
15
+ return {
16
+ name: 'motion-canvas: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('motion-canvas: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('motion-canvas:meta-ack', { source });
61
+ });
62
+ },
63
+ };
64
+ }
65
+ //# sourceMappingURL=settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/partials/settings.ts"],"names":[],"mappings":";;;;;AAKA,wCA+DC;AApED,4CAAoB;AACpB,4CAAoB;AACpB,gDAAwB;AAGxB,SAAgB,cAAc;IAC5B,MAAM,UAAU,GAAG,uBAAuB,CAAC;IAC3C,MAAM,kBAAkB,GAAG,IAAI,GAAG,UAAU,CA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E,CAAC,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;gBAC7D,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,kCAAkC;gBACpC,CAAC;gBAED,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;oBACxB,MAAM,OAAO,CAAC,GAAG,CAAC;wBAChB,YAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,EAAE,MAAM,CAAC;wBACpD,iEAAiE;wBACjE,iCAAiC;wBACjC,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;4BACtD,IAAI,MAAM,EAAE,CAAC;gCACX,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;4BAC9C,CAAC;wBACH,CAAC,CAAC;qBACH,CAAC,CAAC;gBACL,CAAC;gBAED,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAC,MAAM,EAAC,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { Plugin } from 'vite';
2
+ declare module 'source-map' {
3
+ interface SourceNode {
4
+ add(value: string | SourceNode): void;
5
+ }
6
+ interface SourceMapGenerator {
7
+ toJSON(): any;
8
+ }
9
+ }
10
+ export declare function webglPlugin(): Plugin;
@@ -0,0 +1,88 @@
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 });
6
+ exports.webglPlugin = webglPlugin;
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");
11
+ const GLSL_EXTENSION_REGEX = /\.glsl(?:$|\?)/;
12
+ const INCLUDE_REGEX = /^#include "([^"]+)"/;
13
+ function webglPlugin() {
14
+ let config;
15
+ return {
16
+ name: 'motion-canvas:webgl',
17
+ configResolved(resolvedConfig) {
18
+ config = resolvedConfig;
19
+ },
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
+ };
51
+ }
52
+ async function resolveGlsl(context, id, code) {
53
+ const lines = code.split(/\r?\n/);
54
+ const source = new source_map_1.SourceNode(1, 0, '', '');
55
+ if (context.fileStack.includes(id)) {
56
+ throw new Error(`Circular dependency detected: ${context.fileStack.join(' -> ')}`);
57
+ }
58
+ context.fileStack.push(id);
59
+ const sourceMapId = path_1.default.posix.relative(context.rootDir, id);
60
+ for (let i = 0; i < lines.length; i++) {
61
+ const line = lines[i];
62
+ const match = line.match(INCLUDE_REGEX);
63
+ if (match) {
64
+ const childId = await context.resolve(match[1], id);
65
+ if (!childId) {
66
+ continue;
67
+ }
68
+ const childSourceMapId = path_1.default.posix.relative(context.rootDir, childId);
69
+ if (context.includeMap.has(childSourceMapId)) {
70
+ continue;
71
+ }
72
+ context.includeMap.set(childSourceMapId, [sourceMapId, i + 1]);
73
+ context.watchFile(childId);
74
+ const childCode = await fs_1.default.promises.readFile(childId, 'utf-8');
75
+ source.add(await resolveGlsl(context, childId, childCode));
76
+ }
77
+ else {
78
+ let j = 0;
79
+ for (; j < line.length; j++) {
80
+ source.add(new source_map_1.SourceNode(i + 1, j, sourceMapId, line[j]));
81
+ }
82
+ source.add(new source_map_1.SourceNode(i + 1, j, sourceMapId, '\n'));
83
+ }
84
+ }
85
+ context.fileStack.pop();
86
+ return source;
87
+ }
88
+ //# sourceMappingURL=webgl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webgl.js","sourceRoot":"","sources":["../../src/partials/webgl.ts"],"names":[],"mappings":";;;;;AAkBA,kCA6CC;AA/DD,4CAAoB;AACpB,gDAAwB;AACxB,2CAAsC;AACtC,+BAA2D;AAY3D,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAC9C,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAE5C,SAAgB,WAAW;IACzB,IAAI,MAAsB,CAAC;IAC3B,OAAO;QACL,IAAI,EAAE,qBAAqB;QAE3B,cAAc,CAAC,cAAc;YAC3B,MAAM,GAAG,cAAc,CAAC;QAC1B,CAAC;QAED,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE;YACtB,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;gBACnC,OAAO;YACT,CAAC;YAED,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACpC,MAAM,EAAC,GAAG,EAAC,GAAG,cAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACrC,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;YAC1C,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBACtB,OAAO;YACT,CAAC;YAED,MAAM,OAAO,GAAsB;gBACjC,OAAO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C;QAC7D,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,GAAG,CAAC,CAAC;YACV,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC5B,MAAM,CAAC,GAAG,CAAC,IAAI,uBAAU,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7D,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,IAAI,uBAAU,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IACD,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;IAExB,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,104 @@
1
+ import { Plugin as VitePlugin } from 'vite';
2
+ /**
3
+ * Represents a Motion Canvas project configured in the Vite plugin.
4
+ */
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 file relative to the Vite configuration file.
16
+ */
17
+ filePath: string;
18
+ /**
19
+ * The path to access the project relative to the Host Name.
20
+ */
21
+ url: string;
22
+ }
23
+ /**
24
+ * The Motion Canvas configuration passed to each plugin.
25
+ */
26
+ export interface PluginConfig {
27
+ /**
28
+ * The projects configured in the Vite plugin.
29
+ */
30
+ projects: ProjectData[];
31
+ /**
32
+ * The output path relative to the Vite configuration file.
33
+ */
34
+ output: string;
35
+ }
36
+ export declare const PLUGIN_OPTIONS: unique symbol;
37
+ export interface PluginOptions {
38
+ /**
39
+ * An entry point of the runtime plugin.
40
+ *
41
+ * @remarks
42
+ * While the Vite plugin can extend the backend functionality, this entry
43
+ * point lets you include custom runtime code that will be loaded by the
44
+ * browser.
45
+ *
46
+ * It should be a valid module specifier from which the plugin will be
47
+ * imported. The module should contain a default export of a runtime plugin.
48
+ */
49
+ entryPoint: string;
50
+ /**
51
+ * The configuration hook of the plugin.
52
+ *
53
+ * @remarks
54
+ * Invoked during `configResolved` hook of Vite, contains the Motion Canvas
55
+ * specific configuration. Returned value will be merged with the current
56
+ * configuration.
57
+ *
58
+ * @param config - The configuration passed to the plugin.
59
+ */
60
+ config?(config: PluginConfig): Promise<Partial<PluginConfig> | void>;
61
+ /**
62
+ * Get custom configuration that will be passed to the runtime plugin.
63
+ *
64
+ * @remarks
65
+ * The config will be passed as the first argument to the default export of
66
+ * the runtime plugin. When provided as a string, it will be injected to the
67
+ * code as is, letting you define non-serializable values such as functions.
68
+ *
69
+ * If the returned value is an object, it will be converted to a JavaScript
70
+ * object using JSON serialization.
71
+ *
72
+ * @example
73
+ * Returning an object:
74
+ * ```ts
75
+ * {
76
+ * runtimeConfig: () => ({
77
+ * myText: 'Hello!',
78
+ * myNumber: 42,
79
+ * })
80
+ * }
81
+ * ```
82
+ * Returning a string:
83
+ * ```ts
84
+ * {
85
+ * runtimeConfig: () => `{myRegex: /\\.wav$/}`
86
+ * }
87
+ * ```
88
+ */
89
+ runtimeConfig?(): Promise<any>;
90
+ }
91
+ /**
92
+ * Represents a Motion Canvas plugin.
93
+ *
94
+ * @remarks
95
+ * It's a normal Vite plugin that can provide additional configuration specific
96
+ * to Motion Canvas.
97
+ */
98
+ export type Plugin = VitePlugin & {
99
+ /**
100
+ * The configuration specific to Motion Canvas.
101
+ */
102
+ [PLUGIN_OPTIONS]: PluginOptions;
103
+ };
104
+ export declare function isPlugin(value: any): value is Plugin;
package/lib/plugins.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PLUGIN_OPTIONS = void 0;
4
+ exports.isPlugin = isPlugin;
5
+ exports.PLUGIN_OPTIONS = Symbol.for('@efxlab/motion-canvas-vite-plugin/PLUGIN_OPTIONS');
6
+ function isPlugin(value) {
7
+ return value && typeof value === 'object' && exports.PLUGIN_OPTIONS in value;
8
+ }
9
+ //# sourceMappingURL=plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":";;;AAiHA,4BAEC;AA7EY,QAAA,cAAc,GAAG,MAAM,CAAC,GAAG,CACtC,kDAAkD,CACnD,CAAC;AAyEF,SAAgB,QAAQ,CAAC,KAAU;IACjC,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,sBAAc,IAAI,KAAK,CAAC;AACvE,CAAC"}
package/lib/utils.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { ProjectData } from './plugins';
2
+ export declare function createMeta(metaPath: string): Promise<void>;
3
+ export declare function getProjects(project: string | string[]): ProjectData[];