canvas-recorder-lib 0.8.3 → 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 (242) hide show
  1. package/README.md +10 -2
  2. package/dev/canvas-recorder.css +14 -0
  3. package/dev/canvas-recorder.ts +379 -45
  4. package/dev/color-picker.ts +13 -0
  5. package/dev/component-picker.ts +60 -11
  6. package/dev/font-widgets.ts +2 -2
  7. package/dev/format-editor.ts +3 -1
  8. package/dev/fourier-panel.ts +7 -3
  9. package/dev/handwriting-panel.ts +7 -7
  10. package/dev/multi-text-dialog.ts +28 -15
  11. package/dev/player-body.ts +75 -30
  12. package/dev/schedule-helpers.ts +10 -3
  13. package/dev/static-image-panel.ts +4 -4
  14. package/dev/subtitles.ts +170 -0
  15. package/dev/synced-file.ts +34 -0
  16. package/dev/timeline-display.ts +1 -1
  17. package/dev/transcript-align.ts +4 -1
  18. package/dev/transcript-editor.ts +1187 -0
  19. package/dev/transcript-export.ts +90 -0
  20. package/dev/transcript-view.ts +8 -5
  21. package/dev/transcripts.ts +140 -15
  22. package/dev/video-clip-panel.ts +4 -4
  23. package/dist/dev/canvas-recorder.css +14 -0
  24. package/dist/dev/canvas-recorder.js +304 -39
  25. package/dist/dev/canvas-recorder.js.map +1 -1
  26. package/dist/dev/color-picker.d.ts.map +1 -1
  27. package/dist/dev/color-picker.js +15 -0
  28. package/dist/dev/color-picker.js.map +1 -1
  29. package/dist/dev/component-picker.d.ts +2 -1
  30. package/dist/dev/component-picker.d.ts.map +1 -1
  31. package/dist/dev/component-picker.js +56 -11
  32. package/dist/dev/component-picker.js.map +1 -1
  33. package/dist/dev/font-widgets.d.ts +2 -2
  34. package/dist/dev/font-widgets.d.ts.map +1 -1
  35. package/dist/dev/font-widgets.js.map +1 -1
  36. package/dist/dev/format-editor.d.ts.map +1 -1
  37. package/dist/dev/format-editor.js +3 -1
  38. package/dist/dev/format-editor.js.map +1 -1
  39. package/dist/dev/fourier-panel.d.ts.map +1 -1
  40. package/dist/dev/fourier-panel.js +4 -3
  41. package/dist/dev/fourier-panel.js.map +1 -1
  42. package/dist/dev/handwriting-panel.d.ts +4 -4
  43. package/dist/dev/handwriting-panel.d.ts.map +1 -1
  44. package/dist/dev/handwriting-panel.js.map +1 -1
  45. package/dist/dev/multi-text-dialog.d.ts.map +1 -1
  46. package/dist/dev/multi-text-dialog.js +23 -12
  47. package/dist/dev/multi-text-dialog.js.map +1 -1
  48. package/dist/dev/player-body.d.ts +1 -1
  49. package/dist/dev/player-body.d.ts.map +1 -1
  50. package/dist/dev/player-body.js +75 -30
  51. package/dist/dev/player-body.js.map +1 -1
  52. package/dist/dev/schedule-helpers.d.ts.map +1 -1
  53. package/dist/dev/schedule-helpers.js +4 -2
  54. package/dist/dev/schedule-helpers.js.map +1 -1
  55. package/dist/dev/static-image-panel.d.ts +3 -3
  56. package/dist/dev/static-image-panel.d.ts.map +1 -1
  57. package/dist/dev/subtitles.d.ts +36 -0
  58. package/dist/dev/subtitles.d.ts.map +1 -0
  59. package/dist/dev/subtitles.js +135 -0
  60. package/dist/dev/subtitles.js.map +1 -0
  61. package/dist/dev/synced-file.d.ts +14 -0
  62. package/dist/dev/synced-file.d.ts.map +1 -1
  63. package/dist/dev/synced-file.js +22 -0
  64. package/dist/dev/synced-file.js.map +1 -1
  65. package/dist/dev/timeline-display.d.ts +5 -0
  66. package/dist/dev/timeline-display.d.ts.map +1 -1
  67. package/dist/dev/timeline-display.js +1 -1
  68. package/dist/dev/timeline-display.js.map +1 -1
  69. package/dist/dev/transcript-align.d.ts +3 -1
  70. package/dist/dev/transcript-align.d.ts.map +1 -1
  71. package/dist/dev/transcript-align.js +2 -0
  72. package/dist/dev/transcript-align.js.map +1 -1
  73. package/dist/dev/transcript-editor.d.ts +36 -0
  74. package/dist/dev/transcript-editor.d.ts.map +1 -0
  75. package/dist/dev/transcript-editor.js +948 -0
  76. package/dist/dev/transcript-editor.js.map +1 -0
  77. package/dist/dev/transcript-export.d.ts +21 -0
  78. package/dist/dev/transcript-export.d.ts.map +1 -1
  79. package/dist/dev/transcript-export.js +65 -0
  80. package/dist/dev/transcript-export.js.map +1 -1
  81. package/dist/dev/transcript-view.d.ts +2 -0
  82. package/dist/dev/transcript-view.d.ts.map +1 -1
  83. package/dist/dev/transcript-view.js +1 -1
  84. package/dist/dev/transcript-view.js.map +1 -1
  85. package/dist/dev/transcripts.d.ts +18 -1
  86. package/dist/dev/transcripts.d.ts.map +1 -1
  87. package/dist/dev/transcripts.js +102 -12
  88. package/dist/dev/transcripts.js.map +1 -1
  89. package/dist/dev/video-clip-panel.d.ts +3 -3
  90. package/dist/dev/video-clip-panel.d.ts.map +1 -1
  91. package/dist/lib/index.d.ts +1 -0
  92. package/dist/lib/index.d.ts.map +1 -1
  93. package/dist/lib/index.js +1 -0
  94. package/dist/lib/index.js.map +1 -1
  95. package/dist/src/glib/line-font.d.ts +6 -0
  96. package/dist/src/glib/line-font.d.ts.map +1 -1
  97. package/dist/src/glib/line-font.js +9 -0
  98. package/dist/src/glib/line-font.js.map +1 -1
  99. package/dist/src/glib/path-shape.d.ts +16 -0
  100. package/dist/src/glib/path-shape.d.ts.map +1 -1
  101. package/dist/src/glib/path-shape.js +23 -0
  102. package/dist/src/glib/path-shape.js.map +1 -1
  103. package/dist/src/glib/transforms.d.ts +9 -0
  104. package/dist/src/glib/transforms.d.ts.map +1 -1
  105. package/dist/src/glib/transforms.js +7 -4
  106. package/dist/src/glib/transforms.js.map +1 -1
  107. package/dist/src/interpolate.d.ts +17 -10
  108. package/dist/src/interpolate.d.ts.map +1 -1
  109. package/dist/src/interpolate.js +1 -17
  110. package/dist/src/interpolate.js.map +1 -1
  111. package/dist/src/morph-animation.js +1 -1
  112. package/dist/src/morph-animation.js.map +1 -1
  113. package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
  114. package/dist/src/peano-fourier/fourier-shared.js +4 -2
  115. package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
  116. package/dist/src/schedule-helper.d.ts +50 -28
  117. package/dist/src/schedule-helper.d.ts.map +1 -1
  118. package/dist/src/schedule-helper.js +22 -0
  119. package/dist/src/schedule-helper.js.map +1 -1
  120. package/dist/src/showable.d.ts +57 -10
  121. package/dist/src/showable.d.ts.map +1 -1
  122. package/dist/src/showable.js +19 -0
  123. package/dist/src/showable.js.map +1 -1
  124. package/dist/src/slide-components/arrow.d.ts +4 -4
  125. package/dist/src/slide-components/arrow.d.ts.map +1 -1
  126. package/dist/src/slide-components/cross-fade-transition.d.ts +2 -1
  127. package/dist/src/slide-components/cross-fade-transition.d.ts.map +1 -1
  128. package/dist/src/slide-components/cross-fade-transition.js +2 -1
  129. package/dist/src/slide-components/cross-fade-transition.js.map +1 -1
  130. package/dist/src/slide-components/duration-agnostic.d.ts +3 -2
  131. package/dist/src/slide-components/duration-agnostic.d.ts.map +1 -1
  132. package/dist/src/slide-components/duration-agnostic.js +4 -2
  133. package/dist/src/slide-components/duration-agnostic.js.map +1 -1
  134. package/dist/src/slide-components/fixed-duration.d.ts +3 -1
  135. package/dist/src/slide-components/fixed-duration.d.ts.map +1 -1
  136. package/dist/src/slide-components/fixed-duration.js +4 -2
  137. package/dist/src/slide-components/fixed-duration.js.map +1 -1
  138. package/dist/src/slide-components/fourier.d.ts +19 -12
  139. package/dist/src/slide-components/fourier.d.ts.map +1 -1
  140. package/dist/src/slide-components/fourier.js +70 -22
  141. package/dist/src/slide-components/fourier.js.map +1 -1
  142. package/dist/src/slide-components/function-graph.d.ts +4 -3
  143. package/dist/src/slide-components/function-graph.d.ts.map +1 -1
  144. package/dist/src/slide-components/function-graph.js +6 -2
  145. package/dist/src/slide-components/function-graph.js.map +1 -1
  146. package/dist/src/slide-components/halftone-shadow.d.ts +8 -7
  147. package/dist/src/slide-components/halftone-shadow.d.ts.map +1 -1
  148. package/dist/src/slide-components/halftone-shadow.js +2 -1
  149. package/dist/src/slide-components/halftone-shadow.js.map +1 -1
  150. package/dist/src/slide-components/handwriting-effect.d.ts +8 -6
  151. package/dist/src/slide-components/handwriting-effect.d.ts.map +1 -1
  152. package/dist/src/slide-components/handwriting-effect.js +4 -2
  153. package/dist/src/slide-components/handwriting-effect.js.map +1 -1
  154. package/dist/src/slide-components/hold.d.ts +4 -2
  155. package/dist/src/slide-components/hold.d.ts.map +1 -1
  156. package/dist/src/slide-components/hold.js +4 -2
  157. package/dist/src/slide-components/hold.js.map +1 -1
  158. package/dist/src/slide-components/image.d.ts +7 -7
  159. package/dist/src/slide-components/image.d.ts.map +1 -1
  160. package/dist/src/slide-components/image.js +4 -2
  161. package/dist/src/slide-components/image.js.map +1 -1
  162. package/dist/src/slide-components/in-parallel.d.ts +6 -3
  163. package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
  164. package/dist/src/slide-components/in-parallel.js +12 -2
  165. package/dist/src/slide-components/in-parallel.js.map +1 -1
  166. package/dist/src/slide-components/in-series.d.ts +2 -1
  167. package/dist/src/slide-components/in-series.d.ts.map +1 -1
  168. package/dist/src/slide-components/in-series.js +2 -1
  169. package/dist/src/slide-components/in-series.js.map +1 -1
  170. package/dist/src/slide-components/live-duration.d.ts +3 -1
  171. package/dist/src/slide-components/live-duration.d.ts.map +1 -1
  172. package/dist/src/slide-components/live-duration.js +4 -2
  173. package/dist/src/slide-components/live-duration.js.map +1 -1
  174. package/dist/src/slide-components/multi-text.d.ts +39 -26
  175. package/dist/src/slide-components/multi-text.d.ts.map +1 -1
  176. package/dist/src/slide-components/multi-text.js +44 -29
  177. package/dist/src/slide-components/multi-text.js.map +1 -1
  178. package/dist/src/slide-components/rectangle.d.ts +5 -4
  179. package/dist/src/slide-components/rectangle.d.ts.map +1 -1
  180. package/dist/src/slide-components/rectangle.js +2 -1
  181. package/dist/src/slide-components/rectangle.js.map +1 -1
  182. package/dist/src/slide-components/registry.d.ts +5 -0
  183. package/dist/src/slide-components/registry.d.ts.map +1 -1
  184. package/dist/src/slide-components/registry.js +28 -27
  185. package/dist/src/slide-components/registry.js.map +1 -1
  186. package/dist/src/slide-components/show-error.d.ts.map +1 -1
  187. package/dist/src/slide-components/show-error.js +3 -2
  188. package/dist/src/slide-components/show-error.js.map +1 -1
  189. package/dist/src/slide-components/simple-text.d.ts +11 -10
  190. package/dist/src/slide-components/simple-text.d.ts.map +1 -1
  191. package/dist/src/slide-components/simple-text.js +5 -3
  192. package/dist/src/slide-components/simple-text.js.map +1 -1
  193. package/dist/src/slide-components/slide-component.d.ts +14 -13
  194. package/dist/src/slide-components/slide-component.d.ts.map +1 -1
  195. package/dist/src/slide-components/slide-component.js +2 -1
  196. package/dist/src/slide-components/slide-component.js.map +1 -1
  197. package/dist/src/slide-components/slide-left.d.ts +2 -1
  198. package/dist/src/slide-components/slide-left.d.ts.map +1 -1
  199. package/dist/src/slide-components/slide-left.js +2 -1
  200. package/dist/src/slide-components/slide-left.js.map +1 -1
  201. package/dist/src/slide-components/text-effect.d.ts +9 -1
  202. package/dist/src/slide-components/text-effect.d.ts.map +1 -1
  203. package/dist/src/slide-components/text-effect.js.map +1 -1
  204. package/dist/src/slide-components/traditional-text.d.ts +8 -8
  205. package/dist/src/slide-components/traditional-text.d.ts.map +1 -1
  206. package/dist/src/slide-components/video-clip.d.ts +4 -3
  207. package/dist/src/slide-components/video-clip.d.ts.map +1 -1
  208. package/dist/src/slide-components/video-clip.js +2 -1
  209. package/dist/src/slide-components/video-clip.js.map +1 -1
  210. package/lib/index.ts +1 -0
  211. package/package.json +2 -2
  212. package/src/glib/line-font.ts +9 -0
  213. package/src/glib/path-shape.ts +35 -0
  214. package/src/glib/transforms.ts +7 -4
  215. package/src/interpolate.ts +18 -27
  216. package/src/morph-animation.ts +1 -1
  217. package/src/peano-fourier/fourier-shared.ts +4 -2
  218. package/src/schedule-helper.ts +50 -28
  219. package/src/showable.ts +79 -10
  220. package/src/slide-components/arrow.ts +4 -4
  221. package/src/slide-components/cross-fade-transition.ts +9 -2
  222. package/src/slide-components/duration-agnostic.ts +4 -3
  223. package/src/slide-components/fixed-duration.ts +4 -2
  224. package/src/slide-components/fourier.ts +89 -32
  225. package/src/slide-components/function-graph.ts +7 -3
  226. package/src/slide-components/halftone-shadow.ts +9 -7
  227. package/src/slide-components/handwriting-effect.ts +8 -6
  228. package/src/slide-components/hold.ts +18 -4
  229. package/src/slide-components/image.ts +9 -7
  230. package/src/slide-components/in-parallel.ts +16 -1
  231. package/src/slide-components/in-series.ts +3 -1
  232. package/src/slide-components/live-duration.ts +4 -2
  233. package/src/slide-components/multi-text.ts +71 -44
  234. package/src/slide-components/rectangle.ts +6 -4
  235. package/src/slide-components/registry.ts +33 -27
  236. package/src/slide-components/show-error.ts +4 -2
  237. package/src/slide-components/simple-text.ts +22 -12
  238. package/src/slide-components/slide-component.ts +15 -13
  239. package/src/slide-components/slide-left.ts +9 -2
  240. package/src/slide-components/text-effect.ts +9 -0
  241. package/src/slide-components/traditional-text.ts +8 -8
  242. 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,16 +83,43 @@ 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 };
