@biunow/agent-biutalk 0.0.0-stage → 1.1.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 (227) hide show
  1. package/bin/server.js +355 -0
  2. package/engine/AGENTS.md +1414 -0
  3. package/engine/CLAUDE.md +1 -0
  4. package/engine/LICENSE +21 -0
  5. package/engine/README.md +216 -0
  6. package/engine/bin/explainroo.js +19 -0
  7. package/engine/dev/audio-lab.mjs +268 -0
  8. package/engine/docs/media/contact-sheet.jpg +0 -0
  9. package/engine/docs/media/dns-poster.jpg +0 -0
  10. package/engine/docs/media/intro-poster.jpg +0 -0
  11. package/engine/docs/media/logo-dark.png +0 -0
  12. package/engine/docs/media/logo-light.png +0 -0
  13. package/engine/docs/media/looks-dark.webp +0 -0
  14. package/engine/docs/media/looks-light.webp +0 -0
  15. package/engine/docs/media/product-demo.webp +0 -0
  16. package/engine/docs/media/rebase-poster.jpg +0 -0
  17. package/engine/docs/media/sizes-dark.webp +0 -0
  18. package/engine/docs/media/sizes-light.webp +0 -0
  19. package/engine/engine/audio/dsp.js +69 -0
  20. package/engine/engine/audio/instruments.js +147 -0
  21. package/engine/engine/audio/music.js +576 -0
  22. package/engine/engine/audio/pcm.js +93 -0
  23. package/engine/engine/audio/rng.js +40 -0
  24. package/engine/engine/audio/sfx.js +287 -0
  25. package/engine/engine/audio/soundtrack.js +201 -0
  26. package/engine/engine/audio/synth.js +721 -0
  27. package/engine/engine/audio/theory.js +105 -0
  28. package/engine/engine/audio/wav.js +47 -0
  29. package/engine/engine/captions.js +131 -0
  30. package/engine/engine/clips.js +107 -0
  31. package/engine/engine/code.js +179 -0
  32. package/engine/engine/director.js +475 -0
  33. package/engine/engine/frame.html +135 -0
  34. package/engine/engine/icons/LICENSE-lucide.txt +43 -0
  35. package/engine/engine/icons/lucide-tags.json +1 -0
  36. package/engine/engine/icons/lucide.json +1 -0
  37. package/engine/engine/layout.js +69 -0
  38. package/engine/engine/pathdata.js +234 -0
  39. package/engine/engine/pen.js +240 -0
  40. package/engine/engine/player.html +67 -0
  41. package/engine/engine/player.js +219 -0
  42. package/engine/engine/readability.js +9 -0
  43. package/engine/engine/runtime.js +690 -0
  44. package/engine/engine/stage.js +2247 -0
  45. package/engine/engine/studio.html +216 -0
  46. package/engine/engine/text.js +81 -0
  47. package/engine/engine/themes.js +360 -0
  48. package/engine/engine/transitions.js +161 -0
  49. package/engine/engine/ui.js +1042 -0
  50. package/engine/engine/upload.js +32 -0
  51. package/engine/engine/util.js +204 -0
  52. package/engine/examples/callbacks-to-async-await/code-versions.js +34 -0
  53. package/engine/examples/callbacks-to-async-await/scenes.js +106 -0
  54. package/engine/examples/callbacks-to-async-await/script.md +22 -0
  55. package/engine/examples/callbacks-to-async-await/video.json +16 -0
  56. package/engine/examples/circle-area/scenes.js +228 -0
  57. package/engine/examples/circle-area/script.md +37 -0
  58. package/engine/examples/circle-area/video.json +14 -0
  59. package/engine/examples/explainroo-intro/scenes.js +133 -0
  60. package/engine/examples/explainroo-intro/script.md +27 -0
  61. package/engine/examples/explainroo-intro/video.json +8 -0
  62. package/engine/examples/how-dns-works/scenes.js +130 -0
  63. package/engine/examples/how-dns-works/script.md +28 -0
  64. package/engine/examples/how-dns-works/video.json +8 -0
  65. package/engine/examples/leap-years/scenes.js +156 -0
  66. package/engine/examples/leap-years/script.md +25 -0
  67. package/engine/examples/leap-years/video.json +16 -0
  68. package/engine/examples/leap-years-ja/scenes.js +194 -0
  69. package/engine/examples/leap-years-ja/script.md +32 -0
  70. package/engine/examples/leap-years-ja/video.json +17 -0
  71. package/engine/examples/merge-vs-rebase/scenes.js +129 -0
  72. package/engine/examples/merge-vs-rebase/script.md +22 -0
  73. package/engine/examples/merge-vs-rebase/video.json +8 -0
  74. package/engine/examples/password-storage-zh/scenes.js +185 -0
  75. package/engine/examples/password-storage-zh/script.md +25 -0
  76. package/engine/examples/password-storage-zh/video.json +19 -0
  77. package/engine/examples/sqlite-demo/README.md +19 -0
  78. package/engine/examples/sqlite-demo/scenes.js +423 -0
  79. package/engine/examples/sqlite-demo/script.md +35 -0
  80. package/engine/examples/sqlite-demo/video.json +17 -0
  81. package/engine/examples/unspar-demo/assets/fonts/Figtree-400.woff2 +0 -0
  82. package/engine/examples/unspar-demo/assets/fonts/Figtree-500.woff2 +0 -0
  83. package/engine/examples/unspar-demo/assets/fonts/Figtree-600.woff2 +0 -0
  84. package/engine/examples/unspar-demo/assets/fonts/Figtree-700.woff2 +0 -0
  85. package/engine/examples/unspar-demo/assets/fonts/Figtree-OFL.txt +93 -0
  86. package/engine/examples/unspar-demo/assets/unspar-logo.svg +23 -0
  87. package/engine/examples/unspar-demo/scenes.js +367 -0
  88. package/engine/examples/unspar-demo/script.md +25 -0
  89. package/engine/examples/unspar-demo/video.json +21 -0
  90. package/engine/examples/why-is-the-sky-blue-es/scenes.js +160 -0
  91. package/engine/examples/why-is-the-sky-blue-es/script.md +22 -0
  92. package/engine/examples/why-is-the-sky-blue-es/video.json +15 -0
  93. package/engine/fonts/ArchitectsDaughter-400-latin-ext.woff2 +0 -0
  94. package/engine/fonts/ArchitectsDaughter-400-latin.woff2 +0 -0
  95. package/engine/fonts/CabinSketch-400-latin.woff2 +0 -0
  96. package/engine/fonts/CabinSketch-700-latin.woff2 +0 -0
  97. package/engine/fonts/InstrumentSerif-400-italic-latin-ext.woff2 +0 -0
  98. package/engine/fonts/InstrumentSerif-400-italic-latin.woff2 +0 -0
  99. package/engine/fonts/InstrumentSerif-400-normal-latin-ext.woff2 +0 -0
  100. package/engine/fonts/InstrumentSerif-400-normal-latin.woff2 +0 -0
  101. package/engine/fonts/Inter-400-latin-ext.woff2 +0 -0
  102. package/engine/fonts/Inter-400-latin.woff2 +0 -0
  103. package/engine/fonts/JetBrainsMono-400-latin-ext.woff2 +0 -0
  104. package/engine/fonts/JetBrainsMono-400-latin.woff2 +0 -0
  105. package/engine/fonts/Kalam-400-latin-ext.woff2 +0 -0
  106. package/engine/fonts/Kalam-400-latin.woff2 +0 -0
  107. package/engine/fonts/Kalam-700-latin-ext.woff2 +0 -0
  108. package/engine/fonts/Kalam-700-latin.woff2 +0 -0
  109. package/engine/fonts/NotoSansDevanagari-400.ttf +0 -0
  110. package/engine/fonts/NotoSansDevanagari-700.ttf +0 -0
  111. package/engine/fonts/PatrickHand-400-latin-ext.woff2 +0 -0
  112. package/engine/fonts/PatrickHand-400-latin.woff2 +0 -0
  113. package/engine/fonts/PlusJakartaSans-600-latin-ext.woff2 +0 -0
  114. package/engine/fonts/PlusJakartaSans-600-latin.woff2 +0 -0
  115. package/engine/fonts/SpaceGrotesk-500-latin-ext.woff2 +0 -0
  116. package/engine/fonts/SpaceGrotesk-500-latin.woff2 +0 -0
  117. package/engine/fonts/fonts.json +216 -0
  118. package/engine/fonts/licenses/ArchitectsDaughter-OFL.txt +93 -0
  119. package/engine/fonts/licenses/CabinSketch-OFL.txt +93 -0
  120. package/engine/fonts/licenses/InstrumentSerif-OFL.txt +93 -0
  121. package/engine/fonts/licenses/Inter-OFL.txt +93 -0
  122. package/engine/fonts/licenses/JetBrainsMono-OFL.txt +93 -0
  123. package/engine/fonts/licenses/Kalam-OFL.txt +93 -0
  124. package/engine/fonts/licenses/NotoSansDevanagari-OFL.txt +118 -0
  125. package/engine/fonts/licenses/PatrickHand-OFL.txt +93 -0
  126. package/engine/fonts/licenses/PlusJakartaSans-OFL.txt +93 -0
  127. package/engine/fonts/licenses/SpaceGrotesk-OFL.txt +93 -0
  128. package/engine/package-lock.json +1201 -0
  129. package/engine/package.json +67 -0
  130. package/engine/scripts/build-icons.mjs +74 -0
  131. package/engine/scripts/fetch-fonts.mjs +68 -0
  132. package/engine/skills/explainroo/SKILL.md +51 -0
  133. package/engine/src/align.js +357 -0
  134. package/engine/src/browser.js +121 -0
  135. package/engine/src/capture.js +315 -0
  136. package/engine/src/chapters.js +32 -0
  137. package/engine/src/cli.js +421 -0
  138. package/engine/src/clips.js +19 -0
  139. package/engine/src/elevenlabs.js +90 -0
  140. package/engine/src/env.js +16 -0
  141. package/engine/src/export.js +187 -0
  142. package/engine/src/ffmpeg.js +103 -0
  143. package/engine/src/fonts.js +86 -0
  144. package/engine/src/g2p.py +76 -0
  145. package/engine/src/images.js +151 -0
  146. package/engine/src/licenses/misaki-Apache-2.0.txt +201 -0
  147. package/engine/src/math.js +83 -0
  148. package/engine/src/models.js +161 -0
  149. package/engine/src/phonemes.js +162 -0
  150. package/engine/src/pipeline.js +63 -0
  151. package/engine/src/project.js +331 -0
  152. package/engine/src/qa.js +186 -0
  153. package/engine/src/recordings.js +89 -0
  154. package/engine/src/render.js +156 -0
  155. package/engine/src/script.js +266 -0
  156. package/engine/src/server.js +288 -0
  157. package/engine/src/subtitles.js +78 -0
  158. package/engine/src/timeline.js +55 -0
  159. package/engine/src/voice.js +240 -0
  160. package/engine/src/wav.js +98 -0
  161. package/engine/templates/starter/scenes.js +31 -0
  162. package/engine/templates/starter/script.md +14 -0
  163. package/engine/test/align.test.js +108 -0
  164. package/engine/test/brand.test.js +41 -0
  165. package/engine/test/browser.test.js +89 -0
  166. package/engine/test/camera-browser.test.js +225 -0
  167. package/engine/test/caption-phrases.test.js +35 -0
  168. package/engine/test/capture-browser.test.js +90 -0
  169. package/engine/test/capture-fixture.js +46 -0
  170. package/engine/test/capture.test.js +62 -0
  171. package/engine/test/chapters.test.js +41 -0
  172. package/engine/test/cjk-browser.test.js +101 -0
  173. package/engine/test/cjk.test.js +232 -0
  174. package/engine/test/cli-exit.test.js +25 -0
  175. package/engine/test/cli.test.js +116 -0
  176. package/engine/test/clips-browser.test.js +125 -0
  177. package/engine/test/clips.test.js +67 -0
  178. package/engine/test/code-morph-browser.test.js +99 -0
  179. package/engine/test/code-morph.test.js +110 -0
  180. package/engine/test/contrast-browser.test.js +63 -0
  181. package/engine/test/contrast.test.js +80 -0
  182. package/engine/test/director.test.js +316 -0
  183. package/engine/test/engine-pure.test.js +29 -0
  184. package/engine/test/export-browser.test.js +224 -0
  185. package/engine/test/export.test.js +96 -0
  186. package/engine/test/fixtures/capture.html +55 -0
  187. package/engine/test/formats-pace.test.js +104 -0
  188. package/engine/test/languages-browser.test.js +78 -0
  189. package/engine/test/languages.test.js +140 -0
  190. package/engine/test/looks-browser.test.js +109 -0
  191. package/engine/test/looks-preview.test.js +57 -0
  192. package/engine/test/looks.test.js +130 -0
  193. package/engine/test/math-browser.test.js +114 -0
  194. package/engine/test/math.test.js +54 -0
  195. package/engine/test/multi-size-browser.test.js +133 -0
  196. package/engine/test/multi-size.test.js +116 -0
  197. package/engine/test/phonemes.test.js +92 -0
  198. package/engine/test/readability-browser.test.js +36 -0
  199. package/engine/test/readability.test.js +20 -0
  200. package/engine/test/render-options.test.js +52 -0
  201. package/engine/test/script.test.js +67 -0
  202. package/engine/test/server.test.js +256 -0
  203. package/engine/test/stills-browser.test.js +70 -0
  204. package/engine/test/subtitles.test.js +83 -0
  205. package/engine/test/timeline.test.js +31 -0
  206. package/engine/test/transparent-browser.test.js +123 -0
  207. package/engine/test/ui-kit.test.js +96 -0
  208. package/engine/test/upload-browser.test.js +55 -0
  209. package/engine/test/voice-providers.test.js +338 -0
  210. package/lib/host.mjs +480 -0
  211. package/manifest.json +54 -0
  212. package/package.json +8 -4
  213. package/skills/biutalk/SKILL.md +21 -0
  214. package/studio/app.js +209 -0
  215. package/studio/assert-panel-permit.mjs +67 -0
  216. package/studio/composer.css +354 -0
  217. package/studio/composer.js +169 -0
  218. package/studio/index.html +82 -0
  219. package/studio/looks/blueprint.svg +21 -0
  220. package/studio/looks/chalk.svg +15 -0
  221. package/studio/looks/clean.svg +20 -0
  222. package/studio/looks/editorial.svg +18 -0
  223. package/studio/looks/midnight.svg +17 -0
  224. package/studio/looks/paper.svg +11 -0
  225. package/studio/select-menu.js +268 -0
  226. package/studio/styles.css +4 -0
  227. package/README.md +0 -3
