@sunertech/docx 10.0.0 → 10.0.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/index.cjs CHANGED
@@ -20735,7 +20735,6 @@ class ChartRun extends Run {
20735
20735
  }
20736
20736
  prepForXml(context) {
20737
20737
  context.file.Charts.add(this.id, this.chartSpace);
20738
- context.file.ContentTypes.addChart(context.file.Charts.Entries.length);
20739
20738
  return super.prepForXml(context);
20740
20739
  }
20741
20740
  }
@@ -28803,19 +28802,24 @@ class Compiler {
28803
28802
  };
28804
28803
  }),
28805
28804
  ContentTypes: {
28806
- data: xml(
28807
- this.formatter.format(file.ContentTypes, {
28808
- viewWrapper: file.Document,
28809
- file,
28810
- stack: []
28811
- }),
28812
- {
28813
- indent: prettify,
28814
- declaration: {
28815
- encoding: "UTF-8"
28805
+ data: (() => {
28806
+ file.Charts.Entries.forEach((_, index) => {
28807
+ file.ContentTypes.addChart(index + 1);
28808
+ });
28809
+ return xml(
28810
+ this.formatter.format(file.ContentTypes, {
28811
+ viewWrapper: file.Document,
28812
+ file,
28813
+ stack: []
28814
+ }),
28815
+ {
28816
+ indent: prettify,
28817
+ declaration: {
28818
+ encoding: "UTF-8"
28819
+ }
28816
28820
  }
28817
- }
28818
- ),
28821
+ );
28822
+ })(),
28819
28823
  path: "[Content_Types].xml"
28820
28824
  },
28821
28825
  CustomProperties: {
@@ -29476,23 +29480,52 @@ const patchDocument = (_0) => __async(null, [_0], function* ({
29476
29480
  });
29477
29481
  }
29478
29482
  const chartEntries = identifierManager.filter(JSON.stringify(json), context.file.Charts.Entries, (item) => item[0]);
29479
- chartCount = chartEntries.length;
29480
- if (chartCount > 0) {
29483
+ if (chartEntries.length > 0) {
29484
+ chartCount = chartEntries.length;
29481
29485
  relationshipAdditions.push({
29482
29486
  key,
29483
- entries: chartEntries.map((item, index) => ({
29487
+ entries: chartEntries.map(([tempId], index) => ({
29484
29488
  name: `chart${index + 1}`,
29485
29489
  path: "charts",
29486
29490
  type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
29487
- repl: item[0]
29491
+ repl: tempId
29488
29492
  }))
29489
29493
  });
29490
29494
  }
29495
+ chartEntries.forEach(([_, chartWrapper], index) => {
29496
+ const chartFilepath = `word/charts/chart${index + 1}.xml`;
29497
+ relationshipAdditions.push({
29498
+ key: chartFilepath,
29499
+ entries: [
29500
+ {
29501
+ name: `Microsoft_Excel_Sheet${index + 1}.xlsx`,
29502
+ path: "../embeddings",
29503
+ type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package",
29504
+ repl: "embedSheetId"
29505
+ }
29506
+ ]
29507
+ });
29508
+ const formatter2 = new Formatter();
29509
+ const chartElement = toJson(
29510
+ xml(formatter2.format(chartWrapper.View, context), {
29511
+ declaration: { encoding: "UTF-8" }
29512
+ })
29513
+ );
29514
+ map.set(chartFilepath, chartElement);
29515
+ const wb = utils$1.book_new();
29516
+ const ws = utils$1.aoa_to_sheet(chartWrapper.View.dataTable);
29517
+ utils$1.book_append_sheet(wb, ws, "Sheet1");
29518
+ const xlsxData = writeSyncXLSX(wb, { type: "buffer" });
29519
+ binaryContentMap.set(`word/embeddings/Microsoft_Excel_Sheet${index + 1}.xlsx`, xlsxData);
29520
+ });
29491
29521
  }
29492
29522
  map.set(key, json);
29493
29523
  }
29494
29524
  for (const { key, entries } of relationshipAdditions) {
29495
- const relationshipKey = `word/_rels/${key.split("/").pop()}.rels`;
29525
+ const lastIndex = key.lastIndexOf("/");
29526
+ const basePath = key.slice(0, lastIndex);
29527
+ const fileName = key.slice(lastIndex + 1);
29528
+ const relationshipKey = `${basePath}/_rels/${fileName}.rels`;
29496
29529
  const relationshipsJson = (_b = map.get(relationshipKey)) != null ? _b : createRelationshipFile();
29497
29530
  map.set(relationshipKey, relationshipsJson);
29498
29531
  const index = getNextRelationshipIndex(relationshipsJson);
@@ -20735,7 +20735,6 @@ var docx = (function(exports) {
20735
20735
  }
20736
20736
  prepForXml(context) {
20737
20737
  context.file.Charts.add(this.id, this.chartSpace);
20738
- context.file.ContentTypes.addChart(context.file.Charts.Entries.length);
20739
20738
  return super.prepForXml(context);
20740
20739
  }
20741
20740
  }
@@ -28803,19 +28802,24 @@ var docx = (function(exports) {
28803
28802
  };
28804
28803
  }),
28805
28804
  ContentTypes: {
28806
- data: xml(
28807
- this.formatter.format(file.ContentTypes, {
28808
- viewWrapper: file.Document,
28809
- file,
28810
- stack: []
28811
- }),
28812
- {
28813
- indent: prettify,
28814
- declaration: {
28815
- encoding: "UTF-8"
28805
+ data: (() => {
28806
+ file.Charts.Entries.forEach((_, index) => {
28807
+ file.ContentTypes.addChart(index + 1);
28808
+ });
28809
+ return xml(
28810
+ this.formatter.format(file.ContentTypes, {
28811
+ viewWrapper: file.Document,
28812
+ file,
28813
+ stack: []
28814
+ }),
28815
+ {
28816
+ indent: prettify,
28817
+ declaration: {
28818
+ encoding: "UTF-8"
28819
+ }
28816
28820
  }
28817
- }
28818
- ),
28821
+ );
28822
+ })(),
28819
28823
  path: "[Content_Types].xml"
28820
28824
  },
28821
28825
  CustomProperties: {
@@ -29476,23 +29480,52 @@ var docx = (function(exports) {
29476
29480
  });
29477
29481
  }
29478
29482
  const chartEntries = identifierManager.filter(JSON.stringify(json), context.file.Charts.Entries, (item) => item[0]);
29479
- chartCount = chartEntries.length;
29480
- if (chartCount > 0) {
29483
+ if (chartEntries.length > 0) {
29484
+ chartCount = chartEntries.length;
29481
29485
  relationshipAdditions.push({
29482
29486
  key,
29483
- entries: chartEntries.map((item, index) => ({
29487
+ entries: chartEntries.map(([tempId], index) => ({
29484
29488
  name: `chart${index + 1}`,
29485
29489
  path: "charts",
29486
29490
  type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
29487
- repl: item[0]
29491
+ repl: tempId
29488
29492
  }))
29489
29493
  });
29490
29494
  }
29495
+ chartEntries.forEach(([_, chartWrapper], index) => {
29496
+ const chartFilepath = `word/charts/chart${index + 1}.xml`;
29497
+ relationshipAdditions.push({
29498
+ key: chartFilepath,
29499
+ entries: [
29500
+ {
29501
+ name: `Microsoft_Excel_Sheet${index + 1}.xlsx`,
29502
+ path: "../embeddings",
29503
+ type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package",
29504
+ repl: "embedSheetId"
29505
+ }
29506
+ ]
29507
+ });
29508
+ const formatter2 = new Formatter();
29509
+ const chartElement = toJson(
29510
+ xml(formatter2.format(chartWrapper.View, context), {
29511
+ declaration: { encoding: "UTF-8" }
29512
+ })
29513
+ );
29514
+ map.set(chartFilepath, chartElement);
29515
+ const wb = utils$1.book_new();
29516
+ const ws = utils$1.aoa_to_sheet(chartWrapper.View.dataTable);
29517
+ utils$1.book_append_sheet(wb, ws, "Sheet1");
29518
+ const xlsxData = writeSyncXLSX(wb, { type: "buffer" });
29519
+ binaryContentMap.set(`word/embeddings/Microsoft_Excel_Sheet${index + 1}.xlsx`, xlsxData);
29520
+ });
29491
29521
  }
29492
29522
  map.set(key, json);
29493
29523
  }
29494
29524
  for (const { key, entries } of relationshipAdditions) {
29495
- const relationshipKey = `word/_rels/${key.split("/").pop()}.rels`;
29525
+ const lastIndex = key.lastIndexOf("/");
29526
+ const basePath = key.slice(0, lastIndex);
29527
+ const fileName = key.slice(lastIndex + 1);
29528
+ const relationshipKey = `${basePath}/_rels/${fileName}.rels`;
29496
29529
  const relationshipsJson = (_b = map.get(relationshipKey)) != null ? _b : createRelationshipFile();
29497
29530
  map.set(relationshipKey, relationshipsJson);
29498
29531
  const index = getNextRelationshipIndex(relationshipsJson);
package/dist/index.mjs CHANGED
@@ -20733,7 +20733,6 @@ class ChartRun extends Run {
20733
20733
  }
20734
20734
  prepForXml(context) {
20735
20735
  context.file.Charts.add(this.id, this.chartSpace);
20736
- context.file.ContentTypes.addChart(context.file.Charts.Entries.length);
20737
20736
  return super.prepForXml(context);
20738
20737
  }
20739
20738
  }
@@ -28801,19 +28800,24 @@ class Compiler {
28801
28800
  };
28802
28801
  }),
28803
28802
  ContentTypes: {
28804
- data: xml(
28805
- this.formatter.format(file.ContentTypes, {
28806
- viewWrapper: file.Document,
28807
- file,
28808
- stack: []
28809
- }),
28810
- {
28811
- indent: prettify,
28812
- declaration: {
28813
- encoding: "UTF-8"
28803
+ data: (() => {
28804
+ file.Charts.Entries.forEach((_, index) => {
28805
+ file.ContentTypes.addChart(index + 1);
28806
+ });
28807
+ return xml(
28808
+ this.formatter.format(file.ContentTypes, {
28809
+ viewWrapper: file.Document,
28810
+ file,
28811
+ stack: []
28812
+ }),
28813
+ {
28814
+ indent: prettify,
28815
+ declaration: {
28816
+ encoding: "UTF-8"
28817
+ }
28814
28818
  }
28815
- }
28816
- ),
28819
+ );
28820
+ })(),
28817
28821
  path: "[Content_Types].xml"
28818
28822
  },
28819
28823
  CustomProperties: {
@@ -29474,23 +29478,52 @@ const patchDocument = (_0) => __async(null, [_0], function* ({
29474
29478
  });
29475
29479
  }
29476
29480
  const chartEntries = identifierManager.filter(JSON.stringify(json), context.file.Charts.Entries, (item) => item[0]);
29477
- chartCount = chartEntries.length;
29478
- if (chartCount > 0) {
29481
+ if (chartEntries.length > 0) {
29482
+ chartCount = chartEntries.length;
29479
29483
  relationshipAdditions.push({
29480
29484
  key,
29481
- entries: chartEntries.map((item, index) => ({
29485
+ entries: chartEntries.map(([tempId], index) => ({
29482
29486
  name: `chart${index + 1}`,
29483
29487
  path: "charts",
29484
29488
  type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
29485
- repl: item[0]
29489
+ repl: tempId
29486
29490
  }))
29487
29491
  });
29488
29492
  }
29493
+ chartEntries.forEach(([_, chartWrapper], index) => {
29494
+ const chartFilepath = `word/charts/chart${index + 1}.xml`;
29495
+ relationshipAdditions.push({
29496
+ key: chartFilepath,
29497
+ entries: [
29498
+ {
29499
+ name: `Microsoft_Excel_Sheet${index + 1}.xlsx`,
29500
+ path: "../embeddings",
29501
+ type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package",
29502
+ repl: "embedSheetId"
29503
+ }
29504
+ ]
29505
+ });
29506
+ const formatter2 = new Formatter();
29507
+ const chartElement = toJson(
29508
+ xml(formatter2.format(chartWrapper.View, context), {
29509
+ declaration: { encoding: "UTF-8" }
29510
+ })
29511
+ );
29512
+ map.set(chartFilepath, chartElement);
29513
+ const wb = utils$1.book_new();
29514
+ const ws = utils$1.aoa_to_sheet(chartWrapper.View.dataTable);
29515
+ utils$1.book_append_sheet(wb, ws, "Sheet1");
29516
+ const xlsxData = writeSyncXLSX(wb, { type: "buffer" });
29517
+ binaryContentMap.set(`word/embeddings/Microsoft_Excel_Sheet${index + 1}.xlsx`, xlsxData);
29518
+ });
29489
29519
  }
29490
29520
  map.set(key, json);
29491
29521
  }
29492
29522
  for (const { key, entries } of relationshipAdditions) {
29493
- const relationshipKey = `word/_rels/${key.split("/").pop()}.rels`;
29523
+ const lastIndex = key.lastIndexOf("/");
29524
+ const basePath = key.slice(0, lastIndex);
29525
+ const fileName = key.slice(lastIndex + 1);
29526
+ const relationshipKey = `${basePath}/_rels/${fileName}.rels`;
29494
29527
  const relationshipsJson = (_b = map.get(relationshipKey)) != null ? _b : createRelationshipFile();
29495
29528
  map.set(relationshipKey, relationshipsJson);
29496
29529
  const index = getNextRelationshipIndex(relationshipsJson);
@@ -20737,7 +20737,6 @@ var __async = (__this, __arguments, generator) => {
20737
20737
  }
20738
20738
  prepForXml(context) {
20739
20739
  context.file.Charts.add(this.id, this.chartSpace);
20740
- context.file.ContentTypes.addChart(context.file.Charts.Entries.length);
20741
20740
  return super.prepForXml(context);
20742
20741
  }
20743
20742
  }
@@ -28805,19 +28804,24 @@ var __async = (__this, __arguments, generator) => {
28805
28804
  };
28806
28805
  }),
28807
28806
  ContentTypes: {
28808
- data: xml(
28809
- this.formatter.format(file.ContentTypes, {
28810
- viewWrapper: file.Document,
28811
- file,
28812
- stack: []
28813
- }),
28814
- {
28815
- indent: prettify,
28816
- declaration: {
28817
- encoding: "UTF-8"
28807
+ data: (() => {
28808
+ file.Charts.Entries.forEach((_, index) => {
28809
+ file.ContentTypes.addChart(index + 1);
28810
+ });
28811
+ return xml(
28812
+ this.formatter.format(file.ContentTypes, {
28813
+ viewWrapper: file.Document,
28814
+ file,
28815
+ stack: []
28816
+ }),
28817
+ {
28818
+ indent: prettify,
28819
+ declaration: {
28820
+ encoding: "UTF-8"
28821
+ }
28818
28822
  }
28819
- }
28820
- ),
28823
+ );
28824
+ })(),
28821
28825
  path: "[Content_Types].xml"
28822
28826
  },
28823
28827
  CustomProperties: {
@@ -29478,23 +29482,52 @@ var __async = (__this, __arguments, generator) => {
29478
29482
  });
29479
29483
  }
29480
29484
  const chartEntries = identifierManager.filter(JSON.stringify(json), context.file.Charts.Entries, (item) => item[0]);
29481
- chartCount = chartEntries.length;
29482
- if (chartCount > 0) {
29485
+ if (chartEntries.length > 0) {
29486
+ chartCount = chartEntries.length;
29483
29487
  relationshipAdditions.push({
29484
29488
  key,
29485
- entries: chartEntries.map((item, index) => ({
29489
+ entries: chartEntries.map(([tempId], index) => ({
29486
29490
  name: `chart${index + 1}`,
29487
29491
  path: "charts",
29488
29492
  type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",
29489
- repl: item[0]
29493
+ repl: tempId
29490
29494
  }))
29491
29495
  });
29492
29496
  }
29497
+ chartEntries.forEach(([_, chartWrapper], index) => {
29498
+ const chartFilepath = `word/charts/chart${index + 1}.xml`;
29499
+ relationshipAdditions.push({
29500
+ key: chartFilepath,
29501
+ entries: [
29502
+ {
29503
+ name: `Microsoft_Excel_Sheet${index + 1}.xlsx`,
29504
+ path: "../embeddings",
29505
+ type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package",
29506
+ repl: "embedSheetId"
29507
+ }
29508
+ ]
29509
+ });
29510
+ const formatter2 = new Formatter();
29511
+ const chartElement = toJson(
29512
+ xml(formatter2.format(chartWrapper.View, context), {
29513
+ declaration: { encoding: "UTF-8" }
29514
+ })
29515
+ );
29516
+ map.set(chartFilepath, chartElement);
29517
+ const wb = utils$1.book_new();
29518
+ const ws = utils$1.aoa_to_sheet(chartWrapper.View.dataTable);
29519
+ utils$1.book_append_sheet(wb, ws, "Sheet1");
29520
+ const xlsxData = writeSyncXLSX(wb, { type: "buffer" });
29521
+ binaryContentMap.set(`word/embeddings/Microsoft_Excel_Sheet${index + 1}.xlsx`, xlsxData);
29522
+ });
29493
29523
  }
29494
29524
  map.set(key, json);
29495
29525
  }
29496
29526
  for (const { key, entries } of relationshipAdditions) {
29497
- const relationshipKey = `word/_rels/${key.split("/").pop()}.rels`;
29527
+ const lastIndex = key.lastIndexOf("/");
29528
+ const basePath = key.slice(0, lastIndex);
29529
+ const fileName = key.slice(lastIndex + 1);
29530
+ const relationshipKey = `${basePath}/_rels/${fileName}.rels`;
29498
29531
  const relationshipsJson = (_b = map.get(relationshipKey)) != null ? _b : createRelationshipFile();
29499
29532
  map.set(relationshipKey, relationshipsJson);
29500
29533
  const index = getNextRelationshipIndex(relationshipsJson);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunertech/docx",
3
- "version": "10.0.0",
3
+ "version": "10.0.1",
4
4
  "description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
5
5
  "type": "module",
6
6
  "main": "dist/index.umd.cjs",