@qrcommunication/gigapdf-lib 0.66.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 CHANGED
@@ -4,6 +4,25 @@ 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.67.0] - 2026-06-23
8
+
9
+ ### Added
10
+
11
+ - **Structured-editing ModelOps + permissions API exposed in the SDK.** New
12
+ `applyModelOps` variants: paragraph formatting (`setParagraphStyle` — align/indent/
13
+ spacing/line-height), lists (`setListLevel`/`setListMarker`/`setListOrdered`),
14
+ absolute block placement (`setBlockFrame`/`setBlockRotation`), and table styling
15
+ (`setCellShading`/`setRowHeight`/`setColWidth`/`setTableBorder`). Table structural
16
+ edits (`insertTableRow`/`deleteTableRow`/`insertTableColumn`/`deleteTableColumn`/
17
+ `setCellSpan` + sheet row/column ops) and `GigaPdfDoc` permission helpers
18
+ (`permissionsToP`/`decodePermissions`/`getPermissions` + `saveEncrypted({ flags })`)
19
+ are now callable from JS.
20
+
21
+ ### Changed
22
+
23
+ - 8 PDF permission flags are functional: `/P` is computed from named flags per
24
+ ISO 32000-1 Table 22 (previously a cosmetic integer).
25
+
7
26
  ## [0.66.0] - 2026-06-23
8
27
 
9
28
  ### Added
package/dist/index.cjs CHANGED
@@ -27,6 +27,16 @@ module.exports = __toCommonJS(index_exports);
27
27
  var import_node_fs = require("./node-fs.js");
28
28
  var enc = new TextEncoder();
29
29
  var dec = new TextDecoder();
30
+ var ALL_PERMISSIONS = {
31
+ print: true,
32
+ modify: true,
33
+ copy: true,
34
+ annotate: true,
35
+ fillForms: true,
36
+ accessibility: true,
37
+ assemble: true,
38
+ printHighRes: true
39
+ };
30
40
  var GigaPdfEngine = class _GigaPdfEngine {
31
41
  constructor(ex) {
32
42
  this.ex = ex;
@@ -243,6 +253,43 @@ var GigaPdfEngine = class _GigaPdfEngine {
243
253
  );
244
254
  return JSON.parse(dec.decode(json));
245
255
  }
256
+ /**
257
+ * Decode the eight access-permission flags from a `/P` permission bitmask
258
+ * (ISO 32000-1 Table 22) into named booleans (`true` = the action is
259
+ * granted). Reserved bits are ignored.
260
+ */
261
+ decodePermissions(p) {
262
+ const json = dec.decode(this._buffer((o) => this.ex.gp_permissions_from_p(p, o)));
263
+ return JSON.parse(json);
264
+ }
265
+ /**
266
+ * Read a PDF's access permissions **without decrypting it** (no password
267
+ * needed). Returns the eight named flags decoded from the `/Encrypt`
268
+ * dictionary's `/P`; an unencrypted document grants everything.
269
+ */
270
+ getPermissions(pdf) {
271
+ const { encrypted, permissions } = this.encryptionInfo(pdf);
272
+ return encrypted ? this.decodePermissions(permissions) : { ...ALL_PERMISSIONS };
273
+ }
274
+ /**
275
+ * Pack eight access-permission flags into a signed 32-bit `/P` value
276
+ * (ISO 32000-1 Table 22). Omitted flags default to **granted**, so an empty
277
+ * object means "all allowed". Feed the result to {@link GigaPdfDoc.saveEncrypted}
278
+ * via `opts.permissions`, or pass `opts.flags` directly.
279
+ */
280
+ permissionsToP(flags = {}) {
281
+ const f = { ...ALL_PERMISSIONS, ...flags };
282
+ return this.ex.gp_permissions_to_p(
283
+ f.print ? 1 : 0,
284
+ f.modify ? 1 : 0,
285
+ f.copy ? 1 : 0,
286
+ f.annotate ? 1 : 0,
287
+ f.fillForms ? 1 : 0,
288
+ f.accessibility ? 1 : 0,
289
+ f.assemble ? 1 : 0,
290
+ f.printHighRes ? 1 : 0
291
+ );
292
+ }
246
293
  /**
247
294
  * Width of `text` set in standard Helvetica at `size` points (AFM metrics) —
248
295
  * place watermark/header text without embedding a font.
@@ -1525,7 +1572,7 @@ var GigaPdfDoc = class {
1525
1572
  saveEncrypted(password, fileId, opts = {}) {
1526
1573
  const algo = opts.algorithm ?? "aes256";
1527
1574
  const algoCode = algo === "rc4" ? 0 : algo === "aes128" ? 1 : 2;
1528
- const permissions = opts.permissions ?? -44;
1575
+ const permissions = opts.flags !== void 0 ? this.g.permissionsToP(opts.flags) : opts.permissions ?? this.g.permissionsToP();
1529
1576
  let key = opts.keySeed ?? new Uint8Array(0);
1530
1577
  if (algoCode === 2 && key.length < 32) {
1531
1578
  const c = globalThis.crypto;