@harbour-enterprises/superdoc 0.27.3-next.1 → 0.27.3-next.2

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 (26) hide show
  1. package/dist/chunks/{PdfViewer-BkJGiP2u.cjs → PdfViewer-B4iIjHV0.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-Bnj3c-92.es.js → PdfViewer-BjZ5mGJm.es.js} +1 -1
  3. package/dist/chunks/{index-CuLDIhMe.cjs → index-D6aLyyxJ.cjs} +2 -2
  4. package/dist/chunks/{index-lF5qA9nw.es.js → index-DkzQzDKS.es.js} +2 -2
  5. package/dist/chunks/{super-editor.es-RvLsj0rg.cjs → super-editor.es-BbpZtQLg.cjs} +1667 -1746
  6. package/dist/chunks/{super-editor.es-6ikSS3Qu.es.js → super-editor.es-DAZHU_K5.es.js} +1667 -1746
  7. package/dist/super-editor/ai-writer.es.js +2 -2
  8. package/dist/super-editor/chunks/{converter-GcMLdei-.js → converter-qTrGAY0a.js} +1818 -1897
  9. package/dist/super-editor/chunks/{docx-zipper-Y0x9TJvc.js → docx-zipper-BRttLmZq.js} +1 -1
  10. package/dist/super-editor/chunks/{editor-B97ToSSc.js → editor-DqOCeU9J.js} +2 -2
  11. package/dist/super-editor/chunks/{toolbar-Cm21JZgi.js → toolbar-cZin2t1V.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/super-editor/src/core/super-converter/v2/importer/tableImporter.d.ts +0 -16
  17. package/dist/super-editor/super-editor/src/core/super-converter/v3/handlers/w/tc/helpers/legacy-handle-table-cell-node.d.ts +1 -1
  18. package/dist/super-editor/super-editor.es.js +6 -6
  19. package/dist/super-editor/toolbar.es.js +2 -2
  20. package/dist/super-editor.cjs +1 -1
  21. package/dist/super-editor.es.js +1 -1
  22. package/dist/superdoc.cjs +2 -2
  23. package/dist/superdoc.es.js +2 -2
  24. package/dist/superdoc.umd.js +1667 -1746
  25. package/dist/superdoc.umd.js.map +1 -1
  26. package/package.json +1 -1
@@ -34732,53 +34732,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
34732
34732
  attributes: validXmlAttributes$c
34733
34733
  };
34734
34734
  const translator$1b = NodeTranslator.from(config$h);
34735
- function preProcessVerticalMergeCells(table, { editorSchema }) {
34736
- if (!table || !Array.isArray(table.content)) {
34737
- return table;
34738
- }
34739
- const rows = table.content;
34740
- for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
34741
- const row = rows[rowIndex];
34742
- if (!row) continue;
34743
- if (!Array.isArray(row.content)) {
34744
- row.content = [];
34745
- }
34746
- for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
34747
- const cell = row.content[cellIndex];
34748
- if (!cell) continue;
34749
- const attrs = cell.attrs || {};
34750
- if (!attrs.rowspan || attrs.rowspan <= 1) continue;
34751
- const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
34752
- for (let offset2 = 1; offset2 < maxRowspan; offset2++) {
34753
- const rowToChange = rows[rowIndex + offset2];
34754
- if (!rowToChange) continue;
34755
- if (!Array.isArray(rowToChange.content)) {
34756
- rowToChange.content = [];
34757
- }
34758
- const existingCell = rowToChange.content[cellIndex];
34759
- if (existingCell?.attrs?.continueMerge) continue;
34760
- const mergedCell = {
34761
- type: cell.type,
34762
- content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
34763
- attrs: {
34764
- ...cell.attrs,
34765
- rowspan: null,
34766
- continueMerge: true
34767
- }
34768
- };
34769
- rowToChange.content.splice(cellIndex, 0, mergedCell);
34770
- }
34771
- }
34772
- }
34773
- return table;
34774
- }
34775
34735
  const translator$1a = NodeTranslator.from({
34776
- xmlName: "w:cantSplit",
34777
- sdNodeOrKeyName: "cantSplit",
34778
- encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
34779
- decode: ({ node }) => node.attrs?.cantSplit ? { attributes: {} } : void 0
34780
- });
34781
- const translator$19 = NodeTranslator.from({
34782
34736
  xmlName: "w:cnfStyle",
34783
34737
  sdNodeOrKeyName: "cnfStyle",
34784
34738
  attributes: [
@@ -34804,1329 +34758,426 @@ Please report this to https://github.com/markedjs/marked.`, e) {
34804
34758
  return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
34805
34759
  }
34806
34760
  });
34807
- const translator$18 = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
34761
+ const translator$19 = NodeTranslator.from({
34762
+ xmlName: "w:shd",
34763
+ sdNodeOrKeyName: "shading",
34764
+ attributes: [
34765
+ "w:color",
34766
+ "w:fill",
34767
+ "w:themeColor",
34768
+ "w:themeFill",
34769
+ "w:themeFillShade",
34770
+ "w:themeFillTint",
34771
+ "w:themeShade",
34772
+ "w:themeTint",
34773
+ "w:val"
34774
+ ].map((attr) => createAttributeHandler(attr)),
34775
+ encode: (params2, encodedAttrs) => {
34776
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
34777
+ },
34778
+ decode: function({ node }, context) {
34779
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.shading || {} } });
34780
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
34781
+ }
34782
+ });
34783
+ const translator$18 = NodeTranslator.from(createMeasurementPropertyHandler("w:tcW", "cellWidth"));
34808
34784
  const translator$17 = NodeTranslator.from(
34809
34785
  createSingleAttrPropertyHandler(
34810
- "w:gridAfter",
34786
+ "w:gridSpan",
34811
34787
  null,
34812
34788
  "w:val",
34813
34789
  (v2) => parseInteger(v2) ?? void 0,
34814
34790
  (v2) => integerToString(v2)
34815
34791
  )
34816
34792
  );
34817
- const translator$16 = NodeTranslator.from(
34793
+ const translator$16 = NodeTranslator.from(createSingleAttrPropertyHandler("w:vMerge"));
34794
+ const translator$15 = NodeTranslator.from(createBorderPropertyHandler("w:bottom"));
34795
+ const translator$14 = NodeTranslator.from(createMeasurementPropertyHandler("w:bottom", "marginBottom"));
34796
+ const translator$13 = NodeTranslator.from(createBorderPropertyHandler("w:end"));
34797
+ const translator$12 = NodeTranslator.from(createMeasurementPropertyHandler("w:end", "marginEnd"));
34798
+ const translator$11 = NodeTranslator.from(createBorderPropertyHandler("w:insideH"));
34799
+ const translator$10 = NodeTranslator.from(createBorderPropertyHandler("w:insideV"));
34800
+ const translator$$ = NodeTranslator.from(createBorderPropertyHandler("w:left"));
34801
+ const translator$_ = NodeTranslator.from(createMeasurementPropertyHandler("w:left", "marginLeft"));
34802
+ const translator$Z = NodeTranslator.from(createBorderPropertyHandler("w:right"));
34803
+ const translator$Y = NodeTranslator.from(createMeasurementPropertyHandler("w:right", "marginRight"));
34804
+ const translator$X = NodeTranslator.from(createBorderPropertyHandler("w:start"));
34805
+ const translator$W = NodeTranslator.from(createMeasurementPropertyHandler("w:start", "marginStart"));
34806
+ const translator$V = NodeTranslator.from(createBorderPropertyHandler("w:top"));
34807
+ const translator$U = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
34808
+ const translator$T = NodeTranslator.from(createBorderPropertyHandler("w:tl2br"));
34809
+ const translator$S = NodeTranslator.from(createBorderPropertyHandler("w:tr2bl"));
34810
+ const propertyTranslators$6 = [
34811
+ translator$V,
34812
+ translator$X,
34813
+ translator$$,
34814
+ translator$15,
34815
+ translator$13,
34816
+ translator$Z,
34817
+ translator$11,
34818
+ translator$10,
34819
+ translator$T,
34820
+ translator$S
34821
+ ];
34822
+ const translator$R = NodeTranslator.from(
34823
+ createNestedPropertiesTranslator("w:tcBorders", "borders", propertyTranslators$6)
34824
+ );
34825
+ const translator$Q = NodeTranslator.from(
34818
34826
  createSingleAttrPropertyHandler(
34819
- "w:gridBefore",
34827
+ "w:noWrap",
34820
34828
  null,
34821
34829
  "w:val",
34822
- (v2) => parseInteger(v2) ?? void 0,
34823
- (v2) => integerToString(v2)
34830
+ (v2) => parseBoolean(v2 ?? "true"),
34831
+ (v2) => booleanToString(v2)
34824
34832
  )
34825
34833
  );
34826
- const translator$15 = NodeTranslator.from({
34827
- xmlName: "w:hidden",
34828
- sdNodeOrKeyName: "hidden",
34829
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
34830
- decode: ({ node }) => node.attrs.hidden ? { attributes: {} } : void 0
34831
- });
34832
- const translator$14 = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc", "justification"));
34833
- const translator$13 = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "tableCellSpacing"));
34834
- const translator$12 = NodeTranslator.from({
34835
- xmlName: "w:tblHeader",
34836
- sdNodeOrKeyName: "repeatHeader",
34837
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
34838
- decode: ({ node }) => node.attrs.repeatHeader ? { attributes: {} } : void 0
34839
- });
34840
- const translator$11 = NodeTranslator.from({
34841
- xmlName: "w:trHeight",
34842
- sdNodeOrKeyName: "rowHeight",
34843
- encode: ({ nodes }) => {
34844
- const heightAttrs = {};
34845
- const val = nodes[0].attributes["w:val"];
34846
- if (val) {
34847
- heightAttrs["value"] = parseInt(val, 10);
34848
- }
34849
- const rule = nodes[0].attributes["w:hRule"];
34850
- if (rule) {
34851
- heightAttrs["rule"] = rule;
34852
- }
34853
- return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
34854
- },
34855
- decode: ({ node }) => {
34856
- if (!node.attrs?.rowHeight) return;
34857
- const heightAttrs = {};
34858
- if (typeof node.attrs.rowHeight.value === "number" && !isNaN(node.attrs.rowHeight.value)) {
34859
- heightAttrs["w:val"] = String(node.attrs.rowHeight.value);
34860
- }
34861
- if (node.attrs.rowHeight.rule) {
34862
- heightAttrs["w:hRule"] = node.attrs.rowHeight.rule;
34863
- }
34864
- return Object.keys(heightAttrs).length > 0 ? { attributes: heightAttrs } : void 0;
34865
- }
34866
- });
34867
- const translator$10 = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
34868
- const translator$$ = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
34869
- const propertyTranslators$6 = [
34870
- translator$1a,
34871
- translator$19,
34872
- translator$18,
34873
- translator$17,
34874
- translator$16,
34875
- translator$15,
34834
+ const propertyTranslators$5 = [
34876
34835
  translator$14,
34877
- translator$13,
34878
34836
  translator$12,
34879
- translator$11,
34880
- translator$10,
34881
- translator$$
34837
+ translator$_,
34838
+ translator$Y,
34839
+ translator$W,
34840
+ translator$U
34882
34841
  ];
34883
- const translator$_ = NodeTranslator.from(
34884
- createNestedPropertiesTranslator("w:trPr", "tableRowProperties", propertyTranslators$6, {
34885
- cantSplit: false,
34886
- hidden: false,
34887
- repeatHeader: false
34888
- })
34842
+ const translator$P = NodeTranslator.from(
34843
+ createNestedPropertiesTranslator("w:tcMar", "cellMargins", propertyTranslators$5)
34889
34844
  );
34890
- const createPlaceholderCell = (gridWidth, reason) => {
34891
- const safeWidth = Number.isFinite(gridWidth) ? gridWidth : 0;
34892
- const noBorder = { val: "none", size: 0 };
34845
+ const translator$O = NodeTranslator.from(createSingleAttrPropertyHandler("w:textDirection"));
34846
+ const translator$N = NodeTranslator.from(
34847
+ createSingleAttrPropertyHandler(
34848
+ "w:tcFitText",
34849
+ null,
34850
+ "w:val",
34851
+ (v2) => parseBoolean(v2 ?? "true"),
34852
+ (v2) => booleanToString(v2)
34853
+ )
34854
+ );
34855
+ const translator$M = NodeTranslator.from(createSingleAttrPropertyHandler("w:vAlign"));
34856
+ const translator$L = NodeTranslator.from(
34857
+ createSingleAttrPropertyHandler(
34858
+ "w:hideMark",
34859
+ null,
34860
+ "w:val",
34861
+ (v2) => parseBoolean(v2 ?? "true"),
34862
+ (v2) => booleanToString(v2)
34863
+ )
34864
+ );
34865
+ const translator$K = NodeTranslator.from(createSingleAttrPropertyHandler("w:header"));
34866
+ const XML_NODE_NAME$h = "w:headers";
34867
+ const SD_ATTR_KEY$3 = "headers";
34868
+ const encode$n = (params2) => {
34869
+ const { nodes } = params2;
34870
+ const node = nodes[0];
34871
+ const attributes = encodeProperties(node, { [translator$K.xmlName]: translator$K }, true);
34893
34872
  return {
34894
- type: "tableCell",
34895
- attrs: {
34896
- colspan: 1,
34897
- rowspan: 1,
34898
- colwidth: [safeWidth],
34899
- __placeholder: reason,
34900
- borders: {
34901
- top: { ...noBorder },
34902
- right: { ...noBorder },
34903
- bottom: { ...noBorder },
34904
- left: { ...noBorder }
34905
- }
34906
- },
34907
- content: [{ type: "paragraph", content: [] }]
34873
+ xmlName: XML_NODE_NAME$h,
34874
+ sdNodeOrKeyName: SD_ATTR_KEY$3,
34875
+ attributes
34908
34876
  };
34909
34877
  };
34910
- const advancePastRowSpans = (pendingRowSpans, startIndex, totalColumns) => {
34911
- let index2 = startIndex;
34912
- while (index2 < totalColumns && pendingRowSpans[index2] > 0) {
34913
- pendingRowSpans[index2] -= 1;
34914
- index2 += 1;
34915
- }
34916
- return index2;
34917
- };
34918
- const fillPlaceholderColumns = ({
34919
- content,
34920
- pendingRowSpans,
34921
- currentIndex,
34922
- targetIndex,
34923
- totalColumns,
34924
- gridColumnWidths,
34925
- reason
34926
- }) => {
34927
- let index2 = currentIndex;
34928
- while (index2 < targetIndex && index2 < totalColumns) {
34929
- if (pendingRowSpans[index2] > 0) {
34930
- pendingRowSpans[index2] -= 1;
34931
- index2 += 1;
34932
- continue;
34933
- }
34934
- const width = Array.isArray(gridColumnWidths) ? gridColumnWidths[index2] ?? 0 : 0;
34935
- content.push(createPlaceholderCell(width, reason));
34936
- index2 += 1;
34937
- }
34938
- return index2;
34939
- };
34940
- const isPlaceholderCell = (cell) => {
34941
- if (!cell) return false;
34942
- if (cell.attrs?.__placeholder) return true;
34943
- const widths = cell.attrs?.colwidth;
34944
- if (Array.isArray(widths) && widths.length > 0) {
34945
- const hasMeaningfulWidth = widths.some(
34946
- (value) => typeof value === "number" && Number.isFinite(value) && Math.abs(value) > 1
34947
- );
34948
- if (!hasMeaningfulWidth) return true;
34949
- }
34950
- return false;
34951
- };
34952
- const XML_NODE_NAME$h = "w:tr";
34953
- const SD_NODE_NAME$d = "tableRow";
34954
- const validXmlAttributes$b = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
34955
- (xmlName) => createAttributeHandler(xmlName)
34956
- );
34957
- const encode$n = (params2, encodedAttrs) => {
34958
- const { row } = params2.extraParams;
34959
- let tableRowProperties = {};
34960
- const tPr = row.elements.find((el) => el.name === "w:trPr");
34961
- if (tPr) {
34962
- tableRowProperties = translator$_.encode({
34963
- ...params2,
34964
- nodes: [tPr]
34965
- });
34966
- }
34967
- const gridBeforeRaw = tableRowProperties?.["gridBefore"];
34968
- const safeGridBefore = typeof gridBeforeRaw === "number" && Number.isFinite(gridBeforeRaw) && gridBeforeRaw > 0 ? gridBeforeRaw : 0;
34969
- encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
34970
- encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
34971
- encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
34972
- const { columnWidths: gridColumnWidths, activeRowSpans = [] } = params2.extraParams;
34973
- const totalColumns = Array.isArray(gridColumnWidths) ? gridColumnWidths.length : 0;
34974
- const pendingRowSpans = Array.isArray(activeRowSpans) ? activeRowSpans.slice() : [];
34975
- while (pendingRowSpans.length < totalColumns) pendingRowSpans.push(0);
34976
- const cellNodes = row.elements.filter((el) => el.name === "w:tc");
34977
- const content = [];
34978
- let currentColumnIndex = 0;
34979
- const fillUntil = (target, reason) => {
34980
- currentColumnIndex = fillPlaceholderColumns({
34981
- content,
34982
- pendingRowSpans,
34983
- currentIndex: currentColumnIndex,
34984
- targetIndex: target,
34985
- totalColumns,
34986
- gridColumnWidths,
34987
- reason
34988
- });
34989
- };
34990
- const skipOccupiedColumns = () => {
34991
- currentColumnIndex = advancePastRowSpans(pendingRowSpans, currentColumnIndex, totalColumns);
34992
- };
34993
- fillUntil(safeGridBefore, "gridBefore");
34994
- skipOccupiedColumns();
34995
- cellNodes?.forEach((node) => {
34996
- skipOccupiedColumns();
34997
- const startColumn = currentColumnIndex;
34998
- const columnWidth = gridColumnWidths?.[startColumn] || null;
34999
- const result = translator$c.encode({
35000
- ...params2,
35001
- extraParams: {
35002
- ...params2.extraParams,
35003
- node,
35004
- columnIndex: startColumn,
35005
- columnWidth
35006
- }
35007
- });
35008
- if (result) {
35009
- content.push(result);
35010
- const colspan = Math.max(1, result.attrs?.colspan || 1);
35011
- const rowspan = Math.max(1, result.attrs?.rowspan || 1);
35012
- if (rowspan > 1) {
35013
- for (let offset2 = 0; offset2 < colspan; offset2 += 1) {
35014
- const target = startColumn + offset2;
35015
- if (target < pendingRowSpans.length) {
35016
- pendingRowSpans[target] = Math.max(pendingRowSpans[target], rowspan - 1);
35017
- }
35018
- }
35019
- }
35020
- currentColumnIndex = startColumn + colspan;
35021
- }
35022
- });
35023
- skipOccupiedColumns();
35024
- fillUntil(totalColumns, "gridAfter");
34878
+ const decode$p = (params2) => {
34879
+ const { headers = [] } = params2.node.attrs || {};
35025
34880
  const newNode = {
35026
- type: "tableRow",
35027
- content,
35028
- attrs: encodedAttrs
34881
+ name: XML_NODE_NAME$h,
34882
+ attributes: {},
34883
+ elements: headers.map(
34884
+ (header) => translator$K.decode({
34885
+ node: { type: "header", attrs: header }
34886
+ })
34887
+ )
35029
34888
  };
35030
34889
  return newNode;
35031
34890
  };
35032
- const decode$p = (params2, decodedAttrs) => {
35033
- const { node } = params2;
35034
- const cells = node.content || [];
35035
- let leadingPlaceholders = 0;
35036
- while (leadingPlaceholders < cells.length && isPlaceholderCell(cells[leadingPlaceholders])) {
35037
- leadingPlaceholders += 1;
35038
- }
35039
- let trailingPlaceholders = 0;
35040
- while (trailingPlaceholders < cells.length - leadingPlaceholders && isPlaceholderCell(cells[cells.length - 1 - trailingPlaceholders])) {
35041
- trailingPlaceholders += 1;
35042
- }
35043
- const trimmedSlice = cells.slice(leadingPlaceholders, cells.length - trailingPlaceholders);
35044
- const sanitizedCells = trimmedSlice.map((cell) => {
35045
- if (cell?.attrs && "__placeholder" in cell.attrs) {
35046
- const { __placeholder, ...rest } = cell.attrs;
35047
- return { ...cell, attrs: rest };
35048
- }
35049
- return cell;
35050
- });
35051
- const trimmedContent = sanitizedCells.filter((_2, index2) => !isPlaceholderCell(trimmedSlice[index2]));
35052
- const translateParams = {
35053
- ...params2,
35054
- node: { ...node, content: trimmedContent }
35055
- };
35056
- const elements = translateChildNodes(translateParams);
35057
- if (node.attrs?.tableRowProperties) {
35058
- const tableRowProperties = { ...node.attrs.tableRowProperties };
35059
- if (leadingPlaceholders > 0) {
35060
- tableRowProperties.gridBefore = leadingPlaceholders;
35061
- }
35062
- if (trailingPlaceholders > 0) {
35063
- tableRowProperties.gridAfter = trailingPlaceholders;
35064
- }
35065
- if (node.attrs.rowHeight != null) {
35066
- const rowHeightPixels = twipsToPixels(node.attrs.tableRowProperties["rowHeight"]?.value);
35067
- if (rowHeightPixels !== node.attrs.rowHeight) {
35068
- tableRowProperties["rowHeight"] = { value: String(pixelsToTwips(node.attrs["rowHeight"])) };
35069
- }
35070
- }
35071
- tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
35072
- const trPr = translator$_.decode({
35073
- ...params2,
35074
- node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
35075
- });
35076
- if (trPr) elements.unshift(trPr);
35077
- }
35078
- return {
35079
- name: "w:tr",
35080
- attributes: decodedAttrs || {},
35081
- elements
35082
- };
35083
- };
35084
34891
  const config$g = {
35085
34892
  xmlName: XML_NODE_NAME$h,
35086
- sdNodeOrKeyName: SD_NODE_NAME$d,
35087
- type: NodeTranslator.translatorTypes.NODE,
34893
+ sdNodeOrKeyName: SD_ATTR_KEY$3,
35088
34894
  encode: encode$n,
35089
- decode: decode$p,
35090
- attributes: validXmlAttributes$b
34895
+ decode: decode$p
35091
34896
  };
35092
- const translator$Z = NodeTranslator.from(config$g);
35093
- const translator$Y = NodeTranslator.from({
35094
- xmlName: "w:bidiVisual",
35095
- sdNodeOrKeyName: "rightToLeft",
35096
- encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
35097
- decode: ({ node }) => node.attrs.rightToLeft ? { attributes: {} } : void 0
35098
- });
35099
- const translator$X = NodeTranslator.from({
35100
- xmlName: "w:shd",
35101
- sdNodeOrKeyName: "shading",
35102
- attributes: [
35103
- "w:color",
35104
- "w:fill",
35105
- "w:themeColor",
35106
- "w:themeFill",
35107
- "w:themeFillShade",
35108
- "w:themeFillTint",
35109
- "w:themeShade",
35110
- "w:themeTint",
35111
- "w:val"
35112
- ].map((attr) => createAttributeHandler(attr)),
35113
- encode: (params2, encodedAttrs) => {
35114
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
35115
- },
35116
- decode: function({ node }, context) {
35117
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.shading || {} } });
35118
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
35119
- }
35120
- });
35121
- const translator$W = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblCaption", "caption"));
35122
- const translator$V = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblDescription", "description"));
35123
- const translator$U = NodeTranslator.from(createMeasurementPropertyHandler("w:tblInd", "tableIndent"));
35124
- const translator$T = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblLayout", "tableLayout", "w:type"));
35125
- const translator$S = NodeTranslator.from({
35126
- xmlName: "w:tblLook",
35127
- sdNodeOrKeyName: "tblLook",
35128
- attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
35129
- encode: (params2, encodedAttrs) => {
35130
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
35131
- },
35132
- decode: function({ node }, context) {
35133
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
35134
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
35135
- }
35136
- });
35137
- const translator$R = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblOverlap", "overlap"));
35138
- const translator$Q = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblStyle", "tableStyleId"));
35139
- const translator$P = NodeTranslator.from(
35140
- createSingleAttrPropertyHandler("w:tblStyleColBandSize", "tableStyleColBandSize")
35141
- );
35142
- const translator$O = NodeTranslator.from(
35143
- createSingleAttrPropertyHandler("w:tblStyleRowBandSize", "tableStyleRowBandSize")
35144
- );
35145
- const translator$N = NodeTranslator.from(createMeasurementPropertyHandler("w:tblW", "tableWidth"));
35146
- const translator$M = NodeTranslator.from({
35147
- xmlName: "w:tblpPr",
35148
- sdNodeOrKeyName: "floatingTableProperties",
35149
- 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))),
35150
- encode: (params2, encodedAttrs) => {
35151
- return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
35152
- },
35153
- decode: function({ node }, context) {
35154
- const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
35155
- return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
35156
- }
35157
- });
35158
- const translator$L = NodeTranslator.from(createBorderPropertyHandler("w:bottom"));
35159
- const translator$K = NodeTranslator.from(createMeasurementPropertyHandler("w:bottom", "marginBottom"));
35160
- const translator$J = NodeTranslator.from(createBorderPropertyHandler("w:end"));
35161
- const translator$I = NodeTranslator.from(createMeasurementPropertyHandler("w:end", "marginEnd"));
35162
- const translator$H = NodeTranslator.from(createBorderPropertyHandler("w:insideH"));
35163
- const translator$G = NodeTranslator.from(createBorderPropertyHandler("w:insideV"));
35164
- const translator$F = NodeTranslator.from(createBorderPropertyHandler("w:left"));
35165
- const translator$E = NodeTranslator.from(createMeasurementPropertyHandler("w:left", "marginLeft"));
35166
- const translator$D = NodeTranslator.from(createBorderPropertyHandler("w:right"));
35167
- const translator$C = NodeTranslator.from(createMeasurementPropertyHandler("w:right", "marginRight"));
35168
- const translator$B = NodeTranslator.from(createBorderPropertyHandler("w:start"));
35169
- const translator$A = NodeTranslator.from(createMeasurementPropertyHandler("w:start", "marginStart"));
35170
- const translator$z = NodeTranslator.from(createBorderPropertyHandler("w:top"));
35171
- const translator$y = NodeTranslator.from(createMeasurementPropertyHandler("w:top", "marginTop"));
35172
- const propertyTranslators$5 = [
35173
- translator$L,
35174
- translator$J,
35175
- translator$H,
35176
- translator$G,
35177
- translator$F,
35178
- translator$D,
35179
- translator$B,
35180
- translator$z
35181
- ];
35182
- const translator$x = NodeTranslator.from(
35183
- createNestedPropertiesTranslator("w:tblBorders", "borders", propertyTranslators$5)
35184
- );
34897
+ const translator$J = NodeTranslator.from(config$g);
35185
34898
  const propertyTranslators$4 = [
35186
- translator$K,
35187
- translator$I,
35188
- translator$E,
35189
- translator$C,
35190
- translator$A,
35191
- translator$y
35192
- ];
35193
- const translator$w = NodeTranslator.from(
35194
- createNestedPropertiesTranslator("w:tblCellMar", "cellMargins", propertyTranslators$4)
35195
- );
35196
- const propertyTranslators$3 = [
35197
- translator$Y,
35198
- translator$14,
35199
- translator$X,
35200
- translator$W,
35201
- translator$13,
35202
- translator$V,
35203
- translator$U,
35204
- translator$T,
35205
- translator$S,
34899
+ translator$1a,
34900
+ translator$18,
34901
+ translator$17,
34902
+ translator$16,
35206
34903
  translator$R,
34904
+ translator$19,
35207
34905
  translator$Q,
35208
34906
  translator$P,
35209
34907
  translator$O,
35210
34908
  translator$N,
35211
34909
  translator$M,
35212
- translator$x,
35213
- translator$w
34910
+ translator$L,
34911
+ translator$J
35214
34912
  ];
