Commit 93ff260f authored by Fred Chasen's avatar Fred Chasen

Merge branch 'counter-page-reset' into 'master'

[#91] Fixes for reset on page counter

See merge request !128
parents 0284465c c04aa164
Pipeline #559 passed with stage
in 4 minutes and 21 seconds
......@@ -9899,7 +9899,7 @@
"dependencies": {
"jsesc": {
"version": "0.5.0",
"resolved": "http://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz",
"integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=",
"dev": true
}
......@@ -11006,7 +11006,7 @@
},
"through": {
"version": "2.3.8",
"resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
"dev": true
},
......
This diff is collapsed.
const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe("counter-page", () => {
let page;
beforeAll(async () => {
page = await loadPage("counters/counter-page-reset/counter-page-reset.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(1);
expect(pdf).toMatchPDFSnapshot(3);
});
}
}
);
......@@ -39,7 +39,7 @@
}
.start {
counter-reset: page;
counter-reset: page 1;
}
......
......@@ -100,17 +100,21 @@ class Counters extends Handler {
counter = this.counters[c];
this.processCounterIncrements(parsed, counter);
this.processCounterResets(parsed, counter);
this.addCounterValues(parsed, counter);
if (c !== "page") {
this.addCounterValues(parsed, counter);
}
}
}
scopeCounters(counters) {
let countersArray = [];
for (let c in counters) {
countersArray.push(`${counters[c].name} 0`);
if(c !== "page") {
countersArray.push(`${counters[c].name} 0`);
}
}
// Add to pages to allow cross page scope
this.insertRule(`.pagedjs_pages { counter-reset: ${countersArray.join(" ")} pages var(--pagedjs-page-count)}`);
this.insertRule(`.pagedjs_pages { counter-reset: ${countersArray.join(" ")} page 0 pages var(--pagedjs-page-count)}`);
}
insertRule(rule) {
......@@ -215,8 +219,8 @@ class Counters extends Handler {
afterPageLayout(pageElement, page) {
let pgreset = pageElement.querySelectorAll("[data-counter-page-reset]");
pgreset.forEach((reset) => {
let value = reset.datasetCounterPageReset;
this.styleSheet.insertRule(`[data-page-number="${pageElement.dataset.pageNumber}"] { counter-reset: page ${value} }`, this.styleSheet.cssRules.length);
let value = reset.dataset.counterPageReset;
this.styleSheet.insertRule(`[data-page-number="${pageElement.dataset.pageNumber}"] { counter-increment: none; counter-reset: page ${value}; }`, this.styleSheet.cssRules.length);
});
}
......
......@@ -384,13 +384,11 @@ export default `
}
.pagedjs_page.pagedjs_right_page {
counter-increment: page var(--pagedjs-page-counter-increment);
width: var(--pagedjs-width-right);
height: var(--pagedjs-height-right);
}
.pagedjs_page.pagedjs_left_page {
counter-increment: page var(--pagedjs-page-counter-increment);
width: var(--pagedjs-width-left);
height: var(--pagedjs-height-left);
}
......
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