@biunow/agent-biutalk 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/bin/server.js +355 -0
  2. package/engine/AGENTS.md +1414 -0
  3. package/engine/CLAUDE.md +1 -0
  4. package/engine/LICENSE +21 -0
  5. package/engine/README.md +216 -0
  6. package/engine/bin/explainroo.js +19 -0
  7. package/engine/dev/audio-lab.mjs +268 -0
  8. package/engine/docs/media/contact-sheet.jpg +0 -0
  9. package/engine/docs/media/dns-poster.jpg +0 -0
  10. package/engine/docs/media/intro-poster.jpg +0 -0
  11. package/engine/docs/media/logo-dark.png +0 -0
  12. package/engine/docs/media/logo-light.png +0 -0
  13. package/engine/docs/media/looks-dark.webp +0 -0
  14. package/engine/docs/media/looks-light.webp +0 -0
  15. package/engine/docs/media/product-demo.webp +0 -0
  16. package/engine/docs/media/rebase-poster.jpg +0 -0
  17. package/engine/docs/media/sizes-dark.webp +0 -0
  18. package/engine/docs/media/sizes-light.webp +0 -0
  19. package/engine/engine/audio/dsp.js +69 -0
  20. package/engine/engine/audio/instruments.js +147 -0
  21. package/engine/engine/audio/music.js +576 -0
  22. package/engine/engine/audio/pcm.js +93 -0
  23. package/engine/engine/audio/rng.js +40 -0
  24. package/engine/engine/audio/sfx.js +287 -0
  25. package/engine/engine/audio/soundtrack.js +201 -0
  26. package/engine/engine/audio/synth.js +721 -0
  27. package/engine/engine/audio/theory.js +105 -0
  28. package/engine/engine/audio/wav.js +47 -0
  29. package/engine/engine/captions.js +131 -0
  30. package/engine/engine/clips.js +107 -0
  31. package/engine/engine/code.js +179 -0
  32. package/engine/engine/director.js +475 -0
  33. package/engine/engine/frame.html +135 -0
  34. package/engine/engine/icons/LICENSE-lucide.txt +43 -0
  35. package/engine/engine/icons/lucide-tags.json +1 -0
  36. package/engine/engine/icons/lucide.json +1 -0
  37. package/engine/engine/layout.js +69 -0
  38. package/engine/engine/pathdata.js +234 -0
  39. package/engine/engine/pen.js +240 -0
  40. package/engine/engine/player.html +67 -0
  41. package/engine/engine/player.js +219 -0
  42. package/engine/engine/readability.js +9 -0
  43. package/engine/engine/runtime.js +690 -0
  44. package/engine/engine/stage.js +2247 -0
  45. package/engine/engine/studio.html +216 -0
  46. package/engine/engine/text.js +81 -0
  47. package/engine/engine/themes.js +360 -0
  48. package/engine/engine/transitions.js +161 -0
  49. package/engine/engine/ui.js +1042 -0
  50. package/engine/engine/upload.js +32 -0
  51. package/engine/engine/util.js +204 -0
  52. package/engine/examples/callbacks-to-async-await/code-versions.js +34 -0
  53. package/engine/examples/callbacks-to-async-await/scenes.js +106 -0
  54. package/engine/examples/callbacks-to-async-await/script.md +22 -0
  55. package/engine/examples/callbacks-to-async-await/video.json +16 -0
  56. package/engine/examples/circle-area/scenes.js +228 -0
  57. package/engine/examples/circle-area/script.md +37 -0
  58. package/engine/examples/circle-area/video.json +14 -0
  59. package/engine/examples/explainroo-intro/scenes.js +133 -0
  60. package/engine/examples/explainroo-intro/script.md +27 -0
  61. package/engine/examples/explainroo-intro/video.json +8 -0
  62. package/engine/examples/how-dns-works/scenes.js +130 -0
  63. package/engine/examples/how-dns-works/script.md +28 -0
  64. package/engine/examples/how-dns-works/video.json +8 -0
  65. package/engine/examples/leap-years/scenes.js +156 -0
  66. package/engine/examples/leap-years/script.md +25 -0
  67. package/engine/examples/leap-years/video.json +16 -0
  68. package/engine/examples/leap-years-ja/scenes.js +194 -0
  69. package/engine/examples/leap-years-ja/script.md +32 -0
  70. package/engine/examples/leap-years-ja/video.json +17 -0
  71. package/engine/examples/merge-vs-rebase/scenes.js +129 -0
  72. package/engine/examples/merge-vs-rebase/script.md +22 -0
  73. package/engine/examples/merge-vs-rebase/video.json +8 -0
  74. package/engine/examples/password-storage-zh/scenes.js +185 -0
  75. package/engine/examples/password-storage-zh/script.md +25 -0
  76. package/engine/examples/password-storage-zh/video.json +19 -0
  77. package/engine/examples/sqlite-demo/README.md +19 -0
  78. package/engine/examples/sqlite-demo/scenes.js +423 -0
  79. package/engine/examples/sqlite-demo/script.md +35 -0
  80. package/engine/examples/sqlite-demo/video.json +17 -0
  81. package/engine/examples/unspar-demo/assets/fonts/Figtree-400.woff2 +0 -0
  82. package/engine/examples/unspar-demo/assets/fonts/Figtree-500.woff2 +0 -0
  83. package/engine/examples/unspar-demo/assets/fonts/Figtree-600.woff2 +0 -0
  84. package/engine/examples/unspar-demo/assets/fonts/Figtree-700.woff2 +0 -0
  85. package/engine/examples/unspar-demo/assets/fonts/Figtree-OFL.txt +93 -0
  86. package/engine/examples/unspar-demo/assets/unspar-logo.svg +23 -0
  87. package/engine/examples/unspar-demo/scenes.js +367 -0
  88. package/engine/examples/unspar-demo/script.md +25 -0
  89. package/engine/examples/unspar-demo/video.json +21 -0
  90. package/engine/examples/why-is-the-sky-blue-es/scenes.js +160 -0
  91. package/engine/examples/why-is-the-sky-blue-es/script.md +22 -0
  92. package/engine/examples/why-is-the-sky-blue-es/video.json +15 -0
  93. package/engine/fonts/ArchitectsDaughter-400-latin-ext.woff2 +0 -0
  94. package/engine/fonts/ArchitectsDaughter-400-latin.woff2 +0 -0
  95. package/engine/fonts/CabinSketch-400-latin.woff2 +0 -0
  96. package/engine/fonts/CabinSketch-700-latin.woff2 +0 -0
  97. package/engine/fonts/InstrumentSerif-400-italic-latin-ext.woff2 +0 -0
  98. package/engine/fonts/InstrumentSerif-400-italic-latin.woff2 +0 -0
  99. package/engine/fonts/InstrumentSerif-400-normal-latin-ext.woff2 +0 -0
  100. package/engine/fonts/InstrumentSerif-400-normal-latin.woff2 +0 -0
  101. package/engine/fonts/Inter-400-latin-ext.woff2 +0 -0
  102. package/engine/fonts/Inter-400-latin.woff2 +0 -0
  103. package/engine/fonts/JetBrainsMono-400-latin-ext.woff2 +0 -0
  104. package/engine/fonts/JetBrainsMono-400-latin.woff2 +0 -0
  105. package/engine/fonts/Kalam-400-latin-ext.woff2 +0 -0
  106. package/engine/fonts/Kalam-400-latin.woff2 +0 -0
  107. package/engine/fonts/Kalam-700-latin-ext.woff2 +0 -0
  108. package/engine/fonts/Kalam-700-latin.woff2 +0 -0
  109. package/engine/fonts/NotoSansDevanagari-400.ttf +0 -0
  110. package/engine/fonts/NotoSansDevanagari-700.ttf +0 -0
  111. package/engine/fonts/PatrickHand-400-latin-ext.woff2 +0 -0
  112. package/engine/fonts/PatrickHand-400-latin.woff2 +0 -0
  113. package/engine/fonts/PlusJakartaSans-600-latin-ext.woff2 +0 -0
  114. package/engine/fonts/PlusJakartaSans-600-latin.woff2 +0 -0
  115. package/engine/fonts/SpaceGrotesk-500-latin-ext.woff2 +0 -0
  116. package/engine/fonts/SpaceGrotesk-500-latin.woff2 +0 -0
  117. package/engine/fonts/fonts.json +216 -0
  118. package/engine/fonts/licenses/ArchitectsDaughter-OFL.txt +93 -0
  119. package/engine/fonts/licenses/CabinSketch-OFL.txt +93 -0
  120. package/engine/fonts/licenses/InstrumentSerif-OFL.txt +93 -0
  121. package/engine/fonts/licenses/Inter-OFL.txt +93 -0
  122. package/engine/fonts/licenses/JetBrainsMono-OFL.txt +93 -0
  123. package/engine/fonts/licenses/Kalam-OFL.txt +93 -0
  124. package/engine/fonts/licenses/NotoSansDevanagari-OFL.txt +118 -0
  125. package/engine/fonts/licenses/PatrickHand-OFL.txt +93 -0
  126. package/engine/fonts/licenses/PlusJakartaSans-OFL.txt +93 -0
  127. package/engine/fonts/licenses/SpaceGrotesk-OFL.txt +93 -0
  128. package/engine/package-lock.json +1201 -0
  129. package/engine/package.json +67 -0
  130. package/engine/scripts/build-icons.mjs +74 -0
  131. package/engine/scripts/fetch-fonts.mjs +68 -0
  132. package/engine/skills/explainroo/SKILL.md +51 -0
  133. package/engine/src/align.js +357 -0
  134. package/engine/src/browser.js +121 -0
  135. package/engine/src/capture.js +315 -0
  136. package/engine/src/chapters.js +32 -0
  137. package/engine/src/cli.js +421 -0
  138. package/engine/src/clips.js +19 -0
  139. package/engine/src/elevenlabs.js +90 -0
  140. package/engine/src/env.js +16 -0
  141. package/engine/src/export.js +187 -0
  142. package/engine/src/ffmpeg.js +103 -0
  143. package/engine/src/fonts.js +86 -0
  144. package/engine/src/g2p.py +76 -0
  145. package/engine/src/images.js +151 -0
  146. package/engine/src/licenses/misaki-Apache-2.0.txt +201 -0
  147. package/engine/src/math.js +83 -0
  148. package/engine/src/models.js +161 -0
  149. package/engine/src/phonemes.js +162 -0
  150. package/engine/src/pipeline.js +63 -0
  151. package/engine/src/project.js +331 -0
  152. package/engine/src/qa.js +186 -0
  153. package/engine/src/recordings.js +89 -0
  154. package/engine/src/render.js +156 -0
  155. package/engine/src/script.js +266 -0
  156. package/engine/src/server.js +288 -0
  157. package/engine/src/subtitles.js +78 -0
  158. package/engine/src/timeline.js +55 -0
  159. package/engine/src/voice.js +240 -0
  160. package/engine/src/wav.js +98 -0
  161. package/engine/templates/starter/scenes.js +31 -0
  162. package/engine/templates/starter/script.md +14 -0
  163. package/engine/test/align.test.js +108 -0
  164. package/engine/test/brand.test.js +41 -0
  165. package/engine/test/browser.test.js +89 -0
  166. package/engine/test/camera-browser.test.js +225 -0
  167. package/engine/test/caption-phrases.test.js +35 -0
  168. package/engine/test/capture-browser.test.js +90 -0
  169. package/engine/test/capture-fixture.js +46 -0
  170. package/engine/test/capture.test.js +62 -0
  171. package/engine/test/chapters.test.js +41 -0
  172. package/engine/test/cjk-browser.test.js +101 -0
  173. package/engine/test/cjk.test.js +232 -0
  174. package/engine/test/cli-exit.test.js +25 -0
  175. package/engine/test/cli.test.js +116 -0
  176. package/engine/test/clips-browser.test.js +125 -0
  177. package/engine/test/clips.test.js +67 -0
  178. package/engine/test/code-morph-browser.test.js +99 -0
  179. package/engine/test/code-morph.test.js +110 -0
  180. package/engine/test/contrast-browser.test.js +63 -0
  181. package/engine/test/contrast.test.js +80 -0
  182. package/engine/test/director.test.js +316 -0
  183. package/engine/test/engine-pure.test.js +29 -0
  184. package/engine/test/export-browser.test.js +224 -0
  185. package/engine/test/export.test.js +96 -0
  186. package/engine/test/fixtures/capture.html +55 -0
  187. package/engine/test/formats-pace.test.js +104 -0
  188. package/engine/test/languages-browser.test.js +78 -0
  189. package/engine/test/languages.test.js +140 -0
  190. package/engine/test/looks-browser.test.js +109 -0
  191. package/engine/test/looks-preview.test.js +57 -0
  192. package/engine/test/looks.test.js +130 -0
  193. package/engine/test/math-browser.test.js +114 -0
  194. package/engine/test/math.test.js +54 -0
  195. package/engine/test/multi-size-browser.test.js +133 -0
  196. package/engine/test/multi-size.test.js +116 -0
  197. package/engine/test/phonemes.test.js +92 -0
  198. package/engine/test/readability-browser.test.js +36 -0
  199. package/engine/test/readability.test.js +20 -0
  200. package/engine/test/render-options.test.js +52 -0
  201. package/engine/test/script.test.js +67 -0
  202. package/engine/test/server.test.js +256 -0
  203. package/engine/test/stills-browser.test.js +70 -0
  204. package/engine/test/subtitles.test.js +83 -0
  205. package/engine/test/timeline.test.js +31 -0
  206. package/engine/test/transparent-browser.test.js +123 -0
  207. package/engine/test/ui-kit.test.js +96 -0
  208. package/engine/test/upload-browser.test.js +55 -0
  209. package/engine/test/voice-providers.test.js +338 -0
  210. package/lib/host.mjs +480 -0
  211. package/manifest.json +54 -0
  212. package/package.json +8 -4
  213. package/skills/biutalk/SKILL.md +21 -0
  214. package/studio/app.js +209 -0
  215. package/studio/assert-panel-permit.mjs +67 -0
  216. package/studio/composer.css +354 -0
  217. package/studio/composer.js +169 -0
  218. package/studio/index.html +82 -0
  219. package/studio/looks/blueprint.svg +21 -0
  220. package/studio/looks/chalk.svg +15 -0
  221. package/studio/looks/clean.svg +20 -0
  222. package/studio/looks/editorial.svg +18 -0
  223. package/studio/looks/midnight.svg +17 -0
  224. package/studio/looks/paper.svg +11 -0
  225. package/studio/select-menu.js +268 -0
  226. package/studio/styles.css +4 -0
  227. package/README.md +0 -3
