@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
@@ -22523,22 +22523,25 @@
22523
22523
  function inchesToTwips(inches) {
22524
22524
  if (inches == null) return;
22525
22525
  if (typeof inches === "string") inches = parseFloat(inches);
22526
- return Math.round(inches * 1440);
22526
+ return Math.round(Number(inches) * 1440);
22527
22527
  }
22528
22528
  function twipsToInches(twips) {
22529
22529
  if (twips == null) return;
22530
- if (typeof twips === "string") twips = parseInt(twips, 10);
22531
- return Math.round(twips / 1440 * 100) / 100;
22530
+ const value = Number(twips);
22531
+ if (Number.isNaN(value)) return;
22532
+ return value / 1440;
22532
22533
  }
22533
22534
  function twipsToPixels(twips) {
22534
22535
  if (twips == null) return;
22535
- twips = twipsToInches(twips);
22536
- return Math.round(twips * 96);
22536
+ const inches = twipsToInches(twips);
22537
+ if (inches == null) return;
22538
+ const pixels = inches * 96;
22539
+ return Math.round(pixels * 1e3) / 1e3;
22537
22540
  }
22538
22541
  function pixelsToTwips(pixels) {
22539
22542
  if (pixels == null) return;
22540
- pixels = pixels / 96;
22541
- return inchesToTwips(pixels);
22543
+ const inches = Number(pixels) / 96;
22544
+ return inchesToTwips(inches);
22542
22545
  }
22543
22546
  function twipsToLines(twips) {
22544
22547
  if (twips == null) return;
@@ -32426,13 +32429,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32426
32429
  }
32427
32430
  return indent;
32428
32431
  };
32429
- const getParagraphSpacing = (node, docx, styleId = "", marks = []) => {
32432
+ const getParagraphSpacing = (node, docx, styleId = "", marks = [], options = {}) => {
32433
+ const { insideTable = false } = options;
32430
32434
  const spacing = {};
32431
- const { spacing: pDefaultSpacing = {} } = getDefaultParagraphStyle(docx, styleId);
32435
+ const { spacing: pDefaultSpacing = {}, spacingSource } = getDefaultParagraphStyle(docx, styleId);
32432
32436
  let lineSpaceAfter, lineSpaceBefore, line, lineRuleStyle;
32433
32437
  const pPr = node.elements?.find((el) => el.name === "w:pPr");
32434
32438
  const inLineSpacingTag = pPr?.elements?.find((el) => el.name === "w:spacing");
32435
32439
  const inLineSpacing = inLineSpacingTag?.attributes || {};
32440
+ const hasInlineSpacing = !!Object.keys(inLineSpacing).length;
32436
32441
  const textStyleMark = marks.find((el) => el.type === "textStyle");
32437
32442
  const fontSize2 = textStyleMark?.attrs?.fontSize;
32438
32443
  const lineSpacing = inLineSpacing?.["w:line"] || line || pDefaultSpacing?.["w:line"];
@@ -32454,6 +32459,12 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32454
32459
  if (afterAutospacing === "1" && fontSize2) {
32455
32460
  spacing.lineSpaceAfter += Math.round(parseInt(fontSize2) * 0.5 * 96 / 72);
32456
32461
  }
32462
+ if (insideTable && !hasInlineSpacing && spacingSource === "docDefault") {
32463
+ const hasExplicitSpacing = Object.keys(inLineSpacing).length > 0;
32464
+ if (!hasExplicitSpacing) {
32465
+ return void 0;
32466
+ }
32467
+ }
32457
32468
  return spacing;
32458
32469
  };
32459
32470
  const getDefaultParagraphStyle = (docx, styleId = "") => {
@@ -32494,9 +32505,20 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32494
32505
  const { attributes: pPrByIdIndentAttr } = pPrStyleIdIndentTag;
32495
32506
  const spacingRest = isNormalAsDefault ? pPrNormalSpacingAttr || pPrDefaultSpacingAttr : pPrDefaultSpacingAttr || pPrNormalSpacingAttr;
32496
32507
  const indentRest = isNormalAsDefault ? pPrNormalIndentAttr || pPrDefaultIndentAttr : pPrDefaultIndentAttr || pPrNormalIndentAttr;
32508
+ let spacingToUse = pPrByIdSpacingAttr || spacingRest;
32509
+ let spacingSource = "docDefault";
32510
+ if (pPrByIdSpacingAttr) {
32511
+ spacingSource = "style";
32512
+ } else if (spacingRest === pPrNormalSpacingAttr && pPrNormalSpacingAttr) {
32513
+ spacingSource = isNormalAsDefault ? "docDefault" : "normal";
32514
+ } else if (spacingRest === pPrDefaultSpacingAttr && pPrDefaultSpacingAttr) {
32515
+ spacingSource = "docDefault";
32516
+ }
32517
+ let indentToUse = pPrByIdIndentAttr || indentRest;
32497
32518
  return {
32498
- spacing: pPrByIdSpacingAttr || spacingRest,
32499
- indent: pPrByIdIndentAttr || indentRest,
32519
+ spacing: spacingToUse,
32520
+ spacingSource,
32521
+ indent: indentToUse,
32500
32522
  justify: pPrByIdJcAttr
32501
32523
  };
32502
32524
  };
@@ -32671,7 +32693,13 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32671
32693
  }
