@harbour-enterprises/superdoc 0.12.34-next.3 → 0.13.0-RC2

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 (48) hide show
  1. package/dist/chunks/{super-editor.es-B9igwxv-.es.js → super-editor.es-B6M3d3ew.es.js} +1020 -1010
  2. package/dist/chunks/{super-editor.es-BbaXC2pT.cjs → super-editor.es-CG_E8Uh1.cjs} +1020 -1010
  3. package/dist/style.css +67 -54
  4. package/dist/super-editor/ai-writer.es.js +2 -2
  5. package/dist/super-editor/chunks/{converter-DzsjYmnd.js → converter-DdMoUfYl.js} +310 -441
  6. package/dist/super-editor/chunks/{docx-zipper-DQONSIAh.js → docx-zipper-CaPhHWh0.js} +1 -1
  7. package/dist/super-editor/chunks/{editor-CO-n6iZ8.js → editor-DfrK7LO9.js} +1653 -1507
  8. package/dist/super-editor/chunks/{toolbar-CNeu8BVd.js → toolbar-h35AzYvu.js} +2 -2
  9. package/dist/super-editor/converter.es.js +1 -1
  10. package/dist/super-editor/core/Attribute.d.ts +2 -2
  11. package/dist/super-editor/core/Editor.d.ts +8 -1
  12. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  13. package/dist/super-editor/core/Schema.d.ts +2 -2
  14. package/dist/super-editor/core/commands/splitListItem.d.ts +1 -1
  15. package/dist/super-editor/core/commands/splitListItem.d.ts.map +1 -1
  16. package/dist/super-editor/core/helpers/list-numbering-helpers.d.ts +235 -0
  17. package/dist/super-editor/core/helpers/list-numbering-helpers.d.ts.map +1 -0
  18. package/dist/super-editor/core/super-converter/SuperConverter.d.ts +1 -1
  19. package/dist/super-editor/core/super-converter/SuperConverter.d.ts.map +1 -1
  20. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  21. package/dist/super-editor/core/super-converter/v2/importer/listImporter.d.ts +32 -5
  22. package/dist/super-editor/core/super-converter/v2/importer/listImporter.d.ts.map +1 -1
  23. package/dist/super-editor/core/super-converter/v2/importer/paragraphNodeImporter.d.ts.map +1 -1
  24. package/dist/super-editor/docx-zipper.es.js +2 -2
  25. package/dist/super-editor/editor.es.js +3 -3
  26. package/dist/super-editor/extensions/linked-styles/linked-styles.d.ts.map +1 -1
  27. package/dist/super-editor/extensions/list-item/ListItemNodeView.d.ts +56 -0
  28. package/dist/super-editor/extensions/list-item/ListItemNodeView.d.ts.map +1 -0
  29. package/dist/super-editor/extensions/list-item/list-item.d.ts.map +1 -1
  30. package/dist/super-editor/extensions/ordered-list/ordered-list.d.ts.map +1 -1
  31. package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
  32. package/dist/super-editor/file-zipper.es.js +1 -1
  33. package/dist/super-editor/style.css +40 -27
  34. package/dist/super-editor/super-editor.es.js +6 -6
  35. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts +3 -0
  36. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts.map +1 -0
  37. package/dist/super-editor/tests/e2e/test-app/vite.config.d.ts +1 -1
  38. package/dist/super-editor/tests/editor/listItemHelpers.test.d.ts +2 -0
  39. package/dist/super-editor/tests/editor/listItemHelpers.test.d.ts.map +1 -0
  40. package/dist/super-editor/tests/export/export-helpers/export-helpers.d.ts.map +1 -1
  41. package/dist/super-editor/toolbar.es.js +2 -2
  42. package/dist/super-editor.cjs +1 -1
  43. package/dist/super-editor.es.js +1 -1
  44. package/dist/superdoc.cjs +3 -5
  45. package/dist/superdoc.es.js +4 -6
  46. package/dist/superdoc.umd.js +1024 -1016
  47. package/dist/superdoc.umd.js.map +1 -1
  48. package/package.json +1 -1
@@ -17341,16 +17341,6 @@ const carbonCopy = (obj) => {
17341
17341
  return void 0;
17342
17342
  }
17343
17343
  };
