@qrcommunication/gigapdf-lib 0.33.0 → 0.35.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 +30 -0
- package/dist/index.cjs +68 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -1
- package/dist/index.d.ts +41 -1
- package/dist/index.js +68 -20
- package/dist/index.js.map +1 -1
- package/gigapdf.wasm +0 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -199,6 +199,16 @@ declare class GigaPdfEngine {
|
|
|
199
199
|
* ```
|
|
200
200
|
*/
|
|
201
201
|
htmlRenderWith(html: string, fonts?: HtmlFont[], options?: HtmlRenderOptions): Uint8Array;
|
|
202
|
+
/**
|
|
203
|
+
* Phase 1 (unified) — every external resource the document needs the host to
|
|
204
|
+
* fetch, in one list: fonts (`{kind:"font",family,weight,italic,url}`) and
|
|
205
|
+
* external images (`{kind:"image",url}`). Run **one** fetch loop, then pass
|
|
206
|
+
* fonts back as the `fonts` argument to {@link GigaPdfEngine.htmlRenderWith}
|
|
207
|
+
* (download each `url` → TTF) and images via
|
|
208
|
+
* {@link HtmlRenderOptions.resources} (`{url, bytes}`). `data:` image URIs are
|
|
209
|
+
* inlined and never listed.
|
|
210
|
+
*/
|
|
211
|
+
htmlNeededResources(html: string, header?: string, footer?: string): HtmlResourceNeed[];
|
|
202
212
|
}
|
|
203
213
|
/** A Google font the HTML engine needs (resolved from the catalogue). */
|
|
204
214
|
interface HtmlFontRequest {
|
|
@@ -215,6 +225,29 @@ interface HtmlFont {
|
|
|
215
225
|
italic: boolean;
|
|
216
226
|
ttf: Uint8Array;
|
|
217
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* A host-downloaded external resource (image) handed to
|
|
230
|
+
* {@link GigaPdfEngine.htmlRenderWith} via {@link HtmlRenderOptions.resources}.
|
|
231
|
+
* `url` must match the URL referenced in the HTML exactly.
|
|
232
|
+
*/
|
|
233
|
+
interface HtmlResource {
|
|
234
|
+
url: string;
|
|
235
|
+
bytes: Uint8Array;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* One entry from {@link GigaPdfEngine.htmlNeededResources}: a `font` (with its
|
|
239
|
+
* Google-Fonts download metadata) or an external `image` URL the host must fetch.
|
|
240
|
+
*/
|
|
241
|
+
type HtmlResourceNeed = {
|
|
242
|
+
kind: "font";
|
|
243
|
+
family: string;
|
|
244
|
+
weight: number;
|
|
245
|
+
italic: boolean;
|
|
246
|
+
url: string;
|
|
247
|
+
} | {
|
|
248
|
+
kind: "image";
|
|
249
|
+
url: string;
|
|
250
|
+
};
|
|
218
251
|
/** Per-side page margins in points; omitted sides default to 36pt. */
|
|
219
252
|
interface HtmlMargins {
|
|
220
253
|
top?: number;
|
|
@@ -242,6 +275,13 @@ interface HtmlRenderOptions {
|
|
|
242
275
|
footerOffset?: number;
|
|
243
276
|
/** Number assigned to the first page for `{{page}}` (default 1). */
|
|
244
277
|
startPageNumber?: number;
|
|
278
|
+
/**
|
|
279
|
+
* Host-downloaded external images, keyed by the exact URL referenced in the
|
|
280
|
+
* HTML (`<img src>`). Obtain the list with
|
|
281
|
+
* {@link GigaPdfEngine.htmlNeededResources}, fetch each, and pass the bytes
|
|
282
|
+
* here — the engine never touches the network. `data:` URIs need no entry.
|
|
283
|
+
*/
|
|
284
|
+
resources?: HtmlResource[];
|
|
245
285
|
}
|
|
246
286
|
interface FontInfo {
|
|
247
287
|
family: string;
|
|
@@ -883,4 +923,4 @@ declare class GigaPdfDoc {
|
|
|
883
923
|
}): boolean;
|
|
884
924
|
}
|
|
885
925
|
|
|
886
|
-
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 ImageElementInfo, type LayerInfo, type LinkInfo, type NamedDest, type OcrWord, type OutlineEntry, type PageInfo, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
|
|
926
|
+
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 HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type NamedDest, type OcrWord, type OutlineEntry, type PageInfo, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
|
package/dist/index.js
CHANGED
|
@@ -444,6 +444,7 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
444
444
|
const footerOffset = options.footerOffset ?? 18;
|
|
445
445
|
const start = options.startPageNumber ?? 1;
|
|
446
446
|
const blob = packHtmlFonts(fonts);
|
|
447
|
+
const resBlob = packHtmlResources(options.resources ?? []);
|
|
447
448
|
return this._withStr(
|
|
448
449
|
html,
|
|
449
450
|
(hp, hl) => this._withBytes(
|
|
@@ -452,26 +453,31 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
452
453
|
options.header,
|
|
453
454
|
(hdp, hdl) => this._withOptStr(
|
|
454
455
|
options.footer,
|
|
455
|
-
(ftp, ftl) => this.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
456
|
+
(ftp, ftl) => this._withBytes(
|
|
457
|
+
resBlob,
|
|
458
|
+
(rp, rl) => this._buffer(
|
|
459
|
+
(o) => this.ex.gp_html_render_opts(
|
|
460
|
+
hp,
|
|
461
|
+
hl,
|
|
462
|
+
fp,
|
|
463
|
+
fl,
|
|
464
|
+
pw,
|
|
465
|
+
ph,
|
|
466
|
+
mg.top,
|
|
467
|
+
mg.right,
|
|
468
|
+
mg.bottom,
|
|
469
|
+
mg.left,
|
|
470
|
+
hdp,
|
|
471
|
+
hdl,
|
|
472
|
+
ftp,
|
|
473
|
+
ftl,
|
|
474
|
+
headerOffset,
|
|
475
|
+
footerOffset,
|
|
476
|
+
start,
|
|
477
|
+
rp,
|
|
478
|
+
rl,
|
|
479
|
+
o
|
|
480
|
+
)
|
|
475
481
|
)
|
|
476
482
|
)
|
|
477
483
|
)
|
|
@@ -479,7 +485,49 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
479
485
|
)
|
|
480
486
|
);
|
|
481
487
|
}
|
|
488
|
+
/**
|
|
489
|
+
* Phase 1 (unified) — every external resource the document needs the host to
|
|
490
|
+
* fetch, in one list: fonts (`{kind:"font",family,weight,italic,url}`) and
|
|
491
|
+
* external images (`{kind:"image",url}`). Run **one** fetch loop, then pass
|
|
492
|
+
* fonts back as the `fonts` argument to {@link GigaPdfEngine.htmlRenderWith}
|
|
493
|
+
* (download each `url` → TTF) and images via
|
|
494
|
+
* {@link HtmlRenderOptions.resources} (`{url, bytes}`). `data:` image URIs are
|
|
495
|
+
* inlined and never listed.
|
|
496
|
+
*/
|
|
497
|
+
htmlNeededResources(html, header, footer) {
|
|
498
|
+
return this._withStr(
|
|
499
|
+
html,
|
|
500
|
+
(hp, hl) => this._withOptStr(
|
|
501
|
+
header,
|
|
502
|
+
(hdp, hdl) => this._withOptStr(
|
|
503
|
+
footer,
|
|
504
|
+
(ftp, ftl) => this._json((o) => this.ex.gp_html_needed_resources(hp, hl, hdp, hdl, ftp, ftl, o))
|
|
505
|
+
)
|
|
506
|
+
)
|
|
507
|
+
);
|
|
508
|
+
}
|
|
482
509
|
};
|
|
510
|
+
function packHtmlResources(resources) {
|
|
511
|
+
let size = 4;
|
|
512
|
+
for (const r of resources) size += 4 + enc.encode(r.url).length + 4 + r.bytes.length;
|
|
513
|
+
const buf = new Uint8Array(size);
|
|
514
|
+
const dv = new DataView(buf.buffer);
|
|
515
|
+
let o = 0;
|
|
516
|
+
dv.setUint32(o, resources.length, true);
|
|
517
|
+
o += 4;
|
|
518
|
+
for (const r of resources) {
|
|
519
|
+
const url = enc.encode(r.url);
|
|
520
|
+
dv.setUint32(o, url.length, true);
|
|
521
|
+
o += 4;
|
|
522
|
+
buf.set(url, o);
|
|
523
|
+
o += url.length;
|
|
524
|
+
dv.setUint32(o, r.bytes.length, true);
|
|
525
|
+
o += 4;
|
|
526
|
+
buf.set(r.bytes, o);
|
|
527
|
+
o += r.bytes.length;
|
|
528
|
+
}
|
|
529
|
+
return buf;
|
|
530
|
+
}
|
|
483
531
|
function packHtmlFonts(fonts) {
|
|
484
532
|
let size = 4;
|
|
485
533
|
for (const f of fonts) size += 4 + enc.encode(f.family).length + 2 + 1 + 4 + f.ttf.length;
|