From 2ebb259d7fc838b09e34b7db49efd68a21801540 Mon Sep 17 00:00:00 2001 From: Sithel Date: Thu, 2 Jan 2025 21:51:26 -0800 Subject: [PATCH] workin' on stuff --- README.md | 55 +++++++++++++++++++++++++++++++++++- index.html | 65 ++++++++++++++++++++++++++++++++++--------- js/main.js | 3 ++ js/state_modifiers.js | 30 ++++++++++++++++++++ 4 files changed, 139 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index aa604f0..a844b94 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,71 @@ # vip Villainous Imposer Program +Targeting launch early February 2025 + +# TODOs + +There's a lot of features and a lot of work remaining-- + +### Functionality + +- all of PDF page placement + - handling both flip options + - rotation/padding/margin logic +- file downloading (all options) +- all of mark-up + - PDF boundary spine marks + - spine order marks + - punching guidelines/marks (spine/interior) + - cut / fold lines + - corner cross-hairs +- preview + +### UI/UX: + +- enable/disable sections based on entered values +- saving settings/URL params +- correctly re-rendering values when changing Display Units +- PDF placement preview +- debug info / error states / progress bars +- folding information / animations for impositions +- disable outer/bottom for PDF Placement if `Original` scaling +- warn in PDF Placement if known exceeding of bounds (and by how much) +- dynamic button name change for Download from `get that file!` to `get those files!` + +### Stretch/Long Term + +- creep +- PDF skew correction +- page numbers in the margins +- night mode +- more impositions +- improve Imposition options UI/UX to be more compact (in listing options section) + # Helper Functions & Code Structure +## Source PDFs + +Processed in `vip.processUploads`, offloads most the work to `pdf.js`'s `processUploadBlocks` (which calls helper functions within that file). Tucks all results in `window.book.upload_blocks`, each entry containing a `_pagesList` array (`-1` means blank!) and `pdfDoc` (`PDFLib.PDFDocument`) + + ## `unified_source` (steps 1 & 2) Needs `unified_source_modifier.attach()` to be called first to hook everything up (see `state_modifiers.js`). Call `window.book.unified_source.processUpdate()` after base changes to re-calculate things. Things like: +- `window.book.unified_source.hasValidPdf()` : returns a boolean - `window.book.unified_source.maxWidth` / `window.book.unified_source.maxHeight` : raw PDF height (post step 1) - `window.book.unified_source.isTurned()` : returns true if it's -90 or 90 degree rotation (post step 2) - `window.book.unified_source.pdf_w` / `window.book.unified_source.pdf_h` : takes into account PDF margins and rotation. (post step 2) +- `window.book.unified_source.pageCount` : calculated total pages across multiple PDFs and accounting for blanks +- `window.book.unified_source.getPdfPageForPageNumber(pageNum)` : given page `N` in the result PDF, looks up in the `window.book.upload_blocks` to fetch the corresponding `PDFLib.PDFPage` ## Physical (step 3) - `window.book.physical.display_unit` : either `metric`, `imperial`, or `points` -- `window.book.physical.paper_size` : a 2 value list of the sheet's `[width, height]` in points \ No newline at end of file +- `window.book.physical.paper_size` : a 2 value list of the sheet's `[width, height]` in points + +## Download (step 9) + +Check out `files.js` \ No newline at end of file diff --git a/index.html b/index.html index 136ee9b..e0a4a20 100644 --- a/index.html +++ b/index.html @@ -52,6 +52,10 @@ /*--pico-line-height: 0.5rem;*/ --pico-form-element-spacing-vertical: 0rem; } + .disabled { + opacity: 0.5; + pointer-events: none; + } details summary::after { float: left; } @@ -235,7 +239,12 @@ #paper_size_options { width: 20em; } - input { + #paper_margin_short, #paper_margin_long { + width: 4em; + padding: 2px; + margin-top: 0.75em; + } + #paper_size { width: 10em; } fieldset { @@ -284,8 +293,10 @@ margin-bottom: 50px; } #pdf_download { - input { + div { margin-left: 40px; + } + #file_download_name { width:auto; } } @@ -369,7 +380,7 @@

1. Source PDF(s)

-
+

2. PDF Manipulation

Explanation @@ -435,7 +446,9 @@

3. Printer Paper

Instructions/Details

- Omg as if I knew... + This has to do with your machine and the paper you're feeding into it.

+ + The paper margins are to add white space on the edges of the printed page in case you do not have a full-bleed printer. They are mirrored on either side - so a 10 pt margin on the Long Sides will put a 10 pt on both sides for a total of 20 pt

