@tmhs/screencast-mcp 0.49.1 → 0.50.0

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 (134) hide show
  1. package/README.md +13 -8
  2. package/dist/index.js +550 -106
  3. package/dist/wgcRecorder.js +15 -139
  4. package/package.json +8 -4
  5. package/assets/.gitkeep +0 -0
  6. package/assets/icon.png +0 -0
  7. package/dist/cli.js +0 -516
  8. package/dist/context.js +0 -50
  9. package/dist/prompts.js +0 -95
  10. package/dist/resources.js +0 -93
  11. package/dist/server.js +0 -174
  12. package/dist/setup.js +0 -438
  13. package/dist/tools/addMarker.js +0 -93
  14. package/dist/tools/assembleHighlights.js +0 -69
  15. package/dist/tools/backdrop.js +0 -79
  16. package/dist/tools/bugReport.js +0 -243
  17. package/dist/tools/burnSubtitles.js +0 -56
  18. package/dist/tools/callout.js +0 -62
  19. package/dist/tools/chapters.js +0 -156
  20. package/dist/tools/clip.js +0 -52
  21. package/dist/tools/compress.js +0 -51
  22. package/dist/tools/concat.js +0 -67
  23. package/dist/tools/contactSheet.js +0 -113
  24. package/dist/tools/convert.js +0 -46
  25. package/dist/tools/crop.js +0 -43
  26. package/dist/tools/cursor.js +0 -67
  27. package/dist/tools/cutByTranscript.js +0 -86
  28. package/dist/tools/cutIdle.js +0 -84
  29. package/dist/tools/deleteRecording.js +0 -119
  30. package/dist/tools/denoise.js +0 -60
  31. package/dist/tools/doctor.js +0 -146
  32. package/dist/tools/exportGif.js +0 -57
  33. package/dist/tools/exportPreset.js +0 -48
  34. package/dist/tools/extractAudio.js +0 -65
  35. package/dist/tools/findText.js +0 -194
  36. package/dist/tools/getMediaInfo.js +0 -36
  37. package/dist/tools/getSession.js +0 -40
  38. package/dist/tools/indexRecording.js +0 -195
  39. package/dist/tools/keystrokeOverlay.js +0 -90
  40. package/dist/tools/listAudioDevices.js +0 -35
  41. package/dist/tools/listSessions.js +0 -28
  42. package/dist/tools/listTargets.js +0 -76
  43. package/dist/tools/listVideoDevices.js +0 -26
  44. package/dist/tools/musicBed.js +0 -55
  45. package/dist/tools/narrate.js +0 -86
  46. package/dist/tools/normalizeAudio.js +0 -59
  47. package/dist/tools/overlay.js +0 -62
  48. package/dist/tools/pauseRecording.js +0 -44
  49. package/dist/tools/pipeline.js +0 -397
  50. package/dist/tools/readEvents.js +0 -98
  51. package/dist/tools/redactRegion.js +0 -62
  52. package/dist/tools/reframe.js +0 -46
  53. package/dist/tools/resumeRecording.js +0 -46
  54. package/dist/tools/reviewRecording.js +0 -163
  55. package/dist/tools/sampleFrames.js +0 -200
  56. package/dist/tools/saveReplay.js +0 -90
  57. package/dist/tools/scale.js +0 -44
  58. package/dist/tools/screenDiff.js +0 -86
  59. package/dist/tools/screenshot.js +0 -76
  60. package/dist/tools/searchRecording.js +0 -79
  61. package/dist/tools/speed.js +0 -46
  62. package/dist/tools/startRecording.js +0 -398
  63. package/dist/tools/stepGuide.js +0 -249
  64. package/dist/tools/stopRecording.js +0 -132
  65. package/dist/tools/titleCard.js +0 -67
  66. package/dist/tools/transcribe.js +0 -66
  67. package/dist/tools/trim.js +0 -57
  68. package/dist/tools/waitForChange.js +0 -142
  69. package/dist/tools/xfadeTransition.js +0 -58
  70. package/dist/tools/zoom.js +0 -134
  71. package/dist/utils/anim.js +0 -54
  72. package/dist/utils/animExport.js +0 -56
  73. package/dist/utils/argPaths.js +0 -39
  74. package/dist/utils/audio.js +0 -117
  75. package/dist/utils/audioDevices.js +0 -107
  76. package/dist/utils/backdrop.js +0 -162
  77. package/dist/utils/bugReport.js +0 -195
  78. package/dist/utils/callout.js +0 -132
  79. package/dist/utils/calloutAssets.js +0 -42
  80. package/dist/utils/capabilities.js +0 -96
  81. package/dist/utils/captions.js +0 -104
  82. package/dist/utils/chapters.js +0 -227
  83. package/dist/utils/consent.js +0 -29
  84. package/dist/utils/cursor.js +0 -338
  85. package/dist/utils/diff.js +0 -186
  86. package/dist/utils/errors.js +0 -29
  87. package/dist/utils/events.js +0 -403
  88. package/dist/utils/expr.js +0 -11
  89. package/dist/utils/ffmpeg.js +0 -285
  90. package/dist/utils/fontCoverage.js +0 -177
  91. package/dist/utils/fonts.js +0 -154
  92. package/dist/utils/frameQueue.js +0 -50
  93. package/dist/utils/gpu.js +0 -219
  94. package/dist/utils/idle.js +0 -91
  95. package/dist/utils/images.js +0 -38
  96. package/dist/utils/jobs.js +0 -129
  97. package/dist/utils/keystrokes.js +0 -198
  98. package/dist/utils/lifecycle.js +0 -233
  99. package/dist/utils/logging.js +0 -75
  100. package/dist/utils/media.js +0 -584
  101. package/dist/utils/monitors.js +0 -124
  102. package/dist/utils/narrate.js +0 -233
  103. package/dist/utils/ocr.js +0 -222
  104. package/dist/utils/ocrScan.js +0 -93
  105. package/dist/utils/paths.js +0 -155
  106. package/dist/utils/pause.js +0 -190
  107. package/dist/utils/pipeline.js +0 -361
  108. package/dist/utils/player.js +0 -85
  109. package/dist/utils/pool.js +0 -29
  110. package/dist/utils/produce.js +0 -300
  111. package/dist/utils/recipes.js +0 -71
  112. package/dist/utils/recorder.js +0 -173
  113. package/dist/utils/recordingFiles.js +0 -32
  114. package/dist/utils/recordingIndex.js +0 -312
  115. package/dist/utils/replay.js +0 -283
  116. package/dist/utils/resolveTarget.js +0 -25
  117. package/dist/utils/retention.js +0 -48
  118. package/dist/utils/roots.js +0 -43
  119. package/dist/utils/sessions.js +0 -499
  120. package/dist/utils/sheet.js +0 -82
  121. package/dist/utils/stepGuide.js +0 -231
  122. package/dist/utils/steps.js +0 -88
  123. package/dist/utils/still.js +0 -38
  124. package/dist/utils/targetList.js +0 -64
  125. package/dist/utils/targets.js +0 -265
  126. package/dist/utils/timeline.js +0 -85
  127. package/dist/utils/toolSpec.js +0 -31
  128. package/dist/utils/toolsets.js +0 -134
  129. package/dist/utils/transcriptCut.js +0 -149
  130. package/dist/utils/validate.js +0 -23
  131. package/dist/utils/waitLoop.js +0 -50
  132. package/dist/utils/wgc.js +0 -84
  133. package/dist/utils/windows.js +0 -192
  134. package/dist/utils/zoom.js +0 -252
