@json-to-office/core-docx 6.0.0 → 6.1.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.
@@ -5870,7 +5870,7 @@ async function rasterizeVisualSlide(presentation, dpi, propsServerUrl, serviceCo
5870
5870
  serviceConfig?.serverUrl,
5871
5871
  DEFAULT_RASTERIZE_SERVER_URL
5872
5872
  );
5873
- const response = await postJsonToService({
5873
+ const body = await postJsonToService({
5874
5874
  url: serverUrl,
5875
5875
  path: "/rasterize",
5876
5876
  body: {
@@ -5882,11 +5882,12 @@ async function rasterizeVisualSlide(presentation, dpi, propsServerUrl, serviceCo
5882
5882
  headers: serviceConfig?.headers,
5883
5883
  serviceLabel: "PPTX rasterization service",
5884
5884
  onUnreachable: (url, cause) => `PPTX rasterization service is not reachable at ${url}. Configure services.pptx with a \`render\` callback or a running \`serverUrl\`.
5885
- Cause: ${cause}`
5885
+ Cause: ${cause}`,
5886
+ decode: (response) => response.text()
5886
5887
  });
5887
5888
  let result;
5888
5889
  try {
5889
- result = await response.json();
5890
+ result = JSON.parse(body);
5890
5891
  } catch {
5891
5892
  throw new Error(
5892
5893
  "PPTX rasterization service returned a non-JSON response (expected { base64DataUri, width, height })."
@@ -6074,9 +6075,9 @@ async function prerasterizeVisuals(root, serviceConfig, options = {}) {
6074
6075
  DEFAULT_RASTERIZE_SERVER_URL
6075
6076
  );
6076
6077
  const postBatch = async (chunk, fonts) => {
6077
- let response;
6078
+ let body;
6078
6079
  try {
6079
- response = await postJsonToService2({
6080
+ body = await postJsonToService2({
6080
6081
  url: serverUrl,
6081
6082
  path: "/rasterize/batch",
6082
6083
  body: {
@@ -6089,14 +6090,21 @@ async function prerasterizeVisuals(root, serviceConfig, options = {}) {
6089
6090
  },
6090
6091
  headers: serviceConfig?.headers,
6091
6092
  timeoutMs: BATCH_TIMEOUT_BASE_MS + BATCH_TIMEOUT_PER_SLIDE_MS * chunk.length,
6093
+ // The per-visual fallback below IS this call's retry, and a better
6094
+ // one: it degrades to smaller work instead of repeating the same
6095
+ // large request. Retrying here first would spend three full batch
6096
+ // timeouts — up to seventeen minutes on a 32-slide chunk — before
6097
+ // the fallback that was going to run anyway gets its turn.
6098
+ retries: 0,
6092
6099
  serviceLabel: "PPTX batch rasterization service",
6093
- onUnreachable: (url, cause) => `PPTX rasterization service is not reachable at ${url}. Cause: ${cause}`
6100
+ onUnreachable: (url, cause) => `PPTX rasterization service is not reachable at ${url}. Cause: ${cause}`,
6101
+ decode: (response) => response.text()
6094
6102
  });
6095
6103
  } catch (error) {
6096
6104
  return { applied: false, schemaRejected: isSchemaRejection(error) };
6097
6105
  }
6098
6106
  try {
6099
- if (applyBatchResponse(chunk, await response.json(), map)) {
6107
+ if (applyBatchResponse(chunk, JSON.parse(body), map)) {
6100
6108
  return { applied: true };
6101
6109
  }
6102
6110
  } catch {
@@ -6203,7 +6211,7 @@ function containsComponent(root, name) {
6203
6211
  import {
6204
6212
  clampVisualDpi as clampVisualDpi2,
6205
6213
  DEFAULT_VISUAL_DPI as DEFAULT_VISUAL_DPI2,
6206
- limitChartRequest
6214
+ recordChartCollected
6207
6215
  } from "@json-to-office/shared";
6208
6216
  import {
6209
6217
  isNativeVisualProps as isNativeVisualProps2
@@ -6222,9 +6230,8 @@ import {
6222
6230
  withChartTypography,
6223
6231
  resolveServiceUrl as resolveServiceUrl3,
6224
6232
  postJsonToService as postJsonToService3,
6225
- chartRequestKey,
6226
- dedupeChartRequest,
6227
- recordChartRetry
6233
+ recordChartRetry,
6234
+ sendChartRequest
6228
6235
  } from "@json-to-office/shared";
6229
6236
  var DEFAULT_EXPORT_SERVER_URL = "http://localhost:7801";
6230
6237
  function effectiveChartServerUrl(props, servicesConfig) {
@@ -6265,14 +6272,16 @@ async function generateChart(config, servicesConfig, warnings, cache) {
6265
6272
  // byte-identical to before for callers that omit it.
6266
6273
  ...config.resources ? { resources: config.resources } : {}
6267
6274
  };
6268
- return dedupeChartRequest(
6275
+ return sendChartRequest({
6269
6276
  cache,
6270
- chartRequestKey(serverUrl, requestBody),
6271
- () => postChart(serverUrl, requestBody, config, servicesConfig)
6272
- );
6277
+ serverUrl,
6278
+ concurrency: servicesConfig?.concurrency,
6279
+ requestBody,
6280
+ send: () => postChart(serverUrl, requestBody, config, servicesConfig)
6281
+ });
6273
6282
  }
6274
6283
  async function postChart(serverUrl, requestBody, config, servicesConfig) {
6275
- const response = await postJsonToService3({
6284
+ const base64Data = await postJsonToService3({
6276
6285
  url: serverUrl,
6277
6286
  path: "/export",
6278
6287
  body: requestBody,
@@ -6282,16 +6291,13 @@ async function postChart(serverUrl, requestBody, config, servicesConfig) {
6282
6291
  onRetry: recordChartRetry,
6283
6292
  serviceLabel: "Highcharts export server",
6284
6293
  onUnreachable: (url, cause) => `Highcharts Export Server is not running at ${url}. Start it with: npx highcharts-export-server --enableServer true
6285
- Cause: ${cause}`
6294
+ Cause: ${cause}`,
6295
+ decode: (response) => response.text()
6286
6296
  });
6287
- const base64Data = await response.text();
6288
- const base64DataUri = `data:image/png;base64,${base64Data}`;
6289
- const width = config.options.chart.width;
6290
- const height = config.options.chart.height;
6291
6297
  return {
6292
- base64DataUri,
6293
- width,
6294
- height
6298
+ base64DataUri: `data:image/png;base64,${base64Data}`,
6299
+ width: config.options.chart.width,
6300
+ height: config.options.chart.height
6295
6301
  };
6296
6302
  }
6297
6303
  function toChartColor(value, theme) {
@@ -6419,21 +6425,16 @@ async function desugarExternals(document, options) {
6419
6425
  });
6420
6426
  }
6421
6427
  if (node.name === "highcharts") {
6422
- const props = node.props;
6423
- const chartConfig = options.services?.highcharts;
6428
+ recordChartCollected();
6424
6429
  return withNodeIdentity(node, {
6425
6430
  name: "image",
6426
- props: await limitChartRequest(
6427
- effectiveChartServerUrl(props, chartConfig),
6428
- chartConfig?.concurrency,
6429
- () => renderChartToImageProps(
6430
- props,
6431
- options.theme,
6432
- chartConfig,
6433
- options.chartFonts,
6434
- options.warnings,
6435
- chartCache
6436
- )
6431
+ props: await renderChartToImageProps(
6432
+ node.props,
6433
+ options.theme,
6434
+ options.services?.highcharts,
6435
+ options.chartFonts,
6436
+ options.warnings,
6437
+ chartCache
6437
6438
  )
6438
6439
  });
6439
6440
  }