canvas-recorder-lib 0.5.0 → 0.7.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 (347) hide show
  1. package/BREAKING-CHANGES.md +24 -0
  2. package/README.md +131 -25
  3. package/dev/audio-builder.ts +69 -161
  4. package/dev/canvas-recorder.css +59 -0
  5. package/dev/canvas-recorder.ts +1006 -212
  6. package/dev/delay-files.ts +1 -1
  7. package/dev/font-utils.ts +8 -1
  8. package/dev/format-editor.ts +734 -0
  9. package/dev/format-string.ts +110 -0
  10. package/dev/local-file-row.ts +107 -0
  11. package/dev/multi-text-dialog.ts +360 -0
  12. package/dev/multi-text-panel.ts +11 -0
  13. package/dev/player-body.ts +94 -6
  14. package/dev/rect-snap.ts +9 -9
  15. package/dev/slide-panel.ts +1 -1
  16. package/dev/sound-clips.ts +3 -2
  17. package/dev/soundtrack.ts +434 -0
  18. package/dev/split-dialog.ts +13 -2
  19. package/dev/static-image-panel.ts +35 -5
  20. package/dev/timeline-display.ts +50 -5
  21. package/dev/transcripts.ts +5 -3
  22. package/dev/video-clip-panel.ts +202 -16
  23. package/dev/voice/chirp.ts +129 -0
  24. package/dev/voice/folder.ts +84 -0
  25. package/dev/voice/voice-panel.ts +513 -0
  26. package/dev/voice/voice-recorder.ts +603 -0
  27. package/dist/dev/audio-builder.d.ts +14 -31
  28. package/dist/dev/audio-builder.d.ts.map +1 -1
  29. package/dist/dev/audio-builder.js +62 -134
  30. package/dist/dev/audio-builder.js.map +1 -1
  31. package/dist/dev/canvas-recorder.css +59 -0
  32. package/dist/dev/canvas-recorder.js +926 -198
  33. package/dist/dev/canvas-recorder.js.map +1 -1
  34. package/dist/dev/delay-files.js +1 -1
  35. package/dist/dev/delay-files.js.map +1 -1
  36. package/dist/dev/font-utils.d.ts.map +1 -1
  37. package/dist/dev/font-utils.js +9 -1
  38. package/dist/dev/font-utils.js.map +1 -1
  39. package/dist/dev/format-editor.d.ts +75 -0
  40. package/dist/dev/format-editor.d.ts.map +1 -0
  41. package/dist/dev/format-editor.js +642 -0
  42. package/dist/dev/format-editor.js.map +1 -0
  43. package/dist/dev/format-string.d.ts +62 -0
  44. package/dist/dev/format-string.d.ts.map +1 -0
  45. package/dist/dev/format-string.js +86 -0
  46. package/dist/dev/format-string.js.map +1 -0
  47. package/dist/dev/local-file-row.d.ts +22 -0
  48. package/dist/dev/local-file-row.d.ts.map +1 -0
  49. package/dist/dev/local-file-row.js +84 -0
  50. package/dist/dev/local-file-row.js.map +1 -0
  51. package/dist/dev/multi-text-dialog.d.ts +30 -0
  52. package/dist/dev/multi-text-dialog.d.ts.map +1 -0
  53. package/dist/dev/multi-text-dialog.js +297 -0
  54. package/dist/dev/multi-text-dialog.js.map +1 -0
  55. package/dist/dev/multi-text-panel.d.ts +2 -0
  56. package/dist/dev/multi-text-panel.d.ts.map +1 -1
  57. package/dist/dev/multi-text-panel.js +4 -0
  58. package/dist/dev/multi-text-panel.js.map +1 -1
  59. package/dist/dev/player-body.d.ts +1 -1
  60. package/dist/dev/player-body.d.ts.map +1 -1
  61. package/dist/dev/player-body.js +94 -6
  62. package/dist/dev/player-body.js.map +1 -1
  63. package/dist/dev/rect-snap.d.ts +1 -1
  64. package/dist/dev/rect-snap.js +7 -7
  65. package/dist/dev/rect-snap.js.map +1 -1
  66. package/dist/dev/slide-panel.d.ts +1 -1
  67. package/dist/dev/slide-panel.d.ts.map +1 -1
  68. package/dist/dev/slide-panel.js +1 -1
  69. package/dist/dev/slide-panel.js.map +1 -1
  70. package/dist/dev/sound-clips.d.ts +3 -2
  71. package/dist/dev/sound-clips.d.ts.map +1 -1
  72. package/dist/dev/sound-clips.js +3 -2
  73. package/dist/dev/sound-clips.js.map +1 -1
  74. package/dist/dev/soundtrack.d.ts +115 -0
  75. package/dist/dev/soundtrack.d.ts.map +1 -0
  76. package/dist/dev/soundtrack.js +369 -0
  77. package/dist/dev/soundtrack.js.map +1 -0
  78. package/dist/dev/split-dialog.d.ts.map +1 -1
  79. package/dist/dev/split-dialog.js +14 -2
  80. package/dist/dev/split-dialog.js.map +1 -1
  81. package/dist/dev/static-image-panel.d.ts +2 -0
  82. package/dist/dev/static-image-panel.d.ts.map +1 -1
  83. package/dist/dev/static-image-panel.js +29 -5
  84. package/dist/dev/static-image-panel.js.map +1 -1
  85. package/dist/dev/timeline-display.d.ts +23 -2
  86. package/dist/dev/timeline-display.d.ts.map +1 -1
  87. package/dist/dev/timeline-display.js +47 -5
  88. package/dist/dev/timeline-display.js.map +1 -1
  89. package/dist/dev/transcripts.d.ts.map +1 -1
  90. package/dist/dev/transcripts.js +5 -3
  91. package/dist/dev/transcripts.js.map +1 -1
  92. package/dist/dev/video-clip-panel.d.ts +8 -0
  93. package/dist/dev/video-clip-panel.d.ts.map +1 -1
  94. package/dist/dev/video-clip-panel.js +176 -10
  95. package/dist/dev/video-clip-panel.js.map +1 -1
  96. package/dist/dev/voice/chirp.d.ts +27 -0
  97. package/dist/dev/voice/chirp.d.ts.map +1 -0
  98. package/dist/dev/voice/chirp.js +107 -0
  99. package/dist/dev/voice/chirp.js.map +1 -0
  100. package/dist/dev/voice/folder.d.ts +18 -0
  101. package/dist/dev/voice/folder.d.ts.map +1 -0
  102. package/dist/dev/voice/folder.js +68 -0
  103. package/dist/dev/voice/folder.js.map +1 -0
  104. package/dist/dev/voice/voice-panel.d.ts +44 -0
  105. package/dist/dev/voice/voice-panel.d.ts.map +1 -0
  106. package/dist/dev/voice/voice-panel.js +418 -0
  107. package/dist/dev/voice/voice-panel.js.map +1 -0
  108. package/dist/dev/voice/voice-recorder.d.ts +141 -0
  109. package/dist/dev/voice/voice-recorder.d.ts.map +1 -0
  110. package/dist/dev/voice/voice-recorder.js +506 -0
  111. package/dist/dev/voice/voice-recorder.js.map +1 -0
  112. package/dist/lib/index.d.ts +3 -0
  113. package/dist/lib/index.d.ts.map +1 -1
  114. package/dist/lib/index.js +3 -0
  115. package/dist/lib/index.js.map +1 -1
  116. package/dist/lib/main-control.d.ts +50 -4
  117. package/dist/lib/main-control.d.ts.map +1 -1
  118. package/dist/lib/main-control.js +94 -12
  119. package/dist/lib/main-control.js.map +1 -1
  120. package/dist/src/binary-search.js +1 -1
  121. package/dist/src/binary-search.js.map +1 -1
  122. package/dist/src/corner-rounder.d.ts +17 -0
  123. package/dist/src/corner-rounder.d.ts.map +1 -0
  124. package/dist/src/corner-rounder.js +89 -0
  125. package/dist/src/corner-rounder.js.map +1 -0
  126. package/dist/src/cross-fade.d.ts +1 -1
  127. package/dist/src/cross-fade.d.ts.map +1 -1
  128. package/dist/src/cross-fade.js +3 -3
  129. package/dist/src/cross-fade.js.map +1 -1
  130. package/dist/src/fancy-text.d.ts +116 -0
  131. package/dist/src/fancy-text.d.ts.map +1 -0
  132. package/dist/src/fancy-text.js +211 -0
  133. package/dist/src/fancy-text.js.map +1 -0
  134. package/dist/src/glib/letters-base.d.ts +1 -1
  135. package/dist/src/glib/letters-base.d.ts.map +1 -1
  136. package/dist/src/glib/letters-base.js +4 -3
  137. package/dist/src/glib/letters-base.js.map +1 -1
  138. package/dist/src/glib/line-font.d.ts +2 -2
  139. package/dist/src/glib/line-font.d.ts.map +1 -1
  140. package/dist/src/glib/line-font.js +2 -2
  141. package/dist/src/glib/line-font.js.map +1 -1
  142. package/dist/src/glib/paragraph-layout.d.ts +2 -2
  143. package/dist/src/glib/paragraph-layout.d.ts.map +1 -1
  144. package/dist/src/glib/paragraph-layout.js +1 -1
  145. package/dist/src/glib/paragraph-layout.js.map +1 -1
  146. package/dist/src/glib/path-shape-splitter.d.ts +1 -1
  147. package/dist/src/glib/path-shape-splitter.d.ts.map +1 -1
  148. package/dist/src/glib/path-shape-splitter.js +1 -1
  149. package/dist/src/glib/path-shape-splitter.js.map +1 -1
  150. package/dist/src/glib/path-shape.js +2 -2
  151. package/dist/src/glib/path-shape.js.map +1 -1
  152. package/dist/src/interpolate.d.ts +2 -2
  153. package/dist/src/interpolate.d.ts.map +1 -1
  154. package/dist/src/interpolate.js +1 -1
  155. package/dist/src/interpolate.js.map +1 -1
  156. package/dist/src/lattice.d.ts +1 -1
  157. package/dist/src/lattice.d.ts.map +1 -1
  158. package/dist/src/local-files.d.ts +129 -0
  159. package/dist/src/local-files.d.ts.map +1 -0
  160. package/dist/src/local-files.js +327 -0
  161. package/dist/src/local-files.js.map +1 -0
  162. package/dist/src/morph-animation.d.ts +1 -1
  163. package/dist/src/morph-animation.d.ts.map +1 -1
  164. package/dist/src/morph-animation.js +2 -2
  165. package/dist/src/morph-animation.js.map +1 -1
  166. package/dist/src/peano-fourier/fourier-shared.d.ts +1 -1
  167. package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
  168. package/dist/src/peano-fourier/fourier-shared.js +17 -4
  169. package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
  170. package/dist/src/schedule-helper.d.ts +4 -4
  171. package/dist/src/schedule-helper.d.ts.map +1 -1
  172. package/dist/src/schedule-helper.js +2 -2
  173. package/dist/src/schedule-helper.js.map +1 -1
  174. package/dist/src/showable.d.ts +45 -4
  175. package/dist/src/showable.d.ts.map +1 -1
  176. package/dist/src/showable.js +37 -1
  177. package/dist/src/showable.js.map +1 -1
  178. package/dist/src/slide-components/arrow.d.ts +4 -4
  179. package/dist/src/slide-components/arrow.d.ts.map +1 -1
  180. package/dist/src/slide-components/arrow.js +2 -2
  181. package/dist/src/slide-components/arrow.js.map +1 -1
  182. package/dist/src/slide-components/cross-fade-transition.d.ts +3 -3
  183. package/dist/src/slide-components/cross-fade-transition.d.ts.map +1 -1
  184. package/dist/src/slide-components/cross-fade-transition.js +3 -3
  185. package/dist/src/slide-components/cross-fade-transition.js.map +1 -1
  186. package/dist/src/slide-components/duration-agnostic.d.ts +3 -3
  187. package/dist/src/slide-components/duration-agnostic.d.ts.map +1 -1
  188. package/dist/src/slide-components/duration-agnostic.js +1 -1
  189. package/dist/src/slide-components/duration-agnostic.js.map +1 -1
  190. package/dist/src/slide-components/fixed-duration.d.ts +1 -1
  191. package/dist/src/slide-components/fixed-duration.d.ts.map +1 -1
  192. package/dist/src/slide-components/fixed-duration.js +1 -1
  193. package/dist/src/slide-components/fixed-duration.js.map +1 -1
  194. package/dist/src/slide-components/fourier.d.ts +6 -6
  195. package/dist/src/slide-components/fourier.d.ts.map +1 -1
  196. package/dist/src/slide-components/fourier.js +6 -6
  197. package/dist/src/slide-components/fourier.js.map +1 -1
  198. package/dist/src/slide-components/frame-counter.d.ts +2 -2
  199. package/dist/src/slide-components/frame-counter.d.ts.map +1 -1
  200. package/dist/src/slide-components/frame-counter.js +1 -1
  201. package/dist/src/slide-components/frame-counter.js.map +1 -1
  202. package/dist/src/slide-components/function-graph.d.ts +2 -2
  203. package/dist/src/slide-components/function-graph.d.ts.map +1 -1
  204. package/dist/src/slide-components/function-graph.js +3 -3
  205. package/dist/src/slide-components/function-graph.js.map +1 -1
  206. package/dist/src/slide-components/halftone-shadow.d.ts +4 -4
  207. package/dist/src/slide-components/halftone-shadow.d.ts.map +1 -1
  208. package/dist/src/slide-components/halftone-shadow.js +2 -2
  209. package/dist/src/slide-components/halftone-shadow.js.map +1 -1
  210. package/dist/src/slide-components/handwriting-effect.d.ts +5 -5
  211. package/dist/src/slide-components/handwriting-effect.d.ts.map +1 -1
  212. package/dist/src/slide-components/handwriting-effect.js +5 -5
  213. package/dist/src/slide-components/handwriting-effect.js.map +1 -1
  214. package/dist/src/slide-components/hold.d.ts +3 -3
  215. package/dist/src/slide-components/hold.d.ts.map +1 -1
  216. package/dist/src/slide-components/hold.js +3 -3
  217. package/dist/src/slide-components/hold.js.map +1 -1
  218. package/dist/src/slide-components/image.d.ts +3 -3
  219. package/dist/src/slide-components/image.d.ts.map +1 -1
  220. package/dist/src/slide-components/image.js +3 -3
  221. package/dist/src/slide-components/image.js.map +1 -1
  222. package/dist/src/slide-components/in-parallel.d.ts +3 -3
  223. package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
  224. package/dist/src/slide-components/in-parallel.js +2 -2
  225. package/dist/src/slide-components/in-parallel.js.map +1 -1
  226. package/dist/src/slide-components/in-series.d.ts +4 -4
  227. package/dist/src/slide-components/in-series.d.ts.map +1 -1
  228. package/dist/src/slide-components/in-series.js +5 -1
  229. package/dist/src/slide-components/in-series.js.map +1 -1
  230. package/dist/src/slide-components/live-duration.d.ts +1 -1
  231. package/dist/src/slide-components/live-duration.d.ts.map +1 -1
  232. package/dist/src/slide-components/live-duration.js +1 -1
  233. package/dist/src/slide-components/live-duration.js.map +1 -1
  234. package/dist/src/slide-components/multi-text.d.ts +76 -15
  235. package/dist/src/slide-components/multi-text.d.ts.map +1 -1
  236. package/dist/src/slide-components/multi-text.js +170 -25
  237. package/dist/src/slide-components/multi-text.js.map +1 -1
  238. package/dist/src/slide-components/rectangle.d.ts +3 -3
  239. package/dist/src/slide-components/rectangle.d.ts.map +1 -1
  240. package/dist/src/slide-components/rectangle.js +1 -1
  241. package/dist/src/slide-components/rectangle.js.map +1 -1
  242. package/dist/src/slide-components/registry.d.ts +1 -1
  243. package/dist/src/slide-components/registry.d.ts.map +1 -1
  244. package/dist/src/slide-components/registry.js +18 -18
  245. package/dist/src/slide-components/registry.js.map +1 -1
  246. package/dist/src/slide-components/serialize.d.ts +1 -1
  247. package/dist/src/slide-components/serialize.d.ts.map +1 -1
  248. package/dist/src/slide-components/serialize.js +2 -2
  249. package/dist/src/slide-components/serialize.js.map +1 -1
  250. package/dist/src/slide-components/show-error.js +2 -2
  251. package/dist/src/slide-components/show-error.js.map +1 -1
  252. package/dist/src/slide-components/simple-text.d.ts +4 -4
  253. package/dist/src/slide-components/simple-text.d.ts.map +1 -1
  254. package/dist/src/slide-components/simple-text.js +4 -4
  255. package/dist/src/slide-components/simple-text.js.map +1 -1
  256. package/dist/src/slide-components/slide-component.d.ts +5 -5
  257. package/dist/src/slide-components/slide-component.d.ts.map +1 -1
  258. package/dist/src/slide-components/slide-component.js +4 -4
  259. package/dist/src/slide-components/slide-component.js.map +1 -1
  260. package/dist/src/slide-components/slide-left.d.ts +3 -3
  261. package/dist/src/slide-components/slide-left.d.ts.map +1 -1
  262. package/dist/src/slide-components/slide-left.js +3 -3
  263. package/dist/src/slide-components/slide-left.js.map +1 -1
  264. package/dist/src/slide-components/split-video-clip.d.ts +2 -2
  265. package/dist/src/slide-components/split-video-clip.d.ts.map +1 -1
  266. package/dist/src/slide-components/split-video-clip.js +3 -3
  267. package/dist/src/slide-components/split-video-clip.js.map +1 -1
  268. package/dist/src/slide-components/text-effect.d.ts +2 -2
  269. package/dist/src/slide-components/text-effect.d.ts.map +1 -1
  270. package/dist/src/slide-components/traditional-text.d.ts +4 -4
  271. package/dist/src/slide-components/traditional-text.d.ts.map +1 -1
  272. package/dist/src/slide-components/traditional-text.js +3 -3
  273. package/dist/src/slide-components/traditional-text.js.map +1 -1
  274. package/dist/src/slide-components/video-clip.d.ts +17 -5
  275. package/dist/src/slide-components/video-clip.d.ts.map +1 -1
  276. package/dist/src/slide-components/video-clip.js +52 -11
  277. package/dist/src/slide-components/video-clip.js.map +1 -1
  278. package/dist/src/slide-components/video-info.d.ts +11 -11
  279. package/dist/src/slide-components/video-info.d.ts.map +1 -1
  280. package/dist/src/slide-components/video-info.js +32 -21
  281. package/dist/src/slide-components/video-info.js.map +1 -1
  282. package/dist/src/slow-image-sources.d.ts +7 -1
  283. package/dist/src/slow-image-sources.d.ts.map +1 -1
  284. package/dist/src/slow-image-sources.js +36 -5
  285. package/dist/src/slow-image-sources.js.map +1 -1
  286. package/dist/src/snapshot.d.ts +2 -2
  287. package/dist/src/snapshot.d.ts.map +1 -1
  288. package/dist/src/snapshot.js +31 -15
  289. package/dist/src/snapshot.js.map +1 -1
  290. package/dist/src/stroke-colors.d.ts +1 -1
  291. package/dist/src/stroke-colors.d.ts.map +1 -1
  292. package/dist/src/stroke-colors.js +4 -4
  293. package/dist/src/stroke-colors.js.map +1 -1
  294. package/dist/src/utility.d.ts +3 -4
  295. package/dist/src/utility.d.ts.map +1 -1
  296. package/dist/src/utility.js +4 -4
  297. package/dist/src/utility.js.map +1 -1
  298. package/lib/index.ts +3 -0
  299. package/lib/main-control.ts +119 -12
  300. package/package.json +7 -5
  301. package/src/binary-search.ts +2 -2
  302. package/src/corner-rounder.ts +128 -0
  303. package/src/cross-fade.ts +3 -3
  304. package/src/fancy-text.ts +255 -0
  305. package/src/glib/letters-base.ts +4 -3
  306. package/src/glib/line-font.ts +2 -2
  307. package/src/glib/paragraph-layout.ts +2 -2
  308. package/src/glib/path-shape-splitter.ts +1 -1
  309. package/src/glib/path-shape.ts +2 -2
  310. package/src/interpolate.ts +3 -3
  311. package/src/lattice.ts +1 -1
  312. package/src/local-files.ts +389 -0
  313. package/src/morph-animation.ts +2 -2
  314. package/src/peano-fourier/fourier-shared.ts +17 -4
  315. package/src/schedule-helper.ts +4 -4
  316. package/src/showable.ts +63 -4
  317. package/src/slide-components/arrow.ts +4 -4
  318. package/src/slide-components/cross-fade-transition.ts +4 -4
  319. package/src/slide-components/duration-agnostic.ts +3 -3
  320. package/src/slide-components/fixed-duration.ts +1 -1
  321. package/src/slide-components/fourier.ts +9 -9
  322. package/src/slide-components/frame-counter.ts +2 -2
  323. package/src/slide-components/function-graph.ts +4 -4
  324. package/src/slide-components/halftone-shadow.ts +4 -4
  325. package/src/slide-components/handwriting-effect.ts +7 -7
  326. package/src/slide-components/hold.ts +4 -4
  327. package/src/slide-components/image.ts +5 -5
  328. package/src/slide-components/in-parallel.ts +4 -4
  329. package/src/slide-components/in-series.ts +7 -4
  330. package/src/slide-components/live-duration.ts +1 -1
  331. package/src/slide-components/multi-text.ts +195 -30
  332. package/src/slide-components/rectangle.ts +3 -3
  333. package/src/slide-components/registry.ts +19 -19
  334. package/src/slide-components/serialize.ts +2 -2
  335. package/src/slide-components/show-error.ts +2 -2
  336. package/src/slide-components/simple-text.ts +7 -7
  337. package/src/slide-components/slide-component.ts +7 -7
  338. package/src/slide-components/slide-left.ts +4 -4
  339. package/src/slide-components/split-video-clip.ts +4 -4
  340. package/src/slide-components/text-effect.ts +2 -2
  341. package/src/slide-components/traditional-text.ts +5 -5
  342. package/src/slide-components/video-clip.ts +64 -13
  343. package/src/slide-components/video-info.ts +33 -21
  344. package/src/slow-image-sources.ts +38 -6
  345. package/src/snapshot.ts +34 -19
  346. package/src/stroke-colors.ts +4 -4
  347. package/src/utility.ts +5 -5
