canvas-recorder-lib 0.7.4 → 0.8.1
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 +15 -2
- package/dev/canvas-recorder.css +5 -1
- package/dev/canvas-recorder.ts +122 -14
- package/dev/character-panel.ts +201 -0
- package/dev/format-editor.ts +36 -0
- package/dev/fourier-panel.ts +3 -2
- package/dev/multi-text-dialog.ts +31 -2
- package/dev/multi-text-panel.ts +6 -0
- package/dist/dev/canvas-recorder.css +5 -1
- package/dist/dev/canvas-recorder.js +101 -14
- 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/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/fourier-panel.d.ts.map +1 -1
- package/dist/dev/fourier-panel.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/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/peano-fourier/fourier-shared.d.ts +32 -1
- package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.js +21 -3
- package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
- package/dist/src/slide-components/fourier.d.ts +8 -3
- package/dist/src/slide-components/fourier.d.ts.map +1 -1
- package/dist/src/slide-components/fourier.js +11 -4
- package/dist/src/slide-components/fourier.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/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/peano-fourier/fourier-shared.ts +47 -5
- package/src/slide-components/fourier.ts +19 -8
- package/src/slide-components/multi-text.ts +100 -4
- package/src/slide-components/registry.ts +3 -2
- package/src/slide-components/simple-text.ts +76 -4
package/BREAKING-CHANGES.md
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
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.
|
|
8
8
|
|
|
9
|
+
## 0.8.0 (2026-11-12)
|
|
10
|
+
|
|
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. Without it the curve is the same shape, centered on that average.
|
|
13
|
+
`FourierComponent` gets the new default, and so does `getAnimationRules()` given a path string.
|
|
14
|
+
A Fourier component still puts the finished curve in the same place in Dest Rect.
|
|
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. (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
|
+
|
|
9
22
|
## 0.7.0 (2026-11-07)
|
|
10
23
|
|
|
11
24
|
- **`VisualEditorAPI.getDecodedBuffer()` returns a mono buffer,** at 48 kHz, for every file.
|
|
12
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.
|
|
13
|
-
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.
|
|
14
27
|
|
|
15
28
|
## 0.6.0 (2026-11-05)
|
|
16
29
|
|
package/dev/canvas-recorder.css
CHANGED
|
@@ -90,6 +90,10 @@ body {
|
|
|
90
90
|
#main {
|
|
91
91
|
position: absolute;
|
|
92
92
|
outline: 1px solid rgba(0, 0, 0, 0.3);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* Set by applyZoom() when part of the canvas is out of sight. */
|
|
96
|
+
#main.pannable {
|
|
93
97
|
cursor: grab;
|
|
94
98
|
}
|
|
95
99
|
|
|
@@ -104,7 +108,7 @@ body {
|
|
|
104
108
|
pointer-events: none;
|
|
105
109
|
}
|
|
106
110
|
|
|
107
|
-
#main:active {
|
|
111
|
+
#main.pannable:active {
|
|
108
112
|
cursor: grabbing;
|
|
109
113
|
}
|
|
110
114
|
|
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";
|
|
@@ -224,20 +229,24 @@ function clampPan(
|
|
|
224
229
|
px: number,
|
|
225
230
|
py: number,
|
|
226
231
|
): [number, number] {
|
|
227
|
-
|
|
228
|
-
const viewportHeight = viewport.clientHeight;
|
|
229
|
-
if (canvasCssWidth <= viewportWidth) {
|
|
230
|
-
return [
|
|
231
|
-
Math.round((viewportWidth - canvasCssWidth) / 2),
|
|
232
|
-
Math.round((viewportHeight - canvasCssHeight) / 2),
|
|
233
|
-
];
|
|
234
|
-
}
|
|
232
|
+
// Each direction on its own: a portrait video at 100% can fit across but not down.
|
|
235
233
|
return [
|
|
236
|
-
|
|
237
|
-
|
|
234
|
+
clampPanAxis(canvasCssWidth, viewport.clientWidth, px),
|
|
235
|
+
clampPanAxis(canvasCssHeight, viewport.clientHeight, py),
|
|
238
236
|
];
|
|
239
237
|
}
|
|
240
238
|
|
|
239
|
+
/** Centered if the canvas fits this way, otherwise no gap at either edge. */
|
|
240
|
+
function clampPanAxis(
|
|
241
|
+
canvasSize: number,
|
|
242
|
+
viewportSize: number,
|
|
243
|
+
pan: number,
|
|
244
|
+
): number {
|
|
245
|
+
return canvasSize <= viewportSize
|
|
246
|
+
? Math.round((viewportSize - canvasSize) / 2)
|
|
247
|
+
: Math.max(viewportSize - canvasSize, Math.min(0, pan));
|
|
248
|
+
}
|
|
249
|
+
|
|
241
250
|
/**
|
|
242
251
|
* Resizes the canvas to match zoom and repositions it via left/top.
|
|
243
252
|
* zoom = 1.0 → 3840×2160 physical pixels, displayed at 1920×1080 CSS px on Retina.
|
|
@@ -268,6 +277,11 @@ function applyZoom(zoom: number, px = panX, py = panY) {
|
|
|
268
277
|
[panX, panY] = clampPan(cssW, cssH, px, py);
|
|
269
278
|
canvas.style.left = `${panX}px`;
|
|
270
279
|
canvas.style.top = `${panY}px`;
|
|
280
|
+
// The hand cursor, only when there's something to drag into view.
|
|
281
|
+
canvas.classList.toggle(
|
|
282
|
+
"pannable",
|
|
283
|
+
cssW > viewport.clientWidth || cssH > viewport.clientHeight,
|
|
284
|
+
);
|
|
271
285
|
}
|
|
272
286
|
|
|
273
287
|
/** Fits the 16:9 canvas into the viewport at pixel-perfect resolution. */
|
|
@@ -297,6 +311,7 @@ function zoomToFit() {
|
|
|
297
311
|
canvas.style.height = `${cssH}px`;
|
|
298
312
|
canvas.style.left = `${Math.round((vpW - cssW) / 2)}px`;
|
|
299
313
|
canvas.style.top = `${Math.round((vpH - cssH) / 2)}px`;
|
|
314
|
+
canvas.classList.remove("pannable");
|
|
300
315
|
// Immediately redraw so the canvas clear doesn't show as a gray flash.
|
|
301
316
|
showFrame(playheadInVideoMs(), true);
|
|
302
317
|
}
|
|
@@ -1344,6 +1359,8 @@ async function startRecording(
|
|
|
1344
1359
|
canvas.style.top = "50%";
|
|
1345
1360
|
canvas.style.transform = "translate(-50%, -50%)";
|
|
1346
1361
|
canvas.style.transformOrigin = "";
|
|
1362
|
+
// No panning while saving. The finally block puts the zoom back, and this with it.
|
|
1363
|
+
canvas.classList.remove("pannable");
|
|
1347
1364
|
|
|
1348
1365
|
// `output` is created inside the try block below, but we need to reach it
|
|
1349
1366
|
// from the catch block too, so we can still finalize (and thus flush)
|
|
@@ -2457,11 +2474,26 @@ function applyLimits(): void {
|
|
|
2457
2474
|
: "";
|
|
2458
2475
|
}
|
|
2459
2476
|
|
|
2477
|
+
/**
|
|
2478
|
+
* Two playhead times this close are the same: {@link playPositionSeconds} shows ⅒ ms.
|
|
2479
|
+
*/
|
|
2480
|
+
const PLAYHEAD_TOLERANCE_MS = 0.1;
|
|
2481
|
+
|
|
2482
|
+
/**
|
|
2483
|
+
* Set when {@link refreshChapters} pulled the playhead back inside a chapter that got shorter.
|
|
2484
|
+
* Durations change on every keystroke, so typing 25000 over 30000 makes the chapter 2 ms long
|
|
2485
|
+
* on the way. If the chapter grows again before the playhead moves, it goes back toward `fromMs`.
|
|
2486
|
+
* Both are in the video's time.
|
|
2487
|
+
*/
|
|
2488
|
+
let playheadPulledBack: { fromMs: number; toMs: number } | undefined;
|
|
2489
|
+
|
|
2460
2490
|
/**
|
|
2461
2491
|
* Switch the Visual Editor to the root picked in the `<select>`. The play
|
|
2462
2492
|
* limits follow, unless Keep play limits is checked.
|
|
2463
2493
|
*/
|
|
2464
2494
|
function updateFromSelect() {
|
|
2495
|
+
// Where the playhead was in another chapter means nothing here.
|
|
2496
|
+
playheadPulledBack = undefined;
|
|
2465
2497
|
const info = chapterList[select.selectedIndex];
|
|
2466
2498
|
setRootStartMs(info.start);
|
|
2467
2499
|
if (keepLimitsCheckbox.checked && limitsShowable) {
|
|
@@ -2509,12 +2541,42 @@ playRootBtn.addEventListener("click", () => {
|
|
|
2509
2541
|
* playback and the editors alone. When it's gone, this switches roots properly.
|
|
2510
2542
|
*/
|
|
2511
2543
|
function refreshChapters(): void {
|
|
2544
|
+
const playheadMs = playheadInVideoMs();
|
|
2545
|
+
// Not moved since the last clamp: aim for where it was before that.
|
|
2546
|
+
if (
|
|
2547
|
+
playheadPulledBack &&
|
|
2548
|
+
Math.abs(playheadMs - playheadPulledBack.toMs) > PLAYHEAD_TOLERANCE_MS
|
|
2549
|
+
) {
|
|
2550
|
+
playheadPulledBack = undefined;
|
|
2551
|
+
}
|
|
2552
|
+
const wantedMs = playheadPulledBack?.fromMs ?? playheadMs;
|
|
2553
|
+
// limitsChapter still has the start and end from before this change.
|
|
2554
|
+
const old = limitsChapter;
|
|
2555
|
+
const wasInside =
|
|
2556
|
+
playheadPulledBack !== undefined ||
|
|
2557
|
+
old === undefined ||
|
|
2558
|
+
(playheadMs >= old.start - PLAYHEAD_TOLERANCE_MS &&
|
|
2559
|
+
playheadMs <= old.end + PLAYHEAD_TOLERANCE_MS);
|
|
2512
2560
|
if (initChapters()) {
|
|
2513
2561
|
setRootStartMs(chapterList[select.selectedIndex].start);
|
|
2514
2562
|
applyLimits();
|
|
2515
|
-
//
|
|
2516
|
-
//
|
|
2517
|
-
//
|
|
2563
|
+
// A shorter chapter can leave the playhead past its end, showing nothing. Keep it inside
|
|
2564
|
+
// the play limits. sectionEndTime already stops just short of the next chapter's start.
|
|
2565
|
+
// A playhead the user put outside the limits stays there.
|
|
2566
|
+
if (wasInside) {
|
|
2567
|
+
const clampedMs = Math.max(
|
|
2568
|
+
sectionStartTime,
|
|
2569
|
+
Math.min(sectionEndTime, wantedMs),
|
|
2570
|
+
);
|
|
2571
|
+
if (Math.abs(clampedMs - playheadMs) > PLAYHEAD_TOLERANCE_MS) {
|
|
2572
|
+
loadPlayPositionSeconds(clampedMs);
|
|
2573
|
+
}
|
|
2574
|
+
playheadPulledBack =
|
|
2575
|
+
clampedMs === wantedMs
|
|
2576
|
+
? undefined
|
|
2577
|
+
: { fromMs: wantedMs, toMs: clampedMs };
|
|
2578
|
+
}
|
|
2579
|
+
// The range clamped itself to the new bounds; show the real position again.
|
|
2518
2580
|
loadPlayPositionRange();
|
|
2519
2581
|
} else {
|
|
2520
2582
|
updateFromSelect();
|
|
@@ -6684,6 +6746,15 @@ function updateScheduleEditor(selectable: Showable) {
|
|
|
6684
6746
|
// Every keystroke in Divisions or Progress updates the status.
|
|
6685
6747
|
scheduleEditorRefreshers.push(handwritingPanel.refresh);
|
|
6686
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
|
+
}
|
|
6687
6758
|
// A component's own panels, and the project's: after the library's, so on a Fourier
|
|
6688
6759
|
// the library's status comes first.
|
|
6689
6760
|
scheduleEditorFieldset.append(...startEditorPanels(selectable));
|
|
@@ -6738,9 +6809,45 @@ function updateScheduleEditor(selectable: Showable) {
|
|
|
6738
6809
|
}
|
|
6739
6810
|
scheduleEditorFieldset.append(section);
|
|
6740
6811
|
}
|
|
6812
|
+
if (characterPanel) {
|
|
6813
|
+
scheduleEditorFieldset.append(characterPanel.palette);
|
|
6814
|
+
}
|
|
6741
6815
|
scheduleEditorFieldset.append(buildSoundClipSection(selectable));
|
|
6742
6816
|
}
|
|
6743
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
|
+
|
|
6744
6851
|
// MARK: Split
|
|
6745
6852
|
|
|
6746
6853
|
/**
|
|
@@ -6973,6 +7080,7 @@ function buildMultiTextFrame(text: MultiTextComponent): HTMLElement {
|
|
|
6973
7080
|
if (root) updateComponentEditor(root);
|
|
6974
7081
|
updateScheduleEditor(text);
|
|
6975
7082
|
},
|
|
7083
|
+
timeMs: () => componentTimeMs(text),
|
|
6976
7084
|
});
|
|
6977
7085
|
},
|
|
6978
7086
|
});
|
|
@@ -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/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/fourier-panel.ts
CHANGED
|
@@ -67,8 +67,9 @@ import {
|
|
|
67
67
|
// * fourier-shared.ts, cacheHealth (philDebug.cacheHealth): hits and misses of
|
|
68
68
|
// the per-t cache in termsToParametricFunction().
|
|
69
69
|
// * fourier-shared.ts, hasFixedContribution(): finds the frequency 0 term,
|
|
70
|
-
// the center.
|
|
71
|
-
//
|
|
70
|
+
// the center. samplesToFourier() leaves it out unless asked to keep it, so
|
|
71
|
+
// only a `terms` source can have it. checkTermGroups() already warns when
|
|
72
|
+
// it's a group of its own.
|
|
72
73
|
|
|
73
74
|
export type FourierPanel = {
|
|
74
75
|
readonly element: HTMLElement;
|
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();
|
|
@@ -90,6 +90,10 @@ body {
|
|
|
90
90
|
#main {
|
|
91
91
|
position: absolute;
|
|
92
92
|
outline: 1px solid rgba(0, 0, 0, 0.3);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* Set by applyZoom() when part of the canvas is out of sight. */
|
|
96
|
+
#main.pannable {
|
|
93
97
|
cursor: grab;
|
|
94
98
|
}
|
|
95
99
|
|
|
@@ -104,7 +108,7 @@ body {
|
|
|
104
108
|
pointer-events: none;
|
|
105
109
|
}
|
|
106
110
|
|
|
107
|
-
#main:active {
|
|
111
|
+
#main.pannable:active {
|
|
108
112
|
cursor: grabbing;
|
|
109
113
|
}
|
|
110
114
|
|