obsidian-plugin-dev-kit 0.0.0-stage → 0.3.2
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/LICENSE +21 -0
- package/README.md +223 -2
- package/bin/opdk.js +34 -0
- package/dist/build/args.d.ts +10 -0
- package/dist/build/args.js +45 -0
- package/dist/build/bundle-check.d.ts +17 -0
- package/dist/build/bundle-check.js +42 -0
- package/dist/build/bundle-file.d.ts +4 -0
- package/dist/build/bundle-file.js +29 -0
- package/dist/build/commands.d.ts +5 -0
- package/dist/build/commands.js +109 -0
- package/dist/build/config.d.ts +3 -0
- package/dist/build/config.js +103 -0
- package/dist/build/css-imports.d.ts +23 -0
- package/dist/build/css-imports.js +50 -0
- package/dist/build/css-step.d.ts +10 -0
- package/dist/build/css-step.js +27 -0
- package/dist/build/css.d.ts +24 -0
- package/dist/build/css.js +47 -0
- package/dist/build/options.d.ts +55 -0
- package/dist/build/options.js +70 -0
- package/dist/build/release.d.ts +5 -0
- package/dist/build/release.js +34 -0
- package/dist/build/report.d.ts +7 -0
- package/dist/build/report.js +16 -0
- package/dist/build/vault.d.ts +26 -0
- package/dist/build/vault.js +290 -0
- package/dist/build-info.json +1 -0
- package/dist/cli/argv.d.ts +14 -0
- package/dist/cli/argv.js +18 -0
- package/dist/cli/commands.d.ts +3 -0
- package/dist/cli/commands.js +7 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +23 -0
- package/dist/cli/process-reporter.d.ts +5 -0
- package/dist/cli/process-reporter.js +15 -0
- package/dist/cli/registry.d.ts +4 -0
- package/dist/cli/registry.js +15 -0
- package/dist/cli/reporter.d.ts +53 -0
- package/dist/cli/reporter.js +100 -0
- package/dist/cli/run.d.ts +9 -0
- package/dist/cli/run.js +61 -0
- package/dist/cli/types.d.ts +27 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/version.d.ts +13 -0
- package/dist/cli/version.js +61 -0
- package/dist/config/define-config.d.ts +3 -0
- package/dist/config/define-config.js +4 -0
- package/dist/config/load-config.d.ts +6 -0
- package/dist/config/load-config.js +70 -0
- package/dist/config/manifest.d.ts +3 -0
- package/dist/config/manifest.js +72 -0
- package/dist/config/types.d.ts +146 -0
- package/dist/config/types.js +23 -0
- package/dist/demo/args.d.ts +4 -0
- package/dist/demo/args.js +13 -0
- package/dist/demo/checks.d.ts +56 -0
- package/dist/demo/checks.js +124 -0
- package/dist/demo/commands.d.ts +3 -0
- package/dist/demo/commands.js +65 -0
- package/dist/demo/config.d.ts +57 -0
- package/dist/demo/config.js +337 -0
- package/dist/demo/ffmpeg-run.d.ts +18 -0
- package/dist/demo/ffmpeg-run.js +59 -0
- package/dist/demo/ffmpeg.d.ts +63 -0
- package/dist/demo/ffmpeg.js +111 -0
- package/dist/demo/films.d.ts +46 -0
- package/dist/demo/films.js +134 -0
- package/dist/demo/phone-layout.d.ts +38 -0
- package/dist/demo/phone-layout.js +98 -0
- package/dist/demo/phone-render.d.ts +28 -0
- package/dist/demo/phone-render.js +124 -0
- package/dist/demo/published.d.ts +16 -0
- package/dist/demo/published.js +72 -0
- package/dist/demo/run.d.ts +31 -0
- package/dist/demo/run.js +397 -0
- package/dist/demo/stills.d.ts +21 -0
- package/dist/demo/stills.js +62 -0
- package/dist/e2e/artifacts.d.ts +27 -0
- package/dist/e2e/artifacts.js +90 -0
- package/dist/e2e/cleanup.d.ts +54 -0
- package/dist/e2e/cleanup.js +109 -0
- package/dist/e2e/config.d.ts +9 -0
- package/dist/e2e/config.js +42 -0
- package/dist/e2e/create-test.d.ts +37 -0
- package/dist/e2e/create-test.js +109 -0
- package/dist/e2e/demo/clip.d.ts +21 -0
- package/dist/e2e/demo/clip.js +44 -0
- package/dist/e2e/demo/create-demo.d.ts +42 -0
- package/dist/e2e/demo/create-demo.js +439 -0
- package/dist/e2e/demo/manifest.d.ts +76 -0
- package/dist/e2e/demo/manifest.js +168 -0
- package/dist/e2e/demo/names.d.ts +18 -0
- package/dist/e2e/demo/names.js +44 -0
- package/dist/e2e/demo/options.d.ts +22 -0
- package/dist/e2e/demo/options.js +59 -0
- package/dist/e2e/demo/ownership.d.ts +27 -0
- package/dist/e2e/demo/ownership.js +65 -0
- package/dist/e2e/demo/page-scripts.d.ts +82 -0
- package/dist/e2e/demo/page-scripts.js +250 -0
- package/dist/e2e/demo/png.d.ts +8 -0
- package/dist/e2e/demo/png.js +23 -0
- package/dist/e2e/demo/presets.d.ts +43 -0
- package/dist/e2e/demo/presets.js +20 -0
- package/dist/e2e/demo/privacy.d.ts +18 -0
- package/dist/e2e/demo/privacy.js +30 -0
- package/dist/e2e/demo/still-options.d.ts +22 -0
- package/dist/e2e/demo/still-options.js +68 -0
- package/dist/e2e/demo/types.d.ts +184 -0
- package/dist/e2e/demo/types.js +1 -0
- package/dist/e2e/electron-binary.d.ts +15 -0
- package/dist/e2e/electron-binary.js +30 -0
- package/dist/e2e/fixtures.d.ts +62 -0
- package/dist/e2e/fixtures.js +68 -0
- package/dist/e2e/gate.d.ts +4 -0
- package/dist/e2e/gate.js +8 -0
- package/dist/e2e/global-setup.d.ts +11 -0
- package/dist/e2e/global-setup.js +17 -0
- package/dist/e2e/helpers/commands.d.ts +14 -0
- package/dist/e2e/helpers/commands.js +56 -0
- package/dist/e2e/helpers/create-helpers.d.ts +24 -0
- package/dist/e2e/helpers/create-helpers.js +582 -0
- package/dist/e2e/helpers/device-metrics.d.ts +21 -0
- package/dist/e2e/helpers/device-metrics.js +25 -0
- package/dist/e2e/helpers/ime.d.ts +13 -0
- package/dist/e2e/helpers/ime.js +19 -0
- package/dist/e2e/helpers/layout-page-scripts.d.ts +103 -0
- package/dist/e2e/helpers/layout-page-scripts.js +224 -0
- package/dist/e2e/helpers/layout.d.ts +83 -0
- package/dist/e2e/helpers/layout.js +148 -0
- package/dist/e2e/helpers/mobile.d.ts +31 -0
- package/dist/e2e/helpers/mobile.js +26 -0
- package/dist/e2e/helpers/page-scripts.d.ts +194 -0
- package/dist/e2e/helpers/page-scripts.js +467 -0
- package/dist/e2e/helpers/settings.d.ts +8 -0
- package/dist/e2e/helpers/settings.js +16 -0
- package/dist/e2e/helpers/settle.d.ts +28 -0
- package/dist/e2e/helpers/settle.js +33 -0
- package/dist/e2e/helpers/types.d.ts +193 -0
- package/dist/e2e/helpers/types.js +1 -0
- package/dist/e2e/helpers/view-mode.d.ts +23 -0
- package/dist/e2e/helpers/view-mode.js +35 -0
- package/dist/e2e/index.d.ts +14 -0
- package/dist/e2e/index.js +4 -0
- package/dist/e2e/internals.d.ts +155 -0
- package/dist/e2e/internals.js +8 -0
- package/dist/e2e/obsidian-path.d.ts +17 -0
- package/dist/e2e/obsidian-path.js +31 -0
- package/dist/e2e/options.d.ts +123 -0
- package/dist/e2e/options.js +244 -0
- package/dist/e2e/page-scripts.d.ts +45 -0
- package/dist/e2e/page-scripts.js +53 -0
- package/dist/e2e/peers.d.ts +9 -0
- package/dist/e2e/peers.js +19 -0
- package/dist/e2e/plugins.d.ts +32 -0
- package/dist/e2e/plugins.js +119 -0
- package/dist/e2e/process-tree.d.ts +33 -0
- package/dist/e2e/process-tree.js +133 -0
- package/dist/e2e/readiness.d.ts +23 -0
- package/dist/e2e/readiness.js +63 -0
- package/dist/e2e/seed.d.ts +34 -0
- package/dist/e2e/seed.js +122 -0
- package/dist/e2e/session.d.ts +71 -0
- package/dist/e2e/session.js +266 -0
- package/dist/e2e/vault.d.ts +52 -0
- package/dist/e2e/vault.js +146 -0
- package/dist/e2e/version.d.ts +25 -0
- package/dist/e2e/version.js +40 -0
- package/dist/eslint/index.d.ts +2 -0
- package/dist/eslint/index.js +1 -0
- package/dist/eslint/obsidian-plugin.d.ts +49 -0
- package/dist/eslint/obsidian-plugin.js +115 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/kit/args.d.ts +7 -0
- package/dist/kit/args.js +21 -0
- package/dist/kit/commands.d.ts +3 -0
- package/dist/kit/commands.js +52 -0
- package/dist/kit/files.d.ts +3 -0
- package/dist/kit/files.js +24 -0
- package/dist/kit/pins.d.ts +89 -0
- package/dist/kit/pins.js +178 -0
- package/dist/kit/remote.d.ts +13 -0
- package/dist/kit/remote.js +33 -0
- package/dist/kit/runners.d.ts +11 -0
- package/dist/kit/runners.js +53 -0
- package/dist/kit/terminal-text.d.ts +6 -0
- package/dist/kit/terminal-text.js +20 -0
- package/dist/kit/upgrade.d.ts +26 -0
- package/dist/kit/upgrade.js +162 -0
- package/dist/peers/resolve.d.ts +8 -0
- package/dist/peers/resolve.js +28 -0
- package/dist/peers/versions.d.ts +30 -0
- package/dist/peers/versions.js +32 -0
- package/dist/release/api-check.d.ts +27 -0
- package/dist/release/api-check.js +119 -0
- package/dist/release/args.d.ts +40 -0
- package/dist/release/args.js +120 -0
- package/dist/release/assets.d.ts +21 -0
- package/dist/release/assets.js +35 -0
- package/dist/release/build-check.d.ts +43 -0
- package/dist/release/build-check.js +184 -0
- package/dist/release/build-script.d.ts +12 -0
- package/dist/release/build-script.js +30 -0
- package/dist/release/build-tagged.d.ts +26 -0
- package/dist/release/build-tagged.js +52 -0
- package/dist/release/bump.d.ts +24 -0
- package/dist/release/bump.js +58 -0
- package/dist/release/changelog.d.ts +25 -0
- package/dist/release/changelog.js +148 -0
- package/dist/release/check.d.ts +38 -0
- package/dist/release/check.js +150 -0
- package/dist/release/commands.d.ts +3 -0
- package/dist/release/commands.js +154 -0
- package/dist/release/committed-tree.d.ts +63 -0
- package/dist/release/committed-tree.js +118 -0
- package/dist/release/config.d.ts +3 -0
- package/dist/release/config.js +28 -0
- package/dist/release/gh-access.d.ts +14 -0
- package/dist/release/gh-access.js +45 -0
- package/dist/release/gh.d.ts +10 -0
- package/dist/release/gh.js +33 -0
- package/dist/release/git.d.ts +49 -0
- package/dist/release/git.js +111 -0
- package/dist/release/interrupt.d.ts +30 -0
- package/dist/release/interrupt.js +60 -0
- package/dist/release/json.d.ts +33 -0
- package/dist/release/json.js +81 -0
- package/dist/release/kit-check.d.ts +8 -0
- package/dist/release/kit-check.js +51 -0
- package/dist/release/manifest-rules.d.ts +23 -0
- package/dist/release/manifest-rules.js +255 -0
- package/dist/release/preflight.d.ts +10 -0
- package/dist/release/preflight.js +65 -0
- package/dist/release/problems.d.ts +24 -0
- package/dist/release/problems.js +11 -0
- package/dist/release/project-files.d.ts +14 -0
- package/dist/release/project-files.js +16 -0
- package/dist/release/publish-command.d.ts +21 -0
- package/dist/release/publish-command.js +83 -0
- package/dist/release/publish-git.d.ts +37 -0
- package/dist/release/publish-git.js +108 -0
- package/dist/release/publish-state.d.ts +29 -0
- package/dist/release/publish-state.js +70 -0
- package/dist/release/publish-verify.d.ts +41 -0
- package/dist/release/publish-verify.js +112 -0
- package/dist/release/publish-wait.d.ts +25 -0
- package/dist/release/publish-wait.js +56 -0
- package/dist/release/publish.d.ts +35 -0
- package/dist/release/publish.js +181 -0
- package/dist/release/release-assets.d.ts +39 -0
- package/dist/release/release-assets.js +68 -0
- package/dist/release/release.d.ts +37 -0
- package/dist/release/release.js +179 -0
- package/dist/release/remote.d.ts +12 -0
- package/dist/release/remote.js +15 -0
- package/dist/release/reproducible.d.ts +16 -0
- package/dist/release/reproducible.js +34 -0
- package/dist/release/run-tests.d.ts +5 -0
- package/dist/release/run-tests.js +17 -0
- package/dist/release/semver.d.ts +8 -0
- package/dist/release/semver.js +60 -0
- package/dist/release/version-rules.d.ts +28 -0
- package/dist/release/version-rules.js +63 -0
- package/dist/release/versions-json.d.ts +15 -0
- package/dist/release/versions-json.js +88 -0
- package/dist/release/workflow-run.d.ts +44 -0
- package/dist/release/workflow-run.js +71 -0
- package/dist/scanner/code-checks.d.ts +41 -0
- package/dist/scanner/code-checks.js +82 -0
- package/dist/scanner/commands.d.ts +3 -0
- package/dist/scanner/commands.js +43 -0
- package/dist/scanner/config.d.ts +7 -0
- package/dist/scanner/config.js +25 -0
- package/dist/scanner/css-check.d.ts +26 -0
- package/dist/scanner/css-check.js +63 -0
- package/dist/scanner/eslint-nesting.d.ts +16 -0
- package/dist/scanner/eslint-nesting.js +45 -0
- package/dist/scanner/findings.d.ts +23 -0
- package/dist/scanner/findings.js +21 -0
- package/dist/scanner/git-files.d.ts +16 -0
- package/dist/scanner/git-files.js +73 -0
- package/dist/scanner/lint.d.ts +47 -0
- package/dist/scanner/lint.js +163 -0
- package/dist/scanner/meta-checks.d.ts +8 -0
- package/dist/scanner/meta-checks.js +22 -0
- package/dist/scanner/outside-project.d.ts +19 -0
- package/dist/scanner/outside-project.js +20 -0
- package/dist/scanner/run.d.ts +19 -0
- package/dist/scanner/run.js +78 -0
- package/dist/scanner/scanner-config.d.ts +114 -0
- package/dist/scanner/scanner-config.js +207 -0
- package/dist/scanner/typescript-gate.d.ts +30 -0
- package/dist/scanner/typescript-gate.js +73 -0
- package/dist/vitest/build-config.d.ts +17 -0
- package/dist/vitest/build-config.js +106 -0
- package/dist/vitest/define-unit-config.d.ts +27 -0
- package/dist/vitest/define-unit-config.js +45 -0
- package/dist/vitest/dom/elements.d.ts +87 -0
- package/dist/vitest/dom/elements.js +291 -0
- package/dist/vitest/dom/index.d.ts +1 -0
- package/dist/vitest/dom/index.js +1 -0
- package/dist/vitest/dom/install.d.ts +8 -0
- package/dist/vitest/dom/install.js +261 -0
- package/dist/vitest/dom/setup.d.ts +1 -0
- package/dist/vitest/dom/setup.js +3 -0
- package/dist/vitest/index.d.ts +3 -0
- package/dist/vitest/index.js +2 -0
- package/dist/vitest/options.d.ts +92 -0
- package/dist/vitest/options.js +136 -0
- package/dist/vitest/peers.d.ts +10 -0
- package/dist/vitest/peers.js +51 -0
- package/dist/vitest/workspace-root.d.ts +7 -0
- package/dist/vitest/workspace-root.js +39 -0
- package/docs/build.md +232 -0
- package/docs/ci.md +182 -0
- package/docs/demo.md +364 -0
- package/docs/e2e.md +563 -0
- package/docs/release.md +374 -0
- package/docs/scanner.md +204 -0
- package/docs/unit.md +291 -0
- package/package.json +100 -4
- package/plugins/opdk/skills/audit/SKILL.md +81 -0
- package/plugins/opdk/skills/build/SKILL.md +79 -0
- package/plugins/opdk/skills/demo/SKILL.md +102 -0
- package/plugins/opdk/skills/e2e/SKILL.md +132 -0
- package/plugins/opdk/skills/release/SKILL.md +84 -0
- package/plugins/opdk/skills/scanner/SKILL.md +60 -0
- package/plugins/opdk/skills/unit/SKILL.md +90 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
/** Environment variable that points `opdk demo` at an ffmpeg binary (a build with libx264, say) instead of the one on PATH. */
|
|
3
|
+
export const FFMPEG_ENV = "OPDK_FFMPEG";
|
|
4
|
+
export const INSTALL_HINT = `Install ffmpeg (macOS: brew install ffmpeg; Debian or Ubuntu: sudo apt install ffmpeg; Windows: winget install ffmpeg) ` +
|
|
5
|
+
`and make sure it is on PATH, or set ${FFMPEG_ENV} to the binary.`;
|
|
6
|
+
/** Picks the ffmpeg command: `OPDK_FFMPEG` when set (and then it must work), otherwise `ffmpeg` from PATH. */
|
|
7
|
+
export async function locateFfmpeg(env, probe) {
|
|
8
|
+
const fromEnv = env[FFMPEG_ENV];
|
|
9
|
+
const explicit = fromEnv !== undefined && fromEnv !== "";
|
|
10
|
+
const command = explicit ? fromEnv : "ffmpeg";
|
|
11
|
+
const result = await probe(command);
|
|
12
|
+
if (result.ok) {
|
|
13
|
+
return { command, version: result.version ?? command };
|
|
14
|
+
}
|
|
15
|
+
if (explicit) {
|
|
16
|
+
throw new Error(`${FFMPEG_ENV}=${fromEnv} cannot run (${result.error ?? "unknown error"}). Point it at a working ffmpeg binary or unset it to use PATH.`);
|
|
17
|
+
}
|
|
18
|
+
throw new Error(`ffmpeg was not found on PATH (${result.error ?? "unknown error"}). ${INSTALL_HINT}`);
|
|
19
|
+
}
|
|
20
|
+
/** Single quotes in a concat list file are escaped as `'\''`. */
|
|
21
|
+
function quoteConcatPath(file) {
|
|
22
|
+
return `'${file.replaceAll("'", "'\\''")}'`;
|
|
23
|
+
}
|
|
24
|
+
const SINGLE_IMAGE_OPTION = "option pattern_type none";
|
|
25
|
+
/** Seconds the film runs: the sum of the frame holds. */
|
|
26
|
+
export function totalHold(frames) {
|
|
27
|
+
return frames.reduce((sum, frame) => sum + frame.hold, 0);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The concat demuxer list for a film: each frame with its own `duration`.
|
|
31
|
+
*
|
|
32
|
+
* The demuxer ignores the duration of the last entry unless that file is listed once more after it, so the last
|
|
33
|
+
* frame is repeated. The repeat plays the whole last hold a second time (holds of 1 s and 2 s run 5 s; without the
|
|
34
|
+
* repeat the last hold is not honoured), which is why the encodes also pass `-t <total hold>`: it cuts the film
|
|
35
|
+
* back to the sum of the holds.
|
|
36
|
+
*
|
|
37
|
+
* Every entry also sets `option pattern_type none`. The concat demuxer opens each entry with the image2 demuxer, which
|
|
38
|
+
* reads a `%d` in the path as a numbered sequence ("opdk-100%d-x/frame.png" is then looked for as frame 0 to 4 and
|
|
39
|
+
* not found). The error names the list file, not the entry. `-pattern_type none` on the command line does not reach
|
|
40
|
+
* the entries; the `option` line does, and the same list works on macOS and Linux ffmpeg.
|
|
41
|
+
*/
|
|
42
|
+
export function buildConcatList(dir, frames) {
|
|
43
|
+
const last = frames.at(-1);
|
|
44
|
+
if (last === undefined) {
|
|
45
|
+
throw new Error("Cannot build a film from zero frames.");
|
|
46
|
+
}
|
|
47
|
+
const lines = ["ffconcat version 1.0"];
|
|
48
|
+
for (const frame of frames) {
|
|
49
|
+
lines.push(`file ${quoteConcatPath(path.join(dir, frame.file))}`, SINGLE_IMAGE_OPTION, `duration ${frame.hold.toFixed(3)}`);
|
|
50
|
+
}
|
|
51
|
+
lines.push(`file ${quoteConcatPath(path.join(dir, last.file))}`, SINGLE_IMAGE_OPTION);
|
|
52
|
+
return `${lines.join("\n")}\n`;
|
|
53
|
+
}
|
|
54
|
+
const COMMON = ["-hide_banner", "-v", "error", "-y"];
|
|
55
|
+
/**
|
|
56
|
+
* Reads the next input as one picture. Left to itself ffmpeg treats a `%d` in a path as a numbered sequence, and the
|
|
57
|
+
* option `-pattern_type` only exists on the image2 demuxer, which ffmpeg would not pick for a PNG on its own.
|
|
58
|
+
*/
|
|
59
|
+
const SINGLE_IMAGE = ["-f", "image2", "-pattern_type", "none"];
|
|
60
|
+
function concatInput(list, frames) {
|
|
61
|
+
return ["-f", "concat", "-safe", "0", "-i", list, "-t", totalHold(frames).toFixed(3)];
|
|
62
|
+
}
|
|
63
|
+
/** MP4 for the web: x264, yuv420p (the only format every browser and phone plays), even dimensions, moov atom first. */
|
|
64
|
+
export function mp4Args(params) {
|
|
65
|
+
return [
|
|
66
|
+
...COMMON,
|
|
67
|
+
...concatInput(params.list, params.frames),
|
|
68
|
+
"-vf",
|
|
69
|
+
`fps=${String(params.fps)},scale=trunc(iw/2)*2:trunc(ih/2)*2,format=yuv420p`,
|
|
70
|
+
"-c:v",
|
|
71
|
+
"libx264",
|
|
72
|
+
"-crf",
|
|
73
|
+
"20",
|
|
74
|
+
"-preset",
|
|
75
|
+
"slow",
|
|
76
|
+
"-movflags",
|
|
77
|
+
"+faststart",
|
|
78
|
+
"-an",
|
|
79
|
+
params.out,
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
/** GIF with its own palette: `stats_mode=diff` spends colours on what moves, bayer dithering stays small on flat UI. */
|
|
83
|
+
export function gifArgs(params) {
|
|
84
|
+
const filter = `fps=${String(params.fps)},scale=${String(params.width)}:-1:flags=lanczos,split[a][b];` +
|
|
85
|
+
`[a]palettegen=max_colors=${String(params.colors)}:stats_mode=diff[p];` +
|
|
86
|
+
`[b][p]paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle`;
|
|
87
|
+
return [...COMMON, ...concatInput(params.list, params.frames), "-vf", filter, "-loop", "0", params.out];
|
|
88
|
+
}
|
|
89
|
+
/** The poster: the first frame at `width`. `-update 1` writes the output as one picture even when its path has a `%d`. */
|
|
90
|
+
export function posterArgs(params) {
|
|
91
|
+
return [...COMMON, ...SINGLE_IMAGE, "-i", params.frame, "-vf", `scale=${String(params.width)}:-1:flags=lanczos`, "-frames:v", "1", "-update", "1", params.out];
|
|
92
|
+
}
|
|
93
|
+
/** Decodes one picture to raw RGBA on stdout, for comparing pixels. */
|
|
94
|
+
export function rawFrameArgs(frame) {
|
|
95
|
+
return [...COMMON, ...SINGLE_IMAGE, "-i", frame, "-frames:v", "1", "-f", "rawvideo", "-pix_fmt", "rgba", "pipe:1"];
|
|
96
|
+
}
|
|
97
|
+
/** The last non-empty lines of ffmpeg's stderr, where it says what went wrong. */
|
|
98
|
+
export function stderrTail(stderr, lines = 8) {
|
|
99
|
+
return stderr
|
|
100
|
+
.split(/\r?\n/)
|
|
101
|
+
.filter((line) => line.trim() !== "")
|
|
102
|
+
.slice(-lines)
|
|
103
|
+
.join("\n");
|
|
104
|
+
}
|
|
105
|
+
/** GIF width: the configured one, else the frame width capped at `maxAuto`; never above the frame width. */
|
|
106
|
+
export function resolveGifWidth(configured, frameWidth, maxAuto) {
|
|
107
|
+
if (configured === null) {
|
|
108
|
+
return { width: Math.min(frameWidth, maxAuto), clamped: false };
|
|
109
|
+
}
|
|
110
|
+
return configured > frameWidth ? { width: frameWidth, clamped: true } : { width: configured, clamped: false };
|
|
111
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type FilmFrame, type FilmManifest } from "../e2e/demo/manifest.js";
|
|
2
|
+
/** The folder of films under the demo output folder. */
|
|
3
|
+
export declare const FILMS_DIR = "films";
|
|
4
|
+
export interface FoundFilm {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
/** Absolute folder of the film's frames and manifest. */
|
|
7
|
+
readonly dir: string;
|
|
8
|
+
readonly manifest: FilmManifest;
|
|
9
|
+
}
|
|
10
|
+
/** A film folder that cannot be encoded now, and why. */
|
|
11
|
+
export interface SkippedFilm {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly reason: string;
|
|
14
|
+
}
|
|
15
|
+
export interface FilmListing {
|
|
16
|
+
readonly complete: readonly FoundFilm[];
|
|
17
|
+
readonly incomplete: readonly SkippedFilm[];
|
|
18
|
+
/** Folders whose manifest is missing or unreadable: not a film the kit can name, so a problem rather than a skip. */
|
|
19
|
+
readonly broken: readonly SkippedFilm[];
|
|
20
|
+
}
|
|
21
|
+
/** Why a manifest that parsed cannot be encoded, or null when it can. */
|
|
22
|
+
export declare function incompleteReason(manifest: FilmManifest): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* Reads `<outDir>/films/*`/manifest.json. `owner.json` and `.owners/` are the recorder's bookkeeping and are never read.
|
|
25
|
+
* A missing `films` folder is an empty listing, not an error: the caller says what to do about it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function listFilms(outDir: string): FilmListing;
|
|
28
|
+
/**
|
|
29
|
+
* Moves a finished file into place. A rename replaces the old file in one step; across volumes (the work folder in
|
|
30
|
+
* the temp folder, the output in a project on another disk) a rename is impossible, so the file is copied next to its
|
|
31
|
+
* destination first and renamed from there, and the old file still stays whole until the new one is complete.
|
|
32
|
+
*/
|
|
33
|
+
export declare function moveFile(from: string, to: string): void;
|
|
34
|
+
/** Pixel size of a PNG from its first bytes, without reading the picture. */
|
|
35
|
+
export declare function readPngFileSize(file: string): {
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Fails when a frame file is missing or is not `expected` pixels. The encoder needs one size, and a frame that is
|
|
41
|
+
* gone or stale would otherwise show up as a cryptic ffmpeg error or a film with a jump in it.
|
|
42
|
+
*/
|
|
43
|
+
export declare function assertFrameFiles(dir: string, frames: readonly FilmFrame[], expected: {
|
|
44
|
+
width: number | null;
|
|
45
|
+
height: number | null;
|
|
46
|
+
}): void;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { MANIFEST_FILE, parseFilmManifest } from "../e2e/demo/manifest.js";
|
|
4
|
+
import { readPngSize } from "../e2e/demo/png.js";
|
|
5
|
+
/** The folder of films under the demo output folder. */
|
|
6
|
+
export const FILMS_DIR = "films";
|
|
7
|
+
function isMissing(error) {
|
|
8
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
9
|
+
}
|
|
10
|
+
/** Why a manifest that parsed cannot be encoded, or null when it can. */
|
|
11
|
+
export function incompleteReason(manifest) {
|
|
12
|
+
if (!manifest.complete) {
|
|
13
|
+
return "its recording did not finish (the test is still running, or it failed); run the spec again";
|
|
14
|
+
}
|
|
15
|
+
if (manifest.frames.length === 0) {
|
|
16
|
+
return "it has no frames; call film.shot() in the test";
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reads `<outDir>/films/*`/manifest.json. `owner.json` and `.owners/` are the recorder's bookkeeping and are never read.
|
|
22
|
+
* A missing `films` folder is an empty listing, not an error: the caller says what to do about it.
|
|
23
|
+
*/
|
|
24
|
+
export function listFilms(outDir) {
|
|
25
|
+
const root = path.join(outDir, FILMS_DIR);
|
|
26
|
+
let entries;
|
|
27
|
+
try {
|
|
28
|
+
entries = fs.readdirSync(root, { withFileTypes: true });
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (isMissing(error)) {
|
|
32
|
+
return { complete: [], incomplete: [], broken: [] };
|
|
33
|
+
}
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
const complete = [];
|
|
37
|
+
const incomplete = [];
|
|
38
|
+
const broken = [];
|
|
39
|
+
for (const entry of entries.filter((item) => item.isDirectory()).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
40
|
+
const dir = path.join(root, entry.name);
|
|
41
|
+
let text;
|
|
42
|
+
try {
|
|
43
|
+
text = fs.readFileSync(path.join(dir, MANIFEST_FILE), "utf8");
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (!isMissing(error)) {
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
broken.push({ name: entry.name, reason: `${MANIFEST_FILE} is missing (an interrupted recording, or a folder that is not a film)` });
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
let manifest;
|
|
53
|
+
try {
|
|
54
|
+
manifest = parseFilmManifest(text);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
broken.push({ name: entry.name, reason: error instanceof Error ? error.message : String(error) });
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (manifest.name !== entry.name) {
|
|
61
|
+
broken.push({ name: entry.name, reason: `${MANIFEST_FILE} says the film is "${manifest.name}", not the folder name; do not rename film folders` });
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const reason = incompleteReason(manifest);
|
|
65
|
+
if (reason === null) {
|
|
66
|
+
complete.push({ name: entry.name, dir, manifest });
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
incomplete.push({ name: entry.name, reason });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { complete, incomplete, broken };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Moves a finished file into place. A rename replaces the old file in one step; across volumes (the work folder in
|
|
76
|
+
* the temp folder, the output in a project on another disk) a rename is impossible, so the file is copied next to its
|
|
77
|
+
* destination first and renamed from there, and the old file still stays whole until the new one is complete.
|
|
78
|
+
*/
|
|
79
|
+
export function moveFile(from, to) {
|
|
80
|
+
try {
|
|
81
|
+
fs.renameSync(from, to);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (!(error instanceof Error && "code" in error && error.code === "EXDEV")) {
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const partial = `${to}.opdk-partial`;
|
|
90
|
+
try {
|
|
91
|
+
fs.copyFileSync(from, partial);
|
|
92
|
+
fs.renameSync(partial, to);
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
fs.rmSync(partial, { force: true });
|
|
96
|
+
fs.rmSync(from, { force: true });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const PNG_HEADER_BYTES = 24;
|
|
100
|
+
/** Pixel size of a PNG from its first bytes, without reading the picture. */
|
|
101
|
+
export function readPngFileSize(file) {
|
|
102
|
+
const fd = fs.openSync(file, "r");
|
|
103
|
+
try {
|
|
104
|
+
const header = Buffer.alloc(PNG_HEADER_BYTES);
|
|
105
|
+
const read = fs.readSync(fd, header, 0, PNG_HEADER_BYTES, 0);
|
|
106
|
+
return readPngSize(header.subarray(0, read));
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
fs.closeSync(fd);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Fails when a frame file is missing or is not `expected` pixels. The encoder needs one size, and a frame that is
|
|
114
|
+
* gone or stale would otherwise show up as a cryptic ffmpeg error or a film with a jump in it.
|
|
115
|
+
*/
|
|
116
|
+
export function assertFrameFiles(dir, frames, expected) {
|
|
117
|
+
for (const frame of frames) {
|
|
118
|
+
const file = path.join(dir, frame.file);
|
|
119
|
+
let size;
|
|
120
|
+
try {
|
|
121
|
+
size = readPngFileSize(file);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (isMissing(error)) {
|
|
125
|
+
throw new Error(`frame ${frame.file} is missing from ${dir}. Run the spec again to record the film.`, { cause: error });
|
|
126
|
+
}
|
|
127
|
+
throw new Error(`frame ${frame.file} is not a readable PNG: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
128
|
+
}
|
|
129
|
+
if (size.width !== expected.width || size.height !== expected.height) {
|
|
130
|
+
throw new Error(`frame ${frame.file} is ${String(size.width)} x ${String(size.height)} px but the manifest says ${String(expected.width)} x ${String(expected.height)}. ` +
|
|
131
|
+
`The frames and the manifest come from different recordings; run the spec again.`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { DemoPhoneConfig } from "../config/types.js";
|
|
2
|
+
import type { FilmFrame } from "../e2e/demo/manifest.js";
|
|
3
|
+
import type { ThemeMode } from "../e2e/demo/names.js";
|
|
4
|
+
/** CSS size of the composed page. Rendered at 2x, so each frame is 2000 x 1240 px. */
|
|
5
|
+
export declare const PAGE_WIDTH = 1000;
|
|
6
|
+
export declare const PAGE_HEIGHT = 620;
|
|
7
|
+
export declare const PAGE_SCALE = 2;
|
|
8
|
+
/** The stack Obsidian uses for its interface, so the captions look like the app next to them. */
|
|
9
|
+
export declare const OBSIDIAN_FONT = "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Inter, Roboto, Oxygen, Ubuntu, Cantarell, \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\", sans-serif";
|
|
10
|
+
/** What the page is drawn with, after the theme and every layer of `demo.phone` are merged. */
|
|
11
|
+
export interface PhoneLayout {
|
|
12
|
+
readonly background: string;
|
|
13
|
+
readonly text: string;
|
|
14
|
+
readonly muted: string;
|
|
15
|
+
readonly accent: string;
|
|
16
|
+
readonly font: string;
|
|
17
|
+
readonly title: string | null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Merges, weakest first: the defaults of the theme, then for each layer its top-level colours and then the entry of
|
|
21
|
+
* the film's theme. Layers are the `phone` entries of the config, from `demo` down to the film. A film without a
|
|
22
|
+
* theme gets the light defaults and no theme entry.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolvePhoneLayout(layers: readonly DemoPhoneConfig[], theme: ThemeMode | null): PhoneLayout;
|
|
25
|
+
/** Text from the plugin or a test ends up inside HTML: every character that could open markup is escaped. */
|
|
26
|
+
export declare function escapeHtml(text: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Which caption each frame highlights: its own, or the last one before it when it has none (a frame between two
|
|
29
|
+
* steps, such as the tap that opens the next one). Frames before the first caption highlight nothing.
|
|
30
|
+
*/
|
|
31
|
+
export declare function captionSteps(frames: readonly FilmFrame[]): (number | null)[];
|
|
32
|
+
/** The page for one frame: the phone picture on the left, the caption list on the right with `step` highlighted. */
|
|
33
|
+
export declare function buildPhonePage(params: {
|
|
34
|
+
imageDataUrl: string;
|
|
35
|
+
captions: readonly string[];
|
|
36
|
+
step: number | null;
|
|
37
|
+
layout: PhoneLayout;
|
|
38
|
+
}): string;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { assertCssValue } from "./config.js";
|
|
2
|
+
/** CSS size of the composed page. Rendered at 2x, so each frame is 2000 x 1240 px. */
|
|
3
|
+
export const PAGE_WIDTH = 1000;
|
|
4
|
+
export const PAGE_HEIGHT = 620;
|
|
5
|
+
export const PAGE_SCALE = 2;
|
|
6
|
+
/** The stack Obsidian uses for its interface, so the captions look like the app next to them. */
|
|
7
|
+
export const OBSIDIAN_FONT = `-apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif`;
|
|
8
|
+
/** Neutral colours close to the purple one plugin's film uses; a plugin sets its own in `demo.phone`. */
|
|
9
|
+
const DEFAULT_COLORS = {
|
|
10
|
+
light: { background: "#f4f1fd", text: "#222222", muted: "#8b8b94", accent: "#6f4fe0" },
|
|
11
|
+
dark: { background: "#191722", text: "#e4e4e8", muted: "#8a8794", accent: "#a48cff" },
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Merges, weakest first: the defaults of the theme, then for each layer its top-level colours and then the entry of
|
|
15
|
+
* the film's theme. Layers are the `phone` entries of the config, from `demo` down to the film. A film without a
|
|
16
|
+
* theme gets the light defaults and no theme entry.
|
|
17
|
+
*/
|
|
18
|
+
export function resolvePhoneLayout(layers, theme) {
|
|
19
|
+
const defaults = DEFAULT_COLORS[theme ?? "light"];
|
|
20
|
+
let { background, text, muted, accent } = defaults;
|
|
21
|
+
let font = OBSIDIAN_FONT;
|
|
22
|
+
let title = null;
|
|
23
|
+
for (const layer of layers) {
|
|
24
|
+
const themed = theme === null ? undefined : layer[theme];
|
|
25
|
+
for (const source of [layer, themed]) {
|
|
26
|
+
background = source?.background ?? background;
|
|
27
|
+
text = source?.text ?? text;
|
|
28
|
+
muted = source?.muted ?? muted;
|
|
29
|
+
accent = source?.accent ?? accent;
|
|
30
|
+
}
|
|
31
|
+
font = layer.font ?? font;
|
|
32
|
+
title = layer.title ?? title;
|
|
33
|
+
}
|
|
34
|
+
return { background, text, muted, accent, font, title };
|
|
35
|
+
}
|
|
36
|
+
/** Text from the plugin or a test ends up inside HTML: every character that could open markup is escaped. */
|
|
37
|
+
export function escapeHtml(text) {
|
|
38
|
+
return text.replace(/[&<>"']/g, (char) => {
|
|
39
|
+
switch (char) {
|
|
40
|
+
case "&":
|
|
41
|
+
return "&";
|
|
42
|
+
case "<":
|
|
43
|
+
return "<";
|
|
44
|
+
case ">":
|
|
45
|
+
return ">";
|
|
46
|
+
case '"':
|
|
47
|
+
return """;
|
|
48
|
+
default:
|
|
49
|
+
return "'";
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** Escaped text with its line breaks kept as `<br>`. */
|
|
54
|
+
function lines(text) {
|
|
55
|
+
return text.split("\n").map(escapeHtml).join("<br>");
|
|
56
|
+
}
|
|
57
|
+
/** One caption: a text, or a heading and a text when it has a line break (`"Tap a day\nSee its value"`). */
|
|
58
|
+
function captionHtml(caption) {
|
|
59
|
+
const at = caption.indexOf("\n");
|
|
60
|
+
const text = at === -1 ? "" : caption.slice(at + 1).trim();
|
|
61
|
+
if (text === "") {
|
|
62
|
+
return `<span>${escapeHtml(caption.trim())}</span>`;
|
|
63
|
+
}
|
|
64
|
+
return `<span><b>${escapeHtml(caption.slice(0, at).trim())}</b><i>${escapeHtml(text)}</i></span>`;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Which caption each frame highlights: its own, or the last one before it when it has none (a frame between two
|
|
68
|
+
* steps, such as the tap that opens the next one). Frames before the first caption highlight nothing.
|
|
69
|
+
*/
|
|
70
|
+
export function captionSteps(frames) {
|
|
71
|
+
let current = null;
|
|
72
|
+
return frames.map((frame) => {
|
|
73
|
+
current = frame.caption ?? current;
|
|
74
|
+
return current;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/** The page for one frame: the phone picture on the left, the caption list on the right with `step` highlighted. */
|
|
78
|
+
export function buildPhonePage(params) {
|
|
79
|
+
const { layout, captions, step } = params;
|
|
80
|
+
const css = (value, what, kind = "color") => assertCssValue(value, `phone layout ${what}`, kind);
|
|
81
|
+
const items = captions
|
|
82
|
+
.map((caption, index) => `<li${index === step ? ' class="on"' : ""}><span class="n">${String(index + 1)}</span>${captionHtml(caption)}</li>`)
|
|
83
|
+
.join("");
|
|
84
|
+
const heading = layout.title === null ? "" : `<h1>${lines(layout.title)}</h1>`;
|
|
85
|
+
return `<!doctype html><html><head><meta charset="utf-8"><style>
|
|
86
|
+
html,body{margin:0;width:${String(PAGE_WIDTH)}px;height:${String(PAGE_HEIGHT)}px;overflow:hidden;background:${css(layout.background, "background")};font-family:${css(layout.font, "font", "font")};color:${css(layout.text, "text")}}
|
|
87
|
+
.wrap{display:flex;align-items:center;gap:56px;height:100%;padding:0 64px;box-sizing:border-box}
|
|
88
|
+
.phone{display:block;max-height:540px;max-width:420px;border-radius:36px;box-shadow:0 0 0 1px rgba(127,127,127,.28),0 24px 60px rgba(0,0,0,.22),0 4px 12px rgba(0,0,0,.12);flex:none}
|
|
89
|
+
h1{font-size:26px;line-height:1.2;margin:0 0 22px}
|
|
90
|
+
ol{list-style:none;margin:0;padding:0}
|
|
91
|
+
li{display:flex;align-items:center;gap:14px;font-size:20px;line-height:1.3;color:${css(layout.muted, "muted colour")};padding:10px 0}
|
|
92
|
+
li .n{display:inline-grid;place-items:center;width:30px;height:30px;border-radius:50%;border:2px solid currentColor;font-size:15px;font-weight:700;flex:none}
|
|
93
|
+
li b{display:block;font-size:22px}
|
|
94
|
+
li i{display:block;font-style:normal;font-size:17px;font-weight:400;white-space:pre-line}
|
|
95
|
+
li.on{color:${css(layout.text, "text")};font-weight:700}
|
|
96
|
+
li.on .n{background:${css(layout.accent, "accent")};border-color:${css(layout.accent, "accent")};color:#fff}
|
|
97
|
+
</style></head><body><div class="wrap"><img class="phone" src="${params.imageDataUrl}"><div>${heading}<ol>${items}</ol></div></div></body></html>`;
|
|
98
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { FilmFrame } from "../e2e/demo/manifest.js";
|
|
2
|
+
import type { VersionReader } from "../peers/versions.js";
|
|
3
|
+
import { type PhoneLayout } from "./phone-layout.js";
|
|
4
|
+
/**
|
|
5
|
+
* Set to `1` to start Electron with `--no-sandbox`. Needed where Chromium's sandbox cannot start, which is the
|
|
6
|
+
* case on GitHub's Ubuntu runners (no SUID helper, user namespaces restricted); the kit's own CI sets it. Do not
|
|
7
|
+
* set it on a machine where the plugin's Electron starts without it.
|
|
8
|
+
*/
|
|
9
|
+
export declare const NO_SANDBOX_ENV = "OPDK_COMPOSE_NO_SANDBOX";
|
|
10
|
+
/** Rejects with `what` when `work` has not settled in `ms`; the timer is always cleared. */
|
|
11
|
+
export declare function withTimeout<T>(work: Promise<T>, ms: number, what: string): Promise<T>;
|
|
12
|
+
export interface ComposeParams {
|
|
13
|
+
/** The plugin root: `electron` and nothing else is resolved from it. */
|
|
14
|
+
readonly cwd: string;
|
|
15
|
+
/** Folder of the film's frames. */
|
|
16
|
+
readonly filmDir: string;
|
|
17
|
+
readonly frames: readonly FilmFrame[];
|
|
18
|
+
readonly captions: readonly string[];
|
|
19
|
+
readonly layout: PhoneLayout;
|
|
20
|
+
/** Receives one `<frame file>` per input frame, 2000 x 1240 px. */
|
|
21
|
+
readonly outDir: string;
|
|
22
|
+
/** Where the render keeps its profile and script while it runs; removed at the end. Default: the OS temp folder. */
|
|
23
|
+
readonly tmpDir?: string;
|
|
24
|
+
/** Reads installed package versions for the Playwright and Electron check. Default: resolve them from `cwd`. */
|
|
25
|
+
readonly readVersion?: VersionReader;
|
|
26
|
+
}
|
|
27
|
+
/** Composes every frame into the caption page. Throws with what to do when Electron or Playwright is missing. */
|
|
28
|
+
export declare function composePhoneFrames(params: ComposeParams): Promise<void>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { assertE2ePeers } from "../e2e/peers.js";
|
|
6
|
+
import { createVersionReader } from "../peers/resolve.js";
|
|
7
|
+
import { assertElectronInstalled, createElectronProbe } from "../e2e/electron-binary.js";
|
|
8
|
+
import { readPngSize } from "../e2e/demo/png.js";
|
|
9
|
+
import { buildPhonePage, captionSteps, PAGE_HEIGHT, PAGE_SCALE, PAGE_WIDTH } from "./phone-layout.js";
|
|
10
|
+
/**
|
|
11
|
+
* The whole Electron side of the phone layout: a window the user never sees, an empty page. Playwright drives it, so
|
|
12
|
+
* nothing here knows about frames. `OPDK_COMPOSE_USERDATA` keeps Electron's profile out of the user's home.
|
|
13
|
+
*
|
|
14
|
+
* On Linux the window must be shown: Chromium on X11 does not paint a hidden window, so `Page.captureScreenshot`
|
|
15
|
+
* waits forever (GitHub's ubuntu runner under xvfb, and arm64 Docker). It is shown far off-screen and unfocusable,
|
|
16
|
+
* so nobody sees it. macOS paints a hidden window, so there it stays hidden and nothing flashes.
|
|
17
|
+
*/
|
|
18
|
+
const MAIN_SCRIPT = `const { app, BrowserWindow } = require("electron");
|
|
19
|
+
if (process.env.OPDK_COMPOSE_USERDATA) app.setPath("userData", process.env.OPDK_COMPOSE_USERDATA);
|
|
20
|
+
if (app.dock) app.dock.hide();
|
|
21
|
+
app.whenReady().then(() => {
|
|
22
|
+
const linux = process.platform === "linux";
|
|
23
|
+
const placement = linux ? { show: true, x: -20000, y: -20000, focusable: false } : { show: false };
|
|
24
|
+
const win = new BrowserWindow({ width: ${String(PAGE_WIDTH)}, height: ${String(PAGE_HEIGHT)}, ...placement, useContentSize: true, webPreferences: { backgroundThrottling: false } });
|
|
25
|
+
void win.loadURL("about:blank");
|
|
26
|
+
});
|
|
27
|
+
`;
|
|
28
|
+
const LAUNCH_TIMEOUT_MS = 60_000;
|
|
29
|
+
/** One page operation (loading a picture, taking a screenshot) takes milliseconds; this much means the window hung. */
|
|
30
|
+
const STEP_TIMEOUT_MS = 30_000;
|
|
31
|
+
/**
|
|
32
|
+
* Set to `1` to start Electron with `--no-sandbox`. Needed where Chromium's sandbox cannot start, which is the
|
|
33
|
+
* case on GitHub's Ubuntu runners (no SUID helper, user namespaces restricted); the kit's own CI sets it. Do not
|
|
34
|
+
* set it on a machine where the plugin's Electron starts without it.
|
|
35
|
+
*/
|
|
36
|
+
export const NO_SANDBOX_ENV = "OPDK_COMPOSE_NO_SANDBOX";
|
|
37
|
+
/** Rejects with `what` when `work` has not settled in `ms`; the timer is always cleared. */
|
|
38
|
+
export async function withTimeout(work, ms, what) {
|
|
39
|
+
let timer;
|
|
40
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
41
|
+
timer = setTimeout(() => {
|
|
42
|
+
reject(new Error(`${what} did not finish in ${String(ms / 1000)} s; the Electron window is stuck.`));
|
|
43
|
+
}, ms);
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
return await Promise.race([work, timeout]);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Composes every frame into the caption page. Throws with what to do when Electron or Playwright is missing. */
|
|
53
|
+
export async function composePhoneFrames(params) {
|
|
54
|
+
assertE2ePeers(params.readVersion ?? createVersionReader(params.cwd), 'layout "phone-captions"');
|
|
55
|
+
const executablePath = resolveElectron(params.cwd);
|
|
56
|
+
const { _electron } = await loadPlaywright();
|
|
57
|
+
const workDir = fs.mkdtempSync(path.join(params.tmpDir ?? os.tmpdir(), "opdk-demo-electron-"));
|
|
58
|
+
const mainFile = path.join(workDir, "main.cjs");
|
|
59
|
+
fs.writeFileSync(mainFile, MAIN_SCRIPT);
|
|
60
|
+
const env = { OPDK_COMPOSE_USERDATA: path.join(workDir, "profile") };
|
|
61
|
+
const args = process.env[NO_SANDBOX_ENV] === "1" ? ["--no-sandbox", mainFile] : [mainFile];
|
|
62
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
63
|
+
// Set, Electron would run as plain Node and have no `app`.
|
|
64
|
+
if (value !== undefined && key !== "ELECTRON_RUN_AS_NODE") {
|
|
65
|
+
env[key] = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const app = await _electron.launch({ executablePath, args, env, timeout: LAUNCH_TIMEOUT_MS });
|
|
70
|
+
try {
|
|
71
|
+
const win = await withTimeout(app.firstWindow(), LAUNCH_TIMEOUT_MS, "Opening the Electron window");
|
|
72
|
+
const cdp = await win.context().newCDPSession(win);
|
|
73
|
+
await withTimeout(cdp.send("Emulation.setDeviceMetricsOverride", { width: PAGE_WIDTH, height: PAGE_HEIGHT, deviceScaleFactor: PAGE_SCALE, mobile: false }), STEP_TIMEOUT_MS, "Setting the page scale");
|
|
74
|
+
const steps = captionSteps(params.frames);
|
|
75
|
+
fs.mkdirSync(params.outDir, { recursive: true });
|
|
76
|
+
for (const [index, frame] of params.frames.entries()) {
|
|
77
|
+
const image = fs.readFileSync(path.join(params.filmDir, frame.file)).toString("base64");
|
|
78
|
+
const step = steps[index] ?? null;
|
|
79
|
+
await win.setContent(buildPhonePage({ imageDataUrl: `data:image/png;base64,${image}`, captions: params.captions, step, layout: params.layout }), {
|
|
80
|
+
timeout: STEP_TIMEOUT_MS,
|
|
81
|
+
});
|
|
82
|
+
await withTimeout(win.evaluate("Promise.all([...document.images].map((image) => image.decode())).then(() => document.fonts.ready).then(() => undefined)"), STEP_TIMEOUT_MS, `Loading ${frame.file}`);
|
|
83
|
+
const shot = await withTimeout(cdp.send("Page.captureScreenshot", { format: "png" }), STEP_TIMEOUT_MS, `Taking the screenshot of ${frame.file}`);
|
|
84
|
+
const png = Buffer.from(shot.data, "base64");
|
|
85
|
+
const size = readPngSize(png);
|
|
86
|
+
if (size.width !== PAGE_WIDTH * PAGE_SCALE || size.height !== PAGE_HEIGHT * PAGE_SCALE) {
|
|
87
|
+
throw new Error(`the composed frame ${frame.file} is ${String(size.width)} x ${String(size.height)} px, expected ${String(PAGE_WIDTH * PAGE_SCALE)} x ${String(PAGE_HEIGHT * PAGE_SCALE)}. ` +
|
|
88
|
+
`Electron did not apply the 2x device scale.`);
|
|
89
|
+
}
|
|
90
|
+
fs.writeFileSync(path.join(params.outDir, frame.file), png);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
await app.close();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
fs.rmSync(workDir, { recursive: true, force: true });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** The binary of the plugin's own `electron` devDependency, the one its e2e tests run on. */
|
|
102
|
+
function resolveElectron(cwd) {
|
|
103
|
+
try {
|
|
104
|
+
assertElectronInstalled(cwd, createElectronProbe());
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
throw new Error(`layout "phone-captions" renders its frames in Electron, from the plugin's own "electron" devDependency. ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
108
|
+
}
|
|
109
|
+
const resolved = createRequire(path.join(cwd, "noop.js"))("electron");
|
|
110
|
+
if (typeof resolved !== "string") {
|
|
111
|
+
throw new Error(`The "electron" package in ${cwd} did not export the path of its binary. Reinstall it: npm install --save-dev electron.`);
|
|
112
|
+
}
|
|
113
|
+
return resolved;
|
|
114
|
+
}
|
|
115
|
+
async function loadPlaywright() {
|
|
116
|
+
try {
|
|
117
|
+
const { _electron } = await import("@playwright/test");
|
|
118
|
+
return { _electron };
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
throw new Error(`layout "phone-captions" drives Electron through Playwright, and "@playwright/test" cannot be loaded: ${error instanceof Error ? error.message : String(error)}. ` +
|
|
122
|
+
`Install it: npm install --save-dev @playwright/test.`, { cause: error });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** The record of media `opdk demo` wrote, in the demo output folder (`demo.outDir`). */
|
|
2
|
+
export declare const PUBLISHED_FILE = "published.json";
|
|
3
|
+
/** Output path (relative to the project, with `/`) to the name of the film it was encoded from. */
|
|
4
|
+
export type PublishedRecord = Readonly<Record<string, string>>;
|
|
5
|
+
/** Parses the record's text; throws a message that says what is wrong with it. */
|
|
6
|
+
export declare function parsePublished(text: string): PublishedRecord;
|
|
7
|
+
export declare function serializePublished(record: PublishedRecord): string;
|
|
8
|
+
/**
|
|
9
|
+
* The record after a run: entries whose file is gone from disk are dropped (the owner deleted an obsolete file, so it
|
|
10
|
+
* must not be named again), and the files this run wrote are added or re-pointed at their film.
|
|
11
|
+
*/
|
|
12
|
+
export declare function updatePublished(previous: PublishedRecord, written: PublishedRecord, exists: (file: string) => boolean): PublishedRecord;
|
|
13
|
+
export declare function sameRecord(a: PublishedRecord, b: PublishedRecord): boolean;
|
|
14
|
+
/** Reads the record; a missing file is an empty record (the kit has published nothing yet), anything else wrong throws. */
|
|
15
|
+
export declare function readPublished(outDir: string): PublishedRecord;
|
|
16
|
+
export declare function writePublished(outDir: string, record: PublishedRecord): void;
|