@json-to-office/core-docx 1.9.0 → 1.11.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":"inline.d.ts","sourceRoot":"","sources":["../../src/ir/inline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAMjE;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAY7E;AAmDD,0DAA0D;AAC1D,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED,4DAA4D;AAC5D,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED,0DAA0D;AAC1D,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK1E;AAED,MAAM,WAAW,kBAAkB;IACjC,wCAAwC;IACxC,IAAI,EAAE,mBAAmB,CAAC;IAC1B;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,SAAS,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5B,iEAAiE;IACjE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,qBAAqB,GAAG,SAAS,CAAC;IACzE;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,CACZ,EAAE,EAAE,MAAM,KACP;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,U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CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,kBAAkB,GAC1B,YAAY,EAAE,CAShB"}
@@ -40,6 +40,14 @@ export interface DocumentGeneratorOptions {
40
40
  * and fails before rendering on anything outside it.
41
41
  */
42
42
  renderer?: DocxRendererId;
43
+ /**
44
+ * Rasterize a PNG fallback for each inline SVG. Defaults to true.
45
+ *
46
+ * Only readers older than Word 2016 draw that raster; everything current
47
+ * draws the vector. Producing it dominates the render of a document whose
48
+ * artwork is many small SVGs, so it can be turned off.
49
+ */
50
+ svgRasterFallback?: boolean;
43
51
  }
