@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,69 @@
|
|
|
1
|
+
// Where scene content may go, and where the captions sit.
|
|
2
|
+
//
|
|
3
|
+
// Normal sizes keep a 7% margin. Platform formats (tiktok, reels, shorts,
|
|
4
|
+
// vertical) keep clear of the app's own buttons and text, and put the
|
|
5
|
+
// watermark in the top right corner of the part the app leaves free.
|
|
6
|
+
// With captions on, `safe` ends above the caption band, so content placed from
|
|
7
|
+
// `s.safe` never sits under a caption.
|
|
8
|
+
const LINES = 2;
|
|
9
|
+
|
|
10
|
+
export function layoutAreas(config, W, H) {
|
|
11
|
+
const m = Math.round(Math.min(W, H) * 0.07);
|
|
12
|
+
const f = config.safe;
|
|
13
|
+
const wmSize = Math.round(Math.min(W, H) * 0.028);
|
|
14
|
+
const wmBox = Math.round(wmSize * 1.6);
|
|
15
|
+
const capSize = H > W ? 58 : 44;
|
|
16
|
+
const capBoxH = Math.round(capSize * 1.3 * LINES + capSize * 0.55);
|
|
17
|
+
|
|
18
|
+
let left;
|
|
19
|
+
let right;
|
|
20
|
+
let top;
|
|
21
|
+
let bottom;
|
|
22
|
+
let app = null;
|
|
23
|
+
let captions = null;
|
|
24
|
+
|
|
25
|
+
if (f) {
|
|
26
|
+
left = Math.round(W * f.left);
|
|
27
|
+
right = W - Math.round(W * f.right);
|
|
28
|
+
const appTop = Math.round(H * f.top);
|
|
29
|
+
const appBottom = H - Math.round(H * f.bottom);
|
|
30
|
+
app = { left, top: appTop, right, bottom: appBottom };
|
|
31
|
+
top = config.watermark ? appTop + wmBox + 16 : appTop;
|
|
32
|
+
bottom = appBottom;
|
|
33
|
+
if (config.captions) captions = { cx: (left + right) / 2, bottom: appBottom - 10, maxWidth: right - left };
|
|
34
|
+
} else {
|
|
35
|
+
left = m;
|
|
36
|
+
right = W - m;
|
|
37
|
+
top = m;
|
|
38
|
+
bottom = H - m;
|
|
39
|
+
if (config.captions) {
|
|
40
|
+
const maxWidth = W * (H > W ? 0.8 : 0.7) + capSize * 1.1;
|
|
41
|
+
if (H >= W * 1.5) {
|
|
42
|
+
// Tall 9:16 without a platform: captions a quarter of the way up.
|
|
43
|
+
captions = { cx: W / 2, bottom: Math.round(H * 0.74 + capBoxH / 2), maxWidth };
|
|
44
|
+
} else {
|
|
45
|
+
// Wide, square and 4:5: captions at the bottom, clear of the watermark.
|
|
46
|
+
const clear = config.watermark ? wmSize + wmBox + 12 : Math.round(m * 0.6);
|
|
47
|
+
captions = { cx: W / 2, bottom: H - clear, maxWidth };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let band = null;
|
|
53
|
+
if (captions) {
|
|
54
|
+
band = {
|
|
55
|
+
left: captions.cx - captions.maxWidth / 2,
|
|
56
|
+
right: captions.cx + captions.maxWidth / 2,
|
|
57
|
+
top: captions.bottom - capBoxH,
|
|
58
|
+
bottom: captions.bottom,
|
|
59
|
+
};
|
|
60
|
+
bottom = Math.min(bottom, band.top - 24);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
safe: { x: left, y: top, w: right - left, h: bottom - top, left, top, right, bottom },
|
|
65
|
+
captions,
|
|
66
|
+
band,
|
|
67
|
+
app,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// SVG path helpers: parse to absolute commands, scale and move, split into
|
|
2
|
+
// subpaths, measure length, and build paths for the basic shapes.
|
|
3
|
+
|
|
4
|
+
const PARAMS = { M: 2, L: 2, H: 1, V: 1, C: 6, S: 4, Q: 4, T: 2, A: 7, Z: 0 };
|
|
5
|
+
|
|
6
|
+
export function parsePath(d) {
|
|
7
|
+
const out = [];
|
|
8
|
+
const re = /([MLHVCSQTAZmlhvcsqtaz])|(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/g;
|
|
9
|
+
let m;
|
|
10
|
+
let cmd = null;
|
|
11
|
+
let nums = [];
|
|
12
|
+
const flush = () => {
|
|
13
|
+
if (!cmd) return;
|
|
14
|
+
const up = cmd.toUpperCase();
|
|
15
|
+
const n = PARAMS[up];
|
|
16
|
+
if (n === 0) {
|
|
17
|
+
out.push({ c: cmd, v: [] });
|
|
18
|
+
} else {
|
|
19
|
+
let first = true;
|
|
20
|
+
for (let i = 0; i + n <= nums.length; i += n) {
|
|
21
|
+
let c = cmd;
|
|
22
|
+
if (!first && up === 'M') c = cmd === 'm' ? 'l' : 'L';
|
|
23
|
+
out.push({ c, v: nums.slice(i, i + n) });
|
|
24
|
+
first = false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
nums = [];
|
|
28
|
+
};
|
|
29
|
+
// Arc flags can be written without separators ("a1 1 0 011 1"); expand them.
|
|
30
|
+
const src = String(d).replace(/([Aa])([^MLHVCSQTAZmlhvcsqtaz]*)/g, (all, a, body) => a + expandArcFlags(body));
|
|
31
|
+
while ((m = re.exec(src)) !== null) {
|
|
32
|
+
if (m[1]) {
|
|
33
|
+
flush();
|
|
34
|
+
cmd = m[1];
|
|
35
|
+
} else {
|
|
36
|
+
nums.push(parseFloat(m[2]));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
flush();
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function expandArcFlags(body) {
|
|
44
|
+
const tokens = body.match(/-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/g) || [];
|
|
45
|
+
// Only rewrite when flags were glued together, detected by a token count
|
|
46
|
+
// that is not a multiple of 7.
|
|
47
|
+
if (tokens.length % 7 === 0) return body;
|
|
48
|
+
const out = [];
|
|
49
|
+
const raw = body.trim();
|
|
50
|
+
let i = 0;
|
|
51
|
+
let idx = 0;
|
|
52
|
+
const num = /^[\s,]*(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/;
|
|
53
|
+
const flag = /^[\s,]*([01])/;
|
|
54
|
+
while (i < raw.length) {
|
|
55
|
+
const pos = idx % 7;
|
|
56
|
+
const re = pos === 3 || pos === 4 ? flag : num;
|
|
57
|
+
const m = re.exec(raw.slice(i));
|
|
58
|
+
if (!m) break;
|
|
59
|
+
out.push(m[1]);
|
|
60
|
+
i += m[0].length;
|
|
61
|
+
idx++;
|
|
62
|
+
}
|
|
63
|
+
return ' ' + out.join(' ') + ' ';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Converts to absolute M, L, C, Q, A and Z commands.
|
|
67
|
+
export function absolutize(cmds) {
|
|
68
|
+
const out = [];
|
|
69
|
+
let x = 0;
|
|
70
|
+
let y = 0;
|
|
71
|
+
let sx = 0;
|
|
72
|
+
let sy = 0;
|
|
73
|
+
let lastC = null;
|
|
74
|
+
let lastQ = null;
|
|
75
|
+
for (const { c, v } of cmds) {
|
|
76
|
+
const rel = c === c.toLowerCase();
|
|
77
|
+
const up = c.toUpperCase();
|
|
78
|
+
const ax = (i) => v[i] + (rel ? x : 0);
|
|
79
|
+
const ay = (i) => v[i] + (rel ? y : 0);
|
|
80
|
+
let cCtrl = null;
|
|
81
|
+
let qCtrl = null;
|
|
82
|
+
switch (up) {
|
|
83
|
+
case 'M':
|
|
84
|
+
x = ax(0); y = ay(1); sx = x; sy = y;
|
|
85
|
+
out.push({ c: 'M', v: [x, y] });
|
|
86
|
+
break;
|
|
87
|
+
case 'L':
|
|
88
|
+
x = ax(0); y = ay(1);
|
|
89
|
+
out.push({ c: 'L', v: [x, y] });
|
|
90
|
+
break;
|
|
91
|
+
case 'H':
|
|
92
|
+
x = v[0] + (rel ? x : 0);
|
|
93
|
+
out.push({ c: 'L', v: [x, y] });
|
|
94
|
+
break;
|
|
95
|
+
case 'V':
|
|
96
|
+
y = v[0] + (rel ? y : 0);
|
|
97
|
+
out.push({ c: 'L', v: [x, y] });
|
|
98
|
+
break;
|
|
99
|
+
case 'C': {
|
|
100
|
+
const p = [ax(0), ay(1), ax(2), ay(3), ax(4), ay(5)];
|
|
101
|
+
out.push({ c: 'C', v: p });
|
|
102
|
+
cCtrl = [p[2], p[3]];
|
|
103
|
+
x = p[4]; y = p[5];
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
case 'S': {
|
|
107
|
+
const r1 = lastC ? [2 * x - lastC[0], 2 * y - lastC[1]] : [x, y];
|
|
108
|
+
const p = [r1[0], r1[1], ax(0), ay(1), ax(2), ay(3)];
|
|
109
|
+
out.push({ c: 'C', v: p });
|
|
110
|
+
cCtrl = [p[2], p[3]];
|
|
111
|
+
x = p[4]; y = p[5];
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case 'Q': {
|
|
115
|
+
const p = [ax(0), ay(1), ax(2), ay(3)];
|
|
116
|
+
out.push({ c: 'Q', v: p });
|
|
117
|
+
qCtrl = [p[0], p[1]];
|
|
118
|
+
x = p[2]; y = p[3];
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
case 'T': {
|
|
122
|
+
const r1 = lastQ ? [2 * x - lastQ[0], 2 * y - lastQ[1]] : [x, y];
|
|
123
|
+
const p = [r1[0], r1[1], ax(0), ay(1)];
|
|
124
|
+
out.push({ c: 'Q', v: p });
|
|
125
|
+
qCtrl = r1;
|
|
126
|
+
x = p[2]; y = p[3];
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
case 'A': {
|
|
130
|
+
const nx = ax(5);
|
|
131
|
+
const ny = ay(6);
|
|
132
|
+
out.push({ c: 'A', v: [v[0], v[1], v[2], v[3], v[4], nx, ny] });
|
|
133
|
+
x = nx; y = ny;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case 'Z':
|
|
137
|
+
out.push({ c: 'Z', v: [] });
|
|
138
|
+
x = sx; y = sy;
|
|
139
|
+
break;
|
|
140
|
+
default:
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
lastC = cCtrl;
|
|
144
|
+
lastQ = qCtrl;
|
|
145
|
+
}
|
|
146
|
+
return out;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Scales then translates absolute commands.
|
|
150
|
+
export function transform(cmds, s, tx = 0, ty = 0) {
|
|
151
|
+
return cmds.map(({ c, v }) => {
|
|
152
|
+
if (c === 'A') return { c, v: [v[0] * s, v[1] * s, v[2], v[3], v[4], v[5] * s + tx, v[6] * s + ty] };
|
|
153
|
+
return { c, v: v.map((n, i) => n * s + (i % 2 === 0 ? tx : ty)) };
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const r = (n) => Math.round(n * 100) / 100;
|
|
158
|
+
export function serialize(cmds) {
|
|
159
|
+
return cmds.map(({ c, v }) => c + v.map(r).join(' ')).join('');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function scalePath(d, s, tx = 0, ty = 0) {
|
|
163
|
+
return serialize(transform(absolutize(parsePath(d)), s, tx, ty));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Splits an absolute path string into subpath strings.
|
|
167
|
+
export function splitSubpaths(d) {
|
|
168
|
+
const cmds = absolutize(parsePath(d));
|
|
169
|
+
const out = [];
|
|
170
|
+
let cur = [];
|
|
171
|
+
for (const cmd of cmds) {
|
|
172
|
+
if (cmd.c === 'M' && cur.length) {
|
|
173
|
+
out.push(serialize(cur));
|
|
174
|
+
cur = [];
|
|
175
|
+
}
|
|
176
|
+
cur.push(cmd);
|
|
177
|
+
}
|
|
178
|
+
if (cur.length) out.push(serialize(cur));
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
let svgPath = null;
|
|
183
|
+
const lengths = new Map();
|
|
184
|
+
export function pathLength(d) {
|
|
185
|
+
let L = lengths.get(d);
|
|
186
|
+
if (L !== undefined) return L;
|
|
187
|
+
if (!svgPath) {
|
|
188
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
189
|
+
svg.setAttribute('width', '0');
|
|
190
|
+
svg.setAttribute('height', '0');
|
|
191
|
+
svg.style.position = 'absolute';
|
|
192
|
+
svgPath = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
193
|
+
svg.appendChild(svgPath);
|
|
194
|
+
document.body.appendChild(svg);
|
|
195
|
+
}
|
|
196
|
+
svgPath.setAttribute('d', d);
|
|
197
|
+
L = svgPath.getTotalLength() || 0;
|
|
198
|
+
if (lengths.size > 20000) lengths.clear();
|
|
199
|
+
lengths.set(d, L);
|
|
200
|
+
return L;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function pointAt(d, dist) {
|
|
204
|
+
pathLength(d);
|
|
205
|
+
svgPath.setAttribute('d', d);
|
|
206
|
+
const p = svgPath.getPointAtLength(dist);
|
|
207
|
+
return { x: p.x, y: p.y };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Shapes centred on 0,0.
|
|
211
|
+
export function rectD(w, h, rr = 0) {
|
|
212
|
+
const x = -w / 2;
|
|
213
|
+
const y = -h / 2;
|
|
214
|
+
const k = Math.max(0, Math.min(rr, w / 2, h / 2));
|
|
215
|
+
if (!k) return `M${r(x)} ${r(y)}L${r(x + w)} ${r(y)}L${r(x + w)} ${r(y + h)}L${r(x)} ${r(y + h)}Z`;
|
|
216
|
+
return `M${r(x + k)} ${r(y)}L${r(x + w - k)} ${r(y)}A${r(k)} ${r(k)} 0 0 1 ${r(x + w)} ${r(y + k)}L${r(x + w)} ${r(y + h - k)}A${r(k)} ${r(k)} 0 0 1 ${r(x + w - k)} ${r(y + h)}L${r(x + k)} ${r(y + h)}A${r(k)} ${r(k)} 0 0 1 ${r(x)} ${r(y + h - k)}L${r(x)} ${r(y + k)}A${r(k)} ${r(k)} 0 0 1 ${r(x + k)} ${r(y)}Z`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function ellipseD(w, h) {
|
|
220
|
+
const rx = w / 2;
|
|
221
|
+
const ry = h / 2;
|
|
222
|
+
return `M${r(-rx)} 0A${r(rx)} ${r(ry)} 0 1 1 ${r(rx)} 0A${r(rx)} ${r(ry)} 0 1 1 ${r(-rx)} 0Z`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function polyD(points, close = false) {
|
|
226
|
+
if (!points.length) return '';
|
|
227
|
+
let d = `M${r(points[0][0])} ${r(points[0][1])}`;
|
|
228
|
+
for (let i = 1; i < points.length; i++) d += `L${r(points[i][0])} ${r(points[i][1])}`;
|
|
229
|
+
return close ? d + 'Z' : d;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function quadD(a, c, b) {
|
|
233
|
+
return `M${r(a[0])} ${r(a[1])}Q${r(c[0])} ${r(c[1])} ${r(b[0])} ${r(b[1])}`;
|
|
234
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// Draws shapes either crisp (clean looks) or hand-drawn with rough.js
|
|
2
|
+
// (paper, chalk, blueprint), with a draw-on reveal for strokes and fills.
|
|
3
|
+
import { rectD, ellipseD, polyD, splitSubpaths, pathLength } from './pathdata.js';
|
|
4
|
+
import { withAlpha, hashStr, mulberry32, parseColor } from './util.js';
|
|
5
|
+
|
|
6
|
+
export class Pen {
|
|
7
|
+
constructor({ rough, theme }) {
|
|
8
|
+
this.gen = rough.generator();
|
|
9
|
+
this.theme = theme;
|
|
10
|
+
this.cache = new Map();
|
|
11
|
+
this.patterns = new Map();
|
|
12
|
+
this.seedOffset = 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// spec: { kind: 'rect', w, h, r } | { kind: 'ellipse', w, h } | { kind: 'poly', points, close }
|
|
16
|
+
// | { kind: 'path', d }
|
|
17
|
+
// style: { stroke, width, fill, fillStyle, dashed, seed, roughness, shadow, glow }
|
|
18
|
+
// prog: { stroke, fill } in 0..1
|
|
19
|
+
draw(ctx, spec, style, prog = { stroke: 1, fill: 1 }) {
|
|
20
|
+
const rough = style.rough ?? this.theme.stroke.rough;
|
|
21
|
+
if (rough) this.drawRough(ctx, spec, style, prog);
|
|
22
|
+
else this.drawClean(ctx, spec, style, prog);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
specD(spec) {
|
|
26
|
+
switch (spec.kind) {
|
|
27
|
+
case 'rect': return rectD(spec.w, spec.h, spec.r || 0);
|
|
28
|
+
case 'ellipse': return ellipseD(spec.w, spec.h);
|
|
29
|
+
case 'poly': return polyD(spec.points, spec.close);
|
|
30
|
+
case 'path': return spec.d;
|
|
31
|
+
default: throw new Error(`unknown shape kind ${spec.kind}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
prepared(d) {
|
|
36
|
+
const key = 'c|' + d;
|
|
37
|
+
let v = this.cache.get(key);
|
|
38
|
+
if (!v) {
|
|
39
|
+
const subs = splitSubpaths(d).map((sd) => ({ p2d: new Path2D(sd), len: pathLength(sd) }));
|
|
40
|
+
v = { full: new Path2D(d), subs, total: subs.reduce((a, s) => a + s.len, 0) };
|
|
41
|
+
this.remember(key, v);
|
|
42
|
+
}
|
|
43
|
+
return v;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
remember(key, v) {
|
|
47
|
+
if (this.cache.size > 4000) this.cache.clear();
|
|
48
|
+
this.cache.set(key, v);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
strokeStyleFor(color) {
|
|
52
|
+
if (this.theme.stroke.texture === 'chalk') return this.chalkPattern(color);
|
|
53
|
+
return color;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
chalkPattern(color) {
|
|
57
|
+
let p = this.patterns.get(color);
|
|
58
|
+
if (p) return p;
|
|
59
|
+
const c = document.createElement('canvas');
|
|
60
|
+
c.width = 192;
|
|
61
|
+
c.height = 192;
|
|
62
|
+
const g = c.getContext('2d');
|
|
63
|
+
g.fillStyle = color;
|
|
64
|
+
g.fillRect(0, 0, 192, 192);
|
|
65
|
+
const rand = mulberry32(hashStr(color));
|
|
66
|
+
g.globalCompositeOperation = 'destination-out';
|
|
67
|
+
for (let i = 0; i < 2600; i++) {
|
|
68
|
+
g.fillStyle = `rgba(0,0,0,${0.25 + rand() * 0.75})`;
|
|
69
|
+
const s = 0.6 + rand() * 1.8;
|
|
70
|
+
g.fillRect(rand() * 192, rand() * 192, s, s);
|
|
71
|
+
}
|
|
72
|
+
p = g.createPattern(c, 'repeat');
|
|
73
|
+
this.patterns.set(color, p);
|
|
74
|
+
return p;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
applyDash(ctx, style) {
|
|
78
|
+
if (style.dashed) ctx.setLineDash(Array.isArray(style.dashed) ? style.dashed : [style.width * 3, style.width * 2.4]);
|
|
79
|
+
else ctx.setLineDash([]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Strokes subpaths in order until `p` of the total length is drawn.
|
|
83
|
+
reveal(ctx, prep, p, dash) {
|
|
84
|
+
if (p <= 0) return;
|
|
85
|
+
if (p >= 0.999) {
|
|
86
|
+
if (dash) ctx.setLineDash(dash);
|
|
87
|
+
for (const s of prep.subs) ctx.stroke(s.p2d);
|
|
88
|
+
ctx.setLineDash([]);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
let left = prep.total * p;
|
|
92
|
+
for (const s of prep.subs) {
|
|
93
|
+
if (left <= 0) break;
|
|
94
|
+
if (left >= s.len) {
|
|
95
|
+
if (dash) ctx.setLineDash(dash);
|
|
96
|
+
ctx.stroke(s.p2d);
|
|
97
|
+
left -= s.len;
|
|
98
|
+
} else {
|
|
99
|
+
ctx.setLineDash(dashUpTo(dash, left, s.len));
|
|
100
|
+
ctx.stroke(s.p2d);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
ctx.setLineDash([]);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
drawClean(ctx, spec, style, prog) {
|
|
108
|
+
const d = this.specD(spec);
|
|
109
|
+
const prep = this.prepared(d);
|
|
110
|
+
const pf = prog.fill ?? 1;
|
|
111
|
+
const ps = prog.stroke ?? 1;
|
|
112
|
+
ctx.save();
|
|
113
|
+
if (style.fill && style.fill !== 'none' && pf > 0) {
|
|
114
|
+
const sh = style.shadow;
|
|
115
|
+
if (sh) {
|
|
116
|
+
ctx.shadowColor = sh.color;
|
|
117
|
+
ctx.shadowBlur = sh.blur;
|
|
118
|
+
ctx.shadowOffsetY = sh.y || 0;
|
|
119
|
+
}
|
|
120
|
+
ctx.fillStyle = pf < 1 ? withAlpha(style.fill, pf) : style.fill;
|
|
121
|
+
if (spec.kind !== 'poly' || spec.close) ctx.fill(prep.full);
|
|
122
|
+
ctx.shadowColor = 'transparent';
|
|
123
|
+
ctx.shadowBlur = 0;
|
|
124
|
+
ctx.shadowOffsetY = 0;
|
|
125
|
+
}
|
|
126
|
+
if (style.stroke && style.stroke !== 'none' && style.width > 0 && ps > 0) {
|
|
127
|
+
ctx.strokeStyle = this.strokeStyleFor(style.stroke);
|
|
128
|
+
ctx.lineWidth = style.width;
|
|
129
|
+
ctx.lineCap = 'round';
|
|
130
|
+
ctx.lineJoin = 'round';
|
|
131
|
+
if (style.glow) {
|
|
132
|
+
ctx.shadowColor = withAlpha(style.stroke, 0.65);
|
|
133
|
+
ctx.shadowBlur = style.glow;
|
|
134
|
+
}
|
|
135
|
+
this.reveal(ctx, prep, ps, style.dashed ? dashPattern(style) : null);
|
|
136
|
+
}
|
|
137
|
+
ctx.restore();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
drawRough(ctx, spec, style, prog) {
|
|
141
|
+
const t = this.theme.stroke;
|
|
142
|
+
const roughness = style.roughness ?? t.roughness;
|
|
143
|
+
const fillStyle = style.fillStyle || t.fillStyle || 'solid';
|
|
144
|
+
const hasFill = style.fill && style.fill !== 'none';
|
|
145
|
+
const seed = ((style.seed ?? 1) + this.seedOffset) % 2147483647 || 1;
|
|
146
|
+
const opts = {
|
|
147
|
+
seed,
|
|
148
|
+
roughness,
|
|
149
|
+
bowing: t.bowing ?? 1,
|
|
150
|
+
stroke: '#000',
|
|
151
|
+
strokeWidth: style.width || t.width,
|
|
152
|
+
fill: hasFill ? '#000' : undefined,
|
|
153
|
+
fillStyle,
|
|
154
|
+
hachureGap: style.hachureGap ?? t.hachureGap ?? 10,
|
|
155
|
+
fillWeight: style.fillWeight ?? t.fillWeight ?? 2,
|
|
156
|
+
hachureAngle: -41,
|
|
157
|
+
preserveVertices: spec.kind === 'poly',
|
|
158
|
+
disableMultiStroke: !!style.single,
|
|
159
|
+
curveStepCount: 9,
|
|
160
|
+
};
|
|
161
|
+
const key = 'r|' + JSON.stringify([spec.kind, spec.w, spec.h, spec.r, spec.points, spec.close, spec.d, opts.seed, opts.roughness, opts.bowing, opts.fill, opts.fillStyle, opts.hachureGap, opts.disableMultiStroke, opts.preserveVertices]);
|
|
162
|
+
let sets = this.cache.get(key);
|
|
163
|
+
if (!sets) {
|
|
164
|
+
let drawable;
|
|
165
|
+
if (spec.kind === 'rect' && !spec.r) drawable = this.gen.rectangle(-spec.w / 2, -spec.h / 2, spec.w, spec.h, opts);
|
|
166
|
+
else if (spec.kind === 'ellipse') drawable = this.gen.ellipse(0, 0, spec.w, spec.h, opts);
|
|
167
|
+
else if (spec.kind === 'poly' && !spec.close) drawable = this.gen.linearPath(spec.points, opts);
|
|
168
|
+
else if (spec.kind === 'poly' && spec.close) drawable = this.gen.polygon(spec.points, opts);
|
|
169
|
+
else drawable = this.gen.path(this.specD(spec), opts);
|
|
170
|
+
sets = drawable.sets.map((set) => {
|
|
171
|
+
const d = this.gen.opsToPath(set, 2);
|
|
172
|
+
const subs = splitSubpaths(d).map((sd) => ({ p2d: new Path2D(sd), len: pathLength(sd) }));
|
|
173
|
+
return { type: set.type, full: new Path2D(d), subs, total: subs.reduce((a, s) => a + s.len, 0) };
|
|
174
|
+
});
|
|
175
|
+
this.remember(key, sets);
|
|
176
|
+
}
|
|
177
|
+
const pf = prog.fill ?? 1;
|
|
178
|
+
const ps = prog.stroke ?? 1;
|
|
179
|
+
ctx.save();
|
|
180
|
+
ctx.lineCap = 'round';
|
|
181
|
+
ctx.lineJoin = 'round';
|
|
182
|
+
for (const set of sets) {
|
|
183
|
+
if (set.type === 'fillPath' && hasFill && pf > 0) {
|
|
184
|
+
if (style.shadow) {
|
|
185
|
+
ctx.shadowColor = style.shadow.color;
|
|
186
|
+
ctx.shadowBlur = style.shadow.blur;
|
|
187
|
+
ctx.shadowOffsetY = style.shadow.y || 0;
|
|
188
|
+
}
|
|
189
|
+
ctx.fillStyle = withAlpha(style.fill, pf);
|
|
190
|
+
ctx.fill(set.full);
|
|
191
|
+
ctx.shadowColor = 'transparent';
|
|
192
|
+
ctx.shadowBlur = 0;
|
|
193
|
+
} else if (set.type === 'fillSketch' && hasFill && pf > 0) {
|
|
194
|
+
ctx.strokeStyle = this.strokeStyleFor(style.fill);
|
|
195
|
+
ctx.lineWidth = opts.fillWeight;
|
|
196
|
+
this.reveal(ctx, set, pf, null);
|
|
197
|
+
} else if (set.type === 'path' && style.stroke && style.stroke !== 'none' && ps > 0) {
|
|
198
|
+
ctx.strokeStyle = this.strokeStyleFor(style.stroke);
|
|
199
|
+
ctx.lineWidth = opts.strokeWidth;
|
|
200
|
+
if (style.glow) {
|
|
201
|
+
ctx.shadowColor = withAlpha(style.stroke, 0.6);
|
|
202
|
+
ctx.shadowBlur = style.glow;
|
|
203
|
+
}
|
|
204
|
+
this.reveal(ctx, set, ps, style.dashed ? dashPattern(style) : null);
|
|
205
|
+
ctx.shadowColor = 'transparent';
|
|
206
|
+
ctx.shadowBlur = 0;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
ctx.restore();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function dashPattern(style) {
|
|
214
|
+
return Array.isArray(style.dashed) ? style.dashed : [style.width * 3.2, style.width * 2.6];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// A dash array that shows only the first `visible` units of a subpath,
|
|
218
|
+
// keeping a dash pattern if one is set.
|
|
219
|
+
function dashUpTo(dash, visible, len) {
|
|
220
|
+
if (!dash) return [visible, len + 1];
|
|
221
|
+
const out = [];
|
|
222
|
+
let acc = 0;
|
|
223
|
+
let i = 0;
|
|
224
|
+
while (acc < visible && out.length < 400) {
|
|
225
|
+
const take = Math.min(dash[i % dash.length], visible - acc);
|
|
226
|
+
out.push(take);
|
|
227
|
+
acc += take;
|
|
228
|
+
i++;
|
|
229
|
+
}
|
|
230
|
+
// Dash arrays alternate on, off, on, off. End with one long "off".
|
|
231
|
+
if (out.length % 2 === 1) out.push(len + 1);
|
|
232
|
+
else out.push(0, len + 1);
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function isDark(color) {
|
|
237
|
+
const p = parseColor(color);
|
|
238
|
+
if (!p) return false;
|
|
239
|
+
return (0.299 * p.r + 0.587 * p.g + 0.114 * p.b) / 255 < 0.5;
|
|
240
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<meta name="generator" content="explainroo web player">
|
|
7
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self'; connect-src 'self'; media-src 'self' blob:; object-src 'none'; base-uri 'none'">
|
|
8
|
+
<title>explainroo player</title>
|
|
9
|
+
<style>
|
|
10
|
+
*{box-sizing:border-box}html,body{margin:0;background:#111;color:#fff;font:14px system-ui,sans-serif}
|
|
11
|
+
#player{--accent:#c2e7ff;position:relative;width:100%;aspect-ratio:16/9;overflow:hidden;background:#111;container-type:inline-size;outline-offset:-3px}
|
|
12
|
+
#player:fullscreen{height:100%;display:grid;place-items:center}#player.quiet:fullscreen{cursor:none}
|
|
13
|
+
canvas,#poster{display:block;width:100%;height:100%;object-fit:contain}canvas{position:absolute;inset:0}
|
|
14
|
+
#poster{position:absolute;inset:0}#poster[hidden],#start[hidden],#controls[hidden]{display:none}
|
|
15
|
+
button{display:grid;place-items:center;position:relative;flex:none;width:44px;height:44px;padding:0;color:inherit;background:transparent;border:0;border-radius:8px;cursor:pointer;transition:background .15s}
|
|
16
|
+
button:hover{background:rgba(255,255,255,.12)}button:disabled{cursor:wait}
|
|
17
|
+
button svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round;pointer-events:none}
|
|
18
|
+
button[data-icon="play"] svg,button[data-icon="pause"] svg{fill:currentColor;stroke-width:1.2}
|
|
19
|
+
button:focus-visible,input:focus-visible,#player:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
|
|
20
|
+
#player:focus-visible{outline-offset:-3px}
|
|
21
|
+
#start{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:clamp(60px,16cqw,88px);height:clamp(60px,16cqw,88px);border-radius:50%;color:#101724;background:#f7f9fc;box-shadow:0 6px 32px rgba(0,0,0,.25);transition:background .15s,scale .15s}
|
|
22
|
+
#start:focus-visible{box-shadow:0 0 0 6px rgba(0,0,0,.7),0 6px 32px rgba(0,0,0,.25)}
|
|
23
|
+
#start:hover{background:#fff;scale:1.05}#start svg{width:42%;height:42%;fill:currentColor;stroke-width:1.2;translate:2px 0}
|
|
24
|
+
#controls{position:absolute;bottom:0;left:0;z-index:2;isolation:isolate;width:100%;padding:0 12px 6px;opacity:1;transition:opacity .2s}
|
|
25
|
+
#controls::before{content:"";position:absolute;inset:-40px 0 0;z-index:-1;pointer-events:none;background:linear-gradient(to bottom,transparent,rgba(5,7,12,.88) 45%,rgba(5,7,12,.98))}
|
|
26
|
+
#player.quiet #controls{opacity:0;pointer-events:none}#player.quiet #controls:has(:focus-visible){opacity:1;pointer-events:auto}
|
|
27
|
+
#buttons{display:flex;align-items:center;gap:4px}#cc{margin-left:auto}
|
|
28
|
+
#cc[aria-pressed="true"]{color:var(--accent);background:rgba(194,231,255,.12)}#cc[aria-pressed="true"]::after{content:"";position:absolute;bottom:5px;left:calc(50% - 7px);width:14px;height:2px;border-radius:2px;background:var(--accent)}
|
|
29
|
+
#seek{--played:0%;display:block;width:100%;height:40px;margin:0;padding:0;appearance:none;-webkit-appearance:none;background:transparent;cursor:pointer;touch-action:pan-y}
|
|
30
|
+
#seek::-webkit-slider-runnable-track{height:3px;border-radius:3px;background:linear-gradient(to right,var(--accent) var(--played),rgba(255,255,255,.3) var(--played))}
|
|
31
|
+
#seek::-moz-range-track{height:3px;border-radius:3px;background:rgba(255,255,255,.3)}#seek::-moz-range-progress{height:3px;border-radius:3px;background:var(--accent)}
|
|
32
|
+
#seek::-webkit-slider-thumb{appearance:none;-webkit-appearance:none;width:10px;height:10px;margin-top:-3.5px;border:0;border-radius:50%;background:var(--accent);transition:transform .15s}
|
|
33
|
+
#seek::-moz-range-thumb{width:10px;height:10px;border:0;border-radius:50%;background:var(--accent);transition:transform .15s}
|
|
34
|
+
#seek:hover::-webkit-slider-thumb,#seek:focus-visible::-webkit-slider-thumb{transform:scale(1.6)}#seek:hover::-moz-range-thumb,#seek:focus-visible::-moz-range-thumb{transform:scale(1.6)}
|
|
35
|
+
#time{margin-left:6px;color:rgba(255,255,255,.9);font-size:12px;font-variant-numeric:tabular-nums;white-space:nowrap;letter-spacing:.015em}
|
|
36
|
+
#captions{position:absolute;bottom:100px;left:7%;right:7%;z-index:3;text-align:center;white-space:pre-line;font-size:clamp(16px,2.2cqw,32px);line-height:1.4;pointer-events:none}
|
|
37
|
+
#player.quiet #captions{bottom:20px}#captions span{background:rgba(0,0,0,.8);padding:3px 8px;border-radius:4px;box-decoration-break:clone;-webkit-box-decoration-break:clone}#captions:empty{display:none}
|
|
38
|
+
#status{position:absolute;top:12px;left:12px;right:12px;text-align:center;background:rgba(0,0,0,.8)}#status:empty{display:none}
|
|
39
|
+
@container(min-width:700px){#controls{padding:8px 20px 10px}#seek{height:20px}button{width:36px;height:36px}button svg{width:20px;height:20px}#buttons{gap:8px}#captions{bottom:84px}}
|
|
40
|
+
@container(max-width:360px){button{width:40px;height:40px}button svg{width:20px;height:20px}#buttons{gap:2px}#controls{padding-inline:10px}#time{margin-left:4px}}
|
|
41
|
+
@media(prefers-reduced-motion:reduce){#controls,button,#start{transition:none}#seek::-webkit-slider-thumb{transition:none}#seek::-moz-range-thumb{transition:none}}
|
|
42
|
+
</style>
|
|
43
|
+
</head>
|
|
44
|
+
<body>
|
|
45
|
+
<main id="player" tabindex="0" aria-label="Video player">
|
|
46
|
+
<canvas id="c" aria-label="Video"></canvas>
|
|
47
|
+
<img id="poster" src="./poster.jpg" alt="Video cover">
|
|
48
|
+
<button id="start" aria-label="Play" title="Play" disabled>
|
|
49
|
+
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z"/></svg>
|
|
50
|
+
</button>
|
|
51
|
+
<div id="captions" role="region" aria-label="Captions"></div>
|
|
52
|
+
<div id="status" role="status"></div>
|
|
53
|
+
<div id="controls" role="group" aria-label="Playback controls" hidden>
|
|
54
|
+
<input id="seek" type="range" min="0" max="0" step="0.01" value="0" aria-label="Seek" disabled>
|
|
55
|
+
<div id="buttons">
|
|
56
|
+
<button id="play" aria-label="Play" title="Play" disabled></button>
|
|
57
|
+
<button id="mute" aria-label="Mute" title="Mute" aria-pressed="false"></button>
|
|
58
|
+
<span id="time">0:00 / 0:00</span>
|
|
59
|
+
<button id="cc" aria-label="Show captions" title="Show captions" aria-pressed="false"></button>
|
|
60
|
+
<button id="fullscreen" aria-label="Enter fullscreen" title="Enter fullscreen"></button>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
</main>
|
|
64
|
+
<audio id="audio" src="./audio.m4a" preload="none"><track id="track" kind="subtitles" src="./subtitles.vtt" srclang="en" label="English"></audio>
|
|
65
|
+
<script type="module" src="./engine/player.js"></script>
|
|
66
|
+
</body>
|
|
67
|
+
</html>
|