@zilijonas/foliark 0.2.0 → 0.3.1

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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <p align="center"><b>A PDF engine in Rust and WebAssembly for the browser. Extract, search, render, edit, redact and sanitize PDFs on the user's device. The document never leaves it.</b></p>
6
6
 
7
7
  ```sh
8
- npm install @zilijonas/foliark@0.2.0 --save-exact
8
+ npm install @zilijonas/foliark@0.3.1 --save-exact
9
9
  ```
10
10
 
11
11
  ESM only, no runtime dependencies, typed. Runs in a worker, fetches only its own `.wasm` and worker script, and refuses what it cannot do safely with a typed `FoliarkError` instead of degrading quietly.
@@ -87,12 +87,26 @@ const r = await doc.applyChanges({ baseRevision: doc.revision, textEdits: [{ id:
87
87
  if (!r.accepted) console.warn(r.rejected); // typed code per edit, nothing changed
88
88
  ```
89
89
 
90
+ An edit that does not fit its paragraph's own width is laid out at a wider limit read from the page (`ParagraphInfo.maxWrapWidth` and `maxWrapLines`; `EditPreview.wrapWidth` is the width the layout used). Text that fit at `wrapWidth` lays out exactly as before. To let a longer edit grow downward instead of refusing `EDIT_NO_FIT`, opt in per edit with `reflow: "pushDown"` (also an option of `layoutEdit`):
91
+
92
+ ```ts
93
+ const p = await doc.layoutEdit(0, [info.bounds], longerText, { reflow: "pushDown" }); // p.shift: what would move; p.reflowBlocked: why it cannot
94
+ const r = await doc.applyChanges({ baseRevision: doc.revision, textEdits: [{ id: "e1", pageIndex: 0, rects: [info.bounds], text: longerText, reflow: "pushDown" }] });
95
+ // r.remap: ordered { pageIndex, region, dy } steps from the previous working copy, for re-placing your overlays; [] when nothing moved
96
+ ```
97
+
98
+ Content below the paragraph moves by whole lines, nothing leaves the page, and redactions (stated in base-revision coordinates) and later edits are mapped through the move; one that a moved region cuts is refused `INVALID_ARGUMENT` (`redactionTargetShifted`, `editTargetShifted`). Content that cannot move as whole units refuses `EDIT_NO_FIT` with a `reflow*` `feature` (`ParagraphInfo.pushDown` tells the budget beforehand). Without `reflow` nothing outside the paragraph moves.
99
+
100
+ When a registered family matches the source font's name, edits use it: besides Carlito, Caladea, Gelasio and the Liberation faces, the rules cover Roboto, Open Sans, Lato, Noto Serif, Noto Sans, DejaVu Sans and EB Garamond (Verdana, Tahoma and Garamond prefer DejaVu Sans or EB Garamond and fall back to Liberation). Foliark bundles none of them: you register the families you want.
101
+
90
102
  Image-only export burns the redactions into pixels:
91
103
 
92
104
  ```ts
93
105
  const flat = await doc.export(await doc.prepareExport({ mode: "raster", policy: { raster: { acknowledgeLosses: true, scale: 2 } } }));
94
106
  ```
95
107
 
108
+ Native export removes the Info dictionary and XMP by default; `policy: { metadata: "keep" }` writes back Title, Author, Subject, Keywords, Creator, Producer, CreationDate and ModDate (normalized, and dropped when one spells text a redaction or an edit took out; `plan.report.kept.metadata` lists them). Custom keys and XMP are always removed.
109
+
96
110
  Native export removes hyperlinks by default; `policy: { links: "keep" }` keeps `http`, `https`, `mailto` and in-document links that no redaction touches or spells (`plan.report.kept.links`; the rest are `LINKS_REMOVED`).
97
111
 
98
112
  Already running your own dedicated worker with its own recovery? Use the in-worker entry. Same API and errors, no second worker, and your worker supervises hangs and must be replaced after `onReset`:
@@ -116,8 +130,8 @@ Chromium on desktop (macOS arm64) is supported and has budgets. WebKit is suppor
116
130
 
117
131
  - Defaults: 64 MiB input, 1000 pages, 50 Mpx per render, 256 MiB output, 4 open documents (`limits` option). Exceeding one is `LIMIT_EXCEEDED`, with no output.
118
132
  - Repaired or truncated files are refused (`REPAIRED_PDF`) unless you pass `allowRepaired`.
119
- - Native export rewrites the file from scratch and drops metadata, attachments, scripts and outlines, reporting each in `plan.report`.
120
- - Paragraph editing is horizontal, unrotated, left-to-right text only, and needs a registered font when the document's own cannot be reused.
133
+ - Native export rewrites the file from scratch and drops metadata (unless you opt in with `metadata: "keep"`), attachments, scripts and outlines, reporting each in `plan.report`.
134
+ - Paragraph editing is horizontal, unrotated, left-to-right text only, and needs a registered font when the document's own cannot be reused. Push-down moves content within its page only; it never reflows onto the next page.
121
135
  - Redaction is checked inside the engine and by independent oracles on 80 test documents. That is evidence, not a certificate for arbitrary real-world files.
122
136
 
123
137
  ## Links
@@ -128,6 +142,6 @@ Chromium on desktop (macOS arm64) is supported and has budgets. WebKit is suppor
128
142
 
129
143
  [AGPL-3.0-only](https://github.com/zilijonas/foliark/blob/main/LICENSE), the same licence family as the AGPL option PyMuPDF is offered under. If the AGPL does not fit your use, separate commercial licensing is available: see `COMMERCIAL-LICENSING.md` in the package. This is not legal advice. Details are in `LICENSING.md`.
130
144
 
131
- Foliark is free software, so the complete corresponding source of version 0.2.0 (Rust engine, vendored hayro fork and patches, build scripts) is tag `v0.2.0` of https://github.com/zilijonas/foliark. Build steps are in `docs/development.md` there (`scripts/build-wasm.sh`, `pnpm build:sdk`, `tests/package-consumers/pack.sh`). The package contains `dist/`, `wasm/` (5.8 MB raw, 2.2 MB gzip), `cmaps/`, `LICENSE`, `LICENSING.md`, `COMMERCIAL-LICENSING.md`, `LICENSE_FOXIT`, `NOTICE`, `THIRD_PARTY_NOTICES.md` and `SUPPORT_MATRIX.md`.
145
+ Foliark is free software, so the complete corresponding source of version 0.3.1 (Rust engine, vendored hayro fork and patches, build scripts) is tag `v0.3.1` of https://github.com/zilijonas/foliark. Build steps are in `docs/development.md` there (`scripts/build-wasm.sh`, `pnpm build:sdk`, `tests/package-consumers/pack.sh`). The package contains `dist/`, `wasm/` (5.8 MB raw, 2.2 MB gzip), `cmaps/`, `LICENSE`, `LICENSING.md`, `COMMERCIAL-LICENSING.md`, `LICENSE_FOXIT`, `NOTICE`, `THIRD_PARTY_NOTICES.md` and `SUPPORT_MATRIX.md`.
132
146
 
133
147
  PyMuPDF and MuPDF are products of Artifex Software, Inc. Foliark is independent of them and not affiliated with Artifex.
package/SUPPORT_MATRIX.md CHANGED
@@ -35,7 +35,7 @@ Host requirements, each tested in the browser specs: static files only, `applica
35
35
  | Search, hit test, select | supported on the multi-column Unicode fixture (diacritic folding, column drag stays on its line) | `hddn-adapter.md` (NEW-67) | `INVALID_ARGUMENT` | regex and hyphenation-aware search are absent by design (spec 16); not wired into HDDN's UI |
36
36
  | Render | supported with warnings | `native-roundtrip.md` (0 channel values off by more than 2/255 between input and output renders); reduced vs exact decode max diff 1 (`docs/performance/comparison.md`) | warnings `FONT_SUBSTITUTED`, `IMAGE_DECODE_FAILED`, `ANNOTATION_APPEARANCE_MISSING`, `CMAP_MISSING` (page is `complete:false`); `LIMIT_EXCEEDED` over `maxRenderPixels` | pixel accuracy against a second renderer on real documents (PyMuPDF differs by mean 0.02 to 3.1 levels on the scan fixtures) |
37
37
  | Predefined CMaps (legacy CJK encodings) | supported (pack in the package) | `cmaps/` 63 Adobe files; fixture `generated/cjk-predefined-cmaps.pdf`: extract equals PyMuPDF, render has no `CMAP_MISSING`, redaction + native export judged by `objects.py`/PyMuPDF (`crates/foliark-engine/tests/cmaps.rs`), packed-package browser specs in 3 engines (`tests/browser/cmaps.spec.ts`) | `ASSET_LOAD_FAILED` at `open` for a missing or corrupt pack file; `CMAP_MISSING` for a name outside the predefined set; the pack must be served or copied by the caller (`docs/deployment.md`) | text redaction/edit on mixed-length encodings (RKSJ, EUC, UTF16): `FONT_UNSUPPORTED`; CJK glyphs of a non-embedded font are drawn missing |
38
- | Paragraph edit | supported for horizontal, unrotated, left-to-right text in a registered or reusable font | `docs/adr/0003`, `0004`, `0005`, `0011`, `0012`, `0013`; acceptance scenario E over 80 cases; HDDN adapter NEW-68 | `EDIT_NO_FONT`, `EDIT_NO_FIT`, `EDIT_NO_STYLE`, `EDIT_UNSUPPORTED_SCRIPT` (non-BMP, RTL), `EDIT_ROTATED_TEXT`, `FONT_UNSUPPORTED`, `STALE_REVISION` | CFF/Type1 embedded faces, RTL, CJK, vertical, auto-fit (spec 16) |
38
+ | Paragraph edit | supported for horizontal, unrotated, left-to-right text in a registered or reusable font | `docs/adr/0003`, `0004`, `0005`, `0011`, `0012`, `0013`, `0015` (wrap limits from page evidence: `maxWrapWidth`, `maxWrapLines`, `EditPreview.wrapWidth`; push-down reports `EditPreview.shift` and `ChangeResult.remap`), `0017` (default font-match families); acceptance scenario E over 80 cases; HDDN adapter NEW-68; opt-in `reflow: 'pushDown'` judged by `tests/oracles/shift.py` on the `push-*` fixtures | `EDIT_NO_FONT`, `EDIT_NO_FIT` (with a `reflow*` feature when push-down cannot move whole units), `EDIT_NO_STYLE`, `EDIT_UNSUPPORTED_SCRIPT` (non-BMP, RTL), `EDIT_ROTATED_TEXT`, `FONT_UNSUPPORTED`, `STALE_REVISION` | CFF/Type1 embedded faces, RTL, CJK, vertical, auto-fit (spec 16) |
39
39
  | Native export (sanitized rewrite) | supported | `strict-native.md`: 39 fixtures, 31 supported + 8 refused, 0 skipped, independent oracles, negative controls caught; acceptance 80 cases x 6 scenarios | `FORM_APPEARANCE_MISSING`, `XFA_UNSUPPORTED`, `OPTIONAL_CONTENT_UNSUPPORTED`, `SIGNED_INPUT` (policy `refuse`), `REDACT_*`, `STALE_PLAN`, `PLAN_CONSUMED` | what sections 3 and 4 list |
40
40
  | Raster export (image-only, redactions burned in) | supported; needs `policy.raster.acknowledgeLosses` | acceptance: 143 SAFE + 17 refused raster results; `comparison.md` (30 pages, 10 regions, 0 words in the regions) | `CONSENT_REQUIRED`, `RENDER_INCOMPLETE {pages}` (3 acceptance cases, annotation-comment pinned by NEW-56) | encrypted raster fidelity; edge pixels touching a region are checked with a 0.26 pt inset |
41
41
  | Cancellation | supported before an operation starts; results of aborted operations are atomic | acceptance: 27 attempts, finals byte-equal to a clean run | `CANCELLED` | abort while an operation runs through the packed SDK (only 3 pre-aborted attempts ended `CANCELLED`) |
@@ -66,7 +66,7 @@ Each class is removed and reported, or refused. Evidence is `strict-native.md` (
66
66
 
67
67
  | Class | Status | Report |
68
68
  |---|---|---|
69
- | Info and XMP metadata, PieceInfo, private keys | supported (removed) | `METADATA_REMOVED` |
69
+ | Info and XMP metadata, PieceInfo, private keys | supported (removed); with `metadata: 'keep'` (native) the eight standard Info fields are written back unless they spell removed text, XMP still removed (ADR 0016) | `METADATA_REMOVED`, `report.kept.metadata` |
70
70
  | Embedded files, /AF | supported (removed) | `ATTACHMENTS_REMOVED` |
71
71
  | JavaScript, OpenAction, AA, all actions | supported (removed) | `SCRIPTS_REMOVED` |
72
72
  | Annotations | supported (flatten with appearance, or remove); links removed, or with `links: 'keep'` (native) written back when safe (ADR 0014) | `ANNOTATIONS_FLATTENED`, `ANNOTATIONS_REMOVED`, `LINKS_REMOVED`, `report.kept.links` |
@@ -11,6 +11,7 @@ import type { Hit } from "./generated/Hit.js";
11
11
  import type { OpName } from "./generated/OpName.js";
12
12
  import type { PageGeometry } from "./generated/PageGeometry.js";
13
13
  import type { ParagraphInfo } from "./generated/ParagraphInfo.js";
14
+ import type { Reflow } from "./generated/Reflow.js";
14
15
  import type { Point } from "./generated/Point.js";
15
16
  import type { Rect } from "./generated/Rect.js";
16
17
  import type { RenderWarning } from "./generated/RenderWarning.js";
@@ -77,6 +78,7 @@ export interface DocumentHandle {
77
78
  layoutEdit(page: number, rects: Rect[], text: string, o?: {
78
79
  font?: string;
79
80
  glyphs?: boolean;
81
+ reflow?: Reflow;
80
82
  }): Promise<EditPreview>;
81
83
  applyChanges(cs: ChangeSet, o?: Signal): Promise<ChangeResult>;
82
84
  prepareExport(o: ExportOptions): Promise<ExportPlan>;
package/dist/document.js CHANGED
@@ -85,7 +85,7 @@ export function makeHandle(link, id, info) {
85
85
  async layoutEdit(p, rects, text, o) {
86
86
  if (typeof text !== "string")
87
87
  throw invalid("text must be a string");
88
- return call("layoutEdit", { page: page(p), rects, text, font: o?.font, glyphs: o?.glyphs });
88
+ return call("layoutEdit", { page: page(p), rects, text, font: o?.font, glyphs: o?.glyphs, reflow: o?.reflow });
89
89
  },
90
90
  async applyChanges(changes, o) {
91
91
  const r = await call("applyChanges", { changes }, o?.signal);
@@ -1,4 +1,5 @@
1
1
  import type { EditLayout } from "./EditLayout";
2
+ import type { PageShift } from "./PageShift";
2
3
  import type { RejectedChange } from "./RejectedChange";
3
4
  export type ChangeResult = {
4
5
  accepted: boolean;
@@ -9,4 +10,9 @@ export type ChangeResult = {
9
10
  rejected: Array<RejectedChange>;
10
11
  changedPages: Array<number>;
11
12
  layouts: Array<EditLayout>;
13
+ /**
14
+ * ADR 0015: the push-down steps from the previous working copy to this one, in order; map an
15
+ * overlay (a redaction box, a highlight) through them. Empty when nothing moved.
16
+ */
17
+ remap: Array<PageShift>;
12
18
  };
@@ -1,4 +1,5 @@
1
1
  import type { LayoutRun } from "./LayoutRun";
2
+ import type { PageShift } from "./PageShift";
2
3
  import type { PreviewGlyph } from "./PreviewGlyph";
3
4
  import type { PreviewLine } from "./PreviewLine";
4
5
  import type { StyleSpan } from "./StyleSpan";
@@ -18,7 +19,15 @@ export type EditPreview = {
18
19
  fontSize: number;
19
20
  lines: Array<PreviewLine>;
20
21
  neededLines: number;
22
+ /**
23
+ * The budget of the width the layout used.
24
+ */
21
25
  maxLines: number;
26
+ /**
27
+ * The width the chosen layout used (ADR 0015): `wrapWidth`, or `maxWrapWidth` when the text
28
+ * needed it.
29
+ */
30
+ wrapWidth: number;
22
31
  /**
23
32
  * False: `applyChanges` would refuse with `EDIT_NO_FIT`.
24
33
  */
@@ -38,4 +47,12 @@ export type EditPreview = {
38
47
  * Only when asked for.
39
48
  */
40
49
  glyphs?: Array<PreviewGlyph>;
50
+ /**
51
+ * With `reflow: 'pushDown'`: what the commit would move, when it needs to move anything.
52
+ */
53
+ shift?: PageShift | null;
54
+ /**
55
+ * With `reflow: 'pushDown'`: the `EDIT_NO_FIT` feature that blocks the push-down.
56
+ */
57
+ reflowBlocked?: string;
41
58
  };
@@ -1,6 +1,7 @@
1
1
  import type { AnnotationPolicy } from "./AnnotationPolicy";
2
2
  import type { InvisibleTextPolicy } from "./InvisibleTextPolicy";
3
3
  import type { LinkPolicy } from "./LinkPolicy";
4
+ import type { MetadataPolicy } from "./MetadataPolicy";
4
5
  import type { RasterPolicy } from "./RasterPolicy";
5
6
  import type { SignedInputPolicy } from "./SignedInputPolicy";
6
7
  /**
@@ -9,6 +10,7 @@ import type { SignedInputPolicy } from "./SignedInputPolicy";
9
10
  export type ExportPolicy = {
10
11
  annotations: AnnotationPolicy;
11
12
  links: LinkPolicy;
13
+ metadata: MetadataPolicy;
12
14
  signedInput: SignedInputPolicy;
13
15
  invisibleText: InvisibleTextPolicy;
14
16
  raster: RasterPolicy;
@@ -5,5 +5,11 @@ export type KeptReport = {
5
5
  * `LINKS_REMOVED`.
6
6
  */
7
7
  links: number;
8
+ /**
9
+ * Info keys written back under `policy.metadata: 'keep'` (ADR 0016), in the order Title,
10
+ * Author, Subject, Keywords, Creator, Producer, CreationDate, ModDate; the rest are in
11
+ * `removed.metadata`.
12
+ */
13
+ metadata: Array<string>;
8
14
  fontsWithGlyphInventory: Array<string>;
9
15
  };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Native export only (ADR 0016): `Keep` writes the eight standard Info fields back, fresh and
3
+ * normalized, unless one spells text a redaction or an edit took out; XMP is always removed and
4
+ * raster export never writes Info.
5
+ */
6
+ export type MetadataPolicy = "remove" | "keep";
@@ -0,0 +1,2 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { Rect } from "./Rect";
2
+ /**
3
+ * One push-down step (ADR 0015): the content of `region` (display space, before this step)
4
+ * moved down by `dy` display points.
5
+ */
6
+ export type PageShift = {
7
+ pageIndex: number;
8
+ region: Rect;
9
+ dy: number;
10
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,7 @@
1
1
  import type { EditorFace } from "./EditorFace";
2
2
  import type { FontResolution } from "./FontResolution";
3
3
  import type { ParagraphSegment } from "./ParagraphSegment";
4
+ import type { PushDown } from "./PushDown";
4
5
  import type { Rect } from "./Rect";
5
6
  import type { StyleSpan } from "./StyleSpan";
6
7
  import type { TextLook } from "./TextLook";
@@ -23,6 +24,17 @@ export type ParagraphInfo = {
23
24
  wrapWidth: number;
24
25
  maxHeight: number;
25
26
  maxLines: number;
27
+ /**
28
+ * ADR 0015's extended width (never below `wrapWidth`), used only when the text does not fit
29
+ * `wrapWidth`, and its line budget.
30
+ */
31
+ maxWrapWidth: number;
32
+ maxWrapLines: number;
33
+ /**
34
+ * ADR 0015: the line budget at `maxWrapWidth` with `reflow: 'pushDown'` and the region it
35
+ * would move at that budget; null when nothing below can move.
36
+ */
37
+ pushDown: PushDown | null;
26
38
  originalText: string | null;
27
39
  font: FontResolution;
28
40
  editorFace?: EditorFace | null;
@@ -0,0 +1,11 @@
1
+ import type { Rect } from "./Rect";
2
+ /**
3
+ * [`ParagraphInfo::push_down`].
4
+ */
5
+ export type PushDown = {
6
+ maxLines: number;
7
+ /**
8
+ * Display space, before the push.
9
+ */
10
+ region: Rect;
11
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * `TextEdit.reflow` (ADR 0015): what an edit that needs more lines than fit does.
3
+ */
4
+ export type Reflow = "none" | "pushDown";
@@ -0,0 +1,2 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ export {};
@@ -1,4 +1,5 @@
1
1
  import type { Rect } from "./Rect";
2
+ import type { Reflow } from "./Reflow";
2
3
  export type TextEdit = {
3
4
  id: string;
4
5
  pageIndex: number;
@@ -8,4 +9,8 @@ export type TextEdit = {
8
9
  * A registered `fontId`.
9
10
  */
10
11
  font?: string;
12
+ /**
13
+ * Omitted = `none`.
14
+ */
15
+ reflow?: Reflow;
11
16
  };
package/dist/index.d.ts CHANGED
@@ -10,6 +10,9 @@ export type { Capabilities } from "./generated/Capabilities.js";
10
10
  export type { ChangeResult } from "./generated/ChangeResult.js";
11
11
  export type { ChangeSet } from "./generated/ChangeSet.js";
12
12
  export type { TextEdit } from "./generated/TextEdit.js";
13
+ export type { Reflow } from "./generated/Reflow.js";
14
+ export type { PageShift } from "./generated/PageShift.js";
15
+ export type { PushDown } from "./generated/PushDown.js";
13
16
  export type { Redaction } from "./generated/Redaction.js";
14
17
  export type { RejectedChange } from "./generated/RejectedChange.js";
15
18
  export type { EditLayout } from "./generated/EditLayout.js";
package/dist/protocol.js CHANGED
@@ -143,7 +143,8 @@ const isRegisteredFont = shape({
143
143
  const isMode = (x) => x === "native" || x === "raster";
144
144
  /** Rust serializes an absent `Option` as null. */
145
145
  const optNull = (g) => (x) => x === undefined || x === null || g(x);
146
- const isTextEdit = shape({ id: isStr, pageIndex: isU32, rects: arrayOf(isRect), text: isStr, font: optNull(isStr) });
146
+ const isReflow = (x) => x === "none" || x === "pushDown";
147
+ const isTextEdit = shape({ id: isStr, pageIndex: isU32, rects: arrayOf(isRect), text: isStr, font: optNull(isStr), reflow: optNull(isReflow) });
147
148
  const isRedaction = (x) => shape({ id: isStr, pageIndex: isU32, fill: optNull(isRgb) })(x) &&
148
149
  (x.kind === "region" ? isRect(x.rect) : x.kind === "text" && isU32(x.start) && isU32(x.end));
149
150
  const isChangeSet = shape({ baseRevision: isU32, textEdits: opt(arrayOf(isTextEdit)), redactions: opt(arrayOf(isRedaction)) });
@@ -151,16 +152,18 @@ const isLayoutRun = shape({ source: (x) => x === "embedded" || x === "registered
151
152
  const isEditLayout = shape({
152
153
  id: isStr, lines: isU32, approximate: isBool, fingerprint: isStr, runs: arrayOf(isLayoutRun),
153
154
  });
155
+ const isPageShift = shape({ pageIndex: isU32, region: isRect, dy: isNum });
154
156
  const isEditPreview = shape({
155
157
  docId: isStr, revision: isU32, fontRegistryVersion: isU32, fontSize: isNum,
156
158
  lines: arrayOf(shape({ text: isStr, baseline: isNum, x: isNum, width: isNum })),
157
- neededLines: isU32, maxLines: isU32, fits: isBool, approximate: isBool, runs: arrayOf(isLayoutRun), fingerprint: isStr,
159
+ neededLines: isU32, maxLines: isU32, wrapWidth: isNum, fits: isBool, approximate: isBool, runs: arrayOf(isLayoutRun), fingerprint: isStr,
158
160
  glyphs: opt(arrayOf(shape({ line: isU32, font: isStr, gid: isU32, start: isU32, end: isU32, x: isNum, width: isNum }))),
161
+ shift: optNull(isPageShift), reflowBlocked: optNull(isStr),
159
162
  });
160
163
  const isChangeResult = shape({
161
164
  accepted: isBool, revision: isU32,
162
165
  rejected: arrayOf(shape({ id: isStr, code: isErrorCode, details: optNull(isRec) })),
163
- changedPages: arrayOf(isU32), layouts: arrayOf(isEditLayout),
166
+ changedPages: arrayOf(isU32), layouts: arrayOf(isEditLayout), remap: arrayOf(isPageShift),
164
167
  });
165
168
  export const argsGuards = (maxBytes = DEFAULT_MAX_BUFFER_BYTES) => ({
166
169
  init: shape({ wasmUrl: isStr, cmapsUrl: opt(isStr), limits: opt(isRec), fontMatch: opt(arrayOf(shape({ pattern: isStr, family: isStr }))) }),
@@ -180,7 +183,7 @@ export const argsGuards = (maxBytes = DEFAULT_MAX_BUFFER_BYTES) => ({
180
183
  page: isU32, scale: opt((x) => isNum(x) && x > 0), clip: opt(isRect), annotations: opt(isBool), background: opt(tuple(4)),
181
184
  }),
182
185
  prepareParagraph: shape({ page: isU32, rects: arrayOf(isRect), font: opt(isStr), editorFace: opt(isBool) }),
183
- layoutEdit: shape({ page: isU32, rects: arrayOf(isRect), text: isStr, font: opt(isStr), glyphs: opt(isBool) }),
186
+ layoutEdit: shape({ page: isU32, rects: arrayOf(isRect), text: isStr, font: opt(isStr), glyphs: opt(isBool), reflow: opt(isReflow) }),
184
187
  applyChanges: shape({ changes: isChangeSet }),
185
188
  prepareExport: shape({ mode: isMode, policy: opt(isRec) }),
186
189
  export: shape({ planId: isStr }),
@@ -158,7 +158,7 @@ export function createWorkerCore(host, stepBudget = STEP_BUDGET) {
158
158
  return { result: r, transfer: faces.map((face) => face.bytes) };
159
159
  }
160
160
  case "layoutEdit":
161
- return { result: e.layoutEdit(d, a.page, a.rects, a.text, a.font, a.glyphs) };
161
+ return { result: e.layoutEdit(d, a.page, a.rects, a.text, a.font, a.glyphs, a.reflow) };
162
162
  case "export": {
163
163
  const bytes = ownBuffer(e.takeExport(d, a.planId));
164
164
  return { result: bytes, transfer: [bytes] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zilijonas/foliark",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Rust/WebAssembly PDF SDK for the browser: extract text, render, edit, redact and sanitize PDFs offline. A PyMuPDF alternative. AGPL-3.0.",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",
@@ -17,7 +17,7 @@ export class Engine {
17
17
  /**
18
18
  * ADR 0004: the layout an edit would commit, nothing committed.
19
19
  */
20
- layoutEdit(doc: string, page: number, rects: any, text: string, font?: string | null, glyphs?: boolean | null): any;
20
+ layoutEdit(doc: string, page: number, rects: any, text: string, font: string | null | undefined, glyphs: boolean | null | undefined, reflow: any): any;
21
21
  /**
22
22
  * `limits`: a `Partial<Limits>` (or undefined); `generation`: the worker generation;
23
23
  * `font_match`: `FontMatchRule[]` replacing the default table (or undefined).
@@ -72,7 +72,7 @@ export interface InitOutput {
72
72
  readonly engine_fontRegistryVersion: (a: number) => number;
73
73
  readonly engine_hitTest: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
74
74
  readonly engine_info: (a: number, b: number, c: number, d: number) => void;
75
- readonly engine_layoutEdit: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => void;
75
+ readonly engine_layoutEdit: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
76
76
  readonly engine_new: (a: number, b: number, c: number, d: number) => void;
77
77
  readonly engine_open: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
78
78
  readonly engine_pages: (a: number, b: number, c: number, d: number) => void;
@@ -85,11 +85,12 @@ export class Engine {
85
85
  * @param {number} page
86
86
  * @param {any} rects
87
87
  * @param {string} text
88
- * @param {string | null} [font]
89
- * @param {boolean | null} [glyphs]
88
+ * @param {string | null | undefined} font
89
+ * @param {boolean | null | undefined} glyphs
90
+ * @param {any} reflow
90
91
  * @returns {any}
91
92
  */
92
- layoutEdit(doc, page, rects, text, font, glyphs) {
93
+ layoutEdit(doc, page, rects, text, font, glyphs, reflow) {
93
94
  try {
94
95
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
95
96
  const ptr0 = passStringToWasm0(doc, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -98,7 +99,7 @@ export class Engine {
98
99
  const len1 = WASM_VECTOR_LEN;
99
100
  var ptr2 = isLikeNone(font) ? 0 : passStringToWasm0(font, wasm.__wbindgen_export, wasm.__wbindgen_export2);
100
101
  var len2 = WASM_VECTOR_LEN;
101
- wasm.engine_layoutEdit(retptr, this.__wbg_ptr, ptr0, len0, page, addHeapObject(rects), ptr1, len1, ptr2, len2, isLikeNone(glyphs) ? 0xFFFFFF : glyphs ? 1 : 0);
102
+ wasm.engine_layoutEdit(retptr, this.__wbg_ptr, ptr0, len0, page, addHeapObject(rects), ptr1, len1, ptr2, len2, isLikeNone(glyphs) ? 0xFFFFFF : glyphs ? 1 : 0, addHeapObject(reflow));
102
103
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
103
104
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
104
105
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
Binary file
@@ -7,7 +7,7 @@ export const engine_close: (a: number, b: number, c: number) => void;
7
7
  export const engine_fontRegistryVersion: (a: number) => number;
8
8
  export const engine_hitTest: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
9
9
  export const engine_info: (a: number, b: number, c: number, d: number) => void;
10
- export const engine_layoutEdit: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => void;
10
+ export const engine_layoutEdit: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
11
11
  export const engine_new: (a: number, b: number, c: number, d: number) => void;
12
12
  export const engine_open: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
13
13
  export const engine_pages: (a: number, b: number, c: number, d: number) => void;