Commit a0c786f7 authored by Fred Chasen's avatar Fred Chasen

Remove poorly supported css break-*: column, handle with chunker

parent 50e20ed2
Pipeline #36 failed with stage
......@@ -212,7 +212,8 @@ class Chunker {
page.onOverflow((overflow) => {
_requestIdleCallback(() => {
let index = this.pages.indexOf(page) + 1;
if (this.pages[index].breakBefore || this.pages[index].previousBreakAfter) {
if (index < this.pages.length &&
(this.pages[index].breakBefore || this.pages[index].previousBreakAfter)) {
let newPage = this.insertPage(index - 1);
newPage.prepend(overflow);
} else if (index < this.pages.length) {
......
......@@ -6,7 +6,8 @@ import {
rebuildAncestors,
needsBreakBefore,
needsBreakAfter,
needsPreviousBreakAfter
needsPreviousBreakAfter,
needsPageBreak
} from "../utils/dom";
import EventEmitter from "event-emitter";
import Hook from "../utils/hook";
......@@ -55,6 +56,10 @@ class Layout {
return true;
}
if (node.style.display === "none") {
return false;
}
switch (node.tagName) {
// Inline
case "A":
......@@ -148,7 +153,7 @@ class Layout {
this.hooks.layoutNode.trigger(node);
// Check if the rendered element has a breakBefore set
if (hasContent && (needsBreakBefore(node) || needsPreviousBreakAfter(node))) {
if (hasContent && (needsBreakBefore(node) || needsPreviousBreakAfter(node) || needsPageBreak(node))) {
// Check for overflow
hasOverflow = this.hasOverflow();
......@@ -180,17 +185,20 @@ class Layout {
rendered = this.render(node, this.wrapper, breakToken, shallow);
// Only register element content
if (!hasContent && (node.nodeType === 1 || node.nodeType === 3)) {
hasContent = true;
if (!hasContent) {
// Only register visible content
if (rendered.nodeType === 1 && window.getComputedStyle(rendered).display !== "none") {
hasContent = true;
} else if (rendered.nodeType === 3 &&
rendered.textContent.trim().length &&
window.getComputedStyle(rendered.parentNode).display !== "none") {
hasContent = true;
}
}
if (!shallow) {
after = nodeAfter(node, content);
if (next) {
walker = walk(after, content);
}
walker = walk(after, content);
}
......@@ -238,7 +246,7 @@ class Layout {
}
hasOverflow() {
let width = Math.floor(this.wrapper.getBoundingClientRect().width); // or this.element.scrollWidth
let width = Math.max(Math.floor(this.wrapper.getBoundingClientRect().width), this.element.scrollWidth);
return this.width < width;
}
......
......@@ -88,6 +88,14 @@ class Breaks extends Handler {
if (nodeAfter) {
nodeAfter.setAttribute("data-previous-break-after", prop.value);
}
} else if (prop.property === "page") {
elements[i].setAttribute("data-page", prop.value);
let nodeAfter = elementAfter(elements[i], parsed);
if (nodeAfter) {
nodeAfter.setAttribute("data-after-page", prop.value);
}
} else {
elements[i].setAttribute("data-" + prop.property, prop.value);
}
......
......@@ -234,6 +234,7 @@ export default `
margin: unset;
}
/*
[data-page]:not([data-split-from]),
[data-break-before="page"]:not([data-split-from]),
[data-break-before="always"]:not([data-split-from]),
......@@ -242,7 +243,6 @@ export default `
[data-break-before="recto"]:not([data-split-from]),
[data-break-before="verso"]:not([data-split-from])
{
-webkit-column-break-before: always;
break-before: column;
}
......@@ -254,9 +254,9 @@ export default `
[data-break-after="recto"]:not([data-split-to]),
[data-break-after="verso"]:not([data-split-to])
{
-webkit-column-break-after: always;
break-after: column;
}
*/
.pagedjs_clear-after::after {
content: none !important;
......
......@@ -261,3 +261,14 @@ export function needsPreviousBreakAfter(node) {
return false;
}
export function needsPageBreak(node) {
if( typeof node !== "undefined" &&
typeof node.dataset !== "undefined" &&
(node.dataset.page || node.dataset.afterPage)
) {
return true;
}
return false;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment