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.
Files changed (69) hide show
  1. package/BREAKING-CHANGES.md +15 -2
  2. package/dev/canvas-recorder.css +5 -1
  3. package/dev/canvas-recorder.ts +122 -14
  4. package/dev/character-panel.ts +201 -0
  5. package/dev/format-editor.ts +36 -0
  6. package/dev/fourier-panel.ts +3 -2
  7. package/dev/multi-text-dialog.ts +31 -2
  8. package/dev/multi-text-panel.ts +6 -0
  9. package/dist/dev/canvas-recorder.css +5 -1
  10. package/dist/dev/canvas-recorder.js +101 -14
  11. package/dist/dev/canvas-recorder.js.map +1 -1
  12. package/dist/dev/character-panel.d.ts +43 -0
  13. package/dist/dev/character-panel.d.ts.map +1 -0
  14. package/dist/dev/character-panel.js +133 -0
  15. package/dist/dev/character-panel.js.map +1 -0
  16. package/dist/dev/format-editor.d.ts +16 -0
  17. package/dist/dev/format-editor.d.ts.map +1 -1
  18. package/dist/dev/format-editor.js +31 -0
  19. package/dist/dev/format-editor.js.map +1 -1
  20. package/dist/dev/fourier-panel.d.ts.map +1 -1
  21. package/dist/dev/fourier-panel.js.map +1 -1
  22. package/dist/dev/multi-text-dialog.d.ts +2 -0
  23. package/dist/dev/multi-text-dialog.d.ts.map +1 -1
  24. package/dist/dev/multi-text-dialog.js +26 -2
  25. package/dist/dev/multi-text-dialog.js.map +1 -1
  26. package/dist/dev/multi-text-panel.d.ts.map +1 -1
  27. package/dist/dev/multi-text-panel.js +6 -0
  28. package/dist/dev/multi-text-panel.js.map +1 -1
  29. package/dist/src/glib/font-choices.d.ts +61 -0
  30. package/dist/src/glib/font-choices.d.ts.map +1 -0
  31. package/dist/src/glib/font-choices.js +101 -0
  32. package/dist/src/glib/font-choices.js.map +1 -0
  33. package/dist/src/glib/letters-base.d.ts +97 -0
  34. package/dist/src/glib/letters-base.d.ts.map +1 -1
  35. package/dist/src/glib/letters-base.js +120 -18
  36. package/dist/src/glib/letters-base.js.map +1 -1
  37. package/dist/src/glib/line-font.d.ts +23 -3
  38. package/dist/src/glib/line-font.d.ts.map +1 -1
  39. package/dist/src/glib/line-font.js +40 -1
  40. package/dist/src/glib/line-font.js.map +1 -1
  41. package/dist/src/peano-fourier/fourier-shared.d.ts +32 -1
  42. package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
  43. package/dist/src/peano-fourier/fourier-shared.js +21 -3
  44. package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
  45. package/dist/src/slide-components/fourier.d.ts +8 -3
  46. package/dist/src/slide-components/fourier.d.ts.map +1 -1
  47. package/dist/src/slide-components/fourier.js +11 -4
  48. package/dist/src/slide-components/fourier.js.map +1 -1
  49. package/dist/src/slide-components/multi-text.d.ts +24 -0
  50. package/dist/src/slide-components/multi-text.d.ts.map +1 -1
  51. package/dist/src/slide-components/multi-text.js +75 -5
  52. package/dist/src/slide-components/multi-text.js.map +1 -1
  53. package/dist/src/slide-components/registry.d.ts.map +1 -1
  54. package/dist/src/slide-components/registry.js +3 -2
  55. package/dist/src/slide-components/registry.js.map +1 -1
  56. package/dist/src/slide-components/simple-text.d.ts +20 -0
  57. package/dist/src/slide-components/simple-text.d.ts.map +1 -1
  58. package/dist/src/slide-components/simple-text.js +58 -5
  59. package/dist/src/slide-components/simple-text.js.map +1 -1
  60. package/internals.md +402 -406
  61. package/package.json +1 -1
  62. package/src/glib/font-choices.ts +132 -0
  63. package/src/glib/letters-base.ts +212 -18
  64. package/src/glib/line-font.ts +56 -3
  65. package/src/peano-fourier/fourier-shared.ts +47 -5
  66. package/src/slide-components/fourier.ts +19 -8
  67. package/src/slide-components/multi-text.ts +100 -4
  68. package/src/slide-components/registry.ts +3 -2
  69. package/src/slide-components/simple-text.ts +76 -4
