rocx-docx 0.0.0-stage → 0.5.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/LICENSE +504 -0
- package/README.md +106 -2
- package/authoring.js +51 -0
- package/boundary.js +314 -0
- package/browser.js +10 -0
- package/file-io.js +88 -0
- package/generate.js +36 -0
- package/index.d.ts +106 -0
- package/node.js +14 -0
- package/package.json +50 -4
- package/pkg/rocx.js +945 -0
- package/pkg/rocx_bg.wasm +0 -0
- package/rocx-source.tar.gz +0 -0
- package/types/authoring.d.ts +120 -0
- package/types/boundary.d.ts +27 -0
- package/types/drawings.d.ts +202 -0
- package/types/editor.d.ts +316 -0
- package/types/file-io.d.ts +31 -0
- package/types/inspection.d.ts +457 -0
- package/types/resolution.d.ts +73 -0
- package/types/structured.d.ts +228 -0
- package/types/styles.d.ts +175 -0
- package/types/tables.d.ts +132 -0
- package/types/template.d.ts +45 -0
- package/types/text-layout.d.ts +348 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import type { Condition, RenderOptions, ResolveOptions, ResolvedHandle, Rgb } from "./boundary.js";
|
|
2
|
+
import type { V } from "./resolution.js";
|
|
3
|
+
import type { DrawingComponents, ImageRunDeclaration, ResolvedImageRun } from "./drawings.js";
|
|
4
|
+
import type {
|
|
5
|
+
ResolvedComment, TextRevision,
|
|
6
|
+
StructuredBlockComponents, StructuredDocumentFields, StructuredDocumentView,
|
|
7
|
+
StructuredInlineComponents, StructuredStandaloneComponents,
|
|
8
|
+
} from "./structured.js";
|
|
9
|
+
import type { BorderLine, TableComponents, TableStandaloneComponents, VerticalAlignment } from "./tables.js";
|
|
10
|
+
import type { DocumentStyleFields, DocumentStyleView, NumberingReference } from "./styles.js";
|
|
11
|
+
|
|
12
|
+
export interface Metadata {
|
|
13
|
+
readonly creator?: string;
|
|
14
|
+
readonly title?: string;
|
|
15
|
+
readonly subject?: string;
|
|
16
|
+
readonly description?: string;
|
|
17
|
+
readonly keywords?: string;
|
|
18
|
+
readonly category?: string;
|
|
19
|
+
readonly comments?: string;
|
|
20
|
+
readonly version?: string;
|
|
21
|
+
readonly company?: string;
|
|
22
|
+
readonly manager?: string;
|
|
23
|
+
readonly customProperties?: Readonly<Record<string, string>>;
|
|
24
|
+
readonly customBooleanProperties?: Readonly<Record<string, boolean>>;
|
|
25
|
+
}
|
|
26
|
+
export interface DocumentTextFields {
|
|
27
|
+
readonly metadata?: V<Metadata>;
|
|
28
|
+
readonly defaults?: V<DocumentDefaults | undefined>;
|
|
29
|
+
}
|
|
30
|
+
export interface DocumentTextView {
|
|
31
|
+
readonly metadata: Metadata & Required<Pick<Metadata, "customProperties" | "customBooleanProperties">>;
|
|
32
|
+
readonly defaults?: ResolvedDocumentDefaults;
|
|
33
|
+
}
|
|
34
|
+
export interface TextLayoutComponents {
|
|
35
|
+
readonly header: { readonly declaration: HeaderDeclaration; readonly resolved: ResolvedHeaderFooter };
|
|
36
|
+
readonly footer: { readonly declaration: FooterDeclaration; readonly resolved: ResolvedHeaderFooter };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type Alignment = "left" | "center" | "right" | "justify" | "distribute" |
|
|
40
|
+
"justifyMedium" | "justifyHigh" | "justifyLow" | "thaiJustify";
|
|
41
|
+
export type Orientation = "portrait" | "landscape";
|
|
42
|
+
export type SectionType = "nextPage" | "nextColumn" | "continuous" | "evenPage" | "oddPage";
|
|
43
|
+
export type HeaderFooterType = "default" | "first" | "even";
|
|
44
|
+
export type LineNumberRestart = "newPage" | "newSection" | "continuous";
|
|
45
|
+
export type PageBorderDisplay = "allPages" | "firstPage" | "notFirstPage";
|
|
46
|
+
export type PageBorderOffset = "page" | "text";
|
|
47
|
+
export type PageBorderZOrder = "front" | "back";
|
|
48
|
+
export type DocumentGridMode = "default" | "lines" | "linesAndChars" | "snapToChars";
|
|
49
|
+
/** Physical integer lengths given in EMUs, not points or twips. */
|
|
50
|
+
export interface PageSize {
|
|
51
|
+
readonly width?: number | bigint;
|
|
52
|
+
readonly height?: number | bigint;
|
|
53
|
+
}
|
|
54
|
+
/** Physical integer lengths given in EMUs. Omitted fields retain template values. */
|
|
55
|
+
export interface PageMargins {
|
|
56
|
+
readonly top?: number | bigint;
|
|
57
|
+
readonly bottom?: number | bigint;
|
|
58
|
+
readonly left?: number | bigint;
|
|
59
|
+
readonly right?: number | bigint;
|
|
60
|
+
readonly header?: number | bigint;
|
|
61
|
+
readonly footer?: number | bigint;
|
|
62
|
+
}
|
|
63
|
+
export interface Columns {
|
|
64
|
+
readonly count?: number;
|
|
65
|
+
/** Gap in twips. */
|
|
66
|
+
readonly space?: number;
|
|
67
|
+
readonly separator?: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface PageNumbering {
|
|
70
|
+
readonly start?: number;
|
|
71
|
+
readonly format?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface LineNumbering {
|
|
74
|
+
readonly clear?: boolean;
|
|
75
|
+
readonly countBy?: number;
|
|
76
|
+
readonly start?: number;
|
|
77
|
+
/** Gap in twips. */
|
|
78
|
+
readonly distance?: number;
|
|
79
|
+
readonly restart?: LineNumberRestart;
|
|
80
|
+
}
|
|
81
|
+
export interface PageBorder {
|
|
82
|
+
readonly style: BorderLine;
|
|
83
|
+
/** Width in eighths of a point. */
|
|
84
|
+
readonly size?: number;
|
|
85
|
+
/** Offset in points. */
|
|
86
|
+
readonly space?: number;
|
|
87
|
+
readonly color?: Rgb;
|
|
88
|
+
}
|
|
89
|
+
export interface PageBorders {
|
|
90
|
+
readonly offsetFrom?: PageBorderOffset;
|
|
91
|
+
readonly display?: PageBorderDisplay;
|
|
92
|
+
readonly zOrder?: PageBorderZOrder;
|
|
93
|
+
readonly top?: PageBorder;
|
|
94
|
+
readonly left?: PageBorder;
|
|
95
|
+
readonly bottom?: PageBorder;
|
|
96
|
+
readonly right?: PageBorder;
|
|
97
|
+
}
|
|
98
|
+
export interface DocumentGrid {
|
|
99
|
+
readonly mode?: DocumentGridMode;
|
|
100
|
+
readonly linePitch?: number;
|
|
101
|
+
/** Signed pitch difference in 1/4096-point units. */
|
|
102
|
+
readonly characterPitchDelta?: number;
|
|
103
|
+
}
|
|
104
|
+
export interface SectionProperties {
|
|
105
|
+
readonly pageSize?: PageSize;
|
|
106
|
+
readonly pageOrientation?: Orientation;
|
|
107
|
+
readonly pageMargins?: PageMargins;
|
|
108
|
+
readonly pageBorders?: PageBorders;
|
|
109
|
+
readonly documentGrid?: DocumentGrid;
|
|
110
|
+
readonly pageNumbering?: PageNumbering;
|
|
111
|
+
readonly lineNumbering?: LineNumbering;
|
|
112
|
+
readonly columns?: Columns;
|
|
113
|
+
readonly verticalAlign?: VerticalAlignment;
|
|
114
|
+
readonly titlePage?: boolean;
|
|
115
|
+
readonly type?: SectionType;
|
|
116
|
+
readonly bidi?: boolean;
|
|
117
|
+
readonly rtlGutter?: boolean;
|
|
118
|
+
}
|
|
119
|
+
export type ResolvedSectionProperties = Omit<SectionProperties, "lineNumbering"> & {
|
|
120
|
+
readonly lineNumbering?: LineNumbering & Required<Pick<LineNumbering, "clear">>;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** Values are points for exact/minimum, lines for multiplier. */
|
|
124
|
+
export type LineHeight =
|
|
125
|
+
| { readonly kind: "exact"; readonly value: number }
|
|
126
|
+
| { readonly kind: "minimum"; readonly value: number }
|
|
127
|
+
| { readonly kind: "multiplier"; readonly value: number };
|
|
128
|
+
export type TabAlignment = "left" | "center" | "right" | "decimal" | "bar" | "clear" | "start" | "end";
|
|
129
|
+
export type TabLeader = "none" | "dot" | "hyphen" | "underscore" | "heavy" | "middleDot";
|
|
130
|
+
export interface TabStop {
|
|
131
|
+
/** Signed position in points. */
|
|
132
|
+
readonly position?: number;
|
|
133
|
+
readonly alignment?: TabAlignment;
|
|
134
|
+
readonly leader?: TabLeader;
|
|
135
|
+
}
|
|
136
|
+
export interface ParagraphFormat {
|
|
137
|
+
readonly bidi?: boolean;
|
|
138
|
+
readonly heading?: number;
|
|
139
|
+
readonly style?: string;
|
|
140
|
+
readonly alignment?: Alignment;
|
|
141
|
+
readonly spacingBefore?: number;
|
|
142
|
+
readonly spacingAfter?: number;
|
|
143
|
+
readonly lineSpacing?: number;
|
|
144
|
+
readonly lineHeight?: LineHeight;
|
|
145
|
+
readonly leftIndent?: number;
|
|
146
|
+
readonly rightIndent?: number;
|
|
147
|
+
readonly firstLineIndent?: number;
|
|
148
|
+
readonly keepTogether?: boolean;
|
|
149
|
+
readonly keepWithNext?: boolean;
|
|
150
|
+
readonly pageBreakBefore?: boolean;
|
|
151
|
+
readonly widowControl?: boolean;
|
|
152
|
+
readonly suppressLineNumbers?: boolean;
|
|
153
|
+
readonly contextualSpacing?: boolean;
|
|
154
|
+
readonly mirrorIndents?: boolean;
|
|
155
|
+
readonly snapToGrid?: boolean;
|
|
156
|
+
readonly tabStops?: readonly TabStop[];
|
|
157
|
+
}
|
|
158
|
+
export type ThemeColor = "dark1" | "light1" | "dark2" | "light2" |
|
|
159
|
+
"accent1" | "accent2" | "accent3" | "accent4" | "accent5" | "accent6" |
|
|
160
|
+
"hyperlink" | "followedHyperlink" | "background1" | "text1" | "background2" | "text2";
|
|
161
|
+
export type Color = Rgb | "auto" | {
|
|
162
|
+
readonly kind: "theme";
|
|
163
|
+
readonly name: ThemeColor;
|
|
164
|
+
readonly tint?: number;
|
|
165
|
+
readonly shade?: number;
|
|
166
|
+
};
|
|
167
|
+
export type Underline = "none" | "single" | "double" | "dotted" | "dash" | "wave" | "words";
|
|
168
|
+
export interface RunLanguage {
|
|
169
|
+
readonly latin?: string;
|
|
170
|
+
readonly eastAsia?: string;
|
|
171
|
+
readonly bidi?: string;
|
|
172
|
+
}
|
|
173
|
+
export interface RunFormat {
|
|
174
|
+
readonly style?: string;
|
|
175
|
+
readonly bold?: boolean;
|
|
176
|
+
readonly italic?: boolean;
|
|
177
|
+
readonly underline?: Underline | boolean;
|
|
178
|
+
readonly font?: string;
|
|
179
|
+
readonly size?: number;
|
|
180
|
+
readonly color?: Color;
|
|
181
|
+
readonly superscript?: boolean;
|
|
182
|
+
readonly subscript?: boolean;
|
|
183
|
+
readonly strike?: boolean;
|
|
184
|
+
readonly allCaps?: boolean;
|
|
185
|
+
readonly smallCaps?: boolean;
|
|
186
|
+
readonly snapToGrid?: boolean;
|
|
187
|
+
readonly language?: RunLanguage;
|
|
188
|
+
readonly boldComplexScript?: boolean;
|
|
189
|
+
readonly italicComplexScript?: boolean;
|
|
190
|
+
readonly sizeComplexScript?: number;
|
|
191
|
+
readonly rtl?: boolean;
|
|
192
|
+
readonly complexScript?: boolean;
|
|
193
|
+
readonly fontEastAsia?: string;
|
|
194
|
+
readonly fontComplexScript?: string;
|
|
195
|
+
}
|
|
196
|
+
export type ResolvedRunFormat = Omit<RunFormat, "underline"> & { readonly underline?: Underline };
|
|
197
|
+
export type ResolvedParagraphFormat = ParagraphFormat & {
|
|
198
|
+
readonly tabStops: readonly (TabStop & Required<Pick<TabStop, "position" | "alignment">>)[];
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export type FootnotePosition = "pageBottom" | "beneathText";
|
|
202
|
+
export type EndnotePosition = "sectionEnd" | "documentEnd";
|
|
203
|
+
export type NoteNumberRestart = "continuous" | "eachSection" | "eachPage";
|
|
204
|
+
export type NoteNumberFormat = "decimal" | "lowerRoman" | "upperRoman" | "lowerLetter" | "upperLetter";
|
|
205
|
+
export interface NoteNumbering {
|
|
206
|
+
readonly format?: NoteNumberFormat;
|
|
207
|
+
readonly start?: number;
|
|
208
|
+
readonly restart?: NoteNumberRestart;
|
|
209
|
+
}
|
|
210
|
+
export interface DocumentDefaults {
|
|
211
|
+
readonly run?: RunFormat;
|
|
212
|
+
readonly paragraph?: ParagraphFormat;
|
|
213
|
+
readonly footnoteNumbering?: NoteNumbering;
|
|
214
|
+
readonly endnoteNumbering?: NoteNumbering;
|
|
215
|
+
readonly footnotePosition?: FootnotePosition;
|
|
216
|
+
readonly endnotePosition?: EndnotePosition;
|
|
217
|
+
readonly mirrorMargins?: boolean;
|
|
218
|
+
readonly gutterAtTop?: boolean;
|
|
219
|
+
readonly trackRevisions?: boolean;
|
|
220
|
+
}
|
|
221
|
+
export type ResolvedDocumentDefaults = Omit<DocumentDefaults, "run" | "paragraph"> & {
|
|
222
|
+
readonly run?: ResolvedRunFormat;
|
|
223
|
+
readonly paragraph?: ResolvedParagraphFormat;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export interface DocumentProgram extends DocumentStyleFields, DocumentTextFields, StructuredDocumentFields {
|
|
227
|
+
readonly sections: readonly V<SectionDeclaration>[];
|
|
228
|
+
/** Snapshot date text, not parsed or normalized. Omit to use the host clock. */
|
|
229
|
+
readonly timestamp?: V<string | undefined>;
|
|
230
|
+
readonly commentAuthor?: V<string | undefined>;
|
|
231
|
+
}
|
|
232
|
+
export interface SectionDeclaration {
|
|
233
|
+
readonly kind: "section";
|
|
234
|
+
readonly properties?: V<SectionProperties | undefined>;
|
|
235
|
+
readonly children?: V<BlockChildren>;
|
|
236
|
+
readonly headers?: Readonly<Partial<Record<HeaderFooterType, V<HeaderDeclaration>>>>;
|
|
237
|
+
readonly footers?: Readonly<Partial<Record<HeaderFooterType, V<FooterDeclaration>>>>;
|
|
238
|
+
readonly condition?: Condition;
|
|
239
|
+
}
|
|
240
|
+
export interface HeaderDeclaration {
|
|
241
|
+
readonly kind: "header";
|
|
242
|
+
readonly children: V<BlockChildren>;
|
|
243
|
+
readonly condition?: Condition;
|
|
244
|
+
}
|
|
245
|
+
export interface FooterDeclaration {
|
|
246
|
+
readonly kind: "footer";
|
|
247
|
+
readonly children: V<BlockChildren>;
|
|
248
|
+
readonly condition?: Condition;
|
|
249
|
+
}
|
|
250
|
+
interface SimpleComments {
|
|
251
|
+
readonly commentText?: V<string>;
|
|
252
|
+
readonly commentAuthor?: V<string>;
|
|
253
|
+
}
|
|
254
|
+
export type ParagraphDeclaration = SimpleComments & {
|
|
255
|
+
readonly kind: "paragraph";
|
|
256
|
+
readonly format?: V<ParagraphFormat>;
|
|
257
|
+
readonly numbering?: V<NumberingReference | undefined>;
|
|
258
|
+
readonly condition?: Condition;
|
|
259
|
+
} & (
|
|
260
|
+
| { readonly text?: V<string>; readonly runs?: never }
|
|
261
|
+
| { readonly text?: never; readonly runs: V<InlineChildren> }
|
|
262
|
+
);
|
|
263
|
+
export interface TextRunDeclaration extends SimpleComments {
|
|
264
|
+
readonly kind: "text";
|
|
265
|
+
readonly text: V<string>;
|
|
266
|
+
readonly format?: V<RunFormat>;
|
|
267
|
+
readonly revision?: V<TextRevision | undefined>;
|
|
268
|
+
readonly condition?: Condition;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Module-owned custom component declarations and corresponding resolved handles. */
|
|
272
|
+
export type ComponentEntry = { readonly declaration: object; readonly resolved: object };
|
|
273
|
+
type Values<T> = T[keyof T];
|
|
274
|
+
type Declaration<T extends ComponentEntry> = T["declaration"];
|
|
275
|
+
type Resolved<T extends ComponentEntry> = T["resolved"];
|
|
276
|
+
type CustomBlocks = Values<TableComponents & StructuredBlockComponents>;
|
|
277
|
+
type CustomInlines = Values<DrawingComponents & StructuredInlineComponents>;
|
|
278
|
+
|
|
279
|
+
export type BlockChildren = readonly V<BlockDeclaration>[];
|
|
280
|
+
export type InlineChildren = readonly V<InlineDeclaration>[];
|
|
281
|
+
export type BlockDeclaration = ParagraphDeclaration | Declaration<CustomBlocks> |
|
|
282
|
+
{ readonly kind: "resolved"; readonly value: ResolvedBlock };
|
|
283
|
+
export type InlineDeclaration = TextRunDeclaration | ImageRunDeclaration | Declaration<CustomInlines> |
|
|
284
|
+
{ readonly kind: "resolved"; readonly value: ResolvedInline };
|
|
285
|
+
|
|
286
|
+
export type ResolvedBlock = ResolvedParagraph | Resolved<CustomBlocks>;
|
|
287
|
+
export type ResolvedInline = ResolvedTextRun | ResolvedImageRun | Resolved<CustomInlines>;
|
|
288
|
+
export type ResolvedTextRun = ResolvedHandle<"inline", {
|
|
289
|
+
readonly kind: "text";
|
|
290
|
+
readonly text: string;
|
|
291
|
+
readonly displayText: string;
|
|
292
|
+
readonly format: ResolvedRunFormat;
|
|
293
|
+
readonly comment?: ResolvedComment;
|
|
294
|
+
readonly revision?: TextRevision;
|
|
295
|
+
}>;
|
|
296
|
+
export type ResolvedParagraph = ResolvedHandle<"paragraph", {
|
|
297
|
+
readonly text: string;
|
|
298
|
+
readonly runs: readonly ResolvedInline[];
|
|
299
|
+
readonly format: ResolvedParagraphFormat;
|
|
300
|
+
readonly numbering?: NumberingReference;
|
|
301
|
+
readonly comment?: ResolvedComment;
|
|
302
|
+
}>;
|
|
303
|
+
export type ResolvedHeaderFooter = ResolvedHandle<"headerFooter", {
|
|
304
|
+
readonly blocks: readonly ResolvedBlock[];
|
|
305
|
+
}>;
|
|
306
|
+
export type ResolvedSection = ResolvedHandle<"section", {
|
|
307
|
+
readonly properties?: ResolvedSectionProperties;
|
|
308
|
+
readonly headers: Readonly<Partial<Record<HeaderFooterType, ResolvedHeaderFooter>>>;
|
|
309
|
+
readonly footers: Readonly<Partial<Record<HeaderFooterType, ResolvedHeaderFooter>>>;
|
|
310
|
+
readonly blocks: readonly ResolvedBlock[];
|
|
311
|
+
readonly paragraphs: readonly ResolvedParagraph[];
|
|
312
|
+
}>;
|
|
313
|
+
export interface ResolvedDocumentView extends DocumentStyleView, DocumentTextView, StructuredDocumentView {
|
|
314
|
+
readonly timestamp: string;
|
|
315
|
+
readonly commentAuthor?: string;
|
|
316
|
+
readonly sections: readonly ResolvedSection[];
|
|
317
|
+
}
|
|
318
|
+
export interface ResolvedDocument extends ResolvedHandle<"document", ResolvedDocumentView> {
|
|
319
|
+
toDocx(options?: RenderOptions): Uint8Array<ArrayBuffer>;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export function resolveDocument(program: DocumentProgram, options?: ResolveOptions): Promise<ResolvedDocument>;
|
|
323
|
+
export function resolveComponent(declaration: SectionDeclaration, options?: ResolveOptions): Promise<ResolvedSection | undefined>;
|
|
324
|
+
export function resolveComponent(declaration: ParagraphDeclaration, options?: ResolveOptions): Promise<ResolvedParagraph | undefined>;
|
|
325
|
+
export function resolveComponent(declaration: TextRunDeclaration, options?: ResolveOptions): Promise<ResolvedTextRun | undefined>;
|
|
326
|
+
export function resolveComponent(declaration: ImageRunDeclaration, options?: ResolveOptions): Promise<ResolvedImageRun | undefined>;
|
|
327
|
+
|
|
328
|
+
type Unscoped<T> = T extends ComponentEntry ? T extends { readonly scope: string } ? never : T : never;
|
|
329
|
+
type Scoped<T, S> = T extends { readonly scope: S } ? T : never;
|
|
330
|
+
type Matching<T, D> = T extends ComponentEntry ? D extends T["declaration"] ? T["resolved"] : never : never;
|
|
331
|
+
type Custom = CustomBlocks | CustomInlines |
|
|
332
|
+
Values<TextLayoutComponents & TableStandaloneComponents & StructuredStandaloneComponents>;
|
|
333
|
+
|
|
334
|
+
export function resolveComponent<D extends Declaration<Unscoped<Custom>>>(
|
|
335
|
+
declaration: D, options?: ResolveOptions,
|
|
336
|
+
): Promise<Matching<Unscoped<Custom>, D> | undefined>;
|
|
337
|
+
export function resolveComponent<S extends "inline" | "block", D extends Declaration<Scoped<Custom, S>>>(
|
|
338
|
+
declaration: D, options: ResolveOptions & { readonly scope: S },
|
|
339
|
+
): Promise<Matching<Scoped<Custom, S>, D> | undefined>;
|
|
340
|
+
|
|
341
|
+
declare module "./resolution.js" {
|
|
342
|
+
interface ValidationValues {
|
|
343
|
+
readonly runFormat: RunFormat;
|
|
344
|
+
readonly paragraphFormat: ParagraphFormat;
|
|
345
|
+
readonly sectionProperties: SectionProperties;
|
|
346
|
+
readonly documentDefaults: DocumentDefaults;
|
|
347
|
+
}
|
|
348
|
+
}
|