@harbour-enterprises/superdoc 0.20.0-next.6 → 0.20.0-next.8

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 (32) hide show
  1. package/dist/chunks/{PdfViewer-CuiUv0d5.es.js → PdfViewer-BoDHZ2nW.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer--YKlzafo.cjs → PdfViewer-Ch0v9vA6.cjs} +1 -1
  3. package/dist/chunks/{index-Cl1u_lKk.es.js → index-BWPWqVxp.es.js} +2 -2
  4. package/dist/chunks/{index-CuHtS7O9.cjs → index-DFOT300M.cjs} +2 -2
  5. package/dist/chunks/{super-editor.es-BIW7iKAk.cjs → super-editor.es-BQ6kZTNg.cjs} +263 -72
  6. package/dist/chunks/{super-editor.es-DN4v75aq.es.js → super-editor.es-sBfWb5tn.es.js} +263 -72
  7. package/dist/super-editor/ai-writer.es.js +2 -2
  8. package/dist/super-editor/chunks/{converter-kutpjDQU.js → converter-C91Sr_5w.js} +182 -63
  9. package/dist/super-editor/chunks/{docx-zipper-BjcI24VU.js → docx-zipper-Cl7LYpt6.js} +1 -1
  10. package/dist/super-editor/chunks/{editor-ps-v4FlA.js → editor-a7cQT9Dw.js} +83 -11
  11. package/dist/super-editor/chunks/{toolbar-Ch271j8X.js → toolbar-DiNFtCKr.js} +2 -2
  12. package/dist/super-editor/converter.es.js +1 -1
  13. package/dist/super-editor/docx-zipper.es.js +2 -2
  14. package/dist/super-editor/editor.es.js +3 -3
  15. package/dist/super-editor/file-zipper.es.js +1 -1
  16. package/dist/super-editor/src/core/super-converter/v3/handlers/w/p/helpers/w-p-helpers.d.ts +1 -1
  17. package/dist/super-editor/src/core/super-converter/v3/handlers/w/tblGrid/tblGrid-helpers.d.ts +5 -0
  18. package/dist/super-editor/src/core/super-converter/v3/node-translator/node-translator.d.ts +9 -1
  19. package/dist/super-editor/src/extensions/image/imageHelpers/fileNameUtils.d.ts +3 -0
  20. package/dist/super-editor/src/extensions/image/imageHelpers/index.d.ts +1 -0
  21. package/dist/super-editor/src/extensions/structured-content/StructuredContentBlockView.d.ts +0 -1
  22. package/dist/super-editor/src/extensions/structured-content/StructuredContentInlineView.d.ts +0 -1
  23. package/dist/super-editor/src/extensions/structured-content/StructuredContentViewBase.d.ts +1 -1
  24. package/dist/super-editor/super-editor.es.js +6 -6
  25. package/dist/super-editor/toolbar.es.js +2 -2
  26. package/dist/super-editor.cjs +1 -1
  27. package/dist/super-editor.es.js +1 -1
  28. package/dist/superdoc.cjs +2 -2
  29. package/dist/superdoc.es.js +2 -2
  30. package/dist/superdoc.umd.js +263 -72
  31. package/dist/superdoc.umd.js.map +1 -1
  32. package/package.json +1 -1
