canvas-recorder-lib 0.8.1 → 0.8.4

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 (260) hide show
  1. package/README.md +10 -2
  2. package/dev/canvas-recorder.css +20 -6
  3. package/dev/canvas-recorder.ts +389 -54
  4. package/dev/color-picker.ts +13 -0
  5. package/dev/component-picker.ts +60 -11
  6. package/dev/delay-files.ts +3 -1
  7. package/dev/font-widgets.ts +2 -2
  8. package/dev/format-editor.ts +3 -1
  9. package/dev/fourier-panel.ts +7 -3
  10. package/dev/handwriting-panel.ts +7 -7
  11. package/dev/multi-text-dialog.ts +28 -15
  12. package/dev/player-body.ts +78 -33
  13. package/dev/schedule-helpers.ts +10 -3
  14. package/dev/static-image-panel.ts +4 -4
  15. package/dev/subtitles.ts +170 -0
  16. package/dev/synced-file.ts +34 -0
  17. package/dev/timeline-display.ts +1 -1
  18. package/dev/transcribe-core.ts +7 -4
  19. package/dev/transcript-align.ts +24 -18
  20. package/dev/transcript-editor.ts +1187 -0
  21. package/dev/transcript-export.ts +90 -0
  22. package/dev/transcript-view.ts +8 -5
  23. package/dev/transcripts.ts +140 -15
  24. package/dev/video-clip-panel.ts +4 -4
  25. package/dist/dev/canvas-recorder.css +20 -6
  26. package/dist/dev/canvas-recorder.js +314 -48
  27. package/dist/dev/canvas-recorder.js.map +1 -1
  28. package/dist/dev/color-picker.d.ts.map +1 -1
  29. package/dist/dev/color-picker.js +15 -0
  30. package/dist/dev/color-picker.js.map +1 -1
  31. package/dist/dev/component-picker.d.ts +2 -1
  32. package/dist/dev/component-picker.d.ts.map +1 -1
  33. package/dist/dev/component-picker.js +56 -11
  34. package/dist/dev/component-picker.js.map +1 -1
  35. package/dist/dev/delay-files.d.ts.map +1 -1
  36. package/dist/dev/delay-files.js +3 -1
  37. package/dist/dev/delay-files.js.map +1 -1
  38. package/dist/dev/font-widgets.d.ts +2 -2
  39. package/dist/dev/font-widgets.d.ts.map +1 -1
  40. package/dist/dev/font-widgets.js.map +1 -1
  41. package/dist/dev/format-editor.d.ts.map +1 -1
  42. package/dist/dev/format-editor.js +3 -1
  43. package/dist/dev/format-editor.js.map +1 -1
  44. package/dist/dev/fourier-panel.d.ts.map +1 -1
  45. package/dist/dev/fourier-panel.js +4 -3
  46. package/dist/dev/fourier-panel.js.map +1 -1
  47. package/dist/dev/handwriting-panel.d.ts +4 -4
  48. package/dist/dev/handwriting-panel.d.ts.map +1 -1
  49. package/dist/dev/handwriting-panel.js.map +1 -1
  50. package/dist/dev/multi-text-dialog.d.ts.map +1 -1
  51. package/dist/dev/multi-text-dialog.js +23 -12
  52. package/dist/dev/multi-text-dialog.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 +78 -33
  56. package/dist/dev/player-body.js.map +1 -1
  57. package/dist/dev/schedule-helpers.d.ts.map +1 -1
  58. package/dist/dev/schedule-helpers.js +4 -2
  59. package/dist/dev/schedule-helpers.js.map +1 -1
  60. package/dist/dev/static-image-panel.d.ts +3 -3
  61. package/dist/dev/static-image-panel.d.ts.map +1 -1
  62. package/dist/dev/subtitles.d.ts +36 -0
  63. package/dist/dev/subtitles.d.ts.map +1 -0
  64. package/dist/dev/subtitles.js +135 -0
  65. package/dist/dev/subtitles.js.map +1 -0
  66. package/dist/dev/synced-file.d.ts +14 -0
  67. package/dist/dev/synced-file.d.ts.map +1 -1
  68. package/dist/dev/synced-file.js +22 -0
  69. package/dist/dev/synced-file.js.map +1 -1
  70. package/dist/dev/timeline-display.d.ts +5 -0
  71. package/dist/dev/timeline-display.d.ts.map +1 -1
  72. package/dist/dev/timeline-display.js +1 -1
  73. package/dist/dev/timeline-display.js.map +1 -1
  74. package/dist/dev/transcribe-core.d.ts.map +1 -1
  75. package/dist/dev/transcribe-core.js +7 -4
  76. package/dist/dev/transcribe-core.js.map +1 -1
  77. package/dist/dev/transcript-align.d.ts +6 -4
  78. package/dist/dev/transcript-align.d.ts.map +1 -1
  79. package/dist/dev/transcript-align.js +18 -13
  80. package/dist/dev/transcript-align.js.map +1 -1
  81. package/dist/dev/transcript-editor.d.ts +36 -0
  82. package/dist/dev/transcript-editor.d.ts.map +1 -0
  83. package/dist/dev/transcript-editor.js +948 -0
  84. package/dist/dev/transcript-editor.js.map +1 -0
  85. package/dist/dev/transcript-export.d.ts +21 -0
  86. package/dist/dev/transcript-export.d.ts.map +1 -1
  87. package/dist/dev/transcript-export.js +65 -0
  88. package/dist/dev/transcript-export.js.map +1 -1
  89. package/dist/dev/transcript-view.d.ts +2 -0
  90. package/dist/dev/transcript-view.d.ts.map +1 -1
  91. package/dist/dev/transcript-view.js +1 -1
  92. package/dist/dev/transcript-view.js.map +1 -1
  93. package/dist/dev/transcripts.d.ts +18 -1
  94. package/dist/dev/transcripts.d.ts.map +1 -1
  95. package/dist/dev/transcripts.js +102 -12
  96. package/dist/dev/transcripts.js.map +1 -1
  97. package/dist/dev/video-clip-panel.d.ts +3 -3
  98. package/dist/dev/video-clip-panel.d.ts.map +1 -1
  99. package/dist/lib/index.d.ts +1 -0
  100. package/dist/lib/index.d.ts.map +1 -1
  101. package/dist/lib/index.js +1 -0
  102. package/dist/lib/index.js.map +1 -1
  103. package/dist/src/glib/line-font.d.ts +6 -0
  104. package/dist/src/glib/line-font.d.ts.map +1 -1
  105. package/dist/src/glib/line-font.js +9 -0
  106. package/dist/src/glib/line-font.js.map +1 -1
  107. package/dist/src/glib/path-shape.d.ts +23 -0
  108. package/dist/src/glib/path-shape.d.ts.map +1 -1
  109. package/dist/src/glib/path-shape.js +66 -221
  110. package/dist/src/glib/path-shape.js.map +1 -1
  111. package/dist/src/glib/svg-arc.d.ts +41 -0
  112. package/dist/src/glib/svg-arc.d.ts.map +1 -0
  113. package/dist/src/glib/svg-arc.js +114 -0
  114. package/dist/src/glib/svg-arc.js.map +1 -0
  115. package/dist/src/glib/svg-path-parser.d.ts +60 -0
  116. package/dist/src/glib/svg-path-parser.d.ts.map +1 -0
  117. package/dist/src/glib/svg-path-parser.js +258 -0
  118. package/dist/src/glib/svg-path-parser.js.map +1 -0
  119. package/dist/src/glib/transforms.d.ts +9 -0
  120. package/dist/src/glib/transforms.d.ts.map +1 -1
  121. package/dist/src/glib/transforms.js +7 -4
  122. package/dist/src/glib/transforms.js.map +1 -1
  123. package/dist/src/interpolate.d.ts +17 -10
  124. package/dist/src/interpolate.d.ts.map +1 -1
  125. package/dist/src/interpolate.js +1 -17
  126. package/dist/src/interpolate.js.map +1 -1
  127. package/dist/src/morph-animation.js +1 -1
  128. package/dist/src/morph-animation.js.map +1 -1
  129. package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
  130. package/dist/src/peano-fourier/fourier-shared.js +4 -2
  131. package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
  132. package/dist/src/schedule-helper.d.ts +50 -28
  133. package/dist/src/schedule-helper.d.ts.map +1 -1
  134. package/dist/src/schedule-helper.js +22 -0
  135. package/dist/src/schedule-helper.js.map +1 -1
  136. package/dist/src/showable.d.ts +57 -10
  137. package/dist/src/showable.d.ts.map +1 -1
  138. package/dist/src/showable.js +19 -0
  139. package/dist/src/showable.js.map +1 -1
  140. package/dist/src/slide-components/arrow.d.ts +4 -4
  141. package/dist/src/slide-components/arrow.d.ts.map +1 -1
  142. package/dist/src/slide-components/cross-fade-transition.d.ts +2 -1
  143. package/dist/src/slide-components/cross-fade-transition.d.ts.map +1 -1
  144. package/dist/src/slide-components/cross-fade-transition.js +2 -1
  145. package/dist/src/slide-components/cross-fade-transition.js.map +1 -1
  146. package/dist/src/slide-components/duration-agnostic.d.ts +3 -2
  147. package/dist/src/slide-components/duration-agnostic.d.ts.map +1 -1
  148. package/dist/src/slide-components/duration-agnostic.js +4 -2
  149. package/dist/src/slide-components/duration-agnostic.js.map +1 -1
  150. package/dist/src/slide-components/fixed-duration.d.ts +3 -1
  151. package/dist/src/slide-components/fixed-duration.d.ts.map +1 -1
  152. package/dist/src/slide-components/fixed-duration.js +4 -2
  153. package/dist/src/slide-components/fixed-duration.js.map +1 -1
  154. package/dist/src/slide-components/fourier.d.ts +19 -12
  155. package/dist/src/slide-components/fourier.d.ts.map +1 -1
  156. package/dist/src/slide-components/fourier.js +77 -16
  157. package/dist/src/slide-components/fourier.js.map +1 -1
  158. package/dist/src/slide-components/function-graph.d.ts +4 -3
  159. package/dist/src/slide-components/function-graph.d.ts.map +1 -1
  160. package/dist/src/slide-components/function-graph.js +6 -2
  161. package/dist/src/slide-components/function-graph.js.map +1 -1
  162. package/dist/src/slide-components/halftone-shadow.d.ts +8 -7
  163. package/dist/src/slide-components/halftone-shadow.d.ts.map +1 -1
  164. package/dist/src/slide-components/halftone-shadow.js +14 -10
  165. package/dist/src/slide-components/halftone-shadow.js.map +1 -1
  166. package/dist/src/slide-components/handwriting-effect.d.ts +8 -6
  167. package/dist/src/slide-components/handwriting-effect.d.ts.map +1 -1
  168. package/dist/src/slide-components/handwriting-effect.js +4 -2
  169. package/dist/src/slide-components/handwriting-effect.js.map +1 -1
  170. package/dist/src/slide-components/hold.d.ts +4 -2
  171. package/dist/src/slide-components/hold.d.ts.map +1 -1
  172. package/dist/src/slide-components/hold.js +4 -2
  173. package/dist/src/slide-components/hold.js.map +1 -1
  174. package/dist/src/slide-components/image.d.ts +7 -7
  175. package/dist/src/slide-components/image.d.ts.map +1 -1
  176. package/dist/src/slide-components/image.js +4 -2
  177. package/dist/src/slide-components/image.js.map +1 -1
  178. package/dist/src/slide-components/in-parallel.d.ts +6 -3
  179. package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
  180. package/dist/src/slide-components/in-parallel.js +12 -2
  181. package/dist/src/slide-components/in-parallel.js.map +1 -1
  182. package/dist/src/slide-components/in-series.d.ts +2 -1
  183. package/dist/src/slide-components/in-series.d.ts.map +1 -1
  184. package/dist/src/slide-components/in-series.js +2 -1
  185. package/dist/src/slide-components/in-series.js.map +1 -1
  186. package/dist/src/slide-components/live-duration.d.ts +3 -1
  187. package/dist/src/slide-components/live-duration.d.ts.map +1 -1
  188. package/dist/src/slide-components/live-duration.js +4 -2
  189. package/dist/src/slide-components/live-duration.js.map +1 -1
  190. package/dist/src/slide-components/multi-text.d.ts +39 -26
  191. package/dist/src/slide-components/multi-text.d.ts.map +1 -1
  192. package/dist/src/slide-components/multi-text.js +44 -29
  193. package/dist/src/slide-components/multi-text.js.map +1 -1
  194. package/dist/src/slide-components/rectangle.d.ts +5 -4
  195. package/dist/src/slide-components/rectangle.d.ts.map +1 -1
  196. package/dist/src/slide-components/rectangle.js +2 -1
  197. package/dist/src/slide-components/rectangle.js.map +1 -1
  198. package/dist/src/slide-components/registry.d.ts +5 -0
  199. package/dist/src/slide-components/registry.d.ts.map +1 -1
  200. package/dist/src/slide-components/registry.js +28 -27
  201. package/dist/src/slide-components/registry.js.map +1 -1
  202. package/dist/src/slide-components/show-error.d.ts.map +1 -1
  203. package/dist/src/slide-components/show-error.js +12 -4
  204. package/dist/src/slide-components/show-error.js.map +1 -1
  205. package/dist/src/slide-components/simple-text.d.ts +11 -10
  206. package/dist/src/slide-components/simple-text.d.ts.map +1 -1
  207. package/dist/src/slide-components/simple-text.js +5 -3
  208. package/dist/src/slide-components/simple-text.js.map +1 -1
  209. package/dist/src/slide-components/slide-component.d.ts +14 -13
  210. package/dist/src/slide-components/slide-component.d.ts.map +1 -1
  211. package/dist/src/slide-components/slide-component.js +2 -1
  212. package/dist/src/slide-components/slide-component.js.map +1 -1
  213. package/dist/src/slide-components/slide-left.d.ts +2 -1
  214. package/dist/src/slide-components/slide-left.d.ts.map +1 -1
  215. package/dist/src/slide-components/slide-left.js +2 -1
  216. package/dist/src/slide-components/slide-left.js.map +1 -1
  217. package/dist/src/slide-components/text-effect.d.ts +9 -1
  218. package/dist/src/slide-components/text-effect.d.ts.map +1 -1
  219. package/dist/src/slide-components/text-effect.js.map +1 -1
  220. package/dist/src/slide-components/traditional-text.d.ts +8 -8
  221. package/dist/src/slide-components/traditional-text.d.ts.map +1 -1
  222. package/dist/src/slide-components/video-clip.d.ts +4 -3
  223. package/dist/src/slide-components/video-clip.d.ts.map +1 -1
  224. package/dist/src/slide-components/video-clip.js +2 -1
  225. package/dist/src/slide-components/video-clip.js.map +1 -1
  226. package/lib/index.ts +1 -0
  227. package/package.json +2 -2
  228. package/src/glib/line-font.ts +9 -0
  229. package/src/glib/path-shape.ts +101 -245
  230. package/src/glib/svg-arc.ts +141 -0
  231. package/src/glib/svg-path-parser.ts +308 -0
  232. package/src/glib/transforms.ts +7 -4
  233. package/src/interpolate.ts +18 -27
  234. package/src/morph-animation.ts +1 -1
  235. package/src/peano-fourier/fourier-shared.ts +4 -2
  236. package/src/schedule-helper.ts +50 -28
  237. package/src/showable.ts +79 -10
  238. package/src/slide-components/arrow.ts +4 -4
  239. package/src/slide-components/cross-fade-transition.ts +9 -2
  240. package/src/slide-components/duration-agnostic.ts +4 -3
  241. package/src/slide-components/fixed-duration.ts +4 -2
  242. package/src/slide-components/fourier.ts +98 -29
  243. package/src/slide-components/function-graph.ts +7 -3
  244. package/src/slide-components/halftone-shadow.ts +21 -16
  245. package/src/slide-components/handwriting-effect.ts +8 -6
  246. package/src/slide-components/hold.ts +18 -4
  247. package/src/slide-components/image.ts +9 -7
  248. package/src/slide-components/in-parallel.ts +16 -1
  249. package/src/slide-components/in-series.ts +3 -1
  250. package/src/slide-components/live-duration.ts +4 -2
  251. package/src/slide-components/multi-text.ts +71 -44
  252. package/src/slide-components/rectangle.ts +6 -4
  253. package/src/slide-components/registry.ts +33 -27
  254. package/src/slide-components/show-error.ts +13 -4
  255. package/src/slide-components/simple-text.ts +22 -12
  256. package/src/slide-components/slide-component.ts +15 -13
  257. package/src/slide-components/slide-left.ts +9 -2
  258. package/src/slide-components/text-effect.ts +9 -0
  259. package/src/slide-components/traditional-text.ts +8 -8
  260. package/src/slide-components/video-clip.ts +5 -3
