@json-to-office/core-docx 0.21.0 → 0.22.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.
@@ -1 +1 @@
1
- {"version":3,"file":"createDocumentGenerator.d.ts","sourceRoot":"","sources":["../../src/plugin/createDocumentGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAwB,MAAM,WAAW,CAAC;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAG9E,OAAO,KAAK,EAEV,wBAAwB,EAOxB,2BAA2B,EAC5B,MAAM,SAAS,CAAC;AAmBjB;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,kEAAkE;IAClE,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,kFAAkF;IAClF,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3C,4CAA4C;IAC5C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,oFAAoF;IACpF,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB;;;;OAIG;IACH,UAAU,CAAC,EAAE,2BAA2B,CAAC;IACzC,gFAAgF;IAChF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAknBD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,wBAAwB,CAAC,SAAS,EAAE,CAAC,CAgBvC"}
1
+ {"version":3,"file":"createDocumentGenerator.d.ts","sourceRoot":"","sources":["../../src/plugin/createDocumentGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAwB,MAAM,WAAW,CAAC;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAG9E,OAAO,KAAK,EAEV,wBAAwB,EAOxB,2BAA2B,EAC5B,MAAM,SAAS,CAAC;AAmBjB;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,kEAAkE;IAClE,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,kFAAkF;IAClF,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3C,4CAA4C;IAC5C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,oFAAoF;IACpF,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB;;;;OAIG;IACH,UAAU,CAAC,EAAE,2BAA2B,CAAC;IACzC,gFAAgF;IAChF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAwnBD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,wBAAwB,CAAC,SAAS,EAAE,CAAC,CAgBvC"}
@@ -362,12 +362,7 @@ var init_minimal_docx_theme = __esm({
362
362
  },
363
363
  componentDefaults: {
364
364
  table: {
365
- borders: false,
366
- striped: false,
367
- headerBackground: "#fafafa",
368
- headerColor: "#000000",
369
- borderColor: "#f0f0f0",
370
- borderWidth: 0.5
365
+ borderColor: "#f0f0f0"
371
366
  },
372
367
  list: {
373
368
  format: "bullet",
@@ -450,7 +445,12 @@ var init_corporate_docx_theme = __esm({
450
445
  keepNext: true,
451
446
  alignment: "left",
452
447
  borders: {
453
- bottom: { style: "single", size: 2, color: "primary", space: 6 }
448
+ bottom: {
449
+ style: "single",
450
+ size: 2,
451
+ color: "primary",
452
+ space: 6
453
+ }
454
454
  }
455
455
  },
456
456
  heading2: {
@@ -490,12 +490,7 @@ var init_corporate_docx_theme = __esm({
490
490
  },
491
491
  componentDefaults: {
492
492
  table: {
493
- borders: true,
494
- striped: true,
495
- headerBackground: "#1a365d",
496
- headerColor: "#FFFFFF",
497
- borderColor: "#E2E8F0",
498
- borderWidth: 0.5
493
+ borderColor: "#E2E8F0"
499
494
  },
500
495
  list: {
501
496
  format: "bullet",
@@ -612,12 +607,7 @@ var init_modern_docx_theme = __esm({
612
607
  },
613
608
  componentDefaults: {
614
609
  table: {
615
- borders: true,
616
- striped: false,
617
- headerBackground: "#6D28D9",
618
- headerColor: "#FFFFFF",
619
- borderColor: "#E2E8F0",
620
- borderWidth: 0.5
610
+ borderColor: "#E2E8F0"
621
611
  },
622
612
  list: {
623
613
  format: "bullet",
@@ -718,10 +708,13 @@ function resolveColor(colorValue, theme) {
718
708
  );
719
709
  }
720
710
  const colors = getThemeColors(theme);
721
- if (colorValue in colors) {
722
- const resolvedColor = colors[colorValue];
711
+ const resolvedColor = colors[colorValue];
712
+ if (typeof resolvedColor === "string") {
723
713
  return resolveColor(resolvedColor, theme);
724
714
  }
715
+ if (/^[0-9A-Fa-f]{6}$/.test(colorValue)) {
716
+ return colorValue.toUpperCase();
717
+ }
725
718
  throw new Error(
726
719
  `Invalid color value: "${colorValue}". Must be a hex color with # prefix (e.g., "#000000") or a valid theme color name.`
727
720
  );
@@ -1960,10 +1953,10 @@ var RESOLVER_MAP = {
1960
1953
  visual: resolveVisualProps
1961
1954
  };
1962
1955
  function resolveComponentDefaults(component, theme) {
1963
- if (!component.props) return component;
1956
+ const props = component.props ?? {};
1964
1957
  const resolver = RESOLVER_MAP[component.name];
1965
- const resolvedProps = resolver ? resolver(component.props, theme) : resolveCustomComponentProps(
1966
- component.props,
1958
+ const resolvedProps = resolver ? resolver(props, theme) : resolveCustomComponentProps(
1959
+ props,
1967
1960
  theme,
1968
1961
  component.name
1969
1962
  );
@@ -2027,8 +2020,11 @@ function createDocumentMetadata(props, generationDate = /* @__PURE__ */ new Date
2027
2020
  return {
2028
2021
  title: props.metadata?.title,
2029
2022
  subtitle: props.metadata?.subtitle,
2023
+ description: props.metadata?.description,
2030
2024
  author: props.metadata?.author,
2031
2025
  company: props.metadata?.company,
2026
+ version: props.metadata?.version,
2027
+ tags: props.metadata?.tags,
2032
2028
  date: props.metadata?.date ? new Date(props.metadata.date) : generationDate
2033
2029
  };
2034
2030
  }
@@ -4693,6 +4689,32 @@ async function createTable(columns, tableConfig, theme, themeName, _options = {}
4693
4689
  borderColor: "000000",
4694
4690
  borderSize: 1
4695
4691
  });
4692
+ const warnedCellColors = /* @__PURE__ */ new Set();
4693
+ const warnCellColor = (code, message) => {
4694
+ if (warnedCellColors.has(message)) return;
4695
+ warnedCellColors.add(message);
4696
+ console.warn(`[json-to-docx] ${code}: ${message}`);
4697
+ };
4698
+ const resolveCellColor = (value, prop) => {
4699
+ if (value === void 0 || value === "auto") return value;
4700
+ if (value === "transparent") {
4701
+ if (prop === "backgroundColor") return value;
4702
+ warnCellColor(
4703
+ "TABLE_CELL_COLOR_INVALID",
4704
+ `"transparent" is not a valid table cell "color"; ignoring it and using the table style color. It only applies to "backgroundColor".`
4705
+ );
4706
+ return void 0;
4707
+ }
4708
+ if (/^[0-9A-Fa-f]{6}$/.test(value)) return value.toUpperCase();
4709
+ try {
4710
+ return resolveColor(value, theme);
4711
+ } catch {
4712
+ const allowed = prop === "backgroundColor" ? '"auto", or "transparent" for no shading' : 'or "auto"';
4713
+ throw new Error(
4714
+ `Invalid table cell ${prop}: "${value}". Must be a hex color with # prefix (e.g. "#000000"), a theme color name, ${allowed}.`
4715
+ );
4716
+ }
4717
+ };
4696
4718
  const normalizeBorderColor = (border) => {
4697
4719
  if (border === void 0) return void 0;
4698
4720
  if (typeof border === "string") {
@@ -4829,8 +4851,14 @@ async function createTable(columns, tableConfig, theme, themeName, _options = {}
4829
4851
  tableDef?.padding
4830
4852
  );
4831
4853
  return {
4832
- color: cellDef?.color ?? columnDef?.color ?? tableDef?.color ?? defaults.color,
4833
- backgroundColor: cellDef?.backgroundColor ?? columnDef?.backgroundColor ?? tableDef?.backgroundColor ?? defaults.backgroundColor,
4854
+ color: resolveCellColor(
4855
+ cellDef?.color ?? columnDef?.color ?? tableDef?.color ?? defaults.color,
4856
+ "color"
4857
+ ),
4858
+ backgroundColor: resolveCellColor(
4859
+ cellDef?.backgroundColor ?? columnDef?.backgroundColor ?? tableDef?.backgroundColor ?? defaults.backgroundColor,
4860
+ "backgroundColor"
4861
+ ),
4834
4862
  horizontalAlignment: cellDef?.horizontalAlignment ?? columnDef?.horizontalAlignment ?? tableDef?.horizontalAlignment ?? defaults.horizontalAlignment,
4835
4863
  verticalAlignment: cellDef?.verticalAlignment ?? columnDef?.verticalAlignment ?? tableDef?.verticalAlignment ?? defaults.verticalAlignment,
4836
4864
  font: mergedFont,
@@ -4883,8 +4911,14 @@ async function createTable(columns, tableConfig, theme, themeName, _options = {}
4883
4911
  tableDef?.padding
4884
4912
  );
4885
4913
  return {
4886
- color: headerDef?.color ?? headerTableDef?.color ?? columnDef?.color ?? tableDef?.color ?? defaults.color,
4887
- backgroundColor: headerDef?.backgroundColor ?? headerTableDef?.backgroundColor ?? columnDef?.backgroundColor ?? tableDef?.backgroundColor ?? defaults.backgroundColor,
4914
+ color: resolveCellColor(
4915
+ headerDef?.color ?? headerTableDef?.color ?? columnDef?.color ?? tableDef?.color ?? defaults.color,
4916
+ "color"
4917
+ ),
4918
+ backgroundColor: resolveCellColor(
4919
+ headerDef?.backgroundColor ?? headerTableDef?.backgroundColor ?? columnDef?.backgroundColor ?? tableDef?.backgroundColor ?? defaults.backgroundColor,
4920
+ "backgroundColor"
4921
+ ),
4888
4922
  horizontalAlignment: headerDef?.horizontalAlignment ?? headerTableDef?.horizontalAlignment ?? columnDef?.horizontalAlignment ?? tableDef?.horizontalAlignment ?? defaults.horizontalAlignment,
4889
4923
  verticalAlignment: headerDef?.verticalAlignment ?? headerTableDef?.verticalAlignment ?? columnDef?.verticalAlignment ?? tableDef?.verticalAlignment ?? defaults.verticalAlignment,
4890
4924
  font: mergedFont,
@@ -5106,7 +5140,8 @@ async function createTable(columns, tableConfig, theme, themeName, _options = {}
5106
5140
  void 0
5107
5141
  );
5108
5142
  const headerRow = new TableRow({
5109
- tableHeader: tableConfig.repeatHeaderOnPageBreak,
5143
+ // Headers repeat across page breaks unless explicitly disabled
5144
+ tableHeader: tableConfig.repeatHeaderOnPageBreak ?? true,
5110
5145
  height: headerHeight !== void 0 ? { value: headerHeight * 20, rule: "atLeast" } : void 0,
5111
5146
  children: await Promise.all(
5112
5147
  columns.map(async (column, colIndex) => {
@@ -6437,6 +6472,11 @@ function renderTocComponent(component, theme, context) {
6437
6472
  pageNumbersStart = pageNumbersRange.from;
6438
6473
  pageNumbersEnd = pageNumbersRange.to;
6439
6474
  }
6475
+ if (componentProps.numberingStyle !== void 0) {
6476
+ console.warn(
6477
+ `TOC numberingStyle "${componentProps.numberingStyle}" is ignored: Word's table-of-contents field has no numbering switch. TOC entries inherit numbering from the heading styles they reference.`
6478
+ );
6479
+ }
6440
6480
  const includePageNumbers = componentProps.includePageNumbers !== false;
6441
6481
  const scope = componentProps.scope ?? "auto";
6442
6482
  const effectiveScope = scope === "auto" ? context?.section?.sectionBookmarkId ? "section" : "document" : scope;
@@ -6526,6 +6566,9 @@ function renderTocComponent(component, theme, context) {
6526
6566
  return paragraphs;
6527
6567
  }
6528
6568
 
6569
+ // src/components/highcharts.ts
6570
+ init_colorUtils();
6571
+
6529
6572
  // src/utils/environment.ts
6530
6573
  function isNodeEnvironment() {
6531
6574
  return typeof process !== "undefined" && process.versions != null && process.versions.node != null && typeof process.versions.node === "string";
@@ -6575,6 +6618,7 @@ async function postJsonToService(opts) {
6575
6618
  }
6576
6619
 
6577
6620
  // src/components/highcharts.ts
6621
+ import { DEFAULT_CHART_THEME_COLORS } from "@json-to-office/shared";
6578
6622
  var DEFAULT_EXPORT_SERVER_URL = "http://localhost:7801";
6579
6623
  async function generateChart(config, servicesConfig) {
6580
6624
  if (!isNodeEnvironment()) {
@@ -6615,14 +6659,24 @@ Cause: ${cause}`
6615
6659
  height
6616
6660
  };
6617
6661
  }
6662
+ function toChartColor(value, theme) {
6663
+ if (/^#?[0-9A-Fa-f]{6}$/.test(value)) {
6664
+ return value.startsWith("#") ? value : `#${value}`;
6665
+ }
6666
+ try {
6667
+ return `#${resolveColor(value, theme)}`;
6668
+ } catch {
6669
+ return void 0;
6670
+ }
6671
+ }
6618
6672
  function withThemeColors(config, theme) {
6619
6673
  const options = config.options;
6620
6674
  if (!options || options.colors || !theme?.colors) return config;
6621
- const palette = [
6622
- theme.colors.primary,
6623
- theme.colors.secondary,
6624
- theme.colors.accent
6625
- ].filter((c) => typeof c === "string" && c.length > 0).map((c) => c.startsWith("#") ? c : `#${c}`);
6675
+ const themeColors = theme.colors;
6676
+ const palette = DEFAULT_CHART_THEME_COLORS.map((token) => {
6677
+ const value = themeColors[token];
6678
+ return typeof value === "string" && value.length > 0 ? toChartColor(value, theme) : void 0;
6679
+ }).filter((c) => c !== void 0);
6626
6680
  if (palette.length === 0) return config;
6627
6681
  return {
6628
6682
  ...config,
@@ -6820,6 +6874,22 @@ function getAlignment3(alignment) {
6820
6874
  return AlignmentType5.LEFT;
6821
6875
  }
6822
6876
  }
6877
+ function coreProperties(metadata) {
6878
+ const { title, subtitle, description, author, company, version, tags } = metadata;
6879
+ const customProperties = [
6880
+ ...company ? [{ name: "Company", value: company }] : [],
6881
+ ...version ? [{ name: "Version", value: version }] : []
6882
+ ];
6883
+ return {
6884
+ ...title && { title },
6885
+ ...subtitle && { subject: subtitle },
6886
+ ...description && { description },
6887
+ // Word surfaces both names; author is the only person the document knows.
6888
+ ...author && { creator: author, lastModifiedBy: author },
6889
+ ...tags && tags.length > 0 && { keywords: tags.join(", ") },
6890
+ ...customProperties.length > 0 && { customProperties }
6891
+ };
6892
+ }
6823
6893
  async function renderDocument(structure, layout, options) {
6824
6894
  return runWithGenerationDate(
6825
6895
  structure.metadata.date,
@@ -6908,6 +6978,7 @@ async function renderDocumentScoped(structure, layout, options) {
6908
6978
  return new Document({
6909
6979
  styles: createWordStyles(structure.theme, structure.language),
6910
6980
  sections,
6981
+ ...coreProperties(structure.metadata),
6911
6982
  features: {
6912
6983
  updateFields: true,
6913
6984
  // Required for TOC fields to update correctly
@@ -7325,13 +7396,13 @@ function toDosTime(date) {
7325
7396
  function canonicalizeDocxBuffer(buffer, generatedAt = DEFAULT_GENERATION_DATE) {
7326
7397
  const zip = new AdmZip2(buffer);
7327
7398
  const isoTimestamp = generatedAt.toISOString();
7328
- const coreProperties = zip.getEntry("docProps/core.xml");
7329
- if (coreProperties) {
7330
- const normalized = coreProperties.getData().toString("utf8").replace(
7399
+ const coreProperties2 = zip.getEntry("docProps/core.xml");
7400
+ if (coreProperties2) {
7401
+ const normalized = coreProperties2.getData().toString("utf8").replace(
7331
7402
  /(<dcterms:(?:created|modified)\b[^>]*>)[^<]*(<\/dcterms:(?:created|modified)>)/g,
7332
7403
  `$1${isoTimestamp}$2`
7333
7404
  );
7334
- zip.updateFile(coreProperties, Buffer.from(normalized, "utf8"));
7405
+ zip.updateFile(coreProperties2, Buffer.from(normalized, "utf8"));
7335
7406
  }
7336
7407
  const zipTimestamp = toDosTime(generatedAt);
7337
7408
  for (const entry of zip.getEntries()) {
@@ -7530,7 +7601,8 @@ function createBuilderImpl(state) {
7530
7601
  async function generate(document, options) {
7531
7602
  try {
7532
7603
  const preserveSet = resolvePreserveSet(options);
7533
- const internalDocument = document;
7604
+ const rootIn = document;
7605
+ const internalDocument = rootIn.props === void 0 ? { ...rootIn, props: {} } : rootIn;
7534
7606
  const vOpts = {
7535
7607
  ...state.validation,
7536
7608
  ...options?.validation