@harbour-enterprises/superdoc 0.14.0-next.2 → 0.14.0-next.21
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.
- package/dist/chunks/{eventemitter3-BrspJk8q.es.js → eventemitter3-BIPEy-pY.es.js} +1 -1
- package/dist/chunks/{eventemitter3-DfVviFzP.cjs → eventemitter3-DGnD-HK9.cjs} +1 -1
- package/dist/chunks/{index-Diu6UKHt.es.js → index-BvK-G6B1.es.js} +4 -4
- package/dist/chunks/{index-B4J7wgs6.cjs → index-CCRVYhTn.cjs} +2 -2
- package/dist/chunks/{index-Cdsq63Xq.cjs → index-CgJ5KVh6.cjs} +4 -4
- package/dist/chunks/{index-Hr3Um-Bg.es.js → index-oHslWah4.es.js} +2 -2
- package/dist/chunks/{jszip-DckFs3A7.es.js → jszip-CYDYUNnI.es.js} +1 -1
- package/dist/chunks/{jszip-BTAcmbVg.cjs → jszip-D5XoMX4C.cjs} +1 -1
- package/dist/chunks/{super-editor.es-C6TRTeBI.es.js → super-editor.es-Cu7C5Ezf.es.js} +3414 -2237
- package/dist/chunks/{super-editor.es-DFls-Ipj.cjs → super-editor.es-DM3LYkiV.cjs} +3402 -2225
- package/dist/chunks/{url-BIzg4y2i.cjs → url-BG1Z_Z2_.cjs} +2 -2
- package/dist/chunks/{url-CHayXMZH.es.js → url-Dvx6wrNT.es.js} +2 -2
- package/dist/chunks/{vue-Bi1uWinj.es.js → vue-lU0o_RlU.es.js} +35 -15
- package/dist/chunks/{vue-HIY1g7dm.cjs → vue-tQYF719J.cjs} +24 -4
- package/dist/chunks/{xml-js-BjqmFOSP.cjs → xml-js-BHJlXtfU.cjs} +13 -6
- package/dist/chunks/{xml-js-CfClL-1b.es.js → xml-js-DNISVjNF.es.js} +13 -6
- package/dist/composables/use-ai.d.ts +1 -3
- package/dist/composables/use-ai.d.ts.map +1 -1
- package/dist/core/SuperDoc.d.ts +5 -0
- package/dist/core/SuperDoc.d.ts.map +1 -1
- package/dist/helpers/floor.d.ts +2 -0
- package/dist/helpers/floor.d.ts.map +1 -0
- package/dist/stores/hrbr-fields-store.d.ts.map +1 -1
- package/dist/style.css +407 -291
- package/dist/super-editor/ai-writer.es.js +18 -33
- package/dist/super-editor/chunks/{converter-2R-ZXcMD.js → converter-BnCzxu5M.js} +1685 -1609
- package/dist/super-editor/chunks/{docx-zipper-D1Hg-x9a.js → docx-zipper-BPw_B6hI.js} +1 -1
- package/dist/super-editor/chunks/{editor-DYjOoB1N.js → editor-DD4MGOZb.js} +1788 -1251
- package/dist/super-editor/chunks/{toolbar-WyGfV3qj.js → toolbar-BCtZctWE.js} +33 -38
- package/dist/super-editor/components/cursor-helpers.d.ts +23 -0
- package/dist/super-editor/components/cursor-helpers.d.ts.map +1 -1
- package/dist/super-editor/components/slash-menu/constants.d.ts +64 -0
- package/dist/super-editor/components/slash-menu/constants.d.ts.map +1 -0
- package/dist/super-editor/components/slash-menu/menuItems.d.ts +35 -0
- package/dist/super-editor/components/slash-menu/menuItems.d.ts.map +1 -0
- package/dist/super-editor/components/slash-menu/utils.d.ts +10 -0
- package/dist/super-editor/components/slash-menu/utils.d.ts.map +1 -0
- package/dist/super-editor/components/toolbar/defaultItems.d.ts.map +1 -1
- package/dist/super-editor/components/toolbar/super-toolbar.d.ts.map +1 -1
- package/dist/super-editor/components/toolbar/toolbarIcons.d.ts +3 -12
- package/dist/super-editor/components/toolbar/toolbarTexts.d.ts +0 -11
- package/dist/super-editor/converter.es.js +1 -1
- package/dist/super-editor/core/Editor.d.ts +12 -4
- package/dist/super-editor/core/Editor.d.ts.map +1 -1
- package/dist/super-editor/core/InputRule.d.ts.map +1 -1
- package/dist/super-editor/core/commands/decreaseListIndent.d.ts.map +1 -1
- package/dist/super-editor/core/commands/deleteListItem.d.ts.map +1 -1
- package/dist/super-editor/core/commands/deleteSelection.d.ts +2 -0
- package/dist/super-editor/core/commands/deleteSelection.d.ts.map +1 -1
- package/dist/super-editor/core/commands/increaseListIndent.d.ts.map +1 -1
- package/dist/super-editor/core/commands/joinBackward.d.ts.map +1 -1
- package/dist/super-editor/core/commands/joinForward.d.ts.map +1 -1
- package/dist/super-editor/core/commands/splitListItem.d.ts.map +1 -1
- package/dist/super-editor/core/commands/toggleList.d.ts +5 -1
- package/dist/super-editor/core/commands/toggleList.d.ts.map +1 -1
- package/dist/super-editor/core/extensions/keymap.d.ts.map +1 -1
- package/dist/super-editor/core/helpers/list-numbering-helpers.d.ts +6 -5
- package/dist/super-editor/core/helpers/list-numbering-helpers.d.ts.map +1 -1
- package/dist/super-editor/core/super-converter/SuperConverter.d.ts.map +1 -1
- package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
- package/dist/super-editor/core/super-converter/v2/importer/annotationImporter.d.ts +1 -1
- package/dist/super-editor/core/super-converter/v2/importer/annotationImporter.d.ts.map +1 -1
- package/dist/super-editor/core/super-converter/v2/importer/hyperlinkImporter.d.ts.map +1 -1
- package/dist/super-editor/core/super-converter/v2/importer/listImporter.d.ts.map +1 -1
- package/dist/super-editor/core/super-converter/v2/importer/paragraphNodeImporter.d.ts.map +1 -1
- package/dist/super-editor/core/utilities/clipboardUtils.d.ts +27 -0
- package/dist/super-editor/core/utilities/clipboardUtils.d.ts.map +1 -0
- package/dist/super-editor/core/utilities/index.d.ts +1 -0
- package/dist/super-editor/docx-zipper.es.js +2 -2
- package/dist/super-editor/editor.es.js +3 -3
- package/dist/super-editor/extensions/ai/ai-plugin.d.ts.map +1 -1
- package/dist/super-editor/extensions/bullet-list/bullet-list.d.ts.map +1 -1
- package/dist/super-editor/extensions/field-annotation/fieldAnnotationHelpers/findRemovedFieldAnnotations.d.ts.map +1 -1
- package/dist/super-editor/extensions/index.d.ts.map +1 -1
- package/dist/super-editor/extensions/list-item/list-item.d.ts.map +1 -1
- package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts +0 -3
- package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts.map +1 -1
- package/dist/super-editor/extensions/ordered-list/helpers/orderedListSyncPlugin.d.ts.map +1 -1
- package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
- package/dist/super-editor/extensions/pagination/pagination.d.ts.map +1 -1
- package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
- package/dist/super-editor/extensions/slash-menu/index.d.ts +2 -0
- package/dist/super-editor/extensions/slash-menu/index.d.ts.map +1 -0
- package/dist/super-editor/extensions/slash-menu/slash-menu.d.ts +4 -0
- package/dist/super-editor/extensions/slash-menu/slash-menu.d.ts.map +1 -0
- package/dist/super-editor/extensions/table/table.d.ts.map +1 -1
- package/dist/super-editor/file-zipper.es.js +1 -1
- package/dist/super-editor/index.d.ts +1 -1
- package/dist/super-editor/index.d.ts.map +1 -1
- package/dist/super-editor/style.css +368 -261
- package/dist/super-editor/super-editor.es.js +1202 -608
- package/dist/super-editor/toolbar.es.js +2 -2
- package/dist/super-editor.cjs +3 -2
- package/dist/super-editor.es.js +15 -14
- package/dist/superdoc.cjs +89 -76
- package/dist/superdoc.es.js +141 -128
- package/dist/superdoc.umd.js +3716 -2509
- package/dist/superdoc.umd.js.map +1 -1
- package/package.json +2 -2
|
@@ -15941,6 +15941,68 @@ function parseSizeUnit(val = "0") {
|
|
|
15941
15941
|
function minMax(value = 0, min2 = 0, max2 = 0) {
|
|
15942
15942
|
return Math.min(Math.max(value, min2), max2);
|
|
15943
15943
|
}
|
|
15944
|
+
function serializeSelectionToClipboard(state2) {
|
|
15945
|
+
const { from, to } = state2.selection;
|
|
15946
|
+
const slice = state2.selection.content();
|
|
15947
|
+
const htmlContainer = document.createElement("div");
|
|
15948
|
+
htmlContainer.appendChild(
|
|
15949
|
+
DOMSerializer.fromSchema(state2.schema).serializeFragment(slice.content)
|
|
15950
|
+
);
|
|
15951
|
+
const htmlString = htmlContainer.innerHTML;
|
|
15952
|
+
const text = state2.doc.textBetween(from, to);
|
|
15953
|
+
return { htmlString, text };
|
|
15954
|
+
}
|
|
15955
|
+
async function writeToClipboard({ htmlString, text }) {
|
|
15956
|
+
try {
|
|
15957
|
+
if (navigator.clipboard && window.ClipboardItem) {
|
|
15958
|
+
const clipboardItem = new window.ClipboardItem({
|
|
15959
|
+
"text/html": new Blob([htmlString], { type: "text/html" }),
|
|
15960
|
+
"text/plain": new Blob([text], { type: "text/plain" })
|
|
15961
|
+
});
|
|
15962
|
+
await navigator.clipboard.write([clipboardItem]);
|
|
15963
|
+
} else {
|
|
15964
|
+
await navigator.clipboard.writeText(text);
|
|
15965
|
+
}
|
|
15966
|
+
} catch (e) {
|
|
15967
|
+
console.error("Error writing to clipboard", e);
|
|
15968
|
+
}
|
|
15969
|
+
}
|
|
15970
|
+
async function readFromClipboard(state2) {
|
|
15971
|
+
let html = "";
|
|
15972
|
+
let text = "";
|
|
15973
|
+
if (navigator.clipboard && navigator.clipboard.read) {
|
|
15974
|
+
try {
|
|
15975
|
+
const items = await navigator.clipboard.read();
|
|
15976
|
+
for (const item of items) {
|
|
15977
|
+
if (item.types.includes("text/html")) {
|
|
15978
|
+
html = await (await item.getType("text/html")).text();
|
|
15979
|
+
break;
|
|
15980
|
+
} else if (item.types.includes("text/plain")) {
|
|
15981
|
+
text = await (await item.getType("text/plain")).text();
|
|
15982
|
+
}
|
|
15983
|
+
}
|
|
15984
|
+
} catch (e) {
|
|
15985
|
+
text = await navigator.clipboard.readText();
|
|
15986
|
+
}
|
|
15987
|
+
} else {
|
|
15988
|
+
text = await navigator.clipboard.readText();
|
|
15989
|
+
}
|
|
15990
|
+
let content = null;
|
|
15991
|
+
if (html) {
|
|
15992
|
+
try {
|
|
15993
|
+
content = DOMParser.fromSchema(state2.schema).parseSlice(
|
|
15994
|
+
new window.DOMParser().parseFromString(`<body>${html}</body>`, "text/html").body
|
|
15995
|
+
).content;
|
|
15996
|
+
} catch (e) {
|
|
15997
|
+
console.error("error parsing html", e);
|
|
15998
|
+
content = state2.schema.text(text);
|
|
15999
|
+
}
|
|
16000
|
+
}
|
|
16001
|
+
if (!content && text) {
|
|
16002
|
+
content = state2.schema.text(text);
|
|
16003
|
+
}
|
|
16004
|
+
return content;
|
|
16005
|
+
}
|
|
15944
16006
|
function inchesToTwips(inches) {
|
|
15945
16007
|
if (inches == null) return;
|
|
15946
16008
|
if (typeof inches === "string") inches = parseFloat(inches);
|
|
@@ -17412,13 +17474,6 @@ const baseNumbering = {
|
|
|
17412
17474
|
"w:val": "hybridMultilevel"
|
|
17413
17475
|
}
|
|
17414
17476
|
},
|
|
17415
|
-
{
|
|
17416
|
-
"type": "element",
|
|
17417
|
-
"name": "w:tmpl",
|
|
17418
|
-
"attributes": {
|
|
17419
|
-
"w:val": "51EC4E08"
|
|
17420
|
-
}
|
|
17421
|
-
},
|
|
17422
17477
|
{
|
|
17423
17478
|
"type": "element",
|
|
17424
17479
|
"name": "w:lvl",
|
|
@@ -18057,13 +18112,6 @@ const baseNumbering = {
|
|
|
18057
18112
|
"w:val": "hybridMultilevel"
|
|
18058
18113
|
}
|
|
18059
18114
|
},
|
|
18060
|
-
{
|
|
18061
|
-
"type": "element",
|
|
18062
|
-
"name": "w:tmpl",
|
|
18063
|
-
"attributes": {
|
|
18064
|
-
"w:val": "EE6417C4"
|
|
18065
|
-
}
|
|
18066
|
-
},
|
|
18067
18115
|
{
|
|
18068
18116
|
"type": "element",
|
|
18069
18117
|
"name": "w:lvl",
|
|
@@ -19367,13 +19415,22 @@ const inputRulesPlugin = ({ editor, rules }) => {
|
|
|
19367
19415
|
function isWordHtml(html) {
|
|
19368
19416
|
return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(html);
|
|
19369
19417
|
}
|
|
19370
|
-
const handleHtmlPaste$1 = (html, editor
|
|
19418
|
+
const handleHtmlPaste$1 = (html, editor) => {
|
|
19371
19419
|
const htmlWithPtSizing = convertEmToPt(html);
|
|
19372
19420
|
const cleanedHtml = sanitizeHtml(htmlWithPtSizing);
|
|
19373
19421
|
const doc2 = DOMParser.fromSchema(editor.schema).parse(cleanedHtml);
|
|
19374
|
-
const { dispatch } = editor.view;
|
|
19422
|
+
const { dispatch, state: state2 } = editor.view;
|
|
19375
19423
|
if (!dispatch) return false;
|
|
19376
|
-
|
|
19424
|
+
const { $from } = state2.selection;
|
|
19425
|
+
const isInParagraph = $from.parent.type.name === "paragraph";
|
|
19426
|
+
const isSingleParagraph = doc2.childCount === 1 && doc2.firstChild.type.name === "paragraph";
|
|
19427
|
+
if (isInParagraph && isSingleParagraph) {
|
|
19428
|
+
const paragraphContent = doc2.firstChild.content;
|
|
19429
|
+
const tr = state2.tr.replaceSelectionWith(paragraphContent, false);
|
|
19430
|
+
dispatch(tr);
|
|
19431
|
+
} else {
|
|
19432
|
+
dispatch(state2.tr.replaceSelectionWith(doc2, true));
|
|
19433
|
+
}
|
|
19377
19434
|
return true;
|
|
19378
19435
|
};
|
|
19379
19436
|
const convertEmToPt = (html) => {
|
|
@@ -19800,13 +19857,21 @@ function processLinkContentNode(node2) {
|
|
|
19800
19857
|
name: "w:color",
|
|
19801
19858
|
attributes: { "w:val": "467886" }
|
|
19802
19859
|
};
|
|
19860
|
+
const underline = {
|
|
19861
|
+
name: "w:u",
|
|
19862
|
+
attributes: {
|
|
19863
|
+
"w:val": "none"
|
|
19864
|
+
}
|
|
19865
|
+
};
|
|
19803
19866
|
if (contentNode.name === "w:r") {
|
|
19804
19867
|
const runProps = contentNode.elements.find((el) => el.name === "w:rPr");
|
|
19805
19868
|
if (runProps) {
|
|
19806
19869
|
const foundColor = runProps.elements.find((el) => el.name === "w:color");
|
|
19807
19870
|
const foundHyperlinkStyle = runProps.elements.find((el) => el.name === "w:rStyle");
|
|
19871
|
+
const underlineMark = runProps.elements.find((el) => el.name === "w:u");
|
|
19808
19872
|
if (!foundColor) runProps.elements.unshift(color);
|
|
19809
19873
|
if (!foundHyperlinkStyle) runProps.elements.unshift(hyperlinkStyle);
|
|
19874
|
+
if (!underlineMark) runProps.elements.unshift(underline);
|
|
19810
19875
|
} else {
|
|
19811
19876
|
const runProps2 = {
|
|
19812
19877
|
name: "w:rPr",
|
|
@@ -19861,7 +19926,7 @@ function translateList(params) {
|
|
|
19861
19926
|
}
|
|
19862
19927
|
const paragraphNode = node2.content[0]?.content[0];
|
|
19863
19928
|
const outputNode = exportSchemaToJson({ ...params, node: paragraphNode });
|
|
19864
|
-
const pPr = outputNode.elements
|
|
19929
|
+
const pPr = outputNode.elements?.find((n) => n.name === "w:pPr");
|
|
19865
19930
|
if (pPr && pPr.elements && numPrTag) pPr.elements.unshift(numPrTag);
|
|
19866
19931
|
const indentTag = restoreIndent(listItem.attrs.indent);
|
|
19867
19932
|
indentTag && pPr?.elements?.push(indentTag);
|
|
@@ -20707,71 +20772,28 @@ function translateFieldAnnotation(params) {
|
|
|
20707
20772
|
}
|
|
20708
20773
|
}
|
|
20709
20774
|
sdtContentElements = [getFieldHighlightJson(), ...sdtContentElements];
|
|
20710
|
-
const
|
|
20775
|
+
const annotationAttrs = {
|
|
20776
|
+
displayLabel: attrs.displayLabel,
|
|
20777
|
+
defaultDisplayLabel: attrs.defaultDisplayLabel,
|
|
20778
|
+
fieldId: attrs.fieldId,
|
|
20779
|
+
fieldType: attrs.fieldType,
|
|
20780
|
+
fieldTypeShort: attrs.type,
|
|
20781
|
+
fieldColor: attrs.fieldColor,
|
|
20782
|
+
fieldMultipleImage: attrs.multipleImage,
|
|
20783
|
+
fieldFontFamily: attrs.fontFamily,
|
|
20784
|
+
fieldFontSize: attrs.fontSize,
|
|
20785
|
+
fieldTextColor: attrs.textColor,
|
|
20786
|
+
fieldTextHighlight: attrs.textHighlight
|
|
20787
|
+
};
|
|
20788
|
+
const annotationAttrsJson = JSON.stringify(annotationAttrs);
|
|
20711
20789
|
return {
|
|
20712
20790
|
name: "w:sdt",
|
|
20713
20791
|
elements: [
|
|
20714
20792
|
{
|
|
20715
20793
|
name: "w:sdtPr",
|
|
20716
20794
|
elements: [
|
|
20717
|
-
{ name: "w:tag", attributes: { "w:val":
|
|
20718
|
-
{ name: "w:alias", attributes: { "w:val": attrs.displayLabel } }
|
|
20719
|
-
{
|
|
20720
|
-
name: "w:fieldType",
|
|
20721
|
-
attributes: {
|
|
20722
|
-
"xmlns:w": customXmlns,
|
|
20723
|
-
"w:val": attrs.fieldType
|
|
20724
|
-
}
|
|
20725
|
-
},
|
|
20726
|
-
{
|
|
20727
|
-
name: "w:fieldTypeShort",
|
|
20728
|
-
attributes: {
|
|
20729
|
-
"xmlns:w": customXmlns,
|
|
20730
|
-
"w:val": attrs.type
|
|
20731
|
-
}
|
|
20732
|
-
},
|
|
20733
|
-
{
|
|
20734
|
-
name: "w:fieldColor",
|
|
20735
|
-
attributes: {
|
|
20736
|
-
"xmlns:w": customXmlns,
|
|
20737
|
-
"w:val": attrs.fieldColor
|
|
20738
|
-
}
|
|
20739
|
-
},
|
|
20740
|
-
{
|
|
20741
|
-
name: "w:fieldMultipleImage",
|
|
20742
|
-
attributes: {
|
|
20743
|
-
"xmlns:w": customXmlns,
|
|
20744
|
-
"w:val": attrs.multipleImage
|
|
20745
|
-
}
|
|
20746
|
-
},
|
|
20747
|
-
{
|
|
20748
|
-
name: "w:fieldFontFamily",
|
|
20749
|
-
attributes: {
|
|
20750
|
-
"xmlns:w": customXmlns,
|
|
20751
|
-
"w:val": attrs.fontFamily
|
|
20752
|
-
}
|
|
20753
|
-
},
|
|
20754
|
-
{
|
|
20755
|
-
name: "w:fieldFontSize",
|
|
20756
|
-
attributes: {
|
|
20757
|
-
"xmlns:w": customXmlns,
|
|
20758
|
-
"w:val": attrs.fontSize
|
|
20759
|
-
}
|
|
20760
|
-
},
|
|
20761
|
-
{
|
|
20762
|
-
name: "w:fieldTextColor",
|
|
20763
|
-
attributes: {
|
|
20764
|
-
"xmlns:w": customXmlns,
|
|
20765
|
-
"w:val": attrs.textColor
|
|
20766
|
-
}
|
|
20767
|
-
},
|
|
20768
|
-
{
|
|
20769
|
-
name: "w:fieldTextHighlight",
|
|
20770
|
-
attributes: {
|
|
20771
|
-
"xmlns:w": customXmlns,
|
|
20772
|
-
"w:val": attrs.textHighlight
|
|
20773
|
-
}
|
|
20774
|
-
}
|
|
20795
|
+
{ name: "w:tag", attributes: { "w:val": annotationAttrsJson } },
|
|
20796
|
+
{ name: "w:alias", attributes: { "w:val": attrs.displayLabel } }
|
|
20775
20797
|
]
|
|
20776
20798
|
},
|
|
20777
20799
|
{
|
|
@@ -21828,7 +21850,12 @@ const handleHyperlinkNode = (params) => {
|
|
|
21828
21850
|
const styleElements = elements2.filter((el) => el.name === "w:style");
|
|
21829
21851
|
const style = styleElements.find((el) => el.attributes["w:styleId"] === "Hyperlink");
|
|
21830
21852
|
const styleRpr = style?.elements?.find((el) => el.name === "w:rPr");
|
|
21831
|
-
if (styleRpr)
|
|
21853
|
+
if (styleRpr) {
|
|
21854
|
+
styleRpr.elements.forEach((styleEl) => {
|
|
21855
|
+
const hasElInRPr = rPr.elements.find((el) => el.name === styleEl.name);
|
|
21856
|
+
if (!hasElInRPr) rPr.elements.push(styleEl);
|
|
21857
|
+
});
|
|
21858
|
+
}
|
|
21832
21859
|
}
|
|
21833
21860
|
}
|
|
21834
21861
|
}
|
|
@@ -21959,1646 +21986,1684 @@ const canMergeTextNodes = (nodeA, nodeB) => {
|
|
|
21959
21986
|
const areAttrsEqual = (attrsA = {}, attrsB = {}) => {
|
|
21960
21987
|
return objectIncludes(attrsA, attrsB);
|
|
21961
21988
|
};
|
|
21962
|
-
|
|
21963
|
-
|
|
21964
|
-
|
|
21989
|
+
const handleParagraphNode = (params) => {
|
|
21990
|
+
const { nodes, docx, nodeListHandler: nodeListHandler2, filename } = params;
|
|
21991
|
+
if (nodes.length === 0 || nodes[0].name !== "w:p") {
|
|
21992
|
+
return { nodes: [], consumed: 0 };
|
|
21965
21993
|
}
|
|
21966
|
-
|
|
21967
|
-
|
|
21968
|
-
|
|
21969
|
-
|
|
21970
|
-
|
|
21971
|
-
|
|
21972
|
-
|
|
21973
|
-
|
|
21974
|
-
|
|
21975
|
-
|
|
21976
|
-
|
|
21977
|
-
|
|
21978
|
-
|
|
21979
|
-
|
|
21980
|
-
|
|
21981
|
-
|
|
21982
|
-
|
|
21983
|
-
|
|
21984
|
-
|
|
21985
|
-
|
|
21986
|
-
|
|
21987
|
-
|
|
21988
|
-
|
|
21989
|
-
|
|
21990
|
-
|
|
21991
|
-
|
|
21992
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
21993
|
-
}
|
|
21994
|
-
lastSlash = i;
|
|
21995
|
-
dots = 0;
|
|
21996
|
-
continue;
|
|
21997
|
-
}
|
|
21998
|
-
} else if (res.length === 2 || res.length === 1) {
|
|
21999
|
-
res = "";
|
|
22000
|
-
lastSegmentLength = 0;
|
|
22001
|
-
lastSlash = i;
|
|
22002
|
-
dots = 0;
|
|
22003
|
-
continue;
|
|
22004
|
-
}
|
|
22005
|
-
}
|
|
22006
|
-
if (allowAboveRoot) {
|
|
22007
|
-
if (res.length > 0)
|
|
22008
|
-
res += "/..";
|
|
22009
|
-
else
|
|
22010
|
-
res = "..";
|
|
22011
|
-
lastSegmentLength = 2;
|
|
22012
|
-
}
|
|
22013
|
-
} else {
|
|
22014
|
-
if (res.length > 0)
|
|
22015
|
-
res += "/" + path.slice(lastSlash + 1, i);
|
|
22016
|
-
else
|
|
22017
|
-
res = path.slice(lastSlash + 1, i);
|
|
22018
|
-
lastSegmentLength = i - lastSlash - 1;
|
|
21994
|
+
const node2 = carbonCopy(nodes[0]);
|
|
21995
|
+
let schemaNode;
|
|
21996
|
+
let processedElements = preProcessNodesForFldChar(node2.elements);
|
|
21997
|
+
node2.elements = processedElements;
|
|
21998
|
+
const handleStandardNode2 = nodeListHandler2.handlerEntities.find(
|
|
21999
|
+
(e) => e.handlerName === "standardNodeHandler"
|
|
22000
|
+
)?.handler;
|
|
22001
|
+
if (!handleStandardNode2) {
|
|
22002
|
+
console.error("Standard node handler not found");
|
|
22003
|
+
return { nodes: [], consumed: 0 };
|
|
22004
|
+
}
|
|
22005
|
+
const updatedParams = { ...params, nodes: [node2] };
|
|
22006
|
+
const result = handleStandardNode2(updatedParams);
|
|
22007
|
+
if (result.nodes.length === 1) {
|
|
22008
|
+
schemaNode = result.nodes[0];
|
|
22009
|
+
}
|
|
22010
|
+
const pPr = node2.elements?.find((el) => el.name === "w:pPr");
|
|
22011
|
+
const styleTag = pPr?.elements?.find((el) => el.name === "w:pStyle");
|
|
22012
|
+
const nestedRPr = pPr?.elements?.find((el) => el.name === "w:rPr");
|
|
22013
|
+
const framePr = pPr?.elements?.find((el) => el.name === "w:framePr");
|
|
22014
|
+
if (nestedRPr) {
|
|
22015
|
+
let marks = parseMarks(nestedRPr, []);
|
|
22016
|
+
if (!schemaNode.content?.length) {
|
|
22017
|
+
let highlightIndex = marks?.findIndex((i) => i.type === "highlight");
|
|
22018
|
+
if (highlightIndex !== -1) {
|
|
22019
|
+
marks.splice(highlightIndex, 1);
|
|
22019
22020
|
}
|
|
22020
|
-
lastSlash = i;
|
|
22021
|
-
dots = 0;
|
|
22022
|
-
} else if (code2 === 46 && dots !== -1) {
|
|
22023
|
-
++dots;
|
|
22024
|
-
} else {
|
|
22025
|
-
dots = -1;
|
|
22026
22021
|
}
|
|
22022
|
+
schemaNode.attrs.marksAttrs = marks;
|
|
22027
22023
|
}
|
|
22028
|
-
|
|
22029
|
-
|
|
22030
|
-
|
|
22031
|
-
|
|
22032
|
-
var base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
|
|
22033
|
-
if (!dir) {
|
|
22034
|
-
return base;
|
|
22035
|
-
}
|
|
22036
|
-
if (dir === pathObject.root) {
|
|
22037
|
-
return dir + base;
|
|
22024
|
+
let styleId;
|
|
22025
|
+
if (styleTag) {
|
|
22026
|
+
styleId = styleTag.attributes["w:val"];
|
|
22027
|
+
schemaNode.attrs["styleId"] = styleId;
|
|
22038
22028
|
}
|
|
22039
|
-
|
|
22040
|
-
|
|
22041
|
-
|
|
22042
|
-
|
|
22043
|
-
resolve: function resolve() {
|
|
22044
|
-
var resolvedPath = "";
|
|
22045
|
-
var resolvedAbsolute = false;
|
|
22046
|
-
var cwd;
|
|
22047
|
-
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
22048
|
-
var path;
|
|
22049
|
-
if (i >= 0)
|
|
22050
|
-
path = arguments[i];
|
|
22051
|
-
else {
|
|
22052
|
-
if (cwd === void 0)
|
|
22053
|
-
cwd = process$1.cwd();
|
|
22054
|
-
path = cwd;
|
|
22055
|
-
}
|
|
22056
|
-
assertPath(path);
|
|
22057
|
-
if (path.length === 0) {
|
|
22058
|
-
continue;
|
|
22059
|
-
}
|
|
22060
|
-
resolvedPath = path + "/" + resolvedPath;
|
|
22061
|
-
resolvedAbsolute = path.charCodeAt(0) === 47;
|
|
22029
|
+
if (docx) {
|
|
22030
|
+
const indent = getParagraphIndent(node2, docx, styleId);
|
|
22031
|
+
if (!schemaNode.attrs.indent) {
|
|
22032
|
+
schemaNode.attrs.indent = {};
|
|
22062
22033
|
}
|
|
22063
|
-
|
|
22064
|
-
|
|
22065
|
-
if (resolvedPath.length > 0)
|
|
22066
|
-
return "/" + resolvedPath;
|
|
22067
|
-
else
|
|
22068
|
-
return "/";
|
|
22069
|
-
} else if (resolvedPath.length > 0) {
|
|
22070
|
-
return resolvedPath;
|
|
22071
|
-
} else {
|
|
22072
|
-
return ".";
|
|
22034
|
+
if (indent.left || indent.left === 0) {
|
|
22035
|
+
schemaNode.attrs.indent.left = indent.left;
|
|
22073
22036
|
}
|
|
22074
|
-
|
|
22075
|
-
|
|
22076
|
-
assertPath(path);
|
|
22077
|
-
if (path.length === 0) return ".";
|
|
22078
|
-
var isAbsolute2 = path.charCodeAt(0) === 47;
|
|
22079
|
-
var trailingSeparator = path.charCodeAt(path.length - 1) === 47;
|
|
22080
|
-
path = normalizeStringPosix(path, !isAbsolute2);
|
|
22081
|
-
if (path.length === 0 && !isAbsolute2) path = ".";
|
|
22082
|
-
if (path.length > 0 && trailingSeparator) path += "/";
|
|
22083
|
-
if (isAbsolute2) return "/" + path;
|
|
22084
|
-
return path;
|
|
22085
|
-
},
|
|
22086
|
-
isAbsolute: function isAbsolute(path) {
|
|
22087
|
-
assertPath(path);
|
|
22088
|
-
return path.length > 0 && path.charCodeAt(0) === 47;
|
|
22089
|
-
},
|
|
22090
|
-
join: function join2() {
|
|
22091
|
-
if (arguments.length === 0)
|
|
22092
|
-
return ".";
|
|
22093
|
-
var joined;
|
|
22094
|
-
for (var i = 0; i < arguments.length; ++i) {
|
|
22095
|
-
var arg = arguments[i];
|
|
22096
|
-
assertPath(arg);
|
|
22097
|
-
if (arg.length > 0) {
|
|
22098
|
-
if (joined === void 0)
|
|
22099
|
-
joined = arg;
|
|
22100
|
-
else
|
|
22101
|
-
joined += "/" + arg;
|
|
22102
|
-
}
|
|
22037
|
+
if (indent.right || indent.right === 0) {
|
|
22038
|
+
schemaNode.attrs.indent.right = indent.right;
|
|
22103
22039
|
}
|
|
22104
|
-
if (
|
|
22105
|
-
|
|
22106
|
-
return posix.normalize(joined);
|
|
22107
|
-
},
|
|
22108
|
-
relative: function relative(from, to) {
|
|
22109
|
-
assertPath(from);
|
|
22110
|
-
assertPath(to);
|
|
22111
|
-
if (from === to) return "";
|
|
22112
|
-
from = posix.resolve(from);
|
|
22113
|
-
to = posix.resolve(to);
|
|
22114
|
-
if (from === to) return "";
|
|
22115
|
-
var fromStart = 1;
|
|
22116
|
-
for (; fromStart < from.length; ++fromStart) {
|
|
22117
|
-
if (from.charCodeAt(fromStart) !== 47)
|
|
22118
|
-
break;
|
|
22119
|
-
}
|
|
22120
|
-
var fromEnd = from.length;
|
|
22121
|
-
var fromLen = fromEnd - fromStart;
|
|
22122
|
-
var toStart = 1;
|
|
22123
|
-
for (; toStart < to.length; ++toStart) {
|
|
22124
|
-
if (to.charCodeAt(toStart) !== 47)
|
|
22125
|
-
break;
|
|
22126
|
-
}
|
|
22127
|
-
var toEnd = to.length;
|
|
22128
|
-
var toLen = toEnd - toStart;
|
|
22129
|
-
var length = fromLen < toLen ? fromLen : toLen;
|
|
22130
|
-
var lastCommonSep = -1;
|
|
22131
|
-
var i = 0;
|
|
22132
|
-
for (; i <= length; ++i) {
|
|
22133
|
-
if (i === length) {
|
|
22134
|
-
if (toLen > length) {
|
|
22135
|
-
if (to.charCodeAt(toStart + i) === 47) {
|
|
22136
|
-
return to.slice(toStart + i + 1);
|
|
22137
|
-
} else if (i === 0) {
|
|
22138
|
-
return to.slice(toStart + i);
|
|
22139
|
-
}
|
|
22140
|
-
} else if (fromLen > length) {
|
|
22141
|
-
if (from.charCodeAt(fromStart + i) === 47) {
|
|
22142
|
-
lastCommonSep = i;
|
|
22143
|
-
} else if (i === 0) {
|
|
22144
|
-
lastCommonSep = 0;
|
|
22145
|
-
}
|
|
22146
|
-
}
|
|
22147
|
-
break;
|
|
22148
|
-
}
|
|
22149
|
-
var fromCode = from.charCodeAt(fromStart + i);
|
|
22150
|
-
var toCode = to.charCodeAt(toStart + i);
|
|
22151
|
-
if (fromCode !== toCode)
|
|
22152
|
-
break;
|
|
22153
|
-
else if (fromCode === 47)
|
|
22154
|
-
lastCommonSep = i;
|
|
22155
|
-
}
|
|
22156
|
-
var out = "";
|
|
22157
|
-
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
22158
|
-
if (i === fromEnd || from.charCodeAt(i) === 47) {
|
|
22159
|
-
if (out.length === 0)
|
|
22160
|
-
out += "..";
|
|
22161
|
-
else
|
|
22162
|
-
out += "/..";
|
|
22163
|
-
}
|
|
22164
|
-
}
|
|
22165
|
-
if (out.length > 0)
|
|
22166
|
-
return out + to.slice(toStart + lastCommonSep);
|
|
22167
|
-
else {
|
|
22168
|
-
toStart += lastCommonSep;
|
|
22169
|
-
if (to.charCodeAt(toStart) === 47)
|
|
22170
|
-
++toStart;
|
|
22171
|
-
return to.slice(toStart);
|
|
22172
|
-
}
|
|
22173
|
-
},
|
|
22174
|
-
_makeLong: function _makeLong(path) {
|
|
22175
|
-
return path;
|
|
22176
|
-
},
|
|
22177
|
-
dirname: function dirname(path) {
|
|
22178
|
-
assertPath(path);
|
|
22179
|
-
if (path.length === 0) return ".";
|
|
22180
|
-
var code2 = path.charCodeAt(0);
|
|
22181
|
-
var hasRoot = code2 === 47;
|
|
22182
|
-
var end = -1;
|
|
22183
|
-
var matchedSlash = true;
|
|
22184
|
-
for (var i = path.length - 1; i >= 1; --i) {
|
|
22185
|
-
code2 = path.charCodeAt(i);
|
|
22186
|
-
if (code2 === 47) {
|
|
22187
|
-
if (!matchedSlash) {
|
|
22188
|
-
end = i;
|
|
22189
|
-
break;
|
|
22190
|
-
}
|
|
22191
|
-
} else {
|
|
22192
|
-
matchedSlash = false;
|
|
22193
|
-
}
|
|
22194
|
-
}
|
|
22195
|
-
if (end === -1) return hasRoot ? "/" : ".";
|
|
22196
|
-
if (hasRoot && end === 1) return "//";
|
|
22197
|
-
return path.slice(0, end);
|
|
22198
|
-
},
|
|
22199
|
-
basename: function basename(path, ext) {
|
|
22200
|
-
if (ext !== void 0 && typeof ext !== "string") throw new TypeError('"ext" argument must be a string');
|
|
22201
|
-
assertPath(path);
|
|
22202
|
-
var start = 0;
|
|
22203
|
-
var end = -1;
|
|
22204
|
-
var matchedSlash = true;
|
|
22205
|
-
var i;
|
|
22206
|
-
if (ext !== void 0 && ext.length > 0 && ext.length <= path.length) {
|
|
22207
|
-
if (ext.length === path.length && ext === path) return "";
|
|
22208
|
-
var extIdx = ext.length - 1;
|
|
22209
|
-
var firstNonSlashEnd = -1;
|
|
22210
|
-
for (i = path.length - 1; i >= 0; --i) {
|
|
22211
|
-
var code2 = path.charCodeAt(i);
|
|
22212
|
-
if (code2 === 47) {
|
|
22213
|
-
if (!matchedSlash) {
|
|
22214
|
-
start = i + 1;
|
|
22215
|
-
break;
|
|
22216
|
-
}
|
|
22217
|
-
} else {
|
|
22218
|
-
if (firstNonSlashEnd === -1) {
|
|
22219
|
-
matchedSlash = false;
|
|
22220
|
-
firstNonSlashEnd = i + 1;
|
|
22221
|
-
}
|
|
22222
|
-
if (extIdx >= 0) {
|
|
22223
|
-
if (code2 === ext.charCodeAt(extIdx)) {
|
|
22224
|
-
if (--extIdx === -1) {
|
|
22225
|
-
end = i;
|
|
22226
|
-
}
|
|
22227
|
-
} else {
|
|
22228
|
-
extIdx = -1;
|
|
22229
|
-
end = firstNonSlashEnd;
|
|
22230
|
-
}
|
|
22231
|
-
}
|
|
22232
|
-
}
|
|
22233
|
-
}
|
|
22234
|
-
if (start === end) end = firstNonSlashEnd;
|
|
22235
|
-
else if (end === -1) end = path.length;
|
|
22236
|
-
return path.slice(start, end);
|
|
22237
|
-
} else {
|
|
22238
|
-
for (i = path.length - 1; i >= 0; --i) {
|
|
22239
|
-
if (path.charCodeAt(i) === 47) {
|
|
22240
|
-
if (!matchedSlash) {
|
|
22241
|
-
start = i + 1;
|
|
22242
|
-
break;
|
|
22243
|
-
}
|
|
22244
|
-
} else if (end === -1) {
|
|
22245
|
-
matchedSlash = false;
|
|
22246
|
-
end = i + 1;
|
|
22247
|
-
}
|
|
22248
|
-
}
|
|
22249
|
-
if (end === -1) return "";
|
|
22250
|
-
return path.slice(start, end);
|
|
22251
|
-
}
|
|
22252
|
-
},
|
|
22253
|
-
extname: function extname(path) {
|
|
22254
|
-
assertPath(path);
|
|
22255
|
-
var startDot = -1;
|
|
22256
|
-
var startPart = 0;
|
|
22257
|
-
var end = -1;
|
|
22258
|
-
var matchedSlash = true;
|
|
22259
|
-
var preDotState = 0;
|
|
22260
|
-
for (var i = path.length - 1; i >= 0; --i) {
|
|
22261
|
-
var code2 = path.charCodeAt(i);
|
|
22262
|
-
if (code2 === 47) {
|
|
22263
|
-
if (!matchedSlash) {
|
|
22264
|
-
startPart = i + 1;
|
|
22265
|
-
break;
|
|
22266
|
-
}
|
|
22267
|
-
continue;
|
|
22268
|
-
}
|
|
22269
|
-
if (end === -1) {
|
|
22270
|
-
matchedSlash = false;
|
|
22271
|
-
end = i + 1;
|
|
22272
|
-
}
|
|
22273
|
-
if (code2 === 46) {
|
|
22274
|
-
if (startDot === -1)
|
|
22275
|
-
startDot = i;
|
|
22276
|
-
else if (preDotState !== 1)
|
|
22277
|
-
preDotState = 1;
|
|
22278
|
-
} else if (startDot !== -1) {
|
|
22279
|
-
preDotState = -1;
|
|
22280
|
-
}
|
|
22281
|
-
}
|
|
22282
|
-
if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
|
|
22283
|
-
preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
|
|
22284
|
-
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
22285
|
-
return "";
|
|
22040
|
+
if (indent.firstLine || indent.firstLine === 0) {
|
|
22041
|
+
schemaNode.attrs.indent.firstLine = indent.firstLine;
|
|
22286
22042
|
}
|
|
22287
|
-
|
|
22288
|
-
|
|
22289
|
-
format: function format(pathObject) {
|
|
22290
|
-
if (pathObject === null || typeof pathObject !== "object") {
|
|
22291
|
-
throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
|
|
22043
|
+
if (indent.hanging || indent.hanging === 0) {
|
|
22044
|
+
schemaNode.attrs.indent.hanging = indent.hanging;
|
|
22292
22045
|
}
|
|
22293
|
-
|
|
22294
|
-
|
|
22295
|
-
parse: function parse(path) {
|
|
22296
|
-
assertPath(path);
|
|
22297
|
-
var ret = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
22298
|
-
if (path.length === 0) return ret;
|
|
22299
|
-
var code2 = path.charCodeAt(0);
|
|
22300
|
-
var isAbsolute2 = code2 === 47;
|
|
22301
|
-
var start;
|
|
22302
|
-
if (isAbsolute2) {
|
|
22303
|
-
ret.root = "/";
|
|
22304
|
-
start = 1;
|
|
22305
|
-
} else {
|
|
22306
|
-
start = 0;
|
|
22046
|
+
if (indent.textIndent || indent.textIndent === 0) {
|
|
22047
|
+
schemaNode.attrs.textIndent = `${indent.textIndent}in`;
|
|
22307
22048
|
}
|
|
22308
|
-
|
|
22309
|
-
|
|
22310
|
-
|
|
22311
|
-
|
|
22312
|
-
|
|
22313
|
-
|
|
22314
|
-
|
|
22315
|
-
|
|
22316
|
-
|
|
22317
|
-
|
|
22318
|
-
|
|
22319
|
-
|
|
22320
|
-
|
|
22321
|
-
|
|
22322
|
-
|
|
22323
|
-
|
|
22324
|
-
|
|
22325
|
-
|
|
22326
|
-
|
|
22327
|
-
|
|
22328
|
-
|
|
22329
|
-
|
|
22330
|
-
|
|
22331
|
-
|
|
22332
|
-
}
|
|
22049
|
+
}
|
|
22050
|
+
const justify = pPr?.elements?.find((el) => el.name === "w:jc");
|
|
22051
|
+
if (justify && justify.attributes) {
|
|
22052
|
+
schemaNode.attrs["textAlign"] = justify.attributes["w:val"];
|
|
22053
|
+
}
|
|
22054
|
+
const keepLines = pPr?.elements?.find((el) => el.name === "w:keepLines");
|
|
22055
|
+
if (keepLines && keepLines.attributes) {
|
|
22056
|
+
schemaNode.attrs["keepLines"] = keepLines.attributes["w:val"];
|
|
22057
|
+
}
|
|
22058
|
+
const keepNext = pPr?.elements?.find((el) => el.name === "w:keepNext");
|
|
22059
|
+
if (keepNext && keepNext.attributes) {
|
|
22060
|
+
schemaNode.attrs["keepNext"] = keepNext.attributes["w:val"];
|
|
22061
|
+
}
|
|
22062
|
+
if (docx) {
|
|
22063
|
+
const defaultStyleId = node2.attributes?.["w:rsidRDefault"];
|
|
22064
|
+
schemaNode.attrs["spacing"] = getParagraphSpacing(node2, docx, styleId, schemaNode.attrs.marksAttrs);
|
|
22065
|
+
schemaNode.attrs["rsidRDefault"] = defaultStyleId;
|
|
22066
|
+
}
|
|
22067
|
+
if (docx) {
|
|
22068
|
+
const { justify: justify2 } = getDefaultParagraphStyle(docx, styleId);
|
|
22069
|
+
if (justify2) {
|
|
22070
|
+
schemaNode.attrs.justify = {
|
|
22071
|
+
val: justify2["w:val"]
|
|
22072
|
+
};
|
|
22333
22073
|
}
|
|
22334
|
-
if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
|
|
22335
|
-
preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
|
|
22336
|
-
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
22337
|
-
if (end !== -1) {
|
|
22338
|
-
if (startPart === 0 && isAbsolute2) ret.base = ret.name = path.slice(1, end);
|
|
22339
|
-
else ret.base = ret.name = path.slice(startPart, end);
|
|
22340
|
-
}
|
|
22341
|
-
} else {
|
|
22342
|
-
if (startPart === 0 && isAbsolute2) {
|
|
22343
|
-
ret.name = path.slice(1, startDot);
|
|
22344
|
-
ret.base = path.slice(1, end);
|
|
22345
|
-
} else {
|
|
22346
|
-
ret.name = path.slice(startPart, startDot);
|
|
22347
|
-
ret.base = path.slice(startPart, end);
|
|
22348
|
-
}
|
|
22349
|
-
ret.ext = path.slice(startDot, end);
|
|
22350
|
-
}
|
|
22351
|
-
if (startPart > 0) ret.dir = path.slice(0, startPart - 1);
|
|
22352
|
-
else if (isAbsolute2) ret.dir = "/";
|
|
22353
|
-
return ret;
|
|
22354
|
-
},
|
|
22355
|
-
sep: "/",
|
|
22356
|
-
delimiter: ":",
|
|
22357
|
-
win32: null,
|
|
22358
|
-
posix: null
|
|
22359
|
-
};
|
|
22360
|
-
posix.posix = posix;
|
|
22361
|
-
const handleListNode = (params) => {
|
|
22362
|
-
const { nodes, lists, docx } = params;
|
|
22363
|
-
if (nodes.length === 0 || nodes[0].name !== "w:p" || nodes[0].isList) {
|
|
22364
|
-
return { nodes: [], consumed: 0 };
|
|
22365
22074
|
}
|
|
22366
|
-
|
|
22367
|
-
|
|
22368
|
-
|
|
22369
|
-
|
|
22370
|
-
|
|
22371
|
-
|
|
22372
|
-
|
|
22373
|
-
consumed: 1
|
|
22075
|
+
if (framePr && framePr.attributes["w:dropCap"]) {
|
|
22076
|
+
schemaNode.attrs.dropcap = {
|
|
22077
|
+
type: framePr.attributes["w:dropCap"],
|
|
22078
|
+
lines: framePr.attributes["w:lines"],
|
|
22079
|
+
wrap: framePr.attributes["w:wrap"],
|
|
22080
|
+
hAnchor: framePr.attributes["w:hAnchor"],
|
|
22081
|
+
vAnchor: framePr.attributes["w:vAnchor"]
|
|
22374
22082
|
};
|
|
22375
|
-
} else {
|
|
22376
|
-
return { nodes: [], consumed: 0 };
|
|
22377
|
-
}
|
|
22378
|
-
};
|
|
22379
|
-
const listHandlerEntity = {
|
|
22380
|
-
handlerName: "listHandler",
|
|
22381
|
-
handler: handleListNode
|
|
22382
|
-
};
|
|
22383
|
-
function handleListNodes(params, node2) {
|
|
22384
|
-
const { docx, nodeListHandler: nodeListHandler2, lists } = params;
|
|
22385
|
-
const initialpPr = node2.elements.find((el) => el.name === "w:pPr");
|
|
22386
|
-
const styleTag = initialpPr?.elements?.find((el) => el.name === "w:pStyle");
|
|
22387
|
-
const styleId = styleTag?.attributes["w:val"];
|
|
22388
|
-
const { numPr: numPrTag, type: numPrType } = getNumPrRecursive({ node: node2, styleId, docx });
|
|
22389
|
-
const currentListNumId = getNumIdFromTag(numPrTag);
|
|
22390
|
-
const iLvlTag = numPrTag?.elements?.find((el) => el.name === "w:ilvl");
|
|
22391
|
-
let iLvl = Number(iLvlTag?.attributes["w:val"]);
|
|
22392
|
-
if (!iLvl && iLvl !== 0) iLvl = getOutlineLevelFromStyleTag(styleId, docx);
|
|
22393
|
-
const {
|
|
22394
|
-
listType,
|
|
22395
|
-
listOrderingType,
|
|
22396
|
-
listrPrs,
|
|
22397
|
-
listpPrs,
|
|
22398
|
-
start,
|
|
22399
|
-
lvlText,
|
|
22400
|
-
lvlJc,
|
|
22401
|
-
customFormat
|
|
22402
|
-
} = getNodeNumberingDefinition(node2, iLvl, docx);
|
|
22403
|
-
if (!listType) {
|
|
22404
|
-
const pPrIndex = node2.elements.findIndex((el) => el.name === "w:pPr");
|
|
22405
|
-
const pPr = node2.elements[pPrIndex];
|
|
22406
|
-
const numPrIndex2 = pPr?.elements?.findIndex((el) => el.name === "w:numPr");
|
|
22407
|
-
if (numPrIndex2 >= 0) {
|
|
22408
|
-
pPr?.elements?.splice(numPrIndex2, 1);
|
|
22409
|
-
node2.elements[pPrIndex] = pPr;
|
|
22410
|
-
}
|
|
22411
|
-
const styleIdIndex = pPr?.elements?.findIndex((el) => el.name === "w:pStyle");
|
|
22412
|
-
if (styleIdIndex >= 0) pPr?.elements?.splice(styleIdIndex, 1);
|
|
22413
|
-
const fallBack = nodeListHandler2.handler({ ...params, nodes: [node2] })?.filter((n) => n);
|
|
22414
|
-
return fallBack[0];
|
|
22415
22083
|
}
|
|
22416
|
-
|
|
22417
|
-
|
|
22418
|
-
|
|
22419
|
-
|
|
22420
|
-
|
|
22421
|
-
const level = Number(key);
|
|
22422
|
-
if (level > iLvl) {
|
|
22423
|
-
delete currentListByNumId.levels[level];
|
|
22424
|
-
}
|
|
22425
|
-
});
|
|
22426
|
-
const path = generateListPath(
|
|
22427
|
-
iLvl,
|
|
22428
|
-
currentListNumId,
|
|
22429
|
-
styleId,
|
|
22430
|
-
currentListByNumId.levels,
|
|
22431
|
-
docx
|
|
22432
|
-
);
|
|
22433
|
-
if (!path.length) path.push(currentListByNumId.levels[iLvl]);
|
|
22434
|
-
const attrs = {};
|
|
22435
|
-
attrs.lvlText = lvlText;
|
|
22436
|
-
attrs.listLevel = path;
|
|
22437
|
-
attrs.listNumberingType = listOrderingType;
|
|
22438
|
-
attrs.numId = currentListNumId;
|
|
22439
|
-
attrs.level = iLvl;
|
|
22440
|
-
attrs.numPrType = numPrType;
|
|
22441
|
-
attrs.styleId = styleId;
|
|
22442
|
-
attrs.customFormat = customFormat;
|
|
22443
|
-
node2.isList = true;
|
|
22444
|
-
const nodePpr = node2.attrs?.paragraphProperties?.elements?.find((el) => el.name === "w:pPr");
|
|
22445
|
-
const numPrIndex = node2.attrs?.paragraphProperties?.elements?.findIndex((el) => el.name === "w:numPr");
|
|
22446
|
-
nodePpr?.elements?.splice(numPrIndex, 1);
|
|
22447
|
-
const listContents = nodeListHandler2.handler({ ...params, nodes: [node2] });
|
|
22448
|
-
const innerParagraph = listContents.find((el) => el.type === "paragraph");
|
|
22449
|
-
const firstElement = innerParagraph.content[0];
|
|
22450
|
-
firstElement?.marks?.find((mark) => mark.type === "textStyle");
|
|
22451
|
-
attrs.indent = listpPrs?.indent;
|
|
22452
|
-
const processedContents = listContents.map((el, index) => {
|
|
22453
|
-
const { attrs: elementAttrs } = el;
|
|
22454
|
-
const { indent, textIndent, paragraphProperties, ...rest } = elementAttrs;
|
|
22455
|
-
if (index === 0 && !attrs.indent) attrs.indent = indent;
|
|
22456
|
-
return {
|
|
22457
|
-
...el,
|
|
22458
|
-
attrs: rest
|
|
22084
|
+
schemaNode.attrs["filename"] = filename;
|
|
22085
|
+
if (schemaNode && schemaNode.content) {
|
|
22086
|
+
schemaNode = {
|
|
22087
|
+
...schemaNode,
|
|
22088
|
+
content: mergeTextNodes(schemaNode.content)
|
|
22459
22089
|
};
|
|
22460
|
-
}
|
|
22461
|
-
const
|
|
22462
|
-
|
|
22463
|
-
|
|
22464
|
-
attrs
|
|
22465
|
-
|
|
22466
|
-
|
|
22467
|
-
|
|
22468
|
-
|
|
22469
|
-
|
|
22470
|
-
|
|
22471
|
-
|
|
22472
|
-
|
|
22090
|
+
}
|
|
22091
|
+
const sectPr = pPr?.elements?.find((el) => el.name === "w:sectPr");
|
|
22092
|
+
if (sectPr) {
|
|
22093
|
+
if (!schemaNode.attrs.paragraphProperties) schemaNode.attrs.paragraphProperties = {};
|
|
22094
|
+
schemaNode.attrs.paragraphProperties.sectPr = sectPr;
|
|
22095
|
+
schemaNode.attrs.pageBreakSource = "sectPr";
|
|
22096
|
+
}
|
|
22097
|
+
return { nodes: schemaNode ? [schemaNode] : [], consumed: 1 };
|
|
22098
|
+
};
|
|
22099
|
+
const getParagraphIndent = (node2, docx, styleId = "") => {
|
|
22100
|
+
const indent = {
|
|
22101
|
+
left: 0,
|
|
22102
|
+
right: 0,
|
|
22103
|
+
firstLine: 0,
|
|
22104
|
+
hanging: 0,
|
|
22105
|
+
textIndent: 0
|
|
22473
22106
|
};
|
|
22474
|
-
|
|
22475
|
-
|
|
22476
|
-
const
|
|
22477
|
-
const
|
|
22478
|
-
const
|
|
22479
|
-
const
|
|
22480
|
-
|
|
22481
|
-
|
|
22482
|
-
|
|
22107
|
+
const { indent: pDefaultIndent = {} } = getDefaultParagraphStyle(docx, styleId);
|
|
22108
|
+
const pPr = node2.elements?.find((el) => el.name === "w:pPr");
|
|
22109
|
+
const inLineIndentTag = pPr?.elements?.find((el) => el.name === "w:ind");
|
|
22110
|
+
const inLineIndent = inLineIndentTag?.attributes || {};
|
|
22111
|
+
const leftIndent = inLineIndent?.["w:left"] || pDefaultIndent?.["w:left"];
|
|
22112
|
+
const rightIndent = inLineIndent?.["w:right"] || pDefaultIndent?.["w:right"];
|
|
22113
|
+
const firstLine = inLineIndent?.["w:firstLine"] || pDefaultIndent?.["w:firstLine"];
|
|
22114
|
+
const hanging = inLineIndent?.["w:hanging"] || pDefaultIndent?.["w:hanging"];
|
|
22115
|
+
if (leftIndent) {
|
|
22116
|
+
indent.left = twipsToPixels(leftIndent);
|
|
22483
22117
|
}
|
|
22118
|
+
if (rightIndent) {
|
|
22119
|
+
indent.right = twipsToPixels(rightIndent);
|
|
22120
|
+
}
|
|
22121
|
+
if (firstLine) {
|
|
22122
|
+
indent.firstLine = twipsToPixels(firstLine);
|
|
22123
|
+
}
|
|
22124
|
+
if (hanging) {
|
|
22125
|
+
indent.hanging = twipsToPixels(hanging);
|
|
22126
|
+
}
|
|
22127
|
+
const textIndentValue = leftIndent - parseInt(hanging || 0) || 0;
|
|
22128
|
+
if (textIndentValue) {
|
|
22129
|
+
indent.textIndent = twipsToInches(textIndentValue);
|
|
22130
|
+
}
|
|
22131
|
+
return indent;
|
|
22484
22132
|
};
|
|
22485
|
-
|
|
22486
|
-
const
|
|
22487
|
-
const
|
|
22488
|
-
|
|
22489
|
-
const
|
|
22490
|
-
|
|
22491
|
-
|
|
22492
|
-
const
|
|
22493
|
-
|
|
22494
|
-
|
|
22495
|
-
|
|
22496
|
-
const
|
|
22497
|
-
if (
|
|
22498
|
-
|
|
22499
|
-
|
|
22500
|
-
numId = getNumIdFromTag(numPr);
|
|
22501
|
-
const stylePpr = styleTag?.elements?.find((el) => el.name === "w:pPr");
|
|
22502
|
-
ilvl = stylePpr?.elements?.find((el) => el.name === "w:ilvl")?.attributes["w:val"];
|
|
22503
|
-
outlinelvl = stylePpr?.elements?.find((el) => el.name === "w:outlineLvl")?.attributes["w:val"];
|
|
22504
|
-
ilvl = outlinelvl || ilvl;
|
|
22133
|
+
const getParagraphSpacing = (node2, docx, styleId = "", marks = []) => {
|
|
22134
|
+
const spacing = {};
|
|
22135
|
+
const { spacing: pDefaultSpacing = {} } = getDefaultParagraphStyle(docx, styleId);
|
|
22136
|
+
let lineSpaceAfter, lineSpaceBefore, line, lineRuleStyle;
|
|
22137
|
+
const pPr = node2.elements?.find((el) => el.name === "w:pPr");
|
|
22138
|
+
const inLineSpacingTag = pPr?.elements?.find((el) => el.name === "w:spacing");
|
|
22139
|
+
const inLineSpacing = inLineSpacingTag?.attributes || {};
|
|
22140
|
+
const textStyleMark = marks.find((el) => el.type === "textStyle");
|
|
22141
|
+
const fontSize = textStyleMark?.attrs?.fontSize;
|
|
22142
|
+
const lineSpacing = inLineSpacing?.["w:line"] || line || pDefaultSpacing?.["w:line"];
|
|
22143
|
+
if (lineSpacing) spacing.line = twipsToLines(lineSpacing);
|
|
22144
|
+
const lineRule = inLineSpacing?.["w:lineRule"] || lineRuleStyle || pDefaultSpacing?.["w:lineRule"];
|
|
22145
|
+
if (lineRule) spacing.lineRule = lineRule;
|
|
22146
|
+
if (lineRule === "exact" && lineSpacing) {
|
|
22147
|
+
spacing.line = `${twipsToPt(lineSpacing)}pt`;
|
|
22505
22148
|
}
|
|
22506
|
-
const
|
|
22507
|
-
|
|
22508
|
-
|
|
22509
|
-
|
|
22510
|
-
|
|
22511
|
-
|
|
22512
|
-
|
|
22149
|
+
const beforeSpacing = inLineSpacing?.["w:before"] || lineSpaceBefore || pDefaultSpacing?.["w:before"];
|
|
22150
|
+
if (beforeSpacing) spacing.lineSpaceBefore = twipsToPixels(beforeSpacing);
|
|
22151
|
+
const beforeAutospacing = inLineSpacing?.["w:beforeAutospacing"];
|
|
22152
|
+
if (beforeAutospacing === "1" && fontSize) {
|
|
22153
|
+
spacing.lineSpaceBefore += Math.round(parseInt(fontSize) * 0.5 * 96 / 72);
|
|
22154
|
+
}
|
|
22155
|
+
const afterSpacing = inLineSpacing?.["w:after"] || lineSpaceAfter || pDefaultSpacing?.["w:after"];
|
|
22156
|
+
if (afterSpacing) spacing.lineSpaceAfter = twipsToPixels(afterSpacing);
|
|
22157
|
+
const afterAutospacing = inLineSpacing?.["w:afterAutospacing"];
|
|
22158
|
+
if (afterAutospacing === "1" && fontSize) {
|
|
22159
|
+
spacing.lineSpaceAfter += Math.round(parseInt(fontSize) * 0.5 * 96 / 72);
|
|
22160
|
+
}
|
|
22161
|
+
return spacing;
|
|
22513
22162
|
};
|
|
22514
|
-
|
|
22163
|
+
const getDefaultParagraphStyle = (docx, styleId = "") => {
|
|
22515
22164
|
const styles = docx["word/styles.xml"];
|
|
22516
|
-
if (!styles)
|
|
22517
|
-
|
|
22518
|
-
const wStyles = styleEls.find((el) => el.name === "w:styles");
|
|
22519
|
-
const styleTags = wStyles.elements.filter((style) => style.name === "w:style");
|
|
22520
|
-
const styleDef = styleTags.find((tag) => tag.attributes["w:styleId"] === styleId);
|
|
22521
|
-
return styleDef;
|
|
22522
|
-
}
|
|
22523
|
-
function getNumPrRecursive({ node: node2, styleId, docx, seenStyleIds = /* @__PURE__ */ new Set() }) {
|
|
22524
|
-
const initialPpr = node2?.elements?.find((el) => el.name === "w:pPr");
|
|
22525
|
-
const initialNumPr = initialPpr?.elements?.find((el) => el.name === "w:numPr");
|
|
22526
|
-
let numPr = initialNumPr;
|
|
22527
|
-
let numId = getNumIdFromTag(numPr);
|
|
22528
|
-
if (numId) return { numPr, type: "inline" };
|
|
22529
|
-
const matchedStyle = getStyleTagFromStyleId(styleId, docx);
|
|
22530
|
-
const pPr = matchedStyle?.elements?.find((style) => style.name === "w:pPr");
|
|
22531
|
-
numPr = pPr?.elements?.find((style) => style.name === "w:numPr");
|
|
22532
|
-
numId = getNumIdFromTag(numPr);
|
|
22533
|
-
const basedOn = matchedStyle?.elements?.find((style) => style.name === "w:basedOn");
|
|
22534
|
-
if (!numId && !seenStyleIds.has(styleId)) {
|
|
22535
|
-
const basedOnStyleId = basedOn?.attributes["w:val"];
|
|
22536
|
-
seenStyleIds.add(styleId);
|
|
22537
|
-
if (!basedOnStyleId) return {};
|
|
22538
|
-
return getNumPrRecursive({ styleId: basedOnStyleId, docx, seenStyleIds });
|
|
22165
|
+
if (!styles) {
|
|
22166
|
+
return {};
|
|
22539
22167
|
}
|
|
22540
|
-
|
|
22541
|
-
|
|
22542
|
-
const
|
|
22543
|
-
"
|
|
22544
|
-
|
|
22545
|
-
"
|
|
22546
|
-
|
|
22547
|
-
"
|
|
22548
|
-
|
|
22549
|
-
|
|
22550
|
-
|
|
22551
|
-
|
|
22552
|
-
|
|
22553
|
-
|
|
22554
|
-
|
|
22555
|
-
|
|
22556
|
-
|
|
22557
|
-
|
|
22558
|
-
// eg: one, two, three, four, five, ...
|
|
22559
|
-
"ordinalText",
|
|
22560
|
-
// eg: first, second, third, fourth, fifth, ...
|
|
22561
|
-
"hex",
|
|
22562
|
-
// eg: 0, 1, 2, ..., 9, A, B, C, ..., F, 10, 11, ...
|
|
22563
|
-
"chicago",
|
|
22564
|
-
// eg: (0, 1, 2, ..., 9, 10, 11, 12, ..., 19, 1A, 1B, 1C, ..., 1Z, 20, 21, ..., 2Z)
|
|
22565
|
-
"none"
|
|
22566
|
-
// No bullet
|
|
22567
|
-
];
|
|
22568
|
-
const unorderedListTypes = [
|
|
22569
|
-
"bullet",
|
|
22570
|
-
// A standard bullet point (•)
|
|
22571
|
-
"square",
|
|
22572
|
-
// Square bullets (▪)
|
|
22573
|
-
"circle",
|
|
22574
|
-
// Circle bullets (◦)
|
|
22575
|
-
"disc"
|
|
22576
|
-
// Disc bullets (●)
|
|
22577
|
-
];
|
|
22578
|
-
const getListNumIdFromStyleRef = (styleId, docx) => {
|
|
22579
|
-
const styles = docx["word/styles.xml"];
|
|
22580
|
-
if (!styles) return null;
|
|
22581
|
-
const { elements } = styles;
|
|
22582
|
-
const styleTags = elements[0].elements.filter((style2) => style2.name === "w:style");
|
|
22583
|
-
const style = styleTags.find((tag) => tag.attributes["w:styleId"] === styleId) || {};
|
|
22584
|
-
const pPr = style?.elements?.find((style2) => style2.name === "w:pPr");
|
|
22585
|
-
if (!pPr) return null;
|
|
22586
|
-
let numPr = pPr?.elements?.find((style2) => style2.name === "w:numPr");
|
|
22587
|
-
if (!numPr) return null;
|
|
22588
|
-
let numIdTag = numPr?.elements?.find((style2) => style2.name === "w:numId") || {};
|
|
22589
|
-
let numId = getNumIdFromTag(numPr);
|
|
22590
|
-
let ilvlTag = numPr?.elements?.find((style2) => style2.name === "w:ilvl");
|
|
22591
|
-
let ilvl = ilvlTag?.attributes?.["w:val"];
|
|
22592
|
-
const basedOnTag = style?.elements?.find((style2) => style2.name === "w:basedOn");
|
|
22593
|
-
const basedOnId = basedOnTag?.attributes?.["w:val"];
|
|
22594
|
-
let loopCount = 0;
|
|
22595
|
-
while (numPr && !numId && loopCount < 10) {
|
|
22596
|
-
const basedOnStyle = styleTags.find((tag) => tag.attributes["w:styleId"] === basedOnId) || {};
|
|
22597
|
-
const basedOnPPr = basedOnStyle?.elements?.find((style2) => style2.name === "w:pPr");
|
|
22598
|
-
numPr = basedOnPPr?.elements?.find((style2) => style2.name === "w:numPr");
|
|
22599
|
-
numIdTag = numPr?.elements?.find((style2) => style2.name === "w:numId") || {};
|
|
22600
|
-
numId = numIdTag?.attributes?.["w:val"];
|
|
22601
|
-
if (!ilvlTag) {
|
|
22602
|
-
ilvlTag = numPr?.elements?.find((style2) => style2.name === "w:ilvl");
|
|
22603
|
-
ilvl = ilvlTag?.attributes?.["w:val"];
|
|
22604
|
-
}
|
|
22605
|
-
loopCount++;
|
|
22168
|
+
const defaults = styles.elements[0].elements?.find((el) => el.name === "w:docDefaults");
|
|
22169
|
+
const pDefault = defaults.elements.find((el) => el.name === "w:pPrDefault");
|
|
22170
|
+
const pPrDefault = pDefault?.elements?.find((el) => el.name === "w:pPr");
|
|
22171
|
+
const pPrDefaultSpacingTag = pPrDefault?.elements?.find((el) => el.name === "w:spacing") || {};
|
|
22172
|
+
const pPrDefaultIndentTag = pPrDefault?.elements?.find((el) => el.name === "w:ind") || {};
|
|
22173
|
+
const stylesNormal = styles.elements[0].elements?.find((el) => el.name === "w:style" && el.attributes["w:styleId"] === "Normal");
|
|
22174
|
+
const pPrNormal = stylesNormal?.elements?.find((el) => el.name === "w:pPr");
|
|
22175
|
+
const pPrNormalSpacingTag = pPrNormal?.elements?.find((el) => el.name === "w:spacing") || {};
|
|
22176
|
+
const pPrNormalIndentTag = pPrNormal?.elements?.find((el) => el.name === "w:ind") || {};
|
|
22177
|
+
let pPrStyleIdSpacingTag = {};
|
|
22178
|
+
let pPrStyleIdIndentTag = {};
|
|
22179
|
+
let pPrStyleJc = {};
|
|
22180
|
+
if (styleId) {
|
|
22181
|
+
const stylesById = styles.elements[0].elements?.find((el) => el.name === "w:style" && el.attributes["w:styleId"] === styleId);
|
|
22182
|
+
const pPrById = stylesById?.elements?.find((el) => el.name === "w:pPr");
|
|
22183
|
+
pPrStyleIdSpacingTag = pPrById?.elements?.find((el) => el.name === "w:spacing") || {};
|
|
22184
|
+
pPrStyleIdIndentTag = pPrById?.elements?.find((el) => el.name === "w:ind") || {};
|
|
22185
|
+
pPrStyleJc = pPrById?.elements?.find((el) => el.name === "w:jc") || {};
|
|
22606
22186
|
}
|
|
22607
|
-
|
|
22187
|
+
const { attributes: pPrDefaultSpacingAttr } = pPrDefaultSpacingTag;
|
|
22188
|
+
const { attributes: pPrNormalSpacingAttr } = pPrNormalSpacingTag;
|
|
22189
|
+
const { attributes: pPrByIdSpacingAttr } = pPrStyleIdSpacingTag;
|
|
22190
|
+
const { attributes: pPrByIdJcAttr } = pPrStyleJc;
|
|
22191
|
+
const { attributes: pPrDefaultIndentAttr } = pPrDefaultIndentTag;
|
|
22192
|
+
const { attributes: pPrNormalIndentAttr } = pPrNormalIndentTag;
|
|
22193
|
+
const { attributes: pPrByIdIndentAttr } = pPrStyleIdIndentTag;
|
|
22194
|
+
return {
|
|
22195
|
+
spacing: pPrByIdSpacingAttr || pPrDefaultSpacingAttr || pPrNormalSpacingAttr,
|
|
22196
|
+
indent: pPrByIdIndentAttr || pPrDefaultIndentAttr || pPrNormalIndentAttr,
|
|
22197
|
+
justify: pPrByIdJcAttr
|
|
22198
|
+
};
|
|
22608
22199
|
};
|
|
22609
|
-
const
|
|
22610
|
-
|
|
22611
|
-
|
|
22612
|
-
const { elements } = def;
|
|
22613
|
-
const listData = elements[0];
|
|
22614
|
-
const numberingElements = listData.elements;
|
|
22615
|
-
const abstractDefinitions = numberingElements.filter((style) => style.name === "w:abstractNum");
|
|
22616
|
-
const numDefinitions = numberingElements.filter((style) => style.name === "w:num");
|
|
22617
|
-
const numDefinition = numDefinitions.find((style) => style.attributes["w:numId"] == numId);
|
|
22618
|
-
const abstractNumId = numDefinition?.elements[0].attributes["w:val"];
|
|
22619
|
-
let listDefinitionForThisNumId = abstractDefinitions?.find(
|
|
22620
|
-
(style) => style.attributes["w:abstractNumId"] === abstractNumId
|
|
22621
|
-
);
|
|
22622
|
-
const templateIdTag = listDefinitionForThisNumId?.elements?.find((el) => el.name === "w:tmpl");
|
|
22623
|
-
const templateId = templateIdTag?.attributes?.["w:val"];
|
|
22624
|
-
if (templateId) {
|
|
22625
|
-
listDefinitionForThisNumId = numberingElements?.find((el) => {
|
|
22626
|
-
if (el.name !== "w:abstractNum") return false;
|
|
22627
|
-
const tmpl = el.elements?.find((el2) => el2.name === "w:tmpl");
|
|
22628
|
-
if (!tmpl) return false;
|
|
22629
|
-
const tmplId = tmpl.attributes?.["w:val"];
|
|
22630
|
-
return tmplId && tmplId === templateId;
|
|
22631
|
-
});
|
|
22632
|
-
}
|
|
22633
|
-
return listDefinitionForThisNumId;
|
|
22200
|
+
const paragraphNodeHandlerEntity = {
|
|
22201
|
+
handlerName: "paragraphNodeHandler",
|
|
22202
|
+
handler: handleParagraphNode
|
|
22634
22203
|
};
|
|
22635
|
-
|
|
22636
|
-
const
|
|
22637
|
-
|
|
22638
|
-
|
|
22639
|
-
|
|
22640
|
-
|
|
22641
|
-
|
|
22642
|
-
|
|
22643
|
-
|
|
22204
|
+
function getDefaultStyleDefinition(defaultStyleId, docx) {
|
|
22205
|
+
const result = { lineSpaceBefore: null, lineSpaceAfter: null };
|
|
22206
|
+
if (!defaultStyleId) return result;
|
|
22207
|
+
const styles = docx["word/styles.xml"];
|
|
22208
|
+
if (!styles) return result;
|
|
22209
|
+
const { elements } = styles.elements[0];
|
|
22210
|
+
const elementsWithId = elements.filter((el) => {
|
|
22211
|
+
const { attributes } = el;
|
|
22212
|
+
return attributes && attributes["w:styleId"] === defaultStyleId;
|
|
22213
|
+
});
|
|
22214
|
+
const firstMatch = elementsWithId[0];
|
|
22215
|
+
if (!firstMatch) return result;
|
|
22216
|
+
const qFormat = elementsWithId.find((el) => {
|
|
22217
|
+
const qFormat2 = el.elements.find((innerEl) => innerEl.name === "w:qFormat");
|
|
22218
|
+
return qFormat2;
|
|
22219
|
+
});
|
|
22220
|
+
const name = elementsWithId.find(
|
|
22221
|
+
(el) => el.elements.some((inner) => inner.name === "w:name")
|
|
22222
|
+
)?.elements.find((inner) => inner.name === "w:name")?.attributes["w:val"];
|
|
22223
|
+
const pPr = firstMatch.elements.find((el) => el.name === "w:pPr");
|
|
22224
|
+
const spacing = pPr?.elements?.find((el) => el.name === "w:spacing");
|
|
22225
|
+
const justify = pPr?.elements?.find((el) => el.name === "w:jc");
|
|
22226
|
+
const indent = pPr?.elements?.find((el) => el.name === "w:ind");
|
|
22227
|
+
let lineSpaceBefore, lineSpaceAfter, line;
|
|
22228
|
+
if (spacing) {
|
|
22229
|
+
lineSpaceBefore = twipsToPixels(spacing?.attributes["w:before"]);
|
|
22230
|
+
lineSpaceAfter = twipsToPixels(spacing?.attributes["w:after"]);
|
|
22231
|
+
line = twipsToLines(spacing?.attributes["w:line"]);
|
|
22644
22232
|
}
|
|
22645
|
-
|
|
22646
|
-
|
|
22647
|
-
|
|
22648
|
-
|
|
22649
|
-
|
|
22650
|
-
|
|
22651
|
-
if (!level && iLvlFromStyles) level = iLvlFromStyles ? parseInt(iLvlFromStyles) : null;
|
|
22233
|
+
let textAlign, leftIndent, rightIndent, firstLine;
|
|
22234
|
+
if (indent) {
|
|
22235
|
+
textAlign = justify?.attributes["w:val"];
|
|
22236
|
+
leftIndent = twipsToPixels(indent?.attributes["w:left"]);
|
|
22237
|
+
rightIndent = twipsToPixels(indent?.attributes["w:right"]);
|
|
22238
|
+
firstLine = twipsToPixels(indent?.attributes["w:firstLine"]);
|
|
22652
22239
|
}
|
|
22653
|
-
const
|
|
22654
|
-
const
|
|
22655
|
-
const
|
|
22656
|
-
const
|
|
22657
|
-
|
|
22658
|
-
|
|
22659
|
-
|
|
22240
|
+
const keepNext = pPr?.elements?.find((el) => el.name === "w:keepNext");
|
|
22241
|
+
const keepLines = pPr?.elements?.find((el) => el.name === "w:keepLines");
|
|
22242
|
+
const outlineLevel = pPr?.elements?.find((el) => el.name === "w:outlineLvl");
|
|
22243
|
+
const outlineLvlValue = outlineLevel?.attributes["w:val"];
|
|
22244
|
+
const pageBreakBefore = pPr?.elements?.find((el) => el.name === "w:pageBreakBefore");
|
|
22245
|
+
let pageBreakBeforeVal = 0;
|
|
22246
|
+
if (pageBreakBefore) {
|
|
22247
|
+
if (!pageBreakBefore.attributes?.["w:val"]) pageBreakBeforeVal = 1;
|
|
22248
|
+
else pageBreakBeforeVal = Number(pageBreakBefore?.attributes?.["w:val"]);
|
|
22660
22249
|
}
|
|
22661
|
-
const
|
|
22662
|
-
let
|
|
22663
|
-
|
|
22664
|
-
|
|
22665
|
-
|
|
22666
|
-
const choice = altChoice?.elements.find((style) => style.name === "mc:Choice");
|
|
22667
|
-
const choiceNumFmtTag = choice?.elements.find((style) => style.name === "w:numFmt");
|
|
22668
|
-
const choiceNumFmt = choiceNumFmtTag?.attributes["w:val"];
|
|
22669
|
-
if (choiceNumFmt) {
|
|
22670
|
-
numFmtTag = choiceNumFmtTag;
|
|
22671
|
-
numFmt = choiceNumFmt;
|
|
22672
|
-
}
|
|
22250
|
+
const pageBreakAfter = pPr?.elements?.find((el) => el.name === "w:pageBreakAfter");
|
|
22251
|
+
let pageBreakAfterVal;
|
|
22252
|
+
if (pageBreakAfter) {
|
|
22253
|
+
if (!pageBreakAfter.attributes?.["w:val"]) pageBreakAfterVal = 1;
|
|
22254
|
+
else pageBreakAfterVal = Number(pageBreakAfter?.attributes?.["w:val"]);
|
|
22673
22255
|
}
|
|
22674
|
-
|
|
22675
|
-
|
|
22676
|
-
|
|
22677
|
-
|
|
22678
|
-
|
|
22679
|
-
|
|
22680
|
-
|
|
22681
|
-
|
|
22682
|
-
};
|
|
22683
|
-
|
|
22684
|
-
const
|
|
22685
|
-
|
|
22686
|
-
|
|
22687
|
-
|
|
22688
|
-
|
|
22689
|
-
|
|
22690
|
-
|
|
22691
|
-
}
|
|
22692
|
-
|
|
22693
|
-
|
|
22694
|
-
|
|
22695
|
-
|
|
22696
|
-
|
|
22697
|
-
const initialPpr = item.elements.find((el) => el.name === "w:pPr");
|
|
22698
|
-
const styleTag = initialPpr?.elements?.find((el) => el.name === "w:pStyle");
|
|
22699
|
-
const styleId = styleTag?.attributes["w:val"];
|
|
22700
|
-
const { numPr: numPrTag, type: type2 } = getNumPrRecursive({ node: item, styleId, docx });
|
|
22701
|
-
if (!numPrTag) return {};
|
|
22702
|
-
const numIdTag = numPrTag?.elements.find((style) => style.name === "w:numId");
|
|
22703
|
-
const numId = numIdTag?.attributes["w:val"];
|
|
22704
|
-
const pStyle = listStyles.find((style) => style.name === "w:pStyle");
|
|
22705
|
-
const pStyleId = pStyle?.attributes["w:val"];
|
|
22706
|
-
const {
|
|
22707
|
-
start,
|
|
22708
|
-
numFmt: listTypeDef,
|
|
22709
|
-
lvlText,
|
|
22710
|
-
lvlJc,
|
|
22711
|
-
pPr,
|
|
22712
|
-
rPr,
|
|
22713
|
-
customFormat
|
|
22714
|
-
} = getListLevelDefinitionTag(numId, level, pStyleId, docx);
|
|
22715
|
-
let listpPrs, listrPrs;
|
|
22716
|
-
if (pPr) listpPrs = _processListParagraphProperties(pPr, initialPpr);
|
|
22717
|
-
if (rPr) listrPrs = _processListRunProperties(rPr);
|
|
22718
|
-
let listType;
|
|
22719
|
-
if (unorderedListTypes.includes(listTypeDef?.toLowerCase())) listType = "bulletList";
|
|
22720
|
-
else if (orderedListTypes.includes(listTypeDef)) listType = "orderedList";
|
|
22721
|
-
else if (listTypeDef === "custom") {
|
|
22722
|
-
listType = "orderedList";
|
|
22723
|
-
} else {
|
|
22724
|
-
return {};
|
|
22725
|
-
}
|
|
22726
|
-
return { listType, listOrderingType: listTypeDef, listrPrs, listpPrs, start, lvlText, lvlJc, customFormat };
|
|
22727
|
-
}
|
|
22728
|
-
function getDefinitionForLevel(data, level) {
|
|
22729
|
-
return data?.elements?.find((item) => Number(item.attributes["w:ilvl"]) === level);
|
|
22730
|
-
}
|
|
22731
|
-
function parseIndentElement(indElem) {
|
|
22732
|
-
if (!indElem || !indElem.attributes) return {};
|
|
22733
|
-
const out = {};
|
|
22734
|
-
if (indElem.attributes["w:left"] != null) out.left = twipsToPixels(indElem.attributes["w:left"]);
|
|
22735
|
-
if (indElem.attributes["w:right"] != null) out.right = twipsToPixels(indElem.attributes["w:right"]);
|
|
22736
|
-
if (indElem.attributes["w:firstLine"] != null) out.firstLine = twipsToPixels(indElem.attributes["w:firstLine"]);
|
|
22737
|
-
if (indElem.attributes["w:hanging"] != null) out.hanging = twipsToPixels(indElem.attributes["w:hanging"]);
|
|
22738
|
-
if (indElem.attributes["w:leftChars"] != null) out.leftChars = twipsToPixels(indElem.attributes["w:leftChars"]);
|
|
22739
|
-
return out;
|
|
22740
|
-
}
|
|
22741
|
-
function combineIndents(ind1, ind2) {
|
|
22742
|
-
ind1 = ind1 && typeof ind1 === "object" ? ind1 : {};
|
|
22743
|
-
ind2 = ind2 && typeof ind2 === "object" ? ind2 : {};
|
|
22744
|
-
const indent = {};
|
|
22745
|
-
["left", "right", "firstLine", "hanging"].forEach((prop) => {
|
|
22746
|
-
const v1 = ind1[prop] !== void 0 ? Number(ind1[prop]) : null;
|
|
22747
|
-
const v2 = ind2[prop] !== void 0 ? Number(ind2[prop]) : null;
|
|
22748
|
-
if (v1 != null && v2 != null) {
|
|
22749
|
-
indent[prop] = prop === "left" || prop === "hanging" ? Math.max(v1, v2) : v1;
|
|
22750
|
-
} else if (v1 != null) {
|
|
22751
|
-
indent[prop] = v1;
|
|
22752
|
-
} else if (v2 != null) {
|
|
22753
|
-
indent[prop] = v2;
|
|
22256
|
+
const parsedAttrs = {
|
|
22257
|
+
name,
|
|
22258
|
+
qFormat: qFormat ? true : false,
|
|
22259
|
+
keepNext: keepNext ? true : false,
|
|
22260
|
+
keepLines: keepLines ? true : false,
|
|
22261
|
+
outlineLevel: outlineLevel ? parseInt(outlineLvlValue) : null,
|
|
22262
|
+
pageBreakBefore: pageBreakBeforeVal ? true : false,
|
|
22263
|
+
pageBreakAfter: pageBreakAfterVal ? true : false
|
|
22264
|
+
};
|
|
22265
|
+
const rPr = firstMatch.elements.find((el) => el.name === "w:rPr");
|
|
22266
|
+
const parsedMarks = parseMarks(rPr, [], docx) || {};
|
|
22267
|
+
const parsedStyles = {
|
|
22268
|
+
spacing: { lineSpaceAfter, lineSpaceBefore, line },
|
|
22269
|
+
textAlign,
|
|
22270
|
+
indent: { leftIndent, rightIndent, firstLine }
|
|
22271
|
+
};
|
|
22272
|
+
parsedMarks.forEach((mark) => {
|
|
22273
|
+
const { type: type2, attrs } = mark;
|
|
22274
|
+
if (type2 === "textStyle") {
|
|
22275
|
+
Object.entries(attrs).forEach(([key, value]) => {
|
|
22276
|
+
parsedStyles[kebabCase(key)] = value;
|
|
22277
|
+
});
|
|
22278
|
+
return;
|
|
22754
22279
|
}
|
|
22280
|
+
parsedStyles[type2] = attrs;
|
|
22755
22281
|
});
|
|
22756
|
-
return
|
|
22282
|
+
return {
|
|
22283
|
+
attrs: parsedAttrs,
|
|
22284
|
+
styles: parsedStyles
|
|
22285
|
+
};
|
|
22757
22286
|
}
|
|
22758
|
-
function
|
|
22759
|
-
const
|
|
22760
|
-
|
|
22761
|
-
|
|
22762
|
-
|
|
22763
|
-
|
|
22764
|
-
|
|
22765
|
-
|
|
22287
|
+
function preProcessNodesForFldChar(nodes = []) {
|
|
22288
|
+
const processedNodes = [];
|
|
22289
|
+
let buffer2 = [];
|
|
22290
|
+
let collecting = false;
|
|
22291
|
+
for (const node2 of nodes) {
|
|
22292
|
+
const fldCharEl = node2.elements?.find((el) => el.name === "w:fldChar");
|
|
22293
|
+
const fldType = fldCharEl?.attributes?.["w:fldCharType"];
|
|
22294
|
+
if (fldType === "begin") {
|
|
22295
|
+
buffer2 = [node2];
|
|
22296
|
+
collecting = true;
|
|
22297
|
+
continue;
|
|
22298
|
+
}
|
|
22299
|
+
if (fldType === "separate" && collecting) {
|
|
22300
|
+
buffer2.push(node2);
|
|
22301
|
+
continue;
|
|
22302
|
+
}
|
|
22303
|
+
if (fldType === "end" && collecting) {
|
|
22304
|
+
buffer2.push(node2);
|
|
22305
|
+
processedNodes.push(...processCombinedNodesForFldChar(buffer2));
|
|
22306
|
+
buffer2 = [];
|
|
22307
|
+
collecting = false;
|
|
22308
|
+
continue;
|
|
22309
|
+
}
|
|
22310
|
+
if (collecting) {
|
|
22311
|
+
buffer2.push(node2);
|
|
22312
|
+
} else {
|
|
22313
|
+
processedNodes.push(node2);
|
|
22766
22314
|
}
|
|
22767
|
-
});
|
|
22768
|
-
const inlineIndent = inlinePpr?.elements?.find((item) => item.name === "w:ind");
|
|
22769
|
-
const parsedInlineIndent = parseIndentElement(inlineIndent);
|
|
22770
|
-
const styleIndent = elements.find((item) => item.name === "w:ind");
|
|
22771
|
-
parseIndentElement(styleIndent);
|
|
22772
|
-
paragraphProperties.indent = parsedInlineIndent;
|
|
22773
|
-
const justify = elements.find((item) => item.name === "w:jc");
|
|
22774
|
-
if (justify) {
|
|
22775
|
-
const justifyAttrs = {};
|
|
22776
|
-
if (!justify.attributes) justify.attributes = {};
|
|
22777
|
-
if (justify.attributes["w:val"] !== void 0) justifyAttrs.val = justify.attributes["w:val"];
|
|
22778
|
-
paragraphProperties.justify = justifyAttrs;
|
|
22779
22315
|
}
|
|
22780
|
-
|
|
22781
|
-
|
|
22782
|
-
const tabElements = tabs.elements.filter((item) => item.name === "w:tab");
|
|
22783
|
-
const tabStops = [];
|
|
22784
|
-
tabElements.forEach((tab) => {
|
|
22785
|
-
const tabStop = {};
|
|
22786
|
-
if (!tab.attributes) tab.attributes = {};
|
|
22787
|
-
if (tab.attributes["w:val"] !== void 0) tabStop.val = tab.attributes["w:val"];
|
|
22788
|
-
if (tab.attributes["w:leader"] !== void 0) tabStop.leader = tab.attributes["w:leader"];
|
|
22789
|
-
if (tab.attributes["w:pos"] !== void 0) tabStop.pos = twipsToPixels(tab.attributes["w:pos"]);
|
|
22790
|
-
tabStops.push(tabStop);
|
|
22791
|
-
});
|
|
22792
|
-
paragraphProperties.tabStops = tabStops;
|
|
22316
|
+
if (buffer2.length) {
|
|
22317
|
+
processedNodes.push(...buffer2);
|
|
22793
22318
|
}
|
|
22794
|
-
return
|
|
22319
|
+
return processedNodes;
|
|
22795
22320
|
}
|
|
22796
|
-
|
|
22797
|
-
|
|
22798
|
-
|
|
22799
|
-
|
|
22800
|
-
|
|
22801
|
-
"w:
|
|
22802
|
-
|
|
22803
|
-
|
|
22804
|
-
"w:
|
|
22805
|
-
|
|
22806
|
-
|
|
22807
|
-
|
|
22808
|
-
|
|
22809
|
-
|
|
22810
|
-
|
|
22811
|
-
|
|
22812
|
-
|
|
22813
|
-
|
|
22814
|
-
|
|
22815
|
-
|
|
22816
|
-
|
|
22817
|
-
|
|
22818
|
-
|
|
22819
|
-
|
|
22820
|
-
|
|
22821
|
-
|
|
22822
|
-
|
|
22823
|
-
|
|
22824
|
-
const
|
|
22825
|
-
|
|
22826
|
-
|
|
22321
|
+
const processCombinedNodesForFldChar = (nodesToCombine = []) => {
|
|
22322
|
+
let processedNodes = [];
|
|
22323
|
+
let hasPageMarker = false;
|
|
22324
|
+
let isNumPages = false;
|
|
22325
|
+
const textStart = nodesToCombine.findIndex(
|
|
22326
|
+
(n) => n.elements?.some((el) => el.name === "w:fldChar" && el.attributes["w:fldCharType"] === "separate")
|
|
22327
|
+
);
|
|
22328
|
+
const textEnd = nodesToCombine.findIndex(
|
|
22329
|
+
(n) => n.elements?.some((el) => el.name === "w:fldChar" && el.attributes["w:fldCharType"] === "end")
|
|
22330
|
+
);
|
|
22331
|
+
const textNodes = nodesToCombine.slice(textStart + 1, textEnd);
|
|
22332
|
+
const instrTextContainer = nodesToCombine.find((n) => n.elements?.some((el) => el.name === "w:instrText"));
|
|
22333
|
+
const instrTextNode = instrTextContainer?.elements?.find((el) => el.name === "w:instrText");
|
|
22334
|
+
const instrText = instrTextNode?.elements[0].text;
|
|
22335
|
+
if (!hasPageMarker) hasPageMarker = instrText?.trim().startsWith("PAGE");
|
|
22336
|
+
if (!isNumPages) isNumPages = instrText?.trim().startsWith("NUMPAGES");
|
|
22337
|
+
const urlMatch = instrText?.match(/HYPERLINK\s+"([^"]+)"/);
|
|
22338
|
+
if (hasPageMarker) {
|
|
22339
|
+
const pageNumNode = {
|
|
22340
|
+
name: "sd:autoPageNumber",
|
|
22341
|
+
type: "element"
|
|
22342
|
+
};
|
|
22343
|
+
nodesToCombine.forEach((n) => {
|
|
22344
|
+
const rPrNode = n.elements.find((el) => el.name === "w:rPr");
|
|
22345
|
+
if (rPrNode) pageNumNode.elements = [rPrNode];
|
|
22346
|
+
});
|
|
22347
|
+
processedNodes.push(pageNumNode);
|
|
22348
|
+
} else if (isNumPages) {
|
|
22349
|
+
const totalPageNumNode = {
|
|
22350
|
+
name: "sd:totalPageNumber",
|
|
22351
|
+
type: "element"
|
|
22352
|
+
};
|
|
22353
|
+
nodesToCombine.forEach((n) => {
|
|
22354
|
+
const rPrNode = n.elements.find((el) => el.name === "w:rPr");
|
|
22355
|
+
if (rPrNode) totalPageNumNode.elements = [rPrNode];
|
|
22356
|
+
});
|
|
22357
|
+
processedNodes.push(totalPageNumNode);
|
|
22358
|
+
} else if (urlMatch && urlMatch?.length >= 2) {
|
|
22359
|
+
const url = urlMatch[1];
|
|
22360
|
+
const textMarks = [];
|
|
22361
|
+
textNodes.forEach((n) => {
|
|
22362
|
+
const rPr2 = n.elements.find((el) => el.name === "w:rPr");
|
|
22363
|
+
if (!rPr2) return;
|
|
22364
|
+
const { elements } = rPr2;
|
|
22365
|
+
elements.forEach((el) => {
|
|
22366
|
+
textMarks.push(el);
|
|
22367
|
+
});
|
|
22368
|
+
});
|
|
22369
|
+
const linkMark = { name: "link", attributes: { href: url } };
|
|
22370
|
+
const rPr = { name: "w:rPr", type: "element", elements: [linkMark, ...textMarks] };
|
|
22371
|
+
processedNodes.push({
|
|
22372
|
+
name: "w:r",
|
|
22373
|
+
type: "element",
|
|
22374
|
+
elements: [rPr, ...textNodes]
|
|
22827
22375
|
});
|
|
22828
|
-
});
|
|
22829
|
-
return runProperties;
|
|
22830
|
-
}
|
|
22831
|
-
const docxNumberigHelpers = {
|
|
22832
|
-
getListLevelDefinitionTag,
|
|
22833
|
-
combineIndents,
|
|
22834
|
-
parseIndentElement,
|
|
22835
|
-
generateListPath,
|
|
22836
|
-
normalizeLvlTextChar
|
|
22837
|
-
};
|
|
22838
|
-
const handleParagraphNode = (params) => {
|
|
22839
|
-
const { nodes, docx, nodeListHandler: nodeListHandler2, filename } = params;
|
|
22840
|
-
if (nodes.length === 0 || nodes[0].name !== "w:p") {
|
|
22841
|
-
return { nodes: [], consumed: 0 };
|
|
22842
22376
|
}
|
|
22843
|
-
|
|
22844
|
-
|
|
22845
|
-
|
|
22846
|
-
|
|
22847
|
-
|
|
22848
|
-
|
|
22849
|
-
|
|
22850
|
-
if (
|
|
22851
|
-
console.error("Standard node handler not found");
|
|
22377
|
+
return processedNodes;
|
|
22378
|
+
};
|
|
22379
|
+
const tableOfContentsHandler = (params) => {
|
|
22380
|
+
return nodeListHandler.handler({ ...params, nodes: node.elements });
|
|
22381
|
+
};
|
|
22382
|
+
const handleDocPartObj = (params) => {
|
|
22383
|
+
const { nodes } = params;
|
|
22384
|
+
if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
|
|
22852
22385
|
return { nodes: [], consumed: 0 };
|
|
22853
22386
|
}
|
|
22854
|
-
const
|
|
22855
|
-
const
|
|
22856
|
-
|
|
22857
|
-
|
|
22387
|
+
const node2 = nodes[0];
|
|
22388
|
+
const sdtPr = node2.elements.find((el) => el.name === "w:sdtPr");
|
|
22389
|
+
const docPartObj = sdtPr?.elements.find((el) => el.name === "w:docPartObj");
|
|
22390
|
+
const docPartGallery = docPartObj?.elements.find((el) => el.name === "w:docPartGallery");
|
|
22391
|
+
const docPartGalleryType = docPartGallery?.attributes["w:val"];
|
|
22392
|
+
if (!docPartGalleryType) {
|
|
22393
|
+
return { nodes: [], consumed: 0 };
|
|
22858
22394
|
}
|
|
22859
|
-
|
|
22860
|
-
|
|
22861
|
-
const nestedRPr = pPr?.elements?.find((el) => el.name === "w:rPr");
|
|
22862
|
-
const framePr = pPr?.elements?.find((el) => el.name === "w:framePr");
|
|
22863
|
-
if (nestedRPr) {
|
|
22864
|
-
let marks = parseMarks(nestedRPr, []);
|
|
22865
|
-
if (!schemaNode.content?.length) {
|
|
22866
|
-
let highlightIndex = marks?.findIndex((i) => i.type === "highlight");
|
|
22867
|
-
if (highlightIndex !== -1) {
|
|
22868
|
-
marks.splice(highlightIndex, 1);
|
|
22869
|
-
}
|
|
22870
|
-
}
|
|
22871
|
-
schemaNode.attrs.marksAttrs = marks;
|
|
22395
|
+
if (!validGalleryTypeMap[docPartGalleryType]) {
|
|
22396
|
+
return { nodes: [], consumed: 0 };
|
|
22872
22397
|
}
|
|
22873
|
-
|
|
22874
|
-
|
|
22875
|
-
|
|
22876
|
-
|
|
22398
|
+
const content = node2?.elements.find((el) => el.name === "w:sdtContent");
|
|
22399
|
+
const handler = validGalleryTypeMap[docPartGalleryType];
|
|
22400
|
+
const result = handler({ ...params, nodes: [content] });
|
|
22401
|
+
return {
|
|
22402
|
+
nodes: result,
|
|
22403
|
+
consumed: 1
|
|
22404
|
+
};
|
|
22405
|
+
};
|
|
22406
|
+
const validGalleryTypeMap = {
|
|
22407
|
+
"Table of Contents": tableOfContentsHandler
|
|
22408
|
+
};
|
|
22409
|
+
const handleAnnotationNode = (params) => {
|
|
22410
|
+
const { nodes, docx, nodeListHandler: nodeListHandler2, insideTrackChange } = params;
|
|
22411
|
+
if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
|
|
22412
|
+
return { nodes: [], consumed: 0 };
|
|
22877
22413
|
}
|
|
22878
|
-
|
|
22879
|
-
|
|
22880
|
-
|
|
22881
|
-
|
|
22882
|
-
|
|
22883
|
-
|
|
22884
|
-
schemaNode.attrs.indent.left = indent.left;
|
|
22885
|
-
}
|
|
22886
|
-
if (indent.right || indent.right === 0) {
|
|
22887
|
-
schemaNode.attrs.indent.right = indent.right;
|
|
22888
|
-
}
|
|
22889
|
-
if (indent.firstLine || indent.firstLine === 0) {
|
|
22890
|
-
schemaNode.attrs.indent.firstLine = indent.firstLine;
|
|
22891
|
-
}
|
|
22892
|
-
if (indent.hanging || indent.hanging === 0) {
|
|
22893
|
-
schemaNode.attrs.indent.hanging = indent.hanging;
|
|
22894
|
-
}
|
|
22895
|
-
if (indent.textIndent || indent.textIndent === 0) {
|
|
22896
|
-
schemaNode.attrs.textIndent = `${indent.textIndent}in`;
|
|
22897
|
-
}
|
|
22414
|
+
const node2 = nodes[0];
|
|
22415
|
+
const sdtPr = node2.elements.find((el) => el.name === "w:sdtPr");
|
|
22416
|
+
const sdtContent = node2.elements.find((el) => el.name === "w:sdtContent");
|
|
22417
|
+
const docPartObj = sdtPr?.elements.find((el) => el.name === "w:docPartObj");
|
|
22418
|
+
if (docPartObj) {
|
|
22419
|
+
return handleDocPartObj({ nodes, docx, nodeListHandler: nodeListHandler2, insideTrackChange });
|
|
22898
22420
|
}
|
|
22899
|
-
const
|
|
22900
|
-
|
|
22901
|
-
|
|
22421
|
+
const alias = sdtPr?.elements.find((el) => el.name === "w:alias");
|
|
22422
|
+
const tag = sdtPr?.elements.find((el) => el.name === "w:tag");
|
|
22423
|
+
const tagValue = tag?.attributes["w:val"];
|
|
22424
|
+
const processAsJSON = tagValue?.startsWith("{") && tagValue?.endsWith("}");
|
|
22425
|
+
let attrs = {};
|
|
22426
|
+
if (processAsJSON) {
|
|
22427
|
+
const parsedAttrs = parseTagAttrsJSON(tagValue);
|
|
22428
|
+
const attrsFromJSON = {
|
|
22429
|
+
type: parsedAttrs.fieldTypeShort,
|
|
22430
|
+
fieldId: parsedAttrs.fieldId,
|
|
22431
|
+
displayLabel: parsedAttrs.displayLabel,
|
|
22432
|
+
defaultDisplayLabel: parsedAttrs.defaultDisplayLabel,
|
|
22433
|
+
fieldType: parsedAttrs.fieldType,
|
|
22434
|
+
fieldColor: parsedAttrs.fieldColor,
|
|
22435
|
+
multipleImage: parsedAttrs.fieldMultipleImage,
|
|
22436
|
+
fontFamily: parsedAttrs.fieldFontFamily,
|
|
22437
|
+
fontSize: parsedAttrs.fieldFontSize,
|
|
22438
|
+
textColor: parsedAttrs.fieldTextColor,
|
|
22439
|
+
textHighlight: parsedAttrs.fieldTextHighlight
|
|
22440
|
+
};
|
|
22441
|
+
attrs = attrsFromJSON;
|
|
22442
|
+
console.debug("Import annotation attrs", { asJSON: processAsJSON, attrs });
|
|
22443
|
+
} else {
|
|
22444
|
+
const attrsFromElements = getAttrsFromElements({ sdtPr, tag, alias });
|
|
22445
|
+
attrs = attrsFromElements;
|
|
22446
|
+
console.debug("Import annotation attrs", { asJSON: processAsJSON, attrs });
|
|
22902
22447
|
}
|
|
22903
|
-
const
|
|
22904
|
-
|
|
22905
|
-
|
|
22448
|
+
const { attrs: marksAsAttrs, marks } = parseAnnotationMarks(sdtContent);
|
|
22449
|
+
const allAttrs = { ...attrs, ...marksAsAttrs };
|
|
22450
|
+
if (!attrs.fieldId || !attrs.displayLabel) {
|
|
22451
|
+
return { nodes: [], consumed: 0 };
|
|
22906
22452
|
}
|
|
22907
|
-
|
|
22908
|
-
|
|
22909
|
-
|
|
22453
|
+
let result = {
|
|
22454
|
+
type: "text",
|
|
22455
|
+
text: `{{${attrs.displayLabel}}}`,
|
|
22456
|
+
attrs: allAttrs,
|
|
22457
|
+
marks
|
|
22458
|
+
};
|
|
22459
|
+
if (params.editor.options.annotations) {
|
|
22460
|
+
result = {
|
|
22461
|
+
type: "fieldAnnotation",
|
|
22462
|
+
attrs: allAttrs
|
|
22463
|
+
};
|
|
22910
22464
|
}
|
|
22911
|
-
|
|
22912
|
-
|
|
22913
|
-
|
|
22914
|
-
|
|
22465
|
+
return {
|
|
22466
|
+
nodes: [result],
|
|
22467
|
+
consumed: 1
|
|
22468
|
+
};
|
|
22469
|
+
};
|
|
22470
|
+
const parseAnnotationMarks = (content = {}) => {
|
|
22471
|
+
let mainContent = content;
|
|
22472
|
+
const run2 = mainContent.elements?.find((el) => el.name === "w:r");
|
|
22473
|
+
const rPr = run2?.elements?.find((el) => el.name === "w:rPr");
|
|
22474
|
+
if (!rPr) return {};
|
|
22475
|
+
const unknownMarks = [];
|
|
22476
|
+
const marks = parseMarks(rPr, unknownMarks) || [];
|
|
22477
|
+
const marksWithFlatFontStyles = [];
|
|
22478
|
+
marks.forEach((mark) => {
|
|
22479
|
+
const { type: type2 } = mark;
|
|
22480
|
+
if (type2 === "textStyle") {
|
|
22481
|
+
const { attrs: attrs2 } = mark;
|
|
22482
|
+
Object.keys(attrs2).forEach((key) => {
|
|
22483
|
+
marksWithFlatFontStyles.push({ type: key, attrs: attrs2[key] });
|
|
22484
|
+
});
|
|
22485
|
+
} else {
|
|
22486
|
+
marksWithFlatFontStyles.push(mark);
|
|
22487
|
+
}
|
|
22488
|
+
});
|
|
22489
|
+
const attrs = {};
|
|
22490
|
+
marksWithFlatFontStyles?.forEach((mark) => {
|
|
22491
|
+
const { type: type2 } = mark;
|
|
22492
|
+
attrs[type2] = mark.attrs || true;
|
|
22493
|
+
});
|
|
22494
|
+
return {
|
|
22495
|
+
attrs,
|
|
22496
|
+
marks
|
|
22497
|
+
};
|
|
22498
|
+
};
|
|
22499
|
+
function getAttrsFromElements({ sdtPr, tag, alias }) {
|
|
22500
|
+
const type2 = sdtPr?.elements.find((el) => el.name === "w:fieldTypeShort")?.attributes["w:val"];
|
|
22501
|
+
const fieldType = sdtPr?.elements.find((el) => el.name === "w:fieldType")?.attributes["w:val"];
|
|
22502
|
+
const fieldColor = sdtPr?.elements.find((el) => el.name === "w:fieldColor")?.attributes["w:val"];
|
|
22503
|
+
const isMultipleImage = sdtPr?.elements.find((el) => el.name === "w:fieldMultipleImage")?.attributes["w:val"];
|
|
22504
|
+
const fontFamily = sdtPr?.elements.find((el) => el.name === "w:fieldFontFamily")?.attributes["w:val"];
|
|
22505
|
+
const fontSize = sdtPr?.elements.find((el) => el.name === "w:fieldFontSize")?.attributes["w:val"];
|
|
22506
|
+
const textColor = sdtPr?.elements.find((el) => el.name === "w:fieldTextColor")?.attributes["w:val"];
|
|
22507
|
+
const textHighlight = sdtPr?.elements.find((el) => el.name === "w:fieldTextHighlight")?.attributes["w:val"];
|
|
22508
|
+
const attrs = {
|
|
22509
|
+
type: type2,
|
|
22510
|
+
fieldId: tag?.attributes["w:val"],
|
|
22511
|
+
displayLabel: alias?.attributes["w:val"],
|
|
22512
|
+
fieldType,
|
|
22513
|
+
fieldColor,
|
|
22514
|
+
multipleImage: isMultipleImage === "true",
|
|
22515
|
+
fontFamily: fontFamily !== "null" ? fontFamily : null,
|
|
22516
|
+
fontSize: fontSize !== "null" ? fontSize : null,
|
|
22517
|
+
textColor: textColor !== "null" ? textColor : null,
|
|
22518
|
+
textHighlight: textHighlight !== "null" ? textHighlight : null
|
|
22519
|
+
};
|
|
22520
|
+
return attrs;
|
|
22521
|
+
}
|
|
22522
|
+
function parseTagAttrsJSON(json) {
|
|
22523
|
+
try {
|
|
22524
|
+
const attrs = JSON.parse(json);
|
|
22525
|
+
return attrs;
|
|
22526
|
+
} catch (err) {
|
|
22527
|
+
console.error(err);
|
|
22528
|
+
return {};
|
|
22915
22529
|
}
|
|
22916
|
-
|
|
22917
|
-
|
|
22918
|
-
|
|
22919
|
-
|
|
22920
|
-
|
|
22921
|
-
|
|
22530
|
+
}
|
|
22531
|
+
const annotationNodeHandlerEntity = {
|
|
22532
|
+
handlerName: "annotationNodeHandler",
|
|
22533
|
+
handler: handleAnnotationNode
|
|
22534
|
+
};
|
|
22535
|
+
const handleSdtNode = (params) => {
|
|
22536
|
+
const { nodes, nodeListHandler: nodeListHandler2 } = params;
|
|
22537
|
+
if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
|
|
22538
|
+
return { nodes: [], consumed: 0 };
|
|
22539
|
+
}
|
|
22540
|
+
const node2 = nodes[0];
|
|
22541
|
+
const sdtPr = node2.elements.find((el) => el.name === "w:sdtPr");
|
|
22542
|
+
const sdtContent = node2.elements.find((el) => el.name === "w:sdtContent");
|
|
22543
|
+
const { marks } = parseAnnotationMarks(sdtContent);
|
|
22544
|
+
const translatedContent = nodeListHandler2.handler({ ...params, nodes: sdtContent?.elements });
|
|
22545
|
+
let result = {
|
|
22546
|
+
type: "structuredContent",
|
|
22547
|
+
content: translatedContent,
|
|
22548
|
+
marks,
|
|
22549
|
+
attrs: {
|
|
22550
|
+
sdtPr
|
|
22922
22551
|
}
|
|
22552
|
+
};
|
|
22553
|
+
return {
|
|
22554
|
+
nodes: [result],
|
|
22555
|
+
consumed: 1
|
|
22556
|
+
};
|
|
22557
|
+
};
|
|
22558
|
+
const sdtNodeHandlerEntity = {
|
|
22559
|
+
handlerName: "sdtNodeHandler",
|
|
22560
|
+
handler: handleSdtNode
|
|
22561
|
+
};
|
|
22562
|
+
const handleStandardNode = (params) => {
|
|
22563
|
+
const { nodes, docx, nodeListHandler: nodeListHandler2 } = params;
|
|
22564
|
+
if (!nodes || nodes.length === 0) {
|
|
22565
|
+
return { nodes: [], consumed: 0 };
|
|
22923
22566
|
}
|
|
22924
|
-
|
|
22925
|
-
|
|
22926
|
-
|
|
22927
|
-
|
|
22928
|
-
|
|
22929
|
-
|
|
22930
|
-
|
|
22567
|
+
const node2 = nodes[0];
|
|
22568
|
+
const { name } = node2;
|
|
22569
|
+
const { attributes, elements, marks = [] } = parseProperties(node2);
|
|
22570
|
+
if (name === "w:sdt") {
|
|
22571
|
+
return { nodes: [], consumed: 0 };
|
|
22572
|
+
}
|
|
22573
|
+
if (isPropertiesElement(node2)) {
|
|
22574
|
+
return {
|
|
22575
|
+
nodes: [{
|
|
22576
|
+
type: getElementName(node2),
|
|
22577
|
+
attrs: { ...attributes },
|
|
22578
|
+
marks: []
|
|
22579
|
+
}],
|
|
22580
|
+
consumed: 0
|
|
22931
22581
|
};
|
|
22932
22582
|
}
|
|
22933
|
-
|
|
22934
|
-
|
|
22935
|
-
|
|
22936
|
-
|
|
22937
|
-
|
|
22583
|
+
if (!getElementName(node2)) {
|
|
22584
|
+
return {
|
|
22585
|
+
nodes: [{
|
|
22586
|
+
type: name,
|
|
22587
|
+
content: elements,
|
|
22588
|
+
attrs: { ...attributes },
|
|
22589
|
+
marks
|
|
22590
|
+
}],
|
|
22591
|
+
consumed: 0,
|
|
22592
|
+
unhandled: true
|
|
22938
22593
|
};
|
|
22939
22594
|
}
|
|
22940
|
-
const
|
|
22941
|
-
|
|
22942
|
-
|
|
22943
|
-
|
|
22944
|
-
|
|
22595
|
+
const content = [];
|
|
22596
|
+
const parentStyleId = getParentStyleId(node2);
|
|
22597
|
+
if (elements && elements.length) {
|
|
22598
|
+
const updatedElements = elements.map((el) => {
|
|
22599
|
+
if (!el.marks) el.marks = [];
|
|
22600
|
+
el.marks.push(...marks);
|
|
22601
|
+
return el;
|
|
22602
|
+
});
|
|
22603
|
+
const childParams = { ...params, nodes: updatedElements, parentStyleId };
|
|
22604
|
+
const childContent = nodeListHandler2.handler(childParams);
|
|
22605
|
+
content.push(...childContent);
|
|
22945
22606
|
}
|
|
22946
|
-
|
|
22947
|
-
|
|
22948
|
-
|
|
22949
|
-
|
|
22950
|
-
|
|
22951
|
-
right: 0,
|
|
22952
|
-
firstLine: 0,
|
|
22953
|
-
hanging: 0,
|
|
22954
|
-
textIndent: 0
|
|
22607
|
+
const resultNode = {
|
|
22608
|
+
type: getElementName(node2),
|
|
22609
|
+
content,
|
|
22610
|
+
attrs: { ...attributes },
|
|
22611
|
+
marks: []
|
|
22955
22612
|
};
|
|
22956
|
-
|
|
22613
|
+
return { nodes: [resultNode], consumed: 1 };
|
|
22614
|
+
};
|
|
22615
|
+
const getParentStyleId = (node2) => {
|
|
22957
22616
|
const pPr = node2.elements?.find((el) => el.name === "w:pPr");
|
|
22958
|
-
const
|
|
22959
|
-
|
|
22960
|
-
|
|
22961
|
-
|
|
22962
|
-
|
|
22963
|
-
|
|
22964
|
-
|
|
22965
|
-
|
|
22617
|
+
const styleTag = pPr?.elements?.find((el) => el.name === "w:pStyle");
|
|
22618
|
+
return styleTag ? styleTag.attributes["w:val"] : null;
|
|
22619
|
+
};
|
|
22620
|
+
const standardNodeHandlerEntity = {
|
|
22621
|
+
handlerName: "standardNodeHandler",
|
|
22622
|
+
handler: handleStandardNode
|
|
22623
|
+
};
|
|
22624
|
+
const handleLineBreakNode = (params) => {
|
|
22625
|
+
const { nodes } = params;
|
|
22626
|
+
if (nodes.length === 0 || nodes[0].name !== "w:br") {
|
|
22627
|
+
return { nodes: [], consumed: 0 };
|
|
22966
22628
|
}
|
|
22967
|
-
|
|
22968
|
-
|
|
22629
|
+
const lineBreakType = nodes[0].attributes?.["w:type"];
|
|
22630
|
+
const breakType = lineBreakType === "page" ? "hardBreak" : "lineBreak";
|
|
22631
|
+
return {
|
|
22632
|
+
nodes: [{
|
|
22633
|
+
type: breakType
|
|
22634
|
+
}],
|
|
22635
|
+
consumed: 1
|
|
22636
|
+
};
|
|
22637
|
+
};
|
|
22638
|
+
const lineBreakNodeHandlerEntity = {
|
|
22639
|
+
handlerName: "lineBreakNodeHandler",
|
|
22640
|
+
handler: handleLineBreakNode
|
|
22641
|
+
};
|
|
22642
|
+
const handleBookmarkNode = (params) => {
|
|
22643
|
+
const { nodes, nodeListHandler: nodeListHandler2, editor } = params;
|
|
22644
|
+
if (nodes.length === 0 || nodes[0].name !== "w:bookmarkStart") {
|
|
22645
|
+
return { nodes: [], consumed: 0 };
|
|
22969
22646
|
}
|
|
22970
|
-
|
|
22971
|
-
|
|
22647
|
+
const node2 = nodes[0];
|
|
22648
|
+
const handleStandardNode2 = nodeListHandler2.handlerEntities.find(
|
|
22649
|
+
(e) => e.handlerName === "standardNodeHandler"
|
|
22650
|
+
)?.handler;
|
|
22651
|
+
if (!handleStandardNode2) {
|
|
22652
|
+
console.error("Standard node handler not found");
|
|
22653
|
+
return { nodes: [], consumed: 0 };
|
|
22972
22654
|
}
|
|
22973
|
-
|
|
22974
|
-
|
|
22655
|
+
const customMarks = editor?.extensionService?.extensions?.filter((e) => e.isExternal === true) || [];
|
|
22656
|
+
const bookmarkName = node2.attributes["w:name"]?.split(";")[0];
|
|
22657
|
+
const customMark = customMarks.find((mark) => mark.name === bookmarkName);
|
|
22658
|
+
if (customMark) {
|
|
22659
|
+
const bookmarkEndIndex = nodes.findIndex((n) => n.name === "w:bookmarkEnd" && n.attributes["w:id"] === node2.attributes["w:id"]);
|
|
22660
|
+
const textNodes = nodes.slice(1, bookmarkEndIndex);
|
|
22661
|
+
const nodeListHandler3 = params.nodeListHandler;
|
|
22662
|
+
const attrs = {};
|
|
22663
|
+
node2.attributes["w:name"].split(";").forEach((name) => {
|
|
22664
|
+
const [key, value] = name.split("=");
|
|
22665
|
+
if (key && value) {
|
|
22666
|
+
attrs[key] = value;
|
|
22667
|
+
}
|
|
22668
|
+
});
|
|
22669
|
+
const translatedText = nodeListHandler3.handler({ ...params, nodes: textNodes });
|
|
22670
|
+
translatedText.forEach((n) => {
|
|
22671
|
+
n.marks.push({
|
|
22672
|
+
type: customMark.name,
|
|
22673
|
+
attrs
|
|
22674
|
+
});
|
|
22675
|
+
});
|
|
22676
|
+
return {
|
|
22677
|
+
nodes: translatedText,
|
|
22678
|
+
consumed: translatedText.length + 2
|
|
22679
|
+
};
|
|
22975
22680
|
}
|
|
22976
|
-
const
|
|
22977
|
-
|
|
22978
|
-
|
|
22681
|
+
const updatedParams = { ...params, nodes: [node2] };
|
|
22682
|
+
const result = handleStandardNode2(updatedParams);
|
|
22683
|
+
if (result.nodes.length === 1) {
|
|
22684
|
+
result.nodes[0].attrs.name = node2.attributes["w:name"];
|
|
22685
|
+
result.nodes[0].attrs.id = node2.attributes["w:id"];
|
|
22979
22686
|
}
|
|
22980
|
-
return
|
|
22687
|
+
return result;
|
|
22981
22688
|
};
|
|
22982
|
-
const
|
|
22983
|
-
|
|
22984
|
-
|
|
22985
|
-
|
|
22986
|
-
|
|
22987
|
-
const
|
|
22988
|
-
const
|
|
22989
|
-
|
|
22990
|
-
|
|
22991
|
-
const lineSpacing = inLineSpacing?.["w:line"] || line || pDefaultSpacing?.["w:line"];
|
|
22992
|
-
if (lineSpacing) spacing.line = twipsToLines(lineSpacing);
|
|
22993
|
-
const lineRule = inLineSpacing?.["w:lineRule"] || lineRuleStyle || pDefaultSpacing?.["w:lineRule"];
|
|
22994
|
-
if (lineRule) spacing.lineRule = lineRule;
|
|
22995
|
-
if (lineRule === "exact" && lineSpacing) {
|
|
22996
|
-
spacing.line = `${twipsToPt(lineSpacing)}pt`;
|
|
22689
|
+
const bookmarkNodeHandlerEntity = {
|
|
22690
|
+
handlerName: "bookmarkNodeHandler",
|
|
22691
|
+
handler: handleBookmarkNode
|
|
22692
|
+
};
|
|
22693
|
+
const handleAlternateChoice = (params) => {
|
|
22694
|
+
const skipHandlerResponse = { nodes: [], consumed: 0 };
|
|
22695
|
+
const { nodes, nodeListHandler: nodeListHandler2, parentStyleId, docx } = params;
|
|
22696
|
+
if (nodes.length === 0 || nodes[0].name !== "w:p") {
|
|
22697
|
+
return skipHandlerResponse;
|
|
22997
22698
|
}
|
|
22998
|
-
const
|
|
22999
|
-
|
|
23000
|
-
const
|
|
23001
|
-
if (
|
|
23002
|
-
|
|
22699
|
+
const mainNode = nodes[0];
|
|
22700
|
+
const node2 = mainNode?.elements?.find((el) => el.name === "w:r");
|
|
22701
|
+
const hasAltChoice = node2?.elements?.some((el) => el.name === "mc:AlternateContent");
|
|
22702
|
+
if (!hasAltChoice) {
|
|
22703
|
+
return skipHandlerResponse;
|
|
23003
22704
|
}
|
|
23004
|
-
const
|
|
23005
|
-
|
|
23006
|
-
const
|
|
23007
|
-
|
|
23008
|
-
|
|
22705
|
+
const altChoiceNode = node2.elements.find((el) => el.name === "mc:AlternateContent");
|
|
22706
|
+
node2.elements.findIndex((el) => el.name === "mc:AlternateContent");
|
|
22707
|
+
const allowedNamespaces = ["wps", "wp14", "w14", "w15"];
|
|
22708
|
+
const wpsNode = altChoiceNode.elements.find(
|
|
22709
|
+
(el) => el.name === "mc:Choice" && allowedNamespaces.includes(el.attributes["Requires"])
|
|
22710
|
+
);
|
|
22711
|
+
if (!wpsNode) {
|
|
22712
|
+
return skipHandlerResponse;
|
|
23009
22713
|
}
|
|
23010
|
-
|
|
22714
|
+
const contents = wpsNode.elements;
|
|
22715
|
+
const result = nodeListHandler2.handler({
|
|
22716
|
+
...params,
|
|
22717
|
+
nodes: contents
|
|
22718
|
+
});
|
|
22719
|
+
return { nodes: result, consumed: 1 };
|
|
23011
22720
|
};
|
|
23012
|
-
const
|
|
23013
|
-
|
|
23014
|
-
|
|
23015
|
-
|
|
22721
|
+
const alternateChoiceHandler = {
|
|
22722
|
+
handlerName: "alternateChoiceHandler",
|
|
22723
|
+
handler: handleAlternateChoice
|
|
22724
|
+
};
|
|
22725
|
+
const handleAutoPageNumber = (params) => {
|
|
22726
|
+
const { nodes } = params;
|
|
22727
|
+
if (nodes.length === 0 || nodes[0].name !== "sd:autoPageNumber") {
|
|
22728
|
+
return { nodes: [], consumed: 0 };
|
|
23016
22729
|
}
|
|
23017
|
-
const
|
|
23018
|
-
const
|
|
23019
|
-
const
|
|
23020
|
-
|
|
23021
|
-
|
|
23022
|
-
|
|
23023
|
-
|
|
23024
|
-
|
|
23025
|
-
|
|
23026
|
-
|
|
23027
|
-
|
|
23028
|
-
|
|
23029
|
-
|
|
23030
|
-
|
|
23031
|
-
|
|
23032
|
-
|
|
23033
|
-
|
|
23034
|
-
|
|
22730
|
+
const rPr = nodes[0].elements?.find((el) => el.name === "w:rPr");
|
|
22731
|
+
const marks = parseMarks(rPr || { elements: [] });
|
|
22732
|
+
const processedNode = {
|
|
22733
|
+
type: "page-number",
|
|
22734
|
+
attrs: {
|
|
22735
|
+
marksAsAttrs: marks
|
|
22736
|
+
}
|
|
22737
|
+
};
|
|
22738
|
+
return { nodes: [processedNode], consumed: 1 };
|
|
22739
|
+
};
|
|
22740
|
+
const autoPageHandlerEntity = {
|
|
22741
|
+
handlerName: "autoPageNumberHandler",
|
|
22742
|
+
handler: handleAutoPageNumber
|
|
22743
|
+
};
|
|
22744
|
+
const handleAutoTotalPageNumber = (params) => {
|
|
22745
|
+
const { nodes } = params;
|
|
22746
|
+
if (nodes.length === 0 || nodes[0].name !== "sd:totalPageNumber") {
|
|
22747
|
+
return { nodes: [], consumed: 0 };
|
|
23035
22748
|
}
|
|
23036
|
-
const
|
|
23037
|
-
const {
|
|
23038
|
-
const
|
|
23039
|
-
|
|
23040
|
-
|
|
23041
|
-
|
|
23042
|
-
|
|
23043
|
-
return {
|
|
23044
|
-
spacing: pPrByIdSpacingAttr || pPrDefaultSpacingAttr || pPrNormalSpacingAttr,
|
|
23045
|
-
indent: pPrByIdIndentAttr || pPrDefaultIndentAttr || pPrNormalIndentAttr,
|
|
23046
|
-
justify: pPrByIdJcAttr
|
|
22749
|
+
const rPr = nodes[0].elements?.find((el) => el.name === "w:rPr");
|
|
22750
|
+
const marks = parseMarks(rPr || { elements: [] });
|
|
22751
|
+
const processedNode = {
|
|
22752
|
+
type: "total-page-number",
|
|
22753
|
+
attrs: {
|
|
22754
|
+
marksAsAttrs: marks
|
|
22755
|
+
}
|
|
23047
22756
|
};
|
|
22757
|
+
return { nodes: [processedNode], consumed: 1 };
|
|
23048
22758
|
};
|
|
23049
|
-
const
|
|
23050
|
-
handlerName: "
|
|
23051
|
-
handler:
|
|
22759
|
+
const autoTotalPageCountEntity = {
|
|
22760
|
+
handlerName: "autoTotalPageCountEntity",
|
|
22761
|
+
handler: handleAutoTotalPageNumber
|
|
23052
22762
|
};
|
|
23053
|
-
|
|
23054
|
-
const
|
|
23055
|
-
if (
|
|
23056
|
-
|
|
23057
|
-
if (!styles) return result;
|
|
23058
|
-
const { elements } = styles.elements[0];
|
|
23059
|
-
const elementsWithId = elements.filter((el) => {
|
|
23060
|
-
const { attributes } = el;
|
|
23061
|
-
return attributes && attributes["w:styleId"] === defaultStyleId;
|
|
23062
|
-
});
|
|
23063
|
-
const firstMatch = elementsWithId[0];
|
|
23064
|
-
if (!firstMatch) return result;
|
|
23065
|
-
const qFormat = elementsWithId.find((el) => {
|
|
23066
|
-
const qFormat2 = el.elements.find((innerEl) => innerEl.name === "w:qFormat");
|
|
23067
|
-
return qFormat2;
|
|
23068
|
-
});
|
|
23069
|
-
const name = elementsWithId.find(
|
|
23070
|
-
(el) => el.elements.some((inner) => inner.name === "w:name")
|
|
23071
|
-
)?.elements.find((inner) => inner.name === "w:name")?.attributes["w:val"];
|
|
23072
|
-
const pPr = firstMatch.elements.find((el) => el.name === "w:pPr");
|
|
23073
|
-
const spacing = pPr?.elements?.find((el) => el.name === "w:spacing");
|
|
23074
|
-
const justify = pPr?.elements?.find((el) => el.name === "w:jc");
|
|
23075
|
-
const indent = pPr?.elements?.find((el) => el.name === "w:ind");
|
|
23076
|
-
let lineSpaceBefore, lineSpaceAfter, line;
|
|
23077
|
-
if (spacing) {
|
|
23078
|
-
lineSpaceBefore = twipsToPixels(spacing?.attributes["w:before"]);
|
|
23079
|
-
lineSpaceAfter = twipsToPixels(spacing?.attributes["w:after"]);
|
|
23080
|
-
line = twipsToLines(spacing?.attributes["w:line"]);
|
|
22763
|
+
const handleTabNode = (params) => {
|
|
22764
|
+
const { nodes, docx, parentStyleId } = params;
|
|
22765
|
+
if (nodes.length === 0 || nodes[0].name !== "w:tab") {
|
|
22766
|
+
return { nodes: [], consumed: 0 };
|
|
23081
22767
|
}
|
|
23082
|
-
|
|
23083
|
-
|
|
23084
|
-
|
|
23085
|
-
|
|
23086
|
-
|
|
23087
|
-
|
|
23088
|
-
|
|
23089
|
-
|
|
23090
|
-
const keepLines = pPr?.elements?.find((el) => el.name === "w:keepLines");
|
|
23091
|
-
const outlineLevel = pPr?.elements?.find((el) => el.name === "w:outlineLvl");
|
|
23092
|
-
const outlineLvlValue = outlineLevel?.attributes["w:val"];
|
|
23093
|
-
const pageBreakBefore = pPr?.elements?.find((el) => el.name === "w:pageBreakBefore");
|
|
23094
|
-
let pageBreakBeforeVal = 0;
|
|
23095
|
-
if (pageBreakBefore) {
|
|
23096
|
-
if (!pageBreakBefore.attributes?.["w:val"]) pageBreakBeforeVal = 1;
|
|
23097
|
-
else pageBreakBeforeVal = Number(pageBreakBefore?.attributes?.["w:val"]);
|
|
23098
|
-
}
|
|
23099
|
-
const pageBreakAfter = pPr?.elements?.find((el) => el.name === "w:pageBreakAfter");
|
|
23100
|
-
let pageBreakAfterVal;
|
|
23101
|
-
if (pageBreakAfter) {
|
|
23102
|
-
if (!pageBreakAfter.attributes?.["w:val"]) pageBreakAfterVal = 1;
|
|
23103
|
-
else pageBreakAfterVal = Number(pageBreakAfter?.attributes?.["w:val"]);
|
|
22768
|
+
const node2 = nodes[0];
|
|
22769
|
+
const styles = docx["word/styles.xml"];
|
|
22770
|
+
if (styles && styles.elements?.length) {
|
|
22771
|
+
const style = styles.elements[0]?.elements?.find((s) => s.attributes?.["w:styleId"] === parentStyleId);
|
|
22772
|
+
const pPr = style?.elements?.find((s) => s.name === "w:pPr");
|
|
22773
|
+
const tabsDef = pPr?.elements?.find((s) => s.name === "w:tabs");
|
|
22774
|
+
const firstTab = tabsDef?.elements?.find((s) => s.name === "w:tab");
|
|
22775
|
+
twipsToPixels(firstTab?.attributes?.["w:pos"]);
|
|
23104
22776
|
}
|
|
23105
|
-
const
|
|
23106
|
-
|
|
23107
|
-
|
|
23108
|
-
|
|
23109
|
-
|
|
23110
|
-
|
|
23111
|
-
|
|
23112
|
-
pageBreakAfter: pageBreakAfterVal ? true : false
|
|
23113
|
-
};
|
|
23114
|
-
const rPr = firstMatch.elements.find((el) => el.name === "w:rPr");
|
|
23115
|
-
const parsedMarks = parseMarks(rPr, [], docx) || {};
|
|
23116
|
-
const parsedStyles = {
|
|
23117
|
-
spacing: { lineSpaceAfter, lineSpaceBefore, line },
|
|
23118
|
-
textAlign,
|
|
23119
|
-
indent: { leftIndent, rightIndent, firstLine }
|
|
23120
|
-
};
|
|
23121
|
-
parsedMarks.forEach((mark) => {
|
|
23122
|
-
const { type: type2, attrs } = mark;
|
|
23123
|
-
if (type2 === "textStyle") {
|
|
23124
|
-
Object.entries(attrs).forEach(([key, value]) => {
|
|
23125
|
-
parsedStyles[kebabCase(key)] = value;
|
|
23126
|
-
});
|
|
23127
|
-
return;
|
|
23128
|
-
}
|
|
23129
|
-
parsedStyles[type2] = attrs;
|
|
23130
|
-
});
|
|
23131
|
-
return {
|
|
23132
|
-
attrs: parsedAttrs,
|
|
23133
|
-
styles: parsedStyles
|
|
22777
|
+
const { attributes = {} } = node2;
|
|
22778
|
+
const processedNode = {
|
|
22779
|
+
type: "tab",
|
|
22780
|
+
attrs: {
|
|
22781
|
+
tabSize: attributes["w:val"] || 48
|
|
22782
|
+
},
|
|
22783
|
+
content: []
|
|
23134
22784
|
};
|
|
22785
|
+
return { nodes: [processedNode], consumed: 1 };
|
|
22786
|
+
};
|
|
22787
|
+
const tabNodeEntityHandler = {
|
|
22788
|
+
handlerName: "tabNodeHandler",
|
|
22789
|
+
handler: handleTabNode
|
|
22790
|
+
};
|
|
22791
|
+
function assertPath(path) {
|
|
22792
|
+
if (typeof path !== "string") {
|
|
22793
|
+
throw new TypeError("Path must be a string. Received " + JSON.stringify(path));
|
|
22794
|
+
}
|
|
23135
22795
|
}
|
|
23136
|
-
function
|
|
23137
|
-
|
|
23138
|
-
|
|
23139
|
-
|
|
23140
|
-
|
|
23141
|
-
|
|
23142
|
-
|
|
23143
|
-
if (
|
|
23144
|
-
|
|
23145
|
-
|
|
23146
|
-
|
|
23147
|
-
|
|
23148
|
-
|
|
23149
|
-
|
|
23150
|
-
|
|
23151
|
-
|
|
23152
|
-
|
|
23153
|
-
|
|
23154
|
-
|
|
23155
|
-
|
|
23156
|
-
|
|
23157
|
-
|
|
23158
|
-
|
|
23159
|
-
|
|
23160
|
-
|
|
22796
|
+
function normalizeStringPosix(path, allowAboveRoot) {
|
|
22797
|
+
var res = "";
|
|
22798
|
+
var lastSegmentLength = 0;
|
|
22799
|
+
var lastSlash = -1;
|
|
22800
|
+
var dots = 0;
|
|
22801
|
+
var code2;
|
|
22802
|
+
for (var i = 0; i <= path.length; ++i) {
|
|
22803
|
+
if (i < path.length)
|
|
22804
|
+
code2 = path.charCodeAt(i);
|
|
22805
|
+
else if (code2 === 47)
|
|
22806
|
+
break;
|
|
22807
|
+
else
|
|
22808
|
+
code2 = 47;
|
|
22809
|
+
if (code2 === 47) {
|
|
22810
|
+
if (lastSlash === i - 1 || dots === 1) ;
|
|
22811
|
+
else if (lastSlash !== i - 1 && dots === 2) {
|
|
22812
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
|
|
22813
|
+
if (res.length > 2) {
|
|
22814
|
+
var lastSlashIndex = res.lastIndexOf("/");
|
|
22815
|
+
if (lastSlashIndex !== res.length - 1) {
|
|
22816
|
+
if (lastSlashIndex === -1) {
|
|
22817
|
+
res = "";
|
|
22818
|
+
lastSegmentLength = 0;
|
|
22819
|
+
} else {
|
|
22820
|
+
res = res.slice(0, lastSlashIndex);
|
|
22821
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
22822
|
+
}
|
|
22823
|
+
lastSlash = i;
|
|
22824
|
+
dots = 0;
|
|
22825
|
+
continue;
|
|
22826
|
+
}
|
|
22827
|
+
} else if (res.length === 2 || res.length === 1) {
|
|
22828
|
+
res = "";
|
|
22829
|
+
lastSegmentLength = 0;
|
|
22830
|
+
lastSlash = i;
|
|
22831
|
+
dots = 0;
|
|
22832
|
+
continue;
|
|
22833
|
+
}
|
|
22834
|
+
}
|
|
22835
|
+
if (allowAboveRoot) {
|
|
22836
|
+
if (res.length > 0)
|
|
22837
|
+
res += "/..";
|
|
22838
|
+
else
|
|
22839
|
+
res = "..";
|
|
22840
|
+
lastSegmentLength = 2;
|
|
22841
|
+
}
|
|
22842
|
+
} else {
|
|
22843
|
+
if (res.length > 0)
|
|
22844
|
+
res += "/" + path.slice(lastSlash + 1, i);
|
|
22845
|
+
else
|
|
22846
|
+
res = path.slice(lastSlash + 1, i);
|
|
22847
|
+
lastSegmentLength = i - lastSlash - 1;
|
|
22848
|
+
}
|
|
22849
|
+
lastSlash = i;
|
|
22850
|
+
dots = 0;
|
|
22851
|
+
} else if (code2 === 46 && dots !== -1) {
|
|
22852
|
+
++dots;
|
|
23161
22853
|
} else {
|
|
23162
|
-
|
|
22854
|
+
dots = -1;
|
|
23163
22855
|
}
|
|
23164
22856
|
}
|
|
23165
|
-
|
|
23166
|
-
processedNodes.push(...buffer2);
|
|
23167
|
-
}
|
|
23168
|
-
return processedNodes;
|
|
22857
|
+
return res;
|
|
23169
22858
|
}
|
|
23170
|
-
|
|
23171
|
-
|
|
23172
|
-
|
|
23173
|
-
|
|
23174
|
-
|
|
23175
|
-
(n) => n.elements?.some((el) => el.name === "w:fldChar" && el.attributes["w:fldCharType"] === "separate")
|
|
23176
|
-
);
|
|
23177
|
-
const textEnd = nodesToCombine.findIndex(
|
|
23178
|
-
(n) => n.elements?.some((el) => el.name === "w:fldChar" && el.attributes["w:fldCharType"] === "end")
|
|
23179
|
-
);
|
|
23180
|
-
const textNodes = nodesToCombine.slice(textStart + 1, textEnd);
|
|
23181
|
-
const instrTextContainer = nodesToCombine.find((n) => n.elements?.some((el) => el.name === "w:instrText"));
|
|
23182
|
-
const instrTextNode = instrTextContainer?.elements?.find((el) => el.name === "w:instrText");
|
|
23183
|
-
const instrText = instrTextNode?.elements[0].text;
|
|
23184
|
-
if (!hasPageMarker) hasPageMarker = instrText?.trim().startsWith("PAGE");
|
|
23185
|
-
if (!isNumPages) isNumPages = instrText?.trim().startsWith("NUMPAGES");
|
|
23186
|
-
const urlMatch = instrText?.match(/HYPERLINK\s+"([^"]+)"/);
|
|
23187
|
-
if (hasPageMarker) {
|
|
23188
|
-
const pageNumNode = {
|
|
23189
|
-
name: "sd:autoPageNumber",
|
|
23190
|
-
type: "element"
|
|
23191
|
-
};
|
|
23192
|
-
nodesToCombine.forEach((n) => {
|
|
23193
|
-
const rPrNode = n.elements.find((el) => el.name === "w:rPr");
|
|
23194
|
-
if (rPrNode) pageNumNode.elements = [rPrNode];
|
|
23195
|
-
});
|
|
23196
|
-
processedNodes.push(pageNumNode);
|
|
23197
|
-
} else if (isNumPages) {
|
|
23198
|
-
const totalPageNumNode = {
|
|
23199
|
-
name: "sd:totalPageNumber",
|
|
23200
|
-
type: "element"
|
|
23201
|
-
};
|
|
23202
|
-
nodesToCombine.forEach((n) => {
|
|
23203
|
-
const rPrNode = n.elements.find((el) => el.name === "w:rPr");
|
|
23204
|
-
if (rPrNode) totalPageNumNode.elements = [rPrNode];
|
|
23205
|
-
});
|
|
23206
|
-
processedNodes.push(totalPageNumNode);
|
|
23207
|
-
} else if (urlMatch && urlMatch?.length >= 2) {
|
|
23208
|
-
const url = urlMatch[1];
|
|
23209
|
-
const textMarks = [];
|
|
23210
|
-
textNodes.forEach((n) => {
|
|
23211
|
-
const rPr2 = n.elements.find((el) => el.name === "w:rPr");
|
|
23212
|
-
if (!rPr2) return;
|
|
23213
|
-
const { elements } = rPr2;
|
|
23214
|
-
elements.forEach((el) => {
|
|
23215
|
-
textMarks.push(el);
|
|
23216
|
-
});
|
|
23217
|
-
});
|
|
23218
|
-
const linkMark = { name: "link", attributes: { href: url } };
|
|
23219
|
-
const rPr = { name: "w:rPr", type: "element", elements: [linkMark, ...textMarks] };
|
|
23220
|
-
processedNodes.push({
|
|
23221
|
-
name: "w:r",
|
|
23222
|
-
type: "element",
|
|
23223
|
-
elements: [rPr, ...textNodes]
|
|
23224
|
-
});
|
|
23225
|
-
}
|
|
23226
|
-
return processedNodes;
|
|
23227
|
-
};
|
|
23228
|
-
const tableOfContentsHandler = (params) => {
|
|
23229
|
-
return nodeListHandler.handler({ ...params, nodes: node.elements });
|
|
23230
|
-
};
|
|
23231
|
-
const handleDocPartObj = (params) => {
|
|
23232
|
-
const { nodes } = params;
|
|
23233
|
-
if (nodes.length === 0 || nodes[0].name !== "w:sdt") {
|
|
23234
|
-
return { nodes: [], consumed: 0 };
|
|
23235
|
-
}
|
|
23236
|
-
const node2 = nodes[0];
|
|
23237
|
-
const sdtPr = node2.elements.find((el) => el.name === "w:sdtPr");
|
|
23238
|
-
const docPartObj = sdtPr?.elements.find((el) => el.name === "w:docPartObj");
|
|
23239
|
-
const docPartGallery = docPartObj?.elements.find((el) => el.name === "w:docPartGallery");
|
|
23240
|
-
const docPartGalleryType = docPartGallery?.attributes["w:val"];
|
|
23241
|
-
if (!docPartGalleryType) {
|
|
23242
|
-
return { nodes: [], consumed: 0 };
|
|
22859
|
+
function _format(sep, pathObject) {
|
|
22860
|
+
var dir = pathObject.dir || pathObject.root;
|
|
22861
|
+
var base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
|
|
22862
|
+
if (!dir) {
|
|
22863
|
+
return base;
|
|
23243
22864
|
}
|
|
23244
|
-
if (
|
|
23245
|
-
return
|
|
22865
|
+
if (dir === pathObject.root) {
|
|
22866
|
+
return dir + base;
|
|
23246
22867
|
}
|
|
23247
|
-
|
|
23248
|
-
|
|
23249
|
-
|
|
23250
|
-
|
|
23251
|
-
|
|
23252
|
-
|
|
23253
|
-
|
|
23254
|
-
|
|
23255
|
-
|
|
23256
|
-
|
|
23257
|
-
|
|
23258
|
-
|
|
23259
|
-
|
|
23260
|
-
|
|
23261
|
-
|
|
23262
|
-
|
|
23263
|
-
|
|
23264
|
-
|
|
23265
|
-
|
|
23266
|
-
|
|
23267
|
-
|
|
23268
|
-
|
|
23269
|
-
|
|
23270
|
-
|
|
23271
|
-
|
|
23272
|
-
|
|
23273
|
-
|
|
23274
|
-
|
|
23275
|
-
|
|
23276
|
-
|
|
23277
|
-
|
|
23278
|
-
|
|
23279
|
-
|
|
23280
|
-
|
|
23281
|
-
|
|
23282
|
-
|
|
23283
|
-
|
|
23284
|
-
|
|
23285
|
-
|
|
23286
|
-
|
|
23287
|
-
|
|
23288
|
-
|
|
23289
|
-
|
|
23290
|
-
|
|
23291
|
-
|
|
23292
|
-
|
|
23293
|
-
|
|
23294
|
-
|
|
23295
|
-
|
|
23296
|
-
|
|
23297
|
-
|
|
23298
|
-
|
|
23299
|
-
|
|
23300
|
-
|
|
23301
|
-
|
|
23302
|
-
|
|
23303
|
-
|
|
23304
|
-
|
|
23305
|
-
|
|
23306
|
-
|
|
23307
|
-
|
|
23308
|
-
|
|
23309
|
-
|
|
23310
|
-
|
|
23311
|
-
|
|
23312
|
-
|
|
23313
|
-
|
|
23314
|
-
|
|
23315
|
-
|
|
23316
|
-
|
|
23317
|
-
|
|
23318
|
-
|
|
23319
|
-
|
|
23320
|
-
|
|
23321
|
-
|
|
23322
|
-
|
|
23323
|
-
|
|
23324
|
-
|
|
23325
|
-
|
|
23326
|
-
|
|
23327
|
-
|
|
23328
|
-
|
|
22868
|
+
return dir + sep + base;
|
|
22869
|
+
}
|
|
22870
|
+
var posix = {
|
|
22871
|
+
// path.resolve([from ...], to)
|
|
22872
|
+
resolve: function resolve() {
|
|
22873
|
+
var resolvedPath = "";
|
|
22874
|
+
var resolvedAbsolute = false;
|
|
22875
|
+
var cwd;
|
|
22876
|
+
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
22877
|
+
var path;
|
|
22878
|
+
if (i >= 0)
|
|
22879
|
+
path = arguments[i];
|
|
22880
|
+
else {
|
|
22881
|
+
if (cwd === void 0)
|
|
22882
|
+
cwd = process$1.cwd();
|
|
22883
|
+
path = cwd;
|
|
22884
|
+
}
|
|
22885
|
+
assertPath(path);
|
|
22886
|
+
if (path.length === 0) {
|
|
22887
|
+
continue;
|
|
22888
|
+
}
|
|
22889
|
+
resolvedPath = path + "/" + resolvedPath;
|
|
22890
|
+
resolvedAbsolute = path.charCodeAt(0) === 47;
|
|
22891
|
+
}
|
|
22892
|
+
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
|
|
22893
|
+
if (resolvedAbsolute) {
|
|
22894
|
+
if (resolvedPath.length > 0)
|
|
22895
|
+
return "/" + resolvedPath;
|
|
22896
|
+
else
|
|
22897
|
+
return "/";
|
|
22898
|
+
} else if (resolvedPath.length > 0) {
|
|
22899
|
+
return resolvedPath;
|
|
22900
|
+
} else {
|
|
22901
|
+
return ".";
|
|
22902
|
+
}
|
|
22903
|
+
},
|
|
22904
|
+
normalize: function normalize(path) {
|
|
22905
|
+
assertPath(path);
|
|
22906
|
+
if (path.length === 0) return ".";
|
|
22907
|
+
var isAbsolute2 = path.charCodeAt(0) === 47;
|
|
22908
|
+
var trailingSeparator = path.charCodeAt(path.length - 1) === 47;
|
|
22909
|
+
path = normalizeStringPosix(path, !isAbsolute2);
|
|
22910
|
+
if (path.length === 0 && !isAbsolute2) path = ".";
|
|
22911
|
+
if (path.length > 0 && trailingSeparator) path += "/";
|
|
22912
|
+
if (isAbsolute2) return "/" + path;
|
|
22913
|
+
return path;
|
|
22914
|
+
},
|
|
22915
|
+
isAbsolute: function isAbsolute(path) {
|
|
22916
|
+
assertPath(path);
|
|
22917
|
+
return path.length > 0 && path.charCodeAt(0) === 47;
|
|
22918
|
+
},
|
|
22919
|
+
join: function join2() {
|
|
22920
|
+
if (arguments.length === 0)
|
|
22921
|
+
return ".";
|
|
22922
|
+
var joined;
|
|
22923
|
+
for (var i = 0; i < arguments.length; ++i) {
|
|
22924
|
+
var arg = arguments[i];
|
|
22925
|
+
assertPath(arg);
|
|
22926
|
+
if (arg.length > 0) {
|
|
22927
|
+
if (joined === void 0)
|
|
22928
|
+
joined = arg;
|
|
22929
|
+
else
|
|
22930
|
+
joined += "/" + arg;
|
|
22931
|
+
}
|
|
22932
|
+
}
|
|
22933
|
+
if (joined === void 0)
|
|
22934
|
+
return ".";
|
|
22935
|
+
return posix.normalize(joined);
|
|
22936
|
+
},
|
|
22937
|
+
relative: function relative(from, to) {
|
|
22938
|
+
assertPath(from);
|
|
22939
|
+
assertPath(to);
|
|
22940
|
+
if (from === to) return "";
|
|
22941
|
+
from = posix.resolve(from);
|
|
22942
|
+
to = posix.resolve(to);
|
|
22943
|
+
if (from === to) return "";
|
|
22944
|
+
var fromStart = 1;
|
|
22945
|
+
for (; fromStart < from.length; ++fromStart) {
|
|
22946
|
+
if (from.charCodeAt(fromStart) !== 47)
|
|
22947
|
+
break;
|
|
22948
|
+
}
|
|
22949
|
+
var fromEnd = from.length;
|
|
22950
|
+
var fromLen = fromEnd - fromStart;
|
|
22951
|
+
var toStart = 1;
|
|
22952
|
+
for (; toStart < to.length; ++toStart) {
|
|
22953
|
+
if (to.charCodeAt(toStart) !== 47)
|
|
22954
|
+
break;
|
|
22955
|
+
}
|
|
22956
|
+
var toEnd = to.length;
|
|
22957
|
+
var toLen = toEnd - toStart;
|
|
22958
|
+
var length = fromLen < toLen ? fromLen : toLen;
|
|
22959
|
+
var lastCommonSep = -1;
|
|
22960
|
+
var i = 0;
|
|
22961
|
+
for (; i <= length; ++i) {
|
|
22962
|
+
if (i === length) {
|
|
22963
|
+
if (toLen > length) {
|
|
22964
|
+
if (to.charCodeAt(toStart + i) === 47) {
|
|
22965
|
+
return to.slice(toStart + i + 1);
|
|
22966
|
+
} else if (i === 0) {
|
|
22967
|
+
return to.slice(toStart + i);
|
|
22968
|
+
}
|
|
22969
|
+
} else if (fromLen > length) {
|
|
22970
|
+
if (from.charCodeAt(fromStart + i) === 47) {
|
|
22971
|
+
lastCommonSep = i;
|
|
22972
|
+
} else if (i === 0) {
|
|
22973
|
+
lastCommonSep = 0;
|
|
22974
|
+
}
|
|
22975
|
+
}
|
|
22976
|
+
break;
|
|
22977
|
+
}
|
|
22978
|
+
var fromCode = from.charCodeAt(fromStart + i);
|
|
22979
|
+
var toCode = to.charCodeAt(toStart + i);
|
|
22980
|
+
if (fromCode !== toCode)
|
|
22981
|
+
break;
|
|
22982
|
+
else if (fromCode === 47)
|
|
22983
|
+
lastCommonSep = i;
|
|
22984
|
+
}
|
|
22985
|
+
var out = "";
|
|
22986
|
+
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
22987
|
+
if (i === fromEnd || from.charCodeAt(i) === 47) {
|
|
22988
|
+
if (out.length === 0)
|
|
22989
|
+
out += "..";
|
|
22990
|
+
else
|
|
22991
|
+
out += "/..";
|
|
22992
|
+
}
|
|
22993
|
+
}
|
|
22994
|
+
if (out.length > 0)
|
|
22995
|
+
return out + to.slice(toStart + lastCommonSep);
|
|
22996
|
+
else {
|
|
22997
|
+
toStart += lastCommonSep;
|
|
22998
|
+
if (to.charCodeAt(toStart) === 47)
|
|
22999
|
+
++toStart;
|
|
23000
|
+
return to.slice(toStart);
|
|
23001
|
+
}
|
|
23002
|
+
},
|
|
23003
|
+
_makeLong: function _makeLong(path) {
|
|
23004
|
+
return path;
|
|
23005
|
+
},
|
|
23006
|
+
dirname: function dirname(path) {
|
|
23007
|
+
assertPath(path);
|
|
23008
|
+
if (path.length === 0) return ".";
|
|
23009
|
+
var code2 = path.charCodeAt(0);
|
|
23010
|
+
var hasRoot = code2 === 47;
|
|
23011
|
+
var end = -1;
|
|
23012
|
+
var matchedSlash = true;
|
|
23013
|
+
for (var i = path.length - 1; i >= 1; --i) {
|
|
23014
|
+
code2 = path.charCodeAt(i);
|
|
23015
|
+
if (code2 === 47) {
|
|
23016
|
+
if (!matchedSlash) {
|
|
23017
|
+
end = i;
|
|
23018
|
+
break;
|
|
23019
|
+
}
|
|
23020
|
+
} else {
|
|
23021
|
+
matchedSlash = false;
|
|
23022
|
+
}
|
|
23023
|
+
}
|
|
23024
|
+
if (end === -1) return hasRoot ? "/" : ".";
|
|
23025
|
+
if (hasRoot && end === 1) return "//";
|
|
23026
|
+
return path.slice(0, end);
|
|
23027
|
+
},
|
|
23028
|
+
basename: function basename(path, ext) {
|
|
23029
|
+
if (ext !== void 0 && typeof ext !== "string") throw new TypeError('"ext" argument must be a string');
|
|
23030
|
+
assertPath(path);
|
|
23031
|
+
var start = 0;
|
|
23032
|
+
var end = -1;
|
|
23033
|
+
var matchedSlash = true;
|
|
23034
|
+
var i;
|
|
23035
|
+
if (ext !== void 0 && ext.length > 0 && ext.length <= path.length) {
|
|
23036
|
+
if (ext.length === path.length && ext === path) return "";
|
|
23037
|
+
var extIdx = ext.length - 1;
|
|
23038
|
+
var firstNonSlashEnd = -1;
|
|
23039
|
+
for (i = path.length - 1; i >= 0; --i) {
|
|
23040
|
+
var code2 = path.charCodeAt(i);
|
|
23041
|
+
if (code2 === 47) {
|
|
23042
|
+
if (!matchedSlash) {
|
|
23043
|
+
start = i + 1;
|
|
23044
|
+
break;
|
|
23045
|
+
}
|
|
23046
|
+
} else {
|
|
23047
|
+
if (firstNonSlashEnd === -1) {
|
|
23048
|
+
matchedSlash = false;
|
|
23049
|
+
firstNonSlashEnd = i + 1;
|
|
23050
|
+
}
|
|
23051
|
+
if (extIdx >= 0) {
|
|
23052
|
+
if (code2 === ext.charCodeAt(extIdx)) {
|
|
23053
|
+
if (--extIdx === -1) {
|
|
23054
|
+
end = i;
|
|
23055
|
+
}
|
|
23056
|
+
} else {
|
|
23057
|
+
extIdx = -1;
|
|
23058
|
+
end = firstNonSlashEnd;
|
|
23059
|
+
}
|
|
23060
|
+
}
|
|
23061
|
+
}
|
|
23062
|
+
}
|
|
23063
|
+
if (start === end) end = firstNonSlashEnd;
|
|
23064
|
+
else if (end === -1) end = path.length;
|
|
23065
|
+
return path.slice(start, end);
|
|
23066
|
+
} else {
|
|
23067
|
+
for (i = path.length - 1; i >= 0; --i) {
|
|
23068
|
+
if (path.charCodeAt(i) === 47) {
|
|
23069
|
+
if (!matchedSlash) {
|
|
23070
|
+
start = i + 1;
|
|
23071
|
+
break;
|
|
23072
|
+
}
|
|
23073
|
+
} else if (end === -1) {
|
|
23074
|
+
matchedSlash = false;
|
|
23075
|
+
end = i + 1;
|
|
23076
|
+
}
|
|
23077
|
+
}
|
|
23078
|
+
if (end === -1) return "";
|
|
23079
|
+
return path.slice(start, end);
|
|
23080
|
+
}
|
|
23081
|
+
},
|
|
23082
|
+
extname: function extname(path) {
|
|
23083
|
+
assertPath(path);
|
|
23084
|
+
var startDot = -1;
|
|
23085
|
+
var startPart = 0;
|
|
23086
|
+
var end = -1;
|
|
23087
|
+
var matchedSlash = true;
|
|
23088
|
+
var preDotState = 0;
|
|
23089
|
+
for (var i = path.length - 1; i >= 0; --i) {
|
|
23090
|
+
var code2 = path.charCodeAt(i);
|
|
23091
|
+
if (code2 === 47) {
|
|
23092
|
+
if (!matchedSlash) {
|
|
23093
|
+
startPart = i + 1;
|
|
23094
|
+
break;
|
|
23095
|
+
}
|
|
23096
|
+
continue;
|
|
23097
|
+
}
|
|
23098
|
+
if (end === -1) {
|
|
23099
|
+
matchedSlash = false;
|
|
23100
|
+
end = i + 1;
|
|
23101
|
+
}
|
|
23102
|
+
if (code2 === 46) {
|
|
23103
|
+
if (startDot === -1)
|
|
23104
|
+
startDot = i;
|
|
23105
|
+
else if (preDotState !== 1)
|
|
23106
|
+
preDotState = 1;
|
|
23107
|
+
} else if (startDot !== -1) {
|
|
23108
|
+
preDotState = -1;
|
|
23109
|
+
}
|
|
23110
|
+
}
|
|
23111
|
+
if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
|
|
23112
|
+
preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
|
|
23113
|
+
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
23114
|
+
return "";
|
|
23115
|
+
}
|
|
23116
|
+
return path.slice(startDot, end);
|
|
23117
|
+
},
|
|
23118
|
+
format: function format(pathObject) {
|
|
23119
|
+
if (pathObject === null || typeof pathObject !== "object") {
|
|
23120
|
+
throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
|
|
23121
|
+
}
|
|
23122
|
+
return _format("/", pathObject);
|
|
23123
|
+
},
|
|
23124
|
+
parse: function parse(path) {
|
|
23125
|
+
assertPath(path);
|
|
23126
|
+
var ret = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
23127
|
+
if (path.length === 0) return ret;
|
|
23128
|
+
var code2 = path.charCodeAt(0);
|
|
23129
|
+
var isAbsolute2 = code2 === 47;
|
|
23130
|
+
var start;
|
|
23131
|
+
if (isAbsolute2) {
|
|
23132
|
+
ret.root = "/";
|
|
23133
|
+
start = 1;
|
|
23329
23134
|
} else {
|
|
23330
|
-
|
|
23135
|
+
start = 0;
|
|
23331
23136
|
}
|
|
23332
|
-
|
|
23333
|
-
|
|
23334
|
-
|
|
23335
|
-
|
|
23336
|
-
|
|
23337
|
-
|
|
23338
|
-
|
|
23339
|
-
|
|
23340
|
-
|
|
23341
|
-
|
|
23342
|
-
|
|
23343
|
-
|
|
23344
|
-
|
|
23345
|
-
|
|
23346
|
-
}
|
|
23347
|
-
|
|
23348
|
-
|
|
23349
|
-
|
|
23350
|
-
|
|
23351
|
-
|
|
23352
|
-
|
|
23353
|
-
|
|
23354
|
-
|
|
23355
|
-
|
|
23356
|
-
|
|
23357
|
-
let result = {
|
|
23358
|
-
type: "structuredContent",
|
|
23359
|
-
content: translatedContent,
|
|
23360
|
-
marks,
|
|
23361
|
-
attrs: {
|
|
23362
|
-
sdtPr
|
|
23137
|
+
var startDot = -1;
|
|
23138
|
+
var startPart = 0;
|
|
23139
|
+
var end = -1;
|
|
23140
|
+
var matchedSlash = true;
|
|
23141
|
+
var i = path.length - 1;
|
|
23142
|
+
var preDotState = 0;
|
|
23143
|
+
for (; i >= start; --i) {
|
|
23144
|
+
code2 = path.charCodeAt(i);
|
|
23145
|
+
if (code2 === 47) {
|
|
23146
|
+
if (!matchedSlash) {
|
|
23147
|
+
startPart = i + 1;
|
|
23148
|
+
break;
|
|
23149
|
+
}
|
|
23150
|
+
continue;
|
|
23151
|
+
}
|
|
23152
|
+
if (end === -1) {
|
|
23153
|
+
matchedSlash = false;
|
|
23154
|
+
end = i + 1;
|
|
23155
|
+
}
|
|
23156
|
+
if (code2 === 46) {
|
|
23157
|
+
if (startDot === -1) startDot = i;
|
|
23158
|
+
else if (preDotState !== 1) preDotState = 1;
|
|
23159
|
+
} else if (startDot !== -1) {
|
|
23160
|
+
preDotState = -1;
|
|
23161
|
+
}
|
|
23363
23162
|
}
|
|
23364
|
-
|
|
23365
|
-
|
|
23366
|
-
|
|
23367
|
-
|
|
23368
|
-
|
|
23369
|
-
|
|
23370
|
-
|
|
23371
|
-
|
|
23372
|
-
|
|
23163
|
+
if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
|
|
23164
|
+
preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
|
|
23165
|
+
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
23166
|
+
if (end !== -1) {
|
|
23167
|
+
if (startPart === 0 && isAbsolute2) ret.base = ret.name = path.slice(1, end);
|
|
23168
|
+
else ret.base = ret.name = path.slice(startPart, end);
|
|
23169
|
+
}
|
|
23170
|
+
} else {
|
|
23171
|
+
if (startPart === 0 && isAbsolute2) {
|
|
23172
|
+
ret.name = path.slice(1, startDot);
|
|
23173
|
+
ret.base = path.slice(1, end);
|
|
23174
|
+
} else {
|
|
23175
|
+
ret.name = path.slice(startPart, startDot);
|
|
23176
|
+
ret.base = path.slice(startPart, end);
|
|
23177
|
+
}
|
|
23178
|
+
ret.ext = path.slice(startDot, end);
|
|
23179
|
+
}
|
|
23180
|
+
if (startPart > 0) ret.dir = path.slice(0, startPart - 1);
|
|
23181
|
+
else if (isAbsolute2) ret.dir = "/";
|
|
23182
|
+
return ret;
|
|
23183
|
+
},
|
|
23184
|
+
sep: "/",
|
|
23185
|
+
delimiter: ":",
|
|
23186
|
+
win32: null,
|
|
23187
|
+
posix: null
|
|
23373
23188
|
};
|
|
23374
|
-
|
|
23375
|
-
|
|
23376
|
-
|
|
23377
|
-
|
|
23378
|
-
}
|
|
23379
|
-
const node2 = nodes[0];
|
|
23380
|
-
const { name } = node2;
|
|
23381
|
-
const { attributes, elements, marks = [] } = parseProperties(node2);
|
|
23382
|
-
if (name === "w:sdt") {
|
|
23189
|
+
posix.posix = posix;
|
|
23190
|
+
const handleListNode = (params) => {
|
|
23191
|
+
const { nodes, lists, docx } = params;
|
|
23192
|
+
if (nodes.length === 0 || nodes[0].name !== "w:p" || nodes[0].isList) {
|
|
23383
23193
|
return { nodes: [], consumed: 0 };
|
|
23384
23194
|
}
|
|
23385
|
-
|
|
23195
|
+
const node2 = carbonCopy(nodes[0]);
|
|
23196
|
+
const isList = testForList(node2, docx);
|
|
23197
|
+
if (isList) {
|
|
23198
|
+
node2.isList = true;
|
|
23199
|
+
const result = handleListNodes(params, node2);
|
|
23386
23200
|
return {
|
|
23387
|
-
nodes: [
|
|
23388
|
-
|
|
23389
|
-
attrs: { ...attributes },
|
|
23390
|
-
marks: []
|
|
23391
|
-
}],
|
|
23392
|
-
consumed: 0
|
|
23201
|
+
nodes: [result],
|
|
23202
|
+
consumed: 1
|
|
23393
23203
|
};
|
|
23204
|
+
} else {
|
|
23205
|
+
return { nodes: [], consumed: 0 };
|
|
23394
23206
|
}
|
|
23395
|
-
|
|
23207
|
+
};
|
|
23208
|
+
const listHandlerEntity = {
|
|
23209
|
+
handlerName: "listHandler",
|
|
23210
|
+
handler: handleListNode
|
|
23211
|
+
};
|
|
23212
|
+
function handleListNodes(params, node2) {
|
|
23213
|
+
const { docx, nodeListHandler: nodeListHandler2, lists } = params;
|
|
23214
|
+
const initialpPr = node2.elements.find((el) => el.name === "w:pPr");
|
|
23215
|
+
const styleTag = initialpPr?.elements?.find((el) => el.name === "w:pStyle");
|
|
23216
|
+
const styleId = styleTag?.attributes["w:val"];
|
|
23217
|
+
const { numPr: numPrTag, type: numPrType } = getNumPrRecursive({ node: node2, styleId, docx });
|
|
23218
|
+
const currentListNumId = getNumIdFromTag(numPrTag);
|
|
23219
|
+
const iLvlTag = numPrTag?.elements?.find((el) => el.name === "w:ilvl");
|
|
23220
|
+
let iLvl = Number(iLvlTag?.attributes["w:val"]);
|
|
23221
|
+
if (!iLvl && iLvl !== 0) iLvl = getOutlineLevelFromStyleTag(styleId, docx);
|
|
23222
|
+
const {
|
|
23223
|
+
listType,
|
|
23224
|
+
listOrderingType,
|
|
23225
|
+
listrPrs,
|
|
23226
|
+
listpPrs,
|
|
23227
|
+
start,
|
|
23228
|
+
lvlText,
|
|
23229
|
+
lvlJc,
|
|
23230
|
+
customFormat
|
|
23231
|
+
} = getNodeNumberingDefinition(node2, iLvl, docx);
|
|
23232
|
+
if (!listType) {
|
|
23233
|
+
const pPrIndex = node2.elements.findIndex((el) => el.name === "w:pPr");
|
|
23234
|
+
const pPr = node2.elements[pPrIndex];
|
|
23235
|
+
const numPrIndex2 = pPr?.elements?.findIndex((el) => el.name === "w:numPr");
|
|
23236
|
+
if (numPrIndex2 >= 0) {
|
|
23237
|
+
pPr?.elements?.splice(numPrIndex2, 1);
|
|
23238
|
+
node2.elements[pPrIndex] = pPr;
|
|
23239
|
+
}
|
|
23240
|
+
const styleIdIndex = pPr?.elements?.findIndex((el) => el.name === "w:pStyle");
|
|
23241
|
+
if (styleIdIndex >= 0) pPr?.elements?.splice(styleIdIndex, 1);
|
|
23242
|
+
const fallBack = nodeListHandler2.handler({ ...params, nodes: [node2] })?.filter((n) => n);
|
|
23243
|
+
return fallBack[0];
|
|
23244
|
+
}
|
|
23245
|
+
if (!lists[currentListNumId]) lists[currentListNumId] = { levels: {} };
|
|
23246
|
+
const currentListByNumId = lists[currentListNumId];
|
|
23247
|
+
if (!currentListByNumId.levels[iLvl]) currentListByNumId.levels[iLvl] = Number(start) || 1;
|
|
23248
|
+
else currentListByNumId.levels[iLvl]++;
|
|
23249
|
+
Object.keys(currentListByNumId.levels).forEach((key) => {
|
|
23250
|
+
const level = Number(key);
|
|
23251
|
+
if (level > iLvl) {
|
|
23252
|
+
delete currentListByNumId.levels[level];
|
|
23253
|
+
}
|
|
23254
|
+
});
|
|
23255
|
+
const path = generateListPath(
|
|
23256
|
+
iLvl,
|
|
23257
|
+
currentListNumId,
|
|
23258
|
+
styleId,
|
|
23259
|
+
currentListByNumId.levels,
|
|
23260
|
+
docx
|
|
23261
|
+
);
|
|
23262
|
+
if (!path.length) path.push(currentListByNumId.levels[iLvl]);
|
|
23263
|
+
const attrs = {};
|
|
23264
|
+
attrs.lvlText = lvlText;
|
|
23265
|
+
attrs.listLevel = path;
|
|
23266
|
+
attrs.listNumberingType = listOrderingType;
|
|
23267
|
+
attrs.numId = currentListNumId;
|
|
23268
|
+
attrs.level = iLvl;
|
|
23269
|
+
attrs.numPrType = numPrType;
|
|
23270
|
+
attrs.styleId = styleId;
|
|
23271
|
+
attrs.customFormat = customFormat;
|
|
23272
|
+
node2.isList = true;
|
|
23273
|
+
const nodePpr = node2.attrs?.paragraphProperties?.elements?.find((el) => el.name === "w:pPr");
|
|
23274
|
+
const numPrIndex = node2.attrs?.paragraphProperties?.elements?.findIndex((el) => el.name === "w:numPr");
|
|
23275
|
+
nodePpr?.elements?.splice(numPrIndex, 1);
|
|
23276
|
+
const listContents = nodeListHandler2.handler({ ...params, nodes: [node2] });
|
|
23277
|
+
const innerParagraph = listContents.find((el) => el.type === "paragraph");
|
|
23278
|
+
const firstElement = innerParagraph.content[0];
|
|
23279
|
+
firstElement?.marks?.find((mark) => mark.type === "textStyle");
|
|
23280
|
+
attrs.indent = listpPrs?.indent;
|
|
23281
|
+
const processedContents = listContents.map((el, index) => {
|
|
23282
|
+
const { attrs: elementAttrs } = el;
|
|
23283
|
+
const { indent, textIndent, paragraphProperties, ...rest } = elementAttrs;
|
|
23284
|
+
if (index === 0 && !attrs.indent) attrs.indent = indent;
|
|
23396
23285
|
return {
|
|
23397
|
-
|
|
23398
|
-
|
|
23399
|
-
content: elements,
|
|
23400
|
-
attrs: { ...attributes },
|
|
23401
|
-
marks
|
|
23402
|
-
}],
|
|
23403
|
-
consumed: 0,
|
|
23404
|
-
unhandled: true
|
|
23286
|
+
...el,
|
|
23287
|
+
attrs: rest
|
|
23405
23288
|
};
|
|
23406
|
-
}
|
|
23407
|
-
const
|
|
23408
|
-
|
|
23409
|
-
|
|
23410
|
-
|
|
23411
|
-
|
|
23412
|
-
|
|
23413
|
-
|
|
23414
|
-
|
|
23415
|
-
|
|
23416
|
-
|
|
23417
|
-
|
|
23418
|
-
|
|
23419
|
-
const resultNode = {
|
|
23420
|
-
type: getElementName(node2),
|
|
23421
|
-
content,
|
|
23422
|
-
attrs: { ...attributes },
|
|
23423
|
-
marks: []
|
|
23289
|
+
});
|
|
23290
|
+
const listItem = {
|
|
23291
|
+
type: "listItem",
|
|
23292
|
+
content: processedContents || [],
|
|
23293
|
+
attrs
|
|
23294
|
+
};
|
|
23295
|
+
const resultingList = {
|
|
23296
|
+
type: listType,
|
|
23297
|
+
content: [listItem],
|
|
23298
|
+
attrs: {
|
|
23299
|
+
"list-style-type": listOrderingType,
|
|
23300
|
+
listId: currentListNumId
|
|
23301
|
+
}
|
|
23424
23302
|
};
|
|
23425
|
-
return
|
|
23426
|
-
}
|
|
23427
|
-
const
|
|
23428
|
-
const
|
|
23429
|
-
const
|
|
23430
|
-
|
|
23431
|
-
|
|
23432
|
-
|
|
23433
|
-
|
|
23434
|
-
handler: handleStandardNode
|
|
23435
|
-
};
|
|
23436
|
-
const handleLineBreakNode = (params) => {
|
|
23437
|
-
const { nodes } = params;
|
|
23438
|
-
if (nodes.length === 0 || nodes[0].name !== "w:br") {
|
|
23439
|
-
return { nodes: [], consumed: 0 };
|
|
23303
|
+
return resultingList;
|
|
23304
|
+
}
|
|
23305
|
+
const getOutlineLevelFromStyleTag = (styleTag, docx) => {
|
|
23306
|
+
const matchedStyle = getStyleTagFromStyleId(styleTag, docx);
|
|
23307
|
+
const pPr = matchedStyle?.elements?.find((style) => style.name === "w:pPr");
|
|
23308
|
+
const outlineLevel = pPr?.elements?.find((style) => style.name === "w:outlineLvl");
|
|
23309
|
+
try {
|
|
23310
|
+
return parseInt(outlineLevel?.attributes["w:val"]);
|
|
23311
|
+
} catch (e) {
|
|
23440
23312
|
}
|
|
23441
|
-
const lineBreakType = nodes[0].attributes?.["w:type"];
|
|
23442
|
-
const breakType = lineBreakType === "page" ? "hardBreak" : "lineBreak";
|
|
23443
|
-
return {
|
|
23444
|
-
nodes: [{
|
|
23445
|
-
type: breakType
|
|
23446
|
-
}],
|
|
23447
|
-
consumed: 1
|
|
23448
|
-
};
|
|
23449
23313
|
};
|
|
23450
|
-
|
|
23451
|
-
|
|
23452
|
-
|
|
23314
|
+
function testForList(node2, docx) {
|
|
23315
|
+
const { elements } = node2;
|
|
23316
|
+
const pPr = elements?.find((el) => el.name === "w:pPr");
|
|
23317
|
+
if (!pPr) return false;
|
|
23318
|
+
const paragraphStyle = pPr.elements?.find((el) => el.name === "w:pStyle");
|
|
23319
|
+
let numPr = pPr.elements?.find((el) => el.name === "w:numPr");
|
|
23320
|
+
let numId = getNumIdFromTag(numPr);
|
|
23321
|
+
const ilvlTag = numPr?.elements?.find((el) => el.name === "w:ilvl");
|
|
23322
|
+
let ilvl = ilvlTag?.attributes["w:val"];
|
|
23323
|
+
let outlinelvl;
|
|
23324
|
+
const styleId = paragraphStyle?.attributes["w:val"];
|
|
23325
|
+
const styleTag = getStyleTagFromStyleId(styleId, docx);
|
|
23326
|
+
if (styleTag && !numId) {
|
|
23327
|
+
const { numPr: numPrRecursve, type: type2 } = getNumPrRecursive({ node: node2, styleId, docx });
|
|
23328
|
+
numPr = numPrRecursve;
|
|
23329
|
+
numId = getNumIdFromTag(numPr);
|
|
23330
|
+
const stylePpr = styleTag?.elements?.find((el) => el.name === "w:pPr");
|
|
23331
|
+
ilvl = stylePpr?.elements?.find((el) => el.name === "w:ilvl")?.attributes["w:val"];
|
|
23332
|
+
outlinelvl = stylePpr?.elements?.find((el) => el.name === "w:outlineLvl")?.attributes["w:val"];
|
|
23333
|
+
ilvl = outlinelvl || ilvl;
|
|
23334
|
+
}
|
|
23335
|
+
const abstractNumDefinition = getAbstractDefinition(numId, docx);
|
|
23336
|
+
const levelDefinition = abstractNumDefinition?.elements?.find((el) => el.name === "w:lvl" && el.attributes?.["w:ilvl"] == ilvl);
|
|
23337
|
+
if (!levelDefinition) return false;
|
|
23338
|
+
return !!numId;
|
|
23339
|
+
}
|
|
23340
|
+
const getNumIdFromTag = (tag) => {
|
|
23341
|
+
return tag?.elements?.find((el) => el.name === "w:numId")?.attributes["w:val"];
|
|
23453
23342
|
};
|
|
23454
|
-
|
|
23455
|
-
const
|
|
23456
|
-
if (
|
|
23457
|
-
|
|
23343
|
+
function getStyleTagFromStyleId(styleId, docx) {
|
|
23344
|
+
const styles = docx["word/styles.xml"];
|
|
23345
|
+
if (!styles) return {};
|
|
23346
|
+
const styleEls = styles.elements;
|
|
23347
|
+
const wStyles = styleEls.find((el) => el.name === "w:styles");
|
|
23348
|
+
const styleTags = wStyles.elements.filter((style) => style.name === "w:style");
|
|
23349
|
+
const styleDef = styleTags.find((tag) => tag.attributes["w:styleId"] === styleId);
|
|
23350
|
+
return styleDef;
|
|
23351
|
+
}
|
|
23352
|
+
function getNumPrRecursive({ node: node2, styleId, docx, seenStyleIds = /* @__PURE__ */ new Set() }) {
|
|
23353
|
+
const initialPpr = node2?.elements?.find((el) => el.name === "w:pPr");
|
|
23354
|
+
const initialNumPr = initialPpr?.elements?.find((el) => el.name === "w:numPr");
|
|
23355
|
+
let numPr = initialNumPr;
|
|
23356
|
+
let numId = getNumIdFromTag(numPr);
|
|
23357
|
+
if (numId) return { numPr, type: "inline" };
|
|
23358
|
+
const matchedStyle = getStyleTagFromStyleId(styleId, docx);
|
|
23359
|
+
const pPr = matchedStyle?.elements?.find((style) => style.name === "w:pPr");
|
|
23360
|
+
numPr = pPr?.elements?.find((style) => style.name === "w:numPr");
|
|
23361
|
+
numId = getNumIdFromTag(numPr);
|
|
23362
|
+
const basedOn = matchedStyle?.elements?.find((style) => style.name === "w:basedOn");
|
|
23363
|
+
if (!numId && !seenStyleIds.has(styleId)) {
|
|
23364
|
+
const basedOnStyleId = basedOn?.attributes["w:val"];
|
|
23365
|
+
seenStyleIds.add(styleId);
|
|
23366
|
+
if (!basedOnStyleId) return {};
|
|
23367
|
+
return getNumPrRecursive({ styleId: basedOnStyleId, docx, seenStyleIds });
|
|
23458
23368
|
}
|
|
23459
|
-
|
|
23460
|
-
|
|
23461
|
-
|
|
23462
|
-
|
|
23463
|
-
|
|
23464
|
-
|
|
23465
|
-
|
|
23369
|
+
return { numPr, type: "numbering" };
|
|
23370
|
+
}
|
|
23371
|
+
const orderedListTypes = [
|
|
23372
|
+
"decimal",
|
|
23373
|
+
// eg: 1, 2, 3, 4, 5, ...
|
|
23374
|
+
"decimalZero",
|
|
23375
|
+
// eg: 01, 02, 03, 04, 05, ...
|
|
23376
|
+
"lowerRoman",
|
|
23377
|
+
// eg: i, ii, iii, iv, v, ...
|
|
23378
|
+
"upperRoman",
|
|
23379
|
+
// eg: I, II, III, IV, V, ...
|
|
23380
|
+
"lowerLetter",
|
|
23381
|
+
// eg: a, b, c, d, e, ...
|
|
23382
|
+
"upperLetter",
|
|
23383
|
+
// eg: A, B, C, D, E, ...
|
|
23384
|
+
"ordinal",
|
|
23385
|
+
// eg: 1st, 2nd, 3rd, 4th, 5th, ...
|
|
23386
|
+
"cardinalText",
|
|
23387
|
+
// eg: one, two, three, four, five, ...
|
|
23388
|
+
"ordinalText",
|
|
23389
|
+
// eg: first, second, third, fourth, fifth, ...
|
|
23390
|
+
"hex",
|
|
23391
|
+
// eg: 0, 1, 2, ..., 9, A, B, C, ..., F, 10, 11, ...
|
|
23392
|
+
"chicago",
|
|
23393
|
+
// eg: (0, 1, 2, ..., 9, 10, 11, 12, ..., 19, 1A, 1B, 1C, ..., 1Z, 20, 21, ..., 2Z)
|
|
23394
|
+
"none"
|
|
23395
|
+
// No bullet
|
|
23396
|
+
];
|
|
23397
|
+
const unorderedListTypes = [
|
|
23398
|
+
"bullet",
|
|
23399
|
+
// A standard bullet point (•)
|
|
23400
|
+
"square",
|
|
23401
|
+
// Square bullets (▪)
|
|
23402
|
+
"circle",
|
|
23403
|
+
// Circle bullets (◦)
|
|
23404
|
+
"disc"
|
|
23405
|
+
// Disc bullets (●)
|
|
23406
|
+
];
|
|
23407
|
+
const getListNumIdFromStyleRef = (styleId, docx) => {
|
|
23408
|
+
const styles = docx["word/styles.xml"];
|
|
23409
|
+
if (!styles) return null;
|
|
23410
|
+
const { elements } = styles;
|
|
23411
|
+
const styleTags = elements[0].elements.filter((style2) => style2.name === "w:style");
|
|
23412
|
+
const style = styleTags.find((tag) => tag.attributes["w:styleId"] === styleId) || {};
|
|
23413
|
+
const pPr = style?.elements?.find((style2) => style2.name === "w:pPr");
|
|
23414
|
+
if (!pPr) return null;
|
|
23415
|
+
let numPr = pPr?.elements?.find((style2) => style2.name === "w:numPr");
|
|
23416
|
+
if (!numPr) return null;
|
|
23417
|
+
let numIdTag = numPr?.elements?.find((style2) => style2.name === "w:numId") || {};
|
|
23418
|
+
let numId = getNumIdFromTag(numPr);
|
|
23419
|
+
let ilvlTag = numPr?.elements?.find((style2) => style2.name === "w:ilvl");
|
|
23420
|
+
let ilvl = ilvlTag?.attributes?.["w:val"];
|
|
23421
|
+
const basedOnTag = style?.elements?.find((style2) => style2.name === "w:basedOn");
|
|
23422
|
+
const basedOnId = basedOnTag?.attributes?.["w:val"];
|
|
23423
|
+
let loopCount = 0;
|
|
23424
|
+
while (numPr && !numId && loopCount < 10) {
|
|
23425
|
+
const basedOnStyle = styleTags.find((tag) => tag.attributes["w:styleId"] === basedOnId) || {};
|
|
23426
|
+
const basedOnPPr = basedOnStyle?.elements?.find((style2) => style2.name === "w:pPr");
|
|
23427
|
+
numPr = basedOnPPr?.elements?.find((style2) => style2.name === "w:numPr");
|
|
23428
|
+
numIdTag = numPr?.elements?.find((style2) => style2.name === "w:numId") || {};
|
|
23429
|
+
numId = numIdTag?.attributes?.["w:val"];
|
|
23430
|
+
if (!ilvlTag) {
|
|
23431
|
+
ilvlTag = numPr?.elements?.find((style2) => style2.name === "w:ilvl");
|
|
23432
|
+
ilvl = ilvlTag?.attributes?.["w:val"];
|
|
23433
|
+
}
|
|
23434
|
+
loopCount++;
|
|
23466
23435
|
}
|
|
23467
|
-
|
|
23468
|
-
|
|
23469
|
-
|
|
23470
|
-
|
|
23471
|
-
|
|
23472
|
-
|
|
23473
|
-
|
|
23474
|
-
|
|
23475
|
-
|
|
23476
|
-
|
|
23477
|
-
|
|
23478
|
-
|
|
23479
|
-
|
|
23480
|
-
|
|
23481
|
-
|
|
23482
|
-
|
|
23483
|
-
|
|
23484
|
-
|
|
23485
|
-
|
|
23486
|
-
|
|
23436
|
+
return { numId, ilvl };
|
|
23437
|
+
};
|
|
23438
|
+
const getAbstractDefinition = (numId, docx) => {
|
|
23439
|
+
const def = docx["word/numbering.xml"];
|
|
23440
|
+
if (!def) return {};
|
|
23441
|
+
const { elements } = def;
|
|
23442
|
+
const listData = elements[0];
|
|
23443
|
+
const numberingElements = listData.elements;
|
|
23444
|
+
const abstractDefinitions = numberingElements.filter((style) => style.name === "w:abstractNum");
|
|
23445
|
+
const numDefinitions = numberingElements.filter((style) => style.name === "w:num");
|
|
23446
|
+
const numDefinition = numDefinitions.find((style) => style.attributes["w:numId"] == numId);
|
|
23447
|
+
const abstractNumId = numDefinition?.elements[0].attributes["w:val"];
|
|
23448
|
+
let listDefinitionForThisNumId = abstractDefinitions?.find(
|
|
23449
|
+
(style) => style.attributes["w:abstractNumId"] === abstractNumId
|
|
23450
|
+
);
|
|
23451
|
+
const templateIdTag = listDefinitionForThisNumId?.elements?.find((el) => el.name === "w:tmpl");
|
|
23452
|
+
const templateId = templateIdTag?.attributes?.["w:val"];
|
|
23453
|
+
if (templateId) {
|
|
23454
|
+
listDefinitionForThisNumId = numberingElements?.find((el) => {
|
|
23455
|
+
if (el.name !== "w:abstractNum") return false;
|
|
23456
|
+
const tmpl = el.elements?.find((el2) => el2.name === "w:tmpl");
|
|
23457
|
+
if (!tmpl) return false;
|
|
23458
|
+
const hasLevels = el.elements?.some((el2) => el2.name === "w:lvl");
|
|
23459
|
+
const tmplId = tmpl.attributes?.["w:val"];
|
|
23460
|
+
return tmplId && hasLevels && tmplId === templateId;
|
|
23487
23461
|
});
|
|
23488
|
-
return {
|
|
23489
|
-
nodes: translatedText,
|
|
23490
|
-
consumed: translatedText.length + 2
|
|
23491
|
-
};
|
|
23492
|
-
}
|
|
23493
|
-
const updatedParams = { ...params, nodes: [node2] };
|
|
23494
|
-
const result = handleStandardNode2(updatedParams);
|
|
23495
|
-
if (result.nodes.length === 1) {
|
|
23496
|
-
result.nodes[0].attrs.name = node2.attributes["w:name"];
|
|
23497
|
-
result.nodes[0].attrs.id = node2.attributes["w:id"];
|
|
23498
23462
|
}
|
|
23499
|
-
return
|
|
23500
|
-
};
|
|
23501
|
-
const bookmarkNodeHandlerEntity = {
|
|
23502
|
-
handlerName: "bookmarkNodeHandler",
|
|
23503
|
-
handler: handleBookmarkNode
|
|
23463
|
+
return listDefinitionForThisNumId;
|
|
23504
23464
|
};
|
|
23505
|
-
const
|
|
23506
|
-
const
|
|
23507
|
-
const
|
|
23508
|
-
if (
|
|
23509
|
-
|
|
23510
|
-
|
|
23511
|
-
|
|
23512
|
-
|
|
23513
|
-
|
|
23514
|
-
if (!hasAltChoice) {
|
|
23515
|
-
return skipHandlerResponse;
|
|
23516
|
-
}
|
|
23517
|
-
const altChoiceNode = node2.elements.find((el) => el.name === "mc:AlternateContent");
|
|
23518
|
-
node2.elements.findIndex((el) => el.name === "mc:AlternateContent");
|
|
23519
|
-
const allowedNamespaces = ["wps", "wp14", "w14", "w15"];
|
|
23520
|
-
const wpsNode = altChoiceNode.elements.find(
|
|
23521
|
-
(el) => el.name === "mc:Choice" && allowedNamespaces.includes(el.attributes["Requires"])
|
|
23522
|
-
);
|
|
23523
|
-
if (!wpsNode) {
|
|
23524
|
-
return skipHandlerResponse;
|
|
23465
|
+
const generateListPath = (level, numId, styleId, levels, docx) => {
|
|
23466
|
+
const iLvl = Number(level);
|
|
23467
|
+
const path = [];
|
|
23468
|
+
if (iLvl > 0) {
|
|
23469
|
+
for (let i = iLvl; i >= 0; i--) {
|
|
23470
|
+
const { start: lvlStart } = getListLevelDefinitionTag(numId, i, styleId, docx);
|
|
23471
|
+
if (!levels[i]) levels[i] = Number(lvlStart);
|
|
23472
|
+
path.unshift(levels[i]);
|
|
23473
|
+
}
|
|
23525
23474
|
}
|
|
23526
|
-
|
|
23527
|
-
const result = nodeListHandler2.handler({
|
|
23528
|
-
...params,
|
|
23529
|
-
nodes: contents
|
|
23530
|
-
});
|
|
23531
|
-
return { nodes: result, consumed: 1 };
|
|
23532
|
-
};
|
|
23533
|
-
const alternateChoiceHandler = {
|
|
23534
|
-
handlerName: "alternateChoiceHandler",
|
|
23535
|
-
handler: handleAlternateChoice
|
|
23475
|
+
return path;
|
|
23536
23476
|
};
|
|
23537
|
-
const
|
|
23538
|
-
|
|
23539
|
-
|
|
23540
|
-
|
|
23477
|
+
const getListLevelDefinitionTag = (numId, level, pStyleId, docx) => {
|
|
23478
|
+
if (pStyleId) {
|
|
23479
|
+
const { numId: numIdFromStyles, ilvl: iLvlFromStyles } = getListNumIdFromStyleRef(pStyleId, docx) || {};
|
|
23480
|
+
if (!numId && numIdFromStyles) numId = numIdFromStyles;
|
|
23481
|
+
if (!level && iLvlFromStyles) level = iLvlFromStyles ? parseInt(iLvlFromStyles) : null;
|
|
23541
23482
|
}
|
|
23542
|
-
const
|
|
23543
|
-
const
|
|
23544
|
-
const
|
|
23545
|
-
|
|
23546
|
-
|
|
23547
|
-
|
|
23483
|
+
const listDefinitionForThisNumId = getAbstractDefinition(numId, docx);
|
|
23484
|
+
const currentLevel = getDefinitionForLevel(listDefinitionForThisNumId, level);
|
|
23485
|
+
const numStyleLink = listDefinitionForThisNumId?.elements?.find((style) => style.name === "w:numStyleLink");
|
|
23486
|
+
const numStyleLinkId = numStyleLink?.attributes["w:val"];
|
|
23487
|
+
if (numStyleLinkId) {
|
|
23488
|
+
const current = getListNumIdFromStyleRef(numStyleLinkId, docx);
|
|
23489
|
+
return getListLevelDefinitionTag(current.numId, level, null, docx);
|
|
23490
|
+
}
|
|
23491
|
+
const start = currentLevel?.elements?.find((style) => style.name === "w:start")?.attributes["w:val"];
|
|
23492
|
+
let numFmtTag = currentLevel?.elements?.find((style) => style.name === "w:numFmt");
|
|
23493
|
+
let numFmt = numFmtTag?.attributes["w:val"];
|
|
23494
|
+
if (!numFmt) {
|
|
23495
|
+
const altChoice = currentLevel?.elements.find((style) => style.name === "mc:AlternateContent");
|
|
23496
|
+
const choice = altChoice?.elements.find((style) => style.name === "mc:Choice");
|
|
23497
|
+
const choiceNumFmtTag = choice?.elements.find((style) => style.name === "w:numFmt");
|
|
23498
|
+
const choiceNumFmt = choiceNumFmtTag?.attributes["w:val"];
|
|
23499
|
+
if (choiceNumFmt) {
|
|
23500
|
+
numFmtTag = choiceNumFmtTag;
|
|
23501
|
+
numFmt = choiceNumFmt;
|
|
23548
23502
|
}
|
|
23549
|
-
}
|
|
23550
|
-
|
|
23551
|
-
|
|
23552
|
-
|
|
23553
|
-
|
|
23554
|
-
|
|
23503
|
+
}
|
|
23504
|
+
let lvlText = currentLevel?.elements?.find((style) => style.name === "w:lvlText").attributes["w:val"];
|
|
23505
|
+
lvlText = normalizeLvlTextChar(lvlText);
|
|
23506
|
+
let customFormat;
|
|
23507
|
+
if (numFmt === "custom") customFormat = numFmtTag?.attributes?.["w:format"];
|
|
23508
|
+
const lvlJc = currentLevel?.elements?.find((style) => style.name === "w:lvlJc").attributes["w:val"];
|
|
23509
|
+
const pPr = currentLevel?.elements?.find((style) => style.name === "w:pPr");
|
|
23510
|
+
const rPr = currentLevel?.elements?.find((style) => style.name === "w:rPr");
|
|
23511
|
+
return { start, numFmt, lvlText, lvlJc, pPr, rPr, customFormat };
|
|
23555
23512
|
};
|
|
23556
|
-
|
|
23557
|
-
const
|
|
23558
|
-
if (
|
|
23559
|
-
|
|
23513
|
+
function normalizeLvlTextChar(lvlText) {
|
|
23514
|
+
const normalizeChars = ["", "", "○", "o", "■", "□"];
|
|
23515
|
+
if (!lvlText || !normalizeChars.includes(lvlText)) return lvlText;
|
|
23516
|
+
if (lvlText === "") lvlText = "•";
|
|
23517
|
+
if (lvlText === "○" || lvlText === "o") lvlText = "◦";
|
|
23518
|
+
if (lvlText === "■" || lvlText === "") lvlText = "▪";
|
|
23519
|
+
if (lvlText === "□") lvlText = "◯";
|
|
23520
|
+
return lvlText;
|
|
23521
|
+
}
|
|
23522
|
+
function getNodeNumberingDefinition(item, level, docx) {
|
|
23523
|
+
if (!item) return;
|
|
23524
|
+
const { attributes = {} } = item;
|
|
23525
|
+
const { paragraphProperties = {} } = attributes;
|
|
23526
|
+
const { elements: listStyles = [] } = paragraphProperties;
|
|
23527
|
+
const initialPpr = item.elements.find((el) => el.name === "w:pPr");
|
|
23528
|
+
const styleTag = initialPpr?.elements?.find((el) => el.name === "w:pStyle");
|
|
23529
|
+
const styleId = styleTag?.attributes["w:val"];
|
|
23530
|
+
const { numPr: numPrTag, type: type2 } = getNumPrRecursive({ node: item, styleId, docx });
|
|
23531
|
+
if (!numPrTag) return {};
|
|
23532
|
+
const numIdTag = numPrTag?.elements.find((style) => style.name === "w:numId");
|
|
23533
|
+
const numId = numIdTag?.attributes["w:val"];
|
|
23534
|
+
const pStyle = listStyles.find((style) => style.name === "w:pStyle");
|
|
23535
|
+
const pStyleId = pStyle?.attributes["w:val"];
|
|
23536
|
+
const {
|
|
23537
|
+
start,
|
|
23538
|
+
numFmt: listTypeDef,
|
|
23539
|
+
lvlText,
|
|
23540
|
+
lvlJc,
|
|
23541
|
+
pPr,
|
|
23542
|
+
rPr,
|
|
23543
|
+
customFormat
|
|
23544
|
+
} = getListLevelDefinitionTag(numId, level, pStyleId, docx);
|
|
23545
|
+
let listpPrs, listrPrs;
|
|
23546
|
+
if (pPr) listpPrs = _processListParagraphProperties(pPr, initialPpr);
|
|
23547
|
+
if (rPr) listrPrs = _processListRunProperties(rPr);
|
|
23548
|
+
let listType;
|
|
23549
|
+
if (unorderedListTypes.includes(listTypeDef?.toLowerCase())) listType = "bulletList";
|
|
23550
|
+
else if (orderedListTypes.includes(listTypeDef)) listType = "orderedList";
|
|
23551
|
+
else if (listTypeDef === "custom") {
|
|
23552
|
+
listType = "orderedList";
|
|
23553
|
+
} else {
|
|
23554
|
+
return {};
|
|
23560
23555
|
}
|
|
23561
|
-
|
|
23562
|
-
|
|
23563
|
-
|
|
23564
|
-
|
|
23565
|
-
|
|
23566
|
-
|
|
23556
|
+
return { listType, listOrderingType: listTypeDef, listrPrs, listpPrs, start, lvlText, lvlJc, customFormat };
|
|
23557
|
+
}
|
|
23558
|
+
function getDefinitionForLevel(data, level) {
|
|
23559
|
+
return data?.elements?.find((item) => Number(item.attributes["w:ilvl"]) === level);
|
|
23560
|
+
}
|
|
23561
|
+
function parseIndentElement(indElem) {
|
|
23562
|
+
if (!indElem || !indElem.attributes) return {};
|
|
23563
|
+
const out = {};
|
|
23564
|
+
if (indElem.attributes["w:left"] != null) out.left = twipsToPixels(indElem.attributes["w:left"]);
|
|
23565
|
+
if (indElem.attributes["w:right"] != null) out.right = twipsToPixels(indElem.attributes["w:right"]);
|
|
23566
|
+
if (indElem.attributes["w:firstLine"] != null) out.firstLine = twipsToPixels(indElem.attributes["w:firstLine"]);
|
|
23567
|
+
if (indElem.attributes["w:hanging"] != null) out.hanging = twipsToPixels(indElem.attributes["w:hanging"]);
|
|
23568
|
+
if (indElem.attributes["w:leftChars"] != null) out.leftChars = twipsToPixels(indElem.attributes["w:leftChars"]);
|
|
23569
|
+
return out;
|
|
23570
|
+
}
|
|
23571
|
+
function combineIndents(ind1, ind2) {
|
|
23572
|
+
ind1 = ind1 && typeof ind1 === "object" ? ind1 : {};
|
|
23573
|
+
ind2 = ind2 && typeof ind2 === "object" ? ind2 : {};
|
|
23574
|
+
const indent = {};
|
|
23575
|
+
["left", "right", "firstLine", "hanging"].forEach((prop) => {
|
|
23576
|
+
const v1 = ind1[prop] !== void 0 ? Number(ind1[prop]) : null;
|
|
23577
|
+
const v2 = ind2[prop] !== void 0 ? Number(ind2[prop]) : null;
|
|
23578
|
+
if (v1 != null && v2 != null) {
|
|
23579
|
+
indent[prop] = prop === "left" || prop === "hanging" ? Math.max(v1, v2) : v1;
|
|
23580
|
+
} else if (v1 != null) {
|
|
23581
|
+
indent[prop] = v1;
|
|
23582
|
+
} else if (v2 != null) {
|
|
23583
|
+
indent[prop] = v2;
|
|
23567
23584
|
}
|
|
23568
|
-
};
|
|
23569
|
-
return
|
|
23570
|
-
}
|
|
23571
|
-
|
|
23572
|
-
|
|
23573
|
-
|
|
23574
|
-
};
|
|
23575
|
-
|
|
23576
|
-
|
|
23577
|
-
|
|
23578
|
-
|
|
23585
|
+
});
|
|
23586
|
+
return indent;
|
|
23587
|
+
}
|
|
23588
|
+
function _processListParagraphProperties(data, inlinePpr) {
|
|
23589
|
+
const { elements } = data;
|
|
23590
|
+
const expectedTypes = ["w:ind", "w:jc", "w:tabs"];
|
|
23591
|
+
const paragraphProperties = {};
|
|
23592
|
+
if (!elements) return paragraphProperties;
|
|
23593
|
+
elements.forEach((item) => {
|
|
23594
|
+
if (!expectedTypes.includes(item.name)) {
|
|
23595
|
+
console.warn(`[numbering.xml] Unexpected list paragraph prop found: ${item.name}`);
|
|
23596
|
+
}
|
|
23597
|
+
});
|
|
23598
|
+
const inlineIndent = inlinePpr?.elements?.find((item) => item.name === "w:ind");
|
|
23599
|
+
const parsedInlineIndent = parseIndentElement(inlineIndent);
|
|
23600
|
+
const styleIndent = elements.find((item) => item.name === "w:ind");
|
|
23601
|
+
parseIndentElement(styleIndent);
|
|
23602
|
+
paragraphProperties.indent = parsedInlineIndent;
|
|
23603
|
+
const justify = elements.find((item) => item.name === "w:jc");
|
|
23604
|
+
if (justify) {
|
|
23605
|
+
const justifyAttrs = {};
|
|
23606
|
+
if (!justify.attributes) justify.attributes = {};
|
|
23607
|
+
if (justify.attributes["w:val"] !== void 0) justifyAttrs.val = justify.attributes["w:val"];
|
|
23608
|
+
paragraphProperties.justify = justifyAttrs;
|
|
23579
23609
|
}
|
|
23580
|
-
const
|
|
23581
|
-
|
|
23582
|
-
|
|
23583
|
-
const
|
|
23584
|
-
|
|
23585
|
-
|
|
23586
|
-
|
|
23587
|
-
|
|
23610
|
+
const tabs = elements.find((item) => item.name === "w:tabs");
|
|
23611
|
+
if (tabs) {
|
|
23612
|
+
const tabElements = tabs.elements.filter((item) => item.name === "w:tab");
|
|
23613
|
+
const tabStops = [];
|
|
23614
|
+
tabElements.forEach((tab) => {
|
|
23615
|
+
const tabStop = {};
|
|
23616
|
+
if (!tab.attributes) tab.attributes = {};
|
|
23617
|
+
if (tab.attributes["w:val"] !== void 0) tabStop.val = tab.attributes["w:val"];
|
|
23618
|
+
if (tab.attributes["w:leader"] !== void 0) tabStop.leader = tab.attributes["w:leader"];
|
|
23619
|
+
if (tab.attributes["w:pos"] !== void 0) tabStop.pos = twipsToPixels(tab.attributes["w:pos"]);
|
|
23620
|
+
tabStops.push(tabStop);
|
|
23621
|
+
});
|
|
23622
|
+
paragraphProperties.tabStops = tabStops;
|
|
23588
23623
|
}
|
|
23589
|
-
|
|
23590
|
-
|
|
23591
|
-
|
|
23592
|
-
|
|
23593
|
-
|
|
23594
|
-
|
|
23595
|
-
|
|
23596
|
-
|
|
23597
|
-
|
|
23598
|
-
|
|
23599
|
-
|
|
23600
|
-
|
|
23601
|
-
|
|
23624
|
+
return paragraphProperties;
|
|
23625
|
+
}
|
|
23626
|
+
function _processListRunProperties(data) {
|
|
23627
|
+
const { elements } = data;
|
|
23628
|
+
const expectedTypes = [
|
|
23629
|
+
"w:rFonts",
|
|
23630
|
+
"w:b",
|
|
23631
|
+
"w:bCs",
|
|
23632
|
+
"w:i",
|
|
23633
|
+
"w:iCs",
|
|
23634
|
+
"w:strike",
|
|
23635
|
+
"w:dstrike",
|
|
23636
|
+
"w:color",
|
|
23637
|
+
"w:sz",
|
|
23638
|
+
"w:szCs",
|
|
23639
|
+
"w:u",
|
|
23640
|
+
"w:bdr",
|
|
23641
|
+
"w:shd",
|
|
23642
|
+
"w:vertAlign",
|
|
23643
|
+
"w:jc",
|
|
23644
|
+
"w:spacing",
|
|
23645
|
+
"w:w",
|
|
23646
|
+
"w:smallCaps",
|
|
23647
|
+
"w:position",
|
|
23648
|
+
"w:lang"
|
|
23649
|
+
];
|
|
23650
|
+
const runProperties = {};
|
|
23651
|
+
if (!elements) return runProperties;
|
|
23652
|
+
elements.forEach((item) => {
|
|
23653
|
+
if (!expectedTypes.includes(item.name)) ;
|
|
23654
|
+
const { attributes = {} } = item;
|
|
23655
|
+
Object.keys(attributes).forEach((key) => {
|
|
23656
|
+
runProperties[key] = attributes[key];
|
|
23657
|
+
});
|
|
23658
|
+
});
|
|
23659
|
+
return runProperties;
|
|
23660
|
+
}
|
|
23661
|
+
const docxNumberigHelpers = {
|
|
23662
|
+
getListLevelDefinitionTag,
|
|
23663
|
+
combineIndents,
|
|
23664
|
+
parseIndentElement,
|
|
23665
|
+
generateListPath,
|
|
23666
|
+
normalizeLvlTextChar
|
|
23602
23667
|
};
|
|
23603
23668
|
const handlePictNode = (params) => {
|
|
23604
23669
|
const { nodes } = params;
|
|
@@ -24254,7 +24319,7 @@ const _SuperConverter = class _SuperConverter {
|
|
|
24254
24319
|
return;
|
|
24255
24320
|
}
|
|
24256
24321
|
}
|
|
24257
|
-
static updateDocumentVersion(docx = this.convertedXml, version = "0.14.0-next.
|
|
24322
|
+
static updateDocumentVersion(docx = this.convertedXml, version = "0.14.0-next.21") {
|
|
24258
24323
|
const customLocation = "docProps/custom.xml";
|
|
24259
24324
|
if (!docx[customLocation]) {
|
|
24260
24325
|
docx[customLocation] = generateCustomXml();
|
|
@@ -24299,7 +24364,15 @@ const _SuperConverter = class _SuperConverter {
|
|
|
24299
24364
|
typeface = fonts?.attributes["w:ascii"];
|
|
24300
24365
|
fontSizeNormal = Number(rPr?.elements?.find((el2) => el2.name === "w:sz")?.attributes["w:val"]) / 2;
|
|
24301
24366
|
});
|
|
24302
|
-
const
|
|
24367
|
+
const rPrDefaults = defaults?.elements?.find((el) => el.name === "w:rPrDefault");
|
|
24368
|
+
if (rPrDefaults) {
|
|
24369
|
+
const rPr = rPrDefaults.elements?.find((el) => el.name === "w:rPr");
|
|
24370
|
+
const fonts = rPr?.elements?.find((el) => el.name === "w:rFonts");
|
|
24371
|
+
typeface = fonts?.attributes["w:ascii"];
|
|
24372
|
+
const fontSize = typeface ?? rPr?.elements?.find((el) => el.name === "w:sz")?.attributes["w:val"];
|
|
24373
|
+
fontSizeNormal = !fontSizeNormal && fontSize ? Number(fontSize) / 2 : null;
|
|
24374
|
+
}
|
|
24375
|
+
const fontSizePt = fontSizeNormal || Number(rElements.find((el) => el.name === "w:sz")?.attributes["w:val"]) / 2 || 10;
|
|
24303
24376
|
const kern = rElements.find((el) => el.name === "w:kern")?.attributes["w:val"];
|
|
24304
24377
|
return { fontSizePt, kern, typeface, panose };
|
|
24305
24378
|
}
|
|
@@ -24725,7 +24798,7 @@ function storeSuperdocVersion(docx) {
|
|
|
24725
24798
|
function generateCustomXml() {
|
|
24726
24799
|
return DEFAULT_CUSTOM_XML;
|
|
24727
24800
|
}
|
|
24728
|
-
function generateSuperdocVersion(pid = 2, version = "0.14.0-next.
|
|
24801
|
+
function generateSuperdocVersion(pid = 2, version = "0.14.0-next.21") {
|
|
24729
24802
|
return {
|
|
24730
24803
|
type: "element",
|
|
24731
24804
|
name: "property",
|
|
@@ -24793,6 +24866,9 @@ export {
|
|
|
24793
24866
|
getContentTypesFromXml as ac,
|
|
24794
24867
|
xmljs as ad,
|
|
24795
24868
|
vClickOutside as ae,
|
|
24869
|
+
readFromClipboard as af,
|
|
24870
|
+
serializeSelectionToClipboard as ag,
|
|
24871
|
+
writeToClipboard as ah,
|
|
24796
24872
|
canSplit as b,
|
|
24797
24873
|
callOrGet as c,
|
|
24798
24874
|
canJoin as d,
|