@@ -0,0 +1,24 @@
1
+ # Breaking Changes
2
+
3
+ Changes that can break a project using this library, newest first, and what to do about each.
4
+ This is not a full list of changes: new features and fixes aren't here.
5
+
6
+ While the version is 0.x, every breaking change comes with a new minor version (0.5 → 0.6), and nothing else does.
7
+ A project that depends on `"^0.5.0"` gets 0.5.x updates but never 0.6.0, so it only meets these changes when someone installs the new version on purpose.
8
+
9
+ ## 0.7.0 (2026-11-07)
10
+
11
+ - **`VisualEditorAPI.getDecodedBuffer()` returns a mono buffer,** at 48 kHz, for every file.
12
+ It used to return the file's own channels, so a stereo file's channel 0 was its left channel; now it's the average of both.
13
+ A waveform drawn from channel 0 still works, and shows the whole sound. Code that reads channel 1 should read channel 0.
14
+
15
+ ## 0.6.0 (2026-11-05)
16
+
17
+ - **`CANVAS_WIDTH_UNITS`, `CANVAS_HEIGHT_UNITS` and `PIXELS_PER_UNIT` are gone** from `src/slide-components/video-info`.
18
+ The video's size can change now, from the GUI or from `canvasRecorder.size`, so a constant can't hold it.
19
+ Use `canvasWidthUnits()`, `canvasHeightUnits()` and `pixelsPerUnit()` instead, and call them while drawing, not when the module loads.
20
+ To keep the old fixed size, set it in your main program and call `canvasRecorder.lockSize()`.
21
+
22
+ ## 0.5.0 (2026-10-18)
23
+
24
+ The first version on npm.
package/README.md CHANGED
@@ -3,10 +3,20 @@
3
3
  Preview, edit, annotate and record HTML canvas animations.
