Skip to content

Commit

Permalink
Import pdfkit to monorepo (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura authored Apr 12, 2021
1 parent e91f2bb commit 87d9d16
Show file tree
Hide file tree
Showing 54 changed files with 30,191 additions and 20 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"rollup-plugin-node-resolve": "^4.0.1",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-string": "^2.0.2",
"rollup-plugin-terser": "^4.0.4"
},
"lint-staged": {
Expand Down
2 changes: 1 addition & 1 deletion packages/layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"@babel/runtime": "^7.6.2",
"@react-pdf/image": "^2.0.0",
"@react-pdf/pdfkit": "^1.6.0",
"@react-pdf/pdfkit": "^2.0.0",
"@react-pdf/primitives": "^2.0.0",
"@react-pdf/stylesheet": "^2.0.2",
"@react-pdf/textkit": "^2.0.0",
Expand Down
41 changes: 41 additions & 0 deletions packages/pdfkit/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = {
extends: ['../../.eslintrc.js'],
rules: {
yoda: 0,
radix: 0,
'no-var': 1,
'one-var': 1,
camelcase: 0,
'no-shadow': 0,
'no-bitwise': 0,
'no-plusplus': 0,
'vars-on-top': 0,
'prefer-const': 0,
'default-case': 1,
'dot-notation': 1,
'guard-for-in': 0,
'no-undef-init': 1,
'no-unused-vars': 1,
'no-else-return': 1,
'no-path-concat': 0,
'import/no-cycle': 0,
'no-multi-assign': 0,
'no-new-wrappers': 1,
'prefer-template': 0,
'no-throw-literal': 0,
'no-return-assign': 0,
'no-useless-escape': 1,
'no-nested-ternary': 0,
'consistent-return': 0,
'no-param-reassign': 0,
'prefer-rest-params': 0,
'prefer-object-spread': 0,
'max-classes-per-file': 0,
'no-restricted-syntax': 0,
'no-use-before-define': 1,
'no-buffer-constructor': 1,
'class-methods-use-this': 0,
'import/no-mutable-exports': 0,
'lines-between-class-members': 0,
},
};
3 changes: 3 additions & 0 deletions packages/pdfkit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.b64.afm
lib
node_modules
4 changes: 4 additions & 0 deletions packages/pdfkit/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "none"
}
8 changes: 8 additions & 0 deletions packages/pdfkit/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MIT LICENSE
Copyright (c) 2014 Devon Govett

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
73 changes: 73 additions & 0 deletions packages/pdfkit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<p align="center">
<img src="https://user-images.githubusercontent.com/5600341/27505816-c8bc37aa-587f-11e7-9a86-08a2d081a8b9.png" height="280px">
</p>

# @react-pdf/textkit

A JavaScript PDF generation library for Node and the browser.

## Acknowledges

