canvas-recorder-lib 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BREAKING-CHANGES.md +24 -0
- package/README.md +131 -25
- package/dev/audio-builder.ts +69 -161
- package/dev/canvas-recorder.css +59 -0
- package/dev/canvas-recorder.ts +1006 -212
- package/dev/delay-files.ts +1 -1
- package/dev/font-utils.ts +8 -1
- package/dev/format-editor.ts +734 -0
- package/dev/format-string.ts +110 -0
- package/dev/local-file-row.ts +107 -0
- package/dev/multi-text-dialog.ts +360 -0
- package/dev/multi-text-panel.ts +11 -0
- package/dev/player-body.ts +94 -6
- package/dev/rect-snap.ts +9 -9
- package/dev/slide-panel.ts +1 -1
- package/dev/sound-clips.ts +3 -2
- package/dev/soundtrack.ts +434 -0
- package/dev/split-dialog.ts +13 -2
- package/dev/static-image-panel.ts +35 -5
- package/dev/timeline-display.ts +50 -5
- package/dev/transcripts.ts +5 -3
- package/dev/video-clip-panel.ts +202 -16
- package/dev/voice/chirp.ts +129 -0
- package/dev/voice/folder.ts +84 -0
- package/dev/voice/voice-panel.ts +513 -0
- package/dev/voice/voice-recorder.ts +603 -0
- package/dist/dev/audio-builder.d.ts +14 -31
- package/dist/dev/audio-builder.d.ts.map +1 -1
- package/dist/dev/audio-builder.js +62 -134
- package/dist/dev/audio-builder.js.map +1 -1
- package/dist/dev/canvas-recorder.css +59 -0
- package/dist/dev/canvas-recorder.js +926 -198
- package/dist/dev/canvas-recorder.js.map +1 -1
- package/dist/dev/delay-files.js +1 -1
- package/dist/dev/delay-files.js.map +1 -1
- package/dist/dev/font-utils.d.ts.map +1 -1
- package/dist/dev/font-utils.js +9 -1
- package/dist/dev/font-utils.js.map +1 -1
- package/dist/dev/format-editor.d.ts +75 -0
- package/dist/dev/format-editor.d.ts.map +1 -0
- package/dist/dev/format-editor.js +642 -0
- package/dist/dev/format-editor.js.map +1 -0
- package/dist/dev/format-string.d.ts +62 -0
- package/dist/dev/format-string.d.ts.map +1 -0
- package/dist/dev/format-string.js +86 -0
- package/dist/dev/format-string.js.map +1 -0
- package/dist/dev/local-file-row.d.ts +22 -0
- package/dist/dev/local-file-row.d.ts.map +1 -0
- package/dist/dev/local-file-row.js +84 -0
- package/dist/dev/local-file-row.js.map +1 -0
- package/dist/dev/multi-text-dialog.d.ts +30 -0
- package/dist/dev/multi-text-dialog.d.ts.map +1 -0
- package/dist/dev/multi-text-dialog.js +297 -0
- package/dist/dev/multi-text-dialog.js.map +1 -0
- package/dist/dev/multi-text-panel.d.ts +2 -0
- package/dist/dev/multi-text-panel.d.ts.map +1 -1
- package/dist/dev/multi-text-panel.js +4 -0
- 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 +94 -6
- package/dist/dev/player-body.js.map +1 -1
- package/dist/dev/rect-snap.d.ts +1 -1
- package/dist/dev/rect-snap.js +7 -7
- package/dist/dev/rect-snap.js.map +1 -1
- package/dist/dev/slide-panel.d.ts +1 -1
- package/dist/dev/slide-panel.d.ts.map +1 -1
- package/dist/dev/slide-panel.js +1 -1
- package/dist/dev/slide-panel.js.map +1 -1
- package/dist/dev/sound-clips.d.ts +3 -2
- package/dist/dev/sound-clips.d.ts.map +1 -1
- package/dist/dev/sound-clips.js +3 -2
- package/dist/dev/sound-clips.js.map +1 -1
- package/dist/dev/soundtrack.d.ts +115 -0
- package/dist/dev/soundtrack.d.ts.map +1 -0
- package/dist/dev/soundtrack.js +369 -0
- package/dist/dev/soundtrack.js.map +1 -0
- package/dist/dev/split-dialog.d.ts.map +1 -1
- package/dist/dev/split-dialog.js +14 -2
- package/dist/dev/split-dialog.js.map +1 -1
- package/dist/dev/static-image-panel.d.ts +2 -0
- package/dist/dev/static-image-panel.d.ts.map +1 -1
- package/dist/dev/static-image-panel.js +29 -5
- package/dist/dev/static-image-panel.js.map +1 -1
- package/dist/dev/timeline-display.d.ts +23 -2
- package/dist/dev/timeline-display.d.ts.map +1 -1
- package/dist/dev/timeline-display.js +47 -5
- package/dist/dev/timeline-display.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 +8 -0
- package/dist/dev/video-clip-panel.d.ts.map +1 -1
- package/dist/dev/video-clip-panel.js +176 -10
- package/dist/dev/video-clip-panel.js.map +1 -1
- package/dist/dev/voice/chirp.d.ts +27 -0
- package/dist/dev/voice/chirp.d.ts.map +1 -0
- package/dist/dev/voice/chirp.js +107 -0
- package/dist/dev/voice/chirp.js.map +1 -0
- package/dist/dev/voice/folder.d.ts +18 -0
- package/dist/dev/voice/folder.d.ts.map +1 -0
- package/dist/dev/voice/folder.js +68 -0
- package/dist/dev/voice/folder.js.map +1 -0
- package/dist/dev/voice/voice-panel.d.ts +44 -0
- package/dist/dev/voice/voice-panel.d.ts.map +1 -0
- package/dist/dev/voice/voice-panel.js +418 -0
- package/dist/dev/voice/voice-panel.js.map +1 -0
- package/dist/dev/voice/voice-recorder.d.ts +141 -0
- package/dist/dev/voice/voice-recorder.d.ts.map +1 -0
- package/dist/dev/voice/voice-recorder.js +506 -0
- package/dist/dev/voice/voice-recorder.js.map +1 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +3 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/main-control.d.ts +50 -4
- package/dist/lib/main-control.d.ts.map +1 -1
- package/dist/lib/main-control.js +94 -12
- package/dist/lib/main-control.js.map +1 -1
- package/dist/src/binary-search.js +1 -1
- package/dist/src/binary-search.js.map +1 -1
- package/dist/src/corner-rounder.d.ts +17 -0
- package/dist/src/corner-rounder.d.ts.map +1 -0
- package/dist/src/corner-rounder.js +89 -0
- package/dist/src/corner-rounder.js.map +1 -0
- package/dist/src/cross-fade.d.ts +1 -1
- package/dist/src/cross-fade.d.ts.map +1 -1
- package/dist/src/cross-fade.js +3 -3
- package/dist/src/cross-fade.js.map +1 -1
- package/dist/src/fancy-text.d.ts +116 -0
- package/dist/src/fancy-text.d.ts.map +1 -0
- package/dist/src/fancy-text.js +211 -0
- package/dist/src/fancy-text.js.map +1 -0
- package/dist/src/glib/letters-base.d.ts +1 -1
- package/dist/src/glib/letters-base.d.ts.map +1 -1
- package/dist/src/glib/letters-base.js +4 -3
- package/dist/src/glib/letters-base.js.map +1 -1
- package/dist/src/glib/line-font.d.ts +2 -2
- package/dist/src/glib/line-font.d.ts.map +1 -1
- package/dist/src/glib/line-font.js +2 -2
- package/dist/src/glib/line-font.js.map +1 -1
- package/dist/src/glib/paragraph-layout.d.ts +2 -2
- package/dist/src/glib/paragraph-layout.d.ts.map +1 -1
- package/dist/src/glib/paragraph-layout.js +1 -1
- package/dist/src/glib/paragraph-layout.js.map +1 -1
- package/dist/src/glib/path-shape-splitter.d.ts +1 -1
- package/dist/src/glib/path-shape-splitter.d.ts.map +1 -1
- package/dist/src/glib/path-shape-splitter.js +1 -1
- package/dist/src/glib/path-shape-splitter.js.map +1 -1
- package/dist/src/glib/path-shape.js +2 -2
- package/dist/src/glib/path-shape.js.map +1 -1
- package/dist/src/interpolate.d.ts +2 -2
- package/dist/src/interpolate.d.ts.map +1 -1
- package/dist/src/interpolate.js +1 -1
- package/dist/src/interpolate.js.map +1 -1
- package/dist/src/lattice.d.ts +1 -1
- package/dist/src/lattice.d.ts.map +1 -1
- package/dist/src/local-files.d.ts +129 -0
- package/dist/src/local-files.d.ts.map +1 -0
- package/dist/src/local-files.js +327 -0
- package/dist/src/local-files.js.map +1 -0
- package/dist/src/morph-animation.d.ts +1 -1
- package/dist/src/morph-animation.d.ts.map +1 -1
- package/dist/src/morph-animation.js +2 -2
- package/dist/src/morph-animation.js.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.d.ts +1 -1
- package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.js +17 -4
- package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
- package/dist/src/schedule-helper.d.ts +4 -4
- package/dist/src/schedule-helper.d.ts.map +1 -1
- package/dist/src/schedule-helper.js +2 -2
- package/dist/src/schedule-helper.js.map +1 -1
- package/dist/src/showable.d.ts +45 -4
- package/dist/src/showable.d.ts.map +1 -1
- package/dist/src/showable.js +37 -1
- package/dist/src/showable.js.map +1 -1
- package/dist/src/slide-components/arrow.d.ts +4 -4
- package/dist/src/slide-components/arrow.d.ts.map +1 -1
- package/dist/src/slide-components/arrow.js +2 -2
- package/dist/src/slide-components/arrow.js.map +1 -1
- package/dist/src/slide-components/cross-fade-transition.d.ts +3 -3
- package/dist/src/slide-components/cross-fade-transition.d.ts.map +1 -1
- package/dist/src/slide-components/cross-fade-transition.js +3 -3
- package/dist/src/slide-components/cross-fade-transition.js.map +1 -1
- package/dist/src/slide-components/duration-agnostic.d.ts +3 -3
- package/dist/src/slide-components/duration-agnostic.d.ts.map +1 -1
- package/dist/src/slide-components/duration-agnostic.js +1 -1
- package/dist/src/slide-components/duration-agnostic.js.map +1 -1
- package/dist/src/slide-components/fixed-duration.d.ts +1 -1
- package/dist/src/slide-components/fixed-duration.d.ts.map +1 -1
- package/dist/src/slide-components/fixed-duration.js +1 -1
- package/dist/src/slide-components/fixed-duration.js.map +1 -1
- package/dist/src/slide-components/fourier.d.ts +6 -6
- package/dist/src/slide-components/fourier.d.ts.map +1 -1
- package/dist/src/slide-components/fourier.js +6 -6
- package/dist/src/slide-components/fourier.js.map +1 -1
- package/dist/src/slide-components/frame-counter.d.ts +2 -2
- package/dist/src/slide-components/frame-counter.d.ts.map +1 -1
- package/dist/src/slide-components/frame-counter.js +1 -1
- package/dist/src/slide-components/frame-counter.js.map +1 -1
- package/dist/src/slide-components/function-graph.d.ts +2 -2
- package/dist/src/slide-components/function-graph.d.ts.map +1 -1
- package/dist/src/slide-components/function-graph.js +3 -3
- package/dist/src/slide-components/function-graph.js.map +1 -1
- package/dist/src/slide-components/halftone-shadow.d.ts +4 -4
- package/dist/src/slide-components/halftone-shadow.d.ts.map +1 -1
- package/dist/src/slide-components/halftone-shadow.js +2 -2
- package/dist/src/slide-components/halftone-shadow.js.map +1 -1
- package/dist/src/slide-components/handwriting-effect.d.ts +5 -5
- package/dist/src/slide-components/handwriting-effect.d.ts.map +1 -1
- package/dist/src/slide-components/handwriting-effect.js +5 -5
- package/dist/src/slide-components/handwriting-effect.js.map +1 -1
- package/dist/src/slide-components/hold.d.ts +3 -3
- package/dist/src/slide-components/hold.d.ts.map +1 -1
- package/dist/src/slide-components/hold.js +3 -3
- package/dist/src/slide-components/hold.js.map +1 -1
- package/dist/src/slide-components/image.d.ts +3 -3
- package/dist/src/slide-components/image.d.ts.map +1 -1
- package/dist/src/slide-components/image.js +3 -3
- package/dist/src/slide-components/image.js.map +1 -1
- package/dist/src/slide-components/in-parallel.d.ts +3 -3
- package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
- package/dist/src/slide-components/in-parallel.js +2 -2
- package/dist/src/slide-components/in-parallel.js.map +1 -1
- package/dist/src/slide-components/in-series.d.ts +4 -4
- package/dist/src/slide-components/in-series.d.ts.map +1 -1
- package/dist/src/slide-components/in-series.js +5 -1
- package/dist/src/slide-components/in-series.js.map +1 -1
- package/dist/src/slide-components/live-duration.d.ts +1 -1
- package/dist/src/slide-components/live-duration.d.ts.map +1 -1
- package/dist/src/slide-components/live-duration.js +1 -1
- package/dist/src/slide-components/live-duration.js.map +1 -1
- package/dist/src/slide-components/multi-text.d.ts +76 -15
- package/dist/src/slide-components/multi-text.d.ts.map +1 -1
- package/dist/src/slide-components/multi-text.js +170 -25
- package/dist/src/slide-components/multi-text.js.map +1 -1
- package/dist/src/slide-components/rectangle.d.ts +3 -3
- 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.d.ts +1 -1
- package/dist/src/slide-components/registry.d.ts.map +1 -1
- package/dist/src/slide-components/registry.js +18 -18
- package/dist/src/slide-components/registry.js.map +1 -1
- package/dist/src/slide-components/serialize.d.ts +1 -1
- package/dist/src/slide-components/serialize.d.ts.map +1 -1
- package/dist/src/slide-components/serialize.js +2 -2
- package/dist/src/slide-components/serialize.js.map +1 -1
- package/dist/src/slide-components/show-error.js +2 -2
- package/dist/src/slide-components/show-error.js.map +1 -1
- package/dist/src/slide-components/simple-text.d.ts +4 -4
- package/dist/src/slide-components/simple-text.d.ts.map +1 -1
- package/dist/src/slide-components/simple-text.js +4 -4
- package/dist/src/slide-components/simple-text.js.map +1 -1
- package/dist/src/slide-components/slide-component.d.ts +5 -5
- package/dist/src/slide-components/slide-component.d.ts.map +1 -1
- package/dist/src/slide-components/slide-component.js +4 -4
- package/dist/src/slide-components/slide-component.js.map +1 -1
- package/dist/src/slide-components/slide-left.d.ts +3 -3
- package/dist/src/slide-components/slide-left.d.ts.map +1 -1
- package/dist/src/slide-components/slide-left.js +3 -3
- package/dist/src/slide-components/slide-left.js.map +1 -1
- package/dist/src/slide-components/split-video-clip.d.ts +2 -2
- package/dist/src/slide-components/split-video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/split-video-clip.js +3 -3
- package/dist/src/slide-components/split-video-clip.js.map +1 -1
- package/dist/src/slide-components/text-effect.d.ts +2 -2
- package/dist/src/slide-components/text-effect.d.ts.map +1 -1
- package/dist/src/slide-components/traditional-text.d.ts +4 -4
- package/dist/src/slide-components/traditional-text.d.ts.map +1 -1
- package/dist/src/slide-components/traditional-text.js +3 -3
- package/dist/src/slide-components/traditional-text.js.map +1 -1
- package/dist/src/slide-components/video-clip.d.ts +17 -5
- package/dist/src/slide-components/video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/video-clip.js +52 -11
- package/dist/src/slide-components/video-clip.js.map +1 -1
- package/dist/src/slide-components/video-info.d.ts +11 -11
- package/dist/src/slide-components/video-info.d.ts.map +1 -1
- package/dist/src/slide-components/video-info.js +32 -21
- package/dist/src/slide-components/video-info.js.map +1 -1
- package/dist/src/slow-image-sources.d.ts +7 -1
- package/dist/src/slow-image-sources.d.ts.map +1 -1
- package/dist/src/slow-image-sources.js +36 -5
- package/dist/src/slow-image-sources.js.map +1 -1
- package/dist/src/snapshot.d.ts +2 -2
- package/dist/src/snapshot.d.ts.map +1 -1
- package/dist/src/snapshot.js +31 -15
- package/dist/src/snapshot.js.map +1 -1
- package/dist/src/stroke-colors.d.ts +1 -1
- package/dist/src/stroke-colors.d.ts.map +1 -1
- package/dist/src/stroke-colors.js +4 -4
- package/dist/src/stroke-colors.js.map +1 -1
- package/dist/src/utility.d.ts +3 -4
- package/dist/src/utility.d.ts.map +1 -1
- package/dist/src/utility.js +4 -4
- package/dist/src/utility.js.map +1 -1
- package/lib/index.ts +3 -0
- package/lib/main-control.ts +119 -12
- package/package.json +7 -5
- package/src/binary-search.ts +2 -2
- package/src/corner-rounder.ts +128 -0
- package/src/cross-fade.ts +3 -3
- package/src/fancy-text.ts +255 -0
- package/src/glib/letters-base.ts +4 -3
- package/src/glib/line-font.ts +2 -2
- package/src/glib/paragraph-layout.ts +2 -2
- package/src/glib/path-shape-splitter.ts +1 -1
- package/src/glib/path-shape.ts +2 -2
- package/src/interpolate.ts +3 -3
- package/src/lattice.ts +1 -1
- package/src/local-files.ts +389 -0
- package/src/morph-animation.ts +2 -2
- package/src/peano-fourier/fourier-shared.ts +17 -4
- package/src/schedule-helper.ts +4 -4
- package/src/showable.ts +63 -4
- package/src/slide-components/arrow.ts +4 -4
- package/src/slide-components/cross-fade-transition.ts +4 -4
- package/src/slide-components/duration-agnostic.ts +3 -3
- package/src/slide-components/fixed-duration.ts +1 -1
- package/src/slide-components/fourier.ts +9 -9
- package/src/slide-components/frame-counter.ts +2 -2
- package/src/slide-components/function-graph.ts +4 -4
- package/src/slide-components/halftone-shadow.ts +4 -4
- package/src/slide-components/handwriting-effect.ts +7 -7
- package/src/slide-components/hold.ts +4 -4
- package/src/slide-components/image.ts +5 -5
- package/src/slide-components/in-parallel.ts +4 -4
- package/src/slide-components/in-series.ts +7 -4
- package/src/slide-components/live-duration.ts +1 -1
- package/src/slide-components/multi-text.ts +195 -30
- package/src/slide-components/rectangle.ts +3 -3
- package/src/slide-components/registry.ts +19 -19
- package/src/slide-components/serialize.ts +2 -2
- package/src/slide-components/show-error.ts +2 -2
- package/src/slide-components/simple-text.ts +7 -7
- package/src/slide-components/slide-component.ts +7 -7
- package/src/slide-components/slide-left.ts +4 -4
- package/src/slide-components/split-video-clip.ts +4 -4
- package/src/slide-components/text-effect.ts +2 -2
- package/src/slide-components/traditional-text.ts +5 -5
- package/src/slide-components/video-clip.ts +64 -13
- package/src/slide-components/video-info.ts +33 -21
- package/src/slow-image-sources.ts +38 -6
- package/src/snapshot.ts +34 -19
- package/src/stroke-colors.ts +4 -4
- package/src/utility.ts +5 -5
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ALL_FORMATS,
|
|
3
|
+
BlobSource,
|
|
4
|
+
CanvasSink,
|
|
5
|
+
Input,
|
|
6
|
+
UrlSource,
|
|
7
|
+
WrappedCanvas,
|
|
8
|
+
} from "mediabunny";
|
|
9
|
+
import {
|
|
10
|
+
getLocalFile,
|
|
11
|
+
isLocalFileUrl,
|
|
12
|
+
localFilesGeneration,
|
|
13
|
+
} from "../local-files.ts";
|
|
14
|
+
import { ComponentWithLiveDuration } from "./live-duration.ts";
|
|
3
15
|
import { ReadOnlyRect } from "phil-lib/misc";
|
|
4
|
-
import { RectangleScheduleInfo } from "../schedule-helper";
|
|
5
|
-
import { Scalar, ShowOptions, SoundClip } from "../showable";
|
|
6
|
-
import { SlowImage } from "../slow-image-sources";
|
|
7
|
-
import { Keyframe } from "../interpolate";
|
|
8
|
-
import { debugLog } from "../debug-log";
|
|
9
|
-
import { readVideoInfo, VideoInfo } from "./video-info";
|
|
16
|
+
import { RectangleScheduleInfo } from "../schedule-helper.ts";
|
|
17
|
+
import { Scalar, ShowOptions, SoundClip } from "../showable.ts";
|
|
18
|
+
import { SlowImage } from "../slow-image-sources.ts";
|
|
19
|
+
import { Keyframe } from "../interpolate.ts";
|
|
20
|
+
import { debugLog } from "../debug-log.ts";
|
|
21
|
+
import { readVideoInfo, VideoInfo } from "./video-info.ts";
|
|
10
22
|
|
|
11
23
|
// MARK: Streaming Frame Sources
|
|
12
24
|
|
|
@@ -429,7 +441,12 @@ type OpenVideo = {
|
|
|
429
441
|
};
|
|
430
442
|
|
|
431
443
|
async function openVideo(url: string): Promise<OpenVideo> {
|
|
432
|
-
|
|
444
|
+
// A local file is read through a Blob, which is what Mediabunny recommends in a browser.
|
|
445
|
+
// See src/local-files.ts.
|
|
446
|
+
const source = isLocalFileUrl(url)
|
|
447
|
+
? new BlobSource(await getLocalFile(url))
|
|
448
|
+
: new UrlSource(url);
|
|
449
|
+
const input = new Input({ source, formats: ALL_FORMATS });
|
|
433
450
|
const track = await input.getPrimaryVideoTrack();
|
|
434
451
|
if (!track) {
|
|
435
452
|
throw new Error(`No video track found in "${url}".`);
|
|
@@ -455,6 +472,12 @@ export class VideoClipComponent extends ComponentWithLiveDuration {
|
|
|
455
472
|
* tune once this has actually been watched in practice.
|
|
456
473
|
*/
|
|
457
474
|
static readonly CLOSE_ENOUGH_MARK_THRESHOLD_MS = 100;
|
|
475
|
+
/**
|
|
476
|
+
* How far ahead {@link getReady} starts decoding the first frame, in the video's time.
|
|
477
|
+
* Farther ahead than this, the work could pile up: starting the movie would start every
|
|
478
|
+
* clip in the series at once.
|
|
479
|
+
*/
|
|
480
|
+
static readonly GET_READY_MS = 5_000;
|
|
458
481
|
readonly registryKey = "Video Clip";
|
|
459
482
|
readonly urlScalar: Scalar<"string"> = {
|
|
460
483
|
description: "URL",
|
|
@@ -489,6 +512,11 @@ export class VideoClipComponent extends ComponentWithLiveDuration {
|
|
|
489
512
|
soundClips: SoundClip[] = [];
|
|
490
513
|
|
|
491
514
|
#url = "";
|
|
515
|
+
/**
|
|
516
|
+
* {@link localFilesGeneration} when a local file failed to open.
|
|
517
|
+
* When it changes (e.g. the user clicked 🔓), try again. Undefined when there's nothing to retry.
|
|
518
|
+
*/
|
|
519
|
+
#failedAtGeneration: number | undefined;
|
|
492
520
|
#videoPromise: Promise<OpenVideo> | undefined;
|
|
493
521
|
/** Set once #videoPromise resolves -- see #getVideoPromise() for why this can't just be read off the promise itself. */
|
|
494
522
|
#video: OpenVideo | undefined;
|
|
@@ -501,13 +529,17 @@ export class VideoClipComponent extends ComponentWithLiveDuration {
|
|
|
501
529
|
*/
|
|
502
530
|
#getVideoPromise(): Promise<OpenVideo> | undefined {
|
|
503
531
|
const url = this.urlScalar.value;
|
|
504
|
-
|
|
532
|
+
const retry =
|
|
533
|
+
this.#failedAtGeneration !== undefined &&
|
|
534
|
+
this.#failedAtGeneration !== localFilesGeneration();
|
|
535
|
+
if (url !== this.#url || retry) {
|
|
505
536
|
this.#url = url;
|
|
537
|
+
this.#failedAtGeneration = undefined;
|
|
506
538
|
this.#video = undefined;
|
|
507
539
|
this.#lastExactFrame = undefined;
|
|
508
540
|
// The old FrameSource (if any) is simply dropped. Unlike
|
|
509
|
-
// FilePathSource (Node-only), UrlSource
|
|
510
|
-
// like a file handle, so there's nothing to explicitly release.
|
|
541
|
+
// FilePathSource (Node-only), UrlSource and BlobSource hold no OS-level
|
|
542
|
+
// resource like a file handle, so there's nothing to explicitly release.
|
|
511
543
|
this.#videoPromise = url ? openVideo(url) : undefined;
|
|
512
544
|
// A promise only resolves its .then() callbacks in a later microtask,
|
|
513
545
|
// even if already settled -- so show() (synchronous) can't peek at
|
|
@@ -516,7 +548,15 @@ export class VideoClipComponent extends ComponentWithLiveDuration {
|
|
|
516
548
|
// though a separate .then() in getFramePromises() also observes this
|
|
517
549
|
// same promise) is what marks #videoPromise's rejection "handled" --
|
|
518
550
|
// no unhandled-rejection console noise either way.
|
|
519
|
-
|
|
551
|
+
const promise = this.#videoPromise;
|
|
552
|
+
promise
|
|
553
|
+
?.then((v) => (this.#video = v))
|
|
554
|
+
.catch(() => {
|
|
555
|
+
// Only a local file can start working without its URL changing.
|
|
556
|
+
if (isLocalFileUrl(url) && this.#videoPromise === promise) {
|
|
557
|
+
this.#failedAtGeneration = localFilesGeneration();
|
|
558
|
+
}
|
|
559
|
+
});
|
|
520
560
|
}
|
|
521
561
|
return this.#videoPromise;
|
|
522
562
|
}
|
|
@@ -585,6 +625,17 @@ export class VideoClipComponent extends ComponentWithLiveDuration {
|
|
|
585
625
|
}
|
|
586
626
|
super.getFramePromises(timeInMs, set);
|
|
587
627
|
}
|
|
628
|
+
/**
|
|
629
|
+
* Called by an In Series parent before this clip starts. Within {@link GET_READY_MS}, open the
|
|
630
|
+
* file and start decoding the first frame, the same request show() will make at time 0.
|
|
631
|
+
* Then the first frame is usually ready when it's needed, instead of a red ✕.
|
|
632
|
+
*/
|
|
633
|
+
getReady(timeInMs: number): void {
|
|
634
|
+
if (timeInMs < -VideoClipComponent.GET_READY_MS) return;
|
|
635
|
+
// Opens the file, if this is the first time anyone asked.
|
|
636
|
+
if (!this.#getVideoPromise()) return;
|
|
637
|
+
this.#video?.frameSource.getRaf(this.locationInClip(0));
|
|
638
|
+
}
|
|
588
639
|
override show(options: ShowOptions): void {
|
|
589
640
|
const { context, playSpeed, timeInMs } = options;
|
|
590
641
|
const destination = this.destinationRectSchedule.at(timeInMs);
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { Input, InputVideoTrack } from "mediabunny";
|
|
2
2
|
import { ReadOnlyRect } from "phil-lib/misc";
|
|
3
|
+
import { canvasRecorder } from "../../lib/main-control.ts";
|
|
3
4
|
|
|
4
5
|
// MARK: Constants
|
|
5
6
|
|
|
6
|
-
/** The
|
|
7
|
-
export
|
|
8
|
-
|
|
7
|
+
/** The width of the canvas, in units. Usually 16. See {@link canvasRecorder.width}. */
|
|
8
|
+
export function canvasWidthUnits(): number {
|
|
9
|
+
return canvasRecorder.width;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The height of the canvas, in units. Usually 9. See {@link canvasRecorder.height}. */
|
|
13
|
+
export function canvasHeightUnits(): number {
|
|
14
|
+
return canvasRecorder.height;
|
|
15
|
+
}
|
|
9
16
|
|
|
10
17
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* resolution in the final output, with no resampling at all.
|
|
18
|
+
* Output pixels per canvas unit, across. 3840 / 16 = 240 for the defaults.
|
|
19
|
+
* A video drawn at exactly this many of its own pixels per unit appears at its
|
|
20
|
+
* native resolution in the final output, with no resampling at all.
|
|
15
21
|
*/
|
|
16
|
-
export
|
|
22
|
+
export function pixelsPerUnit(): number {
|
|
23
|
+
return canvasRecorder.pixelWidth / canvasRecorder.width;
|
|
24
|
+
}
|
|
17
25
|
|
|
18
26
|
// MARK: Reading a file
|
|
19
27
|
|
|
@@ -114,37 +122,41 @@ export async function readVideoInfo(
|
|
|
114
122
|
|
|
115
123
|
type Size = { readonly width: number; readonly height: number };
|
|
116
124
|
|
|
117
|
-
/** "max fit" / "meet" / "contain": the whole video fits inside the
|
|
125
|
+
/** "max fit" / "meet" / "contain": the whole video fits inside the canvas. */
|
|
118
126
|
export function maxFit(mediaWidth: number, mediaHeight: number): Size {
|
|
127
|
+
const canvasWidth = canvasWidthUnits();
|
|
128
|
+
const canvasHeight = canvasHeightUnits();
|
|
119
129
|
const mediaAspect = mediaWidth / mediaHeight;
|
|
120
|
-
const canvasAspect =
|
|
130
|
+
const canvasAspect = canvasWidth / canvasHeight;
|
|
121
131
|
return mediaAspect > canvasAspect
|
|
122
|
-
? { width:
|
|
123
|
-
: { width:
|
|
132
|
+
? { width: canvasWidth, height: canvasWidth / mediaAspect }
|
|
133
|
+
: { width: canvasHeight * mediaAspect, height: canvasHeight };
|
|
124
134
|
}
|
|
125
135
|
|
|
126
136
|
/** "min to cover" / "slice" / "fill": the canvas is fully covered; the video may overflow it. */
|
|
127
137
|
export function minCover(mediaWidth: number, mediaHeight: number): Size {
|
|
138
|
+
const canvasWidth = canvasWidthUnits();
|
|
139
|
+
const canvasHeight = canvasHeightUnits();
|
|
128
140
|
const mediaAspect = mediaWidth / mediaHeight;
|
|
129
|
-
const canvasAspect =
|
|
141
|
+
const canvasAspect = canvasWidth / canvasHeight;
|
|
130
142
|
return mediaAspect > canvasAspect
|
|
131
|
-
? { width:
|
|
132
|
-
: { width:
|
|
143
|
+
? { width: canvasHeight * mediaAspect, height: canvasHeight }
|
|
144
|
+
: { width: canvasWidth, height: canvasWidth / mediaAspect };
|
|
133
145
|
}
|
|
134
146
|
|
|
135
|
-
/** "preserve pixels": native resolution in the final output. See {@link
|
|
147
|
+
/** "preserve pixels": native resolution in the final output. See {@link pixelsPerUnit}. */
|
|
136
148
|
export function preservePixels(mediaWidth: number, mediaHeight: number): Size {
|
|
137
149
|
return {
|
|
138
|
-
width: mediaWidth /
|
|
139
|
-
height: mediaHeight /
|
|
150
|
+
width: mediaWidth / pixelsPerUnit(),
|
|
151
|
+
height: mediaHeight / pixelsPerUnit(),
|
|
140
152
|
};
|
|
141
153
|
}
|
|
142
154
|
|
|
143
|
-
/** A rectangle of the given size, centered on the
|
|
155
|
+
/** A rectangle of the given size, centered on the canvas. */
|
|
144
156
|
export function centeredOnCanvas(size: Size): ReadOnlyRect {
|
|
145
157
|
return {
|
|
146
|
-
x: (
|
|
147
|
-
y: (
|
|
158
|
+
x: (canvasWidthUnits() - size.width) / 2,
|
|
159
|
+
y: (canvasHeightUnits() - size.height) / 2,
|
|
148
160
|
width: size.width,
|
|
149
161
|
height: size.height,
|
|
150
162
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertFinite } from "phil-lib/misc";
|
|
2
|
-
import { ShowOptions } from "./showable";
|
|
2
|
+
import { ShowOptions } from "./showable.ts";
|
|
3
|
+
import { getLocalFile, isLocalFileUrl, localFilesGeneration } from "./local-files.ts";
|
|
3
4
|
|
|
4
5
|
// MARK: Base Class
|
|
5
6
|
|
|
@@ -15,7 +16,7 @@ import { ShowOptions } from "./showable";
|
|
|
15
16
|
*
|
|
16
17
|
* This class explicitly hides any and all HTML elements.
|
|
17
18
|
* Those are part of the implementation.
|
|
18
|
-
*
|
|
19
|
+
* Like every module in /src, this one doesn't touch the DOM while it loads.
|
|
19
20
|
*/
|
|
20
21
|
export abstract class SlowImage {
|
|
21
22
|
/**
|
|
@@ -27,6 +28,7 @@ export abstract class SlowImage {
|
|
|
27
28
|
* This draws a red rectangle showing the borders edges of the area, and a red x going through the middle.
|
|
28
29
|
* This is an old standard for showing missing images.
|
|
29
30
|
* This is always available, so we're not worried about an await or another exception in an exception handler.
|
|
31
|
+
* An empty rectangle, e.g. a Dest Rect with no width, draws nothing.
|
|
30
32
|
*
|
|
31
33
|
* Side effects:
|
|
32
34
|
* This will take the same liberties with your canvas as described in {@link ShowOptions.context}.
|
|
@@ -46,7 +48,8 @@ export abstract class SlowImage {
|
|
|
46
48
|
) {
|
|
47
49
|
assertFinite(x, y, width, height);
|
|
48
50
|
if (width <= 0 || height <= 0) {
|
|
49
|
-
|
|
51
|
+
// Probably mid-edit in the Visual Editor. A user error is a state, not an exception.
|
|
52
|
+
return;
|
|
50
53
|
}
|
|
51
54
|
const lineWidth = 0.1;
|
|
52
55
|
if (width < lineWidth * 2 || height < lineWidth * 2) {
|
|
@@ -147,13 +150,38 @@ export class SingleImage extends SlowImage {
|
|
|
147
150
|
return this.#promise;
|
|
148
151
|
}
|
|
149
152
|
#element: HTMLImageElement;
|
|
153
|
+
/**
|
|
154
|
+
* For a local file that failed to load: {@link localFilesGeneration} at the time.
|
|
155
|
+
* A newer generation means it's worth making a new one. See {@link worthRetrying}.
|
|
156
|
+
*/
|
|
157
|
+
#failedAtGeneration: number | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* True if this image failed, and something has changed that might fix it.
|
|
160
|
+
* That only happens for local files, e.g. after the user clicks 🔓.
|
|
161
|
+
*/
|
|
162
|
+
get worthRetrying(): boolean {
|
|
163
|
+
return (
|
|
164
|
+
this.#failedAtGeneration !== undefined &&
|
|
165
|
+
this.#failedAtGeneration !== localFilesGeneration()
|
|
166
|
+
);
|
|
167
|
+
}
|
|
150
168
|
constructor(readonly url: string) {
|
|
151
169
|
super();
|
|
152
170
|
this.#element = new Image();
|
|
153
171
|
this.#element.crossOrigin = "anonymous";
|
|
154
172
|
this.data = this.#element;
|
|
155
|
-
|
|
156
|
-
|
|
173
|
+
let loaded: Promise<void>;
|
|
174
|
+
if (isLocalFileUrl(url)) {
|
|
175
|
+
// A local file has no web address. Read it, then give the <img> a blob: URL for it.
|
|
176
|
+
loaded = getLocalFile(url).then((file) => {
|
|
177
|
+
this.#element.src = URL.createObjectURL(file);
|
|
178
|
+
return this.#element.decode();
|
|
179
|
+
});
|
|
180
|
+
} else {
|
|
181
|
+
this.#element.src = url;
|
|
182
|
+
loaded = this.#element.decode();
|
|
183
|
+
}
|
|
184
|
+
this.#promise = loaded.then(() => {
|
|
157
185
|
if (this.#element.naturalWidth <= 0 || this.#element.naturalHeight <= 0) {
|
|
158
186
|
throw new Error(`Unable to load "${url}".`);
|
|
159
187
|
} else {
|
|
@@ -162,6 +190,10 @@ export class SingleImage extends SlowImage {
|
|
|
162
190
|
});
|
|
163
191
|
// Silence "unhandled rejection" noise in the console.
|
|
164
192
|
// The promise stays rejected — getPromise() callers still receive the error.
|
|
165
|
-
this.#promise.catch(() => {
|
|
193
|
+
this.#promise.catch(() => {
|
|
194
|
+
if (isLocalFileUrl(url)) {
|
|
195
|
+
this.#failedAtGeneration = localFilesGeneration();
|
|
196
|
+
}
|
|
197
|
+
});
|
|
166
198
|
}
|
|
167
199
|
}
|
package/src/snapshot.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ease, easeIn, easeOut } from "./interpolate";
|
|
1
|
+
import { ease, easeIn, easeOut } from "./interpolate.ts";
|
|
2
2
|
import {
|
|
3
3
|
applyScalarSnapshot,
|
|
4
4
|
applySnapshot,
|
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
SerializedSchedule,
|
|
10
10
|
Showable,
|
|
11
11
|
SoundClip,
|
|
12
|
-
} from "./showable";
|
|
13
|
-
import { componentRegistry } from "./slide-components/registry";
|
|
14
|
-
import { SerializedChild, buildComponents } from "./slide-components/serialize";
|
|
12
|
+
} from "./showable.ts";
|
|
13
|
+
import { componentRegistry } from "./slide-components/registry.ts";
|
|
14
|
+
import { SerializedChild, buildComponents } from "./slide-components/serialize.ts";
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Serialized state of one {@link Showable.fixedComponents} item.
|
|
@@ -208,8 +208,7 @@ export function applyFixedComponents(
|
|
|
208
208
|
if (childFixedComponents.length && sc.fixedComponents?.length)
|
|
209
209
|
applyFixedComponents(childFixedComponents, sc.fixedComponents);
|
|
210
210
|
if (sc.duration !== undefined) child.setDuration?.(sc.duration);
|
|
211
|
-
|
|
212
|
-
child.soundClips = sc.soundClips.map((c) => ({ ...c }));
|
|
211
|
+
applySoundClips(child, sc.soundClips);
|
|
213
212
|
if (sc.userEditableDescription !== undefined)
|
|
214
213
|
child.userEditableDescription = sc.userEditableDescription;
|
|
215
214
|
}
|
|
@@ -314,9 +313,29 @@ export function applyJsonEntry(
|
|
|
314
313
|
}
|
|
315
314
|
if (entry.duration !== undefined) selectable.setDuration?.(entry.duration);
|
|
316
315
|
selectable.userEditableDescription = entry.userEditableDescription;
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
316
|
+
applySoundClips(selectable, entry.soundClips);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Give `target` the saved sound clips.
|
|
321
|
+
*
|
|
322
|
+
* Every Showable can hold sound clips, so a missing list means an empty one.
|
|
323
|
+
* That's what makes undo remove the first clip added to a component that had
|
|
324
|
+
* none. It's safe because every tree is filled in with
|
|
325
|
+
* {@link fillTreeDefaults} before it's applied.
|
|
326
|
+
*
|
|
327
|
+
* An existing list is changed in place, since a program may keep a reference
|
|
328
|
+
* to it.
|
|
329
|
+
*/
|
|
330
|
+
function applySoundClips(
|
|
331
|
+
target: Showable,
|
|
332
|
+
saved: readonly SoundClip[] | undefined,
|
|
333
|
+
): void {
|
|
334
|
+
const copies = (saved ?? []).map((clip) => ({ ...clip }));
|
|
335
|
+
if (target.soundClips) {
|
|
336
|
+
target.soundClips.splice(0, Infinity, ...copies);
|
|
337
|
+
} else if (copies.length > 0) {
|
|
338
|
+
target.soundClips = copies;
|
|
320
339
|
}
|
|
321
340
|
}
|
|
322
341
|
|
|
@@ -421,11 +440,9 @@ export function omitComponentDefaults(
|
|
|
421
440
|
if (child.duration !== undefined && child.duration !== fresh.duration) {
|
|
422
441
|
result.duration = child.duration;
|
|
423
442
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
) {
|
|
428
|
-
result.soundClips = child.soundClips;
|
|
443
|
+
// An empty list is the same as none.
|
|
444
|
+
if (!sameJson(child.soundClips ?? [], fresh.soundClips ?? [])) {
|
|
445
|
+
result.soundClips = child.soundClips ?? [];
|
|
429
446
|
}
|
|
430
447
|
return result;
|
|
431
448
|
});
|
|
@@ -478,11 +495,9 @@ export function omitTreeDefaults(
|
|
|
478
495
|
if (tree.duration !== undefined && tree.duration !== defaults?.duration) {
|
|
479
496
|
result.duration = tree.duration;
|
|
480
497
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
) {
|
|
485
|
-
result.soundClips = tree.soundClips;
|
|
498
|
+
// An empty list is the same as none.
|
|
499
|
+
if (!sameJson(tree.soundClips ?? [], defaults?.soundClips ?? [])) {
|
|
500
|
+
result.soundClips = tree.soundClips ?? [];
|
|
486
501
|
}
|
|
487
502
|
if (
|
|
488
503
|
tree.userEditableDescription !== undefined &&
|
package/src/stroke-colors.ts
CHANGED
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
positiveModulo,
|
|
7
7
|
radiansPerDegree,
|
|
8
8
|
} from "phil-lib/misc";
|
|
9
|
-
import { PathShapeSplitter } from "./glib/path-shape-splitter";
|
|
10
|
-
import { countPresent } from "./utility";
|
|
11
|
-
import { myRainbow } from "./glib/my-rainbow";
|
|
12
|
-
import { LCommand, PathShape } from "./glib/path-shape";
|
|
9
|
+
import { PathShapeSplitter } from "./glib/path-shape-splitter.ts";
|
|
10
|
+
import { countPresent } from "./utility.ts";
|
|
11
|
+
import { myRainbow } from "./glib/my-rainbow.ts";
|
|
12
|
+
import { LCommand, PathShape } from "./glib/path-shape.ts";
|
|
13
13
|
|
|
14
14
|
// Bug / TODO
|
|
15
15
|
// Display a zero length path.
|
package/src/utility.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { pick, sum, zip } from "phil-lib/misc";
|
|
2
|
-
import { Showable } from "./showable";
|
|
2
|
+
import { Showable } from "./showable.ts";
|
|
3
|
+
import { canvasRecorder } from "../lib/main-control.ts";
|
|
3
4
|
|
|
4
5
|
export type Mutable<T> = {
|
|
5
6
|
-readonly [P in keyof T]: T[P];
|
|
@@ -58,7 +59,7 @@ export const blackBackground: Showable = {
|
|
|
58
59
|
duration: 0,
|
|
59
60
|
show({ context }) {
|
|
60
61
|
context.fillStyle = "black";
|
|
61
|
-
context.fillRect(0, 0,
|
|
62
|
+
context.fillRect(0, 0, canvasRecorder.width, canvasRecorder.height);
|
|
62
63
|
},
|
|
63
64
|
};
|
|
64
65
|
|
|
@@ -370,9 +371,8 @@ export class ArrayMap<Key, Value> {
|
|
|
370
371
|
* And it makes it easier to find debug stuff from the console.
|
|
371
372
|
* Put it all in one place.
|
|
372
373
|
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
* This replaces `(window as any).something = something`, which does not work in node.
|
|
374
|
+
* It uses `globalThis`, not `window`, so it works in a worker too.
|
|
375
|
+
* This replaces `(window as any).something = something`.
|
|
376
376
|
*/
|
|
377
377
|
export const philDebug: Record<string, any> = {};
|
|
378
378
|
(globalThis as any).philDebug = philDebug;
|