@rentnerkev/pdf 1.0.1 → 1.0.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 +6 -6
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/ai.d.ts.map +1 -1
- package/dist/ai.js +8 -3
- package/dist/ai.js.map +1 -1
- package/dist/components/Types/props.d.ts +2 -2
- package/dist/components/components.d.ts +5 -5
- package/dist/components/components.d.ts.map +1 -1
- package/dist/components/components.js +16 -16
- package/dist/components/components.js.map +1 -1
- package/dist/components/host.d.ts +2 -2
- package/dist/engine/Types/backend.d.ts +5 -5
- package/dist/engine/Types/engine.d.ts +8 -8
- package/dist/engine/Types/errors.d.ts +2 -2
- package/dist/engine/Types/render-options.d.ts +1 -1
- package/dist/engine/Types/render-result.d.ts +1 -1
- package/dist/engine/abort.d.ts +2 -2
- package/dist/engine/abort.d.ts.map +1 -1
- package/dist/engine/abort.js +2 -2
- package/dist/engine/abort.js.map +1 -1
- package/dist/engine/assets.d.ts +4 -3
- package/dist/engine/assets.d.ts.map +1 -1
- package/dist/engine/assets.js +19 -11
- package/dist/engine/assets.js.map +1 -1
- package/dist/engine/backend.d.ts +5 -5
- package/dist/engine/backend.d.ts.map +1 -1
- package/dist/engine/backend.js +12 -9
- package/dist/engine/backend.js.map +1 -1
- package/dist/engine/backends/native.d.ts +2 -2
- package/dist/engine/backends/wasm.d.ts +2 -2
- package/dist/engine/backends/wasm.d.ts.map +1 -1
- package/dist/engine/backends/wasm.js +12 -4
- package/dist/engine/backends/wasm.js.map +1 -1
- package/dist/engine/channel.d.ts +5 -8
- package/dist/engine/channel.d.ts.map +1 -1
- package/dist/engine/channel.js +71 -43
- package/dist/engine/channel.js.map +1 -1
- package/dist/engine/create-engine.d.ts +1 -1
- package/dist/engine/create-engine.d.ts.map +1 -1
- package/dist/engine/create-engine.js +11 -5
- package/dist/engine/create-engine.js.map +1 -1
- package/dist/engine/default-fonts.d.ts.map +1 -1
- package/dist/engine/default-fonts.js +24 -17
- package/dist/engine/default-fonts.js.map +1 -1
- package/dist/engine/encode.d.ts +5 -4
- package/dist/engine/encode.d.ts.map +1 -1
- package/dist/engine/encode.js +15 -10
- package/dist/engine/encode.js.map +1 -1
- package/dist/engine/errors.d.ts +3 -3
- package/dist/engine/fonts.d.ts +1 -1
- package/dist/engine/markup.d.ts +3 -3
- package/dist/engine/options.d.ts +2 -2
- package/dist/engine/prepare.d.ts +4 -4
- package/dist/engine/render-many.d.ts +3 -3
- package/dist/engine/render-result.d.ts +9 -3
- package/dist/engine/render-result.d.ts.map +1 -1
- package/dist/engine/render-result.js +8 -1
- package/dist/engine/render-result.js.map +1 -1
- package/dist/engine/render-stream.d.ts +1 -1
- package/dist/engine/render.d.ts +3 -3
- package/dist/index.d.ts +24 -24
- package/dist/ir/Types/input.d.ts +1 -1
- package/dist/ir/factories.d.ts +3 -3
- package/dist/ir/factories.d.ts.map +1 -1
- package/dist/ir/factories.js +8 -3
- package/dist/ir/factories.js.map +1 -1
- package/dist/ir/page-variants.d.ts +3 -0
- package/dist/ir/page-variants.d.ts.map +1 -0
- package/dist/ir/page-variants.js +3 -0
- package/dist/ir/page-variants.js.map +1 -0
- package/dist/jsx/Types/context.d.ts +1 -1
- package/dist/jsx/Types/evaluate.d.ts +4 -4
- package/dist/jsx/Types/jsx.d.ts +1 -1
- package/dist/jsx/context.d.ts +1 -1
- package/dist/jsx/element.d.ts +1 -1
- package/dist/jsx/evaluate.d.ts +3 -3
- package/dist/jsx/evaluate.d.ts.map +1 -1
- package/dist/jsx/evaluate.js +20 -52
- package/dist/jsx/evaluate.js.map +1 -1
- package/dist/jsx/source.d.ts +1 -1
- package/dist/jsx-dev-runtime.d.ts +3 -3
- package/dist/jsx-runtime.d.ts +3 -3
- package/dist/native/loader.d.ts.map +1 -1
- package/dist/native/loader.js +33 -27
- package/dist/native/loader.js.map +1 -1
- package/dist/native/rentnerpdf.linux-arm64-gnu.node +0 -0
- package/dist/native/rentnerpdf.linux-arm64-musl.node +0 -0
- package/dist/native/rentnerpdf.linux-x64-gnu.node +0 -0
- package/dist/native/rentnerpdf.linux-x64-musl.node +0 -0
- package/dist/native/rentnerpdf.win32-arm64-msvc.node +0 -0
- package/dist/native/rentnerpdf.win32-x64-msvc.node +0 -0
- package/dist/node.d.ts +2 -2
- package/dist/react/Types/preview.d.ts +16 -11
- package/dist/react/Types/preview.d.ts.map +1 -1
- package/dist/react/Types/preview.js.map +1 -1
- package/dist/react/Types/render.d.ts +1 -1
- package/dist/react/components.d.ts +4 -4
- package/dist/react/components.d.ts.map +1 -1
- package/dist/react/components.js +23 -23
- package/dist/react/components.js.map +1 -1
- package/dist/react/pdf-preview.d.ts +3 -2
- package/dist/react/pdf-preview.d.ts.map +1 -1
- package/dist/react/pdf-preview.js +2 -1
- package/dist/react/pdf-preview.js.map +1 -1
- package/dist/react/pdf-render.d.ts +4 -4
- package/dist/react/pdf-render.d.ts.map +1 -1
- package/dist/react/pdf-render.js +20 -12
- package/dist/react/pdf-render.js.map +1 -1
- package/dist/react/registry.d.ts +3 -3
- package/dist/react/registry.d.ts.map +1 -1
- package/dist/react/registry.js +6 -3
- package/dist/react/registry.js.map +1 -1
- package/dist/react/render.d.ts +4 -4
- package/dist/react/render.d.ts.map +1 -1
- package/dist/react/render.js +36 -54
- package/dist/react/render.js.map +1 -1
- package/dist/react/same-document.d.ts +2 -1
- package/dist/react/same-document.d.ts.map +1 -1
- package/dist/react/same-document.js +7 -1
- package/dist/react/same-document.js.map +1 -1
- package/dist/react/static.d.ts +5 -0
- package/dist/react/static.d.ts.map +1 -1
- package/dist/react/static.js +20 -16
- package/dist/react/static.js.map +1 -1
- package/dist/react/use-pdf.d.ts +5 -5
- package/dist/react/use-pdf.d.ts.map +1 -1
- package/dist/react/use-pdf.js +81 -14
- package/dist/react/use-pdf.js.map +1 -1
- package/dist/react.d.ts +8 -8
- package/dist/tailwind-merge.d.ts +2 -2
- package/dist/theme/Types/theme.d.ts +8 -1
- package/dist/theme/Types/theme.d.ts.map +1 -1
- package/dist/theme/Types/theme.js.map +1 -1
- package/dist/theme/css-imports.d.ts +1 -1
- package/dist/theme/normalize.d.ts +2 -2
- package/dist/theme/package-imports.d.ts +1 -8
- package/dist/theme/package-imports.d.ts.map +1 -1
- package/dist/theme/package-imports.js +4 -11
- package/dist/theme/package-imports.js.map +1 -1
- package/dist/theme/paths.d.ts +6 -0
- package/dist/theme/paths.d.ts.map +1 -0
- package/dist/theme/paths.js +13 -0
- package/dist/theme/paths.js.map +1 -0
- package/dist/theme/theme-from-css-file.d.ts +1 -3
- package/dist/theme/theme-from-css-file.d.ts.map +1 -1
- package/dist/theme/theme-from-css-file.js +16 -21
- package/dist/theme/theme-from-css-file.js.map +1 -1
- package/dist/theme/theme-from-css.d.ts +1 -1
- package/dist/theme/warnings.d.ts +1 -4
- package/dist/theme/warnings.d.ts.map +1 -1
- package/dist/theme/warnings.js +1 -1
- package/dist/theme/warnings.js.map +1 -1
- package/dist/vite/plugin.d.ts +3 -6
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/vite/plugin.js +17 -7
- package/dist/vite/plugin.js.map +1 -1
- package/dist/vite.d.ts +2 -2
- package/dist/wasm/binding.generated.d.ts +19 -14
- package/dist/wasm/loader.d.ts.map +1 -1
- package/dist/wasm/loader.js +11 -3
- package/dist/wasm/loader.js.map +1 -1
- package/dist/wasm/node-path.d.ts +3 -0
- package/dist/wasm/node-path.d.ts.map +1 -0
- package/dist/wasm/node-path.js +4 -0
- package/dist/wasm/node-path.js.map +1 -0
- package/dist/wasm/pkg/rentnerpdf_wasm.d.ts +19 -14
- package/dist/wasm/pkg/rentnerpdf_wasm.js +39 -75
- package/dist/wasm/pkg/rentnerpdf_wasm_bg.wasm +0 -0
- package/dist/wasm/pkg/rentnerpdf_wasm_bg.wasm.d.ts +8 -7
- package/dist/worker/Types/connection.d.ts +1 -1
- package/dist/worker/Types/protocol.d.ts +2 -2
- package/dist/worker/Types/worker-engine.d.ts +3 -3
- package/dist/worker/client.d.ts +1 -1
- package/dist/worker/client.d.ts.map +1 -1
- package/dist/worker/client.js +10 -10
- package/dist/worker/client.js.map +1 -1
- package/dist/worker/connection.d.ts +2 -2
- package/dist/worker/protocol.d.ts +2 -2
- package/dist/worker/protocol.js.map +1 -1
- package/dist/worker/serve.d.ts +3 -5
- package/dist/worker/serve.d.ts.map +1 -1
- package/dist/worker/serve.js +1 -1
- package/dist/worker/serve.js.map +1 -1
- package/dist/worker.d.ts +3 -3
- package/docs/usage.md +51 -49
- package/package.json +4 -1
- package/dist/engine/pdf-bytes.d.ts +0 -8
- package/dist/engine/pdf-bytes.d.ts.map +0 -1
- package/dist/engine/pdf-bytes.js +0 -9
- package/dist/engine/pdf-bytes.js.map +0 -1
- package/dist/theme/Types/warnings.d.ts +0 -9
- package/dist/theme/Types/warnings.d.ts.map +0 -1
- package/dist/theme/Types/warnings.js +0 -2
- package/dist/theme/Types/warnings.js.map +0 -1
package/dist/worker/client.js
CHANGED
|
@@ -9,11 +9,9 @@ import { throwIfAborted } from '../engine/abort.js';
|
|
|
9
9
|
import { encodeDocument } from '../engine/encode.js';
|
|
10
10
|
import { fontBytes } from '../engine/fonts.js';
|
|
11
11
|
import { ASYNC_DISPOSE, DISPOSE, EngineLifecycle } from '../engine/lifecycle.js';
|
|
12
|
-
import { pdfBytes } from '../engine/pdf-bytes.js';
|
|
13
12
|
import { engineThemeWarnings, prepareEngineOptions, prepareInput, } from '../engine/prepare.js';
|
|
14
|
-
import { toRenderResult } from '../engine/render-result.js';
|
|
13
|
+
import { pdfBytes, toRenderResult } from '../engine/render-result.js';
|
|
15
14
|
import { connectWorker } from './connection.js';
|
|
16
|
-
import { transferable } from './protocol.js';
|
|
17
15
|
const unexpected = (reply) => new TypeError(`unexpected answer from the render worker: ${reply.type}`);
|
|
18
16
|
const stop = (worker) => {
|
|
19
17
|
if (worker.terminate !== undefined)
|
|
@@ -40,9 +38,9 @@ async function renderInWorker(connection, input, signal, detailed, read) {
|
|
|
40
38
|
const { document, locate } = await prepareInput(input);
|
|
41
39
|
throwIfAborted(signal);
|
|
42
40
|
try {
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const reply = await connection.request({ type: 'render', detailed, document:
|
|
41
|
+
const transfer = [];
|
|
42
|
+
const encoded = encodeDocument(document, transfer);
|
|
43
|
+
const reply = await connection.request({ type: 'render', detailed, document: encoded }, transfer, signal);
|
|
46
44
|
return read(reply, locate);
|
|
47
45
|
}
|
|
48
46
|
catch (error) {
|
|
@@ -93,27 +91,29 @@ export async function createWorkerEngine({ worker, wasmModule, ...options }) {
|
|
|
93
91
|
themeWarnings = engineThemeWarnings(prepared.themeWarnings, reply.themeWarnings);
|
|
94
92
|
}
|
|
95
93
|
catch (error) {
|
|
94
|
+
connection?.close(error);
|
|
96
95
|
stop(worker);
|
|
97
96
|
throw toRentnerPdfError(error);
|
|
98
97
|
}
|
|
98
|
+
const connected = connection;
|
|
99
99
|
// Requests are not tracked: closing cancels them (their signals) and
|
|
100
100
|
// stops the worker at once instead of waiting for its answer.
|
|
101
101
|
const lifecycle = new EngineLifecycle();
|
|
102
102
|
const close = () => lifecycle.close(() => {
|
|
103
|
-
|
|
103
|
+
connected.close(new RentnerPdfError('ENGINE_CLOSED', 'the engine was closed'));
|
|
104
104
|
stop(worker);
|
|
105
105
|
});
|
|
106
106
|
return {
|
|
107
107
|
backend: 'wasm',
|
|
108
108
|
version,
|
|
109
109
|
themeWarnings,
|
|
110
|
-
render: (input, renderOptions) => lifecycle.run(renderOptions?.signal, (signal) => renderInWorker(
|
|
111
|
-
renderDetailed: (input, renderOptions) => lifecycle.run(renderOptions?.signal, (signal) => renderInWorker(
|
|
110
|
+
render: (input, renderOptions) => lifecycle.run(renderOptions?.signal, (signal) => renderInWorker(connected, input, signal, false, readPdf)),
|
|
111
|
+
renderDetailed: (input, renderOptions) => lifecycle.run(renderOptions?.signal, (signal) => renderInWorker(connected, input, signal, true, readResult)),
|
|
112
112
|
// Queued before it returns, so it takes its turn before every
|
|
113
113
|
// render called after it.
|
|
114
114
|
registerFont: (font) => lifecycle.run(undefined, async (signal) => {
|
|
115
115
|
try {
|
|
116
|
-
const reply = await
|
|
116
|
+
const reply = await connected.request({ type: 'registerFont', font: fontBytes(font, 'font') }, [], signal);
|
|
117
117
|
if (reply.type !== 'fontRegistered')
|
|
118
118
|
throw unexpected(reply);
|
|
119
119
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../web/src/worker/client.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,gEAAgE;AAChE,mEAAmE;AACnE,wEAAwE;AACxE,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EACH,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,GACf,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAI3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAS5C,MAAM,UAAU,GAAG,CAAC,KAAkB,EAAa,EAAE,CACjD,IAAI,SAAS,CAAC,6CAA6C,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;AAE5E,MAAM,IAAI,GAAG,CAAC,MAAwB,EAAQ,EAAE;IAC5C,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS;QAA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AAK,CAAC,CAAA;YAClC,CAAC;QACL,CAAC,CAAC;QACN,KAAK;QACL,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE;YACZ,KAAK,KAAK,EAAE,CAAA;QAChB,CAAC;QACD,CAAC,aAAa,CAAC,EAAE,KAAK;KACzB,CAAA;AACL,CAAC","sourcesContent":["// `createWorkerEngine`: the familiar render API on the page, with the\n// WebAssembly engine in a Web Worker (concurrency model in 04 –\n// Architecture). Components run on the page, because elements hold\n// functions; their IR is encoded here and crosses as bytes. Errors come\n// back in the engine's format and get their code, IR path and JSX source\n// here, where the source locator of the evaluation lives.\nimport { RentnerPdfError, toRentnerPdfError } from '../engine/errors.ts'\nimport { throwIfAborted } from '../engine/abort.ts'\nimport { encodeDocument } from '../engine/encode.ts'\nimport { fontBytes } from '../engine/fonts.ts'\nimport { ASYNC_DISPOSE, DISPOSE, EngineLifecycle } from '../engine/lifecycle.ts'\nimport { pdfBytes } from '../engine/pdf-bytes.ts'\nimport {\n engineThemeWarnings,\n prepareEngineOptions,\n prepareInput,\n} from '../engine/prepare.ts'\nimport { toRenderResult } from '../engine/render-result.ts'\nimport type { RenderInput } from '../engine/Types/engine.ts'\nimport type { SourceLocator } from '../engine/Types/errors.ts'\nimport type { PdfBytes, RenderResult } from '../engine/Types/render-result.ts'\nimport { connectWorker } from './connection.ts'\nimport { transferable } from './protocol.ts'\nimport type { WorkerConnection } from './Types/connection.ts'\nimport type { WorkerReply } from './Types/protocol.ts'\nimport type {\n RenderWorkerPort,\n WorkerEngine,\n WorkerEngineOptions,\n} from './Types/worker-engine.ts'\n\nconst unexpected = (reply: WorkerReply): TypeError =>\n new TypeError(`unexpected answer from the render worker: ${reply.type}`)\n\nconst stop = (worker: RenderWorkerPort): void => {\n if (worker.terminate !== undefined) worker.terminate()\n else worker.close?.()\n}\n\nconst readPdf = (reply: WorkerReply): PdfBytes => {\n if (reply.type !== 'rendered') throw unexpected(reply)\n return pdfBytes(reply.pdf)\n}\n\nconst readResult = (\n reply: WorkerReply,\n locate: SourceLocator | undefined,\n): RenderResult => {\n if (reply.type !== 'renderedDetailed') throw unexpected(reply)\n return toRenderResult(reply.result, locate)\n}\n\n/**\n * Evaluates and encodes `input` here, renders it in the worker and reads\n * the answer with `read`.\n */\nasync function renderInWorker<T>(\n connection: WorkerConnection,\n input: RenderInput,\n signal: AbortSignal | undefined,\n detailed: boolean,\n read: (reply: WorkerReply, locate: SourceLocator | undefined) => T,\n): Promise<T> {\n throwIfAborted(signal)\n const { document, locate } = await prepareInput(input)\n throwIfAborted(signal)\n try {\n const { ir, assets } = encodeDocument(document)\n const owned = transferable(ir)\n const reply = await connection.request(\n { type: 'render', detailed, document: { ir: owned, assets } },\n [owned.buffer],\n signal,\n )\n return read(reply, locate)\n } catch (error) {\n throw toRentnerPdfError(error, locate)\n }\n}\n\n/**\n * Creates an engine that renders in a Web Worker running\n * `serveRenderWorker()`; reuse it for every render. The worker loads the\n * WebAssembly engine and the fonts once.\n *\n * ```ts\n * const engine = await createWorkerEngine({\n * worker: new Worker(new URL('./pdf.worker.ts', import.meta.url), {\n * type: 'module',\n * }),\n * })\n * const pdf = await engine.render(<Invoice invoice={invoice} />, { signal })\n * ```\n *\n * @experimental Exempt from SemVer in 1.x until promoted: the API of\n * `@rentnerkev/pdf/worker` and its protocol may change in a minor release.\n */\nexport async function createWorkerEngine({\n worker,\n wasmModule,\n ...options\n}: WorkerEngineOptions): Promise<WorkerEngine> {\n let connection: WorkerConnection\n let version: string\n let themeWarnings: WorkerEngine['themeWarnings']\n try {\n const prepared = prepareEngineOptions(options)\n connection = connectWorker(worker)\n const reply = await connection.request(\n {\n type: 'init',\n init: {\n settings: prepared.settings,\n defaultFont: prepared.defaultFont,\n ...(wasmModule === undefined\n ? {}\n : {\n wasmModule:\n wasmModule instanceof URL\n ? wasmModule.href\n : wasmModule,\n }),\n },\n },\n [],\n )\n if (reply.type !== 'ready') throw unexpected(reply)\n version = reply.version\n themeWarnings = engineThemeWarnings(\n prepared.themeWarnings,\n reply.themeWarnings,\n )\n } catch (error) {\n stop(worker)\n throw toRentnerPdfError(error)\n }\n\n // Requests are not tracked: closing cancels them (their signals) and\n // stops the worker at once instead of waiting for its answer.\n const lifecycle = new EngineLifecycle()\n const close = (): Promise<void> =>\n lifecycle.close(() => {\n connection.close(\n new RentnerPdfError('ENGINE_CLOSED', 'the engine was closed'),\n )\n stop(worker)\n })\n\n return {\n backend: 'wasm',\n version,\n themeWarnings,\n render: (input, renderOptions) =>\n lifecycle.run(renderOptions?.signal, (signal) =>\n renderInWorker(connection, input, signal, false, readPdf),\n ),\n renderDetailed: (input, renderOptions) =>\n lifecycle.run(renderOptions?.signal, (signal) =>\n renderInWorker(connection, input, signal, true, readResult),\n ),\n // Queued before it returns, so it takes its turn before every\n // render called after it.\n registerFont: (font) =>\n lifecycle.run(undefined, async (signal) => {\n try {\n const reply = await connection.request(\n { type: 'registerFont', font: fontBytes(font, 'font') },\n [],\n signal,\n )\n if (reply.type !== 'fontRegistered') throw unexpected(reply)\n } catch (error) {\n throw toRentnerPdfError(error)\n }\n }),\n close,\n [DISPOSE]: () => {\n void close()\n },\n [ASYNC_DISPOSE]: close,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../web/src/worker/client.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,gEAAgE;AAChE,mEAAmE;AACnE,wEAAwE;AACxE,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAChF,OAAO,EACH,mBAAmB,EACnB,oBAAoB,EACpB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AAM,EAAE,EAAE;YACtC,IAAI,CAAC;gBACD,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,OAAO,CACjC,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EACvD,EAAE,EACF,MAAM,CACT,CAAA;gBACD,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB;oBAAE,MAAM,UAAU,CAAC,KAAK,CAAC,CAAA;YAChE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,MAAM,iBAAiB,CAAC,KAAK,CAAC,CAAA;YAClC,CAAC;QACL,CAAC,CAAC;QACN,KAAK;QACL,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE;YACZ,KAAK,KAAK,EAAE,CAAA;QAChB,CAAC;QACD,CAAC,aAAa,CAAC,EAAE,KAAK;KACzB,CAAA;AACL,CAAC","sourcesContent":["// `createWorkerEngine`: the familiar render API on the page, with the\n// WebAssembly engine in a Web Worker (concurrency model in 04 –\n// Architecture). Components run on the page, because elements hold\n// functions; their IR is encoded here and crosses as bytes. Errors come\n// back in the engine's format and get their code, IR path and JSX source\n// here, where the source locator of the evaluation lives.\nimport { RentnerPdfError, toRentnerPdfError } from '../engine/errors.ts'\nimport { throwIfAborted } from '../engine/abort.ts'\nimport { encodeDocument } from '../engine/encode.ts'\nimport { fontBytes } from '../engine/fonts.ts'\nimport { ASYNC_DISPOSE, DISPOSE, EngineLifecycle } from '../engine/lifecycle.ts'\nimport {\n engineThemeWarnings,\n prepareEngineOptions,\n prepareInput,\n} from '../engine/prepare.ts'\nimport { pdfBytes, toRenderResult } from '../engine/render-result.ts'\nimport type { RenderInput } from '../engine/Types/engine.ts'\nimport type { SourceLocator } from '../engine/Types/errors.ts'\nimport type { PdfBytes, RenderResult } from '../engine/Types/render-result.ts'\nimport { connectWorker } from './connection.ts'\nimport type { WorkerConnection } from './Types/connection.ts'\nimport type { WorkerReply } from './Types/protocol.ts'\nimport type {\n RenderWorkerPort,\n WorkerEngine,\n WorkerEngineOptions,\n} from './Types/worker-engine.ts'\n\nconst unexpected = (reply: WorkerReply): TypeError =>\n new TypeError(`unexpected answer from the render worker: ${reply.type}`)\n\nconst stop = (worker: RenderWorkerPort): void => {\n if (worker.terminate !== undefined) worker.terminate()\n else worker.close?.()\n}\n\nconst readPdf = (reply: WorkerReply): PdfBytes => {\n if (reply.type !== 'rendered') throw unexpected(reply)\n return pdfBytes(reply.pdf)\n}\n\nconst readResult = (\n reply: WorkerReply,\n locate: SourceLocator | undefined,\n): RenderResult => {\n if (reply.type !== 'renderedDetailed') throw unexpected(reply)\n return toRenderResult(reply.result, locate)\n}\n\n/**\n * Evaluates and encodes `input` here, renders it in the worker and reads\n * the answer with `read`.\n */\nasync function renderInWorker<T>(\n connection: WorkerConnection,\n input: RenderInput,\n signal: AbortSignal | undefined,\n detailed: boolean,\n read: (reply: WorkerReply, locate: SourceLocator | undefined) => T,\n): Promise<T> {\n throwIfAborted(signal)\n const { document, locate } = await prepareInput(input)\n throwIfAborted(signal)\n try {\n const transfer: ArrayBuffer[] = []\n const encoded = encodeDocument(document, transfer)\n const reply = await connection.request(\n { type: 'render', detailed, document: encoded },\n transfer,\n signal,\n )\n return read(reply, locate)\n } catch (error) {\n throw toRentnerPdfError(error, locate)\n }\n}\n\n/**\n * Creates an engine that renders in a Web Worker running\n * `serveRenderWorker()`; reuse it for every render. The worker loads the\n * WebAssembly engine and the fonts once.\n *\n * ```ts\n * const engine = await createWorkerEngine({\n * worker: new Worker(new URL('./pdf.worker.ts', import.meta.url), {\n * type: 'module',\n * }),\n * })\n * const pdf = await engine.render(<Invoice invoice={invoice} />, { signal })\n * ```\n *\n * @experimental Exempt from SemVer in 1.x until promoted: the API of\n * `@rentnerkev/pdf/worker` and its protocol may change in a minor release.\n */\nexport async function createWorkerEngine({\n worker,\n wasmModule,\n ...options\n}: WorkerEngineOptions): Promise<WorkerEngine> {\n let connection: WorkerConnection | undefined\n let version: string\n let themeWarnings: WorkerEngine['themeWarnings']\n try {\n const prepared = prepareEngineOptions(options)\n connection = connectWorker(worker)\n const reply = await connection.request(\n {\n type: 'init',\n init: {\n settings: prepared.settings,\n defaultFont: prepared.defaultFont,\n ...(wasmModule === undefined\n ? {}\n : {\n wasmModule:\n wasmModule instanceof URL\n ? wasmModule.href\n : wasmModule,\n }),\n },\n },\n [],\n )\n if (reply.type !== 'ready') throw unexpected(reply)\n version = reply.version\n themeWarnings = engineThemeWarnings(\n prepared.themeWarnings,\n reply.themeWarnings,\n )\n } catch (error) {\n connection?.close(error)\n stop(worker)\n throw toRentnerPdfError(error)\n }\n const connected = connection\n\n // Requests are not tracked: closing cancels them (their signals) and\n // stops the worker at once instead of waiting for its answer.\n const lifecycle = new EngineLifecycle()\n const close = (): Promise<void> =>\n lifecycle.close(() => {\n connected.close(\n new RentnerPdfError('ENGINE_CLOSED', 'the engine was closed'),\n )\n stop(worker)\n })\n\n return {\n backend: 'wasm',\n version,\n themeWarnings,\n render: (input, renderOptions) =>\n lifecycle.run(renderOptions?.signal, (signal) =>\n renderInWorker(connected, input, signal, false, readPdf),\n ),\n renderDetailed: (input, renderOptions) =>\n lifecycle.run(renderOptions?.signal, (signal) =>\n renderInWorker(connected, input, signal, true, readResult),\n ),\n // Queued before it returns, so it takes its turn before every\n // render called after it.\n registerFont: (font) =>\n lifecycle.run(undefined, async (signal) => {\n try {\n const reply = await connected.request(\n { type: 'registerFont', font: fontBytes(font, 'font') },\n [],\n signal,\n )\n if (reply.type !== 'fontRegistered') throw unexpected(reply)\n } catch (error) {\n throw toRentnerPdfError(error)\n }\n }),\n close,\n [DISPOSE]: () => {\n void close()\n },\n [ASYNC_DISPOSE]: close,\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { WorkerConnection } from './Types/connection.
|
|
2
|
-
import type { RenderWorkerPort } from './Types/worker-engine.
|
|
1
|
+
import type { WorkerConnection } from './Types/connection.js';
|
|
2
|
+
import type { RenderWorkerPort } from './Types/worker-engine.js';
|
|
3
3
|
/** Connects to a worker that runs `serveRenderWorker()`. */
|
|
4
4
|
export declare function connectWorker(port: RenderWorkerPort): WorkerConnection;
|
|
5
5
|
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RenderWorkerPort } from './Types/worker-engine.
|
|
2
|
-
import type { WorkerError, WorkerProtocol, WorkerRequest, WorkerResponse } from './Types/protocol.
|
|
1
|
+
import type { RenderWorkerPort } from './Types/worker-engine.js';
|
|
2
|
+
import type { WorkerError, WorkerProtocol, WorkerRequest, WorkerResponse } from './Types/protocol.js';
|
|
3
3
|
export declare const WORKER_PROTOCOL: WorkerProtocol;
|
|
4
4
|
/** Whether a message is a request of this protocol; others are ignored. */
|
|
5
5
|
export declare const isWorkerRequest: (value: unknown) => value is WorkerRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../web/src/worker/protocol.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,eAAe,GAAmB,qBAAqB,CAAA;AAEpE,MAAM,YAAY,GAAyB,IAAI,GAAG,CAAC;IAC/C,MAAM;IACN,QAAQ;IACR,cAAc;CACjB,CAAC,CAAA;AACF,MAAM,aAAa,GAAyB,IAAI,GAAG,CAAC;IAChD,OAAO;IACP,UAAU;IACV,kBAAkB;IAClB,gBAAgB;IAChB,QAAQ;CACX,CAAC,CAAA;AAEF,MAAM,SAAS,GAAG,CACd,KAAc,EACd,KAA2B,EAC4B,EAAE,CACzD,OAAO,KAAK,KAAK,QAAQ;IACzB,KAAK,KAAK,IAAI;IACd,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,eAAe;IAClD,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CA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,CAAC,IAAY,EAAsB,EAAE;QAC/C,MAAM,KAAK,GACP,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI;YAC7C,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC;YAC7B,CAAC,CAAC,SAAS,CAAA;QACnB,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;IACxD,CAAC,CAAA;IACD,MAAM,KAAK,GAAG,IAAI,KAAK,CACnB,KAAK,CAAC,SAAS,CAAC,IAAI,gDAAgD,CACvE,CAAA;IACD,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,OAAO,CAAA;IACrC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAA;IAC5B,IAAI,KAAK,KAAK,SAAS;QAAE,KAAK,CAAC,KAAK,GAAG,KAAK,CAAA;IAC5C,OAAO,KAAK,CAAA;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,KAAiB;IAC1C,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAA;IACxB,OAAO,MAAM,YAAY,WAAW;QAChC,KAAK,CAAC,UAAU,KAAK,CAAC;QACtB,KAAK,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU;QACtC,CAAC,CAAE,KAAiC;QACpC,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAA;AAC/B,CAAC","sourcesContent":["// The messages between the page and a render worker (`@rentnerkev/pdf/worker`):\n// requests carry an id that the answer repeats, and only plain data crosses.\n// Buffers
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../web/src/worker/protocol.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,eAAe,GAAmB,qBAAqB,CAAA;AAEpE,MAAM,YAAY,GAAyB,IAAI,GAAG,CAAC;IAC/C,MAAM;IACN,QAA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M,YAAY,WAAW;QAChC,KAAK,CAAC,UAAU,KAAK,CAAC;QACtB,KAAK,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU;QACtC,CAAC,CAAE,KAAiC;QACpC,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAA;AAC/B,CAAC","sourcesContent":["// The messages between the page and a render worker (`@rentnerkev/pdf/worker`):\n// requests carry an id that the answer repeats, and only plain data crosses.\n// Buffers the encoder creates and the PDF are transferred. The caller's\n// buffers are copied, so they stay usable.\nimport type { RenderWorkerPort } from './Types/worker-engine.ts'\nimport type {\n WorkerError,\n WorkerProtocol,\n WorkerRequest,\n WorkerResponse,\n} from './Types/protocol.ts'\n\nexport const WORKER_PROTOCOL: WorkerProtocol = 'rentnerpdf-worker/1'\n\nconst requestTypes: ReadonlySet<unknown> = new Set([\n 'init',\n 'render',\n 'registerFont',\n])\nconst responseTypes: ReadonlySet<unknown> = new Set([\n 'ready',\n 'rendered',\n 'renderedDetailed',\n 'fontRegistered',\n 'failed',\n])\n\nconst isMessage = (\n value: unknown,\n types: ReadonlySet<unknown>,\n): value is { readonly type: string; readonly id: number } =>\n typeof value === 'object' &&\n value !== null &&\n Reflect.get(value, 'protocol') === WORKER_PROTOCOL &&\n types.has(Reflect.get(value, 'type')) &&\n typeof Reflect.get(value, 'id') === 'number'\n\n/** Whether a message is a request of this protocol; others are ignored. */\nexport const isWorkerRequest = (value: unknown): value is WorkerRequest =>\n isMessage(value, requestTypes)\n\n/** Whether a message is a response of this protocol; others are ignored. */\nexport const isWorkerResponse = (value: unknown): value is WorkerResponse =>\n isMessage(value, responseTypes)\n\n/** Whether `value` can serve as one end of a render worker channel. */\nexport const isWorkerPort = (value: unknown): value is RenderWorkerPort =>\n typeof value === 'object' &&\n value !== null &&\n typeof Reflect.get(value, 'postMessage') === 'function' &&\n typeof Reflect.get(value, 'addEventListener') === 'function' &&\n typeof Reflect.get(value, 'removeEventListener') === 'function'\n\n/** A thrown value as it crosses to the page. */\nexport function toWorkerError(error: unknown): WorkerError {\n if (!(error instanceof Error)) {\n return { name: 'Error', message: String(error) }\n }\n return error.stack === undefined\n ? { name: error.name, message: error.message }\n : { name: error.name, message: error.message, stack: error.stack }\n}\n\n/**\n * The error a worker reported, rebuilt on the page; `toRentnerPdfError`\n * turns engine errors (`CODE: message (at path)`) into `RentnerPdfError`s.\n */\nexport function fromWorkerError(reported: WorkerError | undefined): Error {\n // Answers come from another realm: read only string fields.\n const field = (name: string): string | undefined => {\n const value: unknown =\n typeof reported === 'object' && reported !== null\n ? Reflect.get(reported, name)\n : undefined\n return typeof value === 'string' ? value : undefined\n }\n const error = new Error(\n field('message') ?? 'the render worker reported an unreadable error',\n )\n error.name = field('name') ?? 'Error'\n const stack = field('stack')\n if (stack !== undefined) error.stack = stack\n return error\n}\n\n/**\n * The bytes in a buffer of their own that can be transferred: `bytes` when\n * they span a whole `ArrayBuffer`, otherwise a copy (a view into a larger\n * buffer, such as a pooled Node.js `Buffer`, must not take that buffer\n * along).\n */\nexport function transferable(bytes: Uint8Array): Uint8Array<ArrayBuffer> {\n const { buffer } = bytes\n return buffer instanceof ArrayBuffer &&\n bytes.byteOffset === 0 &&\n bytes.byteLength === buffer.byteLength\n ? (bytes as Uint8Array<ArrayBuffer>)\n : new Uint8Array(bytes)\n}\n"]}
|
package/dist/worker/serve.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import type { Backend } from '../engine/Types/backend.
|
|
2
|
-
import type { WorkerEngineInit } from './Types/protocol.
|
|
3
|
-
import type { RenderWorkerPort } from './Types/worker-engine.
|
|
1
|
+
import type { Backend } from '../engine/Types/backend.js';
|
|
2
|
+
import type { WorkerEngineInit } from './Types/protocol.js';
|
|
3
|
+
import type { RenderWorkerPort } from './Types/worker-engine.js';
|
|
4
4
|
/** Creates the worker's engine; tests replace it. */
|
|
5
5
|
export type OpenBackend = (init: WorkerEngineInit) => Promise<Backend>;
|
|
6
|
-
/** The WebAssembly engine with the bundled fonts, loaded in this realm. */
|
|
7
|
-
export declare const openWasmBackend: OpenBackend;
|
|
8
6
|
/** Serves the protocol on `port` with the engine `open` creates. */
|
|
9
7
|
export declare function serveWorker(port: RenderWorkerPort, open: OpenBackend): void;
|
|
10
8
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../web/src/worker/serve.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AASzD,OAAO,KAAK,EACR,gBAAgB,EAInB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAER,gBAAgB,EACnB,MAAM,0BAA0B,CAAA;AAEjC,qDAAqD;AACrD,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,gBAAgB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../web/src/worker/serve.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AASzD,OAAO,KAAK,EACR,gBAAgB,EAInB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAER,gBAAgB,EACnB,MAAM,0BAA0B,CAAA;AAEjC,qDAAqD;AACrD,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,gBAAgB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAgCtE,oEAAoE;AACpE,wBAAgB,WAAW,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CA4E3E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAa/D"}
|
package/dist/worker/serve.js
CHANGED
|
@@ -7,7 +7,7 @@ import { loadDefaultFonts } from '../engine/default-fonts.js';
|
|
|
7
7
|
import { loadWasmBinding } from '../wasm/loader.js';
|
|
8
8
|
import { WORKER_PROTOCOL, isWorkerPort, isWorkerRequest, toWorkerError, transferable, } from './protocol.js';
|
|
9
9
|
/** The WebAssembly engine with the bundled fonts, loaded in this realm. */
|
|
10
|
-
|
|
10
|
+
const openWasmBackend = async ({ settings, defaultFont, wasmModule, }) => {
|
|
11
11
|
const [binding, defaultFonts] = await Promise.all([
|
|
12
12
|
loadWasmBinding(wasmModule),
|
|
13
13
|
defaultFont ? loadDefaultFonts() : [],
|
package/dist/worker/serve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../web/src/worker/serve.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,sEAAsE;AACtE,uEAAuE;AACvE,iCAAiC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAE7D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EACH,eAAe,EACf,YAAY,EACZ,eAAe,EACf,aAAa,EACb,YAAY,GACf,MAAM,eAAe,CAAA;AAetB,2EAA2E;AAC3E,MAAM,
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../web/src/worker/serve.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,sEAAsE;AACtE,uEAAuE;AACvE,iCAAiC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAE7D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EACH,eAAe,EACf,YAAY,EACZ,eAAe,EACf,aAAa,EACb,YAAY,GACf,MAAM,eAAe,CAAA;AAetB,2EAA2E;AAC3E,MAAM,eAAe,GAAgB,KAAK,EAAE,EACxC,QAAQ,EACR,WAAW,EACX,U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CAAA;IACL,CAAC;IACD,WAAW,CAAC,KAAK,EAAE,eAAe,CAAC,CAAA;AACvC,CAAC","sourcesContent":["// The worker's side of the protocol: it creates the WebAssembly engine\n// from the page's `init` request and renders the encoded documents it\n// receives, one after another, in the order they arrive. It never sees\n// components or JSX, only bytes.\nimport { createWasmBackend } from '../engine/backends/wasm.ts'\nimport { loadDefaultFonts } from '../engine/default-fonts.ts'\nimport type { Backend } from '../engine/Types/backend.ts'\nimport { loadWasmBinding } from '../wasm/loader.ts'\nimport {\n WORKER_PROTOCOL,\n isWorkerPort,\n isWorkerRequest,\n toWorkerError,\n transferable,\n} from './protocol.ts'\nimport type {\n WorkerEngineInit,\n WorkerReply,\n WorkerRequest,\n WorkerResponse,\n} from './Types/protocol.ts'\nimport type {\n RenderWorkerEvent,\n RenderWorkerPort,\n} from './Types/worker-engine.ts'\n\n/** Creates the worker's engine; tests replace it. */\nexport type OpenBackend = (init: WorkerEngineInit) => Promise<Backend>\n\n/** The WebAssembly engine with the bundled fonts, loaded in this realm. */\nconst openWasmBackend: OpenBackend = async ({\n settings,\n defaultFont,\n wasmModule,\n}) => {\n const [binding, defaultFonts] = await Promise.all([\n loadWasmBinding(wasmModule),\n defaultFont ? loadDefaultFonts() : [],\n ])\n return createWasmBackend(binding, { ...settings, defaultFonts })\n}\n\n/** The answer to a render request and the buffers it hands over. */\nasync function render(\n backend: Backend,\n request: Extract<WorkerRequest, { readonly type: 'render' }>,\n): Promise<{ reply: WorkerReply; transfer: ArrayBuffer[] }> {\n if (!request.detailed) {\n const pdf = transferable(await backend.render(request.document))\n return { reply: { type: 'rendered', pdf }, transfer: [pdf.buffer] }\n }\n const result = await backend.renderDetailed(request.document)\n const pdf = transferable(result.pdf)\n return {\n reply: { type: 'renderedDetailed', result: { ...result, pdf } },\n transfer: [pdf.buffer],\n }\n}\n\n/** Serves the protocol on `port` with the engine `open` creates. */\nexport function serveWorker(port: RenderWorkerPort, open: OpenBackend): void {\n let backend: Promise<Backend> | undefined\n let queue = Promise.resolve()\n\n const send = (response: WorkerResponse, transfer: ArrayBuffer[]): void => {\n port.postMessage(response, transfer)\n }\n\n const answer = async (request: WorkerRequest): Promise<void> => {\n const { id } = request\n try {\n if (request.type === 'init') {\n if (backend !== undefined) {\n throw new Error('the render worker has an engine already')\n }\n const opening = open(request.init)\n backend = opening\n // A failed engine can be created again with a new `init`.\n const { version, themeWarnings } = await opening.catch(\n (error: unknown) => {\n backend = undefined\n throw error\n },\n )\n send(\n {\n type: 'ready',\n version,\n themeWarnings,\n protocol: WORKER_PROTOCOL,\n id,\n },\n [],\n )\n return\n }\n if (backend === undefined) {\n throw new Error(\n 'the render worker has no engine; create one with createWorkerEngine()',\n )\n }\n if (request.type === 'registerFont') {\n const engine = await backend\n engine.registerFont(request.font)\n send(\n { type: 'fontRegistered', protocol: WORKER_PROTOCOL, id },\n [],\n )\n return\n }\n const { reply, transfer } = await render(await backend, request)\n send({ ...reply, protocol: WORKER_PROTOCOL, id }, transfer)\n } catch (error) {\n send(\n {\n type: 'failed',\n error: toWorkerError(error),\n protocol: WORKER_PROTOCOL,\n id,\n },\n [],\n )\n }\n }\n\n port.addEventListener('message', (event: RenderWorkerEvent) => {\n const { data } = event\n if (!isWorkerRequest(data)) return\n queue = queue\n .then(() => answer(data))\n .catch((error: unknown) => {\n // Posting the answer itself failed; the page cannot be told.\n console.error('RentnerPDF render worker:', error)\n })\n })\n port.start?.()\n}\n\n/**\n * Serves render requests from `createWorkerEngine()` inside a Web Worker:\n * the worker's own scope by default, or `port`. Call it once at the top\n * of the worker module.\n *\n * ```ts\n * // pdf.worker.ts\n * import { serveRenderWorker } from '@rentnerkev/pdf/worker'\n *\n * serveRenderWorker()\n * ```\n *\n * @experimental Exempt from SemVer in 1.x until promoted, like the rest of\n * `@rentnerkev/pdf/worker` and its protocol.\n */\nexport function serveRenderWorker(port?: RenderWorkerPort): void {\n const scope: unknown = port ?? globalThis\n if (port === undefined && 'window' in globalThis) {\n throw new TypeError(\n 'serveRenderWorker() runs inside a Web Worker; on the page, use createWorkerEngine()',\n )\n }\n if (!isWorkerPort(scope)) {\n throw new TypeError(\n 'serveRenderWorker() needs a worker scope or a MessagePort to serve',\n )\n }\n serveWorker(scope, openWasmBackend)\n}\n"]}
|
package/dist/worker.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createWorkerEngine } from './worker/client.
|
|
2
|
-
export { serveRenderWorker } from './worker/serve.
|
|
3
|
-
export type { RenderWorkerEvent, RenderWorkerPort, WorkerEngine, WorkerEngineOptions, } from './worker/Types/worker-engine.
|
|
1
|
+
export { createWorkerEngine } from './worker/client.js';
|
|
2
|
+
export { serveRenderWorker } from './worker/serve.js';
|
|
3
|
+
export type { RenderWorkerEvent, RenderWorkerPort, WorkerEngine, WorkerEngineOptions, } from './worker/Types/worker-engine.js';
|
|
4
4
|
//# sourceMappingURL=worker.d.ts.map
|
package/docs/usage.md
CHANGED
|
@@ -35,7 +35,7 @@ Every TypeScript example in this guide is a region of a file in [`web/src/tests/
|
|
|
35
35
|
|
|
36
36
|
## Install
|
|
37
37
|
|
|
38
|
-
Requirements: Node.js 22.14+ or Bun 1.4
|
|
38
|
+
Requirements: Node.js 22.14+ or Bun 1.4+. TypeScript consumers need [TypeScript 5.7 or later](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-7.html#typedarrays-are-now-generic) for typed-array generics such as `Uint8Array<ArrayBuffer>` in the public declarations. The `@rentnerkev/pdf/react` entry requires React 19. See [Compatibility](#compatibility) for the CI matrix.
|
|
39
39
|
|
|
40
40
|
Install the published package with `npm install @rentnerkev/pdf` (or `bun add @rentnerkev/pdf`). It bundles the native engines for Windows and Linux on x64 and ARM64, including glibc and musl on Linux, and the WebAssembly engine. `backend: 'auto'` loads the matching native binary or falls back to WebAssembly, including on macOS.
|
|
41
41
|
|
|
@@ -48,11 +48,11 @@ bun run build:wasm # WebAssembly engine, including on macOS
|
|
|
48
48
|
bun run pack:packages # TypeScript build and one tarball with the built engines
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
Install the tarball from `packages/tarballs/` in your project.
|
|
51
|
+
Install the tarball from `packages/tarballs/` in your project. Use the version shown in the filename.
|
|
52
52
|
|
|
53
53
|
```sh
|
|
54
|
-
bun add <clone>/packages/tarballs/rentnerkev-pdf
|
|
55
|
-
npm install <clone>/packages/tarballs/rentnerkev-pdf
|
|
54
|
+
bun add <clone>/packages/tarballs/rentnerkev-pdf-<version>.tgz
|
|
55
|
+
npm install <clone>/packages/tarballs/rentnerkev-pdf-<version>.tgz
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
The release matrix supplies all six native builds and WebAssembly. A local tarball only includes the engines built from that checkout. `createEngine()` checks that the selected engine can read the IR version the TypeScript API writes.
|
|
@@ -63,13 +63,13 @@ What runs where and what the repository's CI checks for it, on every pull reques
|
|
|
63
63
|
|
|
64
64
|
### Runtimes
|
|
65
65
|
|
|
66
|
-
| Runtime | Engine
|
|
67
|
-
| --------------------------------- |
|
|
68
|
-
| Node.js 22.14+ | Native; WebAssembly
|
|
69
|
-
| Bun 1.4+ | Native; WebAssembly
|
|
70
|
-
| Browsers | WebAssembly in a Web Worker
|
|
71
|
-
| Deno | –
|
|
72
|
-
| Cloudflare Workers, edge runtimes | –
|
|
66
|
+
| Runtime | Engine | Status | Checked in CI |
|
|
67
|
+
| --------------------------------- | ------------------------------------------------------ | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
68
|
+
| Node.js 22.14+ | Native; WebAssembly when the native binary cannot load | Supported | Node.js 24: installs of the packed `@rentnerkev/pdf` on all six native targets, a separate WebAssembly render with the same package, the React smoke test, the TanStack Start `node-server` output. Node.js 22 and 26 do not run in CI |
|
|
69
|
+
| Bun 1.4+ | Native; WebAssembly when the native binary cannot load | Supported | Bun 1.4.5: the whole test suite (Linux x64), installs on glibc Linux and Windows (x64, arm64), the TanStack Start `bun` output and `vite dev`. Not on musl |
|
|
70
|
+
| Browsers | WebAssembly in a Web Worker | Preview helpers; the bundler setup is manual ([details](#browser-preview)) | No browser runs: the worker protocol is tested over a `MessageChannel` and in a Bun `Worker`, `@rentnerkev/pdf/worker` is bundled for browsers without React or the native addon, and the packed `@rentnerkev/pdf` renders through the worker protocol |
|
|
71
|
+
| Deno | – | Not tested | – |
|
|
72
|
+
| Cloudflare Workers, edge runtimes | – | Not supported yet ([recipe](recipes/cloudflare-workers.md)) | – |
|
|
73
73
|
|
|
74
74
|
### Platforms
|
|
75
75
|
|
|
@@ -97,7 +97,7 @@ What runs where and what the repository's CI checks for it, on every pull reques
|
|
|
97
97
|
| Other Vite and Nitro apps | `rentnerPdf()` | The plugin's unit tests and the TanStack Start check |
|
|
98
98
|
| Next.js 16 | `serverExternalPackages: ['@rentnerkev/pdf']` | Locally: Next.js 16.4.6 on Windows ([recipe](recipes/nextjs.md)) |
|
|
99
99
|
| `node:http`, Express 5, Fastify 5, Hono 4, `Bun.serve` | None | Locally: Windows, Node.js 25 and Bun 1.4.5 ([recipe](recipes/node-and-bun.md)) |
|
|
100
|
-
| Tailwind CSS 4, `clsx`, `tailwind-merge` 3 | [Editor support](#editor-support) | CI: the [support matrix](tailwind-support.md) covers every class of Tailwind CSS 4.3.5; theme reading and `tailwind-merge` 3.7.
|
|
100
|
+
| Tailwind CSS 4, `clsx`, `tailwind-merge` 3 | [Editor support](#editor-support) | CI: the [support matrix](tailwind-support.md) covers every class of Tailwind CSS 4.3.5; theme reading and `tailwind-merge` 3.7.2 in the test suite |
|
|
101
101
|
| Cloudflare Workers, Next.js' edge runtime, Nitro's edge presets | – | Not supported yet |
|
|
102
102
|
|
|
103
103
|
## IR versioning
|
|
@@ -143,11 +143,11 @@ Text sizes, spacing and colors are Tailwind CSS v4 utilities; `p-page` is Rentne
|
|
|
143
143
|
|
|
144
144
|
## Authoring paths
|
|
145
145
|
|
|
146
|
-
| Path | Use it for | Imports
|
|
147
|
-
| ------------------------------------------------------ | -------------------------------------------------------------- |
|
|
148
|
-
| Own JSX runtime (`jsxImportSource: '@rentnerkev/pdf'`) | Node.js/Bun services without React; fastest, zero dependencies | `@rentnerkev/pdf`
|
|
149
|
-
| React (`@rentnerkev/pdf/react`) | React projects: hooks, context, `use()`, the app's JSX setup | `@rentnerkev/pdf/react` + engine from
|
|
150
|
-
| Factories (`document()`, `page()`, `view()`, …) | Generated documents, tools, tests; what both JSX paths build | `@rentnerkev/pdf`
|
|
146
|
+
| Path | Use it for | Imports |
|
|
147
|
+
| ------------------------------------------------------ | -------------------------------------------------------------- | ------------------------------------------------------- |
|
|
148
|
+
| Own JSX runtime (`jsxImportSource: '@rentnerkev/pdf'`) | Node.js/Bun services without React; fastest, zero dependencies | `@rentnerkev/pdf` |
|
|
149
|
+
| React (`@rentnerkev/pdf/react`) | React projects: hooks, context, `use()`, the app's JSX setup | `@rentnerkev/pdf/react` + engine from `@rentnerkev/pdf` |
|
|
150
|
+
| Factories (`document()`, `page()`, `view()`, …) | Generated documents, tools, tests; what both JSX paths build | `@rentnerkev/pdf` |
|
|
151
151
|
|
|
152
152
|
Both JSX paths use the same component names and props and render byte-identical PDFs, so switching is an import change.
|
|
153
153
|
|
|
@@ -406,7 +406,7 @@ const { pageCount, warnings, diagnostics } = await engine.renderDetailed(letter)
|
|
|
406
406
|
const sameBytes: Uint8Array = engine.renderSync(letter)
|
|
407
407
|
```
|
|
408
408
|
|
|
409
|
-
`render(element)` from
|
|
409
|
+
`render(element)` from `@rentnerkev/pdf` creates a default engine (bundled fonts, default options) on first use and reuses it; use your own engine for fonts, themes or `strict`.
|
|
410
410
|
|
|
411
411
|
**Backends.** Both render the same input to the same bytes. The native engine renders on its own threads, off the event loop: at most `threads` documents at once, further renders wait in order (`engine.stats().rendersQueued`). The WebAssembly engine renders on the calling thread: `render()` returns a promise but blocks the thread while it works. If its module crashes, the call rejects with `INTERNAL` (a bug in RentnerPDF) and the engine starts the module again for the next call; it registers the same font buffers again, so leave them unchanged.
|
|
412
412
|
|
|
@@ -418,7 +418,7 @@ const backend = wasm.backend // 'wasm'; 'auto' gives 'native' where the addon lo
|
|
|
418
418
|
const version = wasm.version // the engine's version, the same as the package's
|
|
419
419
|
```
|
|
420
420
|
|
|
421
|
-
`engine.version` is the version of the
|
|
421
|
+
`engine.version` is the version of the native or WebAssembly engine used to render. Both engines bundled in the npm release carry the version of `@rentnerkev/pdf`.
|
|
422
422
|
|
|
423
423
|
### Cancellation
|
|
424
424
|
|
|
@@ -1335,8 +1335,8 @@ export function InvoiceDownload({ draft }: { draft: Draft }) {
|
|
|
1335
1335
|
```
|
|
1336
1336
|
|
|
1337
1337
|
- `createWorkerEngine({ worker, …options })` takes the engine options of `createEngine()` except `backend` and `threads` (fonts as bytes, `theme`, `limits`, `strict`, caches, `wasmModule`) and returns an engine with `render()` and `renderDetailed()`: the same bytes, warnings and errors (codes, IR paths, JSX sources) as `createEngine({ backend: 'wasm' })`. `worker` is a `Worker` that calls `serveRenderWorker()`, or a `MessagePort`.
|
|
1338
|
-
- Components are evaluated on the page
|
|
1339
|
-
- `usePdf(document, { engine, debounceMs })` renders when the document
|
|
1338
|
+
- Components are evaluated on the page. The encoder transfers the buffers it creates to the worker, and the worker transfers the PDF buffer back. Caller-owned buffers are copied when sent to the worker so they stay usable on the page. One render at a time runs in the worker, in call order. An aborted `signal` rejects at once and a waiting render never reaches the worker; a render already in the worker finishes there and its result is dropped. `registerFont()` and `close()` work as on [`createEngine()`](#fonts-later-and-closing); `close()` also stops the worker.
|
|
1339
|
+
- `usePdf(document, { engine, debounceMs })` renders when the document content changes and settles for `debounceMs` (200 by default). A newer document aborts the render in progress. `state` holds `status` (`idle`, `rendering`, `done`, `failed`), the latest `pdf`, its object `url`, `pageCount`, `warnings`, `diagnostics` and `error`. The previous PDF stays visible while a newer one renders or fails. The hook revokes its object URL when the PDF is replaced and on unmount. Pass an object with `renderDetailed()`, a promise of one, or a factory as `engine`. The hook calls the latest factory when a render starts. Changing the renderer object or promise starts a new render.
|
|
1340
1340
|
- `<PdfPreview>` shows the URL in an `<iframe>` (a fresh frame per PDF) and passes other props to it; `fallback` shows until the first PDF.
|
|
1341
1341
|
|
|
1342
1342
|
Not in this release:
|
|
@@ -1476,21 +1476,21 @@ Reasons: `KEEP_WITH_NEXT`, `KEEP_TOGETHER`, `KEEP_TOGETHER_TOO_TALL` (split anyw
|
|
|
1476
1476
|
|
|
1477
1477
|
Document content, images, fonts, SVGs and letterheads may come from untrusted users. The engine configuration comes from you. Each render in `renderMany()` receives its own budget. A document that exceeds a budget fails with `LIMIT_EXCEEDED` and the path in the document.
|
|
1478
1478
|
|
|
1479
|
-
| Limit
|
|
1480
|
-
|
|
|
1481
|
-
| Encoded document (IR JSON or React markup)
|
|
1482
|
-
| Pages, including pages created by overflow
|
|
1483
|
-
| Content nodes
|
|
1484
|
-
| Nesting depth below a page
|
|
1485
|
-
| Bytes of one `className
|
|
1486
|
-
| Classes in one `className`
|
|
1487
|
-
| Asset bytes of one render (images, SVGs, PDFs, attachments, table data)
|
|
1488
|
-
| Pixels of one image, read from its header before decoding
|
|
1489
|
-
| Combined raster pixels of one render
|
|
1490
|
-
| Estimated work of parsing and embedding letterheads
|
|
1491
|
-
| Elements of one SVG as it will be drawn¹
|
|
1492
|
-
| UTF-8 bytes of one paragraph or
|
|
1493
|
-
| Bytes of one font file, checked when the engine registers it
|
|
1479
|
+
| Limit | Option | Default | Guards against |
|
|
1480
|
+
| ----------------------------------------------------------------------------- | ------------------------- | ------------- | ------------------------------------------------------- |
|
|
1481
|
+
| Encoded document (IR JSON or React markup) | `maxInputBytes` | 256 MiB | Oversized requests |
|
|
1482
|
+
| Pages, including pages created by overflow | `maxPages` | 100,000 | Runaway pagination |
|
|
1483
|
+
| Content nodes, including table rows, cells, text parts and marker assignments | `maxNodes` | 10,000,000 | Huge trees and page marker state |
|
|
1484
|
+
| Nesting depth below a page | `maxDepth` | 60 | Deep recursion |
|
|
1485
|
+
| Bytes of one `className`, inline CSS value or marker name | `maxClassNameBytes` | 16 KiB | Expensive style parsing and marker names |
|
|
1486
|
+
| Classes in one `className` | `maxClasses` | 512 | Expensive class parsing |
|
|
1487
|
+
| Asset bytes of one render (images, SVGs, PDFs, attachments, table data) | `maxAssetBytes` | 256 MiB | Memory |
|
|
1488
|
+
| Pixels of one image, read from its header before decoding | `maxImagePixels` | 100,000,000 | Decompression bombs |
|
|
1489
|
+
| Combined raster pixels of one render | `maxTotalImagePixels` | 1,000,000,000 | Cumulative image decoding and memory |
|
|
1490
|
+
| Estimated work of parsing and embedding letterheads | `maxLetterheadParseBytes` | 256 MiB | Expensive object traversal and stream expansion |
|
|
1491
|
+
| Elements of one SVG as it will be drawn¹ | `maxSvgElements` | 200,000 | SVG bombs |
|
|
1492
|
+
| UTF-8 bytes of one paragraph, table cell, or marker value | `maxTextBytes` | 4 MiB | Shaping memory, including resolved placeholders |
|
|
1493
|
+
| Bytes of one font file, checked when the engine registers it | `maxFontBytes` | 64 MiB | Font memory; `createEngine()` or `registerFont()` fails |
|
|
1494
1494
|
|
|
1495
1495
|
¹ The converter counts each expanded element instance, including `<use>` copies and referenced clip geometry. It also charges each style rule, each group of up to 32 path segments or dash entries and each group of up to 32 gradient stops per painted element. All text processed for one SVG shares `maxTextBytes`.
|
|
1496
1496
|
|
|
@@ -1502,19 +1502,21 @@ The total pixel budget counts each referenced asset buffer once, including raste
|
|
|
1502
1502
|
|
|
1503
1503
|
These fixed bounds also apply with `limits: 'unlimited'`.
|
|
1504
1504
|
|
|
1505
|
-
| Bound | Value
|
|
1506
|
-
| -------------------------------------------- |
|
|
1507
|
-
| JSON nesting | 128 values
|
|
1508
|
-
| React markup nesting, attributes per element | `maxDepth` + 4 levels (at most 256), 32 attributes
|
|
1509
|
-
| Table columns, cell spans | 1,000 columns per table; `colSpan` 1–1,000, `rowSpan` 1–65,534
|
|
1510
|
-
| SVG structure | 256 levels of elements, `<use>` copies and gradient references, 16 levels of clip paths
|
|
1511
|
-
| SVG expansion | 1,000,000 expanded elements and 1,000,000 path segments and dash entries. An arc emits at most four cubic segments.
|
|
1512
|
-
| SVG CSS | 4 MiB of stylesheet text and fixed budgets for selector work and cascaded declarations
|
|
1513
|
-
| Letterhead PDF structure | 128 object levels, 32 filters per decoded stream and 64 MiB per predictor row
|
|
1514
|
-
| Attachment names | 255 bytes; no `/`, `\`, `:`, control or bidirectional control characters; not `.` or `..`
|
|
1515
|
-
| Metadata | `meta.lang` a BCP 47 tag; no control characters in text fields
|
|
1516
|
-
| Theme CSS (`themeFromCss()`, `theme`) | 4 MiB and 50,000 custom properties per stylesheet, 16 nesting levels, 256 stylesheets, 10,000 JS overrides
|
|
1517
|
-
|
|
|
1505
|
+
| Bound | Value | Result |
|
|
1506
|
+
| -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
|
|
1507
|
+
| JSON nesting | 128 values | `INVALID_DOCUMENT` |
|
|
1508
|
+
| React markup nesting, attributes per element | `maxDepth` + 4 levels (at most 256), 32 attributes | `LIMIT_EXCEEDED` |
|
|
1509
|
+
| Table columns, cell spans | 1,000 columns per table; `colSpan` 1–1,000, `rowSpan` 1–65,534 | `LIMIT_EXCEEDED`; spans `INVALID_DOCUMENT` |
|
|
1510
|
+
| SVG structure | 256 levels of elements, `<use>` copies and gradient references, 16 levels of clip paths. DTDs and reference cycles are rejected. | DTDs and cycles use `UNSUPPORTED_IMAGE`. Depth bounds use `LIMIT_EXCEEDED`. |
|
|
1511
|
+
| SVG expansion | 1,000,000 expanded elements and 1,000,000 path segments and dash entries. An arc emits at most four cubic segments. | `LIMIT_EXCEEDED` |
|
|
1512
|
+
| SVG CSS | 4 MiB of stylesheet text and fixed budgets for selector work and cascaded declarations | `LIMIT_EXCEEDED` |
|
|
1513
|
+
| Letterhead PDF structure | 128 object levels, 32 filters per decoded stream and 64 MiB per predictor row | `LIMIT_EXCEEDED` |
|
|
1514
|
+
| Attachment names | 255 bytes; no `/`, `\`, `:`, control or bidirectional control characters; not `.` or `..` | `INVALID_DOCUMENT` |
|
|
1515
|
+
| Metadata | `meta.lang` a BCP 47 tag; no control characters in text fields | `INVALID_DOCUMENT` |
|
|
1516
|
+
| Theme CSS (`themeFromCss()`, `theme`) | 4 MiB and 50,000 custom properties per stylesheet, 16 nesting levels, 256 stylesheets, 10,000 JS overrides | `INVALID_THEME` warnings; the rest is ignored |
|
|
1517
|
+
| Resolved theme variables | 16 KiB per value, 1,024 substitutions per value, and 16 MiB across retained variable names and values | `INVALID_THEME` warnings |
|
|
1518
|
+
| Table number formats | 256 bytes per prefix, suffix, decimal separator, or group separator | `LIMIT_EXCEEDED` |
|
|
1519
|
+
| Theme files (`themeFromCssFile()`) | 64 files, 16 import levels, 256 imports per file, 4 MiB per file, 16 MiB in all; 100 warnings | `INVALID_THEME` warnings; a missing entry file throws |
|
|
1518
1520
|
|
|
1519
1521
|
The letterhead preflight checks object nesting, cross-reference data, stream expansion and page tree work before opening the PDF. The engine checks each selected page's content before embedding it. It rejects encrypted and unreadable PDFs with `UNSUPPORTED_IMAGE`. Structural limits also apply when the preflight cannot bound an ambiguous object stream, such as a filter defined through an indirect reference.
|
|
1520
1522
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rentnerkev/pdf",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Native-speed PDF engine for TypeScript with a Rust core, React-style components and Tailwind-style classes.",
|
|
5
5
|
"author": "RentnerKev",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
10
|
+
"sideEffects": [
|
|
11
|
+
"./dist/tailwind.css"
|
|
12
|
+
],
|
|
10
13
|
"files": [
|
|
11
14
|
"dist",
|
|
12
15
|
"README.md",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { PdfBytes } from './Types/render-result.ts';
|
|
2
|
-
/**
|
|
3
|
-
* The bindings return fresh buffers backed by an `ArrayBuffer` (a Node.js
|
|
4
|
-
* `Buffer` or a copy out of WebAssembly memory); this states it for the
|
|
5
|
-
* types and copies anything else.
|
|
6
|
-
*/
|
|
7
|
-
export declare const pdfBytes: (bytes: Uint8Array) => PdfBytes;
|
|
8
|
-
//# sourceMappingURL=pdf-bytes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pdf-bytes.d.ts","sourceRoot":"","sources":["../../web/src/engine/pdf-bytes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAExD;;;;GAIG;AACH,eAAO,MAAM,QAAQ,UAAW,UAAU,KAAG,QAGd,CAAA"}
|
package/dist/engine/pdf-bytes.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The bindings return fresh buffers backed by an `ArrayBuffer` (a Node.js
|
|
3
|
-
* `Buffer` or a copy out of WebAssembly memory); this states it for the
|
|
4
|
-
* types and copies anything else.
|
|
5
|
-
*/
|
|
6
|
-
export const pdfBytes = (bytes) => bytes.buffer instanceof ArrayBuffer
|
|
7
|
-
? bytes
|
|
8
|
-
: new Uint8Array(bytes);
|
|
9
|
-
//# sourceMappingURL=pdf-bytes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pdf-bytes.js","sourceRoot":"","sources":["../../web/src/engine/pdf-bytes.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAiB,EAAY,EAAE,CACpD,KAAK,CAAC,MAAM,YAAY,WAAW;IAC/B,CAAC,CAAE,KAAkB;IACrB,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAA","sourcesContent":["import type { PdfBytes } from './Types/render-result.ts'\n\n/**\n * The bindings return fresh buffers backed by an `ArrayBuffer` (a Node.js\n * `Buffer` or a copy out of WebAssembly memory); this states it for the\n * types and copies anything else.\n */\nexport const pdfBytes = (bytes: Uint8Array): PdfBytes =>\n bytes.buffer instanceof ArrayBuffer\n ? (bytes as PdfBytes)\n : new Uint8Array(bytes)\n"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { RenderWarning } from '../../engine/Types/render-result.ts';
|
|
2
|
-
/** The warnings of one theme, bounded. */
|
|
3
|
-
export interface ThemeWarningList {
|
|
4
|
-
/** Adds an `INVALID_THEME` warning, or counts it once the list is full. */
|
|
5
|
-
readonly add: (message: string, path: string | undefined) => void;
|
|
6
|
-
/** The warnings, followed by a summary of the ones that did not fit. */
|
|
7
|
-
readonly list: () => readonly RenderWarning[];
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=warnings.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../../../web/src/theme/Types/warnings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAExE,0CAA0C;AAC1C,MAAM,WAAW,gBAAgB;IAC7B,2EAA2E;IAC3E,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAA;IACjE,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,SAAS,aAAa,EAAE,CAAA;CAChD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"warnings.js","sourceRoot":"","sources":["../../../web/src/theme/Types/warnings.ts"],"names":[],"mappings":"","sourcesContent":["import type { RenderWarning } from '../../engine/Types/render-result.ts'\n\n/** The warnings of one theme, bounded. */\nexport interface ThemeWarningList {\n /** Adds an `INVALID_THEME` warning, or counts it once the list is full. */\n readonly add: (message: string, path: string | undefined) => void\n /** The warnings, followed by a summary of the ones that did not fit. */\n readonly list: () => readonly RenderWarning[]\n}\n"]}
|