17344
- const baseOrderedListDef = {
17345
- "attributes": {
17346
- "w:abstractNumId": "1"
17347
- }
17348
- };
17349
- const baseBulletList = {
17350
- "attributes": {
17351
- "w:abstractNumId": "0"
17352
- }
17353
- };
17354
17344
  const baseNumbering = {
17355
17345
  "declaration": {
17356
17346
  "attributes": {
@@ -18969,7 +18959,7 @@ function generateParagraphProperties(node2) {
18969
18959
  };
18970
18960
  pPrElements.push(spacingElement);
18971
18961
  }
18972
- if (indent) {
18962
+ if (indent && Object.values(indent).some((v) => v !== 0)) {
18973
18963
  const { left, right, firstLine, hanging } = indent;
18974
18964
  const attributes = {};
18975
18965
  if (left || left === 0) attributes["w:left"] = pixelsToTwips(left);
@@ -18984,7 +18974,7 @@ function generateParagraphProperties(node2) {
18984
18974
  attributes
18985
18975
  };
18986
18976
  pPrElements.push(indentElement);
18987
- } else if (textIndent) {
18977
+ } else if (textIndent && textIndent !== "0in") {
18988
18978
  const indentElement = {
18989
18979
  name: "w:ind",
18990
18980
  attributes: {
@@ -19033,6 +19023,9 @@ function generateParagraphProperties(node2) {
19033
19023
  if (sectPr) {
19034
19024
  pPrElements.push(sectPr);
19035
19025
  }
19026
+ const numPr = node2.attrs?.paragraphProperties?.elements?.find((n) => n.name === "w:numPr");
19027
+ const hasNumPr = pPrElements.some((n) => n.name === "w:numPr");
19028
+ if (numPr && !hasNumPr) pPrElements.push(numPr);
19036
19029
  if (!pPrElements.length) return null;
19037
19030
  return {
19038
19031
  name: "w:pPr",
@@ -19281,157 +19274,68 @@ function addNewImageRelationship(params, imagePath) {
19281
19274
  return newId;
19282
19275
  }
19283
19276
  function translateList(params) {
19284
- const { type: type2 } = params.node;
19285
- const flatContent = flattenContent(params);
19286
- const listNodes = [];
19287
- flatContent.forEach((listNode) => {
19288
- const { level, listType, pPrs: additionalPprs, content, attrs = {} } = listNode;
19289
- const attrsNumId = listNode.attrs.numId;
19290
- const actualNumId = attrsNumId || listNode.listId;
19291
- const listId = actualNumId ?? generateNewListDefinition(params, listType);
19292
- const pPr = getListParagraphProperties(level, listId, additionalPprs);
19293
- content.forEach((contentNode, index) => {
19294
- const paragraphNode = Object.assign({}, contentNode);
19295
- paragraphNode.attrs = {
19296
- ...paragraphNode.attrs,
19297
- ...listNode.attrs
19298
- };
19299
- const outputNode = exportSchemaToJson({ ...params, node: paragraphNode });
19300
- if (!outputNode.elements) {
19301
- outputNode.elements = [];
19302
- }
19303
- if (Array.isArray(outputNode)) {
19304
- const mapped = [];
19305
- outputNode.forEach((el, index2) => {
19306
- mapped.push(...el.elements);
19307
- if (index2 < outputNode.length - 1) mapped.push({ name: "w:br", type: "element" });
19308
- });
19309
- mapped.unshift(carbonCopy(pPr));
19310
- return listNodes.push({ name: "w:p", elements: mapped });
19311
- }
19312
- const propsElementIndex = outputNode.elements.findIndex((e) => e.name === "w:pPr");
19313
- const content2 = outputNode.elements.filter((e) => e.name !== "w:pPr");
19314
- if (!content2.length && !Array.isArray(outputNode)) {
19315
- const elements = contentNode.attrs.paragraphProperties ? [contentNode.attrs.paragraphProperties] : [];
19316
- const spacer = {
19317
- name: "w:p",
19318
- type: "element",
19319
- elements
19320
- };
19321
- return listNodes.push(spacer);
19322
- }
19323
- outputNode.elements = outputNode.elements.map((el, index2) => {
19324
- if (el.name === "w:sdt") {
19325
- const contentIndex = el.elements.findIndex((e) => e.name === "w:sdtContent");
19326
- const content3 = el.elements[contentIndex];
19327
- const innerContent = content3.elements[0];
19328
- if (innerContent.name === "w:p") {
19329
- content3.elements = innerContent.elements;
19330
- }
19331
- return {
19332
- name: "w:r",
19333
- type: "element",
19334
- elements: [el]
19335
- };
19336
- } else {
19337
- return el;
19338
- }
19339
- });
19340
- const { attributes: generalAttributes } = attrs;
19341
- const { originalInlineRunProps } = generalAttributes || {};
19342
- if (originalInlineRunProps) pPr.elements.push(originalInlineRunProps);
19343
- if (propsElementIndex === -1) {
19344
- outputNode.elements.unshift(carbonCopy(pPr));
19345
- } else {
19346
- const resultProps = carbonCopy(pPr).elements.map((item) => {
19347
- const isChanged = outputNode.elements[propsElementIndex].elements.find((e) => e.name === item.name);
19348
- return isChanged ? isChanged : item;
19349
- });
19350
- outputNode.elements[propsElementIndex].elements = resultProps;
19351
- }
19352
- let importedFontSize;
19353
- if (listNode.attrs?.importedFontSize) {
19354
- const fontNoUnit = parseInt(listNode.attrs.importedFontSize.split("pt")[0]);
19355
- importedFontSize = {
19356
- name: "w:sz",
19357
- attributes: { "w:val": fontNoUnit * 2 }
19358
- };
19359
- }
19360
- let importedFontFamily;
19361
- if (listNode.attrs?.importedFontFamily) {
19362
- importedFontFamily = {
19363
- name: "w:rFonts",
19364
- attributes: { "w:ascii": listNode.attrs?.importedFontFamily, "w:hAnsi": listNode.attrs?.importedFontFamily }
19365
- };
19366
- }
19367
- const rPrElement = outputNode.elements.find((e) => e.name === "w:rPr");
19368
- if (rPrElement) {
19369
- rPrElement.elements.push(fontSize);
19370
- } else if (importedFontSize || importedFontFamily) {
19371
- const elements = [];
19372
- if (importedFontSize) elements.push(importedFontSize);
19373
- if (importedFontFamily) elements.push(importedFontFamily);
19374
- outputNode.elements.unshift({ name: "w:rPr", elements });
19375
- }
19376
- if (index !== 0) {
19377
- const currentpPr = outputNode.elements.find((e) => e.name === "w:pPr");
19378
- const numPrIndex = currentpPr.elements.findIndex((e) => e.name === "w:numPr");
19379
- if (numPrIndex !== -1) currentpPr.elements.splice(numPrIndex, 1);
19380
- }
19381
- listNodes.push(outputNode);
19382
- });
19383
- });
19384
- return listNodes;
19385
- }
19386
- function generateNewListDefinition(params, listType) {
19387
- const nextNumbering = getLargestListDefinitionIndex(params.converter?.numbering?.definitions);
19388
- const definition = listType === "bullet" ? baseBulletList : baseOrderedListDef;
19389
- const listId = nextNumbering;
19390
- const abstractId = definition.attributes["w:abstractNumId"];
19391
- const newNumDef = {
19277
+ const { node: node2 } = params;
19278
+ const { attrs = {} } = node2;
19279
+ if (node2.content.length > 1) {
19280
+ flattenContent(params);
19281
+ throw new Error("Multi list not supported yet");
19282
+ }
19283
+ const listItem = node2.content[0];
19284
+ const { numId, level } = listItem.attrs;
19285
+ let numPrTag;
19286
+ if (numId) {
19287
+ numPrTag = generateNumPrTag(numId, level);
19288
+ }
19289
+ const paragraphNode = node2.content[0]?.content[0];
19290
+ const outputNode = exportSchemaToJson({ ...params, node: paragraphNode });
19291
+ const pPr = outputNode.elements.find((n) => n.name === "w:pPr");
19292
+ if (pPr && pPr.elements) pPr.elements.unshift(numPrTag);
19293
+ const indentTag = restoreIndent(listItem.attrs.indent);
19294
+ indentTag && pPr?.elements?.push(indentTag);
19295
+ const runNode = outputNode.elements?.find((n) => n.name === "w:r");
19296
+ const rPr = runNode?.elements?.find((n) => n.name === "w:rPr");
19297
+ if (rPr) pPr.elements.push(rPr);
19298
+ if (listItem.attrs.numPrType !== "inline") {
19299
+ const numPrIndex = pPr?.elements?.findIndex((e) => e.name === "w:numPr");
19300
+ if (numPrIndex !== -1) {
19301
+ pPr?.elements?.splice(numPrIndex, 1);
19302
+ }
19303
+ }
19304
+ return [outputNode];
19305
+ }
19306
+ const restoreIndent = (indent) => {
19307
+ const attributes = {};
19308
+ if (!indent) indent = {};
19309
+ if (indent.left || indent.left === 0) attributes["w:left"] = pixelsToTwips(indent.left);
19310
+ if (indent.right || indent.right === 0) attributes["w:right"] = pixelsToTwips(indent.right);
19311
+ if (indent.firstLine || indent.firstLine === 0) attributes["w:firstLine"] = pixelsToTwips(indent.firstLine);
19312
+ if (indent.hanging || indent.hanging === 0) attributes["w:hanging"] = pixelsToTwips(indent.hanging);
19313
+ if (indent.leftChars || indent.leftChars === 0) attributes["w:leftChars"] = pixelsToTwips(indent.leftChars);
19314
+ if (!Object.keys(attributes).length) return;
19315
+ return {
19316
+ name: "w:ind",
19392
19317
  type: "element",
19393
- name: "w:num",
19394
- attributes: {
19395
- "w:numId": String(listId),
19396
- "w16cid:durableId": "485517411"
19397
- },
19398
- elements: [
19399
- { name: "w:abstractNumId", attributes: { "w:val": String(abstractId) } }
19400
- ]
19318
+ attributes
19401
19319
  };
19402
- params.converter.numbering.definitions[listId] = newNumDef;
19403
- return listId;
19404
- }
19405
- const getLargestListDefinitionIndex = (definitions) => {
19406
- if (!definitions || !Object.keys(definitions).length) return 0;
19407
- const maxKey = Math.max(...Object.keys(definitions).map((key) => parseInt(key, 10)));
19408
- return maxKey + 1;
19409
19320
  };
19410
- function getListParagraphProperties(level, numId, additionalPprs = []) {
19321
+ const generateNumPrTag = (numId, level) => {
19411
19322
  return {
19412
- name: "w:pPr",
19323
+ name: "w:numPr",
19413
19324
  type: "element",
19414
19325
  elements: [
19415
19326
  {
19416
- name: "w:numPr",
19327
+ name: "w:numId",
19417
19328
  type: "element",
19418
- elements: [
19419
- {
19420
- name: "w:ilvl",
19421
- type: "element",
19422
- attributes: { "w:val": level }
19423
- },
19424
- {
19425
- name: "w:numId",
19426
- type: "element",
19427
- attributes: { "w:val": numId }
19428
- }
19429
- ]
19329
+ attributes: { "w:val": numId }
19430
19330
  },
19431
- ...additionalPprs
19331
+ {
19332
+ name: "w:ilvl",
19333
+ type: "element",
19334
+ attributes: { "w:val": level }
19335
+ }
19432
19336
  ]
19433
19337
  };
19434
- }
19338
+ };
19435
19339
  function flattenContent({ node: node2 }) {
19436
19340
  const { content, attrs = {} } = node2;
19437
19341
  const { listId, syncId } = node2.attrs || {};
@@ -19502,10 +19406,7 @@ function preProcessVerticalMergeCells(table, { editorSchema }) {
19502
19406
  if (!row.content) continue;
19503
19407
  for (let cellIndex = 0; cellIndex < row.content?.length; cellIndex++) {
19504
19408
  const cell = row.content[cellIndex];
19505
- if (!cell) {
19506
- console.log("no cell");
19507
- continue;
19508
- }
19409
+ if (!cell) continue;
19509
19410
  const { attrs } = cell;
19510
19411
  if (attrs.rowspan > 1) {
19511
19412
  const rowsToChange = content.slice(rowIndex + 1, rowIndex + attrs.rowspan);
@@ -20240,7 +20141,7 @@ function getTranslationByAnnotationType(annotationType) {
20240
20141
  const translateFieldAttrsToMarks = (attrs = {}) => {
20241
20142
  const {
20242
20143
  fontFamily,
20243
- fontSize: fontSize2,
20144
+ fontSize,
20244
20145
  bold,
20245
20146
  underline,
20246
20147
  italic,
@@ -20249,7 +20150,7 @@ const translateFieldAttrsToMarks = (attrs = {}) => {
20249
20150
  } = attrs;
20250
20151
  const marks = [];
20251
20152
  if (fontFamily) marks.push({ type: "fontFamily", attrs: { fontFamily } });
20252
- if (fontSize2) marks.push({ type: "fontSize", attrs: { fontSize: fontSize2 } });
20153
+ if (fontSize) marks.push({ type: "fontSize", attrs: { fontSize } });
20253
20154
  if (bold) marks.push({ type: "bold", attrs: {} });
20254
20155
  if (underline) marks.push({ type: "underline", attrs: {} });
20255
20156
  if (italic) marks.push({ type: "italic", attrs: {} });
@@ -20509,7 +20410,7 @@ function applyMarksToHtmlAnnotation(state2, marks) {
20509
20410
  return state2;
20510
20411
  }
20511
20412
  const fontFamily = marks.find((m) => m.type === "fontFamily");
20512
- const fontSize2 = marks.find((m) => m.type === "fontSize");
20413
+ const fontSize = marks.find((m) => m.type === "fontSize");
20513
20414
  const highlight = marks.find((m) => m.type === "highlight");
20514
20415
  const textStyleType = schema.marks.textStyle;
20515
20416
  const highlightType = schema.marks.highlight;
@@ -20520,17 +20421,17 @@ function applyMarksToHtmlAnnotation(state2, marks) {
20520
20421
  if (!foundTextStyle) {
20521
20422
  tr.addMark(pos, pos + node2.nodeSize, textStyleType.create({
20522
20423
  ...fontFamily?.attrs,
20523
- ...fontSize2?.attrs
20424
+ ...fontSize?.attrs
20524
20425
  }));
20525
20426
  } else if (!foundTextStyle?.attrs.fontFamily && fontFamily) {
20526
20427
  tr.addMark(pos, pos + node2.nodeSize, textStyleType.create({
20527
20428
  ...foundTextStyle?.attrs,
20528
20429
  ...fontFamily.attrs
20529
20430
  }));
20530
- } else if (!foundTextStyle?.attrs.fontSize && fontSize2) {
20431
+ } else if (!foundTextStyle?.attrs.fontSize && fontSize) {
20531
20432
  tr.addMark(pos, pos + node2.nodeSize, textStyleType.create({
20532
20433
  ...foundTextStyle?.attrs,
20533
- ...fontSize2.attrs
20434
+ ...fontSize.attrs
20534
20435
  }));
20535
20436
  }
20536
20437
  if (!foundHighlight) {
@@ -20654,7 +20555,7 @@ function handleTableCellNode(node2, row, table, rowBorders, columnWidth = null,
20654
20555
  const attributes = {};
20655
20556
  const referencedStyles = getReferencedTableStyles(styleTag, docx) || {};
20656
20557
  attributes.cellMargins = getTableCellMargins(marginTag, referencedStyles);
20657
- const { fontSize: fontSize2, fonts = {} } = referencedStyles;
20558
+ const { fontSize, fonts = {} } = referencedStyles;
20658
20559
  const fontFamily = fonts["ascii"];
20659
20560
  if (width) {
20660
20561
  attributes["colwidth"] = [width];
@@ -20682,7 +20583,7 @@ function handleTableCellNode(node2, row, table, rowBorders, columnWidth = null,
20682
20583
  if (colspan) attributes["colspan"] = parseInt(colspan, 10);
20683
20584
  if (background) attributes["background"] = background;
20684
20585
  attributes["verticalAlign"] = verticalAlign;
20685
- if (fontSize2) attributes["fontSize"] = fontSize2;
20586
+ if (fontSize) attributes["fontSize"] = fontSize;
20686
20587
  if (fontFamily) attributes["fontFamily"] = fontFamily["ascii"];
20687
20588
  if (rowBorders) attributes["borders"] = { ...rowBorders };
20688
20589
  if (inlineBorders) attributes["borders"] = Object.assign(attributes["borders"] || {}, inlineBorders);
@@ -20780,8 +20681,8 @@ function getReferencedTableStyles(tblStyleTag, docx, nodeListHandler2) {
20780
20681
  const { "w:ascii": ascii, "w:hAnsi": hAnsi, "w:cs": cs } = fonts.attributes;
20781
20682
  stylesToReturn.fonts = { ascii, hAnsi, cs };
20782
20683
  }
20783
- const fontSize2 = rPr.elements.find((el) => el.name === "w:sz");
20784
- if (fontSize2?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize2.attributes["w:val"]) + "pt";
20684
+ const fontSize = rPr.elements.find((el) => el.name === "w:sz");
20685
+ if (fontSize?.attributes) stylesToReturn.fontSize = halfPointToPoints(fontSize.attributes["w:val"]) + "pt";
20785
20686
  }
20786
20687
  const tblPr = styleTag.elements.find((el) => el.name === "w:tblPr");
20787
20688
  if (tblPr && tblPr.elements) {
@@ -21234,11 +21135,6 @@ function getElementName(element) {
21234
21135
  const isPropertiesElement = (element) => {
21235
21136
  return !!SuperConverter.propertyTypes[element.name || element.type];
21236
21137
  };
21237
- function hasTextNode(elements) {
21238
- const runs = elements.filter((el) => el.name === "w:r");
21239
- const runsHaveText = runs.some((run) => run.elements.some((el) => el.name === "w:t"));
21240
- return runsHaveText;
21241
- }
21242
21138
  const handleTrackChangeNode = (params) => {
21243
21139
  const { nodes, nodeListHandler: nodeListHandler2 } = params;
21244
21140
  if (nodes.length === 0 || !(nodes[0].name === "w:del" || nodes[0].name === "w:ins" || nodes[0].name === "w:sdt")) {
@@ -21440,219 +21336,118 @@ const areAttrsEqual = (attrsA = {}, attrsB = {}) => {
21440
21336
  };
21441
21337
  const handleListNode = (params) => {
21442
21338
  const { nodes, lists, docx } = params;
21443
- if (nodes.length === 0 || nodes[0].name !== "w:p") {
21339
+ if (nodes.length === 0 || nodes[0].name !== "w:p" || nodes[0].isList) {
21444
21340
  return { nodes: [], consumed: 0 };
21445
21341
  }
21446
21342
  const node2 = carbonCopy(nodes[0]);
21447
- const processedElements = preProcessNodesForFldChar(node2.elements);
21448
- node2.elements = processedElements;
21449
- const originalPpr = node2.elements.find((el) => el.name === "w:pPr");
21450
- if (testForList(node2, docx)) {
21451
- const siblings = carbonCopy(nodes);
21452
- const listItems = [];
21453
- let possibleList = siblings.shift();
21454
- while (possibleList && testForList(possibleList, docx)) {
21455
- listItems.push(possibleList);
21456
- possibleList = siblings.shift();
21457
- if (possibleList?.elements && !hasTextNode(possibleList.elements)) {
21458
- listItems.push(possibleList);
21459
- possibleList = siblings.shift();
21460
- }
21461
- }
21462
- const listNodes = handleListNodes({ listItems, params, originalPpr });
21343
+ const isList = testForList(node2, docx);
21344
+ if (isList) {
21345
+ node2.isList = true;
21346
+ const result = handleListNodes(params, node2);
21463
21347
  return {
21464
- nodes: [listNodes],
21465
- consumed: listItems.filter((i) => i.seen).length,
21466
- lists
21348
+ nodes: [result],
21349
+ consumed: 1
21467
21350
  };
21468
21351
  } else {
21469
- return { nodes: [], consumed: 0, lists };
21352
+ return { nodes: [], consumed: 0 };
21470
21353
  }
21471
21354
  };
21472
21355
  const listHandlerEntity = {
21473
21356
  handlerName: "listHandler",
21474
21357
  handler: handleListNode
21475
21358
  };
21476
- function handleListNodes({
21477
- listItems,
21478
- originalPpr,
21479
- params,
21480
- listLevel = 0,
21481
- actualListLevel = 0,
21482
- currentListNumId = null,
21483
- path = "",
21484
- isNested = false
21485
- }) {
21359
+ function handleListNodes(params, node2) {
21486
21360
  const { docx, nodeListHandler: nodeListHandler2, lists } = params;
21487
- const parsedListItems = [];
21488
- let overallListType;
21489
- let listStyleType;
21490
- const handleStandardNode2 = nodeListHandler2.handlerEntities.find(
21491
- (e) => e.handlerName === "standardNodeHandler"
21492
- )?.handler;
21493
- if (!handleStandardNode2) {
21494
- console.error("Standard node handler not found");
21495
- return { nodes: [], consumed: 0 };
21496
- }
21497
- const initialpPr = listItems[0].elements.find((el) => el.name === "w:pPr");
21361
+ const initialpPr = node2.elements.find((el) => el.name === "w:pPr");
21498
21362
  const styleTag = initialpPr?.elements?.find((el) => el.name === "w:pStyle");
21499
21363
  const styleId = styleTag?.attributes["w:val"];
21500
- const numPrTag = getNumPrRecursive({ node: listItems[0], styleId, docx });
21501
- currentListNumId = getNumIdFromTag(numPrTag);
21502
- actualListLevel = parseInt(numPrTag?.elements?.find((el) => el.name === "w:ilvl")?.attributes["w:val"]) || 0;
21503
- if (actualListLevel === void 0) actualListLevel = getOutlineLevelFromStyleTag(styleId, docx);
21504
- let lastNestedListLevel = 0;
21505
- for (let [index, item] of listItems.entries()) {
21506
- if (item.seen) continue;
21507
- const { attributes, elements, marks = [] } = parseProperties(item);
21508
- const matchedStyle = getStyleTagFromStyleId(styleId, docx) || {};
21509
- const { marks: styleIdMarks } = parseProperties(matchedStyle);
21510
- const textStyle = marks.find((mark) => mark.type === "textStyle");
21511
- const textStyleFromStyles = styleIdMarks?.find((mark) => mark.type === "textStyle");
21512
- const {
21513
- listType,
21514
- listOrderingType,
21515
- ilvl,
21516
- listrPrs,
21517
- listpPrs,
21518
- start,
21519
- lvlText,
21520
- lvlJc,
21521
- numId
21522
- } = getNodeNumberingDefinition(item, listLevel, docx);
21523
- listStyleType = listOrderingType;
21524
- const intLevel = parseInt(ilvl);
21525
- const isRoot = actualListLevel === intLevel && numId === currentListNumId;
21526
- const isSameListLevelDef = isSameListLevelDefsExceptStart({
21527
- firstListId: numId,
21528
- secondListId: currentListNumId,
21529
- level: intLevel,
21530
- pStyleId: null,
21531
- docx
21532
- });
21533
- const isDifferentList = numId !== currentListNumId && !isSameListLevelDef;
21534
- const isNested2 = listLevel < intLevel || listLevel === intLevel && isDifferentList && lastNestedListLevel === listLevel;
21535
- if (!lists[currentListNumId]) lists[currentListNumId] = {};
21536
- if (!lists[currentListNumId][listLevel]) {
21537
- lists[currentListNumId][listLevel] = Number(start);
21538
- }
21539
- const nodeAttributes = {};
21540
- if (isRoot && !isNested2) {
21541
- overallListType = listType;
21542
- item.seen = true;
21543
- const schemaElements = [];
21544
- const nodeContents = nodeListHandler2.handler({ ...params, nodes: [attributes.paragraphProperties, ...elements] })?.filter((n) => n) || [];
21545
- let parNode = {
21546
- type: "paragraph",
21547
- content: nodeContents
21548
- };
21549
- if (parNode.content) {
21550
- parNode = {
21551
- ...parNode,
21552
- attrs: {
21553
- textAlign: textStyle?.attrs.textAlign || textStyleFromStyles?.attrs.textAlign || null,
21554
- rsidRDefault: attributes?.["w:rsidRDefault"] || null,
21555
- styleId
21556
- },
21557
- content: mergeTextNodes(parNode.content)
21558
- };
21559
- }
21560
- schemaElements.push(parNode);
21561
- lastNestedListLevel = listLevel;
21562
- let thisItemPath = [];
21563
- if (listStyleType !== "bullet") {
21564
- thisItemPath = [...path, lists[currentListNumId][listLevel]];
21565
- lists[currentListNumId][actualListLevel]++;
21566
- }
21567
- if (!path.length && actualListLevel > 0) {
21568
- const currentDef = lists[currentListNumId];
21569
- if (currentDef) {
21570
- const newPath = [];
21571
- Object.keys(currentDef).forEach((key) => {
21572
- newPath.push(currentDef[key]);
21573
- });
21574
- thisItemPath = newPath;
21575
- }
21576
- }
21577
- const pPr = item.elements.find((el) => el.name === "w:pPr");
21578
- let indent = pPr?.elements.find((el) => el.name === "w:ind");
21579
- const pPrFromStyles = matchedStyle?.elements?.find((style) => style.name === "w:pPr");
21580
- const stylesIndent = pPrFromStyles?.elements?.find((el) => el.name === "w:ind");
21581
- if (!indent) indent = stylesIndent;
21582
- if (indent) {
21583
- const indentAttrs = {};
21584
- if (!indent.attributes) indent.attributes = {};
21585
- if (indent.attributes["w:left"] !== void 0) indentAttrs.left = twipsToPixels(indent.attributes["w:left"]);
21586
- if (indent.attributes["w:right"] !== void 0) indentAttrs.right = twipsToPixels(indent.attributes["w:right"]);
21587
- if (indent.attributes["w:firstLine"] !== void 0) indentAttrs.firstLine = twipsToPixels(indent.attributes["w:firstLine"]);
21588
- if (indent.attributes["w:hanging"] !== void 0) indentAttrs.hanging = twipsToPixels(indent.attributes["w:hanging"]);
21589
- nodeAttributes["indent"] = indentAttrs;
21590
- }
21591
- if (listpPrs) nodeAttributes["listParagraphProperties"] = listpPrs;
21592
- if (listrPrs) nodeAttributes["listRunProperties"] = listrPrs;
21593
- nodeAttributes["textStyle"] = textStyle;
21594
- nodeAttributes["order"] = start;
21595
- nodeAttributes["lvlText"] = lvlText;
21596
- nodeAttributes["lvlJc"] = textStyle?.attrs.textAlign;
21597
- nodeAttributes["listLevel"] = thisItemPath;
21598
- nodeAttributes["listNumberingType"] = listOrderingType;
21599
- nodeAttributes["attributes"] = {
21600
- parentAttributes: item?.attributes || null
21601
- };
21602
- const originalRunProps = originalPpr?.elements?.find((el) => el.name === "w:rPr");
21603
- if (originalRunProps) {
21604
- nodeAttributes.attributes["originalInlineRunProps"] = originalRunProps;
21605
- }
21606
- nodeAttributes["numId"] = numId;
21607
- if (docx) {
21608
- nodeAttributes["spacing"] = getParagraphSpacing(item, docx, styleId);
21609
- }
21610
- const newListItem = createListItem(schemaElements, nodeAttributes, []);
21611
- parsedListItems.push(newListItem);
21612
- } else if (isNested2) {
21613
- const newPath = [...path, lists[currentListNumId][listLevel]];
21614
- const sublist = handleListNodes({
21615
- listItems: listItems.slice(index),
21616
- originalPpr,
21617
- params,
21618
- listLevel: listLevel + 1,
21619
- actualListLevel: listLevel,
21620
- currentListNumId: numId,
21621
- path: newPath,
21622
- isNested: true
21623
- });
21624
- lastNestedListLevel = sublist.lastNestedListLevel;
21625
- delete sublist.lastNestedListLevel;
21626
- const lastItem = parsedListItems[parsedListItems.length - 1];
21627
- if (!lastItem) {
21628
- parsedListItems.push(createListItem([sublist], nodeAttributes, []));
21629
- } else {
21630
- lastItem.content.push(sublist);
21631
- }
21632
- } else if (!numId) {
21633
- item.seen = true;
21634
- const n = handleStandardNode2({ ...params, nodes: [item] }).nodes[0];
21635
- parsedListItems[parsedListItems.length - 1]?.content.push(n);
21636
- } else {
21637
- lastNestedListLevel = listLevel;
21638
- if (listLevel > 0 && item.elements[0].elements.find((el) => el.name === "w:numPr")) {
21639
- lists[currentListNumId][listLevel] = 0;
21364
+ const { numPr: numPrTag, type: numPrType } = getNumPrRecursive({ node: node2, styleId, docx });
21365
+ const currentListNumId = getNumIdFromTag(numPrTag);
21366
+ const iLvlTag = numPrTag?.elements?.find((el) => el.name === "w:ilvl");
21367
+ let iLvl = Number(iLvlTag?.attributes["w:val"]);
21368
+ if (!iLvl && iLvl !== 0) iLvl = getOutlineLevelFromStyleTag(styleId, docx);
21369
+ const {
21370
+ listType,
21371
+ listOrderingType,
21372
+ listrPrs,
21373
+ listpPrs,
21374
+ start,
21375
+ lvlText,
21376
+ lvlJc
21377
+ } = getNodeNumberingDefinition(node2, iLvl, docx);
21378
+ if (!listType) {
21379
+ const pPrIndex = node2.elements.findIndex((el) => el.name === "w:pPr");
21380
+ const pPr = node2.elements[pPrIndex];
21381
+ const numPrIndex2 = pPr?.elements?.findIndex((el) => el.name === "w:numPr");
21382
+ if (numPrIndex2 >= 0) {
21383
+ pPr?.elements?.splice(numPrIndex2, 1);
21384
+ node2.elements[pPrIndex] = pPr;
21385
+ }
21386
+ const styleIdIndex = pPr?.elements?.findIndex((el) => el.name === "w:pStyle");
21387
+ if (styleIdIndex >= 0) pPr?.elements?.splice(styleIdIndex, 1);
21388
+ const fallBack = nodeListHandler2.handler({ ...params, nodes: [node2] })?.filter((n) => n);
21389
+ return fallBack[0];
21390
+ }
21391
+ if (!lists[currentListNumId]) lists[currentListNumId] = { levels: {} };
21392
+ const currentListByNumId = lists[currentListNumId];
21393
+ if (!currentListByNumId.levels[iLvl]) currentListByNumId.levels[iLvl] = Number(start) || 1;
21394
+ else currentListByNumId.levels[iLvl]++;
21395
+ Object.keys(currentListByNumId.levels).forEach((key) => {
21396
+ const level = Number(key);
21397
+ if (level > iLvl) {
21398
+ delete currentListByNumId.levels[level];
21399
+ }
21400
+ });
21401
+ const path = [];
21402
+ if (iLvl > 0) {
21403
+ for (let i = iLvl; i >= 0; i--) {
21404
+ const { start: lvlStart } = getNodeNumberingDefinition(node2, i, docx);
21405
+ if (!currentListByNumId.levels[i]) {
21406
+ currentListByNumId.levels[i] = Number(lvlStart);
21640
21407
  }
21641
- break;
21408
+ path.unshift(currentListByNumId.levels[i]);
21642
21409
  }
21643
21410
  }
21411
+ if (!path.length) path.push(currentListByNumId.levels[iLvl]);
21412
+ const attrs = {};
21413
+ attrs.lvlText = lvlText;
21414
+ attrs.listLevel = path;
21415
+ attrs.listNumberingType = listOrderingType;
21416
+ attrs.numId = currentListNumId;
21417
+ attrs.level = iLvl;
21418
+ attrs.numPrType = numPrType;
21419
+ attrs.styleId = styleId;
21420
+ node2.isList = true;
21421
+ const nodePpr = node2.attrs?.paragraphProperties?.elements?.find((el) => el.name === "w:pPr");
21422
+ const numPrIndex = node2.attrs?.paragraphProperties?.elements?.findIndex((el) => el.name === "w:numPr");
21423
+ nodePpr?.elements?.splice(numPrIndex, 1);
21424
+ const listContents = nodeListHandler2.handler({ ...params, nodes: [node2] });
21425
+ const innerParagraph = listContents.find((el) => el.type === "paragraph");
21426
+ const firstElement = innerParagraph.content[0];
21427
+ firstElement?.marks?.find((mark) => mark.type === "textStyle");
21428
+ attrs.indent = listpPrs?.indent;
21429
+ const processedContents = listContents.map((el, index) => {
21430
+ const { attrs: elementAttrs } = el;
21431
+ const { indent, textIndent, paragraphProperties, ...rest } = elementAttrs;
21432
+ if (index === 0 && !attrs.indent) attrs.indent = indent;
21433
+ return {
21434
+ ...el,
21435
+ attrs: rest
21436
+ };
21437
+ });
21438
+ const listItem = {
21439
+ type: "listItem",
21440
+ content: processedContents || [],
21441
+ attrs
21442
+ };
21644
21443
  const resultingList = {
21645
- type: overallListType || "bulletList",
21646
- content: parsedListItems,
21444
+ type: listType,
21445
+ content: [listItem],
21647
21446
  attrs: {
21648
- "list-style-type": listStyleType,
21649
- listId: currentListNumId,
21650
- attributes: {
21651
- parentAttributes: listItems[0]?.attributes || null
21652
- }
21447
+ "list-style-type": listOrderingType,
21448
+ listId: currentListNumId
21653
21449
  }
21654
21450
  };
21655
- if (isNested) resultingList.lastNestedListLevel = lastNestedListLevel;
21656
21451
  return resultingList;
21657
21452
  }
21658
21453
  const getOutlineLevelFromStyleTag = (styleTag, docx) => {
@@ -21671,11 +21466,27 @@ function testForList(node2, docx) {
21671
21466
  const paragraphStyle = pPr.elements?.find((el) => el.name === "w:pStyle");
21672
21467
  let numPr = pPr.elements?.find((el) => el.name === "w:numPr");
21673
21468
  let numId = getNumIdFromTag(numPr);
21469
+ const ilvlTag = numPr?.elements?.find((el) => el.name === "w:ilvl");
21470
+ let ilvl = ilvlTag?.attributes["w:val"];
21471
+ let outlinelvl;
21674
21472
  const styleId = paragraphStyle?.attributes["w:val"];
21675
- if (styleId && !numId) {
21676
- numPr = getNumPrRecursive({ node: node2, styleId, docx });
21473
+ const styleTag = getStyleTagFromStyleId(styleId, docx);
21474
+ if (styleTag && !numId) {
21475
+ const { numPr: numPrRecursve, type: type2 } = getNumPrRecursive({ node: node2, styleId, docx });
21476
+ numPr = numPrRecursve;
21677
21477
  numId = getNumIdFromTag(numPr);
21678
- }
21478
+ const stylePpr = styleTag?.elements?.find((el) => el.name === "w:pPr");
21479
+ stylePpr?.elements?.find((el) => el.name === "w:numPr");
21480
+ ilvl = stylePpr?.elements?.find((el) => el.name === "w:ilvl")?.attributes["w:val"];
21481
+ outlinelvl = stylePpr?.elements?.find((el) => el.name === "w:outlineLvl")?.attributes["w:val"];
21482
+ ilvl = outlinelvl || ilvl;
21483
+ }
21484
+ const numbering = docx["word/numbering.xml"] || {};
21485
+ const numDefinition = numbering?.elements?.[0].elements?.find((el) => el.attributes?.["w:numId"] == numId);
21486
+ const abstractNumId = numDefinition?.elements?.find((el) => el.name === "w:abstractNumId")?.attributes["w:val"];
21487
+ const abstractNumDefinition = numbering?.elements?.[0].elements?.find((el) => el.attributes?.["w:abstractNumId"] == abstractNumId);
21488
+ const levelDefinition = abstractNumDefinition?.elements?.find((el) => el.name === "w:lvl" && el.attributes?.["w:ilvl"] == ilvl);
21489
+ if (!levelDefinition) return false;
21679
21490
  return !!numId;
21680
21491
  }
21681
21492
  const getNumIdFromTag = (tag) => {
@@ -21683,20 +21494,19 @@ const getNumIdFromTag = (tag) => {
21683
21494
  };
21684
21495
  function getStyleTagFromStyleId(styleId, docx) {
21685
21496
  const styles = docx["word/styles.xml"];
21686
- if (!styles) {
21687
- return {};
21688
- }
21497
+ if (!styles) return {};
21689
21498
  const styleEls = styles.elements;
21690
21499
  const wStyles = styleEls.find((el) => el.name === "w:styles");
21691
21500
  const styleTags = wStyles.elements.filter((style) => style.name === "w:style");
21692
- return styleTags.find((tag) => tag.attributes["w:styleId"] === styleId);
21501
+ const styleDef = styleTags.find((tag) => tag.attributes["w:styleId"] === styleId);
21502
+ return styleDef;
21693
21503
  }
21694
21504
  function getNumPrRecursive({ node: node2, styleId, docx, seenStyleIds = /* @__PURE__ */ new Set() }) {
21695
21505
  const initialPpr = node2?.elements?.find((el) => el.name === "w:pPr");
21696
21506
  const initialNumPr = initialPpr?.elements?.find((el) => el.name === "w:numPr");
21697
21507
  let numPr = initialNumPr;
21698
21508
  let numId = getNumIdFromTag(numPr);
21699
- if (numId) return numPr;
21509
+ if (numId) return { numPr, type: "inline" };
21700
21510
  const matchedStyle = getStyleTagFromStyleId(styleId, docx);
21701
21511
  const pPr = matchedStyle?.elements?.find((style) => style.name === "w:pPr");
21702
21512
  numPr = pPr?.elements?.find((style) => style.name === "w:numPr");
@@ -21705,18 +21515,10 @@ function getNumPrRecursive({ node: node2, styleId, docx, seenStyleIds = /* @__PU
21705
21515
  if (!numId && !seenStyleIds.has(styleId)) {
21706
21516
  const basedOnStyleId = basedOn?.attributes["w:val"];
21707
21517
  seenStyleIds.add(styleId);
21708
- if (!basedOnStyleId) return null;
21518
+ if (!basedOnStyleId) return {};
21709
21519
  return getNumPrRecursive({ styleId: basedOnStyleId, docx, seenStyleIds });
21710
21520
  }
21711
- return numPr;
21712
- }
21713
- function createListItem(content, attrs, marks) {
21714
- return {
21715
- type: "listItem",
21716
- content,
21717
- attrs,
21718
- marks
21719
- };
21521
+ return { numPr, type: "numbering" };
21720
21522
  }
21721
21523
  const orderedListTypes = [
21722
21524
  "decimal",
@@ -21754,18 +21556,6 @@ const unorderedListTypes = [
21754
21556
  "disc"
21755
21557
  // Disc bullets (●)
21756
21558
  ];
21757
- const isSameListLevelDefsExceptStart = ({ firstListId, secondListId, level, pStyleId, docx }) => {
21758
- const { numFmt, lvlText, lvlJc } = getListLevelDefinitionTag(firstListId, level, pStyleId, docx);
21759
- const {
21760
- numFmt: numFmt2,
21761
- lvlText: lvlText2,
21762
- lvlJc: lvlJc2
21763
- } = getListLevelDefinitionTag(secondListId, level, pStyleId, docx);
21764
- const sameNumFmt = numFmt === numFmt2;
21765
- const sameLvlText = lvlText === lvlText2;
21766
- const sameLvlJc = lvlJc === lvlJc2;
21767
- return sameNumFmt && sameLvlText && sameLvlJc;
21768
- };
21769
21559
  const getListNumIdFromStyleRef = (styleId, docx) => {
21770
21560
  const styles = docx["word/styles.xml"];
21771
21561
  if (!styles) return null;
@@ -21797,24 +21587,28 @@ const getListNumIdFromStyleRef = (styleId, docx) => {
21797
21587
  }
21798
21588
  return { numId, ilvl };
21799
21589
  };
21800
- const getListLevelDefinitionTag = (numId, level, pStyleId, docx) => {
21590
+ const getAbstractDefinition = (numId, docx) => {
21801
21591
  const def = docx["word/numbering.xml"];
21802
21592
  if (!def) return {};
21803
21593
  const { elements } = def;
21804
21594
  const listData = elements[0];
21805
- if (pStyleId) {
21806
- const { numId: numIdFromStyles, ilvl: iLvlFromStyles } = getListNumIdFromStyleRef(pStyleId, docx) || {};
21807
- if (!numId && numIdFromStyles) numId = numIdFromStyles;
21808
- if (!level && iLvlFromStyles) level = iLvlFromStyles ? parseInt(iLvlFromStyles) : null;
21809
- }
21810
21595
  const numberingElements = listData.elements;
21811
21596
  const abstractDefinitions = numberingElements.filter((style) => style.name === "w:abstractNum");
21812
21597
  const numDefinitions = numberingElements.filter((style) => style.name === "w:num");
21813
- const numDefinition = numDefinitions.find((style) => style.attributes["w:numId"] === numId);
21598
+ const numDefinition = numDefinitions.find((style) => style.attributes["w:numId"] == numId);
21814
21599
  const abstractNumId = numDefinition?.elements[0].attributes["w:val"];
21815
21600
  const listDefinitionForThisNumId = abstractDefinitions?.find(
21816
21601
  (style) => style.attributes["w:abstractNumId"] === abstractNumId
21817
21602
  );
21603
+ return listDefinitionForThisNumId;
21604
+ };
21605
+ const getListLevelDefinitionTag = (numId, level, pStyleId, docx) => {
21606
+ if (pStyleId) {
21607
+ const { numId: numIdFromStyles, ilvl: iLvlFromStyles } = getListNumIdFromStyleRef(pStyleId, docx) || {};
21608
+ if (!numId && numIdFromStyles) numId = numIdFromStyles;
21609
+ if (!level && iLvlFromStyles) level = iLvlFromStyles ? parseInt(iLvlFromStyles) : null;
21610
+ }
21611
+ const listDefinitionForThisNumId = getAbstractDefinition(numId, docx);
21818
21612
  const currentLevel = getDefinitionForLevel(listDefinitionForThisNumId, level);
21819
21613
  const numStyleLink = listDefinitionForThisNumId?.elements?.find((style) => style.name === "w:numStyleLink");
21820
21614
  const numStyleLinkId = numStyleLink?.attributes["w:val"];
@@ -21823,7 +21617,15 @@ const getListLevelDefinitionTag = (numId, level, pStyleId, docx) => {
21823
21617
  return getListLevelDefinitionTag(current.numId, level, null, docx);
21824
21618
  }
21825
21619
  const start = currentLevel?.elements?.find((style) => style.name === "w:start")?.attributes["w:val"];
21826
- const numFmt = currentLevel?.elements?.find((style) => style.name === "w:numFmt")?.attributes["w:val"];
21620
+ let numFmt = currentLevel?.elements?.find((style) => style.name === "w:numFmt")?.attributes["w:val"];
21621
+ if (!numFmt) {
21622
+ const altChoice = currentLevel?.elements.find((style) => style.name === "mc:AlternateContent");
21623
+ const choice = altChoice?.elements.find((style) => style.name === "mc:Choice");
21624
+ const choiceNumFmt = choice?.elements.find((style) => style.name === "w:numFmt")?.attributes["w:val"];
21625
+ if (choiceNumFmt) {
21626
+ numFmt = choiceNumFmt;
21627
+ }
21628
+ }
21827
21629
  const lvlText = currentLevel?.elements?.find((style) => style.name === "w:lvlText").attributes["w:val"];
21828
21630
  const lvlJc = currentLevel?.elements?.find((style) => style.name === "w:lvlJc").attributes["w:val"];
21829
21631
  const pPr = currentLevel?.elements?.find((style) => style.name === "w:pPr");
@@ -21838,12 +21640,10 @@ function getNodeNumberingDefinition(item, level, docx) {
21838
21640
  const initialPpr = item.elements.find((el) => el.name === "w:pPr");
21839
21641
  const styleTag = initialPpr?.elements?.find((el) => el.name === "w:pStyle");
21840
21642
  const styleId = styleTag?.attributes["w:val"];
21841
- const numPrTag = getNumPrRecursive({ node: item, styleId, docx });
21643
+ const { numPr: numPrTag, type: type2 } = getNumPrRecursive({ node: item, styleId, docx });
21842
21644
  if (!numPrTag) return {};
21843
21645
  const numIdTag = numPrTag?.elements.find((style) => style.name === "w:numId");
21844
21646
  const numId = numIdTag?.attributes["w:val"];
21845
- const ilvlTag = numPrTag?.elements.find((style) => style.name === "w:ilvl");
21846
- const ilvl = ilvlTag?.attributes["w:val"] || getOutlineLevelFromStyleTag(styleId, docx);
21847
21647
  const pStyle = listStyles.find((style) => style.name === "w:pStyle");
21848
21648
  const pStyleId = pStyle?.attributes["w:val"];
21849
21649
  const {
@@ -21855,29 +21655,84 @@ function getNodeNumberingDefinition(item, level, docx) {
21855
21655
  rPr
21856
21656
  } = getListLevelDefinitionTag(numId, level, pStyleId, docx);
21857
21657
  let listpPrs, listrPrs;
21858
- if (pPr) listpPrs = _processListParagraphProperties(pPr);
21658
+ if (pPr) listpPrs = _processListParagraphProperties(pPr, initialPpr);
21859
21659
  if (rPr) listrPrs = _processListRunProperties(rPr);
21860
21660
  let listType;
21861
21661
  if (unorderedListTypes.includes(listTypeDef?.toLowerCase())) listType = "bulletList";
21862
21662
  else if (orderedListTypes.includes(listTypeDef)) listType = "orderedList";
21863
- else return {};
21864
- return { listType, listOrderingType: listTypeDef, ilvl, numId, listrPrs, listpPrs, start, lvlText, lvlJc };
21663
+ else if (listTypeDef === "custom") {
21664
+ listType = "orderedList";
21665
+ } else {
21666
+ return {};
21667
+ }
21668
+ return { listType, listOrderingType: listTypeDef, listrPrs, listpPrs, start, lvlText, lvlJc };
21865
21669
  }
21866
21670
  function getDefinitionForLevel(data, level) {
21867
21671
  return data?.elements?.find((item) => Number(item.attributes["w:ilvl"]) === level);
21868
21672
  }
21869
- function _processListParagraphProperties(data) {
21673
+ function parseIndentElement(indElem) {
21674
+ if (!indElem || !indElem.attributes) return {};
21675
+ const out = {};
21676
+ if (indElem.attributes["w:left"] != null) out.left = twipsToPixels(indElem.attributes["w:left"]);
21677
+ if (indElem.attributes["w:right"] != null) out.right = twipsToPixels(indElem.attributes["w:right"]);
21678
+ if (indElem.attributes["w:firstLine"] != null) out.firstLine = twipsToPixels(indElem.attributes["w:firstLine"]);
21679
+ if (indElem.attributes["w:hanging"] != null) out.hanging = twipsToPixels(indElem.attributes["w:hanging"]);
21680
+ if (indElem.attributes["w:leftChars"] != null) out.leftChars = twipsToPixels(indElem.attributes["w:leftChars"]);
21681
+ return out;
21682
+ }
21683
+ function combineIndents(ind1, ind2) {
21684
+ ind1 = ind1 && typeof ind1 === "object" ? ind1 : {};
21685
+ ind2 = ind2 && typeof ind2 === "object" ? ind2 : {};
21686
+ const indent = {};
21687
+ ["left", "right", "firstLine", "hanging"].forEach((prop) => {
21688
+ const v1 = ind1[prop] !== void 0 ? Number(ind1[prop]) : null;
21689
+ const v2 = ind2[prop] !== void 0 ? Number(ind2[prop]) : null;
21690
+ if (v1 != null && v2 != null) {
21691
+ indent[prop] = prop === "left" || prop === "hanging" ? Math.max(v1, v2) : v1;
21692
+ } else if (v1 != null) {
21693
+ indent[prop] = v1;
21694
+ } else if (v2 != null) {
21695
+ indent[prop] = v2;
21696
+ }
21697
+ });
21698
+ return indent;
21699
+ }
21700
+ function _processListParagraphProperties(data, inlinePpr) {
21870
21701
  const { elements } = data;
21871
21702
  const expectedTypes = ["w:ind", "w:jc", "w:tabs"];
21872
21703
  const paragraphProperties = {};
21873
21704
  if (!elements) return paragraphProperties;
21874
21705
  elements.forEach((item) => {
21875
- if (!expectedTypes.includes(item.name)) ;
21876
- const { attributes = {} } = item;
21877
- Object.keys(attributes).forEach((key) => {
21878
- paragraphProperties[key] = attributes[key];
21879
- });
21706
+ if (!expectedTypes.includes(item.name)) {
21707
+ console.warn(`[numbering.xml] Unexpected list paragraph prop found: ${item.name}`);
21708
+ }
21880
21709
  });
21710
+ const inlineIndent = inlinePpr?.elements?.find((item) => item.name === "w:ind");
21711
+ const parsedInlineIndent = parseIndentElement(inlineIndent);
21712
+ const styleIndent = elements.find((item) => item.name === "w:ind");
21713
+ parseIndentElement(styleIndent);
21714
+ paragraphProperties.indent = parsedInlineIndent;
21715
+ const justify = elements.find((item) => item.name === "w:jc");
21716
+ if (justify) {
21717
+ const justifyAttrs = {};
21718
+ if (!justify.attributes) justify.attributes = {};
21719
+ if (justify.attributes["w:val"] !== void 0) justifyAttrs.val = justify.attributes["w:val"];
21720
+ paragraphProperties.justify = justifyAttrs;
21721
+ }
21722
+ const tabs = elements.find((item) => item.name === "w:tabs");
21723
+ if (tabs) {
21724
+ const tabElements = tabs.elements.filter((item) => item.name === "w:tab");
21725
+ const tabStops = [];
21726
+ tabElements.forEach((tab) => {
21727
+ const tabStop = {};
21728
+ if (!tab.attributes) tab.attributes = {};
21729
+ if (tab.attributes["w:val"] !== void 0) tabStop.val = tab.attributes["w:val"];
21730
+ if (tab.attributes["w:leader"] !== void 0) tabStop.leader = tab.attributes["w:leader"];
21731
+ if (tab.attributes["w:pos"] !== void 0) tabStop.pos = twipsToPixels(tab.attributes["w:pos"]);
21732
+ tabStops.push(tabStop);
21733
+ });
21734
+ paragraphProperties.tabStops = tabStops;
21735
+ }
21881
21736
  return paragraphProperties;
21882
21737
  }
21883
21738
  function _processListRunProperties(data) {
@@ -21924,9 +21779,6 @@ const handleParagraphNode = (params) => {
21924
21779
  let schemaNode;
21925
21780
  let processedElements = preProcessNodesForFldChar(node2.elements);
21926
21781
  node2.elements = processedElements;
21927
- if (testForList(node2, docx)) {
21928
- return { nodes: [], consumed: 0 };
21929
- }
21930
21782
  const handleStandardNode2 = nodeListHandler2.handlerEntities.find(
21931
21783
  (e) => e.handlerName === "standardNodeHandler"
21932
21784
  )?.handler;
@@ -21996,6 +21848,14 @@ const handleParagraphNode = (params) => {
21996
21848
  schemaNode.attrs["spacing"] = getParagraphSpacing(node2, docx, styleId, schemaNode.attrs.marksAttrs);
21997
21849
  schemaNode.attrs["rsidRDefault"] = defaultStyleId;
21998
21850
  }
21851
+ if (docx) {
21852
+ const { justify: justify2 } = getDefaultParagraphStyle(docx, styleId);
21853
+ if (justify2) {
21854
+ schemaNode.attrs.justify = {
21855
+ val: justify2["w:val"]
21856
+ };
21857
+ }
21858
+ }
21999
21859
  if (framePr && framePr.attributes["w:dropCap"]) {
22000
21860
  schemaNode.attrs.dropcap = {
22001
21861
  type: framePr.attributes["w:dropCap"],
@@ -22018,6 +21878,7 @@ const handleParagraphNode = (params) => {
22018
21878
  schemaNode.attrs.paragraphProperties.sectPr = sectPr;
22019
21879
  schemaNode.attrs.pageBreakSource = "sectPr";
22020
21880
  }
21881
+ console.debug("paragraphNodeHandler", schemaNode);
22021
21882
  return { nodes: schemaNode ? [schemaNode] : [], consumed: 1 };
22022
21883
  };
22023
21884
  const getParagraphIndent = (node2, docx, styleId = "") => {
@@ -22067,7 +21928,7 @@ const getParagraphSpacing = (node2, docx, styleId = "", marks = []) => {
22067
21928
  const inLineSpacingTag = pPr?.elements?.find((el) => el.name === "w:spacing");
22068
21929
  const inLineSpacing = inLineSpacingTag?.attributes || {};
22069
21930
  const textStyleMark = marks.find((el) => el.type === "textStyle");
22070
- const fontSize2 = textStyleMark?.attrs?.fontSize;
21931
+ const fontSize = textStyleMark?.attrs?.fontSize;
22071
21932
  const lineSpacing = inLineSpacing?.["w:line"] || line || pDefaultSpacing?.["w:line"];
22072
21933
  if (lineSpacing) spacing.line = twipsToLines(lineSpacing);
22073
21934
  const lineRule = inLineSpacing?.["w:lineRule"] || lineRuleStyle || pDefaultSpacing?.["w:lineRule"];
@@ -22078,14 +21939,14 @@ const getParagraphSpacing = (node2, docx, styleId = "", marks = []) => {
22078
21939
  const beforeSpacing = inLineSpacing?.["w:before"] || lineSpaceBefore || pDefaultSpacing?.["w:before"];
22079
21940
  if (beforeSpacing) spacing.lineSpaceBefore = twipsToPixels(beforeSpacing);
22080
21941
  const beforeAutospacing = inLineSpacing?.["w:beforeAutospacing"];
22081
- if (beforeAutospacing === "1" && fontSize2) {
22082
- spacing.lineSpaceBefore += Math.round(parseInt(fontSize2) * 0.5 * 96 / 72);
21942
+ if (beforeAutospacing === "1" && fontSize) {
21943
+ spacing.lineSpaceBefore += Math.round(parseInt(fontSize) * 0.5 * 96 / 72);
22083
21944
  }
22084
21945
  const afterSpacing = inLineSpacing?.["w:after"] || lineSpaceAfter || pDefaultSpacing?.["w:after"];
22085
21946
  if (afterSpacing) spacing.lineSpaceAfter = twipsToPixels(afterSpacing);
22086
21947
  const afterAutospacing = inLineSpacing?.["w:afterAutospacing"];
22087
- if (afterAutospacing === "1" && fontSize2) {
22088
- spacing.lineSpaceAfter += Math.round(parseInt(fontSize2) * 0.5 * 96 / 72);
21948
+ if (afterAutospacing === "1" && fontSize) {
21949
+ spacing.lineSpaceAfter += Math.round(parseInt(fontSize) * 0.5 * 96 / 72);
22089
21950
  }
22090
21951
  return spacing;
22091
21952
  };
@@ -22345,7 +22206,7 @@ const handleAnnotationNode = (params) => {
22345
22206
  const fieldColor = sdtPr?.elements.find((el) => el.name === "w:fieldColor")?.attributes["w:val"];
22346
22207
  const isMultipleImage = sdtPr?.elements.find((el) => el.name === "w:fieldMultipleImage")?.attributes["w:val"];
22347
22208
  const fontFamily = sdtPr?.elements.find((el) => el.name === "w:fieldFontFamily")?.attributes["w:val"];
22348
- const fontSize2 = sdtPr?.elements.find((el) => el.name === "w:fieldFontSize")?.attributes["w:val"];
22209
+ const fontSize = sdtPr?.elements.find((el) => el.name === "w:fieldFontSize")?.attributes["w:val"];
22349
22210
  const textColor = sdtPr?.elements.find((el) => el.name === "w:fieldTextColor")?.attributes["w:val"];
22350
22211
  const textHighlight = sdtPr?.elements.find((el) => el.name === "w:fieldTextHighlight")?.attributes["w:val"];
22351
22212
  const attrs = {
@@ -22356,7 +22217,7 @@ const handleAnnotationNode = (params) => {
22356
22217
  fieldColor,
22357
22218
  multipleImage: isMultipleImage === "true",
22358
22219
  fontFamily: fontFamily !== "null" ? fontFamily : null,
22359
- fontSize: fontSize2 !== "null" ? fontSize2 : null,
22220
+ fontSize: fontSize !== "null" ? fontSize : null,
22360
22221
  textColor: textColor !== "null" ? textColor : null,
22361
22222
  textHighlight: textHighlight !== "null" ? textHighlight : null
22362
22223
  };
@@ -22922,8 +22783,8 @@ const defaultNodeListHandler = () => {
22922
22783
  alternateChoiceHandler,
22923
22784
  runNodeHandlerEntity,
22924
22785
  pictNodeHandlerEntity,
22925
- paragraphNodeHandlerEntity,
22926
22786
  listHandlerEntity,
22787
+ paragraphNodeHandlerEntity,
22927
22788
  textNodeHandlerEntity,
22928
22789
  lineBreakNodeHandlerEntity,
22929
22790
  annotationNodeHandlerEntity,
@@ -22937,7 +22798,7 @@ const defaultNodeListHandler = () => {
22937
22798
  autoPageHandlerEntity,
22938
22799
  autoTotalPageCountEntity,
22939
22800
  standardNodeHandlerEntity
22940
- //this should be the last one, bcs this parses everything!!!
22801
+ // This is the last one as it can handle everything
22941
22802
  ];
22942
22803
  const handler = createNodeListHandler(entities);
22943
22804
  return {
@@ -23169,6 +23030,8 @@ const importHeadersFooters = (docx, converter, editor) => {
23169
23030
  converter.headers[rId] = { type: "doc", content: [...schema] };
23170
23031
  sectionType && (converter.headerIds[sectionType] = rId);
23171
23032
  });
23033
+ const titlePg = allSectPrElements?.find((el) => el.name === "w:titlePg");
23034
+ if (titlePg) converter.headerIds.titlePg = true;
23172
23035
  footers.forEach((footer) => {
23173
23036
  const { rId, referenceFile, currentFileName } = getHeaderFooterSectionData(footer, docx);
23174
23037
  const sectPrFooter = allSectPrElements.find((el) => el.name === "w:footerReference" && el.attributes["r:id"] === rId);
@@ -23309,7 +23172,7 @@ const _SuperConverter = class _SuperConverter {
23309
23172
  return;
23310
23173
  }
23311
23174
  }
23312
- static updateDocumentVersion(docx = this.convertedXml, version = "0.12.34-next.3") {
23175
+ static updateDocumentVersion(docx = this.convertedXml, version = "0.13.0-RC2") {
23313
23176
  const customLocation = "docProps/custom.xml";
23314
23177
  if (!docx[customLocation]) {
23315
23178
  docx[customLocation] = generateCustomXml();
@@ -23466,7 +23329,7 @@ const _SuperConverter = class _SuperConverter {
23466
23329
  const exporter = new DocxExporter(this);
23467
23330
  return exporter.schemaToXml(data, debug);
23468
23331
  }
23469
- async exportToDocx(jsonData, editorSchema, documentMedia, isFinalDoc = false, commentsExportType, comments = [], editor) {
23332
+ async exportToDocx(jsonData, editorSchema, documentMedia, isFinalDoc = false, commentsExportType, comments = [], editor, exportJsonOnly = false) {
23470
23333
  const commentsWithParaIds = comments.map((c) => prepareCommentParaIds(c));
23471
23334
  const commentDefinitions = commentsWithParaIds.map((c, index) => getCommentDefinition(c, index, commentsWithParaIds, editor));
23472
23335
  const { result, params } = this.exportToXmlJson({
@@ -23478,6 +23341,7 @@ const _SuperConverter = class _SuperConverter {
23478
23341
  isFinalDoc,
23479
23342
  editor
23480
23343
  });
23344
+ if (exportJsonOnly) return result;
23481
23345
  const exporter = new DocxExporter(this);
23482
23346
  const xml = exporter.schemaToXml(result);
23483
23347
  await __privateMethod(this, _SuperConverter_instances, exportProcessMediaFiles_fn).call(this, {
@@ -23778,7 +23642,7 @@ function storeSuperdocVersion(docx) {
23778
23642
  function generateCustomXml() {
23779
23643
  return DEFAULT_CUSTOM_XML;
23780
23644
  }
23781
- function generateSuperdocVersion(pid = 2, version = "0.12.34-next.3") {
23645
+ function generateSuperdocVersion(pid = 2, version = "0.13.0-RC2") {
23782
23646
  return {
23783
23647
  type: "element",
23784
23648
  name: "property",
@@ -23802,7 +23666,7 @@ function generateSuperdocVersion(pid = 2, version = "0.12.34-next.3") {
23802
23666
  };
23803
23667
  }
23804
23668
  export {
23805
- Transform as $,
23669
+ getDefinitionForLevel as $,
23806
23670
  AllSelection as A,
23807
23671
  Buffer2 as B,
23808
23672
  TrackInsertMarkName as C,
@@ -23828,15 +23692,20 @@ export {
23828
23692
  getLineHeightValueString as W,
23829
23693
  toKebabCase as X,
23830
23694
  kebabCase as Y,
23831
- getColStyleDeclaration as Z,
23832
- SelectionRange as _,
23695
+ getStyleTagFromStyleId as Z,
23696
+ getAbstractDefinition as _,
23833
23697
  Plugin as a,
23834
- createColGroup as a0,
23835
- commonjsGlobal as a1,
23836
- getDefaultExportFromCjs$1 as a2,
23837
- getContentTypesFromXml as a3,
23838
- xmljs as a4,
23839
- vClickOutside as a5,
23698
+ parseIndentElement as a0,
23699
+ combineIndents as a1,
23700
+ getColStyleDeclaration as a2,
23701
+ SelectionRange as a3,
23702
+ Transform as a4,
23703
+ createColGroup as a5,
23704
+ commonjsGlobal as a6,
23705
+ getDefaultExportFromCjs$1 as a7,
23706
+ getContentTypesFromXml as a8,
23707
+ xmljs as a9,
23708
+ vClickOutside as aa,
23840
23709
  canSplit as b,
23841
23710
  callOrGet as c,
23842
23711
  canJoin as d,
@@ -23849,13 +23718,13 @@ export {
23849
23718
  NodeRange as k,
23850
23719
  liftTarget as l,
23851
23720
  findWrapping as m,
23852
- isMacOS as n,
23721
+ generateDocxRandomId as n,
23853
23722
  objectIncludes as o,
23854
- isIOS as p,
23855
- generateDocxRandomId as q,
23723
+ minMax as p,
23724
+ generateRandom32BitHex as q,
23856
23725
  replaceStep as r,
23857
- minMax as s,
23858
- generateRandom32BitHex as t,
23726
+ isMacOS as s,
23727
+ isIOS as t,
23859
23728
  DOMSerializer as u,
23860
23729
  Mark as v,
23861
23730
  dropPoint as w,