@superdoc-dev/cli 0.17.0-next.16 → 0.17.0-next.17

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 +1443 -444
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -68327,7 +68327,7 @@ var init_remark_gfm_BhnWr3yf_es = __esm(() => {
68327
68327
  emptyOptions2 = {};
68328
68328
  });
68329
68329
 
68330
- // ../../packages/superdoc/dist/chunks/SuperConverter-DBlOjc68.es.js
68330
+ // ../../packages/superdoc/dist/chunks/SuperConverter-CUxtXQFf.es.js
68331
68331
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
68332
68332
  const fieldValue = extension$1.config[field];
68333
68333
  if (typeof fieldValue === "function")
@@ -84415,6 +84415,61 @@ function parseStyleId(chartSpace) {
84415
84415
  const val = getAttr(findChild$1(chartSpace, "c:style"), "val");
84416
84416
  return val != null ? Number(val) : undefined;
84417
84417
  }
84418
+ function stripRunNodeMarks(nodes) {
84419
+ if (!Array.isArray(nodes))
84420
+ return nodes;
84421
+ return nodes.map((node3) => {
84422
+ if (!node3 || typeof node3 !== "object")
84423
+ return node3;
84424
+ const stripped = node3.type === "run" && Array.isArray(node3.marks) && node3.marks.length > 0 ? {
84425
+ ...node3,
84426
+ marks: []
84427
+ } : node3;
84428
+ if (Array.isArray(stripped.content))
84429
+ return {
84430
+ ...stripped,
84431
+ content: stripRunNodeMarks(stripped.content)
84432
+ };
84433
+ return stripped;
84434
+ });
84435
+ }
84436
+ function importDrawingMLTextbox({ params: params3, drawingNode, textBoxContent, bodyPr, baseAttrs = {}, paragraphImporter }) {
84437
+ if (!textBoxContent)
84438
+ return null;
84439
+ const textboxParagraphs = collectTextBoxParagraphs(preProcessTextBoxContent(textBoxContent, params3)?.elements || []);
84440
+ const importParagraph = typeof paragraphImporter === "function" ? paragraphImporter : (paragraph2) => {
84441
+ return handleParagraphNode$1({
84442
+ ...params3,
84443
+ nodes: [paragraph2]
84444
+ })?.nodes || [];
84445
+ };
84446
+ const contentNodes = stripRunNodeMarks(textboxParagraphs.flatMap((paragraph2) => {
84447
+ const imported = importParagraph(paragraph2);
84448
+ return Array.isArray(imported) ? imported : imported ? [imported] : [];
84449
+ }));
84450
+ const { verticalAlign, insets } = extractBodyPrProperties(bodyPr);
84451
+ return {
84452
+ type: "shapeContainer",
84453
+ attrs: {
84454
+ ...baseAttrs,
84455
+ drawingContent: drawingNode
84456
+ },
84457
+ content: [{
84458
+ type: "shapeTextbox",
84459
+ attrs: {
84460
+ textInsets: {
84461
+ top: insets.top,
84462
+ right: insets.right,
84463
+ bottom: insets.bottom,
84464
+ left: insets.left
84465
+ },
84466
+ textVerticalAlign: verticalAlign,
84467
+ attributes: {}
84468
+ },
84469
+ content: contentNodes
84470
+ }]
84471
+ };
84472
+ }
84418
84473
  function handleImageNode$1(node3, params3, isAnchor) {
84419
84474
  if (!node3)
84420
84475
  return null;
@@ -84886,6 +84941,122 @@ function extractTextFromTextBox(textBoxContent, bodyPr, params3 = {}) {
84886
84941
  wrap: wrap$1
84887
84942
  };
84888
84943
  }
