@nutrient-sdk/document-authoring 1.3.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/ACKNOWLEDGEMENTS +11702 -0
- package/LICENSE.md +5 -0
- package/README.md +124 -0
- package/lib/cli.js +43 -0
- package/lib/docauth.mjs +4 -0
- package/lib/docauth.umd.js +4 -0
- package/lib/docauth.wasm +0 -0
- package/lib/index.d.cts +331 -0
- package/lib/index.d.mts +331 -0
- package/package.json +50 -0
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
export declare type Assets = {
|
|
5
|
+
/**
|
|
6
|
+
* The base path to the Document Authoring assets.
|
|
7
|
+
* If not set, assets will be fetched from a public CDN.
|
|
8
|
+
* To self-host the assets, consult the `README.md`.
|
|
9
|
+
*/
|
|
10
|
+
base?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare type BlobInput = Promise<Response | Blob | ArrayBuffer> | Response | Blob | ArrayBuffer;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instance of the Document Authoring system which can be shared between different tasks
|
|
20
|
+
* like creating editors, importing Word documents or creating PDFs.
|
|
21
|
+
*
|
|
22
|
+
* This loads the JavaScript and WASM code and manages the font cache.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare const createDocAuthSystem: (options?: CreateDocAuthSystemOptions) => Promise<DocAuthSystem>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare type CreateDocAuthSystemOptions = {
|
|
31
|
+
licenseKey?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Assets configuration. If unset the system will use the assets from a CDN.
|
|
34
|
+
*/
|
|
35
|
+
assets?: Assets;
|
|
36
|
+
/**
|
|
37
|
+
* Font configuration.
|
|
38
|
+
*/
|
|
39
|
+
fontConfig?: FontConfig;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export declare type CreateDocumentFromPlaintextOptions = {
|
|
46
|
+
/**
|
|
47
|
+
* Defines the size of the document pages.
|
|
48
|
+
* Can be custom dimensions or standard sizes ('Letter', 'A4', 'A5', 'A6').
|
|
49
|
+
*/
|
|
50
|
+
pageSize?: {
|
|
51
|
+
width: number;
|
|
52
|
+
height: number;
|
|
53
|
+
} | 'Letter' | 'A4' | 'A5' | 'A6';
|
|
54
|
+
/**
|
|
55
|
+
* Defines the margins of the document pages.
|
|
56
|
+
*/
|
|
57
|
+
pageMargins?: {
|
|
58
|
+
left: number;
|
|
59
|
+
right: number;
|
|
60
|
+
bottom: number;
|
|
61
|
+
top: number;
|
|
62
|
+
header?: number;
|
|
63
|
+
footer?: number;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export declare type CreateEditorOptions = {
|
|
71
|
+
/**
|
|
72
|
+
* The document to attach to this editor.
|
|
73
|
+
* If no document is provided, an empty document will be created.
|
|
74
|
+
* @see {@link DocAuthEditor.setCurrentDocument}
|
|
75
|
+
*/
|
|
76
|
+
document?: DocAuthDocument;
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @hidden
|
|
83
|
+
*/
|
|
84
|
+
declare const _default: {
|
|
85
|
+
createDocAuthSystem: (options?: CreateDocAuthSystemOptions | undefined) => Promise<DocAuthSystem>;
|
|
86
|
+
defaultFontIndex: DefaultFontIndex;
|
|
87
|
+
};
|
|
88
|
+
export default _default;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The default font index that is part of the Document Authoring SDK bundle.
|
|
92
|
+
*
|
|
93
|
+
* See {@link FontConfig} for how to customize the set of fonts used by the SDK.
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
export declare type DefaultFontIndex = {
|
|
98
|
+
type: 'default-index';
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The default font index that is part of the Document Authoring SDK bundle.
|
|
103
|
+
*
|
|
104
|
+
* See {@link FontConfig} for how to customize the set of fonts used by the SDK.
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
export declare const defaultFontIndex: DefaultFontIndex;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
export declare type DocAuthDocument = {
|
|
114
|
+
/**
|
|
115
|
+
* Returns the current document in the Document Authoring format as a JavaScript object.
|
|
116
|
+
* This object can be safely persisted.
|
|
117
|
+
*/
|
|
118
|
+
saveDocument(): Promise<object>;
|
|
119
|
+
/**
|
|
120
|
+
* Returns the current document in the Document Authoring format as a JSON string.
|
|
121
|
+
* This string can be safely persisted.
|
|
122
|
+
* @see {@link DocAuthDocument.saveDocument}
|
|
123
|
+
*/
|
|
124
|
+
saveDocumentJSONString(): Promise<string>;
|
|
125
|
+
/**
|
|
126
|
+
* Exports a snapshot of the current document as a PDF file.
|
|
127
|
+
*/
|
|
128
|
+
exportPDF(options?: ExportPDFOptions): Promise<ArrayBuffer>;
|
|
129
|
+
/**
|
|
130
|
+
* Exports a snapshot of the current document as a DOCX file.
|
|
131
|
+
*/
|
|
132
|
+
exportDOCX(options?: ExportDOCXOptions): Promise<ArrayBuffer>;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The `DocAuthSystem` this document is bound to.
|
|
136
|
+
*/
|
|
137
|
+
docAuthSystem(): DocAuthSystem;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A `string` will be treated as a document authoring document in JSON format and loaded.
|
|
142
|
+
* An `object` will be treated as a JavaScript representation of a Document Authoring document
|
|
143
|
+
* (e.g. the result of `JSON.parse` on a Document Authoring JSON string).
|
|
144
|
+
*
|
|
145
|
+
* @public
|
|
146
|
+
*/
|
|
147
|
+
export declare type DocAuthDocumentInput = string | object | Blob | Response | Promise<string | object | Blob | Response>;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @public
|
|
151
|
+
*/
|
|
152
|
+
export declare type DocAuthEditor = {
|
|
153
|
+
/**
|
|
154
|
+
* Attaches the provided document as the current document to the editor.
|
|
155
|
+
*/
|
|
156
|
+
setCurrentDocument(doc: DocAuthDocument): void;
|
|
157
|
+
/**
|
|
158
|
+
* Returns a reference to the currently attached document.
|
|
159
|
+
*/
|
|
160
|
+
currentDocument(): DocAuthDocument;
|
|
161
|
+
/**
|
|
162
|
+
* Removes all DOM elements and releases resources held by the editor.
|
|
163
|
+
* Note: This does not release the underlying `DocAuthSystem`. Use `DocAuthSystem.destroy` after calling `DocAuthEditor.destroy` for a complete teardown.
|
|
164
|
+
*/
|
|
165
|
+
destroy(): void;
|
|
166
|
+
/**
|
|
167
|
+
* Retrieves the `DocAuthSystem` instance this editor is bound to.
|
|
168
|
+
*/
|
|
169
|
+
docAuthSystem(): DocAuthSystem;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* A `DocAuthSystem` instance holds the internal WASM engine and loaded fonts.
|
|
174
|
+
* It is used to load or import documents and create `DocAuthEditor` instances.
|
|
175
|
+
*
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
178
|
+
export declare type DocAuthSystem = {
|
|
179
|
+
/**
|
|
180
|
+
* Loads a document stored in the Document Authoring format.
|
|
181
|
+
* The document can be provided as a JSON string or a JavaScript object.
|
|
182
|
+
*/
|
|
183
|
+
loadDocument(documentInput: DocAuthDocumentInput): Promise<DocAuthDocument>;
|
|
184
|
+
/**
|
|
185
|
+
* Imports a DOCX document.
|
|
186
|
+
*/
|
|
187
|
+
importDOCX(docx: BlobInput, options?: ImportDOCXOptions): Promise<DocAuthDocument>;
|
|
188
|
+
/**
|
|
189
|
+
* Creates an editor in the specified HTML element.
|
|
190
|
+
* **IMPORTANT**: The `position` of the target element cannot be `static` or unset. If unsure, use `relative`.
|
|
191
|
+
*/
|
|
192
|
+
createEditor(target: HTMLElement, options?: CreateEditorOptions): Promise<DocAuthEditor>;
|
|
193
|
+
/**
|
|
194
|
+
* Creates a document from plain text by interpreting patterns and replacing characters.
|
|
195
|
+
* E.g.:
|
|
196
|
+
* - `\n` creates a line break in a paragraph
|
|
197
|
+
* - `\n\n` separates paragraphs
|
|
198
|
+
* - `\t` is replaced with spaces
|
|
199
|
+
*/
|
|
200
|
+
createDocumentFromPlaintext(text: string, options?: CreateDocumentFromPlaintextOptions): Promise<DocAuthDocument>;
|
|
201
|
+
/**
|
|
202
|
+
* Releases resources held by the system.
|
|
203
|
+
* **IMPORTANT**: The system and any editors created by this system can no longer be used after calling this.
|
|
204
|
+
*/
|
|
205
|
+
destroy(): void;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @public
|
|
210
|
+
*/
|
|
211
|
+
export declare type ExportDOCXOptions = {
|
|
212
|
+
/**
|
|
213
|
+
* An optional signal to abort the export operation.
|
|
214
|
+
*/
|
|
215
|
+
abortSignal?: AbortSignal;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @public
|
|
220
|
+
*/
|
|
221
|
+
export declare type ExportPDFOptions = {
|
|
222
|
+
/**
|
|
223
|
+
* An optional signal to abort the export operation.
|
|
224
|
+
*/
|
|
225
|
+
abortSignal?: AbortSignal;
|
|
226
|
+
/**
|
|
227
|
+
* Generate a PDF/A compliant PDF. Defaults to `false`.
|
|
228
|
+
*/
|
|
229
|
+
PDF_A?: boolean;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* @public
|
|
234
|
+
*/
|
|
235
|
+
export declare type FontConfig = {
|
|
236
|
+
/**
|
|
237
|
+
* The set of fonts available to the Document Authoring system.
|
|
238
|
+
* If unset the {@link DefaultFontIndex} is used.
|
|
239
|
+
*
|
|
240
|
+
* Individual fonts can be added directly using a {@link FontFile} or loaded by the system as they are needed using
|
|
241
|
+
* a pre-built {@link FontIndex} that all lists all available fonts. A {@link FontIndex} is the recommended way to provide
|
|
242
|
+
* a set of fonts to the system in a production environment.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* Providing two additional fonts next to the built-in default fonts. In this scenario the system will load both fonts during initialization:
|
|
246
|
+
* ```TypeScript
|
|
247
|
+
* fonts: [
|
|
248
|
+
* DocAuth.defaultFontIndex,
|
|
249
|
+
* { type: 'file', blob: fetch('/fonts/awesome.ttf') },
|
|
250
|
+
* { type: 'file', blob: fetch('/fonts/more-awesome.ttf') },
|
|
251
|
+
* ],
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* Providing multiple additional fonts using a font index in addition to the built-in default fonts. In this scenario the system will only load the fonts that are actually needed:
|
|
256
|
+
* ```TypeScript
|
|
257
|
+
* fonts: [
|
|
258
|
+
* DocAuth.defaultFontIndex,
|
|
259
|
+
* {
|
|
260
|
+
* type: 'index',
|
|
261
|
+
* index: fetch('/fonts/font-index.json'),
|
|
262
|
+
* loadFn: (name) => fetch(`/fonts/${name}`),
|
|
263
|
+
* },
|
|
264
|
+
* ],
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
fonts?: (DefaultFontIndex | FontIndex | FontFile)[];
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* `FontFile` provides a quick way to add a single additional font to the system. The system will load and scan
|
|
272
|
+
* all provided `FontFile`s to extract all the required metadata during initialization.
|
|
273
|
+
*
|
|
274
|
+
* For a production system we recommend building a {@link FontIndex} of all available fonts, which enables
|
|
275
|
+
* the system to load only fonts that are actually needed.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```TypeScript
|
|
279
|
+
* { type:'file', blob: fetch('/fonts/awesome.ttf') }
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* @public
|
|
283
|
+
*/
|
|
284
|
+
export declare type FontFile = {
|
|
285
|
+
type: 'file';
|
|
286
|
+
blob: BlobInput;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* A `FontIndex` is the preferred way to add additional fonts to the system.
|
|
291
|
+
*
|
|
292
|
+
* Document Authoring can efficiently load a single `index` of available fonts, and will then only load the actually
|
|
293
|
+
* required fonts as they are needed by calling `loadFn` with the font name. `loadFn` must return a `BlobInput` for
|
|
294
|
+
* the font file requested.
|
|
295
|
+
*
|
|
296
|
+
* In order to generate a font index from a set of fonts you want to provide to your users, use the Document Authoring CLI utility:
|
|
297
|
+
*
|
|
298
|
+
* ```shell
|
|
299
|
+
* npx document-authoring create-font-index --scan-directory path-to-fonts --write-to font-index.json
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* This will generate a `font-index.json` file that you can then host and load using the `FontIndex` configuration.
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```TypeScript
|
|
306
|
+
* {
|
|
307
|
+
* type: 'index',
|
|
308
|
+
* index: fetch('/fonts/font-index.json'),
|
|
309
|
+
* loadFn: (name) => fetch(`/fonts/${name}`),
|
|
310
|
+
* }
|
|
311
|
+
* ```
|
|
312
|
+
*
|
|
313
|
+
* @public
|
|
314
|
+
*/
|
|
315
|
+
export declare type FontIndex = {
|
|
316
|
+
type: 'index';
|
|
317
|
+
index: BlobInput;
|
|
318
|
+
loadFn: (name: string) => BlobInput;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* @public
|
|
323
|
+
*/
|
|
324
|
+
export declare type ImportDOCXOptions = {
|
|
325
|
+
/**
|
|
326
|
+
* An optional signal to abort the export operation.
|
|
327
|
+
*/
|
|
328
|
+
abortSignal?: AbortSignal;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
export { }
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
export declare type Assets = {
|
|
5
|
+
/**
|
|
6
|
+
* The base path to the Document Authoring assets.
|
|
7
|
+
* If not set, assets will be fetched from a public CDN.
|
|
8
|
+
* To self-host the assets, consult the `README.md`.
|
|
9
|
+
*/
|
|
10
|
+
base?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare type BlobInput = Promise<Response | Blob | ArrayBuffer> | Response | Blob | ArrayBuffer;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instance of the Document Authoring system which can be shared between different tasks
|
|
20
|
+
* like creating editors, importing Word documents or creating PDFs.
|
|
21
|
+
*
|
|
22
|
+
* This loads the JavaScript and WASM code and manages the font cache.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare const createDocAuthSystem: (options?: CreateDocAuthSystemOptions) => Promise<DocAuthSystem>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare type CreateDocAuthSystemOptions = {
|
|
31
|
+
licenseKey?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Assets configuration. If unset the system will use the assets from a CDN.
|
|
34
|
+
*/
|
|
35
|
+
assets?: Assets;
|
|
36
|
+
/**
|
|
37
|
+
* Font configuration.
|
|
38
|
+
*/
|
|
39
|
+
fontConfig?: FontConfig;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export declare type CreateDocumentFromPlaintextOptions = {
|
|
46
|
+
/**
|
|
47
|
+
* Defines the size of the document pages.
|
|
48
|
+
* Can be custom dimensions or standard sizes ('Letter', 'A4', 'A5', 'A6').
|
|
49
|
+
*/
|
|
50
|
+
pageSize?: {
|
|
51
|
+
width: number;
|
|
52
|
+
height: number;
|
|
53
|
+
} | 'Letter' | 'A4' | 'A5' | 'A6';
|
|
54
|
+
/**
|
|
55
|
+
* Defines the margins of the document pages.
|
|
56
|
+
*/
|
|
57
|
+
pageMargins?: {
|
|
58
|
+
left: number;
|
|
59
|
+
right: number;
|
|
60
|
+
bottom: number;
|
|
61
|
+
top: number;
|
|
62
|
+
header?: number;
|
|
63
|
+
footer?: number;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export declare type CreateEditorOptions = {
|
|
71
|
+
/**
|
|
72
|
+
* The document to attach to this editor.
|
|
73
|
+
* If no document is provided, an empty document will be created.
|
|
74
|
+
* @see {@link DocAuthEditor.setCurrentDocument}
|
|
75
|
+
*/
|
|
76
|
+
document?: DocAuthDocument;
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @hidden
|
|
83
|
+
*/
|
|
84
|
+
declare const _default: {
|
|
85
|
+
createDocAuthSystem: (options?: CreateDocAuthSystemOptions | undefined) => Promise<DocAuthSystem>;
|
|
86
|
+
defaultFontIndex: DefaultFontIndex;
|
|
87
|
+
};
|
|
88
|
+
export default _default;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The default font index that is part of the Document Authoring SDK bundle.
|
|
92
|
+
*
|
|
93
|
+
* See {@link FontConfig} for how to customize the set of fonts used by the SDK.
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
export declare type DefaultFontIndex = {
|
|
98
|
+
type: 'default-index';
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The default font index that is part of the Document Authoring SDK bundle.
|
|
103
|
+
*
|
|
104
|
+
* See {@link FontConfig} for how to customize the set of fonts used by the SDK.
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
export declare const defaultFontIndex: DefaultFontIndex;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
export declare type DocAuthDocument = {
|
|
114
|
+
/**
|
|
115
|
+
* Returns the current document in the Document Authoring format as a JavaScript object.
|
|
116
|
+
* This object can be safely persisted.
|
|
117
|
+
*/
|
|
118
|
+
saveDocument(): Promise<object>;
|
|
119
|
+
/**
|
|
120
|
+
* Returns the current document in the Document Authoring format as a JSON string.
|
|
121
|
+
* This string can be safely persisted.
|
|
122
|
+
* @see {@link DocAuthDocument.saveDocument}
|
|
123
|
+
*/
|
|
124
|
+
saveDocumentJSONString(): Promise<string>;
|
|
125
|
+
/**
|
|
126
|
+
* Exports a snapshot of the current document as a PDF file.
|
|
127
|
+
*/
|
|
128
|
+
exportPDF(options?: ExportPDFOptions): Promise<ArrayBuffer>;
|
|
129
|
+
/**
|
|
130
|
+
* Exports a snapshot of the current document as a DOCX file.
|
|
131
|
+
*/
|
|
132
|
+
exportDOCX(options?: ExportDOCXOptions): Promise<ArrayBuffer>;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The `DocAuthSystem` this document is bound to.
|
|
136
|
+
*/
|
|
137
|
+
docAuthSystem(): DocAuthSystem;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A `string` will be treated as a document authoring document in JSON format and loaded.
|
|
142
|
+
* An `object` will be treated as a JavaScript representation of a Document Authoring document
|
|
143
|
+
* (e.g. the result of `JSON.parse` on a Document Authoring JSON string).
|
|
144
|
+
*
|
|
145
|
+
* @public
|
|
146
|
+
*/
|
|
147
|
+
export declare type DocAuthDocumentInput = string | object | Blob | Response | Promise<string | object | Blob | Response>;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @public
|
|
151
|
+
*/
|
|
152
|
+
export declare type DocAuthEditor = {
|
|
153
|
+
/**
|
|
154
|
+
* Attaches the provided document as the current document to the editor.
|
|
155
|
+
*/
|
|
156
|
+
setCurrentDocument(doc: DocAuthDocument): void;
|
|
157
|
+
/**
|
|
158
|
+
* Returns a reference to the currently attached document.
|
|
159
|
+
*/
|
|
160
|
+
currentDocument(): DocAuthDocument;
|
|
161
|
+
/**
|
|
162
|
+
* Removes all DOM elements and releases resources held by the editor.
|
|
163
|
+
* Note: This does not release the underlying `DocAuthSystem`. Use `DocAuthSystem.destroy` after calling `DocAuthEditor.destroy` for a complete teardown.
|
|
164
|
+
*/
|
|
165
|
+
destroy(): void;
|
|
166
|
+
/**
|
|
167
|
+
* Retrieves the `DocAuthSystem` instance this editor is bound to.
|
|
168
|
+
*/
|
|
169
|
+
docAuthSystem(): DocAuthSystem;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* A `DocAuthSystem` instance holds the internal WASM engine and loaded fonts.
|
|
174
|
+
* It is used to load or import documents and create `DocAuthEditor` instances.
|
|
175
|
+
*
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
178
|
+
export declare type DocAuthSystem = {
|
|
179
|
+
/**
|
|
180
|
+
* Loads a document stored in the Document Authoring format.
|
|
181
|
+
* The document can be provided as a JSON string or a JavaScript object.
|
|
182
|
+
*/
|
|
183
|
+
loadDocument(documentInput: DocAuthDocumentInput): Promise<DocAuthDocument>;
|
|
184
|
+
/**
|
|
185
|
+
* Imports a DOCX document.
|
|
186
|
+
*/
|
|
187
|
+
importDOCX(docx: BlobInput, options?: ImportDOCXOptions): Promise<DocAuthDocument>;
|
|
188
|
+
/**
|
|
189
|
+
* Creates an editor in the specified HTML element.
|
|
190
|
+
* **IMPORTANT**: The `position` of the target element cannot be `static` or unset. If unsure, use `relative`.
|
|
191
|
+
*/
|
|
192
|
+
createEditor(target: HTMLElement, options?: CreateEditorOptions): Promise<DocAuthEditor>;
|
|
193
|
+
/**
|
|
194
|
+
* Creates a document from plain text by interpreting patterns and replacing characters.
|
|
195
|
+
* E.g.:
|
|
196
|
+
* - `\n` creates a line break in a paragraph
|
|
197
|
+
* - `\n\n` separates paragraphs
|
|
198
|
+
* - `\t` is replaced with spaces
|
|
199
|
+
*/
|
|
200
|
+
createDocumentFromPlaintext(text: string, options?: CreateDocumentFromPlaintextOptions): Promise<DocAuthDocument>;
|
|
201
|
+
/**
|
|
202
|
+
* Releases resources held by the system.
|
|
203
|
+
* **IMPORTANT**: The system and any editors created by this system can no longer be used after calling this.
|
|
204
|
+
*/
|
|
205
|
+
destroy(): void;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @public
|
|
210
|
+
*/
|
|
211
|
+
export declare type ExportDOCXOptions = {
|
|
212
|
+
/**
|
|
213
|
+
* An optional signal to abort the export operation.
|
|
214
|
+
*/
|
|
215
|
+
abortSignal?: AbortSignal;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @public
|
|
220
|
+
*/
|
|
221
|
+
export declare type ExportPDFOptions = {
|
|
222
|
+
/**
|
|
223
|
+
* An optional signal to abort the export operation.
|
|
224
|
+
*/
|
|
225
|
+
abortSignal?: AbortSignal;
|
|
226
|
+
/**
|
|
227
|
+
* Generate a PDF/A compliant PDF. Defaults to `false`.
|
|
228
|
+
*/
|
|
229
|
+
PDF_A?: boolean;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* @public
|
|
234
|
+
*/
|
|
235
|
+
export declare type FontConfig = {
|
|
236
|
+
/**
|
|
237
|
+
* The set of fonts available to the Document Authoring system.
|
|
238
|
+
* If unset the {@link DefaultFontIndex} is used.
|
|
239
|
+
*
|
|
240
|
+
* Individual fonts can be added directly using a {@link FontFile} or loaded by the system as they are needed using
|
|
241
|
+
* a pre-built {@link FontIndex} that all lists all available fonts. A {@link FontIndex} is the recommended way to provide
|
|
242
|
+
* a set of fonts to the system in a production environment.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* Providing two additional fonts next to the built-in default fonts. In this scenario the system will load both fonts during initialization:
|
|
246
|
+
* ```TypeScript
|
|
247
|
+
* fonts: [
|
|
248
|
+
* DocAuth.defaultFontIndex,
|
|
249
|
+
* { type: 'file', blob: fetch('/fonts/awesome.ttf') },
|
|
250
|
+
* { type: 'file', blob: fetch('/fonts/more-awesome.ttf') },
|
|
251
|
+
* ],
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* Providing multiple additional fonts using a font index in addition to the built-in default fonts. In this scenario the system will only load the fonts that are actually needed:
|
|
256
|
+
* ```TypeScript
|
|
257
|
+
* fonts: [
|
|
258
|
+
* DocAuth.defaultFontIndex,
|
|
259
|
+
* {
|
|
260
|
+
* type: 'index',
|
|
261
|
+
* index: fetch('/fonts/font-index.json'),
|
|
262
|
+
* loadFn: (name) => fetch(`/fonts/${name}`),
|
|
263
|
+
* },
|
|
264
|
+
* ],
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
fonts?: (DefaultFontIndex | FontIndex | FontFile)[];
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* `FontFile` provides a quick way to add a single additional font to the system. The system will load and scan
|
|
272
|
+
* all provided `FontFile`s to extract all the required metadata during initialization.
|
|
273
|
+
*
|
|
274
|
+
* For a production system we recommend building a {@link FontIndex} of all available fonts, which enables
|
|
275
|
+
* the system to load only fonts that are actually needed.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```TypeScript
|
|
279
|
+
* { type:'file', blob: fetch('/fonts/awesome.ttf') }
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* @public
|
|
283
|
+
*/
|
|
284
|
+
export declare type FontFile = {
|
|
285
|
+
type: 'file';
|
|
286
|
+
blob: BlobInput;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* A `FontIndex` is the preferred way to add additional fonts to the system.
|
|
291
|
+
*
|
|
292
|
+
* Document Authoring can efficiently load a single `index` of available fonts, and will then only load the actually
|
|
293
|
+
* required fonts as they are needed by calling `loadFn` with the font name. `loadFn` must return a `BlobInput` for
|
|
294
|
+
* the font file requested.
|
|
295
|
+
*
|
|
296
|
+
* In order to generate a font index from a set of fonts you want to provide to your users, use the Document Authoring CLI utility:
|
|
297
|
+
*
|
|
298
|
+
* ```shell
|
|
299
|
+
* npx document-authoring create-font-index --scan-directory path-to-fonts --write-to font-index.json
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* This will generate a `font-index.json` file that you can then host and load using the `FontIndex` configuration.
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```TypeScript
|
|
306
|
+
* {
|
|
307
|
+
* type: 'index',
|
|
308
|
+
* index: fetch('/fonts/font-index.json'),
|
|
309
|
+
* loadFn: (name) => fetch(`/fonts/${name}`),
|
|
310
|
+
* }
|
|
311
|
+
* ```
|
|
312
|
+
*
|
|
313
|
+
* @public
|
|
314
|
+
*/
|
|
315
|
+
export declare type FontIndex = {
|
|
316
|
+
type: 'index';
|
|
317
|
+
index: BlobInput;
|
|
318
|
+
loadFn: (name: string) => BlobInput;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* @public
|
|
323
|
+
*/
|
|
324
|
+
export declare type ImportDOCXOptions = {
|
|
325
|
+
/**
|
|
326
|
+
* An optional signal to abort the export operation.
|
|
327
|
+
*/
|
|
328
|
+
abortSignal?: AbortSignal;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
export { }
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nutrient-sdk/document-authoring",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "A web SDK for word processing and rich text capabilities.",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "lib/docauth.umd.js",
|
|
7
|
+
"module": "lib/docauth.mjs",
|
|
8
|
+
"types": "lib/index.d.cts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./lib/index.d.mts",
|
|
13
|
+
"default": "./lib/docauth.mjs"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./lib/index.d.cts",
|
|
17
|
+
"default": "./lib/docauth.umd.js"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"bin": {
|
|
22
|
+
"document-authoring": "./lib/cli.js"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"document",
|
|
26
|
+
"authoring",
|
|
27
|
+
"word processing",
|
|
28
|
+
"rich text",
|
|
29
|
+
"SDK",
|
|
30
|
+
"rich text editor",
|
|
31
|
+
"WYSIWYG",
|
|
32
|
+
"editor",
|
|
33
|
+
"text editor",
|
|
34
|
+
"content creation",
|
|
35
|
+
"TypeScript",
|
|
36
|
+
"React",
|
|
37
|
+
"JavaScript",
|
|
38
|
+
"text formatting",
|
|
39
|
+
"DOCX"
|
|
40
|
+
],
|
|
41
|
+
"homepage": "https://www.nutrient.io/sdk/document-authoring/",
|
|
42
|
+
"author": {
|
|
43
|
+
"name": "Nutrient",
|
|
44
|
+
"url": "https://nutrient.io"
|
|
45
|
+
},
|
|
46
|
+
"license": "SEE LICENSE IN https://www.nutrient.io/legal/Nutrient_SDK_User_Evaluation_Subscription_Agreement",
|
|
47
|
+
"bugs": {
|
|
48
|
+
"email": "support@nutrient.io"
|
|
49
|
+
}
|
|
50
|
+
}
|