Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

slides: a rounded table no longer clips rows that outgrow its box; validate() reports table-overflow (#692)

nyblnet7dfaacd63ca1
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a4e2da49..edc91abf 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -2374,6 +2374,11 @@ jobs:
# range across a parent copies parents only, never its states; plural
# and singular toasts.
run: node scripts/test-slides-copy-slides-browser.mjs
+ - name: Rounded tables in Chromium
+ # A rounded table whose rows outgrow its box shows its last row (#494),
+ # keeps rounded corners on its real bottom, and a short one still
+ # fills its box; tables without a radius are unchanged.
+ run: node scripts/test-slides-table-radius-browser.mjs
- name: Paste position in Chromium
# ⌘C then ⌘V onto another slide keeps the element's position; onto the
# source slide it steps +20 and cascades (#569).
diff --git a/AGENTS.md b/AGENTS.md
index 0e0a5adc..c9b904bf 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -208,8 +208,8 @@ node scripts/bento-check.mjs doc.json --json --fail-on warning # machine-reada
```
The loop: write the document JSON (compact where the shell accepts it) → `bento
-check --png` → read `findings` (`text-overflow` says how many px the box is
-short and on which element; `out-of-canvas`, dead links, effects that can
+check --png` → read `findings` (`text-overflow` and `table-overflow` say how
+many px the box is short and on which element; `out-of-canvas`, dead links, effects that can
never run, unknown keys the gate dropped) → look at `contact.png`, one image of
every slide, or a single `page-NN.png` when a finding points at it → fix →
run again. Exit 0 means no finding at or above `--fail-on` (default `error`).
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dbd1ac9d..1a284edd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,12 @@ pre-1.0.
## [Unreleased]
+- **A table with rounded corners no longer hides rows.** When a rounded
+ table's rows needed more height than its box, the rows past the bottom were
+ cut off with nothing to say so. They now show, as they always did for a table
+ without rounded corners, and the corners sit on the table's real bottom.
+ Checking a deck (`bento check`, `validate()`) reports a new `table-overflow`
+ warning with how many pixels the box is short. Reported in #494.
- **The text cursor shows at the start of a line.** While editing a text
box, the cursor at the very beginning of a line was hidden under the blue
editing frame and the selection box's edge. The frame now sits a few pixels
diff --git a/scripts/bento-check.mjs b/scripts/bento-check.mjs
index 98902ac7..7b5af506 100644
--- a/scripts/bento-check.mjs
+++ b/scripts/bento-check.mjs
@@ -265,7 +265,7 @@ if (pngDir) {
// ---- the report ----------------------------------------------------------------------
const findings = report.findings ?? []
-const overflow = findings.filter((f) => f.code === 'text-overflow')
+const overflow = findings.filter((f) => f.code === 'text-overflow' || f.code === 'table-overflow')
const dropped = report.load?.dropped ?? []
const errors = findings.filter((f) => f.severity === 'error').length
const warnings = findings.filter((f) => f.severity === 'warning').length
diff --git a/scripts/test-bento-check.ts b/scripts/test-bento-check.ts
index f89f8159..c92d40cd 100644
--- a/scripts/test-bento-check.ts
+++ b/scripts/test-bento-check.ts
@@ -111,6 +111,27 @@ const r2 = run([p, '--fail-on', 'error'])
ok(r2.code === 0, `the same deck exits 0 with --fail-on error (warnings only) (exit ${r2.code})`)
ok(/warning text-overflow \[t1\]/.test(r2.out) && /out-of-canvas \[r1\]/.test(r2.out), 'the human summary lists both with their ids')
+console.log('\ntables whose rows outgrow the box (#494)\n')
+{
+ const rows = (n: number) => Array.from({ length: n }, (_, i) => ({ cells: [{ html: `Row ${i + 1}` }, { html: String(i * 10) }] }))
+ const table = (id: string, y: number, h: number, n: number, radius: number) => ({
+ id, type: 'table', x: 96, y, w: 400, h, rotation: 0, opacity: 1, columns: [{ w: 1 }, { w: 1 }], header: false,
+ rows: rows(n), style: { fontSize: 16, cellPadX: 10, cellPadY: 8, borderWidth: 1, borderColor: '#ccc', radius },
+ })
+ const deck = { ...full, slides: [{ id: 's1', background: '#ffffff', transition: 'fade', notes: '', elements: [
+ table('round-over', 40, 80, 10, 12), table('round-fits', 40, 400, 3, 12), table('square-over', 460, 60, 8, 0),
+ ] }] }
+ const rt = run([write('tables.json', deck), '--json'])
+ let jt: any = null
+ try { jt = JSON.parse(rt.out) } catch {}
+ const tf = (id: string) => (jt?.findings ?? []).find((f: any) => f.code === 'table-overflow' && f.element === id)
+ ok(!!tf('round-over') && /need (\d+)px/.test(tf('round-over').message) && tf('round-over').path === 'h' && tf('round-over').severity === 'warning',
+ `a rounded table whose rows outgrow its box is reported, with the px they need (${tf('round-over')?.message?.slice(0, 50)}…)`)
+ ok(!!tf('square-over'), 'so is one without a radius')
+ ok(!tf('round-fits'), 'a table that fits its box is not')
+ ok((jt?.overflow ?? []).some((f: any) => f.element === 'round-over'), 'table overflow is in the overflow list too')
+}
+
console.log('\nimages\n')
const outDir = path.join(tmp, 'png')
const r3 = run([p, '--png', outDir, '--json'])
diff --git a/scripts/test-slides-table-radius-browser.mjs b/scripts/test-slides-table-radius-browser.mjs
new file mode 100644
index 00000000..1c05adbb
--- /dev/null
+++ b/scripts/test-slides-table-radius-browser.mjs
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+// A rounded table never hides a row (#494).
+//
+// npm run build:single --prefix slides && node scripts/test-slides-table-radius-browser.mjs
+//
+// WHAT THIS PROVES, in the packaged editor. `style.radius` rounds a table's
+// corners by clipping, and the clip used to be the element's box: every row the
+// box was too short for was cut off, with nothing on screen saying so. Now:
+// 1. a rounded table whose rows outgrow its box shows its LAST row — the
+// point at its centre hit-tests to that row's cell (a clipped area is not
+// hit-testable), and no wrapper ends above it;
+// 2. its corners are still rounded, on the table's real bottom;
+// 3. a rounded table SHORTER than its box still fills it, rows stretched as
+// before (the fix must not shrink tables that fit);
+// 4. a table without a radius is unchanged.
+// (validate()'s `table-overflow` finding, which says the box is too short, is
+// pinned in scripts/test-bento-check.ts.)
+const { chromium } = await import(process.env.PLAYWRIGHT_MODULE || 'playwright')
+
+let checks = 0
+let failures = 0
+function ok(cond, msg) {
+ checks++
+ if (!cond) { failures++; console.log(` FAIL ${msg}`) } else console.log(` ok ${msg}`)
+}
+
+const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH, headless: true })
+try {
+ const p = await browser.newPage({ viewport: { width: 1440, height: 1000 } })
+ const errors = []
+ p.on('pageerror', (e) => errors.push(e.message))
+ await p.route(/^https?:/, (r) => r.abort())
+ await p.goto(new URL('../slides/dist-single/Bento_Slides.bento.html', import.meta.url).href)
+ await p.waitForFunction(() => window.bento?.doc)
+ await p.evaluate(() => {
+ const rows = (n) => Array.from({ length: n }, (_, i) => ({ cells: [{ html: `Row ${i + 1}` }, { html: String(i * 10) }] }))
+ const table = (id, x, h, n, radius) => ({
+ id, type: 'table', x, y: 60, w: 300, h, rotation: 0, opacity: 1, columns: [{ w: 1 }, { w: 1 }], header: false,
+ rows: rows(n), style: { fontSize: 16, cellPadX: 10, cellPadY: 8, borderWidth: 1, borderColor: '#ccc', radius, headerBg: '#eee' },
+ })
+ const d = JSON.parse(JSON.stringify(window.bento.doc))
+ d.slides = [{ id: 's1', background: '#ffffff', elements: [
+ table('over', 60, 90, 9, 14), table('fits', 420, 400, 3, 14), table('plain', 780, 400, 3, 0),
+ ] }]
+ window.bento.loadDoc(JSON.stringify(d))
+ })
+ await p.waitForTimeout(400)
+
+ const look = (id) => p.evaluate((i) => {
+ const node = document.querySelector(`.ed-stage-scale [data-el-id="${i}"]`)
+ const wrap = node.querySelector('.bento-table-wrap'), table = node.querySelector('.bento-table')
+ const rows = [...table.querySelectorAll('tr')]
+ const last = rows.at(-1).getBoundingClientRect(), box = node.getBoundingClientRect(), w = wrap.getBoundingClientRect(), t = table.getBoundingClientRect()
+ const hit = document.elementFromPoint(last.left + last.width / 4, last.top + last.height / 2)
+ return {
+ boxH: Math.round(box.height), tableH: Math.round(t.height), wrapBottom: Math.round(w.bottom), lastBottom: Math.round(last.bottom),
+ lastHit: !!hit && rows.at(-1).contains(hit), radius: getComputedStyle(wrap).borderTopLeftRadius, bottomRadius: getComputedStyle(wrap).borderBottomLeftRadius,
+ rowHs: rows.map((r) => Math.round(r.getBoundingClientRect().height)),
+ }
+ }, id)
+
+ console.log('\na rounded table taller than its box\n')
+ const o = await look('over')
+ ok(o.tableH > o.boxH, `its rows are taller than the box (${o.tableH} > ${o.boxH}) — the case #494 is about`)
+ ok(o.lastHit, 'its last row is on screen: the point at its centre hits that row, not whatever lies beneath')
+ ok(o.wrapBottom >= o.lastBottom - 1, `no wrapper ends above the last row (wrapper bottom ${o.wrapBottom}, row bottom ${o.lastBottom})`)
+ ok(o.radius !== '0px' && o.bottomRadius !== '0px', `its corners are still rounded, the bottom ones on the real bottom (${o.radius})`)
+
+ console.log('\na rounded table shorter than its box\n')
+ const f = await look('fits')
+ ok(Math.abs(f.tableH - f.boxH) <= 1, `it still fills its box (${f.tableH} of ${f.boxH})`)
+ const sum = f.rowHs.reduce((a, b) => a + b, 0)
+ ok(Math.abs(sum - f.boxH) <= 3 && Math.max(...f.rowHs) - Math.min(...f.rowHs) <= 1,
+ `its rows are stretched to share the height, as before (${f.rowHs.join('/')} = ${sum} of ${f.boxH})`)
+
+ console.log('\na table without a radius\n')
+ const q = await look('plain')
+ ok(Math.abs(q.tableH - q.boxH) <= 1 && q.radius === '0px', `fills its box, square corners (${q.tableH} of ${q.boxH})`)
+ ok(JSON.stringify(q.rowHs) === JSON.stringify(f.rowHs), `same row heights as the rounded one (${q.rowHs.join('/')})`)
+
+ ok(errors.length === 0, `no page errors${errors.length ? ': ' + errors.join('; ') : ''}`)
+} finally { await browser.close() }
+
+console.log(`\n${checks - failures}/${checks} checks passed`)
+process.exit(failures ? 1 : 0)
diff --git a/slides/src/measure.ts b/slides/src/measure.ts
index e4222675..9cb3a77d 100644
--- a/slides/src/measure.ts
+++ b/slides/src/measure.ts
@@ -20,7 +20,7 @@
// text layout changed, and drift in a measuring tool is worse than no tool: it
// reads as authoritative and is quietly wrong.
-import type { BentoDoc, TextElement } from './model.ts'
+import type { BentoDoc, TableElement, TextElement } from './model.ts'
import { defaultText } from './model.ts'
import { renderElement } from './render.ts'
@@ -121,6 +121,33 @@ export function measureElements(els: TextElement[], doc: BentoDoc): TextMeasurem
return withHost((host) => els.map((el) => measureInto(host, specOf(el), doc)))
}
+/** How tall a table's rows actually render, and how far past its box. */
+export interface TableMeasurement {
+ /** height the rows need at the element's width, in slide px, rounded up */
+ height: number
+ /** px the rows run past the element's `h` (0 when they fit) */
+ overflow: number
+}
+
+/**
+ * Measure tables the same way — rendered through `renderElement`, at the
+ * element's own width and height, in one host. A table's `height:100%` is a
+ * MINIMUM (a table never shrinks below its rows), so the rendered table height
+ * is what the rows need. offsetHeight, not the bounding box, so a rotated
+ * table measures its own height and not its rotated extent.
+ */
+export function measureTables(els: TableElement[], doc: BentoDoc): TableMeasurement[] {
+ if (!els.length) return []
+ return withHost((host) => els.map((el) => {
+ const node = renderElement({ ...el, x: 0, y: 0 }, doc)
+ host.appendChild(node)
+ const table = node.querySelector<HTMLElement>('.bento-table')
+ const height = Math.ceil(table ? table.offsetHeight : el.h)
+ node.remove()
+ return { height, overflow: Math.max(0, height - el.h) }
+ }))
+}
+
const specOf = (el: TextElement): TextMeasureSpec => ({
html: el.html,
w: el.w,
diff --git a/slides/src/render.ts b/slides/src/render.ts
index 3f65b62f..ec64b9bb 100644
--- a/slides/src/render.ts
+++ b/slides/src/render.ts
@@ -1018,10 +1018,20 @@ export function renderTableHtml(el: TableElement, doc: BentoDoc): string {
})
.join('')
const rad = cssNum(st.radius, 0, 512)
- const radius = rad ? `border-radius:${rad}px;overflow:hidden;` : ''
+ // A radius rounds the corners by CLIPPING, so the clip must follow the table,
+ // not the box: a wrapper held at the box's height cut off every row the box
+ // was too short for, with nothing on screen saying so (#494). As a flex column
+ // with min-height the table still fills a short box (it grows into it) and a
+ // long one makes the wrapper taller — rows overflow visibly, exactly as they
+ // do without a radius, and the rounded corners sit on the real bottom.
+ // validate()'s `table-overflow` reports the box being too short.
+ const wrap = rad
+ ? `min-height:100%;display:flex;flex-direction:column;border-radius:${rad}px;overflow:hidden;`
+ : 'height:100%;'
+ const tableH = rad ? 'flex:1 0 auto;' : 'height:100%;'
return (
- `<div class="bento-table-wrap" style="width:100%;height:100%;${radius}">` +
- `<table class="bento-table" style="width:100%;height:100%;border-collapse:collapse;` +
+ `<div class="bento-table-wrap" style="width:100%;${wrap}">` +
+ `<table class="bento-table" style="width:100%;${tableH}border-collapse:collapse;` +
`table-layout:fixed;font-family:${font};font-size:${cssNum(st.fontSize, 16, 512)}px;line-height:1.3;">` +
`<colgroup>${cols}</colgroup>${rowsHtml}</table></div>`
)
diff --git a/slides/src/validate.ts b/slides/src/validate.ts
index 54a780e6..32864cd8 100644
--- a/slides/src/validate.ts
+++ b/slides/src/validate.ts
@@ -22,10 +22,10 @@
// a DOM (node tooling) the measured checks are skipped and `measured` reports
// false, rather than guessing.
-import type { BentoDoc, Slide, SlideElement, TextElement } from './model.ts'
+import type { BentoDoc, Slide, SlideElement, TableElement, TextElement } from './model.ts'
import { MODEL_KEYS } from './modelkeys.generated.ts'
import { isRemoteUrl } from '../../kernel/src/net.ts'
-import { measureElements } from './measure.ts'
+import { measureElements, measureTables } from './measure.ts'
import { BUILTIN_FONTS } from './fonts.ts'
import { eachRef, paletteOf, parseThemeRef, resolveRef, _readPath } from './palette.ts'
@@ -471,4 +471,19 @@ function measureOverflow(doc: BentoDoc, add: (f: Finding) => void) {
message: `Text needs ${m.height}px but the box is ${el.h}px tall — it overflows by ${m.overflow}px (${m.lines} lines) and will collide with whatever is below it.`,
})
})
+ // Tables the same way: rows that need more height than the box run past
+ // its bottom (#494). With a corner radius they used to be clipped instead,
+ // silently; they now show, so this is what says the box is too short.
+ const tables: Array<{ slide: string; el: TableElement }> = []
+ for (const slide of doc.slides) {
+ for (const el of slide.elements) if (el.type === 'table' && el.rows.length) tables.push({ slide: slide.id, el })
+ }
+ measureTables(tables.map((t) => t.el), doc).forEach((m, i) => {
+ const { slide, el } = tables[i]
+ if (m.overflow <= 1) return
+ add({
+ slide, element: el.id, code: 'table-overflow', severity: 'warning', path: 'h',
+ message: `The table's rows need ${m.height}px but the box is ${el.h}px tall — they run ${m.overflow}px past it and will collide with whatever is below. Make the box taller, or the text or cell padding smaller.`,
+ })
+ })
}