@harbour-enterprises/superdoc 0.22.0-next.1 → 0.22.0-next.10

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 (47) hide show
  1. package/dist/chunks/{PdfViewer-BpwMPbUj.es.js → PdfViewer-CJdQmuIm.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-B3KmcDup.cjs → PdfViewer-DE1NR4Ve.cjs} +1 -1
  3. package/dist/chunks/{index-Cw4YywoD.es.js → index-B9sHxXr_.es.js} +53 -26
  4. package/dist/chunks/{index-BOf6E2I4.cjs → index-nfoifSpX.cjs} +53 -26
  5. package/dist/chunks/{super-editor.es-DHDx2fsy.cjs → super-editor.es-DAP-fnHo.cjs} +2264 -1648
  6. package/dist/chunks/{super-editor.es-vfoWxyZL.es.js → super-editor.es-_iVPQ8J8.es.js} +2264 -1648
  7. package/dist/core/SuperDoc.d.ts +5 -0
  8. package/dist/core/SuperDoc.d.ts.map +1 -1
  9. package/dist/core/types/index.d.ts +4 -4
  10. package/dist/core/types/index.d.ts.map +1 -1
  11. package/dist/stores/comments-store.d.ts +4 -1
  12. package/dist/stores/comments-store.d.ts.map +1 -1
  13. package/dist/style.css +48 -44
  14. package/dist/super-editor/ai-writer.es.js +2 -2
  15. package/dist/super-editor/chunks/{converter-BcqEfCTg.js → converter-DK1NMJZB.js} +439 -169
  16. package/dist/super-editor/chunks/{docx-zipper-DZ9ph0iQ.js → docx-zipper-CmK8TyNb.js} +73 -12
  17. package/dist/super-editor/chunks/{editor-BC2sSIVa.js → editor-YR4uV-dp.js} +1902 -1607
  18. package/dist/super-editor/chunks/{toolbar-DNTo5DDf.js → toolbar-DzJyRvb0.js} +2 -2
  19. package/dist/super-editor/converter.es.js +1 -1
  20. package/dist/super-editor/docx-zipper.es.js +2 -2
  21. package/dist/super-editor/editor.es.js +3 -3
  22. package/dist/super-editor/file-zipper.es.js +1 -1
  23. package/dist/super-editor/src/core/DocxZipper.d.ts +1 -1
  24. package/dist/super-editor/src/core/super-converter/SuperConverter.d.ts +1 -13
  25. package/dist/super-editor/src/core/super-converter/exporter.d.ts +1 -0
  26. package/dist/super-editor/src/core/super-converter/helpers/tableFallbackHelpers.d.ts +24 -0
  27. package/dist/super-editor/src/extensions/custom-selection/custom-selection.d.ts +5 -1
  28. package/dist/super-editor/src/extensions/index.d.ts +2 -1
  29. package/dist/super-editor/src/extensions/structured-content/index.d.ts +1 -0
  30. package/dist/super-editor/src/extensions/structured-content/structured-content-commands.d.ts +67 -0
  31. package/dist/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentBlockTags.d.ts +7 -0
  32. package/dist/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentInlineTags.d.ts +7 -0
  33. package/dist/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentTags.d.ts +7 -0
  34. package/dist/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentTagsById.d.ts +8 -0
  35. package/dist/super-editor/src/extensions/structured-content/structuredContentHelpers/index.d.ts +4 -0
  36. package/dist/super-editor/src/utils/contextmenu-helpers.d.ts +24 -0
  37. package/dist/super-editor/style.css +4 -0
  38. package/dist/super-editor/super-editor.es.js +8 -16
  39. package/dist/super-editor/toolbar.es.js +2 -2
  40. package/dist/super-editor.cjs +1 -1
  41. package/dist/super-editor.es.js +1 -1
  42. package/dist/superdoc.cjs +2 -2
  43. package/dist/superdoc.es.js +2 -2
  44. package/dist/superdoc.umd.js +1665 -1022
  45. package/dist/superdoc.umd.js.map +1 -1
  46. package/package.json +1 -1
  47. package/dist/super-editor/src/components/slash-menu/contextmenu-helpers.d.ts +0 -1
@@ -24846,17 +24846,16 @@ const getParagraphSpacing = (node, docx, styleId = "", marks = [], options = {})
24846
24846
  };
