Skip to content

Commit d574bbc

Browse files
committed
refactor: some improvements
1 parent 51d0dec commit d574bbc

24 files changed

Lines changed: 803 additions & 867 deletions

demo/src/main.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pdfeasy, { Utils } from 'pdfeasy'
1+
import pdfeasy from 'pdfeasy'
22
import './style.css'
33

44
const app = document.querySelector<HTMLDivElement>('#app')!
@@ -19,20 +19,15 @@ pdfeasy.new({
1919
})
2020

2121
pdfeasy.add([
22-
{ raw: 'A simple pdf', text: {}},
22+
{ raw: 'A simple pdf', text: { font: 'Roboto' }},
2323
{ lineBreak: {} },
2424
{ raw: 'using...', text: { position: { x: 250, y: 0 }} },
2525
{ raw: 'hm...', text: {} },
2626
{ pageBreak: {} },
2727
{ raw: 'pdfeasy!', text: {} },
28-
...Utils.content(),
29-
...Utils.content(),
30-
...Utils.content(),
3128
{ raw: 'a first in list...', list: { style: 'counter' } },
3229
{ raw: 'a second in list...', list: { style: 'counter' } },
3330
{ raw: 'a third in list...', list: { style: 'counter' } },
34-
...Utils.content(),
35-
...Utils.content(),
3631
{ raw: 'a list with circle...', list: { style: 'circle' } },
3732
{ table: {
3833
body: {

packages/pdfeasy/package.json

Lines changed: 85 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,85 @@
1-
{
2-
"name": "pdfeasy",
3-
"version": "1.2.2",
4-
"description": "Client/Server Side PDF-Creator based in PDFKit",
5-
"author": "Novout <novout@hotmail.com>",
6-
"license": "MIT",
7-
"repository": "https://github.com/betterwrite/pdfeasy",
8-
"bugs": {
9-
"url": "https://github.com/betterwrite/pdfeasy/issues"
10-
},
11-
"keywords": [
12-
"pdfkit",
13-
"pdf",
14-
"typescript",
15-
"javascript",
16-
"printing",
17-
"layout"
18-
],
19-
"browser": {
20-
"path": "path-browserify",
21-
"crypto": "crypto-browserify",
22-
"stream": "stream-browserify"
23-
},
24-
"exports": {
25-
".": {
26-
"import": "./dist/client.esm.js",
27-
"require": "./dist/client.cjs.js",
28-
"node": "./dist/node.esm.js",
29-
"types": "./dist/index.d.ts"
30-
}
31-
},
32-
"main": "./dist/client.cjs.js",
33-
"module": "./dist/client.esm.js",
34-
"node": "./dist/node.esm.js",
35-
"types": "./dist/index.d.ts",
36-
"scripts": {
37-
"format": "prettier src/**/*.ts scripts/**/*.js --write",
38-
"build": "rimraf dist && cross-env NODE_ENV=development node scripts/build.js && pnpm run normalizeDts",
39-
"build:prod": "rimraf dist && cross-env NODE_ENV=production node scripts/build.js && pnpm run normalizeDts",
40-
"normalizeDts": "tsup ./src/index.ts --dts && rimraf dist/index.js",
41-
"test": "pnpm build:prod && vitest run --coverage",
42-
"node:script": "node -r esm ./scripts/generate/run-node.js",
43-
"demo": "vite --port 3000"
44-
},
45-
"files": [
46-
"dist/**/*",
47-
"LICENSE",
48-
"README.md"
49-
],
50-
"engines": {
51-
"node": ">=14.0"
52-
},
53-
"dependencies": {
54-
"blob-stream": "0.1.3",
55-
"file-saver": "2.0.5",
56-
"fontkit-next": "1.8.3",
57-
"mitt": "3.0.0",
58-
"ohmyfetch": "0.4.21",
59-
"pdfkit": "0.13.0",
60-
"pdfkit-table": "^0.1.99"
61-
},
62-
"devDependencies": {
63-
"@types/blob-stream": "0.1.30",
64-
"@types/file-saver": "2.0.5",
65-
"@types/node": "20.1.2",
66-
"@types/pdfkit": "0.12.9",
67-
"@vitest/coverage-c8": "0.31.0",
68-
"cross-env": "7.0.3",
69-
"esbuild": "0.17.18",
70-
"esbuild-plugin-alias": "0.2.1",
71-
"esbuild-plugin-fileloc": "0.0.6",
72-
"esbuild-plugin-replace": "1.3.0",
73-
"esbuild-plugin-resolve": "1.0.3",
74-
"esm": "3.2.25",
75-
"node-stdlib-browser": "1.2.0",
76-
"prettier": "2.8.8",
77-
"rimraf": "5.0.0",
78-
"tsup": "6.7.0",
79-
"typescript": "5.0.4",
80-
"vite": "4.3.5",
81-
"vitest": "0.31.0"
82-
}
83-
}
1+
{
2+
"name": "pdfeasy",
3+
"version": "1.2.2",
4+
"description": "Client/Server Side PDF-Creator based in PDFKit",
5+
"author": "Novout <novout@hotmail.com>",
6+
"license": "MIT",
7+
"repository": "https://github.com/betterwrite/pdfeasy",
8+
"bugs": {
9+
"url": "https://github.com/betterwrite/pdfeasy/issues"
10+
},
11+
"keywords": [
12+
"pdfkit",
13+
"pdf",
14+
"typescript",
15+
"javascript",
16+
"printing",
17+
"layout"
18+
],
19+
"browser": {
20+
"path": "path-browserify",
21+
"crypto": "crypto-browserify",
22+
"stream": "stream-browserify"
23+
},
24+
"exports": {
25+
".": {
26+
"import": "./dist/client.esm.js",
27+
"require": "./dist/client.cjs.js",
28+
"node": "./dist/node.esm.js",
29+
"types": "./dist/index.d.ts"
30+
}
31+
},
32+
"main": "./dist/client.cjs.js",
33+
"module": "./dist/client.esm.js",
34+
"node": "./dist/node.esm.js",
35+
"types": "./dist/index.d.ts",
36+
"scripts": {
37+
"format": "prettier src/**/*.ts scripts/**/*.js --write",
38+
"build": "rimraf dist && cross-env NODE_ENV=development node scripts/build.js && pnpm run normalizeDts",
39+
"build:prod": "rimraf dist && cross-env NODE_ENV=production node scripts/build.js && pnpm run normalizeDts",
40+
"normalizeDts": "tsup ./src/index.ts --dts && rimraf dist/index.js",
41+
"test": "pnpm build:prod && vitest run --coverage",
42+
"node:script": "node -r esm ./scripts/generate/run-node.js",
43+
"demo": "vite --port 3000"
44+
},
45+
"files": [
46+
"dist/**/*",
47+
"LICENSE",
48+
"README.md"
49+
],
50+
"engines": {
51+
"node": ">=14.0"
52+
},
53+
"dependencies": {
54+
"blob-stream": "0.1.3",
55+
"defu": "6.1.2",
56+
"file-saver": "2.0.5",
57+
"fontkit-next": "1.8.3",
58+
"mitt": "3.0.0",
59+
"ohmyfetch": "0.4.21",
60+
"pdfkit": "0.13.0",
61+
"pdfkit-table": "^0.1.99"
62+
},
63+
"devDependencies": {
64+
"@types/blob-stream": "0.1.30",
65+
"@types/file-saver": "2.0.5",
66+
"@types/node": "20.1.2",
67+
"@types/pdfkit": "0.12.9",
68+
"@vitest/coverage-c8": "0.31.0",
69+
"cross-env": "7.0.3",
70+
"esbuild": "0.17.18",
71+
"esbuild-plugin-alias": "0.2.1",
72+
"esbuild-plugin-fileloc": "0.0.6",
73+
"esbuild-plugin-replace": "1.3.0",
74+
"esbuild-plugin-resolve": "1.0.3",
75+
"esm": "3.2.25",
76+
"happy-dom": "9.20.3",
77+
"node-stdlib-browser": "1.2.0",
78+
"prettier": "2.8.8",
79+
"rimraf": "5.0.0",
80+
"tsup": "6.7.0",
81+
"typescript": "5.0.4",
82+
"vite": "4.3.5",
83+
"vitest": "0.31.0"
84+
}
85+
}

packages/pdfeasy/src/content/image.ts

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PDFEasy } from '../runner/pdfeasy'
1+
import { PDFEasy } from './runner'
22

33
export const onPageAdded = (instance: PDFEasy, cb: any) => {
44
instance.pdfkit?.on('pageAdded', () => {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { $fetch } from 'ohmyfetch'
2+
import { regex } from './utils'
3+
import { ImageRaw } from './types'
24

35
export const getBase64ByURL = (
46
data: string,
@@ -41,3 +43,29 @@ export const getDataUri = (url: string): Promise<string> => {
4143
image.src = url
4244
})
4345
}
46+
47+
export const getRequestImageRaw = (raw: string): Promise<ImageRaw> => {
48+
return new Promise(async (res) => {
49+
if (regex().base64(raw)) {
50+
res({
51+
raw,
52+
type: 'base64',
53+
})
54+
}
55+
56+
if (regex().http(raw)) {
57+
await getDataUri(raw).then((data: string) => {
58+
res({
59+
raw: data,
60+
type: 'http',
61+
})
62+
})
63+
}
64+
65+
// TODO: getDataUri type
66+
res({
67+
raw,
68+
type: 'base64',
69+
})
70+
})
71+
}

packages/pdfeasy/src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { PDFEasy } from './runner/pdfeasy'
1+
import { PDFEasy } from './runner'
22

33
export default new PDFEasy()
4-
export * from './runner/pdfeasy'
4+
export * from './runner'
55

6-
export * as Utils from './utils'
76
export * as Types from './types'

packages/pdfeasy/src/pipe/setter.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

packages/pdfeasy/src/pipe/transform.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)