canvas-recorder-lib 0.5.0 → 0.6.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 (317) hide show
  1. package/BREAKING-CHANGES.md +18 -0
  2. package/README.md +112 -20
  3. package/dev/audio-builder.ts +4 -2
  4. package/dev/canvas-recorder.css +59 -0
  5. package/dev/canvas-recorder.ts +679 -51
  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 +86 -6
  14. package/dev/rect-snap.ts +9 -9
  15. package/dev/slide-panel.ts +1 -1
  16. package/dev/split-dialog.ts +13 -2
  17. package/dev/static-image-panel.ts +35 -5
  18. package/dev/timeline-display.ts +50 -5
  19. package/dev/transcripts.ts +5 -3
  20. package/dev/video-clip-panel.ts +201 -15
  21. package/dist/dev/audio-builder.d.ts +1 -1
  22. package/dist/dev/audio-builder.d.ts.map +1 -1
  23. package/dist/dev/audio-builder.js +3 -2
  24. package/dist/dev/audio-builder.js.map +1 -1
  25. package/dist/dev/canvas-recorder.css +59 -0
  26. package/dist/dev/canvas-recorder.js +612 -50
  27. package/dist/dev/canvas-recorder.js.map +1 -1
  28. package/dist/dev/delay-files.js +1 -1
  29. package/dist/dev/delay-files.js.map +1 -1
  30. package/dist/dev/font-utils.d.ts.map +1 -1
  31. package/dist/dev/font-utils.js +9 -1
  32. package/dist/dev/font-utils.js.map +1 -1
  33. package/dist/dev/format-editor.d.ts +75 -0
  34. package/dist/dev/format-editor.d.ts.map +1 -0
  35. package/dist/dev/format-editor.js +642 -0
  36. package/dist/dev/format-editor.js.map +1 -0
  37. package/dist/dev/format-string.d.ts +62 -0
  38. package/dist/dev/format-string.d.ts.map +1 -0
  39. package/dist/dev/format-string.js +86 -0
  40. package/dist/dev/format-string.js.map +1 -0
  41. package/dist/dev/local-file-row.d.ts +22 -0
  42. package/dist/dev/local-file-row.d.ts.map +1 -0
  43. package/dist/dev/local-file-row.js +84 -0
  44. package/dist/dev/local-file-row.js.map +1 -0
  45. package/dist/dev/multi-text-dialog.d.ts +30 -0
  46. package/dist/dev/multi-text-dialog.d.ts.map +1 -0
  47. package/dist/dev/multi-text-dialog.js +297 -0
  48. package/dist/dev/multi-text-dialog.js.map +1 -0
  49. package/dist/dev/multi-text-panel.d.ts +2 -0
  50. package/dist/dev/multi-text-panel.d.ts.map +1 -1
  51. package/dist/dev/multi-text-panel.js +4 -0
  52. package/dist/dev/multi-text-panel.js.map +1 -1
  53. package/dist/dev/player-body.d.ts +1 -1
  54. package/dist/dev/player-body.d.ts.map +1 -1
  55. package/dist/dev/player-body.js +86 -6
  56. package/dist/dev/player-body.js.map +1 -1
  57. package/dist/dev/rect-snap.d.ts +1 -1
  58. package/dist/dev/rect-snap.js +7 -7
  59. package/dist/dev/rect-snap.js.map +1 -1
  60. package/dist/dev/slide-panel.d.ts +1 -1
  61. package/dist/dev/slide-panel.d.ts.map +1 -1
  62. package/dist/dev/slide-panel.js +1 -1
  63. package/dist/dev/slide-panel.js.map +1 -1
  64. package/dist/dev/split-dialog.d.ts.map +1 -1
  65. package/dist/dev/split-dialog.js +14 -2
  66. package/dist/dev/split-dialog.js.map +1 -1
  67. package/dist/dev/static-image-panel.d.ts +2 -0
  68. package/dist/dev/static-image-panel.d.ts.map +1 -1
  69. package/dist/dev/static-image-panel.js +29 -5
  70. package/dist/dev/static-image-panel.js.map +1 -1
  71. package/dist/dev/timeline-display.d.ts +23 -2
  72. package/dist/dev/timeline-display.d.ts.map +1 -1
  73. package/dist/dev/timeline-display.js +47 -5
  74. package/dist/dev/timeline-display.js.map +1 -1
  75. package/dist/dev/transcripts.d.ts.map +1 -1
  76. package/dist/dev/transcripts.js +5 -3
  77. package/dist/dev/transcripts.js.map +1 -1
  78. package/dist/dev/video-clip-panel.d.ts +8 -0
  79. package/dist/dev/video-clip-panel.d.ts.map +1 -1
  80. package/dist/dev/video-clip-panel.js +175 -9
  81. package/dist/dev/video-clip-panel.js.map +1 -1
  82. package/dist/lib/index.d.ts +3 -0
  83. package/dist/lib/index.d.ts.map +1 -1
  84. package/dist/lib/index.js +3 -0
  85. package/dist/lib/index.js.map +1 -1
  86. package/dist/lib/main-control.d.ts +50 -4
  87. package/dist/lib/main-control.d.ts.map +1 -1
  88. package/dist/lib/main-control.js +94 -12
  89. package/dist/lib/main-control.js.map +1 -1
  90. package/dist/src/binary-search.js +1 -1
  91. package/dist/src/binary-search.js.map +1 -1
  92. package/dist/src/corner-rounder.d.ts +17 -0
  93. package/dist/src/corner-rounder.d.ts.map +1 -0
  94. package/dist/src/corner-rounder.js +89 -0
  95. package/dist/src/corner-rounder.js.map +1 -0
  96. package/dist/src/cross-fade.d.ts +1 -1
  97. package/dist/src/cross-fade.d.ts.map +1 -1
  98. package/dist/src/cross-fade.js +3 -3
  99. package/dist/src/cross-fade.js.map +1 -1
  100. package/dist/src/fancy-text.d.ts +116 -0
  101. package/dist/src/fancy-text.d.ts.map +1 -0
  102. package/dist/src/fancy-text.js +211 -0
  103. package/dist/src/fancy-text.js.map +1 -0
  104. package/dist/src/glib/letters-base.d.ts +1 -1
  105. package/dist/src/glib/letters-base.d.ts.map +1 -1
  106. package/dist/src/glib/letters-base.js +4 -3
  107. package/dist/src/glib/letters-base.js.map +1 -1
  108. package/dist/src/glib/line-font.d.ts +2 -2
  109. package/dist/src/glib/line-font.d.ts.map +1 -1
  110. package/dist/src/glib/line-font.js +2 -2
  111. package/dist/src/glib/line-font.js.map +1 -1
  112. package/dist/src/glib/paragraph-layout.d.ts +2 -2
  113. package/dist/src/glib/paragraph-layout.d.ts.map +1 -1
  114. package/dist/src/glib/paragraph-layout.js +1 -1
  115. package/dist/src/glib/paragraph-layout.js.map +1 -1
  116. package/dist/src/glib/path-shape-splitter.d.ts +1 -1
  117. package/dist/src/glib/path-shape-splitter.d.ts.map +1 -1
  118. package/dist/src/glib/path-shape-splitter.js +1 -1
  119. package/dist/src/glib/path-shape-splitter.js.map +1 -1
  120. package/dist/src/glib/path-shape.js +2 -2
  121. package/dist/src/glib/path-shape.js.map +1 -1
  122. package/dist/src/interpolate.d.ts +2 -2
  123. package/dist/src/interpolate.d.ts.map +1 -1
  124. package/dist/src/interpolate.js +1 -1
  125. package/dist/src/interpolate.js.map +1 -1
  126. package/dist/src/lattice.d.ts +1 -1
  127. package/dist/src/lattice.d.ts.map +1 -1
  128. package/dist/src/local-files.d.ts +129 -0
  129. package/dist/src/local-files.d.ts.map +1 -0
  130. package/dist/src/local-files.js +327 -0
  131. package/dist/src/local-files.js.map +1 -0
  132. package/dist/src/morph-animation.d.ts +1 -1
  133. package/dist/src/morph-animation.d.ts.map +1 -1
  134. package/dist/src/morph-animation.js +2 -2
  135. package/dist/src/morph-animation.js.map +1 -1
  136. package/dist/src/peano-fourier/fourier-shared.d.ts +1 -1
  137. package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
  138. package/dist/src/peano-fourier/fourier-shared.js +17 -4
  139. package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
  140. package/dist/src/schedule-helper.d.ts +4 -4
  141. package/dist/src/schedule-helper.d.ts.map +1 -1
  142. package/dist/src/schedule-helper.js +2 -2
  143. package/dist/src/schedule-helper.js.map +1 -1
  144. package/dist/src/showable.d.ts +36 -4
  145. package/dist/src/showable.d.ts.map +1 -1
  146. package/dist/src/showable.js +37 -1
  147. package/dist/src/showable.js.map +1 -1
  148. package/dist/src/slide-components/arrow.d.ts +4 -4
  149. package/dist/src/slide-components/arrow.d.ts.map +1 -1
  150. package/dist/src/slide-components/arrow.js +2 -2
  151. package/dist/src/slide-components/arrow.js.map +1 -1
  152. package/dist/src/slide-components/cross-fade-transition.d.ts +3 -3
  153. package/dist/src/slide-components/cross-fade-transition.d.ts.map +1 -1
  154. package/dist/src/slide-components/cross-fade-transition.js +3 -3
  155. package/dist/src/slide-components/cross-fade-transition.js.map +1 -1
  156. package/dist/src/slide-components/duration-agnostic.d.ts +3 -3
  157. package/dist/src/slide-components/duration-agnostic.d.ts.map +1 -1
  158. package/dist/src/slide-components/duration-agnostic.js +1 -1
  159. package/dist/src/slide-components/duration-agnostic.js.map +1 -1
  160. package/dist/src/slide-components/fixed-duration.d.ts +1 -1
  161. package/dist/src/slide-components/fixed-duration.d.ts.map +1 -1
  162. package/dist/src/slide-components/fixed-duration.js +1 -1
  163. package/dist/src/slide-components/fixed-duration.js.map +1 -1
  164. package/dist/src/slide-components/fourier.d.ts +6 -6
  165. package/dist/src/slide-components/fourier.d.ts.map +1 -1
  166. package/dist/src/slide-components/fourier.js +6 -6
  167. package/dist/src/slide-components/fourier.js.map +1 -1
  168. package/dist/src/slide-components/frame-counter.d.ts +2 -2
  169. package/dist/src/slide-components/frame-counter.d.ts.map +1 -1
  170. package/dist/src/slide-components/frame-counter.js +1 -1
  171. package/dist/src/slide-components/frame-counter.js.map +1 -1
  172. package/dist/src/slide-components/function-graph.d.ts +2 -2
  173. package/dist/src/slide-components/function-graph.d.ts.map +1 -1
  174. package/dist/src/slide-components/function-graph.js +3 -3
  175. package/dist/src/slide-components/function-graph.js.map +1 -1
  176. package/dist/src/slide-components/halftone-shadow.d.ts +4 -4
  177. package/dist/src/slide-components/halftone-shadow.d.ts.map +1 -1
  178. package/dist/src/slide-components/halftone-shadow.js +2 -2
  179. package/dist/src/slide-components/halftone-shadow.js.map +1 -1
  180. package/dist/src/slide-components/handwriting-effect.d.ts +5 -5
  181. package/dist/src/slide-components/handwriting-effect.d.ts.map +1 -1
  182. package/dist/src/slide-components/handwriting-effect.js +5 -5
  183. package/dist/src/slide-components/handwriting-effect.js.map +1 -1
  184. package/dist/src/slide-components/hold.d.ts +3 -3
  185. package/dist/src/slide-components/hold.d.ts.map +1 -1
  186. package/dist/src/slide-components/hold.js +3 -3
  187. package/dist/src/slide-components/hold.js.map +1 -1
  188. package/dist/src/slide-components/image.d.ts +3 -3
  189. package/dist/src/slide-components/image.d.ts.map +1 -1
  190. package/dist/src/slide-components/image.js +3 -3
  191. package/dist/src/slide-components/image.js.map +1 -1
  192. package/dist/src/slide-components/in-parallel.d.ts +3 -3
  193. package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
  194. package/dist/src/slide-components/in-parallel.js +2 -2
  195. package/dist/src/slide-components/in-parallel.js.map +1 -1
  196. package/dist/src/slide-components/in-series.d.ts +4 -4
  197. package/dist/src/slide-components/in-series.d.ts.map +1 -1
  198. package/dist/src/slide-components/in-series.js +5 -1
  199. package/dist/src/slide-components/in-series.js.map +1 -1
  200. package/dist/src/slide-components/live-duration.d.ts +1 -1
  201. package/dist/src/slide-components/live-duration.d.ts.map +1 -1
  202. package/dist/src/slide-components/live-duration.js +1 -1
  203. package/dist/src/slide-components/live-duration.js.map +1 -1
  204. package/dist/src/slide-components/multi-text.d.ts +76 -15
  205. package/dist/src/slide-components/multi-text.d.ts.map +1 -1
  206. package/dist/src/slide-components/multi-text.js +170 -25
  207. package/dist/src/slide-components/multi-text.js.map +1 -1
  208. package/dist/src/slide-components/rectangle.d.ts +3 -3
  209. package/dist/src/slide-components/rectangle.d.ts.map +1 -1
  210. package/dist/src/slide-components/rectangle.js +1 -1
  211. package/dist/src/slide-components/rectangle.js.map +1 -1
  212. package/dist/src/slide-components/registry.d.ts +1 -1
  213. package/dist/src/slide-components/registry.d.ts.map +1 -1
  214. package/dist/src/slide-components/registry.js +18 -18
  215. package/dist/src/slide-components/registry.js.map +1 -1
  216. package/dist/src/slide-components/serialize.d.ts +1 -1
  217. package/dist/src/slide-components/serialize.d.ts.map +1 -1
  218. package/dist/src/slide-components/serialize.js +2 -2
  219. package/dist/src/slide-components/serialize.js.map +1 -1
  220. package/dist/src/slide-components/show-error.js +2 -2
  221. package/dist/src/slide-components/show-error.js.map +1 -1
  222. package/dist/src/slide-components/simple-text.d.ts +4 -4
  223. package/dist/src/slide-components/simple-text.d.ts.map +1 -1
  224. package/dist/src/slide-components/simple-text.js +4 -4
  225. package/dist/src/slide-components/simple-text.js.map +1 -1
  226. package/dist/src/slide-components/slide-component.d.ts +5 -5
  227. package/dist/src/slide-components/slide-component.d.ts.map +1 -1
  228. package/dist/src/slide-components/slide-component.js +4 -4
  229. package/dist/src/slide-components/slide-component.js.map +1 -1
  230. package/dist/src/slide-components/slide-left.d.ts +3 -3
  231. package/dist/src/slide-components/slide-left.d.ts.map +1 -1
  232. package/dist/src/slide-components/slide-left.js +3 -3
  233. package/dist/src/slide-components/slide-left.js.map +1 -1
  234. package/dist/src/slide-components/split-video-clip.d.ts +2 -2
  235. package/dist/src/slide-components/split-video-clip.d.ts.map +1 -1
  236. package/dist/src/slide-components/split-video-clip.js +3 -3
  237. package/dist/src/slide-components/split-video-clip.js.map +1 -1
  238. package/dist/src/slide-components/text-effect.d.ts +2 -2
  239. package/dist/src/slide-components/text-effect.d.ts.map +1 -1
  240. package/dist/src/slide-components/traditional-text.d.ts +4 -4
  241. package/dist/src/slide-components/traditional-text.d.ts.map +1 -1
  242. package/dist/src/slide-components/traditional-text.js +3 -3
  243. package/dist/src/slide-components/traditional-text.js.map +1 -1
  244. package/dist/src/slide-components/video-clip.d.ts +17 -5
  245. package/dist/src/slide-components/video-clip.d.ts.map +1 -1
  246. package/dist/src/slide-components/video-clip.js +52 -11
  247. package/dist/src/slide-components/video-clip.js.map +1 -1
  248. package/dist/src/slide-components/video-info.d.ts +11 -11
  249. package/dist/src/slide-components/video-info.d.ts.map +1 -1
  250. package/dist/src/slide-components/video-info.js +32 -21
  251. package/dist/src/slide-components/video-info.js.map +1 -1
  252. package/dist/src/slow-image-sources.d.ts +7 -1
  253. package/dist/src/slow-image-sources.d.ts.map +1 -1
  254. package/dist/src/slow-image-sources.js +36 -5
  255. package/dist/src/slow-image-sources.js.map +1 -1
  256. package/dist/src/snapshot.d.ts +2 -2
  257. package/dist/src/snapshot.d.ts.map +1 -1
  258. package/dist/src/snapshot.js +4 -4
  259. package/dist/src/snapshot.js.map +1 -1
  260. package/dist/src/stroke-colors.d.ts +1 -1
  261. package/dist/src/stroke-colors.d.ts.map +1 -1
  262. package/dist/src/stroke-colors.js +4 -4
  263. package/dist/src/stroke-colors.js.map +1 -1
  264. package/dist/src/utility.d.ts +3 -4
  265. package/dist/src/utility.d.ts.map +1 -1
  266. package/dist/src/utility.js +4 -4
  267. package/dist/src/utility.js.map +1 -1
  268. package/lib/index.ts +3 -0
  269. package/lib/main-control.ts +119 -12
  270. package/package.json +7 -5
  271. package/src/binary-search.ts +2 -2
  272. package/src/corner-rounder.ts +128 -0
  273. package/src/cross-fade.ts +3 -3
  274. package/src/fancy-text.ts +255 -0
  275. package/src/glib/letters-base.ts +4 -3
  276. package/src/glib/line-font.ts +2 -2
  277. package/src/glib/paragraph-layout.ts +2 -2
  278. package/src/glib/path-shape-splitter.ts +1 -1
  279. package/src/glib/path-shape.ts +2 -2
  280. package/src/interpolate.ts +3 -3
  281. package/src/lattice.ts +1 -1
  282. package/src/local-files.ts +389 -0
  283. package/src/morph-animation.ts +2 -2
  284. package/src/peano-fourier/fourier-shared.ts +17 -4
  285. package/src/schedule-helper.ts +4 -4
  286. package/src/showable.ts +54 -4
  287. package/src/slide-components/arrow.ts +4 -4
  288. package/src/slide-components/cross-fade-transition.ts +4 -4
  289. package/src/slide-components/duration-agnostic.ts +3 -3
  290. package/src/slide-components/fixed-duration.ts +1 -1
  291. package/src/slide-components/fourier.ts +9 -9
  292. package/src/slide-components/frame-counter.ts +2 -2
  293. package/src/slide-components/function-graph.ts +4 -4
  294. package/src/slide-components/halftone-shadow.ts +4 -4
  295. package/src/slide-components/handwriting-effect.ts +7 -7
  296. package/src/slide-components/hold.ts +4 -4
  297. package/src/slide-components/image.ts +5 -5
  298. package/src/slide-components/in-parallel.ts +4 -4
  299. package/src/slide-components/in-series.ts +7 -4
  300. package/src/slide-components/live-duration.ts +1 -1
  301. package/src/slide-components/multi-text.ts +195 -30
  302. package/src/slide-components/rectangle.ts +3 -3
  303. package/src/slide-components/registry.ts +19 -19
  304. package/src/slide-components/serialize.ts +2 -2
  305. package/src/slide-components/show-error.ts +2 -2
  306. package/src/slide-components/simple-text.ts +7 -7
  307. package/src/slide-components/slide-component.ts +7 -7
  308. package/src/slide-components/slide-left.ts +4 -4
  309. package/src/slide-components/split-video-clip.ts +4 -4
  310. package/src/slide-components/text-effect.ts +2 -2
  311. package/src/slide-components/traditional-text.ts +5 -5
  312. package/src/slide-components/video-clip.ts +64 -13
  313. package/src/slide-components/video-info.ts +33 -21
  314. package/src/slow-image-sources.ts +38 -6
  315. package/src/snapshot.ts +4 -4
  316. package/src/stroke-colors.ts +4 -4
  317. package/src/utility.ts +5 -5
