@f-o-t/e-signature 1.6.1 → 1.6.2

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/README.md CHANGED
@@ -72,11 +72,29 @@ function SignForm() {
72
72
 
73
73
  Runs signing off the main thread to prevent browser freezes.
74
74
 
75
+ **Step 1.** Create a worker file in your project (e.g. `workers/sign-pdf.ts`):
76
+
77
+ ```ts
78
+ import { signPdf } from "@f-o-t/e-signature";
79
+
80
+ self.onmessage = async (e: MessageEvent) => {
81
+ const { id, pdf, options } = e.data;
82
+ try {
83
+ const result = await signPdf(pdf, options);
84
+ self.postMessage({ id, ok: true, result }, { transfer: [result.buffer] });
85
+ } catch (err) {
86
+ self.postMessage({ id, ok: false, error: err instanceof Error ? err.message : String(err) });
87
+ }
88
+ };
89
+ ```
90
+
91
+ **Step 2.** Use `signPdfInWorker` from your component:
92
+
75
93
  ```ts
76
94
  import { signPdfInWorker } from "@f-o-t/e-signature/plugins/worker";
77
95
 
78
96
  const worker = new Worker(
79
- new URL("@f-o-t/e-signature/plugins/worker-entry", import.meta.url),
97
+ new URL("../workers/sign-pdf", import.meta.url),
80
98
  { type: "module" },
81
99
  );
82
100
 
@@ -1,22 +1,49 @@
1
1
  import type { PdfSignOptions } from "../../types.ts";
2
+ export type WorkerRequest = {
3
+ id: number;
4
+ pdf: Uint8Array;
5
+ options: PdfSignOptions;
6
+ };
7
+ export type WorkerResponse = {
8
+ id: number;
9
+ ok: true;
10
+ result: Uint8Array;
11
+ } | {
12
+ id: number;
13
+ ok: false;
14
+ error: string;
15
+ };
2
16
  /**
3
17
  * Sign a PDF in a Web Worker to avoid blocking the main thread.
4
18
  *
5
- * @param worker - A Worker running the worker-entry plugin script
19
+ * The consumer must create a worker file in their project that imports
20
+ * `signPdf` from `@f-o-t/e-signature` — this lets the bundler resolve
21
+ * all dependencies correctly inside the worker context.
22
+ *
23
+ * @param worker - A Worker that handles signing messages
6
24
  * @param pdf - PDF bytes
7
25
  * @param options - Same options as signPdf()
8
26
  * @returns Signed PDF bytes
9
27
  *
10
28
  * @example
11
29
  * ```ts
12
- * const worker = new Worker(
13
- * new URL("@f-o-t/e-signature/plugins/worker-entry", import.meta.url),
14
- * { type: "module" },
15
- * );
30
+ * // 1. Create workers/sign-pdf.ts in your project:
31
+ * // import { signPdf } from "@f-o-t/e-signature";
32
+ * // self.onmessage = async (e) => {
33
+ * // const { id, pdf, options } = e.data;
34
+ * // try {
35
+ * // const result = await signPdf(pdf, options);
36
+ * // self.postMessage({ id, ok: true, result }, [result.buffer]);
37
+ * // } catch (err) {
38
+ * // self.postMessage({ id, ok: false, error: err instanceof Error ? err.message : String(err) });
39
+ * // }
40
+ * // };
41
+ * //
42
+ * // 2. Use in your component:
43
+ * const worker = new Worker(new URL("./workers/sign-pdf", import.meta.url), { type: "module" });
16
44
  * const signed = await signPdfInWorker(worker, pdfBytes, options);
17
45
  * worker.terminate();
18
46
  * ```
19
47
  */
20
48
  export declare function signPdfInWorker(worker: Worker, pdf: Uint8Array, options: PdfSignOptions): Promise<Uint8Array>;
21
- export type { WorkerRequest, WorkerResponse } from "../worker-entry/index.ts";
22
49
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/worker/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGrD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAC5B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,cAAc,GACvB,OAAO,CAAC,UAAU,CAAC,CA8BrB;AAID,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/worker/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,UAAU,CAAC;IAChB,OAAO,EAAE,cAAc,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,cAAc,GACrB;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,GAC5C;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,eAAe,CAC5B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,cAAc,GACvB,OAAO,CAAC,UAAU,CAAC,CA+BrB"}
@@ -24,9 +24,7 @@ function signPdfInWorker(worker, pdf, options) {
24
24
  worker.addEventListener("message", onMessage);
25
25
  worker.addEventListener("error", onError);
26
26
  const transfer = pdf.buffer instanceof ArrayBuffer ? [pdf.buffer] : [];
27
- worker.postMessage({ id, pdf, options }, {
28
- transfer
29
- });
27
+ worker.postMessage({ id, pdf, options }, { transfer });
30
28
  });
31
29
  }
32
30
  var nextId = 1;
@@ -34,4 +32,4 @@ export {
34
32
  signPdfInWorker
35
33
  };
36
34
 
37
- //# debugId=A075BE52F17C089B64756E2164756E21
35
+ //# debugId=B0DB78B0460552D564756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/plugins/worker/index.ts"],
4
4
  "sourcesContent": [
5
- "import type { PdfSignOptions } from \"../../types.ts\";\nimport type { WorkerRequest, WorkerResponse } from \"../worker-entry/index.ts\";\n\n/**\n * Sign a PDF in a Web Worker to avoid blocking the main thread.\n *\n * @param worker - A Worker running the worker-entry plugin script\n * @param pdf - PDF bytes\n * @param options - Same options as signPdf()\n * @returns Signed PDF bytes\n *\n * @example\n * ```ts\n * const worker = new Worker(\n * new URL(\"@f-o-t/e-signature/plugins/worker-entry\", import.meta.url),\n * { type: \"module\" },\n * );\n * const signed = await signPdfInWorker(worker, pdfBytes, options);\n * worker.terminate();\n * ```\n */\nexport function signPdfInWorker(\n worker: Worker,\n pdf: Uint8Array,\n options: PdfSignOptions,\n): Promise<Uint8Array> {\n return new Promise((resolve, reject) => {\n const id = nextId++;\n\n function onMessage(e: MessageEvent<WorkerResponse>) {\n if (e.data.id !== id) return;\n worker.removeEventListener(\"message\", onMessage);\n worker.removeEventListener(\"error\", onError);\n\n if (e.data.ok) {\n resolve(e.data.result);\n } else {\n reject(new Error(e.data.error));\n }\n }\n\n function onError(e: ErrorEvent) {\n worker.removeEventListener(\"message\", onMessage);\n worker.removeEventListener(\"error\", onError);\n reject(new Error(e.message || \"Worker error\"));\n }\n\n worker.addEventListener(\"message\", onMessage);\n worker.addEventListener(\"error\", onError);\n\n const transfer = pdf.buffer instanceof ArrayBuffer ? [pdf.buffer] : [];\n worker.postMessage({ id, pdf, options } satisfies WorkerRequest, {\n transfer,\n });\n });\n}\n\nlet nextId = 1;\n\nexport type { WorkerRequest, WorkerResponse } from \"../worker-entry/index.ts\";\n"
5
+ "import type { PdfSignOptions } from \"../../types.ts\";\n\nexport type WorkerRequest = {\n id: number;\n pdf: Uint8Array;\n options: PdfSignOptions;\n};\n\nexport type WorkerResponse =\n | { id: number; ok: true; result: Uint8Array }\n | { id: number; ok: false; error: string };\n\n/**\n * Sign a PDF in a Web Worker to avoid blocking the main thread.\n *\n * The consumer must create a worker file in their project that imports\n * `signPdf` from `@f-o-t/e-signature` — this lets the bundler resolve\n * all dependencies correctly inside the worker context.\n *\n * @param worker - A Worker that handles signing messages\n * @param pdf - PDF bytes\n * @param options - Same options as signPdf()\n * @returns Signed PDF bytes\n *\n * @example\n * ```ts\n * // 1. Create workers/sign-pdf.ts in your project:\n * // import { signPdf } from \"@f-o-t/e-signature\";\n * // self.onmessage = async (e) => {\n * // const { id, pdf, options } = e.data;\n * // try {\n * // const result = await signPdf(pdf, options);\n * // self.postMessage({ id, ok: true, result }, [result.buffer]);\n * // } catch (err) {\n * // self.postMessage({ id, ok: false, error: err instanceof Error ? err.message : String(err) });\n * // }\n * // };\n * //\n * // 2. Use in your component:\n * const worker = new Worker(new URL(\"./workers/sign-pdf\", import.meta.url), { type: \"module\" });\n * const signed = await signPdfInWorker(worker, pdfBytes, options);\n * worker.terminate();\n * ```\n */\nexport function signPdfInWorker(\n worker: Worker,\n pdf: Uint8Array,\n options: PdfSignOptions,\n): Promise<Uint8Array> {\n return new Promise((resolve, reject) => {\n const id = nextId++;\n\n function onMessage(e: MessageEvent<WorkerResponse>) {\n if (e.data.id !== id) return;\n worker.removeEventListener(\"message\", onMessage);\n worker.removeEventListener(\"error\", onError);\n\n if (e.data.ok) {\n resolve(e.data.result);\n } else {\n reject(new Error(e.data.error));\n }\n }\n\n function onError(e: ErrorEvent) {\n worker.removeEventListener(\"message\", onMessage);\n worker.removeEventListener(\"error\", onError);\n reject(new Error(e.message || \"Worker error\"));\n }\n\n worker.addEventListener(\"message\", onMessage);\n worker.addEventListener(\"error\", onError);\n\n const transfer = pdf.buffer instanceof ArrayBuffer ? [pdf.buffer] : [];\n worker.postMessage(\n { id, pdf, options } satisfies WorkerRequest,\n { transfer },\n );\n });\n}\n\nlet nextId = 1;\n"
6
6
  ],
7
- "mappings": ";;;;AAqBO,SAAS,eAAe,CAC5B,QACA,KACA,SACoB;AAAA,EACpB,OAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AAAA,IACrC,MAAM,KAAK;AAAA,IAEX,SAAS,SAAS,CAAC,GAAiC;AAAA,MACjD,IAAI,EAAE,KAAK,OAAO;AAAA,QAAI;AAAA,MACtB,OAAO,oBAAoB,WAAW,SAAS;AAAA,MAC/C,OAAO,oBAAoB,SAAS,OAAO;AAAA,MAE3C,IAAI,EAAE,KAAK,IAAI;AAAA,QACZ,QAAQ,EAAE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hD,OAAO,iBAAiB,WAAW,SAAS;AAAA,IAC5C,OAAO,iBAAiB,SAAS,OAAO;AAAA,IAExC,MAAM,WAAW,IAAI,kBAAkB,cAAc,CAAC,IAAI,MAAM,IAAI,CAAC;AAAA,IACrE,OAAO,YACJ,EAAE,IAAI,KAAK,QAAQ,GACnB,EAAE,SAAS,CACd;AAAA,GACF;AAAA;AAGJ,IAAI,SAAS;",
8
+ "debugId": "B0DB78B0460552D564756E2164756E21",
9
9
  "names": []
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@f-o-t/e-signature",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "PAdES PDF signing with ICP-Brasil compliance",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,12 +23,6 @@
23
23
  "module": "./dist/plugins/worker/index.js",
24
24
  "import": "./dist/plugins/worker/index.js",
25
25
  "default": "./dist/plugins/worker/index.js"
26
- },
27
- "./plugins/worker-entry": {
28
- "types": "./dist/plugins/worker-entry/index.d.ts",
29
- "module": "./dist/plugins/worker-entry/index.js",
30
- "import": "./dist/plugins/worker-entry/index.js",
31
- "default": "./dist/plugins/worker-entry/index.js"
32
26
  }
33
27
  },