@@ -2,7 +2,7 @@ import { ReadOnlyRect, sum } from "phil-lib/misc";
2
2
  import { myRainbow } from "../glib/my-rainbow.ts";
3
3
  import { ParametricFunction, PathShape } from "../glib/path-shape.ts";
4
4
  import { panAndZoom } from "../glib/transforms.ts";
5
- import { Keyframe } from "../interpolate.ts";
5
+ import { TimedKeyframe } from "../interpolate.ts";
6
6
  import {
7
7
  Complex,
8
8
  FourierTerm,
@@ -83,21 +83,52 @@ export type TermGroups = {
83
83
  /** A range like 0-99999 is a typo, not a request. */
84
84
  const MAX_RANGE = 10_000;
85
85
 
86
+ /**
87
+ * "2", "2 and 3", "3, 5 and 7", "2, 3, 4, 5, 6, 7 and 4 more".
88
+ * Long lists are common here, from pasting over a selection instead of the
89
+ * whole field, so a warning names the first few and counts the rest.
90
+ */
91
+ function listWithMore(items: readonly number[], shownMax = 6): string {
92
+ const shown = items.slice(0, shownMax).map(String);
93
+ const more = items.length - shown.length;
94
+ if (more > 0) shown.push(`${more} more`);
95
+ const last = shown.pop()!;
96
+ return shown.length ? `${shown.join(", ")} and ${last}` : last;
97
+ }
98
+
99
+ /**
100
+ * Where `8-` ends when the source isn't known: the last term of a source made
101
+ * from the default 1024 samples. Terms past a source's end are skipped.
102
+ */
103
+ const OPEN_RANGE_DEFAULT_TERM_COUNT = 1024;
104
+
86
105
  /**
87
106
  * Read the Term Groups format: numbers separated by spaces, a comma between
88
107
  * groups. `5-9` is short for `5 6 7 8 9`. Each group is one step.
108
+ * `8-` is every term from 8 to the end of the source, so one Term Groups can
109
+ * serve sources with different numbers of terms.
89
110
  *
90
- * For example, `0, 1, 2 3, 4-9` is four steps: add term 0, then term 1, then
91
- * terms 2 and 3 together, then terms 4 through 9 together.
111
+ * For example, `0, 1, 2 3, 4-9, 10-` is five steps: add term 0, then term 1,
112
+ * then terms 2 and 3 together, then terms 4 through 9 together, then the rest.
92
113
  *
93
114
  * Pure.
115
+ * @param termCount How many terms the source has, which is where `8-` ends.
116
+ * Without it, `8-` ends at 1023, and terms past the source's end are skipped
117
+ * later.
94
118
  */
95
- export function parseTermGroups(text: string): TermGroups {
119
+ export function parseTermGroups(
120
+ text: string,
121
+ termCount = OPEN_RANGE_DEFAULT_TERM_COUNT,
122
+ ): TermGroups {
96
123
  const errors: string[] = [];
97
124
  const warnings: string[] = [];
98
125
  if (text.trim() === "") return { groups: [], errors, warnings };
126
+ /** Empty groups are common, to keep several Fouriers in step. One warning covers them all. */
127
+ const emptyGroups: number[] = [];
99
128
  /** Where each term was first added, to report repeats. */
100
129
  const firstGroup = new Map<number, number>();
130
+ /** Every term listed a second time, in order. One warning covers them all. */
131
+ const repeats: { term: number; earlier: number; groupNumber: number }[] = [];
101
132
  const groups = text.split(",").map((piece, groupIndex) => {
102
133
  const groupNumber = groupIndex + 1;
103
134
  const group: number[] = [];
@@ -106,25 +137,28 @@ export function parseTermGroups(text: string): TermGroups {
106
137
  if (earlier === undefined) {
107
138
  firstGroup.set(term, groupNumber);
108
139
  } else {
109
- warnings.push(
110
- earlier === groupNumber
111
- ? `Term ${term} is in group ${groupNumber} twice.`
112
- : `Term ${term} is in group ${earlier} and again in group ${groupNumber}. Terms are only ever added, so the second time does nothing.`,
113
- );
140
+ repeats.push({ term, earlier, groupNumber });
114
141
  }
115
142
  group.push(term);
116
143
  };
117
144
  const tokens = piece.trim().split(/\s+/).filter(Boolean);
118
145
  if (tokens.length === 0) {
119
- warnings.push(
120
- `Group ${groupNumber} is empty, so that step adds nothing.`,
121
- );
146
+ emptyGroups.push(groupNumber);
122
147
  }
123
148
  for (const token of tokens) {
124
149
  const single = /^\d+$/.exec(token);
125
150
  const range = /^(\d+)-(\d+)$/.exec(token);
151
+ const openRange = /^(\d+)-$/.exec(token);
126
152
  if (single) {
127
153
  add(Number(token));
154
+ } else if (openRange) {
155
+ const from = Number(openRange[1]);
156
+ if (from >= termCount) {
157
+ warnings.push(
158
+ `"${token}" adds nothing: this source's last term is ${termCount - 1}.`,
159
+ );
160
+ }
161
+ for (let term = from; term < termCount; term++) add(term);
128
162
  } else if (range) {
129
163
  const from = Number(range[1]);
130
164
  const to = Number(range[2]);
@@ -136,11 +170,33 @@ export function parseTermGroups(text: string): TermGroups {
136
170
  for (let term = from; term <= to; term++) add(term);
137
171
  }
138
172
  } else {
139
- errors.push(`"${token}" isn't a term number or a range like 5-9.`);
173
+ errors.push(
174
+ `"${token}" isn't a term number or a range like 5-9 or 8-.`,
175
+ );
140
176
  }
141
177
  }
142
178
  return group;
143
179
  });
180
+ if (repeats.length) {
181
+ const [{ term, earlier, groupNumber }] = repeats;
182
+ const where =
183
+ earlier === groupNumber
184
+ ? `is in group ${groupNumber} twice`
185
+ : `is in group ${earlier} and again in group ${groupNumber}`;
186
+ warnings.push(
187
+ repeats.length === 1
188
+ ? `Term ${term} ${where}. Terms are only ever added, so the second time does nothing.`
189
+ : `Terms ${listWithMore(repeats.map((repeat) => repeat.term))} are each listed twice. ` +
190
+ `Terms are only ever added, so the second time does nothing. The first, ${term}, ${where}.`,
191
+ );
192
+ }
193
+ if (emptyGroups.length) {
194
+ const list = listWithMore(emptyGroups);
195
+ const one = emptyGroups.length === 1;
196
+ warnings.push(
197
+ `${one ? "Group" : "Groups"} ${list} ${one ? "is" : "are"} empty, so ${one ? "that step adds" : "those steps add"} nothing.`,
198
+ );
199
+ }
144
200
  return { groups, errors, warnings };
145
201
  }
146
202
 
@@ -161,11 +217,9 @@ export function checkTermGroups(
161
217
  }
162
218
  if (missing.size) {
163
219
  const list = [...missing].sort((a, b) => a - b);
164
- const shown =
165
- list.length > 6 ? `${list.slice(0, 6).join(", ")}, …` : list.join(", ");
166
220
  warnings.push(
167
221
  `This source has ${terms.length} terms, numbered 0 to ${terms.length - 1}. ` +
168
- `Left out: ${shown}.`,
222
+ `Left out: ${listWithMore(list)}.`,
169
223
  );
170
224
  }
171
225
  // The frequency 0 term is the shape's center. samplesToFourier() leaves it
@@ -228,7 +282,7 @@ export function orderTerms(
228
282
  * Pure.
229
283
  */
230
284
  export function checkStepRange(
231
- step: readonly Keyframe<number>[],
285
+ step: readonly TimedKeyframe<number>[],
232
286
  groupCount: number,
233
287
  ): string[] {
234
288
  const shown = step.map(({ value }) => value).filter((value) => value >= 0);
@@ -296,7 +350,7 @@ function boundsOf(samples: readonly Complex[]): ReadOnlyRect {
296
350
  * away and starts over, which is fine as long as it's rare.
297
351
  */
298
352
  export class FourierComponent extends DurationAgnosticComponent {
299
- readonly registryKey = "Fourier";
353
+ readonly registryKey: string;
300
354
 
301
355
  /**
302
356
  * The curves the Source field can choose from, by name.
@@ -344,18 +398,20 @@ export class FourierComponent extends DurationAgnosticComponent {
344
398
  constructor(
345
399
  initialValues: {
346
400
  description?: string;
401
+ registryKey?: string;
347
402
  source?: string;
348
- termGroups?: string | Keyframe<string>[];
349
- step?: number | Keyframe<number>[];
350
- destRect?: ReadOnlyRect | Keyframe<ReadOnlyRect>[];
351
- fillColor?: string | Keyframe<string>[];
352
- strokeColor?: string | Keyframe<string>[];
353
- lineWidth?: number | Keyframe<number>[];
403
+ termGroups?: string | TimedKeyframe<string>[];
404
+ step?: number | TimedKeyframe<number>[];
405
+ destRect?: ReadOnlyRect | TimedKeyframe<ReadOnlyRect>[];
406
+ fillColor?: string | TimedKeyframe<string>[];
407
+ strokeColor?: string | TimedKeyframe<string>[];
408
+ lineWidth?: number | TimedKeyframe<number>[];
354
409
  /** How long to ask the parent for. The default covers the default Step schedule. */
355
410
  minDuration?: number;
356
411
  } = {},
357
412
  ) {
358
413
  super(initialValues.description ?? "Fourier");
414
+ this.registryKey = initialValues.registryKey ?? "Fourier";
359
415
  const names = [...FourierComponent.sources.keys()];
360
416
  this.sourceSchedule = new SelectScheduleInfo(
361
417
  "Source",
@@ -453,7 +509,7 @@ export class FourierComponent extends DurationAgnosticComponent {
453
509
  return cached;
454
510
  const source = this.termsFor(name);
455
511
  if (typeof source === "string") return source;
456
- const { groups } = parseTermGroups(termGroups);
512
+ const { groups } = parseTermGroups(termGroups, source.terms.length);
457
513
  const ordered = orderTerms(source.terms, groups);
458
514
  const rules =
459
515
  ordered.keyframes.length < 2
@@ -498,6 +554,7 @@ export class FourierComponent extends DurationAgnosticComponent {
498
554
  /**
499
555
  * Draw the curve: fill, then stroke. It's already in place, in canvas
500
556
  * coordinates, so the line width isn't affected by the curve's scale.
557
+ * A Line Width of 0 draws no line, and a transparent Fill Color no fill.
501
558
  *
502
559
  * Override this to draw it differently, e.g. stroked with strokeColors()
503
560
  * like the Sierpiński video.
@@ -512,9 +569,13 @@ export class FourierComponent extends DurationAgnosticComponent {
512
569
  // itself, the fill alternates instead of piling up.
513
570
  context.fill(path, "evenodd");
514
571
  }
572
+ const lineWidth = this.lineWidthSchedule.at(timeInMs);
573
+ // The canvas ignores a width of 0 or less, and would stroke at whatever
574
+ // width came before. 0 means no line.
575
+ if (!(lineWidth > 0)) return;
515
576
  context.lineCap = "round";
516
577
  context.lineJoin = "round";
517
- context.lineWidth = this.lineWidthSchedule.at(timeInMs);
578
+ context.lineWidth = lineWidth;
518
579
  context.strokeStyle = this.strokeColorSchedule.at(timeInMs);
519
580
  context.stroke(path);
520
581
  }
@@ -524,9 +585,17 @@ export class FourierComponent extends DurationAgnosticComponent {
524
585
 
525
586
  // Cheap to create: nothing is computed until a component draws one.
526
587
 
527
- FourierComponent.sources.set("Star", {
528
- path: makePolygon(5, 1, undefined, 0).transform(new DOMMatrix().rotate(-90)),
529
- });
588
+ {
589
+ let star: PathShape | undefined;
590
+ FourierComponent.sources.set("Star", {
591
+ // A getter, so it's made on first use. DOMMatrix doesn't exist in Node.
592
+ get path() {
593
+ return (star ??= makePolygon(5, 1, undefined, 0).transform(
594
+ new DOMMatrix().rotate(-90),
595
+ ));
596
+ },
597
+ });
598
+ }
530
599
  FourierComponent.sources.set("Square", {
531
600
  path: "M -1,-1 L 1,-1 L 1,1 L -1,1 Z",
532
601
  });
@@ -6,7 +6,7 @@ import {
6
6
  NumberScheduleInfo,
7
7
  ColorScheduleInfo,
8
8
  } from "../schedule-helper.ts";
9
- import { Showable, ShowOptions } from "../showable.ts";
9
+ import { ComponentOptions, Showable, ShowOptions } from "../showable.ts";
10
10
  import { showError } from "./show-error.ts";
11
11
 
12
12
  export class FunctionGraphComponent implements Showable {
@@ -21,9 +21,13 @@ export class FunctionGraphComponent implements Showable {
21
21
  */
22
22
  static readonly functions = new Map<string, (x: number) => number>();
23
23
 
24
- readonly registryKey = "Function Graph";
25
- readonly description = "Function Graph";
24
+ readonly registryKey: string;
25
+ readonly description: string;
26
26
  readonly duration = 0;
27
+ constructor(options: ComponentOptions = {}) {
28
+ this.description = options.description ?? "Function Graph";
29
+ this.registryKey = options.registryKey ?? "Function Graph";
30
+ }
27
31
 
28
32
  readonly functionNameSchedule = new StringScheduleInfo(
29
33
  "Function Name",
@@ -1,7 +1,8 @@
1
+ import { canvasRecorder } from "../../lib/main-control.ts";
1
2
  import { ColorScheduleInfo, NumberScheduleInfo } from "../schedule-helper.ts";
2
3
  import { Showable, ShowOptions } from "../showable.ts";
3
4
  import { InParallelComponent } from "./in-parallel.ts";
4
- import { Keyframe } from "../interpolate.ts";
5
+ import { TimedKeyframe } from "../interpolate.ts";
5
6
 
6
7
  /** At 100% opacity the dot radius reaches this fraction of the half-cell width. */
7
8
  const HALFTONE_MAX_RADIUS_FACTOR = 0.9;
@@ -19,7 +20,7 @@ const HALFTONE_MAX_RADIUS_FACTOR = 0.9;
19
20
  * Showable in the constructor to add it as a fixed child.
20
21
  */
21
22
  export class HalftoneShadowComponent extends InParallelComponent {
22
- readonly registryKey = "Halftone Shadow";
23
+ readonly registryKey: string;
23
24
  readonly dotColorSchedule = new ColorScheduleInfo("Dot Color", "#ccc");
24
25
  readonly backgroundColorSchedule = new ColorScheduleInfo(
25
26
  "Background Color",
@@ -38,11 +39,12 @@ export class HalftoneShadowComponent extends InParallelComponent {
38
39
  initialValues: {
39
40
  base?: Showable;
40
41
  description?: string;
41
- dotColor?: string | readonly Keyframe<string>[];
42
- backgroundColor?: string | readonly Keyframe<string>[];
43
- dx?: number | readonly Keyframe<number>[];
44
- dy?: number | readonly Keyframe<number>[];
45
- period?: number | readonly Keyframe<number>[];
42
+ registryKey?: string;
43
+ dotColor?: string | readonly TimedKeyframe<string>[];
44
+ backgroundColor?: string | readonly TimedKeyframe<string>[];
45
+ dx?: number | readonly TimedKeyframe<number>[];
46
+ dy?: number | readonly TimedKeyframe<number>[];
47
+ period?: number | readonly TimedKeyframe<number>[];
46
48
  } = {},
47
49
  ) {
48
50
  const { base } = initialValues;
@@ -50,6 +52,7 @@ export class HalftoneShadowComponent extends InParallelComponent {
50
52
  initialValues.description ??
51
53
  (base ? `${base.description} » shadow` : "Halftone Shadow"),
52
54
  );
55
+ this.registryKey = initialValues.registryKey ?? "Halftone Shadow";
53
56
  this.schedules.push(
54
57
  this.dotColorSchedule,
55
58
  this.backgroundColorSchedule,
@@ -75,18 +78,21 @@ export class HalftoneShadowComponent extends InParallelComponent {
75
78
  const dx = this.dxSchedule.at(timeInMs);
76
79
  const dy = this.dySchedule.at(timeInMs);
77
80
  const period = this.periodSchedule.at(timeInMs);
78
- const cols = Math.ceil(16 / period);
79
- const rows = Math.ceil(9 / period);
81
+ // Read the size every frame: it can change at any time.
82
+ const { width, height } = canvasRecorder;
83
+ // One small pixel per dot. The last row and column can hang past the edge.
84
+ const cols = Math.ceil(width / period);
85
+ const rows = Math.ceil(height / period);
80
86
 
81
87
  // Low-power mode or CLI context: skip the halftone pass.
82
88
  if (options.quality === "Low Power" || typeof document === "undefined") {
83
89
  context.fillStyle = backgroundColor;
84
- context.fillRect(0, 0, 16, 9);
90
+ context.fillRect(0, 0, width, height);
85
91
  super.show(options);
86
92
  return;
87
93
  }
88
94
 
89
- // Resize the small canvas when period changes.
95
+ // Resize the small canvas when the period or the canvas size changes.
90
96
  if (
91
97
  !this.#smallCanvas ||
92
98
  this.#smallCols !== cols ||
@@ -98,23 +104,22 @@ export class HalftoneShadowComponent extends InParallelComponent {
98
104
  this.#smallCtx = this.#smallCanvas.getContext("2d", {
99
105
  willReadFrequently: true,
100
106
  })!;
101
- // Apply the 16×9 root transform once — it stays until the canvas is replaced.
102
- this.#smallCtx.scale(cols / 16, rows / 9);
103
107
  this.#smallCols = cols;
104
108
  this.#smallRows = rows;
105
109
  }
106
110
  const smallCtx = this.#smallCtx!;
107
111
 
108
112
  // Render children into the small canvas for alpha sampling.
109
- smallCtx.save();
110
113
  smallCtx.resetTransform();
111
114
  smallCtx.clearRect(0, 0, cols, rows);
112
- smallCtx.restore();
115
+ // Each small pixel is exactly one cell, so it samples where its dot is drawn.
116
+ // Set every frame: the period can change without changing cols or rows.
117
+ smallCtx.scale(1 / period, 1 / period);
113
118
  super.show({ ...options, context: smallCtx, registerTransform: undefined });
114
119
 
115
120
  // Draw background.
116
121
  context.fillStyle = backgroundColor;
117
- context.fillRect(0, 0, 16, 9);
122
+ context.fillRect(0, 0, width, height);
118
123
 
119
124
  // Build halftone dot path from the alpha channel and draw as the shadow.
120
125
  const { data } = smallCtx.getImageData(0, 0, cols, rows);
@@ -2,9 +2,9 @@
2
2
 
3
3
  import { Command, PathShape } from "../glib/path-shape.ts";
4
4
  import { PathShapeSplitter } from "../glib/path-shape-splitter.ts";
5
- import { Keyframe } from "../interpolate.ts";
5
+ import { TimedKeyframe } from "../interpolate.ts";
6
6
  import { NumberScheduleInfo } from "../schedule-helper.ts";
7
- import { Scalar, ShowOptions } from "../showable.ts";
7
+ import { ComponentOptions, Scalar, ShowOptions } from "../showable.ts";
8
8
  import { showError } from "./show-error.ts";
9
9
  import { EffectLetter, TEXT_EFFECT, TextEffect } from "./text-effect.ts";
10
10
 
@@ -172,7 +172,7 @@ export function handwritingPaths(
172
172
  * resize as it's written.
173
173
  */
174
174
  export class HandwritingEffectComponent implements TextEffect {
175
- readonly registryKey = "Handwriting Effect";
175
+ readonly registryKey: string;
176
176
  /** What one step of Progress means. See {@link HANDWRITING_DIVISIONS}. */
177
177
  readonly divisionsScalar: Scalar<"select"> = {
178
178
  description: "Divisions",
@@ -190,14 +190,16 @@ export class HandwritingEffectComponent implements TextEffect {
190
190
  { time: 3000, value: 1 },
191
191
  ]);
192
192
  readonly schedules = [this.progressSchedule] as const;
193
- readonly description = "Handwriting Effect";
193
+ readonly description: string;
194
194
  readonly duration = 0;
195
195
  constructor(
196
196
  initialValues: {
197
197
  divisions?: HandwritingDivision;
198
- progress?: number | readonly Keyframe<number>[];
199
- } = {},
198
+ progress?: number | readonly TimedKeyframe<number>[];
199
+ } & ComponentOptions = {},
200
200
  ) {
201
+ this.description = initialValues.description ?? "Handwriting Effect";
202
+ this.registryKey = initialValues.registryKey ?? "Handwriting Effect";
201
203
  if (initialValues.divisions !== undefined)
202
204
  this.divisionsScalar.value = initialValues.divisions;
203
205
  if (initialValues.progress !== undefined)
@@ -15,10 +15,17 @@ export class HoldPreviousTransition
15
15
  extends ComponentWithLiveDuration
16
16
  implements Transition
17
17
  {
18
- readonly registryKey = "Hold Previous";
18
+ readonly registryKey: string;
19
19
  override readonly replaceableComponents = undefined;
20
- constructor(options: { description?: string; duration?: number } = {}) {
20
+ constructor(
21
+ options: {
22
+ description?: string;
23
+ registryKey?: string;
24
+ duration?: number;
25
+ } = {},
26
+ ) {
21
27
  super(options.description ?? "Hold Previous", options.duration ?? 1000);
28
+ this.registryKey = options.registryKey ?? "Hold Previous";
22
29
  }
23
30
  override show(options: ShowOptions): void {
24
31
  showError(
@@ -49,10 +56,17 @@ export class HoldNextTransition
49
56
  extends ComponentWithLiveDuration
50
57
  implements Transition
51
58
  {
52
- readonly registryKey = "Hold Next";
59
+ readonly registryKey: string;
53
60
  override readonly replaceableComponents = undefined;
54
- constructor(options: { description?: string; duration?: number } = {}) {
61
+ constructor(
62
+ options: {
63
+ description?: string;
64
+ registryKey?: string;
65
+ duration?: number;
66
+ } = {},
67
+ ) {
55
68
  super(options.description ?? "Hold Next", options.duration ?? 1000);
69
+ this.registryKey = options.registryKey ?? "Hold Next";
56
70
  }
57
71
  override show(options: ShowOptions): void {
58
72
  showError(
@@ -3,9 +3,9 @@ import {
3
3
  StringScheduleInfo,
4
4
  RectangleScheduleInfo,
5
5
  } from "../schedule-helper.ts";
6
- import { Showable, ShowOptions } from "../showable.ts";
6
+ import { ComponentOptions, Showable, ShowOptions } from "../showable.ts";
7
7
  import { SingleImage, SlowImage } from "../slow-image-sources.ts";
8
- import { Keyframe } from "../interpolate.ts";
8
+ import { TimedKeyframe } from "../interpolate.ts";
9
9
 
10
10
  /**
11
11
  * Standard registry component: draws a single image loaded from a URL.
@@ -18,7 +18,7 @@ import { Keyframe } from "../interpolate.ts";
18
18
  * load. The dest-rect schedule is interpolated so you can animate placement.
19
19
  */
20
20
  export class SingleImageComponent implements Showable {
21
- readonly registryKey = "Static Image";
21
+ readonly registryKey: string;
22
22
  readonly urlSchedule = new StringScheduleInfo("URL", "");
23
23
  readonly destRectSchedule = new RectangleScheduleInfo("Dest Rect", {
24
24
  x: 1,
@@ -27,15 +27,17 @@ export class SingleImageComponent implements Showable {
27
27
  height: 7,
28
28
  });
29
29
  readonly schedules = [this.urlSchedule, this.destRectSchedule] as const;
30
- readonly description = "Static Image";
30
+ readonly description: string;
31
31
  readonly duration = 0;
32
32
  #image: SingleImage | undefined;
33
33
  constructor(
34
34
  initialValues: {
35
- url?: string | readonly Keyframe<string>[];
36
- destRect?: ReadOnlyRect | readonly Keyframe<ReadOnlyRect>[];
37
- } = {},
35
+ url?: string | readonly TimedKeyframe<string>[];
36
+ destRect?: ReadOnlyRect | readonly TimedKeyframe<ReadOnlyRect>[];
37
+ } & ComponentOptions = {},
38
38
  ) {
39
+ this.description = initialValues.description ?? "Static Image";
40
+ this.registryKey = initialValues.registryKey ?? "Static Image";
39
41
  if (initialValues.url !== undefined) {
40
42
  this.urlSchedule.set(initialValues.url);
41
43
  }
@@ -1,5 +1,7 @@
1
1
  import { BinaryInserter } from "../binary-search.ts";
2
2
  import {
3
+ ComponentOptions,
4
+ readComponentOptions,
3
5
  Scalar,
4
6
  ScalarInfo,
5
7
  ScheduleInfo,
@@ -151,7 +153,20 @@ export class InParallelComponent implements Showable, ShowableParent {
151
153
  * TextComponent and ArrowComponent both set this to `undefined` to make show() simpler.
152
154
  */
153
155
  readonly replaceableComponents: Showable["replaceableComponents"];
154
- constructor(readonly description: string) {
156
+ readonly description: string;
157
+ /**
158
+ * @param options Its name, or {@link ComponentOptions}: its name and its registry key.
159
+ */
160
+ constructor(options: string | ComponentOptions) {
161
+ const { description, registryKey } = readComponentOptions(
162
+ options,
163
+ "In Parallel",
164
+ );
165
+ this.description = description;
166
+ // Not a declared member: then every subclass that has its own registryKey, in this library
167
+ // and in projects, would need `override` (noImplicitOverride). A subclass's own field
168
+ // still wins, since fields are set after this constructor runs.
169
+ if (registryKey !== undefined) (this as Showable).registryKey = registryKey;
155
170
  const get = (): Showable[] => [...this.#replaceableChildren];
156
171
  const replace = (newItems: readonly Showable[]) => {
157
172
  this.#replaceableChildren.forEach((child) => {
@@ -38,13 +38,15 @@ import type { ComponentRegistryEntry } from "./registry.ts";
38
38
  */
39
39
  export class InSeriesComponent extends InParallelComponent {
40
40
  static readonly TRANSITION = Symbol("Transition");
41
- readonly registryKey = "In Series";
41
+ readonly registryKey: string;
42
42
  constructor(
43
43
  initialValues: {
44
44
  description?: string;
45
+ registryKey?: string;
45
46
  } = {},
46
47
  ) {
47
48
  super(initialValues.description ?? "In Series");
49
+ this.registryKey = initialValues.registryKey ?? "In Series";
48
50
  }
49
51
  /**
50
52
  * Display the children one after another, sorted by zIndex.
@@ -1,3 +1,4 @@
1
+ import { ComponentOptions, readComponentOptions } from "../showable.ts";
1
2
  import { InParallelComponent, ParallelChildInfo } from "./in-parallel.ts";
2
3
 
3
4
  /**
@@ -24,8 +25,9 @@ export class ComponentWithLiveDuration extends InParallelComponent {
24
25
  protected override recomputeDuration(children: readonly ParallelChildInfo[]) {
25
26
  return this.#requestedDuration;
26
27
  }
27
- constructor(description: string, duration: number) {
28
- super(description);
28
+ /** @param options Its name, or {@link ComponentOptions}. */
29
+ constructor(options: string | ComponentOptions, duration: number) {
30
+ super(readComponentOptions(options, "Live Duration"));
29
31
  this.#requestedDuration = duration;
30
32
  }
31
33
  }