@build-qube/papyra 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/encoded.d.ts CHANGED
@@ -6,8 +6,9 @@
6
6
  * imports `encodeBitmap` as a value. See CLAUDE.md.
7
7
  */
8
8
  /**
9
- * Containers papyra can write. All three encoders are pure Rust — that is what keeps
10
- * the browser build free of a C toolchain — so there is no lossy WebP and no AVIF.
9
+ * Containers papyra can rasterise a page into. All three encoders are pure Rust — that
10
+ * is what keeps the browser build free of a C toolchain — so there is no lossy WebP and
11
+ * no AVIF.
11
12
  *
12
13
  * - `webp` is lossless VP8L, and the default: on page content (line art, text, flat
13
14
  * fills) it is ~3x smaller than PNG for roughly the same encode time.
@@ -16,13 +17,24 @@
16
17
  * alpha channel; transparent pixels are composited onto white, matching how pages
17
18
  * are rendered.
18
19
  */
19
- export type EncodedFormat = 'webp' | 'png' | 'jpeg';
20
+ export type RasterFormat = 'webp' | 'png' | 'jpeg';
21
+ /**
22
+ * Every container papyra can write, {@link RasterFormat} plus `svg`.
23
+ *
24
+ * `svg` is separate from the others everywhere it matters: it comes off
25
+ * `Document.renderSvg`, not off pixels, so it takes no DPI and no quality — which is
26
+ * why {@link EncodeOptions.format} accepts only a {@link RasterFormat}.
27
+ */
28
+ export type EncodedFormat = RasterFormat | 'svg';
20
29
  /** MIME type for an encoded format, e.g. `'webp'` -> `'image/webp'`. */
21
30
  export declare function mimeType(format: EncodedFormat): string;
22
31
  /** Which container to write, and how hard to squeeze. */