@@ -14781,22 +14781,25 @@ async function readFromClipboard(state2) {
14781
14781
  function inchesToTwips(inches) {
14782
14782
  if (inches == null) return;
14783
14783
  if (typeof inches === "string") inches = parseFloat(inches);
14784
- return Math.round(inches * 1440);
14784
+ return Math.round(Number(inches) * 1440);
14785
14785
  }
14786
14786
  function twipsToInches(twips) {
14787
14787
  if (twips == null) return;
14788
- if (typeof twips === "string") twips = parseInt(twips, 10);
14789
- return Math.round(twips / 1440 * 100) / 100;
14788
+ const value = Number(twips);
14789
+ if (Number.isNaN(value)) return;
14790
+ return value / 1440;
14790
14791
  }
14791
14792
  function twipsToPixels(twips) {
14792
14793
  if (twips == null) return;
14793
- twips = twipsToInches(twips);
14794
- return Math.round(twips * 96);
14794
+ const inches = twipsToInches(twips);
14795
+ if (inches == null) return;
14796
+ const pixels = inches * 96;
14797
+ return Math.round(pixels * 1e3) / 1e3;
14795
14798
  }
14796
14799
  function pixelsToTwips(pixels) {
14797
14800
  if (pixels == null) return;
14798
- pixels = pixels / 96;
14799
- return inchesToTwips(pixels);
14801
+ const inches = Number(pixels) / 96;
14802
+ return inchesToTwips(inches);
14800
14803
  }
14801
14804
  function twipsToLines(twips) {
14802
14805
  if (twips == null) return;
@@ -24684,13 +24687,15 @@ const getParagraphIndent = (node, docx, styleId = "") => {
24684
24687
  }
24685
24688
  return indent;
24686
24689
  };
24687
- const getParagraphSpacing = (node, docx, styleId = "", marks = []) => {
24690
+ const getParagraphSpacing = (node, docx, styleId = "", marks = [], options = {}) => {
24691
+ const { insideTable = false } = options;
24688
24692
  const spacing = {};
24689
- const { spacing: pDefaultSpacing = {} } = getDefaultParagraphStyle(docx, styleId);
24693
+ const { spacing: pDefaultSpacing = {}, spacingSource } = getDefaultParagraphStyle(docx, styleId);
24690
24694
  let lineSpaceAfter, lineSpaceBefore, line, lineRuleStyle;
24691
24695
  const pPr = node.elements?.find((el) => el.name === "w:pPr");
24692
24696
  const inLineSpacingTag = pPr?.elements?.find((el) => el.name === "w:spacing");
24693
24697
  const inLineSpacing = inLineSpacingTag?.attributes || {};
24698
+ const hasInlineSpacing = !!Object.keys(inLineSpacing).length;
24694
24699
  const textStyleMark = marks.find((el) => el.type === "textStyle");
24695
24700
  const fontSize2 = textStyleMark?.attrs?.fontSize;
24696
24701
  const lineSpacing = inLineSpacing?.["w:line"] || line || pDefaultSpacing?.["w:line"];
@@ -24712,6 +24717,12 @@ const getParagraphSpacing = (node, docx, styleId = "", marks = []) => {
24712
24717
  if (afterAutospacing === "1" && fontSize2) {
24713
24718
  spacing.lineSpaceAfter += Math.round(parseInt(fontSize2) * 0.5 * 96 / 72);
24714
24719
  }
24720
+ if (insideTable && !hasInlineSpacing && spacingSource === "docDefault") {
24721
+ const hasExplicitSpacing = Object.keys(inLineSpacing).length > 0;
24722
+ if (!hasExplicitSpacing) {
24723
+ return void 0;
24724
+ }
24725
+ }
24715
24726
  return spacing;
24716
24727
  };
24717
24728
  const getDefaultParagraphStyle = (docx, styleId = "") => {
@@ -24752,9 +24763,20 @@ const getDefaultParagraphStyle = (docx, styleId = "") => {
24752
24763
  const { attributes: pPrByIdIndentAttr } = pPrStyleIdIndentTag;
24753
24764
  const spacingRest = isNormalAsDefault ? pPrNormalSpacingAttr || pPrDefaultSpacingAttr : pPrDefaultSpacingAttr || pPrNormalSpacingAttr;
24754
24765
  const indentRest = isNormalAsDefault ? pPrNormalIndentAttr || pPrDefaultIndentAttr : pPrDefaultIndentAttr || pPrNormalIndentAttr;
24766
+ let spacingToUse = pPrByIdSpacingAttr || spacingRest;
24767
+ let spacingSource = "docDefault";
24768
+ if (pPrByIdSpacingAttr) {
24769
+ spacingSource = "style";
24770
+ } else if (spacingRest === pPrNormalSpacingAttr && pPrNormalSpacingAttr) {
24771
+ spacingSource = isNormalAsDefault ? "docDefault" : "normal";
24772
+ } else if (spacingRest === pPrDefaultSpacingAttr && pPrDefaultSpacingAttr) {
24773
+ spacingSource = "docDefault";
24774
+ }
24775
+ let indentToUse = pPrByIdIndentAttr || indentRest;
24755
24776
  return {
24756
- spacing: pPrByIdSpacingAttr || spacingRest,
24757
- indent: pPrByIdIndentAttr || indentRest,
24777
+ spacing: spacingToUse,
24778
+ spacingSource,
24779
+ indent: indentToUse,
24758
24780
  justify: pPrByIdJcAttr
24759
24781
  };
24760
24782
  };
@@ -24929,7 +24951,13 @@ const handleParagraphNode$1 = (params2) => {
24929
24951
  }
24930
24952
  if (docx) {
24931
24953
  const defaultStyleId = node.attributes?.["w:rsidRDefault"];
24932
- schemaNode.attrs["spacing"] = getParagraphSpacing(node, docx, styleId, schemaNode.attrs.marksAttrs);
24954
+ const insideTable = (params2.path || []).some((ancestor) => ancestor.name === "w:tc");
24955
+ const spacing = getParagraphSpacing(node, docx, styleId, schemaNode.attrs.marksAttrs, {
24956
+ insideTable
24957
+ });
24958
+ if (spacing) {
24959
+ schemaNode.attrs["spacing"] = spacing;
24960
+ }
24933
24961
  schemaNode.attrs["rsidRDefault"] = defaultStyleId;
24934
24962
  }
24935
24963
  if (docx) {
@@ -25175,10 +25203,10 @@ function createBorderPropertyHandler(xmlName, sdName = null) {
25175
25203
  createAttributeHandler("w:shadow", null, parseBoolean, booleanToString),
25176
25204
  createAttributeHandler("w:frame", null, parseBoolean, booleanToString)
25177
25205
  ],
25178
- encode: (_2, encodedAttrs) => {
25206
+ encode: (params2, encodedAttrs) => {
25179
25207
  return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25180
25208
  },
25181
- decode: function({ node }, _2) {
25209
+ decode: function({ node }, context) {
25182
25210
  const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs[sdName] || {} } });
25183
25211
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25184
25212
  }
@@ -25537,10 +25565,10 @@ const translator$B = NodeTranslator.from({
25537
25565
  "w:themeTint",
25538
25566
  "w:val"
25539
25567
  ].map((attr) => createAttributeHandler(attr)),
25540
- encode: (_2, encodedAttrs) => {
25568
+ encode: (params2, encodedAttrs) => {
25541
25569
  return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25542
25570
  },
25543
- decode: function({ node }, _2) {
25571
+ decode: function({ node }, context) {
25544
25572
  const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.shading || {} } });
25545
25573
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25546
25574
  }
@@ -25553,10 +25581,10 @@ const translator$w = NodeTranslator.from({
25553
25581
  xmlName: "w:tblLook",
25554
25582
  sdNodeOrKeyName: "tblLook",
25555
25583
  attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
25556
- encode: (_2, encodedAttrs) => {
25584
+ encode: (params2, encodedAttrs) => {
25557
25585
  return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25558
25586
  },
25559
- decode: function({ node }, _2) {
25587
+ decode: function({ node }, context) {
25560
25588
  const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
25561
25589
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25562
25590
  }
@@ -25574,10 +25602,10 @@ const translator$q = NodeTranslator.from({
25574
25602
  xmlName: "w:tblpPr",
25575
25603
  sdNodeOrKeyName: "floatingTableProperties",
25576
25604
  attributes: ["w:leftFromText", "w:rightFromText", "w:topFromText", "w:bottomFromText", "w:tblpX", "w:tblpY"].map((attr) => createAttributeHandler(attr, null, parseInteger, integerToString)).concat(["w:horzAnchor", "w:vertAnchor", "w:tblpXSpec", "w:tblpYSpec"].map((attr) => createAttributeHandler(attr))),
25577
- encode: (_2, encodedAttrs) => {
25605
+ encode: (params2, encodedAttrs) => {
25578
25606
  return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
25579
25607
  },
25580
- decode: function({ node }, _2) {
25608
+ decode: function({ node }, context) {
25581
25609
  const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
25582
25610
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
25583
25611
  }
@@ -25598,13 +25626,13 @@ const translator$d = NodeTranslator.from(createBorderPropertyHandler("w:top"));
25598
25626
  const translator$c = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
25599
25627
  const XML_NODE_NAME$a = "w:tblBorders";
25600
25628
  const SD_ATTR_KEY$3 = "borders";
25601
- const encode$a = (params2, _2) => {
25629
+ const encode$a = (params2) => {
25602
25630
  const { nodes } = params2;
25603
25631
  const node = nodes[0];
25604
25632
  const attributes = encodeProperties(node, tblBordersTranslatorsByXmlName);
25605
25633
  return Object.keys(attributes).length > 0 ? attributes : void 0;
25606
25634
  };
25607
- const decode$a = (params2, _2) => {
25635
+ const decode$a = (params2) => {
25608
25636
  const { borders = {} } = params2.node.attrs || {};
25609
25637
  const elements = decodeProperties(tblBordersTranslatorsBySdName, borders);
25610
25638
  const newNode = {
@@ -25641,13 +25669,13 @@ const translator$b = NodeTranslator.from({
25641
25669
  });
25642
25670
  const XML_NODE_NAME$9 = "w:tblCellMar";
25643
25671
  const SD_ATTR_KEY$2 = "cellMargins";
25644
- const encode$9 = (params2, _2) => {
25672
+ const encode$9 = (params2) => {
25645
25673
  const { nodes } = params2;
25646
25674
  const node = nodes[0];
25647
25675
  const attributes = encodeProperties(node, propertyTranslatorsByXmlName$1);
25648
25676
  return Object.keys(attributes).length > 0 ? attributes : void 0;
25649
25677
  };
25650
- const decode$9 = (params2, _2) => {
25678
+ const decode$9 = (params2) => {
25651
25679
  const { cellMargins = {} } = params2.node.attrs || {};
25652
25680
  const elements = decodeProperties(propertyTranslatorsBySdName$1, cellMargins);
25653
25681
  const newNode = {
@@ -25738,6 +25766,53 @@ const translator$9 = NodeTranslator.from(config$8);
25738
25766
  const translator$8 = NodeTranslator.from(
25739
25767
  createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
25740
25768
  );
25769
+ const DEFAULT_COLUMN_WIDTH_PX = 100;
25770
+ const normalizeTwipWidth = (value) => {
25771
+ if (value == null) return null;
25772
+ const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
25773
+ if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
25774
+ return null;
25775
+ }
25776
+ return numericValue;
25777
+ };
25778
+ const getSchemaDefaultColumnWidthPx = (params2) => {
25779
+ const defaultValue = params2?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
25780
+ if (Array.isArray(defaultValue)) {
25781
+ const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
25782
+ if (numericWidth != null) return numericWidth;
25783
+ } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
25784
+ return defaultValue;
25785
+ }
25786
+ return DEFAULT_COLUMN_WIDTH_PX;
25787
+ };
25788
+ const getTableWidthPx = (params2) => {
25789
+ const explicitWidth = params2?.node?.attrs?.tableWidth?.width;
25790
+ if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
25791
+ const tableWidth = params2?.node?.attrs?.tableProperties?.tableWidth;
25792
+ if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
25793
+ const { value, type: type2 } = tableWidth;
25794
+ if (!type2 || type2 === "auto" || type2 === "dxa") {
25795
+ return twipsToPixels(value);
25796
+ }
25797
+ }
25798
+ return null;
25799
+ };
25800
+ const resolveFallbackColumnWidthTwips = (params2, totalColumns, cellMinWidthTwips) => {
25801
+ const columnCount = Math.max(totalColumns, 1);
25802
+ const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params2);
25803
+ const tableWidthPx = getTableWidthPx(params2);
25804
+ const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
25805
+ let fallbackWidthPx = safeDefaultPx;
25806
+ if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
25807
+ fallbackWidthPx = tableWidthPx / columnCount;
25808
+ }
25809
+ const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
25810
+ if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
25811
+ const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
25812
+ return safeDefault;
25813
+ }
25814
+ return Math.max(fallbackWidthTwips, cellMinWidthTwips);
25815
+ };
25741
25816
  const XML_NODE_NAME$7 = "w:tblGrid";
25742
25817
  const SD_ATTR_KEY = "grid";
25743
25818
  const cellMinWidth = pixelsToTwips(10);
@@ -25752,35 +25827,60 @@ const encode$7 = (params2) => {
25752
25827
  };
25753
25828
  };
25754
25829
  const decode$7 = (params2) => {
25755
- const { grid = [] } = params2.node.attrs || {};
25830
+ const { grid: rawGrid } = params2.node.attrs || {};
25831
+ const grid = Array.isArray(rawGrid) ? rawGrid : [];
25756
25832
  const { firstRow = {} } = params2.extraParams || {};
25757
25833
  const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
25758
- const numberOfColumns = cellNodes.length || grid.length;
25834
+ const columnCountFromCells = cellNodes.reduce((count, cell) => {
25835
+ const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
25836
+ return count + spanCount;
25837
+ }, 0);
25838
+ const totalColumns = Math.max(columnCountFromCells, grid.length);
25839
+ const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params2, totalColumns, cellMinWidth);
25759
25840
  const elements = [];
25760
- for (let cellIdx = 0; cellIdx < numberOfColumns; cellIdx++) {
25761
- const cell = cellNodes[cellIdx];
25841
+ let columnIndex = 0;
25842
+ const pushColumn = (widthTwips) => {
25843
+ let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
25844
+ if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
25845
+ numericWidth = fallbackColumnWidthTwips;
25846
+ }
25847
+ numericWidth = Math.max(numericWidth, cellMinWidth);
25848
+ const decoded = translator$8.decode({
25849
+ node: { type: (
25850
+ /** @type {string} */
25851
+ translator$8.sdNodeOrKeyName
25852
+ ), attrs: { col: numericWidth } }
25853
+ });
25854
+ if (decoded) elements.push(decoded);
25855
+ };
25856
+ cellNodes.forEach((cell) => {
25762
25857
  const { colspan = 1, colwidth } = cell?.attrs || {};
25763
- for (let mergedCellIdx = 0; mergedCellIdx < colspan; mergedCellIdx++) {
25764
- const cellWidthPixels = colwidth && colwidth[mergedCellIdx];
25765
- const colGridAttrs = grid?.[mergedCellIdx] || {};
25766
- const gridWidthTwips = colGridAttrs.col;
25767
- const gridWidthPixels = twipsToPixels(gridWidthTwips);
25858
+ const spanCount = Math.max(1, colspan);
25859
+ for (let span = 0; span < spanCount; span++) {
25860
+ const cellWidthPixels = Array.isArray(colwidth) ? colwidth[span] : void 0;
25861
+ const colGridAttrs = grid?.[columnIndex] || {};
25862
+ const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
25863
+ const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
25768
25864
  let cellWidthTwips;
25769
- if (gridWidthPixels === cellWidthPixels) {
25865
+ if (cellWidthPixels != null) {
25866
+ if (gridWidthTwips != null && gridWidthPixels === cellWidthPixels) {
25867
+ cellWidthTwips = gridWidthTwips;
25868
+ } else {
25869
+ cellWidthTwips = pixelsToTwips(cellWidthPixels);
25870
+ }
25871
+ } else if (gridWidthTwips != null) {
25770
25872
  cellWidthTwips = gridWidthTwips;
25771
- } else if (cellWidthPixels) {
25772
- cellWidthTwips = pixelsToTwips(cellWidthPixels);
25773
- }
25774
- const widthTwips = Math.max(cellWidthTwips, cellMinWidth);
25775
- elements.push(
25776
- translator$8.decode({
25777
- node: { type: (
25778
- /** @type {string} */
25779
- translator$8.sdNodeOrKeyName
25780
- ), attrs: { col: widthTwips } }
25781
- })
25782
- );
25873
+ } else {
25874
+ cellWidthTwips = fallbackColumnWidthTwips;
25875
+ }
25876
+ pushColumn(cellWidthTwips);
25877
+ columnIndex++;
25783
25878
  }
25879
+ });
25880
+ while (columnIndex < grid.length) {
25881
+ const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
25882
+ pushColumn(gridWidthTwips);
25883
+ columnIndex++;
25784
25884
  }
25785
25885
  const newNode = {
25786
25886
  name: XML_NODE_NAME$7,
@@ -25803,7 +25903,8 @@ const encode$6 = (params2, encodedAttrs) => {
25803
25903
  const node = nodes[0];
25804
25904
  const tblPr = node.elements.find((el) => el.name === "w:tblPr");
25805
25905
  if (tblPr) {
25806
- encodedAttrs["tableProperties"] = translator$9.encode({ ...params2, nodes: [tblPr] }).attributes;
25906
+ const encodedProperties = translator$9.encode({ ...params2, nodes: [tblPr] });
25907
+ encodedAttrs["tableProperties"] = encodedProperties?.attributes || {};
25807
25908
  }
25808
25909
  const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
25809
25910
  if (tblGrid) {
@@ -25825,7 +25926,7 @@ const encode$6 = (params2, encodedAttrs) => {
25825
25926
  key2 = prop;
25826
25927
  transform = (v2) => v2;
25827
25928
  }
25828
- if (encodedAttrs.tableProperties?.[key2]) {
25929
+ if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key2]) {
25829
25930
  encodedAttrs[key2] = transform(encodedAttrs.tableProperties[key2]);
25830
25931
  }
25831
25932
  });
@@ -25834,11 +25935,17 @@ const encode$6 = (params2, encodedAttrs) => {
25834
25935
  }
25835
25936
  const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
25836
25937
  const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params2);
25938
+ if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
25939
+ encodedAttrs.tableProperties = {
25940
+ ...encodedAttrs.tableProperties || {},
25941
+ cellMargins: referencedStyles.cellMargins
25942
+ };
25943
+ }
25837
25944
  const rows = node.elements.filter((el) => el.name === "w:tr");
25838
25945
  const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
25839
25946
  const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
25840
25947
  encodedAttrs["borders"] = borderData;
25841
- const tblStyleTag = tblPr.elements.find((el) => el.name === "w:tblStyle");
25948
+ const tblStyleTag = tblPr?.elements?.find((el) => el.name === "w:tblStyle");
25842
25949
  const columnWidths = (encodedAttrs["grid"] ?? []).map((item) => twipsToPixels(item.col));
25843
25950
  const content = [];
25844
25951
  rows.forEach((row) => {
@@ -25847,6 +25954,7 @@ const encode$6 = (params2, encodedAttrs) => {
25847
25954
  nodes: [row],
25848
25955
  extraParams: {
25849
25956
  row,
25957
+ table: node,
25850
25958
  rowBorders: borderRowData,
25851
25959
  styleTag: tblStyleTag,
25852
25960
  columnWidths
@@ -25948,7 +26056,12 @@ function _getReferencedTableStyles(tableStyleReference, params2) {
25948
26056
  if (rowBorders) stylesToReturn.rowBorders = rowBorders;
25949
26057
  const cellMargins = {};
25950
26058
  Object.entries(tableProperties.cellMargins || {}).forEach(([key2, attrs]) => {
25951
- if (attrs?.value) cellMargins[key2] = String(attrs.value);
26059
+ if (attrs?.value != null) {
26060
+ cellMargins[key2] = {
26061
+ value: attrs.value,
26062
+ type: attrs.type || "dxa"
26063
+ };
26064
+ }
25952
26065
  });
25953
26066
  if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
25954
26067
  }
@@ -26201,11 +26314,17 @@ const getTableCellMargins = (marginTag, referencedStyles) => {
26201
26314
  marginTop: marginTopStyle,
26202
26315
  marginBottom: marginBottomStyle
26203
26316
  } = cellMargins;
26317
+ const resolveMargin = (inlineValue, styleValue) => {
26318
+ if (inlineValue != null) return inlineValue;
26319
+ if (styleValue == null) return void 0;
26320
+ if (typeof styleValue === "object") return styleValue.value;
26321
+ return styleValue;
26322
+ };
26204
26323
  const margins = {
26205
- left: twipsToPixels(inlineMarginLeftValue ?? marginLeftStyle),
26206
- right: twipsToPixels(inlineMarginRightValue ?? marginRightStyle),
26207
- top: twipsToPixels(inlineMarginTopValue ?? marginTopStyle),
26208
- bottom: twipsToPixels(inlineMarginBottomValue ?? marginBottomStyle)
26324
+ left: twipsToPixels(resolveMargin(inlineMarginLeftValue, marginLeftStyle)),
26325
+ right: twipsToPixels(resolveMargin(inlineMarginRightValue, marginRightStyle)),
26326
+ top: twipsToPixels(resolveMargin(inlineMarginTopValue, marginTopStyle)),
26327
+ bottom: twipsToPixels(resolveMargin(inlineMarginBottomValue, marginBottomStyle))
26209
26328
  };
26210
26329
  return margins;
26211
26330
  };
@@ -26480,7 +26599,7 @@ function parseTagValueJSON(json) {
26480
26599
  }
26481
26600
  try {
26482
26601
  return JSON.parse(trimmed);
26483
- } catch (err) {
26602
+ } catch {
26484
26603
  return {};
26485
26604
  }
26486
26605
  }
@@ -27219,14 +27338,14 @@ function translateAnchorNode(params2) {
27219
27338
  const XML_NODE_NAME$3 = "wp:anchor";
27220
27339
  const SD_NODE_NAME$3 = ["image"];
27221
27340
  const validXmlAttributes$3 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
27222
- function encode$3(params2, encodedAttrs) {
27341
+ function encode$3(params2) {
27223
27342
  const { node } = params2.extraParams;
27224
27343
  if (!node || !node.type) {
27225
27344
  return null;
27226
27345
  }
27227
27346
  return handleAnchorNode(params2);
27228
27347
  }
27229
- function decode$3(params2, decodedAttrs) {
27348
+ function decode$3(params2) {
27230
27349
  const { node } = params2;
27231
27350
  if (!node || !node.type) {
27232
27351
  return null;
@@ -27260,14 +27379,14 @@ function translateInlineNode(params2) {
27260
27379
  const XML_NODE_NAME$2 = "wp:inline";
27261
27380
  const SD_NODE_NAME$2 = ["image"];
27262
27381
  const validXmlAttributes$2 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
27263
- function encode$2(params2, encodedAttrs) {
27382
+ function encode$2(params2) {
27264
27383
  const { node } = params2.extraParams;
27265
27384
  if (!node || !node.type) {
27266
27385
  return null;
27267
27386
  }
27268
27387
  return handleInlineNode(params2);
27269
27388
  }
27270
- function decode$2(params2, decodedAttrs) {
27389
+ function decode$2(params2) {
27271
27390
  const { node } = params2;
27272
27391
  if (!node || !node.type) {
27273
27392
  return null;
@@ -27293,7 +27412,7 @@ const registeredHandlers = Object.freeze({
27293
27412
  const XML_NODE_NAME$1 = "w:drawing";
27294
27413
  const SD_NODE_NAME$1 = [];
27295
27414
  const validXmlAttributes$1 = [];
27296
- function encode$1(params2, encodedAttrs) {
27415
+ function encode$1(params2) {
27297
27416
  const nodes = params2.nodes;
27298
27417
  const node = nodes[0];
27299
27418
  const validChildTranslators = ["wp:anchor", "wp:inline"];
@@ -27304,7 +27423,7 @@ function encode$1(params2, encodedAttrs) {
27304
27423
  return translator2.encode({ ...params2, extraParams: { node: child } }) || acc;
27305
27424
  }, null);
27306
27425
  }
27307
- function decode$1(params2, decodedAttrs) {
27426
+ function decode$1(params2) {
27308
27427
  const { node } = params2;
27309
27428
  if (!node || !node.type) {
27310
27429
  return null;
@@ -28905,7 +29024,7 @@ function translateStructuredContent(params2) {
28905
29024
  const XML_NODE_NAME = "w:sdt";
28906
29025
  const SD_NODE_NAME = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
28907
29026
  const validXmlAttributes = [];
28908
- function encode$s(params2, encodedAttrs) {
29027
+ function encode$s(params2) {
28909
29028
  const nodes = params2.nodes;
28910
29029
  const node = nodes[0];
28911
29030
  const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
@@ -28915,7 +29034,7 @@ function encode$s(params2, encodedAttrs) {
28915
29034
  const result = handler2(params2);
28916
29035
  return result;
28917
29036
  }
28918
- function decode(params2, decodedAttrs) {
29037
+ function decode(params2) {
28919
29038
  const { node } = params2;
28920
29039
  if (!node || !node.type) {
28921
29040
  return null;
@@ -58650,7 +58769,7 @@ const validateUrlAccessibility = async (url) => {
58650
58769
  credentials: "omit"
58651
58770
  });
58652
58771
  return response.ok;
58653
- } catch (_error) {
58772
+ } catch {
58654
58773
  return false;
58655
58774
  }
58656
58775
  };
@@ -58819,6 +58938,57 @@ function multiStepResize(canvas, width, height) {
58819
58938
  }
58820
58939
  resample_high_quality(canvas, width, height);
58821
58940
  }
58941
+ const FALLBACK_NAME = "image";
58942
+ const stripDiacritics = (value) => value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "");
58943
+ const sanitizeSegment = (segment, { allowDots = false } = {}) => {
58944
+ if (!segment) return "";
58945
+ const normalized = stripDiacritics(segment).replace(/[\s\u2000-\u206f]+/g, "_").replace(/[\\/]+/g, "_");
58946
+ const allowedPattern = allowDots ? /[^0-9A-Za-z._-]+/g : /[^0-9A-Za-z_-]+/g;
58947
+ let sanitized = normalized.replace(allowedPattern, "_");
58948
+ sanitized = sanitized.replace(/_+/g, "_");
58949
+ sanitized = sanitized.replace(/^[_.-]+/, "");
58950
+ sanitized = sanitized.replace(/[_-]+$/, "");
58951
+ return sanitized;
58952
+ };
58953
+ const splitFileName = (name) => {
58954
+ const trimmed = name?.trim?.() ?? "";
58955
+ const lastDot = trimmed.lastIndexOf(".");
58956
+ if (lastDot <= 0 || lastDot === trimmed.length - 1) {
58957
+ return { base: trimmed, ext: "" };
58958
+ }
58959
+ return {
58960
+ base: trimmed.slice(0, lastDot),
58961
+ ext: trimmed.slice(lastDot + 1)
58962
+ };
58963
+ };
58964
+ const sanitizeImageFileName = (inputName) => {
58965
+ const { base: base2, ext } = splitFileName(inputName || "");
58966
+ const sanitizedBase = sanitizeSegment(base2, { allowDots: true }) || FALLBACK_NAME;
58967
+ const sanitizedExt = sanitizeSegment(ext, { allowDots: false }).toLowerCase();
58968
+ if (!sanitizedExt) return sanitizedBase;
58969
+ return `${sanitizedBase}.${sanitizedExt}`;
58970
+ };
58971
+ const ensureUniqueFileName = (preferredName, existingNames = /* @__PURE__ */ new Set()) => {
58972
+ const sanitized = sanitizeImageFileName(preferredName);
58973
+ if (!existingNames || typeof existingNames.has !== "function") {
58974
+ return sanitized;
58975
+ }
58976
+ const existingSet = /* @__PURE__ */ new Set();
58977
+ existingNames.forEach((name) => existingSet.add(sanitizeImageFileName(name)));
58978
+ if (!existingSet.has(sanitized)) {
58979
+ return sanitized;
58980
+ }
58981
+ const { base: base2, ext } = splitFileName(sanitized);
58982
+ let counter = 1;
58983
+ let candidate = sanitized;
58984
+ const suffix2 = () => `${base2}-${counter}${ext ? `.${ext}` : ""}`;
58985
+ while (existingSet.has(candidate)) {
58986
+ candidate = suffix2();
58987
+ counter += 1;
58988
+ }
58989
+ return candidate;
58990
+ };
58991
+ const buildMediaPath = (fileName) => `word/media/${fileName}`;
58822
58992
  const fileTooLarge = (file) => {
58823
58993
  let fileSizeMb = Number((file.size / (1024 * 1024)).toFixed(4));
58824
58994
  if (fileSizeMb > 5) {
@@ -58852,16 +59022,37 @@ function replaceSelectionWithImagePlaceholder({ editorOptions, view, id }) {
58852
59022
  tr = addImagePlaceholder(view.state, tr, id, selection.from);
58853
59023
  view.dispatch(tr);
58854
59024
  }
59025
+ const generateUniqueDocPrId = (editor) => {
59026
+ const existingIds = /* @__PURE__ */ new Set();
59027
+ editor?.state?.doc?.descendants((node) => {
59028
+ if (node.type.name === "image" && node.attrs.id !== void 0 && node.attrs.id !== null) {
59029
+ existingIds.add(String(node.attrs.id));
59030
+ }
59031
+ });
59032
+ let candidate;
59033
+ do {
59034
+ const hex2 = generateDocxRandomId();
59035
+ candidate = String(parseInt(hex2, 16));
59036
+ } while (!candidate || existingIds.has(candidate));
59037
+ return candidate;
59038
+ };
58855
59039
  async function uploadAndInsertImage({ editor, view, file, size: size2, id }) {
58856
59040
  const imageUploadHandler = typeof editor.options.handleImageUpload === "function" ? editor.options.handleImageUpload : handleImageUpload;
59041
+ const placeholderId = id;
58857
59042
  try {
58858
- let url = await imageUploadHandler(file);
58859
- let fileName = file.name.replace(" ", "_");
58860
- let placeholderPos = findPlaceholder(view.state, id);
59043
+ const existingFileNames = new Set(Object.keys(editor.storage.image.media ?? {}).map((key2) => key2.split("/").pop()));
59044
+ const uniqueFileName = ensureUniqueFileName(file.name, existingFileNames);
59045
+ const normalizedFile = uniqueFileName === file.name ? file : new File([file], uniqueFileName, {
59046
+ type: file.type,
59047
+ lastModified: file.lastModified ?? Date.now()
59048
+ });
59049
+ let url = await imageUploadHandler(normalizedFile);
59050
+ let placeholderPos = findPlaceholder(view.state, placeholderId);
58861
59051
  if (placeholderPos == null) {
58862
59052
  return;
58863
59053
  }
58864
- let mediaPath = `word/media/${fileName}`;
59054
+ const mediaPath = buildMediaPath(uniqueFileName);
59055
+ const docPrId = generateUniqueDocPrId(editor);
58865
59056
  let rId = null;
58866
59057
  if (editor.options.mode === "docx") {
58867
59058
  const [, path] = mediaPath.split("word/");
@@ -58871,7 +59062,7 @@ async function uploadAndInsertImage({ editor, view, file, size: size2, id }) {
58871
59062
  let imageNode = view.state.schema.nodes.image.create({
58872
59063
  src: mediaPath,
58873
59064
  size: size2,
58874
- id,
59065
+ id: docPrId,
58875
59066
  rId
58876
59067
  });
58877
59068
  editor.storage.image.media = Object.assign(editor.storage.image.media, { [mediaPath]: url });
@@ -58880,10 +59071,10 @@ async function uploadAndInsertImage({ editor, view, file, size: size2, id }) {
58880
59071
  }
58881
59072
  let tr = view.state.tr;
58882
59073
  tr.replaceWith(placeholderPos, placeholderPos, imageNode);
58883
- tr = removeImagePlaceholder(view.state, tr, id);
59074
+ tr = removeImagePlaceholder(view.state, tr, placeholderId);
58884
59075
  view.dispatch(tr);
58885
59076
  } catch {
58886
- const tr = removeImagePlaceholder(view.state, view.state.tr, id);
59077
+ const tr = removeImagePlaceholder(view.state, view.state.tr, placeholderId);
58887
59078
  view.dispatch(tr);
58888
59079
  }
58889
59080
  }
@@ -60054,7 +60245,7 @@ class StructuredContentViewBase {
60054
60245
  this.htmlAttributes = props.htmlAttributes;
60055
60246
  this.mount(props);
60056
60247
  }
60057
- mount(props) {
60248
+ mount() {
60058
60249
  return;
60059
60250
  }
60060
60251
  get dom() {
@@ -1,6 +1,6 @@
1
1
  import { ref, onMounted, onUnmounted, computed, createElementBlock, openBlock, withModifiers, createElementVNode, withDirectives, unref, vModelText, createCommentVNode, nextTick } from "vue";
2
- import { T as TextSelection } from "./chunks/converter-kutpjDQU.js";
3
- import { _ as _export_sfc } from "./chunks/editor-ps-v4FlA.js";
2
+ import { T as TextSelection } from "./chunks/converter-C91Sr_5w.js";
3
+ import { _ as _export_sfc } from "./chunks/editor-a7cQT9Dw.js";
4
4
  const DEFAULT_API_ENDPOINT = "https://sd-dev-express-gateway-i6xtm.ondigitalocean.app/insights";
5
5
  const SYSTEM_PROMPT = "You are an expert copywriter and you are immersed in a document editor. You are to provide document related text responses based on the user prompts. Only write what is asked for. Do not provide explanations. Try to keep placeholders as short as possible. Do not output your prompt. Your instructions are: ";
6
6
  async function baseInsightsFetch(payload, options = {}) {