diff --git a/.gitignore b/.gitignore index df050b03cc111bcba1ba6ce6296a546dc2a02062..d5c3a9a4a198fb1f05c804a0b25f745f1bdb5c51 100755 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules dist lib __diff_output__ +specs/**/*.pdf diff --git a/specs/breaks/break-after/break-after-left/breaks-after-left.pdf b/specs/breaks/break-after/break-after-left/breaks-after-left.pdf deleted file mode 100644 index d17ebccb3dabc3af518e097482653f4f10660b10..0000000000000000000000000000000000000000 Binary files a/specs/breaks/break-after/break-after-left/breaks-after-left.pdf and /dev/null differ diff --git a/specs/breaks/break-after/break-after-page/breaks-after-page.pdf b/specs/breaks/break-after/break-after-page/breaks-after-page.pdf deleted file mode 100644 index 999187d8aefd41964b8aaab4bb3a7bb1e06d0813..0000000000000000000000000000000000000000 Binary files a/specs/breaks/break-after/break-after-page/breaks-after-page.pdf and /dev/null differ diff --git a/specs/breaks/break-after/break-after-right/breaks-after-right.pdf b/specs/breaks/break-after/break-after-right/breaks-after-right.pdf deleted file mode 100644 index 4966c524b6e372795d2abb478286a2b10645574c..0000000000000000000000000000000000000000 Binary files a/specs/breaks/break-after/break-after-right/breaks-after-right.pdf and /dev/null differ diff --git a/specs/breaks/break-before/break-before-left/breaks-before-left.pdf b/specs/breaks/break-before/break-before-left/breaks-before-left.pdf deleted file mode 100644 index d3ad4f088ae8c4d22adee9f72ca972e75c490da5..0000000000000000000000000000000000000000 Binary files a/specs/breaks/break-before/break-before-left/breaks-before-left.pdf and /dev/null differ diff --git a/specs/breaks/break-before/break-before-page/breaks-before-page.pdf b/specs/breaks/break-before/break-before-page/breaks-before-page.pdf deleted file mode 100644 index 11d7defc50990ae8b5507b934281bee830a02360..0000000000000000000000000000000000000000 Binary files a/specs/breaks/break-before/break-before-page/breaks-before-page.pdf and /dev/null differ diff --git a/specs/breaks/break-before/break-before-right/breaks-before-right.pdf b/specs/breaks/break-before/break-before-right/breaks-before-right.pdf deleted file mode 100644 index 8692871b37533ea38198900ddfb0edfadd271029..0000000000000000000000000000000000000000 Binary files a/specs/breaks/break-before/break-before-right/breaks-before-right.pdf and /dev/null differ diff --git a/specs/breaks/breaks.pdf b/specs/breaks/breaks.pdf deleted file mode 100644 index f1767e1c361595726772b91b2b9ed20517357cdf..0000000000000000000000000000000000000000 Binary files a/specs/breaks/breaks.pdf and /dev/null differ diff --git a/specs/counters/counter-page/counter-page.pdf b/specs/counters/counter-page/counter-page.pdf deleted file mode 100644 index 0f5b51cf64adecd9dc06f337f7c7f6a597dd6568..0000000000000000000000000000000000000000 Binary files a/specs/counters/counter-page/counter-page.pdf and /dev/null differ diff --git a/specs/counters/counter-pages/counter-pages.pdf b/specs/counters/counter-pages/counter-pages.pdf deleted file mode 100644 index 992bf3ffbbb23e0e97a8a40d677c041f4f3bba47..0000000000000000000000000000000000000000 Binary files a/specs/counters/counter-pages/counter-pages.pdf and /dev/null differ diff --git a/specs/default/default.pdf b/specs/default/default.pdf deleted file mode 100644 index e1116759faa9d93aa4890c8ce8e2bc5ec58e4d99..0000000000000000000000000000000000000000 Binary files a/specs/default/default.pdf and /dev/null differ diff --git a/specs/issues/duplicate-headers/__image_snapshots__/duplicate-headers-spec-js-duplicate-headers-should-create-a-pdf-1-snap.png b/specs/issues/duplicate-headers/__image_snapshots__/duplicate-headers-spec-js-duplicate-headers-should-create-a-pdf-1-snap.png new file mode 100644 index 0000000000000000000000000000000000000000..ef39653be5bdb1174c4fbbd61264e56f7dc70ee7 Binary files /dev/null and b/specs/issues/duplicate-headers/__image_snapshots__/duplicate-headers-spec-js-duplicate-headers-should-create-a-pdf-1-snap.png differ diff --git a/specs/issues/duplicate-headers/__image_snapshots__/duplicate-headers-spec-js-duplicate-headers-should-create-a-pdf-2-snap.png b/specs/issues/duplicate-headers/__image_snapshots__/duplicate-headers-spec-js-duplicate-headers-should-create-a-pdf-2-snap.png new file mode 100644 index 0000000000000000000000000000000000000000..b2ffc0c8d34b0be8df1b28bff2cb5d74d621ecb7 Binary files /dev/null and b/specs/issues/duplicate-headers/__image_snapshots__/duplicate-headers-spec-js-duplicate-headers-should-create-a-pdf-2-snap.png differ diff --git a/specs/issues/duplicate-headers/__image_snapshots__/duplicate-headers-spec-js-duplicate-headers-should-create-a-pdf-3-snap.png b/specs/issues/duplicate-headers/__image_snapshots__/duplicate-headers-spec-js-duplicate-headers-should-create-a-pdf-3-snap.png new file mode 100644 index 0000000000000000000000000000000000000000..190854ff726e7f4f523f7ccd9e005ce53cde6256 Binary files /dev/null and b/specs/issues/duplicate-headers/__image_snapshots__/duplicate-headers-spec-js-duplicate-headers-should-create-a-pdf-3-snap.png differ diff --git a/specs/issues/duplicate-headers/duplicate-headers.html b/specs/issues/duplicate-headers/duplicate-headers.html new file mode 100644 index 0000000000000000000000000000000000000000..863de6153dd784e49ee7c85c88bb2148e27df8df --- /dev/null +++ b/specs/issues/duplicate-headers/duplicate-headers.html @@ -0,0 +1,193 @@ + + + + + + + Issue #XX + + + + + + + + + + + + + + + +
+