32672
32694
  if (docx) {
32673
32695
  const defaultStyleId = node.attributes?.["w:rsidRDefault"];
32674
- schemaNode.attrs["spacing"] = getParagraphSpacing(node, docx, styleId, schemaNode.attrs.marksAttrs);
32696
+ const insideTable = (params2.path || []).some((ancestor) => ancestor.name === "w:tc");
32697
+ const spacing = getParagraphSpacing(node, docx, styleId, schemaNode.attrs.marksAttrs, {
32698
+ insideTable
32699
+ });
32700
+ if (spacing) {
32701
+ schemaNode.attrs["spacing"] = spacing;
32702
+ }
32675
32703
  schemaNode.attrs["rsidRDefault"] = defaultStyleId;
32676
32704
  }
32677
32705
  if (docx) {
@@ -32917,10 +32945,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32917
32945
  createAttributeHandler("w:shadow", null, parseBoolean, booleanToString),
32918
32946
  createAttributeHandler("w:frame", null, parseBoolean, booleanToString)
32919
32947
  ],
32920
- encode: (_2, encodedAttrs) => {
32948
+ encode: (params2, encodedAttrs) => {
32921
32949
  return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
32922
32950
  },
32923
- decode: function({ node }, _2) {
32951
+ decode: function({ node }, context) {
32924
32952
  const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs[sdName] || {} } });
32925
32953
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
32926
32954
  }
@@ -33279,10 +33307,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33279
33307
  "w:themeTint",
33280
33308
  "w:val"
33281
33309
  ].map((attr) => createAttributeHandler(attr)),
33282
- encode: (_2, encodedAttrs) => {
33310
+ encode: (params2, encodedAttrs) => {
33283
33311
  return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
33284
33312
  },
33285
- decode: function({ node }, _2) {
33313
+ decode: function({ node }, context) {
33286
33314
  const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.shading || {} } });
33287
33315
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
33288
33316
  }
@@ -33295,10 +33323,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33295
33323
  xmlName: "w:tblLook",
33296
33324
  sdNodeOrKeyName: "tblLook",
33297
33325
  attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
33298
- encode: (_2, encodedAttrs) => {
33326
+ encode: (params2, encodedAttrs) => {
33299
33327
  return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
33300
33328
  },
33301
- decode: function({ node }, _2) {
33329
+ decode: function({ node }, context) {
33302
33330
  const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
33303
33331
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
33304
33332
  }
@@ -33316,10 +33344,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33316
33344
  xmlName: "w:tblpPr",
33317
33345
  sdNodeOrKeyName: "floatingTableProperties",
33318
33346
  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))),
