@qrcommunication/gigapdf-lib 0.56.0 → 0.57.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 +29 -0
- package/README.md +3 -1
- package/dist/index.cjs +41 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -1
- package/gigapdf.wasm +0 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -664,6 +664,13 @@ type ModelOp = {
|
|
|
664
664
|
* and the source pixel dimensions. `data` is empty when `format` is `"unknown"`.
|
|
665
665
|
*/
|
|
666
666
|
interface ImageElementInfo {
|
|
667
|
+
/**
|
|
668
|
+
* The image's **unified element index** — the same value accepted by
|
|
669
|
+
* {@link GigaPdfDoc.removeElement} / {@link GigaPdfDoc.transformElement} /
|
|
670
|
+
* {@link GigaPdfDoc.duplicateElement} / {@link GigaPdfDoc.moveElement}. Extract
|
|
671
|
+
* an image here and pass this index to edit *that exact* image. It is **not** an
|
|
672
|
+
* image-local 0,1,2 counter, so it is correct on pages that also have text/paths.
|
|
673
|
+
*/
|
|
667
674
|
index: number;
|
|
668
675
|
x: number;
|
|
669
676
|
y: number;
|
|
@@ -697,6 +704,13 @@ interface PathSegment {
|
|
|
697
704
|
* paths are omitted. The native equivalent of a reader's shape/vector layer.
|
|
698
705
|
*/
|
|
699
706
|
interface VectorPathInfo {
|
|
707
|
+
/**
|
|
708
|
+
* The path's **unified element index** — the same value accepted by
|
|
709
|
+
* {@link GigaPdfDoc.setPathStyle} / {@link GigaPdfDoc.removeElement} /
|
|
710
|
+
* {@link GigaPdfDoc.transformElement}. Extract a path here and pass this index
|
|
711
|
+
* to restyle or remove *that exact* path. Clip-only paths are not reported, so
|
|
712
|
+
* the painted path you see is the one your index targets — not a path-local ordinal.
|
|
713
|
+
*/
|
|
700
714
|
index: number;
|
|
701
715
|
/** Whether `x0..y1` describe a real box (`false` for a degenerate path). */
|
|
702
716
|
hasBounds: boolean;
|
|
@@ -977,6 +991,10 @@ declare class GigaPdfDoc {
|
|
|
977
991
|
* `unknown`), and the source pixel dimensions. DCTDecode/JPXDecode images pass
|
|
978
992
|
* through as jpeg/jp2; Flate/raw DeviceRGB|DeviceGray are re-encoded to PNG.
|
|
979
993
|
* The native replacement for a reader's image extraction (bytes + placement).
|
|
994
|
+
*
|
|
995
|
+
* Each result's `index` is the **unified element index** usable directly with
|
|
996
|
+
* {@link removeElement} / {@link transformElement} / {@link duplicateElement} /
|
|
997
|
+
* {@link moveElement} — so you can extract an image and edit *that exact* image.
|
|
980
998
|
*/
|
|
981
999
|
imageElements(page: number): ImageElementInfo[];
|
|
982
1000
|
/**
|
|
@@ -985,6 +1003,10 @@ declare class GigaPdfDoc {
|
|
|
985
1003
|
* fill/stroke RGB, line width, alpha and dash. Clip-only paths are omitted.
|
|
986
1004
|
* The native replacement for walking a reader's operator list to rebuild the
|
|
987
1005
|
* shape layer.
|
|
1006
|
+
*
|
|
1007
|
+
* Each result's `index` is the **unified element index** usable directly with
|
|
1008
|
+
* {@link setPathStyle} / {@link removeElement} / {@link transformElement} — so
|
|
1009
|
+
* you can extract a path and restyle/remove *that exact* path.
|
|
988
1010
|
*/
|
|
989
1011
|
vectorPaths(page: number): VectorPathInfo[];
|
|
990
1012
|
structuredText(page: number): TextLine[];
|
|
@@ -1001,6 +1023,39 @@ declare class GigaPdfDoc {
|
|
|
1001
1023
|
replaceText(page: number, index: number, text: string): boolean;
|
|
1002
1024
|
removeElement(page: number, index: number): boolean;
|
|
1003
1025
|
moveElement(page: number, index: number, dx: number, dy: number): boolean;
|
|
1026
|
+
/**
|
|
1027
|
+
* Apply a full affine transform to element `index` on `page`, wrapping it in
|
|
1028
|
+
* `q … cm … Q` with the matrix `m = [a, b, c, d, e, f]`. This **generalises**
|
|
1029
|
+
* {@link moveElement} (whose matrix is the pure translate `[1,0,0,1,dx,dy]`)
|
|
1030
|
+
* to scale, rotation, shear and translation in one call. Because it is purely
|
|
1031
|
+
* matrix-based it works identically for text, images and shapes — their
|
|
1032
|
+
* internal coordinates are never touched. Returns `false` if the element/page
|
|
1033
|
+
* doesn't exist.
|
|
1034
|
+
*/
|
|
1035
|
+
transformElement(page: number, index: number, m: [number, number, number, number, number, number]): boolean;
|
|
1036
|
+
/**
|
|
1037
|
+
* Re-style the **path** element `index` on `page` in place: any provided field
|
|
1038
|
+
* overrides that part of the graphics state for the path's paint; omitted
|
|
1039
|
+
* fields keep the inherited state. Implemented by wrapping the path's op range
|
|
1040
|
+
* in `q … Q` and injecting the requested state operators (`rg`/`RG`/`w`/`d`)
|
|
1041
|
+
* before its construction + paint ops, so the original paint op now draws with
|
|
1042
|
+
* the override and following content is unaffected. RGB colours are `[r,g,b]`
|
|
1043
|
+
* in `0..=1`; `dash` is the PDF dash array (`[]` = solid). Returns `false` if
|
|
1044
|
+
* the element is not a path (or the page/index doesn't exist).
|
|
1045
|
+
*
|
|
1046
|
+
* Opacity note: `fillAlpha`/`strokeAlpha` are accepted for API symmetry but
|
|
1047
|
+
* are **not** emitted — PDF opacity needs a named `/ExtGState`, which a pure
|
|
1048
|
+
* content-stream edit cannot create. Use the resource-level shape APIs when
|
|
1049
|
+
* opacity is required.
|
|
1050
|
+
*/
|
|
1051
|
+
setPathStyle(page: number, index: number, style: {
|
|
1052
|
+
fill?: [number, number, number];
|
|
1053
|
+
stroke?: [number, number, number];
|
|
1054
|
+
strokeWidth?: number;
|
|
1055
|
+
fillAlpha?: number;
|
|
1056
|
+
strokeAlpha?: number;
|
|
1057
|
+
dash?: number[];
|
|
1058
|
+
}): boolean;
|
|
1004
1059
|
duplicateElement(page: number, index: number): boolean;
|
|
1005
1060
|
/** Index of the element at page point `(x, y)`, or -1 if none. */
|
|
1006
1061
|
elementAt(page: number, x: number, y: number): number;
|
package/dist/index.d.ts
CHANGED
|
@@ -664,6 +664,13 @@ type ModelOp = {
|
|
|
664
664
|
* and the source pixel dimensions. `data` is empty when `format` is `"unknown"`.
|
|
665
665
|
*/
|
|
666
666
|
interface ImageElementInfo {
|
|
667
|
+
/**
|
|
668
|
+
* The image's **unified element index** — the same value accepted by
|
|
669
|
+
* {@link GigaPdfDoc.removeElement} / {@link GigaPdfDoc.transformElement} /
|
|
670
|
+
* {@link GigaPdfDoc.duplicateElement} / {@link GigaPdfDoc.moveElement}. Extract
|
|
671
|
+
* an image here and pass this index to edit *that exact* image. It is **not** an
|
|
672
|
+
* image-local 0,1,2 counter, so it is correct on pages that also have text/paths.
|
|
673
|
+
*/
|
|
667
674
|
index: number;
|
|
668
675
|
x: number;
|
|
669
676
|
y: number;
|
|
@@ -697,6 +704,13 @@ interface PathSegment {
|
|
|
697
704
|
* paths are omitted. The native equivalent of a reader's shape/vector layer.
|
|
698
705
|
*/
|
|
699
706
|
interface VectorPathInfo {
|
|
707
|
+
/**
|
|
708
|
+
* The path's **unified element index** — the same value accepted by
|
|
709
|
+
* {@link GigaPdfDoc.setPathStyle} / {@link GigaPdfDoc.removeElement} /
|
|
710
|
+
* {@link GigaPdfDoc.transformElement}. Extract a path here and pass this index
|
|
711
|
+
* to restyle or remove *that exact* path. Clip-only paths are not reported, so
|
|
712
|
+
* the painted path you see is the one your index targets — not a path-local ordinal.
|
|
713
|
+
*/
|
|
700
714
|
index: number;
|
|
701
715
|
/** Whether `x0..y1` describe a real box (`false` for a degenerate path). */
|
|
702
716
|
hasBounds: boolean;
|
|
@@ -977,6 +991,10 @@ declare class GigaPdfDoc {
|
|
|
977
991
|
* `unknown`), and the source pixel dimensions. DCTDecode/JPXDecode images pass
|
|
978
992
|
* through as jpeg/jp2; Flate/raw DeviceRGB|DeviceGray are re-encoded to PNG.
|
|
979
993
|
* The native replacement for a reader's image extraction (bytes + placement).
|
|
994
|
+
*
|
|
995
|
+
* Each result's `index` is the **unified element index** usable directly with
|
|
996
|
+
* {@link removeElement} / {@link transformElement} / {@link duplicateElement} /
|
|
997
|
+
* {@link moveElement} — so you can extract an image and edit *that exact* image.
|
|
980
998
|
*/
|
|
981
999
|
imageElements(page: number): ImageElementInfo[];
|
|
982
1000
|
/**
|
|
@@ -985,6 +1003,10 @@ declare class GigaPdfDoc {
|
|
|
985
1003
|
* fill/stroke RGB, line width, alpha and dash. Clip-only paths are omitted.
|
|
986
1004
|
* The native replacement for walking a reader's operator list to rebuild the
|
|
987
1005
|
* shape layer.
|
|
1006
|
+
*
|
|
1007
|
+
* Each result's `index` is the **unified element index** usable directly with
|
|
1008
|
+
* {@link setPathStyle} / {@link removeElement} / {@link transformElement} — so
|
|
1009
|
+
* you can extract a path and restyle/remove *that exact* path.
|
|
988
1010
|
*/
|
|
989
1011
|
vectorPaths(page: number): VectorPathInfo[];
|
|
990
1012
|
structuredText(page: number): TextLine[];
|
|
@@ -1001,6 +1023,39 @@ declare class GigaPdfDoc {
|
|
|
1001
1023
|
replaceText(page: number, index: number, text: string): boolean;
|
|
1002
1024
|
removeElement(page: number, index: number): boolean;
|
|
1003
1025
|
moveElement(page: number, index: number, dx: number, dy: number): boolean;
|
|
1026
|
+
/**
|
|
1027
|
+
* Apply a full affine transform to element `index` on `page`, wrapping it in
|
|
1028
|
+
* `q … cm … Q` with the matrix `m = [a, b, c, d, e, f]`. This **generalises**
|
|
1029
|
+
* {@link moveElement} (whose matrix is the pure translate `[1,0,0,1,dx,dy]`)
|
|
1030
|
+
* to scale, rotation, shear and translation in one call. Because it is purely
|
|
1031
|
+
* matrix-based it works identically for text, images and shapes — their
|
|
1032
|
+
* internal coordinates are never touched. Returns `false` if the element/page
|
|
1033
|
+
* doesn't exist.
|
|
1034
|
+
*/
|
|
1035
|
+
transformElement(page: number, index: number, m: [number, number, number, number, number, number]): boolean;
|
|
1036
|
+
/**
|
|
1037
|
+
* Re-style the **path** element `index` on `page` in place: any provided field
|
|
1038
|
+
* overrides that part of the graphics state for the path's paint; omitted
|
|
1039
|
+
* fields keep the inherited state. Implemented by wrapping the path's op range
|
|
1040
|
+
* in `q … Q` and injecting the requested state operators (`rg`/`RG`/`w`/`d`)
|
|
1041
|
+
* before its construction + paint ops, so the original paint op now draws with
|
|
1042
|
+
* the override and following content is unaffected. RGB colours are `[r,g,b]`
|
|
1043
|
+
* in `0..=1`; `dash` is the PDF dash array (`[]` = solid). Returns `false` if
|
|
1044
|
+
* the element is not a path (or the page/index doesn't exist).
|
|
1045
|
+
*
|
|
1046
|
+
* Opacity note: `fillAlpha`/`strokeAlpha` are accepted for API symmetry but
|
|
1047
|
+
* are **not** emitted — PDF opacity needs a named `/ExtGState`, which a pure
|
|
1048
|
+
* content-stream edit cannot create. Use the resource-level shape APIs when
|
|
1049
|
+
* opacity is required.
|
|
1050
|
+
*/
|
|
1051
|
+
setPathStyle(page: number, index: number, style: {
|
|
1052
|
+
fill?: [number, number, number];
|
|
1053
|
+
stroke?: [number, number, number];
|
|
1054
|
+
strokeWidth?: number;
|
|
1055
|
+
fillAlpha?: number;
|
|
1056
|
+
strokeAlpha?: number;
|
|
1057
|
+
dash?: number[];
|
|
1058
|
+
}): boolean;
|
|
1004
1059
|
duplicateElement(page: number, index: number): boolean;
|
|
1005
1060
|
/** Index of the element at page point `(x, y)`, or -1 if none. */
|
|
1006
1061
|
elementAt(page: number, x: number, y: number): number;
|
package/dist/index.js
CHANGED
|
@@ -891,6 +891,10 @@ var GigaPdfDoc = class {
|
|
|
891
891
|
* `unknown`), and the source pixel dimensions. DCTDecode/JPXDecode images pass
|
|
892
892
|
* through as jpeg/jp2; Flate/raw DeviceRGB|DeviceGray are re-encoded to PNG.
|
|
893
893
|
* The native replacement for a reader's image extraction (bytes + placement).
|
|
894
|
+
*
|
|
895
|
+
* Each result's `index` is the **unified element index** usable directly with
|
|
896
|
+
* {@link removeElement} / {@link transformElement} / {@link duplicateElement} /
|
|
897
|
+
* {@link moveElement} — so you can extract an image and edit *that exact* image.
|
|
894
898
|
*/
|
|
895
899
|
imageElements(page) {
|
|
896
900
|
const raw = this.g._json(
|
|
@@ -907,6 +911,10 @@ var GigaPdfDoc = class {
|
|
|
907
911
|
* fill/stroke RGB, line width, alpha and dash. Clip-only paths are omitted.
|
|
908
912
|
* The native replacement for walking a reader's operator list to rebuild the
|
|
909
913
|
* shape layer.
|
|
914
|
+
*
|
|
915
|
+
* Each result's `index` is the **unified element index** usable directly with
|
|
916
|
+
* {@link setPathStyle} / {@link removeElement} / {@link transformElement} — so
|
|
917
|
+
* you can extract a path and restyle/remove *that exact* path.
|
|
910
918
|
*/
|
|
911
919
|
vectorPaths(page) {
|
|
912
920
|
return this.g._json((o) => this.ex().gp_vector_paths_json(this.h, page, o));
|
|
@@ -943,6 +951,39 @@ var GigaPdfDoc = class {
|
|
|
943
951
|
moveElement(page, index, dx, dy) {
|
|
944
952
|
return this.ex().gp_move_element(this.h, page, index, dx, dy) === 0;
|
|
945
953
|
}
|
|
954
|
+
/**
|
|
955
|
+
* Apply a full affine transform to element `index` on `page`, wrapping it in
|
|
956
|
+
* `q … cm … Q` with the matrix `m = [a, b, c, d, e, f]`. This **generalises**
|
|
957
|
+
* {@link moveElement} (whose matrix is the pure translate `[1,0,0,1,dx,dy]`)
|
|
958
|
+
* to scale, rotation, shear and translation in one call. Because it is purely
|
|
959
|
+
* matrix-based it works identically for text, images and shapes — their
|
|
960
|
+
* internal coordinates are never touched. Returns `false` if the element/page
|
|
961
|
+
* doesn't exist.
|
|
962
|
+
*/
|
|
963
|
+
transformElement(page, index, m) {
|
|
964
|
+
return this.ex().gp_transform_element(this.h, page, index, m[0], m[1], m[2], m[3], m[4], m[5]) === 0;
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Re-style the **path** element `index` on `page` in place: any provided field
|
|
968
|
+
* overrides that part of the graphics state for the path's paint; omitted
|
|
969
|
+
* fields keep the inherited state. Implemented by wrapping the path's op range
|
|
970
|
+
* in `q … Q` and injecting the requested state operators (`rg`/`RG`/`w`/`d`)
|
|
971
|
+
* before its construction + paint ops, so the original paint op now draws with
|
|
972
|
+
* the override and following content is unaffected. RGB colours are `[r,g,b]`
|
|
973
|
+
* in `0..=1`; `dash` is the PDF dash array (`[]` = solid). Returns `false` if
|
|
974
|
+
* the element is not a path (or the page/index doesn't exist).
|
|
975
|
+
*
|
|
976
|
+
* Opacity note: `fillAlpha`/`strokeAlpha` are accepted for API symmetry but
|
|
977
|
+
* are **not** emitted — PDF opacity needs a named `/ExtGState`, which a pure
|
|
978
|
+
* content-stream edit cannot create. Use the resource-level shape APIs when
|
|
979
|
+
* opacity is required.
|
|
980
|
+
*/
|
|
981
|
+
setPathStyle(page, index, style) {
|
|
982
|
+
return this.g._withStr(
|
|
983
|
+
JSON.stringify(style),
|
|
984
|
+
(p, l) => this.ex().gp_set_path_style_json(this.h, page, index, p, l)
|
|
985
|
+
) === 0;
|
|
986
|
+
}
|
|
946
987
|
duplicateElement(page, index) {
|
|
947
988
|
return this.ex().gp_duplicate_element(this.h, page, index) === 0;
|
|
948
989
|
}
|