Repository navigation
v0.7.0
0.7.0
The biggest release in a while! Introduces a significant architectural overhaul for reduced memory footprint and slightly better performance (more on that in the migration guide below). New features include text justification, text decoration (underline, overline, and strikeout) and word-spacing.
Changed
- The layout APIs have changed. See the migration section for more info.
- Retained memory has been reduced greatly in pursuit of an extremely small memory footprint. There are a few properties left and a few more arrays to be merged, but dropflow is now very close to storing little more than needed to represent first principles. Objects that aren't needed to remember a layout are reconstructed on the fly, moving them from old generation to new generation memory which reduces GC churn. More on that here: https://chearon.net/blog/css-boxes-but-with-data-oriented-design/.
- Removed
staticLayoutContributionAPI - Text baseline coordinates are now rounded to match browsers and make underlines prettier
Added
- Support for
word-spacing - Support for
text-align: justify - Support for Node's
createObjectURLAPIs. Loading these URLs synchronously is not possible. The dropflowcreateObjectURLAPI can still be used for that. - Support for
currentColor - Support for
text-decoration
Fixed
- Several cases where glyph runs and inline backgrounds were not painted in logical order
- Trim lines after bidi reordering, not before
- Preserve zero-advance glyphs at the start or end of a paint boundary
- Don't skip painting text following a positioned inline within a positioned inline
- Text after a hard break could get painted on the previous line
- Arabic medials weren't preserved when breaking lines
- Tiny font files would not load correctly in Node 26
- Fixed synchronous loading of images and font buffers in non-SharedArrayBuffer environments
- Relatively positioned inline elements could infinite loop
Migration guide
The new APIs are fully documented in the README, but here's an overview of the changes.
The Big Flat Tree Refactor
The "Big Flat Tree" refactor has resulted in BlockContainer no longer being returned from the layout API.
flow.generateis nowflow.layout. The signature is(el: HTMLElement) => Layout.flow.layoutis nowflow.reflow. The signature is(layout: Layout, width: number, height: number) => void.
const el = flow.parse('hello');
-const blockContainer = flow.generate(el);
-flow.layout(blockContainer, 640, 480);
+const layout = flow.layout(el);
+flow.reflow(layout, 640, 480);The word "layout" is a noun in English, so it refers to the new container of layout boxes and fragments. For now, the layout only has one property, tree, which is where the old BlockContainer is located. The layout class will eventually contain flat lists of fragments and glyph runs as well, reducing memory footprint even further. The act of calculating layout is now called "reflow", which was borrowed from Firefox.
The Layout type can be imported from the API. You can use the root method to get the block container if you need to:
class Layout {
root(): BlockContainer;
}The Optimized BoxArea Refactor
Boxes have been optimized to only allocate a single BoxArea if no border or padding has been specified. If you're accessing areas at all, the API has changed:
-const bwidth = box.borderArea.width;
-const pwidth = box.paddingArea.width;
-const cwidth = box.contentArea.width;
+const bwidth = box.getBorderArea().width;
+const pwidth = box.getPaddingArea().width;
+const cwidth = box.getContentArea().width;