@json-to-office/core-docx 3.1.0 → 3.3.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":"compiler.d.ts","sourceRoot":"","sources":["../../src/ir/compiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EACV,iBAAiB,EAGlB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,gBAAgB,CAAC;AAChE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAiD3D,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,wBAAwB,CAAC;AAuC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAEL,KAAK,MAAM,EAqCZ,MAAM,SAAS,CAAC;AAiBjB,2DAA2D;AAC3D,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,2EAA2E;IAC3E,QAAQ,EAAE,SAAS,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC;IACrD,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B;;;;OAIG;IACH,WAAW,EAAE,oBAAoB,EAAE,CAAC;CACrC;AA8FD,wBAAgB,eAAe,CAC7B,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,UAAU,EAClB,QAAQ,GAAE,iBAAiB,EAAO,EAClC,MAAM,GAAE,cAA0B,EAClC,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACvC,iBAAiB,CAgHnB"}
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../src/ir/compiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EACV,iBAAiB,EAGlB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,gBAAgB,CAAC;AAChE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAiD3D,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,wBAAwB,CAAC;AAuC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAEL,KAAK,MAAM,EAqCZ,MAAM,SAAS,CAAC;AAiBjB,2DAA2D;AAC3D,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,2EAA2E;IAC3E,QAAQ,EAAE,SAAS,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC;IACrD,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B;;;;OAIG;IACH,WAAW,EAAE,oBAAoB,EAAE,CAAC;CACrC;AAoGD,wBAAgB,eAAe,CAC7B,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,UAAU,EAClB,QAAQ,GAAE,iBAAiB,EAAO,EAClC,MAAM,GAAE,cAA0B,EAClC,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACvC,iBAAiB,CAiHnB"}
@@ -110,6 +110,7 @@ export declare function parseInline(text: string, options: ParseInlineOptions):
110
110
  export type PlaceholderResolution = {
111
111
  kind: 'field';
112
112
  instruction: string;
113
+ cachedText?: string;
113
114
  } | {
114
115
  kind: 'text';
115
116
  text: string;
@@ -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;AA8HD,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,UAAU,GAAG,SAAS,CAAA;KAAE,GAAG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AY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,kBAAkB,GAC1B,YAAY,EAAE,CAShB"}
@@ -2348,7 +2348,7 @@ import {
2348
2348
  WpsShapeRun
2349
2349
  } from "docx";
2350
2350
  import { assertNever } from "@json-to-office/shared/rendering";
2351
- function complexField(instruction, formatting, leading) {
2351
+ function complexField(instruction, formatting, leading, cachedText) {
2352
2352
  const options = runOptions(formatting);
2353
2353
  const fieldChar = (type, extra = {}) => new TextRun({
2354
2354
  children: [
@@ -2367,6 +2367,9 @@ function complexField(instruction, formatting, leading) {
2367
2367
  fieldChar("begin", leading),
2368
2368
  new TextRun({ children: [instrText], ...options }),
2369
2369
  fieldChar("separate"),
2370
+ // A sequence number is the one field this pipeline can compute, so its
2371
+ // result is written: a reader that never updates fields shows the count.
2372
+ ...cachedText !== void 0 ? [new TextRun({ text: cachedText, ...options })] : [],
2370
2373
  fieldChar("end")
2371
2374
  ];
2372
2375
  }
@@ -2477,13 +2480,18 @@ function inlineChildren(children, resources = /* @__PURE__ */ new Map()) {
2477
2480
  out.push(new SimpleField(child.instruction, child.cachedText));
2478
2481
  break;
2479
2482
  }
2480
- if (!PAGE_FIELDS.has(child.instruction)) {
2483
+ if (!PAGE_FIELDS.has(child.instruction) && !isSequenceField(child.instruction)) {
2481
2484
  throw new Error(
2482
2485
  `the docxjs renderer has no emitter for the field "${child.instruction}"`
2483
2486
  );
2484
2487
  }
2485
2488
  out.push(
2486
- ...complexField(child.instruction, child.formatting, breakOption())
2489
+ ...complexField(
2490
+ child.instruction,
2491
+ child.formatting,
2492
+ breakOption(),
2493
+ child.cachedText
2494
+ )
2487
2495
  );
2488
2496
  break;
2489
2497
  }
@@ -2857,7 +2865,7 @@ function emitBorder(border3) {
2857
2865
  ...border3.spacePoints !== void 0 ? { space: border3.spacePoints } : {}
2858
2866
  };
2859
2867
  }
2860
- var ALIGNMENT2, PAGE_FIELDS, WRAP_TYPE, VERTICAL_ALIGN, TABLE_ANCHOR, HORIZONTAL_POSITION, VERTICAL_POSITION, BORDER_STYLE;
2868
+ var ALIGNMENT2, PAGE_FIELDS, isSequenceField, WRAP_TYPE, VERTICAL_ALIGN, TABLE_ANCHOR, HORIZONTAL_POSITION, VERTICAL_POSITION, BORDER_STYLE;
2861
2869
  var init_emit = __esm({
2862
2870
  "src/renderers/docxjs/emit.ts"() {
2863
2871
  "use strict";
@@ -2870,6 +2878,7 @@ var init_emit = __esm({
2870
2878
  end: AlignmentType.END
2871
2879
  };
2872
2880
  PAGE_FIELDS = /* @__PURE__ */ new Set(["PAGE", "NUMPAGES"]);
2881
+ isSequenceField = (instruction) => /^SEQ [A-Za-z][\w-]* \\\* ARABIC$/.test(instruction);
2873
2882
  WRAP_TYPE = {
2874
2883
  none: TextWrappingType.NONE,
2875
2884
  square: TextWrappingType.SQUARE,
@@ -5298,6 +5307,10 @@ function resolveServiceUrl(propsUrl, servicesUrl, defaultUrl) {
5298
5307
  const withScheme = /^https?:\/\//i.test(raw) ? raw : `http://${raw}`;
5299
5308
  return withScheme.replace(/\/+$/, "");
5300
5309
  }
5310
+ var SERVICE_UNAVAILABLE_CODE = "SERVICE_UNAVAILABLE";
5311
+ function serviceUnavailable(message) {
5312
+ return Object.assign(new Error(message), { code: SERVICE_UNAVAILABLE_CODE });
5313
+ }
5301
5314
  async function postJsonToService(opts) {
5302
5315
  const resolvedHeaders = typeof opts.headers === "function" ? await opts.headers(opts.body) : opts.headers;
5303
5316
  const headers = {
@@ -5317,12 +5330,12 @@ async function postJsonToService(opts) {
5317
5330
  });
5318
5331
  } catch (error) {
5319
5332
  if (error?.name === "AbortError") {
5320
- throw new Error(
5333
+ throw serviceUnavailable(
5321
5334
  `${opts.serviceLabel} timed out after ${timeoutMs}ms at ${opts.url}.`
5322
5335
  );
5323
5336
  }
5324
5337
  const cause = error instanceof Error ? error.message : String(error);
5325
- throw new Error(opts.onUnreachable(opts.url, cause));
5338
+ throw serviceUnavailable(opts.onUnreachable(opts.url, cause));
5326
5339
  } finally {
5327
5340
  clearTimeout(timer);
5328
5341
  }
@@ -5769,13 +5782,25 @@ init_colorUtils();
5769
5782
  init_layoutUtils();
5770
5783
  import {
5771
5784
  chartFamilyResolver,
5785
+ remoteExportNotice,
5786
+ REMOTE_EXPORT_WARNING,
5772
5787
  chartPointsPerPixel,
5773
5788
  POINTS_PER_PIXEL_96DPI,
5774
5789
  withChartFontFaceCss,
5775
5790
  withChartTypography
5776
5791
  } from "@json-to-office/shared";
5777
5792
  var DEFAULT_EXPORT_SERVER_URL = "http://localhost:7801";
5778
- async function generateChart(config, servicesConfig) {
5793
+ function assertExportServerAllowed(serverUrl, servicesConfig, warnings) {
5794
+ const notice = remoteExportNotice(serverUrl, servicesConfig?.allowRemote);
5795
+ if (notice)
5796
+ warnings?.push({
5797
+ component: "highcharts",
5798
+ severity: "warning",
5799
+ message: notice,
5800
+ context: { code: REMOTE_EXPORT_WARNING, serverUrl }
5801
+ });
5802
+ }
5803
+ async function generateChart(config, servicesConfig, warnings) {
5779
5804
  if (!isNodeEnvironment()) {
5780
5805
  throw new Error(
5781
5806
  "Highcharts export server requires a Node.js environment. Chart generation is not available in browser environments."
@@ -5786,6 +5811,7 @@ async function generateChart(config, servicesConfig) {
5786
5811
  servicesConfig?.serverUrl,
5787
5812
  DEFAULT_EXPORT_SERVER_URL
5788
5813
  );
5814
+ assertExportServerAllowed(serverUrl, servicesConfig, warnings);
5789
5815
  const requestBody = {
5790
5816
  infile: config.options,
5791
5817
  type: "png",
@@ -5898,13 +5924,13 @@ function withChartFontFaces(config, theme, faces) {
5898
5924
  theme.fonts.heading.family
5899
5925
  ]);
5900
5926
  }
5901
- async function renderChartToImageProps(props, theme, servicesConfig, chartFonts) {
5927
+ async function renderChartToImageProps(props, theme, servicesConfig, chartFonts, warnings) {
5902
5928
  const config = withChartFontFaces(
5903
5929
  withThemeTypography(withThemeColors(props, theme), theme),
5904
5930
  theme,
5905
5931
  chartFonts
5906
5932
  );
5907
- const chart = await generateChart(config, servicesConfig);
5933
+ const chart = await generateChart(config, servicesConfig, warnings);
5908
5934
  const hasConfigDimensions = config.width !== void 0 || config.height !== void 0;
5909
5935
  return {
5910
5936
  base64: chart.base64DataUri,
@@ -5944,7 +5970,8 @@ async function desugarExternals(document, options) {
5944
5970
  node.props,
5945
5971
  options.theme,
5946
5972
  options.services?.highcharts,
5947
- options.chartFonts
5973
+ options.chartFonts,
5974
+ options.warnings
5948
5975
  )
5949
5976
  });
5950
5977
  }
@@ -8495,6 +8522,9 @@ function parsePlaceholders(normalized, parseOptions) {
8495
8522
  out.push({
8496
8523
  kind: "field",
8497
8524
  instruction: resolved.instruction,
8525
+ ...resolved.cachedText !== void 0 && {
8526
+ cachedText: resolved.cachedText
8527
+ },
8498
8528
  ...formatting ? { formatting } : {}
8499
8529
  });
8500
8530
  }
@@ -8721,6 +8751,7 @@ function compileDocument(structure, layout, warnings = [], images = /* @__PURE__
8721
8751
  nextBookmarkId: CONTENT_BOOKMARK_ID_BASE + 1,
8722
8752
  bookmarkNames: /* @__PURE__ */ new Set(),
8723
8753
  usesStatistic: false,
8754
+ sequences: /* @__PURE__ */ new Map(),
8724
8755
  styleIds: /* @__PURE__ */ new Set([
8725
8756
  ...styles.paragraph.map((s) => s.id),
8726
8757
  ...styles.character.map((s) => s.id)
@@ -10116,7 +10147,20 @@ function compileRuns(props, text, ctx, path3, mode = "inline") {
10116
10147
  return children;
10117
10148
  }
10118
10149
  function placeholderResolver(ctx) {
10119
- return (name) => resolvePlaceholder(name, ctx.generatedAt);
10150
+ return (name) => {
10151
+ const sequence = /^SEQ:([A-Za-z][\w-]*)$/i.exec(name);
10152
+ if (sequence) {
10153
+ const key = sequence[1];
10154
+ const count = (ctx.sequences.get(key) ?? 0) + 1;
10155
+ ctx.sequences.set(key, count);
10156
+ return {
10157
+ kind: "field",
10158
+ instruction: `SEQ ${key} \\* ARABIC`,
10159
+ cachedText: String(count)
10160
+ };
10161
+ }
10162
+ return resolvePlaceholder(name, ctx.generatedAt);
10163
+ };
10120
10164
  }
10121
10165
  function crossReferenceResolver(ctx, path3) {
10122
10166
  return (id, format2, token) => resolveCrossReference(id, format2, token, ctx, path3);
@@ -11986,6 +12030,7 @@ async function processResolvedDocument(document, resolved, themeName, generation
11986
12030
  };
11987
12031
  }
11988
12032
  function createDocumentMetadata(props, generationDate = /* @__PURE__ */ new Date()) {
12033
+ const parsed = props.metadata?.date ? new Date(props.metadata.date) : void 0;
11989
12034
  return {
11990
12035
  title: props.metadata?.title,
11991
12036
  subtitle: props.metadata?.subtitle,
@@ -11994,7 +12039,7 @@ function createDocumentMetadata(props, generationDate = /* @__PURE__ */ new Date
11994
12039
  company: props.metadata?.company,
11995
12040
  version: props.metadata?.version,
11996
12041
  tags: props.metadata?.tags,
11997
- date: props.metadata?.date ? new Date(props.metadata.date) : generationDate
12042
+ date: parsed && !Number.isNaN(parsed.getTime()) ? parsed : generationDate
11998
12043
  };
11999
12044
  }
12000
12045
  async function extractSections(components, context) {
@@ -12086,7 +12131,10 @@ import {
12086
12131
  normalizeHighchartsChart
12087
12132
  } from "@json-to-office/quality";
12088
12133
  import { DEFAULT_DOCX_RENDERER_ID as DEFAULT_DOCX_RENDERER_ID2 } from "@json-to-office/shared-docx";
12089
- import { designColors as designColors2, resolveDesignColor as resolveDesignColor2 } from "@json-to-office/shared";
12134
+ import {
12135
+ designColors as designColors2,
12136
+ resolveDesignColor as resolveDesignColor2
12137
+ } from "@json-to-office/shared";
12090
12138
 
12091
12139
  // src/json/normalizer.ts
12092
12140
  function normalizeComponent(component) {
@@ -12180,12 +12228,41 @@ import {
12180
12228
  readBlockDefinitions,
12181
12229
  blockValueAt,
12182
12230
  isBlockRecord,
12183
- toAuthoredBlockPointer
12231
+ toAuthoredBlockPointer,
12232
+ blockPointerKey,
12233
+ blockSlotRoles
12184
12234
  } from "@json-to-office/shared";
12185
- import { blockSlotBudgets } from "@json-to-office/shared";
12235
+ import { blockSlotBudgets, blockSlotRoles as blockSlotRoles2 } from "@json-to-office/shared";
12186
12236
  import { validateDocument as validateDocument2 } from "@json-to-office/shared-docx";
12187
12237
  var toAuthoredPointer = toAuthoredBlockPointer;
12188
- function docxBlockContext(document, theme, path3 = "") {
12238
+ function documentSourceLines(document) {
12239
+ if (!isBlockRecord(document)) return [];
12240
+ const invocations = [];
12241
+ const walk2 = (value, path3) => {
12242
+ if (Array.isArray(value)) {
12243
+ value.forEach((item, index) => walk2(item, `${path3}/${index}`));
12244
+ return;
12245
+ }
12246
+ if (!isBlockRecord(value) || value.enabled === false) return;
12247
+ if (value.name === "block") invocations.push(path3);
12248
+ for (const [key, item] of Object.entries(value)) {
12249
+ if (path3 === "/props" && key === "blocks") continue;
12250
+ walk2(item, `${path3}/${blockPointerKey(key)}`);
12251
+ }
12252
+ };
12253
+ walk2(document, "");
12254
+ const seen = /* @__PURE__ */ new Set();
12255
+ const lines = [];
12256
+ for (const slot of blockSlotRoles(document, invocations)) {
12257
+ if (slot.role !== "source" || typeof slot.value !== "string") continue;
12258
+ const text = slot.value.trim();
12259
+ if (text === "" || seen.has(text)) continue;
12260
+ seen.add(text);
12261
+ lines.push({ text, path: slot.path });
12262
+ }
12263
+ return lines;
12264
+ }
12265
+ function docxBlockContext(document, theme, path3, sources) {
12189
12266
  const index = /^\/children\/(\d+)/.exec(path3)?.[1];
12190
12267
  const section2 = index === void 0 ? void 0 : blockValueAt(document, `/children/${index}`);
12191
12268
  const page = isBlockRecord(section2) && isBlockRecord(section2.props) && isBlockRecord(section2.props.page) ? section2.props.page : {};
@@ -12205,26 +12282,46 @@ function docxBlockContext(document, theme, path3 = "") {
12205
12282
  return {
12206
12283
  document: blockValueAt(document, "/props/metadata") ?? {},
12207
12284
  page: { width, height },
12208
- section: {}
12285
+ section: {},
12286
+ sources: sources.map((line) => line.text)
12287
+ };
12288
+ }
12289
+ function docxBlockContextSources(sources) {
12290
+ return {
12291
+ "/document": "/props/metadata",
12292
+ ...Object.fromEntries(
12293
+ sources.map((line, index) => [`/sources/${index}`, line.path])
12294
+ )
12209
12295
  };
12210
12296
  }
12211
- function createDocxBlockEvaluator(document, theme, extra = {}) {
12297
+ function createDocxBlockEvaluator(document, theme, extra = {}, sources = documentSourceLines(document)) {
12212
12298
  return new JsonBlockEvaluator(readBlockDefinitions(document), {
12213
12299
  format: "docx",
12214
12300
  theme,
12215
- contextAt: (path3) => docxBlockContext(document, theme, path3),
12216
- contextSources: { "/document": "/props/metadata" },
12301
+ contextAt: (path3) => docxBlockContext(document, theme, path3, sources),
12302
+ contextSources: docxBlockContextSources(sources),
12217
12303
  measure: (axis, unit, context) => Number(blockValueAt(context, `/page/${axis}`)) / (unit === "twip" ? 1 : unit === "in" ? 1440 : 20),
12218
12304
  ...extra
12219
12305
  });
12220
12306
  }
12221
12307
  function expandBlocks(document, theme) {
12222
12308
  const effects = [];
12223
- const evaluator = createDocxBlockEvaluator(document, theme, {
12224
- onSection: (effect) => effects.push(effect)
12225
- });
12309
+ const sources = documentSourceLines(document);
12310
+ const evaluator = createDocxBlockEvaluator(
12311
+ document,
12312
+ theme,
12313
+ { onSection: (effect) => effects.push(effect) },
12314
+ sources
12315
+ );
12226
12316
  const expanded = evaluator.expand(document);
12227
- return finishDocxBlocks(expanded, document, theme, evaluator, effects);
12317
+ return finishDocxBlocks(
12318
+ expanded,
12319
+ document,
12320
+ theme,
12321
+ evaluator,
12322
+ effects,
12323
+ sources
12324
+ );
12228
12325
  }
12229
12326
  function validateEffects(document, effects) {
12230
12327
  for (const effect of effects) {
@@ -12245,7 +12342,7 @@ function validateEffects(document, effects) {
12245
12342
  ]);
12246
12343
  }
12247
12344
  }
12248
- function finishDocxBlocks(expanded, document, theme, evaluator, effects, validate = true) {
12345
+ function finishDocxBlocks(expanded, document, theme, evaluator, effects, sources, validate = true) {
12249
12346
  if (isBlockRecord(expanded) && Array.isArray(expanded.children)) {
12250
12347
  let inherited;
12251
12348
  expanded.children.forEach((section2, index) => {
@@ -12283,11 +12380,11 @@ function finishDocxBlocks(expanded, document, theme, evaluator, effects, validat
12283
12380
  const environment = {
12284
12381
  ...chrome.environment,
12285
12382
  context: {
12286
- ...docxBlockContext(document, theme, path3),
12383
+ ...docxBlockContext(document, theme, path3, sources),
12287
12384
  section: { tracker }
12288
12385
  },
12289
12386
  contextSources: {
12290
- "/document": "/props/metadata",
12387
+ ...docxBlockContextSources(sources),
12291
12388
  "/section/tracker": trackerSource
12292
12389
  }
12293
12390
  };
@@ -12331,10 +12428,16 @@ function finishDocxBlocks(expanded, document, theme, evaluator, effects, validat
12331
12428
  }
12332
12429
  async function expandBlocksWithPlugins(document, theme, plugins, render, preserve = /* @__PURE__ */ new Set()) {
12333
12430
  const effects = [];
12334
- const evaluator = createDocxBlockEvaluator(document, theme, {
12335
- reservedNames: [...plugins],
12336
- onSection: (effect) => effects.push(effect)
12337
- });
12431
+ const sources = documentSourceLines(document);
12432
+ const evaluator = createDocxBlockEvaluator(
12433
+ document,
12434
+ theme,
12435
+ {
12436
+ reservedNames: [...plugins],
12437
+ onSection: (effect) => effects.push(effect)
12438
+ },
12439
+ sources
12440
+ );
12338
12441
  const walk2 = (value) => composeBlocksWithPlugins(evaluator, value, {
12339
12442
  plugins,
12340
12443
  render,
@@ -12347,6 +12450,7 @@ async function expandBlocksWithPlugins(document, theme, plugins, render, preserv
12347
12450
  theme,
12348
12451
  evaluator,
12349
12452
  effects,
12453
+ sources,
12350
12454
  false
12351
12455
  );
12352
12456
  const second = await walk2(finished.document);
@@ -12446,7 +12550,8 @@ function chartFact(node, props, path3, paletteTokens) {
12446
12550
  kind: "docx/chart",
12447
12551
  path: path3,
12448
12552
  componentName: typeof node.name === "string" ? node.name : "",
12449
- paletteTokens
12553
+ paletteTokens,
12554
+ generated: false
12450
12555
  };
12451
12556
  if (node.name === "highcharts") {
12452
12557
  const shape = normalizeHighchartsChart(props.options);
@@ -12457,7 +12562,11 @@ function chartFact(node, props, path3, paletteTokens) {
12457
12562
  threeD: shape.threeD,
12458
12563
  seriesCount: shape.seriesCount,
12459
12564
  categoryCount: shape.categoryCount,
12460
- seriesColorsStated: shape.seriesColorsStated,
12565
+ // A config that names no `colors` is painted in the theme's chart
12566
+ // palette at render, so the series are the document's whenever the
12567
+ // theme has a palette to give; only a theme with none leaves them to
12568
+ // the export server's default.
12569
+ seriesColorsStated: shape.seriesColorsStated || paletteTokens.length > 0,
12461
12570
  seriesColorsPath: `${path3}/props/options`,
12462
12571
  ...shape.valueAxisMin !== void 0 && {
12463
12572
  valueAxisMin: shape.valueAxisMin
@@ -12829,6 +12938,11 @@ function prepareDocxQualityDocument(document, options = {}) {
12829
12938
  ...fact.relatedPaths && { relatedPaths: fact.relatedPaths }
12830
12939
  };
12831
12940
  };
12941
+ const annotatedInvocations = new Set(
12942
+ blockSlotRoles2(themed.document, expanded.blocks).filter(
12943
+ (slot) => (slot.role === "takeaway" || slot.role === "source") && typeof slot.value === "string" && slot.value.trim() !== ""
12944
+ ).map((slot) => slot.invocation)
12945
+ );
12832
12946
  for (const budget of blockSlotBudgets(themed.document, expanded.blocks)) {
12833
12947
  addFact({
12834
12948
  id: `docx:block-slot:${budget.path}`,
@@ -12836,6 +12950,38 @@ function prepareDocxQualityDocument(document, options = {}) {
12836
12950
  ...budget
12837
12951
  });
12838
12952
  }
12953
+ for (const role of blockSlotRoles2(themed.document, expanded.blocks)) {
12954
+ addFact({
12955
+ id: `docx:chrome-slot:${role.path}`,
12956
+ kind: "docx/chrome-slot",
12957
+ path: role.path,
12958
+ relatedPaths: [role.invocation],
12959
+ block: role.block,
12960
+ slot: role.slot,
12961
+ role: role.role,
12962
+ present: slotIsFilled(role.value),
12963
+ invocation: role.invocation
12964
+ });
12965
+ }
12966
+ const topLevel = Array.isArray(context.document.children) ? context.document.children : [];
12967
+ let inherited = {};
12968
+ topLevel.forEach((node, index) => {
12969
+ if (node?.name !== "section") return;
12970
+ const props = asRecord(node.props) ?? {};
12971
+ const part = (kind) => props[kind] === "linkToPrevious" ? inherited[kind] : props[kind];
12972
+ const header = part("header");
12973
+ const footer = part("footer");
12974
+ inherited = { header, footer };
12975
+ addFact({
12976
+ id: `docx:section-chrome:${index}`,
12977
+ kind: "docx/section-chrome",
12978
+ path: `/children/${index}`,
12979
+ index,
12980
+ header: partPresent(header),
12981
+ footer: partPresent(footer),
12982
+ pageNumber: hasPageField(header) || hasPageField(footer)
12983
+ });
12984
+ });
12839
12985
  const paletteHexes = {};
12840
12986
  const visualColors = designColors2(
12841
12987
  resolved.theme.colors,
@@ -12940,7 +13086,27 @@ function prepareDocxQualityDocument(document, options = {}) {
12940
13086
  }
12941
13087
  if (node.name === "chart" || node.name === "highcharts") {
12942
13088
  const fact = chartFact(node, props, path3, paletteTokens);
12943
- if (fact) addFact(fact);
13089
+ if (fact) {
13090
+ const authored = authoredPath(path3);
13091
+ const invocation = expanded.blocks.filter(
13092
+ (pointer) => authored === pointer || authored.startsWith(`${pointer}/`)
13093
+ ).sort((a, b) => b.length - a.length)[0];
13094
+ const annotated = invocation !== void 0 && annotatedInvocations.has(invocation);
13095
+ addFact({
13096
+ ...fact,
13097
+ generated: !["chart", "highcharts"].includes(
13098
+ String(asRecord(nodeAtPointer(themed.document, authored))?.name)
13099
+ ),
13100
+ seriesColorsPath: authoredPath(fact.seriesColorsPath),
13101
+ ...fact.annotation && {
13102
+ annotation: {
13103
+ ...fact.annotation,
13104
+ path: authoredPath(fact.annotation.path),
13105
+ stated: fact.annotation.stated || annotated
13106
+ }
13107
+ }
13108
+ });
13109
+ }
12944
13110
  }
12945
13111
  if (node.name === "paragraph" || node.name === "text-box") {
12946
13112
  const floating = asRecord(props.floating);
@@ -13010,6 +13176,17 @@ function prepareDocxQualityDocument(document, options = {}) {
13010
13176
  }
13011
13177
  };
13012
13178
  }
13179
+ function slotIsFilled(value) {
13180
+ if (typeof value === "string") return value.trim() !== "";
13181
+ return value !== void 0 && value !== null && value !== false && (!Array.isArray(value) || value.length > 0);
13182
+ }
13183
+ function partPresent(part) {
13184
+ return Array.isArray(part) && part.length > 0;
13185
+ }
13186
+ var PAGE_FIELD = /\{(PAGE|PAGE_NUMBER|TOTAL_PAGES|NUMPAGES)\}/;
13187
+ function hasPageField(part) {
13188
+ return Array.isArray(part) && PAGE_FIELD.test(JSON.stringify(part));
13189
+ }
13013
13190
 
13014
13191
  // src/core/generateFromIr.ts
13015
13192
  var UncompiledComponentError = class extends Error {
@@ -13062,7 +13239,8 @@ async function compileDocumentScoped(document, options, warnings) {
13062
13239
  ...options.services ? { services: options.services } : {},
13063
13240
  ...options.baseDir !== void 0 ? { baseDir: options.baseDir } : {},
13064
13241
  ...visualFonts.length > 0 ? { visualFonts } : {},
13065
- ...chartFonts.length > 0 ? { chartFonts } : {}
13242
+ ...chartFonts.length > 0 ? { chartFonts } : {},
13243
+ warnings
13066
13244
  });
13067
13245
  const resolved = desugared === context.document ? prepared.model.document : resolveDocumentTree(desugared, context.theme);
13068
13246
  const structure = await processResolvedDocument(