ooxml.js 6.3.7 → 7.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.
Files changed (52) hide show
  1. package/README.md +3 -2
  2. package/dist/{codec-D6UovAeS.d.ts → codec-BT_RdGLe.d.ts} +4 -3
  3. package/dist/{codec-BQU_AqVe.d.cts → codec-Ca78GND5.d.cts} +4 -3
  4. package/dist/codec.d.cts +1 -1
  5. package/dist/codec.d.ts +1 -1
  6. package/dist/{document-tree-CjI-Z4Tp.d.cts → document-tree-BQevawcZ.d.cts} +1 -1
  7. package/dist/{document-tree-B17XbBOR.d.ts → document-tree-ryxE_URD.d.ts} +1 -1
  8. package/dist/index.cjs +5 -1
  9. package/dist/index.d.cts +6 -5
  10. package/dist/index.d.ts +6 -5
  11. package/dist/index.js +4 -3
  12. package/dist/{metadata-C74-XCrx.d.cts → metadata-Di0PfE5h.d.cts} +9 -1
  13. package/dist/{metadata-Bjfa88HQ.d.ts → metadata-_k8PRY6p.d.ts} +9 -1
  14. package/dist/{read-6whiWc5N.cjs → read-Bu4DECZB.cjs} +54 -8
  15. package/dist/{read-BrAuHnvH.js → read-DlkyVzBP.js} +53 -7
  16. package/dist/shading-BF2-DM4L.d.ts +9 -0
  17. package/dist/shading-DB9hu40o.d.cts +9 -0
  18. package/dist/typed/document-tree.cjs +1 -1
  19. package/dist/typed/document-tree.d.cts +1 -1
  20. package/dist/typed/document-tree.d.ts +1 -1
  21. package/dist/typed/document-tree.js +1 -1
  22. package/dist/typed/docx/read.cjs +1 -1
  23. package/dist/typed/docx/read.js +1 -1
  24. package/dist/typed/docx/shading.cjs +95 -0
  25. package/dist/typed/docx/shading.d.cts +2 -0
  26. package/dist/typed/docx/shading.d.ts +2 -0
  27. package/dist/typed/docx/shading.js +93 -0
  28. package/dist/typed/docx/write.cjs +2 -5
  29. package/dist/typed/docx/write.d.cts +1 -1
  30. package/dist/typed/docx/write.d.ts +1 -1
  31. package/dist/typed/docx/write.js +2 -5
  32. package/dist/typed/embedded.cjs +1 -1
  33. package/dist/typed/embedded.js +1 -1
  34. package/dist/typed/pptx/read.cjs +1 -1
  35. package/dist/typed/pptx/read.js +1 -1
  36. package/dist/typed/shared/metadata.cjs +53 -0
  37. package/dist/typed/shared/metadata.d.cts +2 -2
  38. package/dist/typed/shared/metadata.d.ts +2 -2
  39. package/dist/typed/shared/metadata.js +52 -1
  40. package/dist/typed/xlsx/build.cjs +10 -4
  41. package/dist/typed/xlsx/build.js +10 -4
  42. package/dist/typed/xlsx/styles.cjs +70 -12
  43. package/dist/typed/xlsx/styles.d.cts +17 -8
  44. package/dist/typed/xlsx/styles.d.ts +17 -8
  45. package/dist/typed/xlsx/styles.js +71 -13
  46. package/dist/typed/xlsx/units.cjs +5 -1
  47. package/dist/typed/xlsx/units.d.cts +2 -1
  48. package/dist/typed/xlsx/units.d.ts +2 -1
  49. package/dist/typed/xlsx/units.js +5 -2
  50. package/dist/{write-BGTpp3RS.d.cts → write-C81qQcnp.d.cts} +1 -1
  51. package/dist/{write-Cnfu3zdB.d.ts → write-h7kU0YPl.d.ts} +1 -1
  52. package/package.json +4 -4
@@ -1,2 +1,2 @@
1
- import { a as SectionHeaderFooterReferencesSchema, i as HeaderFooterPartSchema, n as DocxDocumentSchema, o as readDocxContent, r as FootnoteSchema, t as CommentSchema } from "../../read-BrAuHnvH.js";
1
+ import { a as SectionHeaderFooterReferencesSchema, i as HeaderFooterPartSchema, n as DocxDocumentSchema, o as readDocxContent, r as FootnoteSchema, t as CommentSchema } from "../../read-DlkyVzBP.js";
2
2
  export { CommentSchema, DocxDocumentSchema, FootnoteSchema, HeaderFooterPartSchema, SectionHeaderFooterReferencesSchema, readDocxContent };
