@machinal/scenes 0.0.0-stage → 0.1.1

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 (113) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +201 -0
  3. package/LICENSING.md +13 -0
  4. package/NOTICE +8 -0
  5. package/README.md +183 -2
  6. package/bin/machinal-scenes.mjs +89 -0
  7. package/dist/index.d.ts +3 -0
  8. package/dist/index.js +2 -0
  9. package/dist/runtime/artifact.d.ts +18 -0
  10. package/dist/runtime/artifact.js +26 -0
  11. package/dist/runtime/bridge.d.ts +8 -0
  12. package/dist/runtime/bridge.js +76 -0
  13. package/dist/runtime/choreography.d.ts +32 -0
  14. package/dist/runtime/choreography.js +81 -0
  15. package/dist/runtime/controller.d.ts +5 -0
  16. package/dist/runtime/controller.js +93 -0
  17. package/dist/runtime/geometry.d.ts +20 -0
  18. package/dist/runtime/geometry.js +34 -0
  19. package/dist/runtime/index.d.ts +14 -0
  20. package/dist/runtime/index.js +14 -0
  21. package/dist/runtime/layout.d.ts +17 -0
  22. package/dist/runtime/layout.js +48 -0
  23. package/dist/runtime/math.d.ts +4 -0
  24. package/dist/runtime/math.js +23 -0
  25. package/dist/runtime/media.d.ts +2 -0
  26. package/dist/runtime/media.js +69 -0
  27. package/dist/runtime/models.d.ts +14 -0
  28. package/dist/runtime/models.js +370 -0
  29. package/dist/runtime/objects.d.ts +8 -0
  30. package/dist/runtime/objects.js +24 -0
  31. package/dist/runtime/parameters.d.ts +17 -0
  32. package/dist/runtime/parameters.js +35 -0
  33. package/dist/runtime/resources.d.ts +5 -0
  34. package/dist/runtime/resources.js +63 -0
  35. package/dist/runtime/types.d.ts +76 -0
  36. package/dist/runtime/types.js +1 -0
  37. package/dist/runtime/validation.d.ts +4 -0
  38. package/dist/runtime/validation.js +37 -0
  39. package/dist/runtime/video.d.ts +90 -0
  40. package/dist/runtime/video.js +46 -0
  41. package/dist/svelte/SceneCanvas.svelte +15 -0
  42. package/dist/svelte/SceneCanvas.svelte.d.ts +8 -0
  43. package/dist/svelte/SceneThree.svelte +61 -0
  44. package/dist/svelte/SceneThree.svelte.d.ts +10 -0
  45. package/dist/svelte/SceneVideo.svelte +38 -0
  46. package/dist/svelte/SceneVideo.svelte.d.ts +18 -0
  47. package/dist/svelte/context.d.ts +12 -0
  48. package/dist/svelte/context.js +8 -0
  49. package/dist/svelte/index.d.ts +9 -0
  50. package/dist/svelte/index.js +8 -0
  51. package/dist/svelte/model-assets.d.ts +4 -0
  52. package/dist/svelte/model-assets.js +42 -0
  53. package/dist/svelte/mount.svelte.d.ts +3 -0
  54. package/dist/svelte/mount.svelte.js +42 -0
  55. package/dist/svelte/three-rigs.d.ts +20 -0
  56. package/dist/svelte/three-rigs.js +22 -0
  57. package/dist/svelte/three-session.d.ts +6 -0
  58. package/dist/svelte/three-session.js +66 -0
  59. package/dist/svelte/three.d.ts +15 -0
  60. package/dist/svelte/three.js +33 -0
  61. package/examples/quickstart/gitignore +6 -0
  62. package/examples/quickstart/index.html +48 -0
  63. package/examples/quickstart/package.json +27 -0
  64. package/examples/quickstart/scene.config.json +11 -0
  65. package/examples/quickstart/scene.html +13 -0
  66. package/examples/quickstart/src/ExportPanel.svelte +74 -0
  67. package/examples/quickstart/src/Title.svelte +22 -0
  68. package/examples/quickstart/src/export-api.ts +30 -0
  69. package/examples/quickstart/src/main.ts +114 -0
  70. package/examples/quickstart/src/playback.ts +6 -0
  71. package/examples/quickstart/src/request.ts +5 -0
  72. package/examples/quickstart/src/scene.ts +12 -0
  73. package/examples/quickstart/src/useLocalExport.svelte.ts +46 -0
  74. package/examples/quickstart/src/workspace.css +79 -0
  75. package/examples/quickstart/svelte.config.js +1 -0
  76. package/examples/quickstart/tools/local-export.mjs +120 -0
  77. package/examples/quickstart/tsconfig.json +15 -0
  78. package/examples/quickstart/vite.config.js +17 -0
  79. package/native/THIRD_PARTY_NOTICES.txt +158 -0
  80. package/native/darwin-arm64/scene-render +0 -0
  81. package/native/darwin-x64/scene-render +0 -0
  82. package/native/linux-x64/scene-render +0 -0
  83. package/native/manifest.json +33 -0
  84. package/native/win32-x64/scene-render.exe +0 -0
  85. package/node/cli-output.mjs +10 -0
  86. package/node/download.mjs +37 -0
  87. package/node/ffmpeg-releases.mjs +24 -0
  88. package/node/index.d.ts +50 -0
  89. package/node/index.mjs +2 -0
  90. package/node/platforms.mjs +14 -0
  91. package/node/render.mjs +59 -0
  92. package/node/toolchain.mjs +118 -0
  93. package/package.json +89 -4
  94. package/renderer/browser.go +116 -0
  95. package/renderer/browser_log.go +36 -0
  96. package/renderer/browser_log_test.go +48 -0
  97. package/renderer/browser_test.go +307 -0
  98. package/renderer/cmd/scene-render/main.go +128 -0
  99. package/renderer/cmd/scene-render/main_test.go +37 -0
  100. package/renderer/cmd/scene-render/server.go +42 -0
  101. package/renderer/encoder.go +116 -0
  102. package/renderer/encoder_test.go +22 -0
  103. package/renderer/go.mod +11 -0
  104. package/renderer/go.sum +10 -0
  105. package/renderer/network.go +50 -0
  106. package/renderer/output.go +93 -0
  107. package/renderer/pipeline.go +108 -0
  108. package/renderer/pipeline_test.go +108 -0
  109. package/renderer/render.go +141 -0
  110. package/renderer/request.go +140 -0
  111. package/renderer/request_test.go +94 -0
  112. package/renderer/types.go +113 -0
  113. package/renderer/worker.go +110 -0
@@ -0,0 +1,158 @@
1
+ Go standard library
2
+
3
+ Copyright 2009 The Go Authors.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are
7
+ met:
8
+
9
+ * Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+ * Redistributions in binary form must reproduce the above
12
+ copyright notice, this list of conditions and the following disclaimer
13
+ in the documentation and/or other materials provided with the
14
+ distribution.
15
+ * Neither the name of Google LLC nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+
32
+ --------------------
33
+
34
+ github.com/chromedp/cdproto v0.157.8 (LICENSE)
35
+
36
+ The MIT License (MIT)
37
+
38
+ Copyright (c) 2016-2026 Kenneth Shaw
39
+
40
+ Permission is hereby granted, free of charge, to any person obtaining a copy
41
+ of this software and associated documentation files (the "Software"), to deal
42
+ in the Software without restriction, including without limitation the rights
43
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
44
+ copies of the Software, and to permit persons to whom the Software is
45
+ furnished to do so, subject to the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be included in all
48
+ copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
53
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
55
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
56
+ SOFTWARE.
57
+
58
+
59
+ --------------------
60
+
61
+ github.com/chromedp/chromedp v0.20.1 (LICENSE)
62
+
63
+ The MIT License (MIT)
64
+
65
+ Copyright (c) 2016-2026 Kenneth Shaw
66
+
67
+ Permission is hereby granted, free of charge, to any person obtaining a copy
68
+ of this software and associated documentation files (the "Software"), to deal
69
+ in the Software without restriction, including without limitation the rights
70
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
71
+ copies of the Software, and to permit persons to whom the Software is
72
+ furnished to do so, subject to the following conditions:
73
+
74
+ The above copyright notice and this permission notice shall be included in all
75
+ copies or substantial portions of the Software.
76
+
77
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
78
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
79
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
80
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
81
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
82
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
83
+ SOFTWARE.
84
+
85
+
86
+ --------------------
87
+
88
+ gopkg.in/yaml.v3 v3.0.1 (LICENSE)
89
+
90
+
91
+ This project is covered by two different licenses: MIT and Apache.
92
+
93
+ #### MIT License ####
94
+
95
+ The following files were ported to Go from C files of libyaml, and thus
96
+ are still covered by their original MIT license, with the additional
97
+ copyright staring in 2011 when the project was ported over:
98
+
99
+ apic.go emitterc.go parserc.go readerc.go scannerc.go
100
+ writerc.go yamlh.go yamlprivateh.go
101
+
102
+ Copyright (c) 2006-2010 Kirill Simonov
103
+ Copyright (c) 2006-2011 Kirill Simonov
104
+
105
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
106
+ this software and associated documentation files (the "Software"), to deal in
107
+ the Software without restriction, including without limitation the rights to
108
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
109
+ of the Software, and to permit persons to whom the Software is furnished to do
110
+ so, subject to the following conditions:
111
+
112
+ The above copyright notice and this permission notice shall be included in all
113
+ copies or substantial portions of the Software.
114
+
115
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
116
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
117
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
118
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
119
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
120
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
121
+ SOFTWARE.
122
+
123
+ ### Apache License ###
124
+
125
+ All the remaining project files are covered by the Apache license:
126
+
127
+ Copyright (c) 2011-2019 Canonical Ltd
128
+
129
+ Licensed under the Apache License, Version 2.0 (the "License");
130
+ you may not use this file except in compliance with the License.
131
+ You may obtain a copy of the License at
132
+
133
+ http://www.apache.org/licenses/LICENSE-2.0
134
+
135
+ Unless required by applicable law or agreed to in writing, software
136
+ distributed under the License is distributed on an "AS IS" BASIS,
137
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138
+ See the License for the specific language governing permissions and
139
+ limitations under the License.
140
+
141
+
142
+ --------------------
143
+
144
+ gopkg.in/yaml.v3 v3.0.1 (NOTICE)
145
+
146
+ Copyright 2011-2016 Canonical Ltd.
147
+
148
+ Licensed under the Apache License, Version 2.0 (the "License");
149
+ you may not use this file except in compliance with the License.
150
+ You may obtain a copy of the License at
151
+
152
+ http://www.apache.org/licenses/LICENSE-2.0
153
+
154
+ Unless required by applicable law or agreed to in writing, software
155
+ distributed under the License is distributed on an "AS IS" BASIS,
156
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
157
+ See the License for the specific language governing permissions and
158
+ limitations under the License.
Binary file
Binary file
Binary file
@@ -0,0 +1,33 @@
1
+ {
2
+ "version": 1,
3
+ "targets": [
4
+ {
5
+ "platform": "win32",
6
+ "arch": "x64",
7
+ "file": "win32-x64/scene-render.exe",
8
+ "size": 8543232,
9
+ "sha256": "34bd5002c16df9e73ea4104694e440c06c8c503f735a6fe0850672024f05a3c5"
10
+ },
11
+ {
12
+ "platform": "linux",
13
+ "arch": "x64",
14
+ "file": "linux-x64/scene-render",
15
+ "size": 8274080,
16
+ "sha256": "59e027f9293829f3aa4db965b2e73039c3ee54ea107b847e0d8ef3dfca7eab73"
17
+ },
18
+ {
19
+ "platform": "darwin",
20
+ "arch": "x64",
21
+ "file": "darwin-x64/scene-render",
22
+ "size": 8497744,
23
+ "sha256": "8e718e1863cdc97432fa3baa65444fe2f65e2c3e7c04e9c5eb9b60818043fdd8"
24
+ },
25
+ {
26
+ "platform": "darwin",
27
+ "arch": "arm64",
28
+ "file": "darwin-arm64/scene-render",
29
+ "size": 7940450,
30
+ "sha256": "ae9789bc30c2808ecb8bf5c636c31cf26409509b9e039ffc3e2674d5e3e063dc"
31
+ }
32
+ ]
33
+ }
@@ -0,0 +1,10 @@
1
+ export function formatToolchainStatus(status) {
2
+ const heading = status.ready ? 'Rendering tools are ready.' : 'Rendering tools are not ready.';
3
+ const tools = [['Renderer', status.renderer], ['Chrome Headless Shell', status.browser], ['FFmpeg', status.ffmpeg]];
4
+ const lines = tools.map(([name, tool]) => ` ${name}: ${tool.available ? 'ready' : tool.error ?? 'not available'}`);
5
+ return [heading, ...lines].join('\n');
6
+ }
7
+
8
+ export function formatRenderResult(asset) {
9
+ return `Rendered ${asset.file}\n${asset.width} × ${asset.height} · ${asset.fps} fps · ${asset.duration} s`;
10
+ }
@@ -0,0 +1,37 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { createReadStream, createWriteStream } from 'node:fs';
3
+ import { constants, copyFile, mkdir, rm } from 'node:fs/promises';
4
+ import { dirname } from 'node:path';
5
+ import { Readable, Transform } from 'node:stream';
6
+ import { pipeline } from 'node:stream/promises';
7
+
8
+ export async function sha256(path) {
9
+ const hash = createHash('sha256');
10
+ for await (const chunk of createReadStream(path)) hash.update(chunk);
11
+ return hash.digest('hex');
12
+ }
13
+
14
+ export async function downloadVerified(url, destination, expectedHash, fetchFile = fetch) {
15
+ if (new URL(url).protocol !== 'https:') throw new Error('Tool downloads require HTTPS');
16
+ const response = await fetchFile(url, { signal: AbortSignal.timeout(300_000) });
17
+ if (!response.ok || !response.body) throw new Error(`Tool download failed: HTTP ${response.status}`);
18
+ await mkdir(dirname(destination), { recursive: true });
19
+ const temporary = `${destination}.partial-${randomUUID()}`;
20
+ const hash = createHash('sha256');
21
+ let received = 0;
22
+ const meter = new Transform({
23
+ transform(chunk, encoding, next) {
24
+ received += chunk.length;
25
+ if (received > 128 * 1024 * 1024) return next(new Error('Tool download exceeds the 128 MiB limit'));
26
+ hash.update(chunk);
27
+ next(null, chunk);
28
+ },
29
+ });
30
+ try {
31
+ await pipeline(Readable.fromWeb(response.body), meter, createWriteStream(temporary, { flags: 'wx' }));
32
+ if (hash.digest('hex') !== expectedHash) throw new Error('Tool download SHA-256 mismatch; no executable was installed');
33
+ await copyFile(temporary, destination, constants.COPYFILE_EXCL);
34
+ } finally {
35
+ await rm(temporary, { force: true });
36
+ }
37
+ }
@@ -0,0 +1,24 @@
1
+ // SHA-256 digests published by GitHub for the pinned release assets.
2
+ export const ffmpegRelease = 'b6.1.1';
3
+ export const ffmpegReleases = {
4
+ 'win32-x64': {
5
+ archive: '8883a3dffbd0a16cf4ef95206ea05283f78908dbfb118f73c83f4951dcc06d77',
6
+ license: '8ceb4b9ee5adedde47b31e975c1d90c73ad27b6b165a1dcd80c7c545eb65b903',
7
+ readme: 'a636a7183c58006351acbaf35303c0ed85c6e1320fd4e80de453ba6157de6311',
8
+ },
9
+ 'linux-x64': {
10
+ archive: 'bfe8a8fc511530457b528c48d77b5737527b504a3797a9bc4866aeca69c2dffa',
11
+ license: '8ceb4b9ee5adedde47b31e975c1d90c73ad27b6b165a1dcd80c7c545eb65b903',
12
+ readme: '72f4b1b06d419d22ace6e7cc75f06826f90737345aa0b1736158929f4aacc537',
13
+ },
14
+ 'darwin-x64': {
15
+ archive: '929b375c1182d956c51f7ac25e0b2b0411fb01f6f407aa15c9758efeb4242106',
16
+ license: '2e1d16c72fd74e12063776371da757322f8b77589386532f4fd8634bde7de1af',
17
+ readme: 'e88a0325f8e5b75210355e37341824f074d3cd82def2125be54c914b62848a36',
18
+ },
19
+ 'darwin-arm64': {
20
+ archive: '8923876afa8db5585022d7860ec7e589af192f441c56793971276d450ed3bbfa',
21
+ license: 'cb48bf09a11f5fb576cddb0431c8f5ed0a60157a9ec942adffc13907cbe083f2',
22
+ readme: '05ba4b92c96605434b1aaae3eedf5a2c280c9607bf78ffca9a5b536d9af2dc6a',
23
+ },
24
+ };
@@ -0,0 +1,50 @@
1
+ import type { RenderedSceneAsset, SceneRequest } from '../dist/runtime/index.js';
2
+
3
+ export interface ToolOptions {
4
+ cacheDirectory?: string;
5
+ browserExecutable?: string;
6
+ ffmpegExecutable?: string;
7
+ }
8
+
9
+ export interface ToolStatus {
10
+ path?: string;
11
+ available: boolean;
12
+ version?: string;
13
+ error?: string;
14
+ }
15
+
16
+ export interface ToolchainStatus {
17
+ ready: boolean;
18
+ cacheDirectory: string;
19
+ renderer: ToolStatus;
20
+ browser: ToolStatus;
21
+ ffmpeg: ToolStatus;
22
+ }
23
+
24
+ export interface AudioTrack {
25
+ file: string;
26
+ start: number;
27
+ from?: number;
28
+ duration: number;
29
+ volume?: number;
30
+ }
31
+
32
+ export interface RenderRequest extends SceneRequest {
33
+ url: string;
34
+ audio?: AudioTrack[];
35
+ }
36
+
37
+ export interface RenderOptions extends ToolOptions {
38
+ request: string | RenderRequest;
39
+ serveDirectory?: string;
40
+ output?: string;
41
+ workers?: number;
42
+ noSandbox?: boolean;
43
+ lossless?: boolean;
44
+ gpu?: boolean;
45
+ onProgress?: (message: string) => void;
46
+ }
47
+
48
+ export function setup(options?: ToolOptions & { onProgress?: (message: string) => void }): Promise<ToolchainStatus>;
49
+ export function doctor(options?: ToolOptions): Promise<ToolchainStatus>;
50
+ export function renderVideo(options: RenderOptions): Promise<RenderedSceneAsset>;
package/node/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export { doctor, setup } from './toolchain.mjs';
2
+ export { renderVideo } from './render.mjs';
@@ -0,0 +1,14 @@
1
+ export const rendererTargets = [
2
+ { platform: 'win32', arch: 'x64', goos: 'windows', goarch: 'amd64', file: 'win32-x64/scene-render.exe' },
3
+ { platform: 'linux', arch: 'x64', goos: 'linux', goarch: 'amd64', file: 'linux-x64/scene-render' },
4
+ { platform: 'darwin', arch: 'x64', goos: 'darwin', goarch: 'amd64', file: 'darwin-x64/scene-render' },
5
+ { platform: 'darwin', arch: 'arm64', goos: 'darwin', goarch: 'arm64', file: 'darwin-arm64/scene-render' },
6
+ ];
7
+
8
+ export function platformTarget(platform = process.platform, arch = process.arch) {
9
+ const target = rendererTargets.find(target => target.platform === platform && target.arch === arch);
10
+ if (!target) {
11
+ throw new Error(`Native rendering is not supported on ${platform}-${arch}. Supported: ${rendererTargets.map(target => `${target.platform}-${target.arch}`).join(', ')}. Browser authoring/preview remains available.`);
12
+ }
13
+ return target;
14
+ }
@@ -0,0 +1,59 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { access, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { dirname, join, resolve } from 'node:path';
5
+ import { parseRenderedSceneAsset, validateRequest } from '../dist/runtime/index.js';
6
+ import { doctor } from './toolchain.mjs';
7
+
8
+ export async function renderVideo(options) {
9
+ if (!options?.request) throw new Error('A render request filename or object is required');
10
+ const output = resolve(options.output ?? 'scene.mp4');
11
+ if (!/\.(mp4|webm)$/i.test(output)) throw new Error('Output must be a new .mp4 or .webm file');
12
+ for (const path of [output, `${output}.scene.json`]) {
13
+ try { await access(path); }
14
+ catch (error) { if (error.code === 'ENOENT') continue; throw error; }
15
+ throw new Error(`Output already exists: ${path}. No files were changed.`);
16
+ }
17
+ if (options.workers !== undefined && (!Number.isInteger(options.workers) || options.workers < 1 || options.workers > 16)) throw new Error('workers must be an integer between 1 and 16');
18
+ const tools = await doctor(options);
19
+ if (!tools.ready) throw new Error(`Rendering tools are not ready. Run machinal-scenes setup, then machinal-scenes doctor.\n${[tools.renderer, tools.browser, tools.ffmpeg].filter(tool => !tool.available).map(tool => tool.error).join('\n')}`);
20
+ const directory = await mkdtemp(join(tmpdir(), 'machinal-scene-render-'));
21
+ try {
22
+ let request;
23
+ if (typeof options.request === 'string') request = resolve(options.request);
24
+ else {
25
+ validateRequest(options.request);
26
+ const audio = options.request.audio?.map(track => ({ ...track, file: resolve(track.file) }));
27
+ request = join(directory, 'request.json');
28
+ await writeFile(request, JSON.stringify({ ...options.request, ...(audio ? { audio } : {}) }), 'utf8');
29
+ }
30
+ await mkdir(dirname(output), { recursive: true });
31
+ const args = ['-request', request, '-serve', resolve(options.serveDirectory ?? 'dist'), '-output', output, '-browser', tools.browser.path, '-ffmpeg', tools.ffmpeg.path, '-workers', String(options.workers ?? 2)];
32
+ if (options.noSandbox) args.push('-no-sandbox');
33
+ if (options.lossless) args.push('-lossless');
34
+ if (options.gpu) args.push('-gpu');
35
+ const result = await runRenderer(tools.renderer.path, args, options.onProgress);
36
+ const asset = parseRenderedSceneAsset(JSON.parse(result));
37
+ const persisted = JSON.parse(await readFile(`${output}.scene.json`, 'utf8'));
38
+ if (asset.sha256 !== persisted.sha256) throw new Error('Native renderer result and output manifest do not match');
39
+ return asset;
40
+ } finally {
41
+ await rm(directory, { recursive: true, force: true });
42
+ }
43
+ }
44
+
45
+ function runRenderer(executable, args, onProgress = () => {}) {
46
+ return new Promise((resolve, reject) => {
47
+ const child = spawn(executable, args, { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
48
+ let stdout = '';
49
+ let stderr = '';
50
+ child.stdout.on('data', chunk => { stdout += chunk; });
51
+ child.stderr.on('data', chunk => {
52
+ stderr = (stderr + chunk).slice(-64 * 1024);
53
+ try { onProgress(chunk.toString()); }
54
+ catch (error) { child.kill(); reject(error); }
55
+ });
56
+ child.once('error', reject);
57
+ child.once('close', code => code === 0 ? resolve(stdout) : reject(new Error(`Scene rendering failed (${code}):\n${stderr}`)));
58
+ });
59
+ }
@@ -0,0 +1,118 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { createReadStream, createWriteStream } from 'node:fs';
3
+ import { access, chmod, mkdir, mkdtemp, readFile, rename, rm, writeFile } from 'node:fs/promises';
4
+ import { homedir } from 'node:os';
5
+ import { dirname, join, resolve } from 'node:path';
6
+ import { pipeline } from 'node:stream/promises';
7
+ import { fileURLToPath } from 'node:url';
8
+ import { promisify } from 'node:util';
9
+ import { createGunzip } from 'node:zlib';
10
+ import { Browser, computeExecutablePath, install } from '@puppeteer/browsers';
11
+ import { downloadVerified, sha256 } from './download.mjs';
12
+ import { ffmpegRelease, ffmpegReleases } from './ffmpeg-releases.mjs';
13
+ import { platformTarget } from './platforms.mjs';
14
+
15
+ export const browserBuild = '151.0.7922.34';
16
+ const execute = promisify(execFile);
17
+ const packageRoot = fileURLToPath(new URL('../', import.meta.url));
18
+
19
+ export function cacheDirectory(options = {}) {
20
+ if (options.cacheDirectory || process.env.MACHINAL_SCENES_CACHE) return resolve(options.cacheDirectory || process.env.MACHINAL_SCENES_CACHE);
21
+ const base = process.platform === 'win32' ? process.env.LOCALAPPDATA ?? join(homedir(), 'AppData/Local')
22
+ : process.platform === 'darwin' ? join(homedir(), 'Library/Caches')
23
+ : process.env.XDG_CACHE_HOME ?? join(homedir(), '.cache');
24
+ return join(base, 'machinal-scenes');
25
+ }
26
+
27
+ export function toolPaths(options = {}) {
28
+ platformTarget();
29
+ const cache = cacheDirectory(options);
30
+ return {
31
+ cache,
32
+ browser: resolve(options.browserExecutable || process.env.SCENE_BROWSER || computeExecutablePath({ browser: Browser.CHROMEHEADLESSSHELL, buildId: browserBuild, cacheDir: join(cache, 'browser') })),
33
+ ffmpeg: resolve(options.ffmpegExecutable || process.env.SCENE_FFMPEG || join(cache, 'ffmpeg', ffmpegRelease, `${process.platform}-${process.arch}`, process.platform === 'win32' ? 'ffmpeg.exe' : 'ffmpeg')),
34
+ };
35
+ }
36
+
37
+ export async function rendererPath() {
38
+ const target = platformTarget();
39
+ const manifest = JSON.parse(await readFile(join(packageRoot, 'native/manifest.json'), 'utf8').catch(error => {
40
+ throw new Error(`This installation is missing the precompiled renderer manifest. Install a complete @machinal/scenes release. (${error.code})`);
41
+ }));
42
+ const entry = manifest.targets.find(entry => entry.platform === target.platform && entry.arch === target.arch);
43
+ if (!entry || entry.file !== target.file) throw new Error('Missing native renderer for this platform');
44
+ const executable = join(packageRoot, 'native', entry.file);
45
+ if (await sha256(executable) !== entry.sha256) throw new Error('Native renderer checksum mismatch; reinstall the package');
46
+ return executable;
47
+ }
48
+
49
+ async function probe(path, args) {
50
+ try {
51
+ await access(path);
52
+ const { stdout, stderr } = await execute(path, args, { timeout: 15_000, maxBuffer: 128 * 1024, windowsHide: true });
53
+ return { path, available: true, version: (stdout || stderr).split(/\r?\n/)[0] };
54
+ } catch (error) {
55
+ return { path, available: false, error: error.code === 'ENOENT' ? 'Not installed. Run machinal-scenes setup.' : `Cannot execute tool: ${error.message}` };
56
+ }
57
+ }
58
+
59
+ export async function doctor(options = {}) {
60
+ const paths = toolPaths(options);
61
+ let renderer;
62
+ try { renderer = await probe(await rendererPath(), ['-version']); }
63
+ catch (error) { renderer = { available: false, error: error.message }; }
64
+ const [browser, ffmpeg] = await Promise.all([probe(paths.browser, ['--version']), probe(paths.ffmpeg, ['-version'])]);
65
+ return { ready: renderer.available && browser.available && ffmpeg.available, cacheDirectory: paths.cache, renderer, browser, ffmpeg };
66
+ }
67
+
68
+ export async function setup(options = {}) {
69
+ const paths = toolPaths(options);
70
+ await rendererPath();
71
+ const report = options.onProgress ?? (() => {});
72
+ if (!options.browserExecutable && !process.env.SCENE_BROWSER && !await isInstalled(paths.browser)) {
73
+ report(`Installing Chrome Headless Shell ${browserBuild} (official Chrome for Testing download)...`);
74
+ await install({ browser: Browser.CHROMEHEADLESSSHELL, buildId: browserBuild, cacheDir: join(paths.cache, 'browser'), installDeps: false });
75
+ }
76
+ if (!options.ffmpegExecutable && !process.env.SCENE_FFMPEG) {
77
+ await installFFmpeg(paths.ffmpeg, report);
78
+ }
79
+ const status = await doctor(options);
80
+ if (!status.ready) throw new Error(`Rendering tools are not ready:\n${[status.renderer, status.browser, status.ffmpeg].filter(tool => !tool.available).map(tool => `${tool.path ?? 'renderer'}: ${tool.error}`).join('\n')}\nOn Linux, Chromium also requires system shared libraries; see the README.`);
81
+ return status;
82
+ }
83
+
84
+ async function isInstalled(executable) {
85
+ try { await access(executable); return true; }
86
+ catch (error) { if (error.code === 'ENOENT') return false; throw error; }
87
+ }
88
+
89
+ async function installFFmpeg(executable, report) {
90
+ const target = `${process.platform}-${process.arch}`;
91
+ const hashes = ffmpegReleases[target];
92
+ const directory = dirname(executable);
93
+ try {
94
+ const installed = JSON.parse(await readFile(join(directory, 'installation.json'), 'utf8'));
95
+ if (installed.archiveSHA256 !== hashes.archive || await sha256(executable) !== installed.executableSHA256) throw new Error(`Cached FFmpeg checksum mismatch: ${directory}`);
96
+ if (await sha256(join(directory, 'LICENSE')) !== hashes.license || await sha256(join(directory, 'README')) !== hashes.readme) throw new Error(`Cached FFmpeg license/build information is damaged: ${directory}`);
97
+ return;
98
+ } catch (error) {
99
+ if (error.code !== 'ENOENT') throw error;
100
+ }
101
+ report(`Installing FFmpeg ${ffmpegRelease} (checksum-verified release, including license and build information)...`);
102
+ await mkdir(dirname(directory), { recursive: true });
103
+ const temporary = await mkdtemp(join(dirname(directory), '.install-'));
104
+ const base = `https://github.com/eugeneware/ffmpeg-static/releases/download/${ffmpegRelease}`;
105
+ try {
106
+ await downloadVerified(`${base}/ffmpeg-${target}.gz`, join(temporary, 'ffmpeg.gz'), hashes.archive);
107
+ await downloadVerified(`${base}/${target}.LICENSE`, join(temporary, 'LICENSE'), hashes.license);
108
+ await downloadVerified(`${base}/${target}.README`, join(temporary, 'README'), hashes.readme);
109
+ const binary = join(temporary, process.platform === 'win32' ? 'ffmpeg.exe' : 'ffmpeg');
110
+ await pipeline(createReadStream(join(temporary, 'ffmpeg.gz')), createGunzip(), createWriteStream(binary, { flags: 'wx' }));
111
+ await chmod(binary, 0o755);
112
+ await writeFile(join(temporary, 'installation.json'), JSON.stringify({ archiveSHA256: hashes.archive, executableSHA256: await sha256(binary) }), 'utf8');
113
+ await rm(join(temporary, 'ffmpeg.gz'));
114
+ await rename(temporary, directory);
115
+ } finally {
116
+ await rm(temporary, { recursive: true, force: true });
117
+ }
118
+ }
package/package.json CHANGED
@@ -1,6 +1,91 @@
1
1
  {
2
2
  "name": "@machinal/scenes",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Author, preview and render frame-driven Svelte, HTML and Three.js scenes to MP4 and WebM",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://github.com/catalinfl/machinal-scenes#readme",
7
+ "repository": { "type": "git", "url": "git+https://github.com/catalinfl/machinal-scenes.git" },
8
+ "bugs": { "url": "https://github.com/catalinfl/machinal-scenes/issues" },
9
+ "packageManager": "pnpm@11.9.0",
10
+ "type": "module",
11
+ "types": "./dist/index.d.ts",
12
+ "svelte": "./dist/index.js",
13
+ "bin": { "machinal-scenes": "bin/machinal-scenes.mjs" },
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "svelte": "./dist/index.js",
18
+ "default": "./dist/index.js"
19
+ },
20
+ "./runtime": {
21
+ "types": "./dist/runtime/index.d.ts",
22
+ "import": "./dist/runtime/index.js",
23
+ "default": "./dist/runtime/index.js"
24
+ },
25
+ "./svelte": {
26
+ "types": "./dist/svelte/index.d.ts",
27
+ "svelte": "./dist/svelte/index.js",
28
+ "default": "./dist/svelte/index.js"
29
+ },
30
+ "./node": {
31
+ "types": "./node/index.d.ts",
32
+ "import": "./node/index.mjs"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "files": [
37
+ "bin/",
38
+ "node/",
39
+ "native/",
40
+ "renderer/*.go",
41
+ "renderer/cmd/**/*.go",
42
+ "renderer/go.mod",
43
+ "renderer/go.sum",
44
+ "dist/",
45
+ "examples/quickstart/src/",
46
+ "examples/quickstart/tools/",
47
+ "examples/quickstart/gitignore",
48
+ "examples/quickstart/index.html",
49
+ "examples/quickstart/scene.html",
50
+ "examples/quickstart/scene.config.json",
51
+ "examples/quickstart/package.json",
52
+ "examples/quickstart/tsconfig.json",
53
+ "examples/quickstart/vite.config.js",
54
+ "examples/quickstart/svelte.config.js",
55
+ "LICENSE",
56
+ "NOTICE",
57
+ "LICENSING.md",
58
+ "CHANGELOG.md"
59
+ ],
60
+ "sideEffects": ["**/*.css"],
61
+ "engines": { "node": ">=22.12.0" },
62
+ "keywords": ["svelte", "svelte5", "animation", "motion-graphics", "video", "threejs", "scenes", "frame-driven"],
63
+ "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
64
+ "scripts": {
65
+ "build": "pnpm run build:package",
66
+ "build:package": "pnpm --filter @direction/scene-runtime build && pnpm --filter @direction/scene-svelte build && node scripts/build-package.mjs",
67
+ "build:renderer": "node scripts/build-renderer.mjs",
68
+ "check": "pnpm --filter @direction/scene-runtime check && pnpm --filter @direction/scene-runtime build && pnpm --filter @direction/scene-svelte check",
69
+ "test": "pnpm --filter @direction/scene-runtime build && vitest run",
70
+ "test:package": "pnpm run build:package && pnpm run build:renderer && node --test tests/package.test.mjs",
71
+ "test:cli": "pnpm run build:package && node --test tests/cli.test.mjs tests/local-export.test.mjs",
72
+ "test:go": "go -C renderer test ./...",
73
+ "prepack": "pnpm run build:package && pnpm run build:renderer",
74
+ "prepublishOnly": "pnpm check && pnpm test && pnpm test:cli && pnpm test:go && pnpm test:package"
75
+ },
76
+ "dependencies": {
77
+ "@puppeteer/browsers": "3.2.6",
78
+ "@types/three": "^0.180.0",
79
+ "@webgpu/types": "^0.1.74",
80
+ "three": "^0.180.0"
81
+ },
82
+ "peerDependencies": { "svelte": "^5.15.0" },
83
+ "devDependencies": {
84
+ "@playwright/test": "^1.62.0",
85
+ "@types/node": "^26.1.2",
86
+ "cross-spawn": "^7.0.6",
87
+ "svelte": "^5.15.0",
88
+ "typescript": "^5.9.3",
89
+ "vitest": "^4.1.12"
90
+ }
91
+ }