@qrcommunication/gigapdf-lib 0.64.0 → 0.66.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.ts CHANGED
@@ -103,6 +103,23 @@ declare class GigaPdfEngine {
103
103
  * a recognized Office container, `[]` if it needs no host fonts.
104
104
  */
105
105
  officeNeededFonts(office: Uint8Array): HtmlFontRequest[] | null;
106
+ /**
107
+ * Phase 2 for {@link officeNeededFonts} — render an Office container to PDF with
108
+ * the host-fetched `fonts` embedded, so families the container **references but
109
+ * doesn't embed** (reported by {@link officeNeededFonts}) lay out with the right
110
+ * metrics (e.g. Carlito for a Calibri reference) instead of drifting onto the
111
+ * bundled fallback. Faces the container embeds itself win on conflict, so an
112
+ * empty `fonts` array yields exactly {@link officeToPdf}'s output. Empty array
113
+ * if the bytes are not a recognized Office container.
114
+ *
115
+ * @example
116
+ * const reqs = giga.officeNeededFonts(docx); // phase 1: what to fetch
117
+ * const fonts = await Promise.all( // host fetches each url → TTF
118
+ * (reqs ?? []).map(async (r) => ({ ...r, ttf: await fetchTtf(r.url) }))
119
+ * );
120
+ * const pdf = giga.officeToPdfWith(docx, fonts); // phase 2: render with them
121
+ */
122
+ officeToPdfWith(office: Uint8Array, fonts?: HtmlFont[]): Uint8Array;
106
123
  /**
107
124
  * Image (PNG/JPEG/GIF/WebP/AVIF) → one-page PDF, format auto-detected: the
108
125
  * image is centred and scaled to fit on an A4 portrait page. PNG/JPEG embed
@@ -466,40 +483,292 @@ interface GigaCharStyle {
466
483
  color: [number, number, number] | null;
467
484
  valign: 'baseline' | 'super' | 'sub';
468
485
  }
469
- /** An inline node (tagged): a styled run, a line break, an image, or a link. */
486
+ /** An axis-aligned placement box, lower-left `(x,y)` + size, in PDF points. */
487
+ interface GigaRect {
488
+ x: number;
489
+ y: number;
490
+ w: number;
491
+ h: number;
492
+ }
493
+ /** A hyperlink destination (tagged; mirror of `model::LinkTarget`). */
494
+ type GigaLinkTarget = {
495
+ t: 'url';
496
+ v: string;
497
+ } | {
498
+ t: 'page';
499
+ v: number;
500
+ };
501
+ /**
502
+ * An inline (within-paragraph) node, tagged by `t` (mirror of `model::Inline`).
503
+ * `run` carries the styled text + its `source_index` back to the editable
504
+ * content-stream operator; `br` is a hard line break; `image` an inline image;
505
+ * `link` wraps children with a destination.
506
+ */
470
507
  type GigaInline = {
471
508
  t: 'run';
509
+ v: GigaInlineRun;
510
+ } | {
511
+ t: 'br';
512
+ } | {
513
+ t: 'image';
514
+ v: GigaImageRef;
515
+ } | {
516
+ t: 'link';
517
+ href: GigaLinkTarget;
518
+ children: GigaInline[];
519
+ };
520
+ /** A styled span of text (mirror of `model::InlineRun`). */
521
+ interface GigaInlineRun {
472
522
  text: string;
473
523
  style: GigaCharStyle;
524
+ /** Index of the source content-stream run for in-place round-tripping, or `null`. */
474
525
  source_index: number | null;
526
+ }
527
+ /** Paragraph-level formatting (mirror of `model::style::ParagraphStyle`). */
528
+ interface GigaParagraphStyle {
529
+ align: 'left' | 'center' | 'right' | 'justify';
530
+ space_before_pt: number;
531
+ space_after_pt: number;
532
+ indent_left_pt: number;
533
+ indent_right_pt: number;
534
+ /** First-line indent (positive) or hanging indent (negative), in points. */
535
+ first_line_pt: number;
536
+ /** Leading policy: font-natural, a size multiple, or a fixed point value. */
537
+ line_height: {
538
+ t: 'normal';
539
+ } | {
540
+ t: 'multiple';
541
+ v: number;
542
+ } | {
543
+ t: 'points';
544
+ v: number;
545
+ };
546
+ }
547
+ /** A paragraph: its own style, an optional named-style ref, and its inline runs. */
548
+ interface GigaParagraph {
549
+ style: GigaParagraphStyle;
550
+ /** Named style this paragraph derives from, if any. */
551
+ style_ref: string | null;
552
+ runs: GigaInline[];
553
+ }
554
+ /** A heading (`level` 1..=6) wrapping a paragraph (mirror of `model::Heading`). */
555
+ interface GigaHeading {
556
+ level: number;
557
+ para: GigaParagraph;
558
+ }
559
+ /** A list bullet/number style (tagged; mirror of `model::ListMarker`). */
560
+ type GigaListMarker = {
561
+ t: 'bullet';
562
+ v: string;
475
563
  } | {
476
- t: 'break';
564
+ t: 'decimal';
477
565
  } | {
478
- t: 'image';
479
- [k: string]: unknown;
566
+ t: 'lower_alpha';
480
567
  } | {
481
- t: 'link';
482
- [k: string]: unknown;
568
+ t: 'upper_alpha';
569
+ } | {
570
+ t: 'lower_roman';
571
+ } | {
572
+ t: 'upper_roman';
573
+ };
574
+ /** One list item: nested blocks at a given `level` (mirror of `model::ListItem`). */
575
+ interface GigaListItem {
576
+ blocks: GigaBlock[];
577
+ level: number;
578
+ }
579
+ /** An ordered or unordered list (mirror of `model::List`). */
580
+ interface GigaList {
581
+ ordered: boolean;
582
+ marker: GigaListMarker;
583
+ items: GigaListItem[];
584
+ }
585
+ /** A table cell: block content, span, and optional RGB shading (`model::Cell`). */
586
+ interface GigaTableCell {
587
+ blocks: GigaBlock[];
588
+ col_span: number;
589
+ row_span: number;
590
+ /** RGB `0..=1` background, or `null` for no shading. */
591
+ shading: [number, number, number] | null;
592
+ }
593
+ /** A table row: its cells and an optional fixed height in points (`model::Row`). */
594
+ interface GigaTableRow {
595
+ cells: GigaTableCell[];
596
+ height: number | null;
597
+ }
598
+ /** A table/cell border (mirror of `model::BorderStyle`). */
599
+ interface GigaBorderStyle {
600
+ width: number;
601
+ color: [number, number, number];
602
+ }
603
+ /** A table: rows of cells, explicit column widths, and a border (`model::Table`). */
604
+ interface GigaTable {
605
+ rows: GigaTableRow[];
606
+ col_widths: number[];
607
+ border: GigaBorderStyle;
608
+ }
609
+ /** A reference to an image blob in the document's resource table (`model::ImageRef`). */
610
+ interface GigaImageRef {
611
+ /** Content-hash key into `GigaDocument.resources.images`. */
612
+ resource: number;
613
+ alt: string | null;
614
+ }
615
+ /** A single vector path segment (tagged; mirror of `content::vector::PathSeg`). */
616
+ type GigaPathSeg = {
617
+ t: 'm';
618
+ x: number;
619
+ y: number;
620
+ } | {
621
+ t: 'l';
622
+ x: number;
623
+ y: number;
624
+ } | {
625
+ t: 'c';
626
+ x1: number;
627
+ y1: number;
628
+ x2: number;
629
+ y2: number;
630
+ x: number;
631
+ y: number;
632
+ } | {
633
+ t: 'z';
634
+ };
635
+ /** A vector shape: a path with fill/stroke styling (mirror of `model::Shape`). */
636
+ interface GigaShape {
637
+ segments: GigaPathSeg[];
638
+ /** RGB `0..=1` fill, or `null` when unfilled. */
639
+ fill: [number, number, number] | null;
640
+ /** RGB `0..=1` stroke, or `null` when unstroked. */
641
+ stroke: [number, number, number] | null;
642
+ stroke_width: number;
643
+ dash: number[];
644
+ }
645
+ /** A free-floating text box holding a list of blocks (mirror of `model::TextBox`). */
646
+ interface GigaTextBox {
647
+ blocks: GigaBlock[];
648
+ }
649
+ /** A typed spreadsheet cell (mirror of `model::SheetCell`). */
650
+ interface GigaSheetCell {
651
+ value: GigaCellValue;
652
+ number_format: string | null;
653
+ /** RGB `0..=1` cell fill, or `null` for none. */
654
+ fill: [number, number, number] | null;
655
+ style: GigaCharStyle;
656
+ }
657
+ /** One spreadsheet row (mirror of `model::SheetRow`). */
658
+ interface GigaSheetRow {
659
+ cells: GigaSheetCell[];
660
+ }
661
+ /** An inclusive merged-cell rectangle `(r0,c0)..=(r1,c1)`, zero-based. */
662
+ interface GigaMergeRange {
663
+ r0: number;
664
+ c0: number;
665
+ r1: number;
666
+ c1: number;
667
+ }
668
+ /** A single named worksheet (mirror of `model::Sheet`). */
669
+ interface GigaSheet {
670
+ name: string;
671
+ rows: GigaSheetRow[];
672
+ merges: GigaMergeRange[];
673
+ col_widths: number[];
674
+ }
675
+ /** A block of spreadsheet content: one or more sheets (mirror of `model::SheetBlock`). */
676
+ interface GigaSheetBlock {
677
+ sheets: GigaSheet[];
678
+ }
679
+ /** A slide layout placeholder role (tagged; mirror of `model::PlaceholderRole`). */
680
+ type GigaPlaceholderRole = {
681
+ t: 'title';
682
+ } | {
683
+ t: 'subtitle';
684
+ } | {
685
+ t: 'body';
686
+ } | {
687
+ t: 'other';
688
+ v: string;
483
689
  };
484
- /** A block payload (tagged by `t`); only the common shapes are spelled out. */
485
- interface GigaBlockKind {
486
- t: 'paragraph' | 'heading' | 'list' | 'table' | 'image' | 'shape' | 'textbox' | 'sheet' | 'slide';
487
- /** The variant body — e.g. a paragraph carries `{ runs: GigaInline[], … }`. */
488
- v?: unknown;
690
+ /** A slide placeholder: a block tagged with its semantic role (`model::Placeholder`). */
691
+ interface GigaPlaceholder {
692
+ role: GigaPlaceholderRole;
693
+ block: GigaBlock;
694
+ }
695
+ /** Resolved page size + margins, in points (mirror of `model::geom::PageGeometry`). */
696
+ interface GigaPageGeometry {
697
+ width: number;
698
+ height: number;
699
+ margins: {
700
+ top: number;
701
+ right: number;
702
+ bottom: number;
703
+ left: number;
704
+ };
705
+ }
706
+ /** A single slide (mirror of `model::Slide`). */
707
+ interface GigaSlide {
708
+ geometry: GigaPageGeometry;
709
+ shapes: GigaBlock[];
710
+ placeholders: GigaPlaceholder[];
711
+ notes: GigaBlock[] | null;
489
712
  }
713
+ /** A block of presentation content: an ordered list of slides (`model::SlideBlock`). */
714
+ interface GigaSlideBlock {
715
+ slides: GigaSlide[];
716
+ }
717
+ /**
718
+ * A block payload, **fully typed and discriminated by `t`** (mirror of
719
+ * `model::BlockKind`'s JSON). Narrow on `kind.t` to read the variant body in
720
+ * `kind.v` — e.g. a `paragraph` exposes `v.runs` (each `run` carrying
721
+ * `style.bold`/`style.italic`/`style.size_pt`/`style.color`), a `heading` its
722
+ * `v.level`, a `table` its `v.rows[].cells[]` (with `col_span`/`row_span`), and a
723
+ * `list` its `v.ordered` + `v.items`. This is what lets a thin editor render the
724
+ * recognised structure (bold, headings, tables, lists) 1:1.
725
+ */
726
+ type GigaBlockKind = {
727
+ t: 'paragraph';
728
+ v: GigaParagraph;
729
+ } | {
730
+ t: 'heading';
731
+ v: GigaHeading;
732
+ } | {
733
+ t: 'list';
734
+ v: GigaList;
735
+ } | {
736
+ t: 'table';
737
+ v: GigaTable;
738
+ } | {
739
+ t: 'image';
740
+ v: GigaImageRef;
741
+ } | {
742
+ t: 'shape';
743
+ v: GigaShape;
744
+ } | {
745
+ t: 'textbox';
746
+ v: GigaTextBox;
747
+ } | {
748
+ t: 'sheet';
749
+ v: GigaSheetBlock;
750
+ } | {
751
+ t: 'slide';
752
+ v: GigaSlideBlock;
753
+ };
754
+ /** Block rotation (tagged; mirror of `model::geom::Rotation`). */
755
+ type GigaRotation = {
756
+ t: 'd0';
757
+ } | {
758
+ t: 'd90';
759
+ } | {
760
+ t: 'd180';
761
+ } | {
762
+ t: 'd270';
763
+ } | {
764
+ t: 'deg';
765
+ v: number;
766
+ };
490
767
  /** A block: a stable id, an optional placement frame + rotation, and its kind. */
491
768
  interface GigaBlock {
492
769
  id: number;
493
- frame: {
494
- x: number;
495
- y: number;
496
- w: number;
497
- h: number;
498
- } | null;
499
- rotation: {
500
- t: 'd0' | 'd90' | 'd180' | 'd270' | 'deg';
501
- v?: number;
502
- };
770
+ frame: GigaRect | null;
771
+ rotation: GigaRotation;
503
772
  kind: GigaBlockKind;
504
773
  }
505
774
  /** A page: a list of blocks; `absolute` flags slide/form (positioned) layout. */
@@ -509,20 +778,30 @@ interface GigaPage {
509
778
  }
510
779
  /** A section: one page geometry, optional running header/footer, and its pages. */
511
780
  interface GigaSection {
512
- geometry: {
513
- width: number;
514
- height: number;
515
- [k: string]: unknown;
516
- };
781
+ geometry: GigaPageGeometry;
517
782
  header: GigaBlock[] | null;
518
783
  footer: GigaBlock[] | null;
519
784
  pages: GigaPage[];
520
785
  }
786
+ /**
787
+ * A document outline (bookmark) entry — a label, a zero-based destination page,
788
+ * and nested children (mirror of `model::OutlineNode`). Populated by
789
+ * {@link GigaPdf.officeToModel}/reconstruction from the source's own bookmarks
790
+ * (PDF `/Outlines`) or, lacking those, from detected headings.
791
+ */
792
+ interface GigaOutlineNode {
793
+ /** The bookmark label. */
794
+ title: string;
795
+ /** Zero-based destination page in the document's flattened page sequence. */
796
+ page: number;
797
+ /** Nested sub-bookmarks. */
798
+ children: GigaOutlineNode[];
799
+ }
521
800
  /**
522
801
  * The unified editable document model — the format-neutral tree every format
523
802
  * lowers into and is reconstructed from. `v` is the envelope version. Leaves
524
- * beyond what a host typically edits (`styles`, `outline`, `resources`) are
525
- * carried opaquely so a round-trip preserves them.
803
+ * beyond what a host typically edits (`styles`, `resources`) are carried
804
+ * opaquely so a round-trip preserves them.
526
805
  */
527
806
  interface GigaDocument {
528
807
  v: number;
@@ -535,7 +814,8 @@ interface GigaDocument {
535
814
  };
536
815
  styles: unknown;
537
816
  sections: GigaSection[];
538
- outline: unknown[];
817
+ /** Bookmark / chapter hierarchy (empty when the source has none). */
818
+ outline: GigaOutlineNode[];
539
819
  resources: unknown;
540
820
  }
541
821
  /**
@@ -1468,4 +1748,4 @@ declare class GigaPdfDoc {
1468
1748
  }): boolean;
1469
1749
  }
1470
1750
 
1471
- export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type DocumentLanguage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaInline, type GigaPage, GigaPdfDoc, GigaPdfEngine, type GigaSection, type GigaStylePatch, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type ModelOp, type NamedDest, type OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
1751
+ export { type AnnotationInfo, type Attachment, type Box, type DecodedImage, type DocumentLanguage, type Element, type EmbeddedFont, type FieldInfo, type FieldKind, type FieldStyle, type FontInfo, type GigaBlock, type GigaBlockAddr, type GigaBlockKind, type GigaBorderStyle, type GigaCellValue, type GigaCharStyle, type GigaDocument, type GigaGeneric, type GigaHeading, type GigaImageRef, type GigaInline, type GigaInlineRun, type GigaLinkTarget, type GigaList, type GigaListItem, type GigaListMarker, type GigaMergeRange, type GigaOutlineNode, type GigaPage, type GigaPageGeometry, type GigaParagraph, type GigaParagraphStyle, type GigaPathSeg, GigaPdfDoc, GigaPdfEngine, type GigaPlaceholder, type GigaPlaceholderRole, type GigaRect, type GigaRotation, type GigaSection, type GigaShape, type GigaSheet, type GigaSheetBlock, type GigaSheetCell, type GigaSheetRow, type GigaSlide, type GigaSlideBlock, type GigaStylePatch, type GigaTable, type GigaTableCell, type GigaTableRow, type GigaTextBox, type HeaderFooterAlign, type HeaderFooterSpec, type HtmlFont, type HtmlFontRequest, type HtmlMargins, type HtmlRenderOptions, type HtmlResource, type HtmlResourceNeed, type ImageElementInfo, type LayerInfo, type LinkInfo, type ModelOp, type NamedDest, type OutlineEntry, type PageInfo, type PageMargins, type PathSegment, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
package/dist/index.js CHANGED
@@ -256,6 +256,32 @@ var GigaPdfEngine = class _GigaPdfEngine {
256
256
  (p, l) => this._jsonOrNull((o) => this.ex.gp_office_needed_fonts(p, l, o))
257
257
  );
258
258
  }
259
+ /**
260
+ * Phase 2 for {@link officeNeededFonts} — render an Office container to PDF with
261
+ * the host-fetched `fonts` embedded, so families the container **references but
262
+ * doesn't embed** (reported by {@link officeNeededFonts}) lay out with the right
263
+ * metrics (e.g. Carlito for a Calibri reference) instead of drifting onto the
264
+ * bundled fallback. Faces the container embeds itself win on conflict, so an
265
+ * empty `fonts` array yields exactly {@link officeToPdf}'s output. Empty array
266
+ * if the bytes are not a recognized Office container.
267
+ *
268
+ * @example
269
+ * const reqs = giga.officeNeededFonts(docx); // phase 1: what to fetch
270
+ * const fonts = await Promise.all( // host fetches each url → TTF
271
+ * (reqs ?? []).map(async (r) => ({ ...r, ttf: await fetchTtf(r.url) }))
272
+ * );
273
+ * const pdf = giga.officeToPdfWith(docx, fonts); // phase 2: render with them
274
+ */
275
+ officeToPdfWith(office, fonts = []) {
276
+ const blob = packHtmlFonts(fonts);
277
+ return this._withBytes(
278
+ office,
279
+ (op, ol) => this._withBytes(
280
+ blob,
281
+ (fp, fl) => this._buffer((o) => this.ex.gp_office_to_pdf_with_fonts(op, ol, fp, fl, o))
282
+ )
283
+ );
284
+ }
259
285
  /**
260
286
  * Image (PNG/JPEG/GIF/WebP/AVIF) → one-page PDF, format auto-detected: the
261
287
  * image is centred and scaled to fit on an A4 portrait page. PNG/JPEG embed