@superdoc-dev/cli 0.16.0-next.21 → 0.16.0-next.22

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.
Files changed (2) hide show
  1. package/dist/index.js +919 -659
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -230111,7 +230111,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
230111
230111
  init_remark_gfm_BhnWr3yf_es();
230112
230112
  });
230113
230113
 
230114
- // ../../packages/superdoc/dist/chunks/src-CF4og_LY.es.js
230114
+ // ../../packages/superdoc/dist/chunks/src-B1aSE-tB.es.js
230115
230115
  function deleteProps(obj, propOrProps) {
230116
230116
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
230117
230117
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -270389,6 +270389,187 @@ function computeTabWidth(currentPos, justification, tabs, hangingIndent, firstLi
270389
270389
  tabWidth = nextDefaultTabStop - currentPos;
270390
270390
  return tabWidth;
270391
270391
  }
270392
+ function isSettled(status) {
270393
+ return SETTLED_STATUSES.includes(status);
270394
+ }
270395
+ function normalizeFamilyKey$2(family$1) {
270396
+ return family$1.trim().replace(/^["']|["']$/g, "").toLowerCase();
270397
+ }
270398
+ function splitStack(cssFontFamily) {
270399
+ return cssFontFamily.split(",").map((part) => part.trim()).filter(Boolean);
270400
+ }
270401
+ function createFontResolver() {
270402
+ return new FontResolver;
270403
+ }
270404
+ function resolveFontFamily2(logicalFamily) {
270405
+ return defaultResolver.resolveFontFamily(logicalFamily);
270406
+ }
270407
+ function resolvePhysicalFamily(cssFontFamily) {
270408
+ return defaultResolver.resolvePhysicalFamily(cssFontFamily);
270409
+ }
270410
+ function resolvePrimaryPhysicalFamily(family$1) {
270411
+ return defaultResolver.resolvePrimaryPhysicalFamily(family$1);
270412
+ }
270413
+ function getFontConfigVersion() {
270414
+ return fontConfigVersion;
270415
+ }
270416
+ function bumpFontConfigVersion() {
270417
+ return fontConfigVersion += 1;
270418
+ }
270419
+ function fourFaces(filePrefix) {
270420
+ return [
270421
+ {
270422
+ weight: "normal",
270423
+ style: "normal",
270424
+ file: `${filePrefix}-Regular.woff2`
270425
+ },
270426
+ {
270427
+ weight: "bold",
270428
+ style: "normal",
270429
+ file: `${filePrefix}-Bold.woff2`
270430
+ },
270431
+ {
270432
+ weight: "normal",
270433
+ style: "italic",
270434
+ file: `${filePrefix}-Italic.woff2`
270435
+ },
270436
+ {
270437
+ weight: "bold",
270438
+ style: "italic",
270439
+ file: `${filePrefix}-BoldItalic.woff2`
270440
+ }
270441
+ ];
270442
+ }
270443
+ function family(name, filePrefix, license) {
270444
+ return {
270445
+ family: name,
270446
+ license,
270447
+ faces: fourFaces(filePrefix)
270448
+ };
270449
+ }
270450
+ function withTrailingSlash(base5) {
270451
+ return base5.endsWith("/") ? base5 : `${base5}/`;
270452
+ }
270453
+ function joinUrl(base5, file) {
270454
+ return `${withTrailingSlash(base5)}${file}`;
270455
+ }
270456
+ function weightToken(weight) {
270457
+ return weight === "bold" ? "700" : "400";
270458
+ }
270459
+ function bundledAssetSignature(resolve3) {
270460
+ const family$1 = BUNDLED_MANIFEST[0];
270461
+ const face = family$1?.faces[0];
270462
+ if (!family$1 || !face)
270463
+ return "";
270464
+ return resolve3({
270465
+ file: face.file,
270466
+ family: family$1.family,
270467
+ weight: weightToken(face.weight),
270468
+ style: face.style,
270469
+ source: "bundled-substitute"
270470
+ });
270471
+ }
270472
+ function installBundledSubstitutes(registry2, options = {}) {
270473
+ const resolve3 = options.resolveAssetUrl ?? ((context) => joinUrl(options.assetBaseUrl ?? defaultAssetBase, context.file));
270474
+ const signature = bundledAssetSignature(resolve3);
270475
+ const installed = installedRegistries.get(registry2);
270476
+ if (installed !== undefined) {
270477
+ if (installed !== signature)
270478
+ console.warn(`[superdoc] bundled fonts are already registered for this document from "${installed}"; a later fonts config resolving to "${signature}" is ignored. Use one fonts.assetBaseUrl / fonts.resolveAssetUrl per document.`);
270479
+ return;
270480
+ }
270481
+ installedRegistries.set(registry2, signature);
270482
+ for (const family$1 of BUNDLED_MANIFEST)
270483
+ for (const face of family$1.faces) {
270484
+ const context = {
270485
+ file: face.file,
270486
+ family: family$1.family,
270487
+ weight: weightToken(face.weight),
270488
+ style: face.style,
270489
+ source: "bundled-substitute"
270490
+ };
270491
+ registry2.register({
270492
+ family: family$1.family,
270493
+ source: `url(${resolve3(context)})`,
270494
+ descriptors: {
270495
+ weight: face.weight,
270496
+ style: face.style
270497
+ }
270498
+ });
270499
+ }
270500
+ }
270501
+ function buildFontReport(logicalFamilies, registry2, resolver2) {
270502
+ const seen = /* @__PURE__ */ new Set;
270503
+ const report = [];
270504
+ for (const logical of logicalFamilies) {
270505
+ if (!logical || seen.has(logical))
270506
+ continue;
270507
+ seen.add(logical);
270508
+ const { physicalFamily, reason } = resolver2 ? resolver2.resolveFontFamily(logical) : resolveFontFamily2(logical);
270509
+ const loadStatus = registry2.getStatus(physicalFamily);
270510
+ report.push({
270511
+ logicalFamily: logical,
270512
+ physicalFamily,
270513
+ reason,
270514
+ loadStatus,
270515
+ exportFamily: logical,
270516
+ missing: isSettled(loadStatus) && loadStatus !== "loaded"
270517
+ });
270518
+ }
270519
+ return report;
270520
+ }
270521
+ function quoteFamily(family$1) {
270522
+ return `"${family$1.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
270523
+ }
270524
+ function canonicalizeFontSource(source) {
270525
+ const match$1 = /^\s*url\(\s*([\s\S]*?)\s*\)\s*$/i.exec(source);
270526
+ if (!match$1)
270527
+ return source;
270528
+ let inner = match$1[1].trim();
270529
+ if (inner.startsWith('"') && inner.endsWith('"') || inner.startsWith("'") && inner.endsWith("'"))
270530
+ inner = inner.slice(1, -1);
270531
+ return `url(${JSON.stringify(inner)})`;
270532
+ }
270533
+ function normalizeFamilyKey$1(family$1) {
270534
+ return family$1.trim().replace(/^["']|["']$/g, "").toLowerCase();
270535
+ }
270536
+ function normalizeWeight(weight) {
270537
+ if (weight === undefined)
270538
+ return "400";
270539
+ const w = String(weight).trim().toLowerCase();
270540
+ if (w === "bold" || w === "bolder")
270541
+ return "700";
270542
+ const n = Number(w);
270543
+ return Number.isFinite(n) && n >= 600 ? "700" : "400";
270544
+ }
270545
+ function normalizeStyle$1(style2) {
270546
+ if (!style2)
270547
+ return "normal";
270548
+ const s2 = style2.trim().toLowerCase();
270549
+ return s2.startsWith("italic") || s2.startsWith("oblique") ? "italic" : "normal";
270550
+ }
270551
+ function faceKeyOf$1(family$1, weight, style2) {
270552
+ return `${normalizeFamilyKey$1(family$1)}|${weight}|${style2}`;
270553
+ }
270554
+ function faceProbe(family$1, weight, style2, size$1) {
270555
+ return `${style2 === "italic" ? "italic " : ""}${weight} ${size$1} ${quoteFamily(family$1)}`;
270556
+ }
270557
+ function getFontRegistryFor(fontSet, FontFaceCtor) {
270558
+ if (!fontSet) {
270559
+ if (!domlessRegistry)
270560
+ domlessRegistry = new FontRegistry({});
270561
+ return domlessRegistry;
270562
+ }
270563
+ let registry2 = registriesByFontSet.get(fontSet);
270564
+ if (!registry2) {
270565
+ registry2 = new FontRegistry({
270566
+ fontSet,
270567
+ FontFaceCtor
270568
+ });
270569
+ registriesByFontSet.set(fontSet, registry2);
270570
+ }
270571
+ return registry2;
270572
+ }
270392
270573
  function isResolvedFragmentWithBorders(item) {
270393
270574
  return item !== undefined && item.kind === "fragment" && "paragraphBorders" in item && item.paragraphBorders !== undefined;
270394
270575
  }
@@ -270598,178 +270779,6 @@ function renderPartialEmbeddedTable(params$1) {
270598
270779
  hasSdtContainerChrome: tableResult.hasSdtContainerChrome
270599
270780
  };
270600
270781
  }
270601
- function isSettled(status) {
270602
- return SETTLED_STATUSES.includes(status);
270603
- }
270604
- function normalizeFamilyKey$2(family$1) {
270605
- return family$1.trim().replace(/^["']|["']$/g, "").toLowerCase();
270606
- }
270607
- function splitStack(cssFontFamily) {
270608
- return cssFontFamily.split(",").map((part) => part.trim()).filter(Boolean);
270609
- }
270610
- function createFontResolver() {
270611
- return new FontResolver;
270612
- }
270613
- function resolveFontFamily2(logicalFamily) {
270614
- return defaultResolver.resolveFontFamily(logicalFamily);
270615
- }
270616
- function resolvePhysicalFamily(cssFontFamily) {
270617
- return defaultResolver.resolvePhysicalFamily(cssFontFamily);
270618
- }
270619
- function resolvePrimaryPhysicalFamily(family$1) {
270620
- return defaultResolver.resolvePrimaryPhysicalFamily(family$1);
270621
- }
270622
- function getFontConfigVersion() {
270623
- return fontConfigVersion;
270624
- }
270625
- function bumpFontConfigVersion() {
270626
- return fontConfigVersion += 1;
270627
- }
270628
- function fourFaces(filePrefix) {
270629
- return [
270630
- {
270631
- weight: "normal",
270632
- style: "normal",
270633
- file: `${filePrefix}-Regular.woff2`
270634
- },
270635
- {
270636
- weight: "bold",
270637
- style: "normal",
270638
- file: `${filePrefix}-Bold.woff2`
270639
- },
270640
- {
270641
- weight: "normal",
270642
- style: "italic",
270643
- file: `${filePrefix}-Italic.woff2`
270644
- },
270645
- {
270646
- weight: "bold",
270647
- style: "italic",
270648
- file: `${filePrefix}-BoldItalic.woff2`
270649
- }
270650
- ];
270651
- }
270652
- function family(name, filePrefix, license) {
270653
- return {
270654
- family: name,
270655
- license,
270656
- faces: fourFaces(filePrefix)
270657
- };
270658
- }
270659
- function withTrailingSlash(base5) {
270660
- return base5.endsWith("/") ? base5 : `${base5}/`;
270661
- }
270662
- function joinUrl(base5, file) {
270663
- return `${withTrailingSlash(base5)}${file}`;
270664
- }
270665
- function weightToken(weight) {
270666
- return weight === "bold" ? "700" : "400";
270667
- }
270668
- function bundledAssetSignature(resolve3) {
270669
- const family$1 = BUNDLED_MANIFEST[0];
270670
- const face = family$1?.faces[0];
270671
- if (!family$1 || !face)
270672
- return "";
270673
- return resolve3({
270674
- file: face.file,
270675
- family: family$1.family,
270676
- weight: weightToken(face.weight),
270677
- style: face.style,
270678
- source: "bundled-substitute"
270679
- });
270680
- }
270681
- function installBundledSubstitutes(registry2, options = {}) {
270682
- const resolve3 = options.resolveAssetUrl ?? ((context) => joinUrl(options.assetBaseUrl ?? defaultAssetBase, context.file));
270683
- const signature = bundledAssetSignature(resolve3);
270684
- const installed = installedRegistries.get(registry2);
270685
- if (installed !== undefined) {
270686
- if (installed !== signature)
270687
- console.warn(`[superdoc] bundled fonts are already registered for this document from "${installed}"; a later fonts config resolving to "${signature}" is ignored. Use one fonts.assetBaseUrl / fonts.resolveAssetUrl per document.`);
270688
- return;
270689
- }
270690
- installedRegistries.set(registry2, signature);
270691
- for (const family$1 of BUNDLED_MANIFEST)
270692
- for (const face of family$1.faces) {
270693
- const context = {
270694
- file: face.file,
270695
- family: family$1.family,
270696
- weight: weightToken(face.weight),
270697
- style: face.style,
270698
- source: "bundled-substitute"
270699
- };
270700
- registry2.register({
270701
- family: family$1.family,
270702
- source: `url(${resolve3(context)})`,
270703
- descriptors: {
270704
- weight: face.weight,
270705
- style: face.style
270706
- }
270707
- });
270708
- }
270709
- }
270710
- function buildFontReport(logicalFamilies, registry2, resolver2) {
270711
- const seen = /* @__PURE__ */ new Set;
270712
- const report = [];
270713
- for (const logical of logicalFamilies) {
270714
- if (!logical || seen.has(logical))
270715
- continue;
270716
- seen.add(logical);
270717
- const { physicalFamily, reason } = resolver2 ? resolver2.resolveFontFamily(logical) : resolveFontFamily2(logical);
270718
- const loadStatus = registry2.getStatus(physicalFamily);
270719
- report.push({
270720
- logicalFamily: logical,
270721
- physicalFamily,
270722
- reason,
270723
- loadStatus,
270724
- exportFamily: logical,
270725
- missing: isSettled(loadStatus) && loadStatus !== "loaded"
270726
- });
270727
- }
270728
- return report;
270729
- }
270730
- function quoteFamily(family$1) {
270731
- return `"${family$1.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
270732
- }
270733
- function normalizeFamilyKey$1(family$1) {
270734
- return family$1.trim().replace(/^["']|["']$/g, "").toLowerCase();
270735
- }
270736
- function normalizeWeight(weight) {
270737
- if (weight === undefined)
270738
- return "400";
270739
- const w = String(weight).trim().toLowerCase();
270740
- if (w === "bold" || w === "bolder")
270741
- return "700";
270742
- const n = Number(w);
270743
- return Number.isFinite(n) && n >= 600 ? "700" : "400";
270744
- }
270745
- function normalizeStyle$1(style2) {
270746
- if (!style2)
270747
- return "normal";
270748
- const s2 = style2.trim().toLowerCase();
270749
- return s2.startsWith("italic") || s2.startsWith("oblique") ? "italic" : "normal";
270750
- }
270751
- function faceKeyOf$1(family$1, weight, style2) {
270752
- return `${normalizeFamilyKey$1(family$1)}|${weight}|${style2}`;
270753
- }
270754
- function faceProbe(family$1, weight, style2, size$1) {
270755
- return `${style2 === "italic" ? "italic " : ""}${weight} ${size$1} ${quoteFamily(family$1)}`;
270756
- }
270757
- function getFontRegistryFor(fontSet, FontFaceCtor) {
270758
- if (!fontSet) {
270759
- if (!domlessRegistry)
270760
- domlessRegistry = new FontRegistry({});
270761
- return domlessRegistry;
270762
- }
270763
- let registry2 = registriesByFontSet.get(fontSet);
270764
- if (!registry2) {
270765
- registry2 = new FontRegistry({
270766
- fontSet,
270767
- FontFaceCtor
270768
- });
270769
- registriesByFontSet.set(fontSet, registry2);
270770
- }
270771
- return registry2;
270772
- }
270773
270782
  function isDigit(ch) {
270774
270783
  return ch >= "0" && ch <= "9";
270775
270784
  }
@@ -278396,7 +278405,7 @@ function invalidateHeaderFooterCache(cache$2, cacheState, headerBlocks, footerBl
278396
278405
  }
278397
278406
  }
278398
278407
  async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, options, measureBlock$1, headerFooter, previousMeasures, fontRuntime) {
278399
- const fontSignature = fontRuntime?.fontSignature ?? "";
278408
+ const fontSignature = fontRuntime?.fontContext?.fontSignature ?? "";
278400
278409
  const previousFontSignature = fontRuntime?.previousFontSignature ?? "";
278401
278410
  const isSemanticFlow = options.flowMode === "semantic";
278402
278411
  if (isSemanticFlow) {
@@ -278617,7 +278626,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
278617
278626
  measureCache.invalidate(Array.from(tokenResult.affectedBlockIds));
278618
278627
  const remeasureStart = performance.now();
278619
278628
  const currentPerSectionConstraints = computePerSectionConstraints(options, currentBlocks);
278620
- currentMeasures = await remeasureAffectedBlocks(currentBlocks, currentMeasures, tokenResult.affectedBlockIds, currentPerSectionConstraints, measureBlock$1, measureCache);
278629
+ currentMeasures = await remeasureAffectedBlocks(currentBlocks, currentMeasures, tokenResult.affectedBlockIds, currentPerSectionConstraints, measureBlock$1, fontSignature, measureCache);
278621
278630
  const remeasureTime = performance.now() - remeasureStart;
278622
278631
  totalRemeasureTime += remeasureTime;
278623
278632
  perfLog$1(`[Perf] 4.3.${iteration + 1}.1 Re-measure: ${remeasureTime.toFixed(2)}ms`);
@@ -279935,7 +279944,7 @@ function buildNumberingContext(layout, sections, blockById, chapterContextCache)
279935
279944
  }))
279936
279945
  };
279937
279946
  }