@@ -100,6 +127,8 @@ export function parseTermGroups(text: string): TermGroups {
100
127
  const emptyGroups: number[] = [];
101
128
  /** Where each term was first added, to report repeats. */
102
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 }[] = [];
103
132
  const groups = text.split(",").map((piece, groupIndex) => {
104
133
  const groupNumber = groupIndex + 1;
105
134
  const group: number[] = [];
@@ -108,11 +137,7 @@ export function parseTermGroups(text: string): TermGroups {
108
137
  if (earlier === undefined) {
109
138
  firstGroup.set(term, groupNumber);
110
139
  } else {
111
- warnings.push(
112
- earlier === groupNumber
113
- ? `Term ${term} is in group ${groupNumber} twice.`
114
- : `Term ${term} is in group ${earlier} and again in group ${groupNumber}. Terms are only ever added, so the second time does nothing.`,
115
- );
140
+ repeats.push({ term, earlier, groupNumber });
116
141
  }
117
142
  group.push(term);
118
143
  };
@@ -123,8 +148,17 @@ export function parseTermGroups(text: string): TermGroups {
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,18 +170,28 @@ 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
+ }
144
193
  if (emptyGroups.length) {
145
- // "2", "2 and 3", "3, 5 and 7", "2, 3, 4, 5, 6, 7 and 4 more".
146
- const shown = emptyGroups.slice(0, 6).map(String);
147
- const more = emptyGroups.length - shown.length;
148
- if (more > 0) shown.push(`${more} more`);
149
- const last = shown.pop()!;
150
- const list = shown.length ? `${shown.join(", ")} and ${last}` : last;
194
+ const list = listWithMore(emptyGroups);
151
195
  const one = emptyGroups.length === 1;
152
196
  warnings.push(
153
197
  `${one ? "Group" : "Groups"} ${list} ${one ? "is" : "are"} empty, so ${one ? "that step adds" : "those steps add"} nothing.`,
@@ -173,11 +217,9 @@ export function checkTermGroups(
173
217
  }
174
218
  if (missing.size) {
175
219
  const list = [...missing].sort((a, b) => a - b);
176
- const shown =
177
- list.length > 6 ? `${list.slice(0, 6).join(", ")}, …` : list.join(", ");
178
220
  warnings.push(
179
221
  `This source has ${terms.length} terms, numbered 0 to ${terms.length - 1}. ` +
180
- `Left out: ${shown}.`,
222
+ `Left out: ${listWithMore(list)}.`,
181
223
  );
182
224
  }
183
225
  // The frequency 0 term is the shape's center. samplesToFourier() leaves it
@@ -240,7 +282,7 @@ export function orderTerms(
240
282
  * Pure.
241
283
  */
242
284
  export function checkStepRange(
243
- step: readonly Keyframe<number>[],
285
+ step: readonly TimedKeyframe<number>[],
244
286
  groupCount: number,
245
287
  ): string[] {
246
288
  const shown = step.map(({ value }) => value).filter((value) => value >= 0);
@@ -308,7 +350,7 @@ function boundsOf(samples: readonly Complex[]): ReadOnlyRect {
308
350
  * away and starts over, which is fine as long as it's rare.
309
351
  */
310
352
  export class FourierComponent extends DurationAgnosticComponent {
311
- readonly registryKey = "Fourier";
353
+ readonly registryKey: string;
312
354
 
313
355
  /**
314
356
  * The curves the Source field can choose from, by name.
@@ -356,18 +398,20 @@ export class FourierComponent extends DurationAgnosticComponent {
356
398
  constructor(
357
399
  initialValues: {
358
400
  description?: string;
401
+ registryKey?: string;
359
402
  source?: string;
360
- termGroups?: string | Keyframe<string>[];
361
- step?: number | Keyframe<number>[];
362
- destRect?: ReadOnlyRect | Keyframe<ReadOnlyRect>[];
363
- fillColor?: string | Keyframe<string>[];
364
- strokeColor?: string | Keyframe<string>[];
365
- 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>[];
366
409
  /** How long to ask the parent for. The default covers the default Step schedule. */
367
410
  minDuration?: number;
368
411
  } = {},
369
412
  ) {
370
413
  super(initialValues.description ?? "Fourier");
414
+ this.registryKey = initialValues.registryKey ?? "Fourier";
371
415
  const names = [...FourierComponent.sources.keys()];
372
416
  this.sourceSchedule = new SelectScheduleInfo(
373
417
  "Source",
@@ -465,7 +509,7 @@ export class FourierComponent extends DurationAgnosticComponent {
465
509
  return cached;
466
510
  const source = this.termsFor(name);
467
511
  if (typeof source === "string") return source;
468
- const { groups } = parseTermGroups(termGroups);
512
+ const { groups } = parseTermGroups(termGroups, source.terms.length);
469
513
  const ordered = orderTerms(source.terms, groups);
470
514
  const rules =
471
515
  ordered.keyframes.length < 2
@@ -510,6 +554,7 @@ export class FourierComponent extends DurationAgnosticComponent {
510
554
  /**
511
555
  * Draw the curve: fill, then stroke. It's already in place, in canvas
512
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.
513
558
  *
514
559
  * Override this to draw it differently, e.g. stroked with strokeColors()
515
560
  * like the Sierpiński video.
@@ -524,9 +569,13 @@ export class FourierComponent extends DurationAgnosticComponent {
524
569
  // itself, the fill alternates instead of piling up.
525
570
  context.fill(path, "evenodd");
526
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;
527
576
  context.lineCap = "round";
528
577
  context.lineJoin = "round";
529
- context.lineWidth = this.lineWidthSchedule.at(timeInMs);
578
+ context.lineWidth = lineWidth;
530
579
  context.strokeStyle = this.strokeColorSchedule.at(timeInMs);
531
580
  context.stroke(path);
532
581
  }
@@ -536,9 +585,17 @@ export class FourierComponent extends DurationAgnosticComponent {
536
585
 
537
586
  // Cheap to create: nothing is computed until a component draws one.
538
587
 
539
- FourierComponent.sources.set("Star", {
540
- path: makePolygon(5, 1, undefined, 0).transform(new DOMMatrix().rotate(-90)),
541
- });
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
+ }
542
599
  FourierComponent.sources.set("Square", {
543
600
  path: "M -1,-1 L 1,-1 L 1,1 L -1,1 Z",
544
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",
@@ -2,7 +2,7 @@ import { canvasRecorder } from "../../lib/main-control.ts";
2
2
  import { ColorScheduleInfo, NumberScheduleInfo } from "../schedule-helper.ts";
3
3
  import { Showable, ShowOptions } from "../showable.ts";
4
4
  import { InParallelComponent } from "./in-parallel.ts";
5
- import { Keyframe } from "../interpolate.ts";
5
+ import { TimedKeyframe } from "../interpolate.ts";
6
6
 
7
7
  /** At 100% opacity the dot radius reaches this fraction of the half-cell width. */
8
8
  const HALFTONE_MAX_RADIUS_FACTOR = 0.9;
@@ -20,7 +20,7 @@ const HALFTONE_MAX_RADIUS_FACTOR = 0.9;
20
20
  * Showable in the constructor to add it as a fixed child.
21
21
  */
22
22
  export class HalftoneShadowComponent extends InParallelComponent {
23
- readonly registryKey = "Halftone Shadow";
23
+ readonly registryKey: string;
24
24
  readonly dotColorSchedule = new ColorScheduleInfo("Dot Color", "#ccc");
25
25
  readonly backgroundColorSchedule = new ColorScheduleInfo(
26
26
  "Background Color",
@@ -39,11 +39,12 @@ export class HalftoneShadowComponent extends InParallelComponent {
39
39
  initialValues: {
40
40
  base?: Showable;
41
41
  description?: string;
42
- dotColor?: string | readonly Keyframe<string>[];
43
- backgroundColor?: string | readonly Keyframe<string>[];
44
- dx?: number | readonly Keyframe<number>[];
45
- dy?: number | readonly Keyframe<number>[];
46
- 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>[];
47
48
  } = {},
48
49
  ) {
49
50
  const { base } = initialValues;
@@ -51,6 +52,7 @@ export class HalftoneShadowComponent extends InParallelComponent {
51
52
  initialValues.description ??
52
53
  (base ? `${base.description} » shadow` : "Halftone Shadow"),
53
54
  );
55
+ this.registryKey = initialValues.registryKey ?? "Halftone Shadow";
54
56
  this.schedules.push(
55
57
  this.dotColorSchedule,
56
58
  this.backgroundColorSchedule,
@@ -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
  }