@superdoc-dev/cli 0.5.0-next.25 → 0.5.0-next.27

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 +1064 -822
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -63346,7 +63346,7 @@ var init_remark_gfm_z_sDF4ss_es = __esm(() => {
63346
63346
  emptyOptions2 = {};
63347
63347
  });
63348
63348
 
63349
- // ../../packages/superdoc/dist/chunks/SuperConverter-CYbYOJeZ.es.js
63349
+ // ../../packages/superdoc/dist/chunks/SuperConverter-B9oNf3OB.es.js
63350
63350
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
63351
63351
  const fieldValue = extension$1.config[field];
63352
63352
  if (typeof fieldValue === "function")
@@ -90407,6 +90407,26 @@ function importEndnoteData({ docx, editor, converter, nodeListHandler, numbering
90407
90407
  numbering
90408
90408
  });
90409
90409
  }
90410
+ function extractMathText(node3) {
90411
+ if (!node3)
90412
+ return "";
90413
+ if (node3.type === "text" && typeof node3.text === "string")
90414
+ return node3.text;
90415
+ if (node3.name === "m:t" && Array.isArray(node3.elements))
90416
+ return node3.elements.map((child) => extractMathText(child)).join("");
90417
+ if (Array.isArray(node3.elements))
90418
+ return node3.elements.map((child) => extractMathText(child)).join("");
90419
+ return "";
90420
+ }
90421
+ function extractJustification(oMathParaNode) {
90422
+ const paraPr = (oMathParaNode.elements || []).find((el) => el.name === "m:oMathParaPr");
90423
+ if (!paraPr || !Array.isArray(paraPr.elements))
90424
+ return "centerGroup";
90425
+ const jc = paraPr.elements.find((el) => el.name === "m:jc");
90426
+ if (!jc || !jc.attributes)
90427
+ return "centerGroup";
90428
+ return jc.attributes["m:val"] || "center";
90429
+ }
90410
90430
  function toIdentityValue(value) {
90411
90431
  if (typeof value === "string" && value.length > 0)
90412
90432
  return value;
@@ -92051,6 +92071,8 @@ function exportSchemaToJson(params3) {
92051
92071
  tableOfContents: translator$22,
92052
92072
  index: translator$23,
92053
92073
  indexEntry: translator$24,
92074
+ mathBlock: translatePassthroughNode,
92075
+ mathInline: translatePassthroughNode,
92054
92076
  passthroughBlock: translatePassthroughNode,
92055
92077
  passthroughInline: translatePassthroughNode
92056
92078
  }[type];
@@ -112784,7 +112806,51 @@ var isRegExp = (value) => {
112784
112806
  nodes: [translator$3.encode(params3)],
112785
112807
  consumed: 1
112786
112808
  };
112787
- }, tabNodeEntityHandler, footnoteReferenceHandlerEntity, tableNodeHandlerEntity, tableOfContentsHandlerEntity, indexHandlerEntity, indexEntryHandlerEntity, bibliographyHandlerEntity, commentRangeStartHandlerEntity, commentRangeEndHandlerEntity, permStartHandlerEntity, permEndHandlerEntity, PARAGRAPH_IDENTITY_ATTRS, TABLE_IDENTITY_ATTRS, DEFAULT_BLOCK_IDENTITY_ATTRS, SYNTHETIC_PARA_ID_TYPES, DOCX_ID_LENGTH = 8, MAX_DOCX_ID = 4294967295, BLOCK_IDENTITY_ATTRS, WORD_2012_NAMESPACE = "http://schemas.microsoft.com/office/word/2012/wordml", deepClone2 = (value) => JSON.parse(JSON.stringify(value)), getNumberingRoot = (numberingXml) => {
112809
+ }, tabNodeEntityHandler, footnoteReferenceHandlerEntity, tableNodeHandlerEntity, tableOfContentsHandlerEntity, indexHandlerEntity, indexEntryHandlerEntity, bibliographyHandlerEntity, commentRangeStartHandlerEntity, commentRangeEndHandlerEntity, permStartHandlerEntity, permEndHandlerEntity, handleMathPara = (params3) => {
112810
+ const { nodes } = params3;
112811
+ if (!nodes.length || nodes[0].name !== "m:oMathPara")
112812
+ return {
112813
+ nodes: [],
112814
+ consumed: 0
112815
+ };
112816
+ const xmlNode = nodes[0];
112817
+ return {
112818
+ nodes: [{
112819
+ type: "mathBlock",
112820
+ attrs: {
112821
+ originalXml: carbonCopy(xmlNode),
112822
+ textContent: extractMathText(xmlNode),
112823
+ justification: extractJustification(xmlNode)
112824
+ },
112825
+ marks: []
112826
+ }],
112827
+ consumed: 1
112828
+ };
112829
+ }, handleMathInline = (params3) => {
112830
+ const { nodes } = params3;
112831
+ if (!nodes.length || nodes[0].name !== "m:oMath")
112832
+ return {
112833
+ nodes: [],
112834
+ consumed: 0
112835
+ };
112836
+ const xmlNode = nodes[0];
112837
+ return {
112838
+ nodes: [{
112839
+ type: "mathInline",
112840
+ attrs: {
112841
+ originalXml: carbonCopy(xmlNode),
112842
+ textContent: extractMathText(xmlNode)
112843
+ },
112844
+ marks: []
112845
+ }],
112846
+ consumed: 1
112847
+ };
112848
+ }, handleMathNode = (params3) => {
112849
+ const result = handleMathPara(params3);
112850
+ if (result.consumed > 0)
112851
+ return result;
112852
+ return handleMathInline(params3);
112853
+ }, mathNodeHandlerEntity, PARAGRAPH_IDENTITY_ATTRS, TABLE_IDENTITY_ATTRS, DEFAULT_BLOCK_IDENTITY_ATTRS, SYNTHETIC_PARA_ID_TYPES, DOCX_ID_LENGTH = 8, MAX_DOCX_ID = 4294967295, BLOCK_IDENTITY_ATTRS, WORD_2012_NAMESPACE = "http://schemas.microsoft.com/office/word/2012/wordml", deepClone2 = (value) => JSON.parse(JSON.stringify(value)), getNumberingRoot = (numberingXml) => {
112788
112854
  if (!numberingXml?.elements?.length)
112789
112855
  return null;
112790
112856
  return numberingXml.elements.find((el) => el?.name === "w:numbering") || numberingXml.elements[0] || null;
@@ -112944,6 +113010,7 @@ var isRegExp = (value) => {
112944
113010
  pageReferenceEntity,
112945
113011
  permStartHandlerEntity,
112946
113012
  permEndHandlerEntity,
113013
+ mathNodeHandlerEntity,
112947
113014
  passthroughNodeHandlerEntity
112948
113015
  ];
112949
113016
  return {
@@ -113995,7 +114062,7 @@ var isRegExp = (value) => {
113995
114062
  state.kern = kernNode.attributes["w:val"];
113996
114063
  }
113997
114064
  }, SuperConverter;
113998
- var init_SuperConverter_CYbYOJeZ_es = __esm(() => {
114065
+ var init_SuperConverter_B9oNf3OB_es = __esm(() => {
113999
114066
  init_rolldown_runtime_B2q5OVn9_es();
114000
114067
  init_jszip_ChlR43oI_es();
114001
114068
  init_xml_js_40FWvL78_es();
@@ -129289,6 +129356,7 @@ var init_SuperConverter_CYbYOJeZ_es = __esm(() => {
129289
129356
  "endnoteReference",
129290
129357
  "fieldAnnotation",
129291
129358
  "structuredContent",
129359
+ "mathInline",
129292
129360
  "passthroughInline",
129293
129361
  "page-number",
129294
129362
  "total-page-number",
@@ -149643,6 +149711,10 @@ var init_SuperConverter_CYbYOJeZ_es = __esm(() => {
149643
149711
  commentRangeEndHandlerEntity = generateV2HandlerEntity("commentRangeEndHandler", commentRangeEndTranslator);
149644
149712
  permStartHandlerEntity = generateV2HandlerEntity("permStartHandler", translator$13);
149645
149713
  permEndHandlerEntity = generateV2HandlerEntity("permEndHandler", translator$14);
149714
+ mathNodeHandlerEntity = {
149715
+ handlerName: "mathNodeHandler",
149716
+ handler: handleMathNode
149717
+ };
149646
149718
  PARAGRAPH_IDENTITY_ATTRS = ["sdBlockId", "paraId"];
149647
149719
  TABLE_IDENTITY_ATTRS = [
149648
149720
  "sdBlockId",
@@ -172511,7 +172583,7 @@ var init_remark_gfm_CjV8kaUy_es = __esm(() => {
172511
172583
  init_remark_gfm_z_sDF4ss_es();
172512
172584
  });
172513
172585
 
172514
- // ../../packages/superdoc/dist/chunks/src-BOboPGqd.es.js
172586
+ // ../../packages/superdoc/dist/chunks/src-9QyvRUxO.es.js
172515
172587
  function deleteProps(obj, propOrProps) {
172516
172588
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
172517
172589
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -182802,6 +182874,15 @@ function measureTabAlignmentGroup(startRunIndex, runs2, ctx$1, decimalSeparator
182802
182874
  result.totalWidth += imageWidth;
182803
182875
  continue;
182804
182876
  }
182877
+ if (run2.kind === "math") {
182878
+ const mathWidth = run2.width ?? 20;
182879
+ result.runs.push({
182880
+ runIndex: i4,
182881
+ width: mathWidth
182882
+ });
182883
+ result.totalWidth += mathWidth;
182884
+ continue;
182885
+ }
182805
182886
  if (isFieldAnnotationRun(run2)) {
182806
182887
  const fontSize = run2.fontSize ?? DEFAULT_FIELD_ANNOTATION_FONT_SIZE;
182807
182888
  const { font } = buildFontString({
@@ -183335,6 +183416,27 @@ async function measureParagraphBlock(block, maxWidth) {
183335
183416
  pendingRunSpacing = 0;
183336
183417
  continue;
183337
183418
  }
183419
+ if (run2.kind === "math") {
183420
+ const mathRun = run2;
183421
+ const mathWidth = mathRun.width ?? 20;
183422
+ const mathHeight = mathRun.height ?? 24;
183423
+ if (currentLine) {
183424
+ currentLine.toRun = runIndex;
183425
+ currentLine.toChar = 1;
183426
+ currentLine.width = roundValue(currentLine.width + mathWidth);
183427
+ currentLine.maxImageHeight = Math.max(currentLine.maxImageHeight ?? 0, mathHeight);
183428
+ if (!currentLine.segments)
183429
+ currentLine.segments = [];
183430
+ currentLine.segments.push({
183431
+ runIndex,
183432
+ fromChar: 0,
183433
+ toChar: 1,
183434
+ width: mathWidth
183435
+ });
183436
+ }
183437
+ pendingRunSpacing = 0;
183438
+ continue;
183439
+ }
183338
183440
  if (isFieldAnnotationRun(run2)) {
183339
183441
  const displayText = applyTextTransform$2(run2.displayLabel || "", run2);
183340
183442
  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;
@@ -189221,6 +189323,86 @@ function applyParagraphBordersAndShading(paraWrapper, block) {
189221
189323
  function sdtElementsById(root3, sdtId) {
189222
189324
  return root3.querySelectorAll(`.${DOM_CLASS_NAMES.BLOCK_SDT}[data-sdt-id="${sdtId}"]`);
189223
189325
  }
189326
+ function classifyMathText(text5) {
189327
+ if (/^\d*\.?\d+$/.test(text5))
189328
+ return "mn";
189329
+ if (text5.length === 1 && OPERATOR_CHARS.has(text5))
189330
+ return "mo";
189331
+ return "mi";
189332
+ }
189333
+ function convertChildNodes(children, doc$12) {
189334
+ const fragment2 = doc$12.createDocumentFragment();
189335
+ for (const child of children) {
189336
+ const result = convertNode(child, doc$12);
189337
+ if (result)
189338
+ fragment2.appendChild(result);
189339
+ }
189340
+ return fragment2;
189341
+ }
189342
+ function convertNode(node3, doc$12) {
189343
+ if (!node3)
189344
+ return null;
189345
+ if (node3.type === "text" && typeof node3.text === "string")
189346
+ return doc$12.createTextNode(node3.text);
189347
+ const name = node3.name;
189348
+ if (!name)
189349
+ return null;
189350
+ if (name.endsWith("Pr"))
189351
+ return null;
189352
+ const converter = MATH_OBJECT_REGISTRY[name];
189353
+ if (converter)
189354
+ return converter(node3, doc$12, (children) => convertChildNodes(children, doc$12));
189355
+ if (ARGUMENT_ELEMENTS.has(name)) {
189356
+ const children = node3.elements ?? [];
189357
+ if (children.length === 1)
189358
+ return convertNode(children[0], doc$12);
189359
+ const mrow = doc$12.createElementNS(MATHML_NS, "mrow");
189360
+ for (const child of children) {
189361
+ const result = convertNode(child, doc$12);
189362
+ if (result)
189363
+ mrow.appendChild(result);
189364
+ }
189365
+ return mrow.childNodes.length > 0 ? mrow : null;
189366
+ }
189367
+ if (name === "m:mr") {
189368
+ const fragment$1 = doc$12.createDocumentFragment();
189369
+ for (const child of node3.elements ?? []) {
189370
+ const result = convertNode(child, doc$12);
189371
+ if (result)
189372
+ fragment$1.appendChild(result);
189373
+ }
189374
+ return fragment$1.childNodes.length > 0 ? fragment$1 : null;
189375
+ }
189376
+ if (name in MATH_OBJECT_REGISTRY && MATH_OBJECT_REGISTRY[name] === null) {
189377
+ const mrow = doc$12.createElementNS(MATHML_NS, "mrow");
189378
+ for (const child of node3.elements ?? []) {
189379
+ const result = convertNode(child, doc$12);
189380
+ if (result)
189381
+ mrow.appendChild(result);
189382
+ }
189383
+ return mrow.childNodes.length > 0 ? mrow : null;
189384
+ }
189385
+ const fragment2 = doc$12.createDocumentFragment();
189386
+ for (const child of node3.elements ?? []) {
189387
+ const result = convertNode(child, doc$12);
189388
+ if (result)
189389
+ fragment2.appendChild(result);
189390
+ }
189391
+ return fragment2.childNodes.length > 0 ? fragment2 : null;
189392
+ }
189393
+ function convertOmmlToMathml(ommlJson, doc$12) {
189394
+ if (!ommlJson || typeof ommlJson !== "object")
189395
+ return null;
189396
+ const root3 = ommlJson;
189397
+ const mathEl = doc$12.createElementNS(MATHML_NS, "math");
189398
+ const children = root3.elements ?? [];
189399
+ for (const child of children) {
189400
+ const result = convertNode(child, doc$12);
189401
+ if (result)
189402
+ mathEl.appendChild(result);
189403
+ }
189404
+ return mathEl.childNodes.length > 0 ? mathEl : null;
189405
+ }
189224
189406
  function isMinimalWordLayout(value) {
189225
189407
  if (typeof value !== "object" || value === null)
189226
189408
  return false;
@@ -219432,6 +219614,23 @@ function findSliceAtPosition(slices, pmPos) {
219432
219614
  }
219433
219615
  return null;
219434
219616
  }
219617
+ function resolveLayout(input2) {
219618
+ const { layout, flowMode } = input2;
219619
+ const pages = layout.pages.map((page, index2) => ({
219620
+ id: `page-${index2}`,
219621
+ index: index2,
219622
+ number: page.number,
219623
+ width: page.size?.w ?? layout.pageSize.w,
219624
+ height: page.size?.h ?? layout.pageSize.h,
219625
+ items: []
219626
+ }));
219627
+ return {
219628
+ version: 1,
219629
+ flowMode,
219630
+ pageGap: layout.pageGap ?? 0,
219631
+ pages
219632
+ };
219633
+ }
219435
219634
  function getMeasurementContext() {
219436
219635
  if (measurementCtx)
219437
219636
  return measurementCtx;
@@ -219451,7 +219650,7 @@ function getMeasurementContext() {
219451
219650
  return measurementCtx;
219452
219651
  }
219453
219652
  function getRunFontString(run2) {
219454
- if (run2.kind === "tab" || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || "src" in run2)
219653
+ if (run2.kind === "tab" || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" || "src" in run2)
219455
219654
  return "normal normal 16px Arial";
219456
219655
  return `${run2.italic ? "italic" : "normal"} ${run2.bold ? "bold" : "normal"} ${run2.fontSize ?? 16}px ${run2.fontFamily ?? "Arial"}`;
219457
219656
  }
@@ -219483,6 +219682,10 @@ function sliceRunsForLine(block, line) {
219483
219682
  result.push(run2);
219484
219683
  continue;
219485
219684
  }
219685
+ if (run2.kind === "math") {
219686
+ result.push(run2);
219687
+ continue;
219688
+ }
219486
219689
  const text5 = run2.text ?? "";
219487
219690
  const isFirstRun = runIndex === line.fromRun;
219488
219691
  const isLastRun = runIndex === line.toRun;
@@ -219518,7 +219721,7 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
219518
219721
  return charOffset / Math.max(1, runs$1.reduce((sum, run2) => {
219519
219722
  if (isTabRun(run2))
219520
219723
  return sum + TAB_CHAR_LENGTH;
219521
- if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation")
219724
+ if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
219522
219725
  return sum;
219523
219726
  return sum + (run2.text ?? "").length;
219524
219727
  }, 0)) * renderedLineWidth;
@@ -219539,9 +219742,9 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
219539
219742
  currentCharOffset += runLength$1;
219540
219743
  continue;
219541
219744
  }
219542
- const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
219745
+ const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
219543
219746
  const runLength = text5.length;
219544
- const displayText = applyTextTransform$1(text5, isTabRun(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? undefined : run2.textTransform);
219747
+ const displayText = applyTextTransform$1(text5, isTabRun(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? undefined : run2.textTransform);
219545
219748
  if (currentCharOffset + runLength >= charOffset) {
219546
219749
  const offsetInRun = charOffset - currentCharOffset;
219547
219750
  ctx$1.font = getRunFontString(run2);
@@ -219588,7 +219791,7 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx$1) {
219588
219791
  }
219589
219792
  if (isTabRun(run2))
219590
219793
  return segmentBaseX + (offsetInSegment > 0 ? segment.width ?? 0 : 0);
219591
- if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation")
219794
+ if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
219592
219795
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
219593
219796
  const textUpToTarget = applyTextTransform$1(run2.text ?? "", "textTransform" in run2 ? run2.textTransform : undefined).slice(segment.fromChar, segment.toChar).slice(0, offsetInSegment);
219594
219797
  ctx$1.font = getRunFontString(run2);
@@ -219616,7 +219819,7 @@ function charOffsetToPm(block, line, charOffset, fallbackPmStart) {
219616
219819
  let lastPm = fallbackPmStart;
219617
219820
  for (const run2 of runs2) {
219618
219821
  const isTab = isTabRun(run2);
219619
- const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
219822
+ const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
219620
219823
  const runLength = isTab ? TAB_CHAR_LENGTH : text5.length;
219621
219824
  const runPmStart = typeof run2.pmStart === "number" ? run2.pmStart : null;
219622
219825
  const runPmEnd = typeof run2.pmEnd === "number" ? run2.pmEnd : runPmStart != null ? runPmStart + runLength : null;
@@ -219645,7 +219848,7 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
219645
219848
  const charsInLine = Math.max(1, runs$1.reduce((sum, run2) => {
219646
219849
  if (isTabRun(run2))
219647
219850
  return sum + TAB_CHAR_LENGTH;
219648
- if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation")
219851
+ if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
219649
219852
  return sum;
219650
219853
  return sum + (run2.text ?? "").length;
219651
219854
  }, 0));
@@ -219678,9 +219881,9 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
219678
219881
  currentCharOffset += TAB_CHAR_LENGTH;
219679
219882
  continue;
219680
219883
  }
219681
- const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
219884
+ const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
219682
219885
  const runLength = text5.length;
219683
- const displayText = applyTextTransform$1(text5, isTabRun(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? undefined : run2.textTransform);
219886
+ const displayText = applyTextTransform$1(text5, isTabRun(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? undefined : run2.textTransform);
219684
219887
  if (runLength === 0)
219685
219888
  continue;
219686
219889
  ctx$1.font = getRunFontString(run2);
@@ -219720,457 +219923,6 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
219720
219923
  pmPosition
219721
219924
  };
219722
219925
  }
219723
- function isRtlLine(lineEl) {
219724
- return getComputedStyle(lineEl).direction === "rtl";
219725
- }
219726
- function isVisibleRect(rect) {
219727
- return rect.width > 0 && rect.height > 0;
219728
- }
219729
- function clickToPositionDom(domContainer, clientX, clientY) {
219730
- log2("=== clickToPositionDom START ===");
219731
- log2("Input coords:", {
219732
- clientX,
219733
- clientY
219734
- });
219735
- const pageEl = findPageElement(domContainer, clientX, clientY);
219736
- if (!pageEl) {
219737
- log2("No page element found");
219738
- return null;
219739
- }
219740
- const pageRect = pageEl.getBoundingClientRect();
219741
- const pageLocalX = clientX - pageRect.left;
219742
- const pageLocalY = clientY - pageRect.top;
219743
- const viewX = pageRect.left + pageLocalX;
219744
- const viewY = pageRect.top + pageLocalY;
219745
- log2("Page found:", {
219746
- pageIndex: pageEl.dataset.pageIndex,
219747
- pageRect: {
219748
- left: pageRect.left,
219749
- top: pageRect.top,
219750
- width: pageRect.width,
219751
- height: pageRect.height
219752
- },
219753
- viewCoords: {
219754
- viewX,
219755
- viewY
219756
- }
219757
- });
219758
- let hitChain = [];
219759
- const doc$12 = document;
219760
- const hasElementsFromPoint = typeof doc$12.elementsFromPoint === "function";
219761
- if (hasElementsFromPoint)
219762
- try {
219763
- hitChain = doc$12.elementsFromPoint(viewX, viewY) ?? [];
219764
- } catch {}
219765
- if (!Array.isArray(hitChain)) {
219766
- log2("elementsFromPoint returned non-array");
219767
- return null;
219768
- }
219769
- const hitChainData = hitChain.map((el) => {
219770
- const rect = el.getBoundingClientRect();
219771
- return {
219772
- tag: el.tagName,
219773
- classes: el.className,
219774
- blockId: el.dataset?.blockId,
219775
- pmStart: el.dataset?.pmStart,
219776
- pmEnd: el.dataset?.pmEnd,
219777
- rect: {
219778
- top: Math.round(rect.top),
219779
- bottom: Math.round(rect.bottom),
219780
- left: Math.round(rect.left),
219781
- right: Math.round(rect.right),
219782
- height: Math.round(rect.height)
219783
- }
219784
- };
219785
- });
219786
- log2("Hit chain elements:", JSON.stringify(hitChainData, null, 2));
219787
- const fragmentData = Array.from(pageEl.querySelectorAll(`.${CLASS_NAMES.fragment}`)).map((el) => {
219788
- const rect = el.getBoundingClientRect();
219789
- return {
219790
- blockId: el.dataset.blockId,
219791
- pmStart: el.dataset.pmStart,
219792
- pmEnd: el.dataset.pmEnd,
219793
- rect: {
219794
- top: Math.round(rect.top),
219795
- bottom: Math.round(rect.bottom),
219796
- left: Math.round(rect.left),
219797
- right: Math.round(rect.right),
219798
- height: Math.round(rect.height)
219799
- }
219800
- };
219801
- });
219802
- log2("All fragments on page:", JSON.stringify(fragmentData, null, 2));
219803
- const fragmentEl = hitChain.find((el) => el.classList?.contains?.(CLASS_NAMES.fragment));
219804
- if (!fragmentEl) {
219805
- if (hasElementsFromPoint) {
219806
- log2("No fragment found in hit chain; returning null to allow geometry mapping");
219807
- return null;
219808
- }
219809
- const fallbackFragment = pageEl.querySelector(`.${CLASS_NAMES.fragment}`);
219810
- if (!fallbackFragment) {
219811
- log2("No fragment found in hit chain or fallback");
219812
- return null;
219813
- }
219814
- log2("Using fallback fragment (no elementsFromPoint):", {
219815
- blockId: fallbackFragment.dataset.blockId,
219816
- pmStart: fallbackFragment.dataset.pmStart,
219817
- pmEnd: fallbackFragment.dataset.pmEnd
219818
- });
219819
- const result$1 = processFragment(fallbackFragment, viewX, viewY);
219820
- log2("=== clickToPositionDom END (fallback) ===", { result: result$1 });
219821
- return result$1;
219822
- }
219823
- log2("Fragment found:", {
219824
- blockId: fragmentEl.dataset.blockId,
219825
- pmStart: fragmentEl.dataset.pmStart,
219826
- pmEnd: fragmentEl.dataset.pmEnd
219827
- });
219828
- const hitChainLine = hitChain.find((el) => el.classList?.contains?.(CLASS_NAMES.line) && el.dataset?.pmStart !== undefined && el.dataset?.pmEnd !== undefined);
219829
- if (hitChainLine) {
219830
- log2("Using hit chain line directly:", {
219831
- pmStart: hitChainLine.dataset.pmStart,
219832
- pmEnd: hitChainLine.dataset.pmEnd
219833
- });
219834
- const result$1 = processLineElement(hitChainLine, viewX);
219835
- log2("=== clickToPositionDom END (hitChainLine) ===", { result: result$1 });
219836
- return result$1;
219837
- }
219838
- if (fragmentEl.classList.contains(CLASS_NAMES.tableFragment)) {
219839
- log2("Table fragment without line in hit chain, deferring to geometry fallback");
219840
- return null;
219841
- }
219842
- const result = processFragment(fragmentEl, viewX, viewY);
219843
- log2("=== clickToPositionDom END ===", { result });
219844
- return result;
219845
- }
219846
- function findPageElement(domContainer, clientX, clientY) {
219847
- if (domContainer.classList?.contains?.(CLASS_NAMES.page))
219848
- return domContainer;
219849
- const doc$12 = document;
219850
- if (typeof doc$12.elementsFromPoint === "function")
219851
- try {
219852
- const hitChain = doc$12.elementsFromPoint(clientX, clientY);
219853
- if (Array.isArray(hitChain)) {
219854
- const pageEl = hitChain.find((el) => el.classList?.contains?.(CLASS_NAMES.page));
219855
- if (pageEl)
219856
- return pageEl;
219857
- }
219858
- } catch {}
219859
- const pages = Array.from(domContainer.querySelectorAll(`.${CLASS_NAMES.page}`));
219860
- for (const page of pages) {
219861
- const rect = page.getBoundingClientRect();
219862
- if (clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom)
219863
- return page;
219864
- }
219865
- if (pages.length > 0)
219866
- return pages[0];
219867
- return null;
219868
- }
219869
- function processFragment(fragmentEl, viewX, viewY) {
219870
- log2("processFragment:", {
219871
- viewX,
219872
- viewY,
219873
- blockId: fragmentEl.dataset.blockId
219874
- });
219875
- const lineEls = Array.from(fragmentEl.querySelectorAll(`.${CLASS_NAMES.line}`));
219876
- log2("Lines in fragment:", lineEls.map((el, i4) => {
219877
- const rect = el.getBoundingClientRect();
219878
- return {
219879
- index: i4,
219880
- pmStart: el.dataset.pmStart,
219881
- pmEnd: el.dataset.pmEnd,
219882
- rect: {
219883
- top: rect.top,
219884
- bottom: rect.bottom,
219885
- left: rect.left,
219886
- right: rect.right
219887
- }
219888
- };
219889
- }));
219890
- if (lineEls.length === 0) {
219891
- log2("No lines in fragment");
219892
- return null;
219893
- }
219894
- const lineEl = findLineAtY(lineEls, viewY);
219895
- if (!lineEl) {
219896
- log2("No line found at Y:", viewY);
219897
- return null;
219898
- }
219899
- const lineStart = Number(lineEl.dataset.pmStart ?? "NaN");
219900
- const lineEnd = Number(lineEl.dataset.pmEnd ?? "NaN");
219901
- const lineRect = lineEl.getBoundingClientRect();
219902
- log2("Selected line:", {
219903
- pmStart: lineStart,
219904
- pmEnd: lineEnd,
219905
- rect: {
219906
- top: lineRect.top,
219907
- bottom: lineRect.bottom,
219908
- left: lineRect.left,
219909
- right: lineRect.right
219910
- }
219911
- });
219912
- if (!Number.isFinite(lineStart) || !Number.isFinite(lineEnd)) {
219913
- log2("Line has invalid PM positions");
219914
- return null;
219915
- }
219916
- const spanEls = Array.from(lineEl.querySelectorAll("span, a")).filter((el) => el.dataset.pmStart !== undefined && el.dataset.pmEnd !== undefined && !el.classList.contains(DOM_CLASS_NAMES.INLINE_SDT_WRAPPER));
219917
- log2("Spans/anchors in line:", spanEls.map((el, i4) => {
219918
- const rect = el.getBoundingClientRect();
219919
- return {
219920
- index: i4,
219921
- tag: el.tagName,
219922
- pmStart: el.dataset.pmStart,
219923
- pmEnd: el.dataset.pmEnd,
219924
- text: el.textContent?.substring(0, 20) + (el.textContent && el.textContent.length > 20 ? "..." : ""),
219925
- visibility: el.style.visibility,
219926
- rect: {
219927
- left: rect.left,
219928
- right: rect.right,
219929
- width: rect.width
219930
- }
219931
- };
219932
- }));
219933
- return resolveLinePosition(lineEl, lineStart, lineEnd, spanEls, viewX);
219934
- }
219935
- function mapCharIndexToPm(spanStart, spanEnd, textLength, charIndex) {
219936
- if (!Number.isFinite(spanStart) || !Number.isFinite(spanEnd))
219937
- return spanStart;
219938
- if (textLength <= 0)
219939
- return spanStart;
219940
- const pmRange = spanEnd - spanStart;
219941
- if (!Number.isFinite(pmRange) || pmRange <= 0)
219942
- return spanStart;
219943
- if (pmRange === textLength) {
219944
- const mapped = spanStart + charIndex;
219945
- return Math.min(spanEnd, Math.max(spanStart, mapped));
219946
- }
219947
- return charIndex / textLength <= 0.5 ? spanStart : spanEnd;
219948
- }
219949
- function processLineElement(lineEl, viewX) {
219950
- const lineStart = Number(lineEl.dataset.pmStart ?? "NaN");
219951
- const lineEnd = Number(lineEl.dataset.pmEnd ?? "NaN");
219952
- const lineRect = lineEl.getBoundingClientRect();
219953
- log2("processLineElement:", {
219954
- pmStart: lineStart,
219955
- pmEnd: lineEnd,
219956
- rect: {
219957
- top: lineRect.top,
219958
- bottom: lineRect.bottom,
219959
- left: lineRect.left,
219960
- right: lineRect.right
219961
- }
219962
- });
219963
- if (!Number.isFinite(lineStart) || !Number.isFinite(lineEnd)) {
219964
- log2("Line has invalid PM positions");
219965
- return null;
219966
- }
219967
- const spanEls = Array.from(lineEl.querySelectorAll("span, a")).filter((el) => el.dataset.pmStart !== undefined && el.dataset.pmEnd !== undefined && !el.classList.contains(DOM_CLASS_NAMES.INLINE_SDT_WRAPPER));
219968
- log2("Spans/anchors in line:", spanEls.map((el, i4) => {
219969
- const rect = el.getBoundingClientRect();
219970
- return {
219971
- index: i4,
219972
- tag: el.tagName,
219973
- pmStart: el.dataset.pmStart,
219974
- pmEnd: el.dataset.pmEnd,
219975
- text: el.textContent?.substring(0, 20) + (el.textContent && el.textContent.length > 20 ? "..." : ""),
219976
- visibility: el.style.visibility,
219977
- rect: {
219978
- left: rect.left,
219979
- right: rect.right,
219980
- width: rect.width
219981
- }
219982
- };
219983
- }));
219984
- return resolveLinePosition(lineEl, lineStart, lineEnd, spanEls, viewX);
219985
- }
219986
- function resolveLinePosition(lineEl, lineStart, lineEnd, spanEls, viewX) {
219987
- if (spanEls.length === 0) {
219988
- log2("No spans in line, returning lineStart:", lineStart);
219989
- return lineStart;
219990
- }
219991
- const rtl = isRtlLine(lineEl);
219992
- const allRects = spanEls.map((el) => el.getBoundingClientRect());
219993
- const visibleRects = allRects.filter(isVisibleRect);
219994
- const boundsRects = visibleRects.length > 0 ? visibleRects : allRects;
219995
- const visualLeft = Math.min(...boundsRects.map((r$1) => r$1.left));
219996
- const visualRight = Math.max(...boundsRects.map((r$1) => r$1.right));
219997
- if (viewX <= visualLeft) {
219998
- const pos$1 = rtl ? lineEnd : lineStart;
219999
- log2("Click to visual left of all spans, returning:", pos$1);
220000
- return pos$1;
220001
- }
220002
- if (viewX >= visualRight) {
220003
- const pos$1 = rtl ? lineStart : lineEnd;
220004
- log2("Click to visual right of all spans, returning:", pos$1);
220005
- return pos$1;
220006
- }
220007
- const targetEl = findSpanAtX(spanEls, viewX);
220008
- if (!targetEl) {
220009
- log2("No target element found, returning lineStart:", lineStart);
220010
- return lineStart;
220011
- }
220012
- const spanStart = Number(targetEl.dataset.pmStart ?? "NaN");
220013
- const spanEnd = Number(targetEl.dataset.pmEnd ?? "NaN");
220014
- const targetRect = targetEl.getBoundingClientRect();
220015
- log2("Target element:", {
220016
- tag: targetEl.tagName,
220017
- pmStart: spanStart,
220018
- pmEnd: spanEnd,
220019
- text: targetEl.textContent?.substring(0, 30),
220020
- visibility: targetEl.style.visibility,
220021
- rect: {
220022
- left: targetRect.left,
220023
- right: targetRect.right,
220024
- width: targetRect.width
220025
- }
220026
- });
220027
- if (!Number.isFinite(spanStart) || !Number.isFinite(spanEnd)) {
220028
- log2("Element has invalid PM positions");
220029
- return null;
220030
- }
220031
- const firstChild = targetEl.firstChild;
220032
- if (!firstChild || firstChild.nodeType !== Node.TEXT_NODE || !firstChild.textContent) {
220033
- const closerToLeft = Math.abs(viewX - targetRect.left) <= Math.abs(viewX - targetRect.right);
220034
- const snapPos = rtl ? closerToLeft ? spanEnd : spanStart : closerToLeft ? spanStart : spanEnd;
220035
- log2("Empty/non-text element, snapping to:", {
220036
- closerToLeft,
220037
- rtl,
220038
- snapPos
220039
- });
220040
- return snapPos;
220041
- }
220042
- const textNode = firstChild;
220043
- const charIndex = findCharIndexAtX(textNode, viewX, rtl);
220044
- const pos = mapCharIndexToPm(spanStart, spanEnd, textNode.length, charIndex);
220045
- log2("Character position:", {
220046
- charIndex,
220047
- spanStart,
220048
- rtl,
220049
- finalPos: pos
220050
- });
220051
- return pos;
220052
- }
220053
- function findLineAtY(lineEls, viewY) {
220054
- if (lineEls.length === 0)
220055
- return null;
220056
- for (let i4 = 0;i4 < lineEls.length; i4++) {
220057
- const lineEl = lineEls[i4];
220058
- const rect = lineEl.getBoundingClientRect();
220059
- if (viewY >= rect.top && viewY <= rect.bottom) {
220060
- log2("findLineAtY: Found line at index", i4, {
220061
- pmStart: lineEl.dataset.pmStart,
220062
- pmEnd: lineEl.dataset.pmEnd,
220063
- rect: {
220064
- top: rect.top,
220065
- bottom: rect.bottom
220066
- },
220067
- viewY
220068
- });
220069
- return lineEl;
220070
- }
220071
- }
220072
- const lastLine = lineEls[lineEls.length - 1];
220073
- log2("findLineAtY: Y beyond all lines, using last line:", {
220074
- pmStart: lastLine.dataset.pmStart,
220075
- pmEnd: lastLine.dataset.pmEnd,
220076
- viewY
220077
- });
220078
- return lastLine;
220079
- }
220080
- function findSpanAtX(spanEls, viewX) {
220081
- if (spanEls.length === 0)
220082
- return null;
220083
- let targetSpan = spanEls[0];
220084
- let minDist = Infinity;
220085
- for (let i4 = 0;i4 < spanEls.length; i4++) {
220086
- const span = spanEls[i4];
220087
- const rect = span.getBoundingClientRect();
220088
- if (!isVisibleRect(rect))
220089
- continue;
220090
- if (viewX >= rect.left && viewX <= rect.right) {
220091
- log2("findSpanAtX: Found containing element at index", i4, {
220092
- tag: span.tagName,
220093
- pmStart: span.dataset.pmStart,
220094
- pmEnd: span.dataset.pmEnd,
220095
- rect: {
220096
- left: rect.left,
220097
- right: rect.right
220098
- },
220099
- viewX
220100
- });
220101
- return span;
220102
- }
220103
- const dist = Math.min(Math.abs(viewX - rect.left), Math.abs(viewX - rect.right));
220104
- if (dist < minDist) {
220105
- minDist = dist;
220106
- targetSpan = span;
220107
- }
220108
- }
220109
- log2("findSpanAtX: No containing element, using nearest:", {
220110
- tag: targetSpan.tagName,
220111
- pmStart: targetSpan.dataset.pmStart,
220112
- pmEnd: targetSpan.dataset.pmEnd,
220113
- viewX
220114
- });
220115
- return targetSpan;
220116
- }
220117
- function findCharIndexAtX(textNode, targetX, rtl) {
220118
- const text5 = textNode.textContent ?? "";
220119
- if (text5.length === 0)
220120
- return 0;
220121
- const container = textNode.parentElement;
220122
- if (!container)
220123
- return 0;
220124
- const containerRect = container.getBoundingClientRect();
220125
- const caretIndex = caretOffsetFromPoint(targetX, containerRect.top + containerRect.height / 2, textNode);
220126
- if (caretIndex != null) {
220127
- log2("findCharIndexAtX: caret API returned", caretIndex);
220128
- return caretIndex;
220129
- }
220130
- log2("findCharIndexAtX: falling back to range binary search, rtl =", rtl);
220131
- const range = document.createRange();
220132
- const measureX = (i4) => {
220133
- if (i4 <= 0)
220134
- return rtl ? containerRect.right : containerRect.left;
220135
- range.setStart(textNode, 0);
220136
- range.setEnd(textNode, i4);
220137
- const r$1 = range.getBoundingClientRect();
220138
- return rtl ? r$1.left : r$1.right;
220139
- };
220140
- let lo = 0;
220141
- let hi = text5.length;
220142
- while (lo < hi) {
220143
- const mid = Math.floor((lo + hi) / 2);
220144
- const x = measureX(mid);
220145
- if (rtl ? x > targetX : x < targetX)
220146
- lo = mid + 1;
220147
- else
220148
- hi = mid;
220149
- }
220150
- const index2 = Math.max(0, Math.min(text5.length, lo));
220151
- const xAt = measureX(index2);
220152
- const distAt = Math.abs(xAt - targetX);
220153
- if (index2 > 0) {
220154
- const xPrev = measureX(index2 - 1);
220155
- if (Math.abs(xPrev - targetX) < distAt)
220156
- return index2 - 1;
220157
- }
220158
- return index2;
220159
- }
220160
- function caretOffsetFromPoint(x, y$1, expectedNode) {
220161
- const doc$12 = document;
220162
- if (typeof doc$12.caretPositionFromPoint === "function") {
220163
- const cp = doc$12.caretPositionFromPoint(x, y$1);
220164
- if (cp && cp.offsetNode === expectedNode)
220165
- return cp.offset;
220166
- }
220167
- if (typeof doc$12.caretRangeFromPoint === "function") {
220168
- const r$1 = doc$12.caretRangeFromPoint(x, y$1);
220169
- if (r$1 && r$1.startContainer === expectedNode)
220170
- return r$1.startOffset;
220171
- }
220172
- return null;
220173
- }
220174
219926
  function getWordLayoutConfig(block) {
220175
219927
  if (!block || block.kind !== "paragraph")
220176
219928
  return;
@@ -220531,7 +220283,7 @@ function extractBlockText(block) {
220531
220283
  let pmStart = Infinity;
220532
220284
  let pmEnd = 0;
220533
220285
  for (const run2 of block.runs) {
220534
- text5 += "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text;
220286
+ text5 += "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text;
220535
220287
  if (run2.pmStart !== undefined)
220536
220288
  pmStart = Math.min(pmStart, run2.pmStart);
220537
220289
  if (run2.pmEnd !== undefined)
@@ -220588,7 +220340,7 @@ function fontString(run2) {
220588
220340
  return `${textRun?.italic ? "italic " : ""}${textRun?.bold ? "bold " : ""}${size$1}px ${family}`.trim();
220589
220341
  }
220590
220342
  function runText(run2) {
220591
- return "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
220343
+ return "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
220592
220344
  }
220593
220345
  function measureRunSliceWidth(run2, fromChar, toChar) {
220594
220346
  const context = getCtx();
@@ -220862,7 +220614,9 @@ function computeHeaderFooterContentHash(blocks2) {
220862
220614
  parts.push(block.id);
220863
220615
  if (block.kind === "paragraph")
220864
220616
  for (const run2 of block.runs) {
220865
- if (!("src" in run2) && run2.kind !== "lineBreak" && run2.kind !== "break" && run2.kind !== "fieldAnnotation")
220617
+ if (run2.kind === "math")
220618
+ parts.push(`math:${run2.textContent}`);
220619
+ else if (!("src" in run2) && run2.kind !== "lineBreak" && run2.kind !== "break" && run2.kind !== "fieldAnnotation")
220866
220620
  parts.push(run2.text ?? "");
220867
220621
  if ("bold" in run2 && run2.bold)
220868
220622
  parts.push("b");
@@ -221974,6 +221728,36 @@ function snapToNearestFragment(pageHit, blocks2, measures, pageRelativePoint) {
221974
221728
  }
221975
221729
  return nearestHit;
221976
221730
  }
221731
+ function findBlockIndexByFragmentId(blocks2, fragmentBlockId, targetPmRange) {
221732
+ const index2 = blocks2.findIndex((block) => block.id === fragmentBlockId && block.kind !== "pageBreak" && block.kind !== "sectionBreak");
221733
+ if (index2 !== -1)
221734
+ return index2;
221735
+ const baseBlockId = fragmentBlockId.replace(/-\d+$/, "");
221736
+ if (baseBlockId === fragmentBlockId)
221737
+ return -1;
221738
+ const matchingIndices = [];
221739
+ blocks2.forEach((block, idx) => {
221740
+ if (block.id === baseBlockId && block.kind === "paragraph")
221741
+ matchingIndices.push(idx);
221742
+ });
221743
+ if (matchingIndices.length === 0)
221744
+ return -1;
221745
+ if (matchingIndices.length === 1)
221746
+ return matchingIndices[0];
221747
+ if (targetPmRange)
221748
+ for (const idx of matchingIndices) {
221749
+ const block = blocks2[idx];
221750
+ if (block.kind !== "paragraph")
221751
+ continue;
221752
+ if (block.runs.some((run2) => {
221753
+ if (run2.pmStart == null || run2.pmEnd == null)
221754
+ return false;
221755
+ return run2.pmEnd > targetPmRange.from && run2.pmStart < targetPmRange.to;
221756
+ }))
221757
+ return idx;
221758
+ }
221759
+ return matchingIndices[0];
221760
+ }
221977
221761
  function hitTestPage(layout, point5, geometryHelper) {
221978
221762
  if (geometryHelper) {
221979
221763
  const pageIndex = geometryHelper.getPageIndexAtY(point5.y);
@@ -222052,137 +221836,92 @@ function hitTestFragment(layout, pageHit, blocks2, measures, point5) {
222052
221836
  }
222053
221837
  return null;
222054
221838
  }
222055
- function clickToPosition(layout, blocks2, measures, containerPoint, domContainer, clientX, clientY, geometryHelper) {
222056
- const layoutEpoch = layout.layoutEpoch ?? 0;
222057
- logClickStage("log", "entry", {
222058
- point: containerPoint,
222059
- pages: layout.pages.length,
222060
- hasDomContainer: domContainer != null
222061
- });
222062
- if (domContainer != null && clientX != null && clientY != null) {
222063
- logClickStage("log", "dom-attempt", { trying: "DOM-based mapping" });
222064
- const domPos = clickToPositionDom(domContainer, clientX, clientY);
222065
- const domLayoutEpoch = readLayoutEpochFromDom(domContainer, clientX, clientY) ?? layoutEpoch;
222066
- if (domPos != null) {
222067
- logPositionDebug({
222068
- origin: "dom",
222069
- pos: domPos,
222070
- clientX,
222071
- clientY
222072
- });
222073
- let blockId = "";
222074
- let pageIndex = 0;
222075
- let column = 0;
222076
- let lineIndex = -1;
222077
- for (let pi = 0;pi < layout.pages.length; pi++) {
222078
- const page = layout.pages[pi];
222079
- for (const fragment2 of page.fragments)
222080
- if (fragment2.kind === "para" && fragment2.pmStart != null && fragment2.pmEnd != null) {
222081
- if (domPos >= fragment2.pmStart && domPos <= fragment2.pmEnd) {
222082
- blockId = fragment2.blockId;
222083
- pageIndex = pi;
222084
- column = determineColumn(layout, fragment2.x);
222085
- const blockIndex = findBlockIndexByFragmentId(blocks2, fragment2.blockId);
222086
- if (blockIndex !== -1) {
222087
- const measure = measures[blockIndex];
222088
- if (measure && measure.kind === "paragraph")
222089
- if (fragment2.lines && fragment2.lines.length > 0)
222090
- for (let localIndex = 0;localIndex < fragment2.lines.length; localIndex++) {
222091
- const line = fragment2.lines[localIndex];
222092
- if (!line)
222093
- continue;
222094
- const range = computeLinePmRange(blocks2[blockIndex], line);
222095
- if (range.pmStart != null && range.pmEnd != null) {
222096
- if (domPos >= range.pmStart && domPos <= range.pmEnd) {
222097
- lineIndex = fragment2.fromLine + localIndex;
222098
- break;
222099
- }
222100
- }
221839
+ function resolvePositionHitFromDomPosition(layout, blocks2, measures, domPos, layoutEpoch) {
221840
+ let blockId = "";
221841
+ let pageIndex = 0;
221842
+ let column = 0;
221843
+ let lineIndex = -1;
221844
+ for (let pi = 0;pi < layout.pages.length; pi++) {
221845
+ const page = layout.pages[pi];
221846
+ for (const fragment2 of page.fragments)
221847
+ if (fragment2.kind === "para" && fragment2.pmStart != null && fragment2.pmEnd != null) {
221848
+ if (domPos >= fragment2.pmStart && domPos <= fragment2.pmEnd) {
221849
+ blockId = fragment2.blockId;
221850
+ pageIndex = pi;
221851
+ column = determineColumn(layout, fragment2.x);
221852
+ const blockIndex = findBlockIndexByFragmentId(blocks2, fragment2.blockId);
221853
+ if (blockIndex !== -1) {
221854
+ const measure = measures[blockIndex];
221855
+ if (measure && measure.kind === "paragraph")
221856
+ if (fragment2.lines && fragment2.lines.length > 0)
221857
+ for (let localIndex = 0;localIndex < fragment2.lines.length; localIndex++) {
221858
+ const line = fragment2.lines[localIndex];
221859
+ if (!line)
221860
+ continue;
221861
+ const range = computeLinePmRange$1(blocks2[blockIndex], line);
221862
+ if (range.pmStart != null && range.pmEnd != null) {
221863
+ if (domPos >= range.pmStart && domPos <= range.pmEnd) {
221864
+ lineIndex = fragment2.fromLine + localIndex;
221865
+ break;
222101
221866
  }
222102
- else
222103
- for (let li2 = fragment2.fromLine;li2 < fragment2.toLine; li2++) {
222104
- const line = measure.lines[li2];
222105
- if (!line)
222106
- continue;
222107
- const range = computeLinePmRange(blocks2[blockIndex], line);
222108
- if (range.pmStart != null && range.pmEnd != null) {
222109
- if (domPos >= range.pmStart && domPos <= range.pmEnd) {
222110
- lineIndex = li2;
222111
- break;
222112
- }
222113
- }
221867
+ }
221868
+ }
221869
+ else
221870
+ for (let li2 = fragment2.fromLine;li2 < fragment2.toLine; li2++) {
221871
+ const line = measure.lines[li2];
221872
+ if (!line)
221873
+ continue;
221874
+ const range = computeLinePmRange$1(blocks2[blockIndex], line);
221875
+ if (range.pmStart != null && range.pmEnd != null) {
221876
+ if (domPos >= range.pmStart && domPos <= range.pmEnd) {
221877
+ lineIndex = li2;
221878
+ break;
222114
221879
  }
222115
- }
222116
- logClickStage("log", "success", {
222117
- blockId,
222118
- pos: domPos,
222119
- pageIndex,
222120
- column,
222121
- lineIndex,
222122
- usedMethod: "DOM"
222123
- });
222124
- return {
222125
- pos: domPos,
222126
- layoutEpoch: domLayoutEpoch,
222127
- blockId,
222128
- pageIndex,
222129
- column,
222130
- lineIndex
222131
- };
222132
- }
221880
+ }
221881
+ }
222133
221882
  }
221883
+ return {
221884
+ pos: domPos,
221885
+ layoutEpoch,
221886
+ blockId,
221887
+ pageIndex,
221888
+ column,
221889
+ lineIndex
221890
+ };
221891
+ }
222134
221892
  }
222135
- logClickStage("log", "success", {
222136
- pos: domPos,
222137
- usedMethod: "DOM",
222138
- note: "position found but fragment not located"
222139
- });
222140
- return {
222141
- pos: domPos,
222142
- layoutEpoch: domLayoutEpoch,
222143
- blockId: "",
222144
- pageIndex: 0,
222145
- column: 0,
222146
- lineIndex: -1
222147
- };
222148
- }
222149
- logClickStage("log", "dom-fallback", { reason: "DOM mapping returned null, trying geometry" });
222150
221893
  }
222151
- logClickStage("log", "geometry-attempt", { trying: "geometry-based mapping" });
221894
+ return {
221895
+ pos: domPos,
221896
+ layoutEpoch,
221897
+ blockId: "",
221898
+ pageIndex: 0,
221899
+ column: 0,
221900
+ lineIndex: -1
221901
+ };
221902
+ }
221903
+ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, options) {
221904
+ const layoutEpoch = layout.layoutEpoch ?? 0;
221905
+ const geometryHelper = options?.geometryHelper;
221906
+ const pageHint = options?.pageHint;
222152
221907
  let pageHit = null;
222153
- let domPageRelativeY;
222154
- if (domContainer != null && clientX != null && clientY != null) {
222155
- const pageEl = findPageElement(domContainer, clientX, clientY);
222156
- if (pageEl) {
222157
- const domPageIndex = Number(pageEl.dataset.pageIndex ?? "NaN");
222158
- if (Number.isFinite(domPageIndex) && domPageIndex >= 0 && domPageIndex < layout.pages.length) {
222159
- pageHit = {
222160
- pageIndex: domPageIndex,
222161
- page: layout.pages[domPageIndex]
222162
- };
222163
- const pageRect = pageEl.getBoundingClientRect();
222164
- const layoutPageHeight = pageHit.page.size?.h ?? layout.pageSize.h;
222165
- const domPageHeight = pageRect.height;
222166
- const effectiveZoom = domPageHeight > 0 && layoutPageHeight > 0 ? domPageHeight / layoutPageHeight : 1;
222167
- domPageRelativeY = (clientY - pageRect.top) / effectiveZoom;
222168
- }
222169
- }
221908
+ if (pageHint != null) {
221909
+ const pi = pageHint.pageIndex;
221910
+ if (pi >= 0 && pi < layout.pages.length)
221911
+ pageHit = {
221912
+ pageIndex: pi,
221913
+ page: layout.pages[pi]
221914
+ };
222170
221915
  }
222171
221916
  if (!pageHit)
222172
221917
  pageHit = hitTestPage(layout, containerPoint, geometryHelper);
222173
- if (!pageHit) {
222174
- logClickStage("warn", "no-page", { point: containerPoint });
221918
+ if (!pageHit)
222175
221919
  return null;
222176
- }
222177
221920
  const pageTopY = geometryHelper ? geometryHelper.getPageTop(pageHit.pageIndex) : calculatePageTopFallback(layout, pageHit.pageIndex);
222178
221921
  const pageRelativePoint = {
222179
221922
  x: containerPoint.x,
222180
- y: domPageRelativeY ?? containerPoint.y - pageTopY
221923
+ y: pageHint?.pageRelativeY ?? containerPoint.y - pageTopY
222181
221924
  };
222182
- logClickStage("log", "page-hit", {
222183
- pageIndex: pageHit.pageIndex,
222184
- pageRelativePoint
222185
- });
222186
221925
  let fragmentHit = hitTestFragment(layout, pageHit, blocks2, measures, pageRelativePoint);
222187
221926
  if (!fragmentHit) {
222188
221927
  if (!pageHit.page.fragments.filter((f2) => f2.kind === "table").some((f2) => {
@@ -222196,14 +221935,8 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222196
221935
  if (fragment2.kind === "para" && measure.kind === "paragraph" && block.kind === "paragraph") {
222197
221936
  const lines = fragment2.lines ?? measure.lines.slice(fragment2.fromLine, fragment2.toLine);
222198
221937
  const lineIndex = findLineIndexAtY(lines, pageY, 0, lines.length);
222199
- if (lineIndex == null) {
222200
- logClickStage("warn", "no-line", {
222201
- blockId: fragment2.blockId,
222202
- pageIndex,
222203
- pageY
222204
- });
221938
+ if (lineIndex == null)
222205
221939
  return null;
222206
- }
222207
221940
  const line = lines[lineIndex];
222208
221941
  const isRTL = isRtlBlock(block);
222209
221942
  const indentLeft = typeof block.attrs?.indent?.left === "number" ? block.attrs.indent.left : 0;
@@ -222216,34 +221949,9 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222216
221949
  const isJustified = block.attrs?.alignment === "justify";
222217
221950
  const alignmentOverride = isListItem$1 && !isJustified ? "left" : undefined;
222218
221951
  const pos = mapPointToPm(block, line, pageRelativePoint.x - fragment2.x, isRTL, availableWidth, alignmentOverride);
222219
- if (pos == null) {
222220
- logClickStage("warn", "no-position", {
222221
- blockId: fragment2.blockId,
222222
- lineIndex,
222223
- isRTL
222224
- });
221952
+ if (pos == null)
222225
221953
  return null;
222226
- }
222227
221954
  const column = determineColumn(layout, fragment2.x);
222228
- logPositionDebug({
222229
- origin: "geometry",
222230
- pos,
222231
- blockId: fragment2.blockId,
222232
- pageIndex,
222233
- column,
222234
- lineIndex,
222235
- x: pageRelativePoint.x - fragment2.x,
222236
- y: pageRelativePoint.y,
222237
- isRTL
222238
- });
222239
- logClickStage("log", "success", {
222240
- blockId: fragment2.blockId,
222241
- pos,
222242
- pageIndex,
222243
- column,
222244
- lineIndex,
222245
- origin: "paragraph"
222246
- });
222247
221955
  return {
222248
221956
  pos,
222249
221957
  layoutEpoch,
@@ -222256,18 +221964,8 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222256
221964
  if (isAtomicFragment(fragment2)) {
222257
221965
  const pmRange = getAtomicPmRange(fragment2, block);
222258
221966
  const pos = pmRange.pmStart ?? pmRange.pmEnd ?? null;
222259
- if (pos == null) {
222260
- logClickStage("warn", "atomic-without-range", { fragmentId: fragment2.blockId });
221967
+ if (pos == null)
222261
221968
  return null;
222262
- }
222263
- logClickStage("log", "success", {
222264
- blockId: fragment2.blockId,
222265
- pos,
222266
- pageIndex,
222267
- column: determineColumn(layout, fragment2.x),
222268
- lineIndex: -1,
222269
- origin: "atomic-fragment-hit"
222270
- });
222271
221969
  return {
222272
221970
  pos,
222273
221971
  layoutEpoch,
@@ -222294,15 +221992,7 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222294
221992
  const isListItem$1 = (cellMeasure.marker?.markerWidth ?? 0) > 0;
222295
221993
  const isJustified = cellBlock.attrs?.alignment === "justify";
222296
221994
  const pos = mapPointToPm(cellBlock, line, localX, isRTL, availableWidth, isListItem$1 && !isJustified ? "left" : undefined);
222297
- if (pos != null) {
222298
- logClickStage("log", "success", {
222299
- blockId: tableHit.fragment.blockId,
222300
- pos,
222301
- pageIndex,
222302
- column: determineColumn(layout, tableHit.fragment.x),
222303
- lineIndex,
222304
- origin: "table-cell"
222305
- });
221995
+ if (pos != null)
222306
221996
  return {
222307
221997
  pos,
222308
221998
  layoutEpoch,
@@ -222311,18 +222001,9 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222311
222001
  column: determineColumn(layout, tableHit.fragment.x),
222312
222002
  lineIndex
222313
222003
  };
222314
- }
222315
222004
  }
222316
222005
  const firstRun = cellBlock.runs?.[0];
222317
- if (firstRun && firstRun.pmStart != null) {
222318
- logClickStage("log", "success", {
222319
- blockId: tableHit.fragment.blockId,
222320
- pos: firstRun.pmStart,
222321
- pageIndex,
222322
- column: determineColumn(layout, tableHit.fragment.x),
222323
- lineIndex: 0,
222324
- origin: "table-cell-fallback"
222325
- });
222006
+ if (firstRun && firstRun.pmStart != null)
222326
222007
  return {
222327
222008
  pos: firstRun.pmStart,
222328
222009
  layoutEpoch,
@@ -222331,30 +222012,14 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222331
222012
  column: determineColumn(layout, tableHit.fragment.x),
222332
222013
  lineIndex: 0
222333
222014
  };
222334
- }
222335
- logClickStage("warn", "table-cell-no-position", {
222336
- blockId: tableHit.fragment.blockId,
222337
- cellRow: tableHit.cellRowIndex,
222338
- cellCol: tableHit.cellColIndex
222339
- });
222340
222015
  }
222341
222016
  const atomicHit = hitTestAtomicFragment(pageHit, blocks2, measures, pageRelativePoint);
222342
222017
  if (atomicHit && isAtomicFragment(atomicHit.fragment)) {
222343
222018
  const { fragment: fragment2, block, pageIndex } = atomicHit;
222344
222019
  const pmRange = getAtomicPmRange(fragment2, block);
222345
222020
  const pos = pmRange.pmStart ?? pmRange.pmEnd ?? null;
222346
- if (pos == null) {
222347
- logClickStage("warn", "atomic-without-range", { fragmentId: fragment2.blockId });
222021
+ if (pos == null)
222348
222022
  return null;
222349
- }
222350
- logClickStage("log", "success", {
222351
- blockId: fragment2.blockId,
222352
- pos,
222353
- pageIndex,
222354
- column: determineColumn(layout, fragment2.x),
222355
- lineIndex: -1,
222356
- origin: "atomic-direct-hit"
222357
- });
222358
222023
  return {
222359
222024
  pos,
222360
222025
  layoutEpoch,
@@ -222364,42 +222029,8 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222364
222029
  lineIndex: -1
222365
222030
  };
222366
222031
  }
222367
- logClickStage("warn", "no-fragment", {
222368
- pageIndex: pageHit.pageIndex,
222369
- pageRelativePoint
222370
- });
222371
222032
  return null;
222372
222033
  }
222373
- function findBlockIndexByFragmentId(blocks2, fragmentBlockId, targetPmRange) {
222374
- const index2 = blocks2.findIndex((block) => block.id === fragmentBlockId && block.kind !== "pageBreak" && block.kind !== "sectionBreak");
222375
- if (index2 !== -1)
222376
- return index2;
222377
- const baseBlockId = fragmentBlockId.replace(/-\d+$/, "");
222378
- if (baseBlockId === fragmentBlockId)
222379
- return -1;
222380
- const matchingIndices = [];
222381
- blocks2.forEach((block, idx) => {
222382
- if (block.id === baseBlockId && block.kind === "paragraph")
222383
- matchingIndices.push(idx);
222384
- });
222385
- if (matchingIndices.length === 0)
222386
- return -1;
222387
- if (matchingIndices.length === 1)
222388
- return matchingIndices[0];
222389
- if (targetPmRange)
222390
- for (const idx of matchingIndices) {
222391
- const block = blocks2[idx];
222392
- if (block.kind !== "paragraph")
222393
- continue;
222394
- if (block.runs.some((run2) => {
222395
- if (run2.pmStart == null || run2.pmEnd == null)
222396
- return false;
222397
- return run2.pmEnd > targetPmRange.from && run2.pmStart < targetPmRange.to;
222398
- }))
222399
- return idx;
222400
- }
222401
- return matchingIndices[0];
222402
- }
222403
222034
  function selectionToRects(layout, blocks2, measures, from$1, to, geometryHelper) {
222404
222035
  if (from$1 === to)
222405
222036
  return [];
@@ -222782,7 +222413,7 @@ function pmPosToCharOffset(block, line, pmPos) {
222782
222413
  const run2 = block.runs[runIndex];
222783
222414
  if (!run2)
222784
222415
  continue;
222785
- const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
222416
+ const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
222786
222417
  const runTextLength = text5.length;
222787
222418
  const runPmStart = run2.pmStart ?? null;
222788
222419
  const runPmEnd = run2.pmEnd ?? (runPmStart != null ? runPmStart + runTextLength : null);
@@ -224956,6 +224587,31 @@ function citationNodeToRun(params$1) {
224956
224587
  function authorityEntryNodeToRun(_params) {
224957
224588
  return null;
224958
224589
  }
224590
+ function estimateMathDimensions(textContent$1) {
224591
+ return {
224592
+ width: Math.max(textContent$1.length * 10, 20),
224593
+ height: 24
224594
+ };
224595
+ }
224596
+ function mathInlineNodeToRun({ node: node3, positions, sdtMetadata }) {
224597
+ const textContent$1 = String(node3.attrs?.textContent ?? "");
224598
+ const { width, height } = estimateMathDimensions(textContent$1);
224599
+ const run2 = {
224600
+ kind: "math",
224601
+ ommlJson: node3.attrs?.originalXml ?? null,
224602
+ textContent: textContent$1,
224603
+ width,
224604
+ height
224605
+ };
224606
+ const pos = positions.get(node3);
224607
+ if (pos) {
224608
+ run2.pmStart = pos.start;
224609
+ run2.pmEnd = pos.end;
224610
+ }
224611
+ if (sdtMetadata)
224612
+ run2.sdt = sdtMetadata;
224613
+ return run2;
224614
+ }
224959
224615
  function lineBreakNodeToRun({ node: node3, positions, sdtMetadata }) {
224960
224616
  const attrs = node3.attrs ?? {};
224961
224617
  const breakType = attrs.pageBreakType ?? attrs.lineBreakType ?? "line";
@@ -225860,6 +225516,30 @@ function handleParagraphNode2(node3, context) {
225860
225516
  });
225861
225517
  sectionState.currentParagraphIndex++;
225862
225518
  }
225519
+ function handleMathBlockNode(node3, context) {
225520
+ const { blocks: blocks2, recordBlockKind, nextBlockId, positions } = context;
225521
+ const textContent$1 = String(node3.attrs?.textContent ?? "");
225522
+ const justification = String(node3.attrs?.justification ?? "centerGroup");
225523
+ const { width, height } = estimateMathDimensions(textContent$1);
225524
+ const pos = positions.get(node3);
225525
+ const mathRun = {
225526
+ kind: "math",
225527
+ ommlJson: node3.attrs?.originalXml ?? null,
225528
+ textContent: textContent$1,
225529
+ width,
225530
+ height,
225531
+ pmStart: pos?.start,
225532
+ pmEnd: pos?.end
225533
+ };
225534
+ const block = {
225535
+ kind: "paragraph",
225536
+ id: nextBlockId("paragraph"),
225537
+ runs: [mathRun],
225538
+ attrs: { alignment: JUSTIFICATION_TO_ALIGN[justification] ?? "center" }
225539
+ };
225540
+ blocks2.push(block);
225541
+ recordBlockKind?.(block.kind);
225542
+ }
225863
225543
  function toFlowBlocks(pmDoc, options) {
225864
225544
  const defaultFont = options?.defaultFont ?? DEFAULT_FONT;
225865
225545
  const defaultSize = options?.defaultSize ?? DEFAULT_SIZE2;
@@ -226385,6 +226065,299 @@ function renderRemoteSelection(options) {
226385
226065
  });
226386
226066
  options.renderCaret();
226387
226067
  }
226068
+ function safeElementsFromPoint(doc$12, x, y$1) {
226069
+ if (typeof doc$12.elementsFromPoint !== "function")
226070
+ return [];
226071
+ try {
226072
+ return doc$12.elementsFromPoint(x, y$1) ?? [];
226073
+ } catch {
226074
+ return [];
226075
+ }
226076
+ }
226077
+ function hasElementsFromPoint(doc$12) {
226078
+ return typeof doc$12.elementsFromPoint === "function";
226079
+ }
226080
+ function getContainerDocument(domContainer) {
226081
+ return domContainer.ownerDocument ?? null;
226082
+ }
226083
+ function getNodeDocument(node3) {
226084
+ return node3.ownerDocument ?? null;
226085
+ }
226086
+ function createRangeForNode(node3) {
226087
+ return getNodeDocument(node3)?.createRange() ?? null;
226088
+ }
226089
+ function isVisibleRect(rect) {
226090
+ return rect.width > 0 && rect.height > 0;
226091
+ }
226092
+ function isRtlLine(lineEl) {
226093
+ return getComputedStyle(lineEl).direction === "rtl";
226094
+ }
226095
+ function readPmRange(el) {
226096
+ return {
226097
+ start: Number(el.dataset.pmStart ?? "NaN"),
226098
+ end: Number(el.dataset.pmEnd ?? "NaN")
226099
+ };
226100
+ }
226101
+ function getClickableSpans(lineEl) {
226102
+ return Array.from(lineEl.querySelectorAll("span, a")).filter((el) => el.dataset.pmStart !== undefined && el.dataset.pmEnd !== undefined && !el.classList.contains(CLASS.inlineSdtWrapper));
226103
+ }
226104
+ function clickToPositionDom(domContainer, clientX, clientY) {
226105
+ log2("=== clickToPositionDom START ===", {
226106
+ clientX,
226107
+ clientY
226108
+ });
226109
+ const pageEl = findPageElement(domContainer, clientX, clientY);
226110
+ if (!pageEl) {
226111
+ log2("No page element found");
226112
+ return null;
226113
+ }
226114
+ log2("Page found:", { pageIndex: pageEl.dataset.pageIndex });
226115
+ const doc$12 = getContainerDocument(domContainer);
226116
+ if (!doc$12) {
226117
+ log2("No owner document found");
226118
+ return null;
226119
+ }
226120
+ const hitChain = safeElementsFromPoint(doc$12, clientX, clientY);
226121
+ if (!Array.isArray(hitChain)) {
226122
+ log2("elementsFromPoint returned non-array");
226123
+ return null;
226124
+ }
226125
+ logHitChain(hitChain);
226126
+ const fragmentEl = hitChain.find((el) => el.classList?.contains?.(CLASS.fragment));
226127
+ if (!fragmentEl) {
226128
+ if (hasElementsFromPoint(doc$12)) {
226129
+ log2("No fragment in hit chain; deferring to geometry");
226130
+ return null;
226131
+ }
226132
+ const fallback = pageEl.querySelector(`.${CLASS.fragment}`);
226133
+ if (!fallback)
226134
+ return null;
226135
+ log2("Using fallback fragment (no elementsFromPoint)");
226136
+ return resolveFragment(fallback, clientX, clientY);
226137
+ }
226138
+ const hitChainLine = hitChain.find((el) => el.classList?.contains?.(CLASS.line) && el.dataset?.pmStart !== undefined && el.dataset?.pmEnd !== undefined);
226139
+ if (hitChainLine) {
226140
+ log2("Using hit-chain line directly");
226141
+ return resolveLineAtX(hitChainLine, clientX);
226142
+ }
226143
+ if (fragmentEl.classList.contains(CLASS.tableFragment)) {
226144
+ log2("Table fragment without line in hit chain — deferring to geometry");
226145
+ return null;
226146
+ }
226147
+ return resolveFragment(fragmentEl, clientX, clientY);
226148
+ }
226149
+ function findPageElement(domContainer, clientX, clientY) {
226150
+ if (domContainer.classList?.contains?.(CLASS.page))
226151
+ return domContainer;
226152
+ const doc$12 = getContainerDocument(domContainer);
226153
+ if (!doc$12)
226154
+ return null;
226155
+ const pageFromHit = safeElementsFromPoint(doc$12, clientX, clientY).find((el) => el.classList?.contains?.(CLASS.page));
226156
+ if (pageFromHit)
226157
+ return pageFromHit;
226158
+ const pages = Array.from(domContainer.querySelectorAll(`.${CLASS.page}`));
226159
+ for (const page of pages) {
226160
+ const r$1 = page.getBoundingClientRect();
226161
+ if (clientX >= r$1.left && clientX <= r$1.right && clientY >= r$1.top && clientY <= r$1.bottom)
226162
+ return page;
226163
+ }
226164
+ return pages[0] ?? null;
226165
+ }
226166
+ function readLayoutEpochFromDom(domContainer, clientX, clientY) {
226167
+ const doc$12 = getContainerDocument(domContainer);
226168
+ if (!doc$12 || !hasElementsFromPoint(doc$12))
226169
+ return null;
226170
+ const hitChain = safeElementsFromPoint(doc$12, clientX, clientY);
226171
+ let latestEpoch = null;
226172
+ for (const el of hitChain) {
226173
+ if (!(el instanceof HTMLElement))
226174
+ continue;
226175
+ if (!domContainer.contains(el))
226176
+ continue;
226177
+ const epoch = Number(el.dataset.layoutEpoch);
226178
+ if (!Number.isFinite(epoch))
226179
+ continue;
226180
+ if (latestEpoch == null || epoch > latestEpoch)
226181
+ latestEpoch = epoch;
226182
+ }
226183
+ return latestEpoch;
226184
+ }
226185
+ function resolveFragment(fragmentEl, viewX, viewY) {
226186
+ const lineEls = Array.from(fragmentEl.querySelectorAll(`.${CLASS.line}`));
226187
+ if (lineEls.length === 0) {
226188
+ log2("No lines in fragment");
226189
+ return null;
226190
+ }
226191
+ const lineEl = findLineAtY(lineEls, viewY);
226192
+ if (!lineEl)
226193
+ return null;
226194
+ return resolveLineAtX(lineEl, viewX);
226195
+ }
226196
+ function resolveLineAtX(lineEl, viewX) {
226197
+ const { start: lineStart, end: lineEnd } = readPmRange(lineEl);
226198
+ if (!Number.isFinite(lineStart) || !Number.isFinite(lineEnd)) {
226199
+ log2("Line has invalid PM positions");
226200
+ return null;
226201
+ }
226202
+ return resolvePositionInLine(lineEl, lineStart, lineEnd, getClickableSpans(lineEl), viewX);
226203
+ }
226204
+ function resolvePositionInLine(lineEl, lineStart, lineEnd, spanEls, viewX) {
226205
+ if (spanEls.length === 0) {
226206
+ log2("No spans in line, returning lineStart:", lineStart);
226207
+ return lineStart;
226208
+ }
226209
+ const rtl = isRtlLine(lineEl);
226210
+ const allRects = spanEls.map((el) => el.getBoundingClientRect());
226211
+ const visibleRects = allRects.filter(isVisibleRect);
226212
+ const boundsRects = visibleRects.length > 0 ? visibleRects : allRects;
226213
+ const visualLeft = Math.min(...boundsRects.map((r$1) => r$1.left));
226214
+ const visualRight = Math.max(...boundsRects.map((r$1) => r$1.right));
226215
+ if (viewX <= visualLeft)
226216
+ return rtl ? lineEnd : lineStart;
226217
+ if (viewX >= visualRight)
226218
+ return rtl ? lineStart : lineEnd;
226219
+ const targetEl = findSpanAtX(spanEls, viewX);
226220
+ if (!targetEl)
226221
+ return lineStart;
226222
+ const { start: spanStart, end: spanEnd } = readPmRange(targetEl);
226223
+ if (!Number.isFinite(spanStart) || !Number.isFinite(spanEnd))
226224
+ return null;
226225
+ const firstChild = targetEl.firstChild;
226226
+ if (!firstChild || firstChild.nodeType !== Node.TEXT_NODE || !firstChild.textContent) {
226227
+ const targetRect = targetEl.getBoundingClientRect();
226228
+ const closerToLeft = Math.abs(viewX - targetRect.left) <= Math.abs(viewX - targetRect.right);
226229
+ return rtl ? closerToLeft ? spanEnd : spanStart : closerToLeft ? spanStart : spanEnd;
226230
+ }
226231
+ const textNode = firstChild;
226232
+ const charIndex = findCharIndexAtX(textNode, viewX, rtl);
226233
+ return mapCharIndexToPm(spanStart, spanEnd, textNode.length, charIndex);
226234
+ }
226235
+ function findLineAtY(lineEls, viewY) {
226236
+ if (lineEls.length === 0)
226237
+ return null;
226238
+ for (const lineEl of lineEls) {
226239
+ const r$1 = lineEl.getBoundingClientRect();
226240
+ if (viewY >= r$1.top && viewY <= r$1.bottom)
226241
+ return lineEl;
226242
+ }
226243
+ return lineEls[lineEls.length - 1];
226244
+ }
226245
+ function findSpanAtX(spanEls, viewX) {
226246
+ if (spanEls.length === 0)
226247
+ return null;
226248
+ let nearest = spanEls[0];
226249
+ let minDist = Infinity;
226250
+ for (const span of spanEls) {
226251
+ const r$1 = span.getBoundingClientRect();
226252
+ if (!isVisibleRect(r$1))
226253
+ continue;
226254
+ if (viewX >= r$1.left && viewX <= r$1.right)
226255
+ return span;
226256
+ const dist = Math.min(Math.abs(viewX - r$1.left), Math.abs(viewX - r$1.right));
226257
+ if (dist < minDist) {
226258
+ minDist = dist;
226259
+ nearest = span;
226260
+ }
226261
+ }
226262
+ return nearest;
226263
+ }
226264
+ function mapCharIndexToPm(spanStart, spanEnd, textLength, charIndex) {
226265
+ if (!Number.isFinite(spanStart) || !Number.isFinite(spanEnd))
226266
+ return spanStart;
226267
+ if (textLength <= 0)
226268
+ return spanStart;
226269
+ const pmRange = spanEnd - spanStart;
226270
+ if (!Number.isFinite(pmRange) || pmRange <= 0)
226271
+ return spanStart;
226272
+ if (pmRange === textLength)
226273
+ return Math.min(spanEnd, Math.max(spanStart, spanStart + charIndex));
226274
+ return charIndex / textLength <= 0.5 ? spanStart : spanEnd;
226275
+ }
226276
+ function findCharIndexAtX(textNode, targetX, rtl) {
226277
+ const text5 = textNode.textContent ?? "";
226278
+ if (text5.length === 0)
226279
+ return 0;
226280
+ const container = textNode.parentElement;
226281
+ if (!container)
226282
+ return 0;
226283
+ const containerRect = container.getBoundingClientRect();
226284
+ const caretIndex = caretOffsetFromPoint(targetX, containerRect.top + containerRect.height / 2, textNode);
226285
+ if (caretIndex != null)
226286
+ return caretIndex;
226287
+ return binarySearchCharIndex(textNode, text5.length, targetX, rtl, containerRect);
226288
+ }
226289
+ function caretOffsetFromPoint(x, y$1, expectedNode) {
226290
+ const doc$12 = getNodeDocument(expectedNode);
226291
+ if (!doc$12)
226292
+ return null;
226293
+ if (typeof doc$12.caretPositionFromPoint === "function") {
226294
+ const cp = doc$12.caretPositionFromPoint(x, y$1);
226295
+ if (cp && cp.offsetNode === expectedNode)
226296
+ return cp.offset;
226297
+ }
226298
+ if (typeof doc$12.caretRangeFromPoint === "function") {
226299
+ const r$1 = doc$12.caretRangeFromPoint(x, y$1);
226300
+ if (r$1 && r$1.startContainer === expectedNode)
226301
+ return r$1.startOffset;
226302
+ }
226303
+ return null;
226304
+ }
226305
+ function binarySearchCharIndex(textNode, length$12, targetX, rtl, containerRect) {
226306
+ const range = createRangeForNode(textNode);
226307
+ if (!range)
226308
+ return 0;
226309
+ const measureX = (i4) => {
226310
+ if (i4 <= 0)
226311
+ return rtl ? containerRect.right : containerRect.left;
226312
+ range.setStart(textNode, 0);
226313
+ range.setEnd(textNode, i4);
226314
+ const r$1 = range.getBoundingClientRect();
226315
+ return rtl ? r$1.left : r$1.right;
226316
+ };
226317
+ let lo = 0;
226318
+ let hi = length$12;
226319
+ while (lo < hi) {
226320
+ const mid = Math.floor((lo + hi) / 2);
226321
+ if (rtl ? measureX(mid) > targetX : measureX(mid) < targetX)
226322
+ lo = mid + 1;
226323
+ else
226324
+ hi = mid;
226325
+ }
226326
+ const index2 = Math.max(0, Math.min(length$12, lo));
226327
+ if (index2 > 0 && Math.abs(measureX(index2 - 1) - targetX) < Math.abs(measureX(index2) - targetX))
226328
+ return index2 - 1;
226329
+ return index2;
226330
+ }
226331
+ function logHitChain(hitChain) {}
226332
+ function resolvePointerPositionHit(options) {
226333
+ const { layout, blocks: blocks2, measures, containerPoint, domContainer, clientX, clientY, geometryHelper } = options;
226334
+ const layoutEpoch = layout.layoutEpoch ?? 0;
226335
+ if (domContainer != null && clientX != null && clientY != null) {
226336
+ const domPos = clickToPositionDom(domContainer, clientX, clientY);
226337
+ const domLayoutEpoch = readLayoutEpochFromDom(domContainer, clientX, clientY) ?? layoutEpoch;
226338
+ if (domPos != null)
226339
+ return resolvePositionHitFromDomPosition(layout, blocks2, measures, domPos, domLayoutEpoch);
226340
+ const pageEl = findPageElement(domContainer, clientX, clientY);
226341
+ if (pageEl) {
226342
+ const domPageIndex = Number(pageEl.dataset.pageIndex ?? "NaN");
226343
+ if (Number.isFinite(domPageIndex) && domPageIndex >= 0 && domPageIndex < layout.pages.length) {
226344
+ const page = layout.pages[domPageIndex];
226345
+ const pageRect = pageEl.getBoundingClientRect();
226346
+ const layoutPageHeight = page.size?.h ?? layout.pageSize.h;
226347
+ const domPageHeight = pageRect.height;
226348
+ const effectiveZoom = domPageHeight > 0 && layoutPageHeight > 0 ? domPageHeight / layoutPageHeight : 1;
226349
+ return clickToPositionGeometry(layout, blocks2, measures, containerPoint, {
226350
+ geometryHelper,
226351
+ pageHint: {
226352
+ pageIndex: domPageIndex,
226353
+ pageRelativeY: (clientY - pageRect.top) / effectiveZoom
226354
+ }
226355
+ });
226356
+ }
226357
+ }
226358
+ }
226359
+ return clickToPositionGeometry(layout, blocks2, measures, containerPoint, { geometryHelper });
226360
+ }
226388
226361
  function getCellPosFromTableHit(tableHit, doc$12, blocks2) {
226389
226362
  if (!tableHit || !tableHit.block || typeof tableHit.block.id !== "string") {
226390
226363
  console.warn("[getCellPosFromTableHit] Invalid tableHit input:", tableHit);
@@ -236528,7 +236501,7 @@ var Node$13 = class Node$14 {
236528
236501
  update() {
236529
236502
  return false;
236530
236503
  }
236531
- }, ShapeGroup, CHART_IMMUTABILITY_KEY, chartPositionCache, Chart, sharedAttributes$2 = () => ({
236504
+ }, ShapeGroup, CHART_IMMUTABILITY_KEY, chartPositionCache, Chart, MathInline, MathBlock, sharedAttributes$2 = () => ({
236532
236505
  originalName: { default: null },
236533
236506
  originalXml: { default: null }
236534
236507
  }), hiddenRender = (type) => ["sd-passthrough", {
@@ -241895,7 +241868,34 @@ var Node$13 = class Node$14 {
241895
241868
  }
241896
241869
  element3.style.textAlign = resolveTextAlign(attrs?.alignment, rtl);
241897
241870
  return rtl;
241898
- }, shouldUseSegmentPositioning = (hasExplicitPositioning, hasSegments, isRtl) => hasExplicitPositioning && hasSegments && !isRtl, cssToken = (varName, fallback) => ({
241871
+ }, shouldUseSegmentPositioning = (hasExplicitPositioning, hasSegments, isRtl) => hasExplicitPositioning && hasSegments && !isRtl, MATHML_NS$2 = "http://www.w3.org/1998/Math/MathML", OPERATOR_CHARS, convertMathRun = (node3, doc$12) => {
241872
+ const elements = node3.elements ?? [];
241873
+ let text5 = "";
241874
+ for (const child of elements)
241875
+ if (child.name === "m:t") {
241876
+ const textChildren = child.elements ?? [];
241877
+ for (const tc of textChildren)
241878
+ if (tc.type === "text" && typeof tc.text === "string")
241879
+ text5 += tc.text;
241880
+ }
241881
+ if (!text5)
241882
+ return null;
241883
+ const isNormalText = elements.find((el$1) => el$1.name === "m:rPr")?.elements?.some((el$1) => el$1.name === "m:nor") ?? false;
241884
+ const tag = classifyMathText(text5);
241885
+ const el = doc$12.createElementNS(MATHML_NS$2, tag);
241886
+ el.textContent = text5;
241887
+ if (tag === "mi" && isNormalText)
241888
+ el.setAttribute("mathvariant", "normal");
241889
+ return el;
241890
+ }, MATHML_NS$1 = "http://www.w3.org/1998/Math/MathML", convertFraction = (node3, doc$12, convertChildren) => {
241891
+ const elements = node3.elements ?? [];
241892
+ const num = elements.find((e) => e.name === "m:num");
241893
+ const den = elements.find((e) => e.name === "m:den");
241894
+ const frac = doc$12.createElementNS(MATHML_NS$1, "mfrac");
241895
+ frac.appendChild(convertChildren(num?.elements ?? []));
241896
+ frac.appendChild(convertChildren(den?.elements ?? []));
241897
+ return frac;
241898
+ }, MATHML_NS = "http://www.w3.org/1998/Math/MathML", MATH_OBJECT_REGISTRY, ARGUMENT_ELEMENTS, cssToken = (varName, fallback) => ({
241899
241899
  css: `var(${varName}, ${fallback})`,
241900
241900
  fallback
241901
241901
  }), LIST_MARKER_GAP = 8, DEFAULT_PAGE_HEIGHT_PX = 1056, DEFAULT_VIRTUALIZED_PAGE_GAP = 72, COMMENT_HIGHLIGHT_EXTERNAL, COMMENT_HIGHLIGHT_EXTERNAL_ACTIVE, COMMENT_HIGHLIGHT_EXTERNAL_FADED, COMMENT_HIGHLIGHT_INTERNAL, COMMENT_HIGHLIGHT_INTERNAL_ACTIVE, COMMENT_HIGHLIGHT_INTERNAL_FADED, COMMENT_HIGHLIGHT_EXTERNAL_NESTED_BORDER, COMMENT_HIGHLIGHT_INTERNAL_NESTED_BORDER, LINK_DATASET_KEYS, MAX_HREF_LENGTH = 2048, SAFE_ANCHOR_PATTERN, MAX_DATA_URL_LENGTH, VALID_IMAGE_DATA_URL, MAX_RESIZE_MULTIPLIER = 3, FALLBACK_MAX_DIMENSION = 1000, MIN_IMAGE_DIMENSION = 20, AMBIGUOUS_LINK_PATTERNS, linkMetrics, TRACK_CHANGE_BASE_CLASS, TRACK_CHANGE_FOCUSED_CLASS = "track-change-focused", TRACK_CHANGE_MODIFIER_CLASS, LINK_TARGET_SET, normalizeAnchor$1 = (value) => {
@@ -242474,7 +242474,7 @@ var Node$13 = class Node$14 {
242474
242474
  }
242475
242475
  return block.id;
242476
242476
  }, applyRunStyles = (element3, run2, _isLink = false) => {
242477
- if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation")
242477
+ if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
242478
242478
  return;
242479
242479
  element3.style.fontFamily = run2.fontFamily;
242480
242480
  element3.style.fontSize = `${run2.fontSize}px`;
@@ -242710,6 +242710,9 @@ var Node$13 = class Node$14 {
242710
242710
  },
242711
242711
  setScrollContainer(el) {
242712
242712
  painter.setScrollContainer(el);
242713
+ },
242714
+ setResolvedLayout(resolvedLayout) {
242715
+ painter.setResolvedLayout(resolvedLayout);
242713
242716
  }
242714
242717
  };
242715
242718
  }, VerticalNavigationPluginKey, createDefaultState = () => ({ goalX: null }), VerticalNavigation, createPermissionBlockMarkerNode = ({ name, attributes }) => Node$13.create({
@@ -242908,6 +242911,8 @@ var Node$13 = class Node$14 {
242908
242911
  Image,
242909
242912
  NodeResizer,
242910
242913
  CustomSelection,
242914
+ MathInline,
242915
+ MathBlock,
242911
242916
  PassthroughInline,
242912
242917
  PassthroughBlock
242913
242918
  ];
@@ -243004,6 +243009,8 @@ var Node$13 = class Node$14 {
243004
243009
  PermissionRanges,
243005
243010
  Protection,
243006
243011
  VerticalNavigation,
243012
+ MathInline,
243013
+ MathBlock,
243007
243014
  PassthroughInline,
243008
243015
  PassthroughBlock,
243009
243016
  Diffing
@@ -246339,7 +246346,7 @@ var Node$13 = class Node$14 {
246339
246346
  let totalSpaces = line.spaceCount ?? 0;
246340
246347
  if (totalSpaces === 0)
246341
246348
  totalSpaces = sliceRunsForLine(block, line).reduce((sum, run2) => {
246342
- if (isTabRun(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation")
246349
+ if (isTabRun(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
246343
246350
  return sum;
246344
246351
  return sum + countSpaces(run2.text ?? "");
246345
246352
  }, 0);
@@ -246360,7 +246367,7 @@ var Node$13 = class Node$14 {
246360
246367
  if (maxGaps === 0)
246361
246368
  return 0;
246362
246369
  return Math.min(Math.max(precedingChars, 0), maxGaps) * run2.letterSpacing;
246363
- }, log2 = (...args$1) => {}, CLASS_NAMES, defaultHeaderFooterIdentifier = () => ({
246370
+ }, defaultHeaderFooterIdentifier = () => ({
246364
246371
  headerIds: {
246365
246372
  default: null,
246366
246373
  first: null,
@@ -246698,6 +246705,8 @@ var Node$13 = class Node$14 {
246698
246705
  }
246699
246706
  if (run2.kind === "fieldAnnotation")
246700
246707
  return `fa:${fieldAnnotationKey(run2)}`;
246708
+ if (run2.kind === "math")
246709
+ return `math:${run2.textContent}:${run2.width}:${run2.height}`;
246701
246710
  const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? "";
246702
246711
  const marks = hashRunVisualMarks(run2);
246703
246712
  let trackedKey = "";
@@ -247427,6 +247436,15 @@ var Node$13 = class Node$14 {
247427
247436
  for (let i4 = 0;i4 < a2.runs.length; i4 += 1) {
247428
247437
  const runA = a2.runs[i4];
247429
247438
  const runB = b$1.runs[i4];
247439
+ if (runA.kind === "math" || runB.kind === "math") {
247440
+ if (runA.kind !== runB.kind)
247441
+ return false;
247442
+ if (runA.kind === "math" && runB.kind === "math") {
247443
+ if (runA.textContent !== runB.textContent)
247444
+ return false;
247445
+ }
247446
+ continue;
247447
+ }
247430
247448
  if (("src" in runA || runA.kind === "lineBreak" || runA.kind === "break" || runA.kind === "fieldAnnotation" ? "" : runA.text) !== ("src" in runB || runB.kind === "lineBreak" || runB.kind === "break" || runB.kind === "fieldAnnotation" ? "" : runB.text) || fieldAnnotationKey(runA) !== fieldAnnotationKey(runB) || hashRunVisualMarks(runA) !== hashRunVisualMarks(runB) || getTrackedChangeKey(runA) !== getTrackedChangeKey(runB) || getCommentKey(runA) !== getCommentKey(runB))
247431
247449
  return false;
247432
247450
  }
@@ -248294,7 +248312,7 @@ var Node$13 = class Node$14 {
248294
248312
  }
248295
248313
  }, isAtomicFragment = (fragment2) => {
248296
248314
  return fragment2.kind === "drawing" || fragment2.kind === "image";
248297
- }, logClickStage = (_level, _stage, _payload) => {}, logPositionDebug = (payload) => {}, logSelectionMapDebug = (payload) => {}, blockPmRangeFromAttrs = (block) => {
248315
+ }, blockPmRangeFromAttrs = (block) => {
248298
248316
  const attrs = block?.attrs;
248299
248317
  const pmStart = typeof attrs?.pmStart === "number" ? attrs.pmStart : undefined;
248300
248318
  return {
@@ -248306,10 +248324,65 @@ var Node$13 = class Node$14 {
248306
248324
  pmStart: typeof fragment2.pmStart === "number" ? fragment2.pmStart : blockPmRangeFromAttrs(block).pmStart,
248307
248325
  pmEnd: typeof fragment2.pmEnd === "number" ? fragment2.pmEnd : blockPmRangeFromAttrs(block).pmEnd
248308
248326
  };
248309
- }, rangesOverlap = (startA, endA, startB, endB) => {
248310
- if (startA == null)
248327
+ }, isRtlBlock = (block) => {
248328
+ if (block.kind !== "paragraph")
248311
248329
  return false;
248312
- return (endA ?? startA + 1) > startB && startA < endB;
248330
+ const attrs = block.attrs;
248331
+ if (!attrs)
248332
+ return false;
248333
+ const directionAttr = attrs.direction ?? attrs.dir ?? attrs.textDirection;
248334
+ if (typeof directionAttr === "string" && directionAttr.toLowerCase() === "rtl")
248335
+ return true;
248336
+ if (typeof attrs.rtl === "boolean")
248337
+ return attrs.rtl;
248338
+ return false;
248339
+ }, determineColumn = (layout, fragmentX) => {
248340
+ const columns = layout.columns;
248341
+ if (!columns || columns.count <= 1)
248342
+ return 0;
248343
+ const span = (layout.pageSize.w - columns.gap * (columns.count - 1)) / columns.count + columns.gap;
248344
+ const relative = fragmentX;
248345
+ const raw = Math.floor(relative / Math.max(span, 1));
248346
+ return Math.max(0, Math.min(columns.count - 1, raw));
248347
+ }, findLineIndexAtY = (lines, offsetY, fromLine, toLine) => {
248348
+ if (!lines || lines.length === 0)
248349
+ return null;
248350
+ const lineCount = lines.length;
248351
+ if (fromLine < 0 || toLine > lineCount || fromLine >= toLine)
248352
+ return null;
248353
+ let cursor = 0;
248354
+ for (let i4 = fromLine;i4 < toLine; i4 += 1) {
248355
+ const line = lines[i4];
248356
+ if (!line)
248357
+ return null;
248358
+ const next2 = cursor + line.lineHeight;
248359
+ if (offsetY >= cursor && offsetY < next2)
248360
+ return i4;
248361
+ cursor = next2;
248362
+ }
248363
+ return toLine - 1;
248364
+ }, mapPointToPm = (block, line, x, isRTL, availableWidthOverride, alignmentOverride) => {
248365
+ if (block.kind !== "paragraph")
248366
+ return null;
248367
+ const range = computeLinePmRange$1(block, line);
248368
+ if (range.pmStart == null || range.pmEnd == null)
248369
+ return null;
248370
+ const result = findCharacterAtX(block, line, x, range.pmStart, availableWidthOverride, alignmentOverride);
248371
+ let pmPosition = result.pmPosition;
248372
+ if (isRTL) {
248373
+ const charOffset = result.charOffset;
248374
+ const charsInLine = Math.max(1, line.toChar - line.fromChar);
248375
+ pmPosition = charOffsetToPm(block, line, Math.max(0, Math.min(charsInLine, charsInLine - charOffset)), range.pmStart);
248376
+ }
248377
+ return pmPosition;
248378
+ }, calculatePageTopFallback = (layout, pageIndex) => {
248379
+ const pageGap = layout.pageGap ?? 0;
248380
+ let y$1 = 0;
248381
+ for (let i4 = 0;i4 < pageIndex; i4++) {
248382
+ const pageHeight = layout.pages[i4]?.size?.h ?? layout.pageSize.h;
248383
+ y$1 += pageHeight + pageGap;
248384
+ }
248385
+ return y$1;
248313
248386
  }, hitTestAtomicFragment = (pageHit, blocks2, measures, point5) => {
248314
248387
  for (const fragment2 of pageHit.page.fragments) {
248315
248388
  if (!isAtomicFragment(fragment2))
@@ -248458,32 +248531,10 @@ var Node$13 = class Node$14 {
248458
248531
  }
248459
248532
  }
248460
248533
  return null;
248461
- }, readLayoutEpochFromDom = (domContainer, clientX, clientY) => {
248462
- const doc$12 = domContainer.ownerDocument ?? (typeof document !== "undefined" ? document : null);
248463
- if (!doc$12 || typeof doc$12.elementsFromPoint !== "function")
248464
- return null;
248465
- let hitChain = [];
248466
- try {
248467
- hitChain = doc$12.elementsFromPoint(clientX, clientY) ?? [];
248468
- } catch {
248469
- return null;
248470
- }
248471
- let latestEpoch = null;
248472
- for (const el of hitChain) {
248473
- if (!(el instanceof HTMLElement))
248474
- continue;
248475
- if (!domContainer.contains(el))
248476
- continue;
248477
- const raw = el.dataset.layoutEpoch;
248478
- if (raw == null)
248479
- continue;
248480
- const epoch = Number(raw);
248481
- if (!Number.isFinite(epoch))
248482
- continue;
248483
- if (latestEpoch == null || epoch > latestEpoch)
248484
- latestEpoch = epoch;
248485
- }
248486
- return latestEpoch;
248534
+ }, logSelectionMapDebug = (payload) => {}, rangesOverlap = (startA, endA, startB, endB) => {
248535
+ if (startA == null)
248536
+ return false;
248537
+ return (endA ?? startA + 1) > startB && startA < endB;
248487
248538
  }, DEFAULT_CELL_PADDING, getCellPaddingFromRow = (cellIdx, row2) => {
248488
248539
  const padding = row2?.cells?.[cellIdx]?.attrs?.padding ?? {};
248489
248540
  return {
@@ -248515,39 +248566,6 @@ var Node$13 = class Node$14 {
248515
248566
  for (let i4 = fromLine;i4 < toLine && i4 < measure.lines.length; i4 += 1)
248516
248567
  height += measure.lines[i4]?.lineHeight ?? 0;
248517
248568
  return height;
248518
- }, calculatePageTopFallback = (layout, pageIndex) => {
248519
- const pageGap = layout.pageGap ?? 0;
248520
- let y$1 = 0;
248521
- for (let i4 = 0;i4 < pageIndex; i4++) {
248522
- const pageHeight = layout.pages[i4]?.size?.h ?? layout.pageSize.h;
248523
- y$1 += pageHeight + pageGap;
248524
- }
248525
- return y$1;
248526
- }, determineColumn = (layout, fragmentX) => {
248527
- const columns = layout.columns;
248528
- if (!columns || columns.count <= 1)
248529
- return 0;
248530
- const span = (layout.pageSize.w - columns.gap * (columns.count - 1)) / columns.count + columns.gap;
248531
- const relative = fragmentX;
248532
- const raw = Math.floor(relative / Math.max(span, 1));
248533
- return Math.max(0, Math.min(columns.count - 1, raw));
248534
- }, findLineIndexAtY = (lines, offsetY, fromLine, toLine) => {
248535
- if (!lines || lines.length === 0)
248536
- return null;
248537
- const lineCount = lines.length;
248538
- if (fromLine < 0 || toLine > lineCount || fromLine >= toLine)
248539
- return null;
248540
- let cursor = 0;
248541
- for (let i4 = fromLine;i4 < toLine; i4 += 1) {
248542
- const line = lines[i4];
248543
- if (!line)
248544
- return null;
248545
- const next2 = cursor + line.lineHeight;
248546
- if (offsetY >= cursor && offsetY < next2)
248547
- return i4;
248548
- cursor = next2;
248549
- }
248550
- return toLine - 1;
248551
248569
  }, lineHeightBeforeIndex$1 = (measure, absoluteLineIndex) => {
248552
248570
  if (measure.kind !== "paragraph")
248553
248571
  return 0;
@@ -248555,20 +248573,6 @@ var Node$13 = class Node$14 {
248555
248573
  for (let i4 = 0;i4 < absoluteLineIndex; i4 += 1)
248556
248574
  height += measure.lines[i4]?.lineHeight ?? 0;
248557
248575
  return height;
248558
- }, mapPointToPm = (block, line, x, isRTL, availableWidthOverride, alignmentOverride) => {
248559
- if (block.kind !== "paragraph")
248560
- return null;
248561
- const range = computeLinePmRange(block, line);
248562
- if (range.pmStart == null || range.pmEnd == null)
248563
- return null;
248564
- const result = findCharacterAtX(block, line, x, range.pmStart, availableWidthOverride, alignmentOverride);
248565
- let pmPosition = result.pmPosition;
248566
- if (isRTL) {
248567
- const charOffset = result.charOffset;
248568
- const charsInLine = Math.max(1, line.toChar - line.fromChar);
248569
- pmPosition = charOffsetToPm(block, line, Math.max(0, Math.min(charsInLine, charsInLine - charOffset)), range.pmStart);
248570
- }
248571
- return pmPosition;
248572
248576
  }, mapPmToX = (block, line, offset$1, fragmentWidth, alignmentOverride) => {
248573
248577
  if (fragmentWidth <= 0 || line.width <= 0)
248574
248578
  return 0;
@@ -248593,18 +248597,6 @@ var Node$13 = class Node$14 {
248593
248597
  if (totalIndent > fragmentWidth)
248594
248598
  console.warn(`[mapPmToX] Paragraph indents (${totalIndent}px) exceed fragment width (${fragmentWidth}px) for block ${block.id}. This may indicate a layout miscalculation. Available width clamped to 0.`);
248595
248599
  return measureCharacterX(block, line, offset$1, availableWidth, alignmentOverride);
248596
- }, isRtlBlock = (block) => {
248597
- if (block.kind !== "paragraph")
248598
- return false;
248599
- const attrs = block.attrs;
248600
- if (!attrs)
248601
- return false;
248602
- const directionAttr = attrs.direction ?? attrs.dir ?? attrs.textDirection;
248603
- if (typeof directionAttr === "string" && directionAttr.toLowerCase() === "rtl")
248604
- return true;
248605
- if (typeof attrs.rtl === "boolean")
248606
- return attrs.rtl;
248607
- return false;
248608
248600
  }, WORD_CHARACTER_REGEX, EpochPositionMapper = class {
248609
248601
  #currentEpoch = 0;
248610
248602
  #mapsByFromEpoch = /* @__PURE__ */ new Map;
@@ -251206,7 +251198,7 @@ var Node$13 = class Node$14 {
251206
251198
  return;
251207
251199
  updateGhostListMarkerOffsets(node3, paragraphBlocks, context);
251208
251200
  applyGhostListMarkerOffsets(node3, paragraphBlocks, context);
251209
- }, INLINE_CONVERTERS_REGISTRY, SHAPE_CONVERTERS_REGISTRY, DEFAULT_FONT = "Times New Roman", DEFAULT_SIZE2, nodeHandlers2, converters, SCROLL_DEBOUNCE_MS = 32, DEFAULT_STALE_TIMEOUT_MS, THROTTLE_MS = 16, RemoteCursorManager = class {
251201
+ }, INLINE_CONVERTERS_REGISTRY, SHAPE_CONVERTERS_REGISTRY, JUSTIFICATION_TO_ALIGN, DEFAULT_FONT = "Times New Roman", DEFAULT_SIZE2, nodeHandlers2, converters, SCROLL_DEBOUNCE_MS = 32, DEFAULT_STALE_TIMEOUT_MS, THROTTLE_MS = 16, RemoteCursorManager = class {
251210
251202
  #options;
251211
251203
  #remoteCursorState = /* @__PURE__ */ new Map;
251212
251204
  #remoteCursorElements = /* @__PURE__ */ new Map;
@@ -251429,7 +251421,7 @@ var Node$13 = class Node$14 {
251429
251421
  this.#onCursorsUpdate = null;
251430
251422
  this.#isSetup = false;
251431
251423
  }
251432
- }, SEMANTIC_FOOTNOTES_HEADING_BLOCK_ID = "__sd_semantic_footnotes_heading", SEMANTIC_FOOTNOTE_BLOCK_ID_PREFIX = "__sd_semantic_footnote", MULTI_CLICK_TIME_THRESHOLD_MS = 400, MULTI_CLICK_DISTANCE_THRESHOLD_PX = 5, AUTO_SCROLL_EDGE_PX = 32, AUTO_SCROLL_MAX_SPEED_PX = 24, SCROLL_DETECTION_TOLERANCE_PX = 1, COMMENT_HIGHLIGHT_SELECTOR = ".superdoc-comment-highlight", clamp = (value, min$2, max$2) => Math.max(min$2, Math.min(max$2, value)), EditorInputManager = class {
251424
+ }, log2 = (...args$1) => {}, CLASS, SEMANTIC_FOOTNOTES_HEADING_BLOCK_ID = "__sd_semantic_footnotes_heading", SEMANTIC_FOOTNOTE_BLOCK_ID_PREFIX = "__sd_semantic_footnote", MULTI_CLICK_TIME_THRESHOLD_MS = 400, MULTI_CLICK_DISTANCE_THRESHOLD_PX = 5, AUTO_SCROLL_EDGE_PX = 32, AUTO_SCROLL_MAX_SPEED_PX = 24, SCROLL_DETECTION_TOLERANCE_PX = 1, COMMENT_HIGHLIGHT_SELECTOR = ".superdoc-comment-highlight", clamp = (value, min$2, max$2) => Math.max(min$2, Math.min(max$2, value)), EditorInputManager = class {
251433
251425
  #deps = null;
251434
251426
  #callbacks = {};
251435
251427
  #isDragging = false;
@@ -251939,10 +251931,19 @@ var Node$13 = class Node$14 {
251939
251931
  }
251940
251932
  const viewportHost = this.#deps.getViewportHost();
251941
251933
  const pageGeometryHelper = this.#deps.getPageGeometryHelper();
251942
- const rawHit = clickToPosition(layoutState.layout, layoutState.blocks, layoutState.measures, {
251943
- x,
251944
- y: y$1
251945
- }, viewportHost, event.clientX, event.clientY, pageGeometryHelper ?? undefined);
251934
+ const rawHit = resolvePointerPositionHit({
251935
+ layout: layoutState.layout,
251936
+ blocks: layoutState.blocks,
251937
+ measures: layoutState.measures,
251938
+ containerPoint: {
251939
+ x,
251940
+ y: y$1
251941
+ },
251942
+ domContainer: viewportHost,
251943
+ clientX: event.clientX,
251944
+ clientY: event.clientY,
251945
+ geometryHelper: pageGeometryHelper ?? undefined
251946
+ });
251946
251947
  const doc$12 = editor.state?.doc;
251947
251948
  const epochMapper = this.#deps.getEpochMapper();
251948
251949
  const mapped = rawHit && doc$12 ? epochMapper.mapPosFromLayoutToCurrentDetailed(rawHit.pos, rawHit.layoutEpoch, 1) : null;
@@ -252538,10 +252539,19 @@ var Node$13 = class Node$14 {
252538
252539
  };
252539
252540
  const viewportHost = this.#deps.getViewportHost();
252540
252541
  const pageGeometryHelper = this.#deps.getPageGeometryHelper();
252541
- const rawHit = clickToPosition(layoutState.layout, layoutState.blocks, layoutState.measures, {
252542
- x: normalized.x,
252543
- y: normalized.y
252544
- }, viewportHost, clientX, clientY, pageGeometryHelper ?? undefined);
252542
+ const rawHit = resolvePointerPositionHit({
252543
+ layout: layoutState.layout,
252544
+ blocks: layoutState.blocks,
252545
+ measures: layoutState.measures,
252546
+ containerPoint: {
252547
+ x: normalized.x,
252548
+ y: normalized.y
252549
+ },
252550
+ domContainer: viewportHost,
252551
+ clientX,
252552
+ clientY,
252553
+ geometryHelper: pageGeometryHelper ?? undefined
252554
+ });
252545
252555
  if (!rawHit)
252546
252556
  return;
252547
252557
  if (isFootnoteBlockId(rawHit.blockId))
@@ -254882,9 +254892,9 @@ var Node$13 = class Node$14 {
254882
254892
  return;
254883
254893
  console.log(...args$1);
254884
254894
  }, 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;
254885
- var init_src_BOboPGqd_es = __esm(() => {
254895
+ var init_src_9QyvRUxO_es = __esm(() => {
254886
254896
  init_rolldown_runtime_B2q5OVn9_es();
254887
- init_SuperConverter_CYbYOJeZ_es();
254897
+ init_SuperConverter_B9oNf3OB_es();
254888
254898
  init_jszip_ChlR43oI_es();
254889
254899
  init_uuid_qzgm05fK_es();
254890
254900
  init_constants_CIF8yzNk_es();
@@ -264885,6 +264895,63 @@ ${err.toString()}`);
264885
264895
  return [createChartImmutabilityPlugin()];
264886
264896
  }
264887
264897
  });
264898
+ MathInline = Node$13.create({
264899
+ name: "mathInline",
264900
+ group: "inline",
264901
+ inline: true,
264902
+ atom: true,
264903
+ marks: "",
264904
+ draggable: false,
264905
+ selectable: true,
264906
+ parseDOM() {
264907
+ return [{ tag: "sd-math-inline" }];
264908
+ },
264909
+ renderDOM() {
264910
+ return ["sd-math-inline", { style: "display: inline;" }];
264911
+ },
264912
+ addAttributes() {
264913
+ return {
264914
+ originalXml: {
264915
+ default: null,
264916
+ rendered: false
264917
+ },
264918
+ textContent: {
264919
+ default: "",
264920
+ rendered: false
264921
+ }
264922
+ };
264923
+ }
264924
+ });
264925
+ MathBlock = Node$13.create({
264926
+ name: "mathBlock",
264927
+ group: "block",
264928
+ atom: true,
264929
+ draggable: false,
264930
+ selectable: true,
264931
+ defining: true,
264932
+ parseDOM() {
264933
+ return [{ tag: "sd-math-block" }];
264934
+ },
264935
+ renderDOM() {
264936
+ return ["sd-math-block", { style: "display: block; text-align: center;" }];
264937
+ },
264938
+ addAttributes() {
264939
+ return {
264940
+ originalXml: {
264941
+ default: null,
264942
+ rendered: false
264943
+ },
264944
+ textContent: {
264945
+ default: "",
264946
+ rendered: false
264947
+ },
264948
+ justification: {
264949
+ default: "centerGroup",
264950
+ rendered: false
264951
+ }
264952
+ };
264953
+ }
264954
+ });
264888
264955
  PassthroughBlock = Node$13.create({
264889
264956
  name: "passthroughBlock",
264890
264957
  group: "block",
@@ -273162,6 +273229,7 @@ function print() { __p += __j.call(arguments, '') }
273162
273229
  "indexEntry",
273163
273230
  "tab",
273164
273231
  "footnoteReference",
273232
+ "mathInline",
273165
273233
  "passthroughInline",
273166
273234
  "bookmarkEnd",
273167
273235
  "fieldAnnotation",
@@ -273213,6 +273281,100 @@ function print() { __p += __j.call(arguments, '') }
273213
273281
  ]);
273214
273282
  SDT_BLOCK_SELECTOR = `.${DOM_CLASS_NAMES.BLOCK_SDT}[data-sdt-id]`;
273215
273283
  HOVER_CLASS = DOM_CLASS_NAMES.SDT_HOVER;
273284
+ OPERATOR_CHARS = new Set([
273285
+ "+",
273286
+ "-",
273287
+ "=",
273288
+ "<",
273289
+ ">",
273290
+ "(",
273291
+ ")",
273292
+ "[",
273293
+ "]",
273294
+ "{",
273295
+ "}",
273296
+ "|",
273297
+ "/",
273298
+ "\\",
273299
+ ",",
273300
+ ".",
273301
+ ";",
273302
+ ":",
273303
+ "!",
273304
+ "~",
273305
+ "^",
273306
+ "_",
273307
+ "±",
273308
+ "×",
273309
+ "÷",
273310
+ "←",
273311
+ "↑",
273312
+ "→",
273313
+ "↓",
273314
+ "↔",
273315
+ "∀",
273316
+ "∁",
273317
+ "∂",
273318
+ "∃",
273319
+ "∄",
273320
+ "∅",
273321
+ "∈",
273322
+ "∉",
273323
+ "∋",
273324
+ "∌",
273325
+ "∑",
273326
+ "∏",
273327
+ "√",
273328
+ "∞",
273329
+ "∧",
273330
+ "∨",
273331
+ "∩",
273332
+ "∪",
273333
+ "∫",
273334
+ "∬",
273335
+ "∭",
273336
+ "≠",
273337
+ "≡",
273338
+ "≤",
273339
+ "≥",
273340
+ "⊂",
273341
+ "⊃",
273342
+ "⊆",
273343
+ "⊇"
273344
+ ]);
273345
+ MATH_OBJECT_REGISTRY = {
273346
+ "m:r": convertMathRun,
273347
+ "m:acc": null,
273348
+ "m:bar": null,
273349
+ "m:borderBox": null,
273350
+ "m:box": null,
273351
+ "m:d": null,
273352
+ "m:eqArr": null,
273353
+ "m:f": convertFraction,
273354
+ "m:func": null,
273355
+ "m:groupChr": null,
273356
+ "m:limLow": null,
273357
+ "m:limUpp": null,
273358
+ "m:m": null,
273359
+ "m:nary": null,
273360
+ "m:phant": null,
273361
+ "m:rad": null,
273362
+ "m:sPre": null,
273363
+ "m:sSub": null,
273364
+ "m:sSubSup": null,
273365
+ "m:sSup": null
273366
+ };
273367
+ ARGUMENT_ELEMENTS = new Set([
273368
+ "m:e",
273369
+ "m:num",
273370
+ "m:den",
273371
+ "m:sub",
273372
+ "m:sup",
273373
+ "m:deg",
273374
+ "m:lim",
273375
+ "m:fName",
273376
+ "m:oMath"
273377
+ ]);
273216
273378
  init_dist4();
273217
273379
  COMMENT_HIGHLIGHT_EXTERNAL = cssToken("--sd-comments-highlight-external", "#B1124B40");
273218
273380
  COMMENT_HIGHLIGHT_EXTERNAL_ACTIVE = cssToken("--sd-comments-highlight-external-active", "#B1124B66");
@@ -273326,6 +273488,7 @@ function print() { __p += __j.call(arguments, '') }
273326
273488
  this.activeCommentId = null;
273327
273489
  this.paintSnapshotBuilder = null;
273328
273490
  this.lastPaintSnapshot = null;
273491
+ this.resolvedLayout = null;
273329
273492
  this.options = options;
273330
273493
  this.layoutMode = options.layoutMode ?? "vertical";
273331
273494
  this.isSemanticFlow = (options.flowMode ?? "paginated") === "semantic";
@@ -273387,6 +273550,9 @@ function print() { __p += __j.call(arguments, '') }
273387
273550
  getActiveComment() {
273388
273551
  return this.activeCommentId;
273389
273552
  }
273553
+ setResolvedLayout(resolvedLayout) {
273554
+ this.resolvedLayout = resolvedLayout;
273555
+ }
273390
273556
  getPaintSnapshot() {
273391
273557
  return this.lastPaintSnapshot;
273392
273558
  }
@@ -275382,7 +275548,7 @@ function print() { __p += __j.call(arguments, '') }
275382
275548
  });
275383
275549
  }
275384
275550
  extractLinkData(run2) {
275385
- if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak")
275551
+ if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak" || run2.kind === "math")
275386
275552
  return null;
275387
275553
  const link2 = run2.link;
275388
275554
  if (!link2)
@@ -275526,11 +275692,37 @@ function print() { __p += __j.call(arguments, '') }
275526
275692
  isFieldAnnotationRun(run2) {
275527
275693
  return run2.kind === "fieldAnnotation";
275528
275694
  }
275695
+ isMathRun(run2) {
275696
+ return run2.kind === "math";
275697
+ }
275698
+ renderMathRun(run2) {
275699
+ if (!this.doc)
275700
+ return null;
275701
+ const wrapper = this.doc.createElement("span");
275702
+ wrapper.className = "sd-math";
275703
+ wrapper.style.display = "inline-block";
275704
+ wrapper.style.verticalAlign = "middle";
275705
+ wrapper.style.width = `${run2.width}px`;
275706
+ wrapper.style.height = `${run2.height}px`;
275707
+ wrapper.dataset.layoutEpoch = String(this.layoutEpoch ?? 0);
275708
+ const mathEl = convertOmmlToMathml(run2.ommlJson, this.doc);
275709
+ if (mathEl)
275710
+ wrapper.appendChild(mathEl);
275711
+ else
275712
+ wrapper.textContent = run2.textContent || "";
275713
+ if (run2.pmStart != null)
275714
+ wrapper.dataset.pmStart = String(run2.pmStart);
275715
+ if (run2.pmEnd != null)
275716
+ wrapper.dataset.pmEnd = String(run2.pmEnd);
275717
+ return wrapper;
275718
+ }
275529
275719
  renderRun(run2, context, trackedConfig) {
275530
275720
  if (this.isImageRun(run2))
275531
275721
  return this.renderImageRun(run2);
275532
275722
  if (this.isFieldAnnotationRun(run2))
275533
275723
  return this.renderFieldAnnotationRun(run2);
275724
+ if (this.isMathRun(run2))
275725
+ return this.renderMathRun(run2);
275534
275726
  if (this.isLineBreakRun(run2))
275535
275727
  return null;
275536
275728
  if (this.isBreakRun(run2))
@@ -276282,6 +276474,22 @@ function print() { __p += __j.call(arguments, '') }
276282
276474
  }
276283
276475
  continue;
276284
276476
  }
276477
+ if (this.isMathRun(baseRun)) {
276478
+ const elem = this.renderRun(baseRun, context, trackedConfig);
276479
+ if (elem) {
276480
+ if (styleId)
276481
+ elem.setAttribute("styleid", styleId);
276482
+ const runSegments$1 = segmentsByRun.get(runIndex);
276483
+ const baseSegX = runSegments$1 && runSegments$1[0]?.x !== undefined ? runSegments$1[0].x : cumulativeX;
276484
+ const segX = baseSegX + indentOffset;
276485
+ const segWidth = (runSegments$1 && runSegments$1[0]?.width !== undefined ? runSegments$1[0].width : baseRun.width) ?? 0;
276486
+ elem.style.position = "absolute";
276487
+ elem.style.left = `${segX}px`;
276488
+ appendToLineGeo(elem, baseRun, segX, segWidth);
276489
+ cumulativeX = baseSegX + segWidth;
276490
+ }
276491
+ continue;
276492
+ }
276285
276493
  const runSegments = segmentsByRun.get(runIndex);
276286
276494
  if (!runSegments || runSegments.length === 0)
276287
276495
  continue;
@@ -283959,12 +284167,7 @@ function print() { __p += __j.call(arguments, '') }
283959
284167
  ]);
283960
284168
  init_dist4();
283961
284169
  SPACE_CHARS$1 = SPACE_CHARS;
283962
- CLASS_NAMES = {
283963
- page: DOM_CLASS_NAMES.PAGE,
283964
- fragment: DOM_CLASS_NAMES.FRAGMENT,
283965
- line: DOM_CLASS_NAMES.LINE,
283966
- tableFragment: DOM_CLASS_NAMES.TABLE_FRAGMENT
283967
- };
284170
+ DOM_CLASS_NAMES.PAGE, DOM_CLASS_NAMES.FRAGMENT, DOM_CLASS_NAMES.LINE, DOM_CLASS_NAMES.TABLE_FRAGMENT;
283968
284171
  init_dist4();
283969
284172
  FeatureFlags = {
283970
284173
  NUMBERING_SECTION_AWARE: isEnabled("SD_NUMBERING_SECTION_AWARE", true),
@@ -284269,7 +284472,8 @@ function print() { __p += __j.call(arguments, '') }
284269
284472
  inlineConverter: lineBreakNodeToRun,
284270
284473
  blockConverter: lineBreakNodeToBreakBlock
284271
284474
  },
284272
- table: { blockConverter: tableNodeToBlock }
284475
+ table: { blockConverter: tableNodeToBlock },
284476
+ mathInline: { inlineConverter: mathInlineNodeToRun }
284273
284477
  };
284274
284478
  for (const type of TOKEN_INLINE_TYPES.keys())
284275
284479
  INLINE_CONVERTERS_REGISTRY[type] = { inlineConverter: tokenNodeToRun };
@@ -284280,6 +284484,12 @@ function print() { __p += __j.call(arguments, '') }
284280
284484
  shapeTextbox: shapeTextboxNodeToDrawingBlock,
284281
284485
  chart: chartNodeToDrawingBlock
284282
284486
  };
284487
+ JUSTIFICATION_TO_ALIGN = {
284488
+ center: "center",
284489
+ centerGroup: "center",
284490
+ left: "left",
284491
+ right: "right"
284492
+ };
284283
284493
  DEFAULT_SIZE2 = 10 / 0.75;
284284
284494
  nodeHandlers2 = {
284285
284495
  paragraph: handleParagraphNode2,
@@ -284296,7 +284506,8 @@ function print() { __p += __j.call(arguments, '') }
284296
284506
  shapeGroup: handleShapeGroupNode,
284297
284507
  shapeContainer: handleShapeContainerNode,
284298
284508
  shapeTextbox: handleShapeTextboxNode,
284299
- chart: handleChartNode
284509
+ chart: handleChartNode,
284510
+ mathBlock: handleMathBlockNode
284300
284511
  };
284301
284512
  converters = {
284302
284513
  contentBlockNodeToDrawingBlock,
@@ -284310,6 +284521,13 @@ function print() { __p += __j.call(arguments, '') }
284310
284521
  paragraphToFlowBlocks
284311
284522
  };
284312
284523
  DEFAULT_STALE_TIMEOUT_MS = 300 * 1000;
284524
+ CLASS = {
284525
+ page: DOM_CLASS_NAMES.PAGE,
284526
+ fragment: DOM_CLASS_NAMES.FRAGMENT,
284527
+ line: DOM_CLASS_NAMES.LINE,
284528
+ tableFragment: DOM_CLASS_NAMES.TABLE_FRAGMENT,
284529
+ inlineSdtWrapper: DOM_CLASS_NAMES.INLINE_SDT_WRAPPER
284530
+ };
284313
284531
  SelectionSyncCoordinator = class extends EventEmitter2 {
284314
284532
  #docEpoch = 0;
284315
284533
  #layoutEpoch = 0;
@@ -285863,11 +286081,20 @@ function print() { __p += __j.call(arguments, '') }
285863
286081
  x: localX,
285864
286082
  y: headerPageIndex * headerPageHeight + (localY - headerPageIndex * headerPageHeight)
285865
286083
  };
285866
- return clickToPosition(context.layout, context.blocks, context.measures, headerPoint, undefined, undefined, undefined, undefined) ?? null;
286084
+ return clickToPositionGeometry(context.layout, context.blocks, context.measures, headerPoint) ?? null;
285867
286085
  }
285868
286086
  if (!this.#layoutState.layout)
285869
286087
  return null;
285870
- const rawHit = clickToPosition(this.#layoutState.layout, this.#layoutState.blocks, this.#layoutState.measures, normalized, this.#viewportHost, clientX, clientY, this.#pageGeometryHelper ?? undefined) ?? null;
286088
+ const rawHit = resolvePointerPositionHit({
286089
+ layout: this.#layoutState.layout,
286090
+ blocks: this.#layoutState.blocks,
286091
+ measures: this.#layoutState.measures,
286092
+ containerPoint: normalized,
286093
+ domContainer: this.#viewportHost,
286094
+ clientX,
286095
+ clientY,
286096
+ geometryHelper: this.#pageGeometryHelper ?? undefined
286097
+ }) ?? null;
285871
286098
  if (!rawHit)
285872
286099
  return null;
285873
286100
  const doc$12 = this.#editor.state?.doc;
@@ -287193,6 +287420,7 @@ function print() { __p += __j.call(arguments, '') }
287193
287420
  const previousMeasures = this.#layoutState.measures;
287194
287421
  let layout;
287195
287422
  let measures;
287423
+ let resolvedLayout;
287196
287424
  let headerLayouts;
287197
287425
  let footerLayouts;
287198
287426
  let extraBlocks;
@@ -287219,6 +287447,10 @@ function print() { __p += __j.call(arguments, '') }
287219
287447
  extraMeasures = Array.isArray(result.extraMeasures) ? result.extraMeasures : undefined;
287220
287448
  layout.pageGap = this.#getEffectivePageGap();
287221
287449
  layout.layoutEpoch = layoutEpoch;
287450
+ resolvedLayout = resolveLayout({
287451
+ layout,
287452
+ flowMode: this.#layoutOptions.flowMode ?? "paginated"
287453
+ });
287222
287454
  headerLayouts = result.headers;
287223
287455
  footerLayouts = result.footers;
287224
287456
  } catch (error3) {
@@ -287270,6 +287502,7 @@ function print() { __p += __j.call(arguments, '') }
287270
287502
  this.#updateDecorationProviders(layout);
287271
287503
  }
287272
287504
  const painter = this.#ensurePainter(blocksForLayout, measures);
287505
+ painter.setResolvedLayout?.(resolvedLayout);
287273
287506
  if (!isSemanticFlow && typeof painter.setProviders === "function")
287274
287507
  painter.setProviders(this.#headerFooterSession?.headerDecorationProvider, this.#headerFooterSession?.footerDecorationProvider);
287275
287508
  const headerBlocks = [];
@@ -288168,10 +288401,19 @@ function print() { __p += __j.call(arguments, '') }
288168
288401
  includeDragBuffer: false,
288169
288402
  extraPages: dragLastRawHit ? [dragLastRawHit.pageIndex] : undefined
288170
288403
  });
288171
- const refined = clickToPosition(layout, this.#layoutState.blocks, this.#layoutState.measures, {
288172
- x: normalized.x,
288173
- y: normalized.y
288174
- }, this.#viewportHost, pointer.clientX, pointer.clientY, this.#pageGeometryHelper ?? undefined);
288404
+ const refined = resolvePointerPositionHit({
288405
+ layout,
288406
+ blocks: this.#layoutState.blocks,
288407
+ measures: this.#layoutState.measures,
288408
+ containerPoint: {
288409
+ x: normalized.x,
288410
+ y: normalized.y
288411
+ },
288412
+ domContainer: this.#viewportHost,
288413
+ clientX: pointer.clientX,
288414
+ clientY: pointer.clientY,
288415
+ geometryHelper: this.#pageGeometryHelper ?? undefined
288416
+ });
288175
288417
  if (!refined)
288176
288418
  return;
288177
288419
  if (this.#isSelectionAwareVirtualizationEnabled() && this.#getPageElement(refined.pageIndex) == null) {
@@ -288874,8 +289116,8 @@ var init_zipper_YmNpPIyc_es = __esm(() => {
288874
289116
 
288875
289117
  // ../../packages/superdoc/dist/super-editor.es.js
288876
289118
  var init_super_editor_es = __esm(() => {
288877
- init_src_BOboPGqd_es();
288878
- init_SuperConverter_CYbYOJeZ_es();
289119
+ init_src_9QyvRUxO_es();
289120
+ init_SuperConverter_B9oNf3OB_es();
288879
289121
  init_jszip_ChlR43oI_es();
288880
289122
  init_xml_js_40FWvL78_es();
288881
289123
  init_constants_CIF8yzNk_es();