@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,80 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { contrast, parseColor, suggestColor } from '../engine/util.js';
|
|
4
|
+
|
|
5
|
+
test('suggestion darkens text on a light background while keeping hue and saturation', () => {
|
|
6
|
+
const { color, ratio } = suggestColor('#ffaaaa', '#ffffff');
|
|
7
|
+
const { r, g, b } = parseColor(color);
|
|
8
|
+
assert.match(color, /^#[0-9a-f]{6}$/);
|
|
9
|
+
assert.equal(g, b);
|
|
10
|
+
assert.equal(g, 0);
|
|
11
|
+
assert.ok(r < 255);
|
|
12
|
+
assert.ok(ratio >= 4.5);
|
|
13
|
+
assert.equal(ratio, contrast(color, '#ffffff'));
|
|
14
|
+
assert.ok(contrast(`#${(r + 1).toString(16)}0000`, '#ffffff') < 4.5);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('suggestion lightens text on a dark background while keeping hue and saturation', () => {
|
|
18
|
+
const { color, ratio } = suggestColor('#550000', '#0b1020');
|
|
19
|
+
const { r, g, b } = parseColor(color);
|
|
20
|
+
assert.equal(g, b);
|
|
21
|
+
assert.equal(g, 0);
|
|
22
|
+
assert.ok(r > 85);
|
|
23
|
+
assert.ok(ratio >= 4.5);
|
|
24
|
+
assert.equal(ratio, contrast(color, '#0b1020'));
|
|
25
|
+
assert.ok(contrast(`#${(r - 1).toString(16)}0000`, '#0b1020') < 4.5);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('already passing text keeps its color', () => {
|
|
29
|
+
for (const [fg, bg] of [['#123456', '#ffffff'], ['#abcdef', '#000000']]) {
|
|
30
|
+
assert.deepEqual(suggestColor(fg, bg, 32, { ink: '#000000' }), { color: fg, ratio: contrast(fg, bg) });
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('a passing named color close in hue wins over a hex adjustment', () => {
|
|
35
|
+
const colors = { ink: '#222222', accent: '#990000', red: '#550000' };
|
|
36
|
+
const result = suggestColor('#ffaaaa', '#ffffff', 32, colors);
|
|
37
|
+
assert.equal(result.color, 'accent');
|
|
38
|
+
assert.equal(result.ratio, contrast(colors.accent, '#ffffff'));
|
|
39
|
+
assert.equal(suggestColor('#aaaaaa', '#ffffff', 32, colors).color, 'ink');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('named colors must pass the target and match the hue', () => {
|
|
43
|
+
const result = suggestColor('#ffaaaa', '#ffffff', 32, { red: '#ff8888', blue: '#000099', ink: '#000000' });
|
|
44
|
+
assert.match(result.color, /^#/);
|
|
45
|
+
assert.ok(result.ratio >= 4.5);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('named hue matching wraps around red at zero degrees', () => {
|
|
49
|
+
const result = suggestColor('#ffaaaa', '#ffffff', 32, { pink: '#990019' });
|
|
50
|
+
assert.equal(result.color, 'pink');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('48px text targets 3:1 while smaller text targets 4.5:1', () => {
|
|
54
|
+
const small = suggestColor('#bbbbbb', '#ffffff', 47.99);
|
|
55
|
+
const large = suggestColor('#bbbbbb', '#ffffff', 48);
|
|
56
|
+
assert.equal(small.color, '#767676');
|
|
57
|
+
assert.equal(large.color, '#949494');
|
|
58
|
+
assert.ok(small.ratio >= 4.5);
|
|
59
|
+
assert.ok(large.ratio >= 3 && large.ratio < 4.5);
|
|
60
|
+
assert.equal(suggestColor('#888888', '#ffffff', 48).color, '#888888');
|
|
61
|
+
assert.equal(suggestColor('#bbbbbb', '#ffffff', 48, { gray: '#888888' }).color, 'gray');
|
|
62
|
+
assert.match(suggestColor('#bbbbbb', '#ffffff', 47, { gray: '#888888' }).color, /^#/);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('the closest passing lightness can be on either side of a middle background', () => {
|
|
66
|
+
assert.equal(suggestColor('#767676', '#767676').color, '#040404');
|
|
67
|
+
assert.equal(suggestColor('#999999', '#767676').color, '#fefefe');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('suggestions meet the target after hex rounding across hues and backgrounds', () => {
|
|
71
|
+
for (const fg of ['#fcba03', '#32aa70', '#79d4ea', '#8870ba', '#dd7f9e', '#808080']) {
|
|
72
|
+
for (const bg of ['#f7f3ea', '#0b1020', '#777777']) {
|
|
73
|
+
for (const size of [32, 48]) {
|
|
74
|
+
const result = suggestColor(fg, bg, size);
|
|
75
|
+
assert.ok(result.ratio >= (size >= 48 ? 3 : 4.5), `${fg} on ${bg}: ${result.color}`);
|
|
76
|
+
assert.equal(result.ratio, contrast(result.color, bg));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { planCamera, cameraAt, cameraMoving, compose, continues, frameRect, viewRect } from '../engine/director.js';
|
|
4
|
+
|
|
5
|
+
const frame = { W: 1920, H: 1080 };
|
|
6
|
+
const view = { x: 134, y: 76, w: 1652, h: 928 };
|
|
7
|
+
const el = (kind, x, y, w, h, at, out = Infinity) => ({ kind, at, out, box: { x: x + w / 2, y: y + h / 2, w, h } });
|
|
8
|
+
|
|
9
|
+
// Every card or label is fully inside the frame or fully outside it.
|
|
10
|
+
function cuts(shot, elements, margin = 1) {
|
|
11
|
+
const r = frameRect(shot, view, frame);
|
|
12
|
+
return elements.filter((e) => {
|
|
13
|
+
if (e.kind === 'arrow' || e.kind === 'line') return false;
|
|
14
|
+
const b = { x0: e.box.x - e.box.w / 2, x1: e.box.x + e.box.w / 2, y0: e.box.y - e.box.h / 2, y1: e.box.y + e.box.h / 2 };
|
|
15
|
+
const outside = b.x1 <= r.x0 + margin || b.x0 >= r.x1 - margin || b.y1 <= r.y0 + margin || b.y0 >= r.y1 - margin;
|
|
16
|
+
const inside = b.x0 >= r.x0 - margin && b.x1 <= r.x1 + margin && b.y0 >= r.y0 - margin && b.y1 <= r.y1 + margin;
|
|
17
|
+
return !inside && !outside;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const diagram = [
|
|
22
|
+
el('text', 760, 90, 400, 90, 0.1),
|
|
23
|
+
el('shape', 200, 450, 260, 140, 1.5),
|
|
24
|
+
el('arrow', 470, 500, 300, 40, 2.6),
|
|
25
|
+
el('shape', 780, 450, 260, 140, 2.8),
|
|
26
|
+
el('arrow', 1050, 500, 300, 40, 4.4),
|
|
27
|
+
el('shape', 1360, 450, 260, 140, 4.6),
|
|
28
|
+
el('text', 1360, 640, 260, 40, 6.2),
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
test('no elements means no camera', () => {
|
|
32
|
+
assert.equal(planCamera([], { dur: 5, view, frame }), null);
|
|
33
|
+
assert.equal(planCamera([el('shape', 0, 0, 1920, 1080, 0)], { dur: 5, view, frame }), null);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Zoom direction changes (in after out, or out after in) less than `gap`
|
|
37
|
+
// seconds apart.
|
|
38
|
+
function reversals(plan, gap = 5) {
|
|
39
|
+
let prev = null;
|
|
40
|
+
let n = 0;
|
|
41
|
+
for (const m of plan.moves) {
|
|
42
|
+
const dz = Math.log(m.to.z / m.from.z);
|
|
43
|
+
if (Math.abs(dz) < 0.1) continue;
|
|
44
|
+
if (prev && Math.sign(dz) !== prev.sign && m.start - prev.start < gap) n++;
|
|
45
|
+
prev = { sign: Math.sign(dz), start: m.start };
|
|
46
|
+
}
|
|
47
|
+
return n;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
test('a scene that starts small starts close and widens as the picture grows', () => {
|
|
51
|
+
const row = [0, 1, 2, 3].map((i) => el('shape', 260 + i * 380, 470, 220, 140, 0.5 + i * 3));
|
|
52
|
+
const plan = planCamera(row, { dur: 14, view, frame });
|
|
53
|
+
assert.ok(plan.start.z > 1.3, 'the first shot is close');
|
|
54
|
+
for (const m of plan.moves) assert.ok(m.to.z <= m.from.z + 1e-9, `no zooming in again at ${m.start}`);
|
|
55
|
+
const end = frameRect(cameraAt(plan, 13.9), view, frame);
|
|
56
|
+
for (const e of row) assert.ok(e.box.x - e.box.w / 2 >= end.x0 && e.box.x + e.box.w / 2 <= end.x1, 'the end shows everything');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('something new that already fits the shot needs no move', () => {
|
|
60
|
+
// A large chart, then a line and a label drawn inside it.
|
|
61
|
+
const chart = [
|
|
62
|
+
el('shape', 260, 160, 1400, 760, 0.2),
|
|
63
|
+
el('line', 560, 540, 800, 0, 3),
|
|
64
|
+
el('text', 900, 600, 160, 40, 6.5),
|
|
65
|
+
];
|
|
66
|
+
const plan = planCamera(chart, { dur: 11, view, frame });
|
|
67
|
+
assert.equal(plan.moves.length, 0);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('the camera pushes in on something small when there is time, not again right after, and pulls back at the end', () => {
|
|
71
|
+
const scene = [
|
|
72
|
+
el('shape', 200, 200, 600, 300, 0.2),
|
|
73
|
+
el('shape', 1100, 200, 600, 300, 0.2),
|
|
74
|
+
el('text', 1250, 700, 300, 50, 3),
|
|
75
|
+
el('text', 300, 700, 300, 50, 6.5),
|
|
76
|
+
];
|
|
77
|
+
const plan = planCamera(scene, { dur: 13, view, frame, voiceEnd: 11 });
|
|
78
|
+
const pushes = plan.moves.filter((m) => m.to.z > m.from.z * 1.1);
|
|
79
|
+
assert.equal(pushes.length, 1, 'one push in');
|
|
80
|
+
assert.ok(Math.abs(pushes[0].start - 2.7) < 1e-6, 'on the first note');
|
|
81
|
+
const end = frameRect(cameraAt(plan, 12.9), view, frame);
|
|
82
|
+
for (const e of scene) assert.ok(e.box.x - e.box.w / 2 >= end.x0 - 0.5 && e.box.x + e.box.w / 2 <= end.x1 + 0.5, 'the end shows everything');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('the camera does not keep zooming in and out', () => {
|
|
86
|
+
// New things every two seconds, far apart from each other.
|
|
87
|
+
const spots = [[200, 200], [1500, 800], [300, 820], [1450, 180], [860, 500], [200, 500], [1500, 500]];
|
|
88
|
+
const scene = spots.map(([x, y], i) => el('shape', x - 90, y - 50, 180, 100, 0.2 + i * 2));
|
|
89
|
+
const plan = planCamera(scene, { dur: 16, view, frame, voiceEnd: 14 });
|
|
90
|
+
for (let i = 1; i < plan.moves.length; i++) assert.ok(plan.moves[i].start - plan.moves[i - 1].start >= 2.2 - 1e-9, 'moves are spaced out');
|
|
91
|
+
assert.ok(reversals(plan) <= 1, `reversals: ${reversals(plan)}`);
|
|
92
|
+
assert.ok(plan.moves.length <= 5, `moves: ${plan.moves.length}`);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('no shot cuts a card or label in half while it holds, drift included', () => {
|
|
96
|
+
const plan = planCamera(diagram, { dur: 12, view, frame, voiceEnd: 9 });
|
|
97
|
+
const holds = [0.05, ...plan.moves.map((m) => m.start + m.dur + 0.01), 11.9];
|
|
98
|
+
for (const t of holds) {
|
|
99
|
+
const shot = cameraAt(plan, t);
|
|
100
|
+
const visible = diagram.filter((e) => e.at <= t && e.out > t);
|
|
101
|
+
assert.deepEqual(cuts(shot, visible).map((e) => e.kind), [], `t=${t}`);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('the camera is continuous and only reports real moves as moving', () => {
|
|
106
|
+
const plan = planCamera(diagram, { dur: 12, view, frame, voiceEnd: 9 });
|
|
107
|
+
let prev = cameraAt(plan, 0);
|
|
108
|
+
for (let t = 0.01; t < 12; t += 0.01) {
|
|
109
|
+
const c = cameraAt(plan, t);
|
|
110
|
+
assert.ok(Math.abs(c.x - prev.x) < 25 && Math.abs(c.y - prev.y) < 25 && Math.abs(Math.log(c.z / prev.z)) < 0.03, `jump at ${t.toFixed(2)}`);
|
|
111
|
+
prev = c;
|
|
112
|
+
}
|
|
113
|
+
const m = plan.moves[0];
|
|
114
|
+
assert.equal(cameraMoving(plan, m.start + m.dur / 2), true);
|
|
115
|
+
assert.equal(cameraMoving(plan, m.start - 0.01), false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('a close-up leaves a neighbour out entirely or takes it in, and falls back to the full frame', () => {
|
|
119
|
+
const row = [0, 1, 2, 3, 4].map((i) => el('shape', 805 + i * 205, 335, 190, 130, 3 + i * 0.2));
|
|
120
|
+
const music = el('icon', 1050, 700, 120, 120, 6.7);
|
|
121
|
+
const shot = compose([music], [...row, music], view, frame);
|
|
122
|
+
assert.ok(shot.z > 1.2);
|
|
123
|
+
assert.deepEqual(cuts(shot, row), []);
|
|
124
|
+
// A neighbour hugging the subject on every side cannot be avoided.
|
|
125
|
+
const subject = el('shape', 900, 500, 120, 80, 1);
|
|
126
|
+
const ring = [el('text', 700, 380, 600, 60, 0), el('text', 700, 640, 600, 60, 0), el('text', 560, 380, 60, 320, 0), el('text', 1300, 380, 60, 320, 0)];
|
|
127
|
+
const tight = compose([subject], [subject, ...ring], view, frame);
|
|
128
|
+
assert.deepEqual(cuts(tight, ring), []);
|
|
129
|
+
const v = viewRect(tight, view);
|
|
130
|
+
assert.ok(subject.box.x - subject.box.w / 2 >= v.x0 && subject.box.x + subject.box.w / 2 <= v.x1);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('a scene continues the one before it when its first frame is that scene\'s last picture', () => {
|
|
134
|
+
const a = [el('shape', 200, 450, 260, 140, 0), el('shape', 780, 450, 260, 140, 1), el('text', 780, 640, 260, 40, 2)];
|
|
135
|
+
const b = [el('shape', 200, 450, 260, 140, -1), el('shape', 780, 450, 260, 140, -1), el('text', 780, 640, 260, 40, -1), el('shape', 1360, 450, 260, 140, 2)];
|
|
136
|
+
const everything = { x0: 0, y0: 0, x1: 1920, y1: 1080 };
|
|
137
|
+
assert.equal(continues(a, b, everything), true);
|
|
138
|
+
// Not when A ends on something B leaves out.
|
|
139
|
+
assert.equal(continues(a, b.filter((e) => e.kind !== 'text'), everything), false);
|
|
140
|
+
// Not when A's last close-up shows little of what B carries.
|
|
141
|
+
const closeUp = { x0: 760, y0: 620, x1: 1060, y1: 700 };
|
|
142
|
+
assert.equal(continues(a, b, closeUp), false);
|
|
143
|
+
// Not when B draws its own picture.
|
|
144
|
+
assert.equal(continues(a, [el('shape', 100, 100, 200, 100, -1), el('shape', 400, 100, 200, 100, -1)], everything), false);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('a continued scene starts where the last camera stopped and holds through the dissolve', () => {
|
|
148
|
+
const from = { x: 700, y: 520, z: 1.4 };
|
|
149
|
+
const plan = planCamera(diagram, { dur: 12, view, frame, from, still: 0.6 });
|
|
150
|
+
assert.deepEqual(plan.start, from);
|
|
151
|
+
assert.ok(plan.moves.every((m) => m.start >= 0.6));
|
|
152
|
+
const c = cameraAt(plan, 0);
|
|
153
|
+
assert.ok(Math.abs(c.x - from.x) < 1e-9 && Math.abs(c.z - from.z) < 1e-9);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('pace makes the camera quicker', () => {
|
|
157
|
+
const slow = planCamera(diagram, { dur: 12, view, frame, pace: 1 });
|
|
158
|
+
const fast = planCamera(diagram, { dur: 12, view, frame, pace: 1.5 });
|
|
159
|
+
assert.ok(slow.moves.length && fast.moves.length);
|
|
160
|
+
assert.ok(fast.moves[0].dur < slow.moves[0].dur);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('the opening shot cuts nothing that is on screen before the first move', () => {
|
|
164
|
+
// Two opening cards leave at 1s; the close-up on the card at 2s would cut them.
|
|
165
|
+
const opening = [el('shape', 160, 150, 1600, 100, 0, 1), el('shape', 700, 440, 400, 200, 0, 1), el('shape', 1300, 465, 200, 150, 2)];
|
|
166
|
+
const plan = planCamera(opening, { dur: 8, view, frame });
|
|
167
|
+
for (const t of [0.05, 0.5, 0.9]) {
|
|
168
|
+
const visible = opening.filter((e) => e.at <= t && e.out > t);
|
|
169
|
+
assert.deepEqual(cuts(cameraAt(plan, t), visible).map((e) => e.box.x), [], `t=${t}`);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('every move ends before its scene does', () => {
|
|
174
|
+
const late = [el('shape', 200, 450, 260, 140, 0), el('shape', 1500, 700, 200, 120, 7.5)];
|
|
175
|
+
const plan = planCamera(late, { dur: 8, view, frame });
|
|
176
|
+
for (const m of plan.moves) assert.ok(m.start + m.dur <= 8 + 1e-9, `move ${m.start}+${m.dur}`);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('a full-frame shot does not drift what fits the free part of the frame into the app overlays', () => {
|
|
180
|
+
const tall = { W: 1080, H: 1920 };
|
|
181
|
+
const safe = { x: 119, y: 240, w: 745, h: 1027 };
|
|
182
|
+
const usable = { x0: 119, y0: 240, x1: 864, y1: 1267 };
|
|
183
|
+
const cards = [el('shape', 119, 703, 200, 100, 0), el('shape', 664, 703, 200, 100, 0.2)];
|
|
184
|
+
const plan = planCamera(cards, { dur: 8, view: safe, frame: tall, usable });
|
|
185
|
+
for (const t of [0.5, 4, 7.9]) {
|
|
186
|
+
const cam = cameraAt(plan, t);
|
|
187
|
+
const cx = safe.x + safe.w / 2;
|
|
188
|
+
for (const e of cards) {
|
|
189
|
+
const x0 = cx + (e.box.x - e.box.w / 2 - cam.x) * cam.z;
|
|
190
|
+
const x1 = cx + (e.box.x + e.box.w / 2 - cam.x) * cam.z;
|
|
191
|
+
assert.ok(x0 >= usable.x0 - 0.5 && x1 <= usable.x1 + 0.5, `t=${t}: ${x0.toFixed(1)}..${x1.toFixed(1)}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Boxes given by their center, as the engine measures them.
|
|
197
|
+
const centered = (kind, x, y, w, h, at, out = Infinity, extra = {}) => ({ kind, box: { x, y, w, h }, at, out, ...extra });
|
|
198
|
+
const whole = (shot, e, v = view) => {
|
|
199
|
+
const r = frameRect(shot, v, frame);
|
|
200
|
+
return e.box.x - e.box.w / 2 >= r.x0 - 0.5 && e.box.x + e.box.w / 2 <= r.x1 + 0.5 && e.box.y - e.box.h / 2 >= r.y0 - 0.5 && e.box.y + e.box.h / 2 <= r.y1 + 0.5;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
test('a move that keeps something new whole is made however small it is', () => {
|
|
204
|
+
const wide = { x: 76, y: 76, w: 1768, h: 928 };
|
|
205
|
+
const items = [centered('shape', 1525, 650, 500, 100, 0), centered('shape', 1000, 450, 550, 300, 3), centered('shape', 900, 300, 400, 100, 4.5), centered('shape', 1200, 900, 500, 200, 6)];
|
|
206
|
+
const plan = planCamera(items, { dur: 14, view: wide, frame, voiceEnd: 12 });
|
|
207
|
+
for (let t = 6.2; t < 13.9; t += 0.1) if (!cameraMoving(plan, t)) assert.ok(whole(cameraAt(plan, t), items[3], wide), `t=${t.toFixed(1)}`);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test('a focus region is framed whole, and an arrow that fits does not cancel it', () => {
|
|
211
|
+
const pan = [centered('code', 960, 540, 1600, 700, 0), centered('focus', 600, 540, 200, 80, 0, 3.9, { explicit: true }), centered('focus', 1050, 540, 200, 80, 4, Infinity, { explicit: true })];
|
|
212
|
+
const p1 = planCamera(pan, { dur: 14, view, frame, voiceEnd: 12 });
|
|
213
|
+
assert.ok(whole(cameraAt(p1, 6), pan[2]));
|
|
214
|
+
const arrow = [centered('shape', 960, 540, 1400, 700, 0), centered('focus', 960, 540, 200, 80, 3, Infinity, { explicit: true }), centered('arrow', 960, 700, 500, 20, 3.9)];
|
|
215
|
+
const p2 = planCamera(arrow, { dur: 14, view, frame, voiceEnd: 12 });
|
|
216
|
+
assert.ok(cameraAt(p2, 6).z > 1.5, 'the close-up happens');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('a push in is held for a while before the camera pulls back', () => {
|
|
220
|
+
const items = [centered('shape', 500, 350, 600, 300, 0), centered('shape', 1400, 350, 600, 300, 0), centered('text', 1400, 725, 300, 50, 8.5)];
|
|
221
|
+
const plan = planCamera(items, { dur: 12, view, frame, voiceEnd: 10 });
|
|
222
|
+
for (let i = 0; i < plan.moves.length; i++) {
|
|
223
|
+
const m = plan.moves[i];
|
|
224
|
+
if (m.to.z <= m.from.z * 1.1) continue;
|
|
225
|
+
const next = plan.moves[i + 1]?.start ?? 12;
|
|
226
|
+
assert.ok(next - (m.start + m.dur) >= 1.5 - 1e-9, `held ${(next - m.start - m.dur).toFixed(2)}s`);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test('a large chart is the picture, and a label inside it gets no close-up', () => {
|
|
231
|
+
const items = [centered('chart', 960, 540, 1600, 800, 0), centered('line', 960, 540, 1400, 0, 3), centered('text', 960, 700, 160, 40, 6.5)];
|
|
232
|
+
const plan = planCamera(items, { dur: 12, view, frame, voiceEnd: 10 });
|
|
233
|
+
for (let t = 0.1; t < 11.9; t += 0.5) assert.ok(whole(cameraAt(plan, t), items[0]), `t=${t.toFixed(1)}`);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('a push in makes way for a focus point that comes soon after', () => {
|
|
237
|
+
const items = [centered('shape', 500, 350, 600, 300, 0), centered('shape', 1400, 350, 600, 300, 0), centered('text', 500, 725, 300, 50, 3), centered('focus', 1400, 350, 200, 80, 5.5, Infinity, { explicit: true })];
|
|
238
|
+
const plan = planCamera(items, { dur: 12, view, frame, voiceEnd: 10 });
|
|
239
|
+
for (let i = 0; i < plan.moves.length; i++) {
|
|
240
|
+
const m = plan.moves[i];
|
|
241
|
+
const next = plan.moves[i + 1]?.start ?? 12;
|
|
242
|
+
if (m.to.z > m.from.z * 1.1) assert.ok(next - (m.start + m.dur) >= 1.5 - 1e-9, `held ${(next - m.start - m.dur).toFixed(2)}s`);
|
|
243
|
+
}
|
|
244
|
+
assert.ok(whole(cameraAt(plan, 8), items[3]) && cameraAt(plan, 8).z > 1.5, 'the focus gets its close-up');
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('a scene too short for the pull-back still ends on the whole picture', () => {
|
|
248
|
+
// Three steps in a row; the last one comes a second before the scene ends.
|
|
249
|
+
// They stay until the end, also when they leave right at the end.
|
|
250
|
+
for (const out of [Infinity, 5.6]) {
|
|
251
|
+
const steps = [0, 1, 2].map((i) => el('shape', 300 + i * 520, 470, 260, 140, [0.3, 2.4, 4.4][i], out));
|
|
252
|
+
const plan = planCamera(steps, { dur: 5.6, view, frame, voiceEnd: 5 });
|
|
253
|
+
const end = cameraAt(plan, 5.55);
|
|
254
|
+
for (const e of steps) assert.ok(whole(end, e), `step at ${e.at}, out ${out}`);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('a last move in that becomes a wide shot keeps later things whole', () => {
|
|
259
|
+
const boxes = [[1383, 438, 382, 227, 0], [1632, 306, 119, 209, 0.89], [622, 541, 303, 71, 1.38], [737, 839, 113, 70, 2.19], [252, 632, 252, 163, 3.06]];
|
|
260
|
+
const items = boxes.map(([x, y, w, h, at]) => centered('shape', x, y, w, h, at));
|
|
261
|
+
const plan = planCamera(items, { dur: 5.7, view, frame, pace: 1 });
|
|
262
|
+
const settled = Math.max(3.06, ...plan.moves.map((m) => m.start + m.dur));
|
|
263
|
+
for (let t = settled + 0.05; t < 5.7; t += 0.1) assert.ok(whole(cameraAt(plan, t), items[4]), `t=${t.toFixed(2)}`);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test('a continued scene also ends on the whole picture', () => {
|
|
267
|
+
const items = [centered('shape', 350, 540, 260, 140, 0), centered('shape', 850, 540, 260, 140, 0), centered('shape', 1450, 540, 260, 140, 3.5)];
|
|
268
|
+
const plan = planCamera(items, { dur: 4.8, view, frame, from: { x: 600, y: 540, z: 1.7 }, still: 0.7 });
|
|
269
|
+
const end = cameraAt(plan, 4.75);
|
|
270
|
+
for (const e of items) assert.ok(whole(end, e), `box at ${e.box.x}`);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test("an arrow's label is kept whole, and a labelled arrow gets no close-up", () => {
|
|
274
|
+
const els = [
|
|
275
|
+
el('shape', 300, 420, 300, 160, 0.3),
|
|
276
|
+
el('shape', 1100, 420, 300, 160, 0.3),
|
|
277
|
+
el('arrow', 600, 480, 500, 40, 4),
|
|
278
|
+
el('label', 700, 380, 300, 40, 4),
|
|
279
|
+
el('shape', 1300, 760, 300, 120, 9),
|
|
280
|
+
];
|
|
281
|
+
const plan = planCamera(els, { dur: 14, view, frame });
|
|
282
|
+
assert.ok(!plan.moves.some((m) => m.start > 3 && m.start < 5.5), JSON.stringify(plan.moves.map((m) => m.start)));
|
|
283
|
+
for (let t = 0; t < 14; t += 0.05) {
|
|
284
|
+
if (cameraMoving(plan, t)) continue;
|
|
285
|
+
const shown = els.filter((e) => e.at <= t && e.out > t);
|
|
286
|
+
assert.deepEqual(cuts(cameraAt(plan, t), shown), [], `t=${t.toFixed(2)}`);
|
|
287
|
+
}
|
|
288
|
+
// A close-up next to an arrow leaves its label out or takes it in.
|
|
289
|
+
const label = el('label', 520, 300, 360, 50, 0);
|
|
290
|
+
const shot = compose([el('shape', 860, 360, 200, 120, 0)], [label, el('arrow', 400, 360, 460, 30, 0)], view, frame);
|
|
291
|
+
assert.ok(shot.z > 1.2, `z ${shot.z}`);
|
|
292
|
+
assert.deepEqual(cuts(shot, [label]), []);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test('an icon or shape without words gets no close-up of its own', () => {
|
|
296
|
+
// The picture fills the frame from the start, so the icon fits the shot.
|
|
297
|
+
const picture = [el('text', 560, 120, 800, 120, 0.2), el('shape', 150, 400, 300, 300, 0.2), el('shape', 1470, 400, 300, 300, 0.2)];
|
|
298
|
+
const plan = (icon) => planCamera([...picture, icon], { dur: 12, view, frame, voiceEnd: 11 });
|
|
299
|
+
const icon = el('icon', 900, 600, 120, 120, 3);
|
|
300
|
+
const bare = plan({ ...icon, bare: true });
|
|
301
|
+
assert.ok(!bare.moves.some((m) => m.start > 2 && m.start < 4 && m.to.z > m.from.z * 1.2), JSON.stringify(bare.moves));
|
|
302
|
+
const labelled = plan({ ...icon, box: { ...icon.box, h: 190 } });
|
|
303
|
+
assert.ok(labelled.moves.some((m) => m.start > 2 && m.start < 4 && m.to.z > m.from.z * 1.2), JSON.stringify(labelled.moves));
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test("an arrow's label does not count on its own when a scene continues the one before", () => {
|
|
307
|
+
const card = (x) => el('shape', x, 450, 260, 140, 0.5);
|
|
308
|
+
const arrow = (x) => el('arrow', x, 500, 300, 40, 1);
|
|
309
|
+
const label = (x) => el('label', x + 60, 440, 180, 40, 1);
|
|
310
|
+
const a = [card(200), card(780), arrow(470), label(470), card(1360), arrow(1050), label(1050)];
|
|
311
|
+
const b = [card(200), card(780), card(1360), arrow(470), label(470)].map((e) => ({ ...e, at: -1 }));
|
|
312
|
+
assert.equal(continues(a, b, { x0: 0, y0: 0, x1: 1920, y1: 1080 }), continues(a.filter((e) => e.kind !== 'label'), b.filter((e) => e.kind !== 'label'), { x0: 0, y0: 0, x1: 1920, y1: 1080 }));
|
|
313
|
+
const two = [card(200), card(780), arrow(470), label(470), arrow(1050), label(1050)];
|
|
314
|
+
const one = [card(200), card(780), arrow(470)].map((e) => ({ ...e, at: -1 }));
|
|
315
|
+
assert.ok(continues(two, one, { x0: 0, y0: 0, x1: 1920, y1: 1080 }));
|
|
316
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { parsePath, absolutize, serialize, scalePath, splitSubpaths } from '../engine/pathdata.js';
|
|
4
|
+
import { parseRich } from '../engine/text.js';
|
|
5
|
+
import { highlightLine } from '../engine/code.js';
|
|
6
|
+
|
|
7
|
+
test('relative paths become absolute and scale', () => {
|
|
8
|
+
assert.equal(serialize(absolutize(parsePath('m2 3 l4 0 v2 h-4 z'))), 'M2 3L6 3L6 5L2 5Z');
|
|
9
|
+
assert.equal(scalePath('M1 1L2 2', 10, 5, 5), 'M15 15L25 25');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('glued arc flags are read correctly', () => {
|
|
13
|
+
const cmds = absolutize(parsePath('M0 0a1 1 0 011 1'));
|
|
14
|
+
assert.deepEqual(cmds[1], { c: 'A', v: [1, 1, 0, 0, 1, 1, 1] });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('subpaths split at every move', () => {
|
|
18
|
+
assert.deepEqual(splitSubpaths('M0 0L1 1m2 2l1 0'), ['M0 0L1 1', 'M3 3L4 3']);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('rich text marks *accent* words', () => {
|
|
22
|
+
const w = parseRich('Every site has an *address*. And *two words* here');
|
|
23
|
+
assert.deepEqual(w.filter((x) => x.accent).map((x) => x.text), ['address.', 'two', 'words']);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('code highlighting finds keywords, strings and comments', () => {
|
|
27
|
+
const t = highlightLine('const x = "hi"; // note', 'js');
|
|
28
|
+
assert.deepEqual(t.map((x) => x.type), ['keyword', 'plain', 'punct', 'plain', 'string', 'punct', 'plain', 'comment']);
|
|
29
|
+
});
|
|
@@ -0,0 +1,224 @@
|
|
|
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 http from 'node:http';
|
|
7
|
+
import { findChrome, launch } from '../src/browser.js';
|
|
8
|
+
import { loadProject } from '../src/project.js';
|
|
9
|
+
import { exportPlayer } from '../src/export.js';
|
|
10
|
+
import { withEngine } from '../src/pipeline.js';
|
|
11
|
+
import { ffmpeg, probe } from '../src/ffmpeg.js';
|
|
12
|
+
import { ROOT } from '../src/server.js';
|
|
13
|
+
|
|
14
|
+
let chrome;
|
|
15
|
+
try { chrome = findChrome(); } catch {}
|
|
16
|
+
|
|
17
|
+
async function servePlayer(dir, ranges = true) {
|
|
18
|
+
const types = { '.html': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript', '.json': 'application/json', '.vtt': 'text/vtt', '.m4a': 'audio/mp4', '.mp4': 'video/mp4', '.svg': 'image/svg+xml', '.woff2': 'font/woff2' };
|
|
19
|
+
const server = http.createServer((req, res) => {
|
|
20
|
+
const url = new URL(req.url, 'http://localhost');
|
|
21
|
+
const rel = decodeURIComponent(url.pathname).replace(/^\/docs\/video\//, '');
|
|
22
|
+
const file = path.resolve(dir, rel);
|
|
23
|
+
if (!url.pathname.startsWith('/docs/video/') || !file.startsWith(dir + path.sep) || !fs.existsSync(file) || !fs.statSync(file).isFile()) { res.writeHead(404); res.end(); return; }
|
|
24
|
+
const size = fs.statSync(file).size;
|
|
25
|
+
const range = ranges && /^bytes=(\d+)-(\d*)$/.exec(req.headers.range || '');
|
|
26
|
+
const start = range ? Number(range[1]) : 0;
|
|
27
|
+
const end = range?.[2] ? Math.min(size - 1, Number(range[2])) : size - 1;
|
|
28
|
+
res.writeHead(range ? 206 : 200, { 'Content-Type': types[path.extname(file)] || 'application/octet-stream', 'Content-Length': end - start + 1, ...(ranges ? { 'Accept-Ranges': 'bytes' } : {}), ...(range ? { 'Content-Range': `bytes ${start}-${end}/${size}` } : {}) });
|
|
29
|
+
fs.createReadStream(file, { start, end }).pipe(res);
|
|
30
|
+
});
|
|
31
|
+
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
|
|
32
|
+
return { url: `http://127.0.0.1:${server.address().port}/docs/video/`, close: () => new Promise(resolve => { server.closeAllConnections(); server.close(resolve); }) };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
test('exported player runs at a sub-path with matching frames, clips and accessible controls', { skip: !chrome }, async t => {
|
|
36
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'explainroo-player-browser-'));
|
|
37
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
38
|
+
fs.mkdirSync(path.join(dir, 'assets'));
|
|
39
|
+
fs.writeFileSync(path.join(dir, 'assets/used.svg'), '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><circle cx="50" cy="50" r="40" fill="#245cff"/></svg>');
|
|
40
|
+
fs.writeFileSync(path.join(dir, 'assets/unused.svg'), '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"/>');
|
|
41
|
+
fs.writeFileSync(path.join(dir, 'assets/secret.json'), '{"key":"SECRET"}');
|
|
42
|
+
fs.writeFileSync(path.join(dir, '.env'), 'SECRET');
|
|
43
|
+
fs.copyFileSync(path.join(ROOT, 'fonts/Inter-400-latin.woff2'), path.join(dir, 'assets/unused.woff2'));
|
|
44
|
+
await ffmpeg(['-loglevel', 'error', '-f', 'lavfi', '-i', 'color=red:s=160x90:r=30:d=1', '-f', 'lavfi', '-i', 'color=lime:s=160x90:r=30:d=1', '-filter_complex', '[0:v][1:v]concat=n=2:v=1:a=0[v]', '-map', '[v]', '-c:v', 'libx264', '-threads', '1', path.join(dir, 'assets/clip.mp4')]);
|
|
45
|
+
fs.writeFileSync(path.join(dir, 'video.json'), JSON.stringify({ theme: 'clean', music: false, sfx: false, end: 0, fonts: [{ family: 'Unused', src: 'assets/unused.woff2' }] }));
|
|
46
|
+
fs.writeFileSync(path.join(dir, 'script.md'), '# Player fixture\n## intro {min=12}\n');
|
|
47
|
+
fs.writeFileSync(path.join(dir, 'helper.mjs'), "export const label = 'Player fixture';");
|
|
48
|
+
fs.writeFileSync(path.join(dir, 'scenes.js'), `const modulePath = './helper.mjs';
|
|
49
|
+
const { label } = await import(modulePath);
|
|
50
|
+
export default { intro(s) {
|
|
51
|
+
s.title(label, { y: 220, enter: 'none' });
|
|
52
|
+
s.math('E=mc^2', { y: 440, enter: 'none' });
|
|
53
|
+
s.image('assets/used.svg', { x: 1600, y: 440, w: 160, enter: 'none' });
|
|
54
|
+
s.clip('assets/clip.mp4', { y: 760, w: 480, at: 2, out: 4, enter: 'none', shadow: false, radius: 0 });
|
|
55
|
+
} };`);
|
|
56
|
+
const project = loadProject(dir);
|
|
57
|
+
const output = await exportPlayer(project);
|
|
58
|
+
assert.equal(output.out, path.join(dir, 'out/player'));
|
|
59
|
+
for (const name of ['audio.m4a', 'poster.jpg', 'subtitles.vtt']) assert.ok(fs.existsSync(path.join(output.out, name)));
|
|
60
|
+
assert.ok(!fs.existsSync(path.join(output.out, 'project/build')));
|
|
61
|
+
assert.ok(fs.existsSync(path.join(output.out, 'project/helper.mjs')));
|
|
62
|
+
assert.deepEqual(fs.readdirSync(path.join(output.out, 'project/assets')).sort(), ['clip.mp4', 'used.svg']);
|
|
63
|
+
const exportedState = JSON.parse(fs.readFileSync(path.join(output.out, 'state.json'), 'utf8'));
|
|
64
|
+
assert.deepEqual(exportedState.config.fonts, []);
|
|
65
|
+
const audioInfo = await probe(path.join(output.out, 'audio.m4a'));
|
|
66
|
+
assert.equal(audioInfo.streams[0].codec_name, 'aac');
|
|
67
|
+
assert.ok(Math.abs(Number(audioInfo.format.duration) - 12) < 0.1);
|
|
68
|
+
// A cue exercises the browser's native TextTrack parsing and the HTML overlay.
|
|
69
|
+
fs.writeFileSync(path.join(output.out, 'subtitles.vtt'), 'WEBVTT\n\n00:00:00.000 --> 00:00:10.000\nReadable & accessible\n');
|
|
70
|
+
const timeline = JSON.parse(fs.readFileSync(path.join(project.paths.build, 'timeline.json'), 'utf8'));
|
|
71
|
+
let reference;
|
|
72
|
+
await withEngine(project, timeline, {}, async page => {
|
|
73
|
+
await page.evaluate(() => window.explainroo.stills([{ T: 0, path: 'out/reference.png' }]));
|
|
74
|
+
reference = fs.readFileSync(path.join(project.paths.out, 'reference.png')).toString('base64');
|
|
75
|
+
});
|
|
76
|
+
const server = await servePlayer(output.out);
|
|
77
|
+
t.after(() => server.close());
|
|
78
|
+
const browser = await launch();
|
|
79
|
+
t.after(() => browser.close());
|
|
80
|
+
const context = await browser.newContext({ viewport: { width: 1920, height: 1080 } });
|
|
81
|
+
const page = await context.newPage();
|
|
82
|
+
const errors = [];
|
|
83
|
+
const requests = [];
|
|
84
|
+
page.on('pageerror', e => errors.push(e.message));
|
|
85
|
+
page.on('request', req => requests.push(req.url()));
|
|
86
|
+
await page.goto(server.url + 'index.html?muted=1');
|
|
87
|
+
await page.evaluate(() => window.explainrooReady);
|
|
88
|
+
assert.equal(await page.locator('#poster').isVisible(), true);
|
|
89
|
+
assert.equal(await page.locator('#audio').evaluate(a => a.paused), true);
|
|
90
|
+
assert.ok(!requests.some(url => url.endsWith('/audio.m4a')));
|
|
91
|
+
assert.equal(await page.locator('#cc').getAttribute('aria-pressed'), 'false');
|
|
92
|
+
assert.equal(await page.getByRole('button', { name: 'Play', exact: true }).count(), 1);
|
|
93
|
+
assert.equal(await page.locator('#controls').isVisible(), false);
|
|
94
|
+
assert.equal(await page.locator('#start').isVisible(), true);
|
|
95
|
+
for (const [id, label] of [['mute', 'Unmute'], ['cc', 'Show captions'], ['fullscreen', 'Enter fullscreen']]) assert.equal(await page.locator(`#${id}`).getAttribute('aria-label'), label);
|
|
96
|
+
assert.equal(await page.locator('#seek').getAttribute('aria-label'), 'Seek');
|
|
97
|
+
const icons = JSON.parse(fs.readFileSync(path.join(ROOT, 'engine/icons/lucide.json'), 'utf8')).icons;
|
|
98
|
+
for (const [id, name] of [['play', 'play'], ['mute', 'volume-x'], ['cc', 'closed-caption'], ['fullscreen', 'maximize']]) {
|
|
99
|
+
assert.deepEqual(await page.locator(`#${id} path`).evaluateAll(paths => paths.map(path => path.getAttribute('d'))), icons[name]);
|
|
100
|
+
assert.equal(await page.locator(`#${id}`).getAttribute('title'), await page.locator(`#${id}`).getAttribute('aria-label'));
|
|
101
|
+
}
|
|
102
|
+
await page.locator('#poster').click({ position: { x: 40, y: 40 } });
|
|
103
|
+
await page.waitForFunction(() => Number(document.querySelector('#seek').value) > 0.15);
|
|
104
|
+
assert.ok(await page.locator('#audio').evaluate(a => a.currentTime > 0.1 && !a.paused));
|
|
105
|
+
await page.keyboard.press('k');
|
|
106
|
+
assert.equal(await page.getByRole('button', { name: 'Play', exact: true }).count(), 1);
|
|
107
|
+
assert.equal(await page.locator('#poster').isVisible(), false);
|
|
108
|
+
assert.equal(await page.locator('#start').isVisible(), false);
|
|
109
|
+
assert.equal(await page.locator('#controls').isVisible(), true);
|
|
110
|
+
for (const label of ['Play', 'Unmute', 'Show captions', 'Enter fullscreen']) assert.equal(await page.getByRole('button', { name: label, exact: true }).count(), 1);
|
|
111
|
+
assert.equal(await page.getByRole('slider', { name: 'Seek' }).count(), 1);
|
|
112
|
+
await page.locator('#seek').evaluate(input => { input.value = 0; input.dispatchEvent(new Event('input')); });
|
|
113
|
+
const difference = await page.evaluate(async base64 => {
|
|
114
|
+
const image = new Image(); image.src = 'data:image/png;base64,' + base64; await image.decode();
|
|
115
|
+
const canvas = document.querySelector('#c');
|
|
116
|
+
const other = document.createElement('canvas'); other.width = canvas.width; other.height = canvas.height;
|
|
117
|
+
const ctx = other.getContext('2d'); ctx.drawImage(image, 0, 0);
|
|
118
|
+
const a = canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height).data;
|
|
119
|
+
const b = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
|
120
|
+
let error = 0; for (let i = 0; i < a.length; i++) error += Math.abs(a[i] - b[i]);
|
|
121
|
+
return error / a.length;
|
|
122
|
+
}, reference);
|
|
123
|
+
assert.ok(difference < 0.2, `mean pixel error ${difference}`);
|
|
124
|
+
await page.locator('#player').focus();
|
|
125
|
+
await page.keyboard.press('ArrowRight');
|
|
126
|
+
assert.equal(Number(await page.locator('#seek').inputValue()), 5);
|
|
127
|
+
await page.keyboard.press('ArrowLeft');
|
|
128
|
+
assert.equal(Number(await page.locator('#seek').inputValue()), 0);
|
|
129
|
+
await page.keyboard.press('m');
|
|
130
|
+
assert.equal(await page.locator('#audio').evaluate(a => a.muted), false);
|
|
131
|
+
assert.equal(await page.locator('#mute').getAttribute('title'), 'Mute');
|
|
132
|
+
assert.equal(await page.locator('#mute').getAttribute('data-icon'), 'volume-2');
|
|
133
|
+
await page.keyboard.press('m');
|
|
134
|
+
await page.keyboard.press('Space');
|
|
135
|
+
await page.waitForFunction(() => document.querySelector('#play').getAttribute('aria-label') === 'Pause');
|
|
136
|
+
assert.equal(await page.locator('#play').getAttribute('title'), 'Pause');
|
|
137
|
+
assert.equal(await page.locator('#play').getAttribute('data-icon'), 'pause');
|
|
138
|
+
await page.waitForFunction(() => getComputedStyle(document.querySelector('#controls')).opacity === '0');
|
|
139
|
+
await page.mouse.move(20, 20);
|
|
140
|
+
await page.waitForFunction(() => getComputedStyle(document.querySelector('#controls')).opacity === '1');
|
|
141
|
+
await page.locator('#play').focus();
|
|
142
|
+
await page.waitForTimeout(2200);
|
|
143
|
+
assert.equal(await page.locator('#controls').evaluate(el => getComputedStyle(el).opacity), '1');
|
|
144
|
+
assert.equal(await page.locator('#play').evaluate(el => getComputedStyle(el).outlineStyle), 'solid');
|
|
145
|
+
await page.locator('#player').focus();
|
|
146
|
+
await page.keyboard.press('Space');
|
|
147
|
+
await page.locator('#cc').click();
|
|
148
|
+
await page.waitForFunction(() => document.querySelector('#captions').textContent === 'Readable & accessible');
|
|
149
|
+
assert.equal(await page.locator('#cc').getAttribute('aria-pressed'), 'true');
|
|
150
|
+
assert.equal(await page.locator('#cc').getAttribute('title'), 'Hide captions');
|
|
151
|
+
assert.notEqual(await page.locator('#cc').evaluate(el => getComputedStyle(el, '::after').backgroundColor), 'rgba(0, 0, 0, 0)');
|
|
152
|
+
await page.locator('#seek').evaluate(input => { input.value = 3.5; input.dispatchEvent(new Event('input')); });
|
|
153
|
+
await page.waitForFunction(() => {
|
|
154
|
+
const c = document.querySelector('#c'); const p = c.getContext('2d').getImageData(c.width / 2, c.height * 760 / 1080, 1, 1).data;
|
|
155
|
+
return p[1] > 240 && p[0] < 15;
|
|
156
|
+
});
|
|
157
|
+
await page.locator('#seek').evaluate(input => { input.value = 2.5; input.dispatchEvent(new Event('input')); });
|
|
158
|
+
await page.waitForFunction(() => {
|
|
159
|
+
const c = document.querySelector('#c'); const p = c.getContext('2d').getImageData(c.width / 2, c.height * 760 / 1080, 1, 1).data;
|
|
160
|
+
return p[0] > 240 && p[1] < 15;
|
|
161
|
+
});
|
|
162
|
+
await page.locator('#player').focus();
|
|
163
|
+
await page.keyboard.press('f');
|
|
164
|
+
await page.waitForFunction(() => !!document.fullscreenElement);
|
|
165
|
+
// The label follows the fullscreenchange event, a moment after the element changes.
|
|
166
|
+
await page.waitForFunction(() => document.querySelector('#fullscreen').getAttribute('aria-label') === 'Exit fullscreen');
|
|
167
|
+
assert.equal(await page.getByRole('button', { name: 'Exit fullscreen' }).count(), 1);
|
|
168
|
+
assert.equal(await page.locator('#fullscreen').getAttribute('title'), 'Exit fullscreen');
|
|
169
|
+
assert.equal(await page.locator('#fullscreen').getAttribute('data-icon'), 'minimize');
|
|
170
|
+
await page.keyboard.press('k');
|
|
171
|
+
await page.waitForFunction(() => getComputedStyle(document.querySelector('#controls')).opacity === '0');
|
|
172
|
+
assert.equal(await page.locator('#player').evaluate(el => getComputedStyle(el).cursor), 'none');
|
|
173
|
+
await page.locator('#player').dispatchEvent('pointerdown', { pointerType: 'touch' });
|
|
174
|
+
await page.waitForFunction(() => getComputedStyle(document.querySelector('#controls')).opacity === '1');
|
|
175
|
+
assert.notEqual(await page.locator('#player').evaluate(el => getComputedStyle(el).cursor), 'none');
|
|
176
|
+
await page.keyboard.press('k');
|
|
177
|
+
await page.keyboard.press('f');
|
|
178
|
+
await page.waitForFunction(() => !document.fullscreenElement);
|
|
179
|
+
await page.setViewportSize({ width: 480, height: 320 });
|
|
180
|
+
await page.waitForFunction(() => document.querySelector('#c').width === 480);
|
|
181
|
+
assert.equal(await page.locator('#player').evaluate(el => Math.round(el.getBoundingClientRect().height)), 270);
|
|
182
|
+
await page.setViewportSize({ width: 320, height: 240 });
|
|
183
|
+
const layout = await page.locator('#controls').evaluate(el => {
|
|
184
|
+
const bounds = el.getBoundingClientRect();
|
|
185
|
+
return [...el.querySelectorAll('button,input,#time')].map(child => {
|
|
186
|
+
const box = child.getBoundingClientRect();
|
|
187
|
+
return { inside: box.left >= bounds.left && box.right <= bounds.right, target: child.tagName === 'SPAN' || (box.width >= 40 && box.height >= 40) };
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
assert.ok(layout.every(el => el.inside && el.target));
|
|
191
|
+
await page.emulateMedia({ reducedMotion: 'reduce' });
|
|
192
|
+
assert.equal(await page.locator('#controls').evaluate(el => getComputedStyle(el).transitionDuration), '0s');
|
|
193
|
+
await page.reload();
|
|
194
|
+
await page.evaluate(() => window.explainrooReady);
|
|
195
|
+
assert.equal(await page.locator('#cc').getAttribute('aria-pressed'), 'true');
|
|
196
|
+
assert.equal(await page.locator('#poster').isVisible(), true);
|
|
197
|
+
await page.keyboard.press('k');
|
|
198
|
+
await page.waitForFunction(() => document.querySelector('#play').getAttribute('aria-label') === 'Pause');
|
|
199
|
+
await page.keyboard.press('k');
|
|
200
|
+
await page.goto(server.url + 'index.html?autoplay=1&muted=1&t=6.5');
|
|
201
|
+
await page.evaluate(() => window.explainrooReady);
|
|
202
|
+
await page.waitForFunction(() => Number(document.querySelector('#seek').value) > 6.6);
|
|
203
|
+
assert.equal(await page.locator('#audio').evaluate(a => a.muted), true);
|
|
204
|
+
assert.deepEqual(errors, []);
|
|
205
|
+
assert.ok(requests.every(url => url.startsWith(server.url)), requests.join('\n'));
|
|
206
|
+
assert.ok(!requests.some(url => /__math|__clip|__state|__upload|build\/clips/.test(url)));
|
|
207
|
+
await page.route('**/audio.m4a', route => route.abort());
|
|
208
|
+
await page.goto(server.url + 'index.html?autoplay=1&muted=1&t=6.5');
|
|
209
|
+
await page.evaluate(() => window.explainrooReady);
|
|
210
|
+
await page.waitForFunction(() => Number(document.querySelector('#seek').value) > 6.7);
|
|
211
|
+
assert.ok(await page.locator('#audio').evaluate(a => !!a.error));
|
|
212
|
+
await page.unroute('**/audio.m4a');
|
|
213
|
+
const basic = await servePlayer(output.out, false);
|
|
214
|
+
t.after(() => basic.close());
|
|
215
|
+
await page.goto(basic.url + 'index.html?muted=1&t=3.5');
|
|
216
|
+
await page.evaluate(() => window.explainrooReady);
|
|
217
|
+
assert.ok(await page.locator('video').evaluate(v => v.src.startsWith('blob:')));
|
|
218
|
+
await page.locator('#start').click();
|
|
219
|
+
await page.waitForFunction(() => document.querySelector('#audio').src.startsWith('blob:') && document.querySelector('#audio').currentTime > 3.5);
|
|
220
|
+
await page.keyboard.press('k');
|
|
221
|
+
await page.locator('#seek').evaluate(input => { input.value = 2.5; input.dispatchEvent(new Event('input')); });
|
|
222
|
+
await page.waitForFunction(() => Math.abs(document.querySelector('video').currentTime - 0.5) < 0.05);
|
|
223
|
+
await page.waitForFunction(() => Math.abs(document.querySelector('#audio').currentTime - 2.5) < 0.05);
|
|
224
|
+
});
|