2024‐01‐03 Code Walkthrough - momijizukamori/bookbinder-js GitHub Wiki

Working from SHA d18bb7c9a29e8e48dac86c99f03a43370a71ab95

pre-notes:

The Code

The page renders!

  • main.js has a DOMContentLoaded listener. It hooks up the change listeners

The user does something!

  • changeHandlers.js has some of the change handlers. They primarily call updateForm(book)
  • formUtils.js calls the book's createpages() and then updates the UI, calling several render functions (which live in renderUtils.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/modified this.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 the renderUtils.js for the preview spacing box

A user clicks the Generate button

  • createoutputfiles() is called

    • things start diverging here between classic and wacky
    • calls calculate_dimensions and passes it down as dim for future use
    • passes down calculatelayout as well
  • live notes

  • gotta embed the page into the PDFDocument and then draw the page on the PDFPage

  • 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. see signatures.js (double check that)