33319
- encode: (_2, encodedAttrs) => {
33347
+ encode: (params2, encodedAttrs) => {
33320
33348
  return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
33321
33349
  },
33322
- decode: function({ node }, _2) {
33350
+ decode: function({ node }, context) {
33323
33351
  const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
33324
33352
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
33325
33353
  }
@@ -33340,13 +33368,13 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33340
33368
  const translator$c = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
33341
33369
  const XML_NODE_NAME$a = "w:tblBorders";
33342
33370
  const SD_ATTR_KEY$3 = "borders";
33343
- const encode$a = (params2, _2) => {
33371
+ const encode$a = (params2) => {
33344
33372
  const { nodes } = params2;
33345
33373
  const node = nodes[0];
33346
33374
  const attributes = encodeProperties(node, tblBordersTranslatorsByXmlName);
33347
33375
  return Object.keys(attributes).length > 0 ? attributes : void 0;
33348
33376
  };
33349
- const decode$a = (params2, _2) => {
33377
+ const decode$a = (params2) => {
33350
33378
  const { borders = {} } = params2.node.attrs || {};
33351
33379
  const elements = decodeProperties(tblBordersTranslatorsBySdName, borders);
33352
33380
  const newNode = {
@@ -33383,13 +33411,13 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33383
33411
  });
33384
33412
  const XML_NODE_NAME$9 = "w:tblCellMar";
33385
33413
  const SD_ATTR_KEY$2 = "cellMargins";
33386
- const encode$9 = (params2, _2) => {
33414
+ const encode$9 = (params2) => {
33387
33415
  const { nodes } = params2;
33388
33416
  const node = nodes[0];
33389
33417
  const attributes = encodeProperties(node, propertyTranslatorsByXmlName$1);
33390
33418
  return Object.keys(attributes).length > 0 ? attributes : void 0;
33391
33419
  };
33392
- const decode$9 = (params2, _2) => {
33420
+ const decode$9 = (params2) => {
33393
33421
  const { cellMargins = {} } = params2.node.attrs || {};
33394
33422
  const elements = decodeProperties(propertyTranslatorsBySdName$1, cellMargins);
33395
33423
  const newNode = {
@@ -33480,6 +33508,53 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33480
33508
  const translator$8 = NodeTranslator.from(
33481
33509
  createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
33482
33510
  );
33511
+ const DEFAULT_COLUMN_WIDTH_PX = 100;
33512
+ const normalizeTwipWidth = (value) => {
33513
+ if (value == null) return null;
33514
+ const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
33515
+ if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
33516
+ return null;
33517
+ }
33518
+ return numericValue;
33519
+ };
33520
+ const getSchemaDefaultColumnWidthPx = (params2) => {
33521
+ const defaultValue = params2?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
33522
+ if (Array.isArray(defaultValue)) {
33523
+ const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
33524
+ if (numericWidth != null) return numericWidth;
33525
+ } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
33526
+ return defaultValue;
33527
+ }
33528
+ return DEFAULT_COLUMN_WIDTH_PX;
33529
+ };
33530
+ const getTableWidthPx = (params2) => {
33531
+ const explicitWidth = params2?.node?.attrs?.tableWidth?.width;
33532
+ if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
33533
+ const tableWidth = params2?.node?.attrs?.tableProperties?.tableWidth;
33534
+ if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
33535
+ const { value, type: type2 } = tableWidth;
33536
+ if (!type2 || type2 === "auto" || type2 === "dxa") {
33537
+ return twipsToPixels(value);
33538
+ }
33539
+ }
33540
+ return null;
33541
+ };
33542
+ const resolveFallbackColumnWidthTwips = (params2, totalColumns, cellMinWidthTwips) => {
33543
+ const columnCount = Math.max(totalColumns, 1);
33544
+ const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params2);
33545
+ const tableWidthPx = getTableWidthPx(params2);
33546
+ const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
33547
+ let fallbackWidthPx = safeDefaultPx;
33548
+ if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
33549
+ fallbackWidthPx = tableWidthPx / columnCount;
33550
+ }
33551
+ const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
33552
+ if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
33553
+ const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
33554
+ return safeDefault;
33555
+ }
33556
+ return Math.max(fallbackWidthTwips, cellMinWidthTwips);
33557
+ };
33483
33558
  const XML_NODE_NAME$7 = "w:tblGrid";
33484
33559
  const SD_ATTR_KEY = "grid";
33485
33560
  const cellMinWidth = pixelsToTwips(10);
@@ -33494,35 +33569,60 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33494
33569
  };
33495
33570
  };
