@superdoc-dev/cli 0.5.0-next.24 → 0.5.0-next.26

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 +808 -375
  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-BrtcDgR1.es.js
172586
+ // ../../packages/superdoc/dist/chunks/src-0P3ZlqDX.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) => {
@@ -175875,6 +175947,14 @@ function createNumberingPlugin(editor) {
175875
175947
  if (nextRev != null)
175876
175948
  tr.setNodeAttribute(pos, "sdBlockRev", nextRev);
175877
175949
  };
175950
+ const normalizeListRendering = (listRendering) => listRendering ?? null;
175951
+ const serializeListRendering = (listRendering) => JSON.stringify(normalizeListRendering(listRendering));
175952
+ const updateListRenderingIfNeeded = (node3, pos, nextListRendering) => {
175953
+ if (serializeListRendering(node3?.attrs?.listRendering) === serializeListRendering(nextListRendering))
175954
+ return;
175955
+ tr.setNodeAttribute(pos, "listRendering", normalizeListRendering(nextListRendering));
175956
+ bumpBlockRev(node3, pos);
175957
+ };
175878
175958
  numberingManager.enableCache();
175879
175959
  try {
175880
175960
  newState.doc.descendants((node3, pos) => {
@@ -175888,9 +175968,8 @@ function createNumberingPlugin(editor) {
175888
175968
  editor
175889
175969
  });
175890
175970
  if (!definitionDetails || Object.keys(definitionDetails).length === 0) {
175891
- tr.setNodeAttribute(pos, "listRendering", null);
175892
- bumpBlockRev(node3, pos);
175893
- return;
175971
+ updateListRenderingIfNeeded(node3, pos, null);
175972
+ return false;
175894
175973
  }
175895
175974
  let { lvlText, customFormat, listNumberingType, suffix, justification, abstractId } = definitionDetails;
175896
175975
  let markerText = "";
@@ -175907,18 +175986,14 @@ function createNumberingPlugin(editor) {
175907
175986
  }) ?? "";
175908
175987
  else
175909
175988
  markerText = docxNumberingHelpers.normalizeLvlTextChar(lvlText) ?? "";
175910
- const newListRendering = {
175989
+ updateListRenderingIfNeeded(node3, pos, {
175911
175990
  markerText,
175912
175991
  suffix,
175913
175992
  justification,
175914
175993
  path: path2,
175915
175994
  numberingType: listNumberingType,
175916
175995
  ...customFormat ? { customFormat } : {}
175917
- };
175918
- if (JSON.stringify(node3.attrs.listRendering) !== JSON.stringify(newListRendering)) {
175919
- tr.setNodeAttribute(pos, "listRendering", newListRendering);
175920
- bumpBlockRev(node3, pos);
175921
- }
175996
+ });
175922
175997
  return false;
175923
175998
  });
