@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.
- package/bin/server.js +355 -0
- package/engine/AGENTS.md +1414 -0
- package/engine/CLAUDE.md +1 -0
- package/engine/LICENSE +21 -0
- package/engine/README.md +216 -0
- package/engine/bin/explainroo.js +19 -0
- package/engine/dev/audio-lab.mjs +268 -0
- package/engine/docs/media/contact-sheet.jpg +0 -0
- package/engine/docs/media/dns-poster.jpg +0 -0
- package/engine/docs/media/intro-poster.jpg +0 -0
- package/engine/docs/media/logo-dark.png +0 -0
- package/engine/docs/media/logo-light.png +0 -0
- package/engine/docs/media/looks-dark.webp +0 -0
- package/engine/docs/media/looks-light.webp +0 -0
- package/engine/docs/media/product-demo.webp +0 -0
- package/engine/docs/media/rebase-poster.jpg +0 -0
- package/engine/docs/media/sizes-dark.webp +0 -0
- package/engine/docs/media/sizes-light.webp +0 -0
- package/engine/engine/audio/dsp.js +69 -0
- package/engine/engine/audio/instruments.js +147 -0
- package/engine/engine/audio/music.js +576 -0
- package/engine/engine/audio/pcm.js +93 -0
- package/engine/engine/audio/rng.js +40 -0
- package/engine/engine/audio/sfx.js +287 -0
- package/engine/engine/audio/soundtrack.js +201 -0
- package/engine/engine/audio/synth.js +721 -0
- package/engine/engine/audio/theory.js +105 -0
- package/engine/engine/audio/wav.js +47 -0
- package/engine/engine/captions.js +131 -0
- package/engine/engine/clips.js +107 -0
- package/engine/engine/code.js +179 -0
- package/engine/engine/director.js +475 -0
- package/engine/engine/frame.html +135 -0
- package/engine/engine/icons/LICENSE-lucide.txt +43 -0
- package/engine/engine/icons/lucide-tags.json +1 -0
- package/engine/engine/icons/lucide.json +1 -0
- package/engine/engine/layout.js +69 -0
- package/engine/engine/pathdata.js +234 -0
- package/engine/engine/pen.js +240 -0
- package/engine/engine/player.html +67 -0
- package/engine/engine/player.js +219 -0
- package/engine/engine/readability.js +9 -0
- package/engine/engine/runtime.js +690 -0
- package/engine/engine/stage.js +2247 -0
- package/engine/engine/studio.html +216 -0
- package/engine/engine/text.js +81 -0
- package/engine/engine/themes.js +360 -0
- package/engine/engine/transitions.js +161 -0
- package/engine/engine/ui.js +1042 -0
- package/engine/engine/upload.js +32 -0
- package/engine/engine/util.js +204 -0
- package/engine/examples/callbacks-to-async-await/code-versions.js +34 -0
- package/engine/examples/callbacks-to-async-await/scenes.js +106 -0
- package/engine/examples/callbacks-to-async-await/script.md +22 -0
- package/engine/examples/callbacks-to-async-await/video.json +16 -0
- package/engine/examples/circle-area/scenes.js +228 -0
- package/engine/examples/circle-area/script.md +37 -0
- package/engine/examples/circle-area/video.json +14 -0
- package/engine/examples/explainroo-intro/scenes.js +133 -0
- package/engine/examples/explainroo-intro/script.md +27 -0
- package/engine/examples/explainroo-intro/video.json +8 -0
- package/engine/examples/how-dns-works/scenes.js +130 -0
- package/engine/examples/how-dns-works/script.md +28 -0
- package/engine/examples/how-dns-works/video.json +8 -0
- package/engine/examples/leap-years/scenes.js +156 -0
- package/engine/examples/leap-years/script.md +25 -0
- package/engine/examples/leap-years/video.json +16 -0
- package/engine/examples/leap-years-ja/scenes.js +194 -0
- package/engine/examples/leap-years-ja/script.md +32 -0
- package/engine/examples/leap-years-ja/video.json +17 -0
- package/engine/examples/merge-vs-rebase/scenes.js +129 -0
- package/engine/examples/merge-vs-rebase/script.md +22 -0
- package/engine/examples/merge-vs-rebase/video.json +8 -0
- package/engine/examples/password-storage-zh/scenes.js +185 -0
- package/engine/examples/password-storage-zh/script.md +25 -0
- package/engine/examples/password-storage-zh/video.json +19 -0
- package/engine/examples/sqlite-demo/README.md +19 -0
- package/engine/examples/sqlite-demo/scenes.js +423 -0
- package/engine/examples/sqlite-demo/script.md +35 -0
- package/engine/examples/sqlite-demo/video.json +17 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-400.woff2 +0 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-500.woff2 +0 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-600.woff2 +0 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-700.woff2 +0 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-OFL.txt +93 -0
- package/engine/examples/unspar-demo/assets/unspar-logo.svg +23 -0
- package/engine/examples/unspar-demo/scenes.js +367 -0
- package/engine/examples/unspar-demo/script.md +25 -0
- package/engine/examples/unspar-demo/video.json +21 -0
- package/engine/examples/why-is-the-sky-blue-es/scenes.js +160 -0
- package/engine/examples/why-is-the-sky-blue-es/script.md +22 -0
- package/engine/examples/why-is-the-sky-blue-es/video.json +15 -0
- package/engine/fonts/ArchitectsDaughter-400-latin-ext.woff2 +0 -0
- package/engine/fonts/ArchitectsDaughter-400-latin.woff2 +0 -0
- package/engine/fonts/CabinSketch-400-latin.woff2 +0 -0
- package/engine/fonts/CabinSketch-700-latin.woff2 +0 -0
- package/engine/fonts/InstrumentSerif-400-italic-latin-ext.woff2 +0 -0
- package/engine/fonts/InstrumentSerif-400-italic-latin.woff2 +0 -0
- package/engine/fonts/InstrumentSerif-400-normal-latin-ext.woff2 +0 -0
- package/engine/fonts/InstrumentSerif-400-normal-latin.woff2 +0 -0
- package/engine/fonts/Inter-400-latin-ext.woff2 +0 -0
- package/engine/fonts/Inter-400-latin.woff2 +0 -0
- package/engine/fonts/JetBrainsMono-400-latin-ext.woff2 +0 -0
- package/engine/fonts/JetBrainsMono-400-latin.woff2 +0 -0
- package/engine/fonts/Kalam-400-latin-ext.woff2 +0 -0
- package/engine/fonts/Kalam-400-latin.woff2 +0 -0
- package/engine/fonts/Kalam-700-latin-ext.woff2 +0 -0
- package/engine/fonts/Kalam-700-latin.woff2 +0 -0
- package/engine/fonts/NotoSansDevanagari-400.ttf +0 -0
- package/engine/fonts/NotoSansDevanagari-700.ttf +0 -0
- package/engine/fonts/PatrickHand-400-latin-ext.woff2 +0 -0
- package/engine/fonts/PatrickHand-400-latin.woff2 +0 -0
- package/engine/fonts/PlusJakartaSans-600-latin-ext.woff2 +0 -0
- package/engine/fonts/PlusJakartaSans-600-latin.woff2 +0 -0
- package/engine/fonts/SpaceGrotesk-500-latin-ext.woff2 +0 -0
- package/engine/fonts/SpaceGrotesk-500-latin.woff2 +0 -0
- package/engine/fonts/fonts.json +216 -0
- package/engine/fonts/licenses/ArchitectsDaughter-OFL.txt +93 -0
- package/engine/fonts/licenses/CabinSketch-OFL.txt +93 -0
- package/engine/fonts/licenses/InstrumentSerif-OFL.txt +93 -0
- package/engine/fonts/licenses/Inter-OFL.txt +93 -0
- package/engine/fonts/licenses/JetBrainsMono-OFL.txt +93 -0
- package/engine/fonts/licenses/Kalam-OFL.txt +93 -0
- package/engine/fonts/licenses/NotoSansDevanagari-OFL.txt +118 -0
- package/engine/fonts/licenses/PatrickHand-OFL.txt +93 -0
- package/engine/fonts/licenses/PlusJakartaSans-OFL.txt +93 -0
- package/engine/fonts/licenses/SpaceGrotesk-OFL.txt +93 -0
- package/engine/package-lock.json +1201 -0
- package/engine/package.json +67 -0
- package/engine/scripts/build-icons.mjs +74 -0
- package/engine/scripts/fetch-fonts.mjs +68 -0
- package/engine/skills/explainroo/SKILL.md +51 -0
- package/engine/src/align.js +357 -0
- package/engine/src/browser.js +121 -0
- package/engine/src/capture.js +315 -0
- package/engine/src/chapters.js +32 -0
- package/engine/src/cli.js +421 -0
- package/engine/src/clips.js +19 -0
- package/engine/src/elevenlabs.js +90 -0
- package/engine/src/env.js +16 -0
- package/engine/src/export.js +187 -0
- package/engine/src/ffmpeg.js +103 -0
- package/engine/src/fonts.js +86 -0
- package/engine/src/g2p.py +76 -0
- package/engine/src/images.js +151 -0
- package/engine/src/licenses/misaki-Apache-2.0.txt +201 -0
- package/engine/src/math.js +83 -0
- package/engine/src/models.js +161 -0
- package/engine/src/phonemes.js +162 -0
- package/engine/src/pipeline.js +63 -0
- package/engine/src/project.js +331 -0
- package/engine/src/qa.js +186 -0
- package/engine/src/recordings.js +89 -0
- package/engine/src/render.js +156 -0
- package/engine/src/script.js +266 -0
- package/engine/src/server.js +288 -0
- package/engine/src/subtitles.js +78 -0
- package/engine/src/timeline.js +55 -0
- package/engine/src/voice.js +240 -0
- package/engine/src/wav.js +98 -0
- package/engine/templates/starter/scenes.js +31 -0
- package/engine/templates/starter/script.md +14 -0
- package/engine/test/align.test.js +108 -0
- package/engine/test/brand.test.js +41 -0
- package/engine/test/browser.test.js +89 -0
- package/engine/test/camera-browser.test.js +225 -0
- package/engine/test/caption-phrases.test.js +35 -0
- package/engine/test/capture-browser.test.js +90 -0
- package/engine/test/capture-fixture.js +46 -0
- package/engine/test/capture.test.js +62 -0
- package/engine/test/chapters.test.js +41 -0
- package/engine/test/cjk-browser.test.js +101 -0
- package/engine/test/cjk.test.js +232 -0
- package/engine/test/cli-exit.test.js +25 -0
- package/engine/test/cli.test.js +116 -0
- package/engine/test/clips-browser.test.js +125 -0
- package/engine/test/clips.test.js +67 -0
- package/engine/test/code-morph-browser.test.js +99 -0
- package/engine/test/code-morph.test.js +110 -0
- package/engine/test/contrast-browser.test.js +63 -0
- package/engine/test/contrast.test.js +80 -0
- package/engine/test/director.test.js +316 -0
- package/engine/test/engine-pure.test.js +29 -0
- package/engine/test/export-browser.test.js +224 -0
- package/engine/test/export.test.js +96 -0
- package/engine/test/fixtures/capture.html +55 -0
- package/engine/test/formats-pace.test.js +104 -0
- package/engine/test/languages-browser.test.js +78 -0
- package/engine/test/languages.test.js +140 -0
- package/engine/test/looks-browser.test.js +109 -0
- package/engine/test/looks-preview.test.js +57 -0
- package/engine/test/looks.test.js +130 -0
- package/engine/test/math-browser.test.js +114 -0
- package/engine/test/math.test.js +54 -0
- package/engine/test/multi-size-browser.test.js +133 -0
- package/engine/test/multi-size.test.js +116 -0
- package/engine/test/phonemes.test.js +92 -0
- package/engine/test/readability-browser.test.js +36 -0
- package/engine/test/readability.test.js +20 -0
- package/engine/test/render-options.test.js +52 -0
- package/engine/test/script.test.js +67 -0
- package/engine/test/server.test.js +256 -0
- package/engine/test/stills-browser.test.js +70 -0
- package/engine/test/subtitles.test.js +83 -0
- package/engine/test/timeline.test.js +31 -0
- package/engine/test/transparent-browser.test.js +123 -0
- package/engine/test/ui-kit.test.js +96 -0
- package/engine/test/upload-browser.test.js +55 -0
- package/engine/test/voice-providers.test.js +338 -0
- package/lib/host.mjs +480 -0
- package/manifest.json +54 -0
- package/package.json +8 -4
- package/skills/biutalk/SKILL.md +21 -0
- package/studio/app.js +209 -0
- package/studio/assert-panel-permit.mjs +67 -0
- package/studio/composer.css +354 -0
- package/studio/composer.js +169 -0
- package/studio/index.html +82 -0
- package/studio/looks/blueprint.svg +21 -0
- package/studio/looks/chalk.svg +15 -0
- package/studio/looks/clean.svg +20 -0
- package/studio/looks/editorial.svg +18 -0
- package/studio/looks/midnight.svg +17 -0
- package/studio/looks/paper.svg +11 -0
- package/studio/select-menu.js +268 -0
- package/studio/styles.css +4 -0
- package/README.md +0 -3
|
@@ -0,0 +1,90 @@
|
|
|
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 { execFile } from 'node:child_process';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { findChrome } from '../src/browser.js';
|
|
10
|
+
import { capture } from '../src/capture.js';
|
|
11
|
+
import { normalizeConfig } from '../src/project.js';
|
|
12
|
+
import { captureFixture } from './capture-fixture.js';
|
|
13
|
+
|
|
14
|
+
let chrome;
|
|
15
|
+
try { chrome = findChrome(); } catch {}
|
|
16
|
+
const bin = fileURLToPath(new URL('../bin/explainroo.js', import.meta.url));
|
|
17
|
+
const run = promisify(execFile);
|
|
18
|
+
const dimensions = (file) => {
|
|
19
|
+
const png = fs.readFileSync(file);
|
|
20
|
+
return [png.readUInt32BE(16), png.readUInt32BE(20)];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
test('capture saves a local site, its loaded fonts and desktop and phone screenshots', { skip: !chrome }, async () => {
|
|
24
|
+
const site = await captureFixture();
|
|
25
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-capture-'));
|
|
26
|
+
try {
|
|
27
|
+
const config = '{"title":"Existing project"}\n';
|
|
28
|
+
fs.writeFileSync(path.join(dir, 'video.json'), config);
|
|
29
|
+
fs.mkdirSync(path.join(dir, 'assets'));
|
|
30
|
+
fs.writeFileSync(path.join(dir, 'assets', 'keep.txt'), 'Keep this file');
|
|
31
|
+
const result = await capture(dir, `${site.url}/redirect`, { mobile: true, googleHostCheck: (host) => host === '127.0.0.1' });
|
|
32
|
+
const root = path.join(dir, 'assets/capture/127.0.0.1');
|
|
33
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(root, 'capture.json'))), result);
|
|
34
|
+
assert.equal(result.url, `${site.url}/`);
|
|
35
|
+
assert.equal(result.title, 'Fixture Studio');
|
|
36
|
+
assert.equal(result.description, 'A local page for capture tests.');
|
|
37
|
+
assert.equal(result.themeColor, '#245cff');
|
|
38
|
+
assert.equal(result.colors.accent, '#245cff');
|
|
39
|
+
assert.equal(result.colors.background, '#f8f6f1');
|
|
40
|
+
assert.equal(result.colors.text, '#202020');
|
|
41
|
+
assert.equal(result.colors.heading, '#163469');
|
|
42
|
+
assert.equal(result.colors.link, '#245cff');
|
|
43
|
+
assert.ok(result.colors.other.length <= 6);
|
|
44
|
+
assert.equal(result.fonts.body, 'Fixture Sans');
|
|
45
|
+
assert.deepEqual(result.fonts.headings, ['Fixture Sans']);
|
|
46
|
+
assert.deepEqual(result.fonts.buttons, ['Fixture Sans']);
|
|
47
|
+
assert.equal(result.suggestion.fonts.length, 1);
|
|
48
|
+
assert.equal(result.suggestion.fonts[0].weight, 400);
|
|
49
|
+
assert.equal(site.requests.includes('/unused.woff2'), false);
|
|
50
|
+
assert.deepEqual(fs.readFileSync(path.join(dir, result.suggestion.fonts[0].src)), fs.readFileSync(path.join(site.dir, 'fixture.woff2')));
|
|
51
|
+
assert.deepEqual(result.text.h1, ['Build a clear product demo']);
|
|
52
|
+
assert.deepEqual(result.text.h2, ['Your brand on every screen', 'Capture once, use the files']);
|
|
53
|
+
assert.deepEqual(result.text.navigation, ['Features', 'Plans']);
|
|
54
|
+
assert.deepEqual(result.text.buttons, ['Start a project', 'See examples', 'Create project']);
|
|
55
|
+
assert.deepEqual(result.text.labels, ['Project name']);
|
|
56
|
+
assert.deepEqual(result.text.placeholders, ['My first demo']);
|
|
57
|
+
assert.equal(result.brand.logo, 'assets/capture/127.0.0.1/logo.svg');
|
|
58
|
+
assert.equal(result.logo.picked, result.brand.logo);
|
|
59
|
+
assert.deepEqual(result.logo.candidates.map((c) => path.basename(c.file)), ['logo.svg', 'logo-2.svg', 'logo-3.png']);
|
|
60
|
+
assert.match(fs.readFileSync(path.join(root, 'logo.svg'), 'utf8'), /xmlns="http:\/\/www.w3.org\/2000\/svg"/);
|
|
61
|
+
assert.match(fs.readFileSync(path.join(root, 'logo.svg'), 'utf8'), /fill: rgb\(36, 92, 255\)/);
|
|
62
|
+
assert.doesNotMatch(fs.readFileSync(path.join(root, 'logo.svg'), 'utf8'), /currentColor/i);
|
|
63
|
+
assert.deepEqual(dimensions(path.join(root, 'page.png')), [2880, 1800]);
|
|
64
|
+
assert.deepEqual(dimensions(path.join(root, 'full.png')), [2880, 16000]);
|
|
65
|
+
assert.deepEqual(dimensions(path.join(root, 'mobile.png')), [780, 1688]);
|
|
66
|
+
assert.deepEqual(dimensions(path.join(root, 'mobile-full.png')), [780, 16000]);
|
|
67
|
+
assert.ok(result.files.every((file) => fs.existsSync(path.join(dir, file))));
|
|
68
|
+
assert.deepEqual(normalizeConfig(result.suggestion).brand, result.brand);
|
|
69
|
+
assert.equal(fs.readFileSync(path.join(dir, 'video.json'), 'utf8'), config);
|
|
70
|
+
assert.equal(fs.readFileSync(path.join(dir, 'assets', 'keep.txt'), 'utf8'), 'Keep this file');
|
|
71
|
+
await assert.rejects(capture(dir, `${site.url}/missing`), /page did not load/);
|
|
72
|
+
assert.ok(fs.existsSync(path.join(root, 'mobile.png')));
|
|
73
|
+
fs.writeFileSync(path.join(root, 'stale.txt'), 'old capture');
|
|
74
|
+
const cli = await run(process.execPath, [bin, 'capture', dir, site.url, '--json'], { timeout: 60000 });
|
|
75
|
+
const json = JSON.parse(cli.stdout);
|
|
76
|
+
assert.equal(json.colors.accent, '#245cff');
|
|
77
|
+
assert.equal(json.suggestion.fonts.length, 0);
|
|
78
|
+
assert.match(json.notes.join(' '), /Fixture Sans: get the font files and check the license/);
|
|
79
|
+
assert.equal(fs.existsSync(path.join(root, 'stale.txt')), false);
|
|
80
|
+
assert.equal(fs.existsSync(path.join(root, 'mobile.png')), false);
|
|
81
|
+
const human = await run(process.execPath, [bin, 'capture', '--mobile', site.url], { cwd: dir, timeout: 60000 });
|
|
82
|
+
assert.match(human.stdout, /accent: #245cff/);
|
|
83
|
+
assert.match(human.stdout, /logo: assets\/capture\/127.0.0.1\/logo.svg/);
|
|
84
|
+
assert.match(human.stdout, /Paste into video.json:/);
|
|
85
|
+
assert.ok(fs.existsSync(path.join(root, 'mobile.png')));
|
|
86
|
+
} finally {
|
|
87
|
+
await site.close();
|
|
88
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
89
|
+
}
|
|
90
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import http from 'node:http';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
export async function captureFixture() {
|
|
8
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-capture-site-'));
|
|
9
|
+
fs.copyFileSync(fileURLToPath(new URL('../fonts/Inter-400-latin.woff2', import.meta.url)), path.join(dir, 'fixture.woff2'));
|
|
10
|
+
fs.writeFileSync(path.join(dir, 'icon.svg'), '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" fill="#245cff"/></svg>');
|
|
11
|
+
const png = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aK3sAAAAASUVORK5CYII=', 'base64');
|
|
12
|
+
for (const name of ['touch.png', 'social.png']) fs.writeFileSync(path.join(dir, name), png);
|
|
13
|
+
const requests = [];
|
|
14
|
+
// A second local origin makes the font stylesheet's CSSOM unreadable.
|
|
15
|
+
const styles = http.createServer((req, res) => {
|
|
16
|
+
requests.push(req.url);
|
|
17
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
18
|
+
if (req.url === '/font.css') {
|
|
19
|
+
res.setHeader('Content-Type', 'text/css');
|
|
20
|
+
return res.end("@font-face { font-family: 'Fixture Sans'; src: url('fixture.woff2'); font-weight: 400; } @font-face { font-family: 'Fixture Sans'; src: url('unused.woff2'); font-weight: 900; }");
|
|
21
|
+
}
|
|
22
|
+
if (req.url === '/fixture.woff2') {
|
|
23
|
+
res.setHeader('Content-Type', 'font/woff2');
|
|
24
|
+
return res.end(fs.readFileSync(path.join(dir, 'fixture.woff2')));
|
|
25
|
+
}
|
|
26
|
+
res.writeHead(404);
|
|
27
|
+
res.end('Not found');
|
|
28
|
+
});
|
|
29
|
+
await new Promise((resolve) => styles.listen(0, '127.0.0.1', resolve));
|
|
30
|
+
const html = fs.readFileSync(fileURLToPath(new URL('./fixtures/capture.html', import.meta.url)), 'utf8');
|
|
31
|
+
fs.writeFileSync(path.join(dir, 'index.html'), html.replace('__FONT_CSS__', `http://127.0.0.1:${styles.address().port}/font.css`));
|
|
32
|
+
const server = http.createServer((req, res) => {
|
|
33
|
+
requests.push(req.url);
|
|
34
|
+
if (req.url === '/redirect') { res.writeHead(302, { Location: '/' }); return res.end(); }
|
|
35
|
+
const name = req.url === '/' ? 'index.html' : ['/fixture.woff2', '/icon.svg', '/touch.png', '/social.png'].includes(req.url) ? req.url.slice(1) : null;
|
|
36
|
+
if (!name) { res.writeHead(404); return res.end('Not found'); }
|
|
37
|
+
const type = { '.html': 'text/html', '.woff2': 'font/woff2', '.png': 'image/png', '.svg': 'image/svg+xml' }[path.extname(name)];
|
|
38
|
+
res.writeHead(200, { 'Content-Type': type });
|
|
39
|
+
res.end(fs.readFileSync(path.join(dir, name)));
|
|
40
|
+
});
|
|
41
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
|
42
|
+
return { dir, requests, url: `http://127.0.0.1:${server.address().port}`, close: async () => {
|
|
43
|
+
await Promise.all([server, styles].map((s) => new Promise((resolve) => { s.closeAllConnections(); s.close(resolve); })));
|
|
44
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
45
|
+
} };
|
|
46
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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 { capture, validateUrl, pickColors, rankLogos, isGoogleFont } from '../src/capture.js';
|
|
7
|
+
|
|
8
|
+
test('capture accepts only HTTP URLs without login credentials', () => {
|
|
9
|
+
assert.equal(validateUrl('https://example.com/demo').hostname, 'example.com');
|
|
10
|
+
assert.equal(validateUrl('http://127.0.0.1:1234/').port, '1234');
|
|
11
|
+
for (const value of ['file:///tmp/page.html', 'data:text/html,hello', 'ftp://example.com', 'example.com', '', undefined, 'http://../']) {
|
|
12
|
+
assert.throws(() => validateUrl(value), /http:\/\/ or https:\/\//);
|
|
13
|
+
}
|
|
14
|
+
assert.throws(() => validateUrl('https://user:pass@example.com'), /does not log in/);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('accent counts saturated button backgrounds by area and frequency', () => {
|
|
18
|
+
const samples = [
|
|
19
|
+
{ color: '#eeeeee', area: 9000 }, { color: '#070707', area: 9000 }, { color: '#888888', area: 9000 },
|
|
20
|
+
{ color: '#245CFF', area: 200 }, { color: '#245cff', area: 200 }, { color: '#00aa22', area: 700 },
|
|
21
|
+
{ color: '#fffefa', area: 9000 }, { color: null, area: 20 }, { color: '#aa0000', area: 0 },
|
|
22
|
+
{ color: '#ee0000', area: 10 }, { color: '#ee00ee', area: 10 },
|
|
23
|
+
];
|
|
24
|
+
const colors = pickColors(samples, ['#888888']);
|
|
25
|
+
assert.equal(colors.accent, '#245cff');
|
|
26
|
+
assert.equal(colors.other.some((c) => c.color === '#888888'), false);
|
|
27
|
+
assert.equal(colors.other.length, 6);
|
|
28
|
+
assert.ok(colors.other.every((c) => c.share >= 0 && c.share <= 1));
|
|
29
|
+
assert.deepEqual(pickColors([]), { accent: null, other: [] });
|
|
30
|
+
assert.equal(pickColors([{ color: '#aaaaaa' }]).accent, null);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('logos prefer brand SVGs, SVG icons, large PNGs, then the social image', () => {
|
|
34
|
+
const candidates = [
|
|
35
|
+
{ url: 'social.png', type: 'png', kind: 'og', area: 100000 },
|
|
36
|
+
{ url: 'small.png', type: 'png', kind: 'icon', area: 256 },
|
|
37
|
+
{ url: 'large.png', type: 'png', kind: 'icon', area: 10000 },
|
|
38
|
+
{ url: 'icon.svg', type: 'svg', kind: 'icon', area: 64 },
|
|
39
|
+
{ svg: '<svg/>', type: 'svg', kind: 'brand', area: 32 },
|
|
40
|
+
{ url: 'large.png', type: 'png', kind: 'icon', area: 10000 },
|
|
41
|
+
{ url: 'photo.jpg', type: 'jpg', kind: 'og', area: 200000 },
|
|
42
|
+
];
|
|
43
|
+
assert.deepEqual(rankLogos(candidates).map((c) => c.url || c.svg), ['<svg/>', 'icon.svg', 'large.png', 'small.png', 'social.png']);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('Google font downloads require the exact source host', () => {
|
|
47
|
+
assert.equal(isGoogleFont('https://fonts.gstatic.com/s/inter/v1/font.woff2'), true);
|
|
48
|
+
for (const url of ['https://fonts.googleapis.com/style.css', 'https://fonts.gstatic.com.evil.test/font.woff2', 'https://evil.test/fonts.gstatic.com/a', 'file://fonts.gstatic.com/a', 'bad']) assert.equal(isGoogleFont(url), false);
|
|
49
|
+
assert.equal(isGoogleFont('http://127.0.0.1/font.woff2', (host) => host === '127.0.0.1'), true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('capture refuses to write through a linked assets folder', async () => {
|
|
53
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-capture-link-'));
|
|
54
|
+
try {
|
|
55
|
+
fs.mkdirSync(path.join(dir, 'project'));
|
|
56
|
+
fs.mkdirSync(path.join(dir, 'outside'));
|
|
57
|
+
fs.writeFileSync(path.join(dir, 'project', 'video.json'), '{}');
|
|
58
|
+
fs.symlinkSync(path.join(dir, 'outside'), path.join(dir, 'project', 'assets'), 'junction');
|
|
59
|
+
await assert.rejects(capture(path.join(dir, 'project'), 'http://127.0.0.1'), /not a link or file/);
|
|
60
|
+
assert.deepEqual(fs.readdirSync(path.join(dir, 'outside')), []);
|
|
61
|
+
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
|
62
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { buildChapters, chapterHints, toChaptersText, toChapterMetadata } from '../src/chapters.js';
|
|
4
|
+
|
|
5
|
+
const timeline = { duration: 40, scenes: [
|
|
6
|
+
{ id: 'intro', start: 0, attrs: {} },
|
|
7
|
+
{ id: 'first', start: 12, attrs: { chapter: 'First chapter' } },
|
|
8
|
+
{ id: 'second', start: 26, attrs: { chapter: 'Second chapter' } },
|
|
9
|
+
] };
|
|
10
|
+
|
|
11
|
+
test('chapters start on named scenes and fill the opening with the video title', () => {
|
|
12
|
+
assert.deepEqual(buildChapters(timeline, 'Video title'), [
|
|
13
|
+
{ title: 'Video title', scene: 'intro', start: 0, end: 12 },
|
|
14
|
+
{ title: 'First chapter', scene: 'first', start: 12, end: 26 },
|
|
15
|
+
{ title: 'Second chapter', scene: 'second', start: 26, end: 40 },
|
|
16
|
+
]);
|
|
17
|
+
assert.equal(timeline.scenes[0].attrs.chapter, undefined);
|
|
18
|
+
const namedIntro = { ...timeline, scenes: [{ ...timeline.scenes[0], attrs: { chapter: 'Opening' } }, ...timeline.scenes.slice(1)] };
|
|
19
|
+
assert.equal(buildChapters(namedIntro, 'Video title')[0].title, 'Opening');
|
|
20
|
+
assert.deepEqual(buildChapters({ scenes: [{ start: 0, attrs: {} }] }, 'Title'), []);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('YouTube hints explain ignored chapters without warnings', () => {
|
|
24
|
+
const chapters = buildChapters(timeline, 'Title');
|
|
25
|
+
assert.deepEqual(chapterHints(chapters), []);
|
|
26
|
+
assert.deepEqual(chapterHints([]), []);
|
|
27
|
+
const hints = chapterHints([{ title: 'Short', scene: 'a', start: 0, end: 9.99 }]);
|
|
28
|
+
assert.equal(hints.length, 2);
|
|
29
|
+
assert.ok(hints.every((h) => h.level === 'hint' && /YouTube shows chapters only when/.test(h.message)));
|
|
30
|
+
assert.match(hints[0].message, /3 chapters/);
|
|
31
|
+
assert.match(hints[1].message, /10 seconds/);
|
|
32
|
+
assert.equal(chapterHints([{ start: 0, end: 10 }]).length, 1);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('chapter text uses m:ss below an hour and h:mm:ss from an hour', () => {
|
|
36
|
+
assert.equal(toChaptersText([{ start: 0, title: 'Opening' }, { start: 65.9, title: 'Next' }, { start: 3599, title: 'Later' }, { start: 3600, title: 'Hour' }, { start: 7325, title: 'End' }]), '0:00 Opening\n1:05 Next\n59:59 Later\n1:00:00 Hour\n2:02:05 End\n');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('ffmetadata keeps millisecond boundaries and escapes special title characters', () => {
|
|
40
|
+
assert.equal(toChapterMetadata([{ start: 0, end: 12.345, title: 'A=B; #C\\D' }]), ';FFMETADATA1\n[CHAPTER]\nTIMEBASE=1/1000\nSTART=0\nEND=12345\ntitle=A\\=B\\; \\#C\\\\D\n');
|
|
41
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
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 } from '../src/export.js';
|
|
7
|
+
import { cacheRoot } from '../src/models.js';
|
|
8
|
+
import { languageFonts } from '../src/fonts.js';
|
|
9
|
+
import { findChrome } from '../src/browser.js';
|
|
10
|
+
import { loadProject, THEMES } from '../src/project.js';
|
|
11
|
+
import { buildTimeline } from '../src/timeline.js';
|
|
12
|
+
import { withEngine } from '../src/pipeline.js';
|
|
13
|
+
|
|
14
|
+
let chrome;
|
|
15
|
+
try { chrome = findChrome(); } catch {}
|
|
16
|
+
|
|
17
|
+
for (const language of ['ja', 'zh']) {
|
|
18
|
+
const cached = languageFonts(language).every(f => fs.existsSync(f.path));
|
|
19
|
+
test(`${language} uses cached Noto glyphs in every look and UI, with word and phrase cues`, { skip: !chrome || !cached }, async t => {
|
|
20
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-cjk-browser-'));
|
|
21
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
22
|
+
fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ language, captions: true, sfx: false }));
|
|
23
|
+
fs.writeFileSync(path.join(dir, 'script.md'), '## demo\n解析住所');
|
|
24
|
+
fs.writeFileSync(path.join(dir, 'scenes.js'), `export default { demo(s) { s.text('解析', { at: '解析' }); } };`);
|
|
25
|
+
const project = loadProject(dir);
|
|
26
|
+
const timeline = buildTimeline(project, { demo: { duration: 2, words: [{ text: '解析', start: 0, end: 1 }, { text: '住所', start: 1, end: 2 }], marks: {} } });
|
|
27
|
+
const out = path.join(dir, 'player');
|
|
28
|
+
const sentence = language === 'ja' ? '日本語の解析が始まります。' : '中文解析开始了。';
|
|
29
|
+
copyPlayer(project, timeline, { assets: [], fonts: [], math: {}, text: sentence }, out);
|
|
30
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(out, 'fonts/fonts.json')));
|
|
31
|
+
assert.deepEqual(manifest.map(f => f.weight), [400, 700]);
|
|
32
|
+
const subsets = languageFonts(language).map(f => fs.readFileSync(path.join(out, 'fonts', f.file)));
|
|
33
|
+
for (const data of subsets) {
|
|
34
|
+
assert.equal(data.subarray(0, 4).toString(), 'OTTO');
|
|
35
|
+
assert.ok(data.length < 100_000, `${data.length} bytes`);
|
|
36
|
+
}
|
|
37
|
+
assert.deepEqual(fs.readFileSync(path.join(out, 'fonts/licenses/NotoSansCJK-OFL.txt')), fs.readFileSync(path.join(cacheRoot(), 'fonts', 'NotoSansCJK-OFL.txt')));
|
|
38
|
+
await withEngine(project, timeline, {}, async (page, { server }) => {
|
|
39
|
+
const result = await page.evaluate(async ([language, themes, sentence, subsets]) => {
|
|
40
|
+
const { getTheme, fontString } = await import('/engine/themes.js');
|
|
41
|
+
const { UI } = await import('/engine/ui.js');
|
|
42
|
+
const { Stage } = await import('/engine/stage.js');
|
|
43
|
+
let i = 0;
|
|
44
|
+
// The exported player's reduced fonts still draw every character of the video.
|
|
45
|
+
for (const [k, data] of subsets.entries()) {
|
|
46
|
+
const face = new FontFace('Exported', Uint8Array.from(atob(data), c => c.charCodeAt(0)), { weight: String(400 + k * 300) });
|
|
47
|
+
document.fonts.add(await face.load());
|
|
48
|
+
for (const text of [sentence, '解析住所']) {
|
|
49
|
+
const span = document.createElement('div');
|
|
50
|
+
span.id = 'glyph' + i++;
|
|
51
|
+
span.style.font = `${400 + k * 300} 48px Exported, serif`;
|
|
52
|
+
span.textContent = text;
|
|
53
|
+
document.body.append(span);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const theme of themes) {
|
|
57
|
+
const fonts = ['display', 'body', 'hand', 'mono'].map(role => fontString(getTheme(theme), role, 48));
|
|
58
|
+
fonts.push(UI.prototype.fontString.call({ font: 'Inter' }, 48));
|
|
59
|
+
for (const font of fonts) {
|
|
60
|
+
const span = document.createElement('div');
|
|
61
|
+
span.id = 'glyph' + i++;
|
|
62
|
+
span.style.font = font;
|
|
63
|
+
span.textContent = sentence;
|
|
64
|
+
document.body.append(span);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
await new Promise(resolve => requestAnimationFrame(resolve));
|
|
68
|
+
const s = Object.create(Stage.prototype);
|
|
69
|
+
s.engine = { config: { language } };
|
|
70
|
+
s.words = [{ text: '解析', start: 0.35, end: 1.35 }, { text: '住所', start: 1.35, end: 2.35 }];
|
|
71
|
+
assertCue(s.cue('解析'), 0.35);
|
|
72
|
+
assertCue(s.cueEnd('解析住所'), 2.35);
|
|
73
|
+
s.words.push({ text: '名前の解析', start: 2.5, end: 3 });
|
|
74
|
+
assertCue(s.cue('名前の解析'), 2.5);
|
|
75
|
+
let rejected = false;
|
|
76
|
+
try { s.cue('名前'); } catch { rejected = true; }
|
|
77
|
+
if (!rejected) throw new Error('cue broke inside a word');
|
|
78
|
+
function assertCue(actual, expected) { if (actual !== expected) throw new Error(`cue ${actual} != ${expected}`); }
|
|
79
|
+
return { count: i, issues: window.explainroo.check() };
|
|
80
|
+
}, [language, THEMES, sentence, subsets.map(data => data.toString('base64'))]);
|
|
81
|
+
assert.deepEqual(result.issues.filter(i => i.level === 'error'), []);
|
|
82
|
+
const cdp = await page.context().newCDPSession(page);
|
|
83
|
+
await cdp.send('DOM.enable');
|
|
84
|
+
await cdp.send('CSS.enable');
|
|
85
|
+
const { root } = await cdp.send('DOM.getDocument');
|
|
86
|
+
for (let i = 0; i < result.count; i++) {
|
|
87
|
+
const { nodeId } = await cdp.send('DOM.querySelector', { nodeId: root.nodeId, selector: '#glyph' + i });
|
|
88
|
+
const { fonts } = await cdp.send('CSS.getPlatformFontsForNode', { nodeId });
|
|
89
|
+
assert.ok(fonts.every(f => f.isCustomFont), JSON.stringify(fonts));
|
|
90
|
+
assert.ok(fonts.some(f => f.familyName === (language === 'ja' ? 'Noto Sans CJK JP' : 'Noto Sans CJK SC')), JSON.stringify(fonts));
|
|
91
|
+
}
|
|
92
|
+
assert.equal((await fetch(server.url + '/language-fonts/' + language + '-400.otf')).status, 200);
|
|
93
|
+
const other = language === 'ja' ? 'zh' : 'ja';
|
|
94
|
+
if (languageFonts(other).every(f => fs.existsSync(f.path))) {
|
|
95
|
+
project.config.language = other;
|
|
96
|
+
assert.equal((await fetch(server.url + '/language-fonts/' + other + '-400.otf')).status, 200);
|
|
97
|
+
}
|
|
98
|
+
for (const file of ['NotoSansCJK-OFL.txt', 'ja-400.otf.part', '%2e%2e%2fmodels%2fconfig.json']) assert.equal((await fetch(server.url + '/language-fonts/' + file)).status, 404);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
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 { tokenizeNarration, parseScript, speechChunks, normWord, resolveMarks } from '../src/script.js';
|
|
7
|
+
import { alignWords, readAlike, spreadReadings } from '../src/align.js';
|
|
8
|
+
import { subtitleCues, toSrt, toVtt } from '../src/subtitles.js';
|
|
9
|
+
import { buildPhrases, drawCaptions, clingsToPrevious } from '../engine/captions.js';
|
|
10
|
+
import { getTheme } from '../engine/themes.js';
|
|
11
|
+
import { phonemize, misakiAvailable } from '../src/phonemes.js';
|
|
12
|
+
import { languageFonts, ensureFonts } from '../src/fonts.js';
|
|
13
|
+
import { cacheRoot } from '../src/models.js';
|
|
14
|
+
import { normalizeConfig } from '../src/project.js';
|
|
15
|
+
import { buildTimeline } from '../src/timeline.js';
|
|
16
|
+
|
|
17
|
+
function env(t, key, value) {
|
|
18
|
+
const previous = process.env[key];
|
|
19
|
+
process.env[key] = value;
|
|
20
|
+
t.after(() => { if (previous === undefined) delete process.env[key]; else process.env[key] = previous; });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const native = { ja: '住所を解析します。次の画面を表示します!終わりです?', zh: '浏览器解析地址。下一步显示网页!完成了吗?' };
|
|
24
|
+
|
|
25
|
+
for (const [language, text] of Object.entries(native)) {
|
|
26
|
+
test(`${language} segments words, keeps punctuation and preserves markers and overrides`, () => {
|
|
27
|
+
const units = tokenizeNarration('[#first]' + text + '[pause 0.4][#last]{住所|じゅうしょ}です。', 0, language);
|
|
28
|
+
const words = units.filter(u => u.type === 'word');
|
|
29
|
+
assert.equal(words.map(w => w.display).join(''), text + '住所です。');
|
|
30
|
+
assert.ok(words.some(w => w.display === '解析'));
|
|
31
|
+
assert.deepEqual(words.find(w => w.display === '住所' && w.spoken !== w.display), { type: 'word', display: '住所', spoken: 'じゅうしょ', space: true });
|
|
32
|
+
assert.equal(normWord('解析。'), '解析');
|
|
33
|
+
assert.deepEqual(tokenizeNarration('次に「解析」を行う。', 0, language).filter(u => u.type === 'word').map(u => u.display).join(''), '次に「解析」を行う。');
|
|
34
|
+
assert.ok(tokenizeNarration('次に「解析」を行う。', 0, language).filter(u => u.type === 'word').every(u => normWord(u.display)));
|
|
35
|
+
assert.deepEqual(tokenizeNarration('{住所|じゅうしょ}。次。', 0, language).filter(u => u.type === 'word').map(u => u.display), ['住所。', '次。']);
|
|
36
|
+
assert.deepEqual(speechChunks(tokenizeNarration('{住所|じゅうしょ}。「解析」。', 0, language), { language }).map(c => c.text), ['じゅうしょ。', '「解析」。']);
|
|
37
|
+
assert.equal(normWord('が'), normWord('が'.normalize('NFD')));
|
|
38
|
+
const times = units.map((u, i) => u.type === 'word' ? { start: i, end: i + 0.5 } : null);
|
|
39
|
+
assert.equal(resolveMarks(units, times).first, 1);
|
|
40
|
+
assert.equal(resolveMarks(units, times).last, units.findIndex(u => u.spoken === 'じゅうしょ'));
|
|
41
|
+
const chunks = speechChunks(units, { language });
|
|
42
|
+
assert.deepEqual(chunks.map(c => c.text), [...text.match(/[^。!?]+[。!?]/g), 'じゅうしょです。']);
|
|
43
|
+
assert.equal(chunks.at(-1).gapBefore, 0.7);
|
|
44
|
+
assert.equal(parseScript('## intro\n' + text, { language }).scenes[0].text, text);
|
|
45
|
+
for (const ending of ['。', '!', '?', '.', '!', '?']) {
|
|
46
|
+
assert.equal(speechChunks(tokenizeNarration(`解析${ending}解析${ending}`, 0, language), { language }).length, 2);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test(`${language} alignment ignores Whisper word boundaries and times each word's characters`, () => {
|
|
51
|
+
const words = [{ spoken: '解析' }, { spoken: '地址。' }];
|
|
52
|
+
const whole = alignWords(words, [{ text: '解析地址', start: 0.2, end: 1 }], 1.2, language);
|
|
53
|
+
const single = alignWords(words, [...'解析地址'].map((text, i) => ({ text, start: 0.2 + i * 0.2, end: 0.4 + i * 0.2 })), 1.2, language);
|
|
54
|
+
assert.equal(whole.matchRate, 1);
|
|
55
|
+
assert.deepEqual(whole.words, single.words);
|
|
56
|
+
assert.ok(Math.abs(whole.words[0].start - 0.2) < 1e-9);
|
|
57
|
+
assert.ok(Math.abs(whole.words[0].end - 0.6) < 1e-9);
|
|
58
|
+
const shown = alignWords([{ spoken: 'じゅうしょ', display: '住所' }, { spoken: 'です。' }], [{ text: '住所です', start: 0, end: 1 }], 1, language);
|
|
59
|
+
assert.equal(shown.matchRate, 1);
|
|
60
|
+
assert.ok(shown.words.every(w => w.matched));
|
|
61
|
+
const missing = alignWords([{ spoken: '解析' }, { spoken: '地' }, { spoken: '址' }], [{ text: '解析址', start: 0, end: 0.9 }], 1, language);
|
|
62
|
+
assert.equal(missing.matchRate, 0.75);
|
|
63
|
+
assert.equal(missing.words[1].matched, false);
|
|
64
|
+
assert.ok(missing.words.every(w => w.start <= w.end));
|
|
65
|
+
assert.equal(alignWords([{ spoken: 'かな' }], [{ text: 'かな'.normalize('NFD'), start: 0, end: 1 }], 1, language).matchRate, 1);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test(`${language} captions and subtitles join without spaces and limit lines at word boundaries`, () => {
|
|
69
|
+
const text = native[language].repeat(3);
|
|
70
|
+
const words = tokenizeNarration(text, 0, language).filter(u => u.type === 'word').map((u, i) => ({ text: u.display, start: i * 0.2, end: (i + 1) * 0.2 }));
|
|
71
|
+
const timeline = buildTimeline({ config: normalizeConfig({ language, captions: true }), script: parseScript('## intro\n' + text, { language }) }, { intro: { duration: words.length * 0.2, words, marks: {} } });
|
|
72
|
+
const cues = subtitleCues(timeline);
|
|
73
|
+
assert.equal(cues.map(c => c.text.replaceAll('\n', '')).join(''), text);
|
|
74
|
+
assert.ok(cues.every(c => c.text.split('\n').every(line => line.length <= 18)));
|
|
75
|
+
assert.ok(toSrt(cues).includes('解析'));
|
|
76
|
+
assert.ok(toVtt(cues).includes('解析'));
|
|
77
|
+
const phrases = buildPhrases(timeline, 46);
|
|
78
|
+
assert.equal(phrases.map(p => p.words.map(w => w.text).join(p.separator)).join(''), text);
|
|
79
|
+
assert.ok(phrases.every(p => p.words.map(w => w.text).join('').length <= 18));
|
|
80
|
+
const drawn = [];
|
|
81
|
+
const ctx = new Proxy({ measureText: text => ({ width: text.length * 44 }), fillText: (text, x) => drawn.push({ text, x }) }, { get: (o, key) => o[key] ?? (() => {}) });
|
|
82
|
+
drawCaptions(ctx, phrases, phrases[0].start + 0.1, getTheme('clean'), 1920, 1080);
|
|
83
|
+
assert.equal(drawn[1].x - drawn[0].x, drawn[0].text.length * 44);
|
|
84
|
+
const long = { language, scenes: [{ start: 0, words: Array.from({ length: 30 }, (_, i) => ({ text: '解析', start: i * 0.1, end: (i + 1) * 0.1 })) }] };
|
|
85
|
+
assert.ok(subtitleCues(long).every(c => c.text.split('\n').every(line => line.length <= 18 && line.length % 2 === 0)));
|
|
86
|
+
assert.throws(() => subtitleCues({ language, scenes: [{ words: [{ text: '長'.repeat(19) }] }] }), /longer than 18/);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
test('subtitle lines and caption phrases do not start with a Japanese or Chinese particle', () => {
|
|
91
|
+
const timed = list => list.map((text, i) => ({ text, start: i * 0.3, end: (i + 1) * 0.3 }));
|
|
92
|
+
const ja = timed(['地球', 'の', '動き', 'と', 'カレンダー', 'に', 'ズレ', 'が', 'たまり', 'ます。']);
|
|
93
|
+
const [cue] = subtitleCues({ language: 'ja', scenes: [{ start: 0, words: ja }] });
|
|
94
|
+
assert.equal(cue.text, '地球の動きとカレンダーに\nズレがたまります。');
|
|
95
|
+
const phrases = buildPhrases({ language: 'ja', scenes: [{ start: 0, words: ja }] }, 46);
|
|
96
|
+
assert.equal(phrases.length, 2);
|
|
97
|
+
assert.ok(phrases.every(p => !/^[\u3041-\u3096]/.test(p.words[0].text)), phrases.map(p => p.words.map(w => w.text).join('')).join(' / '));
|
|
98
|
+
const [counter] = subtitleCues({ language: 'ja', scenes: [{ start: 0, words: timed(['そこで、', '基本', 'は', '4', '年', 'ごと', 'に', '1', '日', 'を', '足し', 'ます。']) }] });
|
|
99
|
+
assert.equal(counter.text, 'そこで、基本は4年ごとに\n1日を足します。');
|
|
100
|
+
const clings = clingsToPrevious('ja');
|
|
101
|
+
for (const [text, before] of [['は', '基本'], ['せん', 'ありま'], ['ませんでした。', 'あり'], ['暦', 'グレゴリオ'], ['年', '4'], ['しょう', 'ので']]) assert.equal(clings(text, before), true, text);
|
|
102
|
+
for (const [text, before] of [['うるう年', 'は'], ['ありま', 'では'], ['足', 'を'], ['地球', 'の'], ['カレンダー', 'の'], ['1', 'に']]) assert.equal(clings(text, before), false, text);
|
|
103
|
+
// Breaking before or after に balances the lines equally; に stays with the word before.
|
|
104
|
+
const [even] = subtitleCues({ language: 'ja', scenes: [{ start: 0, words: timed(['アイウエオカキクケ', 'に', 'サシスセソタチツテ。']) }] });
|
|
105
|
+
assert.equal(even.text, 'アイウエオカキクケに\nサシスセソタチツテ。');
|
|
106
|
+
const zh = timed(['这', '是', '我们', '最', '常用', '的', '密码', '保存', '方法', '之一', ',', '也', '很', '安全', '的', '做法', '吗', '?']);
|
|
107
|
+
for (const p of buildPhrases({ language: 'zh', scenes: [{ start: 0, words: zh }] }, 46)) assert.ok(!['的', '吗'].includes(p.words[0].text), p.words.map(w => w.text).join(''));
|
|
108
|
+
for (const c of subtitleCues({ language: 'zh', scenes: [{ start: 0, words: zh }] })) for (const line of c.text.split('\n')) assert.ok(!/^[的吗]/.test(line), line);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('Mandarin alignment reads Traditional characters as Simplified, Japanese keeps them', () => {
|
|
112
|
+
const rate = language => alignWords([{ spoken: '浏览器' }, { spoken: '会询问网址。' }], [{ text: '瀏覽器會詢問網址', start: 0, end: 1.6 }], 1.6, language).matchRate;
|
|
113
|
+
assert.equal(rate('zh'), 1);
|
|
114
|
+
assert.equal(rate('ja'), 0.25);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('Mandarin alignment accepts a character with the same sound, not a different one', () => {
|
|
118
|
+
const words = [{ spoken: '哈希值' }, { spoken: '和' }, { spoken: '盐。' }];
|
|
119
|
+
const heard = text => [{ text, start: 0, end: 1 }];
|
|
120
|
+
// Whisper writes 直 for 值 and 研 for 盐; all are read zhi and yan.
|
|
121
|
+
assert.equal(alignWords(words, heard('哈希直和研'), 1, 'zh').matchRate, 1);
|
|
122
|
+
assert.equal(alignWords(words, heard('哈希職和研'), 1, 'zh').matchRate, 1);
|
|
123
|
+
const wrong = alignWords(words, heard('哈希值和鸡'), 1, 'zh');
|
|
124
|
+
assert.equal(wrong.matchRate, 0.8);
|
|
125
|
+
assert.equal(wrong.words[2].matched, false);
|
|
126
|
+
assert.equal(alignWords(words, heard('哈希直和研'), 1, 'ja').matchRate, 0.6);
|
|
127
|
+
const shown = alignWords([{ spoken: '哈希', display: '哈希值' }], heard('哈希直'), 1, 'zh');
|
|
128
|
+
assert.equal(shown.matchRate, 1);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('Japanese readings are shared out over the characters they cover', () => {
|
|
132
|
+
assert.deepEqual(spreadReadings(['うるう', '年', 'には'], [[0, 4, 'ウルードシ'], [4, 5, 'ニ'], [5, 6, 'ワ']]), ['ウルード', 'シ', 'ニワ']);
|
|
133
|
+
assert.deepEqual(spreadReadings(['ウルードシ', '、'], [[0, 5, 'うるーどし'], [5, 6, '、']]), ['ウルードシ', '、']);
|
|
134
|
+
assert.deepEqual(spreadReadings(['今日', 'は'], [[0, 2, 'キョー']]), ['キョー', '']);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('the Japanese speech check compares readings, and falls back to characters without Python', { skip: process.platform === 'win32' }, async t => {
|
|
138
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-readings-'));
|
|
139
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
140
|
+
const file = path.join(dir, 'python');
|
|
141
|
+
env(t, 'EXPLAINROO_PYTHON', file);
|
|
142
|
+
// A tiny dictionary: 世紀 and 正規 are both read セーキ.
|
|
143
|
+
fs.writeFileSync(file, `#!/usr/bin/env node
|
|
144
|
+
const assert = require('node:assert/strict');
|
|
145
|
+
assert.equal(process.argv[3], 'ja-readings');
|
|
146
|
+
const words = { 世紀: 'セーキ', 正規: 'セーキ', の: 'ノ', 年: 'トシ', とし: 'トシ' };
|
|
147
|
+
let input = '';
|
|
148
|
+
process.stdin.on('data', d => input += d);
|
|
149
|
+
process.stdin.on('end', () => {
|
|
150
|
+
for (const text of input.trimEnd().split('\\n').map(JSON.parse)) {
|
|
151
|
+
const out = [];
|
|
152
|
+
for (let i = 0; i < text.length;) {
|
|
153
|
+
const w = Object.keys(words).find(w => text.startsWith(w, i));
|
|
154
|
+
if (w) { out.push([i, i + w.length, words[w]]); i += w.length; } else i++;
|
|
155
|
+
}
|
|
156
|
+
console.log(JSON.stringify(out));
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
`, { mode: 0o755 });
|
|
160
|
+
const words = [{ spoken: '世紀', display: '世紀' }, { spoken: 'の', display: 'の' }, { spoken: '年。', display: '年。' }];
|
|
161
|
+
const heard = [{ text: '正規の', start: 0, end: 0.6 }, { text: 'とし', start: 0.6, end: 1 }];
|
|
162
|
+
const alike = await readAlike(words, heard, 'ja');
|
|
163
|
+
assert.deepEqual(alike.words.map(w => w.spoken), ['セーキ', 'ノ', 'トシ']);
|
|
164
|
+
assert.deepEqual(alike.heard.map(h => h.text), ['セーキノ', 'トシ']);
|
|
165
|
+
assert.equal(alignWords(alike.words, alike.heard, 1, 'ja').matchRate, 1);
|
|
166
|
+
assert.deepEqual(await readAlike(words, heard, 'zh'), { words, heard });
|
|
167
|
+
fs.rmSync(file);
|
|
168
|
+
assert.deepEqual(await readAlike(words, heard, 'ja'), { words, heard });
|
|
169
|
+
assert.ok(alignWords(words, heard, 1, 'ja').matchRate < 0.7);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('Python batches JSON lines without shell expansion and accepts misaki phonemes unchanged', { skip: process.platform === 'win32' }, async t => {
|
|
173
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-python-'));
|
|
174
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
175
|
+
const file = path.join(dir, 'fake python');
|
|
176
|
+
env(t, 'EXPLAINROO_PYTHON', file);
|
|
177
|
+
fs.writeFileSync(file, `#!/usr/bin/env node
|
|
178
|
+
const assert = require('node:assert/strict');
|
|
179
|
+
assert.equal(process.argv[2].endsWith('/g2p.py'), true);
|
|
180
|
+
assert.ok(['ja', 'zh'].includes(process.argv[3]));
|
|
181
|
+
let input = '';
|
|
182
|
+
process.stdin.on('data', d => input += d);
|
|
183
|
+
process.stdin.on('end', () => {
|
|
184
|
+
const texts = input.trimEnd().split('\\n').map(JSON.parse);
|
|
185
|
+
process.stdout.write(texts.map(t => JSON.stringify(t + '↗')).join('\\n') + '\\n');
|
|
186
|
+
});
|
|
187
|
+
`, { mode: 0o755 });
|
|
188
|
+
for (const language of ['ja', 'zh']) {
|
|
189
|
+
const texts = ['解析。\n次の行', '$( ) `*` "中文" $@'];
|
|
190
|
+
assert.deepEqual(await phonemize(texts, language), texts.map(t => t + '↗'));
|
|
191
|
+
assert.equal(misakiAvailable(language), true);
|
|
192
|
+
assert.deepEqual(await phonemize(['およそ365.2422日。'], language), [language === 'ja' ? 'およそ365点二四二二日。↗' : 'およそ365.2422日。↗']);
|
|
193
|
+
// Latin words are read as English between the misaki pieces.
|
|
194
|
+
assert.deepEqual(await phonemize(['我用JavaScript写代码。', 'API。'], language), ['我用↗ dʒˈɑːvə skɹˈɪpt 写代码。↗', 'ˌeɪpˌiːˈaɪ 。↗']);
|
|
195
|
+
}
|
|
196
|
+
fs.writeFileSync(file, '#!/usr/bin/env node\nconsole.log("not JSON");');
|
|
197
|
+
await assert.rejects(phonemize(['解析'], 'ja'), /incomplete phonemes/);
|
|
198
|
+
assert.equal(misakiAvailable('ja'), false);
|
|
199
|
+
fs.writeFileSync(file, '#!/usr/bin/env node\nconsole.log(JSON.stringify("one"));');
|
|
200
|
+
await assert.rejects(phonemize(['解析', '次'], 'ja'), /incomplete phonemes/);
|
|
201
|
+
fs.writeFileSync(file, '#!/usr/bin/env node\nconsole.error("ModuleNotFoundError: No module named \'misaki\'"); process.exit(1);');
|
|
202
|
+
await assert.rejects(phonemize(['解析'], 'zh'), /pip install "misaki\[zh\]".*Python said: ModuleNotFoundError: No module named 'misaki'/);
|
|
203
|
+
fs.chmodSync(file, 0o644);
|
|
204
|
+
await assert.rejects(phonemize(['解析'], 'ja'), /EXPLAINROO_PYTHON/);
|
|
205
|
+
fs.rmSync(file);
|
|
206
|
+
assert.equal(misakiAvailable('ja'), false);
|
|
207
|
+
await assert.rejects(phonemize(['解析'], 'ja'), /-m unidic download/);
|
|
208
|
+
assert.deepEqual(await phonemize([], 'ja'), []);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('font paths follow EXPLAINROO_CACHE, offline mode refuses missing or damaged fonts', async t => {
|
|
212
|
+
assert.equal(languageFonts('ja')[0].path, path.join(cacheRoot(), 'fonts', 'ja-400.otf'));
|
|
213
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-font-cache-'));
|
|
214
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
215
|
+
env(t, 'EXPLAINROO_CACHE', dir);
|
|
216
|
+
env(t, 'EXPLAINROO_OFFLINE', '1');
|
|
217
|
+
assert.deepEqual(languageFonts('en'), []);
|
|
218
|
+
for (const language of ['ja', 'zh']) {
|
|
219
|
+
const fonts = languageFonts(language);
|
|
220
|
+
assert.deepEqual(fonts.map(f => f.weight), [400, 700]);
|
|
221
|
+
assert.equal(fonts[0].path, path.join(dir, 'fonts', `${language}-400.otf`));
|
|
222
|
+
await assert.rejects(ensureFonts(language), /without EXPLAINROO_OFFLINE/);
|
|
223
|
+
fs.mkdirSync(path.join(dir, 'fonts'), { recursive: true });
|
|
224
|
+
fs.writeFileSync(fonts[0].path, 'OTTOcorrupt');
|
|
225
|
+
await assert.rejects(ensureFonts(language), /missing or damaged/);
|
|
226
|
+
}
|
|
227
|
+
await ensureFonts('en');
|
|
228
|
+
process.env.EXPLAINROO_OFFLINE = '0';
|
|
229
|
+
t.mock.method(globalThis, 'fetch', async () => ({ ok: true, arrayBuffer: async () => Buffer.from('OTTOcorrupt') }));
|
|
230
|
+
await assert.rejects(ensureFonts('ja'), /could not be downloaded or checked/);
|
|
231
|
+
assert.equal(fs.readFileSync(languageFonts('ja')[0].path, 'utf8'), 'OTTOcorrupt');
|
|
232
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { cacheRoot, TTS_MODEL, ASR_MODEL } from '../src/models.js';
|
|
8
|
+
|
|
9
|
+
const bin = fileURLToPath(new URL('../bin/explainroo.js', import.meta.url));
|
|
10
|
+
const run = (args) => spawnSync(process.execPath, [bin, ...args], { encoding: 'utf8', timeout: 120000 });
|
|
11
|
+
|
|
12
|
+
test('the CLI passes on exit codes', () => {
|
|
13
|
+
assert.equal(run(['nosuchcommand']).status, 2);
|
|
14
|
+
assert.equal(run(['check', path.join(cacheRoot(), 'no-such-project')]).status, 1);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// ONNX Runtime aborts with "mutex lock failed" on macOS when process.exit()
|
|
18
|
+
// runs while the models are loaded. doctor --fetch loads both.
|
|
19
|
+
const cached = [TTS_MODEL, ASR_MODEL].every((m) => fs.existsSync(path.join(cacheRoot(), 'models', m)));
|
|
20
|
+
test('the CLI exits cleanly after loading the speech models', { skip: !cached && 'speech models not downloaded' }, () => {
|
|
21
|
+
const r = run(['doctor', '--fetch']);
|
|
22
|
+
assert.doesNotMatch(r.stderr, /mutex lock failed/);
|
|
23
|
+
assert.equal(r.signal, null);
|
|
24
|
+
assert.equal(r.status, 0, r.stderr);
|
|
25
|
+
});
|