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
|
@@ -3,7 +3,14 @@
|
|
|
3
3
|
import { Point } from "bezier-js";
|
|
4
4
|
import { ReadOnlyRect } from "phil-lib/misc";
|
|
5
5
|
import { Font } from "../glib/letters-base.ts";
|
|
6
|
-
import {
|
|
6
|
+
import { MIN_FONT_SIZE, MIN_FONT_WIDTH } from "../glib/line-font.ts";
|
|
7
|
+
import {
|
|
8
|
+
checkCharacters,
|
|
9
|
+
FONT_NAMES,
|
|
10
|
+
FontName,
|
|
11
|
+
makeFontByName,
|
|
12
|
+
MissingCharacters,
|
|
13
|
+
} from "../glib/font-choices.ts";
|
|
7
14
|
import {
|
|
8
15
|
LaidOut,
|
|
9
16
|
ParagraphLayout,
|
|
@@ -491,6 +498,47 @@ export class MultiTextComponent extends DurationAgnosticComponent {
|
|
|
491
498
|
formatInScope(name: string): TextFormatComponent | undefined {
|
|
492
499
|
return getFormat(name, this.#formatsInScope());
|
|
493
500
|
}
|
|
501
|
+
/**
|
|
502
|
+
* Characters in this text that its fonts can't draw. They're left out of
|
|
503
|
+
* the layout, so they never reach the canvas. For the Visual Editor's
|
|
504
|
+
* status.
|
|
505
|
+
*
|
|
506
|
+
* Checked over the whole timeline, not just the playhead: at every keyframe
|
|
507
|
+
* of every span's Content and Style, and of every Text Format's Font.
|
|
508
|
+
* A span whose format can't be found is skipped; {@link show} draws an
|
|
509
|
+
* error for that already.
|
|
510
|
+
*/
|
|
511
|
+
missingCharacters(): MissingCharacters[] {
|
|
512
|
+
const formats = this.#formatsInScope();
|
|
513
|
+
const spans = [
|
|
514
|
+
...this.children.flatMap(({ child }) =>
|
|
515
|
+
child instanceof TextSpanComponent ? [child] : [],
|
|
516
|
+
),
|
|
517
|
+
...this.#programText,
|
|
518
|
+
];
|
|
519
|
+
const times = [
|
|
520
|
+
...spans.flatMap((span) => [
|
|
521
|
+
...span.contentSchedule.schedule,
|
|
522
|
+
...span.styleSchedule.schedule,
|
|
523
|
+
]),
|
|
524
|
+
...formats.flatMap((format) => format.fontSchedule.schedule),
|
|
525
|
+
].map(({ time }) => time);
|
|
526
|
+
return checkCharacters(times, (timeInMs) =>
|
|
527
|
+
spans.flatMap((span) => {
|
|
528
|
+
const { content, style } = span.get(timeInMs);
|
|
529
|
+
const format = getFormat(style, formats);
|
|
530
|
+
return format
|
|
531
|
+
? [
|
|
532
|
+
{
|
|
533
|
+
text: content,
|
|
534
|
+
fontName: format.fontSchedule.at(timeInMs),
|
|
535
|
+
formatName: style,
|
|
536
|
+
},
|
|
537
|
+
]
|
|
538
|
+
: [];
|
|
539
|
+
}),
|
|
540
|
+
);
|
|
541
|
+
}
|
|
494
542
|
/**
|
|
495
543
|
* The point the finished text is anchored to.
|
|
496
544
|
*
|
|
@@ -1202,7 +1250,9 @@ export class TextSpanComponent implements Showable {
|
|
|
1202
1250
|
|
|
1203
1251
|
type CachedFont = {
|
|
1204
1252
|
readonly font: Font;
|
|
1253
|
+
readonly fontName: FontName;
|
|
1205
1254
|
readonly size: number;
|
|
1255
|
+
readonly fontWidth: number;
|
|
1206
1256
|
readonly boldness: number;
|
|
1207
1257
|
readonly obliqueness: number;
|
|
1208
1258
|
};
|
|
@@ -1212,7 +1262,21 @@ export class TextFormatComponent implements Showable {
|
|
|
1212
1262
|
readonly nameScalar = new StringScalarInfo("Name", "");
|
|
1213
1263
|
readonly scalars = [this.nameScalar] as const;
|
|
1214
1264
|
readonly colorSchedule: ColorScheduleInfo;
|
|
1265
|
+
/**
|
|
1266
|
+
* Which font: Line Font, Futura L or Cursive. See {@link FONT_NAMES}.
|
|
1267
|
+
* Each font has its own set of characters.
|
|
1268
|
+
*/
|
|
1269
|
+
readonly fontSchedule = new SelectScheduleInfo<FontName, FontName>(
|
|
1270
|
+
"Font",
|
|
1271
|
+
"Line Font",
|
|
1272
|
+
FONT_NAMES,
|
|
1273
|
+
);
|
|
1215
1274
|
readonly sizeSchedule = new NumberScheduleInfo("Font Size", 1);
|
|
1275
|
+
/**
|
|
1276
|
+
* How wide the letters are, compared to normal, keeping their height. See
|
|
1277
|
+
* {@link Font.stretch}. Not Multi Text's own Width, which is its frame's.
|
|
1278
|
+
*/
|
|
1279
|
+
readonly fontWidthSchedule = new NumberScheduleInfo("Font Width", 1);
|
|
1216
1280
|
readonly boldnessSchedule = new NumberScheduleInfo("Boldness", 1);
|
|
1217
1281
|
readonly obliquenessSchedule = new NumberScheduleInfo("Obliqueness", 0);
|
|
1218
1282
|
readonly alphaSchedule = new NumberScheduleInfo("Alpha", 1);
|
|
@@ -1224,7 +1288,9 @@ export class TextFormatComponent implements Showable {
|
|
|
1224
1288
|
description?: string;
|
|
1225
1289
|
name?: string;
|
|
1226
1290
|
color?: string | readonly Keyframe<string>[] | ColorScheduleInfo;
|
|
1291
|
+
font?: FontName | readonly Keyframe<FontName>[];
|
|
1227
1292
|
size?: number | readonly Keyframe<number>[];
|
|
1293
|
+
fontWidth?: number | readonly Keyframe<number>[];
|
|
1228
1294
|
boldness?: number | readonly Keyframe<number>[];
|
|
1229
1295
|
obliqueness?: number | readonly Keyframe<number>[];
|
|
1230
1296
|
alpha?: number | readonly Keyframe<number>[];
|
|
@@ -1237,8 +1303,12 @@ export class TextFormatComponent implements Showable {
|
|
|
1237
1303
|
"Color",
|
|
1238
1304
|
initialValues.color ?? "#666",
|
|
1239
1305
|
);
|
|
1306
|
+
if (initialValues.font !== undefined)
|
|
1307
|
+
this.fontSchedule.set(initialValues.font);
|
|
1240
1308
|
if (initialValues.size !== undefined)
|
|
1241
1309
|
this.sizeSchedule.set(initialValues.size);
|
|
1310
|
+
if (initialValues.fontWidth !== undefined)
|
|
1311
|
+
this.fontWidthSchedule.set(initialValues.fontWidth);
|
|
1242
1312
|
if (initialValues.boldness !== undefined)
|
|
1243
1313
|
this.boldnessSchedule.set(initialValues.boldness);
|
|
1244
1314
|
if (initialValues.obliqueness !== undefined)
|
|
@@ -1247,7 +1317,9 @@ export class TextFormatComponent implements Showable {
|
|
|
1247
1317
|
this.alphaSchedule.set(initialValues.alpha);
|
|
1248
1318
|
this.schedules.push(
|
|
1249
1319
|
this.colorSchedule,
|
|
1320
|
+
this.fontSchedule,
|
|
1250
1321
|
this.sizeSchedule,
|
|
1322
|
+
this.fontWidthSchedule,
|
|
1251
1323
|
this.boldnessSchedule,
|
|
1252
1324
|
this.obliquenessSchedule,
|
|
1253
1325
|
this.alphaSchedule,
|
|
@@ -1269,18 +1341,42 @@ export class TextFormatComponent implements Showable {
|
|
|
1269
1341
|
*/
|
|
1270
1342
|
freeze(timeInMs: number, sizeMultiplier = 1) {
|
|
1271
1343
|
const color = this.colorSchedule.at(timeInMs);
|
|
1272
|
-
const
|
|
1344
|
+
const fontName = this.fontSchedule.at(timeInMs);
|
|
1345
|
+
// 0 or less can't be drawn. Too small to see is the closest thing.
|
|
1346
|
+
const size = Math.max(
|
|
1347
|
+
MIN_FONT_SIZE,
|
|
1348
|
+
this.sizeSchedule.at(timeInMs) * sizeMultiplier || 0,
|
|
1349
|
+
);
|
|
1350
|
+
// 0 or less can't be drawn. As thin as it goes is the closest thing.
|
|
1351
|
+
const fontWidth = Math.max(
|
|
1352
|
+
MIN_FONT_WIDTH,
|
|
1353
|
+
this.fontWidthSchedule.at(timeInMs) || 0,
|
|
1354
|
+
);
|
|
1273
1355
|
const boldness = this.boldnessSchedule.at(timeInMs);
|
|
1274
1356
|
const obliqueness = this.obliquenessSchedule.at(timeInMs);
|
|
1275
1357
|
const alpha = this.alphaSchedule.at(timeInMs);
|
|
1276
1358
|
if (
|
|
1277
1359
|
!this.#cachedFont ||
|
|
1360
|
+
this.#cachedFont.fontName != fontName ||
|
|
1278
1361
|
this.#cachedFont.size != size ||
|
|
1362
|
+
this.#cachedFont.fontWidth != fontWidth ||
|
|
1279
1363
|
this.#cachedFont.boldness != boldness ||
|
|
1280
1364
|
this.#cachedFont.obliqueness != obliqueness
|
|
1281
1365
|
) {
|
|
1282
|
-
const font =
|
|
1283
|
-
|
|
1366
|
+
const font = makeFontByName(fontName, {
|
|
1367
|
+
size,
|
|
1368
|
+
width: fontWidth,
|
|
1369
|
+
boldness,
|
|
1370
|
+
obliqueness,
|
|
1371
|
+
});
|
|
1372
|
+
this.#cachedFont = {
|
|
1373
|
+
font,
|
|
1374
|
+
fontName,
|
|
1375
|
+
size,
|
|
1376
|
+
fontWidth,
|
|
1377
|
+
boldness,
|
|
1378
|
+
obliqueness,
|
|
1379
|
+
};
|
|
1284
1380
|
}
|
|
1285
1381
|
const font = this.#cachedFont.font;
|
|
1286
1382
|
function drawText({ context }: ShowOptions, pathShape: PathShape): void {
|
|
@@ -288,8 +288,9 @@ export const componentRegistry = new Map<string, ComponentRegistryEntry>([
|
|
|
288
288
|
description:
|
|
289
289
|
"A way to draw fancy text. " +
|
|
290
290
|
"This can contain multiple TextFormat and TextSpan components as children, " +
|
|
291
|
-
"and one text effect, like Handwriting Effect."
|
|
292
|
-
|
|
291
|
+
"and one text effect, like Handwriting Effect. " +
|
|
292
|
+
"Its Text Formats also work in every Multi Text inside it, so wrap a group of them in one to share styles.",
|
|
293
|
+
isGoodForWrapping: true,
|
|
293
294
|
howToGenerate: { type: "class", class: MultiTextComponent },
|
|
294
295
|
},
|
|
295
296
|
],
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { ReadOnlyRect } from "phil-lib/misc";
|
|
2
|
-
import {
|
|
2
|
+
import { MIN_FONT_SIZE, MIN_FONT_WIDTH } from "../glib/line-font.ts";
|
|
3
|
+
import {
|
|
4
|
+
checkCharacters,
|
|
5
|
+
FONT_NAMES,
|
|
6
|
+
FontName,
|
|
7
|
+
makeFontByName,
|
|
8
|
+
MissingCharacters,
|
|
9
|
+
} from "../glib/font-choices.ts";
|
|
3
10
|
import { ParagraphLayout } from "../glib/paragraph-layout.ts";
|
|
4
11
|
import {
|
|
5
12
|
ColorScheduleInfo,
|
|
@@ -15,7 +22,9 @@ import { Font } from "../glib/letters-base.ts";
|
|
|
15
22
|
|
|
16
23
|
type CachedFont = {
|
|
17
24
|
readonly font: Font;
|
|
25
|
+
readonly fontName: FontName;
|
|
18
26
|
readonly size: number;
|
|
27
|
+
readonly fontWidth: number;
|
|
19
28
|
readonly boldness: number;
|
|
20
29
|
readonly obliqueness: number;
|
|
21
30
|
};
|
|
@@ -30,7 +39,21 @@ export class TextComponent extends DurationAgnosticComponent {
|
|
|
30
39
|
height: 4,
|
|
31
40
|
});
|
|
32
41
|
readonly textSchedule = new StringScheduleInfo("Text", "Type Here");
|
|
42
|
+
/**
|
|
43
|
+
* Which font: Line Font, Futura L or Cursive. See {@link FONT_NAMES}.
|
|
44
|
+
* Each font has its own set of characters.
|
|
45
|
+
*/
|
|
46
|
+
readonly fontSchedule = new SelectScheduleInfo<FontName, FontName>(
|
|
47
|
+
"Font",
|
|
48
|
+
"Line Font",
|
|
49
|
+
FONT_NAMES,
|
|
50
|
+
);
|
|
33
51
|
readonly sizeSchedule = new NumberScheduleInfo("Size", 1);
|
|
52
|
+
/**
|
|
53
|
+
* How wide the letters are, compared to normal, keeping their height. See
|
|
54
|
+
* {@link Font.stretch}.
|
|
55
|
+
*/
|
|
56
|
+
readonly fontWidthSchedule = new NumberScheduleInfo("Font Width", 1);
|
|
34
57
|
readonly boldnessSchedule = new NumberScheduleInfo("Boldness", 1);
|
|
35
58
|
readonly obliquenessSchedule = new NumberScheduleInfo("Obliqueness", 0);
|
|
36
59
|
readonly alignmentSchedule = new SelectScheduleInfo("Alignment", "left", [
|
|
@@ -47,7 +70,9 @@ export class TextComponent extends DurationAgnosticComponent {
|
|
|
47
70
|
color?: string | readonly Keyframe<string>[];
|
|
48
71
|
rect?: ReadOnlyRect | readonly Keyframe<ReadOnlyRect>[];
|
|
49
72
|
text?: string | readonly Keyframe<string>[];
|
|
73
|
+
font?: FontName | readonly Keyframe<FontName>[];
|
|
50
74
|
size?: number | readonly Keyframe<number>[];
|
|
75
|
+
fontWidth?: number | readonly Keyframe<number>[];
|
|
51
76
|
boldness?: number | readonly Keyframe<number>[];
|
|
52
77
|
obliqueness?: number | readonly Keyframe<number>[];
|
|
53
78
|
// I have mixed feelings on the complicated type definition.
|
|
@@ -68,7 +93,9 @@ export class TextComponent extends DurationAgnosticComponent {
|
|
|
68
93
|
this.colorSchedule,
|
|
69
94
|
this.rectSchedule,
|
|
70
95
|
this.textSchedule,
|
|
96
|
+
this.fontSchedule,
|
|
71
97
|
this.sizeSchedule,
|
|
98
|
+
this.fontWidthSchedule,
|
|
72
99
|
this.boldnessSchedule,
|
|
73
100
|
this.obliquenessSchedule,
|
|
74
101
|
this.alignmentSchedule,
|
|
@@ -82,9 +109,15 @@ export class TextComponent extends DurationAgnosticComponent {
|
|
|
82
109
|
if (initialValues.text !== undefined) {
|
|
83
110
|
this.textSchedule.set(initialValues.text);
|
|
84
111
|
}
|
|
112
|
+
if (initialValues.font !== undefined) {
|
|
113
|
+
this.fontSchedule.set(initialValues.font);
|
|
114
|
+
}
|
|
85
115
|
if (initialValues.size !== undefined) {
|
|
86
116
|
this.sizeSchedule.set(initialValues.size);
|
|
87
117
|
}
|
|
118
|
+
if (initialValues.fontWidth !== undefined) {
|
|
119
|
+
this.fontWidthSchedule.set(initialValues.fontWidth);
|
|
120
|
+
}
|
|
88
121
|
if (initialValues.boldness !== undefined) {
|
|
89
122
|
this.boldnessSchedule.set(initialValues.boldness);
|
|
90
123
|
}
|
|
@@ -95,6 +128,24 @@ export class TextComponent extends DurationAgnosticComponent {
|
|
|
95
128
|
this.alignmentSchedule.set(initialValues.alignmentSchedule);
|
|
96
129
|
}
|
|
97
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Characters in Text that Font can't draw. They're left out, so they never
|
|
133
|
+
* reach the canvas. For the Visual Editor's status.
|
|
134
|
+
*
|
|
135
|
+
* Checked over the whole timeline: at every keyframe of Text and of Font.
|
|
136
|
+
*/
|
|
137
|
+
missingCharacters(): MissingCharacters[] {
|
|
138
|
+
const times = [
|
|
139
|
+
...this.textSchedule.schedule,
|
|
140
|
+
...this.fontSchedule.schedule,
|
|
141
|
+
].map(({ time }) => time);
|
|
142
|
+
return checkCharacters(times, (timeInMs) => [
|
|
143
|
+
{
|
|
144
|
+
text: this.textSchedule.at(timeInMs),
|
|
145
|
+
fontName: this.fontSchedule.at(timeInMs),
|
|
146
|
+
},
|
|
147
|
+
]);
|
|
148
|
+
}
|
|
98
149
|
#cachedFont: undefined | CachedFont;
|
|
99
150
|
#cachedPath:
|
|
100
151
|
| undefined
|
|
@@ -110,19 +161,40 @@ export class TextComponent extends DurationAgnosticComponent {
|
|
|
110
161
|
const color = this.colorSchedule.at(timeInMs);
|
|
111
162
|
const rect = this.rectSchedule.at(timeInMs);
|
|
112
163
|
const text = this.textSchedule.at(timeInMs);
|
|
113
|
-
const
|
|
164
|
+
const fontName = this.fontSchedule.at(timeInMs);
|
|
165
|
+
// 0 or less can't be drawn. Too small to see is the closest thing.
|
|
166
|
+
const size = Math.max(MIN_FONT_SIZE, this.sizeSchedule.at(timeInMs) || 0);
|
|
167
|
+
// 0 or less can't be drawn. As thin as it goes is the closest thing.
|
|
168
|
+
const fontWidth = Math.max(
|
|
169
|
+
MIN_FONT_WIDTH,
|
|
170
|
+
this.fontWidthSchedule.at(timeInMs) || 0,
|
|
171
|
+
);
|
|
114
172
|
const boldness = this.boldnessSchedule.at(timeInMs);
|
|
115
173
|
const obliqueness = this.obliquenessSchedule.at(timeInMs);
|
|
116
174
|
const alignment = this.alignmentSchedule.at(timeInMs);
|
|
117
175
|
context.strokeStyle = color;
|
|
118
176
|
if (
|
|
119
177
|
!this.#cachedFont ||
|
|
178
|
+
this.#cachedFont.fontName != fontName ||
|
|
120
179
|
this.#cachedFont.size != size ||
|
|
180
|
+
this.#cachedFont.fontWidth != fontWidth ||
|
|
121
181
|
this.#cachedFont.boldness != boldness ||
|
|
122
182
|
this.#cachedFont.obliqueness != obliqueness
|
|
123
183
|
) {
|
|
124
|
-
const font =
|
|
125
|
-
|
|
184
|
+
const font = makeFontByName(fontName, {
|
|
185
|
+
size,
|
|
186
|
+
width: fontWidth,
|
|
187
|
+
boldness,
|
|
188
|
+
obliqueness,
|
|
189
|
+
});
|
|
190
|
+
this.#cachedFont = {
|
|
191
|
+
font,
|
|
192
|
+
fontName,
|
|
193
|
+
size,
|
|
194
|
+
fontWidth,
|
|
195
|
+
boldness,
|
|
196
|
+
obliqueness,
|
|
197
|
+
};
|
|
126
198
|
}
|
|
127
199
|
if (
|
|
128
200
|
!this.#cachedPath ||
|