pdf-password-remover 0.1.0 → 0.2.0
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/CHANGELOG.md +18 -0
- package/README.md +37 -0
- package/bin/pdf-password-remover.js +26 -0
- package/build-package.sh +5 -1
- package/dist/SHA256SUMS +4 -0
- package/dist/node.d.ts +9 -0
- package/dist/node.js +35 -0
- package/dist/vite.d.ts +34 -0
- package/dist/vite.js +106 -0
- package/docs/API.md +32 -0
- package/docs/INTEGRATION.md +34 -3
- package/llms-full.txt +14 -1
- package/llms.txt +6 -0
- package/package.json +17 -3
- package/prepare-package.sh +4 -0
- package/src/node.d.ts +9 -0
- package/src/node.js +35 -0
- package/src/vite.d.ts +34 -0
- package/src/vite.js +106 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- Add `pdf-password-remover/vite`, which serves runtime assets in development
|
|
6
|
+
and emits them during production builds.
|
|
7
|
+
- Add `pdf-password-remover copy-assets <output-directory>` for projects that
|
|
8
|
+
use other bundlers or static asset pipelines.
|
|
9
|
+
- Add `pdf-password-remover/node` for programmatic asset copying in Node.js
|
|
10
|
+
build tooling.
|
|
11
|
+
|
|
12
|
+
## 0.1.1
|
|
13
|
+
|
|
14
|
+
- Correct package README metadata.
|
|
15
|
+
|
|
16
|
+
## 0.1.0
|
|
17
|
+
|
|
18
|
+
- Initial public release.
|
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ Decrypt password-protected PDFs locally in the browser using QPDF compiled to We
|
|
|
4
4
|
|
|
5
5
|
Created and maintained by [HafzalBZ](https://github.com/HafzalBZ). Source, generated WebAssembly artifacts, and reproducible build instructions are published at [github.com/HafzalBZ/pdf-password-remover](https://github.com/HafzalBZ/pdf-password-remover).
|
|
6
6
|
|
|
7
|
+
Use the hosted browser tool at [hafzalbz.github.io/pdf-password-remover](https://hafzalbz.github.io/pdf-password-remover/). The selected PDF and password remain in your browser.
|
|
8
|
+
|
|
7
9
|
## Install
|
|
8
10
|
|
|
9
11
|
```sh
|
|
@@ -27,6 +29,40 @@ Accepted inputs are `File`, `Blob`, `ArrayBuffer`, and typed-array views. The re
|
|
|
27
29
|
|
|
28
30
|
This package does not crack or recover unknown passwords. Only use it for documents you own or are authorized to decrypt.
|
|
29
31
|
|
|
32
|
+
## Vite
|
|
33
|
+
|
|
34
|
+
Add the package plugin once. It serves the worker and WASM during development
|
|
35
|
+
and emits them into the production build automatically.
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import { defineConfig } from 'vite';
|
|
39
|
+
import { pdfPasswordRemoverPlugin } from 'pdf-password-remover/vite';
|
|
40
|
+
|
|
41
|
+
export default defineConfig({
|
|
42
|
+
plugins: [pdfPasswordRemoverPlugin()],
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Use the matching same-origin worker URL when decrypting:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
await decryptPdf(file, password, {
|
|
50
|
+
workerUrl: `${import.meta.env.BASE_URL}vendor/pdf-password-remover/pdf-worker.js`,
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Other build systems
|
|
55
|
+
|
|
56
|
+
Copy the three runtime assets from the installed package as part of the host
|
|
57
|
+
application's build:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
npx pdf-password-remover copy-assets public/vendor/pdf-password-remover
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The command is explicit: installing the package does not run a `postinstall`
|
|
64
|
+
script or write into the consuming project.
|
|
65
|
+
|
|
30
66
|
## Build from source
|
|
31
67
|
|
|
32
68
|
Requirements: Docker and network access for the first build.
|
|
@@ -69,6 +105,7 @@ No `SharedArrayBuffer`, WebAssembly threads, COOP, or COEP is required.
|
|
|
69
105
|
- [API reference](docs/API.md)
|
|
70
106
|
- [Integration guide](docs/INTEGRATION.md)
|
|
71
107
|
- [Security model](docs/SECURITY.md)
|
|
108
|
+
- [Changelog](CHANGELOG.md)
|
|
72
109
|
- [LLM quick context](llms.txt)
|
|
73
110
|
- [LLM complete context](llms-full.txt)
|
|
74
111
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright (c) 2026 HafzalBZ. SPDX-License-Identifier: MIT
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
|
|
5
|
+
import { copyPdfPasswordRemoverAssets } from '../dist/node.js';
|
|
6
|
+
|
|
7
|
+
const [, , command, outputDirectory, ...extraArguments] = process.argv;
|
|
8
|
+
|
|
9
|
+
if (
|
|
10
|
+
command !== 'copy-assets' ||
|
|
11
|
+
!outputDirectory ||
|
|
12
|
+
extraArguments.length > 0
|
|
13
|
+
) {
|
|
14
|
+
console.error(
|
|
15
|
+
'Usage: pdf-password-remover copy-assets <output-directory>',
|
|
16
|
+
);
|
|
17
|
+
process.exitCode = 1;
|
|
18
|
+
} else {
|
|
19
|
+
try {
|
|
20
|
+
await copyPdfPasswordRemoverAssets(outputDirectory);
|
|
21
|
+
console.log(`Copied PDF password remover assets to ${outputDirectory}`);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
24
|
+
process.exitCode = 1;
|
|
25
|
+
}
|
|
26
|
+
}
|
package/build-package.sh
CHANGED
|
@@ -8,13 +8,17 @@ root_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
|
8
8
|
mkdir -p "$root_dir/dist"
|
|
9
9
|
cp "$root_dir/src/index.js" "$root_dir/dist/index.js"
|
|
10
10
|
cp "$root_dir/src/index.d.ts" "$root_dir/dist/index.d.ts"
|
|
11
|
+
cp "$root_dir/src/node.js" "$root_dir/dist/node.js"
|
|
12
|
+
cp "$root_dir/src/node.d.ts" "$root_dir/dist/node.d.ts"
|
|
13
|
+
cp "$root_dir/src/vite.js" "$root_dir/dist/vite.js"
|
|
14
|
+
cp "$root_dir/src/vite.d.ts" "$root_dir/dist/vite.d.ts"
|
|
11
15
|
cp "$root_dir/src/pdf-worker.js" "$root_dir/dist/pdf-worker.js"
|
|
12
16
|
cp "$root_dir/web/pdf-decrypt.js" "$root_dir/dist/pdf-decrypt.js"
|
|
13
17
|
cp "$root_dir/web/pdf-decrypt.wasm" "$root_dir/dist/pdf-decrypt.wasm"
|
|
14
18
|
|
|
15
19
|
(
|
|
16
20
|
cd "$root_dir/dist"
|
|
17
|
-
files="pdf-decrypt.js pdf-decrypt.wasm index.js index.d.ts pdf-worker.js"
|
|
21
|
+
files="pdf-decrypt.js pdf-decrypt.wasm index.js index.d.ts node.js node.d.ts vite.js vite.d.ts pdf-worker.js"
|
|
18
22
|
if command -v sha256sum >/dev/null 2>&1; then
|
|
19
23
|
sha256sum $files > SHA256SUMS
|
|
20
24
|
else
|
package/dist/SHA256SUMS
CHANGED
|
@@ -2,4 +2,8 @@
|
|
|
2
2
|
3032d35d2271559b88203310d03c79172e60a37bf3b9961738df802063894a89 pdf-decrypt.wasm
|
|
3
3
|
1123a3d5cae26607e43273a5347da2e6dfb680e05d2d066901aaa372fa8d4f0b index.js
|
|
4
4
|
2e2b220ac864c8c61a36595d36e6f4911f1120ba4c3ee366e9addbc80151caf3 index.d.ts
|
|
5
|
+
169e0544aa5c0e91b92c9eb40fe05ef3297b4e8c062e70c69d5e6be0049243bd node.js
|
|
6
|
+
fec80f1c9f418178f9514173bf1678cbedb189dd4ebfcc3d6f81d38d283845fa node.d.ts
|
|
7
|
+
0ebff692e4710df65df3e74f17fb72f2c9c79078abd70633c6c2792f48754e12 vite.js
|
|
8
|
+
881f22b3a71bf4dc41efbcfc773d06d5d8c14746ebfe56619f67c40340b96ad9 vite.d.ts
|
|
5
9
|
cb2f1fac3f857e975a99600365f77261dc46a828f604b056fc0f32b476f6d567 pdf-worker.js
|
package/dist/node.d.ts
ADDED
package/dist/node.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright (c) 2026 HafzalBZ. SPDX-License-Identifier: MIT
|
|
2
|
+
import { copyFile, mkdir } from 'node:fs/promises';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
|
|
6
|
+
export const pdfPasswordRemoverAssetNames = Object.freeze([
|
|
7
|
+
'pdf-worker.js',
|
|
8
|
+
'pdf-decrypt.js',
|
|
9
|
+
'pdf-decrypt.wasm',
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
export async function copyPdfPasswordRemoverAssets(outputDirectory) {
|
|
13
|
+
if (
|
|
14
|
+
typeof outputDirectory !== 'string' &&
|
|
15
|
+
!(outputDirectory instanceof URL)
|
|
16
|
+
) {
|
|
17
|
+
throw new TypeError('outputDirectory must be a path string or file URL.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
await mkdir(outputDirectory, { recursive: true });
|
|
21
|
+
|
|
22
|
+
await Promise.all(pdfPasswordRemoverAssetNames.map((assetName) => copyFile(
|
|
23
|
+
new URL(`./${assetName}`, import.meta.url),
|
|
24
|
+
new URL(`./${assetName}`, toDirectoryUrl(outputDirectory)),
|
|
25
|
+
)));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function toDirectoryUrl(directory) {
|
|
29
|
+
if (directory instanceof URL) {
|
|
30
|
+
return new URL(directory.href.endsWith('/') ? directory.href : `${directory.href}/`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const resolved = pathToFileURL(resolve(directory));
|
|
34
|
+
return new URL(resolved.href.endsWith('/') ? resolved.href : `${resolved.href}/`);
|
|
35
|
+
}
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface PdfPasswordRemoverPluginOptions {
|
|
2
|
+
/** Output directory relative to Vite's public base. */
|
|
3
|
+
assetDirectory?: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface PdfPasswordRemoverVitePlugin {
|
|
7
|
+
name: 'pdf-password-remover';
|
|
8
|
+
enforce: 'pre';
|
|
9
|
+
configResolved(config: { base: string }): void;
|
|
10
|
+
configureServer(server: {
|
|
11
|
+
middlewares: {
|
|
12
|
+
use(handler: (
|
|
13
|
+
request: { method?: string; url?: string },
|
|
14
|
+
response: {
|
|
15
|
+
statusCode: number;
|
|
16
|
+
setHeader(name: string, value: string | number): void;
|
|
17
|
+
end(body?: Uint8Array): void;
|
|
18
|
+
},
|
|
19
|
+
next: (error?: unknown) => void,
|
|
20
|
+
) => void): void;
|
|
21
|
+
};
|
|
22
|
+
}): void;
|
|
23
|
+
generateBundle(this: {
|
|
24
|
+
emitFile(asset: {
|
|
25
|
+
type: 'asset';
|
|
26
|
+
fileName: string;
|
|
27
|
+
source: Uint8Array;
|
|
28
|
+
}): void;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export declare function pdfPasswordRemoverPlugin(
|
|
33
|
+
options?: PdfPasswordRemoverPluginOptions,
|
|
34
|
+
): PdfPasswordRemoverVitePlugin;
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Copyright (c) 2026 HafzalBZ. SPDX-License-Identifier: MIT
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
|
|
4
|
+
import { pdfPasswordRemoverAssetNames } from './node.js';
|
|
5
|
+
|
|
6
|
+
const contentTypes = Object.freeze({
|
|
7
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
8
|
+
'.wasm': 'application/wasm',
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export function pdfPasswordRemoverPlugin(options = {}) {
|
|
12
|
+
const assetDirectory = normalizeAssetDirectory(
|
|
13
|
+
options.assetDirectory ?? 'vendor/pdf-password-remover',
|
|
14
|
+
);
|
|
15
|
+
let base = '/';
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
name: 'pdf-password-remover',
|
|
19
|
+
enforce: 'pre',
|
|
20
|
+
|
|
21
|
+
configResolved(config) {
|
|
22
|
+
base = normalizeBase(config.base);
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
configureServer(server) {
|
|
26
|
+
const requestPrefix = `${base}${assetDirectory}/`;
|
|
27
|
+
|
|
28
|
+
server.middlewares.use(async (request, response, next) => {
|
|
29
|
+
try {
|
|
30
|
+
const pathname = new URL(
|
|
31
|
+
request.url ?? '/',
|
|
32
|
+
'http://pdf-password-remover.local',
|
|
33
|
+
).pathname;
|
|
34
|
+
|
|
35
|
+
if (!pathname.startsWith(requestPrefix)) {
|
|
36
|
+
next();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const assetName = pathname.slice(requestPrefix.length);
|
|
41
|
+
if (!pdfPasswordRemoverAssetNames.includes(assetName)) {
|
|
42
|
+
next();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const source = await readPackageAsset(assetName);
|
|
47
|
+
response.statusCode = 200;
|
|
48
|
+
response.setHeader('Content-Type', contentTypeFor(assetName));
|
|
49
|
+
response.setHeader('Content-Length', source.byteLength);
|
|
50
|
+
response.setHeader('Cache-Control', 'no-cache');
|
|
51
|
+
|
|
52
|
+
if (request.method === 'HEAD') {
|
|
53
|
+
response.end();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
response.end(source);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
next(error);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
async generateBundle() {
|
|
65
|
+
await Promise.all(pdfPasswordRemoverAssetNames.map(async (assetName) => {
|
|
66
|
+
this.emitFile({
|
|
67
|
+
type: 'asset',
|
|
68
|
+
fileName: `${assetDirectory}/${assetName}`,
|
|
69
|
+
source: await readPackageAsset(assetName),
|
|
70
|
+
});
|
|
71
|
+
}));
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function normalizeAssetDirectory(value) {
|
|
77
|
+
if (typeof value !== 'string') {
|
|
78
|
+
throw new TypeError('assetDirectory must be a string.');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const normalized = value.replaceAll('\\', '/').replace(/^\/+|\/+$/g, '');
|
|
82
|
+
const segments = normalized.split('/');
|
|
83
|
+
|
|
84
|
+
if (
|
|
85
|
+
normalized.length === 0 ||
|
|
86
|
+
segments.some((segment) => segment === '.' || segment === '..' || segment === '')
|
|
87
|
+
) {
|
|
88
|
+
throw new TypeError('assetDirectory must be a non-empty relative directory.');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return normalized;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function normalizeBase(value) {
|
|
95
|
+
const base = typeof value === 'string' && value.length > 0 ? value : '/';
|
|
96
|
+
return `${base.startsWith('/') ? '' : '/'}${base.replace(/\/*$/, '/')}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function contentTypeFor(assetName) {
|
|
100
|
+
const extension = assetName.endsWith('.wasm') ? '.wasm' : '.js';
|
|
101
|
+
return contentTypes[extension];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function readPackageAsset(assetName) {
|
|
105
|
+
return readFile(new URL(`./${assetName}`, import.meta.url));
|
|
106
|
+
}
|
package/docs/API.md
CHANGED
|
@@ -41,3 +41,35 @@ All expected failures reject with `PdfDecryptError`, whose `code` is stable acro
|
|
|
41
41
|
| `UNSUPPORTED_BROWSER` | A required browser API is unavailable. |
|
|
42
42
|
| `WASM_FAILURE` | Worker or WASM initialization failed. |
|
|
43
43
|
| `PROCESSING_FAILED` | An otherwise unclassified decryption failure occurred. |
|
|
44
|
+
|
|
45
|
+
## `pdf-password-remover/vite`
|
|
46
|
+
|
|
47
|
+
`pdfPasswordRemoverPlugin(options?)` returns a Vite plugin that serves the
|
|
48
|
+
worker, Emscripten bridge, and WASM file in development and emits them in
|
|
49
|
+
production builds.
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
function pdfPasswordRemoverPlugin(options?: {
|
|
53
|
+
assetDirectory?: string;
|
|
54
|
+
}): VitePlugin;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`assetDirectory` defaults to `vendor/pdf-password-remover` and must be a safe
|
|
58
|
+
relative directory.
|
|
59
|
+
|
|
60
|
+
## `pdf-password-remover/node`
|
|
61
|
+
|
|
62
|
+
Build tools can copy the installed package's version-matched runtime assets
|
|
63
|
+
programmatically:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
function copyPdfPasswordRemoverAssets(
|
|
67
|
+
outputDirectory: string | URL,
|
|
68
|
+
): Promise<void>;
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The equivalent CLI is:
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
pdf-password-remover copy-assets <output-directory>
|
|
75
|
+
```
|
package/docs/INTEGRATION.md
CHANGED
|
@@ -1,14 +1,45 @@
|
|
|
1
1
|
# Integration and deployment
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Vite
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Use the package-owned plugin so Vite serves and emits all version-matched
|
|
6
|
+
runtime assets:
|
|
7
|
+
|
|
8
|
+
```js
|
|
9
|
+
import { defineConfig } from 'vite';
|
|
10
|
+
import { pdfPasswordRemoverPlugin } from 'pdf-password-remover/vite';
|
|
11
|
+
|
|
12
|
+
export default defineConfig({
|
|
13
|
+
plugins: [pdfPasswordRemoverPlugin()],
|
|
14
|
+
});
|
|
15
|
+
```
|
|
6
16
|
|
|
7
17
|
```js
|
|
8
18
|
import { decryptPdf } from 'pdf-password-remover';
|
|
19
|
+
|
|
20
|
+
const bytes = await decryptPdf(file, password, {
|
|
21
|
+
workerUrl: `${import.meta.env.BASE_URL}vendor/pdf-password-remover/pdf-worker.js`,
|
|
22
|
+
});
|
|
9
23
|
```
|
|
10
24
|
|
|
11
|
-
The
|
|
25
|
+
The plugin respects Vite's base path. Set `assetDirectory` on the plugin and
|
|
26
|
+
use the same directory in `workerUrl` if the default conflicts with the host
|
|
27
|
+
application.
|
|
28
|
+
|
|
29
|
+
## Webpack, Rollup, Parcel, and static sites
|
|
30
|
+
|
|
31
|
+
Copy the package runtime assets into the host application's public/static
|
|
32
|
+
directory during its build:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
npx pdf-password-remover copy-assets public/vendor/pdf-password-remover
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Then pass the deployed worker URL through `workerUrl`. The worker loads the
|
|
39
|
+
adjacent JavaScript bridge and WASM, so keep all three files together.
|
|
40
|
+
|
|
41
|
+
The CLI deliberately does not run during `postinstall`; it only writes files
|
|
42
|
+
when the consuming project explicitly invokes it.
|
|
12
43
|
|
|
13
44
|
## Required response headers
|
|
14
45
|
|
package/llms-full.txt
CHANGED
|
@@ -64,7 +64,20 @@ The main module copies the input into a transferable ArrayBuffer, creates `pdf-w
|
|
|
64
64
|
|
|
65
65
|
## Deployment
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
For Vite, add `pdfPasswordRemoverPlugin()` from
|
|
68
|
+
`pdf-password-remover/vite`. The plugin serves `pdf-worker.js`,
|
|
69
|
+
`pdf-decrypt.js`, and `pdf-decrypt.wasm` during development and emits the same
|
|
70
|
+
version-matched files during production builds. Pass
|
|
71
|
+
`${import.meta.env.BASE_URL}vendor/pdf-password-remover/pdf-worker.js` as
|
|
72
|
+
`workerUrl`.
|
|
73
|
+
|
|
74
|
+
For other build systems, run
|
|
75
|
+
`pdf-password-remover copy-assets <output-directory>` during the host build,
|
|
76
|
+
or call `copyPdfPasswordRemoverAssets()` from `pdf-password-remover/node`.
|
|
77
|
+
Keep the three assets together and pass the deployed worker URL to
|
|
78
|
+
`decryptPdf`. The package deliberately has no `postinstall` script and does
|
|
79
|
+
not write into a consuming project during installation. Do not load WASM from
|
|
80
|
+
an untrusted public CDN.
|
|
68
81
|
|
|
69
82
|
Serve WASM as `application/wasm`. A strict Content Security Policy normally needs `worker-src 'self'`, `connect-src 'self'`, and `script-src 'self' 'wasm-unsafe-eval'`. `wasm-unsafe-eval` permits WebAssembly compilation without enabling general JavaScript `unsafe-eval`.
|
|
70
83
|
|
package/llms.txt
CHANGED
|
@@ -44,6 +44,12 @@ try {
|
|
|
44
44
|
- Serve `.wasm` with `Content-Type: application/wasm`.
|
|
45
45
|
- This decrypts with a password supplied by the user. It does not crack or recover passwords.
|
|
46
46
|
- The output is an unencrypted copy of the PDF.
|
|
47
|
+
- Vite: add `pdfPasswordRemoverPlugin()` from `pdf-password-remover/vite`,
|
|
48
|
+
then use the matching same-origin `workerUrl`.
|
|
49
|
+
- Other build systems: run
|
|
50
|
+
`pdf-password-remover copy-assets <output-directory>` during the build.
|
|
51
|
+
- The package has no `postinstall` script and never modifies a consumer unless
|
|
52
|
+
its explicit asset-copy command or Node helper is invoked.
|
|
47
53
|
|
|
48
54
|
## Documentation
|
|
49
55
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-password-remover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Remove passwords from authorized PDFs locally in the browser using QPDF and WebAssembly.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "HafzalBZ",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"client-side"
|
|
34
34
|
],
|
|
35
35
|
"files": [
|
|
36
|
+
"bin",
|
|
36
37
|
"dist",
|
|
37
38
|
"src",
|
|
38
39
|
"Dockerfile",
|
|
@@ -41,6 +42,7 @@
|
|
|
41
42
|
"prepare-package.sh",
|
|
42
43
|
"AGENTS.md",
|
|
43
44
|
"AUTHORS.md",
|
|
45
|
+
"CHANGELOG.md",
|
|
44
46
|
"CONTRIBUTING.md",
|
|
45
47
|
"docs",
|
|
46
48
|
"examples",
|
|
@@ -57,7 +59,18 @@
|
|
|
57
59
|
"import": "./dist/index.js"
|
|
58
60
|
},
|
|
59
61
|
"./worker": "./dist/pdf-worker.js",
|
|
60
|
-
"./pdf-decrypt.wasm": "./dist/pdf-decrypt.wasm"
|
|
62
|
+
"./pdf-decrypt.wasm": "./dist/pdf-decrypt.wasm",
|
|
63
|
+
"./node": {
|
|
64
|
+
"types": "./dist/node.d.ts",
|
|
65
|
+
"import": "./dist/node.js"
|
|
66
|
+
},
|
|
67
|
+
"./vite": {
|
|
68
|
+
"types": "./dist/vite.d.ts",
|
|
69
|
+
"import": "./dist/vite.js"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"bin": {
|
|
73
|
+
"pdf-password-remover": "bin/pdf-password-remover.js"
|
|
61
74
|
},
|
|
62
75
|
"publishConfig": {
|
|
63
76
|
"access": "public",
|
|
@@ -66,7 +79,8 @@
|
|
|
66
79
|
"scripts": {
|
|
67
80
|
"build:wasm": "./build.sh",
|
|
68
81
|
"build": "./build-package.sh",
|
|
69
|
-
"check": "node --check src/index.js && node --check src/pdf-worker.js && sh -n build.sh build-package.sh prepare-package.sh serve.sh",
|
|
82
|
+
"check": "node --check src/index.js && node --check src/node.js && node --check src/vite.js && node --check src/pdf-worker.js && node --check bin/pdf-password-remover.js && node --check web/app.js && node --check web/pdf-worker.js && sh -n build.sh build-package.sh prepare-package.sh serve.sh",
|
|
83
|
+
"test": "node --test tests/*.test.mjs",
|
|
70
84
|
"prepack": "npm run check && ./prepare-package.sh"
|
|
71
85
|
}
|
|
72
86
|
}
|
package/prepare-package.sh
CHANGED
package/src/node.d.ts
ADDED
package/src/node.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright (c) 2026 HafzalBZ. SPDX-License-Identifier: MIT
|
|
2
|
+
import { copyFile, mkdir } from 'node:fs/promises';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
|
|
6
|
+
export const pdfPasswordRemoverAssetNames = Object.freeze([
|
|
7
|
+
'pdf-worker.js',
|
|
8
|
+
'pdf-decrypt.js',
|
|
9
|
+
'pdf-decrypt.wasm',
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
export async function copyPdfPasswordRemoverAssets(outputDirectory) {
|
|
13
|
+
if (
|
|
14
|
+
typeof outputDirectory !== 'string' &&
|
|
15
|
+
!(outputDirectory instanceof URL)
|
|
16
|
+
) {
|
|
17
|
+
throw new TypeError('outputDirectory must be a path string or file URL.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
await mkdir(outputDirectory, { recursive: true });
|
|
21
|
+
|
|
22
|
+
await Promise.all(pdfPasswordRemoverAssetNames.map((assetName) => copyFile(
|
|
23
|
+
new URL(`./${assetName}`, import.meta.url),
|
|
24
|
+
new URL(`./${assetName}`, toDirectoryUrl(outputDirectory)),
|
|
25
|
+
)));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function toDirectoryUrl(directory) {
|
|
29
|
+
if (directory instanceof URL) {
|
|
30
|
+
return new URL(directory.href.endsWith('/') ? directory.href : `${directory.href}/`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const resolved = pathToFileURL(resolve(directory));
|
|
34
|
+
return new URL(resolved.href.endsWith('/') ? resolved.href : `${resolved.href}/`);
|
|
35
|
+
}
|
package/src/vite.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface PdfPasswordRemoverPluginOptions {
|
|
2
|
+
/** Output directory relative to Vite's public base. */
|
|
3
|
+
assetDirectory?: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface PdfPasswordRemoverVitePlugin {
|
|
7
|
+
name: 'pdf-password-remover';
|
|
8
|
+
enforce: 'pre';
|
|
9
|
+
configResolved(config: { base: string }): void;
|
|
10
|
+
configureServer(server: {
|
|
11
|
+
middlewares: {
|
|
12
|
+
use(handler: (
|
|
13
|
+
request: { method?: string; url?: string },
|
|
14
|
+
response: {
|
|
15
|
+
statusCode: number;
|
|
16
|
+
setHeader(name: string, value: string | number): void;
|
|
17
|
+
end(body?: Uint8Array): void;
|
|
18
|
+
},
|
|
19
|
+
next: (error?: unknown) => void,
|
|
20
|
+
) => void): void;
|
|
21
|
+
};
|
|
22
|
+
}): void;
|
|
23
|
+
generateBundle(this: {
|
|
24
|
+
emitFile(asset: {
|
|
25
|
+
type: 'asset';
|
|
26
|
+
fileName: string;
|
|
27
|
+
source: Uint8Array;
|
|
28
|
+
}): void;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export declare function pdfPasswordRemoverPlugin(
|
|
33
|
+
options?: PdfPasswordRemoverPluginOptions,
|
|
34
|
+
): PdfPasswordRemoverVitePlugin;
|
package/src/vite.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Copyright (c) 2026 HafzalBZ. SPDX-License-Identifier: MIT
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
|
|
4
|
+
import { pdfPasswordRemoverAssetNames } from './node.js';
|
|
5
|
+
|
|
6
|
+
const contentTypes = Object.freeze({
|
|
7
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
8
|
+
'.wasm': 'application/wasm',
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export function pdfPasswordRemoverPlugin(options = {}) {
|
|
12
|
+
const assetDirectory = normalizeAssetDirectory(
|
|
13
|
+
options.assetDirectory ?? 'vendor/pdf-password-remover',
|
|
14
|
+
);
|
|
15
|
+
let base = '/';
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
name: 'pdf-password-remover',
|
|
19
|
+
enforce: 'pre',
|
|
20
|
+
|
|
21
|
+
configResolved(config) {
|
|
22
|
+
base = normalizeBase(config.base);
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
configureServer(server) {
|
|
26
|
+
const requestPrefix = `${base}${assetDirectory}/`;
|
|
27
|
+
|
|
28
|
+
server.middlewares.use(async (request, response, next) => {
|
|
29
|
+
try {
|
|
30
|
+
const pathname = new URL(
|
|
31
|
+
request.url ?? '/',
|
|
32
|
+
'http://pdf-password-remover.local',
|
|
33
|
+
).pathname;
|
|
34
|
+
|
|
35
|
+
if (!pathname.startsWith(requestPrefix)) {
|
|
36
|
+
next();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const assetName = pathname.slice(requestPrefix.length);
|
|
41
|
+
if (!pdfPasswordRemoverAssetNames.includes(assetName)) {
|
|
42
|
+
next();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const source = await readPackageAsset(assetName);
|
|
47
|
+
response.statusCode = 200;
|
|
48
|
+
response.setHeader('Content-Type', contentTypeFor(assetName));
|
|
49
|
+
response.setHeader('Content-Length', source.byteLength);
|
|
50
|
+
response.setHeader('Cache-Control', 'no-cache');
|
|
51
|
+
|
|
52
|
+
if (request.method === 'HEAD') {
|
|
53
|
+
response.end();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
response.end(source);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
next(error);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
async generateBundle() {
|
|
65
|
+
await Promise.all(pdfPasswordRemoverAssetNames.map(async (assetName) => {
|
|
66
|
+
this.emitFile({
|
|
67
|
+
type: 'asset',
|
|
68
|
+
fileName: `${assetDirectory}/${assetName}`,
|
|
69
|
+
source: await readPackageAsset(assetName),
|
|
70
|
+
});
|
|
71
|
+
}));
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function normalizeAssetDirectory(value) {
|
|
77
|
+
if (typeof value !== 'string') {
|
|
78
|
+
throw new TypeError('assetDirectory must be a string.');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const normalized = value.replaceAll('\\', '/').replace(/^\/+|\/+$/g, '');
|
|
82
|
+
const segments = normalized.split('/');
|
|
83
|
+
|
|
84
|
+
if (
|
|
85
|
+
normalized.length === 0 ||
|
|
86
|
+
segments.some((segment) => segment === '.' || segment === '..' || segment === '')
|
|
87
|
+
) {
|
|
88
|
+
throw new TypeError('assetDirectory must be a non-empty relative directory.');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return normalized;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function normalizeBase(value) {
|
|
95
|
+
const base = typeof value === 'string' && value.length > 0 ? value : '/';
|
|
96
|
+
return `${base.startsWith('/') ? '' : '/'}${base.replace(/\/*$/, '/')}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function contentTypeFor(assetName) {
|
|
100
|
+
const extension = assetName.endsWith('.wasm') ? '.wasm' : '.js';
|
|
101
|
+
return contentTypes[extension];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function readPackageAsset(assetName) {
|
|
105
|
+
return readFile(new URL(`./${assetName}`, import.meta.url));
|
|
106
|
+
}
|