84944
+ function extractFieldInlineNodes(node3) {
84945
+ if (node3?.name === "sd:autoPageNumber")
84946
+ return [{
84947
+ type: "page-number",
84948
+ attrs: {
84949
+ marksAsAttrs: [],
84950
+ instruction: "PAGE"
84951
+ }
84952
+ }];
84953
+ if (node3?.name === "sd:totalPageNumber")
84954
+ return [{
84955
+ type: "total-page-number",
84956
+ attrs: {
84957
+ marksAsAttrs: [],
84958
+ instruction: "NUMPAGES"
84959
+ }
84960
+ }];
84961
+ if (node3?.name === "sd:sectionPageCount") {
84962
+ const cachedText = node3?.attributes?.resolvedText ?? node3?.attributes?.importedCachedText ?? "";
84963
+ if (!cachedText)
84964
+ return [];
84965
+ return [{
84966
+ type: "text",
84967
+ text: cachedText
84968
+ }];
84969
+ }
84970
+ return [];
84971
+ }
84972
+ function extractInlineNodesFromRun(run$1, params3) {
84973
+ if (!run$1?.elements)
84974
+ return [];
84975
+ const nodes = [];
84976
+ run$1.elements.forEach((el) => {
84977
+ if (el.name === "w:t" || el.name === "w:delText") {
84978
+ const textNode = el.elements?.find((n) => n.type === "text");
84979
+ if (!textNode || typeof textNode.text !== "string")
84980
+ return;
84981
+ const cleanedText = textNode.text.replace(/\[\[sdspace\]\]/g, " ");
84982
+ if (cleanedText.length > 0)
84983
+ nodes.push({
84984
+ type: "text",
84985
+ text: cleanedText
84986
+ });
84987
+ } else if (el.name === "w:tab")
84988
+ nodes.push({
84989
+ type: "text",
84990
+ text: "\t"
84991
+ });
84992
+ else if (el.name === "w:br")
84993
+ nodes.push({
84994
+ type: "lineBreak",
84995
+ attrs: {}
84996
+ });
84997
+ else if (el.name === "sd:autoPageNumber" || el.name === "sd:totalPageNumber" || el.name === "sd:sectionPageCount")
84998
+ nodes.push(...extractFieldInlineNodes(el));
84999
+ else if (el.name === "w:drawing") {
85000
+ const inline = el.elements?.find((child) => child?.name === "wp:inline");
85001
+ if (!inline)
85002
+ return;
85003
+ const imagePm = handleImageNode$1(inline, {
85004
+ ...params3,
85005
+ nodes: [el]
85006
+ }, false);
85007
+ if (imagePm?.type === "image" && imagePm.attrs?.hidden !== true)
85008
+ nodes.push(imagePm);
85009
+ }
85010
+ });
85011
+ return nodes;
85012
+ }
85013
+ function paragraphToPmParagraph(paragraph2, params3) {
85014
+ const paragraphNode = collectTextBoxParagraphs([paragraph2])[0];
85015
+ if (!paragraphNode)
85016
+ return null;
85017
+ const paragraphProperties = resolveParagraphPropertiesForTextBox(paragraphNode, params3);
85018
+ const alignment = extractParagraphAlignment(paragraphNode) || "left";
85019
+ const content$2 = [];
85020
+ let pendingRunContent = [];
85021
+ const flushPendingRun = () => {
85022
+ if (pendingRunContent.length === 0)
85023
+ return;
85024
+ content$2.push({
85025
+ type: "run",
85026
+ attrs: {},
85027
+ content: pendingRunContent
85028
+ });
85029
+ pendingRunContent = [];
85030
+ };
85031
+ (paragraphNode.elements || []).forEach((element) => {
85032
+ if (element?.name === "w:r") {
85033
+ extractInlineNodesFromRun(element, params3).forEach((part) => {
85034
+ if (part?.type === "image") {
85035
+ flushPendingRun();
85036
+ content$2.push(part);
85037
+ return;
85038
+ }
85039
+ pendingRunContent.push(part);
85040
+ });
85041
+ return;
85042
+ }
85043
+ if (element?.name?.startsWith("sd:")) {
85044
+ const runContent = extractFieldInlineNodes(element);
85045
+ if (runContent.length > 0)
85046
+ pendingRunContent.push(...runContent);
85047
+ }
85048
+ });
85049
+ flushPendingRun();
85050
+ return {
85051
+ type: "paragraph",
85052
+ attrs: {
85053
+ paragraphProperties,
85054
+ textAlign: alignment
85055
+ },
85056
+ content: content$2,
85057
+ marks: []
85058
+ };
85059
+ }
84889
85060
  function getVectorShape({ params: params3, node: node3, graphicData, size: size2, marginOffset, anchorData, wrap: wrap$1, isAnchor, customGeometry }) {
84890
85061
  const schemaAttrs = {};
84891
85062
  const drawingNode = params3.nodes?.[0];
@@ -84921,14 +85092,45 @@ function getVectorShape({ params: params3, node: node3, graphicData, size: size2
84921
85092
  const textBoxContent = wsp.elements?.find((el) => el.name === "wps:txbx")?.elements?.find((el) => el.name === "w:txbxContent");
84922
85093
  const bodyPr = wsp.elements?.find((el) => el.name === "wps:bodyPr");
84923
85094
  const nonVisualShapeProps = wsp.elements?.find((el) => el.name === "wps:cNvSpPr");
85095
+ const isWordArt = bodyPr?.attributes?.["fromWordArt"] === "1";
85096
+ const isTextBox = nonVisualShapeProps?.attributes?.["txBox"] === "1";
85097
+ if (isTextBox && textBoxContent)
85098
+ return importDrawingMLTextbox({
85099
+ params: params3,
85100
+ drawingNode: drawingNode?.name === "w:drawing" ? drawingNode : null,
85101
+ textBoxContent,
85102
+ bodyPr,
85103
+ baseAttrs: {
85104
+ ...schemaAttrs,
85105
+ width,
85106
+ height,
85107
+ rotation,
85108
+ flipH,
85109
+ flipV,
85110
+ fillColor,
85111
+ strokeColor,
85112
+ strokeWidth,
85113
+ lineEnds,
85114
+ effectExtent,
85115
+ marginOffset,
85116
+ anchorData,
85117
+ wrap: wrap$1,
85118
+ isAnchor,
85119
+ isWordArt,
85120
+ isTextBox,
85121
+ originalAttributes: node3?.attributes
85122
+ },
85123
+ paragraphImporter: params3?.nodeListHandler != null ? undefined : (paragraph2) => {
85124
+ const imported = paragraphToPmParagraph(paragraph2, params3);
85125
+ return Array.isArray(imported) ? imported : imported ? [imported] : [];
85126
+ }
85127
+ });
84924
85128
  let textContent = null;
84925
85129
  let textAlign = "left";
84926
85130
  if (textBoxContent) {
84927
85131
  textContent = extractTextFromTextBox(textBoxContent, bodyPr, params3);
84928
85132
  textAlign = textContent?.horizontalAlign || "left";
84929
85133
  }
84930
- const isWordArt = bodyPr?.attributes?.["fromWordArt"] === "1";
84931
- const isTextBox = nonVisualShapeProps?.attributes?.["txBox"] === "1";
84932
85134
  return {
84933
85135
  type: "vectorShape",
84934
85136
  attrs: {
@@ -101152,9 +101354,15 @@ function handleShapeTextboxImport({ params: params3, pict }) {
101152
101354
  schemaAttrs.attributes = shapeAttrs;
101153
101355
  if (shapeAttrs.fillcolor)
101154
101356
  schemaAttrs.fillcolor = shapeAttrs.fillcolor;
101155
- const shapeStyle = buildStyles(parseInlineStyles(shapeAttrs.style));
101357
+ const parsedStyle = parseInlineStyles(shapeAttrs.style);
101358
+ const shapeStyle = buildStyles(parsedStyle);
101359
+ const positionData = extractPositionData(parsedStyle);
101156
101360
  if (shapeStyle)
101157
101361
  schemaAttrs.style = shapeStyle;
101362
+ if (positionData.anchorData)
101363
+ schemaAttrs.anchorData = positionData.anchorData;
101364
+ if (positionData.marginOffset)
101365
+ schemaAttrs.marginOffset = positionData.marginOffset;
101158
101366
  const textbox = shape.elements?.find((el) => el.name === "v:textbox");
101159
101367
  const wrap$1 = shape.elements?.find((el) => el.name === "w10:wrap");
101160
101368
  if (wrap$1?.attributes)
@@ -101184,6 +101392,38 @@ function buildStyles(styleObject) {
101184
101392
  style += `${prop}: ${value};`;
101185
101393
  return style;
101186
101394
  }
101395
+ function extractPositionData(styleObject) {
101396
+ const anchorData = {};
101397
+ const marginOffset = {};
101398
+ if (styleObject["mso-position-horizontal"])
101399
+ anchorData.alignH = styleObject["mso-position-horizontal"];
101400
+ if (styleObject["mso-position-horizontal-relative"])
101401
+ anchorData.hRelativeFrom = styleObject["mso-position-horizontal-relative"];
101402
+ if (styleObject["mso-position-vertical"])
101403
+ anchorData.alignV = styleObject["mso-position-vertical"];
101404
+ if (styleObject["mso-position-vertical-relative"])
101405
+ anchorData.vRelativeFrom = styleObject["mso-position-vertical-relative"];
101406
+ if (styleObject["margin-left"] != null)
101407
+ marginOffset.horizontal = convertToPixels$2(styleObject["margin-left"]);
101408
+ if (styleObject["margin-top"] != null)
101409
+ marginOffset.top = convertToPixels$2(styleObject["margin-top"]);
101410
+ return {
101411
+ ...Object.keys(anchorData).length > 0 ? { anchorData } : {},
101412
+ ...Object.keys(marginOffset).length > 0 ? { marginOffset } : {}
101413
+ };
101414
+ }
101415
+ function convertToPixels$2(value) {
101416
+ const num = parseFloat(value);
101417
+ if (Number.isNaN(num))
101418
+ return 0;
101419
+ if (value.endsWith("pt"))
101420
+ return num * 96 / 72;
101421
+ if (value.endsWith("in"))
101422
+ return num * 96;
101423
+ if (value.endsWith("px"))
101424
+ return num;
101425
+ return num;
101426
+ }
101187
101427
  function handleShapeImageWatermarkImport({ params: params3, pict }) {
101188
101428
  const shape = pict.elements?.find((el) => el.name === "v:shape");
101189
101429
  if (!shape)
@@ -101704,15 +101944,69 @@ function pictNodeTypeStrategy(node3) {
101704
101944
  handler: null
101705
101945
  };
101706
101946
  }
101947
+ function translateDrawingMLTextbox(params3) {
101948
+ const { node: node3 } = params3;
101949
+ const drawingContent = node3?.attrs?.drawingContent;
101950
+ const shapeTextbox = node3?.content?.find((child) => child?.type === "shapeTextbox");
101951
+ if (!drawingContent || !shapeTextbox)
101952
+ return null;
101953
+ const drawing = carbonCopy(drawingContent);
101954
+ const liveParagraphs = translateChildNodes({
101955
+ ...params3,
101956
+ node: shapeTextbox
101957
+ });
101958
+ const txbxContent = findTextboxContentNode(drawing);
101959
+ if (!txbxContent)
101960
+ return null;
101961
+ txbxContent.elements = liveParagraphs;
101962
+ return wrapTextInRun({
101963
+ name: "mc:AlternateContent",
101964
+ elements: [{
101965
+ name: "mc:Choice",
101966
+ attributes: { Requires: "wps" },
101967
+ elements: [drawing]
101968
+ }]
101969
+ });
101970
+ }
101971
+ function findTextboxContentNode(node3) {
101972
+ if (!node3 || typeof node3 !== "object")
101973
+ return null;
101974
+ if (node3.name === "w:txbxContent")
101975
+ return node3;
101976
+ if (!Array.isArray(node3.elements))
101977
+ return null;
101978
+ for (const child of node3.elements) {
101979
+ const found$1 = findTextboxContentNode(child);
101980
+ if (found$1)
101981
+ return found$1;
101982
+ }
101983
+ return null;
101984
+ }
101707
101985
  function translateShapeContainer(params3) {
101708
101986
  const { node: node3 } = params3;
101987
+ if (node3?.attrs?.drawingContent) {
101988
+ const run$1 = translateDrawingMLTextbox(params3);
101989
+ if (run$1)
101990
+ return {
101991
+ name: "w:p",
101992
+ elements: [run$1]
101993
+ };
101994
+ return {
101995
+ name: "w:p",
101996
+ elements: [wrapTextInRun(node3.attrs.drawingContent)]
101997
+ };
101998
+ }
101709
101999
  const elements = translateChildNodes(params3);
102000
+ const shapeAttributes = {
102001
+ ...node3.attrs.attributes,
102002
+ fillcolor: node3.attrs.fillcolor
102003
+ };
102004
+ const style = buildShapeStyle(node3.attrs);
102005
+ if (style)
102006
+ shapeAttributes.style = style;
101710
102007
  const shape = {
101711
102008
  name: "v:shape",
101712
- attributes: {
101713
- ...node3.attrs.attributes,
101714
- fillcolor: node3.attrs.fillcolor
101715
- },
102009
+ attributes: shapeAttributes,
101716
102010
  elements: [...elements, ...node3.attrs.wrapAttributes ? [{
101717
102011
  name: "w10:wrap",
101718
102012
  attributes: { ...node3.attrs.wrapAttributes }
@@ -101727,6 +102021,33 @@ function translateShapeContainer(params3) {
101727
102021
  })]
101728
102022
  };
101729
102023
  }
102024
+ function buildShapeStyle(attrs) {
102025
+ const originalStyle = parseInlineStyles(attrs.attributes?.style);
102026
+ const managedStyle = parseInlineStyles(attrs.style);
102027
+ const style = {
102028
+ ...originalStyle,
102029
+ ...managedStyle
102030
+ };
102031
+ if (attrs.marginOffset?.horizontal !== undefined)
102032
+ style["margin-left"] = `${convertToPt$2(attrs.marginOffset.horizontal)}pt`;
102033
+ if (attrs.marginOffset?.top !== undefined)
102034
+ style["margin-top"] = `${convertToPt$2(attrs.marginOffset.top)}pt`;
102035
+ if (attrs.anchorData?.alignH)
102036
+ style["mso-position-horizontal"] = attrs.anchorData.alignH;
102037
+ if (attrs.anchorData?.hRelativeFrom)
102038
+ style["mso-position-horizontal-relative"] = attrs.anchorData.hRelativeFrom;
102039
+ if (attrs.anchorData?.alignV)
102040
+ style["mso-position-vertical"] = attrs.anchorData.alignV;
102041
+ if (attrs.anchorData?.vRelativeFrom)
102042
+ style["mso-position-vertical-relative"] = attrs.anchorData.vRelativeFrom;
102043
+ const entries2 = Object.entries(style);
102044
+ if (entries2.length === 0)
102045
+ return;
102046
+ return entries2.map(([prop, value]) => `${prop}:${value}`).join(";");
102047
+ }
102048
+ function convertToPt$2(pixels) {
102049
+ return pixels * 72 / 96;
102050
+ }
101730
102051
  function translateShapeTextbox(params3) {
101731
102052
  const { node: node3 } = params3;
101732
102053
  const textboxContent = {
@@ -104103,7 +104424,7 @@ function hydrateImageBlocks(blocks, mediaFiles) {
104103
104424
  }
104104
104425
  if (blk.kind === "drawing") {
104105
104426
  const drawingBlock = blk;
104106
- if (drawingBlock.drawingKind === "vectorShape") {
104427
+ if (drawingBlock.drawingKind === "vectorShape" || drawingBlock.drawingKind === "textboxShape") {
104107
104428
  const parts = drawingBlock.textContent?.parts;
104108
104429
  if (!parts || parts.length === 0)
104109
104430
  return blk;
@@ -106158,6 +106479,14 @@ function lineBreakNodeToRun({ node: node3, positions, sdtMetadata }) {
106158
106479
  lineBreakRun.sdt = sdtMetadata;
106159
106480
  return lineBreakRun;
106160
106481
  }
106482
+ function hydrateTextboxDrawingContent(node3, drawingBlock, context) {
106483
+ if (drawingBlock.drawingKind !== "textboxShape")
106484
+ return drawingBlock;
106485
+ return {
106486
+ ...drawingBlock,
106487
+ contentBlocks: toTextboxParagraphBlocks(node3, context)
106488
+ };
106489
+ }
106161
106490
  function vectorShapeNodeToDrawingBlock(node3, nextBlockId, positions) {
106162
106491
  const rawAttrs = getAttrs$2(node3);
106163
106492
  if (isHiddenDrawing$1(rawAttrs))
@@ -106202,25 +106531,43 @@ function shapeContainerNodeToDrawingBlock(node3, nextBlockId, positions) {
106202
106531
  const rawAttrs = getAttrs$2(node3);
106203
106532
  if (isHiddenDrawing$1(rawAttrs))
106204
106533
  return null;
106205
- return buildDrawingBlock(rawAttrs, nextBlockId, positions, node3, {
106534
+ const geometry = {
106206
106535
  width: coercePositiveNumber(rawAttrs.width, 1),
106207
106536
  height: coercePositiveNumber(rawAttrs.height, 1),
106208
106537
  rotation: coerceNumber(rawAttrs.rotation) ?? 0,
106209
106538
  flipH: coerceBoolean(rawAttrs.flipH) ?? false,
106210
106539
  flipV: coerceBoolean(rawAttrs.flipV) ?? false
106211
- }, "vectorShape");
106540
+ };
106541
+ const shapeTextboxNode = resolveNestedShapeTextboxNode(node3);
106542
+ const textboxAttrs = shapeTextboxNode ? getAttrs$2(shapeTextboxNode) : {};
106543
+ const textContent = shapeTextboxNode ? extractTextboxTextContent(shapeTextboxNode) : undefined;
106544
+ return buildDrawingBlock({
106545
+ ...rawAttrs,
106546
+ ...textContent ? { textContent } : {},
106547
+ ...rawAttrs.textAlign == null && textContent?.horizontalAlign ? { textAlign: textContent.horizontalAlign } : {},
106548
+ ...rawAttrs.textInsets == null ? { textInsets: resolveTextboxInsetsFromAttrs(textboxAttrs) } : {},
106549
+ ...rawAttrs.textVerticalAlign == null ? { textVerticalAlign: resolveTextboxVerticalAlignFromAttrs(textboxAttrs) } : {}
106550
+ }, nextBlockId, positions, node3, geometry, "textboxShape", { contentBlocks: [] });
106212
106551
  }
106213
106552
  function shapeTextboxNodeToDrawingBlock(node3, nextBlockId, positions) {
106214
106553
  const rawAttrs = getAttrs$2(node3);
106215
106554
  if (isHiddenDrawing$1(rawAttrs))
106216
106555
  return null;
106217
- return buildDrawingBlock(rawAttrs, nextBlockId, positions, node3, {
106556
+ const geometry = {
106218
106557
  width: coercePositiveNumber(rawAttrs.width, 1),
106219
106558
  height: coercePositiveNumber(rawAttrs.height, 1),
106220
106559
  rotation: coerceNumber(rawAttrs.rotation) ?? 0,
106221
106560
  flipH: coerceBoolean(rawAttrs.flipH) ?? false,
106222
106561
  flipV: coerceBoolean(rawAttrs.flipV) ?? false
106223
- }, "vectorShape");
106562
+ };
106563
+ const textContent = extractTextboxTextContent(node3);
106564
+ return buildDrawingBlock({
106565
+ ...rawAttrs,
106566
+ ...textContent ? { textContent } : {},
106567
+ ...rawAttrs.textAlign == null && textContent?.horizontalAlign ? { textAlign: textContent.horizontalAlign } : {},
106568
+ ...rawAttrs.textInsets == null ? { textInsets: resolveTextboxInsetsFromAttrs(rawAttrs) } : {},
106569
+ ...rawAttrs.textVerticalAlign == null ? { textVerticalAlign: resolveTextboxVerticalAlignFromAttrs(rawAttrs) } : {}
106570
+ }, nextBlockId, positions, node3, geometry, "textboxShape", { contentBlocks: [] });
106224
106571
  }
106225
106572
  function handleVectorShapeNode(node3, context) {
106226
106573
  const { blocks, recordBlockKind, nextBlockId, positions } = context;
@@ -106242,7 +106589,7 @@ function handleShapeContainerNode(node3, context) {
106242
106589
  const { blocks, recordBlockKind, nextBlockId, positions } = context;
106243
106590
  const drawingBlock = shapeContainerNodeToDrawingBlock(node3, nextBlockId, positions);
106244
106591
  if (drawingBlock) {
106245
- blocks.push(drawingBlock);
106592
+ blocks.push(hydrateTextboxDrawingContent(node3, drawingBlock, context));
106246
106593
  recordBlockKind?.(drawingBlock.kind);
106247
106594
  }
106248
106595
  }
@@ -106250,7 +106597,7 @@ function handleShapeTextboxNode(node3, context) {
106250
106597
  const { blocks, recordBlockKind, nextBlockId, positions } = context;
106251
106598
  const drawingBlock = shapeTextboxNodeToDrawingBlock(node3, nextBlockId, positions);
106252
106599
  if (drawingBlock) {
106253
- blocks.push(drawingBlock);
106600
+ blocks.push(hydrateTextboxDrawingContent(node3, drawingBlock, context));
106254
106601
  recordBlockKind?.(drawingBlock.kind);
106255
106602
  }
106256
106603
  }
@@ -107007,8 +107354,14 @@ function paragraphToFlowBlocks({ para, nextBlockId, positions, storyKey, tracked
107007
107354
  const converter = SHAPE_CONVERTERS_REGISTRY[node3.type];
107008
107355
  const drawingBlock = converter(node3, stableNextBlockId, positions);
107009
107356
  if (drawingBlock) {
107010
- attachInlineShapeGroupAlignment(drawingBlock);
107011
- blocks.push(attachAnchorParagraphId(drawingBlock, anchorParagraphId));
107357
+ const hydratedBlock = hydrateTextboxDrawingContent(node3, drawingBlock, {
107358
+ converterContext,
107359
+ converters: converters$1,
107360
+ nextBlockId: stableNextBlockId,
107361
+ positions
107362
+ });
107363
+ attachInlineShapeGroupAlignment(hydratedBlock);
107364
+ blocks.push(attachAnchorParagraphId(hydratedBlock, anchorParagraphId));
107012
107365
  }
107013
107366
  return;
107014
107367
  }
@@ -116166,7 +116519,7 @@ var isRegExp = (value) => {
116166
116519
  return attributes["w:rsidDel"];
116167
116520
  }, decode$52 = (attrs) => {
116168
116521
  return attrs.rsidDel;
116169
- }, attributes_default$4, STYLES_KEY = "word/styles.xml", XML_NODE_NAME$32 = "w:r", SD_KEY_NAME = "run", REFERENCE_RUN_STYLE_BY_XML_NAME, hasXmlNodeNamed = (node3, targetName) => {
116522
+ }, attributes_default$4, STYLES_KEY = "word/styles.xml", XML_NODE_NAME$32 = "w:r", SD_KEY_NAME = "run", REFERENCE_RUN_STYLE_BY_XML_NAME, BLOCK_HOIST_TYPES, hasXmlNodeNamed = (node3, targetName) => {
116170
116523
  if (!node3 || typeof node3 !== "object")
116171
116524
  return false;
116172
116525
  if (node3.name === targetName)
@@ -116299,6 +116652,11 @@ var isRegExp = (value) => {
116299
116652
  nodes: contentElements
116300
116653
  };
116301
116654
  const content$2 = nodeListHandler?.handler(childParams) || [];
116655
+ if (Array.isArray(content$2) && content$2.length > 0 && content$2.every((child) => BLOCK_HOIST_TYPES.has(child?.type)))
116656
+ return content$2.filter(Boolean).map((child) => ({
116657
+ ...child,
116658
+ marks: Array.isArray(child?.marks) ? child.marks : []
116659
+ }));
116302
116660
  const filtered = (Array.isArray(content$2) ? content$2 : []).map((child) => {
116303
116661
  if (!child || typeof child !== "object")
116304
116662
  return child;
@@ -122001,7 +122359,86 @@ var isRegExp = (value) => {
122001
122359
  i$1++;
122002
122360
  }
122003
122361
  return { processedNodes };
122004
- }, HEADER_FOOTER_FILENAME_PATTERN, CHART_TYPE_MAP, CHART_TYPE_NAMES, findChild$1 = (node3, name) => node3?.elements?.find((el) => el.name === name), findChildren$2 = (node3, name) => node3?.elements?.filter((el) => el.name === name) ?? [], getAttr = (node3, attr) => node3?.attributes?.[attr], DRAWING_XML_TAG = "w:drawing", SHAPE_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", GROUP_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", SD_IMAGE_ID_NAMESPACE = "7c9e6679-7425-40de-944b-e07fc1f90ae7", normalizeTargetPath$1 = (targetPath = "") => {
122362
+ }, HEADER_FOOTER_FILENAME_PATTERN, CHART_TYPE_MAP, CHART_TYPE_NAMES, findChild$1 = (node3, name) => node3?.elements?.find((el) => el.name === name), findChildren$2 = (node3, name) => node3?.elements?.filter((el) => el.name === name) ?? [], getAttr = (node3, attr) => node3?.attributes?.[attr], PARAGRAPH_PROPERTIES_XML_NAME = "w:pPr", hasMeaningfulParagraphContent = (elements = []) => elements.some((element) => element?.name && element.name !== PARAGRAPH_PROPERTIES_XML_NAME), findParagraphProperties = (elements = []) => elements.find((element) => element?.name === PARAGRAPH_PROPERTIES_XML_NAME) ?? null, hasParagraphProperties = (elements = []) => elements.some((element) => element?.name === PARAGRAPH_PROPERTIES_XML_NAME), cloneParagraphPropertiesForRenderedResult = (paragraphProperties) => {
122363
+ const elements = (paragraphProperties.elements || []).filter((element) => element?.name !== "w:sectPr").map((element) => carbonCopy(element));
122364
+ if (elements.length === 0)
122365
+ return null;
122366
+ return {
122367
+ ...carbonCopy(paragraphProperties),
122368
+ elements
122369
+ };
122370
+ }, inheritWrapperParagraphProperties = (blockFieldElement, paragraphProperties) => {
122371
+ if (!paragraphProperties)
122372
+ return blockFieldElement;
122373
+ const fieldElements = Array.isArray(blockFieldElement?.elements) ? blockFieldElement.elements : [];
122374
+ const firstParagraphIndex = fieldElements.findIndex((element) => element?.name === "w:p");
122375
+ if (firstParagraphIndex < 0)
122376
+ return blockFieldElement;
122377
+ const firstParagraph = fieldElements[firstParagraphIndex];
122378
+ const firstParagraphElements = Array.isArray(firstParagraph.elements) ? firstParagraph.elements : [];
122379
+ if (hasParagraphProperties(firstParagraphElements))
122380
+ return blockFieldElement;
122381
+ const renderedParagraphProperties = cloneParagraphPropertiesForRenderedResult(paragraphProperties);
122382
+ const inheritedFirstParagraph = {
122383
+ ...firstParagraph,
122384
+ elements: renderedParagraphProperties ? [renderedParagraphProperties, ...firstParagraphElements] : firstParagraphElements
122385
+ };
122386
+ return {
122387
+ ...blockFieldElement,
122388
+ attributes: {
122389
+ ...blockFieldElement.attributes || {},
122390
+ wrapperParagraphProperties: carbonCopy(paragraphProperties)
122391
+ },
122392
+ elements: fieldElements.map((element, index2) => index2 === firstParagraphIndex ? inheritedFirstParagraph : element)
122393
+ };
122394
+ }, hoistBlockFieldNodes = (params3, paragraphNode) => {
122395
+ const paragraphElements = Array.isArray(paragraphNode?.elements) ? paragraphNode.elements : [];
122396
+ const blockFieldElements = paragraphElements.filter((element) => BLOCK_FIELD_XML_NAMES.has(element?.name));
122397
+ if (blockFieldElements.length === 0)
122398
+ return null;
122399
+ const nodes = [];
122400
+ const remainingElements = paragraphElements.filter((element) => !BLOCK_FIELD_XML_NAMES.has(element?.name));
122401
+ const wrapperParagraphProperties = findParagraphProperties(remainingElements);
122402
+ const shouldTransferWrapperProperties = !hasMeaningfulParagraphContent(remainingElements);
122403
+ if (hasMeaningfulParagraphContent(remainingElements)) {
122404
+ const paragraph2 = translator.encode({
122405
+ ...params3,
122406
+ nodes: [{
122407
+ ...paragraphNode,
122408
+ elements: remainingElements
122409
+ }]
122410
+ });
122411
+ if (paragraph2)
122412
+ nodes.push(paragraph2);
122413
+ }
122414
+ blockFieldElements.forEach((blockFieldElement) => {
122415
+ const fieldElement = shouldTransferWrapperProperties ? inheritWrapperParagraphProperties(blockFieldElement, wrapperParagraphProperties) : blockFieldElement;
122416
+ nodes.push(...params3.nodeListHandler.handler({
122417
+ ...params3,
122418
+ nodes: [fieldElement],
122419
+ path: [...params3.path || [], paragraphNode]
122420
+ }));
122421
+ });
122422
+ return nodes;
122423
+ }, handleParagraphNode$1 = (params3) => {
122424
+ const { nodes } = params3;
122425
+ if (nodes.length === 0 || nodes[0].name !== "w:p")
122426
+ return {
122427
+ nodes: [],
122428
+ consumed: 0
122429
+ };
122430
+ const hoistedNodes = hoistBlockFieldNodes(params3, nodes[0]);
122431
+ if (hoistedNodes)
122432
+ return {
122433
+ nodes: hoistedNodes,
122434
+ consumed: 1
122435
+ };
122436
+ const schemaNode = translator.encode(params3);
122437
+ return {
122438
+ nodes: Array.isArray(schemaNode) ? schemaNode : schemaNode ? [schemaNode] : [],
122439
+ consumed: 1
122440
+ };
122441
+ }, paragraphNodeHandlerEntity, DRAWING_XML_TAG = "w:drawing", SHAPE_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", GROUP_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", SD_IMAGE_ID_NAMESPACE = "7c9e6679-7425-40de-944b-e07fc1f90ae7", normalizeTargetPath$1 = (targetPath = "") => {
122005
122442
  if (!targetPath)
122006
122443
  return targetPath;
122007
122444
  const trimmed = targetPath.replace(/^\/+/, "");
@@ -122104,6 +122541,35 @@ var isRegExp = (value) => {
122104
122541
  if (result)
122105
122542
  return result;
122106
122543
  }
122544
+ if (wsp.elements?.find((el) => el.name === "wps:cNvSpPr")?.attributes?.["txBox"] === "1" && textBoxContent) {
122545
+ const bodyPr = wsp.elements?.find((el) => el.name === "wps:bodyPr");
122546
+ const drawingNode = params3.nodes?.[0];
122547
+ const result = importDrawingMLTextbox({
122548
+ params: params3,
122549
+ drawingNode: drawingNode?.name === "w:drawing" ? drawingNode : null,
122550
+ textBoxContent,
122551
+ bodyPr,
122552
+ baseAttrs: {
122553
+ width: size2?.width,
122554
+ height: size2?.height,
122555
+ marginOffset,
122556
+ anchorData,
122557
+ wrap: wrap$1,
122558
+ isAnchor,
122559
+ isTextBox: true,
122560
+ originalAttributes: node3?.attributes,
122561
+ ...params3.nodes?.[0]?.name === "w:drawing" ? { drawingContent: params3.nodes[0] } : {}
122562
+ },
122563
+ paragraphImporter: params3?.nodeListHandler != null ? undefined : (paragraph2) => {
122564
+ const imported = paragraphToPmParagraph(paragraph2, params3);
122565
+ return Array.isArray(imported) ? imported : imported ? [imported] : [];
122566
+ }
122567
+ });
122568
+ if (result?.attrs && isHidden)
122569
+ result.attrs.hidden = true;
122570
+ if (result)
122571
+ return result;
122572
+ }
122107
122573
  const placeholder = buildShapePlaceholder(node3, size2, padding, marginOffset, textBoxContent ? "textbox" : "drawing");
122108
122574
  if (placeholder?.attrs && isHidden)
122109
122575
  placeholder.attrs.hidden = true;
@@ -128097,86 +128563,7 @@ var isRegExp = (value) => {
128097
128563
  nodes: [resultNode],
128098
128564
  consumed: 1
128099
128565
  };
128100
- }, textNodeHandlerEntity, PARAGRAPH_PROPERTIES_XML_NAME = "w:pPr", hasMeaningfulParagraphContent = (elements = []) => elements.some((element) => element?.name && element.name !== PARAGRAPH_PROPERTIES_XML_NAME), findParagraphProperties = (elements = []) => elements.find((element) => element?.name === PARAGRAPH_PROPERTIES_XML_NAME) ?? null, hasParagraphProperties = (elements = []) => elements.some((element) => element?.name === PARAGRAPH_PROPERTIES_XML_NAME), cloneParagraphPropertiesForRenderedResult = (paragraphProperties) => {
128101
- const elements = (paragraphProperties.elements || []).filter((element) => element?.name !== "w:sectPr").map((element) => carbonCopy(element));
128102
- if (elements.length === 0)
128103
- return null;
128104
- return {
128105
- ...carbonCopy(paragraphProperties),
128106
- elements
128107
- };
128108
- }, inheritWrapperParagraphProperties = (blockFieldElement, paragraphProperties) => {
128109
- if (!paragraphProperties)
128110
- return blockFieldElement;
128111
- const fieldElements = Array.isArray(blockFieldElement?.elements) ? blockFieldElement.elements : [];
128112
- const firstParagraphIndex = fieldElements.findIndex((element) => element?.name === "w:p");
128113
- if (firstParagraphIndex < 0)
128114
- return blockFieldElement;
128115
- const firstParagraph = fieldElements[firstParagraphIndex];
128116
- const firstParagraphElements = Array.isArray(firstParagraph.elements) ? firstParagraph.elements : [];
128117
- if (hasParagraphProperties(firstParagraphElements))
128118
- return blockFieldElement;
128119
- const renderedParagraphProperties = cloneParagraphPropertiesForRenderedResult(paragraphProperties);
128120
- const inheritedFirstParagraph = {
128121
- ...firstParagraph,
128122
- elements: renderedParagraphProperties ? [renderedParagraphProperties, ...firstParagraphElements] : firstParagraphElements
128123
- };
128124
- return {
128125
- ...blockFieldElement,
128126
- attributes: {
128127
- ...blockFieldElement.attributes || {},
128128
- wrapperParagraphProperties: carbonCopy(paragraphProperties)
128129
- },
128130
- elements: fieldElements.map((element, index2) => index2 === firstParagraphIndex ? inheritedFirstParagraph : element)
128131
- };
128132
- }, hoistBlockFieldNodes = (params3, paragraphNode) => {
128133
- const paragraphElements = Array.isArray(paragraphNode?.elements) ? paragraphNode.elements : [];
128134
- const blockFieldElements = paragraphElements.filter((element) => BLOCK_FIELD_XML_NAMES.has(element?.name));
128135
- if (blockFieldElements.length === 0)
128136
- return null;
128137
- const nodes = [];
128138
- const remainingElements = paragraphElements.filter((element) => !BLOCK_FIELD_XML_NAMES.has(element?.name));
128139
- const wrapperParagraphProperties = findParagraphProperties(remainingElements);
128140
- const shouldTransferWrapperProperties = !hasMeaningfulParagraphContent(remainingElements);
128141
- if (hasMeaningfulParagraphContent(remainingElements)) {
128142
- const paragraph2 = translator.encode({
128143
- ...params3,
128144
- nodes: [{
128145
- ...paragraphNode,
128146
- elements: remainingElements
128147
- }]
128148
- });
128149
- if (paragraph2)
128150
- nodes.push(paragraph2);
128151
- }
128152
- blockFieldElements.forEach((blockFieldElement) => {
128153
- const fieldElement = shouldTransferWrapperProperties ? inheritWrapperParagraphProperties(blockFieldElement, wrapperParagraphProperties) : blockFieldElement;
128154
- nodes.push(...params3.nodeListHandler.handler({
128155
- ...params3,
128156
- nodes: [fieldElement],
128157
- path: [...params3.path || [], paragraphNode]
128158
- }));
128159
- });
128160
- return nodes;
128161
- }, handleParagraphNode$1 = (params3) => {
128162
- const { nodes } = params3;
128163
- if (nodes.length === 0 || nodes[0].name !== "w:p")
128164
- return {
128165
- nodes: [],
128166
- consumed: 0
128167
- };
128168
- const hoistedNodes = hoistBlockFieldNodes(params3, nodes[0]);
128169
- if (hoistedNodes)
128170
- return {
128171
- nodes: hoistedNodes,
128172
- consumed: 1
128173
- };
128174
- const schemaNode = translator.encode(params3);
128175
- return {
128176
- nodes: Array.isArray(schemaNode) ? schemaNode : schemaNode ? [schemaNode] : [],
128177
- consumed: 1
128178
- };
128179
- }, paragraphNodeHandlerEntity, handleSdtNode = (params3) => {
128566
+ }, textNodeHandlerEntity, handleSdtNode = (params3) => {
128180
128567
  const { nodes } = params3;
128181
128568
  if (nodes.length === 0 || nodes[0].name !== "w:sdt")
128182
128569
  return {
@@ -133044,7 +133431,186 @@ var isRegExp = (value) => {
133044
133431
  if (toBoolean(attrs.hidden) === true)
133045
133432
  return true;
133046
133433
  return typeof attrs.visibility === "string" && attrs.visibility.toLowerCase() === "hidden";
133047
- }, normalizeWrapType$1 = (value) => {
133434
+ }, TEXTBOX_CONTAINER_TYPES, resolveTextFormattingFromMarks = (marks) => {
133435
+ if (!Array.isArray(marks) || marks.length === 0)
133436
+ return;
133437
+ const formatting = {};
133438
+ marks.forEach((mark) => {
133439
+ if (!mark || typeof mark.type !== "string")
133440
+ return;
133441
+ const attrs = isPlainObject3(mark.attrs) ? mark.attrs : {};
133442
+ if (mark.type === "bold")
133443
+ formatting.bold = true;
133444
+ if (mark.type === "italic")
133445
+ formatting.italic = true;
133446
+ const color2 = typeof attrs.color === "string" ? attrs.color.replace(/^#/, "") : undefined;
133447
+ if (color2)
133448
+ formatting.color = color2;
133449
+ const fontFamily = typeof attrs.fontFamily === "string" ? attrs.fontFamily : undefined;
133450
+ if (fontFamily)
133451
+ formatting.fontFamily = fontFamily;
133452
+ const fontSize = pickNumber(attrs.fontSize);
133453
+ if (fontSize != null)
133454
+ formatting.fontSize = fontSize;
133455
+ });
133456
+ return Object.keys(formatting).length > 0 ? formatting : undefined;
133457
+ }, pushTextPart = (parts, part) => {
133458
+ if (!part.text && !part.fieldType && !part.isLineBreak)
133459
+ return;
133460
+ parts.push(part);
133461
+ }, extractTextPartsFromTextboxInline = (node3, parts) => {
133462
+ if (!node3)
133463
+ return;
133464
+ const formatting = resolveTextFormattingFromMarks(node3.marks);
133465
+ if (typeof node3.text === "string") {
133466
+ pushTextPart(parts, {
133467
+ text: node3.text,
133468
+ ...formatting ? { formatting } : {}
133469
+ });
133470
+ return;
133471
+ }
133472
+ switch (node3.type) {
133473
+ case "text":
133474
+ pushTextPart(parts, {
133475
+ text: "",
133476
+ ...formatting ? { formatting } : {}
133477
+ });
133478
+ return;
133479
+ case "tab":
133480
+ pushTextPart(parts, {
133481
+ text: "\t",
133482
+ ...formatting ? { formatting } : {}
133483
+ });
133484
+ return;
133485
+ case "lineBreak":
133486
+ pushTextPart(parts, {
133487
+ text: `
133488
+ `,
133489
+ isLineBreak: true,
133490
+ ...formatting ? { formatting } : {}
133491
+ });
133492
+ return;
133493
+ case "page-number":
133494
+ pushTextPart(parts, {
133495
+ text: "",
133496
+ fieldType: "PAGE",
133497
+ pageNumberFormat: typeof node3.attrs?.pageNumberFormat === "string" ? node3.attrs.pageNumberFormat : undefined,
133498
+ ...formatting ? { formatting } : {}
133499
+ });
133500
+ return;
133501
+ case "total-page-number":
133502
+ pushTextPart(parts, {
133503
+ text: typeof node3.attrs?.resolvedText === "string" ? node3.attrs.resolvedText : typeof node3.attrs?.importedCachedText === "string" ? node3.attrs.importedCachedText : "",
133504
+ fieldType: "NUMPAGES",
133505
+ pageNumberFormat: typeof node3.attrs?.pageNumberFormat === "string" ? node3.attrs.pageNumberFormat : undefined,
133506
+ ...formatting ? { formatting } : {}
133507
+ });
133508
+ return;
133509
+ default:
133510
+ break;
133511
+ }
133512
+ if (Array.isArray(node3.content) && (TEXTBOX_CONTAINER_TYPES.has(node3.type) || node3.content.length > 0))
133513
+ node3.content.forEach((child) => extractTextPartsFromTextboxInline(child, parts));
133514
+ }, extractTextboxTextContent = (node3) => {
133515
+ if (!Array.isArray(node3.content) || node3.content.length === 0)
133516
+ return;
133517
+ const parts = [];
133518
+ let horizontalAlign;
133519
+ const paragraphs = node3.content.filter((child) => child?.type === "paragraph");
133520
+ const paragraphHasRenderableContent = (paragraph2) => Array.isArray(paragraph2.content) && paragraph2.content.length > 0;
133521
+ paragraphs.forEach((paragraph2, paragraphIndex) => {
133522
+ const justification = paragraph2.attrs?.paragraphProperties;
133523
+ if (!horizontalAlign && isPlainObject3(justification)) {
133524
+ const value = justification.justification;
133525
+ if (value === "left" || value === "center" || value === "right")
133526
+ horizontalAlign = value;
133527
+ }
133528
+ paragraph2.content?.forEach((child) => extractTextPartsFromTextboxInline(child, parts));
133529
+ if (paragraphIndex < paragraphs.length - 1) {
133530
+ const nextParagraph = paragraphs[paragraphIndex + 1];
133531
+ parts.push({
133532
+ text: `
133533
+ `,
133534
+ isLineBreak: true,
133535
+ isEmptyParagraph: !paragraphHasRenderableContent(paragraph2) || !paragraphHasRenderableContent(nextParagraph)
133536
+ });
133537
+ }
133538
+ });
133539
+ return parts.length > 0 ? {
133540
+ parts,
133541
+ ...horizontalAlign ? { horizontalAlign } : {}
133542
+ } : undefined;
133543
+ }, isParagraphNode = (node3) => node3?.type === "paragraph", toTextboxParagraphBlocks = (node3, context) => {
133544
+ const shapeTextboxNode = node3.type === "shapeTextbox" ? node3 : resolveNestedShapeTextboxNode(node3);
133545
+ const paragraphToFlowBlocks$1 = context.converters?.paragraphToFlowBlocks;
133546
+ if (!shapeTextboxNode || !paragraphToFlowBlocks$1 || !Array.isArray(shapeTextboxNode.content))
133547
+ return [];
133548
+ const textboxBlocks = [];
133549
+ for (const child of shapeTextboxNode.content) {
133550
+ if (!isParagraphNode(child))
133551
+ continue;
133552
+ const convertedBlocks = paragraphToFlowBlocks$1({
133553
+ para: child,
133554
+ nextBlockId: context.nextBlockId,
133555
+ positions: context.positions,
133556
+ storyKey: context.storyKey,
133557
+ trackedChangesConfig: context.trackedChangesConfig,
133558
+ bookmarks: context.bookmarks,
133559
+ hyperlinkConfig: context.hyperlinkConfig,
133560
+ themeColors: context.themeColors,
133561
+ converters: context.converters,
133562
+ converterContext: context.converterContext,
133563
+ enableComments: context.enableComments,
133564
+ previousParagraphFont: getLastParagraphFont(textboxBlocks)
133565
+ });
133566
+ textboxBlocks.push(...convertedBlocks);
133567
+ }
133568
+ return textboxBlocks.filter((block) => block.kind === "paragraph");
133569
+ }, parseTextboxInsetValue = (value) => {
133570
+ const trimmed = value.trim();
133571
+ if (!trimmed)
133572
+ return;
133573
+ if (trimmed.endsWith("pt"))
133574
+ return ptToPx(parseFloat(trimmed.slice(0, -2)));
133575
+ if (trimmed.endsWith("px"))
133576
+ return pickNumber(trimmed.slice(0, -2));
133577
+ if (trimmed.endsWith("in")) {
133578
+ const inches = parseFloat(trimmed.slice(0, -2));
133579
+ return Number.isFinite(inches) ? inches * 96 : undefined;
133580
+ }
133581
+ return pickNumber(trimmed);
133582
+ }, resolveTextboxInsetsFromAttrs = (attrs) => {
133583
+ const explicitInsets = normalizeTextInsets(attrs.textInsets);
133584
+ if (explicitInsets)
133585
+ return explicitInsets;
133586
+ const textboxAttrs = isPlainObject3(attrs.attributes) ? attrs.attributes : undefined;
133587
+ const inset = typeof textboxAttrs?.inset === "string" ? textboxAttrs.inset : undefined;
133588
+ if (!inset)
133589
+ return;
133590
+ const values = inset.split(",").map((entry) => parseTextboxInsetValue(entry));
133591
+ if (values.length !== 4 || values.some((entry) => entry == null))
133592
+ return;
133593
+ return {
133594
+ top: values[1],
133595
+ right: values[2],
133596
+ bottom: values[3],
133597
+ left: values[0]
133598
+ };
133599
+ }, resolveTextboxVerticalAlignFromAttrs = (attrs) => {
133600
+ const explicitAlign = normalizeTextVerticalAlign(attrs.textVerticalAlign);
133601
+ if (explicitAlign)
133602
+ return explicitAlign;
133603
+ const textboxAttrs = isPlainObject3(attrs.attributes) ? attrs.attributes : undefined;
133604
+ const style = typeof textboxAttrs?.style === "string" ? textboxAttrs.style : undefined;
133605
+ if (!style)
133606
+ return;
133607
+ const match = style.match(/v-text-anchor\s*:\s*(top|middle|bottom)/i);
133608
+ if (!match)
133609
+ return;
133610
+ if (match[1].toLowerCase() === "middle")
133611
+ return "center";
133612
+ return match[1].toLowerCase();
133613
+ }, resolveNestedShapeTextboxNode = (node3) => Array.isArray(node3.content) ? node3.content.find((child) => child?.type === "shapeTextbox") : undefined, normalizeWrapType$1 = (value) => {
133048
133614
  if (typeof value !== "string")
133049
133615
  return;
133050
133616
  return WRAP_TYPES$2.has(value) ? value : undefined;
@@ -133761,13 +134327,13 @@ var isRegExp = (value) => {
133761
134327
  if (childNode.type === "shapeContainer" && context.converters?.shapeContainerNodeToDrawingBlock) {
133762
134328
  const drawingBlock = context.converters.shapeContainerNodeToDrawingBlock(childNode, context.nextBlockId, context.positions);
133763
134329
  if (drawingBlock && drawingBlock.kind === "drawing")
133764
- blocks.push(drawingBlock);
134330
+ blocks.push(hydrateTextboxDrawingContent(childNode, drawingBlock, context));
133765
134331
  continue;
133766
134332
  }
133767
134333
  if (childNode.type === "shapeTextbox" && context.converters?.shapeTextboxNodeToDrawingBlock) {
133768
134334
  const drawingBlock = context.converters.shapeTextboxNodeToDrawingBlock(childNode, context.nextBlockId, context.positions);
133769
134335
  if (drawingBlock && drawingBlock.kind === "drawing")
133770
- blocks.push(drawingBlock);
134336
+ blocks.push(hydrateTextboxDrawingContent(childNode, drawingBlock, context));
133771
134337
  continue;
133772
134338
  }
133773
134339
  }
@@ -134327,7 +134893,7 @@ var isRegExp = (value) => {
134327
134893
  state.kern = kernNode.attributes["w:val"];
134328
134894
  }
134329
134895
  }, SuperConverter;
134330
- var init_SuperConverter_DBlOjc68_es = __esm(() => {
134896
+ var init_SuperConverter_CUxtXQFf_es = __esm(() => {
134331
134897
  init_rolldown_runtime_Bg48TavK_es();
134332
134898
  init_jszip_C49i9kUs_es();
134333
134899
  init_xml_js_CqGKpaft_es();
@@ -151088,6 +151654,7 @@ var init_SuperConverter_DBlOjc68_es = __esm(() => {
151088
151654
  "w:footnoteReference": "FootnoteReference",
151089
151655
  "w:endnoteReference": "EndnoteReference"
151090
151656
  };
151657
+ BLOCK_HOIST_TYPES = new Set(["shapeContainer"]);
151091
151658
  COMPLEX_SCRIPT_CODEPOINT_RANGES = [
151092
151659
  [1424, 2303],
151093
151660
  [2304, 4255],
@@ -163173,6 +163740,10 @@ var init_SuperConverter_DBlOjc68_es = __esm(() => {
163173
163740
  "c:surface3DChart": "surfaceChart"
163174
163741
  };
163175
163742
  CHART_TYPE_NAMES = new Set(Object.keys(CHART_TYPE_MAP));
163743
+ paragraphNodeHandlerEntity = {
163744
+ handlerName: "paragraphNodeHandler",
163745
+ handler: handleParagraphNode$1
163746
+ };
163176
163747
  atomElements = /^(img|br|input|textarea|hr)$/i;
163177
163748
  nav = typeof navigator != "undefined" ? navigator : null;
163178
163749
  doc = typeof document != "undefined" ? document : null;
@@ -170909,10 +171480,6 @@ var init_SuperConverter_DBlOjc68_es = __esm(() => {
170909
171480
  handlerName: "textNodeHandler",
170910
171481
  handler: handleTextNode
170911
171482
  };
170912
- paragraphNodeHandlerEntity = {
170913
- handlerName: "paragraphNodeHandler",
170914
- handler: handleParagraphNode$1
170915
- };
170916
171483
  sdtNodeHandlerEntity = {
170917
171484
  handlerName: "sdtNodeHandler",
170918
171485
  handler: handleSdtNode
@@ -173009,6 +173576,14 @@ var init_SuperConverter_DBlOjc68_es = __esm(() => {
173009
173576
  "center",
173010
173577
  "bottom"
173011
173578
  ]);
173579
+ TEXTBOX_CONTAINER_TYPES = new Set([
173580
+ "run",
173581
+ "link",
173582
+ "hyperlink",
173583
+ "structuredContent",
173584
+ "fieldAnnotation",
173585
+ "smartTag"
173586
+ ]);
173012
173587
  WRAP_TYPES$1 = new Set([
173013
173588
  "None",
173014
173589
  "Square",
@@ -174511,7 +175086,7 @@ var init_SuperConverter_DBlOjc68_es = __esm(() => {
174511
175086
  };
174512
175087
  });
174513
175088
 
174514
- // ../../packages/superdoc/dist/chunks/create-headless-toolbar-DWyoHv_L.es.js
175089
+ // ../../packages/superdoc/dist/chunks/create-headless-toolbar-DutCjfp2.es.js
174515
175090
  function parseSizeUnit(val = "0") {
174516
175091
  const length3 = val.toString() || "0";
174517
175092
  const value = Number.parseFloat(length3);
@@ -184906,8 +185481,8 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, normalizeActorId = (value) => {
184906
185481
  }
184907
185482
  };
184908
185483
  };
184909
- var init_create_headless_toolbar_DWyoHv_L_es = __esm(() => {
184910
- init_SuperConverter_DBlOjc68_es();
185484
+ var init_create_headless_toolbar_DutCjfp2_es = __esm(() => {
185485
+ init_SuperConverter_CUxtXQFf_es();
184911
185486
  init_uuid_B2wVPhPi_es();
184912
185487
  init_constants_D9qj59G2_es();
184913
185488
  init_dist_B8HfvhaK_es();
@@ -234076,7 +234651,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
234076
234651
  init_remark_gfm_BhnWr3yf_es();
234077
234652
  });
234078
234653
 
234079
- // ../../packages/superdoc/dist/chunks/src-BnMjPHBh.es.js
234654
+ // ../../packages/superdoc/dist/chunks/src-BBtIMpLJ.es.js
234080
234655
  function deleteProps(obj, propOrProps) {
234081
234656
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
234082
234657
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -275191,7 +275766,7 @@ function hasPageContextTokenInBlock(block) {
275191
275766
  return true;
275192
275767
  } else if (block.kind === "drawing") {
275193
275768
  const drawing = block;
275194
- if (drawing.drawingKind === "vectorShape")
275769
+ if (drawing.drawingKind === "vectorShape" || drawing.drawingKind === "textboxShape")
275195
275770
  return hasPageContextTokenInShapeText(drawing.textContent);
275196
275771
  if (drawing.drawingKind === "shapeGroup")
275197
275772
  return hasPageContextTokenInShapeGroup(drawing.shapes);
@@ -276848,6 +277423,18 @@ function computeParagraphLayoutStartY(input2) {
276848
277423
  const effectiveSpacingBefore = input2.suppressSpacingBefore ? 0 : input2.spacingBefore;
276849
277424
  return computeParagraphContentStartY(y$1, effectiveSpacingBefore, effectiveSpacingBefore === 0, trailingForCollapse);
276850
277425
  }
277426
+ function layoutTextboxContent(block, remeasureParagraph$1) {
277427
+ if (!Array.isArray(block.contentBlocks) || block.contentBlocks.length === 0)
277428
+ return [];
277429
+ const insets = block.textInsets ?? {
277430
+ top: 0,
277431
+ right: 0,
277432
+ bottom: 0,
277433
+ left: 0
277434
+ };
277435
+ const contentWidth = Math.max(1, block.geometry.width - insets.left - insets.right);
277436
+ return block.contentBlocks.map((paragraphBlock) => remeasureParagraph$1(paragraphBlock, contentWidth));
277437
+ }
276851
277438
  function describeCellRenderBlocks(cellMeasure, cellBlock, cellPadding) {
276852
277439
  const measuredBlocks = cellMeasure.blocks;
276853
277440
  const blockDataArray = cellBlock?.blocks;
@@ -278312,6 +278899,7 @@ function layoutParagraphBlock(ctx$1, anchors) {
278312
278899
  fragment2.pmEnd = pmRange.pmEnd;
278313
278900
  state.page.fragments.push(fragment2);
278314
278901
  } else if (entry.block.kind === "drawing" && entry.measure.kind === "drawing") {
278902
+ const contentMeasures = entry.block.drawingKind === "textboxShape" && typeof remeasureParagraph$1 === "function" ? layoutTextboxContent(entry.block, remeasureParagraph$1) : undefined;
278315
278903
  const fragment2 = {
278316
278904
  kind: "drawing",
278317
278905
  blockId: entry.block.id,
@@ -278328,6 +278916,8 @@ function layoutParagraphBlock(ctx$1, anchors) {
278328
278916
  drawingContentId: entry.block.drawingContentId,
278329
278917
  sourceAnchor: entry.block.sourceAnchor
278330
278918
  };
278919
+ if (contentMeasures)
278920
+ fragment2.contentMeasures = contentMeasures;
278331
278921
  if (pmRange.pmStart != null)
278332
278922
  fragment2.pmStart = pmRange.pmStart;
278333
278923
  if (pmRange.pmEnd != null)
@@ -278736,7 +279326,7 @@ function layoutImageBlock({ block, measure, columns, ensurePage, advanceColumn,
278736
279326
  state.cursorY += requiredHeight;
278737
279327
  state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
278738
279328
  }
278739
- function layoutDrawingBlock({ block, measure, columns, ensurePage, advanceColumn, columnX }) {
279329
+ function layoutDrawingBlock({ block, measure, columns, ensurePage, advanceColumn, columnX, textboxContentMeasures }) {
278740
279330
  if (block.anchor?.isAnchored)
278741
279331
  return;
278742
279332
  const marginTop = Math.max(0, block.margin?.top ?? 0);
@@ -278793,6 +279383,8 @@ function layoutDrawingBlock({ block, measure, columns, ensurePage, advanceColumn
278793
279383
  pmEnd: pmRange.pmEnd,
278794
279384
  sourceAnchor: block.sourceAnchor
278795
279385
  };
279386
+ if (textboxContentMeasures)
279387
+ fragment2.contentMeasures = textboxContentMeasures;
278796
279388
  state.page.fragments.push(fragment2);
278797
279389
  state.cursorY += requiredHeight;
278798
279390
  state.maxCursorY = Math.max(state.maxCursorY, state.cursorY);
@@ -281226,6 +281818,7 @@ function layoutDocument(blocks2, measures, options = {}) {
281226
281818
  const state = paginator.ensurePage();
281227
281819
  const drawBlock = block;
281228
281820
  const drawMeasure = measure;
281821
+ const contentMeasures = drawBlock.drawingKind === "textboxShape" && typeof options.remeasureParagraph === "function" ? layoutTextboxContent(drawBlock, options.remeasureParagraph) : undefined;
281229
281822
  const fragment2 = {
281230
281823
  kind: "drawing",
281231
281824
  blockId: drawBlock.id,
@@ -281242,6 +281835,8 @@ function layoutDocument(blocks2, measures, options = {}) {
281242
281835
  drawingContentId: drawBlock.drawingContentId,
281243
281836
  sourceAnchor: drawBlock.sourceAnchor
281244
281837
  };
281838
+ if (contentMeasures)
281839
+ fragment2.contentMeasures = contentMeasures;
281245
281840
  const attrs = drawBlock.attrs;
281246
281841
  if (attrs?.pmStart != null)
281247
281842
  fragment2.pmStart = attrs.pmStart;
@@ -281257,7 +281852,8 @@ function layoutDocument(blocks2, measures, options = {}) {
281257
281852
  columns: getCurrentColumns(),
281258
281853
  ensurePage: paginator.ensurePage,
281259
281854
  advanceColumn: paginator.advanceColumn,
281260
- columnX
281855
+ columnX,
281856
+ textboxContentMeasures: block.drawingKind === "textboxShape" && typeof options.remeasureParagraph === "function" ? layoutTextboxContent(block, options.remeasureParagraph) : undefined
281261
281857
  });
281262
281858
  continue;
281263
281859
  }
@@ -281533,7 +282129,7 @@ function shouldExcludeFromMeasurement(fragment2, block, fragmentBottom, canvasHe
281533
282129
  return true;
281534
282130
  return false;
281535
282131
  }
281536
- function layoutHeaderFooter(blocks2, measures, constraints, kind) {
282132
+ function layoutHeaderFooter(blocks2, measures, constraints, kind, remeasureParagraph$1) {
281537
282133
  if (blocks2.length !== measures.length)
281538
282134
  throw new Error(`layoutHeaderFooter expected measures for every block (blocks=${blocks2.length}, measures=${measures.length})`);
281539
282135
  const width = Number(constraints?.width);
@@ -281557,7 +282153,8 @@ function layoutHeaderFooter(blocks2, measures, constraints, kind) {
281557
282153
  left: 0
281558
282154
  },
281559
282155
  allowParagraphlessAnchoredTableFallback: false,
281560
- allowSectionBreakOnlyPageFallback: false
282156
+ allowSectionBreakOnlyPageFallback: false,
282157
+ remeasureParagraph: remeasureParagraph$1
281561
282158
  });
281562
282159
  if (kind === "footer" && constraints.pageHeight != null)
281563
282160
  normalizeFragmentsForRegion(layout.pages, blocks2, measures, kind, constraints);
@@ -282336,7 +282933,7 @@ function hasPageNumberTokensRequiringPerPageLayout(blocks2) {
282336
282933
  }
282337
282934
  return false;
282338
282935
  }
282339
- async function layoutHeaderFooterWithCache(sections, constraints, measureBlock$1, cache$2 = sharedHeaderFooterCache, totalPages, pageResolver, kind, fontSignature = "") {
282936
+ async function layoutHeaderFooterWithCache(sections, constraints, measureBlock$1, cache$2 = sharedHeaderFooterCache, totalPages, pageResolver, kind, fontSignature = "", remeasureParagraph$1) {
282340
282937
  const result = {};
282341
282938
  if (!pageResolver) {
282342
282939
  const numPages = totalPages ?? 1;
@@ -282349,7 +282946,7 @@ async function layoutHeaderFooterWithCache(sections, constraints, measureBlock$1
282349
282946
  result[type] = {
282350
282947
  blocks: clonedBlocks,
282351
282948
  measures,
282352
- layout: layoutHeaderFooter(clonedBlocks, measures, constraints, kind)
282949
+ layout: layoutHeaderFooter(clonedBlocks, measures, constraints, kind, remeasureParagraph$1)
282353
282950
  };
282354
282951
  }
282355
282952
  return result;
@@ -282366,7 +282963,7 @@ async function layoutHeaderFooterWithCache(sections, constraints, measureBlock$1
282366
282963
  result[type] = {
282367
282964
  blocks: blocks2,
282368
282965
  measures,
282369
- layout: layoutHeaderFooter(blocks2, measures, constraints, kind)
282966
+ layout: layoutHeaderFooter(blocks2, measures, constraints, kind, remeasureParagraph$1)
282370
282967
  };
282371
282968
  continue;
282372
282969
  }
@@ -282388,7 +282985,7 @@ async function layoutHeaderFooterWithCache(sections, constraints, measureBlock$1
282388
282985
  const { displayText, displayNumber, totalPages: totalPagesForPage, sectionPageCount, pageFormat, chapterNumberText, chapterSeparator } = pageResolver(pageNum);
282389
282986
  resolveHeaderFooterTokens(clonedBlocks, pageNum, totalPagesForPage, displayText, displayNumber, sectionPageCount, pageFormat, chapterNumberText, chapterSeparator);
282390
282987
  const measures = await cache$2.measureBlocks(clonedBlocks, constraints, measureBlock$1, fontSignature);
282391
- const pageLayout = layoutHeaderFooter(clonedBlocks, measures, constraints, kind);
282988
+ const pageLayout = layoutHeaderFooter(clonedBlocks, measures, constraints, kind, remeasureParagraph$1);
282392
282989
  const measuresById = /* @__PURE__ */ new Map;
282393
282990
  for (let i4 = 0;i4 < clonedBlocks.length; i4 += 1)
282394
282991
  measuresById.set(clonedBlocks[i4].id, measures[i4]);
@@ -283251,7 +283848,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
283251
283848
  const blocks2 = blocksByRId.get(group.rId);
283252
283849
  if (!blocks2 || blocks2.length === 0)
283253
283850
  continue;
283254
- const layout$1 = (await layoutHeaderFooterWithCache({ default: blocks2 }, group.sectionConstraints, measureFn, headerMeasureCache, 1, pageResolver, kind)).default?.layout;
283851
+ const layout$1 = (await layoutHeaderFooterWithCache({ default: blocks2 }, group.sectionConstraints, measureFn, headerMeasureCache, 1, pageResolver, kind, undefined, (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent))).default?.layout;
283255
283852
  if (!layout$1 || !(layout$1.height > 0))
283256
283853
  continue;
283257
283854
  const nextHeight = Math.max(0, layout$1.height);
@@ -283268,7 +283865,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
283268
283865
  for (const [rId, blocks2] of blocksByRId) {
283269
283866
  if (!blocks2 || blocks2.length === 0)
283270
283867
  continue;
283271
- const layout$1 = (await layoutHeaderFooterWithCache({ default: blocks2 }, constraints, measureFn, headerMeasureCache, 1, pageResolver, kind)).default?.layout;
283868
+ const layout$1 = (await layoutHeaderFooterWithCache({ default: blocks2 }, constraints, measureFn, headerMeasureCache, 1, pageResolver, kind, undefined, (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent))).default?.layout;
283272
283869
  if (layout$1 && layout$1.height > 0)
283273
283870
  heightsByRId.set(rId, layout$1.height);
283274
283871
  }
@@ -283290,7 +283887,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
283290
283887
  };
283291
283888
  headerContentHeights = {};
283292
283889
  if (hasHeaderBlocks && headerFooter.headerBlocks) {
283293
- const preHeaderLayouts = await layoutHeaderFooterWithCache(headerFooter.headerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT, prelayoutPageResolver, "header", fontSignature);
283890
+ const preHeaderLayouts = await layoutHeaderFooterWithCache(headerFooter.headerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT, prelayoutPageResolver, "header", fontSignature, (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent));
283294
283891
  for (const [type, value] of Object.entries(preHeaderLayouts)) {
283295
283892
  if (!isValidHeaderType(type))
283296
283893
  continue;
@@ -283331,7 +283928,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
283331
283928
  footerContentHeights = {};
283332
283929
  try {
283333
283930
  if (hasFooterBlocks && headerFooter.footerBlocks) {
283334
- const preFooterLayouts = await layoutHeaderFooterWithCache(headerFooter.footerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT, prelayoutPageResolver, "footer", fontSignature);
283931
+ const preFooterLayouts = await layoutHeaderFooterWithCache(headerFooter.footerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT, prelayoutPageResolver, "footer", fontSignature, (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent));
283335
283932
  for (const [type, value] of Object.entries(preFooterLayouts)) {
283336
283933
  if (!isValidFooterType(type))
283337
283934
  continue;
@@ -283420,6 +284017,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
283420
284017
  console.warn(`[incrementalLayout] Page token resolution did not converge after ${maxIterations} iterations - stopping`);
283421
284018
  }
283422
284019
  }
284020
+ hydrateTableTextboxMeasures(currentBlocks, (block, maxWidth) => remeasureParagraph(block, maxWidth));
283423
284021
  const totalTokenTime = performance.now() - pageTokenStart;
283424
284022
  if (iteration > 0) {
283425
284023
  perfLog$1(`[Perf] 4.3 Total page token resolution time: ${totalTokenTime.toFixed(2)}ms`);
@@ -284431,10 +285029,17 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
284431
285029
  chapterSeparator: displayInfo?.chapterSeparator
284432
285030
  };
284433
285031
  } : undefined;
284434
- if (headerFooter.headerBlocks)
284435
- headers = serializeHeaderFooterResults("header", await layoutHeaderFooterWithCache(headerFooter.headerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, FeatureFlags.HEADER_FOOTER_PAGE_TOKENS ? undefined : numberingCtx.totalPages, pageResolver, "header", fontSignature));
284436
- if (headerFooter.footerBlocks)
284437
- footers = serializeHeaderFooterResults("footer", await layoutHeaderFooterWithCache(headerFooter.footerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, FeatureFlags.HEADER_FOOTER_PAGE_TOKENS ? undefined : numberingCtx.totalPages, pageResolver, "footer", fontSignature));
285032
+ const hfRemeasure = (block, maxWidth) => remeasureParagraph(block, maxWidth);
285033
+ if (headerFooter.headerBlocks) {
285034
+ for (const blocks2 of Object.values(headerFooter.headerBlocks))
285035
+ hydrateTableTextboxMeasures(blocks2, hfRemeasure);
285036
+ headers = serializeHeaderFooterResults("header", await layoutHeaderFooterWithCache(headerFooter.headerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, FeatureFlags.HEADER_FOOTER_PAGE_TOKENS ? undefined : numberingCtx.totalPages, pageResolver, "header", fontSignature, (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent)));
285037
+ }
285038
+ if (headerFooter.footerBlocks) {
285039
+ for (const blocks2 of Object.values(headerFooter.footerBlocks))
285040
+ hydrateTableTextboxMeasures(blocks2, hfRemeasure);
285041
+ footers = serializeHeaderFooterResults("footer", await layoutHeaderFooterWithCache(headerFooter.footerBlocks, headerFooter.constraints, measureFn, headerMeasureCache, FeatureFlags.HEADER_FOOTER_PAGE_TOKENS ? undefined : numberingCtx.totalPages, pageResolver, "footer", fontSignature, (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent)));
285042
+ }
284438
285043
  perfLog$1(`[Perf] 4.4 Header/footer layout: ${(performance.now() - hfStart).toFixed(2)}ms`);
284439
285044
  const cacheStats = headerMeasureCache.getStats();
284440
285045
  globalMetrics.recordHeaderFooterCacheMetrics(cacheStats);
@@ -284450,6 +285055,19 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
284450
285055
  extraMeasures
284451
285056
  };
284452
285057
  }
285058
+ function hydrateTableTextboxMeasures(blocks2, remeasure) {
285059
+ for (const block of blocks2) {
285060
+ if (block.kind !== "table")
285061
+ continue;
285062
+ for (const row2 of block.rows ?? [])
285063
+ for (const cell2 of row2.cells ?? [])
285064
+ for (const cellBlock of cell2.blocks ?? [])
285065
+ if (cellBlock.kind === "drawing" && cellBlock.drawingKind === "textboxShape")
285066
+ cellBlock.contentMeasures = layoutTextboxContent(cellBlock, remeasure);
285067
+ else if (cellBlock.kind === "table")
285068
+ hydrateTableTextboxMeasures([cellBlock], remeasure);
285069
+ }
285070
+ }
284453
285071
  function rewriteSectionBreaksForSemanticFlow(blocks2, options) {
284454
285072
  const semanticPageSize = options.pageSize;
284455
285073
  const semanticMargins = options.margins;
@@ -284728,41 +285346,6 @@ async function remeasureAffectedBlocks(blocks2, measures, affectedBlockIds, perB
284728
285346
  }
284729
285347
  return updatedMeasures;
284730
285348
  }
284731
- function calculateSummary(samples) {
284732
- if (samples.length === 0)
284733
- return {
284734
- count: 0,
284735
- min: 0,
284736
- max: 0,
284737
- avg: 0,
284738
- p50: 0,
284739
- p95: 0,
284740
- p99: 0
284741
- };
284742
- const values = samples.map((s2) => s2.value).sort((a2, b$1) => a2 - b$1);
284743
- const count2 = values.length;
284744
- const sum = values.reduce((acc, v) => acc + v, 0);
284745
- return {
284746
- count: count2,
284747
- min: values[0],
284748
- max: values[count2 - 1],
284749
- avg: sum / count2,
284750
- p50: percentile(values, 0.5),
284751
- p95: percentile(values, 0.95),
284752
- p99: percentile(values, 0.99)
284753
- };
284754
- }
284755
- function percentile(sortedValues, p$12) {
284756
- if (sortedValues.length === 0)
284757
- return 0;
284758
- if (sortedValues.length === 1)
284759
- return sortedValues[0];
284760
- const index2 = (sortedValues.length - 1) * p$12;
284761
- const lower = Math.floor(index2);
284762
- const upper = Math.ceil(index2);
284763
- const weight = index2 - lower;
284764
- return sortedValues[lower] * (1 - weight) + sortedValues[upper] * weight;
284765
- }
284766
285349
  function resolveColumnsForHit(layout, page, fragmentY) {
284767
285350
  if (page === undefined)
284768
285351
  return layout.columns;
@@ -285058,6 +285641,54 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
285058
285641
  lineIndex
285059
285642
  };
285060
285643
  }
285644
+ if (fragment2.kind === "drawing" && fragment2.drawingKind === "textboxShape" && block.kind === "drawing" && block.drawingKind === "textboxShape") {
285645
+ const textboxHit = resolveTextboxContentHit(fragment2, block, measure, pageIndex, pageRelativePoint);
285646
+ if (textboxHit) {
285647
+ const { contentBlock, contentMeasure, localX, localY, pageIndex: pageIndex$1, paragraphIndex } = textboxHit;
285648
+ const lineIndex = findLineIndexAtY(contentMeasure.lines, localY, 0, contentMeasure.lines.length);
285649
+ if (lineIndex != null) {
285650
+ const line = contentMeasure.lines[lineIndex];
285651
+ const isRTL = isRtlBlock(contentBlock);
285652
+ const indentLeft = typeof contentBlock.attrs?.indent?.left === "number" ? contentBlock.attrs.indent.left : 0;
285653
+ const indentRight = typeof contentBlock.attrs?.indent?.right === "number" ? contentBlock.attrs.indent.right : 0;
285654
+ const totalIndent = (Number.isFinite(indentLeft) ? indentLeft : 0) + (Number.isFinite(indentRight) ? indentRight : 0);
285655
+ const insets = textboxHit.block.textInsets ?? {
285656
+ top: 0,
285657
+ right: 0,
285658
+ bottom: 0,
285659
+ left: 0
285660
+ };
285661
+ let availableWidth = Math.max(0, textboxHit.fragment.width - insets.left - insets.right - totalIndent);
285662
+ if (totalIndent > textboxHit.fragment.width)
285663
+ console.warn(`[clickToPosition:textbox] Paragraph indents (${totalIndent}px) exceed fragment width (${textboxHit.fragment.width}px) for block ${textboxHit.fragment.blockId}. This may indicate a layout miscalculation. Available width clamped to 0.`);
285664
+ if (lineIndex === 0) {
285665
+ const suppressFLI = contentBlock.attrs?.suppressFirstLineIndent === true;
285666
+ const firstLineOffset = getFirstLineIndentOffset(contentBlock.attrs?.indent, suppressFLI);
285667
+ availableWidth = adjustAvailableWidthForTextIndent(availableWidth, firstLineOffset, line.maxWidth);
285668
+ }
285669
+ const pos = mapPointToPm(contentBlock, line, localX, isRTL, availableWidth);
285670
+ if (pos != null)
285671
+ return {
285672
+ pos,
285673
+ layoutEpoch,
285674
+ blockId: textboxHit.fragment.blockId,
285675
+ pageIndex: pageIndex$1,
285676
+ column: determineColumn(layout, textboxHit.fragment.x, layout.pages[pageIndex$1], textboxHit.fragment.y),
285677
+ lineIndex
285678
+ };
285679
+ }
285680
+ const firstRun = contentBlock.runs?.[0];
285681
+ if (firstRun && firstRun.pmStart != null)
285682
+ return {
285683
+ pos: firstRun.pmStart,
285684
+ layoutEpoch,
285685
+ blockId: textboxHit.fragment.blockId,
285686
+ pageIndex: pageIndex$1,
285687
+ column: determineColumn(layout, textboxHit.fragment.x, layout.pages[pageIndex$1], textboxHit.fragment.y),
285688
+ lineIndex: 0
285689
+ };
285690
+ }
285691
+ }
285061
285692
  if (isAtomicFragment(fragment2)) {
285062
285693
  const pmRange = getAtomicPmRange(fragment2, block);
285063
285694
  const pos = pmRange.pmStart ?? pmRange.pmEnd ?? null;
@@ -285135,6 +285766,41 @@ function clickToPositionGeometry(layout, blocks2, measures, containerPoint, opti
285135
285766
  }
285136
285767
  return null;
285137
285768
  }
285769
+ function calculateSummary(samples) {
285770
+ if (samples.length === 0)
285771
+ return {
285772
+ count: 0,
285773
+ min: 0,
285774
+ max: 0,
285775
+ avg: 0,
285776
+ p50: 0,
285777
+ p95: 0,
285778
+ p99: 0
285779
+ };
285780
+ const values = samples.map((s2) => s2.value).sort((a2, b$1) => a2 - b$1);
285781
+ const count2 = values.length;
285782
+ const sum = values.reduce((acc, v) => acc + v, 0);
285783
+ return {
285784
+ count: count2,
285785
+ min: values[0],
285786
+ max: values[count2 - 1],
285787
+ avg: sum / count2,
285788
+ p50: percentile(values, 0.5),
285789
+ p95: percentile(values, 0.95),
285790
+ p99: percentile(values, 0.99)
285791
+ };
285792
+ }
285793
+ function percentile(sortedValues, p$12) {
285794
+ if (sortedValues.length === 0)
285795
+ return 0;
285796
+ if (sortedValues.length === 1)
285797
+ return sortedValues[0];
285798
+ const index2 = (sortedValues.length - 1) * p$12;
285799
+ const lower = Math.floor(index2);
285800
+ const upper = Math.ceil(index2);
285801
+ const weight = index2 - lower;
285802
+ return sortedValues[lower] * (1 - weight) + sortedValues[upper] * weight;
285803
+ }
285138
285804
  function selectionToRects(layout, blocks2, measures, from$1, to, geometryHelper) {
285139
285805
  if (from$1 === to)
285140
285806
  return [];
@@ -288303,6 +288969,73 @@ function computeTableCaretLayoutRectFromDom({ viewportHost, visibleHost, zoom },
288303
288969
  }
288304
288970
  return null;
288305
288971
  }
288972
+ function findTextboxFragmentElement(viewportHost, blockId, pageIndex) {
288973
+ const pageEl = viewportHost.querySelector(`[data-page-index="${pageIndex}"]`) ?? viewportHost;
288974
+ return Array.from(pageEl.querySelectorAll("[data-block-id]")).find((el) => el.dataset.blockId === blockId) ?? null;
288975
+ }
288976
+ function computeTextboxCaretLayoutRectFromDom({ viewportHost, visibleHost, zoom }, pos, fragment2, _block, pageIndex) {
288977
+ const fragmentEl = findTextboxFragmentElement(viewportHost, fragment2.blockId, pageIndex);
288978
+ if (!fragmentEl)
288979
+ return null;
288980
+ const lineEls = Array.from(fragmentEl.querySelectorAll(".superdoc-line[data-pm-start][data-pm-end]"));
288981
+ if (lineEls.length === 0)
288982
+ return null;
288983
+ for (let lineIdx = 0;lineIdx < lineEls.length; lineIdx++) {
288984
+ const lineEl = lineEls[lineIdx];
288985
+ const pmStart = Number(lineEl.dataset.pmStart ?? "NaN");
288986
+ const pmEnd = Number(lineEl.dataset.pmEnd ?? "NaN");
288987
+ if (!Number.isFinite(pmStart) || !Number.isFinite(pmEnd))
288988
+ continue;
288989
+ const isLastLine = lineIdx === lineEls.length - 1;
288990
+ if (pos < pmStart || (isLastLine ? pos > pmEnd : pos >= pmEnd))
288991
+ continue;
288992
+ const spanEls = Array.from(lineEl.querySelectorAll("span[data-pm-start][data-pm-end]"));
288993
+ for (let spanIdx = 0;spanIdx < spanEls.length; spanIdx++) {
288994
+ const spanEl = spanEls[spanIdx];
288995
+ const spanStart = Number(spanEl.dataset.pmStart ?? "NaN");
288996
+ const spanEnd = Number(spanEl.dataset.pmEnd ?? "NaN");
288997
+ if (!Number.isFinite(spanStart) || !Number.isFinite(spanEnd))
288998
+ continue;
288999
+ const isLastSpan = spanIdx === spanEls.length - 1;
289000
+ if (pos < spanStart || (isLastSpan ? pos > spanEnd : pos >= spanEnd))
289001
+ continue;
289002
+ const textNode = spanEl.firstChild;
289003
+ if (!textNode || textNode.nodeType !== Node.TEXT_NODE) {
289004
+ const spanRect = spanEl.getBoundingClientRect();
289005
+ const viewportRect$2 = viewportHost.getBoundingClientRect();
289006
+ return {
289007
+ pageIndex,
289008
+ x: (spanRect.left - viewportRect$2.left + visibleHost.scrollLeft) / zoom,
289009
+ y: (spanRect.top - viewportRect$2.top + visibleHost.scrollTop) / zoom,
289010
+ height: spanRect.height / zoom
289011
+ };
289012
+ }
289013
+ const text5 = textNode.textContent ?? "";
289014
+ const charOffset = Math.max(0, Math.min(text5.length, pos - spanStart));
289015
+ const range = document.createRange();
289016
+ range.setStart(textNode, charOffset);
289017
+ range.setEnd(textNode, charOffset);
289018
+ const rangeRect = range.getBoundingClientRect();
289019
+ const viewportRect$1 = viewportHost.getBoundingClientRect();
289020
+ const lineRect$1 = lineEl.getBoundingClientRect();
289021
+ return {
289022
+ pageIndex,
289023
+ x: (rangeRect.left - viewportRect$1.left + visibleHost.scrollLeft) / zoom,
289024
+ y: (lineRect$1.top - viewportRect$1.top + visibleHost.scrollTop) / zoom,
289025
+ height: lineRect$1.height / zoom
289026
+ };
289027
+ }
289028
+ const lineRect = lineEl.getBoundingClientRect();
289029
+ const viewportRect = viewportHost.getBoundingClientRect();
289030
+ return {
289031
+ pageIndex,
289032
+ x: (lineRect.left - viewportRect.left + visibleHost.scrollLeft) / zoom,
289033
+ y: (lineRect.top - viewportRect.top + visibleHost.scrollTop) / zoom,
289034
+ height: lineRect.height / zoom
289035
+ };
289036
+ }
289037
+ return null;
289038
+ }
288306
289039
  function findLineContainingPos(block, measure, fromLine, toLine, pos) {
288307
289040
  if (measure.kind !== "paragraph" || block.kind !== "paragraph")
288308
289041
  return null;
@@ -288359,6 +289092,12 @@ function computeCaretLayoutRectGeometry({ layout, blocks: blocks2, measures, pai
288359
289092
  visibleHost,
288360
289093
  zoom
288361
289094
  }, effectivePos, hit.fragment, block, measure, hit.pageIndex);
289095
+ if (hit.fragment.kind === "drawing" && block?.kind === "drawing" && block.drawingKind === "textboxShape" && measure?.kind === "drawing")
289096
+ return computeTextboxCaretLayoutRectFromDom({
289097
+ viewportHost,
289098
+ visibleHost,
289099
+ zoom
289100
+ }, effectivePos, hit.fragment, block, hit.pageIndex);
288362
289101
  if (!block || block.kind !== "paragraph" || measure?.kind !== "paragraph")
288363
289102
  return null;
288364
289103
  if (hit.fragment.kind !== "para")
@@ -292980,7 +293719,7 @@ async function layoutBlocksByRId(kind, blocksByRId, referencedRIds, constraints,
292980
293719
  if (!blocks2 || blocks2.length === 0)
292981
293720
  continue;
292982
293721
  try {
292983
- const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, constraints, (block, c) => measureBlock(block, c, fontMeasureContext), undefined, undefined, pageResolver, kind, fontSignature);
293722
+ const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, constraints, (block, c) => measureBlock(block, c, fontMeasureContext), undefined, undefined, pageResolver, kind, fontSignature, (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent));
292984
293723
  if (batchResult.default)
292985
293724
  layoutsByRId.set(rId, {
292986
293725
  kind,
@@ -293040,7 +293779,7 @@ async function layoutWithPerSectionConstraints(kind, blocksByRId, sectionMetadat
293040
293779
  if (!blocks2 || blocks2.length === 0)
293041
293780
  continue;
293042
293781
  try {
293043
- const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, group.sectionConstraints, (block, c) => measureBlock(block, c, fontMeasureContext), undefined, undefined, pageResolver, kind, fontSignature);
293782
+ const batchResult = await layoutHeaderFooterWithCache({ default: blocks2 }, group.sectionConstraints, (block, c) => measureBlock(block, c, fontMeasureContext), undefined, undefined, pageResolver, kind, fontSignature, (block, maxWidth, firstLineIndent) => remeasureParagraph(block, maxWidth, firstLineIndent));
293044
293783
  if (batchResult.default)
293045
293784
  for (const sectionIndex of group.sectionIndices) {
293046
293785
  const contentWidth = buildSectionContentWidth(sectionMetadata.find((s2) => s2.sectionIndex === sectionIndex), fallbackConstraints);
@@ -317032,6 +317771,7 @@ menclose::after {
317032
317771
  drawingWrapper.style.flexShrink = "0";
317033
317772
  drawingWrapper.style.maxWidth = "100%";
317034
317773
  drawingWrapper.style.boxSizing = "border-box";
317774
+ drawingWrapper.dataset.blockId = block.id;
317035
317775
  applySdtDataset$1(drawingWrapper, block.attrs);
317036
317776
  const drawingInner = doc$12.createElement("div");
317037
317777
  drawingInner.classList.add("superdoc-table-drawing");
@@ -317201,6 +317941,7 @@ menclose::after {
317201
317941
  drawingWrapper.style.maxWidth = "100%";
317202
317942
  drawingWrapper.style.boxSizing = "border-box";
317203
317943
  drawingWrapper.style.zIndex = String(zIndex);
317944
+ drawingWrapper.dataset.blockId = anchoredBlock.id;
317204
317945
  applySdtDataset$1(drawingWrapper, anchoredBlock.attrs);
317205
317946
  const drawingInner = doc$12.createElement("div");
317206
317947
  drawingInner.classList.add("superdoc-table-drawing");
@@ -321240,17 +321981,19 @@ menclose::after {
321240
321981
  throw new Error("DomPainter: document is not available");
321241
321982
  if (block.drawingKind === "image")
321242
321983
  return createDrawingImageElement(this.doc, block, this.buildImageHyperlinkAnchor.bind(this));
321243
- if (block.drawingKind === "vectorShape")
321244
- return this.createVectorShapeElement(block, fragment2.geometry, false, 1, 1, context);
321984
+ if (block.drawingKind === "vectorShape" || block.drawingKind === "textboxShape")
321985
+ return this.createVectorShapeElement(block, fragment2.geometry, false, 1, 1, context, fragment2);
321245
321986
  if (block.drawingKind === "shapeGroup")
321246
321987
  return this.createShapeGroupElement(block, context);
321247
321988
  if (block.drawingKind === "chart")
321248
321989
  return this.createChartElement(block);
321249
321990
  return this.createDrawingPlaceholder();
321250
321991
  }
321251
- createVectorShapeElement(block, geometry, applyTransforms = false, groupScaleX = 1, groupScaleY = 1, context) {
321992
+ createVectorShapeElement(block, geometry, applyTransforms = false, groupScaleX = 1, groupScaleY = 1, context, fragment2) {
321252
321993
  const container = this.doc.createElement("div");
321253
321994
  container.classList.add("superdoc-vector-shape");
321995
+ if (block.drawingKind === "textboxShape")
321996
+ container.classList.add("superdoc-textbox-shape");
321254
321997
  container.style.width = "100%";
321255
321998
  container.style.height = "100%";
321256
321999
  container.style.position = "relative";
@@ -321281,8 +322024,8 @@ menclose::after {
321281
322024
  }
321282
322025
  this.applyLineEnds(svgElement, block);
321283
322026
  contentContainer.appendChild(svgElement);
321284
- if (this.hasShapeTextContent(block.textContent)) {
321285
- const textElement = this.createShapeTextElement(block, innerWidth, innerHeight2, groupScaleX, groupScaleY, context);
322027
+ if (block.drawingKind === "textboxShape" || this.hasShapeTextContent(block.textContent)) {
322028
+ const textElement = block.drawingKind === "textboxShape" ? this.createTextboxContentElement(block, fragment2, innerWidth, innerHeight2, context) : this.createShapeTextElement(block, innerWidth, innerHeight2, groupScaleX, groupScaleY, context);
321286
322029
  contentContainer.appendChild(textElement);
321287
322030
  }
321288
322031
  container.appendChild(contentContainer);
@@ -321290,8 +322033,8 @@ menclose::after {
321290
322033
  }
321291
322034
  }
321292
322035
  this.applyFallbackShapeStyle(contentContainer, block);
321293
- if (this.hasShapeTextContent(block.textContent)) {
321294
- const textElement = this.createShapeTextElement(block, innerWidth, innerHeight2, groupScaleX, groupScaleY, context);
322036
+ if (block.drawingKind === "textboxShape" || this.hasShapeTextContent(block.textContent)) {
322037
+ const textElement = block.drawingKind === "textboxShape" ? this.createTextboxContentElement(block, fragment2, innerWidth, innerHeight2, context) : this.createShapeTextElement(block, innerWidth, innerHeight2, groupScaleX, groupScaleY, context);
321295
322038
  contentContainer.appendChild(textElement);
321296
322039
  }
321297
322040
  container.appendChild(contentContainer);
@@ -321331,6 +322074,47 @@ menclose::after {
321331
322074
  return this.createWordArtTextElement(textContent$1, block.textAlign ?? "center", block.textInsets, width, height, context);
321332
322075
  return this.createFallbackTextElement(textContent$1, block.textAlign ?? "center", block.textVerticalAlign, block.textInsets, groupScaleX, groupScaleY, context);
321333
322076
  }
322077
+ createTextboxContentElement(block, fragment2, width, height, context) {
322078
+ const contentMeasures = fragment2?.contentMeasures ?? block.contentMeasures;
322079
+ if (!Array.isArray(contentMeasures) || contentMeasures.length === 0)
322080
+ return this.hasShapeTextContent(block.textContent) ? this.createShapeTextElement(block, width, height, 1, 1, context) : this.doc.createElement("div");
322081
+ const contentRoot = this.doc.createElement("div");
322082
+ contentRoot.style.position = "absolute";
322083
+ contentRoot.style.top = "0";
322084
+ contentRoot.style.left = "0";
322085
+ contentRoot.style.width = "100%";
322086
+ contentRoot.style.height = "100%";
322087
+ contentRoot.style.display = "flex";
322088
+ contentRoot.style.flexDirection = "column";
322089
+ contentRoot.style.boxSizing = "border-box";
322090
+ contentRoot.style.overflow = "hidden";
322091
+ const insets = block.textInsets ?? {
322092
+ top: 0,
322093
+ right: 0,
322094
+ bottom: 0,
322095
+ left: 0
322096
+ };
322097
+ contentRoot.style.padding = `${insets.top}px ${insets.right}px ${insets.bottom}px ${insets.left}px`;
322098
+ const verticalAlign = block.textVerticalAlign ?? "top";
322099
+ contentRoot.style.justifyContent = verticalAlign === "bottom" ? "flex-end" : verticalAlign === "center" ? "center" : "flex-start";
322100
+ const linesHost = this.doc.createElement("div");
322101
+ linesHost.style.display = "flex";
322102
+ linesHost.style.flexDirection = "column";
322103
+ linesHost.style.minWidth = "0";
322104
+ linesHost.style.width = "100%";
322105
+ const renderContext = context ?? this.defaultFragmentRenderContext();
322106
+ const availableWidth = Math.max(1, width - insets.left - insets.right);
322107
+ block.contentBlocks.forEach((paragraphBlock, paragraphIndex) => {
322108
+ const measure = contentMeasures[paragraphIndex];
322109
+ if (!measure?.lines)
322110
+ return;
322111
+ measure.lines.forEach((line, lineIndex) => {
322112
+ linesHost.appendChild(this.renderLine(paragraphBlock, line, renderContext, availableWidth, lineIndex));
322113
+ });
322114
+ });
322115
+ contentRoot.appendChild(linesHost);
322116
+ return contentRoot;
322117
+ }
321334
322118
  shouldUseWordArtTextRenderer(block) {
321335
322119
  return block.attrs?.isWordArt === true && this.hasShapeTextContent(block.textContent);
321336
322120
  }
@@ -321883,7 +322667,7 @@ menclose::after {
321883
322667
  return createDrawingImageElement(this.doc, block, this.buildImageHyperlinkAnchor.bind(this));
321884
322668
  if (block.drawingKind === "shapeGroup")
321885
322669
  return this.createShapeGroupElement(block, context);
321886
- if (block.drawingKind === "vectorShape")
322670
+ if (block.drawingKind === "vectorShape" || block.drawingKind === "textboxShape")
321887
322671
  return this.createVectorShapeElement(block, block.geometry, false, 1, 1, context);
321888
322672
  if (block.drawingKind === "chart")
321889
322673
  return this.createChartElement(block);
@@ -321968,6 +322752,13 @@ menclose::after {
321968
322752
  };
321969
322753
  return runContext;
321970
322754
  }
322755
+ defaultFragmentRenderContext() {
322756
+ return {
322757
+ pageNumber: 1,
322758
+ totalPages: 1,
322759
+ section: "body"
322760
+ };
322761
+ }
321971
322762
  updateFragmentElement(el, fragment2, section, resolvedItem) {
321972
322763
  const fragmentItem = resolvedItem?.kind === "fragment" ? resolvedItem : undefined;
321973
322764
  const story = resolveSectionStory(section);
@@ -322464,6 +323255,15 @@ menclose::after {
322464
323255
  if (!lum)
322465
323256
  return "";
322466
323257
  return [lum.bright ?? "", lum.contrast ?? ""].join(":");
323258
+ }, drawingTextVersion = (block) => {
323259
+ const textboxContentBlocks = "contentBlocks" in block && Array.isArray(block.contentBlocks) ? block.contentBlocks.map((contentBlock) => deriveBlockVersion(contentBlock)).join(";") : "";
323260
+ return JSON.stringify([
323261
+ block.textAlign ?? "",
323262
+ block.textVerticalAlign ?? "",
323263
+ block.textInsets ?? null,
323264
+ block.textContent ?? null,
323265
+ textboxContentBlocks
323266
+ ]);
322467
323267
  }, renderedBlockImageVersion = (image2) => [
322468
323268
  image2.src ?? "",
322469
323269
  image2.width ?? "",
@@ -322671,10 +323471,10 @@ menclose::after {
322671
323471
  if (block.kind === "drawing") {
322672
323472
  if (block.drawingKind === "image")
322673
323473
  return ["drawing:image", renderedBlockImageVersion(block)].join("|");
322674
- if (block.drawingKind === "vectorShape") {
323474
+ if (block.drawingKind === "vectorShape" || block.drawingKind === "textboxShape") {
322675
323475
  const vector = block;
322676
323476
  return [
322677
- "drawing:vector",
323477
+ block.drawingKind === "textboxShape" ? "drawing:textbox" : "drawing:vector",
322678
323478
  vector.shapeKind ?? "",
322679
323479
  vector.fillColor ?? "",
322680
323480
  vector.strokeColor ?? "",
@@ -322683,7 +323483,8 @@ menclose::after {
322683
323483
  vector.geometry.height,
322684
323484
  vector.geometry.rotation ?? 0,
322685
323485
  vector.geometry.flipH ? 1 : 0,
322686
- vector.geometry.flipV ? 1 : 0
323486
+ vector.geometry.flipV ? 1 : 0,
323487
+ drawingTextVersion(vector)
322687
323488
  ].join("|");
322688
323489
  }
322689
323490
  if (block.drawingKind === "shapeGroup") {
@@ -323379,6 +324180,23 @@ menclose::after {
323379
324180
  block.textVerticalAlign ?? "",
323380
324181
  JSON.stringify(block.textInsets ?? null)
323381
324182
  ].join(":");
324183
+ if (block.drawingKind === "textboxShape")
324184
+ return [
324185
+ "drawing:textbox",
324186
+ hashDrawingGeometry(block.geometry),
324187
+ block.shapeKind ?? "",
324188
+ JSON.stringify(block.fillColor ?? null),
324189
+ JSON.stringify(block.strokeColor ?? null),
324190
+ block.strokeWidth ?? "",
324191
+ JSON.stringify(block.customGeometry ?? null),
324192
+ JSON.stringify(block.lineEnds ?? null),
324193
+ JSON.stringify(block.effectExtent ?? null),
324194
+ JSON.stringify(block.textContent ?? null),
324195
+ block.textAlign ?? "",
324196
+ block.textVerticalAlign ?? "",
324197
+ JSON.stringify(block.textInsets ?? null),
324198
+ block.contentBlocks.map((contentBlock) => `${contentBlock.id}:${hashRuns(contentBlock)}`).join("|")
324199
+ ].join(":");
323382
324200
  if (block.drawingKind === "shapeGroup")
323383
324201
  return [
323384
324202
  "drawing:shapeGroup",
@@ -324413,8 +325231,10 @@ menclose::after {
324413
325231
  return false;
324414
325232
  if (a2.drawingKind === "image" && b$1.drawingKind === "image")
324415
325233
  return imageBlocksEqual(a2, b$1);
324416
- if (a2.drawingKind === "vectorShape" && b$1.drawingKind === "vectorShape")
324417
- return drawingGeometryEqual(a2.geometry, b$1.geometry) && a2.shapeKind === b$1.shapeKind && a2.fillColor === b$1.fillColor && a2.strokeColor === b$1.strokeColor && a2.strokeWidth === b$1.strokeWidth;
325234
+ if ((a2.drawingKind === "vectorShape" || a2.drawingKind === "textboxShape") && (b$1.drawingKind === "vectorShape" || b$1.drawingKind === "textboxShape")) {
325235
+ const textboxContentEqual = a2.drawingKind !== "textboxShape" || b$1.drawingKind !== "textboxShape" || jsonEqual(a2.contentBlocks, b$1.contentBlocks);
325236
+ return drawingGeometryEqual(a2.geometry, b$1.geometry) && a2.shapeKind === b$1.shapeKind && a2.fillColor === b$1.fillColor && a2.strokeColor === b$1.strokeColor && a2.strokeWidth === b$1.strokeWidth && a2.textAlign === b$1.textAlign && a2.textVerticalAlign === b$1.textVerticalAlign && jsonEqual(a2.textInsets, b$1.textInsets) && jsonEqual(a2.textContent, b$1.textContent) && jsonEqual(a2.customGeometry, b$1.customGeometry) && jsonEqual(a2.lineEnds, b$1.lineEnds) && jsonEqual(a2.effectExtent, b$1.effectExtent) && textboxContentEqual;
325237
+ }
324418
325238
  if (a2.drawingKind === "shapeGroup" && b$1.drawingKind === "shapeGroup")
324419
325239
  return drawingGeometryEqual(a2.geometry, b$1.geometry) && shapeGroupTransformEqual(a2.groupTransform, b$1.groupTransform) && shapeGroupSizeEqual(a2.size, b$1.size) && shapeGroupChildrenEqual(a2.shapes, b$1.shapes);
324420
325240
  if (a2.drawingKind === "chart" && b$1.drawingKind === "chart")
@@ -325238,7 +326058,329 @@ menclose::after {
325238
326058
  });
325239
326059
  });
325240
326060
  return results;
325241
- }, PRELAYOUT_CHAPTER_MARKER_SEPARATOR_RE, PRELAYOUT_MIN_PAGE_COMPONENT = 10, PageGeometryHelper = class {
326061
+ }, PRELAYOUT_CHAPTER_MARKER_SEPARATOR_RE, PRELAYOUT_MIN_PAGE_COMPONENT = 10, isAtomicFragment = (fragment2) => {
326062
+ return fragment2.kind === "drawing" || fragment2.kind === "image";
326063
+ }, blockPmRangeFromAttrs = (block) => {
326064
+ const attrs = block?.attrs;
326065
+ const pmStart = typeof attrs?.pmStart === "number" ? attrs.pmStart : undefined;
326066
+ return {
326067
+ pmStart,
326068
+ pmEnd: typeof attrs?.pmEnd === "number" ? attrs.pmEnd : pmStart != null ? pmStart + 1 : undefined
326069
+ };
326070
+ }, getAtomicPmRange = (fragment2, block) => {
326071
+ return {
326072
+ pmStart: typeof fragment2.pmStart === "number" ? fragment2.pmStart : blockPmRangeFromAttrs(block).pmStart,
326073
+ pmEnd: typeof fragment2.pmEnd === "number" ? fragment2.pmEnd : blockPmRangeFromAttrs(block).pmEnd
326074
+ };
326075
+ }, isRtlBlock = (block) => {
326076
+ if (block.kind !== "paragraph")
326077
+ return false;
326078
+ return getParagraphInlineDirection(block.attrs) === "rtl";
326079
+ }, determineColumn = (layout, fragmentX, page, fragmentY) => {
326080
+ const columns = resolveColumnsForHit(layout, page, fragmentY);
326081
+ if (!columns || columns.count <= 1)
326082
+ return 0;
326083
+ const pageWidth = page?.size?.w ?? layout.pageSize.w;
326084
+ const margins = page?.margins ?? layout.pages[0]?.margins;
326085
+ const marginLeft = Math.max(0, margins?.left ?? 0);
326086
+ const marginRight = Math.max(0, margins?.right ?? 0);
326087
+ return getColumnAtX(getColumnGeometry(normalizeColumnLayout(columns, Math.max(1, pageWidth - (marginLeft + marginRight)))), fragmentX, marginLeft);
326088
+ }, determineTableColumn = (layout, fragment2, page) => {
326089
+ if (typeof fragment2.columnIndex === "number") {
326090
+ const count2 = resolveColumnsForHit(layout, page, fragment2.y)?.count ?? 1;
326091
+ return Math.max(0, Math.min(Math.max(0, count2 - 1), fragment2.columnIndex));
326092
+ }
326093
+ return determineColumn(layout, fragment2.x, page, fragment2.y);
326094
+ }, findLineIndexAtY = (lines, offsetY, fromLine, toLine) => {
326095
+ if (!lines || lines.length === 0)
326096
+ return null;
326097
+ const lineCount = lines.length;
326098
+ if (fromLine < 0 || toLine > lineCount || fromLine >= toLine)
326099
+ return null;
326100
+ let cursor = 0;
326101
+ for (let i4 = fromLine;i4 < toLine; i4 += 1) {
326102
+ const line = lines[i4];
326103
+ if (!line)
326104
+ return null;
326105
+ const next2 = cursor + line.lineHeight;
326106
+ if (offsetY >= cursor && offsetY < next2)
326107
+ return i4;
326108
+ cursor = next2;
326109
+ }
326110
+ return toLine - 1;
326111
+ }, mapPointToPm = (block, line, x, isRTL, availableWidthOverride, alignmentOverride) => {
326112
+ if (block.kind !== "paragraph")
326113
+ return null;
326114
+ const range = computeLinePmRange(block, line);
326115
+ if (range.pmStart == null || range.pmEnd == null)
326116
+ return null;
326117
+ const result = findCharacterAtX(block, line, x, range.pmStart, availableWidthOverride, alignmentOverride);
326118
+ let pmPosition = result.pmPosition;
326119
+ if (isRTL) {
326120
+ const charOffset = result.charOffset;
326121
+ const charsInLine = Math.max(1, line.toChar - line.fromChar);
326122
+ pmPosition = charOffsetToPm(block, line, Math.max(0, Math.min(charsInLine, charsInLine - charOffset)), range.pmStart);
326123
+ }
326124
+ return pmPosition;
326125
+ }, calculatePageTopFallback = (layout, pageIndex) => {
326126
+ const pageGap = layout.pageGap ?? 0;
326127
+ let y$1 = 0;
326128
+ for (let i4 = 0;i4 < pageIndex; i4++) {
326129
+ const pageHeight = layout.pages[i4]?.size?.h ?? layout.pageSize.h;
326130
+ y$1 += pageHeight + pageGap;
326131
+ }
326132
+ return y$1;
326133
+ }, hitTestAtomicFragment = (pageHit, blocks2, measures, point5) => {
326134
+ for (const fragment2 of pageHit.page.fragments) {
326135
+ if (!isAtomicFragment(fragment2))
326136
+ continue;
326137
+ const withinX = point5.x >= fragment2.x && point5.x <= fragment2.x + fragment2.width;
326138
+ const withinY = point5.y >= fragment2.y && point5.y <= fragment2.y + fragment2.height;
326139
+ if (!withinX || !withinY)
326140
+ continue;
326141
+ const blockIndex = findBlockIndexByFragmentId(blocks2, fragment2.blockId);
326142
+ if (blockIndex === -1)
326143
+ continue;
326144
+ const block = blocks2[blockIndex];
326145
+ const measure = measures[blockIndex];
326146
+ if (!block || !measure)
326147
+ continue;
326148
+ return {
326149
+ fragment: fragment2,
326150
+ block,
326151
+ measure,
326152
+ pageIndex: pageHit.pageIndex,
326153
+ pageY: 0
326154
+ };
326155
+ }
326156
+ return null;
326157
+ }, hitTestTableFragment = (pageHit, blocks2, measures, point5) => {
326158
+ for (const fragment2 of pageHit.page.fragments) {
326159
+ if (fragment2.kind !== "table")
326160
+ continue;
326161
+ const tableFragment = fragment2;
326162
+ const withinX = point5.x >= tableFragment.x && point5.x <= tableFragment.x + tableFragment.width;
326163
+ const withinY = point5.y >= tableFragment.y && point5.y <= tableFragment.y + tableFragment.height;
326164
+ if (!withinX || !withinY)
326165
+ continue;
326166
+ const blockIndex = blocks2.findIndex((block$1) => block$1.id === tableFragment.blockId);
326167
+ if (blockIndex === -1)
326168
+ continue;
326169
+ const block = blocks2[blockIndex];
326170
+ const measure = measures[blockIndex];
326171
+ if (!block || block.kind !== "table" || !measure || measure.kind !== "table")
326172
+ continue;
326173
+ const tableBlock = block;
326174
+ const tableMeasure = measure;
326175
+ const localX = point5.x - tableFragment.x;
326176
+ const localY = point5.y - tableFragment.y;
326177
+ let rowY = 0;
326178
+ let rowIndex = -1;
326179
+ if (tableMeasure.rows.length === 0 || tableBlock.rows.length === 0)
326180
+ continue;
326181
+ for (let r$1 = tableFragment.fromRow;r$1 < tableFragment.toRow && r$1 < tableMeasure.rows.length; r$1++) {
326182
+ const rowMeasure$1 = tableMeasure.rows[r$1];
326183
+ if (localY >= rowY && localY < rowY + rowMeasure$1.height) {
326184
+ rowIndex = r$1;
326185
+ break;
326186
+ }
326187
+ rowY += rowMeasure$1.height;
326188
+ }
326189
+ if (rowIndex === -1) {
326190
+ rowIndex = Math.min(tableFragment.toRow - 1, tableMeasure.rows.length - 1);
326191
+ if (rowIndex < tableFragment.fromRow)
326192
+ continue;
326193
+ }
326194
+ const rowMeasure = tableMeasure.rows[rowIndex];
326195
+ const row2 = tableBlock.rows[rowIndex];
326196
+ if (!rowMeasure || !row2)
326197
+ continue;
326198
+ const firstCellGridStart = rowMeasure.cells[0]?.gridColumnStart ?? 0;
326199
+ let colX = 0;
326200
+ if (firstCellGridStart > 0 && tableMeasure.columnWidths)
326201
+ for (let col = 0;col < firstCellGridStart && col < tableMeasure.columnWidths.length; col++)
326202
+ colX += tableMeasure.columnWidths[col];
326203
+ const initialColX = colX;
326204
+ let colIndex = -1;
326205
+ if (rowMeasure.cells.length === 0 || row2.cells.length === 0)
326206
+ continue;
326207
+ for (let c = 0;c < rowMeasure.cells.length; c++) {
326208
+ const cellMeasure$1 = rowMeasure.cells[c];
326209
+ if (localX >= colX && localX < colX + cellMeasure$1.width) {
326210
+ colIndex = c;
326211
+ break;
326212
+ }
326213
+ colX += cellMeasure$1.width;
326214
+ }
326215
+ if (colIndex === -1) {
326216
+ if (localX < initialColX)
326217
+ colIndex = 0;
326218
+ else
326219
+ colIndex = rowMeasure.cells.length - 1;
326220
+ if (colIndex < 0)
326221
+ continue;
326222
+ }
326223
+ const cellMeasure = rowMeasure.cells[colIndex];
326224
+ const cell2 = row2.cells[colIndex];
326225
+ if (!cellMeasure || !cell2)
326226
+ continue;
326227
+ const cellBlocks = cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
326228
+ const rawMeasures = cellMeasure.blocks ?? (cellMeasure.paragraph ? [cellMeasure.paragraph] : []);
326229
+ const cellBlockMeasures = (Array.isArray(rawMeasures) ? rawMeasures : []).filter((m$1) => m$1 != null && typeof m$1 === "object" && ("kind" in m$1));
326230
+ let blockStartY = 0;
326231
+ let blockStartGlobalLines = 0;
326232
+ const getBlockHeight = (m$1) => {
326233
+ if (!m$1)
326234
+ return 0;
326235
+ if ("totalHeight" in m$1 && typeof m$1.totalHeight === "number")
326236
+ return m$1.totalHeight;
326237
+ if ("height" in m$1 && typeof m$1.height === "number")
326238
+ return m$1.height;
326239
+ return 0;
326240
+ };
326241
+ let nearestParagraphHit = null;
326242
+ for (let i4 = 0;i4 < cellBlocks.length && i4 < cellBlockMeasures.length; i4++) {
326243
+ const cellBlock = cellBlocks[i4];
326244
+ const cellBlockMeasure = cellBlockMeasures[i4];
326245
+ if (cellBlock?.kind !== "paragraph" || cellBlockMeasure?.kind !== "paragraph") {
326246
+ blockStartY += getBlockHeight(cellBlockMeasure);
326247
+ continue;
326248
+ }
326249
+ const blockHeight = getBlockHeight(cellBlockMeasure);
326250
+ const blockEndY = blockStartY + blockHeight;
326251
+ const padding = cell2.attrs?.padding ?? {
326252
+ top: 0,
326253
+ left: 4,
326254
+ right: 4,
326255
+ bottom: 0
326256
+ };
326257
+ const cellLocalX = localX - colX - (padding.left ?? 4);
326258
+ const cellLocalY = localY - rowY - (padding.top ?? 0);
326259
+ const paragraphBlock = cellBlock;
326260
+ const paragraphMeasure = cellBlockMeasure;
326261
+ if (cellLocalY >= blockStartY && cellLocalY < blockEndY) {
326262
+ const unclampedLocalY = cellLocalY - blockStartY;
326263
+ const localYWithinBlock = Math.max(0, Math.min(unclampedLocalY, Math.max(blockHeight, 0)));
326264
+ return {
326265
+ fragment: tableFragment,
326266
+ block: tableBlock,
326267
+ measure: tableMeasure,
326268
+ pageIndex: pageHit.pageIndex,
326269
+ cellRowIndex: rowIndex,
326270
+ cellColIndex: colIndex,
326271
+ cellBlock: paragraphBlock,
326272
+ cellMeasure: paragraphMeasure,
326273
+ localX: Math.max(0, cellLocalX),
326274
+ localY: Math.max(0, localYWithinBlock),
326275
+ blockStartGlobal: blockStartGlobalLines
326276
+ };
326277
+ }
326278
+ const distanceToBlock = cellLocalY < blockStartY ? blockStartY - cellLocalY : Math.max(0, cellLocalY - blockEndY);
326279
+ if (!nearestParagraphHit || distanceToBlock < nearestParagraphHit.distance) {
326280
+ const unclampedLocalY = cellLocalY - blockStartY;
326281
+ nearestParagraphHit = {
326282
+ cellBlock: paragraphBlock,
326283
+ cellMeasure: paragraphMeasure,
326284
+ localX: Math.max(0, cellLocalX),
326285
+ localY: Math.max(0, Math.min(unclampedLocalY, Math.max(blockHeight, 0))),
326286
+ blockStartGlobal: blockStartGlobalLines,
326287
+ distance: distanceToBlock
326288
+ };
326289
+ }
326290
+ blockStartY = blockEndY;
326291
+ blockStartGlobalLines += paragraphMeasure.lines.length;
326292
+ }
326293
+ if (nearestParagraphHit)
326294
+ return {
326295
+ fragment: tableFragment,
326296
+ block: tableBlock,
326297
+ measure: tableMeasure,
326298
+ pageIndex: pageHit.pageIndex,
326299
+ cellRowIndex: rowIndex,
326300
+ cellColIndex: colIndex,
326301
+ cellBlock: nearestParagraphHit.cellBlock,
326302
+ cellMeasure: nearestParagraphHit.cellMeasure,
326303
+ localX: nearestParagraphHit.localX,
326304
+ localY: nearestParagraphHit.localY,
326305
+ blockStartGlobal: nearestParagraphHit.blockStartGlobal
326306
+ };
326307
+ }
326308
+ return null;
326309
+ }, resolveTextboxContentHit = (fragment2, block, measure, pageIndex, point5) => {
326310
+ const fragmentWithContent = fragment2;
326311
+ const contentMeasures = Array.isArray(fragmentWithContent.contentMeasures) ? fragmentWithContent.contentMeasures : Array.isArray(block.contentMeasures) ? block.contentMeasures : [];
326312
+ const contentBlocks = Array.isArray(block.contentBlocks) ? block.contentBlocks : [];
326313
+ if (contentMeasures.length === 0 || contentBlocks.length === 0)
326314
+ return null;
326315
+ const insets = block.textInsets ?? {
326316
+ top: 0,
326317
+ right: 0,
326318
+ bottom: 0,
326319
+ left: 0
326320
+ };
326321
+ const localX = Math.max(0, point5.x - fragment2.x - insets.left);
326322
+ const rawLocalY = point5.y - fragment2.y - insets.top;
326323
+ const totalContentHeight = contentMeasures.reduce((sum, m$1) => sum + (m$1?.kind === "paragraph" ? m$1.totalHeight ?? 0 : 0), 0);
326324
+ const availableHeight = Math.max(0, fragment2.height - insets.top - insets.bottom);
326325
+ const verticalAlign = block.textVerticalAlign ?? "top";
326326
+ let contentOffset = 0;
326327
+ if (verticalAlign === "center")
326328
+ contentOffset = Math.max(0, (availableHeight - totalContentHeight) / 2);
326329
+ else if (verticalAlign === "bottom")
326330
+ contentOffset = Math.max(0, availableHeight - totalContentHeight);
326331
+ const localY = rawLocalY - contentOffset;
326332
+ let paragraphStartY = 0;
326333
+ let blockStartGlobal = 0;
326334
+ let nearestParagraphHit = null;
326335
+ for (let i4 = 0;i4 < contentBlocks.length && i4 < contentMeasures.length; i4 += 1) {
326336
+ const contentBlock = contentBlocks[i4];
326337
+ const contentMeasure = contentMeasures[i4];
326338
+ if (contentBlock?.kind !== "paragraph" || contentMeasure?.kind !== "paragraph")
326339
+ continue;
326340
+ const paragraphHeight = contentMeasure.totalHeight;
326341
+ const paragraphEndY = paragraphStartY + paragraphHeight;
326342
+ if (localY >= paragraphStartY && localY < paragraphEndY)
326343
+ return {
326344
+ fragment: fragment2,
326345
+ block,
326346
+ measure,
326347
+ pageIndex,
326348
+ contentBlock,
326349
+ contentMeasure,
326350
+ paragraphIndex: i4,
326351
+ localX,
326352
+ localY: Math.max(0, Math.min(localY - paragraphStartY, Math.max(paragraphHeight, 0))),
326353
+ blockStartGlobal
326354
+ };
326355
+ const distanceToParagraph = localY < paragraphStartY ? paragraphStartY - localY : Math.max(0, localY - paragraphEndY);
326356
+ if (!nearestParagraphHit || distanceToParagraph < nearestParagraphHit.distance)
326357
+ nearestParagraphHit = {
326358
+ contentBlock,
326359
+ contentMeasure,
326360
+ paragraphIndex: i4,
326361
+ localX,
326362
+ localY: Math.max(0, Math.min(localY - paragraphStartY, Math.max(paragraphHeight, 0))),
326363
+ blockStartGlobal,
326364
+ distance: distanceToParagraph
326365
+ };
326366
+ paragraphStartY = paragraphEndY;
326367
+ blockStartGlobal += contentMeasure.lines.length;
326368
+ }
326369
+ if (nearestParagraphHit)
326370
+ return {
326371
+ fragment: fragment2,
326372
+ block,
326373
+ measure,
326374
+ pageIndex,
326375
+ contentBlock: nearestParagraphHit.contentBlock,
326376
+ contentMeasure: nearestParagraphHit.contentMeasure,
326377
+ paragraphIndex: nearestParagraphHit.paragraphIndex,
326378
+ localX: nearestParagraphHit.localX,
326379
+ localY: nearestParagraphHit.localY,
326380
+ blockStartGlobal: nearestParagraphHit.blockStartGlobal
326381
+ };
326382
+ return null;
326383
+ }, PageGeometryHelper = class {
325242
326384
  constructor(config2) {
325243
326385
  this.cache = null;
325244
326386
  this.config = config2;
@@ -325453,254 +326595,6 @@ menclose::after {
325453
326595
  for (const metric of Object.keys(this.metrics))
325454
326596
  this.metrics[metric] = [];
325455
326597
  }
325456
- }, isAtomicFragment = (fragment2) => {
325457
- return fragment2.kind === "drawing" || fragment2.kind === "image";
325458
- }, blockPmRangeFromAttrs = (block) => {
325459
- const attrs = block?.attrs;
325460
- const pmStart = typeof attrs?.pmStart === "number" ? attrs.pmStart : undefined;
325461
- return {
325462
- pmStart,
325463
- pmEnd: typeof attrs?.pmEnd === "number" ? attrs.pmEnd : pmStart != null ? pmStart + 1 : undefined
325464
- };
325465
- }, getAtomicPmRange = (fragment2, block) => {
325466
- return {
325467
- pmStart: typeof fragment2.pmStart === "number" ? fragment2.pmStart : blockPmRangeFromAttrs(block).pmStart,
325468
- pmEnd: typeof fragment2.pmEnd === "number" ? fragment2.pmEnd : blockPmRangeFromAttrs(block).pmEnd
325469
- };
325470
- }, isRtlBlock = (block) => {
325471
- if (block.kind !== "paragraph")
325472
- return false;
325473
- return getParagraphInlineDirection(block.attrs) === "rtl";
325474
- }, determineColumn = (layout, fragmentX, page, fragmentY) => {
325475
- const columns = resolveColumnsForHit(layout, page, fragmentY);
325476
- if (!columns || columns.count <= 1)
325477
- return 0;
325478
- const pageWidth = page?.size?.w ?? layout.pageSize.w;
325479
- const margins = page?.margins ?? layout.pages[0]?.margins;
325480
- const marginLeft = Math.max(0, margins?.left ?? 0);
325481
- const marginRight = Math.max(0, margins?.right ?? 0);
325482
- return getColumnAtX(getColumnGeometry(normalizeColumnLayout(columns, Math.max(1, pageWidth - (marginLeft + marginRight)))), fragmentX, marginLeft);
325483
- }, determineTableColumn = (layout, fragment2, page) => {
325484
- if (typeof fragment2.columnIndex === "number") {
325485
- const count2 = resolveColumnsForHit(layout, page, fragment2.y)?.count ?? 1;
325486
- return Math.max(0, Math.min(Math.max(0, count2 - 1), fragment2.columnIndex));
325487
- }
325488
- return determineColumn(layout, fragment2.x, page, fragment2.y);
325489
- }, findLineIndexAtY = (lines, offsetY, fromLine, toLine) => {
325490
- if (!lines || lines.length === 0)
325491
- return null;
325492
- const lineCount = lines.length;
325493
- if (fromLine < 0 || toLine > lineCount || fromLine >= toLine)
325494
- return null;
325495
- let cursor = 0;
325496
- for (let i4 = fromLine;i4 < toLine; i4 += 1) {
325497
- const line = lines[i4];
325498
- if (!line)
325499
- return null;
325500
- const next2 = cursor + line.lineHeight;
325501
- if (offsetY >= cursor && offsetY < next2)
325502
- return i4;
325503
- cursor = next2;
325504
- }
325505
- return toLine - 1;
325506
- }, mapPointToPm = (block, line, x, isRTL, availableWidthOverride, alignmentOverride) => {
325507
- if (block.kind !== "paragraph")
325508
- return null;
325509
- const range = computeLinePmRange(block, line);
325510
- if (range.pmStart == null || range.pmEnd == null)
325511
- return null;
325512
- const result = findCharacterAtX(block, line, x, range.pmStart, availableWidthOverride, alignmentOverride);
325513
- let pmPosition = result.pmPosition;
325514
- if (isRTL) {
325515
- const charOffset = result.charOffset;
325516
- const charsInLine = Math.max(1, line.toChar - line.fromChar);
325517
- pmPosition = charOffsetToPm(block, line, Math.max(0, Math.min(charsInLine, charsInLine - charOffset)), range.pmStart);
325518
- }
325519
- return pmPosition;
325520
- }, calculatePageTopFallback = (layout, pageIndex) => {
325521
- const pageGap = layout.pageGap ?? 0;
325522
- let y$1 = 0;
325523
- for (let i4 = 0;i4 < pageIndex; i4++) {
325524
- const pageHeight = layout.pages[i4]?.size?.h ?? layout.pageSize.h;
325525
- y$1 += pageHeight + pageGap;
325526
- }
325527
- return y$1;
325528
- }, hitTestAtomicFragment = (pageHit, blocks2, measures, point5) => {
325529
- for (const fragment2 of pageHit.page.fragments) {
325530
- if (!isAtomicFragment(fragment2))
325531
- continue;
325532
- const withinX = point5.x >= fragment2.x && point5.x <= fragment2.x + fragment2.width;
325533
- const withinY = point5.y >= fragment2.y && point5.y <= fragment2.y + fragment2.height;
325534
- if (!withinX || !withinY)
325535
- continue;
325536
- const blockIndex = findBlockIndexByFragmentId(blocks2, fragment2.blockId);
325537
- if (blockIndex === -1)
325538
- continue;
325539
- const block = blocks2[blockIndex];
325540
- const measure = measures[blockIndex];
325541
- if (!block || !measure)
325542
- continue;
325543
- return {
325544
- fragment: fragment2,
325545
- block,
325546
- measure,
325547
- pageIndex: pageHit.pageIndex,
325548
- pageY: 0
325549
- };
325550
- }
325551
- return null;
325552
- }, hitTestTableFragment = (pageHit, blocks2, measures, point5) => {
325553
- for (const fragment2 of pageHit.page.fragments) {
325554
- if (fragment2.kind !== "table")
325555
- continue;
325556
- const tableFragment = fragment2;
325557
- const withinX = point5.x >= tableFragment.x && point5.x <= tableFragment.x + tableFragment.width;
325558
- const withinY = point5.y >= tableFragment.y && point5.y <= tableFragment.y + tableFragment.height;
325559
- if (!withinX || !withinY)
325560
- continue;
325561
- const blockIndex = blocks2.findIndex((block$1) => block$1.id === tableFragment.blockId);
325562
- if (blockIndex === -1)
325563
- continue;
325564
- const block = blocks2[blockIndex];
325565
- const measure = measures[blockIndex];
325566
- if (!block || block.kind !== "table" || !measure || measure.kind !== "table")
325567
- continue;
325568
- const tableBlock = block;
325569
- const tableMeasure = measure;
325570
- const localX = point5.x - tableFragment.x;
325571
- const localY = point5.y - tableFragment.y;
325572
- let rowY = 0;
325573
- let rowIndex = -1;
325574
- if (tableMeasure.rows.length === 0 || tableBlock.rows.length === 0)
325575
- continue;
325576
- for (let r$1 = tableFragment.fromRow;r$1 < tableFragment.toRow && r$1 < tableMeasure.rows.length; r$1++) {
325577
- const rowMeasure$1 = tableMeasure.rows[r$1];
325578
- if (localY >= rowY && localY < rowY + rowMeasure$1.height) {
325579
- rowIndex = r$1;
325580
- break;
325581
- }
325582
- rowY += rowMeasure$1.height;
325583
- }
325584
- if (rowIndex === -1) {
325585
- rowIndex = Math.min(tableFragment.toRow - 1, tableMeasure.rows.length - 1);
325586
- if (rowIndex < tableFragment.fromRow)
325587
- continue;
325588
- }
325589
- const rowMeasure = tableMeasure.rows[rowIndex];
325590
- const row2 = tableBlock.rows[rowIndex];
325591
- if (!rowMeasure || !row2)
325592
- continue;
325593
- const firstCellGridStart = rowMeasure.cells[0]?.gridColumnStart ?? 0;
325594
- let colX = 0;
325595
- if (firstCellGridStart > 0 && tableMeasure.columnWidths)
325596
- for (let col = 0;col < firstCellGridStart && col < tableMeasure.columnWidths.length; col++)
325597
- colX += tableMeasure.columnWidths[col];
325598
- const initialColX = colX;
325599
- let colIndex = -1;
325600
- if (rowMeasure.cells.length === 0 || row2.cells.length === 0)
325601
- continue;
325602
- for (let c = 0;c < rowMeasure.cells.length; c++) {
325603
- const cellMeasure$1 = rowMeasure.cells[c];
325604
- if (localX >= colX && localX < colX + cellMeasure$1.width) {
325605
- colIndex = c;
325606
- break;
325607
- }
325608
- colX += cellMeasure$1.width;
325609
- }
325610
- if (colIndex === -1) {
325611
- if (localX < initialColX)
325612
- colIndex = 0;
325613
- else
325614
- colIndex = rowMeasure.cells.length - 1;
325615
- if (colIndex < 0)
325616
- continue;
325617
- }
325618
- const cellMeasure = rowMeasure.cells[colIndex];
325619
- const cell2 = row2.cells[colIndex];
325620
- if (!cellMeasure || !cell2)
325621
- continue;
325622
- const cellBlocks = cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
325623
- const rawMeasures = cellMeasure.blocks ?? (cellMeasure.paragraph ? [cellMeasure.paragraph] : []);
325624
- const cellBlockMeasures = (Array.isArray(rawMeasures) ? rawMeasures : []).filter((m$1) => m$1 != null && typeof m$1 === "object" && ("kind" in m$1));
325625
- let blockStartY = 0;
325626
- let blockStartGlobalLines = 0;
325627
- const getBlockHeight = (m$1) => {
325628
- if (!m$1)
325629
- return 0;
325630
- if ("totalHeight" in m$1 && typeof m$1.totalHeight === "number")
325631
- return m$1.totalHeight;
325632
- if ("height" in m$1 && typeof m$1.height === "number")
325633
- return m$1.height;
325634
- return 0;
325635
- };
325636
- let nearestParagraphHit = null;
325637
- for (let i4 = 0;i4 < cellBlocks.length && i4 < cellBlockMeasures.length; i4++) {
325638
- const cellBlock = cellBlocks[i4];
325639
- const cellBlockMeasure = cellBlockMeasures[i4];
325640
- if (cellBlock?.kind !== "paragraph" || cellBlockMeasure?.kind !== "paragraph") {
325641
- blockStartY += getBlockHeight(cellBlockMeasure);
325642
- continue;
325643
- }
325644
- const blockHeight = getBlockHeight(cellBlockMeasure);
325645
- const blockEndY = blockStartY + blockHeight;
325646
- const padding = cell2.attrs?.padding ?? {
325647
- top: 0,
325648
- left: 4,
325649
- right: 4,
325650
- bottom: 0
325651
- };
325652
- const cellLocalX = localX - colX - (padding.left ?? 4);
325653
- const cellLocalY = localY - rowY - (padding.top ?? 0);
325654
- const paragraphBlock = cellBlock;
325655
- const paragraphMeasure = cellBlockMeasure;
325656
- if (cellLocalY >= blockStartY && cellLocalY < blockEndY) {
325657
- const unclampedLocalY = cellLocalY - blockStartY;
325658
- const localYWithinBlock = Math.max(0, Math.min(unclampedLocalY, Math.max(blockHeight, 0)));
325659
- return {
325660
- fragment: tableFragment,
325661
- block: tableBlock,
325662
- measure: tableMeasure,
325663
- pageIndex: pageHit.pageIndex,
325664
- cellRowIndex: rowIndex,
325665
- cellColIndex: colIndex,
325666
- cellBlock: paragraphBlock,
325667
- cellMeasure: paragraphMeasure,
325668
- localX: Math.max(0, cellLocalX),
325669
- localY: Math.max(0, localYWithinBlock),
325670
- blockStartGlobal: blockStartGlobalLines
325671
- };
325672
- }
325673
- const distanceToBlock = cellLocalY < blockStartY ? blockStartY - cellLocalY : Math.max(0, cellLocalY - blockEndY);
325674
- if (!nearestParagraphHit || distanceToBlock < nearestParagraphHit.distance) {
325675
- const unclampedLocalY = cellLocalY - blockStartY;
325676
- nearestParagraphHit = {
325677
- cellBlock: paragraphBlock,
325678
- cellMeasure: paragraphMeasure,
325679
- localX: Math.max(0, cellLocalX),
325680
- localY: Math.max(0, Math.min(unclampedLocalY, Math.max(blockHeight, 0))),
325681
- blockStartGlobal: blockStartGlobalLines,
325682
- distance: distanceToBlock
325683
- };
325684
- }
325685
- blockStartY = blockEndY;
325686
- blockStartGlobalLines += paragraphMeasure.lines.length;
325687
- }
325688
- if (nearestParagraphHit)
325689
- return {
325690
- fragment: tableFragment,
325691
- block: tableBlock,
325692
- measure: tableMeasure,
325693
- pageIndex: pageHit.pageIndex,
325694
- cellRowIndex: rowIndex,
325695
- cellColIndex: colIndex,
325696
- cellBlock: nearestParagraphHit.cellBlock,
325697
- cellMeasure: nearestParagraphHit.cellMeasure,
325698
- localX: nearestParagraphHit.localX,
325699
- localY: nearestParagraphHit.localY,
325700
- blockStartGlobal: nearestParagraphHit.blockStartGlobal
325701
- };
325702
- }
325703
- return null;
325704
326598
  }, logSelectionMapDebug = (payload) => {}, rangesOverlap2 = (startA, endA, startB, endB) => {
325705
326599
  if (startA == null)
325706
326600
  return false;
@@ -327618,10 +328512,15 @@ menclose::after {
327618
328512
  this.#focusEditorAtFirstPosition();
327619
328513
  }
327620
328514
  #handleClickInHeaderFooterMode(event, x, y$1, pageIndex, pageLocalY) {
327621
- const activeSurfaceSelector = this.#deps?.getHeaderFooterSession()?.session?.mode === "footer" ? ".superdoc-page-footer" : ".superdoc-page-header";
328515
+ const session = this.#deps?.getHeaderFooterSession();
328516
+ const activeSurfaceSelector = session?.session?.mode === "footer" ? ".superdoc-page-footer" : ".superdoc-page-header";
327622
328517
  const visiblePointerSurface = resolveVisibleSurfaceAtPointer(event.target, event.clientX, event.clientY);
327623
328518
  const clickedInsideVisibleActiveSurface = visiblePointerSurface?.kind === "headerFooter" && visiblePointerSurface.surface.closest(activeSurfaceSelector) != null;
327624
328519
  if (visiblePointerSurface?.kind === "bodyContent") {
328520
+ const behindDocSection = (event.target instanceof Element ? event.target.closest("[data-behind-doc-section]") : null)?.dataset.behindDocSection;
328521
+ const sessionMode = session?.session?.mode;
328522
+ if (behindDocSection && behindDocSection === sessionMode)
328523
+ return false;
327625
328524
  this.#callbacks.exitHeaderFooterMode?.();
327626
328525
  return false;
327627
328526
  }
@@ -327717,6 +328616,8 @@ menclose::after {
327717
328616
  return false;
327718
328617
  if (fragmentHit.fragment.kind !== "image" && fragmentHit.fragment.kind !== "drawing")
327719
328618
  return false;
328619
+ if (fragmentHit.fragment.kind === "drawing" && fragmentHit.fragment.drawingKind === "textboxShape")
328620
+ return false;
327720
328621
  const editor = this.#deps?.getEditor();
327721
328622
  try {
327722
328623
  const tr = editor.state.tr.setSelection(NodeSelection.create(doc$12, hit.pos));
@@ -330570,7 +331471,8 @@ menclose::after {
330570
331471
  const surfaceElement = pageElement.querySelector(surfaceSelector);
330571
331472
  if (!surfaceElement)
330572
331473
  return null;
330573
- const entry = findSurfaceEntryAtPos(buildSurfacePmEntries(surfaceElement), pos);
331474
+ const behindDocFragments = Array.from(pageElement.querySelectorAll(`[data-behind-doc-section="${this.#session.mode}"]`));
331475
+ const entry = findSurfaceEntryAtPos([...buildSurfacePmEntries(surfaceElement), ...behindDocFragments.flatMap((frag) => buildSurfacePmEntries(frag))].sort((a2, b$1) => a2.pmStart - b$1.pmStart || a2.pmEnd - b$1.pmEnd), pos);
330574
331476
  if (!entry)
330575
331477
  return null;
330576
331478
  const pageRect = pageElement.getBoundingClientRect();
@@ -331734,13 +332636,13 @@ menclose::after {
331734
332636
  return;
331735
332637
  console.log(...args$1);
331736
332638
  }, HEADER_FOOTER_INIT_BUDGET_MS = 200, MAX_ZOOM_WARNING_THRESHOLD = 10, MAX_SELECTION_RECTS_PER_USER = 100, SEMANTIC_RESIZE_DEBOUNCE_MS = 120, MIN_SEMANTIC_CONTENT_WIDTH_PX = 1, GLOBAL_PERFORMANCE, PresentationEditor, ICONS, TEXTS, tableActionsOptions, TRACKED_MARK_NAMES;
331737
- var init_src_BnMjPHBh_es = __esm(() => {
332639
+ var init_src_BBtIMpLJ_es = __esm(() => {
331738
332640
  init_rolldown_runtime_Bg48TavK_es();
331739
- init_SuperConverter_DBlOjc68_es();
332641
+ init_SuperConverter_CUxtXQFf_es();
331740
332642
  init_jszip_C49i9kUs_es();
331741
332643
  init_xml_js_CqGKpaft_es();
331742
332644
  init_uuid_B2wVPhPi_es();
331743
- init_create_headless_toolbar_DWyoHv_L_es();
332645
+ init_create_headless_toolbar_DutCjfp2_es();
331744
332646
  init_constants_D9qj59G2_es();
331745
332647
  init_dist_B8HfvhaK_es();
331746
332648
  init_unified_Dsuw2be5_es();
@@ -338991,7 +339893,89 @@ ${err.toString()}`);
338991
339893
  return { style: attrs.style };
338992
339894
  } },
338993
339895
  wrapAttributes: { rendered: false },
338994
- attributes: { rendered: false }
339896
+ anchorData: { rendered: false },
339897
+ marginOffset: { rendered: false },
339898
+ attributes: { rendered: false },
339899
+ kind: {
339900
+ default: null,
339901
+ rendered: false
339902
+ },
339903
+ width: {
339904
+ default: null,
339905
+ renderDOM: (attrs) => {
339906
+ if (attrs.width == null)
339907
+ return {};
339908
+ return { "data-width": attrs.width };
339909
+ }
339910
+ },
339911
+ height: {
339912
+ default: null,
339913
+ renderDOM: (attrs) => {
339914
+ if (attrs.height == null)
339915
+ return {};
339916
+ return { "data-height": attrs.height };
339917
+ }
339918
+ },
339919
+ fillColor: {
339920
+ default: null,
339921
+ rendered: false
339922
+ },
339923
+ strokeColor: {
339924
+ default: null,
339925
+ rendered: false
339926
+ },
339927
+ strokeWidth: {
339928
+ default: null,
339929
+ rendered: false
339930
+ },
339931
+ rotation: {
339932
+ default: 0,
339933
+ rendered: false
339934
+ },
339935
+ flipH: {
339936
+ default: false,
339937
+ rendered: false
339938
+ },
339939
+ flipV: {
339940
+ default: false,
339941
+ rendered: false
339942
+ },
339943
+ wrap: {
339944
+ default: null,
339945
+ rendered: false
339946
+ },
339947
+ isAnchor: {
339948
+ default: false,
339949
+ rendered: false
339950
+ },
339951
+ drawingContent: {
339952
+ default: null,
339953
+ rendered: false
339954
+ },
339955
+ originalAttributes: {
339956
+ default: null,
339957
+ rendered: false
339958
+ },
339959
+ effectExtent: {
339960
+ default: null,
339961
+ rendered: false
339962
+ },
339963
+ lineEnds: {
339964
+ default: null,
339965
+ rendered: false
339966
+ },
339967
+ hidden: {
339968
+ default: false,
339969
+ rendered: false
339970
+ },
339971
+ isTextBox: {
339972
+ default: false,
339973
+ rendered: false
339974
+ },
339975
+ isWordArt: {
339976
+ default: false,
339977
+ rendered: false
339978
+ }
338995
339979
  };
338996
339980
  },
338997
339981
  parseDOM() {
@@ -339026,7 +340010,15 @@ ${err.toString()}`);
339026
340010
  return attrs.sdBlockId ? { "data-sd-block-id": attrs.sdBlockId } : {};
339027
340011
  }
339028
340012
  },
339029
- attributes: { rendered: false }
340013
+ attributes: { rendered: false },
340014
+ textInsets: {
340015
+ default: null,
340016
+ rendered: false
340017
+ },
340018
+ textVerticalAlign: {
340019
+ default: null,
340020
+ rendered: false
340021
+ }
339030
340022
  };
339031
340023
  },
339032
340024
  parseDOM() {
@@ -362433,14 +363425,21 @@ function print() { __p += __j.call(arguments, '') }
362433
363425
  return null;
362434
363426
  const localX = normalized.x - context.region.localX;
362435
363427
  const localY = (normalized.pageLocalY ?? normalized.y - context.region.pageIndex * (bodyPageHeight + pageGap)) - context.region.localY;
363428
+ const domHit = this.#resolveHeaderFooterDomHit(context, clientX, clientY);
363429
+ if (domHit) {
363430
+ const doc$3 = this.getActiveEditor().state?.doc;
363431
+ return {
363432
+ ...domHit,
363433
+ pos: doc$3 ? Math.max(0, Math.min(domHit.pos, doc$3.content.size)) : domHit.pos
363434
+ };
363435
+ }
362436
363436
  if (localX < 0 || localY < 0 || localX > context.region.width || localY > context.region.height)
362437
363437
  return null;
362438
363438
  const headerPoint = {
362439
363439
  x: localX,
362440
363440
  y: localY
362441
363441
  };
362442
- const geometryHit = clickToPositionGeometry(context.layout, context.blocks, context.measures, headerPoint) ?? null;
362443
- const hit = this.#resolveHeaderFooterDomHit(context, clientX, clientY) ?? geometryHit;
363442
+ const hit = clickToPositionGeometry(context.layout, context.blocks, context.measures, headerPoint) ?? null;
362444
363443
  if (!hit)
362445
363444
  return null;
362446
363445
  const doc$2 = this.getActiveEditor().state?.doc;
@@ -367411,11 +368410,11 @@ function print() { __p += __j.call(arguments, '') }
367411
368410
  ]);
367412
368411
  });
367413
368412
 
367414
- // ../../packages/superdoc/dist/chunks/create-super-doc-ui-Bw8pGh5l.es.js
368413
+ // ../../packages/superdoc/dist/chunks/create-super-doc-ui-e_ogmxkt.es.js
367415
368414
  var DEFAULT_TEXT_ALIGN_OPTIONS, DEFAULT_LINE_HEIGHT_OPTIONS, DEFAULT_ZOOM_OPTIONS, DEFAULT_DOCUMENT_MODE_OPTIONS, DEFAULT_FONT_SIZE_OPTIONS, headlessToolbarConstants, MOD_ALIASES, ALT_ALIASES, CTRL_ALIASES, SHIFT_ALIASES, BUILTIN_CONTEXT_MENU_GROUPS, BUILTIN_GROUP_ORDER, RESERVED_PROXY_PROPERTY_NAMES, ALL_TOOLBAR_COMMAND_IDS, EMPTY_ACTIVE_IDS, FONT_SIZE_OPTIONS;
367416
- var init_create_super_doc_ui_Bw8pGh5l_es = __esm(() => {
367417
- init_SuperConverter_DBlOjc68_es();
367418
- init_create_headless_toolbar_DWyoHv_L_es();
368415
+ var init_create_super_doc_ui_e_ogmxkt_es = __esm(() => {
368416
+ init_SuperConverter_CUxtXQFf_es();
368417
+ init_create_headless_toolbar_DutCjfp2_es();
367419
368418
  DEFAULT_TEXT_ALIGN_OPTIONS = [
367420
368419
  {
367421
368420
  label: "Left",
@@ -367706,16 +368705,16 @@ var init_zipper_yaJVJ4z9_es = __esm(() => {
367706
368705
 
367707
368706
  // ../../packages/superdoc/dist/super-editor.es.js
367708
368707
  var init_super_editor_es = __esm(() => {
367709
- init_src_BnMjPHBh_es();
367710
- init_SuperConverter_DBlOjc68_es();
368708
+ init_src_BBtIMpLJ_es();
368709
+ init_SuperConverter_CUxtXQFf_es();
367711
368710
  init_jszip_C49i9kUs_es();
367712
368711
  init_xml_js_CqGKpaft_es();
367713
- init_create_headless_toolbar_DWyoHv_L_es();
368712
+ init_create_headless_toolbar_DutCjfp2_es();
367714
368713
  init_constants_D9qj59G2_es();
367715
368714
  init_dist_B8HfvhaK_es();
367716
368715
  init_unified_Dsuw2be5_es();
367717
368716
  init_DocxZipper_FUsfThjV_es();
367718
- init_create_super_doc_ui_Bw8pGh5l_es();
368717
+ init_create_super_doc_ui_e_ogmxkt_es();
367719
368718
  init_ui_C5PAS9hY_es();
367720
368719
  init_eventemitter3_BnGqBE_Q_es();
367721
368720
  init_errors_CNaD6vcg_es();