docs(sdlc): keep short cells on one line, unify QA/Tester

This commit is contained in:
Thanakorn
2026-10-02 16:54:10 +07:00
parent 203b541c59
commit 5d3a7a655b
117 changed files with 14 additions and 11 deletions
+8 -5
View File
@@ -354,7 +354,7 @@ async function tableWidthNeededMm(page) {
* them. Returns the IDs or dates that still stick out of their cell.
*/
async function applyProportionalWidths(page, textMm) {
return page.evaluate(({ availMm, SHORT_COLUMN_MM }) => {
return page.evaluate(({ availMm, SHORT_COLUMN_MM, SHORT_CELL_CHARS }) => {
const mm = 96 / 25.4;
const main = document.querySelector('main.delivery-document');
const probe = document.createElement('style');
@@ -373,7 +373,8 @@ async function applyProportionalWidths(page, textMm) {
const rects = [...range.getClientRects()];
const text = rects.length ? Math.max(...rects.map((r) => r.right)) - Math.min(...rects.map((r) => r.left)) : 0;
const style = getComputedStyle(cell);
return text + parseFloat(style.paddingLeft) + parseFloat(style.paddingRight) + 1;
// 1.2mm slack for the cell borders and glyphs that overhang their advance width.
return text + parseFloat(style.paddingLeft) + parseFloat(style.paddingRight) + 1.2 * mm;
};
const measure = (table, mode) => {
const holder = document.createElement('div');
@@ -384,7 +385,7 @@ async function applyProportionalWidths(page, textMm) {
for (const row of holder.querySelector('table').rows) {
let index = 0;
for (const cell of row.cells) {
if (cell.colSpan === 1) (columns[index] ??= []).push({ width: contentWidth(cell) / mm, head: cell.tagName === 'TH' });
if (cell.colSpan === 1) (columns[index] ??= []).push({ width: contentWidth(cell) / mm, head: cell.tagName === 'TH', short: cell.textContent.trim().length <= SHORT_CELL_CHARS });
index += cell.colSpan;
}
}
@@ -401,7 +402,9 @@ async function applyProportionalWidths(page, textMm) {
let floor = narrow.map((c, i) => Math.min(Math.max(...c.map((x) => x.width)), longest[i]));
// Short columns (IDs, dates, statuses) stay on one line when the page allows;
// the prose columns then share what is left in proportion to their content.
const oneLine = floor.map((f, i) => (longest[i] <= SHORT_COLUMN_MM ? longest[i] : f));
// So do short entries in any column - a status word, a list of initials.
const shortest = line.map((c) => Math.max(0, ...c.filter((x) => x.short && !x.head).map((x) => x.width)));
const oneLine = floor.map((f, i) => (longest[i] <= SHORT_COLUMN_MM ? longest[i] : Math.max(f, shortest[i])));
if (oneLine.reduce((a, b) => a + b, 0) < availMm) floor = oneLine;
const weight = line.map((c) => {
const body = c.filter((x) => !x.head);
@@ -462,7 +465,7 @@ async function applyProportionalWidths(page, textMm) {
.map((span) => span.textContent);
main.style.width = '';
return [...new Set(clipped)];
}, { availMm: textMm, SHORT_COLUMN_MM: 35 });
}, { availMm: textMm, SHORT_COLUMN_MM: 35, SHORT_CELL_CHARS: 16 });
}
main().catch((error) => { console.error(error); process.exit(1); });