@laminapdf/wasm 0.2.0-alpha.2 → 0.2.0-alpha.3

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.
Binary file
@@ -1,7 +1,7 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
- /** A page's text as `WasmPage.text` returns it (B9c). */
4
+ /** A page's text as `WasmPage.text` returns it. */
5
5
  export interface PageTextJs {
6
6
  /** The text by line, in content order (runs on one baseline, joined; trimmed). */
7
7
  lines: string[];
@@ -196,6 +196,24 @@ export type AfRelationshipInit = "source" | "data" | "alternative" | "supplement
196
196
  */
197
197
  export type UndoOutcomeJs = "applied" | "partial" | "skipped";
198
198
 
199
+ /**
200
+ * How the Markdown is cut into chunks.
201
+ */
202
+ export interface ChunkInit {
203
+ /**
204
+ * A chunk's budget in approximate tokens (characters / 4); 512 by default.
205
+ */
206
+ maxTokens?: number;
207
+ /**
208
+ * Approximate tokens of whole blocks repeated from the chunk before; 0 by default.
209
+ */
210
+ overlap?: number;
211
+ /**
212
+ * Where chunks may start; `"headings"` by default.
213
+ */
214
+ splitOn?: SplitOnName;
215
+ }
216
+
199
217
  /**
200
218
  * How viewers present the document when it opens.
201
219
  */
@@ -306,7 +324,7 @@ export interface PageLabelInit {
306
324
  }
307
325
 
308
326
  /**
309
- * One text run (`laminapdf::extract::TextRun`): glyphs of one font, size, direction and marked
327
+ * One text run (`laminapdf::extract::PageTextRun`): glyphs of one font, size, direction and marked
310
328
  * content on one baseline, in logical order.
311
329
  */
312
330
  export interface TextRunJs {
@@ -348,6 +366,44 @@ export interface TextRunJs {
348
366
  glyphs: [number, number];
349
367
  }
350
368
 
369
+ /**
370
+ * Options for `WasmDocument.extract`.
371
+ */
372
+ export interface ExtractInit {
373
+ /**
374
+ * What to return.
375
+ */
376
+ format: ExtractFormat;
377
+ /**
378
+ * The 0-based page indices to extract, in this order; every page by default.
379
+ */
380
+ pages?: number[];
381
+ /**
382
+ * Where the reading order comes from; `"auto"` by default.
383
+ */
384
+ readingOrder?: ReadingOrderName;
385
+ /**
386
+ * What happens to hidden text.
387
+ */
388
+ drop?: DropInit;
389
+ /**
390
+ * Which table detectors run; `"lattice"` by default.
391
+ */
392
+ tables?: TableModeName;
393
+ /**
394
+ * Join words hyphenated across lines; on by default.
395
+ */
396
+ dehyphenate?: boolean;
397
+ /**
398
+ * Write `<!-- page N -->` before each page's first block (Markdown, chunks and JSON).
399
+ */
400
+ pageMarkers?: boolean;
401
+ /**
402
+ * How chunks are cut (`chunks`, and `json` to include them).
403
+ */
404
+ chunk?: ChunkInit;
405
+ }
406
+
351
407
  /**
352
408
  * Options for `WasmDocument.openBytes`.
353
409
  */
@@ -573,6 +629,11 @@ export type PageModeInit = "none" | "outlines" | "thumbnails" | "fullScreen" | "
573
629
  */
574
630
  export type SaveModeJs = "auto" | "incremental" | "fullRewrite";
575
631
 
632
+ /**
633
+ * What `WasmDocument.extract` returns.
634
+ */
635
+ export type ExtractFormat = "markdown" | "json" | "text" | "chunks";
636
+
576
637
  /**
577
638
  * What a save wrote (`laminapdf::SaveReport`).
578
639
  */
@@ -608,11 +669,41 @@ export interface SaveReportJs {
608
669
  */
609
670
  export type OutputJs = "whole" | "appendedOnly";
610
671
 
672
+ /**
673
+ * What happens to hidden text and page furniture.
674
+ */
675
+ export interface DropInit {
676
+ /**
677
+ * Keep each dropped run's text in its `dropped` entry (JSON only), for auditing a file.
678
+ */
679
+ keepSpans?: boolean;
680
+ /**
681
+ * Drop running headers, footers, page numbers and artifact-marked text too, listing them
682
+ * in `dropped`; on by default.
683
+ */
684
+ furniture?: boolean;
685
+ }
686
+
611
687
  /**
612
688
  * Where a link or outline item goes.
613
689
  */
614
690
  export type LinkTargetInit = { type: "uri"; uri: string } | { type: "page"; index: number; fit?: FitInit } | { type: "named"; name: string };
615
691
 
692
+ /**
693
+ * Where chunks may start.
694
+ */
695
+ export type SplitOnName = "headings" | "blocks" | "pages";
696
+
697
+ /**
698
+ * Where the reading order comes from.
699
+ */
700
+ export type ReadingOrderName = "auto" | "tagged" | "layout" | "content-stream";
701
+
702
+ /**
703
+ * Which table detectors run.
704
+ */
705
+ export type TableModeName = "off" | "lattice" | "lattice-and-stream";
706
+
616
707
  /**
617
708
  * `Limits` with every field optional (ADR 0003 §3; names as in Rust, camelCase).
618
709
  */
@@ -782,6 +873,15 @@ export class WasmDocument {
782
873
  * error (nothing is applied).
783
874
  */
784
875
  apply(ops: Op[]): EditedJs;
876
+ /**
877
+ * The document's text for retrieval and LLMs, as one string: Markdown, plain text, the
878
+ * `laminapdf.extract/1` JSON, or the chunks as a JSON array (the extract and text modules).
879
+ *
880
+ * # Errors
881
+ * `page-index-out-of-range` for a page in `pages` past the end; `data-pending` and the
882
+ * reading errors; `unknown-option` / `invalid-argument` for bad options.
883
+ */
884
+ extract(options: ExtractInit): string;
785
885
  /**
786
886
  * Whether there are changes no save has written yet.
787
887
  */
@@ -935,7 +1035,8 @@ export class WasmPage {
935
1035
  * The page's current 0-based index.
936
1036
  *
937
1037
  * # Errors
938
- * `unknown-page` when the page is gone; reading errors.
1038
+ * `unknown-page` when the page is gone; `disposed` when its document is freed; reading
1039
+ * errors.
939
1040
  */
940
1041
  index(): number;
941
1042
  /**
@@ -946,12 +1047,12 @@ export class WasmPage {
946
1047
  */
947
1048
  info(): PageInfoJs;
948
1049
  /**
949
- * The page's text: lines, runs, glyph quads and glyph text (B9c; the extract and text
950
- * modules).
1050
+ * The page's text: lines, runs, glyph quads and glyph text (the extract and text modules).
951
1051
  *
952
1052
  * # Errors
953
- * `unknown-page` when the page is gone; `data-pending` and the reading errors;
954
- * `unknown-option` / `invalid-argument` for bad options.
1053
+ * `unknown-page` when the page is gone; `disposed` when its document is freed;
1054
+ * `data-pending` and the reading errors; `unknown-option` / `invalid-argument` for bad
1055
+ * options.
955
1056
  */
956
1057
  text(options: TextOptionsInit | undefined): PageTextJs;
957
1058
  /**
@@ -1155,7 +1256,8 @@ export class WasmSaveJob {
1155
1256
  * `{ state: "done", bytes, report }`.
1156
1257
  *
1157
1258
  * # Errors
1158
- * `cancelled`, `document-changed`, `job-finished`, or the save's own errors.
1259
+ * `cancelled`, `document-changed`, `job-finished`, `disposed` when the document is freed,
1260
+ * or the save's own errors.
1159
1261
  */
1160
1262
  step(budget: number): ({ state: "progress" } & ProgressJs) | { state: "done"; bytes: Uint8Array<ArrayBuffer>; report: SaveReportJs };
1161
1263
  }
@@ -1214,6 +1316,14 @@ export class WasmWarningCursor {
1214
1316
  remaining(): number;
1215
1317
  }
1216
1318
 
1319
+ export function __wbg_reset_state(): void;
1320
+
1321
+ /**
1322
+ * Whether the most recent allocation failed: after a trap, `true` means the module ran out of
1323
+ * memory.
1324
+ */
1325
+ export function allocationFailed(): boolean;
1326
+
1217
1327
  /**
1218
1328
  * Whether this module is the text module (fonts, `text`, `textBox`).
1219
1329
  */
@@ -1236,6 +1346,7 @@ export interface InitOutput {
1236
1346
  readonly __wbg_wasmsavejob_free: (a: number, b: number) => void;
1237
1347
  readonly __wbg_wasmsparsesource_free: (a: number, b: number) => void;
1238
1348
  readonly __wbg_wasmwarningcursor_free: (a: number, b: number) => void;
1349
+ readonly allocationFailed: () => number;
1239
1350
  readonly hasText: () => number;
1240
1351
  readonly version: () => [number, number];
1241
1352
  readonly wasmbuilder_attach: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: any) => [number, number];
@@ -1250,6 +1361,7 @@ export interface InitOutput {
1250
1361
  readonly wasmbuilder_viewerPreferences: (a: number, b: any) => [number, number];
1251
1362
  readonly wasmdocument_apply: (a: number, b: any) => [number, number, number];
1252
1363
  readonly wasmdocument_applyLog: (a: number, b: number, c: number) => [number, number, number];
1364
+ readonly wasmdocument_extract: (a: number, b: any) => [number, number, number, number];
1253
1365
  readonly wasmdocument_hasUnsavedChanges: (a: number) => number;
1254
1366
  readonly wasmdocument_info: (a: number) => [number, number, number];
1255
1367
  readonly wasmdocument_openBytes: (a: number, b: number, c: any) => [number, number, number];