Chapter 1: Lorem ipsum dolor sit amet

+

chapter

+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi non suscipit odio. Aenean ut ligula id mauris efficitur tincidunt vitae non leo. In convallis convallis leo, eget molestie metus imperdiet eu. Praesent pharetra, leo a laoreet mattis, ligula nisl commodo ante, non vestibulum nisi lacus eget magna. Maecenas scelerisque nibh ac felis egestas, egestas elementum risus pellentesque. Nulla iaculis ut leo a iaculis. Donec vel sodales dolor, vel fringilla elit. Vivamus aliquam diam eu maximus elementum. Integer eu urna at felis fermentum hendrerit. +

+

+ Nulla dignissim pellentesque magna ac maximus. Integer id tincidunt erat. Sed elementum posuere augue, quis pharetra mi vehicula in. Nullam rhoncus mi quis lectus gravida dignissim. Pellentesque a tortor ut leo pretium auctor non in massa. Nunc efficitur vestibulum mi, id mattis quam aliquet id. Ut semper tortor sit amet molestie mattis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec laoreet eleifend purus ut sagittis. Nunc consequat vel sapien at convallis. Maecenas sollicitudin quis justo non varius. +

+

+ Maecenas arcu massa, egestas vel est nec, mollis venenatis tortor. Ut eu finibus libero. Phasellus pharetra ante a purus ornare, eget facilisis sem ultricies. Etiam tincidunt feugiat erat, eget hendrerit turpis ullamcorper quis. Fusce finibus porttitor nisi sed blandit. Nunc libero erat, vehicula ut tincidunt quis, maximus vitae eros. Donec tristique urna bibendum, mattis nisl vel, dignissim nisl. Duis tincidunt eros nec volutpat scelerisque. Phasellus id malesuada nulla. Duis aliquam mi non malesuada suscipit. Curabitur pretium nisl eu tortor tempus, et sollicitudin quam iaculis. Ut venenatis eros ligula, in ornare eros facilisis vel. +

+

+ Donec auctor libero a lorem egestas consequat. Cras ac lacinia ipsum. Donec non elementum purus, et porta eros. Cras ullamcorper mi eu semper aliquam. Duis magna ipsum, auctor at leo non, pharetra luctus felis. Ut tempus finibus dui, sit amet scelerisque nisi feugiat non. Proin posuere quam vitae finibus pulvinar. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum id felis at nulla mollis bibendum. +

+

+ Donec odio lacus, maximus a ultrices non, pulvinar eget nunc. Morbi cursus eget enim eleifend tincidunt. In vel odio gravida, hendrerit diam ut, fringilla urna. Aenean sit amet nisi ut nisl placerat bibendum. Aenean consequat dapibus orci non accumsan. In imperdiet leo lectus, vitae euismod quam egestas et. Donec augue mauris, malesuada ac nunc dapibus, faucibus malesuada velit. Vivamus quis enim eget orci sollicitudin ultrices. Duis ut nulla velit. Donec feugiat quam nec sem cursus, vel feugiat nunc fringilla. +

+
+
+

Chapter 2: Praesent placerat lectus

+

chapter left

+ +