33496
33571
  const decode$7 = (params2) => {
33497
- const { grid = [] } = params2.node.attrs || {};
33572
+ const { grid: rawGrid } = params2.node.attrs || {};
33573
+ const grid = Array.isArray(rawGrid) ? rawGrid : [];
33498
33574
  const { firstRow = {} } = params2.extraParams || {};
33499
33575
  const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
33500
- const numberOfColumns = cellNodes.length || grid.length;
33576
+ const columnCountFromCells = cellNodes.reduce((count, cell) => {
33577
+ const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
33578
+ return count + spanCount;
33579
+ }, 0);
33580
+ const totalColumns = Math.max(columnCountFromCells, grid.length);
33581
+ const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params2, totalColumns, cellMinWidth);
33501
33582
  const elements = [];
33502
- for (let cellIdx = 0; cellIdx < numberOfColumns; cellIdx++) {
33503
- const cell = cellNodes[cellIdx];
33583
+ let columnIndex = 0;
33584
+ const pushColumn = (widthTwips) => {
33585
+ let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
33586
+ if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
33587
+ numericWidth = fallbackColumnWidthTwips;
33588
+ }
33589
+ numericWidth = Math.max(numericWidth, cellMinWidth);
33590
+ const decoded = translator$8.decode({
33591
+ node: { type: (
33592
+ /** @type {string} */
33593
+ translator$8.sdNodeOrKeyName
33594
+ ), attrs: { col: numericWidth } }
33595
+ });
33596
+ if (decoded) elements.push(decoded);
33597
+ };
33598
+ cellNodes.forEach((cell) => {
33504
33599
  const { colspan = 1, colwidth } = cell?.attrs || {};
33505
- for (let mergedCellIdx = 0; mergedCellIdx < colspan; mergedCellIdx++) {
33506
- const cellWidthPixels = colwidth && colwidth[mergedCellIdx];
33507
- const colGridAttrs = grid?.[mergedCellIdx] || {};
33508
- const gridWidthTwips = colGridAttrs.col;
33509
- const gridWidthPixels = twipsToPixels(gridWidthTwips);
33600
+ const spanCount = Math.max(1, colspan);
33601
+ for (let span = 0; span < spanCount; span++) {
33602
+ const cellWidthPixels = Array.isArray(colwidth) ? colwidth[span] : void 0;
33603
+ const colGridAttrs = grid?.[columnIndex] || {};
33604
+ const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
33605
+ const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
33510
33606
  let cellWidthTwips;
33511
- if (gridWidthPixels === cellWidthPixels) {
33607
+ if (cellWidthPixels != null) {
33608
+ if (gridWidthTwips != null && gridWidthPixels === cellWidthPixels) {
33609
+ cellWidthTwips = gridWidthTwips;
33610
+ } else {
33611
+ cellWidthTwips = pixelsToTwips(cellWidthPixels);
33612
+ }
33613
+ } else if (gridWidthTwips != null) {
33512
33614
  cellWidthTwips = gridWidthTwips;
33513
- } else if (cellWidthPixels) {
33514
- cellWidthTwips = pixelsToTwips(cellWidthPixels);
33515
- }
33516
- const widthTwips = Math.max(cellWidthTwips, cellMinWidth);
33517
- elements.push(
33518
- translator$8.decode({
33519
- node: { type: (
33520
- /** @type {string} */
33521
- translator$8.sdNodeOrKeyName
33522
- ), attrs: { col: widthTwips } }
33523
- })
33524
- );
33615
+ } else {
33616
+ cellWidthTwips = fallbackColumnWidthTwips;
33617
+ }
33618
+ pushColumn(cellWidthTwips);
33619
+ columnIndex++;
33525
33620
  }
33621
+ });
33622
+ while (columnIndex < grid.length) {
33623
+ const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
33624
+ pushColumn(gridWidthTwips);
33625
+ columnIndex++;
33526
33626
  }
33527
33627
  const newNode = {
33528
33628
  name: XML_NODE_NAME$7,
@@ -33545,7 +33645,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33545
33645
  const node = nodes[0];
33546
33646
  const tblPr = node.elements.find((el) => el.name === "w:tblPr");
33547
33647
  if (tblPr) {
33548
- encodedAttrs["tableProperties"] = translator$9.encode({ ...params2, nodes: [tblPr] }).attributes;
33648
+ const encodedProperties = translator$9.encode({ ...params2, nodes: [tblPr] });
33649
+ encodedAttrs["tableProperties"] = encodedProperties?.attributes || {};
33549
33650
  }
33550
33651
  const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
33551
33652
  if (tblGrid) {
@@ -33567,7 +33668,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33567
33668
  key2 = prop;
33568
33669
  transform = (v2) => v2;
33569
33670
  }
33570
- if (encodedAttrs.tableProperties?.[key2]) {
33671
+ if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key2]) {
33571
33672
  encodedAttrs[key2] = transform(encodedAttrs.tableProperties[key2]);
33572
33673
  }
33573
33674
  });
