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,255 @@
1
+ import { makeLinear } from "phil-lib/misc";
2
+ import { Font } from "./glib/letters-base.ts";
3
+ import { ParagraphLayout, WordInPlace } from "./glib/paragraph-layout.ts";
4
+ import { Command, PathShape } from "./glib/path-shape.ts";
5
+ import { ShowOptions } from "./showable.ts";
6
+ import { strokeColors, StrokeColorsOptions } from "./stroke-colors.ts";
7
+ import { PathShapeSplitter } from "./glib/path-shape-splitter.ts";
8
+
9
+ type CommonSettings = Partial<
10
+ Pick<
11
+ CanvasRenderingContext2D,
12
+ "fillStyle" | "strokeStyle" | "lineCap" | "lineJoin" | "lineWidth"
13
+ >
14
+ >;
15
+ /**
16
+ * A PathShape and some common settings for that PathShape.
17
+ * Fully mutable.
18
+ *
19
+ */
20
+ export class PathElement {
21
+ /**
22
+ *
23
+ * @param pathShape The shape you want to `stroke()` or `fill()`.
24
+ * Explicitly **not** readonly.
25
+ * @param commonSettings These are the settings that are used a lot.
26
+ * By convention you don't have to save the value of any of these.
27
+ *
28
+ * `undefined` means that this object has no opinion on that property.
29
+ * We will rely on the caller to make sure there is some meaningful value in there.
30
+ *
31
+ * Explicitly **not** readonly.
32
+ */
33
+ constructor(
34
+ public commonSettings: CommonSettings = {},
35
+ public pathShape: PathShape = PathShape.EMPTY,
36
+ public tag?: unknown,
37
+ ) {}
38
+ setTag(newTag: unknown) {
39
+ this.tag = newTag;
40
+ return this;
41
+ }
42
+ setLineWidth(lineWidth: number | undefined) {
43
+ this.commonSettings.lineWidth = lineWidth;
44
+ return this;
45
+ }
46
+ /**
47
+ * Copy settings from `requested` into `context`.
48
+ * @param requested New settings to use.
49
+ * @param context Where to put the settings.
50
+ */
51
+ static applySettings(
52
+ requested: CommonSettings,
53
+ context: CanvasRenderingContext2D,
54
+ ) {
55
+ if (requested.fillStyle !== undefined) {
56
+ context.fillStyle = requested.fillStyle;
57
+ }
58
+ if (requested.strokeStyle !== undefined) {
59
+ context.strokeStyle = requested.strokeStyle;
60
+ }
61
+ if (requested.lineCap !== undefined) {
62
+ context.lineCap = requested.lineCap;
63
+ }
64
+ if (requested.lineJoin !== undefined) {
65
+ context.lineJoin = requested.lineJoin;
66
+ }
67
+ if (requested.lineWidth !== undefined) {
68
+ context.lineWidth = requested.lineWidth;
69
+ }
70
+ }
71
+ /**
72
+ * Copy settings from `this.requested` into `context`.
73
+ * @param context Where to put the settings.
74
+ */
75
+ applySettings(context: CanvasRenderingContext2D) {
76
+ PathElement.applySettings(this.commonSettings, context);
77
+ }
78
+ stroke(context: CanvasRenderingContext2D) {
79
+ this.applySettings(context);
80
+ this.pathShape.setCanvasPath(context);
81
+ context.stroke();
82
+ }
83
+ fill(context: CanvasRenderingContext2D) {
84
+ this.applySettings(context);
85
+ this.pathShape.setCanvasPath(context);
86
+ context.fill();
87
+ }
88
+ show(showOptions: ShowOptions) {
89
+ this.stroke(showOptions.context);
90
+ }
91
+ static combine(pathElements: readonly (PathElement | PathShape)[]) {
92
+ return new PathShape(
93
+ pathElements.flatMap((element) => {
94
+ const pathShape =
95
+ element instanceof PathShape ? element : element.pathShape;
96
+ return pathShape.commands;
97
+ }),
98
+ );
99
+ }
100
+ static handwriting(
101
+ pathElements: PathElement[],
102
+ startMs: number,
103
+ endMs: number,
104
+ ) {
105
+ let start = 0;
106
+ const items = pathElements.map((pathElement) => {
107
+ const fullShape = pathElement.pathShape;
108
+ const splitter = PathShapeSplitter.create(fullShape);
109
+ const length = splitter.length;
110
+ const item = { fullShape, splitter, length, pathElement, start };
111
+ start += length;
112
+ return item;
113
+ });
114
+ const getDistance = makeLinear(startMs, 0, endMs, start);
115
+ function drawHandwriting(showOptions: ShowOptions) {
116
+ const distance = getDistance(showOptions.timeInMs);
117
+ items.forEach((item) => {
118
+ const relativeDistance = distance - item.start;
119
+ if (relativeDistance > 0) {
120
+ item.pathElement.pathShape = item.splitter.trim(0, relativeDistance);
121
+ item.pathElement.show(showOptions);
122
+ }
123
+ });
124
+ }
125
+ return drawHandwriting;
126
+ }
127
+ }
128
+
129
+ type MultiColorConfig = Omit<StrokeColorsOptions, "pathShape" | "context">;
130
+
131
+ export class MultiColorPathElement extends PathElement {
132
+ constructor(
133
+ commonSettings: CommonSettings = {},
134
+ public multiColorConfig: MultiColorConfig = {},
135
+ pathShape: PathShape = PathShape.EMPTY,
136
+ ) {
137
+ super(commonSettings, pathShape);
138
+ }
139
+ animator(showOptions: ShowOptions) {}
140
+ override show(showOptions: ShowOptions): void {
141
+ this.animator(showOptions);
142
+ this.applySettings(showOptions.context);
143
+ strokeColors({
144
+ ...this.multiColorConfig,
145
+ context: showOptions.context,
146
+ pathShape: this.pathShape,
147
+ });
148
+ }
149
+ /**
150
+ * In userspace units / millisecond.
151
+ *
152
+ * Multiply this by `globalTime` to get the current `offset`.
153
+ * @param offsetRatio
154
+ */
155
+ animateOffset(offsetRatio: number) {
156
+ this.animator = (showOptions: ShowOptions) => {
157
+ this.multiColorConfig.offset = showOptions.globalTime * offsetRatio;
158
+ };
159
+ return this;
160
+ }
161
+ /**
162
+ * In cycles / millisecond.
163
+ *
164
+ * Multiply this by `globalTime` to get the current `relativeOffset`.
165
+ * @param offsetRatio
166
+ */
167
+ animateRelativeOffset(offsetRatio: number) {
168
+ this.animator = (showOptions: ShowOptions) => {
169
+ this.multiColorConfig.relativeOffset =
170
+ showOptions.globalTime * offsetRatio;
171
+ };
172
+ return this;
173
+ }
174
+ }
175
+
176
+ export class FullFormatter {
177
+ #paragraphLayout: ParagraphLayout;
178
+ #inProgress: {
179
+ pathElement: PathElement;
180
+ commands: Command[];
181
+ words: Set<WordInPlace>;
182
+ }[] = [];
183
+ get font(): Font {
184
+ return this.#paragraphLayout.font;
185
+ }
186
+ constructor(font: Font) {
187
+ this.#paragraphLayout = new ParagraphLayout(font);
188
+ }
189
+ #recentlyAdded = new Array<PathElement>();
190
+ get recentlyAdded() {
191
+ const result = this.#recentlyAdded;
192
+ this.#recentlyAdded = [];
193
+ return result;
194
+ }
195
+ add(
196
+ text: string,
197
+ pathElement: PathElement | (() => PathElement) = new PathElement(),
198
+ font?: Font,
199
+ ) {
200
+ if (!(pathElement instanceof PathElement)) {
201
+ pathElement = pathElement();
202
+ }
203
+ this.#paragraphLayout.addText(text, font, this.#inProgress.length);
204
+ this.#inProgress.push({ pathElement, commands: [], words: new Set() });
205
+ this.#recentlyAdded.push(pathElement);
206
+ return this;
207
+ }
208
+ align(
209
+ options: {
210
+ width?: number;
211
+ alignment?: "left" | "center" | "right" | "justify";
212
+ additionalLineHeight?: number;
213
+ top?: number;
214
+ bottom?: number;
215
+ left?: number;
216
+ } = {},
217
+ ) {
218
+ if (options.top !== undefined && options.bottom !== undefined) {
219
+ throw new Error("At most one of top and bottom may be specified.");
220
+ }
221
+ const laidOut = this.#paragraphLayout.align(
222
+ options.width,
223
+ options.alignment,
224
+ options.additionalLineHeight,
225
+ );
226
+ if (options.top === undefined && options.bottom !== undefined) {
227
+ options.top = options.bottom - laidOut.height;
228
+ }
229
+ laidOut
230
+ .getAllLetters(options.left ?? 0, options.top ?? 0)
231
+ .forEach((letterInfo) => {
232
+ const info = this.#inProgress[letterInfo.word.wordInfo.tag as number];
233
+ info.commands.push(...letterInfo.translatedShape.commands);
234
+ info.words.add(letterInfo.word);
235
+ });
236
+ const pathElements = new Array<PathElement>();
237
+ const words = new Array<Set<WordInPlace>>();
238
+ this.#inProgress.map((inProgress) => {
239
+ const pathShape = new PathShape(inProgress.commands);
240
+ const pathElement = inProgress.pathElement;
241
+ pathElement.pathShape = pathShape;
242
+ pathElements.push(pathElement);
243
+ words.push(inProgress.words);
244
+ });
245
+ return {
246
+ pathElements,
247
+ words,
248
+ laidOut,
249
+ height: laidOut.height,
250
+ width: laidOut.width,
251
+ };
252
+ }
253
+ }
254
+
255
+ export type FancyLayout = ReturnType<FullFormatter["align"]>;
@@ -1,8 +1,9 @@
1
1
  import { assertClass, assertFinite, pickAny } from "phil-lib/misc";
