Commits (151)
......@@ -4,7 +4,7 @@ root = true
end_of_line = lf
insert_final_newline = true
[*.js]
[*.{js,html}]
charset = utf-8
indent_style = tab
indent_size = 2
......@@ -3,7 +3,8 @@ module.exports = {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
"node": true,
"jest": true
},
"globals": {
},
......
FROM node:12-stretch
FROM node:15-stretch
# Application parameters and variables
ENV NODE_ENV=development
......
......@@ -117,6 +117,7 @@ afterPreview(pages)
// Chunker
beforeParsed(content)
filter(content)
afterParsed(parsed)
beforePageLayout(page)
afterPageLayout(pageElement, page, breakToken)
......@@ -134,9 +135,10 @@ onContent(contentNode, declarationNode, ruleNode)
// Layout
layoutNode(node)
renderNode(node, sourceNode)
renderNode(node, sourceNode, layout)
onOverflow(overflow, rendered, bounds)
onBreakToken(breakToken, overflow, rendered)
afterOverflowRemoved(removed, rendered)
```
## Setup
......
This diff is collapsed.
{
"name": "pagedjs",
"version": "0.1.39",
"version": "0.2.0",
"description": "Chunks up a document into paged media flows and applies print styles",
"author": "Fred Chasen",
"license": "MIT",
......@@ -9,47 +9,47 @@
"module": "src/index.js",
"browser": "dist/paged.js",
"dependencies": {
"@babel/polyfill": "^7.8.3",
"@babel/runtime": "^7.8.4",
"css-tree": "1.0.0-alpha.39",
"@babel/polyfill": "^7.10.1",
"@babel/runtime": "^7.14.0",
"clear-cut": "^2.0.2",
"css-tree": "^1.1.3",
"event-emitter": "^0.3.5"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.4",
"@babel/plugin-proposal-async-generator-functions": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^25.1.0",
"chalk": "^3.0.0",
"eslint": "^6.8.0",
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.3",
"@babel/plugin-proposal-async-generator-functions": "^7.14.2",
"@babel/plugin-transform-runtime": "^7.14.3",
"@babel/preset-env": "^7.14.2",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"chalk": "^4.1.1",
"eslint": "^7.27.0",
"express": "^4.17.1",
"ghostscript4js": "^3.1.1",
"jest": "^25.1.0",
"jest-image-snapshot": "^2.12.0",
"puppeteer": "^2.1.1",
"ghostscript4js": "^3.2.1",
"jest": "^26.6.3",
"jest-image-snapshot": "^4.5.0",
"puppeteer": "^9.1.1",
"rimraf": "^3.0.2",
"rollup": "^1.31.1",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-livereload": "^1.0.4",
"rollup": "^2.38.3",
"rollup-plugin-license": "^2.1.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-serve": "^1.0.1"
"rollup-plugin-serve": "^1.1.0"
},
"scripts": {
"build": "./node_modules/.bin/rollup -c",
"legacy": "./node_modules/.bin/rollup -c rollup.legacy.config.js",
"start": "./node_modules/.bin/rollup -w -c rollup.server.config.js",
"test": "npm run tests && npm run specs",
"tests": "./node_modules/.bin/jest",
"specs": "./node_modules/.bin/jest --config=specs/jest.config.js",
"compile": "./node_modules/.bin/babel src/ -d lib/",
"build": "rollup -c",
"legacy": "rollup -c rollup.legacy.config.js",
"start": "rollup -w -c rollup.server.config.js",
"test": "npm run lint && npm run tests && npm run specs",
"tests": "jest",
"specs": "jest --config=specs/jest.config.js",
"compile": "babel src/ -d lib/",
"pretest": "npm run build",
"prepublishOnly": "npm run build && npm run compile && npm run legacy",
"watch": "./node_modules/.bin/rollup -w -c",
"lint": "./node_modules/.bin/eslint -c .eslintrc.js src",
"watch": "rollup -w -c",
"lint": "eslint -c .eslintrc.js src specs",
"docker": "docker build -t pagedmedia/pagedjs . && docker run -it --security-opt 'seccomp=seccomp.json' -v $(pwd)/specs:/home/node/pagedjs/specs pagedmedia/pagedjs npm test"
},
"repository": {
......
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import license from "rollup-plugin-license";
import pkg from './package.json';
import pkg from "./package.json";
const plugins = [
resolve(),
nodeResolve(),
commonjs({
include: 'node_modules/**'
include: "node_modules/**"
}),
json()
json(),
license({
banner: "@license Paged.js v<%= pkg.version %> | MIT | https://gitlab.pagedmedia.org/tools/pagedjs",
})
];
export default [
......@@ -17,9 +21,9 @@ export default [
{
input: pkg.module,
output: {
name: 'Paged',
name: "Paged",
file: pkg.browser,
format: 'umd'
format: "umd"
},
plugins: plugins
},
......@@ -27,9 +31,9 @@ export default [
{
input: pkg.module,
output: {
name: "PagedModule",
file: "./dist/paged.esm.js",
format: 'es'
name: "PagedModule",
file: "./dist/paged.esm.js",
format: "es"
},
plugins: plugins
},
......@@ -37,9 +41,9 @@ export default [
{
input: "./src/polyfill/polyfill.js",
output: {
name: 'PagedPolyfill',
name: "PagedPolyfill",
file: "./dist/paged.polyfill.js",
format: 'umd'
format: "umd"
},
plugins: plugins
}
......
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import pkg from './package.json';
const plugins = [
resolve(),
nodeResolve(),
commonjs(),
json()
];
......
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
// import builtins from 'rollup-plugin-node-builtins';
// import globals from 'rollup-plugin-node-globals';
import pkg from './package.json';
// import pkg from './package.json';
import serve from 'rollup-plugin-serve'
import livereload from 'rollup-plugin-livereload'
const plugins = [
resolve(),
nodeResolve(),
commonjs(),
json(),
// globals(),
......@@ -30,16 +29,6 @@ const plugins = [
];
export default [
{
input: pkg.module,
output: {
name: 'Paged',
file: pkg.browser,
format: 'umd'
},
plugins: plugins
},
{
input: "./src/polyfill/polyfill.js",
output: {
......
{
"env": {
"jest": true
},
"globals": {
"DEBUG": "readonly",
"PDF_SETTINGS": "readonly",
"loadPage": "readonly"
}
}
const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('bleed', () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('bleed/bleed.html')
return page.rendered;
}, TIMEOUT)
describe("bleed", () => {
let page;
beforeAll(async () => {
page = await loadPage("bleed/bleed.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
})
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
it('should render text', async () => {
let text = await page.evaluate(() => document.body.textContent);
expect(text).toContain('Chapter 1. Loomings.');
})
it("should render text", async () => {
let text = await page.evaluate(() => document.body.textContent);
expect(text).toContain("Chapter 1. Loomings.");
});
it('should render 7 pages', async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => r.length);
expect(pages).toBe(7);
})
it("should render 7 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => r.length);
expect(pages).toBe(7);
});
if (!DEBUG) {
it('should create a pdf', async () => {
let pdf = await page.pdf(PDF_SETTINGS);
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(1);
})
}
expect(pdf).toMatchPDFSnapshot(1);
});
}
)
}
);
const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('break-after-avoid', () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('breaks/break-after/break-after-avoid/break-after-avoid.html')
return page.rendered;
}, TIMEOUT)
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
})
it('should render 5 pages', async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(5);
})
it('page 3 should be Section 2', async () => {
let text = await page.$eval("[data-page-number='3']", (r) => r.textContent);
expect(text).toContain('Section 2');
})
describe("break-after-avoid", () => {
let page;
beforeAll(async () => {
page = await loadPage("breaks/break-after/break-after-avoid/break-after-avoid.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
it('should create a pdf', async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(3);
})
await page.close();
}
});
it("should render 5 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(5);
});
it("page 3 should be Section 2", async () => {
let text = await page.$eval("[data-page-number='3']", (r) => r.textContent);
expect(text).toContain("Section 2");
});
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(3);
});
}
)
}
);
const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('break-after-left', () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('breaks/break-after/break-after-left/break-after-left.html')
return page.rendered;
}, TIMEOUT)
describe("break-after-left", () => {
let page;
beforeAll(async () => {
page = await loadPage("breaks/break-after/break-after-left/break-after-left.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
})
it("should render 38 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
it('should render 38 pages', async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(38);
});
expect(pages).toEqual(38);
})
it("should render page 4 as left", async () => {
let isLeft = await page.$eval("[data-page-number='4']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 4 as left', async () => {
let isLeft = await page.$eval("[data-page-number='4']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true);
});
expect(isLeft).toEqual(true);
})
it("page 4 should be Section 2", async () => {
let text = await page.$eval("[data-page-number='4']", (r) => r.textContent);
it('page 4 should be Section 2', async () => {
let text = await page.$eval("[data-page-number='4']", (r) => r.textContent);
expect(text).toContain("Section 2");
});
expect(text).toContain('Section 2');
})
it("should render page 7 as blank", async () => {
let isBlank = await page.$eval("[data-page-number='7']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
it('should render page 7 as blank', async () => {
let isBlank = await page.$eval("[data-page-number='7']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true);
});
expect(isBlank).toEqual(true);
})
it("should render page 8 as left", async () => {
let isLeft = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 8 as left', async () => {
let isLeft = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true);
});
expect(isLeft).toEqual(true);
})
it("page 8 should be Section 3", async () => {
let text = await page.$eval("[data-page-number='8']", (r) => r.textContent);
it('page 8 should be Section 3', async () => {
let text = await page.$eval("[data-page-number='8']", (r) => r.textContent);
expect(text).toContain("Section 3");
});
expect(text).toContain('Section 3');
})
it("page 9 should break after h2", async () => {
let text = await page.$eval("[data-page-number='9']", (r) => r.textContent);
it('page 9 should break after h2', async () => {
let text = await page.$eval("[data-page-number='9']", (r) => r.textContent);
expect(text.trim()).toEqual("A - h2 (inline element)");
});
expect(text.trim()).toEqual('A - h2 (inline element)');
})
it("should render page 10 as left", async () => {
let isLeft = await page.$eval("[data-page-number='10']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 10 as left', async () => {
let isLeft = await page.$eval("[data-page-number='10']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true);
});
expect(isLeft).toEqual(true);
})
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
if (!DEBUG) {
it('should create a pdf', async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(4);
expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(8);
expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(10);
})
}
expect(pdf).toMatchPDFSnapshot(4);
expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(8);
expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(10);
});
}
)
}
);
const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('break-after-page', () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('breaks/break-after/break-after-page/break-after-page.html')
return page.rendered;
}, TIMEOUT)
describe("break-after-page", () => {
let page;
beforeAll(async () => {
page = await loadPage("breaks/break-after/break-after-page/break-after-page.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
})
it("should render 31 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
it('should render 31 pages', async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(31);
});
expect(pages).toEqual(31);
})
it("should render page 2 as left", async () => {
let isLeft = await page.$eval("[data-page-number='2']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 2 as left', async () => {
let isLeft = await page.$eval("[data-page-number='2']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true);
});
expect(isLeft).toEqual(true);
})
it("page 3 should be Section 1", async () => {
let text = await page.$eval("[data-page-number='2']", (r) => r.textContent);
it('page 3 should be Section 1', async () => {
let text = await page.$eval("[data-page-number='2']", (r) => r.textContent);
expect(text).toContain("Section 1");
});
expect(text).toContain('Section 1');
})
it("should render page 4 as left", async () => {
let isLeft = await page.$eval("[data-page-number='4']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 4 as left', async () => {
let isLeft = await page.$eval("[data-page-number='4']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true);
});
expect(isLeft).toEqual(true);
})
it("page 4 should be Section 2", async () => {
let text = await page.$eval("[data-page-number='4']", (r) => r.textContent);
it('page 4 should be Section 2', async () => {
let text = await page.$eval("[data-page-number='4']", (r) => r.textContent);
expect(text).toContain("Section 2");
});
expect(text).toContain('Section 2');
})
it("should render page 7 as right", async () => {
let isRight = await page.$eval("[data-page-number='7']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 7 as right', async () => {
let isRight = await page.$eval("[data-page-number='7']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
expect(isRight).toEqual(true);
})
it("page 7 should be Section 3", async () => {
let text = await page.$eval("[data-page-number='7']", (r) => r.textContent);
it('page 7 should be Section 3', async () => {
let text = await page.$eval("[data-page-number='7']", (r) => r.textContent);
expect(text).toContain("Section 3");
});
expect(text).toContain('Section 3');
})
it("page 8 should break after h2", async () => {
let text = await page.$eval("[data-page-number='8']", (r) => r.textContent);
it('page 8 should break after h2', async () => {
let text = await page.$eval("[data-page-number='8']", (r) => r.textContent);
expect(text.trim()).toEqual("A - h2 (inline element)");
});
expect(text.trim()).toEqual('A - h2 (inline element)');
})
it("should render page 9 as right", async () => {
let isRight = await page.$eval("[data-page-number='9']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 9 as right', async () => {
let isRight = await page.$eval("[data-page-number='9']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
expect(isRight).toEqual(true);
})
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
if (!DEBUG) {
it('should create a pdf', async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(2);
expect(pdf).toMatchPDFSnapshot(4);
expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(8);
expect(pdf).toMatchPDFSnapshot(9);
})
}
expect(pdf).toMatchPDFSnapshot(2);
expect(pdf).toMatchPDFSnapshot(4);
expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(8);
expect(pdf).toMatchPDFSnapshot(9);
});
}
)
}
);
const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('break-after-recto', () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('breaks/break-after/break-after-recto/break-after-recto.html')
return page.rendered;
}, TIMEOUT)
describe("break-after-recto", () => {
let page;
beforeAll(async () => {
page = await loadPage("breaks/break-after/break-after-recto/break-after-recto.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
})
it("should render 39 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
it('should render 39 pages', async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(39);
});
expect(pages).toEqual(39);
})
it("should render page 2 as blank", async () => {
let isBlank = await page.$eval("[data-page-number='2']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
it('should render page 2 as blank', async () => {
let isBlank = await page.$eval("[data-page-number='2']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true);
});
expect(isBlank).toEqual(true);
})
it("should render page 3 as recto", async () => {
let isRight = await page.$eval("[data-page-number='3']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 3 as recto', async () => {
let isRight = await page.$eval("[data-page-number='3']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
expect(isRight).toEqual(true);
})
it("page 3 should be Section 1", async () => {
let text = await page.$eval("[data-page-number='3']", (r) => r.textContent);
it('page 3 should be Section 1', async () => {
let text = await page.$eval("[data-page-number='3']", (r) => r.textContent);
expect(text).toContain("Section 1");
});
expect(text).toContain('Section 1');
})
it("should render page 5 as recto", async () => {
let isRight = await page.$eval("[data-page-number='5']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 5 as recto', async () => {
let isRight = await page.$eval("[data-page-number='5']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
expect(isRight).toEqual(true);
})
it("page 5 should be Section 2", async () => {
let text = await page.$eval("[data-page-number='5']", (r) => r.textContent);
it('page 5 should be Section 2', async () => {
let text = await page.$eval("[data-page-number='5']", (r) => r.textContent);
expect(text).toContain("Section 2");
});
expect(text).toContain('Section 2');
})
it("should render page 8 as blank", async () => {
let isBlank = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
it('should render page 8 as blank', async () => {
let isBlank = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true);
});
expect(isBlank).toEqual(true);
})
it("should render page 9 as recto", async () => {
let isRight = await page.$eval("[data-page-number='9']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 9 as recto', async () => {
let isRight = await page.$eval("[data-page-number='9']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
expect(isRight).toEqual(true);
})
it("page 9 should be Section 3", async () => {
let text = await page.$eval("[data-page-number='9']", (r) => r.textContent);
it('page 9 should be Section 3', async () => {
let text = await page.$eval("[data-page-number='9']", (r) => r.textContent);
expect(text).toContain("Section 3");
});
expect(text).toContain('Section 3');
})
it("page 10 should break after h2", async () => {
let text = await page.$eval("[data-page-number='10']", (r) => r.textContent);
it('page 10 should break after h2', async () => {
let text = await page.$eval("[data-page-number='10']", (r) => r.textContent);
expect(text.trim()).toEqual("A - h2 (inline element)");
});
expect(text.trim()).toEqual('A - h2 (inline element)');
})
it("should render page 11 as recto", async () => {
let isRight = await page.$eval("[data-page-number='11']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 11 as recto', async () => {
let isRight = await page.$eval("[data-page-number='11']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
expect(isRight).toEqual(true);
})
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
if (!DEBUG) {
it('should create a pdf', async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(2);
expect(pdf).toMatchPDFSnapshot(3);
expect(pdf).toMatchPDFSnapshot(5);
expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(10);
expect(pdf).toMatchPDFSnapshot(11);
})
}
expect(pdf).toMatchPDFSnapshot(2);
expect(pdf).toMatchPDFSnapshot(3);
expect(pdf).toMatchPDFSnapshot(5);
expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(10);
expect(pdf).toMatchPDFSnapshot(11);
});
}
)
}
);
const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('break-after-right', () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('breaks/break-after/break-after-right/break-after-right.html')
return page.rendered;
}, TIMEOUT)
describe("break-after-right", () => {
let page;
beforeAll(async () => {
page = await loadPage("breaks/break-after/break-after-right/break-after-right.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
})
it("should render 39 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
it('should render 39 pages', async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(39);
});
expect(pages).toEqual(39);
})
it("should render page 2 as blank", async () => {
let isBlank = await page.$eval("[data-page-number='2']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
it('should render page 2 as blank', async () => {
let isBlank = await page.$eval("[data-page-number='2']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true);
});
expect(isBlank).toEqual(true);
})
it("should render page 3 as right", async () => {
let isRight = await page.$eval("[data-page-number='3']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 3 as right', async () => {
let isRight = await page.$eval("[data-page-number='3']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
expect(isRight).toEqual(true);
})
it("page 3 should be Section 1", async () => {
let text = await page.$eval("[data-page-number='3']", (r) => r.textContent);
it('page 3 should be Section 1', async () => {
let text = await page.$eval("[data-page-number='3']", (r) => r.textContent);
expect(text).toContain("Section 1");
});
expect(text).toContain('Section 1');
})
it("should render page 5 as right", async () => {
let isRight = await page.$eval("[data-page-number='5']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 5 as right', async () => {
let isRight = await page.$eval("[data-page-number='5']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
expect(isRight).toEqual(true);
})
it("page 5 should be Section 2", async () => {
let text = await page.$eval("[data-page-number='5']", (r) => r.textContent);
it('page 5 should be Section 2', async () => {
let text = await page.$eval("[data-page-number='5']", (r) => r.textContent);
expect(text).toContain("Section 2");
});
expect(text).toContain('Section 2');
})
it("should render page 8 as blank", async () => {
let isBlank = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
it('should render page 8 as blank', async () => {
let isBlank = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true);
});
expect(isBlank).toEqual(true);
})
it("should render page 9 as right", async () => {
let isRight = await page.$eval("[data-page-number='9']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 9 as right', async () => {
let isRight = await page.$eval("[data-page-number='9']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
expect(isRight).toEqual(true);
})
it("page 9 should be Section 3", async () => {
let text = await page.$eval("[data-page-number='9']", (r) => r.textContent);
it('page 9 should be Section 3', async () => {
let text = await page.$eval("[data-page-number='9']", (r) => r.textContent);
expect(text).toContain("Section 3");
});
expect(text).toContain('Section 3');
})
it("page 10 should break after h2", async () => {
let text = await page.$eval("[data-page-number='10']", (r) => r.textContent);
it('page 10 should break after h2', async () => {
let text = await page.$eval("[data-page-number='10']", (r) => r.textContent);
expect(text.trim()).toEqual("A - h2 (inline element)");
});
expect(text.trim()).toEqual('A - h2 (inline element)');
})
it("should render page 11 as right", async () => {
let isRight = await page.$eval("[data-page-number='11']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
it('should render page 11 as right', async () => {
let isRight = await page.$eval("[data-page-number='11']", (r) => {
return r.classList.contains("pagedjs_right_page");
});
expect(isRight).toEqual(true);
});
expect(isRight).toEqual(true);
})
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
if (!DEBUG) {
it('should create a pdf', async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(2);
expect(pdf).toMatchPDFSnapshot(3);
expect(pdf).toMatchPDFSnapshot(5);
expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(10);
expect(pdf).toMatchPDFSnapshot(11);
})
}
expect(pdf).toMatchPDFSnapshot(2);
expect(pdf).toMatchPDFSnapshot(3);
expect(pdf).toMatchPDFSnapshot(5);
expect(pdf).toMatchPDFSnapshot(7);
expect(pdf).toMatchPDFSnapshot(9);
expect(pdf).toMatchPDFSnapshot(10);
expect(pdf).toMatchPDFSnapshot(11);
});
}
)
}
);
const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('break-after-verso', () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('breaks/break-after/break-after-verso/break-after-verso.html')
return page.rendered;
}, TIMEOUT)
describe("break-after-verso", () => {
let page;
beforeAll(async () => {
page = await loadPage("breaks/break-after/break-after-verso/break-after-verso.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
})
it("should render 38 pages", async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
it('should render 38 pages', async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => {
return r.length;
});
expect(pages).toEqual(38);
});
expect(pages).toEqual(38);
})
it("should render page 4 as verso", async () => {
let isLeft = await page.$eval("[data-page-number='4']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 4 as verso', async () => {
let isLeft = await page.$eval("[data-page-number='4']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true);
});
expect(isLeft).toEqual(true);
})
it("page 4 should be Section 2", async () => {
let text = await page.$eval("[data-page-number='4']", (r) => r.textContent);
it('page 4 should be Section 2', async () => {
let text = await page.$eval("[data-page-number='4']", (r) => r.textContent);
expect(text).toContain("Section 2");
});
expect(text).toContain('Section 2');
})
it("should render page 7 as blank", async () => {
let isBlank = await page.$eval("[data-page-number='7']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
it('should render page 7 as blank', async () => {
let isBlank = await page.$eval("[data-page-number='7']", (r) => {
return r.classList.contains("pagedjs_blank_page");
});
expect(isBlank).toEqual(true);
});
expect(isBlank).toEqual(true);
})
it("should render page 8 as verso", async () => {
let isLeft = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
it('should render page 8 as verso', async () => {
let isLeft = await page.$eval("[data-page-number='8']", (r) => {
return r.classList.contains("pagedjs_left_page");
});
expect(isLeft).toEqual(true);
});
expect(isLeft).toEqual(true);
})
it("page 8 should be Section 3", async () => {
let text = await page.$eval("[data-page-number='8']", (r) => r.textContent);
it