23
32
  export interface EncodeOptions {
24
- /** Defaults to `'webp'`. */
25
- format?: EncodedFormat;
33
+ /**
34
+ * Defaults to `'webp'`. Rasters only — SVG is not an encoding of a bitmap, so it
35
+ * comes from `Document.renderSvg` instead.
36
+ */
37
+ format?: RasterFormat;
26
38
  /** JPEG only, 1-100. Defaults to 80. Ignored by the lossless formats. */
27
39
  quality?: number;
28
40
  /** Abort a request that has not started yet. */
@@ -52,6 +64,23 @@ export interface EncodedImage {
52
64
  */
53
65
  toDataUrl(): string;
54
66
  }
67
+ /**
68
+ * One page as SVG. An {@link EncodedImage} whose markup is also readable as a string,
69
+ * because the usual thing to do with an SVG is inline it rather than hand a browser
70
+ * a URL.
71
+ */
72
+ export interface SvgPage extends EncodedImage {
73
+ readonly format: 'svg';
74
+ /** The SVG document itself, a single `<svg>` element sized in PDF points. */
75
+ readonly markup: string;
76
+ }
77
+ /**
78
+ * Wrap SVG markup as an {@link SvgPage}.
79
+ *
80
+ * `bytes` is encoded on first access: inlining the markup is the common case, and a
81
+ * page of dense line art is megabytes of text that no one asked to have copied.
82
+ */
83
+ export declare function svgPage(markup: string): SvgPage;
55
84
  /**
56
85
  * Wrap already-encoded bytes as an {@link EncodedImage}.
57
86
  *
@@ -1 +1 @@
1
- {"version":3,"file":"encoded.d.ts","sourceRoot":"","sources":["../src/encoded.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH;;;;;;;;;;GAUG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;AAQpD,wEAAwE;AACxE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAEtD;AAED,yDAAyD;AACzD,MAAM,WAAW,aAAa;IAC5B,4BAA4B;IAC5B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,2FAA2F;AAC3F,MAAM,WAAW,YAAY;IAC3B,0DAA0D;IAC1D,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,iDAAiD;IACjD,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,MAAM,IAAI,IAAI,CAAC;IACf;;;;;;O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;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAqB/C;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,aAAa,GACpB,YAAY,CAYd"}
package/dist/encoded.js CHANGED
@@ -2,11 +2,39 @@ const MIME = {
2
2
  webp: 'image/webp',
3
3
  png: 'image/png',
4
4
  jpeg: 'image/jpeg',
5
+ svg: 'image/svg+xml',
5
6
  };
6
7
  /** MIME type for an encoded format, e.g. `'webp'` -> `'image/webp'`. */
7
8
  export function mimeType(format) {
8
9
  return MIME[format];
9
10
  }
11
+ /**
12
+ * Wrap SVG markup as an {@link SvgPage}.
13
+ *
14
+ * `bytes` is encoded on first access: inlining the markup is the common case, and a
15
+ * page of dense line art is megabytes of text that no one asked to have copied.
16
+ */
17
+ export function svgPage(markup) {
18
+ const mime = MIME.svg;
19
+ let encoded;
20
+ const bytes = () => {
21
+ encoded ??= new TextEncoder().encode(markup);
22
+ return encoded;
23
+ };
24
+ return {
25
+ markup,
26
+ format: 'svg',
27
+ mime,
28
+ get bytes() {
29
+ return bytes();
30
+ },
31
+ toBlob: () => new Blob([markup], { type: mime }),
32
+ toBlobUrl() {
33
+ return URL.createObjectURL(this.toBlob());
34
+ },
35
+ toDataUrl: () => `data:${mime};base64,${base64(bytes())}`,
36
+ };
37
+ }
10
38
  /**
11
39
  * Wrap already-encoded bytes as an {@link EncodedImage}.
12
40
  *
@@ -1 +1 @@
1
- {"version":3,"file":"encoded.js","sourceRoot":"","sources":["../src/encoded.ts"],"names":[],"mappings":"AAoBA,MAAM,IAAI,GAAkC;IAC1C,IAAI,EAAE,YAAY;IAClB,GAAG,EAAE,WAAW;IAChB,IAAI,EAAE,YAAY;CACnB,CAAC;AAEF,wEAAwE;AACxE,MAAM,UAAU,QAAQ,CAAC,MAAqB;IAC5C,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC;AAqCD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
4
+ * The base of both password failures, because a viewer handles them in one place: a
5
+ * dialog that either asks for the first time or says the last answer was wrong.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * try {
10
+ * doc = await open(file, { password });
11
+ * } catch (e) {
12
+ * if (e instanceof PasswordError) showPasswordDialog({ retry: e.retry });
13
+ * else throw e;
14
+ * }
15
+ * ```
16
+ */
17
+ export declare class PasswordError extends Error {
18
+ /**
19
+ * A password was already tried and rejected.
20
+ *
21
+ * `false` the first time, so a dialog can open without an error on it.
22
+ */
23
+ readonly retry: boolean;
24
+ }
25
+ /** The document is encrypted and {@link OpenOptions.password} was not supplied. */
26
+ export declare class PasswordRequiredError extends PasswordError {
27
+ /** Always `'PasswordRequiredError'`. */
28
+ readonly name = "PasswordRequiredError";
29
+ readonly retry = false;
30
+ constructor(message?: string);
31
+ }
32
+ /** A password was supplied and it did not open the document. */
33
+ export declare class IncorrectPasswordError extends PasswordError {
34
+ /** Always `'IncorrectPasswordError'`. */
35
+ readonly name = "IncorrectPasswordError";
36
+ readonly retry = true;
37
+ constructor(message?: string);
38
+ }
39
+ /**
40
+ * Rethrow a load failure as itself, or as the typed error it was tagged as.
41
+ *
42
+ * @internal
43
+ */
44
+ export declare function rethrowLoadError(error: unknown): never;
45
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAS;CACjC;AAED,mFAAmF;AACnF,qBAAa,qBAAsB,SAAQ,aAAa;IACtD,wCAAwC;IACxC,SAAkB,IAAI,2BAA2B;IACjD,SAAkB,KAAK,SAAS;IAChC,YAAY,OAAO,SAAmC,EAErD;CACF;AAED,gEAAgE;AAChE,qBAAa,sBAAuB,SAAQ,aAAa;IACvD,yCAAyC;IACzC,SAAkB,IAAI,4BAA4B;IAClD,SAAkB,KAAK,QAAQ;IAC/B,YAAY,OAAO,SAAuC,EAEzD;CACF;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAQtD"}
package/dist/errors.js ADDED
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Tags the bindings put in front of a load failure's message.
3
+ *
4
+ * napi-rs gives every error it throws the same `code`, so the message is the only
5
+ * channel a typed failure can travel through. These are stripped before the error
6
+ * reaches a caller — keep them in step with `TAG_PASSWORD_REQUIRED` and
7
+ * `TAG_INCORRECT_PASSWORD` in `packages/bindings/src/lib.rs`.
8
+ */
9
+ const TAGS = {
10
+ 'papyra/password-required': (message) => new PasswordRequiredError(message),
11
+ 'papyra/incorrect-password': (message) => new IncorrectPasswordError(message),
12
+ };
13
+ /**
14
+ * A document that could not be opened because of its password.
15
+ *
16
+ * The base of both password failures, because a viewer handles them in one place: a
17
+ * dialog that either asks for the first time or says the last answer was wrong.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * try {
22
+ * doc = await open(file, { password });
23
+ * } catch (e) {
24
+ * if (e instanceof PasswordError) showPasswordDialog({ retry: e.retry });
25
+ * else throw e;
26
+ * }
27
+ * ```
28
+ */
29
+ export class PasswordError extends Error {
30
+ /**
31
+ * A password was already tried and rejected.
32
+ *
33
+ * `false` the first time, so a dialog can open without an error on it.
34
+ */
35
+ retry = false;
36
+ }
37
+ /** The document is encrypted and {@link OpenOptions.password} was not supplied. */
38
+ export class PasswordRequiredError extends PasswordError {
39
+ /** Always `'PasswordRequiredError'`. */
40
+ name = 'PasswordRequiredError';
41
+ retry = false;
42
+ constructor(message = 'this PDF is password-protected') {
43
+ super(message);
44
+ }
45
+ }
46
+ /** A password was supplied and it did not open the document. */
47
+ export class IncorrectPasswordError extends PasswordError {
48
+ /** Always `'IncorrectPasswordError'`. */
49
+ name = 'IncorrectPasswordError';
50
+ retry = true;
51
+ constructor(message = 'the supplied password is incorrect') {
52
+ super(message);
53
+ }
54
+ }
55
+ /**
56
+ * Rethrow a load failure as itself, or as the typed error it was tagged as.
57
+ *
58
+ * @internal
59
+ */
60
+ export function rethrowLoadError(error) {
61
+ const message = error instanceof Error ? error.message : String(error);
62
+ for (const [tag, build] of Object.entries(TAGS)) {
63
+ if (message.startsWith(tag)) {
64
+ throw build(message.slice(tag.length).trim());
65
+ }
66
+ }
67
+ throw error;
68
+ }
69
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,IAAI,GAAG;IACX,0BAA0B,EAAE,CAAC,OAAe,EAAE,EAAE,CAC9C,IAAI,qBAAqB,CAAC,OAAO,CAAC;IACpC,2BAA2B,EAAE,CAAC,OAAe,EAAE,EAAE,CAC/C,IAAI,sBAAsB,CAAC,OAAO,CAAC;CAC7B,CAAC;AAEX;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC;;;;OAIG;IACM,KAAK,GAAY,KAAK,CAAC;CACjC;AAED,mFAAmF;AACnF,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACtD,wCAAwC;IACtB,IAAI,GAAG,uBAAuB,CAAC;IAC/B,KAAK,GAAG,KAAK,CAAC;IAChC,YAAY,OAAO,GAAG,gCAAgC;QACpD,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED,gEAAgE;AAChE,MAAM,OAAO,sBAAuB,SAAQ,aAAa;IACvD,yCAAyC;IACvB,IAAI,GAAG,wBAAwB,CAAC;IAChC,KAAK,GAAG,IAAI,CAAC;IAC/B,YAAY,OAAO,GAAG,oCAAoC;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5B,MAAM,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IACD,MAAM,KAAK,CAAC;AACd,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A stable identifier for a document's bytes.
3
+ *
4
+ * Sixteen hex characters, derived from the head, the tail and the length of the file.
5
+ * Meant as a key for whatever a viewer remembers per document — the page it was left
6
+ * on, the zoom, a set of highlights.
7
+ *
8
+ * **This is a content hash, not the PDF's `/ID`.** hayro exposes no trailer accessor,
9
+ * so the identifier the spec defines is out of reach; the practical difference is
10
+ * that a document saved with an incremental update keeps its `/ID` and gets a new
11
+ * fingerprint here. For "is this the same file I had open", which is what the value
12
+ * is for, hashing the bytes is the stronger answer anyway — it also distinguishes two
13
+ * documents that were copied from one another and kept the same `/ID`.
14
+ *
15
+ * @internal
16
+ */
17
+ export declare function fingerprint(bytes: Uint8Array): string;
18
+ //# sourceMappingURL=fingerprint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../src/fingerprint.ts"],"names":[],"mappings":"AAqBA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAarD"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * How many bytes to read from each end of the file.
3
+ *
4
+ * The tail is the load-bearing half: it holds the cross-reference table and the
5
+ * trailer, and the trailer is where `/ID` lives. So although this never parses the
6
+ * document, a file that carries an `/ID` still contributes it to the hash.
7
+ */
8
+ const SAMPLE = 4096;
9
+ /** FNV-1a, 32-bit. Two runs at different offsets give the 64 bits below. */
10
+ function fnv1a(bytes, seed) {
11
+ let hash = seed;
12
+ for (const byte of bytes) {
13
+ hash ^= byte;
14
+ // The FNV prime, 16777619, as shifts — `Math.imul` keeps this in 32 bits where
15
+ // `*` would silently go through a double and lose the low bits.
16
+ hash = Math.imul(hash, 0x01000193);
17
+ }
18
+ return hash >>> 0;
19
+ }
20
+ /**
21
+ * A stable identifier for a document's bytes.
22
+ *
23
+ * Sixteen hex characters, derived from the head, the tail and the length of the file.
24
+ * Meant as a key for whatever a viewer remembers per document — the page it was left
25
+ * on, the zoom, a set of highlights.
26
+ *
27
+ * **This is a content hash, not the PDF's `/ID`.** hayro exposes no trailer accessor,
28
+ * so the identifier the spec defines is out of reach; the practical difference is
29
+ * that a document saved with an incremental update keeps its `/ID` and gets a new
30
+ * fingerprint here. For "is this the same file I had open", which is what the value
31
+ * is for, hashing the bytes is the stronger answer anyway — it also distinguishes two
32
+ * documents that were copied from one another and kept the same `/ID`.
33
+ *
34
+ * @internal
35
+ */
36
+ export function fingerprint(bytes) {
37
+ const head = bytes.subarray(0, SAMPLE);
38
+ // `subarray` clamps, so a file shorter than one sample simply hashes twice rather
39
+ // than needing a branch.
40
+ const tail = bytes.subarray(Math.max(0, bytes.length - SAMPLE));
41
+ const low = fnv1a(tail, fnv1a(head, 0x811c9dc5));
42
+ // A second pass from a different seed, so the two halves of the output are not the
43
+ // same 32 bits twice. Length goes in as well: it separates a file from its own
44
+ // prefix, which the samples alone would not.
45
+ const high = fnv1a(tail, fnv1a(head, bytes.length >>> 0));
46
+ return high.toString(16).padStart(8, '0') + low.toString(16).padStart(8, '0');
47
+ }
48
+ //# sourceMappingURL=fingerprint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fingerprint.js","sourceRoot":"","sources":["../src/fingerprint.ts"],"names":[],"mappings":"AAAA;;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  export { paintToCanvas, toImageData } from './canvas.js';
18
- export type { ImageHandle, RenderHandle } from './document.js';
18
+ export type { ImageHandle, RenderHandle, SvgHandle } from './document.js';
19
19
  export { Document, open } from './document.js';
20
- export type { EncodedFormat, EncodedImage, EncodeOptions, } from './encode.js';
21
- export { encode, encodedImage, mimeType, PageImage } from './encode.js';
20
+ export type { EncodedFormat, EncodedImage, EncodeOptions, RasterFormat, SvgPage, } from './encode.js';
21
+ export { encode, encodedImage, mimeType, PageImage, svgPage, } from './encode.js';
22
+ export { IncorrectPasswordError, PasswordError, PasswordRequiredError, } from './errors.js';
23
+ export type { LinkTarget, PageLink } from './links.js';
22
24
  export type { DestinationKind, OutlineDestination, OutlineNode, } from './outline.js';
23
25
  export { buildOutlineTree, walkOutline } from './outline.js';
24
26
  export type { Runtime } from './runtime.js';
@@ -28,6 +30,6 @@ export { AbortError, DEFAULT_PRIORITY } from './scheduler.js';
28
30
  export type { MatchOptions, SearchMatch } from './search.js';
29
31
  export { findRanges, searchPageText } from './search.js';
30
32
  export type { PageText, Quad, Rect, TextLine } from './text.js';
31
- export { lineQuad, pageString, quadBounds, scaleQuad, } from './text.js';
32
- export type { OpenOptions, PageSize, PdfSource, RenderedPage, RenderOptions, SearchOptions, StreamedPage, StreamOptions, } from './types.js';
33
+ export { lineQuad, pageString, quadBounds, scaleQuad, scaleRect, } from './text.js';
34
+ export type { DocumentMetadata, OpenOptions, PageSize, PdfSource, RenderedPage, RenderOptions, SearchOptions, StreamedPage, StreamOptions, SvgOptions, } from './types.js';
33
35
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,YAAY,EAAE,WAAW,EAAE,YAAY,E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,EACT,YAAY,EACZ,aAAa,EACb,aAAa,EACb,YAAY,EACZ,aAAa,EACb,UAAU,GACX,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -15,10 +15,11 @@
15
15
  */
16
16
  export { paintToCanvas, toImageData } from './canvas.js';
17
17
  export { Document, open } from './document.js';
18
- export { encode, encodedImage, mimeType, PageImage } from './encode.js';
18
+ export { encode, encodedImage, mimeType, PageImage, svgPage, } from './encode.js';
19
+ export { IncorrectPasswordError, PasswordError, PasswordRequiredError, } from './errors.js';
19
20
  export { buildOutlineTree, walkOutline } from './outline.js';
20
21
  export { backend, currentRuntime, hardwareConcurrency, init, } from './runtime.js';
21
22
  export { AbortError, DEFAULT_PRIORITY } from './scheduler.js';
22
23
  export { findRanges, searchPageText } from './search.js';
23
- export { lineQuad, pageString, quadBounds, scaleQuad, } from './text.js';
24
+ export { lineQuad, pageString, quadBounds, scaleQuad, scaleRect, } from './text.js';
24
25
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAM/C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMxE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,EACL,OAAO,EACP,cAAc,EACd,mBAAmB,EACnB,IAAI,GACL,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EACL,QAAQ,EACR,UAAU,EACV,UAAU,EACV,SAAS,GACV,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAQ/C,OAAO,EACL,MAAM,EACN,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,OAAO,GACR,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAOrB,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,EACL,OAAO,EACP,cAAc,EACd,mBAAmB,EACnB,IAAI,GACL,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EACL,QAAQ,EACR,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,GACV,MAAM,WAAW,CAAC"}
@@ -0,0 +1,53 @@
1
+ import type { PageLink as NativePageLink } from '@build-qube/papyra-native';
2
+ import { type OutlineDestination } from './outline.js';
3
+ import type { Rect } from './text.js';
4
+ /**
5
+ * Where a link goes.
6
+ *
7
+ * A discriminated union rather than two nullable fields, so narrowing on `kind` gives
8
+ * you the payload without a non-null assertion:
9
+ *
10
+ * ```ts
11
+ * if (link.target.kind === 'uri') window.open(link.target.uri);
12
+ * else void doc.render(link.target.dest.page, { fitWidth: 1600 });
13
+ * ```
14
+ */
15
+ export type LinkTarget = {
16
+ /** The link points somewhere in this document. */
17
+ readonly kind: 'internal';
18
+ /** The page and the view, in the same shape an outline entry uses. */
19
+ readonly dest: OutlineDestination;
20
+ } | {
21
+ /**
22
+ * The link points out of this document.
23
+ *
24
+ * Not necessarily `http`: `mailto:` and `file:` are both common, and papyra
25
+ * does not validate the string. Decide for yourself what you are willing to
26
+ * follow before handing it to a browser.
27
+ */
28
+ readonly kind: 'uri';
29
+ /** The URI, exactly as the document wrote it. */
30
+ readonly uri: string;
31
+ };
32
+ /**
33
+ * One link on a page: a clickable region, and what it does.
34
+ *
35
+ * Only links that resolve to something actionable are reported — a `/Link` pointing
36
+ * at a page the document does not contain, or carrying an action papyra does not act
37
+ * on, is dropped rather than handed over as a region that would swallow clicks.
38
+ */
39
+ export interface PageLink {
40
+ /**
41
+ * The clickable region, in the same 72-DPI top-left space as {@link PageText} and
42
+ * {@link PageSize}. Multiply by `rendered.width / pageSize.width` to place it over
43
+ * a render — {@link scaleRect} does exactly that.
44
+ */
45
+ readonly rect: Rect;
46
+ /** Where activating the link goes. Narrow on `target.kind`. */
47
+ readonly target: LinkTarget;
48
+ /** The annotation's tooltip, when it has one. */
49
+ readonly alt: string | null;
50
+ }
51
+ /** @internal */
52
+ export declare function toPageLink(native: NativePageLink): PageLink | null;
53
+ //# sourceMappingURL=links.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,KAAK,kBAAkB,EAAiB,MAAM,cAAc,CAAC;AACtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,UAAU,GAClB;IACE,kDAAkD;IAClD,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;CACnC,GACD;IACE;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,iDAAiD;IACjD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,iDAAiD;IACjD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,gBAAgB;AAChB,wBAAgB,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,GAAG,IAAI,CAelE"}
package/dist/links.js ADDED
@@ -0,0 +1,26 @@
1
+ import { toDestination } from './outline.js';
2
+ /** @internal */
3
+ export function toPageLink(native) {
4
+ const target = linkTarget(native);
5
+ // The bindings only emit a link with one target or the other, so this is
6
+ // unreachable in practice; dropping it beats widening the type with a null target.
7
+ if (!target)
8
+ return null;
9
+ return {
10
+ rect: {
11
+ x: native.x0,
12
+ y: native.y0,
13
+ width: native.x1 - native.x0,
14
+ height: native.y1 - native.y0,
15
+ },
16
+ target,
17
+ alt: native.alt ?? null,
18
+ };
19
+ }
20
+ function linkTarget(native) {
21
+ if (native.uri !== undefined)
22
+ return { kind: 'uri', uri: native.uri };
23
+ const dest = toDestination(native.dest);
24
+ return dest ? { kind: 'internal', dest } : null;
25
+ }
26
+ //# sourceMappingURL=links.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"links.js","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,aAAa,EAAE,MAAM,cAAc,CAAC;AAsDtE,gBAAgB;AAChB,MAAM,UAAU,UAAU,CAAC,MAAsB;IAC/C,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IAClC,yEAAyE;IACzE,mFAAmF;IACnF,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,OAAO;QACL,IAAI,EAAE;YACJ,CAAC,EAAE,MAAM,CAAC,EAAE;YACZ,CAAC,EAAE,MAAM,CAAC,EAAE;YACZ,KAAK,EAAE,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE;YAC5B,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE;SAC9B;QACD,MAAM;QACN,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,IAAI;KACxB,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,MAAsB;IACxC,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;IACtE,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC"}
package/dist/outline.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { OutlineEntry as NativeEntry } from '@build-qube/papyra-native';
1
+ import type { OutlineDestination as NativeDestination, OutlineEntry as NativeEntry } from '@build-qube/papyra-native';
2
2
  /** How a destination positions the page in the window (PDF 32000-1, 12.3.2.2). */
3
3
  export type DestinationKind = 'XYZ' | 'Fit' | 'FitH' | 'FitV' | 'FitR' | 'FitB' | 'FitBH' | 'FitBV';
4
4
  /**
@@ -45,6 +45,14 @@ export interface OutlineNode {
45
45
  /** Nested entries, empty for a leaf. */
46
46
  readonly children: OutlineNode[];
47
47
  }
