@qrcommunication/gigapdf-lib 0.56.0 → 0.58.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 +78 -0
- package/README.md +8 -2
- package/dist/index.cjs +84 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -1
- package/gigapdf.wasm +0 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,84 @@ 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.58.0] - 2026-06-21
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **`setElementOpacity(page, index, fillAlpha)` — constant opacity on *any*
|
|
12
|
+
element.** Sets a single transparency value on a text, image **or** shape
|
|
13
|
+
element in place by registering a page `/ExtGState` (`/ca` = `/CA` =
|
|
14
|
+
`fillAlpha`, clamped to `0..=1`, auto-named `GpGs<n>`) and wrapping the
|
|
15
|
+
element's op range in `q /<gs> gs … Q`, so the alpha applies to that run only
|
|
16
|
+
and following content is unaffected. This is the way to set an **image**'s
|
|
17
|
+
opacity in place; shapes may use either this or `setPathStyle`'s `fillAlpha` /
|
|
18
|
+
`strokeAlpha` (same underlying `/ExtGState` mechanism — the difference is that
|
|
19
|
+
`setElementOpacity` uses one value for both `/ca` and `/CA`, while `setPathStyle`
|
|
20
|
+
can set fill and stroke alpha independently). New ABI
|
|
21
|
+
`gp_set_element_opacity(handle, page, index, fill_alpha)` and core
|
|
22
|
+
`Document::set_element_opacity` / `content::set_element_opacity`. Returns
|
|
23
|
+
`false` for a missing page/index.
|
|
24
|
+
- **`reorderElement(page, index, toFront)` — native PDF stacking order.** Changes
|
|
25
|
+
an element's paint (z) order by splicing its op range to the **end** of the
|
|
26
|
+
content stream (`toFront = true` → painted last, on top) or to the **start**
|
|
27
|
+
(`toFront = false` → painted first, behind everything). The moved range is
|
|
28
|
+
re-wrapped in `q … Q` so it neither inherits nor leaks graphics state; works for
|
|
29
|
+
text, image and shape elements. **The element's unified index changes after the
|
|
30
|
+
splice — re-read `pageElements`.** New ABI `gp_reorder_element(handle, page,
|
|
31
|
+
index, to_front)` and core `Document::reorder_element` /
|
|
32
|
+
`content::reorder_element`. Returns `false` for a missing page/index.
|
|
33
|
+
- **`renderPageExcluding(page, indices, scale?)` — rasterise a page minus given
|
|
34
|
+
elements.** Rasterises a page to PNG while **omitting** the listed top-level
|
|
35
|
+
unified element `indices` (from `pageElements`) — each excluded element paints
|
|
36
|
+
nothing (fills, strokes, shadings, images and text alike) while all
|
|
37
|
+
non-excluded content renders normally. Generalises `renderPageNoText` (which
|
|
38
|
+
suppresses *all* text); an empty `indices` renders the full page and unknown
|
|
39
|
+
indices are ignored. Built for live-overlay editing — paint a background
|
|
40
|
+
without the element currently being edited, then overlay an editable version on
|
|
41
|
+
top. Native rasteriser, no third-party image library. New ABI
|
|
42
|
+
`gp_render_page_excluding(handle, page, indices_ptr, indices_len, scale,
|
|
43
|
+
out_len)` and core `Document::render_page_excluding`, alongside the unchanged
|
|
44
|
+
`renderPage` / `renderPageNoText`.
|
|
45
|
+
|
|
46
|
+
### Changed
|
|
47
|
+
|
|
48
|
+
- **`setPathStyle` opacity is now real.** `fillAlpha` / `strokeAlpha` (`0..=1`)
|
|
49
|
+
are now **fully applied** (previously accepted for API symmetry but a no-op):
|
|
50
|
+
the engine registers an `/ExtGState` carrying `/ca` / `/CA` on the page and
|
|
51
|
+
injects a `/<gs> gs` into the path's `q … Q` wrap, so the alpha applies to that
|
|
52
|
+
path run only. The earlier "opacity not applied — needs an `/ExtGState`"
|
|
53
|
+
limitation no longer holds. For non-path elements (e.g. images) use
|
|
54
|
+
`setElementOpacity`.
|
|
55
|
+
|
|
56
|
+
## [0.57.0] - 2026-06-21
|
|
57
|
+
|
|
58
|
+
### Added
|
|
59
|
+
|
|
60
|
+
- **`transformElement(page, index, m)` — full affine transform of an element in
|
|
61
|
+
place.** Generalises `moveElement` (a translate-only `[1,0,0,1,dx,dy]` matrix)
|
|
62
|
+
to a complete PDF affine matrix `m = [a, b, c, d, e, f]` — scale, rotate, shear
|
|
63
|
+
and translate — so an element can be moved **and** resized **and** rotated in a
|
|
64
|
+
single call. Non-destructive: the element is wrapped in `q a b c d e f cm …
|
|
65
|
+
Q`, so its internal coordinates are never rewritten and it behaves identically
|
|
66
|
+
for text, images and shapes. New ABI `gp_transform_element(handle, page, index,
|
|
67
|
+
a, b, c, d, e, f)` and core `Document::transform_element` /
|
|
68
|
+
`content::transform_element`, alongside the existing `moveElement` /
|
|
69
|
+
`gp_move_element` (kept). Returns `false` for a missing page/element.
|
|
70
|
+
- **`setPathStyle(page, index, style)` — in-place vector restyle.** Re-styles a
|
|
71
|
+
**path** element (returns `false` for a non-path index) without touching its
|
|
72
|
+
geometry: the path's op range is wrapped in `q … Q` and, for each provided
|
|
73
|
+
field, an override operator is injected before the paint op — `fill`→`r g b rg`,
|
|
74
|
+
`stroke`→`r g b RG`, `strokeWidth`→`w`, `dash`→`[…] 0 d`; omitted fields keep
|
|
75
|
+
the inherited graphics state. `style = { fill?, stroke?, strokeWidth?,
|
|
76
|
+
fillAlpha?, strokeAlpha?, dash? }`; colours are RGB `[r,g,b]` in `0..=1` and
|
|
77
|
+
`dash` is the PDF dash array (`[]` = solid). New ABI
|
|
78
|
+
`gp_set_path_style_json(handle, page, index, json_ptr, json_len)` and core
|
|
79
|
+
`content::set_path_style` + `PathStyle` / `Document::set_path_style`. **Note:**
|
|
80
|
+
`fillAlpha` / `strokeAlpha` are accepted for API symmetry but are **not**
|
|
81
|
+
applied — PDF opacity requires a named `/ExtGState` resource, which a pure
|
|
82
|
+
content-stream edit cannot create; use the resource-level shape APIs (whose
|
|
83
|
+
`opacity` argument allocates the `/ExtGState`) when real transparency is needed.
|
|
84
|
+
|
|
7
85
|
## [0.56.0] - 2026-06-21
|
|
8
86
|
|
|
9
87
|
### Added
|
package/README.md
CHANGED
|
@@ -271,13 +271,19 @@ Or call `GigaPdfEngine.load(bytes)` with bytes you read yourself.
|
|
|
271
271
|
`mergePdfs` (concatenate many PDFs), `fontCatalog`/`fontRequestUrl`/`parseCssFontUrl`.
|
|
272
272
|
- **`GigaPdfDoc`** — text intelligence (`textRuns`, `structuredText`, `search`,
|
|
273
273
|
`ocr`, `ocrText`, `elements`, `elementAt`), editing (`replaceText`,
|
|
274
|
-
`removeElement`, `moveElement`, `
|
|
274
|
+
`removeElement`, `moveElement`, `transformElement` (full affine — move + resize
|
|
275
|
+
+ rotate in place), `reorderElement` (native z-order — bring to front / send to
|
|
276
|
+
back), `setPathStyle` (in-place vector restyle: fill/stroke/width/dash + **real
|
|
277
|
+
opacity**), `setElementOpacity` (constant opacity on any element — text/image/shape),
|
|
278
|
+
`duplicateElement`, `redact`), vector drawing
|
|
275
279
|
(`addRectangle`, `drawLine`, `addEllipse`, `addPolygon`, `addPath` (SVG path),
|
|
276
280
|
`addImage` (PNG/JPEG, alpha + opacity)), pages (`rotatePage`, `deletePage`,
|
|
277
281
|
`movePage`, `appendPages`, `extractPages`, `resizePage`, `addPage`, `copyPage`,
|
|
278
282
|
`pageInfo`),
|
|
279
283
|
`renderPage` (and `renderPageNoText` — a text-free background for editors that
|
|
280
|
-
overlay real editable text; vectors/gradients/images/annotations still rendered
|
|
284
|
+
overlay real editable text; vectors/gradients/images/annotations still rendered —
|
|
285
|
+
plus `renderPageExcluding` — a background omitting specific elements for
|
|
286
|
+
live-overlay editing),
|
|
281
287
|
fonts (base-14 `addStandardText`, embed **any** TrueType/OpenType
|
|
282
288
|
via `embedFont`/`addText`, font-aware editing `replaceText`,
|
|
283
289
|
the document's own faces `embeddedFonts`/`extractFont`, `neededFonts`),
|
package/dist/index.cjs
CHANGED
|
@@ -913,6 +913,10 @@ var GigaPdfDoc = class {
|
|
|
913
913
|
* `unknown`), and the source pixel dimensions. DCTDecode/JPXDecode images pass
|
|
914
914
|
* through as jpeg/jp2; Flate/raw DeviceRGB|DeviceGray are re-encoded to PNG.
|
|
915
915
|
* The native replacement for a reader's image extraction (bytes + placement).
|
|
916
|
+
*
|
|
917
|
+
* Each result's `index` is the **unified element index** usable directly with
|
|
918
|
+
* {@link removeElement} / {@link transformElement} / {@link duplicateElement} /
|
|
919
|
+
* {@link moveElement} — so you can extract an image and edit *that exact* image.
|
|
916
920
|
*/
|
|
917
921
|
imageElements(page) {
|
|
918
922
|
const raw = this.g._json(
|
|
@@ -929,6 +933,10 @@ var GigaPdfDoc = class {
|
|
|
929
933
|
* fill/stroke RGB, line width, alpha and dash. Clip-only paths are omitted.
|
|
930
934
|
* The native replacement for walking a reader's operator list to rebuild the
|
|
931
935
|
* shape layer.
|
|
936
|
+
*
|
|
937
|
+
* Each result's `index` is the **unified element index** usable directly with
|
|
938
|
+
* {@link setPathStyle} / {@link removeElement} / {@link transformElement} — so
|
|
939
|
+
* you can extract a path and restyle/remove *that exact* path.
|
|
932
940
|
*/
|
|
933
941
|
vectorPaths(page) {
|
|
934
942
|
return this.g._json((o) => this.ex().gp_vector_paths_json(this.h, page, o));
|
|
@@ -965,6 +973,64 @@ var GigaPdfDoc = class {
|
|
|
965
973
|
moveElement(page, index, dx, dy) {
|
|
966
974
|
return this.ex().gp_move_element(this.h, page, index, dx, dy) === 0;
|
|
967
975
|
}
|
|
976
|
+
/**
|
|
977
|
+
* Apply a full affine transform to element `index` on `page`, wrapping it in
|
|
978
|
+
* `q … cm … Q` with the matrix `m = [a, b, c, d, e, f]`. This **generalises**
|
|
979
|
+
* {@link moveElement} (whose matrix is the pure translate `[1,0,0,1,dx,dy]`)
|
|
980
|
+
* to scale, rotation, shear and translation in one call. Because it is purely
|
|
981
|
+
* matrix-based it works identically for text, images and shapes — their
|
|
982
|
+
* internal coordinates are never touched. Returns `false` if the element/page
|
|
983
|
+
* doesn't exist.
|
|
984
|
+
*/
|
|
985
|
+
transformElement(page, index, m) {
|
|
986
|
+
return this.ex().gp_transform_element(this.h, page, index, m[0], m[1], m[2], m[3], m[4], m[5]) === 0;
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Re-style the **path** element `index` on `page` in place: any provided field
|
|
990
|
+
* overrides that part of the graphics state for the path's paint; omitted
|
|
991
|
+
* fields keep the inherited state. Implemented by wrapping the path's op range
|
|
992
|
+
* in `q … Q` and injecting the requested state operators (`rg`/`RG`/`w`/`d`)
|
|
993
|
+
* before its construction + paint ops, so the original paint op now draws with
|
|
994
|
+
* the override and following content is unaffected. RGB colours are `[r,g,b]`
|
|
995
|
+
* in `0..=1`; `dash` is the PDF dash array (`[]` = solid). Returns `false` if
|
|
996
|
+
* the element is not a path (or the page/index doesn't exist).
|
|
997
|
+
*
|
|
998
|
+
* Opacity: `fillAlpha`/`strokeAlpha` (`0..=1`) are fully supported — an
|
|
999
|
+
* `/ExtGState` carrying `/ca`/`/CA` is registered on the page and a `/<gs> gs`
|
|
1000
|
+
* is injected into the path's `q … Q` wrap, so the alpha applies to that path
|
|
1001
|
+
* run only. (For non-path elements such as images, use
|
|
1002
|
+
* {@link setElementOpacity}.)
|
|
1003
|
+
*/
|
|
1004
|
+
setPathStyle(page, index, style) {
|
|
1005
|
+
return this.g._withStr(
|
|
1006
|
+
JSON.stringify(style),
|
|
1007
|
+
(p, l) => this.ex().gp_set_path_style_json(this.h, page, index, p, l)
|
|
1008
|
+
) === 0;
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Set a constant opacity on element `index` on `page` — text, image **or**
|
|
1012
|
+
* shape — by registering an `/ExtGState` (`/ca` = `/CA` = `fillAlpha`, clamped
|
|
1013
|
+
* to `0..=1`) on the page and wrapping the element's op range in
|
|
1014
|
+
* `q /<gs> gs … Q`. This is the way to set an **image**'s alpha in place;
|
|
1015
|
+
* shapes may also use {@link setPathStyle}'s `fillAlpha`/`strokeAlpha` (same
|
|
1016
|
+
* underlying `/ExtGState` mechanism). Returns `false` if the page/index doesn't
|
|
1017
|
+
* exist.
|
|
1018
|
+
*/
|
|
1019
|
+
setElementOpacity(page, index, fillAlpha) {
|
|
1020
|
+
return this.ex().gp_set_element_opacity(this.h, page, index, fillAlpha) === 0;
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Change the paint order (z-order) of element `index` on `page`. `toFront`
|
|
1024
|
+
* brings it visually on top (its op range is moved to the end of the content
|
|
1025
|
+
* stream, painted last); otherwise it is sent behind everything (moved to the
|
|
1026
|
+
* start, painted first). The moved range is re-wrapped in `q … Q` so it neither
|
|
1027
|
+
* inherits nor leaks graphics state. Works for text, image and shape elements.
|
|
1028
|
+
* The element's index changes after the move — re-read {@link pageElements}.
|
|
1029
|
+
* Returns `false` if the page/index doesn't exist.
|
|
1030
|
+
*/
|
|
1031
|
+
reorderElement(page, index, toFront) {
|
|
1032
|
+
return this.ex().gp_reorder_element(this.h, page, index, toFront ? 1 : 0) === 0;
|
|
1033
|
+
}
|
|
968
1034
|
duplicateElement(page, index) {
|
|
969
1035
|
return this.ex().gp_duplicate_element(this.h, page, index) === 0;
|
|
970
1036
|
}
|
|
@@ -1248,6 +1314,24 @@ var GigaPdfDoc = class {
|
|
|
1248
1314
|
renderPageNoText(page, scale = 1) {
|
|
1249
1315
|
return this.g._buffer((o) => this.ex().gp_render_page_no_text(this.h, page, scale, o));
|
|
1250
1316
|
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Rasterize a page to a PNG while **omitting** the given top-level element
|
|
1319
|
+
* `indices` (from {@link pageElements}). Each excluded element paints nothing
|
|
1320
|
+
* — fills, strokes, shadings, images and text alike — while everything else
|
|
1321
|
+
* (including the non-text content of non-excluded elements) renders normally.
|
|
1322
|
+
* Use it to paint a background without specific elements and overlay live,
|
|
1323
|
+
* editable versions on top. Generalises {@link renderPageNoText} (which
|
|
1324
|
+
* suppresses *all* text). An empty `indices` renders the full page; unknown
|
|
1325
|
+
* indices are ignored.
|
|
1326
|
+
*/
|
|
1327
|
+
renderPageExcluding(page, indices, scale = 1) {
|
|
1328
|
+
return this.g._buffer(
|
|
1329
|
+
(o) => this.g._withU32(
|
|
1330
|
+
indices,
|
|
1331
|
+
(p, c) => this.ex().gp_render_page_excluding(this.h, page, p, c, scale, o)
|
|
1332
|
+
)
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1251
1335
|
// fonts — embed a downloaded font, then add real selectable text
|
|
1252
1336
|
/**
|
|
1253
1337
|
* Embed an outline font program as a Type0 font and return its object number
|