@qrcommunication/gigapdf-lib 0.51.0 → 0.52.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 +45 -0
- package/dist/index.cjs +170 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +305 -1
- package/dist/index.d.ts +305 -1
- package/dist/index.js +170 -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,51 @@ 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.52.0] - 2026-06-18
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **Unified editable document model — reconstruction, importers, exporters, edit
|
|
12
|
+
operations, full JS round-trip.** A format-agnostic `model::Document`
|
|
13
|
+
(Section → Page → Block{Paragraph, Heading, List, Table, Image, Shape, TextBox,
|
|
14
|
+
Sheet, Slide} → Inline) that every format imports into and exports from. PDF →
|
|
15
|
+
model via `reconstruct_model` (structural: positioned runs are rebuilt into
|
|
16
|
+
paragraphs, headings, lists and tables, honouring the `/StructTree` tag tree when
|
|
17
|
+
present); Office/HTML/image → model importers; model →
|
|
18
|
+
DOCX/XLSX/PPTX/ODT/ODS/ODP/HTML/RTF/PDF structured exporters (real editable
|
|
19
|
+
content, not a raster). New `model::edit` operations (`ModelOp`: set/restyle run,
|
|
20
|
+
insert/delete/move block, table & sheet cells…) with `apply_ops`. Exposed to JS:
|
|
21
|
+
`toModel`, `officeToModel`, `htmlToModel`, `applyModelOps`, and
|
|
22
|
+
`modelToDocx/Xlsx/Pptx/Odt/Ods/Odp/Html/Rtf/Pdf`. Foundation for editing any
|
|
23
|
+
document format through one editable model.
|
|
24
|
+
- **Text direction & document-language detection (RTL).** `documentLanguage()`
|
|
25
|
+
reports the dominant script and reading direction (Arabic, Hebrew, Latin, CJK…),
|
|
26
|
+
and each text element now carries its `direction` (`ltr`/`rtl`/`neutral`), so
|
|
27
|
+
editors can switch the canvas and layer properties to right-to-left for correct
|
|
28
|
+
editing.
|
|
29
|
+
- **Page margins + running headers/footers.** `pageMargins`/`setPageMargins`
|
|
30
|
+
(CropBox-aware, falling back to the printable content box) and `setHeader`/
|
|
31
|
+
`setFooter` with `{{page}}`/`{{pages}}` tokens, alignment, page ranges and a
|
|
32
|
+
first-page toggle. Baking is idempotent (wrapped in marked content) and
|
|
33
|
+
reversible via `removeHeaders`/`removeFooters`.
|
|
34
|
+
- **Pixel-perfect colour & images.** Full PDF colour-space resolution — Separation,
|
|
35
|
+
DeviceN (with type-0/2/3 functions and a new PostScript type-4 calculator tint
|
|
36
|
+
transform), Indexed, ICCBased (via `/N` + `/Alternate`), CalRGB/CalGray, Lab
|
|
37
|
+
(D50) and accurate CMYK — applied to fills, strokes (`cs`/`CS` + `sc`/`scn`) and
|
|
38
|
+
image XObjects (honouring `/BitsPerComponent` and `/Decode`), fixing
|
|
39
|
+
blank/garbled non-RGB images. **Progressive (SOF2) JPEG** decoding lands in full
|
|
40
|
+
(baseline already supported; arithmetic-coded JPEG is skipped, not blanked).
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
|
|
44
|
+
- **Subset-CFF glyphs no longer render as tofu.** Simple `/Type1` fonts embedding a
|
|
45
|
+
CFF program (`/FontFile3 /Type1C`, e.g. subsetted MyriadPro/Nexa) now resolve
|
|
46
|
+
glyphs through the CFF charset (`code → glyph name → gid`) instead of a Unicode
|
|
47
|
+
`cmap` they do not carry; an unresolved code paints nothing rather than a box.
|
|
48
|
+
- **Baseline JPEG images now render.** `/DCTDecode` image XObjects (direct and
|
|
49
|
+
nested inside form XObjects, with `/SMask`) are decoded and blitted — previously
|
|
50
|
+
they were skipped, leaving blank slides and image-shaped holes.
|
|
51
|
+
|
|
7
52
|
## [0.51.0] - 2026-06-18
|
|
8
53
|
|
|
9
54
|
### Added
|
package/dist/index.cjs
CHANGED
|
@@ -671,6 +671,113 @@ var GigaPdfEngine = class _GigaPdfEngine {
|
|
|
671
671
|
)
|
|
672
672
|
);
|
|
673
673
|
}
|
|
674
|
+
// ── unified editable model: lower / edit / raise ───────────────────────────
|
|
675
|
+
//
|
|
676
|
+
// The {@link GigaDocument} model is a format-neutral tree (sections → pages →
|
|
677
|
+
// blocks → runs). Lower any format into it (`*ToModel`), edit it with
|
|
678
|
+
// {@link applyModelOps}, then raise it back to any format (`modelTo*`). This is
|
|
679
|
+
// the substrate for a universal editor that edits every format the same way.
|
|
680
|
+
/** Decode a model-JSON buffer returned by a `gp_model_*` export; `null` on an
|
|
681
|
+
* empty (error) result. */
|
|
682
|
+
_modelOrNull(call) {
|
|
683
|
+
const s = this._str(call);
|
|
684
|
+
return s ? JSON.parse(s) : null;
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Lower an Office document (DOCX/XLSX/PPTX/ODT/ODS/ODP, auto-detected) into the
|
|
688
|
+
* unified {@link GigaDocument} model. Returns `null` if the bytes aren't a
|
|
689
|
+
* recognized Office container.
|
|
690
|
+
*/
|
|
691
|
+
officeToModel(office) {
|
|
692
|
+
return this._withBytes(
|
|
693
|
+
office,
|
|
694
|
+
(p, l) => this._modelOrNull((o) => this.ex.gp_model_from_office(p, l, o))
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
/** Lower an HTML string into the unified {@link GigaDocument} model. */
|
|
698
|
+
htmlToModel(html) {
|
|
699
|
+
return this._withStr(
|
|
700
|
+
html,
|
|
701
|
+
(p, l) => JSON.parse(this._str((o) => this.ex.gp_model_from_html(p, l, o)))
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Apply a batch of {@link ModelOp} edits to a model and return the edited
|
|
706
|
+
* model. Ops run in order; out-of-range addresses (and any op that can't be
|
|
707
|
+
* parsed) are silently skipped, so a partially-valid batch never throws.
|
|
708
|
+
*/
|
|
709
|
+
applyModelOps(model, ops) {
|
|
710
|
+
return this._withStr(
|
|
711
|
+
JSON.stringify(model),
|
|
712
|
+
(mp, ml) => this._withStr(
|
|
713
|
+
JSON.stringify(ops),
|
|
714
|
+
(op, ol) => JSON.parse(this._str((o) => this.ex.gp_model_apply_ops(mp, ml, op, ol, o)))
|
|
715
|
+
)
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
/** Raise a {@link GigaDocument} model to an editable Word document (`.docx`). */
|
|
719
|
+
modelToDocx(model) {
|
|
720
|
+
return this._withStr(
|
|
721
|
+
JSON.stringify(model),
|
|
722
|
+
(p, l) => this._buffer((o) => this.ex.gp_model_to_docx(p, l, o))
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
/** Raise a model to an Excel workbook (`.xlsx`). */
|
|
726
|
+
modelToXlsx(model) {
|
|
727
|
+
return this._withStr(
|
|
728
|
+
JSON.stringify(model),
|
|
729
|
+
(p, l) => this._buffer((o) => this.ex.gp_model_to_xlsx(p, l, o))
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
/** Raise a model to a PowerPoint presentation (`.pptx`). */
|
|
733
|
+
modelToPptx(model) {
|
|
734
|
+
return this._withStr(
|
|
735
|
+
JSON.stringify(model),
|
|
736
|
+
(p, l) => this._buffer((o) => this.ex.gp_model_to_pptx(p, l, o))
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
/** Raise a model to an OpenDocument Text (`.odt`). */
|
|
740
|
+
modelToOdt(model) {
|
|
741
|
+
return this._withStr(
|
|
742
|
+
JSON.stringify(model),
|
|
743
|
+
(p, l) => this._buffer((o) => this.ex.gp_model_to_odt(p, l, o))
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
/** Raise a model to an OpenDocument Spreadsheet (`.ods`). */
|
|
747
|
+
modelToOds(model) {
|
|
748
|
+
return this._withStr(
|
|
749
|
+
JSON.stringify(model),
|
|
750
|
+
(p, l) => this._buffer((o) => this.ex.gp_model_to_ods(p, l, o))
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
/** Raise a model to an OpenDocument Presentation (`.odp`). */
|
|
754
|
+
modelToOdp(model) {
|
|
755
|
+
return this._withStr(
|
|
756
|
+
JSON.stringify(model),
|
|
757
|
+
(p, l) => this._buffer((o) => this.ex.gp_model_to_odp(p, l, o))
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
/** Raise a model back to a PDF. */
|
|
761
|
+
modelToPdf(model) {
|
|
762
|
+
return this._withStr(
|
|
763
|
+
JSON.stringify(model),
|
|
764
|
+
(p, l) => this._buffer((o) => this.ex.gp_model_to_pdf(p, l, o))
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
/** Raise a model to standalone HTML (decoded UTF-8 string). */
|
|
768
|
+
modelToHtml(model) {
|
|
769
|
+
return this._withStr(
|
|
770
|
+
JSON.stringify(model),
|
|
771
|
+
(p, l) => this._str((o) => this.ex.gp_model_to_html(p, l, o))
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
/** Raise a model to RTF (decoded UTF-8 string). */
|
|
775
|
+
modelToRtf(model) {
|
|
776
|
+
return this._withStr(
|
|
777
|
+
JSON.stringify(model),
|
|
778
|
+
(p, l) => this._str((o) => this.ex.gp_model_to_rtf(p, l, o))
|
|
779
|
+
);
|
|
780
|
+
}
|
|
674
781
|
};
|
|
675
782
|
function packHtmlResources(resources) {
|
|
676
783
|
let size = 4;
|
|
@@ -774,6 +881,24 @@ var GigaPdfDoc = class {
|
|
|
774
881
|
textElements(page) {
|
|
775
882
|
return this.g._json((o) => this.ex().gp_text_elements_json(this.h, page, o));
|
|
776
883
|
}
|
|
884
|
+
/**
|
|
885
|
+
* The document's aggregate language signal — its dominant reading direction
|
|
886
|
+
* (`ltr`/`rtl`/`neutral`), writing system, and a best-effort ISO-639-1
|
|
887
|
+
* language code — computed across every page's decoded text. Lets a host
|
|
888
|
+
* pick fonts, set the UI direction or label the document without its own bidi
|
|
889
|
+
* pass (e.g. detect an Arabic/Hebrew/Japanese PDF). `lang` is omitted when the
|
|
890
|
+
* script does not pin a single language.
|
|
891
|
+
*/
|
|
892
|
+
documentLanguage() {
|
|
893
|
+
const raw = this.g._json(
|
|
894
|
+
(o) => this.ex().gp_document_language(this.h, o)
|
|
895
|
+
);
|
|
896
|
+
return {
|
|
897
|
+
direction: raw.direction,
|
|
898
|
+
script: raw.script,
|
|
899
|
+
...raw.lang != null ? { lang: raw.lang } : {}
|
|
900
|
+
};
|
|
901
|
+
}
|
|
777
902
|
/**
|
|
778
903
|
* Every image element on a page: its placement box (user space, bottom-left),
|
|
779
904
|
* the embeddable encoded bytes (`data`) + `format` (`jpeg`/`png`/`jp2`/
|
|
@@ -1022,6 +1147,40 @@ var GigaPdfDoc = class {
|
|
|
1022
1147
|
pageInfo(page) {
|
|
1023
1148
|
return this.g._json((o) => this.ex().gp_page_info_json(this.h, page, o));
|
|
1024
1149
|
}
|
|
1150
|
+
// margins + running header/footer
|
|
1151
|
+
/**
|
|
1152
|
+
* A page's margins (points): the gap between `/CropBox` and `/MediaBox` when a
|
|
1153
|
+
* CropBox exists, else estimated from the content bounding box.
|
|
1154
|
+
*/
|
|
1155
|
+
pageMargins(page) {
|
|
1156
|
+
return this.g._json((o) => this.ex().gp_page_margins(this.h, page, o));
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Set a page's margins (points) by insetting its `/CropBox` from the `/MediaBox`
|
|
1160
|
+
* — a real, visible margin change. Returns `true` on success.
|
|
1161
|
+
*/
|
|
1162
|
+
setPageMargins(page, m) {
|
|
1163
|
+
return this.ex().gp_set_page_margins(this.h, page, m.top, m.right, m.bottom, m.left) === 0;
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Bake a running header onto every in-range page (idempotent: re-baking
|
|
1167
|
+
* replaces the prior header). Returns `true` on success.
|
|
1168
|
+
*/
|
|
1169
|
+
setHeader(spec) {
|
|
1170
|
+
return this.g._withStr(JSON.stringify(spec), (p, l) => this.ex().gp_set_header(this.h, p, l)) === 0;
|
|
1171
|
+
}
|
|
1172
|
+
/** Bake a running footer onto every in-range page (idempotent). */
|
|
1173
|
+
setFooter(spec) {
|
|
1174
|
+
return this.g._withStr(JSON.stringify(spec), (p, l) => this.ex().gp_set_footer(this.h, p, l)) === 0;
|
|
1175
|
+
}
|
|
1176
|
+
/** Remove every previously-baked running header from all pages. */
|
|
1177
|
+
removeHeaders() {
|
|
1178
|
+
return this.ex().gp_remove_headers(this.h) === 0;
|
|
1179
|
+
}
|
|
1180
|
+
/** Remove every previously-baked running footer from all pages. */
|
|
1181
|
+
removeFooters() {
|
|
1182
|
+
return this.ex().gp_remove_footers(this.h) === 0;
|
|
1183
|
+
}
|
|
1025
1184
|
// render
|
|
1026
1185
|
renderPage(page, scale = 1) {
|
|
1027
1186
|
return this.g._buffer((o) => this.ex().gp_render_page(this.h, page, scale, o));
|
|
@@ -1147,6 +1306,17 @@ var GigaPdfDoc = class {
|
|
|
1147
1306
|
toHtml() {
|
|
1148
1307
|
return this.g._str((o) => this.ex().gp_to_html(this.h, o));
|
|
1149
1308
|
}
|
|
1309
|
+
/**
|
|
1310
|
+
* Reconstruct this PDF into the **unified editable model** — the
|
|
1311
|
+
* format-neutral {@link GigaDocument} tree (sections → pages → blocks → runs)
|
|
1312
|
+
* that every format lowers into. Edit it with
|
|
1313
|
+
* {@link GigaPdfEngine.applyModelOps}, then export it to any target with
|
|
1314
|
+
* {@link GigaPdfEngine.modelToDocx} / {@link GigaPdfEngine.modelToPdf} / … —
|
|
1315
|
+
* the foundation for editing any document indifferently of its source format.
|
|
1316
|
+
*/
|
|
1317
|
+
toModel() {
|
|
1318
|
+
return JSON.parse(this.g._str((o) => this.ex().gp_model_from_pdf(this.h, o)));
|
|
1319
|
+
}
|
|
1150
1320
|
toDocx() {
|
|
1151
1321
|
return this.g._buffer((o) => this.ex().gp_to_docx(this.h, o));
|
|
1152
1322
|
}
|