@@ -34,11 +34,13 @@ import { pickComponent } from "./component-picker.js";
34
34
  import { buildComponents, } from "../src/slide-components/serialize.js";
35
35
  import { SlideComponent } from "../src/slide-components/slide-component.js";
36
36
  import { VideoClipComponent } from "../src/slide-components/video-clip.js";
37
- import { MultiTextComponent } from "../src/slide-components/multi-text.js";
37
+ import { MultiTextComponent, TextFormatComponent, } from "../src/slide-components/multi-text.js";
38
+ import { TextComponent } from "../src/slide-components/simple-text.js";
38
39
  import { FourierComponent } from "../src/slide-components/fourier.js";
39
40
  import { buildFourierPanel } from "./fourier-panel.js";
40
41
  import { HandwritingEffectComponent } from "../src/slide-components/handwriting-effect.js";
41
42
  import { buildHandwritingPanel } from "./handwriting-panel.js";
43
+ import { buildCharacterPanel } from "./character-panel.js";
42
44
  import { SingleImageComponent } from "../src/slide-components/image.js";
43
45
  import { buildStaticImagePanel } from "./static-image-panel.js";
44
46
  import { InSeriesComponent } from "../src/slide-components/in-series.js";
@@ -97,19 +99,18 @@ let isRecording = false;
97
99
  * When the canvas is smaller than the viewport, centers it instead.
98
100
  */
99
101
  function clampPan(canvasCssWidth, canvasCssHeight, px, py) {
100
- const viewportWidth = viewport.clientWidth;
101
- const viewportHeight = viewport.clientHeight;
102
- if (canvasCssWidth <= viewportWidth) {
103
- return [
104
- Math.round((viewportWidth - canvasCssWidth) / 2),
105
- Math.round((viewportHeight - canvasCssHeight) / 2),
106
- ];
107
- }
102
+ // Each direction on its own: a portrait video at 100% can fit across but not down.
108
103
  return [
109
- Math.max(viewportWidth - canvasCssWidth, Math.min(0, px)),
110
- Math.max(viewportHeight - canvasCssHeight, Math.min(0, py)),
104
+ clampPanAxis(canvasCssWidth, viewport.clientWidth, px),
105
+ clampPanAxis(canvasCssHeight, viewport.clientHeight, py),
111
106
  ];
112
107
  }
108
+ /** Centered if the canvas fits this way, otherwise no gap at either edge. */
109
+ function clampPanAxis(canvasSize, viewportSize, pan) {
110
+ return canvasSize <= viewportSize
111
+ ? Math.round((viewportSize - canvasSize) / 2)
112
+ : Math.max(viewportSize - canvasSize, Math.min(0, pan));
113
+ }
113
114
  /**
114
115
  * Resizes the canvas to match zoom and repositions it via left/top.
115
116
  * zoom = 1.0 → 3840×2160 physical pixels, displayed at 1920×1080 CSS px on Retina.
@@ -141,6 +142,8 @@ function applyZoom(zoom, px = panX, py = panY) {
141
142
  [panX, panY] = clampPan(cssW, cssH, px, py);
142
143
  canvas.style.left = `${panX}px`;
143
144
  canvas.style.top = `${panY}px`;
145
+ // The hand cursor, only when there's something to drag into view.
146
+ canvas.classList.toggle("pannable", cssW > viewport.clientWidth || cssH > viewport.clientHeight);
144
147
  }
145
148
  /** Fits the 16:9 canvas into the viewport at pixel-perfect resolution. */