35215
- const translator$v = NodeTranslator.from(
35216
- createNestedPropertiesTranslator("w:tblPr", "tableProperties", propertyTranslators$3)
34913
+ const translator$I = NodeTranslator.from(
34914
+ createNestedPropertiesTranslator("w:tcPr", "tableCellProperties", propertyTranslators$4)
35217
34915
  );
35218
- const translator$u = NodeTranslator.from(
35219
- createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
35220
- );
35221
- const DEFAULT_COLUMN_WIDTH_PX = 100;
35222
- const normalizeTwipWidth = (value) => {
35223
- if (value == null) return null;
35224
- const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
35225
- if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
35226
- return null;
34916
+ function handleTableCellNode({
34917
+ params: params2,
34918
+ node,
34919
+ table,
34920
+ row,
34921
+ rowBorders,
34922
+ columnIndex,
34923
+ columnWidth = null,
34924
+ allColumnWidths = [],
34925
+ _referencedStyles
34926
+ }) {
34927
+ const { nodeListHandler } = params2;
34928
+ const attributes = {};
34929
+ const referencedStyles = _referencedStyles ?? { fontSize: null, fonts: {}, cellMargins: {} };
34930
+ const tcPr = node.elements.find((el) => el.name === "w:tcPr");
34931
+ const tableCellProperties = tcPr ? translator$I.encode({ ...params2, nodes: [tcPr] }) ?? {} : {};
34932
+ attributes["tableCellProperties"] = tableCellProperties;
34933
+ if (rowBorders?.insideH) {
34934
+ rowBorders["bottom"] = rowBorders.insideH;
34935
+ delete rowBorders.insideH;
35227
34936
  }
35228
- return numericValue;
35229
- };
35230
- const getSchemaDefaultColumnWidthPx = (params2) => {
35231
- const defaultValue = params2?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
35232
- if (Array.isArray(defaultValue)) {
35233
- const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
35234
- if (numericWidth != null) return numericWidth;
35235
- } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
35236
- return defaultValue;
34937
+ if (rowBorders?.insideV) {
34938
+ rowBorders["right"] = rowBorders.insideV;
34939
+ delete rowBorders?.insideV;
35237
34940
  }
35238
- return DEFAULT_COLUMN_WIDTH_PX;
35239
- };
35240
- const getTableWidthPx = (params2) => {
35241
- const explicitWidth = params2?.node?.attrs?.tableWidth?.width;
35242
- if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
35243
- const tableWidth = params2?.node?.attrs?.tableProperties?.tableWidth;
35244
- if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
35245
- const { value, type: type2 } = tableWidth;
35246
- if (!type2 || type2 === "auto" || type2 === "dxa") {
35247
- return twipsToPixels(value);
34941
+ if (rowBorders) attributes["borders"] = { ...rowBorders };
34942
+ const inlineBorders = processInlineCellBorders(tableCellProperties.borders, rowBorders);
34943
+ if (inlineBorders) attributes["borders"] = Object.assign(attributes["borders"] || {}, inlineBorders);
34944
+ const colspan = tableCellProperties.gridSpan;
34945
+ if (colspan && !isNaN(parseInt(colspan, 10))) attributes["colspan"] = parseInt(colspan, 10);
34946
+ let width = tableCellProperties.cellWidth?.value ? twipsToPixels(tableCellProperties.cellWidth?.value) : null;
34947
+ const widthType = tableCellProperties.cellWidth?.type;
34948
+ if (widthType) attributes["widthType"] = widthType;
34949
+ if (!width && columnWidth) width = columnWidth;
34950
+ if (width) {
34951
+ attributes["colwidth"] = [width];
34952
+ attributes["widthUnit"] = "px";
34953
+ const defaultColWidths = allColumnWidths;
34954
+ const hasDefaultColWidths = allColumnWidths && allColumnWidths.length > 0;
34955
+ const colspanNum = parseInt(colspan || 1, 10);
34956
+ if (colspanNum && colspanNum > 1 && hasDefaultColWidths) {
34957
+ let colwidth = [];
34958
+ for (let i2 = 0; i2 < colspanNum; i2++) {
34959
+ let colwidthValue = defaultColWidths[columnIndex + i2];
34960
+ let defaultColwidth = 100;
34961
+ if (typeof colwidthValue !== "undefined") {
34962
+ colwidth.push(colwidthValue);
34963
+ } else {
34964
+ colwidth.push(defaultColwidth);
34965
+ }
34966
+ }
34967
+ if (colwidth.length) {
34968
+ attributes["colwidth"] = [...colwidth];
34969
+ }
35248
34970
  }
35249
34971
  }
35250
- return null;
35251
- };
35252
- const resolveFallbackColumnWidthTwips = (params2, totalColumns, cellMinWidthTwips) => {
35253
- const columnCount = Math.max(totalColumns, 1);
35254
- const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params2);
35255
- const tableWidthPx = getTableWidthPx(params2);
35256
- const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
35257
- let fallbackWidthPx = safeDefaultPx;
35258
- if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
35259
- fallbackWidthPx = tableWidthPx / columnCount;
35260
- }
35261
- const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
35262
- if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
35263
- const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
35264
- return safeDefault;
34972
+ const background = {
34973
+ color: tableCellProperties.shading?.fill
34974
+ };
34975
+ if (background.color) attributes["background"] = background;
34976
+ const verticalAlign = tableCellProperties.vAlign;
34977
+ if (verticalAlign) attributes["verticalAlign"] = verticalAlign;
34978
+ attributes.cellMargins = getTableCellMargins(tableCellProperties.cellMargins, referencedStyles);
34979
+ const { fontSize: fontSize2, fonts = {} } = referencedStyles;
34980
+ const fontFamily2 = fonts["ascii"];
34981
+ if (fontSize2) attributes["fontSize"] = fontSize2;
34982
+ if (fontFamily2) attributes["fontFamily"] = fontFamily2;
34983
+ if (tableCellProperties.vMerge === "restart") {
34984
+ const rows = table.elements.filter((el) => el.name === "w:tr");
34985
+ const currentRowIndex = rows.findIndex((r2) => r2 === row);
34986
+ const remainingRows = rows.slice(currentRowIndex + 1);
34987
+ const cellsInRow = row.elements.filter((el) => el.name === "w:tc");
34988
+ let cellIndex = cellsInRow.findIndex((el) => el === node);
34989
+ let rowspan = 1;
34990
+ for (let remainingRow of remainingRows) {
34991
+ const firstCell = remainingRow.elements.findIndex((el) => el.name === "w:tc");
34992
+ const cellAtIndex = remainingRow.elements[firstCell + cellIndex];
34993
+ if (!cellAtIndex) break;
34994
+ const vMerge = getTableCellVMerge(cellAtIndex);
34995
+ if (!vMerge || vMerge === "restart") {
34996
+ break;
34997
+ }
34998
+ rowspan++;
34999
+ remainingRow.elements.splice(firstCell + cellIndex, 1);
35000
+ }
35001
+ attributes["rowspan"] = rowspan;
35265
35002
  }
35266
- return Math.max(fallbackWidthTwips, cellMinWidthTwips);
35267
- };
35268
- const XML_NODE_NAME$g = "w:tblGrid";
35269
- const SD_ATTR_KEY$3 = "grid";
35270
- const cellMinWidth = pixelsToTwips(10);
35271
- const encode$m = (params2) => {
35272
- const { nodes } = params2;
35273
- const node = nodes[0];
35274
- const attributes = encodeProperties(node, { [translator$u.xmlName]: translator$u }, true);
35275
35003
  return {
35276
- xmlName: XML_NODE_NAME$g,
35277
- sdNodeOrKeyName: SD_ATTR_KEY$3,
35278
- attributes
35004
+ type: "tableCell",
35005
+ content: normalizeTableCellContent(
35006
+ nodeListHandler.handler({
35007
+ ...params2,
35008
+ nodes: node.elements,
35009
+ path: [...params2.path || [], node]
35010
+ }),
35011
+ params2.editor
35012
+ ),
35013
+ attrs: attributes
35279
35014
  };
35280
- };
35281
- const decode$o = (params2) => {
35282
- const { grid: rawGrid } = params2.node.attrs || {};
35283
- const grid = Array.isArray(rawGrid) ? rawGrid : [];
35284
- const { firstRow = {} } = params2.extraParams || {};
35285
- const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
35286
- const columnCountFromCells = cellNodes.reduce((count, cell) => {
35287
- const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
35288
- return count + spanCount;
35289
- }, 0);
35290
- const totalColumns = Math.max(columnCountFromCells, grid.length);
35291
- const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params2, totalColumns, cellMinWidth);
35292
- const elements = [];
35293
- let columnIndex = 0;
35294
- const pushColumn = (widthTwips, { enforceMinimum = false } = {}) => {
35295
- let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
35296
- let shouldEnforceMinimum = enforceMinimum;
35297
- if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
35298
- numericWidth = fallbackColumnWidthTwips;
35299
- shouldEnforceMinimum = true;
35015
+ }
35016
+ function normalizeTableCellContent(content, editor) {
35017
+ if (!Array.isArray(content) || content.length === 0) return content;
35018
+ const normalized = [];
35019
+ const pendingForNextBlock = [];
35020
+ const schema = editor?.schema;
35021
+ const cloneBlock = (node) => {
35022
+ if (!node) return node;
35023
+ const cloned = { ...node };
35024
+ if (Array.isArray(node.content)) {
35025
+ cloned.content = [...node.content];
35300
35026
  }
35301
- const roundedWidth = Math.round(numericWidth);
35302
- const minimumWidth = shouldEnforceMinimum ? cellMinWidth : 1;
35303
- const safeWidth = Math.max(roundedWidth, minimumWidth);
35304
- const decoded = translator$u.decode({
35305
- node: { type: (
35306
- /** @type {string} */
35307
- translator$u.sdNodeOrKeyName
35308
- ), attrs: { col: safeWidth } }
35309
- });
35310
- if (decoded) elements.push(decoded);
35027
+ return cloned;
35311
35028
  };
35312
- cellNodes.forEach((cell) => {
35313
- const { colspan = 1, colwidth } = cell?.attrs || {};
35314
- const spanCount = Math.max(1, colspan);
35315
- for (let span = 0; span < spanCount; span++) {
35316
- const rawWidth = Array.isArray(colwidth) ? colwidth[span] : void 0;
35317
- const cellWidthPixels = typeof rawWidth === "number" && Number.isFinite(rawWidth) ? rawWidth : Number(rawWidth);
35318
- const hasCellWidth = Number.isFinite(cellWidthPixels) && cellWidthPixels > 0;
35319
- const colGridAttrs = grid?.[columnIndex] || {};
35320
- const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
35321
- const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
35322
- let cellWidthTwips;
35323
- let enforceMinimum = false;
35324
- if (hasCellWidth) {
35325
- const tolerance = 0.5;
35326
- if (gridWidthTwips != null && gridWidthPixels != null && Math.abs(gridWidthPixels - cellWidthPixels) <= tolerance) {
35327
- cellWidthTwips = gridWidthTwips;
35328
- } else {
35329
- cellWidthTwips = pixelsToTwips(cellWidthPixels);
35330
- }
35331
- } else if (gridWidthTwips != null) {
35332
- cellWidthTwips = gridWidthTwips;
35333
- } else {
35334
- cellWidthTwips = fallbackColumnWidthTwips;
35335
- enforceMinimum = true;
35336
- }
35337
- pushColumn(cellWidthTwips, { enforceMinimum });
35338
- columnIndex++;
35029
+ const ensureArray = (node) => {
35030
+ if (!Array.isArray(node.content)) {
35031
+ node.content = [];
35339
35032
  }
35340
- });
35341
- while (columnIndex < grid.length) {
35342
- const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
35343
- pushColumn(gridWidthTwips);
35344
- columnIndex++;
35345
- }
35346
- const newNode = {
35347
- name: XML_NODE_NAME$g,
35348
- attributes: {},
35349
- elements
35033
+ return node.content;
35350
35034
  };
35351
- return newNode;
35352
- };
35353
- const config$f = {
35354
- xmlName: XML_NODE_NAME$g,
35355
- sdNodeOrKeyName: SD_ATTR_KEY$3,
35356
- encode: encode$m,
35357
- decode: decode$o
35358
- };
35359
- const translator$t = NodeTranslator.from(config$f);
35360
- const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
35361
- const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
35362
- const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
35363
- const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
35364
- const pctToPercent = (value) => {
35365
- if (value == null) return null;
35366
- return value / 50;
35367
- };
35368
- const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
35369
- const resolveMeasurementWidthPx = (measurement) => {
35370
- if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
35371
- const { value, type: type2 } = measurement;
35372
- if (!type2 || type2 === "auto") return null;
35373
- if (type2 === "dxa") return twipsToPixels(value);
35374
- if (type2 === "pct") {
35375
- const percent2 = pctToPercent(value);
35376
- if (percent2 == null || percent2 <= 0) return null;
35377
- const widthTwips = resolveContentWidthTwips() * percent2 / 100;
35378
- return twipsToPixels(widthTwips);
35379
- }
35380
- return null;
35381
- };
35382
- const countColumnsInRow = (row) => {
35383
- if (!row?.elements?.length) return 0;
35384
- return row.elements.reduce((count, element) => {
35385
- if (element.name !== "w:tc") return count;
35386
- const tcPr = element.elements?.find((el) => el.name === "w:tcPr");
35387
- const gridSpan = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
35388
- const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
35389
- return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
35390
- }, 0);
35391
- };
35392
- const clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
35393
- const createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
35394
- const buildFallbackGridForTable = ({ params: params2, rows, tableWidth, tableWidthMeasurement }) => {
35395
- const firstRow = rows.find((row) => row.elements?.some((el) => el.name === "w:tc"));
35396
- const columnCount = countColumnsInRow(firstRow);
35397
- if (!columnCount) return null;
35398
- const schemaDefaultPx = getSchemaDefaultColumnWidthPx(
35399
- /** @type {any} */
35400
- params2
35401
- );
35402
- const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : DEFAULT_COLUMN_WIDTH_PX;
35403
- let totalWidthPx;
35404
- if (tableWidthMeasurement) {
35405
- const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
35406
- if (resolved != null) totalWidthPx = resolved;
35407
- }
35408
- if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) {
35409
- totalWidthPx = tableWidth.width;
35410
- }
35411
- if (totalWidthPx == null) {
35412
- totalWidthPx = minimumColumnWidthPx * columnCount;
35413
- }
35414
- const rawColumnWidthPx = Math.max(totalWidthPx / columnCount, minimumColumnWidthPx);
35415
- const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(rawColumnWidthPx));
35416
- const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
35417
- return {
35418
- grid: createFallbackGrid(columnCount, columnWidthTwips),
35419
- columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
35035
+ const isInlineNode = (node) => {
35036
+ if (!node || typeof node.type !== "string") return false;
35037
+ if (node.type === "text") return true;
35038
+ if (node.type === "bookmarkStart" || node.type === "bookmarkEnd") return true;
35039
+ const nodeType = schema?.nodes?.[node.type];
35040
+ if (nodeType) {
35041
+ if (typeof nodeType.isInline === "boolean") return nodeType.isInline;
35042
+ if (nodeType.spec?.group && typeof nodeType.spec.group === "string") {
35043
+ return nodeType.spec.group.split(" ").includes("inline");
35044
+ }
35045
+ }
35046
+ return false;
35420
35047
  };
35421
- };
35422
- const XML_NODE_NAME$f = "w:tbl";
35423
- const SD_NODE_NAME$c = "table";
35424
- const encode$l = (params2, encodedAttrs) => {
35425
- const { nodes } = params2;
35426
- const node = nodes[0];
35427
- const tblPr = node.elements.find((el) => el.name === "w:tblPr");
35428
- if (tblPr) {
35429
- const encodedProperties = translator$v.encode({ ...params2, nodes: [tblPr] });
35430
- encodedAttrs["tableProperties"] = encodedProperties || {};
35431
- }
35432
- const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
35433
- if (tblGrid) {
35434
- encodedAttrs["grid"] = translator$t.encode({ ...params2, nodes: [tblGrid] }).attributes;
35435
- }
35436
- [
35437
- "tableStyleId",
35438
- "justification",
35439
- "tableLayout",
35440
- ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
35441
- ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
35442
- ].forEach((prop) => {
35443
- let key2;
35444
- let transform;
35445
- if (Array.isArray(prop)) {
35446
- [key2, transform] = prop;
35447
- } else {
35448
- key2 = prop;
35449
- transform = (v2) => v2;
35048
+ for (const node of content) {
35049
+ if (!node || typeof node.type !== "string") {
35050
+ normalized.push(node);
35051
+ continue;
35450
35052
  }
35451
- if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key2]) {
35452
- encodedAttrs[key2] = transform(encodedAttrs.tableProperties[key2]);
35053
+ if (!isInlineNode(node)) {
35054
+ const blockNode = cloneBlock(node);
35055
+ if (pendingForNextBlock.length) {
35056
+ const blockContent = ensureArray(blockNode);
35057
+ const leadingInline = pendingForNextBlock.splice(0);
35058
+ blockNode.content = [...leadingInline, ...blockContent];
35059
+ } else if (Array.isArray(blockNode.content)) {
35060
+ blockNode.content = [...blockNode.content];
35061
+ }
35062
+ normalized.push(blockNode);
35063
+ continue;
35453
35064
  }
35454
- });
35455
- if (encodedAttrs.tableCellSpacing) {
35456
- encodedAttrs["borderCollapse"] = "separate";
35457
- }
35458
- if (encodedAttrs.tableProperties?.tableWidth) {
35459
- const tableWidthMeasurement = encodedAttrs.tableProperties.tableWidth;
35460
- const widthPx = twipsToPixels(tableWidthMeasurement.value);
35461
- if (widthPx != null) {
35462
- encodedAttrs.tableWidth = {
35463
- width: widthPx,
35464
- type: tableWidthMeasurement.type
35465
- };
35466
- } else if (tableWidthMeasurement.type === "auto") {
35467
- encodedAttrs.tableWidth = {
35468
- width: 0,
35469
- type: tableWidthMeasurement.type
35470
- };
35065
+ const targetIsNextBlock = node.type === "bookmarkStart" || normalized.length === 0;
35066
+ if (targetIsNextBlock) {
35067
+ pendingForNextBlock.push(node);
35068
+ } else {
35069
+ const lastIndex = normalized.length - 1;
35070
+ const lastNode = normalized[lastIndex];
35071
+ if (!lastNode || typeof lastNode.type !== "string" || isInlineNode(lastNode)) {
35072
+ pendingForNextBlock.push(node);
35073
+ continue;
35074
+ }
35075
+ const blockContent = ensureArray(lastNode);
35076
+ if (pendingForNextBlock.length) {
35077
+ blockContent.push(...pendingForNextBlock.splice(0));
35078
+ }
35079
+ blockContent.push(node);
35471
35080
  }
35472
35081
  }
35473
- const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
35474
- const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params2);
35475
- if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
35476
- encodedAttrs.tableProperties = {
35477
- ...encodedAttrs.tableProperties || {},
35478
- cellMargins: referencedStyles.cellMargins
35479
- };
35480
- }
35481
- const rows = node.elements.filter((el) => el.name === "w:tr");
35482
- const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
35483
- const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
35484
- encodedAttrs["borders"] = borderData;
35485
- const tblStyleTag = tblPr?.elements?.find((el) => el.name === "w:tblStyle");
35486
- let columnWidths = Array.isArray(encodedAttrs["grid"]) ? encodedAttrs["grid"].map((item) => twipsToPixels(item.col)) : [];
35487
- if (!columnWidths.length) {
35488
- const fallback = buildFallbackGridForTable({
35489
- params: params2,
35490
- rows,
35491
- tableWidth: encodedAttrs.tableWidth,
35492
- tableWidthMeasurement: encodedAttrs.tableProperties?.tableWidth
35493
- });
35494
- if (fallback) {
35495
- encodedAttrs.grid = fallback.grid;
35496
- columnWidths = fallback.columnWidths;
35082
+ if (pendingForNextBlock.length) {
35083
+ if (normalized.length) {
35084
+ const lastIndex = normalized.length - 1;
35085
+ const lastNode = normalized[lastIndex];
35086
+ if (lastNode && typeof lastNode.type === "string" && !isInlineNode(lastNode)) {
35087
+ const blockContent = ensureArray(lastNode);
35088
+ blockContent.push(...pendingForNextBlock);
35089
+ pendingForNextBlock.length = 0;
35090
+ }
35091
+ }
35092
+ if (pendingForNextBlock.length) {
35093
+ normalized.push({
35094
+ type: "paragraph",
35095
+ attrs: {},
35096
+ content: [...pendingForNextBlock]
35097
+ });
35098
+ pendingForNextBlock.length = 0;
35497
35099
  }
35498
35100
  }
35499
- const content = [];
35500
- const totalColumns = columnWidths.length;
35501
- const activeRowSpans = totalColumns > 0 ? new Array(totalColumns).fill(0) : [];
35502
- rows.forEach((row, rowIndex) => {
35503
- const result = translator$Z.encode({
35504
- ...params2,
35505
- nodes: [row],
35506
- extraParams: {
35507
- row,
35508
- table: node,
35509
- rowBorders: borderRowData,
35510
- styleTag: tblStyleTag,
35511
- columnWidths,
35512
- activeRowSpans: activeRowSpans.slice(),
35513
- rowIndex
35514
- }
35515
- });
35516
- if (result) {
35517
- content.push(result);
35518
- if (totalColumns > 0) {
35519
- const activeRowSpansForCurrentRow = activeRowSpans.slice();
35520
- for (let col = 0; col < totalColumns; col++) {
35521
- if (activeRowSpans[col] > 0) {
35522
- activeRowSpans[col] -= 1;
35523
- }
35524
- }
35525
- let columnIndex = 0;
35526
- const advanceColumnIndex = () => {
35527
- while (columnIndex < totalColumns && activeRowSpansForCurrentRow[columnIndex] > 0) {
35528
- columnIndex += 1;
35529
- }
35530
- };
35531
- advanceColumnIndex();
35532
- result.content?.forEach((cell) => {
35533
- advanceColumnIndex();
35534
- const colspan = Math.max(1, cell.attrs?.colspan || 1);
35535
- const rowspan = Math.max(1, cell.attrs?.rowspan || 1);
35536
- if (rowspan > 1) {
35537
- for (let offset2 = 0; offset2 < colspan && columnIndex + offset2 < totalColumns; offset2++) {
35538
- const targetIndex = columnIndex + offset2;
35539
- const remainingRows = rowspan - 1;
35540
- if (remainingRows > 0 && remainingRows > activeRowSpans[targetIndex]) {
35541
- activeRowSpans[targetIndex] = remainingRows;
35542
- }
35543
- }
35544
- }
35545
- columnIndex += colspan;
35546
- advanceColumnIndex();
35547
- });
35101
+ return normalized;
35102
+ }
35103
+ const processInlineCellBorders = (borders, rowBorders) => {
35104
+ if (!borders) return null;
35105
+ return ["bottom", "top", "left", "right"].reduce((acc, direction) => {
35106
+ const borderAttrs = borders[direction];
35107
+ const rowBorderAttrs = rowBorders[direction];
35108
+ if (borderAttrs && borderAttrs["val"] !== "nil") {
35109
+ const color = borderAttrs["color"];
35110
+ let size2 = borderAttrs["size"];
35111
+ if (size2) size2 = eighthPointsToPixels(size2);
35112
+ acc[direction] = { color, size: size2, val: borderAttrs["val"] };
35113
+ return acc;
35114
+ }
35115
+ if (borderAttrs && borderAttrs["val"] === "nil") {
35116
+ const border = Object.assign({}, rowBorderAttrs || {});
35117
+ if (!Object.keys(border).length) {
35118
+ return acc;
35119
+ } else {
35120
+ border["val"] = "none";
35121
+ acc[direction] = border;
35122
+ return acc;
35548
35123
  }
35549
35124
  }
35550
- });
35551
- return {
35552
- type: "table",
35553
- content,
35554
- attrs: encodedAttrs
35555
- };
35125
+ return acc;
35126
+ }, {});
35556
35127
  };
35557
- const decode$n = (params2, decodedAttrs) => {
35558
- params2.node = preProcessVerticalMergeCells(params2.node, params2);
35559
- const { node } = params2;
35560
- const elements = translateChildNodes(params2);
35561
- const firstRow = node.content?.find((n) => n.type === "tableRow");
35562
- const properties = node.attrs.grid;
35563
- const element = translator$t.decode({
35564
- ...params2,
35565
- node: { ...node, attrs: { ...node.attrs, grid: properties } },
35566
- extraParams: {
35567
- firstRow
35128
+ const getTableCellVMerge = (node) => {
35129
+ const tcPr = node.elements.find((el) => el.name === "w:tcPr");
35130
+ const vMerge = tcPr?.elements?.find((el) => el.name === "w:vMerge");
35131
+ if (!vMerge) return null;
35132
+ return vMerge.attributes?.["w:val"] || "continue";
35133
+ };
35134
+ const getTableCellMargins = (inlineMargins, referencedStyles) => {
35135
+ const { cellMargins = {} } = referencedStyles;
35136
+ return ["left", "right", "top", "bottom"].reduce((acc, direction) => {
35137
+ const key2 = `margin${direction.charAt(0).toUpperCase() + direction.slice(1)}`;
35138
+ const inlineValue = inlineMargins ? inlineMargins?.[key2]?.value : null;
35139
+ const styleValue = cellMargins ? cellMargins[key2] : null;
35140
+ if (inlineValue != null) {
35141
+ acc[direction] = twipsToPixels(inlineValue);
35142
+ } else if (styleValue == null) {
35143
+ acc[direction] = void 0;
35144
+ } else if (typeof styleValue === "object") {
35145
+ acc[direction] = twipsToPixels(styleValue.value);
35146
+ } else {
35147
+ acc[direction] = twipsToPixels(styleValue);
35568
35148
  }
35569
- });
35570
- if (element) elements.unshift(element);
35571
- if (node.attrs?.tableProperties) {
35572
- const properties2 = { ...node.attrs.tableProperties };
35573
- const element2 = translator$v.decode({
35574
- ...params2,
35575
- node: { ...node, attrs: { ...node.attrs, tableProperties: properties2 } }
35576
- });
35577
- if (element2) elements.unshift(element2);
35578
- }
35579
- return {
35580
- name: "w:tbl",
35581
- attributes: decodedAttrs || {},
35582
- elements
35583
- };
35149
+ return acc;
35150
+ }, {});
35584
35151
  };
35585
- function _processTableBorders(rawBorders) {
35586
- const borders = {};
35587
- const rowBorders = {};
35588
- Object.entries(rawBorders).forEach(([name, attributes]) => {
35589
- const attrs = {};
35590
- const color = attributes.color;
35591
- const size2 = attributes.size;
35592
- if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
35593
- if (size2 && size2 !== "auto") attrs["size"] = eighthPointsToPixels(size2);
35594
- const rowBorderNames = ["insideH", "insideV"];
35595
- if (rowBorderNames.includes(name)) rowBorders[name] = attrs;
35596
- borders[name] = attrs;
35152
+ function translateTableCell(params2) {
35153
+ const elements = translateChildNodes({
35154
+ ...params2,
35155
+ tableCell: params2.node
35597
35156
  });
35157
+ const cellProps = generateTableCellProperties(params2.node);
35158
+ elements.unshift(cellProps);
35598
35159
  return {
35599
- borders,
35600
- rowBorders
35160
+ name: "w:tc",
35161
+ elements
35601
35162
  };
35602
35163
  }
35603
- function _getReferencedTableStyles(tableStyleReference, params2) {
35604
- if (!tableStyleReference) return null;
35605
- const stylesToReturn = {};
35606
- const { docx } = params2;
35607
- const styles = docx["word/styles.xml"];
35608
- const { elements } = styles.elements[0];
35609
- const styleElements = elements.filter((el) => el.name === "w:style");
35610
- const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
35611
- if (!styleTag) return null;
35612
- stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
35613
- const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
35614
- let baseTblPr;
35615
- if (basedOn?.attributes) {
35616
- const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
35617
- baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
35164
+ function generateTableCellProperties(node) {
35165
+ const tableCellProperties = { ...node.attrs?.tableCellProperties || {} };
35166
+ const { attrs } = node;
35167
+ const { colwidth = [], cellWidthType = "dxa", widthUnit } = attrs;
35168
+ const colwidthSum = colwidth.reduce((acc, curr) => acc + curr, 0);
35169
+ const propertiesWidthPixels = twipsToPixels(tableCellProperties.cellWidth?.value);
35170
+ if (propertiesWidthPixels !== colwidthSum) {
35171
+ tableCellProperties["cellWidth"] = {
35172
+ value: widthUnit === "px" ? pixelsToTwips(colwidthSum) : inchesToTwips(colwidthSum),
35173
+ type: cellWidthType
35174
+ };
35618
35175
  }
35619
- const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
35620
- if (pPr) {
35621
- const justification = pPr.elements.find((el) => el.name === "w:jc");
35622
- if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
35623
- }
35624
- const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
35625
- if (rPr) {
35626
- const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
35627
- if (fonts) {
35628
- const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
35629
- stylesToReturn.fonts = { ascii, hAnsi, cs };
35630
- }
35631
- const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
35632
- if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
35633
- }
35634
- const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
35635
- if (tblPr && tblPr.elements) {
35636
- if (baseTblPr && baseTblPr.elements) {
35637
- tblPr.elements.push(...baseTblPr.elements);
35638
- }
35639
- const tableProperties = translator$v.encode({ ...params2, nodes: [tblPr] });
35640
- const { borders, rowBorders } = _processTableBorders(tableProperties.borders || {});
35641
- if (borders) stylesToReturn.borders = borders;
35642
- if (rowBorders) stylesToReturn.rowBorders = rowBorders;
35643
- const cellMargins = {};
35644
- Object.entries(tableProperties.cellMargins || {}).forEach(([key2, attrs]) => {
35645
- if (attrs?.value != null) {
35646
- cellMargins[key2] = {
35647
- value: attrs.value,
35648
- type: attrs.type || "dxa"
35649
- };
35650
- }
35651
- });
35652
- if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
35653
- }
35654
- return stylesToReturn;
35655
- }
35656
- const config$e = {
35657
- xmlName: XML_NODE_NAME$f,
35658
- sdNodeOrKeyName: SD_NODE_NAME$c,
35659
- type: NodeTranslator.translatorTypes.NODE,
35660
- encode: encode$l,
35661
- decode: decode$n,
35662
- attributes: []
35663
- };
35664
- const translator$s = NodeTranslator.from(config$e);
35665
- const tableNodeHandlerEntity = generateV2HandlerEntity("tableNodeHandler", translator$s);
35666
- function getReferencedTableStyles(tblStyleTag, docx) {
35667
- if (!tblStyleTag) return null;
35668
- const stylesToReturn = {};
35669
- const { attributes = {} } = tblStyleTag;
35670
- const tableStyleReference = attributes["w:val"];
35671
- if (!tableStyleReference) return null;
35672
- const styles = docx["word/styles.xml"];
35673
- const { elements } = styles.elements[0];
35674
- const styleElements = elements.filter((el) => el.name === "w:style");
35675
- const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
35676
- if (!styleTag) return null;
35677
- stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
35678
- const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
35679
- let baseTblPr;
35680
- if (basedOn?.attributes) {
35681
- const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
35682
- baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
35683
- }
35684
- const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
35685
- if (pPr) {
35686
- const justification = pPr.elements.find((el) => el.name === "w:jc");
35687
- if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
35688
- }
35689
- const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
35690
- if (rPr) {
35691
- const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
35692
- if (fonts) {
35693
- const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
35694
- stylesToReturn.fonts = { ascii, hAnsi, cs };
35695
- }
35696
- const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
35697
- if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
35698
- }
35699
- const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
35700
- if (tblPr && tblPr.elements) {
35701
- if (baseTblPr && baseTblPr.elements) {
35702
- tblPr.elements.push(...baseTblPr.elements);
35703
- }
35704
- const tableBorders = tblPr?.elements?.find((el) => el.name === "w:tblBorders");
35705
- const { elements: borderElements = [] } = tableBorders || {};
35706
- const { borders, rowBorders } = processTableBorders(borderElements);
35707
- if (borders) stylesToReturn.borders = borders;
35708
- if (rowBorders) stylesToReturn.rowBorders = rowBorders;
35709
- const tableCellMargin = tblPr?.elements.find((el) => el.name === "w:tblCellMar");
35710
- if (tableCellMargin) {
35711
- const marginLeft = tableCellMargin.elements.find((el) => el.name === "w:left");
35712
- const marginRight = tableCellMargin.elements.find((el) => el.name === "w:right");
35713
- const marginTop = tableCellMargin.elements.find((el) => el.name === "w:top");
35714
- const marginBottom = tableCellMargin.elements.find((el) => el.name === "w:bottom");
35715
- stylesToReturn.cellMargins = {
35716
- marginLeft: marginLeft?.attributes["w:w"],
35717
- marginRight: marginRight?.attributes["w:w"],
35718
- marginTop: marginTop?.attributes["w:w"],
35719
- marginBottom: marginBottom?.attributes["w:w"]
35720
- };
35721
- }
35722
- }
35723
- return stylesToReturn;
35724
- }
35725
- function processTableBorders(borderElements) {
35726
- const borders = {};
35727
- const rowBorders = {};
35728
- borderElements.forEach((borderElement) => {
35729
- const { name } = borderElement;
35730
- const borderName = name.split("w:")[1];
35731
- const { attributes } = borderElement;
35732
- const attrs = {};
35733
- const color = attributes["w:color"];
35734
- const size2 = attributes["w:sz"];
35735
- if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
35736
- if (size2 && size2 !== "auto") attrs["size"] = eighthPointsToPixels(size2);
35737
- const rowBorderNames = ["insideH", "insideV"];
35738
- if (rowBorderNames.includes(borderName)) rowBorders[borderName] = attrs;
35739
- borders[borderName] = attrs;
35740
- });
35741
- return {
35742
- borders,
35743
- rowBorders
35744
- };
35745
- }
35746
- const translator$r = NodeTranslator.from(createMeasurementPropertyHandler("w:tcW", "cellWidth"));
35747
- const translator$q = NodeTranslator.from(
35748
- createSingleAttrPropertyHandler(
35749
- "w:gridSpan",
35750
- null,
35751
- "w:val",
35752
- (v2) => parseInteger(v2) ?? void 0,
35753
- (v2) => integerToString(v2)
35754
- )
35755
- );
35756
- const translator$p = NodeTranslator.from(createSingleAttrPropertyHandler("w:vMerge"));
35757
- const translator$o = NodeTranslator.from(createBorderPropertyHandler("w:tl2br"));
35758
- const translator$n = NodeTranslator.from(createBorderPropertyHandler("w:tr2bl"));
35759
- const propertyTranslators$2 = [
35760
- translator$z,
35761
- translator$B,
35762
- translator$F,
35763
- translator$L,
35764
- translator$J,
35765
- translator$D,
35766
- translator$H,
35767
- translator$G,
35768
- translator$o,
35769
- translator$n
35770
- ];
35771
- const translator$m = NodeTranslator.from(
35772
- createNestedPropertiesTranslator("w:tcBorders", "borders", propertyTranslators$2)
35773
- );
35774
- const translator$l = NodeTranslator.from(
35775
- createSingleAttrPropertyHandler(
35776
- "w:noWrap",
35777
- null,
35778
- "w:val",
35779
- (v2) => parseBoolean(v2 ?? "true"),
35780
- (v2) => booleanToString(v2)
35781
- )
35782
- );
35783
- const propertyTranslators$1 = [
35784
- translator$K,
35785
- translator$I,
35786
- translator$E,
35787
- translator$C,
35788
- translator$A,
35789
- translator$y
35790
- ];
35791
- const translator$k = NodeTranslator.from(
35792
- createNestedPropertiesTranslator("w:tcMar", "cellMargins", propertyTranslators$1)
35793
- );
35794
- const translator$j = NodeTranslator.from(createSingleAttrPropertyHandler("w:textDirection"));
35795
- const translator$i = NodeTranslator.from(
35796
- createSingleAttrPropertyHandler(
35797
- "w:tcFitText",
35798
- null,
35799
- "w:val",
35800
- (v2) => parseBoolean(v2 ?? "true"),
35801
- (v2) => booleanToString(v2)
35802
- )
35803
- );
35804
- const translator$h = NodeTranslator.from(createSingleAttrPropertyHandler("w:vAlign"));
35805
- const translator$g = NodeTranslator.from(
35806
- createSingleAttrPropertyHandler(
35807
- "w:hideMark",
35808
- null,
35809
- "w:val",
35810
- (v2) => parseBoolean(v2 ?? "true"),
35811
- (v2) => booleanToString(v2)
35812
- )
35813
- );
35814
- const translator$f = NodeTranslator.from(createSingleAttrPropertyHandler("w:header"));
35815
- const XML_NODE_NAME$e = "w:headers";
35816
- const SD_ATTR_KEY$2 = "headers";
35817
- const encode$k = (params2) => {
35818
- const { nodes } = params2;
35819
- const node = nodes[0];
35820
- const attributes = encodeProperties(node, { [translator$f.xmlName]: translator$f }, true);
35821
- return {
35822
- xmlName: XML_NODE_NAME$e,
35823
- sdNodeOrKeyName: SD_ATTR_KEY$2,
35824
- attributes
35825
- };
35826
- };
35827
- const decode$m = (params2) => {
35828
- const { headers = [] } = params2.node.attrs || {};
35829
- const newNode = {
35830
- name: XML_NODE_NAME$e,
35831
- attributes: {},
35832
- elements: headers.map(
35833
- (header) => translator$f.decode({
35834
- node: { type: "header", attrs: header }
35835
- })
35836
- )
35837
- };
35838
- return newNode;
35839
- };
35840
- const config$d = {
35841
- xmlName: XML_NODE_NAME$e,
35842
- sdNodeOrKeyName: SD_ATTR_KEY$2,
35843
- encode: encode$k,
35844
- decode: decode$m
35845
- };
35846
- const translator$e = NodeTranslator.from(config$d);
35847
- const propertyTranslators = [
35848
- translator$19,
35849
- translator$r,
35850
- translator$q,
35851
- translator$p,
35852
- translator$m,
35853
- translator$X,
35854
- translator$l,
35855
- translator$k,
35856
- translator$j,
35857
- translator$i,
35858
- translator$h,
35859
- translator$g,
35860
- translator$e
35861
- ];
35862
- const translator$d = NodeTranslator.from(
35863
- createNestedPropertiesTranslator("w:tcPr", "tableCellProperties", propertyTranslators)
35864
- );
35865
- function handleTableCellNode({
35866
- params: params2,
35867
- node,
35868
- table,
35869
- row,
35870
- rowBorders,
35871
- styleTag,
35872
- columnIndex,
35873
- columnWidth = null,
35874
- allColumnWidths = []
35875
- }) {
35876
- const { docx, nodeListHandler } = params2;
35877
- const attributes = {};
35878
- const tcPr = node.elements.find((el) => el.name === "w:tcPr");
35879
- const tableCellProperties = tcPr ? translator$d.encode({ ...params2, nodes: [tcPr] }) ?? {} : {};
35880
- attributes["tableCellProperties"] = tableCellProperties;
35881
- if (rowBorders?.insideH) {
35882
- rowBorders["bottom"] = rowBorders.insideH;
35883
- delete rowBorders.insideH;
35884
- }
35885
- if (rowBorders?.insideV) {
35886
- rowBorders["right"] = rowBorders.insideV;
35887
- delete rowBorders?.insideV;
35888
- }
35889
- if (rowBorders) attributes["borders"] = { ...rowBorders };
35890
- const inlineBorders = processInlineCellBorders(tableCellProperties.borders, rowBorders);
35891
- if (inlineBorders) attributes["borders"] = Object.assign(attributes["borders"] || {}, inlineBorders);
35892
- const colspan = tableCellProperties.gridSpan;
35893
- if (colspan && !isNaN(parseInt(colspan, 10))) attributes["colspan"] = parseInt(colspan, 10);
35894
- let width = tableCellProperties.cellWidth?.value ? twipsToPixels(tableCellProperties.cellWidth?.value) : null;
35895
- const widthType = tableCellProperties.cellWidth?.type;
35896
- if (widthType) attributes["widthType"] = widthType;
35897
- if (!width && columnWidth) width = columnWidth;
35898
- if (width) {
35899
- attributes["colwidth"] = [width];
35900
- attributes["widthUnit"] = "px";
35901
- const defaultColWidths = allColumnWidths;
35902
- const hasDefaultColWidths = allColumnWidths && allColumnWidths.length > 0;
35903
- const colspanNum = parseInt(colspan || 1, 10);
35904
- if (colspanNum && colspanNum > 1 && hasDefaultColWidths) {
35905
- let colwidth = [];
35906
- for (let i2 = 0; i2 < colspanNum; i2++) {
35907
- let colwidthValue = defaultColWidths[columnIndex + i2];
35908
- let defaultColwidth = 100;
35909
- if (typeof colwidthValue !== "undefined") {
35910
- colwidth.push(colwidthValue);
35911
- } else {
35912
- colwidth.push(defaultColwidth);
35913
- }
35914
- }
35915
- if (colwidth.length) {
35916
- attributes["colwidth"] = [...colwidth];
35917
- }
35918
- }
35919
- }
35920
- const background = {
35921
- color: tableCellProperties.shading?.fill
35922
- };
35923
- if (background.color) attributes["background"] = background;
35924
- const verticalAlign = tableCellProperties.vAlign;
35925
- if (verticalAlign) attributes["verticalAlign"] = verticalAlign;
35926
- const referencedStyles = getReferencedTableStyles(styleTag, docx) || { fontSize: null, fonts: {}, cellMargins: {} };
35927
- attributes.cellMargins = getTableCellMargins(tableCellProperties.cellMargins, referencedStyles);
35928
- const { fontSize: fontSize2, fonts = {} } = referencedStyles;
35929
- const fontFamily2 = fonts["ascii"];
35930
- if (fontSize2) attributes["fontSize"] = fontSize2;
35931
- if (fontFamily2) attributes["fontFamily"] = fontFamily2;
35932
- if (tableCellProperties.vMerge === "restart") {
35933
- const rows = table.elements.filter((el) => el.name === "w:tr");
35934
- const currentRowIndex = rows.findIndex((r2) => r2 === row);
35935
- const remainingRows = rows.slice(currentRowIndex + 1);
35936
- const cellsInRow = row.elements.filter((el) => el.name === "w:tc");
35937
- let cellIndex = cellsInRow.findIndex((el) => el === node);
35938
- let rowspan = 1;
35939
- for (let remainingRow of remainingRows) {
35940
- const firstCell = remainingRow.elements.findIndex((el) => el.name === "w:tc");
35941
- const cellAtIndex = remainingRow.elements[firstCell + cellIndex];
35942
- if (!cellAtIndex) break;
35943
- const vMerge = getTableCellVMerge(cellAtIndex);
35944
- if (!vMerge || vMerge === "restart") {
35945
- break;
35946
- }
35947
- rowspan++;
35948
- remainingRow.elements.splice(firstCell + cellIndex, 1);
35949
- }
35950
- attributes["rowspan"] = rowspan;
35951
- }
35952
- return {
35953
- type: "tableCell",
35954
- content: normalizeTableCellContent(
35955
- nodeListHandler.handler({
35956
- ...params2,
35957
- nodes: node.elements,
35958
- path: [...params2.path || [], node]
35959
- }),
35960
- params2.editor
35961
- ),
35962
- attrs: attributes
35963
- };
35964
- }
35965
- function normalizeTableCellContent(content, editor) {
35966
- if (!Array.isArray(content) || content.length === 0) return content;
35967
- const normalized = [];
35968
- const pendingForNextBlock = [];
35969
- const schema = editor?.schema;
35970
- const cloneBlock = (node) => {
35971
- if (!node) return node;
35972
- const cloned = { ...node };
35973
- if (Array.isArray(node.content)) {
35974
- cloned.content = [...node.content];
35975
- }
35976
- return cloned;
35977
- };
35978
- const ensureArray = (node) => {
35979
- if (!Array.isArray(node.content)) {
35980
- node.content = [];
35981
- }
35982
- return node.content;
35983
- };
35984
- const isInlineNode = (node) => {
35985
- if (!node || typeof node.type !== "string") return false;
35986
- if (node.type === "text") return true;
35987
- if (node.type === "bookmarkStart" || node.type === "bookmarkEnd") return true;
35988
- const nodeType = schema?.nodes?.[node.type];
35989
- if (nodeType) {
35990
- if (typeof nodeType.isInline === "boolean") return nodeType.isInline;
35991
- if (nodeType.spec?.group && typeof nodeType.spec.group === "string") {
35992
- return nodeType.spec.group.split(" ").includes("inline");
35993
- }
35994
- }
35995
- return false;
35996
- };
35997
- for (const node of content) {
35998
- if (!node || typeof node.type !== "string") {
35999
- normalized.push(node);
36000
- continue;
36001
- }
36002
- if (!isInlineNode(node)) {
36003
- const blockNode = cloneBlock(node);
36004
- if (pendingForNextBlock.length) {
36005
- const blockContent = ensureArray(blockNode);
36006
- const leadingInline = pendingForNextBlock.splice(0);
36007
- blockNode.content = [...leadingInline, ...blockContent];
36008
- } else if (Array.isArray(blockNode.content)) {
36009
- blockNode.content = [...blockNode.content];
36010
- }
36011
- normalized.push(blockNode);
36012
- continue;
36013
- }
36014
- const targetIsNextBlock = node.type === "bookmarkStart" || normalized.length === 0;
36015
- if (targetIsNextBlock) {
36016
- pendingForNextBlock.push(node);
36017
- } else {
36018
- const lastIndex = normalized.length - 1;
36019
- const lastNode = normalized[lastIndex];
36020
- if (!lastNode || typeof lastNode.type !== "string" || isInlineNode(lastNode)) {
36021
- pendingForNextBlock.push(node);
36022
- continue;
36023
- }
36024
- const blockContent = ensureArray(lastNode);
36025
- if (pendingForNextBlock.length) {
36026
- blockContent.push(...pendingForNextBlock.splice(0));
36027
- }
36028
- blockContent.push(node);
36029
- }
36030
- }
36031
- if (pendingForNextBlock.length) {
36032
- if (normalized.length) {
36033
- const lastIndex = normalized.length - 1;
36034
- const lastNode = normalized[lastIndex];
36035
- if (lastNode && typeof lastNode.type === "string" && !isInlineNode(lastNode)) {
36036
- const blockContent = ensureArray(lastNode);
36037
- blockContent.push(...pendingForNextBlock);
36038
- pendingForNextBlock.length = 0;
36039
- }
36040
- }
36041
- if (pendingForNextBlock.length) {
36042
- normalized.push({
36043
- type: "paragraph",
36044
- attrs: {},
36045
- content: [...pendingForNextBlock]
36046
- });
36047
- pendingForNextBlock.length = 0;
36048
- }
36049
- }
36050
- return normalized;
36051
- }
36052
- const processInlineCellBorders = (borders, rowBorders) => {
36053
- if (!borders) return null;
36054
- return ["bottom", "top", "left", "right"].reduce((acc, direction) => {
36055
- const borderAttrs = borders[direction];
36056
- const rowBorderAttrs = rowBorders[direction];
36057
- if (borderAttrs && borderAttrs["val"] !== "nil") {
36058
- const color = borderAttrs["color"];
36059
- let size2 = borderAttrs["size"];
36060
- if (size2) size2 = eighthPointsToPixels(size2);
36061
- acc[direction] = { color, size: size2, val: borderAttrs["val"] };
36062
- return acc;
36063
- }
36064
- if (borderAttrs && borderAttrs["val"] === "nil") {
36065
- const border = Object.assign({}, rowBorderAttrs || {});
36066
- if (!Object.keys(border).length) {
36067
- return acc;
36068
- } else {
36069
- border["val"] = "none";
36070
- acc[direction] = border;
36071
- return acc;
36072
- }
36073
- }
36074
- return acc;
36075
- }, {});
36076
- };
36077
- const getTableCellVMerge = (node) => {
36078
- const tcPr = node.elements.find((el) => el.name === "w:tcPr");
36079
- const vMerge = tcPr?.elements?.find((el) => el.name === "w:vMerge");
36080
- if (!vMerge) return null;
36081
- return vMerge.attributes?.["w:val"] || "continue";
36082
- };
36083
- const getTableCellMargins = (inlineMargins, referencedStyles) => {
36084
- const { cellMargins = {} } = referencedStyles;
36085
- return ["left", "right", "top", "bottom"].reduce((acc, direction) => {
36086
- const key2 = `margin${direction.charAt(0).toUpperCase() + direction.slice(1)}`;
36087
- const inlineValue = inlineMargins ? inlineMargins?.[key2]?.value : null;
36088
- const styleValue = cellMargins ? cellMargins[key2] : null;
36089
- if (inlineValue != null) {
36090
- acc[direction] = twipsToPixels(inlineValue);
36091
- } else if (styleValue == null) {
36092
- acc[direction] = void 0;
36093
- } else if (typeof styleValue === "object") {
36094
- acc[direction] = twipsToPixels(styleValue.value);
36095
- } else {
36096
- acc[direction] = twipsToPixels(styleValue);
36097
- }
36098
- return acc;
36099
- }, {});
36100
- };
36101
- function translateTableCell(params2) {
36102
- const elements = translateChildNodes({
36103
- ...params2,
36104
- tableCell: params2.node
36105
- });
36106
- const cellProps = generateTableCellProperties(params2.node);
36107
- elements.unshift(cellProps);
36108
- return {
36109
- name: "w:tc",
36110
- elements
36111
- };
36112
- }
36113
- function generateTableCellProperties(node) {
36114
- const tableCellProperties = { ...node.attrs?.tableCellProperties || {} };
36115
- const { attrs } = node;
36116
- const { colwidth = [], cellWidthType = "dxa", widthUnit } = attrs;
36117
- const colwidthSum = colwidth.reduce((acc, curr) => acc + curr, 0);
36118
- const propertiesWidthPixels = twipsToPixels(tableCellProperties.cellWidth?.value);
36119
- if (propertiesWidthPixels !== colwidthSum) {
36120
- tableCellProperties["cellWidth"] = {
36121
- value: widthUnit === "px" ? pixelsToTwips(colwidthSum) : inchesToTwips(colwidthSum),
36122
- type: cellWidthType
36123
- };
36124
- }
36125
- const { colspan } = attrs;
36126
- if (colspan > 1 && tableCellProperties.gridSpan !== colspan) {
36127
- tableCellProperties["gridSpan"] = colspan;
36128
- } else if (!colspan || tableCellProperties?.gridSpan === 1) {
36129
- delete tableCellProperties.gridSpan;
35176
+ const { colspan } = attrs;
35177
+ if (colspan > 1 && tableCellProperties.gridSpan !== colspan) {
35178
+ tableCellProperties["gridSpan"] = colspan;
35179
+ } else if (!colspan || tableCellProperties?.gridSpan === 1) {
35180
+ delete tableCellProperties.gridSpan;
36130
35181
  }
36131
35182
  const { background = {} } = attrs;
36132
35183
  if (background?.color && tableCellProperties.shading?.fill !== background?.color) {
@@ -36189,22 +35240,22 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36189
35240
  } else if (tableCellProperties?.borders) {
36190
35241
  delete tableCellProperties.borders;
36191
35242
  }
36192
- const result = translator$d.decode({ node: { ...node, attrs: { ...node.attrs, tableCellProperties } } });
35243
+ const result = translator$I.decode({ node: { ...node, attrs: { ...node.attrs, tableCellProperties } } });
36193
35244
  return result;
36194
35245
  }
36195
- const XML_NODE_NAME$d = "w:tc";
36196
- const SD_NODE_NAME$b = "tableCell";
36197
- const validXmlAttributes$a = [];
36198
- function encode$j(params2, encodedAttrs) {
35246
+ const XML_NODE_NAME$g = "w:tc";
35247
+ const SD_NODE_NAME$d = "tableCell";
35248
+ const validXmlAttributes$b = [];
35249
+ function encode$m(params2, encodedAttrs) {
36199
35250
  const {
36200
35251
  node,
36201
35252
  table,
36202
35253
  row,
36203
35254
  rowBorders,
36204
- styleTag,
36205
35255
  columnIndex,
36206
35256
  columnWidth,
36207
- columnWidths: allColumnWidths
35257
+ columnWidths: allColumnWidths,
35258
+ _referencedStyles
36208
35259
  } = params2.extraParams;
36209
35260
  const schemaNode = handleTableCellNode({
36210
35261
  params: params2,
@@ -36212,57 +35263,349 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36212
35263
  table,
36213
35264
  row,
36214
35265
  rowBorders,
36215
- styleTag,
36216
35266
  columnIndex,
36217
35267
  columnWidth,
36218
- allColumnWidths
35268
+ allColumnWidths,
35269
+ _referencedStyles
36219
35270
  });
36220
35271
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
36221
35272
  schemaNode.attrs = { ...schemaNode.attrs, ...encodedAttrs };
36222
35273
  }
36223
35274
  return schemaNode;
36224
35275
  }
36225
- function decode$l(params2, decodedAttrs) {
35276
+ function decode$o(params2, decodedAttrs) {
36226
35277
  const translated = translateTableCell(params2);
36227
35278
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
36228
35279
  translated.attributes = { ...translated.attributes || {}, ...decodedAttrs };
36229
35280
  }
36230
35281
  return translated;
36231
35282
  }
36232
- const config$c = {
36233
- xmlName: XML_NODE_NAME$d,
36234
- sdNodeOrKeyName: SD_NODE_NAME$b,
35283
+ const config$f = {
35284
+ xmlName: XML_NODE_NAME$g,
35285
+ sdNodeOrKeyName: SD_NODE_NAME$d,
36235
35286
  type: NodeTranslator.translatorTypes.NODE,
36236
- encode: encode$j,
36237
- decode: decode$l,
36238
- attributes: validXmlAttributes$a
35287
+ encode: encode$m,
35288
+ decode: decode$o,
35289
+ attributes: validXmlAttributes$b
36239
35290
  };
36240
- const translator$c = NodeTranslator.from(config$c);
36241
- function parseTagValueJSON(json) {
36242
- if (typeof json !== "string") {
36243
- return {};
36244
- }
36245
- const trimmed = json.trim();
36246
- if (!trimmed) {
36247
- return {};
36248
- }
36249
- try {
36250
- return JSON.parse(trimmed);
36251
- } catch {
36252
- return {};
36253
- }
36254
- }
36255
- function handleAnnotationNode(params2) {
36256
- const { nodes } = params2;
36257
- if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
36258
- return null;
35291
+ const translator$H = NodeTranslator.from(config$f);
35292
+ const translator$G = NodeTranslator.from({
35293
+ xmlName: "w:cantSplit",
35294
+ sdNodeOrKeyName: "cantSplit",
35295
+ encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
35296
+ decode: ({ node }) => node.attrs?.cantSplit ? { attributes: {} } : void 0
35297
+ });
35298
+ const translator$F = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
35299
+ const translator$E = NodeTranslator.from(
35300
+ createSingleAttrPropertyHandler(
35301
+ "w:gridAfter",
35302
+ null,
35303
+ "w:val",
35304
+ (v2) => parseInteger(v2) ?? void 0,
35305
+ (v2) => integerToString(v2)
35306
+ )
35307
+ );
35308
+ const translator$D = NodeTranslator.from(
35309
+ createSingleAttrPropertyHandler(
35310
+ "w:gridBefore",
35311
+ null,
35312
+ "w:val",
35313
+ (v2) => parseInteger(v2) ?? void 0,
35314
+ (v2) => integerToString(v2)
35315
+ )
35316
+ );
35317
+ const translator$C = NodeTranslator.from({
35318
+ xmlName: "w:hidden",
35319
+ sdNodeOrKeyName: "hidden",
35320
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
35321
+ decode: ({ node }) => node.attrs.hidden ? { attributes: {} } : void 0
35322
+ });
35323
+ const translator$B = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc", "justification"));
35324
+ const translator$A = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "tableCellSpacing"));
35325
+ const translator$z = NodeTranslator.from({
35326
+ xmlName: "w:tblHeader",
35327
+ sdNodeOrKeyName: "repeatHeader",
35328
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
35329
+ decode: ({ node }) => node.attrs.repeatHeader ? { attributes: {} } : void 0
35330
+ });
35331
+ const translator$y = NodeTranslator.from({
35332
+ xmlName: "w:trHeight",
35333
+ sdNodeOrKeyName: "rowHeight",
35334
+ encode: ({ nodes }) => {
35335
+ const heightAttrs = {};
35336
+ const val = nodes[0].attributes["w:val"];
35337
+ if (val) {
35338
+ heightAttrs["value"] = parseInt(val, 10);
35339
+ }
35340
+ const rule = nodes[0].attributes["w:hRule"];
35341
+ if (rule) {
35342
+ heightAttrs["rule"] = rule;
35343
+ }
35344
+ return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
35345
+ },
35346
+ decode: ({ node }) => {
35347
+ if (!node.attrs?.rowHeight) return;
35348
+ const heightAttrs = {};
35349
+ if (typeof node.attrs.rowHeight.value === "number" && !isNaN(node.attrs.rowHeight.value)) {
35350
+ heightAttrs["w:val"] = String(node.attrs.rowHeight.value);
35351
+ }
35352
+ if (node.attrs.rowHeight.rule) {
35353
+ heightAttrs["w:hRule"] = node.attrs.rowHeight.rule;
35354
+ }
35355
+ return Object.keys(heightAttrs).length > 0 ? { attributes: heightAttrs } : void 0;
36259
35356
  }
36260
- const node = nodes[0];
36261
- const sdtPr = node.elements.find((el) => el.name === "w:sdtPr");
36262
- const sdtContent = node.elements.find((el) => el.name === "w:sdtContent");
36263
- const sdtId = sdtPr?.elements?.find((el) => el.name === "w:id");
36264
- const alias = sdtPr?.elements.find((el) => el.name === "w:alias");
36265
- const tag = sdtPr?.elements.find((el) => el.name === "w:tag");
35357
+ });
35358
+ const translator$x = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
35359
+ const translator$w = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
35360
+ const propertyTranslators$3 = [
35361
+ translator$G,
35362
+ translator$1a,
35363
+ translator$F,
35364
+ translator$E,
35365
+ translator$D,
35366
+ translator$C,
35367
+ translator$B,
35368
+ translator$A,
35369
+ translator$z,
35370
+ translator$y,
35371
+ translator$x,
35372
+ translator$w
35373
+ ];
35374
+ const translator$v = NodeTranslator.from(
35375
+ createNestedPropertiesTranslator("w:trPr", "tableRowProperties", propertyTranslators$3, {
35376
+ cantSplit: false,
35377
+ hidden: false,
35378
+ repeatHeader: false
35379
+ })
35380
+ );
35381
+ const createPlaceholderCell = (gridWidth, reason) => {
35382
+ const safeWidth = Number.isFinite(gridWidth) ? gridWidth : 0;
35383
+ const noBorder = { val: "none", size: 0 };
35384
+ return {
35385
+ type: "tableCell",
35386
+ attrs: {
35387
+ colspan: 1,
35388
+ rowspan: 1,
35389
+ colwidth: [safeWidth],
35390
+ __placeholder: reason,
35391
+ borders: {
35392
+ top: { ...noBorder },
35393
+ right: { ...noBorder },
35394
+ bottom: { ...noBorder },
35395
+ left: { ...noBorder }
35396
+ }
35397
+ },
35398
+ content: [{ type: "paragraph", content: [] }]
35399
+ };
35400
+ };
35401
+ const advancePastRowSpans = (pendingRowSpans, startIndex, totalColumns) => {
35402
+ let index2 = startIndex;
35403
+ while (index2 < totalColumns && pendingRowSpans[index2] > 0) {
35404
+ pendingRowSpans[index2] -= 1;
35405
+ index2 += 1;
35406
+ }
35407
+ return index2;
35408
+ };
35409
+ const fillPlaceholderColumns = ({
35410
+ content,
35411
+ pendingRowSpans,
35412
+ currentIndex,
35413
+ targetIndex,
35414
+ totalColumns,
35415
+ gridColumnWidths,
35416
+ reason
35417
+ }) => {
35418
+ let index2 = currentIndex;
35419
+ while (index2 < targetIndex && index2 < totalColumns) {
35420
+ if (pendingRowSpans[index2] > 0) {
35421
+ pendingRowSpans[index2] -= 1;
35422
+ index2 += 1;
35423
+ continue;
35424
+ }
35425
+ const width = Array.isArray(gridColumnWidths) ? gridColumnWidths[index2] ?? 0 : 0;
35426
+ content.push(createPlaceholderCell(width, reason));
35427
+ index2 += 1;
35428
+ }
35429
+ return index2;
35430
+ };
35431
+ const isPlaceholderCell = (cell) => {
35432
+ if (!cell) return false;
35433
+ if (cell.attrs?.__placeholder) return true;
35434
+ const widths = cell.attrs?.colwidth;
35435
+ if (Array.isArray(widths) && widths.length > 0) {
35436
+ const hasMeaningfulWidth = widths.some(
35437
+ (value) => typeof value === "number" && Number.isFinite(value) && Math.abs(value) > 1
35438
+ );
35439
+ if (!hasMeaningfulWidth) return true;
35440
+ }
35441
+ return false;
35442
+ };
35443
+ const XML_NODE_NAME$f = "w:tr";
35444
+ const SD_NODE_NAME$c = "tableRow";
35445
+ const validXmlAttributes$a = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
35446
+ (xmlName) => createAttributeHandler(xmlName)
35447
+ );
35448
+ const encode$l = (params2, encodedAttrs) => {
35449
+ const { row } = params2.extraParams;
35450
+ let tableRowProperties = {};
35451
+ const tPr = row.elements.find((el) => el.name === "w:trPr");
35452
+ if (tPr) {
35453
+ tableRowProperties = translator$v.encode({
35454
+ ...params2,
35455
+ nodes: [tPr]
35456
+ });
35457
+ }
35458
+ const gridBeforeRaw = tableRowProperties?.["gridBefore"];
35459
+ const safeGridBefore = typeof gridBeforeRaw === "number" && Number.isFinite(gridBeforeRaw) && gridBeforeRaw > 0 ? gridBeforeRaw : 0;
35460
+ encodedAttrs["tableRowProperties"] = Object.freeze(tableRowProperties);
35461
+ encodedAttrs["rowHeight"] = twipsToPixels(tableRowProperties["rowHeight"]?.value);
35462
+ encodedAttrs["cantSplit"] = tableRowProperties["cantSplit"];
35463
+ const { columnWidths: gridColumnWidths, activeRowSpans = [] } = params2.extraParams;
35464
+ const totalColumns = Array.isArray(gridColumnWidths) ? gridColumnWidths.length : 0;
35465
+ const pendingRowSpans = Array.isArray(activeRowSpans) ? activeRowSpans.slice() : [];
35466
+ while (pendingRowSpans.length < totalColumns) pendingRowSpans.push(0);
35467
+ const cellNodes = row.elements.filter((el) => el.name === "w:tc");
35468
+ const content = [];
35469
+ let currentColumnIndex = 0;
35470
+ const fillUntil = (target, reason) => {
35471
+ currentColumnIndex = fillPlaceholderColumns({
35472
+ content,
35473
+ pendingRowSpans,
35474
+ currentIndex: currentColumnIndex,
35475
+ targetIndex: target,
35476
+ totalColumns,
35477
+ gridColumnWidths,
35478
+ reason
35479
+ });
35480
+ };
35481
+ const skipOccupiedColumns = () => {
35482
+ currentColumnIndex = advancePastRowSpans(pendingRowSpans, currentColumnIndex, totalColumns);
35483
+ };
35484
+ fillUntil(safeGridBefore, "gridBefore");
35485
+ skipOccupiedColumns();
35486
+ cellNodes?.forEach((node) => {
35487
+ skipOccupiedColumns();
35488
+ const startColumn = currentColumnIndex;
35489
+ const columnWidth = gridColumnWidths?.[startColumn] || null;
35490
+ const result = translator$H.encode({
35491
+ ...params2,
35492
+ extraParams: {
35493
+ ...params2.extraParams,
35494
+ node,
35495
+ columnIndex: startColumn,
35496
+ columnWidth
35497
+ }
35498
+ });
35499
+ if (result) {
35500
+ content.push(result);
35501
+ const colspan = Math.max(1, result.attrs?.colspan || 1);
35502
+ const rowspan = Math.max(1, result.attrs?.rowspan || 1);
35503
+ if (rowspan > 1) {
35504
+ for (let offset2 = 0; offset2 < colspan; offset2 += 1) {
35505
+ const target = startColumn + offset2;
35506
+ if (target < pendingRowSpans.length) {
35507
+ pendingRowSpans[target] = Math.max(pendingRowSpans[target], rowspan - 1);
35508
+ }
35509
+ }
35510
+ }
35511
+ currentColumnIndex = startColumn + colspan;
35512
+ }
35513
+ });
35514
+ skipOccupiedColumns();
35515
+ fillUntil(totalColumns, "gridAfter");
35516
+ const newNode = {
35517
+ type: "tableRow",
35518
+ content,
35519
+ attrs: encodedAttrs
35520
+ };
35521
+ return newNode;
35522
+ };
35523
+ const decode$n = (params2, decodedAttrs) => {
35524
+ const { node } = params2;
35525
+ const cells = node.content || [];
35526
+ let leadingPlaceholders = 0;
35527
+ while (leadingPlaceholders < cells.length && isPlaceholderCell(cells[leadingPlaceholders])) {
35528
+ leadingPlaceholders += 1;
35529
+ }
35530
+ let trailingPlaceholders = 0;
35531
+ while (trailingPlaceholders < cells.length - leadingPlaceholders && isPlaceholderCell(cells[cells.length - 1 - trailingPlaceholders])) {
35532
+ trailingPlaceholders += 1;
35533
+ }
35534
+ const trimmedSlice = cells.slice(leadingPlaceholders, cells.length - trailingPlaceholders);
35535
+ const sanitizedCells = trimmedSlice.map((cell) => {
35536
+ if (cell?.attrs && "__placeholder" in cell.attrs) {
35537
+ const { __placeholder, ...rest } = cell.attrs;
35538
+ return { ...cell, attrs: rest };
35539
+ }
35540
+ return cell;
35541
+ });
35542
+ const trimmedContent = sanitizedCells.filter((_2, index2) => !isPlaceholderCell(trimmedSlice[index2]));
35543
+ const translateParams = {
35544
+ ...params2,
35545
+ node: { ...node, content: trimmedContent }
35546
+ };
35547
+ const elements = translateChildNodes(translateParams);
35548
+ if (node.attrs?.tableRowProperties) {
35549
+ const tableRowProperties = { ...node.attrs.tableRowProperties };
35550
+ if (leadingPlaceholders > 0) {
35551
+ tableRowProperties.gridBefore = leadingPlaceholders;
35552
+ }
35553
+ if (trailingPlaceholders > 0) {
35554
+ tableRowProperties.gridAfter = trailingPlaceholders;
35555
+ }
35556
+ if (node.attrs.rowHeight != null) {
35557
+ const rowHeightPixels = twipsToPixels(node.attrs.tableRowProperties["rowHeight"]?.value);
35558
+ if (rowHeightPixels !== node.attrs.rowHeight) {
35559
+ tableRowProperties["rowHeight"] = { value: String(pixelsToTwips(node.attrs["rowHeight"])) };
35560
+ }
35561
+ }
35562
+ tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
35563
+ const trPr = translator$v.decode({
35564
+ ...params2,
35565
+ node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
35566
+ });
35567
+ if (trPr) elements.unshift(trPr);
35568
+ }
35569
+ return {
35570
+ name: "w:tr",
35571
+ attributes: decodedAttrs || {},
35572
+ elements
35573
+ };
35574
+ };
35575
+ const config$e = {
35576
+ xmlName: XML_NODE_NAME$f,
35577
+ sdNodeOrKeyName: SD_NODE_NAME$c,
35578
+ type: NodeTranslator.translatorTypes.NODE,
35579
+ encode: encode$l,
35580
+ decode: decode$n,
35581
+ attributes: validXmlAttributes$a
35582
+ };
35583
+ const translator$u = NodeTranslator.from(config$e);
35584
+ function parseTagValueJSON(json) {
35585
+ if (typeof json !== "string") {
35586
+ return {};
35587
+ }
35588
+ const trimmed = json.trim();
35589
+ if (!trimmed) {
35590
+ return {};
35591
+ }
35592
+ try {
35593
+ return JSON.parse(trimmed);
35594
+ } catch {
35595
+ return {};
35596
+ }
35597
+ }
35598
+ function handleAnnotationNode(params2) {
35599
+ const { nodes } = params2;
35600
+ if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
35601
+ return null;
35602
+ }
35603
+ const node = nodes[0];
35604
+ const sdtPr = node.elements.find((el) => el.name === "w:sdtPr");
35605
+ const sdtContent = node.elements.find((el) => el.name === "w:sdtContent");
35606
+ const sdtId = sdtPr?.elements?.find((el) => el.name === "w:id");
35607
+ const alias = sdtPr?.elements.find((el) => el.name === "w:alias");
35608
+ const tag = sdtPr?.elements.find((el) => el.name === "w:tag");
36266
35609
  const tagValue = tag?.attributes["w:val"];
36267
35610
  const shouldProcessAsJson = tagValue?.startsWith("{") && tagValue?.endsWith("}");
36268
35611
  let attrs = {};
@@ -37560,32 +36903,32 @@ Please report this to https://github.com/markedjs/marked.`, e) {
37560
36903
  elements: [...anchorElements, ...elementsWithWrap]
37561
36904
  };
37562
36905
  }
37563
- const XML_NODE_NAME$c = "wp:anchor";
37564
- const SD_NODE_NAME$a = ["image"];
36906
+ const XML_NODE_NAME$e = "wp:anchor";
36907
+ const SD_NODE_NAME$b = ["image"];
37565
36908
  const validXmlAttributes$9 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
37566
- function encode$i(params2) {
36909
+ function encode$k(params2) {
37567
36910
  const { node } = params2.extraParams;
37568
36911
  if (!node || !node.type) {
37569
36912
  return null;
37570
36913
  }
37571
36914
  return handleAnchorNode(params2);
37572
36915
  }
37573
- function decode$k(params2) {
36916
+ function decode$m(params2) {
37574
36917
  const { node } = params2;
37575
36918
  if (!node || !node.type) {
37576
36919
  return null;
37577
36920
  }
37578
36921
  return translateAnchorNode(params2);
37579
36922
  }
37580
- const config$b = {
37581
- xmlName: XML_NODE_NAME$c,
37582
- sdNodeOrKeyName: SD_NODE_NAME$a,
36923
+ const config$d = {
36924
+ xmlName: XML_NODE_NAME$e,
36925
+ sdNodeOrKeyName: SD_NODE_NAME$b,
37583
36926
  type: NodeTranslator.translatorTypes.NODE,
37584
- encode: encode$i,
37585
- decode: decode$k,
36927
+ encode: encode$k,
36928
+ decode: decode$m,
37586
36929
  attributes: validXmlAttributes$9
37587
36930
  };
37588
- const translator$b = NodeTranslator.from(config$b);
36931
+ const translator$t = NodeTranslator.from(config$d);
37589
36932
  function handleInlineNode(params2) {
37590
36933
  const { node } = params2.extraParams;
37591
36934
  if (node.name !== "wp:inline") {
@@ -37601,41 +36944,41 @@ Please report this to https://github.com/markedjs/marked.`, e) {
37601
36944
  elements: nodeElements.elements
37602
36945
  };
37603
36946
  }
37604
- const XML_NODE_NAME$b = "wp:inline";
37605
- const SD_NODE_NAME$9 = ["image"];
36947
+ const XML_NODE_NAME$d = "wp:inline";
36948
+ const SD_NODE_NAME$a = ["image"];
37606
36949
  const validXmlAttributes$8 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
37607
- function encode$h(params2) {
36950
+ function encode$j(params2) {
37608
36951
  const { node } = params2.extraParams;
37609
36952
  if (!node || !node.type) {
37610
36953
  return null;
37611
36954
  }
37612
36955
  return handleInlineNode(params2);
37613
36956
  }
37614
- function decode$j(params2) {
36957
+ function decode$l(params2) {
37615
36958
  const { node } = params2;
37616
36959
  if (!node || !node.type) {
37617
36960
  return null;
37618
36961
  }
37619
36962
  return translateInlineNode(params2);
37620
36963
  }
37621
- const config$a = {
37622
- xmlName: XML_NODE_NAME$b,
37623
- sdNodeOrKeyName: SD_NODE_NAME$9,
36964
+ const config$c = {
36965
+ xmlName: XML_NODE_NAME$d,
36966
+ sdNodeOrKeyName: SD_NODE_NAME$a,
37624
36967
  type: NodeTranslator.translatorTypes.NODE,
37625
- encode: encode$h,
37626
- decode: decode$j,
36968
+ encode: encode$j,
36969
+ decode: decode$l,
37627
36970
  attributes: validXmlAttributes$8
37628
36971
  };
37629
- const translator$a = NodeTranslator.from(config$a);
37630
- const XML_NODE_NAME$a = "w:drawing";
37631
- const SD_NODE_NAME$8 = [];
36972
+ const translator$s = NodeTranslator.from(config$c);
36973
+ const XML_NODE_NAME$c = "w:drawing";
36974
+ const SD_NODE_NAME$9 = [];
37632
36975
  const validXmlAttributes$7 = [];
37633
- function encode$g(params2) {
36976
+ function encode$i(params2) {
37634
36977
  const nodes = params2.nodes;
37635
36978
  const node = nodes[0];
37636
36979
  const translatorByChildName = {
37637
- "wp:anchor": translator$b,
37638
- "wp:inline": translator$a
36980
+ "wp:anchor": translator$t,
36981
+ "wp:inline": translator$s
37639
36982
  };
37640
36983
  return node.elements.reduce((acc, child) => {
37641
36984
  if (acc) return acc;
@@ -37644,12 +36987,12 @@ Please report this to https://github.com/markedjs/marked.`, e) {
37644
36987
  return translator2.encode({ ...params2, extraParams: { node: child } }) || acc;
37645
36988
  }, null);
37646
36989
  }
37647
- function decode$i(params2) {
36990
+ function decode$k(params2) {
37648
36991
  const { node } = params2;
37649
36992
  if (!node || !node.type) {
37650
36993
  return null;
37651
36994
  }
37652
- const childTranslator = node.attrs.isAnchor ? translator$b : translator$a;
36995
+ const childTranslator = node.attrs.isAnchor ? translator$t : translator$s;
37653
36996
  const resultNode = childTranslator.decode(params2);
37654
36997
  return wrapTextInRun(
37655
36998
  {
@@ -37659,15 +37002,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
37659
37002
  []
37660
37003
  );
37661
37004
  }
37662
- const config$9 = {
37663
- xmlName: XML_NODE_NAME$a,
37664
- sdNodeOrKeyName: SD_NODE_NAME$8,
37005
+ const config$b = {
37006
+ xmlName: XML_NODE_NAME$c,
37007
+ sdNodeOrKeyName: SD_NODE_NAME$9,
37665
37008
  type: NodeTranslator.translatorTypes.NODE,
37666
- encode: encode$g,
37667
- decode: decode$i,
37009
+ encode: encode$i,
37010
+ decode: decode$k,
37668
37011
  attributes: validXmlAttributes$7
37669
37012
  };
37670
- const translator$9 = NodeTranslator.from(config$9);
37013
+ const translator$r = NodeTranslator.from(config$b);
37671
37014
  class CommandService {
37672
37015
  /**
37673
37016
  * @param {import('./commands/types/index.js').CommandServiceOptions} props
@@ -39015,7 +38358,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
39015
38358
  return getTextNodeForExport(attrs.displayLabel, [...marks, ...marksFromAttrs], params2);
39016
38359
  }
39017
38360
  function prepareImageAnnotation(params2, imageSize) {
39018
- return translator$9.decode({
38361
+ return translator$r.decode({
39019
38362
  ...params2,
39020
38363
  imageSize
39021
38364
  });
@@ -39042,324 +38385,901 @@ Please report this to https://github.com/markedjs/marked.`, e) {
39042
38385
  if (allMarks.length) {
39043
38386
  state2 = applyMarksToHtmlAnnotation(state2, allMarks);
39044
38387
  }
39045
- const htmlAnnotationNode = state2.doc.toJSON();
39046
- const listTypes = ["bulletList", "orderedList"];
39047
- const { editor } = params2;
39048
- const seenLists = /* @__PURE__ */ new Map();
39049
- state2.doc.descendants((node) => {
39050
- if (listTypes.includes(node.type.name)) {
39051
- const listItem = node.firstChild;
39052
- const { attrs: attrs2 } = listItem;
39053
- const { level, numId } = attrs2;
39054
- if (!seenLists.has(numId)) {
39055
- const newNumId = ListHelpers.changeNumIdSameAbstract(numId, level, node.type.name, editor);
39056
- listItem.attrs.numId = newNumId;
39057
- seenLists.set(numId, newNumId);
39058
- } else {
39059
- const newNumId = seenLists.get(numId);
39060
- listItem.attrs.numId = newNumId;
39061
- }
39062
- }
39063
- });
39064
- const elements = translateChildNodes({
39065
- ...params2,
39066
- node: htmlAnnotationNode
39067
- });
39068
- return {
39069
- name: "htmlAnnotation",
39070
- elements
39071
- };
39072
- }
39073
- function prepareUrlAnnotation(params2) {
39074
- const {
39075
- node: { attrs = {}, marks = [] }
39076
- } = params2;
39077
- if (!attrs.linkUrl) return prepareTextAnnotation(params2);
39078
- const newId = addNewLinkRelationship(params2, attrs.linkUrl);
39079
- const linkTextNode = getTextNodeForExport(attrs.linkUrl, marks, params2);
39080
- const contentNode = processLinkContentNode(linkTextNode);
38388
+ const htmlAnnotationNode = state2.doc.toJSON();
38389
+ const listTypes = ["bulletList", "orderedList"];
38390
+ const { editor } = params2;
38391
+ const seenLists = /* @__PURE__ */ new Map();
38392
+ state2.doc.descendants((node) => {
38393
+ if (listTypes.includes(node.type.name)) {
38394
+ const listItem = node.firstChild;
38395
+ const { attrs: attrs2 } = listItem;
38396
+ const { level, numId } = attrs2;
38397
+ if (!seenLists.has(numId)) {
38398
+ const newNumId = ListHelpers.changeNumIdSameAbstract(numId, level, node.type.name, editor);
38399
+ listItem.attrs.numId = newNumId;
38400
+ seenLists.set(numId, newNumId);
38401
+ } else {
38402
+ const newNumId = seenLists.get(numId);
38403
+ listItem.attrs.numId = newNumId;
38404
+ }
38405
+ }
38406
+ });
38407
+ const elements = translateChildNodes({
38408
+ ...params2,
38409
+ node: htmlAnnotationNode
38410
+ });
38411
+ return {
38412
+ name: "htmlAnnotation",
38413
+ elements
38414
+ };
38415
+ }
38416
+ function prepareUrlAnnotation(params2) {
38417
+ const {
38418
+ node: { attrs = {}, marks = [] }
38419
+ } = params2;
38420
+ if (!attrs.linkUrl) return prepareTextAnnotation(params2);
38421
+ const newId = addNewLinkRelationship(params2, attrs.linkUrl);
38422
+ const linkTextNode = getTextNodeForExport(attrs.linkUrl, marks, params2);
38423
+ const contentNode = processLinkContentNode(linkTextNode);
38424
+ return {
38425
+ name: "w:hyperlink",
38426
+ type: "element",
38427
+ attributes: {
38428
+ "r:id": newId,
38429
+ "w:history": 1
38430
+ },
38431
+ elements: [contentNode]
38432
+ };
38433
+ }
38434
+ function translateFieldAttrsToMarks(attrs = {}) {
38435
+ const { fontFamily: fontFamily2, fontSize: fontSize2, bold, underline, italic, textColor, textHighlight } = attrs;
38436
+ const marks = [];
38437
+ if (fontFamily2) marks.push({ type: "fontFamily", attrs: { fontFamily: fontFamily2 } });
38438
+ if (fontSize2) marks.push({ type: "fontSize", attrs: { fontSize: fontSize2 } });
38439
+ if (bold) marks.push({ type: "bold", attrs: {} });
38440
+ if (underline) marks.push({ type: "underline", attrs: {} });
38441
+ if (italic) marks.push({ type: "italic", attrs: {} });
38442
+ if (textColor) marks.push({ type: "color", attrs: { color: textColor } });
38443
+ if (textHighlight) marks.push({ type: "highlight", attrs: { color: textHighlight } });
38444
+ return marks;
38445
+ }
38446
+ function applyMarksToHtmlAnnotation(state2, marks) {
38447
+ const { tr, doc: doc2, schema } = state2;
38448
+ const allowedMarks = ["fontFamily", "fontSize", "highlight"];
38449
+ if (!marks.some((m2) => allowedMarks.includes(m2.type))) {
38450
+ return state2;
38451
+ }
38452
+ const fontFamily2 = marks.find((m2) => m2.type === "fontFamily");
38453
+ const fontSize2 = marks.find((m2) => m2.type === "fontSize");
38454
+ const highlight = marks.find((m2) => m2.type === "highlight");
38455
+ const textStyleType = schema.marks.textStyle;
38456
+ const highlightType = schema.marks.highlight;
38457
+ doc2.descendants((node, pos) => {
38458
+ if (!node.isText) return;
38459
+ const foundTextStyle = node.marks.find((m2) => m2.type.name === "textStyle");
38460
+ const foundHighlight = node.marks.find((m2) => m2.type.name === "highlight");
38461
+ if (!foundTextStyle) {
38462
+ tr.addMark(
38463
+ pos,
38464
+ pos + node.nodeSize,
38465
+ textStyleType.create({
38466
+ ...fontFamily2?.attrs,
38467
+ ...fontSize2?.attrs
38468
+ })
38469
+ );
38470
+ } else if (!foundTextStyle?.attrs.fontFamily && fontFamily2) {
38471
+ tr.addMark(
38472
+ pos,
38473
+ pos + node.nodeSize,
38474
+ textStyleType.create({
38475
+ ...foundTextStyle?.attrs,
38476
+ ...fontFamily2.attrs
38477
+ })
38478
+ );
38479
+ } else if (!foundTextStyle?.attrs.fontSize && fontSize2) {
38480
+ tr.addMark(
38481
+ pos,
38482
+ pos + node.nodeSize,
38483
+ textStyleType.create({
38484
+ ...foundTextStyle?.attrs,
38485
+ ...fontSize2.attrs
38486
+ })
38487
+ );
38488
+ }
38489
+ if (!foundHighlight) {
38490
+ tr.addMark(
38491
+ pos,
38492
+ pos + node.nodeSize,
38493
+ highlightType.create({
38494
+ ...highlight?.attrs
38495
+ })
38496
+ );
38497
+ }
38498
+ });
38499
+ return state2.apply(tr);
38500
+ }
38501
+ function getFieldHighlightJson(fieldsHighlightColor) {
38502
+ if (!fieldsHighlightColor) return null;
38503
+ let parsedColor = fieldsHighlightColor.trim();
38504
+ const hexRegex2 = /^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/;
38505
+ if (!hexRegex2.test(parsedColor)) {
38506
+ console.warn(`Invalid HEX color provided to fieldsHighlightColor export param: ${fieldsHighlightColor}`);
38507
+ return null;
38508
+ }
38509
+ if (parsedColor.startsWith("#")) {
38510
+ parsedColor = parsedColor.slice(1);
38511
+ }
38512
+ return {
38513
+ name: "w:rPr",
38514
+ elements: [
38515
+ {
38516
+ name: "w:shd",
38517
+ attributes: {
38518
+ "w:fill": `#${parsedColor}`,
38519
+ "w:color": "auto",
38520
+ "w:val": "clear"
38521
+ }
38522
+ }
38523
+ ]
38524
+ };
38525
+ }
38526
+ function translateDocumentSection(params2) {
38527
+ const { node } = params2;
38528
+ const { attrs = {} } = node;
38529
+ const childContent = translateChildNodes({ ...params2, nodes: node.content });
38530
+ const nodeElements = [
38531
+ {
38532
+ name: "w:sdtContent",
38533
+ elements: childContent
38534
+ }
38535
+ ];
38536
+ const exportedTag = JSON.stringify({
38537
+ type: "documentSection",
38538
+ description: attrs.description
38539
+ });
38540
+ const sdtPr = generateSdtPrTagForDocumentSection(attrs.id, attrs.title, exportedTag);
38541
+ const { isLocked } = attrs;
38542
+ if (isLocked) {
38543
+ sdtPr.elements.push({
38544
+ name: "w:lock",
38545
+ attributes: {
38546
+ "w:val": "sdtContentLocked"
38547
+ }
38548
+ });
38549
+ }
38550
+ nodeElements.unshift(sdtPr);
38551
+ const result = {
38552
+ name: "w:sdt",
38553
+ elements: nodeElements
38554
+ };
38555
+ return result;
38556
+ }
38557
+ const generateSdtPrTagForDocumentSection = (id, title, tag) => {
38558
+ return {
38559
+ name: "w:sdtPr",
38560
+ elements: [
38561
+ {
38562
+ name: "w:id",
38563
+ attributes: {
38564
+ "w:val": id
38565
+ }
38566
+ },
38567
+ {
38568
+ name: "w:alias",
38569
+ attributes: {
38570
+ "w:val": title
38571
+ }
38572
+ },
38573
+ {
38574
+ name: "w:tag",
38575
+ attributes: {
38576
+ "w:val": tag
38577
+ }
38578
+ }
38579
+ ]
38580
+ };
38581
+ };
38582
+ function translateDocumentPartObj(params2) {
38583
+ const { node } = params2;
38584
+ const { attrs = {} } = node;
38585
+ const childContent = translateChildNodes({ ...params2, nodes: node.content });
38586
+ const nodeElements = [
38587
+ {
38588
+ name: "w:sdtPr",
38589
+ elements: [
38590
+ {
38591
+ name: "w:id",
38592
+ attributes: {
38593
+ "w:val": attrs.id
38594
+ }
38595
+ },
38596
+ {
38597
+ name: "w:docPartObj",
38598
+ elements: [
38599
+ {
38600
+ name: "w:docPartGallery",
38601
+ attributes: {
38602
+ "w:val": attrs.docPartGallery
38603
+ }
38604
+ },
38605
+ ...attrs.docPartUnique ? [
38606
+ {
38607
+ name: "w:docPartUnique"
38608
+ }
38609
+ ] : []
38610
+ ]
38611
+ }
38612
+ ]
38613
+ },
38614
+ {
38615
+ name: "w:sdtContent",
38616
+ elements: childContent
38617
+ }
38618
+ ];
38619
+ const result = {
38620
+ name: "w:sdt",
38621
+ elements: nodeElements
38622
+ };
38623
+ return result;
38624
+ }
38625
+ function translateStructuredContent(params2) {
38626
+ const { node } = params2;
38627
+ const childContent = translateChildNodes({ ...params2, nodes: node.content });
38628
+ const sdtContent = { name: "w:sdtContent", elements: childContent };
38629
+ const sdtPr = generateSdtPrTagForStructuredContent({ node });
38630
+ const nodeElements = [sdtPr, sdtContent];
38631
+ const result = {
38632
+ name: "w:sdt",
38633
+ elements: nodeElements
38634
+ };
38635
+ return result;
38636
+ }
38637
+ function generateSdtPrTagForStructuredContent({ node }) {
38638
+ const { attrs = {} } = node;
38639
+ const id = {
38640
+ name: "w:id",
38641
+ type: "element",
38642
+ attributes: { "w:val": attrs.id }
38643
+ };
38644
+ const alias = {
38645
+ name: "w:alias",
38646
+ type: "element",
38647
+ attributes: { "w:val": attrs.alias }
38648
+ };
38649
+ const tag = {
38650
+ name: "w:tag",
38651
+ type: "element",
38652
+ attributes: { "w:val": attrs.tag }
38653
+ };
38654
+ const resultElements = [];
38655
+ if (attrs.id) resultElements.push(id);
38656
+ if (attrs.alias) resultElements.push(alias);
38657
+ if (attrs.tag) resultElements.push(tag);
38658
+ if (attrs.sdtPr) {
38659
+ const elements = attrs.sdtPr.elements || [];
38660
+ const elementsToExclude = ["w:id", "w:alias", "w:tag"];
38661
+ const restElements = elements.filter((el) => !elementsToExclude.includes(el.name));
38662
+ const result2 = {
38663
+ name: "w:sdtPr",
38664
+ type: "element",
38665
+ elements: [...resultElements, ...restElements]
38666
+ };
38667
+ return result2;
38668
+ }
38669
+ const result = {
38670
+ name: "w:sdtPr",
38671
+ type: "element",
38672
+ elements: resultElements
38673
+ };
38674
+ return result;
38675
+ }
38676
+ const XML_NODE_NAME$b = "w:sdt";
38677
+ const SD_NODE_NAME$8 = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
38678
+ const validXmlAttributes$6 = [];
38679
+ function encode$h(params2) {
38680
+ const nodes = params2.nodes;
38681
+ const node = nodes[0];
38682
+ const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
38683
+ if (!handler2 || sdtType === "unknown") {
38684
+ return void 0;
38685
+ }
38686
+ const result = handler2(params2);
38687
+ return result;
38688
+ }
38689
+ function decode$j(params2) {
38690
+ const { node } = params2;
38691
+ if (!node || !node.type) {
38692
+ return null;
38693
+ }
38694
+ const types2 = {
38695
+ fieldAnnotation: () => translateFieldAnnotation(params2),
38696
+ structuredContent: () => translateStructuredContent(params2),
38697
+ structuredContentBlock: () => translateStructuredContent(params2),
38698
+ documentSection: () => translateDocumentSection(params2),
38699
+ documentPartObject: () => translateDocumentPartObj(params2),
38700
+ // Handled in doc-part-obj translator
38701
+ default: () => null
38702
+ };
38703
+ const decoder = types2[node.type] ?? types2.default;
38704
+ const result = decoder();
38705
+ return result;
38706
+ }
38707
+ const config$a = {
38708
+ xmlName: XML_NODE_NAME$b,
38709
+ sdNodeOrKeyName: SD_NODE_NAME$8,
38710
+ type: NodeTranslator.translatorTypes.NODE,
38711
+ encode: encode$h,
38712
+ decode: decode$j,
38713
+ attributes: validXmlAttributes$6
38714
+ };
38715
+ const translator$q = NodeTranslator.from(config$a);
38716
+ function preProcessVerticalMergeCells(table, { editorSchema }) {
38717
+ if (!table || !Array.isArray(table.content)) {
38718
+ return table;
38719
+ }
38720
+ const rows = table.content;
38721
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
38722
+ const row = rows[rowIndex];
38723
+ if (!row) continue;
38724
+ if (!Array.isArray(row.content)) {
38725
+ row.content = [];
38726
+ }
38727
+ for (let cellIndex = 0; cellIndex < row.content.length; cellIndex++) {
38728
+ const cell = row.content[cellIndex];
38729
+ if (!cell) continue;
38730
+ const attrs = cell.attrs || {};
38731
+ if (!attrs.rowspan || attrs.rowspan <= 1) continue;
38732
+ const maxRowspan = Math.min(attrs.rowspan, rows.length - rowIndex);
38733
+ for (let offset2 = 1; offset2 < maxRowspan; offset2++) {
38734
+ const rowToChange = rows[rowIndex + offset2];
38735
+ if (!rowToChange) continue;
38736
+ if (!Array.isArray(rowToChange.content)) {
38737
+ rowToChange.content = [];
38738
+ }
38739
+ const existingCell = rowToChange.content[cellIndex];
38740
+ if (existingCell?.attrs?.continueMerge) continue;
38741
+ const mergedCell = {
38742
+ type: cell.type,
38743
+ content: [editorSchema.nodes.paragraph.createAndFill().toJSON()],
38744
+ attrs: {
38745
+ ...cell.attrs,
38746
+ rowspan: null,
38747
+ continueMerge: true
38748
+ }
38749
+ };
38750
+ rowToChange.content.splice(cellIndex, 0, mergedCell);
38751
+ }
38752
+ }
38753
+ }
38754
+ return table;
38755
+ }
38756
+ const translator$p = NodeTranslator.from({
38757
+ xmlName: "w:bidiVisual",
38758
+ sdNodeOrKeyName: "rightToLeft",
38759
+ encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
38760
+ decode: ({ node }) => node.attrs.rightToLeft ? { attributes: {} } : void 0
38761
+ });
38762
+ const translator$o = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblCaption", "caption"));
38763
+ const translator$n = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblDescription", "description"));
38764
+ const translator$m = NodeTranslator.from(createMeasurementPropertyHandler("w:tblInd", "tableIndent"));
38765
+ const translator$l = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblLayout", "tableLayout", "w:type"));
38766
+ const translator$k = NodeTranslator.from({
38767
+ xmlName: "w:tblLook",
38768
+ sdNodeOrKeyName: "tblLook",
38769
+ attributes: ["w:firstColumn", "w:firstRow", "w:lastColumn", "w:lastRow", "w:noHBand", "w:noVBand"].map((attr) => createAttributeHandler(attr, null, parseBoolean, booleanToString)).concat([createAttributeHandler("w:val")]),
38770
+ encode: (params2, encodedAttrs) => {
38771
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
38772
+ },
38773
+ decode: function({ node }, context) {
38774
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.tblLook || {} } });
38775
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
38776
+ }
38777
+ });
38778
+ const translator$j = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblOverlap", "overlap"));
38779
+ const translator$i = NodeTranslator.from(createSingleAttrPropertyHandler("w:tblStyle", "tableStyleId"));
38780
+ const translator$h = NodeTranslator.from(
38781
+ createSingleAttrPropertyHandler("w:tblStyleColBandSize", "tableStyleColBandSize")
38782
+ );
38783
+ const translator$g = NodeTranslator.from(
38784
+ createSingleAttrPropertyHandler("w:tblStyleRowBandSize", "tableStyleRowBandSize")
38785
+ );
38786
+ const translator$f = NodeTranslator.from(createMeasurementPropertyHandler("w:tblW", "tableWidth"));
38787
+ const translator$e = NodeTranslator.from({
38788
+ xmlName: "w:tblpPr",
38789
+ sdNodeOrKeyName: "floatingTableProperties",
38790
+ 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))),
38791
+ encode: (params2, encodedAttrs) => {
38792
+ return Object.keys(encodedAttrs).length > 0 ? encodedAttrs : void 0;
38793
+ },
38794
+ decode: function({ node }, context) {
38795
+ const decodedAttrs = this.decodeAttributes({ node: { ...node, attrs: node.attrs.floatingTableProperties || {} } });
38796
+ return Object.keys(decodedAttrs).length > 0 ? { attributes: decodedAttrs } : void 0;
38797
+ }
38798
+ });
38799
+ const propertyTranslators$2 = [
38800
+ translator$15,
38801
+ translator$13,
38802
+ translator$11,
38803
+ translator$10,
38804
+ translator$$,
38805
+ translator$Z,
38806
+ translator$X,
38807
+ translator$V
38808
+ ];
38809
+ const translator$d = NodeTranslator.from(
38810
+ createNestedPropertiesTranslator("w:tblBorders", "borders", propertyTranslators$2)
38811
+ );
38812
+ const propertyTranslators$1 = [
38813
+ translator$14,
38814
+ translator$12,
38815
+ translator$_,
38816
+ translator$Y,
38817
+ translator$W,
38818
+ translator$U
38819
+ ];
38820
+ const translator$c = NodeTranslator.from(
38821
+ createNestedPropertiesTranslator("w:tblCellMar", "cellMargins", propertyTranslators$1)
38822
+ );
38823
+ const propertyTranslators = [
38824
+ translator$p,
38825
+ translator$B,
38826
+ translator$19,
38827
+ translator$o,
38828
+ translator$A,
38829
+ translator$n,
38830
+ translator$m,
38831
+ translator$l,
38832
+ translator$k,
38833
+ translator$j,
38834
+ translator$i,
38835
+ translator$h,
38836
+ translator$g,
38837
+ translator$f,
38838
+ translator$e,
38839
+ translator$d,
38840
+ translator$c
38841
+ ];
38842
+ const translator$b = NodeTranslator.from(
38843
+ createNestedPropertiesTranslator("w:tblPr", "tableProperties", propertyTranslators)
38844
+ );
38845
+ const translator$a = NodeTranslator.from(
38846
+ createSingleAttrPropertyHandler("w:gridCol", "col", "w:w", parseInteger, integerToString)
38847
+ );
38848
+ const DEFAULT_COLUMN_WIDTH_PX = 100;
38849
+ const normalizeTwipWidth = (value) => {
38850
+ if (value == null) return null;
38851
+ const numericValue = typeof value === "string" ? parseInt(value, 10) : value;
38852
+ if (!Number.isFinite(numericValue) || Number.isNaN(numericValue) || numericValue <= 0) {
38853
+ return null;
38854
+ }
38855
+ return numericValue;
38856
+ };
38857
+ const getSchemaDefaultColumnWidthPx = (params2) => {
38858
+ const defaultValue = params2?.editor?.schema?.nodes?.tableCell?.spec?.attrs?.colwidth?.default;
38859
+ if (Array.isArray(defaultValue)) {
38860
+ const numericWidth = defaultValue.find((width) => typeof width === "number" && Number.isFinite(width) && width > 0);
38861
+ if (numericWidth != null) return numericWidth;
38862
+ } else if (typeof defaultValue === "number" && Number.isFinite(defaultValue) && defaultValue > 0) {
38863
+ return defaultValue;
38864
+ }
38865
+ return DEFAULT_COLUMN_WIDTH_PX;
38866
+ };
38867
+ const getTableWidthPx = (params2) => {
38868
+ const explicitWidth = params2?.node?.attrs?.tableWidth?.width;
38869
+ if (typeof explicitWidth === "number" && explicitWidth > 0) return explicitWidth;
38870
+ const tableWidth = params2?.node?.attrs?.tableProperties?.tableWidth;
38871
+ if (tableWidth?.value != null && typeof tableWidth.value === "number" && tableWidth.value > 0) {
38872
+ const { value, type: type2 } = tableWidth;
38873
+ if (!type2 || type2 === "auto" || type2 === "dxa") {
38874
+ return twipsToPixels(value);
38875
+ }
38876
+ }
38877
+ return null;
38878
+ };
38879
+ const resolveFallbackColumnWidthTwips = (params2, totalColumns, cellMinWidthTwips) => {
38880
+ const columnCount = Math.max(totalColumns, 1);
38881
+ const defaultColumnWidthPx = getSchemaDefaultColumnWidthPx(params2);
38882
+ const tableWidthPx = getTableWidthPx(params2);
38883
+ const safeDefaultPx = Number.isFinite(defaultColumnWidthPx) && defaultColumnWidthPx > 0 ? defaultColumnWidthPx : DEFAULT_COLUMN_WIDTH_PX;
38884
+ let fallbackWidthPx = safeDefaultPx;
38885
+ if (typeof tableWidthPx === "number" && tableWidthPx > 0) {
38886
+ fallbackWidthPx = tableWidthPx / columnCount;
38887
+ }
38888
+ const fallbackWidthTwips = pixelsToTwips(fallbackWidthPx);
38889
+ if (!Number.isFinite(fallbackWidthTwips) || Number.isNaN(fallbackWidthTwips) || fallbackWidthTwips <= 0) {
38890
+ const safeDefault = Math.max(pixelsToTwips(safeDefaultPx), cellMinWidthTwips);
38891
+ return safeDefault;
38892
+ }
38893
+ return Math.max(fallbackWidthTwips, cellMinWidthTwips);
38894
+ };
38895
+ const XML_NODE_NAME$a = "w:tblGrid";
38896
+ const SD_ATTR_KEY$2 = "grid";
38897
+ const cellMinWidth = pixelsToTwips(10);
38898
+ const encode$g = (params2) => {
38899
+ const { nodes } = params2;
38900
+ const node = nodes[0];
38901
+ const attributes = encodeProperties(node, { [translator$a.xmlName]: translator$a }, true);
38902
+ return {
38903
+ xmlName: XML_NODE_NAME$a,
38904
+ sdNodeOrKeyName: SD_ATTR_KEY$2,
38905
+ attributes
38906
+ };
38907
+ };
38908
+ const decode$i = (params2) => {
38909
+ const { grid: rawGrid } = params2.node.attrs || {};
38910
+ const grid = Array.isArray(rawGrid) ? rawGrid : [];
38911
+ const { firstRow = {} } = params2.extraParams || {};
38912
+ const cellNodes = firstRow.content?.filter((n) => n.type === "tableCell") ?? [];
38913
+ const columnCountFromCells = cellNodes.reduce((count, cell) => {
38914
+ const spanCount = Math.max(1, cell?.attrs?.colspan ?? 1);
38915
+ return count + spanCount;
38916
+ }, 0);
38917
+ const totalColumns = Math.max(columnCountFromCells, grid.length);
38918
+ const fallbackColumnWidthTwips = resolveFallbackColumnWidthTwips(params2, totalColumns, cellMinWidth);
38919
+ const elements = [];
38920
+ let columnIndex = 0;
38921
+ const pushColumn = (widthTwips, { enforceMinimum = false } = {}) => {
38922
+ let numericWidth = typeof widthTwips === "string" ? parseInt(widthTwips, 10) : widthTwips;
38923
+ let shouldEnforceMinimum = enforceMinimum;
38924
+ if (numericWidth == null || Number.isNaN(numericWidth) || numericWidth <= 0) {
38925
+ numericWidth = fallbackColumnWidthTwips;
38926
+ shouldEnforceMinimum = true;
38927
+ }
38928
+ const roundedWidth = Math.round(numericWidth);
38929
+ const minimumWidth = shouldEnforceMinimum ? cellMinWidth : 1;
38930
+ const safeWidth = Math.max(roundedWidth, minimumWidth);
38931
+ const decoded = translator$a.decode({
38932
+ node: { type: (
38933
+ /** @type {string} */
38934
+ translator$a.sdNodeOrKeyName
38935
+ ), attrs: { col: safeWidth } }
38936
+ });
38937
+ if (decoded) elements.push(decoded);
38938
+ };
38939
+ cellNodes.forEach((cell) => {
38940
+ const { colspan = 1, colwidth } = cell?.attrs || {};
38941
+ const spanCount = Math.max(1, colspan);
38942
+ for (let span = 0; span < spanCount; span++) {
38943
+ const rawWidth = Array.isArray(colwidth) ? colwidth[span] : void 0;
38944
+ const cellWidthPixels = typeof rawWidth === "number" && Number.isFinite(rawWidth) ? rawWidth : Number(rawWidth);
38945
+ const hasCellWidth = Number.isFinite(cellWidthPixels) && cellWidthPixels > 0;
38946
+ const colGridAttrs = grid?.[columnIndex] || {};
38947
+ const gridWidthTwips = normalizeTwipWidth(colGridAttrs.col);
38948
+ const gridWidthPixels = gridWidthTwips != null ? twipsToPixels(gridWidthTwips) : null;
38949
+ let cellWidthTwips;
38950
+ let enforceMinimum = false;
38951
+ if (hasCellWidth) {
38952
+ const tolerance = 0.5;
38953
+ if (gridWidthTwips != null && gridWidthPixels != null && Math.abs(gridWidthPixels - cellWidthPixels) <= tolerance) {
38954
+ cellWidthTwips = gridWidthTwips;
38955
+ } else {
38956
+ cellWidthTwips = pixelsToTwips(cellWidthPixels);
38957
+ }
38958
+ } else if (gridWidthTwips != null) {
38959
+ cellWidthTwips = gridWidthTwips;
38960
+ } else {
38961
+ cellWidthTwips = fallbackColumnWidthTwips;
38962
+ enforceMinimum = true;
38963
+ }
38964
+ pushColumn(cellWidthTwips, { enforceMinimum });
38965
+ columnIndex++;
38966
+ }
38967
+ });
38968
+ while (columnIndex < grid.length) {
38969
+ const gridWidthTwips = normalizeTwipWidth(grid[columnIndex]?.col);
38970
+ pushColumn(gridWidthTwips);
38971
+ columnIndex++;
38972
+ }
38973
+ const newNode = {
38974
+ name: XML_NODE_NAME$a,
38975
+ attributes: {},
38976
+ elements
38977
+ };
38978
+ return newNode;
38979
+ };
38980
+ const config$9 = {
38981
+ xmlName: XML_NODE_NAME$a,
38982
+ sdNodeOrKeyName: SD_ATTR_KEY$2,
38983
+ encode: encode$g,
38984
+ decode: decode$i
38985
+ };
38986
+ const translator$9 = NodeTranslator.from(config$9);
38987
+ const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
38988
+ const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
38989
+ const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
38990
+ const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
38991
+ const pctToPercent = (value) => {
38992
+ if (value == null) return null;
38993
+ return value / 50;
38994
+ };
38995
+ const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
38996
+ const resolveMeasurementWidthPx = (measurement) => {
38997
+ if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
38998
+ const { value, type: type2 } = measurement;
38999
+ if (!type2 || type2 === "auto") return null;
39000
+ if (type2 === "dxa") return twipsToPixels(value);
39001
+ if (type2 === "pct") {
39002
+ const percent2 = pctToPercent(value);
39003
+ if (percent2 == null || percent2 <= 0) return null;
39004
+ const widthTwips = resolveContentWidthTwips() * percent2 / 100;
39005
+ return twipsToPixels(widthTwips);
39006
+ }
39007
+ return null;
39008
+ };
39009
+ const countColumnsInRow = (row) => {
39010
+ if (!row?.elements?.length) return 0;
39011
+ return row.elements.reduce((count, element) => {
39012
+ if (element.name !== "w:tc") return count;
39013
+ const tcPr = element.elements?.find((el) => el.name === "w:tcPr");
39014
+ const gridSpan = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
39015
+ const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
39016
+ return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
39017
+ }, 0);
39018
+ };
39019
+ const clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
39020
+ const createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
39021
+ const buildFallbackGridForTable = ({ params: params2, rows, tableWidth, tableWidthMeasurement }) => {
39022
+ const firstRow = rows.find((row) => row.elements?.some((el) => el.name === "w:tc"));
39023
+ const columnCount = countColumnsInRow(firstRow);
39024
+ if (!columnCount) return null;
39025
+ const schemaDefaultPx = getSchemaDefaultColumnWidthPx(
39026
+ /** @type {any} */
39027
+ params2
39028
+ );
39029
+ const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : DEFAULT_COLUMN_WIDTH_PX;
39030
+ let totalWidthPx;
39031
+ if (tableWidthMeasurement) {
39032
+ const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
39033
+ if (resolved != null) totalWidthPx = resolved;
39034
+ }
39035
+ if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) {
39036
+ totalWidthPx = tableWidth.width;
39037
+ }
39038
+ if (totalWidthPx == null) {
39039
+ totalWidthPx = minimumColumnWidthPx * columnCount;
39040
+ }
39041
+ const rawColumnWidthPx = Math.max(totalWidthPx / columnCount, minimumColumnWidthPx);
39042
+ const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(rawColumnWidthPx));
39043
+ const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
39081
39044
  return {
39082
- name: "w:hyperlink",
39083
- type: "element",
39084
- attributes: {
39085
- "r:id": newId,
39086
- "w:history": 1
39087
- },
39088
- elements: [contentNode]
39045
+ grid: createFallbackGrid(columnCount, columnWidthTwips),
39046
+ columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
39089
39047
  };
39090
- }
39091
- function translateFieldAttrsToMarks(attrs = {}) {
39092
- const { fontFamily: fontFamily2, fontSize: fontSize2, bold, underline, italic, textColor, textHighlight } = attrs;
39093
- const marks = [];
39094
- if (fontFamily2) marks.push({ type: "fontFamily", attrs: { fontFamily: fontFamily2 } });
39095
- if (fontSize2) marks.push({ type: "fontSize", attrs: { fontSize: fontSize2 } });
39096
- if (bold) marks.push({ type: "bold", attrs: {} });
39097
- if (underline) marks.push({ type: "underline", attrs: {} });
39098
- if (italic) marks.push({ type: "italic", attrs: {} });
39099
- if (textColor) marks.push({ type: "color", attrs: { color: textColor } });
39100
- if (textHighlight) marks.push({ type: "highlight", attrs: { color: textHighlight } });
39101
- return marks;
39102
- }
39103
- function applyMarksToHtmlAnnotation(state2, marks) {
39104
- const { tr, doc: doc2, schema } = state2;
39105
- const allowedMarks = ["fontFamily", "fontSize", "highlight"];
39106
- if (!marks.some((m2) => allowedMarks.includes(m2.type))) {
39107
- return state2;
39048
+ };
39049
+ const XML_NODE_NAME$9 = "w:tbl";
39050
+ const SD_NODE_NAME$7 = "table";
39051
+ const encode$f = (params2, encodedAttrs) => {
39052
+ const { nodes } = params2;
39053
+ const node = nodes[0];
39054
+ const tblPr = node.elements.find((el) => el.name === "w:tblPr");
39055
+ if (tblPr) {
39056
+ const encodedProperties = translator$b.encode({ ...params2, nodes: [tblPr] });
39057
+ encodedAttrs["tableProperties"] = encodedProperties || {};
39108
39058
  }
39109
- const fontFamily2 = marks.find((m2) => m2.type === "fontFamily");
39110
- const fontSize2 = marks.find((m2) => m2.type === "fontSize");
39111
- const highlight = marks.find((m2) => m2.type === "highlight");
39112
- const textStyleType = schema.marks.textStyle;
39113
- const highlightType = schema.marks.highlight;
39114
- doc2.descendants((node, pos) => {
39115
- if (!node.isText) return;
39116
- const foundTextStyle = node.marks.find((m2) => m2.type.name === "textStyle");
39117
- const foundHighlight = node.marks.find((m2) => m2.type.name === "highlight");
39118
- if (!foundTextStyle) {
39119
- tr.addMark(
39120
- pos,
39121
- pos + node.nodeSize,
39122
- textStyleType.create({
39123
- ...fontFamily2?.attrs,
39124
- ...fontSize2?.attrs
39125
- })
39126
- );
39127
- } else if (!foundTextStyle?.attrs.fontFamily && fontFamily2) {
39128
- tr.addMark(
39129
- pos,
39130
- pos + node.nodeSize,
39131
- textStyleType.create({
39132
- ...foundTextStyle?.attrs,
39133
- ...fontFamily2.attrs
39134
- })
39135
- );
39136
- } else if (!foundTextStyle?.attrs.fontSize && fontSize2) {
39137
- tr.addMark(
39138
- pos,
39139
- pos + node.nodeSize,
39140
- textStyleType.create({
39141
- ...foundTextStyle?.attrs,
39142
- ...fontSize2.attrs
39143
- })
39144
- );
39059
+ const tblGrid = node.elements.find((el) => el.name === "w:tblGrid");
39060
+ if (tblGrid) {
39061
+ encodedAttrs["grid"] = translator$9.encode({ ...params2, nodes: [tblGrid] }).attributes;
39062
+ }
39063
+ [
39064
+ "tableStyleId",
39065
+ "justification",
39066
+ "tableLayout",
39067
+ ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
39068
+ ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
39069
+ ].forEach((prop) => {
39070
+ let key2;
39071
+ let transform;
39072
+ if (Array.isArray(prop)) {
39073
+ [key2, transform] = prop;
39074
+ } else {
39075
+ key2 = prop;
39076
+ transform = (v2) => v2;
39145
39077
  }
39146
- if (!foundHighlight) {
39147
- tr.addMark(
39148
- pos,
39149
- pos + node.nodeSize,
39150
- highlightType.create({
39151
- ...highlight?.attrs
39152
- })
39153
- );
39078
+ if (encodedAttrs.tableProperties && encodedAttrs.tableProperties[key2]) {
39079
+ encodedAttrs[key2] = transform(encodedAttrs.tableProperties[key2]);
39154
39080
  }
39155
39081
  });
39156
- return state2.apply(tr);
39157
- }
39158
- function getFieldHighlightJson(fieldsHighlightColor) {
39159
- if (!fieldsHighlightColor) return null;
39160
- let parsedColor = fieldsHighlightColor.trim();
39161
- const hexRegex2 = /^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/;
39162
- if (!hexRegex2.test(parsedColor)) {
39163
- console.warn(`Invalid HEX color provided to fieldsHighlightColor export param: ${fieldsHighlightColor}`);
39164
- return null;
39082
+ if (encodedAttrs.tableCellSpacing) {
39083
+ encodedAttrs["borderCollapse"] = "separate";
39165
39084
  }
39166
- if (parsedColor.startsWith("#")) {
39167
- parsedColor = parsedColor.slice(1);
39085
+ if (encodedAttrs.tableProperties?.tableWidth) {
39086
+ const tableWidthMeasurement = encodedAttrs.tableProperties.tableWidth;
39087
+ const widthPx = twipsToPixels(tableWidthMeasurement.value);
39088
+ if (widthPx != null) {
39089
+ encodedAttrs.tableWidth = {
39090
+ width: widthPx,
39091
+ type: tableWidthMeasurement.type
39092
+ };
39093
+ } else if (tableWidthMeasurement.type === "auto") {
39094
+ encodedAttrs.tableWidth = {
39095
+ width: 0,
39096
+ type: tableWidthMeasurement.type
39097
+ };
39098
+ }
39168
39099
  }
39169
- return {
39170
- name: "w:rPr",
39171
- elements: [
39172
- {
39173
- name: "w:shd",
39174
- attributes: {
39175
- "w:fill": `#${parsedColor}`,
39176
- "w:color": "auto",
39177
- "w:val": "clear"
39100
+ const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
39101
+ const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params2);
39102
+ if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
39103
+ encodedAttrs.tableProperties = {
39104
+ ...encodedAttrs.tableProperties || {},
39105
+ cellMargins: referencedStyles.cellMargins
39106
+ };
39107
+ }
39108
+ const rows = node.elements.filter((el) => el.name === "w:tr");
39109
+ const borderData = Object.assign({}, referencedStyles?.borders || {}, borders || {});
39110
+ const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
39111
+ encodedAttrs["borders"] = borderData;
39112
+ let columnWidths = Array.isArray(encodedAttrs["grid"]) ? encodedAttrs["grid"].map((item) => twipsToPixels(item.col)) : [];
39113
+ if (!columnWidths.length) {
39114
+ const fallback = buildFallbackGridForTable({
39115
+ params: params2,
39116
+ rows,
39117
+ tableWidth: encodedAttrs.tableWidth,
39118
+ tableWidthMeasurement: encodedAttrs.tableProperties?.tableWidth
39119
+ });
39120
+ if (fallback) {
39121
+ encodedAttrs.grid = fallback.grid;
39122
+ columnWidths = fallback.columnWidths;
39123
+ }
39124
+ }
39125
+ const content = [];
39126
+ const totalColumns = columnWidths.length;
39127
+ const activeRowSpans = totalColumns > 0 ? new Array(totalColumns).fill(0) : [];
39128
+ rows.forEach((row, rowIndex) => {
39129
+ const result = translator$u.encode({
39130
+ ...params2,
39131
+ nodes: [row],
39132
+ extraParams: {
39133
+ row,
39134
+ table: node,
39135
+ rowBorders: borderRowData,
39136
+ columnWidths,
39137
+ activeRowSpans: activeRowSpans.slice(),
39138
+ rowIndex,
39139
+ _referencedStyles: referencedStyles
39140
+ }
39141
+ });
39142
+ if (result) {
39143
+ content.push(result);
39144
+ if (totalColumns > 0) {
39145
+ const activeRowSpansForCurrentRow = activeRowSpans.slice();
39146
+ for (let col = 0; col < totalColumns; col++) {
39147
+ if (activeRowSpans[col] > 0) {
39148
+ activeRowSpans[col] -= 1;
39149
+ }
39178
39150
  }
39151
+ let columnIndex = 0;
39152
+ const advanceColumnIndex = () => {
39153
+ while (columnIndex < totalColumns && activeRowSpansForCurrentRow[columnIndex] > 0) {
39154
+ columnIndex += 1;
39155
+ }
39156
+ };
39157
+ advanceColumnIndex();
39158
+ result.content?.forEach((cell) => {
39159
+ advanceColumnIndex();
39160
+ const colspan = Math.max(1, cell.attrs?.colspan || 1);
39161
+ const rowspan = Math.max(1, cell.attrs?.rowspan || 1);
39162
+ if (rowspan > 1) {
39163
+ for (let offset2 = 0; offset2 < colspan && columnIndex + offset2 < totalColumns; offset2++) {
39164
+ const targetIndex = columnIndex + offset2;
39165
+ const remainingRows = rowspan - 1;
39166
+ if (remainingRows > 0 && remainingRows > activeRowSpans[targetIndex]) {
39167
+ activeRowSpans[targetIndex] = remainingRows;
39168
+ }
39169
+ }
39170
+ }
39171
+ columnIndex += colspan;
39172
+ advanceColumnIndex();
39173
+ });
39179
39174
  }
39180
- ]
39175
+ }
39176
+ });
39177
+ return {
39178
+ type: "table",
39179
+ content,
39180
+ attrs: encodedAttrs
39181
39181
  };
39182
- }
39183
- function translateDocumentSection(params2) {
39182
+ };
39183
+ const decode$h = (params2, decodedAttrs) => {
39184
+ params2.node = preProcessVerticalMergeCells(params2.node, params2);
39184
39185
  const { node } = params2;
39185
- const { attrs = {} } = node;
39186
- const childContent = translateChildNodes({ ...params2, nodes: node.content });
39187
- const nodeElements = [
39188
- {
39189
- name: "w:sdtContent",
39190
- elements: childContent
39186
+ const elements = translateChildNodes(params2);
39187
+ const firstRow = node.content?.find((n) => n.type === "tableRow");
39188
+ const properties = node.attrs.grid;
39189
+ const element = translator$9.decode({
39190
+ ...params2,
39191
+ node: { ...node, attrs: { ...node.attrs, grid: properties } },
39192
+ extraParams: {
39193
+ firstRow
39191
39194
  }
39192
- ];
39193
- const exportedTag = JSON.stringify({
39194
- type: "documentSection",
39195
- description: attrs.description
39196
39195
  });
39197
- const sdtPr = generateSdtPrTagForDocumentSection(attrs.id, attrs.title, exportedTag);
39198
- const { isLocked } = attrs;
39199
- if (isLocked) {
39200
- sdtPr.elements.push({
39201
- name: "w:lock",
39202
- attributes: {
39203
- "w:val": "sdtContentLocked"
39204
- }
39196
+ if (element) elements.unshift(element);
39197
+ if (node.attrs?.tableProperties) {
39198
+ const properties2 = { ...node.attrs.tableProperties };
39199
+ const element2 = translator$b.decode({
39200
+ ...params2,
39201
+ node: { ...node, attrs: { ...node.attrs, tableProperties: properties2 } }
39205
39202
  });
39203
+ if (element2) elements.unshift(element2);
39206
39204
  }
39207
- nodeElements.unshift(sdtPr);
39208
- const result = {
39209
- name: "w:sdt",
39210
- elements: nodeElements
39211
- };
39212
- return result;
39213
- }
39214
- const generateSdtPrTagForDocumentSection = (id, title, tag) => {
39215
39205
  return {
39216
- name: "w:sdtPr",
39217
- elements: [
39218
- {
39219
- name: "w:id",
39220
- attributes: {
39221
- "w:val": id
39222
- }
39223
- },
39224
- {
39225
- name: "w:alias",
39226
- attributes: {
39227
- "w:val": title
39228
- }
39229
- },
39230
- {
39231
- name: "w:tag",
39232
- attributes: {
39233
- "w:val": tag
39234
- }
39235
- }
39236
- ]
39206
+ name: "w:tbl",
39207
+ attributes: decodedAttrs || {},
39208
+ elements
39237
39209
  };
39238
39210
  };
39239
- function translateDocumentPartObj(params2) {
39240
- const { node } = params2;
39241
- const { attrs = {} } = node;
39242
- const childContent = translateChildNodes({ ...params2, nodes: node.content });
39243
- const nodeElements = [
39244
- {
39245
- name: "w:sdtPr",
39246
- elements: [
39247
- {
39248
- name: "w:id",
39249
- attributes: {
39250
- "w:val": attrs.id
39251
- }
39252
- },
39253
- {
39254
- name: "w:docPartObj",
39255
- elements: [
39256
- {
39257
- name: "w:docPartGallery",
39258
- attributes: {
39259
- "w:val": attrs.docPartGallery
39260
- }
39261
- },
39262
- ...attrs.docPartUnique ? [
39263
- {
39264
- name: "w:docPartUnique"
39265
- }
39266
- ] : []
39267
- ]
39268
- }
39269
- ]
39270
- },
39271
- {
39272
- name: "w:sdtContent",
39273
- elements: childContent
39274
- }
39275
- ];
39276
- const result = {
39277
- name: "w:sdt",
39278
- elements: nodeElements
39279
- };
39280
- return result;
39281
- }
39282
- function translateStructuredContent(params2) {
39283
- const { node } = params2;
39284
- const childContent = translateChildNodes({ ...params2, nodes: node.content });
39285
- const sdtContent = { name: "w:sdtContent", elements: childContent };
39286
- const sdtPr = generateSdtPrTagForStructuredContent({ node });
39287
- const nodeElements = [sdtPr, sdtContent];
39288
- const result = {
39289
- name: "w:sdt",
39290
- elements: nodeElements
39211
+ function _processTableBorders(rawBorders) {
39212
+ const borders = {};
39213
+ const rowBorders = {};
39214
+ Object.entries(rawBorders).forEach(([name, attributes]) => {
39215
+ const attrs = {};
39216
+ const color = attributes.color;
39217
+ const size2 = attributes.size;
39218
+ if (color && color !== "auto") attrs["color"] = color.startsWith("#") ? color : `#${color}`;
39219
+ if (size2 && size2 !== "auto") attrs["size"] = eighthPointsToPixels(size2);
39220
+ const rowBorderNames = ["insideH", "insideV"];
39221
+ if (rowBorderNames.includes(name)) rowBorders[name] = attrs;
39222
+ borders[name] = attrs;
39223
+ });
39224
+ return {
39225
+ borders,
39226
+ rowBorders
39291
39227
  };
39292
- return result;
39293
39228
  }
39294
- function generateSdtPrTagForStructuredContent({ node }) {
39295
- const { attrs = {} } = node;
39296
- const id = {
39297
- name: "w:id",
39298
- type: "element",
39299
- attributes: { "w:val": attrs.id }
39300
- };
39301
- const alias = {
39302
- name: "w:alias",
39303
- type: "element",
39304
- attributes: { "w:val": attrs.alias }
39305
- };
39306
- const tag = {
39307
- name: "w:tag",
39308
- type: "element",
39309
- attributes: { "w:val": attrs.tag }
39310
- };
39311
- const resultElements = [];
39312
- if (attrs.id) resultElements.push(id);
39313
- if (attrs.alias) resultElements.push(alias);
39314
- if (attrs.tag) resultElements.push(tag);
39315
- if (attrs.sdtPr) {
39316
- const elements = attrs.sdtPr.elements || [];
39317
- const elementsToExclude = ["w:id", "w:alias", "w:tag"];
39318
- const restElements = elements.filter((el) => !elementsToExclude.includes(el.name));
39319
- const result2 = {
39320
- name: "w:sdtPr",
39321
- type: "element",
39322
- elements: [...resultElements, ...restElements]
39323
- };
39324
- return result2;
39229
+ function _getReferencedTableStyles(tableStyleReference, params2) {
39230
+ if (!tableStyleReference) return null;
39231
+ const stylesToReturn = {};
39232
+ const { docx } = params2;
39233
+ const styles = docx["word/styles.xml"];
39234
+ const { elements } = styles.elements[0];
39235
+ const styleElements = elements.filter((el) => el.name === "w:style");
39236
+ const styleTag = styleElements.find((el) => el.attributes["w:styleId"] === tableStyleReference);
39237
+ if (!styleTag) return null;
39238
+ stylesToReturn.name = styleTag.elements.find((el) => el.name === "w:name");
39239
+ const basedOn = styleTag.elements.find((el) => el.name === "w:basedOn");
39240
+ let baseTblPr;
39241
+ if (basedOn?.attributes) {
39242
+ const baseStyles = styleElements.find((el) => el.attributes["w:styleId"] === basedOn.attributes["w:val"]);
39243
+ baseTblPr = baseStyles ? baseStyles.elements.find((el) => el.name === "w:tblPr") : {};
39325
39244
  }
39326
- const result = {
39327
- name: "w:sdtPr",
39328
- type: "element",
39329
- elements: resultElements
39330
- };
39331
- return result;
39332
- }
39333
- const XML_NODE_NAME$9 = "w:sdt";
39334
- const SD_NODE_NAME$7 = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
39335
- const validXmlAttributes$6 = [];
39336
- function encode$f(params2) {
39337
- const nodes = params2.nodes;
39338
- const node = nodes[0];
39339
- const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
39340
- if (!handler2 || sdtType === "unknown") {
39341
- return void 0;
39245
+ const pPr = styleTag.elements.find((el) => el.name === "w:pPr");
39246
+ if (pPr) {
39247
+ const justification = pPr.elements.find((el) => el.name === "w:jc");
39248
+ if (justification?.attributes) stylesToReturn.justification = justification.attributes["w:val"];
39342
39249
  }
39343
- const result = handler2(params2);
39344
- return result;
39345
- }
39346
- function decode$h(params2) {
39347
- const { node } = params2;
39348
- if (!node || !node.type) {
39349
- return null;
39250
+ const rPr = styleTag?.elements.find((el) => el.name === "w:rPr");
39251
+ if (rPr) {
39252
+ const fonts = rPr.elements.find((el) => el.name === "w:rFonts");
39253
+ if (fonts) {
39254
+ const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
39255
+ stylesToReturn.fonts = { ascii, hAnsi, cs };
39256
+ }
39257
+ const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
39258
+ if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
39350
39259
  }
39351
- const types2 = {
39352
- fieldAnnotation: () => translateFieldAnnotation(params2),
39353
- structuredContent: () => translateStructuredContent(params2),
39354
- structuredContentBlock: () => translateStructuredContent(params2),
39355
- documentSection: () => translateDocumentSection(params2),
39356
- documentPartObject: () => translateDocumentPartObj(params2),
39357
- // Handled in doc-part-obj translator
39358
- default: () => null
39359
- };
39360
- const decoder = types2[node.type] ?? types2.default;
39361
- const result = decoder();
39362
- return result;
39260
+ const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
39261
+ if (tblPr && tblPr.elements) {
39262
+ if (baseTblPr && baseTblPr.elements) {
39263
+ tblPr.elements.push(...baseTblPr.elements);
39264
+ }
39265
+ const tableProperties = translator$b.encode({ ...params2, nodes: [tblPr] });
39266
+ if (tableProperties) {
39267
+ const { borders, rowBorders } = _processTableBorders(tableProperties.borders || {});
39268
+ if (borders) stylesToReturn.borders = borders;
39269
+ if (rowBorders) stylesToReturn.rowBorders = rowBorders;
39270
+ const cellMargins = {};
39271
+ Object.entries(tableProperties.cellMargins || {}).forEach(([key2, attrs]) => {
39272
+ if (attrs?.value != null) {
39273
+ cellMargins[key2] = {
39274
+ value: attrs.value,
39275
+ type: attrs.type || "dxa"
39276
+ };
39277
+ }
39278
+ });
39279
+ if (Object.keys(cellMargins).length) stylesToReturn.cellMargins = cellMargins;
39280
+ }
39281
+ }
39282
+ return stylesToReturn;
39363
39283
  }
39364
39284
  const config$8 = {
39365
39285
  xmlName: XML_NODE_NAME$9,
@@ -39367,7 +39287,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
39367
39287
  type: NodeTranslator.translatorTypes.NODE,
39368
39288
  encode: encode$f,
39369
39289
  decode: decode$h,
39370
- attributes: validXmlAttributes$6
39290
+ attributes: []
39371
39291
  };
39372
39292
  const translator$8 = NodeTranslator.from(config$8);
39373
39293
  const encode$e = (attributes) => {
@@ -39882,7 +39802,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
39882
39802
  if (mainNode.name === "w:drawing") node = mainNode;
39883
39803
  else node = mainNode.elements.find((el) => el.name === "w:drawing");
39884
39804
  if (!node) return { nodes: [], consumed: 0 };
39885
- const schemaNode = translator$9.encode(params2);
39805
+ const schemaNode = translator$r.encode(params2);
39886
39806
  const newNodes = schemaNode ? [schemaNode] : [];
39887
39807
  return { nodes: newNodes, consumed: 1 };
39888
39808
  };
@@ -40191,7 +40111,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
40191
40111
  if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
40192
40112
  return { nodes: [], consumed: 0 };
40193
40113
  }
40194
- const result = translator$8.encode(params2);
40114
+ const result = translator$q.encode(params2);
40195
40115
  if (!result) {
40196
40116
  return { nodes: [], consumed: 0 };
40197
40117
  }
@@ -40958,6 +40878,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
40958
40878
  handlerName: "w:tabTranslator",
40959
40879
  handler: handleTabNode
40960
40880
  };
40881
+ const tableNodeHandlerEntity = generateV2HandlerEntity("tableNodeHandler", translator$8);
40961
40882
  const tableOfContentsHandlerEntity = generateV2HandlerEntity("tableOfContentsHandler", translator$4);
40962
40883
  function preProcessPageInstruction(nodesToCombine) {
40963
40884
  const pageNumNode = {
@@ -41967,14 +41888,14 @@ Please report this to https://github.com/markedjs/marked.`, e) {
41967
41888
  bulletList: translateList,
41968
41889
  orderedList: translateList,
41969
41890
  lineBreak: translator$1r,
41970
- table: translator$s,
41971
- tableRow: translator$Z,
41972
- tableCell: translator$c,
41891
+ table: translator$8,
41892
+ tableRow: translator$u,
41893
+ tableCell: translator$H,
41973
41894
  bookmarkStart: translator$7,
41974
41895
  bookmarkEnd: translator$6,
41975
- fieldAnnotation: translator$8,
41896
+ fieldAnnotation: translator$q,
41976
41897
  tab: translator$1p,
41977
- image: translator$9,
41898
+ image: translator$r,
41978
41899
  hardBreak: translator$1r,
41979
41900
  commentRangeStart: commentRangeStartTranslator,
41980
41901
  commentRangeEnd: commentRangeEndTranslator,
@@ -41983,10 +41904,10 @@ Please report this to https://github.com/markedjs/marked.`, e) {
41983
41904
  shapeTextbox: translator,
41984
41905
  contentBlock: translator,
41985
41906
  vectorShape: translateVectorShape,
41986
- structuredContent: translator$8,
41987
- structuredContentBlock: translator$8,
41988
- documentPartObject: translator$8,
41989
- documentSection: translator$8,
41907
+ structuredContent: translator$q,
41908
+ structuredContentBlock: translator$q,
41909
+ documentPartObject: translator$q,
41910
+ documentSection: translator$q,
41990
41911
  "page-number": translatePageNumberNode,
41991
41912
  "total-page-number": translateTotalPageNumberNode,
41992
41913
  pageReference: translator$5,
@@ -99553,86 +99474,86 @@ ${style2}
99553
99474
  "sd:pageReference": translator$5,
99554
99475
  "sd:tableOfContents": translator$4,
99555
99476
  "w:b": translator$1n,
99556
- "w:bidiVisual": translator$Y,
99477
+ "w:bidiVisual": translator$p,
99557
99478
  "w:bookmarkEnd": translator$6,
99558
99479
  "w:bookmarkStart": translator$7,
99559
- "w:bottom": translator$L,
99480
+ "w:bottom": translator$15,
99560
99481
  "w:br": translator$1r,
99561
- "w:cantSplit": translator$1a,
99562
- "w:cnfStyle": translator$19,
99482
+ "w:cantSplit": translator$G,
99483
+ "w:cnfStyle": translator$1a,
99563
99484
  "w:color": translator$1j,
99564
- "w:divId": translator$18,
99565
- "w:drawing": translator$9,
99566
- "w:end": translator$J,
99567
- "w:gridAfter": translator$17,
99568
- "w:gridBefore": translator$16,
99569
- "w:gridCol": translator$u,
99570
- "w:hidden": translator$15,
99485
+ "w:divId": translator$F,
99486
+ "w:drawing": translator$r,
99487
+ "w:end": translator$13,
99488
+ "w:gridAfter": translator$E,
99489
+ "w:gridBefore": translator$D,
99490
+ "w:gridCol": translator$a,
99491
+ "w:hidden": translator$C,
99571
99492
  "w:highlight": translator$1q,
99572
99493
  "w:hyperlink": translator$1c,
99573
99494
  "w:i": translator$1m,
99574
- "w:insideH": translator$H,
99575
- "w:insideV": translator$G,
99576
- "w:jc": translator$14,
99577
- "w:left": translator$F,
99495
+ "w:insideH": translator$11,
99496
+ "w:insideV": translator$10,
99497
+ "w:jc": translator$B,
99498
+ "w:left": translator$$,
99578
99499
  "w:p": translator$1o,
99579
99500
  "w:r": translator$1b,
99580
99501
  "w:rFonts": translator$1i,
99581
99502
  "w:rPr": translator$1d,
99582
99503
  "w:rStyle": translator$1h,
99583
- "w:right": translator$D,
99584
- "w:sdt": translator$8,
99585
- "w:shd": translator$X,
99586
- "w:start": translator$B,
99504
+ "w:right": translator$Z,
99505
+ "w:sdt": translator$q,
99506
+ "w:shd": translator$19,
99507
+ "w:start": translator$X,
99587
99508
  "w:strike": translator$1k,
99588
99509
  "w:sz": translator$1g,
99589
99510
  "w:szCs": translator$1f,
99590
99511
  "w:tab": translator$1p,
99591
- "w:tbl": translator$s,
99592
- "w:tblBorders": translator$x,
99593
- "w:tblCaption": translator$W,
99594
- "w:tblCellMar": translator$w,
99595
- "w:tblCellSpacing": translator$13,
99596
- "w:tblDescription": translator$V,
99597
- "w:tblGrid": translator$t,
99598
- "w:tblHeader": translator$12,
99599
- "w:tblInd": translator$U,
99600
- "w:tblLayout": translator$T,
99601
- "w:tblLook": translator$S,
99602
- "w:tblOverlap": translator$R,
99603
- "w:tblPr": translator$v,
99604
- "w:tblStyle": translator$Q,
99605
- "w:tblStyleColBandSize": translator$P,
99606
- "w:tblStyleRowBandSize": translator$O,
99607
- "w:tblW": translator$N,
99608
- "w:tblpPr": translator$M,
99609
- "w:tc": translator$c,
99610
- "w:top": translator$z,
99611
- "w:tr": translator$Z,
99612
- "w:trHeight": translator$11,
99613
- "w:trPr": translator$_,
99512
+ "w:tbl": translator$8,
99513
+ "w:tblBorders": translator$d,
99514
+ "w:tblCaption": translator$o,
99515
+ "w:tblCellMar": translator$c,
99516
+ "w:tblCellSpacing": translator$A,
99517
+ "w:tblDescription": translator$n,
99518
+ "w:tblGrid": translator$9,
99519
+ "w:tblHeader": translator$z,
99520
+ "w:tblInd": translator$m,
99521
+ "w:tblLayout": translator$l,
99522
+ "w:tblLook": translator$k,
99523
+ "w:tblOverlap": translator$j,
99524
+ "w:tblPr": translator$b,
99525
+ "w:tblStyle": translator$i,
99526
+ "w:tblStyleColBandSize": translator$h,
99527
+ "w:tblStyleRowBandSize": translator$g,
99528
+ "w:tblW": translator$f,
99529
+ "w:tblpPr": translator$e,
99530
+ "w:tc": translator$H,
99531
+ "w:top": translator$V,
99532
+ "w:tr": translator$u,
99533
+ "w:trHeight": translator$y,
99534
+ "w:trPr": translator$v,
99614
99535
  "w:u": translator$1l,
99615
- "w:wAfter": translator$10,
99616
- "w:wBefore": translator$$,
99617
- "wp:anchor": translator$b,
99618
- "wp:inline": translator$a,
99536
+ "w:wAfter": translator$x,
99537
+ "w:wBefore": translator$w,
99538
+ "wp:anchor": translator$t,
99539
+ "wp:inline": translator$s,
99619
99540
  "w:commentRangeStart": commentRangeStartTranslator,
99620
99541
  "w:commentRangeEnd": commentRangeEndTranslator,
99621
- "w:vMerge": translator$p,
99622
- "w:gridSpan": translator$q,
99623
- "w:vAlign": translator$h,
99624
- "w:noWrap": translator$l,
99625
- "w:tcFitText": translator$i,
99626
- "w:tcW": translator$r,
99627
- "w:hideMark": translator$g,
99628
- "w:textDirection": translator$j,
99629
- "w:tl2br": translator$o,
99630
- "w:tr2bl": translator$n,
99631
- "w:header": translator$f,
99632
- "w:headers": translator$e,
99633
- "w:tcBorders": translator$m,
99634
- "w:tcMar": translator$k,
99635
- "w:tcPr": translator$d
99542
+ "w:vMerge": translator$16,
99543
+ "w:gridSpan": translator$17,
99544
+ "w:vAlign": translator$M,
99545
+ "w:noWrap": translator$Q,
99546
+ "w:tcFitText": translator$N,
99547
+ "w:tcW": translator$18,
99548
+ "w:hideMark": translator$L,
99549
+ "w:textDirection": translator$O,
99550
+ "w:tl2br": translator$T,
99551
+ "w:tr2bl": translator$S,
99552
+ "w:header": translator$K,
99553
+ "w:headers": translator$J,
99554
+ "w:tcBorders": translator$R,
99555
+ "w:tcMar": translator$P,
99556
+ "w:tcPr": translator$I
99636
99557
  });
99637
99558
  const baseHandlers = {
99638
99559
  ...runPropertyTranslators,