Commit d5b94dde authored by julien's avatar julien

update package-lock and package.json for the merge

parents ca8fb4c3 5b2060ba
FROM node:10-stretch
FROM node:12-stretch
# Application parameters and variables
ENV NODE_ENV=development
......@@ -19,31 +19,37 @@ RUN apt-get update && \
apt-get install -y libgs-dev && \
rm -rf /var/lib/apt/lists/*
# See https://crbug.com/795759
RUN apt-get update && apt-get install -yq libgconf-2-4
# See https://github.com/GoogleChrome/puppeteer/blob/master/.ci/node12/Dockerfile.linux
RUN apt-get update && \
apt-get -y install xvfb gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 \
libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 \
libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 \
libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 \
libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget && \
rm -rf /var/lib/apt/lists/*
# Update Freetype
COPY docker-font.conf /etc/fonts/local.conf
ENV FREETYPE_PROPERTIES="truetype:interpreter-version=35"
RUN apt-get update \
&& sh -c 'echo "deb http://http.us.debian.org/debian stable main contrib non-free" >> /etc/apt/sources.list' \
&& apt-get update \
&& apt-get install -y ttf-mscorefonts-installer \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
&& sh -c 'echo "deb http://http.us.debian.org/debian stable main contrib non-free" >> /etc/apt/sources.list' \
&& apt-get update \
&& apt-get install -y ttf-mscorefonts-installer \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN apt-get update && apt-get install -y wget --no-install-recommends \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome-unstable.list' \
&& apt-get update \
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get purge --auto-remove -y curl \
&& rm -rf /src/*.deb
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome-unstable.list' \
&& apt-get update \
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get purge --auto-remove -y curl \
&& rm -rf /src/*.deb
# helps prevent zombie chrome processes.
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
......
......@@ -111,6 +111,10 @@ New handlers can be registered from `import { registerHandlers } from 'pagedjs'`
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
// Previewer
beforePreview(content, renderTo)
afterPreview(pages)
// Chunker
beforeParsed(content)
afterParsed(parsed)
......@@ -150,7 +154,17 @@ $ npm start
## Deployment
Build the `dist` output
```sh
$ npm run prepare
$ npm run build
```
Compile the `lib` output
```sh
$ npm run compile
```
Generate legacy builds with polyfills included
```sh
$ npm run legacy
```
## Testing
......@@ -162,7 +176,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
......@@ -188,12 +202,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
......@@ -225,7 +233,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`
......
module.exports = {
testMatch: ['**/?(*.)(test).js?(x)'],
testMatch: ['**/?(*.)(test).js'],
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -9,20 +9,19 @@
"module": "src/index.js",
"browser": "dist/paged.js",
"dependencies": {
"@babel/polyfill": "^7.4.4",
"@babel/runtime": "^7.4.4",
"@babel/polyfill": "^7.6.0",
"@babel/runtime": "^7.6.3",
"css-tree": "1.0.0-alpha.29",
"event-emitter": "^0.3.5",
"lodash": "^4.17.15"
"event-emitter": "^0.3.5"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/plugin-proposal-async-generator-functions": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/plugin-transform-runtime": "^7.6.2",
"@babel/preset-env": "^7.6.3",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.7.1",
"babel-jest": "^24.9.0",
"chalk": "^2.4.2",
"eslint": "^5.16.0",
"express": "^4.16.4",
......@@ -33,10 +32,18 @@
"rimraf": "^2.6.3",
"rollup": "^1.10.1",
"rollup-plugin-commonjs": "^9.3.4",
"eslint": "^6.5.1",
"express": "^4.17.1",
"jest": "^24.9.0",
"jest-image-snapshot": "^2.11.0",
"puppeteer": "^2.0.0",
"rimraf": "^3.0.0",
"rollup": "^1.25.2",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-livereload": "^1.0.1",
"rollup-plugin-livereload": "^1.0.4",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-resolve": "^4.2.3",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-serve": "^1.0.1"
},
"scripts": {
......@@ -44,14 +51,14 @@
"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",
"specs": "jest --config=specs/jest.config.js",
"tests": "./node_modules/.bin/jest",
"specs": "./node_modules/.bin/jest --config=specs/jest.config.js",
"compile": "./node_modules/.bin/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; exit 0",
"docker": "docker build pagedmedia/pagedjs . && docker run -it --security-opt 'seccomp=seccomp.json' -v $(pwd)/specs:/home/node/pagedjs/specs pagedmedia/pagedjs npm test"
"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": {
"type": "git",
......@@ -60,5 +67,8 @@
"files": [
"dist",
"lib"
]
],
"optionalDependencies": {
"ghostscript4js": "^3.1.1"
}
}
......@@ -68,7 +68,7 @@
<p>CSS IS AWE&shy;SOME!</p>
<p>
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps overrrr—the lazy dog.
</p>
</body>
......
......@@ -28,6 +28,12 @@ describe('css is awesome', async () => {
expect(text).toContain('\u2010');
})
xit('page 5 should NOT have a hyphen', async () => {
let text = await page.$eval("[data-page-number='5']", (r) => r.textContent);
expect(text).not.toContain('\u2010');
})
if (!DEBUG) {
xit('should create a pdf', async () => {
......
......@@ -4,7 +4,7 @@ describe('issue', async () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('issues/template/template.html')
page = await loadPage('issues/template/issue.html')
return page.rendered;
}, TIMEOUT)
......
......@@ -3,5 +3,5 @@ module.exports = {
globalSetup: './jest_helpers/setup.js',
globalTeardown: './jest_helpers/teardown.js',
testEnvironment: './jest_helpers/puppeteer_environment.js',
setupTestFrameworkScriptFile: './jest_helpers/setup_tests.js'
setupFilesAfterEnv: ['./jest_helpers/setup_tests.js']
}
......@@ -4,7 +4,7 @@ describe('issue', async () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('issues/template/template.html')
page = await loadPage('margin-boxes/text-align/text-align.html')
return page.rendered;
}, TIMEOUT)
......
......@@ -21,7 +21,7 @@
box-shadow: 0 0 0 1px rgba(0, 0,0,0.2);
}
.pagedjs_page {
.pagedjs_pagebox {
box-shadow: 0 0 0 1px rgba(200, 0,0,0.2);
}
}
......
......@@ -477,7 +477,7 @@ class Chunker {
loadFonts() {
let fontPromises = [];
document.fonts.forEach((fontFace) => {
(document.fonts || []).forEach((fontFace) => {
if (fontFace.status !== "loaded") {
let fontLoaded = fontFace.load().then((r) => {
return fontFace.family;
......
import { Chunker } from '../../src/index.js';
import Chunker from './chunker.js';
describe('Chunker', async () => {
......
......@@ -332,7 +332,7 @@ class Layout {
findBreakToken(rendered, source, bounds=this.bounds, extract=true) {
let overflow = this.findOverflow(rendered, bounds);
let breakToken;
let breakToken, breakLetter;
let overflowHooks = this.hooks.onOverflow.triggerSync(overflow, rendered, bounds, this);
overflowHooks.forEach((newOverflow) => {
......@@ -343,6 +343,11 @@ class Layout {
if (overflow) {
breakToken = this.createBreakToken(overflow, rendered, source);
if (breakToken["node"] && breakToken["offset"] && breakToken["node"].textContent) {
breakLetter = breakToken["node"].textContent.charAt(breakToken["offset"]);
} else {
breakLetter = undefined;
}
let breakHooks = this.hooks.onBreakToken.triggerSync(breakToken, overflow, rendered, this);
breakHooks.forEach((newToken) => {
......@@ -353,7 +358,7 @@ class Layout {
if (breakToken && breakToken.node && extract) {
this.removeOverflow(overflow);
this.removeOverflow(overflow, breakLetter);
}
}
......@@ -568,22 +573,25 @@ class Layout {
return offset;
}
removeOverflow(overflow) {
removeOverflow(overflow, breakLetter) {
let {startContainer} = overflow;
let extracted = overflow.extractContents();
this.hyphenateAtBreak(startContainer);
this.hyphenateAtBreak(startContainer, breakLetter);
return extracted;
}
hyphenateAtBreak(startContainer) {
hyphenateAtBreak(startContainer, breakLetter) {
if (isText(startContainer)) {
let startText = startContainer.textContent;
let prevLetter = startText[startText.length-1];
// Add a hyphen if previous character is a letter or soft hyphen
if (/^\w|\u00AD$/.test(prevLetter)) {
if (
(breakLetter && /^\w|\u00AD$/.test(prevLetter) && /^\w|\u00AD$/.test(breakLetter)) ||
(!breakLetter && /^\w|\u00AD$/.test(prevLetter))
) {
startContainer.parentNode.classList.add("pagedjs_hyphen");
startContainer.textContent += "\u2011";
}
......
......@@ -17,9 +17,10 @@ class Splits extends Handler {
prevPage = pages.children[index - 1];
let from; // Capture the last from element
splits.forEach((split) => {
let ref = split.dataset.ref;
let from = prevPage.querySelector("[data-ref='"+ ref +"']:not([data-split-to])");
from = prevPage.querySelector("[data-ref='"+ ref +"']:not([data-split-to])");
if (from) {
from.dataset.splitTo = ref;
......@@ -27,18 +28,24 @@ class Splits extends Handler {
if (!from.dataset.splitFrom) {
from.dataset.splitOriginal = true;
}
this.handleAlignment(from);
}
});
// Fix alignment on the deepest split element
if (from) {
this.handleAlignment(from);
}
}
handleAlignment(node) {
let styles = window.getComputedStyle(node);
let align = styles["text-align"];
let alignLast = styles["text-align-last"];
node.dataset.lastSplitElement = "true";
if (align === "justify" && alignLast === "auto") {
node.style["text-align-last"] = "justify";
node.dataset.alignLastSplitElement = "justify";
} else {
node.dataset.alignLastSplitElement = alignLast;
}
}
......
......@@ -557,6 +557,11 @@ img {
height: auto;
}
p[data-align-last-split-element='justify'] {
text-align-last: justify;
}
@media print {
html {
width: 100%;
......
import EventEmitter from "event-emitter";
import Hook from "../utils/hook";
import Chunker from "../chunker/chunker";
import Polisher from "../polisher/polisher";
......@@ -17,6 +18,8 @@ class Previewer {
// Hooks
this.hooks = {};
this.hooks.beforePreview = new Hook(this);
this.hooks.afterPreview = new Hook(this);
// default size
this.size = {
......@@ -116,6 +119,8 @@ class Previewer {
async preview(content, stylesheets, renderTo) {
await this.hooks.beforePreview.trigger(content, renderTo);
if (!content) {
content = this.wrapContent();
}
......@@ -142,6 +147,8 @@ class Previewer {
this.emit("rendered", flow);
await this.hooks.afterPreview.trigger(flow.pages);
return flow;
}
}
......
......@@ -3,9 +3,9 @@ import generatedContentHandlers from "../modules/generated-content/index";
import EventEmitter from "event-emitter";
import pipe from "event-emitter/pipe";
let registeredHandlers = [...pagedMediaHandlers, ...generatedContentHandlers];
export let registeredHandlers = [...pagedMediaHandlers, ...generatedContentHandlers];
class Handlers {
export class Handlers {
constructor(chunker, polisher, caller) {
let handlers = [];
......
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