@qrcommunication/gigapdf-lib 0.24.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/CHANGELOG.md +32 -0
- package/README.md +2 -1
- package/dist/index.cjs +67 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -1
- package/gigapdf.wasm +0 -0
- package/package.json +1 -1
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). */
|
|
@@ -121,6 +129,16 @@ declare class GigaPdfEngine {
|
|
|
121
129
|
decodePng(png: Uint8Array): DecodedImage | null;
|
|
122
130
|
/** Decode a GIF (first frame) to `{ width, height, rgba }`, or `null`. */
|
|
123
131
|
decodeGif(gif: Uint8Array): DecodedImage | null;
|
|
132
|
+
/**
|
|
133
|
+
* Encode raw RGBA pixels to a **lossless** WebP (VP8L) with the engine's native
|
|
134
|
+
* encoder — no third-party image library. Empty array on a bad input.
|
|
135
|
+
*/
|
|
136
|
+
encodeWebp(rgba: Uint8Array, width: number, height: number): Uint8Array;
|
|
137
|
+
/**
|
|
138
|
+
* Decode a **lossless** (VP8L) WebP to `{ width, height, rgba }`, or `null`.
|
|
139
|
+
* Lossy (VP8) and extended/animated WebP are not handled (returns `null`).
|
|
140
|
+
*/
|
|
141
|
+
decodeWebp(webp: Uint8Array): DecodedImage | null;
|
|
124
142
|
/** Unpack a `[w:u32 LE][h:u32 LE][rgba]` decode buffer; `null` if empty. */
|
|
125
143
|
_decodeFramed(bytes: Uint8Array, fn: (p: number, l: number, o: number) => number): DecodedImage | null;
|
|
126
144
|
fontCatalog(): FontInfo[];
|
|
@@ -336,6 +354,27 @@ interface NamedDest {
|
|
|
336
354
|
name: string;
|
|
337
355
|
page: number;
|
|
338
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
|
+
}
|
|
339
378
|
/** One sheet read back from an `.xlsx` by {@link GigaPdfEngine.xlsxToGrids}. */
|
|
340
379
|
interface XlsxSheet {
|
|
341
380
|
name: string;
|
|
@@ -623,6 +662,15 @@ declare class GigaPdfDoc {
|
|
|
623
662
|
addNamedDest(name: string, targetPage: number): boolean;
|
|
624
663
|
/** The catalog's named destinations as `{name, page}` pairs. */
|
|
625
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[];
|
|
626
674
|
/**
|
|
627
675
|
* Add an internal hyperlink over a rectangle that jumps to the named
|
|
628
676
|
* destination `name` (define it with {@link addNamedDest}). Unlike
|
|
@@ -683,4 +731,4 @@ declare class GigaPdfDoc {
|
|
|
683
731
|
}): boolean;
|
|
684
732
|
}
|
|
685
733
|
|
|
686
|
-
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). */
|
|
@@ -121,6 +129,16 @@ declare class GigaPdfEngine {
|
|
|
121
129
|
decodePng(png: Uint8Array): DecodedImage | null;
|
|
122
130
|
/** Decode a GIF (first frame) to `{ width, height, rgba }`, or `null`. */
|
|
123
131
|
decodeGif(gif: Uint8Array): DecodedImage | null;
|
|
132
|
+
/**
|
|
133
|
+
* Encode raw RGBA pixels to a **lossless** WebP (VP8L) with the engine's native
|
|
134
|
+
* encoder — no third-party image library. Empty array on a bad input.
|
|
135
|
+
*/
|
|
136
|
+
encodeWebp(rgba: Uint8Array, width: number, height: number): Uint8Array;
|
|
137
|
+
/**
|
|
138
|
+
* Decode a **lossless** (VP8L) WebP to `{ width, height, rgba }`, or `null`.
|
|
139
|
+
* Lossy (VP8) and extended/animated WebP are not handled (returns `null`).
|
|
140
|
+
*/
|
|
141
|
+
decodeWebp(webp: Uint8Array): DecodedImage | null;
|
|
124
142
|
/** Unpack a `[w:u32 LE][h:u32 LE][rgba]` decode buffer; `null` if empty. */
|
|
125
143
|
_decodeFramed(bytes: Uint8Array, fn: (p: number, l: number, o: number) => number): DecodedImage | null;
|
|
126
144
|
fontCatalog(): FontInfo[];
|
|
@@ -336,6 +354,27 @@ interface NamedDest {
|
|
|
336
354
|
name: string;
|
|
337
355
|
page: number;
|
|
338
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
|
+
}
|
|
339
378
|
/** One sheet read back from an `.xlsx` by {@link GigaPdfEngine.xlsxToGrids}. */
|
|
340
379
|
interface XlsxSheet {
|
|
341
380
|
name: string;
|
|
@@ -623,6 +662,15 @@ declare class GigaPdfDoc {
|
|
|
623
662
|
addNamedDest(name: string, targetPage: number): boolean;
|
|
624
663
|
/** The catalog's named destinations as `{name, page}` pairs. */
|
|
625
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[];
|
|
626
674
|
/**
|
|
627
675
|
* Add an internal hyperlink over a rectangle that jumps to the named
|
|
628
676
|
* destination `name` (define it with {@link addNamedDest}). Unlike
|
|
@@ -683,4 +731,4 @@ declare class GigaPdfDoc {
|
|
|
683
731
|
}): boolean;
|
|
684
732
|
}
|
|
685
733
|
|
|
686
|
-
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);
|
|
@@ -260,6 +293,23 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
260
293
|
decodeGif(gif) {
|
|
261
294
|
return this._decodeFramed(gif, (p, l, o) => this.ex.gp_decode_gif(p, l, o));
|
|
262
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* Encode raw RGBA pixels to a **lossless** WebP (VP8L) with the engine's native
|
|
298
|
+
* encoder — no third-party image library. Empty array on a bad input.
|
|
299
|
+
*/
|
|
300
|
+
encodeWebp(rgba, width, height) {
|
|
301
|
+
return this._withBytes(
|
|
302
|
+
rgba,
|
|
303
|
+
(p, l) => this._buffer((o) => this.ex.gp_encode_webp(width, height, p, l, o))
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Decode a **lossless** (VP8L) WebP to `{ width, height, rgba }`, or `null`.
|
|
308
|
+
* Lossy (VP8) and extended/animated WebP are not handled (returns `null`).
|
|
309
|
+
*/
|
|
310
|
+
decodeWebp(webp) {
|
|
311
|
+
return this._decodeFramed(webp, (p, l, o) => this.ex.gp_decode_webp(p, l, o));
|
|
312
|
+
}
|
|
263
313
|
/** Unpack a `[w:u32 LE][h:u32 LE][rgba]` decode buffer; `null` if empty. */
|
|
264
314
|
_decodeFramed(bytes, fn) {
|
|
265
315
|
const framed = this._withBytes(bytes, (p, l) => this._buffer((o) => fn(p, l, o)));
|
|
@@ -1127,6 +1177,23 @@ var GigaPdfDoc = class {
|
|
|
1127
1177
|
namedDests() {
|
|
1128
1178
|
return this.g._json((o) => this.ex().gp_named_dests_json(this.h, o));
|
|
1129
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
|
+
}
|
|
1130
1197
|
/**
|
|
1131
1198
|
* Add an internal hyperlink over a rectangle that jumps to the named
|
|
1132
1199
|
* destination `name` (define it with {@link addNamedDest}). Unlike
|