+ Praesent placerat lectus ac mauris rhoncus, eget iaculis nisl molestie. Etiam posuere luctus ligula quis ornare. Duis semper lectus vel bibendum dapibus. Morbi a lacus eget augue sagittis euismod. Aliquam non leo quis dui bibendum viverra eu vel erat. Fusce iaculis vulputate leo, sit amet laoreet eros aliquam a. Sed id tellus at ligula porttitor pharetra. Morbi non fringilla augue. Cras sodales egestas mi, et porta orci ultricies sed. Sed et nulla a ligula aliquet accumsan non eleifend quam. Aliquam pellentesque, justo vel interdum accumsan, purus ipsum porttitor lectus, ac luctus risus lectus nec lectus. Cras ut augue condimentum, egestas nisi in, dictum erat. Nullam tincidunt tincidunt tempor. Sed in eleifend nibh, sit amet feugiat nisi. Cras at ante ut urna sagittis dictum ut nec elit. +

+

+ In feugiat euismod massa sagittis dictum. Nullam eu nisl eu elit laoreet tincidunt id sed ligula. Praesent vulputate faucibus nibh, ut ultrices nunc aliquam nec. Mauris et condimentum ligula. Vestibulum nec tortor quis urna dictum luctus. Cras quis suscipit metus. Ut dignissim ullamcorper aliquam. Donec condimentum eu tellus at interdum. +

+

+ Proin eu quam id arcu interdum laoreet nec at urna. Vivamus non sem quis dolor sagittis facilisis. Nunc quis urna non neque sollicitudin hendrerit. Vestibulum odio velit, vestibulum vitae elementum convallis, tristique eu est. Sed vitae tortor sed purus accumsan euismod nec finibus lorem. Donec consectetur libero sit amet pretium eleifend. Nulla placerat ipsum sed eros aliquet, at venenatis purus convallis. Pellentesque pulvinar, justo eget tincidunt semper, augue massa placerat enim, non tempus quam erat eu orci. Suspendisse auctor consectetur lectus, a mattis odio. Pellentesque id sem sit amet justo fringilla bibendum id sit amet quam. Vivamus ex est, ultrices non pharetra eu, facilisis nec quam. +

+

+ Etiam molestie sed orci sed suscipit. Donec ipsum est, venenatis ut nisl ut, viverra auctor diam. Cras vestibulum lacus vel nunc dapibus aliquam. Aliquam accumsan lorem rhoncus tortor rhoncus, ut euismod sapien ullamcorper. Vivamus et dictum lacus, eu pellentesque dolor. Suspendisse potenti. Mauris vitae volutpat odio. Duis vitae purus nec enim posuere efficitur at vitae nisl. Etiam enim nisl, rutrum in vestibulum nec, dapibus ut dui. Pellentesque imperdiet molestie ante quis feugiat. Sed nec felis congue, cursus ligula eget, bibendum est. Proin mattis, tortor non lobortis lobortis, nibh quam aliquam neque, sed tristique nibh ex aliquet felis. Phasellus non augue ac ante efficitur consectetur at at est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nullam dui enim, iaculis et felis ac, porta ullamcorper justo. Suspendisse potenti. +

+
+
+

Chapter 3: Aliquam eget massa loborti

+

+ Aliquam eget massa lobortis, maximus leo ac, iaculis quam. Sed non aliquet eros. Integer ultrices consequat tortor eget ullamcorper. Integer quis justo dignissim, porttitor urna sed, faucibus ex. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur elit tortor, pharetra eu nisl vitae, placerat tempus lorem. Praesent rhoncus venenatis sodales. Cras tempor tempus lacus et pharetra. Phasellus at nulla sed ligula gravida hendrerit. Sed lorem tortor, consectetur id tempus eget, accumsan at eros. +

+

+ Aliquam erat volutpat. Aenean ornare elit magna, et efficitur massa dapibus sit amet. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus ultricies posuere magna. Vestibulum placerat ligula bibendum tempus viverra. Morbi et magna eleifend, scelerisque justo ut, suscipit enim. Vestibulum ex arcu, dictum ut ligula feugiat, fringilla feugiat dui. Aenean velit nisi, consectetur eu mi quis, sollicitudin elementum mauris. Phasellus condimentum eu magna nec sollicitudin. Morbi sed velit mollis, aliquam libero vel, rutrum sapien. Etiam sit amet turpis tincidunt, euismod justo eget, pretium leo. Quisque a blandit justo. Proin dolor leo, semper non rhoncus sit amet, varius ac erat. Donec in lacus nec purus iaculis posuere eget et ligula. +

+

+ Vivamus vel velit vel metus bibendum luctus ut vitae tortor. Nullam at ante eu felis ultrices ultrices at in diam. Pellentesque eleifend leo sapien, vel commodo orci mollis vel. Phasellus placerat fermentum odio. Cras placerat posuere risus et consectetur. Fusce dictum faucibus est quis imperdiet. Ut tristique, enim ultrices scelerisque imperdiet, ex mauris pellentesque arcu, sit amet mattis lacus purus in ligula. Vestibulum rhoncus dapibus orci, sit amet volutpat turpis semper ullamcorper. Nullam tincidunt lacus vel purus molestie fermentum. Fusce dapibus pulvinar vehicula. Pellentesque tempor elementum fermentum. Nunc ex erat, gravida sit amet dictum at, semper ut mi. Vestibulum pulvinar congue eros id faucibus. In non tellus et mi egestas aliquet id non dolor. +