@@ -33576,11 +33677,17 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33576
33677
  }
33577
33678
  const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
33578
33679
  const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params2);
33680
+ if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
33681
+ encodedAttrs.tableProperties = {
33682
+ ...encodedAttrs.tableProperties || {},
33683
+ cellMargins: referencedStyles.cellMargins
33684
+ };
33685
+ }
33579
33686
  const rows = node.elements.filter((el) => el.name === "w:tr");
33580
33687
  const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
33581
33688
  const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
33582
33689
  encodedAttrs["borders"] = borderData;
33583
- const tblStyleTag = tblPr.elements.find((el) => el.name === "w:tblStyle");
33690
+ const tblStyleTag = tblPr?.elements?.find((el) => el.name === "w:tblStyle");
33584
33691
  const columnWidths = (encodedAttrs["grid"] ?? []).map((item) => twipsToPixels(item.col));
33585
33692
  const content = [];
33586
33693
  rows.forEach((row) => {
@@ -33589,6 +33696,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33589
33696
  nodes: [row],
33590
33697
  extraParams: {
33591
33698
  row,
33699
+ table: node,
33592
33700
  rowBorders: borderRowData,
33593
33701
  styleTag: tblStyleTag,
33594
33702
  columnWidths
@@ -33690,7 +33798,12 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33690
33798
  if (rowBorders) stylesToReturn.rowBorders = rowBorders;
33691
33799
  const cellMargins = {};
33692
33800
  Object.entries(tableProperties.cellMargins || {}).forEach(([key2, attrs]) => {
33693
- if (attrs?.value) cellMargins[key2] = String(attrs.value);
33801
+ if (attrs?.value != null) {
33802
+ cellMargins[key2] = {
33803
+ value: attrs.value,
33804
+ type: attrs.type || "dxa"
33805
+ };
33806
+ }
33694
33807
  });
33695
33808
  if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
33696
33809
  }
@@ -33943,11 +34056,17 @@ Please report this to https://github.com/markedjs/marked.`, e) {
33943
34056
  marginTop: marginTopStyle,
33944
34057
  marginBottom: marginBottomStyle
33945
34058
  } = cellMargins;
34059
+ const resolveMargin = (inlineValue, styleValue) => {
34060
+ if (inlineValue != null) return inlineValue;
34061
+ if (styleValue == null) return void 0;
34062
+ if (typeof styleValue === "object") return styleValue.value;
34063
+ return styleValue;
34064
+ };
33946
34065
  const margins = {
33947
- left: twipsToPixels(inlineMarginLeftValue ?? marginLeftStyle),
33948
- right: twipsToPixels(inlineMarginRightValue ?? marginRightStyle),
33949
- top: twipsToPixels(inlineMarginTopValue ?? marginTopStyle),
33950
- bottom: twipsToPixels(inlineMarginBottomValue ?? marginBottomStyle)
34066
+ left: twipsToPixels(resolveMargin(inlineMarginLeftValue, marginLeftStyle)),
34067
+ right: twipsToPixels(resolveMargin(inlineMarginRightValue, marginRightStyle)),
34068
+ top: twipsToPixels(resolveMargin(inlineMarginTopValue, marginTopStyle)),
34069
+ bottom: twipsToPixels(resolveMargin(inlineMarginBottomValue, marginBottomStyle))
33951
34070
  };
33952
34071
  return margins;
33953
34072
  };
@@ -34222,7 +34341,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
34222
34341
  }
34223
34342
  try {
34224
34343
  return JSON.parse(trimmed);
34225
- } catch (err) {
34344
+ } catch {
34226
34345
  return {};
34227
34346
  }
34228
34347
  }
@@ -34961,14 +35080,14 @@ Please report this to https://github.com/markedjs/marked.`, e) {
34961
35080
  const XML_NODE_NAME$3 = "wp:anchor";
34962
35081
  const SD_NODE_NAME$3 = ["image"];
34963
35082
  const validXmlAttributes$3 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
34964
- function encode$3(params2, encodedAttrs) {
35083
+ function encode$3(params2) {
34965
35084
  const { node } = params2.extraParams;
34966
35085
  if (!node || !node.type) {
34967
35086
  return null;
34968
35087
  }
34969
35088
  return handleAnchorNode(params2);
34970
35089
  }
34971
- function decode$3(params2, decodedAttrs) {
35090
+ function decode$3(params2) {
34972
35091
  const { node } = params2;
34973
35092
  if (!node || !node.type) {
34974
35093
  return null;
@@ -35002,14 +35121,14 @@ Please report this to https://github.com/markedjs/marked.`, e) {
35002
35121
  const XML_NODE_NAME$2 = "wp:inline";
35003
35122
  const SD_NODE_NAME$2 = ["image"];
35004
35123
  const validXmlAttributes$2 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
35005
- function encode$2(params2, encodedAttrs) {
35124
+ function encode$2(params2) {
35006
35125
  const { node } = params2.extraParams;
35007
35126
  if (!node || !node.type) {
35008
35127
  return null;
35009
35128
  }
35010
35129
  return handleInlineNode(params2);
35011
35130
  }
35012
- function decode$2(params2, decodedAttrs) {
35131
+ function decode$2(params2) {
35013
35132
  const { node } = params2;
35014
35133
  if (!node || !node.type) {
35015
35134
  return null;
@@ -35035,7 +35154,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
35035
35154
  const XML_NODE_NAME$1 = "w:drawing";
35036
35155
  const SD_NODE_NAME$1 = [];
35037
35156
  const validXmlAttributes$1 = [];
35038
- function encode$1(params2, encodedAttrs) {
35157
+ function encode$1(params2) {
35039
35158
  const nodes = params2.nodes;
35040
35159
  const node = nodes[0];
35041
35160
  const validChildTranslators = ["wp:anchor", "wp:inline"];
@@ -35046,7 +35165,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
35046
35165
  return translator2.encode({ ...params2, extraParams: { node: child } }) || acc;
35047
35166
  }, null);
35048
35167
  }
35049
- function decode$1(params2, decodedAttrs) {
35168
+ function decode$1(params2) {
35050
35169
  const { node } = params2;
35051
35170
  if (!node || !node.type) {
35052
35171
  return null;
@@ -36647,7 +36766,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36647
36766
  const XML_NODE_NAME = "w:sdt";
36648
36767
  const SD_NODE_NAME = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
36649
36768
  const validXmlAttributes = [];
36650
- function encode$s(params2, encodedAttrs) {
36769
+ function encode$s(params2) {
36651
36770
  const nodes = params2.nodes;
36652
36771
  const node = nodes[0];
36653
36772
  const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
@@ -36657,7 +36776,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36657
36776
  const result = handler2(params2);
36658
36777
  return result;
36659
36778
  }
36660
- function decode(params2, decodedAttrs) {
36779
+ function decode(params2) {
36661
36780
  const { node } = params2;
36662
36781
  if (!node || !node.type) {
36663
36782
  return null;
@@ -66365,7 +66484,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
66365
66484
  credentials: "omit"
66366
66485
  });
66367
66486
  return response.ok;
66368
- } catch (_error) {
66487
+ } catch {
66369
66488
  return false;
66370
66489
  }
66371
66490
  };
@@ -66534,6 +66653,57 @@ Please report this to https://github.com/markedjs/marked.`, e) {
66534
66653
  }
66535
66654
  resample_high_quality(canvas, width, height);
66536
66655
  }
66656
+ const FALLBACK_NAME = "image";
66657
+ const stripDiacritics = (value) => value.normalize("NFKD").replace(/[\u0300-\u036f]/g, "");
66658
+ const sanitizeSegment = (segment, { allowDots = false } = {}) => {
66659
+ if (!segment) return "";
66660
+ const normalized = stripDiacritics(segment).replace(/[\s\u2000-\u206f]+/g, "_").replace(/[\\/]+/g, "_");
66661
+ const allowedPattern = allowDots ? /[^0-9A-Za-z._-]+/g : /[^0-9A-Za-z_-]+/g;
66662
+ let sanitized = normalized.replace(allowedPattern, "_");
66663
+ sanitized = sanitized.replace(/_+/g, "_");
66664
+ sanitized = sanitized.replace(/^[_.-]+/, "");
66665
+ sanitized = sanitized.replace(/[_-]+$/, "");
66666
+ return sanitized;
66667
+ };
66668
+ const splitFileName = (name) => {
66669
+ const trimmed = name?.trim?.() ?? "";
66670
+ const lastDot = trimmed.lastIndexOf(".");
66671
+ if (lastDot <= 0 || lastDot === trimmed.length - 1) {
66672
+ return { base: trimmed, ext: "" };
66673
+ }
66674
+ return {
66675
+ base: trimmed.slice(0, lastDot),
66676
+ ext: trimmed.slice(lastDot + 1)
66677
+ };
66678
+ };
66679
+ const sanitizeImageFileName = (inputName) => {
66680
+ const { base: base2, ext } = splitFileName(inputName || "");
66681
+ const sanitizedBase = sanitizeSegment(base2, { allowDots: true }) || FALLBACK_NAME;
66682
+ const sanitizedExt = sanitizeSegment(ext, { allowDots: false }).toLowerCase();
66683
+ if (!sanitizedExt) return sanitizedBase;
66684
+ return `${sanitizedBase}.${sanitizedExt}`;
66685
+ };
66686
+ const ensureUniqueFileName = (preferredName, existingNames = /* @__PURE__ */ new Set()) => {
66687
+ const sanitized = sanitizeImageFileName(preferredName);
66688
+ if (!existingNames || typeof existingNames.has !== "function") {
66689
+ return sanitized;
66690
+ }
66691
+ const existingSet = /* @__PURE__ */ new Set();
66692
+ existingNames.forEach((name) => existingSet.add(sanitizeImageFileName(name)));
66693
+ if (!existingSet.has(sanitized)) {
66694
+ return sanitized;
66695
+ }
66696
+ const { base: base2, ext } = splitFileName(sanitized);
66697
+ let counter = 1;
66698
+ let candidate = sanitized;
66699
+ const suffix2 = () => `${base2}-${counter}${ext ? `.${ext}` : ""}`;
66700
+ while (existingSet.has(candidate)) {
66701
+ candidate = suffix2();
66702
+ counter += 1;
66703
+ }
66704
+ return candidate;
66705
+ };
66706
+ const buildMediaPath = (fileName) => `word/media/${fileName}`;
66537
66707
  const fileTooLarge = (file) => {
66538
66708
  let fileSizeMb = Number((file.size / (1024 * 1024)).toFixed(4));
66539
66709
  if (fileSizeMb > 5) {
@@ -66567,16 +66737,37 @@ Please report this to https://github.com/markedjs/marked.`, e) {
66567
66737
  tr = addImagePlaceholder(view.state, tr, id, selection.from);
66568
66738
  view.dispatch(tr);
66569
66739
  }
66740
+ const generateUniqueDocPrId = (editor) => {
66741
+ const existingIds = /* @__PURE__ */ new Set();
66742
+ editor?.state?.doc?.descendants((node) => {
66743
+ if (node.type.name === "image" && node.attrs.id !== void 0 && node.attrs.id !== null) {
66744
+ existingIds.add(String(node.attrs.id));
66745
+ }
66746
+ });
66747
+ let candidate;
66748
+ do {
66749
+ const hex2 = generateDocxRandomId();
66750
+ candidate = String(parseInt(hex2, 16));
66751
+ } while (!candidate || existingIds.has(candidate));
66752
+ return candidate;
66753
+ };
66570
66754
  async function uploadAndInsertImage({ editor, view, file, size: size2, id }) {
66571
66755
  const imageUploadHandler = typeof editor.options.handleImageUpload === "function" ? editor.options.handleImageUpload : handleImageUpload;
66756
+ const placeholderId = id;
66572
66757
  try {
66573
- let url = await imageUploadHandler(file);
66574
- let fileName = file.name.replace(" ", "_");
66575
- let placeholderPos = findPlaceholder(view.state, id);
66758
+ const existingFileNames = new Set(Object.keys(editor.storage.image.media ?? {}).map((key2) => key2.split("/").pop()));
66759
+ const uniqueFileName = ensureUniqueFileName(file.name, existingFileNames);
66760
+ const normalizedFile = uniqueFileName === file.name ? file : new File([file], uniqueFileName, {
66761
+ type: file.type,
66762
+ lastModified: file.lastModified ?? Date.now()
66763
+ });
66764
+ let url = await imageUploadHandler(normalizedFile);
66765
+ let placeholderPos = findPlaceholder(view.state, placeholderId);
66576
66766
  if (placeholderPos == null) {
66577
66767
  return;
66578
66768
  }
66579
- let mediaPath = `word/media/${fileName}`;
66769
+ const mediaPath = buildMediaPath(uniqueFileName);
66770
+ const docPrId = generateUniqueDocPrId(editor);
66580
66771
  let rId = null;
66581
66772
  if (editor.options.mode === "docx") {
66582
66773
  const [, path] = mediaPath.split("word/");
@@ -66586,7 +66777,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
66586
66777
  let imageNode = view.state.schema.nodes.image.create({
66587
66778
  src: mediaPath,
66588
66779
  size: size2,
66589
- id,
66780
+ id: docPrId,
66590
66781
  rId
66591
66782
  });
66592
66783
  editor.storage.image.media = Object.assign(editor.storage.image.media, { [mediaPath]: url });
@@ -66595,10 +66786,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
66595
66786
  }
66596
66787
  let tr = view.state.tr;
66597
66788
  tr.replaceWith(placeholderPos, placeholderPos, imageNode);
66598
- tr = removeImagePlaceholder(view.state, tr, id);
66789
+ tr = removeImagePlaceholder(view.state, tr, placeholderId);
66599
66790
  view.dispatch(tr);
66600
66791
  } catch {
66601
- const tr = removeImagePlaceholder(view.state, view.state.tr, id);
66792
+ const tr = removeImagePlaceholder(view.state, view.state.tr, placeholderId);
66602
66793
  view.dispatch(tr);
66603
66794
  }
66604
66795
  }
@@ -67769,7 +67960,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
67769
67960
  this.htmlAttributes = props.htmlAttributes;
67770
67961
  this.mount(props);
67771
67962
  }
67772
- mount(props) {
67963
+ mount() {
67773
67964
  return;
67774
67965
  }
67775
67966
  get dom() {