@@ -0,0 +1,95 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xml_fragment = require("../../xml/fragment.cjs");
3
+ const require_typed_util = require("../util.cjs");
4
+ let document_schema_js = require("document-schema.js");
5
+ //#region src/typed/docx/shading.ts
6
+ const SHD_VAL_TO_PATTERN_TYPE = {
7
+ pct5: "percent5",
8
+ pct10: "percent10",
9
+ pct12: "percent12",
10
+ pct15: "percent15",
11
+ pct20: "percent20",
12
+ pct25: "percent25",
13
+ pct30: "percent30",
14
+ pct35: "percent35",
15
+ pct37: "percent37",
16
+ pct40: "percent40",
17
+ pct45: "percent45",
18
+ pct50: "percent50",
19
+ pct55: "percent55",
20
+ pct60: "percent60",
21
+ pct62: "percent62",
22
+ pct65: "percent65",
23
+ pct70: "percent70",
24
+ pct75: "percent75",
25
+ pct80: "percent80",
26
+ pct85: "percent85",
27
+ pct87: "percent87",
28
+ pct90: "percent90",
29
+ pct95: "percent95",
30
+ horzStripe: "horizontalStripe",
31
+ vertStripe: "verticalStripe",
32
+ reverseDiagStripe: "reverseDiagonalStripe",
33
+ diagStripe: "diagonalStripe",
34
+ horzCross: "horizontalCross",
35
+ diagCross: "diagonalCross",
36
+ thinHorzStripe: "thinHorizontalStripe",
37
+ thinVertStripe: "thinVerticalStripe",
38
+ thinReverseDiagStripe: "thinReverseDiagonalStripe",
39
+ thinDiagStripe: "thinDiagonalStripe",
40
+ thinHorzCross: "thinHorizontalCross",
41
+ thinDiagCross: "thinDiagonalCross"
42
+ };
43
+ /** The inverse of SHD_VAL_TO_PATTERN_TYPE, built from it rather than restated by hand so the two can never drift apart. Every ContentCellPatternType this writer is ever asked to state has an entry, since the Word-family half of the shared vocabulary is exactly SHD_VAL_TO_PATTERN_TYPE's own value set -- the SpreadsheetML-only members (mediumGray through gray0625) are absent, ST_Shd having no equivalent for them at all. */
44
+ const PATTERN_TYPE_TO_SHD_VAL = new Map(Object.entries(SHD_VAL_TO_PATTERN_TYPE).map(([val, patternType]) => [patternType, val]));
45
+ /** w:shd/@w:color and @w:fill share the identical "auto"/"none" spelling for no concrete colour that w:color/@w:val already uses on a run -- both defer rather than asserting one. */
46
+ function shdColor(value) {
47
+ return value === void 0 || value === "auto" || value === "none" ? void 0 : (0, document_schema_js.rgbHexToColor)(value);
48
+ }
49
+ /** One <w:shd> element -> a ContentCellFill, or undefined where it states none. */
50
+ function readCellShading(tcPr) {
51
+ const shd = tcPr === void 0 ? void 0 : require_typed_util.childrenWithTag(tcPr, "w:shd")[0];
52
+ if (shd === void 0) return;
53
+ const val = require_typed_util.attr(shd, "w:val");
54
+ const fill = shdColor(require_typed_util.attr(shd, "w:fill"));
55
+ const color = shdColor(require_typed_util.attr(shd, "w:color"));
56
+ if (val === void 0 || val === "clear") return fill === void 0 ? void 0 : {
57
+ kind: "solid",
58
+ color: fill
59
+ };
60
+ if (val === "solid") return color === void 0 ? void 0 : {
61
+ kind: "solid",
62
+ color
63
+ };
64
+ const patternType = SHD_VAL_TO_PATTERN_TYPE[val];
65
+ if (patternType === void 0) return;
66
+ return {
67
+ kind: "pattern",
68
+ patternType,
69
+ ...color !== void 0 ? { foregroundColor: color } : {},
70
+ ...fill !== void 0 ? { backgroundColor: fill } : {}
71
+ };
72
+ }
73
+ /** The inverse of readCellShading: a ContentCellFill's own single <w:shd> element. A 'solid' fill writes w:val="clear" with the colour stated as w:fill (the plain background a real producer's own solid cell fill is spelled with) and w:color left automatic. A 'pattern' fill writes its own token from PATTERN_TYPE_TO_SHD_VAL, with w:color/w:fill stated for whichever of foregroundColor/backgroundColor the fill actually carries and left automatic for the one it does not -- throwing for a SpreadsheetML-only pattern name ST_Shd has no member for, rather than writing the wrong pattern or silently dropping it. */
74
+ function buildCellShading(fill) {
75
+ switch (fill.kind) {
76
+ case "solid": return require_xml_fragment.el("w:shd", {
77
+ "w:val": "clear",
78
+ "w:color": "auto",
79
+ "w:fill": (0, document_schema_js.colorToRgbHex)(fill.color)
80
+ });
81
+ case "pattern": {
82
+ const val = PATTERN_TYPE_TO_SHD_VAL.get(fill.patternType);
83
+ if (val === void 0) throw new Error(`ooxml.js cannot write a '${fill.patternType}' cell fill: ECMA-376's own ST_Shd vocabulary has no member for it, that pattern name belonging only to SpreadsheetML's ST_PatternType half of ContentCellPatternType's shared vocabulary`);
84
+ return require_xml_fragment.el("w:shd", {
85
+ "w:val": val,
86
+ "w:color": fill.foregroundColor === void 0 ? "auto" : (0, document_schema_js.colorToRgbHex)(fill.foregroundColor),
87
+ "w:fill": fill.backgroundColor === void 0 ? "auto" : (0, document_schema_js.colorToRgbHex)(fill.backgroundColor)
88
+ });
89
+ }
90
+ default: throw new Error(`ooxml.js cannot write a cell fill with kind '${(0, document_schema_js.unrecognizedFillKind)(fill)}': ContentCellFillSchema's discriminated union only defines 'solid' and 'pattern'`);
91
+ }
92
+ }
93
+ //#endregion
94
+ exports.buildCellShading = buildCellShading;
95
+ exports.readCellShading = readCellShading;
@@ -0,0 +1,2 @@
1
+ import { n as readCellShading, t as buildCellShading } from "../../shading-DB9hu40o.cjs";
2
+ export { buildCellShading, readCellShading };
@@ -0,0 +1,2 @@
1
+ import { n as readCellShading, t as buildCellShading } from "../../shading-BF2-DM4L.js";
2
+ export { buildCellShading, readCellShading };
@@ -0,0 +1,93 @@
1
+ import { el } from "../../xml/fragment.js";
2
+ import { attr, childrenWithTag } from "../util.js";
3
+ import { colorToRgbHex, rgbHexToColor, unrecognizedFillKind } from "document-schema.js";
4
+ //#region src/typed/docx/shading.ts
5
+ const SHD_VAL_TO_PATTERN_TYPE = {
6
+ pct5: "percent5",
7
+ pct10: "percent10",
8
+ pct12: "percent12",
9
+ pct15: "percent15",
10
+ pct20: "percent20",
11
+ pct25: "percent25",
12
+ pct30: "percent30",
13
+ pct35: "percent35",
14
+ pct37: "percent37",
15
+ pct40: "percent40",
16
+ pct45: "percent45",
17
+ pct50: "percent50",
18
+ pct55: "percent55",
19
+ pct60: "percent60",
20
+ pct62: "percent62",
21
+ pct65: "percent65",
22
+ pct70: "percent70",
23
+ pct75: "percent75",
24
+ pct80: "percent80",
25
+ pct85: "percent85",
26
+ pct87: "percent87",
27
+ pct90: "percent90",
28
+ pct95: "percent95",
29
+ horzStripe: "horizontalStripe",
30
+ vertStripe: "verticalStripe",
31
+ reverseDiagStripe: "reverseDiagonalStripe",
32
+ diagStripe: "diagonalStripe",
33
+ horzCross: "horizontalCross",
34
+ diagCross: "diagonalCross",
35
+ thinHorzStripe: "thinHorizontalStripe",
36
+ thinVertStripe: "thinVerticalStripe",
37
+ thinReverseDiagStripe: "thinReverseDiagonalStripe",
38
+ thinDiagStripe: "thinDiagonalStripe",
39
+ thinHorzCross: "thinHorizontalCross",
40
+ thinDiagCross: "thinDiagonalCross"
41
+ };
42
+ /** The inverse of SHD_VAL_TO_PATTERN_TYPE, built from it rather than restated by hand so the two can never drift apart. Every ContentCellPatternType this writer is ever asked to state has an entry, since the Word-family half of the shared vocabulary is exactly SHD_VAL_TO_PATTERN_TYPE's own value set -- the SpreadsheetML-only members (mediumGray through gray0625) are absent, ST_Shd having no equivalent for them at all. */
43
+ const PATTERN_TYPE_TO_SHD_VAL = new Map(Object.entries(SHD_VAL_TO_PATTERN_TYPE).map(([val, patternType]) => [patternType, val]));
44
+ /** w:shd/@w:color and @w:fill share the identical "auto"/"none" spelling for no concrete colour that w:color/@w:val already uses on a run -- both defer rather than asserting one. */
45
+ function shdColor(value) {
46
+ return value === void 0 || value === "auto" || value === "none" ? void 0 : rgbHexToColor(value);
47
+ }
48
+ /** One <w:shd> element -> a ContentCellFill, or undefined where it states none. */
49
+ function readCellShading(tcPr) {
50
+ const shd = tcPr === void 0 ? void 0 : childrenWithTag(tcPr, "w:shd")[0];
51
+ if (shd === void 0) return;
52
+ const val = attr(shd, "w:val");
53
+ const fill = shdColor(attr(shd, "w:fill"));
54
+ const color = shdColor(attr(shd, "w:color"));
55
+ if (val === void 0 || val === "clear") return fill === void 0 ? void 0 : {
56
+ kind: "solid",
57
+ color: fill
58
+ };
59
+ if (val === "solid") return color === void 0 ? void 0 : {
60
+ kind: "solid",
61
+ color
62
+ };
63
+ const patternType = SHD_VAL_TO_PATTERN_TYPE[val];
64
+ if (patternType === void 0) return;
65
+ return {
66
+ kind: "pattern",
67
+ patternType,
68
+ ...color !== void 0 ? { foregroundColor: color } : {},
69
+ ...fill !== void 0 ? { backgroundColor: fill } : {}
70
+ };
71
+ }
72
+ /** The inverse of readCellShading: a ContentCellFill's own single <w:shd> element. A 'solid' fill writes w:val="clear" with the colour stated as w:fill (the plain background a real producer's own solid cell fill is spelled with) and w:color left automatic. A 'pattern' fill writes its own token from PATTERN_TYPE_TO_SHD_VAL, with w:color/w:fill stated for whichever of foregroundColor/backgroundColor the fill actually carries and left automatic for the one it does not -- throwing for a SpreadsheetML-only pattern name ST_Shd has no member for, rather than writing the wrong pattern or silently dropping it. */
73
+ function buildCellShading(fill) {
74
+ switch (fill.kind) {
75
+ case "solid": return el("w:shd", {
76
+ "w:val": "clear",
77
+ "w:color": "auto",
78
+ "w:fill": colorToRgbHex(fill.color)
79
+ });
80
+ case "pattern": {
81
+ const val = PATTERN_TYPE_TO_SHD_VAL.get(fill.patternType);
82
+ if (val === void 0) throw new Error(`ooxml.js cannot write a '${fill.patternType}' cell fill: ECMA-376's own ST_Shd vocabulary has no member for it, that pattern name belonging only to SpreadsheetML's ST_PatternType half of ContentCellPatternType's shared vocabulary`);
83
+ return el("w:shd", {
84
+ "w:val": val,
85
+ "w:color": fill.foregroundColor === void 0 ? "auto" : colorToRgbHex(fill.foregroundColor),
86
+ "w:fill": fill.backgroundColor === void 0 ? "auto" : colorToRgbHex(fill.backgroundColor)
87
+ });
88
+ }
89
+ default: throw new Error(`ooxml.js cannot write a cell fill with kind '${unrecognizedFillKind(fill)}': ContentCellFillSchema's discriminated union only defines 'solid' and 'pattern'`);
90
+ }
91
+ }
92
+ //#endregion
93
+ export { buildCellShading, readCellShading };
@@ -5,6 +5,7 @@ const require_codec = require("../../codec.cjs");
5
5
  const require_xml_fragment = require("../../xml/fragment.cjs");
