@harbour-enterprises/superdoc 0.24.0-next.4 → 0.24.0-next.5

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 (33) hide show
  1. package/dist/chunks/{PdfViewer-kOVuv-4I.cjs → PdfViewer-D6AmuQ3v.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-D7C8g2G4.es.js → PdfViewer-XhwjWR8o.es.js} +1 -1
  3. package/dist/chunks/{index-BFKwBQjS.cjs → index-DAdhqIN8.cjs} +66 -10
  4. package/dist/chunks/{index-CnEAVnHQ.es.js → index-OjiyjDUm.es.js} +66 -10
  5. package/dist/chunks/{super-editor.es-BmGTQ05x.cjs → super-editor.es-BPK2gF1W.cjs} +484 -132
  6. package/dist/chunks/{super-editor.es-CBPoWvjs.es.js → super-editor.es-bHlpz8m_.es.js} +484 -132
  7. package/dist/core/SuperDoc.d.ts.map +1 -1
  8. package/dist/core/helpers/export.d.ts +1 -1
  9. package/dist/core/helpers/export.d.ts.map +1 -1
  10. package/dist/core/types/index.d.ts.map +1 -1
  11. package/dist/style.css +10 -0
  12. package/dist/super-editor/ai-writer.es.js +2 -2
  13. package/dist/super-editor/chunks/{converter-DpPj67OW.js → converter-D-9mYZ83.js} +419 -192
  14. package/dist/super-editor/chunks/{docx-zipper-6Kc95yG-.js → docx-zipper-C1p3F7Ok.js} +1 -1
  15. package/dist/super-editor/chunks/{editor-Dx6AhT5N.js → editor-lJoa5ADp.js} +170 -43
  16. package/dist/super-editor/chunks/{toolbar-CXSg2lJ9.js → toolbar-B5-QnQ4l.js} +2 -2
  17. package/dist/super-editor/converter.es.js +1 -1
  18. package/dist/super-editor/docx-zipper.es.js +2 -2
  19. package/dist/super-editor/editor.es.js +3 -3
  20. package/dist/super-editor/file-zipper.es.js +1 -1
  21. package/dist/super-editor/style.css +10 -0
  22. package/dist/super-editor/super-editor/src/core/super-converter/helpers.d.ts +1 -0
  23. package/dist/super-editor/super-editor/src/core/super-converter/v3/handlers/w/tr/tr-helpers.d.ts +16 -0
  24. package/dist/super-editor/super-editor/src/extensions/table/TableView.d.ts +1 -1
  25. package/dist/super-editor/super-editor.es.js +7 -7
  26. package/dist/super-editor/toolbar.es.js +2 -2
  27. package/dist/super-editor.cjs +1 -1
  28. package/dist/super-editor.es.js +1 -1
  29. package/dist/superdoc.cjs +2 -2
  30. package/dist/superdoc.es.js +2 -2
  31. package/dist/superdoc.umd.js +548 -140
  32. package/dist/superdoc.umd.js.map +1 -1
  33. package/package.json +1 -1
@@ -15074,6 +15074,7 @@ async function readFromClipboard(state2) {
15074
15074
  }
15075
15075
  return content;
15076
15076
  }