@@ -455,11 +468,21 @@

3. Printer Paper

cm
- Margin Short Sides + Flip Paper +                   + +                     + +
+ Paper Margins +           short sides cm -
- Margin Long Sides +       long sides cm
@@ -511,7 +534,7 @@

3. Printer Paper

-
+

5. PDF Placement

Instructions/Details @@ -521,10 +544,10 @@

5. PDF Placement

Only the top and inner margins are considered. Positive values shift it down/away from the spine. Negative values shift it up/towards the spine.
Fit - Proportional
Maintains the original PDF aspect ratio, scaled down to fit into the space provided
- Positive padding numbers push the PDF inward, makes it smaller. Negative padding pulls it out, making it larger. A padding of N on one side and -N on the other side of the PDf is the same as translating/shifting it. The PDF will scale such that it's small enough to honor the tightest constraints (ex: inner/outer margins that squeeze the PDF will override top/bottom margins that expand the PDF)
+ Positive padding numbers push the PDF inward, makes it smaller. Negative padding pulls it out, making it larger. A padding of N on one side and -N on the other side of the PDF is the same as translating/shifting it. The PDF will scale such that it's small enough to honor the tightest constraints (ex: inner/outer margins that squeeze the PDF will override top/bottom margins that expand the PDF)
Fill - Stretch
Distors the PDF's aspect ratio, stretching it in both directions to fill the entire space allowed
- Positive padding numbers push the PDF inward, makes it smaller. Negative padding pulls it out, making it larger. A padding of N on one side and -N on the other side of the PDf is the same as translating/shifting it. + Positive padding numbers push the PDF inward, makes it smaller. Negative padding pulls it out, making it larger. A padding of N on one side and -N on the other side of the PDF is the same as translating/shifting it.

@@ -582,7 +605,7 @@

7. Post-Processing

Not Yet Implemented
-
+

8. Preview

Instructions/Details @@ -595,8 +618,24 @@

8. Preview

9 Download

- .pdf      - +
+ Download: + + + +
+ .pdf      + +
diff --git a/js/main.js b/js/main.js index dcd2377..e4e3f43 100644 --- a/js/main.js +++ b/js/main.js @@ -30,6 +30,9 @@ export const vip = { detailsEl.removeAttribute("style") detailsEl.setAttribute("open", "") console.log("=== Processing Uploads Complete ") + if (window.book.unified_source.hasValidPdf()) { + document.getElementById("page_manipulation").setAttribute("class","") + } window.book.unified_source.processUpdate() } utils.processUploadBlocks(callback); diff --git a/js/state_modifiers.js b/js/state_modifiers.js index 8a6b816..af00a13 100644 --- a/js/state_modifiers.js +++ b/js/state_modifiers.js @@ -34,11 +34,41 @@ export const unified_source_modifier = { _hookUpMinorHelpers: function() { window.book.unified_source.pdfHeight = function() { return } }, + _hasValidPdf: function() { + return this.pdf != undefined && this.pdf.getPageCount() > 0 + }, + _getPdfPageForPageNumber: function shark(pageNum) { + const isNumber = function(value) { + return typeof value === "number" && isFinite(value); + } + const lookForPage = function(acc, curBlock) { + if (!isNumber(acc)) { + return acc + } + const targetPageNum = pageNum - acc + if (targetPageNum < curBlock._pagesList.length) { + const pageListEntry = curBlock._pagesList[targetPageNum][0] + if (pageListEntry == -1) { + const page = curBlock.pdfDoc.getPage(targetPageNum) + return "b" + } + const page = curBlock.pdfDoc.getPage(pageListEntry) + return page + } else { + return acc + curBlock._pagesList.length + } + } + return window.book.upload_blocks + .filter(x => x.pdfDoc != null) + .reduce(lookForPage, 0) + }, attach : function() { window.book.unified_source.isTurned = this._isTurned window.book.unified_source.updatePdfPlacementInfo = this._updatePdfPlacementInfo window.book.unified_source.calcPdfPlacementRenderInfo = this._calcPdfPlacementRenderInfo window.book.unified_source.calcRotationPreviewRenderInfo = this._calcRotationPreviewRenderInfo + window.book.unified_source.hasValidPdf = this._hasValidPdf + window.book.unified_source.getPdfPageForPageNumber = this._getPdfPageForPageNumber this._hookUpMinorHelpers() window.book.unified_source.processUpdate = function() { if (window.book.unified_source.maxHeight == undefined || window.book.unified_source.maxHeight == undefined) {