@@ -1,285 +0,0 @@
1
- import { spawn, spawnSync } from "node:child_process";
2
- import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
- import { ScreencastError } from "./errors.js";
6
- import { buildProbeArgs, parseMediaInfo } from "./media.js";
7
- import { logFfmpegWarnings } from "./logging.js";
8
- const INSTALL_HINT = "ffmpeg and ffprobe must be installed and on PATH (or set FFMPEG_PATH / " +
9
- "FFPROBE_PATH). Windows: `winget install Gyan.FFmpeg` or `choco install " +
10
- "ffmpeg`. macOS: `brew install ffmpeg`. Linux: `apt install ffmpeg`.";
11
- function resolveBinary(envVar, fallback) {
12
- const override = process.env[envVar];
13
- return override && override.trim().length > 0 ? override : fallback;
14
- }
15
- export function binaryWorks(bin) {
16
- try {
17
- const res = spawnSync(bin, ["-version"], {
18
- stdio: "ignore",
19
- windowsHide: true,
20
- });
21
- return res.status === 0;
22
- }
23
- catch {
24
- return false;
25
- }
26
- }
27
- export function detectFfmpeg() {
28
- const ffmpeg = resolveBinary("FFMPEG_PATH", "ffmpeg");
29
- const ffprobe = resolveBinary("FFPROBE_PATH", "ffprobe");
30
- const missing = [];
31
- if (!binaryWorks(ffmpeg))
32
- missing.push("ffmpeg");
33
- if (!binaryWorks(ffprobe))
34
- missing.push("ffprobe");
35
- if (missing.length > 0) {
36
- throw new ScreencastError(`Required ${missing.join(" and ")} not found on PATH.`, INSTALL_HINT);
37
- }
38
- return { ffmpeg, ffprobe };
39
- }
40
- let cached = null;
41
- export function requireFfmpeg() {
42
- if (cached)
43
- return cached;
44
- cached = detectFfmpeg();
45
- return cached;
46
- }
47
- let wgc = null;
48
- export function wgcAvailable() {
49
- if (wgc !== null)
50
- return wgc;
51
- if (process.platform !== "win32")
52
- return (wgc = false);
53
- try {
54
- const res = spawnSync(requireFfmpeg().ffmpeg, ["-hide_banner", "-h", "filter=gfxcapture"], {
55
- encoding: "utf8",
56
- windowsHide: true,
57
- timeout: 10_000,
58
- });
59
- wgc = /gfxcapture AVOptions/.test(res.stdout ?? "");
60
- }
61
- catch {
62
- wgc = false;
63
- }
64
- return wgc;
65
- }
66
- const filterCache = new Map();
67
- export function hasFilter(name) {
68
- const cached = filterCache.get(name);
69
- if (cached !== undefined)
70
- return cached;
71
- let found;
72
- try {
73
- const res = spawnSync(requireFfmpeg().ffmpeg, ["-hide_banner", "-h", `filter=${name}`], {
74
- encoding: "utf8",
75
- windowsHide: true,
76
- timeout: 10_000,
77
- });
78
- found = new RegExp(`^Filter ${name}\\b`, "m").test(res.stdout ?? "");
79
- }
80
- catch {
81
- found = false;
82
- }
83
- filterCache.set(name, found);
84
- return found;
85
- }
86
- export function runCapture(bin, args, timeoutMs = 5 * 60 * 1000, opts = {}) {
87
- return new Promise((resolve, reject) => {
88
- const child = spawn(bin, args, { windowsHide: true });
89
- if (opts.closeStdin)
90
- child.stdin?.end();
91
- let stdout = "";
92
- let stderr = "";
93
- let killError = null;
94
- let graceTimer;
95
- const kill = (error) => {
96
- if (killError)
97
- return;
98
- killError = error;
99
- child.kill("SIGKILL");
100
- graceTimer = setTimeout(() => reject(error), 5_000);
101
- };
102
- const onAbort = () => kill(new ScreencastError(`${bin} was cancelled.`));
103
- const timer = setTimeout(() => kill(new ScreencastError(`${bin} timed out after ${Math.round(timeoutMs / 1000)}s.`)), timeoutMs);
104
- const cleanup = () => {
105
- clearTimeout(timer);
106
- clearTimeout(graceTimer);
107
- opts.signal?.removeEventListener("abort", onAbort);
108
- };
109
- if (opts.signal?.aborted)
110
- onAbort();
111
- else
112
- opts.signal?.addEventListener("abort", onAbort, { once: true });
113
- child.stdout?.on("data", (d) => {
114
- const s = d.toString();
115
- stdout += s;
116
- opts.onStdout?.(s);
117
- });
118
- child.stderr?.on("data", (d) => (stderr += d.toString()));
119
- child.on("error", (err) => {
120
- cleanup();
121
- reject(err);
122
- });
123
- child.on("close", (code) => {
124
- cleanup();
125
- if (killError)
126
- reject(killError);
127
- else
128
- resolve({ code, stdout, stderr });
129
- });
130
- });
131
- }
132
- const SCRIPTABLE_OPTS = new Set(["-vf", "-af", "-filter_complex", "-lavfi", "-filter:v", "-filter:a"]);
133
- export const MAX_INLINE_FILTER = 8_000;
134
- const LEGACY_SCRIPT_OPTS = {
135
- "-vf": "-filter_script:v",
136
- "-filter:v": "-filter_script:v",
137
- "-af": "-filter_script:a",
138
- "-filter:a": "-filter_script:a",
139
- "-filter_complex": "-filter_complex_script",
140
- "-lavfi": "-filter_complex_script",
141
- };
142
- let modernScripts = null;
143
- function supportsOptionFiles() {
144
- if (modernScripts !== null)
145
- return modernScripts;
146
- try {
147
- const res = spawnSync(requireFfmpeg().ffmpeg, ["-hide_banner", "-version"], {
148
- encoding: "utf8",
149
- windowsHide: true,
150
- timeout: 10_000,
151
- });
152
- const avutil = /^\s*libavutil\s+(\d+)\./m.exec(res.stdout ?? "");
153
- modernScripts = avutil?.[1] === undefined || Number(avutil[1]) >= 59;
154
- }
155
- catch {
156
- modernScripts = true;
157
- }
158
- return modernScripts;
159
- }
160
- export function scriptLongFilters(args, modern) {
161
- let dir = null;
162
- const out = [...args];
163
- for (const [i, a] of args.entries()) {
164
- const opt = args[i - 1];
165
- if (opt === undefined || !SCRIPTABLE_OPTS.has(opt) || a.length <= MAX_INLINE_FILTER)
166
- continue;
167
- dir ??= mkdtempSync(join(tmpdir(), "screencast-filter-"));
168
- const file = join(dir, `filter${i}.txt`);
169
- writeFileSync(file, a);
170
- modern ??= supportsOptionFiles();
171
- out[i - 1] = modern ? `-/${opt.slice(1)}` : (LEGACY_SCRIPT_OPTS[opt] ?? opt);
172
- out[i] = file;
173
- }
174
- const d = dir;
175
- return { args: out, cleanup: () => d && rmSync(d, { recursive: true, force: true }) };
176
- }
177
- export async function runFfmpegBuffer(args, timeoutMs = 30_000, opts = {}) {
178
- const chunks = [];
179
- await streamFfmpeg(args, timeoutMs, (d) => chunks.push(d), opts);
180
- return Buffer.concat(chunks);
181
- }
182
- export async function runFfmpegFrames(args, frameBytes, onFrame, timeoutMs = 30_000, opts = {}) {
183
- if (!(frameBytes > 0))
184
- throw new ScreencastError("frameBytes must be positive.");
185
- let pending = Buffer.alloc(0);
186
- let count = 0;
187
- await streamFfmpeg(args, timeoutMs, (d) => {
188
- pending = pending.length ? Buffer.concat([pending, d]) : d;
189
- let o = 0;
190
- for (; o + frameBytes <= pending.length; o += frameBytes) {
191
- onFrame(Buffer.from(pending.subarray(o, o + frameBytes)));
192
- count++;
193
- }
194
- pending = pending.subarray(o);
195
- }, opts);
196
- return count;
197
- }
198
- function streamFfmpeg(rawArgs, timeoutMs, onData, opts) {
199
- const { ffmpeg } = requireFfmpeg();
200
- const { args, cleanup } = scriptLongFilters(rawArgs);
201
- return new Promise((resolve, reject) => {
202
- const child = spawn(ffmpeg, args, { windowsHide: true });
203
- let stderr = "";
204
- let killError = null;
205
- let graceTimer;
206
- const kill = (error) => {
207
- if (killError)
208
- return;
209
- killError = error;
210
- child.kill("SIGKILL");
211
- graceTimer = setTimeout(() => reject(error), 5_000);
212
- };
213
- const onAbort = () => kill(new ScreencastError("ffmpeg was cancelled."));
214
- const timer = setTimeout(() => kill(new ScreencastError(`ffmpeg timed out after ${Math.round(timeoutMs / 1000)}s.`)), timeoutMs);
215
- const settle = () => {
216
- clearTimeout(timer);
217
- clearTimeout(graceTimer);
218
- opts.signal?.removeEventListener("abort", onAbort);
219
- };
220
- if (opts.signal?.aborted)
221
- onAbort();
222
- else
223
- opts.signal?.addEventListener("abort", onAbort, { once: true });
224
- child.stdout?.on("data", (d) => {
225
- if (killError)
226
- return;
227
- try {
228
- onData(d);
229
- }
230
- catch (error) {
231
- kill(error);
232
- }
233
- });
234
- child.stderr?.on("data", (d) => (stderr += d.toString()));
235
- child.on("error", (err) => {
236
- settle();
237
- reject(err);
238
- });
239
- child.on("close", (code) => {
240
- settle();
241
- if (killError)
242
- reject(killError);
243
- else if (code === 0)
244
- resolve();
245
- else
246
- reject(new ScreencastError(`ffmpeg failed (exit ${code}):\n${stderr.trim().split("\n").slice(-6).join("\n")}`));
247
- });
248
- }).finally(cleanup);
249
- }
250
- export async function runFfmpeg(args, timeoutMs, opts = {}) {
251
- const { ffmpeg } = requireFfmpeg();
252
- const scripted = scriptLongFilters(args);
253
- try {
254
- const res = await runCapture(ffmpeg, scripted.args, timeoutMs, opts);
255
- if (res.code !== 0) {
256
- const tail = res.stderr.trim().split("\n").slice(-6).join("\n");
257
- throw new ScreencastError(`ffmpeg failed (exit ${res.code}):\n${tail}`);
258
- }
259
- logFfmpegWarnings(res.stderr);
260
- }
261
- finally {
262
- scripted.cleanup();
263
- }
264
- }
265
- export async function probeDuration(path, opts = {}) {
266
- if (!existsSync(path))
267
- return null;
268
- try {
269
- const res = await runCapture(opts.ffprobe ?? requireFfmpeg().ffprobe, buildProbeArgs(path), 30_000);
270
- if (res.code !== 0)
271
- return null;
272
- return parseMediaInfo(JSON.parse(res.stdout)).durationSec;
273
- }
274
- catch {
275
- return null;
276
- }
277
- }
278
- export async function probeMedia(input) {
279
- const { ffprobe } = requireFfmpeg();
280
- const res = await runCapture(ffprobe, buildProbeArgs(input), 30_000);
281
- if (res.code !== 0) {
282
- throw new ScreencastError(`ffprobe failed (exit ${res.code}): ${res.stderr.trim().slice(-400)}`);
283
- }
284
- return parseMediaInfo(JSON.parse(res.stdout));
285
- }
@@ -1,177 +0,0 @@
1
- export function bufferReader(buf) {
2
- return (offset, length) => buf.subarray(offset, offset + length);
3
- }
4
- function need(b, n, what) {
5
- if (b.length < n)
6
- throw new Error(`Truncated font: ${what}.`);
7
- return b;
8
- }
9
- function faceOffset(read, faceIndex) {
10
- const head = need(read(0, 12), 12, "header");
11
- if (head.toString("latin1", 0, 4) !== "ttcf") {
12
- if (faceIndex !== 0)
13
- throw new Error("Not a font collection; only face 0 exists.");
14
- return 0;
15
- }
16
- const count = head.readUInt32BE(8);
17
- if (faceIndex < 0 || faceIndex >= count)
18
- throw new Error(`Face ${faceIndex} is out of range (collection has ${count}).`);
19
- return need(read(12 + faceIndex * 4, 4), 4, "collection offsets").readUInt32BE(0);
20
- }
21
- class RangeBuilder {
22
- ranges = [];
23
- add(first, last) {
24
- const prev = this.ranges[this.ranges.length - 1];
25
- if (prev && first <= prev[1] + 1)
26
- prev[1] = Math.max(prev[1], last);
27
- else
28
- this.ranges.push([first, last]);
29
- }
30
- }
31
- function parseFormat4(t) {
32
- const segX2 = need(t, 14, "cmap format 4").readUInt16BE(6);
33
- const ends = 14;
34
- const starts = ends + segX2 + 2;
35
- const deltas = starts + segX2;
36
- const rangeOffsets = deltas + segX2;
37
- need(t, rangeOffsets + segX2, "cmap format 4 segments");
38
- const out = new RangeBuilder();
39
- for (let s = 0; s < segX2 / 2; s++) {
40
- const end = t.readUInt16BE(ends + s * 2);
41
- const start = t.readUInt16BE(starts + s * 2);
42
- const delta = t.readUInt16BE(deltas + s * 2);
43
- const ro = t.readUInt16BE(rangeOffsets + s * 2);
44
- if (start > end)
45
- continue;
46
- for (let c = start; c <= end && c !== 0xffff; c++) {
47
- let glyph;
48
- if (ro === 0)
49
- glyph = (c + delta) & 0xffff;
50
- else {
51
- const at = rangeOffsets + s * 2 + ro + (c - start) * 2;
52
- glyph = at + 2 <= t.length ? t.readUInt16BE(at) : 0;
53
- if (glyph !== 0)
54
- glyph = (glyph + delta) & 0xffff;
55
- }
56
- if (glyph !== 0)
57
- out.add(c, c);
58
- }
59
- }
60
- return out.ranges;
61
- }
62
- function parseGroups(t, format) {
63
- const n = need(t, 16, `cmap format ${format}`).readUInt32BE(12);
64
- need(t, 16 + n * 12, `cmap format ${format} groups`);
65
- const groups = [];
66
- for (let i = 0; i < n; i++) {
67
- let first = t.readUInt32BE(16 + i * 12);
68
- const last = Math.min(t.readUInt32BE(20 + i * 12), 0x10ffff);
69
- const glyph = t.readUInt32BE(24 + i * 12);
70
- if (glyph === 0) {
71
- if (format === 13)
72
- continue;
73
- first++;
74
- }
75
- if (first <= last)
76
- groups.push([first, last]);
77
- }
78
- groups.sort((a, b) => a[0] - b[0]);
79
- const out = new RangeBuilder();
80
- for (const [a, b] of groups)
81
- out.add(a, b);
82
- return out.ranges;
83
- }
84
- function subtableRank(platform, encoding) {
85
- if (platform === 3 && encoding === 10)
86
- return 0;
87
- if (platform === 0 && (encoding === 4 || encoding === 6))
88
- return 1;
89
- if (platform === 3 && encoding === 1)
90
- return 2;
91
- if (platform === 0 && encoding <= 3)
92
- return 3;
93
- return -1;
94
- }
95
- export function parseCoverage(read, faceIndex = 0) {
96
- const base = faceOffset(read, faceIndex);
97
- const sfnt = need(read(base, 12), 12, "sfnt header");
98
- const tag = sfnt.toString("latin1", 0, 4);
99
- if (tag !== "\u0000\u0001\u0000\u0000" && tag !== "OTTO" && tag !== "true") {
100
- throw new Error("Not a TrueType/OpenType font.");
101
- }
102
- const numTables = sfnt.readUInt16BE(4);
103
- const dir = need(read(base + 12, numTables * 16), numTables * 16, "table directory");
104
- let cmapAt = -1;
105
- for (let i = 0; i < numTables; i++) {
106
- if (dir.toString("latin1", i * 16, i * 16 + 4) === "cmap")
107
- cmapAt = dir.readUInt32BE(i * 16 + 8);
108
- }
109
- if (cmapAt < 0)
110
- throw new Error("Font has no cmap table.");
111
- const cmapHead = need(read(cmapAt, 4), 4, "cmap header");
112
- const n = cmapHead.readUInt16BE(2);
113
- const recs = need(read(cmapAt + 4, n * 8), n * 8, "cmap records");
114
- const candidates = [];
115
- for (let i = 0; i < n; i++) {
116
- const rank = subtableRank(recs.readUInt16BE(i * 8), recs.readUInt16BE(i * 8 + 2));
117
- if (rank >= 0)
118
- candidates.push({ rank, offset: cmapAt + recs.readUInt32BE(i * 8 + 4) });
119
- }
120
- candidates.sort((a, b) => a.rank - b.rank);
121
- for (const { offset } of candidates) {
122
- const fmtHead = read(offset, 8);
123
- if (fmtHead.length < 8)
124
- continue;
125
- const format = fmtHead.readUInt16BE(0);
126
- if (format === 4)
127
- return parseFormat4(read(offset, fmtHead.readUInt16BE(2)));
128
- if (format === 12 || format === 13)
129
- return parseGroups(read(offset, fmtHead.readUInt32BE(4)), format);
130
- }
131
- throw new Error("Font has no Unicode cmap subtable this reader understands (formats 4, 12, 13).");
132
- }
133
- export function covers(cov, cp) {
134
- let lo = 0;
135
- let hi = cov.length - 1;
136
- while (lo <= hi) {
137
- const mid = (lo + hi) >> 1;
138
- const [first, last] = cov[mid];
139
- if (cp < first)
140
- hi = mid - 1;
141
- else if (cp > last)
142
- lo = mid + 1;
143
- else
144
- return true;
145
- }
146
- return false;
147
- }
148
- export function needsGlyph(cp) {
149
- if (cp < 0x20 || (cp >= 0x7f && cp < 0xa0))
150
- return false;
151
- if (cp === 0xad || cp === 0x34f || cp === 0x61c || cp === 0xfeff)
152
- return false;
153
- if (cp >= 0x200b && cp <= 0x200f)
154
- return false;
155
- if (cp >= 0x202a && cp <= 0x202e)
156
- return false;
157
- if (cp >= 0x2060 && cp <= 0x206f)
158
- return false;
159
- if (cp >= 0xfe00 && cp <= 0xfe0f)
160
- return false;
161
- if (cp >= 0xe0000 && cp <= 0xe0fff)
162
- return false;
163
- return true;
164
- }
165
- export function missingChars(text, cov) {
166
- const seen = new Set();
167
- const out = [];
168
- for (const ch of text) {
169
- const cp = ch.codePointAt(0);
170
- if (seen.has(cp))
171
- continue;
172
- seen.add(cp);
173
- if (needsGlyph(cp) && !covers(cov, cp))
174
- out.push(ch);
175
- }
176
- return out;
177
- }
@@ -1,154 +0,0 @@
1
- import { closeSync, existsSync, openSync, readSync, statSync } from "node:fs";
2
- import { basename, isAbsolute, join } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import { ScreencastError } from "./errors.js";
5
- import { missingChars, parseCoverage } from "./fontCoverage.js";
6
- const FONT_FILES = {
7
- regular: "Inter-Regular.ttf",
8
- bold: "Inter-Bold.ttf",
9
- };
10
- export function bundledFontPath(weight = "bold") {
11
- return fileURLToPath(new URL(`../../assets/fonts/${FONT_FILES[weight]}`, import.meta.url));
12
- }
13
- export function escapeFilterPath(p) {
14
- return p
15
- .replace(/\\/g, "/")
16
- .replace(/:/g, "\\\\:")
17
- .replace(/'/g, "\\\\\\'")
18
- .replace(/([,;[\]])/g, "\\$1");
19
- }
20
- export const FALLBACK_FAMILIES = {
21
- segoe: { name: "Segoe UI", regular: ["segoeui.ttf"], bold: ["segoeuib.ttf", "segoeui.ttf"] },
22
- japanese: {
23
- name: "Yu Gothic",
24
- regular: ["YuGothM.ttc", "meiryo.ttc", "msgothic.ttc"],
25
- bold: ["YuGothB.ttc", "meiryob.ttc", "YuGothM.ttc", "msgothic.ttc"],
26
- },
27
- chineseSimplified: { name: "Microsoft YaHei", regular: ["msyh.ttc", "simsun.ttc"], bold: ["msyhbd.ttc", "msyh.ttc", "simsun.ttc"] },
28
- chineseTraditional: { name: "Microsoft JhengHei", regular: ["msjh.ttc", "mingliub.ttc"], bold: ["msjhbd.ttc", "msjh.ttc"] },
29
- korean: { name: "Malgun Gothic", regular: ["malgun.ttf"], bold: ["malgunbd.ttf", "malgun.ttf"] },
30
- indic: { name: "Nirmala UI", regular: ["Nirmala.ttc", "Nirmala.ttf"], bold: ["NirmalaB.ttf", "Nirmala.ttc", "Nirmala.ttf"] },
31
- thai: { name: "Leelawadee UI", regular: ["LeelawUI.ttf", "tahoma.ttf"], bold: ["LeelaUIb.ttf", "LeelawUI.ttf", "tahomabd.ttf"] },
32
- ethiopic: { name: "Ebrima", regular: ["ebrima.ttf"], bold: ["ebrimabd.ttf", "ebrima.ttf"] },
33
- emoji: { name: "Segoe UI Emoji", regular: ["seguiemj.ttf"], bold: ["seguiemj.ttf"] },
34
- symbol: { name: "Segoe UI Symbol", regular: ["seguisym.ttf"], bold: ["seguisym.ttf"] },
35
- };
36
- const DEFAULT_ORDER = [
37
- "segoe", "japanese", "chineseSimplified", "chineseTraditional", "korean",
38
- "indic", "thai", "ethiopic", "emoji", "symbol",
39
- ];
40
- export function fallbackOrder(text) {
41
- const front = [];
42
- if (/[\u3040-\u30ff\u31f0-\u31ff\uff66-\uff9f]/u.test(text))
43
- front.push("japanese");
44
- if (/[\u1100-\u11ff\u3130-\u318f\uac00-\ud7af]/u.test(text))
45
- front.push("korean");
46
- if (/\p{Script=Han}/u.test(text))
47
- front.push("chineseSimplified");
48
- return [...front, ...DEFAULT_ORDER.filter((k) => !front.includes(k))].map((k) => FALLBACK_FAMILIES[k]);
49
- }
50
- export function chooseFont(text, candidates) {
51
- let best = null;
52
- for (const c of candidates) {
53
- const missing = missingChars(text, c.coverage);
54
- if (missing.length === 0)
55
- return { fontFile: c.path, missing };
56
- if (!best || missing.length < best.missing.length)
57
- best = { fontFile: c.path, missing };
58
- }
59
- return best;
60
- }
61
- export function systemFontsDir() {
62
- return join(process.env.WINDIR ?? process.env.SystemRoot ?? "C:\\Windows", "Fonts");
63
- }
64
- const coverageCache = new Map();
65
- export function fontCoverage(path) {
66
- const cached = coverageCache.get(path);
67
- if (cached !== undefined)
68
- return cached;
69
- let cov;
70
- let fd = null;
71
- try {
72
- fd = openSync(path, "r");
73
- const handle = fd;
74
- const read = (offset, length) => {
75
- const b = Buffer.alloc(length);
76
- return b.subarray(0, readSync(handle, b, 0, length, offset));
77
- };
78
- cov = parseCoverage(read);
79
- }
80
- catch {
81
- cov = null;
82
- }
83
- finally {
84
- if (fd !== null)
85
- closeSync(fd);
86
- }
87
- coverageCache.set(path, cov);
88
- return cov;
89
- }
90
- export function resolveFontFileArg(fontFile) {
91
- if (existsSync(fontFile) && statSync(fontFile).isFile())
92
- return fontFile;
93
- if (!isAbsolute(fontFile) && basename(fontFile) === fontFile) {
94
- const sys = join(systemFontsDir(), fontFile);
95
- if (existsSync(sys))
96
- return sys;
97
- }
98
- throw new ScreencastError(`Font file not found: ${fontFile}`, "Pass a path to a .ttf, .otf or .ttc file, or the file name of a font in C:\\Windows\\Fonts.");
99
- }
100
- function excerpt(text) {
101
- const one = text.replace(/\s+/g, " ").trim();
102
- return `"${one.length > 40 ? `${one.slice(0, 39)}…` : one}"`;
103
- }
104
- export function resolveTextFont(text, opts = {}) {
105
- if (opts.fontFile) {
106
- const fontFile = resolveFontFileArg(opts.fontFile);
107
- const cov = fontCoverage(fontFile);
108
- if (!cov) {
109
- return {
110
- fontFile,
111
- missing: [],
112
- fallback: false,
113
- warning: `Could not read the character map of ${basename(fontFile)}; glyph coverage of ${excerpt(text)} was not checked.`,
114
- };
115
- }
116
- const missing = missingChars(text, cov);
117
- if (missing.length === 0)
118
- return { fontFile, missing, fallback: false };
119
- return {
120
- fontFile,
121
- missing,
122
- fallback: false,
123
- warning: `${basename(fontFile)} has no glyph for ${missing.join(" ")} in ${excerpt(text)}; they render as empty boxes.`,
124
- };
125
- }
126
- const weight = opts.weight ?? "bold";
127
- const bundled = bundledFontPath(weight);
128
- const inter = fontCoverage(bundled);
129
- if (inter && missingChars(text, inter).length === 0)
130
- return { fontFile: bundled, missing: [], fallback: false };
131
- const dir = opts.fontsDir ?? systemFontsDir();
132
- const candidates = inter ? [{ path: bundled, coverage: inter }] : [];
133
- for (const fam of fallbackOrder(text)) {
134
- for (const file of fam[weight]) {
135
- const path = join(dir, file);
136
- const coverage = existsSync(path) ? fontCoverage(path) : null;
137
- if (!coverage)
138
- continue;
139
- if (missingChars(text, coverage).length === 0)
140
- return { fontFile: path, missing: [], fallback: true };
141
- candidates.push({ path, coverage });
142
- break;
143
- }
144
- }
145
- const pick = chooseFont(text, candidates) ?? { fontFile: bundled, missing: [] };
146
- if (pick.missing.length === 0)
147
- return { ...pick, fallback: pick.fontFile !== bundled };
148
- return {
149
- ...pick,
150
- fallback: pick.fontFile !== bundled,
151
- warning: `No available font draws ${pick.missing.join(" ")} in ${excerpt(text)}; they render as empty boxes ` +
152
- `(drawn with ${basename(pick.fontFile)}). Pass fontFile with a font that covers them.`,
153
- };
154
- }
@@ -1,50 +0,0 @@
1
- import { ScreencastError } from "./errors.js";
2
- export class FrameQueue {
3
- waiters = [];
4
- error = null;
5
- ended = false;
6
- push(frame) {
7
- const waiting = this.waiters;
8
- this.waiters = [];
9
- for (const w of waiting)
10
- w.resolve(frame);
11
- }
12
- fail(error) {
13
- if (this.error === null)
14
- this.error = error;
15
- this.rejectAll(this.error);
16
- }
17
- end() {
18
- this.ended = true;
19
- this.rejectAll(new ScreencastError("The screen capture ended unexpectedly."));
20
- }
21
- next(timeoutMs) {
22
- if (this.error !== null)
23
- return Promise.reject(this.error);
24
- if (this.ended)
25
- return Promise.reject(new ScreencastError("The screen capture ended unexpectedly."));
26
- return new Promise((resolve, reject) => {
27
- const timer = setTimeout(() => {
28
- this.waiters = this.waiters.filter((w) => w !== waiter);
29
- reject(new ScreencastError(`No frame from the screen capture within ${Math.round(timeoutMs / 1000)}s.`));
30
- }, timeoutMs);
31
- const waiter = {
32
- resolve: (f) => {
33
- clearTimeout(timer);
34
- resolve(f);
35
- },
36
- reject: (e) => {
37
- clearTimeout(timer);
38
- reject(e);
39
- },
40
- };
41
- this.waiters.push(waiter);
42
- });
43
- }
44
- rejectAll(error) {
45
- const waiting = this.waiters;
46
- this.waiters = [];
47
- for (const w of waiting)
48
- w.reject(error);
49
- }
50
- }