@silurus/ooxml 0.1.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.
@@ -0,0 +1,286 @@
1
+ declare type BodyElement = {
2
+ type: 'paragraph';
3
+ } & DocParagraph | {
4
+ type: 'table';
5
+ } & DocTable | {
6
+ type: 'pageBreak';
7
+ };
8
+
9
+ declare interface BorderSpec {
10
+ width: number;
11
+ color: string | null;
12
+ style: string;
13
+ }
14
+
15
+ declare interface CellBorders {
16
+ top: BorderSpec | null;
17
+ bottom: BorderSpec | null;
18
+ left: BorderSpec | null;
19
+ right: BorderSpec | null;
20
+ }
21
+
22
+ export declare interface DocParagraph {
23
+ alignment: 'left' | 'center' | 'right' | 'justify';
24
+ indentLeft: number;
25
+ indentRight: number;
26
+ indentFirst: number;
27
+ spaceBefore: number;
28
+ spaceAfter: number;
29
+ lineSpacing: LineSpacing | null;
30
+ numbering: NumberingInfo | null;
31
+ tabStops: TabStop[];
32
+ runs: DocRun[];
33
+ /** Paragraph background hex color (w:shd fill) */
34
+ shading?: string | null;
35
+ /** Force a page break before this paragraph (w:pageBreakBefore) */
36
+ pageBreakBefore?: boolean;
37
+ /** Suppress spacing between adjacent same-style paragraphs (w:contextualSpacing) */
38
+ contextualSpacing?: boolean;
39
+ /** Paragraph borders (w:pBdr) */
40
+ borders?: ParagraphBorders | null;
41
+ /** Style ID of the applied paragraph style */
42
+ styleId?: string | null;
43
+ /** Default font size (pt) inherited from style + direct pPr/rPr. Falls back to 10pt. */
44
+ defaultFontSize?: number;
45
+ }
46
+
47
+ export declare type DocRun = {
48
+ type: 'text';
49
+ } & TextRun | {
50
+ type: 'image';
51
+ } & ImageRun | {
52
+ type: 'break';
53
+ breakType: 'line' | 'page' | 'column';
54
+ } | {
55
+ type: 'field';
56
+ } & FieldRun;
57
+
58
+ declare interface DocTable {
59
+ colWidths: number[];
60
+ rows: DocTableRow[];
61
+ borders: TableBorders;
62
+ cellMarginTop: number;
63
+ cellMarginBottom: number;
64
+ cellMarginLeft: number;
65
+ cellMarginRight: number;
66
+ }
67
+
68
+ declare interface DocTableCell {
69
+ content: DocParagraph[];
70
+ colSpan: number;
71
+ vMerge: boolean | null;
72
+ borders: CellBorders;
73
+ background: string | null;
74
+ vAlign: 'top' | 'center' | 'bottom';
75
+ widthPt: number | null;
76
+ }
77
+
78
+ declare interface DocTableRow {
79
+ cells: DocTableCell[];
80
+ rowHeight: number | null;
81
+ isHeader: boolean;
82
+ }
83
+
84
+ declare interface Document_2 {
85
+ section: SectionProps;
86
+ body: BodyElement[];
87
+ headers: HeadersFooters;
88
+ footers: HeadersFooters;
89
+ }
90
+ export { Document_2 as Document }
91
+
92
+ export declare class DocxDocument {
93
+ private _document;
94
+ private _pages;
95
+ private _worker;
96
+ private constructor();
97
+ static load(source: string | ArrayBuffer): Promise<DocxDocument>;
98
+ private _parse;
99
+ destroy(): void;
100
+ get pageCount(): number;
101
+ get document(): Document_2;
102
+ private _getPages;
103
+ renderPage(target: HTMLCanvasElement | OffscreenCanvas, pageIndex: number, opts?: RenderPageOptions): Promise<void>;
104
+ }
105
+
106
+ export declare class DocxViewer {
107
+ private _doc;
108
+ private _currentPage;
109
+ private _canvas;
110
+ private _opts;
111
+ constructor(canvas: HTMLCanvasElement, opts?: DocxViewerOptions);
112
+ load(source: string | ArrayBuffer): Promise<void>;
113
+ get pageCount(): number;
114
+ get currentPage(): number;
115
+ goToPage(index: number): void;
116
+ nextPage(): void;
117
+ prevPage(): void;
118
+ private _render;
119
+ }
120
+
121
+ declare interface DocxViewerOptions extends RenderPageOptions {
122
+ container?: HTMLElement;
123
+ }
124
+
125
+ declare interface FieldRun {
126
+ /** "page" | "numPages" | "other" */
127
+ fieldType: string;
128
+ instruction: string;
129
+ fallbackText: string;
130
+ bold: boolean;
131
+ italic: boolean;
132
+ underline: boolean;
133
+ strikethrough: boolean;
134
+ fontSize: number;
135
+ color: string | null;
136
+ fontFamily: string | null;
137
+ background: string | null;
138
+ vertAlign: 'super' | 'sub' | null;
139
+ allCaps?: boolean;
140
+ smallCaps?: boolean;
141
+ doubleStrikethrough?: boolean;
142
+ highlight?: string | null;
143
+ }
144
+
145
+ declare interface HeaderFooter {
146
+ body: BodyElement[];
147
+ }
148
+
149
+ declare interface HeadersFooters {
150
+ default: HeaderFooter | null;
151
+ first: HeaderFooter | null;
152
+ even: HeaderFooter | null;
153
+ }
154
+
155
+ export declare interface ImageRun {
156
+ dataUrl: string;
157
+ widthPt: number;
158
+ heightPt: number;
159
+ /** true = wp:anchor (absolute positioned), false/undefined = wp:inline (flows with text) */
160
+ anchor?: boolean;
161
+ /** X offset in pt (anchor only) */
162
+ anchorXPt?: number;
163
+ /** Y offset in pt (anchor only) */
164
+ anchorYPt?: number;
165
+ /**
166
+ * If true, anchorXPt is relative to the left margin — add section.marginLeft to get page X.
167
+ * If false/absent, anchorXPt is already page-absolute.
168
+ */
169
+ anchorXFromMargin?: boolean;
170
+ /**
171
+ * If true, anchorYPt is relative to the paragraph's top Y in the renderer.
172
+ * If false/absent, anchorYPt is already page-absolute.
173
+ */
174
+ anchorYFromPara?: boolean;
175
+ /**
176
+ * When set, the renderer replaces all pixels of this hex color (e.g. "FFFFFF") with full
177
+ * transparency. Implements a:clrChange (make-background-transparent).
178
+ */
179
+ colorReplaceFrom?: string;
180
+ /**
181
+ * Wrap mode for anchor images:
182
+ * "square" | "topAndBottom" | "none" | "tight" | "through"
183
+ * Inline images and undetermined cases leave this undefined.
184
+ * MVP renders "tight" and "through" as "square".
185
+ */
186
+ wrapMode?: string;
187
+ /** Padding top (pt). Anchor-only. */
188
+ distTop?: number;
189
+ /** Padding bottom (pt). Anchor-only. */
190
+ distBottom?: number;
191
+ /** Padding left (pt). Anchor-only. */
192
+ distLeft?: number;
193
+ /** Padding right (pt). Anchor-only. */
194
+ distRight?: number;
195
+ /** wrapText attribute: "bothSides" | "left" | "right" | "largest". */
196
+ wrapSide?: string;
197
+ }
198
+
199
+ declare interface LineSpacing {
200
+ value: number;
201
+ rule: 'auto' | 'exact' | 'atLeast';
202
+ }
203
+
204
+ declare interface NumberingInfo {
205
+ numId: number;
206
+ level: number;
207
+ format: string;
208
+ text: string;
209
+ indentLeft: number;
210
+ tab: number;
211
+ }
212
+
213
+ declare interface ParaBorderEdge {
214
+ style: string;
215
+ color: string | null;
216
+ /** pt (sz / 8) */
217
+ width: number;
218
+ /** pt spacing between border and text */
219
+ space: number;
220
+ }
221
+
222
+ declare interface ParagraphBorders {
223
+ top: ParaBorderEdge | null;
224
+ bottom: ParaBorderEdge | null;
225
+ left: ParaBorderEdge | null;
226
+ right: ParaBorderEdge | null;
227
+ between: ParaBorderEdge | null;
228
+ }
229
+
230
+ export declare interface RenderPageOptions {
231
+ /** Canvas CSS width in px; height is auto-computed from page aspect ratio */
232
+ width?: number;
233
+ dpr?: number;
234
+ defaultTextColor?: string;
235
+ }
236
+
237
+ export declare interface SectionProps {
238
+ pageWidth: number;
239
+ pageHeight: number;
240
+ marginTop: number;
241
+ marginRight: number;
242
+ marginBottom: number;
243
+ marginLeft: number;
244
+ headerDistance: number;
245
+ footerDistance: number;
246
+ titlePage: boolean;
247
+ evenAndOddHeaders: boolean;
248
+ }
249
+
250
+ declare interface TableBorders {
251
+ top: BorderSpec | null;
252
+ bottom: BorderSpec | null;
253
+ left: BorderSpec | null;
254
+ right: BorderSpec | null;
255
+ insideH: BorderSpec | null;
256
+ insideV: BorderSpec | null;
257
+ }
258
+
259
+ declare interface TabStop {
260
+ /** tab stop position in pt (from the left of paragraph content area) */
261
+ pos: number;
262
+ alignment: 'left' | 'center' | 'right' | 'decimal' | 'bar' | 'clear';
263
+ leader: 'none' | 'dot' | 'hyphen' | 'underscore' | 'heavy' | 'middleDot';
264
+ }
265
+
266
+ export declare interface TextRun {
267
+ text: string;
268
+ bold: boolean;
269
+ italic: boolean;
270
+ underline: boolean;
271
+ strikethrough: boolean;
272
+ fontSize: number;
273
+ color: string | null;
274
+ fontFamily: string | null;
275
+ isLink: boolean;
276
+ background: string | null;
277
+ vertAlign: 'super' | 'sub' | null;
278
+ /** Target URL for hyperlinks (resolved from relationships.xml) */
279
+ hyperlink: string | null;
280
+ allCaps?: boolean;
281
+ smallCaps?: boolean;
282
+ doubleStrikethrough?: boolean;
283
+ highlight?: string | null;
284
+ }
285
+
286
+ export { }