Align PDF sidebar chip and chrome with Typst layout.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-25 14:40:42 +03:30
parent 9d6a01f010
commit 570eb12e24
2 changed files with 44 additions and 27 deletions

View File

@@ -174,13 +174,15 @@ function Meta(meta)
</div> </div>
]], logo_html, company, subtitle_html, title) ]], logo_html, company, subtitle_html, title)
-- Rotated sidebar labels; page chip comes from print.css @page @bottom-left. -- Rotated sidebar labels (title then destinations, matching typst grid columns).
-- .chip-gap extends the rule to the @bottom-left page chip (persian ۱/N).
local sidebar = string.format([[ local sidebar = string.format([[
<div class="print-sidebar print-only" aria-hidden="true"> <div class="print-sidebar print-only" aria-hidden="true">
<div class="seg">%s</div> <div class="seg">%s</div>
<div class="seg">%s</div> <div class="seg">%s</div>
<div class="chip-gap" aria-hidden="true"></div>
</div> </div>
]], destinations, title) ]], title, destinations)
local running = string.format([[ local running = string.format([[
<div class="print-running-header print-only" aria-hidden="true"> <div class="print-running-header print-only" aria-hidden="true">

View File

@@ -37,21 +37,20 @@
@page { @page {
size: A4; size: A4;
/* Extra left margin for rotated sidebar; bottom-left box = typst page chip */ /* Match typst-templates: 2cm sides, 2.5cm top/bottom */
margin: 2.5cm 2cm 2.5cm 2.8cm; margin: 2.5cm 2cm 2.5cm 2cm;
@bottom-center { @bottom-center {
content: counter(page); content: none;
font-family: "IRNazanin", sans-serif;
font-size: 11pt;
} }
@top-center { @top-center {
content: element(report-header); content: element(report-header);
width: 100%; width: 100%;
} }
/* WeasyPrint only updates counter(page) reliably in @page margin boxes /* Page chip: counters only update in @page margin boxes (not position:fixed).
(not inside position:fixed). Place the black n/N chip at bottom-left. */ Rotate the whole ۱/N string like typst's -90deg sidebar grid.cell
(writing-mode: sideways-lr leaves numerals horizontal in WeasyPrint). */
@bottom-left { @bottom-left {
content: counter(page) " / " counter(pages); content: counter(page, persian) "/" counter(pages, persian);
font-family: "IRZar", "IRNazanin", sans-serif; font-family: "IRZar", "IRNazanin", sans-serif;
font-size: 11pt; font-size: 11pt;
color: #fff; color: #fff;
@@ -61,8 +60,11 @@
height: 20pt; height: 20pt;
text-align: center; text-align: center;
vertical-align: middle; vertical-align: middle;
margin-left: -1.6cm; /* Align chip's content-facing (right) edge with the sidebar rule. */
margin-left: -1.66cm;
margin-bottom: 0.35cm;
direction: ltr; direction: ltr;
transform: rotate(-90deg);
} }
} }
@@ -73,11 +75,16 @@
} }
@media print { @media print {
/* Keep html LTR so position:fixed + left/translateX for the sidebar use a
sane containing block. WeasyPrint with html{direction:rtl} shifts fixed
boxes far right and they clip before reaching the typst left-edge band.
Document content stays RTL on body. */
html { html {
direction: rtl; direction: ltr;
} }
body { body {
direction: rtl;
font-family: "IRNazanin", sans-serif; font-family: "IRNazanin", sans-serif;
font-size: 13pt; font-size: 13pt;
line-height: 1.2; line-height: 1.2;
@@ -139,17 +146,23 @@ nav.toc-active,
} }
/* ===== Left rotated sidebar (every page) ===== */ /* ===== Left rotated sidebar (every page) ===== */
/* Mirrors typst product_test_template / travel-report-template:
rotate(-90deg) grid with columns ~(30%, 30%) + page chip in @bottom-left.
Negative `left` is clipped by WeasyPrint; use translateX into the margin instead. */
.print-sidebar { .print-sidebar {
position: fixed; position: fixed;
left: 0.25cm; left: 0;
/* Leave room at the bottom for the @page bottom-left page chip */ /* Keep >= 0 — negative bottom clips the rotated sidebar in WeasyPrint */
bottom: 3.4cm; bottom: 0.05cm;
width: 16.5cm;
/* Labels + chip-gap (~typst place dy:73% band through page chip) */
width: 11.5cm;
height: 20pt; height: 20pt;
transform-origin: left bottom; transform-origin: left bottom;
transform: rotate(-90deg); /* Pull into left margin (negative left is clipped by WeasyPrint) */
transform: translateX(-0.75cm) rotate(-90deg);
display: flex; display: flex;
flex-direction: row; flex-direction: row-reverse;
align-items: stretch; align-items: stretch;
font-family: "IRZar", "IRNazanin", sans-serif; font-family: "IRZar", "IRNazanin", sans-serif;
font-size: 13pt; font-size: 13pt;
@@ -158,15 +171,22 @@ nav.toc-active,
z-index: 1000; z-index: 1000;
} }
/* Extends the sidebar rule toward the @bottom-left page chip */
.print-sidebar .chip-gap {
flex: 0 0 28pt;
}
.print-sidebar .seg { .print-sidebar .seg {
/* typst columns: 30% / 30% of the label band */
flex: 1 1 0; flex: 1 1 0;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; /* typst: #h(1fr) text #h(5fr) — bias text toward the rule */
justify-content: flex-start;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
padding: 0 6pt; padding: 0 1pt 0 4pt;
direction: rtl; direction: rtl;
} }
@@ -184,6 +204,8 @@ nav.toc-active,
align-items: flex-start; align-items: flex-start;
width: 100%; width: 100%;
margin: 0 0 16pt 0; margin: 0 0 16pt 0;
padding-bottom: 10pt;
border-bottom: 1pt solid black;
direction: ltr; direction: ltr;
} }
@@ -263,20 +285,13 @@ h1, h2, h3, h4 {
page-break-after: avoid; page-break-after: avoid;
} }
/* Level-1/2 headings get a full-width rule above (typst show heading) */
h1, h2 { h1, h2 {
font-size: 14pt; font-size: 14pt;
margin: 16pt 0 10pt 0; margin: 16pt 0 10pt 0;
padding-top: 8pt;
border-top: 1pt solid black;
} }
/* First body heading after Quarto title header: no rule (typst skips at top) */
#title-block-header + h1,
.print-title-block + h1, .print-title-block + h1,
.print-travel-meta + h1 { .print-travel-meta + h1 {
border-top: none !important;
padding-top: 0 !important;
margin-top: 8pt; margin-top: 8pt;
} }