@json-to-office/core-docx 0.26.1 → 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.
@@ -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 → constructor-supplied themebuilt-in); omit it to
27
- * use customThemes → built-in.
26
+ * its own (customThemes → doc-named built-inconstructor-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?: GenerationWarning[]) => ThemeConfig;
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,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAKhC,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAA;KAAE,CAAC;IAC9C,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,QAAQ,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC/B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CAClB,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,iBAAiB,EAAE,KAC3B,WAAW,CAAC;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC,2EAA2E;IAC3E,QAAQ,EAAE,yBAAyB,CAAC;IACpC,KAAK,EAAE,WAAW,CAAC;IACnB,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAC;CACnB;AAoBD,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,yBAAyB,EACrC,OAAO,GAAE,mBAAwB,GAChC,sBAAsB,CA6DxB"}
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,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAKhC,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAA;KAAE,CAAC;IAC9C,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,QAAQ,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC/B;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,CAClB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,iBAAiB,EAAE,GAAG,SAAS,EACzC,QAAQ,EAAE,OAAO,KACd,WAAW,CAAC;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC,2EAA2E;IAC3E,QAAQ,EAAE,yBAAyB,CAAC;IACpC,KAAK,EAAE,WAAW,CAAC;IACnB,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAC;CACnB;AAoBD,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,yBAAyB,EACrC,OAAO,GAAE,mBAAwB,GAChC,sBAAsB,CAkExB"}
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 baseThemeName = document.props.theme || "minimal";
2012
- let theme = resolveNamedTheme ? resolveNamedTheme(baseThemeName, warnings) : defaultNamedThemeLookup(baseThemeName, customThemes, warnings);
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) {
@@ -8292,6 +8297,9 @@ async function runExample(example, options = {}) {
8292
8297
  }
8293
8298
  }
8294
8299
 
8300
+ // src/plugin/createDocumentGenerator.ts
8301
+ init_themes();
8302
+
8295
8303
  // src/plugin/version-resolver.ts
8296
8304
  import { resolveComponentVersion } from "@json-to-office/shared/plugin";
8297
8305
 
@@ -8534,7 +8542,7 @@ function mergeSchemas(customComponents, standardSchemas) {
8534
8542
  // src/plugin/createDocumentGenerator.ts
8535
8543
  function createBuilderImpl(state) {
8536
8544
  const componentMap = new Map(state.components.map((c) => [c.name, c]));
8537
- function resolveDocumentTheme(themeName, warnings) {
8545
+ function resolveDocumentTheme(themeName, warnings, authored) {
8538
8546
  if (state.customThemes) {
8539
8547
  if (state.customThemes[themeName]) {
8540
8548
  return state.customThemes[themeName];
@@ -8546,6 +8554,12 @@ function createBuilderImpl(state) {
8546
8554
  return state.customThemes[key];
8547
8555
  }
8548
8556
  }
8557
+ if (authored && hasTheme(themeName)) {
8558
+ return resolveBuiltInTheme(themeName, {
8559
+ customThemes: state.customThemes,
8560
+ warnings
8561
+ });
8562
+ }
8549
8563
  if (state.theme) {
8550
8564
  return state.theme;
8551
8565
  }