@silurus/ooxml 0.57.0 → 0.59.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.
@@ -62,7 +62,12 @@ export declare interface DocComment {
62
62
 
63
63
  export declare interface DocNote {
64
64
  id: string;
65
- text: string;
65
+ /** ECMA-376 §17.11.2 / §17.11.10 — the note's block-level content
66
+ * (paragraphs / nested tables), parsed with the document's styles +
67
+ * numbering. The leading run is the `<w:footnoteRef/>` auto-number marker
68
+ * (carries a {@link DocxTextRun.noteRef}). Use {@link noteText} to extract
69
+ * the plain-text body without the marker. */
70
+ content: BodyElement[];
66
71
  }
67
72
 
68
73
  export declare interface DocParagraph {
@@ -104,10 +109,21 @@ export declare interface DocParagraph {
104
109
  defaultFontFamily?: string | null;
105
110
  /**
106
111
  * ECMA-376 §17.3.1.6 `<w:bidi>` — right-to-left paragraph. `true` = RTL,
107
- * `false` = explicitly LTR, absent = unspecified (inherit). Phase 0 of RTL
108
- * support: recorded only; alignment/column-order resolution is deferred.
112
+ * `false` = explicitly LTR, absent = unspecified (inherit). The renderer uses
113
+ * this as the paragraph base direction: it seeds the UAX#9 reordering pass
114
+ * (`computeLineVisualOrder`), swaps the left/right indents, resolves the
115
+ * `w:jc` start/end edges (`resolveAlignEdge`), and lays out lines from the
116
+ * right.
109
117
  */
110
118
  bidi?: boolean;
119
+ /**
120
+ * ECMA-376 §17.3.1.32 `<w:snapToGrid>` — when `false`, this paragraph opts out
121
+ * of the section's document grid (`w:docGrid`): its lines use natural font
122
+ * metrics / the line-spacing multiplier directly instead of snapping to the
123
+ * grid pitch. `undefined` = inherit (default on). Set on Word's "Footnote
124
+ * Text" style, so footnote bodies use compact natural line height.
125
+ */
126
+ snapToGrid?: boolean;
111
127
  }
112
128
 
113
129
  export declare interface DocRevision {
@@ -135,6 +151,7 @@ export declare type DocRun = {
135
151
  nodes: MathNode[];
136
152
  display: boolean;
137
153
  fontSize: number;
154
+ jc?: string;
138
155
  };
139
156
 
140
157
  export declare interface DocSettings {
@@ -148,6 +165,10 @@ export declare interface DocSettings {
148
165
  /** §17.15.1.59 `w:noLineBreaksAfter@w:val` — custom set of characters that
149
166
  * cannot end a line (行末禁則). Replaces the default when present. */
150
167
  noLineBreaksAfter?: string;
168
+ /** §22.1.2.30 `m:mathPr/m:defJc@m:val` — document-wide default math
169
+ * justification (ST_Jc math: left|right|center|centerGroup). `undefined`
170
+ * ⇒ the renderer uses the spec default `centerGroup`. */
171
+ mathDefJc?: string;
151
172
  }
152
173
 
153
174
  export declare interface DocTable {
@@ -172,8 +193,8 @@ export declare interface DocTable {
172
193
  /**
173
194
  * ECMA-376 §17.4.1 `<w:bidiVisual>` — render columns in right-to-left
174
195
  * (visual) order. `true` = RTL columns, `false` = explicitly LTR, absent =
175
- * unspecified. Phase 0 of RTL support: recorded only; column-order
176
- * resolution is deferred.
196
+ * unspecified. When `true` the renderer mirrors the grid so logical column 0
197
+ * is placed rightmost, and flips per-cell left/right borders accordingly.
177
198
  */
178
199
  bidiVisual?: boolean;
179
200
  }
@@ -212,7 +233,9 @@ export declare interface DocTableRow {
212
233
 
213
234
  export declare class DocxDocument {
214
235
  private _document;
236
+ private _meta;
215
237
  private _pages;
238
+ private _mode;
216
239
  private _worker;
217
240
  private _bridge;
218
241
  private constructor();
@@ -220,9 +243,46 @@ export declare class DocxDocument {
220
243
  private _parse;
221
244
  destroy(): void;
222
245
  get pageCount(): number;
246
+ /**
247
+ * The raw parsed document model. Available only in `mode: 'main'`; in
248
+ * `mode: 'worker'` the model stays in the worker and this throws.
249
+ */
223
250
  get document(): DocxDocumentModel;
251
+ /**
252
+ * ECMA-376 §17.13.4 — the document's comments (`word/comments.xml`), each with
253
+ * id / author / initials / date / plain-text body. Comments are a data-only
254
+ * API: they are NOT drawn on the page (Word renders them in a margin pane /
255
+ * balloons, which this viewer does not reproduce). Use this to build a review
256
+ * panel, export an annotation list, etc. Returns `[]` when the document has no
257
+ * comments part. The same data is also reachable via `document.comments`.
258
+ */
259
+ get comments(): DocComment[];
260
+ /**
261
+ * ECMA-376 §17.11.10 — the document's footnotes (`word/footnotes.xml`),
262
+ * excluding the reserved separator entries. Each note carries its `id` and
263
+ * block-level `content`; use {@link noteText} for the plain-text body. These
264
+ * ARE drawn at the bottom of the page that holds their reference; this getter
265
+ * additionally exposes them as data. Returns `[]` when absent.
266
+ */
267
+ get footnotes(): DocNote[];
268
+ /**
269
+ * ECMA-376 §17.11.4 — the document's endnotes (`word/endnotes.xml`). Same
270
+ * shape as {@link footnotes}; rendered at the end of the document. Returns
271
+ * `[]` when absent.
272
+ */
273
+ get endnotes(): DocNote[];
224
274
  private _getPages;
225
275
  renderPage(target: HTMLCanvasElement | OffscreenCanvas, pageIndex: number, opts?: RenderPageOptions): Promise<void>;
276
+ /**
277
+ * Render a page and return it as an ImageBitmap. Works in both modes; in
278
+ * worker mode the render runs entirely off the main thread. Paint with:
279
+ * `canvas.getContext('bitmaprenderer').transferFromImageBitmap(bitmap)`.
280
+ *
281
+ * The returned ImageBitmap is owned by the caller: pass it to
282
+ * `transferFromImageBitmap` (which consumes it) or call `bitmap.close()`
283
+ * when done, or its backing memory is held until GC.
284
+ */
285
+ renderPageToBitmap(pageIndex: number, opts?: WireRenderPageOptions): Promise<ImageBitmap>;
226
286
  }
227
287
 
228
288
  export declare interface DocxDocumentModel {
@@ -291,8 +351,10 @@ export declare interface DocxTextRun {
291
351
  * tracked changes appear inline. */
292
352
  revision?: RunRevision;
293
353
  /** ECMA-376 §17.3.2.30 `<w:rtl>` — complex-script / right-to-left run.
294
- * `true` = RTL, `false` = explicitly LTR, absent = unspecified.
295
- * Phase 0: recorded only; glyph-order resolution is deferred. */
354
+ * `true` = RTL, `false` = explicitly LTR, absent = unspecified. The renderer
355
+ * treats a `true` run as RTL for the UAX#9 pass (it forces complex-script
356
+ * shaping and marks the segment so `computeLineVisualOrder` reorders it), and
357
+ * draws the slice with `ctx.direction = 'rtl'` so Canvas mirrors the glyphs. */
296
358
  rtl?: boolean;
297
359
  /** ECMA-376 §17.3.2.7 `<w:cs/>` — complex-script run toggle: cs formatting
298
360
  * applies to ALL characters of the run (§17.3.2.26). Distinct from
@@ -311,6 +373,12 @@ export declare interface DocxTextRun {
311
373
  /** ECMA-376 §17.3.2.20 `<w:lang w:bidi>` — complex-script (RTL) language tag,
312
374
  * lower-cased (e.g. "ar-sa", "ae-ar"). Drives Word's AN digit ordering. */
313
375
  langBidi?: string;
376
+ /** ECMA-376 §17.11.6/.7/.16/.17 — set when this run is a footnote/endnote
377
+ * reference marker (`<w:footnoteReference>` in the body, `<w:footnoteRef>` at
378
+ * the start of the note's content, and the endnote equivalents). `text` holds
379
+ * the raw `@w:id`; the renderer overrides the displayed glyph with the note's
380
+ * sequential number. */
381
+ noteRef?: NoteRef;
314
382
  }
315
383
 
316
384
  /** Information about a rendered text segment for building a transparent selection overlay. */
@@ -337,6 +405,12 @@ export declare class DocxViewer {
337
405
  private _wrapper;
338
406
  private _textLayer;
339
407
  private _opts;
408
+ private readonly _mode;
409
+ /** The canvas's bitmaprenderer context, used only in worker mode (a canvas
410
+ * holds one context type for its lifetime; the main-mode 2d render path is
411
+ * never used on the same canvas). */
412
+ private _bitmapCtx;
413
+ private _warnedNoTextSelection;
340
414
  constructor(canvas: HTMLCanvasElement, opts?: DocxViewerOptions);
341
415
  /**
342
416
  * Load a DOCX from URL or ArrayBuffer and render the first page.
@@ -473,6 +547,14 @@ export declare interface LoadOptions extends LoadOptions_2 {
473
547
  * omitted, equations are skipped and the ~3 MB engine never enters the bundle.
474
548
  */
475
549
  math?: MathRenderer;
550
+ /**
551
+ * 'main' (default): parse in a worker, render on the main thread (current
552
+ * behaviour). 'worker': parse, paginate AND render inside the worker; use
553
+ * {@link DocxDocument.renderPageToBitmap} and paint the returned ImageBitmap
554
+ * via an `ImageBitmapRenderingContext`. Requires OffscreenCanvas. The math
555
+ * engine is unavailable in this mode (equations are skipped).
556
+ */
557
+ mode?: 'main' | 'worker';
476
558
  }
477
559
 
478
560
  /**
@@ -648,6 +730,20 @@ declare interface MathSvg {
648
730
  descentEm: number;
649
731
  }
650
732
 
733
+ /** A footnote / endnote reference marker (ECMA-376 §17.11). */
734
+ export declare interface NoteRef {
735
+ /** "footnote" | "endnote" */
736
+ kind: 'footnote' | 'endnote' | string;
737
+ /** `@w:id` linking the marker to its note. Empty for the in-note
738
+ * `<w:footnoteRef/>` placeholder (the renderer uses the enclosing note). */
739
+ id: string;
740
+ }
741
+
742
+ /** Flatten a footnote/endnote's content to its plain-text body, excluding the
743
+ * auto-number reference marker. Convenience for data-only consumers
744
+ * (the renderer draws {@link DocNote.content} directly). */
745
+ export declare function noteText(note: DocNote): string;
746
+
651
747
  export declare interface NumberingInfo {
652
748
  numId: number;
653
749
  level: number;
@@ -858,4 +954,7 @@ export declare interface TabStop {
858
954
  leader: 'none' | 'dot' | 'hyphen' | 'underscore' | 'heavy' | 'middleDot';
859
955
  }
860
956
 
957
+ /** Serializable subset of RenderPageOptions (callbacks cannot cross the wire). */
958
+ export declare type WireRenderPageOptions = Omit<RenderPageOptions, 'onTextRun'>;
959
+
861
960
  export { }