with one click
debug-ui-layout
// Optimize text copy to fit rendered UI layout using spacewave-debug eval to measure exact line breaks and eliminate orphans.
// Optimize text copy to fit rendered UI layout using spacewave-debug eval to measure exact line breaks and eliminate orphans.
Use the spacewave-debug CLI to inspect and interact with the running page.
Use after completing implementation work to catch AGENTS.md violations, dead code, and issues missed during development. Run before showing results to the user.
| name | debug-ui-layout |
| description | Optimize text copy to fit rendered UI layout using spacewave-debug eval to measure exact line breaks and eliminate orphans. |
Use the spacewave-debug eval bridge to iteratively measure how text copy renders at actual viewport widths, then adjust wording to produce clean line breaks without orphans.
Find the section by its DOM id or heading text:
go run ./cmd/spacewave-debug/ eval "document.getElementById('section-id')?.querySelector('h2')?.textContent"
Write an eval script to .tmp/eval-{section}.js that collects width, height, line count, and line-height for every text element in the section:
var section = document.getElementById("section-id")
if (!section) return "no section"
var ps = section.querySelectorAll("p")
var res = []
for (var i = 0; i < ps.length; i++) {
var p = ps[i]
var rect = p.getBoundingClientRect()
var style = getComputedStyle(p)
var lines = Math.round(rect.height / parseFloat(style.lineHeight))
res.push("p" + i + " w:" + Math.round(rect.width) + " h:" + Math.round(rect.height) + " lines:" + lines + " lh:" + style.lineHeight + " | " + p.textContent.substring(0, 90))
}
return res.join("\n")
Run with:
go run ./cmd/spacewave-debug/ eval --file .tmp/eval-{section}.js
Use the DOM Range API to determine where each line wraps at the rendered width:
var section = document.getElementById("section-id")
if (!section) return "no section"
var cards = section.querySelectorAll("p")
var res = []
for (var idx = 0; idx < cards.length; idx++) {
var p = cards[idx]
var text = p.textContent
var range = document.createRange()
var node = p.firstChild
if (!node) continue
var lines = []
var lastTop = -1
var lineStart = 0
for (var i = 0; i < text.length; i++) {
range.setStart(node, i)
range.setEnd(node, i + 1)
var r = range.getBoundingClientRect()
if (lastTop !== -1 && r.top > lastTop + 2) {
lines.push(text.substring(lineStart, i))
lineStart = i
}
lastTop = r.top
}
lines.push(text.substring(lineStart))
res.push("Card " + idx + " (" + lines.length + " lines):")
for (var j = 0; j < lines.length; j++) {
res.push(" L" + (j + 1) + ": [" + lines[j] + "]")
}
}
return res.join("\n")
Common layout issues to fix:
Adjust wording to fix issues. Strategies:
After each edit:
bun fecheck to bump rev and typecheckbun fecheck that types still pass@lg, @2xl) and viewport — always measure, never guess--file flag avoids shell quoting issues with complex eval scriptsreturn.tmp/ (gitignored) for reuse during the session