canvas-recorder-lib 0.8.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dev/canvas-recorder.css +6 -6
- package/dev/canvas-recorder.ts +10 -9
- package/dev/delay-files.ts +3 -1
- package/dev/player-body.ts +3 -3
- package/dev/transcribe-core.ts +7 -4
- package/dev/transcript-align.ts +20 -17
- package/dist/dev/canvas-recorder.css +6 -6
- package/dist/dev/canvas-recorder.js +10 -9
- package/dist/dev/canvas-recorder.js.map +1 -1
- package/dist/dev/delay-files.d.ts.map +1 -1
- package/dist/dev/delay-files.js +3 -1
- package/dist/dev/delay-files.js.map +1 -1
- package/dist/dev/player-body.d.ts +1 -1
- package/dist/dev/player-body.d.ts.map +1 -1
- package/dist/dev/player-body.js +3 -3
- package/dist/dev/transcribe-core.d.ts.map +1 -1
- package/dist/dev/transcribe-core.js +7 -4
- package/dist/dev/transcribe-core.js.map +1 -1
- package/dist/dev/transcript-align.d.ts +3 -3
- package/dist/dev/transcript-align.d.ts.map +1 -1
- package/dist/dev/transcript-align.js +16 -13
- package/dist/dev/transcript-align.js.map +1 -1
- package/dist/src/glib/path-shape.d.ts +7 -0
- package/dist/src/glib/path-shape.d.ts.map +1 -1
- package/dist/src/glib/path-shape.js +43 -221
- package/dist/src/glib/path-shape.js.map +1 -1
- package/dist/src/glib/svg-arc.d.ts +41 -0
- package/dist/src/glib/svg-arc.d.ts.map +1 -0
- package/dist/src/glib/svg-arc.js +114 -0
- package/dist/src/glib/svg-arc.js.map +1 -0
- package/dist/src/glib/svg-path-parser.d.ts +60 -0
- package/dist/src/glib/svg-path-parser.d.ts.map +1 -0
- package/dist/src/glib/svg-path-parser.js +258 -0
- package/dist/src/glib/svg-path-parser.js.map +1 -0
- package/dist/src/slide-components/fourier.d.ts.map +1 -1
- package/dist/src/slide-components/fourier.js +14 -1
- package/dist/src/slide-components/fourier.js.map +1 -1
- package/dist/src/slide-components/halftone-shadow.d.ts.map +1 -1
- package/dist/src/slide-components/halftone-shadow.js +12 -9
- package/dist/src/slide-components/halftone-shadow.js.map +1 -1
- package/dist/src/slide-components/show-error.d.ts.map +1 -1
- package/dist/src/slide-components/show-error.js +9 -2
- package/dist/src/slide-components/show-error.js.map +1 -1
- package/package.json +1 -1
- package/src/glib/path-shape.ts +66 -245
- package/src/glib/svg-arc.ts +141 -0
- package/src/glib/svg-path-parser.ts +308 -0
- package/src/slide-components/fourier.ts +15 -3
- package/src/slide-components/halftone-shadow.ts +12 -9
- package/src/slide-components/show-error.ts +9 -2
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the `d` attribute of an SVG `<path>`: `"M1,2 L3,4"`.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions, with no dependencies on `PathShape`, so it can be tested on its own.
|
|
5
|
+
* {@link PathShape.fromRawString} turns the result into a `PathShape`.
|
|
6
|
+
*
|
|
7
|
+
* It reads all of the grammar in the SVG specification, section 9.3:
|
|
8
|
+
* * Every command, upper case (absolute) and lower case (relative): `M L H V C S Q T A Z`.
|
|
9
|
+
* * More sets of arguments than the command needs repeat the command. After an `M`, they're `L`s.
|
|
10
|
+
* * Any white space, and one optional comma, between arguments. None at all before a sign or a second decimal point.
|
|
11
|
+
* * Numbers like `.5`, `1.`, `+3`, `1e-3`.
|
|
12
|
+
* * The two arc flags are one character each, with no separator needed: `a1 1 0 0150 20`.
|
|
13
|
+
*
|
|
14
|
+
* What comes out is simpler than what went in. Everything is absolute, and there are only five kinds:
|
|
15
|
+
* `M`, `L`, `Q`, `C` and `Z`.
|
|
16
|
+
* `H` and `V` are lines, `S` and `T` have their control points filled in, and arcs are cubics.
|
|
17
|
+
* @module
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { arcToCubics } from "./svg-arc.ts";
|
|
21
|
+
|
|
22
|
+
/** One step of a path. Always absolute. Each starts where the previous one ended. */
|
|
23
|
+
export type SvgPathSegment =
|
|
24
|
+
| { readonly type: "M"; readonly x: number; readonly y: number }
|
|
25
|
+
| { readonly type: "L"; readonly x: number; readonly y: number }
|
|
26
|
+
| {
|
|
27
|
+
readonly type: "Q";
|
|
28
|
+
readonly x1: number;
|
|
29
|
+
readonly y1: number;
|
|
30
|
+
readonly x: number;
|
|
31
|
+
readonly y: number;
|
|
32
|
+
}
|
|
33
|
+
| {
|
|
34
|
+
readonly type: "C";
|
|
35
|
+
readonly x1: number;
|
|
36
|
+
readonly y1: number;
|
|
37
|
+
readonly x2: number;
|
|
38
|
+
readonly y2: number;
|
|
39
|
+
readonly x: number;
|
|
40
|
+
readonly y: number;
|
|
41
|
+
}
|
|
42
|
+
/** Go back to the last `M`. The caller draws the line, if there's a gap to close. */
|
|
43
|
+
| { readonly type: "Z" };
|
|
44
|
+
|
|
45
|
+
/** The string isn't a valid path. `position` is the index of the first character that didn't make sense. */
|
|
46
|
+
export class SvgPathSyntaxError extends Error {
|
|
47
|
+
constructor(
|
|
48
|
+
message: string,
|
|
49
|
+
readonly position: number,
|
|
50
|
+
) {
|
|
51
|
+
super(message);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** How many numbers each command takes. `Z` takes none. */
|
|
56
|
+
const ARGUMENT_COUNT: Record<string, number> = {
|
|
57
|
+
M: 2,
|
|
58
|
+
L: 2,
|
|
59
|
+
H: 1,
|
|
60
|
+
V: 1,
|
|
61
|
+
C: 6,
|
|
62
|
+
S: 4,
|
|
63
|
+
Q: 4,
|
|
64
|
+
T: 2,
|
|
65
|
+
A: 7,
|
|
66
|
+
Z: 0,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/** The two flags of an arc, among its seven arguments. Each is a single character, 0 or 1. */
|
|
70
|
+
const isArcFlag = (command: string, index: number) =>
|
|
71
|
+
command === "A" && (index === 3 || index === 4);
|
|
72
|
+
|
|
73
|
+
/** An optional sign, then digits and a decimal point: `1`, `1.`, `1.5`, `.5`. Then an optional exponent. */
|
|
74
|
+
const NUMBER = /[-+]?(?:[0-9]+\.?[0-9]*|\.[0-9]+)(?:[eE][-+]?[0-9]+)?/y;
|
|
75
|
+
const WHITE_SPACE = /[ \t\n\r\f]*/y;
|
|
76
|
+
const COMMA = /,/y;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Where a character could begin another number.
|
|
80
|
+
* After a complete set of arguments, this means the command repeats.
|
|
81
|
+
*/
|
|
82
|
+
const STARTS_A_NUMBER = /[-+.0-9]/;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Keeps track of where we are in the string.
|
|
86
|
+
* Every method either succeeds and moves forward, or throws and leaves the position alone.
|
|
87
|
+
*/
|
|
88
|
+
class Reader {
|
|
89
|
+
position = 0;
|
|
90
|
+
constructor(readonly d: string) {}
|
|
91
|
+
|
|
92
|
+
fail(message: string): never {
|
|
93
|
+
throw new SvgPathSyntaxError(message, this.position);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
skipWhiteSpace() {
|
|
97
|
+
WHITE_SPACE.lastIndex = this.position;
|
|
98
|
+
WHITE_SPACE.exec(this.d);
|
|
99
|
+
this.position = WHITE_SPACE.lastIndex;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** White space, then at most one comma, then more white space. */
|
|
103
|
+
skipSeparator() {
|
|
104
|
+
this.skipWhiteSpace();
|
|
105
|
+
COMMA.lastIndex = this.position;
|
|
106
|
+
if (COMMA.test(this.d)) {
|
|
107
|
+
this.position = COMMA.lastIndex;
|
|
108
|
+
this.skipWhiteSpace();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
atEnd() {
|
|
113
|
+
return this.position >= this.d.length;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The next character, or "" at the end. */
|
|
117
|
+
peek() {
|
|
118
|
+
return this.d[this.position] ?? "";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
number(): number {
|
|
122
|
+
NUMBER.lastIndex = this.position;
|
|
123
|
+
const found = NUMBER.exec(this.d);
|
|
124
|
+
if (!found) {
|
|
125
|
+
this.fail("Expected a number.");
|
|
126
|
+
}
|
|
127
|
+
this.position = NUMBER.lastIndex;
|
|
128
|
+
return Number(found[0]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Arc flags are exactly one character, so `"11"` is two flags. */
|
|
132
|
+
flag(): number {
|
|
133
|
+
const c = this.peek();
|
|
134
|
+
if (c !== "0" && c !== "1") {
|
|
135
|
+
this.fail("Expected an arc flag, 0 or 1.");
|
|
136
|
+
}
|
|
137
|
+
this.position++;
|
|
138
|
+
return Number(c);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Read a path string.
|
|
144
|
+
* @param d What you'd put in the `d` attribute of an SVG `<path>`. An empty string is an empty path.
|
|
145
|
+
* @returns The path as a list of absolute segments.
|
|
146
|
+
* @throws {@link SvgPathSyntaxError} if the string isn't valid.
|
|
147
|
+
* Unlike a browser, which draws everything before the first mistake, this doesn't try to draw a part of it.
|
|
148
|
+
*/
|
|
149
|
+
export function svgPathSegments(d: string): SvgPathSegment[] {
|
|
150
|
+
const reader = new Reader(d);
|
|
151
|
+
const result: SvgPathSegment[] = [];
|
|
152
|
+
|
|
153
|
+
// The current point, and where the current subpath started, which `Z` returns to.
|
|
154
|
+
let x = 0;
|
|
155
|
+
let y = 0;
|
|
156
|
+
let startX = 0;
|
|
157
|
+
let startY = 0;
|
|
158
|
+
// `S` and `T` reflect the previous curve's last control point, but only if the previous command was a
|
|
159
|
+
// matching kind of curve. Anything else, including an arc, leaves the control point at the current point.
|
|
160
|
+
let previousCubicControl: { x: number; y: number } | undefined;
|
|
161
|
+
let previousQuadraticControl: { x: number; y: number } | undefined;
|
|
162
|
+
|
|
163
|
+
reader.skipWhiteSpace();
|
|
164
|
+
while (!reader.atEnd()) {
|
|
165
|
+
const letter = reader.peek();
|
|
166
|
+
const command = letter.toUpperCase();
|
|
167
|
+
if (result.length === 0 && command !== "M") {
|
|
168
|
+
reader.fail("Must start with an M command.");
|
|
169
|
+
}
|
|
170
|
+
if (!(command in ARGUMENT_COUNT)) {
|
|
171
|
+
reader.fail(`Expected a command, not "${letter}".`);
|
|
172
|
+
}
|
|
173
|
+
const relative = letter !== command;
|
|
174
|
+
reader.position++;
|
|
175
|
+
reader.skipWhiteSpace();
|
|
176
|
+
|
|
177
|
+
if (command === "Z") {
|
|
178
|
+
result.push({ type: "Z" });
|
|
179
|
+
x = startX;
|
|
180
|
+
y = startY;
|
|
181
|
+
previousCubicControl = previousQuadraticControl = undefined;
|
|
182
|
+
reader.skipSeparator();
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Arguments can repeat without repeating the letter.
|
|
187
|
+
let current = command;
|
|
188
|
+
do {
|
|
189
|
+
const count = ARGUMENT_COUNT[current];
|
|
190
|
+
const args: number[] = [];
|
|
191
|
+
for (let i = 0; i < count; i++) {
|
|
192
|
+
if (i > 0) {
|
|
193
|
+
reader.skipSeparator();
|
|
194
|
+
}
|
|
195
|
+
args.push(isArcFlag(current, i) ? reader.flag() : reader.number());
|
|
196
|
+
}
|
|
197
|
+
reader.skipSeparator();
|
|
198
|
+
|
|
199
|
+
// Relative commands measure from where this set of arguments starts, not where the command letter was.
|
|
200
|
+
const dx = relative ? x : 0;
|
|
201
|
+
const dy = relative ? y : 0;
|
|
202
|
+
let nextCubicControl: typeof previousCubicControl;
|
|
203
|
+
let nextQuadraticControl: typeof previousQuadraticControl;
|
|
204
|
+
switch (current) {
|
|
205
|
+
case "M": {
|
|
206
|
+
x = startX = args[0] + dx;
|
|
207
|
+
y = startY = args[1] + dy;
|
|
208
|
+
result.push({ type: "M", x, y });
|
|
209
|
+
// Any more pairs are lines. Written the same way, absolute or relative.
|
|
210
|
+
current = "L";
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case "L": {
|
|
214
|
+
x = args[0] + dx;
|
|
215
|
+
y = args[1] + dy;
|
|
216
|
+
result.push({ type: "L", x, y });
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
case "H": {
|
|
220
|
+
x = args[0] + dx;
|
|
221
|
+
result.push({ type: "L", x, y });
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case "V": {
|
|
225
|
+
y = args[0] + dy;
|
|
226
|
+
result.push({ type: "L", x, y });
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
case "C": {
|
|
230
|
+
const x1 = args[0] + dx;
|
|
231
|
+
const y1 = args[1] + dy;
|
|
232
|
+
const x2 = args[2] + dx;
|
|
233
|
+
const y2 = args[3] + dy;
|
|
234
|
+
x = args[4] + dx;
|
|
235
|
+
y = args[5] + dy;
|
|
236
|
+
result.push({ type: "C", x1, y1, x2, y2, x, y });
|
|
237
|
+
nextCubicControl = { x: x2, y: y2 };
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case "S": {
|
|
241
|
+
// The first control point is the last one reflected through the current point.
|
|
242
|
+
const x1 = previousCubicControl ? 2 * x - previousCubicControl.x : x;
|
|
243
|
+
const y1 = previousCubicControl ? 2 * y - previousCubicControl.y : y;
|
|
244
|
+
const x2 = args[0] + dx;
|
|
245
|
+
const y2 = args[1] + dy;
|
|
246
|
+
x = args[2] + dx;
|
|
247
|
+
y = args[3] + dy;
|
|
248
|
+
result.push({ type: "C", x1, y1, x2, y2, x, y });
|
|
249
|
+
nextCubicControl = { x: x2, y: y2 };
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
case "Q": {
|
|
253
|
+
const x1 = args[0] + dx;
|
|
254
|
+
const y1 = args[1] + dy;
|
|
255
|
+
x = args[2] + dx;
|
|
256
|
+
y = args[3] + dy;
|
|
257
|
+
result.push({ type: "Q", x1, y1, x, y });
|
|
258
|
+
nextQuadraticControl = { x: x1, y: y1 };
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case "T": {
|
|
262
|
+
const x1 = previousQuadraticControl
|
|
263
|
+
? 2 * x - previousQuadraticControl.x
|
|
264
|
+
: x;
|
|
265
|
+
const y1 = previousQuadraticControl
|
|
266
|
+
? 2 * y - previousQuadraticControl.y
|
|
267
|
+
: y;
|
|
268
|
+
x = args[0] + dx;
|
|
269
|
+
y = args[1] + dy;
|
|
270
|
+
result.push({ type: "Q", x1, y1, x, y });
|
|
271
|
+
nextQuadraticControl = { x: x1, y: y1 };
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
case "A": {
|
|
275
|
+
const [rx, ry, rotation, largeArc, sweep] = args;
|
|
276
|
+
const endX = args[5] + dx;
|
|
277
|
+
const endY = args[6] + dy;
|
|
278
|
+
if (rx === 0 || ry === 0) {
|
|
279
|
+
// The specification says a degenerate ellipse is a line, so a rounded corner of radius 0 works.
|
|
280
|
+
if (endX !== x || endY !== y) {
|
|
281
|
+
result.push({ type: "L", x: endX, y: endY });
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
for (const curve of arcToCubics(
|
|
285
|
+
x,
|
|
286
|
+
y,
|
|
287
|
+
rx,
|
|
288
|
+
ry,
|
|
289
|
+
rotation,
|
|
290
|
+
largeArc !== 0,
|
|
291
|
+
sweep !== 0,
|
|
292
|
+
endX,
|
|
293
|
+
endY,
|
|
294
|
+
)) {
|
|
295
|
+
result.push({ type: "C", ...curve });
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
x = endX;
|
|
299
|
+
y = endY;
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
previousCubicControl = nextCubicControl;
|
|
304
|
+
previousQuadraticControl = nextQuadraticControl;
|
|
305
|
+
} while (!reader.atEnd() && STARTS_A_NUMBER.test(reader.peek()));
|
|
306
|
+
}
|
|
307
|
+
return result;
|
|
308
|
+
}
|
|
@@ -96,6 +96,8 @@ export function parseTermGroups(text: string): TermGroups {
|
|
|
96
96
|
const errors: string[] = [];
|
|
97
97
|
const warnings: string[] = [];
|
|
98
98
|
if (text.trim() === "") return { groups: [], errors, warnings };
|
|
99
|
+
/** Empty groups are common, to keep several Fouriers in step. One warning covers them all. */
|
|
100
|
+
const emptyGroups: number[] = [];
|
|
99
101
|
/** Where each term was first added, to report repeats. */
|
|
100
102
|
const firstGroup = new Map<number, number>();
|
|
101
103
|
const groups = text.split(",").map((piece, groupIndex) => {
|
|
@@ -116,9 +118,7 @@ export function parseTermGroups(text: string): TermGroups {
|
|
|
116
118
|
};
|
|
117
119
|
const tokens = piece.trim().split(/\s+/).filter(Boolean);
|
|
118
120
|
if (tokens.length === 0) {
|
|
119
|
-
|
|
120
|
-
`Group ${groupNumber} is empty, so that step adds nothing.`,
|
|
121
|
-
);
|
|
121
|
+
emptyGroups.push(groupNumber);
|
|
122
122
|
}
|
|
123
123
|
for (const token of tokens) {
|
|
124
124
|
const single = /^\d+$/.exec(token);
|
|
@@ -141,6 +141,18 @@ export function parseTermGroups(text: string): TermGroups {
|
|
|
141
141
|
}
|
|
142
142
|
return group;
|
|
143
143
|
});
|
|
144
|
+
if (emptyGroups.length) {
|
|
145
|
+
// "2", "2 and 3", "3, 5 and 7", "2, 3, 4, 5, 6, 7 and 4 more".
|
|
146
|
+
const shown = emptyGroups.slice(0, 6).map(String);
|
|
147
|
+
const more = emptyGroups.length - shown.length;
|
|
148
|
+
if (more > 0) shown.push(`${more} more`);
|
|
149
|
+
const last = shown.pop()!;
|
|
150
|
+
const list = shown.length ? `${shown.join(", ")} and ${last}` : last;
|
|
151
|
+
const one = emptyGroups.length === 1;
|
|
152
|
+
warnings.push(
|
|
153
|
+
`${one ? "Group" : "Groups"} ${list} ${one ? "is" : "are"} empty, so ${one ? "that step adds" : "those steps add"} nothing.`,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
144
156
|
return { groups, errors, warnings };
|
|
145
157
|
}
|
|
146
158
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { canvasRecorder } from "../../lib/main-control.ts";
|
|
1
2
|
import { ColorScheduleInfo, NumberScheduleInfo } from "../schedule-helper.ts";
|
|
2
3
|
import { Showable, ShowOptions } from "../showable.ts";
|
|
3
4
|
import { InParallelComponent } from "./in-parallel.ts";
|
|
@@ -75,18 +76,21 @@ export class HalftoneShadowComponent extends InParallelComponent {
|
|
|
75
76
|
const dx = this.dxSchedule.at(timeInMs);
|
|
76
77
|
const dy = this.dySchedule.at(timeInMs);
|
|
77
78
|
const period = this.periodSchedule.at(timeInMs);
|
|
78
|
-
|
|
79
|
-
const
|
|
79
|
+
// Read the size every frame: it can change at any time.
|
|
80
|
+
const { width, height } = canvasRecorder;
|
|
81
|
+
// One small pixel per dot. The last row and column can hang past the edge.
|
|
82
|
+
const cols = Math.ceil(width / period);
|
|
83
|
+
const rows = Math.ceil(height / period);
|
|
80
84
|
|
|
81
85
|
// Low-power mode or CLI context: skip the halftone pass.
|
|
82
86
|
if (options.quality === "Low Power" || typeof document === "undefined") {
|
|
83
87
|
context.fillStyle = backgroundColor;
|
|
84
|
-
context.fillRect(0, 0,
|
|
88
|
+
context.fillRect(0, 0, width, height);
|
|
85
89
|
super.show(options);
|
|
86
90
|
return;
|
|
87
91
|
}
|
|
88
92
|
|
|
89
|
-
// Resize the small canvas when period changes.
|
|
93
|
+
// Resize the small canvas when the period or the canvas size changes.
|
|
90
94
|
if (
|
|
91
95
|
!this.#smallCanvas ||
|
|
92
96
|
this.#smallCols !== cols ||
|
|
@@ -98,23 +102,22 @@ export class HalftoneShadowComponent extends InParallelComponent {
|
|
|
98
102
|
this.#smallCtx = this.#smallCanvas.getContext("2d", {
|
|
99
103
|
willReadFrequently: true,
|
|
100
104
|
})!;
|
|
101
|
-
// Apply the 16×9 root transform once — it stays until the canvas is replaced.
|
|
102
|
-
this.#smallCtx.scale(cols / 16, rows / 9);
|
|
103
105
|
this.#smallCols = cols;
|
|
104
106
|
this.#smallRows = rows;
|
|
105
107
|
}
|
|
106
108
|
const smallCtx = this.#smallCtx!;
|
|
107
109
|
|
|
108
110
|
// Render children into the small canvas for alpha sampling.
|
|
109
|
-
smallCtx.save();
|
|
110
111
|
smallCtx.resetTransform();
|
|
111
112
|
smallCtx.clearRect(0, 0, cols, rows);
|
|
112
|
-
|
|
113
|
+
// Each small pixel is exactly one cell, so it samples where its dot is drawn.
|
|
114
|
+
// Set every frame: the period can change without changing cols or rows.
|
|
115
|
+
smallCtx.scale(1 / period, 1 / period);
|
|
113
116
|
super.show({ ...options, context: smallCtx, registerTransform: undefined });
|
|
114
117
|
|
|
115
118
|
// Draw background.
|
|
116
119
|
context.fillStyle = backgroundColor;
|
|
117
|
-
context.fillRect(0, 0,
|
|
120
|
+
context.fillRect(0, 0, width, height);
|
|
118
121
|
|
|
119
122
|
// Build halftone dot path from the alpha channel and draw as the shadow.
|
|
120
123
|
const { data } = smallCtx.getImageData(0, 0, cols, rows);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { canvasRecorder } from "../../lib/main-control.ts";
|
|
1
2
|
import { makeLineFont } from "../glib/line-font.ts";
|
|
2
3
|
import { ParagraphLayout } from "../glib/paragraph-layout.ts";
|
|
3
4
|
|
|
@@ -11,12 +12,18 @@ const errorFont = makeLineFont(1);
|
|
|
11
12
|
*/
|
|
12
13
|
export function showError(context: CanvasRenderingContext2D, text: string) {
|
|
13
14
|
const font = errorFont;
|
|
15
|
+
/** Space on the left and right. */
|
|
16
|
+
const margin = 0.25;
|
|
17
|
+
// Read the width every time: it can change at any time.
|
|
18
|
+
const width = Math.max(1, canvasRecorder.width - 2 * margin);
|
|
14
19
|
const path = ParagraphLayout.singlePathShape({
|
|
15
20
|
font,
|
|
16
21
|
text,
|
|
17
22
|
alignment: "center",
|
|
18
|
-
width
|
|
19
|
-
})
|
|
23
|
+
width,
|
|
24
|
+
})
|
|
25
|
+
// Center on the canvas, not on the paragraph.
|
|
26
|
+
.translate((canvasRecorder.width - width) / 2, 0).canvasPath;
|
|
20
27
|
context.lineCap = "round";
|
|
21
28
|
context.lineJoin = "round";
|
|
22
29
|
context.lineWidth = font.strokeWidth * 3;
|