$ account eKoopmans
html2pdf.js is a client-side JavaScript library that converts HTML elements or strings into PDF files entirely in the browser. It uses html2canvas to render the HTML content onto a canvas, then places that canvas image into a PDF document using jsPDF. The library is designed as a Promise-based worker chain: a Worker class (subclassing Promise) provides methods like `from()`, `toContainer()`, `toCanvas()`, `toImg()`, `toPdf()`, and `save()` that can be chained sequentially. Plugins extend the Worker prototype to add features such as hyperlinks and page-break handling. The main entry point is the `html2pdf` function exported from `src/index.js`, which creates a Worker and optionally starts the conversion chain. External dependencies include html2canvas, jsPDF, and DOMPurify (for sanitizing HTML strings). The library is intended for browser use only and does not run in Node.js. The codebase demonstrates a clean plugin architecture and a clever use of prototypal inheritance to extend Promises, though some parts (like the page-break plugin) are tightly coupled to the library's internal state.