@json-to-office/core-docx 6.2.0 → 6.6.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.
@@ -27,9 +27,14 @@ export interface LoadedImage {
27
27
  *
28
28
  * A source that could not be loaded is absent rather than recorded as an
29
29
  * error: the compiler reports it against the component's own path, which is
30
- * more use than an error attached to a URL.
30
+ * more use than an error attached to a URL. Why it failed is kept beside the
31
+ * images, so that report can say — and so a source that was tried and failed
32
+ * can be told from one the walk never reached.
31
33
  */
32
- export type ImageResources = ReadonlyMap<string, LoadedImage>;
34
+ export interface ImageResources extends ReadonlyMap<string, LoadedImage> {
35
+ /** What each source that did not load threw. */
36
+ readonly failures?: ReadonlyMap<string, unknown>;
37
+ }
33
38
  /** Load every image source in `components`, following nested content. */
34
39
  export declare function loadImageResources(components: Iterable<ComponentDefinition | undefined>): Promise<ImageResources>;
35
40
  //# sourceMappingURL=imageResources.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"imageResources.d.ts","sourceRoot":"","sources":["../../src/core/imageResources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;;AAMH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAOpD,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,SAAS,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/C;AAED;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAE9D,yEAAyE;AACzE,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,QAAQ,CAAC,mBAAmB,GAAG,SAAS,CAAC,GACpD,OAAO,CAAC,cAAc,CAAC,CAyBzB"}
1
+ {"version":3,"file":"imageResources.d.ts","sourceRoot":"","sources":["../../src/core/imageResources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;;AAMH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAOpD,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,SAAS,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/C;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAe,SAAQ,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC;IACtE,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClD;AAED,yEAAyE;AACzE,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,QAAQ,CAAC,mBAAmB,GAAG,SAAS,CAAC,GACpD,OAAO,CAAC,cAAc,CAAC,CA2BzB"}
package/dist/index.js CHANGED
@@ -2670,9 +2670,7 @@ async function downloadImageFromUrl(url) {
2670
2670
  });
2671
2671
  clearTimeout(timeoutId);
2672
2672
  if (!response.ok) {
2673
- throw new Error(
2674
- `Failed to download image: HTTP ${response.status} ${response.statusText}`
2675
- );
2673
+ throw new Error(`HTTP ${response.status} ${response.statusText}`);
2676
2674
  }
2677
2675
  const contentType = response.headers.get("content-type") || void 0;
2678
2676
  const arrayBuffer = await response.arrayBuffer();
@@ -2684,9 +2682,9 @@ async function downloadImageFromUrl(url) {
2684
2682
  "Failed to download image: Request timeout after 10 seconds"
2685
2683
  );
2686
2684
  }
2687
- throw new Error(`Failed to download image from ${url}: ${error.message}`);
2685
+ throw new Error(`Failed to download image: ${error.message}`);
2688
2686
  }
2689
- throw new Error(`Failed to download image from ${url}: Unknown error`);
2687
+ throw new Error("Failed to download image: Unknown error");
2690
2688
  }
2691
2689
  }
2692
2690
  function resolveImageSource(props) {
@@ -6221,6 +6219,7 @@ async function loadImageResources(components) {
6221
6219
  const sources = /* @__PURE__ */ new Set();
6222
6220
  for (const component of components) collectSources(component, sources);
6223
6221
  const loaded = /* @__PURE__ */ new Map();
6222
+ const failures = /* @__PURE__ */ new Map();
6224
6223
  await Promise.all(
6225
6224
  [...sources].map(async (source) => {
6226
6225
  try {
@@ -6231,11 +6230,12 @@ async function loadImageResources(components) {
6231
6230
  ...result.contentType ? { contentType: result.contentType } : {},
6232
6231
  ...intrinsic ? { intrinsic } : {}
6233
6232
  });
6234
- } catch {
6233
+ } catch (error) {
6234
+ failures.set(source, error);
6235
6235
  }
6236
6236
  })
6237
6237
  );
6238
- return loaded;
6238
+ return Object.assign(loaded, { failures });
6239
6239
  }
6240
6240
  function readIntrinsic(bytes, source) {
6241
6241
  try {
@@ -6305,7 +6305,8 @@ function collectCellSource(content, out) {
6305
6305
  // src/ir/compiler.ts
6306
6306
  init_colorUtils();
6307
6307
  import {
6308
- FeatureRequirementCollector
6308
+ FeatureRequirementCollector,
6309
+ assetUnreadableError
6309
6310
  } from "@json-to-office/shared/rendering";
6310
6311
  import { capsFormatting as capsFormatting2, synthesizeFamilyName as synthesizeFamilyName2 } from "@json-to-office/shared";
6311
6312
  import {
@@ -9291,7 +9292,7 @@ function compileChromeImage(component, scope) {
9291
9292
  }
9292
9293
  const loaded = ctx.images.get(source);
9293
9294
  if (!loaded) {
9294
- throw new Error(`Failed to load image from ${source.substring(0, 50)}`);
9295
+ throw unreadableImage(source, ctx) ?? new Error(`Failed to load image from ${source.substring(0, 50)}`);
9295
9296
  }
9296
9297
  const mediaType = detectImageType(source, loaded.contentType);
9297
9298
  if (mediaType === "svg") ctx.features.require("svg-images", path4);
@@ -10900,6 +10901,10 @@ function visualPlacementPixels(props, canvas, reference) {
10900
10901
  );
10901
10902
  }
10902
10903
  var UNLOWERED_IMAGE_PROPS = ["comment"];
10904
+ function unreadableImage(source, ctx) {
10905
+ const { failures } = ctx.images;
10906
+ return failures?.has(source) ? assetUnreadableError(source, failures.get(source)) : void 0;
10907
+ }
10903
10908
  function compileImage2(component, scope) {
10904
10909
  const { ctx, path: path4 } = scope;
10905
10910
  const props = component.props ?? {};
@@ -10916,7 +10921,9 @@ function compileImage2(component, scope) {
10916
10921
  );
10917
10922
  }
10918
10923
  const loaded = ctx.images.get(source);
10919
- if (!loaded) throw new Error(`Failed to load image from ${source}`);
10924
+ if (!loaded) {
10925
+ throw unreadableImage(source, ctx) ?? new Error(`Failed to load image from ${source}`);
10926
+ }
10920
10927
  const mediaType = detectImageType(source, loaded.contentType);
10921
10928
  if (mediaType === "svg") ctx.features.require("svg-images", path4);
10922
10929
  if (typeof props.alt === "string" && props.alt) {
@@ -13942,7 +13949,9 @@ function prepareDocxQualityDocument(document, options = {}) {
13942
13949
  )
13943
13950
  ]
13944
13951
  });
13945
- collectColorLiterals(document).forEach((literal, index) => {
13952
+ const content = { ...document, props: { ...asRecord2(document.props) } };
13953
+ delete content.props.themeOverrides;
13954
+ collectColorLiterals(content).forEach((literal, index) => {
13946
13955
  addFact({
13947
13956
  id: `docx:color:${index}:${literal.path}`,
13948
13957
  kind: "docx/color",
@@ -13951,7 +13960,7 @@ function prepareDocxQualityDocument(document, options = {}) {
13951
13960
  hex: literal.hex
13952
13961
  });
13953
13962
  });
13954
- collectFontFamilies(document).forEach((use, index) => {
13963
+ collectFontFamilies(content).forEach((use, index) => {
13955
13964
  addFact({
13956
13965
  id: `docx:font:${index}:${use.path}`,
13957
13966
  kind: "docx/font-family",