@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.
@@ -1 +1 @@
1
- {"version":3,"file":"createDocumentGenerator.d.ts","sourceRoot":"","sources":["../../src/plugin/createDocumentGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAI7C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9E,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;AAqnBD;;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;AAK7C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9E,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;AAsoBD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,wBAAwB,CAAC,SAAS,EAAE,CAAC,CAgBvC"}
@@ -1915,6 +1915,9 @@ function resolveBuiltInTheme(themeName, options = {}) {
1915
1915
  return getThemeWithFallback(themeName);
1916
1916
  }
1917
1917
 
1918
+ // src/plugin/createDocumentGenerator.ts
1919
+ init_themes();
1920
+
1918
1921
  // src/core/generationContext.ts
1919
1922
  import { applyExportMode, scopedThemeName } from "@json-to-office/shared";
1920
1923
 
@@ -1963,8 +1966,13 @@ function resolveThemeContext(documentIn, options = {}) {
1963
1966
  );
1964
1967
  }
1965
1968
  const document = documentIn.props === void 0 ? { ...documentIn, props: {} } : documentIn;
1966
- const baseThemeName = document.props.theme || "minimal";
1967
- let theme = resolveNamedTheme ? resolveNamedTheme(baseThemeName, warnings) : defaultNamedThemeLookup(baseThemeName, customThemes, warnings);
1969
+ const authoredThemeName = document.props.theme || void 0;
1970
+ const baseThemeName = authoredThemeName ?? "minimal";
1971
+ let theme = resolveNamedTheme ? resolveNamedTheme(
1972
+ baseThemeName,
1973
+ warnings,
1974
+ authoredThemeName !== void 0
1975
+ ) : defaultNamedThemeLookup(baseThemeName, customThemes, warnings);
1968
1976
  const themeOverrides = document.props.themeOverrides;
1969
1977
  let themeName = baseThemeName;
1970
1978
  if (themeOverrides) {
@@ -3855,8 +3863,7 @@ function normalizeUnicodeText(text) {
3855
3863
  // src/utils/placeholderProcessor.ts
3856
3864
  import {
3857
3865
  TextRun as TextRun2,
3858
- PageNumber,
3859
- Tab as Tab2
3866
+ PageNumber
3860
3867
  } from "docx";
3861
3868
 
3862
3869
  // src/utils/textParser.ts
@@ -3963,74 +3970,90 @@ function parseTextWithDecorators(text, baseStyle = {}, options = {}) {
3963
3970
  }
3964
3971
  return runs;
3965
3972
  }
3966
- function createTextRunsWithNewlines(text, baseStyle, options, overrideStyle) {
3973
+ function buildRunCommonProps(baseStyle, overrides) {
3974
+ const bold = overrides?.bold ?? baseStyle.bold;
3975
+ const italics = overrides?.italics ?? baseStyle.italics;
3976
+ return {
3977
+ ...baseStyle.font && { font: baseStyle.font },
3978
+ ...baseStyle.size && { size: baseStyle.size },
3979
+ ...baseStyle.color && {
3980
+ color: bold && overrides?.boldColor ? overrides.boldColor : baseStyle.color
3981
+ },
3982
+ ...bold !== void 0 && { bold },
3983
+ ...italics !== void 0 && { italics },
3984
+ ...baseStyle.underline && { underline: baseStyle.underline },
3985
+ ...baseStyle.scale && { scale: baseStyle.scale },
3986
+ ...baseStyle.characterSpacing && {
3987
+ characterSpacing: baseStyle.characterSpacing
3988
+ },
3989
+ ...baseStyle.language && { language: baseStyle.language }
3990
+ };
3991
+ }
3992
+ function buildLineRuns(line, commonProps, opts) {
3993
+ const { needsLineBreak, noProof } = opts;
3994
+ const wholeRunNoProof = noProof === true;
3995
+ const wordsForLine = wholeRunNoProof ? void 0 : opts.noProofWords;
3996
+ let firstSegment = true;
3997
+ const lineRuns = [];
3998
+ const tabSegments = line.split(" ");
3999
+ tabSegments.forEach((tabSegment, tabIndex) => {
4000
+ if (tabIndex > 0) {
4001
+ lineRuns.push(
4002
+ new TextRun({
4003
+ children: [new Tab()],
4004
+ ...commonProps,
4005
+ ...needsLineBreak && firstSegment && { break: 1 }
4006
+ })
4007
+ );
4008
+ firstSegment = false;
4009
+ }
4010
+ if (!tabSegment && tabSegments.length > 1) return;
4011
+ lineRuns.push(
4012
+ ...splitByNoProofWords(
4013
+ tabSegment,
4014
+ (segment, matched) => {
4015
+ const run = new TextRun({
4016
+ text: segment,
4017
+ ...commonProps,
4018
+ ...(matched || noProof !== void 0) && {
4019
+ noProof: matched || wholeRunNoProof
4020
+ },
4021
+ ...needsLineBreak && firstSegment && { break: 1 }
4022
+ });
4023
+ firstSegment = false;
4024
+ return run;
4025
+ },
4026
+ wordsForLine
4027
+ )
4028
+ );
4029
+ });
4030
+ return lineRuns;
4031
+ }
4032
+ function buildTextRuns(text, commonProps, opts = {}) {
3967
4033
  const runs = [];
3968
4034
  const lines = text.split("\n");
3969
4035
  for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
3970
4036
  const line = lines[lineIndex];
3971
4037
  const needsLineBreak = lineIndex > 0;
3972
4038
  if (line || needsLineBreak) {
3973
- const runStyle = {
3974
- bold: overrideStyle?.bold ?? baseStyle.bold,
3975
- italics: overrideStyle?.italics ?? baseStyle.italics
3976
- };
3977
- const commonProps = {
3978
- ...baseStyle.font && { font: baseStyle.font },
3979
- ...baseStyle.size && { size: baseStyle.size },
3980
- ...baseStyle.color && {
3981
- color: runStyle.bold && options.boldColor ? options.boldColor : baseStyle.color
3982
- },
3983
- ...runStyle.bold !== void 0 && { bold: runStyle.bold },
3984
- ...runStyle.italics !== void 0 && { italics: runStyle.italics },
3985
- ...baseStyle.underline && { underline: baseStyle.underline },
3986
- ...baseStyle.scale && { scale: baseStyle.scale },
3987
- ...baseStyle.characterSpacing && {
3988
- characterSpacing: baseStyle.characterSpacing
3989
- },
3990
- ...baseStyle.language && { language: baseStyle.language }
3991
- };
3992
- const wholeRunNoProof = baseStyle.noProof === true;
3993
- const wordsForLine = wholeRunNoProof ? void 0 : options.noProofWords;
3994
- let firstSegment = true;
3995
- const lineRuns = [];
3996
- const tabSegments = line.split(" ");
3997
- tabSegments.forEach((tabSegment, tabIndex) => {
3998
- if (tabIndex > 0) {
3999
- lineRuns.push(
4000
- new TextRun({
4001
- children: [new Tab()],
4002
- ...commonProps,
4003
- ...needsLineBreak && firstSegment && { break: 1 }
4004
- })
4005
- );
4006
- firstSegment = false;
4007
- }
4008
- if (!tabSegment && tabSegments.length > 1) return;
4009
- lineRuns.push(
4010
- ...splitByNoProofWords(
4011
- tabSegment,
4012
- (segment, matched) => {
4013
- const segNoProof = matched || wholeRunNoProof;
4014
- const run = new TextRun({
4015
- text: segment,
4016
- ...commonProps,
4017
- ...(matched || baseStyle.noProof !== void 0) && {
4018
- noProof: segNoProof
4019
- },
4020
- ...needsLineBreak && firstSegment && { break: 1 }
4021
- });
4022
- firstSegment = false;
4023
- return run;
4024
- },
4025
- wordsForLine
4026
- )
4027
- );
4028
- });
4029
- runs.push(...lineRuns);
4039
+ runs.push(
4040
+ ...buildLineRuns(line, commonProps, { needsLineBreak, ...opts })
4041
+ );
4030
4042
  }
4031
4043
  }
4032
4044
  return runs;
4033
4045
  }
4046
+ function createTextRunsWithNewlines(text, baseStyle, options, overrideStyle) {
4047
+ return buildTextRuns(
4048
+ text,
4049
+ buildRunCommonProps(baseStyle, {
4050
+ bold: overrideStyle?.bold,
4051
+ italics: overrideStyle?.italics,
4052
+ boldColor: options.boldColor
4053
+ }),
4054
+ { noProof: baseStyle.noProof, noProofWords: options.noProofWords }
4055
+ );
4056
+ }
4034
4057
  function parseTextWithHyperlinks(text, baseStyle = {}, options = {}) {
4035
4058
  const normalizedText = normalizeUnicodeText(text);
4036
4059
  const runs = [];
@@ -4247,65 +4270,10 @@ function processTextWithPlaceholders(text, baseStyle = {}, context = {}, noProof
4247
4270
  return result;
4248
4271
  }
4249
4272
  function createTextRunsWithNewlines2(text, baseStyle, noProofWords) {
4250
- const runs = [];
4251
- const lines = text.split("\n");
4252
- for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
4253
- const line = lines[lineIndex];
4254
- const needsLineBreak = lineIndex > 0;
4255
- if (line || needsLineBreak) {
4256
- const commonProps = {
4257
- font: baseStyle.font,
4258
- size: baseStyle.size,
4259
- color: baseStyle.color,
4260
- bold: baseStyle.bold,
4261
- italics: baseStyle.italics,
4262
- underline: baseStyle.underline,
4263
- ...baseStyle.scale && { scale: baseStyle.scale },
4264
- ...baseStyle.characterSpacing && {
4265
- characterSpacing: baseStyle.characterSpacing
4266
- },
4267
- ...baseStyle.language && { language: baseStyle.language }
4268
- };
4269
- const wholeRunNoProof = baseStyle.noProof === true;
4270
- const wordsForLine = wholeRunNoProof ? void 0 : noProofWords;
4271
- let firstSegment = true;
4272
- const lineRuns = [];
4273
- const tabSegments = line.split(" ");
4274
- tabSegments.forEach((tabSegment, tabIndex) => {
4275
- if (tabIndex > 0) {
4276
- lineRuns.push(
4277
- new TextRun2({
4278
- children: [new Tab2()],
4279
- ...commonProps,
4280
- break: needsLineBreak && firstSegment ? 1 : void 0
4281
- })
4282
- );
4283
- firstSegment = false;
4284
- }
4285
- if (!tabSegment && tabSegments.length > 1) return;
4286
- lineRuns.push(
4287
- ...splitByNoProofWords(
4288
- tabSegment,
4289
- (segment, matched) => {
4290
- const run = new TextRun2({
4291
- text: segment,
4292
- ...commonProps,
4293
- ...(matched || baseStyle.noProof !== void 0) && {
4294
- noProof: matched || wholeRunNoProof
4295
- },
4296
- break: needsLineBreak && firstSegment ? 1 : void 0
4297
- });
4298
- firstSegment = false;
4299
- return run;
4300
- },
4301
- wordsForLine
4302
- )
4303
- );
4304
- });
4305
- runs.push(...lineRuns);
4306
- }
4307
- }
4308
- return runs;
4273
+ return buildTextRuns(text, buildRunCommonProps(baseStyle), {
4274
+ noProof: baseStyle.noProof,
4275
+ noProofWords
4276
+ });
4309
4277
  }
4310
4278
  function initializeBuiltinPlaceholders() {
4311
4279
  PlaceholderRegistry.register("PAGE", (context) => {
@@ -7877,7 +7845,7 @@ async function packageDocument(document, options) {
7877
7845
  // src/plugin/createDocumentGenerator.ts
7878
7846
  function createBuilderImpl(state) {
7879
7847
  const componentMap = new Map(state.components.map((c) => [c.name, c]));
7880
- function resolveDocumentTheme(themeName, warnings) {
7848
+ function resolveDocumentTheme(themeName, warnings, authored) {
7881
7849
  if (state.customThemes) {
7882
7850
  if (state.customThemes[themeName]) {
7883
7851
  return state.customThemes[themeName];
@@ -7889,6 +7857,12 @@ function createBuilderImpl(state) {
7889
7857
  return state.customThemes[key];
7890
7858
  }
7891
7859
  }
7860
+ if (authored && hasTheme(themeName)) {
7861
+ return resolveBuiltInTheme(themeName, {
7862
+ customThemes: state.customThemes,
7863
+ warnings
7864
+ });
7865
+ }
7892
7866
  if (state.theme) {
7893
7867
  return state.theme;
7894
7868
  }