@json-to-office/core-docx 0.17.3 → 0.18.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.
@@ -0,0 +1,32 @@
1
+ import type { ComponentDefinition } from '@json-to-office/shared-docx';
2
+ /**
3
+ * @example
4
+ * ```json
5
+ * {
6
+ * "name": "eldermoor-census",
7
+ * "props": { "title": "Regno di Valebrook", "manaPct": "51,2%", "castles": "3.120" }
8
+ * }
9
+ * ```
10
+ */
11
+ export declare const eldermoorCensusComponent: import("../createComponent").CustomComponent<ComponentDefinition, {
12
+ '1.0.0': import("../createComponent").ComponentVersion<ComponentDefinition, import("@sinclair/typebox").TObject<{
13
+ title: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
14
+ manaPct: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
15
+ faithfulSubjects: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
16
+ swornGuilds: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
17
+ mappedTerritoriesPct: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
18
+ castles: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
19
+ outposts: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
20
+ watchtowers: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
21
+ sovereignTreasury: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
22
+ warChest: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
23
+ marketMint: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
24
+ royalServants: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
25
+ servantsLeft: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
26
+ servantsRight: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
27
+ width: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TNumber, import("@sinclair/typebox").TString]>>;
28
+ alignment: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"left">, import("@sinclair/typebox").TLiteral<"center">, import("@sinclair/typebox").TLiteral<"right">]>>;
29
+ caption: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
30
+ }>>;
31
+ }, "eldermoor-census">;
32
+ //# sourceMappingURL=eldermoor-census.component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eldermoor-census.component.d.ts","sourceRoot":"","sources":["../../../src/plugin/example/eldermoor-census.component.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAgNvE;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;sBAwBnC,CAAC"}
@@ -2849,6 +2849,16 @@ async function downloadImageFromUrl(url) {
2849
2849
  throw new Error(`Failed to download image from ${url}: Unknown error`);
2850
2850
  }
2851
2851
  }
2852
+ function resolveImageSource(props) {
2853
+ const hasValue = (v) => typeof v === "string" && v.trim().length > 0;
2854
+ if (hasValue(props.svg)) {
2855
+ const encoded = Buffer.from(props.svg, "utf-8").toString("base64");
2856
+ return `data:image/svg+xml;base64,${encoded}`;
2857
+ }
2858
+ if (hasValue(props.base64)) return props.base64;
2859
+ if (hasValue(props.path)) return props.path;
2860
+ return void 0;
2861
+ }
2852
2862
  async function getImageBuffer(imagePath) {
2853
2863
  if (isBase64Image(imagePath)) {
2854
2864
  return { buffer: decodeBase64Image(imagePath) };
@@ -5066,10 +5076,10 @@ async function createTable(columns, tableConfig, theme, themeName, _options = {}
5066
5076
  } else if (isImageComponent(cell)) {
5067
5077
  const imageComp = cell;
5068
5078
  try {
5069
- const imageSource = imageComp.props.base64 || imageComp.props.path;
5079
+ const imageSource = resolveImageSource(imageComp.props);
5070
5080
  if (!imageSource) {
5071
5081
  throw new Error(
5072
- 'Image component requires either "path" or "base64" property'
5082
+ 'Image component requires one of "path", "base64", or "svg" property'
5073
5083
  );
5074
5084
  }
5075
5085
  const imageResult = await getImageBuffer(imageSource);
@@ -5095,7 +5105,7 @@ async function createTable(columns, tableConfig, theme, themeName, _options = {}
5095
5105
  });
5096
5106
  cellChildren = [imageRun];
5097
5107
  } catch (error) {
5098
- const imageSource = imageComp.props.base64 || imageComp.props.path || "unknown";
5108
+ const imageSource = imageComp.props.svg?.trim() ? "inline-svg" : imageComp.props.base64 || imageComp.props.path || "unknown";
5099
5109
  cellChildren = [
5100
5110
  new TextRun4({
5101
5111
  text: `[IMAGE: ${imageSource.substring(0, 50)}${imageSource.length > 50 ? "..." : ""}]`,
@@ -5772,10 +5782,10 @@ function renderListComponent(component, theme, themeName) {
5772
5782
  async function renderImageComponent(component, theme, themeName) {
5773
5783
  if (!isImageComponent(component)) return [];
5774
5784
  const resolvedConfig = component.props;
5775
- const imageSource = resolvedConfig.base64 || resolvedConfig.path;
5785
+ const imageSource = resolveImageSource(resolvedConfig);
5776
5786
  if (!imageSource) {
5777
5787
  throw new Error(
5778
- 'Image component requires either "path" or "base64" property'
5788
+ 'Image component requires one of "path", "base64", or "svg" property'
5779
5789
  );
5780
5790
  }
5781
5791
  return await createImage(imageSource, theme, themeName, {
@@ -6457,7 +6467,10 @@ async function generateChart(config, servicesConfig) {
6457
6467
  infile: config.options,
6458
6468
  type: "png",
6459
6469
  b64: true,
6460
- scale: config.scale
6470
+ scale: config.scale,
6471
+ // Forward resources verbatim only when present so the payload stays
6472
+ // byte-identical to before for callers that omit it.
6473
+ ...config.resources ? { resources: config.resources } : {}
6461
6474
  };
6462
6475
  const response = await postJsonToService({
6463
6476
  url: serverUrl,
@@ -6795,13 +6808,13 @@ async function renderHeaderFooterComponents(components, theme, themeName, contex
6795
6808
  );
6796
6809
  } else if (isImageComponent(component)) {
6797
6810
  const imageComp = component;
6798
- let imageSource = imageComp.props.base64 || imageComp.props.path;
6811
+ let imageSource = resolveImageSource(imageComp.props);
6799
6812
  if (!imageSource) {
6800
6813
  elements.push(
6801
6814
  new Paragraph7({
6802
6815
  children: [
6803
6816
  new TextRun6({
6804
- text: "[IMAGE: Missing path or base64 property]",
6817
+ text: "[IMAGE: Missing path, base64, or svg property]",
6805
6818
  font: getThemeFonts(theme).body.family,
6806
6819
  size: 20,
6807
6820
  bold: true,
@@ -6875,15 +6888,16 @@ async function renderHeaderFooterComponents(components, theme, themeName, contex
6875
6888
  })
6876
6889
  );
6877
6890
  } catch (error) {
6891
+ const sourcePreview = imageSource.substring(0, 50);
6878
6892
  console.error(
6879
- `[Header/Footer Image Error] Failed to render image: ${imageComp.props.path?.substring(0, 50)}...`,
6893
+ `[Header/Footer Image Error] Failed to render image: ${sourcePreview}...`,
6880
6894
  error instanceof Error ? error.message : error
6881
6895
  );
6882
6896
  elements.push(
6883
6897
  new Paragraph7({
6884
6898
  children: [
6885
6899
  new TextRun6({
6886
- text: `[IMAGE: ${imageComp.props.path}]`,
6900
+ text: `[IMAGE: ${sourcePreview}]`,
6887
6901
  font: getThemeFonts(theme).body.family,
6888
6902
  size: 20,
6889
6903
  color: getThemeColors(theme).secondary,