dynamic-docx-generator 1.0.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 +21 -0
- package/README.md +315 -0
- package/dist/DocxGenerator.d.ts +135 -0
- package/dist/DocxGenerator.d.ts.map +1 -0
- package/dist/DocxGenerator.js +365 -0
- package/dist/DocxGenerator.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +81 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/constants.d.ts +44 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +196 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/image.d.ts +59 -0
- package/dist/utils/image.d.ts.map +1 -0
- package/dist/utils/image.js +158 -0
- package/dist/utils/image.js.map +1 -0
- package/dist/utils/string.d.ts +49 -0
- package/dist/utils/string.d.ts.map +1 -0
- package/dist/utils/string.js +143 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/utils/xml.d.ts +48 -0
- package/dist/utils/xml.d.ts.map +1 -0
- package/dist/utils/xml.js +129 -0
- package/dist/utils/xml.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DocxGenerator - Main class for dynamic DOCX document generation
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const generator = new DocxGenerator();
|
|
8
|
+
* await generator.loadTemplate('./template.docx');
|
|
9
|
+
* generator.setData({ name: 'John', company: 'Acme' });
|
|
10
|
+
* await generator.save('./output.docx');
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
47
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.DocxGenerator = void 0;
|
|
51
|
+
const fs = __importStar(require("fs"));
|
|
52
|
+
const path = __importStar(require("path"));
|
|
53
|
+
const os = __importStar(require("os"));
|
|
54
|
+
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
55
|
+
const string_1 = require("./utils/string");
|
|
56
|
+
const xml_1 = require("./utils/xml");
|
|
57
|
+
const image_1 = require("./utils/image");
|
|
58
|
+
const constants_1 = require("./utils/constants");
|
|
59
|
+
class DocxGenerator {
|
|
60
|
+
/**
|
|
61
|
+
* Create a new DocxGenerator instance
|
|
62
|
+
* @param options - Configuration options
|
|
63
|
+
*/
|
|
64
|
+
constructor(options = {}) {
|
|
65
|
+
this.zip = null;
|
|
66
|
+
this.templateLoaded = false;
|
|
67
|
+
this.data = {};
|
|
68
|
+
this.headerData = {};
|
|
69
|
+
this.footerData = {};
|
|
70
|
+
this.images = [];
|
|
71
|
+
this.tables = [];
|
|
72
|
+
this.options = options;
|
|
73
|
+
this.tempDir = options.tempDir || os.tmpdir();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Load a DOCX template from file path or buffer
|
|
77
|
+
* @param source - Path to template file or Buffer containing template
|
|
78
|
+
* @returns this for method chaining
|
|
79
|
+
*/
|
|
80
|
+
async loadTemplate(source) {
|
|
81
|
+
try {
|
|
82
|
+
if (typeof source === 'string') {
|
|
83
|
+
// Load from file path
|
|
84
|
+
if (!fs.existsSync(source)) {
|
|
85
|
+
throw new Error(`Template file not found: ${source}`);
|
|
86
|
+
}
|
|
87
|
+
this.zip = new adm_zip_1.default(source);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// Load from buffer
|
|
91
|
+
this.zip = new adm_zip_1.default(source);
|
|
92
|
+
}
|
|
93
|
+
this.templateLoaded = true;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw new Error(`Failed to load template: ${error.message}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Set placeholder data for document body
|
|
102
|
+
* @param data - Key-value pairs where key is placeholder name and value is replacement text
|
|
103
|
+
* @returns this for method chaining
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* generator.setData({
|
|
108
|
+
* companyName: 'Acme Corp',
|
|
109
|
+
* productName: 'Widget Pro',
|
|
110
|
+
* date: '2026-01-09'
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
setData(data) {
|
|
115
|
+
this.data = { ...this.data, ...data };
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Set placeholder data for document header
|
|
120
|
+
* @param data - Key-value pairs for header placeholders
|
|
121
|
+
* @returns this for method chaining
|
|
122
|
+
*/
|
|
123
|
+
setHeader(data) {
|
|
124
|
+
this.headerData = { ...this.headerData, ...data };
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Set placeholder data for document footer
|
|
129
|
+
* @param data - Key-value pairs for footer placeholders
|
|
130
|
+
* @returns this for method chaining
|
|
131
|
+
*/
|
|
132
|
+
setFooter(data) {
|
|
133
|
+
this.footerData = { ...this.footerData, ...data };
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Add images to be inserted into the document
|
|
138
|
+
* @param images - Array of image configurations
|
|
139
|
+
* @returns this for method chaining
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* generator.setImages([
|
|
144
|
+
* { placeholder: '{{logo}}', path: './logo.png', width: 200 }
|
|
145
|
+
* ]);
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
setImages(images) {
|
|
149
|
+
this.images = [...this.images, ...images];
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Add a dynamic table to the document
|
|
154
|
+
* @param config - Table configuration
|
|
155
|
+
* @returns this for method chaining
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* generator.addTable({
|
|
160
|
+
* placeholder: '{{itemsTable}}',
|
|
161
|
+
* headers: [
|
|
162
|
+
* { name: 'Item', key: 'item', width: 3000 },
|
|
163
|
+
* { name: 'Quantity', key: 'qty', width: 1500 }
|
|
164
|
+
* ],
|
|
165
|
+
* rows: [['Widget A', '10'], ['Widget B', '5']]
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
addTable(config) {
|
|
170
|
+
this.tables.push(config);
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Process placeholders in XML content
|
|
175
|
+
*/
|
|
176
|
+
processPlaceholders(content, data) {
|
|
177
|
+
let result = content;
|
|
178
|
+
for (const [key, value] of Object.entries(data)) {
|
|
179
|
+
result = (0, string_1.replacePlaceholder)(result, key, value);
|
|
180
|
+
}
|
|
181
|
+
// Fix any double escaping issues
|
|
182
|
+
result = (0, string_1.fixDoubleEscaping)(result);
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Process tables in XML content
|
|
187
|
+
*/
|
|
188
|
+
processTables(content) {
|
|
189
|
+
let result = content;
|
|
190
|
+
for (const table of this.tables) {
|
|
191
|
+
const headers = table.headers.map(h => ({
|
|
192
|
+
name: h.name,
|
|
193
|
+
width: h.width
|
|
194
|
+
}));
|
|
195
|
+
const style = {
|
|
196
|
+
...constants_1.DEFAULT_TABLE_STYLE,
|
|
197
|
+
...table.style
|
|
198
|
+
};
|
|
199
|
+
const tableXml = (0, constants_1.generateTable)(headers, table.rows, style);
|
|
200
|
+
// Replace placeholder with table
|
|
201
|
+
result = (0, string_1.replaceAll)(result, table.placeholder, tableXml);
|
|
202
|
+
result = (0, string_1.replaceAll)(result, `{{${table.placeholder}}}`, tableXml);
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Process images and add them to the document
|
|
208
|
+
*/
|
|
209
|
+
async processImages() {
|
|
210
|
+
if (!this.zip || this.images.length === 0) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
// Get existing relationship IDs
|
|
214
|
+
const relsEntry = this.zip.getEntry('word/_rels/document.xml.rels');
|
|
215
|
+
const relsContent = relsEntry ? relsEntry.getData().toString('utf8') : '';
|
|
216
|
+
const existingIds = (0, xml_1.extractRelationshipIds)(relsContent);
|
|
217
|
+
// Prepare all images
|
|
218
|
+
const preparedImages = [];
|
|
219
|
+
for (let i = 0; i < this.images.length; i++) {
|
|
220
|
+
const prepared = await (0, image_1.prepareImage)(this.images[i], i, [
|
|
221
|
+
...existingIds,
|
|
222
|
+
...preparedImages.map(p => p.id)
|
|
223
|
+
]);
|
|
224
|
+
preparedImages.push(prepared);
|
|
225
|
+
}
|
|
226
|
+
return preparedImages;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Update document relationships with images
|
|
230
|
+
*/
|
|
231
|
+
updateRelationships(images) {
|
|
232
|
+
if (!this.zip || images.length === 0)
|
|
233
|
+
return;
|
|
234
|
+
// Update document.xml.rels
|
|
235
|
+
const relsPath = 'word/_rels/document.xml.rels';
|
|
236
|
+
const relsEntry = this.zip.getEntry(relsPath);
|
|
237
|
+
if (relsEntry) {
|
|
238
|
+
let relsContent = relsEntry.getData().toString('utf8');
|
|
239
|
+
for (const image of images) {
|
|
240
|
+
relsContent = (0, xml_1.addRelationship)(relsContent, image.relationshipXml);
|
|
241
|
+
}
|
|
242
|
+
this.zip.updateFile(relsPath, Buffer.from(relsContent, 'utf8'));
|
|
243
|
+
}
|
|
244
|
+
// Update [Content_Types].xml for image types
|
|
245
|
+
const contentTypesPath = '[Content_Types].xml';
|
|
246
|
+
const contentTypesEntry = this.zip.getEntry(contentTypesPath);
|
|
247
|
+
if (contentTypesEntry) {
|
|
248
|
+
let contentTypesXml = contentTypesEntry.getData().toString('utf8');
|
|
249
|
+
const extensions = new Set(images.map(img => img.extension));
|
|
250
|
+
for (const ext of extensions) {
|
|
251
|
+
contentTypesXml = (0, xml_1.addContentType)(contentTypesXml, ext, (0, xml_1.getImageContentType)(ext));
|
|
252
|
+
}
|
|
253
|
+
this.zip.updateFile(contentTypesPath, Buffer.from(contentTypesXml, 'utf8'));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Add image files to the media folder
|
|
258
|
+
*/
|
|
259
|
+
addImageFiles(images) {
|
|
260
|
+
if (!this.zip || images.length === 0)
|
|
261
|
+
return;
|
|
262
|
+
// Ensure media folder exists
|
|
263
|
+
for (const image of images) {
|
|
264
|
+
this.zip.addFile(`word/media/${image.fileName}`, image.buffer);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Replace image placeholders in document content
|
|
269
|
+
*/
|
|
270
|
+
replaceImagePlaceholders(content, images) {
|
|
271
|
+
let result = content;
|
|
272
|
+
for (const image of images) {
|
|
273
|
+
// Replace {{placeholder}} with image XML
|
|
274
|
+
result = (0, string_1.replaceAll)(result, image.placeholder, image.inlineXml);
|
|
275
|
+
result = (0, string_1.replaceAll)(result, `{{${image.placeholder}}}`, image.inlineXml);
|
|
276
|
+
}
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Generate the final DOCX document as a Buffer
|
|
281
|
+
* @returns Buffer containing the generated DOCX file
|
|
282
|
+
*/
|
|
283
|
+
async generate() {
|
|
284
|
+
if (!this.templateLoaded || !this.zip) {
|
|
285
|
+
throw new Error('No template loaded. Call loadTemplate() first.');
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
// Process images first
|
|
289
|
+
const preparedImages = await this.processImages();
|
|
290
|
+
// Process document.xml
|
|
291
|
+
const documentPath = 'word/document.xml';
|
|
292
|
+
const documentEntry = this.zip.getEntry(documentPath);
|
|
293
|
+
if (documentEntry) {
|
|
294
|
+
let documentXml = documentEntry.getData().toString('utf8');
|
|
295
|
+
// Replace placeholders
|
|
296
|
+
documentXml = this.processPlaceholders(documentXml, this.data);
|
|
297
|
+
// Replace tables
|
|
298
|
+
documentXml = this.processTables(documentXml);
|
|
299
|
+
// Replace image placeholders
|
|
300
|
+
documentXml = this.replaceImagePlaceholders(documentXml, preparedImages);
|
|
301
|
+
this.zip.updateFile(documentPath, Buffer.from(documentXml, 'utf8'));
|
|
302
|
+
}
|
|
303
|
+
// Process header files
|
|
304
|
+
const headerFiles = this.zip.getEntries()
|
|
305
|
+
.filter(entry => entry.entryName.match(/word\/header\d+\.xml/));
|
|
306
|
+
for (const headerEntry of headerFiles) {
|
|
307
|
+
let headerXml = headerEntry.getData().toString('utf8');
|
|
308
|
+
headerXml = this.processPlaceholders(headerXml, { ...this.data, ...this.headerData });
|
|
309
|
+
headerXml = this.replaceImagePlaceholders(headerXml, preparedImages);
|
|
310
|
+
this.zip.updateFile(headerEntry.entryName, Buffer.from(headerXml, 'utf8'));
|
|
311
|
+
}
|
|
312
|
+
// Process footer files
|
|
313
|
+
const footerFiles = this.zip.getEntries()
|
|
314
|
+
.filter(entry => entry.entryName.match(/word\/footer\d+\.xml/));
|
|
315
|
+
for (const footerEntry of footerFiles) {
|
|
316
|
+
let footerXml = footerEntry.getData().toString('utf8');
|
|
317
|
+
footerXml = this.processPlaceholders(footerXml, { ...this.data, ...this.footerData });
|
|
318
|
+
footerXml = this.replaceImagePlaceholders(footerXml, preparedImages);
|
|
319
|
+
this.zip.updateFile(footerEntry.entryName, Buffer.from(footerXml, 'utf8'));
|
|
320
|
+
}
|
|
321
|
+
// Add images to document
|
|
322
|
+
if (preparedImages.length > 0) {
|
|
323
|
+
this.updateRelationships(preparedImages);
|
|
324
|
+
this.addImageFiles(preparedImages);
|
|
325
|
+
}
|
|
326
|
+
// Generate the final buffer
|
|
327
|
+
return this.zip.toBuffer();
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
throw new Error(`Failed to generate document: ${error.message}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Save the generated document to a file
|
|
335
|
+
* @param outputPath - Path where the document should be saved
|
|
336
|
+
*/
|
|
337
|
+
async save(outputPath) {
|
|
338
|
+
const buffer = await this.generate();
|
|
339
|
+
// Ensure directory exists
|
|
340
|
+
const dir = path.dirname(outputPath);
|
|
341
|
+
if (!fs.existsSync(dir)) {
|
|
342
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
343
|
+
}
|
|
344
|
+
await fs.promises.writeFile(outputPath, buffer);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Reset the generator state (keeps template loaded)
|
|
348
|
+
*/
|
|
349
|
+
reset() {
|
|
350
|
+
this.data = {};
|
|
351
|
+
this.headerData = {};
|
|
352
|
+
this.footerData = {};
|
|
353
|
+
this.images = [];
|
|
354
|
+
this.tables = [];
|
|
355
|
+
return this;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Check if a template has been loaded
|
|
359
|
+
*/
|
|
360
|
+
isTemplateLoaded() {
|
|
361
|
+
return this.templateLoaded;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
exports.DocxGenerator = DocxGenerator;
|
|
365
|
+
//# sourceMappingURL=DocxGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocxGenerator.js","sourceRoot":"","sources":["../src/DocxGenerator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AACzB,sDAA6B;AAU7B,2CAAmF;AACnF,qCAA8H;AAC9H,yCAA4D;AAC5D,iDAAuE;AAEvE,MAAa,aAAa;IAWtB;;;OAGG;IACH,YAAY,UAA4B,EAAE;QAblC,QAAG,GAAkB,IAAI,CAAC;QAC1B,mBAAc,GAAY,KAAK,CAAC;QAChC,SAAI,GAAoB,EAAE,CAAC;QAC3B,eAAU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CAAC,IAAI,CAAC,UAAkB;QACzB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QAErC,0BAA0B;QAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACrC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3C,CAAC;QAED,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,KAAK;QACD,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,gBAAgB;QACZ,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;CACJ;AAxWD,sCAwWC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dynamic-docx-generator
|
|
3
|
+
*
|
|
4
|
+
* Generate dynamic DOCX documents from templates with placeholder replacement,
|
|
5
|
+
* tables, and images.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export { DocxGenerator } from './DocxGenerator';
|
|
10
|
+
export * from './types';
|
|
11
|
+
export * as StringUtils from './utils/string';
|
|
12
|
+
export * as XmlUtils from './utils/xml';
|
|
13
|
+
export * as ImageUtils from './utils/image';
|
|
14
|
+
export { generateTable, generateInlineImage, DEFAULT_TABLE_STYLE, escapeXml } from './utils/constants';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,cAAc,SAAS,CAAC;AAGxB,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,QAAQ,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,EACH,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,SAAS,EACZ,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* dynamic-docx-generator
|
|
4
|
+
*
|
|
5
|
+
* Generate dynamic DOCX documents from templates with placeholder replacement,
|
|
6
|
+
* tables, and images.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
23
|
+
}) : function(o, v) {
|
|
24
|
+
o["default"] = v;
|
|
25
|
+
});
|
|
26
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
27
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
28
|
+
};
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
exports.escapeXml = exports.DEFAULT_TABLE_STYLE = exports.generateInlineImage = exports.generateTable = exports.ImageUtils = exports.XmlUtils = exports.StringUtils = exports.DocxGenerator = void 0;
|
|
48
|
+
// Main class
|
|
49
|
+
var DocxGenerator_1 = require("./DocxGenerator");
|
|
50
|
+
Object.defineProperty(exports, "DocxGenerator", { enumerable: true, get: function () { return DocxGenerator_1.DocxGenerator; } });
|
|
51
|
+
// Types
|
|
52
|
+
__exportStar(require("./types"), exports);
|
|
53
|
+
// Utilities (for advanced usage)
|
|
54
|
+
exports.StringUtils = __importStar(require("./utils/string"));
|
|
55
|
+
exports.XmlUtils = __importStar(require("./utils/xml"));
|
|
56
|
+
exports.ImageUtils = __importStar(require("./utils/image"));
|
|
57
|
+
var constants_1 = require("./utils/constants");
|
|
58
|
+
Object.defineProperty(exports, "generateTable", { enumerable: true, get: function () { return constants_1.generateTable; } });
|
|
59
|
+
Object.defineProperty(exports, "generateInlineImage", { enumerable: true, get: function () { return constants_1.generateInlineImage; } });
|
|
60
|
+
Object.defineProperty(exports, "DEFAULT_TABLE_STYLE", { enumerable: true, get: function () { return constants_1.DEFAULT_TABLE_STYLE; } });
|
|
61
|
+
Object.defineProperty(exports, "escapeXml", { enumerable: true, get: function () { return constants_1.escapeXml; } });
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,aAAa;AACb,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AAEtB,QAAQ;AACR,0CAAwB;AAExB,iCAAiC;AACjC,8DAA8C;AAC9C,wDAAwC;AACxC,4DAA4C;AAC5C,+CAK2B;AAJvB,0GAAA,aAAa,OAAA;AACb,gHAAA,mBAAmB,OAAA;AACnB,gHAAA,mBAAmB,OAAA;AACnB,sGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for DocxGenerator
|
|
3
|
+
*/
|
|
4
|
+
export interface GeneratorOptions {
|
|
5
|
+
/** Custom temporary directory for processing */
|
|
6
|
+
tempDir?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for an image to be inserted into the document
|
|
10
|
+
*/
|
|
11
|
+
export interface ImageConfig {
|
|
12
|
+
/** The placeholder text in the template to replace (e.g., "{{logo}}") */
|
|
13
|
+
placeholder: string;
|
|
14
|
+
/** Path to the image file */
|
|
15
|
+
path?: string;
|
|
16
|
+
/** Image data as a Buffer */
|
|
17
|
+
buffer?: Buffer;
|
|
18
|
+
/** URL to download the image from */
|
|
19
|
+
url?: string;
|
|
20
|
+
/** Width of the image in EMUs (914400 EMUs = 1 inch). Default: 914400 */
|
|
21
|
+
width?: number;
|
|
22
|
+
/** Height of the image in EMUs (914400 EMUs = 1 inch). Default: auto */
|
|
23
|
+
height?: number;
|
|
24
|
+
/** Unique ID for the image relationship */
|
|
25
|
+
id?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Table styling options
|
|
29
|
+
*/
|
|
30
|
+
export interface TableStyle {
|
|
31
|
+
/** Header row background color (hex without #) */
|
|
32
|
+
headerBgColor?: string;
|
|
33
|
+
/** Header text color (hex without #) */
|
|
34
|
+
headerTextColor?: string;
|
|
35
|
+
/** Border color (hex without #) */
|
|
36
|
+
borderColor?: string;
|
|
37
|
+
/** Font size in half-points (24 = 12pt) */
|
|
38
|
+
fontSize?: number;
|
|
39
|
+
/** Font family */
|
|
40
|
+
fontFamily?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Configuration for a dynamic table
|
|
44
|
+
*/
|
|
45
|
+
export interface TableConfig {
|
|
46
|
+
/** The placeholder text in the template to replace */
|
|
47
|
+
placeholder: string;
|
|
48
|
+
/** Array of header column names */
|
|
49
|
+
headers: TableHeader[];
|
|
50
|
+
/** 2D array of row data */
|
|
51
|
+
rows: string[][];
|
|
52
|
+
/** Optional styling */
|
|
53
|
+
style?: TableStyle;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Table header configuration
|
|
57
|
+
*/
|
|
58
|
+
export interface TableHeader {
|
|
59
|
+
/** Header display name */
|
|
60
|
+
name: string;
|
|
61
|
+
/** Data key for mapping */
|
|
62
|
+
key: string;
|
|
63
|
+
/** Column width in twips (1440 twips = 1 inch) */
|
|
64
|
+
width?: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Placeholder data for simple text replacement
|
|
68
|
+
*/
|
|
69
|
+
export type PlaceholderData = Record<string, string>;
|
|
70
|
+
/**
|
|
71
|
+
* Result of document generation
|
|
72
|
+
*/
|
|
73
|
+
export interface GenerationResult {
|
|
74
|
+
/** Whether generation was successful */
|
|
75
|
+
success: boolean;
|
|
76
|
+
/** Output file path or buffer */
|
|
77
|
+
output?: string | Buffer;
|
|
78
|
+
/** Error message if failed */
|
|
79
|
+
error?: string;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6BAA6B;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qCAAqC;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,EAAE,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,kDAAkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mCAAmC;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,2BAA2B;IAC3B,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;IACjB,uBAAuB;IACvB,KAAK,CAAC,EAAE,UAAU,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,wCAAwC;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XML template constants for Office Open XML (OOXML) DOCX format
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Generate XML for image relationship entry in .rels file
|
|
6
|
+
*/
|
|
7
|
+
export declare const generateImageRelationship: (imageId: string, imageName: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Generate XML for inline image in document
|
|
10
|
+
*/
|
|
11
|
+
export declare const generateInlineImage: (imageId: string, width?: number, height?: number, name?: string) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Default table style values
|
|
14
|
+
*/
|
|
15
|
+
export declare const DEFAULT_TABLE_STYLE: {
|
|
16
|
+
headerBgColor: string;
|
|
17
|
+
headerTextColor: string;
|
|
18
|
+
borderColor: string;
|
|
19
|
+
fontSize: number;
|
|
20
|
+
fontFamily: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Generate table header row XML
|
|
24
|
+
*/
|
|
25
|
+
export declare const generateTableHeaderRow: (headers: {
|
|
26
|
+
name: string;
|
|
27
|
+
width?: number;
|
|
28
|
+
}[], style?: typeof DEFAULT_TABLE_STYLE) => string;
|
|
29
|
+
/**
|
|
30
|
+
* Generate a single table data row XML
|
|
31
|
+
*/
|
|
32
|
+
export declare const generateTableDataRow: (cells: string[], widths: number[], style?: typeof DEFAULT_TABLE_STYLE) => string;
|
|
33
|
+
/**
|
|
34
|
+
* Generate complete table XML
|
|
35
|
+
*/
|
|
36
|
+
export declare const generateTable: (headers: {
|
|
37
|
+
name: string;
|
|
38
|
+
width?: number;
|
|
39
|
+
}[], rows: string[][], style?: typeof DEFAULT_TABLE_STYLE) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Escape special XML characters
|
|
42
|
+
*/
|
|
43
|
+
export declare const escapeXml: (text: string) => string;
|
|
44
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,yBAAyB,GAAI,SAAS,MAAM,EAAE,WAAW,MAAM,KAAG,MAE9E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC5B,SAAS,MAAM,EACf,QAAO,MAAe,EACtB,SAAQ,MAAe,EACvB,OAAM,MAAkB,KACzB,MAoCF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;;;CAM/B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAC/B,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,EAC3C,QAAO,OAAO,mBAAyC,KACxD,MAyCF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAC7B,OAAO,MAAM,EAAE,EACf,QAAQ,MAAM,EAAE,EAChB,QAAO,OAAO,mBAAyC,KACxD,MAmCF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GACtB,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,EAC3C,MAAM,MAAM,EAAE,EAAE,EAChB,QAAO,OAAO,mBAAyC,KACxD,MA8BF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,MAQxC,CAAC"}
|