@@ -0,0 +1,96 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { copyPlayer, localModules, exportPlayer } from '../src/export.js';
7
+ import { loadProject } from '../src/project.js';
8
+ import { buildTimeline } from '../src/timeline.js';
9
+
10
+ function fixture(t) {
11
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-export-'));
12
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
13
+ fs.mkdirSync(path.join(dir, 'assets'));
14
+ fs.mkdirSync(path.join(dir, 'lib'));
15
+ fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ theme: 'clean', _private: 'SECRET', images: { style: 'PRIVATE NOTES' }, fonts: [{ family: 'Own', src: 'assets/own.woff2' }, { family: 'Unused', src: 'assets/unused.woff2' }] }));
16
+ fs.writeFileSync(path.join(dir, 'script.md'), '## intro {min=3}\n');
17
+ fs.writeFileSync(path.join(dir, 'scenes.js'), "import { draw } from './lib/draw.mjs'; export default { intro: draw };");
18
+ fs.writeFileSync(path.join(dir, 'lib/draw.mjs'), "export { draw } from '../helper.js';");
19
+ fs.writeFileSync(path.join(dir, 'helper.js'), 'export function draw(s) { s.title("Hello"); }');
20
+ for (const name of ['used.svg', 'unused.svg', 'own.woff2', 'unused.woff2', '.env', 'secret.json', 'notes.txt', 'notes.md']) fs.writeFileSync(path.join(dir, 'assets', name), name.includes('svg') ? '<svg xmlns="http://www.w3.org/2000/svg"/>' : 'SECRET');
21
+ fs.writeFileSync(path.join(dir, '.env'), 'SECRET');
22
+ fs.mkdirSync(path.join(dir, 'build/clips'), { recursive: true });
23
+ fs.writeFileSync(path.join(dir, 'build/clips/frame.jpg'), 'extracted');
24
+ const project = loadProject(dir);
25
+ return { dir, project, timeline: buildTimeline(project, {}) };
26
+ }
27
+
28
+ function files(dir) { return fs.readdirSync(dir, { recursive: true }).filter(f => fs.statSync(path.join(dir, f)).isFile()).map(f => f.split(path.sep).join('/')).sort(); }
29
+
30
+ test('player copies only used assets, font families and local modules, with public state', t => {
31
+ const { dir, project, timeline } = fixture(t);
32
+ const out = path.join(dir, 'player');
33
+ const math = { '["x",true]': { paths: ['M0 0'], viewBox: [0, 0, 1, 1] } };
34
+ copyPlayer(project, timeline, { assets: ['assets/used.svg', 'assets/own.woff2'], fonts: ['Inter', 'Own'], math }, out);
35
+ const names = files(out);
36
+ for (const name of ['index.html', 'engine/player.js', 'engine/runtime.js', 'vendor/rough.js', 'engine/icons/lucide.json', 'project/scenes.js', 'project/lib/draw.mjs', 'project/helper.js', 'project/assets/used.svg', 'project/assets/own.woff2', 'state.json', 'math.json', 'subtitles.vtt']) assert.ok(names.includes(name), name);
37
+ assert.deepEqual(names.filter(n => n.startsWith('project/assets/')), ['project/assets/own.woff2', 'project/assets/used.svg']);
38
+ assert.ok(!names.some(n => /build|\.env|secret|notes|unused|soundtrack|upload/.test(n)));
39
+ const manifest = JSON.parse(fs.readFileSync(path.join(out, 'fonts/fonts.json'), 'utf8'));
40
+ assert.deepEqual([...new Set(manifest.map(f => f.family))], ['Inter']);
41
+ assert.deepEqual(names.filter(n => n.startsWith('fonts/') && n.endsWith('.woff2')).sort(), [...new Set(manifest.map(f => 'fonts/' + f.file))].sort());
42
+ const state = JSON.parse(fs.readFileSync(path.join(out, 'state.json'), 'utf8'));
43
+ assert.deepEqual(Object.keys(state).sort(), ['assets', 'config', 'timeline', 'title', 'version']);
44
+ assert.deepEqual(state.assets, ['assets/used.svg']);
45
+ assert.deepEqual(state.config.fonts.map(f => f.family), ['Own']);
46
+ assert.deepEqual(state.timeline, timeline);
47
+ assert.match(state.version, /^[a-f\d]{12}$/);
48
+ assert.ok(!JSON.stringify(state).includes('SECRET'));
49
+ assert.ok(!JSON.stringify(state).includes('PRIVATE NOTES'));
50
+ assert.deepEqual(JSON.parse(fs.readFileSync(path.join(out, 'math.json'), 'utf8')), math);
51
+ const html = fs.readFileSync(path.join(out, 'index.html'), 'utf8');
52
+ for (const [, url] of html.matchAll(/(?:src|href)="([^"]+)"/g)) assert.ok(url.startsWith('./'), url);
53
+ assert.ok(!html.includes('http:') && !html.includes('https:'));
54
+ });
55
+
56
+ test('player ships the Hindi fallback font only when the video draws Hindi', t => {
57
+ const { dir, project, timeline } = fixture(t);
58
+ const families = text => {
59
+ const out = path.join(dir, 'player-' + text.length);
60
+ copyPlayer(project, timeline, { assets: [], fonts: ['Inter', 'Noto Sans Devanagari'], math: {}, text }, out);
61
+ return [...new Set(JSON.parse(fs.readFileSync(path.join(out, 'fonts/fonts.json'), 'utf8')).map(f => f.family))];
62
+ };
63
+ assert.deepEqual(families('Hello'), ['Inter']);
64
+ assert.deepEqual(families('नमस्ते'), ['Inter', 'Noto Sans Devanagari']);
65
+ });
66
+
67
+ test('export follows local imports, refusing private files, outside symlinks and remote modules', t => {
68
+ const { dir, project, timeline } = fixture(t);
69
+ assert.deepEqual([...localModules(dir).keys()], ['scenes.js', 'lib/draw.mjs', 'helper.js']);
70
+ fs.writeFileSync(path.join(dir, 'scenes.js'), `// import 'https://example.com/no.js';
71
+ const label = "import './missing.js'";
72
+ /* export { draw } from './private.js'; */
73
+ import('./lib/draw.mjs?v=1'); export default {};`);
74
+ assert.deepEqual([...localModules(dir).keys()], ['scenes.js', 'lib/draw.mjs', 'helper.js']);
75
+ const out = path.join(dir, 'player');
76
+ for (const rel of ['assets/.env', 'assets/secret.json', 'assets/notes.txt', '../outside.png']) assert.throws(() => copyPlayer(project, timeline, { assets: [rel], fonts: [], math: {} }, out), /cannot be exported/);
77
+ fs.symlinkSync(path.join(dir, '.env'), path.join(dir, 'assets/fake.png'));
78
+ assert.throws(() => copyPlayer(project, timeline, { assets: ['assets/fake.png'], fonts: [], math: {} }, out), /cannot be exported/);
79
+ fs.symlinkSync(path.join(os.tmpdir(), 'outside.js'), path.join(dir, 'outside.js'));
80
+ fs.writeFileSync(path.join(dir, 'scenes.js'), "import 'https://example.com/scenes.js';");
81
+ assert.throws(() => localModules(dir), /relative local import/);
82
+ fs.writeFileSync(path.join(dir, 'scenes.js'), "import '/absolute/scenes.js';");
83
+ assert.throws(() => localModules(dir), /relative local import/);
84
+ fs.writeFileSync(path.join(dir, 'scenes.js'), "import('./.private.js');");
85
+ assert.throws(() => localModules(dir), /cannot be exported/);
86
+ });
87
+
88
+ test('export leaves a non-player output folder alone', async t => {
89
+ const { dir, project } = fixture(t);
90
+ const out = path.join(dir, 'keep');
91
+ fs.mkdirSync(out);
92
+ fs.writeFileSync(path.join(out, 'notes.txt'), 'Keep me');
93
+ await assert.rejects(exportPlayer(project, { out }), /Choose an empty folder/);
94
+ assert.equal(fs.readFileSync(path.join(out, 'notes.txt'), 'utf8'), 'Keep me');
95
+ assert.equal(fs.existsSync(path.join(dir, 'build/voice')), false);
96
+ });
@@ -0,0 +1,55 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Fixture Studio</title>
7
+ <meta name="description" content="A local page for capture tests.">
8
+ <meta name="theme-color" content="#245cff">
9
+ <meta property="og:site_name" content="Fixture">
10
+ <meta property="og:image" content="/social.png">
11
+ <link rel="icon" type="image/svg+xml" href="/icon.svg">
12
+ <link rel="apple-touch-icon" href="/touch.png">
13
+ <link rel="stylesheet" href="__FONT_CSS__">
14
+ <style>
15
+ * { box-sizing: border-box; }
16
+ body { margin: 0; background: #f8f6f1; color: #202020; font-family: 'Fixture Sans', sans-serif; font-weight: 400; }
17
+ header { display: flex; align-items: center; justify-content: space-between; padding: 28px 6%; border-bottom: 1px solid #dedcd6; }
18
+ .logo { display: flex; align-items: center; gap: 12px; color: #245cff; text-decoration: none; font-size: 24px; }
19
+ nav { display: flex; gap: 24px; }
20
+ a { color: #245cff; }
21
+ main { padding: 55px 8%; }
22
+ h1, h2 { color: #163469; font-weight: 400; }
23
+ h1 { font-size: 54px; max-width: 680px; margin: 12px 0; }
24
+ h2 { font-size: 32px; }
25
+ p { font-size: 22px; line-height: 1.5; }
26
+ button, .button { font: 400 18px 'Fixture Sans', sans-serif; color: white; background: #245cff; border: none; border-radius: 8px; padding: 16px 24px; display: inline-block; text-decoration: none; }
27
+ form { display: grid; max-width: 460px; gap: 14px; margin: 34px 0; }
28
+ label { font-size: 18px; }
29
+ input { font: inherit; font-size: 18px; padding: 16px; background: white; border: 1px solid #ccc; border-radius: 8px; }
30
+ .hidden { display: none; }
31
+ .footer { margin-top: 40px; height: 8100px; background: #e9eef8; padding: 24px; }
32
+ @media (max-width: 600px) { header { align-items: flex-start; flex-direction: column; gap: 20px; } h1 { font-size: 36px; } main { padding: 32px 6%; } }
33
+ </style>
34
+ </head>
35
+ <body>
36
+ <header>
37
+ <a class="logo" href="/" aria-label="Fixture home">
38
+ <svg class="logo" aria-label="Fixture logo" width="42" height="42" viewBox="0 0 42 42"><rect x="2" y="2" width="38" height="38" rx="10" fill="currentColor"/><path d="M12 14h19M12 21h15M12 28h10" stroke="white" stroke-width="3"/></svg>
39
+ Fixture Studio
40
+ </a>
41
+ <nav aria-label="Main navigation"><a href="#features">Features</a><a href="#plans">Plans</a><a href="#features">Features</a></nav>
42
+ </header>
43
+ <main>
44
+ <h1>Build a clear product demo</h1>
45
+ <p>Keep your colors, fonts and wording together.</p>
46
+ <button>Start a project</button>
47
+ <a class="button" href="#features">See examples</a>
48
+ <h2 id="features">Your brand on every screen</h2>
49
+ <form><label for="name">Project name</label><input id="name" placeholder="My first demo"><button type="submit">Create project</button></form>
50
+ <button class="hidden">Hidden action</button><input class="hidden" placeholder="Hidden placeholder">
51
+ <h2 id="plans">Capture once, use the files</h2>
52
+ <div class="footer">A long page checks the screenshot height limit.</div>
53
+ </main>
54
+ </body>
55
+ </html>
@@ -0,0 +1,104 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { parseScript, speechChunks } from '../src/script.js';
4
+ import { normalizeConfig, resolveSize, FORMATS, ProjectError } from '../src/project.js';
5
+ import { buildTimeline } from '../src/timeline.js';
6
+ import { layoutAreas } from '../engine/layout.js';
7
+
8
+ const close = (a, b) => assert.ok(Math.abs(a - b) < 1e-9, `${a} is not ${b}`);
9
+
10
+ test('named formats resolve to their size and safe area', () => {
11
+ assert.deepEqual(resolveSize('youtube'), { width: 1920, height: 1080, safe: null });
12
+ assert.equal(resolveSize('tiktok').height, 1920);
13
+ assert.ok(resolveSize('tiktok').safe.bottom > 0.3);
14
+ assert.deepEqual(resolveSize('linkedin'), { width: 1080, height: 1350, safe: null });
15
+ const cfg = normalizeConfig({ size: 'reels' });
16
+ assert.equal(cfg.format, 'reels');
17
+ assert.equal(cfg.captions, true);
18
+ assert.deepEqual(cfg.safe, FORMATS.reels.safe);
19
+ assert.equal(normalizeConfig({ size: '9:16' }).safe, null);
20
+ assert.throws(() => normalizeConfig({ size: 'myspace' }), ProjectError);
21
+ });
22
+
23
+ test('platform safe area keeps content above the captions and clear of the buttons', () => {
24
+ const cfg = normalizeConfig({ size: 'tiktok' });
25
+ const { safe, captions, app } = layoutAreas(cfg, 1080, 1920);
26
+ assert.equal(app.bottom, 1920 - Math.round(1920 * FORMATS.tiktok.safe.bottom));
27
+ assert.ok(captions.bottom < app.bottom);
28
+ assert.ok(safe.bottom < captions.bottom - 150);
29
+ assert.equal(safe.right, 1080 - Math.round(1080 * FORMATS.tiktok.safe.right));
30
+ const plain = layoutAreas(normalizeConfig({ size: '16:9' }), 1920, 1080);
31
+ assert.equal(plain.captions, null);
32
+ assert.equal(plain.band, null);
33
+ assert.equal(plain.safe.left, Math.round(1080 * 0.07));
34
+ });
35
+
36
+ test('captions on feed sizes sit at the bottom, clear of the watermark and the content area', () => {
37
+ for (const size of ['linkedin', 'square', 'instagram']) {
38
+ const cfg = normalizeConfig({ size });
39
+ const { safe, band } = layoutAreas(cfg, cfg.width, cfg.height);
40
+ const wm = Math.round(Math.min(cfg.width, cfg.height) * 0.028);
41
+ assert.ok(band, size);
42
+ assert.ok(band.bottom <= cfg.height - wm - Math.round(wm * 1.6), `${size}: captions reach the watermark`);
43
+ assert.ok(safe.bottom < band.top, `${size}: content area overlaps the captions`);
44
+ }
45
+ const noCaptions = normalizeConfig({ size: 'linkedin', captions: false });
46
+ assert.equal(layoutAreas(noCaptions, 1080, 1350).safe.bottom, 1350 - Math.round(1080 * 0.07));
47
+ });
48
+
49
+ test('pace must stay in range and must not make the voice too fast', () => {
50
+ assert.equal(normalizeConfig({}).pace, 1);
51
+ assert.equal(normalizeConfig({ pace: 1.3 }).pace, 1.3);
52
+ assert.throws(() => normalizeConfig({ pace: 3 }), ProjectError);
53
+ assert.throws(() => normalizeConfig({ speed: 1.5, pace: 1.3 }), ProjectError);
54
+ assert.equal(normalizeConfig({ pace: 1.44 }).music.tempo, 1.2);
55
+ });
56
+
57
+ test('pace shortens pauses between sentences and explicit pauses', () => {
58
+ const { scenes } = parseScript('## a\nOne. Two. [pause 1] Three.');
59
+ const normal = speechChunks(scenes[0].units, { sentenceGap: 0.3 });
60
+ const fast = speechChunks(scenes[0].units, { sentenceGap: 0.3, pace: 1.5 });
61
+ assert.equal(normal[1].gapBefore, 0.3);
62
+ close(fast[1].gapBefore, 0.2);
63
+ assert.ok(Math.abs(normal[2].gapBefore - 1.3) < 1e-9);
64
+ assert.ok(Math.abs(fast[2].gapBefore - 1.3 / 1.5) < 1e-9);
65
+ });
66
+
67
+ test('pace shortens lead-ins, holds and transitions', () => {
68
+ const src = '## a\nHi.\n\n## b {min=3}\n';
69
+ const voice = { a: { duration: 1, words: [{ text: 'Hi.', start: 0, end: 1 }], marks: {}, chunks: [{ start: 0, end: 1 }] } };
70
+ const cfg = { fps: 30, lead: 0.3, hold: 0.6, end: 0 };
71
+ const normal = buildTimeline({ config: normalizeConfig(cfg), script: parseScript(src) }, voice);
72
+ const fast = buildTimeline({ config: normalizeConfig({ ...cfg, pace: 1.5 }), script: parseScript(src) }, voice);
73
+ assert.equal(normal.scenes[0].dur, Math.round((0.3 + 1 + 0.6) * 30) / 30);
74
+ assert.equal(fast.scenes[0].dur, Math.round((0.2 + 1 + 0.4) * 30) / 30);
75
+ close(fast.scenes[0].words[0].start, 0.2);
76
+ assert.equal(fast.scenes[1].dur, 2);
77
+ assert.ok(fast.transitionSeconds < normal.transitionSeconds);
78
+ assert.equal(fast.pace, 1.5);
79
+ });
80
+
81
+ test('in a scene, times stay real seconds and pace shortens animations', async () => {
82
+ const { Stage } = await import('../engine/stage.js');
83
+ const { getTheme } = await import('../engine/themes.js');
84
+ const cfg = normalizeConfig({ pace: 1.6 });
85
+ const engine = {
86
+ config: cfg,
87
+ theme: getTheme('paper'),
88
+ pen: null,
89
+ W: 1920,
90
+ H: 1080,
91
+ fps: 30,
92
+ safeArea: layoutAreas(cfg, 1920, 1080).safe,
93
+ timeline: { pace: 1.6, duration: 10, frames: 300, fps: 30, width: 1920, height: 1080, scenes: [{}] },
94
+ recorder: null,
95
+ };
96
+ const scene = { id: 'a', index: 0, start: 0, dur: 10, lead: 0.2, words: [{ text: 'hello', start: 1, end: 1.4 }], marks: { go: 3 }, voice: { dur: 2 } };
97
+ const s = new Stage(engine, null, scene, 1.5);
98
+ assert.equal(s.time(4), 4);
99
+ assert.equal(s.time('hello') + 0.3, 1.3);
100
+ assert.equal(s.time('#go'), 3);
101
+ assert.equal(s.p(1, 0.8), 1); // 0.8 s at pace 1.6 takes 0.5 s, so it is done at 1.5
102
+ close(s.p(1, 1.6), 0.5); // halfway through 1 s of real time
103
+ assert.equal(s.pace, 1.6);
104
+ });
@@ -0,0 +1,78 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { findChrome } from '../src/browser.js';
7
+ import { loadProject, THEMES } from '../src/project.js';
8
+ import { buildTimeline } from '../src/timeline.js';
9
+ import { withEngine } from '../src/pipeline.js';
10
+
11
+ let chrome;
12
+ try { chrome = findChrome(); } catch {}
13
+
14
+ const sentences = [
15
+ '¿Qué pasó? ¡El niño llegó al café!',
16
+ 'La sœur prépare une leçon en français.',
17
+ 'La città è bella e il caffè è pronto.',
18
+ 'Não há açúcar, mas os pães são bons.',
19
+ 'हिन्दी में शब्दों और तस्वीरों से जानकारी समझाएँ।',
20
+ ];
21
+
22
+ test('every look uses bundled fonts for all five languages, including Devanagari in captions and UI', { skip: !chrome }, async t => {
23
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-language-fonts-'));
24
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
25
+ fs.writeFileSync(path.join(dir, 'script.md'), '## demo {min=3}');
26
+ fs.writeFileSync(path.join(dir, 'scenes.js'), `export default { demo(s) { s.title('Qué', { at: 0 }); } };`);
27
+ for (const theme of THEMES) {
28
+ fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ theme, captions: true, sfx: false }));
29
+ const project = loadProject(dir);
30
+ await withEngine(project, buildTimeline(project, {}), {}, async page => {
31
+ const cdp = await page.context().newCDPSession(page);
32
+ await cdp.send('DOM.enable');
33
+ await cdp.send('CSS.enable');
34
+ const { root } = await cdp.send('DOM.getDocument');
35
+ await page.evaluate(async ([sentences, theme]) => {
36
+ const { getTheme, fontString } = await import('/engine/themes.js');
37
+ const { UI } = await import('/engine/ui.js');
38
+ const fonts = ['display', 'body', 'hand', 'mono'].map(role => fontString(getTheme(theme), role, 48));
39
+ fonts.push(UI.prototype.fontString.call({ font: 'Inter' }, 48));
40
+ let i = 0;
41
+ for (const font of fonts) for (const sentence of sentences) {
42
+ const span = document.createElement('div');
43
+ span.id = 'glyph' + i++;
44
+ span.style.font = font;
45
+ span.textContent = sentence;
46
+ document.body.append(span);
47
+ }
48
+ await new Promise(resolve => requestAnimationFrame(resolve));
49
+ }, [sentences, theme]);
50
+ for (let i = 0; i < 25; i++) {
51
+ const { nodeId } = await cdp.send('DOM.querySelector', { nodeId: root.nodeId, selector: '#glyph' + i });
52
+ const { fonts } = await cdp.send('CSS.getPlatformFontsForNode', { nodeId });
53
+ assert.ok(fonts.length, `${theme} sentence ${i}`);
54
+ assert.ok(fonts.every(f => f.isCustomFont), `${theme} sentence ${i}: ${JSON.stringify(fonts)}`);
55
+ if (i % 5 === 4) assert.ok(fonts.some(f => f.familyName === 'Noto Sans Devanagari'), `${theme} Hindi fallback`);
56
+ }
57
+ });
58
+ }
59
+ });
60
+
61
+ test('accented and Hindi cue words resolve to their spoken times in the page', { skip: !chrome }, async t => {
62
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-language-cues-'));
63
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
64
+ fs.writeFileSync(path.join(dir, 'video.json'), '{}');
65
+ fs.writeFileSync(path.join(dir, 'script.md'), '## demo\nQué cœur pão città फ़ाइलें');
66
+ fs.writeFileSync(path.join(dir, 'scenes.js'), `export default { demo(s) {
67
+ s.text('Qué', { y: 200, at: 'qué' }); s.text('cœur', { y: 300, at: 'CŒUR' });
68
+ s.text('pão', { y: 400, at: 'PÃO' }); s.text('città', { y: 500, at: 'CITTÀ' });
69
+ s.text('फ़ाइलें', { y: 600, at: 'फ़ाइलें' });
70
+ } };`);
71
+ const project = loadProject(dir);
72
+ const words = project.script.scenes[0].units.map((u, i) => ({ text: u.display, start: i * 0.5, end: (i + 1) * 0.5 }));
73
+ const timeline = buildTimeline(project, { demo: { duration: 2.5, words, marks: {} } });
74
+ await withEngine(project, timeline, {}, async page => {
75
+ const result = await page.evaluate(() => window.explainroo.check());
76
+ assert.deepEqual(result.filter(i => i.level === 'error'), []);
77
+ });
78
+ });
@@ -0,0 +1,140 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import crypto from 'node:crypto';
7
+ import { normWord, parseScript, speechChunks, tokenizeNarration } from '../src/script.js';
8
+ import { normWord as browserNorm } from '../engine/util.js';
9
+ import { alignWords, expand } from '../src/align.js';
10
+ import { normalizeConfig, ProjectError } from '../src/project.js';
11
+ import { VOICES, LANGUAGES, voiceLanguage, asrModel, ASR_MODEL, MULTILINGUAL_ASR_MODEL, TTS_MODEL, ttsDtype } from '../src/models.js';
12
+ import { sceneHash } from '../src/voice.js';
13
+ import { recordingCuts } from '../src/recordings.js';
14
+ import { subtitleCues, toSrt, toVtt } from '../src/subtitles.js';
15
+ import { buildPhrases } from '../engine/captions.js';
16
+ import { main } from '../src/cli.js';
17
+
18
+ test('word normalization keeps letters, marks and numbers across scripts, with the existing accent rules', () => {
19
+ for (const [word, expected] of [
20
+ ['Qué', 'que'], ['¿NIÑO?', 'nino'], ['français', 'francais'], ['cœur', 'cœur'],
21
+ ['ação', 'acao'], ['pão', 'pao'], ['città', 'citta'], ['हिन्दी।', 'हिन्दी'],
22
+ ['फ़ाइलें', 'फ़ाइलें'], ['१२३', '१२३'], ['किंतु', 'किंतु'], ['देवनागरी', 'देवनागरी'],
23
+ ["Visitor’s", 'visitors'], ['example.com.', 'example.com'], ['$1,050.50', '$1050.50'], ['API+#@', 'api+#@'],
24
+ ]) {
25
+ assert.equal(normWord(word), expected, word);
26
+ assert.equal(browserNorm(word), expected, word);
27
+ assert.equal(normWord(word.normalize('NFD')), expected, word);
28
+ }
29
+ });
30
+
31
+ test('sentence boundaries include danda and Spanish question and exclamation marks', () => {
32
+ const words = tokenizeNarration('¿Qué pasa? ¡Todo bien! \"यह अच्छा है।\" फिर चलें।');
33
+ const chunks = speechChunks(words);
34
+ assert.deepEqual(chunks.map(c => c.text), ['¿Qué pasa?', '¡Todo bien!', '\"यह अच्छा है।\"', 'फिर चलें।']);
35
+ assert.deepEqual(chunks.map(c => c.gapBefore), [0, 0.3, 0.3, 0.3]);
36
+ assert.equal(tokenizeNarration('एक {दो|दो}।').length, 2);
37
+ });
38
+
39
+ test('each language picks its default and rejects every voice from a different language', () => {
40
+ assert.equal(normalizeConfig({}).language, 'en');
41
+ for (const [language, id] of Object.entries(LANGUAGES)) {
42
+ assert.equal(normalizeConfig({ language }).voice, id);
43
+ assert.equal(normalizeConfig({ language, voice: { provider: 'kokoro', id } }).voice, id);
44
+ for (const voice of Object.keys(VOICES)) {
45
+ if (voiceLanguage(voice) === language) assert.equal(normalizeConfig({ language, voice }).voice, voice);
46
+ else assert.throws(() => normalizeConfig({ language, voice }), e => e instanceof ProjectError && e.message.includes(id));
47
+ }
48
+ for (const voice of [{ provider: 'elevenlabs', id: 'sample' }, { provider: 'recording', src: 'assets/take.wav' }]) {
49
+ assert.equal(normalizeConfig({ language, voice }).language, language);
50
+ }
51
+ assert.equal(asrModel(language), language === 'en' ? ASR_MODEL : MULTILINGUAL_ASR_MODEL);
52
+ }
53
+ for (const language of ['ko', 'pt', '', 'EN', 'toString', null, true, ['es']]) assert.throws(() => normalizeConfig({ language }), /language must be one of/);
54
+ });
55
+
56
+ test('non-English numbers stay digits, including Devanagari, and are never fuzzy matched or spelled out', () => {
57
+ for (const language of ['es', 'fr', 'it', 'pt-br', 'hi']) {
58
+ assert.deepEqual(expand('1,050', language), ['1050']);
59
+ assert.deepEqual(expand('€1.050', language), ['1050']);
60
+ assert.deepEqual(expand('१२%', language), ['12']);
61
+ assert.deepEqual(expand('twenty', language), ['twenty']);
62
+ const r = alignWords([{ spoken: '१२३' }, { spoken: '1050' }], [{ text: '123', start: 0, end: 0.5 }, { text: '1,050', start: 0.5, end: 1 }], 1, language);
63
+ assert.equal(r.matchRate, 1);
64
+ assert.equal(alignWords([{ spoken: '1234' }], [{ text: '1235', start: 0, end: 1 }], 1, language).matchRate, 0);
65
+ assert.equal(alignWords([{ spoken: 'twenty' }], [{ text: '20', start: 0, end: 1 }], 1, language).matchRate, 0);
66
+ }
67
+ assert.deepEqual(expand('twenty'), ['20']);
68
+ });
69
+
70
+ test('Hindi recording cuts use the same language rules as per-scene alignment', () => {
71
+ const scenes = parseScript('## first\n१२३\n## second\nफ़ाइलें').scenes;
72
+ const cuts = recordingCuts(scenes, [{ text: '123', start: 0.2, end: 0.5 }, { text: 'फ़ाइलें', start: 1, end: 1.5 }], 2, 'hi');
73
+ assert.ok(cuts.every(c => c.words[0].matched));
74
+ });
75
+
76
+ test('English cache hashes keep the previous format; other languages are part of the cache', () => {
77
+ const scene = parseScript('## first\n[#a] Hello. Goodbye.').scenes[0];
78
+ const chunks = speechChunks(scene.units);
79
+ const config = normalizeConfig({});
80
+ const previous = crypto.createHash('sha256').update(JSON.stringify({
81
+ PIPELINE: 7, TTS_MODEL, ASR_MODEL, dtype: ttsDtype(), voice: config.voice, speed: config.speed * config.pace,
82
+ chunks: chunks.map(c => [c.gapBefore, c.text]),
83
+ layout: scene.units.map(u => u.type === 'mark' ? `#${u.name}` : u.type === 'word' ? u.display : '').join('|'),
84
+ })).digest('hex').slice(0, 16);
85
+ assert.equal(sceneHash(scene, chunks, config), previous);
86
+ assert.equal(sceneHash(scene, chunks, { ...config, language: undefined }), previous);
87
+ const voice = { provider: 'recording', src: 'assets/take.wav' };
88
+ assert.notEqual(sceneHash(scene, chunks, normalizeConfig({ language: 'fr', voice })), sceneHash(scene, chunks, normalizeConfig({ language: 'es', voice })));
89
+ });
90
+
91
+ test('captions and subtitle files keep native text and split at danda', () => {
92
+ for (const text of ['¿Qué pasó?', 'Le cœur écoute.', 'La città è bella.', 'Não há açúcar.', 'यह अच्छा है। फिर चलें।']) {
93
+ const words = text.split(' ').map((text, i) => ({ text, start: i * 0.2, end: (i + 1) * 0.2 }));
94
+ const timeline = { scenes: [{ start: 0, dur: 10, words }] };
95
+ const cues = subtitleCues(timeline);
96
+ assert.equal(cues.map(c => c.text.replaceAll('\n', ' ')).join(' '), text);
97
+ assert.ok(toSrt(cues).includes(text.split(' ')[0]));
98
+ assert.ok(toVtt(cues).includes(text.split(' ')[0]));
99
+ if (text.includes('।')) {
100
+ assert.equal(cues.length, 2);
101
+ assert.equal(buildPhrases(timeline, 80).length, 2);
102
+ }
103
+ }
104
+ });
105
+
106
+ test('init stores the language and default voice; voices filters and doctor allows missing espeak-ng and misaki', async t => {
107
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-language-cli-'));
108
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
109
+ let output = '';
110
+ let errors = '';
111
+ t.mock.method(process.stdout, 'write', s => { output += s; return true; });
112
+ t.mock.method(process.stderr, 'write', s => { errors += s; return true; });
113
+ assert.equal(await main(['init', path.join(dir, 'video'), '--language', 'es', '--json']), 0);
114
+ const config = JSON.parse(fs.readFileSync(path.join(dir, 'video/video.json')));
115
+ assert.equal(config.language, 'es');
116
+ assert.equal(config.voice, 'ef_dora');
117
+ for (const flags of [['--language', 'ko'], ['--language'], ['--language', 'es', '--voice', 'af_heart']]) {
118
+ assert.equal(await main(['init', path.join(dir, 'bad'), ...flags]), 1);
119
+ assert.equal(fs.existsSync(path.join(dir, 'bad')), false);
120
+ }
121
+ assert.match(errors, /--language needs a value/);
122
+ output = '';
123
+ assert.equal(await main(['voices', '--language', 'es', '--json']), 0);
124
+ const list = JSON.parse(output);
125
+ assert.deepEqual(Object.keys(list.voices), ['ef_dora', 'em_alex', 'em_santa']);
126
+ assert.equal(list.languages.ef_dora, 'es');
127
+ const saved = process.env.EXPLAINROO_ESPEAK;
128
+ process.env.EXPLAINROO_ESPEAK = path.join(dir, 'missing');
129
+ t.after(() => { if (saved === undefined) delete process.env.EXPLAINROO_ESPEAK; else process.env.EXPLAINROO_ESPEAK = saved; });
130
+ output = '';
131
+ assert.equal(await main(['doctor', '--json']), 0);
132
+ assert.match(JSON.parse(output).checks.find(c => c.name === 'espeak-ng').detail, /only needed for Spanish, French, Italian, Portuguese and Hindi/);
133
+ const python = process.env.EXPLAINROO_PYTHON;
134
+ process.env.EXPLAINROO_PYTHON = path.join(dir, 'missing');
135
+ t.after(() => { if (python === undefined) delete process.env.EXPLAINROO_PYTHON; else process.env.EXPLAINROO_PYTHON = python; });
136
+ output = '';
137
+ assert.equal(await main(['doctor', '--json']), 0);
138
+ const misaki = JSON.parse(output).checks.filter(c => c.name.startsWith('misaki'));
139
+ assert.deepEqual(misaki.map(c => [c.name, c.ok, c.detail]), [['misaki ja', true, 'not found; only needed for Japanese'], ['misaki zh', true, 'not found; only needed for Chinese']]);
140
+ });
@@ -0,0 +1,109 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { findChrome } from '../src/browser.js';
7
+ import { loadProject } from '../src/project.js';
8
+ import { withEngine } from '../src/pipeline.js';
9
+ import { buildTimeline } from '../src/timeline.js';
10
+
11
+ let chrome;
12
+ try { chrome = findChrome(); } catch {}
13
+
14
+ function fixture(t, look) {
15
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-look-browser-'));
16
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
17
+ fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ theme: 'look.json', captions: false, sfx: false, fonts: [{ family: 'Figtree', src: 'assets/font.woff2', weight: 700 }] }));
18
+ fs.writeFileSync(path.join(dir, 'look.json'), JSON.stringify(look));
19
+ fs.mkdirSync(path.join(dir, 'assets'));
20
+ fs.copyFileSync(new URL('../examples/unspar-demo/assets/fonts/Figtree-700.woff2', import.meta.url), path.join(dir, 'assets/font.woff2'));
21
+ fs.writeFileSync(path.join(dir, 'script.md'), '## demo {min=2}\n\n## end {min=2}');
22
+ fs.writeFileSync(path.join(dir, 'scenes.js'), `export default {
23
+ demo(s) { s.text('Custom look', { y: 400, at: 0, size: 80 }); s.box('Example', { y: 650, at: 1 }); },
24
+ end(s) { s.circle({ x: 960, y: 540, r: 100, at: 0 }); }
25
+ };`);
26
+ const project = loadProject(dir);
27
+ return { dir, project, timeline: buildTimeline(project, {}) };
28
+ }
29
+
30
+ test('the page builds the custom look, loads its font and uses its transition without serving its JSON', { skip: !chrome }, async t => {
31
+ const { project, timeline } = fixture(t, { extends: 'clean', dark: true, bg: '#152337', ink: '#ffffff', muted: '#c9d1cb', background: 'glow', transition: 'fade', music: 'calm', fonts: { body: { family: 'Figtree', weight: 700 } } });
32
+ await withEngine(project, timeline, {}, async page => {
33
+ const result = await page.evaluate(async () => {
34
+ const { fetchState, Engine } = await import('/engine/runtime.js');
35
+ const { getTheme } = await import('/engine/themes.js');
36
+ const state = await fetchState();
37
+ const theme = getTheme(state.config.theme, state.config.look);
38
+ window.explainroo.frames([45, 61]);
39
+ return {
40
+ theme, music: state.config.music.style,
41
+ transition: Engine.prototype.transitionFor.call({ theme }, state.timeline.scenes[1]),
42
+ explicit: Engine.prototype.transitionFor.call({ theme }, { transition: 'cut' }),
43
+ font: document.fonts.check('700 40px Figtree'),
44
+ fetched: performance.getEntriesByType('resource').some(r => r.name.endsWith('/project/look.json')),
45
+ status: (await fetch('/project/look.json')).status,
46
+ issues: window.explainroo.check(),
47
+ };
48
+ });
49
+ assert.equal(result.theme.background, 'glow');
50
+ assert.equal(result.theme.bg, '#152337');
51
+ assert.equal(result.theme.fonts.body.family, 'Figtree');
52
+ assert.equal(result.font, true);
53
+ assert.equal(result.transition, 'fade');
54
+ assert.equal(result.explicit, 'cut');
55
+ assert.equal(result.music, 'calm');
56
+ assert.equal(result.fetched, false);
57
+ assert.equal(result.status, 404);
58
+ assert.deepEqual(result.issues, []);
59
+ });
60
+ });
61
+
62
+ test('check warns about the custom look palette at the ink and muted thresholds', { skip: !chrome }, async t => {
63
+ const { project, timeline } = fixture(t, { extends: 'clean', bg: '#ffffff', ink: '#888888', muted: '#bbbbbb' });
64
+ await withEngine(project, timeline, {}, async page => {
65
+ const result = await page.evaluate(async () => {
66
+ const { Engine, fetchState } = await import('/engine/runtime.js');
67
+ const state = await fetchState();
68
+ const paletteWarnings = (config) => {
69
+ const engine = new Engine({ canvas: document.createElement('canvas'), state: { ...state, config }, scenes: { demo(s) { s.circle({ at: 0 }); }, end(s) { s.circle({ at: 0 }); } }, icons: {}, images: new Map() });
70
+ return engine.check().filter(i => i.message.startsWith('look.json:'));
71
+ };
72
+ return {
73
+ low: paletteWarnings(state.config),
74
+ good: paletteWarnings({ ...state.config, look: { ...state.config.look, ink: '#000000', muted: '#888888' } }),
75
+ builtin: paletteWarnings({ ...state.config, theme: 'paper', look: null }),
76
+ };
77
+ });
78
+ assert.equal(result.low.length, 2);
79
+ assert.deepEqual(result.low.map(i => i.level), ['warn', 'warn']);
80
+ assert.match(result.low[0].message, /ink.*at least 4.5/);
81
+ assert.match(result.low[1].message, /muted.*at least 3/);
82
+ assert.equal(result.low[0].scene, null);
83
+ assert.deepEqual(result.good, []);
84
+ assert.deepEqual(result.builtin, []);
85
+ });
86
+ });
87
+
88
+ test('all six textures follow bg and render deterministically regardless of the base look', { skip: !chrome }, async t => {
89
+ const { project, timeline } = fixture(t, { extends: 'clean' });
90
+ await withEngine(project, timeline, {}, async page => {
91
+ const results = await page.evaluate(async () => {
92
+ const { getTheme, makeBackground } = await import('/engine/themes.js');
93
+ return ['paper', 'dots', 'chalk', 'grid', 'glow', 'plain'].map(background => {
94
+ const draw = (base, bg) => makeBackground(getTheme('', { extends: base, name: 'custom', background, bg }), 160, 90, 4);
95
+ const a = draw('clean', '#9b5c32');
96
+ const b = draw('paper', '#9b5c32');
97
+ const c = draw('clean', '#28517a');
98
+ const d = draw('clean', '#9b5c32');
99
+ return { background, same: a.toDataURL() === b.toDataURL(), deterministic: a.toDataURL() === d.toDataURL(), changed: a.toDataURL() !== c.toDataURL(), pixel: [...a.getContext('2d').getImageData(80, 45, 1, 1).data] };
100
+ });
101
+ });
102
+ for (const r of results) {
103
+ assert.equal(r.same, true, r.background);
104
+ assert.equal(r.deterministic, true, r.background);
105
+ assert.equal(r.changed, true, r.background);
106
+ }
107
+ assert.deepEqual(results.at(-1).pixel, [155, 92, 50, 255]);
108
+ });
109
+ });
@@ -0,0 +1,57 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { spawn } from 'node:child_process';
7
+ import { once } from 'node:events';
8
+ import { setTimeout } from 'node:timers/promises';
9
+ import { fileURLToPath } from 'node:url';
10
+
11
+ test('preview reloads an outside look and recovers after invalid or missing look files', { timeout: 15000 }, async () => {
12
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-look-preview-'));
13
+ const dir = path.join(root, 'video');
14
+ fs.mkdirSync(dir);
15
+ const settings = path.join(dir, 'video.json');
16
+ const look = path.join(root, 'brand.json');
17
+ fs.writeFileSync(settings, JSON.stringify({ theme: '../brand.json' }));
18
+ fs.writeFileSync(look, JSON.stringify({ extends: 'clean' }));
19
+ fs.writeFileSync(path.join(dir, 'script.md'), '## demo {min=1}');
20
+ fs.writeFileSync(path.join(dir, 'scenes.js'), 'export default { demo() {} };');
21
+ const bin = fileURLToPath(new URL('../bin/explainroo.js', import.meta.url));
22
+ const child = spawn(process.execPath, [bin, 'preview', dir, '--port', '0'], { stdio: ['ignore', 'ignore', 'pipe'] });
23
+ const exited = once(child, 'exit');
24
+ let logs = '';
25
+ child.stderr.on('data', chunk => { logs += chunk; });
26
+ const until = async fn => {
27
+ for (let i = 0; i < 80; i++) {
28
+ const value = await fn();
29
+ if (value) return value;
30
+ await setTimeout(100);
31
+ }
32
+ assert.fail(`preview did not update: ${logs}`);
33
+ };
34
+ try {
35
+ const url = await until(() => /preview: (http:\/\/127\.0\.0\.1:\d+)/.exec(logs)?.[1]);
36
+ const state = async () => (await fetch(url + '/__state.json')).json();
37
+ const first = await state();
38
+ fs.writeFileSync(look, JSON.stringify({ extends: 'clean', bg: '#ffffff' }));
39
+ const changed = await until(async () => {
40
+ const s = await state();
41
+ return s.config.look.bg === '#ffffff' && s;
42
+ });
43
+ assert.notEqual(changed.version, first.version);
44
+ fs.writeFileSync(look, JSON.stringify({ extends: 'clean', dark: 'yes' }));
45
+ await until(async () => (await state()).error?.includes('dark'));
46
+ fs.writeFileSync(look, JSON.stringify({ extends: 'clean', bg: '#eeeeee' }));
47
+ await until(async () => { const s = await state(); return !s.error && s.config.look.bg === '#eeeeee'; });
48
+ fs.writeFileSync(settings, JSON.stringify({ theme: '../missing.json' }));
49
+ await until(async () => (await state()).error?.includes('missing.json'));
50
+ fs.writeFileSync(path.join(root, 'missing.json'), JSON.stringify({ extends: 'paper' }));
51
+ await until(async () => { const s = await state(); return !s.error && s.config.look.extends === 'paper'; });
52
+ } finally {
53
+ child.kill('SIGTERM');
54
+ await exited;
55
+ fs.rmSync(root, { recursive: true, force: true });
56
+ }
57
+ });