+

+ Nam eros tellus, hendrerit ut rhoncus sed, aliquet et felis. Cras a ex malesuada, fringilla magna elementum, cursus purus. Etiam fringilla leo non diam congue tempor. Ut laoreet, est eget blandit congue, mauris magna cursus sapien, dictum tempus sapien diam et dolor. Vestibulum vel egestas velit. Pellentesque vel consectetur urna, eu consequat odio. Sed ac pretium magna, ut ultrices tortor. +

+
+ + diff --git a/specs/issues/duplicate-headers/duplicate-headers.spec.js b/specs/issues/duplicate-headers/duplicate-headers.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..f5e9b331727d25808ecf2a5cc41cf57c97e1c13c --- /dev/null +++ b/specs/issues/duplicate-headers/duplicate-headers.spec.js @@ -0,0 +1,53 @@ +const TIMEOUT = 10000; + +describe('duplicate-headers', async () => { + let page; + let rendered; + beforeAll(async () => { + page = await loadPage('issues/duplicate-headers/duplicate-headers.html') + return page.rendered; + }, TIMEOUT) + + afterAll(async () => { + if (!DEBUG) { + await page.close(); + } + }) + + it('should render 6 pages', async () => { + let pages = await page.$$eval(".pagedjs_page", (r) => { + return r.length; + }); + + expect(pages).toEqual(6); + }) + + it('page 1 header should be "chapter"', async () => { + let text = await page.$eval("[data-page-number='1'] .pagedjs_margin-top-left > .pagedjs_margin-content", (r) => r.textContent); + + expect(text).toContain('chapter'); + }) + + it('page 3 header should be "chapter nth"', async () => { + let text = await page.$eval("[data-page-number='3'] .pagedjs_margin-top-left > .pagedjs_margin-content", (r) => r.textContent); + + expect(text).toContain('chapter nth'); + }) + + it('page 4 header should be "chapter left"', async () => { + let text = await page.$eval("[data-page-number='4'] .pagedjs_margin-top-left > .pagedjs_margin-content", (r) => r.textContent); + + expect(text).toContain('chapter left'); + }) + + if (!DEBUG) { + it('should create a pdf', async () => { + let pdf = await page.pdf(PDF_SETTINGS); + + expect(pdf).toMatchPDFSnapshot(1); + expect(pdf).toMatchPDFSnapshot(3); + expect(pdf).toMatchPDFSnapshot(4); + }) + } + } +) diff --git a/specs/issues/template/issue.html b/specs/issues/template/issue.html new file mode 100644 index 0000000000000000000000000000000000000000..863de6153dd784e49ee7c85c88bb2148e27df8df --- /dev/null +++ b/specs/issues/template/issue.html @@ -0,0 +1,193 @@ + + + + + + + Issue #XX + + + + + + + + + + + + + + + +
+

Chapter 1: Lorem ipsum dolor sit amet

+

chapter

+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi non suscipit odio. Aenean ut ligula id mauris efficitur tincidunt vitae non leo. In convallis convallis leo, eget molestie metus imperdiet eu. Praesent pharetra, leo a laoreet mattis, ligula nisl commodo ante, non vestibulum nisi lacus eget magna. Maecenas scelerisque nibh ac felis egestas, egestas elementum risus pellentesque. Nulla iaculis ut leo a iaculis. Donec vel sodales dolor, vel fringilla elit. Vivamus aliquam diam eu maximus elementum. Integer eu urna at felis fermentum hendrerit. +

+

+ Nulla dignissim pellentesque magna ac maximus. Integer id tincidunt erat. Sed elementum posuere augue, quis pharetra mi vehicula in. Nullam rhoncus mi quis lectus gravida dignissim. Pellentesque a tortor ut leo pretium auctor non in massa. Nunc efficitur vestibulum mi, id mattis quam aliquet id. Ut semper tortor sit amet molestie mattis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec laoreet eleifend purus ut sagittis. Nunc consequat vel sapien at convallis. Maecenas sollicitudin quis justo non varius. +

+

+ Maecenas arcu massa, egestas vel est nec, mollis venenatis tortor. Ut eu finibus libero. Phasellus pharetra ante a purus ornare, eget facilisis sem ultricies. Etiam tincidunt feugiat erat, eget hendrerit turpis ullamcorper quis. Fusce finibus porttitor nisi sed blandit. Nunc libero erat, vehicula ut tincidunt quis, maximus vitae eros. Donec tristique urna bibendum, mattis nisl vel, dignissim nisl. Duis tincidunt eros nec volutpat scelerisque. Phasellus id malesuada nulla. Duis aliquam mi non malesuada suscipit. Curabitur pretium nisl eu tortor tempus, et sollicitudin quam iaculis. Ut venenatis eros ligula, in ornare eros facilisis vel. +