@@ -0,0 +1,110 @@
1
+ // MARK: Format String
2
+
3
+ /**
4
+ * The pure data model behind `FormatEditor` (format-editor.ts). No DOM in this file.
5
+ *
6
+ * Copied from https://github.com/TradeIdeasPhilip/format-editor-prototype, where the tests are.
7
+ * Its copy of `addText1()`'s parser was left behind: use `parseFormatString()` from
8
+ * src/slide-components/multi-text.ts, the real one.
9
+ *
10
+ * The external format is the one accepted by `MultiTextComponent.addText1()`:
11
+ * `"⸨format1⸩content1⸨format2⸩content2"`.
12
+ *
13
+ * Internally we use an array of {@link Unit}s. Each unit is exactly one caret
14
+ * position wide: one UTF-16 code unit of content, or one entire format marker.
15
+ * That makes "replace the selection with this" a simple `Array.splice()`, and it
16
+ * matches the way the DOM counts offsets inside a text node.
17
+ */
18
+
19
+ export const OPEN = "⸨";
20
+ export const CLOSE = "⸩";
21
+
22
+ /**
23
+ * One format marker, e.g. `⸨title⸩`.
24
+ *
25
+ * `name` can be anything that doesn't contain {@link OPEN} or {@link CLOSE}.
26
+ * Whether that name is one of the *known* formats is a separate question, answered by the editor.
27
+ */
28
+ export type FormatUnit = { readonly format: string };
29
+
30
+ /**
31
+ * Either a single UTF-16 code unit of content or a whole format marker.
32
+ */
33
+ export type Unit = string | FormatUnit;
34
+
35
+ export function isFormat(unit: Unit | undefined): unit is FormatUnit {
36
+ return typeof unit == "object";
37
+ }
38
+
39
+ /**
40
+ * Content may not contain the bracket characters.
41
+ * There is no escape mechanism in `addText1()`, so stray brackets can only be dropped.
42
+ */
43
+ const strayBrackets = /[⸨⸩]/g;
44
+
45
+ /**
46
+ * Remove anything that can't legally appear in content.
47
+ * Also normalize Windows and old Mac line endings.
48
+ */
49
+ export function cleanContent(text: string): string {
50
+ return text.replace(/\r\n?/g, "\n").replace(strayBrackets, "");
51
+ }
52
+
53
+ /**
54
+ * Append each code unit of `text` to `units`, after cleaning it.
55
+ * @returns `units`, for chaining.
56
+ */
57
+ export function pushContent(units: Unit[], text: string): Unit[] {
58
+ // split("") gives UTF-16 code units, which is what the DOM uses for offsets.
59
+ units.push(...cleanContent(text).split(""));
60
+ return units;
61
+ }
62
+
63
+ /**
64
+ * Convert a string, presumably from the clipboard, into units.
65
+ *
66
+ * Every complete `⸨…⸩` becomes a format.
67
+ * The name is kept exactly as is, even if it isn't a known format.
68
+ * Any unmatched `⸨` or `⸩` is silently dropped.
69
+ *
70
+ * Unlike `addText1()`, this does *not* require a leading format.
71
+ * You might be pasting into the middle of some existing text.
72
+ */
73
+ export function parse(text: string): Unit[] {
74
+ const result: Unit[] = [];
75
+ const formatMarker = /⸨([^⸨⸩]*)⸩/g;
76
+ let position = 0;
77
+ for (const match of text.matchAll(formatMarker)) {
78
+ pushContent(result, text.slice(position, match.index));
79
+ result.push({ format: match[1] });
80
+ position = match.index + match[0].length;
81
+ }
82
+ pushContent(result, text.slice(position));
83
+ return result;
84
+ }
85
+
86
+ /**
87
+ * The inverse of {@link parse}.
88
+ */
89
+ export function serialize(units: readonly Unit[]): string {
90
+ return units
91
+ .map((unit) => (isFormat(unit) ? OPEN + unit.format + CLOSE : unit))
92
+ .join("");
93
+ }
94
+
95
+ /**
96
+ * Walk backwards from `offset` to find the format that applies there.
97
+ * @returns The name of the format, or undefined if there is no format before `offset`.
98
+ */
99
+ export function formatInEffect(
100
+ units: readonly Unit[],
101
+ offset: number,
102
+ ): string | undefined {
103
+ for (let i = Math.min(offset, units.length) - 1; i >= 0; i--) {
104
+ const unit = units[i];
105
+ if (isFormat(unit)) {
106
+ return unit.format;
107
+ }
108
+ }
109
+ return undefined;
110
+ }
@@ -0,0 +1,107 @@
1
+ import {
2
+ isLocalFileUrl,
3
+ listLocalFiles,
4
+ onLocalFilesChange,
5
+ pickLocalFile,
6
+ } from "../src/local-files.ts";
7
+
8
+ /** What {@link buildLocalFileRow} needs to know. */
9
+ export type LocalFileRowOptions = {
10
+ /** Which files the picker offers, e.g. VIDEO_FILE_TYPES. */
11
+ readonly types: FilePickerAcceptType[];
12
+ /** The picker remembers a folder for each id, e.g. "video-clips". */
13
+ readonly pickerId: string;
14
+ /** Where the picker starts the first time. */
15
+ readonly startIn?: WellKnownDirectory;
16
+ /** The component's URL right now. */
17
+ readonly currentUrl: () => string;
18
+ /** The user chose a file. Store this URL in the component. */
19
+ readonly choose: (url: string) => void;
20
+ };
21
+
22
+ /**
23
+ * A row for a media panel: "📂 Open file…" and a list of the files this browser already
24
+ * knows about. Choosing either one gives the component a `local:` URL.
25
+ * See src/local-files.ts.
26
+ *
27
+ * Typing an http(s) or relative URL in the URL field still works as before.
28
+ */
29
+ export function buildLocalFileRow(options: LocalFileRowOptions): HTMLElement {
30
+ const row = document.createElement("div");
31
+ row.style.cssText = "margin-bottom:0.3em;display:flex;gap:0.3em;align-items:center;flex-wrap:wrap";
32
+
33
+ const pickButton = document.createElement("button");
34
+ pickButton.type = "button";
35
+ pickButton.textContent = "📂 Open file…";
36
+ pickButton.title =
37
+ "Use a file from this computer. The browser remembers it, so next time it's in the list.";
38
+ row.append(pickButton);
39
+
40
+ const recentSelect = document.createElement("select");
41
+ recentSelect.title = "Files this browser already knows about, newest first.";
42
+ recentSelect.style.maxWidth = "18em";
43
+ row.append(recentSelect);
44
+
45
+ const where = document.createElement("span");
46
+ where.style.cssText = "font-size:0.85em;color:#555";
47
+ row.append(where);
48
+
49
+ /** Bumped by every redraw, so an old, slow answer can't overwrite a newer one. */
50
+ let generation = 0;
51
+ async function redraw() {
52
+ const myGeneration = ++generation;
53
+ const url = options.currentUrl();
54
+ where.textContent = isLocalFileUrl(url) ? "On this computer" : url ? "On the web server" : "";
55
+ let files: Awaited<ReturnType<typeof listLocalFiles>>;
56
+ try {
57
+ files = await listLocalFiles();
58
+ } catch {
59
+ files = [];
60
+ }
61
+ if (myGeneration !== generation) return;
62
+ const placeholder = document.createElement("option");
63
+ placeholder.textContent = files.length ? "Recent files…" : "No recent files";
64
+ placeholder.value = "";
65
+ placeholder.disabled = true;
66
+ const choices = files.map((file) => {
67
+ const option = document.createElement("option");
68
+ option.value = file.url;
69
+ option.textContent = file.name;
70
+ return option;
71
+ });
72
+ recentSelect.replaceChildren(placeholder, ...choices);
73
+ recentSelect.value = isLocalFileUrl(url) && files.some((f) => f.url === url) ? url : "";
74
+ recentSelect.disabled = files.length === 0;
75
+ }
76
+
77
+ pickButton.addEventListener("click", async () => {
78
+ try {
79
+ const url = await pickLocalFile({
80
+ id: options.pickerId,
81
+ types: options.types,
82
+ startIn: options.startIn,
83
+ });
84
+ if (url) options.choose(url);
85
+ } catch (error) {
86
+ alert(`Couldn't open that file: ${error}`);
87
+ }
88
+ void redraw();
89
+ });
90
+
91
+ recentSelect.addEventListener("input", () => {
92
+ if (recentSelect.value) options.choose(recentSelect.value);
93
+ });
94
+
95
+ // Another panel may add a file to the list. Stop listening once this row is gone.
96
+ const stopListening = onLocalFilesChange(() => {
97
+ if (!row.isConnected) {
98
+ stopListening();
99
+ return;
100
+ }
101
+ void redraw();
102
+ });
103
+
104
+ void redraw();
105
+ return row;
106
+ }
107
+
@@ -0,0 +1,360 @@
1
+ import { Showable } from "../src/showable.ts";
2
+ import {
3
+ MultiTextComponent,
4
+ TextFormatComponent,
5
+ TextSpanComponent,
6
+ } from "../src/slide-components/multi-text.ts";
7
+ import { FormatEditor } from "./format-editor.ts";
8
+
9
+ /** What the dialog needs from the Visual Editor. It never reaches into canvas-recorder.ts directly. */
10
+ export type MultiTextDialogHooks = {
11
+ /**
12
+ * Save any unsaved changes now, so the History dialog has this text as it was before the
13
+ * dialog changed it.
14
+ */
15
+ readonly saveNow: () => Promise<void>;
16
+ /** The spans or the formats just changed. Mark the video as changed. */
17
+ readonly changed: () => void;
18
+ /** A copy of `component`, the way Copy and Paste make one, or undefined if it can't be copied. */
19
+ readonly copyComponent: (component: Showable) => Showable | undefined;
20
+ /** The dialog closed. Rebuild the editors it covered. */
21
+ readonly closed: () => void;
22
+ };
23
+
24
+ /** Someone animated this span, by hand or in TypeScript. Editing its text flattens it. */
25
+ function isAnimated(span: TextSpanComponent): boolean {
26
+ return span.schedules.some(
27
+ ({ schedule }) =>
28
+ schedule.length > 1 || schedule.some(({ time }) => time !== 0),
29
+ );
30
+ }
31
+
32
+ /**
33
+ * ✎ Edit Text…: a Multi Text's text, typed as one piece of text, with a menu in front of each
34
+ * part naming its Text Format. See development-plans/multi-text-editor.md.
35
+ *
36
+ * The dialog covers the right column, like the font picker, so the canvas stays in view, and
37
+ * the canvas follows every keystroke. The editor's value is a format string, the one
38
+ * `addText1()` reads, and every change goes to {@link MultiTextComponent.setSpans}, which
39
+ * reuses the Text Span children in order.
40
+ *
41
+ * Only the editable spans are here. Text from `addText1()` belongs to the program, and Text
42
+ * Spans added in TypeScript can't be removed, so the dialog just mentions them.
43
+ */
44
+ export async function openMultiTextDialog(
45
+ text: MultiTextComponent,
46
+ hooks: MultiTextDialogHooks,
47
+ ): Promise<void> {
48
+ // Revert, and the History dialog, can then bring back exactly what's here now, animation and all.
49
+ await hooks.saveNow();
50
+
51
+ const originalChildren = text.replaceableComponents!.get();
52
+ const copyKeyframes = <T>(keyframes: readonly T[]) =>
53
+ keyframes.map((keyframe) => ({ ...keyframe }));
54
+ const originalSpans = text.editableSpans().map((span) => ({
55
+ span,
56
+ content: copyKeyframes(span.contentSchedule.schedule),
57
+ style: copyKeyframes(span.styleSchedule.schedule),
58
+ }));
59
+ const initialValue = text.getSpans();
60
+
61
+ // MARK: Layout
62
+
63
+ // Cover the right column so the canvas stays fully visible. See openFontPickerDialog().
64
+ const rect = document.getElementById("right-col")?.getBoundingClientRect();
65
+ const dialog = document.createElement("dialog");
66
+ dialog.style.cssText = rect
67
+ ? [
68
+ `position:fixed`,
69
+ `margin:0`,
70
+ `padding:0`,
71
+ `left:${rect.left}px`,
72
+ `top:${rect.top}px`,
73
+ `width:${rect.width}px`,
74
+ `height:${rect.height}px`,
75
+ `max-width:none`,
76
+ `max-height:none`,
77
+ `border:none`,
78
+ `border-left:2px solid #999`,
79
+ `display:flex`,
80
+ `flex-direction:column`,
81
+ `box-shadow:-4px 0 16px rgba(0,0,0,0.2)`,
82
+ `z-index:9999`,
83
+ `overflow:hidden`,
84
+ ].join(";")
85
+ : "width:min(60em,90vw);height:80vh;display:flex;flex-direction:column;padding:0;border:1px solid #999;overflow:hidden;z-index:9999";
86
+
87
+ const top = document.createElement("div");
88
+ top.style.cssText =
89
+ "padding:0.5em 0.8em;background:#f4f4f4;border-bottom:1px solid #ccc;flex-shrink:0";
90
+ const heading = document.createElement("h3");
91
+ heading.style.margin = "0 0 0.2em 0";
92
+ heading.textContent = `✎ Edit Text: ${text.userEditableDescription ?? text.description}`;
93
+ const hint = document.createElement("div");
94
+ hint.style.cssText = "font-size:0.85em;color:#555";
95
+ hint.textContent =
96
+ "Each menu sets the format of the text after it, up to the next menu. " +
97
+ "+ Format adds a menu at the cursor. New… at the bottom of a menu makes a new format, " +
98
+ "starting as a copy of that one. Copy and paste use ⸨format⸩text, like addText1() in TypeScript.";
99
+ const toolbar = document.createElement("div");
100
+ toolbar.style.marginTop = "0.4em";
101
+ const insertFormatBtn = document.createElement("button");
102
+ insertFormatBtn.type = "button";
103
+ insertFormatBtn.textContent = "+ Format";
104
+ insertFormatBtn.title =
105
+ "Add a format menu at the cursor. It starts as the format already in effect there, " +
106
+ "so nothing changes until you pick another.";
107
+ toolbar.append(insertFormatBtn);
108
+ const notes = document.createElement("div");
109
+ notes.style.cssText = "font-size:0.85em;color:#a06000;margin-top:0.3em";
110
+ top.append(heading, hint, toolbar, notes);
111
+
112
+ const middle = document.createElement("div");
113
+ middle.style.cssText = "flex:1;overflow-y:auto;padding:0.8em";
114
+ const errorLine = document.createElement("div");
115
+ errorLine.style.cssText = "color:#d70015;font-size:0.85em;margin-top:0.3em";
116
+
117
+ const bottom = document.createElement("div");
118
+ bottom.style.cssText =
119
+ "display:flex;gap:0.5em;align-items:center;padding:0.5em 0.8em;background:#f4f4f4;border-top:1px solid #ccc;flex-shrink:0";
120
+ const status = document.createElement("div");
121
+ status.style.cssText = "flex:1;font-size:0.85em;color:#555";
122
+ status.textContent =
123
+ "The canvas follows as you type, when the playhead is inside this text's time.";
124
+ const revertBtn = document.createElement("button");
125
+ revertBtn.type = "button";
126
+ revertBtn.textContent = "Revert";
127
+ revertBtn.title = "Put the text and the formats back the way they were when this opened.";
128
+ revertBtn.disabled = true;
129
+ const doneBtn = document.createElement("button");
130
+ doneBtn.type = "button";
131
+ doneBtn.textContent = "Done";
132
+ doneBtn.title = "Close. Every change has already been made.";
133
+ bottom.append(status, revertBtn, doneBtn);
134
+
135
+ dialog.append(top, middle, bottom);
136
+
137
+ // MARK: Notes
138
+
139
+ const note = (message: string) => {
140
+ const div = document.createElement("div");
141
+ div.textContent = message;
142
+ notes.append(div);
143
+ return div;
144
+ };
145
+ if (text.hasProgramText) {
146
+ note(
147
+ "This Multi Text also has text written by the program (addText1()), " +
148
+ "which always comes after this text. It can't be edited here.",
149
+ );
150
+ }
151
+ if (
152
+ text.children.some(
153
+ ({ replaceable, child }) => !replaceable && child instanceof TextSpanComponent,
154
+ )
155
+ ) {
156
+ note("This Multi Text also has Text Spans built in TypeScript. They can't be edited here.");
157
+ }
158
+ for (const { span } of originalSpans) {
159
+ if (isAnimated(span)) {
160
+ note(
161
+ `“${span.get(0).content}” is animated. Editing it gives it one value, the one shown here. ` +
162
+ "The History dialog can still bring the animation back.",
163
+ );
164
+ }
165
+ }
166
+ const noFormatsNote = note(
167
+ "This text has no Text Formats yet. Pick New… in a menu to make one.",
168
+ );
169
+ /** New… and Revert change which formats there are. */
170
+ const formatsChanged = () => {
171
+ editor.knownNames = text.formatNamesInScope();
172
+ noFormatsNote.hidden = editor.knownNames.length > 0;
173
+ };
174
+
175
+ // MARK: Behavior
176
+
177
+ /** True while Revert puts the editor back, so that change isn't applied a second time. */
178
+ let reverting = false;
179
+
180
+ const editor = new FormatEditor(initialValue, text.formatNamesInScope(), {
181
+ onNewFormat: newFormat,
182
+ });
183
+ editor.element.style.minHeight = "12rem";
184
+ middle.append(editor.element, errorLine);
185
+ formatsChanged();
186
+
187
+ editor.onChange = (value) => {
188
+ if (reverting) return;
189
+ try {
190
+ text.setSpans(value);
191
+ } catch (reason) {
192
+ // The editor always starts with a format, so this shouldn't happen.
193
+ errorLine.textContent = String(reason);
194
+ return;
195
+ }
196
+ errorLine.textContent = "";
197
+ revertBtn.disabled = false;
198
+ hooks.changed();
199
+ };
200
+
201
+ /** New… in a menu. Resolves to the format's name, or undefined if the user cancelled. */
202
+ async function newFormat(currentName: string): Promise<string | undefined> {
203
+ const name = await askFormatName(text.formatNamesInScope());
204
+ if (name === undefined) return undefined;
205
+ // A name that's already there just picks that format.
206
+ if (!text.formatNamesInScope().includes(name)) {
207
+ // A copy, so nothing changes on screen until the new format is edited. A brand new
208
+ // format would draw at its own defaults: a different size and color.
209
+ const source = text.formatInScope(currentName);
210
+ const copy = source && hooks.copyComponent(source);
211
+ const format =
212
+ copy instanceof TextFormatComponent ? copy : new TextFormatComponent();
213
+ format.nameScalar.value = name;
214
+ // So the component list shows the name. Spans find a format by its Name, not this.
215
+ (format as Showable).userEditableDescription = name;
216
+ const children = text.replaceableComponents!.get();
217
+ const lastFormat = children.findLastIndex(
218
+ (child) => child instanceof TextFormatComponent,
219
+ );
220
+ children.splice(lastFormat + 1, 0, format);
221
+ text.replaceableComponents!.replace(children);
222
+ revertBtn.disabled = false;
223
+ hooks.changed();
224
+ }
225
+ formatsChanged();
226
+ return name;
227
+ }
228
+
229
+ // Keep the focus, and so the cursor, in the editor.
230
+ insertFormatBtn.addEventListener("mousedown", (event) => event.preventDefault());
231
+ insertFormatBtn.addEventListener("click", () => editor.insertFormat());
232
+
233
+ revertBtn.addEventListener("click", () => {
234
+ for (const { span, content, style } of originalSpans) {
235
+ span.contentSchedule.set(copyKeyframes(content));
236
+ span.styleSchedule.set(copyKeyframes(style));
237
+ }
238
+ // Brings back deleted spans, and removes new spans and new formats.
239
+ text.replaceableComponents!.replace(originalChildren);
240
+ reverting = true;
241
+ try {
242
+ editor.value = initialValue;
243
+ } finally {
244
+ reverting = false;
245
+ }
246
+ formatsChanged();
247
+ errorLine.textContent = "";
248
+ revertBtn.disabled = true;
249
+ hooks.changed();
250
+ });
251
+
252
+ doneBtn.addEventListener("click", () => dialog.close());
253
+
254
+ // Cmd+Z / Ctrl+Z anywhere in here is the editor's undo, not the History dialog.
255
+ // In the editor itself, the editor has already handled it.
256
+ dialog.addEventListener("keydown", (event) => {
257
+ if (event.defaultPrevented) return;
258
+ if (!(event.metaKey || event.ctrlKey) || event.altKey) return;
259
+ const key = event.key.toLowerCase();
260
+ if (key === "z" && !event.shiftKey) {
261
+ event.preventDefault();
262
+ editor.undo();
263
+ } else if ((key === "z" && event.shiftKey) || key === "y") {
264
+ event.preventDefault();
265
+ editor.redo();
266
+ }
267
+ });
268
+
269
+ // Escape, as well as Done. Every change is already made, so closing is always safe.
270
+ dialog.addEventListener("close", () => {
271
+ editor.destroy();
272
+ dialog.remove();
273
+ hooks.closed();
274
+ });
275
+
276
+ document.body.append(dialog);
277
+ dialog.showModal();
278
+ // Start typing at the end.
279
+ editor.element.focus();
280
+ document.getSelection()?.selectAllChildren(editor.element);
281
+ document.getSelection()?.collapseToEnd();
282
+ }
283
+
284
+ /**
285
+ * Ask for a new format's name.
286
+ * @param existing The names already in use. Picking one of these is allowed: it uses that format.
287
+ * @returns The name, or undefined if the user cancelled.
288
+ */
289
+ function askFormatName(existing: readonly string[]): Promise<string | undefined> {
290
+ const dialog = document.createElement("dialog");
291
+ dialog.style.cssText = "min-width:26em;max-width:36em;padding:1em";
292
+
293
+ const heading = document.createElement("h3");
294
+ heading.style.margin = "0 0 0.2em 0";
295
+ heading.textContent = "New Format";
296
+ const hint = document.createElement("div");
297
+ hint.style.cssText = "font-size:0.85em;color:#555;margin-bottom:0.8em";
298
+ hint.textContent =
299
+ "It starts as a copy of the format it replaces, so nothing changes on the canvas yet. " +
300
+ "After Done, select it in the component list to change how it looks.";
301
+
302
+ const label = document.createElement("label");
303
+ label.append("Name ");
304
+ const input = document.createElement("input");
305
+ input.type = "text";
306
+ input.style.width = "16em";
307
+ label.append(input);
308
+
309
+ const message = document.createElement("div");
310
+ message.style.cssText = "font-size:0.85em;min-height:1.3em;margin:0.3em 0 0.8em 0";
311
+
312
+ const buttons = document.createElement("div");
313
+ buttons.style.cssText = "display:flex;gap:0.5em;justify-content:flex-end";
314
+ const cancelBtn = document.createElement("button");
315
+ cancelBtn.type = "button";
316
+ cancelBtn.textContent = "Cancel";
317
+ const okBtn = document.createElement("button");
318
+ okBtn.type = "button";
319
+ okBtn.textContent = "OK";
320
+ buttons.append(cancelBtn, okBtn);
321
+
322
+ dialog.append(heading, hint, label, message, buttons);
323
+
324
+ function validate(): void {
325
+ const name = input.value;
326
+ const illegal = /[⸨⸩]/.test(name);
327
+ okBtn.disabled = illegal;
328
+ message.style.color = illegal ? "#d70015" : "#555";
329
+ message.textContent = illegal
330
+ ? "A format's name can't contain ⸨ or ⸩."
331
+ : existing.includes(name)
332
+ ? "There's already a format with this name. OK uses it."
333
+ : "";
334
+ }
335
+ input.addEventListener("input", validate);
336
+ input.addEventListener("keydown", (event) => {
337
+ if (event.key === "Enter" && !okBtn.disabled) {
338
+ event.preventDefault();
339
+ okBtn.click();
340
+ }
341
+ });
342
+
343
+ let result: string | undefined;
344
+ okBtn.addEventListener("click", () => {
345
+ result = input.value;
346
+ dialog.close();
347
+ });
348
+ cancelBtn.addEventListener("click", () => dialog.close());
349
+ validate();
350
+
351
+ return new Promise((resolve) => {
352
+ dialog.addEventListener("close", () => {
353
+ dialog.remove();
354
+ resolve(result);
355
+ });
356
+ document.body.append(dialog);
357
+ dialog.showModal();
358
+ input.focus();
359
+ });
360
+ }
@@ -27,6 +27,8 @@ export type TextFramePanelHooks = {
27
27
  readonly rotationChanged: () => void;
28
28
  readonly canvasState: () => CanvasState;
29
29
  readonly setCanvasState: (state: CanvasState) => void;
30
+ /** ✎ Edit Text… was clicked. Open the text editor. See multi-text-dialog.ts. */
31
+ readonly editText: () => void;
30
32
  };
31
33
 
32
34
  export type TextFramePanel = {
@@ -78,6 +80,15 @@ export function buildTextFramePanel(
78
80
 
79
81
  // MARK: Controls
80
82
 
83
+ const editTextRow = line("margin-bottom:0.3em");
84
+ const editTextBtn = button(
85
+ editTextRow,
86
+ "✎ Edit Text…",
87
+ "Type this text, with a menu in front of each part naming its format. " +
88
+ "The canvas follows as you type.",
89
+ );
90
+ editTextBtn.addEventListener("click", () => hooks.editText());
91
+
81
92
  const canvasRow = line();
82
93
  const viewBtn = button(canvasRow, "👁", "Show the frame on the canvas");
83
94
  const editBtn = button(