@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 CHANGED
@@ -4,6 +4,36 @@ 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.35.0] - 2026-06-17
8
+
9
+ ### Added
10
+
11
+ - **Lossy WebP decoding (`decodeWebp`).** `decodeWebp` / `gp_decode_webp` now
12
+ decodes lossy WebP (a `VP8 ` keyframe) in addition to the existing lossless
13
+ (`VP8L`) path — a complete, from-scratch VP8 intra decoder (RFC 6386):
14
+ boolean entropy decoder, coefficient token decode, dequantization, inverse
15
+ WHT/DCT, all intra prediction modes (16×16 / 8×8 / the ten 4×4 sub-block
16
+ modes), the deblocking loop filter (§15), and YUV→RGB. Validated **bit-exact**
17
+ against libvpx's reference decode. No third-party codec.
18
+
19
+ ### Added
20
+
21
+ - **External-resource host port for the HTML→PDF engine.** The native renderer
22
+ is zero-network, so external `<img src>` images (not just `data:` URIs) are now
23
+ fetched by the **host** in the same two-phase pattern as fonts:
24
+ - `htmlNeededResources(html, header?, footer?)` / `gp_html_needed_resources` —
25
+ one unified phase-1 list of everything the document needs: fonts
26
+ (`{kind:"font",family,weight,italic,url}`) **and** external images
27
+ (`{kind:"image",url}`). `data:` images are inlined and never listed.
28
+ - `HtmlRenderOptions.resources` (`{ url, bytes }[]`) on `htmlRenderWith` /
29
+ `RenderOptions.resources` on `render_with` / the `gp_html_render_opts`
30
+ `resources` blob — the host hands the fetched image bytes back, keyed by the
31
+ exact URL referenced in the HTML.
32
+
33
+ This lets a host render documents with remote images while keeping the engine
34
+ fully offline — the native replacement for a headless browser's autonomous
35
+ resource loading, with every fetched URL auditable up-front (SSRF-friendly).
36
+
7
37
  ## [0.33.0] - 2026-06-17
8
38
 
9
39
  ### 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;