@json-to-office/core-docx 0.22.0 → 0.24.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;AAwnBD;;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,EAAE,MAAM,WAAW,CAAC;AAG7C,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;AA8nBD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,wBAAwB,CAAC,SAAS,EAAE,CAAC,CAgBvC"}
@@ -628,10 +628,277 @@ var init_modern_docx_theme = __esm({
628
628
  }
629
629
  });
630
630
 
631
+ // src/templates/themes/apex.docx.theme.json
632
+ var apex_docx_theme_default;
633
+ var init_apex_docx_theme = __esm({
634
+ "src/templates/themes/apex.docx.theme.json"() {
635
+ apex_docx_theme_default = {
636
+ name: "apex",
637
+ displayName: "Apex Consulting",
638
+ description: "A premium consulting theme with deep navy, warm amber accents, and authoritative typography",
639
+ version: "2.0.0",
640
+ colors: {
641
+ primary: "#0C2340",
642
+ secondary: "#1B3A5C",
643
+ accent: "#D4A843",
644
+ text: "#1A1A2E",
645
+ background: "#FFFFFF",
646
+ border: "#D6DAE0",
647
+ textPrimary: "#1A1A2E",
648
+ textSecondary: "#4A5066",
649
+ textMuted: "#8B91A0",
650
+ borderPrimary: "#B8BCC6",
651
+ borderSecondary: "#E8EAF0",
652
+ backgroundPrimary: "#FFFFFF",
653
+ backgroundSecondary: "#F4F5F8"
654
+ },
655
+ fonts: {
656
+ heading: { family: "Georgia", size: 26 },
657
+ body: { family: "Calibri", size: 11 },
658
+ mono: { family: "Consolas", size: 10 },
659
+ light: { family: "Georgia", size: 26 }
660
+ },
661
+ page: {
662
+ size: "A4",
663
+ margins: {
664
+ top: 1440,
665
+ bottom: 1440,
666
+ left: 1200,
667
+ right: 1200,
668
+ header: 720,
669
+ footer: 720,
670
+ gutter: 0
671
+ }
672
+ },
673
+ styles: {
674
+ normal: {
675
+ font: "body",
676
+ color: "textPrimary",
677
+ lineSpacing: { type: "multiple", value: 1.4 },
678
+ alignment: "justify",
679
+ spacing: { after: 8 }
680
+ },
681
+ heading1: {
682
+ font: "heading",
683
+ size: 26,
684
+ bold: false,
685
+ color: "primary",
686
+ spacing: { before: 24, after: 12 },
687
+ keepNext: true,
688
+ alignment: "left",
689
+ borders: {
690
+ bottom: {
691
+ style: "single",
692
+ size: 2,
693
+ color: "accent",
694
+ space: 6
695
+ }
696
+ }
697
+ },
698
+ heading2: {
699
+ font: "heading",
700
+ size: 18,
701
+ bold: false,
702
+ color: "secondary",
703
+ spacing: { before: 18, after: 8 },
704
+ keepNext: true,
705
+ alignment: "left"
706
+ },
707
+ heading3: {
708
+ font: "body",
709
+ size: 13,
710
+ bold: true,
711
+ color: "accent",
712
+ spacing: { before: 12, after: 6 },
713
+ keepNext: true,
714
+ alignment: "left"
715
+ },
716
+ title: {
717
+ font: "light",
718
+ size: 36,
719
+ bold: false,
720
+ color: "primary",
721
+ alignment: "left",
722
+ spacing: { before: 0, after: 18 }
723
+ },
724
+ subtitle: {
725
+ font: "body",
726
+ size: 16,
727
+ italic: false,
728
+ color: "textSecondary",
729
+ alignment: "left",
730
+ spacing: { before: 0, after: 24 }
731
+ }
732
+ },
733
+ componentDefaults: {
734
+ table: {
735
+ borderColor: "#D6DAE0"
736
+ },
737
+ list: {
738
+ format: "bullet",
739
+ bullet: "\u2022",
740
+ indent: 3
741
+ },
742
+ image: {
743
+ alignment: "center"
744
+ },
745
+ statistic: {
746
+ alignment: "center"
747
+ },
748
+ section: {
749
+ pageBreak: false
750
+ },
751
+ heading: {
752
+ numbering: false
753
+ }
754
+ }
755
+ };
756
+ }
757
+ });
758
+
759
+ // src/templates/themes/devportal.docx.theme.json
760
+ var devportal_docx_theme_default;
761
+ var init_devportal_docx_theme = __esm({
762
+ "src/templates/themes/devportal.docx.theme.json"() {
763
+ devportal_docx_theme_default = {
764
+ name: "devportal",
765
+ displayName: "Developer Portal",
766
+ description: "A modern developer-focused theme with cool grays, teal accents, and monospace code styling",
767
+ version: "2.0.0",
768
+ colors: {
769
+ primary: "#0F172A",
770
+ secondary: "#334155",
771
+ accent: "#0D9488",
772
+ text: "#0F172A",
773
+ background: "#FFFFFF",
774
+ border: "#E2E8F0",
775
+ textPrimary: "#0F172A",
776
+ textSecondary: "#475569",
777
+ textMuted: "#94A3B8",
778
+ borderPrimary: "#CBD5E1",
779
+ borderSecondary: "#F1F5F9",
780
+ backgroundPrimary: "#FFFFFF",
781
+ backgroundSecondary: "#F8FAFC"
782
+ },
783
+ fonts: {
784
+ heading: { family: "Helvetica", size: 24 },
785
+ body: { family: "Calibri", size: 11 },
786
+ mono: { family: "Consolas", size: 10 },
787
+ light: { family: "Helvetica", size: 24 }
788
+ },
789
+ page: {
790
+ size: "A4",
791
+ margins: {
792
+ top: 1440,
793
+ bottom: 1440,
794
+ left: 1080,
795
+ right: 1080,
796
+ header: 720,
797
+ footer: 720,
798
+ gutter: 0
799
+ }
800
+ },
801
+ styles: {
802
+ normal: {
803
+ font: "body",
804
+ color: "textPrimary",
805
+ lineSpacing: { type: "multiple", value: 1.5 },
806
+ alignment: "left",
807
+ spacing: { after: 8 }
808
+ },
809
+ heading1: {
810
+ font: "heading",
811
+ size: 24,
812
+ bold: true,
813
+ color: "primary",
814
+ spacing: { before: 24, after: 12 },
815
+ keepNext: true,
816
+ alignment: "left",
817
+ borders: {
818
+ bottom: {
819
+ style: "single",
820
+ size: 1,
821
+ color: "accent",
822
+ space: 6
823
+ }
824
+ }
825
+ },
826
+ heading2: {
827
+ font: "heading",
828
+ size: 18,
829
+ bold: true,
830
+ color: "secondary",
831
+ spacing: { before: 18, after: 8 },
832
+ keepNext: true,
833
+ alignment: "left"
834
+ },
835
+ heading3: {
836
+ font: "body",
837
+ size: 13,
838
+ bold: true,
839
+ color: "accent",
840
+ spacing: { before: 12, after: 6 },
841
+ keepNext: true,
842
+ alignment: "left"
843
+ },
844
+ heading4: {
845
+ font: "body",
846
+ size: 12,
847
+ bold: true,
848
+ color: "textSecondary",
849
+ spacing: { before: 8, after: 4 },
850
+ keepNext: true
851
+ },
852
+ title: {
853
+ font: "heading",
854
+ size: 32,
855
+ bold: true,
856
+ color: "primary",
857
+ alignment: "left",
858
+ spacing: { before: 0, after: 12 }
859
+ },
860
+ subtitle: {
861
+ font: "light",
862
+ size: 16,
863
+ italic: false,
864
+ color: "textSecondary",
865
+ alignment: "left",
866
+ spacing: { before: 0, after: 24 }
867
+ }
868
+ },
869
+ componentDefaults: {
870
+ table: {
871
+ borderColor: "#E2E8F0"
872
+ },
873
+ list: {
874
+ format: "bullet",
875
+ bullet: "\u2013",
876
+ indent: 3
877
+ },
878
+ image: {
879
+ alignment: "center"
880
+ },
881
+ statistic: {
882
+ alignment: "center"
883
+ },
884
+ section: {
885
+ pageBreak: false
886
+ },
887
+ heading: {
888
+ numbering: false
889
+ }
890
+ }
891
+ };
892
+ }
893
+ });
894
+
631
895
  // src/templates/themes/index.ts
