@biunow/agent-biutalk 0.0.0-stage → 1.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 (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,130 @@
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 { loadLook, loadProject, normalizeConfig, ProjectError, THEMES } from '../src/project.js';
7
+ import { getTheme } from '../engine/themes.js';
8
+ import { makeState } from '../src/pipeline.js';
9
+
10
+ function fixture(t) {
11
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-look-'));
12
+ t.after(() => fs.rmSync(root, { recursive: true, force: true }));
13
+ const dir = path.join(root, 'video');
14
+ fs.mkdirSync(dir);
15
+ fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ theme: '../brand.json' }));
16
+ fs.writeFileSync(path.join(dir, 'script.md'), '## demo\nHello.');
17
+ fs.writeFileSync(path.join(dir, 'scenes.js'), 'export default { demo() {} };');
18
+ const file = path.join(root, 'brand.json');
19
+ const write = (raw) => fs.writeFileSync(file, JSON.stringify(raw));
20
+ return { root, dir, file, write };
21
+ }
22
+
23
+ test('a shared look outside the project is loaded in Node and deep merged without changing the base', t => {
24
+ const { dir, write } = fixture(t);
25
+ const base = structuredClone(getTheme('paper'));
26
+ write({ extends: 'paper', bg: '#fbfaf7', colors: { orange: '#e8590c' }, fonts: { display: { weight: 800 } }, stroke: { width: 3 }, code: { bg: '#1d1b16' }, terminal: { prompt: '#e8590c' }, caption: { active: '#e8590c' } });
27
+ const project = loadProject(dir);
28
+ const look = getTheme(project.config.theme, project.config.look);
29
+ assert.equal(project.config.look.name, 'brand');
30
+ assert.equal(project.paths.look, path.resolve(dir, '../brand.json'));
31
+ assert.equal(look.bg, '#fbfaf7');
32
+ assert.equal(look.colors.orange, '#e8590c');
33
+ assert.equal(look.colors.blue, base.colors.blue);
34
+ assert.deepEqual(look.fonts.display, { family: 'Kalam', weight: 800 });
35
+ assert.equal(look.stroke.roughness, base.stroke.roughness);
36
+ assert.equal(look.stroke.width, 3);
37
+ assert.equal(look.code.bg, '#1d1b16');
38
+ assert.equal(look.code.fg, base.code.fg);
39
+ assert.equal(look.terminal.prompt, '#e8590c');
40
+ assert.equal(look.terminal.bg, base.terminal.bg);
41
+ assert.equal(look.caption.active, '#e8590c');
42
+ assert.equal(look.caption.bg, base.caption.bg);
43
+ assert.deepEqual(getTheme('paper'), base);
44
+ });
45
+
46
+ test('look defaults inherit each base texture, transition and music; explicit video settings win', t => {
47
+ const { dir, write } = fixture(t);
48
+ const expected = [['paper', 'paper', 'brush', 'warm'], ['clean', 'dots', 'slide', 'upbeat'], ['chalk', 'chalk', 'brush', 'calm'], ['blueprint', 'grid', 'wipe', 'tech'], ['midnight', 'glow', 'zoom', 'tech']];
49
+ for (const [base, background, transition, music] of expected) {
50
+ write({ extends: base });
51
+ const cfg = loadProject(dir).config;
52
+ const theme = getTheme(cfg.theme, cfg.look);
53
+ assert.equal(theme.background, background);
54
+ assert.equal(theme.transition, transition);
55
+ assert.equal(cfg.transition, 'auto');
56
+ assert.equal(cfg.music.style, music);
57
+ assert.equal(normalizeConfig({ theme: base }).music.style, music);
58
+ }
59
+ write({ extends: 'clean', name: 'acme', background: 'plain', transition: 'fade', music: 'calm' });
60
+ const cfg = loadProject(dir).config;
61
+ assert.equal(getTheme(cfg.theme, cfg.look).background, 'plain');
62
+ assert.equal(getTheme(cfg.theme, cfg.look).transition, 'fade');
63
+ assert.equal(cfg.music.style, 'calm');
64
+ for (const music of ['playful', { style: 'tech', volume: 0.2 }, false]) {
65
+ const explicit = normalizeConfig({ theme: '../brand.json', transition: 'cut', music }, dir);
66
+ assert.equal(explicit.transition, 'cut');
67
+ assert.deepEqual(explicit.music, music === false ? null : { volume: 0.5, seed: 1, tempo: 1, ...(typeof music === 'string' ? { style: music } : music) });
68
+ }
69
+ });
70
+
71
+ test('look fonts must be built in or listed by the video', t => {
72
+ const { dir, write } = fixture(t);
73
+ write({ extends: 'clean', fonts: { body: { family: 'Inter', weight: 500 } } });
74
+ assert.equal(loadProject(dir).config.look.fonts.body.family, 'Inter');
75
+ write({ extends: 'clean', fonts: { display: { family: 'Figtree', weight: 800 } } });
76
+ assert.throws(() => loadProject(dir), /brand.json: fonts.display.family.*Built-in families:.*Inter/);
77
+ const cfg = normalizeConfig({ theme: '../brand.json', fonts: [{ family: 'Figtree', src: 'assets/font.woff2' }] }, dir);
78
+ assert.equal(getTheme(cfg.theme, cfg.look).fonts.display.family, 'Figtree');
79
+ });
80
+
81
+ test('look validation names the file and bad key for every kind of value', t => {
82
+ const { dir, write } = fixture(t);
83
+ const cases = [
84
+ [[], 'look'], [null, 'look'], [{}, 'extends'], [{ extends: 'custom' }, 'extends'],
85
+ [{ typo: true }, 'look.typo'], [{ name: 'clean' }, 'name'], [{ name: '' }, 'name'], [{ name: 2 }, 'name'], [{ name: null }, 'name'],
86
+ [{ dark: 'false' }, 'dark'], [{ bg: 'red' }, 'bg'], [{ ink: '#fff' }, 'ink'], [{ muted: null }, 'muted'], [{ surface: '#gggggg' }, 'surface'],
87
+ [{ accent: 'cyan' }, 'accent'], [{ background: 'clean' }, 'background'], [{ transition: 'auto' }, 'transition'], [{ music: false }, 'music'],
88
+ [{ radius: -1 }, 'radius'], [{ radius: 201 }, 'radius'], [{ radius: '18' }, 'radius'],
89
+ [{ colors: [] }, 'colors'], [{ colors: { cyan: '#000000' } }, 'colors.cyan'], [{ colors: { blue: 'rgba(1,2,3,0.5)' } }, 'colors.blue'],
90
+ [{ fonts: null }, 'fonts'], [{ fonts: { title: {} } }, 'fonts.title'], [{ fonts: { body: [] } }, 'fonts.body'],
91
+ [{ fonts: { body: { style: 'italic' } } }, 'fonts.body.style'], [{ fonts: { body: { family: '' } } }, 'fonts.body.family'],
92
+ [{ fonts: { body: { weight: 0 } } }, 'fonts.body.weight'], [{ fonts: { body: { weight: 1001 } } }, 'fonts.body.weight'], [{ fonts: { body: { weight: 1.5 } } }, 'fonts.body.weight'],
93
+ [{ stroke: null }, 'stroke'], [{ stroke: { wat: 3 } }, 'stroke.wat'], [{ stroke: { rough: 1 } }, 'stroke.rough'],
94
+ [{ stroke: { fillStyle: 'fake' } }, 'stroke.fillStyle'], [{ stroke: { texture: 'paper' } }, 'stroke.texture'],
95
+ [{ stroke: { width: 21 } }, 'stroke.width'], [{ stroke: { roughness: -1 } }, 'stroke.roughness'], [{ stroke: { bowing: '1' } }, 'stroke.bowing'],
96
+ [{ stroke: { hachureGap: 0 } }, 'stroke.hachureGap'], [{ stroke: { fillWeight: 21 } }, 'stroke.fillWeight'], [{ stroke: { glow: 101 } }, 'stroke.glow'],
97
+ [{ code: [] }, 'code'], [{ code: { unknown: '#000000' } }, 'code.unknown'], [{ terminal: { fg: 'white' } }, 'terminal.fg'],
98
+ [{ caption: { bg: 'rgba(256,0,0,0.5)' } }, 'caption.bg'], [{ caption: { bg: 'rgba(1,2,3,1.1)' } }, 'caption.bg'],
99
+ [{ code: { highlight: 'rgba(1,2,3,-1)' } }, 'code.highlight'], [{ code: { highlight: 'rgb(1,2,3)' } }, 'code.highlight'],
100
+ [{ caption: { active: 'rgba(1,2,3,0.5)' } }, 'caption.active'],
101
+ ];
102
+ for (const [raw, key] of cases) {
103
+ write(raw && !Array.isArray(raw) ? { extends: 'clean', ...raw } : raw);
104
+ if (key === 'extends' && Object.keys(raw).length === 0) write(raw);
105
+ assert.throws(() => loadProject(dir), e => e instanceof ProjectError && e.message.includes(`brand.json: ${key} `), JSON.stringify(raw));
106
+ }
107
+ write({ extends: 'clean', caption: { bg: 'rgba(1, 2, 3, .5)' }, code: { highlight: '#abcdef' } });
108
+ assert.equal(loadProject(dir).config.look.caption.bg, 'rgba(1, 2, 3, .5)');
109
+ for (const theme of ['/tmp/look.json', 'C:\\look.json', 'look.txt', 3, null]) assert.throws(() => normalizeConfig({ theme }), /relative path/);
110
+ });
111
+
112
+ test('missing and malformed look files have friendly errors', t => {
113
+ const { dir, file } = fixture(t);
114
+ assert.throws(() => loadProject(dir), /brand.json: theme file is missing/);
115
+ fs.writeFileSync(file, '{');
116
+ assert.throws(() => loadLook(dir, '../brand.json'), /brand.json: theme file could not be read as JSON/);
117
+ });
118
+
119
+ test('editing a look changes the state version and reloads its values', t => {
120
+ const { dir, file, write } = fixture(t);
121
+ write({ extends: 'clean', bg: '#ffffff' });
122
+ const first = makeState(loadProject(dir), {});
123
+ const stamp = fs.statSync(file);
124
+ write({ extends: 'clean', bg: '#eeeeee' });
125
+ fs.utimesSync(file, stamp.atime, stamp.mtime);
126
+ const next = makeState(loadProject(dir), {});
127
+ assert.notEqual(first.version, next.version);
128
+ assert.equal(next.config.look.bg, '#eeeeee');
129
+ assert.deepEqual(THEMES, ['paper', 'clean', 'chalk', 'blueprint', 'midnight', 'editorial']);
130
+ });
@@ -0,0 +1,114 @@
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) {
15
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-math-browser-'));
16
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
17
+ fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ theme: 'chalk', captions: false, sfx: false }));
18
+ fs.writeFileSync(path.join(dir, 'script.md'), '## demo {min=3}\n');
19
+ fs.writeFileSync(path.join(dir, 'scenes.js'), `export default { demo(s) {
20
+ s.math(String.raw\`\\frac{1}{2}\`, { x: 450, y: 540, size: 96, at: 0.5, id: 'fraction' });
21
+ s.math(String.raw\`\\sum_{i=1}^n i\`, { x: 950, y: 540, at: 0.5 });
22
+ s.math(String.raw\`\\begin{pmatrix}1 & 2 \\\\ 3 & 4\\end{pmatrix}\`, { x: 1450, y: 540, at: 0.5 });
23
+ s.annotate('fraction', { at: 2, type: 'underline' });
24
+ }};`);
25
+ const project = loadProject(dir);
26
+ return { project, timeline: buildTimeline(project, {}) };
27
+ }
28
+
29
+ test('fixed formulas preload once and render deterministically before, during and after entering', { skip: !chrome }, async t => {
30
+ const { project, timeline } = fixture(t);
31
+ await withEngine(project, timeline, {}, async page => {
32
+ const result = await page.evaluate(async () => {
33
+ const before = performance.getEntriesByType('resource').filter(r => r.name.includes('/__math?')).length;
34
+ const a = await window.explainroo.frames([0, 28, 55]);
35
+ const b = await window.explainroo.frames([55, 28, 0]);
36
+ const issues = window.explainroo.check();
37
+ const after = performance.getEntriesByType('resource').filter(r => r.name.includes('/__math?')).length;
38
+ return { before, after, deterministic: a.every((f, i) => f === b[2 - i]), changing: new Set(a).size, issues };
39
+ });
40
+ assert.equal(result.before, 3);
41
+ assert.equal(result.after, 3);
42
+ assert.equal(result.deterministic, true);
43
+ assert.equal(result.changing, 3);
44
+ assert.deepEqual(result.issues, []);
45
+ });
46
+ });
47
+
48
+ test('math boxes, transformations, text checks and late-formula errors work in the page', { skip: !chrome }, async t => {
49
+ const { project, timeline } = fixture(t);
50
+ await withEngine(project, timeline, {}, async page => {
51
+ const result = await page.evaluate(async () => {
52
+ const { Engine, fetchState } = await import('/engine/runtime.js');
53
+ const { SceneError } = await import('/engine/stage.js');
54
+ const state = await fetchState();
55
+ const make = async (draw, config = {}) => {
56
+ const engine = new Engine({ canvas: document.createElement('canvas'), state: { ...state, config: { ...state.config, ...config } }, scenes: { demo: draw }, icons: {}, images: new Map() });
57
+ await engine.loadMath();
58
+ return engine;
59
+ };
60
+ const boxes = [];
61
+ const ids = [];
62
+ const geometry = await make(s => {
63
+ boxes.push(s.math('E=mc^2', { x: 400, y: 300, align: 'left', id: 'energy', at: 1 }));
64
+ ids.push(s.get('energy'));
65
+ s.arrow('energy', [1500, 300], { at: 1 });
66
+ s.annotate('energy', { at: 2 });
67
+ });
68
+ geometry.drawScene(geometry.ctx, 0, 0.5);
69
+ const box = boxes.at(-1);
70
+ const id = ids.at(-1);
71
+ const checks = await make(s => {
72
+ s.math('x', { x: -10, y: 200, enter: 'none' });
73
+ s.math('y', { x: 500, y: 400, size: 10, enter: 'none' });
74
+ s.math('z', { x: 20, y: 600, align: 'left', enter: 'none' });
75
+ s.math('a+b', { x: 900, y: 930, enter: 'none' });
76
+ s.math('E=mc^2', { y: 800, enter: 'none' });
77
+ s.text('Energy', { y: 800, enter: 'none' });
78
+ }, { captions: true });
79
+ const transformed = await make(s => s.math('x', { x: 900, y: 500, size: 72, scale: 2, rotate: 90, enter: 'none' }));
80
+ transformed.textLog = [];
81
+ transformed.drawScene(transformed.ctx, 0, 2);
82
+ const log = transformed.textLog[0];
83
+ const late = await make(s => s.math('x=' + Math.floor(s.t), { enter: 'none' }));
84
+ const lateIssues = late.check();
85
+ late.renderFrame(2);
86
+ const invalid = await make(s => s.math(String.raw`\frac{1}`, { at: 1 }));
87
+ let error;
88
+ try { invalid.renderFrame(2); } catch (e) { error = { isSceneError: e instanceof SceneError, message: e.message }; }
89
+ const entrances = [];
90
+ for (const theme of ['paper', 'chalk', 'blueprint', 'clean', 'midnight']) {
91
+ const engine = await make(s => s.math('x', { at: 1 }), { theme, sfx: true });
92
+ const events = engine.collectEvents().events;
93
+ const frames = [0, 1.25, 2.5].map(time => { engine.renderFrame(time); return engine.canvas.toDataURL(); });
94
+ entrances.push({ theme, dur: events[0].dur, changing: new Set(frames).size });
95
+ }
96
+ return { box, id, issues: checks.check(), log, lateIssues, latePaths: [...late.mathCache.values()].every(d => d.paths.length > 0), error, entrances };
97
+ });
98
+ assert.equal(result.box.left, 400);
99
+ assert.equal(result.box.y, 300);
100
+ assert.ok(result.box.w > 0 && result.box.h > 0);
101
+ for (const key of ['x', 'y', 'w', 'h', 'left', 'right', 'top', 'bottom']) assert.ok(Math.abs(result.id[key] - result.box[key]) < 1e-8, key);
102
+ for (const pattern of [/runs off the frame/, /hard to read/, /closer.*edge/, /caption band/, /overlaps/]) assert.ok(result.issues.some(i => pattern.test(i.message)), String(pattern));
103
+ assert.equal(result.log.size, 144);
104
+ assert.ok(result.log.y1 - result.log.y0 > result.log.x1 - result.log.x0);
105
+ assert.ok(result.lateIssues.some(i => i.level === 'error' && /keep TeX strings fixed/.test(i.message)));
106
+ assert.equal(result.latePaths, true);
107
+ assert.equal(result.error.isSceneError, true);
108
+ assert.match(result.error.message, /\\frac\{1\}.*Missing argument/);
109
+ for (const r of result.entrances) {
110
+ assert.equal(r.changing, 3, r.theme);
111
+ assert.equal(r.dur, ['clean', 'midnight'].includes(r.theme) ? 0.75 : 0.9, r.theme);
112
+ }
113
+ });
114
+ });
@@ -0,0 +1,54 @@
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 { typesetMath, mathHash, MAX_TEX_LENGTH } from '../src/math.js';
7
+
8
+ test('math returns standalone paths, a viewBox and baseline metrics', async () => {
9
+ for (const tex of [String.raw`\frac{1}{2}`, String.raw`\int_0^1 x^2\,dx = \tfrac{1}{3}`, String.raw`\begin{pmatrix}1 & 2 \\ 3 & 4\end{pmatrix}`]) {
10
+ const result = await typesetMath(tex);
11
+ assert.equal(result.unitsPerEm, 1000);
12
+ assert.equal(result.viewBox.length, 4);
13
+ assert.ok(result.viewBox.every(Number.isFinite));
14
+ assert.ok(result.viewBox[2] > 0 && result.viewBox[3] > 0);
15
+ assert.ok(result.ascent > 0 && result.descent >= 0);
16
+ assert.equal(result.ascent + result.descent, result.viewBox[3]);
17
+ assert.ok(result.paths.length >= 3);
18
+ for (const d of result.paths) {
19
+ assert.match(d, /^M/);
20
+ assert.doesNotMatch(d, /(?:NaN|Infinity|href|<)/);
21
+ }
22
+ }
23
+ const fraction = await typesetMath(String.raw`\frac{1}{2}`);
24
+ assert.ok(fraction.paths.some(d => /^M120 -220L820 -220L820 -280L120 -280Z$/.test(d)), 'fraction bar includes the flipped SVG coordinates');
25
+ const inline = await typesetMath(String.raw`\frac{1}{2}`, false);
26
+ assert.ok(inline.viewBox[3] < fraction.viewBox[3]);
27
+ });
28
+
29
+ test('math caches by TeX and display style and reuses the disk result', async t => {
30
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-math-'));
31
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
32
+ const tex = String.raw`\sum_{i=1}^n i`;
33
+ const hash = mathHash(tex);
34
+ assert.match(hash, /^[0-9a-f]{64}$/);
35
+ assert.notEqual(hash, mathHash(tex, false));
36
+ assert.notEqual(hash, mathHash('x'));
37
+ const file = path.join(dir, `${hash}.json`);
38
+ const result = await typesetMath(tex, true, file);
39
+ assert.deepEqual(JSON.parse(fs.readFileSync(file)), result);
40
+ fs.utimesSync(file, 1, 1);
41
+ assert.deepEqual(await typesetMath(tex, true, file), result);
42
+ assert.equal(fs.statSync(file).mtimeMs, 1000);
43
+ });
44
+
45
+ test('math errors keep the TeX message and do not leak macros between formulas', async () => {
46
+ await assert.rejects(typesetMath(String.raw`\frac{1}`), /Missing argument for \\frac/);
47
+ await assert.rejects(typesetMath(String.raw`\unknown`), /Undefined control sequence \\unknown/);
48
+ await typesetMath(String.raw`\newcommand{\localmacro}{x}\localmacro`);
49
+ await assert.rejects(typesetMath(String.raw`\localmacro`), /Undefined control sequence/);
50
+ await assert.rejects(typesetMath(String.raw`\require{html}`), /Undefined control sequence/);
51
+ await assert.rejects(typesetMath('x'.repeat(MAX_TEX_LENGTH + 1)), /at most 4096 characters/);
52
+ await assert.rejects(typesetMath(null), /TeX string/);
53
+ await assert.rejects(typesetMath('x', 'false'), /display must be true or false/);
54
+ });
@@ -0,0 +1,133 @@
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, spawnSync } from 'node:child_process';
7
+ import { once } from 'node:events';
8
+ import { setTimeout } from 'node:timers/promises';
9
+ import { fileURLToPath } from 'node:url';
10
+ import { findChrome } from '../src/browser.js';
11
+ import { loadProject } from '../src/project.js';
12
+ import { speechChunks } from '../src/script.js';
13
+ import { sceneHash, voicePaths } from '../src/voice.js';
14
+ import { writeWav } from '../src/wav.js';
15
+ import { probe } from '../src/ffmpeg.js';
16
+
17
+ const bin = fileURLToPath(new URL('../bin/explainroo.js', import.meta.url));
18
+ let chrome;
19
+ try { chrome = findChrome(); } catch {}
20
+
21
+ function fixture(t) {
22
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-sizes-browser-'));
23
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
24
+ fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ size: '320x180', theme: 'clean', fps: 24, music: false, sfx: false, end: 0, lead: 0, hold: 0 }));
25
+ fs.writeFileSync(path.join(dir, 'script.md'), '# Sizes\n\n## intro {min=0.5 chapter="Intro"}\nHello.');
26
+ fs.writeFileSync(path.join(dir, 'scenes.js'), `export default { intro(s) {
27
+ s.text(s.portrait ? 'Tall' : 'Wide', { x: s.cx, y: s.safe.y + s.safe.h / 2, size: s.W * 0.05, at: 0 });
28
+ } };`);
29
+ // A short cached tone avoids loading speech models for output tests.
30
+ const project = loadProject(dir);
31
+ const scene = project.script.scenes[0];
32
+ const chunks = speechChunks(scene.units, project.config);
33
+ fs.mkdirSync(project.paths.voice, { recursive: true });
34
+ const files = voicePaths(project, scene.id);
35
+ writeWav(files.wav, Float32Array.from({ length: 6000 }, (_, i) => 0.1 * Math.sin(i * Math.PI / 24)), 24000);
36
+ fs.writeFileSync(files.json, JSON.stringify({ hash: sceneHash(scene, chunks, project.config), id: scene.id,
37
+ duration: 0.25, words: [{ text: 'Hello.', spoken: 'Hello.', start: 0, end: 0.25, matched: true }],
38
+ marks: {}, chunks: [{ start: 0, end: 0.25, text: 'Hello.' }], transcript: 'Hello.', matchRate: 1, unmatched: [] }));
39
+ return dir;
40
+ }
41
+
42
+ function run(command, dir, flags = []) {
43
+ const r = spawnSync(process.execPath, [bin, command, dir, ...flags, '--json'], { encoding: 'utf8', timeout: 90000 });
44
+ assert.equal(r.status, 0, `${command}: ${r.stderr}\n${r.stdout}`);
45
+ return JSON.parse(r.stdout);
46
+ }
47
+
48
+ test('CLI renders use size names for every extra file and --out wins with and without --draft', { skip: !chrome, timeout: 300000 }, async t => {
49
+ const dir = fixture(t);
50
+ const voiceFile = voicePaths(loadProject(dir), 'intro').json;
51
+ const mtime = fs.statSync(voiceFile).mtimeMs;
52
+ const cases = [
53
+ [[], 'video'],
54
+ [['--draft'], 'draft'],
55
+ [['--out', path.join(dir, 'plain.mp4')], '../plain'],
56
+ [['--draft', '--out', path.join(dir, 'plain-draft.mp4')], '../plain-draft'],
57
+ [['--size', 'tiktok'], 'video-tiktok'],
58
+ [['--size', 'tiktok', '--draft'], 'draft-tiktok'],
59
+ [['--size', 'youtube', '--out', path.join(dir, 'custom.mp4')], '../custom'],
60
+ [['--size', 'youtube', '--draft', '--out', path.join(dir, 'custom-draft.mp4')], '../custom-draft'],
61
+ ];
62
+ for (const [flags, name] of cases) {
63
+ const result = run('render', dir, [...flags, '--scale', '0.1', '--workers', '1']);
64
+ const base = path.resolve(dir, 'out', name);
65
+ assert.equal(result.out, `${base}.mp4`);
66
+ assert.deepEqual(result.subtitles, { srt: `${base}.srt`, vtt: `${base}.vtt` });
67
+ assert.equal(result.cover, `${base}.cover.jpg`);
68
+ assert.equal(result.chapters, `${base}.chapters.txt`);
69
+ for (const ext of ['mp4', 'srt', 'vtt', 'cover.jpg', 'chapters.txt']) assert.ok(fs.statSync(`${base}.${ext}`).size > 0);
70
+ const info = await probe(result.out);
71
+ const video = info.streams.find(s => s.codec_type === 'video');
72
+ assert.equal(video.width, result.width);
73
+ assert.equal(video.height, result.height);
74
+ }
75
+ assert.equal(fs.statSync(voiceFile).mtimeMs, mtime);
76
+ assert.ok(fs.existsSync(path.join(dir, 'out/video.mp4')));
77
+ assert.ok(fs.existsSync(path.join(dir, 'out/video-tiktok.mp4')));
78
+ });
79
+
80
+ test('CLI still, sheet and check use the override, while existing names stay unchanged', { skip: !chrome, timeout: 180000 }, t => {
81
+ const dir = fixture(t);
82
+ for (const [flags, suffix] of [[[], ''], [['--size', 'tiktok'], '-tiktok']]) {
83
+ const still = run('still', dir, [...flags, '--scale', '0.1']).stills[0];
84
+ assert.equal(still.file, path.join(dir, `out/stills${suffix}/intro@end.png`));
85
+ assert.ok(fs.statSync(still.file).size > 0);
86
+ for (const scene of [null, 'intro']) {
87
+ const result = run('sheet', dir, [...flags, ...(scene ? ['--scene', scene] : [])]);
88
+ assert.equal(result.file, path.join(dir, `out/sheet${scene ? '-intro' : ''}${suffix}.jpg`));
89
+ assert.ok(fs.statSync(result.file).size > 0);
90
+ }
91
+ const result = run('check', dir, flags);
92
+ assert.deepEqual(result.issues.filter(i => i.level !== 'hint'), []);
93
+ const timeline = JSON.parse(fs.readFileSync(path.join(dir, 'build/timeline.json'), 'utf8'));
94
+ assert.equal(timeline.width, suffix ? 1080 : 320);
95
+ assert.equal(timeline.height, suffix ? 1920 : 180);
96
+ }
97
+ });
98
+
99
+ test('preview keeps the size override after settings change', { timeout: 15000 }, async t => {
100
+ const dir = fixture(t);
101
+ const child = spawn(process.execPath, [bin, 'preview', dir, '--size', 'tiktok', '--port', '0'], { stdio: ['ignore', 'ignore', 'pipe'] });
102
+ const exited = once(child, 'exit');
103
+ let logs = '';
104
+ child.stderr.on('data', chunk => { logs += chunk; });
105
+ const until = async fn => {
106
+ for (let i = 0; i < 80; i++) {
107
+ const value = await fn();
108
+ if (value) return value;
109
+ await setTimeout(100);
110
+ }
111
+ assert.fail(`preview did not update: ${logs}`);
112
+ };
113
+ try {
114
+ const url = await until(() => /preview: (http:\/\/127\.0\.0\.1:\d+)/.exec(logs)?.[1]);
115
+ const state = async () => (await fetch(url + '/__state.json')).json();
116
+ const first = await state();
117
+ assert.equal(first.config.size, 'tiktok');
118
+ assert.equal(first.config.captions, true);
119
+ assert.equal(first.timeline.height, 1920);
120
+ const settings = path.join(dir, 'video.json');
121
+ fs.writeFileSync(settings, JSON.stringify({ ...JSON.parse(fs.readFileSync(settings, 'utf8')), size: 'square', title: 'Changed' }));
122
+ const changed = await until(async () => { const s = await state(); return s.title === 'Changed' && s; });
123
+ assert.equal(changed.config.size, 'tiktok');
124
+ assert.equal(changed.config.captions, true);
125
+ assert.deepEqual(changed.config.safe, first.config.safe);
126
+ assert.equal(changed.timeline.width, 1080);
127
+ assert.equal(changed.timeline.height, 1920);
128
+ assert.notEqual(changed.version, first.version);
129
+ } finally {
130
+ child.kill('SIGTERM');
131
+ await exited;
132
+ }
133
+ });
@@ -0,0 +1,116 @@
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 { loadProject, normalizeConfig, outputPath, FORMATS } from '../src/project.js';
7
+ import { prepare, reloadProject } from '../src/pipeline.js';
8
+ import { sceneHash, voicePaths } from '../src/voice.js';
9
+ import { speechChunks } from '../src/script.js';
10
+ import { Stage } from '../engine/stage.js';
11
+ import { getTheme } from '../engine/themes.js';
12
+ import { layoutAreas } from '../engine/layout.js';
13
+
14
+ function fixture(t, raw = {}) {
15
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-multi-size-'));
16
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
17
+ fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ size: 'youtube', ...raw }));
18
+ fs.writeFileSync(path.join(dir, 'script.md'), '## intro {min=1}\n');
19
+ fs.writeFileSync(path.join(dir, 'scenes.js'), 'export default { intro(s) {} };');
20
+ return dir;
21
+ }
22
+
23
+ test('size overrides normalize captions, dimensions and safe areas without changing the project file', t => {
24
+ const dir = fixture(t);
25
+ const before = fs.readFileSync(path.join(dir, 'video.json'), 'utf8');
26
+ for (const size of [...Object.keys(FORMATS), '16:9', '9:16', '1:1', '4:5', '1080x1350']) {
27
+ const project = loadProject(dir, { size });
28
+ const expected = normalizeConfig({ size });
29
+ for (const key of ['size', 'format', 'width', 'height', 'captions', 'safe']) assert.deepEqual(project.config[key], expected[key], `${size}: ${key}`);
30
+ assert.deepEqual(layoutAreas(project.config, project.config.width, project.config.height), layoutAreas(expected, expected.width, expected.height));
31
+ assert.equal(project.config.captions, expected.height >= expected.width);
32
+ assert.equal(project.sizeOverride, size);
33
+ assert.equal(reloadProject(project).config.size, size);
34
+ }
35
+ assert.equal(fs.readFileSync(path.join(dir, 'video.json'), 'utf8'), before);
36
+ assert.equal(loadProject(dir).config.size, 'youtube');
37
+ assert.equal(loadProject(dir).sizeOverride, undefined);
38
+ assert.throws(() => loadProject(dir, { size: 'bad' }), /size must be/);
39
+ assert.throws(() => loadProject(dir, { size: '1081x1350' }), /even numbers/);
40
+ });
41
+
42
+ test('overriding a platform size clears its safe area and recalculates auto captions', t => {
43
+ const dir = fixture(t, { size: 'tiktok' });
44
+ const cfg = loadProject(dir, { size: 'youtube' }).config;
45
+ assert.equal(cfg.captions, false);
46
+ assert.equal(cfg.safe, null);
47
+ const areas = layoutAreas(cfg, cfg.width, cfg.height);
48
+ assert.equal(areas.app, null);
49
+ assert.equal(areas.band, null);
50
+ const platform = loadProject(dir).config;
51
+ const tall = layoutAreas(platform, platform.width, platform.height);
52
+ assert.ok(tall.app);
53
+ assert.ok(tall.safe.top > tall.app.top);
54
+ assert.ok(tall.safe.bottom < tall.band.top);
55
+ });
56
+
57
+ test('explicit captions settings survive a size override', t => {
58
+ for (const captions of [true, false]) {
59
+ const dir = fixture(t, { captions });
60
+ for (const size of ['youtube', 'tiktok', 'square']) assert.equal(loadProject(dir, { size }).config.captions, captions);
61
+ }
62
+ });
63
+
64
+ test('output paths keep existing names or add the explicit size to every output type', () => {
65
+ const project = { paths: { out: '/tmp/video/out' } };
66
+ const names = [
67
+ ['video', '.mp4'], ['draft', '.mp4'], ['video', '.gif'], ['draft', '.gif'],
68
+ ['video', '.srt'], ['video', '.vtt'], ['video', '.cover.jpg'], ['video', '.chapters.txt'],
69
+ ['draft', '.srt'], ['draft', '.vtt'], ['draft', '.cover.jpg'], ['draft', '.chapters.txt'],
70
+ ['stills', ''], ['sheet', '.jpg'], ['sheet-intro', '.jpg'],
71
+ ];
72
+ for (const [name, ext] of names) {
73
+ assert.equal(outputPath(project, name, ext), path.resolve(`/tmp/video/out/${name}${ext}`));
74
+ for (const size of ['tiktok', 'youtube', '9:16', '1:1', '1080x1350']) {
75
+ assert.equal(outputPath({ ...project, sizeOverride: size }, name, ext), path.resolve(`/tmp/video/out/${name}-${size.replace(':', '-')}${ext}`));
76
+ }
77
+ }
78
+ for (const sizeOverride of [undefined, 'tiktok']) {
79
+ for (const name of ['video', 'draft']) {
80
+ assert.equal(outputPath({ ...project, sizeOverride }, name, '.mp4', 'chosen.mp4'), path.resolve('chosen.mp4'));
81
+ assert.equal(outputPath({ ...project, sizeOverride }, name, '.gif', '/tmp/chosen.gif'), path.resolve('/tmp/chosen.gif'));
82
+ }
83
+ }
84
+ });
85
+
86
+ test('portrait is true only when the frame is taller than wide', () => {
87
+ for (const size of ['youtube', 'vertical', 'linkedin', 'square', '400x400', '800x600']) {
88
+ const config = normalizeConfig({ size });
89
+ const { width: W, height: H } = config;
90
+ const engine = { config, W, H, theme: getTheme('paper'), safeArea: layoutAreas(config, W, H).safe,
91
+ timeline: { duration: 1, frames: 30, fps: 30, width: W, height: H, scenes: [{}] } };
92
+ const scene = { id: 'intro', index: 0, start: 0, dur: 1, words: [], marks: {} };
93
+ assert.equal(new Stage(engine, null, scene, 0).portrait, H > W, size);
94
+ }
95
+ });
96
+
97
+ test('sizes share voice hashes and caches, while prepare rebuilds the timeline for the current frame', async t => {
98
+ const dir = fixture(t);
99
+ const wide = loadProject(dir);
100
+ const tall = loadProject(dir, { size: 'vertical' });
101
+ const { timeline: first } = await prepare(wide);
102
+ const voiceFile = voicePaths(wide, 'intro').json;
103
+ const mtime = fs.statSync(voiceFile).mtimeMs;
104
+ const { timeline: second } = await prepare(tall);
105
+ assert.equal(voicePaths(tall, 'intro').json, voiceFile);
106
+ assert.equal(fs.statSync(voiceFile).mtimeMs, mtime);
107
+ assert.deepEqual(first.scenes, second.scenes);
108
+ assert.equal(first.duration, second.duration);
109
+ assert.equal(first.width, 1920);
110
+ assert.equal(second.width, 1080);
111
+ assert.equal(second.height, 1920);
112
+ assert.deepEqual(JSON.parse(fs.readFileSync(path.join(dir, 'build/timeline.json'), 'utf8')), second);
113
+ const scene = { ...wide.script.scenes[0], units: [{ type: 'word', display: 'Hello', spoken: 'Hello' }] };
114
+ const chunks = speechChunks(scene.units);
115
+ assert.equal(sceneHash(scene, chunks, wide.config), sceneHash(scene, chunks, tall.config));
116
+ });
@@ -0,0 +1,92 @@
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 { mapPhonemes, phonemize, espeakVersion, generateSpeech } from '../src/phonemes.js';
7
+
8
+ function fake(t, source) {
9
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-espeak-'));
10
+ const file = path.join(dir, 'fake espeak');
11
+ fs.writeFileSync(file, '#!/usr/bin/env node\n' + source, { mode: 0o755 });
12
+ const previous = process.env.EXPLAINROO_ESPEAK;
13
+ process.env.EXPLAINROO_ESPEAK = file;
14
+ t.after(() => {
15
+ if (previous === undefined) delete process.env.EXPLAINROO_ESPEAK;
16
+ else process.env.EXPLAINROO_ESPEAK = previous;
17
+ fs.rmSync(dir, { recursive: true, force: true });
18
+ });
19
+ return file;
20
+ }
21
+
22
+ test('maps every misaki v1.0 tie sequence and leaves language-specific IPA intact', () => {
23
+ assert.equal(mapPhonemes(' a^ɪ a^ʊ d^z d^ʒ e^ɪ o^ʊ ə^ʊ s^s t^s t^ʃ ɔ^ɪ '), 'I W ʣ ʤ A O Q S ʦ ʧ Y');
24
+ assert.equal(mapPhonemes('«ʧˈit-t^sːa» r x ɬ ʲ œ̃ ɔ̃ ɑ̃ ɛ̃ ɐ̃ ʊ̃ n̩'), '(ʧˈitʦːa) r x ɬ ʲ œ̃ ɔ̃ ɑ̃ ɛ̃ ɐ̃ ʊ̃ n̩');
25
+ assert.equal(mapPhonemes('कˈʌcʰcʰi'), 'कˈʌcʰcʰi');
26
+ });
27
+
28
+ const posix = { skip: process.platform === 'win32' && 'the fake espeak-ng is a POSIX script' };
29
+
30
+ test('batches text through stdin, preserves punctuation and removes language flags', posix, async t => {
31
+ fake(t, `
32
+ if (process.argv.includes('--version')) { console.log('eSpeak NG 1.51'); process.exit(0); }
33
+ const assert = require('node:assert/strict');
34
+ assert.deepEqual(process.argv.slice(2), ['-q', '-b', '1', '-v', 'fr-fr', '--ipa=1', '--tie=^']);
35
+ let text = '';
36
+ process.stdin.on('data', d => text += d);
37
+ process.stdin.on('end', () => {
38
+ assert.equal(text, ['bonjour', 'merci', 'שלום $HOME \`echo bad\`', 'encore'].join('\\n') + '\\n');
39
+ process.stdout.write('(en) t^ʃa\\nd^ʒa\\ne^ɪ\\no^ʊ\\n');
40
+ });
41
+ `);
42
+ assert.equal(espeakVersion(), 'eSpeak NG 1.51');
43
+ const result = await phonemize(['«bonjour», (merci)!', 'שלום $HOME `echo bad`\nencore'], 'fr');
44
+ assert.deepEqual(result, ['“ʧa”, (ʤa)!', 'A\nO']);
45
+ });
46
+
47
+ test('punctuation-only text needs no program', async t => {
48
+ const file = fake(t, 'process.exit(1);');
49
+ fs.rmSync(file);
50
+ assert.deepEqual(await phonemize(['¿?!', '(…)'], 'es'), ['¿?!', '(…)']);
51
+ assert.equal(espeakVersion(), null);
52
+ });
53
+
54
+ test('missing and non-executable programs give install instructions for every platform', posix, async t => {
55
+ const file = fake(t, '');
56
+ for (const missing of [false, true]) {
57
+ if (missing) fs.rmSync(file);
58
+ else fs.chmodSync(file, 0o644);
59
+ await assert.rejects(phonemize(['Hola'], 'es'), e => {
60
+ assert.match(e.message, /sudo apt install espeak-ng/);
61
+ assert.match(e.message, /brew install espeak-ng/);
62
+ assert.match(e.message, /espeak-ng\/espeak-ng\/releases/);
63
+ assert.match(e.message, /EXPLAINROO_ESPEAK/);
64
+ return true;
65
+ });
66
+ }
67
+ });
68
+
69
+ test('failed and incomplete output gives a friendly error', posix, async t => {
70
+ const file = fake(t, 'process.stderr.write("failure"); process.exit(2);');
71
+ await assert.rejects(phonemize(['Hola'], 'es'), /could not read the text/);
72
+ fs.writeFileSync(file, '#!/usr/bin/env node\nconsole.log("one");');
73
+ await assert.rejects(phonemize(['Hola', 'Adiós'], 'es'), /incomplete phonemes/);
74
+ await assert.rejects(phonemize(['안녕'], 'ko'), /supports es, fr, it, pt-br and hi/);
75
+ });
76
+
77
+ test('English keeps generate; other languages tokenize mapped phonemes and call generate_from_ids', async () => {
78
+ const calls = [];
79
+ const ids = { dims: [1, 4] };
80
+ const tts = {
81
+ generate(text, options) { calls.push(['english', text, options]); return 'audio'; },
82
+ tokenizer(text, options) { calls.push(['tokens', text, options]); return { input_ids: ids }; },
83
+ generate_from_ids(input, options) { calls.push(['ids', input, options]); return 'audio'; },
84
+ };
85
+ assert.equal(await generateSpeech(tts, 'Hello.', { voice: 'af_heart', speed: 0.9 }), 'audio');
86
+ assert.equal(await generateSpeech(tts, 'Bonjour.', { language: 'fr', voice: 'ff_siwis', speed: 1, phonemes: 'bɔ̃ʒˈuʁ.' }), 'audio');
87
+ assert.deepEqual(calls, [
88
+ ['english', 'Hello.', { voice: 'af_heart', speed: 0.9 }],
89
+ ['tokens', 'bɔ̃ʒˈuʁ.', { truncation: true }],
90
+ ['ids', ids, { voice: 'ff_siwis', speed: 1 }],
91
+ ]);
92
+ });