canvas-recorder-lib 0.8.0 β 0.8.3
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 +8 -8
- package/dev/canvas-recorder.css +6 -6
- package/dev/canvas-recorder.ts +62 -10
- package/dev/character-panel.ts +201 -0
- package/dev/delay-files.ts +3 -1
- package/dev/format-editor.ts +36 -0
- package/dev/multi-text-dialog.ts +31 -2
- package/dev/multi-text-panel.ts +6 -0
- package/dev/player-body.ts +3 -3
- package/dev/transcribe-core.ts +7 -4
- package/dev/transcript-align.ts +20 -17
- package/dist/dev/canvas-recorder.css +6 -6
- package/dist/dev/canvas-recorder.js +57 -10
- package/dist/dev/canvas-recorder.js.map +1 -1
- package/dist/dev/character-panel.d.ts +43 -0
- package/dist/dev/character-panel.d.ts.map +1 -0
- package/dist/dev/character-panel.js +133 -0
- package/dist/dev/character-panel.js.map +1 -0
- package/dist/dev/delay-files.d.ts.map +1 -1
- package/dist/dev/delay-files.js +3 -1
- package/dist/dev/delay-files.js.map +1 -1
- package/dist/dev/format-editor.d.ts +16 -0
- package/dist/dev/format-editor.d.ts.map +1 -1
- package/dist/dev/format-editor.js +31 -0
- package/dist/dev/format-editor.js.map +1 -1
- package/dist/dev/multi-text-dialog.d.ts +2 -0
- package/dist/dev/multi-text-dialog.d.ts.map +1 -1
- package/dist/dev/multi-text-dialog.js +26 -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 +6 -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 +3 -3
- package/dist/dev/transcribe-core.d.ts.map +1 -1
- package/dist/dev/transcribe-core.js +7 -4
- package/dist/dev/transcribe-core.js.map +1 -1
- package/dist/dev/transcript-align.d.ts +3 -3
- package/dist/dev/transcript-align.d.ts.map +1 -1
- package/dist/dev/transcript-align.js +16 -13
- package/dist/dev/transcript-align.js.map +1 -1
- package/dist/src/glib/font-choices.d.ts +61 -0
- package/dist/src/glib/font-choices.d.ts.map +1 -0
- package/dist/src/glib/font-choices.js +101 -0
- package/dist/src/glib/font-choices.js.map +1 -0
- package/dist/src/glib/letters-base.d.ts +97 -0
- package/dist/src/glib/letters-base.d.ts.map +1 -1
- package/dist/src/glib/letters-base.js +120 -18
- package/dist/src/glib/letters-base.js.map +1 -1
- package/dist/src/glib/line-font.d.ts +23 -3
- package/dist/src/glib/line-font.d.ts.map +1 -1
- package/dist/src/glib/line-font.js +40 -1
- package/dist/src/glib/line-font.js.map +1 -1
- package/dist/src/glib/path-shape.d.ts +7 -0
- package/dist/src/glib/path-shape.d.ts.map +1 -1
- package/dist/src/glib/path-shape.js +43 -221
- package/dist/src/glib/path-shape.js.map +1 -1
- package/dist/src/glib/svg-arc.d.ts +41 -0
- package/dist/src/glib/svg-arc.d.ts.map +1 -0
- package/dist/src/glib/svg-arc.js +114 -0
- package/dist/src/glib/svg-arc.js.map +1 -0
- package/dist/src/glib/svg-path-parser.d.ts +60 -0
- package/dist/src/glib/svg-path-parser.d.ts.map +1 -0
- package/dist/src/glib/svg-path-parser.js +258 -0
- package/dist/src/glib/svg-path-parser.js.map +1 -0
- package/dist/src/slide-components/fourier.d.ts.map +1 -1
- package/dist/src/slide-components/fourier.js +14 -1
- package/dist/src/slide-components/fourier.js.map +1 -1
- package/dist/src/slide-components/halftone-shadow.d.ts.map +1 -1
- package/dist/src/slide-components/halftone-shadow.js +12 -9
- package/dist/src/slide-components/halftone-shadow.js.map +1 -1
- package/dist/src/slide-components/multi-text.d.ts +24 -0
- package/dist/src/slide-components/multi-text.d.ts.map +1 -1
- package/dist/src/slide-components/multi-text.js +75 -5
- package/dist/src/slide-components/multi-text.js.map +1 -1
- package/dist/src/slide-components/registry.d.ts.map +1 -1
- package/dist/src/slide-components/registry.js +3 -2
- package/dist/src/slide-components/registry.js.map +1 -1
- package/dist/src/slide-components/show-error.d.ts.map +1 -1
- package/dist/src/slide-components/show-error.js +9 -2
- package/dist/src/slide-components/show-error.js.map +1 -1
- package/dist/src/slide-components/simple-text.d.ts +20 -0
- package/dist/src/slide-components/simple-text.d.ts.map +1 -1
- package/dist/src/slide-components/simple-text.js +58 -5
- package/dist/src/slide-components/simple-text.js.map +1 -1
- package/internals.md +402 -406
- package/package.json +1 -1
- package/src/glib/font-choices.ts +132 -0
- package/src/glib/letters-base.ts +212 -18
- package/src/glib/line-font.ts +56 -3
- package/src/glib/path-shape.ts +66 -245
- package/src/glib/svg-arc.ts +141 -0
- package/src/glib/svg-path-parser.ts +308 -0
- package/src/slide-components/fourier.ts +15 -3
- package/src/slide-components/halftone-shadow.ts +12 -9
- package/src/slide-components/multi-text.ts +100 -4
- package/src/slide-components/registry.ts +3 -2
- package/src/slide-components/show-error.ts +9 -2
- package/src/slide-components/simple-text.ts +76 -4
package/BREAKING-CHANGES.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Breaking Changes
|
|
2
2
|
|
|
3
3
|
Changes that can break a project using this library, newest first, and what to do about each.
|
|
4
|
-
This is not a full list of changes:
|
|
4
|
+
This is not a full list of changes: new features and fixes aren't here.
|
|
5
5
|
|
|
6
6
|
While the version is 0.x, every breaking change comes with a new minor version (0.5 β 0.6), and nothing else does.
|
|
7
7
|
A project that depends on `"^0.5.0"` gets 0.5.x updates but never 0.6.0, so it only meets these changes when someone installs the new version on purpose.
|
|
@@ -9,21 +9,21 @@ A project that depends on `"^0.5.0"` gets 0.5.x updates but never 0.6.0, so it o
|
|
|
9
9
|
## 0.8.0 (2026-11-12)
|
|
10
10
|
|
|
11
11
|
- **`samplesToFourier()` leaves out the frequency 0 term,** the center, unless you pass `{ keepCenter: true }`.
|
|
12
|
-
That term is the average of the samples, a fixed offset.
|
|
12
|
+
That term is the average of the samples, a fixed offset. Without it the curve is the same shape, centered on that average.
|
|
13
13
|
`FourierComponent` gets the new default, and so does `getAnimationRules()` given a path string.
|
|
14
14
|
A Fourier component still puts the finished curve in the same place in Dest Rect.
|
|
15
15
|
- **Every term after the center moves down one number,** so Term Groups can add different terms than before.
|
|
16
|
-
For art drawn away from the origin, the center is often term 0, and everything moves.
|
|
17
|
-
For a shape centered on the origin, the center is tiny and far down the list (the showcase's Star:
|
|
18
|
-
- To get the same picture, subtract 1 from every term number after the center's.
|
|
19
|
-
The finished curve is the same either way.
|
|
20
|
-
- Code that needs the terms to add up to exactly the samples, in place, should pass `{ keepCenter: true }`.
|
|
16
|
+
For art drawn away from the origin, the center is often term 0, and everything moves. (The showcase's Walking Man: term 0, 45% of the total amplitude.)
|
|
17
|
+
For a shape centered on the origin, the center is tiny and far down the list (the showcase's Star: term 42), so only a group that ends past it changes, by one small term.
|
|
18
|
+
- To get the same picture, subtract 1 from every term number after the center's. The showcase's Fourier Component slide did: `0 1, 2, 3-5, 6-8, 9-11` became `0, 1, 2-4, 5-7, 8-10`.
|
|
19
|
+
The finished curve is the same either way. What goes away is the step that slid the curve to the center.
|
|
20
|
+
- Code that needs the terms to add up to exactly the samples, in place, should pass `{ keepCenter: true }`. The showcase's Fourier Morph does.
|
|
21
21
|
|
|
22
22
|
## 0.7.0 (2026-11-07)
|
|
23
23
|
|
|
24
24
|
- **`VisualEditorAPI.getDecodedBuffer()` returns a mono buffer,** at 48 kHz, for every file.
|
|
25
25
|
It used to return the file's own channels, so a stereo file's channel 0 was its left channel; now it's the average of both.
|
|
26
|
-
A waveform drawn from channel 0 still works, and shows the whole sound.
|
|
26
|
+
A waveform drawn from channel 0 still works, and shows the whole sound. Code that reads channel 1 should read channel 0.
|
|
27
27
|
|
|
28
28
|
## 0.6.0 (2026-11-05)
|
|
29
29
|
|
package/dev/canvas-recorder.css
CHANGED
|
@@ -31,7 +31,7 @@ body {
|
|
|
31
31
|
|
|
32
32
|
/* ββ Vertical resize handle between left/right columns ββββββββββββββββ */
|
|
33
33
|
|
|
34
|
-
#
|
|
34
|
+
#v-resize {
|
|
35
35
|
width: 5px;
|
|
36
36
|
background: #999;
|
|
37
37
|
cursor: ew-resize;
|
|
@@ -40,14 +40,14 @@ body {
|
|
|
40
40
|
user-select: none;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
#
|
|
44
|
-
#
|
|
43
|
+
#v-resize:hover,
|
|
44
|
+
#v-resize.dragging {
|
|
45
45
|
background: #444;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/* ββ Horizontal resize handle between top/bottom of each column βββββββ */
|
|
49
49
|
|
|
50
|
-
.
|
|
50
|
+
.h-resize {
|
|
51
51
|
height: 5px;
|
|
52
52
|
background: #999;
|
|
53
53
|
cursor: ns-resize;
|
|
@@ -55,8 +55,8 @@ body {
|
|
|
55
55
|
user-select: none;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
.
|
|
59
|
-
.
|
|
58
|
+
.h-resize:hover,
|
|
59
|
+
.h-resize.dragging {
|
|
60
60
|
background: #444;
|
|
61
61
|
}
|
|
62
62
|
|
package/dev/canvas-recorder.ts
CHANGED
|
@@ -136,11 +136,16 @@ import {
|
|
|
136
136
|
} from "../src/slide-components/serialize.ts";
|
|
137
137
|
import { SlideComponent } from "../src/slide-components/slide-component.ts";
|
|
138
138
|
import { VideoClipComponent } from "../src/slide-components/video-clip.ts";
|
|
139
|
-
import {
|
|
139
|
+
import {
|
|
140
|
+
MultiTextComponent,
|
|
141
|
+
TextFormatComponent,
|
|
142
|
+
} from "../src/slide-components/multi-text.ts";
|
|
143
|
+
import { TextComponent } from "../src/slide-components/simple-text.ts";
|
|
140
144
|
import { FourierComponent } from "../src/slide-components/fourier.ts";
|
|
141
145
|
import { buildFourierPanel } from "./fourier-panel.ts";
|
|
142
146
|
import { HandwritingEffectComponent } from "../src/slide-components/handwriting-effect.ts";
|
|
143
147
|
import { buildHandwritingPanel } from "./handwriting-panel.ts";
|
|
148
|
+
import { buildCharacterPanel, CharacterPanel } from "./character-panel.ts";
|
|
144
149
|
import { SingleImageComponent } from "../src/slide-components/image.ts";
|
|
145
150
|
import { buildStaticImagePanel } from "./static-image-panel.ts";
|
|
146
151
|
import { InSeriesComponent } from "../src/slide-components/in-series.ts";
|
|
@@ -6741,6 +6746,15 @@ function updateScheduleEditor(selectable: Showable) {
|
|
|
6741
6746
|
// Every keystroke in Divisions or Progress updates the status.
|
|
6742
6747
|
scheduleEditorRefreshers.push(handwritingPanel.refresh);
|
|
6743
6748
|
}
|
|
6749
|
+
const characterPanel = buildCharacterPanelFor(selectable);
|
|
6750
|
+
if (characterPanel) {
|
|
6751
|
+
// The warnings here, the list of characters after the properties.
|
|
6752
|
+
scheduleEditorFieldset.append(characterPanel.status);
|
|
6753
|
+
// Every keystroke in Text, and a new Font.
|
|
6754
|
+
scheduleEditorRefreshers.push(characterPanel.refresh);
|
|
6755
|
+
// The Font at the playhead is the one the list shows.
|
|
6756
|
+
goToButtonUpdaters.push(characterPanel.timeChanged);
|
|
6757
|
+
}
|
|
6744
6758
|
// A component's own panels, and the project's: after the library's, so on a Fourier
|
|
6745
6759
|
// the library's status comes first.
|
|
6746
6760
|
scheduleEditorFieldset.append(...startEditorPanels(selectable));
|
|
@@ -6795,9 +6809,45 @@ function updateScheduleEditor(selectable: Showable) {
|
|
|
6795
6809
|
}
|
|
6796
6810
|
scheduleEditorFieldset.append(section);
|
|
6797
6811
|
}
|
|
6812
|
+
if (characterPanel) {
|
|
6813
|
+
scheduleEditorFieldset.append(characterPanel.palette);
|
|
6814
|
+
}
|
|
6798
6815
|
scheduleEditorFieldset.append(buildSoundClipSection(selectable));
|
|
6799
6816
|
}
|
|
6800
6817
|
|
|
6818
|
+
/**
|
|
6819
|
+
* The Characters panel for a Text or a Text Format, or undefined for anything else.
|
|
6820
|
+
*
|
|
6821
|
+
* A Text Format doesn't know its text, so its warnings come from its Multi Text: the
|
|
6822
|
+
* ones for this format. The Multi Text shows them all, in its Text Frame panel.
|
|
6823
|
+
*/
|
|
6824
|
+
function buildCharacterPanelFor(
|
|
6825
|
+
selectable: Showable,
|
|
6826
|
+
): CharacterPanel | undefined {
|
|
6827
|
+
if (selectable instanceof TextComponent) {
|
|
6828
|
+
return buildCharacterPanel({
|
|
6829
|
+
fontName: () => selectable.fontSchedule.at(componentTimeMs(selectable)),
|
|
6830
|
+
missing: () => selectable.missingCharacters(),
|
|
6831
|
+
});
|
|
6832
|
+
}
|
|
6833
|
+
if (selectable instanceof TextFormatComponent) {
|
|
6834
|
+
return buildCharacterPanel({
|
|
6835
|
+
fontName: () => selectable.fontSchedule.at(componentTimeMs(selectable)),
|
|
6836
|
+
missing() {
|
|
6837
|
+
const parent = (selectable as Showable).parent;
|
|
6838
|
+
if (!(parent instanceof MultiTextComponent)) return [];
|
|
6839
|
+
const name = selectable.nameScalar.value;
|
|
6840
|
+
return parent.formatInScope(name) === selectable
|
|
6841
|
+
? parent
|
|
6842
|
+
.missingCharacters()
|
|
6843
|
+
.filter(({ formatName }) => formatName === name)
|
|
6844
|
+
: [];
|
|
6845
|
+
},
|
|
6846
|
+
});
|
|
6847
|
+
}
|
|
6848
|
+
return undefined;
|
|
6849
|
+
}
|
|
6850
|
+
|
|
6801
6851
|
// MARK: Split
|
|
6802
6852
|
|
|
6803
6853
|
/**
|
|
@@ -7030,6 +7080,7 @@ function buildMultiTextFrame(text: MultiTextComponent): HTMLElement {
|
|
|
7030
7080
|
if (root) updateComponentEditor(root);
|
|
7031
7081
|
updateScheduleEditor(text);
|
|
7032
7082
|
},
|
|
7083
|
+
timeMs: () => componentTimeMs(text),
|
|
7033
7084
|
});
|
|
7034
7085
|
},
|
|
7035
7086
|
});
|
|
@@ -8243,8 +8294,9 @@ getById("dumpDbBtn", HTMLButtonElement).addEventListener("click", async () => {
|
|
|
8243
8294
|
const pre = getById("dbDump", HTMLPreElement);
|
|
8244
8295
|
const lines: string[] = [];
|
|
8245
8296
|
|
|
8297
|
+
const entryCount = videoRecord?.entries.length ?? 0;
|
|
8246
8298
|
lines.push(
|
|
8247
|
-
`=== videos["${toShowKey}"] β ${
|
|
8299
|
+
`=== videos["${toShowKey}"] β ${entryCount} ${entryCount === 1 ? "entry" : "entries"} ===`,
|
|
8248
8300
|
);
|
|
8249
8301
|
const latest = videoRecord?.entries.at(-1);
|
|
8250
8302
|
lines.push(latest ? JSON.stringify(latest, null, 2) : "(none)");
|
|
@@ -8353,7 +8405,7 @@ async function fetchJsonSnapshot(): Promise<FetchJsonResult> {
|
|
|
8353
8405
|
*
|
|
8354
8406
|
* A stored entry now covers the entire video, but the Load dialog has always acted on
|
|
8355
8407
|
* whatever the chapter selector points at. Locating `target` inside the snapshot keeps that
|
|
8356
|
-
*
|
|
8408
|
+
* behavior: picking an older entry while a single slide is selected reverts that slide and
|
|
8357
8409
|
* leaves its siblings alone. Selecting the root applies everything.
|
|
8358
8410
|
*/
|
|
8359
8411
|
function applyScopedToTarget(
|
|
@@ -8516,25 +8568,25 @@ function initResizeHandle(handle: HTMLElement, topPane: HTMLElement): void {
|
|
|
8516
8568
|
}
|
|
8517
8569
|
|
|
8518
8570
|
initResizeHandle(
|
|
8519
|
-
getById("
|
|
8571
|
+
getById("h-resize-left", HTMLDivElement),
|
|
8520
8572
|
getById("top-left", HTMLDivElement),
|
|
8521
8573
|
);
|
|
8522
8574
|
initResizeHandle(
|
|
8523
|
-
getById("
|
|
8575
|
+
getById("h-resize-right", HTMLDivElement),
|
|
8524
8576
|
getById("top-right", HTMLDivElement),
|
|
8525
8577
|
);
|
|
8526
8578
|
|
|
8527
8579
|
{
|
|
8528
|
-
const
|
|
8580
|
+
const vHandle = getById("v-resize", HTMLDivElement);
|
|
8529
8581
|
const leftCol = getById("left-col", HTMLDivElement);
|
|
8530
8582
|
const MIN_COL = 80;
|
|
8531
8583
|
const vStorageKey = "pane-width-left-col";
|
|
8532
8584
|
|
|
8533
|
-
|
|
8585
|
+
vHandle.addEventListener("mousedown", (startEvent) => {
|
|
8534
8586
|
startEvent.preventDefault();
|
|
8535
|
-
|
|
8587
|
+
vHandle.classList.add("dragging");
|
|
8536
8588
|
const totalW = document.body.getBoundingClientRect().width;
|
|
8537
|
-
const handleW =
|
|
8589
|
+
const handleW = vHandle.getBoundingClientRect().width;
|
|
8538
8590
|
const startClientX = startEvent.clientX;
|
|
8539
8591
|
const startColW = leftCol.getBoundingClientRect().width;
|
|
8540
8592
|
|
|
@@ -8551,7 +8603,7 @@ initResizeHandle(
|
|
|
8551
8603
|
};
|
|
8552
8604
|
|
|
8553
8605
|
const onUp = () => {
|
|
8554
|
-
|
|
8606
|
+
vHandle.classList.remove("dragging");
|
|
8555
8607
|
document.removeEventListener("mousemove", onMove);
|
|
8556
8608
|
document.removeEventListener("mouseup", onUp);
|
|
8557
8609
|
// flex is "0 0 X%" β store just the percentage part
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import {
|
|
2
|
+
allFontCharacters,
|
|
3
|
+
fontCharacters,
|
|
4
|
+
FontName,
|
|
5
|
+
MissingCharacters,
|
|
6
|
+
} from "../src/glib/font-choices.ts";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The Characters panel, for a Text Format or a Text: every character any
|
|
10
|
+
* font has, with the ones this font doesn't have grayed out. Click one to
|
|
11
|
+
* copy it. And a warning when the text uses a character its font doesn't
|
|
12
|
+
* have.
|
|
13
|
+
*
|
|
14
|
+
* The β Edit Text dialog has one too, where a click types the character.
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export type CharacterPanelHooks = {
|
|
19
|
+
/** The font to gray the characters for: the one at the playhead, or at the cursor. */
|
|
20
|
+
fontName(): FontName;
|
|
21
|
+
/**
|
|
22
|
+
* What to warn about. See `MultiTextComponent.missingCharacters()`.
|
|
23
|
+
* Without this, {@link CharacterPanel.status} stays empty.
|
|
24
|
+
*/
|
|
25
|
+
missing?(): readonly MissingCharacters[];
|
|
26
|
+
/**
|
|
27
|
+
* Clicking a character calls this, instead of copying it. For a panel next to a
|
|
28
|
+
* text field: type the character at the cursor. Clicking doesn't take the focus.
|
|
29
|
+
*/
|
|
30
|
+
onPick?(char: string): void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type CharacterPanel = {
|
|
34
|
+
/** The warnings. Empty, and taking no room, when there's nothing to warn about. */
|
|
35
|
+
readonly status: HTMLElement;
|
|
36
|
+
/** The characters. Goes after the properties: it's tall, and it's for reference. */
|
|
37
|
+
readonly palette: HTMLElement;
|
|
38
|
+
/** Something may have changed: the font, the text. Redraw. */
|
|
39
|
+
refresh(): void;
|
|
40
|
+
/** The playhead or the cursor moved. Cheap unless the font changed. */
|
|
41
|
+
timeChanged(): void;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** Unavailable characters, and the note that counts them. */
|
|
45
|
+
const GRAY = "#b0b0b0";
|
|
46
|
+
|
|
47
|
+
/** Whether the list is open. It stays the way you left it, from one component to the next. */
|
|
48
|
+
let paletteOpen = true;
|
|
49
|
+
|
|
50
|
+
/** A character you can't see, like the no-break space, by its code point. */
|
|
51
|
+
function isInvisible(char: string): boolean {
|
|
52
|
+
return /^[\p{C}\p{Z}]$/u.test(char);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function codePoint(char: string): string {
|
|
56
|
+
return (
|
|
57
|
+
"U+" + char.codePointAt(0)!.toString(16).toUpperCase().padStart(4, "0")
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** βΟββ, with anything invisible spelled out: βΟβ and U+0009. */
|
|
62
|
+
export function showCharacters(characters: readonly string[]): string {
|
|
63
|
+
const visible = characters.filter((char) => !isInvisible(char));
|
|
64
|
+
const invisible = characters.filter(isInvisible).map(codePoint);
|
|
65
|
+
return [...(visible.length ? [`β${visible.join("")}β`] : []), ...invisible]
|
|
66
|
+
.join(" and ")
|
|
67
|
+
.replace(/ and (?=.* and )/g, ", ");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* One warning line's text.
|
|
72
|
+
* @param withFormat Name the Text Format. For a Multi Text, which has several.
|
|
73
|
+
*/
|
|
74
|
+
export function describeMissing(
|
|
75
|
+
{ fontName, formatName, characters }: MissingCharacters,
|
|
76
|
+
withFormat: boolean,
|
|
77
|
+
): string {
|
|
78
|
+
const where =
|
|
79
|
+
withFormat && formatName !== undefined
|
|
80
|
+
? ` (Text Format β${formatName}β)`
|
|
81
|
+
: "";
|
|
82
|
+
return `β Not available in ${fontName}${where}, so not drawn: ${showCharacters(characters)}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function buildCharacterPanel(
|
|
86
|
+
hooks: CharacterPanelHooks,
|
|
87
|
+
): CharacterPanel {
|
|
88
|
+
const status = document.createElement("div");
|
|
89
|
+
status.style.cssText = "font-size:0.9em;color:#a06000;line-height:1.4";
|
|
90
|
+
|
|
91
|
+
const palette = document.createElement("fieldset");
|
|
92
|
+
palette.style.cssText = "border-color:#6a7fae;margin-top:0.4em";
|
|
93
|
+
const legend = document.createElement("legend");
|
|
94
|
+
legend.textContent = "Characters";
|
|
95
|
+
const details = document.createElement("details");
|
|
96
|
+
details.open = paletteOpen;
|
|
97
|
+
details.addEventListener("toggle", () => {
|
|
98
|
+
paletteOpen = details.open;
|
|
99
|
+
});
|
|
100
|
+
const summary = document.createElement("summary");
|
|
101
|
+
summary.style.cssText = "cursor:pointer;font-size:0.9em";
|
|
102
|
+
const grid = document.createElement("div");
|
|
103
|
+
grid.style.cssText =
|
|
104
|
+
"display:flex;flex-wrap:wrap;gap:2px;margin-top:0.3em;user-select:text";
|
|
105
|
+
const note = document.createElement("div");
|
|
106
|
+
note.style.cssText = `font-size:0.85em;color:${GRAY};margin-top:0.3em`;
|
|
107
|
+
const copied = document.createElement("div");
|
|
108
|
+
copied.style.cssText = "font-size:0.85em;color:#555;min-height:1.2em";
|
|
109
|
+
details.append(summary, grid, note);
|
|
110
|
+
palette.append(legend, details);
|
|
111
|
+
if (!hooks.onPick) {
|
|
112
|
+
palette.append(copied);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// MARK: The grid
|
|
116
|
+
|
|
117
|
+
const cells = allFontCharacters().map((char) => {
|
|
118
|
+
const cell = document.createElement("button");
|
|
119
|
+
cell.type = "button";
|
|
120
|
+
const invisible = isInvisible(char);
|
|
121
|
+
// U+FE0E asks for the plain text version of a character like β«, not a color emoji
|
|
122
|
+
// that ignores the gray. Only for showing it: the copy is just `char`.
|
|
123
|
+
cell.textContent = invisible
|
|
124
|
+
? codePoint(char).slice(2)
|
|
125
|
+
: /\p{Extended_Pictographic}/u.test(char)
|
|
126
|
+
? char + "\uFE0E"
|
|
127
|
+
: char;
|
|
128
|
+
cell.style.cssText =
|
|
129
|
+
"min-width:1.9em;height:1.9em;padding:0 0.15em;font-size:1.05em;" +
|
|
130
|
+
"border:1px solid #ddd;border-radius:3px;background:white;cursor:pointer" +
|
|
131
|
+
(invisible ? ";font-size:0.6em;min-width:3.2em;height:3.2em" : "");
|
|
132
|
+
if (hooks.onPick) {
|
|
133
|
+
// Leave the focus, and so the cursor, in the text.
|
|
134
|
+
cell.addEventListener("mousedown", (event) => event.preventDefault());
|
|
135
|
+
}
|
|
136
|
+
cell.addEventListener("click", () => {
|
|
137
|
+
if (hooks.onPick) {
|
|
138
|
+
hooks.onPick(char);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
navigator.clipboard.writeText(char).then(
|
|
142
|
+
() => {
|
|
143
|
+
copied.textContent = `Copied ${showCharacters([char])}.`;
|
|
144
|
+
},
|
|
145
|
+
(reason: unknown) => {
|
|
146
|
+
copied.textContent = `Couldn't copy: ${String(reason)}`;
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
return { char, cell };
|
|
151
|
+
});
|
|
152
|
+
grid.append(...cells.map(({ cell }) => cell));
|
|
153
|
+
|
|
154
|
+
// MARK: Behavior
|
|
155
|
+
|
|
156
|
+
let shownFont: FontName | undefined;
|
|
157
|
+
|
|
158
|
+
function drawPalette(fontName: FontName): void {
|
|
159
|
+
shownFont = fontName;
|
|
160
|
+
const available = fontCharacters(fontName);
|
|
161
|
+
let elsewhere = 0;
|
|
162
|
+
for (const { char, cell } of cells) {
|
|
163
|
+
const has = available.has(char);
|
|
164
|
+
if (!has) elsewhere++;
|
|
165
|
+
cell.style.color = has ? "black" : GRAY;
|
|
166
|
+
cell.title =
|
|
167
|
+
`${codePoint(char)}` +
|
|
168
|
+
(char == "Β " ? ", no-break space: joins two words" : "") +
|
|
169
|
+
(has ? "" : `. Not in ${fontName}.`) +
|
|
170
|
+
(hooks.onPick ? "\nClick to type it." : "\nClick to copy.");
|
|
171
|
+
}
|
|
172
|
+
summary.textContent = hooks.onPick
|
|
173
|
+
? `${available.size} in ${fontName}, the font at the cursor. Click one to type it.`
|
|
174
|
+
: `${available.size} in ${fontName}. Click one to copy it.`;
|
|
175
|
+
note.textContent =
|
|
176
|
+
elsewhere == 0
|
|
177
|
+
? ""
|
|
178
|
+
: `${elsewhere} ${elsewhere == 1 ? "character" : "characters"} only available in other fonts`;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function refresh(): void {
|
|
182
|
+
drawPalette(hooks.fontName());
|
|
183
|
+
status.replaceChildren(
|
|
184
|
+
...(hooks.missing?.() ?? []).map((missing) => {
|
|
185
|
+
const line = document.createElement("div");
|
|
186
|
+
line.textContent = describeMissing(missing, false);
|
|
187
|
+
return line;
|
|
188
|
+
}),
|
|
189
|
+
);
|
|
190
|
+
status.style.marginBottom = status.childElementCount ? "0.4em" : "";
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function timeChanged(): void {
|
|
194
|
+
if (hooks.fontName() !== shownFont) {
|
|
195
|
+
drawPalette(hooks.fontName());
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
refresh();
|
|
200
|
+
return { status, palette, refresh, timeChanged };
|
|
201
|
+
}
|
package/dev/delay-files.ts
CHANGED
|
@@ -31,7 +31,9 @@ export function watchServiceWorkerReady(): void {
|
|
|
31
31
|
|
|
32
32
|
navigator.serviceWorker.getRegistration().then((registration) => {
|
|
33
33
|
if (!registration) {
|
|
34
|
-
|
|
34
|
+
// TODO move this to the test project.
|
|
35
|
+
// See β## Quick Cleanupβ in test-project.md for more details.
|
|
36
|
+
// console.log("No service worker registered.");
|
|
35
37
|
}
|
|
36
38
|
// Else wait for `ready` to resolve.
|
|
37
39
|
});
|
package/dev/format-editor.ts
CHANGED
|
@@ -45,6 +45,12 @@ export class FormatEditor {
|
|
|
45
45
|
*/
|
|
46
46
|
onChange: ((value: string) => void) | undefined;
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Called when the cursor moves inside the editor, including after a change.
|
|
50
|
+
* See {@link formatAtCursor}.
|
|
51
|
+
*/
|
|
52
|
+
onCursorMove: (() => void) | undefined;
|
|
53
|
+
|
|
48
54
|
#knownNames: readonly string[] = [];
|
|
49
55
|
/**
|
|
50
56
|
* If the user deletes the leading format, we put this one back.
|
|
@@ -117,6 +123,7 @@ export class FormatEditor {
|
|
|
117
123
|
const selection = this.#getSelection();
|
|
118
124
|
if (selection) {
|
|
119
125
|
this.#lastSelection = selection;
|
|
126
|
+
this.onCursorMove?.();
|
|
120
127
|
}
|
|
121
128
|
},
|
|
122
129
|
{ signal: this.#abort.signal },
|
|
@@ -192,6 +199,35 @@ export class FormatEditor {
|
|
|
192
199
|
}
|
|
193
200
|
}
|
|
194
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Type `text` at the cursor, replacing the selection, as if the user had typed it.
|
|
204
|
+
* For a button outside the editor: the cursor is where it was last, even if the
|
|
205
|
+
* button took the focus. Format markers in `text` are dropped.
|
|
206
|
+
*/
|
|
207
|
+
insertText(text: string) {
|
|
208
|
+
const selection = this.#getSelection() ??
|
|
209
|
+
this.#lastSelection ?? {
|
|
210
|
+
start: this.#units().length,
|
|
211
|
+
end: this.#units().length,
|
|
212
|
+
};
|
|
213
|
+
this.element.focus();
|
|
214
|
+
this.#replace(selection, pushContent([], text), "typing");
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The name of the format in effect at the cursor, or where the cursor was last.
|
|
219
|
+
* Text typed there would be in this format.
|
|
220
|
+
*/
|
|
221
|
+
formatAtCursor(): string {
|
|
222
|
+
const units = this.#units();
|
|
223
|
+
const offset = (this.#getSelection() ?? this.#lastSelection)?.start;
|
|
224
|
+
// Before the leading format, typing goes after it. See #replace().
|
|
225
|
+
return (
|
|
226
|
+
formatInEffect(units, Math.max(1, offset ?? units.length)) ??
|
|
227
|
+
this.#leadingName
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
195
231
|
undo() {
|
|
196
232
|
if (this.#historyIndex > 0) {
|
|
197
233
|
this.#historyIndex--;
|
package/dev/multi-text-dialog.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
TextFormatComponent,
|
|
5
5
|
TextSpanComponent,
|
|
6
6
|
} from "../src/slide-components/multi-text.ts";
|
|
7
|
+
import { buildCharacterPanel, describeMissing } from "./character-panel.ts";
|
|
7
8
|
import { FormatEditor } from "./format-editor.ts";
|
|
8
9
|
|
|
9
10
|
/** What the dialog needs from the Visual Editor. It never reaches into canvas-recorder.ts directly. */
|
|
@@ -19,6 +20,8 @@ export type MultiTextDialogHooks = {
|
|
|
19
20
|
readonly copyComponent: (component: Showable) => Showable | undefined;
|
|
20
21
|
/** The dialog closed. Rebuild the editors it covered. */
|
|
21
22
|
readonly closed: () => void;
|
|
23
|
+
/** The Multi Text's own time at the playhead. A format's Font can change over time. */
|
|
24
|
+
readonly timeMs: () => number;
|
|
22
25
|
};
|
|
23
26
|
|
|
24
27
|
/** Someone animated this span, by hand or in TypeScript. Editing its text flattens it. */
|
|
@@ -107,7 +110,10 @@ export async function openMultiTextDialog(
|
|
|
107
110
|
toolbar.append(insertFormatBtn);
|
|
108
111
|
const notes = document.createElement("div");
|
|
109
112
|
notes.style.cssText = "font-size:0.85em;color:#a06000;margin-top:0.3em";
|
|
110
|
-
|
|
113
|
+
/** Characters a font doesn't have. It changes as you type, so it's apart from the notes. */
|
|
114
|
+
const missingLines = document.createElement("div");
|
|
115
|
+
missingLines.style.cssText = notes.style.cssText;
|
|
116
|
+
top.append(heading, hint, toolbar, notes, missingLines);
|
|
111
117
|
|
|
112
118
|
const middle = document.createElement("div");
|
|
113
119
|
middle.style.cssText = "flex:1;overflow-y:auto;padding:0.8em";
|
|
@@ -167,6 +173,16 @@ export async function openMultiTextDialog(
|
|
|
167
173
|
);
|
|
168
174
|
}
|
|
169
175
|
}
|
|
176
|
+
/** Every character the text uses that its font doesn't have, over the whole timeline. */
|
|
177
|
+
const showMissing = () => {
|
|
178
|
+
missingLines.replaceChildren(
|
|
179
|
+
...text.missingCharacters().map((missing) => {
|
|
180
|
+
const div = document.createElement("div");
|
|
181
|
+
div.textContent = describeMissing(missing, true);
|
|
182
|
+
return div;
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
185
|
+
};
|
|
170
186
|
const noFormatsNote = note(
|
|
171
187
|
"This text has no Text Formats yet. Pick New⦠in a menu to make one.",
|
|
172
188
|
);
|
|
@@ -174,6 +190,7 @@ export async function openMultiTextDialog(
|
|
|
174
190
|
const formatsChanged = () => {
|
|
175
191
|
editor.knownNames = text.formatNamesInScope();
|
|
176
192
|
noFormatsNote.hidden = editor.knownNames.length > 0;
|
|
193
|
+
showMissing();
|
|
177
194
|
};
|
|
178
195
|
|
|
179
196
|
// MARK: Behavior
|
|
@@ -185,7 +202,16 @@ export async function openMultiTextDialog(
|
|
|
185
202
|
onNewFormat: newFormat,
|
|
186
203
|
});
|
|
187
204
|
editor.element.style.minHeight = "12rem";
|
|
188
|
-
|
|
205
|
+
// Grayed for the font of the format at the cursor. A click types the character there.
|
|
206
|
+
const characters = buildCharacterPanel({
|
|
207
|
+
fontName: () =>
|
|
208
|
+
text
|
|
209
|
+
.formatInScope(editor.formatAtCursor())
|
|
210
|
+
?.fontSchedule.at(hooks.timeMs()) ?? "Line Font",
|
|
211
|
+
onPick: (char) => editor.insertText(char),
|
|
212
|
+
});
|
|
213
|
+
editor.onCursorMove = () => characters.timeChanged();
|
|
214
|
+
middle.append(editor.element, errorLine, characters.palette);
|
|
189
215
|
formatsChanged();
|
|
190
216
|
|
|
191
217
|
editor.onChange = (value) => {
|
|
@@ -199,6 +225,9 @@ export async function openMultiTextDialog(
|
|
|
199
225
|
}
|
|
200
226
|
errorLine.textContent = "";
|
|
201
227
|
revertBtn.disabled = false;
|
|
228
|
+
showMissing();
|
|
229
|
+
// Picking another format in a menu doesn't move the cursor.
|
|
230
|
+
characters.timeChanged();
|
|
202
231
|
hooks.changed();
|
|
203
232
|
};
|
|
204
233
|
|
package/dev/multi-text-panel.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
tidyRect,
|
|
13
13
|
} from "./rect-snap.ts";
|
|
14
14
|
import { buildNumericInput } from "./schedule-helpers.ts";
|
|
15
|
+
import { describeMissing } from "./character-panel.ts";
|
|
15
16
|
|
|
16
17
|
/** Whether the frame is drawn on the canvas (π), and whether it has handles to drag (β). */
|
|
17
18
|
export type CanvasState = {
|
|
@@ -232,6 +233,11 @@ export function buildTextFramePanel(
|
|
|
232
233
|
`Height Mode is unbounded, so the frame's ${sideways ? "width" : "height"} doesn't limit the text.`,
|
|
233
234
|
);
|
|
234
235
|
}
|
|
236
|
+
// Over the whole timeline, not just the playhead. Select a Text Format to see every
|
|
237
|
+
// character its font has.
|
|
238
|
+
for (const missing of text.missingCharacters()) {
|
|
239
|
+
note(describeMissing(missing, true));
|
|
240
|
+
}
|
|
235
241
|
}
|
|
236
242
|
|
|
237
243
|
refresh();
|
package/dev/player-body.ts
CHANGED
|
@@ -98,7 +98,7 @@ export const playerBodyHtml = `
|
|
|
98
98
|
<div id="canvasLoading">Loadingβ¦</div>
|
|
99
99
|
</div>
|
|
100
100
|
</div>
|
|
101
|
-
<div class="
|
|
101
|
+
<div class="h-resize" id="h-resize-left"></div>
|
|
102
102
|
<div id="bottom-left">
|
|
103
103
|
<fieldset id="liveControls">
|
|
104
104
|
<fieldset id="play-controls">
|
|
@@ -263,7 +263,7 @@ export const playerBodyHtml = `
|
|
|
263
263
|
</div>
|
|
264
264
|
|
|
265
265
|
<!-- ββ Vertical resize handle βββββββββββββββββββββββββββββββββββββ -->
|
|
266
|
-
<div id="
|
|
266
|
+
<div id="v-resize"></div>
|
|
267
267
|
|
|
268
268
|
<!-- ββ Right column ββββββββββββββββββββββββββββββββββββββββββββββ -->
|
|
269
269
|
<div id="right-col">
|
|
@@ -301,7 +301,7 @@ export const playerBodyHtml = `
|
|
|
301
301
|
<!-- dynamically populated by canvas-recorder.ts -->
|
|
302
302
|
</fieldset>
|
|
303
303
|
</div>
|
|
304
|
-
<div class="
|
|
304
|
+
<div class="h-resize" id="h-resize-right"></div>
|
|
305
305
|
<div id="bottom-right">
|
|
306
306
|
<fieldset id="scheduleEditor">
|
|
307
307
|
<p>Coming soon! Edit fields here. TODO.</p>
|
package/dev/transcribe-core.ts
CHANGED
|
@@ -244,18 +244,21 @@ export class Transcriber {
|
|
|
244
244
|
const step =
|
|
245
245
|
ALIGNER_WINDOW_SAMPLES - 2 * ALIGNER_OVERLAP_FRAMES * ALIGNER_HOP_SAMPLES;
|
|
246
246
|
let vocabularySize = 0;
|
|
247
|
-
let
|
|
247
|
+
let logProbabilities = new Float32Array(0);
|
|
248
248
|
/** Frames filled in so far, from the start. */
|
|
249
249
|
let written = 0;
|
|
250
250
|
for (let offset = 0; written < frameCount; offset += step) {
|
|
251
251
|
onProgress?.({ stage: "aligning", fraction: offset / samples.length });
|
|
252
252
|
const window = samples.subarray(offset, offset + ALIGNER_WINDOW_SAMPLES);
|
|
253
253
|
const isLast = offset + ALIGNER_WINDOW_SAMPLES >= samples.length;
|
|
254
|
+
// "Logits" is the machine-learning word for a model's raw scores: any
|
|
255
|
+
// number, higher is more likely. logSoftmax() turns them into log
|
|
256
|
+
// probabilities. The name comes from transformers.js, so it stays.
|
|
254
257
|
const { logits } = await model(await processor(window));
|
|
255
258
|
const [, frames, size] = logits.dims as number[];
|
|
256
259
|
if (vocabularySize === 0) {
|
|
257
260
|
vocabularySize = size;
|
|
258
|
-
|
|
261
|
+
logProbabilities = new Float32Array(frameCount * size);
|
|
259
262
|
}
|
|
260
263
|
const data = logits.data as Float32Array;
|
|
261
264
|
const base = offset / ALIGNER_HOP_SAMPLES;
|
|
@@ -266,7 +269,7 @@ export class Transcriber {
|
|
|
266
269
|
);
|
|
267
270
|
const to = isLast ? frames : frames - ALIGNER_OVERLAP_FRAMES;
|
|
268
271
|
for (let k = from; k < to && base + k < frameCount; k++) {
|
|
269
|
-
logSoftmax(data, k * size, size,
|
|
272
|
+
logSoftmax(data, k * size, size, logProbabilities, (base + k) * size);
|
|
270
273
|
written = base + k + 1;
|
|
271
274
|
}
|
|
272
275
|
if (isLast) break;
|
|
@@ -278,7 +281,7 @@ export class Transcriber {
|
|
|
278
281
|
}
|
|
279
282
|
const letterOf = (token: number) => letters.get(token);
|
|
280
283
|
return {
|
|
281
|
-
|
|
284
|
+
logProbabilities,
|
|
282
285
|
vocabularySize,
|
|
283
286
|
frameCount: written,
|
|
284
287
|
frameMs: (ALIGNER_HOP_SAMPLES / SAMPLE_RATE) * 1000,
|