6
6
  const require_xml_entities = require("../../xml/entities.cjs");
7
7
  const require_typed_shared_units = require("../shared/units.cjs");
8
+ const require_typed_docx_shading = require("./shading.cjs");
8
9
  const require_typed_docx_constructs = require("./constructs.cjs");
9
10
  const require_typed_xlsx_build = require("../xlsx/build.cjs");
10
11
  let document_schema_js = require("document-schema.js");
@@ -337,11 +338,7 @@ function buildCell(cell, state, deleted, gridSpan, vMerge) {
337
338
  if (gridSpan > 1) tcPrChildren.push(require_xml_fragment.el("w:gridSpan", { "w:val": String(gridSpan) }));
338
339
  if (vMerge === "restart") tcPrChildren.push(require_xml_fragment.el("w:vMerge", { "w:val": "restart" }));
339
340
  else if (vMerge === "continue") tcPrChildren.push(require_xml_fragment.el("w:vMerge"));
340
- if (cell.background !== void 0) tcPrChildren.push(require_xml_fragment.el("w:shd", {
341
- "w:val": "clear",
342
- "w:color": "auto",
343
- "w:fill": (0, document_schema_js.colorToRgbHex)(cell.background)
344
- }));
341
+ if (cell.background !== void 0) tcPrChildren.push(require_typed_docx_shading.buildCellShading(cell.background));
345
342
  if (cell.borders !== void 0) tcPrChildren.push(buildCellBorders(cell.borders));
346
343
  const content = buildBlockFlow(cell.blocks, state, deleted);
347
344
  const body = content.length === 0 ? [require_xml_fragment.el("w:p")] : content;
@@ -1,2 +1,2 @@
1
- import { i as buildDocxPackageFromContent, n as DocxContent, r as EmbeddedPresentationSerialiser, t as BuildDocxContentOptions } from "../../write-BGTpp3RS.cjs";
1
+ import { i as buildDocxPackageFromContent, n as DocxContent, r as EmbeddedPresentationSerialiser, t as BuildDocxContentOptions } from "../../write-C81qQcnp.cjs";
2
2
  export { BuildDocxContentOptions, DocxContent, EmbeddedPresentationSerialiser, buildDocxPackageFromContent };
@@ -1,2 +1,2 @@
1
- import { i as buildDocxPackageFromContent, n as DocxContent, r as EmbeddedPresentationSerialiser, t as BuildDocxContentOptions } from "../../write-Cnfu3zdB.js";
1
+ import { i as buildDocxPackageFromContent, n as DocxContent, r as EmbeddedPresentationSerialiser, t as BuildDocxContentOptions } from "../../write-h7kU0YPl.js";
2
2
  export { BuildDocxContentOptions, DocxContent, EmbeddedPresentationSerialiser, buildDocxPackageFromContent };
@@ -4,6 +4,7 @@ import { encodePackage } from "../../codec.js";
4
4
  import { el, txt } from "../../xml/fragment.js";
5
5
  import { encodeXmlText } from "../../xml/entities.js";
6
6
  import { ptToEighthPoints, ptToEmu, ptToHalfPoints, ptToTwips } from "../shared/units.js";
7
+ import { buildCellShading } from "./shading.js";
7
8
  import { TABLE_OF_CONTENTS_GALLERY, isDeletedChange } from "./constructs.js";
8
9
  import { buildXlsxPackageFromContent } from "../xlsx/build.js";
9
10
  import { colorToRgbHex, findConstructMarkerImbalance, findRunConstructFault } from "document-schema.js";
@@ -336,11 +337,7 @@ function buildCell(cell, state, deleted, gridSpan, vMerge) {
336
337
  if (gridSpan > 1) tcPrChildren.push(el("w:gridSpan", { "w:val": String(gridSpan) }));
337
338
  if (vMerge === "restart") tcPrChildren.push(el("w:vMerge", { "w:val": "restart" }));
338
339
  else if (vMerge === "continue") tcPrChildren.push(el("w:vMerge"));
339
- if (cell.background !== void 0) tcPrChildren.push(el("w:shd", {
340
- "w:val": "clear",
341
- "w:color": "auto",
342
- "w:fill": colorToRgbHex(cell.background)
343
- }));
340
+ if (cell.background !== void 0) tcPrChildren.push(buildCellShading(cell.background));
344
341
  if (cell.borders !== void 0) tcPrChildren.push(buildCellBorders(cell.borders));
345
342
  const content = buildBlockFlow(cell.blocks, state, deleted);
346
343
  const body = content.length === 0 ? [el("w:p")] : content;
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_read = require("../read-6whiWc5N.cjs");
2
+ const require_read = require("../read-Bu4DECZB.cjs");
3
3
  exports.readEmbeddedOoxmlPayload = require_read.readEmbeddedOoxmlPayload;
4
4
  exports.readEmbeddedPayloadPart = require_read.readEmbeddedPayloadPart;
@@ -1,2 +1,2 @@
1
- import { c as readEmbeddedPayloadPart, s as readEmbeddedOoxmlPayload } from "../read-BrAuHnvH.js";
1
+ import { c as readEmbeddedPayloadPart, s as readEmbeddedOoxmlPayload } from "../read-DlkyVzBP.js";
2
2
  export { readEmbeddedOoxmlPayload, readEmbeddedPayloadPart };
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_read = require("../../read-6whiWc5N.cjs");
2
+ const require_read = require("../../read-Bu4DECZB.cjs");
3
3
  exports.PptxDocumentSchema = require_read.PptxDocumentSchema;
4
4
  exports.readPptxContent = require_read.readPptxContent;
@@ -1,2 +1,2 @@
1
- import { l as PptxDocumentSchema, u as readPptxContent } from "../../read-BrAuHnvH.js";
1
+ import { l as PptxDocumentSchema, u as readPptxContent } from "../../read-DlkyVzBP.js";
2
2
  export { PptxDocumentSchema, readPptxContent };
@@ -1,4 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xml_fragment = require("../../xml/fragment.cjs");
3
+ const require_xml_entities = require("../../xml/entities.cjs");
2
4
  const require_typed_util = require("../util.cjs");
3
5
  let zod = require("zod");
4
6
  //#region src/typed/shared/metadata.ts
@@ -13,6 +15,10 @@ const DocumentMetadataSchema = zod.z.object({
13
15
  });
14
16
  const CORE_PROPERTIES_PATH = "docProps/core.xml";
15
17
  const APP_PROPERTIES_PATH = "docProps/app.xml";
18
+ const CORE_PROPERTIES_NAMESPACE_URI_FOR_PREFIX = {
19
+ cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
20
+ dc: "http://purl.org/dc/elements/1.1/"
21
+ };
16
22
  function firstElementText(root, tag) {
17
23
  if (root === void 0) return;
18
24
  const element = require_typed_util.childrenWithTag(root, tag)[0];
@@ -39,6 +45,53 @@ function readCoreProperties(pkg) {
39
45
  modifiedIso: firstElementText(core, "dcterms:modified")
40
46
  };
41
47
  }
48
+ function hasCoreProperties(pkg) {
49
+ return pkg.parts[CORE_PROPERTIES_PATH]?.kind === "xml";
50
+ }
51
+ function namespacePrefixOf(tag) {
52
+ const colonIndex = tag.indexOf(":");
53
+ return colonIndex === -1 ? void 0 : tag.slice(0, colonIndex);
54
+ }
55
+ function ensureNamespaceDeclared(root, tag) {
56
+ const prefix = namespacePrefixOf(tag);
57
+ if (prefix === void 0) return;
58
+ const uri = CORE_PROPERTIES_NAMESPACE_URI_FOR_PREFIX[prefix];
59
+ if (uri === void 0) return;
60
+ const attrName = `xmlns:${prefix}`;
61
+ if (root.attributes.some((a) => a.name === attrName)) return;
62
+ root.attributes.push({
63
+ name: attrName,
64
+ value: uri
65
+ });
66
+ }
67
+ function setElementText(parent, tag, value) {
68
+ const existing = require_typed_util.childrenWithTag(parent, tag)[0];
69
+ const textNode = require_xml_fragment.txt(require_xml_entities.encodeXmlText(value));
70
+ if (existing !== void 0) {
71
+ existing.children = [textNode];
72
+ return;
73
+ }
74
+ ensureNamespaceDeclared(parent, tag);
75
+ parent.children.push(require_xml_fragment.el(tag, {}, [textNode]));
76
+ }
77
+ function removeChildrenWithTag(parent, tag) {
78
+ parent.children = parent.children.filter((child) => !(child.type === "element" && child.tag === tag));
79
+ }
80
+ function patchCoreProperties(pkg, overrides) {
81
+ const part = pkg.parts[CORE_PROPERTIES_PATH];
82
+ if (part?.kind !== "xml") throw new Error(`patchCoreProperties: package has no '${CORE_PROPERTIES_PATH}' XML part to patch -- check hasCoreProperties first, or build one from scratch instead`);
83
+ const core = require_typed_util.rootElement(part);
84
+ if (core === void 0) throw new Error(`patchCoreProperties: '${CORE_PROPERTIES_PATH}' has no root element`);
85
+ if (overrides.title !== void 0) setElementText(core, "dc:title", overrides.title);
86
+ if (overrides.author !== void 0) setElementText(core, "dc:creator", overrides.author);
87
+ if (overrides.subject !== void 0) setElementText(core, "dc:subject", overrides.subject);
88
+ if (overrides.keywords !== void 0) {
89
+ if (overrides.keywords.length > 0) setElementText(core, "cp:keywords", overrides.keywords.join(", "));
90
+ else removeChildrenWithTag(core, "cp:keywords");
91
+ }
92
+ }
42
93
  //#endregion
43
94
  exports.DocumentMetadataSchema = DocumentMetadataSchema;
95
+ exports.hasCoreProperties = hasCoreProperties;
96
+ exports.patchCoreProperties = patchCoreProperties;
44
97
  exports.readCoreProperties = readCoreProperties;
@@ -1,2 +1,2 @@
1
- import { n as DocumentMetadataSchema, r as readCoreProperties, t as DocumentMetadata } from "../../metadata-C74-XCrx.cjs";
2
- export { DocumentMetadata, DocumentMetadataSchema, readCoreProperties };
1
+ import { a as patchCoreProperties, i as hasCoreProperties, n as DocumentMetadata, o as readCoreProperties, r as DocumentMetadataSchema, t as CorePropertiesOverrides } from "../../metadata-Di0PfE5h.cjs";
2
+ export { CorePropertiesOverrides, DocumentMetadata, DocumentMetadataSchema, hasCoreProperties, patchCoreProperties, readCoreProperties };
@@ -1,2 +1,2 @@
1
- import { n as DocumentMetadataSchema, r as readCoreProperties, t as DocumentMetadata } from "../../metadata-Bjfa88HQ.js";
2
- export { DocumentMetadata, DocumentMetadataSchema, readCoreProperties };
1
+ import { a as patchCoreProperties, i as hasCoreProperties, n as DocumentMetadata, o as readCoreProperties, r as DocumentMetadataSchema, t as CorePropertiesOverrides } from "../../metadata-_k8PRY6p.js";
2
+ export { CorePropertiesOverrides, DocumentMetadata, DocumentMetadataSchema, hasCoreProperties, patchCoreProperties, readCoreProperties };
@@ -1,3 +1,5 @@
1
+ import { el, txt } from "../../xml/fragment.js";
2
+ import { encodeXmlText } from "../../xml/entities.js";
1
3
  import { childrenWithTag, rootElement, textContent } from "../util.js";
2
4
  import { z } from "zod";
3
5
  //#region src/typed/shared/metadata.ts
@@ -12,6 +14,10 @@ const DocumentMetadataSchema = z.object({
12
14
  });
13
15
  const CORE_PROPERTIES_PATH = "docProps/core.xml";
14
16
  const APP_PROPERTIES_PATH = "docProps/app.xml";
17
+ const CORE_PROPERTIES_NAMESPACE_URI_FOR_PREFIX = {
18
+ cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
19
+ dc: "http://purl.org/dc/elements/1.1/"
20
+ };
15
21
  function firstElementText(root, tag) {
16
22
  if (root === void 0) return;
17
23
  const element = childrenWithTag(root, tag)[0];
@@ -38,5 +44,50 @@ function readCoreProperties(pkg) {
38
44
  modifiedIso: firstElementText(core, "dcterms:modified")
39
45
  };
40
46
  }
47
+ function hasCoreProperties(pkg) {
48
+ return pkg.parts[CORE_PROPERTIES_PATH]?.kind === "xml";
49
+ }
50
+ function namespacePrefixOf(tag) {
51
+ const colonIndex = tag.indexOf(":");
52
+ return colonIndex === -1 ? void 0 : tag.slice(0, colonIndex);
53
+ }
54
+ function ensureNamespaceDeclared(root, tag) {
55
+ const prefix = namespacePrefixOf(tag);
56
+ if (prefix === void 0) return;
57
+ const uri = CORE_PROPERTIES_NAMESPACE_URI_FOR_PREFIX[prefix];
58
+ if (uri === void 0) return;
59
+ const attrName = `xmlns:${prefix}`;
60
+ if (root.attributes.some((a) => a.name === attrName)) return;
61
+ root.attributes.push({
62
+ name: attrName,
63
+ value: uri
64
+ });
65
+ }
66
+ function setElementText(parent, tag, value) {
67
+ const existing = childrenWithTag(parent, tag)[0];
68
+ const textNode = txt(encodeXmlText(value));
69
+ if (existing !== void 0) {
70
+ existing.children = [textNode];
71
+ return;
72
+ }
73
+ ensureNamespaceDeclared(parent, tag);
74
+ parent.children.push(el(tag, {}, [textNode]));
75
+ }
76
+ function removeChildrenWithTag(parent, tag) {
77
+ parent.children = parent.children.filter((child) => !(child.type === "element" && child.tag === tag));
78
+ }
79
+ function patchCoreProperties(pkg, overrides) {
80
+ const part = pkg.parts[CORE_PROPERTIES_PATH];
81
+ if (part?.kind !== "xml") throw new Error(`patchCoreProperties: package has no '${CORE_PROPERTIES_PATH}' XML part to patch -- check hasCoreProperties first, or build one from scratch instead`);
82
+ const core = rootElement(part);
83
+ if (core === void 0) throw new Error(`patchCoreProperties: '${CORE_PROPERTIES_PATH}' has no root element`);
84
+ if (overrides.title !== void 0) setElementText(core, "dc:title", overrides.title);
85
+ if (overrides.author !== void 0) setElementText(core, "dc:creator", overrides.author);
86
+ if (overrides.subject !== void 0) setElementText(core, "dc:subject", overrides.subject);
87
+ if (overrides.keywords !== void 0) {
88
+ if (overrides.keywords.length > 0) setElementText(core, "cp:keywords", overrides.keywords.join(", "));
89
+ else removeChildrenWithTag(core, "cp:keywords");
90
+ }
91
+ }
41
92
  //#endregion
42
- export { DocumentMetadataSchema, readCoreProperties };
93
+ export { DocumentMetadataSchema, hasCoreProperties, patchCoreProperties, readCoreProperties };
@@ -197,11 +197,17 @@ function buildStylesPart(cellFormats, dxfTable) {
197
197
  children.push(require_xml_fragment.el("numFmts", { count: String(numFmtElements.length) }, numFmtElements));
198
198
  }
199
199
  const fillElements = cellFormats.fillDeclarations().map((fill) => {
200
- if (fill.patternType === "solid") {
201
- const rgb = fill.rgb ?? "000000";
202
- return require_xml_fragment.el("fill", {}, [require_xml_fragment.el("patternFill", { patternType: "solid" }, [require_xml_fragment.el("fgColor", { rgb: `FF${rgb}` }), require_xml_fragment.el("bgColor", { indexed: "64" })])]);
200
+ switch (fill.kind) {
201
+ case "none": return require_xml_fragment.el("fill", {}, [require_xml_fragment.el("patternFill", { patternType: "none" })]);
202
+ case "gray125": return require_xml_fragment.el("fill", {}, [require_xml_fragment.el("patternFill", { patternType: "gray125" })]);
203
+ case "solid": return require_xml_fragment.el("fill", {}, [require_xml_fragment.el("patternFill", { patternType: "solid" }, [require_xml_fragment.el("fgColor", { rgb: `FF${fill.rgb}` }), require_xml_fragment.el("bgColor", { indexed: "64" })])]);
204
+ case "pattern": {
205
+ const children = [];
206
+ if (fill.fgRgb !== void 0) children.push(require_xml_fragment.el("fgColor", { rgb: `FF${fill.fgRgb}` }));
207
+ if (fill.bgRgb !== void 0) children.push(require_xml_fragment.el("bgColor", { rgb: `FF${fill.bgRgb}` }));
208
+ return require_xml_fragment.el("fill", {}, [require_xml_fragment.el("patternFill", { patternType: fill.patternType }, children)]);
209
+ }
203
210
  }
204
- return require_xml_fragment.el("fill", {}, [require_xml_fragment.el("patternFill", { patternType: fill.patternType })]);
205
211
  });
206
212
  const borderElements = cellFormats.borderDeclarations().map((border) => {
207
213
  const edgeElements = [];
@@ -196,11 +196,17 @@ function buildStylesPart(cellFormats, dxfTable) {
196
196
  children.push(el("numFmts", { count: String(numFmtElements.length) }, numFmtElements));
197
197
  }
198
198
  const fillElements = cellFormats.fillDeclarations().map((fill) => {
199
- if (fill.patternType === "solid") {
200
- const rgb = fill.rgb ?? "000000";
201
- return el("fill", {}, [el("patternFill", { patternType: "solid" }, [el("fgColor", { rgb: `FF${rgb}` }), el("bgColor", { indexed: "64" })])]);
199
+ switch (fill.kind) {
200
+ case "none": return el("fill", {}, [el("patternFill", { patternType: "none" })]);
201
+ case "gray125": return el("fill", {}, [el("patternFill", { patternType: "gray125" })]);
202
+ case "solid": return el("fill", {}, [el("patternFill", { patternType: "solid" }, [el("fgColor", { rgb: `FF${fill.rgb}` }), el("bgColor", { indexed: "64" })])]);
203
+ case "pattern": {
204
+ const children = [];
205
+ if (fill.fgRgb !== void 0) children.push(el("fgColor", { rgb: `FF${fill.fgRgb}` }));
206
+ if (fill.bgRgb !== void 0) children.push(el("bgColor", { rgb: `FF${fill.bgRgb}` }));
207
+ return el("fill", {}, [el("patternFill", { patternType: fill.patternType }, children)]);
208
+ }
202
209
  }
203
- return el("fill", {}, [el("patternFill", { patternType: fill.patternType })]);
204
210
  });
205
211
  const borderElements = cellFormats.borderDeclarations().map((border) => {
206
212
  const edgeElements = [];
@@ -18,6 +18,29 @@ function readNumberFormatCodesById(styleSheet) {
18
18
  }
19
19
  return codes;
20
20
  }
21
+ const SPREADSHEETML_PATTERN_TYPES = /* @__PURE__ */ new Set([
22
+ "mediumGray",
23
+ "darkGray",
24
+ "lightGray",
25
+ "darkHorizontal",
26
+ "darkVertical",
27
+ "darkDown",
28
+ "darkUp",
29
+ "darkGrid",
30
+ "darkTrellis",
31
+ "lightHorizontal",
32
+ "lightVertical",
33
+ "lightDown",
34
+ "lightUp",
35
+ "lightGrid",
36
+ "lightTrellis",
37
+ "gray125",
38
+ "gray0625"
39
+ ]);
40
+ /** Whether `value` is one of ST_PatternType's own seventeen non-solid, non-none members -- the only ContentCellPatternType members a `<patternFill>` can ever name, so a value this returns true for can be used as a ContentCellPatternType directly with no further mapping. */
41
+ function isXlsxPatternType(value) {
42
+ return SPREADSHEETML_PATTERN_TYPES.has(value);
43
+ }
21
44
  const XLSX_BORDER_STYLE = {
22
45
  thin: {
23
46
  weight: "thin",
@@ -89,8 +112,24 @@ function readColorRgb(container, colorTag) {
89
112
  }
90
113
  function readFillBackground(fill) {
91
114
  const patternFill = require_typed_util.childrenWithTag(fill, "patternFill")[0];
92
- if (patternFill === void 0 || require_typed_util.attr(patternFill, "patternType") !== "solid") return;
93
- return readColorRgb(patternFill, "fgColor") ?? readColorRgb(patternFill, "bgColor");
115
+ if (patternFill === void 0) return;
116
+ const patternType = require_typed_util.attr(patternFill, "patternType");
117
+ if (patternType === "solid") {
118
+ const color = readColorRgb(patternFill, "fgColor") ?? readColorRgb(patternFill, "bgColor");
119
+ return color === void 0 ? void 0 : {
120
+ kind: "solid",
121
+ color
122
+ };
123
+ }
124
+ if (patternType === void 0 || !isXlsxPatternType(patternType)) return;
125
+ const foregroundColor = readColorRgb(patternFill, "fgColor");
126
+ const backgroundColor = readColorRgb(patternFill, "bgColor");
127
+ return {
128
+ kind: "pattern",
129
+ patternType,
130
+ ...foregroundColor !== void 0 ? { foregroundColor } : {},
131
+ ...backgroundColor !== void 0 ? { backgroundColor } : {}
132
+ };
94
133
  }
95
134
  function readFills(styleSheet) {
96
135
  const fillsEl = require_typed_util.childrenWithTag(styleSheet, "fills")[0];
@@ -199,9 +238,12 @@ function signatureOfNumberFormat(format) {
199
238
  return format.kind === "builtin" ? `builtin:${format.id}` : `custom:${format.code}`;
200
239
  }
201
240
  const EMPTY_DECORATION = {};
241
+ function fillSignature(fill) {
242
+ return fill.kind === "solid" ? `solid:${(0, document_schema_js.colorToRgbHex)(fill.color)}` : `pattern:${fill.patternType}:${fill.foregroundColor === void 0 ? "" : (0, document_schema_js.colorToRgbHex)(fill.foregroundColor)}:${fill.backgroundColor === void 0 ? "" : (0, document_schema_js.colorToRgbHex)(fill.backgroundColor)}`;
243
+ }
202
244
  function signatureOfDecoration(decoration) {
203
245
  let sig = "";
204
- if (decoration.background !== void 0) sig += `|bg:${(0, document_schema_js.colorToRgbHex)(decoration.background)}`;
246
+ if (decoration.background !== void 0) sig += `|bg:${fillSignature(decoration.background)}`;
205
247
  const borders = decoration.borders;
206
248
  if (borders !== void 0) for (const edge of [
207
249
  "left",
@@ -236,8 +278,8 @@ var CellFormatTable = class {
236
278
  borderId: EMPTY_BORDER_INDEX
237
279
  }];
238
280
  declared = [];
239
- fillIndexByRgb = /* @__PURE__ */ new Map();
240
- fills = [{ patternType: "none" }, { patternType: "gray125" }];
281
+ fillIndexBySignature = /* @__PURE__ */ new Map();
282
+ fills = [{ kind: "none" }, { kind: "gray125" }];
241
283
  borderIndexBySignature = /* @__PURE__ */ new Map();
242
284
  borders = [{ edges: {} }];
243
285
  intern(format, decoration = EMPTY_DECORATION) {
@@ -282,15 +324,31 @@ var CellFormatTable = class {
282
324
  return id;
283
325
  }
284
326
  internFill(background) {
285
- const rgb = (0, document_schema_js.colorToRgbHex)(background);
286
- const existing = this.fillIndexByRgb.get(rgb);
327
+ const signature = fillSignature(background);
328
+ const existing = this.fillIndexBySignature.get(signature);
287
329
  if (existing !== void 0) return existing;
330
+ let declared;
331
+ switch (background.kind) {
332
+ case "solid":
333
+ declared = {
334
+ kind: "solid",
335
+ rgb: (0, document_schema_js.colorToRgbHex)(background.color)
336
+ };
337
+ break;
338
+ case "pattern":
339
+ if (!isXlsxPatternType(background.patternType)) throw new Error(`ooxml.js cannot write a '${background.patternType}' cell fill: ECMA-376's own ST_PatternType vocabulary has no member for it, that pattern name belonging only to WordprocessingML's ST_Shd half of ContentCellPatternType's shared vocabulary`);
340
+ declared = {
341
+ kind: "pattern",
342
+ patternType: background.patternType,
343
+ ...background.foregroundColor === void 0 ? {} : { fgRgb: (0, document_schema_js.colorToRgbHex)(background.foregroundColor) },
344
+ ...background.backgroundColor === void 0 ? {} : { bgRgb: (0, document_schema_js.colorToRgbHex)(background.backgroundColor) }
345
+ };
346
+ break;
347
+ default: throw new Error(`ooxml.js cannot write a cell fill with kind '${(0, document_schema_js.unrecognizedFillKind)(background)}': ContentCellFillSchema's discriminated union only defines 'solid' and 'pattern'`);
348
+ }
288
349
  const index = this.fills.length;
289
- this.fills.push({
290
- patternType: "solid",
291
- rgb
292
- });
293
- this.fillIndexByRgb.set(rgb, index);
350
+ this.fills.push(declared);
351
+ this.fillIndexBySignature.set(signature, index);
294
352
  return index;
295
353
  }
296
354
  internBorder(borders) {