+

+ Donec auctor libero a lorem egestas consequat. Cras ac lacinia ipsum. Donec non elementum purus, et porta eros. Cras ullamcorper mi eu semper aliquam. Duis magna ipsum, auctor at leo non, pharetra luctus felis. Ut tempus finibus dui, sit amet scelerisque nisi feugiat non. Proin posuere quam vitae finibus pulvinar. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum id felis at nulla mollis bibendum. +

+

+ Donec odio lacus, maximus a ultrices non, pulvinar eget nunc. Morbi cursus eget enim eleifend tincidunt. In vel odio gravida, hendrerit diam ut, fringilla urna. Aenean sit amet nisi ut nisl placerat bibendum. Aenean consequat dapibus orci non accumsan. In imperdiet leo lectus, vitae euismod quam egestas et. Donec augue mauris, malesuada ac nunc dapibus, faucibus malesuada velit. Vivamus quis enim eget orci sollicitudin ultrices. Duis ut nulla velit. Donec feugiat quam nec sem cursus, vel feugiat nunc fringilla. +

+
+
+

Chapter 2: Praesent placerat lectus

+

chapter left

+ +

+ Praesent placerat lectus ac mauris rhoncus, eget iaculis nisl molestie. Etiam posuere luctus ligula quis ornare. Duis semper lectus vel bibendum dapibus. Morbi a lacus eget augue sagittis euismod. Aliquam non leo quis dui bibendum viverra eu vel erat. Fusce iaculis vulputate leo, sit amet laoreet eros aliquam a. Sed id tellus at ligula porttitor pharetra. Morbi non fringilla augue. Cras sodales egestas mi, et porta orci ultricies sed. Sed et nulla a ligula aliquet accumsan non eleifend quam. Aliquam pellentesque, justo vel interdum accumsan, purus ipsum porttitor lectus, ac luctus risus lectus nec lectus. Cras ut augue condimentum, egestas nisi in, dictum erat. Nullam tincidunt tincidunt tempor. Sed in eleifend nibh, sit amet feugiat nisi. Cras at ante ut urna sagittis dictum ut nec elit. +

+

+ In feugiat euismod massa sagittis dictum. Nullam eu nisl eu elit laoreet tincidunt id sed ligula. Praesent vulputate faucibus nibh, ut ultrices nunc aliquam nec. Mauris et condimentum ligula. Vestibulum nec tortor quis urna dictum luctus. Cras quis suscipit metus. Ut dignissim ullamcorper aliquam. Donec condimentum eu tellus at interdum. +

+

+ Proin eu quam id arcu interdum laoreet nec at urna. Vivamus non sem quis dolor sagittis facilisis. Nunc quis urna non neque sollicitudin hendrerit. Vestibulum odio velit, vestibulum vitae elementum convallis, tristique eu est. Sed vitae tortor sed purus accumsan euismod nec finibus lorem. Donec consectetur libero sit amet pretium eleifend. Nulla placerat ipsum sed eros aliquet, at venenatis purus convallis. Pellentesque pulvinar, justo eget tincidunt semper, augue massa placerat enim, non tempus quam erat eu orci. Suspendisse auctor consectetur lectus, a mattis odio. Pellentesque id sem sit amet justo fringilla bibendum id sit amet quam. Vivamus ex est, ultrices non pharetra eu, facilisis nec quam. +

+

+ Etiam molestie sed orci sed suscipit. Donec ipsum est, venenatis ut nisl ut, viverra auctor diam. Cras vestibulum lacus vel nunc dapibus aliquam. Aliquam accumsan lorem rhoncus tortor rhoncus, ut euismod sapien ullamcorper. Vivamus et dictum lacus, eu pellentesque dolor. Suspendisse potenti. Mauris vitae volutpat odio. Duis vitae purus nec enim posuere efficitur at vitae nisl. Etiam enim nisl, rutrum in vestibulum nec, dapibus ut dui. Pellentesque imperdiet molestie ante quis feugiat. Sed nec felis congue, cursus ligula eget, bibendum est. Proin mattis, tortor non lobortis lobortis, nibh quam aliquam neque, sed tristique nibh ex aliquet felis. Phasellus non augue ac ante efficitur consectetur at at est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nullam dui enim, iaculis et felis ac, porta ullamcorper justo. Suspendisse potenti. +

+
+
+

Chapter 3: Aliquam eget massa loborti

+

+ Aliquam eget massa lobortis, maximus leo ac, iaculis quam. Sed non aliquet eros. Integer ultrices consequat tortor eget ullamcorper. Integer quis justo dignissim, porttitor urna sed, faucibus ex. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur elit tortor, pharetra eu nisl vitae, placerat tempus lorem. Praesent rhoncus venenatis sodales. Cras tempor tempus lacus et pharetra. Phasellus at nulla sed ligula gravida hendrerit. Sed lorem tortor, consectetur id tempus eget, accumsan at eros. +

