From 400f362841ed7482c5afc05efc3a2446888f5285 Mon Sep 17 00:00:00 2001 From: krflol Date: Sat, 31 Oct 2026 03:35:41 -0500 Subject: [PATCH] Fix pagination in browser starter invoices --- .github/workflows/browser-starter.yml | 6 +- .github/workflows/react-starter.yml | 6 +- .github/workflows/vue-starter.yml | 6 +- examples/browser/README.md | 13 ++ examples/browser/src/invoice.css | 28 +++- examples/browser/src/invoice.html | 4 +- examples/react/README.md | 13 ++ examples/react/src/invoice.css | 28 +++- examples/react/src/invoice.html | 4 +- examples/vue/README.md | 13 ++ examples/vue/src/invoice.css | 28 +++- examples/vue/src/invoice.html | 4 +- tools/check-starter-invoices.py | 182 ++++++++++++++++++++++++++ tools/starter_invoice.py | 83 ++++++++++++ 14 files changed, 388 insertions(+), 30 deletions(-) create mode 100644 tools/check-starter-invoices.py create mode 100644 tools/starter_invoice.py diff --git a/.github/workflows/browser-starter.yml b/.github/workflows/browser-starter.yml index 533997e..3b5102b 100644 --- a/.github/workflows/browser-starter.yml +++ b/.github/workflows/browser-starter.yml @@ -3,9 +3,9 @@ name: Browser starter on: push: branches: [main] - paths: ['examples/browser/**', 'tools/check-browser-starter.py', 'tools/browser-requirements.txt', 'tools/starter_standard_fonts.py', 'tools/starter_engine_fixes.py', 'tools/starter-engine-2.5.22.json', 'tools/starter-engine-2.5.24.json', 'tools/starter-engine-2.5.38.json', '.github/workflows/browser-starter.yml'] + paths: ['examples/browser/**', 'tools/check-browser-starter.py', 'tools/check-starter-invoices.py', 'tools/starter_invoice.py', 'tools/browser-requirements.txt', 'tools/starter_standard_fonts.py', 'tools/starter_engine_fixes.py', 'tools/starter-engine-2.5.22.json', 'tools/starter-engine-2.5.24.json', 'tools/starter-engine-2.5.38.json', '.github/workflows/browser-starter.yml'] pull_request: - paths: ['examples/browser/**', 'tools/check-browser-starter.py', 'tools/browser-requirements.txt', 'tools/starter_standard_fonts.py', 'tools/starter_engine_fixes.py', 'tools/starter-engine-2.5.22.json', 'tools/starter-engine-2.5.24.json', 'tools/starter-engine-2.5.38.json', '.github/workflows/browser-starter.yml'] + paths: ['examples/browser/**', 'tools/check-browser-starter.py', 'tools/check-starter-invoices.py', 'tools/starter_invoice.py', 'tools/browser-requirements.txt', 'tools/starter_standard_fonts.py', 'tools/starter_engine_fixes.py', 'tools/starter-engine-2.5.22.json', 'tools/starter-engine-2.5.24.json', 'tools/starter-engine-2.5.38.json', '.github/workflows/browser-starter.yml'] workflow_dispatch: permissions: @@ -38,6 +38,8 @@ jobs: - run: python -m pip install -r tools/browser-requirements.txt - run: python -m playwright install --with-deps ${{ matrix.browser }} - run: python tools/check-browser-starter.py --dist examples/browser/dist --out output/starter-${{ matrix.browser }} --browser ${{ matrix.browser }} + - name: Verify flowing invoice downloads and every page preview + run: python tools/check-starter-invoices.py --kind browser --dist examples/browser/dist --templates examples/browser/src --out output/starter-${{ matrix.browser }}/invoices --browser ${{ matrix.browser }} - uses: actions/upload-artifact@v4 if: always() with: diff --git a/.github/workflows/react-starter.yml b/.github/workflows/react-starter.yml index 2fff3ee..4123070 100644 --- a/.github/workflows/react-starter.yml +++ b/.github/workflows/react-starter.yml @@ -3,9 +3,9 @@ name: React starter on: push: branches: [main] - paths: ['examples/react/**', 'tools/check-react-starter.py', 'tools/check-react-development.py', 'tools/prepare-react-check.mjs', 'tools/react_component_checks.py', 'tools/browser-requirements.txt', 'tools/starter_standard_fonts.py', 'tools/starter_engine_fixes.py', 'tools/starter-engine-2.5.22.json', 'tools/starter-engine-2.5.24.json', 'tools/starter-engine-2.5.38.json', '.github/workflows/react-starter.yml'] + paths: ['examples/react/**', 'tools/check-react-starter.py', 'tools/check-starter-invoices.py', 'tools/starter_invoice.py', 'tools/check-react-development.py', 'tools/prepare-react-check.mjs', 'tools/react_component_checks.py', 'tools/browser-requirements.txt', 'tools/starter_standard_fonts.py', 'tools/starter_engine_fixes.py', 'tools/starter-engine-2.5.22.json', 'tools/starter-engine-2.5.24.json', 'tools/starter-engine-2.5.38.json', '.github/workflows/react-starter.yml'] pull_request: - paths: ['examples/react/**', 'tools/check-react-starter.py', 'tools/check-react-development.py', 'tools/prepare-react-check.mjs', 'tools/react_component_checks.py', 'tools/browser-requirements.txt', 'tools/starter_standard_fonts.py', 'tools/starter_engine_fixes.py', 'tools/starter-engine-2.5.22.json', 'tools/starter-engine-2.5.24.json', 'tools/starter-engine-2.5.38.json', '.github/workflows/react-starter.yml'] + paths: ['examples/react/**', 'tools/check-react-starter.py', 'tools/check-starter-invoices.py', 'tools/starter_invoice.py', 'tools/check-react-development.py', 'tools/prepare-react-check.mjs', 'tools/react_component_checks.py', 'tools/browser-requirements.txt', 'tools/starter_standard_fonts.py', 'tools/starter_engine_fixes.py', 'tools/starter-engine-2.5.22.json', 'tools/starter-engine-2.5.24.json', 'tools/starter-engine-2.5.38.json', '.github/workflows/react-starter.yml'] workflow_dispatch: permissions: @@ -39,6 +39,8 @@ jobs: - run: python -m pip install -r tools/browser-requirements.txt - run: python -m playwright install --with-deps ${{ matrix.browser }} - run: python tools/check-react-starter.py --dist examples/react/dist --out output/react-${{ matrix.browser }} --browser ${{ matrix.browser }} + - name: Verify flowing invoice downloads and every page preview + run: python tools/check-starter-invoices.py --kind react --dist examples/react/dist --templates examples/react/src --out output/react-${{ matrix.browser }}/invoices --browser ${{ matrix.browser }} - name: Build React development runtime with StrictMode if: matrix.browser == 'chrome' env: diff --git a/.github/workflows/vue-starter.yml b/.github/workflows/vue-starter.yml index 960276b..e42288f 100644 --- a/.github/workflows/vue-starter.yml +++ b/.github/workflows/vue-starter.yml @@ -3,9 +3,9 @@ name: Vue starter on: push: branches: [main] - paths: ['examples/vue/**', 'tools/check-vue-starter.py', 'tools/prepare-vue-check.mjs', 'tools/browser-requirements.txt', 'tools/starter_standard_fonts.py', 'tools/starter_engine_fixes.py', 'tools/starter-engine-2.5.22.json', 'tools/starter-engine-2.5.24.json', 'tools/starter-engine-2.5.38.json', '.github/workflows/vue-starter.yml'] + paths: ['examples/vue/**', 'tools/check-vue-starter.py', 'tools/check-starter-invoices.py', 'tools/starter_invoice.py', 'tools/prepare-vue-check.mjs', 'tools/browser-requirements.txt', 'tools/starter_standard_fonts.py', 'tools/starter_engine_fixes.py', 'tools/starter-engine-2.5.22.json', 'tools/starter-engine-2.5.24.json', 'tools/starter-engine-2.5.38.json', '.github/workflows/vue-starter.yml'] pull_request: - paths: ['examples/vue/**', 'tools/check-vue-starter.py', 'tools/prepare-vue-check.mjs', 'tools/browser-requirements.txt', 'tools/starter_standard_fonts.py', 'tools/starter_engine_fixes.py', 'tools/starter-engine-2.5.22.json', 'tools/starter-engine-2.5.24.json', 'tools/starter-engine-2.5.38.json', '.github/workflows/vue-starter.yml'] + paths: ['examples/vue/**', 'tools/check-vue-starter.py', 'tools/check-starter-invoices.py', 'tools/starter_invoice.py', 'tools/prepare-vue-check.mjs', 'tools/browser-requirements.txt', 'tools/starter_standard_fonts.py', 'tools/starter_engine_fixes.py', 'tools/starter-engine-2.5.22.json', 'tools/starter-engine-2.5.24.json', 'tools/starter-engine-2.5.38.json', '.github/workflows/vue-starter.yml'] workflow_dispatch: permissions: @@ -39,6 +39,8 @@ jobs: - run: python -m pip install -r tools/browser-requirements.txt - run: python -m playwright install --with-deps ${{ matrix.browser }} - run: python tools/check-vue-starter.py --dist examples/vue/dist --out output/vue-${{ matrix.browser }} --browser ${{ matrix.browser }} + - name: Verify flowing invoice downloads and every page preview + run: python tools/check-starter-invoices.py --kind vue --dist examples/vue/dist --templates examples/vue/src --out output/vue-${{ matrix.browser }}/invoices --browser ${{ matrix.browser }} - uses: actions/upload-artifact@v4 if: always() with: diff --git a/examples/browser/README.md b/examples/browser/README.md index 2acf2e7..8f706c3 100644 --- a/examples/browser/README.md +++ b/examples/browser/README.md @@ -40,6 +40,19 @@ Use [supported Fullbleed print CSS](https://docs.fullbleed.dev/css-coverage/). Document scripts do not run. Supply custom image/font bytes through the SDK's `assets` and `fonts` options; document URLs do not trigger browser fetches. +## Let an HTML invoice grow + +Add or remove rows inside `src/invoice.html`'s `` and update both sample +totals. The HTML sample does not calculate amounts. Its stylesheet lets the table +continue onto new pages, repeats column headings, and prints `Page N of M` in the +page margin. The `.closing` group keeps totals and payment details together; it +can move to the next page when there is not enough room. + +Keep the flowing `@page` margins and automatic `.page` height when adapting this +layout. The invoice check covers the short sample, 24 rows, wrapped descriptions, +empty rows and page-boundary cases, including final PDF text bounds and every +displayed preview. + ## Build and deploy ```sh diff --git a/examples/browser/src/invoice.css b/examples/browser/src/invoice.css index 0c83bd8..14142f7 100644 --- a/examples/browser/src/invoice.css +++ b/examples/browser/src/invoice.css @@ -1,11 +1,20 @@ -@page { size: A4; margin: 0; } +@page { + size: A4; margin: 15mm 16mm 20mm; background: #f8f5ec; + @bottom-left { + content: "NORTHSTAR STUDIO / FICTIONAL INVOICE"; + font-family: Inter; font-size: 6.6pt; color: {{ink}}; + } + @bottom-right { + content: "Page " counter(page) " of " counter(pages); + font-family: Inter; font-size: 6.6pt; color: {{ink}}; + } +} * { box-sizing: border-box; } -html, body { margin: 0; padding: 0; } +html, body { margin: 0; padding: 0; background: #f8f5ec; } body { font-family: Inter; font-size: 10pt; line-height: 1.45; color: {{ink}}; } h1, h2, h3, p, figure { margin: 0; } h1, h2, h3 { font-weight: 400; } -.page { width: 210mm; height: 296.9mm; padding: 15mm 16mm; position: relative; break-after: page; background: #f8f5ec; } -.page:last-child { break-after: auto; } +.page { width: auto; height: auto; } .kicker { font-size: 7.2pt; font-weight: 600; letter-spacing: 1.4pt; text-transform: uppercase; } .serif { font-family: 'DM Serif Display'; font-weight: 400; } .display { font-family: 'Bebas Neue'; font-weight: 400; } @@ -16,7 +25,6 @@ h1, h2, h3 { font-weight: 400; } .grid-2 { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 24pt; } .grid-2 > * { min-width: 0; } .grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16pt; } -.footer { position: absolute; left: 16mm; right: 16mm; bottom: 12mm; border-top: .6pt solid #9eafa4; padding-top: 8pt; display: flex; justify-content: space-between; gap: 12pt; font-size: 6.6pt; letter-spacing: .45pt; } table { width: 100%; border-collapse: collapse; font-size: 9pt; } th { font-size: 7.5pt; font-weight: 600; text-align: left; } th, td { padding: 10pt 0; border-bottom: .55pt solid #bdc8bf; vertical-align: top; } @@ -37,12 +45,18 @@ a { color: inherit; } .invoice .details { border-top: .6pt solid #9eafa4; border-bottom: .6pt solid #9eafa4; padding: 15pt 0; margin-bottom: 10pt; } .invoice .details p { margin-top: 5pt; font-size: 8.2pt; } .invoice .details > div + div { border-left: .6pt solid #c7cdc4; padding-left: 14pt; } +.invoice table { table-layout: fixed; } .invoice th { color: #52665a; } +.invoice th:first-child { width: 56%; } +.invoice th:not(:first-child) { width: 14.666%; } +.invoice tr { break-inside: avoid; } .invoice td { padding: 12pt 0; } +.invoice td:first-child { overflow-wrap: anywhere; } .invoice .item-note { color: #617069; font-size: 8pt; margin-top: 4pt; } -.invoice .amounts { display: grid; grid-template-columns: 1fr 1.25fr; gap: 27pt; margin-top: 23pt; } +.invoice .closing { break-inside: avoid; } +.invoice .amounts { display: grid; grid-template-columns: 1fr 1.25fr; gap: 27pt; margin-top: 23pt; break-inside: avoid; } .invoice .thanks { font: italic 22pt/1.2 'DM Serif Display'; color: #b44123; padding-top: 8pt; } .invoice .summary-line { display: flex; justify-content: space-between; padding: 5pt 0; font-size: 8.5pt; } .invoice .total { background: {{ink}}; color: #fff8e8; padding: 16pt; margin-top: 9pt; border-left: 4pt solid #d96238; } .invoice .total .value { font: 38pt/1.1 'Bebas Neue'; margin-top: 7pt; } -.invoice .payment { margin-top: 20pt; padding-top: 12pt; border-top: .6pt solid #9eafa4; display: grid; grid-template-columns: 1fr 1fr; gap: 24pt; font-size: 8pt; } +.invoice .payment { margin-top: 16pt; padding-top: 12pt; border-top: .6pt solid #9eafa4; display: grid; grid-template-columns: 1fr 1fr; gap: 24pt; font-size: 8pt; break-inside: avoid; } diff --git a/examples/browser/src/invoice.html b/examples/browser/src/invoice.html index 4d49034..b923b3b 100644 --- a/examples/browser/src/invoice.html +++ b/examples/browser/src/invoice.html @@ -6,7 +6,9 @@
DESCRIPTIONHOURSRATEAMOUNT
Discovery & brand workshop

Positioning, priorities, and a clear creative direction

8$125.00$1,000.00
Digital design & implementation

A cohesive visual system, from layout to launch

6$95.00$570.00
Review & studio handoff

Final refinements, documentation, and delivery

2$150.00$300.00
+

A little clarity.
A lot of possibility.

Thank you for inviting us
to help shape your next chapter.

Subtotal$1,870.00
Tax · 0% in this sample$0.00
TOTAL DUE · USD
$1,870.00

Payment details

Reference {{reference}} with your payment.
Payment instructions are supplied separately.

A note from the studio

Questions about a line item?
Write to hello@example.invalid.

-
NORTHSTAR STUDIO / INVOICE {{reference}}FICTIONAL SAMPLE · 01 / 01
+ +
diff --git a/examples/react/README.md b/examples/react/README.md index a5d1ecd..7c4b25b 100644 --- a/examples/react/README.md +++ b/examples/react/README.md @@ -102,6 +102,19 @@ termination does not provide a native thread-exit promise. The [browser SDK guide](https://github.com/fullbleed-engine/fullbleed-node/blob/main/docs/browser.md) covers limits, custom font/image bytes, hosting policy, and structured errors. +## Let an HTML invoice grow + +Add or remove rows inside `src/invoice.html`'s `` and update both sample +totals. The HTML sample does not calculate amounts. Its stylesheet lets the table +continue onto new pages, repeats column headings, and prints `Page N of M` in the +page margin. The `.closing` group keeps totals and payment details together; it +can move to the next page when there is not enough room. + +Keep the flowing `@page` margins and automatic `.page` height when adapting this +layout. The invoice check covers the short sample, 24 rows, wrapped descriptions, +empty rows and page-boundary cases, including final PDF text bounds and every +displayed preview. + ## Build and deploy ```sh diff --git a/examples/react/src/invoice.css b/examples/react/src/invoice.css index 0c83bd8..14142f7 100644 --- a/examples/react/src/invoice.css +++ b/examples/react/src/invoice.css @@ -1,11 +1,20 @@ -@page { size: A4; margin: 0; } +@page { + size: A4; margin: 15mm 16mm 20mm; background: #f8f5ec; + @bottom-left { + content: "NORTHSTAR STUDIO / FICTIONAL INVOICE"; + font-family: Inter; font-size: 6.6pt; color: {{ink}}; + } + @bottom-right { + content: "Page " counter(page) " of " counter(pages); + font-family: Inter; font-size: 6.6pt; color: {{ink}}; + } +} * { box-sizing: border-box; } -html, body { margin: 0; padding: 0; } +html, body { margin: 0; padding: 0; background: #f8f5ec; } body { font-family: Inter; font-size: 10pt; line-height: 1.45; color: {{ink}}; } h1, h2, h3, p, figure { margin: 0; } h1, h2, h3 { font-weight: 400; } -.page { width: 210mm; height: 296.9mm; padding: 15mm 16mm; position: relative; break-after: page; background: #f8f5ec; } -.page:last-child { break-after: auto; } +.page { width: auto; height: auto; } .kicker { font-size: 7.2pt; font-weight: 600; letter-spacing: 1.4pt; text-transform: uppercase; } .serif { font-family: 'DM Serif Display'; font-weight: 400; } .display { font-family: 'Bebas Neue'; font-weight: 400; } @@ -16,7 +25,6 @@ h1, h2, h3 { font-weight: 400; } .grid-2 { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 24pt; } .grid-2 > * { min-width: 0; } .grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16pt; } -.footer { position: absolute; left: 16mm; right: 16mm; bottom: 12mm; border-top: .6pt solid #9eafa4; padding-top: 8pt; display: flex; justify-content: space-between; gap: 12pt; font-size: 6.6pt; letter-spacing: .45pt; } table { width: 100%; border-collapse: collapse; font-size: 9pt; } th { font-size: 7.5pt; font-weight: 600; text-align: left; } th, td { padding: 10pt 0; border-bottom: .55pt solid #bdc8bf; vertical-align: top; } @@ -37,12 +45,18 @@ a { color: inherit; } .invoice .details { border-top: .6pt solid #9eafa4; border-bottom: .6pt solid #9eafa4; padding: 15pt 0; margin-bottom: 10pt; } .invoice .details p { margin-top: 5pt; font-size: 8.2pt; } .invoice .details > div + div { border-left: .6pt solid #c7cdc4; padding-left: 14pt; } +.invoice table { table-layout: fixed; } .invoice th { color: #52665a; } +.invoice th:first-child { width: 56%; } +.invoice th:not(:first-child) { width: 14.666%; } +.invoice tr { break-inside: avoid; } .invoice td { padding: 12pt 0; } +.invoice td:first-child { overflow-wrap: anywhere; } .invoice .item-note { color: #617069; font-size: 8pt; margin-top: 4pt; } -.invoice .amounts { display: grid; grid-template-columns: 1fr 1.25fr; gap: 27pt; margin-top: 23pt; } +.invoice .closing { break-inside: avoid; } +.invoice .amounts { display: grid; grid-template-columns: 1fr 1.25fr; gap: 27pt; margin-top: 23pt; break-inside: avoid; } .invoice .thanks { font: italic 22pt/1.2 'DM Serif Display'; color: #b44123; padding-top: 8pt; } .invoice .summary-line { display: flex; justify-content: space-between; padding: 5pt 0; font-size: 8.5pt; } .invoice .total { background: {{ink}}; color: #fff8e8; padding: 16pt; margin-top: 9pt; border-left: 4pt solid #d96238; } .invoice .total .value { font: 38pt/1.1 'Bebas Neue'; margin-top: 7pt; } -.invoice .payment { margin-top: 20pt; padding-top: 12pt; border-top: .6pt solid #9eafa4; display: grid; grid-template-columns: 1fr 1fr; gap: 24pt; font-size: 8pt; } +.invoice .payment { margin-top: 16pt; padding-top: 12pt; border-top: .6pt solid #9eafa4; display: grid; grid-template-columns: 1fr 1fr; gap: 24pt; font-size: 8pt; break-inside: avoid; } diff --git a/examples/react/src/invoice.html b/examples/react/src/invoice.html index 4d49034..b923b3b 100644 --- a/examples/react/src/invoice.html +++ b/examples/react/src/invoice.html @@ -6,7 +6,9 @@
DESCRIPTIONHOURSRATEAMOUNT
Discovery & brand workshop

Positioning, priorities, and a clear creative direction

8$125.00$1,000.00
Digital design & implementation

A cohesive visual system, from layout to launch

6$95.00$570.00
Review & studio handoff

Final refinements, documentation, and delivery

2$150.00$300.00
+

A little clarity.
A lot of possibility.

Thank you for inviting us
to help shape your next chapter.

Subtotal$1,870.00
Tax · 0% in this sample$0.00
TOTAL DUE · USD
$1,870.00

Payment details

Reference {{reference}} with your payment.
Payment instructions are supplied separately.

A note from the studio

Questions about a line item?
Write to hello@example.invalid.

-
NORTHSTAR STUDIO / INVOICE {{reference}}FICTIONAL SAMPLE · 01 / 01
+ +
diff --git a/examples/vue/README.md b/examples/vue/README.md index 5cce7a5..be375fb 100644 --- a/examples/vue/README.md +++ b/examples/vue/README.md @@ -96,6 +96,19 @@ your target devices. Browser termination has no native thread-exit promise. The [browser SDK guide](https://github.com/fullbleed-engine/fullbleed-node/blob/main/docs/browser.md) covers custom font/image bytes, limits, hosting policy, and structured errors. +## Let an HTML invoice grow + +Add or remove rows inside `src/invoice.html`'s `` and update both sample +totals. The HTML sample does not calculate amounts. Its stylesheet lets the table +continue onto new pages, repeats column headings, and prints `Page N of M` in the +page margin. The `.closing` group keeps totals and payment details together; it +can move to the next page when there is not enough room. + +Keep the flowing `@page` margins and automatic `.page` height when adapting this +layout. The invoice check covers the short sample, 24 rows, wrapped descriptions, +empty rows and page-boundary cases, including final PDF text bounds and every +displayed preview. + ## Build and deploy ```sh diff --git a/examples/vue/src/invoice.css b/examples/vue/src/invoice.css index 0c83bd8..14142f7 100644 --- a/examples/vue/src/invoice.css +++ b/examples/vue/src/invoice.css @@ -1,11 +1,20 @@ -@page { size: A4; margin: 0; } +@page { + size: A4; margin: 15mm 16mm 20mm; background: #f8f5ec; + @bottom-left { + content: "NORTHSTAR STUDIO / FICTIONAL INVOICE"; + font-family: Inter; font-size: 6.6pt; color: {{ink}}; + } + @bottom-right { + content: "Page " counter(page) " of " counter(pages); + font-family: Inter; font-size: 6.6pt; color: {{ink}}; + } +} * { box-sizing: border-box; } -html, body { margin: 0; padding: 0; } +html, body { margin: 0; padding: 0; background: #f8f5ec; } body { font-family: Inter; font-size: 10pt; line-height: 1.45; color: {{ink}}; } h1, h2, h3, p, figure { margin: 0; } h1, h2, h3 { font-weight: 400; } -.page { width: 210mm; height: 296.9mm; padding: 15mm 16mm; position: relative; break-after: page; background: #f8f5ec; } -.page:last-child { break-after: auto; } +.page { width: auto; height: auto; } .kicker { font-size: 7.2pt; font-weight: 600; letter-spacing: 1.4pt; text-transform: uppercase; } .serif { font-family: 'DM Serif Display'; font-weight: 400; } .display { font-family: 'Bebas Neue'; font-weight: 400; } @@ -16,7 +25,6 @@ h1, h2, h3 { font-weight: 400; } .grid-2 { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 24pt; } .grid-2 > * { min-width: 0; } .grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16pt; } -.footer { position: absolute; left: 16mm; right: 16mm; bottom: 12mm; border-top: .6pt solid #9eafa4; padding-top: 8pt; display: flex; justify-content: space-between; gap: 12pt; font-size: 6.6pt; letter-spacing: .45pt; } table { width: 100%; border-collapse: collapse; font-size: 9pt; } th { font-size: 7.5pt; font-weight: 600; text-align: left; } th, td { padding: 10pt 0; border-bottom: .55pt solid #bdc8bf; vertical-align: top; } @@ -37,12 +45,18 @@ a { color: inherit; } .invoice .details { border-top: .6pt solid #9eafa4; border-bottom: .6pt solid #9eafa4; padding: 15pt 0; margin-bottom: 10pt; } .invoice .details p { margin-top: 5pt; font-size: 8.2pt; } .invoice .details > div + div { border-left: .6pt solid #c7cdc4; padding-left: 14pt; } +.invoice table { table-layout: fixed; } .invoice th { color: #52665a; } +.invoice th:first-child { width: 56%; } +.invoice th:not(:first-child) { width: 14.666%; } +.invoice tr { break-inside: avoid; } .invoice td { padding: 12pt 0; } +.invoice td:first-child { overflow-wrap: anywhere; } .invoice .item-note { color: #617069; font-size: 8pt; margin-top: 4pt; } -.invoice .amounts { display: grid; grid-template-columns: 1fr 1.25fr; gap: 27pt; margin-top: 23pt; } +.invoice .closing { break-inside: avoid; } +.invoice .amounts { display: grid; grid-template-columns: 1fr 1.25fr; gap: 27pt; margin-top: 23pt; break-inside: avoid; } .invoice .thanks { font: italic 22pt/1.2 'DM Serif Display'; color: #b44123; padding-top: 8pt; } .invoice .summary-line { display: flex; justify-content: space-between; padding: 5pt 0; font-size: 8.5pt; } .invoice .total { background: {{ink}}; color: #fff8e8; padding: 16pt; margin-top: 9pt; border-left: 4pt solid #d96238; } .invoice .total .value { font: 38pt/1.1 'Bebas Neue'; margin-top: 7pt; } -.invoice .payment { margin-top: 20pt; padding-top: 12pt; border-top: .6pt solid #9eafa4; display: grid; grid-template-columns: 1fr 1fr; gap: 24pt; font-size: 8pt; } +.invoice .payment { margin-top: 16pt; padding-top: 12pt; border-top: .6pt solid #9eafa4; display: grid; grid-template-columns: 1fr 1fr; gap: 24pt; font-size: 8pt; break-inside: avoid; } diff --git a/examples/vue/src/invoice.html b/examples/vue/src/invoice.html index 4d49034..b923b3b 100644 --- a/examples/vue/src/invoice.html +++ b/examples/vue/src/invoice.html @@ -6,7 +6,9 @@
DESCRIPTIONHOURSRATEAMOUNT
Discovery & brand workshop

Positioning, priorities, and a clear creative direction

8$125.00$1,000.00
Digital design & implementation

A cohesive visual system, from layout to launch

6$95.00$570.00
Review & studio handoff

Final refinements, documentation, and delivery

2$150.00$300.00
+

A little clarity.
A lot of possibility.

Thank you for inviting us
to help shape your next chapter.

Subtotal$1,870.00
Tax · 0% in this sample$0.00
TOTAL DUE · USD
$1,870.00

Payment details

Reference {{reference}} with your payment.
Payment instructions are supplied separately.

A note from the studio

Questions about a line item?
Write to hello@example.invalid.

-
NORTHSTAR STUDIO / INVOICE {{reference}}FICTIONAL SAMPLE · 01 / 01
+ +
diff --git a/tools/check-starter-invoices.py b/tools/check-starter-invoices.py new file mode 100644 index 0000000..901b367 --- /dev/null +++ b/tools/check-starter-invoices.py @@ -0,0 +1,182 @@ +"""Check actual starter invoice downloads, final text bounds, and all previews.""" +import argparse +import base64 +from datetime import datetime, timezone +from hashlib import sha256 +from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer +import json +from pathlib import Path +import threading +from urllib.parse import unquote, urlsplit +from zipfile import ZipFile + +from playwright.sync_api import sync_playwright, expect +from starter_invoice import cases, inspect + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--kind', choices=['browser', 'react', 'vue'], required=True) + site = parser.add_mutually_exclusive_group(required=True) + site.add_argument('--dist', type=Path) + site.add_argument('--origin', help='URL of the deployed starter, including its path.') + source = parser.add_mutually_exclusive_group(required=True) + source.add_argument('--templates', type=Path) + source.add_argument('--archive', type=Path, help='The exact downloaded starter ZIP.') + parser.add_argument('--out', type=Path, required=True) + parser.add_argument('--browser', choices=['chrome', 'firefox', 'webkit'], default='chrome') + parser.add_argument('--quick', action='store_true', help='Check the short and 24-row invoices only.') + parser.add_argument('--reference', type=Path, help='Compare PDF and every preview byte with a prior verification.') + args = parser.parse_args() + out = args.out.resolve() + out.mkdir(parents=True, exist_ok=False) + if args.templates: + original = (args.templates / 'invoice.html').read_text(encoding='utf-8') + css = (args.templates / 'invoice.css').read_text(encoding='utf-8') + else: + with ZipFile(args.archive) as archive: + assert archive.testzip() is None + prefix = f'fullbleed-{args.kind}-starter/src/' + original = archive.read(prefix + 'invoice.html').decode('utf-8').replace('\r\n', '\n') + css = archive.read(prefix + 'invoice.css').decode('utf-8').replace('\r\n', '\n') + fixtures = cases(original, css) + if args.quick: + fixtures = fixtures[:2] + reference = {} + if args.reference: + proof = json.loads(args.reference.read_text(encoding='utf-8')) + assert proof['ok'] + reference = {case['name']: case for case in proof['cases']} + assert all(case['name'] in reference for case in fixtures) + server = None + thread = None + if args.dist: + root = args.dist.resolve() + prefix = '/nested/invoices/' + + class Handler(SimpleHTTPRequestHandler): + def __init__(self, *a, **kw): + super().__init__(*a, directory=str(root), **kw) + + def translate_path(self, raw): + path = unquote(urlsplit(raw).path) + if not path.startswith(prefix): + return str(root / 'does-not-exist') + resolved = (root / path[len(prefix):]).resolve() + return str(resolved if resolved.is_relative_to(root) else root / 'does-not-exist') + + def end_headers(self): + self.send_header('Cache-Control', 'no-store') + super().end_headers() + + def copyfile(self, source, output): + try: + super().copyfile(source, output) + except (BrokenPipeError, ConnectionResetError, ConnectionAbortedError): + pass + + def log_message(self, *args): + pass + + server = ThreadingHTTPServer(('127.0.0.1', 0), Handler) + thread = threading.Thread(target=server.serve_forever, daemon=True) + thread.start() + origin = f'http://127.0.0.1:{server.server_port}{prefix}' + else: + origin = args.origin.rstrip('/') + '/' + records = [] + network = [] + errors = [] + try: + with sync_playwright() as p: + browser = p.chromium.launch(channel='chrome') if args.browser == 'chrome' else getattr(p, args.browser).launch() + context = browser.new_context(viewport={'width': 1440, 'height': 1000}, accept_downloads=True) + page = context.new_page() + page.on('request', lambda r: network.append({'method': r.method, 'url': r.url})) + page.on('pageerror', lambda error: errors.append(str(error))) + + def ready(): + expect(page.locator('#download')).to_be_enabled(timeout=60000) + expect(page.locator('#status')).to_contain_text('Ready.') + + def download(path): + with page.expect_download() as event: + page.locator('#download').click() + event.value.save_as(path) + + try: + page.goto(origin + '?design=invoice', wait_until='domcontentloaded') + ready() + if page.locator('#auto-preview').count(): + page.locator('#auto-preview').uncheck() + page.locator('#template-editor summary').click() + assert page.locator('#html-source').input_value() == original + assert page.locator('#css-source').input_value() == css + for fixture in fixtures: + folder = out / fixture['name'] + folder.mkdir() + page.locator('#html-source').fill(fixture['html']) + page.locator('#generate').click() + ready() + (folder / 'input.html').write_text(fixture['html'], encoding='utf-8', newline='\n') + (folder / 'style.css').write_text(css, encoding='utf-8', newline='\n') + download(folder / 'document.pdf') + result = inspect(folder / 'document.pdf', fixture) + previews = page.locator('#preview img') + expect(previews).to_have_count(result['pages']) + result['previewSha256'] = [] + for index in range(result['pages']): + encoded = previews.nth(index).evaluate('''async image => { + const bytes = new Uint8Array(await (await fetch(image.src)).arrayBuffer()); + let text = ''; for (const byte of bytes) text += String.fromCharCode(byte); return btoa(text); + }''') + data = base64.b64decode(encoded, validate=True) + assert data.startswith(b'\x89PNG\r\n\x1a\n') + (folder / f'page-{index + 1}.png').write_bytes(data) + result['previewSha256'].append(sha256(data).hexdigest()) + if reference: + prior = reference[fixture['name']] + assert result['pdfSha256'] == prior['pdfSha256'], fixture['name'] + assert result['previewSha256'] == prior['previewSha256'], fixture['name'] + result['pdfAndPreviewsMatchReference'] = True + if fixture['name'] == 'long': + for width, height in [(1440, 1000), (390, 844), (320, 760)]: + page.set_viewport_size({'width': width, 'height': height}) + page.evaluate('window.scrollTo(0, 0)') + assert page.evaluate('document.documentElement.scrollWidth <= innerWidth') + page.screenshot(path=str(folder / f'browser-{width}.png')) + page.set_viewport_size({'width': 1440, 'height': 1000}) + previous = previews.first.get_attribute('src') + page.locator('#generate').click() + ready() + assert previews.first.get_attribute('src') != previous + download(folder / 'repeat.pdf') + assert (folder / 'document.pdf').read_bytes() == (folder / 'repeat.pdf').read_bytes() + result['repeatPdfBytesMatch'] = True + records.append(result) + print(f'{args.kind}/{fixture["name"]}: {result["pages"]} pages, all text within bounds', flush=True) + assert not errors, errors + assert all(row['method'] == 'GET' for row in network) + record = {'ok': True, 'at': datetime.now(timezone.utc).isoformat(), 'kind': args.kind, + 'origin': origin, 'browser': args.browser, 'browserVersion': browser.version, + 'cases': records, 'errors': errors, 'nonGetRequests': 0, + 'sourceSha256': {'html': sha256(original.encode()).hexdigest(), 'css': sha256(css.encode()).hexdigest()}, + 'scope': 'These synthetic invoice records, actual PDF downloads and displayed previews. No universal layout, accessibility, conformance or adoption claim.'} + (out / 'verification.json').write_text(json.dumps(record, indent=2) + '\n', encoding='utf-8') + except Exception: + page.screenshot(path=str(out / 'failure.png')) + (out / 'failure.json').write_text(json.dumps({'cases': records, 'errors': errors, 'network': network}, indent=2) + '\n', encoding='utf-8') + raise + finally: + context.close() + browser.close() + finally: + if server: + server.shutdown() + server.server_close() + thread.join(timeout=5) + print(json.dumps({'ok': True, 'kind': args.kind, 'cases': len(records), 'pages': sum(case['pages'] for case in records)})) + + +if __name__ == '__main__': + main() diff --git a/tools/starter_invoice.py b/tools/starter_invoice.py new file mode 100644 index 0000000..8266670 --- /dev/null +++ b/tools/starter_invoice.py @@ -0,0 +1,83 @@ +"""Synthetic invoice records and independent final-PDF layout checks.""" +from decimal import Decimal +from hashlib import sha256 +from html import escape +import re + +from pypdf import PdfReader +import pypdfium2 as pdfium + + +def cases(original_html, css): + result = [{'name': 'short', 'html': original_html, 'css': css, 'total': '1,870.00', + 'markers': ['Discovery & brand workshop', 'Digital design & implementation', 'Review & studio handoff']}] + for name, count, wrapped in [('long', 24, False), ('empty', 0, False), ('wrapped', 12, True), + *[(f'boundary-{n}', n, False) for n in (4, 5, 16, 17)]]: + markers = [f'Service line {n:03d}' for n in range(1, count + 1)] + detail = 'Synthetic invoice record for pagination review.' + if wrapped: + detail = 'Discuss requirements, prepare the design, implement the agreed changes, and document the handoff. ' * 3 + rows = ''.join('' + escape(marker) + '

' + escape(detail) + + '

1$25.00$25.00' for marker in markers) + html, replacements = re.subn(r'.*?', '' + rows + '', original_html, flags=re.S) + assert replacements == 1 + total = f'{Decimal(count) * Decimal("25.00"):,.2f}' + assert html.count('$1,870.00') == 2 + html = html.replace('$1,870.00', '$' + total) + result.append({'name': name, 'html': html, 'css': css, 'total': total, 'markers': markers}) + return result + + +def inspect(path, fixture): + compact = lambda text: ''.join(text.split()) + reader = PdfReader(path, strict=True) + texts = [compact(page.extract_text()) for page in reader.pages] + joined = ''.join(texts) + positions = [] + item_pages = set() + for marker in fixture['markers']: + marker = compact(marker) + assert joined.count(marker) == 1, (fixture['name'], 'missing or duplicated item', marker) + positions.append(joined.index(marker)) + found = [n for n, text in enumerate(texts) if marker in text] + assert len(found) == 1, (fixture['name'], 'item split across pages', marker) + item_pages.add(found[0]) + assert positions == sorted(positions), (fixture['name'], 'item order') + assert '$' + fixture['total'] in texts[-1] and 'TOTALDUE' in texts[-1] + assert 'Paymentinstructionsaresuppliedseparately.' in texts[-1] + assert any('TOTALDUE' in text and 'Paymentinstructionsaresuppliedseparately.' in text for text in texts) + for n, text in enumerate(texts): + assert text.count(f'Page{n + 1}of{len(texts)}') == 1, (fixture['name'], 'page counter', n + 1) + if n in item_pages: + assert 'DESCRIPTIONHOURSRATEAMOUNT' in text, (fixture['name'], 'table headings', n + 1) + if fixture['name'] in ('short', 'empty'): + assert len(texts) == 1 + elif fixture['name'] in ('long', 'wrapped'): + assert len(texts) > 1 + bounds = [] + with pdfium.PdfDocument(path) as document: + assert len(document) == len(texts) + for n in range(len(document)): + page = document[n] + width, height = page.get_size() + assert abs(width - 595.276) < 0.1 and abs(height - 841.890) < 0.1 + text = page.get_textpage() + boxes = [] + try: + for index in range(text.count_chars()): + if not text.get_text_range(index, 1).strip(): + continue + left, bottom, right, top = text.get_charbox(index) + assert left >= -0.25 and bottom >= -0.25 and right <= width + 0.25 and top <= height + 0.25, ( + fixture['name'], 'text outside visible page', n + 1, index, [left, bottom, right, top]) + boxes.append([left, bottom, right, top]) + assert boxes + bounds.append({'page': n + 1, 'characters': len(boxes), 'textBox': [min(b[0] for b in boxes), + min(b[1] for b in boxes), max(b[2] for b in boxes), max(b[3] for b in boxes)]}) + finally: + text.close() + page.close() + return {'name': fixture['name'], 'pages': len(texts), 'items': len(fixture['markers']), + 'pdfSha256': sha256(path.read_bytes()).hexdigest(), 'allTextWithinPage': True, + 'orderedItemsOnce': True, 'repeatedTableHeadings': True, 'pageCounters': True, + 'totalAndPaymentTogether': True, 'pageBounds': bounds}