@json-to-office/core-docx 0.20.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.
- package/dist/components/highcharts.d.ts.map +1 -1
- package/dist/components/section.d.ts.map +1 -1
- package/dist/components/toc/index.d.ts.map +1 -1
- package/dist/core/cached-render.d.ts.map +1 -1
- package/dist/core/content.d.ts.map +1 -1
- package/dist/core/generator.d.ts +6 -2
- package/dist/core/generator.d.ts.map +1 -1
- package/dist/core/render.d.ts +8 -6
- package/dist/core/render.d.ts.map +1 -1
- package/dist/core/structure.d.ts +5 -2
- package/dist/core/structure.d.ts.map +1 -1
- package/dist/index.js +508 -381
- package/dist/index.js.map +1 -1
- package/dist/plugin/createDocumentGenerator.d.ts +4 -0
- package/dist/plugin/createDocumentGenerator.d.ts.map +1 -1
- package/dist/plugin/example/index.js +486 -321
- package/dist/plugin/example/index.js.map +1 -1
- package/dist/plugin/types.d.ts +4 -0
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/styles/utils/colorUtils.d.ts +4 -3
- package/dist/styles/utils/colorUtils.d.ts.map +1 -1
- package/dist/styles/utils/resolveComponentTree.d.ts +3 -0
- package/dist/styles/utils/resolveComponentTree.d.ts.map +1 -1
- package/dist/templates/themes/apex.docx.theme.json +1 -6
- package/dist/templates/themes/corporate.docx.theme.json +7 -7
- package/dist/templates/themes/devportal.docx.theme.json +1 -6
- package/dist/templates/themes/index.d.ts +12 -0
- package/dist/templates/themes/index.d.ts.map +1 -1
- package/dist/templates/themes/minimal.docx.theme.json +1 -6
- package/dist/templates/themes/modern.docx.theme.json +1 -6
- package/dist/themes/defaults.d.ts +3 -0
- package/dist/themes/defaults.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/bookmarkRegistry.d.ts +5 -2
- package/dist/utils/bookmarkRegistry.d.ts.map +1 -1
- package/dist/utils/fixFloatingImageIds.d.ts +3 -0
- package/dist/utils/fixFloatingImageIds.d.ts.map +1 -1
- package/dist/utils/generationContext.d.ts +5 -0
- package/dist/utils/generationContext.d.ts.map +1 -0
- package/dist/utils/numberingConfig.d.ts +5 -2
- package/dist/utils/numberingConfig.d.ts.map +1 -1
- package/dist/utils/packageDocument.d.ts +20 -0
- package/dist/utils/packageDocument.d.ts.map +1 -0
- package/dist/utils/placeholderProcessor.d.ts +5 -5
- package/dist/utils/placeholderProcessor.d.ts.map +1 -1
- package/dist/utils/revisionUtils.d.ts +5 -5
- package/dist/utils/revisionUtils.d.ts.map +1 -1
- package/dist/utils/textParser.d.ts +3 -3
- package/dist/utils/textParser.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -368,12 +368,7 @@ var init_minimal_docx_theme = __esm({
|
|
|
368
368
|
},
|
|
369
369
|
componentDefaults: {
|
|
370
370
|
table: {
|
|
371
|
-
|
|
372
|
-
striped: false,
|
|
373
|
-
headerBackground: "#fafafa",
|
|
374
|
-
headerColor: "#000000",
|
|
375
|
-
borderColor: "#f0f0f0",
|
|
376
|
-
borderWidth: 0.5
|
|
371
|
+
borderColor: "#f0f0f0"
|
|
377
372
|
},
|
|
378
373
|
list: {
|
|
379
374
|
format: "bullet",
|
|
@@ -456,7 +451,12 @@ var init_corporate_docx_theme = __esm({
|
|
|
456
451
|
keepNext: true,
|
|
457
452
|
alignment: "left",
|
|
458
453
|
borders: {
|
|
459
|
-
bottom: {
|
|
454
|
+
bottom: {
|
|
455
|
+
style: "single",
|
|
456
|
+
size: 2,
|
|
457
|
+
color: "primary",
|
|
458
|
+
space: 6
|
|
459
|
+
}
|
|
460
460
|
}
|
|
461
461
|
},
|
|
462
462
|
heading2: {
|
|
@@ -496,12 +496,7 @@ var init_corporate_docx_theme = __esm({
|
|
|
496
496
|
},
|
|
497
497
|
componentDefaults: {
|
|
498
498
|
table: {
|
|
499
|
-
|
|
500
|
-
striped: true,
|
|
501
|
-
headerBackground: "#1a365d",
|
|
502
|
-
headerColor: "#FFFFFF",
|
|
503
|
-
borderColor: "#E2E8F0",
|
|
504
|
-
borderWidth: 0.5
|
|
499
|
+
borderColor: "#E2E8F0"
|
|
505
500
|
},
|
|
506
501
|
list: {
|
|
507
502
|
format: "bullet",
|
|
@@ -618,12 +613,7 @@ var init_modern_docx_theme = __esm({
|
|
|
618
613
|
},
|
|
619
614
|
componentDefaults: {
|
|
620
615
|
table: {
|
|
621
|
-
|
|
622
|
-
striped: false,
|
|
623
|
-
headerBackground: "#6D28D9",
|
|
624
|
-
headerColor: "#FFFFFF",
|
|
625
|
-
borderColor: "#E2E8F0",
|
|
626
|
-
borderWidth: 0.5
|
|
616
|
+
borderColor: "#E2E8F0"
|
|
627
617
|
},
|
|
628
618
|
list: {
|
|
629
619
|
format: "bullet",
|
|
@@ -724,10 +714,13 @@ function resolveColor(colorValue, theme) {
|
|
|
724
714
|
);
|
|
725
715
|
}
|
|
726
716
|
const colors = getThemeColors(theme);
|
|
727
|
-
|
|
728
|
-
|
|
717
|
+
const resolvedColor = colors[colorValue];
|
|
718
|
+
if (typeof resolvedColor === "string") {
|
|
729
719
|
return resolveColor(resolvedColor, theme);
|
|
730
720
|
}
|
|
721
|
+
if (/^[0-9A-Fa-f]{6}$/.test(colorValue)) {
|
|
722
|
+
return colorValue.toUpperCase();
|
|
723
|
+
}
|
|
731
724
|
throw new Error(
|
|
732
725
|
`Invalid color value: "${colorValue}". Must be a hex color with # prefix (e.g., "#000000") or a valid theme color name.`
|
|
733
726
|
);
|
|
@@ -1692,253 +1685,7 @@ var init_docxImagePositioning = __esm({
|
|
|
1692
1685
|
}
|
|
1693
1686
|
});
|
|
1694
1687
|
|
|
1695
|
-
// src/utils/numberingConfig.ts
|
|
1696
|
-
var numberingConfig_exports = {};
|
|
1697
|
-
__export(numberingConfig_exports, {
|
|
1698
|
-
NumberingRegistry: () => NumberingRegistry,
|
|
1699
|
-
createBulletListConfig: () => createBulletListConfig,
|
|
1700
|
-
createNumberedListConfig: () => createNumberedListConfig,
|
|
1701
|
-
createNumberingConfig: () => createNumberingConfig,
|
|
1702
|
-
globalNumberingRegistry: () => globalNumberingRegistry
|
|
1703
|
-
});
|
|
1704
|
-
import { AlignmentType as AlignmentType3, convertInchesToTwip, LevelFormat } from "docx";
|
|
1705
|
-
function getLevelFormat(format2) {
|
|
1706
|
-
if (!format2) return LevelFormat.BULLET;
|
|
1707
|
-
return LEVEL_FORMAT_MAP[format2] || LevelFormat.BULLET;
|
|
1708
|
-
}
|
|
1709
|
-
function getAlignment2(alignment) {
|
|
1710
|
-
if (!alignment) return AlignmentType3.LEFT;
|
|
1711
|
-
return ALIGNMENT_MAP[alignment] || AlignmentType3.LEFT;
|
|
1712
|
-
}
|
|
1713
|
-
function createDefaultLevel(level, format2 = LevelFormat.BULLET, text) {
|
|
1714
|
-
const baseIndent = 0.5 * (level + 1);
|
|
1715
|
-
const hangingIndent = 0.25;
|
|
1716
|
-
return {
|
|
1717
|
-
level,
|
|
1718
|
-
format: format2,
|
|
1719
|
-
text: text || (format2 === LevelFormat.BULLET ? "\u2022" : "%1."),
|
|
1720
|
-
alignment: AlignmentType3.LEFT,
|
|
1721
|
-
style: {
|
|
1722
|
-
paragraph: {
|
|
1723
|
-
indent: {
|
|
1724
|
-
left: convertInchesToTwip(baseIndent),
|
|
1725
|
-
hanging: convertInchesToTwip(hangingIndent)
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
};
|
|
1730
|
-
}
|
|
1731
|
-
function createNumberingConfig(config) {
|
|
1732
|
-
const levels = [];
|
|
1733
|
-
for (const levelConfig of config.levels) {
|
|
1734
|
-
const format2 = getLevelFormat(levelConfig.format);
|
|
1735
|
-
const alignment = getAlignment2(levelConfig.alignment);
|
|
1736
|
-
const text = levelConfig.text || (format2 === LevelFormat.BULLET ? "\u2022" : `%${levelConfig.level + 1}.`);
|
|
1737
|
-
const baseIndent = levelConfig.indent?.left !== void 0 ? levelConfig.indent.left / 72 : 0.5 * (levelConfig.level + 1);
|
|
1738
|
-
const hangingIndent = levelConfig.indent?.hanging !== void 0 ? levelConfig.indent.hanging / 72 : 0.25;
|
|
1739
|
-
const level = {
|
|
1740
|
-
level: levelConfig.level,
|
|
1741
|
-
format: format2,
|
|
1742
|
-
text,
|
|
1743
|
-
alignment,
|
|
1744
|
-
style: {
|
|
1745
|
-
paragraph: {
|
|
1746
|
-
indent: {
|
|
1747
|
-
left: convertInchesToTwip(baseIndent),
|
|
1748
|
-
hanging: convertInchesToTwip(hangingIndent)
|
|
1749
|
-
}
|
|
1750
|
-
}
|
|
1751
|
-
},
|
|
1752
|
-
// Add start number if specified
|
|
1753
|
-
...levelConfig.start !== void 0 && { start: levelConfig.start }
|
|
1754
|
-
};
|
|
1755
|
-
levels.push(level);
|
|
1756
|
-
}
|
|
1757
|
-
return {
|
|
1758
|
-
reference: config.reference,
|
|
1759
|
-
levels
|
|
1760
|
-
};
|
|
1761
|
-
}
|
|
1762
|
-
function createBulletListConfig(reference, bullet = "\u2022") {
|
|
1763
|
-
return {
|
|
1764
|
-
reference,
|
|
1765
|
-
levels: [
|
|
1766
|
-
createDefaultLevel(0, LevelFormat.BULLET, bullet),
|
|
1767
|
-
createDefaultLevel(1, LevelFormat.BULLET, "\u25E6"),
|
|
1768
|
-
createDefaultLevel(2, LevelFormat.BULLET, "\u25AA")
|
|
1769
|
-
]
|
|
1770
|
-
};
|
|
1771
|
-
}
|
|
1772
|
-
function createNumberedListConfig(reference, start = 1) {
|
|
1773
|
-
return {
|
|
1774
|
-
reference,
|
|
1775
|
-
levels: [
|
|
1776
|
-
{ ...createDefaultLevel(0, LevelFormat.DECIMAL, "%1."), start },
|
|
1777
|
-
createDefaultLevel(1, LevelFormat.LOWER_LETTER, "%2."),
|
|
1778
|
-
createDefaultLevel(2, LevelFormat.LOWER_ROMAN, "%3.")
|
|
1779
|
-
]
|
|
1780
|
-
};
|
|
1781
|
-
}
|
|
1782
|
-
var LEVEL_FORMAT_MAP, ALIGNMENT_MAP, NumberingRegistry, globalNumberingRegistry;
|
|
1783
|
-
var init_numberingConfig = __esm({
|
|
1784
|
-
"src/utils/numberingConfig.ts"() {
|
|
1785
|
-
"use strict";
|
|
1786
|
-
LEVEL_FORMAT_MAP = {
|
|
1787
|
-
decimal: LevelFormat.DECIMAL,
|
|
1788
|
-
upperRoman: LevelFormat.UPPER_ROMAN,
|
|
1789
|
-
lowerRoman: LevelFormat.LOWER_ROMAN,
|
|
1790
|
-
upperLetter: LevelFormat.UPPER_LETTER,
|
|
1791
|
-
lowerLetter: LevelFormat.LOWER_LETTER,
|
|
1792
|
-
bullet: LevelFormat.BULLET,
|
|
1793
|
-
ordinal: LevelFormat.ORDINAL,
|
|
1794
|
-
cardinalText: LevelFormat.CARDINAL_TEXT,
|
|
1795
|
-
ordinalText: LevelFormat.ORDINAL_TEXT,
|
|
1796
|
-
hex: LevelFormat.HEX,
|
|
1797
|
-
chicago: LevelFormat.CHICAGO,
|
|
1798
|
-
ideographDigital: LevelFormat.IDEOGRAPH__DIGITAL,
|
|
1799
|
-
japaneseCounting: LevelFormat.JAPANESE_COUNTING,
|
|
1800
|
-
aiueo: LevelFormat.AIUEO,
|
|
1801
|
-
iroha: LevelFormat.IROHA,
|
|
1802
|
-
decimalFullWidth: LevelFormat.DECIMAL_FULL_WIDTH,
|
|
1803
|
-
decimalHalfWidth: LevelFormat.DECIMAL_HALF_WIDTH,
|
|
1804
|
-
japaneseLegal: LevelFormat.JAPANESE_LEGAL,
|
|
1805
|
-
japaneseDigitalTenThousand: LevelFormat.JAPANESE_DIGITAL_TEN_THOUSAND,
|
|
1806
|
-
decimalEnclosedCircle: LevelFormat.DECIMAL_ENCLOSED_CIRCLE,
|
|
1807
|
-
decimalFullWidth2: LevelFormat.DECIMAL_FULL_WIDTH2,
|
|
1808
|
-
aiueoFullWidth: LevelFormat.AIUEO_FULL_WIDTH,
|
|
1809
|
-
irohaFullWidth: LevelFormat.IROHA_FULL_WIDTH,
|
|
1810
|
-
decimalZero: LevelFormat.DECIMAL_ZERO,
|
|
1811
|
-
ganada: LevelFormat.GANADA,
|
|
1812
|
-
chosung: LevelFormat.CHOSUNG,
|
|
1813
|
-
decimalEnclosedFullstop: LevelFormat.DECIMAL_ENCLOSED_FULLSTOP,
|
|
1814
|
-
decimalEnclosedParen: LevelFormat.DECIMAL_ENCLOSED_PARENTHESES,
|
|
1815
|
-
decimalEnclosedCircleChinese: LevelFormat.DECIMAL_ENCLOSED_CIRCLE_CHINESE,
|
|
1816
|
-
ideographEnclosedCircle: LevelFormat.IDEOGRAPH_ENCLOSED_CIRCLE,
|
|
1817
|
-
ideographTraditional: LevelFormat.IDEOGRAPH_TRADITIONAL,
|
|
1818
|
-
ideographZodiac: LevelFormat.IDEOGRAPH_ZODIAC,
|
|
1819
|
-
ideographZodiacTraditional: LevelFormat.IDEOGRAPH_ZODIAC_TRADITIONAL,
|
|
1820
|
-
taiwaneseCounting: LevelFormat.TAIWANESE_COUNTING,
|
|
1821
|
-
ideographLegalTraditional: LevelFormat.IDEOGRAPH_LEGAL_TRADITIONAL,
|
|
1822
|
-
taiwaneseCountingThousand: LevelFormat.TAIWANESE_COUNTING_THOUSAND,
|
|
1823
|
-
taiwaneseDigital: LevelFormat.TAIWANESE_DIGITAL,
|
|
1824
|
-
chineseCounting: LevelFormat.CHINESE_COUNTING,
|
|
1825
|
-
chineseLegalSimplified: LevelFormat.CHINESE_LEGAL_SIMPLIFIED,
|
|
1826
|
-
chineseCountingThousand: LevelFormat.CHINESE_COUNTING_THOUSAND,
|
|
1827
|
-
koreanDigital: LevelFormat.KOREAN_DIGITAL,
|
|
1828
|
-
koreanCounting: LevelFormat.KOREAN_COUNTING,
|
|
1829
|
-
koreanLegal: LevelFormat.KOREAN_LEGAL,
|
|
1830
|
-
koreanDigital2: LevelFormat.KOREAN_DIGITAL2,
|
|
1831
|
-
vietnameseCounting: LevelFormat.VIETNAMESE_COUNTING,
|
|
1832
|
-
russianLower: LevelFormat.RUSSIAN_LOWER,
|
|
1833
|
-
russianUpper: LevelFormat.RUSSIAN_UPPER,
|
|
1834
|
-
none: LevelFormat.NONE,
|
|
1835
|
-
numberInDash: LevelFormat.NUMBER_IN_DASH,
|
|
1836
|
-
hebrew1: LevelFormat.HEBREW1,
|
|
1837
|
-
hebrew2: LevelFormat.HEBREW2,
|
|
1838
|
-
arabicAlpha: LevelFormat.ARABIC_ALPHA,
|
|
1839
|
-
arabicAbjad: LevelFormat.ARABIC_ABJAD,
|
|
1840
|
-
hindiVowels: LevelFormat.HINDI_VOWELS,
|
|
1841
|
-
hindiConsonants: LevelFormat.HINDI_CONSONANTS,
|
|
1842
|
-
hindiNumbers: LevelFormat.HINDI_NUMBERS,
|
|
1843
|
-
hindiCounting: LevelFormat.HINDI_COUNTING,
|
|
1844
|
-
thaiLetters: LevelFormat.THAI_LETTERS,
|
|
1845
|
-
thaiNumbers: LevelFormat.THAI_NUMBERS,
|
|
1846
|
-
thaiCounting: LevelFormat.THAI_COUNTING
|
|
1847
|
-
};
|
|
1848
|
-
ALIGNMENT_MAP = {
|
|
1849
|
-
start: AlignmentType3.START,
|
|
1850
|
-
end: AlignmentType3.END,
|
|
1851
|
-
left: AlignmentType3.LEFT,
|
|
1852
|
-
right: AlignmentType3.RIGHT,
|
|
1853
|
-
center: AlignmentType3.CENTER
|
|
1854
|
-
};
|
|
1855
|
-
NumberingRegistry = class {
|
|
1856
|
-
configs = /* @__PURE__ */ new Map();
|
|
1857
|
-
counter = 0;
|
|
1858
|
-
/**
|
|
1859
|
-
* Register a numbering configuration
|
|
1860
|
-
*/
|
|
1861
|
-
register(config) {
|
|
1862
|
-
const reference = config.reference;
|
|
1863
|
-
this.configs.set(reference, config);
|
|
1864
|
-
return reference;
|
|
1865
|
-
}
|
|
1866
|
-
/**
|
|
1867
|
-
* Generate a unique reference ID
|
|
1868
|
-
*/
|
|
1869
|
-
generateReference(prefix = "list") {
|
|
1870
|
-
return `${prefix}-${++this.counter}`;
|
|
1871
|
-
}
|
|
1872
|
-
/**
|
|
1873
|
-
* Get all registered configurations as an array suitable for INumberingOptions
|
|
1874
|
-
*/
|
|
1875
|
-
getAll() {
|
|
1876
|
-
return Array.from(this.configs.values());
|
|
1877
|
-
}
|
|
1878
|
-
/**
|
|
1879
|
-
* Clear all configurations
|
|
1880
|
-
*/
|
|
1881
|
-
clear() {
|
|
1882
|
-
this.configs.clear();
|
|
1883
|
-
this.counter = 0;
|
|
1884
|
-
}
|
|
1885
|
-
/**
|
|
1886
|
-
* Check if a reference exists
|
|
1887
|
-
*/
|
|
1888
|
-
has(reference) {
|
|
1889
|
-
return this.configs.has(reference);
|
|
1890
|
-
}
|
|
1891
|
-
/**
|
|
1892
|
-
* Get a configuration by reference
|
|
1893
|
-
*/
|
|
1894
|
-
get(reference) {
|
|
1895
|
-
return this.configs.get(reference);
|
|
1896
|
-
}
|
|
1897
|
-
};
|
|
1898
|
-
globalNumberingRegistry = new NumberingRegistry();
|
|
1899
|
-
}
|
|
1900
|
-
});
|
|
1901
|
-
|
|
1902
|
-
// src/utils/fixFloatingImageIds.ts
|
|
1903
|
-
var fixFloatingImageIds_exports = {};
|
|
1904
|
-
__export(fixFloatingImageIds_exports, {
|
|
1905
|
-
fixFloatingImageIds: () => fixFloatingImageIds
|
|
1906
|
-
});
|
|
1907
|
-
import AdmZip from "adm-zip";
|
|
1908
|
-
async function fixFloatingImageIds(docxPath) {
|
|
1909
|
-
try {
|
|
1910
|
-
const zip = new AdmZip(docxPath);
|
|
1911
|
-
const documentEntry = zip.getEntry("word/document.xml");
|
|
1912
|
-
if (!documentEntry) {
|
|
1913
|
-
throw new Error("document.xml not found in DOCX");
|
|
1914
|
-
}
|
|
1915
|
-
let documentXml = documentEntry.getData().toString("utf8");
|
|
1916
|
-
let idCounter = 1;
|
|
1917
|
-
documentXml = documentXml.replace(
|
|
1918
|
-
/<wp:docPr\s+id="(\d+)"/g,
|
|
1919
|
-
(_match) => {
|
|
1920
|
-
const newId = idCounter++;
|
|
1921
|
-
return `<wp:docPr id="${newId}"`;
|
|
1922
|
-
}
|
|
1923
|
-
);
|
|
1924
|
-
zip.updateFile("word/document.xml", Buffer.from(documentXml, "utf8"));
|
|
1925
|
-
zip.writeZip(docxPath);
|
|
1926
|
-
console.log(
|
|
1927
|
-
`Fixed ${idCounter - 1} duplicate floating image docPr IDs in ${docxPath}`
|
|
1928
|
-
);
|
|
1929
|
-
} catch (error) {
|
|
1930
|
-
console.error("Failed to fix floating image issues:", error);
|
|
1931
|
-
throw error;
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
var init_fixFloatingImageIds = __esm({
|
|
1935
|
-
"src/utils/fixFloatingImageIds.ts"() {
|
|
1936
|
-
"use strict";
|
|
1937
|
-
}
|
|
1938
|
-
});
|
|
1939
|
-
|
|
1940
1688
|
// src/core/generator.ts
|
|
1941
|
-
import { Packer } from "docx";
|
|
1942
1689
|
import { writeFileSync } from "fs";
|
|
1943
1690
|
|
|
1944
1691
|
// src/types/index.ts
|
|
@@ -2087,10 +1834,10 @@ var RESOLVER_MAP = {
|
|
|
2087
1834
|
visual: resolveVisualProps
|
|
2088
1835
|
};
|
|
2089
1836
|
function resolveComponentDefaults(component, theme) {
|
|
2090
|
-
|
|
1837
|
+
const props = component.props ?? {};
|
|
2091
1838
|
const resolver = RESOLVER_MAP[component.name];
|
|
2092
|
-
const resolvedProps = resolver ? resolver(
|
|
2093
|
-
|
|
1839
|
+
const resolvedProps = resolver ? resolver(props, theme) : resolveCustomComponentProps(
|
|
1840
|
+
props,
|
|
2094
1841
|
theme,
|
|
2095
1842
|
component.name
|
|
2096
1843
|
);
|
|
@@ -2111,8 +1858,8 @@ function resolveComponentTree(components, theme) {
|
|
|
2111
1858
|
}
|
|
2112
1859
|
|
|
2113
1860
|
// src/core/structure.ts
|
|
2114
|
-
async function processDocument(document, theme, themeName) {
|
|
2115
|
-
const metadata = createDocumentMetadata(document.props);
|
|
1861
|
+
async function processDocument(document, theme, themeName, generationDate) {
|
|
1862
|
+
const metadata = createDocumentMetadata(document.props, generationDate);
|
|
2116
1863
|
const docDefaults = document.props.componentDefaults;
|
|
2117
1864
|
const mergedComponentDefaults = docDefaults ? mergeWithDefaults2(docDefaults, theme.componentDefaults || {}) : void 0;
|
|
2118
1865
|
const docNoProofWords = document.props.noProofWords;
|
|
@@ -2150,13 +1897,16 @@ async function processDocument(document, theme, themeName) {
|
|
|
2150
1897
|
language: document.props.language
|
|
2151
1898
|
};
|
|
2152
1899
|
}
|
|
2153
|
-
function createDocumentMetadata(props) {
|
|
1900
|
+
function createDocumentMetadata(props, generationDate = /* @__PURE__ */ new Date()) {
|
|
2154
1901
|
return {
|
|
2155
1902
|
title: props.metadata?.title,
|
|
2156
1903
|
subtitle: props.metadata?.subtitle,
|
|
1904
|
+
description: props.metadata?.description,
|
|
2157
1905
|
author: props.metadata?.author,
|
|
2158
1906
|
company: props.metadata?.company,
|
|
2159
|
-
|
|
1907
|
+
version: props.metadata?.version,
|
|
1908
|
+
tags: props.metadata?.tags,
|
|
1909
|
+
date: props.metadata?.date ? new Date(props.metadata.date) : generationDate
|
|
2160
1910
|
};
|
|
2161
1911
|
}
|
|
2162
1912
|
async function extractSections(components, context) {
|
|
@@ -3819,7 +3569,39 @@ function parseTextWithHyperlinks(text, baseStyle = {}, options = {}) {
|
|
|
3819
3569
|
return runs;
|
|
3820
3570
|
}
|
|
3821
3571
|
|
|
3572
|
+
// src/utils/generationContext.ts
|
|
3573
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3574
|
+
var generationDateStorage = new AsyncLocalStorage();
|
|
3575
|
+
function runWithGenerationDate(date, callback) {
|
|
3576
|
+
return generationDateStorage.run(date, callback);
|
|
3577
|
+
}
|
|
3578
|
+
function getGenerationDate() {
|
|
3579
|
+
return generationDateStorage.getStore() ?? /* @__PURE__ */ new Date();
|
|
3580
|
+
}
|
|
3581
|
+
|
|
3822
3582
|
// src/utils/placeholderProcessor.ts
|
|
3583
|
+
function styledPlaceholderText(text, context) {
|
|
3584
|
+
return new TextRun2({
|
|
3585
|
+
text,
|
|
3586
|
+
font: context?.style?.font,
|
|
3587
|
+
size: context?.style?.size,
|
|
3588
|
+
color: context?.style?.color,
|
|
3589
|
+
bold: context?.style?.bold,
|
|
3590
|
+
italics: context?.style?.italics,
|
|
3591
|
+
underline: context?.style?.underline,
|
|
3592
|
+
language: context?.style?.language,
|
|
3593
|
+
noProof: context?.style?.noProof
|
|
3594
|
+
});
|
|
3595
|
+
}
|
|
3596
|
+
function placeholderDate(context) {
|
|
3597
|
+
return context?.date ?? getGenerationDate();
|
|
3598
|
+
}
|
|
3599
|
+
function isoDate(date) {
|
|
3600
|
+
return date.toISOString().slice(0, 10);
|
|
3601
|
+
}
|
|
3602
|
+
function isoDateTime(date) {
|
|
3603
|
+
return date.toISOString().replace("T", " ").replace(/\.\d{3}Z$/, "Z");
|
|
3604
|
+
}
|
|
3823
3605
|
var PlaceholderRegistry = class {
|
|
3824
3606
|
static handlers = /* @__PURE__ */ new Map();
|
|
3825
3607
|
/**
|
|
@@ -3875,8 +3657,6 @@ function processTextWithPlaceholders(text, baseStyle = {}, context = {}, noProof
|
|
|
3875
3657
|
const placeholderResult = handler({ ...context, style: baseStyle });
|
|
3876
3658
|
if (Array.isArray(placeholderResult)) {
|
|
3877
3659
|
result.push(...placeholderResult);
|
|
3878
|
-
} else if (placeholderResult instanceof TextRun2) {
|
|
3879
|
-
result.push(placeholderResult);
|
|
3880
3660
|
} else if (typeof placeholderResult === "string") {
|
|
3881
3661
|
result.push(
|
|
3882
3662
|
...createTextRunsWithNewlines2(
|
|
@@ -3885,6 +3665,8 @@ function processTextWithPlaceholders(text, baseStyle = {}, context = {}, noProof
|
|
|
3885
3665
|
noProofWords
|
|
3886
3666
|
)
|
|
3887
3667
|
);
|
|
3668
|
+
} else {
|
|
3669
|
+
result.push(placeholderResult);
|
|
3888
3670
|
}
|
|
3889
3671
|
} else {
|
|
3890
3672
|
result.push(
|
|
@@ -3999,59 +3781,51 @@ function initializeBuiltinPlaceholders() {
|
|
|
3999
3781
|
underline: context?.style?.underline
|
|
4000
3782
|
});
|
|
4001
3783
|
});
|
|
4002
|
-
PlaceholderRegistry.register(
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
const dateTimeString = now.toLocaleString();
|
|
4018
|
-
return new TextRun2({
|
|
4019
|
-
text: dateTimeString,
|
|
4020
|
-
font: context?.style?.font,
|
|
4021
|
-
size: context?.style?.size,
|
|
4022
|
-
color: context?.style?.color,
|
|
4023
|
-
bold: context?.style?.bold,
|
|
4024
|
-
italics: context?.style?.italics,
|
|
4025
|
-
underline: context?.style?.underline
|
|
4026
|
-
});
|
|
4027
|
-
});
|
|
4028
|
-
PlaceholderRegistry.register("YEAR", (context) => {
|
|
4029
|
-
const year = (/* @__PURE__ */ new Date()).getFullYear().toString();
|
|
4030
|
-
return new TextRun2({
|
|
4031
|
-
text: year,
|
|
4032
|
-
font: context?.style?.font,
|
|
4033
|
-
size: context?.style?.size,
|
|
4034
|
-
color: context?.style?.color,
|
|
4035
|
-
bold: context?.style?.bold,
|
|
4036
|
-
italics: context?.style?.italics,
|
|
4037
|
-
underline: context?.style?.underline
|
|
4038
|
-
});
|
|
4039
|
-
});
|
|
3784
|
+
PlaceholderRegistry.register(
|
|
3785
|
+
"DATE",
|
|
3786
|
+
(context) => styledPlaceholderText(isoDate(placeholderDate(context)), context)
|
|
3787
|
+
);
|
|
3788
|
+
PlaceholderRegistry.register(
|
|
3789
|
+
"DATETIME",
|
|
3790
|
+
(context) => styledPlaceholderText(isoDateTime(placeholderDate(context)), context)
|
|
3791
|
+
);
|
|
3792
|
+
PlaceholderRegistry.register(
|
|
3793
|
+
"YEAR",
|
|
3794
|
+
(context) => styledPlaceholderText(
|
|
3795
|
+
String(placeholderDate(context).getUTCFullYear()),
|
|
3796
|
+
context
|
|
3797
|
+
)
|
|
3798
|
+
);
|
|
4040
3799
|
}
|
|
4041
3800
|
initializeBuiltinPlaceholders();
|
|
4042
3801
|
|
|
4043
3802
|
// src/utils/revisionUtils.ts
|
|
3803
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
4044
3804
|
var DEFAULT_REVISION_AUTHOR = "json-to-office";
|
|
4045
3805
|
var DEFAULT_REVISION_DATE = "1970-01-01T00:00:00Z";
|
|
4046
3806
|
var RevisionIdRegistry = class {
|
|
4047
|
-
|
|
3807
|
+
fallbackCounter = 0;
|
|
3808
|
+
scopes = new AsyncLocalStorage2();
|
|
3809
|
+
runScoped(callback) {
|
|
3810
|
+
return this.scopes.run({ counter: 0 }, callback);
|
|
3811
|
+
}
|
|
4048
3812
|
next() {
|
|
4049
|
-
this.
|
|
4050
|
-
|
|
3813
|
+
const state = this.scopes.getStore();
|
|
3814
|
+
if (state) {
|
|
3815
|
+
state.counter += 1;
|
|
3816
|
+
return state.counter;
|
|
3817
|
+
}
|
|
3818
|
+
this.fallbackCounter += 1;
|
|
3819
|
+
return this.fallbackCounter;
|
|
4051
3820
|
}
|
|
4052
3821
|
/** Test-only: deterministic ids for snapshot assertions. */
|
|
4053
3822
|
clear() {
|
|
4054
|
-
|
|
3823
|
+
const state = this.scopes.getStore();
|
|
3824
|
+
if (state) {
|
|
3825
|
+
state.counter = 0;
|
|
3826
|
+
} else {
|
|
3827
|
+
this.fallbackCounter = 0;
|
|
3828
|
+
}
|
|
4055
3829
|
}
|
|
4056
3830
|
};
|
|
4057
3831
|
var globalRevisionIdRegistry = new RevisionIdRegistry();
|
|
@@ -4179,7 +3953,10 @@ async function clearComponentCache() {
|
|
|
4179
3953
|
}
|
|
4180
3954
|
}
|
|
4181
3955
|
async function renderComponentWithCache(component, theme, themeName, context, bypassCache = false) {
|
|
4182
|
-
const forceBypassForType = component.name === "toc" || component.name === "section" || component.name === "visual" ||
|
|
3956
|
+
const forceBypassForType = component.name === "toc" || component.name === "section" || component.name === "visual" || component.name === "heading" || // Both explicit lists and markdown-list paragraphs register numbering in
|
|
3957
|
+
// the current document scope. Cached paragraphs can otherwise reference
|
|
3958
|
+
// definitions that only existed in a previous render.
|
|
3959
|
+
component.name === "list" || component.name === "paragraph" || "id" in component || componentHasRevision(component);
|
|
4183
3960
|
if (!componentCache) {
|
|
4184
3961
|
initializeComponentCache();
|
|
4185
3962
|
}
|
|
@@ -4189,8 +3966,9 @@ async function renderComponentWithCache(component, theme, themeName, context, by
|
|
|
4189
3966
|
const componentProps = JSON.stringify(component.props || {});
|
|
4190
3967
|
const themeHash = createThemeHash(theme);
|
|
4191
3968
|
const contextKey = context?.section ? `${context.section.currentLayout}:${context.section.columnCount}` : "no-section";
|
|
3969
|
+
const generationDateKey = getGenerationDate().toISOString();
|
|
4192
3970
|
const childrenKey = "children" in component && component.children ? `:children:${JSON.stringify(component.children)}` : "";
|
|
4193
|
-
const cacheKey = `component:${component.name}:${themeHash}:${contextKey}:${componentProps}${childrenKey}`;
|
|
3971
|
+
const cacheKey = `component:${component.name}:${themeHash}:${contextKey}:${generationDateKey}:${componentProps}${childrenKey}`;
|
|
4194
3972
|
const cached = await componentCache.get(cacheKey);
|
|
4195
3973
|
if (cached) {
|
|
4196
3974
|
return cached.result;
|
|
@@ -4261,19 +4039,27 @@ init_styles();
|
|
|
4261
4039
|
init_defaults();
|
|
4262
4040
|
|
|
4263
4041
|
// src/utils/bookmarkRegistry.ts
|
|
4042
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
4264
4043
|
var BookmarkRegistry = class {
|
|
4265
|
-
|
|
4266
|
-
|
|
4044
|
+
fallback = { bookmarks: /* @__PURE__ */ new Map() };
|
|
4045
|
+
scopes = new AsyncLocalStorage3();
|
|
4046
|
+
get state() {
|
|
4047
|
+
return this.scopes.getStore() ?? this.fallback;
|
|
4048
|
+
}
|
|
4049
|
+
/** Run work with an isolated registry that follows its async call chain. */
|
|
4050
|
+
runScoped(callback) {
|
|
4051
|
+
return this.scopes.run({ bookmarks: /* @__PURE__ */ new Map() }, callback);
|
|
4052
|
+
}
|
|
4267
4053
|
/**
|
|
4268
4054
|
* Register a bookmark
|
|
4269
4055
|
*/
|
|
4270
4056
|
register(id, title, type) {
|
|
4271
|
-
if (this.bookmarks.has(id)) {
|
|
4057
|
+
if (this.state.bookmarks.has(id)) {
|
|
4272
4058
|
console.warn(
|
|
4273
4059
|
`Duplicate bookmark ID: ${id}. Using the latest registration.`
|
|
4274
4060
|
);
|
|
4275
4061
|
}
|
|
4276
|
-
this.bookmarks.set(id, { id, title, type });
|
|
4062
|
+
this.state.bookmarks.set(id, { id, title, type });
|
|
4277
4063
|
}
|
|
4278
4064
|
/**
|
|
4279
4065
|
* Generate a unique bookmark ID from text
|
|
@@ -4283,7 +4069,7 @@ var BookmarkRegistry = class {
|
|
|
4283
4069
|
const baseId = text.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").substring(0, 40);
|
|
4284
4070
|
let id = baseId;
|
|
4285
4071
|
let attempt = 0;
|
|
4286
|
-
while (this.bookmarks.has(id) && attempt < 100) {
|
|
4072
|
+
while (this.state.bookmarks.has(id) && attempt < 100) {
|
|
4287
4073
|
id = `${baseId}-${++attempt}`;
|
|
4288
4074
|
}
|
|
4289
4075
|
return id;
|
|
@@ -4292,26 +4078,25 @@ var BookmarkRegistry = class {
|
|
|
4292
4078
|
* Check if a bookmark exists
|
|
4293
4079
|
*/
|
|
4294
4080
|
exists(id) {
|
|
4295
|
-
return this.bookmarks.has(id);
|
|
4081
|
+
return this.state.bookmarks.has(id);
|
|
4296
4082
|
}
|
|
4297
4083
|
/**
|
|
4298
4084
|
* Get bookmark info by ID
|
|
4299
4085
|
*/
|
|
4300
4086
|
get(id) {
|
|
4301
|
-
return this.bookmarks.get(id);
|
|
4087
|
+
return this.state.bookmarks.get(id);
|
|
4302
4088
|
}
|
|
4303
4089
|
/**
|
|
4304
4090
|
* Get all registered bookmarks
|
|
4305
4091
|
*/
|
|
4306
4092
|
getAll() {
|
|
4307
|
-
return Array.from(this.bookmarks.values());
|
|
4093
|
+
return Array.from(this.state.bookmarks.values());
|
|
4308
4094
|
}
|
|
4309
4095
|
/**
|
|
4310
4096
|
* Clear all bookmarks
|
|
4311
4097
|
*/
|
|
4312
4098
|
clear() {
|
|
4313
|
-
this.bookmarks.clear();
|
|
4314
|
-
this.counter = 0;
|
|
4099
|
+
this.state.bookmarks.clear();
|
|
4315
4100
|
}
|
|
4316
4101
|
/**
|
|
4317
4102
|
* Validate that all internal hyperlink references exist
|
|
@@ -4816,6 +4601,32 @@ async function createTable(columns, tableConfig, theme, themeName, _options = {}
|
|
|
4816
4601
|
borderColor: "000000",
|
|
4817
4602
|
borderSize: 1
|
|
4818
4603
|
});
|
|
4604
|
+
const warnedCellColors = /* @__PURE__ */ new Set();
|
|
4605
|
+
const warnCellColor = (code, message) => {
|
|
4606
|
+
if (warnedCellColors.has(message)) return;
|
|
4607
|
+
warnedCellColors.add(message);
|
|
4608
|
+
console.warn(`[json-to-docx] ${code}: ${message}`);
|
|
4609
|
+
};
|
|
4610
|
+
const resolveCellColor = (value, prop) => {
|
|
4611
|
+
if (value === void 0 || value === "auto") return value;
|
|
4612
|
+
if (value === "transparent") {
|
|
4613
|
+
if (prop === "backgroundColor") return value;
|
|
4614
|
+
warnCellColor(
|
|
4615
|
+
"TABLE_CELL_COLOR_INVALID",
|
|
4616
|
+
`"transparent" is not a valid table cell "color"; ignoring it and using the table style color. It only applies to "backgroundColor".`
|
|
4617
|
+
);
|
|
4618
|
+
return void 0;
|
|
4619
|
+
}
|
|
4620
|
+
if (/^[0-9A-Fa-f]{6}$/.test(value)) return value.toUpperCase();
|
|
4621
|
+
try {
|
|
4622
|
+
return resolveColor(value, theme);
|
|
4623
|
+
} catch {
|
|
4624
|
+
const allowed = prop === "backgroundColor" ? '"auto", or "transparent" for no shading' : 'or "auto"';
|
|
4625
|
+
throw new Error(
|
|
4626
|
+
`Invalid table cell ${prop}: "${value}". Must be a hex color with # prefix (e.g. "#000000"), a theme color name, ${allowed}.`
|
|
4627
|
+
);
|
|
4628
|
+
}
|
|
4629
|
+
};
|
|
4819
4630
|
const normalizeBorderColor = (border) => {
|
|
4820
4631
|
if (border === void 0) return void 0;
|
|
4821
4632
|
if (typeof border === "string") {
|
|
@@ -4952,8 +4763,14 @@ async function createTable(columns, tableConfig, theme, themeName, _options = {}
|
|
|
4952
4763
|
tableDef?.padding
|
|
4953
4764
|
);
|
|
4954
4765
|
return {
|
|
4955
|
-
color:
|
|
4956
|
-
|
|
4766
|
+
color: resolveCellColor(
|
|
4767
|
+
cellDef?.color ?? columnDef?.color ?? tableDef?.color ?? defaults.color,
|
|
4768
|
+
"color"
|
|
4769
|
+
),
|
|
4770
|
+
backgroundColor: resolveCellColor(
|
|
4771
|
+
cellDef?.backgroundColor ?? columnDef?.backgroundColor ?? tableDef?.backgroundColor ?? defaults.backgroundColor,
|
|
4772
|
+
"backgroundColor"
|
|
4773
|
+
),
|
|
4957
4774
|
horizontalAlignment: cellDef?.horizontalAlignment ?? columnDef?.horizontalAlignment ?? tableDef?.horizontalAlignment ?? defaults.horizontalAlignment,
|
|
4958
4775
|
verticalAlignment: cellDef?.verticalAlignment ?? columnDef?.verticalAlignment ?? tableDef?.verticalAlignment ?? defaults.verticalAlignment,
|
|
4959
4776
|
font: mergedFont,
|
|
@@ -5006,8 +4823,14 @@ async function createTable(columns, tableConfig, theme, themeName, _options = {}
|
|
|
5006
4823
|
tableDef?.padding
|
|
5007
4824
|
);
|
|
5008
4825
|
return {
|
|
5009
|
-
color:
|
|
5010
|
-
|
|
4826
|
+
color: resolveCellColor(
|
|
4827
|
+
headerDef?.color ?? headerTableDef?.color ?? columnDef?.color ?? tableDef?.color ?? defaults.color,
|
|
4828
|
+
"color"
|
|
4829
|
+
),
|
|
4830
|
+
backgroundColor: resolveCellColor(
|
|
4831
|
+
headerDef?.backgroundColor ?? headerTableDef?.backgroundColor ?? columnDef?.backgroundColor ?? tableDef?.backgroundColor ?? defaults.backgroundColor,
|
|
4832
|
+
"backgroundColor"
|
|
4833
|
+
),
|
|
5011
4834
|
horizontalAlignment: headerDef?.horizontalAlignment ?? headerTableDef?.horizontalAlignment ?? columnDef?.horizontalAlignment ?? tableDef?.horizontalAlignment ?? defaults.horizontalAlignment,
|
|
5012
4835
|
verticalAlignment: headerDef?.verticalAlignment ?? headerTableDef?.verticalAlignment ?? columnDef?.verticalAlignment ?? tableDef?.verticalAlignment ?? defaults.verticalAlignment,
|
|
5013
4836
|
font: mergedFont,
|
|
@@ -5229,7 +5052,8 @@ async function createTable(columns, tableConfig, theme, themeName, _options = {}
|
|
|
5229
5052
|
void 0
|
|
5230
5053
|
);
|
|
5231
5054
|
const headerRow = new TableRow({
|
|
5232
|
-
|
|
5055
|
+
// Headers repeat across page breaks unless explicitly disabled
|
|
5056
|
+
tableHeader: tableConfig.repeatHeaderOnPageBreak ?? true,
|
|
5233
5057
|
height: headerHeight !== void 0 ? { value: headerHeight * 20, rule: "atLeast" } : void 0,
|
|
5234
5058
|
children: await Promise.all(
|
|
5235
5059
|
columns.map(async (column, colIndex) => {
|
|
@@ -5599,8 +5423,173 @@ function renderHeadingComponent(component, theme, themeName) {
|
|
|
5599
5423
|
return [header];
|
|
5600
5424
|
}
|
|
5601
5425
|
|
|
5426
|
+
// src/utils/numberingConfig.ts
|
|
5427
|
+
import { AlignmentType as AlignmentType3, convertInchesToTwip, LevelFormat } from "docx";
|
|
5428
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "async_hooks";
|
|
5429
|
+
var LEVEL_FORMAT_MAP = {
|
|
5430
|
+
decimal: LevelFormat.DECIMAL,
|
|
5431
|
+
upperRoman: LevelFormat.UPPER_ROMAN,
|
|
5432
|
+
lowerRoman: LevelFormat.LOWER_ROMAN,
|
|
5433
|
+
upperLetter: LevelFormat.UPPER_LETTER,
|
|
5434
|
+
lowerLetter: LevelFormat.LOWER_LETTER,
|
|
5435
|
+
bullet: LevelFormat.BULLET,
|
|
5436
|
+
ordinal: LevelFormat.ORDINAL,
|
|
5437
|
+
cardinalText: LevelFormat.CARDINAL_TEXT,
|
|
5438
|
+
ordinalText: LevelFormat.ORDINAL_TEXT,
|
|
5439
|
+
hex: LevelFormat.HEX,
|
|
5440
|
+
chicago: LevelFormat.CHICAGO,
|
|
5441
|
+
ideographDigital: LevelFormat.IDEOGRAPH__DIGITAL,
|
|
5442
|
+
japaneseCounting: LevelFormat.JAPANESE_COUNTING,
|
|
5443
|
+
aiueo: LevelFormat.AIUEO,
|
|
5444
|
+
iroha: LevelFormat.IROHA,
|
|
5445
|
+
decimalFullWidth: LevelFormat.DECIMAL_FULL_WIDTH,
|
|
5446
|
+
decimalHalfWidth: LevelFormat.DECIMAL_HALF_WIDTH,
|
|
5447
|
+
japaneseLegal: LevelFormat.JAPANESE_LEGAL,
|
|
5448
|
+
japaneseDigitalTenThousand: LevelFormat.JAPANESE_DIGITAL_TEN_THOUSAND,
|
|
5449
|
+
decimalEnclosedCircle: LevelFormat.DECIMAL_ENCLOSED_CIRCLE,
|
|
5450
|
+
decimalFullWidth2: LevelFormat.DECIMAL_FULL_WIDTH2,
|
|
5451
|
+
aiueoFullWidth: LevelFormat.AIUEO_FULL_WIDTH,
|
|
5452
|
+
irohaFullWidth: LevelFormat.IROHA_FULL_WIDTH,
|
|
5453
|
+
decimalZero: LevelFormat.DECIMAL_ZERO,
|
|
5454
|
+
ganada: LevelFormat.GANADA,
|
|
5455
|
+
chosung: LevelFormat.CHOSUNG,
|
|
5456
|
+
decimalEnclosedFullstop: LevelFormat.DECIMAL_ENCLOSED_FULLSTOP,
|
|
5457
|
+
decimalEnclosedParen: LevelFormat.DECIMAL_ENCLOSED_PARENTHESES,
|
|
5458
|
+
decimalEnclosedCircleChinese: LevelFormat.DECIMAL_ENCLOSED_CIRCLE_CHINESE,
|
|
5459
|
+
ideographEnclosedCircle: LevelFormat.IDEOGRAPH_ENCLOSED_CIRCLE,
|
|
5460
|
+
ideographTraditional: LevelFormat.IDEOGRAPH_TRADITIONAL,
|
|
5461
|
+
ideographZodiac: LevelFormat.IDEOGRAPH_ZODIAC,
|
|
5462
|
+
ideographZodiacTraditional: LevelFormat.IDEOGRAPH_ZODIAC_TRADITIONAL,
|
|
5463
|
+
taiwaneseCounting: LevelFormat.TAIWANESE_COUNTING,
|
|
5464
|
+
ideographLegalTraditional: LevelFormat.IDEOGRAPH_LEGAL_TRADITIONAL,
|
|
5465
|
+
taiwaneseCountingThousand: LevelFormat.TAIWANESE_COUNTING_THOUSAND,
|
|
5466
|
+
taiwaneseDigital: LevelFormat.TAIWANESE_DIGITAL,
|
|
5467
|
+
chineseCounting: LevelFormat.CHINESE_COUNTING,
|
|
5468
|
+
chineseLegalSimplified: LevelFormat.CHINESE_LEGAL_SIMPLIFIED,
|
|
5469
|
+
chineseCountingThousand: LevelFormat.CHINESE_COUNTING_THOUSAND,
|
|
5470
|
+
koreanDigital: LevelFormat.KOREAN_DIGITAL,
|
|
5471
|
+
koreanCounting: LevelFormat.KOREAN_COUNTING,
|
|
5472
|
+
koreanLegal: LevelFormat.KOREAN_LEGAL,
|
|
5473
|
+
koreanDigital2: LevelFormat.KOREAN_DIGITAL2,
|
|
5474
|
+
vietnameseCounting: LevelFormat.VIETNAMESE_COUNTING,
|
|
5475
|
+
russianLower: LevelFormat.RUSSIAN_LOWER,
|
|
5476
|
+
russianUpper: LevelFormat.RUSSIAN_UPPER,
|
|
5477
|
+
none: LevelFormat.NONE,
|
|
5478
|
+
numberInDash: LevelFormat.NUMBER_IN_DASH,
|
|
5479
|
+
hebrew1: LevelFormat.HEBREW1,
|
|
5480
|
+
hebrew2: LevelFormat.HEBREW2,
|
|
5481
|
+
arabicAlpha: LevelFormat.ARABIC_ALPHA,
|
|
5482
|
+
arabicAbjad: LevelFormat.ARABIC_ABJAD,
|
|
5483
|
+
hindiVowels: LevelFormat.HINDI_VOWELS,
|
|
5484
|
+
hindiConsonants: LevelFormat.HINDI_CONSONANTS,
|
|
5485
|
+
hindiNumbers: LevelFormat.HINDI_NUMBERS,
|
|
5486
|
+
hindiCounting: LevelFormat.HINDI_COUNTING,
|
|
5487
|
+
thaiLetters: LevelFormat.THAI_LETTERS,
|
|
5488
|
+
thaiNumbers: LevelFormat.THAI_NUMBERS,
|
|
5489
|
+
thaiCounting: LevelFormat.THAI_COUNTING
|
|
5490
|
+
};
|
|
5491
|
+
var ALIGNMENT_MAP = {
|
|
5492
|
+
start: AlignmentType3.START,
|
|
5493
|
+
end: AlignmentType3.END,
|
|
5494
|
+
left: AlignmentType3.LEFT,
|
|
5495
|
+
right: AlignmentType3.RIGHT,
|
|
5496
|
+
center: AlignmentType3.CENTER
|
|
5497
|
+
};
|
|
5498
|
+
function getLevelFormat(format2) {
|
|
5499
|
+
if (!format2) return LevelFormat.BULLET;
|
|
5500
|
+
return LEVEL_FORMAT_MAP[format2] || LevelFormat.BULLET;
|
|
5501
|
+
}
|
|
5502
|
+
function getAlignment2(alignment) {
|
|
5503
|
+
if (!alignment) return AlignmentType3.LEFT;
|
|
5504
|
+
return ALIGNMENT_MAP[alignment] || AlignmentType3.LEFT;
|
|
5505
|
+
}
|
|
5506
|
+
function createNumberingConfig(config) {
|
|
5507
|
+
const levels = [];
|
|
5508
|
+
for (const levelConfig of config.levels) {
|
|
5509
|
+
const format2 = getLevelFormat(levelConfig.format);
|
|
5510
|
+
const alignment = getAlignment2(levelConfig.alignment);
|
|
5511
|
+
const text = levelConfig.text || (format2 === LevelFormat.BULLET ? "\u2022" : `%${levelConfig.level + 1}.`);
|
|
5512
|
+
const baseIndent = levelConfig.indent?.left !== void 0 ? levelConfig.indent.left / 72 : 0.5 * (levelConfig.level + 1);
|
|
5513
|
+
const hangingIndent = levelConfig.indent?.hanging !== void 0 ? levelConfig.indent.hanging / 72 : 0.25;
|
|
5514
|
+
const level = {
|
|
5515
|
+
level: levelConfig.level,
|
|
5516
|
+
format: format2,
|
|
5517
|
+
text,
|
|
5518
|
+
alignment,
|
|
5519
|
+
style: {
|
|
5520
|
+
paragraph: {
|
|
5521
|
+
indent: {
|
|
5522
|
+
left: convertInchesToTwip(baseIndent),
|
|
5523
|
+
hanging: convertInchesToTwip(hangingIndent)
|
|
5524
|
+
}
|
|
5525
|
+
}
|
|
5526
|
+
},
|
|
5527
|
+
// Add start number if specified
|
|
5528
|
+
...levelConfig.start !== void 0 && { start: levelConfig.start }
|
|
5529
|
+
};
|
|
5530
|
+
levels.push(level);
|
|
5531
|
+
}
|
|
5532
|
+
return {
|
|
5533
|
+
reference: config.reference,
|
|
5534
|
+
levels
|
|
5535
|
+
};
|
|
5536
|
+
}
|
|
5537
|
+
var NumberingRegistry = class {
|
|
5538
|
+
fallback = {
|
|
5539
|
+
configs: /* @__PURE__ */ new Map(),
|
|
5540
|
+
counter: 0
|
|
5541
|
+
};
|
|
5542
|
+
scopes = new AsyncLocalStorage4();
|
|
5543
|
+
get state() {
|
|
5544
|
+
return this.scopes.getStore() ?? this.fallback;
|
|
5545
|
+
}
|
|
5546
|
+
/** Run work with an isolated registry that follows its async call chain. */
|
|
5547
|
+
runScoped(callback) {
|
|
5548
|
+
return this.scopes.run({ configs: /* @__PURE__ */ new Map(), counter: 0 }, callback);
|
|
5549
|
+
}
|
|
5550
|
+
/**
|
|
5551
|
+
* Register a numbering configuration
|
|
5552
|
+
*/
|
|
5553
|
+
register(config) {
|
|
5554
|
+
const reference = config.reference;
|
|
5555
|
+
this.state.configs.set(reference, config);
|
|
5556
|
+
return reference;
|
|
5557
|
+
}
|
|
5558
|
+
/**
|
|
5559
|
+
* Generate a unique reference ID
|
|
5560
|
+
*/
|
|
5561
|
+
generateReference(prefix = "list") {
|
|
5562
|
+
return `${prefix}-${++this.state.counter}`;
|
|
5563
|
+
}
|
|
5564
|
+
/**
|
|
5565
|
+
* Get all registered configurations as an array suitable for INumberingOptions
|
|
5566
|
+
*/
|
|
5567
|
+
getAll() {
|
|
5568
|
+
return Array.from(this.state.configs.values());
|
|
5569
|
+
}
|
|
5570
|
+
/**
|
|
5571
|
+
* Clear all configurations
|
|
5572
|
+
*/
|
|
5573
|
+
clear() {
|
|
5574
|
+
this.state.configs.clear();
|
|
5575
|
+
this.state.counter = 0;
|
|
5576
|
+
}
|
|
5577
|
+
/**
|
|
5578
|
+
* Check if a reference exists
|
|
5579
|
+
*/
|
|
5580
|
+
has(reference) {
|
|
5581
|
+
return this.state.configs.has(reference);
|
|
5582
|
+
}
|
|
5583
|
+
/**
|
|
5584
|
+
* Get a configuration by reference
|
|
5585
|
+
*/
|
|
5586
|
+
get(reference) {
|
|
5587
|
+
return this.state.configs.get(reference);
|
|
5588
|
+
}
|
|
5589
|
+
};
|
|
5590
|
+
var globalNumberingRegistry = new NumberingRegistry();
|
|
5591
|
+
|
|
5602
5592
|
// src/components/paragraph.ts
|
|
5603
|
-
init_numberingConfig();
|
|
5604
5593
|
function parseMarkdownList(text) {
|
|
5605
5594
|
const lines = text.split("\n");
|
|
5606
5595
|
const items = [];
|
|
@@ -5726,7 +5715,6 @@ function renderParagraphComponent(component, theme, themeName) {
|
|
|
5726
5715
|
}
|
|
5727
5716
|
|
|
5728
5717
|
// src/components/list.ts
|
|
5729
|
-
init_numberingConfig();
|
|
5730
5718
|
function createLevelsFromSimplifiedProps(props) {
|
|
5731
5719
|
const levels = [];
|
|
5732
5720
|
let format2;
|
|
@@ -6150,17 +6138,22 @@ async function renderTableComponent(component, theme, themeName) {
|
|
|
6150
6138
|
|
|
6151
6139
|
// src/components/section.ts
|
|
6152
6140
|
import { Paragraph as Paragraph4, BookmarkStart, BookmarkEnd } from "docx";
|
|
6153
|
-
function generateSectionBookmarkId() {
|
|
6154
|
-
const
|
|
6141
|
+
function generateSectionBookmarkId(context) {
|
|
6142
|
+
const custom = context.custom ??= {};
|
|
6143
|
+
const state = custom.sectionBookmarks ??= {
|
|
6144
|
+
next: 1
|
|
6145
|
+
};
|
|
6146
|
+
const ordinal = state.next++;
|
|
6147
|
+
const linkId = 1e6 + ordinal;
|
|
6155
6148
|
return {
|
|
6156
|
-
id: `
|
|
6149
|
+
id: `_NestedSection_${ordinal}`,
|
|
6157
6150
|
linkId
|
|
6158
6151
|
};
|
|
6159
6152
|
}
|
|
6160
6153
|
async function renderSectionComponent(component, theme, themeName, context) {
|
|
6161
6154
|
if (!isSectionComponent(component)) return [];
|
|
6162
6155
|
const elements = [];
|
|
6163
|
-
const { id: sectionBookmarkId, linkId: bookmarkLinkId } = generateSectionBookmarkId();
|
|
6156
|
+
const { id: sectionBookmarkId, linkId: bookmarkLinkId } = generateSectionBookmarkId(context);
|
|
6164
6157
|
elements.push(
|
|
6165
6158
|
new Paragraph4({
|
|
6166
6159
|
children: [new BookmarkStart(sectionBookmarkId, bookmarkLinkId)],
|
|
@@ -6391,6 +6384,11 @@ function renderTocComponent(component, theme, context) {
|
|
|
6391
6384
|
pageNumbersStart = pageNumbersRange.from;
|
|
6392
6385
|
pageNumbersEnd = pageNumbersRange.to;
|
|
6393
6386
|
}
|
|
6387
|
+
if (componentProps.numberingStyle !== void 0) {
|
|
6388
|
+
console.warn(
|
|
6389
|
+
`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.`
|
|
6390
|
+
);
|
|
6391
|
+
}
|
|
6394
6392
|
const includePageNumbers = componentProps.includePageNumbers !== false;
|
|
6395
6393
|
const scope = componentProps.scope ?? "auto";
|
|
6396
6394
|
const effectiveScope = scope === "auto" ? context?.section?.sectionBookmarkId ? "section" : "document" : scope;
|
|
@@ -6480,6 +6478,9 @@ function renderTocComponent(component, theme, context) {
|
|
|
6480
6478
|
return paragraphs;
|
|
6481
6479
|
}
|
|
6482
6480
|
|
|
6481
|
+
// src/components/highcharts.ts
|
|
6482
|
+
init_colorUtils();
|
|
6483
|
+
|
|
6483
6484
|
// src/utils/environment.ts
|
|
6484
6485
|
function isNodeEnvironment() {
|
|
6485
6486
|
return typeof process !== "undefined" && process.versions != null && process.versions.node != null && typeof process.versions.node === "string";
|
|
@@ -6536,6 +6537,7 @@ async function postJsonToService(opts) {
|
|
|
6536
6537
|
}
|
|
6537
6538
|
|
|
6538
6539
|
// src/components/highcharts.ts
|
|
6540
|
+
import { DEFAULT_CHART_THEME_COLORS } from "@json-to-office/shared";
|
|
6539
6541
|
var DEFAULT_EXPORT_SERVER_URL = "http://localhost:7801";
|
|
6540
6542
|
async function generateChart(config, servicesConfig) {
|
|
6541
6543
|
if (!isNodeEnvironment()) {
|
|
@@ -6576,14 +6578,24 @@ Cause: ${cause}`
|
|
|
6576
6578
|
height
|
|
6577
6579
|
};
|
|
6578
6580
|
}
|
|
6581
|
+
function toChartColor(value, theme) {
|
|
6582
|
+
if (/^#?[0-9A-Fa-f]{6}$/.test(value)) {
|
|
6583
|
+
return value.startsWith("#") ? value : `#${value}`;
|
|
6584
|
+
}
|
|
6585
|
+
try {
|
|
6586
|
+
return `#${resolveColor(value, theme)}`;
|
|
6587
|
+
} catch {
|
|
6588
|
+
return void 0;
|
|
6589
|
+
}
|
|
6590
|
+
}
|
|
6579
6591
|
function withThemeColors(config, theme) {
|
|
6580
6592
|
const options = config.options;
|
|
6581
6593
|
if (!options || options.colors || !theme?.colors) return config;
|
|
6582
|
-
const
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
theme
|
|
6586
|
-
|
|
6594
|
+
const themeColors = theme.colors;
|
|
6595
|
+
const palette = DEFAULT_CHART_THEME_COLORS.map((token) => {
|
|
6596
|
+
const value = themeColors[token];
|
|
6597
|
+
return typeof value === "string" && value.length > 0 ? toChartColor(value, theme) : void 0;
|
|
6598
|
+
}).filter((c) => c !== void 0);
|
|
6587
6599
|
if (palette.length === 0) return config;
|
|
6588
6600
|
return {
|
|
6589
6601
|
...config,
|
|
@@ -6788,14 +6800,40 @@ function getAlignment3(alignment) {
|
|
|
6788
6800
|
return AlignmentType5.LEFT;
|
|
6789
6801
|
}
|
|
6790
6802
|
}
|
|
6803
|
+
function coreProperties(metadata) {
|
|
6804
|
+
const { title, subtitle, description, author, company, version, tags } = metadata;
|
|
6805
|
+
const customProperties = [
|
|
6806
|
+
...company ? [{ name: "Company", value: company }] : [],
|
|
6807
|
+
...version ? [{ name: "Version", value: version }] : []
|
|
6808
|
+
];
|
|
6809
|
+
return {
|
|
6810
|
+
...title && { title },
|
|
6811
|
+
...subtitle && { subject: subtitle },
|
|
6812
|
+
...description && { description },
|
|
6813
|
+
// Word surfaces both names; author is the only person the document knows.
|
|
6814
|
+
...author && { creator: author, lastModifiedBy: author },
|
|
6815
|
+
...tags && tags.length > 0 && { keywords: tags.join(", ") },
|
|
6816
|
+
...customProperties.length > 0 && { customProperties }
|
|
6817
|
+
};
|
|
6818
|
+
}
|
|
6791
6819
|
async function renderDocument(structure, layout, options) {
|
|
6820
|
+
return runWithGenerationDate(
|
|
6821
|
+
structure.metadata.date,
|
|
6822
|
+
() => globalBookmarkRegistry.runScoped(
|
|
6823
|
+
() => globalRevisionIdRegistry.runScoped(
|
|
6824
|
+
() => globalNumberingRegistry.runScoped(
|
|
6825
|
+
() => renderDocumentScoped(structure, layout, options)
|
|
6826
|
+
)
|
|
6827
|
+
)
|
|
6828
|
+
)
|
|
6829
|
+
);
|
|
6830
|
+
}
|
|
6831
|
+
async function renderDocumentScoped(structure, layout, options) {
|
|
6792
6832
|
if (options?.cache) {
|
|
6793
6833
|
initializeComponentCache(options.cache);
|
|
6794
6834
|
} else if (!options?.bypassCache) {
|
|
6795
6835
|
initializeComponentCache();
|
|
6796
6836
|
}
|
|
6797
|
-
const { globalNumberingRegistry: globalNumberingRegistry2 } = await Promise.resolve().then(() => (init_numberingConfig(), numberingConfig_exports));
|
|
6798
|
-
globalNumberingRegistry2.clear();
|
|
6799
6837
|
const sections = [];
|
|
6800
6838
|
const context = createRenderContext(
|
|
6801
6839
|
structure,
|
|
@@ -6852,7 +6890,8 @@ async function renderDocument(structure, layout, options) {
|
|
|
6852
6890
|
structure.themeName,
|
|
6853
6891
|
context,
|
|
6854
6892
|
sectionOrdinal,
|
|
6855
|
-
closeBookmark
|
|
6893
|
+
closeBookmark,
|
|
6894
|
+
options?.bypassCache === true
|
|
6856
6895
|
);
|
|
6857
6896
|
if (layoutSection.isUserSection) {
|
|
6858
6897
|
sectionBookmarkCounter++;
|
|
@@ -6861,10 +6900,11 @@ async function renderDocument(structure, layout, options) {
|
|
|
6861
6900
|
sections.push(rendered);
|
|
6862
6901
|
}
|
|
6863
6902
|
}
|
|
6864
|
-
const numberingConfigs =
|
|
6903
|
+
const numberingConfigs = globalNumberingRegistry.getAll();
|
|
6865
6904
|
return new Document({
|
|
6866
6905
|
styles: createWordStyles(structure.theme, structure.language),
|
|
6867
6906
|
sections,
|
|
6907
|
+
...coreProperties(structure.metadata),
|
|
6868
6908
|
features: {
|
|
6869
6909
|
updateFields: true,
|
|
6870
6910
|
// Required for TOC fields to update correctly
|
|
@@ -7029,7 +7069,7 @@ async function renderHeaderFooterComponents(components, theme, themeName, contex
|
|
|
7029
7069
|
}
|
|
7030
7070
|
return elements;
|
|
7031
7071
|
}
|
|
7032
|
-
async function renderSection(section, theme, themeName, context, sectionOrdinal, closeBookmark) {
|
|
7072
|
+
async function renderSection(section, theme, themeName, context, sectionOrdinal, closeBookmark, bypassCache = false) {
|
|
7033
7073
|
const elements = [];
|
|
7034
7074
|
const isFirstLayoutOfUserSection = section.isUserSection;
|
|
7035
7075
|
const sharedLinkId = section.belongsToUserSection && sectionOrdinal ? sectionOrdinal : void 0;
|
|
@@ -7067,8 +7107,7 @@ async function renderSection(section, theme, themeName, context, sectionOrdinal,
|
|
|
7067
7107
|
theme,
|
|
7068
7108
|
themeName,
|
|
7069
7109
|
sectionContext,
|
|
7070
|
-
|
|
7071
|
-
// Don't bypass cache
|
|
7110
|
+
bypassCache
|
|
7072
7111
|
);
|
|
7073
7112
|
elements.push(...rendered);
|
|
7074
7113
|
}
|
|
@@ -7218,6 +7257,75 @@ async function resolveDocumentFonts(document, theme, fonts, warnings) {
|
|
|
7218
7257
|
// src/core/generator.ts
|
|
7219
7258
|
import { applyExportMode, scopedThemeName } from "@json-to-office/shared";
|
|
7220
7259
|
|
|
7260
|
+
// src/utils/packageDocument.ts
|
|
7261
|
+
import AdmZip2 from "adm-zip";
|
|
7262
|
+
import { Packer } from "docx";
|
|
7263
|
+
|
|
7264
|
+
// src/utils/fixFloatingImageIds.ts
|
|
7265
|
+
import AdmZip from "adm-zip";
|
|
7266
|
+
function fixFloatingImageIdsInBuffer(buffer) {
|
|
7267
|
+
const zip = new AdmZip(buffer);
|
|
7268
|
+
const documentEntry = zip.getEntry("word/document.xml");
|
|
7269
|
+
if (!documentEntry) {
|
|
7270
|
+
throw new Error("document.xml not found in DOCX");
|
|
7271
|
+
}
|
|
7272
|
+
let idCounter = 1;
|
|
7273
|
+
const documentXml = documentEntry.getData().toString("utf8").replace(/<wp:docPr\s+id="(\d+)"/g, () => {
|
|
7274
|
+
const newId = idCounter++;
|
|
7275
|
+
return `<wp:docPr id="${newId}"`;
|
|
7276
|
+
});
|
|
7277
|
+
zip.updateFile(documentEntry, Buffer.from(documentXml, "utf8"));
|
|
7278
|
+
return zip.toBuffer();
|
|
7279
|
+
}
|
|
7280
|
+
|
|
7281
|
+
// src/utils/packageDocument.ts
|
|
7282
|
+
var DEFAULT_GENERATION_DATE = /* @__PURE__ */ new Date("2000-01-01T00:00:00.000Z");
|
|
7283
|
+
function resolveGenerationDate(options) {
|
|
7284
|
+
if (options?.generatedAt !== void 0) {
|
|
7285
|
+
const date = new Date(options.generatedAt);
|
|
7286
|
+
if (Number.isNaN(date.getTime())) {
|
|
7287
|
+
throw new RangeError("generatedAt must be a valid date");
|
|
7288
|
+
}
|
|
7289
|
+
if (date.getUTCFullYear() < 1980) {
|
|
7290
|
+
throw new RangeError(
|
|
7291
|
+
"generatedAt must be on or after 1980-01-01 for ZIP compatibility"
|
|
7292
|
+
);
|
|
7293
|
+
}
|
|
7294
|
+
return date;
|
|
7295
|
+
}
|
|
7296
|
+
return options?.deterministic === false ? /* @__PURE__ */ new Date() : new Date(DEFAULT_GENERATION_DATE);
|
|
7297
|
+
}
|
|
7298
|
+
function toDosTime(date) {
|
|
7299
|
+
const dosDate = (date.getUTCFullYear() - 1980 & 127) << 9 | date.getUTCMonth() + 1 << 5 | date.getUTCDate();
|
|
7300
|
+
const dosTime = date.getUTCHours() << 11 | date.getUTCMinutes() << 5 | date.getUTCSeconds() >> 1;
|
|
7301
|
+
return (dosDate << 16 | dosTime) >>> 0;
|
|
7302
|
+
}
|
|
7303
|
+
function canonicalizeDocxBuffer(buffer, generatedAt = DEFAULT_GENERATION_DATE) {
|
|
7304
|
+
const zip = new AdmZip2(buffer);
|
|
7305
|
+
const isoTimestamp = generatedAt.toISOString();
|
|
7306
|
+
const coreProperties2 = zip.getEntry("docProps/core.xml");
|
|
7307
|
+
if (coreProperties2) {
|
|
7308
|
+
const normalized = coreProperties2.getData().toString("utf8").replace(
|
|
7309
|
+
/(<dcterms:(?:created|modified)\b[^>]*>)[^<]*(<\/dcterms:(?:created|modified)>)/g,
|
|
7310
|
+
`$1${isoTimestamp}$2`
|
|
7311
|
+
);
|
|
7312
|
+
zip.updateFile(coreProperties2, Buffer.from(normalized, "utf8"));
|
|
7313
|
+
}
|
|
7314
|
+
const zipTimestamp = toDosTime(generatedAt);
|
|
7315
|
+
for (const entry of zip.getEntries()) {
|
|
7316
|
+
entry.header.timeval = zipTimestamp;
|
|
7317
|
+
}
|
|
7318
|
+
return zip.toBuffer();
|
|
7319
|
+
}
|
|
7320
|
+
async function packageDocument(document, options) {
|
|
7321
|
+
const packed = await Packer.toBuffer(document);
|
|
7322
|
+
const fixed = fixFloatingImageIdsInBuffer(packed);
|
|
7323
|
+
if (options?.deterministic === false) {
|
|
7324
|
+
return fixed;
|
|
7325
|
+
}
|
|
7326
|
+
return canonicalizeDocxBuffer(fixed, resolveGenerationDate(options));
|
|
7327
|
+
}
|
|
7328
|
+
|
|
7221
7329
|
// src/json/parser.ts
|
|
7222
7330
|
import {
|
|
7223
7331
|
JsonDocumentParser,
|
|
@@ -7375,7 +7483,7 @@ function isReportComponentDefinition(definition) {
|
|
|
7375
7483
|
return false;
|
|
7376
7484
|
}
|
|
7377
7485
|
const def = definition;
|
|
7378
|
-
return def.name === "docx"
|
|
7486
|
+
return def.name === "docx";
|
|
7379
7487
|
}
|
|
7380
7488
|
async function generateDocument(document, options) {
|
|
7381
7489
|
if (!document || document.name !== "docx") {
|
|
@@ -7389,7 +7497,8 @@ async function generateDocument(document, options) {
|
|
|
7389
7497
|
options?.customThemes,
|
|
7390
7498
|
options?.services,
|
|
7391
7499
|
options?.fonts,
|
|
7392
|
-
options?.warnings
|
|
7500
|
+
options?.warnings,
|
|
7501
|
+
resolveGenerationDate(options)
|
|
7393
7502
|
);
|
|
7394
7503
|
}
|
|
7395
7504
|
async function generateFromConfig(props, components, options) {
|
|
@@ -7400,8 +7509,8 @@ async function generateFromConfig(props, components, options) {
|
|
|
7400
7509
|
};
|
|
7401
7510
|
return await generateDocument(reportComponent, options);
|
|
7402
7511
|
}
|
|
7403
|
-
async function generateDocumentWithCustomThemes(documentIn, customThemes, services, fonts, warnings) {
|
|
7404
|
-
let document = documentIn;
|
|
7512
|
+
async function generateDocumentWithCustomThemes(documentIn, customThemes, services, fonts, warnings, generationDate) {
|
|
7513
|
+
let document = documentIn.props === void 0 ? { ...documentIn, props: {} } : documentIn;
|
|
7405
7514
|
let themeName = document.props.theme || "minimal";
|
|
7406
7515
|
let theme;
|
|
7407
7516
|
if (customThemes) {
|
|
@@ -7438,7 +7547,12 @@ async function generateDocumentWithCustomThemes(documentIn, customThemes, servic
|
|
|
7438
7547
|
}
|
|
7439
7548
|
}
|
|
7440
7549
|
await resolveDocumentFonts(document, theme, fonts, warnings);
|
|
7441
|
-
const structure = await processDocument(
|
|
7550
|
+
const structure = await processDocument(
|
|
7551
|
+
document,
|
|
7552
|
+
theme,
|
|
7553
|
+
themeName,
|
|
7554
|
+
generationDate
|
|
7555
|
+
);
|
|
7442
7556
|
const layout = applyLayout(structure.sections, theme, themeName);
|
|
7443
7557
|
const renderedDocument = await renderDocument(structure, layout, {
|
|
7444
7558
|
bypassCache: false,
|
|
@@ -7486,7 +7600,8 @@ async function generateDocumentFromJson(jsonConfig, options) {
|
|
|
7486
7600
|
options?.customThemes,
|
|
7487
7601
|
options?.services,
|
|
7488
7602
|
options?.fonts,
|
|
7489
|
-
options?.warnings
|
|
7603
|
+
options?.warnings,
|
|
7604
|
+
resolveGenerationDate(options)
|
|
7490
7605
|
);
|
|
7491
7606
|
}
|
|
7492
7607
|
function validateJsonSchema(jsonConfig) {
|
|
@@ -7494,11 +7609,11 @@ function validateJsonSchema(jsonConfig) {
|
|
|
7494
7609
|
}
|
|
7495
7610
|
async function generateBufferFromJson(jsonConfig, options) {
|
|
7496
7611
|
const document = await generateDocumentFromJson(jsonConfig, options);
|
|
7497
|
-
return
|
|
7612
|
+
return packageDocument(document, options);
|
|
7498
7613
|
}
|
|
7499
7614
|
async function generateAndSaveFromJson(jsonConfig, filename, options) {
|
|
7500
7615
|
const document = await generateDocumentFromJson(jsonConfig, options);
|
|
7501
|
-
await saveDocument(document, filename);
|
|
7616
|
+
await saveDocument(document, filename, options);
|
|
7502
7617
|
}
|
|
7503
7618
|
async function generateDocumentFromFile(filePath, options) {
|
|
7504
7619
|
const jsonDefinition = await loadJsonDefinition(filePath);
|
|
@@ -7506,25 +7621,19 @@ async function generateDocumentFromFile(filePath, options) {
|
|
|
7506
7621
|
}
|
|
7507
7622
|
async function generateBufferFromFile(filePath, options) {
|
|
7508
7623
|
const document = await generateDocumentFromFile(filePath, options);
|
|
7509
|
-
return
|
|
7624
|
+
return packageDocument(document, options);
|
|
7510
7625
|
}
|
|
7511
7626
|
async function generateAndSaveFromFile(inputFilePath, outputFilePath, options) {
|
|
7512
7627
|
const document = await generateDocumentFromFile(inputFilePath, options);
|
|
7513
|
-
await saveDocument(document, outputFilePath);
|
|
7628
|
+
await saveDocument(document, outputFilePath, options);
|
|
7514
7629
|
}
|
|
7515
|
-
async function saveDocument(document, filename) {
|
|
7516
|
-
const buffer = await
|
|
7630
|
+
async function saveDocument(document, filename, options) {
|
|
7631
|
+
const buffer = await packageDocument(document, options);
|
|
7517
7632
|
writeFileSync(filename, buffer);
|
|
7518
|
-
try {
|
|
7519
|
-
const { fixFloatingImageIds: fixFloatingImageIds2 } = await Promise.resolve().then(() => (init_fixFloatingImageIds(), fixFloatingImageIds_exports));
|
|
7520
|
-
await fixFloatingImageIds2(filename);
|
|
7521
|
-
} catch (error) {
|
|
7522
|
-
console.warn("Failed to fix floating image IDs (non-critical):", error);
|
|
7523
|
-
}
|
|
7524
7633
|
}
|
|
7525
|
-
async function generateAndSave(document, filename) {
|
|
7526
|
-
const generatedDocument = await generateDocument(document);
|
|
7527
|
-
await saveDocument(generatedDocument, filename);
|
|
7634
|
+
async function generateAndSave(document, filename, options) {
|
|
7635
|
+
const generatedDocument = await generateDocument(document, options);
|
|
7636
|
+
await saveDocument(generatedDocument, filename, options);
|
|
7528
7637
|
}
|
|
7529
7638
|
var DocumentGenerator = {
|
|
7530
7639
|
generate: generateDocument,
|
|
@@ -7854,7 +7963,6 @@ async function runExample(example, options = {}) {
|
|
|
7854
7963
|
|
|
7855
7964
|
// src/plugin/createDocumentGenerator.ts
|
|
7856
7965
|
init_styles();
|
|
7857
|
-
import { Packer as Packer2 } from "docx";
|
|
7858
7966
|
import { applyExportMode as applyExportMode2, scopedThemeName as scopedThemeName2 } from "@json-to-office/shared";
|
|
7859
7967
|
|
|
7860
7968
|
// src/plugin/version-resolver.ts
|
|
@@ -8251,7 +8359,10 @@ function createBuilderImpl(state) {
|
|
|
8251
8359
|
debug: state.debug,
|
|
8252
8360
|
enableCache: state.enableCache,
|
|
8253
8361
|
services: state.services,
|
|
8254
|
-
fonts: state.fonts
|
|
8362
|
+
fonts: state.fonts,
|
|
8363
|
+
validation: state.validation,
|
|
8364
|
+
deterministic: state.deterministic,
|
|
8365
|
+
generatedAt: state.generatedAt
|
|
8255
8366
|
};
|
|
8256
8367
|
return createBuilderImpl(
|
|
8257
8368
|
newState
|
|
@@ -8275,7 +8386,8 @@ function createBuilderImpl(state) {
|
|
|
8275
8386
|
async function generate(document, options) {
|
|
8276
8387
|
try {
|
|
8277
8388
|
const preserveSet = resolvePreserveSet(options);
|
|
8278
|
-
const
|
|
8389
|
+
const rootIn = document;
|
|
8390
|
+
const internalDocument = rootIn.props === void 0 ? { ...rootIn, props: {} } : rootIn;
|
|
8279
8391
|
const vOpts = {
|
|
8280
8392
|
...state.validation,
|
|
8281
8393
|
...options?.validation
|
|
@@ -8343,10 +8455,20 @@ function createBuilderImpl(state) {
|
|
|
8343
8455
|
};
|
|
8344
8456
|
const [modedDoc] = normalizeDocument(processedDocument);
|
|
8345
8457
|
await resolveDocumentFonts(modedDoc, modedTheme, state.fonts, warnings);
|
|
8346
|
-
const
|
|
8458
|
+
const packageOptions = {
|
|
8459
|
+
deterministic: options?.deterministic ?? state.deterministic,
|
|
8460
|
+
generatedAt: options?.generatedAt ?? state.generatedAt
|
|
8461
|
+
};
|
|
8462
|
+
const structure = await processDocument(
|
|
8463
|
+
modedDoc,
|
|
8464
|
+
modedTheme,
|
|
8465
|
+
themeName,
|
|
8466
|
+
resolveGenerationDate(packageOptions)
|
|
8467
|
+
);
|
|
8347
8468
|
const layout = applyLayout(structure.sections, modedTheme, themeName);
|
|
8348
8469
|
const generatedDocument = await renderDocument(structure, layout, {
|
|
8349
|
-
services: state.services
|
|
8470
|
+
services: state.services,
|
|
8471
|
+
bypassCache: !state.enableCache
|
|
8350
8472
|
});
|
|
8351
8473
|
const preservedDefinition = preserveSet ? {
|
|
8352
8474
|
...mode.doc,
|
|
@@ -8372,7 +8494,10 @@ function createBuilderImpl(state) {
|
|
|
8372
8494
|
standardDefinition,
|
|
8373
8495
|
preservedDefinition
|
|
8374
8496
|
} = await generate(document, options);
|
|
8375
|
-
const buffer = await
|
|
8497
|
+
const buffer = await packageDocument(doc, {
|
|
8498
|
+
deterministic: options?.deterministic ?? state.deterministic,
|
|
8499
|
+
generatedAt: options?.generatedAt ?? state.generatedAt
|
|
8500
|
+
});
|
|
8376
8501
|
return { buffer, warnings, standardDefinition, preservedDefinition };
|
|
8377
8502
|
}
|
|
8378
8503
|
async function generateFile(document, outputPath, options) {
|
|
@@ -8471,7 +8596,9 @@ function createDocumentGenerator(options) {
|
|
|
8471
8596
|
enableCache: options.enableCache ?? false,
|
|
8472
8597
|
services: options.services,
|
|
8473
8598
|
fonts: options.fonts,
|
|
8474
|
-
validation: options.validation
|
|
8599
|
+
validation: options.validation,
|
|
8600
|
+
deterministic: options.deterministic ?? true,
|
|
8601
|
+
generatedAt: options.generatedAt
|
|
8475
8602
|
};
|
|
8476
8603
|
return createBuilderImpl(initialState);
|
|
8477
8604
|
}
|