+

+ Aliquam erat volutpat. Aenean ornare elit magna, et efficitur massa dapibus sit amet. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus ultricies posuere magna. Vestibulum placerat ligula bibendum tempus viverra. Morbi et magna eleifend, scelerisque justo ut, suscipit enim. Vestibulum ex arcu, dictum ut ligula feugiat, fringilla feugiat dui. Aenean velit nisi, consectetur eu mi quis, sollicitudin elementum mauris. Phasellus condimentum eu magna nec sollicitudin. Morbi sed velit mollis, aliquam libero vel, rutrum sapien. Etiam sit amet turpis tincidunt, euismod justo eget, pretium leo. Quisque a blandit justo. Proin dolor leo, semper non rhoncus sit amet, varius ac erat. Donec in lacus nec purus iaculis posuere eget et ligula. +

+

+ Vivamus vel velit vel metus bibendum luctus ut vitae tortor. Nullam at ante eu felis ultrices ultrices at in diam. Pellentesque eleifend leo sapien, vel commodo orci mollis vel. Phasellus placerat fermentum odio. Cras placerat posuere risus et consectetur. Fusce dictum faucibus est quis imperdiet. Ut tristique, enim ultrices scelerisque imperdiet, ex mauris pellentesque arcu, sit amet mattis lacus purus in ligula. Vestibulum rhoncus dapibus orci, sit amet volutpat turpis semper ullamcorper. Nullam tincidunt lacus vel purus molestie fermentum. Fusce dapibus pulvinar vehicula. Pellentesque tempor elementum fermentum. Nunc ex erat, gravida sit amet dictum at, semper ut mi. Vestibulum pulvinar congue eros id faucibus. In non tellus et mi egestas aliquet id non dolor. +

+

+ Nam eros tellus, hendrerit ut rhoncus sed, aliquet et felis. Cras a ex malesuada, fringilla magna elementum, cursus purus. Etiam fringilla leo non diam congue tempor. Ut laoreet, est eget blandit congue, mauris magna cursus sapien, dictum tempus sapien diam et dolor. Vestibulum vel egestas velit. Pellentesque vel consectetur urna, eu consequat odio. Sed ac pretium magna, ut ultrices tortor. +