2
- import { PathShape } from "./path-shape";
2
+ import { PathShape } from "./path-shape.ts";
3
3
 
4
- import futuraLBase from "./Futura L.json";
5
- import cursiveBase from "./Cursive.json";
4
+ // Node needs the "type", and Vite and browsers accept it.
5
+ import futuraLBase from "./Futura L.json" with { type: "json" };
6
+ import cursiveBase from "./Cursive.json" with { type: "json" };
6
7
 
7
8
  /**
8
9
  * This is an older idea.
@@ -6,7 +6,7 @@ import {
6
6
  pickAny,
7
7
  polarToRectangular,
8
8
  } from "phil-lib/misc";
9
- import { Font, FontMetrics } from "./letters-base";
9
+ import { Font, FontMetrics } from "./letters-base.ts";
10
10
  import {
11
11
  PathShape,
12
12
  PathBuilder,
@@ -14,7 +14,7 @@ import {
14
14
  QCommand,
15
15
  Command,
16
16
  Point,
17
- } from "./path-shape";
17
+ } from "./path-shape.ts";
18
18
  import { Line } from "bezier-js";
19
19
 
20
20
  const dEast = 0;
@@ -1,6 +1,6 @@
1
1
  import { sum } from "phil-lib/misc";
2
- import { DescriptionOfLetter, Font } from "./letters-base";
3
- import { Command, PathShape } from "./path-shape";
2
+ import { DescriptionOfLetter, Font } from "./letters-base.ts";
3
+ import { Command, PathShape } from "./path-shape.ts";
4
4
 
5
5
  class WordInfo {
6
6
  readonly top: number;
@@ -1,4 +1,4 @@
1
- import { Command, CommandSplitter, PathShape, Point } from "./path-shape";
1
+ import { Command, CommandSplitter, PathShape, Point } from "./path-shape.ts";
2
2
 
3
3
  /**
4
4
  * Used internally.
@@ -15,10 +15,10 @@ import {
15
15
  ReadOnlyRect,
16
16
  sum,
17
17
  } from "phil-lib/misc";
18
- import { panAndZoom, transform } from "./transforms";
18
+ import { panAndZoom, transform } from "./transforms.ts";
19
19
 
20
20
  import { Bezier, MinMax } from "bezier-js";
21
- import { mapEachPair, philDebug } from "../utility";
21
+ import { mapEachPair, philDebug } from "../utility.ts";
22
22
 
23
23
  const formatForSvg = new Intl.NumberFormat("en-US", {
24
24
  maximumSignificantDigits: 8,
@@ -5,9 +5,9 @@ import {
5
5
  ReadOnlyRect,
6
6
  RealSvgRect,
7
7
  } from "phil-lib/misc";
8
- import { LCommand, PathShape, Point, QCommand } from "./glib/path-shape";
9
- import { LatticeValue } from "./lattice";
10
- import { Showable } from "./showable";
8
+ import { LCommand, PathShape, Point, QCommand } from "./glib/path-shape.ts";
9
+ import { LatticeValue } from "./lattice.ts";
10
+ import { Showable } from "./showable.ts";
11
11
 
12
12
  /**
13
13
  * If the old code used element.animate(), this file will help build the new code.
package/src/lattice.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LinearFunction, makeLinear, ReadOnlyRect } from "phil-lib/misc";
2
- import { Point } from "./glib/path-shape";
2
+ import { Point } from "./glib/path-shape.ts";
3
3
 
4
4
  /**
5
5
  * A grid of cells covering a rectangular area.