Replace the HTML preview with a worker-rendered PDF preview

Rendering moves into a module Web Worker behind a latest-wins RenderClient
with a watchdog and a handshake-based main-thread fallback. The preview
shows the real PDF through pdf.js at 2x with zoom, page indicator, audit
issues popover and a focus modal. A4/Letter and margin controls are frozen
into each invoice at issue and can be saved as the default (migration M3).
react-pdf and pdf.js are lazy-loaded; the main chunk shrinks from 1.8 MB
to 0.5 MB. The HTML twin and its styles are removed.
This commit is contained in:
2026-10-04 05:47:19 +05:30
parent a014a907e4
commit cedf4839bd
24 changed files with 1579 additions and 505 deletions
+134 -182
View File
@@ -186,218 +186,170 @@ body {
color: var(--cds-text-secondary);
}
/* ---------- Invoice preview ("paper") ---------- */
.inv-preview-wrap {
/* ---------- PDF preview column ---------- */
.voiced-page-setup {
margin-bottom: 1rem;
}
.voiced-page-setup__row {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 1rem;
}
.voiced-page-setup__field {
min-width: 11rem;
flex: 1 1 11rem;
}
.voiced-page-setup__field .cds--label {
display: block;
margin-bottom: 0.5rem;
}
.voiced-page-setup__footer {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.5rem 1rem;
margin-top: 0.75rem;
}
.voiced-page-setup__note {
font-size: 0.75rem;
flex: 1 1 12rem;
}
.voiced-pdf-preview {
display: flex;
flex-direction: column;
gap: 0.5rem;
min-width: 0;
}
.voiced-pdf-preview__status {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 0.25rem 1rem;
min-height: 2rem;
}
.voiced-pdf-preview__chips,
.voiced-pdf-preview__actions {
display: flex;
align-items: center;
gap: 0.5rem;
}
.voiced-pdf-preview__empty {
display: flex;
align-items: center;
justify-content: center;
height: 12rem;
background: var(--cds-layer-accent);
color: var(--cds-text-secondary);
}
.inv-paper {
background: #ffffff;
color: #161616;
width: 100%;
max-width: 820px;
padding: 40px 44px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
font-family: 'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif;
font-size: 13px;
line-height: 1.5;
box-sizing: border-box;
}
.inv-top {
display: grid;
grid-template-columns: minmax(0, 1fr) 220px;
gap: 24px;
align-items: start;
}
.inv-vendor {
.voiced-pdf-viewer {
display: flex;
gap: 16px;
align-items: flex-start;
flex-direction: column;
gap: 0.5rem;
min-width: 0;
}
.inv-vendor > div {
flex: 1 1 0;
min-width: 0;
}
.inv-vendor__logo {
max-height: 56px;
max-width: 220px;
object-fit: contain;
}
.inv-vendor__name {
font-size: 22px;
font-weight: 600;
margin: 0 0 4px;
}
.inv-vendor__line {
margin: 0;
white-space: pre-line;
overflow-wrap: anywhere;
}
.inv-meta {
text-align: right;
min-width: 0;
}
.inv-meta__title {
font-size: 20px;
font-weight: 600;
letter-spacing: 0.08em;
margin: 0 0 8px;
text-transform: uppercase;
}
.inv-meta__row {
.voiced-pdf-viewer__bar {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 16px;
gap: 0.5rem 1rem;
}
.inv-meta__label {
color: #525252;
.voiced-pdf-viewer__zoom {
flex: 0 1 18rem;
}
.inv-meta__value {
font-weight: 600;
}
.inv-split {
display: flex;
justify-content: space-between;
gap: 24px;
margin-top: 28px;
}
.inv-block {
min-width: 0;
}
.inv-block__label {
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
color: #525252;
margin: 0 0 4px;
}
.inv-block__strong {
font-weight: 600;
}
.inv-table {
width: 100%;
border-collapse: collapse;
margin-top: 28px;
}
.inv-table th {
text-align: left;
font-size: 11px;
letter-spacing: 0.06em;
text-transform: uppercase;
color: #525252;
border-bottom: 1.5px solid #161616;
padding: 6px 8px;
}
.inv-table td {
padding: 8px;
border-bottom: 1px solid #e0e0e0;
vertical-align: top;
}
.inv-table .num {
text-align: right;
.voiced-pdf-viewer__page {
font-size: 0.875rem;
color: var(--cds-text-secondary);
white-space: nowrap;
}
.inv-totals {
margin-top: 16px;
.voiced-pdf-preview__scroll {
height: calc(100vh - 25rem);
min-height: 20rem;
overflow: auto;
background: var(--cds-layer-accent);
}
.voiced-pdf-viewer--focus .voiced-pdf-preview__scroll {
height: calc(100vh - 12rem);
}
/* The wrapper is as wide as the widest page so a zoomed page scrolls instead of being clipped. */
.voiced-pdf-preview__pages {
box-sizing: border-box;
display: flex;
justify-content: flex-end;
flex-direction: column;
align-items: center;
gap: 16px;
min-width: 100%;
width: max-content;
padding: 16px;
}
.inv-totals__table {
width: 320px;
.voiced-pdf-preview__page {
flex: none;
background: #ffffff;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}
.inv-totals__row {
display: flex;
justify-content: space-between;
padding: 4px 0;
}
.inv-totals__row--grand {
border-top: 1.5px solid #161616;
margin-top: 4px;
padding-top: 8px;
font-size: 16px;
font-weight: 600;
}
.inv-words {
margin-top: 16px;
font-style: italic;
}
.inv-bottom {
display: flex;
justify-content: space-between;
gap: 24px;
margin-top: 32px;
align-items: flex-end;
}
.inv-signature {
text-align: right;
}
.inv-signature__img {
max-height: 64px;
max-width: 220px;
object-fit: contain;
.voiced-pdf-preview__canvas {
display: block;
margin-left: auto;
width: 100%;
height: 100%;
}
.inv-signature__name {
margin-top: 6px;
font-weight: 600;
border-top: 1px solid #8d8d8d;
padding-top: 4px;
display: inline-block;
min-width: 160px;
.voiced-pdf-focus .cds--modal-container {
width: 96vw;
max-width: 96vw;
height: 94vh;
max-height: 94vh;
}
.inv-fineprint {
margin-top: 8px;
font-size: 10px;
color: #6f6f6f;
text-align: right;
.voiced-pdf-issues {
width: 22rem;
max-width: 80vw;
max-height: 20rem;
overflow: auto;
padding: 0.75rem 1rem;
}
.inv-footer {
margin-top: 28px;
padding-top: 10px;
border-top: 1px solid #e0e0e0;
font-size: 10px;
color: #6f6f6f;
.voiced-pdf-issues__list {
list-style: none;
margin: 0;
padding: 0;
}
.voiced-pdf-issues__item + .voiced-pdf-issues__item {
margin-top: 0.75rem;
}
.voiced-pdf-issues__head {
display: flex;
justify-content: space-between;
gap: 12px;
align-items: center;
gap: 0.5rem;
}
@media print {
.inv-paper {
box-shadow: none;
max-width: none;
}
.voiced-pdf-issues__message {
margin: 0.25rem 0 0;
font-size: 0.875rem;
}
.voiced-tag--warn.cds--tag {
background-color: var(--cds-support-warning);
color: #161616;
}