@pdfme/generator 1.0.0-beta.3 → 1.0.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- import { GenerateProps } from '@pdfme/common';
1
+ import type { GenerateProps } from '@pdfme/common';
2
2
  declare const generate: (props: GenerateProps) => Promise<Uint8Array>;
3
3
  export default generate;
@@ -1,15 +1,14 @@
1
- /// <reference types="node" />
2
1
  import { PDFPage, PDFFont, PDFDocument, PDFImage, PDFEmbeddedPage } from 'pdf-lib';
3
2
  import { Schema, Font, BasePdf, BarCodeType } from '@pdfme/common';
4
3
  export interface InputImageCache {
5
4
  [key: string]: PDFImage;
6
5
  }
7
- export declare const createBarCode: ({ type, input, width, height, backgroundColor, }: {
6
+ export declare const createBarCode: (arg: {
8
7
  type: BarCodeType;
9
8
  input: string;
10
9
  width: number;
11
10
  height: number;
12
- backgroundColor?: string | undefined;
11
+ backgroundColor?: string;
13
12
  }) => Promise<Buffer>;
14
13
  declare type EmbedPdfBox = {
15
14
  mediaBox: {
@@ -0,0 +1,4 @@
1
+ import generate from './generate';
2
+ export { generate };
3
+ export type { Lang, Size, Alignment, SchemaType, BarCodeType, TextSchema, ImageSchema, BarcodeSchema, Schema, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, } from '@pdfme/common';
4
+ export { BLANK_PDF, isTextSchema, isImageSchema, isBarcodeSchema, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput, } from '@pdfme/common';
package/package.json CHANGED
@@ -1,22 +1,25 @@
1
1
  {
2
2
  "name": "@pdfme/generator",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.8",
4
4
  "author": "hand-dot",
5
5
  "license": "MIT",
6
6
  "description": "TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!",
7
7
  "homepage": "https://pdfme.com",
8
- "repository": "git@github.com:pdfme/pdfme.git",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git@github.com:pdfme/pdfme.git"
11
+ },
9
12
  "bugs": {
10
13
  "url": "https://github.com/pdfme/pdfme/issues"
11
14
  },
12
15
  "main": "dist/index.js",
13
- "module": "src/index.ts",
16
+ "module": "dist/index.js",
14
17
  "types": "dist/types/index.d.ts",
15
18
  "engines": {
16
19
  "node": ">=14"
17
20
  },
18
21
  "scripts": {
19
- "develop": "webpack-dev-server --mode development",
22
+ "develop": "webpack --watch --mode development",
20
23
  "build": "NODE_ENV=production webpack --mode production",
21
24
  "clean": "rimraf dist",
22
25
  "lint": "tsc --noEmit",
@@ -27,14 +30,15 @@
27
30
  },
28
31
  "dependencies": {
29
32
  "@pdf-lib/fontkit": "^1.1.1",
30
- "@pdfme/common": "^1.0.0-beta",
31
- "bwip-js": "^3.0.4",
33
+ "@pdfme/common": "^1.0.0-beta.8",
34
+ "bwip-js": "^2.1.3",
32
35
  "pdf-lib": "^1.17.1"
33
36
  },
34
37
  "devDependencies": {
35
38
  "@types/bwip-js": "^3.0.0",
36
39
  "@types/pngjs": "^6.0.1",
37
40
  "jsqr": "^1.4.0",
41
+ "node-polyfill-webpack-plugin": "^1.1.4",
38
42
  "pdf2json": "^2.0.0",
39
43
  "pngjs": "^6.0.0"
40
44
  },
@@ -57,5 +61,8 @@
57
61
  "testMatch": [
58
62
  "**/*.test.ts"
59
63
  ]
64
+ },
65
+ "publishConfig": {
66
+ "access": "public"
60
67
  }
61
68
  }
package/src/generate.ts CHANGED
@@ -1,14 +1,7 @@
1
1
  import { PDFDocument } from 'pdf-lib';
2
2
  import fontkit from '@pdf-lib/fontkit';
3
- import {
4
- GenerateProps,
5
- Template,
6
- Font,
7
- getDefaultFont,
8
- getFallbackFontName,
9
- checkGenerateProps,
10
- } from '@pdfme/common';
11
-
3
+ import type { GenerateProps, Template, Font } from '@pdfme/common';
4
+ import { getDefaultFont, getFallbackFontName, checkGenerateProps } from '@pdfme/common';
12
5
  import {
13
6
  getEmbeddedPagesAndEmbedPdfBoxes,
14
7
  drawInputByTemplateSchema,
package/src/helper.ts CHANGED
@@ -9,7 +9,9 @@ import {
9
9
  setCharacterSpacing,
10
10
  TransformationMatrix,
11
11
  } from 'pdf-lib';
12
- import bwipjs, { ToBufferOptions } from 'bwip-js';
12
+ import { ToBufferOptions } from "bwip-js";
13
+ import bwipjsNode from 'bwip-js/dist/node-bwipjs';
14
+ import bwipjsBrowser from 'bwip-js/dist/bwip-js';
13
15
  import {
14
16
  getB64BasePdf,
15
17
  b64toUint8Array,
@@ -36,40 +38,33 @@ export interface InputImageCache {
36
38
  [key: string]: PDFImage;
37
39
  }
38
40
 
39
- export const createBarCode = async ({
40
- type,
41
- input,
42
- width,
43
- height,
44
- backgroundColor,
45
- }: {
41
+ const barCodeType2Bcid = (type: BarCodeType) => (type === 'nw7' ? 'rationalizedCodabar' : type);
42
+ export const createBarCode = async (arg: {
46
43
  type: BarCodeType;
47
44
  input: string;
48
45
  width: number;
49
46
  height: number;
50
47
  backgroundColor?: string;
51
48
  }): Promise<Buffer> => {
52
- const bwipjsArg: ToBufferOptions = {
53
- bcid: type === 'nw7' ? 'rationalizedCodabar' : type,
54
- text: input,
55
- scale: 5,
56
- width,
57
- height,
58
- includetext: true,
59
- };
49
+ const { type, input, width, height, backgroundColor } = arg;
50
+ const bcid = barCodeType2Bcid(type);
51
+ const includetext = true;
52
+ const scale = 5;
53
+ const bwipjsArg: ToBufferOptions = { bcid, text: input, width, height, scale, includetext };
54
+
60
55
  if (backgroundColor) {
61
56
  bwipjsArg.backgroundcolor = backgroundColor;
62
57
  }
63
58
 
64
59
  let res: Buffer;
65
60
 
66
- if (typeof window !== 'undefined' && bwipjs.toCanvas) {
61
+ if (typeof window !== 'undefined') {
67
62
  const canvas = document.createElement('canvas');
68
- bwipjs.toCanvas(canvas, bwipjsArg);
63
+ bwipjsBrowser.toCanvas(canvas, bwipjsArg);
69
64
  const dataUrl = canvas.toDataURL('image/png');
70
65
  res = b64toUint8Array(dataUrl).buffer as Buffer;
71
66
  } else {
72
- res = await bwipjs.toBuffer(bwipjsArg);
67
+ res = await bwipjsNode.toBuffer(bwipjsArg);
73
68
  }
74
69
 
75
70
  return res;
package/src/index.ts CHANGED
@@ -1,18 +1,16 @@
1
1
  import generate from './generate';
2
- import {
3
- BLANK_PDF,
2
+
3
+ export { generate };
4
+
5
+ export type {
4
6
  Lang,
5
7
  Size,
6
8
  Alignment,
7
9
  SchemaType,
8
- schemaTypes,
9
10
  BarCodeType,
10
11
  TextSchema,
11
- isTextSchema,
12
12
  ImageSchema,
13
- isImageSchema,
14
13
  BarcodeSchema,
15
- isBarcodeSchema,
16
14
  Schema,
17
15
  SchemaForUI,
18
16
  Font,
@@ -24,50 +22,18 @@ import {
24
22
  UIOptions,
25
23
  UIProps,
26
24
  PreviewProps,
27
- PreviewReactProps,
28
25
  DesignerProps,
29
- DesignerReactProps,
30
- checkTemplate,
31
- checkUIProps,
32
- checkPreviewProps,
33
- checkDesignerProps,
34
- checkGenerateProps,
35
- validateBarcodeInput,
36
26
  } from '@pdfme/common';
37
27
 
38
28
  export {
39
- generate,
40
29
  BLANK_PDF,
41
- Lang,
42
- Size,
43
- Alignment,
44
- SchemaType,
45
- schemaTypes,
46
- BarCodeType,
47
- TextSchema,
48
30
  isTextSchema,
49
- ImageSchema,
50
31
  isImageSchema,
51
- BarcodeSchema,
52
32
  isBarcodeSchema,
53
- Schema,
54
- SchemaForUI,
55
- Font,
56
- BasePdf,
57
- Template,
58
- CommonProps,
59
- GeneratorOptions,
60
- GenerateProps,
61
- UIOptions,
62
- UIProps,
63
- PreviewProps,
64
- PreviewReactProps,
65
- DesignerProps,
66
- DesignerReactProps,
67
33
  checkTemplate,
68
34
  checkUIProps,
69
35
  checkPreviewProps,
70
36
  checkDesignerProps,
71
37
  checkGenerateProps,
72
38
  validateBarcodeInput,
73
- };
39
+ } from '@pdfme/common';
package/tsconfig.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "noImplicitAny": true,
4
- "target": "es5",
4
+ "target": "ES2015",
5
5
  "esModuleInterop": true,
6
+ "isolatedModules": true,
6
7
  "declaration": true,
7
8
  "declarationDir": "dist/types",
8
9
  "module": "ES2015",
package/webpack.config.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const path = require('path');
2
+ const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
2
3
  const webpack = require('webpack');
3
4
  // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
4
5
  const pkg = require('./package.json');
@@ -19,6 +20,7 @@ const config = {
19
20
  },
20
21
  plugins: [
21
22
  // new BundleAnalyzerPlugin(),
23
+ new NodePolyfillPlugin(),
22
24
  new webpack.BannerPlugin({
23
25
  banner: BANNER,
24
26
  entryOnly: true,
@@ -35,7 +37,6 @@ const config = {
35
37
  filename: 'index.js',
36
38
  globalObject: 'this',
37
39
  library: {
38
- name: pkg.name,
39
40
  type: 'umd',
40
41
  },
41
42
  },
@@ -1,6 +0,0 @@
1
- export declare const DEFAULT_FONT_SIZE = 13;
2
- export declare const DEFAULT_ALIGNMENT = "left";
3
- export declare const DEFAULT_LINE_HEIGHT = 1;
4
- export declare const DEFAULT_CHARACTER_SPACING = 0;
5
- export declare const DEFAULT_FONT_COLOR = "#000";
6
- export declare const BLANK_PDF = "data:application/pdf;base64,JVBERi0xLjcKJeLjz9MKNSAwIG9iago8PAovRmlsdGVyIC9GbGF0ZURlY29kZQovTGVuZ3RoIDM4Cj4+CnN0cmVhbQp4nCvkMlAwUDC1NNUzMVGwMDHUszRSKErlCtfiyuMK5AIAXQ8GCgplbmRzdHJlYW0KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL01lZGlhQm94IFswIDAgNTk1LjQ0IDg0MS45Ml0KL1Jlc291cmNlcyA8PAo+PgovQ29udGVudHMgNSAwIFIKL1BhcmVudCAyIDAgUgo+PgplbmRvYmoKMiAwIG9iago8PAovVHlwZSAvUGFnZXMKL0tpZHMgWzQgMCBSXQovQ291bnQgMQo+PgplbmRvYmoKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjMgMCBvYmoKPDwKL3RyYXBwZWQgKGZhbHNlKQovQ3JlYXRvciAoU2VyaWYgQWZmaW5pdHkgRGVzaWduZXIgMS4xMC40KQovVGl0bGUgKFVudGl0bGVkLnBkZikKL0NyZWF0aW9uRGF0ZSAoRDoyMDIyMDEwNjE0MDg1OCswOScwMCcpCi9Qcm9kdWNlciAoaUxvdmVQREYpCi9Nb2REYXRlIChEOjIwMjIwMTA2MDUwOTA5WikKPj4KZW5kb2JqCjYgMCBvYmoKPDwKL1NpemUgNwovUm9vdCAxIDAgUgovSW5mbyAzIDAgUgovSUQgWzwyODhCM0VENTAyOEU0MDcyNERBNzNCOUE0Nzk4OUEwQT4gPEY1RkJGNjg4NkVERDZBQUNBNDRCNEZDRjBBRDUxRDlDPl0KL1R5cGUgL1hSZWYKL1cgWzEgMiAyXQovRmlsdGVyIC9GbGF0ZURlY29kZQovSW5kZXggWzAgN10KL0xlbmd0aCAzNgo+PgpzdHJlYW0KeJxjYGD4/5+RUZmBgZHhFZBgDAGxakAEP5BgEmFgAABlRwQJCmVuZHN0cmVhbQplbmRvYmoKc3RhcnR4cmVmCjUzMgolJUVPRgo=";
@@ -1,15 +0,0 @@
1
- import { Template, BasePdf, Font, BarCodeType } from './type';
2
- export declare const getB64BasePdf: (basePdf: BasePdf) => string | Promise<string>;
3
- export declare const b64toUint8Array: (base64: string) => Uint8Array;
4
- export declare const getFallbackFontName: (font: Font) => string;
5
- export declare const getDefaultFont: () => Font;
6
- export declare const checkFont: (arg: {
7
- font: Font;
8
- template: Template;
9
- }) => void;
10
- export declare const checkTemplate: (data: unknown) => void;
11
- export declare const checkUIProps: (data: unknown) => void;
12
- export declare const checkPreviewProps: (data: unknown) => void;
13
- export declare const checkDesignerProps: (data: unknown) => void;
14
- export declare const checkGenerateProps: (data: unknown) => void;
15
- export declare const validateBarcodeInput: (type: BarCodeType, input: string) => boolean;
@@ -1,4 +0,0 @@
1
- import { DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, BLANK_PDF } from './constants';
2
- import { Lang, Size, Alignment, SchemaType, schemaTypes, BarCodeType, TextSchema, isTextSchema, ImageSchema, isImageSchema, BarcodeSchema, isBarcodeSchema, Schema, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, PreviewReactProps, DesignerProps, DesignerReactProps } from './type';
3
- import { getB64BasePdf, b64toUint8Array, getFallbackFontName, getDefaultFont, checkFont, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput } from './helper';
4
- export { DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, BLANK_PDF, Lang, Size, Alignment, SchemaType, schemaTypes, BarCodeType, TextSchema, isTextSchema, ImageSchema, isImageSchema, BarcodeSchema, isBarcodeSchema, Schema, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, PreviewReactProps, DesignerProps, DesignerReactProps, getB64BasePdf, b64toUint8Array, getFallbackFontName, getDefaultFont, checkFont, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput, };