4
4
  This is the tooling from [canvas-recorder](https://github.com/TradeIdeasPhilip/canvas-recorder), packaged as a library, so each video can be its own small project.
5
5
 
6
- **Status:** version 0.x, a first version. Expect breaking changes.
6
+ **Status:** in use for published videos.
7
+ It's still growing: while the version is 0.x, a change that could break your project comes with a new minor version (0.5 → 0.6), and [BREAKING-CHANGES.md](BREAKING-CHANGES.md) says what changed and how to update.
8
+
9
+ **Source:** https://github.com/TradeIdeasPhilip/canvas-recorder-lib
7
10
 
8
11
  **API docs:** https://tradeideasphilip.github.io/canvas-recorder-lib/
9
12
 
13
+ **Try it:** the [Simple Video Editor](https://tradeideasphilip.github.io/canvas-recorder-lib/simple-video-editor/) is this library's player and Visual Editor with an empty project: open video clips from your computer, add text and callouts, and save an MP4.
14
+ Its source is in [simple-video-editor/](https://github.com/TradeIdeasPhilip/canvas-recorder-lib/tree/master/simple-video-editor).
15
+
16
+ **Showcase:** the [showcase](https://tradeideasphilip.github.io/canvas-recorder-lib/tests/showcase.html) is a series of slides that show what the library can do, one topic per slide.
17
+ Looking for code or ideas to copy? Start there.
18
+ Its source is in [test-project/src/showcase/](https://github.com/TradeIdeasPhilip/canvas-recorder-lib/tree/master/test-project/src/showcase), one file per slide.
19
+
10
20
  ## Use
11
21
 
12
22
  ```ts
@@ -17,9 +27,17 @@ import { myVideo } from "./my-video.ts"; // Any Showable.
17
27
  // canvasRecorder.pixelWidth = 1920;
18
28
  // canvasRecorder.pixelHeight = 1080;
19
29
 
30
+ // Optional. For a video drawn for one specific size.
31
+ // canvasRecorder.lockSize();
32
+
20
33
  canvasRecorder.start(myVideo, { name: "my-video" });
21
34
  ```
22
35
 
36
+ The player shows the video's size (pixels and units) in four fields.
37
+ Unless the program calls `lockSize()`, the user can change them, and the player remembers the change for this video.
38
+ So read `canvasRecorder.width` and the rest while drawing, not once at startup.
39
+ The Save dialog can also save one file at a different size, without changing the video.
40
+
23
41
  `start()` replaces the page's `<body>` with the player and its Visual Editor.
24
42
  Leave your HTML's body empty, or put "Please wait…" in it.
25
43
 
@@ -33,19 +51,70 @@ Imports:
33
51
 
34
52
  The package includes the TypeScript source next to the compiled JavaScript, and Go to Definition takes you to the source.
35
53
 
54
+ ## Quick Examples to Copy
55
+
56
+ If you want to create a new video you need to start by creating a new project.
57
+ At the time of this writing the [7 pointed stars](https://github.com/TradeIdeasPhilip/7-pointed-star) video is the most up to date example.
58
+ You can start a new project using [degit](https://github.com/Rich-Harris/degit) to copy this.
59
+
60
+ Note: The embedded test projects show how to write code that uses this library.
61
+ But don't try to copy the entire project.
62
+ Files like .gitignore and package.json will be different for embedded projects like these and stand alone projects like yours.
63
+ This refers to simple-video-editor and showcase found in this repository.
64
+
65
+ Note: [Riemann](https://github.com/TradeIdeasPhilip/riemann-surfaces-3d) provides a different type of example.
66
+ This shows how to attach this library to a project that was not specifically developed for this library.
67
+
36
68
  ## Notes for a project that uses this library
37
69
 
38
70
  Things the first project to use this library ([riemann-surfaces-3d](https://github.com/TradeIdeasPhilip/riemann-surfaces-3d)) ran into.
39
71
 
72
+ ### Installing
73
+
74
+ ```bash
75
+ npm install canvas-recorder-lib
76
+ npm install-scripts deny onnxruntime-node protobufjs
77
+ npm install-scripts ls # should say "No packages with unreviewed install scripts."
78
+ ```
79
+
80
+ - **Depend on the published version,** not `"file:../canvas-recorder-lib"`.
81
+ A `file:` dependency works on your machine, but GitHub's build machine has no `../canvas-recorder-lib`, so your GitHub Pages deploy fails.
82
+ `npm ci` doesn't notice; `tsc` stops with "Cannot find module 'canvas-recorder-lib'."
83
+ - **Deny those two install scripts.** npm 11 skips dependencies' install scripts until your project approves or denies them, and warns about each one.
84
+ Both come from `@huggingface/transformers`, which the library uses for transcription, and neither is needed in a browser.
85
+ `deny` records that in your `package.json`'s `allowScripts`.
86
+ - That field replaces any `allow-scripts` setting in your `~/.npmrc`.
87
+ If your `~/.npmrc` approves `fsevents` (Vite's file watcher on macOS), approve it again here: `npm install-scripts approve fsevents --no-allow-scripts-pin`.
88
+ In a new project that fails with `ENOMATCH`, because the first `npm install` doesn't put `fsevents` in `node_modules`.
89
+ Run `npm install` again (it warns that `fsevents` isn't approved), then approve it.
90
+ - **Expect a big `package-lock.json`.** The library's dependencies are installed in your project, including some that only Node.js uses.
91
+
92
+ ### Working on the library at the same time
93
+
94
+ ```bash
95
+ npm link ../canvas-recorder-lib # in your project
96
+ npm run watch # in canvas-recorder-lib
97
+ ```
98
+
99
+ - `npm link` replaces `node_modules/canvas-recorder-lib` with a symlink to your copy, without touching `package.json` or `package-lock.json`.
100
+ So your deploy keeps using the published version.
101
+ - `npm ls canvas-recorder-lib` shows `-> ./../canvas-recorder-lib` while the link is active.
102
+ - Any later `npm install` or `npm ci` quietly puts the published copy back.
103
+ - Your project uses the library's compiled `dist/`, so keep `npm run watch` running in the library.
104
+ - When the library change is ready, publish a new version, then `npm install canvas-recorder-lib@<version>` in your project and commit both package files.
105
+
40
106
  ### Vite setup
41
107
 
42
- While both projects are on your disk, link the library with `"canvas-recorder-lib": "file:../canvas-recorder-lib"` in package.json.
43
- Then add this to your `vite.config.js`:
108
+ Add this to your `vite.config.js`:
44
109
 
45
110
  ```js
46
111
  import { defineConfig, searchForWorkspaceRoot } from "vite";
47
112
 
48
113
  export default defineConfig({
114
+ base: "./",
115
+ resolve: {
116
+ dedupe: ["phil-lib"],
117
+ },
49
118
  server: {
50
119
  port: 5174, // Pick one per project, and keep it.
51
120
  strictPort: true,
@@ -53,16 +122,28 @@ export default defineConfig({
53
122
  allow: [searchForWorkspaceRoot(process.cwd()), "../canvas-recorder-lib"],
54
123
  },
55
124
  },
125
+ optimizeDeps: {
126
+ include: ["canvas-recorder-lib > @huggingface/transformers"],
127
+ },
128
+ build: {
129
+ rolldownOptions: { output: { keepNames: true } }, // Vite 8. Vite 7: rollupOptions.
130
+ },
56
131
  });
57
132
  ```
58
133
 
59
- - **`fs.allow`:** without it, the server console says the transcription worker is "outside of Vite serving allow list", and transcripts fail.
134
+ - **`base: "./"`:** relative paths, so the build works on GitHub Pages, or in any subdirectory.
135
+ - **`dedupe`:** one copy of phil-lib. With the library linked, Vite would otherwise load two: yours, and the one in the library's `node_modules`.
136
+ - **`fs.allow`:** needed while the library is linked.
137
+ Without it, the server console says the transcription worker is "outside of Vite serving allow list", and transcripts fail.
60
138
  A linked library lives outside your project. Vite serves files that are imported, but the worker is loaded by URL.
61
139
  Setting `allow` turns off Vite's default, so your own folder has to be listed too; that's what `searchForWorkspaceRoot()` is for.
140
+ - **`optimizeDeps.include`:** without it, the first Import audio or transcript reloads the page, under `npm run dev` only.
141
+ Only the transcription worker imports that package, and Vite doesn't look inside workers when it starts, so it finds the package late and reloads to use it.
142
+ - **`keepNames`:** the Visual Editor writes TypeScript that names each component's class (Sync diffs, and `properties/*.txt`).
143
+ In a minified production build, like your GitHub Pages copy, those names come out as `hi` and `Nr` without it.
62
144
  - **A fixed port:** the editor saves your work in the browser (IndexedDB), and the browser keeps a separate copy for each origin.
63
145
  If another project already has the port, Vite quietly moves to the next one (5173 → 5174), and the editor seems to forget everything.
64
146
  `strictPort` makes that an error instead.
65
- - **`npm run watch`:** your project uses the library's compiled `dist/`, so keep this running in the library while you change it.
66
147
 
67
148
  ### Ports
68
149
 
@@ -70,12 +151,14 @@ Each project that uses this library gets its own port, forever.
70
151
  Changing the port loses the editor's saved work, because IndexedDB belongs to the origin, and the port is part of the origin.
71
152
  For a new project, take the next number and add it here.
72
153
 
73
- | Port | Project |
74
- | --- | --- |
75
- | 5173 | [canvas-recorder](https://github.com/TradeIdeasPhilip/canvas-recorder) (Vite's default; historical) |
76
- | 5174 | [riemann-surfaces-3d](https://github.com/TradeIdeasPhilip/riemann-surfaces-3d) |
77
- | 5175 | [affine-transforms](https://github.com/TradeIdeasPhilip/affine-transforms) |
78
- | 5176 | `test-project/` in this repo (planned; see [development-plans/test-project.md](development-plans/test-project.md)) |
154
+ | Port | Project |
155
+ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
156
+ | 5173 | [canvas-recorder](https://github.com/TradeIdeasPhilip/canvas-recorder) (Vite's default; historical) |
157
+ | 5174 | [riemann-surfaces-3d](https://github.com/TradeIdeasPhilip/riemann-surfaces-3d) |
158
+ | 5175 | [affine-transforms](https://github.com/TradeIdeasPhilip/affine-transforms) |
159
+ | 5176 | [`test-project/`](https://github.com/TradeIdeasPhilip/canvas-recorder-lib/tree/master/test-project) in this repo: the showcase, tests and tools |
160
+ | 5177 | [`simple-video-editor/`](https://github.com/TradeIdeasPhilip/canvas-recorder-lib/tree/master/simple-video-editor) in this repo |
161
+ | 5178 | 7-pointed-star |
79
162
 
80
163
  ### Starting the editor
81
164
 
@@ -86,12 +169,26 @@ For a new project, take the next number and add it here.
86
169
  Disabling every sheet that has more than `@font-face` rules works (see `hideOurStyles()` in riemann-surfaces-3d's `src/video-editor.ts`).
87
170
  - **Stop your own animation loop and keyboard handlers.** Otherwise typing in the Visual Editor's text boxes drives your program.
88
171
  - **Put sound files in your `public/` folder** and refer to them as `"./name.m4a"`.
172
+ - **Or use files on your computer.** The Video File and Image File panels have **📂 Open file…**, which stores a URL like `local:Screen Recording.mov`.
173
+ The browser remembers the file, but only in this browser on this computer.
174
+ After a reload it may want your OK again: click **🔓 Allow local files**.
175
+ The Save dialog checks every local file before it starts, so a long recording can't stop halfway to ask.
176
+ In your own code, read media with `fetchMedia()`, which understands `local:` URLs.
89
177
  - **Save the editor's state into your project, so it's in git.** The editor always saves inside the browser (IndexedDB), which git can't see.
90
178
  Make a `properties/` folder, and point **💾 Save As**, the **Save defaults** checkbox, and **Save Diffs** at it.
91
179
  The browser remembers each choice, so after the first time they keep saving there.
92
180
  Add a `properties/README.md` explaining the three files; copy [riemann-surfaces-3d's](https://github.com/TradeIdeasPhilip/riemann-surfaces-3d/blob/master/properties/README.md).
93
181
  - **Register your own components** with `componentRegistry.set(key, { create })`.
94
182
  Then the Visual Editor can add, save and load them, and "TypeScript defaults" can rebuild them.
183
+ - **A mistake in the Visual Editor is a state, not an error.** Your components should treat it that way:
184
+ - Show a warning, in the editor or on the canvas. Never throw, and never a dialog box.
185
+ - Save it like any other state. Editing between two good states often passes through bad ones.
186
+ - Draw as much as still makes sense. Values in worse shape can come back from IndexedDB or a file, so fail gracefully and make them easy to fix.
187
+ - Throwing while saving a video is only for external failures, like an image or video that doesn't load.
188
+ - Assertions are still fine for the programmer's own mistakes, like a table of values checked when the program starts.
189
+ - **Name a replaceable child with `userEditableDescription`,** not the constructor's `description`, when your code adds one with `replaceableComponents.push()`.
190
+ When the editor loads saved changes, it rebuilds those children from the registry, so a `description` from your constructor comes back as the registry's default.
191
+ `userEditableDescription` is saved with the rest, and the diff file uses it to match each child with its TypeScript.
95
192
 
96
193
  ### Recording a program that has its own state
97
194
 
@@ -115,27 +212,36 @@ It is only downloaded if someone uses transcription.
115
212
 
116
213
  ## How this library is made
117
214
 
118
- canvas-recorder is the source of truth.
119
- `npm run import` copies the player, and everything it imports, from `../canvas-recorder` into `dev/` and `src/`, verbatim.
120
- The library's own code lives in `lib/`.
121
-
122
- To pick up newer code from canvas-recorder:
123
-
124
- 1. Make a branch from the previous "Verbatim import from canvas-recorder …" commit.
125
- 2. Run `npm run import`, and commit: "Verbatim import from canvas-recorder <hash>".
126
- 3. Merge that branch into master.
127
- The library's hand edits stay as they are, and history only grows, so a plain `git push` works.
128
- 4. `npm run build`, and bump the version in package.json.
129
-
130
- `imported-files.txt` lists what was copied, and from which commit.
215
+ The code came from [canvas-recorder](https://github.com/TradeIdeasPhilip/canvas-recorder), which is now historical.
216
+ Since 2026-10-14, this library is the master copy: new features and fixes start here.
217
+ `imported-files.txt` lists what was copied, and from which canvas-recorder commit.
131
218
 
132
219
  ## Build
133
220
 
134
221
  ```
135
222
  npm install
136
223
  npm run build # or: npm run watch
224
+ npm run clean # empty dist/
225
+ npm run docs # API docs, in docs/
137
226
  ```
138
227
 
139
228
  Output goes to `dist/`: `.js`, `.d.ts`, source maps, plus the CSS and JSON files the JavaScript imports.
140
229
 
141
- A project that depends on this library through `"canvas-recorder-lib": "file:../canvas-recorder-lib"` sees a change as soon as `npm run watch` recompiles it.
230
+ Every relative import names its file, like `from "./utility.ts"`, and `npm run build` stops if one doesn't.
231
+ tsc turns `.ts` into `.js` in `dist/`, which works everywhere; an import with no extension only works where a tool like Vite guesses it.
232
+
233
+ `build` and `watch` only add and overwrite files in `dist/`, so a project's running dev server never sees it empty.
234
+ A deleted or renamed source file leaves its old output behind until `npm run clean`.
235
+
236
+ A project that has linked this library (see [Working on the library at the same time](#working-on-the-library-at-the-same-time)) sees a change as soon as `npm run watch` recompiles it.
237
+
238
+ The Simple Video Editor is a separate npm project inside this repo. [simple-video-editor/README.md](simple-video-editor/README.md) says how to run it.
239
+
240
+ ## Releasing
241
+
242
+ 1. Bump the version. If [BREAKING-CHANGES.md](BREAKING-CHANGES.md) has an "Unreleased" section: `npm version minor --no-git-tag-version`, and replace "Unreleased" with the new version and the date.
243
+ Otherwise: `npm version patch --no-git-tag-version`. Commit and push.
244
+ 2. `npm publish`. `prepublishOnly` empties and rebuilds `dist/` first, so nothing stale is published.
245
+ 3. In each project: `npm install canvas-recorder-lib@<version>`, `npx tsc --noEmit`, and commit `package.json` and `package-lock.json`.
246
+
247
+ The API docs publish themselves on every push to master.
@@ -1,22 +1,20 @@
1
1
  /**
2
- * This creates a complete audio clip by joining multiple clips.
3
- * It starts with all silence and you can add the clips wherever you need them.
2
+ * The soundtrack mixed into one buffer, for the saved video and 🎤 Record Just Sound.
3
+ *
4
+ * Live playback doesn't use this: it gives each clip its own node, and the browser
5
+ * mixes them. See dev/soundtrack.ts.
4
6
  *
7
+ * It starts with all silence and you can add the clips wherever you need them.
5
8
  * Overlapping clips are mixed: each one is added to whatever is already
6
9
  * there, so two sounds at the same time are both heard.
7
10
  *
8
- * The result is always **mono**. Every source is mixed down to one channel as
9
- * it is added. Nothing recorded for these videos is really stereo: a Mac
10
- * screen recording, for example, writes its one microphone signal into both
11
- * channels, and CapCut's exports have done the same. One channel is less to
12
- * test and can't put a sound in only one ear by accident.
11
+ * The result is always **mono**, and so are the sources: dev/soundtrack.ts mixes
12
+ * each file down to one channel when it decodes it. Nothing recorded for these
13
+ * videos is really stereo: a Mac screen recording, for example, writes its one
14
+ * microphone signal into both channels, and CapCut's exports have done the same.
15
+ * One channel is less to test and can't put a sound in only one ear by accident.
13
16
  */
14
17
  export class AudioBuilder {
15
- /**
16
- * Like AudioContext, but this lets you process data at full speed.
17
- * AudioContext doesn't allow you to process things faster than realtime.
18
- */
19
- private audioContext: OfflineAudioContext;
20
18
  /**
21
19
  * This is the sound we are building.
22
20
  */
@@ -26,67 +24,18 @@ export class AudioBuilder {
26
24
  return this.buffer;
27
25
  }
28
26
 
29
- constructor(totalDurationMs: number) {
30
- const sampleRate = 48000;
31
- // OfflineAudioContext requires length >= 1 -- a project can legitimately
32
- // start out at duration 0 (e.g. an empty timeline before any clips have
33
- // been added yet), so clamp rather than let the constructor throw.
34
- this.audioContext = new OfflineAudioContext({
35
- length: Math.max(1, totalDurationMs * 1000),
36
- sampleRate,
37
- });
27
+ constructor(totalDurationMs: number, sampleRate = 48000) {
28
+ // A project can legitimately be 0 ms long (an empty timeline), and an
29
+ // AudioBuffer needs at least one sample.
38
30
  const totalSamples = Math.max(
39
31
  1,
40
32
  Math.ceil((totalDurationMs / 1000) * sampleRate),
41
33
  );
42
-
43
- this.buffer = this.audioContext.createBuffer(1, totalSamples, sampleRate);
44
- }
45
-
46
- async #createNewAudioBuffer(url: string) {
47
- const time1 = performance.now();
48
- const response = await fetch(url);
49
- const time2 = performance.now();
50
- const encodedSource = await response.arrayBuffer();
51
- const time3 = performance.now();
52
- // decodeAudioData() takes about ⅜ - ¾ of a second to decode 4 minutes and 18 seconds of audio.
53
- const sourceBuffer = await this.audioContext.decodeAudioData(encodedSource);
54
- const time4 = performance.now();
55
- const fileSizeKB = encodedSource.byteLength / 1024;
56
- false &&
57
- console.log(
58
- `[audio] fetch: ${(time2 - time1).toFixed(0)} ms (${fileSizeKB.toFixed(0)} KB, ` +
59
- `${((time2 - time1) / fileSizeKB).toFixed(3)} ms/KB) | ` +
60
- `arrayBuffer: ${(time3 - time2).toFixed(0)} ms | ` +
61
- `decode: ${(time4 - time3).toFixed(0)} ms`,
62
- );
63
- return sourceBuffer;
64
- }
65
-
66
- readonly #cache = new Map<string, Promise<AudioBuffer>>();
67
- readonly #resolved = new Map<string, AudioBuffer>();
68
-
69
- clearCache() {
70
- this.#cache.clear();
71
- this.#resolved.clear();
72
- }
73
-
74
- warmCache(url: string) {
75
- this.#findAudioBuffer(url);
76
- }
77
-
78
- /** Returns the decoded buffer synchronously if already cached, otherwise null. */
79
- getDecodedBuffer(url: string): AudioBuffer | null {
80
- return this.#resolved.get(url) ?? null;
81
- }
82
-
83
- #findAudioBuffer(url: string): Promise<AudioBuffer> {
84
- return this.#cache.getOrInsertComputed(url, (missingUrl) =>
85
- this.#createNewAudioBuffer(missingUrl).then((buf) => {
86
- this.#resolved.set(missingUrl, buf);
87
- return buf;
88
- }),
89
- );
34
+ this.buffer = new AudioBuffer({
35
+ numberOfChannels: 1,
36
+ length: totalSamples,
37
+ sampleRate,
38
+ });
90
39
  }
91
40
 
92
41
  /**
@@ -96,14 +45,7 @@ export class AudioBuilder {
96
45
  * The sum can go past ±1, which clips. That's fine for what this is used
97
46
  * for, a voiceover with the occasional overlap; the WAV encoder clamps, and
98
47
  * live playback clips the same way.
99
- * @param url Where to find the file.
100
- *
101
- * I typically use vite dev mode to run my project.
102
- * I put the files in the `/public` directory of the project.
103
- * And the url will start with "./".
104
- *
105
- * CORS can be an issue depending on the server.
106
- * Local files are forbidden.
48
+ * @param sourceBuffer The decoded sound, mono, at this builder's sample rate.
107
49
  * @param startMsInDestination 0 to play the new clip at the the beginning of the video.
108
50
  * 1000 to start this clip 1 second after the video starts.
109
51
  *
@@ -140,14 +82,13 @@ export class AudioBuilder {
140
82
  * whichever comes first.
141
83
  *
142
84
  * The default is `Infinity`, to copy the entire clip or as much as will fit.
143
- * @returns This promise will resolve (or reject) when the request is complete.
144
85
  */
145
- async add(
146
- url: string,
86
+ add(
87
+ sourceBuffer: AudioBuffer,
147
88
  startMsInDestination: number,
148
89
  trimFromStartMs: number = 0,
149
90
  length: number = Infinity,
150
- ): Promise<void> {
91
+ ): void {
151
92
  if (startMsInDestination < 0) {
152
93
  // Skip the part that would play before the video starts.
153
94
  trimFromStartMs -= startMsInDestination;
@@ -161,8 +102,6 @@ export class AudioBuilder {
161
102
  trimFromStartMs = 0;
162
103
  }
163
104
 
164
- const sourceBuffer = await this.#findAudioBuffer(url);
165
-
166
105
  const samplesPerMs = this.buffer.sampleRate / 1000;
167
106
  const destinationStart = Math.floor(startMsInDestination * samplesPerMs);
168
107
  const sourceStart = Math.floor(trimFromStartMs * samplesPerMs);
@@ -183,89 +122,58 @@ export class AudioBuilder {
183
122
  const destination = this.buffer
184
123
  .getChannelData(0)
185
124
  .subarray(destinationStart, destinationStart + count);
186
- const channels = Array.from(
187
- { length: sourceBuffer.numberOfChannels },
188
- (_, channel) =>
189
- sourceBuffer
190
- .getChannelData(channel)
191
- .subarray(sourceStart, sourceStart + count),
192
- );
193
- if (channels.length === 1) {
194
- // The common case.
195
- const source = channels[0];
196
- for (let i = 0; i < count; i++) {
197
- destination[i] += source[i];
198
- }
199
- } else {
200
- // Average the channels, don't sum them: identical channels (the usual
201
- // "stereo") come out exactly as they went in, where a sum would double
202
- // the level and clip.
203
- const scale = 1 / channels.length;
204
- for (let i = 0; i < count; i++) {
205
- let sum = 0;
206
- for (const channel of channels) {
207
- sum += channel[i];
208
- }
209
- destination[i] += sum * scale;
210
- }
125
+ const source = sourceBuffer
126
+ .getChannelData(0)
127
+ .subarray(sourceStart, sourceStart + count);
128
+ for (let i = 0; i < count; i++) {
129
+ destination[i] += source[i];
211
130
  }
212
131
  }
213
132
 
214
- async toBlob(): Promise<Blob> {
215
- const wavArrayBuffer = this.audioBufferToWav(this.buffer);
216
- return new Blob([wavArrayBuffer], { type: "audio/wav" });
217
- }
218
-
219
- async assignToAudioElement(audioElement: HTMLAudioElement): Promise<void> {
220
- const blob = await this.toBlob();
221
- audioElement.src = URL.createObjectURL(blob);
222
- // Optional: audioElement.load();
133
+ toBlob(): Blob {
134
+ return new Blob([audioBufferToWav(this.buffer)], { type: "audio/wav" });
223
135
  }
136
+ }
224
137
 
225
- // Simple 16-bit PCM WAV encoder
226
- // This takes about 0.6 seconds to save 8½ minutes of data.
227
- private audioBufferToWav(buffer: AudioBuffer): ArrayBuffer {
228
- console.log("audioBufferToWav()");
229
- const numChannels = buffer.numberOfChannels;
230
- const sampleRate = buffer.sampleRate;
231
- const length = buffer.length * numChannels * 2 + 44;
232
- const arrayBuffer = new ArrayBuffer(length);
233
- const view = new DataView(arrayBuffer);
234
-
235
- const writeString = (offset: number, str: string) => {
236
- for (let i = 0; i < str.length; i++)
237
- view.setUint8(offset + i, str.charCodeAt(i));
238
- };
239
-
240
- writeString(0, "RIFF");
241
- view.setUint32(4, 36 + buffer.length * numChannels * 2, true);
242
- writeString(8, "WAVE");
243
- writeString(12, "fmt ");
244
- view.setUint32(16, 16, true);
245
- view.setUint16(20, 1, true);
246
- view.setUint16(22, numChannels, true);
247
- view.setUint32(24, sampleRate, true);
248
- view.setUint32(28, sampleRate * numChannels * 2, true);
249
- view.setUint16(32, numChannels * 2, true);
250
- view.setUint16(34, 16, true);
251
- writeString(36, "data");
252
- view.setUint32(40, buffer.length * numChannels * 2, true);
253
-
254
- let offset = 44;
255
- for (let ch = 0; ch < numChannels; ch++) {
256
- console.log("Wuz lots!");
257
- const channel = buffer.getChannelData(ch);
258
- for (let i = 0; i < buffer.length; i++) {
259
- const sample = Math.max(-1, Math.min(1, channel[i]));
260
- view.setInt16(
261
- offset,
262
- sample < 0 ? sample * 0x8000 : sample * 0x7fff,
263
- true,
264
- );
265
- offset += 2;
266
- }
138
+ /**
139
+ * Simple 16-bit PCM WAV encoder.
140
+ * This takes about 0.6 seconds to save 8½ minutes of data.
141
+ */
142
+ function audioBufferToWav(buffer: AudioBuffer): ArrayBuffer {
143
+ const numChannels = buffer.numberOfChannels;
144
+ const sampleRate = buffer.sampleRate;
145
+ const length = buffer.length * numChannels * 2 + 44;
146
+ const arrayBuffer = new ArrayBuffer(length);
147
+ const view = new DataView(arrayBuffer);
148
+
149
+ const writeString = (offset: number, str: string) => {
150
+ for (let i = 0; i < str.length; i++)
151
+ view.setUint8(offset + i, str.charCodeAt(i));
152
+ };
153
+
154
+ writeString(0, "RIFF");
155
+ view.setUint32(4, 36 + buffer.length * numChannels * 2, true);
156
+ writeString(8, "WAVE");
157
+ writeString(12, "fmt ");
158
+ view.setUint32(16, 16, true);
159
+ view.setUint16(20, 1, true);
160
+ view.setUint16(22, numChannels, true);
161
+ view.setUint32(24, sampleRate, true);
162
+ view.setUint32(28, sampleRate * numChannels * 2, true);
163
+ view.setUint16(32, numChannels * 2, true);
164
+ view.setUint16(34, 16, true);
165
+ writeString(36, "data");
166
+ view.setUint32(40, buffer.length * numChannels * 2, true);
167
+
168
+ let offset = 44;
169
+ for (let ch = 0; ch < numChannels; ch++) {
170
+ const channel = buffer.getChannelData(ch);
171
+ for (let i = 0; i < buffer.length; i++) {
172
+ const sample = Math.max(-1, Math.min(1, channel[i]));
173
+ view.setInt16(offset, sample < 0 ? sample * 0x8000 : sample * 0x7fff, true);
174
+ offset += 2;
267
175
  }
268
-
269
- return arrayBuffer;
270
176
  }
177
+
178
+ return arrayBuffer;
271
179
  }
@@ -367,3 +367,62 @@ body {
367
367
  outline: 2px solid #4a90d9;
368
368
  outline-offset: -2px;
369
369
  }
370
+
371
+ /* ── Multi Text editor ───────────────────────────────────────────────── */
372
+
373
+ /* The FormatEditor in dev/format-editor.ts: plain text with a menu ("chip")
374
+ in front of each run of text, naming its Text Format. From
375
+ format-editor-prototype's style.css. */
376
+ .format-editor {
377
+ min-height: 6rem;
378
+ padding: 0.5rem 0.75rem;
379
+ border: 1px solid #c7c7cc;
380
+ border-radius: 6px;
381
+ background: white;
382
+ /* Newlines are stored as plain "\n" characters, not <br> or <div>. */
383
+ white-space: pre-wrap;
384
+ overflow-wrap: anywhere;
385
+ line-height: 1.9;
386
+ font-size: 1.05rem;
387
+ }
388
+
389
+ .format-editor:focus-within {
390
+ outline: 2px solid #0a66d8;
391
+ outline-offset: 1px;
392
+ }
393
+
394
+ .format-chip {
395
+ display: inline-block;
396
+ margin: 0 1px;
397
+ vertical-align: baseline;
398
+ }
399
+
400
+ .format-chip select {
401
+ font: inherit;
402
+ font-size: 0.8rem;
403
+ line-height: 1.2;
404
+ padding: 0 0.15rem;
405
+ color: #1d1d1f;
406
+ background: #e3edfb;
407
+ border: 1px solid #9dbbe6;
408
+ border-radius: 4px;
409
+ cursor: pointer;
410
+ }
411
+
412
+ /* A name that isn't one of the formats this text can see. */
413
+ .format-chip.invalid select {
414
+ color: #d70015;
415
+ background: #fde8ea;
416
+ border-color: #d70015;
417
+ font-weight: 600;
418
+ }
419
+
420
+ /* In the open menu, all options except the unknown one use the normal color. */
421
+ .format-chip.invalid select option {
422
+ color: #1d1d1f;
423
+ font-weight: normal;
424
+ }
425
+
426
+ .format-chip select option.invalid {
427
+ color: #d70015;
428
+ }