canvas-recorder-lib 0.7.1 → 0.7.2
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.
- package/README.md +38 -8
- package/dev/audio-builder.ts +5 -1
- package/dev/canvas-recorder.css +15 -4
- package/dev/canvas-recorder.ts +255 -82
- package/dev/delay-files.ts +1 -1
- package/dev/format-editor.ts +7 -2
- package/dev/fourier-panel.ts +11 -3
- package/dev/handwriting-panel.ts +14 -9
- package/dev/local-file-row.ts +12 -5
- package/dev/multi-text-dialog.ts +15 -6
- package/dev/multi-text-panel.ts +6 -2
- package/dev/player-body.ts +4 -0
- package/dev/schedule-helpers.ts +11 -4
- package/dev/sound-clips.ts +4 -1
- package/dev/soundtrack.ts +42 -11
- package/dev/split-dialog.ts +49 -19
- package/dev/static-image-panel.ts +17 -5
- package/dev/synced-file.ts +4 -5
- package/dev/timeline-display.ts +152 -50
- package/dev/transcribe-core.ts +48 -17
- package/dev/transcribe-worker.ts +20 -9
- package/dev/transcript-align.ts +95 -20
- package/dev/transcript-export.ts +18 -7
- package/dev/transcript-view.ts +78 -22
- package/dev/transcripts.ts +43 -23
- package/dev/video-clip-panel.ts +64 -18
- package/dev/voice/chirp.ts +21 -5
- package/dev/voice/folder.ts +22 -7
- package/dev/voice/voice-panel.ts +34 -10
- package/dev/voice/voice-recorder.ts +74 -18
- package/dist/dev/audio-builder.js.map +1 -1
- package/dist/dev/canvas-recorder.css +15 -4
- package/dist/dev/canvas-recorder.js +165 -42
- package/dist/dev/canvas-recorder.js.map +1 -1
- package/dist/dev/format-editor.d.ts.map +1 -1
- package/dist/dev/format-editor.js.map +1 -1
- package/dist/dev/fourier-panel.d.ts.map +1 -1
- package/dist/dev/fourier-panel.js.map +1 -1
- package/dist/dev/handwriting-panel.d.ts.map +1 -1
- package/dist/dev/handwriting-panel.js +10 -8
- package/dist/dev/handwriting-panel.js.map +1 -1
- package/dist/dev/local-file-row.d.ts.map +1 -1
- package/dist/dev/local-file-row.js +12 -4
- package/dist/dev/local-file-row.js.map +1 -1
- package/dist/dev/multi-text-dialog.d.ts.map +1 -1
- package/dist/dev/multi-text-dialog.js +4 -2
- package/dist/dev/multi-text-dialog.js.map +1 -1
- package/dist/dev/multi-text-panel.d.ts.map +1 -1
- package/dist/dev/multi-text-panel.js +2 -1
- package/dist/dev/multi-text-panel.js.map +1 -1
- package/dist/dev/player-body.d.ts +1 -1
- package/dist/dev/player-body.d.ts.map +1 -1
- package/dist/dev/player-body.js +4 -0
- package/dist/dev/player-body.js.map +1 -1
- package/dist/dev/schedule-helpers.d.ts.map +1 -1
- package/dist/dev/schedule-helpers.js +4 -1
- package/dist/dev/schedule-helpers.js.map +1 -1
- package/dist/dev/sound-clips.d.ts.map +1 -1
- package/dist/dev/sound-clips.js.map +1 -1
- package/dist/dev/soundtrack.d.ts +12 -0
- package/dist/dev/soundtrack.d.ts.map +1 -1
- package/dist/dev/soundtrack.js +33 -7
- package/dist/dev/soundtrack.js.map +1 -1
- package/dist/dev/split-dialog.d.ts.map +1 -1
- package/dist/dev/split-dialog.js +17 -10
- package/dist/dev/split-dialog.js.map +1 -1
- package/dist/dev/static-image-panel.d.ts.map +1 -1
- package/dist/dev/static-image-panel.js +7 -3
- package/dist/dev/static-image-panel.js.map +1 -1
- package/dist/dev/synced-file.d.ts.map +1 -1
- package/dist/dev/synced-file.js.map +1 -1
- package/dist/dev/timeline-display.d.ts.map +1 -1
- package/dist/dev/timeline-display.js +62 -17
- package/dist/dev/timeline-display.js.map +1 -1
- package/dist/dev/transcribe-core.d.ts.map +1 -1
- package/dist/dev/transcribe-core.js +13 -3
- package/dist/dev/transcribe-core.js.map +1 -1
- package/dist/dev/transcribe-worker.d.ts.map +1 -1
- package/dist/dev/transcribe-worker.js +9 -3
- package/dist/dev/transcribe-worker.js.map +1 -1
- package/dist/dev/transcript-align.d.ts.map +1 -1
- package/dist/dev/transcript-align.js +52 -9
- package/dist/dev/transcript-align.js.map +1 -1
- package/dist/dev/transcript-export.d.ts.map +1 -1
- package/dist/dev/transcript-export.js +10 -4
- package/dist/dev/transcript-export.js.map +1 -1
- package/dist/dev/transcript-view.d.ts +2 -0
- package/dist/dev/transcript-view.d.ts.map +1 -1
- package/dist/dev/transcript-view.js +32 -11
- package/dist/dev/transcript-view.js.map +1 -1
- package/dist/dev/transcripts.d.ts.map +1 -1
- package/dist/dev/transcripts.js +5 -3
- package/dist/dev/transcripts.js.map +1 -1
- package/dist/dev/video-clip-panel.d.ts.map +1 -1
- package/dist/dev/video-clip-panel.js +25 -8
- package/dist/dev/video-clip-panel.js.map +1 -1
- package/dist/dev/voice/chirp.d.ts.map +1 -1
- package/dist/dev/voice/chirp.js +5 -1
- package/dist/dev/voice/chirp.js.map +1 -1
- package/dist/dev/voice/folder.d.ts.map +1 -1
- package/dist/dev/voice/folder.js +1 -1
- package/dist/dev/voice/folder.js.map +1 -1
- package/dist/dev/voice/voice-panel.d.ts.map +1 -1
- package/dist/dev/voice/voice-panel.js +15 -6
- package/dist/dev/voice/voice-panel.js.map +1 -1
- package/dist/dev/voice/voice-recorder.d.ts.map +1 -1
- package/dist/dev/voice/voice-recorder.js +34 -9
- package/dist/dev/voice/voice-recorder.js.map +1 -1
- package/dist/lib/main-control.d.ts.map +1 -1
- package/dist/lib/main-control.js.map +1 -1
- package/dist/src/corner-rounder.d.ts.map +1 -1
- package/dist/src/corner-rounder.js +1 -1
- package/dist/src/corner-rounder.js.map +1 -1
- package/dist/src/local-files.d.ts.map +1 -1
- package/dist/src/local-files.js +5 -2
- package/dist/src/local-files.js.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.d.ts +7 -0
- package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.js +8 -1
- package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
- package/dist/src/slide-components/fourier.d.ts.map +1 -1
- package/dist/src/slide-components/fourier.js +12 -4
- package/dist/src/slide-components/fourier.js.map +1 -1
- package/dist/src/slide-components/image.d.ts.map +1 -1
- package/dist/src/slide-components/image.js +1 -1
- package/dist/src/slide-components/image.js.map +1 -1
- package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
- package/dist/src/slide-components/in-parallel.js.map +1 -1
- package/dist/src/slide-components/multi-text.d.ts.map +1 -1
- package/dist/src/slide-components/multi-text.js +1 -1
- package/dist/src/slide-components/multi-text.js.map +1 -1
- package/dist/src/slide-components/rectangle.d.ts.map +1 -1
- package/dist/src/slide-components/rectangle.js +1 -1
- package/dist/src/slide-components/rectangle.js.map +1 -1
- package/dist/src/slide-components/registry.js.map +1 -1
- package/dist/src/slide-components/serialize.d.ts.map +1 -1
- package/dist/src/slide-components/serialize.js +2 -1
- package/dist/src/slide-components/serialize.js.map +1 -1
- package/dist/src/slide-components/split-video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/split-video-clip.js +4 -1
- package/dist/src/slide-components/split-video-clip.js.map +1 -1
- package/dist/src/slide-components/video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/video-clip.js +7 -4
- package/dist/src/slide-components/video-clip.js.map +1 -1
- package/dist/src/slide-components/video-info.d.ts.map +1 -1
- package/dist/src/slide-components/video-info.js.map +1 -1
- package/dist/src/slow-image-sources.d.ts.map +1 -1
- package/dist/src/slow-image-sources.js +1 -1
- package/dist/src/slow-image-sources.js.map +1 -1
- package/dist/src/snapshot.d.ts.map +1 -1
- package/dist/src/snapshot.js +1 -1
- package/dist/src/snapshot.js.map +1 -1
- package/dist/src/utility.d.ts.map +1 -1
- package/dist/src/utility.js +1 -3
- package/dist/src/utility.js.map +1 -1
- package/lib/main-control.ts +3 -1
- package/package.json +4 -1
- package/src/corner-rounder.ts +5 -12
- package/src/glib/letters-base.ts +1 -1
- package/src/local-files.ts +19 -6
- package/src/peano-fourier/fourier-shared.ts +8 -1
- package/src/slide-components/fourier.ts +32 -10
- package/src/slide-components/image.ts +4 -1
- package/src/slide-components/in-parallel.ts +1 -2
- package/src/slide-components/multi-text.ts +17 -4
- package/src/slide-components/rectangle.ts +4 -1
- package/src/slide-components/registry.ts +1 -1
- package/src/slide-components/serialize.ts +4 -1
- package/src/slide-components/split-video-clip.ts +4 -1
- package/src/slide-components/video-clip.ts +21 -8
- package/src/slide-components/video-info.ts +4 -1
- package/src/slow-image-sources.ts +5 -1
- package/src/snapshot.ts +13 -4
- package/src/utility.ts +70 -33
package/src/glib/letters-base.ts
CHANGED
package/src/local-files.ts
CHANGED
|
@@ -122,7 +122,8 @@ async function readRecord(name: string): Promise<HandleRecord | undefined> {
|
|
|
122
122
|
const db = await openDb();
|
|
123
123
|
return new Promise((resolve, reject) => {
|
|
124
124
|
const request = db.transaction(STORE).objectStore(STORE).get(name);
|
|
125
|
-
request.onsuccess = () =>
|
|
125
|
+
request.onsuccess = () =>
|
|
126
|
+
resolve(request.result as HandleRecord | undefined);
|
|
126
127
|
request.onerror = () => reject(request.error);
|
|
127
128
|
});
|
|
128
129
|
}
|
|
@@ -149,7 +150,9 @@ async function writeRecord(record: HandleRecord): Promise<void> {
|
|
|
149
150
|
/** Handles already read from IndexedDB. The list is short, so this never needs trimming. */
|
|
150
151
|
const handles = new Map<string, FileSystemFileHandle>();
|
|
151
152
|
|
|
152
|
-
async function findHandle(
|
|
153
|
+
async function findHandle(
|
|
154
|
+
name: string,
|
|
155
|
+
): Promise<FileSystemFileHandle | undefined> {
|
|
153
156
|
let handle = handles.get(name);
|
|
154
157
|
if (!handle) {
|
|
155
158
|
handle = (await readRecord(name))?.handle;
|
|
@@ -166,7 +169,9 @@ async function findHandle(name: string): Promise<FileSystemFileHandle | undefine
|
|
|
166
169
|
* A file with the same name replaces the old one. That's how a moved file gets fixed:
|
|
167
170
|
* pick it again from its new place.
|
|
168
171
|
*/
|
|
169
|
-
export async function addLocalFile(
|
|
172
|
+
export async function addLocalFile(
|
|
173
|
+
handle: FileSystemFileHandle,
|
|
174
|
+
): Promise<string> {
|
|
170
175
|
await writeRecord({ name: handle.name, handle, addedAt: Date.now() });
|
|
171
176
|
handles.set(handle.name, handle);
|
|
172
177
|
needingPermission.delete(handle.name);
|
|
@@ -186,7 +191,9 @@ export const VIDEO_FILE_TYPES: FilePickerAcceptType[] = [
|
|
|
186
191
|
export const IMAGE_FILE_TYPES: FilePickerAcceptType[] = [
|
|
187
192
|
{
|
|
188
193
|
description: "Image",
|
|
189
|
-
accept: {
|
|
194
|
+
accept: {
|
|
195
|
+
"image/*": [".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".avif"],
|
|
196
|
+
},
|
|
190
197
|
},
|
|
191
198
|
];
|
|
192
199
|
|
|
@@ -357,7 +364,10 @@ export function localFileUrlsIn(showable: Showable): Set<string> {
|
|
|
357
364
|
}
|
|
358
365
|
for (const schedule of current.schedules ?? []) {
|
|
359
366
|
for (const keyframe of schedule.schedule) {
|
|
360
|
-
if (
|
|
367
|
+
if (
|
|
368
|
+
typeof keyframe.value === "string" &&
|
|
369
|
+
isLocalFileUrl(keyframe.value)
|
|
370
|
+
) {
|
|
361
371
|
found.add(keyframe.value);
|
|
362
372
|
}
|
|
363
373
|
}
|
|
@@ -375,7 +385,10 @@ export function localFileUrlsIn(showable: Showable): Set<string> {
|
|
|
375
385
|
* Like `fetch()`, but it also understands local file URLs.
|
|
376
386
|
* Use this anywhere media is read by URL, so local files work there too.
|
|
377
387
|
*/
|
|
378
|
-
export async function fetchMedia(
|
|
388
|
+
export async function fetchMedia(
|
|
389
|
+
url: string,
|
|
390
|
+
init?: RequestInit,
|
|
391
|
+
): Promise<Response> {
|
|
379
392
|
if (isLocalFileUrl(url)) {
|
|
380
393
|
const file = await getLocalFile(url);
|
|
381
394
|
return new Response(init?.method === "HEAD" ? null : file, {
|
|
@@ -93,6 +93,13 @@ export type Complex = [real: number, imaginary: number];
|
|
|
93
93
|
*/
|
|
94
94
|
export const numberOfFourierSamples = 1024;
|
|
95
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Sample a closed curve, ready for {@link samplesToFourier}.
|
|
98
|
+
* @param func A closed curve: `func(1)` is the same point as `func(0)`.
|
|
99
|
+
* @param numSamples A power of 2.
|
|
100
|
+
* @returns The points at `t = i / numSamples`, evenly spaced in `t`.
|
|
101
|
+
* `t = 1` isn't sampled: it would repeat the first point.
|
|
102
|
+
*/
|
|
96
103
|
export function samplesFromParametric(
|
|
97
104
|
func: ParametricFunction,
|
|
98
105
|
numSamples: number = numberOfFourierSamples,
|
|
@@ -102,7 +109,7 @@ export function samplesFromParametric(
|
|
|
102
109
|
}
|
|
103
110
|
const samples: Complex[] = [];
|
|
104
111
|
for (let i = 0; i < numSamples; i++) {
|
|
105
|
-
const t = i /
|
|
112
|
+
const t = i / numSamples;
|
|
106
113
|
const point = func(t);
|
|
107
114
|
samples.push([point.x, point.y]);
|
|
108
115
|
}
|
|
@@ -111,7 +111,9 @@ export function parseTermGroups(text: string): TermGroups {
|
|
|
111
111
|
};
|
|
112
112
|
const tokens = piece.trim().split(/\s+/).filter(Boolean);
|
|
113
113
|
if (tokens.length === 0) {
|
|
114
|
-
warnings.push(
|
|
114
|
+
warnings.push(
|
|
115
|
+
`Group ${groupNumber} is empty, so that step adds nothing.`,
|
|
116
|
+
);
|
|
115
117
|
}
|
|
116
118
|
for (const token of tokens) {
|
|
117
119
|
const single = /^\d+$/.exec(token);
|
|
@@ -154,7 +156,8 @@ export function checkTermGroups(
|
|
|
154
156
|
}
|
|
155
157
|
if (missing.size) {
|
|
156
158
|
const list = [...missing].sort((a, b) => a - b);
|
|
157
|
-
const shown =
|
|
159
|
+
const shown =
|
|
160
|
+
list.length > 6 ? `${list.slice(0, 6).join(", ")}, …` : list.join(", ");
|
|
158
161
|
warnings.push(
|
|
159
162
|
`This source has ${terms.length} terms, numbered 0 to ${terms.length - 1}. ` +
|
|
160
163
|
`Left out: ${shown}.`,
|
|
@@ -166,7 +169,10 @@ export function checkTermGroups(
|
|
|
166
169
|
groups.forEach((group, index) => {
|
|
167
170
|
if (index === 0) return;
|
|
168
171
|
const valid = group.filter((term) => term < terms.length);
|
|
169
|
-
if (
|
|
172
|
+
if (
|
|
173
|
+
valid.length > 0 &&
|
|
174
|
+
valid.every((term) => terms[term].frequency === 0)
|
|
175
|
+
) {
|
|
170
176
|
warnings.push(
|
|
171
177
|
`Group ${index + 1} is only the center (frequency 0), which can't animate on its own. ` +
|
|
172
178
|
`Put it in the first group, or with other terms.`,
|
|
@@ -221,7 +227,9 @@ export function checkStepRange(
|
|
|
221
227
|
): string[] {
|
|
222
228
|
const shown = step.map(({ value }) => value).filter((value) => value >= 0);
|
|
223
229
|
if (shown.length === 0) {
|
|
224
|
-
return [
|
|
230
|
+
return [
|
|
231
|
+
"Step is never 0 or more, so nothing is ever drawn. Negative means hidden.",
|
|
232
|
+
];
|
|
225
233
|
}
|
|
226
234
|
const warnings: string[] = [];
|
|
227
235
|
const low = Math.min(...shown);
|
|
@@ -317,7 +325,10 @@ export class FourierComponent extends DurationAgnosticComponent {
|
|
|
317
325
|
height: 7,
|
|
318
326
|
});
|
|
319
327
|
/** Drawn first, under the stroke. "transparent" skips filling. */
|
|
320
|
-
readonly fillColorSchedule = new ColorScheduleInfo(
|
|
328
|
+
readonly fillColorSchedule = new ColorScheduleInfo(
|
|
329
|
+
"Fill Color",
|
|
330
|
+
"transparent",
|
|
331
|
+
);
|
|
321
332
|
readonly strokeColorSchedule = new ColorScheduleInfo(
|
|
322
333
|
"Stroke Color",
|
|
323
334
|
myRainbow.myBlue,
|
|
@@ -347,7 +358,8 @@ export class FourierComponent extends DurationAgnosticComponent {
|
|
|
347
358
|
);
|
|
348
359
|
if (initialValues.termGroups !== undefined)
|
|
349
360
|
this.termGroupsSchedule.set(initialValues.termGroups);
|
|
350
|
-
if (initialValues.step !== undefined)
|
|
361
|
+
if (initialValues.step !== undefined)
|
|
362
|
+
this.stepSchedule.set(initialValues.step);
|
|
351
363
|
if (initialValues.destRect !== undefined)
|
|
352
364
|
this.destRectSchedule.set(initialValues.destRect);
|
|
353
365
|
if (initialValues.fillColor !== undefined)
|
|
@@ -386,7 +398,9 @@ export class FourierComponent extends DurationAgnosticComponent {
|
|
|
386
398
|
*/
|
|
387
399
|
termsFor(
|
|
388
400
|
name: string,
|
|
389
|
-
):
|
|
401
|
+
):
|
|
402
|
+
| { readonly terms: readonly FourierTerm[]; readonly bounds: ReadOnlyRect }
|
|
403
|
+
| string {
|
|
390
404
|
if (this.#termsCache?.name === name) return this.#termsCache;
|
|
391
405
|
const source = FourierComponent.sources.get(name);
|
|
392
406
|
if (!source) return `Unknown Fourier source:\n"${name}"`;
|
|
@@ -424,13 +438,16 @@ export class FourierComponent extends DurationAgnosticComponent {
|
|
|
424
438
|
|
|
425
439
|
#animationFor(name: string, termGroups: string) {
|
|
426
440
|
const cached = this.#animationCache;
|
|
427
|
-
if (cached?.name === name && cached.termGroups === termGroups)
|
|
441
|
+
if (cached?.name === name && cached.termGroups === termGroups)
|
|
442
|
+
return cached;
|
|
428
443
|
const source = this.termsFor(name);
|
|
429
444
|
if (typeof source === "string") return source;
|
|
430
445
|
const { groups } = parseTermGroups(termGroups);
|
|
431
446
|
const ordered = orderTerms(source.terms, groups);
|
|
432
447
|
const rules =
|
|
433
|
-
ordered.keyframes.length < 2
|
|
448
|
+
ordered.keyframes.length < 2
|
|
449
|
+
? []
|
|
450
|
+
: getAnimationRules(ordered.terms, ordered.keyframes);
|
|
434
451
|
this.#animationCache = { name, termGroups, rules, bounds: source.bounds };
|
|
435
452
|
return this.#animationCache;
|
|
436
453
|
}
|
|
@@ -508,7 +525,12 @@ FourierComponent.sources.set("Heart", {
|
|
|
508
525
|
const θ = 2 * Math.PI * t;
|
|
509
526
|
return {
|
|
510
527
|
x: 16 * Math.sin(θ) ** 3,
|
|
511
|
-
y: -(
|
|
528
|
+
y: -(
|
|
529
|
+
13 * Math.cos(θ) -
|
|
530
|
+
5 * Math.cos(2 * θ) -
|
|
531
|
+
2 * Math.cos(3 * θ) -
|
|
532
|
+
Math.cos(4 * θ)
|
|
533
|
+
),
|
|
512
534
|
};
|
|
513
535
|
},
|
|
514
536
|
});
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ReadOnlyRect } from "phil-lib/misc";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
StringScheduleInfo,
|
|
4
|
+
RectangleScheduleInfo,
|
|
5
|
+
} from "../schedule-helper.ts";
|
|
3
6
|
import { Showable, ShowOptions } from "../showable.ts";
|
|
4
7
|
import { SingleImage, SlowImage } from "../slow-image-sources.ts";
|
|
5
8
|
import { Keyframe } from "../interpolate.ts";
|
|
@@ -191,8 +191,7 @@ export class InParallelComponent implements Showable, ShowableParent {
|
|
|
191
191
|
): void {}
|
|
192
192
|
readonly #replaceableChildren = new Array<Showable>();
|
|
193
193
|
#cached:
|
|
194
|
-
|
|
195
|
-
| undefined;
|
|
194
|
+
{ duration: number; children: readonly ParallelChildInfo[] } | undefined;
|
|
196
195
|
#fromCache() {
|
|
197
196
|
if (!this.#cached) {
|
|
198
197
|
const children = new Array<Mutable<ParallelChildInfo>>();
|
|
@@ -28,7 +28,12 @@ import {
|
|
|
28
28
|
import { DurationAgnosticComponent } from "./duration-agnostic.ts";
|
|
29
29
|
import { ShowChildInfo } from "./in-parallel.ts";
|
|
30
30
|
import { showError } from "./show-error.ts";
|
|
31
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
EffectLetter,
|
|
33
|
+
isTextEffect,
|
|
34
|
+
TextEffect,
|
|
35
|
+
TEXT_EFFECT,
|
|
36
|
+
} from "./text-effect.ts";
|
|
32
37
|
import { Keyframe } from "../interpolate.ts";
|
|
33
38
|
// Type-only: registry.ts imports this module, so a runtime import would be circular.
|
|
34
39
|
import type { ComponentRegistryEntry } from "./registry.ts";
|
|
@@ -87,7 +92,10 @@ function setTextFormatList(
|
|
|
87
92
|
// MARK: Format strings
|
|
88
93
|
|
|
89
94
|
/** One piece of a format string: a format's name, and the text after it. */
|
|
90
|
-
export type FormattedSpan = {
|
|
95
|
+
export type FormattedSpan = {
|
|
96
|
+
readonly format: string;
|
|
97
|
+
readonly content: string;
|
|
98
|
+
};
|
|
91
99
|
|
|
92
100
|
const FORMAT_STRING_SPLITTER = /^⸨([^⸨⸩]*)⸩([^⸨⸩]*)(.*)$/s;
|
|
93
101
|
|
|
@@ -240,7 +248,10 @@ function turn({ x, y }: Point, quarterTurns: QuarterTurns): Point {
|
|
|
240
248
|
}
|
|
241
249
|
|
|
242
250
|
/** The rectangle `rect` covers after turning it about the origin. Exact, since a quarter turn keeps it axis-aligned. */
|
|
243
|
-
function turnRect(
|
|
251
|
+
function turnRect(
|
|
252
|
+
rect: ReadOnlyRect,
|
|
253
|
+
quarterTurns: QuarterTurns,
|
|
254
|
+
): ReadOnlyRect {
|
|
244
255
|
const a = turn({ x: rect.x, y: rect.y }, quarterTurns);
|
|
245
256
|
const b = turn(
|
|
246
257
|
{ x: rect.x + rect.width, y: rect.y + rect.height },
|
|
@@ -468,7 +479,9 @@ export class MultiTextComponent extends DurationAgnosticComponent {
|
|
|
468
479
|
let node: ShowableParent | undefined = this;
|
|
469
480
|
while (node) {
|
|
470
481
|
if (node instanceof MultiTextComponent) {
|
|
471
|
-
names.push(
|
|
482
|
+
names.push(
|
|
483
|
+
...node.#ownFormatters().map((format) => format.nameScalar.value),
|
|
484
|
+
);
|
|
472
485
|
}
|
|
473
486
|
node = node.parent;
|
|
474
487
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Showable, ShowOptions } from "../showable.ts";
|
|
2
2
|
import { Keyframe } from "../interpolate.ts";
|
|
3
3
|
import { ReadOnlyRect } from "phil-lib/misc";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
ColorScheduleInfo,
|
|
6
|
+
RectangleScheduleInfo,
|
|
7
|
+
} from "../schedule-helper.ts";
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Standard registry component: a filled rectangle with an editable color and
|
|
@@ -234,7 +234,7 @@ export const componentRegistry = new Map<string, ComponentRegistryEntry>([
|
|
|
234
234
|
create() {
|
|
235
235
|
return new RectangleComponent();
|
|
236
236
|
},
|
|
237
|
-
description:"A perfect background, outline, or placeholder.",
|
|
237
|
+
description: "A perfect background, outline, or placeholder.",
|
|
238
238
|
isGoodForWrapping: false,
|
|
239
239
|
howToGenerate: { type: "class", class: RectangleComponent },
|
|
240
240
|
},
|
|
@@ -60,7 +60,10 @@ export function buildComponents(snapshot: SerializedChild[]): Showable[] {
|
|
|
60
60
|
if (child.schedules?.length && sc.schedules?.length) {
|
|
61
61
|
applySnapshot(child.schedules, sc.schedules);
|
|
62
62
|
}
|
|
63
|
-
if (
|
|
63
|
+
if (
|
|
64
|
+
child.replaceableComponents !== undefined &&
|
|
65
|
+
sc.components !== undefined
|
|
66
|
+
) {
|
|
64
67
|
child.replaceableComponents.replace(buildComponents(sc.components));
|
|
65
68
|
}
|
|
66
69
|
return [child];
|
|
@@ -122,7 +122,10 @@ export function cutOutOfSoundClip(
|
|
|
122
122
|
const rest = splitSoundClip(sound, toMs).second;
|
|
123
123
|
pieces.push(
|
|
124
124
|
closeGap
|
|
125
|
-
? {
|
|
125
|
+
? {
|
|
126
|
+
...rest,
|
|
127
|
+
startMsIntoScene: tidy(rest.startMsIntoScene - (toMs - fromMs)),
|
|
128
|
+
}
|
|
126
129
|
: rest,
|
|
127
130
|
);
|
|
128
131
|
}
|
|
@@ -119,7 +119,9 @@ class AsyncFrameSource {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
#contains(frame: WrappedCanvas, seconds: number): boolean {
|
|
122
|
-
return
|
|
122
|
+
return (
|
|
123
|
+
seconds >= frame.timestamp && seconds < frame.timestamp + frame.duration
|
|
124
|
+
);
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
async #restart(seconds: number): Promise<void> {
|
|
@@ -231,9 +233,11 @@ class RafFrameSource {
|
|
|
231
233
|
// own as soon as that first frame lands.
|
|
232
234
|
const newest = this.#localCache.at(-1)?.timestamp;
|
|
233
235
|
const tooFarAhead =
|
|
234
|
-
newest !== undefined &&
|
|
236
|
+
newest !== undefined &&
|
|
237
|
+
seconds - newest > RafFrameSource.MAX_SKIP_SECONDS;
|
|
235
238
|
const tooFarBehind =
|
|
236
|
-
this.#localCache[0] !== undefined &&
|
|
239
|
+
this.#localCache[0] !== undefined &&
|
|
240
|
+
seconds < this.#localCache[0].timestamp;
|
|
237
241
|
if (tooFarAhead || tooFarBehind) {
|
|
238
242
|
this.#reseek(seconds, tooFarAhead ? "too far ahead" : "too far behind");
|
|
239
243
|
}
|
|
@@ -338,7 +342,10 @@ class RafFrameSource {
|
|
|
338
342
|
if (this.#canceled) return;
|
|
339
343
|
if (result.done) {
|
|
340
344
|
this.#atEnd = true;
|
|
341
|
-
debugLog(
|
|
345
|
+
debugLog(
|
|
346
|
+
"RafFrameSource",
|
|
347
|
+
`${this.label}: stream #${generation} ended`,
|
|
348
|
+
);
|
|
342
349
|
return;
|
|
343
350
|
}
|
|
344
351
|
this.#localCache.push(result.value);
|
|
@@ -364,7 +371,10 @@ class RafFrameSource {
|
|
|
364
371
|
// A failed decode just means we stay at whatever we already have;
|
|
365
372
|
// the next get() will try again.
|
|
366
373
|
this.#fetchInProgress = false;
|
|
367
|
-
debugLog(
|
|
374
|
+
debugLog(
|
|
375
|
+
"RafFrameSource",
|
|
376
|
+
`${this.label}: decode failed (stream #${generation}): ${error}`,
|
|
377
|
+
);
|
|
368
378
|
},
|
|
369
379
|
);
|
|
370
380
|
}
|
|
@@ -668,7 +678,8 @@ export class VideoClipComponent extends ComponentWithLiveDuration {
|
|
|
668
678
|
destination.height,
|
|
669
679
|
);
|
|
670
680
|
} else {
|
|
671
|
-
const sourceAspect =
|
|
681
|
+
const sourceAspect =
|
|
682
|
+
this.#video.naturalWidth / this.#video.naturalHeight;
|
|
672
683
|
const destAspect = destination.width / destination.height;
|
|
673
684
|
let drawW: number, drawH: number;
|
|
674
685
|
if (sourceAspect > destAspect) {
|
|
@@ -684,7 +695,8 @@ export class VideoClipComponent extends ComponentWithLiveDuration {
|
|
|
684
695
|
|
|
685
696
|
if (
|
|
686
697
|
frameError !== undefined &&
|
|
687
|
-
Math.abs(frameError) >
|
|
698
|
+
Math.abs(frameError) >
|
|
699
|
+
VideoClipComponent.CLOSE_ENOUGH_MARK_THRESHOLD_MS
|
|
688
700
|
) {
|
|
689
701
|
debugLog(
|
|
690
702
|
"VideoClip",
|
|
@@ -695,7 +707,8 @@ export class VideoClipComponent extends ComponentWithLiveDuration {
|
|
|
695
707
|
// direction: the returned frame is ahead of (cyan) or behind
|
|
696
708
|
// (orange) where we actually asked to be.
|
|
697
709
|
context.fillStyle = frameError > 0 ? "cyan" : "orange";
|
|
698
|
-
const markRadius =
|
|
710
|
+
const markRadius =
|
|
711
|
+
Math.min(destination.width, destination.height) * 0.03;
|
|
699
712
|
context.beginPath();
|
|
700
713
|
context.arc(
|
|
701
714
|
destination.x + destination.width - markRadius * 2,
|
|
@@ -178,7 +178,10 @@ export function sameCenter(size: Size, around: ReadOnlyRect): ReadOnlyRect {
|
|
|
178
178
|
* draws into, because it letterboxes the video inside whatever rectangle it
|
|
179
179
|
* is given.
|
|
180
180
|
*/
|
|
181
|
-
export function shrinkToAspect(
|
|
181
|
+
export function shrinkToAspect(
|
|
182
|
+
rect: ReadOnlyRect,
|
|
183
|
+
aspect: number,
|
|
184
|
+
): ReadOnlyRect {
|
|
182
185
|
const rectAspect = rect.width / rect.height;
|
|
183
186
|
const size =
|
|
184
187
|
rectAspect > aspect
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { assertFinite } from "phil-lib/misc";
|
|
2
2
|
import { ShowOptions } from "./showable.ts";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
getLocalFile,
|
|
5
|
+
isLocalFileUrl,
|
|
6
|
+
localFilesGeneration,
|
|
7
|
+
} from "./local-files.ts";
|
|
4
8
|
|
|
5
9
|
// MARK: Base Class
|
|
6
10
|
|
package/src/snapshot.ts
CHANGED
|
@@ -11,7 +11,10 @@ import {
|
|
|
11
11
|
SoundClip,
|
|
12
12
|
} from "./showable.ts";
|
|
13
13
|
import { componentRegistry } from "./slide-components/registry.ts";
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
SerializedChild,
|
|
16
|
+
buildComponents,
|
|
17
|
+
} from "./slide-components/serialize.ts";
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* Serialized state of one {@link Showable.fixedComponents} item.
|
|
@@ -430,7 +433,9 @@ export function omitComponentDefaults(
|
|
|
430
433
|
if (scalars) result.scalars = scalars;
|
|
431
434
|
if (child.components !== undefined) {
|
|
432
435
|
const components = omitComponentDefaults(child.components);
|
|
433
|
-
if (
|
|
436
|
+
if (
|
|
437
|
+
!sameJson(components, omitComponentDefaults(fresh.components ?? []))
|
|
438
|
+
) {
|
|
434
439
|
result.components = components;
|
|
435
440
|
}
|
|
436
441
|
}
|
|
@@ -476,7 +481,10 @@ export function omitTreeDefaults(
|
|
|
476
481
|
}
|
|
477
482
|
if (tree.fixedComponents) {
|
|
478
483
|
const children = tree.fixedComponents;
|
|
479
|
-
const childDefaults = counterparts(
|
|
484
|
+
const childDefaults = counterparts(
|
|
485
|
+
children,
|
|
486
|
+
defaults?.fixedComponents ?? [],
|
|
487
|
+
);
|
|
480
488
|
const trimmed = children.map((child, index) =>
|
|
481
489
|
omitTreeDefaults(child, childDefaults[index]),
|
|
482
490
|
);
|
|
@@ -485,7 +493,8 @@ export function omitTreeDefaults(
|
|
|
485
493
|
// description, so the nth "note" still lines up with the nth "note".
|
|
486
494
|
const lastChanged = new Map<string, number>();
|
|
487
495
|
for (const [index, child] of trimmed.entries()) {
|
|
488
|
-
if (Object.keys(child).length > 1)
|
|
496
|
+
if (Object.keys(child).length > 1)
|
|
497
|
+
lastChanged.set(child.description, index);
|
|
489
498
|
}
|
|
490
499
|
const kept = trimmed.filter(
|
|
491
500
|
(child, index) => index <= (lastChanged.get(child.description) ?? -1),
|
package/src/utility.ts
CHANGED
|
@@ -441,7 +441,7 @@ export class Random {
|
|
|
441
441
|
a: number,
|
|
442
442
|
b: number,
|
|
443
443
|
c: number,
|
|
444
|
-
d: number
|
|
444
|
+
d: number,
|
|
445
445
|
): RandomFunction {
|
|
446
446
|
function random() {
|
|
447
447
|
a |= 0;
|
|
@@ -513,14 +513,12 @@ export class Random {
|
|
|
513
513
|
throw new Error("invalid input");
|
|
514
514
|
}
|
|
515
515
|
const [a, b, c, d] = seedObject;
|
|
516
|
-
if (
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
)
|
|
523
|
-
) {
|
|
516
|
+
if (!(
|
|
517
|
+
typeof a == "number" &&
|
|
518
|
+
typeof b == "number" &&
|
|
519
|
+
typeof c == "number" &&
|
|
520
|
+
typeof d == "number"
|
|
521
|
+
)) {
|
|
524
522
|
throw new Error("invalid input");
|
|
525
523
|
}
|
|
526
524
|
return this.sfc32(a, b, c, d);
|
|
@@ -643,19 +641,29 @@ export class Random {
|
|
|
643
641
|
try {
|
|
644
642
|
action();
|
|
645
643
|
} finally {
|
|
646
|
-
methods.forEach(
|
|
644
|
+
methods.forEach(
|
|
645
|
+
(method, index) => (console[method] = originals[index]),
|
|
646
|
+
);
|
|
647
647
|
}
|
|
648
648
|
return count;
|
|
649
649
|
}
|
|
650
|
-
function expectMessages(
|
|
650
|
+
function expectMessages(
|
|
651
|
+
name: string,
|
|
652
|
+
expected: number,
|
|
653
|
+
action: () => void,
|
|
654
|
+
) {
|
|
651
655
|
const count = countMessages(action);
|
|
652
656
|
if (count !== expected) {
|
|
653
|
-
problems.push(
|
|
657
|
+
problems.push(
|
|
658
|
+
`${name} wrote ${count} console message${count === 1 ? "" : "s"}, expected ${expected}.`,
|
|
659
|
+
);
|
|
654
660
|
}
|
|
655
661
|
}
|
|
656
662
|
function expectSame(name: string, actual: unknown, expected: unknown) {
|
|
657
663
|
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
658
|
-
problems.push(
|
|
664
|
+
problems.push(
|
|
665
|
+
`${name}: got ${JSON.stringify(actual)}, expected ${JSON.stringify(expected)}.`,
|
|
666
|
+
);
|
|
659
667
|
}
|
|
660
668
|
}
|
|
661
669
|
const draw = (random: () => number, count: number) =>
|
|
@@ -665,37 +673,60 @@ export class Random {
|
|
|
665
673
|
console.log("Random case 1. This should record the seed.");
|
|
666
674
|
expectMessages("Random.create()", 1, () => Random.create());
|
|
667
675
|
console.log("Random case 2. This should run silently.");
|
|
668
|
-
expectMessages('Random.create("[1,2,3,4]")', 0, () =>
|
|
676
|
+
expectMessages('Random.create("[1,2,3,4]")', 0, () =>
|
|
677
|
+
Random.create("[1,2,3,4]"),
|
|
678
|
+
);
|
|
669
679
|
console.log("Random case 3. This should also run silently.");
|
|
670
680
|
expectMessages('Random.fromString("Random case 3")', 0, () =>
|
|
671
681
|
Random.fromString("Random case 3"),
|
|
672
682
|
);
|
|
673
683
|
console.log("Random case 4. Random.seedIsValid(), also silent.");
|
|
674
|
-
expectMessages('Random.seedIsValid("hello")', 0, () =>
|
|
684
|
+
expectMessages('Random.seedIsValid("hello")', 0, () =>
|
|
685
|
+
Random.seedIsValid("hello"),
|
|
686
|
+
);
|
|
675
687
|
|
|
676
688
|
// MARK: Repeatable
|
|
677
689
|
// Everything below is checked silently, so it must not print anything either.
|
|
678
690
|
expectMessages("the repeatability checks", 0, () => {
|
|
679
691
|
const fromSeed = Random.create("[42,17,99,7]");
|
|
680
|
-
expectSame(
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
692
|
+
expectSame(
|
|
693
|
+
'Random.create("[42,17,99,7]")',
|
|
694
|
+
draw(fromSeed, 5),
|
|
695
|
+
[
|
|
696
|
+
1.5366822481155396e-8, 2.1327286958694458e-7, 0.435058941366151,
|
|
697
|
+
0.7251853088382632, 0.7317605882417411,
|
|
698
|
+
],
|
|
699
|
+
);
|
|
700
|
+
expectSame(
|
|
701
|
+
"its currentSeed after 5",
|
|
702
|
+
fromSeed.currentSeed,
|
|
703
|
+
"[1892747913,1308741698,295958450,12]",
|
|
704
|
+
);
|
|
685
705
|
// Used by makePolygon() in fourier-shared.ts, so it's in finished videos.
|
|
686
|
-
expectSame(
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
706
|
+
expectSame(
|
|
707
|
+
'Random.fromString("My seed 2025")',
|
|
708
|
+
draw(Random.fromString("My seed 2025"), 5),
|
|
709
|
+
[
|
|
710
|
+
0.9786544013768435, 0.7879613474942744, 0.050264536403119564,
|
|
711
|
+
0.07471863739192486, 0.040992809226736426,
|
|
712
|
+
],
|
|
713
|
+
);
|
|
714
|
+
expectSame(
|
|
715
|
+
'Random.anyStringToSeed("My seed 2025")',
|
|
716
|
+
Random.anyStringToSeed("My seed 2025"),
|
|
717
|
+
"[-1446261746,783903852,-1683271991,570679246]",
|
|
718
|
+
);
|
|
719
|
+
expectSame(
|
|
720
|
+
"Random.anyStringToSeed(Chinese)",
|
|
693
721
|
Random.anyStringToSeed("在你用中文测试过之前你还没有测试过它。"),
|
|
694
|
-
"[-978814459,-622026031,56408694,127018260]"
|
|
722
|
+
"[-978814459,-622026031,56408694,127018260]",
|
|
723
|
+
);
|
|
695
724
|
// A string that is already a seed is used as is.
|
|
696
|
-
expectSame(
|
|
697
|
-
1
|
|
698
|
-
|
|
725
|
+
expectSame(
|
|
726
|
+
'Random.fromString("[1,2,3,4]")',
|
|
727
|
+
draw(Random.fromString("[1,2,3,4]"), 3),
|
|
728
|
+
[1.6298145055770874e-9, 7.916241884231567e-9, 0.01318361610174179],
|
|
729
|
+
);
|
|
699
730
|
for (const [seed, valid] of [
|
|
700
731
|
["[1,2,3,4]", true],
|
|
701
732
|
["hello", false],
|
|
@@ -704,7 +735,11 @@ export class Random {
|
|
|
704
735
|
// Odd, but phil-lib 1.8.1 accepts it, so keep accepting it.
|
|
705
736
|
["[1.5,2,3,4]", true],
|
|
706
737
|
] as const) {
|
|
707
|
-
expectSame(
|
|
738
|
+
expectSame(
|
|
739
|
+
`Random.seedIsValid(${JSON.stringify(seed)})`,
|
|
740
|
+
Random.seedIsValid(seed),
|
|
741
|
+
valid,
|
|
742
|
+
);
|
|
708
743
|
}
|
|
709
744
|
// A clone made from currentSeed carries on exactly where the original is.
|
|
710
745
|
const original = Random.create("[5,6,7,8]");
|
|
@@ -716,7 +751,9 @@ export class Random {
|
|
|
716
751
|
if (problems.length === 0) {
|
|
717
752
|
console.log("Random done: all passed.");
|
|
718
753
|
} else {
|
|
719
|
-
console.error(
|
|
754
|
+
console.error(
|
|
755
|
+
`Random done: ${problems.length} problem${problems.length === 1 ? "" : "s"}.\n ${problems.join("\n ")}`,
|
|
756
|
+
);
|
|
720
757
|
}
|
|
721
758
|
}
|
|
722
759
|
}
|