@laminapdf/sdk 0.0.0-stage → 0.2.0-alpha.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 +208 -2
- package/dist/api.d.ts +23 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +11 -0
- package/dist/api.js.map +1 -0
- package/dist/builder.d.ts +319 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +540 -0
- package/dist/builder.js.map +1 -0
- package/dist/defined.d.ts +5 -0
- package/dist/defined.d.ts.map +1 -0
- package/dist/defined.js +7 -0
- package/dist/defined.js.map +1 -0
- package/dist/document.d.ts +241 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +427 -0
- package/dist/document.js.map +1 -0
- package/dist/entry/node.d.ts +30 -0
- package/dist/entry/node.d.ts.map +1 -0
- package/dist/entry/node.js +37 -0
- package/dist/entry/node.js.map +1 -0
- package/dist/entry/workerd.d.ts +30 -0
- package/dist/entry/workerd.d.ts.map +1 -0
- package/dist/entry/workerd.js +37 -0
- package/dist/entry/workerd.js.map +1 -0
- package/dist/errors.d.ts +102 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +137 -0
- package/dist/errors.js.map +1 -0
- package/dist/explain.d.ts +20 -0
- package/dist/explain.d.ts.map +1 -0
- package/dist/explain.js +14 -0
- package/dist/explain.js.map +1 -0
- package/dist/font.d.ts +66 -0
- package/dist/font.d.ts.map +1 -0
- package/dist/font.js +103 -0
- package/dist/font.js.map +1 -0
- package/dist/generated/builder-enums.d.ts +29 -0
- package/dist/generated/builder-enums.d.ts.map +1 -0
- package/dist/generated/builder-enums.js +80 -0
- package/dist/generated/builder-enums.js.map +1 -0
- package/dist/generated/codes.d.ts +97 -0
- package/dist/generated/codes.d.ts.map +1 -0
- package/dist/generated/codes.js +453 -0
- package/dist/generated/codes.js.map +1 -0
- package/dist/generated/explain.d.ts +6 -0
- package/dist/generated/explain.d.ts.map +1 -0
- package/dist/generated/explain.js +138 -0
- package/dist/generated/explain.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +80 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +127 -0
- package/dist/init.js.map +1 -0
- package/dist/loader/fetch.d.ts +3 -0
- package/dist/loader/fetch.d.ts.map +1 -0
- package/dist/loader/fetch.js +2 -0
- package/dist/loader/fetch.js.map +1 -0
- package/dist/loader/node.d.ts +3 -0
- package/dist/loader/node.d.ts.map +1 -0
- package/dist/loader/node.js +9 -0
- package/dist/loader/node.js.map +1 -0
- package/dist/loader/workerd.d.ts +3 -0
- package/dist/loader/workerd.d.ts.map +1 -0
- package/dist/loader/workerd.js +15 -0
- package/dist/loader/workerd.js.map +1 -0
- package/dist/matrix.d.ts +16 -0
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +36 -0
- package/dist/matrix.js.map +1 -0
- package/dist/path.d.ts +34 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +49 -0
- package/dist/path.js.map +1 -0
- package/dist/source/http.d.ts +36 -0
- package/dist/source/http.d.ts.map +1 -0
- package/dist/source/http.js +211 -0
- package/dist/source/http.js.map +1 -0
- package/dist/source/range.d.ts +70 -0
- package/dist/source/range.d.ts.map +1 -0
- package/dist/source/range.js +96 -0
- package/dist/source/range.js.map +1 -0
- package/dist/text.d.ts +90 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +127 -0
- package/dist/text.js.map +1 -0
- package/dist/transaction.d.ts +36 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +47 -0
- package/dist/transaction.js.map +1 -0
- package/dist/types.d.ts +79 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/dist/worker/client.d.ts +87 -0
- package/dist/worker/client.d.ts.map +1 -0
- package/dist/worker/client.js +405 -0
- package/dist/worker/client.js.map +1 -0
- package/dist/worker/emitter.d.ts +12 -0
- package/dist/worker/emitter.d.ts.map +1 -0
- package/dist/worker/emitter.js +34 -0
- package/dist/worker/emitter.js.map +1 -0
- package/dist/worker/entry.d.ts +2 -0
- package/dist/worker/entry.d.ts.map +1 -0
- package/dist/worker/entry.js +4 -0
- package/dist/worker/entry.js.map +1 -0
- package/dist/worker/index.d.ts +7 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +4 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/protocol.d.ts +82 -0
- package/dist/worker/protocol.d.ts.map +1 -0
- package/dist/worker/protocol.js +11 -0
- package/dist/worker/protocol.js.map +1 -0
- package/dist/worker/server.d.ts +51 -0
- package/dist/worker/server.d.ts.map +1 -0
- package/dist/worker/server.js +460 -0
- package/dist/worker/server.js.map +1 -0
- package/dist/worker/support.d.ts +39 -0
- package/dist/worker/support.d.ts.map +1 -0
- package/dist/worker/support.js +25 -0
- package/dist/worker/support.js.map +1 -0
- package/dist/worker/transfer.d.ts +3 -0
- package/dist/worker/transfer.d.ts.map +1 -0
- package/dist/worker/transfer.js +13 -0
- package/dist/worker/transfer.js.map +1 -0
- package/dist/worker/types.d.ts +43 -0
- package/dist/worker/types.d.ts.map +1 -0
- package/dist/worker/types.js +2 -0
- package/dist/worker/types.js.map +1 -0
- package/package.json +91 -3
- package/schemas/error.schema.json +288 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.js","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAyB,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAwD,MAAM,EAAE,UAAU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
|
|
1
|
+
import type { InitOptions, WasmSource } from "../init.js";
|
|
2
|
+
/**
|
|
3
|
+
* Loads the base WebAssembly module (read from the file next to the package); with `{ text: true }`, the text
|
|
4
|
+
* module too. Idempotent: later calls return at once (or load the text module). Everything else
|
|
5
|
+
* in the package is synchronous and needs this promise to have resolved.
|
|
6
|
+
*
|
|
7
|
+
* @param input - where the base module comes from (a URL, `Response`, bytes or
|
|
8
|
+
* `WebAssembly.Module`), or options; omitted, the file next to the package.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* await init(); // or: await init({ text: true })
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function init(input?: WasmSource | InitOptions): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Loads the text module (fonts, shaping and text layout; about 940 KB gzipped). Builders
|
|
17
|
+
* created afterwards can draw text. Idempotent.
|
|
18
|
+
*
|
|
19
|
+
* @param source - where it comes from; omitted, the file next to the package.
|
|
20
|
+
*/
|
|
21
|
+
export declare function loadText(source?: WasmSource): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Loads the extract module (reading plus text extraction). Documents opened afterwards can
|
|
24
|
+
* extract text with `page.text()`. Idempotent; not needed when the text module is loaded.
|
|
25
|
+
*
|
|
26
|
+
* @param source - where it comes from; omitted, the file next to the package.
|
|
27
|
+
*/
|
|
28
|
+
export declare function loadExtract(source?: WasmSource): Promise<void>;
|
|
29
|
+
export * from "../api.js";
|
|
30
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/entry/node.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI1D;;;;;;;;;;;GAWG;AACH,wBAAgB,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9D;AAED,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { initWith, loadExtractWith, loadTextWith } from "../init.js";
|
|
2
|
+
import { locate } from "../loader/node.js";
|
|
3
|
+
/**
|
|
4
|
+
* Loads the base WebAssembly module (read from the file next to the package); with `{ text: true }`, the text
|
|
5
|
+
* module too. Idempotent: later calls return at once (or load the text module). Everything else
|
|
6
|
+
* in the package is synchronous and needs this promise to have resolved.
|
|
7
|
+
*
|
|
8
|
+
* @param input - where the base module comes from (a URL, `Response`, bytes or
|
|
9
|
+
* `WebAssembly.Module`), or options; omitted, the file next to the package.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* await init(); // or: await init({ text: true })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function init(input) {
|
|
16
|
+
return initWith(locate, input);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Loads the text module (fonts, shaping and text layout; about 940 KB gzipped). Builders
|
|
20
|
+
* created afterwards can draw text. Idempotent.
|
|
21
|
+
*
|
|
22
|
+
* @param source - where it comes from; omitted, the file next to the package.
|
|
23
|
+
*/
|
|
24
|
+
export function loadText(source) {
|
|
25
|
+
return loadTextWith(locate, source);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Loads the extract module (reading plus text extraction). Documents opened afterwards can
|
|
29
|
+
* extract text with `page.text()`. Idempotent; not needed when the text module is loaded.
|
|
30
|
+
*
|
|
31
|
+
* @param source - where it comes from; omitted, the file next to the package.
|
|
32
|
+
*/
|
|
33
|
+
export function loadExtract(source) {
|
|
34
|
+
return loadExtractWith(locate, source);
|
|
35
|
+
}
|
|
36
|
+
export * from "../api.js";
|
|
37
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/entry/node.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,IAAI,CAAC,KAAgC;IACnD,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAmB;IAC1C,OAAO,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,MAAmB;IAC7C,OAAO,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACzC,CAAC;AAED,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { InitOptions, WasmSource } from "../init.js";
|
|
2
|
+
/**
|
|
3
|
+
* Loads the base WebAssembly module (imported with the Worker's bundle); with `{ text: true }`, the text
|
|
4
|
+
* module too. Idempotent: later calls return at once (or load the text module). Everything else
|
|
5
|
+
* in the package is synchronous and needs this promise to have resolved.
|
|
6
|
+
*
|
|
7
|
+
* @param input - where the base module comes from (a URL, `Response`, bytes or
|
|
8
|
+
* `WebAssembly.Module`), or options; omitted, the file next to the package.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* await init(); // or: await init({ text: true })
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function init(input?: WasmSource | InitOptions): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Loads the text module (fonts, shaping and text layout; about 940 KB gzipped). Builders
|
|
17
|
+
* created afterwards can draw text. Idempotent.
|
|
18
|
+
*
|
|
19
|
+
* @param source - where it comes from; omitted, the file next to the package.
|
|
20
|
+
*/
|
|
21
|
+
export declare function loadText(source?: WasmSource): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Loads the extract module (reading plus text extraction). Documents opened afterwards can
|
|
24
|
+
* extract text with `page.text()`. Idempotent; not needed when the text module is loaded.
|
|
25
|
+
*
|
|
26
|
+
* @param source - where it comes from; omitted, the file next to the package.
|
|
27
|
+
*/
|
|
28
|
+
export declare function loadExtract(source?: WasmSource): Promise<void>;
|
|
29
|
+
export * from "../api.js";
|
|
30
|
+
//# sourceMappingURL=workerd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerd.d.ts","sourceRoot":"","sources":["../../src/entry/workerd.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI1D;;;;;;;;;;;GAWG;AACH,wBAAgB,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9D;AAED,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { initWith, loadExtractWith, loadTextWith } from "../init.js";
|
|
2
|
+
import { locate } from "../loader/workerd.js";
|
|
3
|
+
/**
|
|
4
|
+
* Loads the base WebAssembly module (imported with the Worker's bundle); with `{ text: true }`, the text
|
|
5
|
+
* module too. Idempotent: later calls return at once (or load the text module). Everything else
|
|
6
|
+
* in the package is synchronous and needs this promise to have resolved.
|
|
7
|
+
*
|
|
8
|
+
* @param input - where the base module comes from (a URL, `Response`, bytes or
|
|
9
|
+
* `WebAssembly.Module`), or options; omitted, the file next to the package.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* await init(); // or: await init({ text: true })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function init(input) {
|
|
16
|
+
return initWith(locate, input);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Loads the text module (fonts, shaping and text layout; about 940 KB gzipped). Builders
|
|
20
|
+
* created afterwards can draw text. Idempotent.
|
|
21
|
+
*
|
|
22
|
+
* @param source - where it comes from; omitted, the file next to the package.
|
|
23
|
+
*/
|
|
24
|
+
export function loadText(source) {
|
|
25
|
+
return loadTextWith(locate, source);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Loads the extract module (reading plus text extraction). Documents opened afterwards can
|
|
29
|
+
* extract text with `page.text()`. Idempotent; not needed when the text module is loaded.
|
|
30
|
+
*
|
|
31
|
+
* @param source - where it comes from; omitted, the file next to the package.
|
|
32
|
+
*/
|
|
33
|
+
export function loadExtract(source) {
|
|
34
|
+
return loadExtractWith(locate, source);
|
|
35
|
+
}
|
|
36
|
+
export * from "../api.js";
|
|
37
|
+
//# sourceMappingURL=workerd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerd.js","sourceRoot":"","sources":["../../src/entry/workerd.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,IAAI,CAAC,KAAgC;IACnD,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAmB;IAC1C,OAAO,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,MAAmB;IAC7C,OAAO,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACzC,CAAC;AAED,cAAc,WAAW,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { type ErrorCode, type ErrorKind, RAISED_BY_PACKAGE, type WarningCode } from "./generated/codes.js";
|
|
2
|
+
export type { ErrorKind };
|
|
3
|
+
/** Where a problem is (ADR 0026 §1.1); each field has one meaning, all lamina-made values. */
|
|
4
|
+
export interface Location {
|
|
5
|
+
/** Byte offset in the input file. */
|
|
6
|
+
readonly offset?: number;
|
|
7
|
+
/** Object number of the indirect object the problem is in or at. */
|
|
8
|
+
readonly object?: number;
|
|
9
|
+
/** Byte offset in the decoded data of `object`. */
|
|
10
|
+
readonly streamOffset?: number;
|
|
11
|
+
/** 0-based page index (ADR 0027 §6). */
|
|
12
|
+
readonly pageIndex?: number;
|
|
13
|
+
/** A LaminaPdfId (`p12.0`). */
|
|
14
|
+
readonly id?: string;
|
|
15
|
+
}
|
|
16
|
+
/** The ADR 0026 §1 object: what `LaminaPdfError.toJSON()` returns and the WASM throws. */
|
|
17
|
+
export interface Diagnostic<C extends string = ErrorCode> {
|
|
18
|
+
readonly code: C;
|
|
19
|
+
readonly kind: ErrorKind;
|
|
20
|
+
readonly message: string;
|
|
21
|
+
readonly hint?: string;
|
|
22
|
+
readonly didYouMean?: readonly string[];
|
|
23
|
+
readonly location?: Location;
|
|
24
|
+
readonly data?: Readonly<Record<string, unknown>>;
|
|
25
|
+
readonly docsUrl: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A warning: something Lamina PDF repaired or skipped (ADR 0003, ADR 0026 §1). The §1 object without
|
|
29
|
+
* `didYouMean`; document text appears only in `data`.
|
|
30
|
+
*/
|
|
31
|
+
export type LaminaPdfWarning = Omit<Diagnostic<WarningCode>, "didYouMean">;
|
|
32
|
+
/**
|
|
33
|
+
* The one error class of `@laminapdf/sdk` (ADR 0026 §7). `message`, `hint` and `didYouMean` never
|
|
34
|
+
* hold document text (ADR 0026 §4); that goes in `data`, marked untrusted on the code's page at
|
|
35
|
+
* `docsUrl`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* try {
|
|
40
|
+
* Document.open(bytes, { password: "secret" });
|
|
41
|
+
* } catch (e) {
|
|
42
|
+
* if (isLaminaPdfError(e, "wrong-password")) askAgain();
|
|
43
|
+
* else throw e;
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare class LaminaPdfError<C extends ErrorCode = ErrorCode> extends Error {
|
|
48
|
+
readonly name = "LaminaPdfError";
|
|
49
|
+
/** The stable code (`fixtures/codes.json`). */
|
|
50
|
+
readonly code: C;
|
|
51
|
+
/** What the caller can do about it. */
|
|
52
|
+
readonly kind: ErrorKind;
|
|
53
|
+
/** One actionable sentence for this code. */
|
|
54
|
+
readonly hint?: string;
|
|
55
|
+
/** For `usage` errors: the closest known names (Lamina PDF's own vocabulary). */
|
|
56
|
+
readonly didYouMean?: readonly string[];
|
|
57
|
+
/** Where in the input or the document. */
|
|
58
|
+
readonly location?: Location;
|
|
59
|
+
/** Code-specific fields, documented on the code's page (the only place document text appears). */
|
|
60
|
+
readonly data?: Readonly<Record<string, unknown>>;
|
|
61
|
+
/** The code's page. */
|
|
62
|
+
readonly docsUrl: string;
|
|
63
|
+
/**
|
|
64
|
+
* @param diagnostic - the ADR 0026 §1 object.
|
|
65
|
+
* @param options - `cause`, when wrapping another error.
|
|
66
|
+
*/
|
|
67
|
+
constructor(diagnostic: Diagnostic<C>, options?: {
|
|
68
|
+
readonly cause?: unknown;
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* For `data-pending`: the byte ranges a range document needs fetched before the call can
|
|
72
|
+
* succeed (`data.ranges`); `undefined` for other codes. {@link Document.ensure} fetches them.
|
|
73
|
+
*/
|
|
74
|
+
get ranges(): readonly {
|
|
75
|
+
readonly offset: number;
|
|
76
|
+
readonly length: number;
|
|
77
|
+
}[] | undefined;
|
|
78
|
+
/** The ADR 0026 §1 object (for logs, workers and `--json` output); optional fields omitted. */
|
|
79
|
+
toJSON(): Diagnostic<C>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Whether `e` is a {@link LaminaPdfError}, with `code` when given.
|
|
83
|
+
*
|
|
84
|
+
* @param e - anything caught.
|
|
85
|
+
* @param code - the code to match.
|
|
86
|
+
* @returns true for a LaminaPdfError (with that code).
|
|
87
|
+
*/
|
|
88
|
+
export declare function isLaminaPdfError<C extends ErrorCode>(e: unknown, code?: C): e is LaminaPdfError<C>;
|
|
89
|
+
/** Whether `value` is the §1 object the WASM throws. */
|
|
90
|
+
export declare function isDiagnostic(value: unknown): value is Diagnostic<ErrorCode>;
|
|
91
|
+
/** A LaminaPdfError for a code `@laminapdf/sdk` raises itself (kind and hint from codes.json). */
|
|
92
|
+
export declare function packageError<C extends keyof typeof RAISED_BY_PACKAGE>(code: C, message: string, extra?: Pick<Diagnostic<C>, "didYouMean" | "data"> & {
|
|
93
|
+
readonly cause?: unknown;
|
|
94
|
+
}): LaminaPdfError<C>;
|
|
95
|
+
/** The names in `known` within two edits of `given` (case-insensitive), closest first. */
|
|
96
|
+
export declare function didYouMean(given: string, known: readonly string[]): string[];
|
|
97
|
+
/**
|
|
98
|
+
* Runs `f`, turning the §1 object the WASM throws into a {@link LaminaPdfError}. Other errors (a
|
|
99
|
+
* `RangeError`, a trap) pass through unchanged.
|
|
100
|
+
*/
|
|
101
|
+
export declare function guard<T>(f: () => T): T;
|
|
102
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors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AY,CAAC,CAAC,SAAS,MAAM,OAAO,iBAAiB,EACnE,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC,GAAG;IAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GACpF,cAAc,CAAC,CAAC,CAAC,CAOnB;AAED,0FAA0F;AAC1F,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAmB5E;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAMtC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// LaminaPdfError and LaminaPdfWarning (ADR 0026 §1, §7): every error @laminapdf/sdk throws is a
|
|
2
|
+
// LaminaPdfError built from the §1 object the WASM throws, or raised here with the kind and hint
|
|
3
|
+
// codes.json gives the code.
|
|
4
|
+
import { docsUrl, RAISED_BY_PACKAGE } from "./generated/codes.js";
|
|
5
|
+
/**
|
|
6
|
+
* The one error class of `@laminapdf/sdk` (ADR 0026 §7). `message`, `hint` and `didYouMean` never
|
|
7
|
+
* hold document text (ADR 0026 §4); that goes in `data`, marked untrusted on the code's page at
|
|
8
|
+
* `docsUrl`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* try {
|
|
13
|
+
* Document.open(bytes, { password: "secret" });
|
|
14
|
+
* } catch (e) {
|
|
15
|
+
* if (isLaminaPdfError(e, "wrong-password")) askAgain();
|
|
16
|
+
* else throw e;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export class LaminaPdfError extends Error {
|
|
21
|
+
name = "LaminaPdfError";
|
|
22
|
+
/** The stable code (`fixtures/codes.json`). */
|
|
23
|
+
code;
|
|
24
|
+
/** What the caller can do about it. */
|
|
25
|
+
kind;
|
|
26
|
+
/** One actionable sentence for this code. */
|
|
27
|
+
hint;
|
|
28
|
+
/** For `usage` errors: the closest known names (Lamina PDF's own vocabulary). */
|
|
29
|
+
didYouMean;
|
|
30
|
+
/** Where in the input or the document. */
|
|
31
|
+
location;
|
|
32
|
+
/** Code-specific fields, documented on the code's page (the only place document text appears). */
|
|
33
|
+
data;
|
|
34
|
+
/** The code's page. */
|
|
35
|
+
docsUrl;
|
|
36
|
+
/**
|
|
37
|
+
* @param diagnostic - the ADR 0026 §1 object.
|
|
38
|
+
* @param options - `cause`, when wrapping another error.
|
|
39
|
+
*/
|
|
40
|
+
constructor(diagnostic, options) {
|
|
41
|
+
super(diagnostic.message, options);
|
|
42
|
+
this.code = diagnostic.code;
|
|
43
|
+
this.kind = diagnostic.kind;
|
|
44
|
+
this.docsUrl = diagnostic.docsUrl;
|
|
45
|
+
if (diagnostic.hint !== undefined)
|
|
46
|
+
this.hint = diagnostic.hint;
|
|
47
|
+
// ADR 0026 §1: optional keys are omitted, and an empty list is no candidates at all.
|
|
48
|
+
if (diagnostic.didYouMean !== undefined && diagnostic.didYouMean.length > 0)
|
|
49
|
+
this.didYouMean = diagnostic.didYouMean;
|
|
50
|
+
if (diagnostic.location !== undefined)
|
|
51
|
+
this.location = diagnostic.location;
|
|
52
|
+
if (diagnostic.data !== undefined)
|
|
53
|
+
this.data = diagnostic.data;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* For `data-pending`: the byte ranges a range document needs fetched before the call can
|
|
57
|
+
* succeed (`data.ranges`); `undefined` for other codes. {@link Document.ensure} fetches them.
|
|
58
|
+
*/
|
|
59
|
+
get ranges() {
|
|
60
|
+
if (this.code !== "data-pending")
|
|
61
|
+
return undefined;
|
|
62
|
+
const raw = this.data?.ranges;
|
|
63
|
+
if (!Array.isArray(raw))
|
|
64
|
+
return [];
|
|
65
|
+
return raw.flatMap((r) => Array.isArray(r) && typeof r[0] === "number" && typeof r[1] === "number" ? [{ offset: r[0], length: r[1] }] : []);
|
|
66
|
+
}
|
|
67
|
+
/** The ADR 0026 §1 object (for logs, workers and `--json` output); optional fields omitted. */
|
|
68
|
+
toJSON() {
|
|
69
|
+
return {
|
|
70
|
+
code: this.code,
|
|
71
|
+
kind: this.kind,
|
|
72
|
+
message: this.message,
|
|
73
|
+
...(this.hint === undefined ? {} : { hint: this.hint }),
|
|
74
|
+
...(this.didYouMean === undefined ? {} : { didYouMean: this.didYouMean }),
|
|
75
|
+
...(this.location === undefined ? {} : { location: this.location }),
|
|
76
|
+
...(this.data === undefined ? {} : { data: this.data }),
|
|
77
|
+
docsUrl: this.docsUrl,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Whether `e` is a {@link LaminaPdfError}, with `code` when given.
|
|
83
|
+
*
|
|
84
|
+
* @param e - anything caught.
|
|
85
|
+
* @param code - the code to match.
|
|
86
|
+
* @returns true for a LaminaPdfError (with that code).
|
|
87
|
+
*/
|
|
88
|
+
export function isLaminaPdfError(e, code) {
|
|
89
|
+
return e instanceof LaminaPdfError && (code === undefined || e.code === code);
|
|
90
|
+
}
|
|
91
|
+
/** Whether `value` is the §1 object the WASM throws. */
|
|
92
|
+
export function isDiagnostic(value) {
|
|
93
|
+
if (typeof value !== "object" || value === null || value instanceof Error)
|
|
94
|
+
return false;
|
|
95
|
+
const v = value;
|
|
96
|
+
return typeof v.code === "string" && typeof v.kind === "string" && typeof v.docsUrl === "string";
|
|
97
|
+
}
|
|
98
|
+
/** A LaminaPdfError for a code `@laminapdf/sdk` raises itself (kind and hint from codes.json). */
|
|
99
|
+
export function packageError(code, message, extra = {}) {
|
|
100
|
+
const { kind, hint } = RAISED_BY_PACKAGE[code];
|
|
101
|
+
const { cause, ...fields } = extra;
|
|
102
|
+
return new LaminaPdfError({ code, kind, message, hint, ...fields, docsUrl: docsUrl(code) }, cause === undefined ? undefined : { cause });
|
|
103
|
+
}
|
|
104
|
+
/** The names in `known` within two edits of `given` (case-insensitive), closest first. */
|
|
105
|
+
export function didYouMean(given, known) {
|
|
106
|
+
const distance = (a, b) => {
|
|
107
|
+
let row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
108
|
+
for (let i = 0; i < a.length; i++) {
|
|
109
|
+
const next = [i + 1];
|
|
110
|
+
for (let j = 0; j < b.length; j++) {
|
|
111
|
+
const cost = (row[j] ?? 0) + (a[i] === b[j] ? 0 : 1);
|
|
112
|
+
next.push(Math.min(cost, (row[j + 1] ?? 0) + 1, (next[j] ?? 0) + 1));
|
|
113
|
+
}
|
|
114
|
+
row = next;
|
|
115
|
+
}
|
|
116
|
+
return row[b.length] ?? 0;
|
|
117
|
+
};
|
|
118
|
+
const lower = given.toLowerCase();
|
|
119
|
+
return known
|
|
120
|
+
.map((k) => [distance(lower, k.toLowerCase()), k])
|
|
121
|
+
.filter(([d]) => d <= 2)
|
|
122
|
+
.sort((x, y) => x[0] - y[0])
|
|
123
|
+
.map(([, k]) => k);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Runs `f`, turning the §1 object the WASM throws into a {@link LaminaPdfError}. Other errors (a
|
|
127
|
+
* `RangeError`, a trap) pass through unchanged.
|
|
128
|
+
*/
|
|
129
|
+
export function guard(f) {
|
|
130
|
+
try {
|
|
131
|
+
return f();
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
throw isDiagnostic(e) ? new LaminaPdfError(e) : e;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,iGAAiG;AACjG,6BAA6B;AAC7B,OAAO,EAAE,OAAO,EAAkC,iBAAiB,EAAoB,MAAM,sBAAsB,CAAC;AA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,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3B,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAI,CAAU;IACjC,IAAI,CAAC;QACH,OAAO,CAAC,EAAE,CAAC;IACb,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ErrorCode, type WarningCode } from "./generated/codes.js";
|
|
2
|
+
export type { ErrorCode, ErrorKind, WarningCode } from "./generated/codes.js";
|
|
3
|
+
export { DOCS_URL, docsUrl, ERROR_CODES, HINTS, KINDS, WARNING_CODES } from "./generated/codes.js";
|
|
4
|
+
/** Whether `code` is one of Lamina PDF's error or warning codes. */
|
|
5
|
+
export declare function isCode(code: string): code is ErrorCode | WarningCode;
|
|
6
|
+
/**
|
|
7
|
+
* The explain page of `code` as Markdown (`docs/errors/<code>.md`: what happened, why, how to fix,
|
|
8
|
+
* an example and the `data` fields), or `undefined` for a string that is not a code. The same
|
|
9
|
+
* text as `docsUrl` and `laminapdf::explain` in Rust.
|
|
10
|
+
*
|
|
11
|
+
* @param code - an error or warning code, such as `LaminaPdfError.code`.
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { explain } from "@laminapdf/sdk/explain";
|
|
15
|
+
* console.log(explain("wrong-password"));
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function explain(code: ErrorCode | WarningCode): string;
|
|
19
|
+
export declare function explain(code: string): string | undefined;
|
|
20
|
+
//# sourceMappingURL=explain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.d.ts","sourceRoot":"","sources":["../src/explain.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAS,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAG/E,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEnG,oEAAoE;AACpE,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,SAAS,GAAG,WAAW,CAEpE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,GAAG,MAAM,CAAC;AAC/D,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC"}
|
package/dist/explain.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// `@laminapdf/sdk/explain` (ADR 0026 §6): every code's explain page, kind and hint, for tools and
|
|
2
|
+
// agents that want to tell a user what a code means and what to do. A separate subpath, so the
|
|
3
|
+
// ~80 KB of page text and the tables stay out of the main bundle (and out of the WebAssembly).
|
|
4
|
+
import { HINTS } from "./generated/codes.js";
|
|
5
|
+
import { PAGES } from "./generated/explain.js";
|
|
6
|
+
export { DOCS_URL, docsUrl, ERROR_CODES, HINTS, KINDS, WARNING_CODES } from "./generated/codes.js";
|
|
7
|
+
/** Whether `code` is one of Lamina PDF's error or warning codes. */
|
|
8
|
+
export function isCode(code) {
|
|
9
|
+
return Object.hasOwn(HINTS, code);
|
|
10
|
+
}
|
|
11
|
+
export function explain(code) {
|
|
12
|
+
return isCode(code) ? PAGES[code] : undefined;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=explain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.js","sourceRoot":"","sources":["../src/explain.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,+FAA+F;AAC/F,+FAA+F;AAC/F,OAAO,EAAkB,KAAK,EAAoB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAG/C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEnG,oEAAoE;AACpE,MAAM,UAAU,MAAM,CAAC,IAAY;IACjC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC;AAgBD,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAChD,CAAC"}
|
package/dist/font.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { WasmImage } from "@laminapdf/wasm/base";
|
|
2
|
+
import { type BaseGlue, type TextGlue } from "./init.js";
|
|
3
|
+
/** The standard 14 fonts, by PostScript name: no bytes needed, not embedded, Latin only, unshaped. */
|
|
4
|
+
export type Standard14 = "Times-Roman" | "Times-Bold" | "Times-Italic" | "Times-BoldItalic" | "Helvetica" | "Helvetica-Bold" | "Helvetica-Oblique" | "Helvetica-BoldOblique" | "Courier" | "Courier-Bold" | "Courier-Oblique" | "Courier-BoldOblique" | "Symbol" | "ZapfDingbats";
|
|
5
|
+
/** What a builder knows of a font once registered. */
|
|
6
|
+
export interface FontInfo {
|
|
7
|
+
/** The family name. */
|
|
8
|
+
readonly family: string;
|
|
9
|
+
/** The PostScript name. */
|
|
10
|
+
readonly postscriptName: string;
|
|
11
|
+
/** Whether it is one of the standard 14 (not embedded). */
|
|
12
|
+
readonly isStandard: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A font to draw text with: TrueType or OpenType bytes (subset to the glyphs drawn and embedded)
|
|
16
|
+
* or one of the standard 14. Needs the text module (`init({ text: true })`).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const inter = Font.fromBytes(await (await fetch("/Inter.ttf")).arrayBuffer());
|
|
21
|
+
* surface.text("Hello", { font: inter, size: 12, at: [72, 72] });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class Font {
|
|
25
|
+
/** The font program, for a font loaded from bytes. */
|
|
26
|
+
readonly bytes: Uint8Array | undefined;
|
|
27
|
+
/** The PostScript name, for a standard 14 font. */
|
|
28
|
+
readonly standard: Standard14 | undefined;
|
|
29
|
+
private constructor();
|
|
30
|
+
/**
|
|
31
|
+
* A font from its bytes (TrueType or OpenType/CFF). The bytes are checked when a builder first
|
|
32
|
+
* uses the font (`invalid-font`, `font-not-embeddable`).
|
|
33
|
+
*/
|
|
34
|
+
static fromBytes(bytes: Uint8Array | ArrayBuffer): Font;
|
|
35
|
+
/** One of the standard 14 fonts. */
|
|
36
|
+
static standard(name: Standard14): Font;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* An image to draw: a JPEG (passed through), a PNG (alpha as a soft mask) or raw RGBA pixels.
|
|
40
|
+
* The bytes are copied when the image is created. It is decoded once per WASM module, the first
|
|
41
|
+
* time a builder of that module draws it (or `width`/`height` is read), so problems with the
|
|
42
|
+
* data (`invalid-image`, `unsupported-image`, …) surface there. Written once per document however
|
|
43
|
+
* often it is drawn.
|
|
44
|
+
*/
|
|
45
|
+
export declare class Image {
|
|
46
|
+
#private;
|
|
47
|
+
private constructor();
|
|
48
|
+
/** A JPEG. */
|
|
49
|
+
static jpeg(bytes: Uint8Array): Image;
|
|
50
|
+
/** A PNG. */
|
|
51
|
+
static png(bytes: Uint8Array): Image;
|
|
52
|
+
/** 8-bit RGBA pixels, row by row (`image-data-length` at first use for a wrong length). */
|
|
53
|
+
static rgba(width: number, height: number, pixels: Uint8Array): Image;
|
|
54
|
+
/** Width in pixels (decodes the image if no module has yet). @throws {@link LaminaPdfError} as `in`. */
|
|
55
|
+
get width(): number;
|
|
56
|
+
/** Height in pixels (decodes the image if no module has yet). @throws {@link LaminaPdfError} as `in`. */
|
|
57
|
+
get height(): number;
|
|
58
|
+
/** Frees the image's WASM memory now (otherwise when it is garbage-collected). */
|
|
59
|
+
free(): void;
|
|
60
|
+
/**
|
|
61
|
+
* @internal The image in `glue`'s instance, decoded there at first use.
|
|
62
|
+
* @throws {@link LaminaPdfError} `invalid-image`, `unsupported-image`, `image-too-large`, `image-data-length`.
|
|
63
|
+
*/
|
|
64
|
+
in(glue: BaseGlue | TextGlue): WasmImage;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=font.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"font.d.ts","sourceRoot":"","sources":["../src/font.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,KAAK,QAAQ,EAAc,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErE,sGAAsG;AACtG,MAAM,MAAM,UAAU,GAClB,aAAa,GACb,YAAY,GACZ,cAAc,GACd,kBAAkB,GAClB,WAAW,GACX,gBAAgB,GAChB,mBAAmB,GACnB,uBAAuB,GACvB,SAAS,GACT,cAAc,GACd,iBAAiB,GACjB,qBAAqB,GACrB,QAAQ,GACR,cAAc,CAAC;AAEnB,sDAAsD;AACtD,MAAM,WAAW,QAAQ;IACvB,uBAAuB;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,2BAA2B;IAC3B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,2DAA2D;IAC3D,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B;AAED;;;;;;;;;GASG;AACH,qBAAa,IAAI;IACf,sDAAsD;IACtD,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC;IACvC,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,EAAE,UAAU,GAAG,SAAS,CAAC;IAE1C,OAAO,eAGN;IAED;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI,CAEtD;IAED,oCAAoC;IACpC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAEtC;CACF;AAoBD;;;;;;GAMG;AACH,qBAAa,KAAK;;IAIhB,OAAO,eAEN;IAED,cAAc;IACd,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,CAEpC;IAED,aAAa;IACb,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,CAEnC;IAED,2FAA2F;IAC3F,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,KAAK,CAEpE;IAED,wGAAwG;IACxG,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,yGAAyG;IACzG,IAAI,MAAM,IAAI,MAAM,CAEnB;IAOD,kFAAkF;IAClF,IAAI,IAAI,IAAI,CAGX;IAED;;;OAGG;IACH,EAAE,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAOvC;CACF"}
|
package/dist/font.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { guard } from "./errors.js";
|
|
2
|
+
import { baseModule } from "./init.js";
|
|
3
|
+
/**
|
|
4
|
+
* A font to draw text with: TrueType or OpenType bytes (subset to the glyphs drawn and embedded)
|
|
5
|
+
* or one of the standard 14. Needs the text module (`init({ text: true })`).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const inter = Font.fromBytes(await (await fetch("/Inter.ttf")).arrayBuffer());
|
|
10
|
+
* surface.text("Hello", { font: inter, size: 12, at: [72, 72] });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export class Font {
|
|
14
|
+
/** The font program, for a font loaded from bytes. */
|
|
15
|
+
bytes;
|
|
16
|
+
/** The PostScript name, for a standard 14 font. */
|
|
17
|
+
standard;
|
|
18
|
+
constructor(bytes, standard) {
|
|
19
|
+
this.bytes = bytes;
|
|
20
|
+
this.standard = standard;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A font from its bytes (TrueType or OpenType/CFF). The bytes are checked when a builder first
|
|
24
|
+
* uses the font (`invalid-font`, `font-not-embeddable`).
|
|
25
|
+
*/
|
|
26
|
+
static fromBytes(bytes) {
|
|
27
|
+
return new Font(bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes), undefined);
|
|
28
|
+
}
|
|
29
|
+
/** One of the standard 14 fonts. */
|
|
30
|
+
static standard(name) {
|
|
31
|
+
return new Font(undefined, name);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function decode(glue, source) {
|
|
35
|
+
return guard(() => {
|
|
36
|
+
switch (source.kind) {
|
|
37
|
+
case "jpeg":
|
|
38
|
+
return glue.WasmImage.jpeg(source.bytes);
|
|
39
|
+
case "png":
|
|
40
|
+
return glue.WasmImage.png(source.bytes);
|
|
41
|
+
case "rgba":
|
|
42
|
+
return glue.WasmImage.rgba(source.width, source.height, source.bytes);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* An image to draw: a JPEG (passed through), a PNG (alpha as a soft mask) or raw RGBA pixels.
|
|
48
|
+
* The bytes are copied when the image is created. It is decoded once per WASM module, the first
|
|
49
|
+
* time a builder of that module draws it (or `width`/`height` is read), so problems with the
|
|
50
|
+
* data (`invalid-image`, `unsupported-image`, …) surface there. Written once per document however
|
|
51
|
+
* often it is drawn.
|
|
52
|
+
*/
|
|
53
|
+
export class Image {
|
|
54
|
+
#source;
|
|
55
|
+
#decoded = new Map();
|
|
56
|
+
constructor(source) {
|
|
57
|
+
this.#source = source;
|
|
58
|
+
}
|
|
59
|
+
/** A JPEG. */
|
|
60
|
+
static jpeg(bytes) {
|
|
61
|
+
return new Image({ kind: "jpeg", bytes: bytes.slice() });
|
|
62
|
+
}
|
|
63
|
+
/** A PNG. */
|
|
64
|
+
static png(bytes) {
|
|
65
|
+
return new Image({ kind: "png", bytes: bytes.slice() });
|
|
66
|
+
}
|
|
67
|
+
/** 8-bit RGBA pixels, row by row (`image-data-length` at first use for a wrong length). */
|
|
68
|
+
static rgba(width, height, pixels) {
|
|
69
|
+
return new Image({ kind: "rgba", width, height, bytes: pixels.slice() });
|
|
70
|
+
}
|
|
71
|
+
/** Width in pixels (decodes the image if no module has yet). @throws {@link LaminaPdfError} as `in`. */
|
|
72
|
+
get width() {
|
|
73
|
+
return this.#any().width;
|
|
74
|
+
}
|
|
75
|
+
/** Height in pixels (decodes the image if no module has yet). @throws {@link LaminaPdfError} as `in`. */
|
|
76
|
+
get height() {
|
|
77
|
+
return this.#any().height;
|
|
78
|
+
}
|
|
79
|
+
#any() {
|
|
80
|
+
for (const image of this.#decoded.values())
|
|
81
|
+
return image;
|
|
82
|
+
return this.in(baseModule());
|
|
83
|
+
}
|
|
84
|
+
/** Frees the image's WASM memory now (otherwise when it is garbage-collected). */
|
|
85
|
+
free() {
|
|
86
|
+
for (const image of this.#decoded.values())
|
|
87
|
+
image.free();
|
|
88
|
+
this.#decoded.clear();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @internal The image in `glue`'s instance, decoded there at first use.
|
|
92
|
+
* @throws {@link LaminaPdfError} `invalid-image`, `unsupported-image`, `image-too-large`, `image-data-length`.
|
|
93
|
+
*/
|
|
94
|
+
in(glue) {
|
|
95
|
+
let image = this.#decoded.get(glue);
|
|
96
|
+
if (image === undefined) {
|
|
97
|
+
image = decode(glue, this.#source);
|
|
98
|
+
this.#decoded.set(glue, image);
|
|
99
|
+
}
|
|
100
|
+
return image;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=font.js.map
|