This project is a fork of [pdfkit](https://github.com/foliojs/pdfkit) by @devongovett and continued under the scope of this project since it has react-pdf specific features. Any recongnition should go to him and the original project mantainers.

## Description

PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable documents easy.
It's written in CoffeeScript, but you can choose to use the API in plain 'ol JavaScript if you like. The API embraces
chainability, and includes both low level functions as well as abstractions for higher level functionality. The PDFKit API
is designed to be simple, so generating complex documents is often as simple as a few function calls.

Check out some of the [documentation and examples](http://pdfkit.org/docs/getting_started.html) to see for yourself!
You can also read the guide as a [self-generated PDF](http://pdfkit.org/docs/guide.pdf) with example output displayed inline.
If you'd like to see how it was generated, check out the README in the [docs](https://github.com/devongovett/pdfkit/tree/master/docs)
folder.

You can also try out an interactive in-browser demo of PDFKit [here](http://pdfkit.org/demo/browser.html).

## Installation

Installation uses the [npm](http://npmjs.org/) package manager. Just type the following command after installing npm.

npm install @react-pdf/pdfkit

## Features

* Vector graphics
* HTML5 canvas-like API
* Path operations
* SVG path parser for easy path creation
* Transformations
* Linear and radial gradients
* Text
* Line wrapping
* Text alignments
* Bulleted lists
* Font embedding
* Supports TrueType (.ttf), OpenType (.otf), WOFF, WOFF2, TrueType Collections (.ttc), and Datafork TrueType (.dfont) fonts
* Font subsetting
* See [fontkit](http://github.com/devongovett/fontkit) for more details on advanced glyph layout support.
* Image embedding
* Supports JPEG and PNG files (including indexed PNGs, and PNGs with transparency)
* Annotations
* Links
* Notes
* Highlights
* Underlines
* etc.

## Coming soon!

* Patterns fills
* Outlines
* PDF Security
* Higher level APIs for creating tables and laying out content
* More performance optimizations
* Even more awesomeness, perhaps written by you! Please fork this repository and send me pull requests.

## Documentation

For complete API documentation and more examples, see the [PDFKit website](http://pdfkit.org/).

## License

PDFKit is available under the MIT license.
32 changes: 32 additions & 0 deletions packages/pdfkit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@react-pdf/pdfkit",
"version": "2.0.0",
"description": "A PDF generation library for Node.js",
"main": "lib/pdfkit.cjs.js",
"module": "lib/pdfkit.es.js",
"browser": {
"./lib/pdfkit.es.js": "./lib/pdfkit.browser.es.js",
"./lib/pdfkit.cjs.js": "./lib/pdfkit.browser.cjs.js"
},
"author": {
"name": "Devon Govett",
"email": "[email protected]",
"url": "http://badassjs.com/"
},
"scripts": {
"build": "rimraf ./lib && rimraf ./src/font/data/*.b64.afm && node ./src/font/data/compressData.js && rollup -c ",
"watch": "rimraf ./lib && rimraf ./src/font/data/*.b64.afm && node ./src/font/data/compressData.js && rollup -c -w"
},
"files": [
"lib"
],
"dependencies": {
"@react-pdf/fontkit": "^1.15.0",
"@react-pdf/png-js": "^1.0.0",
"lz-string": "^1.4.4"
},
"devDependencies": {
"blob-stream": "^0.1.2",
"iconv-lite": "^0.4.13"
}
}
101 changes: 101 additions & 0 deletions packages/pdfkit/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import nodeResolve from 'rollup-plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import string from 'rollup-plugin-string';
import replace from 'rollup-plugin-replace';
import ignore from 'rollup-plugin-ignore';

import pkg from './package.json';

const cjs = {
exports: 'named',
format: 'cjs',
};

const esm = {
format: 'es',
};

const getCJS = override => Object.assign({}, cjs, override);
const getESM = override => Object.assign({}, esm, override);

const babelConfig = ({ browser }) => ({
babelrc: false,
exclude: 'node_modules/**',
runtimeHelpers: true,
presets: [
[
'@babel/preset-env',
{
loose: true,
modules: false,
...(browser
? { targets: { browsers: 'last 2 versions' } }
: { targets: { node: '12' } }),
},
],
],
});

const configBase = {
input: 'src/index.js',
plugins: [nodeResolve(), json(), string({ include: '**/*.afm' })],
external: Object.keys(pkg.dependencies),
onwarn: (warning, rollupWarn) => {
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
rollupWarn(warning);
}
},
};

const serverConfig = Object.assign({}, configBase, {
output: [
getESM({ file: 'lib/pdfkit.es.js' }),
getCJS({ file: 'lib/pdfkit.cjs.js' }),
],
plugins: configBase.plugins.concat(
babel(babelConfig({ browser: false })),
replace({
BROWSER: JSON.stringify(false),
}),
),
external: configBase.external.concat(['fs']),
});

const serverProdConfig = Object.assign({}, serverConfig, {
output: [
getESM({ file: 'lib/pdfkit.es.min.js' }),
getCJS({ file: 'lib/pdfkit.cjs.min.js' }),
],
plugins: serverConfig.plugins.concat(terser()),
});

const browserConfig = Object.assign({}, configBase, {
output: [
getESM({ file: 'lib/pdfkit.browser.es.js' }),
getCJS({ file: 'lib/pdfkit.browser.cjs.js' }),
],
plugins: configBase.plugins.concat(
babel(babelConfig({ browser: true })),
replace({
BROWSER: JSON.stringify(true),
}),
ignore(['fs']),
),
});

const browserProdConfig = Object.assign({}, browserConfig, {
output: [
getESM({ file: 'lib/pdfkit.browser.es.min.js' }),
getCJS({ file: 'lib/pdfkit.browser.cjs.min.js' }),
],
plugins: browserConfig.plugins.concat(terser()),
});

export default [
serverConfig,
serverProdConfig,
browserConfig,
browserProdConfig,
];
Loading

0 comments on commit 87d9d16

Please sign in to comment.