Skip to content

Conversation

@ahnafnafee
Copy link
Owner

@ahnafnafee ahnafnafee commented Dec 24, 2025

Experimental: Zero-Config Internal Rendering (WASM + SVG)

Summary

This draft PR introduces a major architectural shift to make the extension "Zero Config". It eliminates the requirement for users to manually install Ghostscript and Poppler by bundling a WebAssembly (WASM) version of Ghostscript and using pdf.js for client-side rendering.

Key Changes

  • Internal Rendering: Replaced child_process calls to system binaries (ps2pdf, pdftocairo) with @jspawn/ghostscript-wasm.
  • SVG-Based Preview: Switched from Canvas rendering to SVG rendering using pdf.js SVGGraphics.
  • Enhanced Zoom/Pan: Integrated svg-pan-zoom for infinite, crisp vector zooming without pixelation.
  • Scoped Backgrounds: Background color picker now applies only to the document "paper", preserving transparency logic.
  • Configuration Removal: Removed all postscript-preview.path.* settings as they are no longer needed.
  • Async Refactoring: Simplified extension.ts command handlers to avoid potential Marketplace flagging for long-running async activations.

Benefits

  • Truly Zero Config: Users just install and run. No more "Ghostscript not found" errors.
  • Consistent Rendering: Using a bundled engine ensuring identical output across Windows, macOS, and Linux.
  • Better UX: Vector-based zoom allows for inspecting fine details in PostScript drawings.

Concerns & Open Questions

1. Extension Size (Critical)

The VSIX package size has increased from ~200KB to ~30MB.

  • Cause: This is primarily due to bundling the ghostscript.wasm binary and its snapshot.
  • Impact: Longer download/install times.
  • Potential Solution: Implementing a "Download on Demand" strategy where the binary is fetched from a CDN on the first run, keeping the core extension small.

2. Startup Performance

Initializing the WASM environment might incur a slight startup penalty compared to spawning a native process, though subsequent operations should be fast.

3. Licensing

ghostscript-wasm is AGPL-licensed. While the extension logic is MIT, bundling AGPL components may have implications for distribution.

Testing

  • Tested on Windows with various .ps and .eps files.
  • Verified special characters in filenames are handled correctly.
  • Confirmed svg-pan-zoom works with valid viewBox scaling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants