@json-to-office/core-docx 0.29.0 → 0.31.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":"createDocumentGenerator.d.ts","sourceRoot":"","sources":["../../src/plugin/createDocumentGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAK7C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9E,OAAO,KAAK,EAEV,wBAAwB,EAOxB,2BAA2B,EAC5B,MAAM,SAAS,CAAC;AAmBjB;;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,4CAA4C;IAC5C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,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,GAAG,IAAI,CAAC;IAC5B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAyoBD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,wBAAwB,CAAC,SAAS,EAAE,CAAC,CAiBvC"}
1
+ {"version":3,"file":"createDocumentGenerator.d.ts","sourceRoot":"","sources":["../../src/plugin/createDocumentGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAK7C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9E,OAAO,KAAK,EAEV,wBAAwB,EAQxB,2BAA2B,EAC5B,MAAM,SAAS,CAAC;AAmBjB;;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,4CAA4C;IAC5C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,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,GAAG,IAAI,CAAC;IAC5B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA8sBD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,wBAAwB,CAAC,SAAS,EAAE,CAAC,CAiBvC"}
@@ -4442,6 +4442,26 @@ function componentHasRevision(component) {
4442
4442
  import { createHash as createHash3 } from "crypto";
4443
4443
  var componentCache = null;
4444
4444
  var cacheKeyGen = null;
4445
+ var bypassStats = /* @__PURE__ */ new Map();
4446
+ function recordBypass(type, reason) {
4447
+ const entry = bypassStats.get(type);
4448
+ if (entry) {
4449
+ entry.renders++;
4450
+ } else {
4451
+ bypassStats.set(type, { renders: 1, reason });
4452
+ }
4453
+ }
4454
+ var DATE_INDEPENDENT_PLACEHOLDERS = /* @__PURE__ */ new Set(["PAGE", "TOTAL_PAGES"]);
4455
+ function usesDateSensitivePlaceholder(serialized) {
4456
+ const placeholderRegex = /\{([^}{]+)\}/g;
4457
+ let match;
4458
+ while ((match = placeholderRegex.exec(serialized)) !== null) {
4459
+ const name = match[1].toUpperCase();
4460
+ if (DATE_INDEPENDENT_PLACEHOLDERS.has(name)) continue;
4461
+ if (PlaceholderRegistry.has(name)) return true;
4462
+ }
4463
+ return false;
4464
+ }
4445
4465
  function createThemeHash(theme) {
4446
4466
  const themeString = JSON.stringify(theme);
4447
4467
  return createHash3("sha256").update(themeString).digest("hex").substring(0, 8);
@@ -4477,22 +4497,31 @@ function initializeComponentCache(cache) {
4477
4497
  }
4478
4498
  }
4479
4499
  async function renderComponentWithCache(component, theme, themeName, context, bypassCache = false) {
4480
- const forceBypassForType = component.name === "toc" || component.name === "section" || component.name === "visual" || component.name === "heading" || // Both explicit lists and markdown-list paragraphs register numbering in
4481
- // the current document scope. Cached paragraphs can otherwise reference
4482
- // definitions that only existed in a previous render.
4483
- component.name === "list" || component.name === "paragraph" || "id" in component || componentHasRevision(component);
4500
+ const bypassReason = componentHasRevision(
4501
+ component
4502
+ ) ? "revision-ids" : "id" in component ? "bookmark-id" : component.name === "toc" || component.name === "section" || component.name === "visual" || component.name === "heading" || // Both explicit lists and markdown-list paragraphs register
4503
+ // numbering in the current document scope. Cached paragraphs can
4504
+ // otherwise reference definitions that only existed in a previous
4505
+ // render.
4506
+ component.name === "list" || component.name === "paragraph" ? "dynamic-context" : null;
4484
4507
  if (!componentCache) {
4485
4508
  initializeComponentCache();
4486
4509
  }
4487
- if (!componentCache || bypassCache || forceBypassForType || !componentCache.getConfig().enabled) {
4510
+ if (bypassReason !== null) {
4511
+ recordBypass(component.name, bypassReason);
4512
+ return renderComponent(component, theme, themeName, context);
4513
+ }
4514
+ if (!componentCache || bypassCache || !componentCache.getConfig().enabled) {
4488
4515
  return renderComponent(component, theme, themeName, context);
4489
4516
  }
4490
4517
  const componentProps = JSON.stringify(component.props || {});
4491
4518
  const themeHash = createThemeHash(theme);
4492
4519
  const contextKey = context?.section ? `${context.section.currentLayout}:${context.section.columnCount}` : "no-section";
4493
- const generationDateKey = getGenerationDate().toISOString();
4494
4520
  const baseDirKey = getBaseDir() ?? "";
4495
4521
  const childrenKey = "children" in component && component.children ? `:children:${JSON.stringify(component.children)}` : "";
4522
+ const generationDateKey = usesDateSensitivePlaceholder(
4523
+ componentProps + childrenKey
4524
+ ) ? getGenerationDate().toISOString() : "no-date";
4496
4525
  const cacheKey = `component:${component.name}:${themeHash}:${contextKey}:${generationDateKey}:${baseDirKey}:${componentProps}${childrenKey}`;
4497
4526
  const cached = await componentCache.get(cacheKey);
4498
4527
  if (cached) {
@@ -7355,6 +7384,11 @@ function createLimiter(max) {
7355
7384
  var DEFAULT_FALLBACK_CONCURRENCY = 4;
7356
7385
  var BATCH_TIMEOUT_BASE_MS = 3e4;
7357
7386
  var BATCH_TIMEOUT_PER_SLIDE_MS = 1e4;
7387
+ var prepassStats = {
7388
+ documents: 0,
7389
+ collected: 0,
7390
+ unique: 0
7391
+ };
7358
7392
  function collectVisualProps(root) {
7359
7393
  const found = [];
7360
7394
  const seen = /* @__PURE__ */ new WeakSet();
@@ -7431,6 +7465,9 @@ async function prerasterizeVisuals(root, serviceConfig, options = {}) {
7431
7465
  }
7432
7466
  }
7433
7467
  if (targets.size === 0) return map;
7468
+ prepassStats.documents++;
7469
+ prepassStats.collected += visuals.length;
7470
+ prepassStats.unique += targets.size;
7434
7471
  const unique = [...targets.values()];
7435
7472
  const limit = createLimiter(
7436
7473
  Math.max(1, options.concurrency ?? DEFAULT_FALLBACK_CONCURRENCY)
@@ -8284,70 +8321,104 @@ function createBuilderImpl(state) {
8284
8321
  }
8285
8322
  return new Set(list);
8286
8323
  }
8287
- async function generate(document, options) {
8288
- try {
8289
- const preserveSet = resolvePreserveSet(options);
8290
- const rootIn = document;
8291
- const internalDocument = rootIn.props === void 0 ? { ...rootIn, props: {} } : rootIn;
8292
- const vOpts = {
8293
- ...state.validation,
8294
- ...options?.validation
8295
- };
8296
- if (vOpts.enabled !== false) {
8297
- const result = validateDocument(
8298
- internalDocument,
8299
- state.components,
8300
- { allowUnknownFields: vOpts.allowUnknownFields }
8324
+ async function expandDocument(document, options) {
8325
+ const preserveSet = resolvePreserveSet(options);
8326
+ const rootIn = document;
8327
+ const internalDocument = rootIn.props === void 0 ? { ...rootIn, props: {} } : rootIn;
8328
+ const vOpts = {
8329
+ ...state.validation,
8330
+ ...options?.validation
8331
+ };
8332
+ if (vOpts.enabled !== false) {
8333
+ const result = validateDocument(
8334
+ internalDocument,
8335
+ state.components,
8336
+ { allowUnknownFields: vOpts.allowUnknownFields }
8337
+ );
8338
+ if (!result.valid) {
8339
+ throw new ComponentValidationError2(
8340
+ (result.errors ?? []).map((e) => ({
8341
+ path: e.path ?? "",
8342
+ message: e.message
8343
+ })),
8344
+ internalDocument
8301
8345
  );
8302
- if (!result.valid) {
8303
- throw new ComponentValidationError2(
8304
- (result.errors ?? []).map((e) => ({
8305
- path: e.path ?? "",
8306
- message: e.message
8307
- })),
8308
- internalDocument
8309
- );
8310
- }
8311
8346
  }
8312
- const validateEmitted = vOpts.enabled === false ? void 0 : (emitted, componentLabel) => {
8313
- const result = validateDocument(
8314
- { ...internalDocument, children: emitted },
8315
- state.components,
8316
- { allowUnknownFields: vOpts.allowUnknownFields }
8347
+ }
8348
+ const validateEmitted = vOpts.enabled === false ? void 0 : (emitted, componentLabel) => {
8349
+ const result = validateDocument(
8350
+ { ...internalDocument, children: emitted },
8351
+ state.components,
8352
+ { allowUnknownFields: vOpts.allowUnknownFields }
8353
+ );
8354
+ if (!result.valid) {
8355
+ throw new ComponentValidationError2(
8356
+ (result.errors ?? []).map((e) => ({
8357
+ path: e.path ?? "",
8358
+ message: `custom component '${componentLabel}' emitted invalid output \u2014 ${e.message}`
8359
+ })),
8360
+ emitted
8317
8361
  );
8318
- if (!result.valid) {
8319
- throw new ComponentValidationError2(
8320
- (result.errors ?? []).map((e) => ({
8321
- path: e.path ?? "",
8322
- message: `custom component '${componentLabel}' emitted invalid output \u2014 ${e.message}`
8323
- })),
8324
- emitted
8325
- );
8326
- }
8362
+ }
8363
+ };
8364
+ const warnings = [];
8365
+ const {
8366
+ document: modedRoot,
8367
+ theme: modedTheme,
8368
+ themeName
8369
+ } = resolveThemeContext(internalDocument, {
8370
+ customThemes: state.customThemes,
8371
+ fonts: state.fonts,
8372
+ warnings,
8373
+ resolveNamedTheme: resolveDocumentTheme
8374
+ });
8375
+ const processed = await processDocumentComponents(
8376
+ modedRoot.children || [],
8377
+ preserveSet,
8378
+ warnings,
8379
+ modedTheme,
8380
+ validateEmitted
8381
+ );
8382
+ const processedDocument = {
8383
+ ...modedRoot,
8384
+ children: processed.standard
8385
+ };
8386
+ const [modedDoc] = normalizeDocument(processedDocument);
8387
+ return {
8388
+ modedRoot,
8389
+ modedTheme,
8390
+ themeName,
8391
+ processed,
8392
+ modedDoc,
8393
+ warnings,
8394
+ preserveSet
8395
+ };
8396
+ }
8397
+ async function expandStandardDefinition(document, options) {
8398
+ try {
8399
+ const { modedDoc, warnings } = await expandDocument(document, options);
8400
+ return {
8401
+ standardDefinition: modedDoc,
8402
+ warnings: warnings.length > 0 ? warnings : null
8327
8403
  };
8328
- const warnings = [];
8404
+ } catch (error) {
8405
+ if (state.debug) {
8406
+ console.error("Document expansion error:", error);
8407
+ }
8408
+ throw error;
8409
+ }
8410
+ }
8411
+ async function generate(document, options) {
8412
+ try {
8329
8413
  const {
8330
- document: modedRoot,
8331
- theme: modedTheme,
8332
- themeName
8333
- } = resolveThemeContext(internalDocument, {
8334
- customThemes: state.customThemes,
8335
- fonts: state.fonts,
8336
- warnings,
8337
- resolveNamedTheme: resolveDocumentTheme
8338
- });
8339
- const processed = await processDocumentComponents(
8340
- modedRoot.children || [],
8341
- preserveSet,
8342
- warnings,
8414
+ modedRoot,
8343
8415
  modedTheme,
8344
- validateEmitted
8345
- );
8346
- const processedDocument = {
8347
- ...modedRoot,
8348
- children: processed.standard
8349
- };
8350
- const [modedDoc] = normalizeDocument(processedDocument);
8416
+ themeName,
8417
+ processed,
8418
+ modedDoc,
8419
+ warnings,
8420
+ preserveSet
8421
+ } = await expandDocument(document, options);
8351
8422
  await resolveDocumentFonts(modedDoc, modedTheme, state.fonts, warnings);
8352
8423
  const packageOptions = {
8353
8424
  deterministic: options?.deterministic ?? state.deterministic,
@@ -8474,6 +8545,7 @@ function createBuilderImpl(state) {
8474
8545
  generate,
8475
8546
  generateBuffer,
8476
8547
  generateFile,
8548
+ expandStandardDefinition,
8477
8549
  getComponentNames,
8478
8550
  validate,
8479
8551
  generateSchema,