@cj-tech-master/excelts 9.5.0 → 9.5.1
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/dist/browser/modules/pdf/excel-bridge.js +27 -1
- package/dist/browser/modules/pdf/render/layout-engine.js +74 -9
- package/dist/browser/modules/pdf/render/style-converter.d.ts +1 -1
- package/dist/browser/modules/pdf/render/style-converter.js +98 -1
- package/dist/browser/modules/pdf/types.d.ts +1 -0
- package/dist/browser/modules/word/color-utils.d.ts +18 -0
- package/dist/browser/modules/word/color-utils.js +94 -0
- package/dist/browser/modules/word/content-types.d.ts +15 -15
- package/dist/browser/modules/word/content-types.js +39 -43
- package/dist/browser/modules/word/crypto.d.ts +17 -0
- package/dist/browser/modules/word/crypto.js +18 -0
- package/dist/browser/modules/word/document-io.d.ts +58 -0
- package/dist/browser/modules/word/document-io.js +239 -0
- package/dist/browser/modules/word/document.d.ts +64 -135
- package/dist/browser/modules/word/document.js +207 -469
- package/dist/browser/modules/word/docx-packager.js +90 -90
- package/dist/browser/modules/word/html-renderer.js +1 -1
- package/dist/browser/modules/word/html.d.ts +13 -0
- package/dist/browser/modules/word/html.js +12 -0
- package/dist/browser/modules/word/index.base.d.ts +6 -9
- package/dist/browser/modules/word/index.base.js +7 -10
- package/dist/browser/modules/word/namespaces.d.ts +159 -0
- package/dist/browser/modules/word/namespaces.js +189 -0
- package/dist/browser/modules/word/relationships.d.ts +15 -16
- package/dist/browser/modules/word/relationships.js +37 -45
- package/dist/cjs/modules/pdf/excel-bridge.js +27 -1
- package/dist/cjs/modules/pdf/render/layout-engine.js +74 -9
- package/dist/cjs/modules/pdf/render/style-converter.js +98 -1
- package/dist/cjs/modules/word/color-utils.js +97 -0
- package/dist/cjs/modules/word/content-types.js +44 -45
- package/dist/cjs/modules/word/crypto.js +34 -0
- package/dist/cjs/modules/word/document-io.js +244 -0
- package/dist/cjs/modules/word/document.js +209 -473
- package/dist/cjs/modules/word/docx-packager.js +88 -88
- package/dist/cjs/modules/word/html-renderer.js +2 -2
- package/dist/cjs/modules/word/html.js +16 -0
- package/dist/cjs/modules/word/index.base.js +17 -27
- package/dist/cjs/modules/word/namespaces.js +192 -0
- package/dist/cjs/modules/word/relationships.js +42 -47
- package/dist/esm/modules/pdf/excel-bridge.js +27 -1
- package/dist/esm/modules/pdf/render/layout-engine.js +74 -9
- package/dist/esm/modules/pdf/render/style-converter.js +98 -1
- package/dist/esm/modules/word/color-utils.js +94 -0
- package/dist/esm/modules/word/content-types.js +39 -43
- package/dist/esm/modules/word/crypto.js +18 -0
- package/dist/esm/modules/word/document-io.js +239 -0
- package/dist/esm/modules/word/document.js +207 -469
- package/dist/esm/modules/word/docx-packager.js +90 -90
- package/dist/esm/modules/word/html-renderer.js +1 -1
- package/dist/esm/modules/word/html.js +12 -0
- package/dist/esm/modules/word/index.base.js +7 -10
- package/dist/esm/modules/word/namespaces.js +189 -0
- package/dist/esm/modules/word/relationships.js +37 -45
- package/dist/iife/excelts.iife.js +153 -11
- package/dist/iife/excelts.iife.js.map +1 -1
- package/dist/iife/excelts.iife.min.js +4 -4
- package/dist/types/modules/pdf/render/style-converter.d.ts +1 -1
- package/dist/types/modules/pdf/types.d.ts +1 -0
- package/dist/types/modules/word/color-utils.d.ts +18 -0
- package/dist/types/modules/word/content-types.d.ts +15 -15
- package/dist/types/modules/word/crypto.d.ts +17 -0
- package/dist/types/modules/word/document-io.d.ts +58 -0
- package/dist/types/modules/word/document.d.ts +64 -135
- package/dist/types/modules/word/html.d.ts +13 -0
- package/dist/types/modules/word/index.base.d.ts +6 -9
- package/dist/types/modules/word/namespaces.d.ts +159 -0
- package/dist/types/modules/word/relationships.d.ts +15 -16
- package/package.json +1 -1
|
@@ -205,42 +205,42 @@ function collectHyperlinksFromHeaderFooter(content) {
|
|
|
205
205
|
async function packageDocx(doc, compressionLevel) {
|
|
206
206
|
const archive = (0, create_archive_1.zip)({ level: compressionLevel ?? 6 });
|
|
207
207
|
// Managers
|
|
208
|
-
const contentTypes =
|
|
209
|
-
const packageRels =
|
|
210
|
-
const documentRels =
|
|
208
|
+
const contentTypes = (0, content_types_1.createContentTypes)();
|
|
209
|
+
const packageRels = (0, relationships_1.createRelationships)();
|
|
210
|
+
const documentRels = (0, relationships_1.createRelationships)();
|
|
211
211
|
// --- Package relationships ---
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
(0, relationships_1.addRelationship)(packageRels, constants_1.RelType.OfficeDocument, "word/document.xml");
|
|
213
|
+
(0, relationships_1.addRelationship)(packageRels, constants_1.RelType.CoreProperties, "docProps/core.xml");
|
|
214
|
+
(0, relationships_1.addRelationship)(packageRels, constants_1.RelType.ExtendedProperties, "docProps/app.xml");
|
|
215
215
|
// Custom properties
|
|
216
216
|
const hasCustomProps = doc.customProperties && doc.customProperties.length > 0;
|
|
217
217
|
if (hasCustomProps) {
|
|
218
|
-
|
|
218
|
+
(0, relationships_1.addRelationship)(packageRels, constants_1.RelType.CustomProperties, "docProps/custom.xml");
|
|
219
219
|
}
|
|
220
220
|
// --- Document relationships ---
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
221
|
+
(0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Styles, "styles.xml");
|
|
222
|
+
(0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Settings, "settings.xml");
|
|
223
|
+
(0, relationships_1.addRelationship)(documentRels, constants_1.RelType.FontTable, "fontTable.xml");
|
|
224
|
+
(0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Theme, "theme/theme1.xml");
|
|
225
225
|
// Numbering
|
|
226
226
|
const hasNumbering = (doc.abstractNumberings && doc.abstractNumberings.length > 0) ||
|
|
227
227
|
(doc.numberingInstances && doc.numberingInstances.length > 0);
|
|
228
228
|
if (hasNumbering) {
|
|
229
|
-
|
|
229
|
+
(0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Numbering, "numbering.xml");
|
|
230
230
|
}
|
|
231
231
|
// Footnotes & Endnotes
|
|
232
232
|
const hasFootnotes = doc.footnotes && doc.footnotes.length > 0;
|
|
233
233
|
const hasEndnotes = doc.endnotes && doc.endnotes.length > 0;
|
|
234
234
|
if (hasFootnotes) {
|
|
235
|
-
|
|
235
|
+
(0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Footnotes, "footnotes.xml");
|
|
236
236
|
}
|
|
237
237
|
if (hasEndnotes) {
|
|
238
|
-
|
|
238
|
+
(0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Endnotes, "endnotes.xml");
|
|
239
239
|
}
|
|
240
240
|
// Comments
|
|
241
241
|
const hasComments = doc.comments && doc.comments.length > 0;
|
|
242
242
|
if (hasComments) {
|
|
243
|
-
|
|
243
|
+
(0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Comments, "comments.xml");
|
|
244
244
|
}
|
|
245
245
|
// Images
|
|
246
246
|
const imageExtensions = new Set();
|
|
@@ -262,14 +262,14 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
262
262
|
const baseName = img.fileName.replace(/\.[^.]+$/, "");
|
|
263
263
|
const fallbackFileName = `${baseName}_fallback.png`;
|
|
264
264
|
// Register PNG fallback as the main rId
|
|
265
|
-
const fbRId =
|
|
265
|
+
const fbRId = (0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Image, `media/${fallbackFileName}`);
|
|
266
266
|
img.rId = fbRId;
|
|
267
267
|
if (oldRid) {
|
|
268
268
|
imageRidMap.set(oldRid, fbRId);
|
|
269
269
|
}
|
|
270
270
|
imageExtensions.add("png");
|
|
271
271
|
// Register SVG as separate image
|
|
272
|
-
const svgRId =
|
|
272
|
+
const svgRId = (0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Image, `media/${img.fileName}`);
|
|
273
273
|
svgRidMap.set(img.fileName, svgRId);
|
|
274
274
|
const ext = img.fileName.split(".").pop()?.toLowerCase();
|
|
275
275
|
if (ext) {
|
|
@@ -278,7 +278,7 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
278
278
|
svgFallbacks.push({ fallbackFileName, data: img.fallbackData });
|
|
279
279
|
}
|
|
280
280
|
else {
|
|
281
|
-
const rId =
|
|
281
|
+
const rId = (0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Image, `media/${img.fileName}`);
|
|
282
282
|
img.rId = rId;
|
|
283
283
|
if (oldRid) {
|
|
284
284
|
imageRidMap.set(oldRid, rId);
|
|
@@ -345,7 +345,7 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
345
345
|
const hyperlinks = collectHyperlinks(doc.body);
|
|
346
346
|
for (const link of hyperlinks) {
|
|
347
347
|
if (link.url) {
|
|
348
|
-
const rId =
|
|
348
|
+
const rId = (0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Hyperlink, link.url, "External");
|
|
349
349
|
link.rId = rId;
|
|
350
350
|
}
|
|
351
351
|
}
|
|
@@ -355,11 +355,11 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
355
355
|
altChunks.forEach((chunk, i) => {
|
|
356
356
|
const fileName = chunk.fileName ?? `afchunk${i + 1}.html`;
|
|
357
357
|
// Register relationship for the alt chunk
|
|
358
|
-
const rId =
|
|
358
|
+
const rId = (0, relationships_1.addRelationship)(documentRels, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk", fileName);
|
|
359
359
|
chunk.rId = rId;
|
|
360
360
|
// Register content type
|
|
361
361
|
const ct = chunk.contentType ?? "text/html";
|
|
362
|
-
|
|
362
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, `/word/${fileName}`, ct);
|
|
363
363
|
// Write data to archive
|
|
364
364
|
if (chunk.data) {
|
|
365
365
|
archive.add(`word/${fileName}`, chunk.data);
|
|
@@ -370,17 +370,17 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
370
370
|
const headerRelManagers = new Map();
|
|
371
371
|
if (doc.headers) {
|
|
372
372
|
for (const [key, headerDef] of doc.headers) {
|
|
373
|
-
const rId =
|
|
373
|
+
const rId = (0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Header, `header${headerIndex}.xml`);
|
|
374
374
|
headerDef.rId = rId;
|
|
375
|
-
// Create per-header relationship
|
|
376
|
-
const hRels =
|
|
375
|
+
// Create per-header relationship state for images and hyperlinks
|
|
376
|
+
const hRels = (0, relationships_1.createRelationships)();
|
|
377
377
|
const imgRids = collectImageRidsFromContent(headerDef.content);
|
|
378
378
|
if (imgRids.size > 0 && doc.images) {
|
|
379
379
|
for (const oldRid of imgRids) {
|
|
380
380
|
// O(1) lookup: direct or via remap
|
|
381
381
|
const img = imageByRid.get(oldRid) ?? imageByRid.get(imageRidMap.get(oldRid) ?? "");
|
|
382
382
|
if (img) {
|
|
383
|
-
|
|
383
|
+
(0, relationships_1.addRelationshipWithId)(hRels, oldRid, constants_1.RelType.Image, `media/${img.fileName}`);
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
386
|
}
|
|
@@ -388,11 +388,11 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
388
388
|
const hLinks = collectHyperlinksFromHeaderFooter(headerDef.content);
|
|
389
389
|
for (const link of hLinks) {
|
|
390
390
|
if (link.url) {
|
|
391
|
-
const linkRId =
|
|
391
|
+
const linkRId = (0, relationships_1.addRelationship)(hRels, constants_1.RelType.Hyperlink, link.url, "External");
|
|
392
392
|
link.rId = linkRId;
|
|
393
393
|
}
|
|
394
394
|
}
|
|
395
|
-
if (hRels
|
|
395
|
+
if ((0, relationships_1.getRelationshipCount)(hRels) > 0) {
|
|
396
396
|
headerRelManagers.set(key, hRels);
|
|
397
397
|
}
|
|
398
398
|
headerIndex++;
|
|
@@ -403,16 +403,16 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
403
403
|
const footerRelManagers = new Map();
|
|
404
404
|
if (doc.footers) {
|
|
405
405
|
for (const [key, footerDef] of doc.footers) {
|
|
406
|
-
const rId =
|
|
406
|
+
const rId = (0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Footer, `footer${footerIndex}.xml`);
|
|
407
407
|
footerDef.rId = rId;
|
|
408
|
-
// Create per-footer relationship
|
|
409
|
-
const fRels =
|
|
408
|
+
// Create per-footer relationship state for images and hyperlinks
|
|
409
|
+
const fRels = (0, relationships_1.createRelationships)();
|
|
410
410
|
const imgRids = collectImageRidsFromContent(footerDef.content);
|
|
411
411
|
if (imgRids.size > 0 && doc.images) {
|
|
412
412
|
for (const oldRid of imgRids) {
|
|
413
413
|
const img = imageByRid.get(oldRid) ?? imageByRid.get(imageRidMap.get(oldRid) ?? "");
|
|
414
414
|
if (img) {
|
|
415
|
-
|
|
415
|
+
(0, relationships_1.addRelationshipWithId)(fRels, oldRid, constants_1.RelType.Image, `media/${img.fileName}`);
|
|
416
416
|
}
|
|
417
417
|
}
|
|
418
418
|
}
|
|
@@ -420,11 +420,11 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
420
420
|
const fLinks = collectHyperlinksFromHeaderFooter(footerDef.content);
|
|
421
421
|
for (const link of fLinks) {
|
|
422
422
|
if (link.url) {
|
|
423
|
-
const linkRId =
|
|
423
|
+
const linkRId = (0, relationships_1.addRelationship)(fRels, constants_1.RelType.Hyperlink, link.url, "External");
|
|
424
424
|
link.rId = linkRId;
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
|
-
if (fRels
|
|
427
|
+
if ((0, relationships_1.getRelationshipCount)(fRels) > 0) {
|
|
428
428
|
footerRelManagers.set(key, fRels);
|
|
429
429
|
}
|
|
430
430
|
footerIndex++;
|
|
@@ -437,67 +437,67 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
437
437
|
if (doc.watermark) {
|
|
438
438
|
// Use next header index
|
|
439
439
|
const wmHdrIdx = headerIndex;
|
|
440
|
-
watermarkHeaderRId =
|
|
440
|
+
watermarkHeaderRId = (0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Header, `header${wmHdrIdx}.xml`);
|
|
441
441
|
watermarkHeaderIndex = wmHdrIdx;
|
|
442
442
|
// If image watermark, add image relationship in header .rels
|
|
443
443
|
if (doc.watermark.type === "image") {
|
|
444
|
-
const wmRels =
|
|
444
|
+
const wmRels = (0, relationships_1.createRelationships)();
|
|
445
445
|
const wmRId = doc.watermark.rId;
|
|
446
446
|
const img = imageByRid.get(wmRId) ?? imageByRid.get(imageRidMap.get(wmRId) ?? "");
|
|
447
447
|
if (img) {
|
|
448
|
-
|
|
448
|
+
(0, relationships_1.addRelationshipWithId)(wmRels, wmRId, constants_1.RelType.Image, `media/${img.fileName}`);
|
|
449
449
|
}
|
|
450
450
|
watermarkHeaderRels = wmRels;
|
|
451
451
|
}
|
|
452
452
|
headerIndex++;
|
|
453
453
|
}
|
|
454
454
|
// --- Content Types ---
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
455
|
+
(0, content_types_1.addImageContentTypeDefaults)(contentTypes, imageExtensions);
|
|
456
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.Document, constants_1.ContentType.Document);
|
|
457
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.Styles, constants_1.ContentType.Styles);
|
|
458
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.Settings, constants_1.ContentType.Settings);
|
|
459
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.FontTable, constants_1.ContentType.FontTable);
|
|
460
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.Theme, constants_1.ContentType.Theme);
|
|
461
461
|
if (hasNumbering) {
|
|
462
|
-
|
|
462
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.Numbering, constants_1.ContentType.Numbering);
|
|
463
463
|
}
|
|
464
464
|
if (hasFootnotes) {
|
|
465
|
-
|
|
465
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.Footnotes, constants_1.ContentType.Footnotes);
|
|
466
466
|
}
|
|
467
467
|
if (hasEndnotes) {
|
|
468
|
-
|
|
468
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.Endnotes, constants_1.ContentType.Endnotes);
|
|
469
469
|
}
|
|
470
470
|
if (hasComments) {
|
|
471
|
-
|
|
471
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.Comments, constants_1.ContentType.Comments);
|
|
472
472
|
}
|
|
473
473
|
headerIndex = 1;
|
|
474
474
|
if (doc.headers) {
|
|
475
475
|
for (const [,] of doc.headers) {
|
|
476
|
-
|
|
476
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.header(headerIndex), constants_1.ContentType.Header);
|
|
477
477
|
headerIndex++;
|
|
478
478
|
}
|
|
479
479
|
}
|
|
480
480
|
footerIndex = 1;
|
|
481
481
|
if (doc.footers) {
|
|
482
482
|
for (const [,] of doc.footers) {
|
|
483
|
-
|
|
483
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.footer(footerIndex), constants_1.ContentType.Footer);
|
|
484
484
|
footerIndex++;
|
|
485
485
|
}
|
|
486
486
|
}
|
|
487
487
|
if (watermarkHeaderIndex !== undefined) {
|
|
488
|
-
|
|
488
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.header(watermarkHeaderIndex), constants_1.ContentType.Header);
|
|
489
489
|
}
|
|
490
|
-
|
|
491
|
-
|
|
490
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.CoreProps, constants_1.ContentType.CoreProperties);
|
|
491
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.AppProps, constants_1.ContentType.ExtendedProperties);
|
|
492
492
|
if (hasCustomProps) {
|
|
493
|
-
|
|
493
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, constants_1.PartPath.CustomProps, constants_1.ContentType.CustomProperties);
|
|
494
494
|
}
|
|
495
495
|
// --- Generate & add parts to archive ---
|
|
496
496
|
// Note: [Content_Types].xml and _rels/.rels are serialized LAST so that any
|
|
497
497
|
// relationships/content types registered during content rendering (e.g.
|
|
498
498
|
// thumbnails, chart parts, alt chunks) are included.
|
|
499
499
|
// word/_rels/document.xml.rels
|
|
500
|
-
archive.add(constants_1.PartPath.DocumentRels, renderXml(xml =>
|
|
500
|
+
archive.add(constants_1.PartPath.DocumentRels, renderXml(xml => (0, relationships_1.renderRelationships)(documentRels, xml)));
|
|
501
501
|
// Build an effective doc that includes the auto-generated watermark header
|
|
502
502
|
// reference in section properties (without mutating the caller's doc).
|
|
503
503
|
let effectiveDoc = doc;
|
|
@@ -533,7 +533,7 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
533
533
|
const chartRIds = [];
|
|
534
534
|
charts.forEach(chartContent => {
|
|
535
535
|
const num = chartRIds.length + 1;
|
|
536
|
-
const rId =
|
|
536
|
+
const rId = (0, relationships_1.addRelationship)(documentRels, constants_1.RelType.Chart, `charts/chart${num}.xml`);
|
|
537
537
|
chartRIds.push(rId);
|
|
538
538
|
// Store rId in registry so renderChartDrawing can look it up
|
|
539
539
|
document_writer_1.CHART_RID_REGISTRY.set(chartContent, rId);
|
|
@@ -548,7 +548,7 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
548
548
|
archive.add(constants_1.PartPath.FontTable, renderXml(xml => (0, parts_writer_1.renderFontTable)(xml, doc.fonts)));
|
|
549
549
|
// word/fonts/*.odttf (embedded fonts)
|
|
550
550
|
if (doc.embeddedFonts && doc.embeddedFonts.length > 0) {
|
|
551
|
-
const fontTableRels =
|
|
551
|
+
const fontTableRels = (0, relationships_1.createRelationships)();
|
|
552
552
|
const usedRIds = new Set();
|
|
553
553
|
// Collect rIds referenced in fontTable
|
|
554
554
|
if (doc.fonts) {
|
|
@@ -572,26 +572,26 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
572
572
|
archive.add(partPath, ef.data);
|
|
573
573
|
// Register relationship from fontTable.xml
|
|
574
574
|
if (usedRIds.has(ef.rId)) {
|
|
575
|
-
|
|
575
|
+
(0, relationships_1.addRelationshipWithId)(fontTableRels, ef.rId, constants_1.RelType.Font, `fonts/${ef.fileName}`);
|
|
576
576
|
}
|
|
577
577
|
else {
|
|
578
578
|
// Add anyway so the embedded font isn't orphaned
|
|
579
|
-
|
|
579
|
+
(0, relationships_1.addRelationshipWithId)(fontTableRels, ef.rId, constants_1.RelType.Font, `fonts/${ef.fileName}`);
|
|
580
580
|
}
|
|
581
581
|
// Register content type for .odttf / .ttf
|
|
582
582
|
const ext = ef.fileName.split(".").pop()?.toLowerCase();
|
|
583
583
|
if (ext === "odttf") {
|
|
584
|
-
|
|
584
|
+
(0, content_types_1.addContentTypeDefault)(contentTypes, "odttf", constants_1.ContentType.ObfuscatedFont);
|
|
585
585
|
}
|
|
586
586
|
else if (ext === "ttf") {
|
|
587
|
-
|
|
587
|
+
(0, content_types_1.addContentTypeDefault)(contentTypes, "ttf", "application/x-font-ttf");
|
|
588
588
|
}
|
|
589
589
|
else if (ext === "otf") {
|
|
590
|
-
|
|
590
|
+
(0, content_types_1.addContentTypeDefault)(contentTypes, "otf", "application/x-font-otf");
|
|
591
591
|
}
|
|
592
592
|
}
|
|
593
593
|
// Write fontTable.xml.rels
|
|
594
|
-
archive.add("word/_rels/fontTable.xml.rels", renderXml(xml =>
|
|
594
|
+
archive.add("word/_rels/fontTable.xml.rels", renderXml(xml => (0, relationships_1.renderRelationships)(fontTableRels, xml)));
|
|
595
595
|
}
|
|
596
596
|
// Custom XML parts (for SDT data binding)
|
|
597
597
|
if (doc.customXmlParts && doc.customXmlParts.length > 0) {
|
|
@@ -622,13 +622,13 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
622
622
|
});
|
|
623
623
|
archive.add(propsPath, propsXml);
|
|
624
624
|
// Write item rels (links itemN.xml → itemPropsN.xml)
|
|
625
|
-
const itemRels =
|
|
626
|
-
|
|
627
|
-
archive.add(`word/customXml/_rels/item${num}.xml.rels`, renderXml(xml =>
|
|
625
|
+
const itemRels = (0, relationships_1.createRelationships)();
|
|
626
|
+
(0, relationships_1.addRelationship)(itemRels, constants_1.RelType.CustomXmlProps, `itemProps${num}.xml`);
|
|
627
|
+
archive.add(`word/customXml/_rels/item${num}.xml.rels`, renderXml(xml => (0, relationships_1.renderRelationships)(itemRels, xml)));
|
|
628
628
|
// Register content types
|
|
629
|
-
|
|
629
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, `/word/customXml/itemProps${num}.xml`, "application/vnd.openxmlformats-officedocument.customXmlProperties+xml");
|
|
630
630
|
// Add to document rels
|
|
631
|
-
|
|
631
|
+
(0, relationships_1.addRelationship)(documentRels, constants_1.RelType.CustomXml, `customXml/item${num}.xml`);
|
|
632
632
|
});
|
|
633
633
|
}
|
|
634
634
|
// word/theme/theme1.xml
|
|
@@ -653,8 +653,8 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
653
653
|
if (hasExtended) {
|
|
654
654
|
const extXml = renderXml(xml => (0, comment_writer_1.renderCommentsExtended)(xml, doc.comments));
|
|
655
655
|
archive.add(constants_1.PartPath.CommentsExtended, extXml);
|
|
656
|
-
|
|
657
|
-
|
|
656
|
+
(0, relationships_1.addRelationship)(documentRels, constants_1.RelType.CommentsExtended, "commentsExtended.xml");
|
|
657
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, `/${constants_1.PartPath.CommentsExtended}`, constants_1.ContentType.CommentsExtended);
|
|
658
658
|
}
|
|
659
659
|
}
|
|
660
660
|
// Headers
|
|
@@ -667,8 +667,8 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
667
667
|
// Header .rels file
|
|
668
668
|
const hKey = keys[hIdx];
|
|
669
669
|
const hRels = headerRelManagers.get(hKey);
|
|
670
|
-
if (hRels && hRels
|
|
671
|
-
archive.add(`word/_rels/header${headerIndex}.xml.rels`, renderXml(xml =>
|
|
670
|
+
if (hRels && (0, relationships_1.getRelationshipCount)(hRels) > 0) {
|
|
671
|
+
archive.add(`word/_rels/header${headerIndex}.xml.rels`, renderXml(xml => (0, relationships_1.renderRelationships)(hRels, xml)));
|
|
672
672
|
}
|
|
673
673
|
headerIndex++;
|
|
674
674
|
hIdx++;
|
|
@@ -684,8 +684,8 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
684
684
|
// Footer .rels file
|
|
685
685
|
const fKey = keys[fIdx];
|
|
686
686
|
const fRels = footerRelManagers.get(fKey);
|
|
687
|
-
if (fRels && fRels
|
|
688
|
-
archive.add(`word/_rels/footer${footerIndex}.xml.rels`, renderXml(xml =>
|
|
687
|
+
if (fRels && (0, relationships_1.getRelationshipCount)(fRels) > 0) {
|
|
688
|
+
archive.add(`word/_rels/footer${footerIndex}.xml.rels`, renderXml(xml => (0, relationships_1.renderRelationships)(fRels, xml)));
|
|
689
689
|
}
|
|
690
690
|
footerIndex++;
|
|
691
691
|
fIdx++;
|
|
@@ -694,8 +694,8 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
694
694
|
// Watermark header
|
|
695
695
|
if (watermarkHeaderIndex !== undefined && doc.watermark) {
|
|
696
696
|
archive.add(constants_1.PartPath.header(watermarkHeaderIndex), renderXml(xml => (0, header_footer_writer_1.renderWatermarkHeader)(xml, doc.watermark)));
|
|
697
|
-
if (watermarkHeaderRels && watermarkHeaderRels
|
|
698
|
-
archive.add(`word/_rels/header${watermarkHeaderIndex}.xml.rels`, renderXml(xml =>
|
|
697
|
+
if (watermarkHeaderRels && (0, relationships_1.getRelationshipCount)(watermarkHeaderRels) > 0) {
|
|
698
|
+
archive.add(`word/_rels/header${watermarkHeaderIndex}.xml.rels`, renderXml(xml => (0, relationships_1.renderRelationships)(watermarkHeaderRels, xml)));
|
|
699
699
|
}
|
|
700
700
|
}
|
|
701
701
|
// Media / images
|
|
@@ -719,14 +719,14 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
719
719
|
// word/webSettings.xml
|
|
720
720
|
if (doc.webSettings) {
|
|
721
721
|
archive.add(constants_1.PartPath.WebSettings, renderXml(xml => (0, parts_writer_1.renderWebSettings)(xml, doc.webSettings)));
|
|
722
|
-
|
|
723
|
-
|
|
722
|
+
(0, relationships_1.addRelationship)(documentRels, constants_1.RelType.WebSettings, "webSettings.xml");
|
|
723
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, `/${constants_1.PartPath.WebSettings}`, constants_1.ContentType.WebSettings);
|
|
724
724
|
}
|
|
725
725
|
// word/people.xml
|
|
726
726
|
if (doc.people && doc.people.length > 0) {
|
|
727
727
|
archive.add(constants_1.PartPath.People, renderXml(xml => (0, parts_writer_1.renderPeople)(xml, doc.people)));
|
|
728
|
-
|
|
729
|
-
|
|
728
|
+
(0, relationships_1.addRelationship)(documentRels, constants_1.RelType.People, "people.xml");
|
|
729
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, `/${constants_1.PartPath.People}`, constants_1.ContentType.People);
|
|
730
730
|
}
|
|
731
731
|
// docProps/thumbnail
|
|
732
732
|
if (doc.thumbnail) {
|
|
@@ -738,8 +738,8 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
738
738
|
const thumbPath = `docProps/thumbnail.${ext}`;
|
|
739
739
|
archive.add(thumbPath, doc.thumbnail.data);
|
|
740
740
|
// Package rels: target is relative to package root (docProps/thumbnail.jpeg)
|
|
741
|
-
|
|
742
|
-
|
|
741
|
+
(0, relationships_1.addRelationship)(packageRels, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail", thumbPath);
|
|
742
|
+
(0, content_types_1.addContentTypeDefault)(contentTypes, ext, doc.thumbnail.contentType);
|
|
743
743
|
}
|
|
744
744
|
// Write opaque (unrecognized) parts for round-trip preservation
|
|
745
745
|
if (doc.opaqueParts) {
|
|
@@ -748,23 +748,23 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
748
748
|
// Register content type: explicit > inferred by extension > skip
|
|
749
749
|
const ext = part.path.split(".").pop()?.toLowerCase();
|
|
750
750
|
if (part.contentType) {
|
|
751
|
-
|
|
751
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, `/${part.path}`, part.contentType);
|
|
752
752
|
}
|
|
753
753
|
else if (ext) {
|
|
754
754
|
// Infer from common extensions so [Content_Types].xml isn't incomplete
|
|
755
755
|
const inferred = inferContentType(ext);
|
|
756
756
|
if (inferred) {
|
|
757
|
-
|
|
757
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, `/${part.path}`, inferred);
|
|
758
758
|
}
|
|
759
759
|
}
|
|
760
760
|
// Write part relationships if any
|
|
761
761
|
if (part.relationships && part.relationships.length > 0) {
|
|
762
|
-
const partRels =
|
|
762
|
+
const partRels = (0, relationships_1.createRelationships)();
|
|
763
763
|
for (const rel of part.relationships) {
|
|
764
|
-
|
|
764
|
+
(0, relationships_1.addRelationshipWithId)(partRels, rel.id, rel.type, rel.target, rel.targetMode);
|
|
765
765
|
}
|
|
766
766
|
const relsPath = getPartRelsPath(part.path);
|
|
767
|
-
archive.add(relsPath, renderXml(xml =>
|
|
767
|
+
archive.add(relsPath, renderXml(xml => (0, relationships_1.renderRelationships)(partRels, xml)));
|
|
768
768
|
}
|
|
769
769
|
}
|
|
770
770
|
}
|
|
@@ -775,12 +775,12 @@ async function packageDocx(doc, compressionLevel) {
|
|
|
775
775
|
// Register chart part
|
|
776
776
|
archive.add(chartPath, renderXml(xml => (0, chart_writer_1.renderChartPart)(xml, chartContent.chart)));
|
|
777
777
|
// Register content type
|
|
778
|
-
|
|
778
|
+
(0, content_types_1.addContentTypeOverride)(contentTypes, `/word/charts/chart${num}.xml`, constants_1.ContentType.Chart);
|
|
779
779
|
});
|
|
780
780
|
// LAST: Write [Content_Types].xml and _rels/.rels after all parts have registered
|
|
781
781
|
// their content types and relationships.
|
|
782
|
-
archive.add(constants_1.PartPath.ContentTypes, renderXml(xml =>
|
|
783
|
-
archive.add(constants_1.PartPath.PackageRels, renderXml(xml =>
|
|
782
|
+
archive.add(constants_1.PartPath.ContentTypes, renderXml(xml => (0, content_types_1.renderContentTypes)(contentTypes, xml)));
|
|
783
|
+
archive.add(constants_1.PartPath.PackageRels, renderXml(xml => (0, relationships_1.renderRelationships)(packageRels, xml)));
|
|
784
784
|
return archive.bytes();
|
|
785
785
|
}
|
|
786
786
|
/** Recursively collect altChunks from body content. */
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.renderToHtml = renderToHtml;
|
|
11
|
-
const
|
|
11
|
+
const color_utils_1 = require("./color-utils");
|
|
12
12
|
const internal_utils_1 = require("./internal-utils");
|
|
13
13
|
/**
|
|
14
14
|
* Convert a DocxDocument to HTML.
|
|
@@ -722,7 +722,7 @@ function resolveColor(color, theme) {
|
|
|
722
722
|
return color.value === "auto" ? undefined : color.value;
|
|
723
723
|
}
|
|
724
724
|
if (color.themeColor && theme) {
|
|
725
|
-
return (0,
|
|
725
|
+
return (0, color_utils_1.resolveThemeColor)(color, theme);
|
|
726
726
|
}
|
|
727
727
|
}
|
|
728
728
|
return undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DOCX Module - HTML Renderer (Subpath Export)
|
|
4
|
+
*
|
|
5
|
+
* Import separately to avoid pulling html-renderer into the bundle
|
|
6
|
+
* when only core document building is needed.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { renderToHtml } from "excelts/word/html";
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.renderToHtml = void 0;
|
|
15
|
+
var html_renderer_1 = require("./html-renderer");
|
|
16
|
+
Object.defineProperty(exports, "renderToHtml", { enumerable: true, get: function () { return html_renderer_1.renderToHtml; } });
|
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
* Shared exports for both Node.js and browser environments.
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.timeField = exports.sequenceField = exports.dateField = exports.sectionField = exports.sectionPagesField = exports.totalPagesField = exports.pageNumberField = exports.field = exports.softHyphen = exports.noBreakHyphen = exports.carriageReturn = exports.ruby = exports.positionalTab = exports.tab = exports.columnBreak = exports.lineBreak = exports.pageBreak = exports.italic = exports.bold = exports.text = exports.
|
|
8
|
+
exports.timeField = exports.sequenceField = exports.dateField = exports.sectionField = exports.sectionPagesField = exports.totalPagesField = exports.pageNumberField = exports.field = exports.softHyphen = exports.noBreakHyphen = exports.carriageReturn = exports.ruby = exports.positionalTab = exports.tab = exports.columnBreak = exports.lineBreak = exports.pageBreak = exports.italic = exports.bold = exports.text = exports.Document = exports.tablePctToPercent = exports.percentToTablePct = exports.spacingToLineMultiplier = exports.lineMultiplierToSpacing = exports.eighthPointToPt = exports.ptToEighthPoint = exports.halfPointToPt = exports.ptToHalfPoint = exports.emuToPx = exports.pxToEmu = exports.ptToEmu = exports.emuToCm = exports.cmToEmu = exports.emuToInches = exports.inchesToEmu = exports.mmToTwips = exports.twipsToPt = exports.ptToTwips = exports.twipsToCm = exports.cmToTwips = exports.twipsToInches = exports.inchesToTwips = exports.isDocxError = exports.DocxUnsupportedFeatureError = exports.DocxInvalidStructureError = exports.DocxMissingPartError = exports.DocxWriteError = exports.DocxParseError = exports.DocxError = void 0;
|
|
9
9
|
exports.mathSubScript = exports.mathSuperScript = exports.mathProduct = exports.mathIntegral = exports.mathSum = exports.mathRoot = exports.mathSqrt = exports.mathFraction = exports.mathRun = exports.mathBlock = exports.checkBox = exports.moveToRangeEnd = exports.moveToRangeStart = exports.moveFromRangeEnd = exports.moveFromRangeStart = exports.movedToRun = exports.movedFromRun = exports.deletedRun = exports.insertedRun = exports.commentReference = exports.commentRangeEnd = exports.commentRangeStart = exports.bookmarkEnd = exports.bookmarkStart = exports.hyperlink = exports.heading = exports.textParagraph = exports.paragraph = exports.formDropdownField = exports.formCheckboxField = exports.formTextField = exports.includePictureField = exports.includeTextField = exports.ifField = exports.indexField = exports.indexEntryField = exports.tcField = exports.tocField = exports.quoteField = exports.hyperlinkField = exports.noteRefField = exports.pageRefField = exports.refField = exports.styleRefField = exports.fileSizeField = exports.fileNameField = exports.keywordsField = exports.subjectField = exports.titleField = exports.authorField = void 0;
|
|
10
|
-
exports.
|
|
11
|
-
exports.renderToHtml = exports.isWellFormedSignature = exports.extractSignatures = exports.parseSignatureXml = exports.hasDigitalSignatures = exports.AGILE_BLOCK_KEYS = void 0;
|
|
10
|
+
exports.MathML = exports.Query = exports.Sdt = exports.TrackChanges = exports.Drawing = exports.Field = exports.patchDocument = exports.toBase64 = exports.toBuffer = exports.readDocx = exports.packageDocx = exports.extractText = exports.tableCount = exports.listHyperlinks = exports.listTables = exports.listImages = exports.findComment = exports.findBookmark = exports.getHeadings = exports.countWords = exports.paragraphCount = exports.mailMerge = exports.resolveThemeColor = exports.replaceText = exports.searchText = exports.simpleTable = exports.table = exports.row = exports.cell = exports.gridBorders = exports.border = exports.structuredDocumentTag = exports.chart = exports.drawingShape = exports.floatingImage = exports.symbol = exports.mathEquationArray = exports.mathBox = exports.mathBar = exports.mathAccent = exports.mathMatrix = exports.mathLimit = exports.mathFunction = exports.mathNary = exports.mathDelimiter = exports.mathBorderBox = exports.mathGroupChar = exports.mathPhantom = exports.mathPreSubSuperScript = exports.mathSubSuperScript = void 0;
|
|
12
11
|
// Errors
|
|
13
12
|
var errors_1 = require("./errors");
|
|
14
13
|
Object.defineProperty(exports, "DocxError", { enumerable: true, get: function () { return errors_1.DocxError; } });
|
|
@@ -44,7 +43,7 @@ Object.defineProperty(exports, "percentToTablePct", { enumerable: true, get: fun
|
|
|
44
43
|
Object.defineProperty(exports, "tablePctToPercent", { enumerable: true, get: function () { return units_1.tablePctToPercent; } });
|
|
45
44
|
// Builder helpers
|
|
46
45
|
var document_1 = require("./document");
|
|
47
|
-
Object.defineProperty(exports, "
|
|
46
|
+
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.Document; } });
|
|
48
47
|
// Run helpers
|
|
49
48
|
Object.defineProperty(exports, "text", { enumerable: true, get: function () { return document_1.text; } });
|
|
50
49
|
Object.defineProperty(exports, "bold", { enumerable: true, get: function () { return document_1.bold; } });
|
|
@@ -156,7 +155,6 @@ Object.defineProperty(exports, "simpleTable", { enumerable: true, get: function
|
|
|
156
155
|
Object.defineProperty(exports, "searchText", { enumerable: true, get: function () { return document_1.searchText; } });
|
|
157
156
|
Object.defineProperty(exports, "replaceText", { enumerable: true, get: function () { return document_1.replaceText; } });
|
|
158
157
|
Object.defineProperty(exports, "resolveThemeColor", { enumerable: true, get: function () { return document_1.resolveThemeColor; } });
|
|
159
|
-
Object.defineProperty(exports, "patchDocument", { enumerable: true, get: function () { return document_1.patchDocument; } });
|
|
160
158
|
Object.defineProperty(exports, "mailMerge", { enumerable: true, get: function () { return document_1.mailMerge; } });
|
|
161
159
|
// Query API
|
|
162
160
|
Object.defineProperty(exports, "paragraphCount", { enumerable: true, get: function () { return document_1.paragraphCount; } });
|
|
@@ -175,25 +173,17 @@ Object.defineProperty(exports, "packageDocx", { enumerable: true, get: function
|
|
|
175
173
|
// Reader
|
|
176
174
|
var docx_reader_1 = require("./docx-reader");
|
|
177
175
|
Object.defineProperty(exports, "readDocx", { enumerable: true, get: function () { return docx_reader_1.readDocx; } });
|
|
178
|
-
//
|
|
179
|
-
var
|
|
180
|
-
Object.defineProperty(exports, "
|
|
181
|
-
Object.defineProperty(exports, "
|
|
182
|
-
Object.defineProperty(exports, "
|
|
183
|
-
//
|
|
184
|
-
var
|
|
185
|
-
Object.defineProperty(exports, "
|
|
186
|
-
Object.defineProperty(exports, "
|
|
187
|
-
Object.defineProperty(exports, "
|
|
188
|
-
Object.defineProperty(exports, "
|
|
189
|
-
Object.defineProperty(exports, "
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
var digital_signatures_1 = require("./digital-signatures");
|
|
193
|
-
Object.defineProperty(exports, "hasDigitalSignatures", { enumerable: true, get: function () { return digital_signatures_1.hasDigitalSignatures; } });
|
|
194
|
-
Object.defineProperty(exports, "parseSignatureXml", { enumerable: true, get: function () { return digital_signatures_1.parseSignatureXml; } });
|
|
195
|
-
Object.defineProperty(exports, "extractSignatures", { enumerable: true, get: function () { return digital_signatures_1.extractSignatures; } });
|
|
196
|
-
Object.defineProperty(exports, "isWellFormedSignature", { enumerable: true, get: function () { return digital_signatures_1.isWellFormedSignature; } });
|
|
197
|
-
// HTML Renderer
|
|
198
|
-
var html_renderer_1 = require("./html-renderer");
|
|
199
|
-
Object.defineProperty(exports, "renderToHtml", { enumerable: true, get: function () { return html_renderer_1.renderToHtml; } });
|
|
176
|
+
// Document IO (toBuffer, toBase64, patchDocument)
|
|
177
|
+
var document_io_1 = require("./document-io");
|
|
178
|
+
Object.defineProperty(exports, "toBuffer", { enumerable: true, get: function () { return document_io_1.toBuffer; } });
|
|
179
|
+
Object.defineProperty(exports, "toBase64", { enumerable: true, get: function () { return document_io_1.toBase64; } });
|
|
180
|
+
Object.defineProperty(exports, "patchDocument", { enumerable: true, get: function () { return document_io_1.patchDocument; } });
|
|
181
|
+
// Sub-namespaces for grouped API ergonomics (no name conflicts with types)
|
|
182
|
+
var namespaces_1 = require("./namespaces");
|
|
183
|
+
Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return namespaces_1.Field; } });
|
|
184
|
+
Object.defineProperty(exports, "Drawing", { enumerable: true, get: function () { return namespaces_1.Drawing; } });
|
|
185
|
+
Object.defineProperty(exports, "TrackChanges", { enumerable: true, get: function () { return namespaces_1.TrackChanges; } });
|
|
186
|
+
Object.defineProperty(exports, "Sdt", { enumerable: true, get: function () { return namespaces_1.Sdt; } });
|
|
187
|
+
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return namespaces_1.Query; } });
|
|
188
|
+
var namespaces_2 = require("./namespaces");
|
|
189
|
+
Object.defineProperty(exports, "MathML", { enumerable: true, get: function () { return namespaces_2.Math; } });
|