Commit 014fa09a authored by Fred Chasen's avatar Fred Chasen

version bump, update readme

parent cbd6f54c
...@@ -7,12 +7,10 @@ $ npm install pagedjs ...@@ -7,12 +7,10 @@ $ npm install pagedjs
``` ```
```js ```js
import { Chunker, Styler} from 'pagedjs'; import { Previewer } from 'pagedjs';
let styles = new Polisher(); let paged = new Previewer();
let styleText = await styles.add("path/to/css/file.css"); let flow = paged.preview(DOMContent, ["path/to/css/file.css"], document.body).then((flow) => {
let chunker = new Chunker(DOMContent, document.body, styles).then((flow) => {
console.log("Rendered", flow.total, "pages."); console.log("Rendered", flow.total, "pages.");
}) })
``` ```
...@@ -37,12 +35,51 @@ Upload and chunk an Epub (using Epub.js): [https://s3.amazonaws.com/pagedmedia/p ...@@ -37,12 +35,51 @@ Upload and chunk an Epub (using Epub.js): [https://s3.amazonaws.com/pagedmedia/p
## Polisher ## Polisher
Converts `@page` css to classes, and applies counters and content. Converts `@page` css to classes, and applies counters and content.
Test styles for Aurorae: [https://s3.amazonaws.com/pagedmedia/pagedjs/examples/styler.html](https://s3.amazonaws.com/pagedmedia/pagedjs/examples/styler.html). Test styles for Aurorae: [https://s3.amazonaws.com/pagedmedia/pagedjs/examples/polisher.html](https://s3.amazonaws.com/pagedmedia/pagedjs/examples/polisher.html).
### CLI ### CLI
Command line interface to render out PDFs of HTML files using Puppeteer: [https://gitlab.pagedmedia.org/polyfills/pagedjs-cli](https://gitlab.pagedmedia.org/polyfills/pagedjs-cli). Command line interface to render out PDFs of HTML files using Puppeteer: [https://gitlab.pagedmedia.org/polyfills/pagedjs-cli](https://gitlab.pagedmedia.org/polyfills/pagedjs-cli).
## Modules
Modules are groups of handlers for that apply the layout and styles of a CSS module, such as Generated Content.
New handlers can be registered from `import { registerHandlers } from 'pagedjs'` or by calling `Paged.registerHandlers` on an html page.
```html
<script src="https://s3.amazonaws.com/pagedmedia/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);
}
}
Paged.registerHandlers(myHandler);
</script>
```
Handlers have methods that correspond to the hooks for the parsing, layout and rendering of the Chunker and Polisher. Returning an promise or `async` function from a method in a handler will complete that task before continuing with the other registered methods for that hook.
```js
// Chunker
afterParsed(parsed)
beforePageLayout(page)
afterPageLayout(pageElement, page, breakToken)
afterRendered(pages)
// Polisher
onUrl(urlNode)
onAtPage(atPageNode)
onRule(ruleNode)
onDeclaration(declarationNode, ruleNode)
onContent(contentNode, declarationNode, ruleNode)
```
## Setup ## Setup
Install dependencies Install dependencies
```sh ```sh
......
{ {
"name": "pagedjs", "name": "pagedjs",
"version": "0.0.4", "version": "0.1.0",
"description": "Chunks up a document into paged media flows and applies print styles", "description": "Chunks up a document into paged media flows and applies print styles",
"author": "Fred Chasen", "author": "Fred Chasen",
"license": "MIT", "license": "MIT",
......
import Chunker from './chunker/chunker'; import Chunker from './chunker/chunker';
import Polisher from './polisher/polisher'; import Polisher from './polisher/polisher';
import Previewer from './polyfill/previewer'; import Previewer from './polyfill/previewer';
import Handler from './modules/handler';
import { registerHandlers, initializeHandlers } from './utils/handlers'; import { registerHandlers, initializeHandlers } from './utils/handlers';
export { export {
Chunker, Chunker,
Polisher, Polisher,
Previewer, Previewer,
Handler,
registerHandlers, registerHandlers,
initializeHandlers initializeHandlers
}; };
...@@ -74,10 +74,6 @@ class TargetText extends Handler { ...@@ -74,10 +74,6 @@ class TargetText extends Handler {
}); });
} }
afterPageLayout(fragment) {
}
} }
export default TargetText; export default TargetText;
...@@ -91,7 +91,7 @@ class Previewer { ...@@ -91,7 +91,7 @@ class Previewer {
return hrefs; return hrefs;
} }
async preview(content, stylesheets) { async preview(content, stylesheets, renderTo) {
if (!stylesheets) { if (!stylesheets) {
stylesheets = this.removeStyles(); stylesheets = this.removeStyles();
} }
...@@ -109,7 +109,7 @@ class Previewer { ...@@ -109,7 +109,7 @@ class Previewer {
let startTime = performance.now(); let startTime = performance.now();
// Render flow // Render flow
let flow = await this.chunker.flow(content); let flow = await this.chunker.flow(content, renderTo);
let endTime = performance.now(); let endTime = performance.now();
let msg = "Rendering " + flow.total + " pages took " + (endTime - startTime) + " milliseconds."; let msg = "Rendering " + flow.total + " pages took " + (endTime - startTime) + " milliseconds.";
......
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