44
52
  /**
45
53
  * Create a document generator with chainable component registration.
@@ -1 +1 @@
1
- {"version":3,"file":"createDocumentGenerator.d.ts","sourceRoot":"","sources":["../../src/plugin/createDocumentGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAK7C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,KAAK,EAEV,wBAAwB,EAOxB,2BAA2B,EAC5B,MAAM,SAAS,CAAC;AAajB;;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,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,G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AAO,CAAC;CAC7B;AA4sBD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,wBAAwB,CAAC,SAAS,EAAE,CAAC,CAkBvC"}
@@ -1834,6 +1834,7 @@ var init_widthUtils = __esm({
1834
1834
 
1835
1835
  // src/utils/imageUtils.ts
1836
1836
  import { readFileSync } from "fs";
1837
+ import { availableParallelism } from "os";
1837
1838
  import probe from "probe-image-size";
1838
1839
  function loadResvg() {
1839
1840
  resvgModule ??= import("@resvg/resvg-js");
@@ -1852,10 +1853,36 @@ function capToPixelBudget(edge, aspect) {
1852
1853
  const scaled = Math.floor(edge * Math.sqrt(SVG_MAX_TOTAL_PX / total));
1853
1854
  return scaled >= SVG_MIN_EDGE_PX ? scaled : void 0;
1854
1855
  }
1856
+ function fallbackConcurrency() {
1857
+ const cpus = availableParallelism?.() ?? 4;
1858
+ return Math.max(1, Math.min(8, cpus));
1859
+ }
1860
+ async function rasterizeSvgFallbacks(jobs, enabled = true) {
1861
+ const out = /* @__PURE__ */ new Map();
1862
+ if (!enabled || jobs.length === 0) return out;
1863
+ let next = 0;
1864
+ const worker = async () => {
1865
+ for (let i = next++; i < jobs.length; i = next++) {
1866
+ const job = jobs[i];
1867
+ out.set(
1868
+ job.key,
1869
+ await rasterizeSvgFallback(job.svg, {
1870
+ width: job.width,
1871
+ height: job.height
1872
+ })
1873
+ );
1874
+ }
1875
+ };
1876
+ await Promise.all(
1877
+ Array.from({ length: Math.min(fallbackConcurrency(), jobs.length) }, worker)
1878
+ );
1879
+ return out;
1880
+ }
1855
1881
  async function rasterizeSvgFallback(svg, transformation) {
1856
1882
  let Resvg;
1883
+ let renderAsync;
1857
1884
  try {
1858
- ({ Resvg } = await loadResvg());
1885
+ ({ Resvg, renderAsync } = await loadResvg());
1859
1886
  } catch (error) {
1860
1887
  reportWarning(
1861
1888
  "image",
@@ -1890,7 +1917,7 @@ async function rasterizeSvgFallback(svg, transformation) {
1890
1917
  return void 0;
1891
1918
  }
1892
1919
  return Buffer.from(
1893
- new Resvg(markup, { fitTo: { mode, value } }).render().asPng()
1920
+ (await renderAsync(markup, { fitTo: { mode, value } })).asPng()
1894
1921
  );
1895
1922
  } catch (error) {
1896
1923
  reportWarning(
@@ -2179,10 +2206,10 @@ import {
2179
2206
  EndnoteReferenceRun,
2180
2207
  ExternalHyperlink,
2181
2208
  FootnoteReferenceRun,
2209
+ ImportedXmlComponent,
2182
2210
  InsertedTextRun,
2183
2211
  InternalHyperlink,
2184
2212
  OverlapType,
2185
- PageNumber,
2186
2213
  Paragraph,
2187
2214
  RelativeHorizontalPosition,
2188
2215
  RelativeVerticalPosition,
@@ -2202,6 +2229,28 @@ import {
2202
2229
  WpsShapeRun
2203
2230
  } from "docx";
2204
2231
  import { assertNever } from "@json-to-office/shared/rendering";
2232
+ function complexField(instruction, formatting, leading) {
2233
+ const options = runOptions(formatting);
2234
+ const fieldChar = (type, extra = {}) => new TextRun({
2235
+ children: [
2236
+ new ImportedXmlComponent("w:fldChar", { "w:fldCharType": type })
2237
+ ],
2238
+ ...options,
2239
+ ...extra
2240
+ });
2241
+ const instrText = new ImportedXmlComponent("w:instrText", {
2242
+ "xml:space": "preserve"
2243
+ });
2244
+ instrText.push(instruction);
2245
+ return [
2246
+ // A pending line break rides on the first run of the field, the same way
2247
+ // it rides on the single run every other inline node emits.
2248
+ fieldChar("begin", leading),
2249
+ new TextRun({ children: [instrText], ...options }),
2250
+ fieldChar("separate"),
2251
+ fieldChar("end")
2252
+ ];
2253
+ }
2205
2254
  function runOptions(formatting) {
2206
2255
  if (!formatting) return {};
2207
2256
  const options = {};
@@ -2306,18 +2355,13 @@ function inlineChildren(children, resources = /* @__PURE__ */ new Map()) {
2306
2355
  out.push(new SimpleField(child.instruction, child.cachedText));
2307
2356
  break;
2308
2357
  }
2309
- const page = PAGE_FIELD[child.instruction];
2310
- if (!page) {
2358
+ if (!PAGE_FIELDS.has(child.instruction)) {
2311
2359
  throw new Error(
2312
2360
  `the docxjs renderer has no emitter for the field "${child.instruction}"`
2313
2361
  );
2314
2362
  }
2315
2363
  out.push(
2316
- new TextRun({
2317
- children: [page],
2318
- ...runOptions(child.formatting),
2319
- ...breakOption()
2320
- })
2364
+ ...complexField(child.instruction, child.formatting, breakOption())
2321
2365
  );
2322
2366
  break;
2323
2367
  }
@@ -2691,7 +2735,7 @@ function emitBorder(border3) {
2691
2735
  ...border3.spacePoints !== void 0 ? { space: border3.spacePoints } : {}
2692
2736
  };
2693
2737
  }
2694
- var ALIGNMENT2, PAGE_FIELD, WRAP_TYPE, VERTICAL_ALIGN, TABLE_ANCHOR, HORIZONTAL_POSITION, VERTICAL_POSITION, BORDER_STYLE;
2738
+ var ALIGNMENT2, PAGE_FIELDS, WRAP_TYPE, VERTICAL_ALIGN, TABLE_ANCHOR, HORIZONTAL_POSITION, VERTICAL_POSITION, BORDER_STYLE;
2695
2739
  var init_emit = __esm({
2696
2740
  "src/renderers/docxjs/emit.ts"() {
2697
2741
  "use strict";
@@ -2703,10 +2747,7 @@ var init_emit = __esm({
2703
2747
  start: AlignmentType.START,
2704
2748
  end: AlignmentType.END
2705
2749
  };
2706
- PAGE_FIELD = {
2707
- PAGE: PageNumber.CURRENT,
2708
- NUMPAGES: PageNumber.TOTAL_PAGES
2709
- };
2750
+ PAGE_FIELDS = /* @__PURE__ */ new Set(["PAGE", "NUMPAGES"]);
2710
2751
  WRAP_TYPE = {
2711
2752
  none: TextWrappingType.NONE,
2712
2753
  square: TextWrappingType.SQUARE,
@@ -3053,7 +3094,10 @@ function createDocxJsRenderer() {
3053
3094
  format: "docx",
3054
3095
  capabilities: DOCXJS_CAPABILITIES,
3055
3096
  async render(ir, renderOptions) {
3056
- const resources = await prepareImages(ir);
3097
+ const resources = await prepareImages(
3098
+ ir,
3099
+ renderOptions?.svgRasterFallback
3100
+ );
3057
3101
  const document = buildDocument(ir, resources);
3058
3102
  const packed = await Packer.toBuffer(document);
3059
3103
  const fixed = fixFloatingImageIdsInBuffer(packed);
@@ -3138,22 +3182,22 @@ function numberingConfig(numbering) {
3138
3182
  }))
3139
3183
  };
3140
3184
  }
3141
- async function prepareImages(ir) {
3185
+ async function prepareImages(ir, svgRasterFallback) {
3142
3186
  const placements = collectImagePlacements(ir);
3143
- const rasters = /* @__PURE__ */ new Map();
3187
+ const jobs = [];
3144
3188
  for (const resource of ir.resources) {
3145
3189
  if (resource.kind !== "image" || resource.mediaType !== "svg") continue;
3146
3190
  for (const size of placements.get(resource.id) ?? []) {
3147
3191
  const [width, height] = size.split("x").map(Number);
3148
- rasters.set(
3149
- `${resource.id}:${size}`,
3150
- await rasterizeSvgFallback(Buffer.from(resource.bytes), {
3151
- width,
3152
- height
3153
- })
3154
- );
3192
+ jobs.push({
3193
+ key: `${resource.id}:${size}`,
3194
+ svg: Buffer.from(resource.bytes),
3195
+ width,
3196
+ height
3197
+ });
3155
3198
  }
3156
3199
  }
3200
+ const rasters = await rasterizeSvgFallbacks(jobs, svgRasterFallback);
3157
3201
  const resources = /* @__PURE__ */ new Map();
3158
3202
  for (const resource of ir.resources) {
3159
3203
  if (resource.kind !== "image") continue;
@@ -4320,7 +4364,11 @@ async function createOfficeOpenDocxRenderer() {
4320
4364
  capabilities: OFFICE_OPEN_CAPABILITIES,
4321
4365
  async render(ir, options) {
4322
4366
  const charts = [];
4323
- const document = await buildDocumentOptions(ir, charts);
4367
+ const document = await buildDocumentOptions(
4368
+ ir,
4369
+ charts,
4370
+ options?.svgRasterFallback
4371
+ );
4324
4372
  const bytes = await backend.generateDocument(document, {
4325
4373
  type: "uint8array"
4326
4374
  });
@@ -4345,10 +4393,10 @@ async function createOfficeOpenDocxRenderer() {
4345
4393
  }
4346
4394
  };
4347
4395
  }
4348
- async function buildDocumentOptions(ir, charts = []) {
4396
+ async function buildDocumentOptions(ir, charts = [], svgRasterFallback) {
4349
4397
  let nextDrawingId = 1;
4350
4398
  const ctx = {
4351
- pictures: await prepareImages2(ir),
4399
+ pictures: await prepareImages2(ir, svgRasterFallback),
4352
4400
  nextDrawingId: () => nextDrawingId++,
4353
4401
  charts
4354
4402
  };
@@ -4397,22 +4445,22 @@ function noteBodies2(notes, ctx) {
4397
4445
  }
4398
4446
  return bodies;
4399
4447
  }
4400
- async function prepareImages2(ir) {
4448
+ async function prepareImages2(ir, svgRasterFallback) {
4401
4449
  const placements = collectImagePlacements2(ir);
4402
- const rasters = /* @__PURE__ */ new Map();
4450
+ const jobs = [];
4403
4451
  for (const resource of ir.resources) {
4404
4452
  if (resource.kind !== "image" || resource.mediaType !== "svg") continue;
4405
4453
  for (const size of placements.get(resource.id) ?? []) {
4406
4454
  const [width, height] = size.split("x").map(Number);
4407
- rasters.set(
4408
- `${resource.id}:${size}`,
4409
- await rasterizeSvgFallback(Buffer.from(resource.bytes), {
4410
- width,
4411
- height
4412
- })
4413
- );
4455
+ jobs.push({
4456
+ key: `${resource.id}:${size}`,
4457
+ svg: Buffer.from(resource.bytes),
4458
+ width,
4459
+ height
4460
+ });
4414
4461
  }
4415
4462
  }
4463
+ const rasters = await rasterizeSvgFallbacks(jobs, svgRasterFallback);
4416
4464
  const resources = /* @__PURE__ */ new Map();
4417
4465
  for (const resource of ir.resources) {
4418
4466
  if (resource.kind !== "image") continue;
@@ -7988,6 +8036,44 @@ function buildNoProofWordsRegex(noProofWords2) {
7988
8036
  );
7989
8037
  }
7990
8038
  var DECORATOR = /(\*\*\*|___)([\s\S]*?)\1|(\*\*|__)([\s\S]*?)\3|(\*|_)([\s\S]*?)\5/g;
8039
+ var ESCAPABLE = "*_[]{}\\";
8040
+ var ESCAPE = /\\([*_[\]{}\\])/g;
8041
+ var SENTINEL = "\uE000";
8042
+ var SENTINEL_SELF = "x";
8043
+ var SENTINEL_DIGIT_BASE = 48;
8044
+ function encodeEscapes(text) {
8045
+ const authored = text.includes(SENTINEL);
8046
+ if (!authored && !text.includes("\\")) return text;
8047
+ const guarded = authored ? text.split(SENTINEL).join(SENTINEL + SENTINEL_SELF) : text;
8048
+ return guarded.replace(
8049
+ ESCAPE,
8050
+ (_whole, char) => SENTINEL + String.fromCharCode(SENTINEL_DIGIT_BASE + ESCAPABLE.indexOf(char))
8051
+ );
8052
+ }
8053
+ function decodeEscapes(text) {
8054
+ if (!text.includes(SENTINEL)) return text;
8055
+ let out = "";
8056
+ for (let i = 0; i < text.length; i += 1) {
8057
+ if (text[i] !== SENTINEL) {
8058
+ out += text[i];
8059
+ continue;
8060
+ }
8061
+ const marker = text[i + 1];
8062
+ if (marker === SENTINEL_SELF) {
8063
+ out += SENTINEL;
8064
+ i += 1;
8065
+ continue;
8066
+ }
8067
+ const index = marker === void 0 ? -1 : marker.charCodeAt(0) - SENTINEL_DIGIT_BASE;
8068
+ if (index >= 0 && index < ESCAPABLE.length) {
8069
+ out += ESCAPABLE[index];
8070
+ i += 1;
8071
+ continue;
8072
+ }
8073
+ out += text[i];
8074
+ }
8075
+ return out;
8076
+ }
7991
8077
  var LINK = /\[([^\]]+)\]\(([^)]+)\)/g;
7992
8078
  var DECORATOR_OR_PLACEHOLDER = /(\*\*\*|___)([\s\S]*?)\1|(\*\*|__)([\s\S]*?)\3|(\*|_)([\s\S]*?)\5|\{([^}]+)\}/g;
7993
8079
  var PLACEHOLDER = /\{([^}]+)\}/;
@@ -8014,7 +8100,7 @@ function containsUnsupportedSyntax(text) {
8014
8100
  return void 0;
8015
8101
  }
8016
8102
  function parseInline(text, options) {
8017
- const normalized = normalizeUnicodeText(text);
8103
+ const normalized = encodeEscapes(normalizeUnicodeText(text));
8018
8104
  if (!normalized) {
8019
8105
  return [
8020
8106
  { kind: "text", text: "", formatting: emptyToUndefined(options.base) }
@@ -8112,7 +8198,7 @@ function parseLinks(normalized, options) {
8112
8198
  lastIndex = match.index + match[0].length;
8113
8199
  if (match[1] === void 0) {
8114
8200
  const resolved = options.resolveCrossReference?.(
8115
- match[3],
8201
+ decodeEscapes(match[3]),
8116
8202
  match[4] ?? "relative",
8117
8203
  match[0]
8118
8204
  );
@@ -8120,7 +8206,8 @@ function parseLinks(normalized, options) {
8120
8206
  else out.push(...parseDecorated(match[0], options));
8121
8207
  continue;
8122
8208
  }
8123
- const [, linkText, target] = match;
8209
+ const [, linkText] = match;
8210
+ const target = decodeEscapes(match[2]);
8124
8211
  out.push({
8125
8212
  kind: "hyperlink",
8126
8213
  // A `#anchor` target names a bookmark in this document and needs no
@@ -8176,7 +8263,7 @@ function pushSegment(out, text, options, override = {}) {
8176
8263
  const bold = override.bold ?? options.base.bold;
8177
8264
  const italic = override.italic ?? options.base.italic;
8178
8265
  const formatting = runFormatting2(options, { bold, italic });
8179
- const lines = text.split("\n");
8266
+ const lines = decodeEscapes(text).split("\n");
8180
8267
  for (const [lineIndex, line] of lines.entries()) {
8181
8268
  if (!line && lineIndex === 0) continue;
8182
8269
  if (lineIndex > 0) out.push({ kind: "lineBreak" });
@@ -8647,8 +8734,8 @@ function compileComponent(component, scope) {
8647
8734
  return compileStatistic(component, scope);
8648
8735
  case "toc":
8649
8736
  return compileToc(component, scope);
8650
- case "rule":
8651
- return compileRule(component, scope);
8737
+ case "divider":
8738
+ return compileDivider(component, scope);
8652
8739
  case "text-box":
8653
8740
  return compileTextBox(component, scope);
8654
8741
  case "columns":
@@ -9225,16 +9312,16 @@ function compileToc(component, scope) {
9225
9312
  });
9226
9313
  return blocks;
9227
9314
  }
9228
- var DEFAULT_RULE_SPACING_PT = 6;
9229
- var DEFAULT_RULE_THICKNESS_PT = 1;
9230
- var RULE_LINE_TWIPS = 20;
9231
- var RULE_BORDER_STYLE = {
9315
+ var DEFAULT_DIVIDER_SPACING_PT = 6;
9316
+ var DEFAULT_DIVIDER_THICKNESS_PT = 1;
9317
+ var DIVIDER_LINE_TWIPS = 20;
9318
+ var DIVIDER_BORDER_STYLE = {
9232
9319
  solid: "single",
9233
9320
  dashed: "dashed",
9234
9321
  dotted: "dotted",
9235
9322
  double: "double"
9236
9323
  };
9237
- function compileRule(component, scope) {
9324
+ function compileDivider(component, scope) {
9238
9325
  const { ctx, path: path3 } = scope;
9239
9326
  const props = component.props ?? {};
9240
9327
  ctx.features.require("borders", path3);
@@ -9242,12 +9329,12 @@ function compileRule(component, scope) {
9242
9329
  12,
9243
9330
  Math.max(
9244
9331
  0.25,
9245
- typeof props.thickness === "number" && Number.isFinite(props.thickness) ? props.thickness : DEFAULT_RULE_THICKNESS_PT
9332
+ typeof props.thickness === "number" && Number.isFinite(props.thickness) ? props.thickness : DEFAULT_DIVIDER_THICKNESS_PT
9246
9333
  )
9247
9334
  );
9248
9335
  const spacing = props.spacing ?? {};
9249
- const beforePt = typeof spacing.before === "number" && Number.isFinite(spacing.before) ? spacing.before : DEFAULT_RULE_SPACING_PT;
9250
- const afterPt = typeof spacing.after === "number" && Number.isFinite(spacing.after) ? spacing.after : DEFAULT_RULE_SPACING_PT;
9336
+ const beforePt = typeof spacing.before === "number" && Number.isFinite(spacing.before) ? spacing.before : DEFAULT_DIVIDER_SPACING_PT;
9337
+ const afterPt = typeof spacing.after === "number" && Number.isFinite(spacing.after) ? spacing.after : DEFAULT_DIVIDER_SPACING_PT;
9251
9338
  return [
9252
9339
  {
9253
9340
  kind: "paragraph",
@@ -9259,13 +9346,13 @@ function compileRule(component, scope) {
9259
9346
  spacing: {
9260
9347
  beforeTwips: pointsToTwips2(beforePt),
9261
9348
  afterTwips: pointsToTwips2(afterPt),
9262
- lineTwips: RULE_LINE_TWIPS,
9349
+ lineTwips: DIVIDER_LINE_TWIPS,
9263
9350
  lineRule: "exact"
9264
9351
  },
9265
- ...ruleIndent(props, ctx, path3),
9352
+ ...dividerIndent(props, ctx, path3),
9266
9353
  borders: {
9267
9354
  bottom: {
9268
- style: RULE_BORDER_STYLE[String(props.style)] ?? "single",
9355
+ style: DIVIDER_BORDER_STYLE[String(props.style)] ?? "single",
9269
9356
  sizeEighthPoints: pointsToEighthPoints(thicknessPt),
9270
9357
  color: irColor(
9271
9358
  resolveColor(String(props.color ?? "border"), ctx.theme)
@@ -9279,7 +9366,7 @@ function compileRule(component, scope) {
9279
9366
  }
9280
9367
  ];
9281
9368
  }
9282
- function ruleIndent(props, ctx, path3) {
9369
+ function dividerIndent(props, ctx, path3) {
9283
9370
  const width = props.width;
9284
9371
  if (width === void 0) return {};
9285
9372
  const page = getPageSetup(ctx.theme);
@@ -9302,8 +9389,8 @@ function ruleIndent(props, ctx, path3) {
9302
9389
  if (remainder < 0) {
9303
9390
  warnOnce(
9304
9391
  ctx,
9305
- "rule",
9306
- `Rule width ${JSON.stringify(width)} at ${path3} is wider than the ${Math.round(measureTwips / 20)}pt text measure; it runs the full measure instead.`
9392
+ "divider",
9393
+ `Divider width ${JSON.stringify(width)} at ${path3} is wider than the ${Math.round(measureTwips / 20)}pt text measure; it runs the full measure instead.`
9307
9394
  );
9308
9395
  }
9309
9396
  return {};
@@ -12113,6 +12200,7 @@ async function renderScoped(document, options, warnings) {
12113
12200
  const bytes = await renderer.render(compiled.ir, {
12114
12201
  ...options.deterministic !== void 0 ? { deterministic: options.deterministic } : {},
12115
12202
  ...options.generatedAt !== void 0 ? { generatedAt: toDate(options.generatedAt) } : {},
12203
+ ...options.svgRasterFallback !== void 0 ? { svgRasterFallback: options.svgRasterFallback } : {},
12116
12204
  warnings: compiled.warnings
12117
12205
  });
12118
12206
  return { buffer: Buffer.from(bytes), warnings: compiled.warnings };
@@ -12289,7 +12377,8 @@ function createBuilderImpl(state) {
12289
12377
  deterministic: state.deterministic,
12290
12378
  generatedAt: state.generatedAt,
12291
12379
  baseDir: state.baseDir,
12292
- renderer: state.renderer
12380
+ renderer: state.renderer,
12381
+ svgRasterFallback: state.svgRasterFallback
12293
12382
  };
12294
12383
  return createBuilderImpl(
12295
12384
  newState
@@ -12546,7 +12635,8 @@ function createDocumentGenerator(options) {
12546
12635
  deterministic: options.deterministic ?? true,
12547
12636
  generatedAt: options.generatedAt,
12548
12637
  baseDir: options.baseDir,
12549
- renderer: options.renderer
12638
+ renderer: options.renderer,
12639
+ svgRasterFallback: options.svgRasterFallback
12550
12640
  };
12551
12641
  return createBuilderImpl(initialState);
12552
12642
  }