146
149
  function zoomToFit() {
@@ -165,6 +168,7 @@ function zoomToFit() {
165
168
  canvas.style.height = `${cssH}px`;
166
169
  canvas.style.left = `${Math.round((vpW - cssW) / 2)}px`;
167
170
  canvas.style.top = `${Math.round((vpH - cssH) / 2)}px`;
171
+ canvas.classList.remove("pannable");
168
172
  // Immediately redraw so the canvas clear doesn't show as a gray flash.
169
173
  showFrame(playheadInVideoMs(), true);
170
174
  }
@@ -1119,6 +1123,8 @@ async function startRecording(saveStartMs = 0, saveEndMs = toShow.duration, pixe
1119
1123
  canvas.style.top = "50%";
1120
1124
  canvas.style.transform = "translate(-50%, -50%)";
1121
1125
  canvas.style.transformOrigin = "";
1126
+ // No panning while saving. The finally block puts the zoom back, and this with it.
1127
+ canvas.classList.remove("pannable");
1122
1128
  // `output` is created inside the try block below, but we need to reach it
1123
1129
  // from the catch block too, so we can still finalize (and thus flush)
1124
1130
  // whatever got encoded before the error.
@@ -2029,11 +2035,24 @@ function applyLimits() {
2029
2035
  ? `Play “${root.description}” instead: set the play limits to its start and end, and go to its start.`
2030
2036
  : "";
2031
2037
  }
2038
+ /**
2039
+ * Two playhead times this close are the same: {@link playPositionSeconds} shows ⅒ ms.
2040
+ */
2041
+ const PLAYHEAD_TOLERANCE_MS = 0.1;
2042
+ /**
2043
+ * Set when {@link refreshChapters} pulled the playhead back inside a chapter that got shorter.
2044
+ * Durations change on every keystroke, so typing 25000 over 30000 makes the chapter 2 ms long
2045
+ * on the way. If the chapter grows again before the playhead moves, it goes back toward `fromMs`.
2046
+ * Both are in the video's time.
2047
+ */
2048
+ let playheadPulledBack;
2032
2049
  /**
2033
2050
  * Switch the Visual Editor to the root picked in the `<select>`. The play
2034
2051
  * limits follow, unless Keep play limits is checked.
2035
2052
  */
2036
2053
  function updateFromSelect() {
2054
+ // Where the playhead was in another chapter means nothing here.
2055
+ playheadPulledBack = undefined;
2037
2056
  const info = chapterList[select.selectedIndex];
2038
2057
  setRootStartMs(info.start);
2039
2058
  if (keepLimitsCheckbox.checked && limitsShowable) {
@@ -2080,12 +2099,36 @@ playRootBtn.addEventListener("click", () => {
2080
2099
  * playback and the editors alone. When it's gone, this switches roots properly.
2081
2100
  */
2082
2101
  function refreshChapters() {
2102
+ const playheadMs = playheadInVideoMs();
2103
+ // Not moved since the last clamp: aim for where it was before that.
2104
+ if (playheadPulledBack &&
2105
+ Math.abs(playheadMs - playheadPulledBack.toMs) > PLAYHEAD_TOLERANCE_MS) {
2106
+ playheadPulledBack = undefined;
2107
+ }
2108
+ const wantedMs = playheadPulledBack?.fromMs ?? playheadMs;
2109
+ // limitsChapter still has the start and end from before this change.
2110
+ const old = limitsChapter;
2111
+ const wasInside = playheadPulledBack !== undefined ||
2112
+ old === undefined ||
2113
+ (playheadMs >= old.start - PLAYHEAD_TOLERANCE_MS &&
2114
+ playheadMs <= old.end + PLAYHEAD_TOLERANCE_MS);
2083
2115
  if (initChapters()) {
2084
2116
  setRootStartMs(chapterList[select.selectedIndex].start);
2085
2117
  applyLimits();
2086
- // The range clamped itself to the new bounds; show the real position again. The
2087
- // number input stays the source of truth, so a playhead past a shortened end is left
2088
- // for playback to wrap rather than moved here.
2118
+ // A shorter chapter can leave the playhead past its end, showing nothing. Keep it inside
2119
+ // the play limits. sectionEndTime already stops just short of the next chapter's start.
2120
+ // A playhead the user put outside the limits stays there.
2121
+ if (wasInside) {
2122
+ const clampedMs = Math.max(sectionStartTime, Math.min(sectionEndTime, wantedMs));
2123
+ if (Math.abs(clampedMs - playheadMs) > PLAYHEAD_TOLERANCE_MS) {
2124
+ loadPlayPositionSeconds(clampedMs);
2125
+ }
2126
+ playheadPulledBack =
2127
+ clampedMs === wantedMs
2128
+ ? undefined
2129
+ : { fromMs: wantedMs, toMs: clampedMs };
2130
+ }
2131
+ // The range clamped itself to the new bounds; show the real position again.
2089
2132
  loadPlayPositionRange();
2090
2133
  }
2091
2134
  else {
@@ -5695,6 +5738,15 @@ function updateScheduleEditor(selectable) {
5695
5738
  // Every keystroke in Divisions or Progress updates the status.
5696
5739
  scheduleEditorRefreshers.push(handwritingPanel.refresh);
5697
5740
  }
5741
+ const characterPanel = buildCharacterPanelFor(selectable);
5742
+ if (characterPanel) {
5743
+ // The warnings here, the list of characters after the properties.
5744
+ scheduleEditorFieldset.append(characterPanel.status);
5745
+ // Every keystroke in Text, and a new Font.
5746
+ scheduleEditorRefreshers.push(characterPanel.refresh);
5747
+ // The Font at the playhead is the one the list shows.
5748
+ goToButtonUpdaters.push(characterPanel.timeChanged);
5749
+ }
5698
5750
  // A component's own panels, and the project's: after the library's, so on a Fourier
5699
5751
  // the library's status comes first.
5700
5752
  scheduleEditorFieldset.append(...startEditorPanels(selectable));
@@ -5741,8 +5793,42 @@ function updateScheduleEditor(selectable) {
5741
5793
  }
5742
5794
  scheduleEditorFieldset.append(section);
5743
5795
  }
5796
+ if (characterPanel) {
5797
+ scheduleEditorFieldset.append(characterPanel.palette);
5798
+ }
5744
5799
  scheduleEditorFieldset.append(buildSoundClipSection(selectable));
5745
5800
  }
5801
+ /**
5802
+ * The Characters panel for a Text or a Text Format, or undefined for anything else.
5803
+ *
5804
+ * A Text Format doesn't know its text, so its warnings come from its Multi Text: the
5805
+ * ones for this format. The Multi Text shows them all, in its Text Frame panel.
5806
+ */
5807
+ function buildCharacterPanelFor(selectable) {
5808
+ if (selectable instanceof TextComponent) {
5809
+ return buildCharacterPanel({
5810
+ fontName: () => selectable.fontSchedule.at(componentTimeMs(selectable)),
5811
+ missing: () => selectable.missingCharacters(),
5812
+ });
5813
+ }
5814
+ if (selectable instanceof TextFormatComponent) {
5815
+ return buildCharacterPanel({
5816
+ fontName: () => selectable.fontSchedule.at(componentTimeMs(selectable)),
5817
+ missing() {
5818
+ const parent = selectable.parent;
5819
+ if (!(parent instanceof MultiTextComponent))
5820
+ return [];
5821
+ const name = selectable.nameScalar.value;
5822
+ return parent.formatInScope(name) === selectable
5823
+ ? parent
5824
+ .missingCharacters()
5825
+ .filter(({ formatName }) => formatName === name)
5826
+ : [];
5827
+ },
5828
+ });
5829
+ }
5830
+ return undefined;
5831
+ }
5746
5832
  // MARK: Split
5747
5833
  /**
5748
5834
  * The series a Video Clip would be split within, or a sentence saying why it
@@ -5958,6 +6044,7 @@ function buildMultiTextFrame(text) {
5958
6044
  updateComponentEditor(root);
5959
6045
  updateScheduleEditor(text);
5960
6046
  },
6047
+ timeMs: () => componentTimeMs(text),
5961
6048
  });
5962
6049
  },
5963
6050
  });