175924
175999
  } finally {
@@ -182799,6 +182874,15 @@ function measureTabAlignmentGroup(startRunIndex, runs2, ctx$1, decimalSeparator
182799
182874
  result.totalWidth += imageWidth;
182800
182875
  continue;
182801
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
+ }
182802
182886
  if (isFieldAnnotationRun(run2)) {
182803
182887
  const fontSize = run2.fontSize ?? DEFAULT_FIELD_ANNOTATION_FONT_SIZE;
182804
182888
  const { font } = buildFontString({
@@ -183332,6 +183416,27 @@ async function measureParagraphBlock(block, maxWidth) {
183332
183416
  pendingRunSpacing = 0;
183333
183417
  continue;
183334
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
+ }
183335
183440
  if (isFieldAnnotationRun(run2)) {
183336
183441
  const displayText = applyTextTransform$2(run2.displayLabel || "", run2);
183337
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;
@@ -189218,6 +189323,86 @@ function applyParagraphBordersAndShading(paraWrapper, block) {
189218
189323
  function sdtElementsById(root3, sdtId) {
189219
189324
  return root3.querySelectorAll(`.${DOM_CLASS_NAMES.BLOCK_SDT}[data-sdt-id="${sdtId}"]`);
189220
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
+ }
189221
189406
  function isMinimalWordLayout(value) {
189222
189407
  if (typeof value !== "object" || value === null)
189223
189408
  return false;
@@ -219448,7 +219633,7 @@ function getMeasurementContext() {
219448
219633
  return measurementCtx;
219449
219634
  }
219450
219635
  function getRunFontString(run2) {
219451
- if (run2.kind === "tab" || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || "src" in run2)
219636
+ if (run2.kind === "tab" || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" || "src" in run2)
219452
219637
  return "normal normal 16px Arial";
219453
219638
  return `${run2.italic ? "italic" : "normal"} ${run2.bold ? "bold" : "normal"} ${run2.fontSize ?? 16}px ${run2.fontFamily ?? "Arial"}`;
219454
219639
  }
@@ -219480,6 +219665,10 @@ function sliceRunsForLine(block, line) {
219480
219665
  result.push(run2);
219481
219666
  continue;
219482
219667
  }
219668
+ if (run2.kind === "math") {
219669
+ result.push(run2);
219670
+ continue;
219671
+ }
219483
219672
  const text5 = run2.text ?? "";
219484
219673
  const isFirstRun = runIndex === line.fromRun;
219485
219674
  const isLastRun = runIndex === line.toRun;
@@ -219515,7 +219704,7 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
219515
219704
  return charOffset / Math.max(1, runs$1.reduce((sum, run2) => {
219516
219705
  if (isTabRun(run2))
219517
219706
  return sum + TAB_CHAR_LENGTH;
219518
- if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation")
219707
+ if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
219519
219708
  return sum;
219520
219709
  return sum + (run2.text ?? "").length;
219521
219710
  }, 0)) * renderedLineWidth;
@@ -219536,9 +219725,9 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
219536
219725
  currentCharOffset += runLength$1;
219537
219726
  continue;
219538
219727
  }
219539
- const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
219728
+ const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
219540
219729
  const runLength = text5.length;
219541
- const displayText = applyTextTransform$1(text5, isTabRun(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? undefined : run2.textTransform);
219730
+ 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);
219542
219731
  if (currentCharOffset + runLength >= charOffset) {
219543
219732
  const offsetInRun = charOffset - currentCharOffset;
219544
219733
  ctx$1.font = getRunFontString(run2);
@@ -219585,7 +219774,7 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx$1) {
219585
219774
  }
219586
219775
  if (isTabRun(run2))
219587
219776
  return segmentBaseX + (offsetInSegment > 0 ? segment.width ?? 0 : 0);
219588
- if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation")
219777
+ if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
219589
219778
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
219590
219779
  const textUpToTarget = applyTextTransform$1(run2.text ?? "", "textTransform" in run2 ? run2.textTransform : undefined).slice(segment.fromChar, segment.toChar).slice(0, offsetInSegment);
219591
219780
  ctx$1.font = getRunFontString(run2);
@@ -219613,7 +219802,7 @@ function charOffsetToPm(block, line, charOffset, fallbackPmStart) {
219613
219802
  let lastPm = fallbackPmStart;
219614
219803
  for (const run2 of runs2) {
219615
219804
  const isTab = isTabRun(run2);
219616
- const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
219805
+ const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
219617
219806
  const runLength = isTab ? TAB_CHAR_LENGTH : text5.length;
219618
219807
  const runPmStart = typeof run2.pmStart === "number" ? run2.pmStart : null;
219619
219808
  const runPmEnd = typeof run2.pmEnd === "number" ? run2.pmEnd : runPmStart != null ? runPmStart + runLength : null;
@@ -219642,7 +219831,7 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
219642
219831
  const charsInLine = Math.max(1, runs$1.reduce((sum, run2) => {
219643
219832
  if (isTabRun(run2))
219644
219833
  return sum + TAB_CHAR_LENGTH;
219645
- if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation")
219834
+ if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
219646
219835
  return sum;
219647
219836
  return sum + (run2.text ?? "").length;
219648
219837
  }, 0));
@@ -219675,9 +219864,9 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
219675
219864
  currentCharOffset += TAB_CHAR_LENGTH;
219676
219865
  continue;
219677
219866
  }
219678
- const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
219867
+ const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
219679
219868
  const runLength = text5.length;
219680
- const displayText = applyTextTransform$1(text5, isTabRun(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? undefined : run2.textTransform);
219869
+ 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);
219681
219870
  if (runLength === 0)
219682
219871
  continue;
219683
219872
  ctx$1.font = getRunFontString(run2);
@@ -219723,13 +219912,13 @@ function isRtlLine(lineEl) {
219723
219912
  function isVisibleRect(rect) {
219724
219913
  return rect.width > 0 && rect.height > 0;
219725
219914
  }
219726
- function clickToPositionDom(domContainer, clientX, clientY) {
219915
+ function clickToPositionDom$1(domContainer, clientX, clientY) {
219727
219916
  log2("=== clickToPositionDom START ===");
219728
219917
  log2("Input coords:", {
219729
219918
  clientX,
219730
219919
  clientY
219731
219920
  });
219732
- const pageEl = findPageElement(domContainer, clientX, clientY);
219921
+ const pageEl = findPageElement$1(domContainer, clientX, clientY);
219733
219922
  if (!pageEl) {
219734
219923
  log2("No page element found");
219735
219924
  return null;
@@ -219840,7 +220029,7 @@ function clickToPositionDom(domContainer, clientX, clientY) {
219840
220029
  log2("=== clickToPositionDom END ===", { result });
219841
220030
  return result;
219842
220031
  }
219843
- function findPageElement(domContainer, clientX, clientY) {
220032
+ function findPageElement$1(domContainer, clientX, clientY) {
219844
220033
  if (domContainer.classList?.contains?.(CLASS_NAMES.page))
219845
220034
  return domContainer;
219846
220035
  const doc$12 = document;
@@ -220528,7 +220717,7 @@ function extractBlockText(block) {
220528
220717
  let pmStart = Infinity;
220529
220718
  let pmEnd = 0;
220530
220719
  for (const run2 of block.runs) {
220531
- text5 += "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text;
220720
+ text5 += "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text;
220532
220721
  if (run2.pmStart !== undefined)
220533
220722
  pmStart = Math.min(pmStart, run2.pmStart);
220534
220723
  if (run2.pmEnd !== undefined)
@@ -220585,7 +220774,7 @@ function fontString(run2) {
220585
220774
  return `${textRun?.italic ? "italic " : ""}${textRun?.bold ? "bold " : ""}${size$1}px ${family}`.trim();
220586
220775
  }
220587
220776
  function runText(run2) {
220588
- return "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
220777
+ return "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
220589
220778
  }
220590
220779
  function measureRunSliceWidth(run2, fromChar, toChar) {
220591
220780
  const context = getCtx();
@@ -220859,7 +221048,9 @@ function computeHeaderFooterContentHash(blocks2) {
220859
221048
  parts.push(block.id);
220860
221049
  if (block.kind === "paragraph")
220861
221050
  for (const run2 of block.runs) {
220862
- if (!("src" in run2) && run2.kind !== "lineBreak" && run2.kind !== "break" && run2.kind !== "fieldAnnotation")
221051
+ if (run2.kind === "math")
221052
+ parts.push(`math:${run2.textContent}`);
221053
+ else if (!("src" in run2) && run2.kind !== "lineBreak" && run2.kind !== "break" && run2.kind !== "fieldAnnotation")
220863
221054
  parts.push(run2.text ?? "");
220864
221055
  if ("bold" in run2 && run2.bold)
220865
221056
  parts.push("b");
@@ -221971,6 +222162,36 @@ function snapToNearestFragment(pageHit, blocks2, measures, pageRelativePoint) {
221971
222162
  }
221972
222163
  return nearestHit;
221973
222164
  }
222165
+ function findBlockIndexByFragmentId(blocks2, fragmentBlockId, targetPmRange) {
222166
+ const index2 = blocks2.findIndex((block) => block.id === fragmentBlockId && block.kind !== "pageBreak" && block.kind !== "sectionBreak");
222167
+ if (index2 !== -1)
222168
+ return index2;
222169
+ const baseBlockId = fragmentBlockId.replace(/-\d+$/, "");
222170
+ if (baseBlockId === fragmentBlockId)
222171
+ return -1;
222172
+ const matchingIndices = [];
222173
+ blocks2.forEach((block, idx) => {
222174
+ if (block.id === baseBlockId && block.kind === "paragraph")
222175
+ matchingIndices.push(idx);
222176
+ });
222177
+ if (matchingIndices.length === 0)
222178
+ return -1;
222179
+ if (matchingIndices.length === 1)
222180
+ return matchingIndices[0];
222181
+ if (targetPmRange)
222182
+ for (const idx of matchingIndices) {
222183
+ const block = blocks2[idx];
222184
+ if (block.kind !== "paragraph")
222185
+ continue;
222186
+ if (block.runs.some((run2) => {
222187
+ if (run2.pmStart == null || run2.pmEnd == null)
222188
+ return false;
222189
+ return run2.pmEnd > targetPmRange.from && run2.pmStart < targetPmRange.to;
222190
+ }))
222191
+ return idx;
222192
+ }
222193
+ return matchingIndices[0];
222194
+ }
221974
222195
  function hitTestPage(layout, point5, geometryHelper) {
221975
222196
  if (geometryHelper) {
221976
222197
  const pageIndex = geometryHelper.getPageIndexAtY(point5.y);
@@ -222049,137 +222270,92 @@ function hitTestFragment(layout, pageHit, blocks2, measures, point5) {
222049
222270
  }
222050
222271
  return null;
222051
222272
  }
222052
- function clickToPosition(layout, blocks2, measures, containerPoint, domContainer, clientX, clientY, geometryHelper) {
222053
- const layoutEpoch = layout.layoutEpoch ?? 0;
222054
- logClickStage("log", "entry", {
222055
- point: containerPoint,
222056
- pages: layout.pages.length,
222057
- hasDomContainer: domContainer != null
222058
- });
222059
- if (domContainer != null && clientX != null && clientY != null) {
222060
- logClickStage("log", "dom-attempt", { trying: "DOM-based mapping" });
222061
- const domPos = clickToPositionDom(domContainer, clientX, clientY);
222062
- const domLayoutEpoch = readLayoutEpochFromDom(domContainer, clientX, clientY) ?? layoutEpoch;
222063
- if (domPos != null) {
222064
- logPositionDebug({
222065
- origin: "dom",
222066
- pos: domPos,
222067
- clientX,
222068
- clientY
222069
- });
222070
- let blockId = "";
222071
- let pageIndex = 0;
222072
- let column = 0;
222073
- let lineIndex = -1;
222074
- for (let pi = 0;pi < layout.pages.length; pi++) {
222075
- const page = layout.pages[pi];
222076
- for (const fragment2 of page.fragments)
222077
- if (fragment2.kind === "para" && fragment2.pmStart != null && fragment2.pmEnd != null) {
222078
- if (domPos >= fragment2.pmStart && domPos <= fragment2.pmEnd) {
222079
- blockId = fragment2.blockId;
222080
- pageIndex = pi;
222081
- column = determineColumn(layout, fragment2.x);
222082
- const blockIndex = findBlockIndexByFragmentId(blocks2, fragment2.blockId);
222083
- if (blockIndex !== -1) {
222084
- const measure = measures[blockIndex];
222085
- if (measure && measure.kind === "paragraph")
222086
- if (fragment2.lines && fragment2.lines.length > 0)
222087
- for (let localIndex = 0;localIndex < fragment2.lines.length; localIndex++) {
222088
- const line = fragment2.lines[localIndex];
222089
- if (!line)
222090
- continue;
222091
- const range = computeLinePmRange(blocks2[blockIndex], line);
222092
- if (range.pmStart != null && range.pmEnd != null) {
222093
- if (domPos >= range.pmStart && domPos <= range.pmEnd) {
222094
- lineIndex = fragment2.fromLine + localIndex;
222095
- break;
222096
- }
222097
- }
222273
+ function resolvePositionHitFromDomPosition(layout, blocks2, measures, domPos, layoutEpoch) {
222274
+ let blockId = "";
222275
+ let pageIndex = 0;
222276
+ let column = 0;
222277
+ let lineIndex = -1;
222278
+ for (let pi = 0;pi < layout.pages.length; pi++) {
222279
+ const page = layout.pages[pi];
222280
+ for (const fragment2 of page.fragments)
222281
+ if (fragment2.kind === "para" && fragment2.pmStart != null && fragment2.pmEnd != null) {
222282
+ if (domPos >= fragment2.pmStart && domPos <= fragment2.pmEnd) {
222283
+ blockId = fragment2.blockId;
222284
+ pageIndex = pi;
222285
+ column = determineColumn(layout, fragment2.x);
222286
+ const blockIndex = findBlockIndexByFragmentId(blocks2, fragment2.blockId);
222287
+ if (blockIndex !== -1) {
222288
+ const measure = measures[blockIndex];
222289
+ if (measure && measure.kind === "paragraph")
222290
+ if (fragment2.lines && fragment2.lines.length > 0)
222291
+ for (let localIndex = 0;localIndex < fragment2.lines.length; localIndex++) {
222292
+ const line = fragment2.lines[localIndex];
222293
+ if (!line)
222294
+ continue;
222295
+ const range = computeLinePmRange$1(blocks2[blockIndex], line);
222296
+ if (range.pmStart != null && range.pmEnd != null) {
222297
+ if (domPos >= range.pmStart && domPos <= range.pmEnd) {
222298
+ lineIndex = fragment2.fromLine + localIndex;
222299
+ break;
222098
222300
  }
222099
- else
222100
- for (let li2 = fragment2.fromLine;li2 < fragment2.toLine; li2++) {
222101
- const line = measure.lines[li2];
222102
- if (!line)
222103
- continue;
222104
- const range = computeLinePmRange(blocks2[blockIndex], line);
222105
- if (range.pmStart != null && range.pmEnd != null) {
222106
- if (domPos >= range.pmStart && domPos <= range.pmEnd) {
222107
- lineIndex = li2;
222108
- break;
222109
- }
222110
- }
222301
+ }
222302
+ }
222303
+ else
222304
+ for (let li2 = fragment2.fromLine;li2 < fragment2.toLine; li2++) {
222305
+ const line = measure.lines[li2];
222306
+ if (!line)
222307
+ continue;
222308
+ const range = computeLinePmRange$1(blocks2[blockIndex], line);
222309
+ if (range.pmStart != null && range.pmEnd != null) {
222310
+ if (domPos >= range.pmStart && domPos <= range.pmEnd) {
222311
+ lineIndex = li2;
222312
+ break;
222111
222313
  }
222112
- }
222113
- logClickStage("log", "success", {
222114
- blockId,
222115
- pos: domPos,
222116
- pageIndex,
222117
- column,
222118
- lineIndex,
222119
- usedMethod: "DOM"
222120
- });
222121
- return {
222122
- pos: domPos,
222123
- layoutEpoch: domLayoutEpoch,
222124
- blockId,
222125
- pageIndex,
222126
- column,
222127
- lineIndex
222128
- };
222129
- }
222314
+ }
222315
+ }
222130
222316
  }
222317
+ return {
222318
+ pos: domPos,
222319
+ layoutEpoch,
222320
+ blockId,
222321
+ pageIndex,
222322
+ column,
222323
+ lineIndex
222324
+ };
222325
+ }
222131
222326
  }
222132
- logClickStage("log", "success", {
222133
- pos: domPos,
222134
- usedMethod: "DOM",
222135
- note: "position found but fragment not located"
222136
- });
222137
- return {
222138
- pos: domPos,
222139
- layoutEpoch: domLayoutEpoch,
222140
- blockId: "",
222141
- pageIndex: 0,
222142
- column: 0,
222143
- lineIndex: -1
222144
- };
222145
- }
222146
- logClickStage("log", "dom-fallback", { reason: "DOM mapping returned null, trying geometry" });
222147
222327
  }
222148
- logClickStage("log", "geometry-attempt", { trying: "geometry-based mapping" });
222328
+ return {
222329
+ pos: domPos,
222330
+ layoutEpoch,
222331
+ blockId: "",
222332
+ pageIndex: 0,
222333
+ column: 0,
222334
+ lineIndex: -1
222335
+ };
222336
+ }
222337
+ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, options) {
222338
+ const layoutEpoch = layout.layoutEpoch ?? 0;
222339
+ const geometryHelper = options?.geometryHelper;
222340
+ const pageHint = options?.pageHint;
222149
222341
  let pageHit = null;
222150
- let domPageRelativeY;
222151
- if (domContainer != null && clientX != null && clientY != null) {
222152
- const pageEl = findPageElement(domContainer, clientX, clientY);
222153
- if (pageEl) {
222154
- const domPageIndex = Number(pageEl.dataset.pageIndex ?? "NaN");
222155
- if (Number.isFinite(domPageIndex) && domPageIndex >= 0 && domPageIndex < layout.pages.length) {
222156
- pageHit = {
222157
- pageIndex: domPageIndex,
222158
- page: layout.pages[domPageIndex]
222159
- };
222160
- const pageRect = pageEl.getBoundingClientRect();
222161
- const layoutPageHeight = pageHit.page.size?.h ?? layout.pageSize.h;
222162
- const domPageHeight = pageRect.height;
222163
- const effectiveZoom = domPageHeight > 0 && layoutPageHeight > 0 ? domPageHeight / layoutPageHeight : 1;
222164
- domPageRelativeY = (clientY - pageRect.top) / effectiveZoom;
222165
- }
222166
- }
222342
+ if (pageHint != null) {
222343
+ const pi = pageHint.pageIndex;
222344
+ if (pi >= 0 && pi < layout.pages.length)
222345
+ pageHit = {
222346
+ pageIndex: pi,
222347
+ page: layout.pages[pi]
222348
+ };
222167
222349
  }
222168
222350
  if (!pageHit)
222169
222351
  pageHit = hitTestPage(layout, containerPoint, geometryHelper);
222170
- if (!pageHit) {
222171
- logClickStage("warn", "no-page", { point: containerPoint });
222352
+ if (!pageHit)
222172
222353
  return null;
222173
- }
222174
222354
  const pageTopY = geometryHelper ? geometryHelper.getPageTop(pageHit.pageIndex) : calculatePageTopFallback(layout, pageHit.pageIndex);
222175
222355
  const pageRelativePoint = {
222176
222356
  x: containerPoint.x,
222177
- y: domPageRelativeY ?? containerPoint.y - pageTopY
222357
+ y: pageHint?.pageRelativeY ?? containerPoint.y - pageTopY
222178
222358
  };
222179
- logClickStage("log", "page-hit", {
222180
- pageIndex: pageHit.pageIndex,
222181
- pageRelativePoint
222182
- });
222183
222359
  let fragmentHit = hitTestFragment(layout, pageHit, blocks2, measures, pageRelativePoint);
222184
222360
  if (!fragmentHit) {
222185
222361
  if (!pageHit.page.fragments.filter((f2) => f2.kind === "table").some((f2) => {
@@ -222193,14 +222369,8 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222193
222369
  if (fragment2.kind === "para" && measure.kind === "paragraph" && block.kind === "paragraph") {
222194
222370
  const lines = fragment2.lines ?? measure.lines.slice(fragment2.fromLine, fragment2.toLine);
222195
222371
  const lineIndex = findLineIndexAtY(lines, pageY, 0, lines.length);
222196
- if (lineIndex == null) {
222197
- logClickStage("warn", "no-line", {
222198
- blockId: fragment2.blockId,
222199
- pageIndex,
222200
- pageY
222201
- });
222372
+ if (lineIndex == null)
222202
222373
  return null;
222203
- }
222204
222374
  const line = lines[lineIndex];
222205
222375
  const isRTL = isRtlBlock(block);
222206
222376
  const indentLeft = typeof block.attrs?.indent?.left === "number" ? block.attrs.indent.left : 0;
@@ -222213,34 +222383,9 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222213
222383
  const isJustified = block.attrs?.alignment === "justify";
222214
222384
  const alignmentOverride = isListItem$1 && !isJustified ? "left" : undefined;
222215
222385
  const pos = mapPointToPm(block, line, pageRelativePoint.x - fragment2.x, isRTL, availableWidth, alignmentOverride);
222216
- if (pos == null) {
222217
- logClickStage("warn", "no-position", {
222218
- blockId: fragment2.blockId,
222219
- lineIndex,
222220
- isRTL
222221
- });
222386
+ if (pos == null)
222222
222387
  return null;
222223
- }
222224
222388
  const column = determineColumn(layout, fragment2.x);
222225
- logPositionDebug({
222226
- origin: "geometry",
222227
- pos,
222228
- blockId: fragment2.blockId,
222229
- pageIndex,
222230
- column,
222231
- lineIndex,
222232
- x: pageRelativePoint.x - fragment2.x,
222233
- y: pageRelativePoint.y,
222234
- isRTL
222235
- });
222236
- logClickStage("log", "success", {
222237
- blockId: fragment2.blockId,
222238
- pos,
222239
- pageIndex,
222240
- column,
222241
- lineIndex,
222242
- origin: "paragraph"
222243
- });
222244
222389
  return {
222245
222390
  pos,
222246
222391
  layoutEpoch,
@@ -222253,18 +222398,8 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222253
222398
  if (isAtomicFragment(fragment2)) {
222254
222399
  const pmRange = getAtomicPmRange(fragment2, block);
222255
222400
  const pos = pmRange.pmStart ?? pmRange.pmEnd ?? null;
222256
- if (pos == null) {
222257
- logClickStage("warn", "atomic-without-range", { fragmentId: fragment2.blockId });
222401
+ if (pos == null)
222258
222402
  return null;
222259
- }
222260
- logClickStage("log", "success", {
222261
- blockId: fragment2.blockId,
222262
- pos,
222263
- pageIndex,
222264
- column: determineColumn(layout, fragment2.x),
222265
- lineIndex: -1,
222266
- origin: "atomic-fragment-hit"
222267
- });
222268
222403
  return {
222269
222404
  pos,
222270
222405
  layoutEpoch,
@@ -222291,15 +222426,7 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222291
222426
  const isListItem$1 = (cellMeasure.marker?.markerWidth ?? 0) > 0;
222292
222427
  const isJustified = cellBlock.attrs?.alignment === "justify";
222293
222428
  const pos = mapPointToPm(cellBlock, line, localX, isRTL, availableWidth, isListItem$1 && !isJustified ? "left" : undefined);
222294
- if (pos != null) {
222295
- logClickStage("log", "success", {
222296
- blockId: tableHit.fragment.blockId,
222297
- pos,
222298
- pageIndex,
222299
- column: determineColumn(layout, tableHit.fragment.x),
222300
- lineIndex,
222301
- origin: "table-cell"
222302
- });
222429
+ if (pos != null)
222303
222430
  return {
222304
222431
  pos,
222305
222432
  layoutEpoch,
@@ -222308,18 +222435,9 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222308
222435
  column: determineColumn(layout, tableHit.fragment.x),
222309
222436
  lineIndex
222310
222437
  };
222311
- }
222312
222438
  }
222313
222439
  const firstRun = cellBlock.runs?.[0];
222314
- if (firstRun && firstRun.pmStart != null) {
222315
- logClickStage("log", "success", {
222316
- blockId: tableHit.fragment.blockId,
222317
- pos: firstRun.pmStart,
222318
- pageIndex,
222319
- column: determineColumn(layout, tableHit.fragment.x),
222320
- lineIndex: 0,
222321
- origin: "table-cell-fallback"
222322
- });
222440
+ if (firstRun && firstRun.pmStart != null)
222323
222441
  return {
222324
222442
  pos: firstRun.pmStart,
222325
222443
  layoutEpoch,
@@ -222328,30 +222446,14 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222328
222446
  column: determineColumn(layout, tableHit.fragment.x),
222329
222447
  lineIndex: 0
222330
222448
  };
222331
- }
222332
- logClickStage("warn", "table-cell-no-position", {
222333
- blockId: tableHit.fragment.blockId,
222334
- cellRow: tableHit.cellRowIndex,
222335
- cellCol: tableHit.cellColIndex
222336
- });
222337
222449
  }
222338
222450
  const atomicHit = hitTestAtomicFragment(pageHit, blocks2, measures, pageRelativePoint);
222339
222451
  if (atomicHit && isAtomicFragment(atomicHit.fragment)) {
222340
222452
  const { fragment: fragment2, block, pageIndex } = atomicHit;
222341
222453
  const pmRange = getAtomicPmRange(fragment2, block);
222342
222454
  const pos = pmRange.pmStart ?? pmRange.pmEnd ?? null;
222343
- if (pos == null) {
222344
- logClickStage("warn", "atomic-without-range", { fragmentId: fragment2.blockId });
222455
+ if (pos == null)
222345
222456
  return null;
222346
- }
222347
- logClickStage("log", "success", {
222348
- blockId: fragment2.blockId,
222349
- pos,
222350
- pageIndex,
222351
- column: determineColumn(layout, fragment2.x),
222352
- lineIndex: -1,
222353
- origin: "atomic-direct-hit"
222354
- });
222355
222457
  return {
222356
222458
  pos,
222357
222459
  layoutEpoch,
@@ -222361,42 +222463,8 @@ function clickToPosition(layout, blocks2, measures, containerPoint, domContainer
222361
222463
  lineIndex: -1
222362
222464
  };
222363
222465
  }
222364
- logClickStage("warn", "no-fragment", {
222365
- pageIndex: pageHit.pageIndex,
222366
- pageRelativePoint
222367
- });
222368
222466
  return null;
222369
222467
  }
222370
- function findBlockIndexByFragmentId(blocks2, fragmentBlockId, targetPmRange) {
222371
- const index2 = blocks2.findIndex((block) => block.id === fragmentBlockId && block.kind !== "pageBreak" && block.kind !== "sectionBreak");
222372
- if (index2 !== -1)
222373
- return index2;
222374
- const baseBlockId = fragmentBlockId.replace(/-\d+$/, "");
222375
- if (baseBlockId === fragmentBlockId)
222376
- return -1;
222377
- const matchingIndices = [];
222378
- blocks2.forEach((block, idx) => {
222379
- if (block.id === baseBlockId && block.kind === "paragraph")
222380
- matchingIndices.push(idx);
222381
- });
222382
- if (matchingIndices.length === 0)
222383
- return -1;
222384
- if (matchingIndices.length === 1)
222385
- return matchingIndices[0];
222386
- if (targetPmRange)
222387
- for (const idx of matchingIndices) {
222388
- const block = blocks2[idx];
222389
- if (block.kind !== "paragraph")
222390
- continue;
222391
- if (block.runs.some((run2) => {
222392
- if (run2.pmStart == null || run2.pmEnd == null)
222393
- return false;
222394
- return run2.pmEnd > targetPmRange.from && run2.pmStart < targetPmRange.to;
222395
- }))
222396
- return idx;
222397
- }
222398
- return matchingIndices[0];
222399
- }
222400
222468
  function selectionToRects(layout, blocks2, measures, from$1, to, geometryHelper) {
222401
222469
  if (from$1 === to)
222402
222470
  return [];
@@ -222779,7 +222847,7 @@ function pmPosToCharOffset(block, line, pmPos) {
222779
222847
  const run2 = block.runs[runIndex];
222780
222848
  if (!run2)
222781
222849
  continue;
222782
- const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
222850
+ const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math" ? "" : run2.text ?? "";
222783
222851
  const runTextLength = text5.length;
222784
222852
  const runPmStart = run2.pmStart ?? null;
222785
222853
  const runPmEnd = run2.pmEnd ?? (runPmStart != null ? runPmStart + runTextLength : null);
@@ -224953,6 +225021,31 @@ function citationNodeToRun(params$1) {
224953
225021
  function authorityEntryNodeToRun(_params) {
224954
225022
  return null;
224955
225023
  }
225024
+ function estimateMathDimensions(textContent$1) {
225025
+ return {
225026
+ width: Math.max(textContent$1.length * 10, 20),
225027
+ height: 24
225028
+ };
225029
+ }
225030
+ function mathInlineNodeToRun({ node: node3, positions, sdtMetadata }) {
225031
+ const textContent$1 = String(node3.attrs?.textContent ?? "");
225032
+ const { width, height } = estimateMathDimensions(textContent$1);
225033
+ const run2 = {
225034
+ kind: "math",
225035
+ ommlJson: node3.attrs?.originalXml ?? null,
225036
+ textContent: textContent$1,
225037
+ width,
225038
+ height
225039
+ };
225040
+ const pos = positions.get(node3);
225041
+ if (pos) {
225042
+ run2.pmStart = pos.start;
225043
+ run2.pmEnd = pos.end;
225044
+ }
225045
+ if (sdtMetadata)
225046
+ run2.sdt = sdtMetadata;
225047
+ return run2;
225048
+ }
224956
225049
  function lineBreakNodeToRun({ node: node3, positions, sdtMetadata }) {
224957
225050
  const attrs = node3.attrs ?? {};
224958
225051
  const breakType = attrs.pageBreakType ?? attrs.lineBreakType ?? "line";
@@ -225857,6 +225950,30 @@ function handleParagraphNode2(node3, context) {
225857
225950
  });
225858
225951
  sectionState.currentParagraphIndex++;
225859
225952
  }
225953
+ function handleMathBlockNode(node3, context) {
225954
+ const { blocks: blocks2, recordBlockKind, nextBlockId, positions } = context;
225955
+ const textContent$1 = String(node3.attrs?.textContent ?? "");
225956
+ const justification = String(node3.attrs?.justification ?? "centerGroup");
225957
+ const { width, height } = estimateMathDimensions(textContent$1);
225958
+ const pos = positions.get(node3);
225959
+ const mathRun = {
225960
+ kind: "math",
225961
+ ommlJson: node3.attrs?.originalXml ?? null,
225962
+ textContent: textContent$1,
225963
+ width,
225964
+ height,
225965
+ pmStart: pos?.start,
225966
+ pmEnd: pos?.end
225967
+ };
225968
+ const block = {
225969
+ kind: "paragraph",
225970
+ id: nextBlockId("paragraph"),
225971
+ runs: [mathRun],
225972
+ attrs: { alignment: JUSTIFICATION_TO_ALIGN[justification] ?? "center" }
225973
+ };
225974
+ blocks2.push(block);
225975
+ recordBlockKind?.(block.kind);
225976
+ }
225860
225977
  function toFlowBlocks(pmDoc, options) {
225861
225978
  const defaultFont = options?.defaultFont ?? DEFAULT_FONT;
225862
225979
  const defaultSize = options?.defaultSize ?? DEFAULT_SIZE2;
@@ -226382,6 +226499,68 @@ function renderRemoteSelection(options) {
226382
226499
  });
226383
226500
  options.renderCaret();
226384
226501
  }
226502
+ function clickToPositionDom(domContainer, clientX, clientY) {
226503
+ return clickToPositionDom$1(domContainer, clientX, clientY);
226504
+ }
226505
+ function findPageElement(domContainer, clientX, clientY) {
226506
+ return findPageElement$1(domContainer, clientX, clientY);
226507
+ }
226508
+ function readLayoutEpochFromDom(domContainer, clientX, clientY) {
226509
+ const doc$12 = domContainer.ownerDocument ?? (typeof document !== "undefined" ? document : null);
226510
+ if (!doc$12 || typeof doc$12.elementsFromPoint !== "function")
226511
+ return null;
226512
+ let hitChain = [];
226513
+ try {
226514
+ hitChain = doc$12.elementsFromPoint(clientX, clientY) ?? [];
226515
+ } catch {
226516
+ return null;
226517
+ }
226518
+ let latestEpoch = null;
226519
+ for (const el of hitChain) {
226520
+ if (!(el instanceof HTMLElement))
226521
+ continue;
226522
+ if (!domContainer.contains(el))
226523
+ continue;
226524
+ const raw = el.dataset.layoutEpoch;
226525
+ if (raw == null)
226526
+ continue;
226527
+ const epoch = Number(raw);
226528
+ if (!Number.isFinite(epoch))
226529
+ continue;
226530
+ if (latestEpoch == null || epoch > latestEpoch)
226531
+ latestEpoch = epoch;
226532
+ }
226533
+ return latestEpoch;
226534
+ }
226535
+ function resolvePointerPositionHit(options) {
226536
+ const { layout, blocks: blocks2, measures, containerPoint, domContainer, clientX, clientY, geometryHelper } = options;
226537
+ const layoutEpoch = layout.layoutEpoch ?? 0;
226538
+ if (domContainer != null && clientX != null && clientY != null) {
226539
+ const domPos = clickToPositionDom(domContainer, clientX, clientY);
226540
+ const domLayoutEpoch = readLayoutEpochFromDom(domContainer, clientX, clientY) ?? layoutEpoch;
226541
+ if (domPos != null)
226542
+ return resolvePositionHitFromDomPosition(layout, blocks2, measures, domPos, domLayoutEpoch);
226543
+ const pageEl = findPageElement(domContainer, clientX, clientY);
226544
+ if (pageEl) {
226545
+ const domPageIndex = Number(pageEl.dataset.pageIndex ?? "NaN");
226546
+ if (Number.isFinite(domPageIndex) && domPageIndex >= 0 && domPageIndex < layout.pages.length) {
226547
+ const page = layout.pages[domPageIndex];
226548
+ const pageRect = pageEl.getBoundingClientRect();
226549
+ const layoutPageHeight = page.size?.h ?? layout.pageSize.h;
226550
+ const domPageHeight = pageRect.height;
226551
+ const effectiveZoom = domPageHeight > 0 && layoutPageHeight > 0 ? domPageHeight / layoutPageHeight : 1;
226552
+ return clickToPositionGeometry(layout, blocks2, measures, containerPoint, {
226553
+ geometryHelper,
226554
+ pageHint: {
226555
+ pageIndex: domPageIndex,
226556
+ pageRelativeY: (clientY - pageRect.top) / effectiveZoom
226557
+ }
226558
+ });
226559
+ }
226560
+ }
226561
+ }
226562
+ return clickToPositionGeometry(layout, blocks2, measures, containerPoint, { geometryHelper });
226563
+ }
226385
226564
  function getCellPosFromTableHit(tableHit, doc$12, blocks2) {
226386
226565
  if (!tableHit || !tableHit.block || typeof tableHit.block.id !== "string") {
226387
226566
  console.warn("[getCellPosFromTableHit] Invalid tableHit input:", tableHit);
@@ -236525,7 +236704,7 @@ var Node$13 = class Node$14 {
236525
236704
  update() {
236526
236705
  return false;
236527
236706
  }
236528
- }, ShapeGroup, CHART_IMMUTABILITY_KEY, chartPositionCache, Chart, sharedAttributes$2 = () => ({
236707
+ }, ShapeGroup, CHART_IMMUTABILITY_KEY, chartPositionCache, Chart, MathInline, MathBlock, sharedAttributes$2 = () => ({
236529
236708
  originalName: { default: null },
236530
236709
  originalXml: { default: null }
236531
236710
  }), hiddenRender = (type) => ["sd-passthrough", {
@@ -241892,7 +242071,34 @@ var Node$13 = class Node$14 {
241892
242071
  }
241893
242072
  element3.style.textAlign = resolveTextAlign(attrs?.alignment, rtl);
241894
242073
  return rtl;
241895
- }, shouldUseSegmentPositioning = (hasExplicitPositioning, hasSegments, isRtl) => hasExplicitPositioning && hasSegments && !isRtl, cssToken = (varName, fallback) => ({
242074
+ }, shouldUseSegmentPositioning = (hasExplicitPositioning, hasSegments, isRtl) => hasExplicitPositioning && hasSegments && !isRtl, MATHML_NS$2 = "http://www.w3.org/1998/Math/MathML", OPERATOR_CHARS, convertMathRun = (node3, doc$12) => {
242075
+ const elements = node3.elements ?? [];
242076
+ let text5 = "";
242077
+ for (const child of elements)
242078
+ if (child.name === "m:t") {
242079
+ const textChildren = child.elements ?? [];
242080
+ for (const tc of textChildren)
242081
+ if (tc.type === "text" && typeof tc.text === "string")
242082
+ text5 += tc.text;
242083
+ }
242084
+ if (!text5)
242085
+ return null;
242086
+ const isNormalText = elements.find((el$1) => el$1.name === "m:rPr")?.elements?.some((el$1) => el$1.name === "m:nor") ?? false;
242087
+ const tag = classifyMathText(text5);
242088
+ const el = doc$12.createElementNS(MATHML_NS$2, tag);
242089
+ el.textContent = text5;
242090
+ if (tag === "mi" && isNormalText)
242091
+ el.setAttribute("mathvariant", "normal");
242092
+ return el;
242093
+ }, MATHML_NS$1 = "http://www.w3.org/1998/Math/MathML", convertFraction = (node3, doc$12, convertChildren) => {
242094
+ const elements = node3.elements ?? [];
242095
+ const num = elements.find((e) => e.name === "m:num");
242096
+ const den = elements.find((e) => e.name === "m:den");
242097
+ const frac = doc$12.createElementNS(MATHML_NS$1, "mfrac");
242098
+ frac.appendChild(convertChildren(num?.elements ?? []));
242099
+ frac.appendChild(convertChildren(den?.elements ?? []));
242100
+ return frac;
242101
+ }, MATHML_NS = "http://www.w3.org/1998/Math/MathML", MATH_OBJECT_REGISTRY, ARGUMENT_ELEMENTS, cssToken = (varName, fallback) => ({
241896
242102
  css: `var(${varName}, ${fallback})`,
241897
242103
  fallback
241898
242104
  }), 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) => {
@@ -242471,7 +242677,7 @@ var Node$13 = class Node$14 {
242471
242677
  }
242472
242678
  return block.id;
242473
242679
  }, applyRunStyles = (element3, run2, _isLink = false) => {
242474
- if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation")
242680
+ if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
242475
242681
  return;
242476
242682
  element3.style.fontFamily = run2.fontFamily;
242477
242683
  element3.style.fontSize = `${run2.fontSize}px`;
@@ -242905,6 +243111,8 @@ var Node$13 = class Node$14 {
242905
243111
  Image,
242906
243112
  NodeResizer,
242907
243113
  CustomSelection,
243114
+ MathInline,
243115
+ MathBlock,
242908
243116
  PassthroughInline,
242909
243117
  PassthroughBlock
242910
243118
  ];
@@ -243001,6 +243209,8 @@ var Node$13 = class Node$14 {
243001
243209
  PermissionRanges,
243002
243210
  Protection,
243003
243211
  VerticalNavigation,
243212
+ MathInline,
243213
+ MathBlock,
243004
243214
  PassthroughInline,
243005
243215
  PassthroughBlock,
243006
243216
  Diffing
@@ -246336,7 +246546,7 @@ var Node$13 = class Node$14 {
246336
246546
  let totalSpaces = line.spaceCount ?? 0;
246337
246547
  if (totalSpaces === 0)
246338
246548
  totalSpaces = sliceRunsForLine(block, line).reduce((sum, run2) => {
246339
- if (isTabRun(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation")
246549
+ if (isTabRun(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" || run2.kind === "math")
246340
246550
  return sum;
246341
246551
  return sum + countSpaces(run2.text ?? "");
246342
246552
  }, 0);
@@ -246695,6 +246905,8 @@ var Node$13 = class Node$14 {
246695
246905
  }
246696
246906
  if (run2.kind === "fieldAnnotation")
246697
246907
  return `fa:${fieldAnnotationKey(run2)}`;
246908
+ if (run2.kind === "math")
246909
+ return `math:${run2.textContent}:${run2.width}:${run2.height}`;
246698
246910
  const text5 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? "";
246699
246911
  const marks = hashRunVisualMarks(run2);
246700
246912
  let trackedKey = "";
@@ -247424,6 +247636,15 @@ var Node$13 = class Node$14 {
247424
247636
  for (let i4 = 0;i4 < a2.runs.length; i4 += 1) {
247425
247637
  const runA = a2.runs[i4];
247426
247638
  const runB = b$1.runs[i4];
247639
+ if (runA.kind === "math" || runB.kind === "math") {
247640
+ if (runA.kind !== runB.kind)
247641
+ return false;
247642
+ if (runA.kind === "math" && runB.kind === "math") {
247643
+ if (runA.textContent !== runB.textContent)
247644
+ return false;
247645
+ }
247646
+ continue;
247647
+ }
247427
247648
  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))
247428
247649
  return false;
247429
247650
  }
@@ -248291,7 +248512,7 @@ var Node$13 = class Node$14 {
248291
248512
  }
248292
248513
  }, isAtomicFragment = (fragment2) => {
248293
248514
  return fragment2.kind === "drawing" || fragment2.kind === "image";
248294
- }, logClickStage = (_level, _stage, _payload) => {}, logPositionDebug = (payload) => {}, logSelectionMapDebug = (payload) => {}, blockPmRangeFromAttrs = (block) => {
248515
+ }, blockPmRangeFromAttrs = (block) => {
248295
248516
  const attrs = block?.attrs;
248296
248517
  const pmStart = typeof attrs?.pmStart === "number" ? attrs.pmStart : undefined;
248297
248518
  return {
@@ -248303,10 +248524,65 @@ var Node$13 = class Node$14 {
248303
248524
  pmStart: typeof fragment2.pmStart === "number" ? fragment2.pmStart : blockPmRangeFromAttrs(block).pmStart,
248304
248525
  pmEnd: typeof fragment2.pmEnd === "number" ? fragment2.pmEnd : blockPmRangeFromAttrs(block).pmEnd
248305
248526
  };
248306
- }, rangesOverlap = (startA, endA, startB, endB) => {
248307
- if (startA == null)
248527
+ }, isRtlBlock = (block) => {
248528
+ if (block.kind !== "paragraph")
248308
248529
  return false;
248309
- return (endA ?? startA + 1) > startB && startA < endB;
248530
+ const attrs = block.attrs;
248531
+ if (!attrs)
248532
+ return false;
248533
+ const directionAttr = attrs.direction ?? attrs.dir ?? attrs.textDirection;
248534
+ if (typeof directionAttr === "string" && directionAttr.toLowerCase() === "rtl")
248535
+ return true;
248536
+ if (typeof attrs.rtl === "boolean")
248537
+ return attrs.rtl;
248538
+ return false;
248539
+ }, determineColumn = (layout, fragmentX) => {
248540
+ const columns = layout.columns;
248541
+ if (!columns || columns.count <= 1)
248542
+ return 0;
248543
+ const span = (layout.pageSize.w - columns.gap * (columns.count - 1)) / columns.count + columns.gap;
248544
+ const relative = fragmentX;
248545
+ const raw = Math.floor(relative / Math.max(span, 1));
248546
+ return Math.max(0, Math.min(columns.count - 1, raw));
248547
+ }, findLineIndexAtY = (lines, offsetY, fromLine, toLine) => {
248548
+ if (!lines || lines.length === 0)
248549
+ return null;
248550
+ const lineCount = lines.length;
248551
+ if (fromLine < 0 || toLine > lineCount || fromLine >= toLine)
248552
+ return null;
248553
+ let cursor = 0;
248554
+ for (let i4 = fromLine;i4 < toLine; i4 += 1) {
248555
+ const line = lines[i4];
248556
+ if (!line)
248557
+ return null;
248558
+ const next2 = cursor + line.lineHeight;
248559
+ if (offsetY >= cursor && offsetY < next2)
248560
+ return i4;
248561
+ cursor = next2;
248562
+ }
248563
+ return toLine - 1;
248564
+ }, mapPointToPm = (block, line, x, isRTL, availableWidthOverride, alignmentOverride) => {
248565
+ if (block.kind !== "paragraph")
248566
+ return null;
248567
+ const range = computeLinePmRange$1(block, line);
248568
+ if (range.pmStart == null || range.pmEnd == null)
248569
+ return null;
248570
+ const result = findCharacterAtX(block, line, x, range.pmStart, availableWidthOverride, alignmentOverride);
248571
+ let pmPosition = result.pmPosition;
248572
+ if (isRTL) {
248573
+ const charOffset = result.charOffset;
248574
+ const charsInLine = Math.max(1, line.toChar - line.fromChar);
248575
+ pmPosition = charOffsetToPm(block, line, Math.max(0, Math.min(charsInLine, charsInLine - charOffset)), range.pmStart);
248576
+ }
248577
+ return pmPosition;
248578
+ }, calculatePageTopFallback = (layout, pageIndex) => {
248579
+ const pageGap = layout.pageGap ?? 0;
248580
+ let y$1 = 0;
248581
+ for (let i4 = 0;i4 < pageIndex; i4++) {
248582
+ const pageHeight = layout.pages[i4]?.size?.h ?? layout.pageSize.h;
248583
+ y$1 += pageHeight + pageGap;
248584
+ }
248585
+ return y$1;
248310
248586
  }, hitTestAtomicFragment = (pageHit, blocks2, measures, point5) => {
248311
248587
  for (const fragment2 of pageHit.page.fragments) {
248312
248588
  if (!isAtomicFragment(fragment2))
@@ -248455,32 +248731,10 @@ var Node$13 = class Node$14 {
248455
248731
  }
248456
248732
  }
248457
248733
  return null;
248458
- }, readLayoutEpochFromDom = (domContainer, clientX, clientY) => {
248459
- const doc$12 = domContainer.ownerDocument ?? (typeof document !== "undefined" ? document : null);
248460
- if (!doc$12 || typeof doc$12.elementsFromPoint !== "function")
248461
- return null;
248462
- let hitChain = [];
248463
- try {
248464
- hitChain = doc$12.elementsFromPoint(clientX, clientY) ?? [];
248465
- } catch {
248466
- return null;
248467
- }
248468
- let latestEpoch = null;
248469
- for (const el of hitChain) {
248470
- if (!(el instanceof HTMLElement))
248471
- continue;
248472
- if (!domContainer.contains(el))
248473
- continue;
248474
- const raw = el.dataset.layoutEpoch;
248475
- if (raw == null)
248476
- continue;
248477
- const epoch = Number(raw);
248478
- if (!Number.isFinite(epoch))
248479
- continue;
248480
- if (latestEpoch == null || epoch > latestEpoch)
248481
- latestEpoch = epoch;
248482
- }
248483
- return latestEpoch;
248734
+ }, logSelectionMapDebug = (payload) => {}, rangesOverlap = (startA, endA, startB, endB) => {
248735
+ if (startA == null)
248736
+ return false;
248737
+ return (endA ?? startA + 1) > startB && startA < endB;
248484
248738
  }, DEFAULT_CELL_PADDING, getCellPaddingFromRow = (cellIdx, row2) => {
248485
248739
  const padding = row2?.cells?.[cellIdx]?.attrs?.padding ?? {};
248486
248740
  return {
@@ -248512,39 +248766,6 @@ var Node$13 = class Node$14 {
248512
248766
  for (let i4 = fromLine;i4 < toLine && i4 < measure.lines.length; i4 += 1)
248513
248767
  height += measure.lines[i4]?.lineHeight ?? 0;
248514
248768
  return height;
248515
- }, calculatePageTopFallback = (layout, pageIndex) => {
248516
- const pageGap = layout.pageGap ?? 0;
248517
- let y$1 = 0;
248518
- for (let i4 = 0;i4 < pageIndex; i4++) {
248519
- const pageHeight = layout.pages[i4]?.size?.h ?? layout.pageSize.h;
248520
- y$1 += pageHeight + pageGap;
248521
- }
248522
- return y$1;
248523
- }, determineColumn = (layout, fragmentX) => {
248524
- const columns = layout.columns;
248525
- if (!columns || columns.count <= 1)
248526
- return 0;
248527
- const span = (layout.pageSize.w - columns.gap * (columns.count - 1)) / columns.count + columns.gap;
248528
- const relative = fragmentX;
248529
- const raw = Math.floor(relative / Math.max(span, 1));
248530
- return Math.max(0, Math.min(columns.count - 1, raw));
248531
- }, findLineIndexAtY = (lines, offsetY, fromLine, toLine) => {
248532
- if (!lines || lines.length === 0)
248533
- return null;
248534
- const lineCount = lines.length;
248535
- if (fromLine < 0 || toLine > lineCount || fromLine >= toLine)
248536
- return null;
248537
- let cursor = 0;
248538
- for (let i4 = fromLine;i4 < toLine; i4 += 1) {
248539
- const line = lines[i4];
248540
- if (!line)
248541
- return null;
248542
- const next2 = cursor + line.lineHeight;
248543
- if (offsetY >= cursor && offsetY < next2)
248544
- return i4;
248545
- cursor = next2;
248546
- }
248547
- return toLine - 1;
248548
248769
  }, lineHeightBeforeIndex$1 = (measure, absoluteLineIndex) => {
248549
248770
  if (measure.kind !== "paragraph")
248550
248771
  return 0;
@@ -248552,20 +248773,6 @@ var Node$13 = class Node$14 {
248552
248773
  for (let i4 = 0;i4 < absoluteLineIndex; i4 += 1)
248553
248774
  height += measure.lines[i4]?.lineHeight ?? 0;
248554
248775
  return height;
248555
- }, mapPointToPm = (block, line, x, isRTL, availableWidthOverride, alignmentOverride) => {
248556
- if (block.kind !== "paragraph")
248557
- return null;
248558
- const range = computeLinePmRange(block, line);
248559
- if (range.pmStart == null || range.pmEnd == null)
248560
- return null;
248561
- const result = findCharacterAtX(block, line, x, range.pmStart, availableWidthOverride, alignmentOverride);
248562
- let pmPosition = result.pmPosition;
248563
- if (isRTL) {
248564
- const charOffset = result.charOffset;
248565
- const charsInLine = Math.max(1, line.toChar - line.fromChar);
248566
- pmPosition = charOffsetToPm(block, line, Math.max(0, Math.min(charsInLine, charsInLine - charOffset)), range.pmStart);
248567
- }
248568
- return pmPosition;
248569
248776
  }, mapPmToX = (block, line, offset$1, fragmentWidth, alignmentOverride) => {
248570
248777
  if (fragmentWidth <= 0 || line.width <= 0)
248571
248778
  return 0;
@@ -248590,18 +248797,6 @@ var Node$13 = class Node$14 {
248590
248797
  if (totalIndent > fragmentWidth)
248591
248798
  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.`);
248592
248799
  return measureCharacterX(block, line, offset$1, availableWidth, alignmentOverride);
248593
- }, isRtlBlock = (block) => {
248594
- if (block.kind !== "paragraph")
248595
- return false;
248596
- const attrs = block.attrs;
248597
- if (!attrs)
248598
- return false;
248599
- const directionAttr = attrs.direction ?? attrs.dir ?? attrs.textDirection;
248600
- if (typeof directionAttr === "string" && directionAttr.toLowerCase() === "rtl")
248601
- return true;
248602
- if (typeof attrs.rtl === "boolean")
248603
- return attrs.rtl;
248604
- return false;
248605
248800
  }, WORD_CHARACTER_REGEX, EpochPositionMapper = class {
248606
248801
  #currentEpoch = 0;
248607
248802
  #mapsByFromEpoch = /* @__PURE__ */ new Map;
@@ -251203,7 +251398,7 @@ var Node$13 = class Node$14 {
251203
251398
  return;
251204
251399
  updateGhostListMarkerOffsets(node3, paragraphBlocks, context);
251205
251400
  applyGhostListMarkerOffsets(node3, paragraphBlocks, context);
251206
- }, 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 {
251401
+ }, 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 {
251207
251402
  #options;
251208
251403
  #remoteCursorState = /* @__PURE__ */ new Map;
251209
251404
  #remoteCursorElements = /* @__PURE__ */ new Map;
@@ -251936,10 +252131,19 @@ var Node$13 = class Node$14 {
251936
252131
  }
251937
252132
  const viewportHost = this.#deps.getViewportHost();
251938
252133
  const pageGeometryHelper = this.#deps.getPageGeometryHelper();
251939
- const rawHit = clickToPosition(layoutState.layout, layoutState.blocks, layoutState.measures, {
251940
- x,
251941
- y: y$1
251942
- }, viewportHost, event.clientX, event.clientY, pageGeometryHelper ?? undefined);
252134
+ const rawHit = resolvePointerPositionHit({
252135
+ layout: layoutState.layout,
252136
+ blocks: layoutState.blocks,
252137
+ measures: layoutState.measures,
252138
+ containerPoint: {
252139
+ x,
252140
+ y: y$1
252141
+ },
252142
+ domContainer: viewportHost,
252143
+ clientX: event.clientX,
252144
+ clientY: event.clientY,
252145
+ geometryHelper: pageGeometryHelper ?? undefined
252146
+ });
251943
252147
  const doc$12 = editor.state?.doc;
251944
252148
  const epochMapper = this.#deps.getEpochMapper();
251945
252149
  const mapped = rawHit && doc$12 ? epochMapper.mapPosFromLayoutToCurrentDetailed(rawHit.pos, rawHit.layoutEpoch, 1) : null;
@@ -252535,10 +252739,19 @@ var Node$13 = class Node$14 {
252535
252739
  };
252536
252740
  const viewportHost = this.#deps.getViewportHost();
252537
252741
  const pageGeometryHelper = this.#deps.getPageGeometryHelper();
252538
- const rawHit = clickToPosition(layoutState.layout, layoutState.blocks, layoutState.measures, {
252539
- x: normalized.x,
252540
- y: normalized.y
252541
- }, viewportHost, clientX, clientY, pageGeometryHelper ?? undefined);
252742
+ const rawHit = resolvePointerPositionHit({
252743
+ layout: layoutState.layout,
252744
+ blocks: layoutState.blocks,
252745
+ measures: layoutState.measures,
252746
+ containerPoint: {
252747
+ x: normalized.x,
252748
+ y: normalized.y
252749
+ },
252750
+ domContainer: viewportHost,
252751
+ clientX,
252752
+ clientY,
252753
+ geometryHelper: pageGeometryHelper ?? undefined
252754
+ });
252542
252755
  if (!rawHit)
252543
252756
  return;
252544
252757
  if (isFootnoteBlockId(rawHit.blockId))
@@ -254879,9 +255092,9 @@ var Node$13 = class Node$14 {
254879
255092
  return;
254880
255093
  console.log(...args$1);
254881
255094
  }, 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;
254882
- var init_src_BrtcDgR1_es = __esm(() => {
255095
+ var init_src_0P3ZlqDX_es = __esm(() => {
254883
255096
  init_rolldown_runtime_B2q5OVn9_es();
254884
- init_SuperConverter_CYbYOJeZ_es();
255097
+ init_SuperConverter_B9oNf3OB_es();
254885
255098
  init_jszip_ChlR43oI_es();
254886
255099
  init_uuid_qzgm05fK_es();
254887
255100
  init_constants_CIF8yzNk_es();
@@ -264882,6 +265095,63 @@ ${err.toString()}`);
264882
265095
  return [createChartImmutabilityPlugin()];
264883
265096
  }
264884
265097
  });
265098
+ MathInline = Node$13.create({
265099
+ name: "mathInline",
265100
+ group: "inline",
265101
+ inline: true,
265102
+ atom: true,
265103
+ marks: "",
265104
+ draggable: false,
265105
+ selectable: true,
265106
+ parseDOM() {
265107
+ return [{ tag: "sd-math-inline" }];
265108
+ },
265109
+ renderDOM() {
265110
+ return ["sd-math-inline", { style: "display: inline;" }];
265111
+ },
265112
+ addAttributes() {
265113
+ return {
265114
+ originalXml: {
265115
+ default: null,
265116
+ rendered: false
265117
+ },
265118
+ textContent: {
265119
+ default: "",
265120
+ rendered: false
265121
+ }
265122
+ };
265123
+ }
265124
+ });
265125
+ MathBlock = Node$13.create({
265126
+ name: "mathBlock",
265127
+ group: "block",
265128
+ atom: true,
265129
+ draggable: false,
265130
+ selectable: true,
265131
+ defining: true,
265132
+ parseDOM() {
265133
+ return [{ tag: "sd-math-block" }];
265134
+ },
265135
+ renderDOM() {
265136
+ return ["sd-math-block", { style: "display: block; text-align: center;" }];
265137
+ },
265138
+ addAttributes() {
265139
+ return {
265140
+ originalXml: {
265141
+ default: null,
265142
+ rendered: false
265143
+ },
265144
+ textContent: {
265145
+ default: "",
265146
+ rendered: false
265147
+ },
265148
+ justification: {
265149
+ default: "centerGroup",
265150
+ rendered: false
265151
+ }
265152
+ };
265153
+ }
265154
+ });
264885
265155
  PassthroughBlock = Node$13.create({
264886
265156
  name: "passthroughBlock",
264887
265157
  group: "block",
@@ -273159,6 +273429,7 @@ function print() { __p += __j.call(arguments, '') }
273159
273429
  "indexEntry",
273160
273430
  "tab",
273161
273431
  "footnoteReference",
273432
+ "mathInline",
273162
273433
  "passthroughInline",
273163
273434
  "bookmarkEnd",
273164
273435
  "fieldAnnotation",
@@ -273210,6 +273481,100 @@ function print() { __p += __j.call(arguments, '') }
273210
273481
  ]);
273211
273482
  SDT_BLOCK_SELECTOR = `.${DOM_CLASS_NAMES.BLOCK_SDT}[data-sdt-id]`;
273212
273483
  HOVER_CLASS = DOM_CLASS_NAMES.SDT_HOVER;
273484
+ OPERATOR_CHARS = new Set([
273485
+ "+",
273486
+ "-",
273487
+ "=",
273488
+ "<",
273489
+ ">",
273490
+ "(",
273491
+ ")",
273492
+ "[",
273493
+ "]",
273494
+ "{",
273495
+ "}",
273496
+ "|",
273497
+ "/",
273498
+ "\\",
273499
+ ",",
273500
+ ".",
273501
+ ";",
273502
+ ":",
273503
+ "!",
273504
+ "~",
273505
+ "^",
273506
+ "_",
273507
+ "±",
273508
+ "×",
273509
+ "÷",
273510
+ "←",
273511
+ "↑",
273512
+ "→",
273513
+ "↓",
273514
+ "↔",
273515
+ "∀",
273516
+ "∁",
273517
+ "∂",
273518
+ "∃",
273519
+ "∄",
273520
+ "∅",
273521
+ "∈",
273522
+ "∉",
273523
+ "∋",
273524
+ "∌",
273525
+ "∑",
273526
+ "∏",
273527
+ "√",
273528
+ "∞",
273529
+ "∧",
273530
+ "∨",
273531
+ "∩",
273532
+ "∪",
273533
+ "∫",
273534
+ "∬",
273535
+ "∭",
273536
+ "≠",
273537
+ "≡",
273538
+ "≤",
273539
+ "≥",
273540
+ "⊂",
273541
+ "⊃",
273542
+ "⊆",
273543
+ "⊇"
273544
+ ]);
273545
+ MATH_OBJECT_REGISTRY = {
273546
+ "m:r": convertMathRun,
273547
+ "m:acc": null,
273548
+ "m:bar": null,
273549
+ "m:borderBox": null,
273550
+ "m:box": null,
273551
+ "m:d": null,
273552
+ "m:eqArr": null,
273553
+ "m:f": convertFraction,
273554
+ "m:func": null,
273555
+ "m:groupChr": null,
273556
+ "m:limLow": null,
273557
+ "m:limUpp": null,
273558
+ "m:m": null,
273559
+ "m:nary": null,
273560
+ "m:phant": null,
273561
+ "m:rad": null,
273562
+ "m:sPre": null,
273563
+ "m:sSub": null,
273564
+ "m:sSubSup": null,
273565
+ "m:sSup": null
273566
+ };
273567
+ ARGUMENT_ELEMENTS = new Set([
273568
+ "m:e",
273569
+ "m:num",
273570
+ "m:den",
273571
+ "m:sub",
273572
+ "m:sup",
273573
+ "m:deg",
273574
+ "m:lim",
273575
+ "m:fName",
273576
+ "m:oMath"
273577
+ ]);
273213
273578
  init_dist4();
273214
273579
  COMMENT_HIGHLIGHT_EXTERNAL = cssToken("--sd-comments-highlight-external", "#B1124B40");
273215
273580
  COMMENT_HIGHLIGHT_EXTERNAL_ACTIVE = cssToken("--sd-comments-highlight-external-active", "#B1124B66");
@@ -275379,7 +275744,7 @@ function print() { __p += __j.call(arguments, '') }
275379
275744
  });
275380
275745
  }
275381
275746
  extractLinkData(run2) {
275382
- if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak")
275747
+ if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak" || run2.kind === "math")
275383
275748
  return null;
275384
275749
  const link2 = run2.link;
275385
275750
  if (!link2)
@@ -275523,11 +275888,37 @@ function print() { __p += __j.call(arguments, '') }
275523
275888
  isFieldAnnotationRun(run2) {
275524
275889
  return run2.kind === "fieldAnnotation";
275525
275890
  }
275891
+ isMathRun(run2) {
275892
+ return run2.kind === "math";
275893
+ }
275894
+ renderMathRun(run2) {
275895
+ if (!this.doc)
275896
+ return null;
275897
+ const wrapper = this.doc.createElement("span");
275898
+ wrapper.className = "sd-math";
275899
+ wrapper.style.display = "inline-block";
275900
+ wrapper.style.verticalAlign = "middle";
275901
+ wrapper.style.width = `${run2.width}px`;
275902
+ wrapper.style.height = `${run2.height}px`;
275903
+ wrapper.dataset.layoutEpoch = String(this.layoutEpoch ?? 0);
275904
+ const mathEl = convertOmmlToMathml(run2.ommlJson, this.doc);
275905
+ if (mathEl)
275906
+ wrapper.appendChild(mathEl);
275907
+ else
275908
+ wrapper.textContent = run2.textContent || "";
275909
+ if (run2.pmStart != null)
275910
+ wrapper.dataset.pmStart = String(run2.pmStart);
275911
+ if (run2.pmEnd != null)
275912
+ wrapper.dataset.pmEnd = String(run2.pmEnd);
275913
+ return wrapper;
275914
+ }
275526
275915
  renderRun(run2, context, trackedConfig) {
275527
275916
  if (this.isImageRun(run2))
275528
275917
  return this.renderImageRun(run2);
275529
275918
  if (this.isFieldAnnotationRun(run2))
275530
275919
  return this.renderFieldAnnotationRun(run2);
275920
+ if (this.isMathRun(run2))
275921
+ return this.renderMathRun(run2);
275531
275922
  if (this.isLineBreakRun(run2))
275532
275923
  return null;
275533
275924
  if (this.isBreakRun(run2))
@@ -276279,6 +276670,22 @@ function print() { __p += __j.call(arguments, '') }
276279
276670
  }
276280
276671
  continue;
276281
276672
  }
276673
+ if (this.isMathRun(baseRun)) {
276674
+ const elem = this.renderRun(baseRun, context, trackedConfig);
276675
+ if (elem) {
276676
+ if (styleId)
276677
+ elem.setAttribute("styleid", styleId);
276678
+ const runSegments$1 = segmentsByRun.get(runIndex);
276679
+ const baseSegX = runSegments$1 && runSegments$1[0]?.x !== undefined ? runSegments$1[0].x : cumulativeX;
276680
+ const segX = baseSegX + indentOffset;
276681
+ const segWidth = (runSegments$1 && runSegments$1[0]?.width !== undefined ? runSegments$1[0].width : baseRun.width) ?? 0;
276682
+ elem.style.position = "absolute";
276683
+ elem.style.left = `${segX}px`;
276684
+ appendToLineGeo(elem, baseRun, segX, segWidth);
276685
+ cumulativeX = baseSegX + segWidth;
276686
+ }
276687
+ continue;
276688
+ }
276282
276689
  const runSegments = segmentsByRun.get(runIndex);
276283
276690
  if (!runSegments || runSegments.length === 0)
276284
276691
  continue;
@@ -284266,7 +284673,8 @@ function print() { __p += __j.call(arguments, '') }
284266
284673
  inlineConverter: lineBreakNodeToRun,
284267
284674
  blockConverter: lineBreakNodeToBreakBlock
284268
284675
  },
284269
- table: { blockConverter: tableNodeToBlock }
284676
+ table: { blockConverter: tableNodeToBlock },
284677
+ mathInline: { inlineConverter: mathInlineNodeToRun }
284270
284678
  };
284271
284679
  for (const type of TOKEN_INLINE_TYPES.keys())
284272
284680
  INLINE_CONVERTERS_REGISTRY[type] = { inlineConverter: tokenNodeToRun };
@@ -284277,6 +284685,12 @@ function print() { __p += __j.call(arguments, '') }
284277
284685
  shapeTextbox: shapeTextboxNodeToDrawingBlock,
284278
284686
  chart: chartNodeToDrawingBlock
284279
284687
  };
284688
+ JUSTIFICATION_TO_ALIGN = {
284689
+ center: "center",
284690
+ centerGroup: "center",
284691
+ left: "left",
284692
+ right: "right"
284693
+ };
284280
284694
  DEFAULT_SIZE2 = 10 / 0.75;
284281
284695
  nodeHandlers2 = {
284282
284696
  paragraph: handleParagraphNode2,
@@ -284293,7 +284707,8 @@ function print() { __p += __j.call(arguments, '') }
284293
284707
  shapeGroup: handleShapeGroupNode,
284294
284708
  shapeContainer: handleShapeContainerNode,
284295
284709
  shapeTextbox: handleShapeTextboxNode,
284296
- chart: handleChartNode
284710
+ chart: handleChartNode,
284711
+ mathBlock: handleMathBlockNode
284297
284712
  };
284298
284713
  converters = {
284299
284714
  contentBlockNodeToDrawingBlock,
@@ -285860,11 +286275,20 @@ function print() { __p += __j.call(arguments, '') }
285860
286275
  x: localX,
285861
286276
  y: headerPageIndex * headerPageHeight + (localY - headerPageIndex * headerPageHeight)
285862
286277
  };
285863
- return clickToPosition(context.layout, context.blocks, context.measures, headerPoint, undefined, undefined, undefined, undefined) ?? null;
286278
+ return clickToPositionGeometry(context.layout, context.blocks, context.measures, headerPoint) ?? null;
285864
286279
  }
285865
286280
  if (!this.#layoutState.layout)
285866
286281
  return null;
285867
- const rawHit = clickToPosition(this.#layoutState.layout, this.#layoutState.blocks, this.#layoutState.measures, normalized, this.#viewportHost, clientX, clientY, this.#pageGeometryHelper ?? undefined) ?? null;
286282
+ const rawHit = resolvePointerPositionHit({
286283
+ layout: this.#layoutState.layout,
286284
+ blocks: this.#layoutState.blocks,
286285
+ measures: this.#layoutState.measures,
286286
+ containerPoint: normalized,
286287
+ domContainer: this.#viewportHost,
286288
+ clientX,
286289
+ clientY,
286290
+ geometryHelper: this.#pageGeometryHelper ?? undefined
286291
+ }) ?? null;
285868
286292
  if (!rawHit)
285869
286293
  return null;
285870
286294
  const doc$12 = this.#editor.state?.doc;
@@ -288165,10 +288589,19 @@ function print() { __p += __j.call(arguments, '') }
288165
288589
  includeDragBuffer: false,
288166
288590
  extraPages: dragLastRawHit ? [dragLastRawHit.pageIndex] : undefined
288167
288591
  });
288168
- const refined = clickToPosition(layout, this.#layoutState.blocks, this.#layoutState.measures, {
288169
- x: normalized.x,
288170
- y: normalized.y
288171
- }, this.#viewportHost, pointer.clientX, pointer.clientY, this.#pageGeometryHelper ?? undefined);
288592
+ const refined = resolvePointerPositionHit({
288593
+ layout,
288594
+ blocks: this.#layoutState.blocks,
288595
+ measures: this.#layoutState.measures,
288596
+ containerPoint: {
288597
+ x: normalized.x,
288598
+ y: normalized.y
288599
+ },
288600
+ domContainer: this.#viewportHost,
288601
+ clientX: pointer.clientX,
288602
+ clientY: pointer.clientY,
288603
+ geometryHelper: this.#pageGeometryHelper ?? undefined
288604
+ });
288172
288605
  if (!refined)
288173
288606
  return;
288174
288607
  if (this.#isSelectionAwareVirtualizationEnabled() && this.#getPageElement(refined.pageIndex) == null) {
@@ -288871,8 +289304,8 @@ var init_zipper_YmNpPIyc_es = __esm(() => {
288871
289304
 
288872
289305
  // ../../packages/superdoc/dist/super-editor.es.js
288873
289306
  var init_super_editor_es = __esm(() => {
288874
- init_src_BrtcDgR1_es();
288875
- init_SuperConverter_CYbYOJeZ_es();
289307
+ init_src_0P3ZlqDX_es();
289308
+ init_SuperConverter_B9oNf3OB_es();
288876
289309
  init_jszip_ChlR43oI_es();
288877
289310
  init_xml_js_40FWvL78_es();
288878
289311
  init_constants_CIF8yzNk_es();