632
896
  import fs from "fs";
633
897
  import path from "path";
634
898
  import { fileURLToPath } from "url";
899
+ import {
900
+ isValidThemeConfig
901
+ } from "@json-to-office/shared-docx";
635
902
  function loadThemesFromJson() {
636
903
  if (_themesCache) {
637
904
  return _themesCache;
@@ -639,7 +906,9 @@ function loadThemesFromJson() {
639
906
  const themes2 = {
640
907
  minimal: ensureThemeDefaults(minimal_docx_theme_default),
641
908
  corporate: ensureThemeDefaults(corporate_docx_theme_default),
642
- modern: ensureThemeDefaults(modern_docx_theme_default)
909
+ modern: ensureThemeDefaults(modern_docx_theme_default),
910
+ apex: ensureThemeDefaults(apex_docx_theme_default),
911
+ devportal: ensureThemeDefaults(devportal_docx_theme_default)
643
912
  };
644
913
  try {
645
914
  const __filename2 = fileURLToPath(import.meta.url);
@@ -650,9 +919,18 @@ function loadThemesFromJson() {
650
919
  for (const themeName of themeFiles) {
651
920
  if (!themes2[themeName]) {
652
921
  try {
653
- const filePath = path.join(themesDir, `${themeName}.docx.theme.json`);
922
+ const filePath = path.join(
923
+ themesDir,
924
+ `${themeName}.docx.theme.json`
925
+ );
654
926
  const content = fs.readFileSync(filePath, "utf8");
655
927
  const parsedTheme = JSON.parse(content);
928
+ if (!isValidThemeConfig(parsedTheme)) {
929
+ console.warn(
930
+ `Skipping theme ${themeName}: does not match the theme schema.`
931
+ );
932
+ continue;
933
+ }
656
934
  themes2[themeName] = ensureThemeDefaults(parsedTheme);
657
935
  } catch (error) {
658
936
  console.warn(
@@ -668,7 +946,7 @@ function loadThemesFromJson() {
668
946
  _themesCache = themes2;
669
947
  return themes2;
670
948
  }
671
- var _themesCache, themes, getTheme, getThemeWithFallback, minimalTheme, corporateTheme, modernTheme;
949
+ var _themesCache, themes, getTheme, getThemeWithFallback, hasTheme, getThemeNames, minimalTheme, corporateTheme, modernTheme;
672
950
  var init_themes = __esm({
673
951
  "src/templates/themes/index.ts"() {
674
952
  "use strict";
@@ -676,6 +954,8 @@ var init_themes = __esm({
676
954
  init_minimal_docx_theme();
677
955
  init_corporate_docx_theme();
678
956
  init_modern_docx_theme();
957
+ init_apex_docx_theme();
958
+ init_devportal_docx_theme();
679
959
  _themesCache = null;
680
960
  themes = loadThemesFromJson();
681
961
  getTheme = (themeName) => {
@@ -690,6 +970,12 @@ var init_themes = __esm({
690
970
  }
691
971
  return theme;
692
972
  };
973
+ hasTheme = (themeName) => {
974
+ return themeName in themes;
975
+ };
976
+ getThemeNames = () => {
977
+ return Object.keys(themes);
978
+ };
693
979
  minimalTheme = themes["minimal"];
694
980
  corporateTheme = themes["corporate"];
695
981
  modernTheme = themes["modern"];
@@ -1301,7 +1587,8 @@ var init_loader = __esm({
1301
1587
  // src/themes/json/index.ts
1302
1588
  import {
1303
1589
  ThemeConfigSchema,
1304
- isValidThemeConfig
1590
+ isValidThemeConfig as isValidThemeConfig2,
1591
+ createMinimalTheme
1305
1592
  } from "@json-to-office/shared-docx";
1306
1593
  var themeParser, themeLoader;
1307
1594
  var init_json = __esm({
@@ -1609,8 +1896,25 @@ var init_docxImagePositioning = __esm({
1609
1896
  // src/plugin/example/index.ts
1610
1897
  import { Packer as Packer2 } from "docx";
1611
1898
 
1899
+ // src/styles/theme-resolver.ts
1900
+ init_themes();
1901
+ function resolveBuiltInTheme(themeName, options = {}) {
1902
+ if (!hasTheme(themeName)) {
1903
+ const available = [
1904
+ ...getThemeNames(),
1905
+ ...Object.keys(options.customThemes ?? {})
1906
+ ].sort();
1907
+ options.warnings?.push({
1908
+ component: "theme",
1909
+ message: `Theme "${themeName}" not found; falling back to "minimal". Available themes: ${available.join(", ")}.`,
1910
+ severity: "warning",
1911
+ context: { code: "theme_not_found", requested: themeName, available }
1912
+ });
1913
+ }
1914
+ return getThemeWithFallback(themeName);
1915
+ }
1916
+
1612
1917
  // src/plugin/createDocumentGenerator.ts
1613
- init_styles();
1614
1918
  import { applyExportMode, scopedThemeName } from "@json-to-office/shared";
1615
1919
 
1616
1920
  // src/core/fontResolution.ts
@@ -7422,7 +7726,7 @@ async function packageDocument(document, options) {
7422
7726
  // src/plugin/createDocumentGenerator.ts
7423
7727
  function createBuilderImpl(state) {
7424
7728
  const componentMap = new Map(state.components.map((c) => [c.name, c]));
7425
- function resolveDocumentTheme(themeName) {
7729
+ function resolveDocumentTheme(themeName, warnings) {
7426
7730
  if (state.customThemes) {
7427
7731
  if (state.customThemes[themeName]) {
7428
7732
  return state.customThemes[themeName];
@@ -7437,7 +7741,10 @@ function createBuilderImpl(state) {
7437
7741
  if (state.theme) {
7438
7742
  return state.theme;
7439
7743
  }
7440
- return getThemeWithFallback(themeName);
7744
+ return resolveBuiltInTheme(themeName, {
7745
+ customThemes: state.customThemes,
7746
+ warnings
7747
+ });
7441
7748
  }
7442
7749
  async function processDocumentComponents(components, preserveSet, warningsCollector, resolvedTheme, validateEmitted, depth = 0) {
7443
7750
  if (depth > 20) {
@@ -7639,9 +7946,9 @@ function createBuilderImpl(state) {
7639
7946
  );
7640
7947
  }
7641
7948
  };
7642
- const baseThemeName = internalDocument.props.theme || "minimal";
7643
- const docTheme = resolveDocumentTheme(baseThemeName);
7644
7949
  const warnings = [];
7950
+ const baseThemeName = internalDocument.props.theme || "minimal";
7951
+ const docTheme = resolveDocumentTheme(baseThemeName, warnings);
7645
7952
  const mode = applyExportMode({
7646
7953
  doc: internalDocument,
7647
7954
  theme: docTheme,