@pdfme/converter 6.0.3 → 6.0.5-dev.1

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.
package/src/pdf2size.ts DELETED
@@ -1,35 +0,0 @@
1
- import type { PDFDocumentProxy } from 'pdfjs-dist';
2
- import { Size, pt2mm } from '@pdfme/common';
3
-
4
- interface Environment {
5
- getDocument: (pdf: ArrayBuffer | Uint8Array) => Promise<PDFDocumentProxy>;
6
- destroyDocument?: (pdfDoc: PDFDocumentProxy) => Promise<void>;
7
- }
8
-
9
- export interface Pdf2SizeOptions {
10
- scale?: number;
11
- }
12
-
13
- export async function pdf2size(
14
- pdf: ArrayBuffer | Uint8Array,
15
- options: Pdf2SizeOptions = {},
16
- env: Environment,
17
- ): Promise<Size[]> {
18
- const { scale = 1 } = options;
19
- const { getDocument, destroyDocument } = env;
20
- const pdfDoc = await getDocument(pdf);
21
-
22
- try {
23
- return await Promise.all(
24
- Array.from({ length: pdfDoc.numPages }, async (_, i) => {
25
- return await pdfDoc.getPage(i + 1).then((page) => {
26
- const { height, width } = page.getViewport({ scale, rotation: 0 });
27
-
28
- return { height: pt2mm(height), width: pt2mm(width) };
29
- });
30
- }),
31
- );
32
- } finally {
33
- await destroyDocument?.(pdfDoc);
34
- }
35
- }
@@ -1,20 +0,0 @@
1
- declare module 'pdfjs-dist/webpack.mjs' {
2
- export * from 'pdfjs-dist';
3
- }
4
-
5
- declare module 'pdfjs-dist/build/pdf.mjs' {
6
- export * from 'pdfjs-dist';
7
- }
8
-
9
- declare module 'pdfjs-dist/build/pdf.worker.mjs';
10
-
11
- declare module 'pdfjs-dist/legacy/build/pdf.mjs' {
12
- export * from 'pdfjs-dist';
13
- }
14
-
15
- declare module 'pdfjs-dist/legacy/build/pdf.worker.mjs';
16
-
17
- declare module '*?worker&url' {
18
- const workerUrl: string;
19
- export default workerUrl;
20
- }
@@ -1,20 +0,0 @@
1
- const uint8ArrayPrototype = Uint8Array.prototype as Uint8Array & {
2
- toHex?: () => string;
3
- };
4
-
5
- if (!uint8ArrayPrototype.toHex) {
6
- Object.defineProperty(Uint8Array.prototype, 'toHex', {
7
- configurable: true,
8
- value(this: Uint8Array) {
9
- let result = '';
10
-
11
- for (let i = 0; i < this.length; i += 1) {
12
- const hex = this[i].toString(16);
13
- result += hex.length === 1 ? `0${hex}` : hex;
14
- }
15
-
16
- return result;
17
- },
18
- writable: true,
19
- });
20
- }
@@ -1,2 +0,0 @@
1
- import './pdfjs-worker-shim.js';
2
- import 'pdfjs-dist/legacy/build/pdf.worker.mjs';
package/src/pdfjs.node.ts DELETED
@@ -1,7 +0,0 @@
1
- import { createRequire } from 'node:module';
2
- import { dirname, join } from 'node:path';
3
-
4
- const require = createRequire(import.meta.url);
5
- const pdfJsDistRoot = dirname(require.resolve('pdfjs-dist/package.json'));
6
-
7
- export const getPdfJsWasmUrl = (): string => join(pdfJsDistRoot, 'wasm/');
package/src/types.d.ts DELETED
@@ -1 +0,0 @@
1
- export type ImageType = 'jpeg' | 'png';
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.build.base.json",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "declarationDir": "./dist",
6
- "emitDeclarationOnly": true,
7
- "module": "ESNext",
8
- "moduleResolution": "bundler",
9
- "outDir": "./dist",
10
- "rootDir": "./src",
11
- "skipLibCheck": true
12
- },
13
- "include": ["src/**/*.ts", "src/**/*.d.ts"]
14
- }
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "composite": true,
5
- "declaration": true,
6
- "declarationDir": "./dist/typecheck",
7
- "emitDeclarationOnly": true,
8
- "module": "ESNext",
9
- "moduleResolution": "bundler",
10
- "outDir": "./dist/typecheck",
11
- "tsBuildInfoFile": "./dist/typecheck/tsconfig.tsbuildinfo",
12
- "skipLibCheck": true
13
- },
14
- "include": ["src/**/*.ts", "src/**/*.d.ts"],
15
- "references": [{ "path": "../common" }, { "path": "../pdf-lib" }]
16
- }
package/vite.config.mts DELETED
@@ -1,70 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { builtinModules } from 'node:module';
3
- import { dirname, resolve } from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import { defineConfig } from 'vite';
6
-
7
- const __dirname = dirname(fileURLToPath(import.meta.url));
8
- const packageJson = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf8')) as {
9
- dependencies?: Record<string, string>;
10
- peerDependencies?: Record<string, string>;
11
- };
12
-
13
- const builtinModuleSet = new Set([
14
- ...builtinModules,
15
- ...builtinModules.map((moduleName) => `node:${moduleName}`),
16
- ]);
17
- const packageDependencies = [
18
- ...Object.keys(packageJson.dependencies ?? {}),
19
- ...Object.keys(packageJson.peerDependencies ?? {}),
20
- ];
21
- const pdfjsWorkerCompatBanner = [
22
- 'const pdfmeUint8ArrayPrototype = Uint8Array.prototype;',
23
- 'if (!pdfmeUint8ArrayPrototype.toHex) {',
24
- " Object.defineProperty(Uint8Array.prototype, 'toHex', {",
25
- ' configurable: true,',
26
- ' value() {',
27
- " let result = '';",
28
- ' for (let i = 0; i < this.length; i += 1) {',
29
- ' const hex = this[i].toString(16);',
30
- ' result += hex.length === 1 ? `0${hex}` : hex;',
31
- ' }',
32
- ' return result;',
33
- ' },',
34
- ' writable: true,',
35
- ' });',
36
- '}',
37
- ].join('\n');
38
-
39
- const isExternal = (id: string) =>
40
- builtinModuleSet.has(id) ||
41
- packageDependencies.some((dependency) => id === dependency || id.startsWith(`${dependency}/`));
42
-
43
- export default defineConfig(() => {
44
- return {
45
- base: './',
46
- build: {
47
- lib: {
48
- entry: {
49
- index: resolve(__dirname, 'src/index.browser.ts'),
50
- 'index.node': resolve(__dirname, 'src/index.node.ts'),
51
- },
52
- fileName: (_, entryName) => `${entryName}.js`,
53
- formats: ['es'],
54
- },
55
- minify: false,
56
- outDir: 'dist',
57
- rollupOptions: { external: isExternal },
58
- sourcemap: true,
59
- target: 'es2020',
60
- },
61
- worker: {
62
- format: 'es',
63
- rollupOptions: {
64
- output: {
65
- banner: pdfjsWorkerCompatBanner,
66
- },
67
- },
68
- },
69
- };
70
- });
File without changes