...
 
Commits (46)
# Paged.js Contributions Guide
Whether you're contributing to Pagedjs through development, creating examples, finding bug or just asking questions - thanks in advance for your help!
## I found a bug!
Please file a bug report on our gitlab issues page: https://gitlab.pagedmedia.org/tools/pagedjs/issues
Issues with a HTML file example and correct / incorrect output PDFs are much quicker to debug and very appreciated.
## I fixed something!
We'll review the code on either a github or gitlab pull request and then merge it into the gitlab repository.
## I need help!
Chat with us on mattermost @ https://mattermost.pagedmedia.org/login
You can also open an issue with the `Question` label: https://gitlab.pagedmedia.org/tools/pagedjs/issues?label_name%5B%5D=Question
## I have a great idea for a feature!
Please open an issue with the `Feature Request` label: https://gitlab.pagedmedia.org/tools/pagedjs/issues?label_name%5B%5D=Feature+Request
......@@ -3,7 +3,13 @@
Paged.js - Paged Media Tools
===========
Paged.js is an open-source library to display paginated content in the browser and to generate print books using web technology.
It contains a set of handlers for CSS transformations and fragmented layout which polyfill the [Paged Media](https://www.w3.org/TR/css-page-3/) and [Generated Content](https://www.w3.org/TR/css-gcpm-3/) CSS modules, along with hooks to create new handlers for custom properties.
The currently supported properties can be found on [the wiki](https://gitlab.pagedmedia.org/tools/pagedjs/wikis/Support-of-specifications).
A quick overview to getting started with Paged Media CSS and Paged.js is available on [pagedmedia.org](https://www.pagedmedia.org/paged-js/).
## NPM Module
```sh
......@@ -41,6 +47,13 @@ However, you can add an async `before` function or return a Promise to delay the
}
},
after: (flow) => { console.log("after", flow) },
handlers: [
{
afterPageLayout(pageFragment, page) {
console.log(pageFragment);
}
}
]
};
</script>
```
......@@ -89,16 +102,15 @@ New handlers can be registered from `import { registerHandlers } from 'pagedjs'`
```html
<script src="https://unpkg.com/pagedjs/dist/paged.polyfill.js"></script>
<script>
class MyHandler extends Paged.Handler {
constructor(chunker, polisher, caller) {
super(chunker, polisher, caller);
}
afterPageLayout(pageFragment, page) {
console.log(pageFragment);
}
window.PagedConfig = {
handlers: [
{
afterPageLayout(pageFragment, page) {
console.log(pageFragment);
}
}
]
}
Paged.registerHandlers(MyHandler);
</script>
```
......@@ -121,6 +133,12 @@ onAtPage(atPageNode)
onRule(ruleNode)
onDeclaration(declarationNode, ruleNode)
onContent(contentNode, declarationNode, ruleNode)
// Layout
layoutNode(node)
renderNode(node, sourceNode)
onOverflow(overflow, rendered, bounds)
onBreakToken(breakToken, overflow, rendered)
```
## Setup
......@@ -136,9 +154,11 @@ $ npm start
```
## Deployment
Build the `dist` output
```sh
$ npm run prepare
$ npm run build
```
## Testing
......@@ -150,7 +170,7 @@ Testing for Paged.js uses [Jest](https://facebook.github.io/jest/en/) but is spl
Unit tests for Chunker and Polisher methods are run in node using JSDOM.
```bash
npm run tests
npm test
```
### Specs
......@@ -176,12 +196,6 @@ sudo apt-get install ghostscript
sudo apt-get install libgs-dev
```
Then you can install the node library
```bash
npm install ghostscript4js --no-save
```
To test the pdf output of specs, you'll need to build the library locally.
```bash
......@@ -213,7 +227,7 @@ A `pagedmedia/pagedjs` docker image contains all the dependencies needed to run
To build the image run
```bash
docker build -t pagedmedia/pagedjs .
docker build -t pagedmedia/pagedjs .
```
By default the container will run the development server with `npm start`
......
@page {
size: 8.5in 11in;
margin: 20mm 25mm;
marks: crop;
/* marks: crop; */
@footnote {
margin: 0.6em 0 0 0;
......@@ -12,7 +12,7 @@
@top-center {
vertical-align: bottom;
padding-bottom: 10mm;
content: string(booktitle);
content: string(booktitle, first-except);
}
}
......@@ -52,7 +52,7 @@
}
@top-center{
content: string(booktitle);
content: string(booktitle, first-except);
}
}
......@@ -115,7 +115,7 @@ font-style: italic;
}
article.section:nth-child(1) h1 {
article.section:nth-child(1) h1, article.section:nth-child(1) .title {
string-set: booktitle content(text);
}
......
#main {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
@media screen {
#navigation {
width: 500px;
position: fixed;
overflow: auto;
top: 0;
left: -525px;
#main {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
background: #ECECEC;
min-height: 100%;
height: 100%;
height: 100vh;
#navigation {
width: 500px;
position: fixed;
overflow: auto;
top: 0;
left: -525px;
overflow: scroll;
-webkit-overflow-scrolling: touch;
padding: 9px;
padding-top: 10px;
background: #ECECEC;
min-height: 100%;
height: 100%;
height: 100vh;
transition: left .2s ease-out;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
overflow: scroll;
-webkit-overflow-scrolling: touch;
padding: 9px;
padding-top: 10px;
z-index: 1;
}
transition: left .2s ease-out;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
#navigation.open {
left: 0;
}
z-index: 1;
}
#opener {
position: absolute;
top: 0;
left: 0;
padding: 10px;
stroke: #E2E2E2;
fill: #E2E2E2;
}
#navigation.open {
left: 0;
}
#opener:hover {
stroke: #777;
fill: #777;
}
#opener {
position: absolute;
top: 0;
left: 0;
padding: 10px;
stroke: #E2E2E2;
fill: #E2E2E2;
}
#header {
height: 30px;
}
#opener:hover {
stroke: #777;
fill: #777;
}
#update {
float: right;
}
#header {
height: 30px;
}
.CodeMirror {
border: 1px solid #eee;
height: calc(100vh - 24px);
box-sizing: border-box;
background: #fbfbfb;
box-shadow: inset 0 0 1px rgba(0,0,0,.8);
}
#update {
float: right;
}
.material-icons {
color: #333;
cursor: pointer;
}
.CodeMirror {
border: 1px solid #eee;
height: calc(100vh - 24px);
box-sizing: border-box;
background: #fbfbfb;
box-shadow: inset 0 0 1px rgba(0,0,0,.8);
}
.material-icons:hover {
color: #525252;
}
.material-icons {
color: #333;
cursor: pointer;
}
.material-icons:active {
color: #000;
}
.material-icons:hover {
color: #525252;
}
.material-icons:active {
color: #000;
}
.pagedjs_page {
box-shadow: 0 0 4px #ccc;
}
.pagedjs_page {
box-shadow: 0 0 4px #ccc;
}
@page {
size: 8.5in 11in;
margin: 20mm 25mm;
marks: crop;
/* marks: crop; */
@footnote {
margin: 0.6em 0 0 0;
......
......@@ -25,7 +25,7 @@
}
.pagedjs_pages {
width: calc((var(--width) * 2) + (var(--margin) * 4));
width: calc((var(--pagedjs-width) * 2) + (var(--margin) * 4));
display: flex;
flex-direction: row;
flex-wrap: wrap;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
{
"name": "pagedjs",
"version": "0.1.30",
"version": "0.1.34",
"description": "Chunks up a document into paged media flows and applies print styles",
"author": "Fred Chasen",
"license": "MIT",
......@@ -9,41 +9,40 @@
"module": "src/index.js",
"browser": "dist/paged.js",
"dependencies": {
"@babel/polyfill": "^7.0.0",
"@babel/runtime": "^7.2.0",
"@babel/polyfill": "^7.4.4",
"@babel/runtime": "^7.4.4",
"css-tree": "1.0.0-alpha.29",
"event-emitter": "^0.3.5",
"lodash": "^4.17.11"
"event-emitter": "^0.3.5"
},
"devDependencies": {
"@babel/cli": "^7.2.0",
"@babel/core": "^7.2.2",
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/plugin-proposal-async-generator-functions": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"chalk": "^2.4.1",
"eslint": "^5.10.0",
"babel-jest": "^24.7.1",
"chalk": "^2.4.2",
"eslint": "^5.16.0",
"express": "^4.16.4",
"jest": "^23.6.0",
"jest-image-snapshot": "^2.7.0",
"puppeteer": "^1.12.2",
"rimraf": "^2.6.2",
"rollup": "^0.68.0",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-livereload": "^0.6.0",
"jest": "^24.7.1",
"jest-image-snapshot": "^2.8.1",
"puppeteer": "^1.15.0",
"rimraf": "^2.6.3",
"rollup": "^1.10.1",
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-livereload": "^1.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-serve": "^0.6.0"
"rollup-plugin-node-resolve": "^4.2.3",
"rollup-plugin-serve": "^1.0.1"
},
"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": "jest --config=tests/jest.config.js",
"tests": "jest --config=src/jest.config.js",
"specs": "jest --config=specs/jest.config.js",
"compile": "./node_modules/.bin/babel src/ -d lib/",
"pretest": "npm run build",
......@@ -58,5 +57,8 @@
"files": [
"dist",
"lib"
]
],
"optionalDependencies": {
"ghostscript4js": "^3.1.1"
}
}
......@@ -6,7 +6,9 @@ import pkg from './package.json';
const plugins = [
resolve(),
commonjs(),
commonjs({
include: 'node_modules/**'
}),
json()
];
......@@ -22,15 +24,15 @@ export default [
plugins: plugins
},
// {
// input: pkg.module,
// output: [
// {
// file: pkg.main,
// format: 'cjs'
// },
// ]
// },
{
input: pkg.module,
output: {
name: "PagedModule",
file: "./dist/paged.esm.js",
format: 'es'
},
plugins: plugins
},
{
input: "./src/polyfill/polyfill.js",
......
This diff is collapsed.
const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('bleed', async () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('bleed/bleed.html')
return page.rendered;
}, TIMEOUT)
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 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);
expect(pdf).toMatchPDFSnapshot(1);
})
}
}
)
......@@ -77,7 +77,7 @@
}
.pagedjs_pages {
width: calc(var(--width) * 2);
width: calc(var(--pagedjs-width) * 2);
display: flex;
flex-direction: row;
flex-wrap: wrap;
......
......@@ -90,7 +90,7 @@
}
.pagedjs_pages {
width: calc(var(--width) * 2);
width: calc(var(--pagedjs-width) * 2);
display: flex;
flex-direction: row;
flex-wrap: wrap;
......
......@@ -90,7 +90,7 @@
}
.pagedjs_pages {
width: calc(var(--width) * 2);
width: calc(var(--pagedjs-width) * 2);
display: flex;
flex-direction: row;
flex-wrap: wrap;
......
......@@ -89,7 +89,7 @@
}
.pagedjs_pages {
width: calc(var(--width) * 2);
width: calc(var(--pagedjs-width) * 2);
display: flex;
flex-direction: row;
flex-wrap: wrap;
......
......@@ -89,7 +89,7 @@
}
.pagedjs_pages {
width: calc(var(--width) * 2);
width: calc(var(--pagedjs-width) * 2);
display: flex;
flex-direction: row;
flex-wrap: wrap;
......
......@@ -90,7 +90,7 @@
}
.pagedjs_pages {
width: calc(var(--width) * 2);
width: calc(var(--pagedjs-width) * 2);
display: flex;
flex-direction: row;
flex-wrap: wrap;
......
......@@ -74,7 +74,7 @@
}
.pagedjs_pages {
width: calc(var(--width) * 2);
width: calc(var(--pagedjs-width) * 2);
display: flex;
flex-direction: row;
flex-wrap: wrap;
......
......@@ -88,7 +88,7 @@
}
.pagedjs_pages {
width: calc(var(--width) * 2);
width: calc(var(--pagedjs-width) * 2);
display: flex;
flex-direction: row;
flex-wrap: wrap;
......