canvas-recorder-lib 0.7.2 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dev/canvas-recorder.ts +376 -105
- package/dist/dev/canvas-recorder.js +306 -88
- package/dist/dev/canvas-recorder.js.map +1 -1
- package/dist/lib/main-control.d.ts +35 -1
- package/dist/lib/main-control.d.ts.map +1 -1
- package/dist/lib/main-control.js +76 -0
- package/dist/lib/main-control.js.map +1 -1
- package/dist/src/showable.d.ts +74 -0
- package/dist/src/showable.d.ts.map +1 -1
- package/dist/src/showable.js.map +1 -1
- package/lib/main-control.ts +92 -1
- package/package.json +1 -1
- package/src/showable.ts +79 -0
package/README.md
CHANGED
|
@@ -222,6 +222,19 @@ For a new project, take the next number and add it here.
|
|
|
222
222
|
When the editor loads saved changes, it rebuilds those children from the registry, so a `description` from your constructor comes back as the registry's default.
|
|
223
223
|
`userEditableDescription` is saved with the rest, and the diff file uses it to match each child with its TypeScript.
|
|
224
224
|
|
|
225
|
+
### Your own panels in the Visual Editor
|
|
226
|
+
|
|
227
|
+
A panel is your own HTML, shown with a component's properties, bottom right, whenever that component is selected.
|
|
228
|
+
It can read the playhead in the component's own time, move it, and change the component's properties.
|
|
229
|
+
See `EditorPanel` in `src/showable.ts`, and the showcase's "Editor Panels" slide (`test-project/src/showcase/editor-panel.ts`).
|
|
230
|
+
|
|
231
|
+
- **On your own component:** give it an `editorPanel`.
|
|
232
|
+
- **On any component, including the library's:** `canvasRecorder.addEditorPanel((component) => …)` returns a panel for the components you choose, and `undefined` for the rest.
|
|
233
|
+
The showcase gives every Fourier a list of its terms this way.
|
|
234
|
+
- **After changing a property, call `propertyChanged()`.** That saves it, like any other edit, and rebuilds the tables.
|
|
235
|
+
- **Anything worth keeping goes in a property.** The panel object lasts as long as its component, but not across a reload.
|
|
236
|
+
- **Touch the DOM only in `start()` and later,** never while a module loads.
|
|
237
|
+
|
|
225
238
|
### Recording a program that has its own state
|
|
226
239
|
|
|
227
240
|
Most of canvas-recorder's components draw any time you ask, in any order.
|
package/dev/canvas-recorder.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
assertNonNullable,
|
|
5
5
|
FIGURE_SPACE,
|
|
6
6
|
parseFloatX,
|
|
7
|
-
parseIntX,
|
|
8
7
|
ReadOnlyRect,
|
|
9
8
|
} from "phil-lib/misc";
|
|
10
9
|
import {
|
|
@@ -22,6 +21,8 @@ import {
|
|
|
22
21
|
QUALITY_HIGH,
|
|
23
22
|
} from "mediabunny";
|
|
24
23
|
import {
|
|
24
|
+
EditorPanel,
|
|
25
|
+
EditorPanelAPI,
|
|
25
26
|
RootComponentEditor,
|
|
26
27
|
SerializedScalar,
|
|
27
28
|
SerializedSchedule,
|
|
@@ -148,7 +149,7 @@ import {
|
|
|
148
149
|
splitSoundClip,
|
|
149
150
|
splitVideoClip,
|
|
150
151
|
} from "../src/slide-components/split-video-clip.ts";
|
|
151
|
-
import { TranscriptView } from "./transcript-view.ts";
|
|
152
|
+
import { TranscriptView, type TranscriptViewClip } from "./transcript-view.ts";
|
|
152
153
|
import { TraditionalTextComponent } from "../src/slide-components/traditional-text.ts";
|
|
153
154
|
import { PaddingComponent } from "../src/slide-components/in-parallel.ts";
|
|
154
155
|
|
|
@@ -521,14 +522,12 @@ function checkVideosLocalFiles() {
|
|
|
521
522
|
* input (pointermove, etc.).
|
|
522
523
|
*/
|
|
523
524
|
function showFrame(timeInMs: number, live: boolean) {
|
|
524
|
-
// While playing, the timeline
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
);
|
|
529
|
-
if (live)
|
|
530
|
-
transcriptView?.update(timeInMs - rootStartMs, playCheckBox.checked);
|
|
525
|
+
// While playing or saving, the timeline and 📖 Text keep the play head on screen.
|
|
526
|
+
const following = !live || playCheckBox.checked;
|
|
527
|
+
timelineDisplay.setPlayMs(timeInMs - rootStartMs, following);
|
|
528
|
+
transcriptView?.update(timeInMs - rootStartMs, following);
|
|
531
529
|
for (const update of goToButtonUpdaters) update();
|
|
530
|
+
editorPanelsTimeChanged();
|
|
532
531
|
context.reset();
|
|
533
532
|
context.setTransform(mainTransform());
|
|
534
533
|
if (live) {
|
|
@@ -1409,6 +1408,7 @@ async function startRecording(
|
|
|
1409
1408
|
|
|
1410
1409
|
await output.start();
|
|
1411
1410
|
infoDiv.innerHTML = "Recording in progress...";
|
|
1411
|
+
showTranscriptViewForSave();
|
|
1412
1412
|
|
|
1413
1413
|
const frameDuration = 1000 / FPS;
|
|
1414
1414
|
|
|
@@ -1532,6 +1532,7 @@ async function startRecording(
|
|
|
1532
1532
|
applyZoom(currentZoomFactor);
|
|
1533
1533
|
}
|
|
1534
1534
|
suspendLiveAnimationLoop = false;
|
|
1535
|
+
endTranscriptViewForSave();
|
|
1535
1536
|
}
|
|
1536
1537
|
}
|
|
1537
1538
|
|
|
@@ -1885,6 +1886,59 @@ function currentRoot(): Showable | undefined {
|
|
|
1885
1886
|
return chapterList[select.selectedIndex]?.selectable;
|
|
1886
1887
|
}
|
|
1887
1888
|
|
|
1889
|
+
// MARK: Chapter paths
|
|
1890
|
+
|
|
1891
|
+
/**
|
|
1892
|
+
* One step down the tree: the child's position among its parent's children, and its name.
|
|
1893
|
+
*
|
|
1894
|
+
* A chapter's row in the `<select>` changes whenever the tree above it changes shape, e.g.
|
|
1895
|
+
* when saved state adds components to an earlier scene. A path of these doesn't.
|
|
1896
|
+
*/
|
|
1897
|
+
type ChapterPathStep = { readonly index: number; readonly name: string };
|
|
1898
|
+
|
|
1899
|
+
/** The name the chapter `<select>` shows. */
|
|
1900
|
+
function chapterName(showable: Showable): string {
|
|
1901
|
+
return showable.userEditableDescription ?? showable.description;
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
/** The way down from the top of the video to this chapter. Find it again with {@link findChapter}. */
|
|
1905
|
+
function chapterPath(info: ShowableTree): ChapterPathStep[] {
|
|
1906
|
+
const path: ChapterPathStep[] = [];
|
|
1907
|
+
for (let step = info; step.parent; step = step.parent) {
|
|
1908
|
+
const child = step.selectable;
|
|
1909
|
+
const index =
|
|
1910
|
+
step.parent.selectable.children?.findIndex((c) => c.child === child) ??
|
|
1911
|
+
-1;
|
|
1912
|
+
path.push({ index, name: chapterName(child) });
|
|
1913
|
+
}
|
|
1914
|
+
return path.reverse();
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
/**
|
|
1918
|
+
* Find a chapter again from its {@link chapterPath}, in a tree that may have changed.
|
|
1919
|
+
*
|
|
1920
|
+
* At each step, the child at the same position if it still has the same name, otherwise the
|
|
1921
|
+
* first sibling with that name. If a step can't be found, the deepest chapter found so far.
|
|
1922
|
+
* @returns An index into {@link chapterList}. 0, the whole video, if nothing matched.
|
|
1923
|
+
*/
|
|
1924
|
+
function findChapter(path: readonly ChapterPathStep[]): number {
|
|
1925
|
+
let current: Showable = toShow;
|
|
1926
|
+
let found = 0;
|
|
1927
|
+
for (const { index, name } of path) {
|
|
1928
|
+
const children = current.children ?? [];
|
|
1929
|
+
const atIndex = children[index]?.child;
|
|
1930
|
+
const next =
|
|
1931
|
+
atIndex && chapterName(atIndex) === name
|
|
1932
|
+
? atIndex
|
|
1933
|
+
: children.find((c) => chapterName(c.child) === name)?.child;
|
|
1934
|
+
if (!next) break;
|
|
1935
|
+
current = next;
|
|
1936
|
+
const position = chapterList.findIndex((d) => d.selectable === next);
|
|
1937
|
+
if (position >= 0) found = position;
|
|
1938
|
+
}
|
|
1939
|
+
return found;
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1888
1942
|
/** When checked, picking another root leaves the play limits alone. */
|
|
1889
1943
|
const keepLimitsCheckbox = getById("keepLimits", HTMLInputElement);
|
|
1890
1944
|
/** Says what the play limits are, below the chapter `<select>`. */
|
|
@@ -1920,6 +1974,8 @@ const visualEditorAPI: VisualEditorAPI = {
|
|
|
1920
1974
|
if (howMuch === "sound") {
|
|
1921
1975
|
soundtrack.request();
|
|
1922
1976
|
} else if (howMuch === "properties") {
|
|
1977
|
+
// A property changed, so it has to be saved, like any other edit.
|
|
1978
|
+
markDirty();
|
|
1923
1979
|
updateScheduleEditor(selectedSlideChild ?? selectable);
|
|
1924
1980
|
} else {
|
|
1925
1981
|
// "structure"
|
|
@@ -2146,6 +2202,124 @@ const timelineWordsMemo = new WeakMap<
|
|
|
2146
2202
|
*/
|
|
2147
2203
|
const scheduleEditorRefreshers: Array<() => void> = [];
|
|
2148
2204
|
|
|
2205
|
+
// MARK: Editor panels
|
|
2206
|
+
|
|
2207
|
+
/** One {@link EditorPanel} shown with the selected component's properties. */
|
|
2208
|
+
type ActivePanel = {
|
|
2209
|
+
readonly panel: EditorPanel;
|
|
2210
|
+
readonly component: Showable;
|
|
2211
|
+
/** What's shown: the panel's element, or an error in its place. */
|
|
2212
|
+
element: HTMLElement;
|
|
2213
|
+
/** False once suspended or broken. Then the panel isn't called again, and its API does nothing. */
|
|
2214
|
+
live: boolean;
|
|
2215
|
+
};
|
|
2216
|
+
|
|
2217
|
+
/**
|
|
2218
|
+
* The panels shown now. Rebuilt by {@link updateScheduleEditor}.
|
|
2219
|
+
* Declared up here because the first schedule editor is built while this module is still loading.
|
|
2220
|
+
*/
|
|
2221
|
+
const activePanels: ActivePanel[] = [];
|
|
2222
|
+
|
|
2223
|
+
/** Where `component` starts, in the Visual Editor's root's time. */
|
|
2224
|
+
function componentStartMs(component: Showable): number {
|
|
2225
|
+
const root = currentRoot();
|
|
2226
|
+
return root ? (startWithin(root, component) ?? 0) : 0;
|
|
2227
|
+
}
|
|
2228
|
+
|
|
2229
|
+
/** The playhead in `component`'s own time: what its `show()` gets as `timeInMs`. */
|
|
2230
|
+
function componentTimeMs(component: Showable): number {
|
|
2231
|
+
return playheadInRootMs() - componentStartMs(component);
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
/** Show `reason` where `active`'s panel was, and stop calling that panel. */
|
|
2235
|
+
function panelFailed(active: ActivePanel, reason: unknown): void {
|
|
2236
|
+
console.error(reason);
|
|
2237
|
+
active.live = false;
|
|
2238
|
+
const name =
|
|
2239
|
+
active.component.userEditableDescription ?? active.component.description;
|
|
2240
|
+
const line = document.createElement("div");
|
|
2241
|
+
line.style.cssText = "color:#b00;margin-bottom:0.4em";
|
|
2242
|
+
line.textContent = `✗ A panel for "${name}" failed: ${String(reason)}`;
|
|
2243
|
+
active.element.replaceWith(line);
|
|
2244
|
+
active.element = line;
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
/** Call into a panel, unless it's suspended or broken. A bug in a panel mustn't break the editor. */
|
|
2248
|
+
function callPanel(
|
|
2249
|
+
active: ActivePanel,
|
|
2250
|
+
call: (panel: EditorPanel) => void,
|
|
2251
|
+
): void {
|
|
2252
|
+
if (!active.live) return;
|
|
2253
|
+
try {
|
|
2254
|
+
call(active.panel);
|
|
2255
|
+
} catch (reason) {
|
|
2256
|
+
panelFailed(active, reason);
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
/** Tell each panel it's going away. Called before every rebuild. */
|
|
2261
|
+
function suspendEditorPanels(): void {
|
|
2262
|
+
for (const active of activePanels.splice(0)) {
|
|
2263
|
+
callPanel(active, (panel) => panel.suspend?.());
|
|
2264
|
+
active.live = false;
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
|
|
2268
|
+
/**
|
|
2269
|
+
* Start `component`'s panels: its own {@link Showable.editorPanel}, then the project's,
|
|
2270
|
+
* from `canvasRecorder.addEditorPanel()`.
|
|
2271
|
+
* @returns The elements to show, in order.
|
|
2272
|
+
*/
|
|
2273
|
+
function startEditorPanels(component: Showable): HTMLElement[] {
|
|
2274
|
+
return canvasRecorder.editorPanelsFor(component).map((panel) => {
|
|
2275
|
+
const active: ActivePanel = {
|
|
2276
|
+
panel,
|
|
2277
|
+
component,
|
|
2278
|
+
element: document.createElement("div"),
|
|
2279
|
+
live: true,
|
|
2280
|
+
};
|
|
2281
|
+
activePanels.push(active);
|
|
2282
|
+
const api: EditorPanelAPI = {
|
|
2283
|
+
getTimeMs: () => componentTimeMs(component),
|
|
2284
|
+
seek(ms) {
|
|
2285
|
+
if (!active.live) return;
|
|
2286
|
+
visualEditorAPI.seek(ms + componentStartMs(component));
|
|
2287
|
+
},
|
|
2288
|
+
propertyChanged(property) {
|
|
2289
|
+
if (!active.live) return;
|
|
2290
|
+
activeRootComponentEditor?.update(component, property);
|
|
2291
|
+
markDirty();
|
|
2292
|
+
// Rebuild so the tables show the new value. That restarts this panel too.
|
|
2293
|
+
updateScheduleEditor(component);
|
|
2294
|
+
},
|
|
2295
|
+
refreshGUI(howMuch) {
|
|
2296
|
+
if (!active.live) return;
|
|
2297
|
+
visualEditorAPI.refreshGUI(howMuch);
|
|
2298
|
+
},
|
|
2299
|
+
};
|
|
2300
|
+
callPanel(active, (panel) => {
|
|
2301
|
+
const element = panel.start(api);
|
|
2302
|
+
if (!(element instanceof HTMLElement)) {
|
|
2303
|
+
throw new Error("start() didn't return an HTMLElement.");
|
|
2304
|
+
}
|
|
2305
|
+
active.element = element;
|
|
2306
|
+
});
|
|
2307
|
+
// Every keystroke in the properties, and every duration change.
|
|
2308
|
+
scheduleEditorRefreshers.push(() =>
|
|
2309
|
+
callPanel(active, (panel) => panel.update?.()),
|
|
2310
|
+
);
|
|
2311
|
+
return active.element;
|
|
2312
|
+
});
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
/** The playhead moved. Called from {@link showFrame}. */
|
|
2316
|
+
function editorPanelsTimeChanged(): void {
|
|
2317
|
+
// A copy: a panel's call may rebuild the list.
|
|
2318
|
+
for (const active of [...activePanels]) {
|
|
2319
|
+
callPanel(active, (panel) => panel.timeChanged?.());
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2149
2323
|
/**
|
|
2150
2324
|
* The schedules the user switched to **Durations**, as opposed to the
|
|
2151
2325
|
* default, **Times**. See {@link buildScheduleSection}.
|
|
@@ -2377,20 +2551,7 @@ onTranscriptsChange(() => {
|
|
|
2377
2551
|
// The transcript as text. It rebuilds itself when the clips or transcripts
|
|
2378
2552
|
// change, so it needs no calls besides the one in showFrame().
|
|
2379
2553
|
transcriptView = new TranscriptView({
|
|
2380
|
-
clips
|
|
2381
|
-
const root = currentRoot();
|
|
2382
|
-
if (!root) return [];
|
|
2383
|
-
return soundOwners(root)
|
|
2384
|
-
.flatMap(({ owner, startMs }) =>
|
|
2385
|
-
(owner.soundClips ?? []).map((clip) => ({
|
|
2386
|
-
clip,
|
|
2387
|
-
owner,
|
|
2388
|
-
startMs: startMs + clip.startMsIntoScene,
|
|
2389
|
-
lengthMs: soundClipLengthMs(clip),
|
|
2390
|
-
})),
|
|
2391
|
-
)
|
|
2392
|
-
.sort((a, b) => a.startMs - b.startMs);
|
|
2393
|
-
},
|
|
2554
|
+
clips: transcriptViewClips,
|
|
2394
2555
|
transcript(source) {
|
|
2395
2556
|
const status = transcriptStatus(source);
|
|
2396
2557
|
if (!status) return undefined;
|
|
@@ -2421,31 +2582,86 @@ transcriptView = new TranscriptView({
|
|
|
2421
2582
|
},
|
|
2422
2583
|
});
|
|
2423
2584
|
getById("timelineCanvas", HTMLCanvasElement).after(transcriptView.element);
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
const
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2585
|
+
|
|
2586
|
+
/** The current chapter's sound clips, in order of time, for 📖 Text. */
|
|
2587
|
+
function transcriptViewClips(): TranscriptViewClip[] {
|
|
2588
|
+
const root = currentRoot();
|
|
2589
|
+
if (!root) return [];
|
|
2590
|
+
return soundOwners(root)
|
|
2591
|
+
.flatMap(({ owner, startMs }) =>
|
|
2592
|
+
(owner.soundClips ?? []).map((clip) => ({
|
|
2593
|
+
clip,
|
|
2594
|
+
owner,
|
|
2595
|
+
startMs: startMs + clip.startMsIntoScene,
|
|
2596
|
+
lengthMs: soundClipLengthMs(clip),
|
|
2597
|
+
})),
|
|
2598
|
+
)
|
|
2599
|
+
.sort((a, b) => a.startMs - b.startMs);
|
|
2600
|
+
}
|
|
2601
|
+
|
|
2602
|
+
// MARK: 📖 Text checkbox
|
|
2603
|
+
|
|
2604
|
+
const transcriptViewCheckbox = getById(
|
|
2605
|
+
"transcriptViewCheckbox",
|
|
2606
|
+
HTMLInputElement,
|
|
2607
|
+
);
|
|
2608
|
+
const TRANSCRIPT_VIEW_KEY = "transcriptView.on";
|
|
2609
|
+
|
|
2610
|
+
/** Show 📖 Text or the timeline, to match the checkbox. */
|
|
2611
|
+
function applyTranscriptViewCheckbox() {
|
|
2612
|
+
const on = transcriptViewCheckbox.checked;
|
|
2613
|
+
transcriptView!.hidden = !on;
|
|
2614
|
+
// The timeline's CSS sets `display`, which would beat the `hidden` attribute.
|
|
2615
|
+
getById("timelineCanvas", HTMLCanvasElement).style.display = on ? "none" : "";
|
|
2616
|
+
if (!on) timelineDisplay.redraw();
|
|
2617
|
+
}
|
|
2618
|
+
|
|
2619
|
+
/**
|
|
2620
|
+
* True while a save has switched to 📖 Text, and the user hasn't touched the checkbox since.
|
|
2621
|
+
* Then the save switches back when it's done.
|
|
2622
|
+
*/
|
|
2623
|
+
let transcriptViewJustForSave = false;
|
|
2624
|
+
|
|
2625
|
+
/**
|
|
2626
|
+
* A save shows 📖 Text by default, so you can read along while it records.
|
|
2627
|
+
* Only when there's something to read: transcripts are on, and the chapter has sound.
|
|
2628
|
+
*/
|
|
2629
|
+
function showTranscriptViewForSave() {
|
|
2630
|
+
if (transcriptViewCheckbox.checked) return;
|
|
2631
|
+
if (!transcriptsEnabled() || transcriptViewClips().length === 0) return;
|
|
2632
|
+
transcriptViewCheckbox.checked = true;
|
|
2633
|
+
transcriptViewJustForSave = true;
|
|
2634
|
+
applyTranscriptViewCheckbox();
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2637
|
+
/** The save is over. Go back to the timeline, unless the user chose since. */
|
|
2638
|
+
function endTranscriptViewForSave() {
|
|
2639
|
+
if (!transcriptViewJustForSave) return;
|
|
2640
|
+
transcriptViewJustForSave = false;
|
|
2641
|
+
transcriptViewCheckbox.checked = false;
|
|
2642
|
+
applyTranscriptViewCheckbox();
|
|
2643
|
+
}
|
|
2644
|
+
|
|
2645
|
+
try {
|
|
2646
|
+
transcriptViewCheckbox.checked =
|
|
2647
|
+
localStorage.getItem(TRANSCRIPT_VIEW_KEY) === "true";
|
|
2648
|
+
} catch {
|
|
2649
|
+
// Remembering is only a convenience.
|
|
2650
|
+
}
|
|
2651
|
+
transcriptViewCheckbox.addEventListener("input", () => {
|
|
2652
|
+
// The user's choice, so a save won't change it back, and it's remembered.
|
|
2653
|
+
transcriptViewJustForSave = false;
|
|
2434
2654
|
try {
|
|
2435
|
-
|
|
2655
|
+
localStorage.setItem(
|
|
2656
|
+
TRANSCRIPT_VIEW_KEY,
|
|
2657
|
+
String(transcriptViewCheckbox.checked),
|
|
2658
|
+
);
|
|
2436
2659
|
} catch {
|
|
2437
|
-
//
|
|
2660
|
+
// See above.
|
|
2438
2661
|
}
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
} catch {
|
|
2443
|
-
// See above.
|
|
2444
|
-
}
|
|
2445
|
-
apply();
|
|
2446
|
-
});
|
|
2447
|
-
apply();
|
|
2448
|
-
}
|
|
2662
|
+
applyTranscriptViewCheckbox();
|
|
2663
|
+
});
|
|
2664
|
+
applyTranscriptViewCheckbox();
|
|
2449
2665
|
|
|
2450
2666
|
timelineDisplay.onSeek = (localMs) => {
|
|
2451
2667
|
stopAudio();
|
|
@@ -2474,6 +2690,7 @@ timelineDisplay.onBlockClick = (id) => {
|
|
|
2474
2690
|
updateComponentEditor(container);
|
|
2475
2691
|
updateScheduleEditor(child);
|
|
2476
2692
|
timelineDisplay.setSelectedId(child);
|
|
2693
|
+
activeRootComponentEditor?.selectionChanged(child);
|
|
2477
2694
|
return true;
|
|
2478
2695
|
}
|
|
2479
2696
|
if (child.children?.length && findIn(child.children, child)) return true;
|
|
@@ -2837,33 +3054,103 @@ function _updateTimeline(selectable: Showable): void {
|
|
|
2837
3054
|
timelineDisplay.setSelectedId(selectedSlideChild ?? undefined);
|
|
2838
3055
|
}
|
|
2839
3056
|
|
|
3057
|
+
/**
|
|
3058
|
+
* Where the user was in the video: the chapter, the play limits, the playhead, and whether
|
|
3059
|
+
* it was playing. {@link saveState} keeps it across a reload.
|
|
3060
|
+
*
|
|
3061
|
+
* Which chapters exist, and where they start, depends on the saved tree, and that's restored
|
|
3062
|
+
* asynchronously, by `initFromDB()`. So this is put back after that, by {@link restorePlace}.
|
|
3063
|
+
*/
|
|
3064
|
+
type SavedPlace = {
|
|
3065
|
+
readonly rootPath: readonly ChapterPathStep[];
|
|
3066
|
+
readonly keepLimits: boolean;
|
|
3067
|
+
readonly limitsPath: readonly ChapterPathStep[] | null;
|
|
3068
|
+
/** From the start of the root, so it stays put if an earlier chapter changes length. null for an empty field. */
|
|
3069
|
+
readonly timeInRootMs: number | null;
|
|
3070
|
+
/** The "on section end" radio button's value. */
|
|
3071
|
+
readonly onSectionEnd: string;
|
|
3072
|
+
readonly wasPlaying: boolean;
|
|
3073
|
+
};
|
|
3074
|
+
|
|
3075
|
+
/**
|
|
3076
|
+
* Read from the last session, waiting for the saved tree to load. If the page unloads
|
|
3077
|
+
* first, {@link saveState} saves this again, not the default place the page is showing.
|
|
3078
|
+
*/
|
|
3079
|
+
let placeToRestore: SavedPlace | undefined;
|
|
3080
|
+
|
|
3081
|
+
function currentPlace(): SavedPlace {
|
|
3082
|
+
const root = chapterList[select.selectedIndex];
|
|
3083
|
+
const limits = chapterList.find((d) => d.selectable === limitsShowable);
|
|
3084
|
+
const timeInRootMs = playheadInRootMs();
|
|
3085
|
+
return {
|
|
3086
|
+
rootPath: root ? chapterPath(root) : [],
|
|
3087
|
+
keepLimits: keepLimitsCheckbox.checked,
|
|
3088
|
+
limitsPath: limits ? chapterPath(limits) : null,
|
|
3089
|
+
timeInRootMs: isFinite(timeInRootMs) ? timeInRootMs : null,
|
|
3090
|
+
onSectionEnd: querySelector(
|
|
3091
|
+
'input[name="onSectionEnd"]:checked',
|
|
3092
|
+
HTMLInputElement,
|
|
3093
|
+
).value,
|
|
3094
|
+
wasPlaying: playCheckBox.checked,
|
|
3095
|
+
};
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
/** Parse what {@link saveState} wrote. undefined if there's nothing, or it's from an older version. */
|
|
3099
|
+
function parseSavedPlace(json: string | null): SavedPlace | undefined {
|
|
3100
|
+
if (!json) return undefined;
|
|
3101
|
+
try {
|
|
3102
|
+
const place = JSON.parse(json) as SavedPlace;
|
|
3103
|
+
return Array.isArray(place?.rootPath) ? place : undefined;
|
|
3104
|
+
} catch {
|
|
3105
|
+
return undefined;
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
/**
|
|
3110
|
+
* Go back to the place saved by the last session, in the tree as it is now.
|
|
3111
|
+
* Call this after the saved tree is restored.
|
|
3112
|
+
*/
|
|
3113
|
+
function restorePlace(place: SavedPlace): void {
|
|
3114
|
+
// The saved tree can change which chapters exist, and where they start.
|
|
3115
|
+
initChapters();
|
|
3116
|
+
select.selectedIndex = findChapter(place.rootPath);
|
|
3117
|
+
updateFromSelect();
|
|
3118
|
+
if (place.keepLimits) {
|
|
3119
|
+
keepLimitsCheckbox.checked = true;
|
|
3120
|
+
if (place.limitsPath) {
|
|
3121
|
+
limitsShowable = chapterList[findChapter(place.limitsPath)].selectable;
|
|
3122
|
+
applyLimits();
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
if (place.timeInRootMs !== null) {
|
|
3126
|
+
const savedMs = rootStartMs + place.timeInRootMs;
|
|
3127
|
+
loadPlayPositionSeconds(
|
|
3128
|
+
Math.max(sectionStartTime, Math.min(sectionEndTime, savedMs)),
|
|
3129
|
+
);
|
|
3130
|
+
}
|
|
3131
|
+
loadPlayPositionRange();
|
|
3132
|
+
// "continue" was removed. A page saved with it pauses instead.
|
|
3133
|
+
const onEnd = document.querySelector<HTMLInputElement>(
|
|
3134
|
+
`input[name="onSectionEnd"][value="${place.onSectionEnd}"]`,
|
|
3135
|
+
);
|
|
3136
|
+
if (onEnd) onEnd.checked = true;
|
|
3137
|
+
if (place.wasPlaying) playCheckBox.checked = true;
|
|
3138
|
+
}
|
|
3139
|
+
|
|
2840
3140
|
/**
|
|
2841
3141
|
* When someone hits refresh in their browser,
|
|
2842
3142
|
* or hits save in vs code so vite causes a refresh,
|
|
2843
3143
|
* restart the user with the same gui settings.
|
|
2844
3144
|
*/
|
|
2845
3145
|
function saveState() {
|
|
2846
|
-
sessionStorage.setItem("index", select.selectedIndex.toString());
|
|
2847
|
-
sessionStorage.setItem("keepLimits", keepLimitsCheckbox.checked ? "1" : "0");
|
|
2848
|
-
sessionStorage.setItem(
|
|
2849
|
-
"limitsIndex",
|
|
2850
|
-
chapterList.findIndex((d) => d.selectable === limitsShowable).toString(),
|
|
2851
|
-
);
|
|
2852
|
-
// From the start of the video, however the field shows it. "" for an empty field.
|
|
2853
|
-
const playheadMs = playheadInVideoMs();
|
|
2854
3146
|
sessionStorage.setItem(
|
|
2855
|
-
"
|
|
2856
|
-
|
|
3147
|
+
"place",
|
|
3148
|
+
JSON.stringify(placeToRestore ?? currentPlace()),
|
|
2857
3149
|
);
|
|
2858
3150
|
sessionStorage.setItem(
|
|
2859
3151
|
"playPositionLocal",
|
|
2860
3152
|
playPositionLocal.checked ? "1" : "0",
|
|
2861
3153
|
);
|
|
2862
|
-
sessionStorage.setItem(
|
|
2863
|
-
"state",
|
|
2864
|
-
querySelector('input[name="onSectionEnd"]:checked', HTMLInputElement).value,
|
|
2865
|
-
);
|
|
2866
|
-
sessionStorage.setItem("wasPlaying", playCheckBox.checked ? "1" : "0");
|
|
2867
3154
|
sessionStorage.setItem("zoomSelect", zoomSelect.value);
|
|
2868
3155
|
sessionStorage.setItem("panX", panX.toString());
|
|
2869
3156
|
sessionStorage.setItem("panY", panY.toString());
|
|
@@ -3894,6 +4181,8 @@ async function initFromDB(unloadBackup?: string | null): Promise<void> {
|
|
|
3894
4181
|
}
|
|
3895
4182
|
_loadSource = source;
|
|
3896
4183
|
_baselineTreeJson = currentTreeJson();
|
|
4184
|
+
// The unload backup is in the database now, or older than it. See the end of "Load previous state".
|
|
4185
|
+
sessionStorage.removeItem("pendingScheduleSave");
|
|
3897
4186
|
|
|
3898
4187
|
canvas.style.visibility = "";
|
|
3899
4188
|
canvasLoading.style.display = "none";
|
|
@@ -4011,6 +4300,11 @@ function currentSaveTarget(): Showable | null {
|
|
|
4011
4300
|
}
|
|
4012
4301
|
|
|
4013
4302
|
function saveOnUnload() {
|
|
4303
|
+
// Still starting up: the live tree is the TypeScript defaults, not the user's work.
|
|
4304
|
+
// A backup of it would be newer than the real state, so the next startup would load it,
|
|
4305
|
+
// and everything made in the Visual Editor would disappear. The last session's backup,
|
|
4306
|
+
// if there was one, is still in sessionStorage until initFromDB() has saved it.
|
|
4307
|
+
if (_loadSource === undefined) return;
|
|
4014
4308
|
// When the history dialog is open the live tree may hold a transient preview from
|
|
4015
4309
|
// _dialogSelectItem. Back up the pre-dialog state instead, so a preview is never
|
|
4016
4310
|
// persisted as if the user had accepted it.
|
|
@@ -6228,6 +6522,7 @@ function buildNameSection(selectable: Showable): HTMLElement {
|
|
|
6228
6522
|
}
|
|
6229
6523
|
|
|
6230
6524
|
function updateScheduleEditor(selectable: Showable) {
|
|
6525
|
+
suspendEditorPanels();
|
|
6231
6526
|
scheduleEditorFieldset.replaceChildren();
|
|
6232
6527
|
editingRectKf = null;
|
|
6233
6528
|
viewingRectKfs.clear();
|
|
@@ -6374,11 +6669,7 @@ function updateScheduleEditor(selectable: Showable) {
|
|
|
6374
6669
|
}
|
|
6375
6670
|
if (selectable instanceof HandwritingEffectComponent) {
|
|
6376
6671
|
const handwritingPanel = buildHandwritingPanel(selectable, {
|
|
6377
|
-
localTimeMs
|
|
6378
|
-
const root = currentRoot();
|
|
6379
|
-
const ownerStart = root ? (startWithin(root, owner) ?? 0) : 0;
|
|
6380
|
-
return playheadInRootMs() - ownerStart;
|
|
6381
|
-
},
|
|
6672
|
+
localTimeMs: componentTimeMs,
|
|
6382
6673
|
progressChanged() {
|
|
6383
6674
|
activeRootComponentEditor?.update(
|
|
6384
6675
|
selectable,
|
|
@@ -6393,6 +6684,9 @@ function updateScheduleEditor(selectable: Showable) {
|
|
|
6393
6684
|
// Every keystroke in Divisions or Progress updates the status.
|
|
6394
6685
|
scheduleEditorRefreshers.push(handwritingPanel.refresh);
|
|
6395
6686
|
}
|
|
6687
|
+
// A component's own panels, and the project's: after the library's, so on a Fourier
|
|
6688
|
+
// the library's status comes first.
|
|
6689
|
+
scheduleEditorFieldset.append(...startEditorPanels(selectable));
|
|
6396
6690
|
|
|
6397
6691
|
for (const info of scalars ?? []) {
|
|
6398
6692
|
const section = buildScalarSection(info, selectable, (s, i) =>
|
|
@@ -7552,6 +7846,12 @@ function applyMarkerDrag(localX: number, localY: number, shiftKey = false) {
|
|
|
7552
7846
|
if (jsonResult.ok) {
|
|
7553
7847
|
applyJsonSnapshot(jsonResult.data, true, false);
|
|
7554
7848
|
}
|
|
7849
|
+
// Now the chapters are the saved tree's, so the last session's place can be found.
|
|
7850
|
+
if (placeToRestore) {
|
|
7851
|
+
const place = placeToRestore;
|
|
7852
|
+
placeToRestore = undefined;
|
|
7853
|
+
restorePlace(place);
|
|
7854
|
+
}
|
|
7555
7855
|
// Catch the synced files up with whatever was restored, rather than
|
|
7556
7856
|
// trusting the last session's final write: a write started as the page
|
|
7557
7857
|
// unloads usually never finishes. (It can't leave a corrupt file, only a
|
|
@@ -7591,46 +7891,8 @@ function applyMarkerDrag(localX: number, localY: number, shiftKey = false) {
|
|
|
7591
7891
|
playPositionLocal.checked = false;
|
|
7592
7892
|
loadPlayPositionSeconds(playheadMs);
|
|
7593
7893
|
}
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
const state = sessionStorage.getItem("state");
|
|
7597
|
-
if (index && timeInSeconds && state) {
|
|
7598
|
-
select.selectedIndex = assertNonNullable(parseIntX(index));
|
|
7599
|
-
if (select.selectedIndex < 0) {
|
|
7600
|
-
// What if you save the state when row 13 is selected, but there are currently
|
|
7601
|
-
// only 5 rows available? That's when we get here. Without this change
|
|
7602
|
-
// updateFromSelect() would throw an exception.
|
|
7603
|
-
select.selectedIndex = 0;
|
|
7604
|
-
}
|
|
7605
|
-
updateFromSelect();
|
|
7606
|
-
if (sessionStorage.getItem("keepLimits") === "1") {
|
|
7607
|
-
keepLimitsCheckbox.checked = true;
|
|
7608
|
-
const limitsIndex = parseIntX(
|
|
7609
|
-
sessionStorage.getItem("limitsIndex") ?? "",
|
|
7610
|
-
);
|
|
7611
|
-
const saved =
|
|
7612
|
-
limitsIndex === undefined ? undefined : chapterList[limitsIndex];
|
|
7613
|
-
if (saved) {
|
|
7614
|
-
limitsShowable = saved.selectable;
|
|
7615
|
-
applyLimits();
|
|
7616
|
-
}
|
|
7617
|
-
}
|
|
7618
|
-
const savedMs = parseFloat(timeInSeconds) * 1000;
|
|
7619
|
-
const clampedMs = Math.max(
|
|
7620
|
-
sectionStartTime,
|
|
7621
|
-
Math.min(sectionEndTime, savedMs),
|
|
7622
|
-
);
|
|
7623
|
-
loadPlayPositionSeconds(clampedMs);
|
|
7624
|
-
loadPlayPositionRange();
|
|
7625
|
-
// "continue" was removed. A page saved with it pauses instead.
|
|
7626
|
-
const onEnd = document.querySelector<HTMLInputElement>(
|
|
7627
|
-
`input[name="onSectionEnd"][value="${state}"]`,
|
|
7628
|
-
);
|
|
7629
|
-
if (onEnd) onEnd.checked = true;
|
|
7630
|
-
if (sessionStorage.getItem("wasPlaying") === "1") {
|
|
7631
|
-
playCheckBox.checked = true;
|
|
7632
|
-
}
|
|
7633
|
-
}
|
|
7894
|
+
// Applied when the saved tree is in: see initFromDB() above.
|
|
7895
|
+
placeToRestore = parseSavedPlace(sessionStorage.getItem("place"));
|
|
7634
7896
|
if (sessionStorage.getItem("quality") === "Low Power") {
|
|
7635
7897
|
getById("lowPower", HTMLInputElement).checked = true;
|
|
7636
7898
|
}
|
|
@@ -7669,6 +7931,15 @@ function applyMarkerDrag(localX: number, localY: number, shiftKey = false) {
|
|
|
7669
7931
|
if (fL) getById("left-col", HTMLDivElement).style.flex = fL;
|
|
7670
7932
|
} finally {
|
|
7671
7933
|
sessionStorage.clear();
|
|
7934
|
+
// Keep the unload backup until initFromDB() has saved it. If the page reloads before
|
|
7935
|
+
// then, saveOnUnload() saves nothing, so this is the only copy.
|
|
7936
|
+
if (unloadBackup !== null) {
|
|
7937
|
+
try {
|
|
7938
|
+
sessionStorage.setItem("pendingScheduleSave", unloadBackup);
|
|
7939
|
+
} catch {
|
|
7940
|
+
// It fit a moment ago.
|
|
7941
|
+
}
|
|
7942
|
+
}
|
|
7672
7943
|
}
|
|
7673
7944
|
}
|
|
7674
7945
|
|