@json-to-office/core-docx 0.25.0 → 0.27.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/core/generationContext.d.ts +6 -3
- package/dist/core/generationContext.d.ts.map +1 -1
- package/dist/index.js +96 -122
- package/dist/index.js.map +1 -1
- package/dist/plugin/createDocumentGenerator.d.ts.map +1 -1
- package/dist/plugin/example/index.js +96 -122
- package/dist/plugin/example/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/placeholderProcessor.d.ts.map +1 -1
- package/dist/utils/textParser.d.ts +37 -0
- package/dist/utils/textParser.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -23,10 +23,13 @@ export interface ThemeContextOptions {
|
|
|
23
23
|
warnings?: GenerationWarning[];
|
|
24
24
|
/**
|
|
25
25
|
* Theme lookup for the base `props.theme` name. The plugin builder passes
|
|
26
|
-
* its own (customThemes →
|
|
27
|
-
* use customThemes → built-in.
|
|
26
|
+
* its own (customThemes → doc-named built-in → constructor-supplied theme →
|
|
27
|
+
* built-in); omit it to use customThemes → built-in. `authored` is true when
|
|
28
|
+
* the name came from the document's own `props.theme` (not the 'minimal'
|
|
29
|
+
* fallback), so the lookup can honor an explicitly doc-named built-in
|
|
30
|
+
* without the constructor theme being shadowed for unnamed docs (#141).
|
|
28
31
|
*/
|
|
29
|
-
resolveNamedTheme?: (name: string, warnings
|
|
32
|
+
resolveNamedTheme?: (name: string, warnings: GenerationWarning[] | undefined, authored: boolean) => ThemeConfig;
|
|
30
33
|
}
|
|
31
34
|
export interface GenerationThemeContext {
|
|
32
35
|
/** The document after the export-mode pre-pass rewrote font references. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generationContext.d.ts","sourceRoot":"","sources":["../../src/core/generationContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,UAAU,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kExB"}
|
package/dist/index.js
CHANGED
|
@@ -2008,8 +2008,13 @@ function resolveThemeContext(documentIn, options = {}) {
|
|
|
2008
2008
|
);
|
|
2009
2009
|
}
|
|
2010
2010
|
const document = documentIn.props === void 0 ? { ...documentIn, props: {} } : documentIn;
|
|
2011
|
-
const
|
|
2012
|
-
|
|
2011
|
+
const authoredThemeName = document.props.theme || void 0;
|
|
2012
|
+
const baseThemeName = authoredThemeName ?? "minimal";
|
|
2013
|
+
let theme = resolveNamedTheme ? resolveNamedTheme(
|
|
2014
|
+
baseThemeName,
|
|
2015
|
+
warnings,
|
|
2016
|
+
authoredThemeName !== void 0
|
|
2017
|
+
) : defaultNamedThemeLookup(baseThemeName, customThemes, warnings);
|
|
2013
2018
|
const themeOverrides = document.props.themeOverrides;
|
|
2014
2019
|
let themeName = baseThemeName;
|
|
2015
2020
|
if (themeOverrides) {
|
|
@@ -3686,8 +3691,7 @@ function normalizeUnicodeText(text) {
|
|
|
3686
3691
|
// src/utils/placeholderProcessor.ts
|
|
3687
3692
|
import {
|
|
3688
3693
|
TextRun as TextRun2,
|
|
3689
|
-
PageNumber
|
|
3690
|
-
Tab as Tab2
|
|
3694
|
+
PageNumber
|
|
3691
3695
|
} from "docx";
|
|
3692
3696
|
|
|
3693
3697
|
// src/utils/textParser.ts
|
|
@@ -3794,74 +3798,90 @@ function parseTextWithDecorators(text, baseStyle = {}, options = {}) {
|
|
|
3794
3798
|
}
|
|
3795
3799
|
return runs;
|
|
3796
3800
|
}
|
|
3797
|
-
function
|
|
3801
|
+
function buildRunCommonProps(baseStyle, overrides) {
|
|
3802
|
+
const bold = overrides?.bold ?? baseStyle.bold;
|
|
3803
|
+
const italics = overrides?.italics ?? baseStyle.italics;
|
|
3804
|
+
return {
|
|
3805
|
+
...baseStyle.font && { font: baseStyle.font },
|
|
3806
|
+
...baseStyle.size && { size: baseStyle.size },
|
|
3807
|
+
...baseStyle.color && {
|
|
3808
|
+
color: bold && overrides?.boldColor ? overrides.boldColor : baseStyle.color
|
|
3809
|
+
},
|
|
3810
|
+
...bold !== void 0 && { bold },
|
|
3811
|
+
...italics !== void 0 && { italics },
|
|
3812
|
+
...baseStyle.underline && { underline: baseStyle.underline },
|
|
3813
|
+
...baseStyle.scale && { scale: baseStyle.scale },
|
|
3814
|
+
...baseStyle.characterSpacing && {
|
|
3815
|
+
characterSpacing: baseStyle.characterSpacing
|
|
3816
|
+
},
|
|
3817
|
+
...baseStyle.language && { language: baseStyle.language }
|
|
3818
|
+
};
|
|
3819
|
+
}
|
|
3820
|
+
function buildLineRuns(line, commonProps, opts) {
|
|
3821
|
+
const { needsLineBreak, noProof } = opts;
|
|
3822
|
+
const wholeRunNoProof = noProof === true;
|
|
3823
|
+
const wordsForLine = wholeRunNoProof ? void 0 : opts.noProofWords;
|
|
3824
|
+
let firstSegment = true;
|
|
3825
|
+
const lineRuns = [];
|
|
3826
|
+
const tabSegments = line.split(" ");
|
|
3827
|
+
tabSegments.forEach((tabSegment, tabIndex) => {
|
|
3828
|
+
if (tabIndex > 0) {
|
|
3829
|
+
lineRuns.push(
|
|
3830
|
+
new TextRun({
|
|
3831
|
+
children: [new Tab()],
|
|
3832
|
+
...commonProps,
|
|
3833
|
+
...needsLineBreak && firstSegment && { break: 1 }
|
|
3834
|
+
})
|
|
3835
|
+
);
|
|
3836
|
+
firstSegment = false;
|
|
3837
|
+
}
|
|
3838
|
+
if (!tabSegment && tabSegments.length > 1) return;
|
|
3839
|
+
lineRuns.push(
|
|
3840
|
+
...splitByNoProofWords(
|
|
3841
|
+
tabSegment,
|
|
3842
|
+
(segment, matched) => {
|
|
3843
|
+
const run = new TextRun({
|
|
3844
|
+
text: segment,
|
|
3845
|
+
...commonProps,
|
|
3846
|
+
...(matched || noProof !== void 0) && {
|
|
3847
|
+
noProof: matched || wholeRunNoProof
|
|
3848
|
+
},
|
|
3849
|
+
...needsLineBreak && firstSegment && { break: 1 }
|
|
3850
|
+
});
|
|
3851
|
+
firstSegment = false;
|
|
3852
|
+
return run;
|
|
3853
|
+
},
|
|
3854
|
+
wordsForLine
|
|
3855
|
+
)
|
|
3856
|
+
);
|
|
3857
|
+
});
|
|
3858
|
+
return lineRuns;
|
|
3859
|
+
}
|
|
3860
|
+
function buildTextRuns(text, commonProps, opts = {}) {
|
|
3798
3861
|
const runs = [];
|
|
3799
3862
|
const lines = text.split("\n");
|
|
3800
3863
|
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
3801
3864
|
const line = lines[lineIndex];
|
|
3802
3865
|
const needsLineBreak = lineIndex > 0;
|
|
3803
3866
|
if (line || needsLineBreak) {
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
};
|
|
3808
|
-
const commonProps = {
|
|
3809
|
-
...baseStyle.font && { font: baseStyle.font },
|
|
3810
|
-
...baseStyle.size && { size: baseStyle.size },
|
|
3811
|
-
...baseStyle.color && {
|
|
3812
|
-
color: runStyle.bold && options.boldColor ? options.boldColor : baseStyle.color
|
|
3813
|
-
},
|
|
3814
|
-
...runStyle.bold !== void 0 && { bold: runStyle.bold },
|
|
3815
|
-
...runStyle.italics !== void 0 && { italics: runStyle.italics },
|
|
3816
|
-
...baseStyle.underline && { underline: baseStyle.underline },
|
|
3817
|
-
...baseStyle.scale && { scale: baseStyle.scale },
|
|
3818
|
-
...baseStyle.characterSpacing && {
|
|
3819
|
-
characterSpacing: baseStyle.characterSpacing
|
|
3820
|
-
},
|
|
3821
|
-
...baseStyle.language && { language: baseStyle.language }
|
|
3822
|
-
};
|
|
3823
|
-
const wholeRunNoProof = baseStyle.noProof === true;
|
|
3824
|
-
const wordsForLine = wholeRunNoProof ? void 0 : options.noProofWords;
|
|
3825
|
-
let firstSegment = true;
|
|
3826
|
-
const lineRuns = [];
|
|
3827
|
-
const tabSegments = line.split(" ");
|
|
3828
|
-
tabSegments.forEach((tabSegment, tabIndex) => {
|
|
3829
|
-
if (tabIndex > 0) {
|
|
3830
|
-
lineRuns.push(
|
|
3831
|
-
new TextRun({
|
|
3832
|
-
children: [new Tab()],
|
|
3833
|
-
...commonProps,
|
|
3834
|
-
...needsLineBreak && firstSegment && { break: 1 }
|
|
3835
|
-
})
|
|
3836
|
-
);
|
|
3837
|
-
firstSegment = false;
|
|
3838
|
-
}
|
|
3839
|
-
if (!tabSegment && tabSegments.length > 1) return;
|
|
3840
|
-
lineRuns.push(
|
|
3841
|
-
...splitByNoProofWords(
|
|
3842
|
-
tabSegment,
|
|
3843
|
-
(segment, matched) => {
|
|
3844
|
-
const segNoProof = matched || wholeRunNoProof;
|
|
3845
|
-
const run = new TextRun({
|
|
3846
|
-
text: segment,
|
|
3847
|
-
...commonProps,
|
|
3848
|
-
...(matched || baseStyle.noProof !== void 0) && {
|
|
3849
|
-
noProof: segNoProof
|
|
3850
|
-
},
|
|
3851
|
-
...needsLineBreak && firstSegment && { break: 1 }
|
|
3852
|
-
});
|
|
3853
|
-
firstSegment = false;
|
|
3854
|
-
return run;
|
|
3855
|
-
},
|
|
3856
|
-
wordsForLine
|
|
3857
|
-
)
|
|
3858
|
-
);
|
|
3859
|
-
});
|
|
3860
|
-
runs.push(...lineRuns);
|
|
3867
|
+
runs.push(
|
|
3868
|
+
...buildLineRuns(line, commonProps, { needsLineBreak, ...opts })
|
|
3869
|
+
);
|
|
3861
3870
|
}
|
|
3862
3871
|
}
|
|
3863
3872
|
return runs;
|
|
3864
3873
|
}
|
|
3874
|
+
function createTextRunsWithNewlines(text, baseStyle, options, overrideStyle) {
|
|
3875
|
+
return buildTextRuns(
|
|
3876
|
+
text,
|
|
3877
|
+
buildRunCommonProps(baseStyle, {
|
|
3878
|
+
bold: overrideStyle?.bold,
|
|
3879
|
+
italics: overrideStyle?.italics,
|
|
3880
|
+
boldColor: options.boldColor
|
|
3881
|
+
}),
|
|
3882
|
+
{ noProof: baseStyle.noProof, noProofWords: options.noProofWords }
|
|
3883
|
+
);
|
|
3884
|
+
}
|
|
3865
3885
|
function parseTextWithHyperlinks(text, baseStyle = {}, options = {}) {
|
|
3866
3886
|
const normalizedText = normalizeUnicodeText(text);
|
|
3867
3887
|
const runs = [];
|
|
@@ -4078,65 +4098,10 @@ function processTextWithPlaceholders(text, baseStyle = {}, context = {}, noProof
|
|
|
4078
4098
|
return result;
|
|
4079
4099
|
}
|
|
4080
4100
|
function createTextRunsWithNewlines2(text, baseStyle, noProofWords) {
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
const needsLineBreak = lineIndex > 0;
|
|
4086
|
-
if (line || needsLineBreak) {
|
|
4087
|
-
const commonProps = {
|
|
4088
|
-
font: baseStyle.font,
|
|
4089
|
-
size: baseStyle.size,
|
|
4090
|
-
color: baseStyle.color,
|
|
4091
|
-
bold: baseStyle.bold,
|
|
4092
|
-
italics: baseStyle.italics,
|
|
4093
|
-
underline: baseStyle.underline,
|
|
4094
|
-
...baseStyle.scale && { scale: baseStyle.scale },
|
|
4095
|
-
...baseStyle.characterSpacing && {
|
|
4096
|
-
characterSpacing: baseStyle.characterSpacing
|
|
4097
|
-
},
|
|
4098
|
-
...baseStyle.language && { language: baseStyle.language }
|
|
4099
|
-
};
|
|
4100
|
-
const wholeRunNoProof = baseStyle.noProof === true;
|
|
4101
|
-
const wordsForLine = wholeRunNoProof ? void 0 : noProofWords;
|
|
4102
|
-
let firstSegment = true;
|
|
4103
|
-
const lineRuns = [];
|
|
4104
|
-
const tabSegments = line.split(" ");
|
|
4105
|
-
tabSegments.forEach((tabSegment, tabIndex) => {
|
|
4106
|
-
if (tabIndex > 0) {
|
|
4107
|
-
lineRuns.push(
|
|
4108
|
-
new TextRun2({
|
|
4109
|
-
children: [new Tab2()],
|
|
4110
|
-
...commonProps,
|
|
4111
|
-
break: needsLineBreak && firstSegment ? 1 : void 0
|
|
4112
|
-
})
|
|
4113
|
-
);
|
|
4114
|
-
firstSegment = false;
|
|
4115
|
-
}
|
|
4116
|
-
if (!tabSegment && tabSegments.length > 1) return;
|
|
4117
|
-
lineRuns.push(
|
|
4118
|
-
...splitByNoProofWords(
|
|
4119
|
-
tabSegment,
|
|
4120
|
-
(segment, matched) => {
|
|
4121
|
-
const run = new TextRun2({
|
|
4122
|
-
text: segment,
|
|
4123
|
-
...commonProps,
|
|
4124
|
-
...(matched || baseStyle.noProof !== void 0) && {
|
|
4125
|
-
noProof: matched || wholeRunNoProof
|
|
4126
|
-
},
|
|
4127
|
-
break: needsLineBreak && firstSegment ? 1 : void 0
|
|
4128
|
-
});
|
|
4129
|
-
firstSegment = false;
|
|
4130
|
-
return run;
|
|
4131
|
-
},
|
|
4132
|
-
wordsForLine
|
|
4133
|
-
)
|
|
4134
|
-
);
|
|
4135
|
-
});
|
|
4136
|
-
runs.push(...lineRuns);
|
|
4137
|
-
}
|
|
4138
|
-
}
|
|
4139
|
-
return runs;
|
|
4101
|
+
return buildTextRuns(text, buildRunCommonProps(baseStyle), {
|
|
4102
|
+
noProof: baseStyle.noProof,
|
|
4103
|
+
noProofWords
|
|
4104
|
+
});
|
|
4140
4105
|
}
|
|
4141
4106
|
function initializeBuiltinPlaceholders() {
|
|
4142
4107
|
PlaceholderRegistry.register("PAGE", (context) => {
|
|
@@ -8332,6 +8297,9 @@ async function runExample(example, options = {}) {
|
|
|
8332
8297
|
}
|
|
8333
8298
|
}
|
|
8334
8299
|
|
|
8300
|
+
// src/plugin/createDocumentGenerator.ts
|
|
8301
|
+
init_themes();
|
|
8302
|
+
|
|
8335
8303
|
// src/plugin/version-resolver.ts
|
|
8336
8304
|
import { resolveComponentVersion } from "@json-to-office/shared/plugin";
|
|
8337
8305
|
|
|
@@ -8574,7 +8542,7 @@ function mergeSchemas(customComponents, standardSchemas) {
|
|
|
8574
8542
|
// src/plugin/createDocumentGenerator.ts
|
|
8575
8543
|
function createBuilderImpl(state) {
|
|
8576
8544
|
const componentMap = new Map(state.components.map((c) => [c.name, c]));
|
|
8577
|
-
function resolveDocumentTheme(themeName, warnings) {
|
|
8545
|
+
function resolveDocumentTheme(themeName, warnings, authored) {
|
|
8578
8546
|
if (state.customThemes) {
|
|
8579
8547
|
if (state.customThemes[themeName]) {
|
|
8580
8548
|
return state.customThemes[themeName];
|
|
@@ -8586,6 +8554,12 @@ function createBuilderImpl(state) {
|
|
|
8586
8554
|
return state.customThemes[key];
|
|
8587
8555
|
}
|
|
8588
8556
|
}
|
|
8557
|
+
if (authored && hasTheme(themeName)) {
|
|
8558
|
+
return resolveBuiltInTheme(themeName, {
|
|
8559
|
+
customThemes: state.customThemes,
|
|
8560
|
+
warnings
|
|
8561
|
+
});
|
|
8562
|
+
}
|
|
8589
8563
|
if (state.theme) {
|
|
8590
8564
|
return state.theme;
|
|
8591
8565
|
}
|