Skip to content

Commit

Permalink
refactor: some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Jun 17, 2023
1 parent 51d0dec commit d574bbc
Show file tree
Hide file tree
Showing 24 changed files with 803 additions and 867 deletions.
9 changes: 2 additions & 7 deletions demo/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pdfeasy, { Utils } from 'pdfeasy'
import pdfeasy from 'pdfeasy'
import './style.css'

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

pdfeasy.add([
{ raw: 'A simple pdf', text: {}},
{ raw: 'A simple pdf', text: { font: 'Roboto' }},
{ lineBreak: {} },
{ raw: 'using...', text: { position: { x: 250, y: 0 }} },
{ raw: 'hm...', text: {} },
{ pageBreak: {} },
{ raw: 'pdfeasy!', text: {} },
...Utils.content(),
...Utils.content(),
...Utils.content(),
{ raw: 'a first in list...', list: { style: 'counter' } },
{ raw: 'a second in list...', list: { style: 'counter' } },
{ raw: 'a third in list...', list: { style: 'counter' } },
...Utils.content(),
...Utils.content(),
{ raw: 'a list with circle...', list: { style: 'circle' } },
{ table: {
body: {
Expand Down
168 changes: 85 additions & 83 deletions packages/pdfeasy/package.json
Original file line number Diff line number Diff line change
@@ -1,83 +1,85 @@
{
"name": "pdfeasy",
"version": "1.2.2",
"description": "Client/Server Side PDF-Creator based in PDFKit",
"author": "Novout <novout@hotmail.com>",
"license": "MIT",
"repository": "https://github.com/betterwrite/pdfeasy",
"bugs": {
"url": "https://github.com/betterwrite/pdfeasy/issues"
},
"keywords": [
"pdfkit",
"pdf",
"typescript",
"javascript",
"printing",
"layout"
],
"browser": {
"path": "path-browserify",
"crypto": "crypto-browserify",
"stream": "stream-browserify"
},
"exports": {
".": {
"import": "./dist/client.esm.js",
"require": "./dist/client.cjs.js",
"node": "./dist/node.esm.js",
"types": "./dist/index.d.ts"
}
},
"main": "./dist/client.cjs.js",
"module": "./dist/client.esm.js",
"node": "./dist/node.esm.js",
"types": "./dist/index.d.ts",
"scripts": {
"format": "prettier src/**/*.ts scripts/**/*.js --write",
"build": "rimraf dist && cross-env NODE_ENV=development node scripts/build.js && pnpm run normalizeDts",
"build:prod": "rimraf dist && cross-env NODE_ENV=production node scripts/build.js && pnpm run normalizeDts",
"normalizeDts": "tsup ./src/index.ts --dts && rimraf dist/index.js",
"test": "pnpm build:prod && vitest run --coverage",
"node:script": "node -r esm ./scripts/generate/run-node.js",
"demo": "vite --port 3000"
},
"files": [
"dist/**/*",
"LICENSE",
"README.md"
],
"engines": {
"node": ">=14.0"
},
"dependencies": {
"blob-stream": "0.1.3",
"file-saver": "2.0.5",
"fontkit-next": "1.8.3",
"mitt": "3.0.0",
"ohmyfetch": "0.4.21",
"pdfkit": "0.13.0",
"pdfkit-table": "^0.1.99"
},
"devDependencies": {
"@types/blob-stream": "0.1.30",
"@types/file-saver": "2.0.5",
"@types/node": "20.1.2",
"@types/pdfkit": "0.12.9",
"@vitest/coverage-c8": "0.31.0",
"cross-env": "7.0.3",
"esbuild": "0.17.18",
"esbuild-plugin-alias": "0.2.1",
"esbuild-plugin-fileloc": "0.0.6",
"esbuild-plugin-replace": "1.3.0",
"esbuild-plugin-resolve": "1.0.3",
"esm": "3.2.25",
"node-stdlib-browser": "1.2.0",
"prettier": "2.8.8",
"rimraf": "5.0.0",
"tsup": "6.7.0",
"typescript": "5.0.4",
"vite": "4.3.5",
"vitest": "0.31.0"
}
}
{
"name": "pdfeasy",
"version": "1.2.2",
"description": "Client/Server Side PDF-Creator based in PDFKit",
"author": "Novout <novout@hotmail.com>",
"license": "MIT",
"repository": "https://github.com/betterwrite/pdfeasy",
"bugs": {
"url": "https://github.com/betterwrite/pdfeasy/issues"
},
"keywords": [
"pdfkit",
"pdf",
"typescript",
"javascript",
"printing",
"layout"
],
"browser": {
"path": "path-browserify",
"crypto": "crypto-browserify",
"stream": "stream-browserify"
},
"exports": {
".": {
"import": "./dist/client.esm.js",
"require": "./dist/client.cjs.js",
"node": "./dist/node.esm.js",
"types": "./dist/index.d.ts"
}
},
"main": "./dist/client.cjs.js",
"module": "./dist/client.esm.js",
"node": "./dist/node.esm.js",
"types": "./dist/index.d.ts",
"scripts": {
"format": "prettier src/**/*.ts scripts/**/*.js --write",
"build": "rimraf dist && cross-env NODE_ENV=development node scripts/build.js && pnpm run normalizeDts",
"build:prod": "rimraf dist && cross-env NODE_ENV=production node scripts/build.js && pnpm run normalizeDts",
"normalizeDts": "tsup ./src/index.ts --dts && rimraf dist/index.js",
"test": "pnpm build:prod && vitest run --coverage",
"node:script": "node -r esm ./scripts/generate/run-node.js",
"demo": "vite --port 3000"
},
"files": [
"dist/**/*",
"LICENSE",
"README.md"
],
"engines": {
"node": ">=14.0"
},
"dependencies": {
"blob-stream": "0.1.3",
"defu": "6.1.2",
"file-saver": "2.0.5",
"fontkit-next": "1.8.3",
"mitt": "3.0.0",
"ohmyfetch": "0.4.21",
"pdfkit": "0.13.0",
"pdfkit-table": "^0.1.99"
},
"devDependencies": {
"@types/blob-stream": "0.1.30",
"@types/file-saver": "2.0.5",
"@types/node": "20.1.2",
"@types/pdfkit": "0.12.9",
"@vitest/coverage-c8": "0.31.0",
"cross-env": "7.0.3",
"esbuild": "0.17.18",
"esbuild-plugin-alias": "0.2.1",
"esbuild-plugin-fileloc": "0.0.6",
"esbuild-plugin-replace": "1.3.0",
"esbuild-plugin-resolve": "1.0.3",
"esm": "3.2.25",
"happy-dom": "9.20.3",
"node-stdlib-browser": "1.2.0",
"prettier": "2.8.8",
"rimraf": "5.0.0",
"tsup": "6.7.0",
"typescript": "5.0.4",
"vite": "4.3.5",
"vitest": "0.31.0"
}
}
68 changes: 0 additions & 68 deletions packages/pdfeasy/src/content/image.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PDFEasy } from '../runner/pdfeasy'
import { PDFEasy } from './runner'

export const onPageAdded = (instance: PDFEasy, cb: any) => {
instance.pdfkit?.on('pageAdded', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { $fetch } from 'ohmyfetch'
import { regex } from './utils'
import { ImageRaw } from './types'

export const getBase64ByURL = (
data: string,
Expand Down Expand Up @@ -41,3 +43,29 @@ export const getDataUri = (url: string): Promise<string> => {
image.src = url
})
}

export const getRequestImageRaw = (raw: string): Promise<ImageRaw> => {
return new Promise(async (res) => {
if (regex().base64(raw)) {
res({
raw,
type: 'base64',
})
}

if (regex().http(raw)) {
await getDataUri(raw).then((data: string) => {
res({
raw: data,
type: 'http',
})
})
}

// TODO: getDataUri type
res({
raw,
type: 'base64',
})
})
}
5 changes: 2 additions & 3 deletions packages/pdfeasy/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PDFEasy } from './runner/pdfeasy'
import { PDFEasy } from './runner'

export default new PDFEasy()
export * from './runner/pdfeasy'
export * from './runner'

export * as Utils from './utils'
export * as Types from './types'
34 changes: 0 additions & 34 deletions packages/pdfeasy/src/pipe/setter.ts

This file was deleted.

28 changes: 0 additions & 28 deletions packages/pdfeasy/src/pipe/transform.ts

This file was deleted.

Loading

0 comments on commit d574bbc

Please sign in to comment.