279938
- async function remeasureAffectedBlocks(blocks2, measures, affectedBlockIds, perBlockConstraints, measureBlock$1, measureCache$1) {
279947
+ async function remeasureAffectedBlocks(blocks2, measures, affectedBlockIds, perBlockConstraints, measureBlock$1, fontSignature, measureCache$1) {
279939
279948
  const updatedMeasures = [...measures];
279940
279949
  for (let i4 = 0;i4 < blocks2.length; i4++) {
279941
279950
  const block = blocks2[i4];
@@ -279945,7 +279954,7 @@ async function remeasureAffectedBlocks(blocks2, measures, affectedBlockIds, perB
279945
279954
  const newMeasure = await measureBlock$1(block, perBlockConstraints[i4]);
279946
279955
  updatedMeasures[i4] = newMeasure;
279947
279956
  const blockConstraints = perBlockConstraints[i4];
279948
- measureCache$1?.set(block, blockConstraints.maxWidth, blockConstraints.maxHeight, newMeasure);
279957
+ measureCache$1?.set(block, blockConstraints.maxWidth, blockConstraints.maxHeight, newMeasure, fontSignature);
279949
279958
  } catch (error3) {
279950
279959
  console.warn(`[incrementalLayout] Failed to re-measure block ${block.id} after token resolution:`, error3);
279951
279960
  }
@@ -285777,8 +285786,10 @@ function clearTableAutoFitMeasurementCaches() {
285777
285786
  autoFitTableResultCache.clear();
285778
285787
  }
285779
285788
  function buildTableCellContentMetricsCacheKey(cell2, options) {
285789
+ const fontContext = options.fontContext ?? DEFAULT_FONT_MEASURE_CONTEXT;
285780
285790
  return stableSerialize({
285781
285791
  maxWidth: Math.max(1, Math.round(options.maxWidth)),
285792
+ fontSignature: fontContext.fontSignature ?? "",
285782
285793
  layoutEpoch: options.layoutEpoch ?? null,
285783
285794
  attrs: cell2.attrs ?? null,
285784
285795
  paragraph: cell2.paragraph ?? null,
@@ -285792,6 +285803,7 @@ function buildAutoFitTableResultCacheKey(table2, options) {
285792
285803
  columnWidths: table2.columnWidths ?? null,
285793
285804
  rowCount: table2.rows.length,
285794
285805
  maxWidth: Math.max(1, Math.round(options.maxWidth)),
285806
+ fontSignature: options.fontSignature ?? "",
285795
285807
  layoutEpoch: options.layoutEpoch ?? null,
285796
285808
  cellMetricKeys: options.cellMetricKeys,
285797
285809
  workingGrid: {
@@ -285831,7 +285843,12 @@ function setCachedAutoFitTableResult(cacheKey, result) {
285831
285843
  autoFitTableResultCache.set(cacheKey, result);
285832
285844
  }
285833
285845
  async function measureTableCellContentMetrics(cell2, options) {
285834
- const cacheKey = buildTableCellContentMetricsCacheKey(cell2, options);
285846
+ const fontContext = options.fontContext ?? DEFAULT_FONT_MEASURE_CONTEXT;
285847
+ const normalizedOptions = {
285848
+ ...options,
285849
+ fontContext
285850
+ };
285851
+ const cacheKey = buildTableCellContentMetricsCacheKey(cell2, normalizedOptions);
285835
285852
  const cached = tableCellMetricsCache.get(cacheKey);
285836
285853
  if (cached)
285837
285854
  return cached;
@@ -285848,7 +285865,7 @@ async function measureTableCellContentMetrics(cell2, options) {
285848
285865
  let minContentWidthPx = 0;
285849
285866
  let maxContentWidthPx = 0;
285850
285867
  for (const block of contentBlocks) {
285851
- const metrics = await measureIntrinsicBlockWidthMetrics(block, options);
285868
+ const metrics = await measureIntrinsicBlockWidthMetrics(block, normalizedOptions);
285852
285869
  minContentWidthPx = Math.max(minContentWidthPx, metrics.minWidthPx);
285853
285870
  maxContentWidthPx = Math.max(maxContentWidthPx, metrics.maxWidthPx);
285854
285871
  }
@@ -285859,7 +285876,7 @@ async function measureTableCellContentMetrics(cell2, options) {
285859
285876
  tableCellMetricsCache.set(cacheKey, result);
285860
285877
  return result;
285861
285878
  }
285862
- async function measureTableAutoFitContentMetrics(table2, workingInput, fixedLayout, measureBlock$1) {
285879
+ async function measureTableAutoFitContentMetrics(table2, workingInput, fixedLayout, measureBlock$1, fontContext = DEFAULT_FONT_MEASURE_CONTEXT) {
285863
285880
  const tableMeasurementBasis = Math.max(1, fixedLayout.totalWidth);
285864
285881
  const cellMetricKeys = [];
285865
285882
  const rowMetrics = await Promise.all(table2.rows.map(async (row2, rowIndex) => {
@@ -285870,10 +285887,14 @@ async function measureTableAutoFitContentMetrics(table2, workingInput, fixedLayo
285870
285887
  const normalizedCell = normalizedRow.cells?.[cellIndex];
285871
285888
  const span = normalizedCell?.span ?? cell2.colSpan ?? 1;
285872
285889
  const measurementMaxWidth = resolveAutoFitCellMeasurementMaxWidth(cell2, normalizedCell, span, fixedLayout, tableMeasurementBasis, workingInput.gridColumnCount);
285873
- cellMetricKeys.push(buildTableCellContentMetricsCacheKey(cell2, { maxWidth: measurementMaxWidth }));
285890
+ cellMetricKeys.push(buildTableCellContentMetricsCacheKey(cell2, {
285891
+ maxWidth: measurementMaxWidth,
285892
+ fontContext
285893
+ }));
285874
285894
  const metrics = await measureTableCellContentMetrics(cell2, {
285875
285895
  maxWidth: measurementMaxWidth,
285876
- measureBlock: measureBlock$1
285896
+ measureBlock: measureBlock$1,
285897
+ fontContext
285877
285898
  });
285878
285899
  return {
285879
285900
  cellIndex,
@@ -285905,7 +285926,7 @@ async function measureTableAutoFitContentMetrics(table2, workingInput, fixedLayo
285905
285926
  }
285906
285927
  async function measureIntrinsicBlockWidthMetrics(block, options) {
285907
285928
  if (block.kind === "paragraph")
285908
- return measureParagraphIntrinsicWidthMetrics(block, options.measureBlock);
285929
+ return measureParagraphIntrinsicWidthMetrics(block, options.measureBlock, options.fontContext);
285909
285930
  if (block.kind === "table")
285910
285931
  return measureNestedTableIntrinsicWidthMetrics(block, options);
285911
285932
  const intrinsicWidth = getIntrinsicAtomicBlockWidth(block);
@@ -285914,13 +285935,13 @@ async function measureIntrinsicBlockWidthMetrics(block, options) {
285914
285935
  maxWidthPx: intrinsicWidth
285915
285936
  };
285916
285937
  }
285917
- async function measureParagraphIntrinsicWidthMetrics(paragraph2, measureBlock$1) {
285938
+ async function measureParagraphIntrinsicWidthMetrics(paragraph2, measureBlock$1, fontContext) {
285918
285939
  const maxLineWidth = (await measureBlock$1(paragraph2, {
285919
285940
  maxWidth: NO_WRAP_MAX_WIDTH,
285920
285941
  maxHeight: Infinity
285921
285942
  })).lines.reduce((widest, line) => Math.max(widest, line.width), 0);
285922
285943
  return {
285923
- minWidthPx: measureParagraphMinTokenWidth(paragraph2),
285944
+ minWidthPx: measureParagraphMinTokenWidth(paragraph2, fontContext),
285924
285945
  maxWidthPx: maxLineWidth
285925
285946
  };
285926
285947
  }
@@ -285939,7 +285960,7 @@ async function measureNestedTableIntrinsicWidthMetrics(table2, options) {
285939
285960
  maxWidthPx: nestedMeasure.totalWidth
285940
285961
  };
285941
285962
  }
285942
- function measureParagraphMinTokenWidth(paragraph2) {
285963
+ function measureParagraphMinTokenWidth(paragraph2, fontContext) {
285943
285964
  let widestToken = 0;
285944
285965
  let currentTokenWidth = 0;
285945
285966
  const flushToken = () => {
@@ -285954,7 +285975,7 @@ function measureParagraphMinTokenWidth(paragraph2) {
285954
285975
  if (isTextLikeRun(run2)) {
285955
285976
  accumulateTextRunMinTokenWidth(run2, (width) => {
285956
285977
  currentTokenWidth += width;
285957
- }, flushToken);
285978
+ }, flushToken, fontContext);
285958
285979
  continue;
285959
285980
  }
285960
285981
  flushToken();
@@ -285963,7 +285984,7 @@ function measureParagraphMinTokenWidth(paragraph2) {
285963
285984
  continue;
285964
285985
  }
285965
285986
  if (run2.kind === "fieldAnnotation") {
285966
- widestToken = Math.max(widestToken, measureFieldAnnotationWidth(run2));
285987
+ widestToken = Math.max(widestToken, measureFieldAnnotationWidth(run2, fontContext));
285967
285988
  continue;
285968
285989
  }
285969
285990
  if (run2.kind === "math")
@@ -285972,8 +285993,8 @@ function measureParagraphMinTokenWidth(paragraph2) {
285972
285993
  flushToken();
285973
285994
  return widestToken;
285974
285995
  }
285975
- function accumulateTextRunMinTokenWidth(run2, appendTokenPiece, flushToken) {
285976
- const font = buildFontString$1(run2);
285996
+ function accumulateTextRunMinTokenWidth(run2, appendTokenPiece, flushToken, fontContext) {
285997
+ const font = buildFontString$1(run2, fontContext);
285977
285998
  let cursor = 0;
285978
285999
  for (const boundary of run2.text.matchAll(TOKEN_BOUNDARY_PATTERN)) {
285979
286000
  const boundaryStart = boundary.index ?? cursor;
@@ -286039,14 +286060,15 @@ function getCanvasContext$1() {
286039
286060
  }
286040
286061
  return canvasContext$1;
286041
286062
  }
286042
- function buildFontString$1(run2) {
286063
+ function buildFontString$1(run2, fontContext) {
286043
286064
  const parts = [];
286044
286065
  if (run2.italic)
286045
286066
  parts.push("italic");
286046
286067
  if (run2.bold)
286047
286068
  parts.push("bold");
286048
286069
  parts.push(`${normalizeFontSize$1(run2.fontSize)}px`);
286049
- parts.push(toCssFontFamily(normalizeFontFamily$1(run2.fontFamily)) ?? normalizeFontFamily$1(run2.fontFamily));
286070
+ const physicalFamily = normalizeFontFamily$1(fontContext.resolvePhysical(normalizeFontFamily$1(run2.fontFamily)));
286071
+ parts.push(toCssFontFamily(physicalFamily) ?? physicalFamily);
286050
286072
  return parts.join(" ");
286051
286073
  }
286052
286074
  function applyTextTransform$1(text5, run2, startOffset = 0) {
@@ -286071,14 +286093,14 @@ function capitalizeText$1(text5, fullText, startOffset) {
286071
286093
  }
286072
286094
  return result;
286073
286095
  }
286074
- function measureFieldAnnotationWidth(run2) {
286096
+ function measureFieldAnnotationWidth(run2, fontContext) {
286075
286097
  const fontSize = typeof run2.fontSize === "number" ? run2.fontSize : typeof run2.fontSize === "string" ? parseFloat(run2.fontSize) || DEFAULT_FIELD_ANNOTATION_FONT_SIZE$1 : DEFAULT_FIELD_ANNOTATION_FONT_SIZE$1;
286076
286098
  const font = buildFontString$1({
286077
286099
  fontFamily: normalizeFontFamily$1(run2.fontFamily ?? "Arial"),
286078
286100
  fontSize,
286079
286101
  bold: run2.bold,
286080
286102
  italic: run2.italic
286081
- });
286103
+ }, fontContext);
286082
286104
  return getMeasuredTextWidth(applyTextTransform$1(run2.displayLabel || "", { text: run2.displayLabel || "" }), font, 0, getCanvasContext$1()) + (run2.highlighted === false ? 0 : FIELD_ANNOTATION_PILL_PADDING$1);
286083
286105
  }
286084
286106
  function isExplicitLineBreakRun(run2) {
@@ -286152,14 +286174,14 @@ function getCanvasContext() {
286152
286174
  }
286153
286175
  return canvasContext;
286154
286176
  }
286155
- function buildFontString(run2, resolvePhysical = resolvePhysicalFamily) {
286177
+ function buildFontString(run2, fontContext) {
286156
286178
  const parts = [];
286157
286179
  if (run2.italic)
286158
286180
  parts.push("italic");
286159
286181
  if (run2.bold)
286160
286182
  parts.push("bold");
286161
286183
  parts.push(`${run2.fontSize}px`);
286162
- const physicalFamily = resolvePhysical(run2.fontFamily);
286184
+ const physicalFamily = fontContext.resolvePhysical(run2.fontFamily);
286163
286185
  if (measurementConfig.mode === "deterministic")
286164
286186
  parts.push(measurementConfig.fonts.fallbackStack.length > 0 ? measurementConfig.fonts.fallbackStack.join(", ") : measurementConfig.fonts.deterministicFamily);
286165
286187
  else
@@ -286224,17 +286246,17 @@ function calculateEmptyParagraphMetrics(fontSize, spacing, fontInfo) {
286224
286246
  function lineHeightFontSize(run2) {
286225
286247
  return resolveBaseFontSizeForVerticalText(run2.fontSize, run2);
286226
286248
  }
286227
- function getFontInfoFromRun(run2) {
286249
+ function getFontInfoFromRun(run2, fontContext) {
286228
286250
  return {
286229
- fontFamily: normalizeFontFamily(run2.fontFamily),
286251
+ fontFamily: normalizeFontFamily(fontContext.resolvePhysical(run2.fontFamily)),
286230
286252
  fontSize: normalizeFontSize2(lineHeightFontSize(run2)),
286231
286253
  bold: run2.bold,
286232
286254
  italic: run2.italic
286233
286255
  };
286234
286256
  }
286235
- function updateMaxFontInfo(currentMaxSize, currentMaxInfo, newRun) {
286257
+ function updateMaxFontInfo(currentMaxSize, currentMaxInfo, newRun, fontContext) {
286236
286258
  if (lineHeightFontSize(newRun) >= currentMaxSize)
286237
- return getFontInfoFromRun(newRun);
286259
+ return getFontInfoFromRun(newRun, fontContext);
286238
286260
  return currentMaxInfo;
286239
286261
  }
286240
286262
  function isTextRun$22(run2) {
@@ -286252,7 +286274,7 @@ function isLineBreakRun(run2) {
286252
286274
  function isFieldAnnotationRun(run2) {
286253
286275
  return run2.kind === "fieldAnnotation";
286254
286276
  }
286255
- function measureTabAlignmentGroup(startRunIndex, runs2, ctx$1, decimalSeparator = ".", resolvePhysical = resolvePhysicalFamily) {
286277
+ function measureTabAlignmentGroup(startRunIndex, runs2, ctx$1, decimalSeparator = ".", fontContext) {
286256
286278
  const result = {
286257
286279
  totalWidth: 0,
286258
286280
  runs: [],
@@ -286273,7 +286295,7 @@ function measureTabAlignmentGroup(startRunIndex, runs2, ctx$1, decimalSeparator
286273
286295
  const textRun = run2;
286274
286296
  const text5 = textRun.text || "";
286275
286297
  if (text5.length > 0) {
286276
- const { font } = buildFontString(textRun, resolvePhysical);
286298
+ const { font } = buildFontString(textRun, fontContext);
286277
286299
  const width = measureRunWidth(text5, font, ctx$1, textRun, 0);
286278
286300
  let beforeDecimalWidth;
286279
286301
  if (!foundDecimal) {
@@ -286327,7 +286349,7 @@ function measureTabAlignmentGroup(startRunIndex, runs2, ctx$1, decimalSeparator
286327
286349
  fontSize,
286328
286350
  bold: run2.bold,
286329
286351
  italic: run2.italic
286330
- }, resolvePhysical);
286352
+ }, fontContext);
286331
286353
  const pillWidth = (run2.displayLabel ? measureRunWidth(run2.displayLabel, font, ctx$1, run2, 0) : 0) + FIELD_ANNOTATION_PILL_PADDING;
286332
286354
  result.runs.push({
286333
286355
  runIndex: i4,
@@ -286343,25 +286365,25 @@ function measureTabAlignmentGroup(startRunIndex, runs2, ctx$1, decimalSeparator
286343
286365
  }
286344
286366
  return result;
286345
286367
  }
286346
- async function measureBlock(block, constraints, resolvePhysical = resolvePhysicalFamily) {
286368
+ async function measureBlock(block, constraints, fontContext = DEFAULT_FONT_MEASURE_CONTEXT) {
286347
286369
  const normalized = normalizeConstraints(constraints);
286348
286370
  if (block.kind === "drawing")
286349
286371
  return measureDrawingBlock(block, normalized);
286350
286372
  if (block.kind === "image")
286351
286373
  return measureImageBlock(block, normalized);
286352
286374
  if (block.kind === "list")
286353
- return measureListBlock(block, normalized, resolvePhysical);
286375
+ return measureListBlock(block, normalized, fontContext);
286354
286376
  if (block.kind === "table")
286355
- return measureTableBlock(block, normalized, resolvePhysical);
286377
+ return measureTableBlock(block, normalized, fontContext);
286356
286378
  if (block.kind === "sectionBreak")
286357
286379
  return { kind: "sectionBreak" };
286358
286380
  if (block.kind === "pageBreak")
286359
286381
  return { kind: "pageBreak" };
286360
286382
  if (block.kind === "columnBreak")
286361
286383
  return { kind: "columnBreak" };
286362
- return measureParagraphBlock(block, normalized.maxWidth, resolvePhysical);
286384
+ return measureParagraphBlock(block, normalized.maxWidth, fontContext);
286363
286385
  }
286364
- async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolvePhysicalFamily) {
286386
+ async function measureParagraphBlock(block, maxWidth, fontContext) {
286365
286387
  const ctx$1 = getCanvasContext();
286366
286388
  const wordLayout = block.attrs?.wordLayout;
286367
286389
  const firstTextRunWithSize = block.runs.find((run2) => isTextRun$22(run2) && ("fontSize" in run2) && run2.fontSize != null);
@@ -286374,7 +286396,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
286374
286396
  fontSize: wordLayout.marker.run.fontSize ?? fallbackFontSize,
286375
286397
  bold: wordLayout.marker.run.bold,
286376
286398
  italic: wordLayout.marker.run.italic
286377
- }, resolvePhysical);
286399
+ }, fontContext);
286378
286400
  const markerText = wordLayout.marker.markerText ?? "";
286379
286401
  const glyphWidth = markerText ? measureText(markerText, markerFont, ctx$1) : 0;
286380
286402
  const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : 8;
@@ -286407,7 +286429,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
286407
286429
  fontSize: marker.run?.fontSize ?? fallbackFontSize,
286408
286430
  bold: marker.run?.bold ?? false,
286409
286431
  italic: marker.run?.italic ?? false
286410
- }, resolvePhysical);
286432
+ }, fontContext);
286411
286433
  return measureText(markerText, markerFont, ctx$1);
286412
286434
  }) ?? textStartPx;
286413
286435
  if (typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft)
@@ -286431,14 +286453,14 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
286431
286453
  if (!dropCapDescriptor.run || !dropCapDescriptor.run.text || !dropCapDescriptor.lines)
286432
286454
  console.warn("Invalid drop cap descriptor - missing required fields:", dropCapDescriptor);
286433
286455
  else {
286434
- const dropCapMeasured = measureDropCap(ctx$1, dropCapDescriptor, spacing, resolvePhysical);
286456
+ const dropCapMeasured = measureDropCap(ctx$1, dropCapDescriptor, spacing, fontContext);
286435
286457
  dropCapMeasure = dropCapMeasured;
286436
286458
  dropCapDescriptor.measuredWidth = dropCapMeasured.width;
286437
286459
  dropCapDescriptor.measuredHeight = dropCapMeasured.height;
286438
286460
  }
286439
286461
  const emptyParagraphRun = normalizedRuns.length === 1 && isEmptyTextRun2(normalizedRuns[0]) && !isEmptySdtPlaceholderRun(normalizedRuns[0]) ? normalizedRuns[0] : null;
286440
286462
  if (emptyParagraphRun) {
286441
- const metrics = calculateEmptyParagraphMetrics(emptyParagraphRun.fontSize ?? DEFAULT_PARAGRAPH_FONT_SIZE, spacing, getFontInfoFromRun(emptyParagraphRun));
286463
+ const metrics = calculateEmptyParagraphMetrics(emptyParagraphRun.fontSize ?? DEFAULT_PARAGRAPH_FONT_SIZE, spacing, getFontInfoFromRun(emptyParagraphRun, fontContext));
286442
286464
  const emptyLine = {
286443
286465
  fromRun: 0,
286444
286466
  fromChar: 0,
@@ -286475,7 +286497,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
286475
286497
  ...markerInfo ? { marker: markerInfo } : {}
286476
286498
  };
286477
286499
  }
286478
- const fallbackFontInfo = firstTextRunWithSize ? getFontInfoFromRun(firstTextRunWithSize) : undefined;
286500
+ const fallbackFontInfo = firstTextRunWithSize ? getFontInfoFromRun(firstTextRunWithSize, fontContext) : undefined;
286479
286501
  let currentLine = null;
286480
286502
  const getEffectiveWidth = (baseWidth) => {
286481
286503
  if (dropCapMeasure && lines.length < dropCapMeasure.lines && dropCapMeasure.mode === "drop")
@@ -286656,7 +286678,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
286656
286678
  if (lineToTrim.fromRun === lineToTrim.toRun && sliceText.trim().length === 0)
286657
286679
  return;
286658
286680
  const keptText = sliceText.slice(0, Math.max(0, sliceText.length - trimCount));
286659
- const { font } = buildFontString(lastRun, resolvePhysical);
286681
+ const { font } = buildFontString(lastRun, fontContext);
286660
286682
  const fullWidth = measureRunWidth(sliceText, font, ctx$1, lastRun, sliceStart);
286661
286683
  const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx$1, lastRun, sliceStart) : 0;
286662
286684
  const delta = Math.max(0, fullWidth - keptWidth);
@@ -286803,7 +286825,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
286803
286825
  toChar: 1,
286804
286826
  width: 0,
286805
286827
  maxFontSize: lastFontSize,
286806
- maxFontInfo: hasSeenTextRun ? undefined : fallbackFontInfo ?? getFontInfoFromRun(run2),
286828
+ maxFontInfo: hasSeenTextRun ? undefined : fallbackFontInfo ?? getFontInfoFromRun(run2, fontContext),
286807
286829
  maxWidth: getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : bodyContentWidth),
286808
286830
  segments: [],
286809
286831
  spaceCount: 0
@@ -286853,7 +286875,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
286853
286875
  if (stop) {
286854
286876
  validateTabStopVal(stop);
286855
286877
  if (stop.val === "end" || stop.val === "center" || stop.val === "decimal") {
286856
- const groupMeasure = measureTabAlignmentGroup(runIndex + 1, runsToProcess, ctx$1, decimalSeparator, resolvePhysical);
286878
+ const groupMeasure = measureTabAlignmentGroup(runIndex + 1, runsToProcess, ctx$1, decimalSeparator, fontContext);
286857
286879
  if (groupMeasure.totalWidth > 0) {
286858
286880
  const relativeTarget = clampedTarget - effectiveIndent;
286859
286881
  let groupStartX;
@@ -287029,7 +287051,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287029
287051
  if (isFieldAnnotationRun(run2)) {
287030
287052
  const displayText = applyTextTransform(run2.displayLabel || "", run2);
287031
287053
  const annotationFontSize = typeof run2.fontSize === "number" ? run2.fontSize : typeof run2.fontSize === "string" ? parseFloat(run2.fontSize) || DEFAULT_FIELD_ANNOTATION_FONT_SIZE : DEFAULT_FIELD_ANNOTATION_FONT_SIZE;
287032
- const annotationFontFamily = run2.fontFamily || "Arial, sans-serif";
287054
+ const annotationFontFamily = fontContext.resolvePhysical(run2.fontFamily || "Arial, sans-serif");
287033
287055
  const fontWeight = run2.bold ? "bold" : "normal";
287034
287056
  ctx$1.font = `${run2.italic ? "italic" : "normal"} ${fontWeight} ${annotationFontSize}px ${annotationFontFamily}`;
287035
287057
  const textWidth = displayText ? ctx$1.measureText(displayText).width : 0;
@@ -287130,7 +287152,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287130
287152
  continue;
287131
287153
  }
287132
287154
  if (isEmptySdtPlaceholderRun(run2)) {
287133
- const placeholderFont = buildFontString(run2, resolvePhysical).font;
287155
+ const placeholderFont = buildFontString(run2, fontContext).font;
287134
287156
  const placeholderText = applyTextTransform(EMPTY_SDT_PLACEHOLDER_TEXT, run2);
287135
287157
  const measuredPlaceholderWidth = getMeasuredTextWidth(placeholderText, placeholderFont, run2.letterSpacing ?? 0, ctx$1);
287136
287158
  const fallbackPlaceholderWidth = placeholderText.length * run2.fontSize * 0.45;
@@ -287143,7 +287165,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287143
287165
  toChar: 0,
287144
287166
  width: placeholderWidth,
287145
287167
  maxFontSize: lineHeightFontSize(run2),
287146
- maxFontInfo: getFontInfoFromRun(run2),
287168
+ maxFontInfo: getFontInfoFromRun(run2, fontContext),
287147
287169
  maxWidth: getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : bodyContentWidth),
287148
287170
  segments: [{
287149
287171
  runIndex,
@@ -287176,7 +287198,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287176
287198
  toChar: 0,
287177
287199
  width: placeholderWidth,
287178
287200
  maxFontSize: lineHeightFontSize(run2),
287179
- maxFontInfo: getFontInfoFromRun(run2),
287201
+ maxFontInfo: getFontInfoFromRun(run2, fontContext),
287180
287202
  maxWidth: getEffectiveWidth(bodyContentWidth),
287181
287203
  segments: [{
287182
287204
  runIndex,
@@ -287190,7 +287212,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287190
287212
  currentLine.toRun = runIndex;
287191
287213
  currentLine.toChar = 0;
287192
287214
  currentLine.width = roundValue(currentLine.width + boundarySpacing + placeholderWidth);
287193
- currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2);
287215
+ currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2, fontContext);
287194
287216
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, lineHeightFontSize(run2));
287195
287217
  appendSegment(currentLine.segments, runIndex, 0, 0, placeholderWidth);
287196
287218
  }
@@ -287202,7 +287224,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287202
287224
  }
287203
287225
  lastFontSize = run2.fontSize;
287204
287226
  hasSeenTextRun = true;
287205
- const { font } = buildFontString(run2, resolvePhysical);
287227
+ const { font } = buildFontString(run2, fontContext);
287206
287228
  const tabSegments = run2.text.split("\t");
287207
287229
  let charPosInRun = 0;
287208
287230
  for (let segmentIndex = 0;segmentIndex < tabSegments.length; segmentIndex++) {
@@ -287222,7 +287244,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287222
287244
  toChar: spacesEndChar,
287223
287245
  width: spacesWidth,
287224
287246
  maxFontSize: lineHeightFontSize(run2),
287225
- maxFontInfo: getFontInfoFromRun(run2),
287247
+ maxFontInfo: getFontInfoFromRun(run2, fontContext),
287226
287248
  maxWidth: getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : bodyContentWidth),
287227
287249
  segments: [{
287228
287250
  runIndex,
@@ -287254,7 +287276,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287254
287276
  toChar: spacesEndChar,
287255
287277
  width: spacesWidth,
287256
287278
  maxFontSize: lineHeightFontSize(run2),
287257
- maxFontInfo: getFontInfoFromRun(run2),
287279
+ maxFontInfo: getFontInfoFromRun(run2, fontContext),
287258
287280
  maxWidth: getEffectiveWidth(bodyContentWidth),
287259
287281
  segments: [{
287260
287282
  runIndex,
@@ -287268,7 +287290,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287268
287290
  currentLine.toRun = runIndex;
287269
287291
  currentLine.toChar = spacesEndChar;
287270
287292
  currentLine.width = roundValue(currentLine.width + boundarySpacing + spacesWidth);
287271
- currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2);
287293
+ currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2, fontContext);
287272
287294
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, lineHeightFontSize(run2));
287273
287295
  appendSegment(currentLine.segments, runIndex, spacesStartChar, spacesEndChar, spacesWidth);
287274
287296
  currentLine.spaceCount += spacesLength;
@@ -287321,7 +287343,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287321
287343
  toChar: spaceEndChar,
287322
287344
  width: singleSpaceWidth,
287323
287345
  maxFontSize: lineHeightFontSize(run2),
287324
- maxFontInfo: getFontInfoFromRun(run2),
287346
+ maxFontInfo: getFontInfoFromRun(run2, fontContext),
287325
287347
  maxWidth: getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : bodyContentWidth),
287326
287348
  segments: [{
287327
287349
  runIndex,
@@ -287355,7 +287377,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287355
287377
  toChar: spaceEndChar,
287356
287378
  width: singleSpaceWidth,
287357
287379
  maxFontSize: lineHeightFontSize(run2),
287358
- maxFontInfo: getFontInfoFromRun(run2),
287380
+ maxFontInfo: getFontInfoFromRun(run2, fontContext),
287359
287381
  maxWidth: getEffectiveWidth(bodyContentWidth),
287360
287382
  segments: [{
287361
287383
  runIndex,
@@ -287369,7 +287391,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287369
287391
  currentLine.toRun = runIndex;
287370
287392
  currentLine.toChar = spaceEndChar;
287371
287393
  currentLine.width = roundValue(currentLine.width + boundarySpacing$1 + singleSpaceWidth);
287372
- currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2);
287394
+ currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2, fontContext);
287373
287395
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, lineHeightFontSize(run2));
287374
287396
  let spaceExplicitX;
287375
287397
  let spacePrecedingTabEndX;
@@ -287425,7 +287447,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287425
287447
  currentLine.toChar = chunkEndChar;
287426
287448
  currentLine.width = roundValue(currentLine.width + chunk2.width);
287427
287449
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, lineHeightFontSize(run2));
287428
- currentLine.maxFontInfo = getFontInfoFromRun(run2);
287450
+ currentLine.maxFontInfo = getFontInfoFromRun(run2, fontContext);
287429
287451
  currentLine.segments.push({
287430
287452
  runIndex,
287431
287453
  fromChar: chunkStartChar,
@@ -287464,7 +287486,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287464
287486
  toChar: chunkEndChar,
287465
287487
  width: chunk2.width,
287466
287488
  maxFontSize: lineHeightFontSize(run2),
287467
- maxFontInfo: getFontInfoFromRun(run2),
287489
+ maxFontInfo: getFontInfoFromRun(run2, fontContext),
287468
287490
  maxWidth: getEffectiveWidth(contentWidth),
287469
287491
  segments: [{
287470
287492
  runIndex,
@@ -287484,7 +287506,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287484
287506
  charPosInRun = wordEndWithSpace;
287485
287507
  } else {
287486
287508
  const chunkLineMaxWidth = getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : contentWidth);
287487
- const metrics = calculateTypographyMetrics(run2.fontSize, spacing, getFontInfoFromRun(run2));
287509
+ const metrics = calculateTypographyMetrics(run2.fontSize, spacing, getFontInfoFromRun(run2, fontContext));
287488
287510
  const chunkLine = {
287489
287511
  fromRun: runIndex,
287490
287512
  fromChar: chunkStartChar,
@@ -287516,7 +287538,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287516
287538
  toChar: wordEndNoSpace,
287517
287539
  width: wordOnlyWidth,
287518
287540
  maxFontSize: lineHeightFontSize(run2),
287519
- maxFontInfo: getFontInfoFromRun(run2),
287541
+ maxFontInfo: getFontInfoFromRun(run2, fontContext),
287520
287542
  maxWidth: getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : bodyContentWidth),
287521
287543
  segments: [{
287522
287544
  runIndex,
@@ -287584,7 +287606,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287584
287606
  toChar: wordEndNoSpace,
287585
287607
  width: wordOnlyWidth,
287586
287608
  maxFontSize: lineHeightFontSize(run2),
287587
- maxFontInfo: getFontInfoFromRun(run2),
287609
+ maxFontInfo: getFontInfoFromRun(run2, fontContext),
287588
287610
  maxWidth: getEffectiveWidth(bodyContentWidth),
287589
287611
  segments: [{
287590
287612
  runIndex,
@@ -287610,7 +287632,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287610
287632
  if (shouldIncludeDelimiterSpace && currentLine.width + boundarySpacing + wordOnlyWidth + spaceWidth > currentLine.maxWidth - WIDTH_FUDGE_PX$1) {
287611
287633
  currentLine.toChar = wordEndNoSpace;
287612
287634
  currentLine.width = roundValue(currentLine.width + boundarySpacing + wordOnlyWidth);
287613
- currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2);
287635
+ currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2, fontContext);
287614
287636
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, lineHeightFontSize(run2));
287615
287637
  let explicitXHere;
287616
287638
  if (inActiveTabGroup && activeTabGroup) {
@@ -287646,7 +287668,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287646
287668
  if (compressedWidth != null)
287647
287669
  currentLine.naturalWidth = roundValue(totalWidthWithWord);
287648
287670
  currentLine.width = roundValue(targetWidth);
287649
- currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2);
287671
+ currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2, fontContext);
287650
287672
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, lineHeightFontSize(run2));
287651
287673
  appendSegment(currentLine.segments, runIndex, wordStartChar, newToChar, wordCommitWidth, explicitX, wordIndex === 0 ? consumeSegmentPrecedingTabEndX() : undefined);
287652
287674
  if (shouldIncludeDelimiterSpace)
@@ -287676,7 +287698,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287676
287698
  toChar: charPosInRun,
287677
287699
  width: 0,
287678
287700
  maxFontSize: lineHeightFontSize(run2),
287679
- maxFontInfo: getFontInfoFromRun(run2),
287701
+ maxFontInfo: getFontInfoFromRun(run2, fontContext),
287680
287702
  maxWidth: getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : bodyContentWidth),
287681
287703
  segments: [],
287682
287704
  spaceCount: 0
@@ -287692,7 +287714,7 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287692
287714
  currentLine.width = roundValue(currentLine.width + tabAdvance);
287693
287715
  if (stop?.source === "explicit")
287694
287716
  currentLine.hasExplicitTabStops = true;
287695
- currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2);
287717
+ currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2, fontContext);
287696
287718
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, lineHeightFontSize(run2));
287697
287719
  currentLine.toRun = runIndex;
287698
287720
  currentLine.toChar = charPosInRun;
@@ -287756,9 +287778,9 @@ async function measureParagraphBlock(block, maxWidth, resolvePhysical = resolveP
287756
287778
  ...dropCapMeasure ? { dropCap: dropCapMeasure } : {}
287757
287779
  };
287758
287780
  }
287759
- async function measureTableBlock(block, constraints, resolvePhysical = resolvePhysicalFamily) {
287781
+ async function measureTableBlock(block, constraints, fontContext) {
287760
287782
  const workingInput = buildAutoFitWorkingGridInput(block, { maxWidth: typeof constraints === "number" ? constraints : constraints.maxWidth });
287761
- const columnWidths = await resolveRuntimeTableColumnWidths(block, workingInput);
287783
+ const columnWidths = await resolveRuntimeTableColumnWidths(block, workingInput, fontContext);
287762
287784
  const gridColumnCount = columnWidths.length;
287763
287785
  const calculateCellWidth = (startCol, colspan) => {
287764
287786
  let width = 0;
@@ -287809,7 +287831,7 @@ async function measureTableBlock(block, constraints, resolvePhysical = resolvePh
287809
287831
  const measure = await measureBlock(block$1, {
287810
287832
  maxWidth: contentWidth$1,
287811
287833
  maxHeight: Infinity
287812
- }, resolvePhysical);
287834
+ }, fontContext);
287813
287835
  blockMeasures.push(measure);
287814
287836
  const blockHeight = "totalHeight" in measure ? measure.totalHeight : ("height" in measure) ? measure.height : 0;
287815
287837
  if ((block$1.kind === "image" || block$1.kind === "drawing") && block$1.anchor?.isAnchored === true && (block$1.wrap?.type ?? "Inline") !== "Inline")
@@ -287897,14 +287919,15 @@ async function measureTableBlock(block, constraints, resolvePhysical = resolvePh
287897
287919
  tableBorderWidths: borderWidthH > 0 || borderWidthV > 0 ? tableBorderWidths : undefined
287898
287920
  };
287899
287921
  }
287900
- async function resolveRuntimeTableColumnWidths(block, workingInput) {
287922
+ async function resolveRuntimeTableColumnWidths(block, workingInput, fontContext) {
287901
287923
  const fixedLayout = computeFixedTableColumnWidths(workingInput);
287902
287924
  if (workingInput.layoutMode === "fixed")
287903
287925
  return fixedLayout.columnWidths;
287904
- const { contentMetrics, cellMetricKeys } = await buildMeasuredAutoFitContentMetrics(block, workingInput, fixedLayout);
287926
+ const { contentMetrics, cellMetricKeys } = await buildMeasuredAutoFitContentMetrics(block, workingInput, fixedLayout, fontContext);
287905
287927
  const cacheKey = buildAutoFitTableResultCacheKey(block, {
287906
287928
  maxWidth: workingInput.maxTableWidth,
287907
287929
  cellMetricKeys,
287930
+ fontSignature: fontContext.fontSignature,
287908
287931
  workingInput,
287909
287932
  fixedLayout
287910
287933
  });
@@ -287922,8 +287945,9 @@ async function resolveRuntimeTableColumnWidths(block, workingInput) {
287922
287945
  });
287923
287946
  return result.columnWidths;
287924
287947
  }
287925
- async function buildMeasuredAutoFitContentMetrics(block, workingInput, fixedLayout) {
287926
- const contentMetrics = await measureTableAutoFitContentMetrics(block, workingInput, fixedLayout, measureBlock);
287948
+ async function buildMeasuredAutoFitContentMetrics(block, workingInput, fixedLayout, fontContext) {
287949
+ const measureBlockWithFontContext = (childBlock, childConstraints) => measureBlock(childBlock, childConstraints, fontContext);
287950
+ const contentMetrics = await measureTableAutoFitContentMetrics(block, workingInput, fixedLayout, measureBlockWithFontContext, fontContext);
287927
287951
  return {
287928
287952
  contentMetrics,
287929
287953
  cellMetricKeys: contentMetrics.cellMetricKeys
@@ -288037,7 +288061,7 @@ function normalizeConstraints(constraints) {
288037
288061
  return { maxWidth: constraints };
288038
288062
  return constraints;
288039
288063
  }
288040
- async function measureListBlock(block, constraints, resolvePhysical = resolvePhysicalFamily) {
288064
+ async function measureListBlock(block, constraints, fontContext) {
288041
288065
  const ctx$1 = getCanvasContext();
288042
288066
  const items = [];
288043
288067
  let totalHeight = 0;
@@ -288056,12 +288080,12 @@ async function measureListBlock(block, constraints, resolvePhysical = resolvePhy
288056
288080
  bold: marker.run.bold,
288057
288081
  italic: marker.run.italic,
288058
288082
  letterSpacing: marker.run.letterSpacing
288059
- }, resolvePhysical);
288083
+ }, fontContext);
288060
288084
  markerTextWidth = marker.markerText ? measureText(marker.markerText, markerFont, ctx$1) : 0;
288061
288085
  markerWidth = 0;
288062
288086
  indentLeft = wordLayout.indentLeftPx ?? 0;
288063
288087
  } else {
288064
- const { font: markerFont } = buildFontString(getPrimaryRun(item.paragraph), resolvePhysical);
288088
+ const { font: markerFont } = buildFontString(getPrimaryRun(item.paragraph), fontContext);
288065
288089
  const markerText = item.marker.text ?? "";
288066
288090
  markerTextWidth = markerText ? measureText(markerText, markerFont, ctx$1) : 0;
288067
288091
  indentLeft = resolveIndentLeft(item);
@@ -288069,7 +288093,7 @@ async function measureListBlock(block, constraints, resolvePhysical = resolvePhy
288069
288093
  markerWidth = Math.max(24, markerTextWidth + 8, indentHanging);
288070
288094
  }
288071
288095
  const paragraphWidth = Math.max(1, constraints.maxWidth - indentLeft - markerWidth);
288072
- const paragraphMeasure = await measureParagraphBlock(item.paragraph, paragraphWidth, resolvePhysical);
288096
+ const paragraphMeasure = await measureParagraphBlock(item.paragraph, paragraphWidth, fontContext);
288073
288097
  totalHeight += paragraphMeasure.totalHeight;
288074
288098
  items.push({
288075
288099
  itemId: item.id,
@@ -288120,15 +288144,18 @@ async function layoutPerRIdHeaderFooters(headerFooterInput, layout, sectionMetad
288120
288144
  async function layoutBlocksByRId(kind, blocksByRId, referencedRIds, constraints, pageResolver, layoutsByRId, fontResolver) {
288121
288145
  if (!blocksByRId || referencedRIds.size === 0)
288122
288146
  return;
288123
- const resolvePhysical = fontResolver ? (css) => fontResolver.resolvePhysicalFamily(css) : undefined;
288124
288147
  const fontSignature = fontResolver?.signature ?? "";
288148
+ const fontMeasureContext = fontResolver ? {
288149
+ resolvePhysical: (css) => fontResolver.resolvePhysicalFamily(css),
288150
+ fontSignature
288151
+ } : undefined;
288125
288152
  for (const [rId, blocks2] of blocksByRId) {
288126
288153
  if (!referencedRIds.has(rId))
288127
288154
  continue;
288128
288155
  if (!blocks2 || blocks2.length === 0)
288129
288156
  continue;
288130
288157
  try {
288131
- const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, constraints, (block, c) => measureBlock(block, c, resolvePhysical), undefined, undefined, pageResolver, kind, fontSignature);
288158
+ const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, constraints, (block, c) => measureBlock(block, c, fontMeasureContext), undefined, undefined, pageResolver, kind, fontSignature);
288132
288159
  if (batchResult.default)
288133
288160
  layoutsByRId.set(rId, {
288134
288161
  kind,
@@ -288177,15 +288204,18 @@ function adjustFramePositionsForContentWidth(layout, blocks2, effectiveWidth, co
288177
288204
  async function layoutWithPerSectionConstraints(kind, blocksByRId, sectionMetadata, fallbackConstraints, pageResolver, layoutsByRId, fontResolver) {
288178
288205
  if (!blocksByRId)
288179
288206
  return;
288180
- const resolvePhysical = fontResolver ? (css) => fontResolver.resolvePhysicalFamily(css) : undefined;
288181
288207
  const fontSignature = fontResolver?.signature ?? "";
288208
+ const fontMeasureContext = fontResolver ? {
288209
+ resolvePhysical: (css) => fontResolver.resolvePhysicalFamily(css),
288210
+ fontSignature
288211
+ } : undefined;
288182
288212
  const groups = buildSectionAwareHeaderFooterMeasurementGroups(kind, blocksByRId, sectionMetadata, fallbackConstraints);
288183
288213
  for (const group of groups) {
288184
288214
  const blocks2 = blocksByRId.get(group.rId);
288185
288215
  if (!blocks2 || blocks2.length === 0)
288186
288216
  continue;
288187
288217
  try {
288188
- const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, group.sectionConstraints, (block, c) => measureBlock(block, c, resolvePhysical), undefined, undefined, pageResolver, kind, fontSignature);
288218
+ const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, group.sectionConstraints, (block, c) => measureBlock(block, c, fontMeasureContext), undefined, undefined, pageResolver, kind, fontSignature);
288189
288219
  if (batchResult.default)
288190
288220
  for (const sectionIndex of group.sectionIndices) {
288191
288221
  const contentWidth = buildSectionContentWidth(sectionMetadata.find((s2) => s2.sectionIndex === sectionIndex), fallbackConstraints);
@@ -288835,6 +288865,16 @@ function defaultInvalidate() {
288835
288865
  clearTextMeasurementCaches();
288836
288866
  measureCache.clear();
288837
288867
  }
288868
+ function toCssFontSource(url2) {
288869
+ return /^\s*url\(/i.test(url2) ? url2 : `url(${JSON.stringify(url2)})`;
288870
+ }
288871
+ function defaultScheduleMicrotask(callback) {
288872
+ if (typeof queueMicrotask === "function") {
288873
+ queueMicrotask(callback);
288874
+ return;
288875
+ }
288876
+ Promise.resolve().then(callback);
288877
+ }
288838
288878
  function faceKey(req) {
288839
288879
  return `${req.family.toLowerCase()}|${req.weight}|${req.style}`;
288840
288880
  }
@@ -309988,7 +310028,370 @@ menclose::after {
309988
310028
  const minReadablePx = getMinimumReadableTextStartPx(markerContentEndPx, gutterWidthPx);
309989
310029
  return Math.max(nextTabStopPx, minReadablePx);
309990
310030
  }
309991
- }, hashParagraphBorder$2 = (border) => {
310031
+ }, SETTLED_STATUSES, BUNDLED_SUBSTITUTES, FontResolver = class {
310032
+ #overrides = /* @__PURE__ */ new Map;
310033
+ #version = 0;
310034
+ #cachedSignature = null;
310035
+ map(logicalFamily, physicalFamily) {
310036
+ const key2 = normalizeFamilyKey$2(logicalFamily);
310037
+ const physical = physicalFamily?.trim();
310038
+ if (!key2 || !physical)
310039
+ return;
310040
+ if (this.#overrides.get(key2) === physical)
310041
+ return;
310042
+ if ((BUNDLED_SUBSTITUTES[key2] ?? logicalFamily.trim()) === physical) {
310043
+ if (this.#overrides.delete(key2)) {
310044
+ this.#version += 1;
310045
+ this.#cachedSignature = null;
310046
+ }
310047
+ return;
310048
+ }
310049
+ this.#overrides.set(key2, physical);
310050
+ this.#version += 1;
310051
+ this.#cachedSignature = null;
310052
+ }
310053
+ unmap(logicalFamily) {
310054
+ if (this.#overrides.delete(normalizeFamilyKey$2(logicalFamily))) {
310055
+ this.#version += 1;
310056
+ this.#cachedSignature = null;
310057
+ }
310058
+ }
310059
+ reset() {
310060
+ if (this.#overrides.size === 0)
310061
+ return;
310062
+ this.#overrides.clear();
310063
+ this.#version += 1;
310064
+ this.#cachedSignature = null;
310065
+ }
310066
+ get version() {
310067
+ return this.#version;
310068
+ }
310069
+ get signature() {
310070
+ if (this.#cachedSignature !== null)
310071
+ return this.#cachedSignature;
310072
+ this.#cachedSignature = this.#overrides.size === 0 ? "" : JSON.stringify([...this.#overrides.entries()].sort(([a2], [b$1]) => a2 < b$1 ? -1 : a2 > b$1 ? 1 : 0));
310073
+ return this.#cachedSignature;
310074
+ }
310075
+ #physicalFor(bareFamily) {
310076
+ const key2 = normalizeFamilyKey$2(bareFamily);
310077
+ const override = this.#overrides.get(key2);
310078
+ if (override)
310079
+ return {
310080
+ physical: override,
310081
+ reason: "custom_mapping"
310082
+ };
310083
+ const bundled = BUNDLED_SUBSTITUTES[key2];
310084
+ if (bundled)
310085
+ return {
310086
+ physical: bundled,
310087
+ reason: "bundled_substitute"
310088
+ };
310089
+ return {
310090
+ physical: bareFamily,
310091
+ reason: "as_requested"
310092
+ };
310093
+ }
310094
+ resolveFontFamily(logicalFamily) {
310095
+ const primary = splitStack(logicalFamily)[0] ?? logicalFamily;
310096
+ const { physical, reason } = this.#physicalFor(primary);
310097
+ return {
310098
+ logicalFamily,
310099
+ physicalFamily: physical,
310100
+ reason
310101
+ };
310102
+ }
310103
+ resolvePhysicalFamily(cssFontFamily) {
310104
+ if (!cssFontFamily)
310105
+ return cssFontFamily;
310106
+ const parts = splitStack(cssFontFamily);
310107
+ if (parts.length === 0)
310108
+ return cssFontFamily;
310109
+ const { physical, reason } = this.#physicalFor(parts[0]);
310110
+ if (reason === "as_requested")
310111
+ return cssFontFamily;
310112
+ return [physical, ...parts.slice(1)].join(", ");
310113
+ }
310114
+ resolvePrimaryPhysicalFamily(family$1) {
310115
+ const primary = splitStack(family$1)[0] ?? family$1;
310116
+ return this.#physicalFor(primary).physical;
310117
+ }
310118
+ resolvePhysicalFamilies(families) {
310119
+ const out = /* @__PURE__ */ new Set;
310120
+ for (const family$1 of families)
310121
+ if (family$1)
310122
+ out.add(this.resolvePrimaryPhysicalFamily(family$1));
310123
+ return [...out];
310124
+ }
310125
+ }, defaultResolver, DEFAULT_FONT_MEASURE_CONTEXT, fontConfigVersion = 0, BUNDLED_MANIFEST, defaultAssetBase = "/fonts/", installedRegistries, DEFAULT_FONT_LOAD_TIMEOUT_MS = 3000, DEFAULT_PROBE_SIZE = "16px", FontRegistry = class {
310126
+ #fontSet;
310127
+ #FontFaceCtor;
310128
+ #probeSize;
310129
+ #scheduleTimeout;
310130
+ #cancelTimeout;
310131
+ #managed = /* @__PURE__ */ new Map;
310132
+ #status = /* @__PURE__ */ new Map;
310133
+ #sources = /* @__PURE__ */ new Map;
310134
+ #warnedFailures = /* @__PURE__ */ new Set;
310135
+ #inflight = /* @__PURE__ */ new Map;
310136
+ #faceStatus = /* @__PURE__ */ new Map;
310137
+ #faceInflight = /* @__PURE__ */ new Map;
310138
+ #faceSources = /* @__PURE__ */ new Map;
310139
+ #facesByFamily = /* @__PURE__ */ new Map;
310140
+ #warnedFaceFailures = /* @__PURE__ */ new Set;
310141
+ constructor(options = {}) {
310142
+ this.#fontSet = options.fontSet ?? null;
310143
+ this.#FontFaceCtor = options.FontFaceCtor ?? null;
310144
+ this.#probeSize = options.probeSize ?? DEFAULT_PROBE_SIZE;
310145
+ this.#scheduleTimeout = options.scheduleTimeout ?? ((cb, ms) => globalThis.setTimeout(cb, ms));
310146
+ this.#cancelTimeout = options.cancelTimeout ?? ((handle3) => globalThis.clearTimeout(handle3));
310147
+ }
310148
+ register(descriptor) {
310149
+ const { family: family$1, source, descriptors: descriptors2 } = descriptor;
310150
+ const identitySource = typeof source === "string" ? canonicalizeFontSource(source) : source;
310151
+ const key2 = faceKeyOf$1(family$1, normalizeWeight(descriptors2?.weight), normalizeStyle$1(descriptors2?.style));
310152
+ if (typeof identitySource === "string") {
310153
+ const existingSource = this.#faceSources.get(key2);
310154
+ if (existingSource === identitySource)
310155
+ return {
310156
+ family: family$1,
310157
+ status: this.getStatus(family$1),
310158
+ changed: false
310159
+ };
310160
+ if (existingSource !== undefined)
310161
+ throw new Error(`[superdoc] font face "${key2}" is already registered from a different source ("${existingSource}"); a registered face's source cannot be replaced`);
310162
+ }
310163
+ if (this.#FontFaceCtor && this.#fontSet) {
310164
+ const face = new this.#FontFaceCtor(family$1, source, descriptors2);
310165
+ this.#fontSet.add(face);
310166
+ this.#managed.set(family$1, face);
310167
+ }
310168
+ if (typeof source === "string") {
310169
+ const list5 = this.#sources.get(family$1) ?? [];
310170
+ if (!list5.includes(source))
310171
+ list5.push(source);
310172
+ this.#sources.set(family$1, list5);
310173
+ }
310174
+ if (!this.#status.has(family$1))
310175
+ this.#status.set(family$1, "unloaded");
310176
+ this.#trackFace(family$1, key2);
310177
+ if (!this.#faceStatus.has(key2))
310178
+ this.#faceStatus.set(key2, "unloaded");
310179
+ if (typeof identitySource === "string" && !this.#faceSources.has(key2))
310180
+ this.#faceSources.set(key2, identitySource);
310181
+ return {
310182
+ family: family$1,
310183
+ status: this.getStatus(family$1),
310184
+ changed: true
310185
+ };
310186
+ }
310187
+ #trackFace(family$1, key2) {
310188
+ const fam = normalizeFamilyKey$1(family$1);
310189
+ const set = this.#facesByFamily.get(fam) ?? /* @__PURE__ */ new Set;
310190
+ set.add(key2);
310191
+ this.#facesByFamily.set(fam, set);
310192
+ }
310193
+ isManaged(family$1) {
310194
+ return this.#managed.has(family$1);
310195
+ }
310196
+ getStatus(family$1) {
310197
+ const statuses = [];
310198
+ const faceKeys = this.#facesByFamily.get(normalizeFamilyKey$1(family$1));
310199
+ if (faceKeys)
310200
+ for (const k$1 of faceKeys)
310201
+ statuses.push(this.#faceStatus.get(k$1) ?? "unloaded");
310202
+ const legacy = this.#status.get(family$1);
310203
+ if (legacy)
310204
+ statuses.push(legacy);
310205
+ if (statuses.length === 0)
310206
+ return "unloaded";
310207
+ for (const s2 of [
310208
+ "failed",
310209
+ "timed_out",
310210
+ "fallback_used",
310211
+ "loaded",
310212
+ "loading",
310213
+ "unloaded"
310214
+ ])
310215
+ if (statuses.includes(s2))
310216
+ return s2;
310217
+ return "unloaded";
310218
+ }
310219
+ isAvailable(family$1) {
310220
+ if (!this.#fontSet)
310221
+ return false;
310222
+ try {
310223
+ return this.#fontSet.check(`${this.#probeSize} ${quoteFamily(family$1)}`);
310224
+ } catch {
310225
+ return false;
310226
+ }
310227
+ }
310228
+ awaitFace(family$1, timeoutMs = DEFAULT_FONT_LOAD_TIMEOUT_MS) {
310229
+ if (this.#status.get(family$1) === "loaded")
310230
+ return Promise.resolve({
310231
+ family: family$1,
310232
+ status: "loaded"
310233
+ });
310234
+ const existing = this.#inflight.get(family$1);
310235
+ if (existing)
310236
+ return existing;
310237
+ const probe = this.#loadOne(family$1, timeoutMs).finally(() => {
310238
+ this.#inflight.delete(family$1);
310239
+ });
310240
+ this.#inflight.set(family$1, probe);
310241
+ return probe;
310242
+ }
310243
+ async awaitFaces(families, options = {}) {
310244
+ const unique$2 = [...new Set(families)];
310245
+ const timeoutMs = options.timeoutMs ?? 3000;
310246
+ return Promise.all(unique$2.map((family$1) => this.awaitFace(family$1, timeoutMs)));
310247
+ }
310248
+ getRequiredFaces(families, timeoutMs = DEFAULT_FONT_LOAD_TIMEOUT_MS) {
310249
+ return [...new Set(families)].map((family$1) => ({
310250
+ family: family$1,
310251
+ status: this.getStatus(family$1),
310252
+ ready: this.awaitFace(family$1, timeoutMs)
310253
+ }));
310254
+ }
310255
+ getStates() {
310256
+ return [...this.#status.entries()].map(([family$1, status]) => ({
310257
+ family: family$1,
310258
+ status
310259
+ }));
310260
+ }
310261
+ getFaceStatus(request) {
310262
+ return this.#faceStatus.get(faceKeyOf$1(request.family, request.weight, request.style)) ?? "unloaded";
310263
+ }
310264
+ awaitFaceRequest(request, timeoutMs = DEFAULT_FONT_LOAD_TIMEOUT_MS) {
310265
+ const key2 = faceKeyOf$1(request.family, request.weight, request.style);
310266
+ if (this.#faceStatus.get(key2) === "loaded")
310267
+ return Promise.resolve({
310268
+ request,
310269
+ status: "loaded"
310270
+ });
310271
+ const existing = this.#faceInflight.get(key2);
310272
+ if (existing)
310273
+ return existing;
310274
+ const probe = this.#loadOneFace(request, key2, timeoutMs).finally(() => {
310275
+ this.#faceInflight.delete(key2);
310276
+ });
310277
+ this.#faceInflight.set(key2, probe);
310278
+ return probe;
310279
+ }
310280
+ async awaitFaceRequests(requests, options = {}) {
310281
+ const timeoutMs = options.timeoutMs ?? 3000;
310282
+ const seen = /* @__PURE__ */ new Set;
310283
+ const unique$2 = [];
310284
+ for (const r$1 of requests) {
310285
+ const key2 = faceKeyOf$1(r$1.family, r$1.weight, r$1.style);
310286
+ if (seen.has(key2))
310287
+ continue;
310288
+ seen.add(key2);
310289
+ unique$2.push(r$1);
310290
+ }
310291
+ return Promise.all(unique$2.map((r$1) => this.awaitFaceRequest(r$1, timeoutMs)));
310292
+ }
310293
+ async#loadOneFace(request, key2, timeoutMs) {
310294
+ this.#trackFace(request.family, key2);
310295
+ const fontSet = this.#fontSet;
310296
+ if (!fontSet) {
310297
+ this.#faceStatus.set(key2, "fallback_used");
310298
+ return {
310299
+ request,
310300
+ status: "fallback_used"
310301
+ };
310302
+ }
310303
+ this.#faceStatus.set(key2, "loading");
310304
+ const probe = faceProbe(request.family, request.weight, request.style, this.#probeSize);
310305
+ const TIMEOUT = Symbol("timeout");
310306
+ let handle3;
310307
+ const timeout$1 = new Promise((resolve3) => {
310308
+ handle3 = this.#scheduleTimeout(() => resolve3(TIMEOUT), timeoutMs);
310309
+ });
310310
+ try {
310311
+ const settled = await Promise.race([fontSet.load(probe), timeout$1]);
310312
+ if (settled === TIMEOUT) {
310313
+ this.#faceStatus.set(key2, "timed_out");
310314
+ return {
310315
+ request,
310316
+ status: "timed_out"
310317
+ };
310318
+ }
310319
+ const status = settled.length > 0 ? "loaded" : "fallback_used";
310320
+ this.#faceStatus.set(key2, status);
310321
+ return {
310322
+ request,
310323
+ status
310324
+ };
310325
+ } catch {
310326
+ this.#faceStatus.set(key2, "failed");
310327
+ this.#warnFaceFailureOnce(request, key2);
310328
+ return {
310329
+ request,
310330
+ status: "failed"
310331
+ };
310332
+ } finally {
310333
+ this.#cancelTimeout(handle3);
310334
+ }
310335
+ }
310336
+ #warnFaceFailureOnce(request, key2) {
310337
+ if (this.#warnedFaceFailures.has(key2))
310338
+ return;
310339
+ this.#warnedFaceFailures.add(key2);
310340
+ const src = this.#faceSources.get(key2);
310341
+ const detail = src ? ` from ${src}` : "";
310342
+ console.warn(`[superdoc] font face failed to load: "${request.family}" ${request.weight} ${request.style}${detail}. Check fonts.assetBaseUrl / fonts.resolveAssetUrl so the bundled .woff2 are served.`);
310343
+ }
310344
+ async#loadOne(family$1, timeoutMs) {
310345
+ const fontSet = this.#fontSet;
310346
+ if (!fontSet) {
310347
+ this.#status.set(family$1, "fallback_used");
310348
+ return {
310349
+ family: family$1,
310350
+ status: "fallback_used"
310351
+ };
310352
+ }
310353
+ this.#status.set(family$1, "loading");
310354
+ const probe = `${this.#probeSize} ${quoteFamily(family$1)}`;
310355
+ const TIMEOUT = Symbol("timeout");
310356
+ let handle3;
310357
+ const timeout$1 = new Promise((resolve3) => {
310358
+ handle3 = this.#scheduleTimeout(() => resolve3(TIMEOUT), timeoutMs);
310359
+ });
310360
+ try {
310361
+ const settled = await Promise.race([fontSet.load(probe), timeout$1]);
310362
+ if (settled === TIMEOUT) {
310363
+ this.#status.set(family$1, "timed_out");
310364
+ return {
310365
+ family: family$1,
310366
+ status: "timed_out"
310367
+ };
310368
+ }
310369
+ const status = settled.length > 0 ? "loaded" : "fallback_used";
310370
+ this.#status.set(family$1, status);
310371
+ return {
310372
+ family: family$1,
310373
+ status
310374
+ };
310375
+ } catch {
310376
+ this.#status.set(family$1, "failed");
310377
+ this.#warnLoadFailureOnce(family$1);
310378
+ return {
310379
+ family: family$1,
310380
+ status: "failed"
310381
+ };
310382
+ } finally {
310383
+ this.#cancelTimeout(handle3);
310384
+ }
310385
+ }
310386
+ #warnLoadFailureOnce(family$1) {
310387
+ if (this.#warnedFailures.has(family$1))
310388
+ return;
310389
+ this.#warnedFailures.add(family$1);
310390
+ const sources = this.#sources.get(family$1);
310391
+ const detail = sources && sources.length ? ` from ${sources.join(", ")}` : "";
310392
+ console.warn(`[superdoc] font asset failed to load for "${family$1}"${detail}. Check fonts.assetBaseUrl / fonts.resolveAssetUrl so the bundled .woff2 are served.`);
310393
+ }
310394
+ }, registriesByFontSet, domlessRegistry = null, hashParagraphBorder$2 = (border) => {
309992
310395
  const parts = [];
309993
310396
  if (border.style !== undefined)
309994
310397
  parts.push(`s:${border.style}`);
@@ -310305,7 +310708,7 @@ menclose::after {
310305
310708
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
310306
310709
  return;
310307
310710
  return value;
310308
- }, resolvePainterMarkerTextWidth = (markerTextWidthPx, marker) => getFiniteNonNegativeNumber(markerTextWidthPx) ?? getFiniteNonNegativeNumber(marker.glyphWidthPx) ?? getFiniteNonNegativeNumber(marker.markerBoxWidthPx) ?? 0, resolvePainterListMarkerGeometry = ({ wordLayout, indentLeftPx, hangingIndentPx, firstLineIndentPx, markerTextWidthPx }) => resolveListMarkerGeometry(wordLayout, indentLeftPx, firstLineIndentPx, hangingIndentPx, (_markerText, marker) => resolvePainterMarkerTextWidth(markerTextWidthPx, marker)), resolvePainterListTextStartPx = ({ wordLayout, indentLeftPx, hangingIndentPx, firstLineIndentPx, markerTextWidthPx }) => resolveListTextStartPx(wordLayout, indentLeftPx, firstLineIndentPx, hangingIndentPx, (_markerText, marker) => resolvePainterMarkerTextWidth(markerTextWidthPx, marker)), isMarkerSuffix = (suffix) => suffix === "tab" || suffix === "space" || suffix === "nothing", createListMarkerElement = (doc$12, markerText, run2, sourceAnchor) => {
310711
+ }, resolvePainterMarkerTextWidth = (markerTextWidthPx, marker) => getFiniteNonNegativeNumber(markerTextWidthPx) ?? getFiniteNonNegativeNumber(marker.glyphWidthPx) ?? getFiniteNonNegativeNumber(marker.markerBoxWidthPx) ?? 0, resolvePainterListMarkerGeometry = ({ wordLayout, indentLeftPx, hangingIndentPx, firstLineIndentPx, markerTextWidthPx }) => resolveListMarkerGeometry(wordLayout, indentLeftPx, firstLineIndentPx, hangingIndentPx, (_markerText, marker) => resolvePainterMarkerTextWidth(markerTextWidthPx, marker)), resolvePainterListTextStartPx = ({ wordLayout, indentLeftPx, hangingIndentPx, firstLineIndentPx, markerTextWidthPx }) => resolveListTextStartPx(wordLayout, indentLeftPx, firstLineIndentPx, hangingIndentPx, (_markerText, marker) => resolvePainterMarkerTextWidth(markerTextWidthPx, marker)), isMarkerSuffix = (suffix) => suffix === "tab" || suffix === "space" || suffix === "nothing", createListMarkerElement = (doc$12, markerText, run2, sourceAnchor, resolvePhysical = resolvePhysicalFamily) => {
310309
310712
  const markerContainer = doc$12.createElement("span");
310310
310713
  markerContainer.classList.add(DOM_CLASS_NAMES.LIST_MARKER);
310311
310714
  markerContainer.style.display = "inline-block";
@@ -310314,7 +310717,8 @@ menclose::after {
310314
310717
  markerEl.classList.add("superdoc-paragraph-marker");
310315
310718
  markerEl.textContent = markerText;
310316
310719
  markerEl.style.pointerEvents = "none";
310317
- markerEl.style.fontFamily = toCssFontFamily(run2.fontFamily) ?? run2.fontFamily ?? "";
310720
+ const cssFontFamily = toCssFontFamily(run2.fontFamily) ?? run2.fontFamily ?? "";
310721
+ markerEl.style.fontFamily = resolvePhysical(cssFontFamily);
310318
310722
  if (run2.fontSize != null)
310319
310723
  markerEl.style.fontSize = `${run2.fontSize}px`;
310320
310724
  markerEl.style.fontWeight = run2.bold ? "bold" : "";
@@ -310332,7 +310736,7 @@ menclose::after {
310332
310736
  applySourceAnchorDataset(markerEl, sourceAnchor);
310333
310737
  return markerContainer;
310334
310738
  }, renderLegacyListMarker = (params$1) => {
310335
- const { doc: doc$12, lineEl, wordLayout, markerLayout, markerMeasure, markerTextWidthPx, indentLeftPx, hangingIndentPx, firstLineIndentPx, isRtl, sourceAnchor } = params$1;
310739
+ const { doc: doc$12, lineEl, wordLayout, markerLayout, markerMeasure, markerTextWidthPx, indentLeftPx, hangingIndentPx, firstLineIndentPx, isRtl, sourceAnchor, resolvePhysical = resolvePhysicalFamily } = params$1;
310336
310740
  const markerTextWidth = markerTextWidthPx ?? markerMeasure?.markerTextWidth ?? 0;
310337
310741
  const markerGeometry = markerLayout?.justification === "left" && wordLayout?.firstLineIndentMode !== true && typeof markerTextWidth === "number" && Number.isFinite(markerTextWidth) && markerTextWidth >= 0 ? resolvePainterListMarkerGeometry({
310338
310742
  wordLayout,
@@ -310369,7 +310773,7 @@ menclose::after {
310369
310773
  lineEl.style.paddingLeft = `${anchorPoint}px`;
310370
310774
  if (markerLayout?.run?.vanish)
310371
310775
  return;
310372
- const markerContainer = createListMarkerElement(doc$12, markerLayout?.markerText ?? "", markerLayout?.run ?? {}, sourceAnchor);
310776
+ const markerContainer = createListMarkerElement(doc$12, markerLayout?.markerText ?? "", markerLayout?.run ?? {}, sourceAnchor, resolvePhysical);
310373
310777
  markerContainer.style.position = "relative";
310374
310778
  if (markerJustification === "right") {
310375
310779
  markerContainer.style.position = "absolute";
@@ -310390,14 +310794,14 @@ menclose::after {
310390
310794
  prependMarkerSuffix(doc$12, lineEl, isMarkerSuffix(suffix) ? suffix : undefined, suffixWidthPx, markerLayout?.run?.fontSize);
310391
310795
  lineEl.prepend(markerContainer);
310392
310796
  }, renderResolvedListMarker = (params$1) => {
310393
- const { doc: doc$12, lineEl, marker, isRtl, sourceAnchor } = params$1;
310797
+ const { doc: doc$12, lineEl, marker, isRtl, sourceAnchor, resolvePhysical = resolvePhysicalFamily } = params$1;
310394
310798
  if (isRtl)
310395
310799
  lineEl.style.paddingRight = `${marker.firstLinePaddingLeftPx}px`;
310396
310800
  else
310397
310801
  lineEl.style.paddingLeft = `${marker.firstLinePaddingLeftPx}px`;
310398
310802
  if (marker.vanish)
310399
310803
  return;
310400
- const markerContainer = createListMarkerElement(doc$12, marker.text, marker.run, marker.sourceAnchor ?? sourceAnchor);
310804
+ const markerContainer = createListMarkerElement(doc$12, marker.text, marker.run, marker.sourceAnchor ?? sourceAnchor, resolvePhysical);
310401
310805
  markerContainer.style.position = "relative";
310402
310806
  if (marker.justification === "right") {
310403
310807
  markerContainer.style.position = "absolute";
@@ -310665,7 +311069,7 @@ menclose::after {
310665
311069
  skipJustifyOverride: (resolvedLine?.skipJustify ?? false) || hasMultipleExplicitPositionedSegments
310666
311070
  }) ? Math.max(lineWidth, availableWidth) : lineWidth;
310667
311071
  }, renderResolvedLines = (params$1) => {
310668
- const { frameEl, block, resolvedContent: content3, markerTextWidth, renderLine: renderLine$1, captureLineSnapshot, convertFinalParagraphMark, lineTopOffset = 0, sourceAnchor } = params$1;
311072
+ const { frameEl, block, resolvedContent: content3, markerTextWidth, renderLine: renderLine$1, captureLineSnapshot, convertFinalParagraphMark, lineTopOffset = 0, sourceAnchor, resolvePhysical = resolvePhysicalFamily } = params$1;
310669
311073
  const renderedLines = [];
310670
311074
  const resolvedMarker = content3.marker;
310671
311075
  const expandedRunsForBlock = expandRunsForInlineNewlines(block.runs);
@@ -310695,7 +311099,8 @@ menclose::after {
310695
311099
  lineEl,
310696
311100
  marker: resolvedMarker,
310697
311101
  isRtl,
310698
- sourceAnchor
311102
+ sourceAnchor,
311103
+ resolvePhysical
310699
311104
  });
310700
311105
  if (convertFinalParagraphMark && index2 === content3.lines.length - 1 && !content3.continuesOnNext)
310701
311106
  convertParagraphMarkToCellMark(lineEl);
@@ -310718,7 +311123,7 @@ menclose::after {
310718
311123
  renderedLines
310719
311124
  };
310720
311125
  }, renderMeasuredLines = (params$1) => {
310721
- const { doc: doc$12, frameEl, block, measure, containerKind, width, localStartLine, localEndLine, linesOverride, lineIndexOffset = 0, continuesFromPrev, continuesOnNext, markerWidth, markerTextWidth, wordLayout, renderLine: renderLine$1, captureLineSnapshot, convertFinalParagraphMark, lineTopOffset = 0, sourceAnchor } = params$1;
311126
+ const { doc: doc$12, frameEl, block, measure, containerKind, width, localStartLine, localEndLine, linesOverride, lineIndexOffset = 0, continuesFromPrev, continuesOnNext, markerWidth, markerTextWidth, wordLayout, renderLine: renderLine$1, captureLineSnapshot, convertFinalParagraphMark, lineTopOffset = 0, sourceAnchor, resolvePhysical = resolvePhysicalFamily } = params$1;
310722
311127
  const lines = linesOverride ?? measure.lines ?? [];
310723
311128
  const paraIndent = block.attrs?.indent;
310724
311129
  const paraIndentLeft = paraIndent?.left ?? 0;
@@ -310792,7 +311197,8 @@ menclose::after {
310792
311197
  hangingIndentPx: markerHanging,
310793
311198
  firstLineIndentPx: markerFirstLine,
310794
311199
  isRtl,
310795
- sourceAnchor
311200
+ sourceAnchor,
311201
+ resolvePhysical
310796
311202
  });
310797
311203
  } else
310798
311204
  applyParagraphLineIndentation({
@@ -310946,7 +311352,7 @@ menclose::after {
310946
311352
  hasSdtContainerChrome
310947
311353
  };
310948
311354
  }, renderTableCell = (deps) => {
310949
- const { doc: doc$12, x, y: y$1, rowHeight, cellMeasure, cell: cell2, borders, useDefaultBorder, renderLine: renderLine$1, captureLineSnapshot, renderDrawingContent, context, applySdtDataset: applySdtDataset$1, chrome: chrome2, ancestorContainerKey, ancestorContainerSdt, ancestorContainerKeys, ancestorContainerSdts, onSdtContainerChrome, tableIndent, isRtl, cellWidth, fromLine, toLine } = deps;
311355
+ const { doc: doc$12, x, y: y$1, rowHeight, cellMeasure, cell: cell2, borders, useDefaultBorder, renderLine: renderLine$1, captureLineSnapshot, renderDrawingContent, context, applySdtDataset: applySdtDataset$1, chrome: chrome2, ancestorContainerKey, ancestorContainerSdt, ancestorContainerKeys, ancestorContainerSdts, onSdtContainerChrome, tableIndent, isRtl, cellWidth, fromLine, toLine, resolvePhysical } = deps;
310950
311356
  const padding = cell2?.attrs?.padding || {
310951
311357
  top: 0,
310952
311358
  left: 4,
@@ -311198,6 +311604,7 @@ menclose::after {
311198
311604
  },
311199
311605
  contentControlsChrome: chrome2,
311200
311606
  applySdtDataset: applySdtDataset$1,
311607
+ resolvePhysical,
311201
311608
  renderLine: ({ block: block$1, line, lineIndex, isLastLine, resolvedListTextStartPx }) => renderLine$1(block$1, line, {
311202
311609
  ...context,
311203
311610
  section: "body"
@@ -311374,7 +311781,7 @@ menclose::after {
311374
311781
  left: baseBorders.left
311375
311782
  };
311376
311783
  }, renderTableRow = (deps) => {
311377
- const { doc: doc$12, container, rowIndex, y: y$1, rowMeasure, row: row2, totalRows, tableBorders, columnWidths, allRowHeights, tableIndent, isRtl, context, renderLine: renderLine$1, captureLineSnapshot, renderDrawingContent, applySdtDataset: applySdtDataset$1, ancestorContainerKey, ancestorContainerSdt, ancestorContainerKeys, ancestorContainerSdts, onSdtContainerChrome, continuesFromPrev, continuesOnNext, partialRow, cellSpacingPx = 0, chrome: chrome2 } = deps;
311784
+ const { doc: doc$12, container, rowIndex, y: y$1, rowMeasure, row: row2, totalRows, tableBorders, columnWidths, allRowHeights, tableIndent, isRtl, context, renderLine: renderLine$1, captureLineSnapshot, renderDrawingContent, applySdtDataset: applySdtDataset$1, ancestorContainerKey, ancestorContainerSdt, ancestorContainerKeys, ancestorContainerSdts, onSdtContainerChrome, continuesFromPrev, continuesOnNext, partialRow, cellSpacingPx = 0, chrome: chrome2, resolvePhysical } = deps;
311378
311785
  const totalCols = columnWidths.length;
311379
311786
  const calculateXPosition = (gridColumnStart) => {
311380
311787
  let x = cellSpacingPx;
@@ -311461,12 +311868,13 @@ menclose::after {
311461
311868
  tableIndent,
311462
311869
  isRtl,
311463
311870
  cellWidth: computedCellWidth > 0 ? computedCellWidth : undefined,
311464
- chrome: chrome2
311871
+ chrome: chrome2,
311872
+ resolvePhysical
311465
311873
  });
311466
311874
  container.appendChild(cellElement);
311467
311875
  }
311468
311876
  }, renderTableFragment = (deps) => {
311469
- const { doc: doc$12, fragment: fragment2, block, measure, cellSpacingPx, effectiveColumnWidths, chrome: chrome2, context, sdtBoundary, ancestorContainerKey, ancestorContainerSdt, ancestorContainerKeys, ancestorContainerSdts, onSdtContainerChrome, renderLine: renderLine$1, captureLineSnapshot, renderDrawingContent, applyFragmentFrame, applySdtDataset: applySdtDataset$1, applyContainerSdtDataset: applyContainerSdtDataset$1, applyStyles: applyStyles$3 } = deps;
311877
+ const { doc: doc$12, fragment: fragment2, block, measure, cellSpacingPx, effectiveColumnWidths, chrome: chrome2, context, sdtBoundary, ancestorContainerKey, ancestorContainerSdt, ancestorContainerKeys, ancestorContainerSdts, onSdtContainerChrome, renderLine: renderLine$1, captureLineSnapshot, renderDrawingContent, applyFragmentFrame, applySdtDataset: applySdtDataset$1, applyContainerSdtDataset: applyContainerSdtDataset$1, applyStyles: applyStyles$3, resolvePhysical } = deps;
311470
311878
  if (!doc$12) {
311471
311879
  console.error("DomPainter: document is not available");
311472
311880
  if (typeof document !== "undefined") {
@@ -311648,7 +312056,8 @@ menclose::after {
311648
312056
  chrome: chrome2,
311649
312057
  continuesFromPrev: false,
311650
312058
  continuesOnNext: false,
311651
- cellSpacingPx
312059
+ cellSpacingPx,
312060
+ resolvePhysical
311652
312061
  });
311653
312062
  y$1 += rowMeasure.height + cellSpacingPx;
311654
312063
  }
@@ -311766,7 +312175,8 @@ menclose::after {
311766
312175
  continuesFromPrev: isFirstRenderedBodyRow && fragment2.continuesFromPrev === true,
311767
312176
  continuesOnNext: isLastRenderedBodyRow && fragment2.continuesOnNext === true,
311768
312177
  partialRow: partialRowData,
311769
- cellSpacingPx
312178
+ cellSpacingPx,
312179
+ resolvePhysical
311770
312180
  });
311771
312181
  y$1 += actualRowHeight + cellSpacingPx;
311772
312182
  }
@@ -311984,7 +312394,7 @@ menclose::after {
311984
312394
  else
311985
312395
  delete el.dataset.continuesOnNext;
311986
312396
  }, isMinimalWordLayout$2 = (value) => isMinimalWordLayout(value), renderParagraphFragment = (params$1) => {
311987
- const { doc: doc$12, fragment: fragment2, sdtBoundary, betweenInfo, resolvedItem, applyStyles: applyStyles$3, applyResolvedFragmentFrame, applyFragmentFrame, applySdtDataset: applySdtDataset$1, applyContainerSdtDataset: applyContainerSdtDataset$1, renderLine: renderLine$1, captureLineSnapshot, createErrorPlaceholder, contentControlsChrome } = params$1;
312397
+ const { doc: doc$12, fragment: fragment2, sdtBoundary, betweenInfo, resolvedItem, applyStyles: applyStyles$3, applyResolvedFragmentFrame, applyFragmentFrame, applySdtDataset: applySdtDataset$1, applyContainerSdtDataset: applyContainerSdtDataset$1, renderLine: renderLine$1, captureLineSnapshot, createErrorPlaceholder, contentControlsChrome, resolvePhysical = resolvePhysicalFamily } = params$1;
311988
312398
  try {
311989
312399
  if (!doc$12)
311990
312400
  throw new Error("DomPainter: document is not available");
@@ -312043,7 +312453,8 @@ menclose::after {
312043
312453
  sdtBoundary,
312044
312454
  applySdtDataset: applySdtDataset$1,
312045
312455
  applyContainerSdtDataset: applyContainerSdtDataset$1,
312046
- renderDropCap: (descriptor, dropCapMeasure) => renderDropCap(doc$12, descriptor, dropCapMeasure),
312456
+ resolvePhysical,
312457
+ renderDropCap: (descriptor, dropCapMeasure) => renderDropCap(doc$12, descriptor, dropCapMeasure, resolvePhysical),
312047
312458
  renderLine: renderLine$1,
312048
312459
  captureLineSnapshot: (lineEl, options) => {
312049
312460
  captureLineSnapshot(lineEl, {
@@ -312062,12 +312473,12 @@ menclose::after {
312062
312473
  });
312063
312474
  return createErrorPlaceholder(fragment2.blockId, error3);
312064
312475
  }
312065
- }, renderDropCap = (doc$12, descriptor, measure) => {
312476
+ }, renderDropCap = (doc$12, descriptor, measure, resolvePhysical = resolvePhysicalFamily) => {
312066
312477
  const { run: run2, mode } = descriptor;
312067
312478
  const dropCapEl = doc$12.createElement("span");
312068
312479
  dropCapEl.classList.add("superdoc-drop-cap");
312069
312480
  dropCapEl.textContent = run2.text;
312070
- dropCapEl.style.fontFamily = run2.fontFamily;
312481
+ dropCapEl.style.fontFamily = resolvePhysical(run2.fontFamily);
312071
312482
  dropCapEl.style.fontSize = `${run2.fontSize}px`;
312072
312483
  if (run2.bold)
312073
312484
  dropCapEl.style.fontWeight = "bold";
@@ -312160,344 +312571,7 @@ menclose::after {
312160
312571
  const visualTextEndOffset = lineEl.dir === "rtl" || lineEl.style.direction === "rtl" ? alignmentOffset : alignmentOffset + lineWidth;
312161
312572
  mark2.style.left = `${Math.max(0, leftOffsetPx + visualTextEndOffset)}px`;
312162
312573
  lineEl.appendChild(mark2);
312163
- }, SETTLED_STATUSES, BUNDLED_SUBSTITUTES, FontResolver = class {
312164
- #overrides = /* @__PURE__ */ new Map;
312165
- #version = 0;
312166
- map(logicalFamily, physicalFamily) {
312167
- const key2 = normalizeFamilyKey$2(logicalFamily);
312168
- const physical = physicalFamily?.trim();
312169
- if (!key2 || !physical)
312170
- return;
312171
- if (this.#overrides.get(key2) === physical)
312172
- return;
312173
- this.#overrides.set(key2, physical);
312174
- this.#version += 1;
312175
- }
312176
- unmap(logicalFamily) {
312177
- if (this.#overrides.delete(normalizeFamilyKey$2(logicalFamily)))
312178
- this.#version += 1;
312179
- }
312180
- reset() {
312181
- if (this.#overrides.size === 0)
312182
- return;
312183
- this.#overrides.clear();
312184
- this.#version += 1;
312185
- }
312186
- get version() {
312187
- return this.#version;
312188
- }
312189
- get signature() {
312190
- if (this.#overrides.size === 0)
312191
- return "";
312192
- return JSON.stringify([...this.#overrides.entries()].sort(([a2], [b$1]) => a2 < b$1 ? -1 : a2 > b$1 ? 1 : 0));
312193
- }
312194
- #physicalFor(bareFamily) {
312195
- const key2 = normalizeFamilyKey$2(bareFamily);
312196
- const override = this.#overrides.get(key2);
312197
- if (override)
312198
- return {
312199
- physical: override,
312200
- reason: "custom_mapping"
312201
- };
312202
- const bundled = BUNDLED_SUBSTITUTES[key2];
312203
- if (bundled)
312204
- return {
312205
- physical: bundled,
312206
- reason: "bundled_substitute"
312207
- };
312208
- return {
312209
- physical: bareFamily,
312210
- reason: "as_requested"
312211
- };
312212
- }
312213
- resolveFontFamily(logicalFamily) {
312214
- const primary = splitStack(logicalFamily)[0] ?? logicalFamily;
312215
- const { physical, reason } = this.#physicalFor(primary);
312216
- return {
312217
- logicalFamily,
312218
- physicalFamily: physical,
312219
- reason
312220
- };
312221
- }
312222
- resolvePhysicalFamily(cssFontFamily) {
312223
- if (!cssFontFamily)
312224
- return cssFontFamily;
312225
- const parts = splitStack(cssFontFamily);
312226
- if (parts.length === 0)
312227
- return cssFontFamily;
312228
- const { physical, reason } = this.#physicalFor(parts[0]);
312229
- if (reason === "as_requested")
312230
- return cssFontFamily;
312231
- return [physical, ...parts.slice(1)].join(", ");
312232
- }
312233
- resolvePrimaryPhysicalFamily(family$1) {
312234
- const primary = splitStack(family$1)[0] ?? family$1;
312235
- return this.#physicalFor(primary).physical;
312236
- }
312237
- resolvePhysicalFamilies(families) {
312238
- const out = /* @__PURE__ */ new Set;
312239
- for (const family$1 of families)
312240
- if (family$1)
312241
- out.add(this.resolvePrimaryPhysicalFamily(family$1));
312242
- return [...out];
312243
- }
312244
- }, defaultResolver, fontConfigVersion = 0, BUNDLED_MANIFEST, defaultAssetBase = "/fonts/", installedRegistries, DEFAULT_FONT_LOAD_TIMEOUT_MS = 3000, DEFAULT_PROBE_SIZE = "16px", FontRegistry = class {
312245
- #fontSet;
312246
- #FontFaceCtor;
312247
- #probeSize;
312248
- #scheduleTimeout;
312249
- #cancelTimeout;
312250
- #managed = /* @__PURE__ */ new Map;
312251
- #status = /* @__PURE__ */ new Map;
312252
- #sources = /* @__PURE__ */ new Map;
312253
- #warnedFailures = /* @__PURE__ */ new Set;
312254
- #inflight = /* @__PURE__ */ new Map;
312255
- #faceStatus = /* @__PURE__ */ new Map;
312256
- #faceInflight = /* @__PURE__ */ new Map;
312257
- #faceSources = /* @__PURE__ */ new Map;
312258
- #facesByFamily = /* @__PURE__ */ new Map;
312259
- #warnedFaceFailures = /* @__PURE__ */ new Set;
312260
- constructor(options = {}) {
312261
- this.#fontSet = options.fontSet ?? null;
312262
- this.#FontFaceCtor = options.FontFaceCtor ?? null;
312263
- this.#probeSize = options.probeSize ?? DEFAULT_PROBE_SIZE;
312264
- this.#scheduleTimeout = options.scheduleTimeout ?? ((cb, ms) => globalThis.setTimeout(cb, ms));
312265
- this.#cancelTimeout = options.cancelTimeout ?? ((handle3) => globalThis.clearTimeout(handle3));
312266
- }
312267
- register(descriptor) {
312268
- const { family: family$1, source, descriptors: descriptors2 } = descriptor;
312269
- if (this.#FontFaceCtor && this.#fontSet) {
312270
- const face = new this.#FontFaceCtor(family$1, source, descriptors2);
312271
- this.#fontSet.add(face);
312272
- this.#managed.set(family$1, face);
312273
- }
312274
- if (typeof source === "string") {
312275
- const list5 = this.#sources.get(family$1) ?? [];
312276
- if (!list5.includes(source))
312277
- list5.push(source);
312278
- this.#sources.set(family$1, list5);
312279
- }
312280
- if (!this.#status.has(family$1))
312281
- this.#status.set(family$1, "unloaded");
312282
- const key2 = faceKeyOf$1(family$1, normalizeWeight(descriptors2?.weight), normalizeStyle$1(descriptors2?.style));
312283
- this.#trackFace(family$1, key2);
312284
- if (!this.#faceStatus.has(key2))
312285
- this.#faceStatus.set(key2, "unloaded");
312286
- if (typeof source === "string" && !this.#faceSources.has(key2))
312287
- this.#faceSources.set(key2, source);
312288
- return {
312289
- family: family$1,
312290
- status: this.getStatus(family$1)
312291
- };
312292
- }
312293
- #trackFace(family$1, key2) {
312294
- const fam = normalizeFamilyKey$1(family$1);
312295
- const set = this.#facesByFamily.get(fam) ?? /* @__PURE__ */ new Set;
312296
- set.add(key2);
312297
- this.#facesByFamily.set(fam, set);
312298
- }
312299
- isManaged(family$1) {
312300
- return this.#managed.has(family$1);
312301
- }
312302
- getStatus(family$1) {
312303
- const statuses = [];
312304
- const faceKeys = this.#facesByFamily.get(normalizeFamilyKey$1(family$1));
312305
- if (faceKeys)
312306
- for (const k$1 of faceKeys)
312307
- statuses.push(this.#faceStatus.get(k$1) ?? "unloaded");
312308
- const legacy = this.#status.get(family$1);
312309
- if (legacy)
312310
- statuses.push(legacy);
312311
- if (statuses.length === 0)
312312
- return "unloaded";
312313
- for (const s2 of [
312314
- "failed",
312315
- "timed_out",
312316
- "fallback_used",
312317
- "loaded",
312318
- "loading",
312319
- "unloaded"
312320
- ])
312321
- if (statuses.includes(s2))
312322
- return s2;
312323
- return "unloaded";
312324
- }
312325
- isAvailable(family$1) {
312326
- if (!this.#fontSet)
312327
- return false;
312328
- try {
312329
- return this.#fontSet.check(`${this.#probeSize} ${quoteFamily(family$1)}`);
312330
- } catch {
312331
- return false;
312332
- }
312333
- }
312334
- awaitFace(family$1, timeoutMs = DEFAULT_FONT_LOAD_TIMEOUT_MS) {
312335
- if (this.#status.get(family$1) === "loaded")
312336
- return Promise.resolve({
312337
- family: family$1,
312338
- status: "loaded"
312339
- });
312340
- const existing = this.#inflight.get(family$1);
312341
- if (existing)
312342
- return existing;
312343
- const probe = this.#loadOne(family$1, timeoutMs).finally(() => {
312344
- this.#inflight.delete(family$1);
312345
- });
312346
- this.#inflight.set(family$1, probe);
312347
- return probe;
312348
- }
312349
- async awaitFaces(families, options = {}) {
312350
- const unique$2 = [...new Set(families)];
312351
- const timeoutMs = options.timeoutMs ?? 3000;
312352
- return Promise.all(unique$2.map((family$1) => this.awaitFace(family$1, timeoutMs)));
312353
- }
312354
- getRequiredFaces(families, timeoutMs = DEFAULT_FONT_LOAD_TIMEOUT_MS) {
312355
- return [...new Set(families)].map((family$1) => ({
312356
- family: family$1,
312357
- status: this.getStatus(family$1),
312358
- ready: this.awaitFace(family$1, timeoutMs)
312359
- }));
312360
- }
312361
- getStates() {
312362
- return [...this.#status.entries()].map(([family$1, status]) => ({
312363
- family: family$1,
312364
- status
312365
- }));
312366
- }
312367
- getFaceStatus(request) {
312368
- return this.#faceStatus.get(faceKeyOf$1(request.family, request.weight, request.style)) ?? "unloaded";
312369
- }
312370
- awaitFaceRequest(request, timeoutMs = DEFAULT_FONT_LOAD_TIMEOUT_MS) {
312371
- const key2 = faceKeyOf$1(request.family, request.weight, request.style);
312372
- if (this.#faceStatus.get(key2) === "loaded")
312373
- return Promise.resolve({
312374
- request,
312375
- status: "loaded"
312376
- });
312377
- const existing = this.#faceInflight.get(key2);
312378
- if (existing)
312379
- return existing;
312380
- const probe = this.#loadOneFace(request, key2, timeoutMs).finally(() => {
312381
- this.#faceInflight.delete(key2);
312382
- });
312383
- this.#faceInflight.set(key2, probe);
312384
- return probe;
312385
- }
312386
- async awaitFaceRequests(requests, options = {}) {
312387
- const timeoutMs = options.timeoutMs ?? 3000;
312388
- const seen = /* @__PURE__ */ new Set;
312389
- const unique$2 = [];
312390
- for (const r$1 of requests) {
312391
- const key2 = faceKeyOf$1(r$1.family, r$1.weight, r$1.style);
312392
- if (seen.has(key2))
312393
- continue;
312394
- seen.add(key2);
312395
- unique$2.push(r$1);
312396
- }
312397
- return Promise.all(unique$2.map((r$1) => this.awaitFaceRequest(r$1, timeoutMs)));
312398
- }
312399
- async#loadOneFace(request, key2, timeoutMs) {
312400
- this.#trackFace(request.family, key2);
312401
- const fontSet = this.#fontSet;
312402
- if (!fontSet) {
312403
- this.#faceStatus.set(key2, "fallback_used");
312404
- return {
312405
- request,
312406
- status: "fallback_used"
312407
- };
312408
- }
312409
- this.#faceStatus.set(key2, "loading");
312410
- const probe = faceProbe(request.family, request.weight, request.style, this.#probeSize);
312411
- const TIMEOUT = Symbol("timeout");
312412
- let handle3;
312413
- const timeout$1 = new Promise((resolve3) => {
312414
- handle3 = this.#scheduleTimeout(() => resolve3(TIMEOUT), timeoutMs);
312415
- });
312416
- try {
312417
- const settled = await Promise.race([fontSet.load(probe), timeout$1]);
312418
- if (settled === TIMEOUT) {
312419
- this.#faceStatus.set(key2, "timed_out");
312420
- return {
312421
- request,
312422
- status: "timed_out"
312423
- };
312424
- }
312425
- const status = settled.length > 0 ? "loaded" : "fallback_used";
312426
- this.#faceStatus.set(key2, status);
312427
- return {
312428
- request,
312429
- status
312430
- };
312431
- } catch {
312432
- this.#faceStatus.set(key2, "failed");
312433
- this.#warnFaceFailureOnce(request, key2);
312434
- return {
312435
- request,
312436
- status: "failed"
312437
- };
312438
- } finally {
312439
- this.#cancelTimeout(handle3);
312440
- }
312441
- }
312442
- #warnFaceFailureOnce(request, key2) {
312443
- if (this.#warnedFaceFailures.has(key2))
312444
- return;
312445
- this.#warnedFaceFailures.add(key2);
312446
- const src = this.#faceSources.get(key2);
312447
- const detail = src ? ` from ${src}` : "";
312448
- console.warn(`[superdoc] font face failed to load: "${request.family}" ${request.weight} ${request.style}${detail}. Check fonts.assetBaseUrl / fonts.resolveAssetUrl so the bundled .woff2 are served.`);
312449
- }
312450
- async#loadOne(family$1, timeoutMs) {
312451
- const fontSet = this.#fontSet;
312452
- if (!fontSet) {
312453
- this.#status.set(family$1, "fallback_used");
312454
- return {
312455
- family: family$1,
312456
- status: "fallback_used"
312457
- };
312458
- }
312459
- this.#status.set(family$1, "loading");
312460
- const probe = `${this.#probeSize} ${quoteFamily(family$1)}`;
312461
- const TIMEOUT = Symbol("timeout");
312462
- let handle3;
312463
- const timeout$1 = new Promise((resolve3) => {
312464
- handle3 = this.#scheduleTimeout(() => resolve3(TIMEOUT), timeoutMs);
312465
- });
312466
- try {
312467
- const settled = await Promise.race([fontSet.load(probe), timeout$1]);
312468
- if (settled === TIMEOUT) {
312469
- this.#status.set(family$1, "timed_out");
312470
- return {
312471
- family: family$1,
312472
- status: "timed_out"
312473
- };
312474
- }
312475
- const status = settled.length > 0 ? "loaded" : "fallback_used";
312476
- this.#status.set(family$1, status);
312477
- return {
312478
- family: family$1,
312479
- status
312480
- };
312481
- } catch {
312482
- this.#status.set(family$1, "failed");
312483
- this.#warnLoadFailureOnce(family$1);
312484
- return {
312485
- family: family$1,
312486
- status: "failed"
312487
- };
312488
- } finally {
312489
- this.#cancelTimeout(handle3);
312490
- }
312491
- }
312492
- #warnLoadFailureOnce(family$1) {
312493
- if (this.#warnedFailures.has(family$1))
312494
- return;
312495
- this.#warnedFailures.add(family$1);
312496
- const sources = this.#sources.get(family$1);
312497
- const detail = sources && sources.length ? ` from ${sources.join(", ")}` : "";
312498
- console.warn(`[superdoc] font asset failed to load for "${family$1}"${detail}. Check fonts.assetBaseUrl / fonts.resolveAssetUrl so the bundled .woff2 are served.`);
312499
- }
312500
- }, registriesByFontSet, domlessRegistry = null, DEFAULT_SUPERSCRIPT_RAISE_RATIO = 0.33, DEFAULT_SUBSCRIPT_LOWER_RATIO = 0.14, underlineThicknessPx = (fontSize) => Math.max(1, Math.round(fontSize / 14)), hasVerticalPositioning = (run2) => normalizeBaselineShift(run2.baselineShift) != null || run2.vertAlign === "superscript" || run2.vertAlign === "subscript", applyRunVerticalPositioning = (element3, run2) => {
312574
+ }, DEFAULT_SUPERSCRIPT_RAISE_RATIO = 0.33, DEFAULT_SUBSCRIPT_LOWER_RATIO = 0.14, underlineThicknessPx = (fontSize) => Math.max(1, Math.round(fontSize / 14)), hasVerticalPositioning = (run2) => normalizeBaselineShift(run2.baselineShift) != null || run2.vertAlign === "superscript" || run2.vertAlign === "subscript", applyRunVerticalPositioning = (element3, run2) => {
312501
312575
  if (hasVerticalPositioning(run2))
312502
312576
  element3.style.lineHeight = "1";
312503
312577
  const explicitBaselineShift = normalizeBaselineShift(run2.baselineShift);
@@ -312701,8 +312775,10 @@ menclose::after {
312701
312775
  annotation.style.height = `${run2.size.height}px`;
312702
312776
  }
312703
312777
  }
312704
- if (run2.fontFamily)
312705
- annotation.style.fontFamily = run2.fontFamily;
312778
+ {
312779
+ const resolvePhysical = context.resolvePhysical ?? resolvePhysicalFamily;
312780
+ annotation.style.fontFamily = resolvePhysical(run2.fontFamily || "Arial, sans-serif");
312781
+ }
312706
312782
  {
312707
312783
  const fontSize = run2.fontSize ? typeof run2.fontSize === "number" ? `${run2.fontSize}pt` : run2.fontSize : BROWSER_DEFAULT_FONT_SIZE;
312708
312784
  annotation.style.fontSize = fontSize;
@@ -315413,6 +315489,7 @@ menclose::after {
315413
315489
  applyFragmentFrame: (el, paraFragment) => this.applyFragmentFrame(el, paraFragment, context.section, context.story),
315414
315490
  applySdtDataset,
315415
315491
  applyContainerSdtDataset,
315492
+ resolvePhysical: this.options.resolvePhysical,
315416
315493
  renderLine: ({ block, line, availableWidth, lineIndex, skipJustify, preExpandedRuns, resolvedListTextStartPx, indentOffsetOverride, paragraphMarkLeftOffsetOverride }) => this.renderLine(block, line, context, availableWidth, lineIndex, skipJustify, preExpandedRuns, resolvedListTextStartPx, indentOffsetOverride, paragraphMarkLeftOffsetOverride),
315417
315494
  captureLineSnapshot: (lineEl, options) => {
315418
315495
  this.capturePaintSnapshotLine(lineEl, context, {
@@ -316185,7 +316262,8 @@ menclose::after {
316185
316262
  applyFragmentFrame: applyFragmentFrameWithSection,
316186
316263
  applySdtDataset,
316187
316264
  applyContainerSdtDataset,
316188
- applyStyles
316265
+ applyStyles,
316266
+ resolvePhysical: this.options.resolvePhysical
316189
316267
  });
316190
316268
  if (resolvedItem) {
316191
316269
  this.applyResolvedFragmentFrame(el, resolvedItem, fragment2, context.section, context.story);
@@ -323661,14 +323739,14 @@ menclose::after {
323661
323739
  if (value === ",")
323662
323740
  return ",";
323663
323741
  return DEFAULT_DECIMAL_SEPARATOR2;
323664
- }, DROP_CAP_PADDING_PX = 4, measureDropCap = (ctx$1, descriptor, spacing, resolvePhysical = resolvePhysicalFamily) => {
323742
+ }, DROP_CAP_PADDING_PX = 4, measureDropCap = (ctx$1, descriptor, spacing, fontContext) => {
323665
323743
  const { run: run2, lines, mode } = descriptor;
323666
323744
  const { font } = buildFontString({
323667
323745
  fontFamily: run2.fontFamily,
323668
323746
  fontSize: run2.fontSize,
323669
323747
  bold: run2.bold,
323670
323748
  italic: run2.italic
323671
- }, resolvePhysical);
323749
+ }, fontContext);
323672
323750
  ctx$1.font = font;
323673
323751
  const displayText = applyTextTransform(run2.text, run2);
323674
323752
  const metrics = ctx$1.measureText(displayText);
@@ -325609,14 +325687,22 @@ menclose::after {
325609
325687
  this.#lastSummary = summarize(results);
325610
325688
  return this.#lastSummary;
325611
325689
  }
325612
- notifyFontConfigChanged() {
325690
+ notifyDocumentFontConfigChanged(options) {
325613
325691
  this.#fontConfigVersion += 1;
325614
- bumpFontConfigVersion();
325615
325692
  this.#resetRequiredAndSeen();
325616
325693
  this.#lateLoadScheduler.cancel();
325617
- this.#invalidateCaches();
325694
+ if (options?.availabilityChanged) {
325695
+ bumpFontConfigVersion();
325696
+ this.#invalidateCaches();
325697
+ }
325618
325698
  this.#requestReflow();
325619
325699
  }
325700
+ invalidateCachesForConfigRegistration() {
325701
+ this.#invalidateCaches();
325702
+ }
325703
+ resolveRegistry() {
325704
+ return this.#resolveContext().registry;
325705
+ }
325620
325706
  resetForDocumentChange() {
325621
325707
  this.#lateLoadScheduler.cancel();
325622
325708
  this.#resetRequiredAndSeen();
@@ -325698,7 +325784,139 @@ menclose::after {
325698
325784
  #flushLateFontLoads() {
325699
325785
  this.#requestReflow();
325700
325786
  }
325701
- }, FACE_STATUS_PRIORITY, DEFAULT_SEMANTIC_FOOTNOTE_HEADING_STYLE, NATIVE_SELECTION_STYLES = `
325787
+ }, FACE_STATUS_PRIORITY, DocumentFontController = class {
325788
+ #resolver;
325789
+ #getGate;
325790
+ #onDocumentFontConfigApplied;
325791
+ #scheduleMicrotask;
325792
+ #runtimeReflowQueued = false;
325793
+ #runtimeReflowToken = 0;
325794
+ #runtimeAvailabilityChanged = false;
325795
+ constructor(deps) {
325796
+ this.#resolver = deps.resolver;
325797
+ this.#getGate = deps.getGate;
325798
+ this.#onDocumentFontConfigApplied = deps.onDocumentFontConfigApplied;
325799
+ this.#scheduleMicrotask = deps.scheduleMicrotask ?? defaultScheduleMicrotask;
325800
+ }
325801
+ map(mappings) {
325802
+ if (this.#applyMappings(mappings))
325803
+ this.#queueRuntimeReflow();
325804
+ }
325805
+ unmap(families) {
325806
+ const before2 = this.#resolver.signature;
325807
+ for (const family$1 of Array.isArray(families) ? families : [families])
325808
+ this.#resolver.unmap(family$1);
325809
+ this.#reflowIfChanged(before2);
325810
+ }
325811
+ reset() {
325812
+ this.#cancelPendingRuntimeReflow();
325813
+ this.#resolver.reset();
325814
+ }
325815
+ dispose() {
325816
+ this.#cancelPendingRuntimeReflow();
325817
+ }
325818
+ applyInitialConfig(config2) {
325819
+ this.#cancelPendingRuntimeReflow();
325820
+ if (!config2)
325821
+ return;
325822
+ const registered$1 = this.#registerFamilies(config2.families);
325823
+ this.#applyMappings(config2.map);
325824
+ if (registered$1)
325825
+ this.#getGate()?.invalidateCachesForConfigRegistration();
325826
+ }
325827
+ add(families) {
325828
+ let committed = false;
325829
+ try {
325830
+ this.#registerFamilies(families, () => {
325831
+ committed = true;
325832
+ });
325833
+ } finally {
325834
+ if (committed) {
325835
+ this.#runtimeAvailabilityChanged = true;
325836
+ this.#queueRuntimeReflow();
325837
+ }
325838
+ }
325839
+ }
325840
+ #registerFamilies(families, onFaceRegistered) {
325841
+ if (!families?.length)
325842
+ return false;
325843
+ const registry2 = this.#getGate()?.resolveRegistry();
325844
+ if (!registry2)
325845
+ throw new Error("[superdoc] fonts.add: the font registry is not ready yet");
325846
+ let changed = false;
325847
+ for (const entry of families) {
325848
+ const family$1 = entry?.family;
325849
+ const faces = entry?.faces;
325850
+ if (typeof family$1 !== "string" || !family$1.trim())
325851
+ throw new Error('[superdoc] fonts.add: each family needs a non-empty "family" name');
325852
+ if (!Array.isArray(faces) || faces.length === 0)
325853
+ throw new Error(`[superdoc] fonts.add: family "${family$1}" needs at least one face in "faces"`);
325854
+ for (const face of faces) {
325855
+ if (!face || typeof face.source !== "string" || !face.source.trim())
325856
+ throw new Error(`[superdoc] fonts.add: family "${family$1}" has a face with no "source" URL`);
325857
+ if (registry2.register({
325858
+ family: family$1,
325859
+ source: toCssFontSource(face.source),
325860
+ descriptors: {
325861
+ weight: face.weight == null ? undefined : String(face.weight),
325862
+ style: face.style
325863
+ }
325864
+ }).changed) {
325865
+ changed = true;
325866
+ onFaceRegistered?.();
325867
+ }
325868
+ }
325869
+ }
325870
+ return changed;
325871
+ }
325872
+ async preload(families) {
325873
+ if (!Array.isArray(families))
325874
+ throw new Error('[superdoc] fonts.preload expects an array of logical family names, e.g. preload(["Georgia"])');
325875
+ const registry2 = this.#getGate()?.resolveRegistry();
325876
+ if (!registry2)
325877
+ throw new Error("[superdoc] fonts.preload: the font registry is not ready yet");
325878
+ const requests = families.map((logical) => ({
325879
+ family: this.#resolver.resolvePrimaryPhysicalFamily(logical),
325880
+ weight: "400",
325881
+ style: "normal"
325882
+ }));
325883
+ await registry2.awaitFaceRequests(requests);
325884
+ }
325885
+ #reflowIfChanged(signatureBefore) {
325886
+ if (this.#resolver.signature !== signatureBefore)
325887
+ this.#queueRuntimeReflow();
325888
+ }
325889
+ #applyMappings(mappings) {
325890
+ if (!mappings)
325891
+ return false;
325892
+ const before2 = this.#resolver.signature;
325893
+ for (const [logicalFamily, physicalFamily] of Object.entries(mappings))
325894
+ this.#resolver.map(logicalFamily, physicalFamily);
325895
+ return this.#resolver.signature !== before2;
325896
+ }
325897
+ #queueRuntimeReflow() {
325898
+ if (this.#runtimeReflowQueued)
325899
+ return;
325900
+ this.#runtimeReflowQueued = true;
325901
+ const token$1 = ++this.#runtimeReflowToken;
325902
+ this.#scheduleMicrotask(() => {
325903
+ if (!this.#runtimeReflowQueued || token$1 !== this.#runtimeReflowToken)
325904
+ return;
325905
+ this.#runtimeReflowQueued = false;
325906
+ const availabilityChanged = this.#runtimeAvailabilityChanged;
325907
+ this.#runtimeAvailabilityChanged = false;
325908
+ this.#onDocumentFontConfigApplied();
325909
+ this.#getGate()?.notifyDocumentFontConfigChanged({ availabilityChanged });
325910
+ });
325911
+ }
325912
+ #cancelPendingRuntimeReflow() {
325913
+ this.#runtimeAvailabilityChanged = false;
325914
+ if (!this.#runtimeReflowQueued)
325915
+ return;
325916
+ this.#runtimeReflowQueued = false;
325917
+ this.#runtimeReflowToken += 1;
325918
+ }
325919
+ }, DEFAULT_SEMANTIC_FOOTNOTE_HEADING_STYLE, NATIVE_SELECTION_STYLES = `
325702
325920
  /* Hide native browser selection on layout engine content.
325703
325921
  * We render our own selection overlay via PresentationEditor's #localSelectionLayer
325704
325922
  * for precise control over selection geometry across pages and zoom levels. */
@@ -325775,7 +325993,7 @@ menclose::after {
325775
325993
  return;
325776
325994
  console.log(...args$1);
325777
325995
  }, HEADER_FOOTER_INIT_BUDGET_MS = 200, MAX_ZOOM_WARNING_THRESHOLD = 10, MAX_SELECTION_RECTS_PER_USER = 100, SEMANTIC_RESIZE_DEBOUNCE_MS = 120, MIN_SEMANTIC_CONTENT_WIDTH_PX = 1, GLOBAL_PERFORMANCE, PresentationEditor, ICONS, TEXTS, tableActionsOptions, TRACKED_MARK_NAMES;
325778
- var init_src_CF4og_LY_es = __esm(() => {
325996
+ var init_src_B1aSE_tB_es = __esm(() => {
325779
325997
  init_rolldown_runtime_Bg48TavK_es();
325780
325998
  init_SuperConverter_B9mZiCO9_es();
325781
325999
  init_jszip_C49i9kUs_es();
@@ -352650,6 +352868,33 @@ function print() { __p += __j.call(arguments, '') }
352650
352868
  "wave",
352651
352869
  "doubleWave"
352652
352870
  ]);
352871
+ SETTLED_STATUSES = [
352872
+ "loaded",
352873
+ "failed",
352874
+ "timed_out",
352875
+ "fallback_used"
352876
+ ];
352877
+ BUNDLED_SUBSTITUTES = Object.freeze({
352878
+ calibri: "Carlito",
352879
+ cambria: "Caladea",
352880
+ arial: "Liberation Sans",
352881
+ "times new roman": "Liberation Serif",
352882
+ "courier new": "Liberation Mono"
352883
+ });
352884
+ defaultResolver = new FontResolver;
352885
+ DEFAULT_FONT_MEASURE_CONTEXT = Object.freeze({
352886
+ resolvePhysical: resolvePhysicalFamily,
352887
+ fontSignature: ""
352888
+ });
352889
+ BUNDLED_MANIFEST = Object.freeze([
352890
+ family("Carlito", "Carlito", "OFL-1.1"),
352891
+ family("Caladea", "Caladea", "Apache-2.0"),
352892
+ family("Liberation Sans", "LiberationSans", "OFL-1.1"),
352893
+ family("Liberation Serif", "LiberationSerif", "OFL-1.1"),
352894
+ family("Liberation Mono", "LiberationMono", "OFL-1.1")
352895
+ ]);
352896
+ installedRegistries = /* @__PURE__ */ new WeakMap;
352897
+ registriesByFontSet = /* @__PURE__ */ new WeakMap;
352653
352898
  PX_PER_PT$12 = 96 / 72;
352654
352899
  BORDER_SIDES3 = [
352655
352900
  "top",
@@ -352681,29 +352926,6 @@ function print() { __p += __j.call(arguments, '') }
352681
352926
  "sdtDocpartId",
352682
352927
  "sdtDocpartInstruction"
352683
352928
  ];
352684
- SETTLED_STATUSES = [
352685
- "loaded",
352686
- "failed",
352687
- "timed_out",
352688
- "fallback_used"
352689
- ];
352690
- BUNDLED_SUBSTITUTES = Object.freeze({
352691
- calibri: "Carlito",
352692
- cambria: "Caladea",
352693
- arial: "Liberation Sans",
352694
- "times new roman": "Liberation Serif",
352695
- "courier new": "Liberation Mono"
352696
- });
352697
- defaultResolver = new FontResolver;
352698
- BUNDLED_MANIFEST = Object.freeze([
352699
- family("Carlito", "Carlito", "OFL-1.1"),
352700
- family("Caladea", "Caladea", "Apache-2.0"),
352701
- family("Liberation Sans", "LiberationSans", "OFL-1.1"),
352702
- family("Liberation Serif", "LiberationSerif", "OFL-1.1"),
352703
- family("Liberation Mono", "LiberationMono", "OFL-1.1")
352704
- ]);
352705
- installedRegistries = /* @__PURE__ */ new WeakMap;
352706
- registriesByFontSet = /* @__PURE__ */ new WeakMap;
352707
352929
  OPERATOR_CHARS = new Set([
352708
352930
  "+",
352709
352931
  "-",
@@ -353936,6 +354158,14 @@ function print() { __p += __j.call(arguments, '') }
353936
354158
  #selectionSync = new SelectionSyncCoordinator;
353937
354159
  #fontGate = null;
353938
354160
  #fontResolver = createFontResolver();
354161
+ #nextFontsChangedSource = null;
354162
+ #fontController = new DocumentFontController({
354163
+ resolver: this.#fontResolver,
354164
+ getGate: () => this.#fontGate,
354165
+ onDocumentFontConfigApplied: () => {
354166
+ this.#nextFontsChangedSource = "config-change";
354167
+ }
354168
+ });
353939
354169
  #fontPlanBlocks = null;
353940
354170
  #lastFontsChangedKey = null;
353941
354171
  #lastFontsChangedPayload = null;
@@ -354222,16 +354452,7 @@ function print() { __p += __j.call(arguments, '') }
354222
354452
  getDocumentFonts: () => {
354223
354453
  return this.#editor.converter?.getDocumentFonts?.() ?? [];
354224
354454
  },
354225
- requestReflow: () => {
354226
- this.#layoutState = {
354227
- ...this.#layoutState,
354228
- blocks: [],
354229
- measures: [],
354230
- layout: null
354231
- };
354232
- this.#pendingDocChange = true;
354233
- this.#scheduleRerender();
354234
- },
354455
+ requestReflow: () => this.#requestFontReflow(),
354235
354456
  getRequiredFaces: () => planRequiredFontFaces(this.#fontPlanBlocks, this.#fontResolver),
354236
354457
  fontResolver: this.#fontResolver,
354237
354458
  onRegistryResolved: (registry2) => installBundledSubstitutes(registry2, {
@@ -354249,6 +354470,7 @@ function print() { __p += __j.call(arguments, '') }
354249
354470
  } : null;
354250
354471
  }
354251
354472
  });
354473
+ this.#fontController.applyInitialConfig(this.#options.fontAssets);
354252
354474
  if (typeof this.#options.disableContextMenu === "boolean")
354253
354475
  this.setContextMenuDisabled(this.#options.disableContextMenu);
354254
354476
  this.#setupHeaderFooterSession();
@@ -355208,6 +355430,28 @@ function print() { __p += __j.call(arguments, '') }
355208
355430
  getMissingFonts() {
355209
355431
  return this.getFontReport().filter((record) => record.missing).map((record) => record.logicalFamily);
355210
355432
  }
355433
+ mapFonts(mappings) {
355434
+ this.#fontController.map(mappings);
355435
+ }
355436
+ unmapFonts(families) {
355437
+ this.#fontController.unmap(families);
355438
+ }
355439
+ addFonts(families) {
355440
+ this.#fontController.add(families);
355441
+ }
355442
+ async preloadFonts(families) {
355443
+ await this.#fontController.preload(families);
355444
+ }
355445
+ #requestFontReflow() {
355446
+ this.#layoutState = {
355447
+ ...this.#layoutState,
355448
+ blocks: [],
355449
+ measures: [],
355450
+ layout: null
355451
+ };
355452
+ this.#pendingDocChange = true;
355453
+ this.#scheduleRerender();
355454
+ }
355211
355455
  #emitFontsChangedIfChanged(summary) {
355212
355456
  const gate = this.#fontGate;
355213
355457
  if (!gate)
@@ -355218,6 +355462,9 @@ function print() { __p += __j.call(arguments, '') }
355218
355462
  return;
355219
355463
  const isInitial = this.#lastFontsChangedKey === null;
355220
355464
  this.#lastFontsChangedKey = key2;
355465
+ const pendingSource = this.#nextFontsChangedSource;
355466
+ this.#nextFontsChangedSource = null;
355467
+ const source = isInitial ? "initial" : pendingSource ?? "late-load";
355221
355468
  let resolutions;
355222
355469
  try {
355223
355470
  resolutions = gate.getReport();
@@ -355235,7 +355482,7 @@ function print() { __p += __j.call(arguments, '') }
355235
355482
  fallbackUsed: 0,
355236
355483
  results: []
355237
355484
  },
355238
- source: isInitial ? "initial" : "late-load",
355485
+ source,
355239
355486
  version: version$1
355240
355487
  };
355241
355488
  this.#lastFontsChangedPayload = payload;
@@ -355246,6 +355493,11 @@ function print() { __p += __j.call(arguments, '') }
355246
355493
  getLastFontsChangedPayload() {
355247
355494
  return this.#lastFontsChangedPayload;
355248
355495
  }
355496
+ #resetFontReportStateForDocumentChange() {
355497
+ this.#nextFontsChangedSource = null;
355498
+ this.#lastFontsChangedKey = null;
355499
+ this.#lastFontsChangedPayload = null;
355500
+ }
355249
355501
  getLayoutOptions() {
355250
355502
  return { ...this.#layoutOptions };
355251
355503
  }
@@ -356114,6 +356366,7 @@ function print() { __p += __j.call(arguments, '') }
356114
356366
  this.#postPaintPipeline.destroy();
356115
356367
  this.#proofingManager?.dispose();
356116
356368
  this.#proofingManager = null;
356369
+ this.#fontController.dispose();
356117
356370
  this.#fontGate?.dispose();
356118
356371
  this.#fontGate = null;
356119
356372
  if (this.#cursorUpdateTimer !== null) {
@@ -356474,7 +356727,10 @@ function print() { __p += __j.call(arguments, '') }
356474
356727
  });
356475
356728
  const handleDocumentReplaced = () => {
356476
356729
  this.#fontGate?.resetForDocumentChange();
356477
- this.#fontResolver.reset();
356730
+ this.#fontController.reset();
356731
+ this.#layoutFontSignature = "";
356732
+ this.#fontController.applyInitialConfig(this.#options.fontAssets);
356733
+ this.#resetFontReportStateForDocumentChange();
356478
356734
  this.#refreshHeaderFooterStructureThenRerender({ purgeCachedEditors: true });
356479
356735
  };
356480
356736
  this.#editor.on("documentReplaced", handleDocumentReplaced);
@@ -357602,6 +357858,10 @@ function print() { __p += __j.call(arguments, '') }
357602
357858
  const resolvePhysical = (css) => this.#fontResolver.resolvePhysicalFamily(css);
357603
357859
  const fontSignature = this.#fontResolver.signature;
357604
357860
  const previousFontSignature = this.#layoutFontSignature;
357861
+ const fontMeasureContext = {
357862
+ resolvePhysical,
357863
+ fontSignature
357864
+ };
357605
357865
  let layout;
357606
357866
  let measures;
357607
357867
  let resolvedLayout;
@@ -357625,8 +357885,8 @@ function print() { __p += __j.call(arguments, '') }
357625
357885
  } catch {}
357626
357886
  try {
357627
357887
  const incrementalLayoutStart = perfNow();
357628
- const result = await incrementalLayout(previousBlocks, previousLayout, blocksForLayout, layoutOptions, (block, constraints) => measureBlock(block, constraints, resolvePhysical), headerFooterInput ?? undefined, previousMeasures, {
357629
- fontSignature,
357888
+ const result = await incrementalLayout(previousBlocks, previousLayout, blocksForLayout, layoutOptions, (block, constraints) => measureBlock(block, constraints, fontMeasureContext), headerFooterInput ?? undefined, previousMeasures, {
357889
+ fontContext: fontMeasureContext,
357630
357890
  previousFontSignature
357631
357891
  });
357632
357892
  perfLog(`[Perf] incrementalLayout: ${(perfNow() - incrementalLayoutStart).toFixed(2)}ms`);
@@ -360478,7 +360738,7 @@ var init_zipper_yaJVJ4z9_es = __esm(() => {
360478
360738
 
360479
360739
  // ../../packages/superdoc/dist/super-editor.es.js
360480
360740
  var init_super_editor_es = __esm(() => {
360481
- init_src_CF4og_LY_es();
360741
+ init_src_B1aSE_tB_es();
360482
360742
  init_SuperConverter_B9mZiCO9_es();
360483
360743
  init_jszip_C49i9kUs_es();
360484
360744
  init_xml_js_CqGKpaft_es();