+
+ + diff --git a/specs/issues/template/issue.spec.js b/specs/issues/template/issue.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..c682e716f083d581d1999c9b3bcf74d585ae9dc8 --- /dev/null +++ b/specs/issues/template/issue.spec.js @@ -0,0 +1,34 @@ +const TIMEOUT = 10000; + +describe('issue', async () => { + let page; + let rendered; + beforeAll(async () => { + page = await loadPage('issues/template/template.html') + return page.rendered; + }, TIMEOUT) + + afterAll(async () => { + if (!DEBUG) { + await page.close(); + } + }) + + xit('should render 6 pages', async () => { + let pages = await page.$$eval(".pagedjs_page", (r) => { + return r.length; + }); + + expect(pages).toEqual(6); + }) + + + if (!DEBUG) { + xit('should create a pdf', async () => { + let pdf = await page.pdf(PDF_SETTINGS); + + expect(pdf).toMatchPDFSnapshot(1); + }) + } + } +) diff --git a/specs/media/print/print.pdf b/specs/media/print/print.pdf deleted file mode 100644 index fe3c49c9490c03596ed03a422bfa85e17ce87cd4..0000000000000000000000000000000000000000 Binary files a/specs/media/print/print.pdf and /dev/null differ diff --git a/specs/named-page/named-page/named-page.html b/specs/named-page/named-page/named-page.html index b74c799d91ea4499e209d8ea2ba5cdd659d1c961..e224439f326a0a5a84e53543c6a00653604da506 100644 --- a/specs/named-page/named-page/named-page.html +++ b/specs/named-page/named-page/named-page.html @@ -17,7 +17,6 @@ @page { size: A5; margin: 20mm 20mm; - /* border: solid 1px black; */ @bottom-left{ content: counter(page); } diff --git a/specs/named-page/named-page/named-page.pdf b/specs/named-page/named-page/named-page.pdf deleted file mode 100644 index 68d00ee06e0ab67a5b8c74b0b26dc16a1b6911f1..0000000000000000000000000000000000000000 Binary files a/specs/named-page/named-page/named-page.pdf and /dev/null differ diff --git a/specs/named-page/page-group/page-group.pdf b/specs/named-page/page-group/page-group.pdf deleted file mode 100644 index 3786dec3dc4a6bff10f596ddf8dc4ece626564b3..0000000000000000000000000000000000000000 Binary files a/specs/named-page/page-group/page-group.pdf and /dev/null differ diff --git a/specs/page-rules/size/length/length.pdf b/specs/page-rules/size/length/length.pdf deleted file mode 100644 index e9cad154f9bb1324e3ce4392665a350a17397830..0000000000000000000000000000000000000000 Binary files a/specs/page-rules/size/length/length.pdf and /dev/null differ diff --git a/specs/page-rules/size/page-size/page-size.pdf b/specs/page-rules/size/page-size/page-size.pdf deleted file mode 100644 index a5a6875539793b4b628bc7a0c401e39472201952..0000000000000000000000000000000000000000 Binary files a/specs/page-rules/size/page-size/page-size.pdf and /dev/null differ diff --git a/specs/page-selector/blank-page/blank-page.pdf b/specs/page-selector/blank-page/blank-page.pdf deleted file mode 100644 index ef5d88a41a1cce781cb98d149407d0113fba86bc..0000000000000000000000000000000000000000 Binary files a/specs/page-selector/blank-page/blank-page.pdf and /dev/null differ diff --git a/specs/page-selector/first-page/first-page.pdf b/specs/page-selector/first-page/first-page.pdf deleted file mode 100644 index 2a043b3f0a1815781d6e112d8e543afc0f6e0240..0000000000000000000000000000000000000000 Binary files a/specs/page-selector/first-page/first-page.pdf and /dev/null differ diff --git a/specs/page-selector/page-group/first-page-of-page-group/first-page-of-page-group.pdf b/specs/page-selector/page-group/first-page-of-page-group/first-page-of-page-group.pdf deleted file mode 100644 index f56ad957272c66505db0c6f2c04dd7da284b2d59..0000000000000000000000000000000000000000 Binary files a/specs/page-selector/page-group/first-page-of-page-group/first-page-of-page-group.pdf and /dev/null differ diff --git a/specs/page-selector/page-group/spread-of-page-group/spread-of-page-group.pdf b/specs/page-selector/page-group/spread-of-page-group/spread-of-page-group.pdf deleted file mode 100644 index e1fff5171c4da269ee738971fe91ab15ccdc8ba6..0000000000000000000000000000000000000000 Binary files a/specs/page-selector/page-group/spread-of-page-group/spread-of-page-group.pdf and /dev/null differ diff --git a/specs/page-selector/page-nth/page-nth.pdf b/specs/page-selector/page-nth/page-nth.pdf deleted file mode 100644 index 3b4b0fd52fe2fd0665656f1b397e466fe6cb9934..0000000000000000000000000000000000000000 Binary files a/specs/page-selector/page-nth/page-nth.pdf and /dev/null differ diff --git a/specs/page-selector/page-spread/page-spread.pdf b/specs/page-selector/page-spread/page-spread.pdf deleted file mode 100644 index 1abe497074471717b1f479d74a36fd9d7d531218..0000000000000000000000000000000000000000 Binary files a/specs/page-selector/page-spread/page-spread.pdf and /dev/null differ diff --git a/src/modules/generated-content/running-headers.js b/src/modules/generated-content/running-headers.js index 1f8472a55b43d70cb9aabec6ca7d27a62112807e..0feb552d53fe503583fd2cdd0c31902f6484eae2 100644 --- a/src/modules/generated-content/running-headers.js +++ b/src/modules/generated-content/running-headers.js @@ -1,5 +1,6 @@ import Handler from "../handler"; import csstree from 'css-tree'; +import { getTypeSelector, getPsuedoSelector, getNthSelector } from "../../utils/csstree"; class RunningHeaders extends Handler { constructor(chunker, polisher, caller) { @@ -12,7 +13,6 @@ class RunningHeaders extends Handler { onDeclaration(declaration, dItem, dList, rule) { if (declaration.property === "position") { let selector = csstree.generate(rule.ruleNode.prelude); - let identifier = declaration.value.children.first().name if (identifier === "running") { @@ -109,13 +109,20 @@ class RunningHeaders extends Handler { } // move elements - for (let selector of Object.keys(this.elements)) { + if (!this.orderedSelectors) { + this.orderedSelectors = this.orderSelectors(this.elements); + } + + for (let selector of this.orderedSelectors) { if (selector) { + let el = this.elements[selector]; let selected = fragment.querySelector(selector); if (selected) { let running = this.runningSelectors[el.args[0]]; - if (running.first) { + if (running && running.first) { + selected.innerHTML = ""; // Clear node + selected.classList.add("pagedjs_clear-after"); // Clear ::after let clone = running.first.cloneNode(true); clone.style.display = null; selected.appendChild(clone); @@ -124,6 +131,92 @@ class RunningHeaders extends Handler { } } } + + /** + * Assign a weight to @page selector classes + * 1) page + * 2) left & right + * 3) blank + * 4) first & nth + * 5) named page + * 6) named left & right + * 7) named first & nth + */ + pageWeight(s) { + let weight = 1; + let selector = s.split(" "); + let parts = selector.length && selector[0].split("."); + + parts.shift() // remove empty first part + + switch (parts.length) { + case 4: + if (parts[3] === "pagedjs_first_page") { + weight = 7; + } else if (parts[3] === "pagedjs_left_page" || parts[3] === "pagedjs_right_page") { + weight = 6; + } + break; + case 3: + if (parts[1] === "pagedjs_named_page") { + if (parts[2].indexOf(":nth-of-type") > -1) { + weight = 7; + } else { + weight = 5; + } + } + break; + case 2: + if (parts[1] === "pagedjs_first_page") { + weight = 4; + } else if (parts[1] === "pagedjs_blank_page") { + weight = 3; + } else if (parts[1] === "pagedjs_left_page" || parts[1] === "pagedjs_right_page") { + weight = 2; + } + break; + default: + if (parts[0].indexOf(":nth-of-type") > -1) { + weight = 4; + } else { + weight = 1; + } + } + + return weight; + } + + /** + * Orders the selectors based on weight + * + * Does not try to deduplicate base on specifity of the selector + * Previous matched selector will just be overwritten + */ + orderSelectors(obj) { + let selectors = Object.keys(obj); + let weighted = { + 1: [], + 2: [], + 3: [], + 4: [], + 5: [], + 6: [], + 7: [] + }; + + let orderedSelectors = []; + + for (let s of selectors) { + let w = this.pageWeight(s); + weighted[w].unshift(s); + } + + for (var i = 1; i <= 7; i++) { + orderedSelectors = orderedSelectors.concat(weighted[i]); + } + + return orderedSelectors; + } } export default RunningHeaders; diff --git a/src/modules/paged-media/atpage.js b/src/modules/paged-media/atpage.js index 9fd0003681f7af539fe91e8a176fc3f8cc47f029..5d827468305d51d6c42bdf2566c81e7c607ca96a 100644 --- a/src/modules/paged-media/atpage.js +++ b/src/modules/paged-media/atpage.js @@ -37,9 +37,11 @@ class AtPage extends Handler { // Find and Remove @page rules onAtPage(node, item, list) { + let page, marginalia; let selector = ""; let name = ""; let named, psuedo, nth; + let needsMerge = false; if (node.prelude) { named = this.getTypeSelector(node); @@ -50,22 +52,30 @@ class AtPage extends Handler { selector = "*"; } + if (selector in this.pages) { + // this.pages[selector] = Object.assign(this.pages[selector], page); + // console.log("after", selector, this.pages[selector]); - let page = this.pageModel(selector); + // this.pages[selector].added = false; + page = this.pages[selector]; + marginalia = this.replaceMarginalia(node); + needsMerge = true; + } else { + page = this.pageModel(selector); + marginalia = this.replaceMarginalia(node); + this.pages[selector] = page; + } page.name = named; page.psuedo = psuedo; page.nth = nth; - if (name in this.pages) { - this.pages[selector] = Object.assign(this.pages[selector], page); - this.pages[selector].added = false; + if (needsMerge) { + page.marginalia = Object.assign(page.marginalia, marginalia); } else { - this.pages[selector] = page; + page.marginalia = marginalia; } - page.marginalia = this.replaceMarginalia(node); - let declarations = this.replaceDeclartations(node); if (declarations.size) { @@ -82,7 +92,11 @@ class AtPage extends Handler { page.marks = declarations.marks; } - page.block = node.block; + if (needsMerge) { + page.block.children.appendList(node.block.children); + } else { + page.block = node.block; + } // Remove the rule list.remove(item); @@ -376,6 +390,11 @@ class AtPage extends Handler { // Named page if (page.name) { + selectors.insert(selectors.createItem({ + type: 'ClassSelector', + name: "pagedjs_named_page" + })); + selectors.insert(selectors.createItem({ type: 'ClassSelector', name: "pagedjs_" + page.name + "_page" @@ -554,6 +573,11 @@ class AtPage extends Handler { // Named page if (page.name) { + selectors.insert(selectors.createItem({ + type: 'ClassSelector', + name: "pagedjs_named_page" + })); + name = page.name + "_page"; selectors.insert(selectors.createItem({ type: 'ClassSelector', @@ -651,6 +675,11 @@ class AtPage extends Handler { // Named page if (page.name) { + selectors.insert(selectors.createItem({ + type: 'ClassSelector', + name: "pagedjs_named_page" + })); + name = page.name + "_page"; selectors.insert(selectors.createItem({ type: 'ClassSelector', @@ -892,6 +921,7 @@ class AtPage extends Handler { if (named) { page.name = named; + page.element.classList.add("pagedjs_named_page"); page.element.classList.add("pagedjs_" + named + "_page"); if (!start.dataset.splitFrom) { diff --git a/src/polisher/base.js b/src/polisher/base.js index 294f0a8a68d537b7a2bb05867989272e166e0986..03f593c255e2d65c070aa2611cc331794e7ed1c4 100644 --- a/src/polisher/base.js +++ b/src/polisher/base.js @@ -193,6 +193,10 @@ export default ` break-after: column; } +.pagedjs_clear-after::after { + content: none !important; +} + @media print { body { width: unset;