@qrcommunication/gigapdf-lib 0.32.0 → 0.34.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 CHANGED
@@ -4,6 +4,37 @@ All notable changes to `@qrcommunication/gigapdf-lib` are documented here.
4
4
  The format follows [Keep a Changelog](https://keepachangelog.com/) and the
5
5
  project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.34.0] - 2026-06-17
8
+
9
+ ### Added
10
+
11
+ - **External-resource host port for the HTML→PDF engine.** The native renderer
12
+ is zero-network, so external `<img src>` images (not just `data:` URIs) are now
13
+ fetched by the **host** in the same two-phase pattern as fonts:
14
+ - `htmlNeededResources(html, header?, footer?)` / `gp_html_needed_resources` —
15
+ one unified phase-1 list of everything the document needs: fonts
16
+ (`{kind:"font",family,weight,italic,url}`) **and** external images
17
+ (`{kind:"image",url}`). `data:` images are inlined and never listed.
18
+ - `HtmlRenderOptions.resources` (`{ url, bytes }[]`) on `htmlRenderWith` /
19
+ `RenderOptions.resources` on `render_with` / the `gp_html_render_opts`
20
+ `resources` blob — the host hands the fetched image bytes back, keyed by the
21
+ exact URL referenced in the HTML.
22
+
23
+ This lets a host render documents with remote images while keeping the engine
24
+ fully offline — the native replacement for a headless browser's autonomous
25
+ resource loading, with every fetched URL auditable up-front (SSRF-friendly).
26
+
27
+ ## [0.33.0] - 2026-06-17
28
+
29
+ ### Added
30
+
31
+ - **`PageInfo` now carries the raw `/MediaBox`.** `pageInfo(page)` /
32
+ `gp_page_info_json` gain a `mediaBox` field (`[x0, y0, x1, y1]` in user-space
33
+ points), and `Document::page_media_box` exposes it natively. Unlike the
34
+ derived `width`/`height` (the box size), this preserves the box **origin**, so
35
+ a host can reconstruct a page's exact coordinate frame — the native
36
+ replacement for a reader's `page.view` / MediaBox read.
37
+
7
38
  ## [0.32.0] - 2026-06-17
8
39
 
9
40
  ### Added
package/dist/index.cjs CHANGED
@@ -485,6 +485,7 @@ var GigaPdfEngine = class _GigaPdfEngine {
485
485
  const footerOffset = options.footerOffset ?? 18;
486
486
  const start = options.startPageNumber ?? 1;
487
487
  const blob = packHtmlFonts(fonts);
488
+ const resBlob = packHtmlResources(options.resources ?? []);
488
489
  return this._withStr(
489
490
  html,
490
491
  (hp, hl) => this._withBytes(
@@ -493,26 +494,31 @@ var GigaPdfEngine = class _GigaPdfEngine {
493
494
  options.header,
494
495
  (hdp, hdl) => this._withOptStr(
495
496
  options.footer,
496
- (ftp, ftl) => this._buffer(
497
- (o) => this.ex.gp_html_render_opts(
498
- hp,
499
- hl,
500
- fp,
501
- fl,
502
- pw,
503
- ph,
504
- mg.top,
505
- mg.right,
506
- mg.bottom,
507
- mg.left,
508
- hdp,
509
- hdl,
510
- ftp,
511
- ftl,
512
- headerOffset,
513
- footerOffset,
514
- start,
515
- o
497
+ (ftp, ftl) => this._withBytes(
498
+ resBlob,
499
+ (rp, rl) => this._buffer(
500
+ (o) => this.ex.gp_html_render_opts(
501
+ hp,
502
+ hl,
503
+ fp,
504
+ fl,
505
+ pw,
506
+ ph,
507
+ mg.top,
508
+ mg.right,
509
+ mg.bottom,
510
+ mg.left,
511
+ hdp,
512
+ hdl,
513
+ ftp,
514
+ ftl,
515
+ headerOffset,
516
+ footerOffset,
517
+ start,
518
+ rp,
519
+ rl,
520
+ o
521
+ )
516
522
  )
517
523
  )
518
524
  )
@@ -520,7 +526,49 @@ var GigaPdfEngine = class _GigaPdfEngine {
520
526
  )
521
527
  );
522
528
  }
529
+ /**
530
+ * Phase 1 (unified) — every external resource the document needs the host to
531
+ * fetch, in one list: fonts (`{kind:"font",family,weight,italic,url}`) and
532
+ * external images (`{kind:"image",url}`). Run **one** fetch loop, then pass
533
+ * fonts back as the `fonts` argument to {@link GigaPdfEngine.htmlRenderWith}
534
+ * (download each `url` → TTF) and images via
535
+ * {@link HtmlRenderOptions.resources} (`{url, bytes}`). `data:` image URIs are
536
+ * inlined and never listed.
537
+ */
538
+ htmlNeededResources(html, header, footer) {
539
+ return this._withStr(
540
+ html,
541
+ (hp, hl) => this._withOptStr(
542
+ header,
543
+ (hdp, hdl) => this._withOptStr(
544
+ footer,
545
+ (ftp, ftl) => this._json((o) => this.ex.gp_html_needed_resources(hp, hl, hdp, hdl, ftp, ftl, o))
546
+ )
547
+ )
548
+ );
549
+ }
523
550
  };
551
+ function packHtmlResources(resources) {
552
+ let size = 4;
553
+ for (const r of resources) size += 4 + enc.encode(r.url).length + 4 + r.bytes.length;
554
+ const buf = new Uint8Array(size);
555
+ const dv = new DataView(buf.buffer);
556
+ let o = 0;
557
+ dv.setUint32(o, resources.length, true);
558
+ o += 4;
559
+ for (const r of resources) {
560
+ const url = enc.encode(r.url);
561
+ dv.setUint32(o, url.length, true);
562
+ o += 4;
563
+ buf.set(url, o);
564
+ o += url.length;
565
+ dv.setUint32(o, r.bytes.length, true);
566
+ o += 4;
567
+ buf.set(r.bytes, o);
568
+ o += r.bytes.length;
569
+ }
570
+ return buf;
571
+ }
524
572
  function packHtmlFonts(fonts) {
525
573
  let size = 4;
526
574
  for (const f of fonts) size += 4 + enc.encode(f.family).length + 2 + 1 + 4 + f.ttf.length;