34
28
  "files": [
@@ -1,16 +0,0 @@
1
- import type { PdfSignOptions } from "../../types.ts";
2
- export type WorkerRequest = {
3
- id: number;
4
- pdf: Uint8Array;
5
- options: PdfSignOptions;
6
- };
7
- export type WorkerResponse = {
8
- id: number;
9
- ok: true;
10
- result: Uint8Array;
11
- } | {
12
- id: number;
13
- ok: false;
14
- error: string;
15
- };
16
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/worker-entry/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,UAAU,CAAC;IAChB,OAAO,EAAE,cAAc,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,cAAc,GACrB;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,GAC5C;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -1,24 +0,0 @@
1
- // @bun
2
- import {
3
- signPdf
4
- } from "../../index-eavt9jtf.js";
5
- import"../../index-r24hmh0q.js";
6
-
7
- // src/plugins/worker-entry/index.ts
8
- if (typeof globalThis.postMessage === "function" && typeof globalThis.onmessage !== "undefined") {
9
- globalThis.onmessage = async (e) => {
10
- const { id, pdf, options } = e.data;
11
- try {
12
- const result = await signPdf(pdf, options);
13
- globalThis.postMessage({ id, ok: true, result }, { transfer: [result.buffer] });
14
- } catch (err) {
15
- globalThis.postMessage({
16
- id,
17
- ok: false,
18
- error: err instanceof Error ? err.message : String(err)
19
- });
20
- }
21
- };
22
- }
23
-
24
- //# debugId=DBE17372DFC4912E64756E2164756E21
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/plugins/worker-entry/index.ts"],
4
- "sourcesContent": [
5
- "import { signPdf } from \"../../sign-pdf.ts\";\nimport type { PdfSignOptions } from \"../../types.ts\";\n\nexport type WorkerRequest = {\n id: number;\n pdf: Uint8Array;\n options: PdfSignOptions;\n};\n\nexport type WorkerResponse =\n | { id: number; ok: true; result: Uint8Array }\n | { id: number; ok: false; error: string };\n\n// Self-register when running as a Worker\nif (\n typeof globalThis.postMessage === \"function\" &&\n typeof globalThis.onmessage !== \"undefined\"\n) {\n globalThis.onmessage = async (e: MessageEvent<WorkerRequest>) => {\n const { id, pdf, options } = e.data;\n try {\n const result = await signPdf(pdf, options);\n (globalThis as unknown as Worker).postMessage(\n { id, ok: true, result } satisfies WorkerResponse,\n { transfer: [result.buffer] },\n );\n } catch (err) {\n (globalThis as unknown as Worker).postMessage({\n id,\n ok: false,\n error: err instanceof Error ? err.message : String(err),\n } satisfies WorkerResponse);\n }\n };\n}\n"
6
- ],
7
- "mappings": ";;;;;;;AAcA,IACG,OAAO,WAAW,gBAAgB,cAClC,OAAO,WAAW,cAAc,aACjC;AAAA,EACC,WAAW,YAAY,OAAO,MAAmC;AAAA,IAC9D,QAAQ,IAAI,KAAK,YAAY,EAAE;AAAA,IAC/B,IAAI;AAAA,MACD,MAAM,SAAS,MAAM,QAAQ,KAAK,OAAO;AAAA,MACxC,WAAiC,YAC/B,EAAE,IAAI,IAAI,MAAM,OAAO,GACvB,EAAE,UAAU,CAAC,OAAO,MAAM,EAAE,CAC/B;AAAA,MACD,OAAO,KAAK;AAAA,MACV,WAAiC,YAAY;AAAA,QAC3C;AAAA,QACA,IAAI;AAAA,QACJ,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAAA,MACzD,CAA0B;AAAA;AAAA;AAGnC;",
8
- "debugId": "DBE17372DFC4912E64756E2164756E21",
9
- "names": []
10
- }