@qrcommunication/gigapdf-lib 0.65.0 → 0.67.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 +50 -0
- package/dist/index.cjs +48 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +465 -30
- package/dist/index.d.ts +465 -30
- package/dist/index.js +48 -1
- package/dist/index.js.map +1 -1
- package/gigapdf.wasm +0 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,30 @@ type Exports = {
|
|
|
18
18
|
gp_free(ptr: number, len: number): void;
|
|
19
19
|
[k: string]: any;
|
|
20
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* The eight PDF access permissions carried by an `/Encrypt` dictionary's `/P`
|
|
23
|
+
* entry (ISO 32000-1 §7.6.3.2, Table 22). Each flag is `true` when the action
|
|
24
|
+
* is **granted** to a user opening the document with the user password; the
|
|
25
|
+
* owner password always lifts every restriction.
|
|
26
|
+
*/
|
|
27
|
+
type PdfPermissions = {
|
|
28
|
+
/** Print the document (low resolution unless {@link printHighRes} is also set). */
|
|
29
|
+
print: boolean;
|
|
30
|
+
/** Modify the document contents (other than annotating, filling or assembling). */
|
|
31
|
+
modify: boolean;
|
|
32
|
+
/** Copy or otherwise extract text and graphics. */
|
|
33
|
+
copy: boolean;
|
|
34
|
+
/** Add or modify annotations and fill in interactive form fields. */
|
|
35
|
+
annotate: boolean;
|
|
36
|
+
/** Fill in existing interactive form fields (even if {@link annotate} is clear). */
|
|
37
|
+
fillForms: boolean;
|
|
38
|
+
/** Extract text and graphics for accessibility tools. */
|
|
39
|
+
accessibility: boolean;
|
|
40
|
+
/** Assemble the document: insert, rotate and delete pages. */
|
|
41
|
+
assemble: boolean;
|
|
42
|
+
/** Print to a high-resolution device (requires {@link print}). */
|
|
43
|
+
printHighRes: boolean;
|
|
44
|
+
};
|
|
21
45
|
/** Loaded engine module. Create documents with {@link open} / {@link openEncrypted}. */
|
|
22
46
|
declare class GigaPdfEngine {
|
|
23
47
|
private readonly ex;
|
|
@@ -84,6 +108,25 @@ declare class GigaPdfEngine {
|
|
|
84
108
|
version: number;
|
|
85
109
|
revision: number;
|
|
86
110
|
};
|
|
111
|
+
/**
|
|
112
|
+
* Decode the eight access-permission flags from a `/P` permission bitmask
|
|
113
|
+
* (ISO 32000-1 Table 22) into named booleans (`true` = the action is
|
|
114
|
+
* granted). Reserved bits are ignored.
|
|
115
|
+
*/
|
|
116
|
+
decodePermissions(p: number): PdfPermissions;
|
|
117
|
+
/**
|
|
118
|
+
* Read a PDF's access permissions **without decrypting it** (no password
|
|
119
|
+
* needed). Returns the eight named flags decoded from the `/Encrypt`
|
|
120
|
+
* dictionary's `/P`; an unencrypted document grants everything.
|
|
121
|
+
*/
|
|
122
|
+
getPermissions(pdf: Uint8Array): PdfPermissions;
|
|
123
|
+
/**
|
|
124
|
+
* Pack eight access-permission flags into a signed 32-bit `/P` value
|
|
125
|
+
* (ISO 32000-1 Table 22). Omitted flags default to **granted**, so an empty
|
|
126
|
+
* object means "all allowed". Feed the result to {@link GigaPdfDoc.saveEncrypted}
|
|
127
|
+
* via `opts.permissions`, or pass `opts.flags` directly.
|
|
128
|
+
*/
|
|
129
|
+
permissionsToP(flags?: Partial<PdfPermissions>): number;
|
|
87
130
|
/**
|
|
88
131
|
* Width of `text` set in standard Helvetica at `size` points (AFM metrics) —
|
|
89
132
|
* place watermark/header text without embedding a font.
|
|
@@ -483,40 +526,292 @@ interface GigaCharStyle {
|
|
|
483
526
|
color: [number, number, number] | null;
|
|
484
527
|
valign: 'baseline' | 'super' | 'sub';
|
|
485
528
|
}
|
|
486
|
-
/** An
|
|
529
|
+
/** An axis-aligned placement box, lower-left `(x,y)` + size, in PDF points. */
|
|
530
|
+
interface GigaRect {
|
|
531
|
+
x: number;
|
|
532
|
+
y: number;
|
|
533
|
+
w: number;
|
|
534
|
+
h: number;
|
|
535
|
+
}
|
|
536
|
+
/** A hyperlink destination (tagged; mirror of `model::LinkTarget`). */
|
|
537
|
+
type GigaLinkTarget = {
|
|
538
|
+
t: 'url';
|
|
539
|
+
v: string;
|
|
540
|
+
} | {
|
|
541
|
+
t: 'page';
|
|
542
|
+
v: number;
|
|
543
|
+
};
|
|
544
|
+
/**
|
|
545
|
+
* An inline (within-paragraph) node, tagged by `t` (mirror of `model::Inline`).
|
|
546
|
+
* `run` carries the styled text + its `source_index` back to the editable
|
|
547
|
+
* content-stream operator; `br` is a hard line break; `image` an inline image;
|
|
548
|
+
* `link` wraps children with a destination.
|
|
549
|
+
*/
|
|
487
550
|
type GigaInline = {
|
|
488
551
|
t: 'run';
|
|
552
|
+
v: GigaInlineRun;
|
|
553
|
+
} | {
|
|
554
|
+
t: 'br';
|
|
555
|
+
} | {
|
|
556
|
+
t: 'image';
|
|
557
|
+
v: GigaImageRef;
|
|
558
|
+
} | {
|
|
559
|
+
t: 'link';
|
|
560
|
+
href: GigaLinkTarget;
|
|
561
|
+
children: GigaInline[];
|
|
562
|
+
};
|
|
563
|
+
/** A styled span of text (mirror of `model::InlineRun`). */
|
|
564
|
+
interface GigaInlineRun {
|
|
489
565
|
text: string;
|
|
490
566
|
style: GigaCharStyle;
|
|
567
|
+
/** Index of the source content-stream run for in-place round-tripping, or `null`. */
|
|
491
568
|
source_index: number | null;
|
|
569
|
+
}
|
|
570
|
+
/** Paragraph-level formatting (mirror of `model::style::ParagraphStyle`). */
|
|
571
|
+
interface GigaParagraphStyle {
|
|
572
|
+
align: 'left' | 'center' | 'right' | 'justify';
|
|
573
|
+
space_before_pt: number;
|
|
574
|
+
space_after_pt: number;
|
|
575
|
+
indent_left_pt: number;
|
|
576
|
+
indent_right_pt: number;
|
|
577
|
+
/** First-line indent (positive) or hanging indent (negative), in points. */
|
|
578
|
+
first_line_pt: number;
|
|
579
|
+
/** Leading policy: font-natural, a size multiple, or a fixed point value. */
|
|
580
|
+
line_height: {
|
|
581
|
+
t: 'normal';
|
|
582
|
+
} | {
|
|
583
|
+
t: 'multiple';
|
|
584
|
+
v: number;
|
|
585
|
+
} | {
|
|
586
|
+
t: 'points';
|
|
587
|
+
v: number;
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
/** A paragraph: its own style, an optional named-style ref, and its inline runs. */
|
|
591
|
+
interface GigaParagraph {
|
|
592
|
+
style: GigaParagraphStyle;
|
|
593
|
+
/** Named style this paragraph derives from, if any. */
|
|
594
|
+
style_ref: string | null;
|
|
595
|
+
runs: GigaInline[];
|
|
596
|
+
}
|
|
597
|
+
/** A heading (`level` 1..=6) wrapping a paragraph (mirror of `model::Heading`). */
|
|
598
|
+
interface GigaHeading {
|
|
599
|
+
level: number;
|
|
600
|
+
para: GigaParagraph;
|
|
601
|
+
}
|
|
602
|
+
/** A list bullet/number style (tagged; mirror of `model::ListMarker`). */
|
|
603
|
+
type GigaListMarker = {
|
|
604
|
+
t: 'bullet';
|
|
605
|
+
v: string;
|
|
492
606
|
} | {
|
|
493
|
-
t: '
|
|
607
|
+
t: 'decimal';
|
|
494
608
|
} | {
|
|
495
|
-
t: '
|
|
496
|
-
[k: string]: unknown;
|
|
609
|
+
t: 'lower_alpha';
|
|
497
610
|
} | {
|
|
498
|
-
t: '
|
|
499
|
-
|
|
611
|
+
t: 'upper_alpha';
|
|
612
|
+
} | {
|
|
613
|
+
t: 'lower_roman';
|
|
614
|
+
} | {
|
|
615
|
+
t: 'upper_roman';
|
|
616
|
+
};
|
|
617
|
+
/** One list item: nested blocks at a given `level` (mirror of `model::ListItem`). */
|
|
618
|
+
interface GigaListItem {
|
|
619
|
+
blocks: GigaBlock[];
|
|
620
|
+
level: number;
|
|
621
|
+
}
|
|
622
|
+
/** An ordered or unordered list (mirror of `model::List`). */
|
|
623
|
+
interface GigaList {
|
|
624
|
+
ordered: boolean;
|
|
625
|
+
marker: GigaListMarker;
|
|
626
|
+
items: GigaListItem[];
|
|
627
|
+
}
|
|
628
|
+
/** A table cell: block content, span, and optional RGB shading (`model::Cell`). */
|
|
629
|
+
interface GigaTableCell {
|
|
630
|
+
blocks: GigaBlock[];
|
|
631
|
+
col_span: number;
|
|
632
|
+
row_span: number;
|
|
633
|
+
/** RGB `0..=1` background, or `null` for no shading. */
|
|
634
|
+
shading: [number, number, number] | null;
|
|
635
|
+
}
|
|
636
|
+
/** A table row: its cells and an optional fixed height in points (`model::Row`). */
|
|
637
|
+
interface GigaTableRow {
|
|
638
|
+
cells: GigaTableCell[];
|
|
639
|
+
height: number | null;
|
|
640
|
+
}
|
|
641
|
+
/** A table/cell border (mirror of `model::BorderStyle`). */
|
|
642
|
+
interface GigaBorderStyle {
|
|
643
|
+
width: number;
|
|
644
|
+
color: [number, number, number];
|
|
645
|
+
}
|
|
646
|
+
/** A table: rows of cells, explicit column widths, and a border (`model::Table`). */
|
|
647
|
+
interface GigaTable {
|
|
648
|
+
rows: GigaTableRow[];
|
|
649
|
+
col_widths: number[];
|
|
650
|
+
border: GigaBorderStyle;
|
|
651
|
+
}
|
|
652
|
+
/** A reference to an image blob in the document's resource table (`model::ImageRef`). */
|
|
653
|
+
interface GigaImageRef {
|
|
654
|
+
/** Content-hash key into `GigaDocument.resources.images`. */
|
|
655
|
+
resource: number;
|
|
656
|
+
alt: string | null;
|
|
657
|
+
}
|
|
658
|
+
/** A single vector path segment (tagged; mirror of `content::vector::PathSeg`). */
|
|
659
|
+
type GigaPathSeg = {
|
|
660
|
+
t: 'm';
|
|
661
|
+
x: number;
|
|
662
|
+
y: number;
|
|
663
|
+
} | {
|
|
664
|
+
t: 'l';
|
|
665
|
+
x: number;
|
|
666
|
+
y: number;
|
|
667
|
+
} | {
|
|
668
|
+
t: 'c';
|
|
669
|
+
x1: number;
|
|
670
|
+
y1: number;
|
|
671
|
+
x2: number;
|
|
672
|
+
y2: number;
|
|
673
|
+
x: number;
|
|
674
|
+
y: number;
|
|
675
|
+
} | {
|
|
676
|
+
t: 'z';
|
|
677
|
+
};
|
|
678
|
+
/** A vector shape: a path with fill/stroke styling (mirror of `model::Shape`). */
|
|
679
|
+
interface GigaShape {
|
|
680
|
+
segments: GigaPathSeg[];
|
|
681
|
+
/** RGB `0..=1` fill, or `null` when unfilled. */
|
|
682
|
+
fill: [number, number, number] | null;
|
|
683
|
+
/** RGB `0..=1` stroke, or `null` when unstroked. */
|
|
684
|
+
stroke: [number, number, number] | null;
|
|
685
|
+
stroke_width: number;
|
|
686
|
+
dash: number[];
|
|
687
|
+
}
|
|
688
|
+
/** A free-floating text box holding a list of blocks (mirror of `model::TextBox`). */
|
|
689
|
+
interface GigaTextBox {
|
|
690
|
+
blocks: GigaBlock[];
|
|
691
|
+
}
|
|
692
|
+
/** A typed spreadsheet cell (mirror of `model::SheetCell`). */
|
|
693
|
+
interface GigaSheetCell {
|
|
694
|
+
value: GigaCellValue;
|
|
695
|
+
number_format: string | null;
|
|
696
|
+
/** RGB `0..=1` cell fill, or `null` for none. */
|
|
697
|
+
fill: [number, number, number] | null;
|
|
698
|
+
style: GigaCharStyle;
|
|
699
|
+
}
|
|
700
|
+
/** One spreadsheet row (mirror of `model::SheetRow`). */
|
|
701
|
+
interface GigaSheetRow {
|
|
702
|
+
cells: GigaSheetCell[];
|
|
703
|
+
}
|
|
704
|
+
/** An inclusive merged-cell rectangle `(r0,c0)..=(r1,c1)`, zero-based. */
|
|
705
|
+
interface GigaMergeRange {
|
|
706
|
+
r0: number;
|
|
707
|
+
c0: number;
|
|
708
|
+
r1: number;
|
|
709
|
+
c1: number;
|
|
710
|
+
}
|
|
711
|
+
/** A single named worksheet (mirror of `model::Sheet`). */
|
|
712
|
+
interface GigaSheet {
|
|
713
|
+
name: string;
|
|
714
|
+
rows: GigaSheetRow[];
|
|
715
|
+
merges: GigaMergeRange[];
|
|
716
|
+
col_widths: number[];
|
|
717
|
+
}
|
|
718
|
+
/** A block of spreadsheet content: one or more sheets (mirror of `model::SheetBlock`). */
|
|
719
|
+
interface GigaSheetBlock {
|
|
720
|
+
sheets: GigaSheet[];
|
|
721
|
+
}
|
|
722
|
+
/** A slide layout placeholder role (tagged; mirror of `model::PlaceholderRole`). */
|
|
723
|
+
type GigaPlaceholderRole = {
|
|
724
|
+
t: 'title';
|
|
725
|
+
} | {
|
|
726
|
+
t: 'subtitle';
|
|
727
|
+
} | {
|
|
728
|
+
t: 'body';
|
|
729
|
+
} | {
|
|
730
|
+
t: 'other';
|
|
731
|
+
v: string;
|
|
500
732
|
};
|
|
501
|
-
/** A
|
|
502
|
-
interface
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
733
|
+
/** A slide placeholder: a block tagged with its semantic role (`model::Placeholder`). */
|
|
734
|
+
interface GigaPlaceholder {
|
|
735
|
+
role: GigaPlaceholderRole;
|
|
736
|
+
block: GigaBlock;
|
|
737
|
+
}
|
|
738
|
+
/** Resolved page size + margins, in points (mirror of `model::geom::PageGeometry`). */
|
|
739
|
+
interface GigaPageGeometry {
|
|
740
|
+
width: number;
|
|
741
|
+
height: number;
|
|
742
|
+
margins: {
|
|
743
|
+
top: number;
|
|
744
|
+
right: number;
|
|
745
|
+
bottom: number;
|
|
746
|
+
left: number;
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
/** A single slide (mirror of `model::Slide`). */
|
|
750
|
+
interface GigaSlide {
|
|
751
|
+
geometry: GigaPageGeometry;
|
|
752
|
+
shapes: GigaBlock[];
|
|
753
|
+
placeholders: GigaPlaceholder[];
|
|
754
|
+
notes: GigaBlock[] | null;
|
|
755
|
+
}
|
|
756
|
+
/** A block of presentation content: an ordered list of slides (`model::SlideBlock`). */
|
|
757
|
+
interface GigaSlideBlock {
|
|
758
|
+
slides: GigaSlide[];
|
|
506
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
* A block payload, **fully typed and discriminated by `t`** (mirror of
|
|
762
|
+
* `model::BlockKind`'s JSON). Narrow on `kind.t` to read the variant body in
|
|
763
|
+
* `kind.v` — e.g. a `paragraph` exposes `v.runs` (each `run` carrying
|
|
764
|
+
* `style.bold`/`style.italic`/`style.size_pt`/`style.color`), a `heading` its
|
|
765
|
+
* `v.level`, a `table` its `v.rows[].cells[]` (with `col_span`/`row_span`), and a
|
|
766
|
+
* `list` its `v.ordered` + `v.items`. This is what lets a thin editor render the
|
|
767
|
+
* recognised structure (bold, headings, tables, lists) 1:1.
|
|
768
|
+
*/
|
|
769
|
+
type GigaBlockKind = {
|
|
770
|
+
t: 'paragraph';
|
|
771
|
+
v: GigaParagraph;
|
|
772
|
+
} | {
|
|
773
|
+
t: 'heading';
|
|
774
|
+
v: GigaHeading;
|
|
775
|
+
} | {
|
|
776
|
+
t: 'list';
|
|
777
|
+
v: GigaList;
|
|
778
|
+
} | {
|
|
779
|
+
t: 'table';
|
|
780
|
+
v: GigaTable;
|
|
781
|
+
} | {
|
|
782
|
+
t: 'image';
|
|
783
|
+
v: GigaImageRef;
|
|
784
|
+
} | {
|
|
785
|
+
t: 'shape';
|
|
786
|
+
v: GigaShape;
|
|
787
|
+
} | {
|
|
788
|
+
t: 'textbox';
|
|
789
|
+
v: GigaTextBox;
|
|
790
|
+
} | {
|
|
791
|
+
t: 'sheet';
|
|
792
|
+
v: GigaSheetBlock;
|
|
793
|
+
} | {
|
|
794
|
+
t: 'slide';
|
|
795
|
+
v: GigaSlideBlock;
|
|
796
|
+
};
|
|
797
|
+
/** Block rotation (tagged; mirror of `model::geom::Rotation`). */
|
|
798
|
+
type GigaRotation = {
|
|
799
|
+
t: 'd0';
|
|
800
|
+
} | {
|
|
801
|
+
t: 'd90';
|
|
802
|
+
} | {
|
|
803
|
+
t: 'd180';
|
|
804
|
+
} | {
|
|
805
|
+
t: 'd270';
|
|
806
|
+
} | {
|
|
807
|
+
t: 'deg';
|
|
808
|
+
v: number;
|
|
809
|
+
};
|
|
507
810
|
/** A block: a stable id, an optional placement frame + rotation, and its kind. */
|
|
508
811
|
interface GigaBlock {
|
|
509
812
|
id: number;
|
|
510
|
-
frame:
|
|
511
|
-
|
|
512
|
-
y: number;
|
|
513
|
-
w: number;
|
|
514
|
-
h: number;
|
|
515
|
-
} | null;
|
|
516
|
-
rotation: {
|
|
517
|
-
t: 'd0' | 'd90' | 'd180' | 'd270' | 'deg';
|
|
518
|
-
v?: number;
|
|
519
|
-
};
|
|
813
|
+
frame: GigaRect | null;
|
|
814
|
+
rotation: GigaRotation;
|
|
520
815
|
kind: GigaBlockKind;
|
|
521
816
|
}
|
|
522
817
|
/** A page: a list of blocks; `absolute` flags slide/form (positioned) layout. */
|
|
@@ -526,20 +821,30 @@ interface GigaPage {
|
|
|
526
821
|
}
|
|
527
822
|
/** A section: one page geometry, optional running header/footer, and its pages. */
|
|
528
823
|
interface GigaSection {
|
|
529
|
-
geometry:
|
|
530
|
-
width: number;
|
|
531
|
-
height: number;
|
|
532
|
-
[k: string]: unknown;
|
|
533
|
-
};
|
|
824
|
+
geometry: GigaPageGeometry;
|
|
534
825
|
header: GigaBlock[] | null;
|
|
535
826
|
footer: GigaBlock[] | null;
|
|
536
827
|
pages: GigaPage[];
|
|
537
828
|
}
|
|
829
|
+
/**
|
|
830
|
+
* A document outline (bookmark) entry — a label, a zero-based destination page,
|
|
831
|
+
* and nested children (mirror of `model::OutlineNode`). Populated by
|
|
832
|
+
* {@link GigaPdf.officeToModel}/reconstruction from the source's own bookmarks
|
|
833
|
+
* (PDF `/Outlines`) or, lacking those, from detected headings.
|
|
834
|
+
*/
|
|
835
|
+
interface GigaOutlineNode {
|
|
836
|
+
/** The bookmark label. */
|
|
837
|
+
title: string;
|
|
838
|
+
/** Zero-based destination page in the document's flattened page sequence. */
|
|
839
|
+
page: number;
|
|
840
|
+
/** Nested sub-bookmarks. */
|
|
841
|
+
children: GigaOutlineNode[];
|
|
842
|
+
}
|
|
538
843
|
/**
|
|
539
844
|
* The unified editable document model — the format-neutral tree every format
|
|
540
845
|
* lowers into and is reconstructed from. `v` is the envelope version. Leaves
|
|
541
|
-
* beyond what a host typically edits (`styles`, `
|
|
542
|
-
*
|
|
846
|
+
* beyond what a host typically edits (`styles`, `resources`) are carried
|
|
847
|
+
* opaquely so a round-trip preserves them.
|
|
543
848
|
*/
|
|
544
849
|
interface GigaDocument {
|
|
545
850
|
v: number;
|
|
@@ -552,7 +857,8 @@ interface GigaDocument {
|
|
|
552
857
|
};
|
|
553
858
|
styles: unknown;
|
|
554
859
|
sections: GigaSection[];
|
|
555
|
-
|
|
860
|
+
/** Bookmark / chapter hierarchy (empty when the source has none). */
|
|
861
|
+
outline: GigaOutlineNode[];
|
|
556
862
|
resources: unknown;
|
|
557
863
|
}
|
|
558
864
|
/**
|
|
@@ -575,6 +881,31 @@ interface GigaStylePatch {
|
|
|
575
881
|
strike?: boolean;
|
|
576
882
|
color?: [number, number, number] | null;
|
|
577
883
|
}
|
|
884
|
+
/**
|
|
885
|
+
* A paragraph-style patch for {@link ModelOp} `setParagraphStyle`: only the
|
|
886
|
+
* present fields are applied (mirror of `model::edit::ParaPatch`). Keys are the
|
|
887
|
+
* op's short names (`indent_left`, not `indent_left_pt`); values in PDF points.
|
|
888
|
+
* Omitting a field leaves the existing value unchanged.
|
|
889
|
+
*/
|
|
890
|
+
interface GigaParaPatch {
|
|
891
|
+
align?: 'left' | 'center' | 'right' | 'justify';
|
|
892
|
+
indent_left?: number;
|
|
893
|
+
indent_right?: number;
|
|
894
|
+
/** First-line indent (positive) or hanging indent (negative), in points. */
|
|
895
|
+
first_line?: number;
|
|
896
|
+
space_before?: number;
|
|
897
|
+
space_after?: number;
|
|
898
|
+
/** Leading policy: font-natural, a size multiple, or a fixed point value. */
|
|
899
|
+
line_height?: {
|
|
900
|
+
t: 'normal';
|
|
901
|
+
} | {
|
|
902
|
+
t: 'multiple';
|
|
903
|
+
v: number;
|
|
904
|
+
} | {
|
|
905
|
+
t: 'points';
|
|
906
|
+
v: number;
|
|
907
|
+
};
|
|
908
|
+
}
|
|
578
909
|
/** A typed spreadsheet cell value (tagged; mirror of `model::CellValue`). */
|
|
579
910
|
type GigaCellValue = {
|
|
580
911
|
t: 'empty';
|
|
@@ -646,6 +977,101 @@ type ModelOp = {
|
|
|
646
977
|
row: number;
|
|
647
978
|
col: number;
|
|
648
979
|
value: GigaCellValue;
|
|
980
|
+
} | {
|
|
981
|
+
op: 'insertTableRow';
|
|
982
|
+
addr: GigaBlockAddr;
|
|
983
|
+
at: number;
|
|
984
|
+
} | {
|
|
985
|
+
op: 'deleteTableRow';
|
|
986
|
+
addr: GigaBlockAddr;
|
|
987
|
+
at: number;
|
|
988
|
+
} | {
|
|
989
|
+
op: 'insertTableColumn';
|
|
990
|
+
addr: GigaBlockAddr;
|
|
991
|
+
at: number;
|
|
992
|
+
} | {
|
|
993
|
+
op: 'deleteTableColumn';
|
|
994
|
+
addr: GigaBlockAddr;
|
|
995
|
+
at: number;
|
|
996
|
+
} | {
|
|
997
|
+
op: 'setCellSpan';
|
|
998
|
+
addr: GigaBlockAddr;
|
|
999
|
+
/** Row index in `rows`. */
|
|
1000
|
+
row: number;
|
|
1001
|
+
/** Cell index in `rows[row].cells` (not a grid column). */
|
|
1002
|
+
col: number;
|
|
1003
|
+
/** Columns the cell spans (clamped to ≥ 1). */
|
|
1004
|
+
col_span: number;
|
|
1005
|
+
/** Rows the cell spans (clamped to ≥ 1). */
|
|
1006
|
+
row_span: number;
|
|
1007
|
+
} | {
|
|
1008
|
+
op: 'insertSheetRow';
|
|
1009
|
+
addr: GigaBlockAddr;
|
|
1010
|
+
sheet: number;
|
|
1011
|
+
at: number;
|
|
1012
|
+
} | {
|
|
1013
|
+
op: 'deleteSheetRow';
|
|
1014
|
+
addr: GigaBlockAddr;
|
|
1015
|
+
sheet: number;
|
|
1016
|
+
at: number;
|
|
1017
|
+
} | {
|
|
1018
|
+
op: 'insertSheetColumn';
|
|
1019
|
+
addr: GigaBlockAddr;
|
|
1020
|
+
sheet: number;
|
|
1021
|
+
at: number;
|
|
1022
|
+
} | {
|
|
1023
|
+
op: 'deleteSheetColumn';
|
|
1024
|
+
addr: GigaBlockAddr;
|
|
1025
|
+
sheet: number;
|
|
1026
|
+
at: number;
|
|
1027
|
+
} | {
|
|
1028
|
+
op: 'setParagraphStyle';
|
|
1029
|
+
addr: GigaBlockAddr;
|
|
1030
|
+
patch: GigaParaPatch;
|
|
1031
|
+
} | {
|
|
1032
|
+
op: 'setListLevel';
|
|
1033
|
+
addr: GigaBlockAddr;
|
|
1034
|
+
level: number;
|
|
1035
|
+
} | {
|
|
1036
|
+
op: 'setListMarker';
|
|
1037
|
+
addr: GigaBlockAddr;
|
|
1038
|
+
marker: GigaListMarker;
|
|
1039
|
+
} | {
|
|
1040
|
+
op: 'setListOrdered';
|
|
1041
|
+
addr: GigaBlockAddr;
|
|
1042
|
+
ordered: boolean;
|
|
1043
|
+
} | {
|
|
1044
|
+
op: 'setBlockFrame';
|
|
1045
|
+
addr: GigaBlockAddr;
|
|
1046
|
+
rect: GigaRect;
|
|
1047
|
+
}
|
|
1048
|
+
/** `deg` is CCW; 0/90/180/270 snap to exact rotations, else an arbitrary angle. */
|
|
1049
|
+
| {
|
|
1050
|
+
op: 'setBlockRotation';
|
|
1051
|
+
addr: GigaBlockAddr;
|
|
1052
|
+
deg: number;
|
|
1053
|
+
}
|
|
1054
|
+
/** `color: null` clears the cell's shading; a triple sets it. */
|
|
1055
|
+
| {
|
|
1056
|
+
op: 'setCellShading';
|
|
1057
|
+
addr: GigaBlockAddr;
|
|
1058
|
+
row: number;
|
|
1059
|
+
col: number;
|
|
1060
|
+
color: [number, number, number] | null;
|
|
1061
|
+
} | {
|
|
1062
|
+
op: 'setRowHeight';
|
|
1063
|
+
addr: GigaBlockAddr;
|
|
1064
|
+
row: number;
|
|
1065
|
+
height: number;
|
|
1066
|
+
} | {
|
|
1067
|
+
op: 'setColWidth';
|
|
1068
|
+
addr: GigaBlockAddr;
|
|
1069
|
+
col: number;
|
|
1070
|
+
width: number;
|
|
1071
|
+
} | {
|
|
1072
|
+
op: 'setTableBorder';
|
|
1073
|
+
addr: GigaBlockAddr;
|
|
1074
|
+
border: GigaBorderStyle;
|
|
649
1075
|
};
|
|
650
1076
|
/**
|
|
651
1077
|
* An image element from {@link GigaPdfDoc.imageElements}: its placement box
|
|
@@ -1323,6 +1749,15 @@ declare class GigaPdfDoc {
|
|
|
1323
1749
|
saveEncrypted(password: string, fileId: string, opts?: {
|
|
1324
1750
|
ownerPassword?: string;
|
|
1325
1751
|
algorithm?: "rc4" | "aes128" | "aes256";
|
|
1752
|
+
/**
|
|
1753
|
+
* Named access permissions (ISO 32000-1 Table 22). Omitted flags default
|
|
1754
|
+
* to **granted**. Takes precedence over `permissions` when present.
|
|
1755
|
+
*/
|
|
1756
|
+
flags?: Partial<PdfPermissions>;
|
|
1757
|
+
/**
|
|
1758
|
+
* Raw signed 32-bit `/P` bitmask. Use {@link flags} for a readable API.
|
|
1759
|
+
* Defaults to all permissions granted when neither is given.
|
|
1760
|
+
*/
|
|
1326
1761
|
permissions?: number;
|
|
1327
1762
|
keySeed?: Uint8Array;
|
|
1328
1763
|
}): Uint8Array;
|
|
@@ -1485,4 +1920,4 @@ declare class GigaPdfDoc {
|
|
|
1485
1920
|
}): boolean;
|
|
1486
1921
|
}
|
|
1487
1922
|
|
|
1488
|
-
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 };
|
|
1923
|
+
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 GigaParaPatch, 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 PdfPermissions, type RadioOption, type SearchHit, type SignP12Options, type TextElementInfo, type TextLine, type TextRunInfo, type VectorPathInfo, type XlsxSheet };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
import { loadDefaultWasmBytes } from "./node-fs.js";
|
|
3
3
|
var enc = new TextEncoder();
|
|
4
4
|
var dec = new TextDecoder();
|
|
5
|
+
var ALL_PERMISSIONS = {
|
|
6
|
+
print: true,
|
|
7
|
+
modify: true,
|
|
8
|
+
copy: true,
|
|
9
|
+
annotate: true,
|
|
10
|
+
fillForms: true,
|
|
11
|
+
accessibility: true,
|
|
12
|
+
assemble: true,
|
|
13
|
+
printHighRes: true
|
|
14
|
+
};
|
|
5
15
|
var GigaPdfEngine = class _GigaPdfEngine {
|
|
6
16
|
constructor(ex) {
|
|
7
17
|
this.ex = ex;
|
|
@@ -218,6 +228,43 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
218
228
|
);
|
|
219
229
|
return JSON.parse(dec.decode(json));
|
|
220
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Decode the eight access-permission flags from a `/P` permission bitmask
|
|
233
|
+
* (ISO 32000-1 Table 22) into named booleans (`true` = the action is
|
|
234
|
+
* granted). Reserved bits are ignored.
|
|
235
|
+
*/
|
|
236
|
+
decodePermissions(p) {
|
|
237
|
+
const json = dec.decode(this._buffer((o) => this.ex.gp_permissions_from_p(p, o)));
|
|
238
|
+
return JSON.parse(json);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Read a PDF's access permissions **without decrypting it** (no password
|
|
242
|
+
* needed). Returns the eight named flags decoded from the `/Encrypt`
|
|
243
|
+
* dictionary's `/P`; an unencrypted document grants everything.
|
|
244
|
+
*/
|
|
245
|
+
getPermissions(pdf) {
|
|
246
|
+
const { encrypted, permissions } = this.encryptionInfo(pdf);
|
|
247
|
+
return encrypted ? this.decodePermissions(permissions) : { ...ALL_PERMISSIONS };
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Pack eight access-permission flags into a signed 32-bit `/P` value
|
|
251
|
+
* (ISO 32000-1 Table 22). Omitted flags default to **granted**, so an empty
|
|
252
|
+
* object means "all allowed". Feed the result to {@link GigaPdfDoc.saveEncrypted}
|
|
253
|
+
* via `opts.permissions`, or pass `opts.flags` directly.
|
|
254
|
+
*/
|
|
255
|
+
permissionsToP(flags = {}) {
|
|
256
|
+
const f = { ...ALL_PERMISSIONS, ...flags };
|
|
257
|
+
return this.ex.gp_permissions_to_p(
|
|
258
|
+
f.print ? 1 : 0,
|
|
259
|
+
f.modify ? 1 : 0,
|
|
260
|
+
f.copy ? 1 : 0,
|
|
261
|
+
f.annotate ? 1 : 0,
|
|
262
|
+
f.fillForms ? 1 : 0,
|
|
263
|
+
f.accessibility ? 1 : 0,
|
|
264
|
+
f.assemble ? 1 : 0,
|
|
265
|
+
f.printHighRes ? 1 : 0
|
|
266
|
+
);
|
|
267
|
+
}
|
|
221
268
|
/**
|
|
222
269
|
* Width of `text` set in standard Helvetica at `size` points (AFM metrics) —
|
|
223
270
|
* place watermark/header text without embedding a font.
|
|
@@ -1500,7 +1547,7 @@ var GigaPdfDoc = class {
|
|
|
1500
1547
|
saveEncrypted(password, fileId, opts = {}) {
|
|
1501
1548
|
const algo = opts.algorithm ?? "aes256";
|
|
1502
1549
|
const algoCode = algo === "rc4" ? 0 : algo === "aes128" ? 1 : 2;
|
|
1503
|
-
const permissions = opts.permissions ??
|
|
1550
|
+
const permissions = opts.flags !== void 0 ? this.g.permissionsToP(opts.flags) : opts.permissions ?? this.g.permissionsToP();
|
|
1504
1551
|
let key = opts.keySeed ?? new Uint8Array(0);
|
|
1505
1552
|
if (algoCode === 2 && key.length < 32) {
|
|
1506
1553
|
const c = globalThis.crypto;
|