15077
+ const PIXELS_PER_INCH = 96;
15077
15078
  function inchesToTwips(inches) {
15078
15079
  if (inches == null) return;
15079
15080
  if (typeof inches === "string") inches = parseFloat(inches);
@@ -15096,12 +15097,12 @@ function pixelsToTwips(pixels) {
15096
15097
  }
15097
15098
  function inchesToPixels(inches) {
15098
15099
  if (inches == null) return;
15099
- const pixels = inches * 96;
15100
+ const pixels = inches * PIXELS_PER_INCH;
15100
15101
  return Math.round(pixels * 1e3) / 1e3;
15101
15102
  }
15102
15103
  function pixelsToInches(pixels) {
15103
15104
  if (pixels == null) return;
15104
- const inches = Number(pixels) / 96;
15105
+ const inches = Number(pixels) / PIXELS_PER_INCH;
15105
15106
  return inches;
15106
15107
  }
15107
15108
  function twipsToLines(twips) {
@@ -15119,7 +15120,7 @@ function halfPointToPoints(halfPoints) {
15119
15120
  function emuToPixels(emu) {
15120
15121
  if (emu == null) return;
15121
15122
  if (typeof emu === "string") emu = parseFloat(emu);
15122
- const pixels = emu * 96 / 914400;
15123
+ const pixels = emu * PIXELS_PER_INCH / 914400;
15123
15124
  return Math.round(pixels);
15124
15125
  }
15125
15126
  function pixelsToEmu(px) {
@@ -15155,12 +15156,12 @@ function degreesToRot(degrees) {
15155
15156
  }
15156
15157
  function pixelsToPolygonUnits(pixels) {
15157
15158
  if (pixels == null) return;
15158
- const pu = pixels * 96;
15159
+ const pu = pixels * PIXELS_PER_INCH;
15159
15160
  return Math.round(pu);
15160
15161
  }
15161
15162
  function polygonUnitsToPixels(pu) {
15162
15163
  if (pu == null) return;
15163
- const pixels = Number(pu) / 96;
15164
+ const pixels = Number(pu) / PIXELS_PER_INCH;
15164
15165
  return Math.round(pixels * 1e3) / 1e3;
15165
15166
  }
15166
15167
  function polygonToObj(polygonNode) {
@@ -27045,6 +27046,68 @@ const translator$_ = NodeTranslator.from(
27045
27046
  repeatHeader: false
27046
27047
  })
27047
27048
  );
27049
+ const createPlaceholderCell = (gridWidth, reason) => {
27050
+ const safeWidth = Number.isFinite(gridWidth) ? gridWidth : 0;
27051
+ const noBorder = { val: "none", size: 0 };
27052
+ return {
27053
+ type: "tableCell",
27054
+ attrs: {
27055
+ colspan: 1,
27056
+ rowspan: 1,
27057
+ colwidth: [safeWidth],
27058
+ __placeholder: reason,
27059
+ borders: {
27060
+ top: { ...noBorder },
27061
+ right: { ...noBorder },
27062
+ bottom: { ...noBorder },
27063
+ left: { ...noBorder }
27064
+ }
27065
+ },
27066
+ content: [{ type: "paragraph", content: [] }]
27067
+ };
27068
+ };
27069
+ const advancePastRowSpans = (pendingRowSpans, startIndex, totalColumns) => {
27070
+ let index2 = startIndex;
27071
+ while (index2 < totalColumns && pendingRowSpans[index2] > 0) {
27072
+ pendingRowSpans[index2] -= 1;
27073
+ index2 += 1;
27074
+ }
27075
+ return index2;
27076
+ };
27077
+ const fillPlaceholderColumns = ({
27078
+ content,
27079
+ pendingRowSpans,
27080
+ currentIndex,
27081
+ targetIndex,
27082
+ totalColumns,
27083
+ gridColumnWidths,
27084
+ reason
27085
+ }) => {
27086
+ let index2 = currentIndex;
27087
+ while (index2 < targetIndex && index2 < totalColumns) {
27088
+ if (pendingRowSpans[index2] > 0) {
27089
+ pendingRowSpans[index2] -= 1;
27090
+ index2 += 1;
27091
+ continue;
27092
+ }
27093
+ const width = Array.isArray(gridColumnWidths) ? gridColumnWidths[index2] ?? 0 : 0;
27094
+ content.push(createPlaceholderCell(width, reason));
27095
+ index2 += 1;
27096
+ }
27097
+ return index2;
27098
+ };
27099
+ const isPlaceholderCell = (cell) => {
27100
+ if (!cell) return false;
27101
+ if (cell.attrs?.__placeholder) return true;
27102
+ const widths = cell.attrs?.colwidth;
27103
+ if (Array.isArray(widths) && widths.length > 0) {
27104
+ const hasMeaningfulWidth = widths.some(
27105
+ (value) => typeof value === "number" && Number.isFinite(value) && Math.abs(value) > 1
27106
+ );
27107
+ if (!hasMeaningfulWidth) return true;
27108
+ }
27109
+ return false;
27110
+ };
27048
27111
  const XML_NODE_NAME$h = "w:tr";
27049
27112
  const SD_NODE_NAME$d = "tableRow";
27050
27113
  const validXmlAttributes$b = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
@@ -27060,29 +27123,64 @@ const encode$n = (params, encodedAttrs) => {
27060
27123
  nodes: [tPr]
27061
27124
  });
27062
27125
  }
27126
+ const gridBeforeRaw = tableRowProperties?.["gridBefore"];
27127
+ const safeGridBefore = typeof gridBeforeRaw === "number" && Number.isFinite(gridBeforeRaw) && gridBeforeRaw > 0 ? gridBeforeRaw : 0;
27063
27128
  encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
27064
27129
  encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
27065
27130
  encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
27066
- const { columnWidths: gridColumnWidths } = params.extraParams;
27131
+ const { columnWidths: gridColumnWidths, activeRowSpans = [] } = params.extraParams;
27132
+ const totalColumns = Array.isArray(gridColumnWidths) ? gridColumnWidths.length : 0;
27133
+ const pendingRowSpans = Array.isArray(activeRowSpans) ? activeRowSpans.slice() : [];
27134
+ while (pendingRowSpans.length < totalColumns) pendingRowSpans.push(0);
27067
27135
  const cellNodes = row.elements.filter((el) => el.name === "w:tc");
27136
+ const content = [];
27068
27137
  let currentColumnIndex = 0;
27069
- const content = cellNodes?.map((n) => {
27070
- let columnWidth = gridColumnWidths?.[currentColumnIndex] || null;
27138
+ const fillUntil = (target, reason) => {
27139
+ currentColumnIndex = fillPlaceholderColumns({
27140
+ content,
27141
+ pendingRowSpans,
27142
+ currentIndex: currentColumnIndex,
27143
+ targetIndex: target,
27144
+ totalColumns,
27145
+ gridColumnWidths,
27146
+ reason
27147
+ });
27148
+ };
27149
+ const skipOccupiedColumns = () => {
27150
+ currentColumnIndex = advancePastRowSpans(pendingRowSpans, currentColumnIndex, totalColumns);
27151
+ };
27152
+ fillUntil(safeGridBefore, "gridBefore");
27153
+ skipOccupiedColumns();
27154
+ cellNodes?.forEach((node) => {
27155
+ skipOccupiedColumns();
27156
+ const startColumn = currentColumnIndex;
27157
+ const columnWidth = gridColumnWidths?.[startColumn] || null;
27071
27158
  const result = translator$c.encode({
27072
27159
  ...params,
27073
27160
  extraParams: {
27074
27161
  ...params.extraParams,
27075
- node: n,
27076
- columnIndex: currentColumnIndex,
27162
+ node,
27163
+ columnIndex: startColumn,
27077
27164
  columnWidth
27078
27165
  }
27079
27166
  });
27080
- const tcPr = n.elements?.find((el) => el.name === "w:tcPr");
27081
- const colspanTag = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
27082
- const colspan = parseInt(colspanTag?.attributes["w:val"] || 1, 10);
27083
- currentColumnIndex += colspan;
27084
- return result;
27085
- }) || [];
27167
+ if (result) {
27168
+ content.push(result);
27169
+ const colspan = Math.max(1, result.attrs?.colspan || 1);
27170
+ const rowspan = Math.max(1, result.attrs?.rowspan || 1);
27171
+ if (rowspan > 1) {
27172
+ for (let offset = 0; offset < colspan; offset += 1) {
27173
+ const target = startColumn + offset;
27174
+ if (target < pendingRowSpans.length) {
27175
+ pendingRowSpans[target] = Math.max(pendingRowSpans[target], rowspan - 1);
27176
+ }
27177
+ }
27178
+ }
27179
+ currentColumnIndex = startColumn + colspan;
27180
+ }
27181
+ });
27182
+ skipOccupiedColumns();
27183
+ fillUntil(totalColumns, "gridAfter");
27086
27184
  const newNode = {
27087
27185
  type: "tableRow",
27088
27186
  content,
@@ -27092,9 +27190,37 @@ const encode$n = (params, encodedAttrs) => {
27092
27190
  };
27093
27191
  const decode$p = (params, decodedAttrs) => {
27094
27192
  const { node } = params;
27095
- const elements = translateChildNodes(params);
27193
+ const cells = node.content || [];
27194
+ let leadingPlaceholders = 0;
27195
+ while (leadingPlaceholders < cells.length && isPlaceholderCell(cells[leadingPlaceholders])) {
27196
+ leadingPlaceholders += 1;
27197
+ }
27198
+ let trailingPlaceholders = 0;
27199
+ while (trailingPlaceholders < cells.length - leadingPlaceholders && isPlaceholderCell(cells[cells.length - 1 - trailingPlaceholders])) {
27200
+ trailingPlaceholders += 1;
27201
+ }
27202
+ const trimmedSlice = cells.slice(leadingPlaceholders, cells.length - trailingPlaceholders);
27203
+ const sanitizedCells = trimmedSlice.map((cell) => {
27204
+ if (cell?.attrs && "__placeholder" in cell.attrs) {
27205
+ const { __placeholder, ...rest } = cell.attrs;
27206
+ return { ...cell, attrs: rest };
27207
+ }
27208
+ return cell;
27209
+ });
27210
+ const trimmedContent = sanitizedCells.filter((_2, index2) => !isPlaceholderCell(trimmedSlice[index2]));
27211
+ const translateParams = {
27212
+ ...params,
27213
+ node: { ...node, content: trimmedContent }
27214
+ };
27215
+ const elements = translateChildNodes(translateParams);
27096
27216
  if (node.attrs?.tableRowProperties) {
27097
27217
  const tableRowProperties = { ...node.attrs.tableRowProperties };
27218
+ if (leadingPlaceholders > 0) {
27219
+ tableRowProperties.gridBefore = leadingPlaceholders;
27220
+ }
27221
+ if (trailingPlaceholders > 0) {
27222
+ tableRowProperties.gridAfter = trailingPlaceholders;
27223
+ }
27098
27224
  if (node.attrs.rowHeight != null) {
27099
27225
  const rowHeightPixels = twipsToPixels(node.attrs.tableRowProperties["rowHeight"]?.value);
27100
27226
  if (rowHeightPixels !== node.attrs.rowHeight) {
@@ -27324,17 +27450,21 @@ const decode$o = (params) => {
27324
27450
  const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params, totalColumns, cellMinWidth);
27325
27451
  const elements = [];
27326
27452
  let columnIndex = 0;
27327
- const pushColumn = (widthTwips) => {
27453
+ const pushColumn = (widthTwips, { enforceMinimum = false } = {}) => {
27328
27454
  let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
27455
+ let shouldEnforceMinimum = enforceMinimum;
27329
27456
  if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
27330
27457
  numericWidth = fallbackColumnWidthTwips;
27458
+ shouldEnforceMinimum = true;
27331
27459
  }
27332
- numericWidth = Math.max(numericWidth, cellMinWidth);
27460
+ const roundedWidth = Math.round(numericWidth);
27461
+ const minimumWidth = shouldEnforceMinimum ? cellMinWidth : 1;
27462
+ const safeWidth = Math.max(roundedWidth, minimumWidth);
27333
27463
  const decoded = translator$u.decode({
27334
27464
  node: { type: (
27335
27465
  /** @type {string} */
27336
27466
  translator$u.sdNodeOrKeyName
27337
- ), attrs: { col: numericWidth } }
27467
+ ), attrs: { col: safeWidth } }
27338
27468
  });
27339
27469
  if (decoded) elements.push(decoded);
27340
27470
  };
@@ -27342,13 +27472,17 @@ const decode$o = (params) => {
27342
27472
  const { colspan = 1, colwidth } = cell?.attrs || {};
27343
27473
  const spanCount = Math.max(1, colspan);
27344
27474
  for (let span = 0; span < spanCount; span++) {
27345
- const cellWidthPixels = Array.isArray(colwidth) ? colwidth[span] : void 0;
27475
+ const rawWidth = Array.isArray(colwidth) ? colwidth[span] : void 0;
27476
+ const cellWidthPixels = typeof rawWidth === "number" && Number.isFinite(rawWidth) ? rawWidth : Number(rawWidth);
27477
+ const hasCellWidth = Number.isFinite(cellWidthPixels) && cellWidthPixels > 0;
27346
27478
  const colGridAttrs = grid?.[columnIndex] || {};
27347
27479
  const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
27348
27480
  const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
27349
27481
  let cellWidthTwips;
27350
- if (cellWidthPixels != null) {
27351
- if (gridWidthTwips != null && gridWidthPixels === cellWidthPixels) {
27482
+ let enforceMinimum = false;
27483
+ if (hasCellWidth) {
27484
+ const tolerance = 0.5;
27485
+ if (gridWidthTwips != null && gridWidthPixels != null && Math.abs(gridWidthPixels - cellWidthPixels) <= tolerance) {
27352
27486
  cellWidthTwips = gridWidthTwips;
27353
27487
  } else {
27354
27488
  cellWidthTwips = pixelsToTwips(cellWidthPixels);
@@ -27357,8 +27491,9 @@ const decode$o = (params) => {
27357
27491
  cellWidthTwips = gridWidthTwips;
27358
27492
  } else {
27359
27493
  cellWidthTwips = fallbackColumnWidthTwips;
27494
+ enforceMinimum = true;
27360
27495
  }
27361
- pushColumn(cellWidthTwips);
27496
+ pushColumn(cellWidthTwips, { enforceMinimum });
27362
27497
  columnIndex++;
27363
27498
  }
27364
27499
  });
@@ -27521,7 +27656,9 @@ const encode$l = (params, encodedAttrs) => {
27521
27656
  }
27522
27657
  }
27523
27658
  const content = [];
27524
- rows.forEach((row) => {
27659
+ const totalColumns = columnWidths.length;
27660
+ const activeRowSpans = totalColumns > 0 ? new Array(totalColumns).fill(0) : [];
27661
+ rows.forEach((row, rowIndex) => {
27525
27662
  const result = translator$Z.encode({
27526
27663
  ...params,
27527
27664
  nodes: [row],
@@ -27530,10 +27667,45 @@ const encode$l = (params, encodedAttrs) => {
27530
27667
  table: node,
27531
27668
  rowBorders: borderRowData,
27532
27669
  styleTag: tblStyleTag,
27533
- columnWidths
27670
+ columnWidths,
27671
+ activeRowSpans: activeRowSpans.slice(),
27672
+ rowIndex
27534
27673
  }
27535
27674
  });
27536
- if (result) content.push(result);
27675
+ if (result) {
27676
+ content.push(result);
27677
+ if (totalColumns > 0) {
27678
+ const activeRowSpansForCurrentRow = activeRowSpans.slice();
27679
+ for (let col = 0; col < totalColumns; col++) {
27680
+ if (activeRowSpans[col] > 0) {
27681
+ activeRowSpans[col] -= 1;
27682
+ }
27683
+ }
27684
+ let columnIndex = 0;
27685
+ const advanceColumnIndex = () => {
27686
+ while (columnIndex < totalColumns && activeRowSpansForCurrentRow[columnIndex] > 0) {
27687
+ columnIndex += 1;
27688
+ }
27689
+ };
27690
+ advanceColumnIndex();
27691
+ result.content?.forEach((cell) => {
27692
+ advanceColumnIndex();
27693
+ const colspan = Math.max(1, cell.attrs?.colspan || 1);
27694
+ const rowspan = Math.max(1, cell.attrs?.rowspan || 1);
27695
+ if (rowspan > 1) {
27696
+ for (let offset = 0; offset < colspan && columnIndex + offset < totalColumns; offset++) {
27697
+ const targetIndex = columnIndex + offset;
27698
+ const remainingRows = rowspan - 1;
27699
+ if (remainingRows > 0 && remainingRows > activeRowSpans[targetIndex]) {
27700
+ activeRowSpans[targetIndex] = remainingRows;
27701
+ }
27702
+ }
27703
+ }
27704
+ columnIndex += colspan;
27705
+ advanceColumnIndex();
27706
+ });
27707
+ }
27708
+ }
27537
27709
  });
27538
27710
  return {
27539
27711
  type: "table",
@@ -28499,6 +28671,7 @@ function sdtNodeTypeStrategy(node) {
28499
28671
  }
28500
28672
  return { type: "unknown", handler: null };
28501
28673
  }
28674
+ const DRAWING_XML_TAG = "w:drawing";
28502
28675
  function handleImageNode(node, params, isAnchor) {
28503
28676
  const { docx, filename } = params;
28504
28677
  const { attributes } = node;
@@ -28510,32 +28683,10 @@ function handleImageNode(node, params, isAnchor) {
28510
28683
  };
28511
28684
  const extent = node.elements.find((el) => el.name === "wp:extent");
28512
28685
  const size = {
28513
- width: emuToPixels(extent.attributes?.cx),
28514
- height: emuToPixels(extent.attributes?.cy)
28686
+ width: emuToPixels(extent?.attributes?.cx),
28687
+ height: emuToPixels(extent?.attributes?.cy)
28515
28688
  };
28516
- const graphic = node.elements.find((el) => el.name === "a:graphic");
28517
- const graphicData = graphic.elements.find((el) => el.name === "a:graphicData");
28518
- const { uri: uri2 } = graphicData?.attributes || {};
28519
- const shapeURI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
28520
- if (!!uri2 && uri2 === shapeURI) {
28521
- return handleShapeDrawing(params, node, graphicData);
28522
- }
28523
- const picture = graphicData.elements.find((el) => el.name === "pic:pic");
28524
- if (!picture || !picture.elements) return null;
28525
- const blipFill = picture.elements.find((el) => el.name === "pic:blipFill");
28526
- const blip = blipFill.elements.find((el) => el.name === "a:blip");
28527
- const spPr = picture.elements.find((el) => el.name === "pic:spPr");
28528
28689
  let transformData = {};
28529
- if (spPr) {
28530
- const xfrm = spPr.elements.find((el) => el.name === "a:xfrm");
28531
- if (xfrm?.attributes) {
28532
- transformData = {
28533
- rotation: rotToDegrees(xfrm.attributes["rot"]),
28534
- verticalFlip: xfrm.attributes["flipV"] === "1",
28535
- horizontalFlip: xfrm.attributes["flipH"] === "1"
28536
- };
28537
- }
28538
- }
28539
28690
  const effectExtent = node.elements.find((el) => el.name === "wp:effectExtent");
28540
28691
  if (effectExtent) {
28541
28692
  const sanitizeEmuValue = (value) => {
@@ -28544,22 +28695,26 @@ function handleImageNode(node, params, isAnchor) {
28544
28695
  return Number.isFinite(numeric) ? numeric : 0;
28545
28696
  };
28546
28697
  transformData.sizeExtension = {
28547
- left: emuToPixels(sanitizeEmuValue(effectExtent.attributes["l"])),
28548
- top: emuToPixels(sanitizeEmuValue(effectExtent.attributes["t"])),
28549
- right: emuToPixels(sanitizeEmuValue(effectExtent.attributes["r"])),
28550
- bottom: emuToPixels(sanitizeEmuValue(effectExtent.attributes["b"]))
28698
+ left: emuToPixels(sanitizeEmuValue(effectExtent.attributes?.["l"])),
28699
+ top: emuToPixels(sanitizeEmuValue(effectExtent.attributes?.["t"])),
28700
+ right: emuToPixels(sanitizeEmuValue(effectExtent.attributes?.["r"])),
28701
+ bottom: emuToPixels(sanitizeEmuValue(effectExtent.attributes?.["b"]))
28551
28702
  };
28552
28703
  }
28553
28704
  const positionHTag = node.elements.find((el) => el.name === "wp:positionH");
28554
28705
  const positionH = positionHTag?.elements.find((el) => el.name === "wp:posOffset");
28555
28706
  const positionHValue = emuToPixels(positionH?.elements[0]?.text);
28556
- const hRelativeFrom = positionHTag?.attributes.relativeFrom;
28557
- const alignH = positionHTag?.elements.find((el) => el.name === "wp:align")?.elements[0]?.text;
28707
+ const hRelativeFrom = positionHTag?.attributes?.relativeFrom;
28708
+ const alignH = positionHTag?.elements.find((el) => el.name === "wp:align")?.elements?.[0]?.text;
28558
28709
  const positionVTag = node.elements.find((el) => el.name === "wp:positionV");
28559
28710
  const positionV = positionVTag?.elements?.find((el) => el.name === "wp:posOffset");
28560
28711
  const positionVValue = emuToPixels(positionV?.elements[0]?.text);
28561
- const vRelativeFrom = positionVTag?.attributes.relativeFrom;
28562
- const alignV = positionVTag?.elements?.find((el) => el.name === "wp:align")?.elements[0]?.text;
28712
+ const vRelativeFrom = positionVTag?.attributes?.relativeFrom;
28713
+ const alignV = positionVTag?.elements?.find((el) => el.name === "wp:align")?.elements?.[0]?.text;
28714
+ const marginOffset = {
28715
+ horizontal: positionHValue,
28716
+ top: positionVValue
28717
+ };
28563
28718
  const simplePos = node.elements.find((el) => el.name === "wp:simplePos");
28564
28719
  const wrapNode = isAnchor ? node.elements.find(
28565
28720
  (el) => ["wp:wrapNone", "wp:wrapSquare", "wp:wrapThrough", "wp:wrapTight", "wp:wrapTopAndBottom"].includes(el.name)
@@ -28567,38 +28722,40 @@ function handleImageNode(node, params, isAnchor) {
28567
28722
  const wrap2 = isAnchor ? { type: wrapNode?.name.slice(7) || "None", attrs: {} } : { type: "Inline" };
28568
28723
  switch (wrap2.type) {
28569
28724
  case "Square":
28570
- wrap2.attrs.wrapText = wrapNode.attributes.wrapText;
28571
- if ("distB" in (wrapNode.attributes || {})) {
28725
+ if (wrapNode?.attributes?.wrapText) {
28726
+ wrap2.attrs.wrapText = wrapNode.attributes.wrapText;
28727
+ }
28728
+ if ("distB" in (wrapNode?.attributes || {})) {
28572
28729
  wrap2.attrs.distBottom = emuToPixels(wrapNode.attributes.distB);
28573
28730
  }
28574
- if ("distL" in (wrapNode.attributes || {})) {
28731
+ if ("distL" in (wrapNode?.attributes || {})) {
28575
28732
  wrap2.attrs.distLeft = emuToPixels(wrapNode.attributes.distL);
28576
28733
  }
28577
- if ("distR" in (wrapNode.attributes || {})) {
28734
+ if ("distR" in (wrapNode?.attributes || {})) {
28578
28735
  wrap2.attrs.distRight = emuToPixels(wrapNode.attributes.distR);
28579
28736
  }
28580
- if ("distT" in (wrapNode.attributes || {})) {
28737
+ if ("distT" in (wrapNode?.attributes || {})) {
28581
28738
  wrap2.attrs.distTop = emuToPixels(wrapNode.attributes.distT);
28582
28739
  }
28583
28740
  break;
28584
28741
  case "Tight":
28585
28742
  case "Through": {
28586
- if ("distL" in (wrapNode.attributes || {})) {
28743
+ if ("distL" in (wrapNode?.attributes || {})) {
28587
28744
  wrap2.attrs.distLeft = emuToPixels(wrapNode.attributes.distL);
28588
28745
  }
28589
- if ("distR" in (wrapNode.attributes || {})) {
28746
+ if ("distR" in (wrapNode?.attributes || {})) {
28590
28747
  wrap2.attrs.distRight = emuToPixels(wrapNode.attributes.distR);
28591
28748
  }
28592
- if ("distT" in (wrapNode.attributes || {})) {
28749
+ if ("distT" in (wrapNode?.attributes || {})) {
28593
28750
  wrap2.attrs.distTop = emuToPixels(wrapNode.attributes.distT);
28594
28751
  }
28595
- if ("distB" in (wrapNode.attributes || {})) {
28752
+ if ("distB" in (wrapNode?.attributes || {})) {
28596
28753
  wrap2.attrs.distBottom = emuToPixels(wrapNode.attributes.distB);
28597
28754
  }
28598
- if ("wrapText" in (wrapNode.attributes || {})) {
28755
+ if ("wrapText" in (wrapNode?.attributes || {})) {
28599
28756
  wrap2.attrs.wrapText = wrapNode.attributes.wrapText;
28600
28757
  }
28601
- const polygon = wrapNode.elements?.find((el) => el.name === "wp:wrapPolygon");
28758
+ const polygon = wrapNode?.elements?.find((el) => el.name === "wp:wrapPolygon");
28602
28759
  if (polygon) {
28603
28760
  wrap2.attrs.polygon = polygonToObj(polygon);
28604
28761
  if (polygon.attributes?.edited !== void 0) {
@@ -28608,10 +28765,10 @@ function handleImageNode(node, params, isAnchor) {
28608
28765
  break;
28609
28766
  }
28610
28767
  case "TopAndBottom":
28611
- if ("distB" in (wrapNode.attributes || {})) {
28768
+ if ("distB" in (wrapNode?.attributes || {})) {
28612
28769
  wrap2.attrs.distBottom = emuToPixels(wrapNode.attributes.distB);
28613
28770
  }
28614
- if ("distT" in (wrapNode.attributes || {})) {
28771
+ if ("distT" in (wrapNode?.attributes || {})) {
28615
28772
  wrap2.attrs.distTop = emuToPixels(wrapNode.attributes.distT);
28616
28773
  }
28617
28774
  break;
@@ -28629,17 +28786,42 @@ function handleImageNode(node, params, isAnchor) {
28629
28786
  alignV
28630
28787
  };
28631
28788
  }
28632
- const marginOffset = {
28633
- horizontal: positionHValue,
28634
- top: positionVValue
28635
- };
28789
+ const graphic = node.elements.find((el) => el.name === "a:graphic");
28790
+ const graphicData = graphic?.elements.find((el) => el.name === "a:graphicData");
28791
+ const { uri: uri2 } = graphicData?.attributes || {};
28792
+ const shapeURI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
28793
+ if (!!uri2 && uri2 === shapeURI) {
28794
+ const shapeMarginOffset = {
28795
+ left: positionHValue,
28796
+ horizontal: positionHValue,
28797
+ top: positionVValue
28798
+ };
28799
+ return handleShapeDrawing(params, node, graphicData, size, padding, shapeMarginOffset);
28800
+ }
28801
+ const picture = graphicData?.elements.find((el) => el.name === "pic:pic");
28802
+ if (!picture || !picture.elements) return null;
28803
+ const blipFill = picture.elements.find((el) => el.name === "pic:blipFill");
28804
+ const blip = blipFill?.elements.find((el) => el.name === "a:blip");
28805
+ if (!blip) return null;
28806
+ const spPr = picture.elements.find((el) => el.name === "pic:spPr");
28807
+ if (spPr) {
28808
+ const xfrm = spPr.elements.find((el) => el.name === "a:xfrm");
28809
+ if (xfrm?.attributes) {
28810
+ transformData = {
28811
+ ...transformData,
28812
+ rotation: rotToDegrees(xfrm.attributes["rot"]),
28813
+ verticalFlip: xfrm.attributes["flipV"] === "1",
28814
+ horizontalFlip: xfrm.attributes["flipH"] === "1"
28815
+ };
28816
+ }
28817
+ }
28636
28818
  const { attributes: blipAttributes = {} } = blip;
28637
28819
  const rEmbed = blipAttributes["r:embed"];
28638
28820
  if (!rEmbed) return null;
28639
28821
  const currentFile = filename || "document.xml";
28640
28822
  let rels = docx[`word/_rels/${currentFile}.rels`];
28641
28823
  if (!rels) rels = docx[`word/_rels/document.xml.rels`];
28642
- const relationships = rels.elements.find((el) => el.name === "Relationships");
28824
+ const relationships = rels?.elements.find((el) => el.name === "Relationships");
28643
28825
  const { elements } = relationships || [];
28644
28826
  const rel = elements?.find((el) => el.attributes["Id"] === rEmbed);
28645
28827
  if (!rel) return null;
@@ -28652,10 +28834,10 @@ function handleImageNode(node, params, isAnchor) {
28652
28834
  type: "image",
28653
28835
  attrs: {
28654
28836
  src: path,
28655
- alt: ["emf", "wmf"].includes(extension) ? "Unable to render EMF/WMF image" : docPr?.attributes.name || "Image",
28837
+ alt: ["emf", "wmf"].includes(extension) ? "Unable to render EMF/WMF image" : docPr?.attributes?.name || "Image",
28656
28838
  extension,
28657
- id: docPr?.attributes.id || "",
28658
- title: docPr?.attributes.descr || "Image",
28839
+ id: docPr?.attributes?.id || "",
28840
+ title: docPr?.attributes?.descr || "Image",
28659
28841
  inline: true,
28660
28842
  padding,
28661
28843
  marginOffset,
@@ -28670,6 +28852,10 @@ function handleImageNode(node, params, isAnchor) {
28670
28852
  }
28671
28853
  },
28672
28854
  wrap: wrap2,
28855
+ ...wrap2.type === "Square" && wrap2.attrs.wrapText ? {
28856
+ wrapText: wrap2.attrs.wrapText
28857
+ } : {},
28858
+ wrapTopAndBottom: wrap2.type === "TopAndBottom",
28673
28859
  originalPadding: {
28674
28860
  distT: attributes["distT"],
28675
28861
  distB: attributes["distB"],
@@ -28681,7 +28867,7 @@ function handleImageNode(node, params, isAnchor) {
28681
28867
  }
28682
28868
  };
28683
28869
  }
28684
- const handleShapeDrawing = (params, node, graphicData) => {
28870
+ const handleShapeDrawing = (params, node, graphicData, size, padding, marginOffset) => {
28685
28871
  const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
28686
28872
  const textBox = wsp.elements.find((el) => el.name === "wps:txbx");
28687
28873
  const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
@@ -28692,21 +28878,14 @@ const handleShapeDrawing = (params, node, graphicData) => {
28692
28878
  return getRectangleShape(params, spPr);
28693
28879
  }
28694
28880
  if (!textBoxContent) {
28695
- return null;
28881
+ return buildShapePlaceholder(node, size, padding, marginOffset, "drawing");
28696
28882
  }
28697
- const { nodeListHandler } = params;
28698
- const translatedElement = nodeListHandler.handler({
28699
- ...params,
28700
- node: textBoxContent.elements[0],
28701
- nodes: textBoxContent.elements,
28702
- path: [...params.path || [], textBoxContent]
28703
- });
28704
- return translatedElement[0];
28883
+ return buildShapePlaceholder(node, size, padding, marginOffset, "textbox");
28705
28884
  };
28706
28885
  const getRectangleShape = (params, node) => {
28707
28886
  const schemaAttrs = {};
28708
28887
  const [drawingNode] = params.nodes;
28709
- if (drawingNode?.name === "w:drawing") {
28888
+ if (drawingNode?.name === DRAWING_XML_TAG) {
28710
28889
  schemaAttrs.drawingContent = drawingNode;
28711
28890
  }
28712
28891
  const xfrm = node.elements.find((el) => el.name === "a:xfrm");
@@ -28730,6 +28909,52 @@ const getRectangleShape = (params, node) => {
28730
28909
  attrs: schemaAttrs
28731
28910
  };
28732
28911
  };
28912
+ const buildShapePlaceholder = (node, size, padding, marginOffset, shapeType) => {
28913
+ const attrs = {
28914
+ drawingContent: {
28915
+ name: DRAWING_XML_TAG,
28916
+ elements: [carbonCopy(node)]
28917
+ },
28918
+ attributes: {
28919
+ "data-shape-type": shapeType
28920
+ }
28921
+ };
28922
+ if (size && (Number.isFinite(size.width) || Number.isFinite(size.height))) {
28923
+ attrs.size = {
28924
+ ...Number.isFinite(size.width) ? { width: size.width } : {},
28925
+ ...Number.isFinite(size.height) ? { height: size.height } : {}
28926
+ };
28927
+ }
28928
+ if (padding) {
28929
+ const paddingData = {};
28930
+ if (Number.isFinite(padding.top)) paddingData["data-padding-top"] = padding.top;
28931
+ if (Number.isFinite(padding.right)) paddingData["data-padding-right"] = padding.right;
28932
+ if (Number.isFinite(padding.bottom)) paddingData["data-padding-bottom"] = padding.bottom;
28933
+ if (Number.isFinite(padding.left)) paddingData["data-padding-left"] = padding.left;
28934
+ if (Object.keys(paddingData).length) {
28935
+ attrs.attributes = {
28936
+ ...attrs.attributes,
28937
+ ...paddingData
28938
+ };
28939
+ }
28940
+ }
28941
+ if (marginOffset) {
28942
+ const offsetData = {};
28943
+ const horizontal = Number.isFinite(marginOffset.horizontal) ? marginOffset.horizontal : Number.isFinite(marginOffset.left) ? marginOffset.left : void 0;
28944
+ if (Number.isFinite(horizontal)) offsetData["data-offset-x"] = horizontal;
28945
+ if (Number.isFinite(marginOffset.top)) offsetData["data-offset-y"] = marginOffset.top;
28946
+ if (Object.keys(offsetData).length) {
28947
+ attrs.attributes = {
28948
+ ...attrs.attributes,
28949
+ ...offsetData
28950
+ };
28951
+ }
28952
+ }
28953
+ return {
28954
+ type: "contentBlock",
28955
+ attrs
28956
+ };
28957
+ };
28733
28958
  function handleAnchorNode(params) {
28734
28959
  const { node } = params.extraParams;
28735
28960
  if (node.name !== "wp:anchor") {
@@ -35441,7 +35666,7 @@ export {
35441
35666
  objectIncludes as Z,
35442
35667
  AddMarkStep as _,
35443
35668
  Plugin as a,
35444
- translator$10 as a$,
35669
+ translator$b as a$,
35445
35670
  twipsToLines as a0,
35446
35671
  pixelsToTwips as a1,
35447
35672
  helpers as a2,
@@ -35452,33 +35677,33 @@ export {
35452
35677
  createDocFromMarkdown as a7,
35453
35678
  createDocFromHTML as a8,
35454
35679
  EditorState as a9,
35455
- xmljs as aA,
35456
- vClickOutside as aB,
35457
- getActiveFormatting as aC,
35458
- readFromClipboard as aD,
35459
- handleClipboardPaste as aE,
35460
- getFileObject as aF,
35461
- runPropertyTranslators as aG,
35462
- translator$d as aH,
35463
- translator$k as aI,
35464
- translator$m as aJ,
35465
- translator$e as aK,
35466
- translator$f as aL,
35467
- translator$n as aM,
35468
- translator$o as aN,
35469
- translator$j as aO,
35470
- translator$g as aP,
35471
- translator$r as aQ,
35472
- translator$i as aR,
35473
- translator$l as aS,
35474
- translator$h as aT,
35475
- translator$q as aU,
35476
- translator$p as aV,
35477
- commentRangeEndTranslator as aW,
35478
- commentRangeStartTranslator as aX,
35479
- translator$a as aY,
35480
- translator$b as aZ,
35481
- translator$$ as a_,
35680
+ getDefaultExportFromCjs$2 as aA,
35681
+ getContentTypesFromXml as aB,
35682
+ xmljs as aC,
35683
+ vClickOutside as aD,
35684
+ getActiveFormatting as aE,
35685
+ readFromClipboard as aF,
35686
+ handleClipboardPaste as aG,
35687
+ getFileObject as aH,
35688
+ runPropertyTranslators as aI,
35689
+ translator$d as aJ,
35690
+ translator$k as aK,
35691
+ translator$m as aL,
35692
+ translator$e as aM,
35693
+ translator$f as aN,
35694
+ translator$n as aO,
35695
+ translator$o as aP,
35696
+ translator$j as aQ,
35697
+ translator$g as aR,
35698
+ translator$r as aS,
35699
+ translator$i as aT,
35700
+ translator$l as aU,
35701
+ translator$h as aV,
35702
+ translator$q as aW,
35703
+ translator$p as aX,
35704
+ commentRangeEndTranslator as aY,
35705
+ commentRangeStartTranslator as aZ,
35706
+ translator$a as a_,
35482
35707
  hasSomeParentWithClass as aa,
35483
35708
  isActive as ab,
35484
35709
  unflattenListsInHtml as ac,
@@ -35496,81 +35721,83 @@ export {
35496
35721
  docxNumberigHelpers as ao,
35497
35722
  parseIndentElement as ap,
35498
35723
  combineIndents as aq,
35499
- SelectionRange as ar,
35500
- Transform as as,
35501
- isInTable as at,
35502
- generateDocxRandomId as au,
35503
- insertNewRelationship as av,
35504
- inchesToPixels as aw,
35505
- commonjsGlobal as ax,
35506
- getDefaultExportFromCjs$2 as ay,
35507
- getContentTypesFromXml as az,
35724
+ twipsToPixels as ar,
35725
+ PIXELS_PER_INCH as as,
35726
+ SelectionRange as at,
35727
+ Transform as au,
35728
+ isInTable as av,
35729
+ generateDocxRandomId as aw,
35730
+ insertNewRelationship as ax,
35731
+ inchesToPixels as ay,
35732
+ commonjsGlobal as az,
35508
35733
  Slice as b,
35509
- _sfc_main as b$,
35510
- translator$1l as b0,
35511
- translator$_ as b1,
35512
- translator$11 as b2,
35513
- translator$Z as b3,
35514
- translator$z as b4,
35515
- translator$c as b5,
35516
- translator$M as b6,
35517
- translator$N as b7,
35518
- translator$O as b8,
35519
- translator$P as b9,
35520
- translator$1o as bA,
35521
- translator$F as bB,
35522
- translator$14 as bC,
35523
- translator$G as bD,
35524
- translator$H as bE,
35525
- translator$1m as bF,
35526
- translator$1c as bG,
35527
- translator$1q as bH,
35528
- translator$15 as bI,
35529
- translator$u as bJ,
35530
- translator$16 as bK,
35531
- translator$17 as bL,
35532
- translator$J as bM,
35533
- translator$9 as bN,
35534
- translator$18 as bO,
35535
- translator$1j as bP,
35536
- translator$19 as bQ,
35537
- translator$1a as bR,
35538
- translator$1r as bS,
35539
- translator$L as bT,
35540
- translator$7 as bU,
35541
- translator$6 as bV,
35542
- translator$Y as bW,
35543
- translator$1n as bX,
35544
- translator$4 as bY,
35545
- translator$5 as bZ,
35546
- translator$1 as b_,
35547
- translator$Q as ba,
35548
- translator$v as bb,
35549
- translator$R as bc,
35550
- translator$S as bd,
35551
- translator$T as be,
35552
- translator$U as bf,
35553
- translator$12 as bg,
35554
- translator$t as bh,
35555
- translator$V as bi,
35556
- translator$13 as bj,
35557
- translator$w as bk,
35558
- translator$W as bl,
35559
- translator$x as bm,
35560
- translator$s as bn,
35561
- translator$1p as bo,
35562
- translator$1f as bp,
35563
- translator$1g as bq,
35564
- translator$1k as br,
35565
- translator$B as bs,
35566
- translator$X as bt,
35567
- translator$8 as bu,
35568
- translator$D as bv,
35569
- translator$1h as bw,
35570
- translator$1d as bx,
35571
- translator$1i as by,
35572
- translator$1b as bz,
35734
+ translator$5 as b$,
35735
+ translator$$ as b0,
35736
+ translator$10 as b1,
35737
+ translator$1l as b2,
35738
+ translator$_ as b3,
35739
+ translator$11 as b4,
35740
+ translator$Z as b5,
35741
+ translator$z as b6,
35742
+ translator$c as b7,
35743
+ translator$M as b8,
35744
+ translator$N as b9,
35745
+ translator$1i as bA,
35746
+ translator$1b as bB,
35747
+ translator$1o as bC,
35748
+ translator$F as bD,
35749
+ translator$14 as bE,
35750
+ translator$G as bF,
35751
+ translator$H as bG,
35752
+ translator$1m as bH,
35753
+ translator$1c as bI,
35754
+ translator$1q as bJ,
35755
+ translator$15 as bK,
35756
+ translator$u as bL,
35757
+ translator$16 as bM,
35758
+ translator$17 as bN,
35759
+ translator$J as bO,
35760
+ translator$9 as bP,
35761
+ translator$18 as bQ,
35762
+ translator$1j as bR,
35763
+ translator$19 as bS,
35764
+ translator$1a as bT,
35765
+ translator$1r as bU,
35766
+ translator$L as bV,
35767
+ translator$7 as bW,
35768
+ translator$6 as bX,
35769
+ translator$Y as bY,
35770
+ translator$1n as bZ,
35771
+ translator$4 as b_,
35772
+ translator$O as ba,
35773
+ translator$P as bb,
35774
+ translator$Q as bc,
35775
+ translator$v as bd,
35776
+ translator$R as be,
35777
+ translator$S as bf,
35778
+ translator$T as bg,
35779
+ translator$U as bh,
35780
+ translator$12 as bi,
35781
+ translator$t as bj,
35782
+ translator$V as bk,
35783
+ translator$13 as bl,
35784
+ translator$w as bm,
35785
+ translator$W as bn,
35786
+ translator$x as bo,
35787
+ translator$s as bp,
35788
+ translator$1p as bq,
35789
+ translator$1f as br,
35790
+ translator$1g as bs,
35791
+ translator$1k as bt,
35792
+ translator$B as bu,
35793
+ translator$X as bv,
35794
+ translator$8 as bw,
35795
+ translator$D as bx,
35796
+ translator$1h as by,
35797
+ translator$1d as bz,
35573
35798
  DOMParser$1 as c,
35799
+ translator$1 as c0,
35800
+ _sfc_main as c1,
35574
35801
  Mark as d,
35575
35802
  dropPoint as e,
35576
35803
  callOrGet as f,