48
+ /**
49
+ * napi omits absent numbers rather than nulling them; normalise to one shape.
50
+ *
51
+ * Shared with the link reader, whose targets resolve to the same destinations.
52
+ *
53
+ * @internal
54
+ */
55
+ export declare function toDestination(dest: NativeDestination | undefined): OutlineDestination | null;
48
56
  /**
49
57
  * Rebuild the tree from the flat pre-order list the bindings return.
50
58
  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tC,MAAM,WAAW,WAAW;IAC1B,+EAA+E;IAC/E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACzC,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,yDAAyD;IACzD,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,2DAA2D;IAC3D,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,yDAAyD;IACzD,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,wCAAwC;IACxC,QAAQ,CAAC,QAAQ,EAAE,WAAW,EAAE,CAAC;CAClC;AAaD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,iBAAiB,GAAG,SAAS,GAClC,kBAAkB,GAAG,IAAI,CAa3B;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,WAAW,EAAE,GAC9B,WAAW,EAAE,CAyBf;AAED,sEAAsE;AACtE,wBAAiB,WAAW,CAC1B,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,KAAK,SAAI,GACR,SAAS,CAAC;IACX,iBAAiB;IACjB,IAAI,EAAE,WAAW,CAAC;IAClB,2DAA2D;IAC3D,KAAK,EAAE,MAAM,CAAC;CACf,CAAC,CAKD"}
package/dist/outline.js CHANGED
@@ -8,8 +8,14 @@ const KINDS = new Set([
8
8
  'FitBH',
9
9
  'FitBV',
10
10
  ]);
11
- /** napi omits absent numbers rather than nulling them; normalise to one shape. */
12
- function destination(dest) {
11
+ /**
12
+ * napi omits absent numbers rather than nulling them; normalise to one shape.
13
+ *
14
+ * Shared with the link reader, whose targets resolve to the same destinations.
15
+ *
16
+ * @internal
17
+ */
18
+ export function toDestination(dest) {
13
19
  if (!dest)
14
20
  return null;
15
21
  return {
@@ -36,7 +42,7 @@ export function buildOutlineTree(entries) {
36
42
  const roots = [];
37
43
  const stack = [];
38
44
  for (const entry of entries) {
39
- const dest = destination(entry.dest);
45
+ const dest = toDestination(entry.dest);
40
46
  const node = {
41
47
  title: entry.title,
42
48
  dest,
@@ -1 +1 @@
1
- {"version":3,"file":"outline.js","sourceRoot":"","sources":["../src/outline.ts"],"names":[],"mappings":"AA8DA,MAAM,KAAK,GAAG,IAAI,GAAG,CAAS;IAC5B,KAAK;IACL,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;CACR,CAAC,CAAC;AAEH,kFAAkF;AAClF,SAAS,WAAW,CAClB,IAAmC;IAEnC,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,8EAA8E;QAC9E,iDAAiD;QACjD,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAoB;QACnE,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI;QACvB,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,IAAI;QACrB,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI;QACzB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,IAAI;QAC3B,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI;KACxB,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAA+B;IAE/B,MAAM,KAAK,GAAkB,EAAE,CAAC;IAChC,MAAM,KAAK,GAAkB,EAAE,CAAC;IAEhC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrC,MAAM,IAAI,GAAgB;YACxB,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C,KAAK,GAAG,CAAC,CAAC,CAAC;QAChC,IAAI,MAAM;YAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;YAClC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,sEAAsE;AACtE,MAAM,SAAS,CAAC,CAAC,WAAW,CAC1B,KAA6B,EAC7B,KAAK,GAAG,CAAC;IAOT,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QACtB,KAAK,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC"}
package/dist/text.d.ts CHANGED
@@ -106,6 +106,8 @@ export declare function pageTextBytes(text: PageText): number;
106
106
  export declare function lineQuad(line: TextLine, start: number, end: number): Quad;
107
107
  /** The smallest upright rectangle containing `quad`. */
108
108
  export declare function quadBounds(quad: Quad): Rect;
109
+ /** Scale a rect from 72-DPI page space into a render's pixels. */
110
+ export declare function scaleRect(rect: Rect, scale: number): Rect;
109
111
  /** Scale a quad from 72-DPI page space into a render's pixels. */
110
112
  export declare function scaleQuad(quad: Quad, scale: number): Quad;
111
113
  //# sourceMappingURL=text.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,IAAI,cAAc,EAE3B,MAAM,2BAA2B,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,WAAW,QAAQ;IACvB,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,gCAAg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MzE;AAED,oDAAoD;AACpD,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAEjD;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAMpD;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAyBzE;AAED,wDAAwD;AACxD,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAM3C;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAOzD;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAWzD"}
package/dist/text.js CHANGED
@@ -56,6 +56,15 @@ export function quadBounds(quad) {
56
56
  const y = Math.min(...ys);
57
57
  return { x, y, width: Math.max(...xs) - x, height: Math.max(...ys) - y };
58
58
  }
59
+ /** Scale a rect from 72-DPI page space into a render's pixels. */
60
+ export function scaleRect(rect, scale) {
61
+ return {
62
+ x: rect.x * scale,
63
+ y: rect.y * scale,
64
+ width: rect.width * scale,
65
+ height: rect.height * scale,
66
+ };
67
+ }
59
68
  /** Scale a quad from 72-DPI page space into a render's pixels. */
60
69
  export function scaleQuad(quad, scale) {
61
70
  return {
package/dist/text.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAoGA,gBAAgB;AAChB,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,MAAsB;IAC7D,OAAO;QACL,IAAI;QACJ,KAAK,EAAE,MAAM,CAAC,KAAyD;QACvE,eAAe,EAAE,MAAM,CAAC,eAAe;KACxC,CAAC;AACJ,CAAC;AAED,oDAAoD;AACp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