@@ -0,0 +1,216 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>explainroo preview</title>
7
+ <style>
8
+ :root { --bg: #111318; --panel: #1a1d24; --line: #2a2f3a; --fg: #e7eaf0; --muted: #8b93a3; --accent: #ffb347; }
9
+ * { box-sizing: border-box; }
10
+ html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 14px/1.4 system-ui, -apple-system, Segoe UI, sans-serif; }
11
+ #app { display: grid; grid-template-columns: 1fr 260px; grid-template-rows: 1fr auto; height: 100%; }
12
+ #stage { position: relative; display: flex; align-items: center; justify-content: center; padding: 20px; min-height: 0; }
13
+ #stage canvas { max-width: 100%; max-height: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.45); border-radius: 4px; background: #000; }
14
+ #side { grid-row: 1 / 3; grid-column: 2; background: var(--panel); border-left: 1px solid var(--line); overflow: auto; padding: 14px; }
15
+ #side h1 { font-size: 15px; margin: 0 0 4px; }
16
+ #side .sub { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
17
+ .scene { display: block; width: 100%; text-align: left; background: none; border: 1px solid transparent; color: var(--fg); padding: 8px 10px; border-radius: 8px; cursor: pointer; margin-bottom: 4px; font: inherit; }
18
+ .scene:hover { background: #222632; }
19
+ .scene.on { border-color: var(--accent); background: #262219; }
20
+ .scene b { display: block; font-size: 13px; }
21
+ .scene span { color: var(--muted); font-size: 12px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
22
+ #bar { grid-column: 1; display: flex; gap: 12px; align-items: center; padding: 10px 20px 16px; }
23
+ #bar button { background: var(--accent); color: #1a1407; border: 0; border-radius: 8px; padding: 8px 14px; font-weight: 700; cursor: pointer; min-width: 74px; }
24
+ #time { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 110px; }
25
+ #track { position: relative; flex: 1; height: 34px; cursor: pointer; }
26
+ #track .seg { position: absolute; top: 8px; height: 18px; border-radius: 4px; background: #2a2f3a; border: 1px solid #353b48; overflow: hidden; color: var(--muted); font-size: 11px; padding: 1px 5px; white-space: nowrap; }
27
+ #track .head { position: absolute; top: 2px; width: 2px; height: 30px; background: var(--accent); pointer-events: none; }
28
+ #status { color: var(--muted); font-size: 12px; min-width: 150px; text-align: right; }
29
+ #error { position: absolute; left: 20px; right: 20px; bottom: 20px; background: #3a1418; border: 1px solid #a33; color: #ffd6d6; padding: 12px 14px; border-radius: 8px; white-space: pre-wrap; font: 13px/1.45 ui-monospace, monospace; display: none; }
30
+ .keys { color: var(--muted); font-size: 12px; margin-top: 16px; line-height: 1.7; }
31
+ kbd { background: #2a2f3a; border-radius: 4px; padding: 1px 5px; font-size: 11px; }
32
+ </style>
33
+ </head>
34
+ <body>
35
+ <div id="app">
36
+ <div id="stage"><canvas id="c"></canvas><div id="error"></div></div>
37
+ <div id="side">
38
+ <h1 id="title">explainroo</h1>
39
+ <div class="sub" id="meta"></div>
40
+ <div id="scenes"></div>
41
+ <div class="keys"><kbd>space</kbd> play / pause<br><kbd>←</kbd> <kbd>→</kbd> one second<br><kbd>,</kbd> <kbd>.</kbd> one frame<br><kbd>[</kbd> <kbd>]</kbd> previous / next scene<br>Saving script.md or scenes.js reloads.</div>
42
+ </div>
43
+ <div id="bar">
44
+ <button id="play">Play</button>
45
+ <div id="time">0.00 / 0.00</div>
46
+ <div id="track"><div class="head" id="head"></div></div>
47
+ <div id="status"></div>
48
+ </div>
49
+ </div>
50
+ <script type="module">
51
+ import { boot, renderAudio, fetchState } from '/engine/runtime.js';
52
+
53
+ const canvas = document.getElementById('c');
54
+ const $ = (id) => document.getElementById(id);
55
+ let engine = null;
56
+ let audioMod = null;
57
+ let state = null;
58
+ let T = 0;
59
+ let playing = false;
60
+ let actx = null;
61
+ let source = null;
62
+ let startedAt = 0;
63
+ let mix = null;
64
+ let mixVersion = null;
65
+ let clockStart = 0;
66
+
67
+ function setStatus(s) { $('status').textContent = s; }
68
+ function showError(msg) { $('error').style.display = msg ? 'block' : 'none'; $('error').textContent = msg || ''; }
69
+
70
+ function draw() {
71
+ if (!engine) return;
72
+ try {
73
+ engine.renderFrame(Math.min(T, state.timeline.duration - 1 / state.config.fps));
74
+ showError(state.error ? 'script error: ' + state.error : '');
75
+ } catch (e) {
76
+ showError(`scene "${e.scene ?? '?'}" at ${e.sceneTime !== undefined ? Number(e.sceneTime).toFixed(2) + 's' : '?'}:\n${e.message}`);
77
+ }
78
+ const d = state.timeline.duration;
79
+ $('time').textContent = `${T.toFixed(2)} / ${d.toFixed(2)}`;
80
+ $('head').style.left = `${(T / d) * 100}%`;
81
+ const i = engine.sceneAt(T);
82
+ document.querySelectorAll('.scene').forEach((el, k) => el.classList.toggle('on', k === i));
83
+ }
84
+
85
+ function buildUi() {
86
+ const tl = state.timeline;
87
+ $('title').textContent = state.title || 'explainroo';
88
+ $('meta').textContent = `${state.config.theme} · ${state.config.width}x${state.config.height} · ${tl.duration.toFixed(1)}s · ${state.config.voice}`;
89
+ $('scenes').innerHTML = '';
90
+ $('track').querySelectorAll('.seg').forEach((s) => s.remove());
91
+ for (const sc of tl.scenes) {
92
+ const b = document.createElement('button');
93
+ b.className = 'scene';
94
+ b.innerHTML = `<b></b><span></span>`;
95
+ b.querySelector('b').textContent = `${sc.id} ${sc.start.toFixed(1)}s`;
96
+ b.querySelector('span').textContent = sc.text || '(no narration)';
97
+ b.onclick = () => seek(sc.start + 0.001);
98
+ $('scenes').appendChild(b);
99
+ const seg = document.createElement('div');
100
+ seg.className = 'seg';
101
+ seg.style.left = `${(sc.start / tl.duration) * 100}%`;
102
+ seg.style.width = `calc(${(sc.dur / tl.duration) * 100}% - 2px)`;
103
+ seg.textContent = sc.id;
104
+ $('track').insertBefore(seg, $('head'));
105
+ }
106
+ }
107
+
108
+ async function load(version) {
109
+ const scale = Math.min(1, 1280 / (await fetchState()).config.width);
110
+ const r = await boot({ canvas, scale, version });
111
+ if (engine) {
112
+ engine.onClipFrame = null;
113
+ engine.clipFrames.close();
114
+ }
115
+ engine = r.engine;
116
+ engine.onClipFrame = draw;
117
+ audioMod = r.audio;
118
+ state = r.state;
119
+ buildUi();
120
+ draw();
121
+ refreshAudio();
122
+ }
123
+
124
+ async function refreshAudio() {
125
+ if (!actx) return;
126
+ const v = state.version;
127
+ setStatus('mixing sound…');
128
+ try {
129
+ const { buffer } = await renderAudio(engine, audioMod);
130
+ if (state.version !== v) return;
131
+ mix = buffer;
132
+ mixVersion = v;
133
+ setStatus('');
134
+ if (playing) { stopSource(); startSource(); }
135
+ } catch (e) {
136
+ setStatus('sound failed');
137
+ showError('sound: ' + e.message);
138
+ }
139
+ }
140
+
141
+ function startSource() {
142
+ if (!mix || !actx) { clockStart = performance.now() / 1000 - T; return; }
143
+ source = actx.createBufferSource();
144
+ source.buffer = mix;
145
+ source.connect(actx.destination);
146
+ source.start(0, Math.min(T, mix.duration - 0.01));
147
+ startedAt = actx.currentTime - T;
148
+ }
149
+ function stopSource() { if (source) { try { source.stop(); } catch {} source = null; } }
150
+
151
+ function tick() {
152
+ if (playing) {
153
+ T = source ? actx.currentTime - startedAt : performance.now() / 1000 - clockStart;
154
+ if (T >= state.timeline.duration) { T = state.timeline.duration; pause(); }
155
+ draw();
156
+ }
157
+ requestAnimationFrame(tick);
158
+ }
159
+
160
+ async function play() {
161
+ if (!actx) { actx = new AudioContext(); await refreshAudio(); }
162
+ if (T >= state.timeline.duration - 0.05) T = 0;
163
+ playing = true;
164
+ $('play').textContent = 'Pause';
165
+ startSource();
166
+ }
167
+ function pause() { playing = false; stopSource(); $('play').textContent = 'Play'; draw(); }
168
+ function seek(t) { T = Math.max(0, Math.min(state.timeline.duration, t)); if (playing) { stopSource(); startSource(); } draw(); }
169
+
170
+ $('play').onclick = () => (playing ? pause() : play());
171
+ $('track').onclick = (e) => { const r = $('track').getBoundingClientRect(); seek(((e.clientX - r.left) / r.width) * state.timeline.duration); };
172
+ window.addEventListener('keydown', (e) => {
173
+ if (!state) return;
174
+ const f = 1 / state.config.fps;
175
+ if (e.key === ' ') { e.preventDefault(); playing ? pause() : play(); }
176
+ else if (e.key === 'ArrowRight') seek(T + 1);
177
+ else if (e.key === 'ArrowLeft') seek(T - 1);
178
+ else if (e.key === '.') seek(T + f);
179
+ else if (e.key === ',') seek(T - f);
180
+ else if (e.key === ']' || e.key === '[') {
181
+ const i = engine.sceneAt(T);
182
+ const j = Math.max(0, Math.min(state.timeline.scenes.length - 1, i + (e.key === ']' ? 1 : -1)));
183
+ seek(state.timeline.scenes[j].start + 0.001);
184
+ }
185
+ });
186
+
187
+ let failed = null;
188
+ async function poll() {
189
+ let s;
190
+ try {
191
+ s = await fetchState();
192
+ } catch {
193
+ setStatus('preview server stopped');
194
+ setTimeout(poll, 1500);
195
+ return;
196
+ }
197
+ const changed = !state || s.version !== state.version || s.error !== state.error;
198
+ if (changed && s.version !== failed) {
199
+ try {
200
+ const keep = T;
201
+ await load(s.version);
202
+ failed = null;
203
+ if (s.error) state.error = s.error;
204
+ seek(keep);
205
+ } catch (e) {
206
+ failed = s.version;
207
+ showError(e.message);
208
+ }
209
+ }
210
+ setTimeout(poll, 800);
211
+ }
212
+
213
+ load().catch((e) => showError(e.message)).finally(() => { requestAnimationFrame(tick); setTimeout(poll, 800); });
214
+ </script>
215
+ </body>
216
+ </html>
@@ -0,0 +1,81 @@
1
+ // Text layout: *accent* runs, word wrapping, and per-word positions so text
2
+ // can be revealed by line, by character or word by word.
3
+
4
+ // "Every site has an *address*" -> words with an accent flag.
5
+ export function parseRich(str) {
6
+ const words = [];
7
+ let accent = false;
8
+ const paragraphs = String(str).split('\n');
9
+ paragraphs.forEach((para, pi) => {
10
+ const tokens = para.split(/(\s+)/).filter((t) => t.length && !/^\s+$/.test(t));
11
+ for (let tok of tokens) {
12
+ let startAccent = accent;
13
+ let endToggle = false;
14
+ if (tok.startsWith('*') && tok.length > 1) {
15
+ startAccent = !accent;
16
+ tok = tok.slice(1);
17
+ }
18
+ if (tok.endsWith('*') && tok.length > 0) {
19
+ tok = tok.slice(0, -1);
20
+ endToggle = true;
21
+ } else {
22
+ const m = /^(.*?)\*([.,;:!?)"'’]*)$/.exec(tok);
23
+ if (m) {
24
+ tok = m[1] + m[2];
25
+ endToggle = true;
26
+ }
27
+ }
28
+ accent = startAccent;
29
+ if (tok) words.push({ text: tok, accent });
30
+ if (endToggle) accent = !accent;
31
+ }
32
+ if (pi < paragraphs.length - 1) words.push({ text: '\n', br: true });
33
+ });
34
+ return words;
35
+ }
36
+
37
+ // Returns { lines: [{ words: [{ text, accent, x, w, index }], width, y }], width, height, lineHeight, ascent }
38
+ // with x relative to the line start and y the baseline relative to the block top.
39
+ export function layoutText(ctx, { str, font, size, maxWidth = Infinity, lineHeight = 1.22 }) {
40
+ ctx.save();
41
+ ctx.font = font;
42
+ const words = parseRich(str);
43
+ const space = ctx.measureText(' ').width;
44
+ const lines = [];
45
+ let cur = { words: [], width: 0 };
46
+ let index = 0;
47
+ for (const w of words) {
48
+ if (w.br) {
49
+ lines.push(cur);
50
+ cur = { words: [], width: 0 };
51
+ continue;
52
+ }
53
+ const ww = ctx.measureText(w.text).width;
54
+ const next = cur.words.length ? cur.width + space + ww : ww;
55
+ if (cur.words.length && next > maxWidth) {
56
+ lines.push(cur);
57
+ cur = { words: [], width: 0 };
58
+ }
59
+ const x = cur.words.length ? cur.width + space : 0;
60
+ cur.words.push({ text: w.text, accent: w.accent, x, w: ww, index: index++ });
61
+ cur.width = x + ww;
62
+ }
63
+ lines.push(cur);
64
+ const m = ctx.measureText('Hxgy');
65
+ ctx.restore();
66
+ const ascent = m.actualBoundingBoxAscent || size * 0.75;
67
+ const descent = m.actualBoundingBoxDescent || size * 0.22;
68
+ const lh = size * lineHeight;
69
+ lines.forEach((l, i) => {
70
+ l.y = ascent + i * lh;
71
+ });
72
+ const width = Math.max(0, ...lines.map((l) => l.width));
73
+ const height = ascent + descent + (lines.length - 1) * lh;
74
+ return { lines, width, height, lineHeight: lh, ascent, descent, count: index, space };
75
+ }
76
+
77
+ export function lineStartX(line, blockWidth, align) {
78
+ if (align === 'left') return 0;
79
+ if (align === 'right') return blockWidth - line.width;
80
+ return (blockWidth - line.width) / 2;
81
+ }
@@ -0,0 +1,360 @@
1
+ // The six looks. A theme decides colors, fonts, how strokes are drawn, how
2
+ // elements enter, the default transition, the sound palette and the music.
3
+ import { mulberry32, mixColor, withAlpha, parseColor, rgba, clamp } from './util.js';
4
+
5
+ const PAPER = {
6
+ name: 'paper',
7
+ background: 'paper',
8
+ music: 'warm',
9
+ dark: false,
10
+ bg: '#f7f3ea',
11
+ ink: '#26221d',
12
+ muted: '#857f73',
13
+ surface: '#fffdf8',
14
+ accent: 'red',
15
+ colors: {
16
+ red: '#df5a3f', orange: '#ee8f3a', yellow: '#f1c04e', green: '#4f9a66', teal: '#2c9c8f',
17
+ blue: '#3c6fa8', purple: '#7b5fa6', pink: '#e07397', gray: '#8f887b', ink: '#26221d',
18
+ },
19
+ fonts: {
20
+ display: { family: 'Kalam', weight: 700 },
21
+ body: { family: 'Kalam', weight: 400 },
22
+ hand: { family: 'Patrick Hand', weight: 400 },
23
+ mono: { family: 'JetBrains Mono', weight: 400 },
24
+ },
25
+ stroke: { rough: true, roughness: 1.15, bowing: 1.2, width: 4.5, fillStyle: 'solid', hachureGap: 11, fillWeight: 2.4 },
26
+ radius: 14,
27
+ tintStrength: 0.2,
28
+ shadow: null,
29
+ enter: { shape: 'draw', text: 'write', title: 'write', icon: 'draw', image: 'pop', list: 'write', code: 'fade', chart: 'grow', number: 'fade' },
30
+ transition: 'brush',
31
+ sfx: { shape: 'scribble', arrow: 'scribble', line: 'scribble', icon: 'pop', image: 'pop', text: null, title: null, list: 'blip', number: 'tick', annotate: 'scribble', chart: 'scribble', code: 'type', terminal: 'type', burst: 'sparkle', transition: 'swipe' },
32
+ code: { bg: '#2b2723', fg: '#f3ede2', comment: '#8f887b', keyword: '#f19a6b', string: '#a8d08d', number: '#f1c04e', fn: '#8cc4f2', punct: '#c9c1b3', lineNo: '#6d665b', highlight: 'rgba(241,192,78,0.18)', border: '#26221d' },
33
+ terminal: { bg: '#23201c', fg: '#f3ede2', prompt: '#f1c04e', muted: '#9c9486', bar: '#35302a' },
34
+ caption: { bg: 'rgba(38,34,29,0.86)', fg: '#fffdf8', active: '#f1c04e' },
35
+ };
36
+
37
+ const CLEAN = {
38
+ name: 'clean',
39
+ background: 'dots',
40
+ music: 'upbeat',
41
+ dark: false,
42
+ bg: '#f4f6fb',
43
+ ink: '#111827',
44
+ muted: '#667085',
45
+ surface: '#ffffff',
46
+ accent: 'blue',
47
+ colors: {
48
+ red: '#f04452', orange: '#ff8a3d', yellow: '#f5b829', green: '#12b886', teal: '#0ea5a4',
49
+ blue: '#3b6cf6', purple: '#7c5cff', pink: '#ec4899', gray: '#98a2b3', ink: '#111827',
50
+ },
51
+ fonts: {
52
+ display: { family: 'Plus Jakarta Sans', weight: 800, tracking: -0.025 },
53
+ body: { family: 'Inter', weight: 400 },
54
+ hand: { family: 'Kalam', weight: 400 },
55
+ mono: { family: 'JetBrains Mono', weight: 400 },
56
+ },
57
+ stroke: { rough: false, width: 3.5 },
58
+ radius: 22,
59
+ tintStrength: 0.12,
60
+ shadow: { color: 'rgba(16,24,40,0.12)', blur: 30, y: 12 },
61
+ enter: { shape: 'pop', text: 'rise', title: 'rise', icon: 'pop', image: 'pop', list: 'rise', code: 'rise', chart: 'grow', number: 'rise', arrow: 'draw', line: 'draw' },
62
+ transition: 'slide',
63
+ sfx: { shape: 'pop', arrow: 'whoosh', line: 'whoosh', icon: 'pop', image: 'pop', text: null, title: null, list: 'blip', number: 'tick', annotate: 'whoosh', chart: 'whoosh', code: 'type', terminal: 'type', burst: 'sparkle', transition: 'swipe' },
64
+ code: { bg: '#0f172a', fg: '#e2e8f0', comment: '#64748b', keyword: '#c084fc', string: '#86efac', number: '#fbbf24', fn: '#7dd3fc', punct: '#94a3b8', lineNo: '#475569', highlight: 'rgba(59,108,246,0.25)', border: '#0f172a' },
65
+ terminal: { bg: '#0f172a', fg: '#e2e8f0', prompt: '#34d399', muted: '#94a3b8', bar: '#1e293b' },
66
+ caption: { bg: 'rgba(17,24,39,0.82)', fg: '#ffffff', active: '#7aa2ff' },
67
+ };
68
+
69
+ const CHALK = {
70
+ name: 'chalk',
71
+ background: 'chalk',
72
+ music: 'calm',
73
+ dark: true,
74
+ bg: '#233d31',
75
+ ink: '#f2f0e6',
76
+ muted: '#a9b8ae',
77
+ surface: '#2b4a3c',
78
+ accent: 'yellow',
79
+ colors: {
80
+ red: '#f28b82', orange: '#f7b267', yellow: '#f6e27f', green: '#a8e6a1', teal: '#84dcc6',
81
+ blue: '#9fd3ef', purple: '#c7aef2', pink: '#f6a8bf', gray: '#c9d1cb', ink: '#f2f0e6',
82
+ },
83
+ fonts: {
84
+ display: { family: 'Cabin Sketch', weight: 700 },
85
+ body: { family: 'Patrick Hand', weight: 400 },
86
+ hand: { family: 'Patrick Hand', weight: 400 },
87
+ mono: { family: 'JetBrains Mono', weight: 400 },
88
+ },
89
+ stroke: { rough: true, roughness: 1.35, bowing: 1.1, width: 5, fillStyle: 'solid', hachureGap: 13, fillWeight: 2.6, texture: 'chalk' },
90
+ radius: 12,
91
+ tintStrength: 0.16,
92
+ shadow: null,
93
+ enter: { shape: 'draw', text: 'write', title: 'write', icon: 'draw', image: 'fade', list: 'write', code: 'fade', chart: 'grow', number: 'fade' },
94
+ transition: 'brush',
95
+ sfx: { shape: 'chalk', arrow: 'chalk', line: 'chalk', icon: 'chalk', image: 'pop', text: null, title: null, list: 'blip', number: 'tick', annotate: 'chalk', chart: 'chalk', code: 'type', terminal: 'type', burst: 'sparkle', transition: 'swipe' },
96
+ code: { bg: '#1b3027', fg: '#f2f0e6', comment: '#8fa497', keyword: '#f6e27f', string: '#a8e6a1', number: '#f7b267', fn: '#9fd3ef', punct: '#c9d1cb', lineNo: '#6f8577', highlight: 'rgba(246,226,127,0.16)', border: '#f2f0e6' },
97
+ terminal: { bg: '#172a21', fg: '#f2f0e6', prompt: '#f6e27f', muted: '#a9b8ae', bar: '#1f3a2d' },
98
+ caption: { bg: 'rgba(20,34,27,0.88)', fg: '#f2f0e6', active: '#f6e27f' },
99
+ };
100
+
101
+ const BLUEPRINT = {
102
+ name: 'blueprint',
103
+ background: 'grid',
104
+ music: 'tech',
105
+ dark: true,
106
+ bg: '#12508f',
107
+ ink: '#f1f7ff',
108
+ muted: '#a9cbef',
109
+ surface: '#185c9f',
110
+ accent: 'yellow',
111
+ colors: {
112
+ red: '#ff8a80', orange: '#ffbd70', yellow: '#ffd866', green: '#a3f0b8', teal: '#8ff0e4',
113
+ blue: '#9fd6ff', purple: '#d0b8ff', pink: '#ffb3d1', gray: '#c3daf2', ink: '#f1f7ff',
114
+ },
115
+ fonts: {
116
+ display: { family: 'Architects Daughter', weight: 400 },
117
+ body: { family: 'Architects Daughter', weight: 400 },
118
+ hand: { family: 'Architects Daughter', weight: 400 },
119
+ mono: { family: 'JetBrains Mono', weight: 400 },
120
+ },
121
+ stroke: { rough: true, roughness: 0.55, bowing: 0.6, width: 3.5, fillStyle: 'solid', hachureGap: 14, fillWeight: 1.4 },
122
+ radius: 6,
123
+ tintStrength: 0.14,
124
+ shadow: null,
125
+ enter: { shape: 'draw', text: 'write', title: 'write', icon: 'draw', image: 'fade', list: 'write', code: 'fade', chart: 'grow', number: 'fade' },
126
+ transition: 'wipe',
127
+ sfx: { shape: 'scribble', arrow: 'whoosh', line: 'scribble', icon: 'click', image: 'pop', text: null, title: null, list: 'blip', number: 'tick', annotate: 'scribble', chart: 'scribble', code: 'type', terminal: 'type', burst: 'sparkle', transition: 'swipe' },
128
+ code: { bg: '#0d3d6e', fg: '#f1f7ff', comment: '#8fb6dd', keyword: '#ffd866', string: '#a3f0b8', number: '#ffbd70', fn: '#9fd6ff', punct: '#c3daf2', lineNo: '#6f9ccc', highlight: 'rgba(255,216,102,0.16)', border: '#f1f7ff' },
129
+ terminal: { bg: '#0b345e', fg: '#f1f7ff', prompt: '#ffd866', muted: '#a9cbef', bar: '#0e4478' },
130
+ caption: { bg: 'rgba(8,40,74,0.88)', fg: '#f1f7ff', active: '#ffd866' },
131
+ };
132
+
133
+ const MIDNIGHT = {
134
+ name: 'midnight',
135
+ background: 'glow',
136
+ music: 'tech',
137
+ dark: true,
138
+ bg: '#0b1020',
139
+ ink: '#e8eef8',
140
+ muted: '#8a97ad',
141
+ surface: '#141c31',
142
+ accent: 'teal',
143
+ colors: {
144
+ red: '#fb7185', orange: '#fb923c', yellow: '#fcd34d', green: '#34d399', teal: '#22d3ee',
145
+ blue: '#60a5fa', purple: '#a78bfa', pink: '#f472b6', gray: '#64748b', ink: '#e8eef8',
146
+ },
147
+ fonts: {
148
+ display: { family: 'Space Grotesk', weight: 700, tracking: -0.02 },
149
+ body: { family: 'Inter', weight: 400 },
150
+ hand: { family: 'Kalam', weight: 400 },
151
+ mono: { family: 'JetBrains Mono', weight: 400 },
152
+ },
153
+ stroke: { rough: false, width: 3, glow: 14 },
154
+ radius: 18,
155
+ tintStrength: 0.16,
156
+ shadow: { color: 'rgba(0,0,0,0.45)', blur: 34, y: 14 },
157
+ enter: { shape: 'pop', text: 'rise', title: 'rise', icon: 'pop', image: 'pop', list: 'rise', code: 'rise', chart: 'grow', number: 'rise', arrow: 'draw', line: 'draw' },
158
+ transition: 'zoom',
159
+ sfx: { shape: 'pop', arrow: 'whoosh', line: 'whoosh', icon: 'pop', image: 'pop', text: null, title: null, list: 'blip', number: 'tick', annotate: 'whoosh', chart: 'whoosh', code: 'type', terminal: 'type', burst: 'sparkle', transition: 'swipe' },
160
+ code: { bg: '#0f172a', fg: '#e2e8f0', comment: '#64748b', keyword: '#c084fc', string: '#86efac', number: '#fbbf24', fn: '#67e8f9', punct: '#94a3b8', lineNo: '#475569', highlight: 'rgba(34,211,238,0.16)', border: '#26324a' },
161
+ terminal: { bg: '#070b16', fg: '#e2e8f0', prompt: '#34d399', muted: '#94a3b8', bar: '#141c31' },
162
+ caption: { bg: 'rgba(7,11,22,0.82)', fg: '#e8eef8', active: '#22d3ee' },
163
+ };
164
+
165
+ const EDITORIAL = {
166
+ name: 'editorial',
167
+ background: 'paper',
168
+ music: 'calm',
169
+ dark: false,
170
+ bg: '#f5f1ea',
171
+ ink: '#1c1a17',
172
+ muted: '#76706a',
173
+ surface: '#fffdf9',
174
+ accent: 'red',
175
+ colors: {
176
+ red: '#c2462b', orange: '#c7782a', yellow: '#b8932a', green: '#3d7a57', teal: '#2c7a74',
177
+ blue: '#2f5b88', purple: '#6a4e8c', pink: '#b04870', gray: '#8a847b', ink: '#1c1a17',
178
+ },
179
+ fonts: {
180
+ display: { family: 'Instrument Serif', weight: 400, tracking: -0.01 },
181
+ body: { family: 'Inter', weight: 400 },
182
+ hand: { family: 'Instrument Serif', weight: 400 },
183
+ mono: { family: 'JetBrains Mono', weight: 400 },
184
+ },
185
+ stroke: { rough: false, width: 2.5 },
186
+ radius: 8,
187
+ tintStrength: 0.1,
188
+ shadow: { color: 'rgba(40,32,20,0.10)', blur: 24, y: 8 },
189
+ enter: { shape: 'fade', text: 'rise', title: 'rise', icon: 'fade', image: 'fade', list: 'rise', code: 'fade', chart: 'grow', number: 'rise', arrow: 'draw', line: 'draw' },
190
+ transition: 'fade',
191
+ sfx: { shape: 'pop', arrow: 'whoosh', line: 'whoosh', icon: 'pop', image: 'pop', text: null, title: null, list: 'blip', number: 'tick', annotate: 'whoosh', chart: 'whoosh', code: 'type', terminal: 'type', burst: 'sparkle', transition: 'swipe' },
192
+ code: { bg: '#1c1a17', fg: '#f3eee6', comment: '#8a847b', keyword: '#e0896f', string: '#a9c49a', number: '#e3b866', fn: '#9cc3dd', punct: '#bdb6aa', lineNo: '#6b655d', highlight: 'rgba(227,184,102,0.16)', border: '#1c1a17' },
193
+ terminal: { bg: '#1c1a17', fg: '#f3eee6', prompt: '#e3b866', muted: '#a49d92', bar: '#2c2925' },
194
+ caption: { bg: 'rgba(28,26,23,0.86)', fg: '#fffdf9', active: '#e3b866' },
195
+ };
196
+
197
+ export const THEMES = { paper: PAPER, clean: CLEAN, chalk: CHALK, blueprint: BLUEPRINT, midnight: MIDNIGHT, editorial: EDITORIAL };
198
+
199
+ export function getTheme(name, look = null) {
200
+ const t = THEMES[look ? look.extends : name];
201
+ if (!t) throw new Error(`unknown theme "${name}". Themes: ${Object.keys(THEMES).join(', ')}`);
202
+ if (!look) return t;
203
+ const { extends: base, ...overrides } = look;
204
+ const merge = (a, b) => Object.fromEntries(Object.entries({ ...a, ...b }).map(([k, v]) =>
205
+ [k, v && typeof v === 'object' && !Array.isArray(v) ? merge(a?.[k], v) : v]));
206
+ return merge(t, overrides);
207
+ }
208
+
209
+ // Resolves a color name ("blue", "accent", "ink", "muted") or passes a CSS color through.
210
+ export function colorOf(theme, c, fallback) {
211
+ if (c === undefined || c === null) return fallback === undefined ? theme.ink : colorOf(theme, fallback);
212
+ if (c === 'accent') return theme.colors[theme.accent];
213
+ if (c === 'ink') return theme.ink;
214
+ if (c === 'muted') return theme.muted;
215
+ if (c === 'bg') return theme.bg;
216
+ if (c === 'surface') return theme.surface;
217
+ if (c === 'none' || c === false) return 'none';
218
+ if (theme.colors[c]) return theme.colors[c];
219
+ return c;
220
+ }
221
+
222
+ // A light fill for a color on light themes, a translucent one on dark themes.
223
+ export function tintOf(theme, c) {
224
+ const base = colorOf(theme, c, 'accent');
225
+ if (base === 'none') return 'none';
226
+ if (theme.dark) return withAlpha(base, theme.tintStrength);
227
+ return mixColor(theme.surface, base, theme.tintStrength);
228
+ }
229
+
230
+ export function fontString(theme, role = 'body', size = 48, weight) {
231
+ const f = theme.fonts[role] || theme.fonts.body;
232
+ const w = weight ?? f.weight;
233
+ const fallback = role === 'mono' ? 'monospace' : 'sans-serif';
234
+ return `${w} ${Math.round(size * 100) / 100}px "${f.family}", "Noto Sans Devanagari", "Noto Sans JP", "Noto Sans SC", ${fallback}`;
235
+ }
236
+
237
+ // Background textures are rendered once and reused on every frame.
238
+ export function makeBackground(theme, W, H, seed = 1) {
239
+ const c = document.createElement('canvas');
240
+ c.width = W;
241
+ c.height = H;
242
+ const g = c.getContext('2d');
243
+ const rand = mulberry32(seed * 7919 + theme.name.length);
244
+ const base = Object.values(THEMES).find((t) => t.background === theme.background);
245
+ const bg = parseColor(theme.bg);
246
+ const original = parseColor(base?.bg || theme.bg);
247
+ // Shift the original tones with the background, keeping built-in pixels unchanged.
248
+ const tone = (color) => {
249
+ if (theme.bg === base?.bg) return color;
250
+ const p = parseColor(color);
251
+ return rgba({ r: clamp(p.r + bg.r - original.r, 0, 255), g: clamp(p.g + bg.g - original.g, 0, 255), b: clamp(p.b + bg.b - original.b, 0, 255), a: p.a });
252
+ };
253
+ const noise = (count, alphaMax, color, sizeMax = 1.6) => {
254
+ for (let i = 0; i < count; i++) {
255
+ g.fillStyle = withAlpha(color, rand() * alphaMax);
256
+ const s = 0.5 + rand() * sizeMax;
257
+ g.fillRect(rand() * W, rand() * H, s, s);
258
+ }
259
+ };
260
+ switch (theme.background) {
261
+ case 'paper': {
262
+ g.fillStyle = theme.bg;
263
+ g.fillRect(0, 0, W, H);
264
+ noise(Math.round(W * H * 0.05), 0.07, tone('#6b5a3d'));
265
+ noise(Math.round(W * H * 0.02), 0.08, tone('#ffffff'), 2);
266
+ g.lineWidth = 0.7;
267
+ for (let i = 0; i < 90; i++) {
268
+ g.strokeStyle = withAlpha(tone('#8a7654'), 0.05 + rand() * 0.05);
269
+ const x = rand() * W;
270
+ const y = rand() * H;
271
+ const a = rand() * Math.PI;
272
+ const l = 8 + rand() * 26;
273
+ g.beginPath();
274
+ g.moveTo(x, y);
275
+ g.quadraticCurveTo(x + Math.cos(a) * l * 0.5 + rand() * 4, y + Math.sin(a) * l * 0.5, x + Math.cos(a) * l, y + Math.sin(a) * l);
276
+ g.stroke();
277
+ }
278
+ const v = g.createRadialGradient(W / 2, H / 2, Math.min(W, H) * 0.35, W / 2, H / 2, Math.max(W, H) * 0.75);
279
+ v.addColorStop(0, tone('rgba(120,96,60,0)'));
280
+ v.addColorStop(1, tone('rgba(120,96,60,0.10)'));
281
+ g.fillStyle = v;
282
+ g.fillRect(0, 0, W, H);
283
+ break;
284
+ }
285
+ case 'dots': {
286
+ const gr = g.createLinearGradient(0, 0, W, H);
287
+ gr.addColorStop(0, tone('#f7f8fc'));
288
+ gr.addColorStop(1, tone('#eef1f8'));
289
+ g.fillStyle = gr;
290
+ g.fillRect(0, 0, W, H);
291
+ g.fillStyle = tone('rgba(17,24,39,0.045)');
292
+ const step = 48;
293
+ for (let y = step / 2; y < H; y += step) for (let x = step / 2; x < W; x += step) g.fillRect(x - 1.2, y - 1.2, 2.4, 2.4);
294
+ break;
295
+ }
296
+ case 'chalk': {
297
+ const gr = g.createRadialGradient(W * 0.45, H * 0.4, 0, W / 2, H / 2, Math.max(W, H) * 0.8);
298
+ gr.addColorStop(0, tone('#2a4a3b'));
299
+ gr.addColorStop(1, tone('#1b3127'));
300
+ g.fillStyle = gr;
301
+ g.fillRect(0, 0, W, H);
302
+ for (let i = 0; i < 26; i++) {
303
+ const x = rand() * W;
304
+ const y = rand() * H;
305
+ const r = 80 + rand() * 320;
306
+ const s = g.createRadialGradient(x, y, 0, x, y, r);
307
+ s.addColorStop(0, tone('rgba(235,240,230,0.035)'));
308
+ s.addColorStop(1, tone('rgba(235,240,230,0)'));
309
+ g.fillStyle = s;
310
+ g.fillRect(x - r, y - r, r * 2, r * 2);
311
+ }
312
+ noise(Math.round(W * H * 0.03), 0.06, tone('#e8efe6'));
313
+ break;
314
+ }
315
+ case 'grid': {
316
+ const gr = g.createLinearGradient(0, 0, 0, H);
317
+ gr.addColorStop(0, tone('#14589d'));
318
+ gr.addColorStop(1, tone('#0f4680'));
319
+ g.fillStyle = gr;
320
+ g.fillRect(0, 0, W, H);
321
+ const minor = Math.round(Math.min(W, H) / 34);
322
+ g.lineWidth = 1;
323
+ for (let x = 0; x <= W; x += minor) {
324
+ g.strokeStyle = tone(x % (minor * 5) === 0 ? 'rgba(190,225,255,0.20)' : 'rgba(190,225,255,0.08)');
325
+ g.beginPath();
326
+ g.moveTo(x + 0.5, 0);
327
+ g.lineTo(x + 0.5, H);
328
+ g.stroke();
329
+ }
330
+ for (let y = 0; y <= H; y += minor) {
331
+ g.strokeStyle = tone(y % (minor * 5) === 0 ? 'rgba(190,225,255,0.20)' : 'rgba(190,225,255,0.08)');
332
+ g.beginPath();
333
+ g.moveTo(0, y + 0.5);
334
+ g.lineTo(W, y + 0.5);
335
+ g.stroke();
336
+ }
337
+ noise(Math.round(W * H * 0.01), 0.05, tone('#ffffff'));
338
+ break;
339
+ }
340
+ case 'glow': {
341
+ g.fillStyle = theme.bg;
342
+ g.fillRect(0, 0, W, H);
343
+ const glow = (x, y, r, color) => {
344
+ const s = g.createRadialGradient(x, y, 0, x, y, r);
345
+ s.addColorStop(0, color);
346
+ s.addColorStop(1, 'rgba(0,0,0,0)');
347
+ g.fillStyle = s;
348
+ g.fillRect(0, 0, W, H);
349
+ };
350
+ glow(W * 0.12, H * 0.08, Math.max(W, H) * 0.6, tone('rgba(34,211,238,0.10)'));
351
+ glow(W * 0.92, H * 0.95, Math.max(W, H) * 0.55, tone('rgba(167,139,250,0.10)'));
352
+ noise(Math.round(W * H * 0.01), 0.05, tone('#ffffff'));
353
+ break;
354
+ }
355
+ default:
356
+ g.fillStyle = theme.bg;
357
+ g.fillRect(0, 0, W, H);
358
+ }
359
+ return c;
360
+ }