Repository navigation
Description
I compared box positions against Chrome, using the Ahem font from assets/ so text metrics match exactly. The repros below are minimized. Setup shared by all of them:
// npm i dropflow@0.8.2 (ESM; AHEM = path to dropflow's assets/Ahem/Ahem.ttf)
import * as flow from "dropflow"
import parse from "dropflow/parse.js"
flow.fonts.add(new flow.FontFace("Ahem", new URL(`file://${process.env.AHEM}`)))
function box(html, sel) {
const root = parse(html); flow.loadSync(root)
const layout = flow.layout(root); flow.reflow(layout, 300, 500)
const a = root.query(sel).boxes[0].getBorderArea()
return [a.x, a.y, a.width, a.height]
}1. reflow never returns. This is a block with a fixed height, text that wraps past that height, an empty float at the end, and an overlong word after the block.
const root = parse(`<div style="width:50px;font:10px Ahem">
<div style="height:17px">XXX XXX XXXXXXXX<div style="float:right"></div></div>XXXXXXXX
</div>`)
flow.loadSync(root)
flow.reflow(flow.layout(root), 300, 500) // spins at 100% CPU foreverDropping the height, the float, or the last word makes it finish. A sized float (width:10px;height:10px) hangs too. This looks different from #35 (that one is an assertion inside an inline).
2. A percentage or unitless number that starts with 0 throws away the entire style attribute. In parse-css.pegjs, LENGTH ends with the alternative '0', which matches the leading 0 of 0%, 0.5% or 0.5 before PERCENTAGE or NUMBER gets a chance. The declaration then fails, and every other declaration in the attribute is lost with it.
box('<div id=b style="width:50%;height:52px;margin-left:24px"></div>', "#b") // [24, 0, 150, 52]
box('<div id=b style="width:0.5%;height:52px;margin-left:24px"></div>', "#b") // [0, 0, 300, 0]
box('<div id=b style="line-height:0.5;height:52px;margin-left:24px"></div>', "#b") // [0, 0, 300, 0]Expected: [24, 0, 1.5, 52] and [24, 0, 276, 52]. Also affected: width:0%, margin-top:0%, padding:0% 10px.
3. A flow-root is too tall when its last descendant's margin is blocked by padding or a border. The children are positioned correctly. But the BFC root's auto height adds the inner margin a second time, which pushes the next sibling down.
box('<div style="display:flow-root"><div style="border-top:1px solid;padding-bottom:8px">' +
'<div style="margin-top:20px"></div></div></div><div id=n style="height:10px"></div>', "#n")
// [0, 49, 300, 10], Chrome: [0, 29, 300, 10]Per CSS 2.1 §8.3.1, the 20px margin doesn't adjoin anything outside the padded box. §10.6.7 puts the flow-root's bottom at the padded box's bottom margin edge (29px).
4. clear adds clearance when there are no floats.
box('<div style="display:flow-root"><div id=b style="clear:left;margin-top:-7px;height:10px"></div></div>', "#b")
// [0, 0, 300, 10], Chrome: [0, -7, 300, 10]CSS 2.1 §9.5.2 only introduces clearance when the box would otherwise not be past a relevant float. Without clear, dropflow gives -7 correctly.
5. An empty inline with padding ignores its own line-height.
box('<div id=r style="font:10px/10px Ahem"><span style="line-height:20px;padding-left:5px"></span></div>', "#r")
// height 10, Chrome: 20An inline with non-zero padding is not a phantom box (§9.4.2), so its line-height should contribute to the line box (§10.8). The same span with text gives 20 in dropflow.
Version: dropflow@0.8.2, also on master db398ef (same as 0.8.2).
Credit: https://ucsbplse.github.io/
Activity