24847
24847
  const getDefaultParagraphStyle = (docx, styleId = "") => {
24848
24848
  const styles = docx["word/styles.xml"];
24849
- if (!styles) {
24849
+ const rootElements = styles?.elements?.[0]?.elements;
24850
+ if (!rootElements?.length) {
24850
24851
  return {};
24851
24852
  }
24852
- const defaults = styles.elements[0].elements?.find((el) => el.name === "w:docDefaults");
24853
- const pDefault = defaults.elements.find((el) => el.name === "w:pPrDefault");
24853
+ const defaults = rootElements.find((el) => el.name === "w:docDefaults");
24854
+ const pDefault = defaults?.elements?.find((el) => el.name === "w:pPrDefault") || {};
24854
24855
  const pPrDefault = pDefault?.elements?.find((el) => el.name === "w:pPr");
24855
24856
  const pPrDefaultSpacingTag = pPrDefault?.elements?.find((el) => el.name === "w:spacing") || {};
24856
24857
  const pPrDefaultIndentTag = pPrDefault?.elements?.find((el) => el.name === "w:ind") || {};
24857
- const stylesNormal = styles.elements[0].elements?.find(
24858
- (el) => el.name === "w:style" && el.attributes["w:styleId"] === "Normal"
24859
- );
24858
+ const stylesNormal = rootElements.find((el) => el.name === "w:style" && el.attributes["w:styleId"] === "Normal");
24860
24859
  const pPrNormal = stylesNormal?.elements?.find((el) => el.name === "w:pPr");
24861
24860
  const pPrNormalSpacingTag = pPrNormal?.elements?.find((el) => el.name === "w:spacing") || {};
24862
24861
  const pPrNormalIndentTag = pPrNormal?.elements?.find((el) => el.name === "w:ind") || {};
@@ -24865,9 +24864,7 @@ const getDefaultParagraphStyle = (docx, styleId = "") => {
24865
24864
  let pPrStyleIdIndentTag = {};
24866
24865
  let pPrStyleJc = {};
24867
24866
  if (styleId) {
24868
- const stylesById = styles.elements[0].elements?.find(
24869
- (el) => el.name === "w:style" && el.attributes["w:styleId"] === styleId
24870
- );
24867
+ const stylesById = rootElements.find((el) => el.name === "w:style" && el.attributes["w:styleId"] === styleId);
24871
24868
  const pPrById = stylesById?.elements?.find((el) => el.name === "w:pPr");
24872
24869
  pPrStyleIdSpacingTag = pPrById?.elements?.find((el) => el.name === "w:spacing") || {};
24873
24870
  pPrStyleIdIndentTag = pPrById?.elements?.find((el) => el.name === "w:ind") || {};
@@ -27170,6 +27167,68 @@ const config$a = {
27170
27167
  decode: decode$h
27171
27168
  };
27172
27169
  const translator$a = NodeTranslator.from(config$a);
27170
+ const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
27171
+ const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
27172
+ const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
27173
+ const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
27174
+ const pctToPercent = (value) => {
27175
+ if (value == null) return null;
27176
+ return value / 50;
27177
+ };
27178
+ const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
27179
+ const resolveMeasurementWidthPx = (measurement) => {
27180
+ if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
27181
+ const { value, type: type2 } = measurement;
27182
+ if (!type2 || type2 === "auto") return null;
27183
+ if (type2 === "dxa") return twipsToPixels(value);
27184
+ if (type2 === "pct") {
27185
+ const percent = pctToPercent(value);
27186
+ if (percent == null || percent <= 0) return null;
27187
+ const widthTwips = resolveContentWidthTwips() * percent / 100;
27188
+ return twipsToPixels(widthTwips);
27189
+ }
27190
+ return null;
27191
+ };
27192
+ const countColumnsInRow = (row) => {
27193
+ if (!row?.elements?.length) return 0;
27194
+ return row.elements.reduce((count, element) => {
27195
+ if (element.name !== "w:tc") return count;
27196
+ const tcPr = element.elements?.find((el) => el.name === "w:tcPr");
27197
+ const gridSpan = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
27198
+ const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
27199
+ return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
27200
+ }, 0);
27201
+ };
27202
+ const clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
27203
+ const createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
27204
+ const buildFallbackGridForTable = ({ params, rows, tableWidth, tableWidthMeasurement }) => {
27205
+ const firstRow = rows.find((row) => row.elements?.some((el) => el.name === "w:tc"));
27206
+ const columnCount = countColumnsInRow(firstRow);
27207
+ if (!columnCount) return null;
27208
+ const schemaDefaultPx = getSchemaDefaultColumnWidthPx(
27209
+ /** @type {any} */
27210
+ params
27211
+ );
27212
+ const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : DEFAULT_COLUMN_WIDTH_PX;
27213
+ let totalWidthPx;
27214
+ if (tableWidthMeasurement) {
27215
+ const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
27216
+ if (resolved != null) totalWidthPx = resolved;
27217
+ }
27218
+ if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) {
27219
+ totalWidthPx = tableWidth.width;
27220
+ }
27221
+ if (totalWidthPx == null) {
27222
+ totalWidthPx = minimumColumnWidthPx * columnCount;
27223
+ }
27224
+ const rawColumnWidthPx = Math.max(totalWidthPx / columnCount, minimumColumnWidthPx);
27225
+ const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(rawColumnWidthPx));
27226
+ const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
27227
+ return {
27228
+ grid: createFallbackGrid(columnCount, columnWidthTwips),
27229
+ columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
27230
+ };
27231
+ };
27173
27232
  const XML_NODE_NAME$9 = "w:tbl";
27174
27233
  const SD_NODE_NAME$9 = "table";
27175
27234
  const encode$g = (params, encodedAttrs) => {
@@ -27189,7 +27248,6 @@ const encode$g = (params, encodedAttrs) => {
27189
27248
  "justification",
27190
27249
  "tableLayout",
27191
27250
  ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
27192
- ["tableWidth", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
27193
27251
  ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
27194
27252
  ].forEach((prop) => {
27195
27253
  let key;
@@ -27207,6 +27265,21 @@ const encode$g = (params, encodedAttrs) => {
27207
27265
  if (encodedAttrs.tableCellSpacing) {
27208
27266
  encodedAttrs["borderCollapse"] = "separate";
27209
27267
  }
27268
+ if (encodedAttrs.tableProperties?.tableWidth) {
27269
+ const tableWidthMeasurement = encodedAttrs.tableProperties.tableWidth;
27270
+ const widthPx = twipsToPixels(tableWidthMeasurement.value);
27271
+ if (widthPx != null) {
27272
+ encodedAttrs.tableWidth = {
27273
+ width: widthPx,
27274
+ type: tableWidthMeasurement.type
27275
+ };
27276
+ } else if (tableWidthMeasurement.type === "auto") {
27277
+ encodedAttrs.tableWidth = {
27278
+ width: 0,
27279
+ type: tableWidthMeasurement.type
27280
+ };
27281
+ }
27282
+ }
27210
27283
  const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
27211
27284
  const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params);
27212
27285
  if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
@@ -27220,7 +27293,19 @@ const encode$g = (params, encodedAttrs) => {
27220
27293
  const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
27221
27294
  encodedAttrs["borders"] = borderData;
27222
27295
  const tblStyleTag = tblPr?.elements?.find((el) => el.name === "w:tblStyle");
27223
- const columnWidths = (encodedAttrs["grid"] ?? []).map((item) => twipsToPixels(item.col));
27296
+ let columnWidths = Array.isArray(encodedAttrs["grid"]) ? encodedAttrs["grid"].map((item) => twipsToPixels(item.col)) : [];
27297
+ if (!columnWidths.length) {
27298
+ const fallback = buildFallbackGridForTable({
27299
+ params,
27300
+ rows,
27301
+ tableWidth: encodedAttrs.tableWidth,
27302
+ tableWidthMeasurement: encodedAttrs.tableProperties?.tableWidth
27303
+ });
27304
+ if (fallback) {
27305
+ encodedAttrs.grid = fallback.grid;
27306
+ columnWidths = fallback.columnWidths;
27307
+ }
27308
+ }
27224
27309
  const content = [];
27225
27310
  rows.forEach((row) => {
27226
27311
  const result = translator$G.encode({
@@ -28082,6 +28167,9 @@ function handleStructuredContentNode(params) {
28082
28167
  const node = nodes[0];
28083
28168
  const sdtPr = node.elements.find((el) => el.name === "w:sdtPr");
28084
28169
  const sdtContent = node.elements.find((el) => el.name === "w:sdtContent");
28170
+ const id = sdtPr?.elements?.find((el) => el.name === "w:id");
28171
+ const tag = sdtPr?.elements?.find((el) => el.name === "w:tag");
28172
+ const alias = sdtPr?.elements?.find((el) => el.name === "w:alias");
28085
28173
  if (!sdtContent) {
28086
28174
  return null;
28087
28175
  }
@@ -28093,15 +28181,16 @@ function handleStructuredContentNode(params) {
28093
28181
  nodes: sdtContent.elements,
28094
28182
  path: [...params.path || [], sdtContent]
28095
28183
  });
28096
- let sdtContentType = "structuredContent";
28097
- if (paragraph || table) {
28098
- sdtContentType = "structuredContentBlock";
28099
- }
28184
+ const isBlockNode = paragraph || table;
28185
+ const sdtContentType = isBlockNode ? "structuredContentBlock" : "structuredContent";
28100
28186
  let result = {
28101
28187
  type: sdtContentType,
28102
28188
  content: translatedContent,
28103
28189
  marks,
28104
28190
  attrs: {
28191
+ id: id?.attributes?.["w:val"] || null,
28192
+ tag: tag?.attributes?.["w:val"] || null,
28193
+ alias: alias?.attributes?.["w:val"] || null,
28105
28194
  sdtPr
28106
28195
  }
28107
28196
  };
@@ -30359,21 +30448,55 @@ const generateSdtPrTagForDocumentSection = (id, title, tag) => {
30359
30448
  };
30360
30449
  function translateStructuredContent(params) {
30361
30450
  const { node } = params;
30362
- const { attrs = {} } = node;
30363
30451
  const childContent = translateChildNodes({ ...params, nodes: node.content });
30364
- const nodeElements = [
30365
- {
30366
- name: "w:sdtContent",
30367
- elements: childContent
30368
- }
30369
- ];
30370
- nodeElements.unshift(attrs.sdtPr);
30452
+ const sdtContent = { name: "w:sdtContent", elements: childContent };
30453
+ const sdtPr = generateSdtPrTagForStructuredContent({ node });
30454
+ const nodeElements = [sdtPr, sdtContent];
30371
30455
  const result = {
30372
30456
  name: "w:sdt",
30373
30457
  elements: nodeElements
30374
30458
  };
30375
30459
  return result;
30376
30460
  }
30461
+ function generateSdtPrTagForStructuredContent({ node }) {
30462
+ const { attrs = {} } = node;
30463
+ const id = {
30464
+ name: "w:id",
30465
+ type: "element",
30466
+ attributes: { "w:val": attrs.id }
30467
+ };
30468
+ const alias = {
30469
+ name: "w:alias",
30470
+ type: "element",
30471
+ attributes: { "w:val": attrs.alias }
30472
+ };
30473
+ const tag = {
30474
+ name: "w:tag",
30475
+ type: "element",
30476
+ attributes: { "w:val": attrs.tag }
30477
+ };
30478
+ const resultElements = [];
30479
+ if (attrs.id) resultElements.push(id);
30480
+ if (attrs.alias) resultElements.push(alias);
30481
+ if (attrs.tag) resultElements.push(tag);
30482
+ if (attrs.sdtPr) {
30483
+ const elements = attrs.sdtPr.elements || [];
30484
+ const elementsToExclude = ["w:id", "w:alias", "w:tag"];
30485
+ const restElements = elements.filter((el) => !elementsToExclude.includes(el.name));
30486
+ const result2 = {
30487
+ name: "w:sdtPr",
30488
+ type: "element",
30489
+ elements: [...resultElements, ...restElements]
30490
+ };
30491
+ return result2;
30492
+ }
30493
+ const result = {
30494
+ name: "w:sdtPr",
30495
+ type: "element",
30496
+ elements: resultElements
30497
+ };
30498
+ return result;
30499
+ }
30377
30500
  const XML_NODE_NAME$3 = "w:sdt";
30378
30501
  const SD_NODE_NAME$3 = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
30379
30502
  const validXmlAttributes$3 = [];
@@ -30601,6 +30724,63 @@ const config = {
30601
30724
  attributes: validXmlAttributes
30602
30725
  };
30603
30726
  const translator = NodeTranslator.from(config);
30727
+ const DEFAULT_SECTION_PROPS_TWIPS = Object.freeze({
30728
+ pageSize: Object.freeze({ width: "12240", height: "15840" }),
30729
+ pageMargins: Object.freeze({
30730
+ top: "1440",
30731
+ right: "1440",
30732
+ bottom: "1440",
30733
+ left: "1440",
30734
+ header: "720",
30735
+ footer: "720",
30736
+ gutter: "0"
30737
+ })
30738
+ });
30739
+ const ensureSectionLayoutDefaults = (sectPr, converter) => {
30740
+ if (!sectPr) {
30741
+ return {
30742
+ type: "element",
30743
+ name: "w:sectPr",
30744
+ elements: []
30745
+ };
30746
+ }
30747
+ if (!sectPr.elements) sectPr.elements = [];
30748
+ const ensureChild = (name) => {
30749
+ let child = sectPr.elements.find((n) => n.name === name);
30750
+ if (!child) {
30751
+ child = {
30752
+ type: "element",
30753
+ name,
30754
+ elements: [],
30755
+ attributes: {}
30756
+ };
30757
+ sectPr.elements.push(child);
30758
+ } else {
30759
+ if (!child.elements) child.elements = [];
30760
+ if (!child.attributes) child.attributes = {};
30761
+ }
30762
+ return child;
30763
+ };
30764
+ const pageSize = converter?.pageStyles?.pageSize;
30765
+ const pgSz = ensureChild("w:pgSz");
30766
+ if (pageSize?.width != null) pgSz.attributes["w:w"] = String(inchesToTwips(pageSize.width));
30767
+ if (pageSize?.height != null) pgSz.attributes["w:h"] = String(inchesToTwips(pageSize.height));
30768
+ if (pgSz.attributes["w:w"] == null) pgSz.attributes["w:w"] = DEFAULT_SECTION_PROPS_TWIPS.pageSize.width;
30769
+ if (pgSz.attributes["w:h"] == null) pgSz.attributes["w:h"] = DEFAULT_SECTION_PROPS_TWIPS.pageSize.height;
30770
+ const pageMargins = converter?.pageStyles?.pageMargins;
30771
+ const pgMar = ensureChild("w:pgMar");
30772
+ if (pageMargins) {
30773
+ Object.entries(pageMargins).forEach(([key, value]) => {
30774
+ const converted = inchesToTwips(value);
30775
+ if (converted != null) pgMar.attributes[`w:${key}`] = String(converted);
30776
+ });
30777
+ }
30778
+ Object.entries(DEFAULT_SECTION_PROPS_TWIPS.pageMargins).forEach(([key, value]) => {
30779
+ const attrKey = `w:${key}`;
30780
+ if (pgMar.attributes[attrKey] == null) pgMar.attributes[attrKey] = value;
30781
+ });
30782
+ return sectPr;
30783
+ };
30604
30784
  const isLineBreakOnlyRun = (node) => {
30605
30785
  if (!node) return false;
30606
30786
  if (node.type === "lineBreak" || node.type === "hardBreak") return true;
@@ -30653,28 +30833,30 @@ function exportSchemaToJson(params) {
30653
30833
  return handler2(params);
30654
30834
  }
30655
30835
  function translateBodyNode(params) {
30656
- let sectPr = params.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
30836
+ let sectPr = params.bodyNode?.elements?.find((n) => n.name === "w:sectPr");
30837
+ if (!sectPr) {
30838
+ sectPr = {
30839
+ type: "element",
30840
+ name: "w:sectPr",
30841
+ elements: []
30842
+ };
30843
+ } else if (!sectPr.elements) {
30844
+ sectPr = { ...sectPr, elements: [] };
30845
+ }
30846
+ sectPr = ensureSectionLayoutDefaults(sectPr, params.converter);
30657
30847
  if (params.converter) {
30658
- const hasHeader = sectPr?.elements?.some((n) => n.name === "w:headerReference");
30848
+ const hasHeader = sectPr.elements?.some((n) => n.name === "w:headerReference");
30659
30849
  const hasDefaultHeader = params.converter.headerIds?.default;
30660
30850
  if (!hasHeader && hasDefaultHeader && !params.editor.options.isHeaderOrFooter) {
30661
30851
  const defaultHeader = generateDefaultHeaderFooter("header", params.converter.headerIds?.default);
30662
30852
  sectPr.elements.push(defaultHeader);
30663
30853
  }
30664
- const hasFooter = sectPr?.elements?.some((n) => n.name === "w:footerReference");
30854
+ const hasFooter = sectPr.elements?.some((n) => n.name === "w:footerReference");
30665
30855
  const hasDefaultFooter = params.converter.footerIds?.default;
30666
30856
  if (!hasFooter && hasDefaultFooter && !params.editor.options.isHeaderOrFooter) {
30667
30857
  const defaultFooter = generateDefaultHeaderFooter("footer", params.converter.footerIds?.default);
30668
30858
  sectPr.elements.push(defaultFooter);
30669
30859
  }
30670
- const newMargins = params.converter.pageStyles.pageMargins;
30671
- const sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
30672
- const { attributes } = sectPrMargins;
30673
- Object.entries(newMargins).forEach(([key, value]) => {
30674
- const convertedValue = inchesToTwips(value);
30675
- attributes[`w:${key}`] = convertedValue;
30676
- });
30677
- sectPrMargins.attributes = attributes;
30678
30860
  }
30679
30861
  const elements = translateChildNodes(params);
30680
30862
  if (params.isHeaderFooter) {
@@ -32101,8 +32283,15 @@ const handlePictNode = (params) => {
32101
32283
  return { nodes: [], consumed: 0 };
32102
32284
  }
32103
32285
  const [pNode] = nodes;
32104
- const run2 = pNode.elements?.find((el) => el.name === "w:r");
32105
- const pict = run2?.elements?.find((el) => el.name === "w:pict");
32286
+ const runs = pNode.elements?.filter((el) => el.name === "w:r") || [];
32287
+ let pict = null;
32288
+ for (const run2 of runs) {
32289
+ const foundPict = run2.elements?.find((el) => el.name === "w:pict");
32290
+ if (foundPict) {
32291
+ pict = foundPict;
32292
+ break;
32293
+ }
32294
+ }
32106
32295
  if (!pict) {
32107
32296
  return { nodes: [], consumed: 0 };
32108
32297
  }
@@ -32689,6 +32878,7 @@ const createDocumentJson = (docx, converter, editor) => {
32689
32878
  const nodeListHandler = defaultNodeListHandler();
32690
32879
  const bodyNode = json.elements[0].elements.find((el) => el.name === "w:body");
32691
32880
  if (bodyNode) {
32881
+ ensureSectionProperties(bodyNode);
32692
32882
  const node = bodyNode;
32693
32883
  const contentElements = node.elements?.filter((n) => n.name !== "w:sectPr") ?? [];
32694
32884
  const content = pruneIgnoredNodes(contentElements);
@@ -32922,6 +33112,59 @@ function getDocumentStyles(node, docx, converter, editor) {
32922
33112
  styles.alternateHeaders = isAlternatingHeadersOddEven(docx);
32923
33113
  return styles;
32924
33114
  }
33115
+ const DEFAULT_SECTION_PROPS = Object.freeze({
33116
+ pageSize: Object.freeze({ width: "12240", height: "15840" }),
33117
+ pageMargins: Object.freeze({
33118
+ top: "1440",
33119
+ right: "1440",
33120
+ bottom: "1440",
33121
+ left: "1440",
33122
+ header: "720",
33123
+ footer: "720",
33124
+ gutter: "0"
33125
+ })
33126
+ });
33127
+ function ensureSectionProperties(bodyNode, converter) {
33128
+ if (!bodyNode.elements) bodyNode.elements = [];
33129
+ let sectPr = bodyNode.elements.find((el) => el.name === "w:sectPr");
33130
+ if (!sectPr) {
33131
+ sectPr = {
33132
+ type: "element",
33133
+ name: "w:sectPr",
33134
+ elements: []
33135
+ };
33136
+ bodyNode.elements.push(sectPr);
33137
+ } else if (!sectPr.elements) {
33138
+ sectPr.elements = [];
33139
+ }
33140
+ const ensureChild = (name, factory) => {
33141
+ let child = sectPr.elements.find((el) => el.name === name);
33142
+ if (!child) {
33143
+ child = factory();
33144
+ sectPr.elements.push(child);
33145
+ } else if (!child.attributes) {
33146
+ child.attributes = {};
33147
+ }
33148
+ return child;
33149
+ };
33150
+ const pgSz = ensureChild("w:pgSz", () => ({
33151
+ type: "element",
33152
+ name: "w:pgSz",
33153
+ attributes: {}
33154
+ }));
33155
+ pgSz.attributes["w:w"] = pgSz.attributes["w:w"] ?? DEFAULT_SECTION_PROPS.pageSize.width;
33156
+ pgSz.attributes["w:h"] = pgSz.attributes["w:h"] ?? DEFAULT_SECTION_PROPS.pageSize.height;
33157
+ const pgMar = ensureChild("w:pgMar", () => ({
33158
+ type: "element",
33159
+ name: "w:pgMar",
33160
+ attributes: {}
33161
+ }));
33162
+ Object.entries(DEFAULT_SECTION_PROPS.pageMargins).forEach(([key, value]) => {
33163
+ const attrKey = `w:${key}`;
33164
+ if (pgMar.attributes[attrKey] == null) pgMar.attributes[attrKey] = value;
33165
+ });
33166
+ return sectPr;
33167
+ }
32925
33168
  function getStyleDefinitions(docx) {
32926
33169
  const styles = docx["word/styles.xml"];
32927
33170
  if (!styles) return [];
@@ -33114,6 +33357,36 @@ const FONT_FAMILY_FALLBACKS = Object.freeze({
33114
33357
  auto: "sans-serif"
33115
33358
  });
33116
33359
  const DEFAULT_GENERIC_FALLBACK = "sans-serif";
33360
+ const DEFAULT_FONT_SIZE_PT = 10;
33361
+ const collectRunDefaultProperties = (runProps, { allowOverrideTypeface = true, allowOverrideSize = true, themeResolver, state: state2 }) => {
33362
+ if (!runProps?.elements?.length || !state2) return;
33363
+ const fontsNode = runProps.elements.find((el) => el.name === "w:rFonts");
33364
+ if (fontsNode?.attributes) {
33365
+ const themeName = fontsNode.attributes["w:asciiTheme"];
33366
+ if (themeName) {
33367
+ const themeInfo = themeResolver?.(themeName) || {};
33368
+ if ((allowOverrideTypeface || !state2.typeface) && themeInfo.typeface) state2.typeface = themeInfo.typeface;
33369
+ if ((allowOverrideTypeface || !state2.panose) && themeInfo.panose) state2.panose = themeInfo.panose;
33370
+ }
33371
+ const ascii = fontsNode.attributes["w:ascii"];
33372
+ if ((allowOverrideTypeface || !state2.typeface) && ascii) {
33373
+ state2.typeface = ascii;
33374
+ }
33375
+ }
33376
+ const sizeNode = runProps.elements.find((el) => el.name === "w:sz");
33377
+ if (sizeNode?.attributes?.["w:val"]) {
33378
+ const sizeTwips = Number(sizeNode.attributes["w:val"]);
33379
+ if (Number.isFinite(sizeTwips)) {
33380
+ if (state2.fallbackSzTwips === void 0) state2.fallbackSzTwips = sizeTwips;
33381
+ const sizePt = sizeTwips / 2;
33382
+ if (allowOverrideSize || state2.fontSizePt === void 0) state2.fontSizePt = sizePt;
33383
+ }
33384
+ }
33385
+ const kernNode = runProps.elements.find((el) => el.name === "w:kern");
33386
+ if (kernNode?.attributes?.["w:val"]) {
33387
+ if (allowOverrideSize || state2.kern === void 0) state2.kern = kernNode.attributes["w:val"];
33388
+ }
33389
+ };
33117
33390
  const _SuperConverter = class _SuperConverter {
33118
33391
  constructor(params = null) {
33119
33392
  __privateAdd(this, _SuperConverter_instances);
@@ -33241,49 +33514,45 @@ const _SuperConverter = class _SuperConverter {
33241
33514
  }
33242
33515
  getDocumentDefaultStyles() {
33243
33516
  const styles = this.convertedXml["word/styles.xml"];
33244
- if (!styles) return {};
33245
- const defaults = styles.elements[0].elements.find((el) => el.name === "w:docDefaults");
33246
- const rDefault = defaults.elements.find((el) => el.name === "w:rPrDefault");
33247
- if (!rDefault.elements) return {};
33248
- const rElements = rDefault.elements[0].elements;
33249
- const rFonts = rElements?.find((el) => el.name === "w:rFonts");
33250
- if ("elements" in rDefault) {
33251
- const fontThemeName = rElements.find((el) => el.name === "w:rFonts")?.attributes["w:asciiTheme"];
33252
- let typeface, panose, fontSizeNormal;
33253
- if (fontThemeName) {
33254
- const fontInfo = this.getThemeInfo(fontThemeName);
33255
- typeface = fontInfo.typeface;
33256
- panose = fontInfo.panose;
33257
- } else if (rFonts) {
33258
- typeface = rFonts?.attributes["w:ascii"];
33259
- }
33260
- const paragraphDefaults = styles.elements[0].elements.filter((el) => {
33261
- return el.name === "w:style" && el.attributes["w:styleId"] === "Normal";
33262
- }) || [];
33263
- paragraphDefaults.forEach((el) => {
33264
- const rPr = el.elements.find((el2) => el2.name === "w:rPr");
33265
- const fonts = rPr?.elements?.find((el2) => el2.name === "w:rFonts");
33266
- typeface = fonts?.attributes["w:ascii"];
33267
- fontSizeNormal = Number(rPr?.elements?.find((el2) => el2.name === "w:sz")?.attributes["w:val"]) / 2;
33268
- });
33269
- const rPrDefaults = defaults?.elements?.find((el) => el.name === "w:rPrDefault");
33270
- if (rPrDefaults) {
33271
- const rPr = rPrDefaults.elements?.find((el) => el.name === "w:rPr");
33272
- const fonts = rPr?.elements?.find((el) => el.name === "w:rFonts");
33273
- if (fonts?.attributes?.["w:ascii"]) {
33274
- typeface = fonts.attributes["w:ascii"];
33275
- }
33276
- const fontSizeRaw = rPr?.elements?.find((el) => el.name === "w:sz")?.attributes?.["w:val"];
33277
- if (!fontSizeNormal && fontSizeRaw) {
33278
- fontSizeNormal = Number(fontSizeRaw) / 2;
33279
- }
33280
- }
33281
- const fallbackSz = Number(rElements.find((el) => el.name === "w:sz")?.attributes?.["w:val"]);
33282
- const fontSizePt = fontSizeNormal ?? (Number.isFinite(fallbackSz) ? fallbackSz / 2 : void 0) ?? 10;
33283
- const kern = rElements.find((el) => el.name === "w:kern")?.attributes["w:val"];
33284
- const fontFamilyCss = _SuperConverter.toCssFontFamily(typeface, this.convertedXml);
33285
- return { fontSizePt, kern, typeface, panose, fontFamilyCss };
33286
- }
33517
+ const styleRoot = styles?.elements?.[0];
33518
+ const styleElements = styleRoot?.elements || [];
33519
+ if (!styleElements.length) return {};
33520
+ const defaults = styleElements.find((el) => el.name === "w:docDefaults");
33521
+ const normalStyle = styleElements.find((el) => el.name === "w:style" && el.attributes?.["w:styleId"] === "Normal");
33522
+ const defaultsState = {
33523
+ typeface: void 0,
33524
+ panose: void 0,
33525
+ fontSizePt: void 0,
33526
+ kern: void 0,
33527
+ fallbackSzTwips: void 0
33528
+ };
33529
+ const docDefaultRun = defaults?.elements?.find((el) => el.name === "w:rPrDefault");
33530
+ const docDefaultProps = docDefaultRun?.elements?.find((el) => el.name === "w:rPr") ?? docDefaultRun;
33531
+ collectRunDefaultProperties(docDefaultProps, {
33532
+ allowOverrideTypeface: true,
33533
+ allowOverrideSize: true,
33534
+ themeResolver: (theme) => this.getThemeInfo(theme),
33535
+ state: defaultsState
33536
+ });
33537
+ const normalRunProps = normalStyle?.elements?.find((el) => el.name === "w:rPr") ?? null;
33538
+ collectRunDefaultProperties(normalRunProps, {
33539
+ allowOverrideTypeface: true,
33540
+ allowOverrideSize: true,
33541
+ themeResolver: (theme) => this.getThemeInfo(theme),
33542
+ state: defaultsState
33543
+ });
33544
+ if (defaultsState.fontSizePt === void 0) {
33545
+ if (Number.isFinite(defaultsState.fallbackSzTwips)) defaultsState.fontSizePt = defaultsState.fallbackSzTwips / 2;
33546
+ else defaultsState.fontSizePt = DEFAULT_FONT_SIZE_PT;
33547
+ }
33548
+ const fontFamilyCss = defaultsState.typeface ? _SuperConverter.toCssFontFamily(defaultsState.typeface, this.convertedXml) : void 0;
33549
+ const result = {};
33550
+ if (defaultsState.fontSizePt !== void 0) result.fontSizePt = defaultsState.fontSizePt;
33551
+ if (defaultsState.kern !== void 0) result.kern = defaultsState.kern;
33552
+ if (defaultsState.typeface) result.typeface = defaultsState.typeface;
33553
+ if (defaultsState.panose) result.panose = defaultsState.panose;
33554
+ if (fontFamilyCss) result.fontFamilyCss = fontFamilyCss;
33555
+ return result;
33287
33556
  }
33288
33557
  getDocumentFonts() {
33289
33558
  const fontTable = this.convertedXml["word/fontTable.xml"];
@@ -33768,7 +34037,7 @@ export {
33768
34037
  objectIncludes as Z,
33769
34038
  AddMarkStep as _,
33770
34039
  Plugin as a,
33771
- translator$M as a$,
34040
+ translator$C as a$,
33772
34041
  twipsToLines as a0,
33773
34042
  pixelsToTwips as a1,
33774
34043
  helpers as a2,
@@ -33779,102 +34048,103 @@ export {
33779
34048
  createDocFromMarkdown as a7,
33780
34049
  createDocFromHTML as a8,
33781
34050
  EditorState as a9,
33782
- readFromClipboard as aA,
33783
- handleClipboardPaste as aB,
33784
- getFileObject as aC,
33785
- runPropertyTranslators as aD,
33786
- translator$5 as aE,
33787
- translator$6 as aF,
33788
- translator$I as aG,
33789
- translator$J as aH,
33790
- translator$10 as aI,
33791
- translator$H as aJ,
33792
- translator$K as aK,
33793
- translator$G as aL,
33794
- translator$g as aM,
33795
- translator$8 as aN,
33796
- translator$t as aO,
33797
- translator$u as aP,
33798
- translator$v as aQ,
33799
- translator$w as aR,
33800
- translator$x as aS,
33801
- translator$c as aT,
33802
- translator$y as aU,
33803
- translator$z as aV,
33804
- translator$A as aW,
33805
- translator$B as aX,
33806
- translator$L as aY,
33807
- translator$a as aZ,
33808
- translator$C as a_,
34051
+ getActiveFormatting as aA,
34052
+ readFromClipboard as aB,
34053
+ handleClipboardPaste as aC,
34054
+ getFileObject as aD,
34055
+ runPropertyTranslators as aE,
34056
+ translator$5 as aF,
34057
+ translator$6 as aG,
34058
+ translator$I as aH,
34059
+ translator$J as aI,
34060
+ translator$10 as aJ,
34061
+ translator$H as aK,
34062
+ translator$K as aL,
34063
+ translator$G as aM,
34064
+ translator$g as aN,
34065
+ translator$8 as aO,
34066
+ translator$t as aP,
34067
+ translator$u as aQ,
34068
+ translator$v as aR,
34069
+ translator$w as aS,
34070
+ translator$x as aT,
34071
+ translator$c as aU,
34072
+ translator$y as aV,
34073
+ translator$z as aW,
34074
+ translator$A as aX,
34075
+ translator$B as aY,
34076
+ translator$L as aZ,
34077
+ translator$a as a_,
33809
34078
  hasSomeParentWithClass as aa,
33810
34079
  isActive as ab,
33811
34080
  unflattenListsInHtml as ac,
33812
34081
  parseSizeUnit as ad,
33813
34082
  minMax as ae,
33814
34083
  getLineHeightValueString as af,
33815
- InputRule as ag,
33816
- kebabCase as ah,
33817
- findParentNodeClosestToPos as ai,
33818
- getListItemStyleDefinitions as aj,
33819
- docxNumberigHelpers as ak,
33820
- parseIndentElement as al,
33821
- combineIndents as am,
33822
- SelectionRange as an,
33823
- Transform as ao,
33824
- isInTable as ap,
33825
- generateDocxRandomId as aq,
33826
- insertNewRelationship as ar,
33827
- updateDOMAttributes as as,
33828
- htmlHandler as at,
33829
- commonjsGlobal as au,
33830
- getDefaultExportFromCjs$1 as av,
33831
- getContentTypesFromXml as aw,
33832
- xmljs as ax,
33833
- vClickOutside as ay,
33834
- getActiveFormatting as az,
34084
+ updateDOMAttributes as ag,
34085
+ findChildren as ah,
34086
+ htmlHandler as ai,
34087
+ InputRule as aj,
34088
+ kebabCase as ak,
34089
+ findParentNodeClosestToPos as al,
34090
+ getListItemStyleDefinitions as am,
34091
+ docxNumberigHelpers as an,
34092
+ parseIndentElement as ao,
34093
+ combineIndents as ap,
34094
+ SelectionRange as aq,
34095
+ Transform as ar,
34096
+ isInTable as as,
34097
+ generateDocxRandomId as at,
34098
+ insertNewRelationship as au,
34099
+ commonjsGlobal as av,
34100
+ getDefaultExportFromCjs$1 as aw,
34101
+ getContentTypesFromXml as ax,
34102
+ xmljs as ay,
34103
+ vClickOutside as az,
33835
34104
  Slice as b,
33836
- translator$d as b0,
33837
- translator$D as b1,
33838
- translator$e as b2,
33839
- translator$9 as b3,
33840
- translator$14 as b4,
33841
- translator$W as b5,
33842
- translator$X as b6,
33843
- translator$$ as b7,
33844
- translator$i as b8,
33845
- translator$E as b9,
33846
- translator$2 as bA,
33847
- translator$1 as bB,
33848
- translator$F as bC,
33849
- translator$12 as bD,
33850
- translator as bE,
33851
- _sfc_main as bF,
33852
- translator$3 as ba,
33853
- translator$k as bb,
33854
- translator$Y as bc,
33855
- translator$V as bd,
33856
- translator$Z as be,
33857
- translator$U as bf,
33858
- translator$13 as bg,
33859
- translator$m as bh,
33860
- translator$N as bi,
33861
- translator$n as bj,
33862
- translator$o as bk,
33863
- translator$11 as bl,
33864
- translator$7 as bm,
33865
- translator$15 as bn,
33866
- translator$O as bo,
33867
- translator$b as bp,
33868
- translator$P as bq,
33869
- translator$Q as br,
33870
- translator$q as bs,
33871
- translator$4 as bt,
33872
- translator$R as bu,
33873
- translator$_ as bv,
33874
- translator$S as bw,
33875
- translator$T as bx,
33876
- translator$16 as by,
33877
- translator$s as bz,
34105
+ translator$M as b0,
34106
+ translator$d as b1,
34107
+ translator$D as b2,
34108
+ translator$e as b3,
34109
+ translator$9 as b4,
34110
+ translator$14 as b5,
34111
+ translator$W as b6,
34112
+ translator$X as b7,
34113
+ translator$$ as b8,
34114
+ translator$i as b9,
34115
+ translator$s as bA,
34116
+ translator$2 as bB,
34117
+ translator$1 as bC,
34118
+ translator$F as bD,
34119
+ translator$12 as bE,
34120
+ translator as bF,
34121
+ _sfc_main as bG,
34122
+ translator$E as ba,
34123
+ translator$3 as bb,
34124
+ translator$k as bc,
34125
+ translator$Y as bd,
34126
+ translator$V as be,
34127
+ translator$Z as bf,
34128
+ translator$U as bg,
34129
+ translator$13 as bh,
34130
+ translator$m as bi,
34131
+ translator$N as bj,
34132
+ translator$n as bk,
34133
+ translator$o as bl,
34134
+ translator$11 as bm,
34135
+ translator$7 as bn,
34136
+ translator$15 as bo,
34137
+ translator$O as bp,
34138
+ translator$b as bq,
34139
+ translator$P as br,
34140
+ translator$Q as bs,
34141
+ translator$q as bt,
34142
+ translator$4 as bu,
34143
+ translator$R as bv,
34144
+ translator$_ as bw,
34145
+ translator$S as bx,
34146
+ translator$T as by,
34147
+ translator$16 as bz,
33878
34148
  DOMParser$1 as c,
33879
34149
  Mark as d,
33880
34150
  dropPoint as e,