@qrcommunication/gigapdf-lib 0.25.0 → 0.26.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/index.d.cts CHANGED
@@ -20,6 +20,8 @@ type Exports = {
20
20
  declare class GigaPdfEngine {
21
21
  private readonly ex;
22
22
  private constructor();
23
+ /** Lazily-built Base64 reverse-lookup table (see {@link _fromBase64}). */
24
+ private static _b64rev?;
23
25
  /** Instantiate from raw wasm bytes, a URL/path, or a Response. */
24
26
  static load(source: ArrayBuffer | Uint8Array | string | Response): Promise<GigaPdfEngine>;
25
27
  /**
@@ -40,6 +42,12 @@ declare class GigaPdfEngine {
40
42
  _buffer(call: (outLenPtr: number) => number): Uint8Array;
41
43
  _str(call: (outLenPtr: number) => number): string;
42
44
  _json<T = unknown>(call: (outLenPtr: number) => number): T;
45
+ /**
46
+ * Decode standard Base64 (RFC 4648) to bytes. Pure-JS table decode, so it
47
+ * works identically in Node and the browser with no dependency (used to turn
48
+ * the JSON `dataBase64` of {@link GigaPdfDoc.attachments} back into bytes).
49
+ */
50
+ _fromBase64(s: string): Uint8Array;
43
51
  /** Pass a string argument; runs `fn(ptr, len)` then frees. */
44
52
  _withStr<T>(s: string, fn: (ptr: number, len: number) => T): T;
45
53
  /** Pass an optional string; an absent/empty value runs `fn(0, 0)` (no alloc). */
@@ -346,6 +354,27 @@ interface NamedDest {
346
354
  name: string;
347
355
  page: number;
348
356
  }
357
+ /**
358
+ * One embedded file attachment read back by {@link GigaPdfDoc.attachments}.
359
+ * `data` is the decoded file bytes; `mime`/`description`/dates are `null` when
360
+ * the PDF didn't record them.
361
+ */
362
+ interface Attachment {
363
+ /** The `/EmbeddedFiles` name-tree key the file was registered under. */
364
+ name: string;
365
+ /** The filespec display filename (`/UF` preferred, else `/F`). */
366
+ filename: string;
367
+ /** The embedded stream's `/Subtype` MIME (e.g. `application/pdf`), or null. */
368
+ mime: string | null;
369
+ /** The filespec `/Desc` human description, or null. */
370
+ description: string | null;
371
+ /** The `/Params /CreationDate` PDF date string, or null. */
372
+ creationDate: string | null;
373
+ /** The `/Params /ModDate` PDF date string, or null. */
374
+ modDate: string | null;
375
+ /** The decoded (filters applied) file bytes. */
376
+ data: Uint8Array;
377
+ }
349
378
  /** One sheet read back from an `.xlsx` by {@link GigaPdfEngine.xlsxToGrids}. */
350
379
  interface XlsxSheet {
351
380
  name: string;
@@ -633,6 +662,15 @@ declare class GigaPdfDoc {
633
662
  addNamedDest(name: string, targetPage: number): boolean;
634
663
  /** The catalog's named destinations as `{name, page}` pairs. */
635
664
  namedDests(): NamedDest[];
665
+ /**
666
+ * Every embedded file attachment in the document's `/Names /EmbeddedFiles`
667
+ * name tree, decoded. Each {@link Attachment} carries the name-tree key, the
668
+ * filespec display name (`/UF`/`/F`), the embedded stream's MIME (`/Subtype`)
669
+ * and `/Params` dates, and the decoded bytes. Entries that don't resolve to a
670
+ * readable embedded stream are skipped, so the result is only extractable
671
+ * files (the native replacement for a reader's `getAttachments()`).
672
+ */
673
+ attachments(): Attachment[];
636
674
  /**
637
675
  * Add an internal hyperlink over a rectangle that jumps to the named
638
676
  * destination `name` (define it with {@link addNamedDest}). Unlike
@@ -693,4 +731,4 @@ declare class GigaPdfDoc {
693
731
  }): boolean;
694
732
  }
695
733
 
696
- export { type AnnotationInfo, type Box, type DecodedImage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, GigaPdfDoc, GigaPdfEngine, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type LayerInfo, type LinkInfo, type NamedDest, type OcrWord, type OutlineEntry, type PageInfo, type RadioOption, type SearchHit, type SignP12Options, type TextLine, type TextRunInfo, type XlsxSheet };
734
+ export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, GigaPdfDoc, GigaPdfEngine, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type LayerInfo, type LinkInfo, type NamedDest, type OcrWord, type OutlineEntry, type PageInfo, type RadioOption, type SearchHit, type SignP12Options, type TextLine, type TextRunInfo, type XlsxSheet };
package/dist/index.d.ts CHANGED
@@ -20,6 +20,8 @@ type Exports = {
20
20
  declare class GigaPdfEngine {
21
21
  private readonly ex;
22
22
  private constructor();
23
+ /** Lazily-built Base64 reverse-lookup table (see {@link _fromBase64}). */
24
+ private static _b64rev?;
23
25
  /** Instantiate from raw wasm bytes, a URL/path, or a Response. */
24
26
  static load(source: ArrayBuffer | Uint8Array | string | Response): Promise<GigaPdfEngine>;
25
27
  /**
@@ -40,6 +42,12 @@ declare class GigaPdfEngine {
40
42
  _buffer(call: (outLenPtr: number) => number): Uint8Array;
41
43
  _str(call: (outLenPtr: number) => number): string;
42
44
  _json<T = unknown>(call: (outLenPtr: number) => number): T;
45
+ /**
46
+ * Decode standard Base64 (RFC 4648) to bytes. Pure-JS table decode, so it
47
+ * works identically in Node and the browser with no dependency (used to turn
48
+ * the JSON `dataBase64` of {@link GigaPdfDoc.attachments} back into bytes).
49
+ */
50
+ _fromBase64(s: string): Uint8Array;
43
51
  /** Pass a string argument; runs `fn(ptr, len)` then frees. */
44
52
  _withStr<T>(s: string, fn: (ptr: number, len: number) => T): T;
45
53
  /** Pass an optional string; an absent/empty value runs `fn(0, 0)` (no alloc). */
@@ -346,6 +354,27 @@ interface NamedDest {
346
354
  name: string;
347
355
  page: number;
348
356
  }
357
+ /**
358
+ * One embedded file attachment read back by {@link GigaPdfDoc.attachments}.
359
+ * `data` is the decoded file bytes; `mime`/`description`/dates are `null` when
360
+ * the PDF didn't record them.
361
+ */
362
+ interface Attachment {
363
+ /** The `/EmbeddedFiles` name-tree key the file was registered under. */
364
+ name: string;
365
+ /** The filespec display filename (`/UF` preferred, else `/F`). */
366
+ filename: string;
367
+ /** The embedded stream's `/Subtype` MIME (e.g. `application/pdf`), or null. */
368
+ mime: string | null;
369
+ /** The filespec `/Desc` human description, or null. */
370
+ description: string | null;
371
+ /** The `/Params /CreationDate` PDF date string, or null. */
372
+ creationDate: string | null;
373
+ /** The `/Params /ModDate` PDF date string, or null. */
374
+ modDate: string | null;
375
+ /** The decoded (filters applied) file bytes. */
376
+ data: Uint8Array;
377
+ }
349
378
  /** One sheet read back from an `.xlsx` by {@link GigaPdfEngine.xlsxToGrids}. */
350
379
  interface XlsxSheet {
351
380
  name: string;
@@ -633,6 +662,15 @@ declare class GigaPdfDoc {
633
662
  addNamedDest(name: string, targetPage: number): boolean;
634
663
  /** The catalog's named destinations as `{name, page}` pairs. */
635
664
  namedDests(): NamedDest[];
665
+ /**
666
+ * Every embedded file attachment in the document's `/Names /EmbeddedFiles`
667
+ * name tree, decoded. Each {@link Attachment} carries the name-tree key, the
668
+ * filespec display name (`/UF`/`/F`), the embedded stream's MIME (`/Subtype`)
669
+ * and `/Params` dates, and the decoded bytes. Entries that don't resolve to a
670
+ * readable embedded stream are skipped, so the result is only extractable
671
+ * files (the native replacement for a reader's `getAttachments()`).
672
+ */
673
+ attachments(): Attachment[];
636
674
  /**
637
675
  * Add an internal hyperlink over a rectangle that jumps to the named
638
676
  * destination `name` (define it with {@link addNamedDest}). Unlike
@@ -693,4 +731,4 @@ declare class GigaPdfDoc {
693
731
  }): boolean;
694
732
  }
695
733
 
696
- export { type AnnotationInfo, type Box, type DecodedImage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, GigaPdfDoc, GigaPdfEngine, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type LayerInfo, type LinkInfo, type NamedDest, type OcrWord, type OutlineEntry, type PageInfo, type RadioOption, type SearchHit, type SignP12Options, type TextLine, type TextRunInfo, type XlsxSheet };
734
+ export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, GigaPdfDoc, GigaPdfEngine, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type LayerInfo, type LinkInfo, type NamedDest, type OcrWord, type OutlineEntry, type PageInfo, type RadioOption, type SearchHit, type SignP12Options, type TextLine, type TextRunInfo, type XlsxSheet };
package/dist/index.js CHANGED
@@ -6,6 +6,8 @@ var GigaPdfEngine = class _GigaPdfEngine {
6
6
  this.ex = ex;
7
7
  }
8
8
  ex;
9
+ /** Lazily-built Base64 reverse-lookup table (see {@link _fromBase64}). */
10
+ static _b64rev;
9
11
  /** Instantiate from raw wasm bytes, a URL/path, or a Response. */
10
12
  static async load(source) {
11
13
  let bytes;
@@ -74,6 +76,37 @@ var GigaPdfEngine = class _GigaPdfEngine {
74
76
  const s = this._str(call);
75
77
  return s ? JSON.parse(s) : [];
76
78
  }
79
+ /**
80
+ * Decode standard Base64 (RFC 4648) to bytes. Pure-JS table decode, so it
81
+ * works identically in Node and the browser with no dependency (used to turn
82
+ * the JSON `dataBase64` of {@link GigaPdfDoc.attachments} back into bytes).
83
+ */
84
+ _fromBase64(s) {
85
+ let rev = _GigaPdfEngine._b64rev;
86
+ if (!rev) {
87
+ rev = new Int16Array(256).fill(-1);
88
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
89
+ for (let i = 0; i < alphabet.length; i++) rev[alphabet.charCodeAt(i)] = i;
90
+ _GigaPdfEngine._b64rev = rev;
91
+ }
92
+ let count = s.length;
93
+ while (count > 0 && s[count - 1] === "=") count--;
94
+ const out = new Uint8Array(count * 3 >> 2);
95
+ let acc = 0;
96
+ let bits = 0;
97
+ let oi = 0;
98
+ for (let i = 0; i < count; i++) {
99
+ const v = rev[s.charCodeAt(i)];
100
+ if (v === void 0 || v < 0) continue;
101
+ acc = acc << 6 | v;
102
+ bits += 6;
103
+ if (bits >= 8) {
104
+ bits -= 8;
105
+ out[oi++] = acc >> bits & 255;
106
+ }
107
+ }
108
+ return oi === out.length ? out : out.subarray(0, oi);
109
+ }
77
110
  /** Pass a string argument; runs `fn(ptr, len)` then frees. */
78
111
  _withStr(s, fn) {
79
112
  const b = enc.encode(s);
@@ -1144,6 +1177,23 @@ var GigaPdfDoc = class {
1144
1177
  namedDests() {
1145
1178
  return this.g._json((o) => this.ex().gp_named_dests_json(this.h, o));
1146
1179
  }
1180
+ /**
1181
+ * Every embedded file attachment in the document's `/Names /EmbeddedFiles`
1182
+ * name tree, decoded. Each {@link Attachment} carries the name-tree key, the
1183
+ * filespec display name (`/UF`/`/F`), the embedded stream's MIME (`/Subtype`)
1184
+ * and `/Params` dates, and the decoded bytes. Entries that don't resolve to a
1185
+ * readable embedded stream are skipped, so the result is only extractable
1186
+ * files (the native replacement for a reader's `getAttachments()`).
1187
+ */
1188
+ attachments() {
1189
+ const raw = this.g._json(
1190
+ (o) => this.ex().gp_attachments_json(this.h, o)
1191
+ );
1192
+ return raw.map(({ dataBase64, ...rest }) => ({
1193
+ ...rest,
1194
+ data: this.g._fromBase64(dataBase64)
1195
+ }));
1196
+ }
1147
1197
  /**
1148
1198
  * Add an internal hyperlink over a rectangle that jumps to the named
1149
1199
  * destination `name` (define it with {@link addNamedDest}). Unlike