add multi-column layout support [breaking!] #63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First things first: this is a breaking change!
What is this about?
It is about making sure the polyfill also works nicely with the CSS Multi-column Layout Module (Level 1), for which the specification can be read here: https://www.w3.org/TR/css-multicol-1/
Browsers already offer multi-column support, but unfortunately this polyfill will break if columns are used.
The changes
This patch could also have been named: break content that overflows horizontally as well as vertically, instead of only checking vertical overflow
This is considered a breaking change: Previously content that overflowed a region horizontally was left intact and all but ignored by the algorithm. With this change that ends. If content overflows horizontally, the algorithm will extract the overflowing content and everything thereafter and (if possible) move it to the next region.
The reason for this is that when columns are activated in CSS*, content will no longer overflow vertically, but will instead overflow horizontally.
(*) Below is an example of how to split a region (or in this case, all regions) into 2 columns:
Safari
The way Safari has implemented Multi-column support means that the bounding rectangle for a split element (over two columns) remains intact (as if the content was not split at all). This would lead to the algorithm detecting vertical overflow and cutting off the content.
To prevent this from happening, we first check overflow without using bounding boxes, by simply comparing offsetHeight with scrollHeight and similarly for the width. The subsequent algorithm then checks each element's bounding rectangle only for the dimension(s) for which overflow was previously detected (could be both, try to prevent that!).
Bonus (future) support for additional break-before/after/inside-values
The polyfill does not support all possible values for
break-inside/before/after
. Unfortunately (up until this point in time) neither do browsers.However, when support for this will grow in browsers, more and more of this will just work for regions (that contain columns) as well. Since it is the browser that creates an additional column to the side (overflowing the right-side region-boundary), it is the browser's support for these CSS properties that will first be parsed, before this polyfill starts taking a look.
In effect that means that region-specific values will still be parsed by the region, but all others are first parsed by the browser's rendering-engine.