2024‐01‐03 Code Walkthrough - momijizukamori/bookbinder-js GitHub Wiki
Working from SHA d18bb7c9a29e8e48dac86c99f03a43370a71ab95
pre-notes:
- Backing PDF manipulation library : https://pdf-lib.js.org/
The Code
The page renders!
main.js
has aDOMContentLoaded
listener. It hooks up the change listeners
The user does something!
changeHandlers.js
has some of the change handlers. They primarily callupdateForm(book)
formUtils.js
calls thebook
'screatepages()
and then updates the UI, calling several render functions (which live inrenderUtils.js
)
The magic of book.js
✨
createpages()
is basically top of the funnel.- manipulates a lot of
book
member variables along the way and then references them all over as it works it's way through sub function calls. - handles converting things from the uploaded PDF (
this.currentdoc
) into the appropriately rotated/modifiedthis.managedDoc
(which should be the source of all downstream PDFs) - applies the Source Manipulation section
- instantiates and sets the appropriate
this.book
object based on layout/imposition - calls
updatePageLayoutInfo
in therenderUtils.js
for the preview spacing box
- manipulates a lot of
A user clicks the Generate button
-
createoutputfiles()
is called- things start diverging here between classic and wacky
- calls
calculate_dimensions
and passes it down asdim
for future use - passes down
calculatelayout
as well
-
live notes
-
gotta embed the page into the
PDFDocument
and then draw the page on thePDFPage
-
transparent line on a page because you can't add a page w/o content -- the library errors!
-
good intro ticket, remove 3rd
BOOKLET_LAYOUTS
param and just reverse the 2nd. seesignatures.js
(double check that)