jacobinwwey_obsidian-NotEMD/scripts/lib/esbuild-bundle-config.js
Jacobinwwey eb777ef93e fix(slide-export): cross-page mermaid/heading integrity, MP4 order+clarity, Windows probe
Slide export improvements across all 6 formats (HTML standalone, HTML
server-script, PDF, PNG, PPTX, MP4):

Cross-page split integrity:
- isTopLevelListItem now anchors to column 0 only, so indented nested
  children (e.g. - Responsibility: under - Module:) stay attached to
  their parent block instead of being orphaned as top-level items on the
  next slide. Regression test added.

PDF/PNG Mermaid blank pages:
- Slidev one-piece export only waits on one shared #mermaid-rendering-container,
  so late Mermaid blocks capture blank. Append --per-slide to PDF/PNG CLI
  invocations so each slide gets its own Mermaid container-wait cycle.
  Keep --wait-until networkidle --wait 3000 as belt-and-suspenders.
  PDF p3 content went 0.00% -> 2.64%.

MP4 slide ordering:
- Replace shell glob (*.png, lexicographic: 1,10,11,...,2) with a
  numerically-sorted concat-demuxer list fed to ffmpeg with explicit
  per-frame durations. Slides encode in deck order regardless of
  zero-padding width or --with-clicks suffix.

Image clarity setting (>=300 ppi default):
- Add slideExportImageClarity setting (standard/high/ultra, default ultra
  = scale 3 ~432 ppi) wired into Slidev --scale on PNG export; MP4
  inherits via PNG sequence. Settings UI dropdown in EN + ZH.
- Add -vf pad=ceil(iw/2)*2:ceil(ih/2)*2 to ffmpeg args so libx264/yuv420p
  encodes odd-height frames (scale 3 -> 2940x1653 -> 1654 padded).

Windows spawn EINVAL on environment probe:
- execFileAsync sets shell:true + windowsHide:true on win32 only so Node
  resolves PATHEXT for .cmd/.bat/.exe shims (npx.cmd, slidev.cmd, ffmpeg).
  macOS/Linux keep direct exec (shell:false), unchanged.
- resolvePlaywrightBrowsersPath covers AppData/Roaming/ms-playwright and
  PLAYWRIGHT_BROWSERS_PATH env var.

Mermaid pre-fit in standalone HTML:
- Inject mermaidPostFitScript into standalone HTML via main.ts export path.
- Add mermaidFitScript.ts, mermaidPostFitScript.txt, assets.d.ts.
- esbuild .txt loader, jest txt transform.

Tests: 1557 pass (1 pre-existing mainlineProgressAuditContract GEO drift
unrelated). tsc clean. Built main.js verified in live Obsidian.
2026-07-01 10:26:57 -05:00

91 lines
2 KiB
JavaScript

const builtins = require('builtin-modules');
const {
MAIN_BUNDLE_OUTPUT_FILE,
RENDER_HOST_RUNTIME_OUTPUT_FILE
} = require('./packaging-contract.js');
const BUNDLE_BANNER =
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;
const SHARED_EXTERNAL = [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/search',
'@codemirror/state',
'@codemirror/view',
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
...builtins
];
function resolveSourceMap(prod) {
return prod ? false : 'inline';
}
function createMainBundleBuildOptions({
prod = false,
metafile = false,
write = true,
logLevel = 'info'
} = {}) {
return {
banner: {
js: BUNDLE_BANNER
},
entryPoints: ['src/main.ts'],
bundle: true,
external: SHARED_EXTERNAL,
loader: { '.txt': 'text' },
format: 'cjs',
target: 'es2018',
logLevel,
sourcemap: resolveSourceMap(prod),
treeShaking: true,
outfile: MAIN_BUNDLE_OUTPUT_FILE,
minify: prod,
metafile,
write
};
}
function createRenderHostBundleBuildOptions({
prod = false,
metafile = false,
write = true,
logLevel = 'info'
} = {}) {
return {
banner: {
js: BUNDLE_BANNER
},
entryPoints: ['src/rendering/runtime/renderHostEntry.ts'],
bundle: true,
format: 'esm',
target: 'es2020',
logLevel,
sourcemap: resolveSourceMap(prod),
treeShaking: true,
outfile: RENDER_HOST_RUNTIME_OUTPUT_FILE,
minify: prod,
platform: 'browser',
metafile,
write
};
}
module.exports = {
BUNDLE_BANNER,
SHARED_EXTERNAL,
createMainBundleBuildOptions,
createRenderHostBundleBuildOptions
};